-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpat.c
52 lines (40 loc) · 740 Bytes
/
pat.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#include <errno.h>
#include <stddef.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <vec.h>
#include <pat.h>
#include <pat.ih>
int
pat_compile(struct pattern *dst, char const *src)
{
struct token *tok = 0;
int err = 0;
if (!dst) return EFAULT;
if (!src) return EFAULT;
err = pat_parse(&tok, src);
if (err) goto finally;
err = pat_marshal(dst, tok);
if (err) goto finally;
finally:
tok_free(tok);
return err;
}
void
pat_free(struct pattern *pat)
{
free(pat->prog);
}
int
pat_execute(struct pattern *pat, char const *str)
{
if (!str) return EFAULT;
if (!pat) return EFAULT;
struct context ctx[1] = {{
.str = str,
.len = strlen(str),
}};
return pat_match(pat, ctx);
}