diff options
Diffstat (limited to 'src/pacman/util.c')
-rw-r--r-- | src/pacman/util.c | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/src/pacman/util.c b/src/pacman/util.c index 1d3844a3..5a60070b 100644 --- a/src/pacman/util.c +++ b/src/pacman/util.c @@ -29,6 +29,7 @@ #include <ctype.h> #include <dirent.h> #include <unistd.h> +#include <regex.h> #ifdef CYGWIN #include <limits.h> /* PATH_MAX */ #endif @@ -224,4 +225,19 @@ int yesno(char *fmt, ...) return(0); } +/* match a string against a regular expression */ +int reg_match(char *string, char *pattern) +{ + int result; + regex_t reg; + + if(regcomp(®, pattern, REG_EXTENDED | REG_NOSUB | REG_ICASE) != 0) { + fprintf(stderr, "error: %s is not a valid regular expression.\n", pattern); + return(-1); + } + result = regexec(®, string, 0, 0, 0); + regfree(®); + return(!(result)); +} + /* vim: set ts=2 sw=2 noet: */ |