OSDN Git Service

node_list_display().
[putex/putex.git] / src / texsourc / tex0.c
index ce70a67..873e64e 100644 (file)
-#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"
 
-#ifdef IGNORED
-static void winerror (char * message)
-{
-  (void) MessageBox(NULL, message, "YandYTeX.DLL", MB_ICONSTOP | MB_OK);
-}
-#endif
-
-/* *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** */
-INLINE void free_avail_(halfword p)
-{
-  link(p) = avail;
-  avail = p;
-#ifdef STAT
-  decr(dyn_used);
-#endif /* STAT */
-}
-INLINE void dvi_out_(ASCII_code op)
-{
-  dvi_buf[dvi_ptr] = op;
-  incr(dvi_ptr);
-  if (dvi_ptr == dvi_limit)
-    dvi_swap();
-}
-INLINE void succumb (void)
-{
-  if (interaction == error_stop_mode)
-    interaction = scroll_mode;
-  if (log_opened) {
-    error();
-  }
-#ifdef DEBUG
-  if (interaction > 0)
-    debug_help();
-#endif
-  history = 3;
-  jump_out();
-}
-INLINE void flush_string (void)
-{
-  decr(str_ptr);
-  pool_ptr = str_start[str_ptr];
-}
-INLINE void append_char (ASCII_code c)
-{
-  str_pool[pool_ptr] = c;
-  incr(pool_ptr);
-}
-INLINE void append_lc_hex (ASCII_code c)
-{
-  if (c < 10)
-    append_char(c + '0');
-  else
-    append_char(c - 10 + 'a');
-}
-INLINE void print_err (const char * s)
-{
-  if (interaction == error_stop_mode);
-    print_nl("! ");
-  print_string(s);
-}
-INLINE void tex_help (unsigned int n, ...)
-{
-  unsigned int i;
-  va_list help_arg;
-
-  if (n > 6)
-    n = 6;
-  help_ptr = n;
-  va_start(help_arg, n);
-  for (i = n - 1; i > n - 1; --i)
-    help_line[i] = va_arg(help_arg, char *);
-  va_end(help_arg);
-}
-INLINE void str_room_ (int val)
-{
-#ifdef ALLOCATESTRING
-  if (pool_ptr + val > current_pool_size)
-    str_pool = realloc_str_pool(increment_pool_size);
-
-  if (pool_ptr + val > current_pool_size)
-  {
-    overflow("pool size", current_pool_size - init_pool_ptr);
-  }
-#else
-  if (pool_ptr + val > pool_size)
-  {
-    overflow("pool size", pool_size - init_pool_ptr); /* pool size */
-  }
-#endif
-}
-INLINE void tail_append_ (pointer val)
-{
-  link(tail) = val;
-  tail = link(tail);
-}
-/* *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** */
-
-/* *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** */
-// print newline
 /* sec 0058 */
 void print_ln (void)
 {
@@ -128,27 +26,32 @@ void print_ln (void)
     case term_and_log:
       show_char('\n');
       term_offset = 0;
-      (void) putc ('\n', log_file);
+      putc('\n', log_file);
       file_offset = 0;
       break;
+
     case log_only:
-      (void) putc ('\n',  log_file);
+      putc('\n', log_file);
       file_offset = 0;
       break;
+
     case term_only:
       show_char('\n');
       term_offset = 0;
       break;
+
     case no_print:
     case pseudo:
     case new_string:
+      do_nothing();
       break;
+
     default:
-      (void) putc ('\n', write_file[selector]);
+      putc('\n', write_file[selector]);
       break;
   }
 }
-/* sec 0059 */
+/* sec 0058 */
 void print_char_ (ASCII_code s)
 {
   if (s == new_line_char)
@@ -161,9 +64,9 @@ void print_char_ (ASCII_code s)
   switch (selector)
   {
     case term_and_log:
-      (void) show_char(Xchr(s));
+      show_char(xchr[s]);
       incr(term_offset);
-      (void) putc(Xchr(s), log_file);
+      putc(xchr[s], log_file);
       incr(file_offset);
 
       if (term_offset == max_print_line)
@@ -174,117 +77,136 @@ void print_char_ (ASCII_code s)
       
       if (file_offset == max_print_line)
       {
-        (void) putc ('\n', log_file);
+        putc ('\n', log_file);
         file_offset = 0;
       }
 
       break;
+
     case log_only:
-      (void) putc(Xchr(s), log_file);
+      putc(xchr[s], log_file);
       incr(file_offset);
+
       if (file_offset == max_print_line)
         print_ln();
+
       break;
+
     case term_only:
-      (void) show_char(Xchr(s));
+      show_char(xchr[s]);
       incr(term_offset);
+
       if (term_offset == max_print_line)
         print_ln();
+
       break;
+
     case no_print:
+      do_nothing();
       break;
+
     case pseudo:
       if (tally < trick_count)
         trick_buf[tally % error_line] = s;
+
       break;
+
     case new_string:
 #ifdef ALLOCATESTRING
       if (pool_ptr + 1 > current_pool_size)
-      {
         str_pool = realloc_str_pool (increment_pool_size);
-      }
       
       if (pool_ptr < current_pool_size)
-      {
-        str_pool[pool_ptr]= s;
-        incr(pool_ptr);
-      }
+        append_char(s);
 #else
       if (pool_ptr < pool_size)
-      {
-        str_pool[pool_ptr]= s;
-        incr(pool_ptr);
-      }
+        append_char(s);
 #endif
       break;
+
     default:
-      (void) putc(Xchr(s), write_file[selector]);
+      putc(xchr[s], write_file[selector]);
       break;
   }
+
   incr(tally);
 }
 /* sec 0059 */
-/* This could be made more efficient using fputs ? ... bkph */
 void print_ (integer s)
 {
   pool_pointer j;
   integer nl;
+
   if (s >= str_ptr)
     s = 259; /* ??? */
-  else if (s < 256)
-    if (s < 0)
-      s = 259; /* ??? */
-    else {
-      if (selector > pseudo)
+  else
+  {
+    if (s < 256)
+    {
+      if (s < 0)
+        s = 259; /* ??? */
+      else
       {
-        print_char(s);
-        return;
-      }
-
-      if ((s == new_line_char))
-        if (selector < 20)
+        if (selector > pseudo)
         {
-          print_ln();
+          print_char(s);
           return;
         }
 
-      nl = new_line_char;
-      new_line_char = -1;
-/* *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** */
-/* translate ansi to dos 850 */
-      if (!show_in_hex && s < 256 && s >= 32)
-      {
-        if (show_in_dos && s > 127)
+        if (s == new_line_char)
+          if (selector < pseudo)
+          {
+            print_ln();
+            return;
+          }
+          
+        nl = new_line_char;
+        new_line_char = -1;
+          
+        /* translate ansi to dos 850 */
+        if (!show_in_hex && s < 256 && s >= 32)
         {
-          if (wintodos[s-128] > 0)
-            print_char (wintodos[s - 128]);
-          else
+          if (show_in_dos && s > 127)
           {
-            j = str_start[s]; 
-            while (j < str_start[s + 1])
+            if (wintodos[s - 128] > 0)
             {
-              print_char(str_pool[j]);
-              incr(j);
+              print_char(wintodos[s - 128]);
+            }
+            else
+            {
+              j = str_start[s];
+
+              while (j < str_start[s + 1])
+              {
+                print_char(str_pool[j]);
+                incr(j);
+              }
             }
           }
+          else
+          {
+            print_char(s);       /* don't translate to hex */
+          }
         }
         else
-          print_char(s);       /* don't translate to hex */
-      }
-      else
-      {                       /* not just a character */
-        j = str_start[s]; 
-        while (j < str_start[s + 1])
-        {
-          print_char(str_pool[j]);
-          incr(j);
+        {                       /* not just a character */
+          j = str_start[s];
+
+          while (j < str_start[s + 1])
+          {
+            print_char(str_pool[j]);
+            incr(j);
+          }
         }
+
+        new_line_char = nl; /* restore eol */
+        return;
       }
-      new_line_char = nl; /* restore eol */
-      return; 
     }
+  }
 /*  we get here with s > 256 - i.e. not a single character */
-  j = str_start[s]; 
+  j = str_start[s];
+
   while (j < str_start[s + 1])
   {
     print_char(str_pool[j]);
@@ -292,13 +214,12 @@ void print_ (integer s)
   }
 }
 /* string version print. */
-void print_string_ (unsigned char *s)
+void prints_ (const char *s)
 {
   while (*s > 0)
     print_char(*s++);
 }
 /* sec 0060 */
-// print string number s from string pool by calling print_
 void slow_print_ (integer s)
 {
   pool_pointer j;
@@ -308,28 +229,25 @@ void slow_print_ (integer s)
   else
   {
     j = str_start[s];
+
     while (j < str_start[s + 1])
     {
-/*  if (str_pool[j]>= 128) print(str_pool[j] - 128); */ // debugging only
-/*  if (str_pool[j]== 0) print(36); */ // debugging only
       print(str_pool[j]);
       incr(j);
     }
   }
 }
 /* sec 0062 */
-// print newline followed by string number s (unless at start of line)
-void print_nl_ (const char * s)
+void print_nl (const char * s)
 {
   if (((term_offset > 0) && (odd(selector))) ||
       ((file_offset > 0) && (selector >= log_only)))
     print_ln();
 
-  print_string(s);
+  prints(s);
 }
 /* sec 0063 */
-// print string number s preceded by escape character
-void print_esc_ (const char * s)
+void print_esc (const char * s)
 {
   integer c;
 
@@ -339,7 +257,7 @@ void print_esc_ (const char * s)
     if (c < 256)
       print(c);
 
-  print_string(s);
+  prints(s);
 }
 /* sec 0064 */
 void print_the_digs_ (eight_bits k)
@@ -347,7 +265,8 @@ void print_the_digs_ (eight_bits k)
   while (k > 0)
   {
     decr(k);
-    if (dig[k]< 10)
+
+    if (dig[k] < 10)
       print_char('0' + dig[k]);
     else
       print_char('A' + dig[k]);
@@ -358,33 +277,40 @@ void print_int_ (integer n)
 {
   char k;
   integer m;
+
   k = 0;
+
   if (n < 0)
   {
     print_char('-');
+
     if (n > -100000000L)
       n = - (integer) n;
     else
     {
       m = -1 - n;
       n = m / 10;
-      m =(m % 10) + 1;
+      m = (m % 10) + 1;
       k = 1;
 
       if (m < 10)
-        dig[0]= (char) m;
+        dig[0] = (char) m;
       else
       {
-        dig[0]= 0;
+        dig[0] = 0;
         incr(n);
       }
     }
   }
-  do {
-    dig[k] = (char) (n % 10);
-    n = n / 10;
-    incr(k);
-  } while (!(n == 0));
+
+  do
+    {
+      dig[k] = (char) (n % 10);
+      n = n / 10;
+      incr(k);
+    }
+  while (!(n == 0));
+
   print_the_digs(k);
 }
 /* sec 0262 */
@@ -400,33 +326,36 @@ void print_cs_ (integer p)
       }
       else
       {
-        print_esc("");print(p - 257);
-/*  if cat_code(p - single_base) = letter then ... p.262 */
-        if (eqtb[(hash_size + 1883) + p - 257].hh.v.RH == letter)
+        print_esc(""); print(p - single_base);
+
+        if (cat_code(p - single_base) == letter)
           print_char(' ');
       }
-    else if (p < 1)
+    else if (p < active_base)
       print_esc("IMPOSSIBLE.");
-    else print(p - 1);
-  else if (p >= (hash_size + 781)) /* undefined_control_sequence */
+    else
+      print(p - active_base);
+  else if (p >= undefined_control_sequence)
     print_esc("IMPOSSIBLE.");
-  else if ((hash[p].v.RH >= str_ptr))
+  else if ((text(p) >= str_ptr))
     print_esc("NONEXISTENT.");
   else
   {
-    print_esc(""); print(hash[p].v.RH);
+    print_esc("");
+    print(text(p));
     print_char(' ');
   }
 }
 /* sec 0263 */
 void sprint_cs_(halfword p)
 { 
-  if (p < hash_base)       /* if p < hash_base then ... p.263 */
-    if (p < single_base)       /* if p < single_base then ... p.263 */
-      print(p - active_base);     /* print (p - active_base); */
-    else if (p < null_cs)      /* else if p < null_cs then ... */
+  if (p < hash_base)
+    if (p < single_base)
+      print(p - active_base);
+    else if (p < null_cs)
     {
-      print_esc(""); print(p - single_base);
+      print_esc("");
+      print(p - single_base);
     }
     else
     {
@@ -435,22 +364,15 @@ void sprint_cs_(halfword p)
     }
   else
   {
-    print_esc(""); print(hash[p].v.RH);
+    print_esc(""); print(text(p));
   }
 }
 /* sec 0518 */
-/* ! I can't find file `  c:/foo/  accents  .tex  '. */
 void print_file_name_(integer n, integer a, integer e)
 {
-/*  sprintf(log_line, "\na %d n %d e %d\n", a, n, e); */
-/*  show_line(log_line, 0); */
-//  print_char('!');  // debugging only
   slow_print(a);
-//  print_char('!');  // debugging only
   slow_print(n);
-//  print_char('!');  // debugging only
   slow_print(e);
-//  print_char('!');  // debugging only
 }
 /* sec 0699 */
 void print_size_ (integer s)
@@ -463,30 +385,32 @@ void print_size_ (integer s)
     print_esc("scriptscriptfont");
 } 
 /* sec 1355 */
