svn commit: r231969 - in user/gabor/tre-integration: contrib/tre/lib include

Gabor Kovesdan gabor at FreeBSD.org
Tue Feb 21 13:08:57 UTC 2012


Author: gabor
Date: Tue Feb 21 13:08:56 2012
New Revision: 231969
URL: http://svn.freebsd.org/changeset/base/231969

Log:
  - Fix some bugs and fix compilation. The code is still not tested in runtime.

Modified:
  user/gabor/tre-integration/contrib/tre/lib/mregcomp.c
  user/gabor/tre-integration/contrib/tre/lib/mregexec.c
  user/gabor/tre-integration/contrib/tre/lib/regexec.c
  user/gabor/tre-integration/contrib/tre/lib/tre-internal.h
  user/gabor/tre-integration/contrib/tre/lib/tre-mfastmatch.c
  user/gabor/tre-integration/contrib/tre/lib/tre-mfastmatch.h
  user/gabor/tre-integration/include/mregex.h

Modified: user/gabor/tre-integration/contrib/tre/lib/mregcomp.c
==============================================================================
--- user/gabor/tre-integration/contrib/tre/lib/mregcomp.c	Tue Feb 21 12:57:52 2012	(r231968)
+++ user/gabor/tre-integration/contrib/tre/lib/mregcomp.c	Tue Feb 21 13:08:56 2012	(r231969)
@@ -30,12 +30,13 @@
 
 #include <string.h>
 #include <errno.h>
+#include <mregex.h>
 #include <regex.h>
 #include <stdlib.h>
 
-#include "tre-fastmatch.h"
 #include "tre-heuristic.h"
 #include "tre-internal.h"
+#include "tre-mfastmatch.h"
 #include "xmalloc.h"
 
 #ifdef TRE_LIBC_BUILD
@@ -53,16 +54,15 @@ __weak_reference(tre_mregfree, mregfree)
  */
 
 int
