From dcffc88047986d7e90c01f4c7be906967e70f201 Mon Sep 17 00:00:00 2001 From: Andreas Scherer Date: Mon, 25 Sep 2023 15:15:18 +0000 Subject: [PATCH] [CWEB] Check for available input. If, for example, the name of a changefile is misspelled, you'd get '(l. 0)' and an extra linebreak. git-svn-id: svn://tug.org/texlive/trunk/Build/source@68365 c570f23f-e606-0410-a88d-b1316a301751 --- texk/web2c/cwebboot.cin | 190 +++++++++++++++++---------------- texk/web2c/cwebdir/ChangeLog | 6 ++ texk/web2c/cwebdir/comm-w2c.ch | 6 +- texk/web2c/cwebdir/common.c | 64 +++++------ texk/web2c/cwebdir/common.w | 6 +- 5 files changed, 143 insertions(+), 129 deletions(-) diff --git a/texk/web2c/cwebboot.cin b/texk/web2c/cwebboot.cin index d354b6b23e..0e8c22b666 100644 --- a/texk/web2c/cwebboot.cin +++ b/texk/web2c/cwebboot.cin @@ -26,20 +26,20 @@ #line 75 "cwebdir/comm-w2c.h" /*:4*//*91:*/ -#line 737 "cwebdir/comm-w2c.ch" +#line 739 "cwebdir/comm-w2c.ch" #if HAVE_GETTEXT #include #else -#line 741 "cwebdir/comm-w2c.ch" +#line 743 "cwebdir/comm-w2c.ch" #define setlocale(a,b) "" #define bindtextdomain(a,b) "" #define textdomain(a) "" #endif -#line 745 "cwebdir/comm-w2c.ch" +#line 747 "cwebdir/comm-w2c.ch" /*:91*//*93:*/ -#line 784 "cwebdir/comm-w2c.ch" +#line 786 "cwebdir/comm-w2c.ch" #include @@ -47,7 +47,7 @@ #include /*:93*//*96:*/ -#line 821 "cwebdir/comm-w2c.ch" +#line 823 "cwebdir/comm-w2c.ch" #define CWEB #include "help.h" @@ -375,47 +375,47 @@ hash_pointer hash_ptr; int history= spotless; /*:65*//*73:*/ -#line 1125 "cwebdir/common.w" +#line 1127 "cwebdir/common.w" int argc; char**argv; char C_file_name[max_file_name_length]; char tex_file_name[max_file_name_length]; char idx_file_name[max_file_name_length]; -#line 454 "cwebdir/comm-w2c.ch" +#line 456 "cwebdir/comm-w2c.ch" char scn_file_name[max_file_name_length]; char check_file_name[max_file_name_length]; -#line 1132 "cwebdir/common.w" +#line 1134 "cwebdir/common.w" boolean flags[128]; /*:73*//*83:*/ -#line 1268 "cwebdir/common.w" +#line 1270 "cwebdir/common.w" FILE*C_file; FILE*tex_file; FILE*idx_file; FILE*scn_file; -#line 582 "cwebdir/comm-w2c.ch" +#line 584 "cwebdir/comm-w2c.ch" FILE*active_file; FILE*check_file; -#line 1274 "cwebdir/common.w" +#line 1276 "cwebdir/common.w" -#line 599 "cwebdir/comm-w2c.ch" +#line 601 "cwebdir/comm-w2c.ch" /*:83*//*86:*/ -#line 627 "cwebdir/comm-w2c.ch" +#line 629 "cwebdir/comm-w2c.ch" const char*use_language= ""; /*:86*//*87:*/ -#line 640 "cwebdir/comm-w2c.ch" +#line 642 "cwebdir/comm-w2c.ch" char cb_banner[max_banner]; string texmf_locale; #ifndef SEPARATORS #define SEPARATORS "://" #endif -#line 646 "cwebdir/comm-w2c.ch" +#line 648 "cwebdir/comm-w2c.ch" char separators[]= SEPARATORS; /*:87*/ @@ -483,12 +483,12 @@ static void extend_section_name(name_pointer,char*,char*,boolean); static int section_name_cmp(char**,size_t,name_pointer); /*:64*//*76:*/ -#line 1185 "cwebdir/common.w" +#line 1187 "cwebdir/common.w" static void scan_args(void); -#line 512 "cwebdir/comm-w2c.ch" +#line 514 "cwebdir/comm-w2c.ch" /*:76*//*98:*/ -#line 834 "cwebdir/comm-w2c.ch" +#line 836 "cwebdir/comm-w2c.ch" static void cb_usage(const_string str); static void cb_usagehelp(const_string*message); @@ -521,7 +521,7 @@ for(hash_ptr= hash;hash_ptr<=hash_end;*hash_ptr++= NULL); #line 78 "cwebdir/comm-w2c.ch" /*94:*/ -#line 796 "cwebdir/comm-w2c.ch" +#line 798 "cwebdir/comm-w2c.ch" kpse_set_program_name(argv[0],"cweb"); @@ -530,7 +530,7 @@ kpse_set_program_name(argv[0],"cweb"); #line 85 "cwebdir/comm-w2c.ch" /*92:*/ -#line 746 "cwebdir/comm-w2c.ch" +#line 748 "cwebdir/comm-w2c.ch" setlocale(LC_MESSAGES,setlocale(LC_CTYPE,"")); texmf_locale= kpse_var_expand("${TEXMFLOCALEDIR}"); @@ -549,23 +549,23 @@ textdomain("cweb"); #line 85 "cwebdir/comm-w2c.ch" /*74:*/ -#line 1138 "cwebdir/common.w" +#line 1140 "cwebdir/common.w" -#line 461 "cwebdir/comm-w2c.ch" +#line 463 "cwebdir/comm-w2c.ch" make_xrefs= true; -#line 1140 "cwebdir/common.w" +#line 1142 "cwebdir/common.w" /*:74*/ #line 86 "cwebdir/comm-w2c.ch" #line 101 "cwebdir/common.w" /*84:*/ -#line 599 "cwebdir/comm-w2c.ch" +#line 601 "cwebdir/comm-w2c.ch" scan_args(); if(program==ctangle){ if(check_for_change)/*88:*/ -#line 657 "cwebdir/comm-w2c.ch" +#line 659 "cwebdir/comm-w2c.ch" { if((C_file= fopen(C_file_name,"a"))==NULL) fatal(_("! Cannot open output file "),C_file_name); @@ -582,7 +582,7 @@ fatal(_("! Cannot open output file "),check_file_name); } /*:88*/ -#line 602 "cwebdir/comm-w2c.ch" +#line 604 "cwebdir/comm-w2c.ch" else if((C_file= fopen(C_file_name,"wb"))==NULL) fatal(_("! Cannot open output file "),C_file_name); @@ -590,7 +590,7 @@ fatal(_("! Cannot open output file "),C_file_name); } else{ if(check_for_change)/*89:*/ -#line 672 "cwebdir/comm-w2c.ch" +#line 674 "cwebdir/comm-w2c.ch" { if((tex_file= fopen(tex_file_name,"a"))==NULL) fatal(_("! Cannot open output file "),tex_file_name); @@ -607,14 +607,14 @@ fatal(_("! Cannot open output file "),check_file_name); } /*:89*/ -#line 608 "cwebdir/comm-w2c.ch" +#line 610 "cwebdir/comm-w2c.ch" else if((tex_file= fopen(tex_file_name,"wb"))==NULL) fatal(_("! Cannot open output file "),tex_file_name); } -#line 1286 "cwebdir/common.w" +#line 1288 "cwebdir/common.w" -#line 617 "cwebdir/comm-w2c.ch" +#line 619 "cwebdir/comm-w2c.ch" /*:84*/ #line 101 "cwebdir/common.w" @@ -1314,12 +1314,14 @@ if(web_file_open)/*67:*/ #line 1031 "cwebdir/common.w" {char*k,*l; -if(changing&&include_depth==change_depth) -#line 371 "cwebdir/comm-w2c.ch" +if(changing&&include_depth==change_depth&&change_line> 0) +#line 372 "cwebdir/comm-w2c.ch" printf(_(". (l. %d of change file)\n"),change_line); -else if(include_depth==0)printf(_(". (l. %d)\n"),cur_line); +else if(cur_line> 0){ +if(include_depth==0)printf(_(". (l. %d)\n"),cur_line); else printf(_(". (l. %d of include file %s)\n"),cur_line,cur_file_name); -#line 1037 "cwebdir/common.w" +#line 1038 "cwebdir/common.w" +} l= (loc>=limit?limit:loc); if(l> buffer){ for(k= buffer;k 0){ if((**(++argv)=='-'||**argv=='+')&&*(*argv+1))/*80:*/ -#line 1246 "cwebdir/common.w" +#line 1248 "cwebdir/common.w" -#line 525 "cwebdir/comm-w2c.ch" +#line 527 "cwebdir/comm-w2c.ch" { if(strcmp("-help",*argv)==0||strcmp("--help",*argv)==0) /*97:*/ -#line 825 "cwebdir/comm-w2c.ch" +#line 827 "cwebdir/comm-w2c.ch" cb_usagehelp(program==ctangle?CTANGLEHELP: program==cweave?CWEAVEHELP:CTWILLHELP); /*:97*/ -#line 528 "cwebdir/comm-w2c.ch" +#line 530 "cwebdir/comm-w2c.ch" if(strcmp("-version",*argv)==0||strcmp("--version",*argv)==0) /*100:*/ -#line 871 "cwebdir/comm-w2c.ch" +#line 873 "cwebdir/comm-w2c.ch" printversionandexit(cb_banner, program==ctwill?"Donald E. Knuth":"Silvio Levy and Donald E. Knuth", @@ -1465,7 +1467,7 @@ NULL,"Contemporary development on https://github.com/ascherer/cweb.\n"); /*:100*/ -#line 531 "cwebdir/comm-w2c.ch" +#line 533 "cwebdir/comm-w2c.ch" if(strcmp("-verbose",*argv)==0||strcmp("--verbose",*argv)==0) @@ -1479,15 +1481,15 @@ case'v':show_banner= show_progress= show_happiness= true;continue; case'q':show_banner= show_progress= show_happiness= false;continue; case'd': if(sscanf(++dot_pos,"%u",&kpathsea_debug)!=1)/*81:*/ -#line 568 "cwebdir/comm-w2c.ch" +#line 570 "cwebdir/comm-w2c.ch" cb_usage(program==ctangle?"ctangle":program==cweave?"cweave":"ctwill"); -#line 1261 "cwebdir/common.w" +#line 1263 "cwebdir/common.w" -#line 576 "cwebdir/comm-w2c.ch" +#line 578 "cwebdir/comm-w2c.ch" /*:81*/ -#line 543 "cwebdir/comm-w2c.ch" +#line 545 "cwebdir/comm-w2c.ch" while(isdigit(*dot_pos))dot_pos++; dot_pos--; @@ -1498,35 +1500,35 @@ default:flags[(eight_bits)*dot_pos]= flag_change;continue; break; } } -#line 1249 "cwebdir/common.w" +#line 1251 "cwebdir/common.w" -#line 568 "cwebdir/comm-w2c.ch" +#line 570 "cwebdir/comm-w2c.ch" /*:80*/ -#line 1168 "cwebdir/common.w" +#line 1170 "cwebdir/common.w" else{ s= name_pos= *argv;dot_pos= NULL; while(*s) -#line 500 "cwebdir/comm-w2c.ch" +#line 502 "cwebdir/comm-w2c.ch" if(*s=='.')dot_pos= s++; else if(*s==DIR_SEPARATOR||*s==DEVICE_SEPARATOR||*s=='/') dot_pos= NULL,name_pos= ++s; else s++; -#line 1175 "cwebdir/common.w" +#line 1177 "cwebdir/common.w" if(!found_web)/*77:*/ -#line 1194 "cwebdir/common.w" +#line 1196 "cwebdir/common.w" { if(s-*argv> max_file_name_length-5) /*82:*/ -#line 576 "cwebdir/comm-w2c.ch" +#line 578 "cwebdir/comm-w2c.ch" fatal(_("! Filename too long\n"),*argv); -#line 1263 "cwebdir/common.w" +#line 1265 "cwebdir/common.w" /*:82*/ -#line 1197 "cwebdir/common.w" +#line 1199 "cwebdir/common.w" if(dot_pos==NULL) sprintf(web_file_name,"%s.w",*argv); @@ -1534,7 +1536,7 @@ else{ strcpy(web_file_name,*argv); *dot_pos= '\0'; } -#line 1205 "cwebdir/common.w" +#line 1207 "cwebdir/common.w" sprintf(tex_file_name,"%s.tex",name_pos); if(make_xrefs){ sprintf(idx_file_name,"%s.idx",name_pos); @@ -1545,22 +1547,22 @@ found_web= true; } /*:77*/ -#line 1176 "cwebdir/common.w" +#line 1178 "cwebdir/common.w" else if(!found_change)/*78:*/ -#line 1214 "cwebdir/common.w" +#line 1216 "cwebdir/common.w" { if(strcmp(*argv,"-")!=0){ if(s-*argv> max_file_name_length-4) /*82:*/ -#line 576 "cwebdir/comm-w2c.ch" +#line 578 "cwebdir/comm-w2c.ch" fatal(_("! Filename too long\n"),*argv); -#line 1263 "cwebdir/common.w" +#line 1265 "cwebdir/common.w" /*:82*/ -#line 1218 "cwebdir/common.w" +#line 1220 "cwebdir/common.w" if(dot_pos==NULL) sprintf(change_file_name,"%s.ch",*argv); @@ -1570,21 +1572,21 @@ found_change= true; } /*:78*/ -#line 1177 "cwebdir/common.w" +#line 1179 "cwebdir/common.w" else if(!found_out)/*79:*/ -#line 1226 "cwebdir/common.w" +#line 1228 "cwebdir/common.w" { if(s-*argv> max_file_name_length-5) /*82:*/ -#line 576 "cwebdir/comm-w2c.ch" +#line 578 "cwebdir/comm-w2c.ch" fatal(_("! Filename too long\n"),*argv); -#line 1263 "cwebdir/common.w" +#line 1265 "cwebdir/common.w" /*:82*/ -#line 1229 "cwebdir/common.w" +#line 1231 "cwebdir/common.w" if(dot_pos==NULL){ sprintf(tex_file_name,"%s.tex",*argv); @@ -1602,36 +1604,36 @@ found_out= true; } /*:79*/ -#line 1178 "cwebdir/common.w" +#line 1180 "cwebdir/common.w" else/*81:*/ -#line 568 "cwebdir/comm-w2c.ch" +#line 570 "cwebdir/comm-w2c.ch" cb_usage(program==ctangle?"ctangle":program==cweave?"cweave":"ctwill"); -#line 1261 "cwebdir/common.w" +#line 1263 "cwebdir/common.w" -#line 576 "cwebdir/comm-w2c.ch" +#line 578 "cwebdir/comm-w2c.ch" /*:81*/ -#line 1179 "cwebdir/common.w" +#line 1181 "cwebdir/common.w" } } if(!found_web)/*81:*/ -#line 568 "cwebdir/comm-w2c.ch" +#line 570 "cwebdir/comm-w2c.ch" cb_usage(program==ctangle?"ctangle":program==cweave?"cweave":"ctwill"); -#line 1261 "cwebdir/common.w" +#line 1263 "cwebdir/common.w" -#line 576 "cwebdir/comm-w2c.ch" +#line 578 "cwebdir/comm-w2c.ch" /*:81*/ -#line 1182 "cwebdir/common.w" +#line 1184 "cwebdir/common.w" } /*:75*//*99:*/ -#line 838 "cwebdir/comm-w2c.ch" +#line 840 "cwebdir/comm-w2c.ch" static void cb_usage(const_string str) { @@ -1663,7 +1665,7 @@ history= spotless;exit(wrap_up()); } /*:99*//*101:*/ -#line 879 "cwebdir/comm-w2c.ch" +#line 881 "cwebdir/comm-w2c.ch" void cb_show_banner(void) { diff --git a/texk/web2c/cwebdir/ChangeLog b/texk/web2c/cwebdir/ChangeLog index f6bc891d5e..4cee3ef0ce 100644 --- a/texk/web2c/cwebdir/ChangeLog +++ b/texk/web2c/cwebdir/ChangeLog @@ -1,3 +1,9 @@ +2023-09-25 Andreas Scherer + + * comm-w2c.h, + * common.c, + * common.w: Check for available input. + 2023-09-24 Andreas Scherer * comm-w2c.h, diff --git a/texk/web2c/cwebdir/comm-w2c.ch b/texk/web2c/cwebdir/comm-w2c.ch index d37c02d23c..b7d4d7ad18 100644 --- a/texk/web2c/cwebdir/comm-w2c.ch +++ b/texk/web2c/cwebdir/comm-w2c.ch @@ -365,11 +365,13 @@ else if (strlen(found_filename) < max_file_name_length) { @x printf(". (l. %d of change file)\n", change_line); -else if (include_depth==0) printf(". (l. %d)\n", cur_line); +else if (cur_line>0) { + if (include_depth==0) printf(". (l. %d)\n", cur_line); else printf(". (l. %d of include file %s)\n", cur_line, cur_file_name); @y printf(_(". (l. %d of change file)\n"), change_line); -else if (include_depth==0) printf(_(". (l. %d)\n"), cur_line); +else if (cur_line>0) { + if (include_depth==0) printf(_(". (l. %d)\n"), cur_line); else printf(_(". (l. %d of include file %s)\n"), cur_line, cur_file_name); @z diff --git a/texk/web2c/cwebdir/common.c b/texk/web2c/cwebdir/common.c index 6d5e8d77f9..5e4e12917a 100644 --- a/texk/web2c/cwebdir/common.c +++ b/texk/web2c/cwebdir/common.c @@ -312,7 +312,7 @@ hash_pointer hash_ptr; int history= spotless; /*:65*//*73:*/ -#line 1125 "common.w" +#line 1127 "common.w" int argc; char**argv; @@ -323,7 +323,7 @@ char scn_file_name[max_file_name_length]; boolean flags[128]; /*:73*//*83:*/ -#line 1268 "common.w" +#line 1270 "common.w" FILE*C_file; FILE*tex_file; @@ -394,7 +394,7 @@ static void extend_section_name(name_pointer,char*,char*,boolean); static int section_name_cmp(char**,size_t,name_pointer); /*:64*//*76:*/ -#line 1185 "common.w" +#line 1187 "common.w" static void scan_args(void); /*:76*/ @@ -424,7 +424,7 @@ for(hash_ptr= hash;hash_ptr<=hash_end;*hash_ptr++= NULL); #line 99 "common.w" /*74:*/ -#line 1138 "common.w" +#line 1140 "common.w" show_banner= show_happiness= show_progress= make_xrefs= true; @@ -432,7 +432,7 @@ show_banner= show_happiness= show_progress= make_xrefs= true; #line 100 "common.w" /*84:*/ -#line 1275 "common.w" +#line 1277 "common.w" scan_args(); if(program==ctangle){ @@ -1092,10 +1092,12 @@ if(web_file_open)/*67:*/ #line 1031 "common.w" {char*k,*l; -if(changing&&include_depth==change_depth) +if(changing&&include_depth==change_depth&&change_line> 0) printf(". (l. %d of change file)\n",change_line); -else if(include_depth==0)printf(". (l. %d)\n",cur_line); +else if(cur_line> 0){ +if(include_depth==0)printf(". (l. %d)\n",cur_line); else printf(". (l. %d of include file %s)\n",cur_line,cur_file_name); +} l= (loc>=limit?limit:loc); if(l> buffer){ for(k= buffer;k harmless_message)return EXIT_FAILURE; else return EXIT_SUCCESS; } /*:68*//*70:*/ -#line 1092 "common.w" +#line 1094 "common.w" void fatal( const char*s,const char*t) @@ -1155,7 +1157,7 @@ history= fatal_message;exit(wrap_up()); } /*:70*//*71:*/ -#line 1103 "common.w" +#line 1105 "common.w" void overflow( const char*t) @@ -1165,7 +1167,7 @@ printf("\n! Sorry, %s capacity exceeded",t);fatal("",""); /*:71*//*75:*/ -#line 1156 "common.w" +#line 1158 "common.w" static void scan_args(void) @@ -1179,13 +1181,13 @@ boolean found_web= false,found_change= false,found_out= false; strcpy(change_file_name,"/dev/null"); while(--argc> 0){ if((**(++argv)=='-'||**argv=='+')&&*(*argv+1))/*80:*/ -#line 1246 "common.w" +#line 1248 "common.w" for(dot_pos= *argv+1;*dot_pos> '\0';dot_pos++) flags[(eight_bits)*dot_pos]= flag_change; /*:80*/ -#line 1168 "common.w" +#line 1170 "common.w" else{ s= name_pos= *argv;dot_pos= NULL; @@ -1194,17 +1196,17 @@ if(*s=='.')dot_pos= s++; else if(*s=='/')dot_pos= NULL,name_pos= ++s; else s++; if(!found_web)/*77:*/ -#line 1194 "common.w" +#line 1196 "common.w" { if(s-*argv> max_file_name_length-5) /*82:*/ -#line 1262 "common.w" +#line 1264 "common.w" fatal("! Filename too long\n",*argv); /*:82*/ -#line 1197 "common.w" +#line 1199 "common.w" if(dot_pos==NULL) sprintf(web_file_name,"%s.w",*argv); @@ -1223,21 +1225,21 @@ found_web= true; } /*:77*/ -#line 1176 "common.w" +#line 1178 "common.w" else if(!found_change)/*78:*/ -#line 1214 "common.w" +#line 1216 "common.w" { if(strcmp(*argv,"-")!=0){ if(s-*argv> max_file_name_length-4) /*82:*/ -#line 1262 "common.w" +#line 1264 "common.w" fatal("! Filename too long\n",*argv); /*:82*/ -#line 1218 "common.w" +#line 1220 "common.w" if(dot_pos==NULL) sprintf(change_file_name,"%s.ch",*argv); @@ -1247,20 +1249,20 @@ found_change= true; } /*:78*/ -#line 1177 "common.w" +#line 1179 "common.w" else if(!found_out)/*79:*/ -#line 1226 "common.w" +#line 1228 "common.w" { if(s-*argv> max_file_name_length-5) /*82:*/ -#line 1262 "common.w" +#line 1264 "common.w" fatal("! Filename too long\n",*argv); /*:82*/ -#line 1229 "common.w" +#line 1231 "common.w" if(dot_pos==NULL){ sprintf(tex_file_name,"%s.tex",*argv); @@ -1278,10 +1280,10 @@ found_out= true; } /*:79*/ -#line 1178 "common.w" +#line 1180 "common.w" else/*81:*/ -#line 1250 "common.w" +#line 1252 "common.w" { if(program==ctangle) @@ -1295,12 +1297,12 @@ else fatal( } /*:81*/ -#line 1179 "common.w" +#line 1181 "common.w" } } if(!found_web)/*81:*/ -#line 1250 "common.w" +#line 1252 "common.w" { if(program==ctangle) @@ -1314,7 +1316,7 @@ else fatal( } /*:81*/ -#line 1182 "common.w" +#line 1184 "common.w" } diff --git a/texk/web2c/cwebdir/common.w b/texk/web2c/cwebdir/common.w index 074275ceb2..c2f88bd002 100644 --- a/texk/web2c/cwebdir/common.w +++ b/texk/web2c/cwebdir/common.w @@ -1030,10 +1030,12 @@ has special line-numbering conventions. @= {char *k,*l; /* pointers into |buffer| */ -if (changing && include_depth==change_depth) +if (changing && include_depth==change_depth && change_line>0) printf(". (l. %d of change file)\n", change_line); -else if (include_depth==0) printf(". (l. %d)\n", cur_line); +else if (cur_line>0) { + if (include_depth==0) printf(". (l. %d)\n", cur_line); else printf(". (l. %d of include file %s)\n", cur_line, cur_file_name); +} l= (loc>=limit? limit: loc); if (l>buffer) { for (k=buffer; k