summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLaurent Bercot <ska-skaware@skarnet.org>2023-02-28 03:32:47 +0000
committerLaurent Bercot <ska@appnovation.com>2023-02-28 03:32:47 +0000
commitcaef85892cd91cdd713562567ab14cb29689f148 (patch)
tree7668fc440814198bfa476f124ad2a31766342aa0 /src
parent6dd30a29f70b246ffc7771d0e79277392834cb71 (diff)
downloadexecline-caef85892cd91cdd713562567ab14cb29689f148.tar.xz
Prepare for 2.9.3.0; add elgetopt -D
Signed-off-by: Laurent Bercot <ska@appnovation.com>
Diffstat (limited to 'src')
-rw-r--r--src/execline/elgetopt.c25
1 files changed, 20 insertions, 5 deletions
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") ;