OSDN Git Service

redesigned backends.
[putex/putex.git] / src / texsourc / tex8.c
index ccc09ee..c8cd06b 100644 (file)
@@ -1,31 +1,24 @@
-#ifdef _WINDOWS
-  #define NOCOMM
-  #define NOSOUND
-  #define NODRIVERS
-  #define STRICT
-  #pragma warning(disable:4115) // kill rpcasync.h complaint
-  #include <windows.h>
-  #define MYLIBAPI __declspec(dllexport)
-#endif
+/* Copyright 2014 Clerk Ma
 
-#include "texwin.h"
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 2 of the License, or
+   (at your option) any later version.
 
-#pragma warning(disable:4996)
-#pragma warning(disable:4131) // old style declarator
-#pragma warning(disable:4135) // conversion between different integral types 
-#pragma warning(disable:4127) // conditional expression is constant
+   This program is distributed in the hope that it will be useful, but
+   WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   General Public License for more details.
 
-#include <setjmp.h>
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, write to the Free Software
+   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+   02110-1301 USA.  */
 
 #define EXTERN extern
 
 #include "texd.h"
 
-#pragma warning(disable:4244)       /* 96/Jan/10 */
-
-/* *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** */
-
-/* math_fraction etc used to be in tex7.c */
 /* sec 1181 */
 void math_fraction (void)
 {
@@ -69,15 +62,17 @@ void math_fraction (void)
       scan_delimiter(right_delimiter(incompleat_noad), false);
     }
 
