875fe9f717d3e839f49acdef7bee2a6ea53f9f5b
kent
  Fri Apr 5 02:23:01 2013 -0700
Adding cgiParsedVars - something that makes it easier to use the cgi var parser.
diff --git src/lib/cheapcgi.c src/lib/cheapcgi.c
index cdf4635..f91eaf7 100644
--- src/lib/cheapcgi.c
+++ src/lib/cheapcgi.c
@@ -2128,15 +2128,49 @@
 
 void cgiDown(float lines)
 // Drop down a certain number of lines (may be fractional)
 {
 printf("<div style='height:%fem;'></div>\n",lines);
 }
 
 char *commonCssStyles()
 /* Returns a string of common CSS styles */
 {
 // Contents currently is OBSOLETE as these have been moved to HGStyle.css
 // TODO: remove all traces (from web.c, hgTracks, hgTables) as this funtion does nothing.
 return "";
 }
 
+static void turnCgiVarsToVals(struct hashEl *hel)
+/* To save cgiParseVars clients from doing an extra lookup, replace
+ * hash filled with cgiVars as values with one filled with cgiVar->val
+ * instead.  Since cgiVar->name is same as hashEl->name,  no info is really
+ * lost, and it simplifies the code that uses us. */
+{
+struct cgiVar *var = hel->val;
+hel->val = var->val;
+}
+
+struct cgiParsedVars *cgiParsedVarsNew(char *cgiString)
+/* Build structure containing parsed out cgiString */
+{
+struct cgiParsedVars *tags;
+AllocVar(tags);
+tags->stringBuf = cloneString(cgiString);
+cgiParseInputAbort(tags->stringBuf, &tags->hash, &tags->list);
+hashTraverseEls(tags->hash, turnCgiVarsToVals);
+return tags;
+}
+
+void cgiParsedVarsFree(struct cgiParsedVars **pTags)
+/* Free up memory associated with cgiParsedVars */
+{
+struct cgiParsedVars *tags = *pTags;
+if (tags != NULL)
+    {
+    slFreeList(&tags->list);
+    hashFree(&tags->hash);
+    freeMem(tags->stringBuf);
+    freez(pTags);
+    }
+}
+