From 611b225a456949639e46d4ccb7d458761c3dc818 Mon Sep 17 00:00:00 2001 From: Andreas Scherer Date: Fri, 16 Apr 2021 12:49:28 +0000 Subject: [CWEB] New release 4.3. This release introduces new features to CWEB 4: * Former option '-t' is now called '-c'. - New option '-t' for CWEAVE when dealing with 'typename' in C++ templates. - New option '-k' for CTANGLE to keep '-separators in numeric literals. * Support for "variadic macros" along "variadic functions". * @d is printed similar to #define (and vice versa): - '#' is no longer printed in boldface. - Spacing is similar in most cases. * Support for extended C99/C++ numeric literals: - hexadecimal, octal, and -- new! -- binary numbers. - NOTE: 'cwebmac.tex 4.3' is NOT compatible with CWEAVE 4.2 and older and vice versa. * Long parameter lists in ANSI function definitions are indented similar to old-style function parameters. - Option '-i' works similar for old-style and modern function headers. * Additional C99/C++ keywords -- from 'alignas' to 'thread_local' -- are supported internally. * '@i'nclude file 'iso_types.w' for numeric types (in addition to 'c++lib.w'). * Countless code modifications, including some corrections amd improvements. Thanks and cudos to Github user "@texdraft" for numerous contributions to this feature release! git-svn-id: svn://tug.org/texlive/trunk@58884 c570f23f-e606-0410-a88d-b1316a301751 --- Build/source/texk/web2c/cwebdir/common.w | 139 +++++++++++++++---------------- 1 file changed, 65 insertions(+), 74 deletions(-) (limited to 'Build/source/texk/web2c/cwebdir/common.w') diff --git a/Build/source/texk/web2c/cwebdir/common.w b/Build/source/texk/web2c/cwebdir/common.w index 15e93c2c5e6..97e2d50118d 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.2 --- February 2021 +% Version 4.3 --- April 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.2)} +\def\title{Common code for CTANGLE and CWEAVE (Version 4.3)} \def\topofcontents{\null\vfill \centerline{\titlefont Common code for {\ttitlefont CTANGLE} and {\ttitlefont CWEAVE}} \vskip 15pt - \centerline{(Version 4.2)} + \centerline{(Version 4.3)} \vfill} \def\botofcontents{\vfill \noindent @@ -47,10 +47,6 @@ 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 @@ -158,13 +154,13 @@ support |feof|, |getc|, and |ungetc| you may have to change things here. @^system dependencies@> @c -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 */ +static boolean input_ln( /* copies a line into |buffer| or returns |false| */ +FILE *fp) /* 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) @@ -172,7 +168,7 @@ FILE *fp@t\2\2@>) /* 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; } @@ -214,7 +210,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))) @= @@ -293,8 +289,9 @@ either `\.{@@*}' or `\.{@@\ }' (possibly preceded by whitespace). This procedure is called only when |buffer @@ -365,9 +362,9 @@ reset_input(void) { limit=buffer; loc=buffer+1; buffer[0]=' '; @@; - include_depth=0; cur_line=0; change_line=0; + include_depth=cur_line=change_line=0; change_depth=include_depth; - changing=1; prime_the_change_buffer(); changing=!changing; + changing=true; prime_the_change_buffer(); changing=!changing; limit=buffer; loc=buffer+1; buffer[0]=' '; input_has_ended=false; } @@ -408,7 +405,7 @@ boolean get_line(void) /* inputs the next line */ { restart: if (changing && include_depth==change_depth) - @@; + @@; if (! changing || include_depth>change_depth) { @@; if (changing && include_depth==change_depth) goto restart; @@ -451,7 +448,7 @@ The remainder of the \.{@@i} line after the file name is ignored. @.CWEBINPUTS@>@= { char temp_file_name[max_file_name_length]; char *cur_file_name_end=cur_file_name+max_file_name_length-1; - char *k=cur_file_name, *kk; + char *kk, *k=cur_file_name; int l; /* length of file name */ if (*loc=='"') { @@ -483,7 +480,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) { @@ -638,10 +635,10 @@ for (h=hash; h<=hash_end; *h++=NULL) ; @c name_pointer -id_lookup(@t\1\1@> /* looks up a string in the identifier table */ +id_lookup( /* 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@t\2\2@>) /* the |ilk|; used by \.{CWEAVE} only */ +char t) /* the |ilk|; used by \.{CWEAVE} only */ { const char *i=first; /* position in |buffer| */ int h; /* hash code */ @@ -678,6 +675,7 @@ 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. + @= { if (byte_ptr+l>byte_mem_end) overflow("byte memory"); if (name_ptr>=name_dir_end) overflow("name"); @@ -719,11 +717,9 @@ name_pointer p) name_pointer q = p+1; while (p!=name_dir) { ss = (p+1)->byte_start-1; - 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; - } + if (*ss==' ' && ss>=s) p=q->link,q=p; + else ss++,p=name_dir,q=NULL; + term_write(s,(size_t)(ss-s)); s = p->byte_start; } if (q) term_write("...",3); /* complete name not yet known */ @@ -739,11 +735,8 @@ 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; } @@ -773,15 +766,15 @@ are null-terminated, and we keep an eye open for prefixes and extensions. @= static int web_strcmp(char *,int,char *,int);@/ -static name_pointer add_section_name(name_pointer,int,char *,char *,int);@/ -static void extend_section_name(name_pointer,char *,char *,int); +static name_pointer add_section_name(name_pointer,int,char *,char *,boolean);@/ +static void extend_section_name(name_pointer,char *,char *,boolean); @ @c -static int web_strcmp(@t\1\1@> /* fuller comparison than |strcmp| */ +static int web_strcmp( /* 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@t\2\2@>) /* length of second string */ + int k_len) /* length of second string */ { char *j1=j+j_len, *k1=k+k_len; while (k /* install a new node in the tree */ +add_section_name( /* 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 */ -int ispref@t\2\2@>) /* are we adding a prefix or a full name? */ +boolean ispref) /* are we adding a prefix or a full name? */ { name_pointer p=name_ptr; /* new node */ char *s=first_chunk(p); @@ -828,19 +821,18 @@ int ispref@t\2\2@>) /* are we adding a prefix or a full name? */ } set_prefix_length(p,name_len); strncpy(s,first,name_len); - p->llink=NULL; - p->rlink=NULL; + p->llink=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(@t\1\1@> +extend_section_name( name_pointer p, /* name to be extended */ char *first, /* beginning of extension text */ char *last, /* one beyond end of extension text */ -int ispref@t\2\2@>) /* are we adding a prefix or a full name? */ +boolean ispref) /* are we adding a prefix or a full name? */ { char *s; name_pointer q=p+1; @@ -864,11 +856,11 @@ exactly equals or is a prefix or extension of a name in the tree. @c name_pointer -section_lookup(@t\1\1@> /* find or install section name in tree */ +section_lookup( /* find or install section name in tree */ char *first,char *last, /* first and last characters of new name */ -int ispref@t\2\2@>) /* is the new name a prefix or a full name? */ +boolean ispref) /* is the new name a prefix or a full name? */ { - int c=0; /* comparison between two names; initialized so some compilers won't complain */ + int c=less; /* 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 */ @@ -931,16 +923,16 @@ switch(section_name_cmp(&first,name_len,r)) { } else if (name_len print_section_name(r); err_print(">"); - return r; + break; default: /* no match: illegal */ fputs("\n! Section name incompatible with <",stdout); @.Section name incompatible...@> @@ -948,8 +940,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 @@ -968,20 +960,20 @@ us to regard \.{@@} as an ``extension'' of itself. @d bad_extension 5 @c -static int section_name_cmp(@t\1\1@> +static int section_name_cmp( char **pfirst, /* pointer to beginning of comparison string */ int len, /* length of string */ -name_pointer r@t\2\2@>) /* section name being compared */ +name_pointer r) /* 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; /* comparison */ - int ispref; /* is chunk |r| a prefix? */ + int c=less; /* comparison */ + boolean ispref; /* is chunk |r| a prefix? */ while (true) { ss=(r+1)->byte_start-1; - if (*ss==' ' && ss>=r->byte_start) ispref=1,q=q->link; - else ispref=0,ss++,q=name_dir; + 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)) { case equal: if (q==name_dir) if (ispref) { @@ -1023,12 +1015,12 @@ if the string begins with |"!"|. @c void -err_print(@t\1\1@> /* prints `\..' and location of error message */ -const char *s@t\2\2@>) +err_print( /* prints `\..' and location of error message */ +const char *s) { char *k,*l; /* pointers into |buffer| */ printf(*s=='!'? "\n%s" : "%s",s); - if(web_file_open) @@; + if (web_file_open) @@; update_terminal; mark_error; } @@ -1051,7 +1043,7 @@ if (l>buffer) { for (k=buffer; k @c @@ -1085,13 +1077,15 @@ int wrap_up(void) { @ @= 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: puts("(That was a fatal error, my friend.)"); -} /* there are no other cases */ +case fatal_message: default: + puts("(That was a fatal error, my friend.)"); +} @ When there is no way to recover from an error, the |fatal| subroutine is invoked. This happens most often when |overflow| occurs. @@ -1179,14 +1173,13 @@ scan_args(void) if ((**(++argv)=='-'||**argv=='+')&&*(*argv+1)) @@; 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) @@; - else if (!found_change) @@; + |web_file_name|, |tex_file_name|, and |C_file_name|@>@; + else if (!found_change) @@; else if (!found_out) @@; else @@; } @@ -1256,10 +1249,8 @@ after the dot. We must check that there is enough room in @ @d flag_change (**argv!='-') @= -{ - 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; @ @= { -- cgit v1.2.3