3 * path.c -- return a pathname
5 * This code is Copyright (c) 2002, by the authors of nmh. See the
6 * COPYRIGHT file in the root directory of the nmh distribution for
7 * complete copyright information.
13 #define NCWD (sizeof(CWD) - 1)
17 #define NPWD (sizeof(PWD) - 1)
24 static char *expath(char *,int);
25 static void compath(char *);
30 return path(name + 1, *name == '+' ? TFOLDER : TSUBCWF);
34 path(char *name, int flag)
36 register char *cp, *ep;
38 if ((cp = expath (name, flag))
39 && (ep = cp + strlen (cp) - 1) > cp
48 expath (char *name, int flag)
50 register char *cp, *ep;
53 if (flag == TSUBCWF) {
54 snprintf (buffer, sizeof(buffer), "%s/%s", getfolder (1), name);
55 name = m_mailpath (buffer);
57 snprintf (buffer, sizeof(buffer), "%s/", m_maildir (""));
58 if (ssequal (buffer, name)) {
60 name = getcpy (name + strlen (buffer));
68 && (strncmp (name, CWD, NCWD)
70 && strcmp (name, DOTDOT)
71 && strncmp (name, PWD, NPWD))))
77 if (strcmp (name, DOT) == 0 || strcmp (name, CWD) == 0)
80 ep = pwds + strlen (pwds);
81 if ((cp = strrchr(pwds, '/')) == NULL)
87 if (strncmp (name, CWD, NCWD) == 0)
90 if (strcmp (name, DOTDOT) == 0 || strcmp (name, PWD) == 0) {
91 snprintf (buffer, sizeof(buffer), "%.*s", (int)(cp - pwds), pwds);
92 return getcpy (buffer);
95 if (strncmp (name, PWD, NPWD) == 0)
100 snprintf (buffer, sizeof(buffer), "%.*s/%s", (int)(cp - pwds), pwds, name);
101 return getcpy (buffer);
108 register char *cp, *dp;
122 for (dp = cp; *dp == '/'; dp++)
128 if (strcmp (cp, DOT) == 0) {
134 if (strcmp (cp, DOTDOT) == 0) {
135 for (cp -= 2; cp > f; cp--)
143 if (strncmp (cp, PWD, NPWD) == 0) {
144 for (dp = cp - 2; dp > f; dp--)
149 strcpy (dp, cp + NPWD - 1);
153 if (strncmp (cp, CWD, NCWD) == 0) {
154 strcpy (cp - 1, cp + NCWD - 1);