076d54726c175d8fab099e10b8e83e3e89ef4eea kent Mon Jun 12 10:02:30 2017 -0700 Adding title option diff --git src/tabFile/tabToHtml/tabToHtml.c src/tabFile/tabToHtml/tabToHtml.c index 552fff9..5c3bed1 100644 --- src/tabFile/tabToHtml/tabToHtml.c +++ src/tabFile/tabToHtml/tabToHtml.c @@ -1,108 +1,119 @@ /* tabToHtml - Convert tab-separated-file to an HTML file that is a table and not much else.. */ #include "common.h" #include "linefile.h" #include "hash.h" #include "options.h" #include "fieldedTable.h" -boolean gEmbed; // If true we embed in another page +char *clTitle = NULL; // Title from command line + +boolean clEmbed; // If true we embed in another page void usage() /* Explain usage and exit. */ { errAbort( "tabToHtml - Convert tab-separated-file to an HTML file that is a table and not much else.\n" "usage:\n" - " tabToHtml XXX\n" + " tabToHtml in.tsv out.html\n" "options:\n" " -embed - don't write beginning and end of page, just controls and tree.\n" " useful for making html to be embedded in another page.\n" + " -title=\"Some sort of table title\"\n" ); } /* Command line validation table. */ static struct optionSpec options[] = { {"embed", OPTION_BOOLEAN}, + {"title", OPTION_STRING}, {NULL, 0}, }; void writeHtml(struct fieldedTable *table, FILE *f) /* Write HTML version of table */ { -if (!gEmbed) +if (!clEmbed) { fputs( "\n" "\n" "\n" " \n" , f); + if (clTitle) + fprintf(f, " %s\n", clTitle); + else fprintf(f, " table %s\n", table->name); fputs( "\n" "\n" , f); fprintf(f, ""); + if (clTitle) + fprintf(f, "

%s

\n", clTitle); + else fprintf(f, "

table from %s

\n", table->name); } /* Print table tag and header row. */ fprintf(f, "\n"); fprintf(f, ""); int i; for (i=0; ifieldCount; ++i) { char *field = table->fields[i]; fprintf(f, " ", field); } fprintf(f, "\n"); /* Print data rows. */ struct fieldedRow *fr; for (fr = table->rowList; fr != NULL; fr = fr->next) { char **row = fr->row; fprintf(f, ""); for (i=0; ifieldCount; ++i) fprintf(f, " ", row[i]); fprintf(f, "\n"); } /* Close up table */ fprintf(f, "
%s
%s
\n"); /* Unless embedded close up web page too. */ -if (!gEmbed) +if (!clEmbed) { fputs( "\n" "\n" "\n" , f); } } void tabToHtml(char *inTsv, char *outHtml) /* tabToHtml - Convert tab-separated-file to an HTML file that is a table and not much else.. */ { struct fieldedTable *table = fieldedTableFromTabFile(inTsv, inTsv, NULL, 0); FILE *f = mustOpen(outHtml, "w"); writeHtml(table, f); carefulClose(&f); } int main(int argc, char *argv[]) /* Process command line. */ { optionInit(&argc, argv, options); if (argc != 3) usage(); -gEmbed = optionExists("embed"); +clEmbed = optionExists("embed"); +clTitle = optionVal("title", NULL); tabToHtml(argv[1], argv[2]); return 0; }