/* If the DFA turns out to have some set of fixed strings one of which must occur in the match, then we build a kwset matcher to find those strings, and thus quickly filter out impossible matches. */ static void kwsmusts (struct compiled_regex *cregex, bool match_icase, bool match_words, bool match_lines, char eolbyte) { struct dfamust const *dm; const char *err; if (cregex->dfa.musts) { kwsinit (&cregex->ckwset, match_icase, match_words, match_lines, eolbyte); /* First, we compile in the substrings known to be exact matches. The kwset matcher will return the index of the matching string that it chooses. */ for (dm = cregex->dfa.musts; dm; dm = dm->next) { if (!dm->exact) continue; cregex->kwset_exact_matches++; if ((err = kwsincr (cregex->ckwset.kwset, dm->must, strlen (dm->must))) != NULL) error (exit_failure, 0, err); } /* Now, we compile the substrings that will require the use of the regexp matcher. */ for (dm = cregex->dfa.musts; dm; dm = dm->next) { if (dm->exact) continue; if ((err = kwsincr (cregex->ckwset.kwset, dm->must, strlen (dm->must))) != NULL) error (exit_failure, 0, err); } if ((err = kwsprep (cregex->ckwset.kwset)) != NULL) error (exit_failure, 0, err); } }
/* If the DFA turns out to have some set of fixed strings one of which must occur in the match, then we build a kwset matcher to find those strings, and thus quickly filter out impossible matches. */ static void kwsmusts (void) { struct dfamust const *dm; char const *err; dm = dfamusts (dfa); if (dm) { kwsinit (&kwset); /* First, we compile in the substrings known to be exact matches. The kwset matcher will return the index of the matching string that it chooses. */ for (; dm; dm = dm->next) { if (!dm->exact) continue; ++kwset_exact_matches; if ((err = kwsincr_case (dm->must)) != NULL) error (EXIT_TROUBLE, 0, "%s", err); } /* Now, we compile the substrings that will require the use of the regexp matcher. */ for (dm = dfamusts (dfa); dm; dm = dm->next) { if (dm->exact) continue; if ((err = kwsincr_case (dm->must)) != NULL) error (EXIT_TROUBLE, 0, "%s", err); } if ((err = kwsprep (kwset)) != NULL) error (EXIT_TROUBLE, 0, "%s", err); } }
static void * Fcompile (const char *pattern, size_t pattern_size, bool match_icase, bool match_words, bool match_lines, char eolbyte) { struct compiled_kwset *ckwset; const char *beg, *lim, *err; ckwset = XMALLOC (struct compiled_kwset); kwsinit (ckwset, match_icase, match_words, match_lines, eolbyte); beg = pattern; do { for (lim = beg; lim < pattern + pattern_size && *lim != '\n'; ++lim) ; if ((err = kwsincr (ckwset->kwset, beg, lim - beg)) != NULL) error (exit_failure, 0, err); if (lim < pattern + pattern_size) ++lim; beg = lim; } while (beg < pattern + pattern_size); if ((err = kwsprep (ckwset->kwset)) != NULL) error (exit_failure, 0, err); return ckwset; }