FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

doc2html: optionally create index and separate html files manually, c… · gnuplot/gnuplot@8cae5d2 · GitHub

Repository navigation

Commit 8cae5d2

Browse files
committed
doc2html: optionally create index and separate html files manually, change command line options and always use hard-coded links
1 parent 8c8b9db commit 8cae5d2

2 files changed

Lines changed: 147 additions & 47 deletions

File tree

‎ChangeLog‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
1+
2011-03-07 Bastian Maerkisch <bmaerkisch@web.de>
2+
3+
* docs/windows/doc2html.c (main): change command line options,
4+
(convert, header, footer) optionally split html files manually
5+
[SPLIT_FILES] (Note: this will produce ~500 files!), optionally
6+
create index file manually [CREATE_INDEX], always use hard-coded
7+
links as none of the open source viewers seem to support k-links
8+
9+
* config/makefile.mgw, config/watcom/Makefile, config/mingw/Makefile:
10+
change command line accordingly
11+
112
2011-03-06 Hans-Bernhard Broeker <broeker@physik.rwth-aachen.de>
213

314
* config/watcom/.cvsignore: Set up list of files to be ignored.

‎docs/windows/doc2html.c‎

Lines changed: 136 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#ifndef lint
2-
static char *RCSid() { return RCSid("$Id: doc2html.c,v 1.2 2011/02/28 11:40:40 markisch Exp $"); }
2+
static char *RCSid() { return RCSid("$Id: doc2html.c,v 1.3 2011/02/28 11:53:40 markisch Exp $"); }
33
#endif
44

