Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 11 May 2011 00:46:22 +0000 (UTC)
From:      Gabor Kovesdan <gabor@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-user@freebsd.org
Subject:   svn commit: r221751 - in user/gabor/tre-integration: contrib/tre/lib include
Message-ID:  <201105110046.p4B0kMP9066656@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: gabor
Date: Wed May 11 00:46:22 2011
New Revision: 221751
URL: http://svn.freebsd.org/changeset/base/221751

Log:
  - Implement the BSD-specific REG_STARTEND flag for regexec()

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

Modified: user/gabor/tre-integration/contrib/tre/lib/regexec.c
==============================================================================
--- user/gabor/tre-integration/contrib/tre/lib/regexec.c	Tue May 10 21:18:45 2011	(r221750)
+++ user/gabor/tre-integration/contrib/tre/lib/regexec.c	Wed May 11 00:46:22 2011	(r221751)
@@ -27,6 +27,7 @@ char *alloca ();
 #endif
 #endif /* TRE_USE_ALLOCA */
 
+#include <stdio.h>
 #include <assert.h>
 #include <stdlib.h>
 #include <string.h>
@@ -206,7 +207,28 @@ tre_regnexec(const regex_t *preg, const 
   tre_tnfa_t *tnfa = (void *)preg->TRE_REGEX_T_FIELD;
   tre_str_type_t type = (TRE_MB_CUR_MAX == 1) ? STR_BYTE : STR_MBS;
 
-  return tre_match(tnfa, str, len, type, nmatch, pmatch, eflags);
+  if (eflags & REG_STARTEND)
+  {
+    off_t s_off = pmatch[0].rm_so;
+    off_t e_off = pmatch[0].rm_eo;
+    size_t slen = e_off - s_off;
+    char *sstr = xmalloc(slen);
+    strncpy(sstr, &str[s_off], slen);
+    int ret = tre_match(tnfa, sstr, slen, type, nmatch, pmatch, eflags);
+    if (!(eflags & REG_NOSUB))
+    {
+      for (unsigned i = 0; i < nmatch; i++)
+      {
+	pmatch[i].rm_so += slen;
+        pmatch[i].rm_eo += slen;
+      }
+    }
+    return ret;
+  }
+  else
+  {
+    return tre_match(tnfa, str, len, type, nmatch, pmatch, eflags);
+  }
 }
 
 int

Modified: user/gabor/tre-integration/include/tre.h
==============================================================================
--- user/gabor/tre-integration/include/tre.h	Tue May 10 21:18:45 2011	(r221750)
+++ user/gabor/tre-integration/include/tre.h	Wed May 11 00:46:22 2011	(r221751)
@@ -64,6 +64,7 @@ typedef enum {
 /* POSIX tre_regexec() flags. */
 #define REG_NOTBOL 1
 #define REG_NOTEOL (REG_NOTBOL << 1)
+#define REG_STARTEND (REG_NOTEOL << 1)
 
 /* Extra tre_regexec() flags. */
 #define REG_APPROX_MATCHER	 (REG_NOTEOL << 1)



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