summaryrefslogtreecommitdiff
path: root/src/libexecline
diff options
context:
space:
mode:
authorLaurent Bercot <ska-skaware@skarnet.org>2024-04-06 17:54:13 +0000
committerLaurent Bercot <ska@appnovation.com>2024-04-06 17:54:13 +0000
commita5b7a319fb558f5df599de286318029d455ed193 (patch)
treeb468c6b2620613aa5f29d793feecb22c94dfedbf /src/libexecline
parentdb852ecd93afc9f893886a132ee58b23579fc79d (diff)
downloadexecline-a5b7a319fb558f5df599de286318029d455ed193.tar.xz
Prepare for 2.9.5.0; add ? support in backtick
Signed-off-by: Laurent Bercot <ska@appnovation.com>
Diffstat (limited to 'src/libexecline')
-rw-r--r--src/libexecline/deps-lib/execline1
-rw-r--r--src/libexecline/el_modifs_and_exec.c72
2 files changed, 73 insertions, 0 deletions
diff --git a/src/libexecline/deps-lib/execline b/src/libexecline/deps-lib/execline
index a1f7c74..608fa7f 100644
--- a/src/libexecline/deps-lib/execline
+++ b/src/libexecline/deps-lib/execline
@@ -2,6 +2,7 @@ el_execsequence.o
el_getstrict.o
el_modif_and_exec.o
el_modif_and_spawn.o
+el_modifs_and_exec.o
el_parse.o
el_parse_from_buffer.o
el_parse_from_string.o
diff --git a/src/libexecline/el_modifs_and_exec.c b/src/libexecline/el_modifs_and_exec.c
new file mode 100644
index 0000000..fe0117c
--- /dev/null
+++ b/src/libexecline/el_modifs_and_exec.c
@@ -0,0 +1,72 @@
+/* ISC license. */
+
+#include <string.h>
+
+#include <skalibs/env.h>
+#include <skalibs/exec.h>
+
+#include <execline/config.h>
+#include <execline/execline.h>
+
+void el_modifs_and_exec (char const *const *argv, char const *const *vars, char const *const *values, size_t n, int doimport)
+{
+ size_t pos = 0 ;
+ size_t yeslen = 0 ;
+ size_t yesn = 0 ;
+ size_t modiflen = 0 ;
+ for (size_t i = 0 ; i < n ; i++)
+ {
+ size_t len = strlen(vars[i]) + 1 ;
+ modiflen += len ;
+ if (values[i])
+ {
+ yesn++ ;
+ yeslen += len ;
+ modiflen += 1 + strlen(values[i]) ;
+ }
+ }
+
+ char modifs[modiflen ? modiflen : 1] ;
+
+ for (size_t i = 0 ; i < n ; i++)
+ {
+ size_t len = strlen(vars[i]) ;
+ memcpy(modifs + pos, vars[i], len) ;
+ pos += len ;
+ if (values[i])
+ {
+ modifs[pos++] = '=' ;
+ len = strlen(values[i]) ;
+ memcpy(modifs + pos, values[i], len) ;
+ pos += len ;
+ }
+ modifs[pos++] = 0 ;
+ }
+
+ if (doimport && yesn)
+ {
+ size_t m = 0 ;
+ size_t ypos = 0 ;
+ char const *newargv[env_len(argv) + 3 + 5 * yesn] ;
+ char yesvars[yeslen ? yeslen : 1] ;
+ newargv[m++] = EXECLINE_BINPREFIX "multisubstitute" ;
+ for (size_t i = 0 ; i < n ; i++) if (values[i])
+ {
+ size_t len = strlen(vars[i]) + 1 ;
+ char *p = yesvars + ypos ;
+ newargv[m++] = " importas" ;
+ newargv[m++] = " -ui" ;
+ newargv[m++] = " --" ;
+ newargv[m++] = p ;
+ newargv[m++] = p ;
+ yesvars[ypos++] = ' ' ;
+ memcpy(yesvars + ypos, vars[i], len) ;
+ ypos += len ;
+ }
+ newargv[m++] = "" ;
+ while (*argv) newargv[m++] = *argv++ ;
+ newargv[m++] = 0 ;
+ xmexec0_n(newargv, modifs, modiflen, n) ;
+ }
+ else xmexec0_n(argv, modifs, modiflen, n) ;
+}