-tre_mcompile(mregex_t *preg, size_t nr, const tre_char_t *wregex[],
-	     size_t wn[], const char *regex[], size_t n, int cflags)
+tre_mcompile(mregex_t *preg, size_t nr, const wchar_t **wregex,
+	     size_t *wn, const char **regex, size_t *n, int cflags)
 {
   int ret;
-  tre_char_t **frags;
+  const wchar_t **frags;
   size_t *siz;
   wmsearch_t *wm;
 
   preg->k = nr;
-  preg->cflags = cflags;
   preg->patterns = xmalloc(nr * sizeof(regex_t));
   if (!preg->patterns)
     return REG_ESPACE;
@@ -79,8 +79,8 @@ tre_mcompile(mregex_t *preg, size_t nr, 
   /* If not literal, check if any of them have fixed-length prefix. */
   if (!(cflags & REG_LITERAL))
     for (int i = 0; i < nr; i++)
-      if ((preg->patterns[i]->heur == NULL) ||
-	 (((heur_t)preg->patterns[i]->heur)->arr[0] == NULL))
+      if ((preg->patterns[i].heur == NULL) ||
+	 (((heur_t *)(preg->patterns[i].heur))->arr[0] == NULL))
 	{
 	  preg->type = MHEUR_NONE;
 	  goto finish;
@@ -102,8 +102,8 @@ tre_mcompile(mregex_t *preg, size_t nr, 
 
       for (int j = 0; j < nr; j++)
 	{
-	  frags[j] = &((heur_t)preg->patterns[j]->heur)->arr[0];
-	  siz[j] = ((heur_t)preg->patterns[j]->heur)->siz[0];
+	  frags[j] = ((heur_t *)(preg->patterns[j].heur))->warr[0];
+	  siz[j] = ((heur_t *)(preg->patterns[j].heur))->siz[0];
 	}
     }
   else
@@ -119,6 +119,7 @@ tre_mcompile(mregex_t *preg, size_t nr, 
   ret = tre_wmcomp(wm, nr, frags, siz, cflags);
     if (ret != REG_OK)
       goto err;
+  wm->cflags = cflags;
   preg->searchdata = wm;
 
   /* Set the specific type of matching. */
@@ -135,8 +136,7 @@ err:
   if (preg->patterns)
     {
       for (int i = 1; i < nr; i++)
-	if (preg->patterns[i])
-	  tre_regfree(preg->patterns[i]);
+	tre_regfree(&preg->patterns[i]);
       xfree(preg->patterns);
     }
   if (wm)
@@ -145,8 +145,8 @@ err:
 finish:
   if (!(cflags & REG_LITERAL))
     {
-      if (frag)
-	xfree(frag);
+      if (frags)
+	xfree(frags);
       if (siz)
 	xfree(siz);
     }
@@ -154,46 +154,48 @@ finish:
 }
 
 int
-tre_mregncomp(mregex_t *preg, size_t nr, const char *regex[],
-	      size_t n[], int cflags)
+tre_mregncomp(mregex_t *preg, size_t nr, const char **regex,
+	      size_t *n, int cflags)
 {
   int i, ret;
-  tre_char_t **wregex;
+  const wchar_t **wr;
+  wchar_t **wregex;
   size_t *wlen;
 
-  wregex = xmalloc(nr * sizeof(tre_char *);
+  wregex = xmalloc(nr * sizeof(wchar_t *));
   if (!wregex)
-    return REG_ENOMEM;
-  wlen = xmalloc(nr * sizeof(size_t);
+    return REG_ESPACE;
+  wlen = xmalloc(nr * sizeof(size_t));
   if (!wlen)
-    return REG_ENOMEM;
+    return REG_ESPACE;
 
-  for (i = 0; i++; i < nr)
+  for (i = 0; i < nr; i++)
     {
       ret = tre_convert_pattern_to_wcs(regex[i], n[i], &wregex[i], &wlen[i]);
       if (ret != REG_OK)
 	goto fail;
     }
 
-  ret = tre_mcompile(preg, nr, regex, n, cflags);
+  wr = (const wchar_t **)wregex;
+  ret = tre_mcompile(preg, nr, wr, wlen, regex, n, cflags);
 
 fail:
-  for (int j = 0; j++; j < i)
+  for (int j = 0; j < i; j++)
     tre_free_wcs_pattern(wregex[j]);
   return ret;
 }
 
 int
-tre_mregcomp(mregex_t *preg, size_t nr, const char *regex[], int cflags)
+tre_mregcomp(mregex_t *preg, size_t nr, const char **regex, int cflags)
 {
   int ret;
   size_t *wlen;
 
-  wlen = xmalloc(nr * sizeof(size_t);
+  wlen = xmalloc(nr * sizeof(size_t));
   if (!wlen)
-    return REG_ENOMEM;
+    return REG_ESPACE;
 
-  for (int i = 0; i++; i < nr)
+  for (int i = 0; i < nr; i++)
     wlen[i] = strlen(regex[i]);
 
   ret = tre_mregncomp(preg, nr, regex, wlen, cflags);
@@ -204,47 +206,49 @@ tre_mregcomp(mregex_t *preg, size_t nr, 
 
 #ifdef TRE_WCHAR
 int
-tre_mregwncomp(mregex_t *preg, size_t nr, const wchar_t *regex[],
-	       size_t n[], int cflags)
+tre_mregwncomp(mregex_t *preg, size_t nr, const wchar_t **regex,
+	       size_t *n, int cflags)
 {
   int i, ret;
+  const char **sr;
   char **sregex;
   size_t *slen;
 
-  sregex = xmalloc(nr * sizeof(char *);
+  sregex = xmalloc(nr * sizeof(char *));
   if (!sregex)
-    return REG_ENOMEM;
-  slen = xmalloc(nr * sizeof(size_t);
+    return REG_ESPACE;
+  slen = xmalloc(nr * sizeof(size_t));
   if (!slen)
-    return REG_ENOMEM;
+    return REG_ESPACE;
 
-  for (i = 0; i++; i < nr)
+  for (i = 0; i < nr; i++)
     {
       ret = tre_convert_pattern_to_mbs(regex[i], n[i], &sregex[i], &slen[i]);
       if (ret != REG_OK)
         goto fail;
     }
 
-  ret = tre_mcompile(preg, nr, regex, n, cflags);
+  sr = (const char **)sregex;
+  ret = tre_mcompile(preg, nr, regex, n, sr, slen, cflags);
 
 fail:
-  for (int j = 0; j++; j < i)
-    tre_free_mbs_pattern(wregex[j]);
+  for (int j = 0; j < i; j++)
+    tre_free_mbs_pattern(sregex[j]);
   return ret;
 }
 
 int
-tre_mregwcomp(mregex_t *preg, size_t nr, const wchar_t *regex[],
+tre_mregwcomp(mregex_t *preg, size_t nr, const wchar_t **regex,
 	      int cflags)
 {
   int ret;
   size_t *wlen;
 
-  wlen = xmalloc(nr * sizeof(size_t);
+  wlen = xmalloc(nr * sizeof(size_t));
   if (!wlen)
-    return REG_ENOMEM;
+    return REG_ESPACE;
 
-  for (int i = 0; i++; i < nr)
+  for (int i = 0; i < nr; i++)
     wlen[i] = tre_strlen(regex[i]);
 
   ret = tre_mregwncomp(preg, nr, regex, wlen, cflags);
@@ -256,7 +260,11 @@ tre_mregwcomp(mregex_t *preg, size_t nr,
 void
 tre_mregfree(mregex_t *preg)
 {
-  wmfree(preg);
+  if (!preg)
+    {
+      tre_wmfree(preg->searchdata);
+      xfree(preg);
+    }
 }
 
 /* EOF */

Modified: user/gabor/tre-integration/contrib/tre/lib/mregexec.c
==============================================================================
--- user/gabor/tre-integration/contrib/tre/lib/mregexec.c	Tue Feb 21 12:57:52 2012	(r231968)
+++ user/gabor/tre-integration/contrib/tre/lib/mregexec.c	Tue Feb 21 13:08:56 2012	(r231969)
@@ -31,6 +31,7 @@
 #include <limits.h>
 #include <mregex.h>
 #include <regex.h>
+#include <string.h>
 #ifdef HAVE_WCHAR_H
 #include <wchar.h>
 #endif /* HAVE_WCHAR_H */
@@ -52,14 +53,16 @@ tre_mmatch(const void *str, size_t len, 
 	   size_t nmatch, regmatch_t pmatch[], int eflags,
 	   const mregex_t *preg)
 {
-  tre_char_t *str_wide = str;
-  char *str_byte = str;
+  const tre_char_t *str_wide = str;
+  const char *str_byte = str;
   int ret;
   bool need_offsets;
 
-  need_offsets = (preg->cflags & REG_NOSUB) && (nmatch > 0);
+  need_offsets = (((wmsearch_t *)(preg->searchdata))->cflags & REG_NOSUB) &&
+		 (nmatch > 0);
 
-#define INPUT(pos) ((type == STR_WIDE) ? str_wide[pos] : str_byte[pos])
+#define INPUT(pos) ((type == STR_WIDE) ? (const void *)&str_wide[pos] : \
+		   (const void *)&str_byte[pos])
 
   /*
    * Worst case: at least one pattern does not have a literal
@@ -83,7 +86,7 @@ tre_mmatch(const void *str, size_t len, 
 	    {
 	      pm[i] = xmalloc(nmatch * sizeof(regmatch_t));
 	      if (!pm[i])
-		goto finish;
+		goto finish1;
 	    }
 	}
 
@@ -102,14 +105,14 @@ tre_mmatch(const void *str, size_t len, 
 	  else if (ret == REG_NOMATCH)
 	    pm[i][0].rm_so = -1;
 	  else if (ret != REG_OK)
-	    goto finish;
+	    goto finish1;
 	}
 
       if (!need_offsets)
 	return REG_NOMATCH;
 
       /* Check whether there has been a match at all. */
-      for (i; i < preg->k; i++)
+      for (i = 0; i < preg->k; i++)
 	if (pm[i][0].rm_so != -1)
 	  {
 	    first = i;
@@ -138,7 +141,7 @@ tre_mmatch(const void *str, size_t len, 
 	}
       ret = REG_OK;
 
-finish:
+finish1:
       if (pm)
 	{
 	  for (i = 0; i < preg->k; i++)
@@ -170,29 +173,29 @@ finish:
       while (st < len)
 	{
 	  /* Look for a possible match. */
-	  ret = tre_wmexec(preg->wm, INPUT(st), len, type, 1, &rpm,
+	  ret = tre_wmexec(preg->searchdata, INPUT(st), len, type, 1, &rpm,
 			   eflags);
 	  if (ret != REG_OK)
-	    goto finish;
+	    goto finish2;
 
 	  /* Need to start from here if this fails. */
 	  st += rpm.rm_so + 1;
 
 	  /* Look for the beginning of the line. */
 	  for (bl = st; bl > 0; bl--)
-	    if ((type == STR_WIDE) ? (str_wide[bl] == TRE_CHAR('\n'))
-		(str_byte[bl] == '\n')
+	    if ((type == STR_WIDE) ? (str_wide[bl] == TRE_CHAR('\n')) :
+		(str_byte[bl] == '\n'))
 	      break;
 
 	  /* Look for the end of the line. */
 	  for (el = st; el < len; el++)
-	   if ((type == STR_WIDE) ? (str_wide[el] == TRE_CHAR('\n'))
-	        (str_byte[el] == '\n')
+	   if ((type == STR_WIDE) ? (str_wide[el] == TRE_CHAR('\n')) :
+	        (str_byte[el] == '\n'))
 	      break;
 
 	  /* Try to match the pattern on the line. */
 	  ret = tre_match(&preg->patterns[rpm.p], INPUT(bl), el - bl,
-			  type, need_offsets ? nmatch : 0, &pm, eflags);
+			  type, need_offsets ? nmatch : 0, pm, eflags);
 
 	  /* Evaluate result. */
 	  if (ret == REG_NOMATCH)
@@ -208,16 +211,16 @@ finish:
 		      pmatch[i].rm_so = pm[i].rm_so;
 		      pmatch[i].rm_eo = pm[i].rm_eo;
 		      pmatch[i].p = rpm.p;
-		      goto finish;
+		      goto finish2;
 		    }
 		}
 	    }
 	  else
-	    goto finish;
+	    goto finish2;
 	}
-finish:
+finish2:
       if (!pm)
-	xfree(pm)
+	xfree(pm);
       return ret;
     }
 
@@ -227,7 +230,8 @@ finish:
    */
   else if (preg->type == MHEUR_LITERAL)
     {
-      return tre_wmexec(preg->wm, str, len, type, nmatch, pmatch, eflags);
+      return tre_wmexec(preg->searchdata, str, len, type, nmatch, pmatch,
+			eflags);
     }
 
   /*
@@ -249,7 +253,8 @@ finish:
 
       while (st < len)
 	{
-	  ret = tre_wmexec(preg->wm, INPUT(st), len, type, nmatch, &rpm, eflags);
+	  ret = tre_wmexec(preg->searchdata, INPUT(st), len, type, nmatch,
+			   &rpm, eflags);
 	  if (ret != REG_OK)
 	    return ret;
 
@@ -261,17 +266,17 @@ finish:
 	      for (int i = 0; i < nmatch; i++)
 		{
 		  pm[i].rm_so += st;
-		  pm[i].rm_eo += eo;
+		  pm[i].rm_eo += st;
 		  pm[i].p = rpm.p;
 		}
-	      goto finish;
+	      goto finish3;
 	    }
 	  else if ((ret != REG_NOMATCH) || (ret != REG_OK))
-	    goto finish;
-	  st += pm1.rm_so + 1;
+	    goto finish3;
+	  st += rpm.rm_so + 1;
 	}
 
-finish:
+finish3:
       if (pm)
 	xfree(pm);
       return ret;
@@ -293,7 +298,7 @@ tre_mregnexec(const mregex_t *preg, cons
 }
 
 int
-tre_regexec(const mregex_t *preg, const char *str,
+tre_mregexec(const mregex_t *preg, const char *str,
 	size_t nmatch, regmatch_t pmatch[], int eflags)
 {
   return tre_mregnexec(preg, str, strlen(str), nmatch, pmatch, eflags);
@@ -319,7 +324,7 @@ int
 tre_mregwexec(const mregex_t *preg, const wchar_t *str,
 	 size_t nmatch, regmatch_t pmatch[], int eflags)
 {
-  return tre_regwnexec(preg, str, tre_strlen(str), nmatch, pmatch, eflags);
+  return tre_mregwnexec(preg, str, tre_strlen(str), nmatch, pmatch, eflags);
 }
 
 #endif /* TRE_WCHAR */

Modified: user/gabor/tre-integration/contrib/tre/lib/regexec.c
==============================================================================
--- user/gabor/tre-integration/contrib/tre/lib/regexec.c	Tue Feb 21 12:57:52 2012	(r231968)
+++ user/gabor/tre-integration/contrib/tre/lib/regexec.c	Tue Feb 21 13:08:56 2012	(r231969)
@@ -157,7 +157,7 @@ tre_have_approx(const regex_t *preg)
   return tnfa->have_approx;
 }
 
-static int
+int
 tre_match(const regex_t *preg, const void *string, size_t len,
 	  tre_str_type_t type, size_t nmatch, regmatch_t pmatch[],
 	  int eflags)

Modified: user/gabor/tre-integration/contrib/tre/lib/tre-internal.h
==============================================================================
--- user/gabor/tre-integration/contrib/tre/lib/tre-internal.h	Tue Feb 21 12:57:52 2012	(r231968)
+++ user/gabor/tre-integration/contrib/tre/lib/tre-internal.h	Tue Feb 21 13:08:56 2012	(r231969)
@@ -294,6 +294,11 @@ int
 tre_compile(regex_t *preg, const tre_char_t *wregex, size_t wn,
 	    const char *regex, size_t n, int cflags);
 
+int
+tre_match(const regex_t *preg, const void *string, size_t len,
+	  tre_str_type_t type, size_t nmatch, regmatch_t pmatch[],
+	  int eflags);
+
 void
 tre_free(regex_t *preg);
 

Modified: user/gabor/tre-integration/contrib/tre/lib/tre-mfastmatch.c
==============================================================================
--- user/gabor/tre-integration/contrib/tre/lib/tre-mfastmatch.c	Tue Feb 21 12:57:52 2012	(r231968)
+++ user/gabor/tre-integration/contrib/tre/lib/tre-mfastmatch.c	Tue Feb 21 13:08:56 2012	(r231969)
@@ -29,7 +29,9 @@
 #endif /* HAVE_CONFIG_H */
 #include <mregex.h>
 #include <regex.h>
+#include <string.h>
 
+#include "hashtable.h"
 #include "tre-mfastmatch.h"
 #include "xmalloc.h"
 
@@ -39,28 +41,28 @@
   var = xmalloc(siz);							\
   if (!var)								\
     {									\
-      err = REG_ESPACE;							\
+      ret = REG_ESPACE;							\
       goto fail;							\
     }
 
 #define FAIL								\
   do									\
     {									\
-      err = REG_BADPAT;							\
+      ret = REG_BADPAT;							\
       goto fail;							\
-    } while (0)
+    } while (0);
 
 #define _PROC_WM(pat_arr, siz_arr, char_size, sh_field, m_field)	\
   /* Determine shortest pattern length */				\
-  wm->m_field = size_arr[0];						\
+  wm->m_field = siz_arr[0];						\
   for (int i = 1; i < nr; i++)						\
-    wm->m_field = size_arr[i] < wm->m_field ? size_arr[i] : wm->m_field;\
+    wm->m_field = siz_arr[i] < wm->m_field ? siz_arr[i] : wm->m_field;	\
 									\
   wm->sh_field = hashtable_init((wm->m_field - 1) * nr * 2, WM_B *	\
-				char_size, sizeof(wmentry_t);		\
+				char_size, sizeof(wmentry_t));		\
   if (!wm->sh_field)							\
     {									\
-      err = REG_ESPACE;							\
+      ret = REG_ESPACE;							\
       goto fail;							\
     }									\
 									\
@@ -71,7 +73,7 @@
 									\
       /* First fragment, treat special because it is a prefix */	\
       ret = hashtable_get(wm->sh_field, pat_arr[i], entry);		\
-      sh = size_arr[i] - WM_B;						\
+      sh = siz_arr[i] - WM_B;						\
       switch (ret)							\
         {								\
           case HASH_NOTFOUND:						\
@@ -90,10 +92,10 @@
               FAIL;							\
         }								\
       /* Intermediate fragments, only shift calculated */		\
-      for (int j = 1; j < size_arr[i] - WB_M; j++)			\
+      for (int j = 1; j < siz_arr[i] - WM_B; j++)			\
         {								\
           ret = hashtable_get(wm->sh_field, &pat_arr[i][j], entry);	\
-          sh = size_arr[i] - WM_B - j;					\
+          sh = siz_arr[i] - WM_B - j;					\
           switch (ret)							\
             {								\
               case HASH_NOTFOUND:					\
@@ -108,9 +110,10 @@
               case HASH_OK:						\
                 entry->shift = entry->shift < sh ? entry->shift : sh;	\
                 if (ret != HASH_UPDATED)				\
-                  FAIL;							\
+                FAIL;							\
+	    }								\
         }								\
-      ret = hashtable_get(wm->sh_field, &pat_arr[i][n[i] - WB_M],	\
+      ret = hashtable_get(wm->sh_field, &pat_arr[i][n[i] - WM_B],	\
 			  entry);					\
       switch (ret)							\
         {								\
@@ -119,7 +122,7 @@
             entry->suff = 1;						\
             entry->pref = 0;						\
             entry->suff_list[0] = i;					\
-            ret = hashtable_put(wm->sh_field, &pat_arr[i][n[i] - WB_M],	\
+            ret = hashtable_put(wm->sh_field, &pat_arr[i][n[i] - WM_B],	\
 				entry);					\
             if (ret != HASH_OK)						\
               FAIL;							\
@@ -132,31 +135,31 @@
     }									\
   xfree(entry);
 
-#ifdef _SAVE_PATTERNS(dst, s)						\
+#define _SAVE_PATTERNS(dst, s, type)					\
   do									\
     {									\
-      ALLOC(dst, sizeof(tre_char_t *) * nr);				\
+      ALLOC(dst, sizeof(type *) * nr);					\
       ALLOC(s, sizeof(size_t) * nr);					\
       for (int i = 0; i < nr; i++)					\
 	{								\
-	  ALLOC(dst[i], n[i]);						\
-	  memcpy(dst[i], regex[i], n[i] * sizeof(tre_char_t));		\
+	  ALLOC(dst[i], n[i] * sizeof(type));				\
+	  memcpy(dst[i], regex[i], n[i] * sizeof(type));		\
 	  s[i] = n[i];							\
 	}								\
     } while (0);
 
 #define SAVE_PATTERNS							\
-  _SAVE_PATTERNS(wm->pat, wm->siz)
+  _SAVE_PATTERNS(wm->pat, wm->siz, char)
 #define SAVE_PATTERNS_WIDE						\
-  _SAVE_PATTERNS(wm->wpat, wm->wsiz)
+  _SAVE_PATTERNS(wm->wpat, wm->wsiz, tre_char_t)
 
 #ifdef TRE_WCHAR
-#define PROC_WM(par_arr, size_arr)					\
+#define PROC_WM(pat_arr, size_arr)					\
   _PROC_WM(pat_arr, size_arr, 1, shift, m)
-#define PROC_WM_WIDE(par_arr, size_arr)					\
+#define PROC_WM_WIDE(pat_arr, size_arr)					\
   _PROC_WM(pat_arr, size_arr, sizeof(tre_char_t), wshift, wm)
 #else
-#define PROC_WM(par_arr, size_arr)					\
+#define PROC_WM(pat_arr, size_arr)					\
   _PROC_WM(pat_arr, size_arr, 1, shift, m)
 #endif
 
@@ -168,14 +171,14 @@
  */
 
 int
-tre_wmcomp(wmsearch_t *wm, size_t nr, const tre_char_t *regex[],
-	   size_t n[], int cflags)
+tre_wmcomp(wmsearch_t *wm, size_t nr, const tre_char_t **regex,
+	   size_t *n, int cflags)
 {
   wmentry_t *entry = NULL;
-  int err;
+  int ret;
 #ifdef TRE_WCHAR
   char **bregex;
-  int *bn;
+  size_t *bn;
 #endif
 
   ALLOC(wm, sizeof(wmsearch_t));
@@ -195,14 +198,13 @@ tre_wmcomp(wmsearch_t *wm, size_t nr, co
       /* Should never happen */
       if (ret == (size_t)-1)
 	{
-	  err = REG_BADPAT;
+	  ret = REG_BADPAT;
 	  goto fail;
 	}
     }
 
-  wm->wpat = bregex;
-  wm->wsize = bn;
-
+  wm->pat = bregex;
+  wm->siz = bn;
   PROC_WM(bregex, bn);
   for (int i = 0; i < nr; i++)
     xfree(bregex[i]);
@@ -218,39 +220,39 @@ tre_wmcomp(wmsearch_t *wm, size_t nr, co
   return REG_OK;
 fail:
 #ifdef TRE_WCHAR
-  if (wm->whash)
-    hashtable_free(wm->whash);
+  if (wm->wshift)
+    hashtable_free(wm->wshift);
 #endif
-  if (wm->hash)
-    hashtable_free(wm->hash);
+  if (wm->shift)
+    hashtable_free(wm->shift);
   if (wm)
     xfree(wm);
   if (entry)
     xfree(entry);
-  return err;
+  return ret;
 }
 
-#define MATCH(beg, end, p)						\
+#define MATCH(beg, end, idx)						\
   do									\
     {									\
-      if (!(preg->cflags & REG_NOSUB) && (nmatch > 0))			\
+      if (!(wm->cflags & REG_NOSUB) && (nmatch > 0))			\
 	{								\
 	  pmatch->rm_so = beg;						\
 	  pmatch->rm_eo = end;						\
-	  pmatch->p = p;						\
-	  err = REG_OK;							\
+	  pmatch->p = idx;						\
+	  ret = REG_OK;							\
 	  goto finish;							\
 	}								\
     } while (0);
 
 #define _WMSEARCH(data, pats, sizes, mlen, tbl, dshift)			\
-  do									\
+  while (pos < len)							\
     {									\
-      ret = hashtable_get(tbl, data[pos - WM_B], s_entry);		\
+      ret = hashtable_get(tbl, &data[pos - WM_B], s_entry);		\
       shift = (ret == HASH_OK) ? s_entry->shift : dshift;		\
       if (shift == 0)							\
 	{								\
-	  ret = hashtable_get(tbl, data[pos - mlen, p_entry);		\
+	  ret = hashtable_get(tbl, &data[pos - mlen], p_entry);		\
 	  if (ret == HASH_NOTFOUND)					\
 	    {								\
 	      pos += 1;							\
@@ -284,13 +286,13 @@ fail:
 	}								\
       else								\
 	pos += shift;							\
-    } while (0);
+    }
 
 #define WMSEARCH							\
-  _WMSEARCH(byte_str, wm->pat, wm->siz, wm->m, wm->hash,		\
+  _WMSEARCH(byte_str, wm->pat, wm->siz, wm->m, wm->shift,		\
 	    wm->defsh)
 #define WMSEARCH_WIDE							\
-   _WMSEARCH(wide_str, wm->wpats, wm->wsiz, wm->wm, wm->whash,		\
+  _WMSEARCH(wide_str, wm->wpat, wm->wsiz, wm->wm, wm->wshift,		\
 	     wm->wdefsh)
 
 int
@@ -299,12 +301,11 @@ tre_wmexec(const wmsearch_t *wm, const v
 	   int eflags)
 {
   wmentry_t *s_entry, *p_entry;
-  tre_char_t *wide_str = str;
-  char *byte_str = str;
+  const tre_char_t *wide_str = str;
+  const char *byte_str = str;
   size_t pos = (type == STR_WIDE) ? wm->wm : wm->m;
   size_t shift;
-  int ret;
-  int err = REG_NOMATCH;
+  int ret = REG_NOMATCH;
 
   ALLOC(s_entry, sizeof(wmentry_t));
   ALLOC(p_entry, sizeof(wmentry_t));
@@ -312,9 +313,13 @@ tre_wmexec(const wmsearch_t *wm, const v
   while (pos < len)
     {
       if (type == STR_WIDE)
-	WMSEARCH;
+	{
+	  WMSEARCH_WIDE;
+	}
       else
-	WMSEARCH_WIDE;
+	{
+	  WMSEARCH;
+	}
     }
 
 fail:
@@ -323,15 +328,15 @@ finish:
     xfree(s_entry);
   if (p_entry)
     xfree(p_entry);
-  return err;
+  return ret;
 }
 
 void
 tre_wmfree(wmsearch_t *wm)
 {
 
-  if (wm->hash)
-    hashtable_free(wm->hash);
+  if (wm->shift)
+    hashtable_free(wm->shift);
   for (int i = 0; i < wm->n; i++)
     if (wm->pat[i])
       xfree(wm->pat[i]);
@@ -340,8 +345,8 @@ tre_wmfree(wmsearch_t *wm)
   if (wm->siz)
     xfree(wm->siz);
 #ifdef TRE_WCHAR
-  if (wm->whash)
-    hashtable_free(wm->whash);
+  if (wm->wshift)
+    hashtable_free(wm->wshift);
   for (int i = 0; i < wm->wn; i++)
     if (wm->wpat[i])
       xfree(wm->wpat[i]);

Modified: user/gabor/tre-integration/contrib/tre/lib/tre-mfastmatch.h
==============================================================================
--- user/gabor/tre-integration/contrib/tre/lib/tre-mfastmatch.h	Tue Feb 21 12:57:52 2012	(r231968)
+++ user/gabor/tre-integration/contrib/tre/lib/tre-mfastmatch.h	Tue Feb 21 13:08:56 2012	(r231969)
@@ -7,6 +7,8 @@
 #include <mregex.h>
 #include <regex.h>
 
+#include "tre-internal.h"
+
 #define WM_MAXPAT 64
 
 #define MHEUR_NONE 0
@@ -21,14 +23,14 @@ typedef struct {
 	size_t n;		/* No of patterns */
         size_t m;		/* Shortest pattern length */
 	size_t defsh;		/* Default shift */
-	void *hash;		/* Wu-Manber shift table */
+	void *shift;		/* Wu-Manber shift table */
 #ifdef TRE_WCHAR
 	tre_char_t **wpat;	/* Patterns (wide) */
-	size_t wsiz;		/* Pattern sizes (wide) */
+	size_t *wsiz;		/* Pattern sizes (wide) */
 	size_t wn;		/* No of patterns (wide) */
 	size_t wm;		/* Shortest pattern length (wide) */
 	size_t wdefsh;		/* Default shift (wide) */
-	void *whash;		/* Wu-Manber shift table (wide) */
+	void *wshift;		/* Wu-Manber shift table (wide) */
 #endif
 } wmsearch_t;
 
@@ -41,8 +43,8 @@ typedef struct {
 } wmentry_t;
 
 int
-tre_wmcomp(wmsearch_t *wm, size_t nr, const tre_char_t *regex[],
-	   size_t n[], int cflags);
+tre_wmcomp(wmsearch_t *wm, size_t nr, const tre_char_t **regex,
+	   size_t *n, int cflags);
 int
 tre_wmexec(const wmsearch_t *wm, const void *str, size_t len,
 	   tre_str_type_t type, size_t nmatch, regmatch_t pmatch[],

Modified: user/gabor/tre-integration/include/mregex.h
==============================================================================
--- user/gabor/tre-integration/include/mregex.h	Tue Feb 21 12:57:52 2012	(r231968)
+++ user/gabor/tre-integration/include/mregex.h	Tue Feb 21 13:08:56 2012	(r231969)
@@ -14,24 +14,24 @@ typedef struct {
 } mregex_t;
 
 int
-tre_mregncomp(mregex_t *preg, size_t nr, const char *regex[],
-	      size_t n[], int cflags);
+tre_mregncomp(mregex_t *preg, size_t nr, const char **regex,
+	      size_t *n, int cflags);
 int
-tre_mregcomp(mregex_t *preg, size_t nr, const char *regex[], int cflags);
+tre_mregcomp(mregex_t *preg, size_t nr, const char **regex, int cflags);
 int
 tre_mregnexec(const mregex_t *preg, const char *str, size_t len,
 	      size_t nmatch, regmatch_t pmatch[], int eflags);
 int
-tre_regexec(const mregex_t *preg, const char *str,
+tre_mregexec(const mregex_t *preg, const char *str,
 	    size_t nmatch, regmatch_t pmatch[], int eflags);
 void
 tre_mregfree(mregex_t *preg);
 #ifdef TRE_WCHAR
 int
-tre_mregwncomp(mregex_t *preg, size_t nr, const wchar_t *regex[],
-	       size_t n[], int cflags);
+tre_mregwncomp(mregex_t *preg, size_t nr, const wchar_t **regex,
+	       size_t *n, int cflags);
 int
-tre_mregwcomp(mregex_t *preg, size_t nr, const wchar_t *regex[],
+tre_mregwcomp(mregex_t *preg, size_t nr, const wchar_t **regex,
 	      int cflags);
 int
 tre_mregwnexec(const mregex_t *preg, const wchar_t *str, size_t len,


More information about the svn-src-user mailing list