-
Notifications
You must be signed in to change notification settings - Fork 1
/
requiredtag.c
85 lines (70 loc) · 1.61 KB
/
requiredtag.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#include <assert.h>
#include "project.h"
#include "requiredtag.h"
#include "errlog.h"
#include "miscutil.h"
jb_err init_req_tag_list(struct req_tag_list *tags, const char* pattern)
{
int errcode;
char ebuf[BUFFER_SIZE];
tags->next = NULL;
tags->tag_regex = zalloc(sizeof(*tags->tag_regex));
if (NULL == tags->tag_regex)
{
return JB_ERR_MEMORY;
}
errcode = regcomp(tags->tag_regex, pattern, (REG_EXTENDED|REG_NOSUB|REG_ICASE));
if (errcode)
{
size_t errlen = regerror(errcode, tags->tag_regex, ebuf, sizeof(ebuf));
if (errlen > (sizeof(ebuf) - (size_t)1))
{
errlen = sizeof(ebuf) - (size_t)1;
}
log_error(LOG_LEVEL_ERROR, "error compiling %s : %s",
pattern, ebuf);
return JB_ERR_PARSE;
}
return JB_ERR_OK;
}
void free_req_tag_list(struct req_tag_list *tags)
{
struct req_tag_list *temp;
if (tags == NULL) return;
while(tags)
{
if (tags->tag_regex)
{
regfree(tags->tag_regex);
freez(tags->tag_regex);
}
temp = tags;
tags = tags->next;
freez(temp);
}
}
static int match_req_tag(struct req_tag_list *rtags, struct list *tags)
{
struct list_entry *tag;
for (tag = tags->first; tag != NULL; tag = tag->next)
{
if (0 == regexec(rtags->tag_regex, tag->str, 0, NULL, 0))
{
return 1;
}
}
return 0;
}
int match_req_tag_list(struct req_tag_list *rtags, struct list *tags)
{
assert(rtags);
while(rtags)
{
if (0 == match_req_tag(rtags, tags))
{
return 0;
}
rtags = rtags->next;
}
return 1;
}