Date: Thu, 16 Feb 2012 14:54:51 +0000 (UTC) From: Gabor Kovesdan <gabor@FreeBSD.org> To: src-committers@freebsd.org, svn-src-user@freebsd.org Subject: svn commit: r231825 - user/gabor/tre-integration/contrib/tre/lib Message-ID: <201202161454.q1GEspfa021579@svn.freebsd.org>
next in thread | raw e-mail | index | archive | help
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
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201202161454.q1GEspfa021579>