1: /* path.c - return a pathname */
   2: 
   3: #include "../h/mh.h"
   4: #include <stdio.h>
   5: 
   6: #define CWD "./"
   7: #define NCWD    (sizeof CWD - 1)
   8: #define DOT "."
   9: #define DOTDOT  ".."
  10: #define PWD "../"
  11: #define NPWD    (sizeof PWD - 1)
  12: 
  13: 
  14: static char *pwds;
  15: 
  16: char   *expath ();
  17: 
  18: 
  19: char   *path (name, flag)
  20: register char   *name;
  21: register int     flag;
  22: {
  23:     register char  *cp,
  24:                    *ep;
  25: 
  26:     if ((cp = expath (name, flag))
  27:         && (ep = cp + strlen (cp) - 1) > cp
  28:         && *ep == '/')
  29:     *ep = NULL;
  30: 
  31:     return cp;
  32: }
  33: 
  34: /*  */
  35: 
  36: static  char   *expath (name, flag)
  37: register char   *name;
  38: register int     flag;
  39: {
  40:     register char  *cp,
  41:                    *ep;
  42:     char    buffer[BUFSIZ];
  43: 
  44:     if (flag == TSUBCWF) {
  45:     (void) sprintf (buffer, "%s/%s", m_getfolder (), name);
  46:     name = m_mailpath (buffer);
  47:     compath (name);
  48:     (void) sprintf (buffer, "%s/", m_maildir (""));
  49:     if (ssequal (buffer, name)) {
  50:         cp = name;
  51:         name = getcpy (name + strlen (buffer));
  52:         free (cp);
  53:     }
  54:     flag = TFOLDER;
  55:     }
  56: 
  57:     if (*name == '/'
  58:         || (flag == TFOLDER
  59:         && (strncmp (name, CWD, NCWD)
  60:             && strcmp (name, DOT)
  61:             && strcmp (name, DOTDOT)
  62:             && strncmp (name, PWD, NPWD))))
  63:     return getcpy (name);
  64: 
  65:     if (pwds == NULL)
  66:     pwds = pwd ();
  67: 
  68:     if (strcmp (name, DOT) == 0 || strcmp (name, CWD) == 0)
  69:     return getcpy (pwds);
  70: 
  71:     ep = pwds + strlen (pwds);
  72:     if ((cp = rindex (pwds, '/')) == NULL)
  73:     cp = ep;
  74:     else
  75:     if (cp == pwds)
  76:         cp++;
  77: 
  78:     if (strncmp (name, CWD, NCWD) == 0)
  79:     name += NCWD;
  80: 
  81:     if (strcmp (name, DOTDOT) == 0 || strcmp (name, PWD) == 0) {
  82:     (void) sprintf (buffer, "%.*s", cp - pwds, pwds);
  83:     return getcpy (buffer);
  84:     }
  85: 
  86:     if (strncmp (name, PWD, NPWD) == 0)
  87:     name += NPWD;
  88:     else
  89:     cp = ep;
  90: 
  91:     (void) sprintf (buffer, "%.*s/%s", cp - pwds, pwds, name);
  92:     return getcpy (buffer);
  93: }
  94: 
  95: /*  */
  96: 
  97: static  compath (f)
  98: register char  *f;
  99: {
 100:     register char  *cp,
 101:                    *dp;
 102: 
 103:     if (*f != '/')
 104:     return;
 105: 
 106:     for (cp = f; *cp;)
 107:     if (*cp == '/') {
 108:         switch (*++cp) {
 109:         case NULL:
 110:             if (--cp > f)
 111:             *cp = NULL;
 112:             break;
 113: 
 114:         case '/':
 115:             for (dp = cp; *dp == '/'; dp++)
 116:             continue;
 117:             (void) strcpy (cp--, dp);
 118:             continue;
 119: 
 120:         case '.':
 121:             if (strcmp (cp, DOT) == 0) {
 122:             if (cp > f + 1)
 123:                 cp--;
 124:             *cp = NULL;
 125:             break;
 126:             }
 127:             if (strcmp (cp, DOTDOT) == 0) {
 128:             for (cp -= 2; cp > f; cp--)
 129:                 if (*cp == '/')
 130:                 break;
 131:             if (cp <= f)
 132:                 cp = f + 1;
 133:             *cp = NULL;
 134:             break;
 135:             }
 136:             if (strncmp (cp, PWD, NPWD) == 0) {
 137:             for (dp = cp - 2; dp > f; dp--)
 138:                 if (*dp == '/')
 139:                 break;
 140:             if (dp <= f)
 141:                 dp = f;
 142:             (void) strcpy (dp, cp + NPWD - 1);
 143:             cp = dp;
 144:             continue;
 145:             }
 146:             if (strncmp (cp, CWD, NCWD) == 0) {
 147:             (void) strcpy (cp - 1, cp + NCWD - 1);
 148:             cp--;
 149:             continue;
 150:             }
 151:             continue;
 152: 
 153:         default:
 154:             cp++;
 155:             continue;
 156:         }
 157:         break;
 158:     }
 159:     else
 160:         cp++;
 161: }

Defined functions

compath defined in line 97; used 1 times
  • in line 47
expath defined in line 36; used 2 times

Defined variables

pwds defined in line 14; used 11 times

Defined macros

CWD defined in line 6; used 5 times
DOT defined in line 8; used 3 times
DOTDOT defined in line 9; used 3 times
NCWD defined in line 7; used 5 times
NPWD defined in line 11; used 5 times
PWD defined in line 10; used 5 times
Last modified: 1985-09-08
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 707
Valid CSS Valid XHTML 1.0 Strict