6 #pragma warning(disable:4115) // kill rpcasync.h complaint
8 #define MYLIBAPI __declspec(dllexport)
13 #pragma warning(disable:4996)
14 #pragma warning(disable:4131) // old style declarator
15 #pragma warning(disable:4135) // conversion between different integral types
16 #pragma warning(disable:4127) // conditional expression is constant
24 #pragma warning(disable:4244) /* 96/Jan/10 */
26 /* following bit used to be end of tex1.c */
30 void restore_trace_(halfword p, char * s)
38 end_diagnostic(false);
48 if (cur_level > level_one)
54 if (save_type(save_ptr) == level_boundary)
57 p = save_index(save_ptr);
59 if (save_type(save_ptr) == insert_token)
68 if (save_type(save_ptr) == restore_old_value)
70 l = save_level(save_ptr);
74 save_stack[save_ptr] = eqtb[undefined_control_sequence];
77 if (eq_level(p) == level_one)
79 eq_destroy(save_stack[save_ptr]);
81 if (tracing_restores > 0)
82 restore_trace(p, "retaining");
88 eqtb[p] = save_stack[save_ptr];
90 if (tracing_restores > 0)
91 restore_trace(p, "restoring");
94 else if (xeq_level[p] != level_one)
96 eqtb[p] = save_stack[save_ptr];
97 xeq_level[p] = l; /* l may be used without having been ... */
99 if (tracing_restores > 0)
100 restore_trace(p, "restoring");
106 if (tracing_restores > 0)
107 restore_trace(p, "retaining");
113 cur_group = save_level(save_ptr);
114 cur_boundary = save_index(save_ptr);
118 confusion("curlevel");
119 return; // abort_flag set
122 /* This is where the old tex2.c used to start */
124 void prepare_mag (void)
126 if ((mag_set > 0) && (mag != mag_set))
128 print_err("Incompatible magnification (");
131 print_nl(" the previous value will be retained");
132 help2("I can handle only one magnification ratio per job. So I've",
133 "reverted to the magnification you used earlier on this run.");
135 geq_word_define(int_base + mag_code, mag_set);
137 if ((mag <= 0) || (mag > 32768L))
139 print_err("Illegal magnification has been changed to 1000");
140 help1("The magnification ratio must be between 1 and 32768.");
142 geq_word_define(int_base + mag_code, 1000);
147 void token_show_ (halfword p)
150 show_token_list(link(p), 0, 10000000L);
153 void print_meaning (void)
155 print_cmd_chr(cur_cmd, cur_chr);
163 else if (cur_cmd == top_bot_mark)
167 token_show(cur_mark[cur_chr]);
171 void show_cur_cmd_chr (void)
175 if (mode != shown_mode)
181 print_cmd_chr(cur_cmd, cur_chr);
183 end_diagnostic(false);
186 void show_context (void)
199 base_ptr = input_ptr;
200 input_stack[base_ptr] = cur_input;
204 cur_input = input_stack[base_ptr];
205 if ((cur_input.state_field != 0))
206 if ((cur_input.name_field > 17) || (base_ptr == 0))
208 if ((base_ptr == input_ptr) || bottomline || (nn < error_context_lines))
210 if ((base_ptr == input_ptr) || (cur_input.state_field != token_list) ||
211 (cur_input.index_field != backed_up) || (cur_input.loc_field != 0))
214 old_setting = selector;
215 if (cur_input.state_field != 0)
217 if (cur_input.name_field <= 17)
218 if ((cur_input.name_field == 0))
222 print_nl("<insert> ");
226 if (cur_input.name_field == 17)
229 print_int(cur_input.name_field - 1);
236 /* show current input file name - ignore if from terminal */
237 if (cur_input.name_field > 17) /* redundant ? */
238 print(cur_input.name_field);
240 print_int(line); /* line number */
247 print_nl("l."); /* l. ? 573 ????? 98/Dec/8 check ! */
248 print_int(line); /* line number */
256 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;
263 for (i = cur_input.start_field; i <= j - 1; i++)
265 if (i == cur_input.loc_field)
268 trick_count = tally + 1 + error_line - half_error_line;
269 if (trick_count < error_line)
270 trick_count = error_line;
277 switch (cur_input.index_field)
280 print_nl("<argument> ");
284 print_nl("<template> ");
287 if (cur_input.loc_field == 0)
288 print_nl("<recently read> ");
290 print_nl("<to be read again> ");
293 print_nl("<inserted text> ");
297 print_cs(cur_input.name_field);
300 print_nl("<output> ");
303 print_nl("<everypar> ");
305 case every_math_text:
306 print_nl("<everymath> ");
308 case every_display_text:
309 print_nl("<everydisplay> ");
311 case every_hbox_text:
312 print_nl("<everyhbox> ");
314 case every_vbox_text:
315 print_nl("<everyvbox> ");
318 print_nl("<everyjob> ");
321 print_nl("<everycr> ");
327 print_nl("<write> ");
337 trick_count = 1000000L;
339 if (cur_input.index_field < macro)
340 show_token_list(cur_input.start_field, cur_input.loc_field, 100000L);
342 show_token_list(link(cur_input.start_field), cur_input.loc_field, 100000L);
344 selector = old_setting;
345 if (trick_count == 1000000L)
348 trick_count = tally + 1 + error_line - half_error_line;
349 if (trick_count < error_line)
350 trick_count = error_line;
353 if (tally < trick_count)
354 m = tally - first_count;
356 m = trick_count - first_count;
358 if (l + first_count <= half_error_line)
366 p = l + first_count - half_error_line + 3;
370 for (q = p; q <= first_count - 1; q++)
371 print_char(trick_buf[q % error_line]);
375 for (q = 1; q <= n; q++)
378 if (m + n <= error_line)
381 p = first_count +(error_line - n - 3);
383 for (q = first_count; q <= p - 1; q++)
384 print_char(trick_buf[q % error_line]);
386 if (m + n > error_line)
391 else if (nn == error_context_lines)
401 cur_input = input_stack[input_ptr];
403 #pragma optimize("g", off) /* 98/Dec/10 experiment */
405 void begin_token_list_ (halfword p, quarterword t)
408 if (input_ptr > max_in_stack)
410 max_in_stack = input_ptr;
411 #ifdef ALLOCATEINPUTSTACK
412 if (input_ptr == current_stack_size)
413 input_stack = realloc_input_stack(increment_stack_size);
414 if (input_ptr == current_stack_size)
415 { /* check again after allocation */
416 overflow("input stack size", current_stack_size);
417 return; // abort_flag set
420 if (input_ptr == stack_size)
421 { /* input stack - not dynamic */
422 overflow("input stack size", stack_size);
423 return; // abort_flag set
427 input_stack[input_ptr] = cur_input;
430 cur_input.state_field = token_list;
431 cur_input.start_field = p;
432 cur_input.index_field = t;
437 cur_input.limit_field = param_ptr;
440 cur_input.loc_field = link(p);
441 if (tracing_macros > 1)
454 print_cmd_chr(assign_toks, t + (hash_size + 1307));
459 end_diagnostic(false);
464 cur_input.loc_field = p;
466 #pragma optimize("", on) /* 98/Dec/10 experiment */
468 void end_token_list (void)
470 if (cur_input.index_field >= backed_up)
472 if (cur_input.index_field <= inserted)
473 flush_list(cur_input.start_field);
476 delete_token_ref(cur_input.start_field);
477 if (cur_input.index_field == macro)
478 while (param_ptr > cur_input.limit_field) {
480 flush_list(param_stack[param_ptr]);
484 else if (cur_input.index_field == u_template)
485 if (align_state > 500000L)
488 fatal_error("(interwoven alignment preambles are not allowed)");
489 return; // abort_flag set
493 cur_input = input_stack[input_ptr];
498 pause_for_instructions();
503 void back_input (void)
506 while ((cur_input.state_field == 0) && (cur_input.loc_field == 0) &&
507 (cur_input.index_field != v_template)) {
518 if (input_ptr > max_in_stack)
520 max_in_stack = input_ptr;
521 #ifdef ALLOCATEINPUTSTACK
522 if (input_ptr == current_stack_size)
523 input_stack = realloc_input_stack(increment_stack_size);
524 if (input_ptr == current_stack_size)
525 { /* check again after allocation */
526 overflow("input stack size", current_stack_size);
527 return; // abort_flag set
530 if (input_ptr == stack_size)
531 { /* stack size - not dynamic */
532 overflow("input stack size", stack_size);
533 return; // abort_flag set
537 input_stack[input_ptr] = cur_input;
540 cur_input.state_field = token_list;
541 cur_input.start_field = p;
542 cur_input.index_field = backed_up;
543 cur_input.loc_field = p;
546 void back_error (void)
548 OK_to_interrupt = false;
550 OK_to_interrupt = true;
554 void ins_error (void)
556 OK_to_interrupt = false;
558 cur_input.index_field = inserted;
559 OK_to_interrupt = true;
563 void begin_file_reading (void)
565 if (in_open == max_in_open)
567 overflow("text input levels", max_in_open); /* text input levels - NOT DYNAMIC */
568 return; // abort_flag set
570 #ifdef ALLOCATEBUFFER
571 if (first == current_buf_size)
572 buffer = realloc_buffer(increment_buf_size);
573 if (first == current_buf_size)
574 { /* check again after allocation */
575 overflow("buffer size", current_buf_size);
576 return; // abort_flag set
579 if (first == buf_size)
581 overflow("buffer size", buf_size); /* buffer size - not dynamic */
582 return; // abort_flag set
586 if (in_open > high_in_open) /* 1999 Jan 17 */
587 high_in_open = in_open;
589 if (input_ptr > max_in_stack)
591 max_in_stack = input_ptr;
592 #ifdef ALLOCATEINPUTSTACK
593 if (input_ptr == current_stack_size)
594 input_stack = realloc_input_stack(increment_stack_size);
595 if (input_ptr == current_stack_size)
597 overflow("input stack size", current_stack_size); /* check again after allocation */
598 return; // abort_flag set
601 if (input_ptr == stack_size)
603 overflow("input stack size", stack_size); /* input stack - not dynamic */
604 return; // abort_flag set
608 input_stack[input_ptr] = cur_input;
611 cur_input.index_field = in_open;
612 line_stack[cur_input.index_field] = line;
613 cur_input.start_field = first;
614 cur_input.state_field = 1;
615 cur_input.name_field = 0;
618 void end_file_reading (void)
620 first = cur_input.start_field;
621 line = line_stack[cur_input.index_field];
622 if (cur_input.name_field > 17)
623 (void) a_close(input_file[cur_input.index_field]);
626 cur_input = input_stack[input_ptr];
630 /* called only form tex0.c */
632 void clear_for_error_prompt (void)
634 while ((cur_input.state_field != 0) &&
635 (cur_input.name_field == 0) &&
637 (cur_input.loc_field > cur_input.limit_field))
642 void check_outer_validity (void)
647 if (scanner_status != 0)
649 deletions_allowed = false;
652 if ((cur_input.state_field == 0) ||
653 (cur_input.name_field < 1) ||
654 (cur_input.name_field > 17))
657 info(p) = 4095 + cur_cs;
658 begin_token_list(p, 3);
664 if (scanner_status > skipping)
668 print_err("File ended");
672 print_err("Forbidden control sequence found");
674 print_string(" while scanning ");
676 switch (scanner_status)
679 print_string("definition");
685 long_state = outer_call;
688 print_string("preamble");
693 /* mem[p].hh.v.LH = (hash_size + 4610); */
694 /* mem[p].hh.v.LH = (hash_size + 4095 + 515); */
695 info(p) = (hash_size + hash_extra + 4095 + 515); /*96/Jan/10*/
696 align_state = -1000000L;
699 print_string("text");
703 begin_token_list(p, 4);
704 print_string(" of ");
705 sprint_cs(warning_index);
706 help4("I suspect you have forgotten a `}', causing me",
707 "to read past where you wanted me to stop.",
708 "I'll try to recover; but if the error is serious,",
709 "you'd better type `E' or `X' now and fix your file.");
714 print_err("Incomplete ");
715 print_cmd_chr(if_test, cur_if);
716 print_string("; all text was ignored after line ");
717 print_int(skip_line);
718 help3("A forbidden control sequence occurred in skipped text.",
719 "This kind of error happens when you say `\\if...' and forget",
720 "the matching `\\fi'. I've inserted a `\\fi'; this might work.");
724 help_line[2] = "The file ended while I was skipping conditional text.";
725 /* cur_tok = (hash_size + 4613); */
726 /* cur_tok = (hash_size + 4095 + 518); */
727 cur_tok = (hash_size + hash_extra + 4095 + 518); /* 96/Jan/10 */
730 deletions_allowed = true;
733 /*****************************************************************************/
734 /* get_next() moved from here to end for pragma optimize reasons 96/Sep/12 */
736 /*****************************************************************************/
738 void firm_up_the_line (void)
742 cur_input.limit_field = last;
748 if (cur_input.start_field < cur_input.limit_field)
749 for (k = cur_input.start_field; k <= cur_input.limit_field - 1; k++)
751 first = cur_input.limit_field;
759 for (k = first; k <= last - 1; k++)
760 buffer[k + cur_input.start_field - first] = buffer[k];
761 cur_input.limit_field = cur_input.start_field + last - first;
766 void get_token (void)
768 no_new_control_sequence = false;
770 no_new_control_sequence = true;
772 cur_tok = (cur_cmd * 256) + cur_chr;
774 cur_tok = 4095 + cur_cs;
777 void macro_call (void)
790 small_number savescannerstatus;
791 halfword savewarningindex;
792 ASCII_code match_chr;
794 savescannerstatus = scanner_status;
795 savewarningindex = warning_index;
796 warning_index = cur_cs;
801 if (tracing_macros > 0)
805 print_cs(warning_index);
806 token_show(refcount);
807 end_diagnostic(false);
811 scanner_status = matching;
813 long_state = eq_type(cur_cs);
814 if (long_state >= outer_call)
815 long_state = long_state - 2;
818 if ((info(r) > 3583) || (info(r) < 3328))
822 match_chr = info(r) - 3328;
830 if (cur_tok == info(r))
833 if ((info(r) >= 3328) && (info(r) <= 3584))
845 print_err("Use of ");
846 sprint_cs(warning_index);
847 print_string(" doesn't match its definition");
848 help4("If you say, e.g., `\\def\\a1{...}', then you must always",
849 "put `1' after `\\a', since control sequence names are",
850 "made up of letters only. The macro here has not been",
851 "followed by the required stuff, so I'm ignoring it.");
862 mem[q].hh.v.LH = mem[t].hh.v.LH;
870 if (cur_tok != info(v))
877 if (info(u) != info(v))
887 if (cur_tok == par_token)
888 if (long_state != long_call)
890 if (long_state == call)
893 print_err("Paragraph ended before ");
894 sprint_cs(warning_index);
895 print_string("was complete");
896 help3("I suspect you've forgotten a `}', causing me to apply this",
897 "control sequence to too much text. How can we recover?",
898 "My plan is to forget the whole thing and hope for the best.");
901 pstack[n] = link(temp_head);
902 align_state = align_state - unbalance;
903 for (m = 0; m <= n; m++)
904 flush_list(pstack[m]);
919 avail = mem[q].hh.v.RH;
927 mem[q].hh.v.LH = cur_tok;
931 if (cur_tok == par_token)
932 if (long_state != long_call)
934 if (long_state == call)
937 print_err("Paragraph ended before ");
938 sprint_cs(warning_index);
939 print_string(" was complete");
940 help3("I suspect you've forgotten a `}', causing me to apply this",
941 "control sequence to too much text. How can we recover?",
942 "My plan is to forget the whole thing and hope for the best.");
945 pstack[n] = link(temp_head);
946 align_state = align_state - unbalance;
947 for (m = 0; m <= n; m++)
948 flush_list(pstack[m]);
966 mem[q].hh.v.LH = cur_tok;
973 print_err("Argument of ");
974 sprint_cs(warning_index);
975 print_string(" has an extra }");
976 help6("I've run across a `}' that doesn't seem to match anything.",
977 "For example, `\\def\\a#1{...}' and `\\a}' would produce",
978 "this error. If you simply proceed now, the `\\par' that",
979 "I've just inserted will cause me to report a runaway",
980 "argument that might be the root of the problem. But if",
981 "your `}' was spurious, just type `2' and it will go away.");
996 mem[p].hh.v.RH = q; /* p may be used without having ... */
997 mem[q].hh.v.LH = cur_tok;
1001 incr(m); /* m may be used without having been ... */
1009 if ((m == 1) && (info(p) < 768) && (p != temp_head))
1011 link(rbraceptr) = 0; /* rbraceptr may be used without ... */
1013 p = link(temp_head);
1018 pstack[n] = link(temp_head);
1020 if (tracing_macros > 0)
1023 //print_nl(match_chr); /* matchchar may be used without ... */
1024 print_nl(""); print(match_chr);
1027 show_token_list(pstack[n - 1], 0, 1000);
1028 end_diagnostic(false);
1031 } while(!(info(r) == 3584));
1034 while((cur_input.state_field == token_list) && (cur_input.loc_field == 0) &&
1035 (cur_input.index_field != v_template))
1037 begin_token_list(refcount, macro);
1038 cur_input.name_field = warning_index;
1039 cur_input.loc_field = link(r);
1042 if (param_ptr + n > max_param_stack)
1044 max_param_stack = param_ptr + n;
1045 #ifdef ALLOCATEPARAMSTACK
1046 if (max_param_stack > current_param_size)
1047 param_stack = realloc_param_stack(increment_param_size);
1048 if (max_param_stack > current_param_size)
1049 { /* check again after allocation */
1050 overflow("parameter stack size", current_param_size);
1051 return; // abort_flag set
1054 if (max_param_stack > param_size)
1056 overflow("parameter stack size", param_size); /* parameter stack - not dynamic */
1057 return; // abort_flag set
1061 for (m = 0; m <= n - 1; m++)
1062 param_stack[param_ptr + m] = pstack[m];
1063 param_ptr = param_ptr + n;
1066 scanner_status = savescannerstatus;
1067 warning_index = savewarningindex;
1070 void insert_relax (void)
1072 cur_tok = 4095 + cur_cs;
1074 /* cur_tok = (hash_size + 4616); */
1075 /* cur_tok = (hash_size + 4095 + 521); */
1076 cur_tok = (hash_size + hash_extra + 4095 + 521); /* 96/Jan/10 */
1078 cur_input.index_field = inserted;
1087 small_number cvlbackup, radixbackup, cobackup;
1088 halfword backupbackup;
1089 small_number savescannerstatus;
1092 cvlbackup = cur_val_level;
1093 radixbackup = radix;
1094 cobackup = cur_order;
1095 backupbackup = link(backup_head);
1098 if (tracing_commands > 1)
1103 if (cur_mark[cur_chr] != 0)
1104 begin_token_list(cur_mark[cur_chr], mark_text);
1110 if (cur_cmd > max_command)
1118 savescannerstatus = scanner_status;
1119 scanner_status = normal;
1121 scanner_status = savescannerstatus;
1124 if (t >= 4095) /* if t>=cs_token_flag then */
1126 /* begin p:=get_avail; info(p):=cs_token_flag+frozen_dont_expand; */
1128 /* mem[p].hh.v.LH = (hash_size + 4618); */
1129 /* mem[p].hh.v.LH = (hash_size + 4095 + 523); */
1130 mem[p].hh.v.LH = (hash_size + hash_extra + 4095 + 523); /*96/Jan/10*/
1131 mem[p].hh.v.RH = cur_input.loc_field;
1132 cur_input.start_field = p;
1133 cur_input.loc_field = p;
1145 mem[q].hh.v.LH = cur_tok;
1148 } while(!(cur_cs != 0));
1149 if (cur_cmd != end_cs_name)
1151 print_err("Missing ");
1152 print_esc("endcsname");
1153 print_string(" inserted");
1154 help2("The control sequence marked <to be read again> should",
1155 "not appear between \\csname and \\endcsname.");
1160 while (p != 0) { /* while p<>null do l.7742 */
1161 if (j >= max_buf_stack)
1163 max_buf_stack = j + 1;
1164 #ifdef ALLOCATEBUFFER
1165 if (max_buf_stack == current_buf_size)
1166 buffer = realloc_buffer (increment_buf_size);
1167 if (max_buf_stack == current_buf_size)
1168 { /* check again after allocation */
1169 overflow("buffer size", current_buf_size);
1170 return; // abort_flag set
1173 if (max_buf_stack == buf_size)
1175 overflow("buffer size", buf_size); /* buffer size - not dynamic */
1176 return; // abort_flag set
1180 buffer[j] = info(p) % 256;
1186 no_new_control_sequence = false;
1187 cur_cs = id_lookup(first, j - first);
1188 no_new_control_sequence = true;
1190 else if (j == first)
1193 cur_cs = single_base + buffer[first];
1195 if (eq_type(cur_cs) == undefined_cs)
1197 eq_define(cur_cs, relax, 256);
1199 cur_tok = cur_cs + 4095;
1212 if (cur_chr > if_limit)
1217 print_err("Extra ");
1218 print_cmd_chr(fi_or_else, cur_chr);
1219 help1("I'm ignoring this; it doesn't match any \\if.");
1228 if_line = mem[p + 1].cint;
1229 cur_if = mem[p].hh.b1;
1230 if_limit = mem[p].hh.b0;
1231 cond_ptr = mem[p].hh.v.RH;
1239 else if (name_in_progress)
1244 print_err("Undefined control sequence");
1245 help5("The control sequence at the end of the top line",
1246 "of your error message was never \\def'ed. If you have",
1247 "misspelled it (e.g., `\\hobx'), type `I' and the correct",
1248 "spelling (e.g., `I\\hbox'). Otherwise just continue,",
1249 "and I'll forget about whatever was undefined.");
1254 else if (cur_cmd < end_template)
1260 /* cur_tok = (hash_size + 4615); */
1261 /* cur_tok = (hash_size + 4095 + 520); */
1262 cur_tok = (hash_size + hash_extra + 4095 + 520); /* 96/Jan/10 */
1266 cur_val_level = cvlbackup;
1267 radix = radixbackup;
1268 cur_order = cobackup;
1269 link(backup_head) = backupbackup;
1272 void get_x_token (void)
1276 if (cur_cmd <= max_command)
1278 if (cur_cmd >= call)
1279 if (cur_cmd < end_template)
1282 /* cur_cs = (hash_size + 520); */
1283 cur_cs = (hash_size + hash_extra + 520); /* 96/Jan/10 */
1292 cur_tok = (cur_cmd * 256) + cur_chr;
1294 cur_tok = 4095 + cur_cs;
1299 while (cur_cmd > max_command) {
1304 cur_tok = (cur_cmd * 256) + cur_chr;
1306 cur_tok = 4095 + cur_cs;
1309 void scan_left_brace (void)
1313 } while(!((cur_cmd != spacer) && (cur_cmd != relax)));
1315 if (cur_cmd != left_brace)
1317 print_err("Missing { inserted");
1318 help4("A left brace was mandatory here, so I've put one in.",
1319 "You might want to delete and/or insert some corrections",
1320 "so that I will find a matching right brace soon.",
1321 "(If you're confused by all this, try typing `I}' now.)");
1324 cur_cmd = left_brace;
1330 void scan_optional_equals (void)
1334 } while(!(cur_cmd != spacer));
1336 if (cur_tok != 3133)
1340 bool scan_keyword_(char * s)
1342 register bool Result;
1353 if ((cur_cs == 0) && ((cur_chr == (*k)) || (cur_chr == (*k) - 32)))
1358 mem[q].hh.v.LH = cur_tok;
1363 else if ((cur_cmd != spacer) || (p != backup_head))
1366 if (p != backup_head)
1367 begin_token_list(link(backup_head), 3);
1372 flush_list(link(backup_head));
1377 void mu_error (void)
1379 print_err("Incompatible glue units");
1380 help1("I'm going to assume that 1mu=1pt when they're mixed.");
1384 void scan_eight_bit_int (void)
1387 if ((cur_val < 0) || (cur_val > 255))
1389 print_err("Bad register code");
1390 help2("A register number must be between 0 and 255.",
1391 "I changed this one to zero.");
1397 void scan_char_num (void)
1400 if ((cur_val < 0) || (cur_val > 255))
1402 print_err("Bad character code");
1403 help2("A character number must be between 0 and 255.",
1404 "I changed this one to zero.");
1410 void scan_four_bit_int (void)
1413 if ((cur_val < 0) || (cur_val > 15))
1415 print_err("Bad number");
1416 help2("Since I expected to read a number between 0 and 15,",
1417 "I changed this one to zero.");
1423 void scan_fifteen_bit_int (void)
1426 if ((cur_val < 0) || (cur_val > 32767))
1428 print_err("Bad mathchar");
1429 help2("A mathchar number must be between 0 and 32767.",
1430 "I changed this one to zero.");
1436 void scan_twenty_seven_bit_int (void)
1439 if ((cur_val < 0) || (cur_val > 134217727L)) /* 2^27 - 1 */
1441 print_err("Bad delimiter code");
1442 help2("A numeric delimiter code must be between 0 and 2^{27}-1.",
1443 "I changed this one to zero.");
1449 void scan_font_ident (void)
1451 internal_font_number f;
1456 } while (!(cur_cmd != spacer));
1458 if (cur_cmd == def_font)
1460 else if (cur_cmd == set_font)
1462 else if (cur_cmd == def_family)
1465 scan_four_bit_int();
1466 f = equiv(m + cur_val);
1470 print_err("Missing font identifier");
1471 help2("I was looking for a control sequence whose",
1472 "current meaning has been defined by \\font.");
1479 void find_font_dimen_(bool writing)
1481 internal_font_number f;
1488 /* if (n <= 0)*/ /* change 98/Oct/5 */
1489 if (n < 0 || (n == 0 && font_dimen_zero == 0))
1493 /* else begin if writing and(n<=space_shrink_code)and@|
1494 (n>=space_code)and(font_glue[f]<>null) then
1495 begin delete_glue_ref(font_glue[f]); l.11225 */
1496 if (writing && (n <= 4) && (n >= 2) && (font_glue[f]!= 0))
1498 delete_glue_ref(font_glue[f]);
1499 font_glue[f]= 0; /* font_glue[f]:=null */
1501 if (n > font_params[f])
1507 /* *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** */
1509 if (fmem_ptr == current_font_mem_size)
1510 { /* 93/Nov/28 ??? */
1511 font_info = realloc_font_info(increment_font_mem_size);
1513 if (fmem_ptr == current_font_mem_size)
1515 overflow("font memory", current_font_mem_size); /* font memory */
1516 return; // abort_flag set
1519 /* *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** */
1520 if (fmem_ptr == font_mem_size)
1522 overflow("font memory", font_mem_size); /* font memory */
1523 return; // abort_flag set
1526 font_info[fmem_ptr].cint = 0;
1528 incr(font_params[f]);
1529 } while(!(n == font_params[f]));
1530 cur_val = fmem_ptr - 1;
1532 /* else cur_val = n + param_base[f]; */ /* 98/Oct/5 */
1534 cur_val = n + param_base[f]; /* 98/Oct/5 */
1535 else cur_val = &font_check[f] - &font_info[0]; /* 98/Oct/5 */
1536 /* checksum = (((font_check[f].b0) << 8 | font_check[f].b1) << 8 |
1537 font_check[f].b2) << 8 | font_check[f].b3; */
1539 /* compiler error: '-' : incompatible types - from 'union fmemoryword *' to 'struct fourunsignedchars *' */
1540 if (cur_val == fmem_ptr)
1543 /* print_esc(hash[(hash_size + 524) + f].v.RH); */
1544 //print_esc(hash[(hash_size + hash_extra + 524) + f].v.RH); /*96/Jan/10*/
1545 print_esc(""); print(hash[(hash_size + hash_extra + 524) + f].v.RH);
1546 print_string(" has only ");
1547 print_int(font_params[f]);
1548 print_string(" fontdimen parameters");
1549 help2("To increase the number of font parameters, you must",
1550 "use \\fontdimen immediately after the \\font is loaded.");
1554 /* NOTE: the above use of /fontdimen0 to access the checksum is a kludge */
1555 /* In future would be better to do this by allocating one more slot for */
1556 /* for parameters when a font is read rather than carry checksum separately */
1557 /* The above gets the value byte order reversed ... 98/Oct/5 */
1559 void scan_something_internal_(small_number level, bool negative)
1569 if (m == math_code_base)
1571 cur_val = math_code(cur_val);
1574 else if (m < math_code_base)
1576 cur_val = equiv(m + cur_val);
1581 cur_val = eqtb[m + cur_val].cint;
1592 print_err("Missing number, treated as zero");
1593 help3("A number should have been here; I inserted `0'.",
1594 "(If you can't figure out why I needed to see a number,",
1595 "look up `weird error' in the index to The TeXbook.)");
1602 else if (cur_cmd <= assign_toks)
1604 if (cur_cmd < assign_toks)
1606 scan_eight_bit_int();
1607 m = toks_base + cur_val;
1610 cur_val = eqtb[m].hh.v.RH;
1619 /* cur_val = (hash_size + 524) + cur_val; */
1620 cur_val = (hash_size + hash_extra + 524) + cur_val; /* 96/Jan/10 */
1627 cur_val = eqtb[m].cint;
1633 cur_val = eqtb[m].cint;
1639 cur_val = eqtb[m].hh.v.RH;
1643 case assign_mu_glue:
1645 cur_val = eqtb[m].hh.v.RH;
1652 print_err("Improper ");
1653 print_cmd_chr(set_aux, m);
1654 help4("You can refer to \\spacefactor only in horizontal mode;",
1655 "you can refer to \\prevdepth only in vertical mode; and",
1656 "neither of these is meaningful inside \\write. So",
1657 "I'm forgetting what you said and using zero instead.");
1672 cur_val = cur_list.aux_field.cint;
1677 cur_val = space_factor;
1689 nest[nest_ptr] = cur_list;
1691 while (abs(nest[p].mode_field)!= 1)
1694 cur_val = nest[p].pg_field;
1702 cur_val = dead_cycles;
1704 cur_val = insert_penalties;
1708 case set_page_dimen:
1710 if ((page_contents == 0) && (! output_active))
1712 cur_val = 1073741823L; /* 2^30 - 1 */
1716 cur_val = page_so_far[m];
1722 if (par_shape_ptr == 0)
1725 cur_val = mem[par_shape_ptr].hh.v.LH;
1731 scan_eight_bit_int();
1732 if (eqtb[box_base + cur_val].hh.v.RH == 0)
1735 cur_val = mem[eqtb[(hash_size + 1578) + cur_val].hh.v.RH + m].cint;
1746 case assign_font_dimen:
1748 find_font_dimen(false);
1749 font_info[fmem_ptr].cint = 0;
1751 cur_val = font_info[cur_val].cint;
1756 case assign_font_int:
1761 cur_val = hyphen_char[cur_val];
1766 cur_val = skew_char[cur_val];
1773 scan_eight_bit_int();
1777 cur_val = eqtb[(hash_size + 3218) + cur_val].cint;
1780 cur_val = eqtb[(hash_size + 3751) + cur_val].cint;
1783 cur_val = eqtb[(hash_size + 800) + cur_val].hh.v.RH;
1786 cur_val = eqtb[(hash_size + 1056) + cur_val].hh.v.RH;
1798 cur_val = last_badness;
1807 cur_val_level = cur_chr;
1808 if (!(tail >= hi_mem_min) && (mode != 0))
1812 if (mem[tail].hh.b0 == 12)
1813 cur_val = mem[tail + 1].cint;
1816 if (mem[tail].hh.b0 == 11)
1817 cur_val = mem[tail + 1].cint;
1820 if (mem[tail].hh.b0 == 10)
1822 cur_val = mem[tail + 1].hh.v.LH;
1823 if (mem[tail].hh.b1 == 99)
1828 else if ((mode == 1) && (tail == cur_list.head_field))
1832 cur_val = last_penalty;
1835 cur_val = last_kern;
1838 /* if (last_glue != 262143L) */ /* NO! */
1839 if (last_glue != empty_flag)
1840 cur_val = last_glue;
1847 print_err("You can't use `");
1848 print_cmd_chr(cur_cmd, cur_chr);
1849 print_string("' after ");
1851 help1("I'm forgetting what you said and using zero instead.");
1866 while (cur_val_level > level) {
1867 if (cur_val_level == 2)
1868 cur_val = mem[cur_val + 1].cint;
1869 else if (cur_val_level == 3)
1873 decr(cur_val_level);
1876 if (cur_val_level >= 2)
1878 cur_val = new_spec(cur_val);
1880 mem[cur_val + 1].cint = - (integer) mem[cur_val + 1].cint;
1881 mem[cur_val + 2].cint = - (integer) mem[cur_val + 2].cint;
1882 mem[cur_val + 3].cint = - (integer) mem[cur_val + 3].cint;
1885 else cur_val = - (integer) cur_val;
1886 else if ((cur_val_level >= 2) && (cur_val_level <= 3))
1887 incr(mem[cur_val].hh.v.RH);
1890 /*****************************************************************************/
1892 /* Moved here to avoid question about pragma optimize 96/Sep/12 */
1894 void get_next (void)
1898 /* char cat; */ /* make this an int ? */
1899 int cat; /* make this an int ? 95/Jan/7 */
1905 if (cur_input.state_field != token_list)
1908 if (cur_input.loc_field <= cur_input.limit_field)
1910 cur_chr = buffer[cur_input.loc_field];
1911 incr(cur_input.loc_field);
1913 cur_cmd = cat_code(cur_chr);
1914 switch (cur_input.state_field + cur_cmd)
1916 case any_state_plus(ignore):
1917 case skip_blanks + spacer:
1918 case new_line + spacer:
1921 case any_state_plus(escape):
1923 if (cur_input.loc_field > cur_input.limit_field)
1928 k = cur_input.loc_field;
1929 cur_chr = buffer[k];
1930 cat = cat_code(cur_chr);
1933 cur_input.state_field = skip_blanks;
1934 else if (cat == spacer)
1935 cur_input.state_field = skip_blanks;
1937 cur_input.state_field = mid_line;
1939 if ((cat == letter) && (k <= cur_input.limit_field))
1942 cur_chr = buffer[k];
1943 cat = cat_code(cur_chr);
1945 } while(!((cat != letter) || (k > cur_input.limit_field)));
1947 if (buffer[k]== cur_chr)
1948 if (cat == sup_mark)
1949 if (k < cur_input.limit_field)
1955 if ((((c >= 48) && (c <= 57)) ||
1956 ((c >= 97) && (c <= 102))))
1957 if (k + 2 <= cur_input.limit_field)
1960 if ((((cc >= 48) && (cc <= 57)) ||
1961 ((cc >= 97) && (cc <= 102))))
1971 cur_chr = 16 * cur_chr + cc - 48;
1973 cur_chr = 16 * cur_chr + cc - 87;
1974 buffer[k - 1] = cur_chr;
1977 buffer[k - 1] = c + 64;
1979 buffer[k - 1] = c - 64;
1980 cur_input.limit_field = cur_input.limit_field - d;
1982 while (k <= cur_input.limit_field) {
1983 buffer[k] = buffer[k + d];
1992 if (k > cur_input.loc_field + 1)
1994 cur_cs = id_lookup(cur_input.loc_field, k - cur_input.loc_field);
1995 cur_input.loc_field = k;
2001 if (buffer[k] == cur_chr)
2002 if (cat == sup_mark)
2003 if (k < cur_input.limit_field)
2006 if (c < 128) /* ? */
2009 if ((((c >= 48) && (c <= 57)) ||
2010 ((c >= 97) && (c <= 102))))
2011 if (k + 2 <= cur_input.limit_field)
2014 if ((((cc >= 48) && (cc <= 57)) ||
2015 ((cc >= 97) && (cc <= 102))))
2024 if (cc <= 57) /* cc may be used without ... */
2025 cur_chr = 16 * cur_chr + cc - 48;
2027 cur_chr = 16 * cur_chr + cc - 87;
2028 buffer[k - 1] = cur_chr;
2031 buffer[k - 1] = c + 64;
2033 buffer[k - 1] = c - 64;
2034 cur_input.limit_field = cur_input.limit_field - d;
2036 while (k <= cur_input.limit_field) {
2037 buffer[k] = buffer[k + d];
2044 cur_cs = single_base + buffer[cur_input.loc_field];
2045 incr(cur_input.loc_field);
2048 cur_cmd = eq_type(cur_cs);
2049 cur_chr = equiv(cur_cs);
2051 if (cur_cmd >= outer_call)
2053 check_outer_validity();
2057 case any_state_plus(active_char):
2059 cur_cs = cur_chr + active_base;
2060 cur_cmd = eq_type(cur_cs);
2061 cur_chr = equiv(cur_cs);
2062 cur_input.state_field = mid_line;
2064 if (cur_cmd >= outer_call)
2066 check_outer_validity();
2070 case any_state_plus(sup_mark):
2072 if (cur_chr == buffer[cur_input.loc_field])
2073 if (cur_input.loc_field < cur_input.limit_field)
2075 c = buffer[cur_input.loc_field + 1];
2078 cur_input.loc_field = cur_input.loc_field + 2;
2079 if ((((c >= 48) && (c <= 57)) ||
2080 ((c >= 97) && (c <= 102))))
2081 if (cur_input.loc_field <= cur_input.limit_field)
2083 cc = buffer[cur_input.loc_field];
2084 if ((((cc >= 48) && (cc <= 57)) ||
2085 ((cc >= 97) && (cc <= 102))))
2087 incr(cur_input.loc_field);
2093 cur_chr = 16 * cur_chr + cc - 48;
2095 cur_chr = 16 * cur_chr + cc - 87;
2106 cur_input.state_field = mid_line;
2109 case any_state_plus(invalid_char):
2111 print_err("Text line contains an invalid character");
2112 help2("A funny symbol that I can't read has just been input.",
2113 "Continue, and I'll forget that it ever happened.");
2114 deletions_allowed = false;
2116 deletions_allowed = true;
2120 case mid_line + spacer:
2122 cur_input.state_field = skip_blanks;
2126 case mid_line + car_ret:
2128 cur_input.loc_field = cur_input.limit_field + 1;
2133 case skip_blanks + car_ret:
2134 case any_state_plus(comment):
2136 cur_input.loc_field = cur_input.limit_field + 1;
2140 case new_line + car_ret:
2142 cur_input.loc_field = cur_input.limit_field + 1;
2144 cur_cmd = eq_type(cur_cs);
2145 cur_chr = equiv(cur_cs);
2147 if (cur_cmd >= outer_call)
2149 check_outer_validity();
2153 case mid_line + left_brace:
2156 case skip_blanks + left_brace:
2157 case new_line + left_brace:
2159 cur_input.state_field = mid_line;
2163 case mid_line + right_brace:
2166 case skip_blanks + right_brace:
2167 case new_line + right_brace:
2169 cur_input.state_field = 1;
2173 case add_delims_to(skip_blanks):
2174 case add_delims_to(new_line):
2175 cur_input.state_field = 1;
2183 cur_input.state_field = new_line;
2185 if (cur_input.name_field > 17)
2188 first = cur_input.start_field;
2191 if (input_ln(input_file[cur_input.index_field], true))
2208 check_outer_validity();
2211 if ((end_line_char < 0) || (end_line_char > 255))
2212 decr(cur_input.limit_field);
2214 buffer[cur_input.limit_field] = end_line_char;
2215 first = cur_input.limit_field + 1;
2216 cur_input.loc_field = cur_input.start_field;
2220 if (!(cur_input.name_field == 0))
2231 if (selector < log_only)
2233 if (interaction > nonstop_mode)
2235 if ((end_line_char < 0) || (end_line_char > 255))
2236 incr(cur_input.limit_field);
2237 if (cur_input.limit_field == cur_input.start_field)
2238 print_nl("(Please type a command or say `\\end')");
2240 first = cur_input.start_field;
2246 cur_input.limit_field = last;
2247 if ((end_line_char < 0) || (end_line_char > 255))
2248 decr(cur_input.limit_field);
2250 buffer[cur_input.limit_field]= end_line_char;
2251 first = cur_input.limit_field + 1;
2252 cur_input.loc_field = cur_input.start_field;
2256 fatal_error("*** (job aborted, no legal \\end found)");
2257 return; // abort_flag set
2263 pause_for_instructions();
2269 else if (cur_input.loc_field != 0)
2271 t = info(cur_input.loc_field);
2272 cur_input.loc_field = link(cur_input.loc_field);
2276 cur_cmd = eq_type(cur_cs);
2277 cur_chr = equiv(cur_cs);
2278 if (cur_cmd >= outer_call)
2279 if (cur_cmd == dont_expand)
2281 cur_cs = info(cur_input.loc_field) - 4095;
2282 cur_input.loc_field = 0;
2283 cur_cmd = eq_type(cur_cs);
2284 cur_chr = equiv(cur_cs);
2286 if (cur_cmd > max_command)
2294 check_outer_validity();
2311 begin_token_list(param_stack[cur_input.limit_field + cur_chr - 1], parameter);
2325 if (cur_cmd <= car_ret)
2326 if (cur_cmd >= tab_mark)
2327 if (align_state == 0)
2329 if ((scanner_status == aligning) && (cur_align == 0))
2331 fatal_error("(interwoven alignment preambles are not allowed)");
2332 return; // abort_flag set
2334 cur_cmd = extra_info(cur_align);
2335 extra_info(cur_align) = cur_chr;
2336 if (cur_cmd == omit)
2337 begin_token_list(omit_template, v_template);
2339 begin_token_list(v_part(cur_align), v_template);
2340 align_state = 1000000L;
2344 #pragma optimize ("", on) /* 96/Sep/12 */