home *** CD-ROM | disk | FTP | other *** search
/ Simtel MSDOS 1992 June / SIMTEL_0692.cdr / msdos / comptbls / attclock.arc / GETPNAME.C < prev    next >
Encoding:
C/C++ Source or Header  |  1988-03-05  |  1004 b   |  37 lines

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