diff options
| author | Laurent Bercot <ska-skaware@skarnet.org> | 2025-03-26 04:27:39 +0000 |
|---|---|---|
| committer | Laurent Bercot <ska@appnovation.com> | 2025-03-26 04:27:39 +0000 |
| commit | ea714e771e8964114285915acacf80707cc17bdd (patch) | |
| tree | 05e036cd629693de1667225cd8df4bf26aa5db10 | |
| parent | 7390d0eacf18f70a3ac4f6f3351cadc12656234e (diff) | |
| download | execline-ea714e771e8964114285915acacf80707cc17bdd.tar.gz | |
Add export-array; update deps
Signed-off-by: Laurent Bercot <ska@appnovation.com>
| -rw-r--r-- | COPYING | 2 | ||||
| -rw-r--r-- | INSTALL | 4 | ||||
| -rw-r--r-- | Makefile | 12 | ||||
| -rw-r--r-- | NEWS | 2 | ||||
| -rwxr-xr-x | configure | 2 | ||||
| -rw-r--r-- | doc/export-array.html | 64 | ||||
| -rw-r--r-- | doc/index.html | 5 | ||||
| -rw-r--r-- | doc/upgrade.html | 4 | ||||
| -rw-r--r-- | package/deps.mak | 3 | ||||
| -rw-r--r-- | package/modes | 1 | ||||
| -rw-r--r-- | src/execline/deps-exe/export-array | 2 | ||||
| -rw-r--r-- | src/execline/export-array.c | 55 |
12 files changed, 150 insertions, 6 deletions
@@ -1,4 +1,4 @@ -Copyright (c) 2011-2024 Laurent Bercot <ska-skaware@skarnet.org> +Copyright (c) 2011-2025 Laurent Bercot <ska-skaware@skarnet.org> Permission to use, copy, modify, and distribute this software for any purpose with or without fee is hereby granted, provided that the above @@ -6,8 +6,8 @@ Build Instructions - A POSIX-compliant C development environment - GNU make version 3.81 or later - - skalibs version 2.14.3.0 or later: https://skarnet.org/software/skalibs/ - - Optional: nsss version 0.2.0.5 or later: https://skarnet.org/software/nsss/ + - skalibs version 2.14.4.0 or later: https://skarnet.org/software/skalibs/ + - Optional: nsss version 0.2.0.6 or later: https://skarnet.org/software/nsss/ This software will run on any operating system that implements POSIX.1-2008, available at: @@ -20,8 +20,10 @@ INTERNAL_LIBS := EXTRA_TARGETS := LIB_DEFS := BIN_SYMLINKS := +PC_DEFS := define library_definition +name := $(lastword $(subst =, ,$(1))) LIB$(firstword $(subst =, ,$(1))) := lib$(lastword $(subst =, ,$(1))).$(if $(DO_ALLSTATIC),a,so).xyzzy ifdef DO_SHARED SHARED_LIBS += lib$(lastword $(subst =, ,$(1))).so.xyzzy @@ -29,6 +31,11 @@ endif ifdef DO_STATIC STATIC_LIBS += lib$(lastword $(subst =, ,$(1))).a.xyzzy endif +PC_DEFS += $(lastword $(subst =, ,$(1))) + +$(lastword $(subst =, ,$(1))).pc: $(if $(DO_SHARED),lib$(lastword $(subst =, ,$(1))).so.xyzzy,) $(if $(DO_STATIC),lib$(lastword $(subst =, ,$(1))).a.xyzzy,) + ./tools/gen-dotpc.sh $(lastword $(subst =, ,$(1))) $(if $(DO_SHARED),true,false) $(if $(DO_STATIC),true,false) "$$($(lastword $(subst =, ,$(1)))_description)" "$(includedir)" "$(dynlibdir)" "$(libdir)" "$$($(lastword $(subst =, ,$(1)))_dependencies)" + endef define binary_installation_rule @@ -146,8 +153,13 @@ $(DESTDIR)$(includedir)/%.h: src/include/%.h %.lo: %.c exec $(CC) $(CPPFLAGS_ALL) $(CFLAGS_ALL) $(CFLAGS_SHARED) -c -o $@ $< +ifdef DO_ALLSTATIC +$(ALL_BINS): -lskarnet + exec $(CC) -o $@ $(CFLAGS_ALL) $(LDFLAGS_ALL) $(LDFLAGS_NOSHARED) $^ $(EXTRA_LIBS) $(LDLIBS) +else $(ALL_BINS): exec $(CC) -o $@ $(CFLAGS_ALL) $(LDFLAGS_ALL) $(LDFLAGS_NOSHARED) $^ $(EXTRA_LIBS) $(LDLIBS) +endif lib%.a.xyzzy: exec $(AR) rc $@ $^ @@ -1,7 +1,9 @@ Changelog for execline. In 2.9.7.0 +---------- + - Bugfixes. - New "-P maxpar" option to forx and forstdin, for bounded parallelism. @@ -60,7 +60,6 @@ exit 0 # generally not a good idea to use echo. # See http://www.etalabs.net/sh_tricks.html echo () { - IFS=" " printf %s\\n "$*" } @@ -433,6 +432,7 @@ if $allstatic ; then echo "DO_ALLSTATIC := 1" else echo ".LIBPATTERNS := lib%.so" + echo "DO_ALLSTATIC :=" fi if $static ; then echo "DO_STATIC := 1" diff --git a/doc/export-array.html b/doc/export-array.html new file mode 100644 index 0000000..bc3d611 --- /dev/null +++ b/doc/export-array.html @@ -0,0 +1,64 @@ +<html> + <head> + <meta name="viewport" content="width=device-width, initial-scale=1.0" /> + <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> + <meta http-equiv="Content-Language" content="en" /> + <title>execline: the export program</title> + <meta name="Description" content="execline: the export program" /> + <meta name="Keywords" content="execline command export environment variable" /> + <!-- <link rel="stylesheet" type="text/css" href="//skarnet.org/default.css" /> --> + </head> +<body> + +<p> +<a href="index.html">execline</a><br /> +<a href="//skarnet.org/software/">Software</a><br /> +<a href="//skarnet.org/">skarnet.org</a> +</p> + +<h1> The <tt>export-array</tt> program </h1> + +<p> +<tt>export-array</tt> encodes a set of values into an environment variable, +then executes a program. +</p> + +<h2> Interface </h2> + +<p> + In an execline script: +</p> + +<pre> + export-array [ -d <em>delim</em> ] <em>var</em> { <em>value1</em> <em>value2</em> ... } <em>prog...</em> +</pre> + +<ul> + <li> <tt>export-array</tt> reads a (possibly empty) <a href="el_semicolon.html">block</a> +of values, and encodes them into the <em>var</em> environment variable. + <li> It then execs into <em>prog</em>. </li> +</ul> + +<h2> Options </h2> + +<ul> + <li> <tt>-d</tt> <em>delim</em> : encode the list of values using the +first character of <em>delim</em> as a terminator. Only use this when you know +the character does not appear in any of the values! By default, no terminator +character is specified, and the values are encoded as netstrings. </li> +</ul> + +<h2> Notes </h2> + +<ul> + <li> <em>var</em> must be given without a dollar! </li> + <li> <em>var</em> must not contain the character <tt>=</tt> . </li> + <li> A list of values encoded via <code>export-array <em>VAR</em> { <em>value1</em> <em>value2</em> ... }</code> +can be retrieved via <code><a href="importas.html">importas</a> -Ssd "" <em>VAR</em></code>. +Then <tt>${VAR}</tt> will be split into as many words as there are values. </li> + <li> A list encoded via <code>export-array -d <em>delim</em> <em>VAR</em> { <em>value1</em> <em>value2</em> ... }</code> +can similarly be retrieved via <code>importas -Ssd <em>delim</em> <em>VAR</em></code>. </li> +</ul> + +</body> +</html> diff --git a/doc/index.html b/doc/index.html index 6dbab1c..324f259 100644 --- a/doc/index.html +++ b/doc/index.html @@ -51,7 +51,7 @@ shell's syntax, and has no security issues. <li> A POSIX-compliant system with a standard C development environment </li> <li> GNU make, version 3.81 or later. </li> <li> <a href="//skarnet.org/software/skalibs/">skalibs</a> version -2.14.3.0 or later. It's a build-time requirement. It's also a run-time +2.14.4.0 or later. It's a build-time requirement. It's also a run-time requirement if you link against the shared version of the skalibs library. </li> </ul> @@ -64,7 +64,7 @@ library. </li> <li> If you're using <a href="https://musl.libc.org/">musl</a> and want nsswitch-like functionality: <a href="//skarnet.org/software/nsss/">nsss</a> version -0.2.0.5 or later (build-time and boot-time) </li> +0.2.0.6 or later (build-time and boot-time) </li> </ul> <h3> Licensing </h3> @@ -131,6 +131,7 @@ the previous versions of execline and the current one. </li> <li><a href="emptyenv.html">The <tt>emptyenv</tt> program</a></li> <li><a href="envfile.html">The <tt>envfile</tt> program</a></li> <li><a href="export.html">The <tt>export</tt> program</a></li> +<li><a href="export-array.html">The <tt>export-array</tt> program</a></li> <li><a href="unexport.html">The <tt>unexport</tt> program</a></li> <li><a href="fdclose.html">The <tt>fdclose</tt> program</a></li> <li><a href="fdblock.html">The <tt>fdblock</tt> program</a></li> diff --git a/doc/upgrade.html b/doc/upgrade.html index 31ddf00..9060ea4 100644 --- a/doc/upgrade.html +++ b/doc/upgrade.html @@ -21,6 +21,10 @@ <h2> in 2.9.7.0 </h2> <ul> + <li> <a href="//skarnet.org/software/skalibs/">skalibs</a> +dependency bumped to 2.14.4.0. </li> + <li> <a href="//skarnet.org/software/nsss/">nsss</a> +optional dependency bumped to 0.2.0.6. </li> <li> <em> New <tt>-P</tt> option to <a href="forx.html">forx</a> and <a href="forstdin.html">forstdin</a>. </li> </ul> diff --git a/package/deps.mak b/package/deps.mak index 1944f0c..87a4521 100644 --- a/package/deps.mak +++ b/package/deps.mak @@ -18,6 +18,7 @@ src/execline/execline-cd.o src/execline/execline-cd.lo: src/execline/execline-cd src/execline/execline-umask.o src/execline/execline-umask.lo: src/execline/execline-umask.c src/execline/execlineb.o src/execline/execlineb.lo: src/execline/execlineb.c src/include/execline/execline.h src/include-local/exlsn.h src/execline/exit.o src/execline/exit.lo: src/execline/exit.c +src/execline/export-array.o src/execline/export-array.lo: src/execline/export-array.c src/include/execline/execline.h src/execline/export.o src/execline/export.lo: src/execline/export.c src/execline/fdblock.o src/execline/fdblock.lo: src/execline/fdblock.c src/execline/fdclose.o src/execline/fdclose.lo: src/execline/fdclose.c @@ -115,6 +116,8 @@ exit: EXTRA_LIBS := -lskarnet exit: src/execline/exit.o export: EXTRA_LIBS := -lskarnet export: src/execline/export.o +export-array: EXTRA_LIBS := -lskarnet +export-array: src/execline/export-array.o ${LIBEXECLINE} fdblock: EXTRA_LIBS := -lskarnet fdblock: src/execline/fdblock.o fdclose: EXTRA_LIBS := -lskarnet diff --git a/package/modes b/package/modes index 0f04782..b07e67a 100644 --- a/package/modes +++ b/package/modes @@ -15,6 +15,7 @@ exec 0755 exit 0755 execlineb 0755 export 0755 +export-array 0755 fdblock 0755 fdclose 0755 fdreserve 0755 diff --git a/src/execline/deps-exe/export-array b/src/execline/deps-exe/export-array new file mode 100644 index 0000000..97021b5 --- /dev/null +++ b/src/execline/deps-exe/export-array @@ -0,0 +1,2 @@ +${LIBEXECLINE} +-lskarnet diff --git a/src/execline/export-array.c b/src/execline/export-array.c new file mode 100644 index 0000000..d883c2d --- /dev/null +++ b/src/execline/export-array.c @@ -0,0 +1,55 @@ +/* ISC license. */ + +#include <string.h> + +#include <skalibs/sgetopt.h> +#include <skalibs/strerr.h> +#include <skalibs/stralloc.h> +#include <skalibs/netstring.h> +#include <skalibs/exec.h> + +#include <execline/execline.h> + +#define USAGE "export-array [ -d delim ] variable { value-list } prog..." +#define dieusage() strerr_dieusage(100, USAGE) +#define dienomem() strerr_diefu1sys(111, "stralloc_catb") + +int main (int argc, char const **argv) +{ + stralloc sa = STRALLOC_ZERO ; + char const *var ; + int argc1 ; + char delim = 0 ; + PROG = "export-array" ; + { + subgetopt l = SUBGETOPT_ZERO ; + for (;;) + { + int opt = subgetopt_r(argc, argv, "d", &l) ; + if (opt == -1) break ; + switch (opt) + { + case 'd' : delim = *l.arg ; break ; + default : dieusage() ; + } + } + argc -= l.ind ; argv += l.ind ; + } + if (argc < 2) dieusage() ; + var = *argv++ ; argc-- ; + if (strchr(var, '=')) strerr_dief2x(100, "invalid variable name: ", var) ; + + argc1 = el_semicolon(argv) ; + if (!argc1) strerr_dief1x(100, "empty block") ; + if (argc1 >= argc) strerr_dief1x(100, "unterminated block") ; + if (argc1 + 1 == argc) dieusage() ; + + if (!stralloc_cats(&sa, var) || !stralloc_catb(&sa, "=", 1)) dienomem() ; + for (; argc1 ; argv++, argc1--) + { + if (delim ? !stralloc_cats(&sa, *argv) || !stralloc_catb(&sa, &delim, 1) : !netstring_appends(&sa, *argv)) dienomem() ; + } + if (!stralloc_0(&sa)) dienomem() ; + + xmexec_n(argv + 1, sa.s, sa.len, 1) ; +} |