55
/* GNUPLOT - doc2html.c */
@@ -40,7 +40,7 @@ static char *RCSid() { return RCSid("$Id: doc2html.c,v 1.2 2011/02/28 11:40:40 m
4040
*
4141
* Derived from doc2rtf and doc2html (version 3.7.3) by B. Maerkisch
4242
*
43-
* usage: doc2html file.doc file.html file.htc [-d]
43+
* usage: doc2html file.doc outputdirectory [-d]
4444
*
4545
*/
4646

@@ -51,6 +51,14 @@ static char *RCSid() { return RCSid("$Id: doc2html.c,v 1.2 2011/02/28 11:40:40 m
5151
# include "config.h"
5252
#endif
5353

54+
#ifdef WXHELP
55+
/* The Microsoft help compiler splits topics and creates the index automatically.
56+
To create help files for wxWidgets we need to do this manually.
57+
Note that this might overwrite the stub index file from CVS. */
58+
#define SPLIT_FILES
59+
#define CREATE_INDEX
60+
#endif
61+
5462
#include "syscfg.h"
5563
#include "stdfn.h"
5664
#define MAX_LINE_LEN 10230
@@ -59,90 +67,137 @@ static char *RCSid() { return RCSid("$Id: doc2html.c,v 1.2 2011/02/28 11:40:40 m
5967
#include "version.h"
6068

6169
static TBOOLEAN debug = FALSE;
70+
static char path[PATH_MAX];
71+
static const char basename[] = "wgnuplot";
6272

63-
void convert __PROTO((FILE *, FILE *, FILE *));
64-
void process_line __PROTO((char *, FILE *, FILE *));
73+
void convert __PROTO((FILE *, FILE *, FILE *, FILE *));
74+
void process_line __PROTO((char *, FILE *, FILE *, FILE *));
6575

6676
int
6777
main (int argc, char **argv)
6878
{
6979
FILE *infile;
7080
FILE *outfile;
7181
FILE *contents;
72-
if (argc == 5 && argv[4][0] == '-' && argv[4][1] == 'd')
73-
debug = TRUE;
82+
FILE *index = NULL;
83+
char filename[PATH_MAX];
84+
char *last_char;
7485

75-
if (argc != 4 && !debug) {
76-
fprintf(stderr, "Usage: %s infile outfile contentfile\n", argv[0]);
86+
if (argc == 4 && argv[3][0] == '-' && argv[3][1] == 'd')
87+
debug = TRUE;
88+
if (argc != 3 && !debug) {
89+
fprintf(stderr, "Usage: %s infile outpath\n", argv[0]);
7790
exit(EXIT_FAILURE);
7891
}
7992
if ((infile = fopen(argv[1], "r")) == (FILE *) NULL) {
8093
fprintf(stderr, "%s: Can't open %s for reading\n",
8194
argv[0], argv[1]);
8295
exit(EXIT_FAILURE);
8396
}
84-
if ((outfile = fopen(argv[2], "w")) == (FILE *) NULL) {
97+
strcpy(path, argv[2]);
98+
/* make sure there's a path separator at the end */
99+
last_char = path + strlen(path);
100+
if ((*last_char != DIRSEP1) && (*last_char != DIRSEP2)) {
101+
*last_char++ = DIRSEP1;
102+
*last_char = 0;
103+
}
104+
strcpy(filename, path);
105+
strcat(filename, basename);
106+
strcat(filename, ".html");
107+
if ((outfile = fopen(filename, "w")) == (FILE *) NULL) {
108+
fprintf(stderr, "%s: Can't open %s for writing\n",
109+
argv[0], filename);
110+
fclose(infile);
111+
exit(EXIT_FAILURE);
112+
}
113+
strcpy(filename, path);
114+
strcat(filename, basename);
115+
strcat(filename, ".hhc");
116+
if ((contents = fopen(filename, "w")) == (FILE *) NULL) {
85117
fprintf(stderr, "%s: Can't open %s for writing\n",
86-
argv[0], argv[2]);
118+
argv[0], filename);
87119
fclose(infile);
120+
fclose(outfile);
88121
exit(EXIT_FAILURE);
89122
}
90-
if ((contents = fopen(argv[3], "w")) == (FILE *) NULL) {
123+
#ifdef CREATE_INDEX
124+
strcpy(filename, path);
125+
strcat(filename, basename);
126+
strcat(filename, ".hhk");
127+
if ((index = fopen(filename, "w")) == (FILE *) NULL) {
91128
fprintf(stderr, "%s: Can't open %s for writing\n",
92-
argv[0], argv[3]);
129+
argv[0], filename);
93130
fclose(infile);
94131
fclose(outfile);
132+
fclose(contents);
95133
exit(EXIT_FAILURE);
96134
}
135+
#endif
97136
parse(infile);
98-
convert(infile, outfile, contents);
137+
convert(infile, outfile, contents, index);
99138
return EXIT_SUCCESS;
100139
}
101140

102141

103142
void
104-
convert(FILE *a, FILE *b, FILE *c)
143+
header(FILE *a, char * title)
144+
{
145+
/* generate html header */
146+
fprintf(a, "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">\n");
147+
fprintf(a, "<html>\n");
148+
fprintf(a, "<head>\n");
149+
fprintf(a, "<meta http-equiv=\"Content-type\" content=\"text/html; charset=windows-1252\">\n");
150+
fprintf(a, "<title>%s</title>\n", title);
151+
fprintf(a, "</head>\n");
152+
fprintf(a, "<body>\n");
153+
}
154+
155+
156+
void
157+
footer(FILE *a)
158+
{
159+
/* close final page and generate trailer */
160+
fprintf(a, "</body>\n");
161+
fprintf(a, "</html>\n");
162+
}
163+
164+
165+
void
166+
convert(FILE *a, FILE *b, FILE *c, FILE *d)
105167
{
106168
static char line[MAX_LINE_LEN+1];
107169

108-
/* generate html header */
109-
fprintf(b, "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">\n");
110-
fprintf(b, "<html>\n");
111-
fprintf(b, "<head>\n");
112-
fprintf(b, "<meta http-equiv=\"Content-type\" content=\"text/html; charset=windows-1252\">\n");
113-
fprintf(b, "<title>gnuplot help</title>\n");
114-
fprintf(b, "</head>\n");
115-
fprintf(b, "<body>\n");
170+
header(b, "gnuplot help");
116171
fprintf(b, "<h1 align=\"center\">gnuplot %s patchlevel %s</h1>\n", gnuplot_version, gnuplot_patchlevel);
117172

118-
/* generate html header */
119-
fprintf(c, "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">\n");
120-
fprintf(c, "<html>\n");
121-
fprintf(c, "<head>\n");
122-
fprintf(c, "<meta http-equiv=\"Content-type\" content=\"text/html; charset=windows-1252\">\n");
123-
fprintf(c, "<title>gnuplot help contents</title>\n");
124-
fprintf(c, "</head>\n");
125-
fprintf(c, "<body>\n");
173+
header(c, "gnuplot help contents");
126174
fprintf(c, "<ul>\n");
127175

176+
if (d) {
177+
header(d, "gnuplot help index");
178+
fprintf(d, "<ul>\n");
179+
}
180+
128181
/* process each line of the file */
129182
while (get_line(line, sizeof(line), a)) {
130-
process_line(line, b, c);
183+
process_line(line, b, c, d);
131184
}
132185

133-
/* close final page and generate trailer */
134-
fprintf(b, "</BODY>\n");
135-
fprintf(b, "</HTML>\n");
186+
footer(b);
136187

137-
/* close final page and generate trailer */
138188
fprintf(c, "</ul>\n");
139-
fprintf(c, "</BODY>\n");
140-
fprintf(c, "</HTML>\n");
189+
footer(c);
190+
191+
if (d) {
192+
fprintf(d, "</ul>\n");
193+
footer(d);
194+
}
195+
141196
list_free();
142197
}
143198

144199
void
145-
process_line(char *line, FILE *b, FILE *c)
200+
process_line(char *line, FILE *b, FILE *c, FILE *d)
146201
{
147202
static int line_count = 0;
148203
static char line2[MAX_LINE_LEN+1];
@@ -159,12 +214,11 @@ process_line(char *line, FILE *b, FILE *c)
159214
static TBOOLEAN inquote = FALSE;
160215
static int inref = 0;
161216
static int klink = 0; /* link number counter */
162-
217+
static char location[PATH_MAX+1] = {0};
163218
struct LIST *klist;
164-
165219
int i, j, k, l;
166-
line_count++;
167220

221+
line_count++;
168222
i = 0;
169223
j = 0;
170224
while (line[i] != NUL) {
@@ -204,8 +258,10 @@ process_line(char *line, FILE *b, FILE *c)
204258
klist = lookup(topic);
205259
if (klist && (k = klist->line) > 0 && (k != last_line)) {
206260
char hyplink1[MAX_LINE_LEN+1];
261+
#if 0
262+
/* K-link: index lookup via ActiveX and JavaScript. */
263+
/* Deactivated, as none of the open source viewers seem to support this */
207264
char id[15];
208-
#ifndef HTML_HARDLINKS
209265
sprintf(id, "link%i", ++klink);
210266
sprintf(hyplink1, "<OBJECT id=%s type=\"application/x-oleobject\" classid=\"clsid:adb880a6-d8ff-11cf-9377-00aa003b7a11\">\n"
211267
" <PARAM name=\"Command\" value=\"KLink\">\n"
@@ -217,10 +273,11 @@ process_line(char *line, FILE *b, FILE *c)
217273
if (debug)
218274
fprintf(stderr, "hyper link \"%s\" - %s on line %d\n", topic, id, line_count);
219275
#else
276+
/* explicit links */
220277
if ((klist->line) > 1)
221278
sprintf(hyplink1, "<a href=\"loc%d.html\">", klist->line);
222279
else
223-
sprintf(hyplink1, "<a href=\"wgnuplot.html\">");
280+
sprintf(hyplink1, "<a href=\"%s.html\">", basename);
224281
if (debug)
225282
fprintf(stderr, "hyper link \"%s\" - loc%d.html on line %d\n", topic, klist->line, line_count);
226283
#endif
@@ -276,13 +333,21 @@ process_line(char *line, FILE *b, FILE *c)
276333
case '?': /* interactive help entry */
277334
case '=': /* latex index entry */
278335
if ((line2[1] != NUL) && (line2[1] != ' ')) {
336+
#ifndef CREATE_INDEX
279337
if (!inkey) {
280338
/* open keyword object */
281339
fprintf(b, "<OBJECT type=\"application/x-oleobject\" classid=\"clsid:1e2a7bd0-dab9-11d0-b93a-00c04fc99f9e\">\n");
282340
inkey = TRUE;
283341
}
284342
/* add keyword */
285343
fprintf(b, " <param name=\"Keyword\" value=\"%s\">\n", &line2[1]);
344+
#else
345+
fprintf(d, "<li> <object type=\"text/sitemap\">\n");
346+
fprintf(d, " <param name=\"Name\" value=\"%s\">\n", &line2[1]);
347+
fprintf(d, " <param name=\"Local\" value=\"%s.html\">\n", location);
348+
fprintf(d, " </object>\n");
349+
/* NB: don't set inkey here */
350+
#endif
286351
if (debug)
287352
fprintf(stderr,"keyword defintion: \"%s\" on line %d.\n", line2 + 1, line_count);
288353
}
@@ -377,7 +442,6 @@ process_line(char *line, FILE *b, FILE *c)
377442
}
378443
default:{
379444
if (isdigit((int)line[0])) { /* start of section */
380-
char location[MAX_LINE_LEN+1];
381445
int newlevel = line[0]-'0';
382446
char spacer[10];
383447

@@ -398,16 +462,41 @@ process_line(char *line, FILE *b, FILE *c)
398462
fprintf(b, "\n");
399463

400464
/* output unique ID */
401-
sprintf(location, "loc%d", line_count);
465+
if (!startpage)
466+
sprintf(location, "loc%d", line_count);
467+
else
468+
strcpy(location, basename);
402469

403-
/* split contents */
470+
#ifndef SPLIT_FILES
471+
/* let hhc auomatically split contents */
404472
if (!startpage) {
405473
fprintf(b, "<OBJECT type=\"application/x-oleobject\" classid=\"clsid:1e2a7bd0-dab9-11d0-b93a-00c04fc99f9e\">\n");
406474
fprintf(b, "<param name=\"New HTML file\" value=\"%s.html\">\n", location);
407475
fprintf(b, "<param name=\"New HTML title\" value=\"%s\">\n", &line2[2]);
408476
fprintf(b, "</OBJECT>\n");
409477
fprintf(b, "<h2>%s</h2>\n", &line2[2]);
410478
}
479+
#else
480+
/* split contents manually */
481+
if (!startpage) {
482+
char newfile[PATH_MAX];
483+
484+
/* close current file */
485+
footer(b);
486+
fclose(b);
487+
488+
/* open new file */
489+
sprintf(newfile, "%s%s.html", path, location);
490+
/* fprintf(stderr, "%s\n", newfile); */
491+
if (!(b = fopen(newfile, "w"))) {
492+
fprintf(stderr, "%s: Can't open %s for writing\n",
493+
"doc2html", newfile);
494+
exit(EXIT_FAILURE);
495+
}
496+
header(b, &line2[2]);
497+
fprintf(b, "<h2>%s</h2>\n", &line2[2]);
498+
}
499+
#endif
411500

412501
/* create toc entry */
413502
if (newlevel > level) {
@@ -427,7 +516,7 @@ process_line(char *line, FILE *b, FILE *c)
427516
spacer[level] = NUL;
428517
fprintf(c, "%s<li> <OBJECT type=\"text/sitemap\">\n", spacer);
429518
fprintf(c, "%s <param name=\"Name\" value=\"%s\">\n", spacer, &line2[2]);
430-
fprintf(c, "%s <param name=\"Local\" value=\"%s.html\">\n", spacer, startpage ? "wgnuplot" : location);
519+
fprintf(c, "%s <param name=\"Local\" value=\"%s.html\">\n", spacer, location);
431520
fprintf(c, "%s </OBJECT>\n", spacer);
432521
if (debug)
433522
fprintf(stderr, "Section \"%s\", Level %i, ID=%s on line %d\n", line2 + 2, level, location, line_count);

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL