diff options
author | Laurent Bercot <ska-skaware@skarnet.org> | 2024-11-06 08:21:30 +0000 |
---|---|---|
committer | Laurent Bercot <ska@appnovation.com> | 2024-11-06 08:21:30 +0000 |
commit | 916e9e7b4937b4dbe79854c461ae83c45ba33857 (patch) | |
tree | 20ce6f599963678ae47c3c5c7963d10c059c2143 | |
parent | 3d91d9ce645efa020800b85be1ac2727ebcbad19 (diff) | |
download | execline-916e9e7b4937b4dbe79854c461ae83c45ba33857.tar.gz execline-916e9e7b4937b4dbe79854c461ae83c45ba33857.tar.xz execline-916e9e7b4937b4dbe79854c461ae83c45ba33857.zip |
Support -P in forbacktickx as well
Signed-off-by: Laurent Bercot <ska@appnovation.com>
-rw-r--r-- | src/execline/forbacktickx.c | 21 |
1 files changed, 15 insertions, 6 deletions
diff --git a/src/execline/forbacktickx.c b/src/execline/forbacktickx.c index b25095e..f704964 100644 --- a/src/execline/forbacktickx.c +++ b/src/execline/forbacktickx.c @@ -12,24 +12,26 @@ #include <execline/config.h> #include <execline/execline.h> -#define USAGE "forbacktickx [ -p | -o okcode,okcode,... | -x breakcode,breakcode,... ] [ -E | -e ] [ -N | -n ] [ -C | -c ] [ -0 | -d delim ] var { backtickcmd... } command..." +#define USAGE "forbacktickx [ -p | -P maxpar | -o okcode,okcode,... | -x breakcode,breakcode,... ] [ -E | -e ] [ -N | -n ] [ -C | -c ] [ -0 | -d delim ] var { backtickcmd... } command..." #define dieusage() strerr_dieusage(100, USAGE) int main (int argc, char const *const *argv) { char const *delim = "\n" ; char const *codes = 0 ; - int crunch = 0, chomp = 1, not = 1, par = 0, doimport = 0 ; + unsigned int maxpar = 1 ; + int crunch = 0, chomp = 1, not = 1, doimport = 0 ; PROG = "forbacktickx" ; { subgetopt l = SUBGETOPT_ZERO ; for (;;) { - int opt = subgetopt_r(argc, argv, "pNnCc0d:o:x:Ee", &l) ; + int opt = subgetopt_r(argc, argv, "pP:NnCc0d:o:x:Ee", &l) ; if (opt == -1) break ; switch (opt) { - case 'p' : par = 1 ; break ; + case 'p' : maxpar = 0 ; break ; + case 'P' : if (!uint0_scan(l.arg, &maxpar)) dieusage() ; break ; case 'N' : chomp = 0 ; break ; case 'n' : chomp = 1 ; break ; case 'C' : crunch = 1 ; break ; @@ -67,8 +69,9 @@ int main (int argc, char const *const *argv) { unsigned int m = 0, i = 1 ; int fd = dup(0) ; - char const *newargv[argc + 19] ; + char const *newargv[argc + 20] ; char fmt[UINT_FMT] ; + char fmtmaxpar[UINT_FMT] ; if (fd < 0) { if (errno != EBADF) strerr_diefu1sys(111, "dup stdin") ; @@ -84,7 +87,13 @@ int main (int argc, char const *const *argv) newargv[m++] = "!" ; newargv[m++] = EXECLINE_BINPREFIX "forstdin" ; newargv[m++] = doimport ? "-E" : "-e" ; - if (par) newargv[m++] = "-p" ; + if (!maxpar) newargv[m++] = "-p" ; + else if (maxpar > 1) + { + newargv[m++] = "-P" ; + newargv[m++] = fmtmaxpar ; + fmtmaxpar[uint_fmt(fmtmaxpar, maxpar)] = 0 ; + } newargv[m++] = chomp ? "-n" : "-N" ; if (crunch) newargv[m++] = "-C" ; if (!delim) newargv[m++] = "-0" ; |