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];
209 if ((state != token_list))
210 if ((name > 17) || (base_ptr == 0))
213 if ((base_ptr == input_ptr) || bottom_line || (nn < error_context_lines))
215 if ((base_ptr == input_ptr) || (state != token_list) ||
216 (index != backed_up) || (loc != 0))
219 old_setting = selector;
221 if (state != token_list)
228 print_nl("<insert> ");
263 if (buffer[limit] == end_line_char)
269 for (i = start; i <= j - 1; i++)
282 print_nl("<argument> ");
287 print_nl("<template> ");
292 print_nl("<recently read> ");
294 print_nl("<to be read again> ");
298 print_nl("<inserted text> ");
307 print_nl("<output> ");
311 print_nl("<everypar> ");
314 case every_math_text:
315 print_nl("<everymath> ");
318 case every_display_text:
319 print_nl("<everydisplay> ");
322 case every_hbox_text:
323 print_nl("<everyhbox> ");
326 case every_vbox_text:
327 print_nl("<everyvbox> ");
331 print_nl("<everyjob> ");
335 print_nl("<everycr> ");
343 print_nl("<write> ");
354 show_token_list(start, loc, 100000L);
356 show_token_list(link(start), loc, 100000L);
359 selector = old_setting;
361 if (trick_count == 1000000L)
364 if (tally < trick_count)
365 m = tally - first_count;
367 m = trick_count - first_count;
369 if (l + first_count <= half_error_line)
377 p = l + first_count - half_error_line + 3;
381 for (q = p; q <= first_count - 1; q++)
382 print_char(trick_buf[q % error_line]);
386 for (q = 1; q <= n; q++)
389 if (m + n <= error_line)
392 p = first_count +(error_line - n - 3);
394 for (q = first_count; q <= p - 1; q++)
395 print_char(trick_buf[q % error_line]);
397 if (m + n > error_line)
403 else if (nn == error_context_lines)
416 cur_input = input_stack[input_ptr];
419 void begin_token_list_ (halfword p, quarterword t)
436 if (tracing_macros > 1)
452 print_cmd_chr(assign_toks, t - output_text + output_routine_loc);
458 end_diagnostic(false);
466 void end_token_list (void)
468 if (index >= backed_up)
470 if (index <= inserted)
474 delete_token_ref(start);
477 while (param_ptr > limit)
480 flush_list(param_stack[param_ptr]);
484 else if (index == u_template)
485 if (align_state > 500000L)
489 fatal_error("(interwoven alignment preambles are not allowed)");
497 void back_input (void)
501 while ((state == 0) && (loc == 0) &&
502 (index != v_template))
510 if (cur_tok < right_brace_limit)
511 if (cur_tok < left_brace_limit)
523 void back_error (void)
525 OK_to_interrupt = false;
527 OK_to_interrupt = true;
531 void ins_error (void)
533 OK_to_interrupt = false;
536 OK_to_interrupt = true;
540 void begin_file_reading (void)
542 if (in_open == max_in_open)
544 overflow("text input levels", max_in_open);
547 #ifdef ALLOCATEBUFFER
548 if (first == current_buf_size)
549 buffer = realloc_buffer(increment_buf_size);
551 if (first == current_buf_size) /* check again after allocation */
553 overflow("buffer size", current_buf_size);
557 if (first == buf_size)
559 overflow("buffer size", buf_size);
566 if (in_open > high_in_open) /* 1999 Jan 17 */
567 high_in_open = in_open;
571 line_stack[index] = line;
577 void end_file_reading (void)
580 line = line_stack[index];
588 /* called only form tex0.c */
590 void clear_for_error_prompt (void)
592 while ((state != 0) && (name == 0) &&
593 (input_ptr > 0) && (loc > limit))
599 void check_outer_validity (void)
604 if (scanner_status != 0)
606 deletions_allowed = false;
610 if ((state == 0) || (name < 1) || (name > 17))
613 info(p) = cs_token_flag + cur_cs;
621 if (scanner_status > skipping)
626 print_err("File ended");
630 print_err("Forbidden control sequence found");
633 prints(" while scanning ");
636 switch (scanner_status)
639 prints("definition");
640 info(p) = right_brace_token + '}';
646 long_state = outer_call;
651 info(p) = right_brace_token + '}';
655 info(p) = cs_token_flag + frozen_cr;
656 align_state = -1000000L;
661 info(p) = right_brace_token + '}';
667 sprint_cs(warning_index);
668 help4("I suspect you have forgotten a `}', causing me",
669 "to read past where you wanted me to stop.",
670 "I'll try to recover; but if the error is serious,",
671 "you'd better type `E' or `X' now and fix your file.");
676 print_err("Incomplete ");
677 print_cmd_chr(if_test, cur_if);
678 prints("; all text was ignored after line ");
679 print_int(skip_line);
680 help3("A forbidden control sequence occurred in skipped text.",
681 "This kind of error happens when you say `\\if...' and forget",
682 "the matching `\\fi'. I've inserted a `\\fi'; this might work.");
687 help_line[2] = "The file ended while I was skipping conditional text.";
689 cur_tok = cs_token_flag + frozen_fi;
693 deletions_allowed = true;
697 void firm_up_the_line (void)
704 if (interaction > nonstop_mode)
710 for (k = start; k <= limit - 1; k++)
718 for (k = first; k <= last - 1; k++)
719 buffer[k + start - first] = buffer[k];
721 limit = start + last - first;
726 void get_token (void)
728 no_new_control_sequence = false;
730 no_new_control_sequence = true;
733 cur_tok = (cur_cmd * 256) + cur_chr;
735 cur_tok = cs_token_flag + cur_cs;
738 void macro_call (void)
751 small_number save_scanner_status;
752 halfword save_warning_index;
753 ASCII_code match_chr;
755 save_scanner_status = scanner_status;
756 save_warning_index = warning_index;
757 warning_index = cur_cs;
762 if (tracing_macros > 0)
766 print_cs(warning_index);
767 token_show(ref_count);
768 end_diagnostic(false);
771 if (info(r) != end_match_token)
773 scanner_status = matching;
775 long_state = eq_type(cur_cs);
777 if (long_state >= outer_call)
778 long_state = long_state - 2;
784 if ((info(r) > match_token + 255) || (info(r) < match_token))
788 match_chr = info(r) - match_token;
798 if (cur_tok == info(r))
802 if ((info(r) >= match_token) && (info(r) <= end_match_token))
804 if (cur_tok < left_brace_limit)
816 print_err("Use of ");
817 sprint_cs(warning_index);
818 prints(" doesn't match its definition");
819 help4("If you say, e.g., `\\def\\a1{...}', then you must always",
820 "put `1' after `\\a', since control sequence names are",
821 "made up of letters only. The macro here has not been",
822 "followed by the required stuff, so I'm ignoring it.");
832 store_new_token(info(t));
840 if (cur_tok != info(v))
848 if (info(u) != info(v))
862 if (cur_tok == par_token)
863 if (long_state != long_call)
865 if (long_state == call)
868 print_err("Paragraph ended before ");
869 sprint_cs(warning_index);
870 prints("was complete");
871 help3("I suspect you've forgotten a `}', causing me to apply this",
872 "control sequence to too much text. How can we recover?",
873 "My plan is to forget the whole thing and hope for the best.");
877 pstack[n] = link(temp_head);
878 align_state = align_state - unbalance;
880 for (m = 0; m <= n; m++)
881 flush_list(pstack[m]);
886 if (cur_tok < right_brace_limit)
887 if (cur_tok < left_brace_limit)
893 fast_store_new_token(cur_tok);
896 if (cur_tok == par_token)
897 if (long_state != long_call)
899 if (long_state == call)
902 print_err("Paragraph ended before ");
903 sprint_cs(warning_index);
904 prints(" was complete");
905 help3("I suspect you've forgotten a `}', causing me to apply this",
906 "control sequence to too much text. How can we recover?",
907 "My plan is to forget the whole thing and hope for the best.");
911 pstack[n] = link(temp_head);
912 align_state = align_state - unbalance;
914 for (m = 0; m <= n; m++)
915 flush_list(pstack[m]);
919 if (cur_tok < right_brace_limit)
920 if (cur_tok < left_brace_limit)
932 store_new_token(cur_tok);
937 print_err("Argument of ");
938 sprint_cs(warning_index);
939 prints(" has an extra }");
940 help6("I've run across a `}' that doesn't seem to match anything.",
941 "For example, `\\def\\a#1{...}' and `\\a}' would produce",
942 "this error. If you simply proceed now, the `\\par' that",
943 "I've just inserted will cause me to report a runaway",
944 "argument that might be the root of the problem. But if",
945 "your `}' was spurious, just type `2' and it will go away.");
954 if (cur_tok == space_token)
955 if (info(r) <= end_match_token)
956 if (info(r) >= match_token)
959 store_new_token(cur_tok);
964 if (info(r) > end_match_token)
967 if (info(r) < match_token)
972 if ((m == 1) && (info(p) < right_brace_limit) && (p != temp_head))
974 link(rbrace_ptr) = 0;
981 pstack[n] = link(temp_head);
985 if (tracing_macros > 0)
988 //print_nl(match_chr);
989 print_nl(""); print(match_chr);
992 show_token_list(pstack[n - 1], 0, 1000);
993 end_diagnostic(false);
997 while (!(info(r) == end_match_token));
1000 while ((state == token_list) && (loc == 0) &&
1001 (index != v_template))
1004 begin_token_list(ref_count, macro);
1005 name = warning_index;
1010 if (param_ptr + n > max_param_stack)
1012 max_param_stack = param_ptr + n;
1014 #ifdef ALLOCATEPARAMSTACK
1015 if (max_param_stack > current_param_size)
1016 param_stack = realloc_param_stack(increment_param_size);
1018 if (max_param_stack > current_param_size)
1020 overflow("parameter stack size", current_param_size);
1024 if (max_param_stack > param_size)
1026 overflow("parameter stack size", param_size);
1032 for (m = 0; m <= n - 1; m++)
1033 param_stack[param_ptr + m] = pstack[m];
1035 param_ptr = param_ptr + n;
1038 scanner_status = save_scanner_status;
1039 warning_index = save_warning_index;
1042 void insert_relax (void)
1044 cur_tok = cs_token_flag + cur_cs;
1046 cur_tok = cs_token_flag + frozen_relax; /* 96/Jan/10 */
1057 small_number cvl_backup, radix_backup, co_backup;
1058 halfword backup_backup;
1059 small_number save_scanner_status;
1061 cv_backup = cur_val;
1062 cvl_backup = cur_val_level;
1063 radix_backup = radix;
1064 co_backup = cur_order;
1065 backup_backup = link(backup_head);
1069 if (tracing_commands > 1)
1075 if (cur_mark[cur_chr] != 0)
1076 begin_token_list(cur_mark[cur_chr], mark_text);
1084 if (cur_cmd > max_command)
1094 save_scanner_status = scanner_status;
1095 scanner_status = normal;
1097 scanner_status = save_scanner_status;
1101 if (t >= cs_token_flag)
1104 info(p) = cs_token_flag + frozen_dont_expand;
1119 store_new_token(cur_tok);
1121 while (!(cur_cs != 0));
1123 if (cur_cmd != end_cs_name)
1125 print_err("Missing ");
1126 print_esc("endcsname");
1127 prints(" inserted");
1128 help2("The control sequence marked <to be read again> should",
1129 "not appear between \\csname and \\endcsname.");
1138 if (j >= max_buf_stack)
1140 max_buf_stack = j + 1;
1142 #ifdef ALLOCATEBUFFER
1143 if (max_buf_stack == current_buf_size)
1144 buffer = realloc_buffer (increment_buf_size);
1146 if (max_buf_stack == current_buf_size)
1148 overflow("buffer size", current_buf_size);
1152 if (max_buf_stack == buf_size)
1154 overflow("buffer size", buf_size);
1160 buffer[j] = info(p) % 256;
1167 no_new_control_sequence = false;
1168 cur_cs = id_lookup(first, j - first);
1169 no_new_control_sequence = true;
1171 else if (j == first)
1174 cur_cs = single_base + buffer[first];
1178 if (eq_type(cur_cs) == undefined_cs)
1180 eq_define(cur_cs, relax, 256);
1183 cur_tok = cur_cs + cs_token_flag;
1200 if (cur_chr > if_limit)
1205 print_err("Extra ");
1206 print_cmd_chr(fi_or_else, cur_chr);
1207 help1("I'm ignoring this; it doesn't match any \\if.");
1212 while (cur_chr != fi_code)
1217 if_line = if_line_field(p);
1218 cur_if = subtype(p);
1221 free_node(p, if_node_size);
1229 else if (name_in_progress)
1236 print_err("Undefined control sequence");
1237 help5("The control sequence at the end of the top line",
1238 "of your error message was never \\def'ed. If you have",
1239 "misspelled it (e.g., `\\hobx'), type `I' and the correct",
1240 "spelling (e.g., `I\\hbox'). Otherwise just continue,",
1241 "and I'll forget about whatever was undefined.");
1246 else if (cur_cmd < end_template)
1252 cur_tok = cs_token_flag + frozen_endv;
1256 cur_val = cv_backup;
1257 cur_val_level = cvl_backup;
1258 radix = radix_backup;
1259 cur_order = co_backup;
1260 link(backup_head) = backup_backup;
1263 void get_x_token (void)
1268 if (cur_cmd <= max_command)
1271 if (cur_cmd >= call)
1272 if (cur_cmd < end_template)
1276 cur_cs = frozen_endv;
1287 cur_tok = (cur_cmd * 256) + cur_chr;
1289 cur_tok = cs_token_flag + cur_cs;
1294 while (cur_cmd > max_command)
1301 cur_tok = (cur_cmd * 256) + cur_chr;
1303 cur_tok = cs_token_flag + cur_cs;
1306 void scan_left_brace (void)
1312 while (!((cur_cmd != spacer) && (cur_cmd != relax)));
1314 if (cur_cmd != left_brace)
1316 print_err("Missing { inserted");
1317 help4("A left brace was mandatory here, so I've put one in.",
1318 "You might want to delete and/or insert some corrections",
1319 "so that I will find a matching right brace soon.",
1320 "(If you're confused by all this, try typing `I}' now.)");
1322 cur_tok = left_brace_token + '{';
1323 cur_cmd = left_brace;
1329 void scan_optional_equals (void)
1335 while (!(cur_cmd != spacer));
1337 if (cur_tok != other_token + '=')
1341 boolean scan_keyword(const char * s)
1355 if ((cur_cs == 0) && ((cur_chr == (*k)) || (cur_chr == (*k) - 'a' + 'A')))
1357 store_new_token(cur_tok);
1360 else if ((cur_cmd != spacer) || (p != backup_head))
1364 if (p != backup_head)
1365 back_list(link(backup_head));
1371 flush_list(link(backup_head));
1376 void mu_error (void)
1378 print_err("Incompatible glue units");
1379 help1("I'm going to assume that 1mu=1pt when they're mixed.");
1383 void scan_eight_bit_int (void)
1387 if ((cur_val < 0) || (cur_val > 255))
1389 print_err("Bad register code");
1390 help2("A register number must be between 0 and 255.",
1391 "I changed this one to zero.");
1397 void scan_char_num (void)
1401 if ((cur_val < 0) || (cur_val > 255))
1403 print_err("Bad character code");
1404 help2("A character number must be between 0 and 255.",
1405 "I changed this one to zero.");
1411 void scan_four_bit_int (void)
1415 if ((cur_val < 0) || (cur_val > 15))
1417 print_err("Bad number");
1418 help2("Since I expected to read a number between 0 and 15,",
1419 "I changed this one to zero.");
1425 void scan_fifteen_bit_int (void)
1429 if ((cur_val < 0) || (cur_val > 32767))
1431 print_err("Bad mathchar");
1432 help2("A mathchar number must be between 0 and 32767.",
1433 "I changed this one to zero.");
1439 void scan_twenty_seven_bit_int (void)
1443 if ((cur_val < 0) || (cur_val > 134217727L))
1445 print_err("Bad delimiter code");
1446 help2("A numeric delimiter code must be between 0 and 2^{27}-1.",
1447 "I changed this one to zero.");
1453 void scan_font_ident (void)
1455 internal_font_number f;
1462 while (!(cur_cmd != spacer));
1464 if (cur_cmd == def_font)
1466 else if (cur_cmd == set_font)
1468 else if (cur_cmd == def_family)
1471 scan_four_bit_int();
1472 f = equiv(m + cur_val);
1476 print_err("Missing font identifier");
1477 help2("I was looking for a control sequence whose",
1478 "current meaning has been defined by \\font.");
1486 void find_font_dimen_(boolean writing)
1488 internal_font_number f;
1500 if (writing && (n <= space_shrink_code) && (n >= space_code) && (font_glue[f] != 0))
1502 delete_glue_ref(font_glue[f]);
1506 if (n > font_params[f])
1514 if (fmem_ptr == current_font_mem_size)
1515 font_info = realloc_font_info(increment_font_mem_size);
1517 if (fmem_ptr == current_font_mem_size)
1519 overflow("font memory", current_font_mem_size);
1523 if (fmem_ptr == font_mem_size)
1525 overflow("font memory", font_mem_size);
1529 font_info[fmem_ptr].cint = 0;
1531 incr(font_params[f]);
1533 while (!(n == font_params[f]));
1535 cur_val = fmem_ptr - 1;
1538 cur_val = n + param_base[f];
1541 if (cur_val == fmem_ptr)
1544 print_esc(""); print(font_id_text(f));
1545 prints(" has only ");
1546 print_int(font_params[f]);
1547 prints(" fontdimen parameters");
1548 help2("To increase the number of font parameters, you must",
1549 "use \\fontdimen immediately after the \\font is loaded.");
1554 void scan_something_internal_(small_number level, boolean negative)
1567 if (m == math_code_base)
1568 scanned_result(math_code(cur_val), int_val);
1569 else if (m < math_code_base)
1570 scanned_result(equiv(m + cur_val), int_val);
1572 scanned_result(eqtb[m + cur_val].cint, int_val);
1581 if (level != tok_val)
1583 print_err("Missing number, treated as zero");
1584 help3("A number should have been here; I inserted `0'.",
1585 "(If you can't figure out why I needed to see a number,",
1586 "look up `weird error' in the index to The TeXbook.)");
1588 scanned_result(0, dimen_val);
1590 else if (cur_cmd <= assign_toks)
1592 if (cur_cmd < assign_toks)
1594 scan_eight_bit_int();
1595 m = toks_base + cur_val;
1598 scanned_result(equiv(m), tok_val);
1604 scanned_result(font_id_base + cur_val, ident_val);
1609 scanned_result(eqtb[m].cint, int_val);
1613 scanned_result(eqtb[m].cint, dimen_val);
1617 scanned_result(equiv(m), glue_val);
1620 case assign_mu_glue:
1621 scanned_result(equiv(m), mu_val);
1627 print_err("Improper ");
1628 print_cmd_chr(set_aux, m);
1629 help4("You can refer to \\spacefactor only in horizontal mode;",
1630 "you can refer to \\prevdepth only in vertical mode; and",
1631 "neither of these is meaningful inside \\write. So",
1632 "I'm forgetting what you said and using zero instead.");
1635 if (level != tok_val)
1636 scanned_result(0, dimen_val);
1638 scanned_result(0, int_val);
1640 else if (m == vmode)
1641 scanned_result(prev_depth, dimen_val);
1643 scanned_result(space_factor, int_val);
1648 scanned_result(0, int_val);
1651 nest[nest_ptr] = cur_list;
1654 while (abs(nest[p].mode_field) != vmode)
1657 scanned_result(nest[p].pg_field, int_val);
1664 cur_val = dead_cycles;
1666 cur_val = insert_penalties;
1672 case set_page_dimen:
1674 if ((page_contents == 0) && (! output_active))
1676 cur_val = max_dimen;
1680 cur_val = page_so_far[m];
1682 cur_val_level = dimen_val;
1688 if (par_shape_ptr == 0)
1691 cur_val = info(par_shape_ptr);
1693 cur_val_level = int_val;
1699 scan_eight_bit_int();
1701 if (box(cur_val) == 0)
1704 cur_val = mem[box(cur_val) + m].cint;
1706 cur_val_level = dimen_val;
1712 scanned_result(cur_chr, int_val);
1715 case assign_font_dimen:
1717 find_font_dimen(false);
1718 font_info[fmem_ptr].cint = 0;
1719 scanned_result(font_info[cur_val].cint, dimen_val);
1723 case assign_font_int:
1728 scanned_result(hyphen_char[cur_val], int_val);
1730 scanned_result(skew_char[cur_val], int_val);
1736 scan_eight_bit_int();
1741 cur_val = count(cur_val);
1745 cur_val = dimen(cur_val);
1749 cur_val = skip(cur_val);
1753 cur_val = mu_skip(cur_val);
1762 if (cur_chr > glue_val)
1764 if (cur_chr == input_line_no_code)
1767 cur_val = last_badness;
1769 cur_val_level = int_val;
1773 if (cur_chr == glue_val)
1774 cur_val = zero_glue;
1778 cur_val_level = cur_chr;
1780 if (!is_char_node(tail) && (mode != 0))
1784 if (type(tail) == penalty_node)
1785 cur_val = penalty(tail);
1789 if (type(tail) == kern_node)
1790 cur_val = width(tail);
1794 if (type(tail) == glue_node)
1796 cur_val = glue_ptr(tail);
1798 if (subtype(tail) == mu_glue)
1799 cur_val_level = mu_val;
1803 else if ((mode == vmode) && (tail == head))
1807 cur_val = last_penalty;
1811 cur_val = last_kern;
1815 if (last_glue != empty_flag)
1816 cur_val = last_glue;
1824 print_err("You can't use `");
1825 print_cmd_chr(cur_cmd, cur_chr);
1828 help1("I'm forgetting what you said and using zero instead.");
1831 if (level != tok_val)
1832 scanned_result(0, dimen_val);
1834 scanned_result(0, int_val);
1839 while (cur_val_level > level)
1841 if (cur_val_level == glue_val)
1842 cur_val = width(cur_val);
1843 else if (cur_val_level == mu_val)
1846 decr(cur_val_level);
1850 if (cur_val_level >= 2)
1852 cur_val = new_spec(cur_val);
1855 width(cur_val) = -width(cur_val);
1856 stretch(cur_val) = -stretch(cur_val);
1857 shrink(cur_val) = -shrink(cur_val);
1862 else if ((cur_val_level >= glue_val) && (cur_val_level <= mu_val))
1863 add_glue_ref(cur_val);
1866 void get_next (void)
1878 if (state != token_list)
1883 cur_chr = buffer[loc];
1886 cur_cmd = cat_code(cur_chr);
1888 switch (state + cur_cmd)
1890 case any_state_plus(ignore):
1891 case skip_blanks + spacer:
1892 case new_line + spacer:
1896 case any_state_plus(escape):
1904 cur_chr = buffer[k];
1905 cat = cat_code(cur_chr);
1909 state = skip_blanks;
1910 else if (cat == spacer)
1911 state = skip_blanks;
1915 if ((cat == letter) && (k <= limit))
1919 cur_chr = buffer[k];
1920 cat = cat_code(cur_chr);
1923 while (!((cat != letter) || (k > limit)));
1926 if (buffer[k]== cur_chr)
1927 if (cat == sup_mark)
1947 buffer[k - 1] = cur_chr;
1950 buffer[k - 1] = c + 64;
1952 buffer[k - 1] = c - 64;
1959 buffer[k] = buffer[k + d];
1973 cur_cs = id_lookup(loc, k - loc);
1980 if (buffer[k] == cur_chr)
1981 if (cat == sup_mark)
1986 if (c < 128) /* ? */
2002 buffer[k - 1] = cur_chr;
2005 buffer[k - 1] = c + 64;
2007 buffer[k - 1] = c - 64;
2014 buffer[k] = buffer[k + d];
2021 cur_cs = single_base + buffer[loc];
2025 cur_cmd = eq_type(cur_cs);
2026 cur_chr = equiv(cur_cs);
2028 if (cur_cmd >= outer_call)
2029 check_outer_validity();
2033 case any_state_plus(active_char):
2035 cur_cs = cur_chr + active_base;
2036 cur_cmd = eq_type(cur_cs);
2037 cur_chr = equiv(cur_cs);
2040 if (cur_cmd >= outer_call)
2041 check_outer_validity();
2045 case any_state_plus(sup_mark):
2047 if (cur_chr == buffer[loc])
2050 c = buffer[loc + 1];
2082 case any_state_plus(invalid_char):
2084 print_err("Text line contains an invalid character");
2085 help2("A funny symbol that I can't read has just been input.",
2086 "Continue, and I'll forget that it ever happened.");
2087 deletions_allowed = false;
2089 deletions_allowed = true;
2094 case mid_line + spacer:
2096 state = skip_blanks;
2101 case mid_line + car_ret:
2109 case skip_blanks + car_ret:
2110 case any_state_plus(comment):
2117 case new_line + car_ret:
2121 cur_cmd = eq_type(cur_cs);
2122 cur_chr = equiv(cur_cs);
2124 if (cur_cmd >= outer_call)
2125 check_outer_validity();
2129 case mid_line + left_brace:
2133 case skip_blanks + left_brace:
2134 case new_line + left_brace:
2141 case mid_line + right_brace:
2145 case skip_blanks + right_brace:
2146 case new_line + right_brace:
2153 case add_delims_to(skip_blanks):
2154 case add_delims_to(new_line):
2173 if (input_ln(cur_file, true))
2186 check_outer_validity();
2190 if (end_line_char_inactive())
2193 buffer[limit] = end_line_char;
2213 if (selector < log_only)
2216 if (interaction > nonstop_mode)
2218 if (end_line_char_inactive())
2222 print_nl("(Please type a command or say `\\end')");
2229 if (end_line_char_inactive())
2232 buffer[limit]= end_line_char;
2239 fatal_error("*** (job aborted, no legal \\end found)");
2253 if (t >= cs_token_flag)
2255 cur_cs = t - cs_token_flag;
2256 cur_cmd = eq_type(cur_cs);
2257 cur_chr = equiv(cur_cs);
2259 if (cur_cmd >= outer_call)
2260 if (cur_cmd == dont_expand)
2262 cur_cs = info(loc) - cs_token_flag;
2264 cur_cmd = eq_type(cur_cs);
2265 cur_chr = equiv(cur_cs);
2267 if (cur_cmd > max_command)
2270 cur_chr = no_expand_flag;
2275 check_outer_validity();
2295 begin_token_list(param_stack[limit + cur_chr - 1], parameter);
2311 if (cur_cmd <= car_ret)
2312 if (cur_cmd >= tab_mark)
2313 if (align_state == 0)
2315 if ((scanner_status == aligning) && (cur_align == 0))
2317 fatal_error("(interwoven alignment preambles are not allowed)");
2321 cur_cmd = extra_info(cur_align);
2322 extra_info(cur_align) = cur_chr;
2324 if (cur_cmd == omit)
2325 begin_token_list(omit_template, v_template);
2327 begin_token_list(v_part(cur_align), v_template);
2329 align_state = 1000000L;