OSDN Git Service

node_list_display().
[putex/putex.git] / src / texsourc / tex0.c
index dadb7b4..873e64e 100644 (file)
    02110-1301 USA.  */
 
 #define EXTERN extern
-
 #include "texd.h"
 
-/* *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** */
-INLINE void synch_h(void)
-{
-  if (cur_h != dvi_h)
-  {
-    movement(cur_h - dvi_h, right1);
-    dvi_h = cur_h;
-  }
-}
-INLINE void synch_v(void)
-{
-  if (cur_v != dvi_v)
-  {
-    movement(cur_v - dvi_v, down1);
-    dvi_v = cur_v;
-  }
-}
-INLINE void set_cur_lang(void)
-{
-  if (language <= 0)
-    cur_lang = 0;
-  else if (language > 255)
-    cur_lang = 0;
-  else
-    cur_lang = language;
-}
-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, ...)
-{
-  int i;
-  va_list help_arg;
-
-  if (n > 6)
-    n = 6;
-
-  help_ptr = n;
-  va_start(help_arg, n);
-
-  for (i = n - 1; i > -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);
-  }
-#endif
-}
-INLINE void tail_append_ (pointer val)
-{
-  link(tail) = val;
-  tail = link(tail);
-}
-/* *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** */
-
-/* *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** */
 /* sec 0058 */
 void print_ln (void)
 {
@@ -151,12 +26,12 @@ 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;
 
@@ -168,10 +43,11 @@ void print_ln (void)
     case no_print:
     case pseudo:
     case new_string:
+      do_nothing();
       break;
 
     default:
-      (void) putc ('\n', write_file[selector]);
+      putc('\n', write_file[selector]);
       break;
   }
 }
@@ -179,20 +55,18 @@ void print_ln (void)
 void print_char_ (ASCII_code s)
 {
   if (s == new_line_char)
-  {
     if (selector < pseudo)
     {
       print_ln();
       return;
     }
-  }
 
   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)
@@ -203,14 +77,14 @@ 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)
@@ -219,7 +93,7 @@ void print_char_ (ASCII_code s)
       break;
 
     case term_only:
-      (void) show_char(Xchr(s));
+      show_char(xchr[s]);
       incr(term_offset);
 
       if (term_offset == max_print_line)
@@ -228,6 +102,7 @@ void print_char_ (ASCII_code s)
       break;
 
     case no_print:
+      do_nothing();
       break;
 
     case pseudo:
@@ -239,26 +114,18 @@ void print_char_ (ASCII_code s)
     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;
   }
 
@@ -286,53 +153,54 @@ void print_ (integer s)
           return;
         }
 
-        if ((s == new_line_char))
+        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)
+        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 (show_in_dos && s > 127)
+            if (wintodos[s - 128] > 0)
             {
-              if (wintodos[s - 128] > 0)
-              {
-                print_char (wintodos[s - 128]);
-              }
-              else
-              {
-                j = str_start[s];
-
-                while (j < str_start[s + 1])
-                {
-                  print_char(str_pool[j]);
-                  incr(j);
-                }
-              }
+              print_char(wintodos[s - 128]);
             }
             else
             {
-              print_char(s);       /* don't translate to hex */
+              j = str_start[s];
+
+              while (j < str_start[s + 1])
+              {
+                print_char(str_pool[j]);
+                incr(j);
+              }
             }
           }
           else
-          {                       /* not just a character */
-            j = str_start[s];
+          {
+            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);
-            }
+          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;
       }
     }
   }
@@ -346,7 +214,7 @@ void print_ (integer s)
   }
 }
 /* string version print. */
-void print_string_ (unsigned char *s)
+void prints_ (const char *s)
 {
   while (*s > 0)
     print_char(*s++);
@@ -357,9 +225,7 @@ void slow_print_ (integer s)
   pool_pointer j;
 
   if ((s >= str_ptr) || (s < 256))
-  {
     print(s);
-  }
   else
   {
     j = str_start[s];
@@ -372,16 +238,16 @@ void slow_print_ (integer s)
   }
 }
 /* sec 0062 */
