zsh-workers
 help / color / mirror / code / Atom feed
* Re: symlink chain.
       [not found]                               ` <150104003130.ZM24261@torch.brasslantern.com>
@ 2015-01-04 18:04                                 ` Vin Shelton
  2015-01-04 18:51                                   ` Peter Stephenson
  2015-01-04 19:39                                   ` Peter Stephenson
       [not found]                                 ` <54A9A76A.7020303@eastlink.ca>
  1 sibling, 2 replies; 4+ messages in thread
From: Vin Shelton @ 2015-01-04 18:04 UTC (permalink / raw)
  To: Zsh Hackers' List

"whence -s" no longer works in a way I would expect.  To wit:

$ echo $PATH
/home/acs/bin:/opt/bin:/usr/bin:/bin:/usr/sbin:/sbin:/etc

$ ls -ld /opt /opt/xemacs /opt/bin/xemacs
lrwxrwxrwx 1 root root 12 Nov 30 23:09 /opt -> raid-3tb/opt
lrwxrwxrwx 1 acs  acs  20 Nov 19  2013 /opt/bin/xemacs -> ../xemacs/bin/xemacs
lrwxrwxrwx 1 acs  acs  22 Jan  1 08:57 /opt/xemacs -> xemacs-21.4-2015-01-01

So /opt/bin/xemacs points to a particular xemacs installation

$ /opt/zsh-2015-01-01/bin/zsh -f
legolas-i5% whence -s xemacs
/opt/bin/xemacs -> /raid-3tb/opt/xemacs-21.4-2015-01-01/bin/xemacs-21.4.22

This version (2015-01-01) makes sense, ultimately resolving the path to a file.

$ /opt/zsh-2015-01-04/bin/zsh -f
legolas-i5% whence -s xemacs
/opt/bin/xemacs -> /raid-3tb/opt

This version is wrong.

Can we please have the old behavior back?

Thank you,
  Vin


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

* Re: symlink chain.
  2015-01-04 18:04                                 ` symlink chain Vin Shelton
@ 2015-01-04 18:51                                   ` Peter Stephenson
  2015-01-04 19:39                                   ` Peter Stephenson
  1 sibling, 0 replies; 4+ messages in thread
From: Peter Stephenson @ 2015-01-04 18:51 UTC (permalink / raw)
  To: Zsh Hackers' List

On Sun, 4 Jan 2015 13:04:20 -0500
Vin Shelton <acs@alumni.princeton.edu> wrote:
> "whence -s" no longer works in a way I would expect.

It doesn't work at all with chains of links owing to a typo when I add
-S...

diff --git a/Src/utils.c b/Src/utils.c
index 2b2a815..959df9a 100644
--- a/Src/utils.c
+++ b/Src/utils.c
@@ -795,12 +795,12 @@ xsymlinks(char *s, int full)
 	    }
 	    if (*xbuf3 == '/') {
 		strcpy(xbuf, "");
-		if (xsymlinks(xbuf3 + 1, 0) < 0)
+		if (xsymlinks(xbuf3 + 1, 1) < 0)
 		    ret = -1;
 		else
 		    xbuflen = strlen(xbuf);
 	    } else
-		if (xsymlinks(xbuf3, 0) < 0)
+		if (xsymlinks(xbuf3, 1) < 0)
 		    ret = -1;
 		else
 		    xbuflen = strlen(xbuf);

-- 
Peter Stephenson <p.w.stephenson@ntlworld.com>
Web page now at http://homepage.ntlworld.com/p.w.stephenson/


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

* Re: symlink chain.
  2015-01-04 18:04                                 ` symlink chain Vin Shelton
  2015-01-04 18:51                                   ` Peter Stephenson
