src/hg/lib/trackDbCustom.c 1.61

1.61 2009/04/10 19:56:35 tdreszer
Added subTdbFind() and tdbFindOrCreate() support routines
Index: src/hg/lib/trackDbCustom.c
===================================================================
RCS file: /projects/compbio/cvsroot/kent/src/hg/lib/trackDbCustom.c,v
retrieving revision 1.60
retrieving revision 1.61
diff -b -B -U 4 -r1.60 -r1.61
--- src/hg/lib/trackDbCustom.c	13 Mar 2009 23:02:08 -0000	1.60
+++ src/hg/lib/trackDbCustom.c	10 Apr 2009 19:56:35 -0000	1.61
@@ -11,8 +11,10 @@
 #include "ra.h"
 #include "hash.h"
 #include "sqlNum.h"
 #include "obscure.h"
+#include "hgMaf.h"
+#include "customTrack.h"
 
 static char const rcsid[] = "$Id$";
 
 /* ----------- End of AutoSQL generated code --------------------- */
@@ -776,4 +778,35 @@
                      || sameWord(setting,"true")
                      || sameWord(setting,"enabled")
                      || atoi(setting) != 0));
 }
+
+struct trackDb *subTdbFind(struct trackDb *parent,char *table)
+/* Return subTrack tdb if it exists in parent. */
+{
+if(parent == NULL)
+    return NULL;
+
+struct trackDb *tdb;
+for (tdb = parent->subtracks;
+     tdb != NULL && differentString(tdb->tableName,table);
+     tdb = tdb->next) {}
+return tdb;
+}
+
+struct trackDb *tdbFindOrCreate(char *db,struct trackDb *parent,char *table)
+/* Find or creates the tdb for this table. May return NULL. */
+{
+struct trackDb *tdb = NULL;
+if (parent != NULL)
+    {
+    if(sameString(parent->tableName, table))
+        tdb = parent;
+    else if(consWiggleFind(db,parent,table) != NULL)
+        tdb = parent;
+    else
+        tdb = subTdbFind(parent,table);
+    }
+if(tdb == NULL && db != NULL)
+    tdb = hTrackDbForTrack(db, table);
+return tdb;
+}