main
pattern.c
1#include "in_all.h"
2#include "pattern.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
16 if (!*s) {
17 return (char *)0;
18 }
19 if (pattern_valid) {
20 regfree(&pattern);
21 pattern_valid = 0;
22 }
23 if (regcomp(&pattern, s, 0) == 0) {
24 pattern_valid = 1;
25 return (char *)0;
26 }
27 return "Error in pattern";
28}
29
30int
31re_exec(char *s)
32{
33 return pattern_valid && regexec(&pattern, s, 0, (regmatch_t *)0, 0) == 0;
34}