aboutsummaryrefslogtreecommitdiff
path: root/sys/cmd/rc/exec.c
diff options
context:
space:
mode:
authorNicholas Noll <nbnoll@eml.cc>2021-10-21 12:02:14 -0700
committerNicholas Noll <nbnoll@eml.cc>2021-10-21 12:02:14 -0700
commit79fb5e6be113678d4ef0349d2e584f219e567426 (patch)
tree48aaedc53f40329c1552eb748ad021a76ec3318c /sys/cmd/rc/exec.c
parentfaaf40e55e002212c0c28f7845dfa2322eb7ad05 (diff)
feat(rc): string join operator
Diffstat (limited to 'sys/cmd/rc/exec.c')
-rw-r--r--sys/cmd/rc/exec.c41
1 files changed, 41 insertions, 0 deletions
diff --git a/sys/cmd/rc/exec.c b/sys/cmd/rc/exec.c
index ac0dc08..425d00f 100644
--- a/sys/cmd/rc/exec.c
+++ b/sys/cmd/rc/exec.c
@@ -625,6 +625,47 @@ Xconcatenate(void)
}
void
+Xjoin(void)
+{
+ int n;
+ char *s;
+ Word *arg, *elt;
+
+ if(count(runner->args->word) != 1){
+ Xerror("variable name is not singleton\n");
+ return;
+ }
+
+ s = runner->args->word->str;
+ // deglob(s)
+
+ arg = var(s)->val;
+ poplist();
+
+ n = count(arg);
+ if(n==0){
+ pushword("");
+ return;
+ }
+
+ for(elt = arg; elt; elt=elt->link)
+ n += strlen(elt->str);
+
+ s = emalloc(n);
+ if(arg){
+ strcpy(s, arg->str);
+ for(elt = arg->link; elt; elt = elt->link){
+ strcat(s, " ");
+ strcat(s, elt->str);
+ }
+ }else
+ s[0] = 0;
+
+ pushword(s);
+ efree(s);
+}
+
+void
Xdollar(void)
{
int n;