Update.
2000-01-25 Ulrich Drepper <drepper@cygnus.com> * posix/fnmatch_loop.c: Fix problem with FNM_LEADING_DIR. * posix/testfnm.c: Add a few more tests. Rearrange test output.
This commit is contained in:
parent
1827fc4c98
commit
479248949b
|
@ -1,3 +1,8 @@
|
||||||
|
2000-01-25 Ulrich Drepper <drepper@cygnus.com>
|
||||||
|
|
||||||
|
* posix/fnmatch_loop.c: Fix problem with FNM_LEADING_DIR.
|
||||||
|
* posix/testfnm.c: Add a few more tests. Rearrange test output.
|
||||||
|
|
||||||
2000-01-25 Andreas Schwab <schwab@suse.de>
|
2000-01-25 Andreas Schwab <schwab@suse.de>
|
||||||
|
|
||||||
* posix/testfnm.c: Add new test case. Use FNM_PATHNAME instead of
|
* posix/testfnm.c: Add new test case. Use FNM_PATHNAME instead of
|
||||||
|
|
|
@ -90,9 +90,31 @@ FCT (pattern, string, no_leading_period, flags)
|
||||||
if (c == L('\0'))
|
if (c == L('\0'))
|
||||||
/* The wildcard(s) is/are the last element of the pattern.
|
/* The wildcard(s) is/are the last element of the pattern.
|
||||||
If the name is a file name and contains another slash
|
If the name is a file name and contains another slash
|
||||||
this does mean it cannot match. */
|
this does mean it cannot match. If the FNM_LEADING_DIR
|
||||||
return ((flags & FNM_FILE_NAME) && STRCHR (n, L('/')) != NULL
|
flag is set and exactly one slash is following, we have
|
||||||
? FNM_NOMATCH : 0);
|
a match. */
|
||||||
|
{
|
||||||
|
int result = (flags & FNM_FILE_NAME) == 0 ? 0 : FNM_NOMATCH;
|
||||||
|
|
||||||
|
if (flags & FNM_FILE_NAME)
|
||||||
|
{
|
||||||
|
const CHAR *slashp = STRCHR (n, L('/'));
|
||||||
|
|
||||||
|
if (flags & FNM_LEADING_DIR)
|
||||||
|
{
|
||||||
|
if (slashp != NULL
|
||||||
|
&& STRCHR (slashp + 1, L('/')) == NULL)
|
||||||
|
result = 0;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (slashp == NULL)
|
||||||
|
result = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
const CHAR *endp;
|
const CHAR *endp;
|
||||||
|
|
|
@ -13,9 +13,9 @@ struct {
|
||||||
{ "a/b", "a[/]b", 0, 0 },
|
{ "a/b", "a[/]b", 0, 0 },
|
||||||
{ "a/b", "a[/]b", FNM_PATHNAME, FNM_NOMATCH },
|
{ "a/b", "a[/]b", FNM_PATHNAME, FNM_NOMATCH },
|
||||||
{ "a/b", "[a-z]/[a-z]", 0, 0 },
|
{ "a/b", "[a-z]/[a-z]", 0, 0 },
|
||||||
{ "a/b", "*", FNM_FILE_NAME, FNM_NOMATCH },
|
{ "a/b", "*", FNM_PATHNAME, FNM_NOMATCH },
|
||||||
{ "a/b", "*[/]b", FNM_FILE_NAME, FNM_NOMATCH },
|
{ "a/b", "*[/]b", FNM_PATHNAME, FNM_NOMATCH },
|
||||||
{ "a/b", "*[b]", FNM_FILE_NAME, FNM_NOMATCH },
|
{ "a/b", "*[b]", FNM_PATHNAME, FNM_NOMATCH },
|
||||||
{ "a/b", "[*]/b", 0, FNM_NOMATCH },
|
{ "a/b", "[*]/b", 0, FNM_NOMATCH },
|
||||||
{ "*/b", "[*]/b", 0, 0 },
|
{ "*/b", "[*]/b", 0, 0 },
|
||||||
{ "a/b", "[?]/b", 0, FNM_NOMATCH },
|
{ "a/b", "[?]/b", 0, FNM_NOMATCH },
|
||||||
|
@ -51,6 +51,9 @@ struct {
|
||||||
{ "a.b", "a?b", FNM_PATHNAME|FNM_PERIOD, 0 },
|
{ "a.b", "a?b", FNM_PATHNAME|FNM_PERIOD, 0 },
|
||||||
{ "a.b", "a*b", FNM_PATHNAME|FNM_PERIOD, 0 },
|
{ "a.b", "a*b", FNM_PATHNAME|FNM_PERIOD, 0 },
|
||||||
{ "a.b", "a[.]b", FNM_PATHNAME|FNM_PERIOD, 0 },
|
{ "a.b", "a[.]b", FNM_PATHNAME|FNM_PERIOD, 0 },
|
||||||
|
{ "a/b", "*a*", FNM_PATHNAME|FNM_LEADING_DIR, 0 },
|
||||||
|
{ "ab/c", "*a?", FNM_PATHNAME|FNM_LEADING_DIR, 0 },
|
||||||
|
{ "ab/c", "a?", FNM_PATHNAME|FNM_LEADING_DIR, 0 },
|
||||||
};
|
};
|
||||||
|
|
||||||
int
|
int
|
||||||
|
@ -64,13 +67,14 @@ main (void)
|
||||||
int match;
|
int match;
|
||||||
|
|
||||||
match = fnmatch (tests[i].pattern, tests[i].name, tests[i].flags);
|
match = fnmatch (tests[i].pattern, tests[i].name, tests[i].flags);
|
||||||
|
|
||||||
|
printf ("[%2zd] %s %s %s -> %s\n", i, tests[i].pattern,
|
||||||
|
match == 0 ? "matches" : "does not match",
|
||||||
|
tests[i].name,
|
||||||
|
match != tests[i].expected ? "FAIL" : "OK");
|
||||||
|
|
||||||
if (match != tests[i].expected)
|
if (match != tests[i].expected)
|
||||||
{
|
++errors ;
|
||||||
printf ("%s %s %s\n", tests[i].pattern,
|
|
||||||
match == 0 ? "matches" : "does not match",
|
|
||||||
tests[i].name);
|
|
||||||
errors++;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
exit (errors != 0);
|
exit (errors != 0);
|
||||||
|
|
Loading…
Reference in New Issue