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

  1. /*    makepath.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. /*    makepath(filespec)
  14.  
  15.     Extract MS-DOS 2 drive/path name from "filespec".
  16.  
  17.     Returns:    (char *)    drive/path name or EOS
  18. */
  19.  
  20. char *makepath(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.          *pathname,            /* returned drive:path\name    */
  29.          *strncpy();
  30.  
  31.     int pathlen;            /* length of drive:path\name    */
  32.  
  33.     /*    determine drive/path delimiting character        */
  34.  
  35.     delimit = 0;
  36.  
  37.     if (strrchr(filespec, '\\') != NULL)
  38.         delimit = '\\';        /* drive:path\ specification    */
  39.  
  40.     if (!delimit)
  41.         if (strrchr(filespec, '/') != NULL)
  42.             delimit = '/';    /* drive:path/ specification    */
  43.         else    delimit = ':';    /* drive: specification        */
  44.  
  45.     /*    locate end of drive/path name                */
  46.  
  47.     if ((pathend = strrchr(filespec, delimit)) != NULL) {
  48.         pathlen = (pathend - filespec) + 1;
  49.         pathname = alloc(pathlen + 1);
  50.         return (strncpy(pathname, filespec, pathlen));
  51.     }
  52.     else {                /* no drive:path\name        */
  53.         pathname = alloc(1);
  54.         *pathname = EOS;
  55.         return (pathname);
  56.     }
  57. }
  58.  
  59. /*    end of makepath.c        */
  60.  
  61. *