From 455af9b13df39ccc2a1bb00484b05689c8452805 Mon Sep 17 00:00:00 2001 From: Leah Neukirchen Date: Thu, 2 Nov 2017 14:09:05 +0100 Subject: properly distinguish both main loops --- xe.c | 106 +++++++++++++++++++++++++++++++++---------------------------------- 1 file changed, 53 insertions(+), 53 deletions(-) (limited to 'xe.c') diff --git a/xe.c b/xe.c index afdf174..462b147 100644 --- a/xe.c +++ b/xe.c @@ -674,6 +674,8 @@ main(int argc, char *argv[], char *envp[]) } } + int keeparg = 0; + if (pflag) { if (maxatonce != 1) { fprintf(stderr, @@ -719,68 +721,66 @@ main(int argc, char *argv[], char *envp[]) } } } - // done with args, so default execution will do nothing - } + } else { + while (1) { + // check if there is an arg from a previous iteration + if (!keeparg) { + while (runjobs >= maxjobs) + mywait(); - int keeparg = 0; - while (1) { - // check if there is an arg from a previous iteration - if (!keeparg) { - while (runjobs >= maxjobs) - mywait(); + arg = getarg(); + if (!arg) + break; + } + keeparg = 0; - arg = getarg(); - if (!arg) - break; - } - keeparg = 0; - - buflen = 0; - argslen = 0; - - if (sflag) { - pusharg("/bin/sh"); - pusharg("-c"); - pusharg(sflag); - pusharg("/bin/sh"); - } else if (optind >= cmdend) { - pusharg("printf"); - pusharg("%s\\n"); - } + buflen = 0; + argslen = 0; - for (i = optind; i < cmdend; i++) { - if (*replace && strcmp(argv[i], replace) == 0) - break; - if (!pusharg(argv[i])) - toolong(); - } + if (sflag) { + pusharg("/bin/sh"); + pusharg("-c"); + pusharg(sflag); + pusharg("/bin/sh"); + } else if (optind >= cmdend) { + pusharg("printf"); + pusharg("%s\\n"); + } - if (!pusharg(arg)) - toolong(); - i++; + for (i = optind; i < cmdend; i++) { + if (*replace && strcmp(argv[i], replace) == 0) + break; + if (!pusharg(argv[i])) + toolong(); + } - // reserve space for final arguments - for (argsresv = 0, j = i; j < cmdend; j++) - argsresv += 1 + strlen(argv[j]); + if (!pusharg(arg)) + toolong(); + i++; - // fill with up to maxatonce arguments - for (j = 0; maxatonce < 1 || j < maxatonce-1; j++) { - arg = getarg(); - if (!arg) - break; - if (!pusharg(arg)) { - // we are out of space, - // deal with this arg in the next iteration - keeparg = 1; - break; + // reserve space for final arguments + for (argsresv = 0, j = i; j < cmdend; j++) + argsresv += 1 + strlen(argv[j]); + + // fill with up to maxatonce arguments + for (j = 0; maxatonce < 1 || j < maxatonce-1; j++) { + arg = getarg(); + if (!arg) + break; + if (!pusharg(arg)) { + // we are out of space, + // deal with this arg in the next iter + keeparg = 1; + break; + } } - } - for (argsresv = 0, j = i; j < cmdend; j++) - if (!pusharg(argv[j])) - toolong(); + for (argsresv = 0, j = i; j < cmdend; j++) + if (!pusharg(argv[j])) + toolong(); - run(); + run(); + } } while (mywait()) -- cgit 1.4.1