2 #pragma warning(disable:4996)
3 #pragma warning(disable:4131) // old style declarator
4 #pragma warning(disable:4135) // conversion between different integral types
5 #pragma warning(disable:4127) // conditional expression is constant
11 #pragma warning(disable:4244) /* 96/Jan/10 */
13 /* following bit used to be end of tex1.c */
17 void restore_trace_(halfword p, char * s)
25 end_diagnostic(false);
35 if (cur_level > level_one)
41 if (save_type(save_ptr) == level_boundary)
44 p = save_index(save_ptr);
46 if (save_type(save_ptr) == insert_token)
55 if (save_type(save_ptr) == restore_old_value)
57 l = save_level(save_ptr);
61 save_stack[save_ptr] = eqtb[undefined_control_sequence];
64 if (eq_level(p) == level_one)
66 eq_destroy(save_stack[save_ptr]);
68 if (tracing_restores > 0)
69 restore_trace(p, "retaining");
75 eqtb[p] = save_stack[save_ptr];
77 if (tracing_restores > 0)
78 restore_trace(p, "restoring");
81 else if (xeq_level[p] != level_one)
83 eqtb[p] = save_stack[save_ptr];
84 xeq_level[p] = l; /* l may be used without having been ... */
86 if (tracing_restores > 0)
87 restore_trace(p, "restoring");
93 if (tracing_restores > 0)
94 restore_trace(p, "retaining");
100 cur_group = save_level(save_ptr);
101 cur_boundary = save_index(save_ptr);
105 confusion("curlevel");
106 return; // abort_flag set
109 /* This is where the old tex2.c used to start */
111 void prepare_mag (void)
113 if ((mag_set > 0) && (mag != mag_set))
115 print_err("Incompatible magnification (");
118 print_nl(" the previous value will be retained");
119 help2("I can handle only one magnification ratio per job. So I've",
120 "reverted to the magnification you used earlier on this run.");
122 geq_word_define(int_base + mag_code, mag_set);
125 if ((mag <= 0) || (mag > 32768L))
127 print_err("Illegal magnification has been changed to 1000");
128 help1("The magnification ratio must be between 1 and 32768.");
130 geq_word_define(int_base + mag_code, 1000);
135 void token_show_ (halfword p)
138 show_token_list(link(p), 0, 10000000L);
141 void print_meaning (void)
143 print_cmd_chr(cur_cmd, cur_chr);
151 else if (cur_cmd == top_bot_mark)
155 token_show(cur_mark[cur_chr]);
159 void show_cur_cmd_chr (void)
164 if (mode != shown_mode)
171 print_cmd_chr(cur_cmd, cur_chr);
173 end_diagnostic(false);
176 void show_context (void)
189 base_ptr = input_ptr;
190 input_stack[base_ptr] = cur_input;
196 cur_input = input_stack[base_ptr];
198 if ((cur_input.state_field != 0))
199 if ((cur_input.name_field > 17) || (base_ptr == 0))
202 if ((base_ptr == input_ptr) || bottomline || (nn < error_context_lines))
204 if ((base_ptr == input_ptr) || (cur_input.state_field != token_list) ||
205 (cur_input.index_field != backed_up) || (cur_input.loc_field != 0))
208 old_setting = selector;
210 if (cur_input.state_field != 0)
212 if (cur_input.name_field <= 17)
213 if ((cur_input.name_field == 0))
217 print_nl("<insert> ");
221 if (cur_input.name_field == 17)
224 print_int(cur_input.name_field - 1);
232 /* show current input file name - ignore if from terminal */
233 if (cur_input.name_field > 17) /* redundant ? */
234 print(cur_input.name_field);
237 print_int(line); /* line number */
244 print_nl("l."); /* l. ? 573 ????? 98/Dec/8 check ! */
245 print_int(line); /* line number */
255 trick_count = 1000000L;
258 if (buffer[cur_input.limit_field] == end_line_char)
259 j = cur_input.limit_field;
261 j = cur_input.limit_field + 1;
264 for (i = cur_input.start_field; i <= j - 1; i++)
266 if (i == cur_input.loc_field)
269 trick_count = tally + 1 + error_line - half_error_line;
271 if (trick_count < error_line)
272 trick_count = error_line;
279 switch (cur_input.index_field)
282 print_nl("<argument> ");
287 print_nl("<template> ");
291 if (cur_input.loc_field == 0)
292 print_nl("<recently read> ");
294 print_nl("<to be read again> ");
298 print_nl("<inserted text> ");
303 print_cs(cur_input.name_field);
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> ");
355 trick_count = 1000000L;
358 if (cur_input.index_field < macro)
359 show_token_list(cur_input.start_field, cur_input.loc_field, 100000L);
361 show_token_list(link(cur_input.start_field), cur_input.loc_field, 100000L);
364 selector = old_setting;
366 if (trick_count == 1000000L)
369 trick_count = tally + 1 + error_line - half_error_line;
371 if (trick_count < error_line)
372 trick_count = error_line;
375 if (tally < trick_count)
376 m = tally - first_count;
378 m = trick_count - first_count;
380 if (l + first_count <= half_error_line)
388 p = l + first_count - half_error_line + 3;
392 for (q = p; q <= first_count - 1; q++)
393 print_char(trick_buf[q % error_line]);
397 for (q = 1; q <= n; q++)
400 if (m + n <= error_line)
403 p = first_count +(error_line - n - 3);
405 for (q = first_count; q <= p - 1; q++)
406 print_char(trick_buf[q % error_line]);
408 if (m + n > error_line)
413 else if (nn == error_context_lines)
425 cur_input = input_stack[input_ptr];
427 #pragma optimize("g", off) /* 98/Dec/10 experiment */
429 void begin_token_list_ (halfword p, quarterword t)
432 if (input_ptr > max_in_stack)
434 max_in_stack = input_ptr;
436 #ifdef ALLOCATEINPUTSTACK
437 if (input_ptr == current_stack_size)
438 input_stack = realloc_input_stack(increment_stack_size);
440 if (input_ptr == current_stack_size) /* check again after allocation */
442 overflow("input stack size", current_stack_size);
443 return; // abort_flag set
446 if (input_ptr == stack_size) /* input stack - not dynamic */
448 overflow("input stack size", stack_size);
449 return; // abort_flag set
454 input_stack[input_ptr] = cur_input;
458 cur_input.state_field = token_list;
459 cur_input.start_field = p;
460 cur_input.index_field = t;
467 cur_input.limit_field = param_ptr;
470 cur_input.loc_field = link(p);
472 if (tracing_macros > 1)
488 print_cmd_chr(assign_toks, t + (hash_size + 1307));
494 end_diagnostic(false);
499 cur_input.loc_field = p;
501 #pragma optimize("", on) /* 98/Dec/10 experiment */
503 void end_token_list (void)
505 if (cur_input.index_field >= backed_up)
507 if (cur_input.index_field <= inserted)
508 flush_list(cur_input.start_field);
511 delete_token_ref(cur_input.start_field);
512 if (cur_input.index_field == macro)
513 while (param_ptr > cur_input.limit_field)
516 flush_list(param_stack[param_ptr]);
520 else if (cur_input.index_field == u_template)
521 if (align_state > 500000L)
525 fatal_error("(interwoven alignment preambles are not allowed)");
526 return; // abort_flag set
531 cur_input = input_stack[input_ptr];
537 pause_for_instructions();
542 void back_input (void)
546 while ((cur_input.state_field == 0) && (cur_input.loc_field == 0) &&
547 (cur_input.index_field != v_template))
555 if (cur_tok < right_brace_limit)
556 if (cur_tok < left_brace_limit)
562 if (input_ptr > max_in_stack)
564 max_in_stack = input_ptr;
565 #ifdef ALLOCATEINPUTSTACK
566 if (input_ptr == current_stack_size)
567 input_stack = realloc_input_stack(increment_stack_size);
569 if (input_ptr == current_stack_size) /* check again after allocation */
571 overflow("input stack size", current_stack_size);
572 return; // abort_flag set
575 if (input_ptr == stack_size) /* stack size - not dynamic */
577 overflow("input stack size", stack_size);
578 return; // abort_flag set
582 input_stack[input_ptr] = cur_input;
586 cur_input.state_field = token_list;
587 cur_input.start_field = p;
588 cur_input.index_field = backed_up;
589 cur_input.loc_field = p;
592 void back_error (void)
594 OK_to_interrupt = false;
596 OK_to_interrupt = true;
600 void ins_error (void)
602 OK_to_interrupt = false;
604 cur_input.index_field = inserted;
605 OK_to_interrupt = true;
609 void begin_file_reading (void)
611 if (in_open == max_in_open)
613 overflow("text input levels", max_in_open); /* text input levels - NOT DYNAMIC */
614 return; // abort_flag set
616 #ifdef ALLOCATEBUFFER
617 if (first == current_buf_size)
618 buffer = realloc_buffer(increment_buf_size);
620 if (first == current_buf_size) /* check again after allocation */
622 overflow("buffer size", current_buf_size);
623 return; // abort_flag set
626 if (first == buf_size)
628 overflow("buffer size", buf_size); /* buffer size - not dynamic */
629 return; // abort_flag set
633 if (in_open > high_in_open) /* 1999 Jan 17 */
634 high_in_open = in_open;
636 if (input_ptr > max_in_stack)
638 max_in_stack = input_ptr;
639 #ifdef ALLOCATEINPUTSTACK
640 if (input_ptr == current_stack_size)
641 input_stack = realloc_input_stack(increment_stack_size);
642 if (input_ptr == current_stack_size)
644 overflow("input stack size", current_stack_size); /* check again after allocation */
645 return; // abort_flag set
648 if (input_ptr == stack_size)
650 overflow("input stack size", stack_size); /* input stack - not dynamic */
651 return; // abort_flag set
655 input_stack[input_ptr] = cur_input;
658 cur_input.index_field = in_open;
659 line_stack[cur_input.index_field] = line;
660 cur_input.start_field = first;
661 cur_input.state_field = 1;
662 cur_input.name_field = 0;
665 void end_file_reading (void)
667 first = cur_input.start_field;
668 line = line_stack[cur_input.index_field];
670 if (cur_input.name_field > 17)
671 (void) a_close(input_file[cur_input.index_field]);
675 cur_input = input_stack[input_ptr];
679 /* called only form tex0.c */
681 void clear_for_error_prompt (void)
683 while ((cur_input.state_field != 0) &&
684 (cur_input.name_field == 0) && (input_ptr > 0) &&
685 (cur_input.loc_field > cur_input.limit_field))
691 void check_outer_validity (void)
696 if (scanner_status != 0)
698 deletions_allowed = false;
702 if ((cur_input.state_field == 0) || (cur_input.name_field < 1) || (cur_input.name_field > 17))
705 info(p) = cs_token_flag + cur_cs;
713 if (scanner_status > skipping)
718 print_err("File ended");
722 print_err("Forbidden control sequence found");
725 print_string(" while scanning ");
728 switch (scanner_status)
731 print_string("definition");
732 info(p) = right_brace_token + '}';
738 long_state = outer_call;
742 print_string("preamble");
743 info(p) = right_brace_token + '}';
747 info(p) = cs_token_flag + frozen_cr; /*96/Jan/10*/
748 align_state = -1000000L;
752 print_string("text");
753 info(p) = right_brace_token + '}';
757 print_string(" of ");
758 sprint_cs(warning_index);
759 help4("I suspect you have forgotten a `}', causing me",
760 "to read past where you wanted me to stop.",
761 "I'll try to recover; but if the error is serious,",
762 "you'd better type `E' or `X' now and fix your file.");
767 print_err("Incomplete ");
768 print_cmd_chr(if_test, cur_if);
769 print_string("; all text was ignored after line ");
770 print_int(skip_line);
771 help3("A forbidden control sequence occurred in skipped text.",
772 "This kind of error happens when you say `\\if...' and forget",
773 "the matching `\\fi'. I've inserted a `\\fi'; this might work.");
778 help_line[2] = "The file ended while I was skipping conditional text.";
780 cur_tok = cs_token_flag + frozen_fi; /* 96/Jan/10 */
783 deletions_allowed = true;
786 /*****************************************************************************/
787 /* get_next() moved from here to end for pragma optimize reasons 96/Sep/12 */
789 /*****************************************************************************/
791 void firm_up_the_line (void)
795 cur_input.limit_field = last;
798 if (interaction > nonstop_mode)
803 if (cur_input.start_field < cur_input.limit_field)
804 for (k = cur_input.start_field; k <= cur_input.limit_field - 1; k++)
807 first = cur_input.limit_field;
817 for (k = first; k <= last - 1; k++)
818 buffer[k + cur_input.start_field - first] = buffer[k];
820 cur_input.limit_field = cur_input.start_field + last - first;
825 void get_token (void)
827 no_new_control_sequence = false;
829 no_new_control_sequence = true;
832 cur_tok = (cur_cmd * 256) + cur_chr;
834 cur_tok = cs_token_flag + cur_cs;
837 void macro_call (void)
850 small_number savescannerstatus;
851 halfword savewarningindex;
852 ASCII_code match_chr;
854 savescannerstatus = scanner_status;
855 savewarningindex = warning_index;
856 warning_index = cur_cs;
861 if (tracing_macros > 0)
865 print_cs(warning_index);
866 token_show(refcount);
867 end_diagnostic(false);
870 if (info(r) != end_match_token)
872 scanner_status = matching;
874 long_state = eq_type(cur_cs);
876 if (long_state >= outer_call)
877 long_state = long_state - 2;
883 if ((info(r) > match_token + 255) || (info(r) < match_token))
887 match_chr = info(r) - match_token;
896 if (cur_tok == info(r))
900 if ((info(r) >= match_token) && (info(r) <= end_match_token))
902 if (cur_tok < left_brace_limit)
914 print_err("Use of ");
915 sprint_cs(warning_index);
916 print_string(" doesn't match its definition");
917 help4("If you say, e.g., `\\def\\a1{...}', then you must always",
918 "put `1' after `\\a', since control sequence names are",
919 "made up of letters only. The macro here has not been",
920 "followed by the required stuff, so I'm ignoring it.");
932 mem[q].hh.v.LH = mem[t].hh.v.LH;
943 if (cur_tok != info(v))
951 if (info(u) != info(v))
965 if (cur_tok == par_token)
966 if (long_state != long_call)
968 if (long_state == call)
971 print_err("Paragraph ended before ");
972 sprint_cs(warning_index);
973 print_string("was complete");
974 help3("I suspect you've forgotten a `}', causing me to apply this",
975 "control sequence to too much text. How can we recover?",
976 "My plan is to forget the whole thing and hope for the best.");
980 pstack[n] = link(temp_head);
981 align_state = align_state - unbalance;
983 for (m = 0; m <= n; m++)
984 flush_list(pstack[m]);
989 if (cur_tok < right_brace_limit)
990 if (cur_tok < left_brace_limit)
1004 avail = mem[q].hh.v.RH;
1013 mem[q].hh.v.LH = cur_tok;
1019 if (cur_tok == par_token)
1020 if (long_state != long_call)
1022 if (long_state == call)
1025 print_err("Paragraph ended before ");
1026 sprint_cs(warning_index);
1027 print_string(" was complete");
1028 help3("I suspect you've forgotten a `}', causing me to apply this",
1029 "control sequence to too much text. How can we recover?",
1030 "My plan is to forget the whole thing and hope for the best.");
1034 pstack[n] = link(temp_head);
1035 align_state = align_state - unbalance;
1037 for (m = 0; m <= n; m++)
1038 flush_list(pstack[m]);
1042 if (cur_tok < right_brace_limit)
1043 if (cur_tok < left_brace_limit)
1059 mem[q].hh.v.LH = cur_tok;
1066 print_err("Argument of ");
1067 sprint_cs(warning_index);
1068 print_string(" has an extra }");
1069 help6("I've run across a `}' that doesn't seem to match anything.",
1070 "For example, `\\def\\a#1{...}' and `\\a}' would produce",
1071 "this error. If you simply proceed now, the `\\par' that",
1072 "I've just inserted will cause me to report a runaway",
1073 "argument that might be the root of the problem. But if",
1074 "your `}' was spurious, just type `2' and it will go away.");
1077 cur_tok = par_token;
1083 if (cur_tok == space_token)
1084 if (info(r) <= end_match_token)
1085 if (info(r) >= match_token)
1090 mem[p].hh.v.RH = q; /* p may be used without having ... */
1091 mem[q].hh.v.LH = cur_tok;
1096 incr(m); /* m may be used without having been ... */
1098 if (info(r) > end_match_token)
1101 if (info(r) < match_token)
1106 if ((m == 1) && (info(p) < right_brace_limit) && (p != temp_head))
1108 link(rbraceptr) = 0; /* rbraceptr may be used without ... */
1110 p = link(temp_head);
1111 pstack[n] = link(p);
1115 pstack[n] = link(temp_head);
1119 if (tracing_macros > 0)
1122 //print_nl(match_chr); /* matchchar may be used without ... */
1123 print_nl(""); print(match_chr);
1126 show_token_list(pstack[n - 1], 0, 1000);
1127 end_diagnostic(false);
1131 while(!(info(r) == end_match_token));
1134 while((cur_input.state_field == token_list) && (cur_input.loc_field == 0) &&
1135 (cur_input.index_field != v_template))
1138 begin_token_list(refcount, macro);
1139 cur_input.name_field = warning_index;
1140 cur_input.loc_field = link(r);
1144 if (param_ptr + n > max_param_stack)
1146 max_param_stack = param_ptr + n;
1148 #ifdef ALLOCATEPARAMSTACK
1149 if (max_param_stack > current_param_size)
1150 param_stack = realloc_param_stack(increment_param_size);
1152 if (max_param_stack > current_param_size) /* check again after allocation */
1154 overflow("parameter stack size", current_param_size);
1155 return; // abort_flag set
1158 if (max_param_stack > param_size)
1160 overflow("parameter stack size", param_size); /* parameter stack - not dynamic */
1161 return; // abort_flag set
1166 for (m = 0; m <= n - 1; m++)
1167 param_stack[param_ptr + m] = pstack[m];
1169 param_ptr = param_ptr + n;
1172 scanner_status = savescannerstatus;
1173 warning_index = savewarningindex;
1176 void insert_relax (void)
1178 cur_tok = cs_token_flag + cur_cs;
1180 cur_tok = cs_token_flag + frozen_relax; /* 96/Jan/10 */
1182 cur_input.index_field = inserted;
1191 small_number cvlbackup, radixbackup, cobackup;
1192 halfword backupbackup;
1193 small_number savescannerstatus;
1196 cvlbackup = cur_val_level;
1197 radixbackup = radix;
1198 cobackup = cur_order;
1199 backupbackup = link(backup_head);
1203 if (tracing_commands > 1)
1209 if (cur_mark[cur_chr] != 0)
1210 begin_token_list(cur_mark[cur_chr], mark_text);
1218 if (cur_cmd > max_command)
1228 savescannerstatus = scanner_status;
1229 scanner_status = normal;
1231 scanner_status = savescannerstatus;
1235 if (t >= cs_token_flag)
1238 info(p) = cs_token_flag + frozen_dont_expand; /*96/Jan/10*/
1239 link(p) = cur_input.loc_field;
1240 cur_input.start_field = p;
1241 cur_input.loc_field = p;
1256 mem[q].hh.v.LH = cur_tok;
1260 while(!(cur_cs != 0));
1262 if (cur_cmd != end_cs_name)
1264 print_err("Missing ");
1265 print_esc("endcsname");
1266 print_string(" inserted");
1267 help2("The control sequence marked <to be read again> should",
1268 "not appear between \\csname and \\endcsname.");
1277 if (j >= max_buf_stack)
1279 max_buf_stack = j + 1;
1281 #ifdef ALLOCATEBUFFER
1282 if (max_buf_stack == current_buf_size)
1283 buffer = realloc_buffer (increment_buf_size);
1285 if (max_buf_stack == current_buf_size) /* check again after allocation */
1287 overflow("buffer size", current_buf_size);
1288 return; // abort_flag set
1291 if (max_buf_stack == buf_size)
1293 overflow("buffer size", buf_size); /* buffer size - not dynamic */
1294 return; // abort_flag set
1299 buffer[j] = info(p) % 256;
1306 no_new_control_sequence = false;
1307 cur_cs = id_lookup(first, j - first);
1308 no_new_control_sequence = true;
1310 else if (j == first)
1313 cur_cs = single_base + buffer[first];
1317 if (eq_type(cur_cs) == undefined_cs)
1319 eq_define(cur_cs, relax, 256);
1322 cur_tok = cur_cs + cs_token_flag;
1339 if (cur_chr > if_limit)
1344 print_err("Extra ");
1345 print_cmd_chr(fi_or_else, cur_chr);
1346 help1("I'm ignoring this; it doesn't match any \\if.");
1351 while(cur_chr != fi_code)
1356 if_line = if_line_field(p);
1357 cur_if = subtype(p);
1360 free_node(p, if_node_size);
1368 else if (name_in_progress)
1375 print_err("Undefined control sequence");
1376 help5("The control sequence at the end of the top line",
1377 "of your error message was never \\def'ed. If you have",
1378 "misspelled it (e.g., `\\hobx'), type `I' and the correct",
1379 "spelling (e.g., `I\\hbox'). Otherwise just continue,",
1380 "and I'll forget about whatever was undefined.");
1385 else if (cur_cmd < end_template)
1391 cur_tok = cs_token_flag + frozen_endv; /* 96/Jan/10 */
1396 cur_val_level = cvlbackup;
1397 radix = radixbackup;
1398 cur_order = cobackup;
1399 link(backup_head) = backupbackup;
1402 void get_x_token (void)
1407 if (cur_cmd <= max_command)
1409 if (cur_cmd >= call)
1410 if (cur_cmd < end_template)
1414 cur_cs = frozen_endv; /* 96/Jan/10 */
1424 cur_tok = (cur_cmd * 256) + cur_chr;
1426 cur_tok = cs_token_flag + cur_cs;
1431 while (cur_cmd > max_command)
1438 cur_tok = (cur_cmd * 256) + cur_chr;
1440 cur_tok = cs_token_flag + cur_cs;
1443 void scan_left_brace (void)
1449 while(!((cur_cmd != spacer) && (cur_cmd != relax)));
1451 if (cur_cmd != left_brace)
1453 print_err("Missing { inserted");
1454 help4("A left brace was mandatory here, so I've put one in.",
1455 "You might want to delete and/or insert some corrections",
1456 "so that I will find a matching right brace soon.",
1457 "(If you're confused by all this, try typing `I}' now.)");
1459 cur_tok = left_brace_token + '{';
1460 cur_cmd = left_brace;
1466 void scan_optional_equals (void)
1472 while(!(cur_cmd != spacer));
1474 if (cur_tok != other_token + '=')
1478 bool scan_keyword_(char * s)
1492 if ((cur_cs == 0) && ((cur_chr == (*k)) || (cur_chr == (*k) - 'a' + 'A')))
1497 mem[q].hh.v.LH = cur_tok;
1503 else if ((cur_cmd != spacer) || (p != backup_head))
1507 if (p != backup_head)
1508 back_list(link(backup_head));
1514 flush_list(link(backup_head));
1519 void mu_error (void)
1521 print_err("Incompatible glue units");
1522 help1("I'm going to assume that 1mu=1pt when they're mixed.");
1526 void scan_eight_bit_int (void)
1530 if ((cur_val < 0) || (cur_val > 255))
1532 print_err("Bad register code");
1533 help2("A register number must be between 0 and 255.",
1534 "I changed this one to zero.");
1540 void scan_char_num (void)
1544 if ((cur_val < 0) || (cur_val > 255))
1546 print_err("Bad character code");
1547 help2("A character number must be between 0 and 255.",
1548 "I changed this one to zero.");
1554 void scan_four_bit_int (void)
1558 if ((cur_val < 0) || (cur_val > 15))
1560 print_err("Bad number");
1561 help2("Since I expected to read a number between 0 and 15,",
1562 "I changed this one to zero.");
1568 void scan_fifteen_bit_int (void)
1571 if ((cur_val < 0) || (cur_val > 32767))
1573 print_err("Bad mathchar");
1574 help2("A mathchar number must be between 0 and 32767.",
1575 "I changed this one to zero.");
1581 void scan_twenty_seven_bit_int (void)
1585 if ((cur_val < 0) || (cur_val > 134217727L)) /* 2^27 - 1 */
1587 print_err("Bad delimiter code");
1588 help2("A numeric delimiter code must be between 0 and 2^{27}-1.",
1589 "I changed this one to zero.");
1595 void scan_font_ident (void)
1597 internal_font_number f;
1604 while (!(cur_cmd != spacer));
1606 if (cur_cmd == def_font)
1608 else if (cur_cmd == set_font)
1610 else if (cur_cmd == def_family)
1613 scan_four_bit_int();
1614 f = equiv(m + cur_val);
1618 print_err("Missing font identifier");
1619 help2("I was looking for a control sequence whose",
1620 "current meaning has been defined by \\font.");
1628 void find_font_dimen_(bool writing)
1630 internal_font_number f;
1638 if (n < 0 || (n == 0 && font_dimen_zero == 0)) /* change 98/Oct/5 */
1642 if (writing && (n <= space_shrink_code) && (n >= space_code) && (font_glue[f] != 0))
1644 delete_glue_ref(font_glue[f]);
1648 if (n > font_params[f])
1656 if (fmem_ptr == current_font_mem_size) /* 93/Nov/28 ??? */
1658 font_info = realloc_font_info(increment_font_mem_size);
1661 if (fmem_ptr == current_font_mem_size) /* 94/Jan/24 */
1663 overflow("font memory", current_font_mem_size); /* font memory */
1664 return; // abort_flag set
1667 if (fmem_ptr == font_mem_size)
1669 overflow("font memory", font_mem_size); /* font memory */
1670 return; // abort_flag set
1673 font_info[fmem_ptr].cint = 0;
1675 incr(font_params[f]);
1677 while(!(n == font_params[f]));
1679 cur_val = fmem_ptr - 1;
1682 cur_val = n + param_base[f]; /* 98/Oct/5 */
1684 cur_val = (&font_check[f] - &font_info[0]); /* 98/Oct/5 */
1685 /* checksum = (((font_check[f].b0) << 8 | font_check[f].b1) << 8 |
1686 font_check[f].b2) << 8 | font_check[f].b3; */
1688 /* compiler error: '-' : incompatible types - from 'union fmemoryword *' to 'struct fourunsignedchars *' */
1689 if (cur_val == fmem_ptr)
1692 /* print_esc(hash[(hash_size + 524) + f].v.RH); */
1693 print_esc(""); print(font_id_text(f));
1694 print_string(" has only ");
1695 print_int(font_params[f]);
1696 print_string(" fontdimen parameters");
1697 help2("To increase the number of font parameters, you must",
1698 "use \\fontdimen immediately after the \\font is loaded.");
1702 /* NOTE: the above use of /fontdimen0 to access the checksum is a kludge */
1703 /* In future would be better to do this by allocating one more slot for */
1704 /* for parameters when a font is read rather than carry checksum separately */
1705 /* The above gets the value byte order reversed ... 98/Oct/5 */
1707 void scan_something_internal_(small_number level, bool negative)
1720 if (m == math_code_base)
1722 cur_val = math_code(cur_val);
1723 cur_val_level = int_val;
1725 else if (m < math_code_base)
1727 cur_val = equiv(m + cur_val);
1728 cur_val_level = int_val;
1732 cur_val = eqtb[m + cur_val].cint;
1733 cur_val_level = int_val;
1743 if (level != tok_val)
1745 print_err("Missing number, treated as zero");
1746 help3("A number should have been here; I inserted `0'.",
1747 "(If you can't figure out why I needed to see a number,",
1748 "look up `weird error' in the index to The TeXbook.)");
1752 cur_val_level = dimen_val;
1755 else if (cur_cmd <= assign_toks)
1757 if (cur_cmd < assign_toks)
1759 scan_eight_bit_int();
1760 m = toks_base + cur_val;
1764 cur_val = eqtb[m].hh.v.RH;
1765 cur_val_level = tok_val;
1774 cur_val = font_id_base + cur_val; /* 96/Jan/10 */
1775 cur_val_level = ident_val;
1782 cur_val = eqtb[m].cint;
1783 cur_val_level = int_val;
1789 cur_val = eqtb[m].cint;
1790 cur_val_level = dimen_val;
1796 cur_val = eqtb[m].hh.v.RH;
1797 cur_val_level = glue_val;
1801 case assign_mu_glue:
1803 cur_val = eqtb[m].hh.v.RH;
1804 cur_val_level = mu_val;
1811 print_err("Improper ");
1812 print_cmd_chr(set_aux, m);
1813 help4("You can refer to \\spacefactor only in horizontal mode;",
1814 "you can refer to \\prevdepth only in vertical mode; and",
1815 "neither of these is meaningful inside \\write. So",
1816 "I'm forgetting what you said and using zero instead.");
1819 if (level != tok_val)
1822 cur_val_level = dimen_val;
1827 cur_val_level = int_val;
1830 else if (m == vmode)
1832 cur_val = cur_list.aux_field.cint;
1833 cur_val_level = dimen_val;
1837 cur_val = space_factor;
1838 cur_val_level = int_val;
1846 cur_val_level = int_val;
1850 nest[nest_ptr] = cur_list;
1853 while (abs(nest[p].mode_field)!= vmode)
1857 cur_val = nest[p].pg_field;
1858 cur_val_level = int_val;
1866 cur_val = dead_cycles;
1868 cur_val = insert_penalties;
1874 case set_page_dimen:
1876 if ((page_contents == 0) && (! output_active))
1878 cur_val = 1073741823L; /* 2^30 - 1 */
1882 cur_val = page_so_far[m];
1884 cur_val_level = dimen_val;
1890 if (par_shape_ptr == 0)
1893 cur_val = info(par_shape_ptr);
1895 cur_val_level = int_val;
1901 scan_eight_bit_int();
1903 if (box(cur_val) == 0)
1906 cur_val = mem[box(cur_val) + m].cint;
1908 cur_val_level = dimen_val;
1916 cur_val_level = int_val;
1920 case assign_font_dimen:
1922 find_font_dimen(false);
1923 font_info[fmem_ptr].cint = 0;
1925 cur_val = font_info[cur_val].cint;
1926 cur_val_level = dimen_val;
1931 case assign_font_int:
1937 cur_val = hyphen_char[cur_val];
1938 cur_val_level = int_val;
1942 cur_val = skew_char[cur_val];
1943 cur_val_level = int_val;
1950 scan_eight_bit_int();
1955 cur_val = count(cur_val);
1959 cur_val = dimen(cur_val);
1963 cur_val = skip(cur_val);
1967 cur_val = mu_skip(cur_val);
1976 if (cur_chr > glue_val)
1978 if (cur_chr == input_line_no_code)
1981 cur_val = last_badness;
1983 cur_val_level = int_val;
1987 if (cur_chr == glue_val)
1988 cur_val = zero_glue;
1992 cur_val_level = cur_chr;
1994 if (!(tail >= hi_mem_min) && (mode != 0))
1998 if (type(tail) == penalty_node)
1999 cur_val = penalty(tail);
2003 if (type(tail) == kern_node)
2004 cur_val = width(tail);
2008 if (type(tail) == glue_node)
2010 cur_val = glue_ptr(tail);
2012 if (subtype(tail) == mu_glue)
2013 cur_val_level = mu_val;
2017 else if ((mode == 1) && (tail == cur_list.head_field))
2021 cur_val = last_penalty;
2025 cur_val = last_kern;
2029 if (last_glue != empty_flag)
2030 cur_val = last_glue;
2038 print_err("You can't use `");
2039 print_cmd_chr(cur_cmd, cur_chr);
2040 print_string("' after ");
2042 help1("I'm forgetting what you said and using zero instead.");
2045 if (level != tok_val)
2048 cur_val_level = dimen_val;
2053 cur_val_level = int_val;
2059 while (cur_val_level > level)
2061 if (cur_val_level == glue_val)
2062 cur_val = width(cur_val);
2063 else if (cur_val_level == mu_val)
2066 decr(cur_val_level);
2070 if (cur_val_level >= 2)
2072 cur_val = new_spec(cur_val);
2075 width(cur_val) = - (integer) width(cur_val);
2076 stretch(cur_val) = - (integer) stretch(cur_val);
2077 shrink(cur_val) = - (integer) shrink(cur_val);
2081 cur_val = - (integer) cur_val;
2082 else if ((cur_val_level >= glue_val) && (cur_val_level <= mu_val))
2083 add_glue_ref(cur_val);
2085 /*****************************************************************************/
2086 /* Moved here to avoid question about pragma optimize 96/Sep/12 */
2088 void get_next (void)
2092 /* char cat; */ /* make this an int ? */
2093 int cat; /* make this an int ? 95/Jan/7 */
2100 if (cur_input.state_field != token_list)
2103 if (cur_input.loc_field <= cur_input.limit_field)
2105 cur_chr = buffer[cur_input.loc_field];
2106 incr(cur_input.loc_field);
2108 cur_cmd = cat_code(cur_chr);
2110 switch (cur_input.state_field + cur_cmd)
2112 case any_state_plus(ignore):
2113 case skip_blanks + spacer:
2114 case new_line + spacer:
2118 case any_state_plus(escape):
2120 if (cur_input.loc_field > cur_input.limit_field)
2125 k = cur_input.loc_field;
2126 cur_chr = buffer[k];
2127 cat = cat_code(cur_chr);
2131 cur_input.state_field = skip_blanks;
2132 else if (cat == spacer)
2133 cur_input.state_field = skip_blanks;
2135 cur_input.state_field = mid_line;
2137 if ((cat == letter) && (k <= cur_input.limit_field))
2141 cur_chr = buffer[k];
2142 cat = cat_code(cur_chr);
2145 while(!((cat != letter) || (k > cur_input.limit_field)));
2148 if (buffer[k]== cur_chr)
2149 if (cat == sup_mark)
2150 if (k < cur_input.limit_field)
2157 if ((((c >= 48) && (c <= 57)) || ((c >= 97) && (c <= 102))))
2158 if (k + 2 <= cur_input.limit_field)
2162 if ((((cc >= 48) && (cc <= 57)) || ((cc >= 97) && (cc <= 102))))
2174 cur_chr = 16 * cur_chr + cc - 48;
2176 cur_chr = 16 * cur_chr + cc - 87;
2178 buffer[k - 1] = cur_chr;
2181 buffer[k - 1] = c + 64;
2183 buffer[k - 1] = c - 64;
2185 cur_input.limit_field = cur_input.limit_field - d;
2188 while (k <= cur_input.limit_field)
2190 buffer[k] = buffer[k + d];
2202 if (k > cur_input.loc_field + 1)
2204 cur_cs = id_lookup(cur_input.loc_field, k - cur_input.loc_field);
2205 cur_input.loc_field = k;
2211 if (buffer[k] == cur_chr)
2212 if (cat == sup_mark)
2213 if (k < cur_input.limit_field)
2217 if (c < 128) /* ? */
2220 if ((((c >= 48) && (c <= 57)) || ((c >= 97) && (c <= 102))))
2221 if (k + 2 <= cur_input.limit_field)
2225 if ((((cc >= 48) && (cc <= 57)) || ((cc >= 97) && (cc <= 102))))
2236 if (cc <= 57) /* cc may be used without ... */
2237 cur_chr = 16 * cur_chr + cc - 48;
2239 cur_chr = 16 * cur_chr + cc - 87;
2241 buffer[k - 1] = cur_chr;
2244 buffer[k - 1] = c + 64;
2246 buffer[k - 1] = c - 64;
2248 cur_input.limit_field = cur_input.limit_field - d;
2251 while (k <= cur_input.limit_field)
2253 buffer[k] = buffer[k + d];
2260 cur_cs = single_base + buffer[cur_input.loc_field];
2261 incr(cur_input.loc_field);
2264 cur_cmd = eq_type(cur_cs);
2265 cur_chr = equiv(cur_cs);
2267 if (cur_cmd >= outer_call)
2268 check_outer_validity();
2272 case any_state_plus(active_char):
2274 cur_cs = cur_chr + active_base;
2275 cur_cmd = eq_type(cur_cs);
2276 cur_chr = equiv(cur_cs);
2277 cur_input.state_field = mid_line;
2279 if (cur_cmd >= outer_call)
2280 check_outer_validity();
2284 case any_state_plus(sup_mark):
2286 if (cur_chr == buffer[cur_input.loc_field])
2287 if (cur_input.loc_field < cur_input.limit_field)
2289 c = buffer[cur_input.loc_field + 1];
2293 cur_input.loc_field = cur_input.loc_field + 2;
2295 if ((((c >= 48) && (c <= 57)) || ((c >= 97) && (c <= 102))))
2296 if (cur_input.loc_field <= cur_input.limit_field)
2298 cc = buffer[cur_input.loc_field];
2300 if ((((cc >= 48) && (cc <= 57)) || ((cc >= 97) && (cc <= 102))))
2302 incr(cur_input.loc_field);
2310 cur_chr = 16 * cur_chr + cc - 48;
2312 cur_chr = 16 * cur_chr + cc - 87;
2327 cur_input.state_field = mid_line;
2331 case any_state_plus(invalid_char):
2333 print_err("Text line contains an invalid character");
2334 help2("A funny symbol that I can't read has just been input.",
2335 "Continue, and I'll forget that it ever happened.");
2336 deletions_allowed = false;
2338 deletions_allowed = true;
2343 case mid_line + spacer:
2345 cur_input.state_field = skip_blanks;
2350 case mid_line + car_ret:
2352 cur_input.loc_field = cur_input.limit_field + 1;
2358 case skip_blanks + car_ret:
2359 case any_state_plus(comment):
2361 cur_input.loc_field = cur_input.limit_field + 1;
2366 case new_line + car_ret:
2368 cur_input.loc_field = cur_input.limit_field + 1;
2370 cur_cmd = eq_type(cur_cs);
2371 cur_chr = equiv(cur_cs);
2373 if (cur_cmd >= outer_call)
2374 check_outer_validity();
2378 case mid_line + left_brace:
2382 case skip_blanks + left_brace:
2383 case new_line + left_brace:
2385 cur_input.state_field = mid_line;
2390 case mid_line + right_brace:
2394 case skip_blanks + right_brace:
2395 case new_line + right_brace:
2397 cur_input.state_field = 1;
2402 case add_delims_to(skip_blanks):
2403 case add_delims_to(new_line):
2404 cur_input.state_field = 1;
2413 cur_input.state_field = new_line;
2415 if (cur_input.name_field > 17)
2418 first = cur_input.start_field;
2422 if (input_ln(input_file[cur_input.index_field], true))
2437 check_outer_validity();
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 if (!(cur_input.name_field == 0))
2464 if (selector < log_only)
2467 if (interaction > nonstop_mode)
2469 if ((end_line_char < 0) || (end_line_char > 255))
2470 incr(cur_input.limit_field);
2472 if (cur_input.limit_field == cur_input.start_field)
2473 print_nl("(Please type a command or say `\\end')");
2476 first = cur_input.start_field;
2484 cur_input.limit_field = last;
2486 if ((end_line_char < 0) || (end_line_char > 255))
2487 decr(cur_input.limit_field);
2489 buffer[cur_input.limit_field]= end_line_char;
2491 first = cur_input.limit_field + 1;
2492 cur_input.loc_field = cur_input.start_field;
2496 fatal_error("*** (job aborted, no legal \\end found)");
2497 return; // abort_flag set
2504 pause_for_instructions();
2511 else if (cur_input.loc_field != 0)
2513 t = info(cur_input.loc_field);
2514 cur_input.loc_field = link(cur_input.loc_field);
2516 if (t >= cs_token_flag)
2518 cur_cs = t - cs_token_flag;
2519 cur_cmd = eq_type(cur_cs);
2520 cur_chr = equiv(cur_cs);
2522 if (cur_cmd >= outer_call)
2523 if (cur_cmd == dont_expand)
2525 cur_cs = info(cur_input.loc_field) - cs_token_flag;
2526 cur_input.loc_field = 0;
2527 cur_cmd = eq_type(cur_cs);
2528 cur_chr = equiv(cur_cs);
2530 if (cur_cmd > max_command)
2533 cur_chr = no_expand_flag;
2538 check_outer_validity();
2558 begin_token_list(param_stack[cur_input.limit_field + cur_chr - 1], parameter);
2574 if (cur_cmd <= car_ret)
2575 if (cur_cmd >= tab_mark)
2576 if (align_state == 0)
2578 if ((scanner_status == aligning) && (cur_align == 0))
2580 fatal_error("(interwoven alignment preambles are not allowed)");
2581 return; // abort_flag set
2584 cur_cmd = extra_info(cur_align);
2585 extra_info(cur_align) = cur_chr;
2587 if (cur_cmd == omit)
2588 begin_token_list(omit_template, v_template);
2590 begin_token_list(v_part(cur_align), v_template);
2592 align_state = 1000000L;
2596 #pragma optimize ("", on) /* 96/Sep/12 */