# 2.11BSD#431 - /usr/src/local/mtools/parse.c

##### Functions

    get_drive         X
    get_name          X
    get_path          X

       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: }

#### Defined functions

get_drive defined in line 103; used 21 times

- in /usr/src/local/mtools/mattrib.c line 33, 93
- in /usr/src/local/mtools/mcd.c line 30, 45
- in /usr/src/local/mtools/mdel.c line 33, 58
- in /usr/src/local/mtools/mdir.c line 35, 67-72(2)
- in /usr/src/local/mtools/mmd.c line 34, 65
- in /usr/src/local/mtools/mrd.c line 33, 51
- in /usr/src/local/mtools/mread.c line 49, 101
- in /usr/src/local/mtools/mren.c line 29, 50
- in /usr/src/local/mtools/mtype.c line 33, 64
- in /usr/src/local/mtools/mwrite.c line 42, 84

get_name defined in line 12; used 20 times

- in /usr/src/local/mtools/mattrib.c line 34, 101
- in /usr/src/local/mtools/mcd.c line 28, 46
- in /usr/src/local/mtools/mdel.c line 32, 72
- in /usr/src/local/mtools/mdir.c line 33, 68-73(2)
- in /usr/src/local/mtools/mrd.c line 32, 66
- in /usr/src/local/mtools/mread.c line 47, 109
- in /usr/src/local/mtools/mren.c line 30, 55-60(2)
- in /usr/src/local/mtools/mtype.c line 32, 72
- in /usr/src/local/mtools/mwrite.c line 42, 90

get_path defined in line 45; used 21 times

- in /usr/src/local/mtools/mattrib.c line 34, 102
- in /usr/src/local/mtools/mcd.c line 29, 47
- in /usr/src/local/mtools/mdel.c line 32, 73
- in /usr/src/local/mtools/mdir.c line 33, 69-74(2)
- in /usr/src/local/mtools/mmd.c line 34, 83
- in /usr/src/local/mtools/mrd.c line 32, 67
- in /usr/src/local/mtools/mread.c line 48, 110
- in /usr/src/local/mtools/mren.c line 30, 56
- in /usr/src/local/mtools/mtype.c line 33, 73
- in /usr/src/local/mtools/mwrite.c line 43, 91

Last modified: 1992-06-24 Generated: 2016-12-26 | Generated by src2html V0.67 page hit count: 523 |