-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 */
-void print_esc_ (const char * s)
+void print_esc (const char * s)
 {
   integer c;
 
@@ -391,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)
@@ -467,7 +333,8 @@ void print_cs_ (integer p)
       }
     else if (p < active_base)
       print_esc("IMPOSSIBLE.");
-    else print(p - active_base);
+    else
+      print(p - active_base);
   else if (p >= undefined_control_sequence)
     print_esc("IMPOSSIBLE.");
   else if ((text(p) >= str_ptr))
@@ -518,10 +385,9 @@ void print_size_ (integer s)
     print_esc("scriptscriptfont");
 } 
 /* sec 1355 */
-void print_write_whatsit_(str_number s, pointer p)
+void print_write_whatsit_(const char * s, pointer p)
 {
-  print_esc("");
-  print(s);
+  print_esc(s);
 
   if (write_stream(p) < 16)
     print_int(write_stream(p)); 
@@ -544,7 +410,7 @@ void jump_out (void)
     ready_already = 0;
 
     if (trace_flag)
-      show_line("EXITING at JUMPOUT\n", 0);
+      puts("EXITING at JUMPOUT");
 
     if ((history != 0) && (history != 1))
       code = 1;
@@ -571,21 +437,17 @@ 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
+      c = buffer[first];
 
-      if (c >= 'a')         // uppercase letter first
-        c = (unsigned char) (c + 'A' - 'a'); 
+      if (c >= 'a')
+        c = (c + 'A' - 'a'); 
 
       switch (c)
       {
@@ -609,9 +471,9 @@ 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)
             {
@@ -627,7 +489,7 @@ 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;
 
@@ -635,10 +497,11 @@ lab22:
         case 'D':
           {
             debug_help();
-            goto lab22;       /* loop again */
+            goto continu;
           }
           break;
-#endif /* DEBUG */
+#endif
+
         case 'E':
           if (base_ptr > 0)
           {
@@ -661,18 +524,20 @@ 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;
 
@@ -682,19 +547,18 @@ lab22:
 
             if (last > first + 1)
             {
-              cur_input.loc_field = first + 1;
+              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;
@@ -705,7 +569,7 @@ lab22:
           {
             error_count = 0; 
             interaction = 0 + c - 81; /* Q = 0, R = 1, S = 2, T = 3 */
-            print_string("OK, entering ");
+            prints("OK, entering ");
 
             switch (c)
             {
@@ -713,19 +577,19 @@ lab22:
                 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;
@@ -742,19 +606,19 @@ lab22:
       }           /* 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);
 
@@ -773,7 +637,7 @@ 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] == NULL ? "" : help_line[help_ptr]);
@@ -787,7 +651,7 @@ lab22:
   print_ln();
 }
 /* sec 0093 */
-void fatal_error_(char * s)
+void fatal_error(char * s)
 {
   normalize_selector();
   print_err("Emergency stop");
@@ -799,7 +663,7 @@ void overflow_(char * s, integer n)
 {
   normalize_selector();
   print_err("TeX capacity exceeded, sorry [");
-  print_string(s);
+  prints(s);
   print_char('=');
   print_int(n);
   print_char(']');
@@ -808,12 +672,12 @@ 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);
@@ -823,14 +687,14 @@ void overflow_(char * s, integer n)
   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");
   }
@@ -852,41 +716,35 @@ boolean init_terminal (void)
 
   if (last > first)
   {
-    cur_input.loc_field = first;
+    loc = first;
 
-    while((cur_input.loc_field < last) && (buffer[cur_input.loc_field]== ' '))
-      incr(cur_input.loc_field);    // step over initial white space
+    while ((loc < last) && (buffer[loc]== ' '))
+      incr(loc);    // step over initial white space
 
-    if (cur_input.loc_field < last)
+    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);
+    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);
+      puts("! End of file on the terminal... why?\n");
       return false;
     }
 
-    cur_input.loc_field = first;
+    loc = first;
 
-    while ((cur_input.loc_field < last) && (buffer[cur_input.loc_field]== ' '))
-      incr(cur_input.loc_field);    // step over intial white space
+    while ((loc < last) && (buffer[loc]== ' '))
+      incr(loc);    // step over intial white space
 
-    if (cur_input.loc_field < last)
+    if (loc < last)
       return true;
 
     sprintf(log_line, "%s\n", "Please type the name of your input file.");
@@ -903,15 +761,16 @@ 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;
 
@@ -930,7 +789,7 @@ boolean str_eq_buf_ (str_number s, integer k)
     if (str_pool[j] != buffer[k])
     {
       result = false;
-      goto lab45;
+      goto not_found;
     }
 
     incr(j);
@@ -938,7 +797,8 @@ boolean str_eq_buf_ (str_number s, integer k)
   }
 
   result = true;
-lab45:
+
+not_found:
   return result;
 }
 /* sec 0045 */
@@ -950,7 +810,7 @@ boolean str_eq_str_ (str_number s, str_number t)
   result = false;
 
   if (length(s) != length(t))
-    goto lab45;
+    goto not_found;
 
   j = str_start[s];
   k = str_start[t];
@@ -958,14 +818,15 @@ boolean str_eq_str_ (str_number s, str_number 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:
+
+not_found:
   return result;
 }
 /* sec 0066 */
@@ -1048,180 +909,25 @@ void print_current_string (void)
   }
 }
 
