aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLeah Neukirchen <leah@vuxu.org>2017-07-12 22:31:01 +0200
committerLeah Neukirchen <leah@vuxu.org>2017-07-12 22:31:01 +0200
commit157542c3e7dd3eb89401bd3a8397693d4818efd8 (patch)
tree497baab029592636a4c53b50c5b01aae776e4b2a
parent73d80d80f98436aff9b3ce8b99089d5f909e7c63 (diff)
downloadmblaze-157542c3e7dd3eb89401bd3a8397693d4818efd8.tar.gz
mlist: extract squeeze_slash
-rw-r--r--GNUmakefile1
-rw-r--r--blaze822.h3
-rw-r--r--mlist.c12
-rw-r--r--squeeze_slash.c15
4 files changed, 20 insertions, 11 deletions
diff --git a/GNUmakefile b/GNUmakefile
index 0058e81..a6062ee 100644
--- a/GNUmakefile
+++ b/GNUmakefile
@@ -33,6 +33,7 @@ mshow : filter.o safe_u8putstr.o rfc2231.o pipeto.o
mscan : pipeto.o
msort : mystrverscmp.o
mmime : slurp.o
+mlist : squeeze_slash.o
museragent: FRC
@printf '#!/bin/sh\nprintf "User-Agent: mblaze/%s (%s)\\n"\n' \
diff --git a/blaze822.h b/blaze822.h
index a5cb008..45ee66a 100644
--- a/blaze822.h
+++ b/blaze822.h
@@ -97,3 +97,6 @@ void safe_u8putstr(char *s0, size_t l, FILE *stream);
pid_t pipeto(const char *cmdline);
int pipeclose(pid_t pid);
+// squeeze_slash.c
+
+void squeeze_slash(char *);
diff --git a/mlist.c b/mlist.c
index 8ad53f9..d796fc7 100644
--- a/mlist.c
+++ b/mlist.c
@@ -168,17 +168,7 @@ listdir(char *dir)
void
listarg(char *arg)
{
- char *s, *t;
-
- // squeeze slashes
- s = t = arg;
- while ((*s++ = *t))
- while (*t++ == '/' && *t == '/')
- ;
- // remove trailing slashes
- s--;
- while (*--s == '/')
- *s = 0;
+ squeeze_slash(arg);
struct stat st;
if (stat(arg, &st) < 0)
diff --git a/squeeze_slash.c b/squeeze_slash.c
new file mode 100644
index 0000000..b493cd1
--- /dev/null
+++ b/squeeze_slash.c
@@ -0,0 +1,15 @@
+void
+squeeze_slash(char *arg) {
+ char *s, *t;
+
+ // squeeze slashes
+ s = t = arg;
+ while ((*s++ = *t))
+ while (*t++ == '/' && *t == '/')
+ ;
+
+ // remove trailing slashes
+ s--;
+ while (*--s == '/')
+ *s = 0;
+}