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)
49 if (save_type(save_ptr) == level_boundary)
52 p = save_index(save_ptr);
54 if (save_type(save_ptr) == insert_token)
63 if (save_type(save_ptr) == restore_old_value)
65 l = save_level(save_ptr);
69 save_stack[save_ptr] = eqtb[undefined_control_sequence];
72 if (eq_level(p) == level_one)
74 eq_destroy(save_stack[save_ptr]);
76 if (tracing_restores > 0)
77 restore_trace(p, "retaining");
83 eqtb[p] = save_stack[save_ptr];
85 if (tracing_restores > 0)
86 restore_trace(p, "restoring");
89 else if (xeq_level[p] != level_one)
91 eqtb[p] = save_stack[save_ptr];
94 if (tracing_restores > 0)
95 restore_trace(p, "restoring");
101 if (tracing_restores > 0)
102 restore_trace(p, "retaining");
108 cur_group = save_level(save_ptr);
109 cur_boundary = save_index(save_ptr);
113 confusion("curlevel");
114 return; // abort_flag set
117 /* This is where the old tex2.c used to start */
119 void prepare_mag (void)
121 if ((mag_set > 0) && (mag != mag_set))
123 print_err("Incompatible magnification (");
126 print_nl(" the previous value will be retained");
127 help2("I can handle only one magnification ratio per job. So I've",
128 "reverted to the magnification you used earlier on this run.");
130 geq_word_define(int_base + mag_code, mag_set);
133 if ((mag <= 0) || (mag > 32768L))
135 print_err("Illegal magnification has been changed to 1000");
136 help1("The magnification ratio must be between 1 and 32768.");
138 geq_word_define(int_base + mag_code, 1000);
144 void token_show_ (halfword p)
147 show_token_list(link(p), 0, 10000000L);
150 void print_meaning (void)
152 print_cmd_chr(cur_cmd, cur_chr);
160 else if (cur_cmd == top_bot_mark)
164 token_show(cur_mark[cur_chr]);
168 void show_cur_cmd_chr (void)
173 if (mode != shown_mode)
180 print_cmd_chr(cur_cmd, cur_chr);
182 end_diagnostic(false);
185 void show_context (void)
198 base_ptr = input_ptr;
199 input_stack[base_ptr] = cur_input;
205 cur_input = input_stack[base_ptr];
207 if ((cur_input.state_field != 0))
208 if ((cur_input.name_field > 17) || (base_ptr == 0))
211 if ((base_ptr == input_ptr) || bottomline || (nn < error_context_lines))
213 if ((base_ptr == input_ptr) || (cur_input.state_field != token_list) ||
214 (cur_input.index_field != backed_up) || (cur_input.loc_field != 0))
217 old_setting = selector;
219 if (cur_input.state_field != 0)
221 if (cur_input.name_field <= 17)
222 if ((cur_input.name_field == 0))
226 print_nl("<insert> ");
230 if (cur_input.name_field == 17)
233 print_int(cur_input.name_field - 1);
241 /* show current input file name - ignore if from terminal */
242 if (cur_input.name_field > 17) /* redundant ? */
243 print(cur_input.name_field);
246 print_int(line); /* line number */
253 print_nl("l."); /* l. ? 573 ????? 98/Dec/8 check ! */
254 print_int(line); /* line number */
264 trick_count = 1000000L;
267 if (buffer[cur_input.limit_field] == end_line_char)
268 j = cur_input.limit_field;
270 j = cur_input.limit_field + 1;
273 for (i = cur_input.start_field; i <= j - 1; i++)
275 if (i == cur_input.loc_field)
278 trick_count = tally + 1 + error_line - half_error_line;
280 if (trick_count < error_line)
281 trick_count = error_line;
288 switch (cur_input.index_field)
291 print_nl("<argument> ");
296 print_nl("<template> ");
300 if (cur_input.loc_field == 0)
301 print_nl("<recently read> ");
303 print_nl("<to be read again> ");
307 print_nl("<inserted text> ");
312 print_cs(cur_input.name_field);
316 print_nl("<output> ");
320 print_nl("<everypar> ");
323 case every_math_text:
324 print_nl("<everymath> ");
327 case every_display_text:
328 print_nl("<everydisplay> ");
331 case every_hbox_text:
332 print_nl("<everyhbox> ");
335 case every_vbox_text:
336 print_nl("<everyvbox> ");
340 print_nl("<everyjob> ");
344 print_nl("<everycr> ");
352 print_nl("<write> ");
364 trick_count = 1000000L;
367 if (cur_input.index_field < macro)
368 show_token_list(cur_input.start_field, cur_input.loc_field, 100000L);
370 show_token_list(link(cur_input.start_field), cur_input.loc_field, 100000L);
373 selector = old_setting;
375 if (trick_count == 1000000L)
378 trick_count = tally + 1 + error_line - half_error_line;
380 if (trick_count < error_line)
381 trick_count = error_line;
384 if (tally < trick_count)
385 m = tally - first_count;
387 m = trick_count - first_count;
389 if (l + first_count <= half_error_line)
397 p = l + first_count - half_error_line + 3;
401 for (q = p; q <= first_count - 1; q++)
402 print_char(trick_buf[q % error_line]);
406 for (q = 1; q <= n; q++)
409 if (m + n <= error_line)
412 p = first_count +(error_line - n - 3);
414 for (q = first_count; q <= p - 1; q++)
415 print_char(trick_buf[q % error_line]);
417 if (m + n > error_line)
422 else if (nn == error_context_lines)
434 cur_input = input_stack[input_ptr];
436 //#pragma optimize("g", off) /* 98/Dec/10 experiment */
438 void begin_token_list_ (halfword p, quarterword t)
441 if (input_ptr > max_in_stack)
443 max_in_stack = input_ptr;
445 #ifdef ALLOCATEINPUTSTACK
446 if (input_ptr == current_stack_size)
447 input_stack = realloc_input_stack(increment_stack_size);
449 if (input_ptr == current_stack_size) /* check again after allocation */
451 overflow("input stack size", current_stack_size);
452 return; // abort_flag set
455 if (input_ptr == stack_size) /* input stack - not dynamic */
457 overflow("input stack size", stack_size);
458 return; // abort_flag set
463 input_stack[input_ptr] = cur_input;
467 cur_input.state_field = token_list;
468 cur_input.start_field = p;
469 cur_input.index_field = t;
476 cur_input.limit_field = param_ptr;
479 cur_input.loc_field = link(p);
481 if (tracing_macros > 1)
497 print_cmd_chr(assign_toks, t - output_text + output_routine_loc);
503 end_diagnostic(false);
508 cur_input.loc_field = p;
510 //#pragma optimize("", on) /* 98/Dec/10 experiment */
512 void end_token_list (void)
514 if (cur_input.index_field >= backed_up)
516 if (cur_input.index_field <= inserted)
517 flush_list(cur_input.start_field);
520 delete_token_ref(cur_input.start_field);
521 if (cur_input.index_field == macro)
522 while (param_ptr > cur_input.limit_field)
525 flush_list(param_stack[param_ptr]);
529 else if (cur_input.index_field == u_template)
530 if (align_state > 500000L)
534 fatal_error("(interwoven alignment preambles are not allowed)");
535 return; // abort_flag set
540 cur_input = input_stack[input_ptr];
546 pause_for_instructions();
551 void back_input (void)
555 while ((cur_input.state_field == 0) && (cur_input.loc_field == 0) &&
556 (cur_input.index_field != v_template))
564 if (cur_tok < right_brace_limit)
565 if (cur_tok < left_brace_limit)
571 if (input_ptr > max_in_stack)
573 max_in_stack = input_ptr;
574 #ifdef ALLOCATEINPUTSTACK
575 if (input_ptr == current_stack_size)
576 input_stack = realloc_input_stack(increment_stack_size);
578 if (input_ptr == current_stack_size) /* check again after allocation */
580 overflow("input stack size", current_stack_size);
581 return; // abort_flag set
584 if (input_ptr == stack_size) /* stack size - not dynamic */
586 overflow("input stack size", stack_size);
587 return; // abort_flag set
591 input_stack[input_ptr] = cur_input;
595 cur_input.state_field = token_list;
596 cur_input.start_field = p;
597 cur_input.index_field = backed_up;
598 cur_input.loc_field = p;
601 void back_error (void)
603 OK_to_interrupt = false;
605 OK_to_interrupt = true;
609 void ins_error (void)
611 OK_to_interrupt = false;
613 cur_input.index_field = inserted;
614 OK_to_interrupt = true;
618 void begin_file_reading (void)
620 if (in_open == max_in_open)
622 overflow("text input levels", max_in_open); /* text input levels - NOT DYNAMIC */
623 return; // abort_flag set
625 #ifdef ALLOCATEBUFFER
626 if (first == current_buf_size)
627 buffer = realloc_buffer(increment_buf_size);
629 if (first == current_buf_size) /* check again after allocation */
631 overflow("buffer size", current_buf_size);
632 return; // abort_flag set
635 if (first == buf_size)
637 overflow("buffer size", buf_size); /* buffer size - not dynamic */
638 return; // abort_flag set
642 if (in_open > high_in_open) /* 1999 Jan 17 */
643 high_in_open = in_open;
645 if (input_ptr > max_in_stack)
647 max_in_stack = input_ptr;
648 #ifdef ALLOCATEINPUTSTACK
649 if (input_ptr == current_stack_size)
650 input_stack = realloc_input_stack(increment_stack_size);
651 if (input_ptr == current_stack_size)
653 overflow("input stack size", current_stack_size); /* check again after allocation */
654 return; // abort_flag set
657 if (input_ptr == stack_size)
659 overflow("input stack size", stack_size); /* input stack - not dynamic */
660 return; // abort_flag set
664 input_stack[input_ptr] = cur_input;
667 cur_input.index_field = in_open;
668 line_stack[cur_input.index_field] = line;
669 cur_input.start_field = first;
670 cur_input.state_field = 1;
671 cur_input.name_field = 0;
674 void end_file_reading (void)
676 first = cur_input.start_field;
677 line = line_stack[cur_input.index_field];
679 if (cur_input.name_field > 17)
680 (void) a_close(input_file[cur_input.index_field]);
684 cur_input = input_stack[input_ptr];
688 /* called only form tex0.c */
690 void clear_for_error_prompt (void)
692 while ((cur_input.state_field != 0) &&
693 (cur_input.name_field == 0) && (input_ptr > 0) &&
694 (cur_input.loc_field > cur_input.limit_field))
700 void check_outer_validity (void)
705 if (scanner_status != 0)
707 deletions_allowed = false;
711 if ((cur_input.state_field == 0) || (cur_input.name_field < 1) || (cur_input.name_field > 17))
714 info(p) = cs_token_flag + cur_cs;
722 if (scanner_status > skipping)
727 print_err("File ended");
731 print_err("Forbidden control sequence found");
734 print_string(" while scanning ");
737 switch (scanner_status)
740 print_string("definition");
741 info(p) = right_brace_token + '}';
747 long_state = outer_call;
751 print_string("preamble");
752 info(p) = right_brace_token + '}';
756 info(p) = cs_token_flag + frozen_cr; /*96/Jan/10*/
757 align_state = -1000000L;
761 print_string("text");
762 info(p) = right_brace_token + '}';
766 print_string(" of ");
767 sprint_cs(warning_index);
768 help4("I suspect you have forgotten a `}', causing me",
769 "to read past where you wanted me to stop.",
770 "I'll try to recover; but if the error is serious,",
771 "you'd better type `E' or `X' now and fix your file.");
776 print_err("Incomplete ");
777 print_cmd_chr(if_test, cur_if);
778 print_string("; all text was ignored after line ");
779 print_int(skip_line);
780 help3("A forbidden control sequence occurred in skipped text.",
781 "This kind of error happens when you say `\\if...' and forget",
782 "the matching `\\fi'. I've inserted a `\\fi'; this might work.");
787 help_line[2] = "The file ended while I was skipping conditional text.";
789 cur_tok = cs_token_flag + frozen_fi; /* 96/Jan/10 */
792 deletions_allowed = true;
795 /*****************************************************************************/
796 /* get_next() moved from here to end for pragma optimize reasons 96/Sep/12 */
798 /*****************************************************************************/
800 void firm_up_the_line (void)
804 cur_input.limit_field = last;
807 if (interaction > nonstop_mode)
812 if (cur_input.start_field < cur_input.limit_field)
813 for (k = cur_input.start_field; k <= cur_input.limit_field - 1; k++)
816 first = cur_input.limit_field;
821 for (k = first; k <= last - 1; k++)
822 buffer[k + cur_input.start_field - first] = buffer[k];
824 cur_input.limit_field = cur_input.start_field + last - first;
829 void get_token (void)
831 no_new_control_sequence = false;
833 no_new_control_sequence = true;
836 cur_tok = (cur_cmd * 256) + cur_chr;
838 cur_tok = cs_token_flag + cur_cs;
841 void macro_call (void)
854 small_number savescannerstatus;
855 halfword savewarningindex;
856 ASCII_code match_chr;
858 savescannerstatus = scanner_status;
859 savewarningindex = warning_index;
860 warning_index = cur_cs;
865 if (tracing_macros > 0)
869 print_cs(warning_index);
870 token_show(refcount);
871 end_diagnostic(false);
874 if (info(r) != end_match_token)
876 scanner_status = matching;
878 long_state = eq_type(cur_cs);
880 if (long_state >= outer_call)
881 long_state = long_state - 2;
887 if ((info(r) > match_token + 255) || (info(r) < match_token))
891 match_chr = info(r) - match_token;
900 if (cur_tok == info(r))
904 if ((info(r) >= match_token) && (info(r) <= end_match_token))
906 if (cur_tok < left_brace_limit)
918 print_err("Use of ");
919 sprint_cs(warning_index);
920 print_string(" doesn't match its definition");
921 help4("If you say, e.g., `\\def\\a1{...}', then you must always",
922 "put `1' after `\\a', since control sequence names are",
923 "made up of letters only. The macro here has not been",
924 "followed by the required stuff, so I'm ignoring it.");
933 store_new_token(info(t));
941 if (cur_tok != info(v))
949 if (info(u) != info(v))
963 if (cur_tok == par_token)
964 if (long_state != long_call)
966 if (long_state == call)
969 print_err("Paragraph ended before ");
970 sprint_cs(warning_index);
971 print_string("was complete");
972 help3("I suspect you've forgotten a `}', causing me to apply this",
973 "control sequence to too much text. How can we recover?",
974 "My plan is to forget the whole thing and hope for the best.");
978 pstack[n] = link(temp_head);
979 align_state = align_state - unbalance;
981 for (m = 0; m <= n; m++)
982 flush_list(pstack[m]);
987 if (cur_tok < right_brace_limit)
988 if (cur_tok < left_brace_limit)
994 fast_store_new_token(cur_tok);
997 if (cur_tok == par_token)
998 if (long_state != long_call)
1000 if (long_state == call)
1003 print_err("Paragraph ended before ");
1004 sprint_cs(warning_index);
1005 print_string(" was complete");
1006 help3("I suspect you've forgotten a `}', causing me to apply this",
1007 "control sequence to too much text. How can we recover?",
1008 "My plan is to forget the whole thing and hope for the best.");
1012 pstack[n] = link(temp_head);
1013 align_state = align_state - unbalance;
1015 for (m = 0; m <= n; m++)
1016 flush_list(pstack[m]);
1020 if (cur_tok < right_brace_limit)
1021 if (cur_tok < left_brace_limit)
1033 store_new_token(cur_tok);
1038 print_err("Argument of ");
1039 sprint_cs(warning_index);
1040 print_string(" has an extra }");
1041 help6("I've run across a `}' that doesn't seem to match anything.",
1042 "For example, `\\def\\a#1{...}' and `\\a}' would produce",
1043 "this error. If you simply proceed now, the `\\par' that",
1044 "I've just inserted will cause me to report a runaway",
1045 "argument that might be the root of the problem. But if",
1046 "your `}' was spurious, just type `2' and it will go away.");
1049 cur_tok = par_token;
1055 if (cur_tok == space_token)
1056 if (info(r) <= end_match_token)
1057 if (info(r) >= match_token)
1060 store_new_token(cur_tok);
1063 incr(m); /* m may be used without having been ... */
1065 if (info(r) > end_match_token)
1068 if (info(r) < match_token)
1073 if ((m == 1) && (info(p) < right_brace_limit) && (p != temp_head))
1075 link(rbraceptr) = 0; /* rbraceptr may be used without ... */
1077 p = link(temp_head);
1078 pstack[n] = link(p);
1082 pstack[n] = link(temp_head);
1086 if (tracing_macros > 0)
1089 //print_nl(match_chr); /* matchchar may be used without ... */
1090 print_nl(""); print(match_chr);
1093 show_token_list(pstack[n - 1], 0, 1000);
1094 end_diagnostic(false);
1098 while(!(info(r) == end_match_token));
1101 while((cur_input.state_field == token_list) && (cur_input.loc_field == 0) &&
1102 (cur_input.index_field != v_template))
1105 begin_token_list(refcount, macro);
1106 cur_input.name_field = warning_index;
1107 cur_input.loc_field = link(r);
1111 if (param_ptr + n > max_param_stack)
1113 max_param_stack = param_ptr + n;
1115 #ifdef ALLOCATEPARAMSTACK
1116 if (max_param_stack > current_param_size)
1117 param_stack = realloc_param_stack(increment_param_size);
1119 if (max_param_stack > current_param_size) /* check again after allocation */
1121 overflow("parameter stack size", current_param_size);
1122 return; // abort_flag set
1125 if (max_param_stack > param_size)
1127 overflow("parameter stack size", param_size); /* parameter stack - not dynamic */
1128 return; // abort_flag set
1133 for (m = 0; m <= n - 1; m++)
1134 param_stack[param_ptr + m] = pstack[m];
1136 param_ptr = param_ptr + n;
1139 scanner_status = savescannerstatus;
1140 warning_index = savewarningindex;
1143 void insert_relax (void)
1145 cur_tok = cs_token_flag + cur_cs;
1147 cur_tok = cs_token_flag + frozen_relax; /* 96/Jan/10 */
1149 cur_input.index_field = inserted;
1158 small_number cvlbackup, radixbackup, cobackup;
1159 halfword backupbackup;
1160 small_number savescannerstatus;
1163 cvlbackup = cur_val_level;
1164 radixbackup = radix;
1165 cobackup = cur_order;
1166 backupbackup = link(backup_head);
1170 if (tracing_commands > 1)
1176 if (cur_mark[cur_chr] != 0)
1177 begin_token_list(cur_mark[cur_chr], mark_text);
1185 if (cur_cmd > max_command)
1195 savescannerstatus = scanner_status;
1196 scanner_status = normal;
1198 scanner_status = savescannerstatus;
1202 if (t >= cs_token_flag)
1205 info(p) = cs_token_flag + frozen_dont_expand; /*96/Jan/10*/
1206 link(p) = cur_input.loc_field;
1207 cur_input.start_field = p;
1208 cur_input.loc_field = p;
1220 store_new_token(cur_tok);
1222 while(!(cur_cs != 0));
1224 if (cur_cmd != end_cs_name)
1226 print_err("Missing ");
1227 print_esc("endcsname");
1228 print_string(" inserted");
1229 help2("The control sequence marked <to be read again> should",
1230 "not appear between \\csname and \\endcsname.");
1239 if (j >= max_buf_stack)
1241 max_buf_stack = j + 1;
1243 #ifdef ALLOCATEBUFFER
1244 if (max_buf_stack == current_buf_size)
1245 buffer = realloc_buffer (increment_buf_size);
1247 if (max_buf_stack == current_buf_size) /* check again after allocation */
1249 overflow("buffer size", current_buf_size);
1250 return; // abort_flag set
1253 if (max_buf_stack == buf_size)
1255 overflow("buffer size", buf_size); /* buffer size - not dynamic */
1256 return; // abort_flag set
1261 buffer[j] = info(p) % 256;
1268 no_new_control_sequence = false;
1269 cur_cs = id_lookup(first, j - first);
1270 no_new_control_sequence = true;
1272 else if (j == first)
1275 cur_cs = single_base + buffer[first];
1279 if (eq_type(cur_cs) == undefined_cs)
1281 eq_define(cur_cs, relax, 256);
1284 cur_tok = cur_cs + cs_token_flag;
1301 if (cur_chr > if_limit)
1306 print_err("Extra ");
1307 print_cmd_chr(fi_or_else, cur_chr);
1308 help1("I'm ignoring this; it doesn't match any \\if.");
1313 while(cur_chr != fi_code)
1318 if_line = if_line_field(p);
1319 cur_if = subtype(p);
1322 free_node(p, if_node_size);
1330 else if (name_in_progress)
1337 print_err("Undefined control sequence");
1338 help5("The control sequence at the end of the top line",
1339 "of your error message was never \\def'ed. If you have",
1340 "misspelled it (e.g., `\\hobx'), type `I' and the correct",
1341 "spelling (e.g., `I\\hbox'). Otherwise just continue,",
1342 "and I'll forget about whatever was undefined.");
1347 else if (cur_cmd < end_template)
1353 cur_tok = cs_token_flag + frozen_endv; /* 96/Jan/10 */
1358 cur_val_level = cvlbackup;
1359 radix = radixbackup;
1360 cur_order = cobackup;
1361 link(backup_head) = backupbackup;
1364 void get_x_token (void)
1369 if (cur_cmd <= max_command)
1371 if (cur_cmd >= call)
1372 if (cur_cmd < end_template)
1376 cur_cs = frozen_endv; /* 96/Jan/10 */
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)
1527 if ((cur_val < 0) || (cur_val > 32767))
1529 print_err("Bad mathchar");
1530 help2("A mathchar number must be between 0 and 32767.",
1531 "I changed this one to zero.");
1537 void scan_twenty_seven_bit_int (void)
1541 if ((cur_val < 0) || (cur_val > 134217727L)) /* 2^27 - 1 */
1543 print_err("Bad delimiter code");
1544 help2("A numeric delimiter code must be between 0 and 2^{27}-1.",
1545 "I changed this one to zero.");
1551 void scan_font_ident (void)
1553 internal_font_number f;
1560 while (!(cur_cmd != spacer));
1562 if (cur_cmd == def_font)
1564 else if (cur_cmd == set_font)
1566 else if (cur_cmd == def_family)
1569 scan_four_bit_int();
1570 f = equiv(m + cur_val);
1574 print_err("Missing font identifier");
1575 help2("I was looking for a control sequence whose",
1576 "current meaning has been defined by \\font.");
1584 void find_font_dimen_(boolean writing)
1586 internal_font_number f;
1594 if (n < 0 || (n == 0 && font_dimen_zero == 0)) /* change 98/Oct/5 */
1598 if (writing && (n <= space_shrink_code) && (n >= space_code) && (font_glue[f] != 0))
1600 delete_glue_ref(font_glue[f]);
1604 if (n > font_params[f])
1612 if (fmem_ptr == current_font_mem_size) /* 93/Nov/28 ??? */
1614 font_info = realloc_font_info(increment_font_mem_size);
1617 if (fmem_ptr == current_font_mem_size) /* 94/Jan/24 */
1619 overflow("font memory", current_font_mem_size); /* font memory */
1620 return; // abort_flag set
1623 if (fmem_ptr == font_mem_size)
1625 overflow("font memory", font_mem_size); /* font memory */
1626 return; // abort_flag set
1629 font_info[fmem_ptr].cint = 0;
1631 incr(font_params[f]);
1633 while(!(n == font_params[f]));
1635 cur_val = fmem_ptr - 1;
1638 cur_val = n + param_base[f];
1641 if (cur_val == fmem_ptr)
1644 print_esc(""); print(font_id_text(f));
1645 print_string(" has only ");
1646 print_int(font_params[f]);
1647 print_string(" fontdimen parameters");
1648 help2("To increase the number of font parameters, you must",
1649 "use \\fontdimen immediately after the \\font is loaded.");
1654 void scan_something_internal_(small_number level, boolean negative)
1667 if (m == math_code_base)
1669 cur_val = math_code(cur_val);
1670 cur_val_level = int_val;
1672 else if (m < math_code_base)
1674 cur_val = equiv(m + cur_val);
1675 cur_val_level = int_val;
1679 cur_val = eqtb[m + cur_val].cint;
1680 cur_val_level = int_val;
1690 if (level != tok_val)
1692 print_err("Missing number, treated as zero");
1693 help3("A number should have been here; I inserted `0'.",
1694 "(If you can't figure out why I needed to see a number,",
1695 "look up `weird error' in the index to The TeXbook.)");
1699 cur_val_level = dimen_val;
1702 else if (cur_cmd <= assign_toks)
1704 if (cur_cmd < assign_toks)
1706 scan_eight_bit_int();
1707 m = toks_base + cur_val;
1711 cur_val = eqtb[m].hh.rh;
1712 cur_val_level = tok_val;
1721 cur_val = font_id_base + cur_val;
1722 cur_val_level = ident_val;
1729 cur_val = eqtb[m].cint;
1730 cur_val_level = int_val;
1736 cur_val = eqtb[m].cint;
1737 cur_val_level = dimen_val;
1743 cur_val = eqtb[m].hh.rh;
1744 cur_val_level = glue_val;
1748 case assign_mu_glue:
1750 cur_val = eqtb[m].hh.rh;
1751 cur_val_level = mu_val;
1758 print_err("Improper ");
1759 print_cmd_chr(set_aux, m);
1760 help4("You can refer to \\spacefactor only in horizontal mode;",
1761 "you can refer to \\prevdepth only in vertical mode; and",
1762 "neither of these is meaningful inside \\write. So",
1763 "I'm forgetting what you said and using zero instead.");
1766 if (level != tok_val)
1769 cur_val_level = dimen_val;
1774 cur_val_level = int_val;
1777 else if (m == vmode)
1779 cur_val = cur_list.aux_field.cint;
1780 cur_val_level = dimen_val;
1784 cur_val = space_factor;
1785 cur_val_level = int_val;
1793 cur_val_level = int_val;
1797 nest[nest_ptr] = cur_list;
1800 while (abs(nest[p].mode_field) != vmode)
1804 cur_val = nest[p].pg_field;
1805 cur_val_level = int_val;
1813 cur_val = dead_cycles;
1815 cur_val = insert_penalties;
1821 case set_page_dimen:
1823 if ((page_contents == 0) && (! output_active))
1825 cur_val = 1073741823L; /* 2^30 - 1 */
1829 cur_val = page_so_far[m];
1831 cur_val_level = dimen_val;
1837 if (par_shape_ptr == 0)
1840 cur_val = info(par_shape_ptr);
1842 cur_val_level = int_val;
1848 scan_eight_bit_int();
1850 if (box(cur_val) == 0)
1853 cur_val = mem[box(cur_val) + m].cint;
1855 cur_val_level = dimen_val;
1863 cur_val_level = int_val;
1867 case assign_font_dimen:
1869 find_font_dimen(false);
1870 font_info[fmem_ptr].cint = 0;
1872 cur_val = font_info[cur_val].cint;
1873 cur_val_level = dimen_val;
1878 case assign_font_int:
1884 cur_val = hyphen_char[cur_val];
1885 cur_val_level = int_val;
1889 cur_val = skew_char[cur_val];
1890 cur_val_level = int_val;
1897 scan_eight_bit_int();
1902 cur_val = count(cur_val);
1906 cur_val = dimen(cur_val);
1910 cur_val = skip(cur_val);
1914 cur_val = mu_skip(cur_val);
1923 if (cur_chr > glue_val)
1925 if (cur_chr == input_line_no_code)
1928 cur_val = last_badness;
1930 cur_val_level = int_val;
1934 if (cur_chr == glue_val)
1935 cur_val = zero_glue;
1939 cur_val_level = cur_chr;
1941 if (!(tail >= hi_mem_min) && (mode != 0))
1945 if (type(tail) == penalty_node)
1946 cur_val = penalty(tail);
1950 if (type(tail) == kern_node)
1951 cur_val = width(tail);
1955 if (type(tail) == glue_node)
1957 cur_val = glue_ptr(tail);
1959 if (subtype(tail) == mu_glue)
1960 cur_val_level = mu_val;
1964 else if ((mode == 1) && (tail == cur_list.head_field))
1968 cur_val = last_penalty;
1972 cur_val = last_kern;
1976 if (last_glue != empty_flag)
1977 cur_val = last_glue;
1985 print_err("You can't use `");
1986 print_cmd_chr(cur_cmd, cur_chr);
1987 print_string("' after ");
1989 help1("I'm forgetting what you said and using zero instead.");
1992 if (level != tok_val)
1995 cur_val_level = dimen_val;
2000 cur_val_level = int_val;
2006 while (cur_val_level > level)
2008 if (cur_val_level == glue_val)
2009 cur_val = width(cur_val);
2010 else if (cur_val_level == mu_val)
2013 decr(cur_val_level);
2017 if (cur_val_level >= 2)
2019 cur_val = new_spec(cur_val);
2022 width(cur_val) = - (integer) width(cur_val);
2023 stretch(cur_val) = - (integer) stretch(cur_val);
2024 shrink(cur_val) = - (integer) shrink(cur_val);
2028 cur_val = - (integer) cur_val;
2029 else if ((cur_val_level >= glue_val) && (cur_val_level <= mu_val))
2030 add_glue_ref(cur_val);
2033 void get_next (void)
2037 /* char cat; */ /* make this an int ? */
2038 int cat; /* make this an int ? 95/Jan/7 */
2045 if (cur_input.state_field != token_list)
2048 if (cur_input.loc_field <= cur_input.limit_field)
2050 cur_chr = buffer[cur_input.loc_field];
2051 incr(cur_input.loc_field);
2053 cur_cmd = cat_code(cur_chr);
2055 switch (cur_input.state_field + cur_cmd)
2057 case any_state_plus(ignore):
2058 case skip_blanks + spacer:
2059 case new_line + spacer:
2063 case any_state_plus(escape):
2065 if (cur_input.loc_field > cur_input.limit_field)
2070 k = cur_input.loc_field;
2071 cur_chr = buffer[k];
2072 cat = cat_code(cur_chr);
2076 cur_input.state_field = skip_blanks;
2077 else if (cat == spacer)
2078 cur_input.state_field = skip_blanks;
2080 cur_input.state_field = mid_line;
2082 if ((cat == letter) && (k <= cur_input.limit_field))
2086 cur_chr = buffer[k];
2087 cat = cat_code(cur_chr);
2090 while(!((cat != letter) || (k > cur_input.limit_field)));
2093 if (buffer[k]== cur_chr)
2094 if (cat == sup_mark)
2095 if (k < cur_input.limit_field)
2102 if ((((c >= 48) && (c <= 57)) || ((c >= 97) && (c <= 102))))
2103 if (k + 2 <= cur_input.limit_field)
2107 if ((((cc >= 48) && (cc <= 57)) || ((cc >= 97) && (cc <= 102))))
2119 cur_chr = 16 * cur_chr + cc - 48;
2121 cur_chr = 16 * cur_chr + cc - 87;
2123 buffer[k - 1] = cur_chr;
2126 buffer[k - 1] = c + 64;
2128 buffer[k - 1] = c - 64;
2130 cur_input.limit_field = cur_input.limit_field - d;
2133 while (k <= cur_input.limit_field)
2135 buffer[k] = buffer[k + d];
2147 if (k > cur_input.loc_field + 1)
2149 cur_cs = id_lookup(cur_input.loc_field, k - cur_input.loc_field);
2150 cur_input.loc_field = k;
2156 if (buffer[k] == cur_chr)
2157 if (cat == sup_mark)
2158 if (k < cur_input.limit_field)
2162 if (c < 128) /* ? */
2165 if ((((c >= 48) && (c <= 57)) || ((c >= 97) && (c <= 102))))
2166 if (k + 2 <= cur_input.limit_field)
2170 if ((((cc >= 48) && (cc <= 57)) || ((cc >= 97) && (cc <= 102))))
2181 if (cc <= 57) /* cc may be used without ... */
2182 cur_chr = 16 * cur_chr + cc - 48;
2184 cur_chr = 16 * cur_chr + cc - 87;
2186 buffer[k - 1] = cur_chr;
2189 buffer[k - 1] = c + 64;
2191 buffer[k - 1] = c - 64;
2193 cur_input.limit_field = cur_input.limit_field - d;
2196 while (k <= cur_input.limit_field)
2198 buffer[k] = buffer[k + d];
2205 cur_cs = single_base + buffer[cur_input.loc_field];
2206 incr(cur_input.loc_field);
2209 cur_cmd = eq_type(cur_cs);
2210 cur_chr = equiv(cur_cs);
2212 if (cur_cmd >= outer_call)
2213 check_outer_validity();
2217 case any_state_plus(active_char):
2219 cur_cs = cur_chr + active_base;
2220 cur_cmd = eq_type(cur_cs);
2221 cur_chr = equiv(cur_cs);
2222 cur_input.state_field = mid_line;
2224 if (cur_cmd >= outer_call)
2225 check_outer_validity();
2229 case any_state_plus(sup_mark):
2231 if (cur_chr == buffer[cur_input.loc_field])
2232 if (cur_input.loc_field < cur_input.limit_field)
2234 c = buffer[cur_input.loc_field + 1];
2238 cur_input.loc_field = cur_input.loc_field + 2;
2240 if ((((c >= 48) && (c <= 57)) || ((c >= 97) && (c <= 102))))
2241 if (cur_input.loc_field <= cur_input.limit_field)
2243 cc = buffer[cur_input.loc_field];
2245 if ((((cc >= 48) && (cc <= 57)) || ((cc >= 97) && (cc <= 102))))
2247 incr(cur_input.loc_field);
2255 cur_chr = 16 * cur_chr + cc - 48;
2257 cur_chr = 16 * cur_chr + cc - 87;
2272 cur_input.state_field = mid_line;
2276 case any_state_plus(invalid_char):
2278 print_err("Text line contains an invalid character");
2279 help2("A funny symbol that I can't read has just been input.",
2280 "Continue, and I'll forget that it ever happened.");
2281 deletions_allowed = false;
2283 deletions_allowed = true;
2288 case mid_line + spacer:
2290 cur_input.state_field = skip_blanks;
2295 case mid_line + car_ret:
2297 cur_input.loc_field = cur_input.limit_field + 1;
2303 case skip_blanks + car_ret:
2304 case any_state_plus(comment):
2306 cur_input.loc_field = cur_input.limit_field + 1;
2311 case new_line + car_ret:
2313 cur_input.loc_field = cur_input.limit_field + 1;
2315 cur_cmd = eq_type(cur_cs);
2316 cur_chr = equiv(cur_cs);
2318 if (cur_cmd >= outer_call)
2319 check_outer_validity();
2323 case mid_line + left_brace:
2327 case skip_blanks + left_brace:
2328 case new_line + left_brace:
2330 cur_input.state_field = mid_line;
2335 case mid_line + right_brace:
2339 case skip_blanks + right_brace:
2340 case new_line + right_brace:
2342 cur_input.state_field = 1;
2347 case add_delims_to(skip_blanks):
2348 case add_delims_to(new_line):
2349 cur_input.state_field = 1;
2358 cur_input.state_field = new_line;
2360 if (cur_input.name_field > 17)
2363 first = cur_input.start_field;
2367 if (input_ln(input_file[cur_input.index_field], true))
2382 check_outer_validity();
2386 if ((end_line_char < 0) || (end_line_char > 255))
2387 decr(cur_input.limit_field);
2389 buffer[cur_input.limit_field] = end_line_char;
2391 first = cur_input.limit_field + 1;
2392 cur_input.loc_field = cur_input.start_field;
2396 if (!(cur_input.name_field == 0))
2409 if (selector < log_only)
2412 if (interaction > nonstop_mode)
2414 if ((end_line_char < 0) || (end_line_char > 255))
2415 incr(cur_input.limit_field);
2417 if (cur_input.limit_field == cur_input.start_field)
2418 print_nl("(Please type a command or say `\\end')");
2421 first = cur_input.start_field;
2423 cur_input.limit_field = last;
2425 if ((end_line_char < 0) || (end_line_char > 255))
2426 decr(cur_input.limit_field);
2428 buffer[cur_input.limit_field]= end_line_char;
2430 first = cur_input.limit_field + 1;
2431 cur_input.loc_field = cur_input.start_field;
2435 fatal_error("*** (job aborted, no legal \\end found)");
2436 return; // abort_flag set
2443 pause_for_instructions();
2450 else if (cur_input.loc_field != 0)
2452 t = info(cur_input.loc_field);
2453 cur_input.loc_field = link(cur_input.loc_field);
2455 if (t >= cs_token_flag)
2457 cur_cs = t - cs_token_flag;
2458 cur_cmd = eq_type(cur_cs);
2459 cur_chr = equiv(cur_cs);
2461 if (cur_cmd >= outer_call)
2462 if (cur_cmd == dont_expand)
2464 cur_cs = info(cur_input.loc_field) - cs_token_flag;
2465 cur_input.loc_field = 0;
2466 cur_cmd = eq_type(cur_cs);
2467 cur_chr = equiv(cur_cs);
2469 if (cur_cmd > max_command)
2472 cur_chr = no_expand_flag;
2477 check_outer_validity();
2497 begin_token_list(param_stack[cur_input.limit_field + cur_chr - 1], parameter);
2513 if (cur_cmd <= car_ret)
2514 if (cur_cmd >= tab_mark)
2515 if (align_state == 0)
2517 if ((scanner_status == aligning) && (cur_align == 0))
2519 fatal_error("(interwoven alignment preambles are not allowed)");
2520 return; // abort_flag set
2523 cur_cmd = extra_info(cur_align);
2524 extra_info(cur_align) = cur_chr;
2526 if (cur_cmd == omit)
2527 begin_token_list(omit_template, v_template);
2529 begin_token_list(v_part(cur_align), v_template);
2531 align_state = 1000000L;