home *** CD-ROM | disk | FTP | other *** search
/ vsiftp.vmssoftware.com / VSIPUBLIC@vsiftp.vmssoftware.com.tar / FREEWARE / FREEWARE40.ZIP / flistfrontend / src / pathup.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-06-06  |  3.2 KB  |  137 lines

  1. #ifndef NO_IDENT
  2. static char *Id = "$Id: pathup.c,v 1.7 1995/06/06 13:28:46 tom Exp $";
  3. #endif
  4.  
  5. /*
  6.  * Title:    pathup.c
  7.  * Author:    Thomas E. Dickey
  8.  * Created:    02 Jul 1984, recode from 'dirent.c' module
  9.  * Last update:
  10.  *        19 Feb 1995, str/sys utils prototypes
  11.  *        11 Apr 1985, do a translate-logical before trying to scan the
  12.  *                 pathname.  Some system stuff does logical-names for
  13.  *                 subdirectories.
  14.  *        09 Sep 1984, use 'rmsinit'
  15.  *        25 Aug 1984
  16.  *
  17.  * Function:    Given a filespec, do a parse to obtain the pathname portion,
  18.  *        and then determine the name of the parent directory.  For
  19.  *        example, given
  20.  *
  21.  *            "DBC4:[DICKEY.EXE]"    - pathname in
  22.  *        obtain
  23.  *            "DBC4:[DICKEY]"
  24.  *
  25.  * Parameters:    co_    => output buffer (NAM$C_MAXRSS bytes)
  26.  *        ci_    => input filespec/pathname
  27.  *
  28.  * Returns:    TRUE if no error was detected.
  29.  */
  30.  
  31. #include    <starlet.h>
  32. #include    <stdio.h>
  33. #include    <string.h>
  34. #include    <rms.h>
  35.  
  36. #include    "bool.h"
  37. #include    "pathup.h"
  38. #include    "rmsinit.h"
  39.  
  40. #include    "strutils.h"
  41. #include    "sysutils.h"
  42.  
  43. int    pathup (char *co_, char *ci_)
  44. {
  45.     int    len,    j,    first,    rootUIC = TRUE;
  46.     struct    FAB    fab;
  47.     struct    NAM    nam;
  48.     char    delim,
  49.         esa    [NAM$C_MAXRSS],
  50.         strn    [NAM$C_MAXRSS];
  51.  
  52.     strcpy (co_, ci_);        /* (return something, even if bad)*/
  53.  
  54.     /*
  55.      * We do a parse-loop to handle (possibly) two substitutions.  Most
  56.      * file specifications will fall through in one scan, e.g., DBC4 will
  57.      * immediately evaluate to a physical device name.  However, we may
  58.      * have logical assignments such as the ones in the system:
  59.      *
  60.      *    SYS$MANAGER: => SYS$SYSROOT:[SYSMGR] => __DRA0:[SYS0.SYSMGR]
  61.      *
  62.      * The second step is the crucial one; we must translate SYS$SYSROOT
  63.      * to find the actual location (__DRA0:[SYS0]) of the SYS$MANAGER
  64.      * directory file SYSMGR.DIR;1.  The intermediate logical is
  65.      *
  66.      *    SYS$SYSROOT => __DRA0:[SYS0.]
  67.      *
  68.      * The trailing ".]" permits use to refer to SYS$SYSROOT as a true
  69.      * logical device (with dependent directories), but confuses the
  70.      * path-up translation.
  71.      */
  72.     for (;;)
  73.     {
  74.         rmsinit_fab (&fab, &nam, 0, co_);
  75.         rmsinit_nam (&nam, 0, esa);
  76.  
  77.         if (RMS$_NORMAL != sys$parse(&fab))    return (FALSE);
  78.  
  79. #define    COPY(dst,f)\
  80.         strncpy(dst, nam.nam$l_node, len = nam.f - nam.nam$l_node);\
  81.         dst[len] = EOS
  82.  
  83.         esa[nam.nam$b_esl] = EOS;
  84.  
  85.         COPY(strn,nam$l_dir-1);    /* Extract the device name    */
  86.         systrnlog (co_, strn);    /* Expand it...            */
  87.         if (strcmp(co_, strn))    /* Substitution done ?        */
  88.         {
  89.             if (co_[j=(strlen(co_)-1)] == ']')
  90.             {
  91.                 if (co_[j-1] == '.')    j--;
  92.                 ci_ = nam.nam$l_dir;
  93.                 if (*ci_ == '[')
  94.                     sprintf (&co_[j], ".%s", ci_+1);
  95.                 else
  96.                     sprintf (&co_[j], "]%s", ci_);
  97.             }
  98.             else
  99.                 break;
  100.         }
  101.         else
  102.             break;
  103.     }
  104.  
  105.     /*
  106.      * Copy the expanded string, truncating it at the end of the directory,
  107.      * e.g.,
  108.      *    DBC4:[DICKEY]FILE.TMP
  109.      * becomes
  110.      *    DBC4:[DICKEY]
  111.      */
  112.     COPY(co_,nam$l_name);
  113.  
  114.     first    = nam.nam$l_dir  - nam.nam$l_node;
  115.     delim    = co_[len-1];
  116.  
  117.     for (j = len-2; j > first; j--)
  118.     {
  119.         if (co_[j] != '0' && co_[j] != ',')    rootUIC = FALSE;
  120.         if (co_[j] == '.')    break;
  121.     }
  122.  
  123.     strncpy (esa, &co_[j+1], len -= j+2);
  124.     esa[len] = EOS;
  125.  
  126.     if (j == first)
  127.     {
  128.         strcpy (&co_[j+1], "0,0");
  129.         if (rootUIC)
  130.             strcpy (esa, "000000");
  131.     }
  132.     else
  133.         co_[j] = EOS;
  134.     sprintf (strnull(co_), "%c%s.DIR", delim, esa);
  135.     return (TRUE);
  136. }
  137.