-int stringlength (int str_ptr)
-{
-  return (str_start[str_ptr + 1] - str_start[str_ptr]) + 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 += 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;
-#ifdef _WINDOWS
-  char * querystring = NULL;
-#endif
-//  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;
+  
+  if (!knuth_flag)
+    show_line("\n", 0);
 
-  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);
+  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)
@@ -1230,12 +936,11 @@ void term_input (char * term_str, int term_help_lines)
 
   print_ln();
   incr(selector);     // reset selector again
-#endif
 }
 /* sec 0091 */
 void int_error_ (integer n)
 {
-  print_string(" (");
+  prints(" (");
   print_int(n);
   print_char(')');
   error();
@@ -1317,6 +1022,7 @@ void print_scaled_(scaled s)
     {
       if (delta > 65536L)
         s = s - 17232; /* 2^15 - 50000 - rounding */
+
       print_char('0' + (s / 65536L));
       s = 10 * (s % 65536L);
       delta = delta * 10;
@@ -1532,56 +1238,55 @@ void show_token_list_(integer p, integer q, integer l)
 
       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);
   }
@@ -1601,22 +1306,22 @@ void runaway (void)
     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;
     }
@@ -1664,7 +1369,7 @@ halfword get_avail (void)
       {
         runaway();
         overflow("main memory size", mem_max + 1 - mem_min);
-        return 0;           // abort_flag set
+        return 0;
       }
 
       incr(mem_end);        /* then grab from new area */
@@ -1710,7 +1415,7 @@ pointer get_node_(integer s)
   pointer q;
   integer r;
   integer t;
-lab20:
+restart:
 
   p = rover;
 
@@ -1718,7 +1423,7 @@ lab20:
     {
       q = p + node_size(p);
 
-      while ((mem[q].hh.rh == empty_flag))
+      while (is_empty(q))
       {
         t = rlink(q);
 
@@ -1736,7 +1441,7 @@ lab20:
       {
         node_size(p) = r - p;
         rover = p;
-        goto lab40;
+        goto found;
       }
 
       if (r == p)
@@ -1746,7 +1451,7 @@ lab20:
           t = llink(p);
           llink(rover) = t;
           rlink(t) = rover;
-          goto lab40;
+          goto found;
         }
 
       node_size(p) = q - p;
@@ -1757,7 +1462,7 @@ lab20:
   if (s == 1073741824L)    /* 2^30 - special case - merge adjacent */
   {
     if (trace_flag)
-      show_line("Merged adjacent multi-word nodes\n", 0);
+      puts("Merged adjacent multi-word nodes\n");
 
     return max_halfword;
   }
@@ -1789,7 +1494,7 @@ lab20:
       link(lo_mem_max) = 0;
       info(lo_mem_max) = 0;
       rover = q;
-      goto lab20;
+      goto restart;
     }
 
 /* *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** */
