home *** CD-ROM | disk | FTP | other *** search
- /*
- * ctree server
- * convert user name to system name
- *
- * This program is the CONFIDENTIAL and PROPRIETARY property
- * of FairCom(R) Corporation. Any unauthorized use, reproduction or
- * transfer of this program is strictly prohibited.
- *
- * Copyright (c) 1987, 1988, 1989 FairCom Corporation
- * (Subject to limited distribution and
- * restricted disclosure only.)
- * *** ALL RIGHTS RESERVED ***
- *
- * 4006 West Broadway
- * Columbia, MO 65203
- *
- *
- * c-tree(R) Version 4.3
- * Release C
- * February 7, 1989 17:30
- *
- */
-
- #include "ctstdr.h"
- #include "ctoptn.h"
- #include "ctstrc.h"
- #include "cterrc.h"
- #include "ctcomm.h"
-
- #define UNKNOWN 9999 /* %%%%%%%%% TEMP %%%%%%%%%%% */
-
- #ifdef DEBUG
- #ifdef LOCAL
- #undef LOCAL
- #define LOCAL /* */
- #endif
- #endif
-
- LOCAL TEXT *def_dir;
-
- extern COUNT uerr_cod;
-
-
-
- /*
- * called from getmid in ctsmsg to get a copy of working
- * dir at system startup time.
- */
-
- COUNT get_default_dir()
- {
- TEXT *getcwd();
-
- if (NULL == (def_dir = getcwd(NULL, 64)))
- return (uerr_cod = SSPC_ERR);
- strlwr(def_dir);
- return (0);
- }
-
-
- /*
- * fulnam - converts file name from user to fully specified form
- *
- * returns 0 if name is okay, returns error code and sets uerr_cod
- * if name is too long or if badly formed.
- *
- * filenames from users are converted as shown in the table below.
- * def_dir is the default drive:\directory
- * in effect when the ctree server was started.
- *
- * Note that is the user specifies a drive code other than the def_dir,
- * then the 'working directory' for that drive is the root.
- *
- * drive drive== leading example result (assume
- * spec'd? default? "\"? user name def_dir == "c:\ctree")
- * ------- -------- ------- --------- --------------------------
- * N Y* N data c:\ctree\data
- * Y Y N c:data c:\ctree\data
- * Y N N d:data d:\data
- * N Y* Y \sub\data c:\sub\data
- * Y Y Y c:\data c:\data
- * Y N Y d:\data d:\data
- *
- * * if drive not spec'd then default drive used
- */
-
- COUNT fulnam(dp, tp, maxlen)
- PFAST TEXT *dp,*tp;
- COUNT maxlen; /* includes null */
- {
- COUNT i;
- strlwr(tp); /* make lower case */
-
- for (i=0; tp[i]; i++) /* change fwd slash to back sl. */
- if (tp[i] == '/')
- tp[i] == '\\';
-
- /* build drive letter and colon in destination */
-
- if (strlen(tp) >= 2 && tp[1] == ':') {
- dp[0] = *tp;
- tp += 2;
- }
- else
- dp[0] = def_dir[0]; /* use default if not in target */
-
- dp[1] = ':';
- dp[2] = '\0';
-
- /* add working directory unless user fully spec'd path */
-
- if (*tp == '\\')
- tp++;
- else if (dp[0] == def_dir[0]) {
- strcat(dp, def_dir + 2); /* skip drive and colon in def_dir */
- }
-
- /* add separator before user part */
- strcat(dp, "\\");
-
- /* now dp contains either "x:\" or "x:\cwd\" */
-
- /* loop to copy rest, looking out for .. and . */
-
- i = strlen(dp); /* next place in dest str */
- while (*tp) {
- if (!strncmp(tp, ".\\", 2))
- tp += 2; /* just dump "." */
- else if (!strncmp(tp, "..\\", 3)) {
- tp += 3;
- /* throw out one member for ".." */
- while (dp[--i] != '\\')
- if (i == 2)
- /* invalid path */
- return (uerr_cod = ABDR_ERR);
- }
- else {
- /* copy target to dest until next \ */
- do {
- if ((i + 2) >= maxlen)
- /* max path length exceeded */
- return (uerr_cod = AFLN_ERR);
- dp[i++] = *tp++;
- } while (*tp && *(tp-1) != '\\');
- }
- }
- dp[i] = '\0'; /* terminating null */
- return(NO_ERROR);
- }
-