mirror of
git://git.code.sf.net/p/zsh/code
synced 2025-09-01 09:41:44 +02:00
37305: typeset -p can now output arrays on one line
This commit is contained in:
parent
dc8c39efff
commit
16684952fb
5 changed files with 13 additions and 45 deletions
|
@ -1,5 +1,9 @@
|
|||
2015-12-04 Peter Stephenson <p.stephenson@samsung.com>
|
||||
|
||||
* 37305: Src/params.c, Test/A06assign.ztst,
|
||||
Test/B02typeset.ztst, Test/V10private.ztst: typeset -p
|
||||
can now output arrays on one line.
|
||||
|
||||
* unposted: Src/exec.c, Src/init.c: fix up init_io() calls
|
||||
in previous change.
|
||||
|
||||
|
|
26
Src/params.c
26
Src/params.c
|
@ -5182,9 +5182,6 @@ printparamvalue(Param p, int printflags)
|
|||
}
|
||||
if (printflags & PRINT_KV_PAIR)
|
||||
putchar(' ');
|
||||
else if ((printflags & PRINT_TYPESET) &&
|
||||
(PM_TYPE(p->node.flags) == PM_ARRAY || PM_TYPE(p->node.flags) == PM_HASHED))
|
||||
printf("%s=", p->node.nam);
|
||||
else
|
||||
putchar('=');
|
||||
|
||||
|
@ -5255,7 +5252,6 @@ mod_export void
|
|||
printparamnode(HashNode hn, int printflags)
|
||||
{
|
||||
Param p = (Param) hn;
|
||||
int array_typeset;
|
||||
|
||||
if (p->node.flags & PM_UNSET) {
|
||||
if (isset(POSIXBUILTINS) && (p->node.flags & PM_READONLY) &&
|
||||
|
@ -5280,28 +5276,8 @@ printparamnode(HashNode hn, int printflags)
|
|||
*/
|
||||
return;
|
||||
}
|
||||
/*
|
||||
* Printing the value of array: this needs to be on
|
||||
* a separate line so more care is required.
|
||||
*/
|
||||
array_typeset = (PM_TYPE(p->node.flags) == PM_ARRAY ||
|
||||
PM_TYPE(p->node.flags) == PM_HASHED) &&
|
||||
!(printflags & PRINT_NAMEONLY);
|
||||
if (array_typeset && (p->node.flags & PM_READONLY)) {
|
||||
/*
|
||||
* We need to create the array before making it
|
||||
* readonly.
|
||||
*/
|
||||
printf("typeset -a ");
|
||||
zputs(p->node.nam, stdout);
|
||||
putchar('\n');
|
||||
printparamvalue(p, printflags);
|
||||
printflags |= PRINT_NAMEONLY;
|
||||
}
|
||||
printf("typeset ");
|
||||
}
|
||||
else
|
||||
array_typeset = 0;
|
||||
|
||||
/* Print the attributes of the parameter */
|
||||
if (printflags & (PRINT_TYPE|PRINT_TYPESET)) {
|
||||
|
@ -5349,8 +5325,6 @@ printparamnode(HashNode hn, int printflags)
|
|||
} else {
|
||||
quotedzputs(p->node.nam, stdout);
|
||||
|
||||
if (array_typeset)
|
||||
putchar('\n');
|
||||
printparamvalue(p, printflags);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -437,8 +437,7 @@
|
|||
typeset -p i n x f)
|
||||
0:GLOB_ASSIGN with numeric types
|
||||
>typeset -i i=0
|
||||
>typeset -a n
|
||||
>n=( tmpfile1 tmpfile2 )
|
||||
>typeset -a n=( tmpfile1 tmpfile2 )
|
||||
>typeset x=tmpfile2
|
||||
>typeset -E f=4.000000000e+00
|
||||
|
||||
|
|
|
@ -454,8 +454,7 @@
|
|||
fn() { typeset -p array nonexistent; }
|
||||
fn
|
||||
1:declare -p shouldn't create scoped values
|
||||
>typeset -a array
|
||||
>array=( foo bar )
|
||||
>typeset -a array=( foo bar )
|
||||
?fn:typeset: no such variable: nonexistent
|
||||
|
||||
unsetopt typesetsilent
|
||||
|
@ -508,11 +507,8 @@
|
|||
typeset -pm 'a[12]'
|
||||
typeset -pm 'r[12]'
|
||||
0:readonly -p output
|
||||
>typeset -a a1
|
||||
>a1=( one two )
|
||||
>typeset -ar a1
|
||||
>typeset -a a2
|
||||
>a2=( three four )
|
||||
>typeset -ar a1=( one two )
|
||||
>typeset -a a2=( three four )
|
||||
>typeset -r r1=yes
|
||||
>typeset -r r2=no
|
||||
|
||||
|
@ -707,8 +703,6 @@
|
|||
fn
|
||||
print $array
|
||||
0:setting empty array in typeset
|
||||
>typeset -a array
|
||||
>array=( '' two '' four )
|
||||
>typeset -a array
|
||||
>array=( one '' three )
|
||||
>typeset -a array=( '' two '' four )
|
||||
>typeset -a array=( one '' three )
|
||||
>no really nothing here
|
||||
|
|
|
@ -127,12 +127,9 @@
|
|||
outer
|
||||
print ${(kv)hash_test}
|
||||
0:private hides value from surrounding scope in nested scope
|
||||
>typeset -a hash_test
|
||||
>hash_test=( top level )
|
||||
>typeset -A hash_test
|
||||
>hash_test=( in function )
|
||||
>typeset -a hash_test
|
||||
>hash_test=( top level )
|
||||
>typeset -a hash_test=( top level )
|
||||
>typeset -A hash_test=( in function )
|
||||
>typeset -a hash_test=( top level )
|
||||
>array-local top level
|
||||
>top level
|
||||
F:note "typeset" rather than "private" in output from outer
|
||||
|
|
Loading…
Reference in a new issue