zsh-workers
 help / color / mirror / code / Atom feed
* [PATCH] Make typeset -p1 work in combination with -m.
@ 2017-10-17 18:27 ` Daniel Shahaf
  2017-10-17 18:56   ` Oliver Kiddle
  2017-10-18  8:31   ` Peter Stephenson
  0 siblings, 2 replies; 6+ messages in thread
From: Daniel Shahaf @ 2017-10-17 18:27 UTC (permalink / raw)
  To: zsh-workers

---
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
+>)
+


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] Make typeset -p1 work in combination with -m.
  2017-10-17 18:27 ` [PATCH] Make typeset -p1 work in combination with -m Daniel Shahaf
@ 2017-10-17 18:56   ` Oliver Kiddle
  2017-10-18  8:31   ` Peter Stephenson
  1 sibling, 0 replies; 6+ messages in thread
From: Oliver Kiddle @ 2017-10-17 18:56 UTC (permalink / raw)
  To: zsh-workers

Daniel Shahaf wrote:
> We should also teach _typeset about the new optional argument.

Like this, right?

diff --git a/Completion/Zsh/Command/_typeset b/Completion/Zsh/Command/_typeset
index 160150234..fb9e3ab5e 100644
--- a/Completion/Zsh/Command/_typeset
+++ b/Completion/Zsh/Command/_typeset
@@ -30,7 +30,7 @@ allargs=(
   k "($popts -w -z)-+k[mark function for ksh-style autoloading]"
   l "($popts -T)-l[convert the value to lowercase]"
   m '(-A -E -F -T -i)-m[treat arguments as patterns]'
-  p '-p[output parameters in form of calls to typeset]'
+  p '-p+[output parameters in form of calls to typeset]::option:((1\:multi-line\ output\ of\ arrays))'
   r '(-f)-+r[mark parameters as readonly]'
   rf '-r[remember autoload path]'
   Rf '-R[remember autoload path, error if not found]'


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] Make typeset -p1 work in combination with -m.
  2017-10-17 18:27 ` [PATCH] Make typeset -p1 work in combination with -m Daniel Shahaf
  2017-10-17 18:56   ` Oliver Kiddle
@ 2017-10-18  8:31   ` Peter Stephenson
  2017-10-19 14:40     ` Daniel Shahaf
  1 sibling, 1 reply; 6+ messages in thread
From: Peter Stephenson @ 2017-10-18  8:31 UTC (permalink / raw)
  To: zsh-workers

On Tue, 17 Oct 2017 18:27:00 +0000
Daniel Shahaf <d.s@daniel.shahaf.name> wrote:
> The PRINT_INCLUDEVALUE codepath will now pass
> PRINT_LINE|PRINT_TYPESET|PRINT_INCLUDEVALUE; is that correct?

Yes, as long as the resulting output makes sense the flag can be passed
through.

pws


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] Make typeset -p1 work in combination with -m.
  2017-10-18  8:31   ` Peter Stephenson
@ 2017-10-19 14:40     ` Daniel Shahaf
  2017-10-19 18:24       ` Daniel Shahaf
  0 siblings, 1 reply; 6+ messages in thread
From: Daniel Shahaf @ 2017-10-19 14:40 UTC (permalink / raw)
  To: zsh-workers

Peter Stephenson wrote on Wed, Oct 18, 2017 at 09:31:19 +0100:
> On Tue, 17 Oct 2017 18:27:00 +0000
> Daniel Shahaf <d.s@daniel.shahaf.name> wrote:
> > The PRINT_INCLUDEVALUE codepath will now pass
> > PRINT_LINE|PRINT_TYPESET|PRINT_INCLUDEVALUE; is that correct?
> 
> Yes, as long as the resulting output makes sense the flag can be passed
> through.

Ack.  I'll double check the output before pushing.


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] Make typeset -p1 work in combination with -m.
  2017-10-19 14:40     ` Daniel Shahaf
@ 2017-10-19 18:24       ` Daniel Shahaf
  2017-10-20  9:41         ` Peter Stephenson
  0 siblings, 1 reply; 6+ messages in thread
From: Daniel Shahaf @ 2017-10-19 18:24 UTC (permalink / raw)
  To: zsh-workers

