11 Commits

Author SHA1 Message Date
59b69355ef Update bootstrap files.
All checks were successful
BuildTest / Build and test (pull_request) Successful in 4m8s
2024-03-15 15:31:49 +00:00
b51c8f7a6e Give all functions a formal prototype.
This makes the code C89 compliant, and removes all warnings on macOS.
2024-03-15 15:31:49 +00:00
88f1603b2d 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 15:31:49 +00:00
b993c46cce 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 15:31:49 +00:00
6d436f82a6 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 15:31:49 +00:00
063fdca1ca Fix typo in pull_request workflow
All checks were successful
BuildTest / Build and test (push) Successful in 3m56s
We cannot spell the word "branches"
2024-03-15 15:31:17 +00:00
cead310efc Merge pull request 'And support for Gitea workflow' (#2) from workflows-demo into main
All checks were successful
BuildTest / Build and test (push) Successful in 3m50s
Reviewed-on: http://diskstation1.local:10000/mgrettondann/nuweb/pulls/2
2024-03-15 15:07:41 +00:00
8dd1620936 And support for Gitea workflow
Adds a workflow that will build and test whenever any changes are pushed
to the main branch, or a PR is opened against the main branch.
2024-03-15 15:04:57 +00:00
1dcf5ae370 Output #line directives as part of nuweb tangling.
This makes error location easier.
2024-03-15 08:31:10 +00:00
d8f33c3ce4 Add license
We copy the copyright header from the top of nuweb.w
2024-03-15 08:13:51 +00:00
087732177f Add initial .gitignore file.
We ignore all generated files, apart from the *.c files which are needed
to be able to bootstrap nuweb.
2024-03-15 08:13:02 +00:00
15 changed files with 1751 additions and 521 deletions

View File

@@ -0,0 +1,33 @@
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

11
.gitignore vendored Normal file
View File

@@ -0,0 +1,11 @@
# .gitignore for nuweb
*.o
*.swp
nuweb
nuweb.tex
nuweb.1
*.aux
*.dvi
*.log
*.out
*.toc

92
LICENSE Normal file
View File

@@ -0,0 +1,92 @@
Copyright (c) 1996, Preston Briggs
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
Neither name of the product nor the names of its contributors may
be used to endorse or promote products derived from this software without
specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS
OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Notes:
Update on 2011-12-16 from Keith Harwood.
-- @@s in scrap supresses indent of following fragment expansion
-- @@<Name@@> in text is expanded
Update on 2011-04-20 from Keith Harwood.
-- @@t provide fragment title in output
Changes from 2010-03-11 in the Sourceforge revision history. -- sjw
Updates on 2004-02-23 from Gregor Goldbach
<glauschwuffel@@users.sourceforge.net>
-- new command line option -r which will make nuweb typeset each
NWtarget and NWlink instance with \LaTeX-commands from the hyperref
package. This gives clickable scrap numbers which is very useful
when viewing the document on-line.
Updates on 2004-02-13 from Gregor Goldbach
<glauschwuffel@@users.sourceforge.net>
-- new command line option -l which will make nuweb typeset scraps
with the help of LaTeX's listings packages instead or pure
verbatim.
-- man page corrections and additions.
Updates on 2003-04-24 from Keith Harwood <Keith.Harwood@@vitalmis.com>
-- sectioning commands (@@s and global-plus-sign in scrap names)
-- @@x..@@x labelling
-- @@f current file
-- @@\# suppress indent
This file has been changed by Javier Goizueta <jgoizueta@@jazzfree.es>
on 2001-02-15.
These are the changes:
LANG -- Introduction of \NW macros to substitue language dependent text
DIAM -- Introduction of \NWsep instead of the \diamond separator
HYPER -- Introduction of hyper-references
NAME -- LaTeX formatting of macro names in HTML output
ADJ -- Adjust of the spacing between < and a fragment name
TEMPN -- Fix of the use of tempnam
LINE -- Synchronizing #lines when @@% is used
MAC -- definition of the macros used by LANG,DIAM,HYPER
CHAR -- Introduce @@r to change the nuweb meta character (@@)
TIE -- Replacement of ~ by "\nobreak\ "
SCRAPs-- Elimination of s
DNGL -- Correction: option -d was not working and was misdocumented
--after the CHAR modifications, to be able to specify non-ascii characters
for the scape character, the program must be compiled with the -K
option in Borland compilers or the -funsigned-char in GNU's gcc
to treat char as an unsigned value when converted to int.
To make the program independent of those options, either char
should be changed to unsigned char (bad solution, since unsigned
char should be used for numerical purposes) or attention should
be payed to all char-int conversions. (including comparisons)
--2002-01-15: the TILDE modificiation is necessary because some ties
have been introduced in version 0.93 in troublesome places when
the babel package is used with the spanish.ldf option (which makes
~ an active character).
--2002-01-15: an ``s'' was being added to the NWtxtDefBy and
NWtxtDefBy messages when followed by more than one reference.

23
arena.c
View File

@@ -1,13 +1,20 @@
#line 938 "nuweb.w"
#include "global.h" #include "global.h"
#line 6512 "nuweb.w"
typedef struct chunk { typedef struct chunk {
struct chunk *next; struct chunk *next;
char *limit; char *limit;
char *avail; char *avail;
} Chunk; } Chunk;
#line 6526 "nuweb.w"
static Chunk first = { NULL, NULL, NULL }; static Chunk first = { NULL, NULL, NULL };
static Chunk *arena = &first; static Chunk *arena = &first;
void *arena_getmem(n)
size_t n; #line 6540 "nuweb.w"
void *arena_getmem(size_t n)
{ {
char *q; char *q;
char *p = arena->avail; char *p = arena->avail;
@@ -18,6 +25,8 @@ void *arena_getmem(n)
return p; return p;
} }
/* Find a new chunk of memory */ /* Find a new chunk of memory */
#line 6561 "nuweb.w"
{ {
Chunk *ap = arena; Chunk *ap = arena;
Chunk *np = ap->next; Chunk *np = ap->next;
@@ -32,6 +41,8 @@ void *arena_getmem(n)
np = ap->next; np = ap->next;
} }
/* Allocate a new chunk of memory */ /* Allocate a new chunk of memory */
#line 6581 "nuweb.w"
{ {
size_t m = n + 10000; size_t m = n + 10000;
np = (Chunk *) malloc(m); np = (Chunk *) malloc(m);
@@ -42,9 +53,15 @@ void *arena_getmem(n)
arena = np; arena = np;
return sizeof(Chunk) + (char *) np; return sizeof(Chunk) + (char *) np;
} }
#line 6574 "nuweb.w"
} }
#line 6550 "nuweb.w"
} }
void arena_free()
#line 6598 "nuweb.w"
void arena_free(void)
{ {
arena = &first; arena = &first;
} }

View File

@@ -1,6 +1,10 @@
#line 944 "nuweb.w"
#include "global.h" #include "global.h"
/* Operating System Dependencies */ /* Operating System Dependencies */
#line 972 "nuweb.w"
#if defined(VMS) #if defined(VMS)
#define PATH_SEP(c) (c==']'||c==':') #define PATH_SEP(c) (c==']'||c==':')
#define PATH_SEP_CHAR "" #define PATH_SEP_CHAR ""
@@ -15,7 +19,11 @@
#define DEFAULT_PATH "." #define DEFAULT_PATH "."
#endif #endif
#line 945 "nuweb.w"
/* Global variable definitions */ /* Global variable definitions */
#line 1067 "nuweb.w"
int tex_flag = TRUE; int tex_flag = TRUE;
int html_flag = FALSE; int html_flag = FALSE;
int output_flag = TRUE; int output_flag = TRUE;
@@ -38,19 +46,39 @@ char * hyperoptions = "";
int includepath_flag = FALSE; /* Do we have an include path? */ int includepath_flag = FALSE; /* Do we have an include path? */
struct incl * include_list = NULL; struct incl * include_list = NULL;
/* The list of include paths */ /* The list of include paths */
#line 1097 "nuweb.w"
int nw_char='@'; int nw_char='@';
#line 1108 "nuweb.w"
char *command_name = NULL; char *command_name = NULL;
#line 1510 "nuweb.w"
unsigned char current_sector = 1; unsigned char current_sector = 1;
unsigned char prev_sector = 1; unsigned char prev_sector = 1;
#line 1707 "nuweb.w"
char blockBuff[6400]; char blockBuff[6400];
#line 2422 "nuweb.w"
int extra_scraps = 0; int extra_scraps = 0;
#line 3906 "nuweb.w"
char *source_name = NULL; char *source_name = NULL;
int source_line = 0; int source_line = 0;
#line 4241 "nuweb.w"
int already_warned = 0; int already_warned = 0;
#line 5108 "nuweb.w"
Name *file_names = NULL; Name *file_names = NULL;
Name *macro_names = NULL; Name *macro_names = NULL;
Name *user_names = NULL; Name *user_names = NULL;
int scrap_name_has_parameters; int scrap_name_has_parameters;
int scrap_ended_with; int scrap_ended_with;
#line 946 "nuweb.w"
#line 6478 "nuweb.w"
label_node * label_tab = NULL; label_node * label_tab = NULL;

161
global.h
View File

