| 1 |
@q Changes for CWEB in TeX Live from numerous contributors. @> |
| 2 |
@q This file is in the Public Domain. @> |
| 3 |
|
| 4 |
@q Most of the original Kpathsea changes by Wlodek Bzyl and Olaf Weber @> |
| 5 |
@q were merged with the set of change files of the CWEBbin project; @> |
| 6 |
@q see https://github.com/ascherer/cwebbin for the original parts. @> |
| 7 |
|
| 8 |
@q This stripped change file {comm,ctang,cweav,ctwill,cwebman}-w2c.ch @> |
| 9 |
@q has been created from the elaborate set of change files @> |
| 10 |
@q {comm,ctang,cweav,cwebman}-patch.ch, @> |
| 11 |
@q {comm,cweav,cwebman}-extensions.ch, {comm,ctang,cweav}-output.ch, @> |
| 12 |
@q {comm,ctang,cweav}-i18n.ch, and cweav-twill.ch for CTWILL, and @> |
| 13 |
@q {comm,ctang,cweav,ctwill,cwebman}-texlive.ch with the 'tie' processor @> |
| 14 |
@q and is used as a monolithic changefile for {common,ctangle,cweave}.w @> |
| 15 |
@q and cwebman.tex in TeX Live. @> |
| 16 |
|
| 17 |
@q Please send comments, suggestions, etc. to tex-k@@tug.org. @> |
| 18 |
|
| 19 |
@x [0.0] l.25 |
| 20 |
\def\title{Common code for CTANGLE and CWEAVE (Version 4.12.2)} |
| 21 |
@y |
| 22 |
\def\Kpathsea/{{\mc KPATHSEA\spacefactor1000}} \ifacro\sanitizecommand\Kpathsea{KPATHSEA}\fi |
| 23 |
\def\title{Common code for CTANGLE and CWEAVE (4.12.2 [\TeX~Live])} |
| 24 |
@z |
| 25 |
|
| 26 |
@x [0.0] l.30 |
| 27 |
\centerline{(Version 4.12.2)} |
| 28 |
@y |
| 29 |
\centerline{(Version 4.12.2 [\TeX~Live])} |
| 30 |
@z |
| 31 |
|
| 32 |
@x [0.0] l.32 |
| 33 |
\def\botofcontents{\vfill |
| 34 |
@y |
| 35 |
\def\covernote{\vbox{% |
| 36 |
@z |
| 37 |
|
| 38 |
@x [0.0] l.45 |
| 39 |
} |
| 40 |
@y |
| 41 |
}}\datecontentspage |
| 42 |
@z |
| 43 |
|
| 44 |
@x [1.1] l.51 |
| 45 |
to both \.{CTANGLE} and \.{CWEAVE}, which roughly concerns the following |
| 46 |
@y |
| 47 |
to \.{CTANGLE}, \.{CWEAVE}, and \.{CTWILL}, |
| 48 |
which roughly concerns the following |
| 49 |
@z |
| 50 |
|
| 51 |
@x [1.1] l.57 |
| 52 |
sometimes use \.{CWEB} to refer to either of the two component |
| 53 |
@y |
| 54 |
sometimes use \.{CWEB} to refer to any of the three component |
| 55 |
@z |
| 56 |
|
| 57 |
@x [1.2] l.72 |
| 58 |
@i common.h |
| 59 |
@y |
| 60 |
@i comm-w2c.h |
| 61 |
@z |
| 62 |
|
| 63 |
@x [1.18] l.77 |
| 64 |
|program|. |
| 65 |
@y |
| 66 |
|program|. And \.{CTWILL} adds some extra twists. |
| 67 |
@z |
| 68 |
|
| 69 |
@x [1.18] l.80 |
| 70 |
bool program; /* \.{CWEAVE} or \.{CTANGLE}? */ |
| 71 |
@y |
| 72 |
cweb program; /* \.{CTANGLE} or \.{CWEAVE} or \.{CTWILL}? */ |
| 73 |
@z |
| 74 |
|
| 75 |
@x [1.20] l.99 |
| 76 |
@<Initialize pointers@>@; |
| 77 |
@y |
| 78 |
@<Initialize pointers@>@; |
| 79 |
@<Set up \.{PROGNAME} feature and initialize the search path mechanism@>@; |
| 80 |
@z |
| 81 |
|
| 82 |
@x [1.20] l.100 |
| 83 |
@<Set the default options common to \.{CTANGLE} and \.{CWEAVE}@>@; |
| 84 |
@y |
| 85 |
@<Set locale and bind language catalogs@>@; |
| 86 |
@<Set the default options common to \.{CTANGLE} and \.{CWEAVE}@>@; |
| 87 |
@z |
| 88 |
|
| 89 |
@x [3.23] l.165 |
| 90 |
if ((*(k++) = c) != ' ') limit = k; |
| 91 |
@y |
| 92 |
if ((*(k++) = c) != ' ' && c != '\r') limit = k; |
| 93 |
@z |
| 94 |
|
| 95 |
@x [3.23] l.168 |
| 96 |
loc=buffer; err_print("! Input line too long"); |
| 97 |
@y |
| 98 |
loc=buffer; err_print(_("! Input line too long")); |
| 99 |
@z |
| 100 |
|
| 101 |
@x [4.25] l.197 |
| 102 |
static char alt_web_file_name[max_file_name_length]; /* alternate name to try */ |
| 103 |
@y |
| 104 |
char *found_filename; /* filename found by |kpse_find_file| */ |
| 105 |
@z |
| 106 |
|
| 107 |
@x [4.29] l.253 |
| 108 |
err_print("! Missing @@x in change file"); |
| 109 |
@y |
| 110 |
err_print(_("! Missing @@x in change file")); |
| 111 |
@z |
| 112 |
|
| 113 |
@x [4.30] l.264 |
| 114 |
err_print("! Change file ended after @@x"); |
| 115 |
@y |
| 116 |
err_print(_("! Change file ended after @@x")); |
| 117 |
@z |
| 118 |
|
| 119 |
@x [4.32] l.310 |
| 120 |
err_print("! Change file ended before @@y"); |
| 121 |
@y |
| 122 |
err_print(_("! Change file ended before @@y")); |
| 123 |
@z |
| 124 |
|
| 125 |
@x [4.32] l.324 |
| 126 |
err_print("! CWEB file ended during a change"); |
| 127 |
@y |
| 128 |
err_print(_("! CWEB file ended during a change")); |
| 129 |
@z |
| 130 |
|
| 131 |
@x [4.34] l.338 |
| 132 |
loc=buffer+2; err_print("! Where is the matching @@y?"); |
| 133 |
@y |
| 134 |
loc=buffer+2; err_print(_("! Where is the matching @@y?")); |
| 135 |
@z |
| 136 |
|
| 137 |
@x [4.34] l.345 |
| 138 |
err_print("of the preceding lines failed to match"); |
| 139 |
@y |
| 140 |
err_print(_("of the preceding lines failed to match")); |
| 141 |
@z |
| 142 |
|
| 143 |
@x [4.35] l.378 |
| 144 |
err_print("! Include file name not given"); |
| 145 |
@y |
| 146 |
err_print(_("! Include file name not given")); |
| 147 |
@z |
| 148 |
|
| 149 |
@x [4.35] l.383 |
| 150 |
err_print("! Too many nested includes"); |
| 151 |
@y |
| 152 |
err_print(_("! Too many nested includes")); |
| 153 |
@z |
| 154 |
|
| 155 |
@x [4.36] l.393 |
| 156 |
@ When an \.{@@i} line is found in the |cur_file|, we must temporarily |
| 157 |
stop reading it and start reading from the named include file. The |
| 158 |
\.{@@i} line should give a complete file name with or without |
| 159 |
double quotes. |
| 160 |
If the environment variable |CWEBINPUTS| is set, or if the compiler flag |
| 161 |
of the same name was defined at compile time, |
| 162 |
\.{CWEB} will look for include files in the directory thus named, if |
| 163 |
it cannot find them in the current directory. |
| 164 |
(Colon-separated paths are not supported.) |
| 165 |
The remainder of the \.{@@i} line after the file name is ignored. |
| 166 |
@y |
| 167 |
@ When an \.{@@i} line is found in the |cur_file|, we must temporarily |
| 168 |
stop reading it and start reading from the named include file. The |
| 169 |
\.{@@i} line should give a complete file name with or without |
| 170 |
double quotes. |
| 171 |
The actual file lookup is done with the help of the \Kpathsea/ library; |
| 172 |
see section~\X93:File lookup with \Kpathsea/\X~for details. % FIXME |
| 173 |
The remainder of the \.{@@i} line after the file name is ignored. |
| 174 |
@^system dependencies@> |
| 175 |
@z |
| 176 |
|
| 177 |
@x [4.36] l.405 |
| 178 |
err_print("! Include file name too long"); goto restart;} |
| 179 |
@y |
| 180 |
err_print(_("! Include file name too long")); goto restart;} |
| 181 |
@z |
| 182 |
|
| 183 |
@x [4.36] l.408 |
| 184 |
char temp_file_name[max_file_name_length]; |
| 185 |
char *cur_file_name_end=cur_file_name+max_file_name_length-1; |
| 186 |
char *kk, *k=cur_file_name; |
| 187 |
size_t l; /* length of file name */ |
| 188 |
@y |
| 189 |
char *cur_file_name_end=cur_file_name+max_file_name_length-1; |
| 190 |
char *k=cur_file_name; |
| 191 |
@z |
| 192 |
|
| 193 |
@x [4.36] l.422 |
| 194 |
if ((cur_file=fopen(cur_file_name,"r"))!=NULL) { |
| 195 |
@y |
| 196 |
if ((found_filename=kpse_find_cweb(cur_file_name))!=NULL @| |
| 197 |
&& (cur_file=fopen(found_filename,"r"))!=NULL) { |
| 198 |
/* Copy name for \#\&{line} directives. */ |
| 199 |
if (strlen(found_filename) < max_file_name_length) { |
| 200 |
if (strcmp(cur_file_name, found_filename)) |
| 201 |
strcpy(cur_file_name, found_filename + |
| 202 |
((strncmp(found_filename,"./",2)==0) ? 2 : 0)); |
| 203 |
free(found_filename); |
| 204 |
} else fatal(_("! Filename too long\n"), found_filename); |
| 205 |
@z |
| 206 |
|
| 207 |
@x [4.36] l.426 |
| 208 |
if ((kk=getenv("CWEBINPUTS"))!=NULL) { |
| 209 |
if ((l=strlen(kk))>max_file_name_length-2) too_long(); |
| 210 |
strcpy(temp_file_name,kk); |
| 211 |
} |
| 212 |
else { |
| 213 |
#ifdef CWEBINPUTS |
| 214 |
if ((l=strlen(CWEBINPUTS))>max_file_name_length-2) too_long(); |
| 215 |
strcpy(temp_file_name,CWEBINPUTS); |
| 216 |
#else |
| 217 |
l=0; |
| 218 |
#endif /* |CWEBINPUTS| */ |
| 219 |
} |
| 220 |
if (l>0) { |
| 221 |
if (k+l+2>=cur_file_name_end) too_long(); |
| 222 |
@.Include file name ...@> |
| 223 |
for (; k>=cur_file_name; k--) *(k+l+1)=*k; |
| 224 |
strcpy(cur_file_name,temp_file_name); |
| 225 |
cur_file_name[l]='/'; /* \UNIX/ pathname separator */ |
| 226 |
@^system dependencies@> |
| 227 |
if ((cur_file=fopen(cur_file_name,"r"))!=NULL) { |
| 228 |
cur_line=0; print_where=true; |
| 229 |
goto restart; /* success */ |
| 230 |
} |
| 231 |
} |
| 232 |
include_depth--; err_print("! Cannot open include file"); goto restart; |
| 233 |
@y |
| 234 |
include_depth--; err_print(_("! Cannot open include file")); goto restart; |
| 235 |
@z |
| 236 |
|
| 237 |
@x [4.38] l.473 |
| 238 |
err_print("! Change file ended without @@z"); |
| 239 |
@y |
| 240 |
err_print(_("! Change file ended without @@z")); |
| 241 |
@z |
| 242 |
|
| 243 |
@x [4.38] l.489 |
| 244 |
err_print("! Where is the matching @@z?"); |
| 245 |
@y |
| 246 |
err_print(_("! Where is the matching @@z?")); |
| 247 |
@z |
| 248 |
|
| 249 |
@x [4.39] l.509 |
| 250 |
err_print("! Change file entry did not match"); |
| 251 |
@y |
| 252 |
err_print(_("! Change file entry did not match")); |
| 253 |
@z |
| 254 |
|
| 255 |
@x [4.41] l.534 |
| 256 |
if ((web_file=fopen(web_file_name,"r"))==NULL) { |
| 257 |
strcpy(web_file_name,alt_web_file_name); |
| 258 |
if ((web_file=fopen(web_file_name,"r"))==NULL) |
| 259 |
fatal("! Cannot open input file ", web_file_name); |
| 260 |
} |
| 261 |
@y |
| 262 |
if ((found_filename=kpse_find_cweb(web_file_name))==NULL @| |
| 263 |
|| (web_file=fopen(found_filename,"r"))==NULL) |
| 264 |
fatal(_("! Cannot open input file "), web_file_name); |
| 265 |
else if (strlen(found_filename) < max_file_name_length) { |
| 266 |
/* Copy name for \#\&{line} directives. */ |
| 267 |
if (strcmp(web_file_name, found_filename)) |
| 268 |
strcpy(web_file_name, found_filename + |
| 269 |
((strncmp(found_filename,"./",2)==0) ? 2 : 0)); |
| 270 |
free(found_filename); |
| 271 |
} else fatal(_("! Filename too long\n"), found_filename); |
| 272 |
@z |
| 273 |
|
| 274 |
@x [4.41] l.542 |
| 275 |
if ((change_file=fopen(change_file_name,"r"))==NULL) |
| 276 |
fatal("! Cannot open change file ", change_file_name); |
| 277 |
@y |
| 278 |
if ((found_filename=kpse_find_cweb(change_file_name))==NULL @| |
| 279 |
|| (change_file=fopen(found_filename,"r"))==NULL) |
| 280 |
fatal(_("! Cannot open change file "), change_file_name); |
| 281 |
else if (strlen(found_filename) < max_file_name_length) { |
| 282 |
/* Copy name for \#\&{line} directives. */ |
| 283 |
if (strcmp(change_file_name, found_filename)) |
| 284 |
strcpy(change_file_name, found_filename + |
| 285 |
((strncmp(found_filename,"./",2)==0) ? 2 : 0)); |
| 286 |
free(found_filename); |
| 287 |
} else fatal(_("! Filename too long\n"), found_filename); |
| 288 |
@z |
| 289 |
|
| 290 |
@x [5.46] l.619 |
| 291 |
@d hash_size 353 /* should be prime */ |
| 292 |
@y |
| 293 |
@d hash_size 8501 /* should be prime */ |
| 294 |
@z |
| 295 |
|
| 296 |
@x [5.51] l.673 |
| 297 |
if (byte_ptr+l>byte_mem_end) overflow("byte memory"); |
| 298 |
if (name_ptr>=name_dir_end) overflow("name"); |
| 299 |
@y |
| 300 |
if (byte_ptr+l>byte_mem_end) overflow(_("byte memory")); |
| 301 |
if (name_ptr>=name_dir_end) overflow(_("name")); |
| 302 |
@z |
| 303 |
|
| 304 |
@x [5.51] l.677 |
| 305 |
if (program==cweave) p->ilk=t, init_node(p); |
| 306 |
@y |
| 307 |
if (program!=ctangle) p->ilk=t, init_node(p); |
| 308 |
@z |
| 309 |
|
| 310 |
@x [5.57] l.806 |
| 311 |
if (s+name_len>byte_mem_end) overflow("byte memory"); |
| 312 |
if (name_ptr+1>=name_dir_end) overflow("name"); |
| 313 |
@y |
| 314 |
if (s+name_len>byte_mem_end) overflow(_("byte memory")); |
| 315 |
if (name_ptr+1>=name_dir_end) overflow(_("name")); |
| 316 |
@z |
| 317 |
|
| 318 |
@x [5.58] l.833 |
| 319 |
if (name_ptr>=name_dir_end) overflow("name"); |
| 320 |
@y |
| 321 |
if (name_ptr>=name_dir_end) overflow(_("name")); |
| 322 |
@z |
| 323 |
|
| 324 |
@x [5.58] l.838 |
| 325 |
if (s+name_len>byte_mem_end) overflow("byte memory"); |
| 326 |
@y |
| 327 |
if (s+name_len>byte_mem_end) overflow(_("byte memory")); |
| 328 |
@z |
| 329 |
|
| 330 |
@x [5.60] l.883 |
| 331 |
printf("%s","\n! Ambiguous prefix: matches <"); |
| 332 |
@y |
| 333 |
printf("%s",_("\n! Ambiguous prefix: matches <")); |
| 334 |
@z |
| 335 |
|
| 336 |
@x [5.60] l.886 |
| 337 |
printf("%s",">\n and <"); |
| 338 |
@y |
| 339 |
printf("%s",_(">\n and <")); |
| 340 |
@z |
| 341 |
|
| 342 |
@x [5.62] l.912 |
| 343 |
printf("%s","\n! New name is a prefix of <"); |
| 344 |
@y |
| 345 |
printf("%s",_("\n! New name is a prefix of <")); |
| 346 |
@z |
| 347 |
|
| 348 |
@x [5.62] l.924 |
| 349 |
printf("%s","\n! New name extends <"); |
| 350 |
@y |
| 351 |
printf("%s",_("\n! New name extends <")); |
| 352 |
@z |
| 353 |
|
| 354 |
@x [5.62] l.930 |
| 355 |
printf("%s","\n! Section name incompatible with <"); |
| 356 |
@y |
| 357 |
printf("%s",_("\n! Section name incompatible with <")); |
| 358 |
@z |
| 359 |
|
| 360 |
@x [5.62] l.933 |
| 361 |
printf("%s",">,\n which abbreviates <"); |
| 362 |
@y |
| 363 |
printf("%s",_(">,\n which abbreviates <")); |
| 364 |
@z |
| 365 |
|
| 366 |
@x [6.67] l.1031 |
| 367 |
printf(". (l. %d of change file)\n", change_line); |
| 368 |
else if (cur_line>0) { |
| 369 |
if (include_depth==0) printf(". (l. %d)\n", cur_line); |
| 370 |
else printf(". (l. %d of include file %s)\n", cur_line, cur_file_name); |
| 371 |
@y |
| 372 |
printf(_(". (l. %d of change file)\n"), change_line); |
| 373 |
else if (cur_line>0) { |
| 374 |
if (include_depth==0) printf(_(". (l. %d)\n"), cur_line); |
| 375 |
else printf(_(". (l. %d of include file %s)\n"), cur_line, cur_file_name); |
| 376 |
@z |
| 377 |
|
| 378 |
@x [6.68] l.1068 |
| 379 |
@<Print the job |history|@>@; |
| 380 |
@y |
| 381 |
@<Print the job |history|@>@; |
| 382 |
@<Remove the temporary file if not already done@>@; |
| 383 |
@z |
| 384 |
|
| 385 |
@x [6.69] l.1075 |
| 386 |
case spotless: |
| 387 |
if (show_happiness) puts("(No errors were found.)"); break; |
| 388 |
case harmless_message: |
| 389 |
puts("(Did you see the warning message above?)"); break; |
| 390 |
case error_message: |
| 391 |
puts("(Pardon me, but I think I spotted something wrong.)"); break; |
| 392 |
case fatal_message: default: |
| 393 |
puts("(That was a fatal error, my friend.)"); |
| 394 |
@y |
| 395 |
case spotless: |
| 396 |
if (show_happiness) puts(_("(No errors were found.)")); break; |
| 397 |
case harmless_message: |
| 398 |
puts(_("(Did you see the warning message above?)")); break; |
| 399 |
case error_message: |
| 400 |
puts(_("(Pardon me, but I think I spotted something wrong.)")); break; |
| 401 |
case fatal_message: default: |
| 402 |
puts(_("(That was a fatal error, my friend.)")); |
| 403 |
@z |
| 404 |
|
| 405 |
@x [6.71] l.1106 |
| 406 |
printf("\n! Sorry, %s capacity exceeded",t); fatal("",""); |
| 407 |
@y |
| 408 |
printf(_("\n! Sorry, %s capacity exceeded"),t); fatal("",""); |
| 409 |
@z |
| 410 |
|
| 411 |
@x [7.73] l.1118 |
| 412 |
or flags to be turned on (beginning with |"+"|). |
| 413 |
@y |
| 414 |
or flags to be turned on (beginning with |"+"|). |
| 415 |
\TeX~Live's \.{CWEB} executables accept several ``long options'' as well; |
| 416 |
see section |@<Handle flag arg...@>| for details. |
| 417 |
@z |
| 418 |
|
| 419 |
@x [7.73] l.1130 |
| 420 |
char scn_file_name[max_file_name_length]; /* name of |scn_file| */ |
| 421 |
@y |
| 422 |
char scn_file_name[max_file_name_length]; /* name of |scn_file| */ |
| 423 |
char check_file_name[max_file_name_length]; /* name of |check_file| */ |
| 424 |
@z |
| 425 |
|
| 426 |
@x [7.75] l.1142 |
| 427 |
file. It may have an extension, or it may omit the extension to get |".w"| or |
| 428 |
|".web"| added. The \TEX/ output file name is formed by replacing the \.{CWEB} |
| 429 |
@y |
| 430 |
file. It may have an extension, or it may omit the extension to get |".w"| |
| 431 |
added. The \TEX/ output file name is formed by replacing the \.{CWEB} |
| 432 |
@z |
| 433 |
|
| 434 |
@x [7.75] l.1149 |
| 435 |
An omitted change file argument means that |"/dev/null"| should be used, |
| 436 |
when no changes are desired. |
| 437 |
@y |
| 438 |
An omitted change file argument means that |"/dev/null"| or---on non-\UNIX/ |
| 439 |
systems the contents of the compile-time variable |DEV_NULL| (\TeX~Live) or |
| 440 |
|_DEV_NULL| (Amiga)---should be used, when no changes are desired. |
| 441 |
@z |
| 442 |
|
| 443 |
@x [7.75] l.1165 |
| 444 |
strcpy(change_file_name,"/dev/null"); |
| 445 |
@y |
| 446 |
strcpy(change_file_name,"/dev/null"); |
| 447 |
#if defined DEV_NULL |
| 448 |
strncpy(change_file_name,DEV_NULL,max_file_name_length-2); |
| 449 |
change_file_name[max_file_name_length-2]='\0'; |
| 450 |
#elif defined _DEV_NULL |
| 451 |
strncpy(change_file_name,_DEV_NULL,max_file_name_length-2); |
| 452 |
change_file_name[max_file_name_length-2]='\0'; |
| 453 |
#endif |
| 454 |
@^system dependencies@> |
| 455 |
@z |
| 456 |
|
| 457 |
@x [7.75] l.1171 |
| 458 |
if (*s=='.') dot_pos=s++; |
| 459 |
else if (*s=='/') dot_pos=NULL,name_pos=++s; |
| 460 |
else s++; |
| 461 |
@y |
| 462 |
if (*s=='.') dot_pos=s++; |
| 463 |
else if (*s==DIR_SEPARATOR || *s==DEVICE_SEPARATOR || *s=='/') |
| 464 |
dot_pos=NULL,name_pos=++s; |
| 465 |
else s++; |
| 466 |
@^system dependencies@> |
| 467 |
@z |
| 468 |
|
| 469 |
@x [7.77] l.1186 |
| 470 |
@ We use all of |*argv| for the |web_file_name| if there is a |'.'| in it, |
| 471 |
otherwise we add |".w"|. If this file can't be opened, we prepare an |
| 472 |
|alt_web_file_name| by adding |"web"| after the dot. |
| 473 |
@y |
| 474 |
@ We use all of |*argv| for the |web_file_name| if there is a |'.'| in it, |
| 475 |
otherwise we add |".w"|. |
| 476 |
@z |
| 477 |
|
| 478 |
@x [7.77] l.1203 |
| 479 |
sprintf(alt_web_file_name,"%s.web",*argv); |
| 480 |
@y |
| 481 |
@z |
| 482 |
|
| 483 |
@x [7.80] l.1246 |
| 484 |
for(dot_pos=*argv+1;*dot_pos>'\0';dot_pos++) |
| 485 |
flags[(eight_bits)*dot_pos]=flag_change; |
| 486 |
@y |
| 487 |
{ |
| 488 |
if (strcmp("-help",*argv)==0 || strcmp("--help",*argv)==0) |
| 489 |
@.--help@> |
| 490 |
@<Display help message and |exit|@>@; |
| 491 |
if (strcmp("-version",*argv)==0 || strcmp("--version",*argv)==0) |
| 492 |
@.--version@> |
| 493 |
@<Display version information and |exit|@>@; |
| 494 |
if (strcmp("-verbose",*argv)==0 || strcmp("--verbose",*argv)==0) |
| 495 |
@.--verbose@> |
| 496 |
strcpy(*argv,"-v"); |
| 497 |
if (strcmp("-quiet",*argv)==0 || strcmp("--quiet",*argv)==0) |
| 498 |
@.--quiet@> |
| 499 |
strcpy(*argv,"-q"); |
| 500 |
for(dot_pos=*argv+1;*dot_pos>'\0';dot_pos++) { |
| 501 |
switch (*dot_pos) { |
| 502 |
case 'v': show_banner=show_progress=show_happiness=true; continue; |
| 503 |
case 'q': show_banner=show_progress=show_happiness=false; continue; |
| 504 |
case 'd': |
| 505 |
if (sscanf(++dot_pos,"%u",&kpathsea_debug)!=1) @<Print usage error...@>@; |
| 506 |
while (isdigit(*dot_pos)) dot_pos++; /* skip numeric part */ |
| 507 |
dot_pos--; /* reset to final digit */ |
| 508 |
continue; |
| 509 |
case 'l': use_language=++dot_pos; break; /* from |switch| */ |
| 510 |
default: flags[(eight_bits)*dot_pos]=flag_change; continue; |
| 511 |
} |
| 512 |
break; /* from |for| loop */ |
| 513 |
} |
| 514 |
} |
| 515 |
@z |
| 516 |
|
| 517 |
@x [7.81] l.1249 |
| 518 |
@ @<Print usage error message and quit@>= |
| 519 |
{ |
| 520 |
if (program==ctangle) |
| 521 |
fatal( |
| 522 |
"! Usage: ctangle [options] webfile[.w] [{changefile[.ch]|-} [outfile[.c]]]\n" |
| 523 |
,""); |
| 524 |
@.Usage:@> |
| 525 |
else fatal( |
| 526 |
"! Usage: cweave [options] webfile[.w] [{changefile[.ch]|-} [outfile[.tex]]]\n" |
| 527 |
,""); |
| 528 |
} |
| 529 |
@y |
| 530 |
@ @<Print usage error message and quit@>= |
| 531 |
cb_usage(program==ctangle ? "ctangle" : program==cweave ? "cweave" : "ctwill"); |
| 532 |
@.Usage:@> |
| 533 |
@z |
| 534 |
|
| 535 |
@x [7.82] l.1261 |
| 536 |
@ @<Complain about arg...@>= fatal("! Filename too long\n", *argv); |
| 537 |
@y |
| 538 |
@ @<Complain about arg...@>= fatal(_("! Filename too long\n"), *argv); |
| 539 |
@z |
| 540 |
|
| 541 |
@x [8.83] l.1272 |
| 542 |
FILE *active_file; /* currently active file for \.{CWEAVE} output */ |
| 543 |
@y |
| 544 |
FILE *active_file; /* currently active file for \.{CWEAVE} output */ |
| 545 |
FILE *check_file; /* temporary output file */ |
| 546 |
@z |
| 547 |
|
| 548 |
@x [8.84] l.1274 |
| 549 |
@ @<Scan arguments and open output files@>= |
| 550 |
scan_args(); |
| 551 |
if (program==ctangle) { |
| 552 |
if ((C_file=fopen(C_file_name,"wb"))==NULL) |
| 553 |
fatal("! Cannot open output file ", C_file_name); |
| 554 |
@.Cannot open output file@> |
| 555 |
} |
| 556 |
else { |
| 557 |
if ((tex_file=fopen(tex_file_name,"wb"))==NULL) |
| 558 |
fatal("! Cannot open output file ", tex_file_name); |
| 559 |
} |
| 560 |
@y |
| 561 |
@ @<Scan arguments and open output files@>= |
| 562 |
scan_args(); |
| 563 |
if (program==ctangle) { |
| 564 |
if (check_for_change) @<Open intermediate \CEE/ output file@>@; |
| 565 |
else if ((C_file=fopen(C_file_name,"wb"))==NULL) |
| 566 |
fatal(_("! Cannot open output file "), C_file_name); |
| 567 |
@.Cannot open output file@> |
| 568 |
} |
| 569 |
else { |
| 570 |
if (check_for_change) @<Open intermediate \TEX/ output file@>@; |
| 571 |
else if ((tex_file=fopen(tex_file_name,"wb"))==NULL) |
| 572 |
fatal(_("! Cannot open output file "), tex_file_name); |
| 573 |
} |
| 574 |
@z |
| 575 |
|
| 576 |
@x [9.85] l.1286 |
| 577 |
@* Index. |
| 578 |
@y |
| 579 |
@* Extensions to {\tentex CWEB}. The following sections introduce new or |
| 580 |
improved features that have been created by numerous contributors over the |
| 581 |
course of a quarter century. |
| 582 |
|
| 583 |
Care has been taken to keep the original section numbering intact, so this new |
| 584 |
material should nicely integrate with the original ``\&{85.~Index}.'' |
| 585 |
|
| 586 |
@*1 Language setting. This global variable is set by the argument of the |
| 587 |
`\.{+l}' (or `\.{-l}') command-line option. |
| 588 |
|
| 589 |
@<Global var...@>= |
| 590 |
const char *use_language=""; /* prefix of \.{cwebmac.tex} in \TEX/ output */ |
| 591 |
|
| 592 |
|
| 593 |
@*1 User communication. The |scan_args| and |cb_show_banner| routines and the |
| 594 |
|bindtextdomain| argument string need a few extra variables. |
| 595 |
|
| 596 |
@d max_banner 50 |
| 597 |
|
| 598 |
@d PATH_SEPARATOR separators[0] |
| 599 |
@d DIR_SEPARATOR separators[1] |
| 600 |
@d DEVICE_SEPARATOR separators[2] |
| 601 |
|
| 602 |
@<Global var...@>= |
| 603 |
char cb_banner[max_banner];@/ |
| 604 |
string texmf_locale;@/ |
| 605 |
#ifndef SEPARATORS |
| 606 |
#define SEPARATORS "://"@^system dependencies@> |
| 607 |
#endif |
| 608 |
char separators[]=SEPARATORS; |
| 609 |
|
| 610 |
@*1 Temporary file output. Most \CEE/ projects are controlled by a \.{Makefile} |
| 611 |
that automatically takes care of the temporal dependencies between the different |
| 612 |
source modules. It may be convenient that \.{CWEB} doesn't create new output |
| 613 |
for all existing files, when there are only changes to some of them. Thus the |
| 614 |
\.{make} process will only recompile those modules where necessary. You can |
| 615 |
activate this feature with the `\.{+c}' command-line option. The idea and basic |
| 616 |
implementation of this mechanism can be found in the program \.{NUWEB} by |
| 617 |
Preston Briggs, to whom credit is due. |
| 618 |
|
| 619 |
@<Open intermediate \CEE/ output file@>= { |
| 620 |
if ((C_file=fopen(C_file_name,"a"))==NULL) |
| 621 |
fatal(_("! Cannot open output file "), C_file_name); |
| 622 |
@.Cannot open output file@> |
| 623 |
else fclose(C_file); /* Test accessability */ |
| 624 |
strcpy(check_file_name,C_file_name); |
| 625 |
if(check_file_name[0]!='\0') { |
| 626 |
char *dot_pos=strrchr(check_file_name,'.'); |
| 627 |
if(dot_pos==NULL) strcat(check_file_name,".ttp"); |
| 628 |
else strcpy(dot_pos,".ttp"); |
| 629 |
} |
| 630 |
if ((C_file=fopen(check_file_name,"wb"))==NULL) |
| 631 |
fatal(_("! Cannot open output file "), check_file_name); |
| 632 |
} |
| 633 |
|
| 634 |
@ @<Open intermediate \TEX/ output file@>= { |
| 635 |
if ((tex_file=fopen(tex_file_name,"a"))==NULL) |
| 636 |
fatal(_("! Cannot open output file "), tex_file_name); |
| 637 |
@.Cannot open output file@> |
| 638 |
else fclose(tex_file); /* Test accessability */ |
| 639 |
strcpy(check_file_name,tex_file_name); |
| 640 |
if(check_file_name[0]!='\0') { |
| 641 |
char *dot_pos=strrchr(check_file_name,'.'); |
| 642 |
if(dot_pos==NULL) strcat(check_file_name,".wtp"); |
| 643 |
else strcpy(dot_pos,".wtp"); |
| 644 |
} |
| 645 |
if ((tex_file=fopen(check_file_name,"wb"))==NULL) |
| 646 |
fatal(_("! Cannot open output file "), check_file_name); |
| 647 |
} |
| 648 |
|
| 649 |
@ Before we leave the program we have to make |
| 650 |
sure that the output files are correctly written. |
| 651 |
|
| 652 |
@<Remove the temporary file...@>= |
| 653 |
if(C_file) fclose(C_file); |
| 654 |
if(tex_file) fclose(tex_file); |
| 655 |
if(check_file) fclose(check_file); |
| 656 |
if(strlen(check_file_name)) /* Delete the temporary file in case of a break */ |
| 657 |
remove(check_file_name); |
| 658 |
|
| 659 |
@*1 Internationalization. If translation catalogs for your personal |
| 660 |
\.{LANGUAGE} are installed at the appropriate place, \.{CTANGLE} and \.{CWEAVE} |
| 661 |
will talk to you in your favorite language. Catalog \.{cweb} contains all |
| 662 |
strings from ``plain \.{CWEB},'' catalog \.{cweb-tl} contains a few extra |
| 663 |
strings specific to the \TeX~Live interface, and catalog \.{web2c-help} |
| 664 |
contains the ``\.{--help}'' texts for \.{CTANGLE} and \.{CWEAVE}. |
| 665 |
@.cweb.mo@> |
| 666 |
@.cweb-tl.mo@> |
| 667 |
@.web2c-help.mo@> |
| 668 |
@.--help@> |
| 669 |
|
| 670 |
If such translation files are not available, you may want to improve this |
| 671 |
system by checking out the sources and translating the strings in files |
| 672 |
\.{cweb.pot}, \.{cweb-tl.pot}, and \.{web2c-help.pot}, and submitting the |
| 673 |
resulting \.{*.po} files to the maintainers at \.{tex-k@@tug.org}. |
| 674 |
|
| 675 |
\medskip \noindent \&{Note to maintainers:} \.{CWEB} in \TeX~Live generally |
| 676 |
does \\{not} set |HAVE_GETTEXT| at build-time, so \.{i18n} is ``off'' by |
| 677 |
default. If you want to create \.{CWEB} executables with NLS support, you |
| 678 |
have to recompile the \TeX~Live sources with a positive value for |
| 679 |
|HAVE_GETTEXT| in \.{comm-w2c.h}. Also you have to ``compile'' the NLS |
| 680 |
catalogs provided for \.{CWEB} in the source tree with \.{msgfmt} and store the |
| 681 |
resulting \.{.mo} files at an appropriate place in the file system. |
| 682 |
|
| 683 |
Plans for \TeX~Live are to store NLS catalogs inside the ``\TeX\ Directory |
| 684 |
Structure'' (TDS) and look them up with the help of the configuration variable |
| 685 |
``|TEXMFLOCALEDIR|,'' which should contain a single absolute path definition. |
| 686 |
Below we use the \Kpathsea/ function |kpse_var_expand| to evaluate this |
| 687 |
variable from various origins and redirect the ``GNU~gettext utilities'' |
| 688 |
to a possibly different location than the canonical \.{/usr/share/locale}. |
| 689 |
|
| 690 |
There are several ways to set |TEXMFLOCALEDIR|: |
| 691 |
\smallskip |
| 692 |
{\parindent5em |
| 693 |
\item{(a)} a user-set environment variable \.{TEXMFLOCALEDIR}\hfil\break |
| 694 |
(overridden by \.{TEXMFLOCALEDIR\_cweb}); |
| 695 |
\item{(b)} a line in \Kpathsea/ configuration file \.{texmf.cnf},\hfil\break |
| 696 |
e.g., \.{TEXMFLOCALEDIR=\$TEXMFMAIN/locale}\hfil\break |
| 697 |
or \.{TEXMFLOCALEDIR.cweb=\$TEXMFMAIN/locale}.\par} |
| 698 |
|
| 699 |
@<Include files@>= |
| 700 |
#if HAVE_GETTEXT |
| 701 |
#include <locale.h> /* |@!LC_MESSAGES|, |@!LC_CTYPE| */ |
| 702 |
#else |
| 703 |
#define setlocale(a,b) "" |
| 704 |
#define bindtextdomain(a,b) "" |
| 705 |
#define textdomain(a) "" |
| 706 |
#endif |
| 707 |
|
| 708 |
@ @<Set locale...@>= |
| 709 |
setlocale(LC_MESSAGES, setlocale(LC_CTYPE, "")); |
| 710 |
texmf_locale = kpse_var_expand ("${TEXMFLOCALEDIR}"); |
| 711 |
|
| 712 |
bindtextdomain("cweb", |
| 713 |
bindtextdomain("cweb-tl", |
| 714 |
bindtextdomain("web2c-help", @| |
| 715 |
strcmp(texmf_locale, "") ? |
| 716 |
texmf_locale : "/usr/share/locale"))); |
| 717 |
|
| 718 |
free(texmf_locale); |
| 719 |
textdomain("cweb"); /* the majority of |"strings"| come from ``plain \.{CWEB}'' */ |
| 720 |
@.cweb.mo@> |
| 721 |
|
| 722 |
@*1 File lookup with \Kpathsea/. The \.{CTANGLE} and \.{CWEAVE} programs from |
| 723 |
the original \.{CWEB} package use the compile-time default directory or the |
| 724 |
value of the environment variable \.{CWEBINPUTS} as an alternative place to be |
| 725 |
searched for files, if they could not be found in the current directory. |
| 726 |
|
| 727 |
This version uses the \Kpathsea/ mechanism for searching files. |
| 728 |
The directories to be searched for come from three sources: |
| 729 |
\smallskip |
| 730 |
{\parindent5em |
| 731 |
\item{(a)} a user-set environment variable \.{CWEBINPUTS} |
| 732 |
(overridden by \.{CWEBINPUTS\_cweb}); |
| 733 |
\item{(b)} a line in \Kpathsea/ configuration file \.{texmf.cnf},\hfil\break |
| 734 |
e.g., \.{CWEBINPUTS=\$TEXMFDOTDIR:\$TEXMF/texmf/cweb//}\hfil\break |
| 735 |
or \.{CWEBINPUTS.cweb=\$TEXMFDOTDIR:\$TEXMF/texmf/cweb//}; |
| 736 |
\item{(c)} compile-time default directories (specified in |
| 737 |
\.{texmf.in}),\hfil\break |
| 738 |
i.e., \.{\$TEXMFDOTDIR:\$TEXMF/texmf/cweb//}.\par} |
| 739 |
@.CWEBINPUTS@> |
| 740 |
|
| 741 |
@s const_string int |
| 742 |
@s string int |
| 743 |
|
| 744 |
@d kpse_find_cweb(name) kpse_find_file(name,kpse_cweb_format,true) |
| 745 |
|
| 746 |
@<Include files@>= |
| 747 |
#include <kpathsea/kpathsea.h> /* include every \Kpathsea/ header; |
| 748 |
|@!kpathsea_debug|, |@!const_string|, |@!string| */ |
| 749 |
#include <w2c/config.h> /* \&{integer} */ |
| 750 |
#include <lib/lib.h> /* |@!versionstring| */ |
| 751 |
|
| 752 |
@ We set |kpse_program_name| to `\.{cweb}'. This means if the variable |
| 753 |
\.{CWEBINPUTS.cweb} is present in \.{texmf.cnf} (or \.{CWEBINPUTS\_cweb} |
| 754 |
in the environment) its value will be used as the search path for filenames. |
| 755 |
This allows different flavors of \.{CWEB} to have different search paths. |
| 756 |
@.CWEBINPUTS@> |
| 757 |
|
| 758 |
@<Set up \.{PROGNAME} feature and initialize the search path mechanism@>= |
| 759 |
kpse_set_program_name(argv[0], "cweb"); |
| 760 |
|
| 761 |
@ When the files you expect are not found, the thing to do is to enable |
| 762 |
\Kpathsea/ runtime debugging by assigning to the |kpathsea_debug| variable a |
| 763 |
small number via the `\.{-d}' option. The meaning of this number is shown |
| 764 |
below. To set more than one debugging option, simply sum the corresponding |
| 765 |
numbers. |
| 766 |
\medskip |
| 767 |
\halign{\hskip5em\tt\hfil#&&\qquad\rm#\hfil\cr |
| 768 |
1&report `\.{stat}' calls\cr |
| 769 |
2&report lookups in all hash tables\cr |
| 770 |
4&report file openings and closings\cr |
| 771 |
8&report path information\cr |
| 772 |
16&report directory list\cr |
| 773 |
32&report on each file search\cr |
| 774 |
64&report values of variables being looked up\cr} |
| 775 |
\medskip |
| 776 |
Debugging output is always written to |stderr|, and begins with the string |
| 777 |
`\.{kdebug:}'. |
| 778 |
|
| 779 |
@*1 System dependent changes. The most volatile stuff comes at the very end. |
| 780 |
|
| 781 |
Modules for dealing with help messages and version info. |
| 782 |
|
| 783 |
@<Include files@>=@^system dependencies@> |
| 784 |
#define CWEB |
| 785 |
#include "help.h" /* |@!CTANGLEHELP|, |@!CWEAVEHELP|, |@!CTWILLHELP| */ |
| 786 |
|
| 787 |
@ @<Display help message and |exit|@>= |
| 788 |
cb_usagehelp(program==ctangle ? CTANGLEHELP : |
| 789 |
program==cweave ? CWEAVEHELP : CTWILLHELP); |
| 790 |
@.--help@> |
| 791 |
|
| 792 |
@ Special variants from Web2c's `\.{lib/usage.c}', adapted for |
| 793 |
\.{i18n}/\.{t10n}. We simply filter the strings through the catalogs |
| 794 |
(if available). |
| 795 |
|
| 796 |
@<Predecl...@>= |
| 797 |
static void cb_usage (const_string str);@/ |
| 798 |
static void cb_usagehelp (const_string *message);@/ |
| 799 |
|
| 800 |
@ @c |
| 801 |
static void cb_usage (const_string str) |
| 802 |
{ |
| 803 |
textdomain("cweb-tl"); |
| 804 |
@.cweb-tl.mo@> |
| 805 |
fprintf(stderr, _("%s: Need one to three file arguments.\n"), str); |
| 806 |
fprintf(stderr, _("Try `%s --help' for more information.\n"), str); |
| 807 |
@.--help@> |
| 808 |
textdomain("cweb"); |
| 809 |
@.cweb.mo@> |
| 810 |
history=fatal_message; exit(wrap_up()); |
| 811 |
} |
| 812 |
|
| 813 |
static void cb_usagehelp (const_string *message) |
| 814 |
{ |
| 815 |
textdomain("web2c-help"); |
| 816 |
@.web2c-help.mo@> |
| 817 |
while (*message) { |
| 818 |
/* empty string \.{""} has special meaning for |gettext| */ |
| 819 |
printf("%s\n", strcmp("", *message) ? _(*message) : *message); |
| 820 |
++message; |
| 821 |
} |
| 822 |
textdomain("cweb-tl"); |
| 823 |
@.cweb-tl.mo@> |
| 824 |
printf(_("\nPackage home page: %s.\n"), "https://ctan.org/pkg/cweb"); |
| 825 |
textdomain("cweb"); |
| 826 |
@.cweb.mo@> |
| 827 |
history=spotless; exit(wrap_up()); |
| 828 |
} |
| 829 |
|
| 830 |
@ The version information will not be translated, it uses a generic text |
| 831 |
template in English. |
| 832 |
|
| 833 |
@<Display version information and |exit|@>= |
| 834 |
printversionandexit(cb_banner, |
| 835 |
program == ctwill ? "Donald E. Knuth" : "Silvio Levy and Donald E. Knuth", |
| 836 |
NULL, "Contemporary development on https://github.com/ascherer/cweb.\n"); |
| 837 |
@.--version@> |
| 838 |
|
| 839 |
@ But the ``banner'' is, at least the first part. |
| 840 |
|
| 841 |
@c |
| 842 |
void cb_show_banner (void) |
| 843 |
{ |
| 844 |
textdomain("cweb-tl"); |
| 845 |
@.cweb-tl.mo@> |
| 846 |
printf("%s%s\n", _(cb_banner), versionstring); |
| 847 |
textdomain("cweb"); |
| 848 |
@.cweb.mo@> |
| 849 |
} |
| 850 |
|
| 851 |
@* Index. |
| 852 |
@z |