OSDN Git Service

check_existence().
[putex/putex.git] / src / texsourc / tex2.c
1 /* Copyright 2014 Clerk Ma
2
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.
7
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.
12
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
16    02110-1301 USA.  */
17
18 #define EXTERN extern
19
20 #include "texd.h"
21
22 /* following bit used to be end of tex1.c */
23 #ifdef STAT
24 /* sec 0284 */
25 void restore_trace_(halfword p, char * s)
26 {
27   begin_diagnostic();
28   print_char('{');
29   prints(s);
30   print_char(' ');
31   show_eqtb(p);
32   print_char('}');
33   end_diagnostic(false);
34 }
35 #endif
36 /* sec 0281 */
37 void unsave (void)
38 {
39   halfword p;
40   quarterword l;
41   halfword t;
42
43   if (cur_level > level_one)
44   {
45     decr(cur_level);
46
47     while (true)
48     {
49       decr(save_ptr);
50
51       if (save_type(save_ptr) == level_boundary)
52         goto done;
53
54       p = save_index(save_ptr);
55
56       if (save_type(save_ptr) == insert_token)
57       {
58         t = cur_tok;
59         cur_tok = p;
60         back_input();
61         cur_tok = t;
62       }
63       else
64       {
65         if (save_type(save_ptr) == restore_old_value)
66         {
67           l = save_level(save_ptr);
68           decr(save_ptr);
69         }
70         else
71           save_stack[save_ptr] = eqtb[undefined_control_sequence];
72         
73         if (p < int_base)
74           if (eq_level(p) == level_one)
75           {
76             eq_destroy(save_stack[save_ptr]);
77 #ifdef STAT
78             if (tracing_restores > 0)
79               restore_trace(p, "retaining");
80 #endif
81           }
82           else
83           {
84             eq_destroy(eqtb[p]);
85             eqtb[p] = save_stack[save_ptr];
86 #ifdef STAT
87             if (tracing_restores > 0)
88               restore_trace(p, "restoring");
89 #endif
90           }
91         else if (xeq_level[p] != level_one)
92         {
93           eqtb[p] = save_stack[save_ptr];
94           xeq_level[p] = l;
95 #ifdef STAT
96           if (tracing_restores > 0)
97             restore_trace(p, "restoring");
98 #endif
99         }
100         else
101         {
102 #ifdef STAT
103           if (tracing_restores > 0)
104             restore_trace(p, "retaining");
105 #endif
106         }
107       }
108     }
109 done:
110     cur_group = save_level(save_ptr);
111     cur_boundary = save_index(save_ptr);
112   }
113   else
114   {
115     confusion("curlevel");
116     return;
117   }
118 }
119 /* This is where the old tex2.c used to start */
120 /* sec 0288 */
121 void prepare_mag (void) 
122 {
123   if ((mag_set > 0) && (mag != mag_set))
124   {
125     print_err("Incompatible magnification (");
126     print_int(mag);
127     prints(");");
128     print_nl(" the previous value will be retained");
129     help2("I can handle only one magnification ratio per job. So I've",
130         "reverted to the magnification you used earlier on this run.");
131     int_error(mag_set);
132     geq_word_define(int_base + mag_code, mag_set);
133   }
134
135   if ((mag <= 0) || (mag > 32768L))
136   {
137     print_err("Illegal magnification has been changed to 1000");
138     help1("The magnification ratio must be between 1 and 32768.");
139     int_error(mag);
140     geq_word_define(int_base + mag_code, 1000);
141   }
142
143   mag_set = mag;
144 }
145 /* sec 0295 */
146 void token_show_ (halfword p)
147 {
148   if (p != 0)
149     show_token_list(link(p), 0, 10000000L);
150 }
151 /* sec 0296 */
152 void print_meaning (void) 
153 {
154   print_cmd_chr(cur_cmd, cur_chr);
155
156   if (cur_cmd >= call)
157   {
158     print_char(':');
159     print_ln();
160     token_show(cur_chr);
161   }
162   else if (cur_cmd == top_bot_mark)
163   {
164     print_char(':');
165     print_ln();
166     token_show(cur_mark[cur_chr]);
167   }
168 }
169 /* sec 0299 */
170 void show_cur_cmd_chr (void)
171
172   begin_diagnostic();
173   print_nl("{");
174
175   if (mode != shown_mode)
176   {
177     print_mode(mode);
178     prints(": ");
179     shown_mode = mode;
180   }
181
182   print_cmd_chr(cur_cmd, cur_chr);
183   print_char('}');
184   end_diagnostic(false);
185 }
186 /* sec 0311 */
187 void show_context (void)
188 {
189   char old_setting;
190   integer nn;
191   boolean bottom_line;
192   integer i;
193   integer j;
194   integer l;
195   integer m;
196   integer n;
197   integer p;
198   integer q;
199
200   base_ptr = input_ptr;
201   input_stack[base_ptr] = cur_input;
202   nn = -1;
203   bottom_line = false;
204
205   while (true)
206   {
207     cur_input = input_stack[base_ptr];
208
209     if ((state != token_list))
210       if ((name > 17) || (base_ptr == 0))
211         bottom_line = true;
212
213     if ((base_ptr == input_ptr) || bottom_line || (nn < error_context_lines))
214     {
215       if ((base_ptr == input_ptr) || (state != token_list) ||
216           (index != backed_up) || (loc != 0))
217       {
218         tally = 0;
219         old_setting = selector;
220
221         if (state != token_list)
222         {
223           if (name <= 17)
224             if (name == 0)
225               if (base_ptr == 0)
226                 print_nl("<*>");
227               else
228                 print_nl("<insert> ");
229             else
230             {
231               print_nl("<read ");
232
233               if (name == 17)
234                 print_char('*');
235               else
236                 print_int(name - 1);
237
238               print_char('>');
239             }
240           else
241           {
242             if (c_style_flag)
243             {
244               print_ln();
245
246               if (name > 17)
247                 print(name);
248
249               print_char('(');
250               print_int(line);
251               prints(") :");
252             }
253             else
254             {
255               print_nl("l.");
256               print_int(line);
257             }
258           }
259
260           print_char(' ');
261           begin_pseudoprint();
262
263           if (buffer[limit] == end_line_char)
264             j = limit;
265           else
266             j = limit + 1;
267
268           if (j > 0)
269             for (i = start; i <= j - 1; i++)
270             {
271               if (i == loc)
272                 set_trick_count();
273
274               print(buffer[i]);
275             }
276         }
277         else
278         {
279           switch (index)
280           {
281             case parameter:
282               print_nl("<argument> ");
283               break;
284
285             case u_template:
286             case v_template:
287               print_nl("<template> ");
288               break;
289
290             case backed_up:
291               if (loc == 0)
292                 print_nl("<recently read> ");
293               else
294                 print_nl("<to be read again> ");
295               break;
296
297             case inserted:
298               print_nl("<inserted text> ");
299               break;
300
301             case macro:
302               print_ln();
303               print_cs(name);
304               break;
305
306             case output_text:
307               print_nl("<output> ");
308               break;
309
310             case every_par_text:
311               print_nl("<everypar> ");
312               break;
313
314             case every_math_text:
315               print_nl("<everymath> ");
316               break;
317
318             case every_display_text:
319               print_nl("<everydisplay> ");
320               break;
321
322             case every_hbox_text:
323               print_nl("<everyhbox> ");
324               break;
325
326             case every_vbox_text:
327               print_nl("<everyvbox> ");
328               break;
329
330             case every_job_text:
331               print_nl("<everyjob> ");
332               break;
333
334             case every_cr_text:
335               print_nl("<everycr> ");
336               break;
337
338             case mark_text:
339               print_nl("<mark> ");
340               break;
341
342             case write_text:
343               print_nl("<write> ");
344               break;
345
346             default:
347               print_nl("?");
348               break;
349           }
350
351           begin_pseudoprint();
352
353           if (index < macro)
354             show_token_list(start, loc, 100000L);
355           else
356             show_token_list(link(start), loc, 100000L);
357         }
358
359         selector = old_setting;
360
361         if (trick_count == 1000000L)
362           set_trick_count();
363         
364         if (tally < trick_count)
365           m = tally - first_count;
366         else
367           m = trick_count - first_count;
368
369         if (l + first_count <= half_error_line)
370         {
371           p = 0;
372           n = l + first_count;
373         }
374         else
375         {
376           prints("...");
377           p = l + first_count - half_error_line + 3;
378           n = half_error_line;
379         }
380
381         for (q = p; q <= first_count - 1; q++)
382           print_char(trick_buf[q % error_line]);
383
384         print_ln();
385
386         for (q = 1; q <= n; q++)
387           print_char(' ');
388
389         if (m + n <= error_line)
390           p = first_count + m;
391         else
392           p = first_count +(error_line - n - 3);
393
394         for (q = first_count; q <= p - 1; q++)
395           print_char(trick_buf[q % error_line]);
396
397         if (m + n > error_line)
398           prints("...");
399
400         incr(nn);
401       }
402     }
403     else if (nn == error_context_lines)
404     {
405       print_nl("...");
406       incr(nn); 
407     }
408
409     if (bottom_line)
410       goto done;
411
412     decr(base_ptr);
413   }
414
415 done:
416   cur_input = input_stack[input_ptr];
417 }
418 /* sec 0323 */
419 void begin_token_list_ (halfword p, quarterword t)
420 {
421   push_input();
422   state = token_list;
423   start = p;
424   index = t;
425
426   if (t >= macro)
427   {
428     add_token_ref(p);
429
430     if (t == macro)
431       limit = param_ptr;
432     else
433     {
434       loc = link(p);
435
436       if (tracing_macros > 1)
437       {
438         begin_diagnostic(); 
439         print_nl("");
440
441         switch (t)
442         {
443           case mark_text:
444             print_esc("mark");
445             break;
446
447           case write_text:
448             print_esc("write");
449             break;
450
451           default:
452             print_cmd_chr(assign_toks, t - output_text + output_routine_loc);
453             break;
454         }
455
456         prints("->");
457         token_show(p);
458         end_diagnostic(false);
459       }
460     }
461   }
462   else
463     loc = p;
464 }
465 /* sec 0324 */
466 void end_token_list (void) 
467
468   if (index >= backed_up)
469   {
470     if (index <= inserted)
471       flush_list(start); 
472     else
473     {
474       delete_token_ref(start);
475
476       if (index == macro)
477         while (param_ptr > limit)
478         {
479           decr(param_ptr);
480           flush_list(param_stack[param_ptr]);
481         }
482     }
483   }
484   else if (index == u_template)
485     if (align_state > 500000L)
486       align_state = 0;
487     else
488     {
489       fatal_error("(interwoven alignment preambles are not allowed)");
490       return;
491     }
492
493   pop_input();
494   check_interrupt();
495 }
496 /* sec 0325 */
497 void back_input (void)
498 {
499   halfword p;
500
501   while ((state == 0) && (loc == 0) &&
502       (index != v_template))
503   {
504     end_token_list();
505   }
506
507   p = get_avail();
508   info(p) = cur_tok;
509
510   if (cur_tok < right_brace_limit)
511     if (cur_tok < left_brace_limit)
512       decr(align_state);
513     else
514       incr(align_state);
515
516   push_input();
517   state = token_list;
518   start = p;
519   index = backed_up;
520   loc = p;
521 }
522 /* sec 0327 */
523 void back_error (void)
524 {
525   OK_to_interrupt = false;
526   back_input();
527   OK_to_interrupt = true;
528   error();
529 }
530 /* sec 0327 */
531 void ins_error (void) 
532 {
533   OK_to_interrupt = false;
534   back_input();
535   index = inserted;
536   OK_to_interrupt = true;
537   error();
538 }
539 /* sec 0328 */
540 void begin_file_reading (void)
541 {
542   if (in_open == max_in_open)
543   {
544     overflow("text input levels", max_in_open);
545     return;
546   }
547 #ifdef ALLOCATEBUFFER
548   if (first == current_buf_size)
549     buffer = realloc_buffer(increment_buf_size);
550
551   if (first == current_buf_size) /* check again after allocation */
552   {
553     overflow("buffer size", current_buf_size);
554     return;
555   }
556 #else
557   if (first == buf_size)
558   {
559     overflow("buffer size", buf_size);
560     return;
561   }
562 #endif
563
564   incr(in_open);
565
566   if (in_open > high_in_open) /* 1999 Jan 17 */
567     high_in_open = in_open;
568
569   push_input();
570   index = in_open;
571   line_stack[index] = line;
572   start = first;
573   state = 1;
574   name = 0;
575 }
576 /* sec 0329 */
577 void end_file_reading (void)
578 {
579   first = start;
580   line = line_stack[index];
581
582   if (name > 17)
583     a_close(cur_file);
584
585   pop_input();
586   decr(in_open);
587 }
588 /* called only form tex0.c */
589 /* sec 0330 */
590 void clear_for_error_prompt (void) 
591 {
592   while ((state != 0) && (name == 0) &&
593     (input_ptr > 0) && (loc > limit))
594     end_file_reading();
595
596   print_ln();
597 }
598 /* sec 0336 */
599 void check_outer_validity (void)
600 {
601   halfword p;
602   halfword q;
603
604   if (scanner_status != 0)
605   {
606     deletions_allowed = false;
607
608     if (cur_cs != 0)
609     {
610       if ((state == 0) || (name < 1) || (name > 17))
611       {
612         p = get_avail();
613         info(p) = cs_token_flag + cur_cs;
614         back_list(p);
615       }
616
617       cur_cmd = spacer;
618       cur_chr = ' ';
619     }
620
621     if (scanner_status > skipping)
622     {
623       runaway();
624
625       if (cur_cs == 0)
626         print_err("File ended");
627       else
628       {
629         cur_cs = 0;
630         print_err("Forbidden control sequence found");
631       }
632
633       prints(" while scanning ");
634       p = get_avail();
635
636       switch (scanner_status)
637       {
638         case defining:
639           prints("definition");
640           info(p) = right_brace_token + '}';
641           break;
642
643         case matching:
644           prints("use");
645           info(p) = par_token;
646           long_state = outer_call;
647           break;
648
649         case aligning:
650           prints("preamble");
651           info(p) = right_brace_token + '}';
652           q = p;
653           p = get_avail();
654           link(p) = q;
655           info(p) = cs_token_flag + frozen_cr;
656           align_state = -1000000L;
657           break;
658
659         case absorbing:
660           prints("text");
661           info(p) = right_brace_token + '}';
662           break;
663       }
664
665       ins_list(p);
666       prints(" of ");
667       sprint_cs(warning_index);
668       help4("I suspect you have forgotten a `}', causing me",
669           "to read past where you wanted me to stop.",
670           "I'll try to recover; but if the error is serious,",
671           "you'd better type `E' or `X' now and fix your file.");
672       error();
673     }
674     else
675     {
676       print_err("Incomplete ");
677       print_cmd_chr(if_test, cur_if);
678       prints("; all text was ignored after line ");
679       print_int(skip_line);
680       help3("A forbidden control sequence occurred in skipped text.",
681           "This kind of error happens when you say `\\if...' and forget",
682           "the matching `\\fi'. I've inserted a `\\fi'; this might work.");
683
684       if (cur_cs != 0)
685         cur_cs = 0; 
686       else
687         help_line[2] = "The file ended while I was skipping conditional text.";
688
689       cur_tok = cs_token_flag + frozen_fi;
690       ins_error();
691     }
692
693     deletions_allowed = true;
694   }
695 }
696 /* sec 0363 */
697 void firm_up_the_line (void)
698 {
699   integer k;
700
701   limit = last;
702
703   if (pausing > 0)
704     if (interaction > nonstop_mode)
705     {
706       ;
707       print_ln();
708
709       if (start < limit)
710         for (k = start; k <= limit - 1; k++)
711           print(buffer[k]);
712
713       first = limit;
714       prompt_input("=>");
715
716       if (last > first)
717       {
718         for (k = first; k <= last - 1; k++)
719           buffer[k + start - first] = buffer[k];
720
721         limit = start + last - first;
722       }
723     }
724 }
725 /* sec 0365 */
726 void get_token (void)
727
728   no_new_control_sequence = false;
729   get_next();
730   no_new_control_sequence = true;
731
732   if (cur_cs == 0)
733     cur_tok = (cur_cmd * 256) + cur_chr;
734   else
735     cur_tok = cs_token_flag + cur_cs;
736 }
737 /* sec 0389 */
738 void macro_call (void)
739 {
740   halfword r;
741   halfword p;
742   halfword q;
743   halfword s;
744   halfword t;
745   halfword u, v;
746   halfword rbrace_ptr;
747   small_number n;
748   halfword unbalance;
749   halfword m;
750   halfword ref_count;
751   small_number save_scanner_status;
752   halfword save_warning_index;
753   ASCII_code match_chr;
754
755   save_scanner_status = scanner_status;
756   save_warning_index = warning_index;
757   warning_index = cur_cs;
758   ref_count = cur_chr;
759   r = link(ref_count);
760   n = 0;
761
762   if (tracing_macros > 0)
763   {
764     begin_diagnostic();
765     print_ln();
766     print_cs(warning_index);
767     token_show(ref_count);
768     end_diagnostic(false);
769   }
770
771   if (info(r) != end_match_token)
772   {
773     scanner_status = matching;
774     unbalance = 0;
775     long_state = eq_type(cur_cs);
776
777     if (long_state >= outer_call)
778       long_state = long_state - 2;
779
780     do
781       {
782         link(temp_head) = 0;
783
784         if ((info(r) > match_token + 255) || (info(r) < match_token))
785           s = 0;
786         else
787         {
788           match_chr = info(r) - match_token;
789           s = link(r);
790           r = s;
791           p = temp_head;
792           m = 0;
793         }
794
795 continu:
796         get_token();
797
798         if (cur_tok == info(r))
799         {
800           r = link(r);
801
802           if ((info(r) >= match_token) && (info(r) <= end_match_token))
803           {
804             if (cur_tok < left_brace_limit)
805               decr(align_state);
806
807             goto found;
808           }
809           else
810             goto continu;
811         }
812
813         if (s != r)
814           if (s == 0)
815           {
816             print_err("Use of ");
817             sprint_cs(warning_index);
818             prints(" doesn't match its definition");
819             help4("If you say, e.g., `\\def\\a1{...}', then you must always",
820               "put `1' after `\\a', since control sequence names are",
821               "made up of letters only. The macro here has not been",
822               "followed by the required stuff, so I'm ignoring it.");
823             error();
824             goto exit;
825           }
826           else
827           {
828             t = s;
829
830             do
831               {
832                 store_new_token(info(t));
833                 incr(m);
834                 u = link(t);
835                 v = s;
836
837                 while (true)
838                 {
839                   if (u == r)
840                     if (cur_tok != info(v))
841                       goto done;
842                     else
843                     {
844                       r = link(v);
845                       goto continu;
846                     }
847
848                     if (info(u) != info(v))
849                       goto done;
850
851                     u = link(u);
852                     v = link(v);
853                 }
854 done:
855                 t = link(t);
856               }
857             while (!(t == r));
858
859             r = s;
860           }
861
862         if (cur_tok == par_token)
863           if (long_state != long_call)
864           {
865             if (long_state == call)
866             {
867               runaway();
868               print_err("Paragraph ended before ");
869               sprint_cs(warning_index);
870               prints("was complete");
871               help3("I suspect you've forgotten a `}', causing me to apply this",
872                   "control sequence to too much text. How can we recover?",
873                   "My plan is to forget the whole thing and hope for the best.");
874               back_error();
875             }
876
877             pstack[n] = link(temp_head);
878             align_state = align_state - unbalance;
879
880             for (m = 0; m <= n; m++)
881               flush_list(pstack[m]);
882
883             goto exit;
884           }
885
886         if (cur_tok < right_brace_limit)
887           if (cur_tok < left_brace_limit)
888           {
889             unbalance = 1;
890
891             while (true)
892             {
893               fast_store_new_token(cur_tok);
894               get_token();
895
896               if (cur_tok == par_token)
897                 if (long_state != long_call)
898                 {
899                   if (long_state == call)
900                   {
901                     runaway();
902                     print_err("Paragraph ended before ");
903                     sprint_cs(warning_index);
904                     prints(" was complete");
905                     help3("I suspect you've forgotten a `}', causing me to apply this",
906                         "control sequence to too much text. How can we recover?",
907                         "My plan is to forget the whole thing and hope for the best.");
908                     back_error();
909                   }
910
911                   pstack[n] = link(temp_head);
912                   align_state = align_state - unbalance;
913
914                   for (m = 0; m <= n; m++)
915                     flush_list(pstack[m]);
916                   goto exit;
917                 }
918
919               if (cur_tok < right_brace_limit)
920                 if (cur_tok < left_brace_limit)
921                   incr(unbalance);
922                 else
923                 {
924                   decr(unbalance);
925
926                   if (unbalance == 0)
927                     goto done1;
928                 }
929             }
930 done1:
931             rbrace_ptr = p;
932             store_new_token(cur_tok);
933           }
934           else
935           {
936             back_input();
937             print_err("Argument of ");
938             sprint_cs(warning_index);
939             prints(" has an extra }");
940             help6("I've run across a `}' that doesn't seem to match anything.",
941                 "For example, `\\def\\a#1{...}' and `\\a}' would produce",
942                 "this error. If you simply proceed now, the `\\par' that",
943                 "I've just inserted will cause me to report a runaway",
944                 "argument that might be the root of the problem. But if",
945                 "your `}' was spurious, just type `2' and it will go away.");
946             incr(align_state);
947             long_state = call;
948             cur_tok = par_token;
949             ins_error();
950             goto continu;
951           }
952         else
953         {
954           if (cur_tok == space_token)
955             if (info(r) <= end_match_token)
956               if (info(r) >= match_token)
957                 goto continu;
958
959           store_new_token(cur_tok);
960         }
961
962         incr(m);
963
964         if (info(r) > end_match_token)
965           goto continu;
966
967         if (info(r) < match_token)
968           goto continu;
969 found:
970         if (s != 0)
971         {
972           if ((m == 1) && (info(p) < right_brace_limit) && (p != temp_head))
973           {
974             link(rbrace_ptr) = 0;
975             free_avail(p);
976             p = link(temp_head);
977             pstack[n] = link(p);
978             free_avail(p);
979           }
980           else
981             pstack[n] = link(temp_head);
982
983           incr(n);
984
985           if (tracing_macros > 0)
986           {
987             begin_diagnostic();
988             //print_nl(match_chr);
989             print_nl(""); print(match_chr);
990             print_int(n);
991             prints("<-");
992             show_token_list(pstack[n - 1], 0, 1000);
993             end_diagnostic(false);
994           }
995         }
996       }
997     while (!(info(r) == end_match_token));
998   }
999
1000   while ((state == token_list) && (loc == 0) &&
1001       (index != v_template))
1002     end_token_list();
1003
1004   begin_token_list(ref_count, macro);
1005   name = warning_index;
1006   loc = link(r);
1007
1008   if (n > 0)
1009   {
1010     if (param_ptr + n > max_param_stack)
1011     {
1012       max_param_stack = param_ptr + n;
1013
1014 #ifdef ALLOCATEPARAMSTACK
1015       if (max_param_stack > current_param_size)
1016         param_stack = realloc_param_stack(increment_param_size);
1017
1018       if (max_param_stack > current_param_size)
1019       {
1020         overflow("parameter stack size", current_param_size);
1021         return;
1022       }
1023 #else
1024       if (max_param_stack > param_size)
1025       {
1026         overflow("parameter stack size", param_size);
1027         return;
1028       }
1029 #endif
1030     }
1031
1032     for (m = 0; m <= n - 1; m++)
1033       param_stack[param_ptr + m] = pstack[m];
1034
1035     param_ptr = param_ptr + n;
1036   }
1037 exit:
1038   scanner_status = save_scanner_status;
1039   warning_index = save_warning_index;
1040 }
1041 /* sec 0379 */
1042 void insert_relax (void)
1043 {
1044   cur_tok = cs_token_flag + cur_cs;
1045   back_input();
1046   cur_tok = cs_token_flag + frozen_relax;  /* 96/Jan/10 */
1047   back_input();
1048   index = inserted;
1049 }
1050 /* sec 0366 */
1051 void expand (void)
1052 {
1053   halfword t;
1054   pointer p, q, r;
1055   integer j;
1056   integer cv_backup;
1057   small_number cvl_backup, radix_backup, co_backup;
1058   halfword backup_backup;
1059   small_number save_scanner_status;
1060
1061   cv_backup = cur_val;
1062   cvl_backup = cur_val_level;
1063   radix_backup = radix;
1064   co_backup = cur_order;
1065   backup_backup = link(backup_head);
1066
1067   if (cur_cmd < call)
1068   {
1069     if (tracing_commands > 1)
1070       show_cur_cmd_chr();
1071
1072     switch (cur_cmd)
1073     {
1074       case top_bot_mark:
1075         if (cur_mark[cur_chr] != 0)
1076           begin_token_list(cur_mark[cur_chr], mark_text);
1077         break;
1078
1079       case expand_after:
1080         get_token();
1081         t = cur_tok;
1082         get_token();
1083
1084         if (cur_cmd > max_command)
1085           expand();
1086         else
1087           back_input();
1088
1089         cur_tok = t;
1090         back_input();
1091         break;
1092
1093       case no_expand:
1094         save_scanner_status = scanner_status;
1095         scanner_status = normal;
1096         get_token();
1097         scanner_status = save_scanner_status;
1098         t = cur_tok;
1099         back_input();
1100
1101         if (t >= cs_token_flag)
1102         {
1103           p = get_avail();
1104           info(p) = cs_token_flag + frozen_dont_expand;
1105           link(p) = loc;
1106           start = p;
1107           loc = p;
1108         }
1109         break;
1110
1111       case cs_name:
1112         r = get_avail();
1113         p = r;
1114         do
1115           {
1116             get_x_token();
1117   
1118             if (cur_cs == 0)
1119               store_new_token(cur_tok);
1120           }
1121         while (!(cur_cs != 0));
1122
1123         if (cur_cmd != end_cs_name)
1124         {
1125           print_err("Missing ");
1126           print_esc("endcsname");
1127           prints(" inserted");
1128           help2("The control sequence marked <to be read again> should",
1129               "not appear between \\csname and \\endcsname.");
1130           back_error();
1131         }
1132
1133         j = first;
1134         p = link(r);
1135
1136         while (p != 0)
1137         {
1138           if (j >= max_buf_stack)
1139           {
1140             max_buf_stack = j + 1;
1141
1142 #ifdef ALLOCATEBUFFER
1143             if (max_buf_stack == current_buf_size)
1144               buffer = realloc_buffer (increment_buf_size);
1145
1146             if (max_buf_stack == current_buf_size)
1147             {
1148               overflow("buffer size", current_buf_size);
1149               return;
1150             }
1151 #else
1152             if (max_buf_stack == buf_size)
1153             {
1154               overflow("buffer size", buf_size);
1155               return;
1156             }
1157 #endif
1158           }
1159
1160           buffer[j] = info(p) % 256;
1161           incr(j);
1162           p = link(p);
1163         }
1164
1165         if (j > first + 1)
1166         {
1167           no_new_control_sequence = false;
1168           cur_cs = id_lookup(first, j - first);
1169           no_new_control_sequence = true;
1170         }
1171         else if (j == first)
1172           cur_cs = null_cs;
1173         else
1174           cur_cs = single_base + buffer[first];
1175
1176         flush_list(r);
1177
1178         if (eq_type(cur_cs) == undefined_cs)
1179         {
1180           eq_define(cur_cs, relax, 256);
1181         }
1182
1183         cur_tok = cur_cs + cs_token_flag;
1184         back_input();
1185         break;
1186
1187       case convert:
1188         conv_toks();
1189         break;
1190
1191       case the:
1192         ins_the_toks();
1193         break;
1194
1195       case if_test:
1196         conditional();
1197         break;
1198
1199       case fi_or_else:
1200         if (cur_chr > if_limit)
1201           if (if_limit == 1)
1202             insert_relax();
1203           else
1204           {
1205             print_err("Extra ");
1206             print_cmd_chr(fi_or_else, cur_chr);
1207             help1("I'm ignoring this; it doesn't match any \\if.");
1208             error();
1209           }
1210         else
1211         {
1212           while (cur_chr != fi_code)
1213             pass_text();
1214
1215           {
1216             p = cond_ptr;
1217             if_line = if_line_field(p);
1218             cur_if = subtype(p);
1219             if_limit = type(p);
1220             cond_ptr = link(p);
1221             free_node(p, if_node_size);
1222           }
1223         }
1224         break;
1225
1226       case input:
1227         if (cur_chr > 0)
1228           force_eof = true;
1229         else if (name_in_progress)
1230           insert_relax();
1231         else
1232           start_input();
1233         break;
1234
1235       default:
1236         print_err("Undefined control sequence");
1237         help5("The control sequence at the end of the top line",
1238             "of your error message was never \\def'ed. If you have",
1239             "misspelled it (e.g., `\\hobx'), type `I' and the correct",
1240             "spelling (e.g., `I\\hbox'). Otherwise just continue,",
1241             "and I'll forget about whatever was undefined.");
1242         error();
1243         break;
1244     }
1245   }
1246   else if (cur_cmd < end_template)
1247   {
1248     macro_call();
1249   }
1250   else
1251   {
1252     cur_tok = cs_token_flag + frozen_endv;
1253     back_input();
1254   }
1255
1256   cur_val = cv_backup;
1257   cur_val_level = cvl_backup;
1258   radix = radix_backup;
1259   cur_order = co_backup;
1260   link(backup_head) = backup_backup;
1261 }
1262 /* sec 0380 */
1263 void get_x_token (void)
1264 {
1265 restart:
1266   get_next();
1267
1268   if (cur_cmd <= max_command)
1269     goto done;
1270
1271   if (cur_cmd >= call)
1272     if (cur_cmd < end_template)
1273       macro_call();
1274     else
1275     {
1276       cur_cs = frozen_endv;
1277       cur_cmd = endv;
1278       goto done;
1279     }
1280   else
1281     expand();
1282
1283   goto restart;
1284
1285 done:
1286   if (cur_cs == 0)
1287     cur_tok = (cur_cmd * 256) + cur_chr;
1288   else
1289     cur_tok = cs_token_flag + cur_cs;
1290 }
1291 /* sec 0381 */
1292 void x_token (void)
1293 {
1294   while (cur_cmd > max_command)
1295   {
1296     expand();
1297     get_next();
1298   }
1299
1300   if (cur_cs == 0)
1301     cur_tok = (cur_cmd * 256) + cur_chr;
1302   else
1303     cur_tok = cs_token_flag + cur_cs;
1304 }
1305 /* sec 0403 */
1306 void scan_left_brace (void)
1307 {
1308   do
1309     {
1310       get_x_token();
1311     }
1312   while (!((cur_cmd != spacer) && (cur_cmd != relax)));
1313
1314   if (cur_cmd != left_brace)
1315   {
1316     print_err("Missing { inserted");
1317     help4("A left brace was mandatory here, so I've put one in.",
1318         "You might want to delete and/or insert some corrections",
1319         "so that I will find a matching right brace soon.",
1320         "(If you're confused by all this, try typing `I}' now.)");
1321     back_error();
1322     cur_tok = left_brace_token + '{';
1323     cur_cmd = left_brace;
1324     cur_chr = '{';
1325     incr(align_state);
1326   }
1327 }
1328 /* sec 0405 */
1329 void scan_optional_equals (void)
1330 {
1331   do
1332     {
1333       get_x_token();
1334     }
1335   while (!(cur_cmd != spacer));
1336
1337   if (cur_tok != other_token + '=')
1338     back_input();
1339 }
1340 /* sec 0407 */
1341 boolean scan_keyword(const char * s)
1342 {
1343   halfword p;
1344   halfword q;
1345   const char * k;
1346
1347   p = backup_head;
1348   link(p) = 0;
1349   k = s;
1350
1351   while (*k)
1352   {
1353     get_x_token(); 
1354
1355     if ((cur_cs == 0) && ((cur_chr == (*k)) || (cur_chr == (*k) - 'a' + 'A')))
1356     {
1357       store_new_token(cur_tok);
1358       incr(k);
1359     }
1360     else if ((cur_cmd != spacer) || (p != backup_head))
1361     {
1362       back_input();
1363
1364       if (p != backup_head)
1365         back_list(link(backup_head));
1366
1367       return false;
1368     }
1369   }
1370
1371   flush_list(link(backup_head));
1372
1373   return true;
1374 }
1375 /* sec 0408 */
1376 void mu_error (void)
1377 {
1378   print_err("Incompatible glue units");
1379   help1("I'm going to assume that 1mu=1pt when they're mixed.");
1380   error();
1381 }
1382 /* sec 0433 */
1383 void scan_eight_bit_int (void)
1384 {
1385   scan_int();
1386
1387   if ((cur_val < 0) || (cur_val > 255))
1388   {
1389     print_err("Bad register code");
1390     help2("A register number must be between 0 and 255.",
1391         "I changed this one to zero.");
1392     int_error(cur_val);
1393     cur_val = 0;
1394   }
1395 }
1396 /* sec 0434 */
1397 void scan_char_num (void)
1398 {
1399   scan_int();
1400
1401   if ((cur_val < 0) || (cur_val > 255))
1402   {
1403     print_err("Bad character code");
1404     help2("A character number must be between 0 and 255.",
1405         "I changed this one to zero.");
1406     int_error(cur_val);
1407     cur_val = 0;
1408   }
1409 }
1410 /* sec 0435 */
1411 void scan_four_bit_int (void)
1412 {
1413   scan_int();
1414
1415   if ((cur_val < 0) || (cur_val > 15))
1416   {
1417     print_err("Bad number");
1418     help2("Since I expected to read a number between 0 and 15,",
1419         "I changed this one to zero.");
1420     int_error(cur_val);
1421     cur_val = 0;
1422   }
1423 }
1424 /* sec 0436 */
1425 void scan_fifteen_bit_int (void) 
1426 {
1427   scan_int();
1428
1429   if ((cur_val < 0) || (cur_val > 32767))
1430   {
1431     print_err("Bad mathchar");
1432     help2("A mathchar number must be between 0 and 32767.",
1433         "I changed this one to zero.");
1434     int_error(cur_val);
1435     cur_val = 0;
1436   }
1437 }
1438 /* sec 0437 */
1439 void scan_twenty_seven_bit_int (void)
1440 {
1441   scan_int();
1442
1443   if ((cur_val < 0) || (cur_val > 134217727L))
1444   {
1445     print_err("Bad delimiter code");
1446     help2("A numeric delimiter code must be between 0 and 2^{27}-1.",
1447         "I changed this one to zero.");
1448     int_error(cur_val);
1449     cur_val = 0;
1450   }
1451 }
1452 /* sec 0577 */
1453 void scan_font_ident (void) 
1454 {
1455   internal_font_number f;
1456   halfword m;
1457
1458   do
1459     {
1460       get_x_token();
1461     }
1462   while (!(cur_cmd != spacer));
1463
1464   if (cur_cmd == def_font)
1465     f = cur_font;
1466   else if (cur_cmd == set_font)
1467     f = cur_chr; 
1468   else if (cur_cmd == def_family)
1469   {
1470     m = cur_chr;
1471     scan_four_bit_int();
1472     f = equiv(m + cur_val);
1473   }
1474   else
1475   {
1476     print_err("Missing font identifier");
1477     help2("I was looking for a control sequence whose",
1478         "current meaning has been defined by \\font.");
1479     back_error();
1480     f = null_font;
1481   }
1482
1483   cur_val = f;
1484 }
1485 /* sec 0578 */
1486 void find_font_dimen_(boolean writing)
1487 {
1488   internal_font_number f;
1489   integer n;
1490
1491   scan_int();
1492   n = cur_val;
1493   scan_font_ident();
1494   f = cur_val;
1495
1496   if (n < 0)
1497     cur_val = fmem_ptr;
1498   else
1499   {
1500     if (writing && (n <= space_shrink_code) && (n >= space_code) && (font_glue[f] != 0)) 
1501     {
1502       delete_glue_ref(font_glue[f]);
1503       font_glue[f] = 0;
1504     }
1505
1506     if (n > font_params[f])
1507       if (f < font_ptr)
1508         cur_val = fmem_ptr;
1509       else
1510       {
1511         do
1512           {
1513  #ifdef ALLOCATEFONT
1514             if (fmem_ptr == current_font_mem_size)
1515               font_info = realloc_font_info(increment_font_mem_size);
1516
1517             if (fmem_ptr == current_font_mem_size)
1518             {
1519               overflow("font memory", current_font_mem_size);
1520               return;
1521             }
1522 #else
1523             if (fmem_ptr == font_mem_size)
1524             {
1525               overflow("font memory", font_mem_size);
1526               return;
1527             }
1528 #endif
1529             font_info[fmem_ptr].cint = 0;
1530             incr(fmem_ptr);
1531             incr(font_params[f]);
1532           }
1533         while (!(n == font_params[f]));
1534
1535         cur_val = fmem_ptr - 1;
1536       }
1537     else if (n > 0)
1538       cur_val = n + param_base[f];
1539   }
1540
1541   if (cur_val == fmem_ptr)
1542   {
1543     print_err("Font ");
1544     print_esc(""); print(font_id_text(f));
1545     prints(" has only ");
1546     print_int(font_params[f]);
1547     prints(" fontdimen parameters");
1548     help2("To increase the number of font parameters, you must",
1549       "use \\fontdimen immediately after the \\font is loaded.");
1550     error();
1551   }
1552 }
1553 /* sec 0413 */
1554 void scan_something_internal_(small_number level, boolean negative)
1555 {
1556   halfword m;
1557   integer p;
1558
1559   m = cur_chr;
1560
1561   switch (cur_cmd)
1562   {
1563     case def_code:
1564       {
1565         scan_char_num();
1566
1567         if (m == math_code_base)
1568           scanned_result(math_code(cur_val), int_val);
1569         else if (m < math_code_base)
1570           scanned_result(equiv(m + cur_val), int_val);
1571         else
1572           scanned_result(eqtb[m + cur_val].cint, int_val);
1573       }
1574       break;
1575
1576     case toks_register:
1577     case assign_toks:
1578     case def_family:
1579     case set_font:
1580     case def_font:
1581       if (level != tok_val)
1582       {
1583         print_err("Missing number, treated as zero");
1584         help3("A number should have been here; I inserted `0'.",
1585             "(If you can't figure out why I needed to see a number,",
1586             "look up `weird error' in the index to The TeXbook.)");
1587         back_error();
1588         scanned_result(0, dimen_val);
1589       }
1590       else if (cur_cmd <= assign_toks)
1591       {
1592         if (cur_cmd < assign_toks)
1593         {
1594           scan_eight_bit_int();
1595           m = toks_base + cur_val;
1596         }
1597
1598         scanned_result(equiv(m), tok_val);
1599       }
1600       else
1601       {
1602         back_input();
1603         scan_font_ident();
1604         scanned_result(font_id_base + cur_val, ident_val);
1605       }
1606       break;
1607
1608     case assign_int:
1609       scanned_result(eqtb[m].cint, int_val);
1610       break;
1611
1612     case assign_dimen:
1613       scanned_result(eqtb[m].cint, dimen_val);
1614       break; 
1615
1616     case assign_glue:
1617       scanned_result(equiv(m), glue_val);
1618       break;
1619
1620     case assign_mu_glue:
1621       scanned_result(equiv(m), mu_val);
1622       break;
1623
1624     case set_aux:
1625       if (abs(mode) != m)
1626       {
1627         print_err("Improper ");
1628         print_cmd_chr(set_aux, m);
1629         help4("You can refer to \\spacefactor only in horizontal mode;",
1630             "you can refer to \\prevdepth only in vertical mode; and",
1631             "neither of these is meaningful inside \\write. So",
1632             "I'm forgetting what you said and using zero instead.");
1633         error();
1634
1635         if (level != tok_val)
1636           scanned_result(0, dimen_val);
1637         else
1638           scanned_result(0, int_val);
1639       }
1640       else if (m == vmode)
1641         scanned_result(prev_depth, dimen_val);
1642       else
1643         scanned_result(space_factor, int_val);
1644       break;
1645
1646     case set_prev_graf:
1647       if (mode == 0)
1648         scanned_result(0, int_val);
1649       else
1650       {
1651         nest[nest_ptr] = cur_list;
1652         p = nest_ptr;
1653
1654         while (abs(nest[p].mode_field) != vmode)
1655           decr(p);
1656
1657         scanned_result(nest[p].pg_field, int_val);
1658       }
1659       break;
1660
1661     case set_page_int:
1662       {
1663         if (m == 0)
1664           cur_val = dead_cycles; 
1665         else
1666           cur_val = insert_penalties;
1667
1668         cur_val_level = 0;
1669       }
1670       break;
1671
1672     case set_page_dimen:
1673       {
1674         if ((page_contents == 0) && (! output_active))
1675           if (m == 0)
1676             cur_val = max_dimen;
1677           else
1678             cur_val = 0;
1679         else
1680           cur_val = page_so_far[m];
1681
1682         cur_val_level = dimen_val;
1683       }
1684       break;
1685
1686     case set_shape:
1687       {
1688         if (par_shape_ptr == 0)
1689           cur_val = 0; 
1690         else
1691           cur_val = info(par_shape_ptr);
1692
1693         cur_val_level = int_val;
1694       }
1695       break;
1696
1697     case set_box_dimen:
1698       {
1699         scan_eight_bit_int();
1700
1701         if (box(cur_val) == 0)
1702           cur_val = 0;
1703         else
1704           cur_val = mem[box(cur_val) + m].cint;
1705
1706         cur_val_level = dimen_val;
1707       }
1708       break;
1709
1710     case char_given:
1711     case math_given:
1712       scanned_result(cur_chr, int_val);
1713       break;
1714
1715     case assign_font_dimen:
1716       {
1717         find_font_dimen(false);
1718         font_info[fmem_ptr].cint = 0;
1719         scanned_result(font_info[cur_val].cint, dimen_val);
1720       }
1721       break;
1722
1723     case assign_font_int:
1724       {
1725         scan_font_ident();
1726
1727         if (m == 0)
1728           scanned_result(hyphen_char[cur_val], int_val);
1729         else
1730           scanned_result(skew_char[cur_val], int_val);
1731       }
1732       break;
1733
1734     case tex_register:
1735       {
1736         scan_eight_bit_int();
1737
1738         switch (m)
1739         {
1740           case int_val:
1741             cur_val = count(cur_val);
1742             break;
1743
1744           case dimen_val:
1745             cur_val = dimen(cur_val);
1746             break;
1747
1748           case glue_val:
1749             cur_val = skip(cur_val);
1750             break;
1751
1752           case mu_val:
1753             cur_val = mu_skip(cur_val);
1754             break;
1755         }
1756         
1757         cur_val_level = m;
1758       }
1759       break;
1760
1761     case last_item:
1762       if (cur_chr > glue_val)
1763       {
1764         if (cur_chr == input_line_no_code)
1765           cur_val = line;
1766         else
1767           cur_val = last_badness;
1768
1769         cur_val_level = int_val;
1770       }
1771       else
1772       {
1773         if (cur_chr == glue_val)
1774           cur_val = zero_glue;
1775         else
1776           cur_val = 0;
1777
1778         cur_val_level = cur_chr;
1779
1780         if (!is_char_node(tail) && (mode != 0))
1781           switch (cur_chr)
1782           {
1783             case int_val:
1784               if (type(tail) == penalty_node)
1785                 cur_val = penalty(tail);
1786               break;
1787
1788             case dimen_val:
1789               if (type(tail) == kern_node)
1790                 cur_val = width(tail);
1791               break;
1792
1793             case glue_val:
1794               if (type(tail) == glue_node)
1795               {
1796                 cur_val = glue_ptr(tail);
1797
1798                 if (subtype(tail) == mu_glue)
1799                   cur_val_level = mu_val;
1800               }
1801               break;
1802           }
1803         else if ((mode == vmode) && (tail == head))
1804           switch (cur_chr)
1805           {
1806             case int_val:
1807               cur_val = last_penalty;
1808               break;
1809
1810             case dimen_val:
1811               cur_val = last_kern;
1812               break;
1813
1814             case glue_val:
1815               if (last_glue != empty_flag)
1816                 cur_val = last_glue;
1817               break;
1818           }
1819       }
1820       break;
1821
1822     default:
1823       {
1824         print_err("You can't use `");
1825         print_cmd_chr(cur_cmd, cur_chr);
1826         prints("' after ");
1827         print_esc("the");
1828         help1("I'm forgetting what you said and using zero instead.");
1829         error();
1830
1831         if (level != tok_val)
1832           scanned_result(0, dimen_val);
1833         else
1834           scanned_result(0, int_val);
1835       }
1836       break;
1837   }
1838
1839   while (cur_val_level > level)
1840   {
1841     if (cur_val_level == glue_val)
1842       cur_val = width(cur_val);
1843     else if (cur_val_level == mu_val)
1844       mu_error();
1845
1846     decr(cur_val_level);
1847   }
1848
1849   if (negative)
1850     if (cur_val_level >= 2)
1851     {
1852       cur_val = new_spec(cur_val);
1853
1854       {
1855         width(cur_val) = -width(cur_val);
1856         stretch(cur_val) = -stretch(cur_val);
1857         shrink(cur_val) = -shrink(cur_val);
1858       }
1859     }
1860     else
1861       cur_val = -cur_val;
1862   else if ((cur_val_level >= glue_val) && (cur_val_level <= mu_val))
1863     add_glue_ref(cur_val);
1864 }
1865 /* sec 0341 */
1866 void get_next (void)
1867 {
1868   integer k;
1869   halfword t;
1870 /* char cat; */
1871   int cat;
1872   ASCII_code c, cc;
1873   char d;
1874
1875 restart:
1876   cur_cs = 0;
1877
1878   if (state != token_list)
1879   {
1880 lab_switch:
1881     if (loc <= limit)
1882     {
1883       cur_chr = buffer[loc];
1884       incr(loc);
1885 reswitch:
1886       cur_cmd = cat_code(cur_chr);
1887
1888       switch (state + cur_cmd)
1889       {
1890         case any_state_plus(ignore):
1891         case skip_blanks + spacer:
1892         case new_line + spacer:
1893           goto lab_switch;
1894           break;
1895
1896         case any_state_plus(escape):
1897           {
1898             if (loc > limit)
1899               cur_cs = null_cs;
1900             else
1901             {
1902 start_cs:
1903               k = loc;
1904               cur_chr = buffer[k];
1905               cat = cat_code(cur_chr);
1906               incr(k);
1907
1908               if (cat == letter)
1909                 state = skip_blanks;
1910               else if (cat == spacer)
1911                 state = skip_blanks;
1912               else
1913                 state = mid_line;
1914
1915               if ((cat == letter) && (k <= limit))
1916               {
1917                 do
1918                   {
1919                     cur_chr = buffer[k];
1920                     cat = cat_code(cur_chr);
1921                     incr(k);
1922                   }
1923                 while (!((cat != letter) || (k > limit)));
1924
1925                 {
1926                   if (buffer[k]== cur_chr)
1927                     if (cat == sup_mark)
1928                       if (k < limit)
1929                       {
1930                         c = buffer[k + 1];
1931
1932                         if (c < 128)
1933                         {
1934                           d = 2;
1935                           if (is_hex(c))
1936                             if (k + 2 <= limit)
1937                             {
1938                               cc = buffer[k + 2];
1939
1940                               if (is_hex(cc))
1941                                 incr(d);
1942                             }
1943
1944                           if (d > 2)
1945                           {
1946                             hex_to_cur_chr();
1947                             buffer[k - 1] = cur_chr;
1948                           }
1949                           else if (c < 64)
1950                             buffer[k - 1] = c + 64;
1951                           else
1952                             buffer[k - 1] = c - 64;
1953
1954                           limit = limit - d;
1955                           first = first - d;
1956
1957                           while (k <= limit)
1958                           {
1959                             buffer[k] = buffer[k + d];
1960                             incr(k);
1961                           }
1962
1963                           goto start_cs;
1964                         }
1965                       }
1966                 }
1967
1968                 if (cat != letter)
1969                   decr(k);
1970
1971                 if (k > loc + 1)
1972                 {
1973                   cur_cs = id_lookup(loc, k - loc);
1974                   loc = k;
1975                   goto found;
1976                 }
1977               }
1978               else
1979               {
1980                 if (buffer[k] == cur_chr)
1981                   if (cat == sup_mark)
1982                     if (k < limit)
1983                     {
1984                       c = buffer[k + 1];
1985
1986                       if (c < 128)             /* ? */
1987                       {
1988                         d = 2;
1989
1990                         if (is_hex(c))
1991                           if (k + 2 <= limit)
1992                           {
1993                             cc = buffer[k + 2];
1994
1995                             if (is_hex(cc))
1996                               incr(d);
1997                           }
1998
1999                         if (d > 2)
2000                         {
2001                           hex_to_cur_chr();
2002                           buffer[k - 1] = cur_chr;
2003                         }
2004                         else if (c < 64)
2005                           buffer[k - 1] = c + 64;
2006                         else
2007                           buffer[k - 1] = c - 64;
2008
2009                         limit = limit - d;
2010                         first = first - d;
2011
2012                         while (k <= limit)
2013                         {
2014                           buffer[k] = buffer[k + d];
2015                           incr(k);
2016                         }
2017                         goto start_cs;
2018                       }
2019                     }
2020               }
2021               cur_cs = single_base + buffer[loc];
2022               incr(loc);
2023             }
2024 found:
2025             cur_cmd = eq_type(cur_cs);
2026             cur_chr = equiv(cur_cs);
2027             
2028             if (cur_cmd >= outer_call)
2029               check_outer_validity();
2030           }
2031           break;
2032
2033         case any_state_plus(active_char):
2034           {
2035             cur_cs = cur_chr + active_base;
2036             cur_cmd = eq_type(cur_cs);
2037             cur_chr = equiv(cur_cs);
2038             state = mid_line;
2039             
2040             if (cur_cmd >= outer_call)
2041               check_outer_validity();
2042           }
2043           break;
2044
2045         case any_state_plus(sup_mark):
2046           {
2047             if (cur_chr == buffer[loc])
2048               if (loc < limit)
2049               {
2050                 c = buffer[loc + 1];
2051
2052                 if (c < 128)
2053                 {
2054                   loc = loc + 2;
2055
2056                   if (is_hex(c))
2057                     if (loc <= limit)
2058                     {
2059                       cc = buffer[loc];
2060
2061                       if (is_hex(cc))
2062                       {
2063                         incr(loc);
2064                         hex_to_cur_chr();
2065                         goto reswitch;
2066                       }
2067                     }
2068
2069                   if (c < 64)
2070                     cur_chr = c + 64;
2071                   else
2072                     cur_chr = c - 64;
2073
2074                   goto reswitch;
2075                 }
2076               }
2077
2078               state = mid_line;
2079           }
2080           break;
2081
2082         case any_state_plus(invalid_char):
2083           {
2084             print_err("Text line contains an invalid character");
2085             help2("A funny symbol that I can't read has just been input.",
2086                 "Continue, and I'll forget that it ever happened.");
2087             deletions_allowed = false;
2088             error();
2089             deletions_allowed = true;
2090             goto restart;
2091           }
2092           break;
2093
2094         case mid_line + spacer:
2095           {
2096             state = skip_blanks;
2097             cur_chr = ' ';
2098           }
2099           break;
2100
2101         case mid_line + car_ret:
2102           {
2103             loc = limit + 1;
2104             cur_cmd = spacer;
2105             cur_chr = ' ';
2106           }
2107           break;
2108
2109         case skip_blanks + car_ret:
2110         case any_state_plus(comment):
2111           {
2112             loc = limit + 1;
2113             goto lab_switch;
2114           }
2115           break;
2116
2117         case new_line + car_ret:
2118           {
2119             loc = limit + 1;
2120             cur_cs = par_loc;
2121             cur_cmd = eq_type(cur_cs);
2122             cur_chr = equiv(cur_cs);
2123             
2124             if (cur_cmd >= outer_call)
2125               check_outer_validity();
2126           }
2127           break;
2128
2129         case mid_line + left_brace:
2130           incr(align_state);
2131           break;
2132
2133         case skip_blanks + left_brace:
2134         case new_line + left_brace:
2135           {
2136             state = mid_line;
2137             incr(align_state);
2138           }
2139           break;
2140
2141         case mid_line + right_brace:
2142           decr(align_state);
2143           break;
2144
2145         case skip_blanks + right_brace:
2146         case new_line + right_brace:
2147           {
2148             state = 1;
2149             decr(align_state);
2150           }
2151           break;
2152
2153         case add_delims_to(skip_blanks):
2154         case add_delims_to(new_line):
2155           state = 1;
2156           break;
2157
2158         default:
2159           break;
2160       }
2161     }
2162     else
2163     {
2164       state = new_line;
2165
2166       if (name > 17)
2167       {
2168         incr(line);
2169         first = start;
2170
2171         if (!force_eof)
2172         {
2173           if (input_ln(cur_file, true))
2174             firm_up_the_line();
2175           else
2176             force_eof = true;
2177         }
2178
2179         if (force_eof)
2180         {
2181           print_char(')');
2182           decr(open_parens);
2183           update_terminal();
2184           force_eof = false;
2185           end_file_reading();
2186           check_outer_validity();
2187           goto restart;
2188         }
2189
2190         if (end_line_char_inactive())
2191           decr(limit);
2192         else
2193           buffer[limit] = end_line_char;
2194
2195         first = limit + 1;
2196         loc = start;
2197       }
2198       else
2199       {
2200         if (!(name == 0))
2201         {
2202           cur_cmd = 0;
2203           cur_chr = 0;
2204           return;
2205         }
2206
2207         if (input_ptr > 0)
2208         {
2209           end_file_reading();
2210           goto restart;
2211         }
2212
2213         if (selector < log_only)
2214           open_log_file();
2215
2216         if (interaction > nonstop_mode)
2217         {
2218           if (end_line_char_inactive())
2219             incr(limit);
2220
2221           if (limit == start)
2222             print_nl("(Please type a command or say `\\end')");
2223
2224           print_ln();
2225           first = start;
2226           prompt_input("*");
2227           limit = last;
2228
2229           if (end_line_char_inactive())
2230             decr(limit);
2231           else
2232             buffer[limit]= end_line_char;
2233
2234           first = limit + 1;
2235           loc = start;
2236         }
2237         else
2238         {
2239           fatal_error("*** (job aborted, no legal \\end found)");
2240           return;
2241         }
2242       }
2243
2244       check_interrupt();
2245       goto lab_switch;
2246     }
2247   }
2248   else if (loc != 0)
2249   {
2250     t = info(loc);
2251     loc = link(loc);
2252
2253     if (t >= cs_token_flag)
2254     {
2255       cur_cs = t - cs_token_flag;
2256       cur_cmd = eq_type(cur_cs);
2257       cur_chr = equiv(cur_cs);
2258
2259       if (cur_cmd >= outer_call)
2260         if (cur_cmd == dont_expand)
2261         {
2262           cur_cs = info(loc) - cs_token_flag;
2263           loc = 0;
2264           cur_cmd = eq_type(cur_cs);
2265           cur_chr = equiv(cur_cs);
2266
2267           if (cur_cmd > max_command)
2268           {
2269             cur_cmd = relax;
2270             cur_chr = no_expand_flag;
2271           }
2272         }
2273         else
2274         {
2275           check_outer_validity();
2276         }
2277     }
2278     else
2279     {
2280       cur_cmd = t / 256;
2281       cur_chr = t % 256;
2282
2283       switch (cur_cmd)
2284       {
2285         case left_brace:
2286           incr(align_state);
2287           break;
2288
2289         case right_brace:
2290           decr(align_state);
2291           break;
2292
2293         case out_param:
2294           {
2295             begin_token_list(param_stack[limit + cur_chr - 1], parameter);
2296             goto restart;
2297           }
2298           break;
2299
2300         default:
2301           break;
2302       }
2303     }
2304   }
2305   else
2306   {
2307     end_token_list();
2308     goto restart;
2309   }
2310
2311   if (cur_cmd <= car_ret)
2312     if (cur_cmd >= tab_mark)
2313       if (align_state == 0)
2314       {
2315         if ((scanner_status == aligning) && (cur_align == 0))
2316         {
2317           fatal_error("(interwoven alignment preambles are not allowed)");
2318           return;
2319         }
2320
2321         cur_cmd = extra_info(cur_align);
2322         extra_info(cur_align) = cur_chr;
2323
2324         if (cur_cmd == omit)
2325           begin_token_list(omit_template, v_template);
2326         else
2327           begin_token_list(v_part(cur_align), v_template);
2328
2329         align_state = 1000000L;
2330         goto restart;
2331       }
2332 }