Added KSH_TYPESET option.

This commit is contained in:
Peter Stephenson 2001-06-12 10:34:57 +00:00
parent ae09302120
commit c26704f7a3
6 changed files with 66 additions and 7 deletions

View File

@ -1,3 +1,9 @@
2001-06-12 Peter Stephenson <pws@csr.com>
* 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 <clint@zsh.org>
* 14843: Src/Modules/tcp.c, Src/Modules/zftp.c:

View File

@ -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) <K>)(
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)

View File

@ -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},

View File

@ -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);

View File

@ -1384,6 +1384,7 @@ enum {
KSHAUTOLOAD,
KSHGLOB,
KSHOPTIONPRINT,
KSHTYPESET,
LISTAMBIGUOUS,
LISTBEEP,
LISTPACKED,

View File

@ -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*