]>
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.
14 #define NCWD (sizeof(CWD) - 1)
18 #define NPWD (sizeof(PWD) - 1)
25 static char *expath(char *,int);
26 static void compath(char *);
31 return path(name
+ 1, *name
== '+' ? TFOLDER
: TSUBCWF
);
35 path(char *name
, int flag
)
39 if ((cp
= expath (name
, flag
))
40 && (ep
= cp
+ strlen (cp
) - 1) > cp
49 expath (char *name
, int flag
)
54 if (flag
== TSUBCWF
) {
55 snprintf (buffer
, sizeof(buffer
), "%s/%s", getfolder (1), name
);
56 name
= m_mailpath (buffer
);
58 snprintf (buffer
, sizeof(buffer
), "%s/", m_maildir (""));
59 if (ssequal (buffer
, name
)) {
61 name
= mh_xstrdup(name
+ strlen(buffer
));
69 && (strncmp (name
, CWD
, NCWD
)
71 && strcmp (name
, DOTDOT
)
72 && strncmp (name
, PWD
, NPWD
))))
73 return mh_xstrdup(name
);
78 if (strcmp (name
, DOT
) == 0 || strcmp (name
, CWD
) == 0)
79 return mh_xstrdup(pwds
);
81 ep
= pwds
+ strlen (pwds
);
82 if ((cp
= strrchr(pwds
, '/')) == NULL
)
88 if (strncmp (name
, CWD
, NCWD
) == 0)
91 if (strcmp (name
, DOTDOT
) == 0 || strcmp (name
, PWD
) == 0) {
92 snprintf (buffer
, sizeof(buffer
), "%.*s", (int)(cp
- pwds
), pwds
);
93 return mh_xstrdup(buffer
);
96 if (strncmp (name
, PWD
, NPWD
) == 0)
101 snprintf (buffer
, sizeof(buffer
), "%.*s/%s", (int)(cp
- pwds
), pwds
, name
);
102 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 (strncmp (cp
, PWD
, NPWD
) == 0) {
145 for (dp
= cp
- 2; dp
> f
; dp
--)
150 strcpy (dp
, cp
+ NPWD
- 1);
154 if (strncmp (cp
, CWD
, NCWD
) == 0) {
155 strcpy (cp
- 1, cp
+ NCWD
- 1);