]>
diplodocus.org Git - nmh/blob - sbr/path.c
1 /* path.c -- return a pathname
3 * This code is Copyright (c) 2002, by the authors of nmh. See the
4 * COPYRIGHT file in the root directory of the nmh distribution for
5 * complete copyright information.
10 #include "m_maildir.h"
22 static char *expath(char *,int);
23 static void compath(char *);
28 return path(name
+ 1, *name
== '+' ? TFOLDER
: TSUBCWF
);
32 path(char *name
, int flag
)
36 if ((cp
= expath (name
, flag
))
37 && (ep
= cp
+ strlen (cp
) - 1) > cp
46 expath (char *name
, int flag
)
51 if (flag
== TSUBCWF
) {
52 snprintf (buffer
, sizeof(buffer
), "%s/%s", getfolder (1), name
);
53 name
= m_mailpath (buffer
);
55 snprintf (buffer
, sizeof(buffer
), "%s/", m_maildir (""));
56 if (ssequal (buffer
, name
)) {
58 name
= mh_xstrdup(name
+ strlen(buffer
));
66 && (!has_prefix(name
, CWD
)
68 && strcmp (name
, DOTDOT
)
69 && !has_prefix(name
, PWD
))))
70 return mh_xstrdup(name
);
75 if (strcmp (name
, DOT
) == 0 || strcmp (name
, CWD
) == 0)
76 return mh_xstrdup(pwds
);
78 ep
= pwds
+ strlen (pwds
);
79 if ((cp
= strrchr(pwds
, '/')) == NULL
)
84 if (has_prefix(name
, CWD
))
87 if (strcmp (name
, DOTDOT
) == 0 || strcmp (name
, PWD
) == 0) {
88 snprintf (buffer
, sizeof(buffer
), "%.*s", (int)(cp
- pwds
), pwds
);
89 return mh_xstrdup(buffer
);
92 if (has_prefix(name
, PWD
))
97 snprintf (buffer
, sizeof(buffer
), "%.*s/%s", (int)(cp
- pwds
), pwds
, name
);
98 return mh_xstrdup(buffer
);
123 for (dp
= cp
; *dp
== '/'; dp
++)
129 if (strcmp (cp
, DOT
) == 0) {
135 if (strcmp (cp
, DOTDOT
) == 0) {
136 for (cp
-= 2; cp
> f
; cp
--)
144 if (has_prefix(cp
, PWD
)) {
145 for (dp
= cp
- 2; dp
> f
; dp
--)
150 strcpy (dp
, cp
+ LEN(PWD
) - 1);
154 if (has_prefix(cp
, CWD
)) {
155 strcpy (cp
- 1, cp
+ LEN(CWD
) - 1);