OSDN Git Service

removed unused flags.
[putex/putex.git] / src / texsourc / tex4.c
index 3c0ec8e..37cfea4 100644 (file)
@@ -1,28 +1,24 @@
-#ifdef _WINDOWS
-  #define NOCOMM
-  #define NOSOUND
-  #define NODRIVERS
-  #define STRICT
-  #pragma warning(disable:4115) // kill rpcasync.h complaint
-  #include <windows.h>
-  #define MYLIBAPI __declspec(dllexport)
-#endif
+/* Copyright 2014 Clerk Ma
 
-#include "texwin.h"
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 2 of the License, or
+   (at your option) any later version.
 
-#pragma warning(disable:4996)
-#pragma warning(disable:4131) // old style declarator
-#pragma warning(disable:4135) // conversion between different integral types 
-#pragma warning(disable:4127) // conditional expression is constant
+   This program is distributed in the hope that it will be useful, but
+   WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   General Public License for more details.
 
-#include <setjmp.h>
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, write to the Free Software
+   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+   02110-1301 USA.  */
 
 #define EXTERN extern
 
 #include "texd.h"
 
-#pragma warning(disable:4244)       /* 96/Jan/10 */
-
 /* sec 0581 */
 void char_warning_(internal_font_number f, eight_bits c)
 { 
@@ -89,7 +85,7 @@ halfword new_character_(internal_font_number f, eight_bits c)
 
   if (font_bc[f] <= c)
     if (font_ec[f] >= c)
-      if ((font_info[char_base[f] + c].qqqq.b0 > 0))
+      if (char_exists(char_info(f, c)))
       {
         p = get_avail();
         font(p) = f;
@@ -97,10 +93,9 @@ halfword new_character_(internal_font_number f, eight_bits c)
         return p;
       }
 
-  char_warning(f, c); /* char_warning(f,c); l.11283 */
+  char_warning(f, c);
   return 0;
 }
-/* following needs access to dvi_buf=zdvibuf see coerce.h */
 /* sec 0598 */
 void dvi_swap (void)
 { 
@@ -126,33 +121,25 @@ void dvi_swap (void)
 
   dvi_gone = dvi_gone + half_buf;
 }
-/* following needs access to dvi_buf=zdvibuf see coerce.h */
 /* attempt at speeding up bkph - is compiler smart ? */
 /* sec 0600 */
 void dvi_four_(integer x)
 { 
   if (x >= 0)
-    // dvi_out(x % 16777216L);
-    dvi_out((x >> 24));
+    dvi_out(x / 0100000000); // dvi_out((x >> 24));
   else
   {
-    x = x + 1073741824L;    /* 2^30 40000000 hex */
-    x = x + 1073741824L;
-    //dvi_out((x / 16777216L) + 128);
-    dvi_out((x >> 24) + 128);
+    x = x + 010000000000;
+    x = x + 010000000000;
+    dvi_out((x / 0100000000) + 128); // dvi_out((x >> 24) + 128);
   }
-/*  x = x % 16777216L;  */  /* % 2^24 */
-  x = x & 16777215L;
-  //dvi_out(x / 65536L);
-  dvi_out((x >> 16));
-/*  x = x % 65536L;  */ /* % 2^16 */
-  x = x & 65535L;
-  //dvi_out(x / 256);
-  dvi_out((x >> 8));
-  //dvi_out(x % 256);
-  dvi_out(x & 255);
+
+  x = x % 0100000000; // x = x & 16777215L;
+  dvi_out(x / 0200000); // dvi_out((x >> 16));
+  x = x % 0200000; // x = x & 65535L;
+  dvi_out(x / 0400); // dvi_out((x >> 8));
+  dvi_out(x % 0400); // dvi_out(x & 255);
 }
-/* following needs access to dvi_buf=zdvibuf see coerce.h */
 /* sec 0601 */
 void zdvipop(integer l)
 {
@@ -161,7 +148,6 @@ void zdvipop(integer l)
   else
     dvi_out(142);
 }
-/* following needs access to dvi_buf=zdvibuf see coerce.h */
 /* sec 0602 */
 void dvi_font_def_(internal_font_number f)
 {
@@ -183,8 +169,7 @@ void dvi_font_def_(internal_font_number f)
   dvi_out(fnt_def1);
   dvi_out(f - 1);
 #endif
-/* *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** */
-/* spit out the font checksum now */
+
   dvi_out(font_check[f].b0);
   dvi_out(font_check[f].b1);
   dvi_out(font_check[f].b2);
@@ -200,7 +185,6 @@ void dvi_font_def_(internal_font_number f)
   for (k = str_start[font_name[f]]; k <= str_start[font_name[f] + 1] - 1; k++)
     dvi_out(str_pool[k]);
 }