@@ -1809,18 +1514,18 @@ lab20:
   {
     if (trace_flag)
     {
-      sprintf(log_line, "mem_min %d, mem_start %d, block_size %d\n", mem_min, mem_start, block_size);
+      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;
   }
 
-  add_variable_space (block_size); /* now to be found in itex.c */
-  goto lab20;         /* go try get_node again */
+  add_variable_space (block_size);
+  goto restart; /* go try get_node again */
 
-lab40:
+found:
   link(r) = 0;
 
 #ifdef STAT
@@ -1986,7 +1691,7 @@ pointer new_skip_param_(small_number n)
   return p;
 }
 /* sec 0155 */
-pointer new_kern_(scaled w)
+pointer new_kern(scaled w)
 {
   pointer p;
 
@@ -1998,7 +1703,7 @@ pointer new_kern_(scaled w)
   return p;
 }
 /* sec 0158 */
-pointer new_penalty_(integer m)
+pointer new_penalty(integer m)
 {
   pointer p;
 
@@ -2012,7 +1717,7 @@ pointer new_penalty_(integer m)
 
 #ifdef DEBUG
 /* sec 0167 */
-void check_mem_(boolean printlocs)
+void check_mem(boolean printlocs)
 {
   pointer p, q;
   boolean clobbered;
@@ -2032,13 +1737,13 @@ void check_mem_(boolean 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;
@@ -2055,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++)
@@ -2064,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))
@@ -2182,7 +1887,8 @@ void short_display_(integer p)
 {
   integer n; 
 
-  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)
@@ -2196,6 +1902,7 @@ void short_display_(integer p)
              print_esc("");
              print(font_id_text(font(p)));
            }
+
            print_char(' ');
            font_in_short_display = font(p);
          }
@@ -2211,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('|');
@@ -2231,9 +1938,11 @@ void short_display_(integer 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;
@@ -2244,7 +1953,7 @@ 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.");
@@ -2275,9 +1984,9 @@ void print_mark_ (integer p)
   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);
@@ -2288,17 +1997,19 @@ 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");
+    prints("fil");
 
-    while (order > 1) {
+    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)
@@ -2310,17 +2021,17 @@ void print_spec_(integer p, char * s)
     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);
     }
   }
@@ -2352,7 +2063,7 @@ void print_subsidiary_data_(halfword p, ASCII_code c)
   if ((pool_ptr - str_start[str_ptr]) >= depth_threshold)
   {
     if (math_type(p) != 0)
-      print_string(" []");
+      prints(" []");
   }
   else
   {
@@ -2376,7 +2087,7 @@ void print_subsidiary_data_(halfword p, ASCII_code c)
         {
           print_ln();
           print_current_string();
-          print_string("{}");
+          prints("{}");
         }
         else
           show_info();
@@ -2407,7 +2118,7 @@ void print_style_(integer c)
       print_esc("scriptscriptstyle");
       break;
     default:
-      print_string("Unknown style!");
+      prints("Unknown style!");
       break;
   }
 }
@@ -2489,7 +2200,7 @@ void print_skip_param_(integer n)
       break;
 
     default:
-      print_string("[unknown glue parameter!]");
+      prints("[unknown glue parameter!]");
       break;
   }
 }
@@ -2502,7 +2213,7 @@ void show_node_list_(integer p)
   if (cur_length > depth_threshold)
   {
     if (p != 0)    /* fixed 94/Mar/23 BUG FIX NOTE: still not fixed in 3.14159 ! */
-      print_string(" []");
+      prints(" []");
 
     return; 
   }
