X-Git-Url: https://diplodocus.org/git/nmh/blobdiff_plain/0c1ab746fc2890dbabb7a0de58fd71fa6eee1c42..9218e2cd90aabd1d559b2bd0a594a92f72e92447:/sbr/path.c diff --git a/sbr/path.c b/sbr/path.c index 8f6bd55f..3038df41 100644 --- a/sbr/path.c +++ b/sbr/path.c @@ -1,6 +1,4 @@ - -/* - * path.c -- return a pathname +/* path.c -- return a pathname * * This code is Copyright (c) 2002, by the authors of nmh. See the * COPYRIGHT file in the root directory of the nmh distribution for @@ -9,6 +7,7 @@ #include #include +#include "m_maildir.h" #define CWD "./" #define DOT "." @@ -64,10 +63,10 @@ expath (char *name, int flag) if (*name == '/' || (flag == TFOLDER - && (!HasPrefix(name, CWD) + && (!has_prefix(name, CWD) && strcmp (name, DOT) && strcmp (name, DOTDOT) - && !HasPrefix(name, PWD)))) + && !has_prefix(name, PWD)))) return mh_xstrdup(name); if (pwds == NULL) @@ -83,7 +82,7 @@ expath (char *name, int flag) if (cp == pwds) cp++; - if (HasPrefix(name, CWD)) + if (has_prefix(name, CWD)) name += LEN(CWD); if (strcmp (name, DOTDOT) == 0 || strcmp (name, PWD) == 0) { @@ -91,7 +90,7 @@ expath (char *name, int flag) return mh_xstrdup(buffer); } - if (HasPrefix(name, PWD)) + if (has_prefix(name, PWD)) name += LEN(PWD); else cp = ep; @@ -109,59 +108,60 @@ compath (char *f) if (*f != '/') return; - for (cp = f; *cp;) - if (*cp == '/') { - switch (*++cp) { - case 0: - if (--cp > f) - *cp = '\0'; - break; - - case '/': - for (dp = cp; *dp == '/'; dp++) - continue; - strcpy (cp--, dp); - continue; - - case '.': - if (strcmp (cp, DOT) == 0) { - if (cp > f + 1) - cp--; - *cp = '\0'; - break; - } - if (strcmp (cp, DOTDOT) == 0) { - for (cp -= 2; cp > f; cp--) - if (*cp == '/') - break; - if (cp <= f) - cp = f + 1; - *cp = '\0'; - break; - } - if (HasPrefix(cp, PWD)) { - for (dp = cp - 2; dp > f; dp--) - if (*dp == '/') - break; - if (dp <= f) - dp = f; - strcpy (dp, cp + LEN(PWD) - 1); - cp = dp; - continue; - } - if (HasPrefix(cp, CWD)) { - strcpy (cp - 1, cp + LEN(CWD) - 1); - cp--; - continue; - } - continue; - - default: - cp++; - continue; - } - break; - } - else + for (cp = f; *cp;) { + if (*cp != '/') { cp++; + continue; + } + + switch (*++cp) { + case 0: + if (--cp > f) + *cp = '\0'; + return; + + case '/': + for (dp = cp; *dp == '/'; dp++) + continue; + strcpy (cp--, dp); + continue; + + case '.': + if (strcmp (cp, DOT) == 0) { + if (cp > f + 1) + cp--; + *cp = '\0'; + return; + } + if (strcmp (cp, DOTDOT) == 0) { + for (cp -= 2; cp > f; cp--) + if (*cp == '/') + break; + if (cp <= f) + cp = f + 1; + *cp = '\0'; + return; + } + if (has_prefix(cp, PWD)) { + for (dp = cp - 2; dp > f; dp--) + if (*dp == '/') + break; + if (dp <= f) + dp = f; + strcpy (dp, cp + LEN(PWD) - 1); + cp = dp; + continue; + } + if (has_prefix(cp, CWD)) { + strcpy (cp - 1, cp + LEN(CWD) - 1); + cp--; + continue; + } + continue; + + default: + cp++; + continue; + } + } }