From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 29640 invoked by alias); 8 Nov 2014 20:41:28 -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: 33653 Received: (qmail 12810 invoked from network); 8 Nov 2014 20:41:27 -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-Originating-IP: [80.3.229.105] X-Spam: 0 X-Authority: v=2.1 cv=dY0O3Bne c=1 sm=1 tr=0 a=uz1KDxDNIq33yePw376BBA==:117 a=uz1KDxDNIq33yePw376BBA==:17 a=NLZqzBF-AAAA:8 a=kj9zAlcOel0A:10 a=q2GGsy2AAAAA:8 a=i2pjTgbTvCT8Ud-7seAA:9 a=CjuIK1q_8ugA:10 Date: Sat, 8 Nov 2014 20:41:23 +0000 From: Peter Stephenson To: "Zsh Hackers' List" Subject: Re: 'whence' question Message-ID: <20141108204123.1fcc698e@pws-pc.ntlworld.com> In-Reply-To: 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: Claws Mail 3.8.0 (GTK+ 2.24.7; x86_64-redhat-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit On Thu, 6 Nov 2014 13:58:56 -0800 Bart Schaefer wrote: > On Thu, Nov 6, 2014 at 1:10 PM, Peter Stephenson < > p.w.stephenson@ntlworld.com> wrote: > > > > > Don't we want something like this? > > > > 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. I hadn't worked out which additional options -m handled as it's all hidden in functions. It's not worth factoring out the common code; it would need a whole heap of options passing in, passing back a value ignored in one case, passing in both a string and a pattern where only one is used each time... Unless someone else can see a neater way. Anyway, I will commit this and someone else can apply their elegant optimisations. The results would look better with a bit more sorting, but that's a separate issue. pws diff --git a/Src/builtin.c b/Src/builtin.c index 5b711ed..dd22d09 100644 --- a/Src/builtin.c +++ b/Src/builtin.c @@ -3228,11 +3228,47 @@ bin_whence(char *nam, char **argv, Options ops, int func) scanmatchtable(builtintab, pprog, 1, 0, DISABLED, builtintab->printnode, printflags); } - /* Done search for `internal' commands, if the -p option * - * was not used. Now search the path. */ - cmdnamtab->filltable(cmdnamtab); - scanmatchtable(cmdnamtab, pprog, 1, 0, 0, - cmdnamtab->printnode, printflags); + if (all) { + char **pp, *buf, *fn; + DIR *od; + + pushheap(); + for (pp = path; *pp; pp++) { + if (!**pp) + continue; + od = opendir(*pp); + if (!od) + continue; + + while ((fn = zreaddir(od, 0))) { + if (!pattry(pprog, fn)) + continue; + + buf = zhtricat(*pp, "/", fn); + + if (iscom(buf)) { + if (wd) { + printf("%s: command\n", fn); + } else { + if (v && !csh) + zputs(fn, stdout), fputs(" is ", stdout); + zputs(buf, stdout); + if (OPT_ISSET(ops,'s')) + print_if_link(buf); + fputc('\n', stdout); + } + } + } + closedir(od); + } + popheap(); + } else { + /* Done search for `internal' commands, if the -p option * + * was not used. Now search the path. */ + cmdnamtab->filltable(cmdnamtab); + scanmatchtable(cmdnamtab, pprog, 1, 0, 0, + cmdnamtab->printnode, printflags); + } unqueue_signals(); }