8#include "tpcclibConfig.h"
20static char *info[] = {
21 "Make simple HTML page working as a gallery of argument SVG plots.",
23 "Usage: @P [Options] htmlfile svgfiles",
26 " -cols=<Max columns>",
27 " Maximum number of plots on one row (default is 5).",
31 " @P study.html study*.svg",
52int main(
int argc,
char **argv)
54 int ai, help=0, version=0, verbose=1;
55 char svgfile[FILENAME_MAX], htmlfile[FILENAME_MAX];
56 int firstfile=0, fileNr=0;
63 if(argc==1) {
tpcPrintUsage(argv[0], info, stderr);
return(1);}
66 for(ai=1; ai<argc; ai++)
if(*argv[ai]==
'-') {
68 char *cptr=argv[ai]+1;
if(*cptr==
'-') cptr++;
if(!*cptr)
continue;
69 if(strncasecmp(cptr,
"COLS=", 5)==0) {
70 if(
atoiCheck(cptr+5, &maxCols)==0 && maxCols>0)
continue;
71 }
else if(strncasecmp(cptr,
"COL=", 4)==0) {
72 if(
atoiCheck(cptr+4, &maxCols)==0 && maxCols>0)
continue;
74 fprintf(stderr,
"Error: invalid option '%s'.\n", argv[ai]);
83 if(help==2) {
tpcHtmlUsage(argv[0], info,
"");
return(0);}
88 if(ai<argc) {
strlcpy(htmlfile, argv[ai++], FILENAME_MAX);}
90 firstfile=ai; fileNr=1;
91 strlcpy(svgfile, argv[ai++], FILENAME_MAX);
93 fprintf(stderr,
"Error: missing filename.\n");
return(1);
96 for(; ai<argc; ai++) {
97 if(access(argv[ai], 0) == -1) {}
else fileNr++;
102 if(!htmlfile[0] || fileNr<1) {
103 fprintf(stderr,
"Error: missing command-line argument; use option --help\n");
109 printf(
"htmlfile := %s\n", htmlfile);
110 printf(
"fileNr := %d\n", fileNr);
114 if(fileNr<maxCols) maxCols=fileNr;
115 double iw=90./(double)maxCols;
119 if(verbose>1) printf(
"opening %s for writing\n", htmlfile);
121 if((fp=fopen(htmlfile,
"w")) == NULL) {
122 printf(
"Error: cannot open %s.\n", htmlfile);
127 int len=fprintf(fp,
"<!DOCTYPE html>\n");
128 if(len<10) {fclose(fp);
return(12);}
129 fprintf(fp,
"<html>\n");
130 fprintf(fp,
"<head>\n");
131 fprintf(fp,
" <meta charset=\"UTF-8\">\n");
132 fprintf(fp,
" <title>%s</title>\n",
"Gallery");
133 fprintf(fp,
" <style type=\"text/css\">\n");
134 fprintf(fp,
" * {font-family: monospace;}\n");
135 fprintf(fp,
" img {border-width: 0px; padding: 5px 0px 0px 10px; width:%g%%;}\n", iw);
136 fprintf(fp,
" </style>\n");
137 fprintf(fp,
"</head>\n\n");
140 fprintf(fp,
"<body>\n");
143 fprintf(fp,
"<figure>\n");
147 for(
int ai=firstfile; ai<argc; ai++) {
148 strlcpy(svgfile, argv[ai], FILENAME_MAX);
150 fprintf(fp,
" <a href=\"%s\">", svgfile);
152 fprintf(fp,
"<img src=\"%s\" alt=\"%s\">", svgfile, svgfile);
154 fprintf(fp,
"</a>\n");
156 if(column==maxCols) {
157 if(ai<argc) fprintf(fp,
" <br>\n");
163 fprintf(fp,
"</figure>\n");
166 fprintf(fp,
"</body>\n");
167 fprintf(fp,
"</html>\n");
int atoiCheck(const char *s, int *v)
int tpcProcessStdOptions(const char *s, int *print_usage, int *print_version, int *verbose_level)
int tpcHtmlUsage(const char *program, char *text[], const char *path)
void tpcPrintBuild(const char *program, FILE *fp)
void tpcPrintUsage(const char *program, char *text[], FILE *fp)
void statusInit(TPCSTATUS *s)
void statusSet(TPCSTATUS *s, const char *func, const char *srcfile, int srcline, tpcerror error)
size_t strlcpy(char *dst, const char *src, size_t dstsize)
int verbose
Verbose level, used by statusPrint() etc.
Header file for library libtpcextensions.