From owner-svn-src-user@FreeBSD.ORG Fri Dec 23 12:05:52 2011 Return-Path: Delivered-To: svn-src-user@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 69D05106566C; Fri, 23 Dec 2011 12:05:52 +0000 (UTC) (envelope-from gabor@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 49FB28FC13; Fri, 23 Dec 2011 12:05:52 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.4/8.14.4) with ESMTP id pBNC5qxt064853; Fri, 23 Dec 2011 12:05:52 GMT (envelope-from gabor@svn.freebsd.org) Received: (from gabor@localhost) by svn.freebsd.org (8.14.4/8.14.4/Submit) id pBNC5qmv064849; Fri, 23 Dec 2011 12:05:52 GMT (envelope-from gabor@svn.freebsd.org) Message-Id: <201112231205.pBNC5qmv064849@svn.freebsd.org> From: Gabor Kovesdan Date: Fri, 23 Dec 2011 12:05:52 +0000 (UTC) To: src-committers@freebsd.org, svn-src-user@freebsd.org X-SVN-Group: user MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r228839 - user/gabor/tre-integration/contrib/tre/lib X-BeenThere: svn-src-user@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the experimental " user" src tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 23 Dec 2011 12:05:52 -0000 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)