Give all functions a formal prototype.
This makes the code C89 compliant, and removes all warnings on macOS.
This commit is contained in:
293
nuweb.w
293
nuweb.w
@@ -954,9 +954,7 @@ then handles any files listed on the command line.
|
||||
@o main.c -cc -d
|
||||
@{
|
||||
#include <stdlib.h>
|
||||
int main(argc, argv)
|
||||
int argc;
|
||||
char **argv;
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
int arg = 1;
|
||||
@<Interpret command-line arguments@>
|
||||
@@ -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);
|
||||
@@ -2034,30 +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)
|
||||
char *file_name;
|
||||
char *tex_name;
|
||||
@{void write_tex(char *file_name, char *tex_name)
|
||||
{
|
||||
FILE *tex_file = fopen(tex_name, "w");
|
||||
if (tex_file) {
|
||||
@@ -2495,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);
|
||||
@@ -2604,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;
|
||||
@@ -2929,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);
|
||||
@@ -3002,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);
|
||||
@@ -3143,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);
|
||||
@@ -3237,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;
|
||||
@@ -3471,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("<a href=\"#nuweb", html_file);
|
||||
write_single_scrap_ref(html_file, num);
|
||||
@@ -3484,9 +3472,7 @@ end the paragraph.
|
||||
@| display_scrap_ref @}
|
||||
|
||||
@o html.c
|
||||
@{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;
|
||||
@@ -3499,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);
|
||||
@@ -3514,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();
|
||||
@@ -3659,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);
|
||||
@@ -3731,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);
|
||||
@@ -3785,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);
|
||||
@@ -3911,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 */
|
||||
@}
|
||||
@@ -3961,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;
|
||||
@@ -4127,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) {
|
||||
@@ -4185,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;
|
||||
};
|
||||
@@ -4194,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));
|
||||
@@ -4212,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)
|
||||
@@ -4239,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);
|
||||
@@ -4277,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;
|
||||
@@ -4295,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);
|
||||
@@ -4305,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;
|
||||
@@ -4530,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;
|
||||
@@ -4547,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
|
||||
@@ -4604,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
|
||||
@@ -4636,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;
|
||||
@@ -4671,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;
|
||||
@@ -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) {
|
||||
@<Extend goto graph with \verb|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;
|
||||
}
|
||||
|
Reference in New Issue
Block a user