3c7eac91d29c927409064b2e668e8aeeeb8e841c
tdreszer
  Thu Jun 12 17:04:47 2014 -0700
Extended URL trackDb setting to new tokens for item start and stop.  Currently coded to use 1 bases coordinates for both start and stop.  Redmine #13218
diff --git src/hg/hgc/hgc.c src/hg/hgc/hgc.c
index 692f920..4df31f6 100644
--- src/hg/hgc/hgc.c
+++ src/hg/hgc/hgc.c
@@ -944,31 +944,31 @@
     char query[1024];
     sqlSafef(query, sizeof(query), sql, itemName);
     struct sqlConnection *conn = hAllocConn(database);
     id = sqlQuickString(conn, query);
     hFreeConn(&conn);
     }
 return id;
 }
 
 char* replaceInUrl(struct trackDb *tdb, char *url, char *idInUrl, boolean encode) 
 /* replace $$ in url with idInUrl. Supports many other wildchards */
 {
 struct dyString *uUrl = NULL;
 struct dyString *eUrl = NULL;
 char startString[64], endString[64];
-char *ins[9], *outs[9];
+char *ins[11], *outs[11];
 char *eItem = (encode ? cgiEncode(idInUrl) : cloneString(idInUrl));
 
 safef(startString, sizeof startString, "%d", winStart);
 safef(endString, sizeof endString, "%d", winEnd);
 ins[0] = "$$";
 outs[0] = idInUrl;
 ins[1] = "$T";
 outs[1] = tdb->track;
 ins[2] = "$S";
 outs[2] = seqName;
 ins[3] = "$[";
 outs[3] = startString;
 ins[4] = "$]";
 outs[4] = endString;
 ins[5] = "$s";
@@ -981,30 +981,50 @@
     char *itemClone = cloneString(idInUrl);
     char *suffix = stringIn(":", itemClone);
     char *suffixClone = cloneString(suffix+1); /* +1 skip the : */
     char *nextColon = stringIn(":", suffixClone+1);
     if (nextColon)	/* terminate suffixClone suffix */
         *nextColon = '\0';	/* when next colon is present */
     *suffix = '\0';   /* terminate itemClone prefix */
     outs[7] = itemClone;
     outs[8] = suffixClone;
     /* small memory leak here for these cloned strings */
     /* not important for a one-time operation in a CGI that will exit */
 } else {
     outs[7] = idInUrl;	/* otherwise, these are not expected */
     outs[8] = idInUrl;	/* to be used */
 }
+
+// URL may now contain item boundaries
+ins[9] = "${";
+ins[10] = "$}";
+if (cartOptionalString(cart, "o") && cartOptionalString(cart, "t"))
+    {
+    int itemBeg = cartIntExp(cart, "o") + 1; // Should strip any unexpected commas
+    int itemEnd = cartIntExp(cart, "t");
+    char begItem[64], endItem[64];
+    safef(begItem, sizeof begItem, "%d", itemBeg);
+    safef(endItem, sizeof endItem, "%d", itemEnd);
+    outs[9] = begItem;
+    outs[10] = endItem;
+    }
+else // should never be but I am unwilling to bet the farm
+    {
+    outs[9] = startString;
+    outs[10] = endString;
+    }
+
 uUrl = subMulti(url, ArraySize(ins), ins, outs);
 outs[0] = eItem;
 eUrl = subMulti(url, ArraySize(ins), ins, outs);
 freeDyString(&uUrl);
 freeMem(eItem);
 return eUrl->string;
 }
 
 char* constructUrl(struct trackDb *tdb, char *urlSetting, char *idInUrl, boolean encode) 
 {
 /* construct the url by replacing $$, etc in the url given by urlSetting.
  * Replace $$ with itemName.  */
 
 // check the url setting prefix and get the correct url setting from trackDb 
 char *url;