From owner-svn-src-user@FreeBSD.ORG Mon Aug 22 20:25:55 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 81420106564A; Mon, 22 Aug 2011 20:25:55 +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 7140B8FC0A; Mon, 22 Aug 2011 20:25:55 +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 p7MKPtkQ067133; Mon, 22 Aug 2011 20:25:55 GMT (envelope-from gabor@svn.freebsd.org) Received: (from gabor@localhost) by svn.freebsd.org (8.14.4/8.14.4/Submit) id p7MKPt57067131; Mon, 22 Aug 2011 20:25:55 GMT (envelope-from gabor@svn.freebsd.org) Message-Id: <201108222025.p7MKPt57067131@svn.freebsd.org> From: Gabor Kovesdan Date: Mon, 22 Aug 2011 20:25:55 +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: r225087 - 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: Mon, 22 Aug 2011 20:25:55 -0000 Author: gabor Date: Mon Aug 22 20:25:55 2011 New Revision: 225087 URL: http://svn.freebsd.org/changeset/base/225087 Log: - Partly fix offset handling Modified: user/gabor/tre-integration/contrib/tre/lib/regexec.c Modified: user/gabor/tre-integration/contrib/tre/lib/regexec.c ============================================================================== --- user/gabor/tre-integration/contrib/tre/lib/regexec.c Mon Aug 22 19:46:25 2011 (r225086) +++ user/gabor/tre-integration/contrib/tre/lib/regexec.c Mon Aug 22 20:25:55 2011 (r225087) @@ -162,42 +162,76 @@ tre_match(const tre_tnfa_t *tnfa, const return tre_match_fast(shortcut, string, len, type, nmatch, pmatch, eflags); +#define FIX_OFFSETS \ + if (ret == REG_NOMATCH) \ + { \ + st += n; \ + continue; \ + } \ + else if ((ret == REG_OK) && !(tnfa->cflags & REG_NOSUB)) \ + for (int i = 0; i < nmatch; i++) \ + { \ + pmatch[i].rm_so += st; \ + pmatch[i].rm_eo += st; \ + } \ + return ret; + +#define SEEK_TO(off) \ + string = (type == STR_WIDE) ? (void *)&data_wide[off] : \ + (void *)&data_byte[off]; + /* Check if we have a heuristic to speed up the search. */ if (heur != NULL) { int ret; - size_t st = 0, j; + size_t st = 0, n; const char *data_byte = string; const tre_char_t *data_wide = string; - const void *tmp; - /* Look for the beginning of possibly matching text. */ - ret = tre_match_fast(heur->start, string, len, type, nmatch, - pmatch, eflags); - if (ret != REG_OK) - return ret; - st = pmatch[0].rm_so; - j = pmatch[0].rm_eo; - string = (type == STR_WIDE) ? (void *)&data_wide[st] : - (void *)&data_byte[st]; - - /* When having a fixed-length pattern there is only one heuristic. */ - if (heur->end == NULL) - return tre_match(tnfa, string, - heur->prefix ? (len - st) : (j - st), - type, nmatch, pmatch, eflags, NULL, NULL); - - tmp = (type == STR_WIDE) ? (void *)&data_wide[j] : - (void *)&data_byte[j]; - - /* Look for the end of possibly matching text. */ - ret = tre_match_fast(heur->end, tmp, len - j, type, nmatch, - pmatch, eflags); - if (ret != REG_OK) - return ret; + while (st < len) + { + SEEK_TO(st); - return tre_match(tnfa, string, pmatch[0].rm_eo + j - st, - type, nmatch, pmatch, eflags, NULL, NULL); + /* Look for the beginning of possibly matching text. */ + ret = tre_match_fast(heur->start, string, len - st, type, nmatch, + pmatch, eflags); + if (ret != REG_OK) + return ret; + st += pmatch[0].rm_so; + n = pmatch[0].rm_eo; + + /* + * When having a fixed-length pattern there is only + * one heuristic. + */ + if (heur->end == NULL) + { + SEEK_TO(st); + + ret = tre_match(tnfa, string, + heur->prefix ? (len - st) : + n, type, nmatch, + pmatch, eflags, NULL, NULL); + + FIX_OFFSETS; + } + + SEEK_TO(st + n); + + /* Look for the end of possibly matching text. */ + ret = tre_match_fast(heur->end, string, len - st - n, type, + nmatch, pmatch, eflags); + + if (ret != REG_OK) + return ret; + + SEEK_TO(st); + + ret = tre_match(tnfa, string, pmatch[0].rm_eo + n, + type, nmatch, pmatch, eflags, NULL, NULL); + + FIX_OFFSETS; + } } if (tnfa->num_tags > 0 && nmatch > 0)