unless it is considered as white space (for
example, carriage return and line feed), in which case it's sent directly to the
output. */ if (c < ' ') { if (isspace(c)) { fputc(c, out); } else {
fputs("^", out); fputc(c + '@', out); fputs("", out); } /* ISO
graphic character. */ } else if (c > 160) { fputc(c, out); if (nonbreak
&& c == '«' && *lp != 0 && isspace(*lp)) {
fputs(" ", out); lp++; } /* Normal ASCII 7 bit graphic character. */ } if
(c >= ' ' && c <= '~') { /* Italic switch character */ if (!inmath
&& c == '_') { italics = !italics; if (italics) { fputs("", out); }
else { fputs("", out); } /* Math mode start and end sequences. */ } else if
(c == '\\' && (*lp == '(' || *lp == ')')) { fputc(c, out); inmath = *lp
== '('; /* Start footnote */ } else if (!inmath && (c == '[' || (c == '
' && *lp == '[') || (c == ' ' && *lp == ' ' && lp[1] ==
'['))) { if (foot == NULL) { char s[256]; sprintf(s, "%s/%s_foot.html",
basename, basename); foot = fopen(s, "w"); fputs("\n\n\n\n\n
\n", foot); } fprintf(out, "",
basename, ++footcount); fputs("", out); infoot++; if (c == ' ') { if (*lp == ' ') { lp++; }
lp++; } fprintf(foot, "", footcount); /* End footnote */ } else if
(!inmath && infoot && c == ']') { int i; fputs("", foot);
fputs("\n
", foot);
for (i = 0; i < 30; i++) {
fputs("\n", foot);
}
fputs("
\n", foot); infoot--; if (infoot < 0) {
infoot = 0; } /* ASCII characters requiring verbatim handling */ } else if (c ==
'<') { fputs("<", out); } else if (c == '>') { fputs(">", out); }
else if (c == '&') { fputs("&", out); } else if (c == '"') { fputs(""",
out); } else if (c == '<') { fputs("<", out); /* Try to convert dumb ASCII
quotes to open and close quotes. */ } else if (!inmath && c == '"') {
fputs(quoth ? "''" : "``", out); quoth = !quoth; /* Normal character */ } else {
if (nonbreak && isspace(c) && *lp != 0 &&
strchr(PUNCTUATION, *lp) != NULL) { fputs(" ", out); } else { fputc(c,
out); } } } /* Note that other characters, specifically those in the range from
127 through 160, get dropped. */ } #undef out } else { /* L A T E X */ #define
out tout int c; /* Now process the input file character by character and
translate each character, if required, emitting the results to the output
stream. */ while ((c = *lp++) != EOS) { /* It's a control character. Emit as
^ unless it is considered as white space (for example, carriage return
and line feed), in which case it's sent directly to the output. */ if (c < '
') { if (isspace(c)) { putc(c, out); } else { fputs("\\verb+^", out); putc(c +
'@', out); putc('+', out); } /* ISO graphic character. */ } else if (c > 160)
{ fputs(texform[c - 161], out); if (nonbreak && c == '«' && *lp
!= 0 && isspace(*lp)) { putc('~', out); lp++; } /* Normal ASCII 7 bit
graphic character. */ } if (c >= ' ' && c <= '~') { /* Italic
switch character */ if (!inmath && c == '_') { italics = !italics; if
(italics) { fputs("{\\it ", out); } else { fputs("}", out); } /* Math mode start
and end sequences. */ } else if (c == '\\' && (*lp == '(' || *lp ==
')')) { fputc(c, out); inmath = *lp == '('; /* Start footnote */ } else if
(!inmath && (c == '[' || (c == ' ' && *lp == '[') || (c == ' '
&& *lp == ' ' && lp[1] == '['))) { fputs("\\footnote{", out); if
(c == ' ') { if (*lp == ' ') { lp++; } lp++; } /* End footnote */ } else if
(!inmath && c == ']') { fputs("}", out); /* Dash */ } else if (c == '-'
&& *lp == '-') { /* Turn "--" into "---" for M-dash. */ fputs("---",
out); lp += 1; /* Ellipsis */ } else if (c == '.' && *lp == '.'
&& lp[1] == '.') { fputs("\\ldots", out); if (lp[2] == ' ') { fputs(" ",
out); } else { fputs("\\ ", out); } lp += 2; /* ASCII characters requiring
verbatim handling */ } else if (c == '~') { fputs("\\verb+", out); fputc(c,
out); fputc('+', out); } else if (!inmath && c == '^') {
fputs("\\verb+", out); fputc(c, out); fputc('+', out); /* ASCII characters
requiring math-mode quoting. */ } else if (!inmath &&
strchr("|<>", c) != NULL) { fputc('$', out); fputc(c, out); fputc('$',
out); /* Try to convert dumb ASCII quotes to open and close quotes. */ } else if
(!inmath && c == '"') { fputs(quoth ? "''" : "``", out); quoth = !quoth;
/* Normal character */ } else { if (nonbreak && isspace(c) &&
*lp != 0 && strchr(PUNCTUATION, *lp) != NULL) { putc('~', out); } else {
/* Characters requiring protection against interpretation as control sequences.
*/ if (strchr("$&%#", c) != NULL) { putc('\\', out); } if (!inmath
&& strchr("{}", c) != NULL) { putc('\\', out); } putc(c, out); } } } /*
Note that other characters, specifically those in the range from 127 through
160, get dropped. */ } #undef out } } /* ENDQUOTE -- Terminate a block quotation
when a non-conforming line is encountered. */ static void endquote(out) FILE
*out; { if (html) { if (saith) { fputs("\n
\n", out); saith = 0; } } else { if (saith) {
fputs("\n\\end{quote}\n", out); saith = 0; } } } /* NAVAIDS -- Create navigation
panel buttons. */ static void navaids(basename, chapno, last, out) char
*basename; int chapno, last; FILE *out; { char s[256]; /* Previous chapter
button. */ if (chapno > 1) { sprintf(s, "", basename, chapno - 1); fputs(s, out);
fputs("\n",
out); } else { fputs("\n", out); } /* Up to table of contents button. */ sprintf(s, " \n", basename); fputs(s, out); /* Next chapter button. */ if
(!last) { sprintf(s, "", basename, chapno
+ 1); fputs(s, out); } sprintf(s, "", last ? "_gr" : "", last ? "" : "Next"); fputs(s, out); if
(!last) { fputs("\n", out); } else { fputc('\n', out); } } /* ENDCHAP --
Standard end of chapter processing. */ static void endchap(basename, chapno,
last, out) char *basename; int chapno, last; FILE *out; { fputs("
\n", out); navaids(basename, chapno, last, out); fputs("\n", out); fputs("\n",
out); fclose(out); } /* Main program */ int main(argc, argv) int argc; char
*argv[]; { int i, f = 0, peeked = 0, titling = 1, chapno = 0, ctl, ttl = 0, atl
= 0; char *cp, opt; FILE *in = stdin, *out = stdout, *chap = NULL; unsigned char
line[256], peek[256], basename[256], sbuf[256]; unsigned char titre[10][256],
auteur[10][256], ctitle[10][256]; #define tstream ((chap == NULL) ? out : chap)
#define ostream ((chap == NULL) ? out : (infoot ? foot : chap)) for (i = 1; i
< argc; i++) { cp = argv[i]; if (*cp == '-') { opt = *(++cp); if
(islower(opt)) opt = toupper(opt); switch (opt) { case 'F': nonbreak = 1; break;
case 'H': if (f > 0) { fprintf(stderr, "Must specify -h before any file
name.\n"); return 2; } html = 1; break; case '?': case 'U':
fprintf(stderr,"\nETSET -- Typeset ISO 8859 Latin-1 Etext. Call");
fprintf(stderr, "\n with etset [input [output]]"); fprintf(stderr,"\n");
fprintf(stderr,"\n Options:"); fprintf(stderr,"\n -f Use nonbreaking spaces for
French punctuation"); fprintf(stderr,"\n -h Generate HTML");
fprintf(stderr,"\n"); fprintf(stderr,"\n"); return 0; } } else { switch (f) {
case 0: if ((in = fopen(cp, "r")) == NULL) { fprintf(stderr, "Cannot open input
file %s\n", cp); return 2; } f++; break; case 1: if (html) { strcpy(basename,
cp); sprintf(line, "%s/%s.html", basename, basename); if ((out = fopen(line,
"w")) == NULL) { fprintf(stderr, "Cannot open output file %s\n", line); return
2; } } else { if ((out = fopen(cp, "w")) == NULL) { fprintf(stderr, "Cannot open
output file %s\n", cp); return 2; } } f++; break; default: fprintf(stderr, "Too
many file names specified.\n"); } } } if (html && f < 2) {
fprintf(stderr, "Must specify input and output file names for HTML.\n"); } /*
Output document header. */ if (html) { outgif(basename, "foot", d_foot, sizeof
d_foot); outgif(basename, "next", d_next, sizeof d_next); outgif(basename,
"prev", d_prev, sizeof d_prev); outgif(basename, "up", d_up, sizeof d_up);
outgif(basename, "next_gr", d_next_gr, sizeof d_next_gr); outgif(basename,
"prev_gr", d_prev_gr, sizeof d_prev_gr); fprintf(out, "\n", VERSION, REVDATE); fputs("\n", out);
fputs("\n", out); fputs("\n
\n", out); } else { fputs("}\n\\author{\n", out); } continue; } } /*
Heuristic justification for lines which begin with white space. */ if (line[0]
== ' ') { int n = strlen(line) - 2, w; unsigned char *ap = line + 1; while
(isspace(*ap)) { ap++; n--; } line[strlen(line) - 1] = EOS; if (abs((w =
((FormatWidth - n) / 2) - (ap - lp))) < 3) { /* It's centered: check for
chapter separators. */ if (fgets((char *) peek, (sizeof peek) - 1, in) != NULL)
{ unsigned char *pp = peek; int cheddar = 1, chonk = 0; peeked = 1; trim(peek);
while (*pp != EOS) { if (!(isspace(*pp) || (*pp == '-'))) { cheddar = 0; break;
} if (*pp++ == '-') { chonk++; } } if (cheddar && chonk > 2) {
chapout = 0; peeked = 0; if (author) { author = 0; if (html) { int n;
fputs("\n\n\n", out); if (ttl > 0) { fputs("
", out); for (n = 0; n < ttl; n++) { protext(titre[n], out, basename);
fputc('\n', out); } fputs("
\n", out); } if (atl > 0) { fputs("
", out); for (n = 0; n < atl; n++) { protext(auteur[n], out, basename);
fputc('\n', out); } fputs("
\n", out); } fputs("
\n", out); } else { fputs("}\n\\begin{document}\n\\maketitle\n", out); if
(nonbreak) { fputs("\\frenchspacing\n", out); } } } while (fgets((char *)
peek, (sizeof peek) - 1, in) != NULL) { trim(peek); pp = peek;
peek[strlen(peek) - 1] = EOS; while (*pp && isspace(*pp)) { pp++; } if
(*pp == EOS) { break; } if (!chapout) { if (html) { if (chap != NULL) {
endchap(basename, chapno, 0, chap); chap = NULL; } firstchap = 1; chapout = 1;
ctl = 0; sprintf(line, "%s/%s_chap%d.html", basename, basename, ++chapno);
chap = fopen(line, "w"); fputs("\n\n\n\n\n", ostream); navaids(basename,
chapno, 0, ostream); sprintf(sbuf, "
\n
\n", ostream); /* Now make link to chapter from table of contents. */
sprintf(sbuf, "
- ", basename, chapno); fputs(sbuf,
out); for (i = 0; i < ctl; i++) { protext(ctitle[i], out, basename);
fputc('\n', out); } fputs("\n", out); } else { fputs("}\n", out); } }
continue; } } if (!titling && !author) { if (html) {
endquote(ostream); fputs("\n
\n", ostream); eline = "
\n"; } else { endquote(out);
fputs("\n{\\centering ", out); eline = "\\\\}\n"; } } } else { int n; /* Check
for a block quote. */ for (n = 1; n < QuoteIndent; n++) { if (line[n] != '
') { n = -1; break; } } if (n > 1 && !isspace(line[QuoteIndent])) {
if (!saith) { if (html) { fputs("
\n", ostream); } else { fputs("\\begin{quote}\n", out); } saith
= 1; } /* Ragged left or ragged right: determine which and output
appropriate command. */ } else if (!titling && !author) { if (html)
{ endquote(ostream); } else { endquote(out); fputs(w < 0 ?
"{\\raggedleft" : "{\\raggedright", out); eline = "\\\\ }\n\n"; } } } lp =
ap - 1; } else { if (html) { endquote(ostream); } else { endquote(out); } }
if (titling || author) { unsigned char *ap = line; int nonbs = 0; while (*ap
!= EOS) { if (!isspace(*ap)) { nonbs = 1; break; } ap++; } if (!nonbs) {
continue; } } if (html) { if (titling) { strcpy(titre[ttl++], lp); } if
(author) { strcpy(auteur[atl++], lp); continue; } protext(lp, tstream,
basename); if (eline) { fputs(eline, tstream); } } else { protext(lp, out,
NULL); if (titling || author) { fputs("\\\\\n", out); } if (eline) {
fputs(eline, out); } } } /* Output document trailer. */ if (html) {
fputs("
\n", out); fputs("\n", out); fputs("\n", out); if
(chap != NULL) { endchap(basename, chapno, 1, chap); } if (foot != NULL) {
fputs("\n", foot); fputs("\n", foot); fclose(foot); } } else {
fputs("\\end{document}\n", out); } fclose(out); return 0; } End of The Project
Gutenberg Etext of Tour Du Mond 80 Jours by Jules Verne