Index: /trunk/psLib/src/db/psDB.c
===================================================================
--- /trunk/psLib/src/db/psDB.c	(revision 14126)
+++ /trunk/psLib/src/db/psDB.c	(revision 14127)
@@ -12,6 +12,6 @@
  *  @author Joshua Hoblitt
  *
- *  @version $Revision: 1.142 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2007-04-18 19:37:31 $
+ *  @version $Revision: 1.143 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2007-07-11 02:03:30 $
  *
  *  Copyright (C) 2005-2006  Joshua Hoblitt, University of Hawaii
@@ -1587,4 +1587,58 @@
     // Reset iterator to head of list
     psListIteratorSet(cursor, 0);
+    // look for INDEX values
+    while ((item = psListGetAndIncrement(cursor))) {
+        // don't compile a regex unless we have too
+        if (psStrcasestr(item->comment, "INDEX") == NULL) {
+            continue;
+        }
+
+        regex_t         myregex;
+        regmatch_t      mymatch[2];     // match + 1 sub strings
+        int             errbuf_size = 1024;
+        char            errbuf[errbuf_size];
+        char            *pattern = "INDEX[:space:]*[(]([^)]*)";
+
+        int status = regcomp(&myregex, pattern, REG_EXTENDED|REG_ICASE);
+        if (status != 0) {
+            regerror(status, &myregex, errbuf, errbuf_size);
+            psError(PS_ERR_UNKNOWN, true, "regcomp() failed: %s", errbuf);
+            psFree(query);
+            psFree(cursor);
+            return NULL;
+        }
+        
+        psTrace("psLib.db", 10, "trying regex pattern: %s against string: %s", pattern, item->comment);
+        status = regexec(&myregex, item->comment, 2, mymatch, 0);
+        if (status != 0) {
+            regerror(status, &myregex, errbuf, errbuf_size);
+            psError(PS_ERR_UNKNOWN, true, "regexec() failed: %s", errbuf);
+            psFree(query);
+            psFree(cursor);
+            return NULL;
+        }
+        
+        regfree(&myregex);
+
+        // sub string 1: index(.*)
+        size_t matchStart = (size_t)mymatch[1].rm_so;
+        size_t matchEnd   = (size_t)mymatch[1].rm_eo;
+        size_t matchLength = matchEnd - matchStart;
+
+        if (matchStart == -1) {
+            psError(PS_ERR_UNKNOWN, true, "substring 1 failed to match");
+            psFree(query);
+            psFree(cursor);
+            return NULL;
+        }
+
+        psString index = psStringNCopy(item->comment + matchStart, matchLength);
+        psTrace("psLib.db", 10, "regex $1 matched: %s", index);
+        psStringAppend(&query, ", INDEX(%s)", index);
+        psFree(index);
+    }
+
+    // Reset iterator to head of list
+    psListIteratorSet(cursor, 0);
     // look for foreign keys after all other key types
     while ((item = psListGetAndIncrement(cursor))) {
