2 ** path.c -- return a pathname
4 ** This code is Copyright (c) 2002, by the authors of nmh. See the
5 ** COPYRIGHT file in the root directory of the nmh distribution for
6 ** complete copyright information.
12 #define NCWD (sizeof(CWD) - 1)
16 #define NPWD (sizeof(PWD) - 1)
23 static char *expath(char *,int);
24 static void compath(char *);
29 return path(name + 1, *name == '+' ? TFOLDER : TSUBCWF);
33 path(char *name, int flag)
35 register char *cp, *ep;
37 if ((cp = expath(name, flag))
38 && (ep = cp + strlen(cp) - 1) > cp
47 expath(char *name, int flag)
49 register char *cp, *ep;
52 if (flag == TSUBCWF) {
53 snprintf(buffer, sizeof(buffer), "%s/%s", getfolder(1), name);
54 name = m_mailpath(buffer);
56 snprintf(buffer, sizeof(buffer), "%s/", m_maildir(""));
57 if (ssequal(buffer, name)) {
59 name = getcpy(name + strlen(buffer));
65 if (*name == '/' || (flag == TFOLDER
66 && (strncmp(name, CWD, NCWD) && strcmp(name, DOT)
67 && strcmp(name, DOTDOT) && strncmp(name, PWD, NPWD))))
73 if (strcmp(name, DOT) == 0 || strcmp(name, CWD) == 0)
76 ep = pwds + strlen(pwds);
77 if ((cp = strrchr(pwds, '/')) == NULL)
83 if (strncmp(name, CWD, NCWD) == 0)
86 if (strcmp(name, DOTDOT) == 0 || strcmp(name, PWD) == 0) {
87 snprintf(buffer, sizeof(buffer), "%.*s", (int)(cp - pwds), pwds);
88 return getcpy(buffer);
91 if (strncmp(name, PWD, NPWD) == 0)
96 snprintf(buffer, sizeof(buffer), "%.*s/%s", (int)(cp - pwds), pwds, name);
97 return getcpy(buffer);
104 register char *cp, *dp;
118 for (dp = cp; *dp == '/'; dp++)
124 if (strcmp(cp, DOT) == 0) {
130 if (strcmp(cp, DOTDOT) == 0) {
131 for (cp -= 2; cp > f; cp--)
139 if (strncmp(cp, PWD, NPWD) == 0) {
140 for (dp = cp - 2; dp > f; dp--)
145 strcpy(dp, cp + NPWD - 1);
149 if (strncmp(cp, CWD, NCWD) == 0) {
150 strcpy(cp - 1, cp + NCWD - 1);