709fe2b919636225cb13fb2d95cf177702346bd1
angie
  Wed Apr 25 15:50:25 2012 -0700
Feature #6152 (Variant Annotation Tool): Added region type and positioninputs to UI -- and it actually executes some queries now!

diff --git src/hg/lib/hdb.c src/hg/lib/hdb.c
index fb55bf9..81196bc 100644
--- src/hg/lib/hdb.c
+++ src/hg/lib/hdb.c
@@ -4730,30 +4730,66 @@
     return NULL;
 
 buffer[sizeof(buffer) - 1] = 0;
 if (!hgParseChromRange(NULL, position, &chromName, &winStart, &winEnd))
     strncpy(buffer, position, sizeof(buffer) - 1);
 else
     {
     sprintLongWithCommas(num1Buf, winStart + 1);
     sprintLongWithCommas(num2Buf, winEnd);
     safef(buffer, sizeof(buffer) - 1, "%s:%s-%s",chromName, num1Buf,  num2Buf);
     }
 
 return buffer;
 }
 
+INLINE boolean isAllDigits(char *str)
+/* Return TRUE if every character in str is a digit. */
+{
+char *p = str;
+while (*p != '\0')
+    if (!isdigit(*p++))
+	return FALSE;
+return TRUE;
+}
+
+boolean parsePosition(char *position, char **retChrom, uint *retStart, uint *retEnd)
+/* If position is word:number-number (possibly with commas & whitespace),
+ * set retChrom, retStart (subtracting 1) and retEnd, and return TRUE.
+ * Otherwise return FALSE and leave rets unchanged. */
+{
+char *chrom = cloneString(position);
+stripChar(chrom, ',');
+eraseWhiteSpace(chrom);
+char *startStr = strchr(chrom, ':');
+if (startStr == NULL)
+    return FALSE;
+*startStr++ = '\0';
+char *endStr = strchr(startStr, '-');
+if (endStr == NULL)
+    return FALSE;
+*endStr++ = '\0';
+if (!isAllDigits(startStr))
+    return FALSE;
+if (!isAllDigits(endStr))
+    return FALSE;
+*retChrom = chrom;
+*retStart = sqlUnsigned(startStr) - 1;
+*retEnd = sqlUnsigned(endStr);
+return TRUE;
+}
+
 static struct grp* loadGrps(char *db, char *confName, char *defaultTbl)
 /* load all of the grp rows from a table.  The table name is first looked up
  * in hg.conf with confName. If not there, use defaultTbl.  If the table
  * doesn't exist, return NULL */
 {
 char query[128];
 struct grp *grps = NULL;
 char *tbl = cfgOption(confName);
 struct slName *tables = NULL, *table;
 
 if (tbl == NULL)
     tbl = defaultTbl;
 tables = slNameListFromComma(tbl);
 slReverse(&tables);