1
0
Fork 0
mirror of git://git.code.sf.net/p/zsh/code synced 2024-04-30 05:45:16 +02:00

52752: typeset -p fixes for local exports and "export -x" / "readonly -r" output.

This commit is contained in:
Bart Schaefer 2024-03-14 13:11:31 -07:00
parent 21fe2dce44
commit 326e8635fe
3 changed files with 30 additions and 10 deletions

View File

@ -1,3 +1,8 @@
2024-03-14 Bart Schaefer <schaefer@zsh.org>
* 52752: Src/params.c, Test/B02typeset.ztst: more typeset -p fixes
for local exports and improper "export -x" / "readonly -r" output.
2024-03-13 Bart Schaefer <schaefer@zsh.org>
* 52753: Doc/Zsh/grammar.yo: Clarify "nocorrect" when introducing

View File

@ -6044,6 +6044,7 @@ printparamnode(HashNode hn, int printflags)
{
Param p = (Param) hn;
Param peer = NULL;
int altname = 0;
if (!(p->node.flags & PM_HASHELEM) &&
!(printflags & PRINT_WITH_NAMESPACE) && *(p->node.nam) == '.')
@ -6089,16 +6090,26 @@ printparamnode(HashNode hn, int printflags)
if (printflags & PRINT_POSIX_EXPORT) {
if (!(p->node.flags & PM_EXPORTED))
return;
altname = 'x';
printf("export ");
} else if (printflags & PRINT_POSIX_READONLY) {
if (!(p->node.flags & PM_READONLY))
return;
altname = 'r';
printf("readonly ");
} else if (locallevel && p->level >= locallevel) {
printf("typeset "); /* printf("local "); */
} else if ((p->node.flags & PM_EXPORTED) &&
!(p->node.flags & (PM_ARRAY|PM_HASHED))) {
printf("export ");
if (p->level && p->level >= locallevel)
printf("local ");
else {
altname = 'x';
printf("export ");
}
} else if (locallevel && p->level >= locallevel) {
if (p->node.flags & PM_EXPORTED)
printf("local ");
else
printf("typeset "); /* printf("local "); */
} else if (locallevel) {
printf("typeset -g ");
} else
@ -6112,6 +6123,10 @@ printparamnode(HashNode hn, int printflags)
for (pmptr = pmtypes, i = 0; i < PMTYPES_SIZE; i++, pmptr++) {
int doprint = 0;
if (altname && altname == pmptr->typeflag)
continue;
if (pmptr->flags & PMTF_TEST_LEVEL) {
if (p->level) {
/*

View File

@ -311,7 +311,7 @@
print $OUTER
0:Export of tied parameters
>i:n:n:e:r
>typeset -xT OUTER outer=( i n n e r )
>local -xT OUTER outer=( i n n e r )
>typeset -aT OUTER outer=( i n n e r )
>OUTER=i:n:n:e:r
>outer=( i n n e r )
@ -1099,12 +1099,12 @@
}
0: no array/hash in POSIX export/readonly -p
>zsh:
>typeset -arx zsh_exported_readonly_array=( 2 )
>typeset -Arx zsh_exported_readonly_hash=( [3]=3 )
>typeset -rx zsh_exported_readonly_scalar=1
>typeset -arx zsh_exported_readonly_array=( 2 )
>typeset -Arx zsh_exported_readonly_hash=( [3]=3 )
>typeset -rx zsh_exported_readonly_scalar=1
>local -arx zsh_exported_readonly_array=( 2 )
>local -Arx zsh_exported_readonly_hash=( [3]=3 )
>local -rx zsh_exported_readonly_scalar=1
>local -arx zsh_exported_readonly_array=( 2 )
>local -Arx zsh_exported_readonly_hash=( [3]=3 )
>local -rx zsh_exported_readonly_scalar=1
>sh:
>export zsh_exported_readonly_scalar=1
>readonly zsh_exported_readonly_scalar=1