From: Daniel Shahaf <d.s@daniel.shahaf.name>
To: zsh-workers@zsh.org
Subject: [PATCH] Make typeset -p1 work in combination with -m.
Date: Tue, 17 Oct 2017 18:27:00 +0000 [thread overview]
Message-ID: <20171017182700.28303-1-danielsh@tarpaulin.shahaf.local2> (raw)
---
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
+>)
+
next reply other threads:[~2017-10-17 18:27 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <CGME20171017182806epcas1p25cabca4be0c223080d6aa3b8fbd30055@epcas1p2.samsung.com>
2017-10-17 18:27 ` Daniel Shahaf [this message]
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20171017182700.28303-1-danielsh@tarpaulin.shahaf.local2 \
--to=d.s@daniel.shahaf.name \
--cc=zsh-workers@zsh.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).