Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

[PATCH] Make typeset -p1 work in combination with -m.



---
tl;dr: "typeset -p 1 -m foo" did not honour the "1" argument to the -p flag.

The PRINT_INCLUDEVALUE codepath will now pass PRINT_LINE|PRINT_TYPESET|PRINT_INCLUDEVALUE;
is that correct?

We should also teach _typeset about the new optional argument.

Cheers,

Daniel

 Src/builtin.c        | 19 ++++++++++---------
 Test/B02typeset.ztst | 20 ++++++++++++++++++++
 2 files changed, 30 insertions(+), 9 deletions(-)

diff --git a/Src/builtin.c b/Src/builtin.c
index 84a2beee0..1dc59562b 100644
--- a/Src/builtin.c
+++ b/Src/builtin.c
@@ -2026,7 +2026,7 @@ typeset_setwidth(const char * name, Param pm, Options ops, int on, int always)
 static Param
 typeset_single(char *cname, char *pname, Param pm, UNUSED(int func),
 	       int on, int off, int roff, Asgment asg, Param altpm,
-	       Options ops, int joinchar)
+	       Options ops, int joinchar, int printflags)
 {
     int usepm, tc, keeplocal = 0, newspecial = NS_NONE, readonly, dont_set = 0;
     char *subscript;
@@ -2201,10 +2201,10 @@ typeset_single(char *cname, char *pname, Param pm, UNUSED(int func),
 	on &= ~PM_LOCAL;
 	if (!on && !roff && !ASG_VALUEP(asg)) {
 	    if (OPT_ISSET(ops,'p'))
-		paramtab->printnode(&pm->node, PRINT_TYPESET);
+		paramtab->printnode(&pm->node, printflags);
 	    else if (!OPT_ISSET(ops,'g') &&
 		     (unset(TYPESETSILENT) || OPT_ISSET(ops,'m')))
-		paramtab->printnode(&pm->node, PRINT_INCLUDEVALUE);
+		paramtab->printnode(&pm->node, printflags | PRINT_INCLUDEVALUE);
 	    return pm;
 	}
 	if ((pm->node.flags & PM_RESTRICTED) && isset(RESTRICTED)) {
@@ -2272,7 +2272,7 @@ typeset_single(char *cname, char *pname, Param pm, UNUSED(int func),
 	    return NULL;
 	pm->node.flags |= (on & PM_READONLY);
 	if (OPT_ISSET(ops,'p'))
-	    paramtab->printnode(&pm->node, PRINT_TYPESET);
+	    paramtab->printnode(&pm->node, printflags);
 	return pm;
     }
 
@@ -2565,7 +2565,7 @@ typeset_single(char *cname, char *pname, Param pm, UNUSED(int func),
     pm->node.flags |= (on & PM_READONLY);
 
     if (OPT_ISSET(ops,'p'))
-	paramtab->printnode(&pm->node, PRINT_TYPESET);
+	paramtab->printnode(&pm->node, printflags);
 
     return pm;
 }
@@ -2822,7 +2822,8 @@ bin_typeset(char *name, char **argv, LinkList assigns, Options ops, int func)
 				 (Param)paramtab->getnode(paramtab,
 							  asg->name),
 				 func, (on | PM_ARRAY) & ~PM_EXPORTED,
-				 off, roff, &asg2, NULL, ops, 0))) {
+				 off, roff, &asg2, NULL, ops, 0,
+				 printflags))) {
 	    if (oldval)
 		zsfree(oldval);
 	    unqueue_signals();
@@ -2836,7 +2837,7 @@ bin_typeset(char *name, char **argv, LinkList assigns, Options ops, int func)
 				(Param)paramtab->getnode(paramtab,
 							 asg0.name),
 				func, on, off, roff, &asg0, apm,
-				ops, joinchar))) {
+				ops, joinchar, printflags))) {
 	    if (oldval)
 		zsfree(oldval);
 	    unsetparam_pm(apm, 1, 1);
@@ -2915,7 +2916,7 @@ bin_typeset(char *name, char **argv, LinkList assigns, Options ops, int func)
 	    for (pmnode = firstnode(pmlist); pmnode; incnode(pmnode)) {
 		pm = (Param) getdata(pmnode);
 		if (!typeset_single(name, pm->node.nam, pm, func, on, off, roff,
-				    asg, NULL, ops, 0))
+				    asg, NULL, ops, 0, printflags))
 		    returnval = 1;
 	    }
 	}
@@ -2940,7 +2941,7 @@ bin_typeset(char *name, char **argv, LinkList assigns, Options ops, int func)
 	}
 	if (!typeset_single(name, asg->name, (Param)hn,
 			    func, on, off, roff, asg, NULL,
-			    ops, 0))
+			    ops, 0, printflags))
 	    returnval = 1;
     }
     unqueue_signals();
diff --git a/Test/B02typeset.ztst b/Test/B02typeset.ztst
index 996af064f..b4d5ab484 100644
--- a/Test/B02typeset.ztst
+++ b/Test/B02typeset.ztst
@@ -819,3 +819,23 @@
 >  [one]=two
 >  [three]=''
 >)
+
+  typeset -a myarray
+  typeset -A myhash
+  typeset -p1 -m myarray
+  typeset -p1 -m myhash
+  myhash=( key value )
+  myarray=( key value )
+  typeset -p 1 -m myarray
+  typeset -m -p 1 myhash
+0:typeset -p1 with -m
+>typeset -a myarray=()
+>typeset -A myhash=()
+>typeset -a myarray=(
+>  key
+>  value
+>)
+>typeset -A myhash=(
+>  [key]=value
+>)
+



Messages sorted by: Reverse Date, Date, Thread, Author