home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / CLIPPER / MISC / MAKEMAKE.ZIP / GETPNAME.C < prev    next >
Encoding:
C/C++ Source or Header  |  1987-06-14  |  950 b   |  36 lines

  1. /*
  2. *     getpname -- extract the base name of a program from the pathname
  3. *     string (deletes a drive specifier, any leading path node information,
  4. *     and the extension
  5. *     From Augie Hansen's "Proficient C"
  6. */
  7.  
  8. #include <stdio.h>
  9. #include <ctype.h>
  10.  
  11. void getpname(path, pname)
  12. char *path;       /* full or relative pathname */
  13. char *pname;      /* program name identifier */
  14. {
  15.    char *cp;
  16.  
  17.    /* find the end of the pathname string */
  18.    cp = path;     /* start  of pathname */
  19.    while (*cp != '\0')
  20.       ++cp;
  21.    --cp;          /* went one to far */
  22.  
  23.    /* find the start of the filename part */
  24.    while (cp > path && *cp != '\\' && *cp != ':' && *cp != '/')
  25.       --cp;
  26.    if (cp > path)
  27.       ++cp;       /* move to right of pathname separator */
  28.  
  29.    /* copy the filename part only */
  30.    while ((*pname = tolower(*cp)) != '.' && *pname != '\0') {
  31.       ++cp;
  32.       ++pname;
  33.    }
  34.    *pname = '\0';
  35. }
  36.