summaryrefslogtreecommitdiff
path: root/lib/glob/sm_loop.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/glob/sm_loop.c')
-rw-r--r--lib/glob/sm_loop.c24
1 files changed, 18 insertions, 6 deletions
diff --git a/lib/glob/sm_loop.c b/lib/glob/sm_loop.c
index 9e16412c..c3a2aa37 100644
--- a/lib/glob/sm_loop.c
+++ b/lib/glob/sm_loop.c
@@ -119,9 +119,6 @@ fprintf(stderr, "gmatch: pattern = %s; pe = %s\n", pattern, pe);
break;
case '*': /* Match zero or more characters */
- if (p == pe)
- return 0;
-
if ((flags & FNM_PERIOD) && sc == L('.') &&
(n == string || ((flags & FNM_PATHNAME) && n[-1] == L('/'))))
/* `*' cannot match a `.' if it is the first character of the
@@ -129,6 +126,9 @@ fprintf(stderr, "gmatch: pattern = %s; pe = %s\n", pattern, pe);
we are matching a pathname. */
return FNM_NOMATCH;
+ if (p == pe)
+ return 0;
+
/* Collapse multiple consecutive `*' and `?', but make sure that
one character of the string is consumed for each `?'. */
for (c = *p++; (c == L('?') || c == L('*')); c = *p++)
@@ -140,14 +140,26 @@ fprintf(stderr, "gmatch: pattern = %s; pe = %s\n", pattern, pe);
else if ((flags & FNM_EXTMATCH) && c == L('?') && *p == L('(')) /* ) */
{
CHAR *newn;
+
+#if 0
for (newn = n; newn < se; ++newn)
{
if (EXTMATCH (c, newn, se, p, pe, flags) == 0)
return (0);
}
- /* We didn't match. If we have a `?(...)', we can match 0
- or 1 times. */
- return 0;
+#else
+ /* We can match 0 or 1 times. If we match, return success */
+ if (EXTMATCH (c, n, se, p, pe, flags) == 0)
+ return (0);
+#endif
+
+ /* We didn't match the extended glob pattern, but
+ that's OK, since we can match 0 or 1 occurrences.
+ We need to skip the glob pattern and see if we
+ match the rest of the string. */
+ newn = PATSCAN (p + 1, pe, 0);
+ /* If NEWN is 0, we have an ill-formed pattern. */
+ p = newn ? newn : pe;
}
#endif
else if (c == L('?'))