-/* following needs access to dvi_buf=zdvibuf see coerce.h */
 /* sec 0607 */
 void zmovement(scaled w, eight_bits o)
 {
@@ -409,6 +393,7 @@ void prune_movements_(integer l)
     down_ptr = link(p);
     free_node(p, movement_node_size);
   }
+
 lab30:
   while (right_ptr != 0)
   {
@@ -420,49 +405,30 @@ lab30:
     free_node(p, movement_node_size);
   }
 }
-/* following needs access to dvi_buf=zdvibuf see coerce.h */
 /* sec 1368 */
-void special_out_(halfword p)
+void special_out_(pointer p)
 {
   char old_setting;
   pool_pointer k;
 
-  if (cur_h != dvi_h)
-  {
-    movement(cur_h - dvi_h, right1);
-    dvi_h = cur_h;
-  }
-
-  if (cur_v != dvi_v)
-  {
-    movement(cur_v - dvi_v, down1);
-    dvi_v = cur_v;
-  }
-
+  synch_h();
+  synch_v();
   old_setting = selector;
   selector = new_string;
 
-/* *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** */
-/* About output \special{...} make some space in string pool 97/Mar/9 */
 #ifdef ALLOCATESTRING
   if (pool_ptr + 32000 > current_pool_size)
     str_pool = realloc_str_pool (increment_pool_size);
-/* We don't bother to check whether this worked - will catch later */
-#endif
-/* Potential problem here if current_pool_size is not much more than pool_ptr! */
-/* Fixed 97/Mar/9 in version 2.0.3 */
-/* *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** */
-#ifdef ALLOCATESTRING
+
   show_token_list(link(write_tokens(p)), 0, 10000000L);
-/*  Above is safe, since print/print_char/print_esc will extend string space */
 #else
-/* *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** */
   show_token_list(link(write_tokens(p)), 0, pool_size - pool_ptr);
 #endif
+
   selector = old_setting;
   str_room(1);
 
-  if (cur_length < 256)  /* can use xxx1 ? */
+  if (cur_length < 256)
   {
     dvi_out(xxx1);
     dvi_out(cur_length);
@@ -473,54 +439,13 @@ void special_out_(halfword p)
     dvi_four(cur_length); 
   } 
 
-#ifdef IGNORED
-/*  debugging code for \special{src: ... } 98/Nov/11 */
-  {
-    int k = str_start[str_ptr];
-    int kend = pool_ptr;
-    /* \special{src: ... } */
-    if (kend > k + 4)
-    {
-      if (str_pool [k] == 's' && str_pool [k + 1] == 'r' && str_pool [k + 2] == 'c' && str_pool [k + 3] == ':')
-      {
-        show_char('\n');
-        s = log_line;
-
-        while (k < kend)
-        {
-          *s++ = str_pool[k++];
-        }
-
-        *s++ = ' ';
-        *s++ = '\0';
-        show_line(log_line, 0)
-#ifndef _WINDOWS
-        fflush(stdout);
-#endif
-        if (cur_input.name_field > 17) /* redundant ? */
-        {
-          print(cur_input.name_field);          
-          print_char('(');
-          print_int(line);      /* line number */
-          print_char(')');
-          print_char(' ');
-          print_char(':');
-        }
-#ifndef _WINDOWS
-        fflush(stdout);
-#endif
-      }
-    }
-  }
-#endif
   for (k = str_start[str_ptr]; k <= pool_ptr - 1; k++)
     dvi_out(str_pool[k]);
 
   pool_ptr = str_start[str_ptr];
 }
-/* noew returns -1 if it fails */
 /* sec 1370 */
-void write_out_(halfword p)
+void write_out_(pointer p)
 {
   char old_setting;
 /*  integer oldmode;  */
@@ -556,7 +481,7 @@ void write_out_(halfword p)
       {
         get_token();
       }
-    while(!(cur_tok == end_write_token)); /*1996/Jan/10*/
+    while(!(cur_tok == end_write_token));
   }
 
   mode = oldmode;
@@ -580,7 +505,7 @@ void write_out_(halfword p)
   selector = old_setting;
 }
 /* sec 1373 */
-void out_what_(halfword p)
+void out_what_(pointer p)
 {
 /*  small_number j;  */
   int j;            /* 1995/Jan/7 */
@@ -643,7 +568,6 @@ void out_what_(halfword p)
       break;
   }
 }
