]>
diplodocus.org Git - nmh/blob - sbr/path.c
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.
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
)
37 if ((cp
= expath (name
, flag
))
38 && (ep
= cp
+ strlen (cp
) - 1) > cp
47 expath (char *name
, int flag
)
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
= mh_xstrdup(name
+ strlen(buffer
));
67 && (!has_prefix(name
, CWD
)
69 && strcmp (name
, DOTDOT
)
70 && !has_prefix(name
, PWD
))))
71 return mh_xstrdup(name
);
76 if (strcmp (name
, DOT
) == 0 || strcmp (name
, CWD
) == 0)
77 return mh_xstrdup(pwds
);
79 ep
= pwds
+ strlen (pwds
);
80 if ((cp
= strrchr(pwds
, '/')) == NULL
)
86 if (has_prefix(name
, CWD
))
89 if (strcmp (name
, DOTDOT
) == 0 || strcmp (name
, PWD
) == 0) {
90 snprintf (buffer
, sizeof(buffer
), "%.*s", (int)(cp
- pwds
), pwds
);
91 return mh_xstrdup(buffer
);
94 if (has_prefix(name
, PWD
))
99 snprintf (buffer
, sizeof(buffer
), "%.*s/%s", (int)(cp
- pwds
), pwds
, name
);
100 return mh_xstrdup(buffer
);
121 for (dp
= cp
; *dp
== '/'; dp
++)
127 if (strcmp (cp
, DOT
) == 0) {
133 if (strcmp (cp
, DOTDOT
) == 0) {
134 for (cp
-= 2; cp
> f
; cp
--)
142 if (has_prefix(cp
, PWD
)) {
143 for (dp
= cp
- 2; dp
> f
; dp
--)
148 strcpy (dp
, cp
+ LEN(PWD
) - 1);
152 if (has_prefix(cp
, CWD
)) {
153 strcpy (cp
- 1, cp
+ LEN(CWD
) - 1);