diff options
Diffstat (limited to 'web/nuweb/nuweb0.87b/html.c')
-rw-r--r-- | web/nuweb/nuweb0.87b/html.c | 335 |
1 files changed, 335 insertions, 0 deletions
diff --git a/web/nuweb/nuweb0.87b/html.c b/web/nuweb/nuweb0.87b/html.c new file mode 100644 index 0000000000..b48a61e95e --- /dev/null +++ b/web/nuweb/nuweb0.87b/html.c @@ -0,0 +1,335 @@ +#include "global.h" +static void copy_scrap(); /* formats the body of a scrap */ +static void display_scrap_ref(); /* formats a scrap reference */ +static void display_scrap_numbers(); /* formats a list of scrap numbers */ +static void print_scrap_numbers(); /* pluralizes scrap formats list */ +static void format_entry(); /* formats an index entry */ +static void format_user_entry(); +void write_html(file_name, html_name) + char *file_name; + char *html_name; +{ + FILE *html_file = fopen(html_name, "w"); + if (html_file) { + if (verbose_flag) + fprintf(stderr, "writing %s\n", html_name); + source_open(file_name); + { + int scraps = 1; + int c = source_get(); + while (c != EOF) { + if (c == '@') + { + c = source_get(); + switch (c) { + case 'O': + case 'o': { + Name *name = collect_file_name(); + { + fputs("\\begin{rawhtml}\n", html_file); + fputs("<pre>\n", html_file); + } + fputs("<a name=\"nuweb", html_file); + write_single_scrap_ref(html_file, scraps); + fprintf(html_file, "\"><code>\"%s\"</code> ", name->spelling); + write_single_scrap_ref(html_file, scraps); + fputs("</a> =\n", html_file); + + scraps++; + { + copy_scrap(html_file); + fputs("<></pre>\n", html_file); + } + { + if (name->defs->next) { + fputs("File defined by ", html_file); + print_scrap_numbers(html_file, name->defs); + fputs("<br>\n", html_file); + } + } + { + fputs("\\end{rawhtml}\n", html_file); + c = source_get(); /* Get rid of current at command. */ + } + } + break; + case 'D': + case 'd': { + Name *name = collect_macro_name(); + { + fputs("\\begin{rawhtml}\n", html_file); + fputs("<pre>\n", html_file); + } + fputs("<a name=\"nuweb", html_file); + write_single_scrap_ref(html_file, scraps); + fprintf(html_file, "\"><%s ", name->spelling); + write_single_scrap_ref(html_file, scraps); + fputs("></a> =\n", html_file); + + scraps++; + { + copy_scrap(html_file); + fputs("<></pre>\n", html_file); + } + { + if (name->defs->next) { + fputs("Macro defined by ", html_file); + print_scrap_numbers(html_file, name->defs); + fputs("<br>\n", html_file); + } + } + { + if (name->uses) { + fputs("Macro referenced in ", html_file); + print_scrap_numbers(html_file, name->uses); + } + else { + fputs("Macro never referenced.\n", html_file); + fprintf(stderr, "%s: <%s> never referenced.\n", + command_name, name->spelling); + } + fputs("<br>\n", html_file); + } + { + fputs("\\end{rawhtml}\n", html_file); + c = source_get(); /* Get rid of current at command. */ + } + } + break; + case 'f': { + if (file_names) { + fputs("\\begin{rawhtml}\n", html_file); + fputs("<dl compact>\n", html_file); + format_entry(file_names, html_file, TRUE); + fputs("</dl>\n", html_file); + fputs("\\end{rawhtml}\n", html_file); + } + c = source_get(); + } + break; + case 'm': { + if (macro_names) { + fputs("\\begin{rawhtml}\n", html_file); + fputs("<dl compact>\n", html_file); + format_entry(macro_names, html_file, FALSE); + fputs("</dl>\n", html_file); + fputs("\\end{rawhtml}\n", html_file); + } + c = source_get(); + } + break; + case 'u': { + if (user_names) { + fputs("\\begin{rawhtml}\n", html_file); + fputs("<dl compact>\n", html_file); + format_user_entry(user_names, html_file); + fputs("</dl>\n", html_file); + fputs("\\end{rawhtml}\n", html_file); + } + c = source_get(); + } + break; + case '@': putc(c, html_file); + default: c = source_get(); + break; + } + } + else { + putc(c, html_file); + c = source_get(); + } + } + } + fclose(html_file); + } + else + fprintf(stderr, "%s: can't open %s\n", command_name, html_name); +} +static void display_scrap_ref(html_file, num) + FILE *html_file; + int num; +{ + fputs("<a href=\"#nuweb", html_file); + write_single_scrap_ref(html_file, num); + fputs("\">", html_file); + write_single_scrap_ref(html_file, num); + fputs("</a>", html_file); +} +static void display_scrap_numbers(html_file, scraps) + FILE *html_file; + Scrap_Node *scraps; +{ + display_scrap_ref(html_file, scraps->scrap); + scraps = scraps->next; + while (scraps) { + fputs(", ", html_file); + display_scrap_ref(html_file, scraps->scrap); + scraps = scraps->next; + } +} +static void print_scrap_numbers(html_file, scraps) + FILE *html_file; + Scrap_Node *scraps; +{ + fputs("scrap", html_file); + if (scraps->next) fputc('s', html_file); + fputc(' ', html_file); + display_scrap_numbers(html_file, scraps); + fputs(".\n", html_file); +} +static void copy_scrap(file) + FILE *file; +{ + int indent = 0; + int c = source_get(); + while (1) { + switch (c) { + case '@': { + c = source_get(); + switch (c) { + case '@': fputc(c, file); + break; + case '|': { + do { + do + c = source_get(); + while (c != '@'); + c = source_get(); + } while (c != '}'); + } + case '}': return; + case '<': { + Name *name = collect_scrap_name(); + fprintf(file, "<%s ", name->spelling); + if (name->defs) + { + Scrap_Node *p = name->defs; + display_scrap_ref(file, p->scrap); + if (p->next) + fputs(", ... ", file); + } + else { + putc('?', file); + fprintf(stderr, "%s: scrap never defined <%s>\n", + command_name, name->spelling); + } + fputs(">", file); + } + break; + default: /* ignore these since pass1 will have warned about them */ + break; + } + } + break; + case '<' : fputs("<", file); + indent++; + break; + case '>' : fputs(">", file); + indent++; + break; + case '&' : fputs("&", file); + indent++; + break; + case '\n': fputc(c, file); + indent = 0; + break; + case '\t': { + int delta = 8 - (indent % 8); + indent += delta; + while (delta > 0) { + putc(' ', file); + delta--; + } + } + break; + default: putc(c, file); + indent++; + break; + } + c = source_get(); + } +} +static void format_entry(name, html_file, file_flag) + Name *name; + FILE *html_file; + int file_flag; +{ + while (name) { + format_entry(name->llink, html_file, file_flag); + { + fputs("<dt> ", html_file); + if (file_flag) { + fprintf(html_file, "<code>\"%s\"</code>\n<dd> ", name->spelling); + { + fputs("Defined by ", html_file); + print_scrap_numbers(html_file, name->defs); + } + } + else { + fprintf(html_file, "<%s ", name->spelling); + { + if (name->defs) + display_scrap_numbers(html_file, name->defs); + else + putc('?', html_file); + } + fputs(">\n<dd> ", html_file); + { + Scrap_Node *p = name->uses; + if (p) { + fputs("Referenced in ", html_file); + print_scrap_numbers(html_file, p); + } + else + fputs("Not referenced.\n", html_file); + } + } + putc('\n', html_file); + } + name = name->rlink; + } +} +static void format_user_entry(name, html_file) + Name *name; + FILE *html_file; +{ + while (name) { + format_user_entry(name->llink, html_file); + { + Scrap_Node *uses = name->uses; + if (uses) { + Scrap_Node *defs = name->defs; + fprintf(html_file, "<dt><code>%s</code>:\n<dd> ", name->spelling); + if (uses->scrap < defs->scrap) { + display_scrap_ref(html_file, uses->scrap); + uses = uses->next; + } + else { + if (defs->scrap == uses->scrap) + uses = uses->next; + fputs("<strong>", html_file); + display_scrap_ref(html_file, defs->scrap); + fputs("</strong>", html_file); + defs = defs->next; + } + while (uses || defs) { + fputs(", ", html_file); + if (uses && (!defs || uses->scrap < defs->scrap)) { + display_scrap_ref(html_file, uses->scrap); + uses = uses->next; + } + else { + if (uses && defs->scrap == uses->scrap) + uses = uses->next; + fputs("<strong>", html_file); + display_scrap_ref(html_file, defs->scrap); + fputs("</strong>", html_file); + defs = defs->next; + } + } + fputs(".\n", html_file); + } + } + name = name->rlink; + } +} |