X-Git-Url: http://mj.ucw.cz/gitweb/?a=blobdiff_plain;ds=sidebyside;f=lib%2Fregex.c;h=ce230848facdd0ba7b1709dc311daa23dd66312b;hb=b42162f5526360acc6930e3d2e296af1fef08e63;hp=888f36b918bb4a422f234647ae891596674f936a;hpb=ac9212c1d03bd23f6322bef39a4a0384b5afcc5d;p=libucw.git diff --git a/lib/regex.c b/lib/regex.c index 888f36b9..ce230848 100644 --- a/lib/regex.c +++ b/lib/regex.c @@ -1,17 +1,23 @@ /* * Sherlock Library -- Regular Expressions * - * (c) 1997 Martin Mares, + * (c) 1997 Martin Mares + * (c) 2001 Robert Spalek + * + * This software may be freely distributed and used according to the terms + * of the GNU Lesser General Public License. */ +#include "lib/lib.h" +#include "lib/chartype.h" + #include #include #include #include -#include "lib.h" - #define INITIAL_MEM 1024 /* Initial space allocated for each pattern */ +#define CHAR_SET_SIZE 256 /* How many characters in the character set. */ struct regex { struct re_pattern_buffer buf; @@ -20,14 +26,24 @@ struct regex { }; regex * -rx_compile(byte *p) +rx_compile(byte *p, int icase) { - regex *r = xmalloc(sizeof(regex)); + regex *r = xmalloc_zero(sizeof(regex)); const char *msg; - bzero(r, sizeof(struct regex)); r->buf.buffer = xmalloc(INITIAL_MEM); r->buf.allocated = INITIAL_MEM; + if (icase) + { + unsigned i; + r->buf.translate = xmalloc (CHAR_SET_SIZE); + /* Map uppercase characters to corresponding lowercase ones. */ + for (i = 0; i < CHAR_SET_SIZE; i++) + r->buf.translate[i] = Cupcase(i); + } + else + r->buf.translate = NULL; + re_set_syntax(RE_SYNTAX_POSIX_EXTENDED); msg = re_compile_pattern(p, strlen(p), &r->buf); if (!msg) return r; @@ -37,8 +53,10 @@ rx_compile(byte *p) void rx_free(regex *r) { - free(r->buf.buffer); - free(r); + xfree(r->buf.buffer); + if (r->buf.translate) + xfree(r->buf.translate); + xfree(r); } int