3 * path.c -- return a pathname
7 * This code is Copyright (c) 2002, by the authors of nmh. See the
8 * COPYRIGHT file in the root directory of the nmh distribution for
9 * complete copyright information.
15 #define NCWD (sizeof(CWD) - 1)
19 #define NPWD (sizeof(PWD) - 1)
26 static char *expath(char *,int);
27 static void compath(char *);
32 return path(name + 1, *name == '+' ? TFOLDER : TSUBCWF);
36 path(char *name, int flag)
38 register char *cp, *ep;
40 if ((cp = expath (name, flag))
41 && (ep = cp + strlen (cp) - 1) > cp
50 expath (char *name, int flag)
52 register char *cp, *ep;
55 if (flag == TSUBCWF) {
56 snprintf (buffer, sizeof(buffer), "%s/%s", getfolder (1), name);
57 name = m_mailpath (buffer);
59 snprintf (buffer, sizeof(buffer), "%s/", m_maildir (""));
60 if (ssequal (buffer, name)) {
62 name = getcpy (name + strlen (buffer));
70 && (strncmp (name, CWD, NCWD)
72 && strcmp (name, DOTDOT)
73 && strncmp (name, PWD, NPWD))))
79 if (strcmp (name, DOT) == 0 || strcmp (name, CWD) == 0)
82 ep = pwds + strlen (pwds);
83 if ((cp = strrchr(pwds, '/')) == NULL)
89 if (strncmp (name, CWD, NCWD) == 0)
92 if (strcmp (name, DOTDOT) == 0 || strcmp (name, PWD) == 0) {
93 snprintf (buffer, sizeof(buffer), "%.*s", (int)(cp - pwds), pwds);
94 return getcpy (buffer);
97 if (strncmp (name, PWD, NPWD) == 0)
102 snprintf (buffer, sizeof(buffer), "%.*s/%s", (int)(cp - pwds), pwds, name);
103 return getcpy (buffer);
110 register char *cp, *dp;
124 for (dp = cp; *dp == '/'; dp++)
130 if (strcmp (cp, DOT) == 0) {
136 if (strcmp (cp, DOTDOT) == 0) {
137 for (cp -= 2; cp > f; cp--)
145 if (strncmp (cp, PWD, NPWD) == 0) {
146 for (dp = cp - 2; dp > f; dp--)
151 strcpy (dp, cp + NPWD - 1);
155 if (strncmp (cp, CWD, NCWD) == 0) {
156 strcpy (cp - 1, cp + NCWD - 1);