X-Git-Url: http://mj.ucw.cz/gitweb/?a=blobdiff_plain;f=lib%2Fregex.c;h=ce230848facdd0ba7b1709dc311daa23dd66312b;hb=54eb231d1d8fcb8b02c56d437152699764bcda3e;hp=5fea0976d83babbe178743efe45ee07b7c750e52;hpb=e9aa499507f33db9fac50f3864609a6b292685e0;p=libucw.git diff --git a/lib/regex.c b/lib/regex.c index 5fea0976..ce230848 100644 --- a/lib/regex.c +++ b/lib/regex.c @@ -2,9 +2,14 @@ * Sherlock Library -- Regular Expressions * * (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 @@ -12,6 +17,7 @@ #include #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,13 +26,24 @@ struct regex { }; regex * -rx_compile(byte *p) +rx_compile(byte *p, int icase) { regex *r = xmalloc_zero(sizeof(regex)); const char *msg; 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,6 +54,8 @@ void rx_free(regex *r) { xfree(r->buf.buffer); + if (r->buf.translate) + xfree(r->buf.translate); xfree(r); }