| 1 |
% weave.ch for C compilation using web2c. |
| 2 |
% |
| 3 |
% 11/29/82 HWT Original version. This modifies weave to allow a new |
| 4 |
% control sequence: |
| 5 |
% @=...text...@> Put ...text... verbatim on a line |
| 6 |
% by itself in the Pascal output. |
| 7 |
% (argument must fit on one line) |
| 8 |
% This control sequence facilitates putting #include "gcons.h" |
| 9 |
% (for example) in files meant for the pc compiler. |
| 10 |
% Also, there is a command line option, -c, which means that |
| 11 |
% only the modules affected by the change file are to generate |
| 12 |
% TeX output. (All the limbo stuff still goes to the output |
| 13 |
% file, as does the index and table of contents.) |
| 14 |
% 2/12/83 HWT Brought up for use with version 1.3. Uses Knuth's new |
| 15 |
% control sequences for verbatim Pascal (as above, without |
| 16 |
% the "on one line" part), and the force_line (@\) primitive. |
| 17 |
% Also, he added stuff to keep track of changed modules, and |
| 18 |
% output enough information that macros can choose only to |
| 19 |
% print changed modules. This isn't as efficient as my |
| 20 |
% implementation because I avoided outputting the text for |
| 21 |
% non-changed modules altogether, but this feature won't be |
| 22 |
% used too often (just for TeX and TeXware), so Knuth's |
| 23 |
% solution is accepted. |
| 24 |
% The change file changes that used |
| 25 |
% to implement these features have been removed. |
| 26 |
% There is a -x flag to cause WEAVE to omit cross referencing |
| 27 |
% of identifiers, and index and T.of.C. processing. |
| 28 |
% This, too, is unnecessary, for one could simply redefine some |
| 29 |
% WEB macros to avoid the printing, but there are only a couple |
| 30 |
% of easy changes, so they have been made. |
| 31 |
% 2/18 HWT Increased stack size to 400 (not for TeX-related programs). |
| 32 |
% 3/18 HWT Brought up for Version 1.5. Made it print newline at end of |
| 33 |
% run. |
| 34 |
% 4/13 PC Merged with Pavel's version, including adding a call to |
| 35 |
% exit() at the end of the program, based upon the value of |
| 36 |
% `history'. |
| 37 |
% 4/16 PC Brought up to version 1.5 released with TeX 0.97 in April 1983 |
| 38 |
% 6/29 HWT Brought up to version 1.7 released with TeX 0.99 in June 1983, |
| 39 |
% introducing a new change file format |
| 40 |
% 7/17 HWT Brought up to version 2.0 released with TeX 0.999 in July 1983 |
| 41 |
% 7/29 HWT Brought up to version 2.1 |
| 42 |
% 11/17 HWT Brought up to version 2.4 released with TeX 1.0. Made |
| 43 |
% changes to use C routines for I/O, for speedup. |
| 44 |
% 1/31 HWT Brought up to version 2.6 |
| 45 |
% 12/15/85 ETM Brought up to version 2.8 |
| 46 |
% 03/15/88 ETM Converted for use with WEB to C, and for version 2.9 of Weave. |
| 47 |
% 11/30/89 KB Version 4. |
| 48 |
% (more recent changes in the ChangeLog) |
| 49 |
|
| 50 |
@x [0.0] l.43 - WEAVE: print changes only |
| 51 |
\def\title{WEAVE} |
| 52 |
@y |
| 53 |
\let\maybe=\iffalse |
| 54 |
\def\title{WEAVE changes for C} |
| 55 |
@z |
| 56 |
|
| 57 |
@x [1.1] l.77 - Define my_name |
| 58 |
@d banner=='This is WEAVE, Version 4.5' |
| 59 |
@y |
| 60 |
@d my_name=='weave' |
| 61 |
@d banner=='This is WEAVE, Version 4.5' |
| 62 |
@z |
| 63 |
|
| 64 |
@x [1.2] l.85 - No global labels, define and call parse_arguments. |
| 65 |
calls the `|jump_out|' procedure, which goes to the label |end_of_WEAVE|. |
| 66 |
|
| 67 |
@d end_of_WEAVE = 9999 {go here to wrap it up} |
| 68 |
@y |
| 69 |
calls the `|jump_out|' procedure. |
| 70 |
@z |
| 71 |
@x [1.2] l.91 |
| 72 |
label end_of_WEAVE; {go here to finish} |
| 73 |
const @<Constants in the outer block@>@/ |
| 74 |
type @<Types in the outer block@>@/ |
| 75 |
var @<Globals in the outer block@>@/ |
| 76 |
@<Error handling procedures@>@/ |
| 77 |
procedure initialize; |
| 78 |
var @<Local variables for initialization@>@/ |
| 79 |
begin @<Set initial values@>@/ |
| 80 |
@y |
| 81 |
const @<Constants in the outer block@>@/ |
| 82 |
type @<Types in the outer block@>@/ |
| 83 |
var @<Globals in the outer block@>@/ |
| 84 |
@<Define \(|parse_arguments|@>@/ |
| 85 |
@<Error handling procedures@>@/ |
| 86 |
procedure initialize; |
| 87 |
var @<Local variables for initialization@>@/ |
| 88 |
begin |
| 89 |
kpse_set_program_name (argv[0], my_name); |
| 90 |
parse_arguments; |
| 91 |
@<Set initial values@>@/ |
| 92 |
@z |
| 93 |
|
| 94 |
@x [1.8] l.186 - Increase constants for tex2pdf, etc. |
| 95 |
@!max_bytes=45000; {|1/ww| times the number of bytes in identifiers, |
| 96 |
index entries, and module names; must be less than 65536} |
| 97 |
@!max_names=5000; {number of identifiers, index entries, and module names; |
| 98 |
must be less than 10240} |
| 99 |
@y |
| 100 |
@!max_bytes=65535; {|1/ww| times the number of bytes in identifiers, |
| 101 |
index entries, and module names; must be less than 65536} |
| 102 |
@!max_names=10239; {number of identifiers, index entries, and module names; |
| 103 |
must be less than 10240} |
| 104 |
@z |
| 105 |
@x [1.8] l.190 |
| 106 |
@!max_modules=2000;{greater than the total number of modules} |
| 107 |
@!hash_size=353; {should be prime} |
| 108 |
@!buf_size=100; {maximum length of input line} |
| 109 |
@!longest_name=400; {module names shouldn't be longer than this} |
| 110 |
@!long_buf_size=500; {|buf_size+longest_name|} |
| 111 |
@!line_length=80; {lines of \TeX\ output have at most this many characters, |
| 112 |
@y |
| 113 |
@!max_modules=4000; {greater than the total number of modules} |
| 114 |
@!hash_size=8501; {should be prime} |
| 115 |
@!buf_size=1000; {maximum length of input line} |
| 116 |
@!longest_name=10000; {module names shouldn't be longer than this} |
| 117 |
@!long_buf_size=buf_size+longest_name; {C arithmetic in \PASCAL\ constant} |
| 118 |
@!line_length=80; {lines of \TeX\ output have at most this many characters, |
| 119 |
@z |
| 120 |
@x [1.8] l.197 |
| 121 |
@!max_refs=30000; {number of cross references; must be less than 65536} |
| 122 |
@!max_toks=30000; {number of symbols in \PASCAL\ texts being parsed; |
| 123 |
must be less than 65536} |
| 124 |
@!max_texts=2000; {number of phrases in \PASCAL\ texts being parsed; |
| 125 |
must be less than 10240} |
| 126 |
@!max_scraps=1000; {number of tokens in \PASCAL\ texts being parsed} |
| 127 |
@!stack_size=200; {number of simultaneous output levels} |
| 128 |
@y |
| 129 |
@!max_refs=65535; {number of cross references; must be less than 65536} |
| 130 |
@!max_toks=65535; {number of symbols in \PASCAL\ texts being parsed; |
| 131 |
must be less than 65536} |
| 132 |
@!max_texts=10239; {number of phrases in \PASCAL\ texts being parsed; |
| 133 |
must be less than 10240} |
| 134 |
@!max_scraps=10000; {number of tokens in \PASCAL\ texts being parsed} |
| 135 |
@!stack_size=2000; {number of simultaneous output levels} |
| 136 |
@z |
| 137 |
|
| 138 |
% [12] The text_char type is used as an array index into xord. The |
| 139 |
% default type `char' produces signed integers, which are bad array |
| 140 |
% indices in C. |
| 141 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 142 |
@x [2.12] l.307 |
| 143 |
@d text_char == char {the data type of characters in text files} |
| 144 |
@y |
| 145 |
@d text_char == ASCII_code {the data type of characters in text files} |
| 146 |
@z |
| 147 |
|
| 148 |
@x [2.17] l.488 - enable maximum character set |
| 149 |
for i:=1 to @'37 do xchr[i]:=' '; |
| 150 |
for i:=@'200 to @'377 do xchr[i]:=' '; |
| 151 |
@y |
| 152 |
for i:=1 to @'37 do xchr[i]:=chr(i); |
| 153 |
for i:=@'200 to @'377 do xchr[i]:=chr(i); |
| 154 |
@z |
| 155 |
|
| 156 |
@x [3.20] l.514 - Terminal I/O. |
| 157 |
@d print(#)==write(term_out,#) {`|print|' means write on the terminal} |
| 158 |
@y |
| 159 |
@d term_out==stdout |
| 160 |
@d print(#)==write(term_out,#) {`|print|' means write on the terminal} |
| 161 |
@z |
| 162 |
@x [3.20] l.521 |
| 163 |
@<Globals...@>= |
| 164 |
@!term_out:text_file; {the terminal as an output file} |
| 165 |
@y |
| 166 |
@z |
| 167 |
|
| 168 |
@x [3.21] l.524 - Don't initialize the terminal. |
| 169 |
@ Different systems have different ways of specifying that the output on a |
| 170 |
certain file will appear on the user's terminal. Here is one way to do this |
| 171 |
on the \PASCAL\ system that was used in \.{TANGLE}'s initial development: |
| 172 |
@^system dependencies@> |
| 173 |
|
| 174 |
@<Set init...@>= |
| 175 |
rewrite(term_out,'TTY:'); {send |term_out| output to the terminal} |
| 176 |
@y |
| 177 |
@ Different systems have different ways of specifying that the output on a |
| 178 |
certain file will appear on the user's terminal. |
| 179 |
@^system dependencies@> |
| 180 |
|
| 181 |
@<Set init...@>= |
| 182 |
{nothing need be done} |
| 183 |
@z |
| 184 |
|
| 185 |
@x [3.22] l.537 - `break' is `fflush'. |
| 186 |
@d update_terminal == break(term_out) {empty the terminal output buffer} |
| 187 |
@y |
| 188 |
@d update_terminal == fflush(term_out) {empty the terminal output buffer} |
| 189 |
@z |
| 190 |
|
| 191 |
@x [3.24] l.546 - Open input files. |
| 192 |
@ The following code opens the input files. Since these files were listed |
| 193 |
in the program header, we assume that the \PASCAL\ runtime system has |
| 194 |
already checked that suitable file names have been given; therefore no |
| 195 |
additional error checking needs to be done. We will see below that |
| 196 |
\.{WEAVE} reads through the entire input twice. |
| 197 |
@^system dependencies@> |
| 198 |
|
| 199 |
@p procedure open_input; {prepare to read |web_file| and |change_file|} |
| 200 |
begin reset(web_file); reset(change_file); |
| 201 |
end; |
| 202 |
@y |
| 203 |
@ The following code opens the input files. |
| 204 |
This is called after the filename variables have been set appropriately. |
| 205 |
@^system dependencies@> |
| 206 |
|
| 207 |
@p procedure open_input; {prepare to read |web_file| and |change_file|} |
| 208 |
begin web_file := kpse_open_file(web_name, kpse_web_format); |
| 209 |
if chg_name then change_file := kpse_open_file(chg_name, kpse_web_format); |
| 210 |
end; |
| 211 |
@z |
| 212 |
|
| 213 |
@x [3.26] l.569 - Opening the .tex file. |
| 214 |
rewrite(tex_file); |
| 215 |
@y |
| 216 |
rewrite(tex_file,tex_name); |
| 217 |
@z |
| 218 |
|
| 219 |
@x [3.28] l.597 - web2c doesn't understand f^. |
| 220 |
begin buffer[limit]:=xord[f^]; get(f); |
| 221 |
incr(limit); |
| 222 |
if buffer[limit-1]<>" " then final_limit:=limit; |
| 223 |
if limit=buf_size then |
| 224 |
begin while not eoln(f) do get(f); |
| 225 |
@y |
| 226 |
begin buffer[limit]:=xord[getc(f)]; |
| 227 |
incr(limit); |
| 228 |
if buffer[limit-1]<>" " then final_limit:=limit; |
| 229 |
if limit=buf_size then |
| 230 |
begin while not eoln(f) do vgetc(f); |
| 231 |
@z |
| 232 |
|
| 233 |
@x [4.33] l.678 - Fix jump_out |
| 234 |
@ The |jump_out| procedure just cuts across all active procedure levels |
| 235 |
and jumps out of the program. This is the only non-local \&{goto} statement |
| 236 |
in \.{WEAVE}. It is used when no recovery from a particular error has |
| 237 |
been provided. |
| 238 |
|
| 239 |
Some \PASCAL\ compilers do not implement non-local |goto| statements. |
| 240 |
@^system dependencies@> |
| 241 |
In such cases the code that appears at label |end_of_WEAVE| should be |
| 242 |
copied into the |jump_out| procedure, followed by a call to a system procedure |
| 243 |
that terminates the program. |
| 244 |
@y |
| 245 |
@ The |jump_out| procedure just cuts across all active procedure levels |
| 246 |
and jumps out of the program. |
| 247 |
It is used when no recovery from a particular error has |
| 248 |
been provided. |
| 249 |
@z |
| 250 |
@x [4.33] l.689 |
| 251 |
@d fatal_error(#)==begin new_line; print(#); error; mark_fatal; jump_out; |
| 252 |
end |
| 253 |
|
| 254 |
@<Error handling...@>= |
| 255 |
procedure jump_out; |
| 256 |
begin goto end_of_WEAVE; |
| 257 |
end; |
| 258 |
@y |
| 259 |
@d fatal_error(#)==begin new_line; write(stderr, #); |
| 260 |
error; mark_fatal; jump_out; |
| 261 |
end |
| 262 |
|
| 263 |
@<Error handling...@>= |
| 264 |
procedure jump_out; |
| 265 |
begin |
| 266 |
stat @<Print statistics about memory usage@>;@+tats@;@/ |
| 267 |
@t\4\4@>{here files should be closed if the operating system requires it} |
| 268 |
@<Print the job |history|@>; |
| 269 |
new_line; |
| 270 |
if (history <> spotless) and (history <> harmless_message) then |
| 271 |
uexit(1) |
| 272 |
else |
| 273 |
uexit(0); |
| 274 |
end; |
| 275 |
@z |
| 276 |
|
| 277 |
@x [5.37] l.726 - extend 'byte_mem' for "pdftex.web + pdftex-final.ch" |
| 278 |
there are programs that need more than 65536 bytes; \TeX\ is one of these. |
| 279 |
@y |
| 280 |
there are programs that need more than 65536 bytes; \TeX\ is one of these |
| 281 |
(and the pdf\TeX\ variant even requires more than twice that amount when |
| 282 |
its ``final'' change file is applied). |
| 283 |
@z |
| 284 |
@x [5.37] l.729 |
| 285 |
is either 0 or 1. (For generality, the first index is actually allowed to |
| 286 |
run between 0 and |ww-1|, where |ww| is defined to be 2; the program will |
| 287 |
@y |
| 288 |
is either 0, 1 or 2. (For generality, the first index is actually allowed to |
| 289 |
run between 0 and |ww-1|, where |ww| is defined to be 3; the program will |
| 290 |
@z |
| 291 |
@x [5.37] l.734 |
| 292 |
@d ww=2 {we multiply the byte capacity by approximately this amount} |
| 293 |
@y |
| 294 |
@d ww=3 {we multiply the byte capacity by approximately this amount} |
| 295 |
@z |
| 296 |
|
| 297 |
@x [5.50] l.910 - don't enter xrefs if no_xref set |
| 298 |
@d append_xref(#)==if xref_ptr=max_refs then overflow('cross reference') |
| 299 |
else begin incr(xref_ptr); num(xref_ptr):=#; |
| 300 |
end |
| 301 |
|
| 302 |
@p procedure new_xref(@!p:name_pointer); |
| 303 |
label exit; |
| 304 |
var q:xref_number; {pointer to previous cross reference} |
| 305 |
@!m,@!n: sixteen_bits; {new and previous cross-reference value} |
| 306 |
begin if (reserved(p)or(byte_start[p]+1=byte_start[p+ww]))and |
| 307 |
@y |
| 308 |
If the user has sent the |no_xref| flag (the `\.{-x}' option on the |
| 309 |
command line), then it is unnecessary to keep track of cross references |
| 310 |
for identifiers. |
| 311 |
If one were careful, one could probably make more changes around module |
| 312 |
100 to avoid a lot of identifier looking up. |
| 313 |
|
| 314 |
@d append_xref(#)==if xref_ptr=max_refs then overflow('cross reference') |
| 315 |
else begin incr(xref_ptr); num(xref_ptr):=#; |
| 316 |
end |
| 317 |
|
| 318 |
@p procedure new_xref(@!p:name_pointer); |
| 319 |
label exit; |
| 320 |
var q:xref_number; {pointer to previous cross-reference} |
| 321 |
@!m,@!n: sixteen_bits; {new and previous cross-reference value} |
| 322 |
begin if no_xref then return; |
| 323 |
if (reserved(p)or(byte_start[p]+1=byte_start[p+ww]))and |
| 324 |
@z |
| 325 |
|
| 326 |
@x [9.82] l.1448 - Guard against get_line() when parsing a module name |
| 327 |
@p procedure get_line; {inputs the next line} |
| 328 |
label restart; |
| 329 |
begin restart:if changing then |
| 330 |
@<Read from |change_file| and maybe turn off |changing|@>; |
| 331 |
if not changing then |
| 332 |
begin @<Read from |web_file| and maybe turn on |changing|@>; |
| 333 |
if changing then goto restart; |
| 334 |
end; |
| 335 |
loc:=0; buffer[limit]:=" "; |
| 336 |
end; |
| 337 |
@y |
| 338 |
@p procedure get_line; {inputs the next line} |
| 339 |
label restart; |
| 340 |
begin |
| 341 |
if in_module_name then begin |
| 342 |
err_print('! Call to get_line when parsing a module name'); |
| 343 |
loc:=limit; {Reset to the |'|'| at the end of the line} |
| 344 |
end else |
| 345 |
begin restart:if changing then |
| 346 |
@<Read from |change_file| and maybe turn off |changing|@>; |
| 347 |
if not changing then |
| 348 |
begin @<Read from |web_file| and maybe turn on |changing|@>; |
| 349 |
if changing then goto restart; |
| 350 |
end; |
| 351 |
loc:=0; buffer[limit]:=" "; |
| 352 |
end; |
| 353 |
end; |
| 354 |
@z |
| 355 |
|
| 356 |
@x [12.124] l.2199 |
| 357 |
`\.{\\input webmac}'. |
| 358 |
@.\\input webmac@> |
| 359 |
@.webmac@> |
| 360 |
@y |
| 361 |
`\.{\\input webmac}'. |
| 362 |
@.\\input webmac@> |
| 363 |
@.webmac@> |
| 364 |
|
| 365 |
If the user has sent the |pdf_output| flag (the `\.{-p}' option on the |
| 366 |
command line), then we use alternative \TeX\ macros from `\.{\\input pwebmac}'. |
| 367 |
@.\\input pwebmac@> |
| 368 |
@.pwebmac@> |
| 369 |
@z |
| 370 |
@x [12.124] l.2204 |
| 371 |
out_ptr:=1; out_line:=1; out_buf[1]:="c"; write(tex_file,'\input webma'); |
| 372 |
@y |
| 373 |
out_ptr:=1; out_line:=1; out_buf[1]:="c"; |
| 374 |
if pdf_output then write(tex_file,'\input pwebma') |
| 375 |
else write(tex_file,'\input webma'); |
| 376 |
@z |
| 377 |
|
| 378 |
@x [12.127] l.2234 - see https://tug.org/pipermail/tex-live/2023-July/049306.htm |
| 379 |
preceded by another backslash. In the latter case, a |"%"| is output at |
| 380 |
the break. |
| 381 |
@y |
| 382 |
preceded by another backslash or a \TeX\ comment marker. In the latter case, a |
| 383 |
|'%'| is output at the break. |
| 384 |
@z |
| 385 |
@x [12.127] l.2248 - deal with malign user input |
| 386 |
if (d="\")and(out_buf[k-1]<>"\") then {in this case |k>1|} |
| 387 |
@y |
| 388 |
if (d="\")and(out_buf[k-1]<>"\")and(out_buf[k-1]<>"%") then |
| 389 |
{in this case |k>1|} |
| 390 |
@z |
| 391 |
|
| 392 |
@x [15.148] l.3007 - Purify 'reduce' and 'squash'. |
| 393 |
@d production(#)==@!debug prod(#) gubed; goto found |
| 394 |
@d reduce(#)==red(#); production |
| 395 |
@d production_end(#)==@!debug prod(#) gubed; goto found; |
| 396 |
end |
| 397 |
@d squash(#)==begin sq(#); production_end |
| 398 |
@y |
| 399 |
@d production(#)==@!debug prod(#) gubed; goto found; end |
| 400 |
@d reduce(#)==begin red(#); production |
| 401 |
@d squash(#)==begin sq(#); production |
| 402 |
@z |
| 403 |
|
| 404 |
@x [15.151] l.3100 - Special case 'k=0'. |
| 405 |
else if cat[pp+1]=simp then squash(pp+1,1,math,0)(4) |
| 406 |
@y |
| 407 |
else if cat[pp+1]=simp then reduce(pp+1,0,math,0)(4) |
| 408 |
@z |
| 409 |
|
| 410 |
@x [15.157] l.3151 - Special case 'k=0'. |
| 411 |
squash(pp,1,intro,-3)(14) |
| 412 |
@y |
| 413 |
reduce(pp,0,intro,-3)(14) |
| 414 |
@z |
| 415 |
|
| 416 |
@x [15.161] l.3193 - Special case 'k=0'. |
| 417 |
else squash(pp,1,simp,-2)(25) |
| 418 |
@y |
| 419 |
else reduce(pp,0,simp,-2)(25) |
| 420 |
@z |
| 421 |
|
| 422 |
@x [15.162] l.3212 - Special case 'k=0'. |
| 423 |
else if cat[pp+1]=simp then squash(pp+1,1,math,0)(35) |
| 424 |
@y |
| 425 |
else if cat[pp+1]=simp then reduce(pp+1,0,math,0)(35) |
| 426 |
@z |
| 427 |
|
| 428 |
@x [15.166] l.3272 - Special case 'k=0'. |
| 429 |
squash(pp,1,terminator,-3)(42) |
| 430 |
@y |
| 431 |
reduce(pp,0,terminator,-3)(42) |
| 432 |
@z |
| 433 |
|
| 434 |
@x [15.167] l.3275 - Special case 'k=0'. |
| 435 |
if cat[pp+1]=close then squash(pp,1,stmt,-2)(43) |
| 436 |
@y |
| 437 |
if cat[pp+1]=close then reduce(pp,0,stmt,-2)(43) |
| 438 |
@z |
| 439 |
@x [15.167] l.3277 - Apply 'squash(...,2,...)'. |
| 440 |
begin app(force); app(backup); app2(pp); reduce(pp,2,intro,-3)(44); |
| 441 |
@y |
| 442 |
begin app(force); app(backup); squash(pp,2,intro,-3)(44); |
| 443 |
@z |
| 444 |
|
| 445 |
@x [15.169] l.3291 - Special case 'k=0'. |
| 446 |
squash(pp,1,stmt,-2)(50) |
| 447 |
@y |
| 448 |
reduce(pp,0,stmt,-2)(50) |
| 449 |
@z |
| 450 |
|
| 451 |
@x [15.170] l.3294 - Special case 'k=0'. |
| 452 |
if cat[pp+1]=beginning then squash(pp,1,stmt,-2)(51) |
| 453 |
@y |
| 454 |
if cat[pp+1]=beginning then reduce(pp,0,stmt,-2)(51) |
| 455 |
@z |
| 456 |
|
| 457 |
@x [15.172] l.3325 - Move special case 'k=1' from 'squash' to special case 'k=0' here. |
| 458 |
scrap list. |
| 459 |
@y |
| 460 |
scrap list. This procedure takes advantage of the simplification that |
| 461 |
occurs when |k=0|. |
| 462 |
@z |
| 463 |
@x [15.172] l.3330 |
| 464 |
begin cat[j]:=c; trans[j]:=text_ptr; freeze_text; |
| 465 |
@y |
| 466 |
begin cat[j]:=c; |
| 467 |
if k>0 then |
| 468 |
begin |
| 469 |
trans[j]:=text_ptr; freeze_text; |
| 470 |
end; |
| 471 |
@z |
| 472 |
@x [15.172] l.3337 - Fix spacing. |
| 473 |
@<Change |pp| to $\max(|scrap_base|,|pp+d|)$@>; |
| 474 |
@y |
| 475 |
@<Change |pp| to $\max(|scrap_base|,\,|pp+d|)$@>; |
| 476 |
@z |
| 477 |
|
| 478 |
@x [15.173] l.3340 - Fix spacing. |
| 479 |
@ @<Change |pp| to $\max(|scrap_base|,|pp+d|)$@>= |
| 480 |
@y |
| 481 |
@ @<Change |pp| to $\max(|scrap_base|,\,|pp+d|)$@>= |
| 482 |
@z |
| 483 |
|
| 484 |
@x [15.174] l.3344 - Rewrite 'squash' to match description in section [148]. |
| 485 |
@ Similarly, the `|squash|' macro invokes a procedure called `|sq|'. This |
| 486 |
procedure takes advantage of the simplification that occurs when |k=1|. |
| 487 |
@y |
| 488 |
@ Similarly, the `|squash|' macro invokes a procedure called `|sq|', which |
| 489 |
combines |app|${}_k$ and |red| for matching numbers~|k|. |
| 490 |
@z |
| 491 |
@x [15.174] l.3349 |
| 492 |
var i:0..max_scraps; {index into scrap memory} |
| 493 |
begin if k=1 then |
| 494 |
begin cat[j]:=c; @<Change |pp|...@>; |
| 495 |
end |
| 496 |
else begin for i:=j to j+k-1 do |
| 497 |
begin app1(i); |
| 498 |
end; |
| 499 |
red(j,k,c,d); |
| 500 |
end; |
| 501 |
@y |
| 502 |
begin |
| 503 |
case k of |
| 504 |
1: begin app1(j);@+ end; |
| 505 |
2: begin app2(j);@+ end; |
| 506 |
3: begin app3(j);@+ end; |
| 507 |
othercases confusion('squash') |
| 508 |
endcases;@/ |
| 509 |
red(j,k,c,d); |
| 510 |
@z |
| 511 |
|
| 512 |
@x [16.185] l.3555 |
| 513 |
string,verbatim: @<Append a \(string scrap@>; |
| 514 |
identifier: @<Append an identifier scrap@>; |
| 515 |
TeX_string: @<Append a \TeX\ string scrap@>; |
| 516 |
@y |
| 517 |
string,verbatim: @<Append \(a \(string scrap@>; |
| 518 |
identifier: @<Append \(an identifier scrap@>; |
| 519 |
TeX_string: @<Append \(a \TeX\ string scrap@>; |
| 520 |
@z |
| 521 |
|
| 522 |
@x [16.189] l.3652 |
| 523 |
@<Append a \(string scrap@>= |
| 524 |
@y |
| 525 |
@<Append \(a \(string scrap@>= |
| 526 |
@z |
| 527 |
|
| 528 |
@x [16.190] l.3690 |
| 529 |
@ @<Append a \TeX\ string scrap@>= |
| 530 |
@y |
| 531 |
@ @<Append \(a \TeX\ string scrap@>= |
| 532 |
@z |
| 533 |
|
| 534 |
@x [16.191] l.3697 |
| 535 |
@ @<Append an identifier scrap@>= |
| 536 |
@y |
| 537 |
@ @<Append \(an identifier scrap@>= |
| 538 |
@z |
| 539 |
|
| 540 |
@x [16.193] l.3731 |
| 541 |
else_like: begin @<Append |terminator| if not already present@>; |
| 542 |
@y |
| 543 |
else_like: begin @<Append \(|terminator| if not already present@>; |
| 544 |
@z |
| 545 |
@x [16.193] l.3734 |
| 546 |
end_like: begin @<Append |term...@>; |
| 547 |
@y |
| 548 |
end_like: begin @<Append \(|term...@>; |
| 549 |
@z |
| 550 |
@x [16.193] l.3752 |
| 551 |
until_like: begin @<Append |term...@>; |
| 552 |
@y |
| 553 |
until_like: begin @<Append \(|term...@>; |
| 554 |
@z |
| 555 |
|
| 556 |
@x [16.194] l.3762 |
| 557 |
@<Append |termin...@>= |
| 558 |
@y |
| 559 |
@<Append \(|termin...@>= |
| 560 |
@z |
| 561 |
|
| 562 |
@x [17.202] l.3913 - Guard against get_line() while parsing module name |
| 563 |
@ @d cur_end==cur_state.end_field {current ending location in |tok_mem|} |
| 564 |
@y |
| 565 |
@ The module name Pascal parser re-uses the buffer and |get_next| |
| 566 |
infrastructure. However we don't want |get_next| to cause the next source line |
| 567 |
to be read with |get_line|, so we set a flag to trigger an error and recover if |
| 568 |
this happens. |
| 569 |
|
| 570 |
@d cur_end==cur_state.end_field {current ending location in |tok_mem|} |
| 571 |
@z |
| 572 |
@x [17.202] l.3919 - Guard against get_line() while parsing module name |
| 573 |
@!cur_state:output_state; {|cur_end|, |cur_tok|, |cur_mode|} |
| 574 |
@y |
| 575 |
@!in_module_name:boolean; {are we scanning a module name?} |
| 576 |
@!cur_state:output_state; {|cur_end|, |cur_tok|, |cur_mode|} |
| 577 |
@z |
| 578 |
|
| 579 |
@x [17.203] l.3925 - Guard against get_line() while parsing module name |
| 580 |
@ @<Set init...@>=stat max_stack_ptr:=0;@+tats |
| 581 |
@y |
| 582 |
@ @<Set init...@>=@!in_module_name:=false; |
| 583 |
stat max_stack_ptr:=0;@+tats |
| 584 |
@z |
| 585 |
|
| 586 |
@x [17.214] l.4170 - Guard against get_line() while parsing module name |
| 587 |
buffer[limit]:="|"; output_Pascal; |
| 588 |
@y |
| 589 |
buffer[limit]:="|"; |
| 590 |
in_module_name:=true; output_Pascal; in_module_name:=false; |
| 591 |
@z |
| 592 |
|
| 593 |
@x [18.222] l.4285 - Reject verbatim in TeX part |
| 594 |
TeX_string,xref_roman,xref_wildcard,xref_typewriter,module_name: |
| 595 |
begin loc:=loc-2; next_control:=get_next; {skip to \.{@@>}} |
| 596 |
if next_control=TeX_string then |
| 597 |
err_print('! TeX string should be in Pascal text only'); |
| 598 |
@.TeX string should be...@> |
| 599 |
end; |
| 600 |
@y |
| 601 |
TeX_string,xref_roman,xref_wildcard,xref_typewriter,module_name,verbatim: |
| 602 |
begin loc:=loc-2; next_control:=get_next; {skip to \.{@@>}} |
| 603 |
if next_control=TeX_string then |
| 604 |
err_print('! TeX string should be in Pascal text only') |
| 605 |
@.TeX string should be...@> |
| 606 |
else if next_control=verbatim then |
| 607 |
err_print('! Verbatim string should be in Pascal text only'); |
| 608 |
@.Verbatim string should be...@> |
| 609 |
end; |
| 610 |
@z |
| 611 |
|
| 612 |
@x [19.239] l.4537 - omit index and module names if no_xref set |
| 613 |
@<Phase III: Output the cross-reference index@>= |
| 614 |
@y |
| 615 |
If the user has set the |no_xref| flag (the `\.{-x} option on the |
| 616 |
command line), just finish off the page, omitting the index, module |
| 617 |
name list, and table of contents. |
| 618 |
|
| 619 |
@<Phase III: Output the cross-reference index@>= |
| 620 |
if no_xref then begin |
| 621 |
finish_line; |
| 622 |
out("\"); out5("v")("f")("i")("l")("l"); |
| 623 |
out4("\")("e")("n")("d"); |
| 624 |
finish_line; |
| 625 |
end |
| 626 |
else begin |
| 627 |
@z |
| 628 |
@x [19.239] l.4551 |
| 629 |
print('Done.'); |
| 630 |
@y |
| 631 |
end; |
| 632 |
print('Done.'); |
| 633 |
@z |
| 634 |
|
| 635 |
@x [20.258] l.4782 - term_in == stdin, when debugging. |
| 636 |
any error stop will set |debug_cycle| to zero. |
| 637 |
@y |
| 638 |
any error stop will set |debug_cycle| to zero. |
| 639 |
|
| 640 |
@d term_in==stdin |
| 641 |
@z |
| 642 |
@x [20.258] l.4790 |
| 643 |
@!term_in:text_file; {the user's terminal as an input file} |
| 644 |
@y |
| 645 |
@z |
| 646 |
|
| 647 |
@x [20.259] l.4798 - Take out reset(term_in) |
| 648 |
reset(term_in,'TTY:','/I'); {open |term_in| as the terminal, don't do a |get|} |
| 649 |
@y |
| 650 |
@z |
| 651 |
|
| 652 |
@x [21.261] l.4851 - print newline at end of run and exit based upon value of history |
| 653 |
print_ln(banner); {print a ``banner line''} |
| 654 |
@y |
| 655 |
print (banner); {print a ``banner line''} |
| 656 |
print_ln (version_string); |
| 657 |
@z |
| 658 |
@x [21.261] l.4856 |
| 659 |
end_of_WEAVE: |
| 660 |
stat @<Print statistics about memory usage@>;@+tats@;@/ |
| 661 |
@t\4\4@>{here files should be closed if the operating system requires it} |
| 662 |
@<Print the job |history|@>; |
| 663 |
end. |
| 664 |
@y |
| 665 |
jump_out; |
| 666 |
end. |
| 667 |
@z |
| 668 |
|
| 669 |
@x [22.264] l.4886 - System-dependent changes. |
| 670 |
This module should be replaced, if necessary, by changes to the program |
| 671 |
that are necessary to make \.{WEAVE} work at a particular installation. |
| 672 |
It is usually best to design your change file so that all changes to |
| 673 |
previous modules preserve the module numbering; then everybody's version |
| 674 |
will be consistent with the printed program. More extensive changes, |
| 675 |
which introduce new modules, can be inserted here; then only the index |
| 676 |
itself will get a new module number. |
| 677 |
@^system dependencies@> |
| 678 |
@y |
| 679 |
Parse a Unix-style command line. |
| 680 |
|
| 681 |
@d argument_is (#) == (strcmp (long_options[option_index].name, #) = 0) |
| 682 |
|
| 683 |
@<Define \(|parse_arguments|@> = |
| 684 |
procedure parse_arguments; |
| 685 |
const n_options = 4; {Pascal won't count array lengths for us.} |
| 686 |
var @!long_options: array[0..n_options] of getopt_struct; |
| 687 |
@!getopt_return_val: integer; |
| 688 |
@!option_index: c_int_type; |
| 689 |
@!current_option: 0..n_options; |
| 690 |
begin |
| 691 |
@<Define the option table@>; |
| 692 |
repeat |
| 693 |
getopt_return_val := getopt_long_only (argc, argv, '', long_options, |
| 694 |
address_of (option_index)); |
| 695 |
if getopt_return_val = -1 then begin |
| 696 |
do_nothing; {End of arguments; we exit the loop below.} |
| 697 |
|
| 698 |
end else if getopt_return_val = "?" then begin |
| 699 |
usage (my_name); |
| 700 |
|
| 701 |
end else if argument_is ('help') then begin |
| 702 |
usage_help (WEAVE_HELP, nil); |
| 703 |
|
| 704 |
end else if argument_is ('version') then begin |
| 705 |
print_version_and_exit (banner, nil, 'D.E. Knuth', nil); |
| 706 |
|
| 707 |
end; {Else it was a flag; |getopt| has already done the assignment.} |
| 708 |
until getopt_return_val = -1; |
| 709 |
|
| 710 |
{Now |optind| is the index of first non-option on the command line.} |
| 711 |
if (optind + 1 > argc) or (optind + 3 < argc) then begin |
| 712 |
write_ln (stderr, my_name, ': Need one to three file arguments.'); |
| 713 |
usage (my_name); |
| 714 |
end; |
| 715 |
|
| 716 |
{Supply |".web"| and |".ch"| extensions if necessary.} |
| 717 |
web_name := extend_filename (cmdline (optind), 'web'); |
| 718 |
if optind + 2 <= argc then begin |
| 719 |
if strcmp(char_to_string('-'), cmdline (optind + 1)) <> 0 then |
| 720 |
chg_name := extend_filename (cmdline (optind + 1), 'ch'); |
| 721 |
end; |
| 722 |
|
| 723 |
{Change |".web"| to |".tex"| and use the current directory.} |
| 724 |
if optind + 3 = argc then |
| 725 |
tex_name := extend_filename (cmdline (optind + 2), 'tex') |
| 726 |
else |
| 727 |
tex_name := basename_change_suffix (web_name, '.web', '.tex'); |
| 728 |
end; |
| 729 |
|
| 730 |
@ Here are the options we allow. The first is one of the standard GNU options. |
| 731 |
@.-help@> |
| 732 |
|
| 733 |
@<Define the option...@> = |
| 734 |
current_option := 0; |
| 735 |
long_options[current_option].name := 'help'; |
| 736 |
long_options[current_option].has_arg := 0; |
| 737 |
long_options[current_option].flag := 0; |
| 738 |
long_options[current_option].val := 0; |
| 739 |
incr (current_option); |
| 740 |
|
| 741 |
@ Another of the standard options. |
| 742 |
@.-version@> |
| 743 |
|
| 744 |
@<Define the option...@> = |
| 745 |
long_options[current_option].name := 'version'; |
| 746 |
long_options[current_option].has_arg := 0; |
| 747 |
long_options[current_option].flag := 0; |
| 748 |
long_options[current_option].val := 0; |
| 749 |
incr (current_option); |
| 750 |
|
| 751 |
@ Use alternative \TeX\ macros more suited for {\mc PDF} output? |
| 752 |
@.-p@> |
| 753 |
|
| 754 |
@<Define the option...@> = |
| 755 |
long_options[current_option].name := char_to_string ('p'); |
| 756 |
long_options[current_option].has_arg := 0; |
| 757 |
long_options[current_option].flag := address_of (pdf_output); |
| 758 |
long_options[current_option].val := 1; |
| 759 |
incr (current_option); |
| 760 |
|
| 761 |
@ Omit cross-referencing? |
| 762 |
@.-x@> |
| 763 |
|
| 764 |
@<Define the option...@> = |
| 765 |
long_options[current_option].name := char_to_string ('x'); |
| 766 |
long_options[current_option].has_arg := 0; |
| 767 |
long_options[current_option].flag := address_of (no_xref); |
| 768 |
long_options[current_option].val := 1; |
| 769 |
incr (current_option); |
| 770 |
|
| 771 |
@ @<Global...@> = |
| 772 |
@!no_xref:c_int_type; |
| 773 |
@!pdf_output:c_int_type; |
| 774 |
|
| 775 |
@ An element with all zeros always ends the list. |
| 776 |
|
| 777 |
@<Define the option...@> = |
| 778 |
long_options[current_option].name := 0; |
| 779 |
long_options[current_option].has_arg := 0; |
| 780 |
long_options[current_option].flag := 0; |
| 781 |
long_options[current_option].val := 0; |
| 782 |
|
| 783 |
@ Global filenames. |
| 784 |
|
| 785 |
@<Global...@> = |
| 786 |
@!web_name,@!chg_name,@!tex_name:const_c_string; |
| 787 |
@z |