OSDN Git Service

char * -> const char *.
[putex/putex.git] / src / texsourc / tex2.c
index 97a8847..3c33419 100644 (file)
 /* following bit used to be end of tex1.c */
 #ifdef STAT
 /* sec 0284 */
-void restore_trace_(halfword p, char * s)
+void restore_trace_(pointer p, const char * s)
 {
   begin_diagnostic();
   print_char('{');
-  print_string(s);
+  prints(s);
   print_char(' ');
   show_eqtb(p);
   print_char('}');
@@ -36,18 +36,20 @@ void restore_trace_(halfword p, char * s)
 /* sec 0281 */
 void unsave (void)
 {
-  halfword p;
+  pointer p;
   quarterword l;
   halfword t;
 
   if (cur_level > level_one)
   {
     decr(cur_level);
-    while (true) {
+
+    while (true)
+    {
       decr(save_ptr);
 
       if (save_type(save_ptr) == level_boundary)
-        goto lab30;
+        goto done;
 
       p = save_index(save_ptr);
 
@@ -75,7 +77,7 @@ void unsave (void)
 #ifdef STAT
             if (tracing_restores > 0)
               restore_trace(p, "retaining");
-#endif /* STAT */
+#endif
           }
           else
           {
@@ -84,7 +86,7 @@ void unsave (void)
 #ifdef STAT
             if (tracing_restores > 0)
               restore_trace(p, "restoring");
-#endif /* STAT */
+#endif
           }
         else if (xeq_level[p] != level_one)
         {
@@ -93,25 +95,26 @@ void unsave (void)
 #ifdef STAT
           if (tracing_restores > 0)
             restore_trace(p, "restoring");
-#endif /* STAT */
+#endif
         }
         else
         {
 #ifdef STAT
           if (tracing_restores > 0)
             restore_trace(p, "retaining");
-#endif /* STAT */
+#endif
         }
       }
     }
-lab30:
+
+done:
     cur_group = save_level(save_ptr);
     cur_boundary = save_index(save_ptr);
   }
   else
   {
     confusion("curlevel");
-    return;       // abort_flag set
+    return;
   }
 }
 /* This is where the old tex2.c used to start */
@@ -122,7 +125,7 @@ void prepare_mag (void)
   {
     print_err("Incompatible magnification (");
     print_int(mag);
-    print_string(");");
+    prints(");");
     print_nl(" the previous value will be retained");
     help2("I can handle only one magnification ratio per job. So I've",
         "reverted to the magnification you used earlier on this run.");
@@ -141,7 +144,7 @@ void prepare_mag (void)
   mag_set = mag;
 }
 /* sec 0295 */
-void token_show_ (halfword p)
+void token_show_ (pointer p)
 {
   if (p != 0)
     show_token_list(link(p), 0, 10000000L);
@@ -173,7 +176,7 @@ void show_cur_cmd_chr (void)
   if (mode != shown_mode)
   {
     print_mode(mode);
-    print_string(": ");
+    prints(": ");
     shown_mode = mode;
   }
 
@@ -186,7 +189,7 @@ void show_context (void)
 {
   char old_setting;
   integer nn;
-  bool bottomline;
+  boolean bottom_line;
   integer i;
   integer j;
   integer l;
@@ -198,28 +201,28 @@ void show_context (void)
   base_ptr = input_ptr;
   input_stack[base_ptr] = cur_input;
   nn = -1;
-  bottomline = false;
+  bottom_line = false;
 
   while (true)
   {
     cur_input = input_stack[base_ptr];
 
-    if ((cur_input.state_field != 0))
-      if ((cur_input.name_field > 17) || (base_ptr == 0))
-        bottomline = true;
+    if ((state != token_list))
+      if ((name > 17) || (base_ptr == 0))
+        bottom_line = true;
 
-    if ((base_ptr == input_ptr) || bottomline || (nn < error_context_lines))
+    if ((base_ptr == input_ptr) || bottom_line || (nn < error_context_lines))
     {
-      if ((base_ptr == input_ptr) || (cur_input.state_field != token_list) ||
-          (cur_input.index_field != backed_up) || (cur_input.loc_field != 0))
+      if ((base_ptr == input_ptr) || (state != token_list) ||
+          (index != backed_up) || (loc != 0))
       {
         tally = 0;
         old_setting = selector;
 
-        if (cur_input.state_field != 0)
+        if (state != token_list)
         {
-          if (cur_input.name_field <= 17)
-            if ((cur_input.name_field == 0))
+          if (name <= 17)
+            if (name == 0)
               if (base_ptr == 0)
                 print_nl("<*>");
               else
@@ -227,10 +230,12 @@ void show_context (void)
             else
             {
               print_nl("<read ");
-              if (cur_input.name_field == 17)
+
+              if (name == 17)
                 print_char('*');
               else
-                print_int(cur_input.name_field - 1);
+                print_int(name - 1);
+
               print_char('>');
             }
           else
@@ -238,54 +243,41 @@ void show_context (void)
             if (c_style_flag)
             {
               print_ln();
-              /* show current input file name - ignore if from terminal */
-              if (cur_input.name_field > 17)  /* redundant ? */
-                print(cur_input.name_field);
+
+              if (name > 17)
+                print(name);
 
               print_char('(');
-              print_int(line); /* line number */
-              print_char(')');
-              print_char(' ');
-              print_char(':');
+              print_int(line);
+              prints(") :");
             }
             else
             {
-              print_nl("l.");        /* l. ? 573 ????? 98/Dec/8 check ! */
-              print_int(line);      /* line number */
+              print_nl("l.");
+              print_int(line);
             }
           }
 
           print_char(' ');
+          begin_pseudoprint();
 
-          {
-            l = tally;
-            tally = 0;
-            selector = pseudo;
-            trick_count = 1000000L;
-          }
-
-          if (buffer[cur_input.limit_field] == end_line_char)
-            j = cur_input.limit_field;
+          if (buffer[limit] == end_line_char)
+            j = limit;
           else
-            j = cur_input.limit_field + 1;
+            j = limit + 1;
 
           if (j > 0)
-            for (i = cur_input.start_field; i <= j - 1; i++)
+            for (i = start; i <= j - 1; i++)
             {
-              if (i == cur_input.loc_field)
-              {
-                first_count = tally;
-                trick_count = tally + 1 + error_line - half_error_line;
+              if (i == loc)
+                set_trick_count();
 
-                if (trick_count < error_line)
-                  trick_count = error_line;
-              }
               print(buffer[i]);
             }
         }
         else
         {
-          switch (cur_input.index_field)
+          switch (index)
           {
             case parameter:
               print_nl("<argument> ");
@@ -297,7 +289,7 @@ void show_context (void)
               break;
 
             case backed_up:
-              if (cur_input.loc_field == 0)
+              if (loc == 0)
                 print_nl("<recently read> ");
               else
                 print_nl("<to be read again> ");
@@ -309,7 +301,7 @@ void show_context (void)
 
             case macro:
               print_ln();
-              print_cs(cur_input.name_field);
+              print_cs(name);
               break;
 
             case output_text:
@@ -357,29 +349,18 @@ void show_context (void)
               break;
           }
 
-          {
-            l = tally;
-            tally = 0;
-            selector = pseudo;
-            trick_count = 1000000L;
-          }
+          begin_pseudoprint();
 
-          if (cur_input.index_field < macro)
-            show_token_list(cur_input.start_field, cur_input.loc_field, 100000L);
+          if (index < macro)
+            show_token_list(start, loc, 100000L);
           else
-            show_token_list(link(cur_input.start_field), cur_input.loc_field, 100000L);
+            show_token_list(link(start), loc, 100000L);
         }
 
         selector = old_setting;
 
         if (trick_count == 1000000L)
-        {
-          first_count = tally;
-          trick_count = tally + 1 + error_line - half_error_line;
-
-          if (trick_count < error_line)
-            trick_count = error_line;
-        }
+          set_trick_count();
         
         if (tally < trick_count)
           m = tally - first_count;
@@ -393,14 +374,14 @@ void show_context (void)
         }
         else
         {
-          print_string("...");
+          prints("...");
           p = l + first_count - half_error_line + 3;
           n = half_error_line;
         }
 
         for (q = p; q <= first_count - 1; q++)
           print_char(trick_buf[q % error_line]);
-        
+
         print_ln();
 
         for (q = 1; q <= n; q++)
@@ -415,7 +396,8 @@ void show_context (void)
           print_char(trick_buf[q % error_line]);
 
         if (m + n > error_line)
-          print_string("...");
+          prints("...");
+
         incr(nn);
       }
     }
@@ -425,58 +407,32 @@ void show_context (void)
       incr(nn); 
     }
 
