master xplshn/aruu / cmd / extra / yap / pattern.c
 1#include "pattern.h"
 2#include "in_all.h"
 3#include <regex.h>
 4
 5/*
 6 * Interface to POSIX regular expression routines.
 7 */
 8
 9static regex_t pattern;
10static int     pattern_valid;
11
12char *
13re_comp(char *s)
14{
15  if (!*s) {
16    return (char *)0;
17  }
18  if (pattern_valid) {
19    regfree(&pattern);
20    pattern_valid = 0;
21  }
22  if (regcomp(&pattern, s, 0) == 0) {
23    pattern_valid = 1;
24    return (char *)0;
25  }
26  return "Error in pattern";
27}
28
29int
30re_exec(char *s)
31{
32  return pattern_valid && regexec(&pattern, s, 0, (regmatch_t *)0, 0) == 0;
33}