From ea714e771e8964114285915acacf80707cc17bdd Mon Sep 17 00:00:00 2001 From: Laurent Bercot Date: Wed, 26 Mar 2025 04:27:39 +0000 Subject: Add export-array; update deps Signed-off-by: Laurent Bercot --- COPYING | 2 +- INSTALL | 4 +-- Makefile | 12 +++++++ NEWS | 2 ++ configure | 2 +- doc/export-array.html | 64 ++++++++++++++++++++++++++++++++++++++ doc/index.html | 5 +-- doc/upgrade.html | 4 +++ package/deps.mak | 3 ++ package/modes | 1 + src/execline/deps-exe/export-array | 2 ++ src/execline/export-array.c | 55 ++++++++++++++++++++++++++++++++ 12 files changed, 150 insertions(+), 6 deletions(-) create mode 100644 doc/export-array.html create mode 100644 src/execline/deps-exe/export-array create mode 100644 src/execline/export-array.c diff --git a/COPYING b/COPYING index 2ea7ac0..1a9e8a2 100644 --- a/COPYING +++ b/COPYING @@ -1,4 +1,4 @@ -Copyright (c) 2011-2024 Laurent Bercot +Copyright (c) 2011-2025 Laurent Bercot Permission to use, copy, modify, and distribute this software for any purpose with or without fee is hereby granted, provided that the above diff --git a/INSTALL b/INSTALL index cf1fd35..0f5ea3c 100644 --- a/INSTALL +++ b/INSTALL @@ -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: diff --git a/Makefile b/Makefile index bf8f053..c9f20d3 100644 --- a/Makefile +++ b/Makefile @@ -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 $@ $^ diff --git a/NEWS b/NEWS index 72be9f5..3055f08 100644 --- a/NEWS +++ b/NEWS @@ -1,7 +1,9 @@ Changelog for execline. In 2.9.7.0 +---------- + - Bugfixes. - New "-P maxpar" option to forx and forstdin, for bounded parallelism. diff --git a/configure b/configure index 09cd454..8a537ae 100755 --- a/configure +++ b/configure @@ -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 @@ + + + + + + execline: the export program + + + + + + +

+execline
+Software
+skarnet.org +

+ +

The export-array program

+ +

+export-array encodes a set of values into an environment variable, +then executes a program. +

+ +

Interface

+ +

+ In an execline script: +

+ +
+     export-array [ -d delim ] var { value1 value2 ... } prog...
+
+ +
    +
  • export-array reads a (possibly empty) block +of values, and encodes them into the var environment variable. +
  • It then execs into prog.
  • +
+ +

Options

+ +
    +
  • -d delim : encode the list of values using the +first character of delim 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.
  • +
+ +

Notes

+ +
    +
  • var must be given without a dollar!
  • +
  • var must not contain the character = .
  • +
  • A list of values encoded via export-array VAR { value1 value2 ... } +can be retrieved via importas -Ssd "" VAR. +Then ${VAR} will be split into as many words as there are values.
  • +
  • A list encoded via export-array -d delim VAR { value1 value2 ... } +can similarly be retrieved via importas -Ssd delim VAR.
  • +
+ + + 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.
  • A POSIX-compliant system with a standard C development environment
  • GNU make, version 3.81 or later.
  • skalibs 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.
  • @@ -64,7 +64,7 @@ library.
  • If you're using musl and want nsswitch-like functionality: nsss version -0.2.0.5 or later (build-time and boot-time)
  • +0.2.0.6 or later (build-time and boot-time)

    Licensing

    @@ -131,6 +131,7 @@ the previous versions of execline and the current one.
  • The emptyenv program
  • The envfile program
  • The export program
  • +
  • The export-array program
  • The unexport program
  • The fdclose program
  • The fdblock program
  • 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 @@

    in 2.9.7.0

      +
    • skalibs +dependency bumped to 2.14.4.0.
    • +
    • nsss +optional dependency bumped to 0.2.0.6.
    • New -P option to forx and forstdin.
    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 + +#include +#include +#include +#include +#include + +#include + +#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) ; +} -- cgit v1.3.1