home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / INFO / C / DLIBSSRC.ZIP / FULLPATH.C < prev    next >
Encoding:
C/C++ Source or Header  |  1987-07-27  |  1.6 KB  |  66 lines

  1. #include <osbind.h>
  2. #include <stdio.h>
  3.  
  4. char *fullpath(full, part)
  5. register char *full;
  6. register char *part;
  7. /*
  8.  *    <part> is a (possibly) ambiguous file/path specification.  A
  9.  *    non-ambiguous file/path spec is created which includes a drive
  10.  *    letter and all intermediate sub-directories.  If the partial
  11.  *    specification is not valid, NULL is returned, otherwise a
  12.  *    pointer to <full> is returned.  If NULL is specified for <full>,
  13.  *    an internal buffer is used and a pointer to it is returned.
  14.  */
  15. {
  16.     static char buf[PATHSIZE];
  17.     register char *bp = buf;
  18.     register int drv;
  19.     char *strlwr(), *strcpy();
  20.  
  21.     if (*part && (part[1] == ':')) {
  22.         drv = *bp++ = *part++;
  23.         drv = ((drv - 1) & 0xF);
  24.         *bp++ = *part++;
  25.     }
  26.     else {
  27.         *bp++ = (drv = Dgetdrv()) + 'a';
  28.         *bp++ = ':';
  29.     }
  30.     if (*part == '\\')
  31.         ++part;
  32.     else {
  33.         Dgetpath(bp, drv+1);    /* 1 BASED drive number here */
  34.         while(*bp++)
  35.             ;
  36.         --bp;
  37.     }
  38.     *bp++ = '\\';
  39.     *bp = '\0';
  40.     while(*part) {            /* handle dots and copy path & file */
  41.         if (*part == '.') {
  42.             if (*++part == '.') {
  43.                 if (*++part == '\\') {    /* parent */
  44.                     --bp;
  45.                     while((*--bp != '\\') && (*bp != ':'))
  46.                         ;
  47.                     if (*bp++ == ':')
  48.                         ++bp;
  49.                     ++part;
  50.                 }
  51.                 else
  52.                     return(NULL);    /* illegal pathname */
  53.             }
  54.             else if (*part++ != '\\')
  55.                 return(NULL);        /* illegal pathname */
  56.         }
  57.         else
  58.             while(*part && ((*bp++ = *part++) != '\\'))
  59.                 ;
  60.     }
  61.     *bp = '\0';
  62.     if (full == NULL)    /* special case to use local buffer */
  63.         full = buf;
  64.     return(strlwr(strcpy(full, buf)));    /* lowercase and return */
  65. }
  66.