home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / INFO / C / DLIBSSRC.ZIP / PFINDFIL.C < prev    next >
Encoding:
C/C++ Source or Header  |  1987-10-05  |  997 b   |  37 lines

  1. #include <stdio.h>
  2.  
  3. char *pfindfile(afn, ext)
  4. register char *afn;
  5. char *ext;
  6. /*
  7.  *    Like findfile() but search all directories listed in the environment
  8.  *    variable "PATH", if no match is found in the current directory. If
  9.  *    <afn> specifies a drive or directory, "PATH" is not used.
  10.  */
  11. {
  12.     static char tmp[PATHSIZE];
  13.     register char *path, *p;
  14.     char *findfile(), *strchr(), *getenv(), *strcpy();
  15.  
  16.     if((p = findfile(afn, ext)) ||            /* search . first */
  17.        strchr(afn, '\\') || strchr(afn, ':'))    /* path specified */
  18.         return(p);
  19.     if(path = getenv("PATH")) {            /* get PATH= */
  20.         while(*path) {
  21.             p = tmp;
  22.             while((*path != '\0') &&
  23.                   (*path != ';') &&
  24.                   (*path != ','))    /* copy directory */
  25.                 *p++ = *path++;
  26.             if(*path)            /* move past delim */
  27.                 ++path;
  28.             if(p[-1] != '\\')        /* add \ if needed */
  29.                 *p++ = '\\';
  30.             strcpy(p, afn);            /* copy filename */
  31.             if(p = findfile(tmp, ext))    /* do search */
  32.                 return(p);
  33.         }
  34.     }
  35.     return(NULL);
  36. }
  37.