mirror of
https://github.com/moparisthebest/imapfilter
synced 2024-11-14 13:25:25 -05:00
4fe1a3d649
Move the source code to the src dir, the man pages to the doc dir, and the example configuration files to the samples dir, and update all relevant files to reflect the changes.
43 lines
793 B
C
43 lines
793 B
C
#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);
|
|
}
|
|
}
|