Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 15 Aug 2011 18:03:36 +0000 (UTC)
From:      Gabor Kovesdan <gabor@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-user@freebsd.org
Subject:   svn commit: r224894 - user/gabor/tre-integration/contrib/tre/lib
Message-ID:  <201108151803.p7FI3aRi020944@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: gabor
Date: Mon Aug 15 18:03:35 2011
New Revision: 224894
URL: http://svn.freebsd.org/changeset/base/224894

Log:
  - Eliminate code duplication
  - TRE-specific style changes

Modified:
  user/gabor/tre-integration/contrib/tre/lib/regexec.c
  user/gabor/tre-integration/contrib/tre/lib/tre-compile.c

Modified: user/gabor/tre-integration/contrib/tre/lib/regexec.c
==============================================================================
--- user/gabor/tre-integration/contrib/tre/lib/regexec.c	Mon Aug 15 17:23:06 2011	(r224893)
+++ user/gabor/tre-integration/contrib/tre/lib/regexec.c	Mon Aug 15 18:03:35 2011	(r224894)
@@ -216,6 +216,28 @@ tre_match(const tre_tnfa_t *tnfa, const 
   return status;
 }
 
+#define ADJUST_OFFSETS							\
+  {									\
+    size_t slen = (size_t)(pmatch[0].rm_eo - pmatch[0].rm_so);		\
+    size_t offset = pmatch[0].rm_so;					\
+    int ret;								\
+									\
+    if ((len != (unsigned)-1) && (pmatch[0].rm_eo > len))		\
+      return REG_NOMATCH;						\
+    if ((long long)pmatch[0].rm_eo - pmatch[0].rm_so < 0)		\
+      return REG_NOMATCH;						\
+    ret = tre_match(tnfa, &str[offset], slen, type, nmatch,		\
+		    pmatch, eflags, preg->shortcut);			\
+    for (unsigned i = 0; (i == 0) || (!(eflags & REG_NOSUB) &&		\
+	 (i < nmatch)); i++)						\
+      {									\
+	pmatch[i].rm_so += offset;					\
+	pmatch[i].rm_eo += offset;					\
+      }									\
+    return ret;								\
+  }
+
+
 int
 tre_regnexec(const regex_t *preg, const char *str, size_t len,
 	 size_t nmatch, regmatch_t pmatch[], int eflags)
@@ -224,32 +246,10 @@ tre_regnexec(const regex_t *preg, const 
   tre_str_type_t type = (TRE_MB_CUR_MAX == 1) ? STR_BYTE : STR_MBS;
 
   if (eflags & REG_STARTEND)
-  {
-    if ((len != (unsigned)-1) && (pmatch[0].rm_eo > len))
-      return REG_NOMATCH;
-    if ((long long)pmatch[0].rm_eo - pmatch[0].rm_so < 0)
-      return REG_NOMATCH;
-    size_t slen = (size_t)(pmatch[0].rm_eo - pmatch[0].rm_so);
-    size_t offset = pmatch[0].rm_so;
-    int ret = tre_match(tnfa, &str[offset], slen, type, nmatch, pmatch, eflags,
-			preg->shortcut);
-    pmatch[0].rm_so += offset;
-    pmatch[0].rm_eo += offset;
-    if (!(eflags & REG_NOSUB))
-    {
-      for (unsigned i = 1; i < nmatch; i++)
-      {
-	pmatch[i].rm_so += offset;
-        pmatch[i].rm_eo += offset;
-      }
-    }
-    return ret;
-  }
+    ADJUST_OFFSETS
   else
-  {
     return tre_match(tnfa, str, len, type, nmatch, pmatch, eflags,
 		     preg->shortcut);
-  }
 }
 
 int
@@ -267,34 +267,13 @@ tre_regwnexec(const regex_t *preg, const
 	  size_t nmatch, regmatch_t pmatch[], int eflags)
 {
   tre_tnfa_t *tnfa = (void *)preg->TRE_REGEX_T_FIELD;
+  tre_str_type_t type = STR_WIDE;
 
   if (eflags & REG_STARTEND)
-  {
-    if ((len != (unsigned)-1) && (pmatch[0].rm_eo > len))
-      return REG_NOMATCH;
-    if ((long long)pmatch[0].rm_eo - pmatch[0].rm_so < 0)
-      return REG_NOMATCH;
-    size_t slen = (size_t)(pmatch[0].rm_eo - pmatch[0].rm_so);
-    size_t offset = pmatch[0].rm_so;
-    int ret = tre_match(tnfa, &str[offset], slen, STR_WIDE, nmatch, pmatch, eflags,
-			preg->shortcut);
-    pmatch[0].rm_so += offset;
-    pmatch[0].rm_eo += offset;
-    if (!(eflags & REG_NOSUB))
-    {
-      for (unsigned i = 0; i < nmatch; i++)
-      {
-        pmatch[i].rm_so += offset;
-        pmatch[i].rm_eo += offset;
-      }
-    }
-    return ret;
-  }
+    ADJUST_OFFSETS
   else
-  {
     return tre_match(tnfa, str, len, STR_WIDE, nmatch, pmatch, eflags,
 		     preg->shortcut);
-  }
 }
 
 int

Modified: user/gabor/tre-integration/contrib/tre/lib/tre-compile.c
==============================================================================
--- user/gabor/tre-integration/contrib/tre/lib/tre-compile.c	Mon Aug 15 17:23:06 2011	(r224893)
+++ user/gabor/tre-integration/contrib/tre/lib/tre-compile.c	Mon Aug 15 18:03:35 2011	(r224894)
@@ -1876,8 +1876,8 @@ tre_compile(regex_t *preg, const tre_cha
   if (!shortcut)
     return REG_ESPACE;
   ret = (cflags & REG_LITERAL)
-    ? tre_compile_literal(shortcut, regex, n, cflags)
-    : tre_compile_fast(shortcut, regex, n, cflags);
+	? tre_compile_literal(shortcut, regex, n, cflags)
+	: tre_compile_fast(shortcut, regex, n, cflags);
   if (ret == REG_OK)
     {
       preg->shortcut = shortcut;



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201108151803.p7FI3aRi020944>