Rearranged code in the file.
authormarkus schnalke <meillo@marmaro.de>
Sat, 5 Nov 2011 16:51:30 +0000 (17:51 +0100)
committermarkus schnalke <meillo@marmaro.de>
Sat, 5 Nov 2011 16:51:30 +0000 (17:51 +0100)
sbr/path.c

index 3b633d0..8802eaa 100644 (file)
 
 static char *pwds;
 
+
 /*
-** static prototypes
+**  Compactify an absolute path name by removing unneccessary parts.
+**  Removes trailing slashes, but not if it would empty the string then.
+**  Modifies f.
 */
-static char *expath(char *, int);
-static void packpath(char *);
-
-char *
-pluspath(char *name)
+static void
+packpath(char *f)
 {
-       return path(name + 1, *name == '+' ? TFOLDER : TSUBCWF);
-}
+       char *cp, *dp;
+       int abspath;
 
-char *
-path(char *name, int type)
-{
-       char *cp, *ep;
+       if (!f || !*f) {
+               return;
+       }
+       abspath = (*f == '/');
 
-       if ((cp = expath(name, type)) &&
-                       (ep = cp+strlen(cp)-1) > cp &&
-                       *ep == '/') {
-               *ep = '\0';
+       for (cp=f; *cp; ) {
+               if (*cp != '/') {
+                       /* Skip. Interesting places are only after slashes. */
+                       /* We don't care about "./" beginnings */
+                       cp++;
+                       continue;
+               }
+
+               /* Let's see what follows the slash ... */
+               switch (*++cp) {
+               case '\0':
+                       *--cp = '\0';
+                       continue;  /* ... and thus exit the loop */
+
+               case '/':
+                       /* reduce subsequent slashes to one */
+                       for (dp = cp; *dp == '/'; dp++) {
+                               continue;
+                       }
+                       strcpy(cp, dp);
+                       cp--;
+                       continue;  /* ... at the slash */
+
+               case '.':
+                       if (cp[1] == '/' || cp[1] == '\0') {
+                               /* one-dot element */
+                               strcpy(cp-1, cp+1);
+                               cp--;
+                               continue;
+                       } else if ((strncmp(cp, "../", 3) == 0) ||
+                                       (strcmp(cp, "..") == 0)) {
+                               /* dot-dot element */
+                               /* crop out previous path element */
+                               for (dp=cp-2; dp>f && *dp!='/'; dp--) {
+                                       continue;
+                               }
+                               if (dp < f) {
+                                       /* path starts with "/.." */
+                                       dp = f;
+                               }
+                               strcpy(dp, cp+2);
+                               cp = dp;
+                               continue;
+                       } else {
+                               /* a normal hidden file */
+                               cp++;
+                               continue;
+                       }
+
+               default:
+                       /* nothing special */
+                       cp++;
+                       continue;
+               }
        }
 
-       return cp;
+       if (!strlen(f)) {
+               /* We have removed everything, but need something. */
+               strcpy(f, abspath ? "/" : ".");
+       }
 }
 
 
+/*
+**
+*/
 static char *
 expath(char *name, int type)
 {
@@ -109,79 +165,28 @@ expath(char *name, int type)
 
 
 /*
-**  Compactify an absolute path name by removing unneccessary parts.
-**  Removes trailing slashes, but not if it would empty the string then.
-**  Modifies f.
+**
 */
-static void
-packpath(char *f)
+char *
+path(char *name, int type)
 {
-       char *cp, *dp;
-       int abspath;
+       char *cp, *ep;
 
-       if (!f || !*f) {
-               return;
+       if ((cp = expath(name, type)) &&
+                       (ep = cp+strlen(cp)-1) > cp &&
+                       *ep == '/') {
+               *ep = '\0';
        }
-       abspath = (*f == '/');
-
-       for (cp=f; *cp; ) {
-               if (*cp != '/') {
-                       /* Skip. Interesting places are only after slashes. */
-                       /* We don't care about "./" beginnings */
-                       cp++;
-                       continue;
-               }
-
-               /* Let's see what follows the slash ... */
-               switch (*++cp) {
-               case '\0':
-                       *--cp = '\0';
-                       continue;  /* ... and thus exit the loop */
-
-               case '/':
-                       /* reduce subsequent slashes to one */
-                       for (dp = cp; *dp == '/'; dp++) {
-                               continue;
-                       }
-                       strcpy(cp, dp);
-                       cp--;
-                       continue;  /* ... at the slash */
 
-               case '.':
-                       if (cp[1] == '/' || cp[1] == '\0') {
-                               /* one-dot element */
-                               strcpy(cp-1, cp+1);
-                               cp--;
-                               continue;
-                       } else if ((strncmp(cp, "../", 3) == 0) ||
-                                       (strcmp(cp, "..") == 0)) {
-                               /* dot-dot element */
-                               /* crop out previous path element */
-                               for (dp=cp-2; dp>f && *dp!='/'; dp--) {
-                                       continue;
-                               }
-                               if (dp < f) {
-                                       /* path starts with "/.." */
-                                       dp = f;
-                               }
-                               strcpy(dp, cp+2);
-                               cp = dp;
-                               continue;
-                       } else {
-                               /* a normal hidden file */
-                               cp++;
-                               continue;
-                       }
+       return cp;
+}
 
-               default:
-                       /* nothing special */
-                       cp++;
-                       continue;
-               }
-       }
 
-       if (!strlen(f)) {
-               /* We have removed everything, but need something. */
-               strcpy(f, abspath ? "/" : ".");
-       }
+/*
+** Call path() appropriately for ``+folder'' or ``@folder''
+*/
+char *
+pluspath(char *name)
+{
+       return path(name+1, (*name == '+') ? TFOLDER : TSUBCWF);
 }