From 9983edf33b1eb4d91bf1187f8e4b7c0c3d288e53 Mon Sep 17 00:00:00 2001 From: Laurent Bercot Date: Mon, 3 Jun 2024 13:31:59 +0000 Subject: Add importas -S Signed-off-by: Laurent Bercot --- NEWS | 2 ++ doc/importas.html | 5 +++++ doc/upgrade.html | 3 +++ src/libexecline/exlsn_importas.c | 16 ++++++++++------ 4 files changed, 20 insertions(+), 6 deletions(-) diff --git a/NEWS b/NEWS index 281bd09..938c3d2 100644 --- a/NEWS +++ b/NEWS @@ -6,6 +6,8 @@ In 2.9.6.0 - elglob can now provide a single word, where the results of the globbing are separated by a given delimiter (or encoded into a netstring). + - New option: importas -S, with the same functionality as the old +"import" command: import a variable with the same name. In 2.9.5.1 diff --git a/doc/importas.html b/doc/importas.html index ac95e87..ae39de6 100644 --- a/doc/importas.html +++ b/doc/importas.html @@ -27,6 +27,7 @@ environment variable, then executes another program.
      importas [ -i | -D default ] [ -u ] [ -s ] [ -C | -c ] [ -N | -n ] [ -d delim ] variable envvar prog...
+     importas -S [ -i | -D default ] [ -u ] [ -s ] [ -C | -c ] [ -N | -n ] [ -d delim ] envvar prog...
 
diff --git a/doc/upgrade.html b/doc/upgrade.html index 17da599..f4cd3dc 100644 --- a/doc/upgrade.html +++ b/doc/upgrade.html @@ -25,6 +25,9 @@ dependency bumped to 2.14.2.0.
  • elglob now has an option to provide its results as one word (including the possibility of netstring encoding).
  • +
  • importas now has an option that can be +used instead of repeating a variable when it is imported with the same +name.
  • in 2.9.5.1

    diff --git a/src/libexecline/exlsn_importas.c b/src/libexecline/exlsn_importas.c index 70c53a7..1ae175f 100644 --- a/src/libexecline/exlsn_importas.c +++ b/src/libexecline/exlsn_importas.c @@ -1,11 +1,13 @@ /* ISC license. */ #include + #include #include #include #include #include + #include #include "exlsn.h" @@ -16,6 +18,7 @@ int exlsn_importas (int argc, char const **argv, char const *const *envp, exlsn_ elsubst_t blah ; char const *defaultval = 0 ; char const *x ; + unsigned int ivar = 1 ; int insist = 0 ; int unexport = 0 ; blah.var = info->vars.len ; @@ -23,10 +26,11 @@ int exlsn_importas (int argc, char const **argv, char const *const *envp, exlsn_ for (;;) { - int opt = subgetopt_r(argc, argv, "iuD:NnsCcd:", &localopt) ; + int opt = subgetopt_r(argc, argv, "SiuD:NnsCcd:", &localopt) ; if (opt < 0) break ; switch (opt) { + case 'S' : ivar = 0 ; break ; case 'i' : insist = 1 ; break ; case 'u' : unexport = 1 ; break ; case 'D' : defaultval = localopt.arg ; break ; @@ -41,18 +45,18 @@ int exlsn_importas (int argc, char const **argv, char const *const *envp, exlsn_ } argc -= localopt.ind ; argv += localopt.ind ; - if ((unsigned int)argc < 2) return -3 ; + if (argc < 1 + ivar) return -3 ; if (!*argv[0] || el_vardupl(argv[0], info->vars.s, info->vars.len)) return -2 ; if (!stralloc_catb(&info->vars, argv[0], strlen(argv[0]) + 1)) return -1 ; - x = env_get2(envp, argv[1]) ; + x = env_get2(envp, argv[ivar]) ; if (!x) { - if (insist) strerr_dienotset(100, argv[1]) ; + if (insist) strerr_dienotset(100, argv[ivar]) ; x = defaultval ; } else if (unexport) { - if (!stralloc_catb(&info->modifs, argv[1], strlen(argv[1]) + 1)) goto err ; + if (!stralloc_catb(&info->modifs, argv[ivar], strlen(argv[ivar]) + 1)) goto err ; } if (!x) blah.n = 0 ; else @@ -64,7 +68,7 @@ int exlsn_importas (int argc, char const **argv, char const *const *envp, exlsn_ blah.n = r ; } if (!genalloc_append(elsubst_t, &info->data, &blah)) goto err ; - return localopt.ind + 2 ; + return localopt.ind + 1 + ivar ; err: info->vars.len = blah.var ; -- cgit v1.2.3