1b99bc125d897c0712377c4fb4d23ff9f6cbca9f
angie
  Fri Feb 25 11:43:27 2011 -0800
New src/inc/regexHelper.h module replaces the regex conveniencefunctions that were previously down in hg/lib/hgFindSpecCustom.c.
The primary motivation for this is so I can use regex functions in
the new src/lib/vcf.c for Feature #2821 (VCF parser), but I hope
this will make it easier in general to use regexes in any new code.

diff --git src/hg/checkHgFindSpec/checkHgFindSpec.c src/hg/checkHgFindSpec/checkHgFindSpec.c
index 45ba12c..1ab55d7 100644
--- src/hg/checkHgFindSpec/checkHgFindSpec.c
+++ src/hg/checkHgFindSpec/checkHgFindSpec.c
@@ -1,28 +1,29 @@
 /* checkHgFindSpec - test & describe search specs in hgFindSpec table. */
 #include "common.h"
 #include "options.h"
 #include "jksql.h"
 #include "hash.h"
 #include "dystring.h"
 #include "portable.h"
 #include "hdb.h"
 #include "hui.h"
 #include "cheapcgi.h"
 #include "cart.h"
 #include "hgFind.h"
 #include "hgFindSpec.h"
+#include "regexHelper.h"
 
 static char const rcsid[] = "$Id: checkHgFindSpec.c,v 1.12 2008/09/03 19:18:21 markd Exp $";
 
 char *database = NULL;
 /* Need to get a cart in order to use hgFind. */
 struct cart *cart = NULL;
 
 /* Command line option specifications */
 static struct optionSpec optionSpecs[] = {
     {"showSearches",    OPTION_BOOLEAN},
     {"checkTermRegex",  OPTION_BOOLEAN},
     {"exampleFor",      OPTION_STRING},
     {"checkIndexes",    OPTION_BOOLEAN},
     {"makeExamples",    OPTION_BOOLEAN},
     {NULL, 0}
@@ -67,59 +68,59 @@
 struct hgFindSpec *hfs = NULL;
 struct hgPositions *hgp = NULL;
 int startMs = 0, endMs = 0;
 boolean gotError = FALSE;
 char *chrom = NULL;
 int chromStart = 0, chromEnd = 0;
 
 hgFindSpecGetAllSpecs(database, &shortList, &longList);
 puts("\n");
 startMs = clock1000();
 for (hfs = shortList;  hfs != NULL;  hfs = hfs->next)
     {
     boolean matches = TRUE;
     boolean tablesExist = hTableOrSplitExists(database, hfs->searchTable);
     if (isNotEmpty(termToSearch) && isNotEmpty(hfs->termRegex))
-	matches = matchRegex(termToSearch, hfs->termRegex);
+	matches = regexMatchNoCase(termToSearch, hfs->termRegex);
     if (isNotEmpty(hfs->xrefTable))
 	tablesExist |= hTableExists(database, hfs->xrefTable);
     if (matches && tablesExist)
 	{
 	verbose(1, "SHORT-CIRCUIT %s\n", hfs->searchName);
 	}
     else if (matches)
 	{
 	verbose(1, "no table %s: %s%s%s\n", hfs->searchName, hfs->searchTable,
 		isNotEmpty(hfs->xrefTable) ? " and/or " : "",
 		isNotEmpty(hfs->xrefTable) ? hfs->xrefTable : "");
 	}
     else
 	{
 	verbose(1, "no match %s: %s\n", hfs->searchName, hfs->termRegex);
 	}
     }
 endMs = clock1000();
 printf("\nTook %dms to determine short-circuit searches.\n\n",
        endMs - startMs);
 
 startMs = clock1000();
 for (hfs = longList;  hfs != NULL;  hfs = hfs->next)
     {
     boolean matches = TRUE;
     boolean tablesExist = hTableOrSplitExists(database, hfs->searchTable);
     if (isNotEmpty(termToSearch) && isNotEmpty(hfs->termRegex))
-	matches = matchRegex(termToSearch, hfs->termRegex);
+	matches = regexMatchNoCase(termToSearch, hfs->termRegex);
     if (isNotEmpty(hfs->xrefTable))
 	tablesExist |= hTableExists(database, hfs->xrefTable);
     if (matches && tablesExist)
 	{
 	verbose(1, "ADDITIVE %s\n", hfs->searchName);
 	}
     else if (matches)
 	{
 	verbose(1, "no table %s: %s%s%s\n", hfs->searchName, hfs->searchTable,
 		isNotEmpty(hfs->xrefTable) ? " and/or " : "",
 		isNotEmpty(hfs->xrefTable) ? hfs->xrefTable : "");
 	}
     else
 	{
 	verbose(1, "no match %s: %s\n", hfs->searchName, hfs->termRegex);
@@ -182,33 +183,33 @@
 static boolean checkRegexOnTableField(char *exp, char *altExp, char *table,
 				      char *field, char *searchName)
 /* Return TRUE and complain if any values of table.field do not match exp. */
 {
 struct sqlConnection *conn = hAllocConn(database);
 struct sqlResult *sr = NULL;
 char **row = NULL;
 int errCount = 0;
 char buf[512];
 safef(buf, sizeof(buf), "select %s from %s", field, table);
 sr = sqlGetResult(conn, buf);
 while ((row = sqlNextRow(sr)) != NULL)
     {
     if (isEmpty(row[0]))
 	continue;
-    if (! matchRegex(row[0], exp))
+    if (! regexMatchNoCase(row[0], exp))
 	{
-	if (isNotEmpty(altExp) && matchRegex(row[0], altExp))
+	if (isNotEmpty(altExp) && regexMatchNoCase(row[0], altExp))
 	    continue;
 	if (errCount < 1 ||
 	    (errCount < 10 && verboseLevel() > 1))
 	    {
 	    printf("Error: %s.%s.%s value \"%s\" doesn't match termRegex \"%s\"",
 		   database, table, field, row[0], exp);
 	    if (isNotEmpty(altExp))
 		printf(" or dontCheck \"%s\"", altExp);
 	    printf(" for search %s\n", searchName);
 	    }
 	errCount++;
 	}
     }
 if (errCount > 0)
     verbose(2, "Search %s: %d values of %s.%s overlooked.\n",