diff options
author | Laurent Bercot <ska-skaware@skarnet.org> | 2023-02-28 03:32:47 +0000 |
---|---|---|
committer | Laurent Bercot <ska@appnovation.com> | 2023-02-28 03:32:47 +0000 |
commit | caef85892cd91cdd713562567ab14cb29689f148 (patch) | |
tree | 7668fc440814198bfa476f124ad2a31766342aa0 | |
parent | 6dd30a29f70b246ffc7771d0e79277392834cb71 (diff) | |
download | execline-caef85892cd91cdd713562567ab14cb29689f148.tar.xz |
Prepare for 2.9.3.0; add elgetopt -D
Signed-off-by: Laurent Bercot <ska@appnovation.com>
-rw-r--r-- | NEWS | 6 | ||||
-rw-r--r-- | doc/elgetopt.html | 13 | ||||
-rw-r--r-- | doc/index.html | 2 | ||||
-rw-r--r-- | doc/upgrade.html | 7 | ||||
-rw-r--r-- | package/info | 2 | ||||
-rw-r--r-- | src/execline/elgetopt.c | 25 |
6 files changed, 46 insertions, 9 deletions
@@ -1,5 +1,11 @@ Changelog for execline. +In 2.9.3.0 +---------- + + - New -D option to elgetopt. + + In 2.9.2.1 ---------- diff --git a/doc/elgetopt.html b/doc/elgetopt.html index b3a28ce..bb2563f 100644 --- a/doc/elgetopt.html +++ b/doc/elgetopt.html @@ -26,7 +26,7 @@ arguments to an execline script. <h2> Interface </h2> <pre> - elgetopt <em>optstring</em> <em>prog...</em> + elgetopt [ -D <em>default</em> ] <em>optstring</em> <em>prog...</em> </pre> <ul> @@ -44,13 +44,22 @@ string. </li> <li> If the <tt>-<em>c</em></tt> switch is recognized, <tt>elgetopt</tt> sets the <tt>ELGETOPT_<em>c</em></tt> environment variable. The value of that variable is the argument to the <tt>-<em>c</em></tt> switch if -it has one, and 1 otherwise. </li> +it has one, and <tt>1</tt> (or <em>default</em> if given) otherwise. </li> <li> After setting all recognized options, <tt>elgetopt</tt> makes new <tt>#</tt>, <tt>1</tt>, <tt>2</tt>... "positional parameters" with what remains. </li> <li> <tt>elgetopt</tt> then execs into <em>prog...</em>. </li> </ul> +<h2> Options </h2> + +<ul> + <li> <tt>-D <em>default</em></tt> : use <em>default</em> as the +value for the <tt>ELGETOPT_<em>c</em></tt> environment variable if there is +no argument to the <tt>-<em>c</em></tt> switch. Default is <tt>1</tt>. The +value is the same for all the options defined by elgetopt. </li> +</ul> + <h2> Notes </h2> <ul> diff --git a/doc/index.html b/doc/index.html index 87c6f75..0e6b43f 100644 --- a/doc/index.html +++ b/doc/index.html @@ -77,7 +77,7 @@ want nsswitch-like functionality: <h3> Download </h3> <ul> - <li> The current released version of execline is <a href="execline-2.9.2.1.tar.gz">2.9.2.1</a>. </li> + <li> The current released version of execline is <a href="execline-2.9.3.0.tar.gz">2.9.3.0</a>. </li> <li> Alternatively, you can checkout a copy of the <a href="//git.skarnet.org/cgi-bin/cgit.cgi/execline/">execline git repository</a>: diff --git a/doc/upgrade.html b/doc/upgrade.html index 6a65fac..23479b9 100644 --- a/doc/upgrade.html +++ b/doc/upgrade.html @@ -18,6 +18,13 @@ <h1> What has changed in execline </h1> +<h2> in 2.9.3.0 </h2> + +<ul> + <li> New <tt>-D <em>default</em></tt> option to +<a href="elgetopt.html">elgetopt</a>. </li> +</ul> + <h2> in 2.9.2.1 </h2> <ul> diff --git a/package/info b/package/info index b44cce3..9c1ad98 100644 --- a/package/info +++ b/package/info @@ -1,4 +1,4 @@ package=execline -version=2.9.2.1 +version=2.9.3.0 category=admin package_macro_name=EXECLINE diff --git a/src/execline/elgetopt.c b/src/execline/elgetopt.c index 040be31..54a89c0 100644 --- a/src/execline/elgetopt.c +++ b/src/execline/elgetopt.c @@ -11,17 +11,32 @@ #include <execline/execline.h> -#define USAGE "elgetopt optstring prog..." +#define USAGE "elgetopt [ -D default ] optstring prog..." int main (int argc, char const *const *argv, char const *const *envp) { size_t envlen = env_len(envp) ; stralloc modif = STRALLOC_ZERO ; char const *x = getenv("#") ; + char const *dfl = "1" ; unsigned int n, nbak ; PROG = "elgetopt" ; - if (argc < 3) strerr_dieusage(100, USAGE) ; + { + subgetopt l = SUBGETOPT_ZERO ; + for (;;) + { + int opt = subgetopt_r(argc, argv, "D:", &l) ; + if (opt == -1) break ; + switch (opt) + { + case 'D' : dfl = l.arg ; break ; + default : strerr_dieusage(100, USAGE) ; + } + } + argc -= l.ind ; argv += l.ind ; + } + if (argc < 2) strerr_dieusage(100, USAGE) ; if (!x) strerr_dienotset(100, "#") ; if (!uint0_scan(x, &n)) strerr_dieinvalid(100, "#") ; nbak = n++ ; @@ -40,11 +55,11 @@ int main (int argc, char const *const *argv, char const *const *envp) for (;;) { char hmpf[11] = "ELGETOPT_?" ; - int opt = sgetopt_r(n, args, argv[1], &l) ; + int opt = sgetopt_r(n, args, argv[0], &l) ; if (opt == -1) break ; if (opt == '?') return 1 ; hmpf[9] = opt ; - if (!env_addmodif(&modif, hmpf, l.arg ? l.arg : "1")) goto err ; + if (!env_addmodif(&modif, hmpf, l.arg ? l.arg : dfl)) goto err ; } n -= l.ind ; for (i = 0 ; i < nbak ; i++) @@ -64,7 +79,7 @@ int main (int argc, char const *const *argv, char const *const *envp) char const *v[envlen] ; if (el_pushenv(&satmp, envp, envlen, list, 1) < 0) goto err ; if (!env_make(v, envlen, satmp.s, satmp.len)) goto err ; - xmexec_fm(argv+2, v, envlen, modif.s, modif.len) ; + xmexec_fm(argv+1, v, envlen, modif.s, modif.len) ; } err: strerr_diefu1sys(111, "update environment") ; |