87a162ccdc3ac94525fc1011dec5bc10e2cf2171 markd Thu Jul 2 16:12:57 2020 -0700 web blat working diff --git src/jkOwnLib/gfWebLib.c src/jkOwnLib/gfWebLib.c index 57ed706..0ce5cc1 100644 --- src/jkOwnLib/gfWebLib.c +++ src/jkOwnLib/gfWebLib.c @@ -13,73 +13,98 @@ struct gfServerAt *server = serverList; if (cgiVarExists(varName)) { char *db = cgiString(varName); for (server = serverList; server != NULL; server = server->next) { if (sameString(db, server->name)) break; } if (server == NULL) errAbort("%s %s not found", varName, db); } return server; } -struct gfWebConfig *gfWebConfigRead(char *fileName) -/* Read configuration file into globals. */ -{ -struct gfWebConfig *cfg; -struct lineFile *lf = lineFileOpen(fileName, TRUE); -char *line, *word; -struct hash *uniqHash = newHash(0), *uniqTransHash = newHash(0), *hash; - -AllocVar(cfg); -cfg->company = ""; -while (lineFileNextReal(lf, &line)) - { - word = nextWord(&line); - if (sameWord("company", word)) +static void checkForDup(struct gfServerAt *server, char *type, struct lineFile *lf, + struct hash *hash) +/* check for duplicate server specification and record this one */ { - cfg->company = cloneString(trimSpaces(line)); +if (hashLookup(hash, server->name)) + errAbort("Duplicate %s name %s line %d of %s", + type, server->name, lf->lineIx, lf->fileName); +hashAdd(hash, server->name, NULL); } - else if (sameWord("gfServer", word) || sameWord("gfServerTrans", word)) + +static void addServer(struct gfWebConfig *cfg, char *type, struct lineFile *lf, + char *line, struct hash *uniqHash, struct hash *uniqTransHash) +/* add a server parsed from the config */ { struct gfServerAt *server; +boolean isDynamic = sameString(type, "dynServer"); char *dupe = cloneString(line); AllocVar(server); server->host = nextWord(&dupe); server->port = nextWord(&dupe); +if (isDynamic) + server->dynGenome = nextWord(&dupe); server->seqDir = nextWord(&dupe); server->name = trimSpaces(dupe); if (server->name == NULL || server->name[0] == 0) errAbort("Badly formed gfServer command line %d of %s:\n%s", - lf->lineIx, fileName, line); - if (sameString("gfServerTrans", word)) + lf->lineIx, lf->fileName, line); +if (isDynamic) + { + slAddTail(&cfg->serverList, server); + checkForDup(server, type, lf, uniqHash); + struct gfServerAt *serverCp = cloneMem(server, sizeof(struct gfServerAt)); + slAddTail(&cfg->transServerList, serverCp); + checkForDup(serverCp, type, lf, uniqTransHash); + } +else if (sameString("gfServerTrans", type)) { slAddTail(&cfg->transServerList, server); - hash = uniqTransHash; + checkForDup(server, type, lf, uniqTransHash); } else { slAddTail(&cfg->serverList, server); - hash = uniqHash; + checkForDup(server, type, lf, uniqHash); } - if (hashLookup(hash, server->name)) - errAbort("Duplicate %s name %s line %d of %s", - word, server->name, lf->lineIx, fileName); - hashAdd(hash, server->name, NULL); +} + + +struct gfWebConfig *gfWebConfigRead(char *fileName) +/* Read configuration file into globals. */ +{ +struct gfWebConfig *cfg; +struct lineFile *lf = lineFileOpen(fileName, TRUE); +char *line, *word; +struct hash *uniqHash = newHash(0), *uniqTransHash = newHash(0); + +AllocVar(cfg); +cfg->company = ""; +while (lineFileNextReal(lf, &line)) + { + word = nextWord(&line); + if (sameWord("company", word)) + { + cfg->company = cloneString(trimSpaces(line)); + } + else if (sameWord("gfServer", word) || sameWord("gfServerTrans", word) || sameWord("dynServer", word)) + { + addServer(cfg, word, lf, line, uniqHash, uniqTransHash); } else if (sameWord("tempDir", word)) { cfg->tempDir = cloneString(trimSpaces(line)); } else if (sameWord("background", word)) { cfg->background = cloneString(trimSpaces(line)); } else { errAbort("Unrecognized command %s line %d of %s", word, lf->lineIx, fileName); } }