1
0
mirror of https://github.com/samba-team/samba.git synced 2025-01-13 13:18:06 +03:00

better handling of '.'

better verbose print
This commit is contained in:
Andrew Tridgell -
parent 2c509c9860
commit 1f8b8a7189

View File

@ -40,12 +40,19 @@ int ms_fnmatch_lanman_core(char *pattern, char *string)
char *p = pattern, *n = string; char *p = pattern, *n = string;
char c; char c;
if (strcmp(p,"?")==0 && strcmp(n,".")==0) return 0; if (strcmp(p,"?")==0 && strcmp(n,".")==0) goto match;
while ((c = *p++)) { while ((c = *p++)) {
switch (c) { switch (c) {
case '.':
if (!strchr(p,'.') && !*n && ms_fnmatch_lanman_core(p, n)==0)
goto match;
if (*n != '.') goto nomatch;
n++;
break;
case '?': case '?':
if (*n == '.' || ! *n) return ms_fnmatch_lanman_core(p, n); if ((*n == '.' && n[1] != '.') || ! *n) goto next;
n++; n++;
break; break;
@ -55,7 +62,7 @@ int ms_fnmatch_lanman_core(char *pattern, char *string)
if (ms_fnmatch_lanman_core(p, n) == 0) goto match; if (ms_fnmatch_lanman_core(p, n) == 0) goto match;
goto nomatch; goto nomatch;
} }
if (! *n) return ms_fnmatch_lanman_core(p, n); if (! *n) goto next;
n++; n++;
break; break;
@ -90,11 +97,14 @@ int ms_fnmatch_lanman_core(char *pattern, char *string)
if (! *n) goto match; if (! *n) goto match;
nomatch: nomatch:
if (verbose) printf("NOMATCH pattern=[%s] string=[%s]\n", pattern, string); if (verbose) printf("NOMATCH pattern=[%s] string=[%s]\n", pattern, string);
return -1; return -1;
next:
if (ms_fnmatch_lanman_core(p, n) == 0) goto match;
goto nomatch;
match: match:
if (verbose) printf("MATCH pattern=[%s] string=[%s]\n", pattern, string); if (verbose) printf("MATCH pattern=[%s] string=[%s]\n", pattern, string);
return 0; return 0;
@ -102,19 +112,11 @@ int ms_fnmatch_lanman_core(char *pattern, char *string)
int ms_fnmatch_lanman(char *pattern, char *string) int ms_fnmatch_lanman(char *pattern, char *string)
{ {
int ret; if (!strpbrk(pattern, "?*<>\"")) {
pattern = strdup(pattern); return strcmp(pattern, string);
/* it appears that '.' at the end of a pattern is stripped if the
pattern contains any wildcard characters. Bizarre */
if (strpbrk(pattern, "?*<>\"")) {
int len = strlen(pattern);
if (len > 0 && pattern[len-1] == '.') pattern[len-1] = 0;
} }
ret = ms_fnmatch_lanman_core(pattern, string); return ms_fnmatch_lanman_core(pattern, string);
free(pattern);
return ret;
} }
static BOOL reg_match_one(char *pattern, char *file) static BOOL reg_match_one(char *pattern, char *file)