home *** CD-ROM | disk | FTP | other *** search
/ Hall of Fame / HallofFameCDROM.cdr / proglc / makemak.lzh / GETPNAME.C < prev    next >
Text File  |  1987-06-14  |  950b  |  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.