@@ -2515,7 +2226,7 @@ void show_node_list_(integer p)
 
     if (p > mem_end)
     {
-      print_string("Bad link, display aborted.");
+      prints("Bad link, display aborted.");
       return;
     }
 
@@ -2523,11 +2234,11 @@ void show_node_list_(integer p)
 
     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 (type(p))
     {
@@ -2541,31 +2252,31 @@ void show_node_list_(integer p)
             print_esc("v");
           else print_esc("unset");
 
-          print_string("box(");
+          prints("box(");
           print_scaled(height(p));
           print_char('+');
           print_scaled(depth(p));
-          print_string(")x");
+          prints(")x");
           print_scaled(width(p));
 
           if (type(p) == unset_node)
           {
             if (span_count(p) != 0)
             {
-              print_string(" (");
+              prints(" (");
               print_int(span_count(p) + 1);
-              print_string(" columns)");
+              prints(" columns)");
             }
 
             if (glue_stretch(p) != 0)
             {
-              print_string(", stretch ");
+              prints(", stretch ");
               print_glue(glue_stretch(p), glue_order(p), "");
             }
 
             if (glue_shrink(p) != 0)
             {
-              print_string(", shrink ");
+              prints(", shrink ");
               print_glue(glue_shrink(p), glue_sign(p), "");
             }
           }
@@ -2575,39 +2286,32 @@ void show_node_list_(integer p)
 
             if ((g != 0.0) && (glue_sign(p) != 0))
             {
-              print_string(", glue set ");
+              prints(", glue set ");
 
               if (glue_sign(p) == shrinking)
-                print_string("- ");
+                prints("- ");
 
               if (fabs(g)> 20000.0)
               {
                 if (g > 0.0)
                   print_char('>');
                 else
-                  print_string("< -");
+                  prints("< -");
 
-                print_glue(20000 * 65536L, glue_order(p), "");
+                print_glue(20000 * unity, glue_order(p), "");
               }
               else
-                print_glue(round(65536L * g), glue_order(p), "");
+                print_glue(round(unity * g), glue_order(p), "");
             }
 
             if (shift_amount(p) != 0)
             {
-              print_string(", shifted ");
+              prints(", shifted ");
               print_scaled(shift_amount(p));
             }
           }
 
-          {
-            {
-              str_pool[pool_ptr] = 46;
-              incr(pool_ptr);
-            }
-            show_node_list(mem[p + 5].hh.rh);
-            decr(pool_ptr);
-          }
+          node_list_display(list_ptr(p));
         }
         break;
 
@@ -2617,7 +2321,7 @@ void show_node_list_(integer p)
           print_rule_dimen(height(p));
           print_char('+');
           print_rule_dimen(depth(p));
-          print_string(")x");
+          prints(")x");
           print_rule_dimen(width(p));
         }
         break;
@@ -2626,30 +2330,24 @@ void show_node_list_(integer p)
         {
           print_esc("insert");
           print_int(subtype(p));
-          print_string(", natural size ");
+          prints(", natural size ");
           print_scaled(height(p));
-          print_string("; split(");
+          prints("; split(");
           print_spec(split_top_ptr(p), "");
           print_char(',');
           print_scaled(depth(p));
-          print_string("); float cost ");
+          prints("); float cost ");
           print_int(float_cost(p));
-          {
-            {
-              str_pool[pool_ptr] = 46;
-              incr(pool_ptr);
-            }
-            show_node_list(mem[p + 4].hh.lh);
-            decr(pool_ptr);
-          }
+          node_list_display(ins_ptr(p));
         }
         break;
