home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c004 / 3.ddi / OS2LAN / CTFULNAM.C < prev    next >
Encoding:
C/C++ Source or Header  |  1989-04-18  |  3.6 KB  |  150 lines

  1. /*
  2.  *    ctree server
  3.  *    convert user name to system name
  4.  *
  5.  *    This program is the CONFIDENTIAL and PROPRIETARY property 
  6.  *    of FairCom(R) Corporation. Any unauthorized use, reproduction or
  7.  *    transfer of this program is strictly prohibited.
  8.  *
  9.  *      Copyright (c) 1987, 1988, 1989 FairCom Corporation
  10.  *    (Subject to limited distribution and
  11.  *     restricted disclosure only.)
  12.  *    *** ALL RIGHTS RESERVED ***
  13.  *
  14.  *    4006 West Broadway
  15.  *    Columbia, MO 65203
  16.  *
  17.  *
  18.  *    c-tree(R)    Version 4.3
  19.  *            Release C
  20.  *            February 7, 1989 17:30
  21.  *
  22.  */
  23.  
  24. #include "ctstdr.h"
  25. #include "ctoptn.h"
  26. #include "ctstrc.h"
  27. #include "cterrc.h"
  28. #include "ctcomm.h"
  29.  
  30. #define UNKNOWN 9999    /* %%%%%%%%% TEMP %%%%%%%%%%% */
  31.  
  32. #ifdef DEBUG
  33.  #ifdef LOCAL
  34.   #undef LOCAL
  35.   #define LOCAL /* */
  36.  #endif
  37. #endif
  38.  
  39. LOCAL TEXT *def_dir;
  40.  
  41. extern COUNT uerr_cod;
  42.  
  43.  
  44.  
  45. /*
  46.  * called from getmid in ctsmsg to get a copy of working
  47.  * dir at system startup time.
  48.  */
  49.  
  50. COUNT get_default_dir()
  51. {
  52.     TEXT *getcwd();
  53.  
  54.     if (NULL == (def_dir = getcwd(NULL, 64)))
  55.         return (uerr_cod = SSPC_ERR);
  56.     strlwr(def_dir);
  57.     return (0);
  58. }
  59.  
  60.  
  61. /*
  62.  * fulnam - converts file name from user to fully specified form
  63.  *
  64.  * returns 0 if name is okay, returns error code and sets uerr_cod
  65.  * if name is too long or if badly formed.
  66.  *
  67.  * filenames from users are converted as shown in the table below.
  68.  * def_dir is the default drive:\directory
  69.  * in effect when the ctree server was started.
  70.  *
  71.  * Note that is the user specifies a drive code other than the def_dir,
  72.  * then the 'working directory' for that drive is the root.
  73.  * 
  74.  * drive    drive==   leading   example      result (assume 
  75.  * spec'd?  default?   "\"?     user name     def_dir == "c:\ctree")
  76.  * -------  --------  -------   ---------    --------------------------
  77.  *   N        Y*        N       data         c:\ctree\data
  78.  *   Y        Y         N       c:data       c:\ctree\data
  79.  *   Y        N         N       d:data       d:\data
  80.  *   N        Y*        Y       \sub\data    c:\sub\data
  81.  *   Y        Y         Y       c:\data      c:\data
  82.  *   Y        N         Y       d:\data      d:\data
  83.  *
  84.  *   * if drive not spec'd then default drive used
  85.  */
  86.  
  87. COUNT fulnam(dp, tp, maxlen)
  88. PFAST TEXT  *dp,*tp;
  89. COUNT             maxlen;    /* includes null */
  90. {
  91.     COUNT i;
  92.     strlwr(tp);            /* make lower case */
  93.  
  94.     for (i=0; tp[i]; i++)        /* change fwd slash to back sl. */
  95.         if (tp[i] == '/')
  96.             tp[i] == '\\';
  97.  
  98.     /* build drive letter and colon in destination */
  99.  
  100.     if (strlen(tp) >= 2 && tp[1] == ':') {
  101.         dp[0] = *tp;
  102.         tp += 2;
  103.     }
  104.     else
  105.         dp[0] = def_dir[0];    /* use default if not in target */
  106.  
  107.     dp[1] = ':';
  108.     dp[2] = '\0';
  109.  
  110.     /* add working directory unless user fully spec'd path */
  111.  
  112.     if (*tp == '\\')
  113.         tp++;
  114.     else if (dp[0] == def_dir[0]) {
  115.         strcat(dp, def_dir + 2);        /* skip drive and colon in def_dir */
  116.     }
  117.  
  118.     /* add separator before user part */
  119.     strcat(dp, "\\");
  120.  
  121.     /* now dp contains either "x:\" or "x:\cwd\" */
  122.  
  123.     /* loop to copy rest, looking out for .. and . */
  124.  
  125.     i = strlen(dp);            /* next place in dest str */
  126.     while (*tp) {
  127.         if (!strncmp(tp, ".\\", 2))
  128.             tp += 2;        /* just dump "." */
  129.         else if (!strncmp(tp, "..\\", 3)) {
  130.             tp += 3;
  131.             /* throw out one member for ".." */
  132.             while (dp[--i] != '\\')
  133.                 if (i == 2)
  134.                     /* invalid path */
  135.                     return (uerr_cod = ABDR_ERR);
  136.         }
  137.         else {
  138.             /* copy target to dest until next \ */
  139.             do {
  140.                 if ((i + 2) >= maxlen)
  141.                     /* max path length exceeded */
  142.                     return (uerr_cod = AFLN_ERR);
  143.                 dp[i++] = *tp++;
  144.             } while (*tp && *(tp-1) != '\\');
  145.         }
  146.     }
  147.     dp[i] = '\0';        /* terminating null */
  148.     return(NO_ERROR);
  149. }
  150.