diff options
Diffstat (limited to 'web/nuweb/msdos/pass1.c')
-rw-r--r-- | web/nuweb/msdos/pass1.c | 116 |
1 files changed, 116 insertions, 0 deletions
diff --git a/web/nuweb/msdos/pass1.c b/web/nuweb/msdos/pass1.c new file mode 100644 index 0000000000..1c8edcf9c4 --- /dev/null +++ b/web/nuweb/msdos/pass1.c @@ -0,0 +1,116 @@ +#include <stdio.h> +#include <string.h> +#include <ctype.h> + +#ifndef FALSE +#define FALSE 0 +#endif +#ifndef TRUE +#define TRUE (!0) +#endif +typedef struct scrap_node { + struct scrap_node *next; + int scrap; +} Scrap_Node; +typedef struct name { + char *spelling; + struct name *llink; + struct name *rlink; + Scrap_Node *defs; + Scrap_Node *uses; + int mark; + char tab_flag; + char indent_flag; + char debug_flag; +} Name; + +int tex_flag; /* if FALSE, don't emit the .tex file */ +int output_flag; /* if FALSE, don't emit the output files */ +int compare_flag; /* if FALSE, overwrite without comparison */ +char *command_name; +char *source_name; /* name of the current file */ +int source_line; /* current line in the source file */ +Name *file_names; +Name *macro_names; +Name *user_names; + +void pass1(); +void write_tex(); +void write_files(); +void source_open(); /* pass in the name of the source file */ +int source_get(); /* no args; returns the next char or EOF */ +void init_scraps(); +int collect_scrap(); +int write_scraps(); +Name *collect_file_name(); +Name *collect_macro_name(); +Name *collect_scrap_name(); +Name *name_add(); +Name *prefix_add(); +char *save_string(); +void reverse_lists(); +void *arena_getmem(); +void arena_free(); + + +void pass1(file_name) + char *file_name; +{ + source_open(file_name); + init_scraps(); + macro_names = NULL; + file_names = NULL; + user_names = NULL; + { + int c = source_get(); + while (c != EOF) { + if (c == '@') + { + c = source_get(); + switch (c) { + case 'O': + case 'o': { + Name *name = collect_file_name(); /* returns a pointer to the name entry */ + int scrap = collect_scrap(); /* returns an index to the scrap */ + { + Scrap_Node *def = (Scrap_Node *) arena_getmem(sizeof(Scrap_Node)); + def->scrap = scrap; + def->next = name->defs; + name->defs = def; + } + } + break; + case 'D': + case 'd': { + Name *name = collect_macro_name(); + int scrap = collect_scrap(); + { + Scrap_Node *def = (Scrap_Node *) arena_getmem(sizeof(Scrap_Node)); + def->scrap = scrap; + def->next = name->defs; + name->defs = def; + } + } + break; + case '@': + case 'u': + case 'm': + case 'f': /* ignore during this pass */ + break; + default: fprintf(stderr, + "%s: unexpected @ sequence ignored (%s, line %d)\n", + command_name, source_name, source_line); + break; + } + } + c = source_get(); + } + } + if (tex_flag) + search(); + { + reverse_lists(file_names); + reverse_lists(macro_names); + reverse_lists(user_names); + } +} |