home *** CD-ROM | disk | FTP | other *** search
/ Microsoft Programmer's Library 1.3 / Microsoft-Programers-Library-v1.3.iso / sampcode / prof_c / util / getpname.c < prev    next >
Encoding:
C/C++ Source or Header  |  1988-08-11  |  834 b   |  36 lines

  1. /*
  2.  *    getpname -- extract the base name of a program from
  3.  *    the pathname string (deletes a drive specifier, any
  4.  *    leading path node information, and the extension)
  5.  */
  6.  
  7. #include <stdio.h>
  8. #include <ctype.h>
  9.  
  10. char *
  11. getpname(path, pname)
  12. char *path;    /* full or relative pathname */
  13. char *pname;    /* program name pointer */
  14. {
  15.     register 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 too 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 off the 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.