1
0
Fork 0
mirror of git://git.code.sf.net/p/zsh/code synced 2024-05-12 10:36:17 +02:00

"typeset -p" uses "export" commands or the "-g" option for parameters that are not local to the current scope

This commit is contained in:
Barton E. Schaefer 2016-10-24 07:14:39 -07:00
parent 71dd0ab62e
commit 0f5e670cde
7 changed files with 39 additions and 10 deletions

View File

@ -1,3 +1,12 @@
2016-10-24 Barton E. Schaefer <schaefer@zsh.org>
* unposted: NEWS, README: update for 39704.
* 39704: Src/params.c, Test/B02typeset.ztst, Test/B03print.ztst,
Test/V10private.ztst: the output of "typeset -p" uses "export"
commands or the "-g" option for parameters that are not local to
the current scope.
2016-10-24 Daniel Shahaf <d.s@daniel.shahaf.name>
* 39706: Completion/Unix/Type/_tilde_files, Doc/Zsh/compsys.yo:

3
NEWS
View File

@ -15,6 +15,9 @@ removed, even when /before/here is itself a symbolic link. It is
recommended to review uses of ':A' and, if appropriate, convert them
to ':P' as soon as compatibility with 5.2 is no longer a requirement.
The output of "typeset -p" uses "export" commands or the "-g" option
for parameters that are not local to the current scope.
Changes from 5.1.1 to 5.2
-------------------------

5
README
View File

@ -110,6 +110,11 @@ possible to return a non-zero status to the parent shell from a command
executed as a replacement, and the new implementation is more consistent
with other shells.
7) The output of "typeset -p" (and synonyms) now takes into account the
function scope and export state of each parameter. Exported parameters
are output as "export" commands unless the parameter is also local, and
other parameters not local to the scope are output with the "-g" option.
Incompatibilities between 5.0.8 and 5.2
---------------------------------------

View File

@ -5225,7 +5225,7 @@ printparamvalue(Param p, int printflags)
{
char *t, **u;
if (p->node.flags & PM_AUTOLOAD) {
if ((p->node.flags & PM_EXPORTED) && !p->env) {
putchar('\n');
return;
}
@ -5312,9 +5312,13 @@ printparamnode(HashNode hn, int printflags)
*/
printflags |= PRINT_NAMEONLY;
}
else if (p->node.flags & PM_EXPORTED)
printflags |= PRINT_NAMEONLY;
else
return;
}
if (p->node.flags & PM_AUTOLOAD)
printflags |= PRINT_NAMEONLY;
if (printflags & PRINT_TYPESET) {
if ((p->node.flags & (PM_READONLY|PM_SPECIAL)) ==
@ -5326,7 +5330,14 @@ printparamnode(HashNode hn, int printflags)
*/
return;
}
printf("typeset ");
if (locallevel && p->level >= locallevel) {
printf("typeset "); /* printf("local "); */
} else if (p->node.flags & PM_EXPORTED) {
printf("export ");
} else if (locallevel) {
printf("typeset -g ");
} else
printf("typeset ");
}
/* Print the attributes of the parameter */
@ -5339,7 +5350,9 @@ printparamnode(HashNode hn, int printflags)
if (pmptr->flags & PMTF_TEST_LEVEL) {
if (p->level)
doprint = 1;
} else if (p->node.flags & pmptr->binflag)
} else if ((pmptr->binflag != PM_EXPORTED ||
((p->node.flags & PM_LOCAL) || p->level)) &&
(p->node.flags & pmptr->binflag))
doprint = 1;
if (doprint) {
@ -5351,9 +5364,8 @@ printparamnode(HashNode hn, int printflags)
}
putchar(pmptr->typeflag);
}
} else {
} else
printf("%s ", pmptr->string);
}
if ((pmptr->flags & PMTF_USE_BASE) && p->base) {
printf("%d ", p->base);
doneminus = 0;

View File

@ -454,7 +454,7 @@
fn() { typeset -p array nonexistent; }
fn
1:declare -p shouldn't create scoped values
>typeset -a array=( foo bar )
>typeset -g -a array=( foo bar )
?fn:typeset: no such variable: nonexistent
unsetopt typesetsilent
@ -490,7 +490,7 @@
?0
?(eval):5: read-only variable: pbro
?(eval):6: read-only variable: pbro
?typeset -r pbro
?typeset -g -r pbro
?0
?(eval):10: read-only variable: pbro

View File

@ -308,5 +308,5 @@
printf -v foo "%s\0%s-" into the breach
typeset -p foo
0:print and printf into a variable
>typeset foo='once more'
>typeset foo=$'into\C-@the-breach\C-@-'
>typeset -g foo='once more'
>typeset -g foo=$'into\C-@the-breach\C-@-'

View File

@ -129,7 +129,7 @@
0:private hides value from surrounding scope in nested scope
>typeset -a hash_test=( top level )
>typeset -A hash_test=( in function )
>typeset -a hash_test=( top level )
>typeset -g -a hash_test=( top level )
>array-local top level
>top level
F:note "typeset" rather than "private" in output from outer