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

  1. #ifndef NO_IDENT
  2. static char *Id = "$Id: pathdown.c,v 1.6 1995/06/06 12:58:22 tom Exp $";
  3. #endif
  4.  
  5. /*
  6.  * Title:    pathdown.c
  7.  * Author:    Thomas E. Dickey
  8.  * Created:    02 Jul 1984, recode from 'dirent.c' module
  9.  * Last update:
  10.  *        19 Feb 1995, prototypes
  11.  *        10 Sep 1985, calls using FILENT-arguments may have a trailing
  12.  *                 '.' in 'name_' field.
  13.  *        09 Sep 1984, use "rmsinit"
  14.  *        25 Aug 1984
  15.  *
  16.  * Function:    Given a filespec, do a parse to obtain the pathname portion,
  17.  *        and then create a character string containing the pathname of a
  18.  *        subdirectory whose name is given.  For example, given
  19.  *
  20.  *            "DBC4:[DICKEY]"    - pathname in
  21.  *            "XX" - directory name
  22.  *        obtain
  23.  *            "DBC4:[DICKEY.XX]"
  24.  *
  25.  *        This procedure tests for the "[0,0]" UIC-code, but no others,
  26.  *        since I cannot experiment much on numeric UIC's.
  27.  *
  28.  * Parameters:    co_    => output buffer (NAM$C_MAXRSS bytes)
  29.  *        ci_    => input filespec/pathname
  30.  *        name_    => name of dependent directory
  31.  *
  32.  * Returns:    TRUE if no error was detected.  Errors include parse-errors,
  33.  *        and attempts to recur on the "[0,0]" name "000000".
  34.  */
  35.  
  36. #include    <stdio.h>
  37. #include    <string.h>
  38.  
  39. #include    <starlet.h>
  40. #include    <rms.h>
  41.  
  42. #include    "bool.h"
  43. #include    "pathup.h"
  44. #include    "rmsinit.h"
  45.  
  46. int    pathdown (char    *co_, char *ci_, char *name_)
  47. {
  48. int    len;
  49. int    j,
  50.     rootUIC = TRUE;
  51. char    delim,    delim2;
  52. struct    FAB    fab;
  53. struct    NAM    nam;
  54. char    tmp    [NAM$C_MAXRSS],
  55.     esa    [NAM$C_MAXRSS];
  56.  
  57.     strcpy (co_, ci_);        /* (return something, even if bad)*/
  58.  
  59.     rmsinit_fab (&fab, &nam, 0, ci_);
  60.     rmsinit_nam (&nam, 0, esa);
  61.  
  62.     if (RMS$_NORMAL != sys$parse(&fab))    return (FALSE);
  63.  
  64.     strncpy (co_, nam.nam$l_node, len = nam.nam$b_esl);
  65.     co_[len] = '\0';
  66.  
  67.     /* cf: NAME_DOT in DIRENT.H */
  68.     strcpy (tmp, name_);
  69.     len    = strlen (name_ = tmp);
  70.     if (tmp[len-1] == '.')    tmp[--len] = '\0';
  71.  
  72.     len    = nam.nam$l_name - nam.nam$l_node;
  73.     delim    = co_[len-1];
  74.     delim2    = (delim == ']') ? '[' : '<';
  75.  
  76.     for (j = len-2; co_[j] != delim2 && j >= 0; j--)
  77.     {
  78.         if (co_[j] != '0' && co_[j] != ',')
  79.         {
  80.             rootUIC = FALSE;
  81.             break;
  82.         }
  83.     }
  84.  
  85.     if (rootUIC && co_[j] == delim2)
  86.     {
  87.         if (strcmp (name_, "000000") == 0)
  88.             return (FALSE);
  89.         sprintf (&co_[j+1], "%s%c", name_, delim);
  90.     }
  91.     else
  92.         sprintf (&co_[len-1], ".%s%c", name_, delim);
  93.     return (TRUE);
  94. }
  95.