-void print_write_whatsit_(str_number s, halfword p)
+void print_write_whatsit_(const char * s, pointer p)
 {
-  print_esc(""); print(s);
-  if (mem[p + 1].hh.v.LH < 16)
-    print_int(mem[p + 1].hh.v.LH); 
-  else if (mem[p + 1].hh.v.LH == 16)
+  print_esc(s);
+
+  if (write_stream(p) < 16)
+    print_int(write_stream(p)); 
+  else if (write_stream(p) == 16)
     print_char('*');
   else print_char('-');
 }
 /* sec 0081 */
-// called from itex.c and tex0.c only  NASTY NASTY!
-// now uses uses non-local goto (longjmp) 1999/Nov/7
 void jump_out (void) 
 {
-  close_files_and_terminate(); 
+  close_files_and_terminate();
+
   {
     int code;
+
 #ifndef _WINDOWS
     fflush(stdout); 
 #endif
+
     ready_already = 0;
 
     if (trace_flag)
-      show_line("EXITING at JUMPOUT\n", 0);
+      puts("EXITING at JUMPOUT");
 
     if ((history != 0) && (history != 1))
       code = 1;
@@ -513,17 +437,18 @@ void error (void)
   if (interaction == error_stop_mode)
     while (true)
     {
-lab22:
+continu:
       clear_for_error_prompt();
-      { /* prompt_input */
-        print_string("? ");
-        term_input("? ", help_ptr);
-      }
+      prompt_input("? ");
+
       if (last == first)
         return; // no input
-      c = buffer[first];   // analyze first letter typed
-      if (c >= 'a')         // uppercase letter first
-        c = (unsigned char) (c + 'A' - 'a'); 
+
+      c = buffer[first];
+
+      if (c >= 'a')
+        c = (c + 'A' - 'a'); 
+
       switch (c)
       {
         case '0':
@@ -546,15 +471,16 @@ lab22:
             OK_to_interrupt = false;
 
             if ((last > first + 1) && (buffer[first + 1] >= '0') && (buffer[first + 1] <= '9'))
-              c = (unsigned char) (c * 10 + buffer[first + 1] - '0' * 11);
+              c = (c * 10 + buffer[first + 1] - '0' * 11);
             else
-              c = (unsigned char) (c - 48);
+              c = (c - 48);
             
             while (c > 0)
             {
               get_token();
               decr(c);
             }
+
             cur_tok = s1;
             cur_cmd = s2;
             cur_chr = s3;
@@ -563,17 +489,19 @@ lab22:
             help2("I have just deleted some text, as you asked.",
                 "You can now delete more, or insert, or whatever.");
             show_context();
-            goto lab22;     /* loop again */
+            goto continu;
           }
           break;
+
 #ifdef DEBUG
         case 'D':
           {
             debug_help();
-            goto lab22;       /* loop again */
+            goto continu;
           }
           break;
-#endif /* DEBUG */
+#endif
+
         case 'E':
           if (base_ptr > 0)
           {
@@ -583,6 +511,7 @@ lab22:
             jump_out();
           }
           break;
+
         case 'H':
           {
             if (use_err_help)
@@ -595,94 +524,104 @@ lab22:
               if (help_ptr == 0)
                 help2("Sorry, I don't know how to help in this situation.",
                     "Maybe you should try asking a human?");
-              do {
-                decr(help_ptr);
-                print_string(help_line[help_ptr]);
-                print_ln();
-              } while (!(help_ptr == 0));
+              do
+                {
+                  decr(help_ptr);
+                  prints(help_line[help_ptr]);
+                  print_ln();
+                }
+              while (!(help_ptr == 0));
             }
 
             help4("Sorry, I already gave what help I could...",
                 "Maybe you should try asking a human?",
                 "An error might have occurred before I noticed any problems.",
                 "``If all else fails, read the instructions.''");
-            goto lab22; /* loop again */
+            goto continu;
           }
           break;
+
         case 'I':
           {
             begin_file_reading();
 
             if (last > first + 1)
             {
-              cur_input.loc_field = first + 1;
-              buffer[first]= 32;
+              loc = first + 1;
+              buffer[first] = 32;
             }
             else
             {
-              { /* prompt_input */
-                print_string("insert>");
-                term_input("insert>", 0);
-              }
-              cur_input.loc_field = first;
+              prompt_input("insert>");
+              loc = first;
             }
+
             first = last;
-            cur_input.limit_field = last - 1;
+            limit = last - 1;
+
             return;
           }
           break;
+
         case 'Q':
         case 'R':
         case 'S':
           {
             error_count = 0; 
             interaction = 0 + c - 81; /* Q = 0, R = 1, S = 2, T = 3 */
-            print_string("OK, entering ");
+            prints("OK, entering ");
+
             switch (c)
             {
               case 'Q':
                 print_esc("batchmode");
                 decr(selector);
                 break;
+
               case 'R':
                 print_esc("nonstopmode");
                 break;
+
               case 'S':
                 print_esc("scrollmode");
                 break;
             }
-            print_string("...");
+
+            prints("...");
             print_ln();
-#ifndef _WINDOWS
-            fflush(stdout);
-#endif
+            update_terminal();
             return;
           }
           break;
+
         case 'X':
           {
             interaction = 2;
             jump_out();
           }
           break;
+
         default:
           break;
       }           /* end of switch analysing response character */
+
       {
-        print_string("Type <return> to proceed, S to scroll future error messages,");
+        prints("Type <return> to proceed, S to scroll future error messages,");
         print_nl("R to run without stopping, Q to run quietly,");
         print_nl("I to insert something, ");
 
         if (base_ptr > 0)
-          print_string("E to edit your file,");
+          prints("E to edit your file,");
+
         if (deletions_allowed)
           print_nl("1 or ... or 9 to ignore the next 1 to 9 tokens of input,");
 
         print_nl("H for help, X to quit.");
       }
-    } /* end of while(true) loop */
+    }
 
   incr(error_count);
+
   if (error_count == 100)
   {
     print_nl("(That makes 100 errors; please try again.)");
@@ -698,10 +637,10 @@ lab22:
     print_ln();
     give_err_help();
   }
-  else while(help_ptr > 0)
+  else while (help_ptr > 0)
   {
     decr(help_ptr);
-    print_nl(help_line[help_ptr]);
+    print_nl(help_line[help_ptr] == NULL ? "" : help_line[help_ptr]);
   }
 
   print_ln();
@@ -712,7 +651,7 @@ lab22:
   print_ln();
 }
 /* sec 0093 */
-void fatal_error_(char * s)
+void fatal_error(char * s)
 {
   normalize_selector();
   print_err("Emergency stop");
@@ -723,8 +662,8 @@ void fatal_error_(char * s)
 void overflow_(char * s, integer n)
 {
   normalize_selector();
-  print_err("TeX capacity exceeded, sorry[");
-  print_string(s);
+  print_err("TeX capacity exceeded, sorry [");
+  prints(s);
   print_char('=');
   print_int(n);
   print_char(']');
@@ -733,27 +672,29 @@ void overflow_(char * s, integer n)
 
   if (!knuth_flag)
   {
-    if (!strcmp(s, "pattern memory") && n == trie_size)
+    if (!strcmp(s, "pattern memory") && (n == trie_size))
     {
       sprintf(log_line, "\n  (Maybe use -h=... on command line in ini-TeX)\n");
       show_line(log_line, 0);
-    } else if (!strcmp(s, "exception dictionary") && n == hyphen_prime)
+    }
+    else if (!strcmp(s, "exception dictionary") && (n == hyphen_prime))
     {
       sprintf(log_line, "\n  (Maybe use -e=... on command line in ini-TeX)\n");
       show_line(log_line, 0);
     }
   }
+
   succumb();
 }
 /* sec 0095 */
-void confusion_(char * s)
+void confusion_(const char * s)
 {
   normalize_selector();
 
   if (history < error_message_issued)
   {
     print_err("This can't happen (");
-    print_string(s);
+    prints(s);
     print_char(')');
     help1("I'm broken. Please show this to someone who can fix can fix");
   }
@@ -763,65 +704,56 @@ void confusion_(char * s)
     help2("One of your faux pas seems to have wounded me deeply...",
         "in fact, I'm barely conscious. Please fix it and try again.");
   }
