Skip to content

Commit

Permalink
mlist: extract squeeze_slash
Browse files Browse the repository at this point in the history
  • Loading branch information
leahneukirchen committed Jul 12, 2017
1 parent 73d80d8 commit 157542c
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 11 deletions.
1 change: 1 addition & 0 deletions GNUmakefile
Original file line number Diff line number Diff line change
Expand Up @@ -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' \
Expand Down
3 changes: 3 additions & 0 deletions blaze822.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 *);
12 changes: 1 addition & 11 deletions mlist.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
15 changes: 15 additions & 0 deletions squeeze_slash.c
Original file line number Diff line number Diff line change
@@ -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;
}

0 comments on commit 157542c

Please sign in to comment.