-    if (bottomline)
-      goto lab30;
+    if (bottom_line)
+      goto done;
 
     decr(base_ptr);
   }
-lab30:
+
+done:
   cur_input = input_stack[input_ptr];
 }
-//#pragma optimize("g", off)          /* 98/Dec/10 experiment */
 /* sec 0323 */
-void begin_token_list_ (halfword p, quarterword t)
+void begin_token_list_ (pointer p, quarterword t)
 {
-  {
-    if (input_ptr > max_in_stack)
-    {
-      max_in_stack = input_ptr;
-
-#ifdef ALLOCATEINPUTSTACK
-      if (input_ptr == current_stack_size)
-        input_stack = realloc_input_stack(increment_stack_size);
-
-      if (input_ptr == current_stack_size) /* check again after allocation */
-      {
-        overflow("input stack size", current_stack_size);
-        return;     // abort_flag set
-      }
-#else
-      if (input_ptr == stack_size) /* input stack - not dynamic */
-      {
-        overflow("input stack size", stack_size);
-        return;     // abort_flag set
-      }
-#endif
-    }
-
-    input_stack[input_ptr] = cur_input;
-    incr(input_ptr);
-  }
-
-  cur_input.state_field = token_list;
-  cur_input.start_field = p;
-  cur_input.index_field = t;
+  push_input();
+  state = token_list;
+  start = p;
+  index = t;
 
   if (t >= macro)
   {
     add_token_ref(p);
 
     if (t == macro)
-      cur_input.limit_field = param_ptr;
+      limit = param_ptr;
     else
     {
-      cur_input.loc_field = link(p);
+      loc = link(p);
 
       if (tracing_macros > 1)
       {
@@ -494,66 +450,57 @@ void begin_token_list_ (halfword p, quarterword t)
             break;
 
           default:
-            print_cmd_chr(assign_toks, t + (hash_size + 1307));
+            print_cmd_chr(assign_toks, t - output_text + output_routine_loc);
             break;
         }
 
-        print_string("->");
+        prints("->");
         token_show(p);
         end_diagnostic(false);
       }
     }
   }
   else
-    cur_input.loc_field = p;
+    loc = p;
 }
-//#pragma optimize("", on)          /* 98/Dec/10 experiment */
 /* sec 0324 */
 void end_token_list (void) 
 { 
-  if (cur_input.index_field >= backed_up)
+  if (index >= backed_up)
   {
-    if (cur_input.index_field <= inserted)
-      flush_list(cur_input.start_field); 
+    if (index <= inserted)
+      flush_list(start); 
     else
     {
-      delete_token_ref(cur_input.start_field);
-      if (cur_input.index_field == macro)
-        while (param_ptr > cur_input.limit_field)
+      delete_token_ref(start);
+
+      if (index == macro)
+        while (param_ptr > limit)
         {
           decr(param_ptr);
           flush_list(param_stack[param_ptr]);
         }
     }
   }
-  else if (cur_input.index_field == u_template)
+  else if (index == u_template)
     if (align_state > 500000L)
       align_state = 0;
     else
     {
       fatal_error("(interwoven alignment preambles are not allowed)");
-      return;     // abort_flag set
+      return;
     }
 
-  {
-    decr(input_ptr);
-    cur_input = input_stack[input_ptr];
-  }
-
-  {
-    if (interrupt != 0)
-    {
-      pause_for_instructions();
-    }
-  }
+  pop_input();
+  check_interrupt();
 }
 /* sec 0325 */
 void back_input (void)
 {
-  halfword p;
+  pointer p;
 
-  while ((cur_input.state_field == 0) && (cur_input.loc_field == 0) &&
-      (cur_input.index_field != v_template))
+  while ((state == 0) && (loc == 0) &&
+      (index != v_template))
   {
     end_token_list();
   }
@@ -567,35 +514,11 @@ void back_input (void)
     else
       incr(align_state);
 
-  {
-    if (input_ptr > max_in_stack)
-    {
-      max_in_stack = input_ptr;
-#ifdef ALLOCATEINPUTSTACK
-      if (input_ptr == current_stack_size)
-        input_stack = realloc_input_stack(increment_stack_size);
-
-      if (input_ptr == current_stack_size) /* check again after allocation */
-      {
-        overflow("input stack size", current_stack_size);
-        return;     // abort_flag set
-      }
-#else
-      if (input_ptr == stack_size) /* stack size - not dynamic */
-      {
-        overflow("input stack size", stack_size);
-        return;     // abort_flag set
-      }
-#endif
-    }
-    input_stack[input_ptr] = cur_input;
-    incr(input_ptr);
-  }
-
-  cur_input.state_field = token_list;
-  cur_input.start_field = p;
-  cur_input.index_field = backed_up;
-  cur_input.loc_field = p;
+  push_input();
+  state = token_list;
+  start = p;
+  index = backed_up;
+  loc = p;
 }
 /* sec 0327 */
 void back_error (void)
@@ -610,7 +533,7 @@ void ins_error (void)
 {
   OK_to_interrupt = false;
   back_input();
-  cur_input.index_field = inserted;
+  index = inserted;
   OK_to_interrupt = true;
   error();
 }