-    switch(c % delimited_code)
+    switch (c % delimited_code)
     {
       case above_code:
         scan_dimen(false, false, false);
         thickness(incompleat_noad) = cur_val;
         break;
+
       case over_code:
         thickness(incompleat_noad) = default_code;
         break;
+
       case atop_code:
         thickness(incompleat_noad) = 0;
         break;
@@ -88,7 +83,7 @@ void math_fraction (void)
 void math_left_right (void)
 {
   small_number t;
-  halfword p;
+  pointer p;
 
   t = cur_chr;
 
@@ -123,10 +118,7 @@ void math_left_right (void)
     {
       p = fin_mlist(p);
       unsave();
-      {
-        mem[tail].hh.v.RH = new_noad();
-        tail = mem[tail].hh.v.RH;
-      }
+      tail_append(new_noad());
       type(tail) = inner_noad;
       math_type(nucleus(tail)) = sub_mlist;
       info(nucleus(tail)) = p;
@@ -136,12 +128,12 @@ void math_left_right (void)
 /* sec 1194 */
 void after_math (void)
 {
-  bool l;
-  bool danger;
+  boolean l;
+  boolean danger;
   integer m;
-  halfword p;
-  halfword a;
-  halfword b;
+  pointer p;
+  pointer a;
+  pointer b;
   scaled w;
   scaled z;
   scaled e;
@@ -149,14 +141,14 @@ void after_math (void)
   scaled d;
   scaled s;
   small_number g1, g2;
-  halfword r;
-  halfword t;
+  pointer r;
+  pointer t;
 
   danger = false;
   
-  if ((font_params[fam_fnt(2 + text_size)] < 22) ||
-    (font_params[fam_fnt(2 + script_size)] < 22) ||
-    (font_params[fam_fnt(2 + script_script_size)] < 22))
+  if ((font_params[fam_fnt(2 + text_size)] < total_mathsy_params) ||
+    (font_params[fam_fnt(2 + script_size)] < total_mathsy_params) ||
+    (font_params[fam_fnt(2 + script_script_size)] < total_mathsy_params))
   {
     print_err("Math formula deleted: Insufficient symbol fonts");
     help3("Sorry, but I can't typeset math unless \\textfont 2",
@@ -166,9 +158,9 @@ void after_math (void)
     flush_math();
     danger = true;
   }
-  else if ((font_params[fam_fnt(3 + text_size)] < 13) ||
-      (font_params[fam_fnt(3 + script_size)] < 13) ||
-      (font_params[fam_fnt(3 + script_script_size)] < 13))
+  else if ((font_params[fam_fnt(3 + text_size)] < total_mathex_params) ||
+    (font_params[fam_fnt(3 + script_size)] < total_mathex_params) ||
+    (font_params[fam_fnt(3 + script_script_size)] < total_mathex_params))
   {
     print_err("Math formula deleted: Insufficient extension fonts");
     help3("Sorry, but I can't typeset math unless \\textfont 3",
@@ -196,6 +188,7 @@ void after_math (void)
         back_error();
       }
     }
+
     cur_mlist = p;
     cur_style = text_style;
     mlist_penalties = false;
@@ -204,14 +197,14 @@ void after_math (void)
     unsave();
     decr(save_ptr);
 
-    if (save_stack[save_ptr + 0].cint == 1)
+    if (saved(0) == 1)
       l = true;
 
     danger = false;
 
-    if ((font_params[fam_fnt(2 + text_size)] < 22) ||
-      (font_params[fam_fnt(2 + script_size)] < 22) ||
-      (font_params[fam_fnt(2 + script_script_size)] < 22))
+    if ((font_params[fam_fnt(2 + text_size)] < total_mathsy_params) ||
+      (font_params[fam_fnt(2 + script_size)] < total_mathsy_params) ||
+      (font_params[fam_fnt(2 + script_script_size)] < total_mathsy_params))
     {
       print_err("Math formula deleted: Insufficient symbol fonts");
       help3("Sorry, but I can't typeset math unless \\textfont 2",
@@ -221,9 +214,9 @@ void after_math (void)
       flush_math();
       danger = true;
     }
-    else if ((font_params[fam_fnt(3 + text_size)] < 13) ||
-       (font_params[fam_fnt(3 + script_size)] < 13) ||
-       (font_params[fam_fnt(3 + script_script_size)] < 13))
+    else if ((font_params[fam_fnt(3 + text_size)] < total_mathex_params) ||
+      (font_params[fam_fnt(3 + script_size)] < total_mathex_params) ||
+      (font_params[fam_fnt(3 + script_script_size)] < total_mathex_params))
     {
       print_err("Math formula deleted: Insufficient extension fonts");
       help3("Sorry, but I can't typeset math unless \\textfont 3",
@@ -242,10 +235,7 @@ void after_math (void)
 
   if (m < 0)
   {
-    {
-      mem[tail].hh.v.RH = new_math(math_surround, 0);
-      tail = mem[tail].hh.v.RH;
-    }
+    tail_append(new_math(math_surround, 0));
     cur_mlist = p;
     cur_style = text_style;
     mlist_penalties = (mode > 0);
@@ -255,10 +245,7 @@ void after_math (void)
     while(link(tail) != 0)
       tail = link(tail);
 
-    {
-      mem[tail].hh.v.RH = new_math(math_surround, 1);
-      tail = mem[tail].hh.v.RH;
-    }
+    tail_append(new_math(math_surround, 1));
     space_factor = 1000;
     unsave();
   }
@@ -276,6 +263,7 @@ void after_math (void)
         back_error();
       }
     }
+
     cur_mlist = p;
     cur_style = display_style;
     mlist_penalties = false;
@@ -303,7 +291,8 @@ void after_math (void)
 
     if (w + q > z)
     {
-      if ((e != 0) && ((w - total_shrink[normal] + q <= z) || (total_shrink[fil] != 0) || (total_shrink[fill] != 0) || (total_shrink[filll] != 0)))
+      if ((e != 0) && ((w - total_shrink[normal] + q <= z) || (total_shrink[fil] != 0) ||
+        (total_shrink[fill] != 0) || (total_shrink[filll] != 0)))
       {
         free_node(b, box_node_size);
         b = hpack(p, z - q, 0);
@@ -333,10 +322,7 @@ void after_math (void)
             d = 0;
     }
 
-    {
-      mem[tail].hh.v.RH = new_penalty(pre_display_penalty);
-      tail = mem[tail].hh.v.RH;
-    }
+    tail_append(new_penalty(pre_display_penalty));
 
     if ((d + s <= pre_display_size) || l)
     {
@@ -352,15 +338,11 @@ void after_math (void)
     {
       shift_amount(a) = s;
       append_to_vlist(a);
-      {
-        mem[tail].hh.v.RH = new_penalty(10000);
-        tail = mem[tail].hh.v.RH;
-      }
+      tail_append(new_penalty(10000));
     }
     else
     {
-      mem[tail].hh.v.RH = new_param_glue(g1);
-      tail = mem[tail].hh.v.RH;
+      tail_append(new_param_glue(g1));
     }
 
     if (e != 0)
@@ -387,10 +369,7 @@ void after_math (void)
 
     if ((a != 0) && (e == 0) && !l)
     {
-      {
-        mem[tail].hh.v.RH = new_penalty(10000);
-        tail = mem[tail].hh.v.RH;
-      }
+      tail_append(new_penalty(10000));
       shift_amount(a) = s + z - width(a);
       append_to_vlist(a);
       g2 = 0;
@@ -398,19 +377,15 @@ void after_math (void)
 
     if (t != adjust_head)
     {
-      mem[tail].hh.v.RH = mem[adjust_head].hh.v.RH;
+      link(tail) = link(adjust_head);
       tail = t;
     }
 
-    {
-      mem[tail].hh.v.RH = new_penalty(post_display_penalty);
-      tail = mem[tail].hh.v.RH;
-    }
+    tail_append(new_penalty(post_display_penalty));
 
     if (g2 > 0)
     {
-      mem[tail].hh.v.RH = new_param_glue(g2);
-      tail = mem[tail].hh.v.RH;
+      tail_append(new_param_glue(g2));
     }
 
     resume_after_display();
@@ -430,14 +405,7 @@ void resume_after_display (void)
   push_nest();
   mode = hmode;
   space_factor = 1000;
-
-  if (language <= 0)
-    cur_lang = 0; 
-  else if (language > 255)
-    cur_lang = 0;
-  else
-    cur_lang = language;
-
+  set_cur_lang();
   clang = cur_lang;
   prev_graf =(norm_min(left_hyphen_min) * 64 + norm_min(right_hyphen_min)) * 65536L + cur_lang;
 
@@ -461,7 +429,7 @@ lab20:
     {
       get_token();
     }
-  while (!(cur_tok != 2592));
+  while (!(cur_tok != space_token));
 
   if ((cur_cs == 0) || (cur_cs > frozen_control_sequence))
   {
@@ -493,7 +461,7 @@ void trap_zero_glue (void)
 /* sec 1236 */
 void do_register_command_ (small_number a)
 {
-  halfword l, q, r, s;
+  pointer l, q, r, s;
   char p;
 
   q = cur_cmd;
@@ -525,24 +493,27 @@ void do_register_command_ (small_number a)
     p = cur_chr;
     scan_eight_bit_int();
 
-    switch(p)
+    switch (p)
     {
       case int_val:
         l = cur_val + count_base;
         break;
+
       case dimen_val:
         l = cur_val + scaled_base;
         break;
+
       case glue_val:
         l = cur_val + skip_base;
         break;
+
       case mu_val:
         l = cur_val + mu_skip_base;
         break;
     }
   }
-lab40:;
 
+lab40:
   if (q == tex_register)
     scan_optional_equals();
   else
@@ -659,7 +630,6 @@ lab40:;
       eq_define(l, glue_ref, cur_val);
   }
 }
-/* called only from itex.c */
 /* sec 1243 */
 void alter_aux (void)
 {
@@ -702,7 +672,7 @@ void alter_prev_graf (void)
   nest[nest_ptr] = cur_list;
   p = nest_ptr;
 
-  while(abs(nest[p].mode_field) != vmode)
+  while (abs(nest[p].mode_field) != vmode)
     decr(p);
 
   scan_optional_equals();
@@ -763,7 +733,7 @@ void alter_box_dimen (void)
 /* sec 1257 */
 void new_font_(small_number a)
 {
-  halfword u;
+  pointer u;
   scaled s;
   internal_font_number f;
   str_number t;
@@ -786,31 +756,11 @@ void new_font_(small_number a)
   else
   {
     old_setting = selector;
-    selector = 21;
+    selector = new_string;
     print_string("FONT");
     print(u - active_base);
     selector = old_setting;
-
-    {
-#ifdef ALLOCATESTRING
-      if (pool_ptr + 1 > current_pool_size)
-        str_pool = realloc_str_pool (increment_pool_size);
-
-      if (pool_ptr + 1 > current_pool_size) /* 94/Jan/24 */
-      {
-        overflow("pool size", current_pool_size - init_pool_ptr); /* 97/Mar/9 */
-        return;     // abort_flag set
-      }
-#else
-      if (pool_ptr + 1 > pool_size)
-      {
-        overflow("pool size", pool_size - init_pool_ptr); /* pool size */
-        return;     // abort_flag set
-      }
-#endif
-
-    }
-
+    str_room(1);
     t = make_string();
   }
 
@@ -831,13 +781,13 @@ void new_font_(small_number a)
 
     if ((s <= 0) || (s >= 134217728L)) /* 2^27 */
     {
-      print_err("Improper `at' size(");
+      print_err("Improper `at' size (");
       print_scaled(s);
       print_string("pt), replaced by 10pt");
       help2("I can only handle fonts at positive sizes that are",
         "less than 2048pt, so I've changed what you said to 10pt.");
       error();
-      s = 10 * 65536L;    /* 10pt */
+      s = 10 * 65536L;
     }
   }
   else if (scan_keyword("scaled"))
@@ -860,7 +810,7 @@ void new_font_(small_number a)
 
   flushable_string = str_ptr - 1;
 
-  if (trace_flag) /* debugging stuff only 98/Oct/5 */
+  if (trace_flag)
   {
     int i, k1, k2, l1, l2;
     char *sch = log_line;
@@ -886,8 +836,7 @@ void new_font_(small_number a)
     show_line(log_line, 0);
   }
 
-/* paragraph 1260 for f <- fontbase+1 to font_ptr do */
-  for (f = 1; f < font_ptr; f++)
+  for (f = font_base + 1; f < font_ptr; f++)
   {
     if (str_eq_str(font_name[f], cur_name) && str_eq_str(font_area[f], cur_area))
     {
@@ -901,7 +850,7 @@ void new_font_(small_number a)
       {
         if (s == font_size[f])
         {
-          if (ignore_frozen == 0 || f > frozenfontptr)
+          if (ignore_frozen == 0 || f > frozen_font_ptr)
           {
             if (trace_flag)
             {
@@ -914,8 +863,8 @@ void new_font_(small_number a)
       }
       else if (font_size[f] == xn_over_d(font_dsize[f], - (integer) s, 1000))
       {
-        if (ignore_frozen == 0 || f > frozenfontptr)
-        { /* 99/Mar/26 */
+        if (ignore_frozen == 0 || f > frozen_font_ptr)
+        {
           if (trace_flag)
           {
             sprintf(log_line, "SKIPPING %ld ", s);
@@ -1006,38 +955,24 @@ void open_or_close_in (void)
     scan_file_name();
     pack_file_name(cur_name, cur_area, cur_ext);
 
-/* *** some changes in following in 3.14159 *** */
-/*  if current extension is *not* empty, try to open using name as is */
-/*  string 335 is "" the empty string */
     if ((cur_ext != 335) && a_open_in(read_file[n], TEXINPUTPATH))
-      read_open[n]= 1;
-/*  we get here if extension is "", or file with extension failed to open */
-/*  if current extension is not `tex,' and `tex' is not irrelevant, try it */
-/*  string 785 is  .tex */
-    else if ((cur_ext != 785) && (name_length + 5 < PATHMAX) &&
-/* *** some changes in above file name handling *** */
-      (!extensionirrelevantp(name_of_file, name_length, "tex")))
+      read_open[n] = 1;
+    else if ((cur_ext != 785) && (name_length + 5 < PATH_MAX))
+    {
+      strncpy((char *) name_of_file + name_length + 1, ".tex ", 5);
+      name_length = name_length + 4;
+
+      if (a_open_in(read_file[n], TEXINPUTPATH))
+        read_open[n] = just_open;
+      else
       {
-        name_of_file[name_length + 1] = '.';    /* .tex  */
-        name_of_file[name_length + 2] = 't';
-        name_of_file[name_length + 3] = 'e';
-        name_of_file[name_length + 4] = 'x';
-        name_of_file[name_length + 5] = ' ';
-        name_length = name_length + 4;
-
-        if (a_open_in(read_file[n], TEXINPUTPATH))
-          read_open[n] = just_open;
-        else
-        {
-          name_length = name_length - 4;      /* remove ".tex" again */
-          name_of_file[name_length + 1] = ' ';
+        name_length = name_length - 4;
+        name_of_file[name_length + 1] = ' ';
 
-          if ((cur_ext == 335) && a_open_in(read_file[n], TEXINPUTPATH))
-            read_open[n]= 1;
-          else if (maketextex () && a_open_in(read_file[n], TEXINPUTPATH))
-            read_open[n]= 1;
-        }
+        if ((cur_ext == 335) && a_open_in(read_file[n], TEXINPUTPATH))
+          read_open[n] = 1;
       }
+    }
   }
 }
 /* sec 1279 */
@@ -1054,26 +989,7 @@ void issue_message (void)
   token_show(def_ref);
   selector = old_setting;
   flush_list(def_ref);
-
-  {
-#ifdef ALLOCATESTRING
-    if (pool_ptr + 1 > current_pool_size)
-      str_pool = realloc_str_pool (increment_pool_size);
-
-    if (pool_ptr + 1 > current_pool_size)
-    {
-      overflow("pool size", current_pool_size - init_pool_ptr);
-      return;     // abort_flag set
-    }
-#else
-    if (pool_ptr + 1 > pool_size)
-    {
-      overflow("pool size", pool_size - init_pool_ptr); /* pool size */
-      return;     // abort_flag set
-    }
-#endif
-  }
-
+  str_room(1);
   s = make_string();
 
   if (c == 0)
@@ -1118,8 +1034,8 @@ void issue_message (void)
 /* sec 1288 */
 void shift_case (void)
 {
-  halfword b;
-  halfword p;
+  pointer b;
+  pointer p;
   halfword t;
   eight_bits c;
 
@@ -1131,7 +1047,7 @@ void shift_case (void)
   {
     t = info(p); 
 
-    if (t < cs_token_flag + single_base)    /* 4095 + 257 = cs_tokenflag + single_base */
+    if (t < cs_token_flag + single_base)
     {
       c = t % 256;
 
@@ -1141,15 +1057,16 @@ void shift_case (void)
 
     p = link(p);
   }
+
   begin_token_list(link(def_ref), 3);
   free_avail(def_ref);
 }
 /* sec 1293 */
 void show_whatever (void)
 {
-  halfword p;
+  pointer p;
 
-  switch(cur_chr)
+  switch (cur_chr)
   {
     case show_lists:
       {
@@ -1157,6 +1074,7 @@ void show_whatever (void)
         show_activities();
       }
       break;
+
     case show_box_code:
       {
         scan_eight_bit_int();
@@ -1171,6 +1089,7 @@ void show_whatever (void)
           show_box(box(cur_val));
       }
       break;
+
     case show_code:
       {
         get_token();
@@ -1190,6 +1109,7 @@ void show_whatever (void)
         goto lab50;
       }
       break;
+
     default:
       {
         p = the_toks();
@@ -1237,12 +1157,13 @@ lab50:
       "And type `I\\tracingonline=1\\show...' to show boxes and",
       "lists on your terminal as well as in the transcript file.");
   }
+
   error();
 }
 /* sec 1349 */
 void new_whatsit_(small_number s, small_number w)
 {
-  halfword p;
+  pointer p;
 
   p = get_node(w);
   type(p) = whatsit_node;
@@ -1268,15 +1189,14 @@ void new_write_whatsit_(small_number w)
     else if (cur_val > 15)
       cur_val = 16;
   }
+
   write_stream(tail) = cur_val;
 }
 /* sec 1348 */
 void do_extension (void)
 {
-/*  integer i, j, k;  */
   integer k;
-/*  halfword p, q, r;  */
-  halfword p;
+  pointer p;
 
   switch(cur_chr)
   {
@@ -1290,6 +1210,7 @@ void do_extension (void)
         open_ext(tail) = cur_ext;
       }
       break;
+
     case write_node:
       {
         k = cur_cs;
@@ -1299,12 +1220,14 @@ void do_extension (void)
         write_tokens(tail) = def_ref;
       }
       break;
+
     case close_node:
       {
         new_write_whatsit(write_node_size);
         write_tokens(tail) = 0;
       }
       break;
+
     case special_node:
       {
         new_whatsit(special_node, write_node_size);
@@ -1313,6 +1236,7 @@ void do_extension (void)
         write_tokens(tail) = def_ref;
       }
       break;
+
     case immediate_code:
       {
         get_x_token();
@@ -1330,6 +1254,7 @@ void do_extension (void)
           back_input();
       }
       break;
+
     case set_language_code:
       if (abs(mode) != hmode)
       {
@@ -1352,9 +1277,10 @@ void do_extension (void)
         what_rhm(tail) = norm_min(right_hyphen_min);
       }
       break;
+
     default:
       {
-        confusion("display");
+        confusion("ext1");
         return;       // abort_flag set
       }
       break;
@@ -1394,6 +1320,7 @@ void handle_right_brace (void)
     case simple_group:
       unsave();
       break;
+
     case bottom_level:
       {
         print_err("Too many }'s");
@@ -1402,32 +1329,38 @@ void handle_right_brace (void)
         error();
       }
       break;
+
     case semi_simple_group:
     case math_shift_group:
     case math_left_group:
       extra_right_brace();
       break;
+
     case hbox_group:
       package(0);
       break;
+
     case adjust_hbox_group:
       {
         adjust_tail = adjust_head;
         package(0);
       }
       break;
+
     case vbox_group:
       {
         end_graf();
         package(0);
       }
       break;
+
     case vtop_group:
       {
         end_graf();
         package(vtop_code);
       }
       break;
+
     case insert_group:
       {
         end_graf();
@@ -1437,17 +1370,14 @@ void handle_right_brace (void)
         f = floating_penalty;
         unsave();
         decr(save_ptr);
-        p = vpackage(mem[head].hh.v.RH, 0, 1, 1073741823L);  /* 2^30 - 1 */
+        p = vpackage(link(head), 0, 1, 1073741823L);  /* 2^30 - 1 */
         pop_nest();
 
-        if (save_stack[save_ptr + 0].cint < 255)
+        if (saved(0) < 255)
         {
-          {
-            mem[tail].hh.v.RH = get_node(5);
-            tail = mem[tail].hh.v.RH;
-          }
+          tail_append(get_node(ins_node_size));
           type(tail) = ins_node;
-          subtype(tail) = save_stack[save_ptr + 0].cint;
+          subtype(tail) = saved(0);
           height(tail) = height(p) + depth(p);
           ins_ptr(tail) = list_ptr(p);
           split_top_ptr(tail) = q;
@@ -1456,10 +1386,7 @@ void handle_right_brace (void)
         }
         else
         {
-          {
-            mem[tail].hh.v.RH = get_node(2);
-            tail = mem[tail].hh.v.RH;
-          }
+          tail_append(get_node(small_node_size));
           type(tail) = adjust_node;
           subtype(tail) = 0;
           adjust_ptr(tail) = list_ptr(p);
@@ -1481,12 +1408,14 @@ void handle_right_brace (void)
           help2("Your sneaky output routine has problematic {'s and/or }'s.",
             "I can't handle that very well; good luck.");
           error();
+
           do
             {
               get_token();
             }
           while (!(cur_input.loc_field == 0));
         }
+
         end_token_list();
         end_graf();
         unsave();
@@ -1499,7 +1428,7 @@ void handle_right_brace (void)
           print_esc("box");
           print_int(255);
           help3("Your \\output commands should empty \\box255,",
-            "e.g., by saying `\\ship_out\\box255'.",
+            "e.g., by saying `\\shipout\\box255'.",
             "Proceed; I'll discard its present contents.");
           box_error(255);
         }
@@ -1524,9 +1453,11 @@ void handle_right_brace (void)
         build_page();
       }
       break;
+
     case disc_group:
       build_discretionary();
       break;
+
     case align_group:
       {
         back_input();
@@ -1538,6 +1469,7 @@ void handle_right_brace (void)
         ins_error();
       }
       break;
+
     case no_align_group:
       {
         end_graf();
@@ -1545,32 +1477,33 @@ void handle_right_brace (void)
         align_peek();
       }
       break;
+
     case vcenter_group:
       {
         end_graf();
         unsave();
         save_ptr = save_ptr - 2;
-        p = vpackage(link(head), save_stack[save_ptr + 1].cint, save_stack[save_ptr + 0].cint, 1073741823L);   /* 2^30 - 1 */
+        p = vpackage(link(head), saved(1), saved(0), 1073741823L);   /* 2^30 - 1 */
         pop_nest();
-        {
-          mem[tail].hh.v.RH = new_noad();
-          tail = mem[tail].hh.v.RH;
-        }
+        tail_append(new_noad());
         type(tail) = vcenter_noad;
         math_type(nucleus(tail)) = sub_box;
         info(nucleus(tail)) = p;
       }
       break;
+
     case math_choice_group:
       build_choices();
       break;
+
     case math_group:
       {
         unsave();
         decr(save_ptr);
-        math_type(save_stack[save_ptr + 0].cint) = sub_mlist;
+        math_type(saved(0)) = sub_mlist;
         p = fin_mlist(0);
-        info(save_stack[save_ptr + 0].cint) = p;
+        info(saved(0)) = p;
+
         if (p != 0)
           if (link(p) == 0)
             if (type(p) == ord_noad)
@@ -1578,12 +1511,12 @@ void handle_right_brace (void)
               if (math_type(subscr(p)) == 0)
                 if (math_type(supscr(p)) == 0)
                 {
-                  mem[save_stack[save_ptr + 0].cint].hh = mem[p + 1].hh;
+                  mem[saved(0)].hh = mem[nucleus(p)].hh;
                   free_node(p, noad_size);
                 }
             }
             else if (type(p) == accent_noad)
-              if (save_stack[save_ptr + 0].cint == nucleus(tail))
+              if (saved(0) == nucleus(tail))
                 if (type(tail) == ord_noad)
                 {
                   q = head;
@@ -1647,6 +1580,7 @@ lab21:
     case hmode + char_given:
       goto lab70;
       break;
+
     case hmode + char_num:
       {
         scan_char_num();
@@ -1654,6 +1588,7 @@ lab21:
         goto lab70;
       }
       break;
+
     case hmode + no_boundary:
       {
         get_x_token();
@@ -1664,22 +1599,26 @@ lab21:
         goto lab21;
       }
       break;
+
     case hmode + spacer:
       if (space_factor == 1000)
         goto lab120;
       else
         app_space();
       break;
+
     case hmode + ex_space:
     case mmode + ex_space:
       goto lab120;
       break;
+
     case any_mode(relax):
     case vmode + spacer:
     case mmode + spacer:
     case mmode + no_boundary:
       ;
       break;
+
     case any_mode(ignore_spaces):
       {
         do
@@ -1690,10 +1629,12 @@ lab21:
         goto lab21;
       }
       break;
+
     case vmode + stop:
       if (its_all_over())
         return;
       break;
+
     case vmode + vmove:
     case hmode + hmove:
     case mmode + hmove:
@@ -1704,6 +1645,7 @@ lab21:
     case any_mode(mac_param):
       report_illegal_case();
       break;
+
     case non_math(sup_mark):
     case non_math(sub_mark):
     case non_math(math_char_num):
@@ -1730,14 +1672,12 @@ lab21:
     case mmode + hrule:
       insert_dollar_sign();
       break;
+
     case vmode + hrule:
     case hmode + vrule:
     case mmode + vrule:
       {
-        {
-          mem[tail].hh.v.RH = scan_rule_spec();
-          tail = mem[tail].hh.v.RH;
-        }
+        tail_append(scan_rule_spec());
 
         if (abs(mode) == vmode)
           prev_depth = ignore_depth;
@@ -1745,31 +1685,38 @@ lab21:
           space_factor = 1000;
       }
       break;
+
     case vmode + vskip:
     case hmode + hskip:
     case mmode + hskip:
     case mmode + mskip:
       append_glue();
       break;
+
     case any_mode(kern):
     case mmode + mkern:
       append_kern();
       break;
+
     case non_math(left_brace):
       new_save_level(simple_group);
       break;
+
     case any_mode(begin_group):
       new_save_level(semi_simple_group);
       break;
+
     case any_mode(end_group):
       if (cur_group == semi_simple_group)
         unsave();
       else
         off_save();
       break;
+
     case any_mode(right_brace):
       handle_right_brace();
       break;
+
     case vmode + hmove:
     case hmode + vmove:
     case mmode + vmove:
@@ -1783,15 +1730,19 @@ lab21:
           scan_box(- (integer) cur_val);
       }
       break;
+
     case any_mode(leader_ship):
       scan_box(leader_flag - a_leaders + cur_chr);
       break;
+
     case any_mode(make_box):
       begin_box(0);
       break;
+
     case vmode + start_par:
       new_graf(cur_chr > 0);
       break;
+
     case vmode + letter:
     case vmode + other_char:
     case vmode + char_num:
@@ -1810,10 +1761,12 @@ lab21:
         new_graf(true);
       }
       break;
+
     case hmode + start_par:
     case mmode + start_par:
       indent_in_hmode();
       break;
+
     case vmode + par_end:
       {
         normal_paragraph();
@@ -1822,6 +1775,7 @@ lab21:
           build_page();
       }
       break;
+
     case hmode + par_end:
       {
         if (align_state < 0)
@@ -1833,6 +1787,7 @@ lab21:
           build_page();
       }
       break;
+
     case hmode + stop:
     case hmode + vskip:
     case hmode + hrule:
@@ -1840,55 +1795,66 @@ lab21:
     case hmode + halign:
       head_for_vmode();
       break;
+
     case any_mode(insert):
     case hmode + vadjust:
     case mmode + vadjust:
       begin_insert_or_adjust();
       break;
+
     case any_mode(mark):
       make_mark();
       break;
+
     case any_mode(break_penalty):
       append_penalty();
       break;
+
     case any_mode(remove_item):
       delete_last();
       break;
+
     case vmode + un_vbox:
     case hmode + un_hbox:
     case mmode + un_hbox:
       unpackage();
       break;
+
     case hmode + ital_corr:
       append_italic_correction();
       break;
+
     case mmode + ital_corr:
-      {
-        mem[tail].hh.v.RH = new_kern(0);
-        tail = mem[tail].hh.v.RH;
-      }
+      tail_append(new_kern(0));
       break;
+
     case hmode + discretionary:
     case mmode + discretionary:
       append_discretionary();
       break;
+
     case hmode + accent:
       make_accent();
       break;
+
     case any_mode(car_ret):
     case any_mode(tab_mark):
       align_error();
       break;
+
     case any_mode(no_align):
       noalign_error();
       break;
+
     case any_mode(omit):
       omit_error();
       break;
+
     case vmode + halign:
     case hmode + valign:
       init_align();
       break;
+
     case mmode + halign:
       if (privileged ())
         if (cur_group == math_shift_group)
@@ -1896,16 +1862,20 @@ lab21:
         else
           off_save();
       break;
+
     case vmode + endv:
     case hmode + endv:
       do_endv();
       break;
+
     case any_mode(end_cs_name):
       cs_error();
       break;
+
     case hmode + math_shift:
       init_math();
       break;
+
     case mmode + eq_no:
       if (privileged ())
         if (cur_group == math_shift_group)
@@ -1913,21 +1883,21 @@ lab21:
         else
           off_save();
       break;
+
     case mmode + left_brace:
       {
-        {
-          mem[tail].hh.v.RH = new_noad();
-          tail = mem[tail].hh.v.RH;
-        }
+        tail_append(new_noad());
         back_input();
         scan_math(nucleus(tail));
       }
       break;
+
     case mmode + letter:
     case mmode + other_char:
     case mmode + char_given:
       set_math_char(math_code(cur_chr));
       break;
+
     case mmode + char_num:
       {
         scan_char_num();
@@ -1935,41 +1905,46 @@ lab21:
         set_math_char(math_code(cur_chr));
       }
       break;
+
     case mmode + math_char_num:
       {
         scan_fifteen_bit_int();
         set_math_char(cur_val);
       }
       break;
+
     case mmode + math_given:
       set_math_char(cur_chr);
       break;
+
     case mmode + delim_num:
       {
         scan_twenty_seven_bit_int();
         set_math_char(cur_val / 4096);
       }
       break;
+
     case mmode + math_comp:
       {
-        {
-          mem[tail].hh.v.RH = new_noad();
-          tail = mem[tail].hh.v.RH;
-        }
+        tail_append(new_noad());
         type(tail) = cur_chr;
         scan_math(nucleus(tail));
       }
       break;
+
     case mmode + limit_switch:
       math_limit_switch();
       break;
+
     case mmode + radical:
       math_radical();
       break;
+
     case mmode + accent:
     case mmode + math_accent:
       math_ac();
       break;
+
     case mmode + vcenter:
       {
         scan_spec(vcenter_group, false);
@@ -1982,40 +1957,42 @@ lab21:
           begin_token_list(every_vbox, every_vbox_text);
       }
       break;
+
     case mmode + math_style:
-      {
-        mem[tail].hh.v.RH = new_style(cur_chr);
-        tail = mem[tail].hh.v.RH;
-      }
+      tail_append(new_style(cur_chr));
       break;
+
     case mmode + non_script:
       {
-        {
-          mem[tail].hh.v.RH = new_glue(0);
-          tail = mem[tail].hh.v.RH;
-        }
+        tail_append(new_glue(0));
         subtype(tail) = cond_math_glue;
       }
       break;
+
     case mmode + math_choice:
       append_choices();
       break;
+
     case mmode + sub_mark:
     case mmode + sup_mark:
       sub_sup();
       break;
+
     case mmode + above:
       math_fraction();
       break;
+
     case mmode + left_right:
       math_left_right();
       break;
+
     case mmode + math_shift:
       if (cur_group == math_shift_group)
         after_math();
       else
         off_save();
       break;
+
     case any_mode(toks_register):
     case any_mode(assign_toks):
     case any_mode(assign_int):
@@ -2048,30 +2025,37 @@ lab21:
     case any_mode(set_interaction):
       prefixed_command();
       break;
+
     case any_mode(after_assignment):
       {
         get_token();
         after_token = cur_tok;
       }
       break;
+
     case any_mode(after_group):
       {
         get_token();
         save_for_after(cur_tok);
       }
       break;
+
     case any_mode(in_stream):
       open_or_close_in();
       break;
+
     case any_mode(message):
       issue_message();
       break;
+
     case any_mode(case_shift):
       shift_case();
       break;
+
     case any_mode(xray):
       show_whatever();
       break;
+
     case any_mode(extension):
       do_extension();
       break;
@@ -2087,20 +2071,8 @@ lab70:
   if (mode > 0)
     if (language != clang)
       fix_language();
-  {
-    lig_stack = avail;
 
-    if (lig_stack == 0)
-      lig_stack = get_avail();
-    else
-    {
-      avail = mem[lig_stack].hh.v.RH;
-      mem[lig_stack].hh.v.RH = 0;
-#ifdef STAT
-      incr(dyn_used);
-#endif /* STAT */
-    }
-  }
+  fast_get_avail(lig_stack);
   font(lig_stack) = main_f;
   cur_l = cur_chr;
   character(lig_stack) = cur_l;
@@ -2193,20 +2165,7 @@ lab100:
 
 lab101:
   adjust_space_factor();
-  {
-    lig_stack = avail;
-
-    if (lig_stack == 0)
-      lig_stack = get_avail();
-    else
-    {
-      avail = mem[lig_stack].hh.v.RH;
-      mem[lig_stack].hh.v.RH = 0;
-#ifdef STAT
-      incr(dyn_used);
-#endif /* STAT */
-    }
-  }
+  fast_get_avail(lig_stack);
   font(lig_stack) = main_f;
   cur_r = cur_chr;
   character(lig_stack) = cur_r;
@@ -2252,10 +2211,7 @@ lab112:
       if (op_byte(main_j) >= kern_flag)
       {
         wrapup(rt_hit);
-        {
-          mem[tail].hh.v.RH = new_kern(char_kern(main_f, main_j));
-          tail = mem[tail].hh.v.RH;
-        }
+        tail_append(new_kern(char_kern(main_f, main_j)));
         goto lab90;
       }
 
@@ -2360,10 +2316,7 @@ lab95:
   main_p = lig_ptr(lig_stack);
 
   if (main_p != 0)     /* BUG FIX */
-  {
-    mem[tail].hh.v.RH = main_p;
-    tail = mem[tail].hh.v.RH;
-  }
+    tail_append(main_p);
 
   temp_ptr = lig_stack;
   lig_stack = link(temp_ptr);