From 13e43acae7ae26354649e47b8deae2469fa2c5bb Mon Sep 17 00:00:00 2001 From: Andreas Scherer Date: Fri, 22 Sep 2023 14:22:50 +0000 Subject: [PATCH] [CWEB] Reuse code for secondary output. We try to keep the total section count of CTANGLE (104) intact. git-svn-id: svn://tug.org/texlive/trunk/Build/source@68343 c570f23f-e606-0410-a88d-b1316a301751 --- texk/web2c/cwebdir/ChangeLog | 6 + texk/web2c/cwebdir/ctang-w2c.ch | 16 +- texk/web2c/cwebdir/ctangle.c | 271 +++++++++++++++++--------------- texk/web2c/cwebdir/ctangle.w | 49 +++--- 4 files changed, 183 insertions(+), 159 deletions(-) diff --git a/texk/web2c/cwebdir/ChangeLog b/texk/web2c/cwebdir/ChangeLog index ea87259652..bbf510d7c3 100644 --- a/texk/web2c/cwebdir/ChangeLog +++ b/texk/web2c/cwebdir/ChangeLog @@ -1,3 +1,9 @@ +2023-09-22 Andreas Scherer + + * ctang-w2c.ch, + * ctangle.c, + * ctangle.w: Reuse code for secondary output. + 2023-09-22 Andreas Scherer * cwebacromac.tex: Factor out PDF/HINT macros. diff --git a/texk/web2c/cwebdir/ctang-w2c.ch b/texk/web2c/cwebdir/ctang-w2c.ch index 674f5755c7..6d8d7f411b 100644 --- a/texk/web2c/cwebdir/ctang-w2c.ch +++ b/texk/web2c/cwebdir/ctang-w2c.ch @@ -122,12 +122,8 @@ for (an_output_file=end_output_files; an_output_file>cur_out_file;) { @.Cannot open output file@> if (show_progress) { printf("\n(%s)",output_file_name); update_terminal(); } cur_line=1; - stack_ptr=stack+1; - cur_name=*an_output_file; - cur_repl=(text_pointer)cur_name->equiv; - cur_byte=cur_repl->tok_start; - while (stack_ptr > stack) get_output(); - flush_buffer(); + @@; + @@; } @y @= @@ -147,12 +143,8 @@ for (an_output_file=end_output_files; an_output_file>cur_out_file;) { } if (show_progress) { printf("\n(%s)",output_file_name); update_terminal(); } cur_line=1; - stack_ptr=stack+1; - cur_name=*an_output_file; - cur_repl=(text_pointer)cur_name->equiv; - cur_byte=cur_repl->tok_start; - while (stack_ptr > stack) get_output(); - flush_buffer(); + @@; + @@; if (check_for_change) { fclose(C_file); C_file=NULL; @@; diff --git a/texk/web2c/cwebdir/ctangle.c b/texk/web2c/cwebdir/ctangle.c index 683c5b0c1a..f01fc24f20 100644 --- a/texk/web2c/cwebdir/ctangle.c +++ b/texk/web2c/cwebdir/ctangle.c @@ -305,53 +305,53 @@ static output_state stack[stack_size+2]; static stack_pointer stack_end= stack+stack_size; static stack_pointer stack_ptr; -/*:32*//*37:*/ -#line 357 "ctangle.w" +/*:32*//*38:*/ +#line 367 "ctangle.w" static int cur_val; -/*:37*//*42:*/ -#line 449 "ctangle.w" +/*:38*//*42:*/ +#line 457 "ctangle.w" static eight_bits out_state; static boolean protect; /*:42*//*45:*/ -#line 480 "ctangle.w" +#line 488 "ctangle.w" static name_pointer output_files[max_files]; static name_pointer*cur_out_file,*end_output_files,*an_output_file; static char cur_section_name_char; static char output_file_name[longest_name+1]; -/*:45*//*52:*/ -#line 573 "ctangle.w" +/*:45*//*53:*/ +#line 584 "ctangle.w" static boolean output_defs_seen= false; -/*:52*//*57:*/ -#line 687 "ctangle.w" +/*:53*//*57:*/ +#line 694 "ctangle.w" static char translit[0200][translit_length]; /*:57*//*62:*/ -#line 763 "ctangle.w" +#line 770 "ctangle.w" static eight_bits ccode[256]; /*:62*//*66:*/ -#line 823 "ctangle.w" +#line 830 "ctangle.w" static boolean comment_continues= false; /*:66*//*68:*/ -#line 860 "ctangle.w" +#line 867 "ctangle.w" static name_pointer cur_section_name; static boolean no_where; /*:68*//*82:*/ -#line 1177 "ctangle.w" +#line 1184 "ctangle.w" static text_pointer cur_text; static eight_bits next_control; @@ -399,54 +399,48 @@ extern void print_stats(void); #line 242 "ctangle.w" static void store_two_bytes(sixteen_bits); -/*:30*//*35:*/ -#line 321 "ctangle.w" +/*:30*//*37:*/ +#line 347 "ctangle.w" static void push_level(name_pointer); static void pop_level(boolean); - -/*:35*//*39:*/ -#line 394 "ctangle.w" static void get_output(void); -/*:39*//*44:*/ -#line 470 "ctangle.w" +/*:37*//*44:*/ +#line 478 "ctangle.w" static void flush_buffer(void); /*:44*//*49:*/ -#line 541 "ctangle.w" -static void phase_two(void); - -/*:49*//*53:*/ -#line 576 "ctangle.w" +#line 547 "ctangle.w" +static void phase_two(void); static void output_defs(void); static void out_char(eight_bits); -/*:53*//*65:*/ -#line 803 "ctangle.w" +/*:49*//*65:*/ +#line 810 "ctangle.w" static eight_bits skip_ahead(void); static boolean skip_comment(boolean); /*:65*//*70:*/ -#line 910 "ctangle.w" +#line 917 "ctangle.w" static eight_bits get_next(void); /*:70*//*84:*/ -#line 1203 "ctangle.w" +#line 1210 "ctangle.w" static void scan_repl(eight_bits); /*:84*//*91:*/ -#line 1395 "ctangle.w" +#line 1402 "ctangle.w" static void scan_section(void); /*:91*//*99:*/ -#line 1472 "ctangle.w" +#line 1479 "ctangle.w" static void phase_one(void); /*:99*//*101:*/ -#line 1505 "ctangle.w" +#line 1512 "ctangle.w" static void skip_limbo(void); /*:101*/ @@ -479,12 +473,12 @@ init_node(name_dir); last_unnamed= text_info;text_info->text_link= macro; /*:27*//*46:*/ -#line 490 "ctangle.w" +#line 498 "ctangle.w" cur_out_file= end_output_files= output_files+max_files; /*:46*//*58:*/ -#line 690 "ctangle.w" +#line 697 "ctangle.w" {int i; for(i= 0;i<0200;i++) @@ -492,7 +486,7 @@ snprintf(translit[i],translit_length,"X%02X",(unsigned int)(0200+i)); } /*:58*//*63:*/ -#line 766 "ctangle.w" +#line 773 "ctangle.w" { int c; for(c= 0;c<256;c++)ccode[c]= ignore; @@ -512,7 +506,7 @@ ccode['<']= ccode['(']= section_name; ccode['\'']= ord; /*:63*//*78:*/ -#line 1098 "ctangle.w" +#line 1105 "ctangle.w" section_text[0]= ' '; /*:78*/ @@ -559,8 +553,8 @@ if(tok_ptr+2> tok_mem_end)overflow("token"); *tok_ptr++= x&0377; } -/*:29*//*34:*/ -#line 307 "ctangle.w" +/*:29*//*35:*/ +#line 315 "ctangle.w" static void push_level( @@ -575,8 +569,9 @@ cur_byte= cur_repl->tok_start;cur_section= 0; } } -/*:34*//*36:*/ -#line 329 "ctangle.w" + +/*:35*//*36:*/ +#line 334 "ctangle.w" static void pop_level( @@ -590,8 +585,8 @@ stack_ptr--; if(stack_ptr> stack)cur_state= *stack_ptr; } -/*:36*//*38:*/ -#line 364 "ctangle.w" +/*:36*//*39:*/ +#line 374 "ctangle.w" static void get_output(void) @@ -614,7 +609,7 @@ switch(a/024000){ case 0:cur_val= (int)a;out_char(identifier);break; case 1:if(a==output_defs_flag)output_defs(); else/*40:*/ -#line 399 "ctangle.w" +#line 407 "ctangle.w" { a-= 024000; @@ -628,7 +623,7 @@ goto restart; } /*:40*/ -#line 385 "ctangle.w" +#line 395 "ctangle.w" break; default:cur_val= (int)a-050000; @@ -638,8 +633,8 @@ out_char(section_number); } } -/*:38*//*43:*/ -#line 457 "ctangle.w" +/*:39*//*43:*/ +#line 465 "ctangle.w" static void flush_buffer(void) @@ -654,7 +649,7 @@ cur_line++; } /*:43*//*48:*/ -#line 509 "ctangle.w" +#line 517 "ctangle.w" static void phase_two(void){ @@ -664,20 +659,21 @@ cur_line= 1; /*33:*/ #line 296 "ctangle.w" -stack_ptr= stack+1;cur_name= name_dir;cur_repl= text_info->text_link+text_info; +stack_ptr= stack+1;cur_name= name_dir; +cur_repl= text_info->text_link+text_info; cur_byte= cur_repl->tok_start;cur_section= 0; /*:33*/ -#line 515 "ctangle.w" +#line 523 "ctangle.w" -/*51:*/ -#line 569 "ctangle.w" +/*52:*/ +#line 580 "ctangle.w" if(!output_defs_seen) output_defs(); -/*:51*/ -#line 516 "ctangle.w" +/*:52*/ +#line 524 "ctangle.w" if(text_info->text_link==macro&&cur_out_file==end_output_files){ printf("%s","\n! No program text was specified.");mark_harmless(); @@ -691,12 +687,20 @@ printf(cur_out_file==end_output_files? update_terminal(); } -if(text_info->text_link!=macro){ +if(text_info->text_link!=macro) +/*51:*/ +#line 570 "ctangle.w" + +{ while(stack_ptr> stack)get_output(); flush_buffer(); } + +/*:51*/ +#line 538 "ctangle.w" + /*50:*/ -#line 547 "ctangle.w" +#line 556 "ctangle.w" for(an_output_file= end_output_files;an_output_file> cur_out_file;){ an_output_file--; @@ -707,16 +711,31 @@ fatal("! Cannot open output file ",output_file_name); if(show_progress){printf("\n(%s)",output_file_name);update_terminal();} cur_line= 1; -stack_ptr= stack+1; -cur_name= *an_output_file; +/*34:*/ +#line 303 "ctangle.w" + +stack_ptr= stack+1;cur_name= *an_output_file; cur_repl= (text_pointer)cur_name->equiv; cur_byte= cur_repl->tok_start; + +/*:34*/ +#line 566 "ctangle.w" + +/*51:*/ +#line 570 "ctangle.w" + +{ while(stack_ptr> stack)get_output(); flush_buffer(); } +/*:51*/ +#line 567 "ctangle.w" + +} + /*:50*/ -#line 533 "ctangle.w" +#line 539 "ctangle.w" if(show_happiness){ if(show_progress)new_line(); @@ -726,7 +745,7 @@ printf("%s","Done."); } /*:48*//*54:*/ -#line 585 "ctangle.w" +#line 592 "ctangle.w" static void output_defs(void) @@ -766,7 +785,7 @@ pop_level(false); } /*:54*//*55:*/ -#line 628 "ctangle.w" +#line 635 "ctangle.w" static void out_char( @@ -779,7 +798,7 @@ case'\n':if(protect&&out_state!=verbatim)C_putc(' '); if(protect||out_state==verbatim)C_putc('\\'); flush_buffer();if(out_state!=verbatim)out_state= normal;break; /*59:*/ -#line 696 "ctangle.w" +#line 703 "ctangle.w" case identifier: if(out_state==num_or_id)C_putc(' '); @@ -791,10 +810,10 @@ else C_printf("%s",translit[(eight_bits)(*j)-0200]); out_state= num_or_id;break; /*:59*/ -#line 639 "ctangle.w" +#line 646 "ctangle.w" /*60:*/ -#line 706 "ctangle.w" +#line 713 "ctangle.w" case section_number: if(cur_val> 0)C_printf("/*%d:*/",cur_val); @@ -821,10 +840,10 @@ C_putc('"');C_putc('\n'); break; /*:60*/ -#line 640 "ctangle.w" +#line 647 "ctangle.w" /*56:*/ -#line 658 "ctangle.w" +#line 665 "ctangle.w" case plus_plus:C_putc('+');C_putc('+');out_state= normal;break; case minus_minus:C_putc('-');C_putc('-');out_state= normal;break; @@ -845,7 +864,7 @@ case minus_gt_ast:C_putc('-');C_putc('>');C_putc('*');out_state= normal; break; /*:56*/ -#line 641 "ctangle.w" +#line 648 "ctangle.w" case'=':case'>':C_putc(cur_char);C_putc(' '); out_state= normal;break; @@ -864,7 +883,7 @@ default:C_putc(cur_char);out_state= normal;break; } /*:55*//*64:*/ -#line 787 "ctangle.w" +#line 794 "ctangle.w" static eight_bits skip_ahead(void) @@ -882,7 +901,7 @@ if(c!=ignore||*(loc-1)=='>')return c; } /*:64*//*67:*/ -#line 826 "ctangle.w" +#line 833 "ctangle.w" static boolean skip_comment( boolean is_long_comment) @@ -916,7 +935,7 @@ else loc++; } /*:67*//*69:*/ -#line 867 "ctangle.w" +#line 874 "ctangle.w" static eight_bits get_next(void) @@ -930,7 +949,7 @@ if(get_line()==false)return new_section; else if(print_where&&!no_where){ print_where= false; /*85:*/ -#line 1213 "ctangle.w" +#line 1220 "ctangle.w" { eight_bits a; @@ -947,7 +966,7 @@ store_id(a); } /*:85*/ -#line 879 "ctangle.w" +#line 886 "ctangle.w" } else return(eight_bits)'\n'; @@ -960,7 +979,7 @@ else continue; } loc++; if(xisdigit(c)||c=='.')/*73:*/ -#line 951 "ctangle.w" +#line 958 "ctangle.w" { boolean hex_flag= false; id_first= loc-1; @@ -994,13 +1013,13 @@ return constant; } /*:73*/ -#line 890 "ctangle.w" +#line 897 "ctangle.w" else if(c=='\''||c=='"' ||((c=='L'||c=='u'||c=='U')&&(*loc=='\''||*loc=='"')) ||((c=='u'&&*loc=='8')&&(*(loc+1)=='\''||*(loc+1)=='"'))) /*74:*/ -#line 988 "ctangle.w" +#line 995 "ctangle.w" { char delim= (char)c; id_first= section_text+1; @@ -1044,11 +1063,11 @@ return string; } /*:74*/ -#line 894 "ctangle.w" +#line 901 "ctangle.w" else if(isalpha((int)c)||isxalpha(c)||ishigh(c)) /*72:*/ -#line 942 "ctangle.w" +#line 949 "ctangle.w" { id_first= --loc; do @@ -1059,10 +1078,10 @@ id_loc= loc;return identifier; } /*:72*/ -#line 896 "ctangle.w" +#line 903 "ctangle.w" else if(c=='@')/*75:*/ -#line 1033 "ctangle.w" +#line 1040 "ctangle.w" switch(c= ccode[(eight_bits)*loc++]){ case ignore:continue; @@ -1077,11 +1096,11 @@ continue; case section_name: cur_section_name_char= *(loc-1); /*77:*/ -#line 1078 "ctangle.w" +#line 1085 "ctangle.w" { char*k= section_text; /*79:*/ -#line 1100 "ctangle.w" +#line 1107 "ctangle.w" while(true){ if(loc> limit&&get_line()==false){ @@ -1091,7 +1110,7 @@ loc= buffer+1;break; } c= (eight_bits)*loc; /*80:*/ -#line 1123 "ctangle.w" +#line 1130 "ctangle.w" if(c=='@'){ c= (eight_bits)*(loc+1); @@ -1110,7 +1129,7 @@ err_print("! Nesting of section names not allowed");break; } /*:80*/ -#line 1108 "ctangle.w" +#line 1115 "ctangle.w" loc++;if(k section_text)k--; /*:79*/ -#line 1080 "ctangle.w" +#line 1087 "ctangle.w" if(k-section_text> 3&&strncmp(k-2,"...",3)==0) cur_section_name= section_lookup(section_text+1,k-3,true); @@ -1136,7 +1155,7 @@ else cur_section_name= section_lookup(section_text+1,k,false); if(cur_section_name_char=='(') /*47:*/ -#line 494 "ctangle.w" +#line 502 "ctangle.w" { for(an_output_file= cur_out_file; @@ -1150,16 +1169,16 @@ else overflow("output files"); } /*:47*/ -#line 1088 "ctangle.w" +#line 1095 "ctangle.w" return section_name; } /*:77*/ -#line 1046 "ctangle.w" +#line 1053 "ctangle.w" case string:/*81:*/ -#line 1145 "ctangle.w" +#line 1152 "ctangle.w" id_first= loc++;*(limit+1)= '@';*(limit+2)= '>'; while(*loc!='@'||*(loc+1)!='>')loc++; @@ -1169,10 +1188,10 @@ id_loc= loc;loc+= 2; return string; /*:81*/ -#line 1047 "ctangle.w" +#line 1054 "ctangle.w" case ord:/*76:*/ -#line 1058 "ctangle.w" +#line 1065 "ctangle.w" id_first= loc; if(*loc=='\\') @@ -1194,13 +1213,13 @@ loc++; return ord; /*:76*/ -#line 1048 "ctangle.w" +#line 1055 "ctangle.w" default:return c; } /*:75*/ -#line 897 "ctangle.w" +#line 904 "ctangle.w" else if(xisspace(c)){ if(!preprocessing||loc> limit)continue; @@ -1210,7 +1229,7 @@ else return(eight_bits)' '; } else if(c=='#'&&loc==buffer+1)preprocessing= true; mistake:/*71:*/ -#line 919 "ctangle.w" +#line 926 "ctangle.w" switch(c){ case'+':if(*loc=='+')compress(plus_plus);break; @@ -1235,14 +1254,14 @@ case'!':if(*loc=='=')compress(non_eq);break; } /*:71*/ -#line 905 "ctangle.w" +#line 912 "ctangle.w" return c; } } /*:69*//*83:*/ -#line 1181 "ctangle.w" +#line 1188 "ctangle.w" static void scan_repl( @@ -1250,7 +1269,7 @@ eight_bits t) { sixteen_bits a; if(t==section_name)/*85:*/ -#line 1213 "ctangle.w" +#line 1220 "ctangle.w" { eight_bits a; @@ -1267,11 +1286,11 @@ store_id(a); } /*:85*/ -#line 1187 "ctangle.w" +#line 1194 "ctangle.w" while(true)switch(a= get_next()){ /*86:*/ -#line 1228 "ctangle.w" +#line 1235 "ctangle.w" case identifier:store_id(a); if(*buffer=='#'&&( @@ -1284,7 +1303,7 @@ break; case section_name:if(t!=section_name)goto done; else{ /*87:*/ -#line 1269 "ctangle.w" +#line 1276 "ctangle.w" { char*try_loc= loc; while(*try_loc==' '&&try_loctok_start= tok_ptr; } /*:83*//*90:*/ -#line 1362 "ctangle.w" +#line 1369 "ctangle.w" static void scan_section(void) @@ -1465,7 +1484,7 @@ printf("*%d",(int)section_count);update_terminal(); next_control= ignore; while(true){ /*92:*/ -#line 1403 "ctangle.w" +#line 1410 "ctangle.w" while(next_controltext_link= macro; /*:93*/ -#line 1378 "ctangle.w" +#line 1385 "ctangle.w" continue; } @@ -1504,14 +1523,14 @@ p= name_dir;break; if(next_control==section_name){ p= cur_section_name; /*94:*/ -#line 1432 "ctangle.w" +#line 1439 "ctangle.w" while((next_control= get_next())=='+'); if(next_control!='='&&next_control!=eq_eq) continue; /*:94*/ -#line 1386 "ctangle.w" +#line 1393 "ctangle.w" break; } @@ -1519,20 +1538,20 @@ return; } no_where= print_where= false; /*95:*/ -#line 1437 "ctangle.w" +#line 1444 "ctangle.w" /*96:*/ -#line 1442 "ctangle.w" +#line 1449 "ctangle.w" store_two_bytes((sixteen_bits)(0150000+section_count)); /*:96*/ -#line 1438 "ctangle.w" +#line 1445 "ctangle.w" scan_repl(section_name); /*97:*/ -#line 1446 "ctangle.w" +#line 1453 "ctangle.w" if(p==name_dir||p==NULL){ last_unnamed->text_link= cur_text-text_info;last_unnamed= cur_text; @@ -1549,16 +1568,16 @@ cur_text->text_link= section_flag; /*:97*/ -#line 1440 "ctangle.w" +#line 1447 "ctangle.w" /*:95*/ -#line 1392 "ctangle.w" +#line 1399 "ctangle.w" } /*:90*//*98:*/ -#line 1461 "ctangle.w" +#line 1468 "ctangle.w" static void phase_one(void){ @@ -1571,7 +1590,7 @@ check_complete(); } /*:98*//*100:*/ -#line 1477 "ctangle.w" +#line 1484 "ctangle.w" static void skip_limbo(void) @@ -1585,7 +1604,7 @@ char c= *loc++; switch(ccode[(eight_bits)c]){ case new_section:return; case translit_code:/*102:*/ -#line 1507 "ctangle.w" +#line 1514 "ctangle.w" while(xisspace(*loc)&&loc= -stack_ptr=stack+1; cur_name=name_dir; cur_repl=text_info->text_link+text_info; +stack_ptr=stack+1; cur_name=name_dir; +cur_repl=text_info->text_link+text_info; cur_byte=cur_repl->tok_start; cur_section=0; +@ Similar settings are used for secondary output files. + +@= +stack_ptr=stack+1; cur_name=*an_output_file; +cur_repl=(text_pointer)cur_name->equiv; +cur_byte=cur_repl->tok_start; + @ When the replacement text for name |p| is to be inserted into the output, the following subroutine is called to save the old level of output and get the new one going. @@ -318,9 +326,6 @@ name_pointer p) } } -@ @= -static void push_level(name_pointer);@/ -static void pop_level(boolean); @ When we come to the end of a replacement text, the |pop_level| subroutine does the right thing: It either moves to the continuation of this replacement @@ -339,6 +344,11 @@ boolean flag) /* |flag==false| means we are in |output_defs| */ if (stack_ptr>stack) cur_state=*stack_ptr;@^system dependencies@> } +@ @= +static void push_level(name_pointer);@/ +static void pop_level(boolean);@/ +static void get_output(void); + @ The heart of the output procedure is the function |get_output|, which produces the next token of output and sends it on to the lower-level function |out_char|. The main purpose of |get_output| is to handle the @@ -391,8 +401,6 @@ get_output(void) /* sends next token to |out_char| */ } } -@ @=@+static void get_output(void); - @ The user may have forgotten to give any \CEE/ text for a section name, or the \CEE/ text may have been associated with a different name by mistake. @@ -526,10 +534,8 @@ phase_two (void) { @.Writing the output...@> update_terminal(); } - if (text_info->text_link!=macro) { - while (stack_ptr>stack) get_output(); - flush_buffer(); - } + if (text_info->text_link!=macro) + @@; @@; if (show_happiness) { if (show_progress) new_line(); @@ -538,7 +544,10 @@ phase_two (void) { } } -@ @=@+static void phase_two(void); +@ @= +static void phase_two(void);@/ +static void output_defs(void);@/ +static void out_char(eight_bits); @ To write the named output files, we proceed as for the unnamed section. @@ -554,12 +563,14 @@ for (an_output_file=end_output_files; an_output_file>cur_out_file;) { @.Cannot open output file@> if (show_progress) { printf("\n(%s)",output_file_name); update_terminal(); } cur_line=1; - stack_ptr=stack+1; - cur_name=*an_output_file; - cur_repl=(text_pointer)cur_name->equiv; - cur_byte=cur_repl->tok_start; - while (stack_ptr > stack) get_output(); - flush_buffer(); + @@; + @@; +} + +@ @= +{ + while (stack_ptr>stack) get_output(); + flush_buffer(); } @ If a \.{@@h} was not encountered in the input, @@ -573,10 +584,6 @@ that refer to macros, preceded by the \.{\#define} preprocessor command. @ @= static boolean output_defs_seen=false; -@ @= -static void output_defs(void);@/ -static void out_char(eight_bits); - @ @d macro_end (cur_text+1)->tok_start /* end of |macro| replacement text */ @# @d C_printf(c,a) fprintf(C_file,c,a)