zsh-workers
 help / color / mirror / code / Atom feed
From: Peter Stephenson <p.w.stephenson@ntlworld.com>
To: "Zsh Hackers' List" <zsh-workers@zsh.org>
Subject: Re: 'whence' question
Date: Sat, 8 Nov 2014 20:41:23 +0000	[thread overview]
Message-ID: <20141108204123.1fcc698e@pws-pc.ntlworld.com> (raw)
In-Reply-To: <CAH+w=7ZwAdoO7XzU6_j60f9+i-ft5t-d2st98i-ew2fEmQxDzw@mail.gmail.com>

On Thu, 6 Nov 2014 13:58:56 -0800
Bart Schaefer <schaefer@brasslantern.com> 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();
 	}


  reply	other threads:[~2014-11-08 20:41 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <545A6D66.3080500@eastlink.ca>
     [not found] ` <1458.1415209763@thecus.kiddle.eu>
     [not found]   ` <20141105180035.22f6e9b1@pwslap01u.europe.root.pri>
     [not found]     ` <141105204330.ZM2973@torch.brasslantern.com>
2014-11-06 21:10       ` Peter Stephenson
2014-11-06 21:58         ` Bart Schaefer
2014-11-08 20:41           ` Peter Stephenson [this message]
2014-11-09 18:51             ` Bart Schaefer
2014-11-10  5:15               ` 'whence' question and others Ray Andrews
2014-11-10  8:20                 ` Bart Schaefer
2014-11-10  8:23                   ` Bart Schaefer
2014-11-10 16:57                   ` Ray Andrews
2014-11-10 19:53                     ` Vin Shelton
2014-11-11 16:52               ` 'whence' question Ray Andrews
2014-11-11 19:14                 ` Bart Schaefer
2014-11-11 19:38                   ` Bart Schaefer
2014-11-11 20:22                   ` Ray Andrews
2014-11-11 18:16               ` Ray Andrews
2014-11-11 19:33                 ` Bart Schaefer
2014-11-11 20:40                   ` Ray Andrews
2014-11-08 21:55           ` Bart Schaefer
2014-11-10 10:04             ` 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=20141108204123.1fcc698e@pws-pc.ntlworld.com \
    --to=p.w.stephenson@ntlworld.com \
    --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).