@@ -619,79 +542,57 @@ void begin_file_reading (void)
 {
   if (in_open == max_in_open)
   {
-    overflow("text input levels", max_in_open); /* text input levels - NOT DYNAMIC */
-    return;     // abort_flag set
+    overflow("text input levels", max_in_open);
+    return;
   }
+
 #ifdef ALLOCATEBUFFER
   if (first == current_buf_size)
     buffer = realloc_buffer(increment_buf_size);
 
-  if (first == current_buf_size) /* check again after allocation */
+  if (first == current_buf_size)
   {
     overflow("buffer size", current_buf_size);
-    return;     // abort_flag set
+    return;
   }
 #else
   if (first == buf_size)
   {
-    overflow("buffer size", buf_size);  /* buffer size - not dynamic */
-    return;     // abort_flag set
+    overflow("buffer size", buf_size);
+    return;
   }
 #endif
+
   incr(in_open);
-  if (in_open > high_in_open)     /* 1999 Jan 17 */
+
+  if (in_open > high_in_open) /* 1999 Jan 17 */
     high_in_open = in_open;
-  {
-    if (input_ptr > max_in_stack)
-    {
-      max_in_stack = input_ptr;
-#ifdef ALLOCATEINPUTSTACK
-      if (input_ptr == current_stack_size)
-        input_stack = realloc_input_stack(increment_stack_size);
-      if (input_ptr == current_stack_size)
-      {
-        overflow("input stack size", current_stack_size);  /* check again after allocation */
-        return;     // abort_flag set
-      }
-#else
-      if (input_ptr == stack_size)
-      {
-        overflow("input stack size", stack_size);    /* input stack - not dynamic */
-        return;     // abort_flag set
-      }
-#endif
-    }
-    input_stack[input_ptr] = cur_input;
-    incr(input_ptr);
-  }
-  cur_input.index_field = in_open;
-  line_stack[cur_input.index_field] = line;
-  cur_input.start_field = first;
-  cur_input.state_field = 1;
-  cur_input.name_field = 0;
+
+  push_input();
+  index = in_open;
+  line_stack[index] = line;
+  start = first;
+  state = 1;
+  name = 0;
 }
 /* sec 0329 */
 void end_file_reading (void)
 {
-  first = cur_input.start_field;
-  line = line_stack[cur_input.index_field];
+  first = start;
+  line = line_stack[index];
 
-  if (cur_input.name_field > 17)
-    (void) a_close(input_file[cur_input.index_field]);
+  if (name > 17)
+    a_close(cur_file);
 
-  {
-    decr(input_ptr);
-    cur_input = input_stack[input_ptr];
-  }
+  pop_input();
   decr(in_open);
 }
 /* called only form tex0.c */
 /* sec 0330 */
 void clear_for_error_prompt (void) 
 {
-  while ((cur_input.state_field != 0) &&
-      (cur_input.name_field == 0) && (input_ptr > 0) &&
-      (cur_input.loc_field > cur_input.limit_field))
+  while ((state != 0) && (name == 0) &&
+    (input_ptr > 0) && (loc > limit))
     end_file_reading();
 
   print_ln();
@@ -699,8 +600,8 @@ void clear_for_error_prompt (void)
 /* sec 0336 */
 void check_outer_validity (void)
 {
-  halfword p;
-  halfword q;
+  pointer p;
+  pointer q;
 
   if (scanner_status != 0)
   {
@@ -708,7 +609,7 @@ void check_outer_validity (void)
 
     if (cur_cs != 0)
     {
-      if ((cur_input.state_field == 0) || (cur_input.name_field < 1) || (cur_input.name_field > 17))
+      if ((state == 0) || (name < 1) || (name > 17))
       {
         p = get_avail();
         info(p) = cs_token_flag + cur_cs;
@@ -731,39 +632,40 @@ void check_outer_validity (void)
         print_err("Forbidden control sequence found");
       }
 
-      print_string(" while scanning ");
+      prints(" while scanning ");
       p = get_avail();
 
       switch (scanner_status)
       {
         case defining:
-          print_string("definition");
+          prints("definition");
           info(p) = right_brace_token + '}';
           break;
 
         case matching:
-          print_string("use");
+          prints("use");
           info(p) = par_token;
           long_state = outer_call;
           break;
 
         case aligning:
-          print_string("preamble");
+          prints("preamble");
           info(p) = right_brace_token + '}';
           q = p;
           p = get_avail();
           link(p) = q;
-          info(p) = cs_token_flag + frozen_cr; /*96/Jan/10*/
+          info(p) = cs_token_flag + frozen_cr;
           align_state = -1000000L;
           break;
 
         case absorbing:
-          print_string("text");
+          prints("text");
           info(p) = right_brace_token + '}';
           break;
       }
+
       ins_list(p);
-      print_string(" of ");
+      prints(" of ");
       sprint_cs(warning_index);
       help4("I suspect you have forgotten a `}', causing me",
           "to read past where you wanted me to stop.",
@@ -775,7 +677,7 @@ void check_outer_validity (void)
     {
       print_err("Incomplete ");
       print_cmd_chr(if_test, cur_if);
-      print_string("; all text was ignored after line ");
+      prints("; all text was ignored after line ");
       print_int(skip_line);
       help3("A forbidden control sequence occurred in skipped text.",
           "This kind of error happens when you say `\\if...' and forget",
@@ -786,22 +688,19 @@ void check_outer_validity (void)
       else
         help_line[2] = "The file ended while I was skipping conditional text.";
 
-      cur_tok = cs_token_flag + frozen_fi; /* 96/Jan/10 */
+      cur_tok = cs_token_flag + frozen_fi;
       ins_error();
-  }
+    }
+
     deletions_allowed = true;
   }
 }
-/*****************************************************************************/
-/* get_next() moved from here to end for pragma optimize reasons 96/Sep/12 */
-void get_next(void);
-/*****************************************************************************/
 /* sec 0363 */
 void firm_up_the_line (void)
 {
   integer k;
 
-  cur_input.limit_field = last;
+  limit = last;
 
   if (pausing > 0)
     if (interaction > nonstop_mode)
@@ -809,24 +708,19 @@ void firm_up_the_line (void)
       ;
       print_ln();
 
-      if (cur_input.start_field < cur_input.limit_field)
-        for (k = cur_input.start_field; k <= cur_input.limit_field - 1; k++)
+      if (start < limit)
+        for (k = start; k <= limit - 1; k++)
           print(buffer[k]);
 
-      first = cur_input.limit_field;
-
-      {
-        ;
-        print_string("=>");
-        term_input("=>", 0);
-      }
+      first = limit;
+      prompt_input("=>");
 
       if (last > first)
       {
         for (k = first; k <= last - 1; k++)
-          buffer[k + cur_input.start_field - first] = buffer[k];
+          buffer[k + start - first] = buffer[k];
 
-        cur_input.limit_field = cur_input.start_field + last - first;
+        limit = start + last - first;
       }
     }
 }
@@ -845,26 +739,26 @@ void get_token (void)
 /* sec 0389 */
 void macro_call (void)
 {
-  halfword r;
-  halfword p;
-  halfword q;
-  halfword s;
-  halfword t;
-  halfword u, v;
-  halfword rbraceptr;
+  pointer r;
+  pointer p;
+  pointer q;
+  pointer s;
+  pointer t;
+  pointer u, v;
+  pointer rbrace_ptr;
   small_number n;
   halfword unbalance;
   halfword m;
-  halfword refcount;
-  small_number savescannerstatus;
-  halfword savewarningindex;
+  pointer ref_count;
+  small_number save_scanner_status;
+  pointer save_warning_index;
   ASCII_code match_chr;
 
-  savescannerstatus = scanner_status;
-  savewarningindex = warning_index;
+  save_scanner_status = scanner_status;
+  save_warning_index = warning_index;
   warning_index = cur_cs;
-  refcount = cur_chr;
-  r = link(refcount);
+  ref_count = cur_chr;
+  r = link(ref_count);
   n = 0;
 
   if (tracing_macros > 0)
@@ -872,7 +766,7 @@ void macro_call (void)
     begin_diagnostic();
     print_ln();
     print_cs(warning_index);
-    token_show(refcount);
+    token_show(ref_count);
     end_diagnostic(false);
   }
 
@@ -899,7 +793,8 @@ void macro_call (void)
           p = temp_head;
           m = 0;
         }
-lab22:
+
+continu:
         get_token();
 
         if (cur_tok == info(r))
@@ -911,10 +806,10 @@ lab22:
             if (cur_tok < left_brace_limit)
               decr(align_state);
 
-            goto lab40;
+            goto found;
           }
           else
-            goto lab22;
+            goto continu;
         }
 
         if (s != r)
@@ -922,26 +817,21 @@ lab22:
           {
             print_err("Use of ");
             sprint_cs(warning_index);
-            print_string(" doesn't match its definition");
+            prints(" doesn't match its definition");
             help4("If you say, e.g., `\\def\\a1{...}', then you must always",
               "put `1' after `\\a', since control sequence names are",
               "made up of letters only. The macro here has not been",
               "followed by the required stuff, so I'm ignoring it.");
             error();
-            goto lab10;
+            goto exit;
           }
           else
           {
             t = s;
+
             do
               {
-                {
-                  q = get_avail();
-                  mem[p].hh.v.RH = q;
-                  mem[q].hh.v.LH = mem[t].hh.v.LH;
-                  p = q;
-                }
-
+                store_new_token(info(t));
                 incr(m);
                 u = link(t);
                 v = s;
@@ -950,23 +840,23 @@ lab22:
                 {
                   if (u == r)
                     if (cur_tok != info(v))
-                      goto lab30;
+                      goto done;
                     else
                     {
                       r = link(v);
-                      goto lab22;
+                      goto continu;
                     }
 
                     if (info(u) != info(v))
-                      goto lab30;
+                      goto done;
 
                     u = link(u);
                     v = link(v);
                 }
-lab30:
+done:
                 t = link(t);
               }
-            while(!(t == r));
+            while (!(t == r));
 
             r = s;
           }
