diff options
Diffstat (limited to 'toys/posix')
-rw-r--r-- | toys/posix/paste.c | 17 | ||||
-rw-r--r-- | toys/posix/xargs.c | 8 |
2 files changed, 16 insertions, 9 deletions
diff --git a/toys/posix/paste.c b/toys/posix/paste.c index 92a52534..0e170cdb 100644 --- a/toys/posix/paste.c +++ b/toys/posix/paste.c @@ -28,28 +28,26 @@ GLOBALS( void paste_main(void) { - char *p, *buf = toybuf; - char **args = toys.optargs; + char *p, *buf = toybuf, **args = toys.optargs; size_t ndelim = 0; int i, j, c; // Process delimiter list // TODO: Handle multibyte characters if (!(toys.optflags & FLAG_d)) TT.delim = "\t"; - p = TT.delim; - for (; *p; p++, buf++, ndelim++) { + for (p = TT.delim; *p; p++, buf++, ndelim++) { if (*p == '\\') { p++; if (-1 == (i = stridx("nt\\0", *p))) error_exit("bad delimiter: \\%c", *p); *buf = "\n\t\\\0"[i]; - } - else *buf = *p; + } else *buf = *p; } *buf = 0; if (toys.optflags & FLAG_s) { // Sequential FILE *f; + for (; *args; args++) { if ((*args)[0] == '-' && !(*args)[1]) f = stdin; else if (!(f = fopen(*args, "r"))) perror_exit("%s", *args); @@ -66,20 +64,21 @@ void paste_main(void) if (f != stdin) fclose(f); putchar('\n'); } - } - else { // Parallel + } else { // Parallel // Need to be careful not to print an extra line at the end FILE **files; int anyopen = 1; + files = (FILE**)(buf + 1); for (; *args; args++, files++) { if ((*args)[0] == '-' && !(*args)[1]) *files = stdin; else if (!(*files = fopen(*args, "r"))) perror_exit("%s", *args); } - for (; anyopen;) { + while (anyopen) { anyopen = 0; for (i = 0; i < toys.optc; i++) { FILE **f = (FILE**)(buf + 1) + i; + if (*f) for (;;) { c = getc(*f); if (c != EOF) { diff --git a/toys/posix/xargs.c b/toys/posix/xargs.c index 18b70f2e..e1611ec3 100644 --- a/toys/posix/xargs.c +++ b/toys/posix/xargs.c @@ -25,6 +25,14 @@ config XARGS #-r Don't run command with empty input #-L Max number of lines of input per command -E stop at line matching string + +config XARGS_PEDANTIC + bool "TODO xargs pedantic posix compatability" + default n + depends on XARGS + help + This version supports insane posix whitespace handling rendered obsolete + by -0 mode. */ #define FOR_xargs |