diff options
Diffstat (limited to 'Src')
-rw-r--r-- | Src/Modules/parameter.c | 2 | ||||
-rw-r--r-- | Src/Zle/zle_misc.c | 2 | ||||
-rw-r--r-- | Src/hist.c | 28 | ||||
-rw-r--r-- | Src/subst.c | 33 |
4 files changed, 60 insertions, 5 deletions
diff --git a/Src/Modules/parameter.c b/Src/Modules/parameter.c index bc8918e0f..e46b14108 100644 --- a/Src/Modules/parameter.c +++ b/Src/Modules/parameter.c @@ -1098,7 +1098,7 @@ histwgetfn(Param pm) int i = addhistnum(curhist, -1, HIST_FOREIGN), iw; Histent he = quietgethistent(i, GETHIST_UPWARD); - ll = bufferwords(NULL); + ll = bufferwords(NULL, NULL, NULL); for (n = firstnode(ll); n; incnode(n)) pushnode(l, getdata(n)); diff --git a/Src/Zle/zle_misc.c b/Src/Zle/zle_misc.c index a6adcc4fd..91b7317ed 100644 --- a/Src/Zle/zle_misc.c +++ b/Src/Zle/zle_misc.c @@ -549,7 +549,7 @@ copyprevshellword(char **args) int i; char *p = NULL; - l = bufferwords(&i); + l = bufferwords(NULL, NULL, &i); for (n = firstnode(l); n; incnode(n)) if (!i--) { diff --git a/Src/hist.c b/Src/hist.c index 530b6e05c..3dde19845 100644 --- a/Src/hist.c +++ b/Src/hist.c @@ -2037,17 +2037,28 @@ unlockhistfile(char *fn) /**/ mod_export LinkList -bufferwords(int *index) +bufferwords(LinkList list, char *buf, int *index) { - LinkList list = newlinklist(); int num = 0, cur = -1, got = 0, ne = noerrs, ocs = cs; char *p; + if (!list) + list = newlinklist(); + zleparse = 1; addedx = 0; noerrs = 1; lexsave(); - if (!isfirstln && chline) { + if (buf) { + int l = strlen(buf); + + p = (char *) zhalloc(l + 2); + memcpy(p, buf, l); + p[l] = ' '; + p[l + 1] = '\0'; + inpush(p, 0, NULL); + cs = 0; + } else if (!isfirstln && chline) { p = (char *) zhalloc(hptr - chline + ll + 2); memcpy(p, chline, hptr - chline); memcpy(p + (hptr - chline), line, ll); @@ -2074,6 +2085,17 @@ bufferwords(int *index) untokenize((p = dupstring(tokstr))); addlinknode(list, p); num++; + } else if (buf) { + if (IS_REDIROP(tok) && tokfd >= 0) { + char b[20]; + + sprintf(b, "%d%s", tokfd, tokstrings[tok]); + addlinknode(list, dupstring(b)); + num++; + } else if (tok != NEWLIN) { + addlinknode(list, dupstring(tokstrings[tok])); + num++; + } } if (!got && !zleparse) { got = 1; diff --git a/Src/subst.c b/Src/subst.c index 668d5eda3..1f992dd54 100644 --- a/Src/subst.c +++ b/Src/subst.c @@ -750,6 +750,7 @@ paramsubst(LinkList l, LinkNode n, char **str, int qt, int ssub) int casmod = 0; int quotemod = 0, quotetype = 0, quoteerr = 0; int visiblemod = 0; + int shsplit = 0; char *sep = NULL, *spsep = NULL; char *premul = NULL, *postmul = NULL, *preone = NULL, *postone = NULL; char *replstr = NULL; /* replacement string for /orig/repl */ @@ -971,6 +972,10 @@ paramsubst(LinkList l, LinkNode n, char **str, int qt, int ssub) presc++; break; + case 'z': + shsplit = 1; + break; + default: flagerr: zerr("error in flags", NULL, 0); @@ -1748,6 +1753,34 @@ paramsubst(LinkList l, LinkNode n, char **str, int qt, int ssub) val = nicedupstring(val); } } + if (shsplit) { + LinkList list = NULL; + + if (isarr) { + char **ap; + for (ap = aval; *ap; ap++) + list = bufferwords(list, *ap, NULL); + isarr = 0; + } else + list = bufferwords(NULL, val, NULL); + + if (!firstnode(list)) + val = dupstring(""); + else if (!nextnode(firstnode(list))) + val = getdata(firstnode(list)); + else { + char **ap; + LinkNode node; + + aval = ap = (char **) zhalloc((countlinknodes(list) + 1) * + sizeof(char *)); + for (node = firstnode(list); node; incnode(node)) + *ap++ = (char *) getdata(node); + *ap = NULL; + mult_isarr = isarr = 2; + } + copied = 1; + } if (isarr) { char *x; char *y; |