Daniel Shahaf wrote on Thu, 19 Oct 2017 14:40 +0000:
> Peter Stephenson wrote on Wed, Oct 18, 2017 at 09:31:19 +0100:
> > On Tue, 17 Oct 2017 18:27:00 +0000
> > Daniel Shahaf <d.s@daniel.shahaf.name> wrote:
> > > The PRINT_INCLUDEVALUE codepath will now pass
> > > PRINT_LINE|PRINT_TYPESET|PRINT_INCLUDEVALUE; is that correct?
> > 
> > Yes, as long as the resulting output makes sense the flag can be passed
> > through.
> 
> Ack.  I'll double check the output before pushing.

There's an unwanted output change:

before% typeset -m argv
argv=(  )

after% typeset -m argv
array argv

It persists even if I strip the PRINT_TYPESET bit at the PRINT_INCLUDEVALUE callsite.

Hopefully this rings a bell to someone?  It looks like some issue with the PRINT_* flags.

In the meantime here's a regression test.

Daniel

diff --git a/Test/B02typeset.ztst b/Test/B02typeset.ztst
index 996af064f..3aea55d4c 100644
--- a/Test/B02typeset.ztst
+++ b/Test/B02typeset.ztst
@@ -794,6 +794,10 @@
 1:Mixed syntax with [key]=val not allowed for hash.
 ?(eval):1: bad [key]=value syntax for associative array
 
+  () { typeset -m argv }
+0:typeset -m of array, without pattern matching (regression)
+>argv=(  )
+
   local -a myarray
   typeset -p1 myarray
   myarray=("&" sand '""' "" plugh)


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] Make typeset -p1 work in combination with -m.
  2017-10-19 18:24       ` Daniel Shahaf
@ 2017-10-20  9:41         ` Peter Stephenson
  0 siblings, 0 replies; 6+ messages in thread
From: Peter Stephenson @ 2017-10-20  9:41 UTC (permalink / raw)
  To: zsh-workers

On Thu, 19 Oct 2017 18:24:11 +0000
Daniel Shahaf <d.s@daniel.shahaf.name> wrote:

> Daniel Shahaf wrote on Thu, 19 Oct 2017 14:40 +0000:
> > Peter Stephenson wrote on Wed, Oct 18, 2017 at 09:31:19 +0100:
> > > On Tue, 17 Oct 2017 18:27:00 +0000
> > > Daniel Shahaf <d.s@daniel.shahaf.name> wrote:
> > > > The PRINT_INCLUDEVALUE codepath will now pass
> > > > PRINT_LINE|PRINT_TYPESET|PRINT_INCLUDEVALUE; is that correct?
> > > 
> > > Yes, as long as the resulting output makes sense the flag can be passed
> > > through.
> > 
> > Ack.  I'll double check the output before pushing.
> 
> There's an unwanted output change:
> 
> before% typeset -m argv
> argv=(  )
> 
> after% typeset -m argv
> array argv

That can only be this chunk at the end of printparamnode() --- there's
nowhere else where we deal with the value.  So something you've done has
changed the result of that first test.  You'll probably just have to
step through and look at what's happening here.

pws

    if ((printflags & PRINT_NAMEONLY) ||
	((p->node.flags & PM_HIDEVAL) && !(printflags & PRINT_INCLUDEVALUE))) {
	zputs(p->node.nam, stdout);
	putchar('\n');
    } else {
	if (printflags & PRINT_KV_PAIR) {
	    if (printflags & PRINT_LINE)
		printf("\n  ");
	    putchar('[');
	}
	quotedzputs(p->node.nam, stdout);
	if (printflags & PRINT_KV_PAIR)
	    printf("]=");

	printparamvalue(p, printflags);
    }


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2017-10-20  9:48 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <CGME20171017182806epcas1p25cabca4be0c223080d6aa3b8fbd30055@epcas1p2.samsung.com>
2017-10-17 18:27 ` [PATCH] Make typeset -p1 work in combination with -m Daniel Shahaf
2017-10-17 18:56   ` Oliver Kiddle
2017-10-18  8:31   ` Peter Stephenson
2017-10-19 14:40     ` Daniel Shahaf
2017-10-19 18:24       ` Daniel Shahaf
2017-10-20  9:41         ` Peter Stephenson

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).