From c26704f7a37f615820cebeacb763aa2748c290ec Mon Sep 17 00:00:00 2001 From: Peter Stephenson Date: Tue, 12 Jun 2001 10:34:57 +0000 Subject: Added KSH_TYPESET option. --- ChangeLog | 6 ++++++ Doc/Zsh/options.yo | 14 ++++++++++++++ Src/options.c | 1 + Src/subst.c | 13 ++++++++++--- Src/zsh.h | 1 + Test/E01options.ztst | 38 ++++++++++++++++++++++++++++++++++---- 6 files changed, 66 insertions(+), 7 deletions(-) diff --git a/ChangeLog b/ChangeLog index dd5f71346..026ec09ac 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2001-06-12 Peter Stephenson + + * 14858: Doc/Zsh/options.yo, Src/options.c, Src/subst.c, + Src/zsh.h, Test/E01options.ztst: KSH_TYPESET option allows + assignments after typeset not to be split. + 2001-06-11 Clint Adams * 14843: Src/Modules/tcp.c, Src/Modules/zftp.c: diff --git a/Doc/Zsh/options.yo b/Doc/Zsh/options.yo index 490946cd5..564e6701b 100644 --- a/Doc/Zsh/options.yo +++ b/Doc/Zsh/options.yo @@ -668,6 +668,16 @@ Alters the way options settings are printed: instead of separate lists of set and unset options, all options are shown, marked `on' if they are in the non-default state, `off' otherwise. ) +pindex(KSH_TYPESET) +cindex(argument splitting, in typeset etc.) +cindex(ksh, argument splitting in typeset) +item(tt(KSH_TYPESET) )( +Alters the way arguments to the tt(typeset) family of commands, including +tt(declare), tt(export), tt(float), tt(integer), tt(local) and +tt(readonly), are processed. Without this option, zsh will perform normal +word splitting after command and parameter expansion in arguments of an +assignment; with it, word splitting does not take place in those cases. +) pindex(LIST_AMBIGUOUS) cindex(ambiguous completion) cindex(completion, ambiguous) @@ -757,6 +767,10 @@ not otherwise treated specially; it is passed to the command as a single argument, and not used as an actual parameter assignment. For example, in tt(echo foo=~/bar:~/rod), both occurrences of tt(~) would be replaced. Note that this happens anyway with tt(typeset) and similar statements. + +This option respects the setting of the tt(KSH_TYPESET) option. In other +words, if both options are in effect, arguments looking like +assignments will not undergo wordsplitting. ) pindex(MAIL_WARNING) cindex(mail, warning of reading) diff --git a/Src/options.c b/Src/options.c index 139926428..2c63f194a 100644 --- a/Src/options.c +++ b/Src/options.c @@ -145,6 +145,7 @@ static struct optname optns[] = { {NULL, "kshautoload", OPT_EMULATE|OPT_BOURNE, KSHAUTOLOAD}, {NULL, "kshglob", OPT_EMULATE|OPT_KSH, KSHGLOB}, {NULL, "kshoptionprint", OPT_EMULATE|OPT_KSH, KSHOPTIONPRINT}, +{NULL, "kshtypeset", OPT_EMULATE|OPT_KSH, KSHTYPESET}, {NULL, "listambiguous", OPT_ALL, LISTAMBIGUOUS}, {NULL, "listbeep", OPT_ALL, LISTBEEP}, {NULL, "listpacked", 0, LISTPACKED}, diff --git a/Src/subst.c b/Src/subst.c index 25eda1cee..b5480d75e 100644 --- a/Src/subst.c +++ b/Src/subst.c @@ -50,6 +50,7 @@ mod_export void prefork(LinkList list, int flags) { LinkNode node; + int asssub = (flags & PF_TYPESET) && isset(KSHTYPESET); queue_signals(); for (node = firstnode(list); node; incnode(node)) { @@ -70,7 +71,7 @@ prefork(LinkList list, int flags) if (isset(SHFILEEXPANSION)) filesub((char **)getaddrdata(node), flags & (PF_TYPESET|PF_ASSIGN)); - if (!(node = stringsubst(list, node, flags & PF_SINGLE))) { + if (!(node = stringsubst(list, node, flags & PF_SINGLE, asssub))) { unqueue_signals(); return; } @@ -97,7 +98,7 @@ prefork(LinkList list, int flags) /**/ static LinkNode -stringsubst(LinkList list, LinkNode node, int ssub) +stringsubst(LinkList list, LinkNode node, int ssub, int asssub) { int qt; char *str3 = (char *)getdata(node); @@ -211,6 +212,12 @@ stringsubst(LinkList list, LinkNode node, int ssub) str3 = str2; setdata(node, str3); continue; + } else if (asssub && ((c == '=') || c == Equals) && str != str3) { + /* + * We are in a normal argument which looks like an assignment + * and is to be treated like one, with no word splitting. + */ + ssub = 1; } str++; } @@ -1885,7 +1892,7 @@ paramsubst(LinkList l, LinkNode n, char **str, int qt, int ssub) *--fstr = Marker; init_list1(tl, fstr); - if (!eval && !stringsubst(&tl, firstnode(&tl), ssub)) + if (!eval && !stringsubst(&tl, firstnode(&tl), ssub, 0)) return NULL; *str = aptr; tn = firstnode(&tl); diff --git a/Src/zsh.h b/Src/zsh.h index c510b9759..5ab5661d1 100644 --- a/Src/zsh.h +++ b/Src/zsh.h @@ -1384,6 +1384,7 @@ enum { KSHAUTOLOAD, KSHGLOB, KSHOPTIONPRINT, + KSHTYPESET, LISTAMBIGUOUS, LISTBEEP, LISTPACKED, diff --git a/Test/E01options.ztst b/Test/E01options.ztst index 3e272509c..8ffba78b7 100644 --- a/Test/E01options.ztst +++ b/Test/E01options.ztst @@ -502,6 +502,22 @@ >unset >globassign + setopt kshtypeset + ktvars=(ktv1 ktv2) + typeset ktfoo=`echo arg1 arg2` $ktvars + print $+ktv1 $+ktv2 $+ktv3 + print $ktfoo + unsetopt kshtypeset + typeset noktfoo=`echo noktarg1 noktarg2` + print $noktfoo + print $+noktarg1 $+noktarg2 + unset ktfoo ktv1 ktv2 noktfoo noktarg2 +0:KSH_TYPESET option +>1 1 0 +>arg1 arg2 +>noktarg1 +>0 1 + showopt() { setopt | egrep 'localoptions|ksharrays'; } f1() { setopt localoptions ksharrays; showopt } f2() { setopt ksharrays; showopt } @@ -526,14 +542,28 @@ # LOCAL_TRAPS was tested in C03traps (phew). - fn() { local HOME=/any/old/name; print var=~ 'anything goes/here'=~; } + fn() { + local HOME=/any/old/name + print -l var=~ 'anything goes/here'=~ split=`echo maybe not`; + } setopt magicequalsubst fn - unsetopt magicequalsubst + setopt kshtypeset + fn + unsetopt magicequalsubst kshtypeset fn 0:MAGIC_EQUAL_SUBST option ->var=/any/old/name anything goes/here=/any/old/name ->var=~ anything goes/here=~ +>var=/any/old/name +>anything goes/here=/any/old/name +>split=maybe +>not +>var=/any/old/name +>anything goes/here=/any/old/name +>split=maybe not +>var=~ +>anything goes/here=~ +>split=maybe +>not setopt MARK_DIRS print tmp* -- cgit 1.4.1