Skip to content

Commit

Permalink
[CWEB] Factor out cwebacromac.tex.
Browse files Browse the repository at this point in the history
Extract common macros from cwebmac.tex and the PDF variants of the
CTWILL macros. Update cwebman.tex accordingly.

Fixes in CWEB code:
- Consistent formatting of terminal output in cases of error
- Revert fputs back to printf
- Add curly braces for progress report (harmless glitch in CWEB 2.0)

git-svn-id: svn://tug.org/texlive/trunk/Build/source@68327 c570f23f-e606-0410-a88d-b1316a301751
  • Loading branch information
Andreas Scherer committed Sep 20, 2023
1 parent 82f01a1 commit e2daf87
Show file tree
Hide file tree
Showing 23 changed files with 207 additions and 625 deletions.
10 changes: 5 additions & 5 deletions texk/web2c/ctangleboot.cin
Original file line number Diff line number Diff line change
Expand Up @@ -665,7 +665,7 @@ a-= 024000;
if((a+name_dir)->equiv!=(void*)text_info)push_level(a+name_dir);
else if(a!=0){
#line 85 "cwebdir/ctang-w2c.ch"
fputs(_("\n! Not present: <"),stdout);
printf("%s",_("\n! Not present: <"));
#line 405 "cwebdir/ctangle.w"
print_section_name(a+name_dir);err_print(">");

Expand Down Expand Up @@ -727,7 +727,7 @@ output_defs();

if(text_info->text_link==macro&&cur_out_file==end_output_files){
#line 97 "cwebdir/ctang-w2c.ch"
fputs(_("\n! No program text was specified."),stdout);mark_harmless();
printf("%s",_("\n! No program text was specified."));mark_harmless();
#line 519 "cwebdir/ctangle.w"

}
Expand Down Expand Up @@ -1007,7 +1007,7 @@ strcpy(check_file_name,"");
if(show_happiness){
if(show_progress)new_line();
#line 111 "cwebdir/ctang-w2c.ch"
fputs(_("Done."),stdout);
printf("%s",_("Done."));
#line 537 "cwebdir/ctangle.w"
}
}
Expand Down Expand Up @@ -1343,7 +1343,7 @@ if(++id_loc<=section_text_end)*id_loc= (char)c;
}
if(id_loc>=section_text_end){
#line 247 "cwebdir/ctang-w2c.ch"
fputs(_("\n! String too long: "),stdout);
printf("%s",_("\n! String too long: "));
#line 1022 "cwebdir/ctangle.w"

term_write(section_text+1,25);
Expand Down Expand Up @@ -1440,7 +1440,7 @@ c= (eight_bits)' ';if(*(k-1)==' ')k--;
}
if(k>=section_text_end){
#line 283 "cwebdir/ctang-w2c.ch"
fputs(_("\n! Section name too long: "),stdout);
printf("%s",_("\n! Section name too long: "));
#line 1117 "cwebdir/ctangle.w"

term_write(section_text+1,25);
Expand Down
50 changes: 26 additions & 24 deletions texk/web2c/cwebboot.cin
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,7 @@ char check_file_name[max_file_name_length];
boolean flags[128];

/*:73*//*83:*/
#line 1266 "cwebdir/common.w"
#line 1268 "cwebdir/common.w"

FILE*C_file;
FILE*tex_file;
Expand All @@ -398,7 +398,7 @@ FILE*scn_file;
#line 582 "cwebdir/comm-w2c.ch"
FILE*active_file;
FILE*check_file;
#line 1272 "cwebdir/common.w"
#line 1274 "cwebdir/common.w"

#line 599 "cwebdir/comm-w2c.ch"
/*:83*//*86:*/
Expand Down Expand Up @@ -612,7 +612,7 @@ fatal(_("! Cannot open output file "),check_file_name);
else if((tex_file= fopen(tex_file_name,"wb"))==NULL)
fatal(_("! Cannot open output file "),tex_file_name);
}
#line 1284 "cwebdir/common.w"
#line 1286 "cwebdir/common.w"

