diff options
-rw-r--r-- | ChangeLog | 4 | ||||
-rw-r--r-- | Doc/Zsh/expn.yo | 4 | ||||
-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 |
6 files changed, 68 insertions, 5 deletions
diff --git a/ChangeLog b/ChangeLog index cebe082f9..edfba2db2 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,9 @@ 2000-05-03 Sven Wischnowsky <wischnow@informatik.hu-berlin.de> + * 11113: Doc/Zsh/expn.yo, Src/hist.c, Src/subst.c, + Src/Modules/parameter.c, Src/Zle/zle_misc.c: new (z) parameter + flag to do shell-word splitting on the value + * 11110: Completion/Core/_expand, Src/Zle/complist.c: remove backslashes before `$' in _expand when `substitute' is unset; fix for clearing end-of-list lines in menu-selection diff --git a/Doc/Zsh/expn.yo b/Doc/Zsh/expn.yo index 50021ed0d..e9e3b95c9 100644 --- a/Doc/Zsh/expn.yo +++ b/Doc/Zsh/expn.yo @@ -676,6 +676,10 @@ item(tt(f))( Split the result of the expansion to lines. This is a shorthand for `tt(ps:\n:)'. ) +item(tt(z))( +Split the result of the expansion into words using shell parsing to +find the words, i.e. taking into account any quoting in the value. +) item(tt(t))( Use a string describing the type of the parameter where the value of the parameter would usually appear. This string consists of keywords 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; |