]> diplodocus.org Git - nmh/blobdiff - sbr/path.c
context_find.c: Move interface to own file.
[nmh] / sbr / path.c
index 3038df413f4755c8dbfbdf90f0664ee9c9542dea..d425dc8bb6cb59ea7ceac9f1745af422464e1fc7 100644 (file)
@@ -5,8 +5,9 @@
  * complete copyright information.
  */
 
  * complete copyright information.
  */
 
-#include <h/mh.h>
-#include <h/utils.h>
+#include "h/mh.h"
+#include "path.h"
+#include "h/utils.h"
 #include "m_maildir.h"
 
 #define        CWD     "./"
 #include "m_maildir.h"
 
 #define        CWD     "./"
@@ -22,26 +23,31 @@ static char *pwds;
 static char *expath(char *,int);
 static void compath(char *);
 
 static char *expath(char *,int);
 static void compath(char *);
 
+
+/* Return value must be free(3)'d. */
 char *
 pluspath(char *name)
 {
        return path(name + 1, *name == '+' ? TFOLDER : TSUBCWF);
 }
 
 char *
 pluspath(char *name)
 {
        return path(name + 1, *name == '+' ? TFOLDER : TSUBCWF);
 }
 
+
+/* Return value must be free(3)'d. */
 char *
 path(char *name, int flag)
 {
 char *
 path(char *name, int flag)
 {
-    char *cp, *ep;
+    char *p, *last;
 
 
-    if ((cp = expath (name, flag))
-           && (ep = cp + strlen (cp) - 1) > cp
-           && *ep == '/')
-       *ep = '\0';
+    p = expath(name, flag);
+    last = p + strlen(p) - 1;
+    if (last > p && *last == '/')
+       *last = '\0';
 
 
-    return cp;
+    return p;
 }
 
 
 }
 
 
+/* Return value must be free(3)'d. */
 static char *
 expath (char *name, int flag)
 {
 static char *
 expath (char *name, int flag)
 {
@@ -78,9 +84,8 @@ expath (char *name, int flag)
     ep = pwds + strlen (pwds);
     if ((cp = strrchr(pwds, '/')) == NULL)
        cp = ep;
     ep = pwds + strlen (pwds);
     if ((cp = strrchr(pwds, '/')) == NULL)
        cp = ep;
-    else
-       if (cp == pwds)
-           cp++;
+    else if (cp == pwds)
+        cp++;
 
     if (has_prefix(name, CWD))
        name += LEN(CWD);
 
     if (has_prefix(name, CWD))
        name += LEN(CWD);