diff --git a/arena.c b/arena.c index 13c46ad..16529b8 100644 --- a/arena.c +++ b/arena.c @@ -1,13 +1,20 @@ + +#line 938 "nuweb.w" #include "global.h" + +#line 6512 "nuweb.w" typedef struct chunk { struct chunk *next; char *limit; char *avail; } Chunk; + +#line 6526 "nuweb.w" static Chunk first = { NULL, NULL, NULL }; static Chunk *arena = &first; -void *arena_getmem(n) - size_t n; + +#line 6540 "nuweb.w" +void *arena_getmem(size_t n) { char *q; char *p = arena->avail; @@ -18,6 +25,8 @@ void *arena_getmem(n) return p; } /* Find a new chunk of memory */ + +#line 6561 "nuweb.w" { Chunk *ap = arena; Chunk *np = ap->next; @@ -32,6 +41,8 @@ void *arena_getmem(n) np = ap->next; } /* Allocate a new chunk of memory */ + +#line 6581 "nuweb.w" { size_t m = n + 10000; np = (Chunk *) malloc(m); @@ -42,9 +53,15 @@ void *arena_getmem(n) arena = np; return sizeof(Chunk) + (char *) np; } +#line 6574 "nuweb.w" + } +#line 6550 "nuweb.w" + } -void arena_free() + +#line 6598 "nuweb.w" +void arena_free(void) { arena = &first; } diff --git a/global.c b/global.c index 54db28a..3b50fa7 100644 --- a/global.c +++ b/global.c @@ -1,6 +1,10 @@ + +#line 944 "nuweb.w" #include "global.h" /* Operating System Dependencies */ +#line 972 "nuweb.w" + #if defined(VMS) #define PATH_SEP(c) (c==']'||c==':') #define PATH_SEP_CHAR "" @@ -15,7 +19,11 @@ #define DEFAULT_PATH "." #endif +#line 945 "nuweb.w" + /* Global variable definitions */ + +#line 1067 "nuweb.w" int tex_flag = TRUE; int html_flag = FALSE; int output_flag = TRUE; @@ -38,19 +46,39 @@ char * hyperoptions = ""; int includepath_flag = FALSE; /* Do we have an include path? */ struct incl * include_list = NULL; /* The list of include paths */ + +#line 1097 "nuweb.w" int nw_char='@'; + +#line 1108 "nuweb.w" char *command_name = NULL; + +#line 1510 "nuweb.w" unsigned char current_sector = 1; unsigned char prev_sector = 1; + +#line 1707 "nuweb.w" char blockBuff[6400]; + +#line 2422 "nuweb.w" int extra_scraps = 0; - char *source_name = NULL; + +#line 3906 "nuweb.w" +char *source_name = NULL; int source_line = 0; + +#line 4241 "nuweb.w" int already_warned = 0; + +#line 5108 "nuweb.w" Name *file_names = NULL; Name *macro_names = NULL; Name *user_names = NULL; int scrap_name_has_parameters; int scrap_ended_with; +#line 946 "nuweb.w" + + +#line 6478 "nuweb.w" label_node * label_tab = NULL; diff --git a/global.h b/global.h index 69608a5..1df537c 100644 --- a/global.h +++ b/global.h @@ -1,5 +1,9 @@ + +#line 826 "nuweb.w" /* Include files */ +#line 835 "nuweb.w" + #include #include #include @@ -7,7 +11,11 @@ #include #include +#line 826 "nuweb.w" + /* Type declarations */ + +#line 854 "nuweb.w" #ifndef FALSE #define FALSE 0 #endif @@ -15,12 +23,21 @@ #define TRUE 1 #endif +#line 1815 "nuweb.w" +typedef int *Parameters; + +#line 3784 "nuweb.w" + #define MAX_INDENT 500 + +#line 5074 "nuweb.w" typedef struct scrap_node { struct scrap_node *next; int scrap; char quoted; } Scrap_Node; + +#line 5083 "nuweb.w" typedef struct name { char *spelling; struct name *llink; @@ -35,20 +52,30 @@ typedef struct name { unsigned char comment_flag; unsigned char sector; } Name; + +#line 5536 "nuweb.w" #define ARG_CHR '\001' + +#line 5596 "nuweb.w" typedef struct arglist {Name * name; struct arglist * args; struct arglist * next; } Arglist; + +#line 5760 "nuweb.w" typedef struct embed { Scrap_Node * defs; Arglist * args; } Embed_Node; + +#line 6240 "nuweb.w" typedef struct uses { struct uses *next; Name *defn; } Uses; + +#line 6482 "nuweb.w" typedef struct l_node { struct l_node * left, * right; @@ -56,13 +83,21 @@ typedef struct l_node char name[1]; } label_node; +#line 827 "nuweb.w" + /* Limits */ +#line 864 "nuweb.w" + #ifndef MAX_NAME_LEN #define MAX_NAME_LEN 1024 #endif +#line 828 "nuweb.w" + /* Global variable declarations */ + +#line 1036 "nuweb.w" extern int tex_flag; /* if FALSE, don't emit the documentation file */ extern int html_flag; /* if TRUE, emit HTML instead of LaTeX scraps. */ extern int output_flag; /* if FALSE, don't emit the output files */ @@ -86,62 +121,135 @@ extern char * hyperoptions; /* The options to pass to the extern int includepath_flag; /* Do we have an include path? */ extern struct incl{char * name; struct incl * next;} * include_list; /* The list of include paths */ + +#line 1094 "nuweb.w" extern int nw_char; + +#line 1104 "nuweb.w" extern char *command_name; + +#line 1505 "nuweb.w" extern unsigned char current_sector; extern unsigned char prev_sector; + +#line 1703 "nuweb.w" extern char blockBuff[6400]; + +#line 2418 "nuweb.w" extern int extra_scraps; + +#line 3901 "nuweb.w" extern char *source_name; /* name of the current file */ extern int source_line; /* current line in the source file */ + +#line 4237 "nuweb.w" extern int already_warned; + +#line 5100 "nuweb.w" extern Name *file_names; extern Name *macro_names; extern Name *user_names; extern int scrap_name_has_parameters; extern int scrap_ended_with; + +#line 6491 "nuweb.w" extern label_node * label_tab; +#line 829 "nuweb.w" + /* Function prototypes */ -extern void pass1(); -extern void write_tex(); + +#line 1400 "nuweb.w" +extern void pass1(char *file_name); + +#line 2034 "nuweb.w" +extern void write_tex(char *file_name, char *tex_name); + +#line 2582 "nuweb.w" void initialise_delimit_scrap_array(void); + +#line 2676 "nuweb.w" void update_delimit_scrap(); + +#line 3100 "nuweb.w" extern int has_sector(Name *, unsigned char); -extern void write_html(); -extern void write_files(); -extern void source_open(); /* pass in the name of the source file */ -extern int source_get(); /* no args; returns the next char or EOF */ + +#line 3227 "nuweb.w" +extern void write_html(char *file_name, char *html_name); + +#line 3764 "nuweb.w" +extern void write_files(Name *files); + +#line 3889 "nuweb.w" +extern void source_open(char *name); + /* pass in the name of the source file */ +extern int source_get(void); + /* no args; returns the next char or EOF */ extern int source_last; /* what last source_get() returned. */ extern int source_peek; /* The next character to get */ + +#line 3964 "nuweb.w" extern void source_ungetc(int*); -extern void init_scraps(); -extern int collect_scrap(); -extern int write_scraps(); -extern void write_scrap_ref(); -extern void write_single_scrap_ref(); -extern int num_scraps(); + +#line 4173 "nuweb.w" +extern void init_scraps(void); +extern int collect_scrap(void); +extern int write_scraps(FILE *file, char *spelling, Scrap_Node *defs, + int global_indent, char *indent_chars, + char debug_flag, char tab_flag, char indent_flag, + unsigned char comment_flag, Arglist *inArgs, + char *inParams[9], Parameters parameters, + char *title); +extern void write_scrap_ref(FILE *file, int num, int first, int *page); +extern void write_single_scrap_ref(FILE *file, int num); +extern int num_scraps(void); + +#line 4501 "nuweb.w" extern void add_to_use(Name * name, int current_scrap); -Arglist * instance(); -extern void collect_numbers(); -extern Name *collect_file_name(); -extern Name *collect_macro_name(); -extern Arglist *collect_scrap_name(); -extern Name *name_add(); -extern Name *prefix_add(); -extern char *save_string(); -extern void reverse_lists(); + +#line 4575 "nuweb.w" +extern Arglist *instance(Arglist *a, Arglist *par, char *arg[9], int *ch); + +#line 4984 "nuweb.w" +extern void collect_numbers(char *aux_name); + +#line 5116 "nuweb.w" +extern Name *collect_file_name(void); +extern Name *collect_macro_name(void); +extern Arglist *collect_scrap_name(int current_scrap); +extern Name *name_add(Name **rt, char *spelling, unsigned char sector); +extern Name *prefix_add(Name **rt, char *spelling, unsigned char sector); +extern char *save_string(char *); +extern void reverse_lists(Name *names); + +#line 5260 "nuweb.w" extern int robs_strcmp(char*, char*); -extern Name *install_args(); -extern void search(); + +#line 5579 "nuweb.w" +extern Name *install_args(Name * name, int argc, char *arg[0]); + +#line 6000 "nuweb.w" +extern void search(void); + +#line 6247 "nuweb.w" extern void format_uses_refs(FILE *, int); + +#line 6302 "nuweb.w" extern void format_defs_refs(FILE *, int); + +#line 6413 "nuweb.w" void write_label(char label_name[], FILE * file); -extern void *arena_getmem(); -extern void arena_free(); + +#line 6506 "nuweb.w" +extern void *arena_getmem(size_t n); +extern void arena_free(void); + +#line 830 "nuweb.w" /* Operating System Dependencies */ +#line 972 "nuweb.w" + #if defined(VMS) #define PATH_SEP(c) (c==']'||c==':') #define PATH_SEP_CHAR "" @@ -155,4 +263,5 @@ extern void arena_free(); #define PATH_SEP_CHAR "/" #define DEFAULT_PATH "." #endif -typedef int *Parameters; + +#line 831 "nuweb.w" diff --git a/html.c b/html.c index dcd35ed..ef6e924 100644 --- a/html.c +++ b/html.c @@ -1,14 +1,17 @@ #include "global.h" static int scraps = 1; -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; +static void copy_scrap(FILE *file, int prefix); + /* formats the body of a scrap */ +static void display_scrap_ref(FILE *html_file, int num); + /* formats a scrap reference */ +static void display_scrap_numbers(FILE *html_file, Scrap_Node *scraps); + /* formats a list of scrap numbers */ +static void print_scrap_numbers(FILE *html_file, Scrap_Node *scraps); + /* pluralizes scrap formats list */ +static void format_entry(Name *name, FILE *html_file, int file_flag); + /* formats an index entry */ +static void format_user_entry(Name *name, FILE *html_file, int sector); +void write_html(char *file_name, char *html_name) { FILE *html_file = fopen(html_name, "w"); FILE *tex_file = html_file; @@ -183,9 +186,7 @@ void write_html(file_name, html_name) 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; +static void display_scrap_ref(FILE *html_file, int num) { fputs("", html_file); } -static void display_scrap_numbers(html_file, scraps) - FILE *html_file; - Scrap_Node *scraps; +static void display_scrap_numbers(FILE *html_file, Scrap_Node *scraps) { display_scrap_ref(html_file, scraps->scrap); scraps = scraps->next; @@ -205,16 +204,12 @@ static void display_scrap_numbers(html_file, scraps) scraps = scraps->next; } } -static void print_scrap_numbers(html_file, scraps) - FILE *html_file; - Scrap_Node *scraps; +static void print_scrap_numbers(FILE *html_file, Scrap_Node *scraps) { display_scrap_numbers(html_file, scraps); fputs(".\n", html_file); } -static void copy_scrap(file, prefix) - FILE *file; - int prefix; +static void copy_scrap(FILE *file, int prefix) { int indent = 0; int c = source_get(); @@ -353,10 +348,7 @@ static void copy_scrap(file, prefix) c = source_get(); } } -static void format_entry(name, html_file, file_flag) - Name *name; - FILE *html_file; - int file_flag; +static void format_entry(Name *name, FILE *html_file, int file_flag) { while (name) { format_entry(name->llink, html_file, file_flag); @@ -395,10 +387,7 @@ static void format_entry(name, html_file, file_flag) name = name->rlink; } } -static void format_user_entry(name, html_file, sector) - Name *name; - FILE *html_file; - int sector; +static void format_user_entry(Name *name, FILE *html_file, int sector) { while (name) { format_user_entry(name->llink, html_file, sector); diff --git a/input.c b/input.c index 5975e48..ca9d3e6 100644 --- a/input.c +++ b/input.c @@ -1,21 +1,31 @@ + +#line 919 "nuweb.w" #include "global.h" + +#line 3914 "nuweb.w" static FILE *source_file; /* the current input file */ static int double_at; static int include_depth; + +#line 3921 "nuweb.w" static struct { FILE *file; char *name; int line; } stack[10]; +#line 3938 "nuweb.w" + int source_peek; int source_last; -int source_get() +int source_get(void) { int c; source_last = c = source_peek; switch (c) { - case EOF: { + case EOF: +#line 4088 "nuweb.w" + { fclose(source_file); if (include_depth) { include_depth--; @@ -26,12 +36,16 @@ int source_get() c = source_get(); } } +#line 3946 "nuweb.w" + return c; case '\n': source_line++; default: if (c==nw_char) { /* Handle an ``at'' character */ + +#line 3985 "nuweb.w" { c = getc(source_file); if (double_at) { @@ -41,7 +55,9 @@ int source_get() } else switch (c) { - case 'i': { + case 'i': +#line 4027 "nuweb.w" + { char name[FILENAME_MAX]; char fullname[FILENAME_MAX]; struct incl * p = include_list; @@ -52,6 +68,8 @@ int source_get() exit(-1); } /* Collect include-file name */ + +#line 4067 "nuweb.w" { char *p = name; do @@ -68,6 +86,8 @@ int source_get() exit(-1); } } +#line 4037 "nuweb.w" + stack[include_depth].file = source_file; fullname[0] = '\0'; for (;;) { @@ -95,6 +115,8 @@ int source_get() source_peek = getc(source_file); c = source_get(); } +#line 3994 "nuweb.w" + break; case '#': case 'f': case 'm': case 'u': case 'v': case 'd': case 'o': case 'D': case 'O': case 's': @@ -125,12 +147,16 @@ int source_get() exit(-1); } } +#line 3952 "nuweb.w" + return c; } source_peek = getc(source_file); return c; } } + +#line 3969 "nuweb.w" void source_ungetc(int *c) { ungetc(source_peek, source_file); @@ -138,8 +164,9 @@ void source_ungetc(int *c) source_line--; source_peek=*c; } -void source_open(name) - char *name; + +#line 4107 "nuweb.w" +void source_open(char *name) { source_file = fopen(name, "r"); if (!source_file) { diff --git a/latex.c b/latex.c index baf2b94..19df15c 100644 --- a/latex.c +++ b/latex.c @@ -1,17 +1,25 @@ + +#line 893 "nuweb.w" #include "global.h" static int scraps = 1; -static void copy_scrap(); /* formats the body of a scrap */ -static void print_scrap_numbers(); /* formats a list of scrap numbers */ -static void format_entry(); /* formats an index entry */ -static void format_file_entry(); /* formats a file index entry */ -static void format_user_entry(); -static void write_arg(); -static void write_literal(); -static void write_ArglistElement(); -void write_tex(file_name, tex_name, sector) - char *file_name; - char *tex_name; - unsigned char sector; + +#line 2041 "nuweb.w" +static void copy_scrap(FILE *file, int prefix, Name *name); + /* formats the body of a scrap */ +static void print_scrap_numbers(FILE *tex_file, Scrap_Node *scraps); + /* formats a list of scrap numbers */ +static void format_entry(Name *name, FILE *tex_file, unsigned char sector); + /* formats an index entry */ +static void format_file_entry(Name *name, FILE *tex_file); + /* formats a file index entry */ +static void format_user_entry(Name *name, FILE *tex_file, + unsigned char sector); +static void write_arg(FILE *tex_file, char *p); +static void write_literal(FILE *tex_file, char *p, int mode); +static void write_ArglistElement(FILE *file, Arglist *args, char **params); + +#line 2060 "nuweb.w" +void write_tex(char *file_name, char *tex_name) { FILE *tex_file = fopen(tex_name, "w"); if (tex_file) { @@ -19,6 +27,8 @@ void write_tex(file_name, tex_name, sector) fprintf(stderr, "writing %s\n", tex_name); source_open(file_name); /* Write LaTeX limbo definitions */ + +#line 2084 "nuweb.w" if (hyperref_flag) { fputs("\\newcommand{\\NWtarget}[2]{\\hypertarget{#1}{#2}}\n", tex_file); fputs("\\newcommand{\\NWlink}[2]{\\hyperlink{#1}{#2}}\n", tex_file); @@ -42,11 +52,19 @@ void write_tex(file_name, tex_name, sector) if (hyperoptions[0] != '\0') { /* Write the hyperlink usage macro */ + +#line 2112 "nuweb.w" fprintf(tex_file, "\\usepackage[%s]{hyperref}", hyperoptions); +#line 2106 "nuweb.w" + } fputs("}\n", tex_file); +#line 2067 "nuweb.w" + /* Copy \verb|source_file| into \verb|tex_file| */ + +#line 2119 "nuweb.w" { int inBlock = FALSE; int c = source_get(); @@ -54,6 +72,8 @@ void write_tex(file_name, tex_name, sector) if (c == nw_char) { /* Interpret at-sequence */ + +#line 2135 "nuweb.w" { int big_definition = FALSE; c = source_get(); @@ -64,18 +84,26 @@ void write_tex(file_name, tex_name, sector) update_delimit_scrap(); break; case 'O': big_definition = TRUE; - case 'o': { + case 'o': +#line 2259 "nuweb.w" + { Name *name = collect_file_name(); /* Begin the scrap environment */ + +#line 2346 "nuweb.w" { if (big_definition) { if (inBlock) { /* End block */ + +#line 2377 "nuweb.w" fputs("\\end{minipage}\\vspace{4ex}\n", tex_file); fputs("\\end{flushleft}\n", tex_file); inBlock = FALSE; +#line 2351 "nuweb.w" + } fputs("\\begin{flushleft} \\small", tex_file); } @@ -84,17 +112,27 @@ void write_tex(file_name, tex_name, sector) if (inBlock) { /* Switch block */ + +#line 2374 "nuweb.w" fputs("\\par\\vspace{\\baselineskip}\n", tex_file); +#line 2359 "nuweb.w" + } else { /* Start block */ + +#line 2370 "nuweb.w" fputs("\\begin{flushleft} \\small\n\\begin{minipage}{\\linewidth}", tex_file); inBlock = TRUE; +#line 2363 "nuweb.w" + } } fprintf(tex_file, "\\label{scrap%d}\\raggedright\\small\n", scraps); } +#line 2261 "nuweb.w" + fputs("\\NWtarget{nuweb", tex_file); write_single_scrap_ref(tex_file, scraps); fputs("}{} ", tex_file); @@ -102,13 +140,19 @@ void write_tex(file_name, tex_name, sector) write_single_scrap_ref(tex_file, scraps); fputs("}}$\\equiv$\n", tex_file); /* Fill in the middle of the scrap environment */ + +#line 2387 "nuweb.w" { fputs("\\vspace{-1ex}\n\\begin{list}{}{} \\item\n", tex_file); extra_scraps = 0; copy_scrap(tex_file, TRUE, name); fputs("{\\NWsep}\n\\end{list}\n", tex_file); } +#line 2268 "nuweb.w" + /* Begin the cross-reference environment */ + +#line 2433 "nuweb.w" { fputs("\\vspace{-1.5ex}\n", tex_file); fputs("\\footnotesize\n", tex_file); @@ -116,8 +160,12 @@ void write_tex(file_name, tex_name, sector) tex_file); fputs("\\setlength{\\itemindent}{-\\leftmargin}}\n", tex_file);} +#line 2269 "nuweb.w" + if ( scrap_flag ) { /* Write file defs */ + +#line 2452 "nuweb.w" { if (name->defs) { if (name->defs->next) { @@ -130,15 +178,23 @@ void write_tex(file_name, tex_name, sector) name->spelling); } } +#line 2271 "nuweb.w" + } format_defs_refs(tex_file, scraps); format_uses_refs(tex_file, scraps++); /* Finish the cross-reference environment */ + +#line 2446 "nuweb.w" { fputs("\n\\item{}", tex_file); fputs("\n\\end{list}\n", tex_file); } +#line 2275 "nuweb.w" + /* Finish the scrap environment */ + +#line 2404 "nuweb.w" { scraps += extra_scraps; if (big_definition) @@ -146,32 +202,48 @@ void write_tex(file_name, tex_name, sector) else { /* End block */ + +#line 2377 "nuweb.w" fputs("\\end{minipage}\\vspace{4ex}\n", tex_file); fputs("\\end{flushleft}\n", tex_file); inBlock = FALSE; +#line 2410 "nuweb.w" + } do c = source_get(); while (isspace(c)); } +#line 2276 "nuweb.w" + } +#line 2145 "nuweb.w" + break; case 'Q': case 'D': big_definition = TRUE; case 'q': - case 'd': { + case 'd': +#line 2284 "nuweb.w" + { Name *name = collect_macro_name(); /* Begin the scrap environment */ + +#line 2346 "nuweb.w" { if (big_definition) { if (inBlock) { /* End block */ + +#line 2377 "nuweb.w" fputs("\\end{minipage}\\vspace{4ex}\n", tex_file); fputs("\\end{flushleft}\n", tex_file); inBlock = FALSE; +#line 2351 "nuweb.w" + } fputs("\\begin{flushleft} \\small", tex_file); } @@ -180,21 +252,33 @@ void write_tex(file_name, tex_name, sector) if (inBlock) { /* Switch block */ + +#line 2374 "nuweb.w" fputs("\\par\\vspace{\\baselineskip}\n", tex_file); +#line 2359 "nuweb.w" + } else { /* Start block */ + +#line 2370 "nuweb.w" fputs("\\begin{flushleft} \\small\n\\begin{minipage}{\\linewidth}", tex_file); inBlock = TRUE; +#line 2363 "nuweb.w" + } } fprintf(tex_file, "\\label{scrap%d}\\raggedright\\small\n", scraps); } +#line 2287 "nuweb.w" + fputs("\\NWtarget{nuweb", tex_file); write_single_scrap_ref(tex_file, scraps); fputs("}{} $\\langle\\,${\\itshape ", tex_file); /* Write the macro's name */ + +#line 2306 "nuweb.w" { char * p = name->spelling; int i = 0; @@ -208,17 +292,25 @@ void write_tex(file_name, tex_name, sector) fputc(*p++, tex_file); } } +#line 2291 "nuweb.w" + fputs("}\\nobreak\\ {\\footnotesize {", tex_file); write_single_scrap_ref(tex_file, scraps); fputs("}}$\\,\\rangle\\equiv$\n", tex_file); /* Fill in the middle of the scrap environment */ + +#line 2387 "nuweb.w" { fputs("\\vspace{-1ex}\n\\begin{list}{}{} \\item\n", tex_file); extra_scraps = 0; copy_scrap(tex_file, TRUE, name); fputs("{\\NWsep}\n\\end{list}\n", tex_file); } +#line 2295 "nuweb.w" + /* Begin the cross-reference environment */ + +#line 2433 "nuweb.w" { fputs("\\vspace{-1.5ex}\n", tex_file); fputs("\\footnotesize\n", tex_file); @@ -226,14 +318,22 @@ void write_tex(file_name, tex_name, sector) tex_file); fputs("\\setlength{\\itemindent}{-\\leftmargin}}\n", tex_file);} +#line 2296 "nuweb.w" + /* Write macro defs */ + +#line 2466 "nuweb.w" { if (name->defs->next) { fputs("\\item \\NWtxtMacroDefBy\\ ", tex_file); print_scrap_numbers(tex_file, name->defs); } } +#line 2297 "nuweb.w" + /* Write macro refs */ + +#line 2474 "nuweb.w" { if (name->uses) { if (name->uses->next) { @@ -256,14 +356,22 @@ void write_tex(file_name, tex_name, sector) command_name, name->spelling); } } +#line 2298 "nuweb.w" + format_defs_refs(tex_file, scraps); format_uses_refs(tex_file, scraps++); /* Finish the cross-reference environment */ + +#line 2446 "nuweb.w" { fputs("\n\\item{}", tex_file); fputs("\n\\end{list}\n", tex_file); } +#line 2301 "nuweb.w" + /* Finish the scrap environment */ + +#line 2404 "nuweb.w" { scraps += extra_scraps; if (big_definition) @@ -271,37 +379,59 @@ void write_tex(file_name, tex_name, sector) else { /* End block */ + +#line 2377 "nuweb.w" fputs("\\end{minipage}\\vspace{4ex}\n", tex_file); fputs("\\end{flushleft}\n", tex_file); inBlock = FALSE; +#line 2410 "nuweb.w" + } do c = source_get(); while (isspace(c)); } +#line 2302 "nuweb.w" + } +#line 2150 "nuweb.w" + break; case 's': /* Step to next sector */ +#line 1493 "nuweb.w" + prev_sector += 1; current_sector = prev_sector; c = source_get(); +#line 2153 "nuweb.w" + break; case 'S': /* Close the current sector */ + +#line 1500 "nuweb.w" current_sector = 1; c = source_get(); +#line 2156 "nuweb.w" + break; case '{': case '[': - case '(': copy_scrap(tex_file, FALSE, NULL); + case '(': +#line 2426 "nuweb.w" + copy_scrap(tex_file, FALSE, NULL); c = source_get(); +#line 2160 "nuweb.w" + break; - case '<': { + case '<': +#line 2192 "nuweb.w" + { Parameters local_parameters = 0; int changed; char indent_chars[MAX_INDENT]; @@ -318,36 +448,66 @@ void write_tex(file_name, tex_name, sector) c = source_get(); } +#line 2162 "nuweb.w" + break; - case 'x': { + case 'x': +#line 2749 "nuweb.w" + { /* Get label from */ + +#line 6398 "nuweb.w" char label_name[MAX_NAME_LEN]; char * p = label_name; - while (c = source_get(), c != nw_char) /* Here is 150a-01 */ + while (c = +#line 2750 "nuweb.w" + source_get(), c != nw_char) /* Here is 148c-01 */ *p++ = c; *p = '\0'; - c = source_get(); + c = +#line 2750 "nuweb.w" + source_get(); - write_label(label_name, tex_file); +#line 2750 "nuweb.w" + + write_label(label_name, +#line 2164 "nuweb.w" + tex_file); } +#line 2164 "nuweb.w" + c = source_get(); break; - case 'c': if (inBlock) + case 'c': +#line 1785 "nuweb.w" + if (inBlock) { /* End block */ + +#line 2377 "nuweb.w" fputs("\\end{minipage}\\vspace{4ex}\n", tex_file); fputs("\\end{flushleft}\n", tex_file); inBlock = FALSE; +#line 1787 "nuweb.w" + } else { /* Start block */ + +#line 2370 "nuweb.w" fputs("\\begin{flushleft} \\small\n\\begin{minipage}{\\linewidth}", tex_file); inBlock = TRUE; +#line 1791 "nuweb.w" + } +#line 2167 "nuweb.w" + c = source_get(); break; - case 'f': { + case 'f': +#line 2915 "nuweb.w" + { if (file_names) { fputs("\n{\\small\\begin{list}{}{\\setlength{\\itemsep}{-\\parsep}", tex_file); @@ -357,8 +517,12 @@ void write_tex(file_name, tex_name, sector) } c = source_get(); } +#line 2170 "nuweb.w" + break; - case 'm': { + case 'm': +#line 2965 "nuweb.w" + { unsigned char sector = current_sector; int c = source_get(); if (c == '+') @@ -377,8 +541,12 @@ void write_tex(file_name, tex_name, sector) } c = source_get(); +#line 2172 "nuweb.w" + break; - case 'u': { + case 'u': +#line 3118 "nuweb.w" + { unsigned char sector = current_sector; c = source_get(); if (c == '+') { @@ -393,10 +561,16 @@ void write_tex(file_name, tex_name, sector) fputs("\\end{list}}", tex_file); } } +#line 2174 "nuweb.w" + break; - case 'v': fputs(version_string, tex_file); + case 'v': +#line 2187 "nuweb.w" + fputs(version_string, tex_file); c = source_get(); +#line 2176 "nuweb.w" + break; default: if (c==nw_char) @@ -405,6 +579,8 @@ void write_tex(file_name, tex_name, sector) break; } } +#line 2125 "nuweb.w" + } else { putc(c, tex_file); @@ -412,11 +588,15 @@ void write_tex(file_name, tex_name, sector) } } } +#line 2068 "nuweb.w" + fclose(tex_file); } else fprintf(stderr, "%s: can't open %s\n", command_name, tex_name); } + +#line 2321 "nuweb.w" static void write_arg(FILE * tex_file, char * p) { fputs("\\hbox{\\slshape\\sffamily ", tex_file); @@ -439,9 +619,9 @@ static void write_arg(FILE * tex_file, char * p) fputs("\\/}", tex_file); } -static void print_scrap_numbers(tex_file, scraps) - FILE *tex_file; - Scrap_Node *scraps; + +#line 2498 "nuweb.w" +static void print_scrap_numbers(FILE *tex_file, Scrap_Node *scraps) { int page; fputs("\\NWlink{nuweb", tex_file); @@ -460,6 +640,8 @@ static void print_scrap_numbers(tex_file, scraps) } fputs(".\n", tex_file); } + +#line 2535 "nuweb.w" static char *orig_delimit_scrap[3][5] = { /* {} mode: begin, end, insert nw_char, prefix, suffix */ { "\\verb@", "@", "@{\\tt @}\\verb@", "\\mbox{}", "\\\\" }, @@ -470,6 +652,8 @@ static char *orig_delimit_scrap[3][5] = { }; static char *delimit_scrap[3][5]; + +#line 2554 "nuweb.w" void initialise_delimit_scrap_array() { int i,j; for(i = 0; i < 3; i++) { @@ -495,7 +679,11 @@ void initialise_delimit_scrap_array() { } } } + +#line 2586 "nuweb.w" int scrap_type = 0; + +#line 2590 "nuweb.w" static void write_literal(FILE * tex_file, char * p, int mode) { fputs(delimit_scrap[mode][0], tex_file); @@ -508,10 +696,9 @@ static void write_literal(FILE * tex_file, char * p, int mode) } fputs(delimit_scrap[mode][1], tex_file); } -static void copy_scrap(file, prefix, name) - FILE *file; - int prefix; - Name * name; + +#line 2605 "nuweb.w" +static void copy_scrap(FILE *file, int prefix, Name *name) { int indent = 0; int c; @@ -531,7 +718,9 @@ static void copy_scrap(file, prefix, name) fputs(delimit_scrap[scrap_type][0], file); indent = 0; break; - case '\t': { + case '\t': +#line 2680 "nuweb.w" + { int delta = 8 - (indent % 8); indent += delta; while (delta > 0) { @@ -539,41 +728,69 @@ static void copy_scrap(file, prefix, name) delta--; } } +#line 2625 "nuweb.w" + break; default: if (c==nw_char) { /* Check at-sequence for end-of-scrap */ + +#line 2690 "nuweb.w" { c = source_get(); switch (c) { - case 'c': { + case 'c': +#line 1714 "nuweb.w" + { fputs(delimit_scrap[scrap_type][1],file); fprintf(file, "\\hbox{\\sffamily\\slshape (Comment)}"); fputs(delimit_scrap[scrap_type][0], file); } +#line 2693 "nuweb.w" + break; - case 'x': { + case 'x': +#line 2749 "nuweb.w" + { /* Get label from */ + +#line 6398 "nuweb.w" char label_name[MAX_NAME_LEN]; char * p = label_name; - while (c = source_get(), c != nw_char) /* Here is 150a-01 */ + while (c = +#line 2750 "nuweb.w" + source_get(), c != nw_char) /* Here is 148c-01 */ *p++ = c; *p = '\0'; - c = source_get(); + c = +#line 2750 "nuweb.w" + source_get(); - write_label(label_name, file); +#line 2750 "nuweb.w" + + write_label(label_name, +#line 2695 "nuweb.w" + file); } +#line 2695 "nuweb.w" + break; - case 'v': fputs(version_string, file); + case 'v': +#line 2745 "nuweb.w" + fputs(version_string, file); +#line 2697 "nuweb.w" + case 's': break; case '+': case '-': case '*': - case '|': { + case '|': +#line 2758 "nuweb.w" + { do { do c = source_get(); @@ -581,12 +798,16 @@ static void copy_scrap(file, prefix, name) c = source_get(); } while (c != '}' && c != ']' && c != ')' ); } +#line 2703 "nuweb.w" + case ',': case ')': case ']': case '}': fputs(delimit_scrap[scrap_type][1], file); return; - case '<': { + case '<': +#line 2798 "nuweb.w" + { Arglist *args = collect_scrap_name(-1); Name *name = args->name; char * p = name->spelling; @@ -616,6 +837,8 @@ static void copy_scrap(file, prefix, name) if (scrap_name_has_parameters) { /* Format macro parameters */ +#line 1962 "nuweb.w" + char sep; sep = '('; @@ -642,10 +865,14 @@ static void copy_scrap(file, prefix, name) c = source_get(); } +#line 2826 "nuweb.w" + } fprintf(file, "{\\footnotesize "); if (name->defs) /* Write abbreviated definition list */ + +#line 2844 "nuweb.w" { Scrap_Node *p = name->defs; fputs("\\NWlink{nuweb", file); @@ -657,6 +884,8 @@ static void copy_scrap(file, prefix, name) if (p) fputs(", \\ldots\\ ", file); } +#line 2830 "nuweb.w" + else { putc('?', file); fprintf(stderr, "%s: never defined <%s>\n", @@ -667,14 +896,22 @@ static void copy_scrap(file, prefix, name) fputs("}", file); fputs(delimit_scrap[scrap_type][0], file); } +#line 2709 "nuweb.w" + break; - case '%': { + case '%': +#line 2768 "nuweb.w" + { do c = source_get(); while (c != '\n'); } +#line 2711 "nuweb.w" + break; - case '_': { + case '_': +#line 2777 "nuweb.w" + { fputs(delimit_scrap[scrap_type][1],file); fprintf(file, "\\hbox{\\sffamily\\bfseries "); c = source_get(); @@ -686,18 +923,28 @@ static void copy_scrap(file, prefix, name) fprintf(file, "}"); fputs(delimit_scrap[scrap_type][0], file); } +#line 2713 "nuweb.w" + break; - case 't': { + case 't': +#line 2791 "nuweb.w" + { fputs(delimit_scrap[scrap_type][1],file); fprintf(file, "\\hbox{\\sffamily\\slshape fragment title}"); fputs(delimit_scrap[scrap_type][0], file); } +#line 2715 "nuweb.w" + break; - case 'f': { + case 'f': +#line 2791 "nuweb.w" + { fputs(delimit_scrap[scrap_type][1],file); fprintf(file, "\\hbox{\\sffamily\\slshape file name}"); fputs(delimit_scrap[scrap_type][0], file); } +#line 2717 "nuweb.w" + break; case '1': case '2': case '3': case '4': case '5': case '6': @@ -723,6 +970,8 @@ static void copy_scrap(file, prefix, name) break; } } +#line 2630 "nuweb.w" + break; } putc(c, file); @@ -732,6 +981,8 @@ static void copy_scrap(file, prefix, name) c = source_get(); } } + +#line 2646 "nuweb.w" void update_delimit_scrap() { /* {}-mode begin */ @@ -759,6 +1010,8 @@ void update_delimit_scrap() /* ()-mode insert nw_char */ delimit_scrap[2][2][0] = nw_char; } + +#line 2857 "nuweb.w" static void write_ArglistElement(FILE * file, Arglist * args, char ** params) { @@ -801,6 +1054,8 @@ write_ArglistElement(FILE * file, Arglist * args, char ** params) /* Format macro parameters */ +#line 1962 "nuweb.w" + char sep; sep = '('; @@ -827,10 +1082,14 @@ write_ArglistElement(FILE * file, Arglist * args, char ** params) c = source_get(); } +#line 2897 "nuweb.w" + } fprintf(file, "{\\footnotesize "); if (name->defs) /* Write abbreviated definition list */ + +#line 2844 "nuweb.w" { Scrap_Node *p = name->defs; fputs("\\NWlink{nuweb", file); @@ -842,6 +1101,8 @@ write_ArglistElement(FILE * file, Arglist * args, char ** params) if (p) fputs(", \\ldots\\ ", file); } +#line 2901 "nuweb.w" + else { putc('?', file); fprintf(stderr, "%s: never defined <%s>\n", @@ -850,17 +1111,21 @@ write_ArglistElement(FILE * file, Arglist * args, char ** params) fputs("}$\\,\\rangle$", file); } } -static void format_file_entry(name, tex_file) - Name *name; - FILE *tex_file; + +#line 2927 "nuweb.w" +static void format_file_entry(Name *name, FILE *tex_file) { while (name) { format_file_entry(name->llink, tex_file); /* Format a file index entry */ + +#line 2938 "nuweb.w" fputs("\\item ", tex_file); fprintf(tex_file, "\\verb%c\"%s\"%c ", nw_char, name->spelling, nw_char); /* Write file's defining scrap numbers */ - { + +#line 2944 "nuweb.w" + { Scrap_Node *p = name->defs; fputs("{\\footnotesize {\\NWtxtDefBy}", tex_file); if (p->next) { @@ -879,10 +1144,16 @@ static void format_file_entry(name, tex_file) } putc('}', tex_file); } +#line 2940 "nuweb.w" + putc('\n', tex_file); +#line 2931 "nuweb.w" + name = name->rlink; } } + +#line 2986 "nuweb.w" static int load_entry(Name * name, Name ** nms, int n) { while (name) { @@ -892,16 +1163,17 @@ static int load_entry(Name * name, Name ** nms, int n) } return n; } -static void format_entry(name, tex_file, sector) - Name *name; - FILE *tex_file; - unsigned char sector; + +#line 2998 "nuweb.w" +static void format_entry(Name *name, FILE *tex_file, unsigned char sector) { Name ** nms = malloc(num_scraps()*sizeof(Name *)); int n = load_entry(name, nms, 0); int i; /* Sort 'nms' of size 'n' for */ + +#line 3018 "nuweb.w" int j; for (j = 1; j < n; j++) { @@ -912,7 +1184,9 @@ static void format_entry(name, tex_file, sector) { Name * ki = nms[i]; - if (robs_strcmp(ki->spelling, kj->spelling) < 0) + if ( +#line 3015 "nuweb.w" + robs_strcmp(ki->spelling, kj->spelling) < 0) break; nms[i + 1] = ki; i -= 1; @@ -920,15 +1194,21 @@ static void format_entry(name, tex_file, sector) nms[i + 1] = kj; } +#line 3004 "nuweb.w" + for (i = 0; i < n; i++) { Name * name = nms[i]; /* Format an index entry */ + +#line 3038 "nuweb.w" if (name->sector == sector){ fputs("\\item ", tex_file); fputs("$\\langle\\,$", tex_file); /* Write the macro's name */ + +#line 2306 "nuweb.w" { char * p = name->spelling; int i = 0; @@ -942,8 +1222,12 @@ static void format_entry(name, tex_file, sector) fputc(*p++, tex_file); } } +#line 3041 "nuweb.w" + fputs("\\nobreak\\ {\\footnotesize ", tex_file); /* Write defining scrap numbers */ + +#line 3050 "nuweb.w" { Scrap_Node *p = name->defs; if (p) { @@ -966,8 +1250,12 @@ static void format_entry(name, tex_file, sector) else putc('?', tex_file); } +#line 3043 "nuweb.w" + fputs("}$\\,\\rangle$ ", tex_file); /* Write referencing scrap numbers */ + +#line 3074 "nuweb.w" { Scrap_Node *p = name->uses; fputs("{\\footnotesize ", tex_file); @@ -992,10 +1280,16 @@ static void format_entry(name, tex_file, sector) fputs("{\\NWtxtNoRef}.", tex_file); putc('}', tex_file); } +#line 3045 "nuweb.w" + putc('\n', tex_file); } +#line 3009 "nuweb.w" + } } + +#line 3104 "nuweb.w" int has_sector(Name * name, unsigned char sector) { while(name) { @@ -1007,14 +1301,15 @@ int has_sector(Name * name, unsigned char sector) } return FALSE; } -static void format_user_entry(name, tex_file, sector) - Name *name; - FILE *tex_file; - unsigned char sector; + +#line 3136 "nuweb.w" +static void format_user_entry(Name *name, FILE *tex_file, unsigned char sector) { while (name) { format_user_entry(name->llink, tex_file, sector); /* Format a user index entry */ + +#line 3148 "nuweb.w" if (name->sector == sector){ Scrap_Node *uses = name->uses; if ( uses || dangling_flag ) { @@ -1081,6 +1376,8 @@ static void format_user_entry(name, tex_file, sector) fputs(".\n", tex_file); } } +#line 3140 "nuweb.w" + name = name->rlink; } } diff --git a/main.c b/main.c index 7c50281..c26c764 100644 --- a/main.c +++ b/main.c @@ -1,17 +1,25 @@ + +#line 878 "nuweb.w" #include "global.h" +#line 955 "nuweb.w" + #include -int main(argc, argv) - int argc; - char **argv; +int main(int argc, char** argv) { int arg = 1; /* Interpret command-line arguments */ + +#line 1113 "nuweb.w" command_name = argv[0]; + +#line 1119 "nuweb.w" while (arg < argc) { char *s = argv[arg]; if (*s++ == '-') { /* Interpret the argument string \verb|s| */ + +#line 1139 "nuweb.w" { char c = *s++; while (c) { @@ -56,8 +64,12 @@ int main(argc, argv) } HasValue:; } +#line 1122 "nuweb.w" + arg++; /* Perhaps get the prepend path */ + +#line 1186 "nuweb.w" if (prepend_flag) { if (*s == '\0') @@ -66,7 +78,11 @@ HasValue:; prepend_flag = FALSE; } +#line 1124 "nuweb.w" + /* Perhaps get the version info string */ + +#line 1214 "nuweb.w" if (version_info_flag) { if (*s == '\0') @@ -75,7 +91,11 @@ HasValue:; version_info_flag = FALSE; } +#line 1125 "nuweb.w" + /* Perhaps get the hyperref options */ + +#line 1224 "nuweb.w" if (hyperopt_flag) { if (*s == '\0') @@ -85,7 +105,11 @@ HasValue:; hyperref_flag = TRUE; } +#line 1126 "nuweb.w" + /* Perhaps add an include path */ + +#line 1196 "nuweb.w" if (includepath_flag) { struct incl * le @@ -102,11 +126,17 @@ HasValue:; includepath_flag = FALSE; } +#line 1127 "nuweb.w" + } else break; } +#line 960 "nuweb.w" + /* Set locale information */ +#line 1240 "nuweb.w" + { /* try to get locale information */ char *s=getenv("LC_CTYPE"); @@ -118,8 +148,12 @@ HasValue:; fprintf(stderr, "Setting locale failed\n"); } +#line 961 "nuweb.w" + initialise_delimit_scrap_array(); /* Process the remaining arguments (file names) */ + +#line 1259 "nuweb.w" { if (arg >= argc) { fprintf(stderr, "%s: expected a file name. ", command_name); @@ -128,11 +162,15 @@ HasValue:; } do { /* Handle the file name in \verb|argv[arg]| */ + +#line 1281 "nuweb.w" { char source_name[FILENAME_MAX]; char tex_name[FILENAME_MAX]; char aux_name[FILENAME_MAX]; /* Build \verb|source_name| and \verb|tex_name| */ + +#line 1304 "nuweb.w" { char *p = argv[arg]; char *q = source_name; @@ -150,6 +188,8 @@ HasValue:; c = *p++; } /* Add the source path to the include path list */ + +#line 1344 "nuweb.w" if (trim != source_name) { struct incl * le = (struct incl *)arena_getmem(sizeof(struct incl)); @@ -165,6 +205,8 @@ HasValue:; *trim = sv; } +#line 1320 "nuweb.w" + *q = '\0'; if (dot) { *dot = '\0'; /* produce HTML when the file extension is ".hw" */ @@ -181,7 +223,11 @@ HasValue:; *q = '\0'; } } +#line 1285 "nuweb.w" + /* Process a file */ + +#line 1370 "nuweb.w" { pass1(source_name); current_sector = 1; @@ -191,7 +237,7 @@ HasValue:; int saved_number_flag = number_flag; number_flag = TRUE; collect_numbers(aux_name); - write_html(source_name, tex_name, 0/*Dummy */); + write_html(source_name, tex_name); number_flag = saved_number_flag; } else { @@ -203,9 +249,15 @@ HasValue:; write_files(file_names); arena_free(); } +#line 1286 "nuweb.w" + } +#line 1266 "nuweb.w" + arg++; } while (arg < argc); } +#line 963 "nuweb.w" + exit(0); } diff --git a/names.c b/names.c index aeccbbd..a307bb9 100644 --- a/names.c +++ b/names.c @@ -1,9 +1,11 @@ + +#line 932 "nuweb.w" #include "global.h" + +#line 5126 "nuweb.w" enum { LESS, GREATER, EQUAL, PREFIX, EXTENSION }; -static int compare(x, y) - char *x; - char *y; +static int compare(char *x, char *y) { int len, result; int xl = strlen(x); @@ -26,21 +28,22 @@ static int compare(x, y) } else return EQUAL; } -char *save_string(s) - char *s; + +#line 5155 "nuweb.w" +char *save_string(char *s) { char *new = (char *) arena_getmem((strlen(s) + 1) * sizeof(char)); strcpy(new, s); return new; } -static int ambiguous_prefix(); + +#line 5164 "nuweb.w" +static int ambiguous_prefix(Name *node, char *spelling, + unsigned char sector); static char * found_name = NULL; -Name *prefix_add(rt, spelling, sector) - Name **rt; - char *spelling; - unsigned char sector; +Name *prefix_add(Name **rt, char *spelling, unsigned char sector) { Name *node = *rt; int cmp; @@ -64,18 +67,24 @@ Name *prefix_add(rt, spelling, sector) if (cmp == EXTENSION) node->spelling = save_string(spelling); return node; - case PREFIX: { + case PREFIX: +#line 5207 "nuweb.w" + { if (ambiguous_prefix(node->llink, spelling, sector) || ambiguous_prefix(node->rlink, spelling, sector)) fprintf(stderr, "%s: ambiguous prefix %c<%s...%c> (%s, line %d)\n", command_name, nw_char, spelling, nw_char, source_name, source_line); } +#line 5193 "nuweb.w" + return node; } node = *rt; } /* Create new name entry */ + +#line 5330 "nuweb.w" { node = (Name *) arena_getmem(sizeof(Name)); if (found_name && robs_strcmp(found_name, spelling) == 0) @@ -104,11 +113,12 @@ Name *prefix_add(rt, spelling, sector) *rt = node; return node; } +#line 5198 "nuweb.w" + } -static int ambiguous_prefix(node, spelling, sector) - Name *node; - char *spelling; - unsigned char sector; + +#line 5216 "nuweb.w" +static int ambiguous_prefix(Name *node, char *spelling, unsigned char sector) { while (node) { switch (compare(node->spelling, spelling)) { @@ -131,6 +141,8 @@ static int ambiguous_prefix(node, spelling, sector) } return FALSE; } + +#line 5264 "nuweb.w" int robs_strcmp(char* x, char* y) { int cmp = 0; @@ -138,13 +150,21 @@ int robs_strcmp(char* x, char* y) for (; *x && *y; x++, y++) { /* Skip invisibles on 'x' */ + +#line 5298 "nuweb.w" if (*x == '|') x++; +#line 5270 "nuweb.w" + /* Skip invisibles on 'y' */ + +#line 5298 "nuweb.w" if (*y == '|') y++; +#line 5271 "nuweb.w" + if (*x == *y) continue; if (islower(*x) && toupper(*x) == *y) @@ -165,10 +185,9 @@ int robs_strcmp(char* x, char* y) return -2; return cmp; } -Name *name_add(rt, spelling, sector) - Name **rt; - char *spelling; - unsigned char sector; + +#line 5303 "nuweb.w" +Name *name_add(Name **rt, char *spelling, unsigned char sector) { Name *node = *rt; while (node) { @@ -190,6 +209,8 @@ Name *name_add(rt, spelling, sector) node = *rt; } /* Create new name entry */ + +#line 5330 "nuweb.w" { node = (Name *) arena_getmem(sizeof(Name)); if (found_name && robs_strcmp(found_name, spelling) == 0) @@ -218,8 +239,12 @@ Name *name_add(rt, spelling, sector) *rt = node; return node; } +#line 5324 "nuweb.w" + } -Name *collect_file_name() + +#line 5363 "nuweb.w" +Name *collect_file_name(void) { Name *new_name; char name[MAX_NAME_LEN]; @@ -241,6 +266,8 @@ Name *collect_file_name() /* File names are always global. */ new_name = name_add(&file_names, name, 0); /* Handle optional per-file flags */ + +#line 5396 "nuweb.w" { while (1) { while (isspace(c)) @@ -255,7 +282,9 @@ Name *collect_file_name() break; case 'i': new_name->indent_flag = FALSE; break; - case 'c': c = source_get(); + case 'c': +#line 5425 "nuweb.w" + c = source_get(); if (c == 'c') new_name->comment_flag = 1; else if (c == '+') @@ -266,6 +295,8 @@ Name *collect_file_name() fprintf(stderr, "%s: Unrecognised comment flag (%s, %d)\n", command_name, source_name, source_line); +#line 5410 "nuweb.w" + break; default : fprintf(stderr, "%s: unexpected per-file flag (%s, %d)\n", command_name, source_name, source_line); @@ -277,6 +308,8 @@ Name *collect_file_name() else break; } } +#line 5384 "nuweb.w" + c2 = source_get(); if (c != nw_char || (c2 != '{' && c2 != '(' && c2 != '[')) { fprintf(stderr, "%s: expected %c{, %c[, or %c( after file name (%s, %d)\n", @@ -285,7 +318,9 @@ Name *collect_file_name() } return new_name; } -Name *collect_macro_name() + +#line 5446 "nuweb.w" +Name *collect_macro_name(void) { char name[MAX_NAME_LEN]; char args[1000]; @@ -312,7 +347,9 @@ Name *collect_macro_name() c = source_get(); while (c == ' ' || c == '\t'); break; - case '\n': { + case '\n': +#line 5564 "nuweb.w" + { do c = source_get(); while (isspace(c)); @@ -323,6 +360,8 @@ Name *collect_macro_name() exit(-1); } /* Cleanup and install name */ + +#line 5547 "nuweb.w" { if (p > name && p[-1] == ' ') p--; @@ -338,18 +377,26 @@ Name *collect_macro_name() *p = '\0'; node = prefix_add(¯o_names, name, sector); } +#line 5574 "nuweb.w" + return install_args(node, argc, arg); } +#line 5473 "nuweb.w" + default: if (c==nw_char) { /* Check for terminating at-sequence and return name */ + +#line 5494 "nuweb.w" { c = source_get(); switch (c) { case '(': case '[': - case '{': { + case '{': +#line 5547 "nuweb.w" + { if (p > name && p[-1] == ' ') p--; if (p - name > 3 && p[-1] == '.' && p[-2] == '.' && p[-3] == '.') { @@ -364,18 +411,26 @@ Name *collect_macro_name() *p = '\0'; node = prefix_add(¯o_names, name, sector); } +#line 5499 "nuweb.w" + return install_args(node, argc, arg); - case '\'': arg[argc] = argp; + case '\'': +#line 5517 "nuweb.w" + arg[argc] = argp; while ((c = source_get()) != EOF) { if (c==nw_char) { c2 = source_get(); if (c2=='\'') { /* Make this argument */ + +#line 5540 "nuweb.w" if (argc < 9) { *argp++ = '\000'; argc += 1; } +#line 5522 "nuweb.w" + c = source_get(); break; } @@ -387,6 +442,8 @@ Name *collect_macro_name() } *p++ = ARG_CHR; +#line 5501 "nuweb.w" + break; default: if (c==nw_char) @@ -400,6 +457,8 @@ Name *collect_macro_name() exit(-1); } } +#line 5477 "nuweb.w" + break; } *p++ = c; @@ -412,6 +471,8 @@ Name *collect_macro_name() exit(-1); return NULL; /* unreachable return to avoid warnings on some compilers */ } + +#line 5583 "nuweb.w" Name *install_args(Name * name, int argc, char *arg[9]) { int i; @@ -422,6 +483,8 @@ Name *install_args(Name * name, int argc, char *arg[9]) } return name; } + +#line 5604 "nuweb.w" Arglist * buildArglist(Name * name, Arglist * a) { Arglist * args = (Arglist *)arena_getmem(sizeof(Arglist)); @@ -431,6 +494,8 @@ Arglist * buildArglist(Name * name, Arglist * a) args->name = name; return args; } + +#line 5617 "nuweb.w" Arglist * collect_scrap_name(int current_scrap) { char name[MAX_NAME_LEN]; @@ -459,6 +524,8 @@ Arglist * collect_scrap_name(int current_scrap) if (c==nw_char) { /* Look for end of scrap name and return */ + +#line 5666 "nuweb.w" { Name * node; @@ -467,6 +534,8 @@ Arglist * collect_scrap_name(int current_scrap) case '\'': { /* Add plain string argument */ + +#line 5723 "nuweb.w" char buff[MAX_NAME_LEN]; char * s = buff; int c, c2; @@ -483,9 +552,15 @@ Arglist * collect_scrap_name(int current_scrap) } *s = '\000'; /* Add buff to current arg list */ - *tail = buildArglist(NULL, (Arglist *)save_string(buff)); + +#line 5774 "nuweb.w" + *tail = buildArglist(NULL, (Arglist *)save_string(buff)); tail = &(*tail)->next; +#line 5738 "nuweb.w" + +#line 5673 "nuweb.w" + } *p++ = ARG_CHR; c = source_get(); @@ -494,20 +569,30 @@ Arglist * collect_scrap_name(int current_scrap) case '4': case '5': case '6': case '7': case '8': case '9': { /* Add a propagated argument */ + +#line 5744 "nuweb.w" char buff[3]; buff[0] = ARG_CHR; buff[1] = c; buff[2] = '\000'; /* Add buff to current arg list */ - *tail = buildArglist(NULL, (Arglist *)save_string(buff)); + +#line 5774 "nuweb.w" + *tail = buildArglist(NULL, (Arglist *)save_string(buff)); tail = &(*tail)->next; +#line 5748 "nuweb.w" + +#line 5681 "nuweb.w" + } *p++ = ARG_CHR; c = source_get(); break; case '{': { /* Add an inline scrap argument */ + +#line 5751 "nuweb.w" int s = collect_scrap(); Scrap_Node * d = (Scrap_Node *)arena_getmem(sizeof(Scrap_Node)); d->scrap = s; @@ -515,23 +600,31 @@ Arglist * collect_scrap_name(int current_scrap) d->next = NULL; *tail = buildArglist((Name *)1, (Arglist *)d); tail = &(*tail)->next; +#line 5687 "nuweb.w" + } *p++ = ARG_CHR; c = source_get(); break; case '<': /* Add macro call argument */ + +#line 5767 "nuweb.w" *tail = collect_scrap_name(current_scrap); if (current_scrap >= 0) add_to_use((*tail)->name, current_scrap); tail = &(*tail)->next; +#line 5693 "nuweb.w" + *p++ = ARG_CHR; c = source_get(); break; case '(': scrap_name_has_parameters = 1; /* Cleanup and install name */ + +#line 5547 "nuweb.w" { if (p > name && p[-1] == ' ') p--; @@ -547,10 +640,14 @@ Arglist * collect_scrap_name(int current_scrap) *p = '\0'; node = prefix_add(¯o_names, name, sector); } +#line 5699 "nuweb.w" + return buildArglist(node, head); case '>': scrap_name_has_parameters = 0; /* Cleanup and install name */ + +#line 5547 "nuweb.w" { if (p > name && p[-1] == ' ') p--; @@ -566,6 +663,8 @@ Arglist * collect_scrap_name(int current_scrap) *p = '\0'; node = prefix_add(¯o_names, name, sector); } +#line 5703 "nuweb.w" + return buildArglist(node, head); default: @@ -581,6 +680,8 @@ Arglist * collect_scrap_name(int current_scrap) exit(-1); } } +#line 5644 "nuweb.w" + break; } if (!isgraph(c)) { @@ -599,10 +700,11 @@ Arglist * collect_scrap_name(int current_scrap) exit(-1); return NULL; /* unreachable return to avoid warnings on some compilers */ } -static Scrap_Node *reverse(); /* a forward declaration */ -void reverse_lists(names) - Name *names; +#line 5779 "nuweb.w" +static Scrap_Node *reverse(Scrap_Node *a); /* a forward declaration */ + +void reverse_lists(Name *names) { while (names) { reverse_lists(names->llink); @@ -611,8 +713,9 @@ void reverse_lists(names) names = names->rlink; } } -static Scrap_Node *reverse(a) - Scrap_Node *a; + +#line 5796 "nuweb.w" +static Scrap_Node *reverse(Scrap_Node *a) { if (a) { Scrap_Node *b = a->next; diff --git a/nuweb.w b/nuweb.w index aefdb83..726fb63 100644 --- a/nuweb.w +++ b/nuweb.w @@ -954,9 +954,7 @@ then handles any files listed on the command line. @o main.c -cc -d @{ #include -int main(argc, argv) - int argc; - char **argv; +int main(int argc, char** argv) { int arg = 1; @ @@ -1378,7 +1376,7 @@ is forced when generating HTML. int saved_number_flag = number_flag; number_flag = TRUE; collect_numbers(aux_name); - write_html(source_name, tex_name, 0/*Dummy */); + write_html(source_name, tex_name); number_flag = saved_number_flag; } else { @@ -1399,7 +1397,7 @@ During the first pass, we scan the file, recording the definitions of each fragment and file and accumulating all the scraps. @d Function pro... -@{extern void pass1(); +@{extern void pass1(char *file_name); @} @@ -1413,8 +1411,7 @@ our data structures. Next, we seach all the scraps for references to the user-specified index entries. Finally, we must reverse all the cross-reference lists accumulated while scanning the scraps. @o pass1.c -cc -d -@{void pass1(file_name) - char *file_name; +@{void pass1(char *file_name) { if (verbose_flag) fprintf(stderr, "reading %s\n", file_name); @@ -1814,7 +1811,7 @@ Fragment parameters were added on later in nuweb's development. There still is not, for example, an index of fragment parameters. We need a data type to keep track of fragment parameters. -@o global.h -cc -d +@d Type decl... @{typedef int *Parameters; @| Parameters @} @@ -2034,31 +2031,33 @@ modify nuweb to work with a different typesetting system, this would be the place to look. @d Function... -@{extern void write_tex(); +@{extern void write_tex(char *file_name, char *tex_name); @} We need a few local function declarations before we get into the body of \verb|write_tex|. @o latex.c -cc -d -@{static void copy_scrap(); /* formats the body of a scrap */ -static void print_scrap_numbers(); /* formats a list of scrap numbers */ -static void format_entry(); /* formats an index entry */ -static void format_file_entry(); /* formats a file index entry */ -static void format_user_entry(); -static void write_arg(); -static void write_literal(); -static void write_ArglistElement(); +@{static void copy_scrap(FILE *file, int prefix, Name *name); + /* formats the body of a scrap */ +static void print_scrap_numbers(FILE *tex_file, Scrap_Node *scraps); + /* formats a list of scrap numbers */ +static void format_entry(Name *name, FILE *tex_file, unsigned char sector); + /* formats an index entry */ +static void format_file_entry(Name *name, FILE *tex_file); + /* formats a file index entry */ +static void format_user_entry(Name *name, FILE *tex_file, + unsigned char sector); +static void write_arg(FILE *tex_file, char *p); +static void write_literal(FILE *tex_file, char *p, int mode); +static void write_ArglistElement(FILE *file, Arglist *args, char **params); @} The routine \verb|write_tex| takes two file names as parameters: the name of the web source file and the name of the \verb|.tex| output file. @o latex.c -cc -d -@{void write_tex(file_name, tex_name, sector) - char *file_name; - char *tex_name; - unsigned char sector; +@{void write_tex(char *file_name, char *tex_name) { FILE *tex_file = fopen(tex_name, "w"); if (tex_file) { @@ -2496,9 +2495,7 @@ list. }@} @o latex.c -cc -d -@{static void print_scrap_numbers(tex_file, scraps) - FILE *tex_file; - Scrap_Node *scraps; +@{static void print_scrap_numbers(FILE *tex_file, Scrap_Node *scraps) { int page; fputs("\\NWlink{nuweb", tex_file); @@ -2605,10 +2602,7 @@ command. @| write_literal @} @o latex.c -cc -d -@{static void copy_scrap(file, prefix, name) - FILE *file; - int prefix; - Name * name; +@{static void copy_scrap(FILE *file, int prefix, Name *name) { int indent = 0; int c; @@ -2930,9 +2924,7 @@ write_ArglistElement(FILE * file, Arglist * args, char ** params) }@} @o latex.c -cc -d -@{static void format_file_entry(name, tex_file) - Name *name; - FILE *tex_file; +@{static void format_file_entry(Name *name, FILE *tex_file) { while (name) { format_file_entry(name->llink, tex_file); @@ -3003,10 +2995,7 @@ c = source_get(); @| load_entry @} @o latex.c -cc -d -@{static void format_entry(name, tex_file, sector) - Name *name; - FILE *tex_file; - unsigned char sector; +@{static void format_entry(Name *name, FILE *tex_file, unsigned char sector) { Name ** nms = malloc(num_scraps()*sizeof(Name *)); int n = load_entry(name, nms, 0); @@ -3144,10 +3133,7 @@ for (j = 1; j < @2; j++) @o latex.c -cc -d -@{static void format_user_entry(name, tex_file, sector) - Name *name; - FILE *tex_file; - unsigned char sector; +@{static void format_user_entry(Name *name, FILE *tex_file, unsigned char sector) { while (name) { format_user_entry(name->llink, tex_file, sector); @@ -3238,28 +3224,31 @@ copies most of the text from the source file straight into a cross-reference information is printed out. @d Function... -@{extern void write_html(); +@{extern void write_html(char *file_name, char *html_name); @} We need a few local function declarations before we get into the body of \verb|write_html|. @o html.c -@{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(); +@{static void copy_scrap(FILE *file, int prefix); + /* formats the body of a scrap */ +static void display_scrap_ref(FILE *html_file, int num); + /* formats a scrap reference */ +static void display_scrap_numbers(FILE *html_file, Scrap_Node *scraps); + /* formats a list of scrap numbers */ +static void print_scrap_numbers(FILE *html_file, Scrap_Node *scraps); + /* pluralizes scrap formats list */ +static void format_entry(Name *name, FILE *html_file, int file_flag); + /* formats an index entry */ +static void format_user_entry(Name *name, FILE *html_file, int sector); @} The routine \verb|write_html| takes two file names as parameters: the name of the web source file and the name of the \verb|.tex| output file. @o html.c -@{void write_html(file_name, html_name) - char *file_name; - char *html_name; +@{void write_html(char *file_name, char *html_name) { FILE *html_file = fopen(html_name, "w"); FILE *tex_file = html_file; @@ -3472,9 +3461,7 @@ end the paragraph. }@} @o html.c -@{static void display_scrap_ref(html_file, num) - FILE *html_file; - int num; +@{static void display_scrap_ref(FILE *html_file, int num) { fputs("scrap); scraps = scraps->next; @@ -3500,9 +3485,7 @@ end the paragraph. @| display_scrap_numbers @} @o html.c -@{static void print_scrap_numbers(html_file, scraps) - FILE *html_file; - Scrap_Node *scraps; +@{static void print_scrap_numbers(FILE *html_file, Scrap_Node *scraps) { display_scrap_numbers(html_file, scraps); fputs(".\n", html_file); @@ -3515,9 +3498,7 @@ end the paragraph. We must translate HTML special keywords into entities in scraps. @o html.c -@{static void copy_scrap(file, prefix) - FILE *file; - int prefix; +@{static void copy_scrap(FILE *file, int prefix) { int indent = 0; int c = source_get(); @@ -3660,10 +3641,7 @@ pointed out any during the first pass. }@} @o html.c -@{static void format_entry(name, html_file, file_flag) - Name *name; - FILE *html_file; - int file_flag; +@{static void format_entry(Name *name, FILE *html_file, int file_flag) { while (name) { format_entry(name->llink, html_file, file_flag); @@ -3732,10 +3710,7 @@ pointed out any during the first pass. @o html.c -@{static void format_user_entry(name, html_file, sector) - Name *name; - FILE *html_file; - int sector; +@{static void format_user_entry(Name *name, FILE *html_file, int sector) { while (name) { format_user_entry(name->llink, html_file, sector); @@ -3786,12 +3761,11 @@ pointed out any during the first pass. \section{Writing the Output Files} \label{output-files} @d Function pro... -@{extern void write_files(); +@{extern void write_files(Name *files); @} @o output.c -cc -d -@{void write_files(files) - Name *files; +@{void write_files(Name *files) { while (files) { write_files(files->llink); @@ -3912,8 +3886,10 @@ if (0 != rename(temp_name, real_name)) { We need two routines to handle reading the source files. @d Function pro... -@{extern void source_open(); /* pass in the name of the source file */ -extern int source_get(); /* no args; returns the next char or EOF */ +@{extern void source_open(char *name); + /* pass in the name of the source file */ +extern int source_get(void); + /* no args; returns the next char or EOF */ extern int source_last; /* what last source_get() returned. */ extern int source_peek; /* The next character to get */ @} @@ -3962,7 +3938,7 @@ are defining. @{ int source_peek; int source_last; -int source_get() +int source_get(void) { int c; source_last = c = source_peek; @@ -4128,8 +4104,7 @@ The routine \verb|source_open| takes a file name and tries to open the file. If unsuccessful, it complains and halts. Otherwise, it sets \verb|source_name|, \verb|source_line|, and \verb|double_at|. @o input.c -cc -d -@{void source_open(name) - char *name; +@{void source_open(char *name) { source_file = fopen(name, "r"); if (!source_file) { @@ -4186,7 +4161,7 @@ static ScrapEntry *SCRAP[SCRAP_SIZE]; #define scrap_array(i) SCRAP[(i) >> SCRAP_SHIFT][(i) & SCRAP_MASK] static int scraps; -int num_scraps() +int num_scraps(void) { return scraps; }; @@ -4195,17 +4170,22 @@ int num_scraps() @d Function pro... -@{extern void init_scraps(); -extern int collect_scrap(); -extern int write_scraps(); -extern void write_scrap_ref(); -extern void write_single_scrap_ref(); -extern int num_scraps(); +@{extern void init_scraps(void); +extern int collect_scrap(void); +extern int write_scraps(FILE *file, char *spelling, Scrap_Node *defs, + int global_indent, char *indent_chars, + char debug_flag, char tab_flag, char indent_flag, + unsigned char comment_flag, Arglist *inArgs, + char *inParams[9], Parameters parameters, + char *title); +extern void write_scrap_ref(FILE *file, int num, int first, int *page); +extern void write_single_scrap_ref(FILE *file, int num); +extern int num_scraps(void); @} @o scraps.c -cc -d -@{void init_scraps() +@{void init_scraps(void) { scraps = 1; SCRAP[0] = (ScrapEntry *) arena_getmem(SCRAP_SIZE * sizeof(ScrapEntry)); @@ -4213,11 +4193,7 @@ extern int num_scraps(); @| init_scraps @} @o scraps.c -cc -d -@{void write_scrap_ref(file, num, first, page) - FILE *file; - int num; - int first; - int *page; +@{void write_scrap_ref(FILE *file, int num, int first, int *page) { if (scrap_array(num).page >= 0) { if (first!=0) @@ -4240,9 +4216,7 @@ extern int num_scraps(); @| write_scrap_ref @} @o scraps.c -cc -d -@{void write_single_scrap_ref(file, num) - FILE *file; - int num; +@{void write_single_scrap_ref(FILE *file, int num) { int page; write_scrap_ref(file, num, TRUE, &page); @@ -4278,9 +4252,7 @@ extern int num_scraps(); @o scraps.c -cc -d -@{static void push(c, manager) - char c; - Manager *manager; +@{static void push(char c, Manager *manager) { Slab *scrap = manager->scrap; int index = manager->index; @@ -4296,9 +4268,7 @@ extern int num_scraps(); @| push @} @o scraps.c -cc -d -@{static void pushs(s, manager) - char *s; - Manager *manager; +@{static void pushs(char *s, Manager *manager) { while (*s) push(*s++, manager); @@ -4306,7 +4276,7 @@ extern int num_scraps(); @| pushs @} @o scraps.c -cc -d -@{int collect_scrap() +@{int collect_scrap(void) { int current_scrap, lblseq = 0; int depth = 1; @@ -4531,8 +4501,7 @@ add_to_use(Name * name, int current_scrap) @{extern void add_to_use(Name * name, int current_scrap); @} @o scraps.c -cc -d -@{static char pop(manager) - Manager *manager; +@{static char pop(Manager *manager) { Slab *scrap = manager->scrap; int index = manager->index; @@ -4548,9 +4517,7 @@ add_to_use(Name * name, int current_scrap) @| pop @} @o scraps.c -cc -d -@{static void backup(n, manager) - int n; - Manager *manager; +@{static void backup(int n, Manager *manager) { int index = manager->index; if (n > index @@ -4605,7 +4572,7 @@ lookup(int n, Arglist * par, char * arg[9], Name **name, Arglist ** args) @| instance @} @d Function prototypes -@{Arglist * instance(); +@{extern Arglist *instance(Arglist *a, Arglist *par, char *arg[9], int *ch); @} @d Set up name, args and next @@ -4637,9 +4604,7 @@ a->args = args; a->next = next;@} @o scraps.c -cc -d -@{static Arglist *pop_scrap_name(manager, parameters) - Manager *manager; - Parameters *parameters; +@{static Arglist *pop_scrap_name(Manager *manager, Parameters *parameters) { char name[MAX_NAME_LEN]; char *p = name; @@ -4672,22 +4637,11 @@ a->next = next;@} }@} @o scraps.c -cc -d -@{int write_scraps(file, spelling, defs, global_indent, indent_chars, - debug_flag, tab_flag, indent_flag, - comment_flag, inArgs, inParams, parameters, title) - FILE *file; - char * spelling; - Scrap_Node *defs; - int global_indent; - char *indent_chars; - char debug_flag; - char tab_flag; - char indent_flag; - unsigned char comment_flag; - Arglist * inArgs; - char * inParams[9]; - Parameters parameters; - char * title; +@{int write_scraps(FILE *file, char *spelling, Scrap_Node *defs, + int global_indent, char *indent_chars, char debug_flag, + char tab_flag, char indent_flag, + unsigned char comment_flag, Arglist *inArgs, + char *inParams[9], Parameters parameters, char *title) { /* This is in file @f */ int indent = 0; @@ -5000,7 +4954,8 @@ comment_ArglistElement(FILE * file, Arglist * args, int quote) @d Include an embedded scrap in comment @{Embed_Node * e = (Embed_Node *)q; fputc('{', file); -write_scraps(file, "", e->defs, -1, "", 0, 0, 0, 0, e->args, 0, 1, ""); +write_scraps(file, "", e->defs, -1, "", 0, 0, 0, 0, e->args, 0, + (Parameters)1, ""); fputc('}', file);@} @d Include a fragment use in comment @@ -5026,12 +4981,11 @@ fputc('>', file);@} \subsection{Collecting Page Numbers} @d Function... -@{extern void collect_numbers(); +@{extern void collect_numbers(char *aux_name); @} @o scraps.c -cc -d -@{void collect_numbers(aux_name) - char *aux_name; +@{void collect_numbers(char *aux_name) { if (number_flag) { int i; @@ -5159,21 +5113,19 @@ int scrap_ended_with; @} @d Function pro... -@{extern Name *collect_file_name(); -extern Name *collect_macro_name(); -extern Arglist *collect_scrap_name(); -extern Name *name_add(); -extern Name *prefix_add(); -extern char *save_string(); -extern void reverse_lists(); +@{extern Name *collect_file_name(void); +extern Name *collect_macro_name(void); +extern Arglist *collect_scrap_name(int current_scrap); +extern Name *name_add(Name **rt, char *spelling, unsigned char sector); +extern Name *prefix_add(Name **rt, char *spelling, unsigned char sector); +extern char *save_string(char *); +extern void reverse_lists(Name *names); @} @o names.c -cc -d @{enum { LESS, GREATER, EQUAL, PREFIX, EXTENSION }; -static int compare(x, y) - char *x; - char *y; +static int compare(char *x, char *y) { int len, result; int xl = strlen(x); @@ -5200,8 +5152,7 @@ static int compare(x, y) @o names.c -cc -d -@{char *save_string(s) - char *s; +@{char *save_string(char *s) { char *new = (char *) arena_getmem((strlen(s) + 1) * sizeof(char)); strcpy(new, s); @@ -5210,14 +5161,12 @@ static int compare(x, y) @| save_string @} @o names.c -cc -d -@{static int ambiguous_prefix(); +@{static int ambiguous_prefix(Name *node, char *spelling, + unsigned char sector); static char * found_name = NULL; -Name *prefix_add(rt, spelling, sector) - Name **rt; - char *spelling; - unsigned char sector; +Name *prefix_add(Name **rt, char *spelling, unsigned char sector) { Name *node = *rt; int cmp; @@ -5264,10 +5213,7 @@ continue the search down {\em both\/} branches of the tree. }@} @o names.c -cc -d -@{static int ambiguous_prefix(node, spelling, sector) - Name *node; - char *spelling; - unsigned char sector; +@{static int ambiguous_prefix(Name *node, char *spelling, unsigned char sector) { while (node) { switch (compare(node->spelling, spelling)) { @@ -5354,10 +5300,7 @@ them to be considered for the alphabetical ordering. @} @o names.c -cc -d -@{Name *name_add(rt, spelling, sector) - Name **rt; - char *spelling; - unsigned char sector; +@{Name *name_add(Name **rt, char *spelling, unsigned char sector) { Name *node = *rt; while (node) { @@ -5417,7 +5360,7 @@ them to be considered for the alphabetical ordering. Name terminated by whitespace. Also check for ``per-file'' flags. Keep skipping white space until we reach scrap. @o names.c -cc -d -@{Name *collect_file_name() +@{Name *collect_file_name(void) { Name *new_name; char name[MAX_NAME_LEN]; @@ -5500,7 +5443,7 @@ char * comment_end[4] = { "", " */", "", ""}; Name terminated by \verb+\n+ or \verb+@@{+; but keep skipping until \verb+@@{+ @o names.c -cc -d -@{Name *collect_macro_name() +@{Name *collect_macro_name(void) { char name[MAX_NAME_LEN]; char args[1000]; @@ -5633,7 +5576,7 @@ while ((c = source_get()) != EOF) { }@} @d Function prototypes -@{extern Name *install_args(); +@{extern Name *install_args(Name * name, int argc, char *arg[0]); @} @o names.c -cc -d @@ -5833,10 +5776,9 @@ tail = &(*tail)->next; @} @o names.c -cc -d -@{static Scrap_Node *reverse(); /* a forward declaration */ +@{static Scrap_Node *reverse(Scrap_Node *a); /* a forward declaration */ -void reverse_lists(names) - Name *names; +void reverse_lists(Name *names) { while (names) { reverse_lists(names->llink); @@ -5851,8 +5793,7 @@ Just for fun, here's a non-recursive version of the traditional list reversal code. Note that it reverses the list in place; that is, it does no new allocations. @o names.c -cc -d -@{static Scrap_Node *reverse(a) - Scrap_Node *a; +@{static Scrap_Node *reverse(Scrap_Node *a) { if (a) { Scrap_Node *b = a->next; @@ -5910,9 +5851,7 @@ static Goto_Node **depths; @o scraps.c -cc -d -@{static Goto_Node *goto_lookup(c, g) - char c; - Goto_Node *g; +@{static Goto_Node *goto_lookup(char c, Goto_Node *g) { Move_Node *m = g->moves; while (m && m->c != c) @@ -6058,14 +5997,14 @@ else if (m->prev) \subsection{Building the Automata} @d Function pro... -@{extern void search(); +@{extern void search(void); @} @o scraps.c -cc -d -@{static void build_gotos(); -static int reject_match(); +@{static void build_gotos(Name *tree); +static int reject_match(Name *name, char post, ArgManager *reader); -void search() +void search(void) { int i; for (i=0; i<128; i++) @@ -6083,8 +6022,7 @@ void search() @o scraps.c -cc -d -@{static void build_gotos(tree) - Name *tree; +@{static void build_gotos(Name *tree) { while (tree) { @spelling|@> @@ -6261,8 +6199,8 @@ void search() @d Forward declarations for scraps.c @{ -static void add_uses(); -static int scrap_is_in(); +static void add_uses(Uses **root, Name *name); +static int scrap_is_in(Scrap_Node * list, int i); @} @o scraps.c -cc -d @@ -6422,8 +6360,7 @@ For the present, we'll consider the mechanism an experiment. @o scraps.c -cc -d @{#define sym_char(c) (isalnum(c) || (c) == '_') -static int op_char(c) - char c; +static int op_char(char c) { switch (c) { case '!': case '#': case '%': case '$': case '^': @@ -6437,10 +6374,7 @@ static int op_char(c) @| sym_char op_char @} @o scraps.c -cc -d -@{static int reject_match(name, post, reader) - Name *name; - char post; - ArgManager *reader; +@{static int reject_match(Name *name, char post, ArgManager *reader) { int len = strlen(name->spelling); char first = name->spelling[0]; @@ -6569,8 +6503,8 @@ be allocated. When the storage is no longer required, the entire arena is freed with a single call to \verb|arena_free()|. Both operations are quite fast. @d Function p... -@{extern void *arena_getmem(); -extern void arena_free(); +@{extern void *arena_getmem(size_t n); +extern void arena_free(void); @} @@ -6603,8 +6537,7 @@ that returned pointers are always aligned. We align to the nearest 4-byte alignment restrictions too. @o arena.c -cc -d -@{void *arena_getmem(n) - size_t n; +@{void *arena_getmem(size_t n) { char *q; char *p = arena->avail; @@ -6662,7 +6595,7 @@ need to allocate a new one. To free all the memory in the arena, we need only point \verb|arena| back to the first empty chunk. @o arena.c -cc -d -@{void arena_free() +@{void arena_free(void) { arena = &first; } diff --git a/output.c b/output.c index cb8ef44..a27bad6 100644 --- a/output.c +++ b/output.c @@ -1,10 +1,15 @@ + +#line 908 "nuweb.w" #include "global.h" -void write_files(files) - Name *files; + +#line 3768 "nuweb.w" +void write_files(Name *files) { while (files) { write_files(files->llink); /* Write out \verb|files->spelling| */ + +#line 3789 "nuweb.w" { static char temp_name[FILENAME_MAX]; static char real_name[FILENAME_MAX]; @@ -14,6 +19,8 @@ void write_files(files) /* Find a free temporary file */ +#line 3809 "nuweb.w" + for( temp_name_count = 0; temp_name_count < 10000; temp_name_count++) { sprintf(temp_name,"%s%snw%06d", dirpath, path_sep, temp_name_count); #ifdef O_EXCL @@ -38,6 +45,8 @@ void write_files(files) exit(-1); } +#line 3796 "nuweb.w" + sprintf(real_name, "%s%s%s", dirpath, path_sep, files->spelling); if (verbose_flag) @@ -49,8 +58,12 @@ void write_files(files) /* Move the temporary file to the target, if required */ +#line 3839 "nuweb.w" + if (compare_flag) /* Compare the temp file and the old file */ + +#line 3850 "nuweb.w" { FILE *old_file = fopen(real_name, "r"); if (old_file) { @@ -68,34 +81,52 @@ void write_files(files) remove(real_name); /* Rename the temporary file to the target */ +#line 3872 "nuweb.w" + if (0 != rename(temp_name, real_name)) { fprintf(stderr, "%s: can't rename output file to %s\n", command_name, real_name); } +#line 3865 "nuweb.w" + } } else /* Rename the temporary file to the target */ +#line 3872 "nuweb.w" + if (0 != rename(temp_name, real_name)) { fprintf(stderr, "%s: can't rename output file to %s\n", command_name, real_name); } +#line 3869 "nuweb.w" + } +#line 3841 "nuweb.w" + else { remove(real_name); /* Rename the temporary file to the target */ +#line 3872 "nuweb.w" + if (0 != rename(temp_name, real_name)) { fprintf(stderr, "%s: can't rename output file to %s\n", command_name, real_name); } +#line 3844 "nuweb.w" + } +#line 3806 "nuweb.w" + } +#line 3772 "nuweb.w" + files = files->rlink; } } diff --git a/pass1.c b/pass1.c index 09733c5..e1b0441 100644 --- a/pass1.c +++ b/pass1.c @@ -1,6 +1,9 @@ + +#line 885 "nuweb.w" #include "global.h" -void pass1(file_name) - char *file_name; + +#line 1414 "nuweb.w" +void pass1(char *file_name) { if (verbose_flag) fprintf(stderr, "reading %s\n", file_name); @@ -10,11 +13,15 @@ void pass1(file_name) file_names = NULL; user_names = NULL; /* Scan the source file, looking for at-sequences */ + +#line 1433 "nuweb.w" { int c = source_get(); while (c != EOF) { if (c == nw_char) /* Scan at-sequence */ + +#line 1446 "nuweb.w" { char quoted = 0; @@ -26,10 +33,14 @@ void pass1(file_name) update_delimit_scrap(); break; case 'O': - case 'o': { + case 'o': +#line 1524 "nuweb.w" + { Name *name = collect_file_name(); /* returns a pointer to the name entry */ int scrap = collect_scrap(); /* returns an index to the scrap */ /* Add \verb|scrap| to \verb|name|'s definition list */ + +#line 1543 "nuweb.w" { Scrap_Node *def = (Scrap_Node *) arena_getmem(sizeof(Scrap_Node)); def->scrap = scrap; @@ -37,15 +48,23 @@ void pass1(file_name) def->next = name->defs; name->defs = def; } +#line 1527 "nuweb.w" + } +#line 1457 "nuweb.w" + break; case 'Q': case 'q': quoted = 1; case 'D': - case 'd': { + case 'd': +#line 1532 "nuweb.w" + { Name *name = collect_macro_name(); int scrap = collect_scrap(); /* Add \verb|scrap| to \verb|name|'s definition list */ + +#line 1543 "nuweb.w" { Scrap_Node *def = (Scrap_Node *) arena_getmem(sizeof(Scrap_Node)); def->scrap = scrap; @@ -53,26 +72,40 @@ void pass1(file_name) def->next = name->defs; name->defs = def; } +#line 1535 "nuweb.w" + } +#line 1462 "nuweb.w" + break; case 's': /* Step to next sector */ +#line 1493 "nuweb.w" + prev_sector += 1; current_sector = prev_sector; c = source_get(); +#line 1465 "nuweb.w" + break; case 'S': /* Close the current sector */ + +#line 1500 "nuweb.w" current_sector = 1; c = source_get(); +#line 1468 "nuweb.w" + break; case '<': case '(': case '[': case '{': +#line 1552 "nuweb.w" + { int c; int depth = 1; @@ -80,6 +113,8 @@ void pass1(file_name) if (c == nw_char) /* Skip over at-sign or go to skipped */ +#line 1569 "nuweb.w" + { c = source_get(); switch (c) { @@ -107,6 +142,8 @@ void pass1(file_name) } } +#line 1558 "nuweb.w" + } fprintf(stderr, "%s: unexpected EOF in text at (%s, %d)\n", command_name, source_name, source_line); @@ -115,25 +152,37 @@ void pass1(file_name) skipped: ; } +#line 1473 "nuweb.w" + break; - case 'c': { + case 'c': +#line 1600 "nuweb.w" + { char * p = blockBuff; char * e = blockBuff + (sizeof(blockBuff)/sizeof(blockBuff[0])) - 1; /* Skip whitespace */ + +#line 1618 "nuweb.w" while (source_peek == ' ' || source_peek == '\t' || source_peek == '\n') (void)source_get(); +#line 1604 "nuweb.w" + while (p < e) { /* Add one char to the block buffer */ + +#line 1625 "nuweb.w" int c = source_get(); if (c == nw_char) { /* Add an at character to the block or break */ + +#line 1643 "nuweb.w" int cc = source_peek; if (cc == 'c') @@ -161,6 +210,8 @@ void pass1(file_name) *p++ = source_get(); } +#line 1629 "nuweb.w" + } else if (c == EOF) { @@ -171,7 +222,11 @@ void pass1(file_name) { /* Add any other character to the block */ +#line 1672 "nuweb.w" + /* Perhaps skip white-space */ + +#line 1678 "nuweb.w" if (c == ' ') { while (source_peek == ' ') @@ -189,22 +244,34 @@ void pass1(file_name) c = ' '; } +#line 1673 "nuweb.w" + *p++ = c; +#line 1638 "nuweb.w" + } +#line 1607 "nuweb.w" + } if (p == e) { /* Skip to the next nw-char */ + +#line 1697 "nuweb.w" int c; while ((c = source_get()), c != nw_char && c != EOF)/* Skip */ source_ungetc(&c); +#line 1611 "nuweb.w" + } *p = '\000'; } +#line 1475 "nuweb.w" + break; case 'x': case 'v': @@ -220,15 +287,23 @@ void pass1(file_name) break; } } +#line 1437 "nuweb.w" + c = source_get(); } } +#line 1423 "nuweb.w" + if (tex_flag) search(); /* Reverse cross-reference lists */ + +#line 1802 "nuweb.w" { reverse_lists(file_names); reverse_lists(macro_names); reverse_lists(user_names); } +#line 1426 "nuweb.w" + } diff --git a/scraps.c b/scraps.c index 7a6d845..41b7fd1 100644 --- a/scraps.c +++ b/scraps.c @@ -1,10 +1,16 @@ + +#line 925 "nuweb.w" #include "global.h" + +#line 4130 "nuweb.w" #define SLAB_SIZE 1024 typedef struct slab { struct slab *next; char chars[SLAB_SIZE]; } Slab; + +#line 4139 "nuweb.w" typedef struct { char *file_name; Slab *slab; @@ -16,6 +22,8 @@ typedef struct { unsigned char sector; } ScrapEntry; +#line 4154 "nuweb.w" + #define SCRAP_BITS 10 #define SCRAP_SIZE (1<> SCRAP_SHIFT][(i) & SCRAP_MASK] static int scraps; -int num_scraps() +int num_scraps(void) { return scraps; }; /* Forward declarations for scraps.c */ + +#line 4658 "nuweb.w" int delayed_indent = 0; + +#line 4935 "nuweb.w" static void comment_ArglistElement(FILE * file, Arglist * args, int quote) { @@ -44,12 +56,19 @@ comment_ArglistElement(FILE * file, Arglist * args, int quote) fprintf(file, "'%s'", (char *)q); } else if (name == (Name *)1) { /* Include an embedded scrap in comment */ + +#line 4955 "nuweb.w" Embed_Node * e = (Embed_Node *)q; fputc('{', file); - write_scraps(file, "", e->defs, -1, "", 0, 0, 0, 0, e->args, 0, 1, ""); + write_scraps(file, "", e->defs, -1, "", 0, 0, 0, 0, e->args, 0, + (Parameters)1, ""); fputc('}', file); +#line 4947 "nuweb.w" + } else { /* Include a fragment use in comment */ + +#line 4962 "nuweb.w" char * p = name->spelling; if (quote) fputc(nw_char, file); @@ -68,25 +87,33 @@ comment_ArglistElement(FILE * file, Arglist * args, int quote) if (quote) fputc(nw_char, file); fputc('>', file); +#line 4949 "nuweb.w" + } } + +#line 5439 "nuweb.w" char * comment_begin[4] = { "", "/* ", "// ", "# "}; char * comment_mid[4] = { "", " * ", "// ", "# "}; char * comment_end[4] = { "", " */", "", ""}; -static void add_uses(); -static int scrap_is_in(); +#line 6201 "nuweb.w" -void init_scraps() +static void add_uses(Uses **root, Name *name); +static int scrap_is_in(Scrap_Node * list, int i); + +#line 4168 "nuweb.w" + + +#line 4188 "nuweb.w" +void init_scraps(void) { scraps = 1; SCRAP[0] = (ScrapEntry *) arena_getmem(SCRAP_SIZE * sizeof(ScrapEntry)); } -void write_scrap_ref(file, num, first, page) - FILE *file; - int num; - int first; - int *page; + +#line 4196 "nuweb.w" +void write_scrap_ref(FILE *file, int num, int first, int *page) { if (scrap_array(num).page >= 0) { if (first!=0) @@ -102,6 +129,8 @@ void write_scrap_ref(file, num, first, page) else fputs(", ?", file); /* Warn (only once) about needing to rerun after Latex */ + +#line 4228 "nuweb.w" { if (!already_warned) { fprintf(stderr, "%s: you'll need to rerun nuweb after running latex\n", @@ -109,25 +138,29 @@ void write_scrap_ref(file, num, first, page) already_warned = TRUE; } } +#line 4211 "nuweb.w" + } if (first>=0) *page = scrap_array(num).page; } -void write_single_scrap_ref(file, num) - FILE *file; - int num; + +#line 4219 "nuweb.w" +void write_single_scrap_ref(FILE *file, int num) { int page; write_scrap_ref(file, num, TRUE, &page); } + +#line 4245 "nuweb.w" typedef struct { Slab *scrap; Slab *prev; int index; } Manager; -static void push(c, manager) - char c; - Manager *manager; + +#line 4255 "nuweb.w" +static void push(char c, Manager *manager) { Slab *scrap = manager->scrap; int index = manager->index; @@ -140,19 +173,23 @@ static void push(c, manager) } manager->index = index; } -static void pushs(s, manager) - char *s; - Manager *manager; + +#line 4271 "nuweb.w" +static void pushs(char *s, Manager *manager) { while (*s) push(*s++, manager); } -int collect_scrap() + +#line 4279 "nuweb.w" +int collect_scrap(void) { int current_scrap, lblseq = 0; int depth = 1; Manager writer; /* Create new scrap, managed by \verb|writer| */ + +#line 4290 "nuweb.w" { Slab *scrap = (Slab *) arena_getmem(sizeof(Slab)); if ((scraps & SCRAP_MASK) == 0) @@ -169,7 +206,11 @@ int collect_scrap() writer.index = 0; current_scrap = scraps++; } +#line 4284 "nuweb.w" + /* Accumulate scrap and return \verb|scraps++| */ + +#line 4309 "nuweb.w" { int c = source_get(); while (1) { @@ -182,6 +223,8 @@ int collect_scrap() if (c==nw_char) { /* Handle at-sign during scrap accumulation */ + +#line 4331 "nuweb.w" { c = source_get(); switch (c) { @@ -192,7 +235,9 @@ int collect_scrap() case '+': case '-': case '*': - case '|': { + case '|': +#line 4398 "nuweb.w" + { do { int type = c; do { @@ -213,6 +258,8 @@ int collect_scrap() case '*': sector = current_sector; /* Add user identifier use */ + +#line 4442 "nuweb.w" name = name_add(&user_names, new_name, sector); if (!name->uses || name->uses->scrap != current_scrap) { Scrap_Node *use = (Scrap_Node *) arena_getmem(sizeof(Scrap_Node)); @@ -221,9 +268,13 @@ int collect_scrap() name->uses = use; add_uses(&(scrap_array(current_scrap).uses), name); } +#line 4418 "nuweb.w" + break; case '-': /* Add user identifier use */ + +#line 4442 "nuweb.w" name = name_add(&user_names, new_name, sector); if (!name->uses || name->uses->scrap != current_scrap) { Scrap_Node *use = (Scrap_Node *) arena_getmem(sizeof(Scrap_Node)); @@ -232,12 +283,16 @@ int collect_scrap() name->uses = use; add_uses(&(scrap_array(current_scrap).uses), name); } +#line 4421 "nuweb.w" + /* Fall through */ case '|': sector = current_sector; /* Fall through */ case '+': /* Add user identifier definition */ + +#line 4452 "nuweb.w" name = name_add(&user_names, new_name, sector); if (!name->defs || name->defs->scrap != current_scrap) { Scrap_Node *def = (Scrap_Node *) arena_getmem(sizeof(Scrap_Node)); @@ -246,6 +301,8 @@ int collect_scrap() name->defs = def; add_uses(&(scrap_array(current_scrap).defs), name); } +#line 4427 "nuweb.w" + break; } } @@ -258,6 +315,8 @@ int collect_scrap() exit(-1); } } +#line 4341 "nuweb.w" + /* Fall through */ case ')': case ']': @@ -268,10 +327,14 @@ int collect_scrap() push('\0', &writer); scrap_ended_with = c; return current_scrap; - case '<': { + case '<': +#line 4462 "nuweb.w" + { Arglist * args = collect_scrap_name(current_scrap); Name *name = args->name; /* Save macro name */ + +#line 4477 "nuweb.w" { char buff[24]; @@ -281,9 +344,13 @@ int collect_scrap() sprintf(buff, "%p", args); pushs(buff, &writer); } +#line 4465 "nuweb.w" + add_to_use(name, current_scrap); if (scrap_name_has_parameters) { /* Save macro parameters */ + +#line 1895 "nuweb.w" { int param_scrap; char param_buf[10]; @@ -308,34 +375,56 @@ int collect_scrap() /* ZZZ print error */; } } +#line 4468 "nuweb.w" + } push(nw_char, &writer); push('>', &writer); c = source_get(); } +#line 4352 "nuweb.w" + break; - case '%': { + case '%': +#line 2768 "nuweb.w" + { do c = source_get(); while (c != '\n'); } +#line 4354 "nuweb.w" + /* emit line break to the output file to keep #line in sync. */ push('\n', &writer); c = source_get(); break; - case 'x': { + case 'x': +#line 4387 "nuweb.w" + { /* Get label from */ + +#line 6398 "nuweb.w" char label_name[MAX_NAME_LEN]; char * p = label_name; - while (c = source_get(), c != nw_char) /* Here is 150a-01 */ + while (c = +#line 4388 "nuweb.w" + source_get(), c != nw_char) /* Here is 148c-01 */ *p++ = c; *p = '\0'; - c = source_get(); + c = +#line 4388 "nuweb.w" + source_get(); +#line 4388 "nuweb.w" + /* Save label to label store */ + +#line 6424 "nuweb.w" if (label_name[0]) /* Search for label(,) */ - { + +#line 6446 "nuweb.w" + { label_node * * plbl = &label_tab; for (;;) { @@ -354,6 +443,8 @@ int collect_scrap() else { /* Complain about duplicate labels */ + +#line 6440 "nuweb.w" fprintf(stderr, "Duplicate label %s.\n", label_name); break; } @@ -361,6 +452,8 @@ int collect_scrap() else { /* Create a new label entry */ + +#line 6432 "nuweb.w" lbl = (label_node *)arena_getmem(sizeof(label_node) + (p - label_name)); lbl->left = lbl->right = NULL; strcpy(lbl->name, label_name); @@ -372,18 +465,30 @@ int collect_scrap() } } +#line 6425 "nuweb.w" + else { /* Complain about empty label */ + +#line 6443 "nuweb.w" fprintf(stderr, "Empty label.\n"); +#line 6428 "nuweb.w" + } +#line 4389 "nuweb.w" + push(nw_char, &writer); push('x', &writer); pushs(label_name, &writer); push(nw_char, &writer); } +#line 4359 "nuweb.w" + break; - case 'c': { + case 'c': +#line 1726 "nuweb.w" + { char * p = blockBuff; push(nw_char, &writer); @@ -393,6 +498,8 @@ int collect_scrap() c = *p++; } while (c != '\0'); } +#line 4361 "nuweb.w" + break; case '1': case '2': case '3': case '4': case '5': case '6': @@ -416,6 +523,8 @@ int collect_scrap() exit(-1); } } +#line 4320 "nuweb.w" + break; } push(c, &writer); @@ -424,7 +533,11 @@ int collect_scrap() } } } +#line 4285 "nuweb.w" + } + +#line 4488 "nuweb.w" void add_to_use(Name * name, int current_scrap) { @@ -435,8 +548,9 @@ add_to_use(Name * name, int current_scrap) name->uses = use; } } -static char pop(manager) - Manager *manager; + +#line 4504 "nuweb.w" +static char pop(Manager *manager) { Slab *scrap = manager->scrap; int index = manager->index; @@ -449,9 +563,9 @@ static char pop(manager) manager->index = index; return c; } -static void backup(n, manager) - int n; - Manager *manager; + +#line 4520 "nuweb.w" +static void backup(int n, Manager *manager) { int index = manager->index; if (n > index @@ -463,6 +577,8 @@ static void backup(n, manager) } manager->index = (n <= index ? index - n : 0); } + +#line 4535 "nuweb.w" void lookup(int n, Arglist * par, char * arg[9], Name **name, Arglist ** args) { @@ -482,6 +598,8 @@ lookup(int n, Arglist * par, char * arg[9], Name **name, Arglist ** args) *args = p->args; } } + +#line 4557 "nuweb.w" Arglist * instance(Arglist * a, Arglist * par, char * arg[9], int * ch) { if (a != NULL) { @@ -489,6 +607,8 @@ Arglist * instance(Arglist * a, Arglist * par, char * arg[9], int * ch) Arglist *args, *next; Name* name; /* Set up name, args and next */ + +#line 4579 "nuweb.w" next = instance(a->next, par, arg, &changed); name = a->name; if (name == (Name *)1) { @@ -509,21 +629,27 @@ Arglist * instance(Arglist * a, Arglist * par, char * arg[9], int * ch) args = a->args; } } +#line 4563 "nuweb.w" + if (changed){ /* Build a new arglist */ + +#line 4601 "nuweb.w" a = (Arglist *)arena_getmem(sizeof(Arglist)); a->name = name; a->args = args; a->next = next; +#line 4565 "nuweb.w" + *ch = 1; } } return a; } -static Arglist *pop_scrap_name(manager, parameters) - Manager *manager; - Parameters *parameters; + +#line 4607 "nuweb.w" +static Arglist *pop_scrap_name(Manager *manager, Parameters *parameters) { char name[MAX_NAME_LEN]; char *p = name; @@ -544,10 +670,14 @@ static Arglist *pop_scrap_name(manager, parameters) exit(-1); } /* Check for end of scrap name */ + +#line 4634 "nuweb.w" { c = pop(manager); /* Check for macro parameters */ +#line 1925 "nuweb.w" + if (c == '(') { Parameters res = arena_getmem(10 * sizeof(int)); int *p2 = res; @@ -579,31 +709,28 @@ static Arglist *pop_scrap_name(manager, parameters) *parameters = res; } +#line 4636 "nuweb.w" + } +#line 4627 "nuweb.w" + return args; } -int write_scraps(file, spelling, defs, global_indent, indent_chars, - debug_flag, tab_flag, indent_flag, - comment_flag, inArgs, inParams, parameters, title) - FILE *file; - char * spelling; - Scrap_Node *defs; - int global_indent; - char *indent_chars; - char debug_flag; - char tab_flag; - char indent_flag; - unsigned char comment_flag; - Arglist * inArgs; - char * inParams[9]; - Parameters parameters; - char * title; + +#line 4640 "nuweb.w" +int write_scraps(FILE *file, char *spelling, Scrap_Node *defs, + int global_indent, char *indent_chars, char debug_flag, + char tab_flag, char indent_flag, + unsigned char comment_flag, Arglist *inArgs, + char *inParams[9], Parameters parameters, char *title) { /* This is in file scraps.c */ int indent = 0; int newline = 1; while (defs) { /* Copy \verb|defs->scrap| to \verb|file| */ + +#line 4662 "nuweb.w" { char c; Manager reader; @@ -612,17 +739,27 @@ int write_scraps(file, spelling, defs, global_indent, indent_chars, reader.scrap = scrap_array(defs->scrap).slab; reader.index = 0; /* Insert debugging information if required */ + +#line 4726 "nuweb.w" if (debug_flag) { fprintf(file, "\n#line %d \"%s\"\n", line_number, scrap_array(defs->scrap).file_name); /* Insert appropriate indentation */ + +#line 4734 "nuweb.w" { char c1 = pop(&reader); char c2 = pop(&reader); - if (indent_flag && !(c1 == '\n' - || (c1 == nw_char && (c2 == '#' || (delayed_indent |= (c2 == '<')))))) { + if (indent_flag && !( +#line 4760 "nuweb.w" + c1 == '\n' + || (c1 == nw_char && (c2 == '#' || (delayed_indent |= (c2 == '<')))) +#line 4738 "nuweb.w" + )) { /* Put out the indent */ + +#line 4746 "nuweb.w" if (tab_flag) for (indent=0; indent= 0) { /* Add more indentation ''\t'' */ + +#line 4714 "nuweb.w" { if (global_indent + indent >= MAX_INDENT) { fprintf(stderr, @@ -715,27 +890,37 @@ int write_scraps(file, spelling, defs, global_indent, indent_chars, } indent_chars[global_indent + indent] = '\t'; } +#line 4770 "nuweb.w" + } indent++; } } +#line 4690 "nuweb.w" + delayed_indent = 0; break; default: if (c==nw_char) { /* Check for macro invocation in scrap */ + +#line 4778 "nuweb.w" { int oldin = indent; char oldcf = comment_flag; c = pop(&reader); switch (c) { - case 't': { + case 't': +#line 4901 "nuweb.w" + { char * p = title; Arglist *q = inArgs; int narg; /* Comment this macro use */ + +#line 4914 "nuweb.w" narg = 0; while (*p != '\000') { if (*p == ARG_CHR) { @@ -755,27 +940,39 @@ int write_scraps(file, spelling, defs, global_indent, indent_chars, else fputc(*p++, file); } +#line 4906 "nuweb.w" + if (xref_flag) { putc(' ', file); write_single_scrap_ref(file, defs->scrap); } } +#line 4783 "nuweb.w" + break; - case 'c': { + case 'c': +#line 1738 "nuweb.w" + { int bgn = indent + global_indent; int posn = bgn + strlen(comment_begin[comment_flag]); int i; /* Perhaps put a delayed indent */ + +#line 4895 "nuweb.w" if (delayed_indent) for (i = indent + global_indent; --i >= 0; ) putc(' ', file); +#line 1743 "nuweb.w" + c = pop(&reader); fputs(comment_begin[comment_flag], file); while (c != '\0') { /* Move a word to the file */ + +#line 1767 "nuweb.w" do { putc(c, file); @@ -783,8 +980,14 @@ int write_scraps(file, spelling, defs, global_indent, indent_chars, c = pop(&reader); } while (c > ' '); +#line 1748 "nuweb.w" + /* If we break the line at this word */ + +#line 1776 "nuweb.w" if (c == '\n' || (c == ' ' && posn > 60)) +#line 1749 "nuweb.w" + { putc('\n', file); for (i = 0; i < bgn ; i++) @@ -800,32 +1003,56 @@ int write_scraps(file, spelling, defs, global_indent, indent_chars, fputs(comment_end[comment_flag], file); } +#line 4785 "nuweb.w" + break; - case 'f': if (defs->quoted) + case 'f': +#line 4826 "nuweb.w" + if (defs->quoted) fprintf(file, "%cf", nw_char); else fputs(spelling, file); +#line 4787 "nuweb.w" + break; - case 'x': { + case 'x': +#line 4820 "nuweb.w" + { /* Get label from */ + +#line 6398 "nuweb.w" char label_name[MAX_NAME_LEN]; char * p = label_name; - while (c = pop(&reader), c != nw_char) /* Here is 150a-01 */ + while (c = +#line 4821 "nuweb.w" + pop(&reader), c != nw_char) /* Here is 148c-01 */ *p++ = c; *p = '\0'; - c = pop(&reader); + c = +#line 4821 "nuweb.w" + pop(&reader); +#line 4821 "nuweb.w" + write_label(label_name, file); } +#line 4789 "nuweb.w" + case '_': break; - case 'v': fputs(version_string, file); + case 'v': +#line 2745 "nuweb.w" + fputs(version_string, file); +#line 4791 "nuweb.w" + break; case 's': indent = -global_indent; comment_flag = 0; break; - case '<': { + case '<': +#line 4833 "nuweb.w" + { Arglist *a = pop_scrap_name(&reader, &local_parameters); Name *name = a->name; int changed; @@ -842,14 +1069,22 @@ int write_scraps(file, spelling, defs, global_indent, indent_chars, } if (name->defs && !defs->quoted) { /* Perhaps comment this macro */ + +#line 4878 "nuweb.w" if (comment_flag && newline) { /* Perhaps put a delayed indent */ + +#line 4895 "nuweb.w" if (delayed_indent) for (i = indent + global_indent; --i >= 0; ) putc(' ', file); +#line 4879 "nuweb.w" + fputs(comment_begin[comment_flag], file); /* Comment this macro use */ + +#line 4914 "nuweb.w" narg = 0; while (*p != '\000') { if (*p == ARG_CHR) { @@ -869,6 +1104,8 @@ int write_scraps(file, spelling, defs, global_indent, indent_chars, else fputc(*p++, file); } +#line 4881 "nuweb.w" + if (xref_flag) { putc(' ', file); write_single_scrap_ref(file, name->defs->scrap); @@ -880,6 +1117,8 @@ int write_scraps(file, spelling, defs, global_indent, indent_chars, putc(' ', file); } +#line 4849 "nuweb.w" + name->mark = TRUE; indent = write_scraps(file, spelling, name->defs, global_indent + indent, indent_chars, debug_flag, tab_flag, indent_flag, @@ -900,6 +1139,8 @@ int write_scraps(file, spelling, defs, global_indent, indent_chars, if (name->sector == 0) fputc('+', file); /* Comment this macro use */ + +#line 4914 "nuweb.w" narg = 0; while (*p != '\000') { if (*p == ARG_CHR) { @@ -919,24 +1160,38 @@ int write_scraps(file, spelling, defs, global_indent, indent_chars, else fputc(*p++, file); } +#line 4869 "nuweb.w" + fprintf(file, "%c>", nw_char); if (!defs->quoted && !tex_flag) fprintf(stderr, "%s: macro never defined <%s>\n", command_name, name->spelling); } } +#line 4796 "nuweb.w" + /* Insert debugging information if required */ + +#line 4726 "nuweb.w" if (debug_flag) { fprintf(file, "\n#line %d \"%s\"\n", line_number, scrap_array(defs->scrap).file_name); /* Insert appropriate indentation */ + +#line 4734 "nuweb.w" { char c1 = pop(&reader); char c2 = pop(&reader); - if (indent_flag && !(c1 == '\n' - || (c1 == nw_char && (c2 == '#' || (delayed_indent |= (c2 == '<')))))) { + if (indent_flag && !( +#line 4760 "nuweb.w" + c1 == '\n' + || (c1 == nw_char && (c2 == '#' || (delayed_indent |= (c2 == '<')))) +#line 4738 "nuweb.w" + )) { /* Put out the indent */ + +#line 4746 "nuweb.w" if (tab_flag) for (indent=0; indent= 0; ) putc(' ', file); +#line 4879 "nuweb.w" + fputs(comment_begin[comment_flag], file); /* Comment this macro use */ + +#line 4914 "nuweb.w" narg = 0; while (*p != '\000') { if (*p == ARG_CHR) { @@ -1006,6 +1277,8 @@ int write_scraps(file, spelling, defs, global_indent, indent_chars, else fputc(*p++, file); } +#line 4881 "nuweb.w" + if (xref_flag) { putc(' ', file); write_single_scrap_ref(file, name->defs->scrap); @@ -1017,6 +1290,8 @@ int write_scraps(file, spelling, defs, global_indent, indent_chars, putc(' ', file); } +#line 1850 "nuweb.w" + indent = write_scraps(file, spelling, name->defs, global_indent + indent, indent_chars, debug_flag, @@ -1027,6 +1302,8 @@ int write_scraps(file, spelling, defs, global_indent, indent_chars, else if (args != NULL) { if (delayed_indent) { /* Put out the indent */ + +#line 4746 "nuweb.w" if (tab_flag) for (indent=0; indent= 0) { /* Add more indentation '' '' */ + +#line 4714 "nuweb.w" { if (global_indent + indent >= MAX_INDENT) { fprintf(stderr, @@ -1075,6 +1362,8 @@ int write_scraps(file, spelling, defs, global_indent, indent_chars, } indent_chars[global_indent + indent] = ' '; } +#line 4809 "nuweb.w" + } indent++; break; @@ -1083,11 +1372,15 @@ int write_scraps(file, spelling, defs, global_indent, indent_chars, break; } } +#line 4696 "nuweb.w" + break; } putc(c, file); if (global_indent >= 0) { /* Add more indentation '' '' */ + +#line 4714 "nuweb.w" { if (global_indent + indent >= MAX_INDENT) { fprintf(stderr, @@ -1097,6 +1390,8 @@ int write_scraps(file, spelling, defs, global_indent, indent_chars, } indent_chars[global_indent + indent] = ' '; } +#line 4701 "nuweb.w" + } indent++; if (c > ' ') newline = 0; @@ -1106,12 +1401,15 @@ int write_scraps(file, spelling, defs, global_indent, indent_chars, c = pop(&reader); } } +#line 4650 "nuweb.w" + defs = defs->next; } return indent + global_indent; } -void collect_numbers(aux_name) - char *aux_name; + +#line 4988 "nuweb.w" +void collect_numbers(char *aux_name) { if (number_flag) { int i; @@ -1126,6 +1424,8 @@ void collect_numbers(aux_name) while (fgets(aux_line, 500, aux_file)) { /* Read line in \verb|.aux| file */ +#line 5014 "nuweb.w" + int scrap_number; int page_number; int i; @@ -1146,6 +1446,8 @@ void collect_numbers(aux_name) scrap_array(scrap_number).page = page_number; else /* Warn (only once) about needing to rerun after Latex */ + +#line 4228 "nuweb.w" { if (!already_warned) { fprintf(stderr, "%s: you'll need to rerun nuweb after running latex\n", @@ -1153,63 +1455,95 @@ void collect_numbers(aux_name) already_warned = TRUE; } } +#line 5034 "nuweb.w" + } } +#line 5001 "nuweb.w" + } fclose(aux_file); /* Add letters to scraps with duplicate page numbers */ + +#line 5041 "nuweb.w" { int i = 0; /* Step 'i' to the next valid scrap */ + +#line 5055 "nuweb.w" do i++; while (i < scraps && scrap_array(i).page == -1); +#line 5044 "nuweb.w" + /* For all remaining scraps */ - while (i < scraps) { + +#line 5061 "nuweb.w" + while (i < scraps) +#line 5045 "nuweb.w" + { int j = i; /* Step 'j' to the next valid scrap */ + +#line 5055 "nuweb.w" do j++; while (j < scraps && scrap_array(j).page == -1); +#line 5047 "nuweb.w" + /* Perhaps add letters to the page numbers */ + +#line 5064 "nuweb.w" if (scrap_array(i).page == scrap_array(j).page) { if (scrap_array(i).letter == 0) scrap_array(i).letter = 'a'; scrap_array(j).letter = scrap_array(i).letter + 1; } +#line 5048 "nuweb.w" + i = j; } } +#line 5004 "nuweb.w" + } } } + +#line 5823 "nuweb.w" typedef struct name_node { struct name_node *next; Name *name; } Name_Node; + +#line 5830 "nuweb.w" typedef struct goto_node { Name_Node *output; /* list of words ending in this state */ struct move_node *moves; /* list of possible moves */ struct goto_node *fail; /* and where to go when no move fits */ struct goto_node *next; /* next goto node with same depth */ } Goto_Node; + +#line 5839 "nuweb.w" typedef struct move_node { struct move_node *next; Goto_Node *state; char c; } Move_Node; + +#line 5847 "nuweb.w" static Goto_Node *root[256]; static int max_depth; static Goto_Node **depths; -static Goto_Node *goto_lookup(c, g) - char c; - Goto_Node *g; + +#line 5854 "nuweb.w" +static Goto_Node *goto_lookup(char c, Goto_Node *g) { Move_Node *m = g->moves; while (m && m->c != c) @@ -1219,6 +1553,8 @@ static Goto_Node *goto_lookup(c, g) else return NULL; } + +#line 5869 "nuweb.w" typedef struct ArgMgr_s { char * pv; @@ -1226,11 +1562,15 @@ typedef struct ArgMgr_s Arglist * arg; struct ArgMgr_s * old; } ArgMgr; + +#line 5879 "nuweb.w" typedef struct ArgManager_s { Manager * m; ArgMgr * a; } ArgManager; + +#line 5887 "nuweb.w" static void pushArglist(ArgManager * mgr, Arglist * a) { @@ -1246,6 +1586,8 @@ pushArglist(ArgManager * mgr, Arglist * a) b->old = mgr->a; mgr->a = b; } + +#line 5905 "nuweb.w" static char argpop(ArgManager * mgr) { while (mgr->a != NULL) @@ -1253,6 +1595,8 @@ static char argpop(ArgManager * mgr) ArgMgr * a = mgr->a; /* Perhaps |return| a character from the current arg */ + +#line 5923 "nuweb.w" if (a->pv != NULL) { char c = *a->pv++; @@ -1263,7 +1607,11 @@ static char argpop(ArgManager * mgr) return ' '; } +#line 5911 "nuweb.w" + /* Perhaps start a new arg */ + +#line 5939 "nuweb.w" if (a->arg) { Arglist * b = a->arg; @@ -1275,15 +1623,23 @@ static char argpop(ArgManager * mgr) } else { pushArglist(mgr, b->args); } +#line 5912 "nuweb.w" + /* Otherwise pop the current arg */ + +#line 5952 "nuweb.w" } else { mgr->a = a->old; free(a); } +#line 5913 "nuweb.w" + } return (pop(mgr->m)); } + +#line 5958 "nuweb.w" static char prev_char(ArgManager * mgr, int n) { @@ -1293,6 +1649,8 @@ prev_char(ArgManager * mgr, int n) if (a != NULL) { /* Get the nth previous character from an argument */ + +#line 5976 "nuweb.w" if (a->pv && a->pv - n >= a->bgn) c = *a->pv; else if (a->bgn) { @@ -1304,8 +1662,12 @@ prev_char(ArgManager * mgr, int n) c = ' '; } +#line 5966 "nuweb.w" + } else { /* Get the nth previous character from a scrap */ + +#line 5989 "nuweb.w" int k = m->index - n - 2; if (k >= 0) @@ -1313,14 +1675,18 @@ prev_char(ArgManager * mgr, int n) else if (m->prev) c = m->prev->chars[SLAB_SIZE - k]; +#line 5968 "nuweb.w" + } return c; } -static void build_gotos(); -static int reject_match(); -void search() +#line 6004 "nuweb.w" +static void build_gotos(Name *tree); +static int reject_match(Name *name, char post, ArgManager *reader); + +void search(void) { int i; for (i=0; i<128; i++) @@ -1331,6 +1697,8 @@ void search() depths[i] = NULL; build_gotos(user_names); /* Build failure functions */ + +#line 6090 "nuweb.w" { int depth; for (depth=1; depthoutput) { @@ -1436,12 +1820,17 @@ void search() } } } +#line 6018 "nuweb.w" + } -static void build_gotos(tree) - Name *tree; + +#line 6025 "nuweb.w" +static void build_gotos(Name *tree) { while (tree) { /* Extend goto graph with \verb|tree->spelling| */ + +#line 6036 "nuweb.w" { int depth = 2; char *p = tree->spelling; @@ -1493,11 +1882,15 @@ static void build_gotos(tree) q->output->next = last; q->output->name = tree; } +#line 6028 "nuweb.w" + build_gotos(tree->rlink); tree = tree->llink; } } +#line 6207 "nuweb.w" + static int scrap_is_in(Scrap_Node * list, int i) { while (list != NULL) { @@ -1508,6 +1901,8 @@ static int scrap_is_in(Scrap_Node * list, int i) return FALSE; } +#line 6220 "nuweb.w" + static void add_uses(Uses * * root, Name *name) { int cmp; @@ -1525,17 +1920,23 @@ static void add_uses(Uses * * root, Name *name) } } +#line 6251 "nuweb.w" + void format_uses_refs(FILE * tex_file, int scrap) { Uses * p = scrap_array(scrap).uses; if (p != NULL) /* Write uses references */ + +#line 6262 "nuweb.w" { char join = ' '; fputs("\\item \\NWtxtIdentsUsed\\nobreak\\", tex_file); do { /* Write one use reference */ + +#line 6274 "nuweb.w" Name * name = p->defn; Scrap_Node *defs = name->defs; int first = TRUE, page = -1; @@ -1546,11 +1947,15 @@ format_uses_refs(FILE * tex_file, int scrap) { do { /* Write one referenced scrap */ + +#line 6295 "nuweb.w" fputs("\\NWlink{nuweb", tex_file); write_scrap_ref(tex_file, defs->scrap, -1, &page); fputs("}{", tex_file); write_scrap_ref(tex_file, defs->scrap, first, &page); fputs("}", tex_file); +#line 6283 "nuweb.w" + first = FALSE; defs = defs->next; }while (defs!= NULL); @@ -1560,24 +1965,34 @@ format_uses_refs(FILE * tex_file, int scrap) fputs("\\NWnotglobal", tex_file); } +#line 6266 "nuweb.w" + join = ','; p = p->next; }while (p != NULL); fputs(".", tex_file); } +#line 6257 "nuweb.w" + } +#line 6306 "nuweb.w" + void format_defs_refs(FILE * tex_file, int scrap) { Uses * p = scrap_array(scrap).defs; if (p != NULL) /* Write defs references */ + +#line 6317 "nuweb.w" { char join = ' '; fputs("\\item \\NWtxtIdentsDefed\\nobreak\\", tex_file); do { /* Write one def reference */ + +#line 6329 "nuweb.w" Name * name = p->defn; Scrap_Node *defs = name->uses; int first = TRUE, page = -1; @@ -1592,27 +2007,36 @@ format_defs_refs(FILE * tex_file, int scrap) do { if (defs->scrap != scrap) { /* Write one referenced scrap */ + +#line 6295 "nuweb.w" fputs("\\NWlink{nuweb", tex_file); write_scrap_ref(tex_file, defs->scrap, -1, &page); fputs("}{", tex_file); write_scrap_ref(tex_file, defs->scrap, first, &page); fputs("}", tex_file); +#line 6342 "nuweb.w" + first = FALSE; } defs = defs->next; }while (defs!= NULL); } +#line 6321 "nuweb.w" + join = ','; p = p->next; }while (p != NULL); fputs(".", tex_file); } +#line 6312 "nuweb.w" + } + +#line 6361 "nuweb.w" #define sym_char(c) (isalnum(c) || (c) == '_') -static int op_char(c) - char c; +static int op_char(char c) { switch (c) { case '!': case '#': case '%': case '$': case '^': @@ -1623,10 +2047,9 @@ static int op_char(c) return c==nw_char ? TRUE : FALSE; } } -static int reject_match(name, post, reader) - Name *name; - char post; - ArgManager *reader; + +#line 6377 "nuweb.w" +static int reject_match(Name *name, char post, ArgManager *reader) { int len = strlen(name->spelling); char first = name->spelling[0]; @@ -1636,11 +2059,15 @@ static int reject_match(name, post, reader) if (sym_char(first) && sym_char(prev)) return TRUE; if (op_char(last) && op_char(post)) return TRUE; if (op_char(first) && op_char(prev)) return TRUE; - return FALSE; /* Here is 149b-01 */ + return FALSE; /* Here is 148b-01 */ } + +#line 6407 "nuweb.w" void write_label(char label_name[], FILE * file) /* Search for label(,) */ + +#line 6446 "nuweb.w" { label_node * * plbl = &label_tab; for (;;) @@ -1660,6 +2087,8 @@ write_label(char label_name[], FILE * file) else { /* Write the label to file */ + +#line 6417 "nuweb.w" write_single_scrap_ref(file, lbl->scrap); fprintf(file, "-%02d", lbl->seq); break; @@ -1668,9 +2097,13 @@ write_label(char label_name[], FILE * file) else { /* Complain about missing label */ + +#line 6421 "nuweb.w" fprintf(stderr, "Can't find label %s.\n", label_name); break; } } } +#line 6409 "nuweb.w" +