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);
97 for(; ai<argc; ai++) {
98 if(access(argv[ai], 0) == -1) ret++;
else fileNr++;
103 if(!htmlfile[0] || fileNr<1) {
104 fprintf(stderr,
"Error: missing command-line argument; use option --help\n");
110 printf(
"htmlfile := %s\n", htmlfile);
111 printf(
"fileNr := %d\n", fileNr);
115 if(fileNr<maxCols) maxCols=fileNr;
116 double iw=90./(double)maxCols;
120 if(verbose>1) printf(
"opening %s for writing\n", htmlfile);
122 if((fp=fopen(htmlfile,
"w")) == NULL) {
123 printf(
"Error: cannot open %s.\n", htmlfile);
128 int len=fprintf(fp,
"<!DOCTYPE html>\n");
129 if(len<10) {fclose(fp);
return(12);}
130 fprintf(fp,
"<html>\n");
131 fprintf(fp,
"<head>\n");
132 fprintf(fp,
" <meta charset=\"UTF-8\">\n");
133 fprintf(fp,
" <title>%s</title>\n",
"Gallery");
134 fprintf(fp,
" <style type=\"text/css\">\n");
135 fprintf(fp,
" * {font-family: monospace;}\n");
136 fprintf(fp,
" img {border-width: 0px; padding: 5px 0px 0px 10px; width:%g%%;}\n", iw);
137 fprintf(fp,
" </style>\n");
138 fprintf(fp,
"</head>\n\n");
141 fprintf(fp,
"<body>\n");
144 fprintf(fp,
"<figure>\n");
148 for(
int ai=firstfile; ai<argc; ai++) {
149 strlcpy(svgfile, argv[ai], FILENAME_MAX);
151 fprintf(fp,
" <a href=\"%s\">", svgfile);
153 fprintf(fp,
"<img src=\"%s\" alt=\"%s\">", svgfile, svgfile);
155 fprintf(fp,
"</a>\n");
157 if(column==maxCols) {
158 if(ai<argc) fprintf(fp,
" <br>\n");
164 fprintf(fp,
"</figure>\n");
167 fprintf(fp,
"</body>\n");
168 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.