X-Git-Url: https://git.notmuchmail.org/git?p=notmuch;a=blobdiff_plain;f=xutil.c;fp=xutil.c;h=eadd3783f9477735d43cabd84f96c9a53e900184;hp=7ee7a698f3c7142e1cab717eeaa930ced6fd18ad;hb=d008389a4ae306e510b11cc18947d305704f9236;hpb=22b2265cacb2930c11b75282046707355446788e diff --git a/xutil.c b/xutil.c index 7ee7a698..eadd3783 100644 --- a/xutil.c +++ b/xutil.c @@ -92,3 +92,42 @@ xstrndup (const char *s, size_t n) return ret; } + +void +xregcomp (regex_t *preg, const char *regex, int cflags) +{ + int rerr; + + rerr = regcomp (preg, regex, cflags); + if (rerr) { + size_t error_size = regerror (rerr, preg, NULL, 0); + char *error = xmalloc (error_size); + + regerror (rerr, preg, error, error_size); + fprintf (stderr, "Internal error compiling regex %s: %s\n", + regex, error); + free (error); + exit (1); + } +} + +int +xregexec (const regex_t *preg, const char *string, + size_t nmatch, regmatch_t pmatch[], int eflags) +{ + int i, rerr; + + rerr = regexec (preg, string, nmatch, pmatch, eflags); + if (rerr) + return rerr; + + for (i = 0; i < nmatch; i++) { + if (pmatch[i].rm_so == -1) { + fprintf (stderr, "Internal error matching regex against %s: Sub-match %d not found\n", + string, i); + exit (1); + } + } + + return 0; +}