Debian Codegraph @

texk/web2c/alephdir/com16bit.ch

raw
1 % com16bit.ch: Aleph version of file tex.ch
2 %
3 % tex.ch for C compilation with web2c, derived from various other change files.
4 % By Tim Morgan, UC Irvine ICS Department, and many others.
5 %
6 % (05/28/86) ETM Started with TeX 2.0
7 % (06/03/87) ETM Brought up to TeX 2.2
8 % (09/26/87) ETM Brought up to TeX 2.3
9 % (10/01/87) ETM Brought up to TeX 2.5
10 % (12/21/87) ETM Brought up to TeX 2.7
11 % (01/14/88) ETM Brought up to TeX 2.9
12 % (02/20/88) PAM Revised format and module numbers
13 % (03/01/88) ETM Eliminated some unused variables and unnecesary tests
14 % (05/09/88) ETM Added yet another casting bug fix
15 % (06/21/88) ETM Brought up to TeX version 2.93
16 % (12/11/88) ETM Brought up to TeX version 2.94
17 % (01/12/89) PAM Brought up to TeX version 2.95
18 % (02/14/89) ETM Brought up to TeX version 2.96
19 % (03/10/89) ETM Brought up to TeX version 2.98
20 % (07/06/89) ETM Brought up to TeX version 2.991
21 % (11/30/89) KB To version 2.992 (8-bit).
22 % (01/10/90) SR To version 2.993.
23 % (03/27/90) KY To version 3.0.
24 % (more recent changes in ChangeLog)
25 %
26 % The TeX program is copyright (C) 1982 by D. E. Knuth.
27 % TeX is a trademark of the American Mathematical Society.
28 %
29 % The module numbers in this change file refer to TEX.WEB 3.141592 as
30 % of March, 1995 (published as Donald E. Knuth, TeX: The Program,
31 % Volume B of Computers & Typesetting).
32
33 @x [0.0] l.83 - WEAVE: print changes only.
34 \def\?##1]{\hbox to 1in{\hfil##1.\ }}
35 }
36 @y 83
37 \def\?##1]{\hbox{Changes to \hbox to 1em{\hfil##1}.\ }}
38 }
39 \let\maybe=\iffalse
40 @z
41
42 @x
43 @d banner=='This is Aleph, Version 3.141592653-',Omega_version_banner,'-',eTeX_version_banner,'-',Aleph_version_banner {printed when \TeX\ starts}
44 @y
45 @d banner=='This is Aleph, Version 3.141592653-',Omega_version_banner,'-',eTeX_version_banner,'-',Aleph_version_banner {printed when \TeX\ starts}
46 @d banner_k==banner {Web2C announces itself}
47 @z
48
49 @x [1.4] l.233 - program header
50 Actually the heading shown here is not quite normal: The |program| line
51 does not mention any |output| file, because \ph\ would ask the \TeX\ user
52 to specify a file name if |output| were specified here.
53 @:PASCAL H}{\ph@>
54 @^system dependencies@>
55 @y
56 @z
57
58 @x [1.4] l.243 - labels in outer block not needed
59 program OMEGA; {all file names are defined dynamically}
60 label @<Labels in the outer block@>@/
61 @y
62 program OMEGA; {all file names are defined dynamically}
63 @z
64
65 @x [1.6] l.267 - labels in outer block not needed
66 @ Three labels must be declared in the main program, so we give them
67 symbolic names.
68
69 @d start_of_TEX=1 {go here when \TeX's variables are initialized}
70 @d end_of_TEX=9998 {go here to close files and terminate gracefully}
71 @d final_end=9999 {this label marks the ending of the program}
72
73 @<Labels in the out...@>=
74 start_of_TEX@t\hskip-2pt@>, end_of_TEX@t\hskip-2pt@>,@,final_end;
75 {key control points}
76 @y
77 @ For Web2c, labels are not declared in the main program, but
78 we still have to declare the symbolic names.
79
80 @d start_of_TEX=1 {go here when \TeX's variables are initialized}
81 @d final_end=9999 {this label marks the ending of the program}
82 @z
83
84 % Here we change these WEB symbols, which are used much as #ifdef's
85 % are in C, into something which will get translated into actual #ifdef's.
86 @x [1.7] l.292 - debug..gubed, stat..tats
87 @d debug==@{ {change this to `$\\{debug}\equiv\null$' when debugging}
88 @d gubed==@t@>@} {change this to `$\\{gubed}\equiv\null$' when debugging}
89 @y
90 @d debug==ifdef('TEXMF_DEBUG')
91 @d gubed==endif('TEXMF_DEBUG')
92 @z
93 @x [1.7] l.297 - debug..gubed, stat..tats
94 @d stat==@{ {change this to `$\\{stat}\equiv\null$' when gathering
95 usage statistics}
96 @d tats==@t@>@} {change this to `$\\{tats}\equiv\null$' when gathering
97 usage statistics}
98 @y
99 @d stat==ifdef('STAT')
100 @d tats==endif('STAT')
101 @z
102
103 @x [1.8] l.312 - Same, for `init...tini'.
104 @d init== {change this to `$\\{init}\equiv\.{@@\{}$' in the production version}
105 @d tini== {change this to `$\\{tini}\equiv\.{@@\}}$' in the production version}
106 @y 312
107 @d init==ifdef('INITEX')
108 @d tini==endif('INITEX')
109 @z
110
111 @x [1.8] l.319 - init...tini is dynamic
112 @!init @<Initialize table entries (done by \.{INITEX} only)@>@;@+tini
113 @y 318
114 @!init
115 if ini_version then
116 begin @<Initialize table entries (done by \.{INITEX} only)@>@;
117 end;
118 @+tini
119 @z
120
121 @x [1.11] l.375 - Compile-time constants: most removed for dynamic allocation.
122 @<Constants...@>=
123 @!mem_max=30000; {greatest index in \TeX's internal |mem| array;
124 must be strictly less than |max_halfword|;
125 must be equal to |mem_top| in \.{INITEX}, otherwise |>=mem_top|}
126 @!mem_min=0; {smallest index in \TeX's internal |mem| array;
127 must be |min_halfword| or more;
128 must be equal to |mem_bot| in \.{INITEX}, otherwise |<=mem_bot|}
129 @!buf_size=500; {maximum number of characters simultaneously present in
130 current lines of open files and in control sequences between
131 \.{\\csname} and \.{\\endcsname}; must not exceed |max_halfword|}
132 @!error_line=72; {width of context lines on terminal error messages}
133 @!half_error_line=42; {width of first lines of contexts in terminal
134 error messages; should be between 30 and |error_line-15|}
135 @!max_print_line=79; {width of longest text lines output; should be at least 60}
136 @!stack_size=200; {maximum number of simultaneous input sources}
137 @!max_in_open=6; {maximum number of input files and error insertions that
138 can be going on simultaneously}
139 @y
140 @d file_name_size == maxint
141 @d ssup_error_line = 255
142 @d ssup_max_strings == 2097151
143 {Larger values may be used, but then the arrays consume much more memory.}
144 @d ssup_trie_opcode == 65535
145 @d ssup_trie_size == @"3FFFFF
146
147 @d ssup_hyph_size == 65535 {Changing this requires changing (un)dumping!}
148 @d iinf_hyphen_size == 610 {Must be not less than |hyph_prime|!}
149
150 @<Constants...@>=
151 @!mem_bot=0; {smallest index in the |mem| array dumped by \.{INITEX};
152 must not be less than |mem_min|}
153 {Use |mem_bot=0| for compilers which cannot decrement pointers.}
154 @z
155
156 @x
157 @!font_max=65535; {maximum internal font number; must be at most |font_biggest|}
158 @!param_size=60; {maximum number of simultaneous macro parameters}
159 @!nest_size=40; {maximum number of semantic levels simultaneously active}
160 @!max_strings=3000; {maximum number of strings; must not exceed |max_halfword|}
161 @!string_vacancies=8000; {the minimum number of characters that should be
162 available for the user's control sequences and font names,
163 after \TeX's own error messages are stored}
164 @!pool_size=32000; {maximum number of characters in strings, including all
165 error messages and help texts, and the names of all fonts and
166 control sequences; must exceed |string_vacancies| by the total
167 length of \TeX's own strings, which is currently about 23000}
168 @!save_size=600; {space for saving values outside of current group; must be
169 at most |max_halfword|}
170 @!trie_size=8000; {space for hyphenation patterns; should be larger for
171 \.{INITEX} than it is in production versions of \TeX}
172 @!trie_op_size=500; {space for ``opcodes'' in the hyphenation patterns}
173 @!dvi_buf_size=800; {size of the output buffer; must be a multiple of 8}
174 @!file_name_size=40; {file names shouldn't be longer than this}
175 @!pool_name='TeXformats:ALEPH.POOL ';
176 {string of length |file_name_size|; tells where the string pool appears}
177 @y
178 @!font_max=65535; {maximum internal font number; must be at most |font_biggest|}
179 @!hash_offset=514; {smallest index in hash array, i.e., |hash_base| }
180 {Use |hash_offset=0| for compilers which cannot decrement pointers.}
181 @!trie_op_size=15011; {space for ``opcodes'' in the hyphenation patterns;
182 best if relatively prime to 313, 361, and 1009.}
183 @!neg_trie_op_size=-35111; {for lower |trie_op_hash| array bound;
184 must be equal to |-trie_op_size|.}
185 @!min_trie_op=0; {first possible trie op code for any language}
186 @!max_trie_op=ssup_trie_opcode; {largest possible trie opcode for any language}
187 @!pool_name=TEXMF_POOL_NAME; {this is configurable, for the sake of ML-\TeX}
188 {string of length |file_name_size|; tells where the string pool appears}
189 @!engine_name=TEXMF_ENGINE_NAME; {the name of this engine}
190 @#
191 @!inf_main_memory = 2000000;
192 @!sup_main_memory = 256000000;
193
194 @!inf_trie_size = 80000;
195 @!sup_trie_size = ssup_trie_size;
196
197 @!inf_max_strings = 100000;
198 @!sup_max_strings = ssup_max_strings;
199
200 @!inf_strings_free = 100;
201 @!sup_strings_free = sup_max_strings;
202
203 @!inf_buf_size = 500;
204 @!sup_buf_size = 30000000;
205
206 @!inf_nest_size = 40;
207 @!sup_nest_size = 4000;
208
209 @!inf_max_in_open = 6;
210 @!sup_max_in_open = 127;
211
212 @!inf_param_size = 60;
213 @!sup_param_size = 32767;
214
215 @!inf_save_size = 600;
216 @!sup_save_size = 30000000;
217
218 @!inf_stack_size = 200;
219 @!sup_stack_size = 30000;
220
221 @!inf_dvi_buf_size = 800;
222 @!sup_dvi_buf_size = 65536;
223
224 @!inf_pool_size = 32000;
225 @!sup_pool_size = 40000000;
226 @!inf_pool_free = 1000;
227 @!sup_pool_free = sup_pool_size;
228 @!inf_string_vacancies = 8000;
229 @!sup_string_vacancies = sup_pool_size - 23000;
230
231 @!sup_hyph_size = ssup_hyph_size;
232 @!inf_hyph_size = iinf_hyphen_size; {Must be not less than |hyph_prime|!}
233
234 @!inf_expand_depth = 10;
235 @!sup_expand_depth = 10000000;
236 @z
237
238 @x [1.12] l.427 - Constants that are WEB numeric macros.
239 @d mem_bot=0 {smallest index in the |mem| array dumped by \.{INITEX};
240 must not be less than |mem_min|}
241 @d mem_top==30000 {largest index in the |mem| array dumped by \.{INITEX};
242 must be substantially larger than |mem_bot|
243 and not greater than |mem_max|}
244 @d font_base=0 {smallest internal font number; must not be less
245 than |min_quarterword|}
246 @d hash_size=65536 {maximum number of control sequences; it should be at most
247 about |(mem_max-mem_min)/10|}
248 @d hash_prime=55711 {a prime number equal to about 85\pct! of |hash_size|}
249 @d hyph_size=307 {another prime; the number of \.{\\hyphenation} exceptions}
250 @y
251 @d font_base=0 {smallest internal font number; must not be less
252 than |min_quarterword|}
253 @d hash_size=65536 {maximum number of control sequences; it should be at most
254 about |(mem_max-mem_min)/10|}
255 @d hash_prime=55711 {a prime number equal to about 85\pct! of |hash_size|}
256 @d hyph_prime=607 {another prime for hashing \.{\\hyphenation} exceptions;
257 if you change this, you should also change |iinf_hyphen_size|.}
258 @z
259
260 @x [1.16] l.498 - Use C macros for `incr' and `decr'.
261 @d incr(#) == #:=#+1 {increase a variable by unity}
262 @d decr(#) == #:=#-1 {decrease a variable by unity}
263 @y
264 @z
265
266 % The text_char type is used as an array index into xord. The
267 % default type `char' produces signed integers, which are bad array
268 % indices in C.
269 @x [2.19] l.565 - data type text_char is 8-bit ASCII_code
270 @d text_char == char {the data type of characters in text files}
271 @y
272 @d text_char == ASCII_code {the data type of characters in text files}
273 @z
274
275 % [3.26] name_of_file is no longer an array. And change the destination
276 % type to text_char, which fixes:
277 %
278 % Date: 19 Sep 1994 10:38:24 +0200
279 % From: [email protected] (Lars Mathiesen)
280 % When echoed to the screen and in the log, character codes
281 % above '177 in file names are shown wrongly (typically as ^@).
282 %
283 @x [3.26] l.789 - name_of_file is no longer an array
284 @!name_of_file:packed array[1..file_name_size] of char;@;@/
285 {on some systems this may be a \&{record} variable}
286 @y
287 @!name_of_file:^char;
288 @z
289
290 @x [3.27] l.794 - Do file opening in C.
291 @ The \ph\ compiler with which the present version of \TeX\ was prepared has
292 extended the rules of \PASCAL\ in a very convenient way. To open file~|f|,
293 we can write
294 $$\vbox{\halign{#\hfil\qquad&#\hfil\cr
295 |reset(f,@t\\{name}@>,'/O')|&for input;\cr
296 |rewrite(f,@t\\{name}@>,'/O')|&for output.\cr}}$$
297 The `\\{name}' parameter, which is of type `{\bf packed array
298 $[\langle\\{any}\rangle]$ of \\{char}}', stands for the name of
299 the external file that is being opened for input or output.
300 Blank spaces that might appear in \\{name} are ignored.
301
302 The `\.{/O}' parameter tells the operating system not to issue its own
303 error messages if something goes wrong. If a file of the specified name
304 cannot be found, or if such a file cannot be opened for some other reason
305 (e.g., someone may already be trying to write the same file), we will have
306 |@!erstat(f)<>0| after an unsuccessful |reset| or |rewrite|. This allows
307 \TeX\ to undertake appropriate corrective action.
308 @:PASCAL H}{\ph@>
309 @^system dependencies@>
310
311 \TeX's file-opening procedures return |false| if no file identified by
312 |name_of_file| could be opened.
313
314 @d reset_OK(#)==erstat(#)=0
315 @d rewrite_OK(#)==erstat(#)=0
316
317 @p function a_open_in(var f:alpha_file):boolean;
318 {open a text file for input}
319 begin reset(f,name_of_file,'/O'); a_open_in:=reset_OK(f);
320 end;
321 @#
322 function a_open_out(var f:alpha_file):boolean;
323 {open a text file for output}
324 begin rewrite(f,name_of_file,'/O'); a_open_out:=rewrite_OK(f);
325 end;
326 @#
327 function b_open_in(var f:byte_file):boolean;
328 {open a binary file for input}
329 begin reset(f,name_of_file,'/O'); b_open_in:=reset_OK(f);
330 end;
331 @#
332 function b_open_out(var f:byte_file):boolean;
333 {open a binary file for output}
334 begin rewrite(f,name_of_file,'/O'); b_open_out:=rewrite_OK(f);
335 end;
336 @#
337 function w_open_in(var f:word_file):boolean;
338 {open a word file for input}
339 begin reset(f,name_of_file,'/O'); w_open_in:=reset_OK(f);
340 end;
341 @#
342 function w_open_out(var f:word_file):boolean;
343 {open a word file for output}
344 begin rewrite(f,name_of_file,'/O'); w_open_out:=rewrite_OK(f);
345 end;
346 @y
347 @ All of the file opening functions are defined in C.
348 @z
349
350 @x [3.28] l.850 - Do file closing in C.
351 @ Files can be closed with the \ph\ routine `|close(f)|', which
352 @:PASCAL H}{\ph@>
353 @^system dependencies@>
354 should be used when all input or output with respect to |f| has been completed.
355 This makes |f| available to be opened again, if desired; and if |f| was used for
356 output, the |close| operation makes the corresponding external file appear
357 on the user's area, ready to be read.
358
359 These procedures should not generate error messages if a file is
360 being closed before it has been successfully opened.
361
362 @p procedure a_close(var f:alpha_file); {close a text file}
363 begin close(f);
364 end;
365 @#
366 procedure b_close(var f:byte_file); {close a binary file}
367 begin close(f);
368 end;
369 @#
370 procedure w_close(var f:word_file); {close a word file}
371 begin close(f);
372 end;
373 @y
374 @ And all the file closing routines as well.
375 @z
376
377 @x [3.30] l.888 - Array size of input buffer is determined at runtime.
378 @!buffer:array[0..buf_size] of ASCII_code; {lines of characters being read}
379 @y
380 @!buffer:^ASCII_code; {lines of characters being read}
381 @z
382
383 @x [3.31] l.933 - Do `input_ln' in C.
384 @p function input_ln(var f:alpha_file;@!bypass_eoln:boolean):boolean;
385 {inputs the next line or returns |false|}
386 var last_nonblank:0..buf_size; {|last| with trailing blanks removed}
387 begin if bypass_eoln then if not eof(f) then get(f);
388 {input the first character of the line into |f^|}
389 last:=first; {cf.\ Matthew 19\thinspace:\thinspace30}
390 if eof(f) then input_ln:=false
391 else begin last_nonblank:=first;
392 while not eoln(f) do
393 begin if last>=max_buf_stack then
394 begin max_buf_stack:=last+1;
395 if max_buf_stack=buf_size then
396 @<Report overflow of the input buffer, and abort@>;
397 end;
398 buffer[last]:=f^; get(f); incr(last);
399 if buffer[last-1]<>" " then last_nonblank:=last;
400 end;
401 last:=last_nonblank; input_ln:=true;
402 end;
403 end;
404 @y
405 We define |input_ln| in C, for efficiency.
406 @z
407
408 % [3.32] `term_in' and `term_out' are standard input and output.
409 % Declare the variables that used to be constants.
410 @x [3.32] l.961 - `term_in' and `term_out' are standard input and output.
411 @<Glob...@>=
412 @!term_in:alpha_file; {the terminal as an input file}
413 @!term_out:alpha_file; {the terminal as an output file}
414 @y
415 @d term_in==stdin {the terminal as an input file}
416 @d term_out==stdout {the terminal as an output file}
417
418 @<Glob...@>=
419 @!init
420 @!ini_version:boolean; {are we \.{INITEX}?}
421 @!dump_option:boolean; {was the dump name option used?}
422 @!dump_line:boolean; {was a \.{\%\AM format} line seen?}
423 tini@/
424 @#
425 @!dump_name:const_cstring; {format name for terminal display}
426 @#
427 @!bound_default:integer; {temporary for setup}
428 @!bound_name:const_cstring; {temporary for setup}
429 @#
430 @!main_memory:integer; {total memory words allocated in initex}
431 @!extra_mem_bot:integer; {|mem_min:=mem_bot-extra_mem_bot| except in \.{INITEX}}
432 @!mem_min:integer; {smallest index in \TeX's internal |mem| array;
433 must be |min_halfword| or more;
434 must be equal to |mem_bot| in \.{INITEX}, otherwise |<=mem_bot|}
435 @!mem_top:integer; {largest index in the |mem| array dumped by \.{INITEX};
436 must be substantially larger than |mem_bot|,
437 equal to |mem_max| in \.{INITEX}, else not greater than |mem_max|}
438 @!extra_mem_top:integer; {|mem_max:=mem_top+extra_mem_top| except in \.{INITEX}}
439 @!mem_max:integer; {greatest index in \TeX's internal |mem| array;
440 must be strictly less than |max_halfword|;
441 must be equal to |mem_top| in \.{INITEX}, otherwise |>=mem_top|}
442 @!error_line:integer; {width of context lines on terminal error messages}
443 @!half_error_line:integer; {width of first lines of contexts in terminal
444 error messages; should be between 30 and |error_line-15|}
445 @!max_print_line:integer;
446 {width of longest text lines output; should be at least 60}
447 @!max_strings:integer; {maximum number of strings; must not exceed |max_halfword|}
448 @!strings_free:integer; {strings available after format loaded}
449 @!string_vacancies:integer; {the minimum number of characters that should be
450 available for the user's control sequences and font names,
451 after \TeX's own error messages are stored}
452 @!pool_size:integer; {maximum number of characters in strings, including all
453 error messages and help texts, and the names of all fonts and
454 control sequences; must exceed |string_vacancies| by the total
455 length of \TeX's own strings, which is currently about 23000}
456 @!pool_free:integer;{pool space free after format loaded}
457 @!hyph_size:integer; {maximun number of hyphen exceptions}
458 @!trie_size:integer; {space for hyphenation patterns; should be larger for
459 \.{INITEX} than it is in production versions of \TeX. 50000 is
460 needed for English, German, and Portuguese.}
461 @!buf_size:integer; {maximum number of characters simultaneously present in
462 current lines of open files and in control sequences between
463 \.{\\csname} and \.{\\endcsname}; must not exceed |max_halfword|}
464 @!stack_size:integer; {maximum number of simultaneous input sources}
465 @!max_in_open:integer; {maximum number of input files and error insertions that
466 can be going on simultaneously}
467 @!param_size:integer; {maximum number of simultaneous macro parameters}
468 @!nest_size:integer; {maximum number of semantic levels simultaneously active}
469 @!save_size:integer; {space for saving values outside of current group; must be
470 at most |max_halfword|}
471 @!dvi_buf_size:integer; {size of the output buffer; must be a multiple of 8}
472 @!expand_depth:integer; {limits recursive calls to the |expand| procedure}
473 @!quoted_filename:boolean; {current filename is quoted}
474 @z
475
476 @x [3.33] l.964 - We don't need to open terminal files.
477 @ Here is how to open the terminal files
478 in \ph. The `\.{/I}' switch suppresses the first |get|.
479 @:PASCAL H}{\ph@>
480 @^system dependencies@>
481
482 @d t_open_in==reset(term_in,'TTY:','/O/I') {open the terminal for text input}
483 @d t_open_out==rewrite(term_out,'TTY:','/O') {open the terminal for text output}
484 @y
485 @ Here is how to open the terminal files. |t_open_out| does nothing.
486 |t_open_in|, on the other hand, does the work of ``rescanning,'' or getting
487 any command line arguments the user has provided. It's defined in C.
488
489 @d t_open_out == {output already open for text output}
490 @z
491
492 @x [3.34] l.982 - Flushing output to terminal files.
493 these operations can be specified in \ph:
494 @:PASCAL H}{\ph@>
495 @^system dependencies@>
496
497 @d update_terminal == break(term_out) {empty the terminal output buffer}
498 @d clear_terminal == break_in(term_in,true) {clear the terminal input buffer}
499 @y
500 these operations can be specified with {\mc UNIX}. |update_terminal|
501 does an |fflush|. |clear_terminal| is redefined
502 to do nothing, since the user should control the terminal.
503 @^system dependencies@>
504
505 @d update_terminal == fflush (term_out)
506 @d clear_terminal == do_nothing
507 @z
508
509 @x [3.35] l.1017 - Do `input_ln' in C => section not needed.
510 @<Report overflow of the input buffer, and abort@>=
511 if format_ident=0 then
512 begin write_ln(term_out,'Buffer size exceeded!'); goto final_end;
513 @.Buffer size exceeded@>
514 end
515 else begin cur_input.loc_field:=first; cur_input.limit_field:=last-1;
516 overflow("buffer size",buf_size);
517 @:TeX capacity exceeded buffer size}{\quad buffer size@>
518 end
519 @y
520 Routine is implemented in C; part of module is, however, needed for e-TeX.
521
522 @<Report overflow of the input buffer, and abort@>=
523 begin cur_input.loc_field:=first; cur_input.limit_field:=last-1;
524 overflow("buffer size",buf_size);
525 @:TeX capacity exceeded buffer size}{\quad buffer size@>
526 end
527 @z
528
529 @x [3.37] l.1055 - |init_terminal|, reading the command line.
530 @ The following program does the required initialization
531 without retrieving a possible command line.
532 It should be clear how to modify this routine to deal with command lines,
533 if the system permits them.
534 @^system dependencies@>
535
536 @p function init_terminal:boolean; {gets the terminal input started}
537 label exit;
538 begin t_open_in;
539 @y
540 @ The following program does the required initialization.
541 Iff anything has been specified on the command line, then |t_open_in|
542 will return with |last > first|.
543 @^system dependencies@>
544
545 @p function init_terminal:boolean; {gets the terminal input started}
546 label exit;
547 begin t_open_in;
548 if last > first then
549 begin loc := first;
550 while (loc < last) and (buffer[loc]=' ') do incr(loc);
551 if loc < last then
552 begin init_terminal := true; goto exit;
553 end;
554 end;
555 @z
556
557 @x [3.37] l.1068 - |init_terminal|, output missing newline.
558 write(term_out,'! End of file on the terminal... why?');
559 @y
560 write_ln(term_out,'! End of file on the terminal... why?');
561 @z
562
563 @x [4.38] l.1126 - Array size for string pool is determined at runtime.
564 @!pool_pointer = 0..pool_size; {for variables that point into |str_pool|}
565 @!str_number = 0..max_strings; {for variables that point into |str_start|}
566 @y
567 @!pool_pointer = integer; {for variables that point into |str_pool|}
568 @!str_number = 0..ssup_max_strings; {for variables that point into |str_start|}
569 @z
570
571 @x [4.39] l.1131 - Dynamically size pool arrays.
572 @!str_pool:packed array[pool_pointer] of packed_ASCII_code; {the characters}
573 @!str_start_ar : array[str_number] of pool_pointer; {the starting pointers}
574 @y
575 @!str_pool: ^packed_ASCII_code; {the characters}
576 @!str_start_ar : ^pool_pointer; {the starting pointers}
577 @z
578
579 @x [4.47] l.1237 - string recycling
580 @p @!init function get_strings_started:boolean; {initializes the string pool,
581 @y
582 @p @t\4@>@<Declare additional routines for string recycling@>@/
583
584 @!init function get_strings_started:boolean; {initializes the string pool,
585 @z
586
587 @x - unused variables.
588 var k,@!l:0..biggest_char; {small indices or counters}
589 @!m,@!n:text_char; {characters input from |pool_file|}
590 @!g:str_number; {garbage}
591 @!a:integer; {accumulator for check sum}
592 @!c:boolean; {check sum has been checked}
593 @y
594 var g:str_number; {garbage}
595 @z
596
597 @x
598 @ @d bad_pool(#)==begin wake_up_terminal; write_ln(term_out,#);
599 a_close(pool_file); get_strings_started:=false; return;
600 end
601 @<Read the other strings...@>=
602 name_of_file:=pool_name; {we needn't set |name_length|}
603 if a_open_in(pool_file) then
604 begin c:=false;
605 repeat @<Read one string, but return |false| if the
606 string memory space is getting too tight for comfort@>;
607 until c;
608 a_close(pool_file); get_strings_started:=true;
609 end
610 else bad_pool('! I can''t read ALEPH.POOL.')
611 @.I can't read ALEPH.POOL@>
612
613 @ @<Read one string...@>=
614 begin if eof(pool_file) then bad_pool('! ALEPH.POOL has no check sum.');
615 @.ALEPH.POOL has no check sum@>
616 read(pool_file,m,n); {read two digits of string length}
617 if m='*' then @<Check the pool check sum@>
618 else begin if (m<"0")or(m>"9")or@|
619 (n<"0")or(n>"9") then
620 bad_pool('! ALEPH.POOL line doesn''t begin with two digits.');
621 @.ALEPH.POOL line doesn't...@>
622 l:=m*10+n-"0"*11; {compute the length}
623 if pool_ptr+l+string_vacancies>pool_size then
624 bad_pool('! You have to increase POOLSIZE.');
625 @.You have to increase POOLSIZE@>
626 for k:=1 to l do
627 begin if eoln(pool_file) then m:=' '@+else read(pool_file,m);
628 append_char(m);
629 end;
630 read_ln(pool_file); g:=make_string;
631 end;
632 end
633
634 @ The \.{WEB} operation \.{@@\$} denotes the value that should be at the
635 end of this \.{OMEGA.POOL} file; any other value means that the wrong pool
636 file has been loaded.
637 @^check sum@>
638
639 @<Check the pool check sum@>=
640 begin a:=0; k:=1;
641 loop@+ begin if (n<"0")or(n>"9") then
642 bad_pool('! ALEPH.POOL check sum doesn''t have nine digits.');
643 @.ALEPH.POOL check sum...@>
644 a:=10*a+n-"0";
645 if k=9 then goto done;
646 incr(k); read(pool_file,n);
647 end;
648 done: if a<>@$ then bad_pool('! ALEPH.POOL doesn''t match; OTANGLE me again.');
649 @.ALEPH.POOL doesn't match@>
650 c:=true;
651 end
652 @y
653 @ @<Read the other strings...@>=
654 g := loadpoolstrings((pool_size-string_vacancies));
655 if g=0 then begin
656 wake_up_terminal; write_ln(term_out,'! You have to increase POOLSIZE.');
657 get_strings_started:=false;
658 return;
659 end;
660 get_strings_started:=true;
661
662 @ Empty module
663
664 @ Empty module
665 @z
666
667 @x [5.54] l.1422 - error_line
668 @!trick_buf:array[0..error_line] of ASCII_code; {circular buffer for
669 @y
670 @!trick_buf:array[0..ssup_error_line] of ASCII_code; {circular buffer for
671 @z
672
673 @x [5.61] l.1556 - Print rest of banner.
674 wterm(eTeX_banner);
675 if format_ident=0 then wterm_ln(' (no format preloaded)')
676 else begin slow_print(format_ident); print_ln;
677 end;
678 @y
679 wterm(eTeX_banner);
680 wterm(version_string);
681 if format_ident=0 then wterm_ln(' (preloaded format=',dump_name,')')
682 else begin slow_print(format_ident); print_ln;
683 end;
684 @z
685
686 @x [5.??] term_input: set limit when fatal_error (patch to omtrans.ch)
687 if not new_input_ln(term_in,term_in_mode,term_in_translation,true)
688 then fatal_error("End of file on the terminal!");
689 @y
690 if not new_input_ln(term_in,term_in_mode,term_in_translation,true)
691 then begin limit:=0; fatal_error("End of file on the terminal!"); end;
692 @z
693
694 @x [6.73] l.1732 - Add unspecified_mode.
695 @d error_stop_mode=3 {stops at every opportunity to interact}
696 @y
697 @d error_stop_mode=3 {stops at every opportunity to interact}
698 @d unspecified_mode=4 {extra value for command-line switch}
699 @z
700
701 @x [6.73] l.1738 - Add interaction_option.
702 @!interaction:batch_mode..error_stop_mode; {current level of interaction}
703 @y
704 @!interaction:batch_mode..error_stop_mode; {current level of interaction}
705 @!interaction_option:batch_mode..unspecified_mode; {set from command line}
706 @z
707
708 @x [6.74] l.1740 - Allow override by command line switch.
709 @ @<Set init...@>=interaction:=error_stop_mode;
710 @y
711 @ @<Set init...@>=if interaction_option=unspecified_mode then
712 interaction:=error_stop_mode
713 else
714 interaction:=interaction_option;
715 @z
716
717 % [6.81] Eliminate nonlocal goto, since C doesn't have them.
718 % Plus, it's nicer just to do an exit with the appropriate status code
719 % under Unix. We call it `uexit' because there's a WEB symbol called
720 % `exit' already. We use a C macro to change `uexit' back to `exit'.
721 @x [6.81] l.1852 - Eliminate nonlocal goto, since C doesn't have them.
722 @<Error hand...@>=
723 procedure jump_out;
724 begin goto end_of_TEX;
725 end;
726 @y
727 @d do_final_end==begin
728 update_terminal;
729 ready_already:=0;
730 if (history <> spotless) and (history <> warning_issued) then
731 uexit(1)
732 else
733 uexit(0);
734 end
735
736 @<Error hand...@>=
737 procedure jump_out;
738 begin
739 close_files_and_terminate;
740 do_final_end;
741 end;
742 @z
743
744 % Original reports:
745 % https://tex.stackexchange.com/questions/551313/
746 % https://tug.org/pipermail/tex-live/2020-June/045876.html
747 %
748 % This will probably be fixed by DEK in the 2021 tuneup in a different
749 % way (so we'll have to remove or alter this change), but the interaction
750 % sequence in the reports above causes a segmentation fault in web2c -
751 % writing to the closed \write15 stream because we wrongly decrement
752 % selector from 16 to 15 in term_input, due to the lack of this check in
753 % a recursive error() call.
754 %
755 %@x [6.83] l.1893 - avoid wrong interaction
756 %applied in 3.141592653
757 %loop@+begin continue: clear_for_error_prompt; prompt_input("? ");
758 %@y
759 %loop@+begin continue:
760 %if interaction<>error_stop_mode then return;
761 %clear_for_error_prompt; prompt_input("? ");
762 %@z
763
764 @x [6.84] l.1904 - Implement the switch-to-editor option.
765 line ready to be edited. But such an extension requires some system
766 wizardry, so the present implementation simply types out the name of the
767 file that should be
768 edited and the relevant line number.
769 @^system dependencies@>
770
771 There is a secret `\.D' option available when the debugging routines haven't
772 been commented~out.
773 @^debugging@>
774 @y
775 line ready to be edited.
776 We do this by calling the external procedure |call_edit| with a pointer to
777 the filename, its length, and the line number.
778 However, here we just set up the variables that will be used as arguments,
779 since we don't want to do the switch-to-editor until after TeX has closed
780 its files.
781 @^system dependencies@>
782
783 There is a secret `\.D' option available when the debugging routines haven't
784 been commented~out.
785 @^debugging@>
786 @d edit_file==input_stack[base_ptr]
787 @z
788
789 @x [6.84] l.1903 - Implement the switch-to-editor option.
790 "E": if base_ptr>0 then if input_stack[base_ptr].name_field>=256 then
791 begin print_nl("You want to edit file ");
792 @.You want to edit file x@>
793 slow_print(input_stack[base_ptr].name_field);
794 print(" at line "); print_int(line);
795 interaction:=scroll_mode; jump_out;
796 @y
797 "E": if base_ptr>0 then if input_stack[base_ptr].name_field>=256 then
798 begin edit_name_start:=str_start(edit_file.name_field);
799 edit_name_length:=str_start(edit_file.name_field+1) -
800 str_start(edit_file.name_field);
801 edit_line:=line;
802 jump_out;
803 @z
804
805 % [7.104] `remainder' is a library routine on some systems, so change
806 % its name to avoid conflicts.
807 @x [7.104] l.2227 - avoid name conflicts with lib routine remainder()
808 |remainder|, holds the remainder after a division.
809
810 @<Glob...@>=
811 @y
812 |remainder|, holds the remainder after a division.
813
814 @d remainder==tex_remainder
815
816 @<Glob...@>=
817 @z
818
819 @x [7.109] l.2352 - Define glue_ratio in C.
820 @!glue_ratio=real; {one-word representation of a glue expansion factor}
821 @y
822 @z
823
824 @x [8.112] l.2450 - Efficiency.
825 macros are simplified in the obvious way when |min_quarterword=0|.
826 @^inner loop@>@^system dependencies@>
827
828 @d qi(#)==#+min_quarterword
829 {to put an |eight_bits| item into a quarterword}
830 @d qo(#)==#-min_quarterword
831 {to take an |eight_bits| item out of a quarterword}
832 @d hi(#)==#+min_halfword
833 {to put a sixteen-bit item into a halfword}
834 @d ho(#)==#-min_halfword
835 {to take a sixteen-bit item from a halfword}
836 @y
837 macros are simplified in the obvious way when |min_quarterword=0|.
838 So they have been simplified here in the obvious way.
839 @^inner loop@>@^system dependencies@>
840
841 The \.{WEB} source for \TeX\ defines |hi(#)==#+min_halfword| which can be
842 simplified when |min_halfword=0|. The Web2C implemetation of \Aleph\
843 occasionally uses |null| as~0, and therefore requires |min_halfword=0|.
844
845 @d qi(#)==# {to put an |eight_bits| item into a quarterword}
846 @d qo(#)==# {to take an |eight_bits| item from a quarterword}
847 @d hi(#)==# {to put a sixteen-bit item into a halfword}
848 @d ho(#)==# {to take a sixteen-bit item from a halfword}
849 @z
850
851 % [8.113] We've put the memory structure into the include file
852 % `texmf.h', since it's too hard to translate automatically.
853 @x [8.113] l.2453 - data structures for main memory
854 @!quarterword = min_quarterword..max_quarterword; {1/4 of a word}
855 @!halfword=min_halfword..max_halfword; {1/2 of a word}
856 @!two_choices = 1..2; {used when there are two variants in a record}
857 @!four_choices = 1..4; {used when there are four variants in a record}
858 @!two_halves = packed record@;@/
859 @!rh:halfword;
860 case two_choices of
861 1: (@!lh:halfword);
862 2: (@!b0:quarterword; @!b1:quarterword);
863 end;
864 @!four_quarters = packed record@;@/
865 @!b0:quarterword;
866 @!b1:quarterword;
867 @!b2:quarterword;
868 @!b3:quarterword;
869 end;
870 @!memory_word = record@;@/
871 case four_choices of
872 1: (@!int:integer);
873 2: (@!gr:glue_ratio);
874 3: (@!hh:two_halves);
875 4: (@!qqqq:four_quarters);
876 end;
877 @y
878 @!quarterword = min_quarterword..max_quarterword;
879 @!halfword = min_halfword..max_halfword;
880 @!two_choices = 1..2; {used when there are two variants in a record}
881 @!four_choices = 1..4; {used when there are four variants in a record}
882 @=#include "texmfmem.h";@>
883 @=#include "alephmem.h";@>
884 @z
885
886 % [9.116] Change `mem' to `zmem', so we can define mem to be a register
887 % pointer to the memory array for speed.
888 @x [9.116] l.2545 - definition of main memory array
889 @!mem : array[mem_min..mem_max] of memory_word; {the big dynamic storage area}
890 @y
891 @!yzmem : ^memory_word; {the big dynamic storage area}
892 @!zmem : ^memory_word; {the big dynamic storage area}
893 @z
894
895 % [11.165] Fix the word `free' so that it doesn't conflict with the
896 % standard C library routine of the same name.
897 @x [11.165] l.3364 - avoid conflict with lib function free()
898 are debugging.)
899 @y
900 are debugging.)
901
902 @d free==free_arr
903 @z
904
905 @x [11.165] l.3367 - dummy |free| and |was_free| arrays
906 @!debug @!free: packed array [mem_min..mem_max] of boolean; {free cells}
907 @t\hskip10pt@>@!was_free: packed array [mem_min..mem_max] of boolean;
908 @y
909 {The debug memory arrays have not been mallocated yet.}
910 @!debug @!free: packed array [0..9] of boolean; {free cells}
911 @t\hskip10pt@>@!was_free: packed array [0..9] of boolean;
912 @z
913
914 @x [12.174] l.3526 - Eliminate unsigned comparisons to zero.
915 begin if (font(p)<font_base)or(font(p)>font_max) then
916 print_char("*")
917 @.*\relax@>
918 else @<Print the font identifier for |font(p)|@>;
919 @y
920 begin @<Print the font identifier for |font(p)|@>;
921 @z
922
923 @x [12.176] l.3563 - Eliminate unsigned comparisons to zero.
924 begin if p>mem_end then print_esc("CLOBBERED.")
925 else begin if (font(p)<font_base)or(font(p)>font_max) then print_char("*")
926 @.*\relax@>
927 else @<Print the font identifier for |font(p)|@>;
928 @y
929 begin if p>mem_end then print_esc("CLOBBERED.")
930 else begin @<Print the font identifier for |font(p)|@>;
931 @z
932
933 @x [12.186] l.3747 - Don't worry about strange floating point values.
934 if abs(mem[p+glue_offset].int)<@'4000000 then print("?.?")
935 else if abs(g)>float_constant(20000) then
936 @y 3747
937 { The Unix |pc| folks removed this restriction with a remark that
938 invalid bit patterns were vanishingly improbable, so we follow
939 their example without really understanding it.
940 |if abs(mem[p+glue_offset].int)<@'4000000 then print('?.?')|
941 |else| }
942 if fabs(g)>float_constant(20000) then
943 @z
944
945
946 @x [16.213] l.4321 - texarray
947 @!nest:array[0..nest_size] of list_state_record;
948 @y
949 @!nest:^list_state_record;
950 @z
951
952 @x [16.215] l.4344 - remove mem[] reference from initialize.
953 @<Start a new current page@>;
954 @y
955 @/{The following piece of code is a copy of module 991:}
956 page_contents:=empty; page_tail:=page_head; {|link(page_head):=null;|}@/
957 last_glue:=max_halfword; last_penalty:=0; last_kern:=0;
958 page_depth:=0; page_max_depth:=0;
959 @z
960
961 @x [17.241] l.5219 - Do `fix_date_and_time' in C.
962 @ The following procedure, which is called just before \TeX\ initializes its
963 input and output, establishes the initial values of the date and time.
964 @^system dependencies@>
965 Since standard \PASCAL\ cannot provide such information, something special
966 is needed. The program here simply assumes that suitable values appear in
967 the global variables \\{sys\_time}, \\{sys\_day}, \\{sys\_month}, and
968 \\{sys\_year} (which are initialized to noon on 4 July 1776,
969 in case the implementor is careless).
970
971 @p procedure fix_date_and_time;
972 begin sys_time:=12*60;
973 sys_day:=4; sys_month:=7; sys_year:=1776; {self-evident truths}
974 time:=sys_time; {minutes since midnight}
975 day:=sys_day; {day of the month}
976 month:=sys_month; {month of the year}
977 year:=sys_year; {Anno Domini}
978 end;
979 @y
980 @ The following procedure, which is called just before \TeX\ initializes its
981 input and output, establishes the initial values of the date and time.
982 It calls an externally defined |date_and_time|, which also sets up
983 interrupt catching. See more comments in \.{tex.ch}.
984 @^system dependencies@>
985
986 @d fix_date_and_time==o_date_and_time(int_base+time_code,
987 int_base+day_code,
988 int_base+month_code,
989 int_base+year_code)
990 @z
991
992 @x [18.262] l.5584 - Remove more unsigned comparisons to zero.
993 else if (newtext(p)<0)or(newtext(p)>=str_ptr) then print_esc("NONEXISTENT.")
994 @y
995 else if (newtext(p)>=str_ptr) then print_esc("NONEXISTENT.")
996 @z
997
998 @x [19.271] l.5872 - texarray
999 @!save_stack : array[0..save_size] of memory_word;
1000 @y
1001 @!save_stack : ^memory_word;
1002 @z
1003
1004 @x [22.301] l.6432 - texarray
1005 @!input_stack : array[0..stack_size] of in_state_record;
1006 @y
1007 @!input_stack : ^in_state_record;
1008 @z
1009
1010 @x [22.304] l.6536 - texarray
1011 @!input_file : array[1..max_in_open] of alpha_file;
1012 @!input_file_mode : array[1..max_in_open] of halfword;
1013 @!input_file_translation : array[1..max_in_open] of halfword;
1014 @!line : integer; {current line number in the current source file}
1015 @!line_stack : array[1..max_in_open] of integer;
1016 @y
1017 @!input_file : ^alpha_file;
1018 @!input_file_mode : ^halfword;
1019 @!input_file_translation : ^halfword;
1020 @!line : integer; {current line number in the current source file}
1021 @!line_stack : ^integer;
1022 @z
1023
1024 @x [22.308] l.6701 - texarray
1025 @!param_stack:array [0..param_size] of pointer;
1026 {token list pointers for parameters}
1027 @y
1028 @!param_stack: ^pointer;
1029 {token list pointers for parameters}
1030 @z
1031
1032 @x [23.328] l.7043 - keep top of source_filename_stack initialized
1033 incr(in_open); push_input; index:=in_open;
1034 @y
1035 incr(in_open); push_input; index:=in_open;
1036 source_filename_stack[index]:=0;full_source_filename_stack[index]:=0;
1037 @z
1038
1039 @x [23.331] l.7071 - init source file name stacks
1040 begin input_ptr:=0; max_in_stack:=0;
1041 @y
1042 begin input_ptr:=0; max_in_stack:=0;
1043 source_filename_stack[0]:=0;full_source_filename_stack[0]:=0;
1044 @z
1045
1046 @x [25.366] l.7672 - expansion depth overflow
1047 begin cv_backup:=cur_val; cvl_backup:=cur_val_level; radix_backup:=radix;
1048 @y
1049 begin
1050 incr(expand_depth_count);
1051 if expand_depth_count>=expand_depth then overflow("expansion depth",expand_depth);
1052 cv_backup:=cur_val; cvl_backup:=cur_val_level; radix_backup:=radix;
1053 @z
1054
1055 @x [25.366] l.7678 - expansion depth overflow
1056 cur_order:=co_backup; link(backup_head):=backup_backup;
1057 @y
1058 cur_order:=co_backup; link(backup_head):=backup_backup;
1059 decr(expand_depth_count);
1060 @z
1061
1062 % Original report: https://tex.stackexchange.com/questions/609423
1063 % TeX bug entry: https://tug.org/texmfbug/newbug.html#B155endwrite
1064 @x [25.369] l.7717 - disallow \noexpand\endwrite
1065 if t>=cs_token_flag then
1066 @y
1067 if (t>=cs_token_flag)and(t<>end_write_token) then
1068 @z
1069
1070 @x [27.???] set limit when fatal_error
1071 else fatal_error("*** (cannot \read from terminal in nonstop modes)")
1072 @y
1073 else begin
1074 limit:=0;
1075 fatal_error("*** (cannot \read from terminal in nonstop modes)");
1076 end
1077 @z
1078
1079 @x [28.501] l.9747 - \eof18
1080 if_eof_code: begin scan_four_bit_int; b:=(read_open[cur_val]=closed);
1081 end;
1082 @y
1083 if_eof_code: begin scan_four_bit_int_or_18;
1084 if cur_val=18 then b:=not shellenabledp
1085 else b:=(read_open[cur_val]=closed);
1086 end;
1087 @z
1088
1089 @x [29.513] l.9951 - Area and extension rules for filenames.
1090 @ The file names we shall deal with for illustrative purposes have the
1091 following structure: If the name contains `\.>' or `\.:', the file area
1092 consists of all characters up to and including the final such character;
1093 otherwise the file area is null. If the remaining file name contains
1094 `\..', the file extension consists of all such characters from the first
1095 remaining `\..' to the end, otherwise the file extension is null.
1096 @y
1097 @ The file names we shall deal with have the
1098 following structure: If the name contains `\./' or `\.:'
1099 (for Amiga only), the file area
1100 consists of all characters up to and including the final such character;
1101 otherwise the file area is null. If the remaining file name contains
1102 `\..', the file extension consists of all such characters from the last
1103 `\..' to the end, otherwise the file extension is null.
1104 @z
1105
1106 @x [29.513] l.9963 - Area and extension rules for filenames.
1107 @!area_delimiter:pool_pointer; {the most recent `\.>' or `\.:', if any}
1108 @!ext_delimiter:pool_pointer; {the relevant `\..', if any}
1109 @y
1110 @!area_delimiter:pool_pointer; {the most recent `\./', if any}
1111 @!ext_delimiter:pool_pointer; {the most recent `\..', if any}
1112 @z
1113
1114 @x [29.514] l.9973 - TeX area directories.
1115 @d TEX_area=="TeXinputs:"
1116 @.TeXinputs@>
1117 @d TEX_font_area=="TeXfonts:"
1118 @.TeXfonts@>
1119 @y
1120 In C, the default paths are specified separately.
1121 @z
1122
1123 @x [29.515] l.9995 - filenames: quoted
1124 begin area_delimiter:=0; ext_delimiter:=0;
1125 @y
1126 begin area_delimiter:=0; ext_delimiter:=0; quoted_filename:=false;
1127 @z
1128
1129 @x [29.516] l.9992 - filenames: more_name
1130 begin if c=" " then more_name:=false
1131 @y
1132 begin if (c=" ") and stop_at_space and (not quoted_filename) then
1133 more_name:=false
1134 else if c="""" then begin
1135 quoted_filename:=not quoted_filename;
1136 more_name:=true;
1137 end
1138 @z
1139
1140 @x [29.516] l.9994 - filenames: more_name
1141 if (c=">")or(c=":") then
1142 @y
1143 if IS_DIR_SEP(c) then
1144 @z
1145
1146 @x [29.516] l.9997 - filenames: more_name
1147 else if (c=".")and(ext_delimiter=0) then ext_delimiter:=cur_length;
1148 @y
1149 else if c="." then ext_delimiter:=cur_length;
1150 @z
1151
1152 @x [29.517] l.10002 - end_name: string recycling
1153 @ The third.
1154 @^system dependencies@>
1155
1156 @p procedure end_name;
1157 @y
1158 @ The third.
1159 @^system dependencies@>
1160 If a string is already in the string pool, the function
1161 |slow_make_string| does not create a new string but returns this string
1162 number, thus saving string space. Because of this new property of the
1163 returned string number it is not possible to apply |flush_string| to
1164 these strings.
1165
1166 @p procedure end_name;
1167 var temp_str: str_number; {result of file name cache lookups}
1168 @!j,@!s,@!t: pool_pointer; {running indices}
1169 @!must_quote:boolean; {whether we need to quote a string}
1170 @z
1171
1172 @x [29.517] l.10022 - end_name: spaces in filenames
1173 @:TeX capacity exceeded number of strings}{\quad number of strings@>
1174 @y
1175 @:TeX capacity exceeded number of strings}{\quad number of strings@>
1176 str_room(6); {Room for quotes, if needed.}
1177 {add quotes if needed}
1178 if area_delimiter<>0 then begin
1179 {maybe quote |cur_area|}
1180 must_quote:=false;
1181 s:=str_start(str_ptr);
1182 t:=str_start(str_ptr)+area_delimiter;
1183 j:=s;
1184 while (not must_quote) and (j<t) do begin
1185 must_quote:=str_pool[j]=" "; incr(j);
1186 end;
1187 if must_quote then begin
1188 for j:=pool_ptr-1 downto t do str_pool[j+2]:=str_pool[j];
1189 str_pool[t+1]:="""";
1190 for j:=t-1 downto s do str_pool[j+1]:=str_pool[j];
1191 str_pool[s]:="""";
1192 if ext_delimiter<>0 then ext_delimiter:=ext_delimiter+2;
1193 area_delimiter:=area_delimiter+2;
1194 pool_ptr:=pool_ptr+2;
1195 end;
1196 end;
1197 {maybe quote |cur_name|}
1198 s:=str_start(str_ptr)+area_delimiter;
1199 if ext_delimiter=0 then t:=pool_ptr else t:=str_start(str_ptr)+ext_delimiter-1;
1200 must_quote:=false;
1201 j:=s;
1202 while (not must_quote) and (j<t) do begin
1203 must_quote:=str_pool[j]=" "; incr(j);
1204 end;
1205 if must_quote then begin
1206 for j:=pool_ptr-1 downto t do str_pool[j+2]:=str_pool[j];
1207 str_pool[t+1]:="""";
1208 for j:=t-1 downto s do str_pool[j+1]:=str_pool[j];
1209 str_pool[s]:="""";
1210 if ext_delimiter<>0 then ext_delimiter:=ext_delimiter+2;
1211 pool_ptr:=pool_ptr+2;
1212 end;
1213 if ext_delimiter<>0 then begin
1214 {maybe quote |cur_ext|}
1215 s:=str_start(str_ptr)+ext_delimiter-1;
1216 t:=pool_ptr;
1217 must_quote:=false;
1218 j:=s;
1219 while (not must_quote) and (j<t) do begin
1220 must_quote:=str_pool[j]=" "; incr(j);
1221 end;
1222 if must_quote then begin
1223 str_pool[t+1]:="""";
1224 for j:=t-1 downto s do str_pool[j+1]:=str_pool[j];
1225 str_pool[s]:="""";
1226 pool_ptr:=pool_ptr+2;
1227 end;
1228 end;
1229 @z
1230
1231 @x [29.517] l.10011 - end_name: string recycling
1232 str_start(str_ptr+1):=str_start(str_ptr)+area_delimiter; incr(str_ptr);
1233 end;
1234 if ext_delimiter=0 then
1235 begin cur_ext:=""; cur_name:=make_string;
1236 @y
1237 str_start(str_ptr+1):=str_start(str_ptr)+area_delimiter; incr(str_ptr);
1238 temp_str:=search_string(cur_area);
1239 if temp_str>0 then
1240 begin cur_area:=temp_str;
1241 decr(str_ptr); {no |flush_string|, |pool_ptr| will be wrong!}
1242 for j:=str_start(str_ptr+1) to pool_ptr-1 do
1243 begin str_pool[j-area_delimiter]:=str_pool[j];
1244 end;
1245 pool_ptr:=pool_ptr-area_delimiter; {update |pool_ptr|}
1246 end;
1247 end;
1248 if ext_delimiter=0 then
1249 begin cur_ext:=""; cur_name:=slow_make_string;
1250 @z
1251
1252 @x [29.517] l.10016 - end_name: string recycling
1253 else begin cur_name:=str_ptr;
1254 str_start(str_ptr+1):=str_start(str_ptr)+ext_delimiter-area_delimiter-1;
1255 incr(str_ptr); cur_ext:=make_string;
1256 @y
1257 else begin cur_name:=str_ptr;
1258 str_start(str_ptr+1):=str_start(str_ptr)+ext_delimiter-area_delimiter-1;
1259 incr(str_ptr); cur_ext:=make_string;
1260 decr(str_ptr); {undo extension string to look at name part}
1261 temp_str:=search_string(cur_name);
1262 if temp_str>0 then
1263 begin cur_name:=temp_str;
1264 decr(str_ptr); {no |flush_string|, |pool_ptr| will be wrong!}
1265 for j:=str_start(str_ptr+1) to pool_ptr-1 do
1266 begin str_pool[j-ext_delimiter+area_delimiter+1]:=str_pool[j];
1267 end;
1268 pool_ptr:=pool_ptr-ext_delimiter+area_delimiter+1; {update |pool_ptr|}
1269 end;
1270 cur_ext:=slow_make_string; {remake extension string}
1271 @z
1272
1273 @x [29.518] l.10042 - print_file_name: quote if spaces in names.
1274 begin slow_print(a); slow_print(n); slow_print(e);
1275 @y
1276 var must_quote: boolean; {whether to quote the filename}
1277 @!j:pool_pointer; {index into |str_pool|}
1278 begin
1279 must_quote:=false;
1280 if a<>0 then begin
1281 j:=str_start(a);
1282 while (not must_quote) and (j<str_start(a+1)) do begin
1283 must_quote:=str_pool[j]=" "; incr(j);
1284 end;
1285 end;
1286 if n<>0 then begin
1287 j:=str_start(n);
1288 while (not must_quote) and (j<str_start(n+1)) do begin
1289 must_quote:=str_pool[j]=" "; incr(j);
1290 end;
1291 end;
1292 if e<>0 then begin
1293 j:=str_start(e);
1294 while (not must_quote) and (j<str_start(e+1)) do begin
1295 must_quote:=str_pool[j]=" "; incr(j);
1296 end;
1297 end;
1298 {FIXME: Alternative is to assume that any filename that has to be quoted has
1299 at least one quoted component...if we pick this, a number of insertions
1300 of |print_file_name| should go away.
1301 |must_quote|:=((|a|<>0)and(|str_pool|[|str_start|(|a|)]=""""))or
1302 ((|n|<>0)and(|str_pool|[|str_start|(|n|)]=""""))or
1303 ((|e|<>0)and(|str_pool|[|str_start|(|e|)]=""""));}
1304 if must_quote then print_char("""");
1305 if a<>0 then
1306 for j:=str_start(a) to str_start(a+1)-1 do
1307 if so(str_pool[j])<>"""" then
1308 print_char(so(str_pool[j]));
1309 if n<>0 then
1310 for j:=str_start(n) to str_start(n+1)-1 do
1311 if so(str_pool[j])<>"""" then
1312 print_char(so(str_pool[j]));
1313 if e<>0 then
1314 for j:=str_start(e) to str_start(e+1)-1 do
1315 if so(str_pool[j])<>"""" then
1316 print_char(so(str_pool[j]));
1317 if must_quote then print_char("""");
1318 @z
1319
1320 @x [29.519] l.10051 - have append_to_name skip quotes.
1321 @d append_to_name(#)==begin c:=#; incr(k);
1322 if k<=file_name_size then name_of_file[k]:=xchr[c];
1323 end
1324 @y
1325 @d append_to_name(#)==begin c:=#; if not (c="""") then begin incr(k);
1326 if k<=file_name_size then name_of_file[k]:=xchr[c];
1327 end end
1328 @z
1329
1330 % [29.519] In pack_file_name, leave room for the extra null we append at
1331 % the end of a filename.
1332 @x [29.519] l.10047 - pack_file_name, leave room for the extra null
1333 for j:=str_start(a) to str_start(a+1)-1 do append_to_name(so(str_pool[j]));
1334 @y
1335 if name_of_file then libc_free (name_of_file);
1336 name_of_file:= xmalloc_array(char, 1 + length(a) + length(n) + length(e));
1337 for j:=str_start(a) to str_start(a+1)-1 do append_to_name(so(str_pool[j]));
1338 @z
1339
1340 @x [29.519] l.10051 - pack_file_name, append the extra null
1341 for k:=name_length+1 to file_name_size do name_of_file[k]:=' ';
1342 @y
1343 name_of_file[name_length+1]:=0;
1344 @z
1345
1346 @x [29.520] l.10060 - filenames: default format.
1347 @d format_default_length=20 {length of the |TEX_format_default| string}
1348 @d format_area_length=11 {length of its area part}
1349 @d format_ext_length=4 {length of its `\.{.fmt}' part}
1350 @d format_extension=".fmt" {the extension, as a \.{WEB} constant}
1351 @y
1352 Under {\mc UNIX} we don't give the area part, instead depending
1353 on the path searching that will happen during file opening. Also, the
1354 length will be set in the main program.
1355
1356 @d format_area_length=0 {length of its area part}
1357 @d format_ext_length=4 {length of its `\.{.fmt}' part}
1358 @d format_extension=".fmt" {the extension, as a \.{WEB} constant}
1359 @z
1360
1361 @x [29.521] l.10066 - filenames: default format, where `plain.fmt' is.
1362 @!TEX_format_default:packed array[1..format_default_length] of char;
1363
1364 @ @<Set init...@>=
1365 TEX_format_default:='TeXformats:plain.fmt';
1366 @y
1367 @!format_default_length: integer;
1368 @!TEX_format_default: ^char;
1369
1370 @ We set the name of the default format file and the length of that name
1371 in C, instead of Pascal, since we want them to depend on the name of the
1372 program.
1373 @z
1374
1375 @x [29.523] l.10095 - Change to pack_buffered_name as with pack_file_name.
1376 for j:=1 to n do append_to_name(TEX_format_default[j]);
1377 @y
1378 if name_of_file then libc_free (name_of_file);
1379 name_of_file := xmalloc_array (char, 1 + n + (b - a + 1) + format_ext_length);
1380 for j:=1 to n do append_to_name(TEX_format_default[j]);
1381 @z
1382
1383 @x [29.523] l.10100 - Change to pack_buffered_name as with pack_file_name.
1384 for k:=name_length+1 to file_name_size do name_of_file[k]:=' ';
1385 @y
1386 name_of_file[name_length+1]:=0;
1387 @z
1388
1389 @x [29.524] l.10118 - Format file opening: only try once, with path searching.
1390 pack_buffered_name(0,loc,j-1); {try first without the system file area}
1391 if w_open_in(fmt_file) then goto found;
1392 pack_buffered_name(format_area_length,loc,j-1);
1393 {now try the system format file area}
1394 if w_open_in(fmt_file) then goto found;
1395 @y
1396 pack_buffered_name(0,loc,j-1); {Kpathsea does everything}
1397 if w_open_in(fmt_file) then goto found;
1398 @z
1399
1400 @x [29.524] l.10124 - replace `PLAIN' in error messages with `default'.
1401 wterm_ln('Sorry, I can''t find that format;',' will try PLAIN.');
1402 @y
1403 wterm ('Sorry, I can''t find the format `');
1404 fputs (name_of_file + 1, stdout);
1405 wterm ('''; will try `');
1406 fputs (TEX_format_default + 1, stdout);
1407 wterm_ln ('''.');
1408 @z
1409
1410 @x [29.524] l.10132 - replace `PLAIN' in error messages with `default'.
1411 wterm_ln('I can''t find the PLAIN format file!');
1412 @.I can't find PLAIN...@>
1413 @y
1414 wterm ('I can''t find the format file `');
1415 fputs (TEX_format_default + 1, stdout);
1416 wterm_ln ('''!');
1417 @.I can't find the format...@>
1418 @z
1419
1420 @x [29.525] l.10163 - make_name_string
1421 @p function make_name_string:str_number;
1422 var k:1..file_name_size; {index into |name_of_file|}
1423 begin if (pool_ptr+name_length>pool_size)or(str_ptr=max_strings)or
1424 (cur_length>0) then
1425 make_name_string:="?"
1426 else begin for k:=1 to name_length do append_char(name_of_file[k]);
1427 make_name_string:=make_string;
1428 end;
1429 @y
1430 @p function make_name_string:str_number;
1431 var k:1..file_name_size; {index into |name_of_file|}
1432 save_area_delimiter, save_ext_delimiter: pool_pointer;
1433 save_name_in_progress, save_stop_at_space: boolean;
1434 begin if (pool_ptr+name_length>pool_size)or(str_ptr=max_strings)or
1435 (cur_length>0) then
1436 make_name_string:="?"
1437 else begin for k:=1 to name_length do append_char(name_of_file[k]);
1438 make_name_string:=make_string;
1439 {At this point we also set |cur_name|, |cur_ext|, and |cur_area| to
1440 match the contents of |name_of_file|.}
1441 save_area_delimiter:=area_delimiter; save_ext_delimiter:=ext_delimiter;
1442 save_name_in_progress:=name_in_progress; save_stop_at_space:=stop_at_space;
1443 name_in_progress:=true;
1444 begin_name;
1445 stop_at_space:=false;
1446 k:=1;
1447 while (k<=name_length)and(more_name(name_of_file[k])) do
1448 incr(k);
1449 stop_at_space:=save_stop_at_space;
1450 end_name;
1451 name_in_progress:=save_name_in_progress;
1452 area_delimiter:=save_area_delimiter; ext_delimiter:=save_ext_delimiter;
1453 end;
1454 @z
1455
1456 @x [29.526] l.10193 - look for a left_brace when scanning a file name
1457 @p procedure scan_file_name;
1458 label done;
1459 @y
1460 @p procedure scan_file_name;
1461 label done;
1462 var
1463 @!save_warning_index: pointer;
1464 begin
1465 save_warning_index := warning_index;
1466 warning_index := cur_cs; {store |cur_cs| here to remember until later}
1467 @<Get the next non-blank non-relax non-call...@>; {here the program expands
1468 tokens and removes spaces and \.{\\relax}es from the input. The \.{\\relax}
1469 removal follows LuaTeX''s implementation, and other cases of
1470 balanced text scanning.}
1471 back_input; {return the last token to be read by either code path}
1472 if cur_cmd=left_brace then
1473 scan_file_name_braced
1474 else
1475 @z
1476
1477 @x [29.526] l.10194 - stop scanning file name if we're at end-of-line.
1478 if not more_name(cur_chr) then goto done;
1479 @y
1480 {If |cur_chr| is a space and we're not scanning a token list, check
1481 whether we're at the end of the buffer. Otherwise we end up adding
1482 spurious spaces to file names in some cases.}
1483 if (cur_chr=" ") and (state<>token_list) and (loc>limit) then goto done;
1484 if not more_name(cur_chr) then goto done;
1485 @z
1486
1487 @x [29.526] l.10203 - scan a bgroup/egroup-delimited file name
1488 done: end_name; name_in_progress:=false;
1489 end;
1490 @y
1491 end;
1492 done: end_name; name_in_progress:=false;
1493 warning_index := save_warning_index; {restore |warning_index|}
1494 end;
1495
1496 @ When |scan_file_name| starts it looks for a |left_brace|
1497 (skipping \.{\\relax}es, as other \.{\\toks}-like primitives).
1498 If a |left_brace| is found, then the procedure scans a file
1499 name contained in a balanced token list, expanding tokens as
1500 it goes. When the scanner finds the balanced token list, it
1501 is converted into a string and fed character-by-character to
1502 |more_name| to do its job the same as in the ``normal'' file
1503 name scanning.
1504
1505 @p procedure scan_file_name_braced;
1506 var
1507 @!save_scanner_status: small_number; {|scanner_status| upon entry}
1508 @!save_def_ref: pointer; {|def_ref| upon entry, important if inside `\.{\\message}}
1509 @!save_cur_cs: pointer;
1510 @!s: str_number; {temp string}
1511 @!p: pointer; {temp pointer}
1512 @!i: integer; {loop tally}
1513 @!save_stop_at_space: boolean; {this should be in tex.ch}
1514 @!dummy: boolean;
1515 {Initialising}
1516 begin save_scanner_status := scanner_status; {|scan_toks| sets |scanner_status| to |absorbing|}
1517 save_def_ref := def_ref; {|scan_toks| uses |def_ref| to point to the token list just read}
1518 save_cur_cs := cur_cs; {we set |cur_cs| back a few tokens to use in runaway errors}
1519 {Scanning a token list}
1520 cur_cs := warning_index; {for possible runaway error}
1521 {mimick |call_func| from pdfTeX}
1522 if scan_toks(false, true) <> 0 then do_nothing; {actually do the scanning}
1523 {s := tokens_to_string(def_ref);}
1524 old_setting := selector; selector:=new_string;
1525 show_token_list(link(def_ref),null,pool_size-pool_ptr);
1526 selector := old_setting;
1527 s := make_string;
1528 {turns the token list read in a string to input}
1529 {Restoring some variables}
1530 delete_token_ref(def_ref); {remove the token list from memory}
1531 def_ref := save_def_ref; {and restore |def_ref|}
1532 cur_cs := save_cur_cs; {restore |cur_cs|}
1533 scanner_status := save_scanner_status; {restore |scanner_status|}
1534 {Passing the read string to the input machinery}
1535 save_stop_at_space := stop_at_space; {save |stop_at_space|}
1536 stop_at_space := false; {set |stop_at_space| to false to allow spaces in file names}
1537 begin_name;
1538 for i:=str_start(s) to str_start(s+1)-1 do
1539 dummy := more_name(str_pool[i]); {add each read character to the current file name}
1540 stop_at_space := save_stop_at_space; {restore |stop_at_space|}
1541 end;
1542 @z
1543
1544 @x [29.530] l.10245 - prompt_file_name: prevent empty filenames.
1545 var k:0..buf_size; {index into |buffer|}
1546 @y
1547 var k:0..buf_size; {index into |buffer|}
1548 @!saved_cur_name:str_number; {to catch empty terminal input}
1549 @!saved_cur_ext:str_number; {to catch empty terminal input}
1550 @!saved_cur_area:str_number; {to catch empty terminal input}
1551 @z
1552
1553 @x [29.530] l.10252 - prompt_file_name: No default extension is TeX input file.
1554 if e=".tex" then show_context;
1555 @y
1556 if (e=".tex") or (e="") then show_context;
1557 print_ln; print_c_string(prompt_file_name_help_msg);
1558 if (e<>"") then
1559 begin
1560 print("; default file extension is `"); print(e); print("'");
1561 end;
1562 print(")"); print_ln;
1563 @z
1564
1565 @x [29.530] l.10258 - prompt_file_name: prevent empty filenames.
1566 clear_terminal; prompt_input(": "); @<Scan file name in the buffer@>;
1567 if cur_ext="" then cur_ext:=e;
1568 @y
1569 saved_cur_name:=cur_name;
1570 saved_cur_ext:=cur_ext;
1571 saved_cur_area:=cur_area;
1572 clear_terminal; prompt_input(": "); @<Scan file name in the buffer@>;
1573 if (length(cur_name)=0) and (cur_ext="") and (cur_area="") then
1574 begin
1575 cur_name:=saved_cur_name;
1576 cur_ext:=saved_cur_ext;
1577 cur_area:=saved_cur_area;
1578 end
1579 else
1580 if cur_ext="" then cur_ext:=e;
1581 @z
1582
1583 @x [29.532] l.10263 - avoid conflict, `logname' in <unistd.h> on some systems.
1584 @ Here's an example of how these conventions are used. Whenever it is time to
1585 ship out a box of stuff, we shall use the macro |ensure_dvi_open|.
1586
1587 @y
1588 @ Here's an example of how these conventions are used. Whenever it is time to
1589 ship out a box of stuff, we shall use the macro |ensure_dvi_open|.
1590
1591 @d log_name == texmf_log_name
1592 @z
1593
1594 @x [29.534] l.10285 - Adjust for C string conventions.
1595 @!months:packed array [1..36] of char; {abbreviations of month names}
1596 @y
1597 @!months:const_cstring;
1598 @z
1599
1600 @x [29.534] l. - Send the job_name to the file recorder.
1601 begin old_setting:=selector;
1602 if job_name=0 then job_name:="texput";
1603 @y
1604 begin old_setting:=selector;
1605 if job_name=0 then job_name:=get_job_name("texput");
1606 pack_job_name(".ofl");
1607 recorder_change_filename(stringcast(name_of_file+1));
1608 @z
1609
1610 @x [29.536] l.10324 - Print rest of banner.
1611 begin wlog(eTeX_banner);
1612 @y
1613 begin wlog(eTeX_banner);
1614 wlog(version_string);
1615 @z
1616
1617 @x [29.536] l.10327 - Adjust for C string conventions.
1618 months:='JANFEBMARAPRMAYJUNJULAUGSEPOCTNOVDEC';
1619 @y
1620 months := ' JANFEBMARAPRMAYJUNJULAUGSEPOCTNOVDEC';
1621 @z
1622
1623 % [29.537] Use a path when calling a_open_in to do a \input; also, try
1624 % to open the file with and without the `.tex' extension, regardless of
1625 % whether the file already has an extension. This allows filenames like
1626 % `foo' and `foo.bar.tex', as well as `foo.tex' and `foo.bar'.
1627 @x [29.537] l.10338 - start_input
1628 begin scan_file_name; {set |cur_name| to desired file name}
1629 if cur_ext="" then cur_ext:=".tex";
1630 pack_cur_name;
1631 loop@+ begin begin_file_reading; {set up |cur_file| and new level of input}
1632 if a_open_in(cur_file) then goto done;
1633 if cur_area="" then
1634 begin pack_file_name(cur_name,TEX_area,cur_ext);
1635 if a_open_in(cur_file) then goto done;
1636 end;
1637 @y
1638 var temp_str: str_number;
1639 begin scan_file_name; {set |cur_name| to desired file name}
1640 pack_cur_name;
1641 loop@+ begin begin_file_reading; {set up |cur_file| and new level of input}
1642 tex_input_type := 1; {Tell |open_input| we are \.{\\input}.}
1643 {Kpathsea tries all the various ways to get the file.}
1644 if kpse_in_name_ok(name_of_file+1)
1645 and a_open_in(cur_file, kpse_tex_format) then
1646 goto done;
1647 @z
1648
1649 @x [29.537] l.10348 - start_input: don't force ".tex" extension.
1650 prompt_file_name("input file name",".tex");
1651 @y
1652 prompt_file_name("input file name","");
1653 @z
1654
1655 @x [29.537] l.10350 - start_input: string recycling
1656 done: name:=a_make_name_string(cur_file);
1657 @y
1658 done: name:=a_make_name_string(cur_file);
1659 if name=str_ptr-1 then {we can try to conserve string pool space now}
1660 begin temp_str:=search_string(name);
1661 if temp_str>0 then
1662 begin name:=temp_str; flush_string;
1663 end;
1664 end;
1665 @z
1666
1667 @x [29.537] l.10352 - start_input: use different heuristic for initex.
1668 begin job_name:=cur_name; open_log_file;
1669 @y
1670 begin job_name:=get_job_name(cur_name); open_log_file;
1671 @z
1672
1673 @x [29.537] l.10359 - start_input: don't return filename to string pool.
1674 if name=str_ptr-1 then {conserve string pool space (but see note above)}
1675 begin flush_string; name:=cur_name;
1676 end;
1677 @y
1678 @z
1679
1680 @x [30.560] l.10898 - Check lengths
1681 @!file_opened:boolean; {was |tfm_file| successfully opened?}
1682 @y
1683 @!name_too_long:boolean; {|nom| or |aire| exceeds 255 bytes?}
1684 @!file_opened:boolean; {was |tfm_file| successfully opened?}
1685 @z
1686
1687 @x [30.561] l.10939 - Check lengths
1688 else print(" not loadable: Metric (TFM/OFM) file not found");
1689 @y
1690 else if name_too_long then print(" not loadable: Metric (TFM/OFM) file name too long")
1691 else print(" not loadable: Metric (TFM/OFM) file not found");
1692 @z
1693
1694 @x [30.563] l.10960 - Check lengths
1695 file_opened:=false;
1696 @y
1697 file_opened:=false;
1698 name_too_long:=(length(nom)>255)or(length(aire)>255);
1699 if name_too_long then abort;
1700 @z
1701
1702 @x [30.563] l.10961 - Don't use TEX_font_area.
1703 if aire="" then pack_file_name(nom,TEX_font_area,".ofm")
1704 else pack_file_name(nom,aire,".ofm");
1705 if not b_open_in(tfm_file) then abort;
1706 @y
1707 {|kpse_find_file| will append the |".ofm"| or |".tfm"|,
1708 and avoid searching the disk before the font alias files as well.}
1709 pack_file_name(nom,aire,"");
1710 if not ofm_open_in(tfm_file) then abort;
1711 @z
1712
1713 % [30.564] Reading the tfm file. As a special case, whenever we open a
1714 % tfm file, we read its first byte into `tfm_temp' right away. TeX
1715 % looks at `fbyte' before calling `fget', so it ends up seeing every
1716 % byte. This is Pascal-like I/O.
1717 @x [30.564] l.10956 - reading the tfm file, define fget & fbyte
1718 @d fget==get(tfm_file)
1719 @d fbyte==tfm_file^
1720 @y
1721 @d fget==tfm_temp:=getc(tfm_file)
1722 @d fbyte==tfm_temp
1723 @z
1724
1725 % [32.575] We only want `eof' on the TFM file to be true if we
1726 % previously had EOF, not if we're at EOF now. This is like `feof', and
1727 % unlike our implementation of `eof' elsewhere.
1728 @x [32.575] l.11161 - Reading the tfm file, replace eof() by feof().
1729 if eof(tfm_file) then abort;
1730 @y
1731 if feof(tfm_file) then abort;
1732 @z
1733
1734 @x [32.595] l.11860 - texarray
1735 @!dvi_buf:array[dvi_index] of real_eight_bits; {buffer for \.{DVI} output}
1736 @!half_buf:dvi_index; {half of |dvi_buf_size|}
1737 @!dvi_limit:dvi_index; {end of the current half buffer}
1738 @!dvi_ptr:dvi_index; {the next available buffer address}
1739 @y
1740 @!dvi_buf:^real_eight_bits; {buffer for \.{DVI} output}
1741 @!half_buf:integer; {half of |dvi_buf_size|}
1742 @!dvi_limit:integer; {end of the current half buffer}
1743 @!dvi_ptr:integer; {the next available buffer address}
1744 @z
1745
1746 @x [32.597] l.11886 - write_dvi done in C.
1747 @p procedure write_dvi(@!a,@!b:dvi_index);
1748 var k:dvi_index;
1749 begin for k:=a to b do write(dvi_file,dvi_buf[k]);
1750 end;
1751 @y
1752 In C, we use a macro to call |fwrite| or |write| directly, writing all
1753 the bytes in one shot. Much better even than writing four
1754 bytes at a time.
1755 @z
1756
1757 @x [32.601] l.11911 - check dvi file size
1758 each time, we use the macro |dvi_out|.
1759 @y
1760 each time, we use the macro |dvi_out|.
1761
1762 The length of |dvi_file| should not exceed |@"7FFFFFFF|; we set |cur_s:=-2|
1763 to prevent further \.{DVI} output causing infinite recursion.
1764 @z
1765
1766 @x [32.601] l.11918 - dvi_swap: check dvi file size
1767 begin if dvi_limit=dvi_buf_size then
1768 @y
1769 begin if dvi_ptr>(@"7FFFFFFF-dvi_offset) then
1770 begin cur_s:=-2;
1771 fatal_error("dvi length exceeds ""7FFFFFFF");
1772 @.dvi length exceeds...@>
1773 end;
1774 if dvi_limit=dvi_buf_size then
1775 @z
1776
1777 @x [32.602] l.11932 - empty the last bytes: check dvi file size
1778 if dvi_ptr>0 then write_dvi(0,dvi_ptr-1)
1779 @y
1780 if dvi_ptr>(@"7FFFFFFF-dvi_offset) then
1781 begin cur_s:=-2;
1782 fatal_error("dvi length exceeds ""7FFFFFFF");
1783 @.dvi length exceeds...@>
1784 end;
1785 if dvi_ptr>0 then write_dvi(0,dvi_ptr-1)
1786 @z
1787
1788 @x [32.617] l.12261 - Use output_comment if the user set it. Assume it's short enough.
1789 old_setting:=selector; selector:=new_string;
1790 @y
1791 if output_comment then
1792 begin l:=strlen(output_comment); dvi_out(l);
1793 for s:=0 to l-1 do dvi_out(output_comment[s]);
1794 end
1795 else begin {the default code is unchanged}
1796 old_setting:=selector; selector:=new_string;
1797 @z
1798
1799 @x [32.617] l.12268 - Use output_comment if the user set it.
1800 pool_ptr:=str_start(str_ptr); {flush the current string}
1801 @y
1802 pool_ptr:=str_start(str_ptr); {flush the current string}
1803 end;
1804 @z
1805
1806 % We output each portion of the page as we get to it, if we are using
1807 % IPC, so that the previewer (TeXView) can display it immediately. [SPM]
1808 @x [32.640] l.12690 - IPC
1809 dvi_out(eop); incr(total_pages); cur_s:=-1;
1810 @y
1811 dvi_out(eop); incr(total_pages); cur_s:=-1;
1812 ifdef ('IPC')
1813 if ipc_on>0 then
1814 begin if dvi_limit=half_buf then
1815 begin write_dvi(half_buf, dvi_buf_size-1);
1816 flush_dvi;
1817 dvi_gone:=dvi_gone+half_buf;
1818 end;
1819 if dvi_ptr>(@"7FFFFFFF-dvi_offset) then
1820 begin cur_s:=-2;
1821 fatal_error("dvi length exceeds ""7FFFFFFF");
1822 @.dvi length exceeds...@>
1823 end;
1824 if dvi_ptr>0 then
1825 begin write_dvi(0, dvi_ptr-1);
1826 flush_dvi;
1827 dvi_offset:=dvi_offset+dvi_ptr; dvi_gone:=dvi_gone+dvi_ptr;
1828 end;
1829 dvi_ptr:=0; dvi_limit:=dvi_buf_size;
1830 ipc_page(dvi_gone);
1831 end;
1832 endif ('IPC');
1833 @z
1834
1835 @x [32.645] l.12766 - check dvi file size
1836 else begin dvi_out(post); {beginning of the postamble}
1837 @y
1838 else if cur_s<>-2 then
1839 begin dvi_out(post); {beginning of the postamble}
1840 @z
1841
1842 @x [32.645] l.12775 - Use dvi_offset instead of dvi_buf_size with IPC stuff.
1843 k:=4+((dvi_buf_size-dvi_ptr) mod 4); {the number of 223's}
1844 @y
1845 ifdef ('IPC')
1846 k:=7-((3+dvi_offset+dvi_ptr) mod 4); {the number of 223's}
1847 endif ('IPC')
1848 ifndef ('IPC')
1849 k:=4+((dvi_buf_size-dvi_ptr) mod 4); {the number of 223's}
1850 endifn ('IPC')
1851 @z
1852
1853 @x [32.642] l.12773 - use print_file_name
1854 print_nl("Output written on "); slow_print(output_file_name);
1855 @y
1856 print_nl("Output written on "); print_file_name(0, output_file_name, 0);
1857 @z
1858
1859 @x [42.920] l.18068 - bigtrie: allow larger hyphenation tries.
1860 @!trie_pointer=0..trie_size; {an index into |trie|}
1861 @y
1862 @!trie_pointer=0..ssup_trie_size; {an index into |trie|}
1863 @z
1864
1865 @x [42.921] l.18075 - bigtrie: allow larger hyphenation tries.
1866 @!trie:array[trie_pointer] of two_halves; {|trie_link|, |trie_char|, |trie_op|}
1867 @y
1868 {We will dynamically allocate this arrays.}
1869 @!trie:^two_halves; {|trie_link|}
1870 @z
1871
1872 %%%%%%%% dynamic hyph_size
1873 @x 18126 m.925
1874 different from $\alpha$, we can conclude that $\alpha$ is not in the table.
1875 @y 18126
1876 different from $\alpha$, we can conclude that $\alpha$ is not in the table.
1877 This is a clever scheme which saves the need for a hash link array.
1878 However, it is difficult to increase the size of the hyphen exception
1879 arrays. To make this easier, the ordered hash has been replaced by
1880 a simple hash, using an additional array |hyph_link|. The value
1881 |0| in |hyph_link[k]| means that there are no more entries corresponding
1882 to the specific hash chain. When |hyph_link[k]>0|, the next entry in
1883 the hash chain is |hyph_link[k]-1|. This value is used because the
1884 arrays start at |0|.
1885 @z
1886
1887 %%%%%%%% dynamic hyph_size
1888 @x 18134 m.925
1889 @!hyph_pointer=0..hyph_size; {an index into the ordered hash table}
1890 @y 18134
1891 @!hyph_pointer=0..ssup_hyph_size; {index into hyphen exceptions hash table;
1892 enlarging this requires changing (un)dump code}
1893 @z
1894
1895 %%%%%%%% dynamic hyph_size
1896 @x 18137 m.926
1897 @!hyph_word:array[hyph_pointer] of str_number; {exception words}
1898 @!hyph_list:array[hyph_pointer] of pointer; {lists of hyphen positions}
1899 @!hyph_count:hyph_pointer; {the number of words in the exception dictionary}
1900 @y 18139
1901 @!hyph_word: ^str_number; {exception words}
1902 @!hyph_list: ^pointer; {list of hyphen positions}
1903 @!hyph_link: ^hyph_pointer; {link array for hyphen exceptions hash table}
1904 @!hyph_count:integer; {the number of words in the exception dictionary}
1905 @!hyph_next:integer; {next free slot in hyphen exceptions hash table}
1906 @z
1907
1908 %%%%%%%% dynamic hyph_size
1909 @x 18145 m.928
1910 for z:=0 to hyph_size do
1911 begin hyph_word[z]:=0; hyph_list[z]:=null;
1912 end;
1913 hyph_count:=0;
1914 @y 18148
1915 for z:=0 to hyph_size do
1916 begin hyph_word[z]:=0; hyph_list[z]:=null; hyph_link[z]:=0;
1917 end;
1918 hyph_count:=0;
1919 hyph_next:=hyph_prime+1; if hyph_next>hyph_size then hyph_next:=hyph_prime;
1920 @z
1921
1922 %%%%%%%% dynamic hyph_size
1923 @x 18163 m.930
1924 h:=hc[1]; incr(hn); hc[hn]:=cur_lang;
1925 for j:=2 to hn do h:=(h+h+hc[j]) mod hyph_size;
1926 loop@+ begin @<If the string |hyph_word[h]| is less than \(hc)|hc[1..hn]|,
1927 |goto not_found|; but if the two strings are equal,
1928 set |hyf| to the hyphen positions and |goto found|@>;
1929 if h>0 then decr(h)@+else h:=hyph_size;
1930 end;
1931 not_found: decr(hn)
1932 @y 18170
1933 h:=hc[1]; incr(hn); hc[hn]:=cur_lang;
1934 for j:=2 to hn do h:=(h+h+hc[j]) mod hyph_prime;
1935 loop@+ begin @<If the string |hyph_word[h]| is less than \(hc)|hc[1..hn]|,
1936 |goto not_found|; but if the two strings are equal,
1937 set |hyf| to the hyphen positions and |goto found|@>;
1938 h:=hyph_link[h]; if h=0 then goto not_found;
1939 decr(h);
1940 end;
1941 not_found: decr(hn)
1942 @z
1943
1944 %%%%%%%% dynamic hyph_size
1945 @x 18172 m.931
1946 @ @<If the string |hyph_word[h]| is less than \(hc)...@>=
1947 k:=hyph_word[h]; if k=0 then goto not_found;
1948 if length(k)<hn then goto not_found;
1949 if length(k)=hn then
1950 begin j:=1; u:=str_start(k);
1951 repeat if so(str_pool[u])<hc[j] then goto not_found;
1952 if so(str_pool[u])>hc[j] then goto done;
1953 incr(j); incr(u);
1954 until j>hn;
1955 @<Insert hyphens as specified in |hyph_list[h]|@>;
1956 decr(hn); goto found;
1957 end;
1958 done:
1959 @y 18184
1960 @ @<If the string |hyph_word[h]| is less than \(hc)...@>=
1961 {This is now a simple hash list, not an ordered one, so
1962 the module title is no longer descriptive.}
1963 k:=hyph_word[h]; if k=0 then goto not_found;
1964 if length(k)=hn then
1965 begin j:=1; u:=str_start(k);
1966 repeat
1967 if so(str_pool[u])<>hc[j] then goto done;
1968 incr(j); incr(u);
1969 until j>hn;
1970 @<Insert hyphens as specified in |hyph_list[h]|@>;
1971 decr(hn); goto found;
1972 end;
1973 done:
1974 @z
1975
1976 % The GNU C compiler complains of unused variables.
1977 @x
1978 @!s,@!t:str_number; {strings being compared or stored}
1979 @y
1980 @!s:str_number; {strings being compared or stored}
1981 @z
1982
1983 %%%%%%%% dynamic hyph_size
1984 @x 18274 m.939
1985 begin h:=(h+h+hc[j]) mod hyph_size;
1986 @y 18274
1987 begin h:=(h+h+hc[j]) mod hyph_prime;
1988 @z
1989
1990 %%%%%%%% dynamic hyph_size
1991 @x 18281 m.940
1992 @ @<Insert the \(p)pair |(s,p)|...@>=
1993 if hyph_count=hyph_size then overflow("exception dictionary",hyph_size);
1994 @:TeX capacity exceeded exception dictionary}{\quad exception dictionary@>
1995 incr(hyph_count);
1996 while hyph_word[h]<>0 do
1997 begin @<If the string |hyph_word[h]| is less than \(or)or equal to
1998 |s|, interchange |(hyph_word[h],hyph_list[h])| with |(s,p)|@>;
1999 if h>0 then decr(h)@+else h:=hyph_size;
2000 end;
2001 hyph_word[h]:=s; hyph_list[h]:=p
2002 @y 18290
2003 @ @<Insert the \(p)pair |(s,p)|...@>=
2004 if hyph_next <= hyph_prime then
2005 while (hyph_next>0) and (hyph_word[hyph_next-1]>0) do decr(hyph_next);
2006 if (hyph_count=hyph_size)or(hyph_next=0) then
2007 overflow("exception dictionary",hyph_size);
2008 @:TeX capacity exceeded exception dictionary}{\quad exception dictionary@>
2009 incr(hyph_count);
2010 while hyph_word[h]<>0 do
2011 begin @<If the string |hyph_word[h]| is less than \(or)or equal to
2012 |s|, interchange |(hyph_word[h],hyph_list[h])| with |(s,p)|@>;
2013 if hyph_link[h]=0 then
2014 begin
2015 hyph_link[h]:=hyph_next;
2016 if hyph_next >= hyph_size then hyph_next:=hyph_prime;
2017 if hyph_next > hyph_prime then incr(hyph_next);
2018 end;
2019 h:=hyph_link[h]-1;
2020 end;
2021
2022 found: hyph_word[h]:=s; hyph_list[h]:=p
2023 @z
2024
2025 %%%%%%%% dynamic hyph_size
2026 @x 18292 m.941
2027 @ @<If the string |hyph_word[h]| is less than \(or)...@>=
2028 k:=hyph_word[h];
2029 if length(k)<length(s) then goto found;
2030 if length(k)>length(s) then goto not_found;
2031 u:=str_start(k); v:=str_start(s);
2032 repeat if str_pool[u]<str_pool[v] then goto found;
2033 if str_pool[u]>str_pool[v] then goto not_found;
2034 incr(u); incr(v);
2035 until u=str_start(k+1);
2036 found:q:=hyph_list[h]; hyph_list[h]:=p; p:=q;@/
2037 t:=hyph_word[h]; hyph_word[h]:=s; s:=t;
2038 not_found:
2039 @y 18303
2040 @ @<If the string |hyph_word[h]| is less than \(or)...@>=
2041 {This is now a simple hash list, not an ordered one, so
2042 the module title is no longer descriptive.}
2043 k:=hyph_word[h];
2044 if length(k)<>length(s) then goto not_found;
2045 u:=str_start(k); v:=str_start(s);
2046 repeat if str_pool[u]<>str_pool[v] then goto not_found;
2047 incr(u); incr(v);
2048 until u=str_start(k+1);
2049 {repeat hyphenation exception; flushing old data}
2050 flush_string; s:=hyph_word[h]; {avoid |slow_make_string|!}
2051 decr(hyph_count);
2052 { We could also |flush_list(hyph_list[h]);|, but it interferes
2053 with \.{trip.log}. }
2054 goto found;
2055 not_found:
2056 @z
2057
2058 @x [43.943] l.18346 - web2c can't parse negative lower bounds in arrays. Sorry.
2059 @!init @!trie_op_hash:array[-trie_op_size..trie_op_size] of 0..trie_op_size;
2060 @y
2061 @!init @!trie_op_hash:array[neg_trie_op_size..trie_op_size] of 0..trie_op_size;
2062 @z
2063
2064 @x [43.944] l.18365 - web2c can't parse negative lower bounds in arrays. Sorry
2065 var h:-trie_op_size..trie_op_size; {trial hash location}
2066 @y
2067 var h:neg_trie_op_size..trie_op_size; {trial hash location}
2068 @z
2069
2070 @x [43.944] l.18370 - Another casting problem, and use |neg_trie_op_size|.
2071 begin h:=abs(n+313*d+361*v+1009*cur_lang) mod (trie_op_size+trie_op_size)
2072 - trie_op_size;
2073 @y
2074 begin h:=abs(n+313*d+361*v+1009*cur_lang) mod (trie_op_size-neg_trie_op_size)
2075 + neg_trie_op_size;
2076 @z
2077
2078 @x [43.947] l.18438 - Dynamically allocate arrays, and a casting problem.
2079 @!init @!trie_c:packed array[trie_pointer] of ASCII_code;
2080 {characters to match}
2081 @t\hskip10pt@>@!trie_o:packed array[trie_pointer] of quarterword;
2082 {operations to perform}
2083 @t\hskip10pt@>@!trie_l:packed array[trie_pointer] of trie_pointer;
2084 {left subtrie links}
2085 @t\hskip10pt@>@!trie_r:packed array[trie_pointer] of trie_pointer;
2086 {right subtrie links}
2087 @t\hskip10pt@>@!trie_ptr:trie_pointer; {the number of nodes in the trie}
2088 @t\hskip10pt@>@!trie_hash:packed array[trie_pointer] of trie_pointer;
2089 {used to identify equivalent subtries}
2090 tini
2091 @y
2092 @!init @!trie_c:^ASCII_code;
2093 {characters to match}
2094 @t\hskip10pt@>@!trie_o:^quarterword;
2095 {operations to perform}
2096 @t\hskip10pt@>@!trie_l:^trie_pointer;
2097 {left subtrie links}
2098 @t\hskip10pt@>@!trie_r:^trie_pointer;
2099 {right subtrie links}
2100 @t\hskip10pt@>@!trie_ptr:trie_pointer; {the number of nodes in the trie}
2101 @t\hskip10pt@>@!trie_hash:^trie_pointer;
2102 {used to identify equivalent subtries}
2103 tini
2104 @z
2105
2106 @x [43.590] l.18524 - Dynamically allocate & larger tries.
2107 @!init @!trie_taken:packed array[1..trie_size] of boolean;
2108 {does a family start here?}
2109 @t\hskip10pt@>@!trie_min:array[ASCII_code] of trie_pointer;
2110 {the first possible slot for each character}
2111 @t\hskip10pt@>@!trie_max:trie_pointer; {largest location used in |trie|}
2112 @t\hskip10pt@>@!trie_not_ready:boolean; {is the trie still in linked form?}
2113 tini
2114 @y
2115 @!init @!trie_taken: ^boolean;
2116 {does a family start here?}
2117 @t\hskip10pt@>@!trie_min:^trie_pointer;
2118 {the first possible slot for each character}
2119 @t\hskip10pt@>@!trie_max:trie_pointer; {largest location used in |trie|}
2120 @t\hskip10pt@>@!trie_not_ready:boolean; {is the trie still in linked form?}
2121 tini
2122 @z
2123
2124 @x [43.951] l.18539 - Dynamically allocate.
2125 trie_not_ready:=true; trie_root:=0; trie_c[0]:=si(0); trie_ptr:=0;
2126 @y
2127 trie_not_ready:=true;
2128 @z
2129
2130 %%
2131 %% We can rewrite the original code after "main_loop_move+2" upto the
2132 %% "tail_append(lig_stack)" in module 1036 as
2133 %%
2134 %
2135 % main_loop_move+2:
2136 % if font_bc[main_f]<=cur_chr then
2137 % if cur_chr<=font_ec[main_f] then
2138 % begin main_i:=char_info(main_f)(cur_l);
2139 % if char_exists(main_i) goto main_loop_move+3;
2140 % end;
2141 % char_warning(main_f,cur_chr); free_avail(lig_stack); goto big_switch;
2142 % main_loop_move+3:
2143 % tail_append(lig_stack) {|main_loop_lookahead| is next}
2144 %
2145
2146 @x [49.1252] l.23230 - INI = VIR, so have to do runtime test.
2147 hyph_data: if cur_chr=1 then
2148 begin @!init new_patterns; goto done;@;@+tini@/
2149 @y 23215
2150 hyph_data: if cur_chr=1 then
2151 begin @!init if ini_version then
2152 begin new_patterns; goto done; end; @;@+tini@/
2153 @z
2154
2155 @x
2156 @!flushable_string:str_number; {string not yet referenced}
2157 @y
2158 @z
2159
2160 % undo Knuth's change because
2161 % a) the string is already replaced in |scan_file_name| and therefore
2162 % b) the wrong string will get flushed!!!
2163 %
2164 @x [49.1260] l.23331 new_font: string recycling -- already done
2165 flushable_string:=str_ptr-1;
2166 @y
2167 @z
2168
2169 % If you don't want to remove code with the following two changes,
2170 % please replace the former change by
2171 %
2172 % @x
2173 % flushable_string:=str_ptr-1;
2174 % @y
2175 % if cur_name=str_ptr-1 then
2176 % flushable_string:=str_ptr-1
2177 % else
2178 % flushable_string:=str_ptr; {number of a non-existing}
2179 % @z
2180 %
2181 % otherwise the wrong string will get removed by |flush_string|!!
2182 %
2183 @x [49.1260] l.23334 new_font: string recycling -- already done
2184 begin if cur_name=flushable_string then
2185 begin flush_string; cur_name:=font_name(f);
2186 end;
2187 if s>0 then
2188 @y
2189 begin if s>0 then
2190 @z
2191
2192 @x [49.1265] if batchmode, mktex... scripts should be silent.
2193 interaction:=cur_chr;
2194 @y
2195 interaction:=cur_chr;
2196 if interaction = batch_mode
2197 then kpse_make_tex_discard_errors := 1
2198 else kpse_make_tex_discard_errors := 0;
2199 @z
2200
2201 @x [49.1275] l.23441 - Same stuff as for \input, this time for \openin.
2202 if cur_ext="" then cur_ext:=".tex";
2203 pack_cur_name;
2204 if a_open_in(read_file[n]) then read_open[n]:=just_open;
2205 @y
2206 pack_cur_name;
2207 tex_input_type:=0; {Tell |open_input| we are \.{\\openin}.}
2208 if kpse_in_name_ok(name_of_file+1)
2209 and a_open_in(read_file[n], kpse_tex_format) then
2210 read_open[n]:=just_open;
2211 @z
2212
2213 @x [50.1301] l.23679 - INI = VIR, so runtime test.
2214 format_ident:=" (INIALEPH)";
2215 @y
2216 if ini_version then format_ident:=" (INIALEPH)";
2217 @z
2218
2219 % The GNU C compiler complains of unused variables.
2220 % Add format_engine.
2221 @x [50.1302] l.23690 - Eliminate now-unused variable `w' in `store_fmt_file'.
2222 var j,@!k,@!l:integer; {all-purpose indices}
2223 @!p,@!q: pointer; {all-purpose pointers}
2224 @!x: integer; {something to dump}
2225 @!w: four_quarters; {four ASCII codes}
2226 @y
2227 var j,@!k:integer; {all-purpose indices}
2228 @!p,@!q: pointer; {all-purpose pointers}
2229 @!x: integer; {something to dump}
2230 @!format_engine: ^char;
2231 @z
2232
2233 @x [50.1303] l.23722 - Ditto, for `load_fmt_file'.
2234 @!w: four_quarters; {four ASCII codes}
2235 @y
2236 @!format_engine: ^char;
2237 @z
2238
2239 @x [50.1305] l.23751 - Do dumping and undumping of fmt files in C.
2240 @d dump_wd(#)==begin fmt_file^:=#; put(fmt_file);@+end
2241 @d dump_int(#)==begin fmt_file^.int:=#; put(fmt_file);@+end
2242 @d dump_hh(#)==begin fmt_file^.hh:=#; put(fmt_file);@+end
2243 @d dump_qqqq(#)==begin fmt_file^.qqqq:=#; put(fmt_file);@+end
2244 @y
2245 @z
2246 @x [1306]
2247 @d undump_wd(#)==begin get(fmt_file); #:=fmt_file^;@+end
2248 @d undump_int(#)==begin get(fmt_file); #:=fmt_file^.int;@+end
2249 @d undump_hh(#)==begin get(fmt_file); #:=fmt_file^.hh;@+end
2250 @d undump_qqqq(#)==begin get(fmt_file); #:=fmt_file^.qqqq;@+end
2251 @y
2252 @z
2253 @x [still 1306] debug format file
2254 @d undump_size_end_end(#)==too_small(#)@+else undump_end_end
2255 @y
2256 @d format_debug_end(#)==
2257 write_ln (stderr, ' = ', #);
2258 end;
2259 @d format_debug(#)==
2260 if debug_format_file then begin
2261 write (stderr, 'fmtdebug:', #);
2262 format_debug_end
2263 @d undump_size_end_end(#)==
2264 too_small(#)@+else format_debug (#)(x); undump_end_end
2265 @z
2266
2267 @x [50,1307] l.23779 - texarray
2268 dump_int(@$);@/
2269 @y
2270 dump_int(@"57325458); {Web2C \TeX's magic constant: "W2TX"}
2271 {Align engine to 4 bytes with one or more trailing NUL}
2272 x:=strlen(engine_name);
2273 format_engine:=xmalloc_array(char,x+4);
2274 strcpy(format_engine, engine_name);
2275 for k:=x to x+3 do format_engine[k]:=0;
2276 x:=x+4-(x mod 4);
2277 dump_int(x);dump_things(format_engine[0], x);
2278 libc_free(format_engine);@/
2279 dump_int(@$);@/
2280 dump_int(max_halfword);@/
2281 @z
2282
2283 %%%%%%%% dynamic hyph_size
2284 @x 23784 m.1307
2285 dump_int(hyph_size)
2286 @y 23784
2287 dump_int(hyph_prime)
2288 @z
2289
2290 @x [50.1308] l.23793 - texarray
2291 x:=fmt_file^.int;
2292 if x<>@$ then goto bad_fmt; {check that strings are the same}
2293 @/@<Undump the \eTeX\ state@>@/
2294 undump_int(x);
2295 if x<>mem_bot then goto bad_fmt;
2296 undump_int(x);
2297 if x<>mem_top then goto bad_fmt;
2298 @y
2299 @+init
2300 if ini_version then
2301 begin libc_free(str_pool); libc_free(str_start_ar); libc_free(yzmem);
2302 end;
2303 @+tini
2304 undump_int(x);
2305 format_debug('format magic number')(x);
2306 if x<>@"57325458 then goto bad_fmt; {not a format file}
2307 undump_int(x);
2308 format_debug('engine name size')(x);
2309 if (x<0) or (x>256) then goto bad_fmt; {corrupted format file}
2310 format_engine:=xmalloc_array(char, x);
2311 undump_things(format_engine[0], x);
2312 format_engine[x-1]:=0; {force string termination, just in case}
2313 if strcmp(engine_name, format_engine) then
2314 begin wake_up_terminal;
2315 wterm_ln('---! ', stringcast(name_of_file+1), ' was written by ', format_engine);
2316 libc_free(format_engine);
2317 goto bad_fmt;
2318 end;
2319 libc_free(format_engine);
2320 undump_int(x);
2321 format_debug('string pool checksum')(x);
2322 if x<>@$ then begin {check that strings are the same}
2323 wake_up_terminal;
2324 wterm_ln('---! ', stringcast(name_of_file+1),
2325 ' made by different executable version, strings are different');
2326 goto bad_fmt;
2327 end;
2328 undump_int(x);
2329 if x<>max_halfword then goto bad_fmt; {check |max_halfword|}
2330 @/@<Undump the \eTeX\ state@>@/
2331
2332 undump_int(x); format_debug ('mem_bot')(x);
2333 if x<>mem_bot then goto bad_fmt;
2334 undump_int(mem_top); format_debug ('mem_top')(mem_top);
2335 if mem_bot+1100>mem_top then goto bad_fmt;
2336
2337
2338 head:=contrib_head; tail:=contrib_head;
2339 page_tail:=page_head; {page initialization}
2340
2341 mem_min := mem_bot - extra_mem_bot;
2342 mem_max := mem_top + extra_mem_top;
2343
2344 yzmem:=xmalloc_array (memory_word, mem_max - mem_min + 1);
2345 zmem := yzmem - mem_min; {this pointer arithmetic fails with some compilers}
2346 mem := zmem;
2347 @z
2348
2349 %%%%%%%% dynamic hyph_size
2350 @x 23804 m.1308
2351 if x<>hyph_size then goto bad_fmt
2352 @y 23804
2353 if x<>hyph_prime then goto bad_fmt
2354 @z
2355
2356 % [1309] Make dumping/undumping more efficient by doing whole arrays at
2357 % a time, via fread/fwrite in texmfmp.c.
2358 @x [50.1309] l.23814 - Make dumping/undumping more efficient.
2359 for k:=too_big_char to str_ptr do dump_int(str_start(k));
2360 k:=0;
2361 while k+4<pool_ptr do
2362 begin dump_four_ASCII; k:=k+4;
2363 end;
2364 k:=pool_ptr-4; dump_four_ASCII;
2365 @y
2366 dump_things(str_start(too_big_char), str_ptr-too_big_char+1);
2367 dump_things(str_pool[0], pool_ptr);
2368 @z
2369
2370 @x [50.1310] l.23829 - Make dumping/undumping more efficient.
2371 undump_size(0)(pool_size)('string pool size')(pool_ptr);
2372 undump_size(0)(max_strings)('max strings')(str_ptr);
2373 for k:=too_big_char to str_ptr do undump(0)(pool_ptr)(str_start(k));
2374 k:=0;
2375 while k+4<pool_ptr do
2376 begin undump_four_ASCII; k:=k+4;
2377 end;
2378 k:=pool_ptr-4; undump_four_ASCII;
2379 @y
2380 undump_size(0)(sup_pool_size-pool_free)('string pool size')(pool_ptr);
2381 if pool_size<pool_ptr+pool_free then
2382 pool_size:=pool_ptr+pool_free;
2383 undump_size(0)(sup_max_strings-strings_free)('sup strings')(str_ptr);@/
2384 if max_strings<str_ptr+strings_free then
2385 max_strings:=str_ptr+strings_free;
2386 str_start_ar:=xmalloc_array(pool_pointer, max_strings-biggest_char);
2387 undump_things(str_start(too_big_char), str_ptr-too_big_char+1);
2388 str_pool:=xmalloc_array(packed_ASCII_code, pool_size);
2389 undump_things(str_pool[0], pool_ptr);
2390 @z
2391
2392 @x [50.1311] l.23850 - Make dumping/undumping more efficient.
2393 repeat for k:=p to q+1 do dump_wd(mem[k]);
2394 @y
2395 repeat dump_things(mem[p], q+2-p);
2396 @z
2397
2398 @x [50.1311] l.23855 - Make dumping/undumping more efficient.
2399 for k:=p to lo_mem_max do dump_wd(mem[k]);
2400 @y
2401 dump_things(mem[p], lo_mem_max+1-p);
2402 @z
2403
2404 @x [50.1311] l.23858 - Make dumping/undumping more efficient.
2405 for k:=hi_mem_min to mem_end do dump_wd(mem[k]);
2406 @y
2407 dump_things(mem[hi_mem_min], mem_end+1-hi_mem_min);
2408 @z
2409
2410 @x [50.1312] l.23873 - Make dumping/undumping more efficient.
2411 repeat for k:=p to q+1 do undump_wd(mem[k]);
2412 @y
2413 repeat undump_things(mem[p], q+2-p);
2414 @z
2415
2416 @x [50.1312] l.23878 - Make dumping/undumping more efficient.
2417 for k:=p to lo_mem_max do undump_wd(mem[k]);
2418 @y
2419 undump_things(mem[p], lo_mem_max+1-p);
2420 @z
2421
2422 @x [50.1312] l.23888 - Make dumping/undumping more efficient.
2423 for k:=hi_mem_min to mem_end do undump_wd(mem[k]);
2424 @y
2425 undump_things (mem[hi_mem_min], mem_end+1-hi_mem_min);
2426 @z
2427
2428 %%%%%%%% dynamic hyph_size
2429 @x 24058 m.1324
2430 dump_int(hyph_count);
2431 for k:=0 to hyph_size do if hyph_word[k]<>0 then
2432 begin dump_int(k); dump_int(hyph_word[k]); dump_int(hyph_list[k]);
2433 end;
2434 @y 24061
2435 dump_int(hyph_count);
2436 if hyph_next <= hyph_prime then hyph_next:=hyph_size;
2437 dump_int(hyph_next);{minumum value of |hyphen_size| needed}
2438 for k:=0 to hyph_size do if hyph_word[k]<>0 then
2439 begin dump_int(k+65536*hyph_link[k]);
2440 {assumes number of hyphen exceptions does not exceed 65535}
2441 dump_int(hyph_word[k]); dump_int(hyph_list[k]);
2442 end;
2443 @z
2444
2445 @x [50.1324] l.24066 - Make dumping/undumping more efficient - trie
2446 for k:=0 to trie_max do dump_hh(trie[k]);
2447 dump_int(max_hyph_char);
2448 dump_int(trie_op_ptr);
2449 for k:=1 to trie_op_ptr do
2450 begin dump_int(hyf_distance[k]);
2451 dump_int(hyf_num[k]);
2452 dump_int(hyf_next[k]);
2453 end;
2454 @y
2455 dump_things(trie[0],trie_max+1);
2456 dump_int(max_hyph_char);
2457 dump_int(trie_op_ptr);
2458 dump_things(hyf_distance[1], trie_op_ptr);
2459 dump_things(hyf_num[1], trie_op_ptr);
2460 dump_things(hyf_next[1], trie_op_ptr);
2461 @z
2462
2463 @x [50.1325] l.24086 - Make dumping/undumping more efficient - trie
2464 @<Undump the hyphenation tables@>=
2465 @y
2466 {This is only used for the hyphenation tries below, and the size is
2467 always |j+1|.}
2468 @d xmalloc_and_undump(#) ==
2469 if not # then #:=xmalloc_array(two_halves, j+1);
2470 undump_things(#[0], j+1);
2471
2472 @<Undump the hyphenation tables@>=
2473 @z
2474
2475 %%%%%%%% dynamic hyph_size
2476 @x 24087 m.1325
2477 undump(0)(hyph_size)(hyph_count);
2478 for k:=1 to hyph_count do
2479 begin undump(0)(hyph_size)(j);
2480 undump(0)(str_ptr)(hyph_word[j]);
2481 undump(min_halfword)(max_halfword)(hyph_list[j]);
2482 end;
2483 @y 24092
2484 undump_size(0)(hyph_size)('hyph_size')(hyph_count);
2485 undump_size(hyph_prime)(hyph_size)('hyph_size')(hyph_next);
2486 j:=0;
2487 for k:=1 to hyph_count do
2488 begin undump_int(j); if j<0 then goto bad_fmt;
2489 if j>65535 then
2490 begin hyph_next:= j div 65536; j:=j - hyph_next * 65536; end
2491 else hyph_next:=0;
2492 if (j>=hyph_size)or(hyph_next>hyph_size) then goto bad_fmt;
2493 hyph_link[j]:=hyph_next;
2494 undump(0)(str_ptr)(hyph_word[j]);
2495 undump(min_halfword)(max_halfword)(hyph_list[j]);
2496 end;
2497 {|j| is now the largest occupied location in |hyph_word|}
2498 incr(j);
2499 if j<hyph_prime then j:=hyph_prime;
2500 hyph_next:=j;
2501 if hyph_next >= hyph_size then hyph_next:=hyph_prime else
2502 if hyph_next >= hyph_prime then incr(hyph_next);
2503 @z
2504
2505
2506 @x [50.1325] l.24094 - Make dumping/undumping more efficient - trie
2507 for k:=0 to j do undump_hh(trie[k]);
2508 undump_int(max_hyph_char);
2509 undump_size(0)(trie_op_size)('trie op size')(j); @+init trie_op_ptr:=j;@+tini
2510 for k:=1 to j do
2511 begin undump(0)(63)(hyf_distance[k]); {a |small_number|}
2512 undump(0)(63)(hyf_num[k]);
2513 undump(min_quarterword)(max_quarterword)(hyf_next[k]);
2514 end;
2515 @y
2516 {The first array has not been allocated yet unless we're \.{INITEX};
2517 we do that precisely so we don't allocate more space than necessary.}
2518 xmalloc_and_undump(trie);
2519 undump_int(max_hyph_char);
2520 undump_size(0)(trie_op_size)('trie op size')(j); @+init trie_op_ptr:=j;@+tini
2521 {I'm not sure we have such a strict limitation (64) on these values, so
2522 let's leave them unchecked.}
2523 undump_things(hyf_distance[1], j);
2524 undump_things(hyf_num[1], j);
2525 undump_upper_check_things(max_quarterword, hyf_next[1], j);
2526 @z
2527
2528 @x [50.1327] l.24117 - Allow command line to override dumped value.
2529 undump(batch_mode)(error_stop_mode)(interaction);
2530 @y
2531 undump(batch_mode)(error_stop_mode)(interaction);
2532 if interaction_option<>unspecified_mode then interaction:=interaction_option;
2533 @z
2534
2535 @x [50.1327] l.24172 - Test for end-of-file already done by undump.
2536 if (x<>69069)or eof(fmt_file) then goto bad_fmt
2537 @y
2538 if x<>69069 then goto bad_fmt
2539 @z
2540
2541 @x [51.1332] l.24203 - make the main program a procedure, for eqtb hack.
2542 @p begin @!{|start_here|}
2543 @y
2544 @d const_chk(#)==begin if # < inf@&# then # := inf@&# else
2545 if # > sup@&# then # := sup@&# end
2546
2547 {|setup_bound_var| stuff duplicated in \.{mf.ch}.}
2548 @d setup_bound_var(#)==bound_default:=#; setup_bound_var_end
2549 @d setup_bound_var_end(#)==bound_name:=#; setup_bound_var_end_end
2550 @d setup_bound_var_end_end(#)==
2551 setup_bound_variable(addressof(#), bound_name, bound_default);
2552
2553 @p procedure main_body;
2554 begin @!{|start_here|}
2555
2556 {Always start the file recorder?}
2557 {|recorder_enabled:=true;|}
2558
2559 {Bounds that may be set from the configuration file. We want the user to
2560 be able to specify the names with underscores, but \.{TANGLE} removes
2561 underscores, so we're stuck giving the names twice, once as a string,
2562 once as the identifier. How ugly.}
2563 setup_bound_var (1000000)('main_memory')(main_memory);
2564 {|memory_word|s for |mem| in \.{INITEX}}
2565 setup_bound_var (0)('extra_mem_top')(extra_mem_top);
2566 {increase high mem in \.{VIRTEX}}
2567 setup_bound_var (0)('extra_mem_bot')(extra_mem_bot);
2568 {increase low mem in \.{VIRTEX}}
2569 setup_bound_var (300000)('pool_size')(pool_size);
2570 setup_bound_var (200000)('string_vacancies')(string_vacancies);
2571 setup_bound_var (5000)('pool_free')(pool_free); {min pool avail after fmt}
2572 setup_bound_var (100000)('max_strings')(max_strings);
2573 setup_bound_var (100)('strings_free')(strings_free);
2574 setup_bound_var (20000)('trie_size')(trie_size);
2575 {if |ssup_trie_size| increases, recompile}
2576 setup_bound_var (659)('hyph_size')(hyph_size);
2577 setup_bound_var (20000)('buf_size')(buf_size);
2578 setup_bound_var (50)('nest_size')(nest_size);
2579 setup_bound_var (15)('max_in_open')(max_in_open);
2580 setup_bound_var (60)('param_size')(param_size);
2581 setup_bound_var (4000)('save_size')(save_size);
2582 setup_bound_var (300)('stack_size')(stack_size);
2583 setup_bound_var (16384)('dvi_buf_size')(dvi_buf_size);
2584 setup_bound_var (79)('error_line')(error_line);
2585 setup_bound_var (50)('half_error_line')(half_error_line);
2586 setup_bound_var (79)('max_print_line')(max_print_line);
2587 setup_bound_var (10000)('expand_depth')(expand_depth);
2588 const_chk (main_memory);
2589 @+init
2590 if ini_version then begin
2591 extra_mem_top := 0;
2592 end;
2593 @+tini
2594 extra_mem_bot := 0;
2595 if extra_mem_top>sup_main_memory then extra_mem_top:=sup_main_memory;
2596 {|mem_top| is an index, |main_memory| a size}
2597 mem_top := mem_bot + main_memory -1;
2598 mem_min := mem_bot;
2599 mem_max := mem_top;
2600
2601 {Check other constants against their sup and inf.}
2602 const_chk (trie_size);
2603 const_chk (hyph_size);
2604 const_chk (buf_size);
2605 const_chk (nest_size);
2606 const_chk (max_in_open);
2607 const_chk (param_size);
2608 const_chk (save_size);
2609 const_chk (stack_size);
2610 const_chk (dvi_buf_size);
2611 const_chk (pool_size);
2612 const_chk (string_vacancies);
2613 const_chk (pool_free);
2614 const_chk (max_strings);
2615 const_chk (strings_free);
2616 if error_line > ssup_error_line then error_line := ssup_error_line;
2617
2618 {array memory allocation}
2619 buffer:=xmalloc_array (ASCII_code, buf_size);
2620 nest:=xmalloc_array (list_state_record, nest_size);
2621 save_stack:=xmalloc_array (memory_word, save_size);
2622 input_stack:=xmalloc_array (in_state_record, stack_size);
2623 input_file:=xmalloc_array (alpha_file, max_in_open);
2624 input_file_mode:=xmalloc_array (halfword, max_in_open);
2625 input_file_translation:=xmalloc_array (halfword, max_in_open);
2626 line_stack:=xmalloc_array (integer, max_in_open);
2627 param_stack:=xmalloc_array (halfword, param_size);
2628 dvi_buf:=xmalloc_array (real_eight_bits, dvi_buf_size);
2629 hyph_word:=xmalloc_array (str_number, hyph_size);
2630 hyph_list:=xmalloc_array (halfword, hyph_size);
2631 hyph_link:=xmalloc_array (hyph_pointer, hyph_size);
2632 @+init
2633 if ini_version then begin
2634 yzmem:=xmalloc_array (memory_word, mem_top - mem_bot + 1);
2635 zmem := yzmem - mem_bot; {Some compilers require |mem_bot=0|}
2636
2637 str_start_ar:=xmalloc_array (pool_pointer, max_strings-biggest_char);
2638 str_pool:=xmalloc_array (packed_ASCII_code, pool_size);
2639 end;
2640 @+tini
2641 @z
2642
2643 @x [51.1332] l.24215 - INI = VIR, so pool init needs runtime test
2644 @!init if not get_strings_started then goto final_end;
2645 init_prim; {call |primitive| for each primitive}
2646 init_str_ptr:=str_ptr; init_pool_ptr:=pool_ptr; fix_date_and_time;
2647 tini@/
2648 @y
2649 @+init if ini_version then
2650 begin if not get_strings_started then goto final_end;
2651 init_prim; {call |primitive| for each primitive}
2652 init_str_ptr:=str_ptr; init_pool_ptr:=pool_ptr; fix_date_and_time;
2653 end;
2654 @+tini@/
2655 @z
2656
2657 @x [51.1332] l.24225 - main
2658 end_of_TEX: close_files_and_terminate;
2659 final_end: ready_already:=0;
2660 end.
2661 @y
2662 close_files_and_terminate;
2663 final_end: do_final_end;
2664 end {|main_body|};
2665 @z
2666
2667 @x
2668 begin @<Finish the extensions@>; new_line_char:=-1;
2669 @y
2670 begin @<Finish the extensions@>; set_new_eqtb_int(int_base+new_line_char_code,-1);
2671 @z
2672
2673 @x [51.1333] l.24254 - Print new line before termination; switch to editor if necessary.
2674 slow_print(log_name); print_char(".");
2675 end;
2676 end;
2677 @y
2678 print_file_name(0, log_name, 0); print_char(".");
2679 end;
2680 end;
2681 print_ln;
2682 if (edit_name_start<>0) and (interaction>batch_mode) then
2683 call_edit(str_pool,edit_name_start,edit_name_length,edit_line);
2684 @z
2685
2686 @x [51.1334] l. - Remove reference to fontmemsize
2687 wlog_ln(', out of ',font_mem_size:1,' for ',font_max-font_base:1);@/
2688 @y
2689 @z
2690
2691 @x
2692 begin c:=cur_chr; if c<>1 then new_line_char:=-1;
2693 @y
2694 begin c:=cur_chr; if c<>1 then set_new_eqtb_int(int_base+new_line_char_code,-1);
2695 @z
2696
2697 @x [51.1335] l.24335 - Only do dump if ini.
2698 begin @!init for c:=top_mark_code to split_bot_mark_code do
2699 if cur_mark[c]<>null then delete_token_ref(cur_mark[c]);
2700 if sa_mark<>null then
2701 if do_marks(destroy_marks,0,sa_mark) then sa_mark:=null;
2702 for c:=last_box_code to vsplit_code do flush_node_list(disc_ptr[c]);
2703 if last_glue<>max_halfword then delete_glue_ref(last_glue);
2704 store_fmt_file; return;@+tini@/
2705 @y
2706 begin @!init if ini_version then
2707 begin for c:=top_mark_code to split_bot_mark_code do
2708 if cur_mark[c]<>null then delete_token_ref(cur_mark[c]);
2709 if sa_mark<>null then
2710 if do_marks(destroy_marks,0,sa_mark) then sa_mark:=null;
2711 for c:=last_box_code to vsplit_code do flush_node_list(disc_ptr[c]);
2712 store_fmt_file; return;
2713 end;@+tini@/
2714 @z
2715
2716 @x [51.1337] l.24361 - Handle %&format in all cases.
2717 if (format_ident=0)or(buffer[loc]="&") then
2718 @y
2719 if (format_ident=0)or(buffer[loc]="&")or dump_line then
2720 @z
2721
2722 @x [51.1337] l.24371 - Allocate hyphenation tries.
2723 fix_date_and_time;@/
2724 @y
2725 fix_date_and_time;@/
2726
2727 @!init
2728 if trie_not_ready then begin {initex without format loaded}
2729 trie:=xmalloc_array (two_halves, trie_size);
2730
2731 trie_c:=xmalloc_array (ASCII_code, trie_size);
2732 trie_o:=xmalloc_array (quarterword, trie_size);
2733 trie_l:=xmalloc_array (trie_pointer, trie_size);
2734 trie_r:=xmalloc_array (trie_pointer, trie_size);
2735 trie_hash:=xmalloc_array (trie_pointer, trie_size);
2736 trie_taken:=xmalloc_array (boolean, trie_size);
2737 trie_min:=xmalloc_array (trie_pointer, too_big_char);
2738
2739 trie_root:=0; trie_c[0]:=si(0); trie_ptr:=0;
2740 end;
2741 tini@/
2742
2743 @z
2744
2745 % [52.1338] Core-dump in debugging mode on 0 input. Under Unix, it's
2746 % not possible to portably switch into the debugger while a program is
2747 % running. The best approximation is to do a core dump, then run the
2748 % debugger on it later.
2749 @x [52.1338] l.24411 - Core-dump in debugging mode on 0 input.
2750 begin goto breakpoint;@/ {go to every declared label at least once}
2751 breakpoint: m:=0; @{'BREAKPOINT'@}@/
2752 end
2753 @y
2754 dump_core {do something to cause a core dump}
2755 @z
2756
2757 % The GNU C compiler complains of unused variables.
2758 @x
2759 procedure do_extension;
2760 var i,@!j,@!k:integer; {all-purpose integers}
2761 @!p,@!q,@!r:pointer; {all-purpose pointers}
2762 @y
2763 procedure do_extension;
2764 var @!k:integer; {all-purpose integers}
2765 @!p:pointer; {all-purpose pointers}
2766 @z
2767
2768 % [53.1350] (new_write_whatsit) Allow 18 as a \write stream. We never
2769 % refer to an actual file, though, so we don't need to change the
2770 % write_file or write_open arrays. We provide for disabling this at
2771 % runtime, for paranoids.
2772 @x [53.1350] l.24609 - system: Allow 18 as a \write stream.
2773 else if cur_val>15 then cur_val:=16;
2774 @y
2775 else if (cur_val>15) and (cur_val <> 18) then cur_val:=16;
2776 @z
2777
2778 @x [53.1370] l.24770 - system: (write_out) \write18{foo} => system(foo).
2779 begin @<Expand macros in the token list
2780 @y
2781 @!d:integer; {number of characters in incomplete current string}
2782 @!clobbered:boolean; {system string is ok?}
2783 @!runsystem_ret:integer; {return value from |runsystem|}
2784 begin @<Expand macros in the token list
2785 @z
2786
2787 @x [53.1370] l.24773 - system: (write_out) \write18{foo} => system(foo).
2788 if write_open[j] then selector:=j
2789 @y
2790 if j=18 then selector := new_string
2791 else if write_open[j] then selector:=j
2792 @z
2793
2794 % Then call system(3) on that string.
2795 @x [53.1370] l.24779 - system: (write_out) \write18{foo} => system(foo).
2796 flush_list(def_ref); selector:=old_setting;
2797 @y
2798 flush_list(def_ref);
2799 if j=18 then
2800 begin if (tracing_online<=0) then
2801 selector:=log_only {Show what we're doing in the log file.}
2802 else selector:=term_and_log; {Show what we're doing.}
2803 {If the log file isn't open yet, we can only send output to the terminal.
2804 Calling |open_log_file| from here seems to result in bad data in the log.}
2805 if not log_opened then selector:=term_only;
2806 print_nl("runsystem(");
2807 for d:=0 to cur_length-1 do
2808 begin {|print| gives up if passed |str_ptr|, so do it by hand.}
2809 print(so(str_pool[str_start(str_ptr)+d])); {N.B.: not |print_char|}
2810 end;
2811 print(")...");
2812 if shellenabledp then begin
2813 str_room(1); append_char(0); {Append a null byte to the expansion.}
2814 clobbered:=false;
2815 for d:=0 to cur_length-1 do {Convert to external character set.}
2816 begin
2817 str_pool[str_start(str_ptr)+d]:=xchr[str_pool[str_start(str_ptr)+d]];
2818 if (str_pool[str_start(str_ptr)+d]=null_code)
2819 and (d<cur_length-1) then clobbered:=true;
2820 {minimal checking: NUL not allowed in argument string of |system|()}
2821 end;
2822 if clobbered then print("clobbered")
2823 else begin {We have the command. See if we're allowed to execute it,
2824 and report in the log. We don't check the actual exit status of
2825 the command, or do anything with the output.}
2826 for d:=0 to cur_length-1 do {Convert to external character set.}
2827 begin
2828 outside_string_array[d]:=xchr[str_pool[str_start(str_ptr)+d]];
2829 end;
2830 outside_string_array[cur_length]:=null_code;
2831 runsystem_ret := runsystem(stringcast(outside_string_array));
2832 if runsystem_ret = -1 then print("quotation error in system command")
2833 else if runsystem_ret = 0 then print("disabled (restricted)")
2834 else if runsystem_ret = 1 then print("executed")
2835 else if runsystem_ret = 2 then print("executed safely (allowed)")
2836 end;
2837 end else begin
2838 print("disabled"); {|shellenabledp| false}
2839 end;
2840 print_char("."); print_nl(""); print_ln;
2841 pool_ptr:=str_start(str_ptr); {erase the string}
2842 end;
2843 selector:=old_setting;
2844 @z
2845
2846 @x [53.1373] Need new local.
2847 procedure out_what(@!p:pointer);
2848 var j:small_number; {write stream number}
2849 @y
2850 procedure out_what(@!p:pointer);
2851 var j:small_number; {write stream number}
2852 @!old_setting:0..max_selector;
2853 @z
2854
2855 @x [53.1374]
2856 else begin if write_open[j] then a_close(write_file[j]);
2857 if subtype(p)=close_node then write_open[j]:=false
2858 @y
2859 else begin if write_open[j] then begin a_close(write_file[j]);
2860 write_open[j]:=false; end;
2861 if subtype(p)=close_node then do_nothing {already closed}
2862 @z
2863
2864 @x [still 53.1374] Disallow certain \openout filenames, and log results.
2865 while not a_open_out(write_file[j]) do
2866 prompt_file_name("output file name",".tex");
2867 write_open[j]:=true;
2868 @y
2869 while not kpse_out_name_ok(name_of_file+1)
2870 or not a_open_out(write_file[j]) do
2871 prompt_file_name("output file name",".tex");
2872 write_open[j]:=true;
2873 {If on first line of input, log file is not ready yet, so don't log.}
2874 if log_opened and texmf_yesno('log_openout') then begin
2875 old_setting:=selector;
2876 if (tracing_online<=0) then
2877 selector:=log_only {Show what we're doing in the log file.}
2878 else selector:=term_and_log; {Show what we're doing.}
2879 print_nl("\openout");
2880 print_int(j);
2881 print(" = `");
2882 print_file_name(cur_name,cur_area,cur_ext);
2883 print("'."); print_nl(""); print_ln;
2884 selector:=old_setting;
2885 end;
2886 @z
2887
2888 @x [54.1376] l.24903 - Add editor-switch variables to globals.
2889 @* \[54] System-dependent changes.
2890 @y
2891 @* \[54/web2c] System-dependent changes for Web2c.
2892 Here are extra variables for Web2c. (This numbering of the
2893 system-dependent section allows easy integration of Web2c and e-\TeX, etc.)
2894 @^<system dependencies@>
2895
2896 @<Glob...@>=
2897 @!edit_name_start: pool_pointer; {where the filename to switch to starts}
2898 @!edit_name_length,@!edit_line: integer; {what line to start editing at}
2899 @!ipc_on: cinttype; {level of IPC action, 0 for none [default]}
2900 @!stop_at_space: boolean; {whether |more_name| returns false for space}
2901
2902 @ The |edit_name_start| will be set to point into |str_pool| somewhere after
2903 its beginning if \TeX\ is supposed to switch to an editor on exit.
2904
2905 Initialize the |stop_at_space| variable for filename parsing.
2906
2907 Initialize the |halting_on_error_p| variable to avoid infloop with
2908 \.{--halt-on-error}.
2909
2910 @<Set init...@>=
2911 edit_name_start:=0;
2912 stop_at_space:=true;
2913 halting_on_error_p:=false;
2914
2915 @ These are used when we regenerate the representation of the first 256
2916 strings.
2917
2918 @<Global...@> =
2919 @!save_str_ptr: str_number;
2920 @!save_pool_ptr: pool_pointer;
2921 @!shellenabledp: cinttype;
2922 @!restrictedshell: cinttype;
2923 @!output_comment: ^char;
2924 @!k,l: 0..65535; {used by `Make the first 256 strings', etc.}
2925
2926 @ When debugging a macro package, it can be useful to see the exact
2927 control sequence names in the format file. For example, if ten new
2928 csnames appear, it's nice to know what they are, to help pinpoint where
2929 they came from. (This isn't a truly ``basic'' printing procedure, but
2930 that's a convenient module in which to put it.)
2931
2932 @<Basic printing procedures@> =
2933 procedure print_csnames (hstart:integer; hfinish:integer);
2934 var c,h:integer;
2935 begin
2936 write_ln(stderr, 'fmtdebug:csnames from ', hstart, ' to ', hfinish, ':');
2937 for h := hstart to hfinish do begin
2938 if newtext(h) > 0 then begin {if have anything at this position}
2939 for c := str_start(newtext(h)) to str_start(newtext(h) + 1) - 1
2940 do begin
2941 put_byte(str_pool[c], stderr); {print the characters}
2942 end;
2943 write_ln(stderr, '|');
2944 end;
2945 end;
2946 end;
2947
2948 @ Are we printing extra info as we read the format file?
2949
2950 @<Glob...@> =
2951 @!debug_format_file: boolean;
2952
2953
2954 @ A helper for printing file:line:error style messages. Look for a
2955 filename in |full_source_filename_stack|, and if we fail to find
2956 one fall back on the non-file:line:error style.
2957
2958 @<Basic print...@>=
2959 procedure print_file_line;
2960 var level: 0..max_in_open;
2961 begin
2962 level:=in_open;
2963 while (level>0) and (full_source_filename_stack[level]=0) do
2964 decr(level);
2965 if level=0 then
2966 print_nl("! ")
2967 else begin
2968 print_nl (""); print (full_source_filename_stack[level]); print (":");
2969 if level=in_open then print_int (line)
2970 else print_int (line_stack[level+1]);
2971 print (": ");
2972 end;
2973 end;
2974
2975 @ To be able to determine whether \.{\\write18} is enabled from within
2976 \TeX\ we also implement \.{\\eof18}. We sort of cheat by having an
2977 additional route |scan_four_bit_int_or_18| which is the same as
2978 |scan_four_bit_int| except it also accepts the value 18.
2979
2980 @<Declare procedures that scan restricted classes of integers@>=
2981 procedure scan_four_bit_int_or_18;
2982 begin scan_int;
2983 if (cur_val<0)or((cur_val>15)and(cur_val<>18)) then
2984 begin print_err("Bad number");
2985 @.Bad number@>
2986 help2("Since I expected to read a number between 0 and 15,")@/
2987 ("I changed this one to zero."); int_error(cur_val); cur_val:=0;
2988 end;
2989 end;
2990
2991 @* \[54/web2c-string] The string recycling routines.
2992 \TeX{} uses 2 upto 4 {\it new\/} strings when scanning a filename in an
2993 \.{\\input}, \.{\\openin}, or \.{\\openout} operation. These strings are
2994 normally lost because the reference to them are not saved after finishing
2995 the operation. |search_string| searches through the string pool for the
2996 given string and returns either 0 or the found string number.
2997
2998 @<Declare additional routines for string recycling@>=
2999 function search_string(@!search:str_number):str_number;
3000 label found;
3001 var result: str_number;
3002 @!s: str_number; {running index}
3003 @!len: integer; {length of searched string}
3004 begin result:=0; len:=length(search);
3005 if len=0 then {trivial case}
3006 begin result:=""; goto found;
3007 end
3008 else begin s:=search-1; {start search with newest string below |s|; |search>1|!}
3009 while s>65535 do {first 65536 strings depend on implementation!!}
3010 begin if length(s)=len then
3011 if str_eq_str(s,search) then
3012 begin result:=s; goto found;
3013 end;
3014 decr(s);
3015 end;
3016 end;
3017 found:search_string:=result;
3018 end;
3019
3020 @ The following routine is a variant of |make_string|. It searches
3021 the whole string pool for a string equal to the string currently built
3022 and returns a found string. Otherwise a new string is created and
3023 returned. Be cautious, you can not apply |flush_string| to a replaced
3024 string!
3025
3026 @<Declare additional routines for string recycling@>=
3027 function slow_make_string : str_number;
3028 label exit;
3029 var s: str_number; {result of |search_string|}
3030 @!t: str_number; {new string}
3031 begin t:=make_string; s:=search_string(t);
3032 if s>0 then
3033 begin flush_string; slow_make_string:=s; return;
3034 end;
3035 slow_make_string:=t;
3036 exit:end;
3037
3038 @ This function used to be in pdftex, but is useful in aleph too.
3039
3040 @p function get_nullstr: str_number;
3041 begin
3042 get_nullstr := "";
3043 end;
3044
3045
3046 @* \[54/web2c] More changes for Web2c.
3047 % Related to [25.366] expansion depth check
3048 Sometimes, recursive calls to the |expand| routine may
3049 cause exhaustion of the run-time calling stack, resulting in
3050 forced execution stops by the operating system. To diminish the chance
3051 of this happening, a counter is used to keep track of the recursion
3052 depth, in conjunction with a constant called |expand_depth|.
3053
3054 This does not catch all possible infinite recursion loops, just the ones
3055 that exhaust the application calling stack. The actual maximum value of
3056 |expand_depth| is outside of our control, but the initial setting of
3057 |10000| should be enough to prevent problems.
3058 @^system dependencies@>
3059
3060 @<Global...@>=
3061 expand_depth_count:integer;
3062
3063 @ @<Set init...@>=
3064 expand_depth_count:=0;
3065
3066
3067 @* \[54] System-dependent changes.
3068 @z