]> mj.ucw.cz Git - libucw.git/blobdiff - lib/regex.c
Removed obsolete examples of custom attributes. The image search attributes
[libucw.git] / lib / regex.c
index 5fea0976d83babbe178743efe45ee07b7c750e52..6ed90243c86a727e99a4a34c91a567dccb85e0d7 100644 (file)
@@ -2,9 +2,11 @@
  *     Sherlock Library -- Regular Expressions
  *
  *     (c) 1997 Martin Mares <mj@ucw.cz>
  *     Sherlock Library -- Regular Expressions
  *
  *     (c) 1997 Martin Mares <mj@ucw.cz>
+ *     (c) 2001 Robert Spalek <robert@ucw.cz>
  */
 
 #include "lib/lib.h"
  */
 
 #include "lib/lib.h"
+#include "lib/chartype.h"
 
 #include <stdio.h>
 #include <string.h>
 
 #include <stdio.h>
 #include <string.h>
@@ -12,6 +14,7 @@
 #include <regex.h>
 
 #define INITIAL_MEM 1024               /* Initial space allocated for each pattern */
 #include <regex.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;
 
 struct regex {
   struct re_pattern_buffer buf;
@@ -20,13 +23,24 @@ struct regex {
 };
 
 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;
 {
   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;
   msg = re_compile_pattern(p, strlen(p), &r->buf);
   if (!msg)
     return r;
@@ -37,6 +51,8 @@ void
 rx_free(regex *r)
 {
   xfree(r->buf.buffer);
 rx_free(regex *r)
 {
   xfree(r->buf.buffer);
+  if (r->buf.translate)
+    xfree(r->buf.translate);
   xfree(r);
 }
 
   xfree(r);
 }