1 /* Copyright 2014 Clerk Ma
3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the GNU General Public License as published by
5 the Free Software Foundation; either version 2 of the License, or
6 (at your option) any later version.
8 This program is distributed in the hope that it will be useful, but
9 WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 General Public License for more details.
13 You should have received a copy of the GNU General Public License
14 along with this program; if not, write to the Free Software
15 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
22 /* *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** */
27 movement(cur_h - dvi_h, right1);
35 movement(cur_v - dvi_v, down1);
39 void set_cur_lang(void)
43 else if (language > 255)
48 INLINE void free_avail_(halfword p)
56 INLINE void dvi_out_(ASCII_code op)
58 dvi_buf[dvi_ptr] = op;
61 if (dvi_ptr == dvi_limit)
64 INLINE void succumb (void)
66 if (interaction == error_stop_mode)
67 interaction = scroll_mode;
82 INLINE void flush_string (void)
85 pool_ptr = str_start[str_ptr];
87 INLINE void append_char (ASCII_code c)
89 str_pool[pool_ptr] = c;
92 INLINE void append_lc_hex (ASCII_code c)
97 append_char(c - 10 + 'a');
99 INLINE void print_err (const char * s)
101 if (interaction == error_stop_mode);
105 INLINE void tex_help (unsigned int n, ...)
114 va_start(help_arg, n);
116 for (i = n - 1; i > -1; --i)
117 help_line[i] = va_arg(help_arg, char *);
121 INLINE void str_room_ (int val)
123 #ifdef ALLOCATESTRING
124 if (pool_ptr + val > current_pool_size)
125 str_pool = realloc_str_pool(increment_pool_size);
127 if (pool_ptr + val > current_pool_size)
129 overflow("pool size", current_pool_size - init_pool_ptr);
132 if (pool_ptr + val > pool_size)
134 overflow("pool size", pool_size - init_pool_ptr);
138 INLINE void tail_append_ (pointer val)
143 /* *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** */
145 /* *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** */
154 (void) putc ('\n', log_file);
159 (void) putc ('\n', log_file);
174 (void) putc ('\n', write_file[selector]);
179 void print_char_ (ASCII_code s)
181 if (s == new_line_char)
183 if (selector < pseudo)
193 (void) show_char(Xchr(s));
195 (void) putc(Xchr(s), log_file);
198 if (term_offset == max_print_line)
204 if (file_offset == max_print_line)
206 (void) putc ('\n', log_file);
213 (void) putc(Xchr(s), log_file);
216 if (file_offset == max_print_line)
222 (void) show_char(Xchr(s));
225 if (term_offset == max_print_line)
234 if (tally < trick_count)
235 trick_buf[tally % error_line] = s;
240 #ifdef ALLOCATESTRING
241 if (pool_ptr + 1 > current_pool_size)
243 str_pool = realloc_str_pool (increment_pool_size);
246 if (pool_ptr < current_pool_size)
248 str_pool[pool_ptr]= s;
252 if (pool_ptr < pool_size)
254 str_pool[pool_ptr]= s;
261 (void) putc(Xchr(s), write_file[selector]);
268 void print_ (integer s)
283 if (selector > pseudo)
289 if ((s == new_line_char))
290 if (selector < pseudo)
298 /* translate ansi to dos 850 */
299 if (!show_in_hex && s < 256 && s >= 32)
301 if (show_in_dos && s > 127)
303 if (wintodos[s - 128] > 0)
305 print_char (wintodos[s - 128]);
311 while (j < str_start[s + 1])
313 print_char(str_pool[j]);
320 print_char(s); /* don't translate to hex */
324 { /* not just a character */
327 while (j < str_start[s + 1])
329 print_char(str_pool[j]);
333 new_line_char = nl; /* restore eol */
338 /* we get here with s > 256 - i.e. not a single character */
341 while (j < str_start[s + 1])
343 print_char(str_pool[j]);
347 /* string version print. */
348 void print_string_ (unsigned char *s)
354 // print string number s from string pool by calling print_
355 void slow_print_ (integer s)
359 if ((s >= str_ptr) || (s < 256))
367 while (j < str_start[s + 1])
375 // print newline followed by string number s (unless at start of line)
376 void print_nl_ (const char * s)
378 if (((term_offset > 0) && (odd(selector))) ||
379 ((file_offset > 0) && (selector >= log_only)))
385 // print string number s preceded by escape character
386 void print_esc_ (const char * s)
399 void print_the_digs_ (eight_bits k)
406 print_char('0' + dig[k]);
408 print_char('A' + dig[k]);
412 void print_int_ (integer n)
444 dig[k] = (char) (n % 10);
453 void print_cs_ (integer p)
456 if (p >= single_base)
460 print_esc("endcsname");
465 print_esc(""); print(p - single_base);
467 if (cat_code(p - single_base) == letter)
470 else if (p < active_base)
471 print_esc("IMPOSSIBLE.");
472 else print(p - active_base);
473 else if (p >= undefined_control_sequence)
474 print_esc("IMPOSSIBLE.");
475 else if ((text(p) >= str_ptr))
476 print_esc("NONEXISTENT.");
479 print_esc(""); print(text(p));
484 void sprint_cs_(halfword p)
488 print(p - active_base);
489 else if (p < null_cs)
491 print_esc(""); print(p - single_base);
496 print_esc("endcsname");
500 print_esc(""); print(text(p));
504 void print_file_name_(integer n, integer a, integer e)
511 void print_size_ (integer s)
514 print_esc("textfont");
516 print_esc("scriptfont");
518 print_esc("scriptscriptfont");
521 void print_write_whatsit_(str_number s, halfword p)
523 print_esc(""); print(s);
524 if (write_stream(p) < 16)
525 print_int(write_stream(p));
526 else if (write_stream(p) == 16)
528 else print_char('-');
533 close_files_and_terminate();
545 show_line("EXITING at JUMPOUT\n", 0);
547 if ((history != 0) && (history != 1))
556 // deal with error by asking for user response 0-9, D, E, H, I, X, Q, R, S
557 // NOTE: this may JUMPOUT either via X, or because of too many errors
561 integer s1, s2, s3, s4;
563 if (history < error_message_issued)
564 history = error_message_issued;
569 if (interaction == error_stop_mode)
573 clear_for_error_prompt();
577 term_input("? ", help_ptr);
583 c = buffer[first]; // analyze first letter typed
585 if (c >= 'a') // uppercase letter first
586 c = (unsigned char) (c + 'A' - 'a');
600 if (deletions_allowed)
606 align_state = 1000000L;
607 OK_to_interrupt = false;
609 if ((last > first + 1) && (buffer[first + 1] >= '0') && (buffer[first + 1] <= '9'))
610 c = (unsigned char) (c * 10 + buffer[first + 1] - '0' * 11);
612 c = (unsigned char) (c - 48);
624 OK_to_interrupt = true;
625 help2("I have just deleted some text, as you asked.",
626 "You can now delete more, or insert, or whatever.");
628 goto lab22; /* loop again */
636 goto lab22; /* loop again */
643 edit_name_start = str_start[input_stack[base_ptr].name_field];
644 edit_name_length = length(input_stack[base_ptr].name_field);
655 use_err_help = false;
660 help2("Sorry, I don't know how to help in this situation.",
661 "Maybe you should try asking a human?");
664 print_string(help_line[help_ptr]);
666 } while (!(help_ptr == 0));
669 help4("Sorry, I already gave what help I could...",
670 "Maybe you should try asking a human?",
671 "An error might have occurred before I noticed any problems.",
672 "``If all else fails, read the instructions.''");
673 goto lab22; /* loop again */
679 begin_file_reading();
681 if (last > first + 1)
683 cur_input.loc_field = first + 1;
689 print_string("insert>");
690 term_input("insert>", 0);
692 cur_input.loc_field = first;
695 cur_input.limit_field = last - 1;
705 interaction = 0 + c - 81; /* Q = 0, R = 1, S = 2, T = 3 */
706 print_string("OK, entering ");
711 print_esc("batchmode");
715 print_esc("nonstopmode");
718 print_esc("scrollmode");
740 } /* end of switch analysing response character */
743 print_string("Type <return> to proceed, S to scroll future error messages,");
744 print_nl("R to run without stopping, Q to run quietly,");
745 print_nl("I to insert something, ");
748 print_string("E to edit your file,");
750 if (deletions_allowed)
751 print_nl("1 or ... or 9 to ignore the next 1 to 9 tokens of input,");
753 print_nl("H for help, X to quit.");
755 } /* end of while(true) loop */
759 if (error_count == 100)
761 print_nl("(That makes 100 errors; please try again.)");
766 if (interaction > batch_mode)
774 else while(help_ptr > 0)
777 print_nl(help_line[help_ptr] == NULL ? "" : help_line[help_ptr]);
782 if (interaction > batch_mode)
788 void fatal_error_(char * s)
790 normalize_selector();
791 print_err("Emergency stop");
796 void overflow_(char * s, integer n)
798 normalize_selector();
799 print_err("TeX capacity exceeded, sorry [");
804 help2("If you really absolutely need more capacity,",
805 "you can ask a wizard to enlarge me.");
809 if (!strcmp(s, "pattern memory") && n == trie_size)
811 sprintf(log_line, "\n (Maybe use -h=... on command line in ini-TeX)\n");
812 show_line(log_line, 0);
814 else if (!strcmp(s, "exception dictionary") && n == hyphen_prime)
816 sprintf(log_line, "\n (Maybe use -e=... on command line in ini-TeX)\n");
817 show_line(log_line, 0);
824 void confusion_(char * s)
826 normalize_selector();
828 if (history < error_message_issued)
830 print_err("This can't happen (");
833 help1("I'm broken. Please show this to someone who can fix can fix");
837 print_err("I can't go on meeting you like this");
838 help2("One of your faux pas seems to have wounded me deeply...",
839 "in fact, I'm barely conscious. Please fix it and try again.");
845 bool init_terminal (void)
853 cur_input.loc_field = first;
855 while((cur_input.loc_field < last) && (buffer[cur_input.loc_field]== ' '))
856 incr(cur_input.loc_field); // step over initial white space
858 if (cur_input.loc_field < last)
862 // failed to find input file name
866 flag = ConsoleInput("**", "Please type a file name or a control sequence\r\n(or ^z to exit)", (char *) &buffer[first]);
867 last = first + strlen((char *) &buffer[first]); /* -1 ? */
868 // may need to be more elaborate see input_line in texmf.c
870 (void) fputs("**", stdout);
872 flag = input_ln(stdin, true);
878 show_line("! End of file on the terminal... why?\n", 1);
882 cur_input.loc_field = first;
884 while ((cur_input.loc_field < last) && (buffer[cur_input.loc_field]== ' '))
885 incr(cur_input.loc_field); // step over intial white space
887 if (cur_input.loc_field < last)
890 sprintf(log_line, "%s\n", "Please type the name of your input file.");
891 show_line(log_line, 1);
895 // Make string from str_start[str_ptr] to pool_ptr
896 str_number make_string (void)
898 #ifdef ALLOCATESTRING
899 if (str_ptr == current_max_strings)
900 str_start = realloc_str_start(increment_max_strings);
902 if (str_ptr == current_max_strings)
904 overflow("number of strings", current_max_strings - init_str_ptr); /* 97/Mar/9 */
905 return 0; // abort_flag set
908 if (str_ptr == max_strings)
910 overflow("number of strings", max_strings - init_str_ptr);
911 return 0; // abort_flag set
915 str_start[str_ptr] = pool_ptr;
917 return (str_ptr - 1);
920 bool str_eq_buf_ (str_number s, integer k)
922 register bool Result;
928 while (j < str_start[s + 1])
930 if (str_pool[j] != buffer[k])
945 bool str_eq_str_ (str_number s, str_number t)
947 register bool Result;
953 if (length(s) != length(t))
959 while (j < str_start[s + 1])
961 if (str_pool[j] != str_pool[k])
973 void print_two_(integer n)
976 print_char('0' + (n / 10));
977 print_char('0' + (n % 10));
980 void print_hex_(integer n)
989 dig[k] = (unsigned char) (n % 16);
998 void print_roman_int_(integer n)
1001 nonnegative_integer u, v;
1003 j = str_start[260]; /* m2d5c2l5x2v5i */
1010 print_char(str_pool[j]);
1018 u = v / (str_pool[k - 1] - '0');
1020 if (str_pool[k - 1] == 50)
1023 u = u / (str_pool[k - 1] - '0');
1028 print_char(str_pool[k]);
1034 v = v / (str_pool[j - 1] - '0');
1039 void print_current_string (void)
1043 j = str_start[str_ptr];
1045 while (j < pool_ptr)
1047 print_char(str_pool[j]);
1052 int stringlength (int str_ptr)
1054 return (str_start[str_ptr + 1] - str_start[str_ptr]) + 2;
1057 char * add_string (char *s, char * str_string)
1061 n = strlen(str_string);
1062 memcpy(s, &str_string, n);
1070 int addextrahelp = 1;
1072 // make one long \r\n separated string out of help lines
1073 // str_pool is packed_ASCII_code *
1075 char * make_up_help_string (int nhelplines)
1077 char * helpstring, *s;
1080 // get length of help for this specific message
1081 for (k = nhelplines - 1; k >= 0; k--)
1083 nlen += strlen(help_line[k]);
1086 nlen += 2; // for blank line separator: "\r\n"
1090 nlen += stringlength(265);
1091 nlen += stringlength(266);
1092 nlen += stringlength(267);
1095 nlen += stringlength(268);
1097 if (deletions_allowed)
1098 nlen += stringlength(269);
1100 nlen += stringlength(270);
1103 helpstring = (char *) malloc(nlen + 1); // +1 = '\0'
1106 for (k = nhelplines-1; k >= 0; k--)
1108 s = add_string(s, help_line[k]);
1115 s = add_string(s, "Type <return> to proceed, S to scroll future error messages,");
1116 s = add_string(s, "R to run without stopping, Q to run quietly,");
1117 s = add_string(s, "I to insert something, ");
1120 s = add_string(s, "E to edit your file, ");
1122 if (deletions_allowed)
1123 s = add_string(s, "1 or ... or 9 to ignore the next 1 to 9 tokens of input,");
1125 s = add_string(s, "H for help, X to quit.");
1131 char * make_up_query_string (int promptstr)
1134 int nstart, nnext, n;
1137 nstart = str_start[ promptstr];
1138 nnext = str_start[ promptstr + 1];
1140 querystr = (char *) malloc(n + 1);
1142 memcpy(s, &str_pool[nstart], n);
1149 // abort_flag set if input_line / ConsoleInput returns non-zero
1150 // should set interrupt instead ???
1151 // called from tex0.c, tex2.c, tex3.c
1153 // void term_input(void)
1154 void term_input (char * term_str, int term_help_lines)
1158 char * helpstring = NULL;
1160 char * querystring = NULL;
1162 // if (nhelplines != 0) {
1163 // helpstring = make_up_help_string (nhelplines);
1164 // printf(helpstring);
1165 // free(helpstring);
1167 show_line("\n", 0); // force it to show what may be buffered up ???
1171 if (term_str != NULL)
1172 querystring = term_str;
1174 if (term_help_lines != NULL)
1175 helpstring = make_up_help_string(term_help_lines);
1177 if (helpstring == NULL && querystring != NULL)
1179 if (strcmp(querystring, ": ") == 0)
1180 helpstring = xstrdup("Please type another file name (or ^z to exit):");
1181 else if (strcmp(querystring, "=>") == 0) // from firm_up_the_line
1182 helpstring = xstrdup("Please type <enter> to accept this line\r\nor type a replacement line");
1183 else if (strcmp(querystring, "insert>") == 0) // from error() after "I"
1184 helpstring = xstrdup("Please type something to insert here");
1185 else if (strcmp(querystring, "") == 0) // from read_toks
1186 helpstring = xstrdup("Please type a control sequence");
1187 else if (strcmp(querystring, "= ") == 0) // from read_toks
1188 helpstring = xstrdup("Please type a token");
1189 else if (strcmp(querystring, "*") == 0) // get_next
1190 helpstring = xstrdup("Please type a control sequence\r\n(or ^z to exit)");
1193 flag = ConsoleInput(querystring, helpstring, (char *) &buffer[first]); // ???
1194 // flag == 0 means trouble --- EOF on terminal
1195 if (querystring != NULL)
1198 if (helpstring != NULL)
1201 helpstring = querystring = NULL;
1203 last = first + strlen((char *) &buffer[first]); /* -1 ? */
1204 // flag = (last > first);
1205 // may need to be more elaborate see input_line in texmf.c ???
1206 // sprintf(log_line, "first %d last %d flag %d - %s",
1207 // first, last, flag, (char *) &buffer[first]);
1208 // winerror(log_line);
1211 flag = input_ln(stdin, true);
1215 fatal_error("End of file on the terminal!");
1216 return; // abort_flag set
1220 // echo what was typed into Console buffer also
1222 for (k = first; k <= last - 1; k++)
1226 decr(selector); // shut off echo
1229 for (k = first; k <= last - 1; k++)
1233 incr(selector); // reset selector again
1237 void int_error_ (integer n)
1245 void normalize_selector (void)
1248 selector = term_and_log;
1250 selector = term_only;
1255 if (interaction == batch_mode)
1259 void pause_for_instructions (void)
1261 if (OK_to_interrupt)
1263 interaction = error_stop_mode;
1265 if ((selector == log_only) || (selector == no_print))
1268 print_err("Interruption");
1270 "Try to insert some instructions for me (e.g.,`I\\showlists'),",
1271 "unless you just want to quit by typing `X'.");
1272 deletions_allowed = false;
1274 deletions_allowed = true;
1279 integer half_(integer x)
1282 return ((x + 1) / 2);
1287 scaled round_decimals_(small_number k)
1296 a = (a + dig[k] * 131072L) / 10; /* 2^17 */
1299 return ((a + 1) / 2);
1302 /* This has some minor speedup changes - no real advantage probably ... */
1303 void print_scaled_(scaled s)
1313 print_int(s / 65536L);
1315 s = 10 * (s % 65536L) + 5;
1321 s = s - 17232; /* 2^15 - 50000 - rounding */
1322 print_char('0' + (s / 65536L));
1323 s = 10 * (s % 65536L);
1326 while (!(s <= delta));
1329 scaled mult_and_add_(integer n, scaled x, scaled y, scaled maxanswer)
1339 else if (((x <= (maxanswer - y) / n) && (- (integer) x <= (maxanswer + y) / n)))
1348 scaled x_over_n_(scaled x, integer n)
1350 register scaled Result;
1373 tex_remainder = x % n;
1377 Result = - (integer) ((- (integer) x)/ n);
1378 tex_remainder = - (integer) ((- (integer) x)% n);
1383 tex_remainder = - (integer) tex_remainder;
1388 scaled xn_over_d_(scaled x, integer n, integer d)
1390 register scaled Result;
1392 nonnegative_integer t, u, v;
1402 t = (x % 32767L) * n;
1403 u = (x / 32768L) * n + (t / 32768L);
1404 v = (u % d) * 32768L + (t % 32768L);
1406 if (u / d >= 32768L)
1409 u = 32768L * (u / d) + (v / d);
1414 tex_remainder = v % d;
1418 Result = - (integer) u;
1419 tex_remainder = - (integer)(v % d);
1425 halfword badness_(scaled t, scaled s)
1437 else if (s >= 1663497L)
1445 return (r * r * r + 131072L) / 262144L; /* 2^17 */
1450 void print_word_(memory_word w)
1454 print_scaled(w.cint);
1456 print_scaled(round(65536L * w.gr));
1458 print_int(w.hh.v.LH);
1464 print_int(w.hh.v.RH);
1466 print_int(w.qqqq.b0);
1468 print_int(w.qqqq.b1);
1470 print_int(w.qqqq.b2);
1472 print_int(w.qqqq.b3);
1474 /* need this version only if SHORTFONTINFO defined */
1475 void zprintfword(fmemoryword w)
1479 print_scaled(w.cint);
1481 print_scaled(round(65536L * w.gr));
1483 print_int(w.hh.v.LH);
1487 print_int(w .hh.b1);
1489 print_int(w.hh.v.RH);
1491 print_int(w.qqqq.b0);
1493 print_int(w.qqqq.b1);
1495 print_int(w.qqqq.b2);
1497 print_int(w.qqqq.b3);
1501 void show_token_list_(integer p, integer q, integer l)
1504 ASCII_code match_chr;
1511 while ((p != 0) && (tally < l))
1515 first_count = tally;
1516 trick_count = tally + 1 + error_line - half_error_line;
1518 if (trick_count < error_line)
1519 trick_count = error_line;
1522 if ((p < hi_mem_min) || (p > mem_end))
1524 print_esc("CLOBBERED.");
1528 if (info(p) >= cs_token_flag)
1529 print_cs(info(p) - cs_token_flag);
1561 print_char(c + '0');
1570 match_chr = (ASCII_code) c;
1599 if (scanner_status > 1)
1601 print_nl("Runaway ");
1603 switch (scanner_status)
1606 print_string("definition");
1611 print_string("argument");
1616 print_string("preamble");
1621 print_string("text");
1628 show_token_list(link(p), 0, error_line - 10);
1632 /* *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** */
1633 /* first try list of available nodes (avail != NULL) */
1634 /* then see if can go upwards (mem_end < mem_max) */
1635 /* then see if can go downwards (hi_mem_min > lo_mem_max) */
1636 /* if not, extend memory at the top and grab from there --- new */
1637 /* else fail ! paragraph 120 */
1638 /* *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** */
1639 halfword get_avail (void)
1646 avail = link(avail);
1647 else if (mem_end < mem_max)
1657 if (hi_mem_min <= lo_mem_max) /* have we run out in middle ? */
1660 mem = realloc_main (0, mem_top / 2); /* zzzaa = zmem = mem */
1665 if (mem_end >= mem_max)
1668 overflow("main memory size", mem_max + 1 - mem_min);
1669 return 0; // abort_flag set
1672 incr(mem_end); /* then grab from new area */
1673 p = mem_end; /* 1993/Dec/14 */
1677 link(p) = 0; /* link(p) = null !!! */
1686 void flush_list_(halfword p) /* paragraph 123 */
1690 if (p != 0) /* null !!! */
1702 while (!(r == 0)); /* r != null */
1709 halfword get_node_(integer s)
1711 register halfword Result;
1722 q = p + node_size(p);
1724 while ((mem[q].hh.v.RH == empty_flag))
1731 llink(t) = llink(q);
1732 rlink(llink(q)) = t;
1733 q = q + node_size(q);
1738 if (r > toint(p + 1))
1740 node_size(p) = r - p;
1755 node_size(p) = q - p;
1758 while (!(p == rover));
1760 if (s == 1073741824L) /* 2^30 - special case - merge adjacent */
1762 Result = max_halfword;
1765 show_line("Merged adjacent multi-word nodes\n", 0);
1770 /* maybe try downward epxansion first instead ? */
1771 if (lo_mem_max + 2 < hi_mem_min)
1772 if (lo_mem_max + 2 <= mem_bot + max_halfword) /* silly ? flush 93/Dec/16 */
1774 /* if (hi_mem_min - lo_mem_max >= 1998) */
1775 if (hi_mem_min - lo_mem_max >= (block_size + block_size - 2))
1776 /* t = lo_mem_max + 1000; */
1777 t = lo_mem_max + block_size;
1779 t = lo_mem_max + 1 + (hi_mem_min - lo_mem_max) / 2;
1786 if (t > mem_bot + max_halfword)
1787 t = mem_bot + max_halfword; /* silly ? flush 93/Dec/16 */
1791 link(q) = empty_flag;
1792 node_size(q) = t - lo_mem_max; /* block size */
1794 link(lo_mem_max) = 0;
1795 info(lo_mem_max) = 0;
1800 /* *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** */
1801 /* we've run out of space in the middle for variable length blocks */
1802 /* try and add new block from below mem_bot *//* first check if space ! */
1803 if (mem_min - (block_size + 1) <= mem_start) /* extend lower memory downwards */
1805 mem = realloc_main (mem_top/2 + block_size, 0); /* zzzaa = zmem = mem */
1813 if (mem_min - (block_size + 1) <= mem_start) /* check again */
1817 sprintf(log_line, "mem_min %d, mem_start %d, block_size %d\n", mem_min, mem_start, block_size);
1818 show_line(log_line, 0);
1821 overflow("main memory size", mem_max + 1 - mem_min); /* darn: allocation failed ! */
1822 return 0; // abort_flag set
1824 /* avoid function call in following ? */
1825 add_variable_space (block_size); /* now to be found in itex.c */
1826 goto lab20; /* go try get_node again */
1832 var_used = var_used + s;
1839 void free_node_(halfword p, halfword s)
1844 link(p) = empty_flag;
1851 var_used = var_used - s;
1855 halfword new_null_box (void)
1859 p = get_node(box_node_size);
1860 type(p) = hlist_node;
1861 subtype(p) = min_quarterword;
1865 shift_amount(p) = 0;
1867 glue_sign(p) = normal;
1868 glue_order(p) = normal;
1874 halfword new_rule (void)
1878 p = get_node(rule_node_size);
1879 type(p) = rule_node;
1881 width(p) = null_flag;
1882 depth(p) = null_flag;
1883 height(p) = null_flag;
1888 halfword new_ligature_(quarterword f, quarterword c, halfword q)
1892 p = get_node(small_node_size);
1893 type(p) = ligature_node;
1894 font(lig_char(p)) = f;
1895 character(lig_char(p)) = c;
1902 halfword new_lig_item_(quarterword c)
1906 p = get_node(small_node_size);
1913 halfword new_disc (void)
1917 p = get_node(small_node_size);
1918 type(p) = disc_node;
1919 replace_count(p) = 0;
1926 halfword new_math_(scaled w, small_number s)
1930 p = get_node(small_node_size);
1931 type(p) = math_node;
1938 halfword new_spec_(halfword p)
1942 q = get_node(glue_spec_size);
1944 glue_ref_count(q) = 0;
1945 width(q) = width(p);
1946 stretch(q) = stretch(p);
1947 shrink(q) = shrink(p);
1952 halfword new_param_glue_(small_number n)
1957 p = get_node(small_node_size);
1958 type(p) = glue_node;
1963 incr(glue_ref_count(q));
1968 halfword new_glue_(halfword q)
1972 p = get_node(small_node_size);
1973 type(p) = glue_node;
1974 subtype(p) = normal;
1977 incr(glue_ref_count(q));
1982 halfword new_skip_param_(small_number n)
1986 temp_ptr = new_spec(glue_par(n));
1987 p = new_glue(temp_ptr);
1988 glue_ref_count(temp_ptr) = 0;
1994 halfword new_kern_(scaled w)
1998 p = get_node(small_node_size);
1999 type(p) = kern_node;
2000 subtype(p) = normal;
2006 halfword new_penalty_(integer m)
2010 p = get_node(small_node_size);
2011 type(p) = penalty_node;
2020 void check_mem_(bool printlocs)
2025 for (p = mem_min; p <= lo_mem_max; p++) freearr[p] = false;
2026 for (p = hi_mem_min; p <= mem_end; p++) freearr[p] = false;
2031 if ((p > mem_end) || (p < hi_mem_min))
2033 else if (freearr[p])
2038 print_nl("AVAIL list clobbered at ");
2051 if ((p >= lo_mem_max) || (p < mem_min))
2053 else if ((rlink(p) >= lo_mem_max) || (rlink(p) < mem_min))
2055 else if (!(is_empty(p)) || (node_size(p) < 2) ||
2056 (p + node_size(p) > lo_mem_max) || (llink(rlink(p)) != p))
2061 print_nl("Double-AVAIL list clobbered at ");
2066 for (q = p; q <= p + node_size(p) - 1; q++)
2070 print_nl("Doubly free location at ");
2078 } while (!(p == rover));
2081 while (p <= lo_mem_max) {
2084 print_nl("Bad flag at ");
2087 while ((p <= lo_mem_max) && !freearr[p]) incr(p);
2088 while ((p <= lo_mem_max) && freearr[p]) incr(p);
2093 print_nl("New busy locs:");
2095 for (p = mem_min; p <= lo_mem_max; p++)
2096 if (!freearr[p] && ((p > was_lo_max) || wasfree[p]))
2102 for (p = hi_mem_min; p <= mem_end; p++)
2103 if (!freearr[p] && ((p < was_hi_min) || (p > was_mem_end) || wasfree[p]))
2110 for (p = mem_min; p <= lo_mem_max; p++) wasfree[p] = freearr[p];
2111 for (p = hi_mem_min; p <= mem_end; p++) wasfree[p] = freearr[p];
2113 was_mem_end = mem_end;
2114 was_lo_max = lo_mem_max;
2115 was_hi_min = hi_mem_min;
2121 void search_mem_(halfword p)
2125 for (q = mem_min; q <= lo_mem_max; q++)
2141 for (q = hi_mem_min; q <= mem_end; q++)
2157 for (q = active_base; q <= box_base + 255; q++)
2166 for (q = 0; q <= save_ptr - 1; q++)
2168 if (equiv_field(save_stack[q]) == p)
2176 for (q = 0; q <= hyphen_prime; q++)
2177 if (hyph_list[q] == p)
2186 void short_display_(integer p)
2190 while (p != 0) { /* want p != null here bkph 93/Dec/15 !!! NOTE: still not fixed in 3.14159 ! */
2191 if (is_char_node(p))
2195 if (font(p) != font_in_short_display)
2197 if ((font(p) > font_max))
2202 print(font_id_text(font(p)));
2205 font_in_short_display = font(p);
2207 print(character(p));
2210 else switch (mem[p].hh.b0)
2225 if (glue_ptr(p) != 0)
2232 short_display(lig_ptr(p));
2235 short_display(pre_break(p));
2236 short_display(post_break(p));
2237 n = replace_count(p);
2240 if (link(p) != 0) /* if link(p)<>null then */
2252 void print_font_and_char_ (integer p)
2255 print_esc("CLOBBERED.");
2258 if ((font(p) > font_max))
2263 print(font_id_text(font(p)));
2267 print(character(p));
2271 void print_mark_ (integer p)
2275 if ((p < hi_mem_min)||(p > mem_end))
2276 print_esc("CLOBBERED.");
2278 show_token_list(link(p), 0, max_print_line - 10);
2283 void print_rule_dimen_ (scaled d)
2285 if ((d == -1073741824L)) /* - 2^30 */
2291 void print_glue_(scaled d, integer order, char * s)
2295 if ((order < normal) || (order > filll))
2296 print_string("foul");
2299 print_string("fil");
2305 } else if (*s != '\0')
2309 void print_spec_(integer p, char * s)
2311 if ((p < mem_min)||(p >= lo_mem_max))
2315 print_scaled(width(p));
2320 if (stretch(p) != 0)
2322 print_string("plus");
2323 print_glue(stretch(p), stretch_order(p), s);
2328 print_string("minus");
2329 print_glue(shrink(p), shrink_order(p), s);
2334 void print_fam_and_char_(halfword p)
2339 print(character(p));
2342 void print_delimiter_(halfword p)
2346 a = small_fam(p) * 256 + small_char(p);
2347 a = a * 4096 + large_fam(p) * 256 + large_char(p);
2355 void print_subsidiary_data_(halfword p, ASCII_code c)
2357 if ((pool_ptr - str_start[str_ptr]) >= depth_threshold)
2359 if (math_type(p) != 0)
2360 print_string(" []");
2367 switch (math_type(p))
2371 print_current_string();
2372 print_fam_and_char(p);
2383 print_current_string();
2398 void print_style_(integer c)
2403 print_esc("displaystyle");
2406 print_esc("textstyle");
2409 print_esc("scriptstyle");
2412 print_esc("scriptscriptstyle");
2415 print_string("Unknown style!");
2420 void print_skip_param_(integer n)
2424 case line_skip_code:
2425 print_esc("lineskip");
2428 case baseline_skip_code:
2429 print_esc("baselineskip");
2433 print_esc("parskip");
2436 case above_display_skip_code:
2437 print_esc("abovedisplayskip");
2440 case below_display_skip_code:
2441 print_esc("belowdisplayskip");
2444 case above_display_short_skip_code:
2445 print_esc("abovedisplayshortskip");
2448 case below_display_short_skip_code:
2449 print_esc("belowdisplayshortskip");
2452 case left_skip_code:
2453 print_esc("leftskip");
2456 case right_skip_code:
2457 print_esc("rightskip");
2461 print_esc("topskip");
2464 case split_top_skip_code:
2465 print_esc("splittopskip");
2469 print_esc("tabskip");
2472 case space_skip_code:
2473 print_esc("spaceskip");
2476 case xspace_skip_code:
2477 print_esc("xspaceskip");
2480 case par_fill_skip_code:
2481 print_esc("parfillskip");
2484 case thin_mu_skip_code:
2485 print_esc("thinmuskip");
2488 case med_mu_skip_code:
2489 print_esc("medmuskip");
2492 case thick_mu_skip_code:
2493 print_esc("thickmuskip");
2497 print_string("[unknown glue parameter!]");
2502 void show_node_list_(integer p)
2507 if (cur_length > depth_threshold)
2509 /* if (p > 0) */ /* was p>null !!! line 3662 in tex.web */
2510 if (p != 0) /* fixed 94/Mar/23 BUG FIX NOTE: still not fixed in 3.14159 ! */
2511 print_string(" []");
2517 while (p != 0) { /* want p != null - bkph 93/Dec/15 NOTE: still not fixed in 3.14159 ! */
2519 print_current_string();
2523 print_string("Bad link, display aborted.");
2529 if (n > breadth_max)
2531 print_string("etc.");
2535 if ((p >= hi_mem_min))
2536 print_font_and_char(p);
2537 else switch (type(p))
2543 if (type(p) == hlist_node)
2545 else if (type(p) == vlist_node)
2547 else print_esc("unset");
2549 print_string("box(");
2550 print_scaled(height(p));
2552 print_scaled(depth(p));
2554 print_scaled(width(p));
2556 if (type(p) == unset_node)
2558 if (span_count(p) != 0)
2561 print_int(span_count(p) + 1);
2562 print_string(" columns)");
2565 if (glue_stretch(p) != 0)
2567 print_string(", stretch ");
2568 print_glue(glue_stretch(p), glue_order(p), "");
2571 if (glue_shrink(p) != 0)
2573 print_string(", shrink ");
2574 print_glue(glue_shrink(p), glue_sign(p), "");
2581 if ((g != 0.0) && (glue_sign(p) != 0))
2583 print_string(", glue set ");
2585 if (glue_sign(p) == shrinking)
2588 if (fabs(g)> 20000.0)
2593 print_string("< -");
2595 print_glue(20000 * 65536L, glue_order(p), "");
2598 print_glue(round(65536L * g), glue_order(p), "");
2601 if (shift_amount(p) != 0)
2603 print_string(", shifted ");
2604 print_scaled(shift_amount(p));
2610 str_pool[pool_ptr] = 46;
2613 show_node_list(mem[p + 5].hh.v.RH);
2622 print_rule_dimen(height(p));
2624 print_rule_dimen(depth(p));
2626 print_rule_dimen(width(p));
2632 print_esc("insert");
2633 print_int(subtype(p));
2634 print_string(", natural size ");
2635 print_scaled(height(p));
2636 print_string("; split(");
2637 print_spec(split_top_ptr(p), "");
2639 print_scaled(depth(p));
2640 print_string("); float cost ");
2641 print_int(float_cost(p));
2644 str_pool[pool_ptr] = 46;
2647 show_node_list(mem[p + 4].hh.v.LH);
2657 print_write_whatsit(1279, p); /* debug # (-1 to exit): */
2659 print_file_name(open_name(p), open_area(p), open_ext(p));
2665 print_write_whatsit(591, p); /* write */
2666 print_mark(write_tokens(p));
2671 print_write_whatsit(1280, p); /* closeout */
2676 print_esc("special");
2677 print_mark(write_tokens(p));
2683 print_esc("setlanguage");
2684 print_int(what_lang(p));
2685 print_string(" (hyphenmin ");
2686 print_int(what_lhm(p));
2688 print_int(what_rhm(p));
2694 print_string("whatsit?");
2700 if (subtype(p) >= a_leaders)
2704 if (subtype(p) == c_leaders)
2706 else if (subtype(p) == x_leaders)
2709 print_string("leaders ");
2711 print_spec(glue_ptr(p), "");
2714 str_pool[pool_ptr] = 46;
2717 show_node_list(mem[p + 1].hh.v.RH);
2725 if (subtype(p) != normal)
2729 if (subtype(p) < cond_math_glue)
2730 print_skip_param(subtype(p) - 1);
2731 else if (subtype(p) == cond_math_glue)
2732 print_esc("nonscript");
2733 else print_esc("mskip");
2738 if (subtype(p) != cond_math_glue)
2742 if (subtype(p) < cond_math_glue)
2743 print_spec(glue_ptr(p), "");
2745 print_spec(glue_ptr(p), "mu");
2751 if (subtype(p) != mu_glue)
2755 if (subtype(p) != normal)
2758 print_scaled(width(p));
2760 if (subtype(p) == acc_kern)
2761 print_string(" (for accent)");
2766 print_scaled(width(p));
2775 if (subtype(p) == before)
2778 print_string("off");
2782 print_string(", surrounded ");
2783 print_scaled(width(p));
2790 print_font_and_char(lig_char(p));
2791 print_string("(ligature ");
2796 font_in_short_display = font(lig_char(p));
2797 short_display(lig_ptr(p));
2799 if (odd(subtype(p)))
2808 print_esc("penalty ");
2809 print_int(penalty(p));
2815 print_esc("discretionary");
2817 if (replace_count(p) > 0)
2819 print_string(" replacing ");
2820 print_int(replace_count(p));
2825 str_pool[pool_ptr] = 46;
2828 show_node_list(mem[p + 1].hh.v.LH);
2832 str_pool[pool_ptr]= 124;
2835 show_node_list(mem[p + 1].hh.v.RH);
2843 print_mark(mark_ptr(p));
2849 print_esc("vadjust");
2852 str_pool[pool_ptr] = 46;
2855 show_node_list(mem[p + 1].cint);
2862 print_style(subtype(p));
2867 print_esc("mathchoice");
2869 show_node_list(display_mlist(p));
2872 show_node_list(text_mlist(p));
2875 show_node_list(script_mlist(p));
2878 show_node_list(script_script_mlist(p));
2902 print_esc("mathord");
2906 print_esc("mathop");
2910 print_esc("mathbin");
2914 print_esc("mathrel");
2918 print_esc("mathopen");
2922 print_esc("mathclose");
2926 print_esc("mathpunct");
2930 print_esc("mathinner");
2934 print_esc("overline");
2938 print_esc("underline");
2942 print_esc("vcenter");
2947 print_esc("radical");
2948 print_delimiter(left_delimiter(p));
2954 print_esc("accent");
2955 print_fam_and_char(accent_chr(p));
2962 print_delimiter(delimiter(p));
2969 print_delimiter(delimiter(p));
2974 if (subtype(p) != normal)
2975 if (subtype(p) == limits)
2976 print_esc("limits");
2978 print_esc("nolimits");
2980 if (type(p) < left_noad)
2981 print_subsidiary_data(nucleus(p), '.');
2983 print_subsidiary_data(supscr(p), '^');
2984 print_subsidiary_data(subscr(p), '_');
2990 print_esc("fraction, thickness ");
2992 if (thickness(p) == 1073741824L) /* 2^30 */
2993 print_string("= default");
2995 print_scaled(thickness(p));
2997 if ((small_fam(left_delimiter(p)) != 0) || (small_char(left_delimiter(p)) != 0) ||
2998 (large_fam(left_delimiter(p)) != 0) || (large_char(left_delimiter(p)) != 0))
3000 print_string(", left-delimiter ");
3001 print_delimiter(left_delimiter(p));
3004 if ((small_fam(right_delimiter(p)) != 0) || (small_char(right_delimiter(p)) != 0) ||
3005 (large_fam(right_delimiter(p)) != 0)||(large_char(right_delimiter(p)) != 0))
3007 print_string(", right-delimiter ");
3008 print_delimiter(right_delimiter(p));
3011 print_subsidiary_data(numerator(p), '\\');
3012 print_subsidiary_data(denominator(p), '/');
3017 print_string("Unknown node type!");