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 /* following bit used to be end of tex1.c */
25 void restore_trace_(halfword p, char * s)
33 end_diagnostic(false);
43 if (cur_level > level_one)
51 if (save_type(save_ptr) == level_boundary)
54 p = save_index(save_ptr);
56 if (save_type(save_ptr) == insert_token)
65 if (save_type(save_ptr) == restore_old_value)
67 l = save_level(save_ptr);
71 save_stack[save_ptr] = eqtb[undefined_control_sequence];
74 if (eq_level(p) == level_one)
76 eq_destroy(save_stack[save_ptr]);
78 if (tracing_restores > 0)
79 restore_trace(p, "retaining");
85 eqtb[p] = save_stack[save_ptr];
87 if (tracing_restores > 0)
88 restore_trace(p, "restoring");
91 else if (xeq_level[p] != level_one)
93 eqtb[p] = save_stack[save_ptr];
96 if (tracing_restores > 0)
97 restore_trace(p, "restoring");
103 if (tracing_restores > 0)
104 restore_trace(p, "retaining");
110 cur_group = save_level(save_ptr);
111 cur_boundary = save_index(save_ptr);
115 confusion("curlevel");
119 /* This is where the old tex2.c used to start */
121 void prepare_mag (void)
123 if ((mag_set > 0) && (mag != mag_set))
125 print_err("Incompatible magnification (");
128 print_nl(" the previous value will be retained");
129 help2("I can handle only one magnification ratio per job. So I've",
130 "reverted to the magnification you used earlier on this run.");
132 geq_word_define(int_base + mag_code, mag_set);
135 if ((mag <= 0) || (mag > 32768L))
137 print_err("Illegal magnification has been changed to 1000");
138 help1("The magnification ratio must be between 1 and 32768.");
140 geq_word_define(int_base + mag_code, 1000);
146 void token_show_ (halfword p)
149 show_token_list(link(p), 0, 10000000L);
152 void print_meaning (void)
154 print_cmd_chr(cur_cmd, cur_chr);
162 else if (cur_cmd == top_bot_mark)
166 token_show(cur_mark[cur_chr]);
170 void show_cur_cmd_chr (void)
175 if (mode != shown_mode)
182 print_cmd_chr(cur_cmd, cur_chr);
184 end_diagnostic(false);
187 void show_context (void)
200 base_ptr = input_ptr;
201 input_stack[base_ptr] = cur_input;
207 cur_input = input_stack[base_ptr];
210 if ((cur_input.name_field > 17) || (base_ptr == 0))
213 if ((base_ptr == input_ptr) || bottomline || (nn < error_context_lines))
215 if ((base_ptr == input_ptr) || (state != token_list) ||
216 (index != backed_up) || (loc != 0))
219 old_setting = selector;
223 if (cur_input.name_field <= 17)
224 if ((cur_input.name_field == 0))
228 print_nl("<insert> ");
232 if (cur_input.name_field == 17)
235 print_int(cur_input.name_field - 1);
244 if (cur_input.name_field > 17)
245 print(cur_input.name_field);
266 trick_count = 1000000L;
269 if (buffer[limit] == end_line_char)
275 for (i = start; i <= j - 1; i++)
280 trick_count = tally + 1 + error_line - half_error_line;
282 if (trick_count < error_line)
283 trick_count = error_line;
293 print_nl("<argument> ");
298 print_nl("<template> ");
303 print_nl("<recently read> ");
305 print_nl("<to be read again> ");
309 print_nl("<inserted text> ");
314 print_cs(cur_input.name_field);
318 print_nl("<output> ");
322 print_nl("<everypar> ");
325 case every_math_text:
326 print_nl("<everymath> ");
329 case every_display_text:
330 print_nl("<everydisplay> ");
333 case every_hbox_text:
334 print_nl("<everyhbox> ");
337 case every_vbox_text:
338 print_nl("<everyvbox> ");
342 print_nl("<everyjob> ");
346 print_nl("<everycr> ");
354 print_nl("<write> ");
366 trick_count = 1000000L;
370 show_token_list(start, loc, 100000L);
372 show_token_list(link(start), loc, 100000L);
375 selector = old_setting;
377 if (trick_count == 1000000L)
380 trick_count = tally + 1 + error_line - half_error_line;
382 if (trick_count < error_line)
383 trick_count = error_line;
386 if (tally < trick_count)
387 m = tally - first_count;
389 m = trick_count - first_count;
391 if (l + first_count <= half_error_line)
399 p = l + first_count - half_error_line + 3;
403 for (q = p; q <= first_count - 1; q++)
404 print_char(trick_buf[q % error_line]);
408 for (q = 1; q <= n; q++)
411 if (m + n <= error_line)
414 p = first_count +(error_line - n - 3);
416 for (q = first_count; q <= p - 1; q++)
417 print_char(trick_buf[q % error_line]);
419 if (m + n > error_line)
424 else if (nn == error_context_lines)
436 cur_input = input_stack[input_ptr];
438 //#pragma optimize("g", off) /* 98/Dec/10 experiment */
440 void begin_token_list_ (halfword p, quarterword t)
443 if (input_ptr > max_in_stack)
445 max_in_stack = input_ptr;
447 #ifdef ALLOCATEINPUTSTACK
448 if (input_ptr == current_stack_size)
449 input_stack = realloc_input_stack(increment_stack_size);
451 if (input_ptr == current_stack_size) /* check again after allocation */
453 overflow("input stack size", current_stack_size);
454 return; // abort_flag set
457 if (input_ptr == stack_size) /* input stack - not dynamic */
459 overflow("input stack size", stack_size);
460 return; // abort_flag set
465 input_stack[input_ptr] = cur_input;
483 if (tracing_macros > 1)
499 print_cmd_chr(assign_toks, t + (hash_size + 1307));
505 end_diagnostic(false);
512 //#pragma optimize("", on) /* 98/Dec/10 experiment */
514 void end_token_list (void)
516 if (index >= backed_up)
518 if (index <= inserted)
522 delete_token_ref(start);
524 while (param_ptr > limit)
527 flush_list(param_stack[param_ptr]);
531 else if (index == u_template)
532 if (align_state > 500000L)
536 fatal_error("(interwoven alignment preambles are not allowed)");
537 return; // abort_flag set
542 cur_input = input_stack[input_ptr];
548 pause_for_instructions();
553 void back_input (void)
557 while ((state == 0) && (loc == 0) &&
558 (index != v_template))
566 if (cur_tok < right_brace_limit)
567 if (cur_tok < left_brace_limit)
573 if (input_ptr > max_in_stack)
575 max_in_stack = input_ptr;
576 #ifdef ALLOCATEINPUTSTACK
577 if (input_ptr == current_stack_size)
578 input_stack = realloc_input_stack(increment_stack_size);
580 if (input_ptr == current_stack_size) /* check again after allocation */
582 overflow("input stack size", current_stack_size);
583 return; // abort_flag set
586 if (input_ptr == stack_size) /* stack size - not dynamic */
588 overflow("input stack size", stack_size);
589 return; // abort_flag set
593 input_stack[input_ptr] = cur_input;
603 void back_error (void)
605 OK_to_interrupt = false;
607 OK_to_interrupt = true;
611 void ins_error (void)
613 OK_to_interrupt = false;
616 OK_to_interrupt = true;
620 void begin_file_reading (void)
622 if (in_open == max_in_open)
624 overflow("text input levels", max_in_open); /* text input levels - NOT DYNAMIC */
625 return; // abort_flag set
627 #ifdef ALLOCATEBUFFER
628 if (first == current_buf_size)
629 buffer = realloc_buffer(increment_buf_size);
631 if (first == current_buf_size) /* check again after allocation */
633 overflow("buffer size", current_buf_size);
634 return; // abort_flag set
637 if (first == buf_size)
639 overflow("buffer size", buf_size); /* buffer size - not dynamic */
640 return; // abort_flag set
644 if (in_open > high_in_open) /* 1999 Jan 17 */
645 high_in_open = in_open;
647 if (input_ptr > max_in_stack)
649 max_in_stack = input_ptr;
650 #ifdef ALLOCATEINPUTSTACK
651 if (input_ptr == current_stack_size)
652 input_stack = realloc_input_stack(increment_stack_size);
653 if (input_ptr == current_stack_size)
655 overflow("input stack size", current_stack_size); /* check again after allocation */
656 return; // abort_flag set
659 if (input_ptr == stack_size)
661 overflow("input stack size", stack_size); /* input stack - not dynamic */
662 return; // abort_flag set
666 input_stack[input_ptr] = cur_input;
670 line_stack[index] = line;
673 cur_input.name_field = 0;
676 void end_file_reading (void)
679 line = line_stack[index];
681 if (cur_input.name_field > 17)
682 (void) a_close(input_file[index]);
686 cur_input = input_stack[input_ptr];
690 /* called only form tex0.c */
692 void clear_for_error_prompt (void)
694 while ((state != 0) &&
695 (cur_input.name_field == 0) && (input_ptr > 0) &&
702 void check_outer_validity (void)
707 if (scanner_status != 0)
709 deletions_allowed = false;
713 if ((state == 0) || (cur_input.name_field < 1) || (cur_input.name_field > 17))
716 info(p) = cs_token_flag + cur_cs;
724 if (scanner_status > skipping)
729 print_err("File ended");
733 print_err("Forbidden control sequence found");
736 print_string(" while scanning ");
739 switch (scanner_status)
742 print_string("definition");
743 info(p) = right_brace_token + '}';
749 long_state = outer_call;
753 print_string("preamble");
754 info(p) = right_brace_token + '}';
758 info(p) = cs_token_flag + frozen_cr; /*96/Jan/10*/
759 align_state = -1000000L;
763 print_string("text");
764 info(p) = right_brace_token + '}';
768 print_string(" of ");
769 sprint_cs(warning_index);
770 help4("I suspect you have forgotten a `}', causing me",
771 "to read past where you wanted me to stop.",
772 "I'll try to recover; but if the error is serious,",
773 "you'd better type `E' or `X' now and fix your file.");
778 print_err("Incomplete ");
779 print_cmd_chr(if_test, cur_if);
780 print_string("; all text was ignored after line ");
781 print_int(skip_line);
782 help3("A forbidden control sequence occurred in skipped text.",
783 "This kind of error happens when you say `\\if...' and forget",
784 "the matching `\\fi'. I've inserted a `\\fi'; this might work.");
789 help_line[2] = "The file ended while I was skipping conditional text.";
791 cur_tok = cs_token_flag + frozen_fi; /* 96/Jan/10 */
794 deletions_allowed = true;
798 void firm_up_the_line (void)
805 if (interaction > nonstop_mode)
811 for (k = start; k <= limit - 1; k++)
819 for (k = first; k <= last - 1; k++)
820 buffer[k + start - first] = buffer[k];
822 limit = start + last - first;
827 void get_token (void)
829 no_new_control_sequence = false;
831 no_new_control_sequence = true;
834 cur_tok = (cur_cmd * 256) + cur_chr;
836 cur_tok = cs_token_flag + cur_cs;
839 void macro_call (void)
852 small_number save_scanner_status;
853 halfword save_warning_index;
854 ASCII_code match_chr;
856 save_scanner_status = scanner_status;
857 save_warning_index = warning_index;
858 warning_index = cur_cs;
863 if (tracing_macros > 0)
867 print_cs(warning_index);
868 token_show(ref_count);
869 end_diagnostic(false);
872 if (info(r) != end_match_token)
874 scanner_status = matching;
876 long_state = eq_type(cur_cs);
878 if (long_state >= outer_call)
879 long_state = long_state - 2;
885 if ((info(r) > match_token + 255) || (info(r) < match_token))
889 match_chr = info(r) - match_token;
898 if (cur_tok == info(r))
902 if ((info(r) >= match_token) && (info(r) <= end_match_token))
904 if (cur_tok < left_brace_limit)
916 print_err("Use of ");
917 sprint_cs(warning_index);
918 print_string(" doesn't match its definition");
919 help4("If you say, e.g., `\\def\\a1{...}', then you must always",
920 "put `1' after `\\a', since control sequence names are",
921 "made up of letters only. The macro here has not been",
922 "followed by the required stuff, so I'm ignoring it.");
931 store_new_token(info(t));
939 if (cur_tok != info(v))
947 if (info(u) != info(v))
961 if (cur_tok == par_token)
962 if (long_state != long_call)
964 if (long_state == call)
967 print_err("Paragraph ended before ");
968 sprint_cs(warning_index);
969 print_string("was complete");
970 help3("I suspect you've forgotten a `}', causing me to apply this",
971 "control sequence to too much text. How can we recover?",
972 "My plan is to forget the whole thing and hope for the best.");
976 pstack[n] = link(temp_head);
977 align_state = align_state - unbalance;
979 for (m = 0; m <= n; m++)
980 flush_list(pstack[m]);
985 if (cur_tok < right_brace_limit)
986 if (cur_tok < left_brace_limit)
992 fast_store_new_token(cur_tok);
995 if (cur_tok == par_token)
996 if (long_state != long_call)
998 if (long_state == call)
1001 print_err("Paragraph ended before ");
1002 sprint_cs(warning_index);
1003 print_string(" was complete");
1004 help3("I suspect you've forgotten a `}', causing me to apply this",
1005 "control sequence to too much text. How can we recover?",
1006 "My plan is to forget the whole thing and hope for the best.");
1010 pstack[n] = link(temp_head);
1011 align_state = align_state - unbalance;
1013 for (m = 0; m <= n; m++)
1014 flush_list(pstack[m]);
1018 if (cur_tok < right_brace_limit)
1019 if (cur_tok < left_brace_limit)
1031 store_new_token(cur_tok);
1036 print_err("Argument of ");
1037 sprint_cs(warning_index);
1038 print_string(" has an extra }");
1039 help6("I've run across a `}' that doesn't seem to match anything.",
1040 "For example, `\\def\\a#1{...}' and `\\a}' would produce",
1041 "this error. If you simply proceed now, the `\\par' that",
1042 "I've just inserted will cause me to report a runaway",
1043 "argument that might be the root of the problem. But if",
1044 "your `}' was spurious, just type `2' and it will go away.");
1047 cur_tok = par_token;
1053 if (cur_tok == space_token)
1054 if (info(r) <= end_match_token)
1055 if (info(r) >= match_token)
1058 store_new_token(cur_tok);
1061 incr(m); /* m may be used without having been ... */
1063 if (info(r) > end_match_token)
1066 if (info(r) < match_token)
1071 if ((m == 1) && (info(p) < right_brace_limit) && (p != temp_head))
1073 link(rbrace_ptr) = 0; /* rbrace_ptr may be used without ... */
1075 p = link(temp_head);
1076 pstack[n] = link(p);
1080 pstack[n] = link(temp_head);
1084 if (tracing_macros > 0)
1087 //print_nl(match_chr); /* matchchar may be used without ... */
1088 print_nl(""); print(match_chr);
1091 show_token_list(pstack[n - 1], 0, 1000);
1092 end_diagnostic(false);
1096 while (!(info(r) == end_match_token));
1099 while ((state == token_list) && (loc == 0) &&
1100 (index != v_template))
1103 begin_token_list(ref_count, macro);
1104 cur_input.name_field = warning_index;
1109 if (param_ptr + n > max_param_stack)
1111 max_param_stack = param_ptr + n;
1113 #ifdef ALLOCATEPARAMSTACK
1114 if (max_param_stack > current_param_size)
1115 param_stack = realloc_param_stack(increment_param_size);
1117 if (max_param_stack > current_param_size) /* check again after allocation */
1119 overflow("parameter stack size", current_param_size);
1120 return; // abort_flag set
1123 if (max_param_stack > param_size)
1125 overflow("parameter stack size", param_size); /* parameter stack - not dynamic */
1126 return; // abort_flag set
1131 for (m = 0; m <= n - 1; m++)
1132 param_stack[param_ptr + m] = pstack[m];
1134 param_ptr = param_ptr + n;
1137 scanner_status = save_scanner_status;
1138 warning_index = save_warning_index;
1141 void insert_relax (void)
1143 cur_tok = cs_token_flag + cur_cs;
1145 cur_tok = cs_token_flag + frozen_relax; /* 96/Jan/10 */
1156 small_number cvl_backup, radix_backup, co_backup;
1157 halfword backup_backup;
1158 small_number save_scanner_status;
1160 cv_backup = cur_val;
1161 cvl_backup = cur_val_level;
1162 radix_backup = radix;
1163 co_backup = cur_order;
1164 backup_backup = link(backup_head);
1168 if (tracing_commands > 1)
1174 if (cur_mark[cur_chr] != 0)
1175 begin_token_list(cur_mark[cur_chr], mark_text);
1183 if (cur_cmd > max_command)
1193 save_scanner_status = scanner_status;
1194 scanner_status = normal;
1196 scanner_status = save_scanner_status;
1200 if (t >= cs_token_flag)
1203 info(p) = cs_token_flag + frozen_dont_expand; /*96/Jan/10*/
1218 store_new_token(cur_tok);
1220 while (!(cur_cs != 0));
1222 if (cur_cmd != end_cs_name)
1224 print_err("Missing ");
1225 print_esc("endcsname");
1226 print_string(" inserted");
1227 help2("The control sequence marked <to be read again> should",
1228 "not appear between \\csname and \\endcsname.");
1237 if (j >= max_buf_stack)
1239 max_buf_stack = j + 1;
1241 #ifdef ALLOCATEBUFFER
1242 if (max_buf_stack == current_buf_size)
1243 buffer = realloc_buffer (increment_buf_size);
1245 if (max_buf_stack == current_buf_size) /* check again after allocation */
1247 overflow("buffer size", current_buf_size);
1248 return; // abort_flag set
1251 if (max_buf_stack == buf_size)
1253 overflow("buffer size", buf_size); /* buffer size - not dynamic */
1254 return; // abort_flag set
1259 buffer[j] = info(p) % 256;
1266 no_new_control_sequence = false;
1267 cur_cs = id_lookup(first, j - first);
1268 no_new_control_sequence = true;
1270 else if (j == first)
1273 cur_cs = single_base + buffer[first];
1277 if (eq_type(cur_cs) == undefined_cs)
1279 eq_define(cur_cs, relax, 256);
1282 cur_tok = cur_cs + cs_token_flag;
1299 if (cur_chr > if_limit)
1304 print_err("Extra ");
1305 print_cmd_chr(fi_or_else, cur_chr);
1306 help1("I'm ignoring this; it doesn't match any \\if.");
1311 while (cur_chr != fi_code)
1316 if_line = if_line_field(p);
1317 cur_if = subtype(p);
1320 free_node(p, if_node_size);
1328 else if (name_in_progress)
1335 print_err("Undefined control sequence");
1336 help5("The control sequence at the end of the top line",
1337 "of your error message was never \\def'ed. If you have",
1338 "misspelled it (e.g., `\\hobx'), type `I' and the correct",
1339 "spelling (e.g., `I\\hbox'). Otherwise just continue,",
1340 "and I'll forget about whatever was undefined.");
1345 else if (cur_cmd < end_template)
1351 cur_tok = cs_token_flag + frozen_endv; /* 96/Jan/10 */
1355 cur_val = cv_backup;
1356 cur_val_level = cvl_backup;
1357 radix = radix_backup;
1358 cur_order = co_backup;
1359 link(backup_head) = backup_backup;
1362 void get_x_token (void)
1367 if (cur_cmd <= max_command)
1370 if (cur_cmd >= call)
1371 if (cur_cmd < end_template)
1375 cur_cs = frozen_endv;
1386 cur_tok = (cur_cmd * 256) + cur_chr;
1388 cur_tok = cs_token_flag + cur_cs;
1393 while (cur_cmd > max_command)
1400 cur_tok = (cur_cmd * 256) + cur_chr;
1402 cur_tok = cs_token_flag + cur_cs;
1405 void scan_left_brace (void)
1411 while (!((cur_cmd != spacer) && (cur_cmd != relax)));
1413 if (cur_cmd != left_brace)
1415 print_err("Missing { inserted");
1416 help4("A left brace was mandatory here, so I've put one in.",
1417 "You might want to delete and/or insert some corrections",
1418 "so that I will find a matching right brace soon.",
1419 "(If you're confused by all this, try typing `I}' now.)");
1421 cur_tok = left_brace_token + '{';
1422 cur_cmd = left_brace;
1428 void scan_optional_equals (void)
1434 while (!(cur_cmd != spacer));
1436 if (cur_tok != other_token + '=')
1440 boolean scan_keyword(const char * s)
1454 if ((cur_cs == 0) && ((cur_chr == (*k)) || (cur_chr == (*k) - 'a' + 'A')))
1456 store_new_token(cur_tok);
1459 else if ((cur_cmd != spacer) || (p != backup_head))
1463 if (p != backup_head)
1464 back_list(link(backup_head));
1470 flush_list(link(backup_head));
1475 void mu_error (void)
1477 print_err("Incompatible glue units");
1478 help1("I'm going to assume that 1mu=1pt when they're mixed.");
1482 void scan_eight_bit_int (void)
1486 if ((cur_val < 0) || (cur_val > 255))
1488 print_err("Bad register code");
1489 help2("A register number must be between 0 and 255.",
1490 "I changed this one to zero.");
1496 void scan_char_num (void)
1500 if ((cur_val < 0) || (cur_val > 255))
1502 print_err("Bad character code");
1503 help2("A character number must be between 0 and 255.",
1504 "I changed this one to zero.");
1510 void scan_four_bit_int (void)
1514 if ((cur_val < 0) || (cur_val > 15))
1516 print_err("Bad number");
1517 help2("Since I expected to read a number between 0 and 15,",
1518 "I changed this one to zero.");
1524 void scan_fifteen_bit_int (void)
1528 if ((cur_val < 0) || (cur_val > 32767))
1530 print_err("Bad mathchar");
1531 help2("A mathchar number must be between 0 and 32767.",
1532 "I changed this one to zero.");
1538 void scan_twenty_seven_bit_int (void)
1542 if ((cur_val < 0) || (cur_val > 134217727L)) /* 2^27 - 1 */
1544 print_err("Bad delimiter code");
1545 help2("A numeric delimiter code must be between 0 and 2^{27}-1.",
1546 "I changed this one to zero.");
1552 void scan_font_ident (void)
1554 internal_font_number f;
1561 while (!(cur_cmd != spacer));
1563 if (cur_cmd == def_font)
1565 else if (cur_cmd == set_font)
1567 else if (cur_cmd == def_family)
1570 scan_four_bit_int();
1571 f = equiv(m + cur_val);
1575 print_err("Missing font identifier");
1576 help2("I was looking for a control sequence whose",
1577 "current meaning has been defined by \\font.");
1585 void find_font_dimen_(boolean writing)
1587 internal_font_number f;
1595 if (n < 0 || (n == 0 && font_dimen_zero == 0)) /* change 98/Oct/5 */
1599 if (writing && (n <= space_shrink_code) && (n >= space_code) && (font_glue[f] != 0))
1601 delete_glue_ref(font_glue[f]);
1605 if (n > font_params[f])
1613 if (fmem_ptr == current_font_mem_size)
1614 font_info = realloc_font_info(increment_font_mem_size);
1616 if (fmem_ptr == current_font_mem_size)
1618 overflow("font memory", current_font_mem_size);
1622 if (fmem_ptr == font_mem_size)
1624 overflow("font memory", font_mem_size);
1628 font_info[fmem_ptr].cint = 0;
1630 incr(font_params[f]);
1632 while (!(n == font_params[f]));
1634 cur_val = fmem_ptr - 1;
1637 cur_val = n + param_base[f];
1640 if (cur_val == fmem_ptr)
1643 print_esc(""); print(font_id_text(f));
1644 print_string(" has only ");
1645 print_int(font_params[f]);
1646 print_string(" fontdimen parameters");
1647 help2("To increase the number of font parameters, you must",
1648 "use \\fontdimen immediately after the \\font is loaded.");
1653 void scan_something_internal_(small_number level, boolean negative)
1666 if (m == math_code_base)
1667 scanned_result(math_code(cur_val), int_val);
1668 else if (m < math_code_base)
1669 scanned_result(equiv(m + cur_val), int_val);
1671 scanned_result(eqtb[m + cur_val].cint, int_val);
1680 if (level != tok_val)
1682 print_err("Missing number, treated as zero");
1683 help3("A number should have been here; I inserted `0'.",
1684 "(If you can't figure out why I needed to see a number,",
1685 "look up `weird error' in the index to The TeXbook.)");
1687 scanned_result(0, dimen_val);
1689 else if (cur_cmd <= assign_toks)
1691 if (cur_cmd < assign_toks)
1693 scan_eight_bit_int();
1694 m = toks_base + cur_val;
1697 scanned_result(equiv(m), tok_val);
1703 scanned_result(font_id_base + cur_val, ident_val);
1708 scanned_result(eqtb[m].cint, int_val);
1712 scanned_result(eqtb[m].cint, dimen_val);
1716 scanned_result(equiv(m), glue_val);
1719 case assign_mu_glue:
1720 scanned_result(equiv(m), mu_val);
1726 print_err("Improper ");
1727 print_cmd_chr(set_aux, m);
1728 help4("You can refer to \\spacefactor only in horizontal mode;",
1729 "you can refer to \\prevdepth only in vertical mode; and",
1730 "neither of these is meaningful inside \\write. So",
1731 "I'm forgetting what you said and using zero instead.");
1734 if (level != tok_val)
1735 scanned_result(0, dimen_val);
1737 scanned_result(0, int_val);
1739 else if (m == vmode)
1740 scanned_result(prev_depth, dimen_val);
1742 scanned_result(space_factor, int_val);
1747 scanned_result(0, int_val);
1750 nest[nest_ptr] = cur_list;
1753 while (abs(nest[p].mode_field) != vmode)
1756 scanned_result(nest[p].pg_field, int_val);
1763 cur_val = dead_cycles;
1765 cur_val = insert_penalties;
1771 case set_page_dimen:
1773 if ((page_contents == 0) && (! output_active))
1775 cur_val = max_dimen;
1779 cur_val = page_so_far[m];
1781 cur_val_level = dimen_val;
1787 if (par_shape_ptr == 0)
1790 cur_val = info(par_shape_ptr);
1792 cur_val_level = int_val;
1798 scan_eight_bit_int();
1800 if (box(cur_val) == 0)
1803 cur_val = mem[box(cur_val) + m].cint;
1805 cur_val_level = dimen_val;
1811 scanned_result(cur_chr, int_val);
1814 case assign_font_dimen:
1816 find_font_dimen(false);
1817 font_info[fmem_ptr].cint = 0;
1818 scanned_result(font_info[cur_val].cint, dimen_val);
1822 case assign_font_int:
1827 scanned_result(hyphen_char[cur_val], int_val);
1829 scanned_result(skew_char[cur_val], int_val);
1835 scan_eight_bit_int();
1840 cur_val = count(cur_val);
1844 cur_val = dimen(cur_val);
1848 cur_val = skip(cur_val);
1852 cur_val = mu_skip(cur_val);
1861 if (cur_chr > glue_val)
1863 if (cur_chr == input_line_no_code)
1866 cur_val = last_badness;
1868 cur_val_level = int_val;
1872 if (cur_chr == glue_val)
1873 cur_val = zero_glue;
1877 cur_val_level = cur_chr;
1879 if (!is_char_node(tail) && (mode != 0))
1883 if (type(tail) == penalty_node)
1884 cur_val = penalty(tail);
1888 if (type(tail) == kern_node)
1889 cur_val = width(tail);
1893 if (type(tail) == glue_node)
1895 cur_val = glue_ptr(tail);
1897 if (subtype(tail) == mu_glue)
1898 cur_val_level = mu_val;
1902 else if ((mode == vmode) && (tail == head))
1906 cur_val = last_penalty;
1910 cur_val = last_kern;
1914 if (last_glue != empty_flag)
1915 cur_val = last_glue;
1923 print_err("You can't use `");
1924 print_cmd_chr(cur_cmd, cur_chr);
1925 print_string("' after ");
1927 help1("I'm forgetting what you said and using zero instead.");
1930 if (level != tok_val)
1931 scanned_result(0, dimen_val);
1933 scanned_result(0, int_val);
1938 while (cur_val_level > level)
1940 if (cur_val_level == glue_val)
1941 cur_val = width(cur_val);
1942 else if (cur_val_level == mu_val)
1945 decr(cur_val_level);
1949 if (cur_val_level >= 2)
1951 cur_val = new_spec(cur_val);
1954 width(cur_val) = -width(cur_val);
1955 stretch(cur_val) = -stretch(cur_val);
1956 shrink(cur_val) = -shrink(cur_val);
1961 else if ((cur_val_level >= glue_val) && (cur_val_level <= mu_val))
1962 add_glue_ref(cur_val);
1965 void get_next (void)
1969 /* char cat; */ /* make this an int ? */
1970 int cat; /* make this an int ? 95/Jan/7 */
1977 if (state != token_list)
1982 cur_chr = buffer[loc];
1985 cur_cmd = cat_code(cur_chr);
1987 switch (state + cur_cmd)
1989 case any_state_plus(ignore):
1990 case skip_blanks + spacer:
1991 case new_line + spacer:
1995 case any_state_plus(escape):
2003 cur_chr = buffer[k];
2004 cat = cat_code(cur_chr);
2008 state = skip_blanks;
2009 else if (cat == spacer)
2010 state = skip_blanks;
2014 if ((cat == letter) && (k <= limit))
2018 cur_chr = buffer[k];
2019 cat = cat_code(cur_chr);
2022 while (!((cat != letter) || (k > limit)));
2025 if (buffer[k]== cur_chr)
2026 if (cat == sup_mark)
2034 if ((((c >= 48) && (c <= 57)) || ((c >= 97) && (c <= 102))))
2039 if ((((cc >= 48) && (cc <= 57)) || ((cc >= 97) && (cc <= 102))))
2051 cur_chr = 16 * cur_chr + cc - 48;
2053 cur_chr = 16 * cur_chr + cc - 87;
2055 buffer[k - 1] = cur_chr;
2058 buffer[k - 1] = c + 64;
2060 buffer[k - 1] = c - 64;
2067 buffer[k] = buffer[k + d];
2081 cur_cs = id_lookup(loc, k - loc);
2088 if (buffer[k] == cur_chr)
2089 if (cat == sup_mark)
2094 if (c < 128) /* ? */
2097 if ((((c >= 48) && (c <= 57)) || ((c >= 97) && (c <= 102))))
2102 if ((((cc >= 48) && (cc <= 57)) || ((cc >= 97) && (cc <= 102))))
2113 if (cc <= 57) /* cc may be used without ... */
2114 cur_chr = 16 * cur_chr + cc - 48;
2116 cur_chr = 16 * cur_chr + cc - 87;
2118 buffer[k - 1] = cur_chr;
2121 buffer[k - 1] = c + 64;
2123 buffer[k - 1] = c - 64;
2130 buffer[k] = buffer[k + d];
2137 cur_cs = single_base + buffer[loc];
2141 cur_cmd = eq_type(cur_cs);
2142 cur_chr = equiv(cur_cs);
2144 if (cur_cmd >= outer_call)
2145 check_outer_validity();
2149 case any_state_plus(active_char):
2151 cur_cs = cur_chr + active_base;
2152 cur_cmd = eq_type(cur_cs);
2153 cur_chr = equiv(cur_cs);
2156 if (cur_cmd >= outer_call)
2157 check_outer_validity();
2161 case any_state_plus(sup_mark):
2163 if (cur_chr == buffer[loc])
2166 c = buffer[loc + 1];
2172 if ((((c >= 48) && (c <= 57)) || ((c >= 97) && (c <= 102))))
2177 if ((((cc >= 48) && (cc <= 57)) || ((cc >= 97) && (cc <= 102))))
2187 cur_chr = 16 * cur_chr + cc - 48;
2189 cur_chr = 16 * cur_chr + cc - 87;
2208 case any_state_plus(invalid_char):
2210 print_err("Text line contains an invalid character");
2211 help2("A funny symbol that I can't read has just been input.",
2212 "Continue, and I'll forget that it ever happened.");
2213 deletions_allowed = false;
2215 deletions_allowed = true;
2220 case mid_line + spacer:
2222 state = skip_blanks;
2227 case mid_line + car_ret:
2235 case skip_blanks + car_ret:
2236 case any_state_plus(comment):
2243 case new_line + car_ret:
2247 cur_cmd = eq_type(cur_cs);
2248 cur_chr = equiv(cur_cs);
2250 if (cur_cmd >= outer_call)
2251 check_outer_validity();
2255 case mid_line + left_brace:
2259 case skip_blanks + left_brace:
2260 case new_line + left_brace:
2267 case mid_line + right_brace:
2271 case skip_blanks + right_brace:
2272 case new_line + right_brace:
2279 case add_delims_to(skip_blanks):
2280 case add_delims_to(new_line):
2292 if (cur_input.name_field > 17)
2299 if (input_ln(input_file[index], true))
2314 check_outer_validity();
2318 if ((end_line_char < 0) || (end_line_char > 255))
2321 buffer[limit] = end_line_char;
2328 if (!(cur_input.name_field == 0))
2341 if (selector < log_only)
2344 if (interaction > nonstop_mode)
2346 if ((end_line_char < 0) || (end_line_char > 255))
2350 print_nl("(Please type a command or say `\\end')");
2357 if ((end_line_char < 0) || (end_line_char > 255))
2360 buffer[limit]= end_line_char;
2367 fatal_error("*** (job aborted, no legal \\end found)");
2368 return; // abort_flag set
2375 pause_for_instructions();
2387 if (t >= cs_token_flag)
2389 cur_cs = t - cs_token_flag;
2390 cur_cmd = eq_type(cur_cs);
2391 cur_chr = equiv(cur_cs);
2393 if (cur_cmd >= outer_call)
2394 if (cur_cmd == dont_expand)
2396 cur_cs = info(loc) - cs_token_flag;
2398 cur_cmd = eq_type(cur_cs);
2399 cur_chr = equiv(cur_cs);
2401 if (cur_cmd > max_command)
2404 cur_chr = no_expand_flag;
2409 check_outer_validity();
2429 begin_token_list(param_stack[limit + cur_chr - 1], parameter);
2445 if (cur_cmd <= car_ret)
2446 if (cur_cmd >= tab_mark)
2447 if (align_state == 0)
2449 if ((scanner_status == aligning) && (cur_align == 0))
2451 fatal_error("(interwoven alignment preambles are not allowed)");
2452 return; // abort_flag set
2455 cur_cmd = extra_info(cur_align);
2456 extra_info(cur_align) = cur_chr;
2458 if (cur_cmd == omit)
2459 begin_token_list(omit_template, v_template);
2461 begin_token_list(v_part(cur_align), v_template);
2463 align_state = 1000000L;