@@ -1,5 +1,9 @@
#line 826 "nuweb.w"
/* Include files */ /* Include files */
#line 835 "nuweb.w"
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
@@ -7,7 +11,11 @@
#include <signal.h> #include <signal.h>
#include <locale.h> #include <locale.h>
#line 826 "nuweb.w"
/* Type declarations */ /* Type declarations */
#line 854 "nuweb.w"
#ifndef FALSE #ifndef FALSE
#define FALSE 0 #define FALSE 0
#endif #endif
@@ -15,12 +23,21 @@
#define TRUE 1 #define TRUE 1
#endif #endif
#line 1815 "nuweb.w"
typedef int *Parameters;
#line 3784 "nuweb.w"
#define MAX_INDENT 500 #define MAX_INDENT 500
#line 5074 "nuweb.w"
typedef struct scrap_node { typedef struct scrap_node {
struct scrap_node *next; struct scrap_node *next;
int scrap; int scrap;
char quoted; char quoted;
} Scrap_Node; } Scrap_Node;
#line 5083 "nuweb.w"
typedef struct name { typedef struct name {
char *spelling; char *spelling;
struct name *llink; struct name *llink;
@@ -35,20 +52,30 @@ typedef struct name {
unsigned char comment_flag; unsigned char comment_flag;
unsigned char sector; unsigned char sector;
} Name; } Name;
#line 5536 "nuweb.w"
#define ARG_CHR '\001' #define ARG_CHR '\001'
#line 5596 "nuweb.w"
typedef struct arglist typedef struct arglist
{Name * name; {Name * name;
struct arglist * args; struct arglist * args;
struct arglist * next; struct arglist * next;
} Arglist; } Arglist;
#line 5760 "nuweb.w"
typedef struct embed { typedef struct embed {
Scrap_Node * defs; Scrap_Node * defs;
Arglist * args; Arglist * args;
} Embed_Node; } Embed_Node;
#line 6240 "nuweb.w"
typedef struct uses { typedef struct uses {
struct uses *next; struct uses *next;
Name *defn; Name *defn;
} Uses; } Uses;
#line 6482 "nuweb.w"
typedef struct l_node typedef struct l_node
{ {
struct l_node * left, * right; struct l_node * left, * right;
@@ -56,13 +83,21 @@ typedef struct l_node
char name[1]; char name[1];
} label_node; } label_node;
#line 827 "nuweb.w"
/* Limits */ /* Limits */
#line 864 "nuweb.w"
#ifndef MAX_NAME_LEN #ifndef MAX_NAME_LEN
#define MAX_NAME_LEN 1024 #define MAX_NAME_LEN 1024
#endif #endif
#line 828 "nuweb.w"
/* Global variable declarations */ /* Global variable declarations */
#line 1036 "nuweb.w"
extern int tex_flag; /* if FALSE, don't emit the documentation file */ 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 html_flag; /* if TRUE, emit HTML instead of LaTeX scraps. */
extern int output_flag; /* if FALSE, don't emit the output files */ extern int output_flag; /* if FALSE, don't emit the output files */
@@ -86,62 +121,135 @@ extern char * hyperoptions; /* The options to pass to the
extern int includepath_flag; /* Do we have an include path? */ extern int includepath_flag; /* Do we have an include path? */
extern struct incl{char * name; struct incl * next;} * include_list; extern struct incl{char * name; struct incl * next;} * include_list;
/* The list of include paths */ /* The list of include paths */
#line 1094 "nuweb.w"
extern int nw_char; extern int nw_char;
#line 1104 "nuweb.w"
extern char *command_name; extern char *command_name;
#line 1505 "nuweb.w"
extern unsigned char current_sector; extern unsigned char current_sector;
extern unsigned char prev_sector; extern unsigned char prev_sector;
#line 1703 "nuweb.w"
extern char blockBuff[6400]; extern char blockBuff[6400];
#line 2418 "nuweb.w"
extern int extra_scraps; extern int extra_scraps;
#line 3901 "nuweb.w"
extern char *source_name; /* name of the current file */ extern char *source_name; /* name of the current file */
extern int source_line; /* current line in the source file */ extern int source_line; /* current line in the source file */
#line 4237 "nuweb.w"
extern int already_warned; extern int already_warned;
#line 5100 "nuweb.w"
extern Name *file_names; extern Name *file_names;
extern Name *macro_names; extern Name *macro_names;
extern Name *user_names; extern Name *user_names;
extern int scrap_name_has_parameters; extern int scrap_name_has_parameters;
extern int scrap_ended_with; extern int scrap_ended_with;
#line 6491 "nuweb.w"
extern label_node * label_tab; extern label_node * label_tab;
#line 829 "nuweb.w"
/* Function prototypes */ /* Function prototypes */
extern void pass1();
extern void write_tex(); #line 1400 "nuweb.w"
extern void pass1(char *file_name);
#line 2034 "nuweb.w"
extern void write_tex(char *file_name, char *tex_name);
#line 2582 "nuweb.w"
void initialise_delimit_scrap_array(void); void initialise_delimit_scrap_array(void);
#line 2676 "nuweb.w"
void update_delimit_scrap(); void update_delimit_scrap();
#line 3100 "nuweb.w"
extern int has_sector(Name *, unsigned char); extern int has_sector(Name *, unsigned char);
extern void write_html();
extern void write_files(); #line 3227 "nuweb.w"
extern void source_open(); /* pass in the name of the source file */ extern void write_html(char *file_name, char *html_name);
extern int source_get(); /* no args; returns the next char or EOF */
#line 3764 "nuweb.w"
extern void write_files(Name *files);
#line 3889 "nuweb.w"
extern void source_open(char *name);
/* pass in the name of the source file */
extern int source_get(void);
/* no args; returns the next char or EOF */
extern int source_last; /* what last source_get() returned. */ extern int source_last; /* what last source_get() returned. */
extern int source_peek; /* The next character to get */ extern int source_peek; /* The next character to get */
#line 3964 "nuweb.w"
extern void source_ungetc(int*); extern void source_ungetc(int*);
extern void init_scraps();
extern int collect_scrap(); #line 4173 "nuweb.w"
extern int write_scraps(); extern void init_scraps(void);
extern void write_scrap_ref(); extern int collect_scrap(void);
extern void write_single_scrap_ref(); extern int write_scraps(FILE *file, char *spelling, Scrap_Node *defs,
extern int num_scraps(); int global_indent, char *indent_chars,
char debug_flag, char tab_flag, char indent_flag,
unsigned char comment_flag, Arglist *inArgs,
char *inParams[9], Parameters parameters,
char *title);
extern void write_scrap_ref(FILE *file, int num, int first, int *page);
extern void write_single_scrap_ref(FILE *file, int num);
extern int num_scraps(void);
#line 4501 "nuweb.w"
extern void add_to_use(Name * name, int current_scrap); extern void add_to_use(Name * name, int current_scrap);
Arglist * instance();
extern void collect_numbers(); #line 4575 "nuweb.w"
extern Name *collect_file_name(); extern Arglist *instance(Arglist *a, Arglist *par, char *arg[9], int *ch);
extern Name *collect_macro_name();
extern Arglist *collect_scrap_name(); #line 4984 "nuweb.w"
extern Name *name_add(); extern void collect_numbers(char *aux_name);
extern Name *prefix_add();
extern char *save_string(); #line 5116 "nuweb.w"
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);
#line 5260 "nuweb.w"
extern int robs_strcmp(char*, char*); extern int robs_strcmp(char*, char*);
extern Name *install_args();
extern void search(); #line 5579 "nuweb.w"
extern Name *install_args(Name * name, int argc, char *arg[0]);
#line 6000 "nuweb.w"
extern void search(void);
#line 6247 "nuweb.w"
extern void format_uses_refs(FILE *, int); extern void format_uses_refs(FILE *, int);
#line 6302 "nuweb.w"
extern void format_defs_refs(FILE *, int); extern void format_defs_refs(FILE *, int);
#line 6413 "nuweb.w"
void write_label(char label_name[], FILE * file); void write_label(char label_name[], FILE * file);
extern void *arena_getmem();
extern void arena_free(); #line 6506 "nuweb.w"
extern void *arena_getmem(size_t n);
extern void arena_free(void);
#line 830 "nuweb.w"
/* Operating System Dependencies */ /* Operating System Dependencies */
#line 972 "nuweb.w"
#if defined(VMS) #if defined(VMS)
#define PATH_SEP(c) (c==']'||c==':') #define PATH_SEP(c) (c==']'||c==':')
#define PATH_SEP_CHAR "" #define PATH_SEP_CHAR ""
@@ -155,4 +263,5 @@ extern void arena_free();
#define PATH_SEP_CHAR "/" #define PATH_SEP_CHAR "/"
#define DEFAULT_PATH "." #define DEFAULT_PATH "."
#endif #endif
typedef int *Parameters;
#line 831 "nuweb.w"

47
html.c
View File

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

37
input.c
View File

