summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--NEWS2
-rw-r--r--doc/importas.html5
-rw-r--r--doc/upgrade.html3
-rw-r--r--src/libexecline/exlsn_importas.c16
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.
<pre>
importas [ -i | -D default ] [ -u ] [ -s ] [ -C | -c ] [ -N | -n ] [ -d <em>delim</em> ] <em>variable</em> <em>envvar</em> <em>prog...</em>
+ importas -S [ -i | -D default ] [ -u ] [ -s ] [ -C | -c ] [ -N | -n ] [ -d <em>delim</em> ] <em>envvar</em> <em>prog...</em>
</pre>
<ul>
@@ -54,6 +55,10 @@ error message. This has precedence over any <tt>-D</tt> option. </li>
the environment after the substitution. <tt>importas -u <em>variable</em>
<em>envvar</em></tt> is equivalent to <tt>importas <em>variable</em>
<em>envvar</em> unexport <em>envvar</em></tt>. </li>
+ <li> <tt>-S</tt>&nbsp;: import with same name. This option allows
+<em>variable</em> to be omitted; it will be the same as <em>envvar</em>.
+In other words, <code>importas -S <em>var</em></code> is the same as
+<code>importas <em>var</em> <em>var</em></code>. </li>
<li> Other options are used to <a href="el_transform.html">control
the substitution mechanism</a>. </li>
</ul>
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. </li>
<li> <a href="elglob.html">elglob</a> now has an option to provide its
results as one word (including the possibility of netstring encoding). </li>
+ <li> <a href="importas.html">importas</a> now has an option that can be
+used instead of repeating a variable when it is imported with the same
+name. </li>
</ul>
<h2> in 2.9.5.1 </h2>
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 <string.h>
+
#include <skalibs/sgetopt.h>
#include <skalibs/strerr.h>
#include <skalibs/stralloc.h>
#include <skalibs/genalloc.h>
#include <skalibs/env.h>
+
#include <execline/execline.h>
#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 ;