From owner-svn-src-user@FreeBSD.ORG Fri Sep 16 22:38:57 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 D2EAB1065674; Fri, 16 Sep 2011 22:38:57 +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 B7A618FC13; Fri, 16 Sep 2011 22:38:57 +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 p8GMcv7i041478; Fri, 16 Sep 2011 22:38:57 GMT (envelope-from gabor@svn.freebsd.org) Received: (from gabor@localhost) by svn.freebsd.org (8.14.4/8.14.4/Submit) id p8GMcvi6041474; Fri, 16 Sep 2011 22:38:57 GMT (envelope-from gabor@svn.freebsd.org) Message-Id: <201109162238.p8GMcvi6041474@svn.freebsd.org> From: Gabor Kovesdan Date: Fri, 16 Sep 2011 22:38:57 +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: r225631 - 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, 16 Sep 2011 22:38:57 -0000 Author: gabor Date: Fri Sep 16 22:38:57 2011 New Revision: 225631 URL: http://svn.freebsd.org/changeset/base/225631 Log: - Factor out duplicated macro into a common header file Modified: user/gabor/tre-integration/contrib/tre/lib/fastmatch.c user/gabor/tre-integration/contrib/tre/lib/regexec.c user/gabor/tre-integration/contrib/tre/lib/tre-internal.h Modified: user/gabor/tre-integration/contrib/tre/lib/fastmatch.c ============================================================================== --- user/gabor/tre-integration/contrib/tre/lib/fastmatch.c Fri Sep 16 19:53:56 2011 (r225630) +++ user/gabor/tre-integration/contrib/tre/lib/fastmatch.c Fri Sep 16 22:38:57 2011 (r225631) @@ -127,28 +127,6 @@ tre_fastfree(fastmatch_t *preg) tre_free_fast(preg); } -/* XXX: avoid duplication */ -#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_fast(preg, &string[offset], slen, type, nmatch, \ - pmatch, eflags); \ - 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_fastnexec(const fastmatch_t *preg, const char *string, size_t len, size_t nmatch, regmatch_t pmatch[], int eflags) @@ -156,7 +134,8 @@ tre_fastnexec(const fastmatch_t *preg, c tre_str_type_t type = (TRE_MB_CUR_MAX == 1) ? STR_BYTE : STR_MBS; if (eflags & REG_STARTEND) - ADJUST_OFFSETS + CALL_WITH_OFFSET(tre_match_fast(preg, &string[offset], slen, + type, nmatch, pmatch, eflags)); else return tre_match_fast(preg, string, len, type, nmatch, pmatch, eflags); @@ -176,7 +155,8 @@ tre_fastwnexec(const fastmatch_t *preg, tre_str_type_t type = STR_WIDE; if (eflags & REG_STARTEND) - ADJUST_OFFSETS + CALL_WITH_OFFSET(tre_match_fast(preg, &string[offset], slen, + type, nmatch, pmatch, eflags)); else return tre_match_fast(preg, string, len, type, nmatch, pmatch, eflags); Modified: user/gabor/tre-integration/contrib/tre/lib/regexec.c ============================================================================== --- user/gabor/tre-integration/contrib/tre/lib/regexec.c Fri Sep 16 19:53:56 2011 (r225630) +++ user/gabor/tre-integration/contrib/tre/lib/regexec.c Fri Sep 16 22:38:57 2011 (r225631) @@ -303,27 +303,6 @@ 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, preg->heur); \ - 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) @@ -332,7 +311,8 @@ 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) - ADJUST_OFFSETS + CALL_WITH_OFFSET(tre_match(tnfa, &str[offset], slen, type, nmatch, + pmatch, eflags, preg->shortcut, preg->heur)); else return tre_match(tnfa, str, len, type, nmatch, pmatch, eflags, preg->shortcut, preg->heur); @@ -356,7 +336,8 @@ tre_regwnexec(const regex_t *preg, const tre_str_type_t type = STR_WIDE; if (eflags & REG_STARTEND) - ADJUST_OFFSETS + CALL_WITH_OFFSET(tre_match(tnfa, &str[offset], slen, type, nmatch, + pmatch, eflags, preg->shortcut, preg->heur)); else return tre_match(tnfa, str, len, STR_WIDE, nmatch, pmatch, eflags, preg->shortcut, preg->heur); Modified: user/gabor/tre-integration/contrib/tre/lib/tre-internal.h ============================================================================== --- user/gabor/tre-integration/contrib/tre/lib/tre-internal.h Fri Sep 16 19:53:56 2011 (r225630) +++ user/gabor/tre-integration/contrib/tre/lib/tre-internal.h Fri Sep 16 22:38:57 2011 (r225631) @@ -256,6 +256,26 @@ struct tnfa { int params_depth; }; +#define CALL_WITH_OFFSET(fn) \ + do \ + { \ + 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 = fn; \ + for (unsigned i = 0; (!(eflags & REG_NOSUB) && (i < nmatch)); i++)\ + { \ + pmatch[i].rm_so += offset; \ + pmatch[i].rm_eo += offset; \ + } \ + return ret; \ + } while (0 /*CONSTCOND*/) + int tre_convert_pattern(const char *regex, size_t n, tre_char_t **w, size_t *wn);