8715d83d38d8bb18adfdd9ce05771b4cede85407
angie
  Fri Dec 5 09:52:07 2014 -0800
Moved some hgTables code that had been copied into a couple differentplaces into a new lib module, cartTrackDb.  hgGenome/import.c has code
that is fairly similar but that also needs to filter out custom tracks
that were generated by hgGenome.

diff --git src/hg/hgVai/libifyMe.c src/hg/hgVai/libifyMe.c
index 8baf084..8db79a6 100644
--- src/hg/hgVai/libifyMe.c
+++ src/hg/hgVai/libifyMe.c
@@ -68,222 +68,30 @@
 if (range[0] != 0)
     isSingle = searchPosition(range, cart, cartVar);
 else
     cartSetString(cart, cartVar, hDefaultPos(db));
 return isSingle;
 }
 
 void nbSpaces(int count)
 /* Print some non-breaking spaces. */
 {
 int i;
 for (i=0; i<count; ++i)
     printf("&nbsp;");
 }
 
-//#*** --------------------- almost verbatim from hgTables/custom.c (+ globals) -------------------------
-static struct customTrack *getCustomTracks(char *database, struct cart *cart)
-/* Get custom track list. */
-{
-static struct slName *browserLines = NULL;
-static struct customTrack *theCtList = NULL;
-if (theCtList == NULL)
-    theCtList = customTracksParseCart(database, cart, &browserLines, NULL);
-return theCtList;
-}
-//#*** --------------------- end verbatim from hgTables/custom.c -------------------------
-
-boolean hasCustomTracks(struct cart *cart)
-/* Return TRUE if cart has custom tracks for the current db. */
-{
-char *db = cartString(cart, "db");
-struct customTrack *ctList = getCustomTracks(db, cart);
-return (ctList != NULL);
-}
-
-//#*** libify to hg/lib/wikiTrack.c
-//#*** should it sort trackDb, or leave that to the caller?
-void wikiTrackDb(struct trackDb **list)
-/* create a trackDb entry for the wiki track */
-{
-struct trackDb *tdb;
-
-AllocVar(tdb);
-tdb->track = WIKI_TRACK_TABLE;
-tdb->table = WIKI_TRACK_TABLE;
-tdb->shortLabel = WIKI_TRACK_LABEL;
-tdb->longLabel = WIKI_TRACK_LONGLABEL;
-tdb->visibility = tvFull;
-tdb->priority = WIKI_TRACK_PRIORITY;
-
-tdb->html = hFileContentsOrWarning(hHelpFile(tdb->track));
-tdb->type = "none";
-tdb->grp = "map";
-tdb->canPack = FALSE;
-
-slAddHead(list, tdb);
-slSort(list, trackDbCmp);
-}
-
-static struct trackDb *getFullTrackList(struct cart *cart, struct hubConnectStatus *hubList,
-					struct grp **pHubGroups)
-/* Get all tracks including custom tracks if any. *pHubGroups is reversed. */
-{
-char *db = cartString(cart, "db");
-struct trackDb *list = hTrackDb(db);
-struct customTrack *ctList, *ct;
-
-/* exclude any track with a 'tableBrowser off' setting */
-//#*** NOTE: this only scans top-level tdb's, and would miss a setting applied
-//#*** only to lower levels.  So far we have not encountered such a track.
-struct trackDb *tdb, *nextTdb, *newList = NULL;
-for (tdb = list;  tdb != NULL;  tdb = nextTdb)
-    {
-    nextTdb = tdb->next;
-    if (tdbIsDownloadsOnly(tdb) || tdb->table == NULL)
-        {
-        //freeMem(tdb);  // should not free tdb's.
-        // While hdb.c should and says it does cache the tdbList, it doesn't.
-        // The most notable reason that the tdbs are not cached is this hgTables CGI !!!
-        // It needs to be rewritten to make tdbRef structures for the lists it creates here!
-        continue;
-        }
-
-    char *tbOff = trackDbSetting(tdb, "tableBrowser");
-    if (tbOff == NULL || !startsWithWord("off", tbOff))
-	slAddHead(&newList, tdb);
-    }
-slReverse(&newList);
-list = newList;
-
-/* add wikiTrack if enabled */
-if (wikiTrackEnabled(db, NULL))
-    wikiTrackDb(&list);
-
-/* Add hub tracks. */
-struct trackDb *hubTrackList = hubCollectTracks(db, pHubGroups);
-if (hubTrackList != NULL)
-    list = slCat(list, hubTrackList);
-
-/* Add custom tracks to list */
-ctList = getCustomTracks(db, cart);
-for (ct = ctList; ct != NULL; ct = ct->next)
-    {
-    slAddHead(&list, ct->tdb);
-    }
-
-return list;
-}
-
-static struct grp *makeGroupList(char *db, struct trackDb *trackList,
-				 struct grp **pHubGrpList, boolean allTablesOk)
-/* Get list of groups that actually have something in them. */
-{
-struct grp *groupsAll, *groupList = NULL, *group;
-struct hash *groupsInTrackList = newHash(0);
-struct hash *groupsInDb = newHash(0);
-struct trackDb *track;
-
-/* Stream through track list building up hash of active groups. */
-for (track = trackList; track != NULL; track = track->next)
-    hashStoreName(groupsInTrackList, track->grp);
-
-/* Scan through group table, putting in ones where we have data. */
-groupsAll = hLoadGrps(db);
-for (group = slPopHead(&groupsAll); group != NULL; group = slPopHead(&groupsAll))
-    {
-    if (hashLookup(groupsInTrackList, group->name))
-	{
-	slAddTail(&groupList, group);
-	hashAdd(groupsInDb, group->name, group);
-	}
-    else
-        grpFree(&group);
-    }
-
-/* if we have custom tracks, we want to add the track hubs
- * after that group */
-struct grp *addAfter = NULL;
-if (sameString(groupList->name, "user"))
-    addAfter = groupList;
-
-/* Add in groups from hubs.  *pHubGrpList is reversed, so we add at head to restore order. */
-for (group = slPopHead(pHubGrpList); group != NULL; group = slPopHead(pHubGrpList))
-    {
-    /* check to see if we're inserting hubs rather than
-     * adding them to the front of the list */
-    if (addAfter != NULL)
-	{
-	group->next = addAfter->next;
-	addAfter->next = group;
-	}
-    else
-	slAddHead(&groupList, group);
-    hashAdd(groupsInDb, group->name, group);
-    }
-
-/* Do some error checking for tracks with group names that are
- * not in db.  Just warn about them. */
-for (track = trackList; track != NULL; track = track->next)
-    {
-    if (!hashLookup(groupsInDb, track->grp))
-         warn("Track %s has group %s, which isn't in grp table",
-	      track->table, track->grp);
-    }
-
-/* Create dummy group for all tracks. */
-AllocVar(group);
-group->name = cloneString("allTracks");
-group->label = cloneString("All Tracks");
-slAddTail(&groupList, group);
-
-/* Create another dummy group for all tables. */
-if (allTablesOk)
-    {
-    AllocVar(group);
-    group->name = cloneString("allTables");
-    group->label = cloneString("All Tables");
-    slAddTail(&groupList, group);
-    }
-
-hashFree(&groupsInTrackList);
-hashFree(&groupsInDb);
-return groupList;
-}
-
-void initGroupsTracksTables(struct cart *cart,
-			    struct trackDb **retFullTrackList, struct grp **retFullGroupList)
-/* Get lists of all tracks and of groups that actually have tracks in them. */
-{
-static boolean inited = FALSE;
-static struct trackDb *fullTrackList = NULL;
-static struct grp *fullGroupList = NULL;
-if (! inited)
-    {
-    struct hubConnectStatus *hubList = hubConnectStatusListFromCart(cart);
-    struct grp *hubGrpList = NULL;
-    fullTrackList = getFullTrackList(cart, hubList, &hubGrpList);
-    char *db= cartString(cart, "db");
-    fullGroupList = makeGroupList(db, fullTrackList, &hubGrpList, FALSE);
-    inited = TRUE;
-    }
-if (retFullTrackList != NULL)
-    *retFullTrackList = fullTrackList;
-if (retFullGroupList != NULL)
-    *retFullGroupList = fullGroupList;
-}
-
 //#*** duplicated in hgVarAnnoGrator and annoGratorTester
 struct annoAssembly *getAnnoAssembly(char *db)
 /* Make annoAssembly for db. */
 {
 static struct annoAssembly *aa = NULL;
 if (aa == NULL)
     {
     char *nibOrTwoBitDir = hDbDbNibPath(db);
     if (nibOrTwoBitDir == NULL)
         errAbort("Can't find .2bit for db '%s'", db);
     char twoBitPath[HDB_MAX_PATH_STRING];
     safef(twoBitPath, sizeof(twoBitPath), "%s/%s.2bit", nibOrTwoBitDir, db);
     char *path = hReplaceGbdb(twoBitPath);
     aa = annoAssemblyNew(db, path);
     freeMem(path);