summaryrefslogtreecommitdiff
path: root/Build/source/texk/web2c/cwebdir/common.w
diff options
context:
space:
mode:
authorAndreas Scherer <andreas_tex@freenet.de>2021-05-02 13:12:20 +0000
committerAndreas Scherer <andreas_tex@freenet.de>2021-05-02 13:12:20 +0000
commitd28619b4358aaa5c7ae210ce855df17e80b042a5 (patch)
tree96141dd0510f9501c56e1b3b0f5331179bd3fff9 /Build/source/texk/web2c/cwebdir/common.w
parentac2076a1c1574e8973c41270faf9064b46fd5130 (diff)
Revert "[CWEB] New release 4.3."
This reverts commit 3ccac2a7d0f4a19dde861c6f4c178e853d90f0cc. CWEB 4.3 is seriously broken. git-svn-id: svn://tug.org/texlive/trunk@59048 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Build/source/texk/web2c/cwebdir/common.w')
-rw-r--r--Build/source/texk/web2c/cwebdir/common.w139
1 files changed, 74 insertions, 65 deletions
diff --git a/Build/source/texk/web2c/cwebdir/common.w b/Build/source/texk/web2c/cwebdir/common.w
index 97e2d50118d..15e93c2c5e6 100644
--- a/Build/source/texk/web2c/cwebdir/common.w
+++ b/Build/source/texk/web2c/cwebdir/common.w
@@ -2,7 +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 4.3 --- April 2021
+% Version 4.2 --- February 2021
% Copyright (C) 1987,1990,1993,2000 Silvio Levy and Donald E. Knuth
@@ -22,12 +22,12 @@
\def\v{\char'174} % vertical (|) in typewriter font
-\def\title{Common code for CTANGLE and CWEAVE (Version 4.3)}
+\def\title{Common code for CTANGLE and CWEAVE (Version 4.2)}
\def\topofcontents{\null\vfill
\centerline{\titlefont Common code for {\ttitlefont CTANGLE} and
{\ttitlefont CWEAVE}}
\vskip 15pt
- \centerline{(Version 4.3)}
+ \centerline{(Version 4.2)}
\vfill}
\def\botofcontents{\vfill
\noindent
@@ -47,6 +47,10 @@ under the terms of a permission notice identical to this one.
\pageno=\contentspagenumber \advance\pageno by 1
\let\maybe=\iftrue
+@s boolean int
+@s uint8_t int
+@s uint16_t int
+
@** Introduction. This file contains code common
to both \.{CTANGLE} and \.{CWEAVE}, which roughly concerns the following
problems: character uniformity, input routines, error handling and
@@ -154,13 +158,13 @@ support |feof|, |getc|, and |ungetc| you may have to change things here.
@^system dependencies@>
@c
-static boolean input_ln( /* copies a line into |buffer| or returns |false| */
-FILE *fp) /* what file to read from */
+static boolean input_ln(@t\1\1@> /* copies a line into |buffer| or returns |false| */
+FILE *fp@t\2\2@>) /* what file to read from */
{
- register int c=EOF; /* character read; initialized so some compilers won't complain */
- register char *k; /* where next character goes */
- if (feof(fp)) return false; /* we have hit end-of-file */
- limit = k = buffer; /* beginning of buffer */
+ register int c=EOF; /* character read; initialized so some compilers won't complain */
+ register char *k; /* where next character goes */
+ if (feof(fp)) return false; /* we have hit end-of-file */
+ limit = k = buffer; /* beginning of buffer */
while (k<=buffer_end && (c=getc(fp)) != EOF && c!='\n')
if ((*(k++) = c) != ' ') limit = k;
if (k>buffer_end)
@@ -168,7 +172,7 @@ FILE *fp) /* what file to read from */
ungetc(c,fp); loc=buffer; err_print("! Input line too long");
@.Input line too long@>
}
- if (c==EOF && limit==buffer) return false; /* there was nothing after
+ if (c==EOF && limit==buffer) return false; /* there was nothing after
the last newline */
return true;
}
@@ -210,7 +214,7 @@ so that no further matches will be made.
Here's a shorthand expression for inequality between the two lines:
-@d lines_dont_match (change_limit-change_buffer != limit-buffer @| ||
+@d lines_dont_match (change_limit-change_buffer != limit-buffer || @|
strncmp(buffer, change_buffer, (size_t)(limit-buffer)))
@<Global var...@>=
@@ -289,9 +293,8 @@ either `\.{@@*}' or `\.{@@\ }' (possibly preceded by whitespace).
This procedure is called only when |buffer<limit|, i.e., when the
current line is nonempty.
-@d if_section_start_make_pending(b) {
- *limit='!';@+
- for (loc=buffer;xisspace(*loc);loc++) ;@+
+@d if_section_start_make_pending(b) {@+*limit='!';
+ for (loc=buffer;xisspace(*loc);loc++) ;
*limit=' ';
if (*loc=='@@' && (xisspace(*(loc+1)) || *(loc+1)=='*')) change_pending=b;
}
@@ -308,7 +311,7 @@ check_change(void) /* switches to |change_file| if the buffers match */
if (!change_pending) changed_section[section_count]=true;
}
while (true) {
- changing=print_where=true; change_line++;
+ changing=true; print_where=true; change_line++;
if (!input_ln(change_file)) {
err_print("! Change file ended before @@y");
@.Change file ended...@>
@@ -362,9 +365,9 @@ reset_input(void)
{
limit=buffer; loc=buffer+1; buffer[0]=' ';
@<Open input files@>@;
- include_depth=cur_line=change_line=0;
+ include_depth=0; cur_line=0; change_line=0;
change_depth=include_depth;
- changing=true; prime_the_change_buffer(); changing=!changing;
+ changing=1; prime_the_change_buffer(); changing=!changing;
limit=buffer; loc=buffer+1; buffer[0]=' '; input_has_ended=false;
}
@@ -405,7 +408,7 @@ boolean get_line(void) /* inputs the next line */
{
restart:
if (changing && include_depth==change_depth)
- @<Read from |change_file| and maybe turn off |changing|@>@;
+ @<Read from |change_file| and maybe turn off |changing|@>@;
if (! changing || include_depth>change_depth) {
@<Read from |cur_file| and maybe turn on |changing|@>@;
if (changing && include_depth==change_depth) goto restart;
@@ -448,7 +451,7 @@ The remainder of the \.{@@i} line after the file name is ignored.
@.CWEBINPUTS@>@<Try to open...@>= {
char temp_file_name[max_file_name_length];
char *cur_file_name_end=cur_file_name+max_file_name_length-1;
- char *kk, *k=cur_file_name;
+ char *k=cur_file_name, *kk;
int l; /* length of file name */
if (*loc=='"') {
@@ -480,7 +483,7 @@ The remainder of the \.{@@i} line after the file name is ignored.
if (l>0) {
if (k+l+2>=cur_file_name_end) too_long();
@.Include file name ...@>
- for (; k>=cur_file_name; k--) *(k+l+1)=*k;
+ for (; k>= cur_file_name; k--) *(k+l+1)=*k;
strcpy(cur_file_name,temp_file_name);
cur_file_name[l]='/'; /* \UNIX/ pathname separator */
if ((cur_file=fopen(cur_file_name,"r"))!=NULL) {
@@ -635,10 +638,10 @@ for (h=hash; h<=hash_end; *h++=NULL) ;
@c
name_pointer
-id_lookup( /* looks up a string in the identifier table */
+id_lookup(@t\1\1@> /* looks up a string in the identifier table */
const char *first, /* first character of string */
const char *last, /* last character of string plus one */
-char t) /* the |ilk|; used by \.{CWEAVE} only */
+char t@t\2\2@>) /* the |ilk|; used by \.{CWEAVE} only */
{
const char *i=first; /* position in |buffer| */
int h; /* hash code */
@@ -675,7 +678,6 @@ if (p==NULL) {
@ The information associated with a new identifier must be initialized
in a slightly different way in \.{CWEAVE} than in \.{CTANGLE}; hence the
|init_p| procedure.
-
@<Enter a new name...@>= {
if (byte_ptr+l>byte_mem_end) overflow("byte memory");
if (name_ptr>=name_dir_end) overflow("name");
@@ -717,9 +719,11 @@ name_pointer p)
name_pointer q = p+1;
while (p!=name_dir) {
ss = (p+1)->byte_start-1;
- if (*ss==' ' && ss>=s) p=q->link,q=p;
- else ss++,p=name_dir,q=NULL;
- term_write(s,(size_t)(ss-s));
+ if (*ss==' ' && ss>=s) {
+ term_write(s,(size_t)(ss-s)); p=q->link; q=p;
+ } else {
+ term_write(s,(size_t)(ss+1-s)); p=name_dir; q=NULL;
+ }
s = p->byte_start;
}
if (q) term_write("...",3); /* complete name not yet known */
@@ -735,8 +739,11 @@ sprint_section_name(
name_pointer q = p+1;
while (p!=name_dir) {
ss = (p+1)->byte_start-1;
- if (*ss==' ' && ss>=s) p=q->link,q=p;
- else ss++,p=name_dir;
+ if (*ss==' ' && ss>=s) {
+ p=q->link; q=p;
+ } else {
+ ss++; p=name_dir;
+ }
strncpy(dest,s,(size_t)(ss-s)), dest+=ss-s;
s = p->byte_start;
}
@@ -766,15 +773,15 @@ are null-terminated, and we keep an eye open for prefixes and extensions.
@<Predecl...@>=
static int web_strcmp(char *,int,char *,int);@/
-static name_pointer add_section_name(name_pointer,int,char *,char *,boolean);@/
-static void extend_section_name(name_pointer,char *,char *,boolean);
+static name_pointer add_section_name(name_pointer,int,char *,char *,int);@/
+static void extend_section_name(name_pointer,char *,char *,int);
@ @c
-static int web_strcmp( /* fuller comparison than |strcmp| */
+static int web_strcmp(@t\1\1@> /* fuller comparison than |strcmp| */
char *j, /* beginning of first string */
int j_len, /* length of first string */
char *k, /* beginning of second string */
- int k_len) /* length of second string */
+ int k_len@t\2\2@>) /* length of second string */
{
char *j1=j+j_len, *k1=k+k_len;
while (k<k1 && j<j1 && *j==*k) k++, j++;
@@ -800,12 +807,12 @@ and \.{ctangle.w}.
@c
static name_pointer
-add_section_name( /* install a new node in the tree */
+add_section_name(@t\1\1@> /* install a new node in the tree */
name_pointer par, /* parent of new node */
int c, /* right or left? */
char *first, /* first character of section name */
char *last, /* last character of section name, plus one */
-boolean ispref) /* are we adding a prefix or a full name? */
+int ispref@t\2\2@>) /* are we adding a prefix or a full name? */
{
name_pointer p=name_ptr; /* new node */
char *s=first_chunk(p);
@@ -821,18 +828,19 @@ boolean ispref) /* are we adding a prefix or a full name? */
}
set_prefix_length(p,name_len);
strncpy(s,first,name_len);
- p->llink=p->rlink=NULL;
+ p->llink=NULL;
+ p->rlink=NULL;
init_node(p);
return par==NULL ? (root=p) : c==less ? (par->llink=p) : (par->rlink=p);
}
@ @c
static void
-extend_section_name(
+extend_section_name(@t\1\1@>
name_pointer p, /* name to be extended */
char *first, /* beginning of extension text */
char *last, /* one beyond end of extension text */
-boolean ispref) /* are we adding a prefix or a full name? */
+int ispref@t\2\2@>) /* are we adding a prefix or a full name? */
{
char *s;
name_pointer q=p+1;
@@ -856,11 +864,11 @@ exactly equals or is a prefix or extension of a name in the tree.
@c
name_pointer
-section_lookup( /* find or install section name in tree */
+section_lookup(@t\1\1@> /* find or install section name in tree */
char *first,char *last, /* first and last characters of new name */
-boolean ispref) /* is the new name a prefix or a full name? */
+int ispref@t\2\2@>) /* is the new name a prefix or a full name? */
{
- int c=less; /* comparison between two names; initialized so some compilers won't complain */
+ int c=0; /* comparison between two names; initialized so some compilers won't complain */
name_pointer p=root; /* current node of the search tree */
name_pointer q=NULL; /* another place to look in the tree */
name_pointer r=NULL; /* where a match has been found */
@@ -923,16 +931,16 @@ switch(section_name_cmp(&first,name_len,r)) {
}
else if (name_len<prefix_length(r)) set_prefix_length(r,name_len);
/* fall through */
- case equal: break;
+ case equal: return r;
case extension: if (!ispref || first<=last)
extend_section_name(r,first,last+1,ispref);
- break;
+ return r;
case bad_extension:
fputs("\n! New name extends <",stdout);
@.New name extends...@>
print_section_name(r);
err_print(">");
- break;
+ return r;
default: /* no match: illegal */
fputs("\n! Section name incompatible with <",stdout);
@.Section name incompatible...@>
@@ -940,8 +948,8 @@ switch(section_name_cmp(&first,name_len,r)) {
fputs(">,\n which abbreviates <",stdout);
print_section_name(r);
err_print(">");
+ return r;
}
-return r;
@ The return codes of |section_name_cmp|, which compares a string with
the full name of a section, are those of |web_strcmp| plus
@@ -960,20 +968,20 @@ us to regard \.{@@<foo...@@>} as an ``extension'' of itself.
@d bad_extension 5
@c
-static int section_name_cmp(
+static int section_name_cmp(@t\1\1@>
char **pfirst, /* pointer to beginning of comparison string */
int len, /* length of string */
-name_pointer r) /* section name being compared */
+name_pointer r@t\2\2@>) /* section name being compared */
{
char *first=*pfirst; /* beginning of comparison string */
name_pointer q=r+1; /* access to subsequent chunks */
char *ss, *s=first_chunk(r);
- int c=less; /* comparison */
- boolean ispref; /* is chunk |r| a prefix? */
+ int c; /* comparison */
+ int ispref; /* is chunk |r| a prefix? */
while (true) {
ss=(r+1)->byte_start-1;
- if (*ss==' ' && ss>=r->byte_start) ispref=true,q=q->link;
- else ispref=false,ss++,q=name_dir;
+ if (*ss==' ' && ss>=r->byte_start) ispref=1,q=q->link;
+ else ispref=0,ss++,q=name_dir;
switch(c=web_strcmp(first,len,s,ss-s)) {
case equal: if (q==name_dir)
if (ispref) {
@@ -1015,12 +1023,12 @@ if the string begins with |"!"|.
@c
void
-err_print( /* prints `\..' and location of error message */
-const char *s)
+err_print(@t\1\1@> /* prints `\..' and location of error message */
+const char *s@t\2\2@>)
{
char *k,*l; /* pointers into |buffer| */
printf(*s=='!'? "\n%s" : "%s",s);
- if (web_file_open) @<Print error location based on input buffer@>@;
+ if(web_file_open) @<Print error location based on input buffer@>@;
update_terminal; mark_error;
}
@@ -1043,7 +1051,7 @@ if (l>buffer) {
for (k=buffer; k<l; k++)
if (*k=='\t') putchar(' ');
else putchar(*k); /* print the characters already read */
- new_line;
+ putchar('\n');
for (k=buffer; k<l; k++) putchar(' '); /* space out the next line */
}
for (k=l; k<limit; k++) putchar(*k); /* print the part not yet read */
@@ -1062,7 +1070,7 @@ interface above and in the index.
Some implementations may wish to pass the |history| value to the
operating system so that it can be used to govern whether or not other
programs are started. Here, for instance, we pass the operating system
-a status of |EXIT_SUCCESS| if and only if only harmless messages were printed.
+a status of 0 if and only if only harmless messages were printed.
@^system dependencies@>
@c
@@ -1077,15 +1085,13 @@ int wrap_up(void) {
@ @<Print the job |history|@>=
switch (history) {
-case spotless:
- if (show_happiness) puts("(No errors were found.)"); break;
+case spotless: if (show_happiness) puts("(No errors were found.)"); break;
case harmless_message:
puts("(Did you see the warning message above?)"); break;
case error_message:
puts("(Pardon me, but I think I spotted something wrong.)"); break;
-case fatal_message: default:
- puts("(That was a fatal error, my friend.)");
-}
+case fatal_message: puts("(That was a fatal error, my friend.)");
+} /* there are no other cases */
@ When there is no way to recover from an error, the |fatal| subroutine is
invoked. This happens most often when |overflow| occurs.
@@ -1173,13 +1179,14 @@ scan_args(void)
if ((**(++argv)=='-'||**argv=='+')&&*(*argv+1)) @<Handle flag argument@>@;
else {
s=name_pos=*argv;@+dot_pos=NULL;
- while (*s)
+ while (*s) {
if (*s=='.') dot_pos=s++;
else if (*s=='/') dot_pos=NULL,name_pos=++s;
else s++;
+ }
if (!found_web) @<Make
- |web_file_name|, |tex_file_name|, and |C_file_name|@>@;
- else if (!found_change) @<Make |change_file_name|@>@;
+ |web_file_name|, |tex_file_name|, and |C_file_name|@>@;
+ else if (!found_change) @<Make |change_file_name| from |fname|@>@;
else if (!found_out) @<Override |tex_file_name| and |C_file_name|@>@;
else @<Print usage error message and quit@>@;
}
@@ -1249,8 +1256,10 @@ after the dot. We must check that there is enough room in
@ @d flag_change (**argv!='-')
@<Handle flag...@>=
-for(dot_pos=*argv+1;*dot_pos>'\0';dot_pos++)
- flags[(eight_bits)*dot_pos]=flag_change;
+{
+ for(dot_pos=*argv+1;*dot_pos>'\0';dot_pos++)
+ flags[(eight_bits)*dot_pos]=flag_change;
+}
@ @<Print usage error message and quit@>=
{