X-Git-Url: http://mj.ucw.cz/gitweb/?a=blobdiff_plain;f=lib%2Fregex.c;h=ce230848facdd0ba7b1709dc311daa23dd66312b;hb=54eb231d1d8fcb8b02c56d437152699764bcda3e;hp=2df8fd043027e421c1c2eaaca86ad873656db83d;hpb=5b53087fa5a07ff89d34cf3bf3bc1b28809f05c2;p=libucw.git diff --git a/lib/regex.c b/lib/regex.c index 2df8fd04..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/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