@@ -1,21 +1,31 @@
#line 919 "nuweb.w"
#include "global.h" #include "global.h"
#line 3914 "nuweb.w"
static FILE *source_file; /* the current input file */ static FILE *source_file; /* the current input file */
static int double_at; static int double_at;
static int include_depth; static int include_depth;
#line 3921 "nuweb.w"
static struct { static struct {
FILE *file; FILE *file;
char *name; char *name;
int line; int line;
} stack[10]; } stack[10];
#line 3938 "nuweb.w"
int source_peek; int source_peek;
int source_last; int source_last;
int source_get() int source_get(void)
{ {
int c; int c;
source_last = c = source_peek; source_last = c = source_peek;
switch (c) { switch (c) {
case EOF: { case EOF:
#line 4088 "nuweb.w"
{
fclose(source_file); fclose(source_file);
if (include_depth) { if (include_depth) {
include_depth--; include_depth--;
@@ -26,12 +36,16 @@ int source_get()
c = source_get(); c = source_get();
} }
} }
#line 3946 "nuweb.w"
return c; return c;
case '\n': source_line++; case '\n': source_line++;
default: default:
if (c==nw_char) if (c==nw_char)
{ {
/* Handle an ``at'' character */ /* Handle an ``at'' character */
#line 3985 "nuweb.w"
{ {
c = getc(source_file); c = getc(source_file);
if (double_at) { if (double_at) {
@@ -41,7 +55,9 @@ int source_get()
} }
else else
switch (c) { switch (c) {
case 'i': { case 'i':
#line 4027 "nuweb.w"
{
char name[FILENAME_MAX]; char name[FILENAME_MAX];
char fullname[FILENAME_MAX]; char fullname[FILENAME_MAX];
struct incl * p = include_list; struct incl * p = include_list;
@@ -52,6 +68,8 @@ int source_get()
exit(-1); exit(-1);
} }
/* Collect include-file name */ /* Collect include-file name */
#line 4067 "nuweb.w"
{ {
char *p = name; char *p = name;
do do
@@ -68,6 +86,8 @@ int source_get()
exit(-1); exit(-1);
} }
} }
#line 4037 "nuweb.w"
stack[include_depth].file = source_file; stack[include_depth].file = source_file;
fullname[0] = '\0'; fullname[0] = '\0';
for (;;) { for (;;) {
@@ -95,6 +115,8 @@ int source_get()
source_peek = getc(source_file); source_peek = getc(source_file);
c = source_get(); c = source_get();
} }
#line 3994 "nuweb.w"
break; break;
case '#': case 'f': case 'm': case 'u': case 'v': case '#': case 'f': case 'm': case 'u': case 'v':
case 'd': case 'o': case 'D': case 'O': case 's': case 'd': case 'o': case 'D': case 'O': case 's':
@@ -125,12 +147,16 @@ int source_get()
exit(-1); exit(-1);
} }
} }
#line 3952 "nuweb.w"
return c; return c;
} }
source_peek = getc(source_file); source_peek = getc(source_file);
return c; return c;
} }
} }
#line 3969 "nuweb.w"
void source_ungetc(int *c) void source_ungetc(int *c)
{ {
ungetc(source_peek, source_file); ungetc(source_peek, source_file);
@@ -138,8 +164,9 @@ void source_ungetc(int *c)
source_line--; source_line--;
source_peek=*c; source_peek=*c;
} }
void source_open(name)
char *name; #line 4107 "nuweb.w"
void source_open(char *name)
{ {
source_file = fopen(name, "r"); source_file = fopen(name, "r");
if (!source_file) { if (!source_file) {

411
latex.c
View File

@@ -1,17 +1,25 @@
#line 893 "nuweb.w"
#include "global.h" #include "global.h"
static int scraps = 1; static int scraps = 1;
static void copy_scrap(); /* formats the body of a scrap */
static void print_scrap_numbers(); /* formats a list of scrap numbers */ #line 2041 "nuweb.w"
static void format_entry(); /* formats an index entry */ static void copy_scrap(FILE *file, int prefix, Name *name);
static void format_file_entry(); /* formats a file index entry */ /* formats the body of a scrap */
static void format_user_entry(); static void print_scrap_numbers(FILE *tex_file, Scrap_Node *scraps);
static void write_arg(); /* formats a list of scrap numbers */
static void write_literal(); static void format_entry(Name *name, FILE *tex_file, unsigned char sector);
static void write_ArglistElement(); /* formats an index entry */
void write_tex(file_name, tex_name, sector) static void format_file_entry(Name *name, FILE *tex_file);
char *file_name; /* formats a file index entry */
char *tex_name; static void format_user_entry(Name *name, FILE *tex_file,
unsigned char sector; unsigned char sector);
static void write_arg(FILE *tex_file, char *p);
static void write_literal(FILE *tex_file, char *p, int mode);
static void write_ArglistElement(FILE *file, Arglist *args, char **params);
#line 2060 "nuweb.w"
void write_tex(char *file_name, char *tex_name)
{ {
FILE *tex_file = fopen(tex_name, "w"); FILE *tex_file = fopen(tex_name, "w");
if (tex_file) { if (tex_file) {
@@ -19,6 +27,8 @@ void write_tex(file_name, tex_name, sector)
fprintf(stderr, "writing %s\n", tex_name); fprintf(stderr, "writing %s\n", tex_name);
source_open(file_name); source_open(file_name);
/* Write LaTeX limbo definitions */ /* Write LaTeX limbo definitions */
#line 2084 "nuweb.w"
if (hyperref_flag) { if (hyperref_flag) {
fputs("\\newcommand{\\NWtarget}[2]{\\hypertarget{#1}{#2}}\n", tex_file); fputs("\\newcommand{\\NWtarget}[2]{\\hypertarget{#1}{#2}}\n", tex_file);
fputs("\\newcommand{\\NWlink}[2]{\\hyperlink{#1}{#2}}\n", tex_file); fputs("\\newcommand{\\NWlink}[2]{\\hyperlink{#1}{#2}}\n", tex_file);
@@ -42,11 +52,19 @@ void write_tex(file_name, tex_name, sector)
if (hyperoptions[0] != '\0') if (hyperoptions[0] != '\0')
{ {
/* Write the hyperlink usage macro */ /* Write the hyperlink usage macro */
#line 2112 "nuweb.w"
fprintf(tex_file, "\\usepackage[%s]{hyperref}", hyperoptions); fprintf(tex_file, "\\usepackage[%s]{hyperref}", hyperoptions);
#line 2106 "nuweb.w"
} }
fputs("}\n", tex_file); fputs("}\n", tex_file);
#line 2067 "nuweb.w"
/* Copy \verb|source_file| into \verb|tex_file| */ /* Copy \verb|source_file| into \verb|tex_file| */
#line 2119 "nuweb.w"
{ {
int inBlock = FALSE; int inBlock = FALSE;
int c = source_get(); int c = source_get();
@@ -54,6 +72,8 @@ void write_tex(file_name, tex_name, sector)
if (c == nw_char) if (c == nw_char)
{ {
/* Interpret at-sequence */ /* Interpret at-sequence */
#line 2135 "nuweb.w"
{ {
int big_definition = FALSE; int big_definition = FALSE;
c = source_get(); c = source_get();
@@ -64,18 +84,26 @@ void write_tex(file_name, tex_name, sector)
update_delimit_scrap(); update_delimit_scrap();
break; break;
case 'O': big_definition = TRUE; case 'O': big_definition = TRUE;
case 'o': { case 'o':
#line 2259 "nuweb.w"
{
Name *name = collect_file_name(); Name *name = collect_file_name();
/* Begin the scrap environment */ /* Begin the scrap environment */
#line 2346 "nuweb.w"
{ {
if (big_definition) if (big_definition)
{ {
if (inBlock) if (inBlock)
{ {
/* End block */ /* End block */
#line 2377 "nuweb.w"
fputs("\\end{minipage}\\vspace{4ex}\n", tex_file); fputs("\\end{minipage}\\vspace{4ex}\n", tex_file);
fputs("\\end{flushleft}\n", tex_file); fputs("\\end{flushleft}\n", tex_file);
inBlock = FALSE; inBlock = FALSE;
#line 2351 "nuweb.w"
} }
fputs("\\begin{flushleft} \\small", tex_file); fputs("\\begin{flushleft} \\small", tex_file);
} }
@@ -84,17 +112,27 @@ void write_tex(file_name, tex_name, sector)
if (inBlock) if (inBlock)
{ {
/* Switch block */ /* Switch block */
#line 2374 "nuweb.w"
fputs("\\par\\vspace{\\baselineskip}\n", tex_file); fputs("\\par\\vspace{\\baselineskip}\n", tex_file);
#line 2359 "nuweb.w"
} }
else else
{ {
/* Start block */ /* Start block */
#line 2370 "nuweb.w"
fputs("\\begin{flushleft} \\small\n\\begin{minipage}{\\linewidth}", tex_file); fputs("\\begin{flushleft} \\small\n\\begin{minipage}{\\linewidth}", tex_file);
inBlock = TRUE; inBlock = TRUE;
#line 2363 "nuweb.w"
} }
} }
fprintf(tex_file, "\\label{scrap%d}\\raggedright\\small\n", scraps); fprintf(tex_file, "\\label{scrap%d}\\raggedright\\small\n", scraps);
} }
#line 2261 "nuweb.w"
fputs("\\NWtarget{nuweb", tex_file); fputs("\\NWtarget{nuweb", tex_file);
write_single_scrap_ref(tex_file, scraps); write_single_scrap_ref(tex_file, scraps);
fputs("}{} ", tex_file); fputs("}{} ", tex_file);
@@ -102,13 +140,19 @@ void write_tex(file_name, tex_name, sector)
write_single_scrap_ref(tex_file, scraps); write_single_scrap_ref(tex_file, scraps);
fputs("}}$\\equiv$\n", tex_file); fputs("}}$\\equiv$\n", tex_file);
/* Fill in the middle of the scrap environment */ /* Fill in the middle of the scrap environment */
#line 2387 "nuweb.w"
{ {
fputs("\\vspace{-1ex}\n\\begin{list}{}{} \\item\n", tex_file); fputs("\\vspace{-1ex}\n\\begin{list}{}{} \\item\n", tex_file);
extra_scraps = 0; extra_scraps = 0;
copy_scrap(tex_file, TRUE, name); copy_scrap(tex_file, TRUE, name);
fputs("{\\NWsep}\n\\end{list}\n", tex_file); fputs("{\\NWsep}\n\\end{list}\n", tex_file);
} }
#line 2268 "nuweb.w"
/* Begin the cross-reference environment */ /* Begin the cross-reference environment */
#line 2433 "nuweb.w"
{ {
fputs("\\vspace{-1.5ex}\n", tex_file); fputs("\\vspace{-1.5ex}\n", tex_file);
fputs("\\footnotesize\n", tex_file); fputs("\\footnotesize\n", tex_file);
@@ -116,8 +160,12 @@ void write_tex(file_name, tex_name, sector)
tex_file); tex_file);
fputs("\\setlength{\\itemindent}{-\\leftmargin}}\n", tex_file);} fputs("\\setlength{\\itemindent}{-\\leftmargin}}\n", tex_file);}
#line 2269 "nuweb.w"
if ( scrap_flag ) { if ( scrap_flag ) {
/* Write file defs */ /* Write file defs */
#line 2452 "nuweb.w"
{ {
if (name->defs) { if (name->defs) {
if (name->defs->next) { if (name->defs->next) {
@@ -130,15 +178,23 @@ void write_tex(file_name, tex_name, sector)
name->spelling); name->spelling);
} }
} }
#line 2271 "nuweb.w"
} }
format_defs_refs(tex_file, scraps); format_defs_refs(tex_file, scraps);
format_uses_refs(tex_file, scraps++); format_uses_refs(tex_file, scraps++);
/* Finish the cross-reference environment */ /* Finish the cross-reference environment */
#line 2446 "nuweb.w"
{ {
fputs("\n\\item{}", tex_file); fputs("\n\\item{}", tex_file);
fputs("\n\\end{list}\n", tex_file); fputs("\n\\end{list}\n", tex_file);
} }
#line 2275 "nuweb.w"
/* Finish the scrap environment */ /* Finish the scrap environment */
#line 2404 "nuweb.w"
{ {
scraps += extra_scraps; scraps += extra_scraps;
if (big_definition) if (big_definition)
@@ -146,32 +202,48 @@ void write_tex(file_name, tex_name, sector)
else else
{ {
/* End block */ /* End block */
#line 2377 "nuweb.w"
fputs("\\end{minipage}\\vspace{4ex}\n", tex_file); fputs("\\end{minipage}\\vspace{4ex}\n", tex_file);
fputs("\\end{flushleft}\n", tex_file); fputs("\\end{flushleft}\n", tex_file);
inBlock = FALSE; inBlock = FALSE;
#line 2410 "nuweb.w"
} }
do do
c = source_get(); c = source_get();
while (isspace(c)); while (isspace(c));
} }
#line 2276 "nuweb.w"
} }
#line 2145 "nuweb.w"
break; break;
case 'Q': case 'Q':
case 'D': big_definition = TRUE; case 'D': big_definition = TRUE;
case 'q': case 'q':
case 'd': { case 'd':
#line 2284 "nuweb.w"
{
Name *name = collect_macro_name(); Name *name = collect_macro_name();
/* Begin the scrap environment */ /* Begin the scrap environment */
#line 2346 "nuweb.w"
{ {
if (big_definition) if (big_definition)
{ {
if (inBlock) if (inBlock)
{ {
/* End block */ /* End block */
#line 2377 "nuweb.w"
fputs("\\end{minipage}\\vspace{4ex}\n", tex_file); fputs("\\end{minipage}\\vspace{4ex}\n", tex_file);
fputs("\\end{flushleft}\n", tex_file); fputs("\\end{flushleft}\n", tex_file);
inBlock = FALSE; inBlock = FALSE;
#line 2351 "nuweb.w"
} }
fputs("\\begin{flushleft} \\small", tex_file); fputs("\\begin{flushleft} \\small", tex_file);
} }
@@ -180,21 +252,33 @@ void write_tex(file_name, tex_name, sector)
if (inBlock) if (inBlock)
{ {
/* Switch block */ /* Switch block */
#line 2374 "nuweb.w"
fputs("\\par\\vspace{\\baselineskip}\n", tex_file); fputs("\\par\\vspace{\\baselineskip}\n", tex_file);
#line 2359 "nuweb.w"
} }
else else
{ {
/* Start block */ /* Start block */
#line 2370 "nuweb.w"
fputs("\\begin{flushleft} \\small\n\\begin{minipage}{\\linewidth}", tex_file); fputs("\\begin{flushleft} \\small\n\\begin{minipage}{\\linewidth}", tex_file);
inBlock = TRUE; inBlock = TRUE;
#line 2363 "nuweb.w"
} }
} }
fprintf(tex_file, "\\label{scrap%d}\\raggedright\\small\n", scraps); fprintf(tex_file, "\\label{scrap%d}\\raggedright\\small\n", scraps);
} }
#line 2287 "nuweb.w"
fputs("\\NWtarget{nuweb", tex_file); fputs("\\NWtarget{nuweb", tex_file);
write_single_scrap_ref(tex_file, scraps); write_single_scrap_ref(tex_file, scraps);
fputs("}{} $\\langle\\,${\\itshape ", tex_file); fputs("}{} $\\langle\\,${\\itshape ", tex_file);
/* Write the macro's name */ /* Write the macro's name */
#line 2306 "nuweb.w"
{ {
char * p = name->spelling; char * p = name->spelling;
int i = 0; int i = 0;
@@ -208,17 +292,25 @@ void write_tex(file_name, tex_name, sector)
fputc(*p++, tex_file); fputc(*p++, tex_file);
} }
} }
#line 2291 "nuweb.w"
fputs("}\\nobreak\\ {\\footnotesize {", tex_file); fputs("}\\nobreak\\ {\\footnotesize {", tex_file);
write_single_scrap_ref(tex_file, scraps); write_single_scrap_ref(tex_file, scraps);
fputs("}}$\\,\\rangle\\equiv$\n", tex_file); fputs("}}$\\,\\rangle\\equiv$\n", tex_file);
/* Fill in the middle of the scrap environment */ /* Fill in the middle of the scrap environment */
#line 2387 "nuweb.w"
{ {
fputs("\\vspace{-1ex}\n\\begin{list}{}{} \\item\n", tex_file); fputs("\\vspace{-1ex}\n\\begin{list}{}{} \\item\n", tex_file);
extra_scraps = 0; extra_scraps = 0;
copy_scrap(tex_file, TRUE, name); copy_scrap(tex_file, TRUE, name);
fputs("{\\NWsep}\n\\end{list}\n", tex_file); fputs("{\\NWsep}\n\\end{list}\n", tex_file);
} }
#line 2295 "nuweb.w"
/* Begin the cross-reference environment */ /* Begin the cross-reference environment */
#line 2433 "nuweb.w"
{ {
fputs("\\vspace{-1.5ex}\n", tex_file); fputs("\\vspace{-1.5ex}\n", tex_file);
fputs("\\footnotesize\n", tex_file); fputs("\\footnotesize\n", tex_file);
@@ -226,14 +318,22 @@ void write_tex(file_name, tex_name, sector)
tex_file); tex_file);
fputs("\\setlength{\\itemindent}{-\\leftmargin}}\n", tex_file);} fputs("\\setlength{\\itemindent}{-\\leftmargin}}\n", tex_file);}
#line 2296 "nuweb.w"
/* Write macro defs */ /* Write macro defs */
#line 2466 "nuweb.w"
{ {
if (name->defs->next) { if (name->defs->next) {
fputs("\\item \\NWtxtMacroDefBy\\ ", tex_file); fputs("\\item \\NWtxtMacroDefBy\\ ", tex_file);
print_scrap_numbers(tex_file, name->defs); print_scrap_numbers(tex_file, name->defs);
} }
} }
#line 2297 "nuweb.w"
/* Write macro refs */ /* Write macro refs */
#line 2474 "nuweb.w"
{ {
if (name->uses) { if (name->uses) {
if (name->uses->next) { if (name->uses->next) {
@@ -256,14 +356,22 @@ void write_tex(file_name, tex_name, sector)
command_name, name->spelling); command_name, name->spelling);
} }
} }
#line 2298 "nuweb.w"
format_defs_refs(tex_file, scraps); format_defs_refs(tex_file, scraps);
format_uses_refs(tex_file, scraps++); format_uses_refs(tex_file, scraps++);
/* Finish the cross-reference environment */ /* Finish the cross-reference environment */
#line 2446 "nuweb.w"
{ {
fputs("\n\\item{}", tex_file); fputs("\n\\item{}", tex_file);
fputs("\n\\end{list}\n", tex_file); fputs("\n\\end{list}\n", tex_file);
} }
#line 2301 "nuweb.w"
/* Finish the scrap environment */ /* Finish the scrap environment */
#line 2404 "nuweb.w"
{ {
scraps += extra_scraps; scraps += extra_scraps;
if (big_definition) if (big_definition)
@@ -271,37 +379,59 @@ void write_tex(file_name, tex_name, sector)
else else
{ {
/* End block */ /* End block */
#line 2377 "nuweb.w"
fputs("\\end{minipage}\\vspace{4ex}\n", tex_file); fputs("\\end{minipage}\\vspace{4ex}\n", tex_file);
fputs("\\end{flushleft}\n", tex_file); fputs("\\end{flushleft}\n", tex_file);
inBlock = FALSE; inBlock = FALSE;
#line 2410 "nuweb.w"
} }
do do
c = source_get(); c = source_get();
while (isspace(c)); while (isspace(c));
} }
#line 2302 "nuweb.w"
} }
#line 2150 "nuweb.w"
break; break;
case 's': case 's':
/* Step to next sector */ /* Step to next sector */
#line 1493 "nuweb.w"
prev_sector += 1; prev_sector += 1;
current_sector = prev_sector; current_sector = prev_sector;
c = source_get(); c = source_get();
#line 2153 "nuweb.w"
break; break;
case 'S': case 'S':
/* Close the current sector */ /* Close the current sector */
#line 1500 "nuweb.w"
current_sector = 1; current_sector = 1;
c = source_get(); c = source_get();
#line 2156 "nuweb.w"
break; break;
case '{': case '{':
case '[': case '[':
case '(': copy_scrap(tex_file, FALSE, NULL); case '(':
#line 2426 "nuweb.w"
copy_scrap(tex_file, FALSE, NULL);
c = source_get(); c = source_get();
#line 2160 "nuweb.w"
break; break;
case '<': { case '<':
#line 2192 "nuweb.w"
{
Parameters local_parameters = 0; Parameters local_parameters = 0;
int changed; int changed;
char indent_chars[MAX_INDENT]; char indent_chars[MAX_INDENT];
@@ -318,36 +448,66 @@ void write_tex(file_name, tex_name, sector)
c = source_get(); c = source_get();
} }
#line 2162 "nuweb.w"
break; break;
case 'x': { case 'x':
#line 2749 "nuweb.w"
{
/* Get label from */ /* Get label from */
#line 6398 "nuweb.w"
char label_name[MAX_NAME_LEN]; char label_name[MAX_NAME_LEN];
char * p = label_name; char * p = label_name;
while (c = source_get(), c != nw_char) /* Here is 150a-01 */ while (c =
#line 2750 "nuweb.w"
source_get(), c != nw_char) /* Here is 148c-01 */
*p++ = c; *p++ = c;
*p = '\0'; *p = '\0';
c = source_get(); c =
#line 2750 "nuweb.w"
source_get();
write_label(label_name, tex_file); #line 2750 "nuweb.w"
write_label(label_name,
#line 2164 "nuweb.w"
tex_file);
} }
#line 2164 "nuweb.w"
c = source_get(); c = source_get();
break; break;
case 'c': if (inBlock) case 'c':
#line 1785 "nuweb.w"
if (inBlock)
{ {
/* End block */ /* End block */
#line 2377 "nuweb.w"
fputs("\\end{minipage}\\vspace{4ex}\n", tex_file); fputs("\\end{minipage}\\vspace{4ex}\n", tex_file);
fputs("\\end{flushleft}\n", tex_file); fputs("\\end{flushleft}\n", tex_file);
inBlock = FALSE; inBlock = FALSE;
#line 1787 "nuweb.w"
} }
else else
{ {
/* Start block */ /* Start block */
#line 2370 "nuweb.w"
fputs("\\begin{flushleft} \\small\n\\begin{minipage}{\\linewidth}", tex_file); fputs("\\begin{flushleft} \\small\n\\begin{minipage}{\\linewidth}", tex_file);
inBlock = TRUE; inBlock = TRUE;
#line 1791 "nuweb.w"
} }
#line 2167 "nuweb.w"
c = source_get(); c = source_get();
break; break;
case 'f': { case 'f':
#line 2915 "nuweb.w"
{
if (file_names) { if (file_names) {
fputs("\n{\\small\\begin{list}{}{\\setlength{\\itemsep}{-\\parsep}", fputs("\n{\\small\\begin{list}{}{\\setlength{\\itemsep}{-\\parsep}",
tex_file); tex_file);
@@ -357,8 +517,12 @@ void write_tex(file_name, tex_name, sector)
} }
c = source_get(); c = source_get();
} }
#line 2170 "nuweb.w"
break; break;
case 'm': { case 'm':
#line 2965 "nuweb.w"
{
unsigned char sector = current_sector; unsigned char sector = current_sector;
int c = source_get(); int c = source_get();
if (c == '+') if (c == '+')
@@ -377,8 +541,12 @@ void write_tex(file_name, tex_name, sector)
} }
c = source_get(); c = source_get();
#line 2172 "nuweb.w"
break; break;
case 'u': { case 'u':
#line 3118 "nuweb.w"
{
unsigned char sector = current_sector; unsigned char sector = current_sector;
c = source_get(); c = source_get();
if (c == '+') { if (c == '+') {
@@ -393,10 +561,16 @@ void write_tex(file_name, tex_name, sector)
fputs("\\end{list}}", tex_file); fputs("\\end{list}}", tex_file);
} }
} }
#line 2174 "nuweb.w"
break; break;
case 'v': fputs(version_string, tex_file); case 'v':
#line 2187 "nuweb.w"
fputs(version_string, tex_file);
c = source_get(); c = source_get();
#line 2176 "nuweb.w"
break; break;
default: default:
if (c==nw_char) if (c==nw_char)
@@ -405,6 +579,8 @@ void write_tex(file_name, tex_name, sector)
break; break;
} }
} }
#line 2125 "nuweb.w"
} }
else { else {
putc(c, tex_file); putc(c, tex_file);
@@ -412,11 +588,15 @@ void write_tex(file_name, tex_name, sector)
} }
} }
} }
#line 2068 "nuweb.w"
fclose(tex_file); fclose(tex_file);
} }
else else
fprintf(stderr, "%s: can't open %s\n", command_name, tex_name); 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) static void write_arg(FILE * tex_file, char * p)
{ {
fputs("\\hbox{\\slshape\\sffamily ", tex_file); fputs("\\hbox{\\slshape\\sffamily ", tex_file);
@@ -439,9 +619,9 @@ static void write_arg(FILE * tex_file, char * p)
fputs("\\/}", tex_file); fputs("\\/}", tex_file);
} }
static void print_scrap_numbers(tex_file, scraps)
FILE *tex_file; #line 2498 "nuweb.w"
Scrap_Node *scraps; static void print_scrap_numbers(FILE *tex_file, Scrap_Node *scraps)
{ {
int page; int page;
fputs("\\NWlink{nuweb", tex_file); fputs("\\NWlink{nuweb", tex_file);
@@ -460,6 +640,8 @@ static void print_scrap_numbers(tex_file, scraps)
} }
fputs(".\n", tex_file); fputs(".\n", tex_file);
} }
#line 2535 "nuweb.w"
static char *orig_delimit_scrap[3][5] = { static char *orig_delimit_scrap[3][5] = {
/* {} mode: begin, end, insert nw_char, prefix, suffix */ /* {} mode: begin, end, insert nw_char, prefix, suffix */
{ "\\verb@", "@", "@{\\tt @}\\verb@", "\\mbox{}", "\\\\" }, { "\\verb@", "@", "@{\\tt @}\\verb@", "\\mbox{}", "\\\\" },
@@ -470,6 +652,8 @@ static char *orig_delimit_scrap[3][5] = {
}; };
static char *delimit_scrap[3][5]; static char *delimit_scrap[3][5];
#line 2554 "nuweb.w"
void initialise_delimit_scrap_array() { void initialise_delimit_scrap_array() {
int i,j; int i,j;
for(i = 0; i < 3; i++) { for(i = 0; i < 3; i++) {
@@ -495,7 +679,11 @@ void initialise_delimit_scrap_array() {
} }
} }
} }
#line 2586 "nuweb.w"
int scrap_type = 0; int scrap_type = 0;
#line 2590 "nuweb.w"
static void write_literal(FILE * tex_file, char * p, int mode) static void write_literal(FILE * tex_file, char * p, int mode)
{ {
fputs(delimit_scrap[mode][0], tex_file); fputs(delimit_scrap[mode][0], tex_file);
@@ -508,10 +696,9 @@ static void write_literal(FILE * tex_file, char * p, int mode)
} }
fputs(delimit_scrap[mode][1], tex_file); fputs(delimit_scrap[mode][1], tex_file);
} }
static void copy_scrap(file, prefix, name)
FILE *file; #line 2605 "nuweb.w"
int prefix; static void copy_scrap(FILE *file, int prefix, Name *name)
Name * name;
{ {
int indent = 0; int indent = 0;
int c; int c;
@@ -531,7 +718,9 @@ static void copy_scrap(file, prefix, name)
fputs(delimit_scrap[scrap_type][0], file); fputs(delimit_scrap[scrap_type][0], file);
indent = 0; indent = 0;
break; break;
case '\t': { case '\t':
#line 2680 "nuweb.w"
{
int delta = 8 - (indent % 8); int delta = 8 - (indent % 8);
indent += delta; indent += delta;
while (delta > 0) { while (delta > 0) {
@@ -539,41 +728,69 @@ static void copy_scrap(file, prefix, name)
delta--; delta--;
} }
} }
#line 2625 "nuweb.w"
break; break;
default: default:
if (c==nw_char) if (c==nw_char)
{ {
/* Check at-sequence for end-of-scrap */ /* Check at-sequence for end-of-scrap */
#line 2690 "nuweb.w"
{ {
c = source_get(); c = source_get();
switch (c) { switch (c) {
case 'c': { case 'c':
#line 1714 "nuweb.w"
{
fputs(delimit_scrap[scrap_type][1],file); fputs(delimit_scrap[scrap_type][1],file);
fprintf(file, "\\hbox{\\sffamily\\slshape (Comment)}"); fprintf(file, "\\hbox{\\sffamily\\slshape (Comment)}");
fputs(delimit_scrap[scrap_type][0], file); fputs(delimit_scrap[scrap_type][0], file);
} }
#line 2693 "nuweb.w"
break; break;
case 'x': { case 'x':
#line 2749 "nuweb.w"
{
/* Get label from */ /* Get label from */
#line 6398 "nuweb.w"
char label_name[MAX_NAME_LEN]; char label_name[MAX_NAME_LEN];
char * p = label_name; char * p = label_name;
while (c = source_get(), c != nw_char) /* Here is 150a-01 */ while (c =
#line 2750 "nuweb.w"
source_get(), c != nw_char) /* Here is 148c-01 */
*p++ = c; *p++ = c;
*p = '\0'; *p = '\0';
c = source_get(); c =
#line 2750 "nuweb.w"
source_get();
write_label(label_name, file); #line 2750 "nuweb.w"
write_label(label_name,
#line 2695 "nuweb.w"
file);
} }
#line 2695 "nuweb.w"
break; break;
case 'v': fputs(version_string, file); case 'v':
#line 2745 "nuweb.w"
fputs(version_string, file);
#line 2697 "nuweb.w"
case 's': case 's':
break; break;
case '+': case '+':
case '-': case '-':
case '*': case '*':
case '|': { case '|':
#line 2758 "nuweb.w"
{
do { do {
do do
c = source_get(); c = source_get();
@@ -581,12 +798,16 @@ static void copy_scrap(file, prefix, name)
c = source_get(); c = source_get();
} while (c != '}' && c != ']' && c != ')' ); } while (c != '}' && c != ']' && c != ')' );
} }
#line 2703 "nuweb.w"
case ',': case ',':
case ')': case ')':
case ']': case ']':
case '}': fputs(delimit_scrap[scrap_type][1], file); case '}': fputs(delimit_scrap[scrap_type][1], file);
return; return;
case '<': { case '<':
#line 2798 "nuweb.w"
{
Arglist *args = collect_scrap_name(-1); Arglist *args = collect_scrap_name(-1);
Name *name = args->name; Name *name = args->name;
char * p = name->spelling; char * p = name->spelling;
@@ -616,6 +837,8 @@ static void copy_scrap(file, prefix, name)
if (scrap_name_has_parameters) { if (scrap_name_has_parameters) {
/* Format macro parameters */ /* Format macro parameters */
#line 1962 "nuweb.w"
char sep; char sep;
sep = '('; sep = '(';
@@ -642,10 +865,14 @@ static void copy_scrap(file, prefix, name)
c = source_get(); c = source_get();
} }
#line 2826 "nuweb.w"
} }
fprintf(file, "{\\footnotesize "); fprintf(file, "{\\footnotesize ");
if (name->defs) if (name->defs)
/* Write abbreviated definition list */ /* Write abbreviated definition list */
#line 2844 "nuweb.w"
{ {
Scrap_Node *p = name->defs; Scrap_Node *p = name->defs;
fputs("\\NWlink{nuweb", file); fputs("\\NWlink{nuweb", file);
@@ -657,6 +884,8 @@ static void copy_scrap(file, prefix, name)
if (p) if (p)
fputs(", \\ldots\\ ", file); fputs(", \\ldots\\ ", file);
} }
#line 2830 "nuweb.w"
else { else {
putc('?', file); putc('?', file);
fprintf(stderr, "%s: never defined <%s>\n", fprintf(stderr, "%s: never defined <%s>\n",
@@ -667,14 +896,22 @@ static void copy_scrap(file, prefix, name)
fputs("}", file); fputs("}", file);
fputs(delimit_scrap[scrap_type][0], file); fputs(delimit_scrap[scrap_type][0], file);
} }
#line 2709 "nuweb.w"
break; break;
case '%': { case '%':
#line 2768 "nuweb.w"
{
do do
c = source_get(); c = source_get();
while (c != '\n'); while (c != '\n');
} }
#line 2711 "nuweb.w"
break; break;
case '_': { case '_':
#line 2777 "nuweb.w"
{
fputs(delimit_scrap[scrap_type][1],file); fputs(delimit_scrap[scrap_type][1],file);
fprintf(file, "\\hbox{\\sffamily\\bfseries "); fprintf(file, "\\hbox{\\sffamily\\bfseries ");
c = source_get(); c = source_get();
@@ -686,18 +923,28 @@ static void copy_scrap(file, prefix, name)
fprintf(file, "}"); fprintf(file, "}");
fputs(delimit_scrap[scrap_type][0], file); fputs(delimit_scrap[scrap_type][0], file);
} }
#line 2713 "nuweb.w"
break; break;
case 't': { case 't':
#line 2791 "nuweb.w"
{
fputs(delimit_scrap[scrap_type][1],file); fputs(delimit_scrap[scrap_type][1],file);
fprintf(file, "\\hbox{\\sffamily\\slshape fragment title}"); fprintf(file, "\\hbox{\\sffamily\\slshape fragment title}");
fputs(delimit_scrap[scrap_type][0], file); fputs(delimit_scrap[scrap_type][0], file);
} }
#line 2715 "nuweb.w"
break; break;
case 'f': { case 'f':
#line 2791 "nuweb.w"
{
fputs(delimit_scrap[scrap_type][1],file); fputs(delimit_scrap[scrap_type][1],file);
fprintf(file, "\\hbox{\\sffamily\\slshape file name}"); fprintf(file, "\\hbox{\\sffamily\\slshape file name}");
fputs(delimit_scrap[scrap_type][0], file); fputs(delimit_scrap[scrap_type][0], file);
} }
#line 2717 "nuweb.w"
break; break;
case '1': case '2': case '3': case '1': case '2': case '3':
case '4': case '5': case '6': case '4': case '5': case '6':
@@ -723,6 +970,8 @@ static void copy_scrap(file, prefix, name)
break; break;
} }
} }
#line 2630 "nuweb.w"
break; break;
} }
putc(c, file); putc(c, file);
@@ -732,6 +981,8 @@ static void copy_scrap(file, prefix, name)
c = source_get(); c = source_get();
} }
} }
#line 2646 "nuweb.w"
void update_delimit_scrap() void update_delimit_scrap()
{ {
/* {}-mode begin */ /* {}-mode begin */
@@ -759,6 +1010,8 @@ void update_delimit_scrap()
/* ()-mode insert nw_char */ /* ()-mode insert nw_char */
delimit_scrap[2][2][0] = nw_char; delimit_scrap[2][2][0] = nw_char;
} }
#line 2857 "nuweb.w"
static void static void
write_ArglistElement(FILE * file, Arglist * args, char ** params) write_ArglistElement(FILE * file, Arglist * args, char ** params)
{ {
@@ -801,6 +1054,8 @@ write_ArglistElement(FILE * file, Arglist * args, char ** params)
/* Format macro parameters */ /* Format macro parameters */
#line 1962 "nuweb.w"
char sep; char sep;
sep = '('; sep = '(';
@@ -827,10 +1082,14 @@ write_ArglistElement(FILE * file, Arglist * args, char ** params)
c = source_get(); c = source_get();
} }
#line 2897 "nuweb.w"
} }
fprintf(file, "{\\footnotesize "); fprintf(file, "{\\footnotesize ");
if (name->defs) if (name->defs)
/* Write abbreviated definition list */ /* Write abbreviated definition list */
#line 2844 "nuweb.w"
{ {
Scrap_Node *p = name->defs; Scrap_Node *p = name->defs;
fputs("\\NWlink{nuweb", file); fputs("\\NWlink{nuweb", file);
@@ -842,6 +1101,8 @@ write_ArglistElement(FILE * file, Arglist * args, char ** params)
if (p) if (p)
fputs(", \\ldots\\ ", file); fputs(", \\ldots\\ ", file);
} }
#line 2901 "nuweb.w"
else { else {
putc('?', file); putc('?', file);
fprintf(stderr, "%s: never defined <%s>\n", fprintf(stderr, "%s: never defined <%s>\n",
@@ -850,16 +1111,20 @@ write_ArglistElement(FILE * file, Arglist * args, char ** params)
fputs("}$\\,\\rangle$", file); fputs("}$\\,\\rangle$", file);
} }
} }
static void format_file_entry(name, tex_file)
Name *name; #line 2927 "nuweb.w"
FILE *tex_file; static void format_file_entry(Name *name, FILE *tex_file)
{ {
while (name) { while (name) {
format_file_entry(name->llink, tex_file); format_file_entry(name->llink, tex_file);
/* Format a file index entry */ /* Format a file index entry */
#line 2938 "nuweb.w"
fputs("\\item ", tex_file); fputs("\\item ", tex_file);
fprintf(tex_file, "\\verb%c\"%s\"%c ", nw_char, name->spelling, nw_char); fprintf(tex_file, "\\verb%c\"%s\"%c ", nw_char, name->spelling, nw_char);
/* Write file's defining scrap numbers */ /* Write file's defining scrap numbers */
#line 2944 "nuweb.w"
{ {
Scrap_Node *p = name->defs; Scrap_Node *p = name->defs;
fputs("{\\footnotesize {\\NWtxtDefBy}", tex_file); fputs("{\\footnotesize {\\NWtxtDefBy}", tex_file);
@@ -879,10 +1144,16 @@ static void format_file_entry(name, tex_file)
} }
putc('}', tex_file); putc('}', tex_file);
} }
#line 2940 "nuweb.w"
putc('\n', tex_file); putc('\n', tex_file);
#line 2931 "nuweb.w"
name = name->rlink; name = name->rlink;
} }
} }
#line 2986 "nuweb.w"
static int load_entry(Name * name, Name ** nms, int n) static int load_entry(Name * name, Name ** nms, int n)
{ {
while (name) { while (name) {
@@ -892,16 +1163,17 @@ static int load_entry(Name * name, Name ** nms, int n)
} }
return n; return n;
} }
static void format_entry(name, tex_file, sector)
Name *name; #line 2998 "nuweb.w"
FILE *tex_file; static void format_entry(Name *name, FILE *tex_file, unsigned char sector)
unsigned char sector;
{ {
Name ** nms = malloc(num_scraps()*sizeof(Name *)); Name ** nms = malloc(num_scraps()*sizeof(Name *));
int n = load_entry(name, nms, 0); int n = load_entry(name, nms, 0);
int i; int i;
/* Sort 'nms' of size 'n' for <Rob's ordering> */ /* Sort 'nms' of size 'n' for <Rob's ordering> */
#line 3018 "nuweb.w"
int j; int j;
for (j = 1; j < n; j++) for (j = 1; j < n; j++)
{ {
@@ -912,7 +1184,9 @@ static void format_entry(name, tex_file, sector)
{ {
Name * ki = nms[i]; Name * ki = nms[i];
if (robs_strcmp(ki->spelling, kj->spelling) < 0) if (
#line 3015 "nuweb.w"
robs_strcmp(ki->spelling, kj->spelling) < 0)
break; break;
nms[i + 1] = ki; nms[i + 1] = ki;
i -= 1; i -= 1;
@@ -920,15 +1194,21 @@ static void format_entry(name, tex_file, sector)
nms[i + 1] = kj; nms[i + 1] = kj;
} }
#line 3004 "nuweb.w"
for (i = 0; i < n; i++) for (i = 0; i < n; i++)
{ {
Name * name = nms[i]; Name * name = nms[i];
/* Format an index entry */ /* Format an index entry */
#line 3038 "nuweb.w"
if (name->sector == sector){ if (name->sector == sector){
fputs("\\item ", tex_file); fputs("\\item ", tex_file);
fputs("$\\langle\\,$", tex_file); fputs("$\\langle\\,$", tex_file);
/* Write the macro's name */ /* Write the macro's name */
#line 2306 "nuweb.w"
{ {
char * p = name->spelling; char * p = name->spelling;
int i = 0; int i = 0;
@@ -942,8 +1222,12 @@ static void format_entry(name, tex_file, sector)
fputc(*p++, tex_file); fputc(*p++, tex_file);
} }
} }
#line 3041 "nuweb.w"
fputs("\\nobreak\\ {\\footnotesize ", tex_file); fputs("\\nobreak\\ {\\footnotesize ", tex_file);
/* Write defining scrap numbers */ /* Write defining scrap numbers */
#line 3050 "nuweb.w"
{ {
Scrap_Node *p = name->defs; Scrap_Node *p = name->defs;
if (p) { if (p) {
@@ -966,8 +1250,12 @@ static void format_entry(name, tex_file, sector)
else else
putc('?', tex_file); putc('?', tex_file);
} }
#line 3043 "nuweb.w"
fputs("}$\\,\\rangle$ ", tex_file); fputs("}$\\,\\rangle$ ", tex_file);
/* Write referencing scrap numbers */ /* Write referencing scrap numbers */
#line 3074 "nuweb.w"
{ {
Scrap_Node *p = name->uses; Scrap_Node *p = name->uses;
fputs("{\\footnotesize ", tex_file); fputs("{\\footnotesize ", tex_file);
@@ -992,10 +1280,16 @@ static void format_entry(name, tex_file, sector)
fputs("{\\NWtxtNoRef}.", tex_file); fputs("{\\NWtxtNoRef}.", tex_file);
putc('}', tex_file); putc('}', tex_file);
} }
#line 3045 "nuweb.w"
putc('\n', tex_file); putc('\n', tex_file);
} }
#line 3009 "nuweb.w"
} }
} }
#line 3104 "nuweb.w"
int has_sector(Name * name, unsigned char sector) int has_sector(Name * name, unsigned char sector)
{ {
while(name) { while(name) {
@@ -1007,14 +1301,15 @@ int has_sector(Name * name, unsigned char sector)
} }
return FALSE; return FALSE;
} }
static void format_user_entry(name, tex_file, sector)
Name *name; #line 3136 "nuweb.w"
FILE *tex_file; static void format_user_entry(Name *name, FILE *tex_file, unsigned char sector)
unsigned char sector;
{ {
while (name) { while (name) {
format_user_entry(name->llink, tex_file, sector); format_user_entry(name->llink, tex_file, sector);
/* Format a user index entry */ /* Format a user index entry */
#line 3148 "nuweb.w"
if (name->sector == sector){ if (name->sector == sector){
Scrap_Node *uses = name->uses; Scrap_Node *uses = name->uses;
if ( uses || dangling_flag ) { if ( uses || dangling_flag ) {
@@ -1081,6 +1376,8 @@ static void format_user_entry(name, tex_file, sector)
fputs(".\n", tex_file); fputs(".\n", tex_file);
} }
} }
#line 3140 "nuweb.w"
name = name->rlink; name = name->rlink;
} }
} }

60
main.c
View File

@@ -1,17 +1,25 @@
#line 878 "nuweb.w"
#include "global.h" #include "global.h"
#line 955 "nuweb.w"
#include <stdlib.h> #include <stdlib.h>
int main(argc, argv) int main(int argc, char** argv)
int argc;
char **argv;
{ {
int arg = 1; int arg = 1;
/* Interpret command-line arguments */ /* Interpret command-line arguments */
#line 1113 "nuweb.w"
command_name = argv[0]; command_name = argv[0];
#line 1119 "nuweb.w"
while (arg < argc) { while (arg < argc) {
char *s = argv[arg]; char *s = argv[arg];
if (*s++ == '-') { if (*s++ == '-') {
/* Interpret the argument string \verb|s| */ /* Interpret the argument string \verb|s| */
#line 1139 "nuweb.w"
{ {
char c = *s++; char c = *s++;
while (c) { while (c) {
@@ -56,8 +64,12 @@ int main(argc, argv)
} }
HasValue:; HasValue:;
} }
#line 1122 "nuweb.w"
arg++; arg++;
/* Perhaps get the prepend path */ /* Perhaps get the prepend path */
#line 1186 "nuweb.w"
if (prepend_flag) if (prepend_flag)
{ {
if (*s == '\0') if (*s == '\0')
@@ -66,7 +78,11 @@ HasValue:;
prepend_flag = FALSE; prepend_flag = FALSE;
} }
#line 1124 "nuweb.w"
/* Perhaps get the version info string */ /* Perhaps get the version info string */
#line 1214 "nuweb.w"
if (version_info_flag) if (version_info_flag)
{ {
if (*s == '\0') if (*s == '\0')
@@ -75,7 +91,11 @@ HasValue:;
version_info_flag = FALSE; version_info_flag = FALSE;
} }
#line 1125 "nuweb.w"
/* Perhaps get the hyperref options */ /* Perhaps get the hyperref options */
#line 1224 "nuweb.w"
if (hyperopt_flag) if (hyperopt_flag)
{ {
if (*s == '\0') if (*s == '\0')
@@ -85,7 +105,11 @@ HasValue:;
hyperref_flag = TRUE; hyperref_flag = TRUE;
} }
#line 1126 "nuweb.w"
/* Perhaps add an include path */ /* Perhaps add an include path */
#line 1196 "nuweb.w"
if (includepath_flag) if (includepath_flag)
{ {
struct incl * le struct incl * le
@@ -102,11 +126,17 @@ HasValue:;
includepath_flag = FALSE; includepath_flag = FALSE;
} }
#line 1127 "nuweb.w"
} }
else break; else break;
} }
#line 960 "nuweb.w"
/* Set locale information */ /* Set locale information */
#line 1240 "nuweb.w"
{ {
/* try to get locale information */ /* try to get locale information */
char *s=getenv("LC_CTYPE"); char *s=getenv("LC_CTYPE");
@@ -118,8 +148,12 @@ HasValue:;
fprintf(stderr, "Setting locale failed\n"); fprintf(stderr, "Setting locale failed\n");
} }
#line 961 "nuweb.w"
initialise_delimit_scrap_array(); initialise_delimit_scrap_array();
/* Process the remaining arguments (file names) */ /* Process the remaining arguments (file names) */
#line 1259 "nuweb.w"
{ {
if (arg >= argc) { if (arg >= argc) {
fprintf(stderr, "%s: expected a file name. ", command_name); fprintf(stderr, "%s: expected a file name. ", command_name);
@@ -128,11 +162,15 @@ HasValue:;
} }
do { do {
/* Handle the file name in \verb|argv[arg]| */ /* Handle the file name in \verb|argv[arg]| */
#line 1281 "nuweb.w"
{ {
char source_name[FILENAME_MAX]; char source_name[FILENAME_MAX];
char tex_name[FILENAME_MAX]; char tex_name[FILENAME_MAX];
char aux_name[FILENAME_MAX]; char aux_name[FILENAME_MAX];
/* Build \verb|source_name| and \verb|tex_name| */ /* Build \verb|source_name| and \verb|tex_name| */
#line 1304 "nuweb.w"
{ {
char *p = argv[arg]; char *p = argv[arg];
char *q = source_name; char *q = source_name;
@@ -150,6 +188,8 @@ HasValue:;
c = *p++; c = *p++;
} }
/* Add the source path to the include path list */ /* Add the source path to the include path list */
#line 1344 "nuweb.w"
if (trim != source_name) { if (trim != source_name) {
struct incl * le struct incl * le
= (struct incl *)arena_getmem(sizeof(struct incl)); = (struct incl *)arena_getmem(sizeof(struct incl));
@@ -165,6 +205,8 @@ HasValue:;
*trim = sv; *trim = sv;
} }
#line 1320 "nuweb.w"
*q = '\0'; *q = '\0';
if (dot) { if (dot) {
*dot = '\0'; /* produce HTML when the file extension is ".hw" */ *dot = '\0'; /* produce HTML when the file extension is ".hw" */
@@ -181,7 +223,11 @@ HasValue:;
*q = '\0'; *q = '\0';
} }
} }
#line 1285 "nuweb.w"
/* Process a file */ /* Process a file */
#line 1370 "nuweb.w"
{ {
pass1(source_name); pass1(source_name);
current_sector = 1; current_sector = 1;
@@ -191,7 +237,7 @@ HasValue:;
int saved_number_flag = number_flag; int saved_number_flag = number_flag;
number_flag = TRUE; number_flag = TRUE;
collect_numbers(aux_name); collect_numbers(aux_name);
write_html(source_name, tex_name, 0/*Dummy */); write_html(source_name, tex_name);
number_flag = saved_number_flag; number_flag = saved_number_flag;
} }
else { else {
@@ -203,9 +249,15 @@ HasValue:;
write_files(file_names); write_files(file_names);
arena_free(); arena_free();
} }
#line 1286 "nuweb.w"
} }
#line 1266 "nuweb.w"
arg++; arg++;
} while (arg < argc); } while (arg < argc);
} }
#line 963 "nuweb.w"
exit(0); exit(0);
} }

