summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog5
-rw-r--r--Src/params.c21
-rw-r--r--Test/B02typeset.ztst14
3 files changed, 30 insertions, 10 deletions
diff --git a/ChangeLog b/ChangeLog
index ab59d83d7..5eca27d43 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -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
diff --git a/Src/params.c b/Src/params.c
index 973df3fe5..f65aa1e80 100644
--- a/Src/params.c
+++ b/Src/params.c
@@ -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) {
/*
diff --git a/Test/B02typeset.ztst b/Test/B02typeset.ztst
index d90f17d13..914eea92b 100644
--- a/Test/B02typeset.ztst
+++ b/Test/B02typeset.ztst
@@ -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