index : pacman | |
Archlinux32 fork of pacman | gitolite user |
summaryrefslogtreecommitdiff |
author | Patrick Steinhardt <steinhardt.ptk@gmail.com> | 2013-06-18 17:44:15 +0200 |
---|---|---|
committer | Allan McRae <allan@archlinux.org> | 2013-06-26 15:32:16 +1000 |
commit | dfcea1456da5df042f2ba2ba23efeb245436718f (patch) | |
tree | 63dcff337bd1306335a8fd98312399dc3da8464e /lib/libalpm/util.c | |
parent | ec831e05f58e3db1c06aadb23a87b5b82ab3ebf3 (diff) |
-rw-r--r-- | lib/libalpm/util.c | 31 |
diff --git a/lib/libalpm/util.c b/lib/libalpm/util.c index f84fb666..15c1a67c 100644 --- a/lib/libalpm/util.c +++ b/lib/libalpm/util.c @@ -1249,6 +1249,37 @@ int _alpm_access(alpm_handle_t *handle, const char *dir, const char *file, int a return ret; } +/** Checks whether a string matches at least one shell wildcard pattern. + * Checks for matches with fnmatch. Matches are inverted by prepending + * patterns with an exclamation mark. Preceding exclamation marks may be + * escaped. Subsequent matches override previous ones. + * @param patterns patterns to match against + * @param string string to check against pattern + * @return 0 if string matches pattern, negative if they don't match and + * positive if the last match was inverted + */ +int _alpm_fnmatch_patterns(alpm_list_t *patterns, const char *string) +{ + alpm_list_t *i; + char *pattern; + short inverted; + + for(i = alpm_list_last(patterns); i; i = alpm_list_previous(i)) { + pattern = i->data; + + inverted = pattern[0] == '!'; + if(inverted || pattern[0] == '\\') { + pattern++; + } + + if(_alpm_fnmatch(pattern, string) == 0) { + return inverted; + } + } + + return -1; +} + /** Checks whether a string matches a shell wildcard pattern. * Wrapper around fnmatch. * @param pattern pattern to match against |