home *** CD-ROM | disk | FTP | other *** search
/ Boston 2 / boston-2.iso / DOS / PROGRAM / C / CFLOW / MAKEFILE.C < prev    next >
Text File  |  1993-12-01  |  2KB  |  64 lines

  1. /*    makefile.c    CI-C86 Utility Function
  2. **
  3. **    Copyright (c) 1985 by:
  4. **
  5. **        Lawrence R. Steeger
  6. **        1009 North Jackson Street
  7. **        Milwaukee, Wisconsin 53202
  8. **        414-277-8149
  9. */
  10.  
  11. #include <stdio.h>
  12.  
  13. /*    makefile(filespec)
  14. **
  15. **    Extract MS-DOS 2 file name from "filespec".
  16. **
  17. **    Returns:    (char *)    file name or EOS
  18. */
  19.  
  20. char *makefile(filespec)
  21. unsigned char *filespec;
  22. {
  23.     unsigned char delimit,        /* strrchr() delimiter        */
  24.               *pathend,        /* end of drive:path\spec    */
  25.               *strrchr();    /* reverse strchr()        */
  26.  
  27.     char *alloc(),            /* storage allocator        */
  28.          *filename,            /* returned drive:path\name    */
  29.          *strncpy();        /* copy string for n characters    */
  30.  
  31.     int filelen,            /* length of file name        */
  32.         pathlen,            /* length of drive:path\name    */
  33.         strlen();            /* get length of string        */
  34.  
  35.     /*    determine drive/path delimiting character        */
  36.  
  37.     delimit = 0;
  38.  
  39.     if (strrchr(filespec, '\\') != NULL)
  40.         delimit = '\\';        /* drive:path\ specification    */
  41.  
  42.     if (!delimit)
  43.         if (strrchr(filespec, '/') != NULL)
  44.             delimit = '/';    /* drive:path/ specification    */
  45.         else    delimit = ':';    /* drive: specification        */
  46.  
  47.     /*    locate end of drive/path name                */
  48.  
  49.     if ((pathend = strrchr(filespec, delimit)) != NULL) {
  50.         pathlen = (pathend - filespec) + 1;
  51.         filelen = strlen(&filespec[pathlen]);
  52.         filename = alloc(strlen(filelen) + 1);
  53.         return (strncpy(filename, &filespec[pathlen], filelen));
  54.     }
  55.     else {                /* no path name            */
  56.         filename = alloc(strlen(filespec) + 1);
  57.         strcpy(filename, filespec);
  58.         return (filename);
  59.     }
  60. }
  61.  
  62. /*    end of makefile.c                        */
  63.  
  64. f