Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
[PATCH] Make typeset -p1 work in combination with -m.
- X-seq: zsh-workers 41925
 
- From: Daniel Shahaf <d.s@xxxxxxxxxxxxxxxxxx>
 
- To: zsh-workers@xxxxxxx
 
- Subject: [PATCH] Make typeset -p1 work in combination with -m.
 
- Date: Tue, 17 Oct 2017 18:27:00 +0000
 
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=	daniel.shahaf.name; h=date:from:message-id:subject:to	:x-me-sender:x-me-sender:x-sasl-enc; s=fm1; bh=Ol9Oc1cKlbATKWEUL	ERoghGx2wp/aTLFS8eroVvyCM4=; b=JfMHMgnKweY9pDg8tfSVVTm79hlre407x	zzmxKvD4z7gIIeSFlwbIGkxEk226eALKEQGDBKcdp6MlwzA/Vz5+L6lEBJqGeKcg	aIUcFC9Pn+KINx3sl1148QQQzH4DFYBmSlSHGVupWL6riIHA7Kwti/qNq16Ktxl4	IrBjHozkLwfXqnn7e++V6WHQDN4VZ+ITSrubjqbjaTprf3+4GmwiF49u2aHdIWDB	qnq7ueY+BQL8HFptR1xBdlX2ZWtDyV0LgQpr9RGMeMovKS9uvG5H1/xg1Uxz2CT8	SZT58r5nKOZc/yDUO/JbViJk8XOTGTd9EVh9DY3jQQ6GewdY5BH9Q==
 
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=	messagingengine.com; h=date:from:message-id:subject:to	:x-me-sender:x-me-sender:x-sasl-enc; s=fm1; bh=Ol9Oc1cKlbATKWEUL	ERoghGx2wp/aTLFS8eroVvyCM4=; b=aSaVBV9Rv9LC8Am/wFAMBB+Wcu2A88xPr	kHXgC1EOEgWYlXEovr2Wpo8bztRnUMaxXxYAv14bpKYI/vEkgpOdhrfPkoQHCjGr	+tmSGxtQ9W8x90UKjwoosiBYhbxGGG56tuBeh+4ZfM3WFGCT3vZam7yfFxnxeaT+	ombhnBPe5NiUF6FuxUJHnUr2QI9hMlzvsRaFN6stFFtpSnOWbIq4fYb87sfu1EFZ	TDSLhtnTxyA7o6odVanAzGe9yGJr22H03N5h/J5soDfmT9JH+cyMjqZgmhWn4kLv	0nGPd657LA9Otn/Kbew80rskxzNMYfsAkAs8KWIEDkOl9fAD/Qt0g==
 
- List-help: <mailto:zsh-workers-help@zsh.org>
 
- List-id: Zsh Workers List <zsh-workers.zsh.org>
 
- List-post: <mailto:zsh-workers@zsh.org>
 
- List-unsubscribe: <mailto:zsh-workers-unsubscribe@zsh.org>
 
- Mailing-list: contact zsh-workers-help@xxxxxxx; run by ezmlm
 
---
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