From owner-svn-src-user@FreeBSD.ORG Thu Feb 16 14:54:51 2012 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 DD696106566B; Thu, 16 Feb 2012 14:54:51 +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 AE11F8FC18; Thu, 16 Feb 2012 14:54:51 +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 q1GEsp2M021581; Thu, 16 Feb 2012 14:54:51 GMT (envelope-from gabor@svn.freebsd.org) Received: (from gabor@localhost) by svn.freebsd.org (8.14.4/8.14.4/Submit) id q1GEspfa021579; Thu, 16 Feb 2012 14:54:51 GMT (envelope-from gabor@svn.freebsd.org) Message-Id: <201202161454.q1GEspfa021579@svn.freebsd.org> From: Gabor Kovesdan Date: Thu, 16 Feb 2012 14:54:51 +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: r231825 - 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: Thu, 16 Feb 2012 14:54:51 -0000 Author: gabor Date: Thu Feb 16 14:54:51 2012 New Revision: 231825 URL: http://svn.freebsd.org/changeset/base/231825 Log: - Implement compilation of multiple patterns for heuristic matching Modified: user/gabor/tre-integration/contrib/tre/lib/mregcomp.c Modified: user/gabor/tre-integration/contrib/tre/lib/mregcomp.c ============================================================================== --- user/gabor/tre-integration/contrib/tre/lib/mregcomp.c Thu Feb 16 14:54:20 2012 (r231824) +++ user/gabor/tre-integration/contrib/tre/lib/mregcomp.c Thu Feb 16 14:54:51 2012 (r231825) @@ -48,19 +48,88 @@ __weak_reference(tre_mregfree, mregfree) /* TODO: * - * - compilation * - REG_ICASE * - Test */ int -tre_mcompile(mregex_t *preg, size_t nr, const char *regex[], - size_t n[], int cflags) +tre_mcompile(mregex_t *preg, size_t nr, const tre_char_t *wregex[], + size_t wn[], int cflags) { + int ret; + size_t mfrag = 0; + tre_char_t **frags; + size_t *siz; + wmsearch_t *wm; + + preg->k = nr; + preg->patterns = xmalloc(nr * sizeof(regex_t)); + if (!preg->patterns) + return REG_ESPACE; + + for (int i = 0; i < nr; i++) + { + ret = tre_compile_nfa(&preg->patterns[i], wregex[i], wn[i], cflags); + if (ret != REG_OK) + goto err; + ret = tre_compile_heur(&preg->patterns[i], wregex[i], wn[i], cflags); + if (ret != REG_OK) + goto err; + } + + for (mfrag = 0; mfrag < nr; mfrag++) + for (int j = 0; j < nr; j++) + if (((heur_t)preg->patterns[j]->heur)->arr[mfrag] == NULL) + goto out; +out: + + preg->mfrag = mfrag; + + /* Worst case, not all patterns have a literal prefix */ + if (mfrag == 0) + return REG_OK; + + wm = xmalloc(mfrag * sizeof(wmsearch_t)); + if (!wm) + goto err; + + frags = xmalloc(nr * sizeof(char *)); + if (!frags) + goto err; + + siz = xmalloc(nr * sizeof(size_t)); + // XXX: check NULL - // TODO: Get heuristics and then use Wu-Manber + for (int i = 0; i < mfrag; i++) + { + for (int j = 0; j < nr; j++) + { + frags[j] = &((heur_t)preg->patterns[j]->heur)->arr[i]; + siz[j] = ((heur_t)preg->patterns[j]->heur)->siz[i]; + } + ret = tre_wmcomp(&wm[i], nr, frags, siz, cflags); + if (ret != REG_OK) + goto err; + } + + preg->searchdata = wm; return REG_OK; + +err: + if (preg->patterns) + xfree(preg->patterns); + if (wm) + { + for (int i = 0; i < mfrag; i++) + tre_wmfree(&wm[i]); + xfree(wm); + } + if (frags) + xfree(frags); + if (siz) + xfree(siz); + return ret; } int