-/* following needs access to dvi_buf=zdvibuf see coerce.h */
 /* sec 0619 */
 void hlist_out (void)
 {
@@ -660,7 +584,7 @@ void hlist_out (void)
   halfword leader_box;
   scaled leader_wd;
   scaled lx;
-  bool outer_doing_leaders;
+  boolean outer_doing_leaders;
   scaled edge;
   real glue_temp;
   real cur_glue;
@@ -688,17 +612,8 @@ void hlist_out (void)
 lab21:
     if (is_char_node(p))
     {
-      if (cur_h != dvi_h)
-      {
-        movement(cur_h - dvi_h, right1);
-        dvi_h = cur_h;
-      }
-
-      if (cur_v != dvi_v)
-      {
-        movement(cur_v - dvi_v, down1);
-        dvi_v = cur_v;
-      }
+      synch_h();
+      synch_v();
 
       do
         {
@@ -714,8 +629,7 @@ lab21:
             }
 
             if (f <= 64 + font_base)
-              dvi_out(f - font_base - 1 + fnt_num_0); /* fnt_num_0 --- fnt_num_63 */
-/* *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** */
+              dvi_out(f - font_base - 1 + fnt_num_0);
 #ifdef INCREASEFONTS
             /* if we allow greater than 256 fonts */
             else if (f <= 256)
@@ -754,6 +668,7 @@ lab21:
           p = link(p);
         }
       while(!(!(p >= hi_mem_min)));
+
       dvi_h = cur_h;
   }
   else
@@ -879,21 +794,9 @@ lab21:
               while (cur_h + leader_wd <= edge)
               {
                 cur_v = base_line + shift_amount(leader_box);
-
-                if (cur_v != dvi_v)
-                {
-                  movement(cur_v - dvi_v, down1);
-                  dvi_v = cur_v;
-                }
-
+                synch_v();
                 save_v = dvi_v;
-
-                if (cur_h != dvi_h)
-                {
-                  movement(cur_h - dvi_h, right1);
-                  dvi_h = cur_h;
-                }
-
+                synch_h();
                 save_h = dvi_h;
                 temp_ptr = leader_box;
                 outer_doing_leaders = doing_leaders;
@@ -950,24 +853,12 @@ lab14:
 
     if ((rule_ht > 0) && (rule_wd > 0))
     {
-      if (cur_h != dvi_h)
-      {
-        movement(cur_h - dvi_h, right1);
-        dvi_h = cur_h;
-      }
-
+      synch_h();
       cur_v = base_line + rule_dp;
-
-      if (cur_v != dvi_v)
-      {
-        movement(cur_v - dvi_v, down1);
-        dvi_v = cur_v;
-      }
-
+      synch_v();
       dvi_out(set_rule);
       dvi_four(rule_ht);
       dvi_four(rule_wd);
-
       cur_v = base_line;
       dvi_h = dvi_h + rule_wd;
     }
@@ -984,7 +875,6 @@ lab15:
 
   decr(cur_s);
 }
-/* following needs access to dvi_buf=zdvibuf see coerce.h */
 /* sec 0629 */
 void vlist_out (void)
 {
@@ -1001,7 +891,7 @@ void vlist_out (void)
   halfword leader_box;
   scaled leader_ht;
   scaled lx;
-  bool outer_doing_leaders;
+  boolean outer_doing_leaders;
   scaled edge;
   real glue_temp;
   real cur_glue;
@@ -1044,13 +934,7 @@ void vlist_out (void)
           else
           {
             cur_v = cur_v + height(p);
-
-            if (cur_v != dvi_v)
-            {
-              movement(cur_v - dvi_v, down1);
-              dvi_v = cur_v;
-            }
-
+            synch_v();
             save_h = dvi_h;
             save_v = dvi_v;
             cur_h = left_edge + shift_amount(p);
@@ -1155,7 +1039,7 @@ void vlist_out (void)
                     cur_v = cur_v + (lr / 2);
                   else
                   {
-                    lx =(2 * lr + lq + 1) / (2 * lq + 2);
+                    lx = (2 * lr + lq + 1) / (2 * lq + 2);
                     cur_v = cur_v + ((lr - (lq - 1) * lx) / 2);
                   }
                 }
@@ -1163,22 +1047,10 @@ void vlist_out (void)
                 while (cur_v + leader_ht <= edge)
                 {
                   cur_h = left_edge + shift_amount(leader_box);
-
-                  if (cur_h != dvi_h)
-                  {
-                    movement(cur_h - dvi_h, right1);
-                    dvi_h = cur_h;
-                  }
-
+                  synch_h();
                   save_h = dvi_h;
                   cur_v = cur_v + height(leader_box);
-
-                  if (cur_v != dvi_v)
-                  {
-                    movement(cur_v - dvi_v, down1);
-                    dvi_v = cur_v;
-                  }
-
+                  synch_v();
                   save_v = dvi_v;
                   temp_ptr = leader_box;
                   outer_doing_leaders = doing_leaders;
@@ -1222,22 +1094,13 @@ lab14:
 
       if ((rule_ht > 0) && (rule_wd > 0))
       {
-        if (cur_h != dvi_h)
-        {
-          movement(cur_h - dvi_h, right1);
-          dvi_h = cur_h;
-        }
-
-        if (cur_v != dvi_v)
-        {
-          movement(cur_v - dvi_v, down1);
-          dvi_v = cur_v;
-        }
-
+        synch_h();
+        synch_v();
         dvi_out(put_rule);
         dvi_four(rule_ht);
         dvi_four(rule_wd);
       }
+
       goto lab15;
 lab13:
       cur_v = cur_v + rule_ht;
@@ -1245,6 +1108,7 @@ lab13:
 lab15:
     p = link(p);
   }
+
   prune_movements(save_loc);
 
   if (cur_s > 0)
@@ -1252,18 +1116,8 @@ lab15:
 
   decr(cur_s);
 }