@@ -979,7 +869,7 @@ lab30:
               runaway();
               print_err("Paragraph ended before ");
               sprint_cs(warning_index);
-              print_string("was complete");
+              prints("was complete");
               help3("I suspect you've forgotten a `}', causing me to apply this",
                   "control sequence to too much text. How can we recover?",
                   "My plan is to forget the whole thing and hope for the best.");
@@ -992,7 +882,7 @@ lab30:
             for (m = 0; m <= n; m++)
               flush_list(pstack[m]);
 
-            goto lab10;
+            goto exit;
           }
 
         if (cur_tok < right_brace_limit)
@@ -1002,27 +892,7 @@ lab30:
 
             while (true)
             {
-              {
-                {
-                  q = avail;
-
-                  if (q == 0)
-                    q = get_avail();
-                  else
-                  {
-                    avail = mem[q].hh.v.RH;
-                    mem[q].hh.v.RH = 0;
-#ifdef STAT
-                    incr(dyn_used);
-#endif /* STAT */
-                  }
-                }
-
-                mem[p].hh.v.RH = q;
-                mem[q].hh.v.LH = cur_tok;
-                p = q;
-              }
-
+              fast_store_new_token(cur_tok);
               get_token();
 
               if (cur_tok == par_token)
@@ -1033,7 +903,7 @@ lab30:
                     runaway();
                     print_err("Paragraph ended before ");
                     sprint_cs(warning_index);
-                    print_string(" was complete");
+                    prints(" was complete");
                     help3("I suspect you've forgotten a `}', causing me to apply this",
                         "control sequence to too much text. How can we recover?",
                         "My plan is to forget the whole thing and hope for the best.");
@@ -1045,7 +915,7 @@ lab30:
 
                   for (m = 0; m <= n; m++)
                     flush_list(pstack[m]);
-                  goto lab10;
+                  goto exit;
                 }
 
               if (cur_tok < right_brace_limit)
@@ -1056,25 +926,19 @@ lab30:
                   decr(unbalance);
 
                   if (unbalance == 0)
-                    goto lab31;
+                    goto done1;
                 }
             }
-lab31:
-            rbraceptr = p;
-
-            {
-              q = get_avail();
-              mem[p].hh.v.RH = q;
-              mem[q].hh.v.LH = cur_tok;
-              p = q;
-            }
+done1:
+            rbrace_ptr = p;
+            store_new_token(cur_tok);
           }
           else
           {
             back_input();
             print_err("Argument of ");
             sprint_cs(warning_index);
-            print_string(" has an extra }");
+            prints(" has an extra }");
             help6("I've run across a `}' that doesn't seem to match anything.",
                 "For example, `\\def\\a#1{...}' and `\\a}' would produce",
                 "this error. If you simply proceed now, the `\\par' that",
@@ -1085,36 +949,32 @@ lab31:
             long_state = call;
             cur_tok = par_token;
             ins_error();
-            goto lab22;
+            goto continu;
           }
         else
         {
           if (cur_tok == space_token)
             if (info(r) <= end_match_token)
               if (info(r) >= match_token)
-                goto lab22;
+                goto continu;
 
-          {
-            q = get_avail();
-            mem[p].hh.v.RH = q;   /* p may be used without having ... */
-            mem[q].hh.v.LH = cur_tok;
-            p = q;
-          }
+          store_new_token(cur_tok);
         }
 
-        incr(m);          /* m may be used without having been ... */
+        incr(m);
 
         if (info(r) > end_match_token)
-          goto lab22;
+          goto continu;
 
         if (info(r) < match_token)
-          goto lab22;
-lab40:
+          goto continu;
+
+found:
         if (s != 0)
         {
           if ((m == 1) && (info(p) < right_brace_limit) && (p != temp_head))
           {
-            link(rbraceptr) = 0; /* rbraceptr may be used without ... */
+            link(rbrace_ptr) = 0;
             free_avail(p);
             p = link(temp_head);
             pstack[n] = link(p);
@@ -1128,25 +988,25 @@ lab40:
           if (tracing_macros > 0)
           {
             begin_diagnostic();
-            //print_nl(match_chr); /* matchchar may be used without ... */
+            //print_nl(match_chr);
             print_nl(""); print(match_chr);
             print_int(n);
-            print_string("<-");
+            prints("<-");
             show_token_list(pstack[n - 1], 0, 1000);
             end_diagnostic(false);
           }
         }
       }
-    while(!(info(r) == end_match_token));
+    while (!(info(r) == end_match_token));
   }
 
-  while((cur_input.state_field == token_list) && (cur_input.loc_field == 0) &&
-      (cur_input.index_field != v_template))
+  while ((state == token_list) && (loc == 0) &&
+      (index != v_template))
     end_token_list();
 
-  begin_token_list(refcount, macro);
-  cur_input.name_field = warning_index;
-  cur_input.loc_field = link(r);
+  begin_token_list(ref_count, macro);
+  name = warning_index;
+  loc = link(r);
 
   if (n > 0)
   {
@@ -1158,16 +1018,16 @@ lab40:
       if (max_param_stack > current_param_size)
         param_stack = realloc_param_stack(increment_param_size);
 
-      if (max_param_stack > current_param_size) /* check again after allocation */
+      if (max_param_stack > current_param_size)
       {
         overflow("parameter stack size", current_param_size);
-        return;     // abort_flag set
+        return;
       }
 #else
       if (max_param_stack > param_size)
       {
-        overflow("parameter stack size", param_size); /* parameter stack - not dynamic */
-        return;     // abort_flag set
+        overflow("parameter stack size", param_size);
+        return;
       }
 #endif
     }
@@ -1177,35 +1037,36 @@ lab40:
 
     param_ptr = param_ptr + n;
   }