163
names.c
View File

@@ -1,9 +1,11 @@
#line 932 "nuweb.w"
#include "global.h" #include "global.h"
#line 5126 "nuweb.w"
enum { LESS, GREATER, EQUAL, PREFIX, EXTENSION }; enum { LESS, GREATER, EQUAL, PREFIX, EXTENSION };
static int compare(x, y) static int compare(char *x, char *y)
char *x;
char *y;
{ {
int len, result; int len, result;
int xl = strlen(x); int xl = strlen(x);
@@ -26,21 +28,22 @@ static int compare(x, y)
} }
else return EQUAL; else return EQUAL;
} }
char *save_string(s)
char *s; #line 5155 "nuweb.w"
char *save_string(char *s)
{ {
char *new = (char *) arena_getmem((strlen(s) + 1) * sizeof(char)); char *new = (char *) arena_getmem((strlen(s) + 1) * sizeof(char));
strcpy(new, s); strcpy(new, s);
return new; return new;
} }
static int ambiguous_prefix();
#line 5164 "nuweb.w"
static int ambiguous_prefix(Name *node, char *spelling,
unsigned char sector);
static char * found_name = NULL; static char * found_name = NULL;
Name *prefix_add(rt, spelling, sector) Name *prefix_add(Name **rt, char *spelling, unsigned char sector)
Name **rt;
char *spelling;
unsigned char sector;
{ {
Name *node = *rt; Name *node = *rt;
int cmp; int cmp;
@@ -64,18 +67,24 @@ Name *prefix_add(rt, spelling, sector)
if (cmp == EXTENSION) if (cmp == EXTENSION)
node->spelling = save_string(spelling); node->spelling = save_string(spelling);
return node; return node;
case PREFIX: { case PREFIX:
#line 5207 "nuweb.w"
{
if (ambiguous_prefix(node->llink, spelling, sector) || if (ambiguous_prefix(node->llink, spelling, sector) ||
ambiguous_prefix(node->rlink, spelling, sector)) ambiguous_prefix(node->rlink, spelling, sector))
fprintf(stderr, fprintf(stderr,
"%s: ambiguous prefix %c<%s...%c> (%s, line %d)\n", "%s: ambiguous prefix %c<%s...%c> (%s, line %d)\n",
command_name, nw_char, spelling, nw_char, source_name, source_line); command_name, nw_char, spelling, nw_char, source_name, source_line);
} }
#line 5193 "nuweb.w"
return node; return node;
} }
node = *rt; node = *rt;
} }
/* Create new name entry */ /* Create new name entry */
#line 5330 "nuweb.w"
{ {
node = (Name *) arena_getmem(sizeof(Name)); node = (Name *) arena_getmem(sizeof(Name));
if (found_name && robs_strcmp(found_name, spelling) == 0) if (found_name && robs_strcmp(found_name, spelling) == 0)
@@ -104,11 +113,12 @@ Name *prefix_add(rt, spelling, sector)
*rt = node; *rt = node;
return node; return node;
} }
#line 5198 "nuweb.w"
} }
static int ambiguous_prefix(node, spelling, sector)
Name *node; #line 5216 "nuweb.w"
char *spelling; static int ambiguous_prefix(Name *node, char *spelling, unsigned char sector)
unsigned char sector;
{ {
while (node) { while (node) {
switch (compare(node->spelling, spelling)) { switch (compare(node->spelling, spelling)) {
@@ -131,6 +141,8 @@ static int ambiguous_prefix(node, spelling, sector)
} }
return FALSE; return FALSE;
} }
#line 5264 "nuweb.w"
int robs_strcmp(char* x, char* y) int robs_strcmp(char* x, char* y)
{ {
int cmp = 0; int cmp = 0;
@@ -138,13 +150,21 @@ int robs_strcmp(char* x, char* y)
for (; *x && *y; x++, y++) for (; *x && *y; x++, y++)
{ {
/* Skip invisibles on 'x' */ /* Skip invisibles on 'x' */
#line 5298 "nuweb.w"
if (*x == '|') if (*x == '|')
x++; x++;
#line 5270 "nuweb.w"
/* Skip invisibles on 'y' */ /* Skip invisibles on 'y' */
#line 5298 "nuweb.w"
if (*y == '|') if (*y == '|')
y++; y++;
#line 5271 "nuweb.w"
if (*x == *y) if (*x == *y)
continue; continue;
if (islower(*x) && toupper(*x) == *y) if (islower(*x) && toupper(*x) == *y)
@@ -165,10 +185,9 @@ int robs_strcmp(char* x, char* y)
return -2; return -2;
return cmp; return cmp;
} }
Name *name_add(rt, spelling, sector)
Name **rt; #line 5303 "nuweb.w"
char *spelling; Name *name_add(Name **rt, char *spelling, unsigned char sector)
unsigned char sector;
{ {
Name *node = *rt; Name *node = *rt;
while (node) { while (node) {
@@ -190,6 +209,8 @@ Name *name_add(rt, spelling, sector)
node = *rt; node = *rt;
} }
/* Create new name entry */ /* Create new name entry */
#line 5330 "nuweb.w"
{ {
node = (Name *) arena_getmem(sizeof(Name)); node = (Name *) arena_getmem(sizeof(Name));
if (found_name && robs_strcmp(found_name, spelling) == 0) if (found_name && robs_strcmp(found_name, spelling) == 0)
@@ -218,8 +239,12 @@ Name *name_add(rt, spelling, sector)
*rt = node; *rt = node;
return node; return node;
} }
#line 5324 "nuweb.w"
} }
Name *collect_file_name()
#line 5363 "nuweb.w"
Name *collect_file_name(void)
{ {
Name *new_name; Name *new_name;
char name[MAX_NAME_LEN]; char name[MAX_NAME_LEN];
@@ -241,6 +266,8 @@ Name *collect_file_name()
/* File names are always global. */ /* File names are always global. */
new_name = name_add(&file_names, name, 0); new_name = name_add(&file_names, name, 0);
/* Handle optional per-file flags */ /* Handle optional per-file flags */
#line 5396 "nuweb.w"
{ {
while (1) { while (1) {
while (isspace(c)) while (isspace(c))
@@ -255,7 +282,9 @@ Name *collect_file_name()
break; break;
case 'i': new_name->indent_flag = FALSE; case 'i': new_name->indent_flag = FALSE;
break; break;
case 'c': c = source_get(); case 'c':
#line 5425 "nuweb.w"
c = source_get();
if (c == 'c') if (c == 'c')
new_name->comment_flag = 1; new_name->comment_flag = 1;
else if (c == '+') else if (c == '+')
@@ -266,6 +295,8 @@ Name *collect_file_name()
fprintf(stderr, "%s: Unrecognised comment flag (%s, %d)\n", fprintf(stderr, "%s: Unrecognised comment flag (%s, %d)\n",
command_name, source_name, source_line); command_name, source_name, source_line);
#line 5410 "nuweb.w"
break; break;
default : fprintf(stderr, "%s: unexpected per-file flag (%s, %d)\n", default : fprintf(stderr, "%s: unexpected per-file flag (%s, %d)\n",
command_name, source_name, source_line); command_name, source_name, source_line);
@@ -277,6 +308,8 @@ Name *collect_file_name()
else break; else break;
} }
} }
#line 5384 "nuweb.w"
c2 = source_get(); c2 = source_get();
if (c != nw_char || (c2 != '{' && c2 != '(' && c2 != '[')) { if (c != nw_char || (c2 != '{' && c2 != '(' && c2 != '[')) {
fprintf(stderr, "%s: expected %c{, %c[, or %c( after file name (%s, %d)\n", fprintf(stderr, "%s: expected %c{, %c[, or %c( after file name (%s, %d)\n",
@@ -285,7 +318,9 @@ Name *collect_file_name()
} }
return new_name; return new_name;
} }
Name *collect_macro_name()
#line 5446 "nuweb.w"
Name *collect_macro_name(void)
{ {
char name[MAX_NAME_LEN]; char name[MAX_NAME_LEN];
char args[1000]; char args[1000];
@@ -312,7 +347,9 @@ Name *collect_macro_name()
c = source_get(); c = source_get();
while (c == ' ' || c == '\t'); while (c == ' ' || c == '\t');
break; break;
case '\n': { case '\n':
#line 5564 "nuweb.w"
{
do do
c = source_get(); c = source_get();
while (isspace(c)); while (isspace(c));
@@ -323,6 +360,8 @@ Name *collect_macro_name()
exit(-1); exit(-1);
} }
/* Cleanup and install name */ /* Cleanup and install name */
#line 5547 "nuweb.w"
{ {
if (p > name && p[-1] == ' ') if (p > name && p[-1] == ' ')
p--; p--;
@@ -338,18 +377,26 @@ Name *collect_macro_name()
*p = '\0'; *p = '\0';
node = prefix_add(&macro_names, name, sector); node = prefix_add(&macro_names, name, sector);
} }
#line 5574 "nuweb.w"
return install_args(node, argc, arg); return install_args(node, argc, arg);
} }
#line 5473 "nuweb.w"
default: default:
if (c==nw_char) if (c==nw_char)
{ {
/* Check for terminating at-sequence and return name */ /* Check for terminating at-sequence and return name */
#line 5494 "nuweb.w"
{ {
c = source_get(); c = source_get();
switch (c) { switch (c) {
case '(': case '(':
case '[': case '[':
case '{': { case '{':
#line 5547 "nuweb.w"
{
if (p > name && p[-1] == ' ') if (p > name && p[-1] == ' ')
p--; p--;
if (p - name > 3 && p[-1] == '.' && p[-2] == '.' && p[-3] == '.') { if (p - name > 3 && p[-1] == '.' && p[-2] == '.' && p[-3] == '.') {
@@ -364,18 +411,26 @@ Name *collect_macro_name()
*p = '\0'; *p = '\0';
node = prefix_add(&macro_names, name, sector); node = prefix_add(&macro_names, name, sector);
} }
#line 5499 "nuweb.w"
return install_args(node, argc, arg); return install_args(node, argc, arg);
case '\'': arg[argc] = argp; case '\'':
#line 5517 "nuweb.w"
arg[argc] = argp;
while ((c = source_get()) != EOF) { while ((c = source_get()) != EOF) {
if (c==nw_char) { if (c==nw_char) {
c2 = source_get(); c2 = source_get();
if (c2=='\'') { if (c2=='\'') {
/* Make this argument */ /* Make this argument */
#line 5540 "nuweb.w"
if (argc < 9) { if (argc < 9) {
*argp++ = '\000'; *argp++ = '\000';
argc += 1; argc += 1;
} }
#line 5522 "nuweb.w"
c = source_get(); c = source_get();
break; break;
} }
@@ -387,6 +442,8 @@ Name *collect_macro_name()
} }
*p++ = ARG_CHR; *p++ = ARG_CHR;
#line 5501 "nuweb.w"
break; break;
default: default:
if (c==nw_char) if (c==nw_char)
@@ -400,6 +457,8 @@ Name *collect_macro_name()
exit(-1); exit(-1);
} }
} }
#line 5477 "nuweb.w"
break; break;
} }
*p++ = c; *p++ = c;
@@ -412,6 +471,8 @@ Name *collect_macro_name()
exit(-1); exit(-1);
return NULL; /* unreachable return to avoid warnings on some compilers */ return NULL; /* unreachable return to avoid warnings on some compilers */
} }
#line 5583 "nuweb.w"
Name *install_args(Name * name, int argc, char *arg[9]) Name *install_args(Name * name, int argc, char *arg[9])
{ {
int i; int i;
@@ -422,6 +483,8 @@ Name *install_args(Name * name, int argc, char *arg[9])
} }
return name; return name;
} }
#line 5604 "nuweb.w"
Arglist * buildArglist(Name * name, Arglist * a) Arglist * buildArglist(Name * name, Arglist * a)
{ {
Arglist * args = (Arglist *)arena_getmem(sizeof(Arglist)); Arglist * args = (Arglist *)arena_getmem(sizeof(Arglist));
@@ -431,6 +494,8 @@ Arglist * buildArglist(Name * name, Arglist * a)
args->name = name; args->name = name;
return args; return args;
} }
#line 5617 "nuweb.w"
Arglist * collect_scrap_name(int current_scrap) Arglist * collect_scrap_name(int current_scrap)
{ {
char name[MAX_NAME_LEN]; char name[MAX_NAME_LEN];
@@ -459,6 +524,8 @@ Arglist * collect_scrap_name(int current_scrap)
if (c==nw_char) if (c==nw_char)
{ {
/* Look for end of scrap name and return */ /* Look for end of scrap name and return */
#line 5666 "nuweb.w"
{ {
Name * node; Name * node;
@@ -467,6 +534,8 @@ Arglist * collect_scrap_name(int current_scrap)
case '\'': { case '\'': {
/* Add plain string argument */ /* Add plain string argument */
#line 5723 "nuweb.w"
char buff[MAX_NAME_LEN]; char buff[MAX_NAME_LEN];
char * s = buff; char * s = buff;
int c, c2; int c, c2;
@@ -483,9 +552,15 @@ Arglist * collect_scrap_name(int current_scrap)
} }
*s = '\000'; *s = '\000';
/* Add buff to current arg list */ /* 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; tail = &(*tail)->next;
#line 5738 "nuweb.w"
#line 5673 "nuweb.w"
} }
*p++ = ARG_CHR; *p++ = ARG_CHR;
c = source_get(); c = source_get();
@@ -494,20 +569,30 @@ Arglist * collect_scrap_name(int current_scrap)
case '4': case '5': case '6': case '4': case '5': case '6':
case '7': case '8': case '9': { case '7': case '8': case '9': {
/* Add a propagated argument */ /* Add a propagated argument */
#line 5744 "nuweb.w"
char buff[3]; char buff[3];
buff[0] = ARG_CHR; buff[0] = ARG_CHR;
buff[1] = c; buff[1] = c;
buff[2] = '\000'; buff[2] = '\000';
/* Add buff to current arg list */ /* 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; tail = &(*tail)->next;
#line 5748 "nuweb.w"
#line 5681 "nuweb.w"
} }
*p++ = ARG_CHR; *p++ = ARG_CHR;
c = source_get(); c = source_get();
break; break;
case '{': { case '{': {
/* Add an inline scrap argument */ /* Add an inline scrap argument */
#line 5751 "nuweb.w"
int s = collect_scrap(); int s = collect_scrap();
Scrap_Node * d = (Scrap_Node *)arena_getmem(sizeof(Scrap_Node)); Scrap_Node * d = (Scrap_Node *)arena_getmem(sizeof(Scrap_Node));
d->scrap = s; d->scrap = s;
@@ -515,23 +600,31 @@ Arglist * collect_scrap_name(int current_scrap)
d->next = NULL; d->next = NULL;
*tail = buildArglist((Name *)1, (Arglist *)d); *tail = buildArglist((Name *)1, (Arglist *)d);
tail = &(*tail)->next; tail = &(*tail)->next;
#line 5687 "nuweb.w"
} }
*p++ = ARG_CHR; *p++ = ARG_CHR;
c = source_get(); c = source_get();
break; break;
case '<': case '<':
/* Add macro call argument */ /* Add macro call argument */
#line 5767 "nuweb.w"
*tail = collect_scrap_name(current_scrap); *tail = collect_scrap_name(current_scrap);
if (current_scrap >= 0) if (current_scrap >= 0)
add_to_use((*tail)->name, current_scrap); add_to_use((*tail)->name, current_scrap);
tail = &(*tail)->next; tail = &(*tail)->next;
#line 5693 "nuweb.w"
*p++ = ARG_CHR; *p++ = ARG_CHR;
c = source_get(); c = source_get();
break; break;
case '(': case '(':
scrap_name_has_parameters = 1; scrap_name_has_parameters = 1;
/* Cleanup and install name */ /* Cleanup and install name */
#line 5547 "nuweb.w"
{ {
if (p > name && p[-1] == ' ') if (p > name && p[-1] == ' ')
p--; p--;
@@ -547,10 +640,14 @@ Arglist * collect_scrap_name(int current_scrap)
*p = '\0'; *p = '\0';
node = prefix_add(&macro_names, name, sector); node = prefix_add(&macro_names, name, sector);
} }
#line 5699 "nuweb.w"
return buildArglist(node, head); return buildArglist(node, head);
case '>': case '>':
scrap_name_has_parameters = 0; scrap_name_has_parameters = 0;
/* Cleanup and install name */ /* Cleanup and install name */
#line 5547 "nuweb.w"
{ {
if (p > name && p[-1] == ' ') if (p > name && p[-1] == ' ')
p--; p--;
@@ -566,6 +663,8 @@ Arglist * collect_scrap_name(int current_scrap)
*p = '\0'; *p = '\0';
node = prefix_add(&macro_names, name, sector); node = prefix_add(&macro_names, name, sector);
} }
#line 5703 "nuweb.w"
return buildArglist(node, head); return buildArglist(node, head);
default: default:
@@ -581,6 +680,8 @@ Arglist * collect_scrap_name(int current_scrap)
exit(-1); exit(-1);
} }
} }
#line 5644 "nuweb.w"
break; break;
} }
if (!isgraph(c)) { if (!isgraph(c)) {
@@ -599,10 +700,11 @@ Arglist * collect_scrap_name(int current_scrap)
exit(-1); exit(-1);
return NULL; /* unreachable return to avoid warnings on some compilers */ return NULL; /* unreachable return to avoid warnings on some compilers */
} }
static Scrap_Node *reverse(); /* a forward declaration */
void reverse_lists(names) #line 5779 "nuweb.w"
Name *names; static Scrap_Node *reverse(Scrap_Node *a); /* a forward declaration */
void reverse_lists(Name *names)
{ {
while (names) { while (names) {
reverse_lists(names->llink); reverse_lists(names->llink);
@@ -611,8 +713,9 @@ void reverse_lists(names)
names = names->rlink; names = names->rlink;
} }
} }
static Scrap_Node *reverse(a)
Scrap_Node *a; #line 5796 "nuweb.w"
static Scrap_Node *reverse(Scrap_Node *a)
{ {
if (a) { if (a) {
Scrap_Node *b = a->next; Scrap_Node *b = a->next;

471
nuweb.w

File diff suppressed because it is too large Load Diff

View File

@@ -1,10 +1,15 @@
#line 908 "nuweb.w"
#include "global.h" #include "global.h"
void write_files(files)
Name *files; #line 3768 "nuweb.w"
void write_files(Name *files)
{ {
while (files) { while (files) {
write_files(files->llink); write_files(files->llink);
/* Write out \verb|files->spelling| */ /* Write out \verb|files->spelling| */
#line 3789 "nuweb.w"
{ {
static char temp_name[FILENAME_MAX]; static char temp_name[FILENAME_MAX];
static char real_name[FILENAME_MAX]; static char real_name[FILENAME_MAX];
@@ -14,6 +19,8 @@ void write_files(files)
/* Find a free temporary file */ /* Find a free temporary file */
#line 3809 "nuweb.w"
for( temp_name_count = 0; temp_name_count < 10000; temp_name_count++) { for( temp_name_count = 0; temp_name_count < 10000; temp_name_count++) {
sprintf(temp_name,"%s%snw%06d", dirpath, path_sep, temp_name_count); sprintf(temp_name,"%s%snw%06d", dirpath, path_sep, temp_name_count);
#ifdef O_EXCL #ifdef O_EXCL
@@ -38,6 +45,8 @@ void write_files(files)
exit(-1); exit(-1);
} }
#line 3796 "nuweb.w"
sprintf(real_name, "%s%s%s", dirpath, path_sep, files->spelling); sprintf(real_name, "%s%s%s", dirpath, path_sep, files->spelling);
if (verbose_flag) if (verbose_flag)
@@ -49,8 +58,12 @@ void write_files(files)
/* Move the temporary file to the target, if required */ /* Move the temporary file to the target, if required */
#line 3839 "nuweb.w"
if (compare_flag) if (compare_flag)
/* Compare the temp file and the old file */ /* Compare the temp file and the old file */
#line 3850 "nuweb.w"
{ {
FILE *old_file = fopen(real_name, "r"); FILE *old_file = fopen(real_name, "r");
if (old_file) { if (old_file) {
@@ -68,34 +81,52 @@ void write_files(files)
remove(real_name); remove(real_name);
/* Rename the temporary file to the target */ /* Rename the temporary file to the target */
#line 3872 "nuweb.w"
if (0 != rename(temp_name, real_name)) { if (0 != rename(temp_name, real_name)) {
fprintf(stderr, "%s: can't rename output file to %s\n", fprintf(stderr, "%s: can't rename output file to %s\n",
command_name, real_name); command_name, real_name);
} }
#line 3865 "nuweb.w"
} }
} }
else else
/* Rename the temporary file to the target */ /* Rename the temporary file to the target */
#line 3872 "nuweb.w"
if (0 != rename(temp_name, real_name)) { if (0 != rename(temp_name, real_name)) {
fprintf(stderr, "%s: can't rename output file to %s\n", fprintf(stderr, "%s: can't rename output file to %s\n",
command_name, real_name); command_name, real_name);
} }
#line 3869 "nuweb.w"
} }
#line 3841 "nuweb.w"
else { else {
remove(real_name); remove(real_name);
/* Rename the temporary file to the target */ /* Rename the temporary file to the target */
#line 3872 "nuweb.w"
if (0 != rename(temp_name, real_name)) { if (0 != rename(temp_name, real_name)) {
fprintf(stderr, "%s: can't rename output file to %s\n", fprintf(stderr, "%s: can't rename output file to %s\n",
command_name, real_name); command_name, real_name);
} }
} #line 3844 "nuweb.w"
} }
#line 3806 "nuweb.w"
}
#line 3772 "nuweb.w"
files = files->rlink; files = files->rlink;
} }
} }

85
pass1.c
View File

@@ -1,6 +1,9 @@
#line 885 "nuweb.w"
#include "global.h" #include "global.h"
void pass1(file_name)
char *file_name; #line 1414 "nuweb.w"
void pass1(char *file_name)
{ {
if (verbose_flag) if (verbose_flag)
fprintf(stderr, "reading %s\n", file_name); fprintf(stderr, "reading %s\n", file_name);
@@ -10,11 +13,15 @@ void pass1(file_name)
file_names = NULL; file_names = NULL;
user_names = NULL; user_names = NULL;
/* Scan the source file, looking for at-sequences */ /* Scan the source file, looking for at-sequences */
#line 1433 "nuweb.w"
{ {
int c = source_get(); int c = source_get();
while (c != EOF) { while (c != EOF) {
if (c == nw_char) if (c == nw_char)
/* Scan at-sequence */ /* Scan at-sequence */
#line 1446 "nuweb.w"
{ {
char quoted = 0; char quoted = 0;
@@ -26,10 +33,14 @@ void pass1(file_name)
update_delimit_scrap(); update_delimit_scrap();
break; break;
case 'O': case 'O':
case 'o': { case 'o':
#line 1524 "nuweb.w"
{
Name *name = collect_file_name(); /* returns a pointer to the name entry */ Name *name = collect_file_name(); /* returns a pointer to the name entry */
int scrap = collect_scrap(); /* returns an index to the scrap */ int scrap = collect_scrap(); /* returns an index to the scrap */
/* Add \verb|scrap| to \verb|name|'s definition list */ /* Add \verb|scrap| to \verb|name|'s definition list */
#line 1543 "nuweb.w"
{ {
Scrap_Node *def = (Scrap_Node *) arena_getmem(sizeof(Scrap_Node)); Scrap_Node *def = (Scrap_Node *) arena_getmem(sizeof(Scrap_Node));
def->scrap = scrap; def->scrap = scrap;
@@ -37,15 +48,23 @@ void pass1(file_name)
def->next = name->defs; def->next = name->defs;
name->defs = def; name->defs = def;
} }
#line 1527 "nuweb.w"
} }
#line 1457 "nuweb.w"
break; break;
case 'Q': case 'Q':
case 'q': quoted = 1; case 'q': quoted = 1;
case 'D': case 'D':
case 'd': { case 'd':
#line 1532 "nuweb.w"
{
Name *name = collect_macro_name(); Name *name = collect_macro_name();
int scrap = collect_scrap(); int scrap = collect_scrap();
/* Add \verb|scrap| to \verb|name|'s definition list */ /* Add \verb|scrap| to \verb|name|'s definition list */
#line 1543 "nuweb.w"
{ {
Scrap_Node *def = (Scrap_Node *) arena_getmem(sizeof(Scrap_Node)); Scrap_Node *def = (Scrap_Node *) arena_getmem(sizeof(Scrap_Node));
def->scrap = scrap; def->scrap = scrap;
@@ -53,26 +72,40 @@ void pass1(file_name)
def->next = name->defs; def->next = name->defs;
name->defs = def; name->defs = def;
} }
#line 1535 "nuweb.w"
} }
#line 1462 "nuweb.w"
break; break;
case 's': case 's':
/* Step to next sector */ /* Step to next sector */
#line 1493 "nuweb.w"
prev_sector += 1; prev_sector += 1;
current_sector = prev_sector; current_sector = prev_sector;
c = source_get(); c = source_get();
#line 1465 "nuweb.w"
break; break;
case 'S': case 'S':
/* Close the current sector */ /* Close the current sector */
#line 1500 "nuweb.w"
current_sector = 1; current_sector = 1;
c = source_get(); c = source_get();
#line 1468 "nuweb.w"
break; break;
case '<': case '<':
case '(': case '(':
case '[': case '[':
case '{': case '{':
#line 1552 "nuweb.w"
{ {
int c; int c;
int depth = 1; int depth = 1;
@@ -80,6 +113,8 @@ void pass1(file_name)
if (c == nw_char) if (c == nw_char)
/* Skip over at-sign or go to skipped */ /* Skip over at-sign or go to skipped */
#line 1569 "nuweb.w"
{ {
c = source_get(); c = source_get();
switch (c) { switch (c) {
@@ -107,6 +142,8 @@ void pass1(file_name)
} }
} }
#line 1558 "nuweb.w"
} }
fprintf(stderr, "%s: unexpected EOF in text at (%s, %d)\n", fprintf(stderr, "%s: unexpected EOF in text at (%s, %d)\n",
command_name, source_name, source_line); command_name, source_name, source_line);
@@ -115,25 +152,37 @@ void pass1(file_name)
skipped: ; skipped: ;
} }
#line 1473 "nuweb.w"
break; break;
case 'c': { case 'c':
#line 1600 "nuweb.w"
{
char * p = blockBuff; char * p = blockBuff;
char * e = blockBuff + (sizeof(blockBuff)/sizeof(blockBuff[0])) - 1; char * e = blockBuff + (sizeof(blockBuff)/sizeof(blockBuff[0])) - 1;
/* Skip whitespace */ /* Skip whitespace */
#line 1618 "nuweb.w"
while (source_peek == ' ' while (source_peek == ' '
|| source_peek == '\t' || source_peek == '\t'
|| source_peek == '\n') || source_peek == '\n')
(void)source_get(); (void)source_get();
#line 1604 "nuweb.w"
while (p < e) while (p < e)
{ {
/* Add one char to the block buffer */ /* Add one char to the block buffer */
#line 1625 "nuweb.w"
int c = source_get(); int c = source_get();
if (c == nw_char) if (c == nw_char)
{ {
/* Add an at character to the block or break */ /* Add an at character to the block or break */
#line 1643 "nuweb.w"
int cc = source_peek; int cc = source_peek;
if (cc == 'c') if (cc == 'c')
@@ -161,6 +210,8 @@ void pass1(file_name)
*p++ = source_get(); *p++ = source_get();
} }
#line 1629 "nuweb.w"
} }
else if (c == EOF) else if (c == EOF)
{ {
@@ -171,7 +222,11 @@ void pass1(file_name)
{ {
/* Add any other character to the block */ /* Add any other character to the block */
#line 1672 "nuweb.w"
/* Perhaps skip white-space */ /* Perhaps skip white-space */
#line 1678 "nuweb.w"
if (c == ' ') if (c == ' ')
{ {
while (source_peek == ' ') while (source_peek == ' ')
@@ -189,22 +244,34 @@ void pass1(file_name)
c = ' '; c = ' ';
} }
#line 1673 "nuweb.w"
*p++ = c; *p++ = c;
#line 1638 "nuweb.w"
} }
#line 1607 "nuweb.w"
} }
if (p == e) if (p == e)
{ {
/* Skip to the next nw-char */ /* Skip to the next nw-char */
#line 1697 "nuweb.w"
int c; int c;
while ((c = source_get()), c != nw_char && c != EOF)/* Skip */ while ((c = source_get()), c != nw_char && c != EOF)/* Skip */
source_ungetc(&c); source_ungetc(&c);
#line 1611 "nuweb.w"
} }
*p = '\000'; *p = '\000';
} }
#line 1475 "nuweb.w"
break; break;
case 'x': case 'x':
case 'v': case 'v':
@@ -220,15 +287,23 @@ void pass1(file_name)
break; break;
} }
} }
#line 1437 "nuweb.w"
c = source_get(); c = source_get();
} }
} }
#line 1423 "nuweb.w"
if (tex_flag) if (tex_flag)
search(); search();
/* Reverse cross-reference lists */ /* Reverse cross-reference lists */
#line 1802 "nuweb.w"
{ {
reverse_lists(file_names); reverse_lists(file_names);
reverse_lists(macro_names); reverse_lists(macro_names);
reverse_lists(user_names); reverse_lists(user_names);
} }
#line 1426 "nuweb.w"
} }

605
scraps.c

File diff suppressed because it is too large Load Diff