-/****************HPDF******************/
-/*
-void error_handler (HPDF_STATUS error_no, HPDF_STATUS detail_no, void * user_data)
-{
-    printf ("ERROR: error_no=%04X, detail_no=%u\n", (HPDF_UINT)error_no, (HPDF_UINT)detail_no);
-}
-*/
-/****************HPDF******************/
 /* sec 0638 */
-/* following needs access to dvi_buf=zdvibuf see coerce.h */
-/* sec 0638 */
-void ship_out_(halfword p)
+void dvi_ship_out_(halfword p)
 {
   integer page_loc;
   char j, k;
@@ -1324,6 +1178,7 @@ void ship_out_(halfword p)
       show_box(p);
       end_diagnostic(true);
     }
+
     goto lab30;
   }
 
@@ -1331,7 +1186,7 @@ void ship_out_(halfword p)
     max_v = height(p) + depth(p) + v_offset;
 
   if (width(p) + h_offset > max_h)
-    max_h = height(p) + h_offset;
+    max_h = width(p) + h_offset;
 
   dvi_h = 0;
   dvi_v = 0;
@@ -1397,7 +1252,7 @@ void ship_out_(halfword p)
   else
     hlist_out();
 
-  dvi_out(eop);
+  dvi_out(eop); // do not need a endpage in haru.
   incr(total_pages);
   cur_s = -1;
 lab30:;
@@ -1436,8 +1291,21 @@ lab30:;
   }
 #endif /* STAT */
 }
+void ship_out_(halfword p)
+{
+  switch (shipout_flag)
+  {
+    case out_pdf_flag:
+      pdf_ship_out(p);
+      break;
+    case out_dvi_flag:
+    case out_xdv_flag:
+      dvi_ship_out_(p);
+      break;
+  }
+}
 /* sec 0645 */
-void scan_spec_(group_code c, bool three_codes)
+void scan_spec_(group_code c, boolean three_codes)
 {
   integer s;
   char spec_code;
@@ -1457,6 +1325,7 @@ void scan_spec_(group_code c, bool three_codes)
   }
 
   scan_dimen(false, false, false);
+
 lab40:
   if (three_codes)
   {
@@ -1481,7 +1350,7 @@ halfword hpack_(halfword p, scaled w, small_number m)
 /*  glue_ord o;  */
   int o;              /* 95/Jan/7 */
   internal_font_number f;
-  ffourquarters i;
+  four_quarters i;
   eight_bits hd;
 
   last_badness = 0;
@@ -1561,7 +1430,7 @@ lab21:
             {
               link(adjust_tail) = adjust_ptr(p);
 
-              while (link(adjust_tail)!= 0)
+              while (link(adjust_tail) != 0)
                 adjust_tail = link(adjust_tail);
 
               p = link(p);
@@ -2122,7 +1991,7 @@ halfword overbar_(halfword b, scaled k, scaled t)
 /* sec 0709 */
 halfword char_box_(internal_font_number f, quarterword c)
 {
-  ffourquarters q;
+  four_quarters q;
   eight_bits hd;
   halfword b, p;
 
@@ -2150,9 +2019,9 @@ void stack_into_box_(halfword b, internal_font_number f, quarterword c)
   height(b) = height(p);
 }
 /* sec 0712 */
-scaled height_plus_depth_(internal_font_number f, fquarterword c)
+scaled height_plus_depth_(internal_font_number f, quarterword c)
 {
-  ffourquarters q;
+  four_quarters q;
   eight_bits hd;
 
   q = char_info(f, c);
@@ -2168,12 +2037,12 @@ halfword var_delimiter_(halfword d, small_number s, scaled v)
   integer m, n;
   scaled u;
   scaled w;
-  ffourquarters q;
-  ffourquarters r;
+  four_quarters q;
+  four_quarters r;
   eight_bits hd;
 /*  small_number z;  */
   int z;                  /* 95/Jan/7 */
-/*  bool large_attempt;  */
+/*  boolean large_attempt;  */
   int large_attempt;           /* 95/Jan/7 */
 
   f = null_font;