+
   succumb();
 }
 /* sec 0037 */
-bool init_terminal (void)
+boolean init_terminal (void)
 {
-  register bool Result;
   int flag;
+
   t_open_in();
 
   if (last > first)
   {
-    cur_input.loc_field = first;
-    while((cur_input.loc_field < last) && (buffer[cur_input.loc_field]== ' '))
-      incr(cur_input.loc_field);    // step over initial white space
-    if (cur_input.loc_field < last)
-    {
-      Result = true;
-      return Result;    // there is an input file name
-    }
+    loc = first;
+
+    while ((loc < last) && (buffer[loc]== ' '))
+      incr(loc);    // step over initial white space
+
+    if (loc < last)
+      return true;
   }
 
 // failed to find input file name
-  while (true) {
-#ifdef _WINDOWS
-    flag = ConsoleInput("**", "Please type a file name or a control sequence\r\n(or ^z to exit)", (char *) &buffer[first]);
-    last = first + strlen((char *) &buffer[first]); /* -1 ? */
-//    may need to be more elaborate see input_line in texmf.c
-#else
-    (void) fputs("**", stdout);
-    fflush(stdout);
+  while (true)
+  {
+    fputs("**", stdout);
+    update_terminal();
     flag = input_ln(stdin, true);
-#endif
+
     if (!flag)
     {
       show_char('\n');
-      show_line("! End of file on the terminal... why?\n", 1);
-      Result = false;
-      return Result;
+      puts("! End of file on the terminal... why?\n");
+      return false;
     }
 
-    cur_input.loc_field = first;
-    while ((cur_input.loc_field < last) && (buffer[cur_input.loc_field]== ' '))
-      incr(cur_input.loc_field);    // step over intial white space
-    if (cur_input.loc_field < last)
-    {
-      Result = true;
-      return Result;    // there is an input file name
-    }
+    loc = first;
+
+    while ((loc < last) && (buffer[loc]== ' '))
+      incr(loc);    // step over intial white space
+
+    if (loc < last)
+      return true;
 
     sprintf(log_line, "%s\n", "Please type the name of your input file.");
     show_line(log_line, 1);
   }
 }
 /* sec 0043 */
-// Make string from str_start[str_ptr] to pool_ptr
 str_number make_string (void)
 {
-  register str_number Result; 
-
 #ifdef ALLOCATESTRING
   if (str_ptr == current_max_strings)
     str_start = realloc_str_start(increment_max_strings);
@@ -829,64 +761,73 @@ str_number make_string (void)
   if (str_ptr == current_max_strings)
   {
     overflow("number of strings", current_max_strings - init_str_ptr); /* 97/Mar/9 */
-    return 0;     // abort_flag set
+    return 0;
   }
 #else
   if (str_ptr == max_strings)
   {
     overflow("number of strings", max_strings - init_str_ptr);
-    return 0;     // abort_flag set
+    return 0;
   }
 #endif
+
   incr(str_ptr);
   str_start[str_ptr] = pool_ptr;
-  Result = str_ptr - 1;
-  return Result;
+
+  return (str_ptr - 1);
 }
 /* sec 0044 */
-bool str_eq_buf_ (str_number s, integer k)
+boolean str_eq_buf_ (str_number s, integer k)
 {
-  register bool Result;
   pool_pointer j;
-  bool result;
+  boolean result;
+
   j = str_start[s];
+
   while (j < str_start[s + 1])
   {
-    if (str_pool[j]!= buffer[k])
+    if (str_pool[j] != buffer[k])
     {
       result = false;
-      goto lab45;
+      goto not_found;
     }
+
     incr(j);
     incr(k);
   }
+
   result = true;
-lab45:
-  Result = result;
-  return Result;
+
+not_found:
+  return result;
 }
 /* sec 0045 */
-bool str_eq_str_ (str_number s, str_number t)
+boolean str_eq_str_ (str_number s, str_number t)
 {
-  register bool Result;
   pool_pointer j, k;
-  bool result;
+  boolean result;
+
   result = false;
+
   if (length(s) != length(t))
-    goto lab45;
+    goto not_found;
+
   j = str_start[s];
   k = str_start[t];
+
   while (j < str_start[s + 1])
   {
     if (str_pool[j] != str_pool[k])
-      goto lab45;
+      goto not_found;
+
     incr(j);
     incr(k);
   }
+
   result = true;
-lab45:
-  Result = result;
-  return Result;
+
+not_found:
+  return result;
 }
 /* sec 0066 */
 void print_two_(integer n)
@@ -899,13 +840,18 @@ void print_two_(integer n)
 void print_hex_(integer n)
 {
   char k;
+
   k = 0;
   print_char('"');
-  do {
-    dig[k] = (unsigned char) (n % 16);
-    n = n / 16;
-    incr(k);
-  } while (!(n == 0));
+
+  do
+    {
+      dig[k] = (unsigned char) (n % 16);
+      n = n / 16;
+      incr(k);
+    }
+  while (!(n == 0));
+
   print_the_digs(k);
 }
 /* sec 0069 */
@@ -913,22 +859,30 @@ void print_roman_int_(integer n)
 {
   pool_pointer j, k;
   nonnegative_integer u, v;
+
   j = str_start[260]; /*  m2d5c2l5x2v5i */
   v = 1000;
-  while (true) {
-    while (n >= v) {
+
+  while (true)
+  {
+    while (n >= v)
+    {
       print_char(str_pool[j]);
       n = n - v;
     }
+
     if (n <= 0)
       return;
+
     k = j + 2;
     u = v / (str_pool[k - 1] - '0');
+
     if (str_pool[k - 1] == 50)
     {
       k = k + 2;
       u = u / (str_pool[k - 1] - '0');
     }
+
     if (n + u >= v)
     {
       print_char(str_pool[k]);
@@ -937,7 +891,7 @@ void print_roman_int_(integer n)
     else
     {
       j = j + 2;
-      v = v / (str_pool[j - 1]- '0');
+      v = v / (str_pool[j - 1] - '0');
     }
   }
 }
@@ -945,7 +899,9 @@ void print_roman_int_(integer n)
 void print_current_string (void)
 {
   pool_pointer j;
+
   j = str_start[str_ptr];
+
   while (j < pool_ptr)
   {
     print_char(str_pool[j]);
@@ -953,164 +909,38 @@ void print_current_string (void)
   }
 }
 
-int stringlength (int str_ptr)
-{
-  int nstart, nnext;
-  nstart = str_start[str_ptr];
-  nnext = str_start[str_ptr + 1];
-  return (nnext - nstart) + 2;
-}
-
-char * add_string (char *s, char * str_string)
-{
-  int n;
-  n = strlen(str_string);
-  memcpy(s, &str_string, n);
-  s += n;
-  strcpy(s, "\r\n");
-  s += 2;
-  return s;
-}
-
-int addextrahelp=1;
-
-// make one long \r\n separated string out of help lines 
-// str_pool is packed_ASCII_code *
-
-char * make_up_help_string (int nhelplines)
-{
-  char * helpstring, *s;
-  int k, nlen = 0;
-  
-//  get length of help for this specific message
-  for (k = nhelplines - 1; k >= 0; k--) {
-    //nlen += stringlength(help_line[k]);
-    nlen += strlen(help_line[k]);
-  }
-  nlen += 2; // for blank line separator: "\r\n"
-  if (addextrahelp) {
-    nlen += stringlength(265);
-    nlen += stringlength(266);
-    nlen += stringlength(267);
-    if (base_ptr > 0)
-      nlen += stringlength(268);
-    if (deletions_allowed)
-      nlen += stringlength(269);
-    nlen += stringlength(270);
-  }
-  helpstring = (char *) malloc(nlen + 1); // +1 = '\0'
-  s = helpstring;
-  for (k = nhelplines-1; k >= 0; k--) {
-    s = add_string(s, help_line[k]);
-  }
-  if (addextrahelp) {
-    strcpy(s, "\r\n");
-    s += 2;
-    s = add_string(s, "Type <return> to proceed, S to scroll future error messages,");
-    s = add_string(s, "R to run without stopping, Q to run quietly,");
-    s = add_string(s, "I to insert something, ");
-    if (base_ptr > 0)
-      s = add_string(s, "E to edit your file, ");
-    if (deletions_allowed)
-      s = add_string(s, "1 or ... or 9 to ignore the next 1 to 9 tokens of input,");
-    s = add_string(s, "H for help, X to quit.");
-  }
-  return helpstring;
-}
-
-char * make_up_query_string (int promptstr)
-{
-  char *querystr;
-  int nstart, nnext, n;
-  char *s;
-  nstart = str_start[ promptstr];
-  nnext = str_start[ promptstr + 1];
-  n = nnext - nstart;
-  querystr = (char *) malloc(n + 1);
-  s = querystr;
-  memcpy(s, &str_pool[nstart], n);  
-  s += n;
-  *s = '\0';
-  return querystr;
-}
-
-// abort_flag set if input_line / ConsoleInput returns non-zero
-// should set interrupt instead ???
-// called from tex0.c, tex2.c, tex3.c
 /* sec 0071 */
-// void term_input(void)
-void term_input (char * term_str, int term_help_lines)
+void term_input(void)
 { 
   integer k;
   int flag;
-  char * helpstring = NULL;
-  char * querystring = NULL;
-//  if (nhelplines != 0) {
-//    helpstring = make_up_help_string (nhelplines);
-//    printf(helpstring);
-//    free(helpstring);
-//  }
-  show_line("\n", 0);    // force it to show what may be buffered up ???
-  helpstring = NULL;  
-#ifdef _WINDOWS
-  if (term_str != NULL) querystring = term_str;
-  if (term_help_lines != NULL) helpstring = make_up_help_string(term_help_lines);
-  if (helpstring == NULL && querystring != NULL)
-  {
-    if (strcmp(querystring, ": ") == 0)
-      helpstring = xstrdup("Please type another file name (or ^z to exit):");
-    else if (strcmp(querystring, "=>") == 0)    // from firm_up_the_line
-      helpstring = xstrdup("Please type <enter> to accept this line\r\nor type a replacement line");
-    else if (strcmp(querystring, "insert>") == 0) // from error() after "I"
-      helpstring = xstrdup("Please type something to insert here");
-    else if (strcmp(querystring, "") == 0)      // from read_toks
-      helpstring = xstrdup("Please type a control sequence");
-    else if (strcmp(querystring, "= ") == 0)    // from read_toks
-      helpstring = xstrdup("Please type a token");
-    else if (strcmp(querystring, "*") == 0)   // get_next
-      helpstring = xstrdup("Please type a control sequence\r\n(or ^z to exit)");
-  }
-  flag = ConsoleInput(querystring, helpstring, (char *) &buffer[first]);  // ???
-//  flag == 0 means trouble --- EOF on terminal
-  if (querystring != NULL) free(querystring);
-  if (helpstring != NULL) free(helpstring);
-  helpstring = querystring = NULL;
-
-  last = first + strlen((char *) &buffer[first]); /* -1 ? */
-//  flag = (last > first);
-//  may need to be more elaborate see input_line in texmf.c ???
-//  sprintf(log_line, "first %d last %d flag %d - %s",
-//      first, last, flag, (char *) &buffer[first]);
-//  winerror(log_line);
-#else
-  fflush(stdout);
+  
+  if (!knuth_flag)
+    show_line("\n", 0);
+
+  update_terminal();
   flag = input_ln(stdin, true);
-#endif
+
   if (!flag)
   {
     fatal_error("End of file on the terminal!");
-    return;         // abort_flag set
+    return;
   }
+
   term_offset = 0;
-#ifdef _WINDOWS
-// echo what was typed into Console buffer also
-  if (last != first)
-    for (k = first; k <= last - 1; k++)
-      print(buffer[k]);
-  print_ln();
-#else
   decr(selector);     // shut off echo
+
   if (last != first)
     for (k = first; k <= last - 1; k++)
       print(buffer[k]);
+
   print_ln();
   incr(selector);     // reset selector again
-#endif
 }
 /* sec 0091 */
 void int_error_ (integer n)
 {
-  print_string(" (");
+  prints(" (");
   print_int(n);
   print_char(')');
   error();
@@ -1135,8 +965,10 @@ void pause_for_instructions (void)
    if (OK_to_interrupt)
    {
     interaction = error_stop_mode;
+
     if ((selector == log_only) || (selector == no_print))
       incr(selector);
+
     print_err("Interruption");
     help3("You rang?",
         "Try to insert some instructions for me (e.g.,`I\\showlists'),",
@@ -1150,31 +982,31 @@ void pause_for_instructions (void)
 /* sec 0100 */
 integer half_(integer x)
 {
-  register integer Result;
   if (odd(x))
-    Result =(x + 1) / 2;
+    return ((x + 1) / 2);
   else
-    Result = x / 2;
-  return Result;
+    return (x / 2);
 }
 /* sec 0102 */
 scaled round_decimals_(small_number k)
 {
-  register scaled Result;
   integer a;
+
   a = 0;
-  while (k > 0) {
+
+  while (k > 0)
+  {
     decr(k);
     a = (a + dig[k] * 131072L) / 10; /* 2^17 */
   }
-  Result =(a + 1) / 2;
-  return Result;
+  
+  return ((a + 1) / 2);
 }
 /* sec 0103 */
-/* This has some minor speedup changes - no real advantage probably ... */
 void print_scaled_(scaled s)
-{ 
+{
   scaled delta;
+
   if (s < 0)
   {
     print_char('-');
@@ -1185,18 +1017,21 @@ void print_scaled_(scaled s)
   print_char('.');
   s = 10 * (s % 65536L) + 5;
   delta = 10;
-  do {
-    if (delta > 65536L)
-      s = s - 17232; /* 2^15 - 50000 - rounding */
-    print_char('0' + (s / 65536L));
-    s = 10 * (s % 65536L);
-    delta = delta * 10;
-  } while (!(s <= delta));
+
+  do
+    {
+      if (delta > 65536L)
+        s = s - 17232; /* 2^15 - 50000 - rounding */
+
+      print_char('0' + (s / 65536L));
+      s = 10 * (s % 65536L);
+      delta = delta * 10;
+    }
+  while (!(s <= delta));
 }
 /* sec 0105 */
 scaled mult_and_add_(integer n, scaled x, scaled y, scaled maxanswer)
 {
-  register scaled Result;
   if (n < 0)
   {
     x = - (integer) x;
@@ -1204,22 +1039,23 @@ scaled mult_and_add_(integer n, scaled x, scaled y, scaled maxanswer)
   }
 
   if (n == 0)
-    Result = y;
+    return y;
   else if (((x <= (maxanswer - y) / n) && (- (integer) x <= (maxanswer + y) / n)))
-    Result = n * x + y; 
-  else {
+    return (n * x + y); 
+  else
+  {
     arith_error = true;
-    Result = 0;
+    return 0;
   }
-
-  return Result;
 }
 /* sec 0106 */
 scaled x_over_n_(scaled x, integer n)
 {
   register scaled Result;
-  bool negative;
+  boolean negative;
+
   negative = false;
+
   if (n == 0)
   {
     arith_error = true;
@@ -1256,24 +1092,25 @@ scaled x_over_n_(scaled x, integer n)
 scaled xn_over_d_(scaled x, integer n, integer d)
 {
   register scaled Result;
-  bool positive;
+  boolean positive;
   nonnegative_integer t, u, v;
+
   if (x >= 0)
     positive = true; 
-  else {
+  else
+  {
     x = - (integer) x;
     positive = false;
   }
-/*  t =(x % 32768L)* n;  */
-  t =(x & 32767L) * n;
-/*  u =(x / 32768L)* n +(t / 32768L);  */
-  u =(x >> 15) * n + (t >> 15); 
-/*  v =(u % d)* 32768L +(t % 32768L);  */
-  v =((u % d) << 15) + (t & 32767L); 
+
+  t = (x % 32767L) * n;
+  u = (x / 32768L) * n + (t / 32768L);
+  v = (u % d) * 32768L + (t % 32768L); 
+
   if (u / d >= 32768L)
     arith_error = true; 
-/*  else u = 32768L *(u / d)+(v / d);  */ 
-  else u =((u / d) << 15) + (v / d);
+  else
+    u = 32768L * (u / d) + (v / d);
 
   if (positive)
   {
@@ -1291,29 +1128,28 @@ scaled xn_over_d_(scaled x, integer n, integer d)
 /* sec 0108 */
 halfword badness_(scaled t, scaled s)
 {
-  register halfword Result;
   integer r;
+
   if (t == 0)
-    Result = 0;
+    return 0;
   else if (s <= 0)
-    Result = 10000;
-  else {
+    return 10000;
+  else
+  {
     if (t <= 7230584L)
       r = (t * 297) / s;
     else if (s >= 1663497L)
       r = t / (s / 297);
     else
       r = t;
+
     if (r > 1290)
-      Result = 10000; 
-/*    safe to assume that r is positive ? */
-/*    else Result =(r * r * r + 131072L)/ 262144L;  */
+      return 10000; 
     else
-      Result = (r * r * r + 131072L) >> 18;  /* 2^17 */
+      return (r * r * r + 131072L) / 262144L;  /* 2^17 */
   }
-  return Result;
 }
-
+/* sec 0114 */
 #ifdef DEBUG
 void print_word_(memory_word w)
 { 
@@ -1323,13 +1159,13 @@ void print_word_(memory_word w)
   print_char(' ');
   print_scaled(round(65536L * w.gr));
   print_ln();
-  print_int(w.hh.v.LH);
+  print_int(w.hh.lh);
   print_char('=');
   print_int(w.hh.b0);
   print_char(':');
   print_int(w.hh.b1);
   print_char(';');
-  print_int(w.hh.v.RH);
+  print_int(w.hh.rh);
   print_char(' ');
   print_int(w.qqqq.b0); 
   print_char(':');
@@ -1340,7 +1176,7 @@ void print_word_(memory_word w)
   print_int(w.qqqq.b3);
 } 
 /* need this version only if SHORTFONTINFO defined */
-void zprintfword(fmemoryword w)
+void zprintfword(memory_word w)
 {
   print_int(w.cint);
   print_char(' ');
@@ -1348,13 +1184,13 @@ void zprintfword(fmemoryword w)
   print_char(' ');
   print_scaled(round(65536L * w.gr));
   print_ln();
-  print_int(w.hh.v.LH);
+  print_int(w.hh.lh);
   print_char('=');
   print_int(w.hh.b0);
   print_char(':');
   print_int(w .hh.b1);
   print_char(';');
-  print_int(w.hh.v.RH);
+  print_int(w.hh.rh);
   print_char(' ');
   print_int(w.qqqq.b0);
   print_char(':');
@@ -1371,11 +1207,13 @@ void show_token_list_(integer p, integer q, integer l)
   integer m, c;
   ASCII_code match_chr;
   ASCII_code n;
-  match_chr = 35;
-  n = 48;
+
+  match_chr = '#';
+  n = '0';
   tally = 0;
-/* while (p<>null) and (tally<l) do l.6239 */
-  while ((p != 0) && (tally < l)) {
+
+  while ((p != 0) && (tally < l))
+  {
     if (p == q)
     {
       first_count = tally;
@@ -1391,56 +1229,64 @@ void show_token_list_(integer p, integer q, integer l)
       return;
     }
 
-    if (info(p) >= 4095)
-      print_cs(info(p) - 4095);
-    else {
+    if (info(p) >= cs_token_flag)
+      print_cs(info(p) - cs_token_flag);
+    else
+    {
       m = info(p) / 256;
       c = info(p) % 256;
+
       if (info(p) < 0)
         print_esc("BAD.");
-      else
-        switch (m)
-        {
-          case left_brace:
-          case right_brace:
-          case math_shift:
-          case tab_mark:
-          case sup_mark:
-          case sub_mark:
-          case spacer:
-          case letter:
-          case other_char:
-            print(c);
-            break;
-          case mac_param:
-            print(c);
-            print(c);
-            break;
-          case out_param:
-            print(match_chr);
-            if (c <= 9)
-              print_char(c + '0');
-            else
-            {
-              print_char('!');
-              return;
-            }
-            break;
-          case match:
-            match_chr = (ASCII_code) c;
-            print(c);
-            incr(n);
-            print_char(n);
-            if (n > '9')
-              return;
-            break;
-          case end_match:
-            print_string("->");
-            break;
-          default:
-            print_esc("BAD.");
-            break;
-        }
+      else switch (m)
+      {
+        case left_brace:
+        case right_brace:
+        case math_shift:
+        case tab_mark:
+        case sup_mark:
+        case sub_mark:
+        case spacer:
+        case letter:
+        case other_char:
+          print(c);
+          break;
+        
+        case mac_param:
+          print(c);
+          print(c);
+          break;
+        
+        case out_param:
+          print(match_chr);
+          
+          if (c <= 9)
+            print_char(c + '0');
+          else
+          {
+            print_char('!');
+            return;
+          }
+          break;
+        
+        case match:
+          match_chr = (ASCII_code) c;
+          print(c);
+          incr(n);
+          print_char(n);
+          
+          if (n > '9')
+            return;
+          break;
+        
+        case end_match:
+          prints("->");
+          break;
+        
+        default:
+          print_esc("BAD.");
+          break;
+      }
     }
     p = link(p);
   }
@@ -1452,28 +1298,34 @@ void show_token_list_(integer p, integer q, integer l)
 void runaway (void)
 {
   halfword p;
+
   if (scanner_status > 1)
   {
     print_nl("Runaway ");
+
     switch (scanner_status)
     {
       case defining:
-        print_string("definition");
+        prints("definition");
         p = def_ref;
         break;
+
       case matching:
-        print_string("argument");
+        prints("argument");
         p = temp_head;
         break;
+
       case aligning:
-        print_string("preamble");
+        prints("preamble");
         p = hold_head;
         break;
+
       case absorbing:
-        print_string("text");
+        prints("text");
         p = def_ref;
         break;
     }
+
     print_char('?');
     print_ln();
     show_token_list(link(p), 0, error_line - 10); 
@@ -1489,12 +1341,13 @@ void runaway (void)
 /* *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** */
 halfword get_avail (void)
 {
-  register halfword Result;
-  halfword p;
+  pointer p;
+
   p = avail;
-  if (p != 0) /* while p<>null do */
+
+  if (p != 0)
     avail = link(avail);
-  else if (mem_end < mem_max) /* mem_end + 1 < mem_max ? NO */
+  else if (mem_end < mem_max)
   {
     incr(mem_end);
     p = mem_end;
@@ -1503,192 +1356,206 @@ halfword get_avail (void)
   {
     decr(hi_mem_min);
     p = hi_mem_min;
-/* *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** */
+
     if (hi_mem_min <= lo_mem_max) /* have we run out in middle ? */
     {
-      incr(hi_mem_min);       /* undo the change */
-/*    realloc_main (0, mem_top/2); */ /* extend main memory at hi end */
+      incr(hi_mem_min);
       mem = realloc_main (0, mem_top / 2);  /* zzzaa = zmem = mem */
+
       if (mem == NULL)
         return 0;
-/* presumably now mem_end < mem_max - but need test in case allocation fails */
+
       if (mem_end >= mem_max)
       {
         runaway();
-        overflow("main memory size", mem_max + 1 - mem_min); /* main memory size */
-        return 0;           // abort_flag set
+        overflow("main memory size", mem_max + 1 - mem_min);
+        return 0;
       }
+
       incr(mem_end);        /* then grab from new area */
       p = mem_end;          /* 1993/Dec/14 */
     }
-/* *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** */
   }
+
   link(p) = 0;       /* link(p) = null !!! */
-  ;
+
 #ifdef STAT
   incr(dyn_used); 
 #endif /* STAT */
-  Result = p; 
-  return Result
+
+  return p
 } 
 /* sec 0123 */
-void flush_list_(halfword p)          /* paragraph 123 */
+void flush_list_(pointer p)
 { 
-  halfword q, r; 
+  pointer q, r;
+
   if (p != 0)              /* null !!! */
   {
     r = p;
-    do {
-      q = r;
-      r = link(r);
-      ;
+
+    do
+      {
+        q = r;
+        r = link(r);
 #ifdef STAT
-      decr(dyn_used);
+        decr(dyn_used);
 #endif /* STAT */
-    } while (!(r == 0));     /* r != null */
+      }
+    while (!(r == 0));     /* r != null */
+
     link(q) = avail;
     avail = p;
   }
 }
 /* sec 0125 */
-halfword get_node_(integer s)
+pointer get_node_(integer s)
 {
-  register halfword Result;
-  halfword p;
-  halfword q;
+  pointer p;
+  pointer q;
   integer r;
   integer t;
-lab20:
+restart:
+
   p = rover;
-  do {
-      q = p + mem[p].hh.v.LH;
-/* *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** */
-      while ((mem[q].hh.v.RH == empty_flag)) {
-/* *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** */
-        if (q == 0) {
-/* should never happen, since this field is reference count for zeroglue */
-        }  /* debugging code 93/DEC/15 */ /* eventually remove */
-/* *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** */
-        t = mem[q + 1].hh.v.RH;
+
+  do
+    {
+      q = p + node_size(p);
+
+      while (is_empty(q))
+      {
+        t = rlink(q);
+
         if (q == rover)
           rover = t;
-        mem[t + 1].hh.v.LH = mem[q + 1].hh.v.LH;
-        mem[mem[q + 1].hh.v.LH + 1].hh.v.RH = t;
-        q = q + mem[q].hh.v.LH;
+
+        llink(t) = llink(q);
+        rlink(llink(q)) = t;
+        q = q + node_size(q);
       }
+
       r = q - s;
+
       if (r > toint(p + 1)) 
       {
-        mem[p].hh.v.LH = r - p;
+        node_size(p) = r - p;
         rover = p;
-        goto lab40;
+        goto found;
       }
+
       if (r == p)
-        if (mem[p + 1].hh.v.RH != p)
+        if (rlink(p) != p)
         {
-          rover = mem[p + 1].hh.v.RH;
-          t = mem[p + 1].hh.v.LH;
-          mem[rover + 1].hh.v.LH = t;
-          mem[t + 1].hh.v.RH = rover;
-          goto lab40;
+          rover = rlink(p);
+          t = llink(p);
+          llink(rover) = t;
+          rlink(t) = rover;
+          goto found;
         }
-      mem[p].hh.v.LH = q - p;
-      p = mem[p + 1].hh.v.RH;
-  } while (!(p == rover));
+
+      node_size(p) = q - p;
+      p = rlink(p);
+    }
+  while (!(p == rover));
+
   if (s == 1073741824L)    /* 2^30 - special case - merge adjacent */
   {
-    Result = empty_flag;
-/* *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** */
     if (trace_flag)
-      show_line("Merged adjacent multi-word nodes\n", 0);
-/* *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** */
-    return Result;
+      puts("Merged adjacent multi-word nodes\n");
+
+    return max_halfword;
   }
+
 /*  maybe try downward epxansion first instead ? */
   if (lo_mem_max + 2 < hi_mem_min)
-/*  if (lo_mem_max + 2 <= 262143L) */  /* NO! */
     if (lo_mem_max + 2 <= mem_bot + max_halfword)  /* silly ? flush 93/Dec/16 */
     {
-/*    if (hi_mem_min - lo_mem_max >= 1998) */
+      /* if (hi_mem_min - lo_mem_max >= 1998) */
       if (hi_mem_min - lo_mem_max >= (block_size + block_size - 2))
-/*    t = lo_mem_max + 1000;  */
+        /* t = lo_mem_max + 1000; */
         t = lo_mem_max + block_size;
       else
-        t = lo_mem_max + 1 +(hi_mem_min - lo_mem_max) / 2;
-      p = mem[rover + 1].hh.v.LH;
+        t = lo_mem_max + 1 + (hi_mem_min - lo_mem_max) / 2;
+
+      p = llink(rover);
       q = lo_mem_max;
-      mem[p + 1].hh.v.RH = q;
-      mem[rover + 1].hh.v.LH = q;
-/*    if (t > 262143L)   t = 262143L;  */ /* NO! */
+      rlink(p) = q;
+      llink(rover) = q;
+
       if (t > mem_bot + max_halfword)
         t = mem_bot + max_halfword;     /* silly ? flush 93/Dec/16 */
-      mem[q + 1].hh.v.RH = rover;
-      mem[q + 1].hh.v.LH = p;
-      mem[q].hh.v.RH = empty_flag;
-      mem[q].hh.v.LH = t - lo_mem_max; /* block size */
+
+      rlink(q) = rover;
+      llink(q) = p;
+      link(q) = empty_flag;
+      node_size(q) = t - lo_mem_max; /* block size */
       lo_mem_max = t;
-      mem[lo_mem_max].hh.v.RH = 0;
-      mem[lo_mem_max].hh.v.LH = 0;
+      link(lo_mem_max) = 0;
+      info(lo_mem_max) = 0;
       rover = q;
-      goto lab20;
+      goto restart;
     }
-/*  overflow("main memory size", mem_max + 1 - mem_min);  */ /* what used to happen! */
+
 /* *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** */
 /* we've run out of space in the middle for variable length blocks */
 /* try and add new block from below mem_bot *//* first check if space ! */
-  if (mem_min - (block_size + 1) <= mem_start) {/* extend lower memory downwards */
-/*    realloc_main (mem_top/2, 0); */
+  if (mem_min - (block_size + 1) <= mem_start) /* extend lower memory downwards */
+  {
     mem = realloc_main (mem_top/2 + block_size, 0);  /* zzzaa = zmem = mem */
-    if (mem == NULL) {
+
+    if (mem == NULL)
+    {
       return 0;
     }
   }
-/*  if (trace_flag) show_line("Extending downwards by %d\n", block_size, 0); */
-  if (mem_min - (block_size + 1) <= mem_start) { /* check again */
-    if (trace_flag) {
-      sprintf(log_line, "mem_min %d, mem_start %d, block_size %d\n", mem_min, mem_start, block_size);
+
+  if (mem_min - (block_size + 1) <= mem_start) /* check again */
+  {
+    if (trace_flag)
+    {
+      sprintf(log_line, "mem_min %lld, mem_start %ld, block_size %d\n", mem_min, mem_start, block_size);
       show_line(log_line, 0);
     }
+
     overflow("main memory size", mem_max + 1 - mem_min); /* darn: allocation failed ! */
-    return 0;     // abort_flag set
+    return 0;
   }
-/* avoid function call in following ? */
-  add_variable_space (block_size); /* now to be found in itex.c */
-  goto lab20;         /* go try get_node again */
-/* *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** */
 
-  lab40: mem[r].hh.v.RH = 0; 
-  ;
+  add_variable_space (block_size);
+  goto restart; /* go try get_node again */
+
+found:
+  link(r) = 0;
+
 #ifdef STAT
   var_used = var_used + s; 
 #endif /* STAT */
 
-/*  if (trace_flag) {
-    if (r == 0) show_line("r IS ZERO in ZGETNODE!\n", 0);
-  } */      /* debugging code 93/dec/15 */
-
-  Result = r; 
-  return Result; 
+  return r; 
 } 
-/* sec  */
+/* sec 0130 */
 void free_node_(halfword p, halfword s)
 { 
-  halfword q;
-  mem[p].hh.v.LH = s;
+  pointer q;
+
+  node_size(p) = s;
   link(p) = empty_flag;
   q = llink(rover);
   llink(p) = q;
   rlink(p) = rover;
   llink(rover) = p;
   rlink(q) = p;
+
 #ifdef STAT
   var_used = var_used - s; 
 #endif /* STAT */
 }
 /* sec 0136 */
-halfword new_null_box (void) 
+pointer new_null_box (void) 
 {
-  halfword p;
+  pointer p;
+
   p = get_node(box_node_size);
   type(p) = hlist_node;
   subtype(p) = min_quarterword;
@@ -1700,79 +1567,93 @@ halfword new_null_box (void)
   glue_sign(p) = normal;
   glue_order(p) = normal;
   glue_set(p) = 0.0;
+
   return p;
 }
 /* sec 0139 */
-halfword new_rule (void) 
+pointer new_rule (void) 
 {
-  halfword p;
+  pointer p;
+
   p = get_node(rule_node_size);
   type(p) = rule_node;
   subtype(p) = 0;
   width(p) = null_flag;
   depth(p) = null_flag;
   height(p) = null_flag;
+
   return p;
 }
 /* sec 0144 */
-halfword new_ligature_(quarterword f, quarterword c, halfword q)
+pointer new_ligature_(quarterword f, quarterword c, pointer q)
 {
-  halfword p; 
+  pointer p;
+
   p = get_node(small_node_size);
   type(p) = ligature_node;
   font(lig_char(p)) = f;
   character(lig_char(p)) = c;
   lig_ptr(p) = q;
   subtype(p) = 0;
+
   return p;
 }
 /* sec 0144 */
-halfword new_lig_item_(quarterword c)
+pointer new_lig_item_(quarterword c)
 {
-  halfword p;
+  pointer p;
+
   p = get_node(small_node_size);
   character(p) = c;
   lig_ptr(p) = 0;
+
   return p;
 }
 /* sec 0145 */
-halfword new_disc (void) 
+pointer new_disc (void) 
 {
-  halfword p;
+  pointer p;
+
   p = get_node(small_node_size);
   type(p) = disc_node;
   replace_count(p) = 0;
   pre_break(p) = 0;
   post_break(p) = 0;
+
   return p;
 }
 /* sec 0147 */
-halfword new_math_(scaled w, small_number s)
+pointer new_math_(scaled w, small_number s)
 {
-  halfword p;
+  pointer p;
+
   p = get_node(small_node_size);
   type(p) = math_node;
   subtype(p) = s;
   width(p) = w;
+
   return p;
 }
 /* sec 0151 */
-halfword new_spec_(halfword p)
+pointer new_spec_(pointer p)
 {
-  halfword q;
+  pointer q;
+
   q = get_node(glue_spec_size);
   mem[q] = mem[p];
   glue_ref_count(q) = 0;
   width(q) = width(p);
   stretch(q) = stretch(p);
   shrink(q) = shrink(p);
+
   return q;
 }
 /* se 0152 */
-halfword new_param_glue_(small_number n)
+pointer new_param_glue_(small_number n)
 {
-  halfword p;
-  halfword q;
+  pointer p;
+  pointer q;
+
   p = get_node(small_node_size);
   type(p) = glue_node;
   subtype(p) = n + 1;
@@ -1780,57 +1661,66 @@ halfword new_param_glue_(small_number n)
   q = glue_par(n);
   glue_ptr(p) = q;
   incr(glue_ref_count(q));
+
   return p;
 }
 /* sec 0153 */
-halfword new_glue_(halfword q)
+pointer new_glue_(pointer q)
 {
-  halfword p;
+  pointer p;
+
   p = get_node(small_node_size);
   type(p) = glue_node;
   subtype(p) = normal;
   leader_ptr(p) = 0; 
   glue_ptr(p) = q;
   incr(glue_ref_count(q));
+
   return p;
 }
 /* sec 0154 */
-halfword new_skip_param_(small_number n)
+pointer new_skip_param_(small_number n)
 {
-  halfword p;
+  pointer p;
+
   temp_ptr = new_spec(glue_par(n));
   p = new_glue(temp_ptr); 
   glue_ref_count(temp_ptr) = 0;
   subtype(p) = n + 1;
+
   return p;
 }
 /* sec 0155 */
-halfword new_kern_(scaled w)
+pointer new_kern(scaled w)
 {
-  halfword p; 
+  pointer p;
+
   p = get_node(small_node_size);
   type(p) = kern_node;
   subtype(p) = normal;
   width(p) = w;
+
   return p;
 }
 /* sec 0158 */
-halfword new_penalty_(integer m)
+pointer new_penalty(integer m)
 {
-  halfword p;
+  pointer p;
+
   p = get_node(small_node_size);
   type(p) = penalty_node;
   subtype(p) = 0;
   penalty(p) = m;
+
   return p;
 }
 
 #ifdef DEBUG
 /* sec 0167 */
-void check_mem_(bool printlocs)
+void check_mem(boolean printlocs)
 {
-  halfword p, q;
-  bool clobbered;
+  pointer p, q;
+  boolean clobbered;
 
   for (p = mem_min; p <= lo_mem_max; p++) freearr[p] = false;
   for (p = hi_mem_min; p <= mem_end; p++) freearr[p] = false;
@@ -1847,13 +1737,13 @@ void check_mem_(bool printlocs)
     {
       print_nl("AVAIL list clobbered at ");
       print_int(q);
-      goto lab31;
+      goto done1;
     }
     freearr[p] = true;
     q = p;
     p = link(q);
   }
-lab31:;
+done1:;
   p = rover;
   q = 0;
   clobbered = false;
@@ -1870,7 +1760,7 @@ lab31:;
       {
         print_nl("Double-AVAIL list clobbered at ");
         print_int(q);
-        goto lab32;
+        goto done2;
       }
 
       for (q = p; q <= p + node_size(p) - 1; q++)
@@ -1879,14 +1769,14 @@ lab31:;
         {
           print_nl("Doubly free location at ");
           print_int(q);
-          goto lab32;
+          goto done2;
         }
         freearr[q]= true;
       }
       q = p;
       p = rlink(p);
   } while (!(p == rover));
-lab32:;
+done2:;
   p = mem_min;
   while (p <= lo_mem_max) {
     if (is_empty(p))
@@ -1996,8 +1886,9 @@ void search_mem_(halfword p)
 void short_display_(integer p)
 {
   integer n; 
-/*  while(p > mem_min){ */
-  while (p != 0) {      /* want p != null here bkph 93/Dec/15 !!! NOTE: still not fixed in 3.14159 ! */
+
+  while (p != 0) /* want p != null here ! */
+  {
      if (is_char_node(p))
      {
        if (p <= mem_end)
@@ -2009,8 +1900,9 @@ void short_display_(integer p)
            else
            {
              print_esc("");
-             print(hash[(hash_size + hash_extra + 524) + mem[p].hh.b0].v.RH);
+             print(font_id_text(font(p)));
            }
+
            print_char(' ');
            font_in_short_display = font(p);
          }
@@ -2026,7 +1918,7 @@ void short_display_(integer p)
       case mark_node:
       case adjust_node:
       case unset_node:
-        print_string("[]");
+        prints("[]");
         break;
       case rule_node:
         print_char('|');
@@ -2045,9 +1937,12 @@ void short_display_(integer p)
         short_display(pre_break(p));
         short_display(post_break(p));
         n = replace_count(p);
-        while (n > 0) {
-          if (link(p) != 0) /* if link(p)<>null then */
+
+        while (n > 0)
+        {
+          if (link(p) != 0)
             p = link(p);
+
           decr(n);
         }
         break;
@@ -2058,18 +1953,20 @@ void short_display_(integer p)
   }
 }
 /* sec 0176 */
-void print_font_and_char_ (integer p)
+void print_font_and_char (integer p)
 {
   if (p > mem_end)
     print_esc("CLOBBERED.");
-  else {
+  else
+  {
     if ((font(p) > font_max))
       print_char('*');
     else
     {
       print_esc("");
-      print(hash[(hash_size + hash_extra + 524) + mem[p].hh.b0].v.RH);
+      print(font_id_text(font(p)));
     }
+
     print_char(' ');
     print(character(p));
   }
@@ -2078,16 +1975,18 @@ void print_font_and_char_ (integer p)
 void print_mark_ (integer p)
 { 
   print_char('{');
-  if ((p < hi_mem_min)||(p > mem_end))
+
+  if ((p < hi_mem_min) || (p > mem_end))
     print_esc("CLOBBERED.");
   else
     show_token_list(link(p), 0, max_print_line - 10);
+
   print_char('}');
 }
 /* sec 0176 */
-void print_rule_dimen(scaled d)
+void print_rule_dimen(scaled d)
 {
-  if ((d == -1073741824L)) /* - 2^30 */
+  if (is_running(d))
     print_char('*');
   else
     print_scaled(d);
@@ -2096,38 +1995,43 @@ void print_rule_dimen_ (scaled d)
 void print_glue_(scaled d, integer order, char * s)
 {
   print_scaled(d); 
+
   if ((order < normal) || (order > filll))
-    print_string("foul");
+    prints("foul");
   else if (order > 0)
   {
-    print_string("fil");
-    while (order > 1) {
+    prints("fil");
+
+    while (order > 1)
+    {
       print_char('l');
       decr(order);
     }
-  } else if (*s != '\0')
-    print_string(s);
+  }
+  else if (*s != '\0')
+    prints(s);
 }
 /* sec 0178 */
 void print_spec_(integer p, char * s)
 {
-  if ((p < mem_min)||(p >= lo_mem_max)) 
+  if ((p < mem_min) || (p >= lo_mem_max)) 
     print_char('*');
-  else {
-    print_scaled(mem[p + 1].cint);
+  else
+  {
+    print_scaled(width(p));
 
     if (*s != '\0')
-      print_string(s);
+      prints(s);
 
     if (stretch(p) != 0)
     {
-      print_string("plus");
+      prints("plus");
       print_glue(stretch(p), stretch_order(p), s);
     }
 
     if (shrink(p) != 0)
     {
-      print_string("minus");
+      prints("minus");
       print_glue(shrink(p), shrink_order(p), s);
     }
   }
@@ -2136,16 +2040,18 @@ void print_spec_(integer p, char * s)
 void print_fam_and_char_(halfword p)
 {
   print_esc("fam");
-  print_int(mem[p].hh.b0);
+  print_int(fam(p));
   print_char(' ');
-  print(mem[p].hh.b1);
+  print(character(p));
 }
 /* sec 0691 */
 void print_delimiter_(halfword p)
 {
   integer a;
-  a = mem[p].qqqq.b0 * 256 + mem[p].qqqq.b1;
-  a = a * 4096 + mem[p].qqqq.b2 * 256 + mem[p].qqqq.b3;
+
+  a = small_fam(p) * 256 + small_char(p);
+  a = a * 0x1000 + large_fam(p) * 256 + large_char(p);
+
   if (a < 0)
     print_int(a);
   else
@@ -2156,36 +2062,41 @@ void print_subsidiary_data_(halfword p, ASCII_code c)
 {
   if ((pool_ptr - str_start[str_ptr]) >= depth_threshold)
   {
-    if (mem[p].hh.v.RH != 0)
-      print_string("[]");
+    if (math_type(p) != 0)
+      prints(" []");
   }
   else
   {
     append_char(c);
     temp_ptr = p;
-    switch (mem[p].hh.v.RH)
+
+    switch (math_type(p))
     {
-      case 1:
+      case math_char:
         print_ln();
         print_current_string();
         print_fam_and_char(p);
         break;
-      case 2:
+
+      case sub_box:
         show_info();
         break;
-      case 3:
+
+      case sub_mlist:
         if (info(p) == 0)
         {
           print_ln();
           print_current_string();
-          print_string("{}");
+          prints("{}");
         }
         else
           show_info();
         break;
+
       default:
         break;
     }
+
     decr(pool_ptr);
   }
 }
@@ -2207,7 +2118,7 @@ void print_style_(integer c)
       print_esc("scriptscriptstyle");
       break;
     default:
-      print_string("Unknown style!");
+      prints("Unknown style!");
       break;
   }
 }
@@ -2219,59 +2130,77 @@ void print_skip_param_(integer n)
     case line_skip_code:
       print_esc("lineskip");
       break;
+
     case baseline_skip_code:
       print_esc("baselineskip");
       break; 
+
     case par_skip_code:
       print_esc("parskip");
       break;
+
     case above_display_skip_code:
       print_esc("abovedisplayskip");
       break;
+
     case below_display_skip_code:
       print_esc("belowdisplayskip");
       break;
+
     case above_display_short_skip_code:
       print_esc("abovedisplayshortskip");
       break;
+
     case below_display_short_skip_code:
       print_esc("belowdisplayshortskip");
       break;
+
     case left_skip_code:
       print_esc("leftskip");
       break;
+
     case right_skip_code:
       print_esc("rightskip");
       break;
+
     case top_skip_code:
       print_esc("topskip");
       break;
+
     case split_top_skip_code:
       print_esc("splittopskip");
       break;
+
     case tab_skip_code:
       print_esc("tabskip");
       break;
+
     case space_skip_code:
       print_esc("spaceskip");
       break;
+
     case xspace_skip_code:
       print_esc("xspaceskip");
       break;
+
     case par_fill_skip_code:
       print_esc("parfillskip");
       break;
+
     case thin_mu_skip_code:
       print_esc("thinmuskip");
       break;
+
     case med_mu_skip_code:
       print_esc("medmuskip");
       break; 
+
     case thick_mu_skip_code:
       print_esc("thickmuskip");
       break;
+
     default:
-      print_string("[unknown glue parameter!]");
+      prints("[unknown glue parameter!]");
       break;
   }
 }
@@ -2283,444 +2212,479 @@ void show_node_list_(integer p)
 
   if (cur_length > depth_threshold)
   {
-/*  if (p > 0) */  /* was p>null !!! line 3662 in tex.web */
     if (p != 0)    /* fixed 94/Mar/23 BUG FIX NOTE: still not fixed in 3.14159 ! */
-    print_string("[]");
+      prints(" []");
+
     return; 
-  } 
+  }
+
   n = 0; 
-/*  while(p > mem_min){ */  /* was p>mem_min !!! line 3667 in tex.web */
+
   while (p != 0) {      /* want p != null - bkph 93/Dec/15 NOTE: still not fixed in 3.14159 ! */
     print_ln(); 
     print_current_string(); 
+
     if (p > mem_end)
     {
-      print_string("Bad link, display aborted.");
+      prints("Bad link, display aborted.");
       return;
     }
+
     incr(n);
+
     if (n > breadth_max)
     {
-      print_string("etc.");
+      prints("etc.");
       return;
     }
-    if ((p >= hi_mem_min))
+
+    if (is_char_node(p))
       print_font_and_char(p);
-    else switch (mem[p].hh.b0)
+    else switch (type(p))
     {
-      case 0:
-      case 1:
-      case 13:
+      case hlist_node:
+      case vlist_node:
+      case unset_node:
         {
-          if (mem[p].hh.b0 == 0)
+          if (type(p) == hlist_node)
             print_esc("h");
-          else if (mem[p].hh.b0 == 1)
+          else if (type(p) == vlist_node)
             print_esc("v");
           else print_esc("unset");
-          print_string("box(");
-          print_scaled(mem[p + 3].cint);
+
+          prints("box(");
+          print_scaled(height(p));
           print_char('+');
-          print_scaled(mem[p + 2].cint);
-          print_string(", shifted ");
-          print_scaled(mem[p + 1].cint);
-          if (mem[p].hh.b0 == 13)
+          print_scaled(depth(p));
+          prints(")x");
+          print_scaled(width(p));
+
+          if (type(p) == unset_node)
           {
-            if (mem[p].hh.b1 != 0)
+            if (span_count(p) != 0)
             {
-              print_string(" (");
-              print_int(mem[p].hh.b1 + 1);
-              print_string(" columns)");
+              prints(" (");
+              print_int(span_count(p) + 1);
+              prints(" columns)");
             }
-            if (mem[p + 6].cint != 0)
+
+            if (glue_stretch(p) != 0)
             {
-              print_string(", stretch");
-              print_glue(mem[p + 6].cint, mem[p + 5].hh.b1, "");
+              prints(", stretch ");
+              print_glue(glue_stretch(p), glue_order(p), "");
             }
-            if (mem[p + 4].cint != 0)
+
+            if (glue_shrink(p) != 0)
             {
-              print_string(", shrink");
-              print_glue(mem[p + 4].cint, mem[p + 5].hh.b0, "");
+              prints(", shrink ");
+              print_glue(glue_shrink(p), glue_sign(p), "");
             }
-          } else {
-            g = mem[p + 6].gr;
-            if ((g != 0.0)&&(mem[p + 5].hh.b0 != 0))
+          }
+          else
+          {
+            g = glue_set(p);
+
+            if ((g != 0.0) && (glue_sign(p) != 0))
             {
-              print_string(", glue set");
-              if (mem[p + 5].hh.b0 == 2)
-                print_string("- ");
+              prints(", glue set ");
+
+              if (glue_sign(p) == shrinking)
+                prints("- ");
+
               if (fabs(g)> 20000.0)
               {
                 if (g > 0.0)
                   print_char('>');
                 else
-                  print_string("< -");
-                print_glue(20000 * 65536L, mem[p + 5].hh.b1, "");
-              } else print_glue(round(65536L * g), mem[p + 5].hh.b1, "");
-            }
-            if (mem[p + 4].cint != 0)
-            {
-              print_string("shifted");
-              print_scaled(mem[p + 4].cint);
+                  prints("< -");
+
+                print_glue(20000 * unity, glue_order(p), "");
+              }
+              else
+                print_glue(round(unity * g), glue_order(p), "");
             }
-          }
-          {
+
+            if (shift_amount(p) != 0)
             {
-              str_pool[pool_ptr]= 46;
-              incr(pool_ptr);
+              prints(", shifted ");
+              print_scaled(shift_amount(p));
             }
-            show_node_list(mem[p + 5].hh.v.RH);
-            decr(pool_ptr);
           }
+
+          node_list_display(list_ptr(p));
         }
         break;
-      case 2:
+
+      case rule_node:
         {
           print_esc("rule(");
-          print_rule_dimen(mem[p + 3].cint);
+          print_rule_dimen(height(p));
           print_char('+');
-          print_rule_dimen(mem[p + 2].cint);
-          print_string(")x");
-          print_rule_dimen(mem[p + 1].cint);
+          print_rule_dimen(depth(p));
+          prints(")x");
+          print_rule_dimen(width(p));
         }
         break;
-      case 3:
+
+      case ins_node:
         {
           print_esc("insert");
-          print_int(mem[p].hh.b1);
-          print_string(", natural size ");
-          print_scaled(mem[p + 3].cint);
-          print_string("; split(");
-          print_spec(mem[p + 4].hh.v.RH, "");
+          print_int(subtype(p));
+          prints(", natural size ");
+          print_scaled(height(p));
+          prints("; split(");
+          print_spec(split_top_ptr(p), "");
           print_char(',');
-          print_scaled(mem[p + 2].cint);
-          print_string("(; float cost");
-          print_int(mem[p + 1].cint);
-          {
-            {
-              str_pool[pool_ptr]= 46;
-              incr(pool_ptr);
-            }
-            show_node_list(mem[p + 4].hh.v.LH);
-            decr(pool_ptr);
-          }
+          print_scaled(depth(p));
+          prints("); float cost ");
+          print_int(float_cost(p));
+          node_list_display(ins_ptr(p));
         }
         break;
-      case 8:
-        switch (mem[p].hh.b1)
+
+      case whatsit_node:
+        switch (subtype(p))
         {
-          case 0:
+          case open_node:
             {
-              print_write_whatsit(1279, p);   /* debug # (-1 to exit): */
+              print_write_whatsit("openout", p);
               print_char('=');
-              print_file_name(mem[p + 1].hh.v.RH, mem[p + 2].hh.v.LH, mem[p + 2].hh.v.RH);
+              print_file_name(open_name(p), open_area(p), open_ext(p));
             }
             break;
-          case 1:
+
+          case write_node:
             {
-              print_write_whatsit(591, p);  /* write */
-              print_mark(mem[p + 1].hh.v.RH);
+              print_write_whatsit("write", p);
+              print_mark(write_tokens(p));
             }
             break;
-          case 2:
-            print_write_whatsit(1280, p); /* closeout */
+
+          case close_node:
+            print_write_whatsit("closeout", p);
             break;
-          case 3:
+
+          case special_node:
             {
               print_esc("special");
-              print_mark(mem[p + 1].hh.v.RH);
+              print_mark(write_tokens(p));
             }
             break;
-          case 4:
+
+          case language_node:
             {
               print_esc("setlanguage");
-              print_int(mem[p + 1].hh.v.RH);
-              print_string(" (hyphenmin");
-              print_int(mem[p + 1].hh.b0);
+              print_int(what_lang(p));
+              prints(" (hyphenmin ");
+              print_int(what_lhm(p));
               print_char(',');
-              print_int(mem[p + 1].hh.b1);
+              print_int(what_rhm(p));
               print_char(')');
             }
             break;
+
           default:
-            print_string("whatsit");
+            prints("whatsit?");
             break;
         }
         break;
-      case 10:
-        if (mem[p].hh.b1 >= 100)
+
+      case glue_node:
+        if (subtype(p) >= a_leaders)
         {
           print_esc("");
-          if (mem[p].hh.b1 == 101)
+
+          if (subtype(p) == c_leaders)
             print_char('c');
-          else if (mem[p].hh.b1 == 102)
+          else if (subtype(p) == x_leaders)
             print_char('x');
-          print_string("leaders ");
-          print_spec(mem[p + 1].hh.v.LH, "");
-          {
-            {
-              str_pool[pool_ptr]= 46;
-              incr(pool_ptr);
-            }
-            show_node_list(mem[p + 1].hh.v.RH);
-            decr(pool_ptr);
-          }
-        } else {
+
+          prints("leaders ");
+          print_spec(glue_ptr(p), "");
+          node_list_display(leader_ptr(p));
+        }
+        else
+        {
           print_esc("glue");
-          if (mem[p].hh.b1 != 0)
+
+          if (subtype(p) != normal)
           {
             print_char('(');
-            if (mem[p].hh.b1 < 98)
-              print_skip_param(mem[p].hh.b1 - 1);
-            else if (mem[p].hh.b1 == 98)
+
+            if (subtype(p) < cond_math_glue)
+              print_skip_param(subtype(p) - 1);
+            else if (subtype(p) == cond_math_glue)
               print_esc("nonscript");
             else print_esc("mskip");
+
             print_char(')');
           }
-          if (mem[p].hh.b1 != 98)
+
+          if (subtype(p) != cond_math_glue)
           {
             print_char(' ');
-            if (mem[p].hh.b1 < 98)
-              print_spec(mem[p + 1].hh.v.LH, "");
+
+            if (subtype(p) < cond_math_glue)
+              print_spec(glue_ptr(p), "");
             else
-              print_spec(mem[p + 1].hh.v.LH, "mu");
+              print_spec(glue_ptr(p), "mu");
           }
         }
         break;
-      case 11:
-        if (mem[p].hh.b1 != 99)
+
+      case kern_node:
+        if (subtype(p) != mu_glue)
         {
           print_esc("kern");
-          if (mem[p].hh.b1 != 0)
+
+          if (subtype(p) != normal)
             print_char(' ');
-          print_scaled(mem[p + 1].cint);
-          if (mem[p].hh.b1 == 2)
-            print_string(" (for accent)");
-        } else {
+
+          print_scaled(width(p));
+
+          if (subtype(p) == acc_kern)
+            prints(" (for accent)");
+        }
+        else
+        {
           print_esc("mkern");
-          print_scaled(mem[p + 1].cint);
-          print_string("mu");
+          print_scaled(width(p));
+          prints("mu");
         }
         break;
-      case 9:
+
+      case math_node:
         {
           print_esc("math");
-          if (mem[p].hh.b1 == 0)
-            print_string("on");
-          else print_string("off");
-          if (mem[p + 1].cint != 0)
+
+          if (subtype(p) == before)
+            prints("on");
+          else
+            prints("off");
+
+          if (width(p) != 0)
           {
-            print_string(", surrounded");
-            print_scaled(mem[p + 1].cint);
+            prints(", surrounded ");
+            print_scaled(width(p));
           }
         }
         break;
-      case 6:
+
+      case ligature_node:
         {
-          print_font_and_char(p + 1);
-          print_string("(ligature");
-          if (mem[p].hh.b1 > 1)
+          print_font_and_char(lig_char(p));
+          prints("(ligature ");
+
+          if (subtype(p) > 1)
             print_char('|');
-          font_in_short_display = mem[p + 1].hh.b0; 
-          short_display(mem[p + 1].hh.v.RH);
-          if (odd(mem[p].hh.b1))
+
+          font_in_short_display = font(lig_char(p)); 
+          short_display(lig_ptr(p));
+
+          if (odd(subtype(p)))
             print_char('|');
+
           print_char(')');
         }
         break;
-      case 12:
+
+      case penalty_node:
         {
           print_esc("penalty ");
-          print_int(mem[p + 1].cint);
+          print_int(penalty(p));
         }
         break;
-      case 7:
+
+      case disc_node:
         {
           print_esc("discretionary");
-          if (mem[p].hh.b1 > 0)
-          {
-            print_string(" replacing ");
-            print_int(mem[p].hh.b1);
-          }
-          {
-            {
-              str_pool[pool_ptr]= 46;
-              incr(pool_ptr);
-            }
-            show_node_list(mem[p + 1].hh.v.LH);
-            decr(pool_ptr);
-          }
+
+          if (replace_count(p) > 0)
           {
-            str_pool[pool_ptr]= 124;
-            incr(pool_ptr);
+            prints(" replacing ");
+            print_int(replace_count(p));
           }
-          show_node_list(mem[p + 1].hh.v.RH);
+
+          node_list_display(pre_break(p));
+          append_char('|');
+          show_node_list(post_break(p));
           decr(pool_ptr);
         }
         break;
-      case 4:
+
+      case mark_node:
         {
           print_esc("mark");
-          print_mark(mem[p + 1].cint);
+          print_mark(mark_ptr(p));
         }
         break;
-      case 5:
+
+      case adjust_node:
         {
           print_esc("vadjust");
-          {
-            {
-              str_pool[pool_ptr]= 46;
-              incr(pool_ptr);
-            }
-            show_node_list(mem[p + 1].cint);
-            decr(pool_ptr);
-          }
+          node_list_display(adjust_ptr(p));
         }
         break;
-      case 14:
-        print_style(mem[p].hh.b1);
+
+      case style_node:
+        print_style(subtype(p));
         break;
-      case 15:
+
+      case choice_node:
         {
           print_esc("mathchoice");
-          {
-            str_pool[pool_ptr]= 68;
-            incr(pool_ptr);
-          }
-          show_node_list(mem[p + 1].hh.v.LH);
+          append_char('D');
+          show_node_list(display_mlist(p));
           decr(pool_ptr);
-          {
-            str_pool[pool_ptr]= 84;
-            incr(pool_ptr);
-          }
-          show_node_list(mem[p + 1].hh.v.RH);
+          append_char('T');
+          show_node_list(text_mlist(p));
           decr(pool_ptr);
-          {
-            str_pool[pool_ptr]= 83;
-            incr(pool_ptr);
-          }
-          show_node_list(mem[p + 2].hh.v.LH);
+          append_char('S');
+          show_node_list(script_mlist(p));
           decr(pool_ptr);
-          {
-            str_pool[pool_ptr]= 115;
-            incr(pool_ptr);
-          } 
-          show_node_list(mem[p + 2].hh.v.RH); 
+          append_char('s');
+          show_node_list(script_script_mlist(p)); 
           decr(pool_ptr); 
         } 
         break;
-      case 16:
-      case 17:
-      case 18:
-      case 19:
-      case 20:
-      case 21:
-      case 22:
-      case 23:
-      case 24:
-      case 27:
-      case 26:
-      case 29:
-      case 28:
-      case 30:
-      case 31:
+
+      case ord_noad:
+      case op_noad:
+      case bin_noad:
+      case rel_noad:
+      case open_noad:
+      case close_noad:
+      case punct_noad:
+      case inner_noad:
+      case radical_noad:
+      case over_noad:
+      case under_noad:
+      case vcenter_noad:
+      case accent_noad:
+      case left_noad:
+      case right_noad:
         {
-          switch (mem[p].hh.b0)
+          switch (type(p))
           {
-            case 16:
+            case ord_noad:
               print_esc("mathord");
               break;
-            case 17:
+
+            case op_noad:
               print_esc("mathop");
               break;
-            case 18:
+
+            case bin_noad:
               print_esc("mathbin");
               break;
-            case 19:
+
+            case rel_noad:
               print_esc("mathrel");
               break;
-            case 20:
+
+            case open_noad:
               print_esc("mathopen");
               break;
-            case 21:
+
+            case close_noad:
               print_esc("mathclose");
               break;
-            case 22:
+
+            case punct_noad:
               print_esc("mathpunct");
               break;
-            case 23:
+
+            case inner_noad:
               print_esc("mathinner");
               break;
-            case 27:
+
+            case over_noad:
               print_esc("overline");
               break;
-            case 26:
+
+            case under_noad:
               print_esc("underline");
               break;
-            case 29:
+
+            case vcenter_noad:
               print_esc("vcenter");
               break;
-            case 24:
+
+            case radical_noad:
               {
                 print_esc("radical");
-                print_delimiter(p + 4);
+                print_delimiter(left_delimiter(p));
               }
               break;
-            case 28:
+
+            case accent_noad:
               {
                 print_esc("accent");
-                print_fam_and_char(p + 4);
+                print_fam_and_char(accent_chr(p));
               }
               break;
-            case 30:
+
+            case left_noad:
               {
                 print_esc("left");
-                print_delimiter(p + 1);
+                print_delimiter(delimiter(p));
               }
               break;
-            case 31:
+
+            case right_noad:
               {
                 print_esc("right");
-                print_delimiter(p + 1);
+                print_delimiter(delimiter(p));
               }
               break;
-          } 
-          if (mem[p].hh.b1 != 0)
-            if (mem[p].hh.b1 == 1)
+          }
+
+          if (subtype(p) != normal)
+            if (subtype(p) == limits)
               print_esc("limits");
-            else print_esc("nolimits");
-          if (mem[p].hh.b0 < 30)
-            print_subsidiary_data(p + 1, 46);
-          print_subsidiary_data(p + 2, 94);
-          print_subsidiary_data(p + 3, 95);
+            else
+              print_esc("nolimits");
+
+          if (type(p) < left_noad)
+            print_subsidiary_data(nucleus(p), '.');
+
+          print_subsidiary_data(supscr(p), '^');
+          print_subsidiary_data(subscr(p), '_');
         }
         break;
-      case 25:
+
+      case fraction_noad:
         {
-          print_esc("fraction");
-          if (mem[p + 1].cint == 1073741824L)  /* 2^30 */
-            print_string("= default");
-          else print_scaled(mem[p + 1].cint); 
-          if ((mem[p + 4].qqqq.b0 != 0) || (mem[p + 4].qqqq.b1 != 0) ||
-              (mem[p + 4].qqqq.b2 != 0) || (mem[p + 4].qqqq.b3 != 0))
+          print_esc("fraction, thickness ");
+
+          if (thickness(p) == 1073741824L)  /* 2^30 */
+            prints("= default");
+          else
+            print_scaled(thickness(p));
+
+          if ((small_fam(left_delimiter(p)) != 0) || (small_char(left_delimiter(p)) != 0) ||
+              (large_fam(left_delimiter(p)) != 0) || (large_char(left_delimiter(p)) != 0))
           {
-            print_string(", left");
-            print_delimiter(p + 4);
+            prints(", left-delimiter ");
+            print_delimiter(left_delimiter(p));
           }
-          if ((mem[p + 5].qqqq.b0 != 0) || (mem[p + 5].qqqq.b1 != 0) ||
-              (mem[p + 5].qqqq.b2 != 0)||(mem[p + 5].qqqq.b3 != 0))
+
+          if ((small_fam(right_delimiter(p)) != 0) || (small_char(right_delimiter(p)) != 0) ||
+              (large_fam(right_delimiter(p)) != 0) || (large_char(right_delimiter(p)) != 0))
           {
-            print_string(", right");
-            print_delimiter(p + 5);
+            prints(", right-delimiter ");
+            print_delimiter(right_delimiter(p));
           }
-          print_subsidiary_data(p + 2, 92);
-          print_subsidiary_data(p + 3, 47);
+
+          print_subsidiary_data(numerator(p), '\\');
+          print_subsidiary_data(denominator(p), '/');
         }
         break;
+
       default:
-        print_string("Unknown node type!");
+        prints("Unknown node type!");
         break;
     }
-    p = mem[p].hh.v.RH;
-  } 
-} 
-/* NOTE: 262143L should be empty_flag */
+    p = link(p);
+  }
+}
\ No newline at end of file