From 79fb5e6be113678d4ef0349d2e584f219e567426 Mon Sep 17 00:00:00 2001 From: Nicholas Noll Date: Thu, 21 Oct 2021 12:02:14 -0700 Subject: feat(rc): string join operator --- sys/cmd/rc/exec.c | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) (limited to 'sys/cmd/rc/exec.c') 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 @@ -624,6 +624,47 @@ Xconcatenate(void) runner->args->word = w; } +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) { -- cgit v1.2.1