// CRM114 Regex redirection bounce package this file bounces // CRM114 regex requests to whichever regex package has been // compiled and linked in to CRM114. // // Adding a new regex package is relatively easy- just mimic the // ifdef stanzas below to map the functions // // crm_regcomp // crm_regexec // crm_regerror // crm_regfree // crm_regversion // // into whatever calls your preferred regex package uses. // #include "crm114_sysincludes.h" // // include any local crm114 configuration file #include "crm114_config.h" // include the crm114 data structures file #include "crm114_structs.h" // and include the routine declarations file #include "crm114.h" // // How to do a register compilation // int crm_regcomp (regex_t *preg, char *regex, long regex_len, int cflags) { // compile it with the TRE regex compiler // // bug workaround - many regex compilers don't compile the null // regex correctly, but _do_ compile "()" correctly, which // matches the same thing). if (regex_len == 0) { return (regncomp (preg, "()", 2, cflags)); } return ( regncomp (preg, regex, regex_len, cflags)); } // // // How to do a regex execution from the compiled register // int crm_regexec ( regex_t *preg, char *string, long string_len, size_t nmatch, regmatch_t pmatch[], int eflags, char *aux_string) { if (!string) { nonfatalerror("crm_regexec - Regular Expression Problem:\n", "NULL pointer to the string to match ."); return (REG_NOMATCH); }; if (aux_string == NULL || strlen (aux_string) < 1) { return (regnexec (preg, string, string_len, nmatch, pmatch, eflags)); } else { int i; // parse out the aux string for approximation parameters regamatch_t mblock; regaparams_t pblock; mblock.nmatch = nmatch; mblock.pmatch = pmatch; sscanf (aux_string, "%d %d %d %d", &pblock.cost_subst, &pblock.cost_ins, &pblock.max_cost, &pblock.cost_del); if (user_trace) fprintf (stderr, "Using approximate match. Costs: Subst %d Ins %d Max %d Del %d \n", pblock.cost_subst, pblock.cost_ins, pblock.max_cost, pblock.cost_del); // now we can run the actual match i = reganexec (preg, string, string_len, &mblock, pblock, eflags); if (user_trace) fprintf (stderr, "approximate Regex match returned %d .\n", i); return (i); }; } size_t crm_regerror (int errorcode, regex_t *preg, char *errbuf, size_t errbuf_size) { return (regerror (errorcode, preg, errbuf, errbuf_size)); } void crm_regfree (regex_t *preg) { return (regfree (preg)); }; char * crm_regversion () { static char vs[129]; strcat (vs, "TRE "); strcat (vs, tre_version ()); return (vs); };