fix getsup (HH)
[luatex.git] / source / texk / web2c / luatexdir / tex / printing.w
blob006392810b92d52ddc6d2a35f4ef8b7cb7eac9aa
1 % printing.w
3 % Copyright 2009-2013 Taco Hoekwater <taco@@luatex.org>
5 % This file is part of LuaTeX.
7 % LuaTeX is free software; you can redistribute it and/or modify it under
8 % the terms of the GNU General Public License as published by the Free
9 % Software Foundation; either version 2 of the License, or (at your
10 % option) any later version.
12 % LuaTeX is distributed in the hope that it will be useful, but WITHOUT
13 % ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 % FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
15 % License for more details.
17 % You should have received a copy of the GNU General Public License along
18 % with LuaTeX; if not, see <http://www.gnu.org/licenses/>.
20 @ @c
21 #include "ptexlib.h"
22 #include "lua/luatex-api.h" /* for luatex_banner */
24 @ @c
25 #define wlog(A) fputc(A,log_file)
26 #define wterm(A) fputc(A,term_out)
28 int new_string_line = 0;
29 int escape_controls = 1;
31 @ Messages that are sent to a user's terminal and to the transcript-log file
32 are produced by several `|print|' procedures. These procedures will
33 direct their output to a variety of places, based on the setting of
34 the global variable |selector|, which has the following possible
35 values:
37 \yskip
38 \hang |term_and_log|, the normal setting, prints on the terminal and on the
39 transcript file.
41 \hang |log_only|, prints only on the transcript file.
43 \hang |term_only|, prints only on the terminal.
45 \hang |no_print|, doesn't print at all. This is used only in rare cases
46 before the transcript file is open.
48 \hang |pseudo|, puts output into a cyclic buffer that is used
49 by the |show_context| routine; when we get to that routine we shall discuss
50 the reasoning behind this curious mode.
52 \hang |new_string|, appends the output to the current string in the
53 string pool.
55 \hang 0 to 15, prints on one of the sixteen files for \.{\\write} output.
57 \yskip
58 \noindent The symbolic names `|term_and_log|', etc., have been assigned
59 numeric codes that satisfy the convenient relations |no_print+1=term_only|,
60 |no_print+2=log_only|, |term_only+2=log_only+1=term_and_log|.
62 Three additional global variables, |tally| and |term_offset| and
63 |file_offset|, record the number of characters that have been printed
64 since they were most recently cleared to zero. We use |tally| to record
65 the length of (possibly very long) stretches of printing; |term_offset|
66 and |file_offset|, on the other hand, keep track of how many characters
67 have appeared so far on the current line that has been output to the
68 terminal or to the transcript file, respectively.
71 alpha_file log_file; /* transcript of \TeX\ session */
72 int selector = term_only; /* where to print a message */
73 int dig[23]; /* digits in a number being output */
74 int tally = 0; /* the number of characters recently printed */
75 int term_offset = 0; /* the number of characters on the current terminal line */
76 int file_offset = 0; /* the number of characters on the current file line */
77 packed_ASCII_code trick_buf[(ssup_error_line + 1)]; /* circular buffer for pseudoprinting */
78 int trick_count; /* threshold for pseudoprinting, explained later */
79 int first_count; /* another variable for pseudoprinting */
80 boolean inhibit_par_tokens = false; /* for minor adjustments to |show_token_list| */
82 @ To end a line of text output, we call |print_ln|
85 void print_ln(void)
87 switch (selector) {
88 case no_print:
89 break;
90 case term_only:
91 wterm_cr();
92 term_offset = 0;
93 break;
94 case log_only:
95 wlog_cr();
96 file_offset = 0;
97 break;
98 case term_and_log:
99 wterm_cr();
100 wlog_cr();
101 term_offset = 0;
102 file_offset = 0;
103 break;
104 case pseudo:
105 break;
106 case new_string:
107 if (new_string_line > 0)
108 print_char(new_string_line);
109 break;
110 default:
111 fprintf(write_file[selector], "\n");
112 break;
114 /* |tally| is not affected */
117 @ The |print_char| procedure sends one byte to the desired destination.
118 All printing comes through |print_ln| or |print_char|, except for the
119 case of |tprint| (see below).
121 The checking of the line length is an inheritance from previosu engines
122 and we might drop it after release 1.0. We're not too picky about the exact
123 match of that length because we have utf output so length is then a bit
124 fuzzy anyway.
127 #define needs_escaping(A) \
128 ((! escape_controls) || (A>=0x20) || (A==0x0A) || (A==0x0D) || (A==0x09))
130 #define escaped_char(A) \
131 A+64
133 #define wterm_char(A) \
134 if (needs_escaping(A)) { \
135 wterm(A); \
136 } else { \
137 if (term_offset+2>=max_print_line) { \
138 wterm_cr(); \
139 term_offset=0; \
141 wterm('^'); \
142 wterm('^'); \
143 wterm(escaped_char(A)); \
144 term_offset += 2; \
149 #define needs_wrapping(A,B) \
150 (((A>=0xF0)&&(B+4>=max_print_line)) || \
151 ((A>=0xE0)&&(B+3>=max_print_line)) || \
152 ((A>=0xC0)&&(B+2>=max_print_line)))
154 we have mostly ascii in logs, so ...
158 #define needs_wrapping(A,B) \
159 ( (A>=0xC0) && \
160 (((A>=0xF0) && (B+4>=max_print_line)) || \
161 ((A>=0xE0) && (B+3>=max_print_line)) || \
162 ( (B+2>=max_print_line))) \
165 #define fix_term_offset(A) \
166 if (needs_wrapping(A,term_offset)){ \
167 wterm_cr(); \
168 term_offset=0; \
171 #define fix_log_offset(A) \
172 if (needs_wrapping(A,file_offset)){ \
173 wlog_cr(); \
174 file_offset=0; \
177 void print_char(int s)
179 if (s < 0 || s > 255) {
180 formatted_warning("print","weird character %i",s);
181 return;
183 if (s == new_line_char_par) {
184 if (selector < pseudo) {
185 print_ln();
186 return;
189 switch (selector) {
190 case no_print:
191 break;
192 case term_only:
193 fix_term_offset(s);
194 wterm_char(s);
195 incr(term_offset);
196 if (term_offset == max_print_line) {
197 wterm_cr();
198 term_offset = 0;
200 break;
201 case log_only:
202 fix_log_offset(s);
203 wlog(s);
204 incr(file_offset);
205 if (file_offset == max_print_line) {
206 wlog_cr();
207 file_offset = 0;
209 break;
210 case term_and_log:
211 fix_term_offset(s);
212 fix_log_offset(s);
213 wterm_char(s);
214 wlog(s);
215 incr(term_offset);
216 incr(file_offset);
217 if (term_offset == max_print_line) {
218 wterm_cr();
219 term_offset = 0;
221 if (file_offset == max_print_line) {
222 wlog_cr();
223 file_offset = 0;
225 break;
226 case pseudo:
227 if (tally < trick_count)
228 trick_buf[tally % error_line] = (packed_ASCII_code) s;
229 break;
230 case new_string:
231 append_char(s);
232 break;
233 default:
234 fprintf(write_file[selector], "%c", s);
236 incr(tally);
239 @ An entire string is output by calling |print|. Note that if we are outputting
240 the single standard ASCII character \.c, we could call |print("c")|, since
241 |"c"=99| is the number of a single-character string, as explained above. But
242 |print_char("c")| is quicker, so \TeX\ goes directly to the |print_char|
243 routine when it knows that this is safe. (The present implementation
244 assumes that it is always safe to print a visible ASCII character.)
246 @^system dependencies@>
248 The first 256 entries above the 17th unicode plane are used for a
249 special trick: when \TeX\ has to print items in that range, it will
250 instead print the character that results from substracting 0x110000
251 from that value. This allows byte-oriented output to things like
252 \.{\\specials} and \.{\\pdfextension literals}. Todo: Perhaps it would be useful
253 to do the same substraction while typesetting.
256 void print(int s)
258 if (s >= str_ptr) {
259 normal_warning("print","bad string pointer");
260 return;
261 } else if (s < STRING_OFFSET) {
262 if (s < 0) {
263 normal_warning("print","bad string offset");
264 } else {
265 /* TH not sure about this, disabled for now! */
266 if ((false) && (selector > pseudo)) {
267 /* internal strings are not expanded */
268 print_char(s);
269 return;
271 if (s == new_line_char_par) {
272 if (selector < pseudo) {
273 print_ln();
274 return;
277 if (s <= 0x7F) {
278 print_char(s);
279 } else if (s <= 0x7FF) {
280 print_char(0xC0 + (s / 0x40));
281 print_char(0x80 + (s % 0x40));
282 } else if (s <= 0xFFFF) {
283 print_char(0xE0 + (s / 0x1000));
284 print_char(0x80 + ((s % 0x1000) / 0x40));
285 print_char(0x80 + ((s % 0x1000) % 0x40));
286 } else if (s >= 0x110000) {
287 int c = s - 0x110000;
288 if (c >= 256) {
289 formatted_warning("print", "bad raw byte to print (c=%d), skipped",c);
290 } else {
291 print_char(c);
293 } else {
294 print_char(0xF0 + (s / 0x40000));
295 print_char(0x80 + ((s % 0x40000) / 0x1000));
296 print_char(0x80 + (((s % 0x40000) % 0x1000) / 0x40));
297 print_char(0x80 + (((s % 0x40000) % 0x1000) % 0x40));
300 return;
302 if (selector == new_string) {
303 append_string(str_string(s), (unsigned) str_length(s));
304 return;
306 lprint(&str_lstring(s));
309 void lprint (lstring *ss) {
310 unsigned char *j, *l; /* current character code position */
311 j = ss->s;
312 l = j + ss->l;
313 while (j < l) {
314 /* 0x110000 in utf=8: 0xF4 0x90 0x80 0x80 */
315 /* I don't bother checking the last two bytes explicitly */
316 if ((j < l - 4) && (*j == 0xF4) && (*(j + 1) == 0x90)) {
317 int c = (*(j + 2) - 128) * 64 + (*(j + 3) - 128);
318 assert(c >= 0 && c < 256);
319 print_char(c);
320 j = j + 4;
321 } else {
322 print_char(*j);
323 incr(j);
328 @ The procedure |print_nl| is like |print|, but it makes sure that the
329 string appears at the beginning of a new line.
332 void print_nlp(void)
333 { /* move to beginning of a line */
334 if (new_string_line > 0) {
335 print_char(new_string_line);
336 } else if (((term_offset > 0) && (odd(selector))) ||
337 ((file_offset > 0) && (selector >= log_only))) {
338 print_ln();
342 void print_nl(str_number s)
343 { /* prints string |s| at beginning of line */
344 print_nlp();
345 print(s);
348 @ |char *| versions of the same procedures. |tprint| is
349 different because it uses buffering, which works well because
350 most of the output actually comes through |tprint|.
353 #define t_flush_buffer(target,offset) \
354 buffer[i++] = '\n'; \
355 buffer[i++] = '\0';\
356 fputs(buffer, target); \
357 i = 0; \
358 buffer[0] = '\0'; \
359 offset=0;
361 void tprint(const char *sss)
363 char *buffer = NULL;
364 int i = 0; /* buffer index */
365 int newlinechar = new_line_char_par;
366 int dolog = 0;
367 int doterm = 0;
368 switch (selector) {
369 case no_print:
370 return;
371 break;
372 case term_only:
373 doterm = 1;
374 break;
375 case log_only:
376 dolog = 1;
377 break;
378 case term_and_log:
379 dolog = 1;
380 doterm = 1;
381 break;
382 case pseudo:
383 while (*sss) {
384 if (tally < trick_count) {
385 trick_buf[tally % error_line] = (packed_ASCII_code) *sss++;
386 tally++;
387 } else {
388 return;
391 return;
392 break;
393 case new_string:
394 append_string((const unsigned char *)sss, (unsigned) strlen(sss));
395 return;
396 break;
397 default:
399 char *newstr = xstrdup(sss);
400 char *s;
401 for (s=newstr;*s;s++) {
402 if (*s == newlinechar) {
403 *s = '\n';
406 fputs(newstr, write_file[selector]);
407 free(newstr);
408 return;
410 break;
412 /* what is left is the 3 term/log settings */
413 if (dolog || doterm) {
414 buffer = xmalloc(strlen(sss)*3);
415 if (dolog) {
416 const unsigned char *ss = (const unsigned char *) sss;
417 while (*ss) {
418 int s = *ss++;
419 if (needs_wrapping(s,file_offset) || s == newlinechar) {
420 t_flush_buffer(log_file,file_offset);
422 if (s != newlinechar) {
423 buffer[i++] = s;
424 if (file_offset++ == max_print_line) {
425 t_flush_buffer(log_file,file_offset);
429 if (*buffer) {
430 buffer[i++] = '\0';
431 fputs(buffer, log_file);
432 buffer[0] = '\0';
434 i = 0;
436 if (doterm) {
437 const unsigned char *ss = (const unsigned char *) sss;
438 while (*ss) {
439 int s = *ss++;
440 if (needs_wrapping(s,term_offset) || s == newlinechar) {
441 t_flush_buffer(term_out,term_offset);
443 if (s != newlinechar) {
444 if (needs_escaping(s)) {
445 buffer[i++] = s;
446 } else {
447 buffer[i++] = '^';
448 buffer[i++] = '^';
449 buffer[i++] = escaped_char(s);
450 term_offset += 2;
452 if (++term_offset == max_print_line) {
453 t_flush_buffer(term_out,term_offset);
457 if (*buffer) {
458 buffer[i++] = '\0';
459 fputs(buffer, term_out);
462 free(buffer);
466 void tprint_nl(const char *s)
468 print_nlp();
469 tprint(s);
472 @ Here is the very first thing that \TeX\ prints: a headline that identifies
473 the version number and format package. The |term_offset| variable is temporarily
474 incorrect, but the discrepancy is not serious since we assume that the banner
475 and format identifier together will occupy at most |max_print_line|
476 character positions.
479 void print_banner(const char *v)
481 int callback_id = callback_defined(start_run_callback);
482 if (callback_id == 0) {
483 fprintf(term_out, "This is " MyName ", Version %s%s ", v, WEB2CVERSION);
484 if (format_ident > 0)
485 print(format_ident);
486 print_ln();
487 if (show_luahashchars){
488 wterm(' ');
489 fprintf(term_out,"Number of bits used by the hash function (" my_name "): %d",LUAI_HASHLIMIT);
490 print_ln();
492 if (shellenabledp) {
493 wterm(' ');
494 if (restrictedshell)
495 fprintf(term_out, "restricted ");
496 fprintf(term_out, "system commands enabled.\n");
498 } else if (callback_id > 0) {
499 run_callback(callback_id, "->");
503 @ @c
504 void log_banner(const char *v)
506 const char *months[] = { " ",
507 "JAN", "FEB", "MAR", "APR", "MAY", "JUN",
508 "JUL", "AUG", "SEP", "OCT", "NOV", "DEC"
510 unsigned month = (unsigned) month_par;
511 if (month > 12)
512 month = 0;
513 fprintf(log_file, "This is " MyName ", Version %s%s ", v, WEB2CVERSION);
514 print(format_ident);
515 print_char(' ');
516 print_char(' ');
517 print_int(day_par);
518 print_char(' ');
519 fprintf(log_file, "%s", months[month]);
520 print_char(' ');
521 print_int(year_par);
522 print_char(' ');
523 print_two(time_par / 60);
524 print_char(':');
525 print_two(time_par % 60);
526 if (shellenabledp) {
527 wlog_cr();
528 wlog(' ');
529 if (restrictedshell)
530 fprintf(log_file, "restricted ");
531 fprintf(log_file, "system commands enabled.");
533 if (filelineerrorstylep) {
534 wlog_cr();
535 fprintf(log_file, " file:line:error style messages enabled.");
539 @ @c
540 void print_version_banner(void)
542 fprintf(term_out, "%s", luatex_banner);
545 @ The procedure |print_esc| prints a string that is preceded by
546 the user's escape character (which is usually a backslash).
549 void print_esc(str_number s)
551 int c = escape_char_par; /* Set variable |c| to the current escape character */
552 if (c >= 0 && c < STRING_OFFSET)
553 print(c);
554 print(s);
557 @ This prints escape character, then |s|.
560 void tprint_esc(const char *s)
562 int c = escape_char_par; /* Set variable |c| to the current escape character */
563 if (c >= 0 && c < STRING_OFFSET)
564 print(c);
565 tprint(s);
568 @ An array of digits in the range |0..15| is printed by |print_the_digs|.
571 void print_the_digs(eight_bits k)
573 /* prints |dig[k-1]|$\,\ldots\,$|dig[0]| */
574 while (k-- > 0) {
575 if (dig[k] < 10)
576 print_char('0' + dig[k]);
577 else
578 print_char('A' - 10 + dig[k]);
582 @ The following procedure, which prints out the decimal representation of a
583 given integer |n|, has been written carefully so that it works properly
584 if |n=0| or if |(-n)| would cause overflow. It does not apply |mod| or |div|
585 to negative arguments, since such operations are not implemented consistently
586 by all PASCAL compilers.
589 void print_int(longinteger n)
591 int k = 0; /* index to current digit; we assume that $|n|<10^{23}$ */
592 longinteger m; /* used to negate |n| in possibly dangerous cases */
593 if (n < 0) {
594 print_char('-');
595 if (n > -100000000) {
596 n = -n;
597 } else {
598 m = -1 - n;
599 n = m / 10;
600 m = (m % 10) + 1;
601 k = 1;
602 if (m < 10)
603 dig[0] = (int) m;
604 else {
605 dig[0] = 0;
606 incr(n);
610 do {
611 dig[k] = (int) (n % 10);
612 n = n / 10;
613 incr(k);
614 } while (n != 0);
615 print_the_digs((eight_bits) k);
619 @ Here is a trivial procedure to print two digits; it is usually called with
620 a parameter in the range |0<=n<=99|.
623 void print_two(int n)
625 n = abs(n) % 100;
626 print_char('0' + (n / 10));
627 print_char('0' + (n % 10));
630 @ Hexadecimal printing of nonnegative integers is accomplished by |print_hex|.
633 void print_hex(int n)
635 int k = 0 ; /* index to current digit; we assume that $0\L n<16^{22}$ */
636 print_char('"');
637 do {
638 dig[k] = n % 16;
639 n = n / 16;
640 incr(k);
641 } while (n != 0);
642 print_the_digs((eight_bits) k);
645 @ Roman numerals are produced by the |print_roman_int| routine. Readers
646 who like puzzles might enjoy trying to figure out how this tricky code
647 works; therefore no explanation will be given. Notice that 1990 yields
648 \.{mcmxc}, not \.{mxm}.
651 void print_roman_int(int n)
653 char *j, *k; /* mysterious indices */
654 int u, v; /* mysterious numbers */
655 char mystery[] = "m2d5c2l5x2v5i";
656 j = (char *) mystery;
657 v = 1000;
658 while (1) {
659 while (n >= v) {
660 print_char(*j);
661 n = n - v;
663 if (n <= 0) {
664 /* nonpositive input produces no output */
665 return;
667 k = j + 2;
668 u = v / (*(k - 1) - '0');
669 if (*(k - 1) == '2') {
670 k = k + 2;
671 u = u / (*(k - 1) - '0');
673 if (n + u >= v) {
674 print_char(*k);
675 n = n + u;
676 } else {
677 j = j + 2;
678 v = v / (*(j - 1) - '0');
683 @ The |print| subroutine will not print a string that is still being
684 created. The following procedure will.
687 void print_current_string(void)
689 unsigned j = 0; /* points to current character code */
690 while (j < cur_length)
691 print_char(cur_string[j++]);
694 @ The procedure |print_cs| prints the name of a control sequence, given
695 a pointer to its address in |eqtb|. A space is printed after the name
696 unless it is a single nonletter or an active character. This procedure
697 might be invoked with invalid data, so it is ``extra robust.'' The
698 individual characters must be printed one at a time using |print|, since
699 they may be unprintable.
702 void print_cs(int p)
704 str_number t = cs_text(p);
705 if (p < hash_base) {
706 /* nullcs */
707 if (p == null_cs) {
708 tprint_esc("csname");
709 tprint_esc("endcsname");
710 print_char(' ');
711 } else {
712 tprint_esc("IMPOSSIBLE.");
714 } else if ((p >= undefined_control_sequence) &&
715 ((p <= eqtb_size) || p > eqtb_size + hash_extra)) {
716 tprint_esc("IMPOSSIBLE.");
717 } else if (t >= str_ptr) {
718 tprint_esc("NONEXISTENT.");
719 } else {
720 if (is_active_cs(t)) {
721 print(active_cs_value(t));
722 } else {
723 print_esc(t);
724 if (single_letter(t)) {
725 if (get_cat_code(cat_code_table_par, pool_to_unichar(str_string(t))) == letter_cmd)
726 print_char(' ');
727 } else {
728 print_char(' ');
734 @ Here is a similar procedure; it avoids the error checks, and it never
735 prints a space after the control sequence.
738 void sprint_cs(pointer p)
740 str_number t;
741 if (p == null_cs) {
742 tprint_esc("csname");
743 tprint_esc("endcsname");
744 } else {
745 t = cs_text(p);
746 if (is_active_cs(t))
747 print(active_cs_value(t));
748 else
749 print_esc(t);
753 void sprint_cs_name(pointer p)
755 str_number t;
756 if (p != null_cs) {
757 t = cs_text(p);
758 if (is_active_cs(t))
759 print(active_cs_value(t));
760 else
761 print(t);
765 @ This procedure is never called when |interaction<scroll_mode|.
768 void prompt_input(const char *s)
770 wake_up_terminal();
771 tprint(s);
772 term_input();
775 @ Then there is a subroutine that prints glue stretch and shrink, possibly
776 followed by the name of finite units:
779 void print_glue(scaled d, int order, const char *s)
781 print_scaled(d);
782 if ((order < normal) || (order > filll)) {
783 tprint("foul");
784 } else if (order > normal) {
785 tprint("fi");
786 while (order > sfi) {
787 print_char('l');
788 decr(order);
790 } else if (s != NULL) {
791 tprint(s);
795 @ The next subroutine prints a whole glue specification
798 void print_spec(int p, const char *s)
800 if (p < 0) {
801 print_char('*');
802 } else {
803 print_scaled(width(p));
804 if (s != NULL)
805 tprint(s);
806 if (stretch(p) != 0) {
807 tprint(" plus ");
808 print_glue(stretch(p), stretch_order(p), s);
810 if (shrink(p) != 0) {
811 tprint(" minus ");
812 print_glue(shrink(p), shrink_order(p), s);
817 @ We can reinforce our knowledge of the data structures just introduced
818 by considering two procedures that display a list in symbolic form.
819 The first of these, called |short_display|, is used in ``overfull box''
820 messages to give the top-level description of a list. The other one,
821 called |show_node_list|, prints a detailed description of exactly what
822 is in the data structure.
824 The philosophy of |short_display| is to ignore the fine points about exactly
825 what is inside boxes, except that ligatures and discretionary breaks are
826 expanded. As a result, |short_display| is a recursive procedure, but the
827 recursion is never more than one level deep.
828 @^recursion@>
830 A global variable |font_in_short_display| keeps track of the font code that
831 is assumed to be present when |short_display| begins; deviations from this
832 font will be printed.
835 int font_in_short_display; /* an internal font number */
837 @ Boxes, rules, inserts, whatsits, marks, and things in general that are
838 sort of ``complicated'' are indicated only by printing `\.{[]}'.
841 void print_font_identifier(internal_font_number f)
843 str_number fonttext;
844 fonttext = font_id_text(f);
845 if (fonttext > 0) {
846 print_esc(fonttext);
847 } else {
848 tprint_esc("FONT");
849 print_int(f);
851 if (tracing_fonts_par > 0) {
852 tprint(" (");
853 print_font_name(f);
854 if (font_size(f) != font_dsize(f)) {
855 tprint("@@");
856 print_scaled(font_size(f));
857 tprint("pt");
859 print_char(')');
863 @ This prints highlights of list |p|.
866 void short_display(int p)
868 while (p != null) {
869 if (is_char_node(p)) {
870 if (lig_ptr(p) != null) {
871 short_display(lig_ptr(p));
872 } else {
873 if (font(p) != font_in_short_display) {
874 if (!is_valid_font(font(p)))
875 print_char('*');
876 else
877 print_font_identifier(font(p));
878 print_char(' ');
879 font_in_short_display = font(p);
881 print(character(p));
883 } else {
884 /* Print a short indication of the contents of node |p| */
885 print_short_node_contents(p);
887 p = vlink(p);
891 @ The |show_node_list| routine requires some auxiliary subroutines: one to
892 print a font-and-character combination, one to print a token list without
893 its reference count, and one to print a rule dimension.
895 @ This prints |char_node| data.
898 void print_font_and_char(int p)
900 if (!is_valid_font(font(p)))
901 print_char('*');
902 else
903 print_font_identifier(font(p));
904 print_char(' ');
905 print(character(p));
908 @ This prints token list data in braces
911 void print_mark(int p)
913 print_char('{');
914 if ((p < (int) fix_mem_min) || (p > (int) fix_mem_end))
915 tprint_esc("CLOBBERED.");
916 else
917 show_token_list(token_link(p), null, max_print_line - 10);
918 print_char('}');
921 @ This prints dimensions of a rule node.
924 void print_rule_dimen(scaled d)
926 if (is_running(d))
927 print_char('*');
928 else
929 print_scaled(d);
932 @ Since boxes can be inside of boxes, |show_node_list| is inherently recursive,
933 @^recursion@>
934 up to a given maximum number of levels. The history of nesting is indicated
935 by the current string, which will be printed at the beginning of each line;
936 the length of this string, namely |cur_length|, is the depth of nesting.
938 A global variable called |depth_threshold| is used to record the maximum
939 depth of nesting for which |show_node_list| will show information. If we
940 have |depth_threshold=0|, for example, only the top level information will
941 be given and no sublists will be traversed. Another global variable, called
942 |breadth_max|, tells the maximum number of items to show at each level;
943 |breadth_max| had better be positive, or you won't see anything.
946 int depth_threshold; /* maximum nesting depth in box displays */
947 int breadth_max; /* maximum number of items shown at the same list level */
949 @ The recursive machinery is started by calling |show_box|. Assign the values
950 |depth_threshold:=show_box_depth| and |breadth_max:=show_box_breadth|
953 void show_box(halfword p)
955 depth_threshold = show_box_depth_par;
956 breadth_max = show_box_breadth_par;
957 if (breadth_max <= 0)
958 breadth_max = 5;
959 /* the show starts at |p| */
960 show_node_list(p);
961 print_ln();
964 @ Helper for debugging purposes. It prints highlights of list |p|
967 void short_display_n(int p, int m)
969 int i = 0;
970 font_in_short_display = null_font;
971 if (p == null)
972 return;
973 while (p != null) {
974 if (is_char_node(p)) {
975 if (p <= max_halfword) {
976 if (font(p) != font_in_short_display) {
977 if (!is_valid_font(font(p)))
978 print_char('*');
979 else
980 print_font_identifier(font(p));
981 print_char(' ');
982 font_in_short_display = font(p);
984 print(character(p));
986 } else {
987 if ( (type(p) == glue_node) ||
988 (type(p) == disc_node) ||
989 (type(p) == penalty_node) ||
990 ((type(p) == kern_node) && (subtype(p) == explicit_kern ||
991 subtype(p) == italic_kern ))) {
992 incr(i);
994 if (i >= m)
995 return;
996 if (type(p) == disc_node) {
997 print_char('|');
998 short_display(vlink(pre_break(p)));
999 print_char('|');
1000 short_display(vlink(post_break(p)));
1001 print_char('|');
1002 } else {
1003 /* Print a short indication of the contents of node |p| */
1004 print_short_node_contents(p);
1007 p = vlink(p);
1008 if (p == null)
1009 return;
1011 update_terminal();
1014 @ When debugging a macro package, it can be useful to see the exact
1015 control sequence names in the format file. For example, if ten new
1016 csnames appear, it's nice to know what they are, to help pinpoint where
1017 they came from. (This isn't a truly ``basic'' printing procedure, but
1018 that's a convenient module in which to put it.)
1021 void print_csnames(int hstart, int hfinish)
1023 int h;
1024 unsigned char *c, *l;
1025 fprintf(stderr, "fmtdebug:csnames from %d to %d:", (int) hstart, (int) hfinish);
1026 for (h = hstart; h <= hfinish; h++) {
1027 if (cs_text(h) > 0) {
1028 /* we have anything at this position */
1029 c = str_string(cs_text(h));
1030 l = c + str_length(cs_text(h));
1031 while (c < l) {
1032 /* print the characters */
1033 fputc(*c++, stderr);
1035 fprintf(stderr, "|");
1040 @ A helper for printing file:line:error style messages. Look for a
1041 filename in |full_source_filename_stack|, and if we fail to find
1042 one fall back on the non-file:line:error style.
1045 void print_file_line(void)
1047 int level = in_open;
1048 while ((level > 0) && (full_source_filename_stack[level] == 0))
1049 decr(level);
1050 if (level == 0) {
1051 tprint_nl("! ");
1052 } else {
1053 tprint_nl("");
1054 tprint(full_source_filename_stack[level]);
1055 print_char(':');
1056 if (level == in_open)
1057 print_int(line);
1058 else
1059 print_int(line_stack[level + 1]);
1060 tprint(": ");
1064 @ \TeX\ is occasionally supposed to print diagnostic information that
1065 goes only into the transcript file, unless |tracing_online| is positive.
1066 Here are two routines that adjust the destination of print commands:
1069 void begin_diagnostic(void)
1071 global_old_setting = selector;
1072 if ((tracing_online_par <= 0) && (selector == term_and_log)) {
1073 decr(selector);
1074 if (history == spotless)
1075 history = warning_issued;
1079 @ Restore proper conditions after tracing.
1082 void end_diagnostic(boolean blank_line)
1084 tprint_nl("");
1085 if (blank_line)
1086 print_ln();
1087 selector = global_old_setting;
1090 @ Of course we had better declare another global variable, if the previous
1091 routines are going to work.
1094 int global_old_setting;