Reformat match_pattern_list().

git-svn-id: svn+ssh://svn.berlios.de/svnroot/repos/libssh/trunk@715 7dcaeef0-15fb-0310-b436-a5af3365683c
This commit is contained in:
Andreas Schneider
2009-05-05 07:14:09 +00:00
parent 1a280d859d
commit 5c934d0970

View File

@@ -112,12 +112,11 @@ static int match_pattern(const char *s, const char *pattern) {
} }
/* /*
* Tries to match the string against the * Tries to match the string against the comma-separated sequence of subpatterns
* comma-separated sequence of subpatterns (each possibly preceded by ! to * (each possibly preceded by ! to indicate negation).
* indicate negation). Returns -1 if negation matches, 1 if there is * Returns -1 if negation matches, 1 if there is a positive match, 0 if there is
* a positive match, 0 if there is no match at all. * no match at all.
*/ */
static int match_pattern_list(const char *string, const char *pattern, static int match_pattern_list(const char *string, const char *pattern,
unsigned int len, int dolower) { unsigned int len, int dolower) {
char sub[1024]; char sub[1024];
@@ -131,8 +130,9 @@ static int match_pattern_list(const char *string, const char *pattern,
if (pattern[i] == '!') { if (pattern[i] == '!') {
negated = 1; negated = 1;
i++; i++;
} else } else {
negated = 0; negated = 0;
}
/* /*
* Extract the subpattern up to a comma or end. Convert the * Extract the subpattern up to a comma or end. Convert the
@@ -140,28 +140,33 @@ static int match_pattern_list(const char *string, const char *pattern,
*/ */
for (subi = 0; for (subi = 0;
i < len && subi < sizeof(sub) - 1 && pattern[i] != ','; i < len && subi < sizeof(sub) - 1 && pattern[i] != ',';
subi++, i++) subi++, i++) {
sub[subi] = dolower && isupper(pattern[i]) ? sub[subi] = dolower && isupper(pattern[i]) ?
(char)tolower(pattern[i]) : pattern[i]; (char)tolower(pattern[i]) : pattern[i];
}
/* If subpattern too long, return failure (no match). */ /* If subpattern too long, return failure (no match). */
if (subi >= sizeof(sub) - 1) if (subi >= sizeof(sub) - 1) {
return 0; return 0;
}
/* If the subpattern was terminated by a comma, skip the comma. */ /* If the subpattern was terminated by a comma, skip the comma. */
if (i < len && pattern[i] == ',') if (i < len && pattern[i] == ',') {
i++; i++;
}
/* Null-terminate the subpattern. */ /* Null-terminate the subpattern. */
sub[subi] = '\0'; sub[subi] = '\0';
/* Try to match the subpattern against the string. */ /* Try to match the subpattern against the string. */
if (match_pattern(string, sub)) { if (match_pattern(string, sub)) {
if (negated) if (negated) {
return -1; /* Negative */ return -1; /* Negative */
else } else {
got_positive = 1; /* Positive */ got_positive = 1; /* Positive */
} }
} }
}
/* /*
* Return success if got a positive match. If there was a negative * Return success if got a positive match. If there was a negative