-lab10:
-  scanner_status = savescannerstatus;
-  warning_index = savewarningindex;
+
+exit:
+  scanner_status = save_scanner_status;
+  warning_index = save_warning_index;
 }
 /* sec 0379 */
 void insert_relax (void)
 {
   cur_tok = cs_token_flag + cur_cs;
   back_input();
-  cur_tok = cs_token_flag + frozen_relax;  /* 96/Jan/10 */
+  cur_tok = cs_token_flag + frozen_relax;
   back_input();
-  cur_input.index_field = inserted;
+  index = inserted;
 }
 /* sec 0366 */
 void expand (void)
 {
   halfword t;
-  halfword p, q, r;
+  pointer p, q, r;
   integer j;
-  integer cvbackup;
-  small_number cvlbackup, radixbackup, cobackup;
-  halfword backupbackup;
-  small_number savescannerstatus;
+  integer cv_backup;
+  small_number cvl_backup, radix_backup, co_backup;
+  pointer backup_backup;
+  small_number save_scanner_status;
 
-  cvbackup = cur_val;
-  cvlbackup = cur_val_level;
-  radixbackup = radix;
-  cobackup = cur_order;
-  backupbackup = link(backup_head);
+  cv_backup = cur_val;
+  cvl_backup = cur_val_level;
+  radix_backup = radix;
+  co_backup = cur_order;
+  backup_backup = link(backup_head);
 
   if (cur_cmd < call)
   {
@@ -1234,20 +1095,20 @@ void expand (void)
         break;
 
       case no_expand:
-        savescannerstatus = scanner_status;
+        save_scanner_status = scanner_status;
         scanner_status = normal;
         get_token();
-        scanner_status = savescannerstatus;
+        scanner_status = save_scanner_status;
         t = cur_tok;
         back_input();
 
         if (t >= cs_token_flag)
         {
           p = get_avail();
-          info(p) = cs_token_flag + frozen_dont_expand; /*96/Jan/10*/
-          link(p) = cur_input.loc_field;
-          cur_input.start_field = p;
-          cur_input.loc_field = p;
+          info(p) = cs_token_flag + frozen_dont_expand;
+          link(p) = loc;
+          start = p;
+          loc = p;
         }
         break;
 
@@ -1259,20 +1120,15 @@ void expand (void)
             get_x_token();
   
             if (cur_cs == 0)
-            {
-              q = get_avail();
-              mem[p].hh.v.RH = q;
-              mem[q].hh.v.LH = cur_tok;
-              p = q;
-            }
+              store_new_token(cur_tok);
           }
-        while(!(cur_cs != 0));
+        while (!(cur_cs != 0));
 
         if (cur_cmd != end_cs_name)
         {
           print_err("Missing ");
           print_esc("endcsname");
-          print_string(" inserted");
+          prints(" inserted");
           help2("The control sequence marked <to be read again> should",
               "not appear between \\csname and \\endcsname.");
           back_error();
@@ -1291,16 +1147,16 @@ void expand (void)
             if (max_buf_stack == current_buf_size)
               buffer = realloc_buffer (increment_buf_size);
 
-            if (max_buf_stack == current_buf_size) /* check again after allocation */
+            if (max_buf_stack == current_buf_size)
             {
               overflow("buffer size", current_buf_size);
-              return;     // abort_flag set
+              return;
             }
 #else
             if (max_buf_stack == buf_size)
             {
-              overflow("buffer size", buf_size); /* buffer size - not dynamic */
-              return;     // abort_flag set
+              overflow("buffer size", buf_size);
+              return;
             }
 #endif
           }
@@ -1357,7 +1213,7 @@ void expand (void)
           }
         else
         {
-          while(cur_chr != fi_code)
+          while (cur_chr != fi_code)
             pass_text();
 
           {
@@ -1397,38 +1253,40 @@ void expand (void)
   }
   else
   {
-    cur_tok = cs_token_flag + frozen_endv; /* 96/Jan/10 */
+    cur_tok = cs_token_flag + frozen_endv;
     back_input();
   }
 
-  cur_val = cvbackup;
-  cur_val_level = cvlbackup;
-  radix = radixbackup;
-  cur_order = cobackup;
-  link(backup_head) = backupbackup;
+  cur_val = cv_backup;
+  cur_val_level = cvl_backup;
+  radix = radix_backup;
+  cur_order = co_backup;
+  link(backup_head) = backup_backup;
 }
 /* sec 0380 */
 void get_x_token (void)
 {
-lab20:
+restart:
   get_next();
 
   if (cur_cmd <= max_command)
-    goto lab30;
+    goto done;
+
   if (cur_cmd >= call)
     if (cur_cmd < end_template)
       macro_call();
     else
     {
-      cur_cs = frozen_endv;  /* 96/Jan/10 */
+      cur_cs = frozen_endv;
       cur_cmd = endv;
-      goto lab30;
+      goto done;
     }
   else
     expand();
 
-  goto lab20;
-lab30:
+  goto restart;
+
+done:
   if (cur_cs == 0)
     cur_tok = (cur_cmd * 256) + cur_chr;
   else
@@ -1455,7 +1313,7 @@ void scan_left_brace (void)
     {
       get_x_token();
     }
-  while(!((cur_cmd != spacer) && (cur_cmd != relax)));
+  while (!((cur_cmd != spacer) && (cur_cmd != relax)));
 
   if (cur_cmd != left_brace)
   {
@@ -1478,17 +1336,17 @@ void scan_optional_equals (void)
     {
       get_x_token();
     }
-  while(!(cur_cmd != spacer));
+  while (!(cur_cmd != spacer));
 
   if (cur_tok != other_token + '=')
     back_input();
 }
 /* sec 0407 */
-bool scan_keyword_(char * s)
+boolean scan_keyword(const char * s)
 {
-  halfword p;
-  halfword q;
-  char * k;
+  pointer p;
+  pointer q;
+  const char * k;
 
   p = backup_head;
   link(p) = 0;
@@ -1500,13 +1358,7 @@ bool scan_keyword_(char * s)
 
     if ((cur_cs == 0) && ((cur_chr == (*k)) || (cur_chr == (*k) - 'a' + 'A')))
     {
-      {
-        q = get_avail();
-        mem[p].hh.v.RH = q;
-        mem[q].hh.v.LH = cur_tok;
-        p = q;
-      }
-
+      store_new_token(cur_tok);
       incr(k);
     }
     else if ((cur_cmd != spacer) || (p != backup_head))
@@ -1577,6 +1429,7 @@ void scan_four_bit_int (void)
 void scan_fifteen_bit_int (void) 
 {
   scan_int();
+
   if ((cur_val < 0) || (cur_val > 32767))
   {
     print_err("Bad mathchar");
@@ -1591,7 +1444,7 @@ void scan_twenty_seven_bit_int (void)
 {
   scan_int();
 
-  if ((cur_val < 0) || (cur_val > 134217727L)) /* 2^27 - 1 */
+  if ((cur_val < 0) || (cur_val > 134217727L))
   {
     print_err("Bad delimiter code");
     help2("A numeric delimiter code must be between 0 and 2^{27}-1.",
@@ -1634,7 +1487,7 @@ void scan_font_ident (void)
   cur_val = f;
 }
 /* sec 0578 */
-void find_font_dimen_(bool writing)
+void find_font_dimen_(boolean writing)
 {
   internal_font_number f;
   integer n;
@@ -1644,7 +1497,7 @@ void find_font_dimen_(bool writing)
   scan_font_ident();
   f = cur_val;
 
-  if (n < 0 || (n == 0 && font_dimen_zero == 0)) /* change 98/Oct/5 */
+  if (n < 0)
     cur_val = fmem_ptr;
   else
   {
@@ -1657,63 +1510,52 @@ void find_font_dimen_(bool writing)
     if (n > font_params[f])
       if (f < font_ptr)
         cur_val = fmem_ptr;
-    else
-    {
-      do
-        {
- #ifdef ALLOCATEFONT
-          if (fmem_ptr == current_font_mem_size) /* 93/Nov/28 ??? */
+      else
+      {
+        do
           {
-            font_info = realloc_font_info(increment_font_mem_size);
-          }
+ #ifdef ALLOCATEFONT
+            if (fmem_ptr == current_font_mem_size)
+              font_info = realloc_font_info(increment_font_mem_size);
 
-          if (fmem_ptr == current_font_mem_size) /* 94/Jan/24 */
-          {
-            overflow("font memory", current_font_mem_size); /* font memory */
-            return;     // abort_flag set
-          }
+            if (fmem_ptr == current_font_mem_size)
+            {
+              overflow("font memory", current_font_mem_size);
+              return;
+            }
 #else
-          if (fmem_ptr == font_mem_size)
-          {
-            overflow("font memory", font_mem_size); /* font memory */
-            return;     // abort_flag set
-          }
+            if (fmem_ptr == font_mem_size)
+            {
+              overflow("font memory", font_mem_size);
+              return;
+            }
 #endif
-          font_info[fmem_ptr].cint = 0;
-          incr(fmem_ptr);
-          incr(font_params[f]);
-        }
-      while(!(n == font_params[f]));
+            font_info[fmem_ptr].cint = 0;
+            incr(fmem_ptr);
+            incr(font_params[f]);
+          }
+        while (!(n == font_params[f]));
 
-      cur_val = fmem_ptr - 1;
-    }
-  else if (n > 0)
-    cur_val = n + param_base[f];    /* 98/Oct/5 */
-//  else
-//    cur_val = (&font_check[f] - &font_info[0]); /* 98/Oct/5 */
-/*  checksum =  (((font_check[f].b0) << 8 | font_check[f].b1) << 8 |
-        font_check[f].b2) << 8 | font_check[f].b3; */
+        cur_val = fmem_ptr - 1;
+      }
+    else if (n > 0)
+      cur_val = n + param_base[f];
   }
-/* compiler error: '-' : incompatible types - from 'union fmemoryword *' to 'struct fourunsignedchars *' */
+
   if (cur_val == fmem_ptr)
   {
     print_err("Font ");
-/*    print_esc(hash[(hash_size + 524) + f].v.RH); */
     print_esc(""); print(font_id_text(f));
-    print_string(" has only ");
+    prints(" has only ");
     print_int(font_params[f]);
-    print_string(" fontdimen parameters");
+    prints(" fontdimen parameters");
     help2("To increase the number of font parameters, you must",
       "use \\fontdimen immediately after the \\font is loaded.");
     error();
   }
 }
-/* NOTE: the above use of /fontdimen0 to access the checksum is a kludge */
-/* In future would be better to do this by allocating one more slot for */
-/* for parameters when a font is read rather than carry checksum separately */
-/* The above gets the value byte order reversed ... 98/Oct/5 */
 /* sec 0413 */
-void scan_something_internal_(small_number level, bool negative)
+void scan_something_internal_(small_number level, boolean negative)
 {
   halfword m;
   integer p;
@@ -1727,20 +1569,11 @@ void scan_something_internal_(small_number level, bool negative)
         scan_char_num();
 
         if (m == math_code_base)
-        {
-          cur_val = math_code(cur_val);
-          cur_val_level = int_val;
-        }
+          scanned_result(math_code(cur_val), int_val);
         else if (m < math_code_base)
-        {
-          cur_val = equiv(m + cur_val);
-          cur_val_level = int_val;
-        }
+          scanned_result(equiv(m + cur_val), int_val);
         else
-        {
-          cur_val = eqtb[m + cur_val].cint;
-          cur_val_level = int_val;
-        }
+          scanned_result(eqtb[m + cur_val].cint, int_val);
       }
       break;
 
@@ -1756,10 +1589,7 @@ void scan_something_internal_(small_number level, bool negative)
             "(If you can't figure out why I needed to see a number,",
             "look up `weird error' in the index to The TeXbook.)");
         back_error();
-        {
-          cur_val = 0;
-          cur_val_level = dimen_val;
-        }
+        scanned_result(0, dimen_val);
       }
       else if (cur_cmd <= assign_toks)
       {
@@ -1769,53 +1599,34 @@ void scan_something_internal_(small_number level, bool negative)
           m = toks_base + cur_val;
         }
 
-        {
-          cur_val = eqtb[m].hh.v.RH;
-          cur_val_level = tok_val;
-        }
+        scanned_result(equiv(m), tok_val);
       }
       else
       {
         back_input();
         scan_font_ident();
-
-        {
-          cur_val = font_id_base + cur_val; /* 96/Jan/10 */
-          cur_val_level = ident_val;
-        }
+        scanned_result(font_id_base + cur_val, ident_val);
       }
       break;
 
     case assign_int:
-      {
-        cur_val = eqtb[m].cint;
-        cur_val_level = int_val;
-      }
+      scanned_result(eqtb[m].cint, int_val);
       break;
 
     case assign_dimen:
-      {
-        cur_val = eqtb[m].cint;
-        cur_val_level = dimen_val;
-      }
+      scanned_result(eqtb[m].cint, dimen_val);
       break; 
 
     case assign_glue:
-      {
-        cur_val = eqtb[m].hh.v.RH;
-        cur_val_level = glue_val;
-      }
+      scanned_result(equiv(m), glue_val);
       break;
 
     case assign_mu_glue:
-      {
-        cur_val = eqtb[m].hh.v.RH;
-        cur_val_level = mu_val;
-      }
+      scanned_result(equiv(m), mu_val);
       break;
 
     case set_aux:
-      if (abs(mode)!= m)
+      if (abs(mode) != m)
       {
         print_err("Improper ");
         print_cmd_chr(set_aux, m);
@@ -1826,46 +1637,28 @@ void scan_something_internal_(small_number level, bool negative)
         error();
 
         if (level != tok_val)
-        {
-          cur_val = 0;
-          cur_val_level = dimen_val;
-        }
+          scanned_result(0, dimen_val);
         else
-        {
-          cur_val = 0;
-          cur_val_level = int_val;
-        }
+          scanned_result(0, int_val);
       }
       else if (m == vmode)
-      {
-        cur_val = cur_list.aux_field.cint;
-        cur_val_level = dimen_val;
-      }
+        scanned_result(prev_depth, dimen_val);
       else
-      {
-        cur_val = space_factor;
-        cur_val_level = int_val;
-      }
+        scanned_result(space_factor, int_val);
       break;
 
     case set_prev_graf:
       if (mode == 0)
-      {
-        cur_val = 0;
-        cur_val_level = int_val;
-      }
+        scanned_result(0, int_val);
       else
       {
         nest[nest_ptr] = cur_list;
         p = nest_ptr;
 
-        while (abs(nest[p].mode_field)!= vmode)
+        while (abs(nest[p].mode_field) != vmode)
           decr(p);
 
-        {
-          cur_val = nest[p].pg_field;
-          cur_val_level = int_val;
-        }
+        scanned_result(nest[p].pg_field, int_val);
       }
       break;
 
@@ -1884,7 +1677,7 @@ void scan_something_internal_(small_number level, bool negative)
       {
         if ((page_contents == 0) && (! output_active))
           if (m == 0)
-            cur_val = 1073741823L;  /* 2^30 - 1 */
+            cur_val = max_dimen;
           else
             cur_val = 0;
         else
@@ -1920,20 +1713,14 @@ void scan_something_internal_(small_number level, bool negative)
 
     case char_given:
     case math_given:
-      {
-        cur_val = cur_chr;
-        cur_val_level = int_val;
-      }
+      scanned_result(cur_chr, int_val);
       break;
 
     case assign_font_dimen:
       {
         find_font_dimen(false);
         font_info[fmem_ptr].cint = 0;
-        {
-          cur_val = font_info[cur_val].cint;
-          cur_val_level = dimen_val;
-        }
+        scanned_result(font_info[cur_val].cint, dimen_val);
       }
       break;
 
@@ -1942,15 +1729,9 @@ void scan_something_internal_(small_number level, bool negative)
         scan_font_ident();
 
         if (m == 0)
-        {
-          cur_val = hyphen_char[cur_val];
-          cur_val_level = int_val;
-        }
+          scanned_result(hyphen_char[cur_val], int_val);
         else
-        {
-          cur_val = skew_char[cur_val];
-          cur_val_level = int_val;
-        }
+          scanned_result(skew_char[cur_val], int_val);
       }
       break;
 
@@ -1958,7 +1739,7 @@ void scan_something_internal_(small_number level, bool negative)
       {
         scan_eight_bit_int();
 
-        switch(m)
+        switch (m)
         {
           case int_val:
             cur_val = count(cur_val);
@@ -2000,8 +1781,8 @@ void scan_something_internal_(small_number level, bool negative)
 
         cur_val_level = cur_chr;
 
-        if (!(tail >= hi_mem_min) && (mode != 0))
-          switch(cur_chr)
+        if (!is_char_node(tail) && (mode != 0))
+          switch (cur_chr)
           {
             case int_val:
               if (type(tail) == penalty_node)
@@ -2023,7 +1804,7 @@ void scan_something_internal_(small_number level, bool negative)
               }
               break;
           }
-        else if ((mode == 1) && (tail == cur_list.head_field))
+        else if ((mode == vmode) && (tail == head))
           switch (cur_chr)
           {
             case int_val:
@@ -2046,21 +1827,15 @@ void scan_something_internal_(small_number level, bool negative)
       {
         print_err("You can't use `");
         print_cmd_chr(cur_cmd, cur_chr);
-        print_string("' after ");
+        prints("' after ");
         print_esc("the");
         help1("I'm forgetting what you said and using zero instead.");
         error();
 
         if (level != tok_val)
-        {
-          cur_val = 0;
-          cur_val_level = dimen_val;
-        }
+          scanned_result(0, dimen_val);
         else
-        {
-          cur_val = 0;
-          cur_val_level = int_val;
-        }
+          scanned_result(0, int_val);
       }
       break;
   }
@@ -2081,69 +1856,68 @@ void scan_something_internal_(small_number level, bool negative)
       cur_val = new_spec(cur_val);
 
       {
-        width(cur_val) = - (integer) width(cur_val);
-        stretch(cur_val) = - (integer) stretch(cur_val);
-        shrink(cur_val) = - (integer) shrink(cur_val);
+        width(cur_val) = -width(cur_val);
+        stretch(cur_val) = -stretch(cur_val);
+        shrink(cur_val) = -shrink(cur_val);
       }
     }
     else
-      cur_val = - (integer) cur_val;
+      cur_val = -cur_val;
   else if ((cur_val_level >= glue_val) && (cur_val_level <= mu_val))
     add_glue_ref(cur_val);
 }
-/*****************************************************************************/
-/* Moved here to avoid question about pragma optimize 96/Sep/12 */
 /* sec 0341 */
 void get_next (void)
 {
   integer k;
   halfword t;
-/*  char cat; */    /* make this an int ? */
-  int cat;      /* make this an int ? 95/Jan/7 */
+/* char cat; */
+  int cat;
   ASCII_code c, cc;
   char d;
 
-lab20:
+restart:
   cur_cs = 0;
 
-  if (cur_input.state_field != token_list)
+  if (state != token_list)
   {
-lab25:
-    if (cur_input.loc_field <= cur_input.limit_field)
+lab_switch:
+    if (loc <= limit)
     {
-      cur_chr = buffer[cur_input.loc_field];
-      incr(cur_input.loc_field);
-lab21:
+      cur_chr = buffer[loc];
+      incr(loc);
+
+reswitch:
       cur_cmd = cat_code(cur_chr);
 
-      switch (cur_input.state_field + cur_cmd)
+      switch (state + cur_cmd)
       {
         case any_state_plus(ignore):
         case skip_blanks + spacer:
         case new_line + spacer:
-          goto lab25;
+          goto lab_switch;
           break;
 
         case any_state_plus(escape):
           {
-            if (cur_input.loc_field > cur_input.limit_field)
+            if (loc > limit)
               cur_cs = null_cs;
             else
             {
-lab26:
-              k = cur_input.loc_field;
+start_cs:
+              k = loc;
               cur_chr = buffer[k];
               cat = cat_code(cur_chr);
               incr(k);
 
               if (cat == letter)
-                cur_input.state_field = skip_blanks;
+                state = skip_blanks;
               else if (cat == spacer)
-                cur_input.state_field = skip_blanks;
+                state = skip_blanks;
               else
-                cur_input.state_field = mid_line;
+                state = mid_line;
 
-              if ((cat == letter) && (k <= cur_input.limit_field))
+              if ((cat == letter) && (k <= limit))
               {
                 do
                   {
@@ -2151,39 +1925,30 @@ lab26:
                     cat = cat_code(cur_chr);
                     incr(k);
                   }
-                while(!((cat != letter) || (k > cur_input.limit_field)));
+                while (!((cat != letter) || (k > limit)));
 
                 {
                   if (buffer[k]== cur_chr)
                     if (cat == sup_mark)
-                      if (k < cur_input.limit_field)
+                      if (k < limit)
                       {
                         c = buffer[k + 1];
 
                         if (c < 128)
                         {
                           d = 2;
-                          if ((((c >= 48) && (c <= 57)) || ((c >= 97) && (c <= 102))))
-                            if (k + 2 <= cur_input.limit_field)
+                          if (is_hex(c))
+                            if (k + 2 <= limit)
                             {
                               cc = buffer[k + 2];
 
-                              if ((((cc >= 48) && (cc <= 57)) || ((cc >= 97) && (cc <= 102))))
+                              if (is_hex(cc))
                                 incr(d);
                             }
 
                           if (d > 2)
                           {
-                            if (c <= 57)
-                              cur_chr = c - 48;
-                            else
-                              cur_chr = c - 87;
-
-                            if (cc <= 57)
-                              cur_chr = 16 * cur_chr + cc - 48;
-                            else
-                              cur_chr = 16 * cur_chr + cc - 87;
-
+                            hex_to_cur_chr();
                             buffer[k - 1] = cur_chr;
                           }
                           else if (c < 64)
@@ -2191,16 +1956,16 @@ lab26:
                           else
                             buffer[k - 1] = c - 64;
 
-                          cur_input.limit_field = cur_input.limit_field - d;
+                          limit = limit - d;
                           first = first - d;
 
-                          while (k <= cur_input.limit_field)
+                          while (k <= limit)
                           {
                             buffer[k] = buffer[k + d];
                             incr(k);
                           }
 
-                          goto lab26;
+                          goto start_cs;
                         }
                       }
                 }
@@ -2208,45 +1973,37 @@ lab26:
                 if (cat != letter)
                   decr(k);
 
-                if (k > cur_input.loc_field + 1)
+                if (k > loc + 1)
                 {
-                  cur_cs = id_lookup(cur_input.loc_field, k - cur_input.loc_field);
-                  cur_input.loc_field = k;
-                  goto lab40;
+                  cur_cs = id_lookup(loc, k - loc);
+                  loc = k;
+                  goto found;
                 }
               }
               else
               {
                 if (buffer[k] == cur_chr)
                   if (cat == sup_mark)
-                    if (k < cur_input.limit_field)
+                    if (k < limit)
                     {
                       c = buffer[k + 1];
 
                       if (c < 128)             /* ? */
                       {
                         d = 2;
-                        if ((((c >= 48) && (c <= 57)) || ((c >= 97) && (c <= 102))))
-                          if (k + 2 <= cur_input.limit_field)
+
+                        if (is_hex(c))
+                          if (k + 2 <= limit)
                           {
                             cc = buffer[k + 2];
 
-                            if ((((cc >= 48) && (cc <= 57)) || ((cc >= 97) && (cc <= 102))))
+                            if (is_hex(cc))
                               incr(d);
                           }
 
                         if (d > 2)
                         {
-                          if (c <= 57)
-                            cur_chr = c - 48;
-                          else
-                            cur_chr = c - 87;
-
-                          if (cc <= 57)          /* cc may be used without ... */
-                            cur_chr = 16 * cur_chr + cc - 48;
-                          else
-                            cur_chr = 16 * cur_chr + cc - 87;
-
+                          hex_to_cur_chr();
                           buffer[k - 1] = cur_chr;
                         }
                         else if (c < 64)
@@ -2254,22 +2011,24 @@ lab26:
                         else
                           buffer[k - 1] = c - 64;
 
-                        cur_input.limit_field = cur_input.limit_field - d;
+                        limit = limit - d;
                         first = first - d;
 
-                        while (k <= cur_input.limit_field)
+                        while (k <= limit)
                         {
                           buffer[k] = buffer[k + d];
                           incr(k);
                         }
-                        goto lab26;
+
+                        goto start_cs;
                       }
                     }
               }
-              cur_cs = single_base + buffer[cur_input.loc_field];
-              incr(cur_input.loc_field);
+
+              cur_cs = single_base + buffer[loc];
+              incr(loc);
             }
-lab40:
+found:
             cur_cmd = eq_type(cur_cs);
             cur_chr = equiv(cur_cs);
             
@@ -2283,7 +2042,7 @@ lab40:
             cur_cs = cur_chr + active_base;
             cur_cmd = eq_type(cur_cs);
             cur_chr = equiv(cur_cs);
-            cur_input.state_field = mid_line;
+            state = mid_line;
             
             if (cur_cmd >= outer_call)
               check_outer_validity();
@@ -2292,35 +2051,25 @@ lab40:
 
         case any_state_plus(sup_mark):
           {
-            if (cur_chr == buffer[cur_input.loc_field])
-              if (cur_input.loc_field < cur_input.limit_field)
+            if (cur_chr == buffer[loc])
+              if (loc < limit)
               {
-                c = buffer[cur_input.loc_field + 1];
+                c = buffer[loc + 1];
 
                 if (c < 128)
                 {
-                  cur_input.loc_field = cur_input.loc_field + 2;
+                  loc = loc + 2;
 
-                  if ((((c >= 48) && (c <= 57)) || ((c >= 97) && (c <= 102))))
-                    if (cur_input.loc_field <= cur_input.limit_field)
+                  if (is_hex(c))
+                    if (loc <= limit)
                     {
-                      cc = buffer[cur_input.loc_field];
+                      cc = buffer[loc];
 
-                      if ((((cc >= 48) && (cc <= 57)) || ((cc >= 97) && (cc <= 102))))
+                      if (is_hex(cc))
                       {
-                        incr(cur_input.loc_field);
-
-                        if (c <= 57)
-                          cur_chr = c - 48;
-                        else
-                          cur_chr = c - 87;
-
-                        if (cc <= 57)
-                          cur_chr = 16 * cur_chr + cc - 48;
-                        else
-                          cur_chr = 16 * cur_chr + cc - 87;
-
-                        goto lab21;
+                        incr(loc);
+                        hex_to_cur_chr();
+                        goto reswitch;
                       }
                     }
 
@@ -2329,11 +2078,11 @@ lab40:
                   else
                     cur_chr = c - 64;
 
-                  goto lab21;
+                  goto reswitch;
                 }
               }
 
-              cur_input.state_field = mid_line;
+              state = mid_line;
           }
           break;
 
@@ -2345,20 +2094,20 @@ lab40:
             deletions_allowed = false;
             error();
             deletions_allowed = true;
-            goto lab20;
+            goto restart;
           }
           break;
 
         case mid_line + spacer:
           {
-            cur_input.state_field = skip_blanks;
+            state = skip_blanks;
             cur_chr = ' ';
           }
           break;
 
         case mid_line + car_ret:
           {
-            cur_input.loc_field = cur_input.limit_field + 1;
+            loc = limit + 1;
             cur_cmd = spacer;
             cur_chr = ' ';
           }
@@ -2367,14 +2116,14 @@ lab40:
         case skip_blanks + car_ret:
         case any_state_plus(comment):
           {
-            cur_input.loc_field = cur_input.limit_field + 1;
-            goto lab25;
+            loc = limit + 1;
+            goto lab_switch;
           }
           break;
 
         case new_line + car_ret:
           {
-            cur_input.loc_field = cur_input.limit_field + 1;
+            loc = limit + 1;
             cur_cs = par_loc;
             cur_cmd = eq_type(cur_cs);
             cur_chr = equiv(cur_cs);
@@ -2391,7 +2140,7 @@ lab40:
         case skip_blanks + left_brace:
         case new_line + left_brace:
           {
-            cur_input.state_field = mid_line;
+            state = mid_line;
             incr(align_state);
           }
           break;
@@ -2403,14 +2152,14 @@ lab40:
         case skip_blanks + right_brace:
         case new_line + right_brace:
           {
-            cur_input.state_field = 1;
+            state = 1;
             decr(align_state);
           }
           break;
 
         case add_delims_to(skip_blanks):
         case add_delims_to(new_line):
-          cur_input.state_field = 1;
+          state = 1;
           break;
 
         default:
@@ -2419,16 +2168,16 @@ lab40:
     }
     else
     {
-      cur_input.state_field = new_line;
+      state = new_line;
 
-      if (cur_input.name_field > 17)
+      if (name > 17)
       {
         incr(line);
-        first = cur_input.start_field;
+        first = start;
 
         if (!force_eof)
         {
-          if (input_ln(input_file[cur_input.index_field], true))
+          if (input_ln(cur_file, true))
             firm_up_the_line();
           else
             force_eof = true;
@@ -2438,26 +2187,24 @@ lab40:
         {
           print_char(')');
           decr(open_parens);
-#ifndef _WINDOWS
-          fflush(stdout);
-#endif
+          update_terminal();
           force_eof = false;
           end_file_reading();
           check_outer_validity();
-          goto lab20;
+          goto restart;
         }
 
-        if ((end_line_char < 0) || (end_line_char > 255))
-          decr(cur_input.limit_field);
+        if (end_line_char_inactive())
+          decr(limit);
         else
-          buffer[cur_input.limit_field] = end_line_char;
+          buffer[limit] = end_line_char;
 
-        first = cur_input.limit_field + 1;
-        cur_input.loc_field = cur_input.start_field;
+        first = limit + 1;
+        loc = start;
       }
       else
       {
-        if (!(cur_input.name_field == 0))
+        if (!(name == 0))
         {
           cur_cmd = 0;
           cur_chr = 0;
@@ -2467,7 +2214,7 @@ lab40:
         if (input_ptr > 0)
         {
           end_file_reading();
-          goto lab20;
+          goto restart;
         }
 
         if (selector < log_only)
@@ -2475,52 +2222,40 @@ lab40:
 
         if (interaction > nonstop_mode)
         {
-          if ((end_line_char < 0) || (end_line_char > 255))
-            incr(cur_input.limit_field);
+          if (end_line_char_inactive())
+            incr(limit);
 
-          if (cur_input.limit_field == cur_input.start_field)
+          if (limit == start)
             print_nl("(Please type a command or say `\\end')");
 
           print_ln();
-          first = cur_input.start_field;
+          first = start;
+          prompt_input("*");
+          limit = last;
 
-          {
-            ;
-            print_string("*");
-            term_input("*", 0);
-          }
-
-          cur_input.limit_field = last;
-
-          if ((end_line_char < 0) || (end_line_char > 255))
-            decr(cur_input.limit_field);
+          if (end_line_char_inactive())
+            decr(limit);
           else
-            buffer[cur_input.limit_field]= end_line_char;
+            buffer[limit]= end_line_char;
 
-          first = cur_input.limit_field + 1;
-          cur_input.loc_field = cur_input.start_field;
+          first = limit + 1;
+          loc = start;
         }
         else
         {
           fatal_error("*** (job aborted, no legal \\end found)");
-          return;     // abort_flag set
-        }
-      }
-
-      {
-        if (interrupt != 0)
-        {
-          pause_for_instructions();
+          return;
         }
       }
 
-      goto lab25;
+      check_interrupt();
+      goto lab_switch;
     }
   }
-  else if (cur_input.loc_field != 0)
+  else if (loc != 0)
   {
-    t = info(cur_input.loc_field);
-    cur_input.loc_field = link(cur_input.loc_field);
+    t = info(loc);
+    loc = link(loc);
 
     if (t >= cs_token_flag)
     {
@@ -2531,8 +2266,8 @@ lab40:
       if (cur_cmd >= outer_call)
         if (cur_cmd == dont_expand)
         {
-          cur_cs = info(cur_input.loc_field) - cs_token_flag;
-          cur_input.loc_field = 0;
+          cur_cs = info(loc) - cs_token_flag;
+          loc = 0;
           cur_cmd = eq_type(cur_cs);
           cur_chr = equiv(cur_cs);
 
@@ -2564,8 +2299,8 @@ lab40:
 
         case out_param:
           {
-            begin_token_list(param_stack[cur_input.limit_field + cur_chr - 1], parameter);
-            goto lab20;
+            begin_token_list(param_stack[limit + cur_chr - 1], parameter);
+            goto restart;
           }
           break;
 
@@ -2577,7 +2312,7 @@ lab40:
   else
   {
     end_token_list();
-    goto lab20;
+    goto restart;
   }
 
   if (cur_cmd <= car_ret)
@@ -2587,7 +2322,7 @@ lab40:
         if ((scanner_status == aligning) && (cur_align == 0))
         {
           fatal_error("(interwoven alignment preambles are not allowed)");
-          return;     // abort_flag set
+          return;
         }
 
         cur_cmd = extra_info(cur_align);
@@ -2599,7 +2334,6 @@ lab40:
           begin_token_list(v_part(cur_align), v_template);
 
         align_state = 1000000L;
-        goto lab20;
+        goto restart;
       }
-}
-//#pragma optimize ("", on)             /* 96/Sep/12 */
\ No newline at end of file
+}
\ No newline at end of file