3 Commits

Author SHA1 Message Date
124b7550ab Move definition on Parameters earlier in global.h
We typedef int * to Parmeters in global.h, but not at the same time as
the other typedefs.  This causes problems when we add a function
declaration for write_scrap().

This also highlights a random `1` being passed as the parameter in one
call to write_scrap().  This is obviously wrong, but the purpose of this
fix is to remove warnings - not do a deep dive into what the code is
doing.
2024-03-15 08:51:38 +00:00
cbcfc68afa Correct prototype of write_tex().
In a reverse of write_html(), write_tex() is declared with three
parameters, but only called with two.

Removing the third parameter is fine as it is unused.
2024-03-15 08:40:54 +00:00
a44adf4baf Correct calls to write_html()
write_html() is declared as taking two parameters, but the call to it
passes three.

We fix this by dropping the third parameter, which was labelled 'DUMMY'
anyway.
2024-03-15 08:33:40 +00:00
13 changed files with 432 additions and 1559 deletions

View File

@@ -1,33 +0,0 @@
name: "BuildTest"
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
jobs:
build:
name: "Build and test"
runs-on: ubuntu-latest
steps:
- name: "Install build deps"
run: |
export DEBIAN_FRONTEND=noninteractive
sudo apt-get update
sudo apt-get -y --no-install-recommends install build-essential \
texlive-latex-base texlive-latex-recommended
- name: "Checkout repo"
uses: actions/checkout@v3
- name: "Bootstrap nuweb"
run: make nuweb
- name: "Make nuweb.tex"
run: make nuweb.tex nuwebdoc.tex
- name: "Build again"
run: make nuweb
- name: "Run tests"
run: make check

23
arena.c
View File

@@ -1,20 +1,13 @@
#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;
#line 6540 "nuweb.w"
void *arena_getmem(size_t n)
void *arena_getmem(n)
size_t n;
{
char *q;
char *p = arena->avail;
@@ -25,8 +18,6 @@ void *arena_getmem(size_t n)
return p;
}
/* Find a new chunk of memory */
#line 6561 "nuweb.w"
{
Chunk *ap = arena;
Chunk *np = ap->next;
@@ -41,8 +32,6 @@ void *arena_getmem(size_t n)
np = ap->next;
}
/* Allocate a new chunk of memory */
#line 6581 "nuweb.w"
{
size_t m = n + 10000;
np = (Chunk *) malloc(m);
@@ -53,15 +42,9 @@ void *arena_getmem(size_t n)
arena = np;
return sizeof(Chunk) + (char *) np;
}
#line 6574 "nuweb.w"
}
#line 6550 "nuweb.w"
}
#line 6598 "nuweb.w"
void arena_free(void)
void arena_free()
{
arena = &first;
}

View File

@@ -1,10 +1,6 @@
#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 ""
@@ -19,11 +15,7 @@
#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;
@@ -46,39 +38,19 @@ 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;
#line 3906 "nuweb.w"
char *source_name = NULL;
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;

161
global.h
View File

@@ -1,9 +1,5 @@
#line 826 "nuweb.w"
/* Include files */
#line 835 "nuweb.w"
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
@@ -11,11 +7,7 @@
#include <signal.h>
#include <locale.h>
#line 826 "nuweb.w"
/* Type declarations */
#line 854 "nuweb.w"
#ifndef FALSE
#define FALSE 0
#endif
@@ -23,21 +15,12 @@
#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;
@@ -52,30 +35,20 @@ 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;
@@ -83,21 +56,13 @@ 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 */
@@ -121,135 +86,62 @@ 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 */
#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"
extern void pass1();
extern void write_tex();
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);
#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 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 */
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*);
#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 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 add_to_use(Name * name, int current_scrap);
#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"
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();
extern int robs_strcmp(char*, char*);
#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 Name *install_args();
extern void search();
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);
#line 6506 "nuweb.w"
extern void *arena_getmem(size_t n);
extern void arena_free(void);
#line 830 "nuweb.w"
extern void *arena_getmem();
extern void arena_free();
/* Operating System Dependencies */
#line 972 "nuweb.w"
#if defined(VMS)
#define PATH_SEP(c) (c==']'||c==':')
#define PATH_SEP_CHAR ""
@@ -263,5 +155,4 @@ extern void arena_free(void);
#define PATH_SEP_CHAR "/"
#define DEFAULT_PATH "."
#endif
#line 831 "nuweb.w"
typedef int *Parameters;

47
html.c
View File

