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 + (hash_size + 1307));
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;
826 for (k = first; k <= last - 1; k++)
827 buffer[k + cur_input.start_field - first] = buffer[k];
829 cur_input.limit_field = cur_input.start_field + last - first;
834 void get_token (void)
836 no_new_control_sequence = false;
838 no_new_control_sequence = true;
841 cur_tok = (cur_cmd * 256) + cur_chr;
843 cur_tok = cs_token_flag + cur_cs;
846 void macro_call (void)
859 small_number savescannerstatus;
860 halfword savewarningindex;
861 ASCII_code match_chr;
863 savescannerstatus = scanner_status;
864 savewarningindex = warning_index;
865 warning_index = cur_cs;
870 if (tracing_macros > 0)
874 print_cs(warning_index);
875 token_show(refcount);
876 end_diagnostic(false);
879 if (info(r) != end_match_token)
881 scanner_status = matching;
883 long_state = eq_type(cur_cs);
885 if (long_state >= outer_call)
886 long_state = long_state - 2;
892 if ((info(r) > match_token + 255) || (info(r) < match_token))
896 match_chr = info(r) - match_token;
905 if (cur_tok == info(r))
909 if ((info(r) >= match_token) && (info(r) <= end_match_token))
911 if (cur_tok < left_brace_limit)
923 print_err("Use of ");
924 sprint_cs(warning_index);
925 print_string(" doesn't match its definition");
926 help4("If you say, e.g., `\\def\\a1{...}', then you must always",
927 "put `1' after `\\a', since control sequence names are",
928 "made up of letters only. The macro here has not been",
929 "followed by the required stuff, so I'm ignoring it.");
938 store_new_token(info(t));
946 if (cur_tok != info(v))
954 if (info(u) != info(v))
968 if (cur_tok == par_token)
969 if (long_state != long_call)
971 if (long_state == call)
974 print_err("Paragraph ended before ");
975 sprint_cs(warning_index);
976 print_string("was complete");
977 help3("I suspect you've forgotten a `}', causing me to apply this",
978 "control sequence to too much text. How can we recover?",
979 "My plan is to forget the whole thing and hope for the best.");
983 pstack[n] = link(temp_head);
984 align_state = align_state - unbalance;
986 for (m = 0; m <= n; m++)
987 flush_list(pstack[m]);
992 if (cur_tok < right_brace_limit)
993 if (cur_tok < left_brace_limit)
999 fast_store_new_token(cur_tok);
1002 if (cur_tok == par_token)
1003 if (long_state != long_call)
1005 if (long_state == call)
1008 print_err("Paragraph ended before ");
1009 sprint_cs(warning_index);
1010 print_string(" was complete");
1011 help3("I suspect you've forgotten a `}', causing me to apply this",
1012 "control sequence to too much text. How can we recover?",
1013 "My plan is to forget the whole thing and hope for the best.");
1017 pstack[n] = link(temp_head);
1018 align_state = align_state - unbalance;
1020 for (m = 0; m <= n; m++)
1021 flush_list(pstack[m]);
1025 if (cur_tok < right_brace_limit)
1026 if (cur_tok < left_brace_limit)
1038 store_new_token(cur_tok);
1043 print_err("Argument of ");
1044 sprint_cs(warning_index);
1045 print_string(" has an extra }");
1046 help6("I've run across a `}' that doesn't seem to match anything.",
1047 "For example, `\\def\\a#1{...}' and `\\a}' would produce",
1048 "this error. If you simply proceed now, the `\\par' that",
1049 "I've just inserted will cause me to report a runaway",
1050 "argument that might be the root of the problem. But if",
1051 "your `}' was spurious, just type `2' and it will go away.");
1054 cur_tok = par_token;
1060 if (cur_tok == space_token)
1061 if (info(r) <= end_match_token)
1062 if (info(r) >= match_token)
1065 store_new_token(cur_tok);
1068 incr(m); /* m may be used without having been ... */
1070 if (info(r) > end_match_token)
1073 if (info(r) < match_token)
1078 if ((m == 1) && (info(p) < right_brace_limit) && (p != temp_head))
1080 link(rbraceptr) = 0; /* rbraceptr may be used without ... */
1082 p = link(temp_head);
1083 pstack[n] = link(p);
1087 pstack[n] = link(temp_head);
1091 if (tracing_macros > 0)
1094 //print_nl(match_chr); /* matchchar may be used without ... */
1095 print_nl(""); print(match_chr);
1098 show_token_list(pstack[n - 1], 0, 1000);
1099 end_diagnostic(false);
1103 while(!(info(r) == end_match_token));
1106 while((cur_input.state_field == token_list) && (cur_input.loc_field == 0) &&
1107 (cur_input.index_field != v_template))
1110 begin_token_list(refcount, macro);
1111 cur_input.name_field = warning_index;
1112 cur_input.loc_field = link(r);
1116 if (param_ptr + n > max_param_stack)
1118 max_param_stack = param_ptr + n;
1120 #ifdef ALLOCATEPARAMSTACK
1121 if (max_param_stack > current_param_size)
1122 param_stack = realloc_param_stack(increment_param_size);
1124 if (max_param_stack > current_param_size) /* check again after allocation */
1126 overflow("parameter stack size", current_param_size);
1127 return; // abort_flag set
1130 if (max_param_stack > param_size)
1132 overflow("parameter stack size", param_size); /* parameter stack - not dynamic */
1133 return; // abort_flag set
1138 for (m = 0; m <= n - 1; m++)
1139 param_stack[param_ptr + m] = pstack[m];
1141 param_ptr = param_ptr + n;
1144 scanner_status = savescannerstatus;
1145 warning_index = savewarningindex;
1148 void insert_relax (void)
1150 cur_tok = cs_token_flag + cur_cs;
1152 cur_tok = cs_token_flag + frozen_relax; /* 96/Jan/10 */
1154 cur_input.index_field = inserted;
1163 small_number cvlbackup, radixbackup, cobackup;
1164 halfword backupbackup;
1165 small_number savescannerstatus;
1168 cvlbackup = cur_val_level;
1169 radixbackup = radix;
1170 cobackup = cur_order;
1171 backupbackup = link(backup_head);
1175 if (tracing_commands > 1)
1181 if (cur_mark[cur_chr] != 0)
1182 begin_token_list(cur_mark[cur_chr], mark_text);
1190 if (cur_cmd > max_command)
1200 savescannerstatus = scanner_status;
1201 scanner_status = normal;
1203 scanner_status = savescannerstatus;
1207 if (t >= cs_token_flag)
1210 info(p) = cs_token_flag + frozen_dont_expand; /*96/Jan/10*/
1211 link(p) = cur_input.loc_field;
1212 cur_input.start_field = p;
1213 cur_input.loc_field = p;
1225 store_new_token(cur_tok);
1227 while(!(cur_cs != 0));
1229 if (cur_cmd != end_cs_name)
1231 print_err("Missing ");
1232 print_esc("endcsname");
1233 print_string(" inserted");
1234 help2("The control sequence marked <to be read again> should",
1235 "not appear between \\csname and \\endcsname.");
1244 if (j >= max_buf_stack)
1246 max_buf_stack = j + 1;
1248 #ifdef ALLOCATEBUFFER
1249 if (max_buf_stack == current_buf_size)
1250 buffer = realloc_buffer (increment_buf_size);
1252 if (max_buf_stack == current_buf_size) /* check again after allocation */
1254 overflow("buffer size", current_buf_size);
1255 return; // abort_flag set
1258 if (max_buf_stack == buf_size)
1260 overflow("buffer size", buf_size); /* buffer size - not dynamic */
1261 return; // abort_flag set
1266 buffer[j] = info(p) % 256;
1273 no_new_control_sequence = false;
1274 cur_cs = id_lookup(first, j - first);
1275 no_new_control_sequence = true;
1277 else if (j == first)
1280 cur_cs = single_base + buffer[first];
1284 if (eq_type(cur_cs) == undefined_cs)
1286 eq_define(cur_cs, relax, 256);
1289 cur_tok = cur_cs + cs_token_flag;
1306 if (cur_chr > if_limit)
1311 print_err("Extra ");
1312 print_cmd_chr(fi_or_else, cur_chr);
1313 help1("I'm ignoring this; it doesn't match any \\if.");
1318 while(cur_chr != fi_code)
1323 if_line = if_line_field(p);
1324 cur_if = subtype(p);
1327 free_node(p, if_node_size);
1335 else if (name_in_progress)
1342 print_err("Undefined control sequence");
1343 help5("The control sequence at the end of the top line",
1344 "of your error message was never \\def'ed. If you have",
1345 "misspelled it (e.g., `\\hobx'), type `I' and the correct",
1346 "spelling (e.g., `I\\hbox'). Otherwise just continue,",
1347 "and I'll forget about whatever was undefined.");
1352 else if (cur_cmd < end_template)
1358 cur_tok = cs_token_flag + frozen_endv; /* 96/Jan/10 */
1363 cur_val_level = cvlbackup;
1364 radix = radixbackup;
1365 cur_order = cobackup;
1366 link(backup_head) = backupbackup;
1369 void get_x_token (void)
1374 if (cur_cmd <= max_command)
1376 if (cur_cmd >= call)
1377 if (cur_cmd < end_template)
1381 cur_cs = frozen_endv; /* 96/Jan/10 */
1391 cur_tok = (cur_cmd * 256) + cur_chr;
1393 cur_tok = cs_token_flag + cur_cs;
1398 while (cur_cmd > max_command)
1405 cur_tok = (cur_cmd * 256) + cur_chr;
1407 cur_tok = cs_token_flag + cur_cs;
1410 void scan_left_brace (void)
1416 while(!((cur_cmd != spacer) && (cur_cmd != relax)));
1418 if (cur_cmd != left_brace)
1420 print_err("Missing { inserted");
1421 help4("A left brace was mandatory here, so I've put one in.",
1422 "You might want to delete and/or insert some corrections",
1423 "so that I will find a matching right brace soon.",
1424 "(If you're confused by all this, try typing `I}' now.)");
1426 cur_tok = left_brace_token + '{';
1427 cur_cmd = left_brace;
1433 void scan_optional_equals (void)
1439 while(!(cur_cmd != spacer));
1441 if (cur_tok != other_token + '=')
1445 bool scan_keyword_(char * s)
1459 if ((cur_cs == 0) && ((cur_chr == (*k)) || (cur_chr == (*k) - 'a' + 'A')))
1461 store_new_token(cur_tok);
1464 else if ((cur_cmd != spacer) || (p != backup_head))
1468 if (p != backup_head)
1469 back_list(link(backup_head));
1475 flush_list(link(backup_head));
1480 void mu_error (void)
1482 print_err("Incompatible glue units");
1483 help1("I'm going to assume that 1mu=1pt when they're mixed.");
1487 void scan_eight_bit_int (void)
1491 if ((cur_val < 0) || (cur_val > 255))
1493 print_err("Bad register code");
1494 help2("A register number must be between 0 and 255.",
1495 "I changed this one to zero.");
1501 void scan_char_num (void)
1505 if ((cur_val < 0) || (cur_val > 255))
1507 print_err("Bad character code");
1508 help2("A character number must be between 0 and 255.",
1509 "I changed this one to zero.");
1515 void scan_four_bit_int (void)
1519 if ((cur_val < 0) || (cur_val > 15))
1521 print_err("Bad number");
1522 help2("Since I expected to read a number between 0 and 15,",
1523 "I changed this one to zero.");
1529 void scan_fifteen_bit_int (void)
1532 if ((cur_val < 0) || (cur_val > 32767))
1534 print_err("Bad mathchar");
1535 help2("A mathchar number must be between 0 and 32767.",
1536 "I changed this one to zero.");
1542 void scan_twenty_seven_bit_int (void)
1546 if ((cur_val < 0) || (cur_val > 134217727L)) /* 2^27 - 1 */
1548 print_err("Bad delimiter code");
1549 help2("A numeric delimiter code must be between 0 and 2^{27}-1.",
1550 "I changed this one to zero.");
1556 void scan_font_ident (void)
1558 internal_font_number f;
1565 while (!(cur_cmd != spacer));
1567 if (cur_cmd == def_font)
1569 else if (cur_cmd == set_font)
1571 else if (cur_cmd == def_family)
1574 scan_four_bit_int();
1575 f = equiv(m + cur_val);
1579 print_err("Missing font identifier");
1580 help2("I was looking for a control sequence whose",
1581 "current meaning has been defined by \\font.");
1589 void find_font_dimen_(bool writing)
1591 internal_font_number f;
1599 if (n < 0 || (n == 0 && font_dimen_zero == 0)) /* change 98/Oct/5 */
1603 if (writing && (n <= space_shrink_code) && (n >= space_code) && (font_glue[f] != 0))
1605 delete_glue_ref(font_glue[f]);
1609 if (n > font_params[f])
1617 if (fmem_ptr == current_font_mem_size) /* 93/Nov/28 ??? */
1619 font_info = realloc_font_info(increment_font_mem_size);
1622 if (fmem_ptr == current_font_mem_size) /* 94/Jan/24 */
1624 overflow("font memory", current_font_mem_size); /* font memory */
1625 return; // abort_flag set
1628 if (fmem_ptr == font_mem_size)
1630 overflow("font memory", font_mem_size); /* font memory */
1631 return; // abort_flag set
1634 font_info[fmem_ptr].cint = 0;
1636 incr(font_params[f]);
1638 while(!(n == font_params[f]));
1640 cur_val = fmem_ptr - 1;
1643 cur_val = n + param_base[f]; /* 98/Oct/5 */
1645 // cur_val = (&font_check[f] - &font_info[0]); /* 98/Oct/5 */
1646 /* checksum = (((font_check[f].b0) << 8 | font_check[f].b1) << 8 |
1647 font_check[f].b2) << 8 | font_check[f].b3; */
1649 /* compiler error: '-' : incompatible types - from 'union fmemoryword *' to 'struct fourunsignedchars *' */
1650 if (cur_val == fmem_ptr)
1653 /* print_esc(hash[(hash_size + 524) + f].rh); */
1654 print_esc(""); print(font_id_text(f));
1655 print_string(" has only ");
1656 print_int(font_params[f]);
1657 print_string(" fontdimen parameters");
1658 help2("To increase the number of font parameters, you must",
1659 "use \\fontdimen immediately after the \\font is loaded.");
1664 void scan_something_internal_(small_number level, bool negative)
1677 if (m == math_code_base)
1679 cur_val = math_code(cur_val);
1680 cur_val_level = int_val;
1682 else if (m < math_code_base)
1684 cur_val = equiv(m + cur_val);
1685 cur_val_level = int_val;
1689 cur_val = eqtb[m + cur_val].cint;
1690 cur_val_level = int_val;
1700 if (level != tok_val)
1702 print_err("Missing number, treated as zero");
1703 help3("A number should have been here; I inserted `0'.",
1704 "(If you can't figure out why I needed to see a number,",
1705 "look up `weird error' in the index to The TeXbook.)");
1709 cur_val_level = dimen_val;
1712 else if (cur_cmd <= assign_toks)
1714 if (cur_cmd < assign_toks)
1716 scan_eight_bit_int();
1717 m = toks_base + cur_val;
1721 cur_val = eqtb[m].hh.rh;
1722 cur_val_level = tok_val;
1731 cur_val = font_id_base + cur_val; /* 96/Jan/10 */
1732 cur_val_level = ident_val;
1739 cur_val = eqtb[m].cint;
1740 cur_val_level = int_val;
1746 cur_val = eqtb[m].cint;
1747 cur_val_level = dimen_val;
1753 cur_val = eqtb[m].hh.rh;
1754 cur_val_level = glue_val;
1758 case assign_mu_glue:
1760 cur_val = eqtb[m].hh.rh;
1761 cur_val_level = mu_val;
1768 print_err("Improper ");
1769 print_cmd_chr(set_aux, m);
1770 help4("You can refer to \\spacefactor only in horizontal mode;",
1771 "you can refer to \\prevdepth only in vertical mode; and",
1772 "neither of these is meaningful inside \\write. So",
1773 "I'm forgetting what you said and using zero instead.");
1776 if (level != tok_val)
1779 cur_val_level = dimen_val;
1784 cur_val_level = int_val;
1787 else if (m == vmode)
1789 cur_val = cur_list.aux_field.cint;
1790 cur_val_level = dimen_val;
1794 cur_val = space_factor;
1795 cur_val_level = int_val;
1803 cur_val_level = int_val;
1807 nest[nest_ptr] = cur_list;
1810 while (abs(nest[p].mode_field)!= vmode)
1814 cur_val = nest[p].pg_field;
1815 cur_val_level = int_val;
1823 cur_val = dead_cycles;
1825 cur_val = insert_penalties;
1831 case set_page_dimen:
1833 if ((page_contents == 0) && (! output_active))
1835 cur_val = 1073741823L; /* 2^30 - 1 */
1839 cur_val = page_so_far[m];
1841 cur_val_level = dimen_val;
1847 if (par_shape_ptr == 0)
1850 cur_val = info(par_shape_ptr);
1852 cur_val_level = int_val;
1858 scan_eight_bit_int();
1860 if (box(cur_val) == 0)
1863 cur_val = mem[box(cur_val) + m].cint;
1865 cur_val_level = dimen_val;
1873 cur_val_level = int_val;
1877 case assign_font_dimen:
1879 find_font_dimen(false);
1880 font_info[fmem_ptr].cint = 0;
1882 cur_val = font_info[cur_val].cint;
1883 cur_val_level = dimen_val;
1888 case assign_font_int:
1894 cur_val = hyphen_char[cur_val];
1895 cur_val_level = int_val;
1899 cur_val = skew_char[cur_val];
1900 cur_val_level = int_val;
1907 scan_eight_bit_int();
1912 cur_val = count(cur_val);
1916 cur_val = dimen(cur_val);
1920 cur_val = skip(cur_val);
1924 cur_val = mu_skip(cur_val);
1933 if (cur_chr > glue_val)
1935 if (cur_chr == input_line_no_code)
1938 cur_val = last_badness;
1940 cur_val_level = int_val;
1944 if (cur_chr == glue_val)
1945 cur_val = zero_glue;
1949 cur_val_level = cur_chr;
1951 if (!(tail >= hi_mem_min) && (mode != 0))
1955 if (type(tail) == penalty_node)
1956 cur_val = penalty(tail);
1960 if (type(tail) == kern_node)
1961 cur_val = width(tail);
1965 if (type(tail) == glue_node)
1967 cur_val = glue_ptr(tail);
1969 if (subtype(tail) == mu_glue)
1970 cur_val_level = mu_val;
1974 else if ((mode == 1) && (tail == cur_list.head_field))
1978 cur_val = last_penalty;
1982 cur_val = last_kern;
1986 if (last_glue != empty_flag)
1987 cur_val = last_glue;
1995 print_err("You can't use `");
1996 print_cmd_chr(cur_cmd, cur_chr);
1997 print_string("' after ");
1999 help1("I'm forgetting what you said and using zero instead.");
2002 if (level != tok_val)
2005 cur_val_level = dimen_val;
2010 cur_val_level = int_val;
2016 while (cur_val_level > level)
2018 if (cur_val_level == glue_val)
2019 cur_val = width(cur_val);
2020 else if (cur_val_level == mu_val)
2023 decr(cur_val_level);
2027 if (cur_val_level >= 2)
2029 cur_val = new_spec(cur_val);
2032 width(cur_val) = - (integer) width(cur_val);
2033 stretch(cur_val) = - (integer) stretch(cur_val);
2034 shrink(cur_val) = - (integer) shrink(cur_val);
2038 cur_val = - (integer) cur_val;
2039 else if ((cur_val_level >= glue_val) && (cur_val_level <= mu_val))
2040 add_glue_ref(cur_val);
2043 void get_next (void)
2047 /* char cat; */ /* make this an int ? */
2048 int cat; /* make this an int ? 95/Jan/7 */
2055 if (cur_input.state_field != token_list)
2058 if (cur_input.loc_field <= cur_input.limit_field)
2060 cur_chr = buffer[cur_input.loc_field];
2061 incr(cur_input.loc_field);
2063 cur_cmd = cat_code(cur_chr);
2065 switch (cur_input.state_field + cur_cmd)
2067 case any_state_plus(ignore):
2068 case skip_blanks + spacer:
2069 case new_line + spacer:
2073 case any_state_plus(escape):
2075 if (cur_input.loc_field > cur_input.limit_field)
2080 k = cur_input.loc_field;
2081 cur_chr = buffer[k];
2082 cat = cat_code(cur_chr);
2086 cur_input.state_field = skip_blanks;
2087 else if (cat == spacer)
2088 cur_input.state_field = skip_blanks;
2090 cur_input.state_field = mid_line;
2092 if ((cat == letter) && (k <= cur_input.limit_field))
2096 cur_chr = buffer[k];
2097 cat = cat_code(cur_chr);
2100 while(!((cat != letter) || (k > cur_input.limit_field)));
2103 if (buffer[k]== cur_chr)
2104 if (cat == sup_mark)
2105 if (k < cur_input.limit_field)
2112 if ((((c >= 48) && (c <= 57)) || ((c >= 97) && (c <= 102))))
2113 if (k + 2 <= cur_input.limit_field)
2117 if ((((cc >= 48) && (cc <= 57)) || ((cc >= 97) && (cc <= 102))))
2129 cur_chr = 16 * cur_chr + cc - 48;
2131 cur_chr = 16 * cur_chr + cc - 87;
2133 buffer[k - 1] = cur_chr;
2136 buffer[k - 1] = c + 64;
2138 buffer[k - 1] = c - 64;
2140 cur_input.limit_field = cur_input.limit_field - d;
2143 while (k <= cur_input.limit_field)
2145 buffer[k] = buffer[k + d];
2157 if (k > cur_input.loc_field + 1)
2159 cur_cs = id_lookup(cur_input.loc_field, k - cur_input.loc_field);
2160 cur_input.loc_field = k;
2166 if (buffer[k] == cur_chr)
2167 if (cat == sup_mark)
2168 if (k < cur_input.limit_field)
2172 if (c < 128) /* ? */
2175 if ((((c >= 48) && (c <= 57)) || ((c >= 97) && (c <= 102))))
2176 if (k + 2 <= cur_input.limit_field)
2180 if ((((cc >= 48) && (cc <= 57)) || ((cc >= 97) && (cc <= 102))))
2191 if (cc <= 57) /* cc may be used without ... */
2192 cur_chr = 16 * cur_chr + cc - 48;
2194 cur_chr = 16 * cur_chr + cc - 87;
2196 buffer[k - 1] = cur_chr;
2199 buffer[k - 1] = c + 64;
2201 buffer[k - 1] = c - 64;
2203 cur_input.limit_field = cur_input.limit_field - d;
2206 while (k <= cur_input.limit_field)
2208 buffer[k] = buffer[k + d];
2215 cur_cs = single_base + buffer[cur_input.loc_field];
2216 incr(cur_input.loc_field);
2219 cur_cmd = eq_type(cur_cs);
2220 cur_chr = equiv(cur_cs);
2222 if (cur_cmd >= outer_call)
2223 check_outer_validity();
2227 case any_state_plus(active_char):
2229 cur_cs = cur_chr + active_base;
2230 cur_cmd = eq_type(cur_cs);
2231 cur_chr = equiv(cur_cs);
2232 cur_input.state_field = mid_line;
2234 if (cur_cmd >= outer_call)
2235 check_outer_validity();
2239 case any_state_plus(sup_mark):
2241 if (cur_chr == buffer[cur_input.loc_field])
2242 if (cur_input.loc_field < cur_input.limit_field)
2244 c = buffer[cur_input.loc_field + 1];
2248 cur_input.loc_field = cur_input.loc_field + 2;
2250 if ((((c >= 48) && (c <= 57)) || ((c >= 97) && (c <= 102))))
2251 if (cur_input.loc_field <= cur_input.limit_field)
2253 cc = buffer[cur_input.loc_field];
2255 if ((((cc >= 48) && (cc <= 57)) || ((cc >= 97) && (cc <= 102))))
2257 incr(cur_input.loc_field);
2265 cur_chr = 16 * cur_chr + cc - 48;
2267 cur_chr = 16 * cur_chr + cc - 87;
2282 cur_input.state_field = mid_line;
2286 case any_state_plus(invalid_char):
2288 print_err("Text line contains an invalid character");
2289 help2("A funny symbol that I can't read has just been input.",
2290 "Continue, and I'll forget that it ever happened.");
2291 deletions_allowed = false;
2293 deletions_allowed = true;
2298 case mid_line + spacer:
2300 cur_input.state_field = skip_blanks;
2305 case mid_line + car_ret:
2307 cur_input.loc_field = cur_input.limit_field + 1;
2313 case skip_blanks + car_ret:
2314 case any_state_plus(comment):
2316 cur_input.loc_field = cur_input.limit_field + 1;
2321 case new_line + car_ret:
2323 cur_input.loc_field = cur_input.limit_field + 1;
2325 cur_cmd = eq_type(cur_cs);
2326 cur_chr = equiv(cur_cs);
2328 if (cur_cmd >= outer_call)
2329 check_outer_validity();
2333 case mid_line + left_brace:
2337 case skip_blanks + left_brace:
2338 case new_line + left_brace:
2340 cur_input.state_field = mid_line;
2345 case mid_line + right_brace:
2349 case skip_blanks + right_brace:
2350 case new_line + right_brace:
2352 cur_input.state_field = 1;
2357 case add_delims_to(skip_blanks):
2358 case add_delims_to(new_line):
2359 cur_input.state_field = 1;
2368 cur_input.state_field = new_line;
2370 if (cur_input.name_field > 17)
2373 first = cur_input.start_field;
2377 if (input_ln(input_file[cur_input.index_field], true))
2392 check_outer_validity();
2396 if ((end_line_char < 0) || (end_line_char > 255))
2397 decr(cur_input.limit_field);
2399 buffer[cur_input.limit_field] = end_line_char;
2401 first = cur_input.limit_field + 1;
2402 cur_input.loc_field = cur_input.start_field;
2406 if (!(cur_input.name_field == 0))
2419 if (selector < log_only)
2422 if (interaction > nonstop_mode)
2424 if ((end_line_char < 0) || (end_line_char > 255))
2425 incr(cur_input.limit_field);
2427 if (cur_input.limit_field == cur_input.start_field)
2428 print_nl("(Please type a command or say `\\end')");
2431 first = cur_input.start_field;
2439 cur_input.limit_field = last;
2441 if ((end_line_char < 0) || (end_line_char > 255))
2442 decr(cur_input.limit_field);
2444 buffer[cur_input.limit_field]= end_line_char;
2446 first = cur_input.limit_field + 1;
2447 cur_input.loc_field = cur_input.start_field;
2451 fatal_error("*** (job aborted, no legal \\end found)");
2452 return; // abort_flag set
2459 pause_for_instructions();
2466 else if (cur_input.loc_field != 0)
2468 t = info(cur_input.loc_field);
2469 cur_input.loc_field = link(cur_input.loc_field);
2471 if (t >= cs_token_flag)
2473 cur_cs = t - cs_token_flag;
2474 cur_cmd = eq_type(cur_cs);
2475 cur_chr = equiv(cur_cs);
2477 if (cur_cmd >= outer_call)
2478 if (cur_cmd == dont_expand)
2480 cur_cs = info(cur_input.loc_field) - cs_token_flag;
2481 cur_input.loc_field = 0;
2482 cur_cmd = eq_type(cur_cs);
2483 cur_chr = equiv(cur_cs);
2485 if (cur_cmd > max_command)
2488 cur_chr = no_expand_flag;
2493 check_outer_validity();
2513 begin_token_list(param_stack[cur_input.limit_field + cur_chr - 1], parameter);
2529 if (cur_cmd <= car_ret)
2530 if (cur_cmd >= tab_mark)
2531 if (align_state == 0)
2533 if ((scanner_status == aligning) && (cur_align == 0))
2535 fatal_error("(interwoven alignment preambles are not allowed)");
2536 return; // abort_flag set
2539 cur_cmd = extra_info(cur_align);
2540 extra_info(cur_align) = cur_chr;
2542 if (cur_cmd == omit)
2543 begin_token_list(omit_template, v_template);
2545 begin_token_list(v_part(cur_align), v_template);
2547 align_state = 1000000L;