Skip to content

Commit

Permalink
CWEB - release 4.5, 2021-07-14.
Browse files Browse the repository at this point in the history
This is a service release for CWEB 4.4:

* Code review with the 'splint' tool.
* All 'length' variables were retyped to 'size_t'.
* A few new bugs were created and fixed.
  • Loading branch information
ascherer committed Jul 14, 2021
1 parent 8beb834 commit bc5703f
Show file tree
Hide file tree
Showing 23 changed files with 372 additions and 354 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This file is part of CWEB.
# It is distributed WITHOUT ANY WARRANTY, express or implied.
# Version 4.4 --- June 2021
# Version 4.5 --- July 2021

# Copyright (C) 1987,1990,1993,2000 Silvio Levy and Donald E. Knuth

Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# cweb 4.4
# cweb 4.5

people have been accumulating several decades of experience with
[cweb](http://www-cs-faculty.stanford.edu/~uno/cweb.html), and we know that
Expand All @@ -19,7 +19,7 @@ details in the
besides for further development, this ‘project’ is used as an – obviously
incomplete – repository of original release versions of levy/knuth
[cweb](http://www-cs-faculty.stanford.edu/~uno/cweb.html). you can either
compile these sources directly or stick the recent version “cweb-4.4” into my
compile these sources directly or stick the recent version “cweb-4.5” into my
[cwebbin](https://github.com/ascherer/cwebbin), which introduces convenient
extensions and prepares cweb for inclusion in the “tex live” distribution.

Expand Down
4 changes: 2 additions & 2 deletions comm-mac.ch
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ No changes to CTANGLE or CWEAVE are needed.
(Contributed 13 Oct 2000 by [email protected]; slightly edited by Don Knuth)
@x in limbo, change the title page document to specify Mac version
\centerline{(Version 4.4)}
\centerline{(Version 4.5)}
@y
\centerline{(Version 4.4 for MacOS)}
\centerline{(Version 4.5 for MacOS)}
@z
@x section 23: Make input_ln accept \n, \r, \n\r, or \r\n as line endings
Expand Down
8 changes: 4 additions & 4 deletions comm-ql.ch
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,24 @@ ex <dev_>cc;'-v -h -c -=500000 -DCWEBINPUTS=flp2_ common_c'
@x
\def\v{\char'174} % vertical (|) in typewriter font

\def\title{Common code for CTANGLE and CWEAVE (Version 4.4)}
\def\title{Common code for CTANGLE and CWEAVE (Version 4.5)}
\def\topofcontents{\null\vfill
\centerline{\titlefont Common code for {\ttitlefont CTANGLE} and
{\ttitlefont CWEAVE}}
\vskip 15pt
\centerline{(Version 4.4)}
\centerline{(Version 4.5)}
\vfill}
\def\botofcontents{\vfill
\noindent
@y
\def\v{\char'174} % vertical (|) in typewriter font
\def\title{Common code for CTANGLE and CWEAVE (QL Version 4.4)}
\def\title{Common code for CTANGLE and CWEAVE (QL Version 4.5)}
\def\topofcontents{\null\vfill
\centerline{\titlefont Common code for {\ttitlefont CTANGLE} and
{\ttitlefont CWEAVE}}
\vskip 15pt
\centerline{(Version 4.4)}
\centerline{(Version 4.5)}
\vfill}
\def\botofcontents{\vfill
\noindent
Expand Down
62 changes: 31 additions & 31 deletions common.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,12 @@

#define compress(c) if(loc++<=limit) return c \

#define xisalpha(c) (isalpha((eight_bits) (c) ) &&((eight_bits) (c) <0200) )
#define xisdigit(c) (isdigit((eight_bits) (c) ) &&((eight_bits) (c) <0200) )
#define xisspace(c) (isspace((eight_bits) (c) ) &&((eight_bits) (c) <0200) )
#define xislower(c) (islower((eight_bits) (c) ) &&((eight_bits) (c) <0200) )
#define xisupper(c) (isupper((eight_bits) (c) ) &&((eight_bits) (c) <0200) )
#define xisxdigit(c) (isxdigit((eight_bits) (c) ) &&((eight_bits) (c) <0200) )
#define xisalpha(c) (isalpha((int) (c) ) &&((eight_bits) (c) <0200) )
#define xisdigit(c) (isdigit((int) (c) ) &&((eight_bits) (c) <0200) )
#define xisspace(c) (isspace((int) (c) ) &&((eight_bits) (c) <0200) )
#define xislower(c) (islower((int) (c) ) &&((eight_bits) (c) <0200) )
#define xisupper(c) (isupper((int) (c) ) &&((eight_bits) (c) <0200) )
#define xisxdigit(c) (isxdigit((int) (c) ) &&((eight_bits) (c) <0200) )
#define isxalpha(c) ((c) =='_'||(c) =='$') \

#define ishigh(c) ((eight_bits) (c) > 0177) \
Expand Down Expand Up @@ -93,24 +93,24 @@
#define max_sections 2000 \

#define lines_dont_match (change_limit-change_buffer!=limit-buffer|| \
strncmp(buffer,change_buffer,(size_t) (limit-buffer) ) ) \
strncmp(buffer,change_buffer,(size_t) (limit-buffer) ) !=0) \

#define if_section_start_make_pending(b) \
*limit= '!'; \
for(loc= buffer;xisspace(*loc) ;loc++) ; \
*limit= ' '; \
if(*loc=='@'&&(xisspace(*(loc+1) ) ||*(loc+1) =='*') ) change_pending= b; \
if(*loc=='@'&&(xisspace(*(loc+1) ) ||*(loc+1) =='*') ) change_pending= b \

#define too_long() {include_depth--; \
err_print("! Include file name too long") ;goto restart;} \

#define hash_size 353 \

#define first_chunk(p) ((p) ->byte_start+2)
#define prefix_length(p) (int) ((eight_bits) *((p) ->byte_start) *256+ \
#define prefix_length(p) (size_t) ((eight_bits) *((p) ->byte_start) *256+ \
(eight_bits) *((p) ->byte_start+1) )
#define set_prefix_length(p,m) (*((p) ->byte_start) = (m) /256, \
*((p) ->byte_start+1) = (m) %256) \
#define set_prefix_length(p,m) (*((p) ->byte_start) = (char) ((m) /256) , \
*((p) ->byte_start+1) = (char) ((m) %256) ) \

#define less 0
#define equal 1
Expand Down Expand Up @@ -344,7 +344,7 @@ extern void reset_input(void);
#line 166 "common.h"

extern boolean names_match(name_pointer,const char*,size_t,eight_bits);
extern name_pointer id_lookup(const char*,const char*,char);
extern name_pointer id_lookup(const char*,const char*,eight_bits);

extern name_pointer section_lookup(char*,char*,boolean);
extern void init_node(name_pointer);
Expand Down Expand Up @@ -382,13 +382,13 @@ static void check_change(void);
/*:33*//*55:*/
#line 764 "common.w"

static int web_strcmp(char*,int,char*,int);
static int web_strcmp(char*,size_t,char*,size_t);
static name_pointer add_section_name(name_pointer,int,char*,char*,boolean);
static void extend_section_name(name_pointer,char*,char*,boolean);

/*:55*//*64:*/
#line 991 "common.w"
static int section_name_cmp(char**,int,name_pointer);
static int section_name_cmp(char**,size_t,name_pointer);

/*:64*//*76:*/
#line 1186 "common.w"
Expand Down Expand Up @@ -484,7 +484,7 @@ change_line++;
if(!input_ln(change_file))return;
if(limit<buffer+2)continue;
if(buffer[0]!='@')continue;
if(xisupper(buffer[1]))buffer[1]= tolower((eight_bits)buffer[1]);
if(xisupper(buffer[1]))buffer[1]= tolower((int)buffer[1]);
if(buffer[1]=='x')break;
if(buffer[1]=='y'||buffer[1]=='z'||buffer[1]=='i'){
loc= buffer+2;
Expand Down Expand Up @@ -544,7 +544,7 @@ change_limit= change_buffer;changing= false;
return;
}
if(limit> buffer+1&&buffer[0]=='@'){
char xyz_code= xisupper(buffer[1])?tolower((eight_bits)buffer[1]):buffer[1];
char xyz_code= xisupper(buffer[1])?tolower((int)buffer[1]):buffer[1];
/*34:*/
#line 336 "common.w"

Expand Down Expand Up @@ -644,7 +644,7 @@ changed_section[section_count]= true;change_pending= false;
}
*limit= ' ';
if(buffer[0]=='@'){
if(xisupper(buffer[1]))buffer[1]= tolower((eight_bits)buffer[1]);
if(xisupper(buffer[1]))buffer[1]= tolower((int)buffer[1]);
if(buffer[1]=='x'||buffer[1]=='y'){
loc= buffer+2;
err_print("! Where is the matching @z?");
Expand Down Expand Up @@ -707,7 +707,7 @@ include_depth++;
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;
int l;
size_t l;

if(*loc=='"'){
loc++;
Expand Down Expand Up @@ -777,18 +777,18 @@ name_pointer
id_lookup(
const char*first,
const char*last,
char t)
eight_bits t)
{
const char*i= first;
int h;
int l;
size_t l;
name_pointer p;
if(last==NULL)for(last= first;*last!='\0';last++);
l= (int)(last-first);
l= (size_t)(last-first);
/*49:*/
#line 656 "common.w"

h= (eight_bits)*i;
h= (int)((eight_bits)*i);
while(++i<last)h= (h+h+(int)((eight_bits)*i))%hash_size;


Expand Down Expand Up @@ -871,7 +871,7 @@ print_prefix_name(
name_pointer p)
{
char*s= first_chunk(p);
int l= prefix_length(p);
size_t l= prefix_length(p);
term_write(s,l);
if(s+l<(p+1)->byte_start)term_write("...",3);
}
Expand All @@ -881,9 +881,9 @@ if(s+l<(p+1)->byte_start)term_write("...",3);

static int web_strcmp(
char*j,
int j_len,
size_t j_len,
char*k,
int k_len)
size_t k_len)
{
char*j1= j+j_len,*k1= k+k_len;
while(k<k1&&j<j1&&*j==*k)k++,j++;
Expand All @@ -907,7 +907,7 @@ boolean ispref)
{
name_pointer p= name_ptr;
char*s= first_chunk(p);
int name_len= (int)(last-first)+ispref;
size_t name_len= (size_t)(last-first+(int)ispref);
if(s+name_len> byte_mem_end)overflow("byte memory");
if(name_ptr+1>=name_dir_end)overflow("name");
(++name_ptr)->byte_start= byte_ptr= s+name_len;
Expand Down Expand Up @@ -936,7 +936,7 @@ boolean ispref)
{
char*s;
name_pointer q= p+1;
int name_len= (int)(last-first)+ispref;
size_t name_len= (size_t)(last-first+(int)ispref);
if(name_ptr>=name_dir_end)overflow("name");
while(q->link!=name_dir)q= q->link;
q->link= name_ptr;
Expand All @@ -962,7 +962,7 @@ name_pointer q= NULL;
name_pointer r= NULL;
name_pointer par= NULL;

int name_len= (int)(last-first)+1;
size_t name_len= (size_t)(last-first+1);
/*60:*/
#line 878 "common.w"

Expand Down Expand Up @@ -1046,7 +1046,7 @@ return r;

static int section_name_cmp(
char**pfirst,
int len,
size_t len,
name_pointer r)
{
char*first= *pfirst;
Expand All @@ -1058,7 +1058,7 @@ 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;
switch(c= web_strcmp(first,len,s,ss-s)){
switch(c= web_strcmp(first,len,s,(size_t)(ss-s))){
case equal:if(q==name_dir)
if(ispref){
*pfirst= first+(ptrdiff_t)(ss-s);
Expand All @@ -1082,7 +1082,7 @@ void
err_print(
const char*s)
{
printf(*s=='!'?"\n%s":"%s",s);
*s=='!'?printf("\n%s",s):printf("%s",s);
if(web_file_open)/*67:*/
#line 1032 "common.w"

Expand Down
16 changes: 8 additions & 8 deletions common.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.4 --- June 2021 (works also with later versions)
% Version 4.5 --- July 2021 (works also with later versions)

% Copyright (C) 1987,1990,1993 Silvio Levy and Donald E. Knuth

Expand Down Expand Up @@ -78,12 +78,12 @@ extern char *id_first; /* where the current identifier begins in the buffer */
extern char *id_loc; /* just after the current identifier in the buffer */

@ Code related to input routines:
@d xisalpha(c) (isalpha((eight_bits)(c))&&((eight_bits)(c)<0200))
@d xisdigit(c) (isdigit((eight_bits)(c))&&((eight_bits)(c)<0200))
@d xisspace(c) (isspace((eight_bits)(c))&&((eight_bits)(c)<0200))
@d xislower(c) (islower((eight_bits)(c))&&((eight_bits)(c)<0200))
@d xisupper(c) (isupper((eight_bits)(c))&&((eight_bits)(c)<0200))
@d xisxdigit(c) (isxdigit((eight_bits)(c))&&((eight_bits)(c)<0200))
@d xisalpha(c) (isalpha((int)(c))&&((eight_bits)(c)<0200))
@d xisdigit(c) (isdigit((int)(c))&&((eight_bits)(c)<0200))
@d xisspace(c) (isspace((int)(c))&&((eight_bits)(c)<0200))
@d xislower(c) (islower((int)(c))&&((eight_bits)(c)<0200))
@d xisupper(c) (isupper((int)(c))&&((eight_bits)(c)<0200))
@d xisxdigit(c) (isxdigit((int)(c))&&((eight_bits)(c)<0200))
@d isxalpha(c) ((c)=='_' || (c)=='$')
/* non-alpha characters allowed in identifier */
@d ishigh(c) ((eight_bits)(c)>0177)
Expand Down Expand Up @@ -165,7 +165,7 @@ extern hash_pointer h; /* index into hash-head array */

@ @<Predecl...@>=
extern boolean names_match(name_pointer,const char *,size_t,eight_bits);@/
extern name_pointer id_lookup(const char *,const char *,char);
extern name_pointer id_lookup(const char *,const char *,eight_bits);
/* looks up a string in the identifier table */
extern name_pointer section_lookup(char *,char *,boolean); /* finds section name */
extern void init_node(name_pointer);@/
Expand Down
Loading

0 comments on commit bc5703f

Please sign in to comment.