#line 617 "cwebdir/comm-w2c.ch"
/*:84*/
Expand Down Expand Up @@ -1190,12 +1190,12 @@ p= (c==less?p->llink:p->rlink);
}else{
if(r!=NULL){
#line 333 "cwebdir/comm-w2c.ch"
fputs(_("\n! Ambiguous prefix: matches <"),stdout);
printf("%s",_("\n! Ambiguous prefix: matches <"));
#line 887 "cwebdir/common.w"

print_prefix_name(p);
#line 339 "cwebdir/comm-w2c.ch"
fputs(_(">\n and <"),stdout);
printf("%s",_(">\n and <"));
#line 890 "cwebdir/common.w"
print_prefix_name(r);
err_print(">");
Expand Down Expand Up @@ -1229,7 +1229,7 @@ switch(section_name_cmp(&first,name_len,r)){
case prefix:
if(!ispref){
#line 345 "cwebdir/comm-w2c.ch"
fputs(_("\n! New name is a prefix of <"),stdout);
printf("%s",_("\n! New name is a prefix of <"));
#line 916 "cwebdir/common.w"

print_section_name(r);
Expand All @@ -1243,20 +1243,20 @@ extend_section_name(r,first,last+1,ispref);
break;
case bad_extension:
#line 351 "cwebdir/comm-w2c.ch"
fputs(_("\n! New name extends <"),stdout);
printf("%s",_("\n! New name extends <"));
#line 928 "cwebdir/common.w"

print_section_name(r);
err_print(">");
break;
default:
#line 357 "cwebdir/comm-w2c.ch"
fputs(_("\n! Section name incompatible with <"),stdout);
printf("%s",_("\n! Section name incompatible with <"));
#line 934 "cwebdir/common.w"

print_prefix_name(r);
#line 363 "cwebdir/comm-w2c.ch"
fputs(_(">,\n which abbreviates <"),stdout);
printf("%s",_(">,\n which abbreviates <"));
#line 937 "cwebdir/common.w"
print_section_name(r);
err_print(">");
Expand Down Expand Up @@ -1309,7 +1309,7 @@ void
err_print(
const char*s)
{
*s=='!'?printf("\n%s",s):printf("%s",s);
printf(*s=='!'?"\n%s":"%s",s);
if(web_file_open)/*67:*/
#line 1031 "cwebdir/common.w"

Expand Down Expand Up @@ -1343,7 +1343,7 @@ update_terminal();mark_error();
#line 1064 "cwebdir/common.w"

int wrap_up(void){
if(show_progress)new_line();
if(show_progress||show_happiness||history!=spotless)new_line();
if(show_stats)
print_stats();
#line 401 "cwebdir/comm-w2c.ch"
Expand Down Expand Up @@ -1394,7 +1394,7 @@ void
fatal(
const char*s,const char*t)
{
if(*s)err_print(s);
if(*s)printf("%s",s);
err_print(t);
history= fatal_message;exit(wrap_up());
}
Expand Down Expand Up @@ -1438,7 +1438,7 @@ change_file_name[max_file_name_length-2]= '\0';
#line 1167 "cwebdir/common.w"
while(--argc> 0){
if((**(++argv)=='-'||**argv=='+')&&*(*argv+1))/*80:*/
#line 1244 "cwebdir/common.w"
#line 1246 "cwebdir/common.w"

#line 525 "cwebdir/comm-w2c.ch"
{
Expand Down Expand Up @@ -1483,7 +1483,7 @@ if(sscanf(++dot_pos,"%u",&kpathsea_debug)!=1)/*81:*/

cb_usage(program==ctangle?"ctangle":program==cweave?"cweave":"ctwill");

#line 1259 "cwebdir/common.w"
#line 1261 "cwebdir/common.w"

#line 576 "cwebdir/comm-w2c.ch"
/*:81*/
Expand All @@ -1498,7 +1498,7 @@ default:flags[(eight_bits)*dot_pos]= flag_change;continue;
break;
}
}
#line 1247 "cwebdir/common.w"
#line 1249 "cwebdir/common.w"

#line 568 "cwebdir/comm-w2c.ch"
/*:80*/
Expand All @@ -1522,7 +1522,7 @@ if(s-*argv> max_file_name_length-5)
/*82:*/
#line 576 "cwebdir/comm-w2c.ch"
fatal(_("! Filename too long\n"),*argv);
#line 1261 "cwebdir/common.w"
#line 1263 "cwebdir/common.w"


/*:82*/
Expand All @@ -1536,8 +1536,10 @@ strcpy(web_file_name,*argv);
}
#line 1205 "cwebdir/common.w"
sprintf(tex_file_name,"%s.tex",name_pos);
if(make_xrefs){
sprintf(idx_file_name,"%s.idx",name_pos);
sprintf(scn_file_name,"%s.scn",name_pos);
}
sprintf(C_file_name,"%s.c",name_pos);
found_web= true;
}
Expand All @@ -1546,19 +1548,19 @@ found_web= true;
#line 1176 "cwebdir/common.w"

else if(!found_change)/*78:*/
#line 1212 "cwebdir/common.w"
#line 1214 "cwebdir/common.w"

{
if(strcmp(*argv,"-")!=0){
if(s-*argv> max_file_name_length-4)
/*82:*/
#line 576 "cwebdir/comm-w2c.ch"
fatal(_("! Filename too long\n"),*argv);
#line 1261 "cwebdir/common.w"
#line 1263 "cwebdir/common.w"


/*:82*/
#line 1216 "cwebdir/common.w"
#line 1218 "cwebdir/common.w"

if(dot_pos==NULL)
sprintf(change_file_name,"%s.ch",*argv);
Expand All @@ -1571,18 +1573,18 @@ found_change= true;
#line 1177 "cwebdir/common.w"

else if(!found_out)/*79:*/
#line 1224 "cwebdir/common.w"
#line 1226 "cwebdir/common.w"

{
if(s-*argv> max_file_name_length-5)
/*82:*/
#line 576 "cwebdir/comm-w2c.ch"
fatal(_("! Filename too long\n"),*argv);
#line 1261 "cwebdir/common.w"
#line 1263 "cwebdir/common.w"


/*:82*/
#line 1227 "cwebdir/common.w"
#line 1229 "cwebdir/common.w"

if(dot_pos==NULL){
sprintf(tex_file_name,"%s.tex",*argv);
Expand All @@ -1607,7 +1609,7 @@ else/*81:*/

cb_usage(program==ctangle?"ctangle":program==cweave?"cweave":"ctwill");

#line 1259 "cwebdir/common.w"
#line 1261 "cwebdir/common.w"

#line 576 "cwebdir/comm-w2c.ch"
/*:81*/
Expand All @@ -1620,7 +1622,7 @@ if(!found_web)/*81:*/

cb_usage(program==ctangle?"ctangle":program==cweave?"cweave":"ctwill");

#line 1259 "cwebdir/common.w"
#line 1261 "cwebdir/common.w"

#line 576 "cwebdir/comm-w2c.ch"
/*:81*/
Expand Down
12 changes: 8 additions & 4 deletions texk/web2c/cwebdir/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,15 @@ CTANGLE = ./ctangle
SOURCES = cweave.w common.w ctangle.w
ALL = common.w ctangle.w cweave.w prod.w \
Makefile README common.c common.h ctangle.c \
cwebman.tex cwebmac.tex comm-vms.ch ctang-vms.ch \
cweav-vms.ch comm-man.ch ctang-man.ch cweav-man.ch \
comm-pc.ch ctang-pc.ch cweav-pc.ch comm-amiga.ch \
cwebman.tex cwebacromac.tex cwebmac.tex \
cweb.1 cweb.el c++lib.w iso_types.w \
comm-man.ch ctang-man.ch cweav-man.ch \
comm-bs.ch ctang-bs.ch cweav-bs.ch makefile.bs \
comm-pc.ch ctang-pc.ch cweav-pc.ch comm-amiga.ch \
comm-ql.ch ctang-ql.ch cweav-ql.ch readme.ql \
comm-vms.ch ctang-vms.ch cweav-vms.ch \
comm-w32.ch ctang-w32.ch cweav-w32.ch \
comm-os2.ch comm-mac.ch cweb.1 cweb.el c++lib.w iso_types.w
comm-os2.ch comm-mac.ch

.SUFFIXES: .dvi .tex .w .pdf

Expand Down Expand Up @@ -178,6 +180,8 @@ install: all
$(CP) cweb.1 $(MANDIR)/cweb.$(MANEXT)
chmod 644 $(MANDIR)/cweb.$(MANEXT)
- mkdir $(MACROSDIR)
$(CP) cwebacromac.tex $(MACROSDIR)
chmod 644 $(MACROSDIR)/cwebacromac.tex
$(CP) cwebmac.tex $(MACROSDIR)
chmod 644 $(MACROSDIR)/cwebmac.tex
- mkdir $(EMACSDIR)
Expand Down
1 change: 1 addition & 0 deletions texk/web2c/cwebdir/README
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ cweave-w32.ch
cweave.w
cweb.1
cweb.el
cwebacromac.tex
cwebmac.tex
cwebman.tex
examples/
Expand Down
12 changes: 8 additions & 4 deletions texk/web2c/cwebdir/comm-ql.ch
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,10 @@ the routine as if it would work.
}
sprintf(alt_web_file_name,"%s.web",*argv);
sprintf(tex_file_name,"%s.tex",name_pos); /* strip off directory name */
sprintf(idx_file_name,"%s.idx",name_pos);
sprintf(scn_file_name,"%s.scn",name_pos);
if (make_xrefs) { /* indexes will be generated */
sprintf(idx_file_name,"%s.idx",name_pos);
sprintf(scn_file_name,"%s.scn",name_pos);
}
sprintf(C_file_name,"%s.c",name_pos);
found_web=true;
}
Expand All @@ -170,8 +172,10 @@ the routine as if it would work.
}
sprintf(alt_web_file_name,"%s_web",*argv);
sprintf(tex_file_name,"%s_tex",name_pos); /* strip off directory name */
sprintf(idx_file_name,"%s_idx",name_pos);
sprintf(scn_file_name,"%s_scn",name_pos);
if (make_xrefs) { /* indexes will be generated */
sprintf(idx_file_name,"%s_idx",name_pos);
sprintf(scn_file_name,"%s_scn",name_pos);
}
sprintf(C_file_name,"%s_c",name_pos);
found_web=true;
}
Expand Down
24 changes: 12 additions & 12 deletions texk/web2c/cwebdir/comm-w2c.ch
Original file line number Diff line number Diff line change
Expand Up @@ -328,39 +328,39 @@ else if (strlen(found_filename) < max_file_name_length) {
@z

@x
fputs("\n! Ambiguous prefix: matches <",stdout);
printf("%s","\n! Ambiguous prefix: matches <");
@y
fputs(_("\n! Ambiguous prefix: matches <"),stdout);
printf("%s",_("\n! Ambiguous prefix: matches <"));
@z

@x
fputs(">\n and <",stdout);
printf("%s",">\n and <");
@y
fputs(_(">\n and <"),stdout);
printf("%s",_(">\n and <"));
@z

@x
fputs("\n! New name is a prefix of <",stdout);
printf("%s","\n! New name is a prefix of <");
@y
fputs(_("\n! New name is a prefix of <"),stdout);
printf("%s",_("\n! New name is a prefix of <"));
@z

@x
fputs("\n! New name extends <",stdout);
printf("%s","\n! New name extends <");
@y
fputs(_("\n! New name extends <"),stdout);
printf("%s",_("\n! New name extends <"));
@z

@x
fputs("\n! Section name incompatible with <",stdout);
printf("%s","\n! Section name incompatible with <");
@y
fputs(_("\n! Section name incompatible with <"),stdout);
printf("%s",_("\n! Section name incompatible with <"));
@z

@x
fputs(">,\n which abbreviates <",stdout);
printf("%s",">,\n which abbreviates <");
@y
fputs(_(">,\n which abbreviates <"),stdout);
printf("%s",_(">,\n which abbreviates <"));
@z

@x
Expand Down
2 changes: 1 addition & 1 deletion texk/web2c/cwebdir/comm-w2c.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ extern int phase; /* which phase are we in? */

@ The procedure that gets everything rolling:
@<Predecl...@>=
extern void common_init(void);@/
extern void common_init(void);

@ You may have noticed that almost all \.{"strings"} in the \.{CWEB} sources
are placed in the context of the `|_|'~macro. This is just a shortcut for the
Expand Down
Loading

0 comments on commit e2daf87

Please sign in to comment.