svn commit: r228839 - user/gabor/tre-integration/contrib/tre/lib
Gabor Kovesdan
gabor at FreeBSD.org
Fri Dec 23 12:05:52 UTC 2011
Author: gabor
Date: Fri Dec 23 12:05:51 2011
New Revision: 228839
URL: http://svn.freebsd.org/changeset/base/228839
Log:
- Some trivial fixes
- Add more comments
Modified:
user/gabor/tre-integration/contrib/tre/lib/regexec.c
user/gabor/tre-integration/contrib/tre/lib/tre-fastmatch.c
user/gabor/tre-integration/contrib/tre/lib/tre-heuristic.c
Modified: user/gabor/tre-integration/contrib/tre/lib/regexec.c
==============================================================================
--- user/gabor/tre-integration/contrib/tre/lib/regexec.c Fri Dec 23 09:09:42 2011 (r228838)
+++ user/gabor/tre-integration/contrib/tre/lib/regexec.c Fri Dec 23 12:05:51 2011 (r228839)
@@ -250,9 +250,9 @@ tre_match(const tre_tnfa_t *tnfa, const
n = pmatch[0].rm_eo;
/* Intermediate heuristics */
- while (!((heur->heurs[i] == NULL) ||
- ((heur->type == HEUR_PREFIX_ARRAY) &&
- heur->heurs[i + 1] == NULL)))
+ while (!(heur->heurs[i] == NULL) &&
+ ((heur->heurs[i + 1] != NULL) ||
+ ((heur->heurs[i + 1] == NULL) && (heur->type == HEUR_PREFIX_ARRAY))))
{
SEEK_TO(st + n);
ret = tre_match_fast(heur->heurs[i], string, len - st - n,
@@ -283,7 +283,7 @@ tre_match(const tre_tnfa_t *tnfa, const
{
size_t l = (heur->tlen == -1) ? len - st : heur->tlen;
- if (l < len - st)
+ if (l > len - st)
return REG_NOMATCH;
SEEK_TO(st);
ret = tre_match(tnfa, string, l, type, nmatch,
Modified: user/gabor/tre-integration/contrib/tre/lib/tre-fastmatch.c
==============================================================================
--- user/gabor/tre-integration/contrib/tre/lib/tre-fastmatch.c Fri Dec 23 09:09:42 2011 (r228838)
+++ user/gabor/tre-integration/contrib/tre/lib/tre-fastmatch.c Fri Dec 23 12:05:51 2011 (r228839)
@@ -542,10 +542,8 @@ tre_compile_fast(fastmatch_t *fg, const
case TRE_CHAR('{'):
if (!(cflags & REG_EXTENDED) ^ escaped)
STORE_CHAR;
- else if (!(cflags & REG_EXTENDED) && (i == 0))
+ else if (i == 0)
STORE_CHAR;
- else if ((cflags & REG_EXTENDED) && (i == 0))
- continue;
else
goto badpat;
continue;
Modified: user/gabor/tre-integration/contrib/tre/lib/tre-heuristic.c
==============================================================================
--- user/gabor/tre-integration/contrib/tre/lib/tre-heuristic.c Fri Dec 23 09:09:42 2011 (r228838)
+++ user/gabor/tre-integration/contrib/tre/lib/tre-heuristic.c Fri Dec 23 12:05:51 2011 (r228839)
@@ -179,10 +179,8 @@ tre_compile_heur(heur_t *h, const tre_ch
case TRE_CHAR('{'):
if (escaped && (i == 1))
STORE_CHAR;
- else if ((i == 0) && !(cflags & REG_EXTENDED))
+ else if (i == 0)
STORE_CHAR;
- else if ((i == 0) && (cflags & REG_EXTENDED))
- continue;
PARSE_UNIT('{', '}');
if (escaped ^ (cflags & REG_EXTENDED))
@@ -332,12 +330,14 @@ end_segment:
else if (pos == 0)
continue;
+ /* Too many fragments - should never happen but to be safe */
if (j == MAX_FRAGMENTS)
{
errcode = REG_BADPAT;
goto err;
}
+ /* Alloc space for fragment and copy it */
arr[j] = xmalloc((pos + 1) * sizeof(tre_char_t));
if (!arr[j])
{
@@ -358,9 +358,16 @@ ok:
h->tlen = tlen;
+ /* Look up maximum length fragment */
for (int i = 1; i < j; i++)
m = (length[i] > length[m]) ? i : m;
+ /*
+ * If possible, store prefix, maximum internal fragment and suffix.
+ * If not possible, store prefix and either maximum internal fragment
+ * or suffix if it is the same. In the worst case, only prefix is
+ * stored. The closing element is always NULL.
+ */
for (int i = 0; i < MIN(3, j + 1); i++)
{
h->heurs[i] = xmalloc(sizeof(fastmatch_t));
@@ -380,12 +387,19 @@ ok:
if (cflags & REG_NEWLINE)
{
+ /* For REG_NEWLINE, only store longest fragment. */
ret = tre_compile_literal(h->heurs[0], arr[m], length[m], 0);
CHECK_ERR
h->type = HEUR_LONGEST;
}
else
{
+ /*
+ * If possible, store prefix, maximum internal fragment and suffix.
+ * If not possible, store prefix and either maximum internal fragment
+ * or suffix if it is the same. In the worst case, only prefix is
+ * stored. The closing element is always NULL.
+ */
ret = tre_compile_literal(h->heurs[0], arr[0], length[0], 0);
CHECK_ERR
if (j == 1)
More information about the svn-src-user
mailing list