about summary refs log tree commit diff
path: root/xe.c
diff options
context:
space:
mode:
authorLeah Neukirchen <leah@vuxu.org>2017-11-02 14:09:05 +0100
committerLeah Neukirchen <leah@vuxu.org>2017-11-02 14:09:05 +0100
commit455af9b13df39ccc2a1bb00484b05689c8452805 (patch)
treee23eb6a9b66965f87b28e14cec9c096ecfad9c20 /xe.c
parent958c9fb4320820859e6ed6f1daf6010681b6864c (diff)
downloadxe-455af9b13df39ccc2a1bb00484b05689c8452805.tar.gz
xe-455af9b13df39ccc2a1bb00484b05689c8452805.tar.xz
xe-455af9b13df39ccc2a1bb00484b05689c8452805.zip
properly distinguish both main loops
Diffstat (limited to 'xe.c')
-rw-r--r--xe.c106
1 files changed, 53 insertions, 53 deletions
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())