From: Daniel Shahaf <d.s@daniel.shahaf.name>
To: Peter Stephenson <p.stephenson@samsung.com>
Cc: zsh-users@zsh.org
Subject: Re: globbing in conditional expressions
Date: Mon, 2 Jun 2014 12:57:23 +0000 [thread overview]
Message-ID: <20140602125723.GC1871@tarsus.local2> (raw)
In-Reply-To: <20140602104050.3ca249b8@pwslap01u.europe.root.pri>
[-- Attachment #1: Type: text/plain, Size: 245 bytes --]
Peter Stephenson wrote on Mon, Jun 02, 2014 at 10:40:50 +0100:
> % print Completio?/*(NY/)
>
> % print Completion/*(NY/)
> Completion/Darwin
scanner() wrongly assumed that any call to insert() increases matchct.
Test and fix attached.
Daniel
[-- Attachment #2: 0001-After-10ae77c-Fix-users-18869.patch --]
[-- Type: text/x-patch, Size: 3326 bytes --]
>From 72770405cdd21bc75fc8266cd0fa39fb179b7118 Mon Sep 17 00:00:00 2001
From: Daniel Shahaf <d.s@daniel.shahaf.name>
Date: Mon, 2 Jun 2014 11:55:18 +0000
Subject: [PATCH] After 10ae77c: Fix users/18869
---
Src/glob.c | 21 +++++++++++----------
Test/D02glob.ztst | 5 +++++
2 files changed, 16 insertions(+), 10 deletions(-)
diff --git a/Src/glob.c b/Src/glob.c
index 1420ac7..0ca63fc 100644
--- a/Src/glob.c
+++ b/Src/glob.c
@@ -297,15 +297,16 @@ statfullpath(const char *s, struct stat *st, int l)
char **inserts;
-/* add a match to the list */
+/* add a match to the list. Return 1 if it was inserted, 0 otherwise. */
/**/
-static void
+static int
insert(char *s, int checked)
{
struct stat buf, buf2, *bp;
char *news = s;
int statted = 0;
+ int inserted = 0;
queue_signals();
inserts = NULL;
@@ -316,7 +317,7 @@ insert(char *s, int checked)
checked = statted = 1;
if (statfullpath(s, &buf, 1)) {
unqueue_signals();
- return;
+ return inserted;
}
mode = buf.st_mode;
if (gf_follow) {
@@ -340,7 +341,7 @@ insert(char *s, int checked)
if (!statted && statfullpath(s, &buf, 1)) {
unqueue_signals();
- return;
+ return inserted;
}
news = dyncat(pathbuf, news);
@@ -365,7 +366,7 @@ insert(char *s, int checked)
/* Try next alternative, or return if there are no more */
if (!(qo = qo->or)) {
unqueue_signals();
- return;
+ return inserted;
}
qn = qo;
continue;
@@ -375,7 +376,7 @@ insert(char *s, int checked)
} else if (!checked) {
if (statfullpath(s, NULL, 1)) {
unqueue_signals();
- return;
+ return inserted;
}
statted = 1;
news = dyncat(pathbuf, news);
@@ -435,6 +436,7 @@ insert(char *s, int checked)
}
matchptr++;
+ inserted = 1;
if (++matchct == matchsz) {
matchbuf = (Gmatch )realloc((char *)matchbuf,
sizeof(struct gmatch) * (matchsz *= 2));
@@ -445,6 +447,7 @@ insert(char *s, int checked)
break;
}
unqueue_signals();
+ return inserted;
}
/* Do the globbing: scanner is called recursively *
@@ -525,8 +528,7 @@ scanner(Complist q, int shortcircuit)
} else {
if (str[l])
str = dupstrpfx(str, l);
- insert(str, 0);
- if (shortcircuit)
+ if (insert(str, 0) == 1 && shortcircuit)
return 1;
}
} else {
@@ -617,8 +619,7 @@ scanner(Complist q, int shortcircuit)
subdirlen += sizeof(int);
} else
/* if the last filename component, just add it */
- insert(fn, 1);
- if (shortcircuit)
+ if (insert(fn, 1) == 1 && shortcircuit)
return 1;
}
}
diff --git a/Test/D02glob.ztst b/Test/D02glob.ztst
index d197098..9e29de2 100644
--- a/Test/D02glob.ztst
+++ b/Test/D02glob.ztst
@@ -546,9 +546,14 @@
(){ print $#@ } glob.tmp/dir*(Y)
(){ print $#@ } glob.tmp/file*(NY)
(){ [[ $1 = glob.tmp/dir? ]] && echo "(Y) returns a matching filename" } glob.tmp/dir*(Y)
+ # Can be negated
(){ print $@:t } glob.tmp/dir*(Y^Y)
+ (){ [[ $#@ -eq 1 ]] && print Globs before last path component } glob.tmp/dir?/subdir(NY)
+ (){ [[ $#@ -eq 0 ]] && print Respects qualifiers } glob.tmp/dir?/subdir(NY.)
0:short-circuit modifier
>1
>0
>(Y) returns a matching filename
>dir1 dir2 dir3 dir4
+>Globs before last path component
+>Respects qualifiers
--
1.7.10.4
next prev parent reply other threads:[~2014-06-02 12:57 UTC|newest]
Thread overview: 31+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-05-07 12:41 Roman Neuhauser
2014-05-07 14:44 ` Peter Stephenson
2014-05-08 10:55 ` Daniel Shahaf
2014-05-08 11:20 ` Peter Stephenson
2014-05-08 15:34 ` Bart Schaefer
2014-05-08 20:19 ` Roman Neuhauser
2014-05-13 15:41 ` Bart Schaefer
2014-05-14 4:19 ` Daniel Shahaf
2014-05-14 7:18 ` Bart Schaefer
2014-05-15 4:55 ` Bart Schaefer
2014-05-15 9:35 ` Daniel Shahaf
2014-05-15 14:33 ` Bart Schaefer
2014-05-15 9:29 ` Daniel Shahaf
2014-05-15 14:50 ` Bart Schaefer
2014-05-26 23:52 ` Daniel Shahaf
2014-05-30 3:59 ` Bart Schaefer
2014-05-30 8:47 ` Peter Stephenson
2014-05-30 15:55 ` Bart Schaefer
2014-05-31 4:43 ` Bart Schaefer
2014-05-31 17:34 ` Daniel Shahaf
2014-05-31 17:59 ` Bart Schaefer
2014-06-02 9:40 ` Peter Stephenson
2014-06-02 12:57 ` Daniel Shahaf [this message]
2014-06-02 14:15 ` Peter Stephenson
2014-05-30 14:45 ` Daniel Shahaf
2014-05-14 7:42 ` Christoph (Stucki) von Stuckrad
2014-05-14 21:09 ` Roman Neuhauser
2014-05-15 9:14 ` Daniel Shahaf
2014-05-15 10:05 ` Roman Neuhauser
2014-05-07 14:57 ` Mikael Magnusson
2014-05-07 15:03 ` Bart Schaefer
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=20140602125723.GC1871@tarsus.local2 \
--to=d.s@daniel.shahaf.name \
--cc=p.stephenson@samsung.com \
--cc=zsh-users@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).