]> mj.ucw.cz Git - libucw.git/blobdiff - ucw/regex.c
xtypes: Added FIXME with possible segfault.
[libucw.git] / ucw / regex.c
index 6ead4648e9f8e270e77c232bd4a62211b67c2403..131620b4620c5cc6484159985e76fcba44b30eeb 100644 (file)
@@ -8,15 +8,15 @@
  *     of the GNU Lesser General Public License.
  */
 
-#include "ucw/lib.h"
-#include "ucw/chartype.h"
-#include "ucw/hashfunc.h"
-#include "ucw/regex.h"
+#include <ucw/lib.h>
+#include <ucw/chartype.h>
+#include <ucw/hashfunc.h>
+#include <ucw/regex.h>
 
 #include <stdio.h>
 #include <string.h>
 
-#ifdef CONFIG_POSIX_REGEX
+#ifdef CONFIG_UCW_POSIX_REGEX
 
 /* POSIX regular expression library */
 
@@ -68,7 +68,7 @@ rx_match(regex *r, const char *s)
 }
 
 int
-rx_subst(regex *r, const char *by, const char *src, char *dest, uns destlen)
+rx_subst(regex *r, const char *by, const char *src, char *dest, uint destlen)
 {
   char *end = dest + destlen - 1;
 
@@ -82,11 +82,11 @@ rx_subst(regex *r, const char *by, const char *src, char *dest, uns destlen)
          by++;
          if (*by >= '0' && *by <= '9') /* \0 gets replaced by entire pattern */
            {
-             uns j = *by++ - '0';
+             uint j = *by++ - '0';
              if (j <= r->rx.re_nsub && r->matches[j].rm_so >= 0)
                {
                  const char *s = src + r->matches[j].rm_so;
-                 uns i = r->matches[j].rm_eo - r->matches[j].rm_so;
+                 uint i = r->matches[j].rm_eo - r->matches[j].rm_so;
                  if (dest + i >= end)
                    return -1;
                  memcpy(dest, s, i);
@@ -104,7 +104,7 @@ rx_subst(regex *r, const char *by, const char *src, char *dest, uns destlen)
   return 1;
 }
 
-#elif defined(CONFIG_PCRE)
+#elif defined(CONFIG_UCW_PCRE)
 
 /* PCRE library */
 
@@ -113,8 +113,8 @@ rx_subst(regex *r, const char *by, const char *src, char *dest, uns destlen)
 struct regex {
   pcre *rx;
   pcre_extra *extra;
-  uns match_array_size;
-  uns real_matches;
+  uint match_array_size;
+  uint real_matches;
   int matches[0];                      /* (max_matches+1) pairs (pos,len) plus some workspace */
 };
 
@@ -168,7 +168,7 @@ rx_match(regex *r, const char *s)
 }
 
 int
-rx_subst(regex *r, const char *by, const char *src, char *dest, uns destlen)
+rx_subst(regex *r, const char *by, const char *src, char *dest, uint destlen)
 {
   char *end = dest + destlen - 1;
 
@@ -182,11 +182,11 @@ rx_subst(regex *r, const char *by, const char *src, char *dest, uns destlen)
          by++;
          if (*by >= '0' && *by <= '9') /* \0 gets replaced by entire pattern */
            {
-             uns j = *by++ - '0';
+             uint j = *by++ - '0';
              if (j < r->real_matches && r->matches[2*j] >= 0)
                {
-                 char *s = src + r->matches[2*j];
-                 uns i = r->matches[2*j+1] - r->matches[2*j];
+                 const char *s = src + r->matches[2*j];
+                 uint i = r->matches[2*j+1] - r->matches[2*j];
                  if (dest + i >= end)
                    return -1;
                  memcpy(dest, s, i);
@@ -229,7 +229,7 @@ rx_compile(const char *p, int icase)
   r->buf.allocated = INITIAL_MEM;
   if (icase)
     {
-      unsigned i;
+      uint i;
       r->buf.translate = xmalloc (CHAR_SET_SIZE);
       /* Map uppercase characters to corresponding lowercase ones.  */
       for (i = 0; i < CHAR_SET_SIZE; i++)
@@ -267,7 +267,7 @@ rx_match(regex *r, const char *s)
 }
 
 int
-rx_subst(regex *r, const char *by, const char *src, char *dest, uns destlen)
+rx_subst(regex *r, const char *by, const char *src, char *dest, uint destlen)
 {
   char *end = dest + destlen - 1;
 
@@ -281,11 +281,11 @@ rx_subst(regex *r, const char *by, const char *src, char *dest, uns destlen)
          by++;
          if (*by >= '0' && *by <= '9') /* \0 gets replaced by entire pattern */
            {
-             uns j = *by++ - '0';
+             uint j = *by++ - '0';
              if (j < r->regs.num_regs)
                {
                  const char *s = src + r->regs.start[j];
-                 uns i = r->regs.end[j] - r->regs.start[j];
+                 uint i = r->regs.end[j] - r->regs.start[j];
                  if (r->regs.start[j] > r->len_cache || r->regs.end[j] > r->len_cache)
                    return -1;
                  if (dest + i >= end)