-      case 8:
+
+      case whatsit_node:
         switch (subtype(p))
         {
           case open_node:
             {
-              print_write_whatsit(1279, p);   /* debug # (-1 to exit): */
+              print_write_whatsit("openout", p);
               print_char('=');
               print_file_name(open_name(p), open_area(p), open_ext(p));
             }
@@ -2657,13 +2355,13 @@ void show_node_list_(integer p)
 
           case write_node:
             {
-              print_write_whatsit(591, p);  /* write */
+              print_write_whatsit("write", p);
               print_mark(write_tokens(p));
             }
             break;
 
           case close_node:
-            print_write_whatsit(1280, p); /* closeout */
+            print_write_whatsit("closeout", p);
             break;
 
           case special_node:
@@ -2677,7 +2375,7 @@ void show_node_list_(integer p)
             {
               print_esc("setlanguage");
               print_int(what_lang(p));
-              print_string(" (hyphenmin ");
+              prints(" (hyphenmin ");
               print_int(what_lhm(p));
               print_char(',');
               print_int(what_rhm(p));
@@ -2686,7 +2384,7 @@ void show_node_list_(integer p)
             break;
 
           default:
-            print_string("whatsit?");
+            prints("whatsit?");
             break;
         }
         break;
@@ -2701,17 +2399,9 @@ void show_node_list_(integer p)
           else if (subtype(p) == x_leaders)
             print_char('x');
 
-          print_string("leaders ");
-
+          prints("leaders ");
           print_spec(glue_ptr(p), "");
-          {
-            {
-              str_pool[pool_ptr] = 46;
-              incr(pool_ptr);
-            }
-            show_node_list(mem[p + 1].hh.rh);
-            decr(pool_ptr);
-          }
+          node_list_display(leader_ptr(p));
         }
         else
         {
@@ -2753,13 +2443,13 @@ void show_node_list_(integer p)
           print_scaled(width(p));
 
           if (subtype(p) == acc_kern)
-            print_string(" (for accent)");
+            prints(" (for accent)");
         }
         else
         {
           print_esc("mkern");
           print_scaled(width(p));
-          print_string("mu");
+          prints("mu");
         }
         break;
 
@@ -2768,13 +2458,13 @@ void show_node_list_(integer p)
           print_esc("math");
 
           if (subtype(p) == before)
-            print_string("on");
+            prints("on");
           else
-            print_string("off");
+            prints("off");
 
           if (width(p) != 0)
           {
-            print_string(", surrounded ");
+            prints(", surrounded ");
             print_scaled(width(p));
           }
         }
@@ -2783,7 +2473,7 @@ void show_node_list_(integer p)
       case ligature_node:
         {
           print_font_and_char(lig_char(p));
-          print_string("(ligature ");
+          prints("(ligature ");
 
           if (subtype(p) > 1)
             print_char('|');
@@ -2811,23 +2501,13 @@ void show_node_list_(integer p)
 
           if (replace_count(p) > 0)
           {
-            print_string(" replacing ");
+            prints(" replacing ");
             print_int(replace_count(p));
           }
 
-          {
-            {
-              str_pool[pool_ptr] = 46;
-              incr(pool_ptr);
-            }
-            show_node_list(mem[p + 1].hh.lh);
-            decr(pool_ptr);
-          }
-          {
-            str_pool[pool_ptr]= 124;
-            incr(pool_ptr);
-          }
-          show_node_list(mem[p + 1].hh.rh);
+          node_list_display(pre_break(p));
+          append_char('|');
+          show_node_list(post_break(p));
           decr(pool_ptr);
         }
         break;
@@ -2842,14 +2522,7 @@ void show_node_list_(integer p)
       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;
 
@@ -2985,21 +2658,21 @@ void show_node_list_(integer p)
           print_esc("fraction, thickness ");
 
           if (thickness(p) == 1073741824L)  /* 2^30 */
-            print_string("= default");
+            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-delimiter ");
+            prints(", left-delimiter ");
             print_delimiter(left_delimiter(p));
           }
 
           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-delimiter ");
+            prints(", right-delimiter ");
             print_delimiter(right_delimiter(p));
           }
 
@@ -3009,7 +2682,7 @@ void show_node_list_(integer p)
         break;
 
       default:
-        print_string("Unknown node type!");
+        prints("Unknown node type!");
         break;
     }
     p = link(p);