diff options
-rwxr-xr-x | tests | 8 | ||||
-rw-r--r-- | xe.c | 21 |
2 files changed, 23 insertions, 6 deletions
diff --git a/tests b/tests index 2e92b79..07b68e1 100755 --- a/tests +++ b/tests @@ -1,5 +1,5 @@ #!/bin/sh -printf '1..43\n' +printf '1..44\n' set -e @@ -175,6 +175,12 @@ check_output 'with ITER' '$XE -a -s "echo \$ITER" -- a b c' <<EOF 3 EOF +check_output 'is eager' '{ echo 1; sleep 1; echo 11 >/dev/stderr; echo 2; } | xe echo' <<EOF +1 +11 +2 +EOF + printf '# error handling\n' check_output 'exit code on success' 'true | $XE; echo $?' <<EOF diff --git a/xe.c b/xe.c index a660435..2825396 100644 --- a/xe.c +++ b/xe.c @@ -349,8 +349,16 @@ main(int argc, char *argv[], char *envp[]) } } - arg = getarg(); - while (arg) { + int keeparg = 0; + while (1) { + // check if there is an arg from a previous iteration + if (!keeparg) { + arg = getarg(); + if (!arg) + break; + } + keeparg = 0; + buflen = 0; argslen = 0; @@ -373,7 +381,6 @@ main(int argc, char *argv[], char *envp[]) if (!pusharg(arg)) toolong(); - arg = getarg(); i++; // reserve space for final arguments @@ -382,11 +389,15 @@ main(int argc, char *argv[], char *envp[]) // fill with up to maxatonce arguments for (j = 0; maxatonce < 1 || j < maxatonce-1; j++) { + arg = getarg(); if (!arg) break; - if (!pusharg(arg)) + if (!pusharg(arg)) { + // we are out of space, + // deal with this arg in the next iteration + keeparg = 1; break; - arg = getarg(); + } } for (argsresv = 0, j = i; j < cmdend; j++) |