From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 7380 invoked by alias); 8 Nov 2014 21:55:03 -0000 Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Workers List List-Post: List-Help: X-Seq: 33656 Received: (qmail 19792 invoked from network); 8 Nov 2014 21:55:01 -0000 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.2 X-CMAE-Score: 0 X-CMAE-Analysis: v=2.1 cv=TstRX4Tk c=1 sm=1 tr=0 a=FT8er97JFeGWzr5TCOCO5w==:117 a=kj9zAlcOel0A:10 a=q2GGsy2AAAAA:8 a=oR5dmqMzAAAA:8 a=-9mUelKeXuEA:10 a=d_m0ltwoO92wLNwn8FoA:9 a=CjuIK1q_8ugA:10 From: Bart Schaefer Message-id: <141108135508.ZM32372@torch.brasslantern.com> Date: Sat, 08 Nov 2014 13:55:08 -0800 In-reply-to: Comments: In reply to Bart Schaefer "Re: 'whence' question" (Nov 6, 1:58pm) References: <545A6D66.3080500@eastlink.ca> <1458.1415209763@thecus.kiddle.eu> <20141105180035.22f6e9b1@pwslap01u.europe.root.pri> <141105204330.ZM2973@torch.brasslantern.com> <20141106211017.11b8848a@pws-pc.ntlworld.com> X-Mailer: OpenZMail Classic (0.9.2 24April2005) To: "Zsh Hackers' List" Subject: Re: 'whence' question MIME-version: 1.0 Content-type: text/plain; charset=us-ascii On Nov 6, 1:58pm, Bart Schaefer wrote: } } Yes, we want something LIKE that, but simply calling zputs() doesn't } handle either the -v or the -s options, and it seems a shame to } duplicate all that code from the existing "if (all)" loop later in the } function. This is what I was thinking when I asked about ${(k)commands[(I)pat]}. I wish there were a better way to make fetchcmdnamnode a closure, but what you C is what you get ... diff --git a/Src/builtin.c b/Src/builtin.c index 5b711ed..c2af51f 100644 --- a/Src/builtin.c +++ b/Src/builtin.c @@ -3154,6 +3154,15 @@ bin_unset(char *name, char **argv, Options ops, int func) /* type, whence, which, command */ +static LinkList matchednodes; + +static void +fetchcmdnamnode(HashNode hn, UNUSED(int printflags)) +{ + Cmdnam cn = (Cmdnam) hn; + addlinknode(matchednodes, cn->node.nam); +} + /**/ int bin_whence(char *nam, char **argv, Options ops, int func) @@ -3165,7 +3174,7 @@ bin_whence(char *nam, char **argv, Options ops, int func) int aliasflags; int csh, all, v, wd; int informed; - char *cnam; + char *cnam, **allmatched = 0; /* Check some option information */ csh = OPT_ISSET(ops,'c'); @@ -3198,6 +3207,10 @@ bin_whence(char *nam, char **argv, Options ops, int func) /* With -m option -- treat arguments as a glob patterns */ if (OPT_ISSET(ops,'m')) { + if (all) { + pushheap(); + matchednodes = newlinklist(); + } for (; *argv; argv++) { /* parse the pattern */ tokenize(*argv); @@ -3232,11 +3245,17 @@ bin_whence(char *nam, char **argv, Options ops, int func) * was not used. Now search the path. */ cmdnamtab->filltable(cmdnamtab); scanmatchtable(cmdnamtab, pprog, 1, 0, 0, - cmdnamtab->printnode, printflags); + (all ? fetchcmdnamnode : cmdnamtab->printnode), + printflags); unqueue_signals(); } - return returnval; + if (all) { + allmatched = argv = zlinklist2array(matchednodes); + matchednodes = NULL; + popheap(); + } else + return returnval; } /* Take arguments literally -- do not glob */ @@ -3244,7 +3263,7 @@ bin_whence(char *nam, char **argv, Options ops, int func) for (; *argv; argv++) { informed = 0; - if (!OPT_ISSET(ops,'p')) { + if (!OPT_ISSET(ops,'p') && !allmatched) { char *suf; /* Look for alias */ @@ -3344,6 +3363,9 @@ bin_whence(char *nam, char **argv, Options ops, int func) returnval = 1; } } + if (allmatched) + freearray(allmatched); + unqueue_signals(); return returnval; } -- Barton E. Schaefer