1: #include <stdio.h>
   2: #include <ctype.h>
   3: #include "msdos.h"
   4: 
   5: extern char *mcwd;
   6: 
   7: /*
   8:  * Get name component of filename.  Translates name to upper case.  Returns
   9:  * pointer to static area.
  10:  */
  11: 
  12: char *
  13: get_name(filename)
  14: char *filename;
  15: {
  16:     char *s, *temp, *strcpy(), *strrchr(), buf[MAX_PATH];
  17:     static char ans[13];
  18: 
  19:     strcpy(buf, filename);
  20:     temp = buf;
  21:                     /* skip drive letter */
  22:     if (buf[0] && buf[1] == ':')
  23:         temp = &buf[2];
  24:                     /* find the last separator */
  25:     if (s = strrchr(temp, '/'))
  26:         temp = s + 1;
  27:     if (s = strrchr(temp, '\\'))
  28:         temp = s + 1;
  29:                     /* xlate to upper case */
  30:     for (s = temp; *s; ++s) {
  31:         if (islower(*s))
  32:             *s = toupper(*s);
  33:     }
  34: 
  35:     strcpy(ans, temp);
  36:     return(ans);
  37: }
  38: 
  39: /*
  40:  * Get the path component of the filename.  Translates to upper case.
  41:  * Returns pointer to a static area.  Doesn't alter leading separator,
  42:  * always strips trailing separator (unless it is the path itself).
  43:  */
  44: 
  45: char *
  46: get_path(filename)
  47: char *filename;
  48: {
  49:     char *s, *end, *begin, *strcpy(), *strrchr(), buf[MAX_PATH];
  50:     char drive, *strcat();
  51:     static char ans[MAX_PATH];
  52:     int has_sep;
  53: 
  54:     strcpy(buf, filename);
  55:     begin = buf;
  56:                     /* skip drive letter */
  57:     drive = '\0';
  58:     if (buf[0] && buf[1] == ':') {
  59:         drive = (islower(buf[0])) ? toupper(buf[0]) : buf[0];
  60:         begin = &buf[2];
  61:     }
  62:                     /* if absolute path */
  63:     if (*begin == '/' || *begin == '\\')
  64:         ans[0] = '\0';
  65:     else {
  66:         if (!drive || drive == *mcwd)
  67:             strcpy(ans, mcwd + 2);
  68:         else
  69:             strcpy(ans, "/");
  70:     }
  71:                     /* find last separator */
  72:     has_sep = 0;
  73:     end = begin;
  74:     if (s = strrchr(end, '/')) {
  75:         has_sep++;
  76:         end = s;
  77:     }
  78:     if (s = strrchr(end, '\\')) {
  79:         has_sep++;
  80:         end = s;
  81:     }
  82:                     /* zap the trailing separator */
  83:     *end = '\0';
  84:                     /* translate to upper case */
  85:     for (s = begin; *s; ++s) {
  86:         if (islower(*s))
  87:             *s = toupper(*s);
  88:         if (*s == '\\')
  89:             *s = '/';
  90:     }
  91:                     /* if separator alone, put it back */
  92:     if (!strlen(begin) && has_sep)
  93:         strcat(ans, "/");
  94: 
  95:     strcat(ans, begin);
  96:     return(ans);
  97: }
  98: 
  99: /*
 100:  * get the drive letter designation
 101:  */
 102: 
 103: char
 104: get_drive(filename)
 105: char *filename;
 106: {
 107:     if (*filename && *(filename + 1) == ':') {
 108:         if (islower(*filename))
 109:             return(toupper(*filename));
 110:         else
 111:             return(*filename);
 112:     }
 113:     else
 114:         return(*mcwd);
 115: }
Last modified: 1992-06-24
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 2353
Valid CSS Valid XHTML 1.0 Strict