2 * This file is part of DisOrder
3 * Copyright (C) 2017 Mark Wooding
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 /** @file lib/regexp.c
19 * @brief Regular expressions
26 void regexp_setup(void)
28 pcre_malloc = xmalloc;
32 regexp *regexp_compile(const char *pat, unsigned f,
33 char *errbuf, size_t errlen, size_t *erroff_out)
41 re = pcre_compile(pat, f, &e, &erroff, 0);
44 for(p = errbuf, i = errlen - 1; i && *e; i--) *p++ = *e++;
50 int regexp_match(const regexp *re, const char *s, size_t n, unsigned f,
51 size_t *ov, size_t on)
57 myov = xmalloc(on*sizeof(*myov));
58 rc = pcre_exec(re, 0, s, n, 0, f, myov, on);
59 for(i = 0; i < on; i++) ov[i] = myov[i];
64 void regexp_free(regexp *re)