8#include "tpcclibConfig.h"
20static char *info[] = {
21 "Convert user information text file, printed by command-line programs and",
22 "scripts, to HTML format.",
24 "Usage: @P [Options] txtfile [htmlfile]",
28 " Sets HTML-links for 'See also:' list.",
30 " Link to GNU GPL is added (default) or not added.",
34 " program --help > temp.txt",
35 " pdoc2htm temp.txt program.html",
56int main(
int argc,
char **argv)
58 int ai, help=0, version=0, verbose=1;
59 char *cptr, txtfile[FILENAME_MAX], htmfile[FILENAME_MAX];
67 if(argc==1) {
tpcPrintUsage(argv[0], info, stderr);
return(1);}
68 txtfile[0]=htmfile[0]=(char)0;
70 for(ai=1; ai<argc; ai++)
if(*argv[ai]==
'-') {
72 cptr=argv[ai]+1;
if(*cptr==
'-') cptr++;
if(!*cptr)
continue;
73 if(strncasecmp(cptr,
"GPL=", 4)==0) {
75 if(strncasecmp(cptr,
"NO", 1)==0) {
77 }
else if(strncasecmp(cptr,
"YES", 1)==0) {
80 }
else if(strncasecmp(cptr,
"LINKS", 1)==0) {
81 set_links=1;
continue;
83 fprintf(stderr,
"Error: invalid option '%s'.\n", argv[ai]);
92 if(help==2) {
tpcHtmlUsage(argv[0], info,
"");
return(0);}
97 if(ai<argc) {
strlcpy(txtfile, argv[ai++], FILENAME_MAX);}
98 if(ai<argc) {
strlcpy(htmfile, argv[ai++], FILENAME_MAX);}
99 if(ai<argc) {fprintf(stderr,
"Error: too many arguments.\n");
return(1);}
103 fprintf(stderr,
"Error: missing command-line argument; use option --help\n");
108 strcpy(htmfile, txtfile);
110 fprintf(stderr,
"Error: cannot construct output file name.\n");
113 strlcat(htmfile,
".html", FILENAME_MAX);
118 printf(
"txtfile := %s\n", txtfile);
119 printf(
"htmlfile := %s\n", htmfile);
120 printf(
"set_links := %d\n", set_links);
121 printf(
"set_gpl := %d\n", set_gpl);
127 if(verbose>1) printf(
"opening %s for reading\n", txtfile);
128 if((fp=fopen(txtfile,
"r")) == NULL) {
129 printf(
"Error: cannot open %s.\n", txtfile);
134 if(txtsize<3 || txtsize>99999) {
135 printf(
"Error: invalid contents in %s.\n", txtfile);
136 fclose(fp);
return(3);
142 printf(
"Error: cannot read %s.\n", txtfile);
147 if(verbose>1) printf(
"opening %s for writing\n", htmfile);
148 if((fp=fopen(htmfile,
"w")) == NULL) {
149 printf(
"Error: cannot open %s.\n", htmfile);
150 free(buf);
return(11);
154 int len=fprintf(fp,
"<!DOCTYPE html>\n");
155 if(len<10) {free(buf); fclose(fp);
return(12);}
156 fprintf(fp,
"<html>\n");
157 fprintf(fp,
"<head>\n");
158 fprintf(fp,
" <meta charset=\"UTF-8\">\n");
159 fprintf(fp,
" <title>%s</title>\n",
"User information");
160 fprintf(fp,
" <style type=\"text/css\">\n");
161 fprintf(fp,
" * {font-family: monospace;}\n");
162 fprintf(fp,
" footer {\n");
163 fprintf(fp,
" border:1px solid gray;\n");
164 fprintf(fp,
" font-size: smaller;\n");
166 fprintf(fp,
" img {border-width: 0px;}\n");
167 fprintf(fp,
" </style>\n");
168 fprintf(fp,
"</head>\n\n");
171 fprintf(fp,
"<body>\n");
174 fprintf(fp,
"<pre>\n");
185 char *cptr2=
strcasestr(cptr+3,
"Turku PET Centre");
188 fprintf(fp,
"%s©%s", docline, cptr+3);
190 fprintf(fp,
"<a href=\"https://www.turkupetcentre.fi\">Turku PET Centre</a>\n");
192 fprintf(fp,
"%s©%s\n", docline, cptr+3);
201 if(set_links!=0 &&
strcasestr(docline,
"See also: ")!=NULL) {
204 while(*cptr2!=
'\0') {
206 if(*cptr2==
':') {cptr2++;
break;}
214 if(j>1) fputc(
',', fp);
215 fprintf(fp,
" <a href=\"./%s.html\">%s</a>", swname, swname);
226 if(*cptr==
'<') fputs(
"<", fp);
227 else if(*cptr==
'>') fputs(
">", fp);
228 else if(*cptr==
'&') fputs(
"&", fp);
229 else fputc(*cptr, fp);
235 fprintf(fp,
"</pre>\n");
238 fprintf(fp,
"\n<footer>\n");
242 fprintf(fp,
"<div>\n");
244 fprintf(fp,
"<a href=\"https://www.gnu.org/licenses/gpl-3.0-standalone.html\">\n");
245 fprintf(fp,
"<img alt=\"GNU GPL\" ");
246 fprintf(fp,
"style=\"width:88px; height:31px; float:left; margin: 5px 20px 5px 5px;\"");
247 fprintf(fp,
"\n src=\"https://www.turkupetcentre.net/software/gplv3-88x31.png\"></a>\n");
248 fprintf(fp,
"</div>\n");
251 fprintf(fp,
"</footer>\n");
254 fprintf(fp,
"</body>\n");
255 fprintf(fp,
"</html>\n");
int filenameRmExtension(char *s)
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)
char * asciiFileRead(FILE *fp, char *data, size_t maxlen)
size_t asciiFileSize(FILE *fp, int *nonprintable)
void statusInit(TPCSTATUS *s)
void statusSet(TPCSTATUS *s, const char *func, const char *srcfile, int srcline, tpcerror error)
int strTokenNCpy(const char *s1, const char *s2, int i, char *s3, int count)
size_t strlcpy(char *dst, const char *src, size_t dstsize)
char * strcasestr(const char *haystack, const char *needle)
size_t strlcat(char *dst, const char *src, size_t dstsize)
int verbose
Verbose level, used by statusPrint() etc.
Header file for library libtpcextensions.