File: regexp.c

package info (click to toggle)
imapfilter 1%3A1.2.2-1
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 300 kB
  • ctags: 315
  • sloc: ansic: 3,392; sh: 182; makefile: 103
file content (42 lines) | stat: -rw-r--r-- 793 bytes parent folder | download | duplicates (10)
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
#include <stdio.h>
#include <sys/types.h>
#include <regex.h>

#include "imapfilter.h"
#include "regexp.h"


/*
 * Compile all the patterns and allocate the necessary space for the substring
 * matching.
 */
void
regexp_compile(regexp *reg)
{
	regexp *re;

	for (re = reg; re->pattern != NULL; re++) {
		re->preg = (regex_t *)xmalloc(sizeof(regex_t));
		regcomp(re->preg, re->pattern, REG_EXTENDED | REG_ICASE);
		re->nmatch = re->preg->re_nsub + 1;
		re->pmatch = (regmatch_t *)xmalloc(sizeof(regmatch_t) *
		    re->nmatch);
	}
}


/*
 * Free the compiled regular expressions and the space allocated for the
 * substring matching.
 */
void
regexp_free(regexp *reg)
{
	regexp *re;

	for (re = reg; re->pattern != NULL; re++) {
		regfree(re->preg);
		xfree(re->preg);
		xfree(re->pmatch);
	}
}