diff --git a/xargs.c b/xargs.c index b0c43b5..66087cf 100644 --- a/xargs.c +++ b/xargs.c @@ -19,7 +19,7 @@ static int eatspace(void); static int parsequote(int); static int parseescape(void); static char *poparg(void); -static void pusharg(char *); +static void deinputstr(char *); static void waitchld(void); static void runcmd(void); @@ -86,7 +86,7 @@ main(int argc, char *argv[]) i >= NARGS - 1) { if (strlen(arg) + 1 > argmaxsz) enprintf(EXIT_FAILURE, "insufficient argument space\n"); - pusharg(arg); + deinputstr(arg); break; } cmd[i] = strdup(arg); @@ -122,6 +122,15 @@ deinputc(int ch) ungetc(ch, stdin); } +static void +deinputstr(char *arg) +{ + char *p; + + for (p = &arg[strlen(arg) - 1]; p >= arg; p--) + deinputc(*p); +} + static void fillargbuf(int ch) { @@ -157,10 +166,8 @@ parsequote(int q) int ch; while ((ch = inputc()) != EOF) { - if (ch == q) { - fillargbuf('\0'); + if (ch == q) return 0; - } if (ch != '\n') { fillargbuf(ch); argbpos++; @@ -225,15 +232,6 @@ out: return NULL; } -static void -pusharg(char *arg) -{ - char *p; - - for (p = &arg[strlen(arg) - 1]; p >= arg; p--) - deinputc(*p); -} - static void waitchld(void) {