@@ -1,17 +1,14 @@
#include "global.h"
static int scraps = 1;
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)
static void copy_scrap(); /* formats the body of a scrap */
static void display_scrap_ref(); /* formats a scrap reference */
static void display_scrap_numbers(); /* formats a list of scrap numbers */
static void print_scrap_numbers(); /* pluralizes scrap formats list */
static void format_entry(); /* formats an index entry */
static void format_user_entry();
void write_html(file_name, html_name)
char *file_name;
char *html_name;
{
FILE *html_file = fopen(html_name, "w");
FILE *tex_file = html_file;
@@ -186,7 +183,9 @@ void write_html(char *file_name, char *html_name)
else
fprintf(stderr, "%s: can't open %s\n", command_name, html_name);
}
static void display_scrap_ref(FILE *html_file, int num)
static void display_scrap_ref(html_file, num)
FILE *html_file;
int num;
{
fputs("<a href=\"#nuweb", html_file);
write_single_scrap_ref(html_file, num);
@@ -194,7 +193,9 @@ static void display_scrap_ref(FILE *html_file, int num)
write_single_scrap_ref(html_file, num);
fputs("</a>", html_file);
}
static void display_scrap_numbers(FILE *html_file, Scrap_Node *scraps)
static void display_scrap_numbers(html_file, scraps)
FILE *html_file;
Scrap_Node *scraps;
{
display_scrap_ref(html_file, scraps->scrap);
scraps = scraps->next;
@@ -204,12 +205,16 @@ static void display_scrap_numbers(FILE *html_file, Scrap_Node *scraps)
scraps = scraps->next;
}
}
static void print_scrap_numbers(FILE *html_file, Scrap_Node *scraps)
static void print_scrap_numbers(html_file, scraps)
FILE *html_file;
Scrap_Node *scraps;
{
display_scrap_numbers(html_file, scraps);
fputs(".\n", html_file);
}
static void copy_scrap(FILE *file, int prefix)
static void copy_scrap(file, prefix)
FILE *file;
int prefix;
{
int indent = 0;
int c = source_get();
@@ -348,7 +353,10 @@ static void copy_scrap(FILE *file, int prefix)
c = source_get();
}
}
static void format_entry(Name *name, FILE *html_file, int file_flag)
static void format_entry(name, html_file, file_flag)
Name *name;
FILE *html_file;
int file_flag;
{
while (name) {
format_entry(name->llink, html_file, file_flag);
@@ -387,7 +395,10 @@ static void format_entry(Name *name, FILE *html_file, int file_flag)
name = name->rlink;
}
}
static void format_user_entry(Name *name, FILE *html_file, int sector)
static void format_user_entry(name, html_file, sector)
Name *name;
FILE *html_file;
int sector;
{
while (name) {
format_user_entry(name->llink, html_file, sector);

37
input.c
View File

@@ -1,31 +1,21 @@
#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(void)
int source_get()
{
int c;
source_last = c = source_peek;
switch (c) {
case EOF:
#line 4088 "nuweb.w"
{
case EOF: {
fclose(source_file);
if (include_depth) {
include_depth--;
@@ -36,16 +26,12 @@ int source_get(void)
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) {
@@ -55,9 +41,7 @@ int source_get(void)
}
else
switch (c) {
case 'i':
#line 4027 "nuweb.w"
{
case 'i': {
char name[FILENAME_MAX];
char fullname[FILENAME_MAX];
struct incl * p = include_list;
@@ -68,8 +52,6 @@ int source_get(void)
exit(-1);
}
/* Collect include-file name */
#line 4067 "nuweb.w"
{
char *p = name;
do
@@ -86,8 +68,6 @@ int source_get(void)
exit(-1);
}
}
#line 4037 "nuweb.w"
stack[include_depth].file = source_file;
fullname[0] = '\0';
for (;;) {
@@ -115,8 +95,6 @@ int source_get(void)
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':
@@ -147,16 +125,12 @@ int source_get(void)
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);
@@ -164,9 +138,8 @@ void source_ungetc(int *c)
source_line--;
source_peek=*c;
}
#line 4107 "nuweb.w"
void source_open(char *name)
void source_open(name)
char *name;
{
source_file = fopen(name, "r");
if (!source_file) {

413
latex.c
View File

@@ -1,25 +1,17 @@
#line 893 "nuweb.w"
#include "global.h"
static int scraps = 1;
#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)
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;
{
FILE *tex_file = fopen(tex_name, "w");
if (tex_file) {
@@ -27,8 +19,6 @@ void write_tex(char *file_name, char *tex_name)
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);
@@ -52,19 +42,11 @@ void write_tex(char *file_name, char *tex_name)
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();
@@ -72,8 +54,6 @@ void write_tex(char *file_name, char *tex_name)
if (c == nw_char)
{
/* Interpret at-sequence */
#line 2135 "nuweb.w"
{
int big_definition = FALSE;
c = source_get();
@@ -84,26 +64,18 @@ void write_tex(char *file_name, char *tex_name)
update_delimit_scrap();
break;
case 'O': big_definition = TRUE;
case 'o':
#line 2259 "nuweb.w"
{
case 'o': {
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);
}
@@ -112,27 +84,17 @@ void write_tex(char *file_name, char *tex_name)
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);
@@ -140,19 +102,13 @@ void write_tex(char *file_name, char *tex_name)
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);
@@ -160,12 +116,8 @@ void write_tex(char *file_name, char *tex_name)
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) {
@@ -178,23 +130,15 @@ void write_tex(char *file_name, char *tex_name)
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)
@@ -202,48 +146,32 @@ void write_tex(char *file_name, char *tex_name)
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':
#line 2284 "nuweb.w"
{
case 'd': {
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);
}
@@ -252,33 +180,21 @@ void write_tex(char *file_name, char *tex_name)
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;
@@ -292,25 +208,17 @@ void write_tex(char *file_name, char *tex_name)
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);
@@ -318,22 +226,14 @@ void write_tex(char *file_name, char *tex_name)
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) {
@@ -356,22 +256,14 @@ void write_tex(char *file_name, char *tex_name)
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)
@@ -379,59 +271,37 @@ void write_tex(char *file_name, char *tex_name)
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 '(':
#line 2426 "nuweb.w"
copy_scrap(tex_file, FALSE, NULL);
case '(': copy_scrap(tex_file, FALSE, NULL);
c = source_get();
#line 2160 "nuweb.w"
break;
case '<':
#line 2192 "nuweb.w"
{
case '<': {
Parameters local_parameters = 0;
int changed;
char indent_chars[MAX_INDENT];
@@ -448,66 +318,36 @@ void write_tex(char *file_name, char *tex_name)
c = source_get();
}
#line 2162 "nuweb.w"
break;
case 'x':
#line 2749 "nuweb.w"
{
case 'x': {
/* Get label from */
#line 6398 "nuweb.w"
char label_name[MAX_NAME_LEN];
char * p = label_name;
while (c =
#line 2750 "nuweb.w"
source_get(), c != nw_char) /* Here is 148c-01 */
while (c = source_get(), c != nw_char) /* Here is 150a-01 */
*p++ = c;
*p = '\0';
c =
#line 2750 "nuweb.w"
source_get();
c = source_get();
#line 2750 "nuweb.w"
write_label(label_name,
#line 2164 "nuweb.w"
tex_file);
write_label(label_name, tex_file);
}
#line 2164 "nuweb.w"
c = source_get();
break;
case 'c':
#line 1785 "nuweb.w"
if (inBlock)
case 'c': 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':
#line 2915 "nuweb.w"
{
case 'f': {
if (file_names) {
fputs("\n{\\small\\begin{list}{}{\\setlength{\\itemsep}{-\\parsep}",
tex_file);
@@ -517,12 +357,8 @@ void write_tex(char *file_name, char *tex_name)
}
c = source_get();
}
#line 2170 "nuweb.w"
break;
case 'm':
#line 2965 "nuweb.w"
{
case 'm': {
unsigned char sector = current_sector;
int c = source_get();
if (c == '+')
@@ -541,12 +377,8 @@ void write_tex(char *file_name, char *tex_name)
}
c = source_get();
#line 2172 "nuweb.w"
break;
case 'u':
#line 3118 "nuweb.w"
{
case 'u': {
unsigned char sector = current_sector;
c = source_get();
if (c == '+') {
@@ -561,16 +393,10 @@ void write_tex(char *file_name, char *tex_name)
fputs("\\end{list}}", tex_file);
}
}
#line 2174 "nuweb.w"
break;
case 'v':
#line 2187 "nuweb.w"
fputs(version_string, tex_file);
case 'v': fputs(version_string, tex_file);
c = source_get();
#line 2176 "nuweb.w"
break;
default:
if (c==nw_char)
@@ -579,8 +405,6 @@ void write_tex(char *file_name, char *tex_name)
break;
}
}
#line 2125 "nuweb.w"
}
else {
putc(c, tex_file);
@@ -588,15 +412,11 @@ void write_tex(char *file_name, char *tex_name)
}
}
}
#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);
@@ -619,9 +439,9 @@ static void write_arg(FILE * tex_file, char * p)
fputs("\\/}", tex_file);
}
#line 2498 "nuweb.w"
static void print_scrap_numbers(FILE *tex_file, Scrap_Node *scraps)
static void print_scrap_numbers(tex_file, scraps)
FILE *tex_file;
Scrap_Node *scraps;
{
int page;
fputs("\\NWlink{nuweb", tex_file);
@@ -640,8 +460,6 @@ static void print_scrap_numbers(FILE *tex_file, Scrap_Node *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{}", "\\\\" },
@@ -652,8 +470,6 @@ 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++) {
@@ -679,11 +495,7 @@ 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);
@@ -696,9 +508,10 @@ static void write_literal(FILE * tex_file, char * p, int mode)
}
fputs(delimit_scrap[mode][1], tex_file);
}
#line 2605 "nuweb.w"
static void copy_scrap(FILE *file, int prefix, Name *name)
static void copy_scrap(file, prefix, name)
FILE *file;
int prefix;
Name * name;
{
int indent = 0;
int c;
@@ -718,9 +531,7 @@ static void copy_scrap(FILE *file, int prefix, Name *name)
fputs(delimit_scrap[scrap_type][0], file);
indent = 0;
break;
case '\t':
#line 2680 "nuweb.w"
{
case '\t': {
int delta = 8 - (indent % 8);
indent += delta;
while (delta > 0) {
@@ -728,69 +539,41 @@ static void copy_scrap(FILE *file, int prefix, Name *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':
#line 1714 "nuweb.w"
{
case 'c': {
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':
#line 2749 "nuweb.w"
{
case 'x': {
/* Get label from */
#line 6398 "nuweb.w"
char label_name[MAX_NAME_LEN];
char * p = label_name;
while (c =
#line 2750 "nuweb.w"
source_get(), c != nw_char) /* Here is 148c-01 */
while (c = source_get(), c != nw_char) /* Here is 150a-01 */
*p++ = c;
*p = '\0';
c =
#line 2750 "nuweb.w"
source_get();
c = source_get();
#line 2750 "nuweb.w"
write_label(label_name,
#line 2695 "nuweb.w"
file);
write_label(label_name, file);
}
#line 2695 "nuweb.w"
break;
case 'v':
#line 2745 "nuweb.w"
fputs(version_string, file);
case 'v': fputs(version_string, file);
#line 2697 "nuweb.w"
case 's':
break;
case '+':
case '-':
case '*':
case '|':
#line 2758 "nuweb.w"
{
case '|': {
do {
do
c = source_get();
@@ -798,16 +581,12 @@ static void copy_scrap(FILE *file, int prefix, Name *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 '<':
#line 2798 "nuweb.w"
{
case '<': {
Arglist *args = collect_scrap_name(-1);
Name *name = args->name;
char * p = name->spelling;
@@ -837,8 +616,6 @@ static void copy_scrap(FILE *file, int prefix, Name *name)
if (scrap_name_has_parameters) {
/* Format macro parameters */
#line 1962 "nuweb.w"
char sep;
sep = '(';
@@ -865,14 +642,10 @@ static void copy_scrap(FILE *file, int prefix, Name *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);
@@ -884,8 +657,6 @@ static void copy_scrap(FILE *file, int prefix, Name *name)
if (p)
fputs(", \\ldots\\ ", file);
}
#line 2830 "nuweb.w"
else {
putc('?', file);
fprintf(stderr, "%s: never defined <%s>\n",
@@ -896,22 +667,14 @@ static void copy_scrap(FILE *file, int prefix, Name *name)
fputs("}", file);
fputs(delimit_scrap[scrap_type][0], file);
}
#line 2709 "nuweb.w"
break;
case '%':
#line 2768 "nuweb.w"
{
case '%': {
do
c = source_get();
while (c != '\n');
}
#line 2711 "nuweb.w"
break;
case '_':
#line 2777 "nuweb.w"
{
case '_': {
fputs(delimit_scrap[scrap_type][1],file);
fprintf(file, "\\hbox{\\sffamily\\bfseries ");
c = source_get();
@@ -923,28 +686,18 @@ static void copy_scrap(FILE *file, int prefix, Name *name)
fprintf(file, "}");
fputs(delimit_scrap[scrap_type][0], file);
}
#line 2713 "nuweb.w"
break;
case 't':
#line 2791 "nuweb.w"
{
case 't': {
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':
#line 2791 "nuweb.w"
{
case 'f': {
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':
@@ -970,8 +723,6 @@ static void copy_scrap(FILE *file, int prefix, Name *name)
break;
}
}
#line 2630 "nuweb.w"
break;
}
putc(c, file);
@@ -981,8 +732,6 @@ static void copy_scrap(FILE *file, int prefix, Name *name)
c = source_get();
}
}
#line 2646 "nuweb.w"
void update_delimit_scrap()
{
/* {}-mode begin */
@@ -1010,8 +759,6 @@ 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)
{
@@ -1054,8 +801,6 @@ write_ArglistElement(FILE * file, Arglist * args, char ** params)
/* Format macro parameters */
#line 1962 "nuweb.w"
char sep;
sep = '(';
@@ -1082,14 +827,10 @@ 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);
@@ -1101,8 +842,6 @@ 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",
@@ -1111,21 +850,17 @@ write_ArglistElement(FILE * file, Arglist * args, char ** params)
fputs("}$\\,\\rangle$", file);
}
}
#line 2927 "nuweb.w"
static void format_file_entry(Name *name, FILE *tex_file)
static void format_file_entry(name, tex_file)
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) {
@@ -1144,16 +879,10 @@ static void format_file_entry(Name *name, FILE *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) {
@@ -1163,17 +892,16 @@ static int load_entry(Name * name, Name ** nms, int n)
}
return n;
}
#line 2998 "nuweb.w"
static void format_entry(Name *name, FILE *tex_file, unsigned char sector)
static void format_entry(name, tex_file, sector)
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 <Rob's ordering> */
#line 3018 "nuweb.w"
int j;
for (j = 1; j < n; j++)
{
@@ -1184,9 +912,7 @@ static void format_entry(Name *name, FILE *tex_file, unsigned char sector)
{
Name * ki = nms[i];
if (
#line 3015 "nuweb.w"
robs_strcmp(ki->spelling, kj->spelling) < 0)
if (robs_strcmp(ki->spelling, kj->spelling) < 0)
break;
nms[i + 1] = ki;
i -= 1;
@@ -1194,21 +920,15 @@ static void format_entry(Name *name, FILE *tex_file, unsigned char 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;
@@ -1222,12 +942,8 @@ static void format_entry(Name *name, FILE *tex_file, unsigned char 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) {
@@ -1250,12 +966,8 @@ static void format_entry(Name *name, FILE *tex_file, unsigned char 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);
@@ -1280,16 +992,10 @@ static void format_entry(Name *name, FILE *tex_file, unsigned char 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) {
@@ -1301,15 +1007,14 @@ int has_sector(Name * name, unsigned char sector)
}
return FALSE;
}
#line 3136 "nuweb.w"
static void format_user_entry(Name *name, FILE *tex_file, unsigned char sector)
static void format_user_entry(name, tex_file, sector)
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 ) {
@@ -1376,8 +1081,6 @@ static void format_user_entry(Name *name, FILE *tex_file, unsigned char sector)
fputs(".\n", tex_file);
}
}
#line 3140 "nuweb.w"
name = name->rlink;
}
}

60
main.c
View File

@@ -1,25 +1,17 @@
#line 878 "nuweb.w"
#include "global.h"
#line 955 "nuweb.w"
#include <stdlib.h>
int main(int argc, char** argv)
int main(argc, argv)
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) {
@@ -64,12 +56,8 @@ int main(int argc, char** argv)
}
HasValue:;
}
#line 1122 "nuweb.w"
arg++;
/* Perhaps get the prepend path */
#line 1186 "nuweb.w"
if (prepend_flag)
{
if (*s == '\0')
@@ -78,11 +66,7 @@ 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')
@@ -91,11 +75,7 @@ HasValue:;
version_info_flag = FALSE;
}
#line 1125 "nuweb.w"
/* Perhaps get the hyperref options */
#line 1224 "nuweb.w"
if (hyperopt_flag)
{
if (*s == '\0')
@@ -105,11 +85,7 @@ HasValue:;
hyperref_flag = TRUE;
}
#line 1126 "nuweb.w"
/* Perhaps add an include path */
#line 1196 "nuweb.w"
if (includepath_flag)
{
struct incl * le
@@ -126,17 +102,11 @@ 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");
@@ -148,12 +118,8 @@ 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);
@@ -162,15 +128,11 @@ 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;
@@ -188,8 +150,6 @@ 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));
@@ -205,8 +165,6 @@ HasValue:;
*trim = sv;
}
#line 1320 "nuweb.w"
*q = '\0';
if (dot) {
*dot = '\0'; /* produce HTML when the file extension is ".hw" */
@@ -223,11 +181,7 @@ HasValue:;
*q = '\0';
}
}
#line 1285 "nuweb.w"
/* Process a file */
#line 1370 "nuweb.w"
{
pass1(source_name);
current_sector = 1;
@@ -237,7 +191,7 @@ HasValue:;
int saved_number_flag = number_flag;
number_flag = TRUE;
collect_numbers(aux_name);
write_html(source_name, tex_name);
write_html(source_name, tex_name, 0/*Dummy */);
number_flag = saved_number_flag;
}
else {
@@ -249,15 +203,9 @@ 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);
}

167
names.c
View File

@@ -1,11 +1,9 @@
#line 932 "nuweb.w"
#include "global.h"
#line 5126 "nuweb.w"
enum { LESS, GREATER, EQUAL, PREFIX, EXTENSION };
static int compare(char *x, char *y)
static int compare(x, y)
char *x;
char *y;
{
int len, result;
int xl = strlen(x);
@@ -28,22 +26,21 @@ static int compare(char *x, char *y)
}
else return EQUAL;
}
#line 5155 "nuweb.w"
char *save_string(char *s)
char *save_string(s)
char *s;
{
char *new = (char *) arena_getmem((strlen(s) + 1) * sizeof(char));
strcpy(new, s);
return new;
}
#line 5164 "nuweb.w"
static int ambiguous_prefix(Name *node, char *spelling,
unsigned char sector);
static int ambiguous_prefix();
static char * found_name = NULL;
Name *prefix_add(Name **rt, char *spelling, unsigned char sector)
Name *prefix_add(rt, spelling, sector)
Name **rt;
char *spelling;
unsigned char sector;
{
Name *node = *rt;
int cmp;
@@ -67,24 +64,18 @@ Name *prefix_add(Name **rt, char *spelling, unsigned char sector)
if (cmp == EXTENSION)
node->spelling = save_string(spelling);
return node;
case PREFIX:
#line 5207 "nuweb.w"
{
case PREFIX: {
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)
@@ -113,12 +104,11 @@ Name *prefix_add(Name **rt, char *spelling, unsigned char sector)
*rt = node;
return node;
}
#line 5198 "nuweb.w"
}
#line 5216 "nuweb.w"
static int ambiguous_prefix(Name *node, char *spelling, unsigned char sector)
static int ambiguous_prefix(node, spelling, sector)
Name *node;
char *spelling;
unsigned char sector;
{
while (node) {
switch (compare(node->spelling, spelling)) {
@@ -141,8 +131,6 @@ static int ambiguous_prefix(Name *node, char *spelling, unsigned char sector)
}
return FALSE;
}
#line 5264 "nuweb.w"
int robs_strcmp(char* x, char* y)
{
int cmp = 0;
@@ -150,21 +138,13 @@ 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)
@@ -185,9 +165,10 @@ int robs_strcmp(char* x, char* y)
return -2;
return cmp;
}
#line 5303 "nuweb.w"
Name *name_add(Name **rt, char *spelling, unsigned char sector)
Name *name_add(rt, spelling, sector)
Name **rt;
char *spelling;
unsigned char sector;
{
Name *node = *rt;
while (node) {
@@ -209,8 +190,6 @@ Name *name_add(Name **rt, char *spelling, unsigned char 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)
@@ -239,12 +218,8 @@ Name *name_add(Name **rt, char *spelling, unsigned char sector)
*rt = node;
return node;
}
#line 5324 "nuweb.w"
}
#line 5363 "nuweb.w"
Name *collect_file_name(void)
Name *collect_file_name()
{
Name *new_name;
char name[MAX_NAME_LEN];
@@ -266,8 +241,6 @@ Name *collect_file_name(void)
/* 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))
@@ -282,9 +255,7 @@ Name *collect_file_name(void)
break;
case 'i': new_name->indent_flag = FALSE;
break;
case 'c':
#line 5425 "nuweb.w"
c = source_get();
case 'c': c = source_get();
if (c == 'c')
new_name->comment_flag = 1;
else if (c == '+')
@@ -295,8 +266,6 @@ Name *collect_file_name(void)
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);
@@ -308,8 +277,6 @@ Name *collect_file_name(void)
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",
@@ -318,9 +285,7 @@ Name *collect_file_name(void)
}
return new_name;
}
#line 5446 "nuweb.w"
Name *collect_macro_name(void)
Name *collect_macro_name()
{
char name[MAX_NAME_LEN];
char args[1000];
@@ -347,9 +312,7 @@ Name *collect_macro_name(void)
c = source_get();
while (c == ' ' || c == '\t');
break;
case '\n':
#line 5564 "nuweb.w"
{
case '\n': {
do
c = source_get();
while (isspace(c));
@@ -360,8 +323,6 @@ Name *collect_macro_name(void)
exit(-1);
}
/* Cleanup and install name */
#line 5547 "nuweb.w"
{
if (p > name && p[-1] == ' ')
p--;
@@ -377,26 +338,18 @@ Name *collect_macro_name(void)
*p = '\0';
node = prefix_add(&macro_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 '{':
#line 5547 "nuweb.w"
{
case '{': {
if (p > name && p[-1] == ' ')
p--;
if (p - name > 3 && p[-1] == '.' && p[-2] == '.' && p[-3] == '.') {
@@ -411,26 +364,18 @@ Name *collect_macro_name(void)
*p = '\0';
node = prefix_add(&macro_names, name, sector);
}
#line 5499 "nuweb.w"
return install_args(node, argc, arg);
case '\'':
#line 5517 "nuweb.w"
arg[argc] = argp;
case '\'': 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;
}
@@ -442,8 +387,6 @@ Name *collect_macro_name(void)
}
*p++ = ARG_CHR;
#line 5501 "nuweb.w"
break;
default:
if (c==nw_char)
@@ -457,8 +400,6 @@ Name *collect_macro_name(void)
exit(-1);
}
}
#line 5477 "nuweb.w"
break;
}
*p++ = c;
@@ -471,8 +412,6 @@ Name *collect_macro_name(void)
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;
@@ -483,8 +422,6 @@ 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));
@@ -494,8 +431,6 @@ 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];
@@ -524,8 +459,6 @@ 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;
@@ -534,8 +467,6 @@ 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;
@@ -552,15 +483,9 @@ Arglist * collect_scrap_name(int current_scrap)
}
*s = '\000';
/* Add buff to current arg list */
#line 5774 "nuweb.w"
*tail = buildArglist(NULL, (Arglist *)save_string(buff));
*tail = buildArglist(NULL, (Arglist *)save_string(buff));
tail = &(*tail)->next;
#line 5738 "nuweb.w"
#line 5673 "nuweb.w"
}
*p++ = ARG_CHR;
c = source_get();
@@ -569,30 +494,20 @@ 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 */
#line 5774 "nuweb.w"
*tail = buildArglist(NULL, (Arglist *)save_string(buff));
*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;
@@ -600,31 +515,23 @@ 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--;
@@ -640,14 +547,10 @@ Arglist * collect_scrap_name(int current_scrap)
*p = '\0';
node = prefix_add(&macro_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--;
@@ -663,8 +566,6 @@ Arglist * collect_scrap_name(int current_scrap)
*p = '\0';
node = prefix_add(&macro_names, name, sector);
}
#line 5703 "nuweb.w"
return buildArglist(node, head);
default:
@@ -680,8 +581,6 @@ Arglist * collect_scrap_name(int current_scrap)
exit(-1);
}
}
#line 5644 "nuweb.w"
break;
}
if (!isgraph(c)) {
@@ -700,11 +599,10 @@ 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 */
#line 5779 "nuweb.w"
static Scrap_Node *reverse(Scrap_Node *a); /* a forward declaration */
void reverse_lists(Name *names)
void reverse_lists(names)
Name *names;
{
while (names) {
reverse_lists(names->llink);
@@ -713,9 +611,8 @@ void reverse_lists(Name *names)
names = names->rlink;
}
}
#line 5796 "nuweb.w"
static Scrap_Node *reverse(Scrap_Node *a)
static Scrap_Node *reverse(a)
Scrap_Node *a;
{
if (a) {
Scrap_Node *b = a->next;

293
nuweb.w
View File

@@ -954,7 +954,9 @@ then handles any files listed on the command line.
@o main.c -cc -d
@{
#include <stdlib.h>
int main(int argc, char** argv)
int main(argc, argv)
int argc;
char **argv;
{
int arg = 1;
@<Interpret command-line arguments@>
@@ -1397,7 +1399,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(char *file_name);
@{extern void pass1();
@}
@@ -1411,7 +1413,8 @@ 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(char *file_name)
@{void pass1(file_name)
char *file_name;
{
if (verbose_flag)
fprintf(stderr, "reading %s\n", file_name);
@@ -2031,33 +2034,30 @@ modify nuweb to work with a different typesetting system, this would
be the place to look.
@d Function...
@{extern void write_tex(char *file_name, char *tex_name);
@{extern void write_tex();
@}
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(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);
@{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();
@}
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(char *file_name, char *tex_name)
@{void write_tex(file_name, tex_name)
char *file_name;
char *tex_name;
{
FILE *tex_file = fopen(tex_name, "w");
if (tex_file) {
@@ -2495,7 +2495,9 @@ list.
}@}
@o latex.c -cc -d
@{static void print_scrap_numbers(FILE *tex_file, Scrap_Node *scraps)
@{static void print_scrap_numbers(tex_file, scraps)
FILE *tex_file;
Scrap_Node *scraps;
{
int page;
fputs("\\NWlink{nuweb", tex_file);
@@ -2602,7 +2604,10 @@ command.
@| write_literal @}
@o latex.c -cc -d
@{static void copy_scrap(FILE *file, int prefix, Name *name)
@{static void copy_scrap(file, prefix, name)
FILE *file;
int prefix;
Name * name;
{
int indent = 0;
int c;
@@ -2924,7 +2929,9 @@ write_ArglistElement(FILE * file, Arglist * args, char ** params)
}@}
@o latex.c -cc -d
@{static void format_file_entry(Name *name, FILE *tex_file)
@{static void format_file_entry(name, tex_file)
Name *name;
FILE *tex_file;
{
while (name) {
format_file_entry(name->llink, tex_file);
@@ -2995,7 +3002,10 @@ c = source_get();
@| load_entry @}
@o latex.c -cc -d
@{static void format_entry(Name *name, FILE *tex_file, unsigned char sector)
@{static void format_entry(name, tex_file, sector)
Name *name;
FILE *tex_file;
unsigned char sector;
{
Name ** nms = malloc(num_scraps()*sizeof(Name *));
int n = load_entry(name, nms, 0);
@@ -3133,7 +3143,10 @@ for (j = 1; j < @2; j++)
@o latex.c -cc -d
@{static void format_user_entry(Name *name, FILE *tex_file, unsigned char sector)
@{static void format_user_entry(name, tex_file, sector)
Name *name;
FILE *tex_file;
unsigned char sector;
{
while (name) {
format_user_entry(name->llink, tex_file, sector);
@@ -3224,31 +3237,28 @@ copies most of the text from the source file straight into a
cross-reference information is printed out.
@d Function...
@{extern void write_html(char *file_name, char *html_name);
@{extern void write_html();
@}
We need a few local function declarations before we get into the body
of \verb|write_html|.
@o html.c
@{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);
@{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();
@}
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(char *file_name, char *html_name)
@{void write_html(file_name, html_name)
char *file_name;
char *html_name;
{
FILE *html_file = fopen(html_name, "w");
FILE *tex_file = html_file;
@@ -3461,7 +3471,9 @@ end the paragraph.
}@}
@o html.c
@{static void display_scrap_ref(FILE *html_file, int num)
@{static void display_scrap_ref(html_file, num)
FILE *html_file;
int num;
{
fputs("<a href=\"#nuweb", html_file);
write_single_scrap_ref(html_file, num);
@@ -3472,7 +3484,9 @@ end the paragraph.
@| display_scrap_ref @}
@o html.c
@{static void display_scrap_numbers(FILE *html_file, Scrap_Node *scraps)
@{static void display_scrap_numbers(html_file, scraps)
FILE *html_file;
Scrap_Node *scraps;
{
display_scrap_ref(html_file, scraps->scrap);
scraps = scraps->next;
@@ -3485,7 +3499,9 @@ end the paragraph.
@| display_scrap_numbers @}
@o html.c
@{static void print_scrap_numbers(FILE *html_file, Scrap_Node *scraps)
@{static void print_scrap_numbers(html_file, scraps)
FILE *html_file;
Scrap_Node *scraps;
{
display_scrap_numbers(html_file, scraps);
fputs(".\n", html_file);
@@ -3498,7 +3514,9 @@ end the paragraph.
We must translate HTML special keywords into entities in scraps.
@o html.c
@{static void copy_scrap(FILE *file, int prefix)
@{static void copy_scrap(file, prefix)
FILE *file;
int prefix;
{
int indent = 0;
int c = source_get();
@@ -3641,7 +3659,10 @@ pointed out any during the first pass.
}@}
@o html.c
@{static void format_entry(Name *name, FILE *html_file, int file_flag)
@{static void format_entry(name, html_file, file_flag)
Name *name;
FILE *html_file;
int file_flag;
{
while (name) {
format_entry(name->llink, html_file, file_flag);
@@ -3710,7 +3731,10 @@ pointed out any during the first pass.
@o html.c
@{static void format_user_entry(Name *name, FILE *html_file, int sector)
@{static void format_user_entry(name, html_file, sector)
Name *name;
FILE *html_file;
int sector;
{
while (name) {
format_user_entry(name->llink, html_file, sector);
@@ -3761,11 +3785,12 @@ pointed out any during the first pass.
\section{Writing the Output Files} \label{output-files}
@d Function pro...
@{extern void write_files(Name *files);
@{extern void write_files();
@}
@o output.c -cc -d
@{void write_files(Name *files)
@{void write_files(files)
Name *files;
{
while (files) {
write_files(files->llink);
@@ -3886,10 +3911,8 @@ if (0 != rename(temp_name, real_name)) {
We need two routines to handle reading the source files.
@d Function pro...
@{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 void source_open(); /* pass in the name of the source file */
extern int source_get(); /* 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 */
@}
@@ -3938,7 +3961,7 @@ are defining.
@{
int source_peek;
int source_last;
int source_get(void)
int source_get()
{
int c;
source_last = c = source_peek;
@@ -4104,7 +4127,8 @@ 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(char *name)
@{void source_open(name)
char *name;
{
source_file = fopen(name, "r");
if (!source_file) {
@@ -4161,7 +4185,7 @@ static ScrapEntry *SCRAP[SCRAP_SIZE];
#define scrap_array(i) SCRAP[(i) >> SCRAP_SHIFT][(i) & SCRAP_MASK]
static int scraps;
int num_scraps(void)
int num_scraps()
{
return scraps;
};
@@ -4170,22 +4194,17 @@ int num_scraps(void)
@d Function pro...
@{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);
@{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();
@}
@o scraps.c -cc -d
@{void init_scraps(void)
@{void init_scraps()
{
scraps = 1;
SCRAP[0] = (ScrapEntry *) arena_getmem(SCRAP_SIZE * sizeof(ScrapEntry));
@@ -4193,7 +4212,11 @@ extern int num_scraps(void);
@| init_scraps @}
@o scraps.c -cc -d
@{void write_scrap_ref(FILE *file, int num, int first, int *page)
@{void write_scrap_ref(file, num, first, page)
FILE *file;
int num;
int first;
int *page;
{
if (scrap_array(num).page >= 0) {
if (first!=0)
@@ -4216,7 +4239,9 @@ extern int num_scraps(void);
@| write_scrap_ref @}
@o scraps.c -cc -d
@{void write_single_scrap_ref(FILE *file, int num)
@{void write_single_scrap_ref(file, num)
FILE *file;
int num;
{
int page;
write_scrap_ref(file, num, TRUE, &page);
@@ -4252,7 +4277,9 @@ extern int num_scraps(void);
@o scraps.c -cc -d
@{static void push(char c, Manager *manager)
@{static void push(c, manager)
char c;
Manager *manager;
{
Slab *scrap = manager->scrap;
int index = manager->index;
@@ -4268,7 +4295,9 @@ extern int num_scraps(void);
@| push @}
@o scraps.c -cc -d
@{static void pushs(char *s, Manager *manager)
@{static void pushs(s, manager)
char *s;
Manager *manager;
{
while (*s)
push(*s++, manager);
@@ -4276,7 +4305,7 @@ extern int num_scraps(void);
@| pushs @}
@o scraps.c -cc -d
@{int collect_scrap(void)
@{int collect_scrap()
{
int current_scrap, lblseq = 0;
int depth = 1;
@@ -4501,7 +4530,8 @@ 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)
@{static char pop(manager)
Manager *manager;
{
Slab *scrap = manager->scrap;
int index = manager->index;
@@ -4517,7 +4547,9 @@ add_to_use(Name * name, int current_scrap)
@| pop @}
@o scraps.c -cc -d
@{static void backup(int n, Manager *manager)
@{static void backup(n, manager)
int n;
Manager *manager;
{
int index = manager->index;
if (n > index
@@ -4572,7 +4604,7 @@ lookup(int n, Arglist * par, char * arg[9], Name **name, Arglist ** args)
@| instance @}
@d Function prototypes
@{extern Arglist *instance(Arglist *a, Arglist *par, char *arg[9], int *ch);
@{Arglist * instance();
@}
@d Set up name, args and next
@@ -4604,7 +4636,9 @@ a->args = args;
a->next = next;@}
@o scraps.c -cc -d
@{static Arglist *pop_scrap_name(Manager *manager, Parameters *parameters)
@{static Arglist *pop_scrap_name(manager, parameters)
Manager *manager;
Parameters *parameters;
{
char name[MAX_NAME_LEN];
char *p = name;
@@ -4637,11 +4671,22 @@ a->next = next;@}
}@}
@o scraps.c -cc -d
@{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)
@{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;
{
/* This is in file @f */
int indent = 0;
@@ -4981,11 +5026,12 @@ fputc('>', file);@}
\subsection{Collecting Page Numbers}
@d Function...
@{extern void collect_numbers(char *aux_name);
@{extern void collect_numbers();
@}
@o scraps.c -cc -d
@{void collect_numbers(char *aux_name)
@{void collect_numbers(aux_name)
char *aux_name;
{
if (number_flag) {
int i;
@@ -5113,19 +5159,21 @@ int scrap_ended_with;
@}
@d Function pro...
@{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);
@{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();
@}
@o names.c -cc -d
@{enum { LESS, GREATER, EQUAL, PREFIX, EXTENSION };
static int compare(char *x, char *y)
static int compare(x, y)
char *x;
char *y;
{
int len, result;
int xl = strlen(x);
@@ -5152,7 +5200,8 @@ static int compare(char *x, char *y)
@o names.c -cc -d
@{char *save_string(char *s)
@{char *save_string(s)
char *s;
{
char *new = (char *) arena_getmem((strlen(s) + 1) * sizeof(char));
strcpy(new, s);
@@ -5161,12 +5210,14 @@ static int compare(char *x, char *y)
@| save_string @}
@o names.c -cc -d
@{static int ambiguous_prefix(Name *node, char *spelling,
unsigned char sector);
@{static int ambiguous_prefix();
static char * found_name = NULL;
Name *prefix_add(Name **rt, char *spelling, unsigned char sector)
Name *prefix_add(rt, spelling, sector)
Name **rt;
char *spelling;
unsigned char sector;
{
Name *node = *rt;
int cmp;
@@ -5213,7 +5264,10 @@ continue the search down {\em both\/} branches of the tree.
}@}
@o names.c -cc -d
@{static int ambiguous_prefix(Name *node, char *spelling, unsigned char sector)
@{static int ambiguous_prefix(node, spelling, sector)
Name *node;
char *spelling;
unsigned char sector;
{
while (node) {
switch (compare(node->spelling, spelling)) {
@@ -5300,7 +5354,10 @@ them to be considered for the alphabetical ordering.
@}
@o names.c -cc -d
@{Name *name_add(Name **rt, char *spelling, unsigned char sector)
@{Name *name_add(rt, spelling, sector)
Name **rt;
char *spelling;
unsigned char sector;
{
Name *node = *rt;
while (node) {
@@ -5360,7 +5417,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(void)
@{Name *collect_file_name()
{
Name *new_name;
char name[MAX_NAME_LEN];
@@ -5443,7 +5500,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(void)
@{Name *collect_macro_name()
{
char name[MAX_NAME_LEN];
char args[1000];
@@ -5576,7 +5633,7 @@ while ((c = source_get()) != EOF) {
}@}
@d Function prototypes
@{extern Name *install_args(Name * name, int argc, char *arg[0]);
@{extern Name *install_args();
@}
@o names.c -cc -d
@@ -5776,9 +5833,10 @@ tail = &(*tail)->next;
@}
@o names.c -cc -d
@{static Scrap_Node *reverse(Scrap_Node *a); /* a forward declaration */
@{static Scrap_Node *reverse(); /* a forward declaration */
void reverse_lists(Name *names)
void reverse_lists(names)
Name *names;
{
while (names) {
reverse_lists(names->llink);
@@ -5793,7 +5851,8 @@ 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(Scrap_Node *a)
@{static Scrap_Node *reverse(a)
Scrap_Node *a;
{
if (a) {
Scrap_Node *b = a->next;
@@ -5851,7 +5910,9 @@ static Goto_Node **depths;
@o scraps.c -cc -d
@{static Goto_Node *goto_lookup(char c, Goto_Node *g)
@{static Goto_Node *goto_lookup(c, g)
char c;
Goto_Node *g;
{
Move_Node *m = g->moves;
while (m && m->c != c)
@@ -5997,14 +6058,14 @@ else if (m->prev)
\subsection{Building the Automata}
@d Function pro...
@{extern void search(void);
@{extern void search();
@}
@o scraps.c -cc -d
@{static void build_gotos(Name *tree);
static int reject_match(Name *name, char post, ArgManager *reader);
@{static void build_gotos();
static int reject_match();
void search(void)
void search()
{
int i;
for (i=0; i<128; i++)
@@ -6022,7 +6083,8 @@ void search(void)
@o scraps.c -cc -d
@{static void build_gotos(Name *tree)
@{static void build_gotos(tree)
Name *tree;
{
while (tree) {
@<Extend goto graph with \verb|tree->spelling|@>
@@ -6199,8 +6261,8 @@ void search(void)
@d Forward declarations for scraps.c
@{
static void add_uses(Uses **root, Name *name);
static int scrap_is_in(Scrap_Node * list, int i);
static void add_uses();
static int scrap_is_in();
@}
@o scraps.c -cc -d
@@ -6360,7 +6422,8 @@ 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(char c)
static int op_char(c)
char c;
{
switch (c) {
case '!': case '#': case '%': case '$': case '^':
@@ -6374,7 +6437,10 @@ static int op_char(char c)
@| sym_char op_char @}
@o scraps.c -cc -d
@{static int reject_match(Name *name, char post, ArgManager *reader)
@{static int reject_match(name, post, reader)
Name *name;
char post;
ArgManager *reader;
{
int len = strlen(name->spelling);
char first = name->spelling[0];
@@ -6503,8 +6569,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(size_t n);
extern void arena_free(void);
@{extern void *arena_getmem();
extern void arena_free();
@}
@@ -6537,7 +6603,8 @@ that returned pointers are always aligned. We align to the nearest
4-byte alignment restrictions too.
@o arena.c -cc -d
@{void *arena_getmem(size_t n)
@{void *arena_getmem(n)
size_t n;
{
char *q;
char *p = arena->avail;
@@ -6595,7 +6662,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)
@{void arena_free()
{
arena = &first;
}

View File

@@ -1,15 +1,10 @@
#line 908 "nuweb.w"
#include "global.h"
#line 3768 "nuweb.w"
void write_files(Name *files)
void write_files(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];
@@ -19,8 +14,6 @@ void write_files(Name *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
@@ -45,8 +38,6 @@ void write_files(Name *files)
exit(-1);
}
#line 3796 "nuweb.w"
sprintf(real_name, "%s%s%s", dirpath, path_sep, files->spelling);
if (verbose_flag)
@@ -58,12 +49,8 @@ void write_files(Name *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) {
@@ -81,52 +68,34 @@ void write_files(Name *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;
}
}

85
pass1.c
View File

@@ -1,9 +1,6 @@
#line 885 "nuweb.w"
#include "global.h"
#line 1414 "nuweb.w"
void pass1(char *file_name)
void pass1(file_name)
char *file_name;
{
if (verbose_flag)
fprintf(stderr, "reading %s\n", file_name);
@@ -13,15 +10,11 @@ void pass1(char *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;
@@ -33,14 +26,10 @@ void pass1(char *file_name)
update_delimit_scrap();
break;
case 'O':
case 'o':
#line 1524 "nuweb.w"
{
case 'o': {
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;
@@ -48,23 +37,15 @@ void pass1(char *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':
#line 1532 "nuweb.w"
{
case 'd': {
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;
@@ -72,40 +53,26 @@ void pass1(char *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;
@@ -113,8 +80,6 @@ void pass1(char *file_name)
if (c == nw_char)
/* Skip over at-sign or go to skipped */
#line 1569 "nuweb.w"
{
c = source_get();
switch (c) {
@@ -142,8 +107,6 @@ void pass1(char *file_name)
}
}
#line 1558 "nuweb.w"
}
fprintf(stderr, "%s: unexpected EOF in text at (%s, %d)\n",
command_name, source_name, source_line);
@@ -152,37 +115,25 @@ void pass1(char *file_name)
skipped: ;
}
#line 1473 "nuweb.w"
break;
case 'c':
#line 1600 "nuweb.w"
{
case 'c': {
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')
@@ -210,8 +161,6 @@ void pass1(char *file_name)
*p++ = source_get();
}
#line 1629 "nuweb.w"
}
else if (c == EOF)
{
@@ -222,11 +171,7 @@ void pass1(char *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 == ' ')
@@ -244,34 +189,22 @@ void pass1(char *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':
@@ -287,23 +220,15 @@ void pass1(char *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"
}

607
scraps.c

File diff suppressed because it is too large Load Diff