Debian Codegraph @

texk/web2c/luatexdir/tex/mainbody.c

raw
1 /*
2
3 mainbody.w
4
5 Copyright 2009-2010 Taco Hoekwater <taco@@luatex.org>
6
7 This file is part of LuaTeX.
8
9 LuaTeX is free software; you can redistribute it and/or modify it under
10 the terms of the GNU General Public License as published by the Free
11 Software Foundation; either version 2 of the License, or (at your
12 option) any later version.
13
14 LuaTeX is distributed in the hope that it will be useful, but WITHOUT
15 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
16 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
17 License for more details.
18
19 You should have received a copy of the GNU General Public License along
20 with LuaTeX; if not, see <http://www.gnu.org/licenses/>.
21
22 */
23
24 #include "ptexlib.h"
25
26 /*tex
27
28 This is where the action starts. We're speaking of \LUATEX, a continuation of
29 \PDFTEX\ (which included \ETEX) and \ALEPH. As \TEX, \LUATEX\ is a document
30 compiler intended to simplify high quality typesetting for many of the world's
31 languages. It is an extension of D. E. Knuth's \TEX, which was designed
32 essentially for the typesetting of languages using the Latin alphabet. Although
33 it is a direct decendant of \TEX, and therefore mostly compatible, there are
34 some subtle differences that relate to \UNICODE\ support and \OPENTYPE\ math.
35
36 The \ALEPH\ subsystem loosens many of the restrictions imposed by~\TeX: register
37 numbers are no longer limited to 8~bits. Fonts may have more than 256~characters,
38 more than 256~fonts may be used, etc. We use a similar model. We also borrowed
39 the directional model but have upgraded it a bit as well as integrated it more
40 tightly.
41
42 This program is directly derived from Donald E. Knuth's \TEX; the change history
43 which follows and the reward offered for finders of bugs refer specifically to
44 \TEX; they should not be taken as referring to \LUATEX, \PDFTEX, nor \ETEX,
45 although the change history is relevant in that it demonstrates the evolutionary
46 path followed. This program is not \TEX; that name is reserved strictly for the
47 program which is the creation and sole responsibility of Professor Knuth.
48
49 \starttyping
50 % Version 0 was released in September 1982 after it passed a variety of tests.
51 % Version 1 was released in November 1983 after thorough testing.
52 % Version 1.1 fixed ``disappearing font identifiers'' et alia (July 1984).
53 % Version 1.2 allowed `0' in response to an error, et alia (October 1984).
54 % Version 1.3 made memory allocation more flexible and local (November 1984).
55 % Version 1.4 fixed accents right after line breaks, et alia (April 1985).
56 % Version 1.5 fixed \the\toks after other expansion in \edefs (August 1985).
57 % Version 2.0 (almost identical to 1.5) corresponds to "Volume B" (April 1986).
58 % Version 2.1 corrected anomalies in discretionary breaks (January 1987).
59 % Version 2.2 corrected "(Please type...)" with null \endlinechar (April 1987).
60 % Version 2.3 avoided incomplete page in premature termination (August 1987).
61 % Version 2.4 fixed \noaligned rules in indented displays (August 1987).
62 % Version 2.5 saved cur_order when expanding tokens (September 1987).
63 % Version 2.6 added 10sp slop when shipping leaders (November 1987).
64 % Version 2.7 improved rounding of negative-width characters (November 1987).
65 % Version 2.8 fixed weird bug if no \patterns are used (December 1987).
66 % Version 2.9 made \csname\endcsname's "relax" local (December 1987).
67 % Version 2.91 fixed \outer\def\a0{}\a\a bug (April 1988).
68 % Version 2.92 fixed \patterns, also file names with complex macros (May 1988).
69 % Version 2.93 fixed negative halving in allocator when mem_min<0 (June 1988).
70 % Version 2.94 kept open_log_file from calling fatal_error (November 1988).
71 % Version 2.95 solved that problem a better way (December 1988).
72 % Version 2.96 corrected bug in "Infinite shrinkage" recovery (January 1989).
73 % Version 2.97 corrected blunder in creating 2.95 (February 1989).
74 % Version 2.98 omitted save_for_after at outer level (March 1989).
75 % Version 2.99 caught $$\begingroup\halign..$$ (June 1989).
76 % Version 2.991 caught .5\ifdim.6... (June 1989).
77 % Version 2.992 introduced major changes for 8-bit extensions (September 1989).
78 % Version 2.993 fixed a save_stack synchronization bug et alia (December 1989).
79 % Version 3.0 fixed unusual displays; was more \output robust (March 1990).
80 % Version 3.1 fixed nullfont, disabled \write{\the\prevgraf} (September 1990).
81 % Version 3.14 fixed unprintable font names and corrected typos (March 1991).
82 % Version 3.141 more of same; reconstituted ligatures better (March 1992).
83 % Version 3.1415 preserved nonexplicit kerns, tidied up (February 1993).
84 % Version 3.14159 allowed fontmemsize to change; bulletproofing (March 1995).
85 % Version 3.141592 fixed \xleaders, glueset, weird alignments (December 2002).
86 % Version 3.1415926 was a general cleanup with minor fixes (February 2008).
87 \stoptyping
88
89 Although considerable effort has been expended to make the LuaTeX program correct
90 and reliable, no warranty is implied; the authors disclaim any obligation or
91 liability for damages, including but not limited to special, indirect, or
92 consequential damages arising out of or in connection with the use or performance
93 of this software. This work has been a ``labor of love'' and the authors hope
94 that users enjoy it.
95
96 {\em You will find a lot of comments that originate in original \TEX. We kept them
97 as a side effect of the conversion from \WEB\ to \CWEB. Because there is not much
98 webbing going on here eventually the files became regular \CCODE\ files with still
99 potentially typeset comments. As we add our own comments, and also comments are
100 there from \PDFTEX, \ALEPH\ and \ETEX, we get a curious mix. The best comments are
101 of course from Don Knuth. All bad comments are ours. All errors are ours too!
102
103 Not all comments make sense, because some things are implemented differently, for
104 instance some memory management. But the principles of tokens and nodes stayed.
105 It anyway means that you sometimes need to keep in mind that the explanation is
106 more geared to traditional \TEX. But that's not a bad thing. Sorry Don for any
107 confusion we introduced. The readers should have a copy of the \TEX\ books at hand
108 anyway.}
109
110 A large piece of software like \TeX\ has inherent complexity that cannot be
111 reduced below a certain level of difficulty, although each individual part is
112 fairly simple by itself. The \.{WEB} language is intended to make the algorithms
113 as readable as possible, by reflecting the way the individual program pieces fit
114 together and by providing the cross-references that connect different parts.
115 Detailed comments about what is going on, and about why things were done in
116 certain ways, have been liberally sprinkled throughout the program. These
117 comments explain features of the implementation, but they rarely attempt to
118 explain the \TeX\ language itself, since the reader is supposed to be familiar
119 with {\sl The \TeX book}.
120
121 The present implementation has a long ancestry, beginning in the summer of~1977,
122 when Michael~F. Plass and Frank~M. Liang designed and coded a prototype @^Plass,
123 Michael Frederick@> @^Liang, Franklin Mark@> @^Knuth, Donald Ervin@> based on
124 some specifications that the author had made in May of that year. This original
125 proto\TeX\ included macro definitions and elementary manipulations on boxes and
126 glue, but it did not have line-breaking, page-breaking, mathematical formulas,
127 alignment routines, error recovery, or the present semantic nest; furthermore, it
128 used character lists instead of token lists, so that a control sequence like
129 \.{\\halign} was represented by a list of seven characters. A complete version of
130 \TeX\ was designed and coded by the author in late 1977 and early 1978; that
131 program, like its prototype, was written in the {\mc SAIL} language, for which an
132 excellent debugging system was available. Preliminary plans to convert the {\mc
133 SAIL} code into a form somewhat like the present ``web'' were developed by Luis
134 Trabb~Pardo and @^Trabb Pardo, Luis Isidoro@> the author at the beginning of
135 1979, and a complete implementation was created by Ignacio~A. Zabala in 1979 and
136 1980. The \TeX82 program, which @^Zabala Salelles, Ignacio Andr\'es@> was written
137 by the author during the latter part of 1981 and the early part of 1982, also
138 incorporates ideas from the 1979 implementation of @^Guibas, Leonidas Ioannis@>
139 @^Sedgewick, Robert@> @^Wyatt, Douglas Kirk@> \TeX\ in {\mc MESA} that was
140 written by Leonidas Guibas, Robert Sedgewick, and Douglas Wyatt at the Xerox Palo
141 Alto Research Center. Several hundred refinements were introduced into \TeX82
142 based on the experiences gained with the original implementations, so that
143 essentially every part of the system has been substantially improved. After the
144 appearance of ``Version 0'' in September 1982, this program benefited greatly
145 from the comments of many other people, notably David~R. Fuchs and Howard~W.
146 Trickey. A final revision in September 1989 extended the input character set to
147 eight-bit codes and introduced the ability to hyphenate words from different
148 languages, based on some ideas of Michael~J. Ferguson. @^Fuchs, David Raymond@>
149 @^Trickey, Howard Wellington@> @^Ferguson, Michael John@>
150
151 No doubt there still is plenty of room for improvement, but the author is firmly
152 committed to keeping \TeX82 ``frozen'' from now on; stability and reliability are
153 to be its main virtues.
154 On the other hand, the \.{WEB} description can be extended without changing the
155 core of \TeX82 itself, and the program has been designed so that such extensions
156 are not extremely difficult to make. The |banner| string defined here should be
157 changed whenever \TeX\ undergoes any modifications, so that it will be clear
158 which version of \TeX\ might be the guilty party when a problem arises.
159 @^extensions to \TeX@> @^system dependencies@>
160
161 This program contains code for various features extending \TeX, therefore this
162 program is called `\eTeX' and not `\TeX'; the official name `\TeX' by itself is
163 reserved for software systems that are fully compatible with each other. A
164 special test suite called the ``\.{TRIP} test'' is available for helping to
165 determine whether a particular implementation deserves to be known as `\TeX'
166 [cf.~Stanford Computer Science report CS1027, November 1984].
167
168 A similar test suite called the ``\.{e-TRIP} test'' is available for helping to
169 determine whether a particular implementation deserves to be known as `\eTeX'.
170
171 This is the first of many sections of \TeX\ where global variables are defined.
172
173 */
174
175 /*tex Are we using lua for initializations? */
176
177 boolean luainit;
178
179 /*tex Print file open and close info? */
180
181 boolean tracefilenames;
182
183 /*tex Extra line in tracingmacros? */
184
185 boolean traceextranewline;
186
187
188 /*tex
189
190 This program has two important variations: (1) There is a long and slow version
191 called \.{INITEX}, which does the extra calculations needed to @.INITEX@>
192 initialize \TeX's internal tables; and (2)~there is a shorter and faster
193 production version, which cuts the initialization to a bare minimum.
194
195 */
196
197 /*tex are we \.{INITEX}? */
198
199 boolean ini_version;
200
201 /*tex was the dump name option used? */
202
203 boolean dump_option;
204
205 /*tex was a \.{\%\AM format} line seen? */
206
207 boolean dump_line;
208
209 /*tex temporary for setup */
210
211 int bound_default;
212
213 /*tex temporary for setup */
214
215 char *bound_name;
216
217 /*tex width of context lines on terminal error messages */
218
219 int error_line;
220
221 /*tex
222 width of first lines of contexts in terminal error messages; should be
223 between 30 and |error_line-15|
224 */
225
226 int half_error_line;
227
228 /*tex width of longest text lines output; should be at least 60 */
229
230 int max_print_line;
231
232 /*tex maximum number of strings; must not exceed |max_halfword| */
233
234 int max_strings;
235
236 /*tex strings available after format loaded */
237
238 int strings_free;
239
240 /*tex loop variable for initialization */
241
242 int font_k;
243
244 /*tex
245 putting a character in front of a macro trace (feature suggested by PO on
246 tex implementor list
247 */
248
249 int level_max;
250 int level_chr;
251
252 /*tex
253 maximum number of characters simultaneously present in current lines of open
254 files and in control sequences between \.{\\csname} and \.{\\endcsname}; must
255 not exceed |max_halfword|
256 */
257
258 int buf_size;
259
260 /*tex maximum number of simultaneous input sources */
261
262 int stack_size;
263
264 /*tex
265 maximum number of input files and error insertions that can be going on
266 simultaneously
267 */
268
269 int max_in_open;
270
271 /*tex maximum number of simultaneous macro parameters */
272
273 int param_size;
274
275 /*tex maximum number of semantic levels simultaneously active */
276
277 int nest_size;
278
279 /*tex
280 space for saving values outside of current group; must be at most
281 |max_halfword|
282 */
283
284 int save_size;
285
286 /*tex limits recursive calls of the |expand| procedure */
287
288 int expand_depth;
289
290 /* parse the first line for options is ignored. */
291
292 /*int parsefirstlinep;*/
293
294 /*tex format messages as file:line:error */
295
296 int filelineerrorstylep;
297
298 /*tex stop at first error */
299
300 int haltonerrorp;
301
302 /*tex already trying to halt? */
303
304 boolean haltingonerrorp;
305
306 /*tex current filename is quoted */
307
308 boolean quoted_filename;
309
310 int get_luatexversion(void)
311 {
312 return luatex_version;
313 }
314
315 /*tex the number of pages that have been shipped out */
316
317 int total_pages = 0;
318
319 /*tex abort when DVI exceeds 65535 pages */
320
321 int check_dvi_total_pages = 1;
322
323 /*tex recent outputs that didn't ship anything out */
324
325 int dead_cycles = 0;
326
327 str_number get_luatexrevision(void)
328 {
329 return luatex_revision;
330 }
331
332 /*tex
333
334 This is it: the part of \TeX\ that executes all those procedures we have written.
335
336 We have noted that there are two versions of \TeX82. One, called \.{INITEX},
337 @.INITEX@> has to be run first; it initializes everything from scratch, without
338 reading a format file, and it has the capability of dumping a format file. The
339 other one is called `\.{VIRTEX}'; it is a ``virgin'' program that needs
340 @.VIRTEX@> to input a format file in order to get started.
341
342 For \LUATEX\ it is important to know that we still dump a format. But, in order
343 to gain speed and a smaller footprint, we gzip the format (level 3). We also
344 store some information that makes an abort possible in case of an incompatible
345 engine version, which is important as \LUATEX\ develops. It is possible to store
346 \LUA\ code in the format but not the current upvalues so you still need to
347 initialize. Also, traditional fonts are stored, as are extended fonts but any
348 additional information needed for instance to deal with \OPENTYPE\ fonts is to be
349 handled by \LUA\ code and therefore not present in the format.
350
351 */
352
353 #define const_chk(A) do { \
354 if (A < inf_##A) \
355 A = inf_##A; \
356 if (A > sup_##A) \
357 A = sup_##A; \
358 } while (0)
359
360 #define setup_bound_var(A,B,C) do { \
361 if (luainit>0) { \
362 get_lua_number("texconfig",B,&C); \
363 if (C==0) \
364 C=A; \
365 } else { \
366 integer x; \
367 setupboundvariable(&x, B, A); \
368 C = (int)x; \
369 } \
370 } while (0)
371
372 int ready_already = 0;
373
374 int main_initialize(void)
375 {
376 /*
377 In case somebody has inadvertently made bad settings of the
378 ``constants,'' \LUATEX\ checks them using a variable called |bad|.
379 */
380 int bad = 0;
381 /*tex
382 Bounds that may be set from the configuration file. We want the user to
383 be able to specify the names with underscores, but \.{TANGLE} removes
384 underscores, so we're stuck giving the names twice, once as a string,
385 once as the identifier. How ugly. (We can change that now.)
386 */
387 setup_bound_var(15000, "max_strings", max_strings);
388 setup_bound_var(100, "strings_free", strings_free);
389 setup_bound_var(3000, "buf_size", buf_size);
390 setup_bound_var(50, "nest_size", nest_size);
391 setup_bound_var(15, "max_in_open", max_in_open);
392 setup_bound_var(60, "param_size", param_size);
393 setup_bound_var(4000, "save_size", save_size);
394 setup_bound_var(300, "stack_size", stack_size);
395 setup_bound_var(16384, "dvi_buf_size", dvi_buf_size);
396 setup_bound_var(79, "error_line", error_line);
397 setup_bound_var(50, "half_error_line", half_error_line);
398 setup_bound_var(79, "max_print_line", max_print_line);
399 setup_bound_var(0, "hash_extra", hash_extra);
400 setup_bound_var(72, "pk_dpi", pk_dpi);
401 setup_bound_var(10000, "expand_depth", expand_depth);
402 setup_bound_var(0, "level_max", level_max);
403 setup_bound_var('.', "level_chr", level_chr);
404 /*tex
405 Check other constants against their sup and inf.
406 */
407 const_chk(buf_size);
408 const_chk(nest_size);
409 const_chk(max_in_open);
410 const_chk(param_size);
411 const_chk(save_size);
412 const_chk(stack_size);
413 const_chk(dvi_buf_size);
414 const_chk(max_strings);
415 const_chk(strings_free);
416 const_chk(hash_extra);
417 const_chk(pk_dpi);
418 if (error_line > ssup_error_line) {
419 error_line = ssup_error_line;
420 }
421 /*tex
422 Array memory allocation
423 */
424 buffer = xmallocarray(packed_ASCII_code, (unsigned) buf_size);
425 nest = xmallocarray(list_state_record, (unsigned) nest_size);
426 save_stack = xmallocarray(save_record, (unsigned) save_size);
427 input_stack = xmallocarray(in_state_record, (unsigned) stack_size);
428 input_file = xmallocarray(alpha_file, (unsigned) max_in_open);
429 input_file_callback_id = xmallocarray(int, (unsigned) max_in_open);
430 line_stack = xmallocarray(int, (unsigned) max_in_open);
431 eof_seen = xmallocarray(boolean, (unsigned) max_in_open);
432 grp_stack = xmallocarray(save_pointer, (unsigned) max_in_open);
433 if_stack = xmallocarray(pointer, (unsigned) max_in_open);
434 source_filename_stack = xmallocarray(str_number, (unsigned) max_in_open);
435 full_source_filename_stack = xmallocarray(char *, (unsigned) max_in_open);
436 param_stack = xmallocarray(halfword, (unsigned) param_size);
437 dvi_buf = xmallocarray(eight_bits, (unsigned) dvi_buf_size);
438 /*tex
439 Only in ini mode:
440 */
441 if (ini_version) {
442 fixmem = xmallocarray(smemory_word, fix_mem_init + 1);
443 memset(voidcast(fixmem), 0, (fix_mem_init + 1) * sizeof(smemory_word));
444 fix_mem_min = 0;
445 fix_mem_max = fix_mem_init;
446 eqtb_top = eqtb_size + hash_extra;
447 if (hash_extra == 0)
448 hash_top = undefined_control_sequence;
449 else
450 hash_top = eqtb_top;
451 hash = xmallocarray(two_halves, (unsigned) (hash_top + 1));
452 memset(hash, 0, sizeof(two_halves) * (unsigned) (hash_top + 1));
453 eqtb = xmallocarray(memory_word, (unsigned) (eqtb_top + 1));
454 memset(eqtb, 0, sizeof(memory_word) * (unsigned) (eqtb_top + 1));
455 init_string_pool_array((unsigned) max_strings);
456 reset_cur_string();
457 }
458 /*tex
459 Check the ``constant'' values...
460 */
461 if ((half_error_line < 30) || (half_error_line > error_line - 15))
462 bad = 1;
463 if (max_print_line < 60)
464 bad = 2;
465 if (dvi_buf_size % 8 != 0)
466 bad = 3;
467 if (hash_prime > hash_size)
468 bad = 5;
469 if (max_in_open >= (sup_max_in_open+1)) /* 128 */
470 bad = 6;
471 /*tex
472 Here are the inequalities that the quarterword and halfword values
473 must satisfy (or rather, the inequalities that they mustn't satisfy):
474 */
475 if ((min_quarterword > 0) || (max_quarterword < 0x7FFF))
476 bad = 11;
477 if ((min_halfword > 0) || (max_halfword < 0x3FFFFFFF))
478 bad = 12;
479 if ((min_quarterword < min_halfword) || (max_quarterword > max_halfword))
480 bad = 13;
481 if (font_base < min_quarterword)
482 bad = 15;
483 if ((save_size > max_halfword) || (max_strings > max_halfword))
484 bad = 17;
485 if (buf_size > max_halfword)
486 bad = 18;
487 if (max_quarterword - min_quarterword < 0xFFFF)
488 bad = 19;
489 if (cs_token_flag + eqtb_size + hash_extra > max_halfword)
490 bad = 21;
491 if (bad > 0) {
492 wterm_cr();
493 fprintf(term_out,
494 "Ouch---my internal constants have been clobbered! ---case %d",
495 (int) bad
496 );
497 } else {
498 /*tex Set global variables to their starting values. */
499 initialize();
500 if (ini_version) {
501 /*tex Initialize all the primitives. */
502 no_new_control_sequence = false;
503 first = 0;
504 initialize_commands();
505 initialize_etex_commands();
506 init_str_ptr = str_ptr;
507 no_new_control_sequence = true;
508 fix_date_and_time();
509 }
510 ready_already = 314159;
511 }
512 return bad;
513 }
514
515
516 void main_body(void)
517 {
518 static char pdftex_map[] = "pdftex.map";
519 int bad = main_initialize();
520 /*tex in case we quit during initialization */
521 history = fatal_error_stop;
522 /*tex open the terminal for output */
523 t_open_out();
524 if (!luainit)
525 tracefilenames = true;
526 if (bad > 0) {
527 goto FINAL_END;
528 }
529 print_banner(luatex_version_string);
530 /*tex
531 Get the first line of input and prepare to start When we begin the
532 following code, \TeX's tables may still contain garbage; the strings
533 might not even be present. Thus we must proceed cautiously to get
534 bootstrapped in.
535
536 But when we finish this part of the program, \TeX\ is ready to call on
537 the |main_control| routine to do its work.
538 */
539 /*tex
540 This copies the command line,
541 */
542 initialize_inputstack();
543 if (buffer[iloc] == '*')
544 incr(iloc);
545 if ((format_ident == 0) || (buffer[iloc] == '&') || dump_line) {
546 char *fname = NULL;
547 if (format_ident != 0 && !ini_version) {
548 /*tex Erase preloaded format. */
549 initialize();
550 }
551 if ((fname = open_fmt_file()) == NULL)
552 goto FINAL_END;
553 if (!load_fmt_file(fname)) {
554 zwclose(fmt_file);
555 goto FINAL_END;
556 }
557 zwclose(fmt_file);
558 while ((iloc < ilimit) && (buffer[iloc] == ' '))
559 incr(iloc);
560 }
561 if (output_mode_option != 0)
562 output_mode_par = output_mode_value;
563 if (draft_mode_option != 0) {
564 draft_mode_par = draft_mode_value;
565 }
566 /*tex can this be moved? */
567 pdf_init_map_file((char *) pdftex_map);
568 /* */
569 if (end_line_char_inactive)
570 decr(ilimit);
571 else
572 buffer[ilimit] = (packed_ASCII_code) end_line_char_par;
573 fix_date_and_time();
574 random_seed = (microseconds * 1000) + (epochseconds % 1000000);
575 init_randoms(random_seed);
576 initialize_math();
577 fixup_selector(log_opened_global);
578 check_texconfig_init();
579 if ((iloc < ilimit) && (get_cat_code(cat_code_table_par, buffer[iloc]) != escape_cmd)) {
580 /*tex \.{\\input} assumed */
581 start_input();
582 }
583 /*tex Initialize |text_dir_ptr| */
584 text_dir_ptr = new_dir(0);
585 /*tex Ready to go! */
586 history = spotless;
587 /*tex Initialize synctex primitive */
588 synctexinitcommand();
589 /*tex Come to life. */
590 main_control();
591 flush_node(text_dir_ptr);
592 /*tex Prepare for death. */
593 final_cleanup();
594 close_files_and_terminate();
595 FINAL_END:
596 do_final_end();
597 }
598
599 /*tex
600
601 Here we do whatever is needed to complete \TeX's job gracefully on the local
602 operating system. The code here might come into play after a fatal error; it must
603 therefore consist entirely of ``safe'' operations that cannot produce error
604 messages. For example, it would be a mistake to call |str_room| or |make_string|
605 at this time, because a call on |overflow| might lead to an infinite loop.
606 @^system dependencies@>
607
608 Actually there's one way to get error messages, via |prepare_mag|; but that can't
609 cause infinite recursion. @^recursion@>
610
611 This program doesn't bother to close the input files that may still be open.
612
613 */
614
615 void close_files_and_terminate(void)
616 {
617 int callback_id;
618 callback_id = callback_defined(stop_run_callback);
619 finalize_write_files();
620 if (tracing_stats_par > 0) {
621 if (callback_id == 0) {
622 /*tex
623 Output statistics about this job. The present section goes
624 directly to the log file instead of using |print| commands,
625 because there's no need for these strings to take up
626 |string_pool| memory when a non-{\bf stat} version of \TeX\ is
627 being used.
628 */
629 if (log_opened_global) {
630 fprintf(log_file,
631 "\n\nHere is how much of LuaTeX's memory you used:\n"
632 );
633 fprintf(log_file, " %d string%s out of %d\n",
634 (int) (str_ptr - init_str_ptr),
635 (str_ptr == (init_str_ptr + 1) ? "" : "s"),
636 (int) (max_strings - init_str_ptr + STRING_OFFSET)
637 );
638 fprintf(log_file, " %d,%d words of node,token memory allocated",
639 (int) var_mem_max, (int) fix_mem_max
640 );
641 print_node_mem_stats();
642 fprintf(log_file,
643 " %d multiletter control sequences out of %ld+%d\n",
644 (int) cs_count, (long) hash_size, (int) hash_extra
645 );
646 fprintf(log_file, " %d font%s using %d bytes\n",
647 (int) max_font_id(), (max_font_id() == 1 ? "" : "s"),
648 (int) font_bytes
649 );
650 fprintf(log_file,
651 " %di,%dn,%dp,%db,%ds stack positions out of %di,%dn,%dp,%db,%ds\n",
652 (int) max_in_stack, (int) max_nest_stack,
653 (int) max_param_stack, (int) max_buf_stack,
654 (int) max_save_stack + 6, (int) stack_size,
655 (int) nest_size, (int) param_size, (int) buf_size,
656 (int) save_size
657 );
658 }
659 }
660 }
661 wake_up_terminal();
662 /*tex
663 Rubish, these \PDF arguments, passed, needs to be fixed, e.g. with a
664 dummy in \DVI.
665 */
666 wrapup_backend();
667 /*tex
668 Close {\sl Sync\TeX} file and write status.
669 */
670 synctexterminate(log_opened_global);
671 /*tex
672 The following is needed because synctex removes files and we want to keep
673 them which means renaming a temp file .. we can't bypass the terminate
674 because it might do mem cleanup.
675 */
676 if (synctex_get_mode() > 0) {
677 callback_id = callback_defined(finish_synctex_callback);
678 if (callback_id > 0) {
679 run_callback(callback_id, "->");
680 }
681 }
682 /* free_text_codes(); */
683 /* free_math_codes(); */
684 if (log_opened_global) {
685 wlog_cr();
686 selector = selector - 2;
687 if ((selector == term_only) && (callback_id == 0)) {
688 tprint_nl("Transcript written on ");
689 tprint_file_name(NULL, texmf_log_name, NULL);
690 print_char('.');
691 print_ln();
692 }
693 lua_a_close_out(log_file);
694 log_opened_global = false;
695 }
696 callback_id = callback_defined(wrapup_run_callback);
697 if (callback_id > 0) {
698 run_callback(callback_id, "->");
699 }
700 free_text_codes();
701 free_math_codes();
702 }
703
704 /*tex
705
706 We get to the |final_cleanup| routine when \.{\\end} or \.{\\dump} has been
707 scanned and |its_all_over|.
708
709 */
710
711 void final_cleanup(void)
712 {
713 /*tex This one gets the value 0 for \.{\\end}, 1 for \.{\\dump}. */
714 int c;
715 /*tex Here's one for looping marks: */
716 halfword i;
717 /*tex This was a global temp_ptr: */
718 halfword t;
719 c = cur_chr;
720 if (job_name == 0)
721 open_log_file();
722 while (input_ptr > 0)
723 if (istate == token_list)
724 end_token_list();
725 else
726 end_file_reading();
727 while (open_parens > 0) {
728 report_stop_file(filetype_tex);
729 decr(open_parens);
730 }
731 if (cur_level > level_one) {
732 tprint_nl("(\\end occurred inside a group at level ");
733 print_int(cur_level - level_one);
734 print_char(')');
735 show_save_groups();
736 }
737 while (cond_ptr != null) {
738 tprint_nl("(\\end occurred when ");
739 print_cmd_chr(if_test_cmd, cur_if);
740 if (if_line != 0) {
741 tprint(" on line ");
742 print_int(if_line);
743 }
744 tprint(" was incomplete)");
745 if_line = if_line_field(cond_ptr);
746 cur_if = subtype(cond_ptr);
747 t = cond_ptr;
748 cond_ptr = vlink(cond_ptr);
749 flush_node(t);
750 }
751 if (callback_defined(stop_run_callback) == 0)
752 if (history != spotless)
753 if ((history == warning_issued) || (interaction < error_stop_mode))
754 if (selector == term_and_log) {
755 selector = term_only;
756 tprint_nl("(see the transcript file for additional information)");
757 selector = term_and_log;
758 }
759 if (c == 1) {
760 if (ini_version) {
761 for (i = 0; i <= biggest_used_mark; i++) {
762 delete_top_mark(i);
763 delete_first_mark(i);
764 delete_bot_mark(i);
765 delete_split_first_mark(i);
766 delete_split_bot_mark(i);
767 }
768 for (c = last_box_code; c <= vsplit_code; c++)
769 flush_node_list(disc_ptr[c]);
770 if (last_glue != max_halfword) {
771 flush_node(last_glue);
772 }
773 /*tex Flush the pseudo files. */
774 while (pseudo_files != null) {
775 pseudo_close();
776 }
777 store_fmt_file();
778 return;
779 }
780 tprint_nl("(\\dump is performed only by INITEX)");
781 return;
782 }
783 }
784
785 /*tex
786
787 Once \TeX\ is working, you should be able to diagnose most errors with the
788 \.{\\show} commands and other diagnostic features.
789
790 Because we have made some internal changes the optional debug interface
791 has been removed.
792
793 */