From owner-svn-src-user@FreeBSD.ORG Mon Aug 15 18:03:36 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 6766B1065673; Mon, 15 Aug 2011 18:03:36 +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 4CF198FC13; Mon, 15 Aug 2011 18:03:36 +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 p7FI3aJj020947; Mon, 15 Aug 2011 18:03:36 GMT (envelope-from gabor@svn.freebsd.org) Received: (from gabor@localhost) by svn.freebsd.org (8.14.4/8.14.4/Submit) id p7FI3aRi020944; Mon, 15 Aug 2011 18:03:36 GMT (envelope-from gabor@svn.freebsd.org) Message-Id: <201108151803.p7FI3aRi020944@svn.freebsd.org> From: Gabor Kovesdan Date: Mon, 15 Aug 2011 18:03:36 +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: r224894 - 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, 15 Aug 2011 18:03:36 -0000 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;