summaryrefslogtreecommitdiff
path: root/web/c_cpp/cweb/cweave.w
diff options
context:
space:
mode:
Diffstat (limited to 'web/c_cpp/cweb/cweave.w')
-rw-r--r--web/c_cpp/cweb/cweave.w1456
1 files changed, 750 insertions, 706 deletions
diff --git a/web/c_cpp/cweb/cweave.w b/web/c_cpp/cweb/cweave.w
index e06762b1fc..a8e31055b2 100644
--- a/web/c_cpp/cweb/cweave.w
+++ b/web/c_cpp/cweb/cweave.w
@@ -2,10 +2,7 @@
% This program by Silvio Levy and Donald E. Knuth
% is based on a program by Knuth.
% It is distributed WITHOUT ANY WARRANTY, express or implied.
-% Version 3.64 --- February 2002
-% (essentially the same as version 3.6, which added
-% recently introduced features of standard C++ to version 3.4)
-% (In November 2016 I made minor adjustments but changed no code -- DEK)
+% Version 4.2 --- February 2021
% Copyright (C) 1987,1990,1993,2000 Silvio Levy and Donald E. Knuth
@@ -18,6 +15,11 @@
% entire resulting derived work is given a different name and distributed
% under the terms of a permission notice identical to this one.
+% Amendments to 'cweave.w' resulting in this updated version were created
+% by numerous collaborators over the course of many years.
+
+% Please send comments, suggestions, etc. to tex-k@@tug.org.
+
% Here is TeX material that gets inserted after \input cwebmac
\def\hang{\hangindent 3em\indent\ignorespaces}
\def\pb{$\.|\ldots\.|$} % C brackets (|...|)
@@ -30,11 +32,11 @@
\def\skipxTeX{\\{skip\_\TEX/}}
\def\copyxTeX{\\{copy\_\TEX/}}
-\def\title{CWEAVE (Version 3.64)}
+\def\title{CWEAVE (Version 4.2)}
\def\topofcontents{\null\vfill
\centerline{\titlefont The {\ttitlefont CWEAVE} processor}
\vskip 15pt
- \centerline{(Version 3.64)}
+ \centerline{(Version 4.2)}
\vfill}
\def\botofcontents{\vfill
\noindent
@@ -52,7 +54,6 @@ under the terms of a permission notice identical to this one.
}
\pageno=\contentspagenumber \advance\pageno by 1
\let\maybe=\iftrue
-@s not_eq normal @q unreserve a C++ keyword @>
@** Introduction.
This is the \.{CWEAVE} program by Silvio Levy and Donald E. Knuth,
@@ -66,27 +67,15 @@ Crusius, and others who have contributed improvements.
The ``banner line'' defined here should be changed whenever \.{CWEAVE}
is modified.
-@d banner "This is CWEAVE (Version 3.64)\n"
+@d banner "This is CWEAVE (Version 4.2)"
@c @<Include files@>@/
@h
@<Common code for \.{CWEAVE} and \.{CTANGLE}@>@/
@<Typedef declarations@>@/
-@<Global variables@>@/
+@<Private variables@>@/
@<Predeclaration of procedures@>
-@ We predeclare several standard system functions here instead of including
-their system header files, because the names of the header files are not as
-standard as the names of the functions. (For example, some \CEE/ environments
-have \.{<string.h>} where others have \.{<strings.h>}.)
-
-@<Predecl...@>=
-extern int strlen(); /* length of string */
-extern int strcmp(); /* compare strings lexicographically */
-extern char* strcpy(); /* copy one string to another */
-extern int strncmp(); /* compare up to $n$ string characters */
-extern char* strncpy(); /* copy up to $n$ string characters */
-
@ \.{CWEAVE} has a fairly straightforward outline. It operates in
three phases: First it inputs the source file and stores cross-reference
data, then it inputs the source once again and produces the \TEX/ output
@@ -96,52 +85,40 @@ Please read the documentation for \.{common}, the set of routines common
to \.{CTANGLE} and \.{CWEAVE}, before proceeding further.
@c
-int main (ac, av)
-int ac; /* argument count */
-char **av; /* argument values */
+int main (@t\1\1@>
+int ac, /* argument count */
+char **av@t\2\2@>) /* argument values */
{
argc=ac; argv=av;
program=cweave;
- make_xrefs=force_lines=make_pb=1; /* controlled by command-line options */
+ @<Set initial values@>@;
common_init();
- @<Set initial values@>;
- if (show_banner) printf(banner); /* print a ``banner line'' */
- @<Store all the reserved words@>;
+ @<Start \TEX/ output@>@;
+ if (show_banner) puts(banner); /* print a ``banner line'' */
+ @<Store all the reserved words@>@;
phase_one(); /* read all the user's text and store the cross-references */
phase_two(); /* read all the text again and translate it to \TEX/ form */
phase_three(); /* output the cross-reference index */
+ if (tracing==2 && !show_progress) new_line;
return wrap_up(); /* and exit gracefully */
}
+@ The next few sections contain stuff from the file |"common.w"| that must
+be included in both |"ctangle.w"| and |"cweave.w"|. It appears in
+file |"common.h"|, which is also included in |"common.w"| to propagate
+possible changes from this \.{COMMON} interface consistently.
+
+@i common.h
+
@ The following parameters were sufficient in the original \.{WEAVE} to
handle \TEX/, so they should be sufficient for most applications of \.{CWEAVE}.
-If you change |max_bytes|, |max_names|, |hash_size|, or |buf_size|
-you have to change them also in the file |"common.w"|.
-
-@d max_bytes 90000 /* the number of bytes in identifiers,
- index entries, and section names */
-@d max_names 4000 /* number of identifiers, strings, section names;
- must be less than 10240; used in |"common.w"| */
-@d max_sections 2000 /* greater than the total number of sections */
-@d hash_size 353 /* should be prime */
-@d buf_size 100 /* maximum length of input line, plus one */
-@d longest_name 10000 /* section names and strings shouldn't be longer than this */
-@d long_buf_size (buf_size+longest_name)
+
@d line_length 80 /* lines of \TEX/ output have at most this many characters;
should be less than 256 */
-@d max_refs 20000 /* number of cross-references; must be less than 65536 */
-@d max_toks 20000 /* number of symbols in \CEE/ texts being parsed;
- must be less than 65536 */
-@d max_texts 4000 /* number of phrases in \CEE/ texts being parsed;
+@d max_refs 65535 /* number of cross-references; must be less than 65536 */
+@d max_texts 10239 /* number of phrases in \CEE/ texts being parsed;
must be less than 10240 */
-@d max_scraps 2000 /* number of tokens in \CEE/ texts being parsed */
-@d stack_size 400 /* number of simultaneous output levels */
-
-@ The next few sections contain stuff from the file |"common.w"| that must
-be included in both |"ctangle.w"| and |"cweave.w"|. It appears in
-file |"common.h"|, which needs to be updated when |"common.w"| changes.
-
-@i common.h
+@d max_scraps 10000 /* number of tokens in \CEE/ texts being parsed */
@* Data structures exclusive to {\tt CWEAVE}.
As explained in \.{common.w}, the field of a |name_info| structure
@@ -205,8 +182,8 @@ is the total number of sections that have started. Sections which have
been altered by a change file entry have their |changed_section| flag
turned on during the first phase.
-@<Global...@>=
-boolean change_exists; /* has any section changed? */
+@<Private...@>=
+static boolean change_exists; /* has any section changed? */
@ The other large memory area in \.{CWEAVE} keeps the cross-reference data.
All uses of the name |p| are recorded in a linked list beginning at
@@ -237,11 +214,11 @@ typedef struct xref_info {
} xref_info;
typedef xref_info *xref_pointer;
-@ @<Global...@>=
-xref_info xmem[max_refs]; /* contains cross-reference information */
-xref_pointer xmem_end = xmem+max_refs-1;
-xref_pointer xref_ptr; /* the largest occupied position in |xmem| */
-sixteen_bits xref_switch,section_xref_switch; /* either zero or |def_flag| */
+@ @<Private...@>=
+static xref_info xmem[max_refs]; /* contains cross-reference information */
+static xref_pointer xmem_end = xmem+max_refs-1;
+static xref_pointer xref_ptr; /* the largest occupied position in |xmem| */
+static sixteen_bits xref_switch,section_xref_switch; /* either zero or |def_flag| */
@ A section that is used for multi-file output (with the \.{@@(} feature)
has a special first cross-reference whose |num| field is |file_flag|.
@@ -252,7 +229,7 @@ has a special first cross-reference whose |num| field is |file_flag|.
@d xref equiv_or_xref
@<Set init...@>=
-xref_ptr=xmem; name_dir->xref=(char*)xmem; xref_switch=0; section_xref_switch=0;
+xref_ptr=xmem; init_node(name_dir); xref_switch=0; section_xref_switch=0;
xmem->num=0; /* sentinel value */
@ A new cross-reference for an identifier is formed by calling |new_xref|,
@@ -266,16 +243,20 @@ If one were careful, one could probably make more changes around section
@d append_xref(c) if (xref_ptr==xmem_end) overflow("cross-reference");
else (++xref_ptr)->num=c;
-@d no_xref (flags['x']==0)
-@d make_xrefs flags['x'] /* should cross references be output? */
+@d no_xref (!make_xrefs)
@d is_tiny(p) ((p+1)->byte_start==(p)->byte_start+1)
@d unindexed(a) (a<res_wd_end && a->ilk>=custom)
/* tells if uses of a name are to be indexed */
-@c
-void
-new_xref(p)
-name_pointer p;
+@<Predecl...@>=
+static void new_xref(name_pointer);@/
+static void new_section_xref(name_pointer);@/
+static void set_file_flag(name_pointer);
+
+@ @c
+static void
+new_xref(
+name_pointer p)
{
xref_pointer q; /* pointer to previous cross-reference */
sixteen_bits m, n; /* new and previous cross-reference value */
@@ -289,7 +270,7 @@ name_pointer p;
q->num=m; return;
}
}
- append_xref(m); xref_ptr->xlink=q; p->xref=(char*)xref_ptr;
+ append_xref(m); xref_ptr->xlink=q; update_node(p);
}
@ The cross-reference lists for section names are slightly different.
@@ -304,9 +285,9 @@ the length of the list, under foreseeable uses of \.{CWEAVE} this inefficiency
is insignificant.
@c
-void
-new_section_xref(p)
-name_pointer p;
+static void
+new_section_xref(
+name_pointer p)
{
xref_pointer q,r; /* pointers to previous cross-references */
q=(xref_pointer)p->xref; r=xmem;
@@ -316,7 +297,7 @@ name_pointer p;
return; /* don't duplicate entries */
append_xref(section_count+section_xref_switch);
xref_ptr->xlink=q; section_xref_switch=0;
- if (r==xmem) p->xref=(char*)xref_ptr;
+ if (r==xmem) update_node(p);
else r->xlink=xref_ptr;
}
@@ -324,23 +305,23 @@ name_pointer p;
|file_flag|. Here's how that flag gets put~in.
@c
-void
-set_file_flag(p)
-name_pointer p;
+static void
+set_file_flag(
+name_pointer p)
{
xref_pointer q;
q=(xref_pointer)p->xref;
if (q->num==file_flag) return;
append_xref(file_flag);
xref_ptr->xlink = q;
- p->xref = (char *)xref_ptr;
+ update_node(p);
}
@ A third large area of memory is used for sixteen-bit `tokens', which appear
in short lists similar to the strings of characters in |byte_mem|. Token lists
are used to contain the result of \CEE/ code translated into \TEX/ form;
-further details about them will be explained later. A |text_pointer| variable
-is an index into |tok_start|.
+further details about them will be explained later. A \&{text\_pointer}
+variable is an index into |tok_start|.
@<Typed...@>=
typedef sixteen_bits token;
@@ -352,49 +333,58 @@ that is unoccupied by replacement text is called |tok_ptr|, and the first
unused location of |tok_start| is called |text_ptr|.
Thus, we usually have |*text_ptr==tok_ptr|.
-@<Global...@>=
-token tok_mem[max_toks]; /* tokens */
-token_pointer tok_mem_end = tok_mem+max_toks-1; /* end of |tok_mem| */
-token_pointer tok_start[max_texts]; /* directory into |tok_mem| */
-token_pointer tok_ptr; /* first unused position in |tok_mem| */
-text_pointer text_ptr; /* first unused position in |tok_start| */
-text_pointer tok_start_end = tok_start+max_texts-1; /* end of |tok_start| */
-token_pointer max_tok_ptr; /* largest value of |tok_ptr| */
-text_pointer max_text_ptr; /* largest value of |text_ptr| */
+@<Private...@>=
+static token tok_mem[max_toks]; /* tokens */
+static token_pointer tok_mem_end = tok_mem+max_toks-1; /* end of |tok_mem| */
+static token_pointer tok_ptr; /* first unused position in |tok_mem| */
+static token_pointer max_tok_ptr; /* largest value of |tok_ptr| */
+static token_pointer tok_start[max_texts]; /* directory into |tok_mem| */
+static text_pointer tok_start_end = tok_start+max_texts-1; /* end of |tok_start| */
+static text_pointer text_ptr; /* first unused position in |tok_start| */
+static text_pointer max_text_ptr; /* largest value of |text_ptr| */
@ @<Set init...@>=
-tok_ptr=tok_mem+1; text_ptr=tok_start+1; tok_start[0]=tok_mem+1;
-tok_start[1]=tok_mem+1;
-max_tok_ptr=tok_mem+1; max_text_ptr=tok_start+1;
+tok_ptr=max_tok_ptr=tok_mem+1;@/
+tok_start[0]=tok_start[1]=tok_mem+1;@/
+text_ptr=max_text_ptr=tok_start+1;
@ Here are the three procedures needed to complete |id_lookup|:
@c
-int names_match(p,first,l,t)
-name_pointer p; /* points to the proposed match */
-char *first; /* position of first character of string */
-int l; /* length of identifier */
-eight_bits t; /* desired ilk */
+boolean names_match(@t\1\1@>
+name_pointer p, /* points to the proposed match */
+const char *first, /* position of first character of string */
+size_t l, /* length of identifier */
+eight_bits t@t\2\2@>) /* desired |ilk| */
{
- if (length(p)!=l) return 0;
- if (p->ilk!=t && !(t==normal && abnormal(p))) return 0;
+ if (length(p)!=l) return false;
+ if (p->ilk!=t && !(t==normal && abnormal(p))) return false;
return !strncmp(first,p->byte_start,l);
}
void
-init_p(p,t)
-name_pointer p;
-eight_bits t;
+init_p(
+name_pointer p,
+eight_bits t)
{
- p->ilk=t; p->xref=(char*)xmem;
+ p->ilk=t; init_node(p);
}
void
-init_node(p)
-name_pointer p;
+init_node(
+name_pointer p)
{
- p->xref=(char*)xmem;
+ p->xref=(void *)xmem;
}
+static void
+update_node(
+name_pointer p)
+{
+ p->xref=(void *)xref_ptr;
+}
+
+@ @<Predecl...@>=@+static void update_node(name_pointer p);
+
@ We have to get \CEE/'s
reserved words into the hash table, and the simplest way to do this is
to insert them every time \.{CWEAVE} is run. Fortunately there are relatively
@@ -499,8 +489,7 @@ id_lookup("volatile",NULL,const_like);
id_lookup("wchar_t",NULL,raw_int);
id_lookup("while",NULL,for_like);
id_lookup("xor",NULL,alfop);
-id_lookup("xor_eq",NULL,alfop);
-res_wd_end=name_ptr;
+id_lookup("xor_eq",NULL,alfop);@+ res_wd_end=name_ptr;
id_lookup("TeX",NULL,custom);
id_lookup("make_pair",NULL,func_template);
@@ -556,8 +545,8 @@ scanning routines.
@ Control codes are converted to \.{CWEAVE}'s internal
representation by means of the table |ccode|.
-@<Global...@>=
-eight_bits ccode[256]; /* meaning of a char following \.{@@} */
+@<Private...@>=
+static eight_bits ccode[256]; /* meaning of a char following \.{@@} */
@ @<Set ini...@>=
{int c; for (c=0; c<256; c++) ccode[c]=0;}
@@ -598,19 +587,20 @@ operation appears in limbo, we want to use it to adjust the default
interpretation of identifiers.
@<Predec...@>=
-void skip_limbo();
+static void skip_limbo(void);@/
+static eight_bits skip_TeX(void);
@ @c
-void
-skip_limbo() {
- while(1) {
- if (loc>limit && get_line()==0) return;
+static void
+skip_limbo(void) {
+ while(true) {
+ if (loc>limit && get_line()==false) return;
*(limit+1)='@@';
- while (*loc!='@@') loc++; /* look for '@@', then skip two chars */
+ while (*loc!='@@') loc++; /* look for `\.{@@}', then skip two chars */
if (loc++ <=limit) { int c=ccode[(eight_bits)*loc++];
if (c==new_section) return;
if (c==noop) skip_restricted();
- else if (c==format_code) @<Process simple format in limbo@>;
+ else if (c==format_code) @<Process simple format in limbo@>@;
}
}
}
@@ -623,15 +613,15 @@ assumed to exist at the very end of the file.
@f skip_TeX TeX
@c
-unsigned
-skip_TeX() /* skip past pure \TEX/ code */
+static eight_bits
+skip_TeX(void) /* skip past pure \TEX/ code */
{
- while (1) {
- if (loc>limit && get_line()==0) return(new_section);
+ while (true) {
+ if (loc>limit && get_line()==false) return new_section;
*(limit+1)='@@';
while (*loc!='@@' && *loc!='|') loc++;
- if (*loc++ =='|') return('|');
- if (loc<=limit) return(ccode[(eight_bits)*(loc++)]);
+ if (*loc++ =='|') return '|';
+ if (loc<=limit) return ccode[(eight_bits)*(loc++)];
}
}
@@ -675,13 +665,9 @@ it sets |xref_switch| to |def_flag| and goes on to the next token.
@d string 0201 /* \CEE/ string */
@d identifier 0202 /* \CEE/ identifier or reserved word */
-@<Global...@>=
-name_pointer cur_section; /* name of section just scanned */
-char cur_section_char; /* the character just before that name */
-
-@ @<Include...@>=
-#include <ctype.h> /* definition of |isalpha|, |isdigit| and so on */
-#include <stdlib.h> /* definition of |exit| */
+@<Private...@>=
+static name_pointer cur_section; /* name of section just scanned */
+static char cur_section_char; /* the character just before that name */
@ As one might expect, |get_next| consists mostly of a big switch
that branches to the various special cases that can arise.
@@ -693,31 +679,33 @@ compilers even allow the dollar sign.
@d ishigh(c) ((eight_bits)(c)>0177)
@^high-bit character handling@>
-@<Predecl...@>=
-eight_bits get_next();
-
-@ @c
-eight_bits
-get_next() /* produces the next input token */
-{@+eight_bits c; /* the current character */
- while (1) {
- @<Check if we're at the end of a preprocessor command@>;
- if (loc>limit && get_line()==0) return(new_section);
+@c
+static eight_bits
+get_next(void) /* produces the next input token */
+{
+ eight_bits c; /* the current character */
+ while (true) {
+ @<Check if we're at the end of a preprocessor command@>@;
+ if (loc>limit && get_line()==false) return new_section;
c=*(loc++);
if (xisdigit(c) || c=='.') @<Get a constant@>@;
- else if (c=='\'' || c=='"' || (c=='L'&&(*loc=='\'' || *loc=='"'))@|
- || (c=='<' && sharp_include_line==1))
+ else if (c=='\'' || c=='"'@|
+ || ((c=='L' || c=='u' || c=='U')&&(*loc=='\'' || *loc=='"'))@|
+ || ((c=='u' && *loc=='8')&&(*(loc+1)=='\'' || *(loc+1)=='"'))@|
+ || (c=='<' && sharp_include_line==true))
@<Get a string@>@;
else if (xisalpha(c) || isxalpha(c) || ishigh(c))
@<Get an identifier@>@;
else if (c=='@@') @<Get control code and possible section name@>@;
else if (xisspace(c)) continue; /* ignore spaces and tabs */
- if (c=='#' && loc==buffer+1) @<Raise preprocessor flag@>;
+ if (c=='#' && loc==buffer+1) @<Raise preprocessor flag@>@;
mistake: @<Compress two-symbol operator@>@;
- return(c);
+ return c;
}
}
+@ @<Predecl...@>=@+static eight_bits get_next(void);
+
@ Because preprocessor commands do not fit in with the rest of the syntax
of \CEE/,
we have to deal with them separately. One solution is to enclose such
@@ -731,25 +719,25 @@ for |ord|, since |get_next| changes |ord| into a string.
@d left_preproc ord /* begins a preprocessor command */
@d right_preproc 0217 /* ends a preprocessor command */
-@<Glob...@>=
-boolean preprocessing=0; /* are we scanning a preprocessor command? */
+@<Private...@>=
+static boolean preprocessing=false; /* are we scanning a preprocessor command? */
@ @<Raise prep...@>= {
- preprocessing=1;
- @<Check if next token is |include|@>;
- return (left_preproc);
+ preprocessing=true;
+ @<Check if next token is |include|@>@;
+ return left_preproc;
}
@ An additional complication is the freakish use of \.< and \.> to delimit
a file name in lines that start with \.{\#include}. We must treat this file
name as a string.
-@<Glob...@>=
-boolean sharp_include_line=0; /* are we scanning a |#include| line? */
+@<Private...@>=
+static boolean sharp_include_line=false; /* are we scanning a \&{\#include} line? */
@ @<Check if next token is |include|@>=
while (loc<=buffer_end-7 && xisspace(*loc)) loc++;
-if (loc<=buffer_end-6 && strncmp(loc,"include",7)==0) sharp_include_line=1;
+if (loc<=buffer_end-6 && strncmp(loc,"include",7)==0) sharp_include_line=true;
@ When we get to the end of a preprocessor line,
we lower the flag and send a code |right_preproc|, unless
@@ -757,10 +745,10 @@ the last character was a \.\\.
@<Check if we're at...@>=
while (loc==limit-1 && preprocessing && *loc=='\\')
- if (get_line()==0) return(new_section); /* still in preprocessor mode */
+ if (get_line()==false) return new_section; /* still in preprocessor mode */
if (loc>=limit && preprocessing) {
- preprocessing=sharp_include_line=0;
- return(right_preproc);
+ preprocessing=sharp_include_line=false;
+ return right_preproc;
}
@ The following code assigns values to the combinations \.{++},
@@ -770,7 +758,7 @@ combinations \.{...}, \.{::}, \.{.*} and \.{->*}.
The compound assignment operators (e.g., \.{+=}) are
treated as separate tokens.
-@d compress(c) if (loc++<=limit) return(c)
+@d compress(c) if (loc++<=limit) return c
@<Compress tw...@>=
switch(c) {
@@ -778,8 +766,8 @@ switch(c) {
else if (*loc=='/') compress(begin_short_comment); break;
case '+': if (*loc=='+') compress(plus_plus); break;
case '-': if (*loc=='-') {compress(minus_minus);}
- else if (*loc=='>') if (*(loc+1)=='*') {loc++; compress(minus_gt_ast);}
- else compress(minus_gt); break;
+ else { if (*loc=='>') { if (*(loc+1)=='*') {loc++; compress(minus_gt_ast);}
+ else compress(minus_gt); } } break;
case '.': if (*loc=='*') {compress(period_ast);}
else if (*loc=='.' && *(loc+1)=='.') {
loc++; compress(dot_dot_dot);
@@ -793,13 +781,14 @@ switch(c) {
else if (*loc=='<') compress(lt_lt); break;
case '&': if (*loc=='&') compress(and_and); break;
case '|': if (*loc=='|') compress(or_or); break;
- case '!': if (*loc=='=') compress(not_eq); break;
+ case '!': if (*loc=='=') compress(non_eq); break;
}
@ @<Get an identifier@>= {
id_first=--loc;
- while (isalpha(*++loc) || isdigit(*loc) || isxalpha(*loc) || ishigh(*loc));
- id_loc=loc; return(identifier);
+ while (isalpha((eight_bits)*++loc) || isdigit((eight_bits)*loc) @|
+ || isxalpha((eight_bits)*loc) || ishigh((eight_bits)*loc));
+ id_loc=loc; return identifier;
}
@ Different conventions are followed by \TEX/ and \CEE/ to express octal
@@ -833,9 +822,9 @@ are pointers into the array |section_text|, not into |buffer|.
}
while (*loc=='u' || *loc=='U' || *loc=='l' || *loc=='L'
|| *loc=='f' || *loc=='F') {
- *id_loc++='$'; *id_loc++=toupper(*loc); loc++;
+ *id_loc++='$'; *id_loc++=toupper((eight_bits)*loc); loc++;
}
- return(constant);
+ return constant;
}
@ \CEE/ strings and character constants, delimited by double and single
@@ -849,17 +838,18 @@ convention, but do not allow the string to be longer than |longest_name|.
id_loc = section_text;
if (delim=='\'' && *(loc-2)=='@@') {*++id_loc='@@'; *++id_loc='@@';}
*++id_loc=delim;
- if (delim=='L') { /* wide character constant */
+ if (delim=='L' || delim=='u' || delim=='U') { /* wide character constant */
+ if (delim=='u' && *loc=='8') { *++id_loc=*loc++; }
delim=*loc++; *++id_loc=delim;
}
- if (delim=='<') delim='>'; /* for file names in |#include| lines */
- while (1) {
+ if (delim=='<') delim='>'; /* for file names in \&{\#include} lines */
+ while (true) {
if (loc>=limit) {
if(*(limit-1)!='\\') {
err_print("! String didn't end"); loc=limit; break;
@.String didn't end@>
}
- if(get_line()==0) {
+ if(get_line()==false) {
err_print("! Input ended in middle of string"); loc=buffer; break;
@.Input ended in middle of string@>
}
@@ -868,20 +858,20 @@ convention, but do not allow the string to be longer than |longest_name|.
if (++id_loc<=section_text_end) *id_loc=c;
break;
}
- if (c=='\\') if (loc>=limit) continue;
- else if (++id_loc<=section_text_end) {
+ if (c=='\\') { if (loc>=limit) continue;
+ else { if (++id_loc<=section_text_end) {
*id_loc = '\\'; c=*loc++;
- }
+ } } }
if (++id_loc<=section_text_end) *id_loc=c;
}
if (id_loc>=section_text_end) {
- printf("\n! String too long: ");
+ fputs("\n! String too long: ",stdout);
@.String too long@>
term_write(section_text+1,25);
printf("..."); mark_error;
}
id_loc++;
- return(string);
+ return string;
}
@ After an \.{@@} sign has been scanned, the next character tells us
@@ -894,13 +884,13 @@ whether there is more work to do.
@.Use @@l in limbo...@>
case underline: xref_switch=def_flag; continue;
case trace: tracing=c-'0'; continue;
- case xref_roman: case xref_wildcard: case xref_typewriter:
- case noop: case TeX_string: c=ccode[c]; skip_restricted(); return(c);
+ case xref_roman: case xref_wildcard: case xref_typewriter: case noop:
+ case TeX_string: c=ccode[(eight_bits)c]; skip_restricted(); return c;
case section_name:
- @<Scan the section name and make |cur_section| point to it@>;
- case verbatim: @<Scan a verbatim string@>;
- case ord: @<Get a string@>;
- default: return(ccode[(eight_bits)c]);
+ @<Scan the section name and make |cur_section| point to it@>@;
+ case verbatim: @<Scan a verbatim string@>@;
+ case ord: @<Get a string@>@;
+ default: return ccode[(eight_bits)c];
}
}
@@ -910,11 +900,11 @@ because the section name might (for example) follow \&{int}.
@<Scan the section name...@>= {
char *k; /* pointer into |section_text| */
cur_section_char=*(loc-1);
- @<Put section name into |section_text|@>;
+ @<Put section name into |section_text|@>@;
if (k-section_text>3 && strncmp(k-2,"...",3)==0)
cur_section=section_lookup(section_text+1,k-3,1); /* 1 indicates a prefix */
else cur_section=section_lookup(section_text+1,k,0);
- xref_switch=0; return(section_name);
+ xref_switch=0; return section_name;
}
@ Section names are placed into the |section_text| array with consecutive spaces,
@@ -927,14 +917,14 @@ character of the name.)
@ @<Put section name...@>=
k=section_text;
-while (1) {
- if (loc>limit && get_line()==0) {
+while (true) {
+ if (loc>limit && get_line()==false) {
err_print("! Input ended in section name");
@.Input ended in section name@>
loc=buffer+1; break;
}
c=*loc;
- @<If end of name or erroneous control code, |break|@>;
+ @<If end of name or erroneous control code, |break|@>@;
loc++; if (k<section_text_end) k++;
if (xisspace(c)) {
c=' '; if (*(k-1)==' ') k--;
@@ -942,7 +932,7 @@ while (1) {
*k=c;
}
if (k>=section_text_end) {
- printf("\n! Section name too long: ");
+ fputs("\n! Section name too long: ",stdout);
@.Section name too long@>
term_write(section_text+1,25);
printf("..."); mark_harmless;
@@ -968,12 +958,9 @@ if (c=='@@') {
@ This function skips over a restricted context at relatively high speed.
-@<Predecl...@>=
-void skip_restricted();
-
-@ @c
-void
-skip_restricted()
+@c
+static void
+skip_restricted(void)
{
id_first=loc; *(limit+1)='@@';
false_alarm:
@@ -991,6 +978,8 @@ false_alarm:
}
}
+@ @<Predecl...@>=@+static void skip_restricted(void);
+
@ At the present point in the program we
have |*(loc-1)==verbatim|; we set |id_first| to the beginning
of the string itself, and |id_loc| to its ending-plus-one location in the
@@ -1002,7 +991,7 @@ buffer. We also set |loc| to the position just after the ending delimiter.
if (loc>=limit) err_print("! Verbatim string didn't end");
@.Verbatim string didn't end@>
id_loc=loc; loc+=2;
- return (verbatim);
+ return verbatim;
}
@** Phase one processing.
@@ -1015,41 +1004,40 @@ The global variable |next_control| often contains the most recent output of
|get_next|; in interesting cases, this will be the control code that
ended a section or part of a section.
-@<Global...@>=
-eight_bits next_control; /* control code waiting to be acting upon */
+@<Private...@>=
+static eight_bits next_control; /* control code waiting to be acting upon */
@ The overall processing strategy in phase one has the following
straightforward outline.
-@<Predecl...@>=
-void phase_one();
-
-@ @c
-void
-phase_one() {
+@c
+static void
+phase_one(void) {
phase=1; reset_input(); section_count=0;
- skip_limbo(); change_exists=0;
+ skip_limbo(); change_exists=false;
while (!input_has_ended)
- @<Store cross-reference data for the current section@>;
+ @<Store cross-reference data for the current section@>@;
changed_section[section_count]=change_exists;
/* the index changes if anything does */
phase=2; /* prepare for second phase */
- @<Print error messages about unused or undefined section names@>;
+ @<Print error messages about unused or undefined section names@>@;
}
+@ @<Predecl...@>=@+static void phase_one(void);
+
@ @<Store cross-reference data...@>=
{
if (++section_count==max_sections) overflow("section number");
changed_section[section_count]=changing;
- /* it will become 1 if any line changes */
+ /* it will become |true| if any line changes */
if (*(loc-1)=='*' && show_progress) {
printf("*%d",section_count);
update_terminal; /* print a progress report */
}
- @<Store cross-references in the \TEX/ part of a section@>;
- @<Store cross-references in the definition part of a section@>;
- @<Store cross-references in the \CEE/ part of a section@>;
- if (changed_section[section_count]) change_exists=1;
+ @<Store cross-references in the \TEX/ part of a section@>@;
+ @<Store cross-references in the definition part of a section@>@;
+ @<Store cross-references in the \CEE/ part of a section@>@;
+ if (changed_section[section_count]) change_exists=true;
}
@ The |C_xref| subroutine stores references to identifiers in
@@ -1074,12 +1062,13 @@ the relations |xref_roman==identifier+roman| and |xref_wildcard==identifier
as well as |normal==0|.
@<Predecl...@>=
-void C_xref();
+static void C_xref(eight_bits);@/
+static void outer_xref(void);
@ @c
-void
-C_xref( spec_ctrl ) /* makes cross-references for \CEE/ identifiers */
- eight_bits spec_ctrl;
+static void
+C_xref(@t\1\1@> /* makes cross-references for \CEE/ identifiers */
+ eight_bits spec_ctrl@t\2\2@>)
{
name_pointer p; /* a referenced name */
while (next_control<format_code || next_control==spec_ctrl) {
@@ -1101,12 +1090,9 @@ C_xref( spec_ctrl ) /* makes cross-references for \CEE/ identifiers */
with |next_control!='|'| and ends with |next_control>=format_code|. Thus, it
handles \CEE/ text with embedded comments.
-@<Predecl...@>=
-void outer_xref();
-
-@ @c
-void
-outer_xref() /* extension of |C_xref| */
+@c
+static void
+outer_xref(void) /* extension of |C_xref| */
{
int bal; /* brace level in comment */
while (next_control<format_code)
@@ -1129,7 +1115,7 @@ enclosed in \.{@@\^}$\,\ldots\,$\.{@@>} or \.{@@.}$\,\ldots\,$\.{@@>}
or \.{@@:}$\,\ldots\,$\.{@@>}.
@<Store cross-references in the \T...@>=
-while (1) {
+while (true) {
switch (next_control=skip_TeX()) {
case translit_code: err_print("! Use @@l in limbo only"); continue;
@.Use @@l in limbo...@>
@@ -1171,9 +1157,9 @@ entirely, even if it contains \pb\ constructions.
The variables |lhs| and |rhs| point to the respective identifiers involved
in a format definition.
-@<Global...@>=
-name_pointer lhs, rhs; /* pointers to |byte_start| for format identifiers */
-name_pointer res_wd_end; /* pointer to the first nonreserved identifier */
+@<Private...@>=
+static name_pointer lhs, rhs; /* pointers to |byte_start| for format identifiers */
+static name_pointer res_wd_end; /* pointer to the first nonreserved identifier */
@ When we get to the following code we have |next_control>=format_code|.
@@ -1182,7 +1168,7 @@ while (next_control<=definition) { /* |format_code| or |definition| */
if (next_control==definition) {
xref_switch=def_flag; /* implied \.{@@!} */
next_control=get_next();
- } else @<Process a format definition@>;
+ } else @<Process a format definition@>@;
outer_xref();
}
@@ -1205,7 +1191,7 @@ discover should be unindexed.
for (q=(xref_pointer)lhs->xref;q>xmem;q=q->xlink)
if (q->num<def_flag)
if (r) r->xlink=q->xlink;
- else lhs->xref=(char*)q->xlink;
+ else lhs->xref=(void *)q->xlink;
else r=q;
}
next_control=get_next();
@@ -1255,41 +1241,42 @@ if (next_control<=section_name) { /* |begin_C| or |section_name| */
section name was both defined and used. The variable |cur_xref| will point
to cross-references for the current section name of interest.
-@<Global...@>=
-xref_pointer cur_xref; /* temporary cross-reference pointer */
-boolean an_output; /* did |file_flag| precede |cur_xref|? */
+@<Private...@>=
+static xref_pointer cur_xref; /* temporary cross-reference pointer */
+static boolean an_output; /* did |file_flag| precede |cur_xref|? */
@ The following recursive procedure
walks through the tree of section names and prints out anomalies.
@^recursion@>
-@<Predecl...@>=
-void section_check();
-
-@ @c
-void
-section_check(p)
-name_pointer p; /* print anomalies in subtree |p| */
+@c
+static void
+section_check(
+name_pointer p) /* print anomalies in subtree |p| */
{
if (p) {
section_check(p->llink);
cur_xref=(xref_pointer)p->xref;
- if (cur_xref->num==file_flag) {an_output=1; cur_xref=cur_xref->xlink;}
- else an_output=0;
+ if (cur_xref->num==file_flag) {an_output=true; cur_xref=cur_xref->xlink;}
+ else an_output=false;
if (cur_xref->num <def_flag) {
- printf("\n! Never defined: <"); print_section_name(p); putchar('>'); mark_harmless;
+ fputs("\n! Never defined: <",stdout);
+ print_section_name(p); putchar('>'); mark_harmless;
@.Never defined: <section name>@>
}
while (cur_xref->num >=cite_flag) cur_xref=cur_xref->xlink;
if (cur_xref==xmem && !an_output) {
- printf("\n! Never used: <"); print_section_name(p); putchar('>'); mark_harmless;
+ fputs("\n! Never used: <",stdout);
+ print_section_name(p); putchar('>'); mark_harmless;
@.Never used: <section name>@>
}
section_check(p->rlink);
}
}
-@ @<Print error messages about un...@>=section_check(root)
+@ @<Predecl...@>=@+static void section_check(name_pointer);
+
+@ @<Print error messages about un...@>=section_check(root);
@* Low-level output routines.
The \TEX/ output is supposed to appear in lines at most |line_length|
@@ -1297,17 +1284,17 @@ characters long, so we place it into an output buffer. During the output
process, |out_line| will hold the current line number of the line about to
be output.
-@<Global...@>=
-char out_buf[line_length+1]; /* assembled characters */
-char *out_ptr; /* last character in |out_buf| */
-char *out_buf_end = out_buf+line_length; /* end of |out_buf| */
-int out_line; /* number of next line to be output */
+@<Private...@>=
+static char out_buf[line_length+1]; /* assembled characters */
+static char *out_buf_end = out_buf+line_length; /* end of |out_buf| */
+static char *out_ptr; /* last character in |out_buf| */
+static int out_line; /* number of next line to be output */
@ The |flush_buffer| routine empties the buffer up to a given breakpoint,
and moves any remaining characters to the beginning of the next line.
-If the |per_cent| parameter is 1 a |'%'| is appended to the line
+If the |per_cent| parameter is |true|, a |'%'| is appended to the line
that is being output; in this case the breakpoint |b| should be strictly
-less than |out_buf_end|. If the |per_cent| parameter is |0|,
+less than |out_buf_end|. If the |per_cent| parameter is |false|,
trailing blanks are suppressed.
The characters emptied from the buffer form a new line of output;
if the |carryover| parameter is true, a |"%"| in that line will be
@@ -1317,13 +1304,18 @@ of commented-out text).
@d c_line_write(c) fflush(active_file),fwrite(out_buf+1,sizeof(char),c,active_file)
@d tex_putc(c) putc(c,active_file)
@d tex_new_line putc('\n',active_file)
-@d tex_printf(c) fprintf(active_file,c)
+@d tex_printf(c) fprintf(active_file,"%s",c)
+@d tex_puts(c) fputs(c,active_file)
-@c
-void
-flush_buffer(b,per_cent,carryover)
-char *b; /* outputs from |out_buf+1| to |b|,where |b<=out_ptr| */
-boolean per_cent,carryover;
+@<Predecl...@>=
+static void flush_buffer(char *,boolean,boolean);@/
+static void finish_line(void);
+
+@ @c
+static void
+flush_buffer(@t\1\1@>
+char *b, /* outputs from |out_buf+1| to |b|, where |b<=out_ptr| */
+boolean per_cent,boolean carryover@t\2\2@>)
{
char *j; j=b; /* pointer into |out_buf| */
if (! per_cent) /* remove trailing blanks */
@@ -1336,7 +1328,7 @@ boolean per_cent,carryover;
if (*j--=='%' && (j==out_buf || *j!='\\')) {
*b--='%'; break;
}
- if (b<out_ptr) strncpy(out_buf+1,b+1,out_ptr-b);
+ if (b<out_ptr) memcpy(out_buf+1,b+1,(size_t)(out_ptr-b));
out_ptr-=b-out_buf;
}
@@ -1349,15 +1341,15 @@ will not be copied. The |finish_line| routine is called just before
been emitted during the output of translated \CEE/ text.
@c
-void
-finish_line() /* do this at the end of a line */
+static void
+finish_line(void) /* do this at the end of a line */
{
char *k; /* pointer into |buffer| */
- if (out_ptr>out_buf) flush_buffer(out_ptr,0,0);
+ if (out_ptr>out_buf) flush_buffer(out_ptr,false,false);
else {
for (k=buffer; k<=limit; k++)
if (!(xisspace(*k))) return;
- flush_buffer(out_buf,0,0);
+ flush_buffer(out_buf,false,false);
}
}
@@ -1366,7 +1358,7 @@ beginning of phase two. We initialize the output variables in a slightly
tricky way so that the first line of the output file will be
`\.{\\input cwebmac}'.
-@<Set init...@>=
+@<Start \TEX/...@>=
out_ptr=out_buf+1; out_line=1; active_file=tex_file;
*out_ptr='c'; tex_printf("\\input cwebma");
@@ -1380,10 +1372,14 @@ A line break will occur at a space or after a single-nonletter
@d out(c) {if (out_ptr>=out_buf_end) break_out(); *(++out_ptr)=c;}
-@c
-void
-out_str(s) /* output characters from |s| to end of string */
-char *s;
+@<Predecl...@>=
+static void out_str(const char *);@/
+static void break_out(void);
+
+@ @c
+static void
+out_str(@t\1\1@> /* output characters from |s| to end of string */
+const char*s@t\2\2@>)
{
while (*s) out(*s++);
}
@@ -1399,21 +1395,18 @@ out_buf[0]='\\';
preceded by another backslash. In the latter case, a |'%'| is output at
the break.
-@<Predecl...@>=
-void break_out();
-
-@ @c
-void
-break_out() /* finds a way to break the output line */
+@c
+static void
+break_out(void) /* finds a way to break the output line */
{
char *k=out_ptr; /* pointer into |out_buf| */
- while (1) {
- if (k==out_buf) @<Print warning message, break the line, |return|@>;
+ while (true) {
+ if (k==out_buf) @<Print warning message, break the line, |return|@>@;
if (*k==' ') {
- flush_buffer(k,0,1); return;
+ flush_buffer(k,false,true); return;
}
if (*(k--)=='\\' && *k!='\\') { /* we've decreased |k| */
- flush_buffer(k,1,1); return;
+ flush_buffer(k,true,true); return;
}
}
}
@@ -1429,7 +1422,7 @@ line by putting a |'%'| just before the last character.
@.Line had to be broken@>
term_write(out_buf+1, out_ptr-out_buf-1);
new_line; mark_harmless;
- flush_buffer(out_ptr-1,1,1); return;
+ flush_buffer(out_ptr-1,true,true); return;
}
@ Here is a macro that outputs a section number in decimal notation.
@@ -1437,10 +1430,14 @@ The number to be converted by |out_section| is known to be less than
|def_flag|, so it cannot have more than five decimal digits. If
the section is changed, we output `\.{\\*}' just after the number.
-@c
-void
-out_section(n)
-sixteen_bits n;
+@<Predecl...@>=
+static void out_section(sixteen_bits);@/
+static void out_name(name_pointer,boolean);
+
+@ @c
+static void
+out_section(
+sixteen_bits n)
{
char s[6];
sprintf(s,"%d",n); out_str(s);
@@ -1452,10 +1449,10 @@ sixteen_bits n;
entry, enclosing it in braces.
@c
-void
-out_name(p,quote_xalpha)
-name_pointer p;
-boolean quote_xalpha;
+static void
+out_name(
+name_pointer p,
+boolean quote_xalpha)
{
char *k, *k_end=(p+1)->byte_start; /* pointers into |byte_mem| */
out('{');
@@ -1469,11 +1466,9 @@ boolean quote_xalpha;
}
@* Routines that copy \TEX/ material.
-During phase two, we use subroutines |copy_limbo|, |copy_TeX|, and
-|copy_comment| in place of the analogous |skip_limbo|, |skip_TeX|, and
-|skip_comment| that were used in phase one. (Well, |copy_comment|
-was actually written in such a way that it functions as |skip_comment|
-in phase one.)
+During phase two, we use the subroutines |copy_limbo| and |copy_TeX| (and
+|copy_comment|) in place of the analogous |skip_limbo| and |skip_TeX|
+that were used in phase one.
The |copy_limbo| routine, for example, takes \TEX/ material that is not
part of any section and transcribes it almost verbatim to the output file.
@@ -1481,13 +1476,18 @@ The use of `\.{@@}' signs is severely restricted in such material:
`\.{@@@@}' pairs are replaced by singletons; `\.{@@l}' and `\.{@@q}' and
`\.{@@s}' are interpreted.
-@c
-void
-copy_limbo()
+@<Predecl...@>=
+static void copy_limbo(void);@/
+static eight_bits copy_TeX(void);@/
+static int copy_comment(boolean,int);
+
+@ @c
+static void
+copy_limbo(void)
{
char c;
- while (1) {
- if (loc>limit && (finish_line(), get_line()==0)) return;
+ while (true) {
+ if (loc>limit && (finish_line(), get_line()==false)) return;
*(limit+1)='@@';
while (*loc!='@@') out(*(loc++));
if (loc++<=limit) {
@@ -1515,21 +1515,21 @@ way. It returns the next control code or `\.{\v}' found in the input.
We don't copy spaces or tab marks into the beginning of a line. This
makes the test for empty lines in |finish_line| work.
-@ @f copy_TeX TeX
+@f copy_TeX TeX
@c
-eight_bits
-copy_TeX()
+static eight_bits
+copy_TeX(void)
{
char c; /* current character being copied */
- while (1) {
- if (loc>limit && (finish_line(), get_line()==0)) return(new_section);
+ while (true) {
+ if (loc>limit && (finish_line(), get_line()==false)) return new_section;
*(limit+1)='@@';
while ((c=*(loc++))!='|' && c!='@@') {
out(c);
if (out_ptr==out_buf+1 && (xisspace(c))) out_ptr--;
}
- if (c=='|') return('|');
- if (loc<=limit) return(ccode[(eight_bits)*(loc++)]);
+ if (c=='|') return '|';
+ if (loc<=limit) return ccode[(eight_bits)*(loc++)];
}
}
@@ -1545,19 +1545,16 @@ one further token without overflow.
@d app_tok(c) {if (tok_ptr+2>tok_mem_end) overflow("token"); *(tok_ptr++)=c;}
-@<Predec...@>=
-int copy_comment();
-
-@ @c
-int copy_comment(is_long_comment,bal) /* copies \TEX/ code in comments */
-boolean is_long_comment; /* is this a traditional \CEE/ comment? */
-int bal; /* brace balance */
+@c
+static int copy_comment(@t\1\1@> /* copies \TeX\ code in comments */
+boolean is_long_comment, /* is this a traditional \CEE/ comment? */
+int bal@t\2\2@>) /* brace balance */
{
char c; /* current character being copied */
- while (1) {
+ while (true) {
if (loc>limit) {
if (is_long_comment) {
- if (get_line()==0) {
+ if (get_line()==false) {
err_print("! Input ended in mid-comment");
@.Input ended in mid-comment@>
loc=buffer+1; goto done;
@@ -1570,13 +1567,13 @@ int bal; /* brace balance */
}
}
c=*(loc++);
- if (c=='|') return(bal);
- if (is_long_comment) @<Check for end of comment@>;
+ if (c=='|') return bal;
+ if (is_long_comment) @<Check for end of comment@>@;
if (phase==2) {
if (ishigh(c)) app_tok(quoted_char);
app_tok(c);
}
- @<Copy special things when |c=='@@', '\\'|@>;
+ @<Copy special things when |c=='@@', '\\'|@>@;
if (c=='{') bal++;
else if (c=='}') {
if(bal>1) bal--;
@@ -1586,7 +1583,7 @@ int bal; /* brace balance */
}
}
}
-done:@<Clear |bal| and |return|@>;
+done:@<Clear |bal| and |return|@>@;
}
@ @<Check for end of comment@>=
@@ -1605,15 +1602,15 @@ if (c=='@@') {
loc-=2; if (phase==2) *(tok_ptr-1)=' '; goto done;
}
}
-else if (c=='\\' && *loc!='@@')
- if (phase==2) app_tok(*(loc++))@; else loc++;
+else { if (c=='\\' && *loc!='@@') {
+ if (phase==2) app_tok(*(loc++))@; else loc++; } }
@ We output
enough right braces to keep \TEX/ happy.
@<Clear |bal|...@>=
if (phase==2) while (bal-- >0) app_tok('}');
-return(0);
+return 0;
@** Parsing.
The most intricate part of \.{CWEAVE} is its mechanism for converting
@@ -1660,9 +1657,12 @@ In the \TEX/ file, this will specify an optional line break after the
comma, with penalty 90.
At each opportunity the longest possible production is applied. For
-example, if the current sequence of scraps is |int_like| |cast|
-|lbrace|, rule 31 is applied; but if the sequence is |int_like| |cast|
-followed by anything other than |lbrace|, rule 32 takes effect.
+example, if the current sequence of scraps is |if_clause| |stmt|
+|else_like| |if_like|, rule 63 is applied; but if the sequence is
+|if_clause| |stmt| |else_like| followed by anything other than
+|if_like|, rule 64 takes effect; and if the sequence is |if_clause|
+|stmt| followed by anything other than |else_like|, rule 65 takes
+effect.
Translation rules such as `$E_1C\,\\{opt}9\,E_2$' above use subscripts
to distinguish between translations of scraps whose categories have the
@@ -1711,13 +1711,11 @@ same initial letter; these subscripts are assigned from left to right.
@d begin_arg 61 /* \.{@@[} */
@d end_arg 62 /* \.{@@]} */
-@<Glo...@>=
-char cat_name[256][12];
-eight_bits cat_index;
+@<Private...@>=
+static char cat_name[256][12];
@ @<Set in...@>=
- for (cat_index=0;cat_index<255;cat_index++)
- strcpy(cat_name[cat_index],"UNKNOWN");
+{int c; for (c=0;c<256;c++) strcpy(cat_name[c],"UNKNOWN");}
@.UNKNOWN@>
strcpy(cat_name[exp],"exp");
strcpy(cat_name[unop],"unop");
@@ -1781,13 +1779,15 @@ eight_bits cat_index;
@ This code allows \.{CWEAVE} to display its parsing steps.
@c
-void
-print_cat(c) /* symbolic printout of a category */
-eight_bits c;
+static void
+print_cat(@t\1\1@> /* symbolic printout of a category */
+eight_bits c@t\2\2@>)
{
- printf(cat_name[c]);
+ fputs(cat_name[c],stdout);
}
+@ @<Predecl...@>=@+static void print_cat(eight_bits);
+
@ The token lists for translated \TEX/ output contain some special control
symbols as well as ordinary characters. These control symbols are
interpreted by \.{CWEAVE} before they are written to the output file.
@@ -2098,15 +2098,15 @@ typedef scrap *scrap_pointer;
@ @d trans trans_plus.Trans /* translation texts of scraps */
-@<Global...@>=
-scrap scrap_info[max_scraps]; /* memory array for scraps */
-scrap_pointer scrap_info_end=scrap_info+max_scraps -1; /* end of |scrap_info| */
-scrap_pointer pp; /* current position for reducing productions */
-scrap_pointer scrap_base; /* beginning of the current scrap sequence */
-scrap_pointer scrap_ptr; /* ending of the current scrap sequence */
-scrap_pointer lo_ptr; /* last scrap that has been examined */
-scrap_pointer hi_ptr; /* first scrap that has not been examined */
-scrap_pointer max_scr_ptr; /* largest value assumed by |scrap_ptr| */
+@<Private...@>=
+static scrap scrap_info[max_scraps]; /* memory array for scraps */
+static scrap_pointer scrap_info_end=scrap_info+max_scraps-1; /* end of |scrap_info| */
+static scrap_pointer scrap_base; /* beginning of the current scrap sequence */
+static scrap_pointer scrap_ptr; /* ending of the current scrap sequence */
+static scrap_pointer max_scr_ptr; /* largest value assumed by |scrap_ptr| */
+static scrap_pointer pp; /* current position for reducing productions */
+static scrap_pointer lo_ptr; /* last scrap that has been examined */
+static scrap_pointer hi_ptr; /* first scrap that has not been examined */
@ @<Set init...@>=
scrap_base=scrap_info+1;
@@ -2136,9 +2136,9 @@ translated without line-break controls.
@d inner_tok_flag 5*id_flag /* signifies a token list in `\pb' */
@c
-void
-print_text(p) /* prints a token list for debugging; not used in |main| */
-text_pointer p;
+static void
+print_text(@t\1\1@> /* prints a token list for debugging; not used in |main| */
+text_pointer p@t\2\2@>)
{
token_pointer j; /* index into |tok_mem| */
sixteen_bits r; /* remainder of token after the flag has been stripped off */
@@ -2154,12 +2154,14 @@ text_pointer p;
break; /* |section_flag| */
case 4: printf("[[%d]]",r); break; /* |tok_flag| */
case 5: printf("|[[%d]]|",r); break; /* |inner_tok_flag| */
- default: @<Print token |r| in symbolic form@>;
+ default: @<Print token |r| in symbolic form@>@;
}
}
- fflush(stdout);
+ update_terminal;
}
+@ @<Predecl...@>=@+static void print_text(text_pointer p);
+
@ @<Print token |r|...@>=
switch (r) {
case math_rel: printf("\\mathrel{"@q}@>); break;
@@ -2173,7 +2175,7 @@ switch (r) {
case force: printf("[force]"); break;
case big_force: printf("[fforce]"); break;
case preproc_line: printf("[preproc]"); break;
- case quoted_char: j++; printf("[%o]",(unsigned)*j); break;
+ case quoted_char: j++; printf("[%o]",(unsigned int)*j); break;
case end_translation: printf("[quit]"); break;
case inserted: printf("[inserted]"); break;
default: putxchar(r);
@@ -2219,7 +2221,7 @@ example, `|squash(pp,3,exp,-2,3)|' is an abbreviation for `\\{app3}|(pp);
reduce(pp,3,exp,-2,3)|'.
A couple more words of explanation:
-Both |big_app| and |app| append a token (while |big_app1| to |big_app4|
+Both |big_app| and |app| append a token (while |big_app1| to |big_app3|
append the specified number of scrap translations) to the current token list.
The difference between |big_app| and |app| is simply that |big_app|
checks whether there can be a conflict between math and non-math
@@ -2253,24 +2255,28 @@ productions as they were listed earlier.
@d maybe_math 0 /* works in either horizontal or math mode */
@d big_app2(a) big_app1(a);big_app1(a+1)
@d big_app3(a) big_app2(a);big_app1(a+2)
-@d big_app4(a) big_app3(a);big_app1(a+3)
-@d app(a) *(tok_ptr++)=a
-@d app1(a) *(tok_ptr++)=tok_flag+(int)((a)->trans-tok_start)
+@d app(a) *(tok_ptr++)=(token)(a)
+@d app1(a) *(tok_ptr++)=(token)(tok_flag+(int)((a)->trans-tok_start))
+
+@<Private...@>=
+static int cur_mathness, init_mathness;
-@<Global...@>=
-int cur_mathness, init_mathness;
+@ @<Predecl...@>=
+static void app_str(const char *);@/
+static void big_app(token);@/
+static void big_app1(scrap_pointer);
@ @c
-void
-app_str(s)
-char *s;
+static void
+app_str(
+const char *s)
{
while (*s) app_tok(*(s++));
}
-void
-big_app(a)
-token a;
+static void
+big_app(
+token a)
{
if (a==' ' || (a>=big_cancel && a<=big_force)) /* non-math token */ {
if (cur_mathness==maybe_math) init_mathness=no_math;
@@ -2285,9 +2291,9 @@ token a;
app(a);
}
-void
-big_app1(a)
-scrap_pointer a;
+static void
+big_app1(
+scrap_pointer a)
{
switch (a->mathness % 4) { /* left boundary */
case (no_math):
@@ -2316,11 +2322,11 @@ code needs to be provided with a proper environment.
@d lhs_not_simple (pp->cat!=public_like
&& pp->cat!=semi
&& pp->cat!=prelangle
- && pp->cat!=prerangle
+ && pp->cat!=prerangle @|
&& pp->cat!=template_like
&& pp->cat!=new_like
&& pp->cat!=new_exp
- && pp->cat!=ftemplate
+ && pp->cat!=ftemplate @|
&& pp->cat!=raw_ubin
&& pp->cat!=const_like
&& pp->cat!=raw_int
@@ -2336,53 +2342,53 @@ code needs to be provided with a proper environment.
else if (cat3==insert) squash(pp+2,2,(pp+2)->cat,0,0);
else
switch (pp->cat) {
- case exp: @<Cases for |exp|@>; @+break;
- case lpar: @<Cases for |lpar|@>; @+break;
- case unop: @<Cases for |unop|@>; @+break;
- case ubinop: @<Cases for |ubinop|@>; @+break;
- case binop: @<Cases for |binop|@>; @+break;
- case cast: @<Cases for |cast|@>; @+break;
- case sizeof_like: @<Cases for |sizeof_like|@>; @+break;
- case int_like: @<Cases for |int_like|@>; @+break;
- case public_like: @<Cases for |public_like|@>; @+break;
- case colcol: @<Cases for |colcol|@>; @+break;
- case decl_head: @<Cases for |decl_head|@>; @+break;
- case decl: @<Cases for |decl|@>; @+break;
- case base: @<Cases for |base|@>; @+break;
- case struct_like: @<Cases for |struct_like|@>; @+break;
- case struct_head: @<Cases for |struct_head|@>; @+break;
- case fn_decl: @<Cases for |fn_decl|@>; @+break;
- case function: @<Cases for |function|@>; @+break;
- case lbrace: @<Cases for |lbrace|@>; @+break;
- case if_like: @<Cases for |if_like|@>; @+break;
- case else_like: @<Cases for |else_like|@>; @+break;
- case else_head: @<Cases for |else_head|@>; @+break;
- case if_clause: @<Cases for |if_clause|@>; @+break;
- case if_head: @<Cases for |if_head|@>; @+break;
- case do_like: @<Cases for |do_like|@>; @+break;
- case case_like: @<Cases for |case_like|@>; @+break;
- case catch_like: @<Cases for |catch_like|@>; @+break;
- case tag: @<Cases for |tag|@>; @+break;
- case stmt: @<Cases for |stmt|@>; @+break;
- case semi: @<Cases for |semi|@>; @+break;
- case lproc: @<Cases for |lproc|@>; @+break;
- case section_scrap: @<Cases for |section_scrap|@>; @+break;
- case insert: @<Cases for |insert|@>; @+break;
- case prelangle: @<Cases for |prelangle|@>; @+break;
- case prerangle: @<Cases for |prerangle|@>; @+break;
- case langle: @<Cases for |langle|@>; @+break;
- case template_like: @<Cases for |template_like|@>; @+break;
- case new_like: @<Cases for |new_like|@>; @+break;
- case new_exp: @<Cases for |new_exp|@>; @+break;
- case ftemplate: @<Cases for |ftemplate|@>; @+break;
- case for_like: @<Cases for |for_like|@>; @+break;
- case raw_ubin: @<Cases for |raw_ubin|@>; @+break;
- case const_like: @<Cases for |const_like|@>; @+break;
- case raw_int: @<Cases for |raw_int|@>; @+break;
- case operator_like: @<Cases for |operator_like|@>; @+break;
- case typedef_like: @<Cases for |typedef_like|@>; @+break;
- case delete_like: @<Cases for |delete_like|@>; @+break;
- case question: @<Cases for |question|@>; @+break;
+ case exp: @<Cases for |exp|@>@; @+break;
+ case lpar: @<Cases for |lpar|@>@; @+break;
+ case unop: @<Cases for |unop|@>@; @+break;
+ case ubinop: @<Cases for |ubinop|@>@; @+break;
+ case binop: @<Cases for |binop|@>@; @+break;
+ case cast: @<Cases for |cast|@>@; @+break;
+ case sizeof_like: @<Cases for |sizeof_like|@>@; @+break;
+ case int_like: @<Cases for |int_like|@>@; @+break;
+ case public_like: @<Cases for |public_like|@>@; @+break;
+ case colcol: @<Cases for |colcol|@>@; @+break;
+ case decl_head: @<Cases for |decl_head|@>@; @+break;
+ case decl: @<Cases for |decl|@>@; @+break;
+ case base: @<Cases for |base|@>@; @+break;
+ case struct_like: @<Cases for |struct_like|@>@; @+break;
+ case struct_head: @<Cases for |struct_head|@>@; @+break;
+ case fn_decl: @<Cases for |fn_decl|@>@; @+break;
+ case function: @<Cases for |function|@>@; @+break;
+ case lbrace: @<Cases for |lbrace|@>@; @+break;
+ case if_like: @<Cases for |if_like|@>@; @+break;
+ case else_like: @<Cases for |else_like|@>@; @+break;
+ case else_head: @<Cases for |else_head|@>@; @+break;
+ case if_clause: @<Cases for |if_clause|@>@; @+break;
+ case if_head: @<Cases for |if_head|@>@; @+break;
+ case do_like: @<Cases for |do_like|@>@; @+break;
+ case case_like: @<Cases for |case_like|@>@; @+break;
+ case catch_like: @<Cases for |catch_like|@>@; @+break;
+ case tag: @<Cases for |tag|@>@; @+break;
+ case stmt: @<Cases for |stmt|@>@; @+break;
+ case semi: @<Cases for |semi|@>@; @+break;
+ case lproc: @<Cases for |lproc|@>@; @+break;
+ case section_scrap: @<Cases for |section_scrap|@>@; @+break;
+ case insert: @<Cases for |insert|@>@; @+break;
+ case prelangle: @<Cases for |prelangle|@>@; @+break;
+ case prerangle: @<Cases for |prerangle|@>@; @+break;
+ case langle: @<Cases for |langle|@>@; @+break;
+ case template_like: @<Cases for |template_like|@>@; @+break;
+ case new_like: @<Cases for |new_like|@>@; @+break;
+ case new_exp: @<Cases for |new_exp|@>@; @+break;
+ case ftemplate: @<Cases for |ftemplate|@>@; @+break;
+ case for_like: @<Cases for |for_like|@>@; @+break;
+ case raw_ubin: @<Cases for |raw_ubin|@>@; @+break;
+ case const_like: @<Cases for |const_like|@>@; @+break;
+ case raw_int: @<Cases for |raw_int|@>@; @+break;
+ case operator_like: @<Cases for |operator_like|@>@; @+break;
+ case typedef_like: @<Cases for |typedef_like|@>@; @+break;
+ case delete_like: @<Cases for |delete_like|@>@; @+break;
+ case question: @<Cases for |question|@>@; @+break;
}
pp++; /* if no match was found, we move to the right */
}
@@ -2404,17 +2410,23 @@ of identifiers in case labels.
If the first identifier is the keyword `\&{operator}', we give up;
users who want to index definitions of overloaded \CPLUSPLUS/ operators
should say, for example, `\.{@@!@@\^\\\&\{operator\} \$+\{=\}\$@@>}' (or,
-more properly alphebetized,
+more properly alpha\-betized,
`\.{@@!@@:operator+=\}\{\\\&\{operator\} \$+\{=\}\$@@>}').
@d no_ident_found (token_pointer)0 /* distinct from any identifier token */
@d case_found (token_pointer)1 /* likewise */
@d operator_found (token_pointer)2 /* likewise */
-@c
-token_pointer
-find_first_ident(p)
-text_pointer p;
+@<Predecl...@>=
+static token_pointer find_first_ident(text_pointer);@/
+static void make_reserved(scrap_pointer);@/
+static void make_underlined(scrap_pointer);@/
+static void underline_xref(name_pointer);
+
+@ @c
+static token_pointer
+find_first_ident(
+text_pointer p)
{
token_pointer q; /* token to be returned */
token_pointer j; /* token being looked at */
@@ -2444,11 +2456,11 @@ occurrence of the identifier that we're making reserved; hence
the |for| loop below.
@c
-void
-make_reserved(p) /* make the first identifier in |p->trans| like |int| */
-scrap_pointer p;
+static void
+make_reserved(@t\1\1@> /* make the first identifier in |p->trans| like |int| */
+scrap_pointer p@t\2\2@>)
{
- sixteen_bits tok_value; /* the name of this identifier, plus its flag*/
+ sixteen_bits tok_value; /* the name of this identifier, plus its flag */
token_pointer tok_loc; /* pointer to |tok_value| */
if ((tok_loc=find_first_ident(p->trans))<=operator_found)
return; /* this should not happen */
@@ -2475,10 +2487,10 @@ of a function, we find out that the identifier is being defined only after
it has been swallowed up by an |exp|.
@c
-void
-make_underlined(p)
+static void
+make_underlined(@t\1\1@>
/* underline the entry for the first identifier in |p->trans| */
-scrap_pointer p;
+scrap_pointer p@t\2\2@>)
{
token_pointer tok_loc; /* where the first identifier appears */
if ((tok_loc=find_first_ident(p->trans))<=operator_found)
@@ -2492,13 +2504,10 @@ because this would just make a new cross-reference at the end of the list.
We actually have to search through the list for the existing
cross-reference.
-@<Predecl...@>=
-void underline_xref();
-
-@ @c
-void
-underline_xref(p)
-name_pointer p;
+@c
+static void
+underline_xref(
+name_pointer p)
{
xref_pointer q=(xref_pointer)p->xref; /* pointer to cross-reference being examined */
xref_pointer r; /* temporary pointer for permuting cross-references */
@@ -2515,7 +2524,7 @@ name_pointer p;
else if (n>=def_flag && n<m) break;
q=q->xlink;
}
- @<Insert new cross-reference at |q|, not at beginning of list@>;
+ @<Insert new cross-reference at |q|, not at beginning of list@>@;
}
@ We get to this section only when the identifier is one letter long,
@@ -2528,7 +2537,7 @@ to insert the new cross-reference not at the beginning of the list
@<Insert new cross-reference at |q|...@>=
append_xref(0); /* this number doesn't matter */
xref_ptr->xlink=(xref_pointer)p->xref; r=xref_ptr;
- p->xref=(char*)xref_ptr;
+ update_node(p);
while (r->xlink!=q) {r->num=r->xlink->num; r=r->xlink;}
r->num=m; /* everything from |q| on is left undisturbed */
@@ -2818,7 +2827,11 @@ else if (cat1==stmt||cat1==decl||cat1==function) {
grouped together on the same line.
@d force_lines flags['f'] /* should each statement be on its own line? */
-@<Cases for |stmt|@>=
+
+@<Set init...@>=
+force_lines=true;
+
+@ @<Cases for |stmt|@>=
if (cat1==stmt||cat1==decl||cat1==function) {
big_app1(pp);
if (cat1==function) big_app(big_force);
@@ -3000,12 +3013,16 @@ too large, since it is assumed that this test was done beforehand.
@d freeze_text *(++text_ptr)=tok_ptr
-@c
-void
-reduce(j,k,c,d,n)
-scrap_pointer j;
-eight_bits c;
-short k, d, n;
+@<Predecl...@>=
+static void reduce(scrap_pointer,short,eight_bits,short,short);@/
+static void squash(scrap_pointer,short,eight_bits,short,short);
+
+@ @c
+static void
+reduce(
+scrap_pointer j, short k,
+eight_bits c,
+short d, short n)
{
scrap_pointer i, i1; /* pointers into scrap memory */
j->cat=c; j->trans=text_ptr;
@@ -3019,7 +3036,7 @@ short k, d, n;
lo_ptr=lo_ptr-k+1;
}
pp=(pp+d<scrap_base? scrap_base: pp+d);
- @<Print a snapshot of the scrap list if debugging @>;
+ @<Print a snapshot of the scrap list if debugging @>@;
pp--; /* we next say |pp++| */
}
@@ -3027,16 +3044,16 @@ short k, d, n;
takes advantage of the simplification that occurs when |k==1|.
@c
-void
-squash(j,k,c,d,n)
-scrap_pointer j;
-eight_bits c;
-short k, d, n;
+static void
+squash(
+scrap_pointer j, short k,
+eight_bits c,
+short d, short n)
{
scrap_pointer i; /* pointers into scrap memory */
if (k==1) {
j->cat=c; pp=(pp+d<scrap_base? scrap_base: pp+d);
- @<Print a snapshot...@>;
+ @<Print a snapshot...@>@;
pp--; /* we next say |pp++| */
return;
}
@@ -3058,8 +3075,8 @@ than to squeeze the last bit of space from the memory arrays.
@d safe_scrap_incr 10
@<Reduce the scraps using the productions until no more rules apply@>=
-while (1) {
- @<Make sure the entries |pp| through |pp+3| of |cat| are defined@>;
+while (true) {
+ @<Make sure the entries |pp| through |pp+3| of |cat| are defined@>@;
if (tok_ptr+safe_tok_incr>tok_mem_end) {
if (tok_ptr>max_tok_ptr) max_tok_ptr=tok_ptr;
overflow("token");
@@ -3070,7 +3087,7 @@ while (1) {
}
if (pp>lo_ptr) break;
init_mathness=cur_mathness=maybe_math;
- @<Match a production...@>;
+ @<Match a production...@>@;
}
@ If we get to the end of the scrap list, category codes equal to zero are
@@ -3090,22 +3107,22 @@ current stack categories will be printed out when |tracing| is set to 2;
a sequence of two or more irreducible scraps will be printed out when
|tracing| is set to 1.
-@<Global...@>=
-int tracing; /* can be used to show parsing details */
+@<Private...@>=
+static int tracing; /* can be used to show parsing details */
@ @<Print a snapsh...@>=
-{ scrap_pointer k; /* pointer into |scrap_info| */
+{ scrap_pointer k_l; /* pointer into |scrap_info| */
if (tracing==2) {
printf("\n%d:",n);
- for (k=scrap_base; k<=lo_ptr; k++) {
- if (k==pp) putxchar('*'); else putxchar(' ');
- if (k->mathness %4 == yes_math) putchar('+');
- else if (k->mathness %4 == no_math) putchar('-');
- print_cat(k->cat);
- if (k->mathness /4 == yes_math) putchar('+');
- else if (k->mathness /4 == no_math) putchar('-');
+ for (k_l=scrap_base; k_l<=lo_ptr; k_l++) {
+ if (k_l==pp) putxchar('*'); else putxchar(' ');
+ if (k_l->mathness %4 == yes_math) putchar('+');
+ else if (k_l->mathness %4 == no_math) putchar('-');
+ print_cat(k_l->cat);
+ if (k_l->mathness /4 == yes_math) putchar('+');
+ else if (k_l->mathness /4 == no_math) putchar('-');
}
- if (hi_ptr<=scrap_ptr) printf("..."); /* indicate that more is coming */
+ if (hi_ptr<=scrap_ptr) fputs("...",stdout); /* indicate that more is coming */
}
}
@@ -3123,24 +3140,26 @@ since |translate| might add a new text and a new scrap before it checks
for overflow.
@c
-text_pointer
-translate() /* converts a sequence of scraps */
+static text_pointer
+translate(void) /* converts a sequence of scraps */
{
scrap_pointer i, /* index into |cat| */
j; /* runs through final scraps */
pp=scrap_base; lo_ptr=pp-1; hi_ptr=pp;
- @<If tracing, print an indication of where we are@>;
- @<Reduce the scraps...@>;
- @<Combine the irreducible scraps that remain@>;
+ @<If tracing, print an indication of where we are@>@;
+ @<Reduce the scraps...@>@;
+ @<Combine the irreducible scraps that remain@>@;
}
+@ @<Predecl...@>=@+static text_pointer translate(void);
+
@ If the initial sequence of scraps does not reduce to a single scrap,
we concatenate the translations of all remaining scraps, separated by
blank spaces, with dollar signs surrounding the translations of scraps
where appropriate.
@<Combine the irreducible...@>= {
- @<If semi-tracing, show the irreducible scraps@>;
+ @<If semi-tracing, show the irreducible scraps@>@;
for (j=scrap_base; j<=lo_ptr; j++) {
if (j!=scrap_base) app(' ');
if (j->mathness % 4 == yes_math) app('$');
@@ -3148,7 +3167,7 @@ where appropriate.
if (j->mathness / 4 == yes_math) app('$');
if (tok_ptr+6>tok_mem_end) overflow("token");
}
- freeze_text; return(text_ptr-1);
+ freeze_text; return text_ptr-1;
}
@ @<If semi-tracing, show the irreducible scraps@>=
@@ -3188,19 +3207,21 @@ what it reads are appended into the |cat| and |trans| arrays, and |scrap_ptr|
is advanced.
@c
-void
-C_parse(spec_ctrl) /* creates scraps from \CEE/ tokens */
- eight_bits spec_ctrl;
+static void
+C_parse(@t\1\1@> /* creates scraps from \CEE/ tokens */
+ eight_bits spec_ctrl@t\2\2@>)
{
int count; /* characters remaining before string break */
while (next_control<format_code || next_control==spec_ctrl) {
- @<Append the scrap appropriate to |next_control|@>;
+ @<Append the scrap appropriate to |next_control|@>@;
next_control=get_next();
if (next_control=='|' || next_control==begin_comment ||
next_control==begin_short_comment) return;
}
}
+@ @<Predecl...@>=@+static void C_parse(eight_bits);
+
@ The following macro is used to append a scrap whose tokens have just
been appended:
@@ -3211,76 +3232,77 @@ been appended:
}
@ @<Append the scr...@>=
-@<Make sure that there is room for the new scraps, tokens, and texts@>;
+@<Make sure that there is room for the new scraps, tokens, and texts@>@;
switch (next_control) {
case section_name:
app(section_flag+(int)(cur_section-name_dir));
app_scrap(section_scrap,maybe_math);
app_scrap(exp,yes_math);@+break;
- case string: case constant: case verbatim: @<Append a string or constant@>;
- @+break;
- case identifier: app_cur_id(1);@+break;
- case TeX_string: @<Append a \TEX/ string, without forming a scrap@>;@+break;
+ case string: case constant: case verbatim:
+ @<Append a string or constant@>@;@+break;
+ case identifier: app_cur_id(true);@+break;
+ case TeX_string:
+ @<Append a \TEX/ string, without forming a scrap@>@;@+break;
case '/': case '.':
- app(next_control); app_scrap(binop,yes_math);@+break;
+ app(next_control);@+app_scrap(binop,yes_math);@+break;
case '<': app_str("\\langle");@+app_scrap(prelangle,yes_math);@+break;
@.\\langle@>
case '>': app_str("\\rangle");@+app_scrap(prerangle,yes_math);@+break;
@.\\rangle@>
- case '=': app_str("\\K"); app_scrap(binop,yes_math);@+break;
+ case '=': app_str("\\K");@+app_scrap(binop,yes_math);@+break;
@.\\K@>
- case '|': app_str("\\OR"); app_scrap(binop,yes_math);@+break;
+ case '|': app_str("\\OR");@+app_scrap(binop,yes_math);@+break;
@.\\OR@>
- case '^': app_str("\\XOR"); app_scrap(binop,yes_math);@+break;
+ case '^': app_str("\\XOR");@+app_scrap(binop,yes_math);@+break;
@.\\XOR@>
- case '%': app_str("\\MOD"); app_scrap(binop,yes_math);@+break;
+ case '%': app_str("\\MOD");@+app_scrap(binop,yes_math);@+break;
@.\\MOD@>
- case '!': app_str("\\R"); app_scrap(unop,yes_math);@+break;
+ case '!': app_str("\\R");@+app_scrap(unop,yes_math);@+break;
@.\\R@>
- case '~': app_str("\\CM"); app_scrap(unop,yes_math);@+break;
+ case '~': app_str("\\CM");@+app_scrap(unop,yes_math);@+break;
@.\\CM@>
- case '+': case '-': app(next_control); app_scrap(ubinop,yes_math);@+break;
- case '*': app(next_control); app_scrap(raw_ubin,yes_math);@+break;
- case '&': app_str("\\AND"); app_scrap(raw_ubin,yes_math);@+break;
+ case '+': case '-': app(next_control);@+app_scrap(ubinop,yes_math);@+break;
+ case '*': app(next_control);@+app_scrap(raw_ubin,yes_math);@+break;
+ case '&': app_str("\\AND");@+app_scrap(raw_ubin,yes_math);@+break;
@.\\AND@>
- case '?': app_str("\\?"); app_scrap(question,yes_math);@+break;
+ case '?': app_str("\\?");@+app_scrap(question,yes_math);@+break;
@.\\?@>
- case '#': app_str("\\#"); app_scrap(ubinop,yes_math);@+break;
+ case '#': app_str("\\#");@+app_scrap(ubinop,yes_math);@+break;
@.\\\#@>
case ignore: case xref_roman: case xref_wildcard:
case xref_typewriter: case noop:@+break;
- case '(': case '[': app(next_control); app_scrap(lpar,maybe_math);@+break;
- case ')': case ']': app(next_control); app_scrap(rpar,maybe_math);@+break;
- case '{': app_str("\\{"@q}@>); app_scrap(lbrace,yes_math);@+break;
+ case '(': case '[': app(next_control);@+app_scrap(lpar,maybe_math);@+break;
+ case ')': case ']': app(next_control);@+app_scrap(rpar,maybe_math);@+break;
+ case '{': app_str("\\{"@q}@>);@+app_scrap(lbrace,yes_math);@+break;
@.\\\{@>@q}@>
- case '}': app_str(@q{@>"\\}"); app_scrap(rbrace,yes_math);@+break;
+ case '}': app_str(@q{@>"\\}");@+app_scrap(rbrace,yes_math);@+break;
@q{@>@.\\\}@>
- case ',': app(','); app_scrap(comma,yes_math);@+break;
- case ';': app(';'); app_scrap(semi,maybe_math);@+break;
- case ':': app(':'); app_scrap(colon,no_math);@+break;@/
+ case ',': app(',');@+app_scrap(comma,yes_math);@+break;
+ case ';': app(';');@+app_scrap(semi,maybe_math);@+break;
+ case ':': app(':');@+app_scrap(colon,no_math);@+break;@/
@t\4@> @<Cases involving nonstandard characters@>@;
- case thin_space: app_str("\\,"); app_scrap(insert,maybe_math);@+break;
+ case thin_space: app_str("\\,");@+app_scrap(insert,maybe_math);@+break;
@.\\,@>
- case math_break: app(opt); app_str("0");
+ case math_break: app(opt);@+app_str("0");@+
app_scrap(insert,maybe_math);@+break;
- case line_break: app(force); app_scrap(insert,no_math);@+break;
- case left_preproc: app(force); app(preproc_line);
- app_str("\\#"); app_scrap(lproc,no_math);@+break;
+ case line_break: app(force);@+app_scrap(insert,no_math);@+break;
+ case left_preproc: app(force);@+app(preproc_line);@+app_str("\\#");
+ app_scrap(lproc,no_math);@+break;
@.\\\#@>
- case right_preproc: app(force); app_scrap(rproc,no_math);@+break;
- case big_line_break: app(big_force); app_scrap(insert,no_math);@+break;
- case no_line_break: app(big_cancel); app(noop); app(break_space);
- app(noop); app(big_cancel);
+ case right_preproc: app(force);@+app_scrap(rproc,no_math);@+break;
+ case big_line_break: app(big_force);@+app_scrap(insert,no_math);@+break;
+ case no_line_break: app(big_cancel);@+app(noop);@+app(break_space);@+
+ app(noop);@+app(big_cancel);
app_scrap(insert,no_math);@+break;
case pseudo_semi: app_scrap(semi,maybe_math);@+break;
case macro_arg_open: app_scrap(begin_arg,maybe_math);@+break;
case macro_arg_close: app_scrap(end_arg,maybe_math);@+break;
- case join: app_str("\\J"); app_scrap(insert,no_math);@+break;
+ case join: app_str("\\J");@+app_scrap(insert,no_math);@+break;
@.\\J@>
- case output_defs_code: app(force); app_str("\\ATH"); app(force);
+ case output_defs_code: app(force);@+app_str("\\ATH");@+app(force);
app_scrap(insert,no_math);@+break;
@.\\ATH@>
- default: app(inserted); app(next_control);
+ default: app(inserted);@+app(next_control);
app_scrap(insert,maybe_math);@+break;
}
@@ -3299,7 +3321,7 @@ standard ones. They are converted to \TEX/ control sequences so that it is
possible to keep \.{CWEAVE} from outputting unusual |char| codes.
@<Cases involving nonstandard...@>=
-case not_eq: app_str("\\I");@+app_scrap(binop,yes_math);@+break;
+case non_eq: app_str("\\I");@+app_scrap(binop,yes_math);@+break;
@.\\I@>
case lt_eq: app_str("\\Z");@+app_scrap(binop,yes_math);@+break;
@.\\Z@>
@@ -3416,15 +3438,17 @@ while (id_first<id_loc)
app(@q{@>'}');
@ The function |app_cur_id| appends the current identifier to the
-token list; it also builds a new scrap if |scrapping==1|.
+token list; it also builds a new scrap if |scrapping==true|.
@<Predec...@>=
-void app_cur_id();
+static void app_cur_id(boolean);@/
+static text_pointer C_translate(void);@/
+static void outer_parse(void);
@ @c
-void
-app_cur_id(scrapping)
-boolean scrapping; /* are we making this into a scrap? */
+static void
+app_cur_id(@t\1\1@>
+boolean scrapping@t\2\2@>) /* are we making this into a scrap? */
{
name_pointer p=id_lookup(id_first,id_loc,normal);
if (p->ilk<=custom) { /* not a reserved word */
@@ -3447,8 +3471,8 @@ that text. If scraps exist in |scrap_info|, they are
unaffected by this translation process.
@c
-text_pointer
-C_translate()
+static text_pointer
+C_translate(void)
{
text_pointer p; /* points to the translation */
scrap_pointer save_base; /* holds original value of |scrap_base| */
@@ -3461,7 +3485,7 @@ C_translate()
p=translate(); /* make the translation */
if (scrap_ptr>max_scr_ptr) max_scr_ptr=scrap_ptr;
scrap_ptr=scrap_base-1; scrap_base=save_base; /* scrap the scraps */
- return(p);
+ return p;
}
@ The |outer_parse| routine is to |C_parse| as |outer_xref|
@@ -3476,9 +3500,12 @@ program text.
@d make_pb flags['e']
-@c
-void
-outer_parse() /* makes scraps from \CEE/ tokens and comments */
+@<Set init...@>=
+make_pb=true;
+
+@ @c
+static void
+outer_parse(void) /* makes scraps from \CEE/ tokens and comments */
{
int bal; /* brace level in comment */
text_pointer p, q; /* partial comments */
@@ -3487,7 +3514,7 @@ outer_parse() /* makes scraps from \CEE/ tokens and comments */
C_parse(ignore);
else {
boolean is_long_comment=(next_control==begin_comment);
- @<Make sure that there is room for the new...@>;
+ @<Make sure that there is room for the new...@>@;
app(cancel); app(inserted);
if (is_long_comment) app_str("\\C{"@q}@>);
@.\\C@>
@@ -3568,12 +3595,12 @@ typedef output_state *stack_pointer;
@d cur_mode cur_state.mode_field /* current mode of interpretation */
@d init_stack stack_ptr=stack;cur_mode=outer /* initialize the stack */
-@<Global...@>=
-output_state cur_state; /* |cur_end|, |cur_tok|, |cur_mode| */
-output_state stack[stack_size]; /* info for non-current levels */
-stack_pointer stack_ptr; /* first unused location in the output state stack */
-stack_pointer stack_end=stack+stack_size-1; /* end of |stack| */
-stack_pointer max_stack_ptr; /* largest value assumed by |stack_ptr| */
+@<Private...@>=
+static output_state cur_state; /* |cur_end|, |cur_tok|, |cur_mode| */
+static output_state stack[stack_size]; /* info for non-current levels */
+static stack_pointer stack_end=stack+stack_size-1; /* end of |stack| */
+static stack_pointer stack_ptr; /* first unused location in the output state stack */
+static stack_pointer max_stack_ptr; /* largest value assumed by |stack_ptr| */
@ @<Set init...@>=
max_stack_ptr=stack;
@@ -3582,10 +3609,14 @@ max_stack_ptr=stack;
is called; it saves the old level of output and gets a new one going.
The value of |cur_mode| is not changed.
-@c
-void
-push_level(p) /* suspends the current level */
-text_pointer p;
+@<Predecl...@>=
+static void push_level(text_pointer);@/
+static void pop_level(void);
+
+@ @c
+static void
+push_level(@t\1\1@> /* suspends the current level */
+text_pointer p@t\2\2@>)
{
if (stack_ptr==stack_end) overflow("stack");
if (stack_ptr>stack) { /* save current state */
@@ -3603,8 +3634,8 @@ force when the current level was begun. This subroutine will never be
called when |stack_ptr==1|.
@c
-void
-pop_level()
+static void
+pop_level(void)
{
cur_end=(--stack_ptr)->end_field;
cur_tok=stack_ptr->tok_field; cur_mode=stack_ptr->mode_field;
@@ -3618,15 +3649,20 @@ by a complex routine that might generate additional levels of output).
In these cases |cur_name| points to the identifier or section name in
question.
-@<Global...@>=
-name_pointer cur_name;
+@<Private...@>=
+static name_pointer cur_name;
@ @d res_word 0201 /* returned by |get_output| for reserved words */
@d section_code 0200 /* returned by |get_output| for section names */
-@c
-eight_bits
-get_output() /* returns the next token of output */
+@<Predecl...@>=
+static eight_bits get_output(void);@/
+static void output_C(void);@/
+static void make_output(void);
+
+@ @c
+static eight_bits
+get_output(void) /* returns the next token of output */
{
sixteen_bits a; /* current item read from |tok_mem| */
restart: while (cur_tok==cur_end) pop_level();
@@ -3634,16 +3670,16 @@ get_output() /* returns the next token of output */
if (a>=0400) {
cur_name=a % id_flag + name_dir;
switch (a / id_flag) {
- case 2: return(res_word); /* |a==res_flag+cur_name| */
- case 3: return(section_code); /* |a==section_flag+cur_name| */
+ case 2: return res_word ; /* |a==res_flag+cur_name| */
+ case 3: return section_code ; /* |a==section_flag+cur_name| */
case 4: push_level(a % id_flag + tok_start); goto restart;
/* |a==tok_flag+cur_name| */
case 5: push_level(a % id_flag + tok_start); cur_mode=inner; goto restart;
/* |a==inner_tok_flag+cur_name| */
- default: return(identifier); /* |a==id_flag+cur_name| */
+ default: return identifier; /* |a==id_flag+cur_name| */
}
}
- return(a);
+ return (eight_bits)a;
}
@ The real work associated with token output is done by |make_output|.
@@ -3662,8 +3698,8 @@ while outputting the name of a section.
@^recursion@>
@c
-void
-output_C() /* outputs the current token list */
+static void
+output_C(void) /* outputs the current token list */
{
token_pointer save_tok_ptr;
text_pointer save_text_ptr;
@@ -3684,17 +3720,14 @@ output_C() /* outputs the current token list */
@ Here is \.{CWEAVE}'s major output handler.
-@<Predecl...@>=
-void make_output();
-
-@ @c
-void
-make_output() /* outputs the equivalents of tokens */
+@c
+static void
+make_output(void) /* outputs the equivalents of tokens */
{
- eight_bits a, /* current output byte */
+ eight_bits a=0, /* current output byte */
b; /* next output byte */
int c; /* count of |indent| and |outdent| tokens */
- char scratch[longest_name]; /* scratch area for section names */
+ char scratch[longest_name+1]; /* scratch area for section names */
char *k, *k_limit; /* indices into |scratch| */
char *j; /* index into |buffer| */
char *p; /* index into |byte_mem| */
@@ -3704,28 +3737,28 @@ make_output() /* outputs the equivalents of tokens */
boolean save_mode; /* value of |cur_mode| before a sequence of breaks */
app(end_translation); /* append a sentinel */
freeze_text; push_level(text_ptr-1);
- while (1) {
+ while (true) {
a=get_output();
reswitch: switch(a) {
case end_translation: return;
- case identifier: case res_word: @<Output an identifier@>; break;
- case section_code: @<Output a section name@>; break;
+ case identifier: case res_word: @<Output an identifier@>@; break;
+ case section_code: @<Output a section name@>@; break;
case math_rel: out_str("\\MRL{"@q}@>);
@.\\MRL@>
case noop: case inserted: break;
case cancel: case big_cancel: c=0; b=a;
- while (1) {
+ while (true) {
a=get_output();
if (a==inserted) continue;
if ((a<indent && !(b==big_cancel&&a==' ')) || a>big_force) break;
if (a==indent) c++; else if (a==outdent) c--;
else if (a==opt) a=get_output();
}
- @<Output saved |indent| or |outdent| tokens@>;
+ @<Output saved |indent| or |outdent| tokens@>@;
goto reswitch;
case indent: case outdent: case opt: case backup: case break_space:
case force: case big_force: case preproc_line: @<Output a control,
- look ahead in case of line breaks, possibly |goto reswitch|@>; break;
+ look ahead in case of line breaks, possibly |goto reswitch|@>@; break;
case quoted_char: out(*(cur_tok++));
case qualifier: break;
default: out(a); /* otherwise |a| is an ordinary character */
@@ -3767,7 +3800,7 @@ if (is_tiny(cur_name)) {
out('\\');
out((cur_name->byte_start)[0]);
}
-else out_name(cur_name,1);
+else out_name(cur_name,true);
@ The current mode does not affect the behavior of \.{CWEAVE}'s output routine
except when we are outputting control tokens.
@@ -3783,7 +3816,7 @@ if (a<break_space || a==preproc_line) {
@.\\8@>
if (a==opt) {
b=get_output(); /* |opt| is followed by a digit */
- if (b!='0' || force_lines==0) out(b)@;
+ if (b!='0' || force_lines==false) out(b)@;
else out_str("{-1}"); /* |force_lines| encourages more \.{@@\v} breaks */
}
} else if (a==opt) b=get_output(); /* ignore digit following |opt| */
@@ -3798,18 +3831,18 @@ is suppressed (i.e., a line break that follows `\.{\\Y\\B}').
@<Look ahead for st...@>= {
b=a; save_mode=cur_mode; c=0;
- while (1) {
+ while (true) {
a=get_output();
if (a==inserted) continue;
if (a==cancel || a==big_cancel) {
- @<Output saved |indent| or |outdent| tokens@>;
+ @<Output saved |indent| or |outdent| tokens@>@;
goto reswitch; /* |cancel| overrides everything */
}
if ((a!=' ' && a<indent) || a==backup || a>big_force) {
if (save_mode==outer) {
if (out_ptr>out_buf+3 && strncmp(out_ptr-3,"\\Y\\B",4)==0)
goto reswitch;
- @<Output saved |indent| or |outdent| tokens@>;
+ @<Output saved |indent| or |outdent| tokens@>@;
out('\\'); out(b-cancel+'0');
@.\\5@>
@.\\6@>
@@ -3843,8 +3876,8 @@ input buffer and the translation process uses the end of the active
out_str("\\X");
@.\\X@>
cur_xref=(xref_pointer)cur_name->xref;
- if (cur_xref->num==file_flag) {an_output=1; cur_xref=cur_xref->xlink;}
- else an_output=0;
+ if (cur_xref->num==file_flag) {an_output=true; cur_xref=cur_xref->xlink;}
+ else an_output=false;
if (cur_xref->num>=def_flag) {
out_section(cur_xref->num-def_flag);
if (phase==3) {
@@ -3860,7 +3893,7 @@ input buffer and the translation process uses the end of the active
out(':');
if (an_output) out_str("\\.{"@q}@>);
@.\\.@>
- @<Output the text of the section name@>;
+ @<Output the text of the section name@>@;
if (an_output) out_str(@q{@>" }");
out_str("\\X");
}
@@ -3872,7 +3905,7 @@ k_limit=scratch+strlen(scratch);
cur_section_name=cur_name;
while (k<k_limit) {
b=*(k++);
- if (b=='@@') @<Skip next character, give error if not `\.{@@}'@>;
+ if (b=='@@') @<Skip next character, give error if not `\.{@@}'@>@;
if (an_output)
switch (b) {
case ' ':case '\\':case '#':case '%':case '$':case '^':
@@ -3891,18 +3924,18 @@ while (k<k_limit) {
@.\\\_@>
default: out(b);
}
- else if (b!='|') out(b)@;
+ else { if (b!='|') out(b)@;
else {
- @<Copy the \CEE/ text into the |buffer| array@>;
+ @<Copy the \CEE/ text into the |buffer| array@>@;
save_loc=loc; save_limit=limit; loc=limit+2; limit=j+1;
*limit='|'; output_C();
loc=save_loc; limit=save_limit;
- }
+ } }
}
@ @<Skip next char...@>=
if (*k++!='@@') {
- printf("\n! Illegal control code in section name: <");
+ fputs("\n! Illegal control code in section name: <",stdout);
@.Illegal control code...@>
print_section_name(cur_section_name); printf("> "); mark_error;
}
@@ -3915,9 +3948,9 @@ equals the delimiter that began the string being copied.
@<Copy the \CEE/ text into...@>=
j=limit+1; *j='|'; delim=0;
-while (1) {
+while (true) {
if (k>=k_limit) {
- printf("\n! C text in section name didn't end: <");
+ fputs("\n! C text in section name didn't end: <",stdout);
@.C text...didn't end@>
print_section_name(cur_section_name); printf("> "); mark_error; break;
}
@@ -3925,9 +3958,9 @@ while (1) {
if (b=='@@' || (b=='\\' && delim!=0))
@<Copy a quoted character into the buffer@>@;
else {
- if (b=='\'' || b=='"')
+ if (b=='\'' || b=='"') {
if (delim==0) delim=b;
- else if (delim==b) delim=0;
+ else if (delim==b) delim=0; }
if (b!='|' || delim!=0) {
if (j>buffer+long_buf_size-3) overflow("buffer");
*(++j)=b;
@@ -3948,19 +3981,18 @@ is analogous to phase one, except that more work is involved because we must
actually output the \TEX/ material instead of merely looking at the
\.{CWEB} specifications.
-@<Predecl...@>=
-void phase_two();
-
-@ @c
-void
-phase_two() {
-reset_input(); if (show_progress) printf("\nWriting the output file...");
+@c
+static void
+phase_two(void) {
+reset_input(); if (show_progress) fputs("\nWriting the output file...",stdout);
@.Writing the output file...@>
-section_count=0; format_visible=1; copy_limbo();
-finish_line(); flush_buffer(out_buf,0,0); /* insert a blank line, it looks nice */
-while (!input_has_ended) @<Translate the current section@>;
+section_count=0; format_visible=true; copy_limbo();
+finish_line(); flush_buffer(out_buf,false,false); /* insert a blank line, it looks nice */
+while (!input_has_ended) @<Translate the current section@>@;
}
+@ @<Predecl...@>=@+static void phase_two(void);
+
@ The output file will contain the control sequence \.{\\Y} between non-null
sections of a section, e.g., between the \TEX/ and definition parts if both
are nonempty. This puts a little white space between the parts when they are
@@ -3972,27 +4004,27 @@ and `|emit_space_if_needed|' are able to handle the situation:
@d save_position save_line=out_line; save_place=out_ptr
@d emit_space_if_needed if (save_line!=out_line || save_place!=out_ptr)
out_str("\\Y");
- space_checked=1
+ space_checked=true;
@.\\Y@>
-@<Global...@>=
-int save_line; /* former value of |out_line| */
-char *save_place; /* former value of |out_ptr| */
-int sec_depth; /* the integer, if any, following \.{@@*} */
-boolean space_checked; /* have we done |emit_space_if_needed|? */
-boolean format_visible; /* should the next format declaration be output? */
-boolean doing_format=0; /* are we outputting a format declaration? */
-boolean group_found=0; /* has a starred section occurred? */
+@<Private...@>=
+static int save_line; /* former value of |out_line| */
+static char *save_place; /* former value of |out_ptr| */
+static int sec_depth; /* the integer, if any, following \.{@@*} */
+static boolean space_checked; /* have we done |emit_space_if_needed|? */
+static boolean format_visible; /* should the next format declaration be output? */
+static boolean doing_format=false; /* are we outputting a format declaration? */
+static boolean group_found=false; /* has a starred section occurred? */
@ @<Translate the current section@>= {
section_count++;
- @<Output the code for the beginning of a new section@>;
+ @<Output the code for the beginning of a new section@>@;
save_position;
- @<Translate the \TEX/ part of the current section@>;
- @<Translate the definition part of the current section@>;
- @<Translate the \CEE/ part of the current section@>;
- @<Show cross-references to this section@>;
- @<Output the code for the end of a section@>;
+ @<Translate the \TEX/ part of the current section@>@;
+ @<Translate the definition part of the current section@>@;
+ @<Translate the \CEE/ part of the current section@>@;
+ @<Show cross-references to this section@>@;
+ @<Output the code for the end of a section@>@;
}
@ Sections beginning with the \.{CWEB} control sequence `\.{@@\ }' start in the
@@ -4016,7 +4048,7 @@ else {
sec_depth = sec_depth*10 + (*loc) -'0';
}
while (*loc == ' ') loc++; /* remove spaces before group title */
- group_found=1;
+ group_found=true;
out_str("\\N");
@.\\N@>
{@+ char s[32];@+sprintf(s,"{%d}",sec_depth+1);@+out_str(s);@+}
@@ -4052,13 +4084,13 @@ index entries are not copied and \CEE/ text within \pb\ is translated.
the token memory is in its initial empty state.
@<Translate the d...@>=
-space_checked=0;
+space_checked=false;
while (next_control<=definition) { /* |format_code| or |definition| */
init_stack;
if (next_control==definition) @<Start a macro definition@>@;
- else @<Start a format definition@>;
- outer_parse(); finish_C(format_visible); format_visible=1;
- doing_format=0;
+ else @<Start a format definition@>@;
+ outer_parse(); finish_C(format_visible); format_visible=true;
+ doing_format=false;
}
@ The |finish_C| procedure outputs the translation of the current
@@ -4071,13 +4103,10 @@ takes place, so that the translation will normally end with \.{\\6} or
\.{\\7} (the \TEX/ macros for |force| and |big_force|). This \.{\\6} or
\.{\\7} is replaced by the concluding \.{\\par} or by \.{\\Y\\par}.
-@<Predecl...@>=
-void finish_C();
-
-@ @c
-void
-finish_C(visible) /* finishes a definition or a \CEE/ part */
- boolean visible; /* nonzero if we should produce \TEX/ output */
+@c
+static void
+finish_C(@t\1\1@> /* finishes a definition or a \CEE/ part */
+ boolean visible@t\2\2@>) /* nonzero if we should produce \TeX\ output */
{
text_pointer p; /* translation of the scraps */
if (visible) {
@@ -4085,13 +4114,15 @@ finish_C(visible) /* finishes a definition or a \CEE/ part */
p=translate();
@.\\B@>
app(tok_flag+(int)(p-tok_start)); make_output(); /* output the list */
- if (out_ptr>out_buf+1)
- if (*(out_ptr-1)=='\\')
+ if (out_ptr>out_buf+1) {
+ if (*(out_ptr-1)=='\\') {
@.\\6@>
@.\\7@>
@.\\Y@>
if (*out_ptr=='6') out_ptr-=2;
else if (*out_ptr=='7') *out_ptr='Y';
+ }
+ }
out_str("\\par"); finish_line();
}
if (text_ptr>max_text_ptr) max_text_ptr=text_ptr;
@@ -4101,6 +4132,8 @@ finish_C(visible) /* finishes a definition or a \CEE/ part */
/* forget the tokens and the scraps */
}
+@ @<Predecl...@>=@+static void finish_C(boolean);
+
@ Keeping in line with the conventions of the \CEE/ preprocessor (and
otherwise contrary to the rules of \.{CWEB}) we distinguish here
between the case that `\.(' immediately follows an identifier and the
@@ -4118,11 +4151,11 @@ it starts after we scan the matching `\.)'.
err_print("! Improper macro definition");
@.Improper macro definition@>
else {
- app('$'); app_cur_id(0);
+ app('$'); app_cur_id(false);
if (*loc=='(')
reswitch: switch (next_control=get_next()) {
case '(': case ',': app(next_control); goto reswitch;
- case identifier: app_cur_id(0); goto reswitch;
+ case identifier: app_cur_id(false); goto reswitch;
case ')': app(next_control); next_control=get_next(); break;
default: err_print("! Improper macro definition"); break;
}
@@ -4133,8 +4166,8 @@ it starts after we scan the matching `\.)'.
}
@ @<Start a format...@>= {
- doing_format=1;
- if(*(loc-1)=='s' || *(loc-1)=='S') format_visible=0;
+ doing_format=true;
+ if(*(loc-1)=='s' || *(loc-1)=='S') format_visible=false;
if(!space_checked){emit_space_if_needed;save_position;}
app_str("\\F"); /* this will produce `\&{format }' */
@.\\F@>
@@ -4158,8 +4191,8 @@ it starts after we scan the matching `\.)'.
|next_control>=begin_C|. We will make the global variable |this_section|
point to the current section name, if it has a name.
-@<Global...@>=
-name_pointer this_section; /* the current section name, or zero */
+@<Private...@>=
+static name_pointer this_section; /* the current section name, or zero */
@ @<Translate the \CEE/...@>=
this_section=name_dir;
@@ -4169,13 +4202,13 @@ if (next_control<=section_name) {
else {
this_section=cur_section;
@<Check that '=' or '==' follows this section name, and
- emit the scraps to start the section definition@>;
+ emit the scraps to start the section definition@>@;
}
while (next_control<=section_name) {
outer_parse();
- @<Emit the scrap for a section name if present@>;
+ @<Emit the scrap for a section name if present@>@;
}
- finish_C(1);
+ finish_C(true);
}
@ The title of the section and an $\E$ or $\mathrel+\E$ are made
@@ -4196,8 +4229,8 @@ cur_xref=(xref_pointer)this_section->xref;
if(cur_xref->num==file_flag) cur_xref=cur_xref->xlink;
app_str("${}");
if (cur_xref->num!=section_count+def_flag) {
- app_str("\\mathrel+"); /*section name is multiply defined*/
- this_section=name_dir; /*so we won't give cross-reference info here*/
+ app_str("\\mathrel+"); /* section name is multiply defined */
+ this_section=name_dir; /* so we won't give cross-reference info here */
}
app_str("\\E"); /* output an equivalence sign */
@.\\E@>
@@ -4223,8 +4256,8 @@ after the section ends.
@<Show cross...@>=
if (this_section>name_dir) {
cur_xref=(xref_pointer)this_section->xref;
- if (cur_xref->num==file_flag){an_output=1;cur_xref=cur_xref->xlink;}
- else an_output=0;
+ if (cur_xref->num==file_flag){an_output=true;cur_xref=cur_xref->xlink;}
+ else an_output=false;
if (cur_xref->num>def_flag)
cur_xref=cur_xref->xlink; /* bypass current section number */
footnote(def_flag); footnote(cite_flag); footnote(0);
@@ -4242,13 +4275,10 @@ leaves |cur_xref| pointing to the first element not printed. Typical outputs:
Note that the output of \.{CWEAVE} is not English-specific; users may
supply new definitions for the macros \.{\\A}, \.{\\As}, etc.
-@<Predecl...@>=
-void footnote();
-
-@ @c
-void
-footnote(flag) /* outputs section cross-references */
-sixteen_bits flag;
+@c
+static void
+footnote(@t\1\1@> /* outputs section cross-references */
+sixteen_bits flag@t\2\2@>)
{
xref_pointer q; /* cross-reference pointer variable */
if (cur_xref->num<=flag) return;
@@ -4257,17 +4287,19 @@ sixteen_bits flag;
@.\\Q@>
@.\\U@>
out(flag==0? 'U': flag==cite_flag? 'Q': 'A');
- @<Output all the section numbers on the reference list |cur_xref|@>;
+ @<Output all the section numbers on the reference list |cur_xref|@>@;
out('.');
}
+@ @<Predecl...@>=@+static void footnote(sixteen_bits);
+
@ The following code distinguishes three cases, according as the number
of cross-references is one, two, or more than two. Variable |q| points
to the first cross-reference, and the last link is a zero.
@<Output all the section numbers...@>=
q=cur_xref; if (q->xlink->num>flag) out('s'); /* plural */
-while (1) {
+while (true) {
out_section(cur_xref->num-flag);
cur_xref=cur_xref->xlink; /* point to the next cross-reference to output */
if (cur_xref->num<=flag) break;
@@ -4281,7 +4313,7 @@ while (1) {
@ @<Output the code for the end of a section@>=
out_str("\\fi"); finish_line();
@.\\fi@>
-flush_buffer(out_buf,0,0); /* insert a blank line, it looks nice */
+flush_buffer(out_buf,false,false); /* insert a blank line, it looks nice */
@** Phase three processing.
We are nearly finished! \.{CWEAVE}'s only remaining task is to write out the
@@ -4291,12 +4323,9 @@ If the user has set the |no_xref| flag (the \.{-x} option on the command line),
just finish off the page, omitting the index, section name list, and table of
contents.
-@<Predecl...@>=
-void phase_three();
-
-@ @c
-void
-phase_three() {
+@c
+static void
+phase_three(void) {
if (no_xref) {
finish_line();
out_str("\\end");
@@ -4304,29 +4333,29 @@ if (no_xref) {
finish_line();
}
else {
- phase=3; if (show_progress) printf("\nWriting the index...");
+ phase=3; if (show_progress) fputs("\nWriting the index...",stdout);
@.Writing the index...@>
finish_line();
- if ((idx_file=fopen(idx_file_name,"w"))==NULL)
+ if ((idx_file=fopen(idx_file_name,"wb"))==NULL)
fatal("! Cannot open index file ",idx_file_name);
@.Cannot open index file@>
if (change_exists) {
- @<Tell about changed sections@>; finish_line(); finish_line();
+ @<Tell about changed sections@>@; finish_line(); finish_line();
}
out_str("\\inx"); finish_line();
@.\\inx@>
active_file=idx_file; /* change active file to the index file */
- @<Do the first pass of sorting@>;
- @<Sort and output the index@>;
+ @<Do the first pass of sorting@>@;
+ @<Sort and output the index@>@;
finish_line(); fclose(active_file); /* finished with |idx_file| */
active_file=tex_file; /* switch back to |tex_file| for a tic */
out_str("\\fin"); finish_line();
@.\\fin@>
- if ((scn_file=fopen(scn_file_name,"w"))==NULL)
+ if ((scn_file=fopen(scn_file_name,"wb"))==NULL)
fatal("! Cannot open section file ",scn_file_name);
@.Cannot open section file@>
active_file=scn_file; /* change active file to section listing file */
- @<Output all the section names@>;
+ @<Output all the section names@>@;
finish_line(); fclose(active_file); /* finished with |scn_file| */
active_file=tex_file;
if (group_found) out_str("\\con");@+else out_str("\\end");
@@ -4335,15 +4364,20 @@ else {
finish_line();
fclose(active_file);
}
-if (show_happiness) printf("\nDone.");
+if (show_happiness) {
+ if (show_progress) new_line;
+ fputs("Done.",stdout);
+}
check_complete(); /* was all of the change file used? */
}
+@ @<Predecl...@>=@+static void phase_three(void);
+
@ Just before the index comes a list of all the changed sections, including
the index section itself.
-@<Global...@>=
-sixteen_bits k_section; /* runs through the sections */
+@<Private...@>=
+static sixteen_bits k_section; /* runs through the sections */
@ @<Tell about changed sections@>= {
/* remember that the index is already marked as changed */
@@ -4362,28 +4396,28 @@ sixteen_bits k_section; /* runs through the sections */
@ A left-to-right radix sorting method is used, since this makes it easy to
adjust the collating sequence and since the running time will be at worst
proportional to the total length of all entries in the index. We put the
-identifiers into 102 different lists based on their first characters.
+identifiers into different lists based on their first characters.
(Uppercase letters are put into the same list as the corresponding lowercase
letters, since we want to have `$t<\\{TeX}<\&{to}$'.) The
list for character |c| begins at location |bucket[c]| and continues through
the |blink| array.
-@<Global...@>=
-name_pointer bucket[256];
-name_pointer next_name; /* successor of |cur_name| when sorting */
-name_pointer blink[max_names]; /* links in the buckets */
+@<Private...@>=
+static name_pointer bucket[256];
+static name_pointer next_name; /* successor of |cur_name| when sorting */
+static name_pointer blink[max_names]; /* links in the buckets */
@ To begin the sorting, we go through all the hash lists and put each entry
having a nonempty cross-reference list into the proper bucket.
@<Do the first pass...@>= {
int c;
-for (c=0; c<=255; c++) bucket[c]=NULL;
+for (c=0; c<256; c++) bucket[c]=NULL;
for (h=hash; h<=hash_end; h++) {
next_name=*h;
while (next_name) {
cur_name=next_name; next_name=cur_name->link;
- if (cur_name->xref!=(char*)xmem) {
+ if (cur_name->xref!=(void *)xmem) {
c=(eight_bits)((cur_name->byte_start)[0]);
if (xisupper(c)) c=tolower(c);
blink[cur_name-name_dir]=bucket[c]; bucket[c]=cur_name;
@@ -4401,7 +4435,7 @@ present; the lists are output in reverse order (first |sort_ptr|, then
|k| characters of all entries on this list are known to be equal we have
|depth[j]==k|.
-@ @<Rest of |trans_plus| union@>=
+@<Rest of |trans_plus| union@>=
name_pointer Head;
@ @d depth cat /* reclaims memory that is no longer needed for parsing */
@@ -4411,11 +4445,11 @@ name_pointer Head;
@d sort_ptr scrap_ptr /* ditto */
@d max_sorts max_scraps /* ditto */
-@<Global...@>=
-eight_bits cur_depth; /* depth of current buckets */
-char *cur_byte; /* index into |byte_mem| */
-sixteen_bits cur_val; /* current cross-reference number */
-sort_pointer max_sort_ptr; /* largest value of |sort_ptr| */
+@<Private...@>=
+static eight_bits cur_depth; /* depth of current buckets */
+static char *cur_byte; /* index into |byte_mem| */
+static sixteen_bits cur_val; /* current cross-reference number */
+static sort_pointer max_sort_ptr; /* largest value of |sort_ptr| */
@ @<Set init...@>=
max_sort_ptr=scrap_info;
@@ -4423,8 +4457,8 @@ max_sort_ptr=scrap_info;
@ The desired alphabetic order is specified by the |collate| array; namely,
$|collate|[0]<|collate|[1]<\cdots<|collate|[100]$.
-@<Global...@>=
-eight_bits collate[102+128]; /* collation order */
+@<Private...@>=
+static eight_bits collate[101+128]; /* collation order */
@^high-bit character handling@>
@ We use the order $\hbox{null}<\.\ <\hbox{other characters}<{}$\.\_${}<
@@ -4438,29 +4472,41 @@ some \CEE/ compilers choke on long strings.
@<Set init...@>=
collate[0]=0;
-strcpy(collate+1," \1\2\3\4\5\6\7\10\11\12\13\14\15\16\17");
+memcpy((char *)collate+1,
+ " \1\2\3\4\5\6\7\10\11\12\13\14\15\16\17",16);
/* 16 characters + 1 = 17 */
-strcpy(collate+17,"\20\21\22\23\24\25\26\27\30\31\32\33\34\35\36\37");
+memcpy((char *)collate+17,
+ "\20\21\22\23\24\25\26\27\30\31\32\33\34\35\36\37",16);
/* 16 characters + 17 = 33 */
-strcpy(collate+33,"!\42#$%&'()*+,-./:;<=>?@@[\\]^`{|}~_");
+memcpy((char *)collate+33,
+ "!\42#$%&'()*+,-./:;<=>?@@[\\]^`{|}~_",32);
/* 32 characters + 33 = 65 */
-strcpy(collate+65,"abcdefghijklmnopqrstuvwxyz0123456789");
+memcpy((char *)collate+65,
+ "abcdefghijklmnopqrstuvwxyz0123456789",36);
/* (26 + 10) characters + 65 = 101 */
-strcpy(collate+101,"\200\201\202\203\204\205\206\207\210\211\212\213\214\215\216\217");
+memcpy((char *)collate+101,
+ "\200\201\202\203\204\205\206\207\210\211\212\213\214\215\216\217",16);
/* 16 characters + 101 = 117 */
-strcpy(collate+117,"\220\221\222\223\224\225\226\227\230\231\232\233\234\235\236\237");
+memcpy((char *)collate+117,
+ "\220\221\222\223\224\225\226\227\230\231\232\233\234\235\236\237",16);
/* 16 characters + 117 = 133 */
-strcpy(collate+133,"\240\241\242\243\244\245\246\247\250\251\252\253\254\255\256\257");
+memcpy((char *)collate+133,
+ "\240\241\242\243\244\245\246\247\250\251\252\253\254\255\256\257",16);
/* 16 characters + 133 = 149 */
-strcpy(collate+149,"\260\261\262\263\264\265\266\267\270\271\272\273\274\275\276\277");
+memcpy((char *)collate+149,
+ "\260\261\262\263\264\265\266\267\270\271\272\273\274\275\276\277",16);
/* 16 characters + 149 = 165 */
-strcpy(collate+165,"\300\301\302\303\304\305\306\307\310\311\312\313\314\315\316\317");
+memcpy((char *)collate+165,
+ "\300\301\302\303\304\305\306\307\310\311\312\313\314\315\316\317",16);
/* 16 characters + 165 = 181 */
-strcpy(collate+181,"\320\321\322\323\324\325\326\327\330\331\332\333\334\335\336\337");
+memcpy((char *)collate+181,
+ "\320\321\322\323\324\325\326\327\330\331\332\333\334\335\336\337",16);
/* 16 characters + 181 = 197 */
-strcpy(collate+197,"\340\341\342\343\344\345\346\347\350\351\352\353\354\355\356\357");
+memcpy((char *)collate+197,
+ "\340\341\342\343\344\345\346\347\350\351\352\353\354\355\356\357",16);
/* 16 characters + 197 = 213 */
-strcpy(collate+213,"\360\361\362\363\364\365\366\367\370\371\372\373\374\375\376\377");
+memcpy((char *)collate+213,
+ "\360\361\362\363\364\365\366\367\370\371\372\373\374\375\376\377",16);
/* 16 characters + 213 = 229 */
@ Procedure |unbucket| goes through the buckets and adds nonempty lists
@@ -4471,16 +4517,13 @@ regarded as identical.
@d infinity 255 /* $\infty$ (approximately) */
-@<Predecl...@>=
-void unbucket();
-
-@ @c
-void
-unbucket(d) /* empties buckets having depth |d| */
-eight_bits d;
+@c
+static void
+unbucket(@t\1\1@> /* empties buckets having depth |d| */
+eight_bits d@t\2\2@>)
{
int c; /* index into |bucket|; cannot be a simple |char| because of sign
- comparison below*/
+ comparison below */
for (c=100+128; c>= 0; c--) if (bucket[collate[c]]) {
@^high-bit character handling@>
if (sort_ptr>=scrap_info_end) overflow("sorting");
@@ -4492,13 +4535,15 @@ eight_bits d;
}
}
+@ @<Predecl...@>=@+static void unbucket(eight_bits);
+
@ @<Sort and output...@>=
sort_ptr=scrap_info; unbucket(1);
while (sort_ptr>scrap_info) {
cur_depth=sort_ptr->depth;
if (blink[sort_ptr->head-name_dir]==0 || cur_depth==infinity)
@<Output index entries for the list at |sort_ptr|@>@;
- else @<Split the list at |sort_ptr| into further lists@>;
+ else @<Split the list at |sort_ptr| into further lists@>@;
}
@ @<Split the list...@>= {
@@ -4522,8 +4567,8 @@ while (sort_ptr>scrap_info) {
do {
out_str("\\I");
@.\\I@>
- @<Output the name at |cur_name|@>;
- @<Output the cross-references at |cur_name|@>;
+ @<Output the name at |cur_name|@>@;
+ @<Output the cross-references at |cur_name|@>@;
cur_name=blink[cur_name-name_dir];
} while (cur_name);
--sort_ptr;
@@ -4546,7 +4591,7 @@ lowcase: out_str("\\\\");
@.\\9@>
case typewriter: out_str("\\.");
@.\\.@>
- case roman: not_an_identifier: out_name(cur_name,0); goto name_done;
+ case roman: not_an_identifier: out_name(cur_name,false); goto name_done;
case custom: {char *j; out_str("$\\");
for (j=cur_name->byte_start;j<(cur_name+1)->byte_start;j++)
out(*j=='_'? 'x': *j=='$'? 'X': *j);
@@ -4556,14 +4601,14 @@ lowcase: out_str("\\\\");
default: out_str("\\&");
@.\\\&@>
}
-out_name(cur_name,1);
+out_name(cur_name,true);
name_done:@;
@ Section numbers that are to be underlined are enclosed in
`\.{\\[}$\,\ldots\,$\.]'.
@<Output the cross-references...@>=
-@<Invert the cross-reference list at |cur_name|, making |cur_xref| the head@>;
+@<Invert the cross-reference list at |cur_name|, making |cur_xref| the head@>@;
do {
out_str(", "); cur_val=cur_xref->num;
if (cur_val<def_flag) out_section(cur_val);
@@ -4576,8 +4621,8 @@ out('.'); finish_line();
@ List inversion is best thought of as popping elements off one stack and
pushing them onto another. In this case |cur_xref| will be the head of
the stack that we push things onto.
-@<Global...@>=
-xref_pointer next_xref, this_xref;
+@<Private...@>=
+static xref_pointer next_xref, this_xref;
/* pointer variables for rearranging a list */
@ @<Invert the cross-reference list at |cur_name|, making |cur_xref| the head@>=
@@ -4591,13 +4636,10 @@ do {
prints them.
@^recursion@>
-@<Predecl...@>=
-void section_print();
-
-@ @c
-void
-section_print(p) /* print all section names in subtree |p| */
-name_pointer p;
+@c
+static void
+section_print(@t\1\1@> /* print all section names in subtree |p| */
+name_pointer p@t\2\2@>)
{
if (p) {
section_print(p->llink); out_str("\\I");
@@ -4611,34 +4653,36 @@ name_pointer p;
}
}
-@ @<Output all the section names@>=section_print(root)
+@ @<Predecl...@>=@+static void section_print(name_pointer);
+
+@ @<Output all the section names@>=section_print(root);
-@ Because on some systems the difference between two pointers is a |long|
+@ Because on some systems the difference between two pointers is a |ptrdiff_t|
rather than an |int|, we use \.{\%ld} to print these quantities.
@c
void
-print_stats() {
- printf("\nMemory usage statistics:\n");
+print_stats(void) {
+ puts("\nMemory usage statistics:");
@.Memory usage statistics:@>
printf("%ld names (out of %ld)\n",
- (long)(name_ptr-name_dir),(long)max_names);
+ (ptrdiff_t)(name_ptr-name_dir),(long)max_names);
printf("%ld cross-references (out of %ld)\n",
- (long)(xref_ptr-xmem),(long)max_refs);
+ (ptrdiff_t)(xref_ptr-xmem),(long)max_refs);
printf("%ld bytes (out of %ld)\n",
- (long)(byte_ptr-byte_mem),(long)max_bytes);
- printf("Parsing:\n");
+ (ptrdiff_t)(byte_ptr-byte_mem),(long)max_bytes);
+ puts("Parsing:");
printf("%ld scraps (out of %ld)\n",
- (long)(max_scr_ptr-scrap_info),(long)max_scraps);
+ (ptrdiff_t)(max_scr_ptr-scrap_info),(long)max_scraps);
printf("%ld texts (out of %ld)\n",
- (long)(max_text_ptr-tok_start),(long)max_texts);
+ (ptrdiff_t)(max_text_ptr-tok_start),(long)max_texts);
printf("%ld tokens (out of %ld)\n",
- (long)(max_tok_ptr-tok_mem),(long)max_toks);
+ (ptrdiff_t)(max_tok_ptr-tok_mem),(long)max_toks);
printf("%ld levels (out of %ld)\n",
- (long)(max_stack_ptr-stack),(long)stack_size);
- printf("Sorting:\n");
+ (ptrdiff_t)(max_stack_ptr-stack),(long)stack_size);
+ puts("Sorting:");
printf("%ld levels (out of %ld)\n",
- (long)(max_sort_ptr-scrap_info),(long)max_scraps);
+ (ptrdiff_t)(max_sort_ptr-scrap_info),(long)max_scraps);
}
@** Index.