diff options
author | Leah Neukirchen <leah@vuxu.org> | 2017-05-19 17:13:14 +0200 |
---|---|---|
committer | Leah Neukirchen <leah@vuxu.org> | 2017-05-19 17:13:14 +0200 |
commit | 00164de3bc60ad362d97631d4b5dbc66b2d3c96b (patch) | |
tree | b4e1e18adc56063b2569bb877f15d8918c964188 /xe.c | |
parent | a240ad0707f96e8b205678aaedd813f95122199c (diff) | |
download | xe-00164de3bc60ad362d97631d4b5dbc66b2d3c96b.tar.gz xe-00164de3bc60ad362d97631d4b5dbc66b2d3c96b.tar.xz xe-00164de3bc60ad362d97631d4b5dbc66b2d3c96b.zip |
xe: revise logic to only read new arguments when we immediately need them
This changes behavior on pipes that are written slowly, else there is a one-line delay between executions.
Diffstat (limited to 'xe.c')
-rw-r--r-- | xe.c | 21 |
1 files changed, 16 insertions, 5 deletions
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++) |