@ 2015-01-04 19:39                                   ` Peter Stephenson
  1 sibling, 0 replies; 4+ messages in thread
From: Peter Stephenson @ 2015-01-04 19:39 UTC (permalink / raw)
  To: Zsh Hackers' List

On Sun, 4 Jan 2015 13:04:20 -0500
Vin Shelton <acs@alumni.princeton.edu> wrote:
> $ echo $PATH
> /home/acs/bin:/opt/bin:/usr/bin:/bin:/usr/sbin:/sbin:/etc
> 
> $ ls -ld /opt /opt/xemacs /opt/bin/xemacs
> lrwxrwxrwx 1 root root 12 Nov 30 23:09 /opt -> raid-3tb/opt
> lrwxrwxrwx 1 acs  acs  20 Nov 19  2013 /opt/bin/xemacs -> ../xemacs/bin/xemacs
> lrwxrwxrwx 1 acs  acs  22 Jan  1 08:57 /opt/xemacs -> xemacs-21.4-2015-01-01
> 
> So /opt/bin/xemacs points to a particular xemacs installation
> 
> $ /opt/zsh-2015-01-01/bin/zsh -f
> legolas-i5% whence -s xemacs
> /opt/bin/xemacs -> /raid-3tb/opt/xemacs-21.4-2015-01-01/bin/xemacs-21.4.22

This interesting example of chains of symlinkx tickles an existing
problem with xsymlinks() (I think --- its behaviour is a bit obscure)
that causes whence -S to fail.  In resolving "..", xbuflen counts the
final '\0', which it doesn't elsewhere --- xbuflen at the end is
equivalent to strlen(xbuf) after the final '\0' has been appended.

This was obscured by the fact that we usually strcat() onto xbuf, so
making xbuflen less useful than it might be.  The code I added uses
strcpy(xbuf + xbuflen), hence showing the problem.  It would be
preferable to use strcpy() in both places but I'm fed up fixing bugs for
today.

diff --git a/Src/utils.c b/Src/utils.c
index 959df9a..390f513 100644
--- a/Src/utils.c
+++ b/Src/utils.c
@@ -741,6 +741,8 @@ xsymlinks(char *s, int full)
 	    while (*--p != '/')
 		xbuflen--;
 	    *p = '\0';
+	    /* The \0 isn't included in the length */
+	    xbuflen--;
 	    continue;
 	}
 	sprintf(xbuf2, "%s/%s", xbuf, *pp);

pws


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

* [PATCH] Exit status of "whence" (Re: symlink chain.)
       [not found]                                   ` <150104173448.ZM19453@torch.brasslantern.com>
@ 2015-01-05  2:05                                     ` Bart Schaefer
  0 siblings, 0 replies; 4+ messages in thread
From: Bart Schaefer @ 2015-01-05  2:05 UTC (permalink / raw)
  To: zsh-workers

On Jan 4,  5:34pm, Bart Schaefer wrote:
}
} 	whence -m /this/is/a/file/path
} and
} 	whence -a this_is_not_a_command
} 
} both return zero.  Other cases in which whence does not find anything
} return nonzero.  So you can't successfully write
} 
} 	whence -m $1 || whence -a $1 || whence $1
} 
} which would be the "normal" way to do what you want.  I think whence
} should return a detectable failure when the pattern doesn't match,
} rather than just output nothing.

I think this does it.  I hope nobody objects to my having minimized the
diffs by not re-indenting everything.  I also factored out filltable()
because it doesn't seem like it should be necessary to repeat it for
every argument.  Yes, this fills the command table even on a bad search
pattern ... is that terrible?

Note that if you do "whence this that those" you get an exit status of
zero if ANY of them are found.  I think that was always the case.

diff --git a/Src/builtin.c b/Src/builtin.c
index ebc0654..4a46cbc 100644
--- a/Src/builtin.c
+++ b/Src/builtin.c
@@ -3173,7 +3173,7 @@ bin_whence(char *nam, char **argv, Options ops, int func)
     int printflags = 0;
     int aliasflags;
     int csh, all, v, wd;
-    int informed;
+    int informed = 0;
     char *cnam, **allmatched = 0;
 
     /* Check some option information */
@@ -3207,6 +3207,7 @@ bin_whence(char *nam, char **argv, Options ops, int func)
 
     /* With -m option -- treat arguments as a glob patterns */
     if (OPT_ISSET(ops,'m')) {
+	cmdnamtab->filltable(cmdnamtab);
 	if (all) {
 	    pushheap();
 	    matchednodes = newlinklist();
@@ -3225,17 +3226,19 @@ bin_whence(char *nam, char **argv, Options ops, int func)
 		/* -p option is for path search only.    *
 		 * We're not using it, so search for ... */
 
+		informed = /* logical OR of what follows */
+
 		/* aliases ... */
 		scanmatchtable(aliastab, pprog, 1, 0, DISABLED,
-			       aliastab->printnode, printflags);
+			       aliastab->printnode, printflags) ||
 
 		/* and reserved words ... */
 		scanmatchtable(reswdtab, pprog, 1, 0, DISABLED,
-			       reswdtab->printnode, printflags);
+			       reswdtab->printnode, printflags) ||
 
 		/* and shell functions... */
 		scanmatchtable(shfunctab, pprog, 1, 0, DISABLED,
-			       shfunctab->printnode, printflags);
+			       shfunctab->printnode, printflags) ||
 
 		/* and builtins. */
 		scanmatchtable(builtintab, pprog, 1, 0, DISABLED,
@@ -3243,7 +3246,7 @@ bin_whence(char *nam, char **argv, Options ops, int func)
 	    }
 	    /* Done search for `internal' commands, if the -p option *
 	     * was not used.  Now search the path.                   */
-	    cmdnamtab->filltable(cmdnamtab);
+	    informed +=
 	    scanmatchtable(cmdnamtab, pprog, 1, 0, 0,
 			   (all ? fetchcmdnamnode : cmdnamtab->printnode),
 			   printflags);
