mirror of
git://git.code.sf.net/p/zsh/code
synced 2025-10-27 04:40:59 +01:00
users/18870: fix glob scanner insert counting check.
Was causing problems with globs in paths with (Y) glob qualifier
This commit is contained in:
parent
f5ad1ccbd6
commit
06a4913245
3 changed files with 22 additions and 10 deletions
|
|
@ -1,3 +1,9 @@
|
|||
2014-06-02 Peter Stephenson <p.stephenson@samsung.com>
|
||||
|
||||
* Daniel Sharaf: users/18870: Src/glob.c, Test/D02glob.ztst:
|
||||
glob scanner needed some coaxing with counting matches with (Y)
|
||||
glob qualifier.
|
||||
|
||||
2014-06-01 Barton E. Schaefer <schaefer@zsh.org>
|
||||
|
||||
* 32653: Completion/Unix/Command/_php: complete files with the
|
||||
|
|
|
|||
21
Src/glob.c
21
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;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue