diff options
author | Andreas Schneider <mail@cynapses.org> | 2009-05-05 07:14:09 +0000 |
---|---|---|
committer | Andreas Schneider <mail@cynapses.org> | 2009-05-05 07:14:09 +0000 |
commit | 5c934d09700a9b440e95333d7bb5eb1a3a8847f4 (patch) | |
tree | 8c84823eb6bf040715120b564ad82fc3f72736be /libssh/match.c | |
parent | 1a280d859d26690e06030b520973639eab04ead7 (diff) | |
download | libssh-5c934d09700a9b440e95333d7bb5eb1a3a8847f4.tar.gz libssh-5c934d09700a9b440e95333d7bb5eb1a3a8847f4.tar.xz libssh-5c934d09700a9b440e95333d7bb5eb1a3a8847f4.zip |
Reformat match_pattern_list().
git-svn-id: svn+ssh://svn.berlios.de/svnroot/repos/libssh/trunk@715 7dcaeef0-15fb-0310-b436-a5af3365683c
Diffstat (limited to 'libssh/match.c')
-rw-r--r-- | libssh/match.c | 111 |
1 files changed, 58 insertions, 53 deletions
diff --git a/libssh/match.c b/libssh/match.c index 33771f9..e48a5c8 100644 --- a/libssh/match.c +++ b/libssh/match.c @@ -112,62 +112,67 @@ static int match_pattern(const char *s, const char *pattern) { } /* - * Tries to match the string against the - * comma-separated sequence of subpatterns (each possibly preceded by ! to - * indicate negation). Returns -1 if negation matches, 1 if there is - * a positive match, 0 if there is no match at all. + * Tries to match the string against the comma-separated sequence of subpatterns + * (each possibly preceded by ! to indicate negation). + * Returns -1 if negation matches, 1 if there is a positive match, 0 if there is + * no match at all. */ - static int match_pattern_list(const char *string, const char *pattern, unsigned int len, int dolower) { - char sub[1024]; - int negated; - int got_positive; - unsigned int i, subi; - - got_positive = 0; - for (i = 0; i < len;) { - /* Check if the subpattern is negated. */ - if (pattern[i] == '!') { - negated = 1; - i++; - } else - negated = 0; - - /* - * Extract the subpattern up to a comma or end. Convert the - * subpattern to lowercase. - */ - for (subi = 0; - i < len && subi < sizeof(sub) - 1 && pattern[i] != ','; - subi++, i++) - sub[subi] = dolower && isupper(pattern[i]) ? - (char)tolower(pattern[i]) : pattern[i]; - /* If subpattern too long, return failure (no match). */ - if (subi >= sizeof(sub) - 1) - return 0; - - /* If the subpattern was terminated by a comma, skip the comma. */ - if (i < len && pattern[i] == ',') - i++; - - /* Null-terminate the subpattern. */ - sub[subi] = '\0'; - - /* Try to match the subpattern against the string. */ - if (match_pattern(string, sub)) { - if (negated) - return -1; /* Negative */ - else - got_positive = 1; /* Positive */ - } - } - - /* - * Return success if got a positive match. If there was a negative - * match, we have already returned -1 and never get here. - */ - return got_positive; + char sub[1024]; + int negated; + int got_positive; + unsigned int i, subi; + + got_positive = 0; + for (i = 0; i < len;) { + /* Check if the subpattern is negated. */ + if (pattern[i] == '!') { + negated = 1; + i++; + } else { + negated = 0; + } + + /* + * Extract the subpattern up to a comma or end. Convert the + * subpattern to lowercase. + */ + for (subi = 0; + i < len && subi < sizeof(sub) - 1 && pattern[i] != ','; + subi++, i++) { + sub[subi] = dolower && isupper(pattern[i]) ? + (char)tolower(pattern[i]) : pattern[i]; + } + + /* If subpattern too long, return failure (no match). */ + if (subi >= sizeof(sub) - 1) { + return 0; + } + + /* If the subpattern was terminated by a comma, skip the comma. */ + if (i < len && pattern[i] == ',') { + i++; + } + + /* Null-terminate the subpattern. */ + sub[subi] = '\0'; + + /* Try to match the subpattern against the string. */ + if (match_pattern(string, sub)) { + if (negated) { + return -1; /* Negative */ + } else { + got_positive = 1; /* Positive */ + } + } + } + + /* + * Return success if got a positive match. If there was a negative + * match, we have already returned -1 and never get here. + */ + return got_positive; } /* |