From 9a2bef433271cd830d318e5b17efc38ac74e34a3 Mon Sep 17 00:00:00 2001 From: Christian Neukirchen Date: Mon, 2 Nov 2015 22:32:48 +0100 Subject: -R to fail when no arguments are passed --- README.md | 6 +++++- xe.c | 11 ++++++++--- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 1940209..631d590 100644 --- a/README.md +++ b/README.md @@ -21,12 +21,13 @@ Over apply: ## Usage: - xe [-0knv] [-I arg] [-N maxargs] [-j maxjobs] COMMAND... + xe [-0Rknv] [-I arg] [-N maxargs] [-j maxjobs] COMMAND... | -s SHELLSCRIPT | -a COMMAND... -- ARGS... | -A ARGSEP COMMAND... ARGSEP ARGS... * `-0`: input filenames are seperated by NUL bytes (default: newlines). +* `-R`: return with status 122 when no arguments have been passed. * `-k`: keep going: don't stop when a command failed to execute. * `-n`: don't run the commands, just print them. * `-v`: print commands before running them. @@ -55,6 +56,9 @@ Like GNU and OpenBSD xargs: * 127 if the command is not found * 1 if some other error occurred. +Additionally, 122 is returned when `-R` is passed and no +input/arguments were passed. + ## Installation Use `make all` to build, `make install` to install relative to `PREFIX` diff --git a/xe.c b/xe.c index 2578b6d..f9c7206 100644 --- a/xe.c +++ b/xe.c @@ -29,7 +29,8 @@ static char *sflag; static int maxatonce = 1; static int maxjobs = 1; static int runjobs = 0; -static int aflag, kflag, nflag, vflag; +static int Rflag, aflag, kflag, nflag, vflag; +static int iterations = 0; static char * xstrdup(const char *s) @@ -143,6 +144,7 @@ run(char *cmd[]) if (runjobs >= maxjobs) mywait(); runjobs++; + iterations++; if (vflag || nflag) trace(cmd); @@ -181,12 +183,13 @@ main(int argc, char *argv[]) int i, cmdend; char *arg, **cmd; - while ((c = getopt(argc, argv, "+0A:I:N:aj:kns:v")) != -1) + while ((c = getopt(argc, argv, "+0A:I:N:Raj:kns:v")) != -1) switch(c) { case '0': delim = '\0'; break; case 'A': argsep = optarg; aflag++; break; case 'I': replace = optarg; break; case 'N': maxatonce = atoi(optarg); break; + case 'R': Rflag++; break; case 'a': aflag++; break; case 'j': maxjobs = atoi(optarg); break; case 'k': kflag++; break; @@ -195,7 +198,7 @@ main(int argc, char *argv[]) case 'v': vflag++; break; default: fprintf(stderr, - "Usage: %s [-0knv] [-I arg] [-N maxargs] [-j maxjobs] COMMAND...\n" + "Usage: %s [-0Rknv] [-I arg] [-N maxargs] [-j maxjobs] COMMAND...\n" " | -s SHELLSCRIPT\n" " | -a COMMAND... -- ARGS...\n" " | -A ARGSEP COMMAND... ARGSEP ARGS...\n", @@ -263,5 +266,7 @@ main(int argc, char *argv[]) free(cmd); free(getarg_line); + if (Rflag && iterations == 0) + return 122; return 0; } -- cgit 1.4.1