@@ -3255,61 +3258,59 @@ bin_whence(char *nam, char **argv, Options ops, int func)
 	    matchednodes = NULL;
 	    popheap();
 	} else
-	    return returnval;
+	    return returnval || !informed;
     }
 
     /* Take arguments literally -- do not glob */
     queue_signals();
     for (; *argv; argv++) {
-	informed = 0;
-
 	if (!OPT_ISSET(ops,'p') && !allmatched) {
 	    char *suf;
 
 	    /* Look for alias */
 	    if ((hn = aliastab->getnode(aliastab, *argv))) {
 		aliastab->printnode(hn, aliasflags);
+		informed = 1;
 		if (!all)
 		    continue;
-		informed = 1;
 	    }
 	    /* Look for suffix alias */
 	    if ((suf = strrchr(*argv, '.')) && suf[1] &&
 		suf > *argv && suf[-1] != Meta &&
 		(hn = sufaliastab->getnode(sufaliastab, suf+1))) {
 		sufaliastab->printnode(hn, printflags);
+		informed = 1;
 		if (!all)
 		    continue;
-		informed = 1;
 	    }
 	    /* Look for reserved word */
 	    if ((hn = reswdtab->getnode(reswdtab, *argv))) {
 		reswdtab->printnode(hn, printflags);
+		informed = 1;
 		if (!all)
 		    continue;
-		informed = 1;
 	    }
 	    /* Look for shell function */
 	    if ((hn = shfunctab->getnode(shfunctab, *argv))) {
 		shfunctab->printnode(hn, printflags);
+		informed = 1;
 		if (!all)
 		    continue;
-		informed = 1;
 	    }
 	    /* Look for builtin command */
 	    if ((hn = builtintab->getnode(builtintab, *argv))) {
 		builtintab->printnode(hn, printflags);
+		informed = 1;
 		if (!all)
 		    continue;
-		informed = 1;
 	    }
 	    /* Look for commands that have been added to the *
 	     * cmdnamtab with the builtin `hash foo=bar'.    */
 	    if ((hn = cmdnamtab->getnode(cmdnamtab, *argv)) && (hn->flags & HASHED)) {
 		cmdnamtab->printnode(hn, printflags);
+		informed = 1;
 		if (!all)
 		    continue;
-		informed = 1;
 	    }
 	}
 
@@ -3356,6 +3357,7 @@ bin_whence(char *nam, char **argv, Options ops, int func)
 		    print_if_link(cnam, OPT_ISSET(ops,'S'));
 		fputc('\n', stdout);
 	    }
+	    informed = 1;
 	} else {
 	    /* Not found at all. */
 	    if (v || csh || wd)
@@ -3367,7 +3369,7 @@ bin_whence(char *nam, char **argv, Options ops, int func)
 	freearray(allmatched);
 
     unqueue_signals();
-    return returnval;
+    return returnval || !informed;
 }
 
 /**** command & named directory hash table builtins ****/


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

end of thread, other threads:[~2015-01-05  2:05 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <549E3A7B.9010209@eastlink.ca>
     [not found] ` <20150102170307.7d2e644a@ntlworld.com>
     [not found]   ` <54A6E6B1.6070201@eastlink.ca>
     [not found]     ` <20150102212422.3a761af5@ntlworld.com>
     [not found]       ` <54A7136C.1060102@eastlink.ca>
     [not found]         ` <20150102222140.1303a633@ntlworld.com>
     [not found]           ` <54A72CEF.9090102@eastlink.ca>
     [not found]             ` <54A740F3.4040902@eastlink.ca>
     [not found]               ` <150102210337.ZM22099@torch.brasslantern.com>
     [not found]                 ` <54A783C3.3000006@eastlink.ca>
     [not found]                   ` <150102231734.ZM22168@torch.brasslantern.com>
     [not found]                     ` <54A82374.1030208@eastlink.ca>
     [not found]                       ` <150103120252.ZM23074@torch.brasslantern.com>
     [not found]                         ` <54A85B6C.4020103@eastlink.ca>
     [not found]                           ` <150103164002.ZM23676@torch.brasslantern.com>
     [not found]                             ` <54A8B4EE.30908@eastlink.ca>
     [not found]                               ` <150104003130.ZM24261@torch.brasslantern.com>
2015-01-04 18:04                                 ` symlink chain Vin Shelton
2015-01-04 18:51                                   ` Peter Stephenson
2015-01-04 19:39                                   ` Peter Stephenson
     [not found]                                 ` <54A9A76A.7020303@eastlink.ca>
     [not found]                                   ` <150104173448.ZM19453@torch.brasslantern.com>
2015-01-05  2:05                                     ` [PATCH] Exit status of "whence" (Re: symlink chain.) Bart Schaefer

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