OSDN Git Service

bool to boolean.
[putex/putex.git] / src / texsourc / local.c
index 32326f0..38b1c40 100644 (file)
@@ -60,7 +60,7 @@ char log_line[MAXLINE];  // used also in tex9.c
 int mem_spec_flag     = 0;    /* non-zero if `-m=...' was used */ 
 int format_spec       = 0;    /* non-zero if a format specified on command line */
 int closed_already    = 0;    /* make sure we don't try this more than once */
-bool reorder_arg_flag = true; /* put command line flags/arguments first */
+boolean reorder_arg_flag = true; /* put command line flags/arguments first */
 
 /* Mapping from Windows ANSI to DOS code page 850 96/Jan/20 */
 /* Used in tex0.c with wintodos[c-128]                      */
@@ -532,9 +532,7 @@ int max_address     = 0;  /* maximum address seen in allocated memory */
 void show_maximums (FILE *output)
 {
   sprintf(log_line, "Max allocated %d --- max address %d\n", total_allocated, max_address);
-//  if (output != NULL) fputs(log_line, output); // log file
-//  else if (flag == 0) show_line(log_line, 0); // informative
-//  else if (flag == 1) show_line(log_line, 1); // error
+
   if (output == stderr)
     show_line(log_line, 1);
   else if (output == stdout)
@@ -583,17 +581,18 @@ void *ourrealloc (void *old, size_t new_size)
           mnew, new_size, old, old_size);
       show_line(log_line, 0);
     }
+
     return mnew;
   }
-/*  *********************************************************************** */
-/*  do this if you want to call the real realloc next -  */
+
+  /*  do this if you want to call the real realloc next -  */
   mnew = realloc (old, new_size);
 
   if (mnew != NULL)
     return mnew;
-/*  we are screwed typically if we ever drop through here - no more space */
-/*  *********************************************************************** */
-  mnew = malloc (new_size);          /* otherwise find new space */
+
+  /*  we are screwed typically if we ever drop through here - no more space */
+  mnew = malloc (new_size); /* otherwise find new space */
 
   if (mnew == NULL)
     return mnew;        /* if unable to allocate */
@@ -603,8 +602,9 @@ void *ourrealloc (void *old, size_t new_size)
   else
     overlap = new_size;
 
-  memcpy (mnew, old, overlap);         /* copy old data to new area */
-  free(old);                  /* free the old area */
+  memcpy (mnew, old, overlap); /* copy old data to new area */
+  free(old); /* free the old area */
+
   return mnew;
 }
 #endif
@@ -673,20 +673,12 @@ int allocate_tries (int trie_max)
 {
   int n, nl, no, nc;
 
-/*  if (trie_max > trie_size)
-  {
-    sprintf(log_line, "ERROR: invalid trie size (%d > %d)\n",
-      trie_max, trie_size);
-      show_line(log_line, 1);
-    exit (1);
-  } */ /* ??? removed 1993/dec/17 */
   if (trie_max > 1000000)
-    trie_max = 1000000; /* some sort of sanity limit */
+    trie_max = 1000000;
 
-  /*  important + 1 because original was halfword trie_trl[trie_size + 1] etc. */
-  nl = (trie_max + 1) * sizeof(halfword);    /* trie_trl[trie_size + 1] */
-  no = (trie_max + 1) * sizeof(halfword);    /* trie_tro[trie_size + 1] */
-  nc = (trie_max + 1) * sizeof(quarterword); /* trie_trc[trie_size + 1] */
+  nl = (trie_max + 1) * sizeof(halfword);
+  no = (trie_max + 1) * sizeof(halfword);
+  nc = (trie_max + 1) * sizeof(quarterword);
   n = nl + no + nc;
 
   if (trace_flag)
@@ -708,22 +700,21 @@ int allocate_tries (int trie_max)
     show_line(log_line, 0);
   }
 
-  update_statistics ((int) trie_trl, nl, 0);
-  update_statistics ((int) trie_tro, no, 0);
-  update_statistics ((int) trie_trc, nc, 0);
+  update_statistics((int) trie_trl, nl, 0);
+  update_statistics((int) trie_tro, no, 0);
+  update_statistics((int) trie_trc, nc, 0);
 
-  /*  sprintf(log_line, "trie_size %d trie_max %d\n", trie_size, trie_max); */ /* debug */
-  trie_size = trie_max;           /* BUG FIX 98/Jan/5 */
+  trie_size = trie_max;
 
   if (trace_flag)
-    probe_show();     /* 94/Mar/25 */
+    probe_show();
 
   return 0; // success
 }
 #endif
 
 #ifdef ALLOCATEHYPHEN
-bool prime (int); /* test function later in this file */
+boolean prime (int); /* test function later in this file */
 
 int current_prime = 0; /* remember in case reallocated later */
 
@@ -753,12 +744,8 @@ int realloc_hyphen (int hyphen_prime)
   if (trace_flag)
     trace_memory("hyphen exception", n);
 
-/*  initially hyph_word will be NULL so this acts like malloc */
-/*  hyph_word = (str_number *) malloc (nw); */
-  hyph_word = (str_number *) REALLOC (hyph_word, nw);  /* 94/Mar/24 */
-/*  initially hyph_list will be NULL so this acts like malloc */
-/*  hyph_list = (halfword *) malloc (nl); */
-  hyph_list = (halfword *) REALLOC (hyph_list, nl);   /* 94/Mar/24 */
+  hyph_word = (str_number *) REALLOC (hyph_word, nw);
+  hyph_list = (halfword *) REALLOC (hyph_list, nl);
 
   if (hyph_word == NULL || hyph_list == NULL)
   {
@@ -789,21 +776,21 @@ int realloc_hyphen (int hyphen_prime)
 
   if (current_prime != 0)
   {
-    update_statistics ((int) hyph_word, nw, (current_prime + 1) * sizeof(str_number));
-    update_statistics ((int) hyph_list, nl, (current_prime + 1) * sizeof(halfword));
+    update_statistics((int) hyph_word, nw, (current_prime + 1) * sizeof(str_number));
+    update_statistics((int) hyph_list, nl, (current_prime + 1) * sizeof(halfword));
   }
   else
   {
-    update_statistics ((int) hyph_word, nw, 0);
-    update_statistics ((int) hyph_list, nl, 0);
+    update_statistics((int) hyph_word, nw, 0);
+    update_statistics((int) hyph_list, nl, 0);
   }
 
   current_prime = hyphen_prime;
 
   if (trace_flag)
-    probe_show();     /* 94/Mar/25 */
+    probe_show();
 
-  return 0;               // success
+  return 0; // success
 }
 #endif
 
@@ -821,12 +808,6 @@ memory_word *allocate_main_memory (int size)
 {
   int n;
 
-/*  Using -i *and* pre-loading format */
-/*  in this case get called twice */
-/*  Get rid of initial blank memory again or use realloc ... */
-/*  Could we avoid this by detecting presence of & before allocating ? */
-/*  Also, if its already large enough, maybe we can avoid this ? */
-/*  don't bother if current_mem_size == mem_max - mem_start ? */
   if (main_memory != NULL)
   {
     if (trace_flag)
@@ -843,8 +824,6 @@ memory_word *allocate_main_memory (int size)
   if (trace_flag)
     trace_memory("main memory", n);
 
-/*  main_memory = (memory_word *) malloc (n); */  /* 94/March/24 */
-/*  normally main_memory == NULL here so acts like malloc ... */
   main_memory = (memory_word *) REALLOC (main_memory, n);
 
   if (main_memory == NULL)
@@ -1044,9 +1023,9 @@ memory_word *realloc_main (int losize, int hisize)
 int current_font_mem_size = 0;
 
 /* fmemoryword can be either halfword or memory_word */
-fmemoryword * realloc_font_info (int size)
+memory_word * realloc_font_info (int size)
 {
-  fmemoryword *newfontinfo = NULL;
+  memory_word *newfontinfo = NULL;
   int k, minsize;
   int newsize = 0;
   int n = 0;
@@ -1082,12 +1061,12 @@ fmemoryword * realloc_font_info (int size)
       newsize = font_mem_size; /* bump against limit */
 
 /*    important + 1 since fmemoryword font_info[font_mem_size + 1]  original */
-    n = (newsize + 1) * sizeof (fmemoryword);
+    n = (newsize + 1) * sizeof (memory_word);
 
     if (trace_flag)
       trace_memory("font_info", n);
 
-    newfontinfo = (fmemoryword *) REALLOC (font_info, n);
+    newfontinfo = (memory_word *) REALLOC (font_info, n);
 
     if (newfontinfo != NULL)
       break;   /* did we get it ? */
@@ -1112,7 +1091,7 @@ fmemoryword * realloc_font_info (int size)
     show_line(log_line, 0);
   }
 
-  update_statistics ((int) font_info, n, current_font_mem_size * sizeof(fmemoryword));
+  update_statistics ((int) font_info, n, current_font_mem_size * sizeof(memory_word));
   current_font_mem_size = newsize;
 
   if (trace_flag)
@@ -1286,7 +1265,7 @@ int allocate_ini (int size)
   nh = nr = nl = (size + 1) *  sizeof(trie_pointer);
   no = (size + 1) *  sizeof(trie_op_code);
   nc = (size + 1) *  sizeof(packed_ASCII_code);
-/*    nt = (size + 1) *  sizeof(bool); */
+/*    nt = (size + 1) *  sizeof(boolean); */
   nt = (size + 1) *  sizeof(char);
   n = nl + no + nc + nr + nh + nt;
 /*    n = (size + 1) * (sizeof(packed_ASCII_code) + sizeof(trie_op_code) +
@@ -1660,7 +1639,7 @@ ASCII_code *realloc_buffer (int size)
     show_line(log_line, 0);
   }
 
-  if (current_buf_size == buf_size)  /* arbitrary limit */
+  if (current_buf_size == buf_size)
   {
 /*    memory_error ("buffer", buf_size); */
 /*    exit (1); */
@@ -1682,7 +1661,7 @@ ASCII_code *realloc_buffer (int size)
     if (newsize > buf_size)
       newsize = buf_size;
 
-    n = (newsize + 1) * sizeof(ASCII_code);  /* buffer[buf_size + 1] */
+    n = (newsize + 1) * sizeof(ASCII_code);
 
     if (trace_flag)
       trace_memory("buffer", n);
@@ -1695,7 +1674,7 @@ ASCII_code *realloc_buffer (int size)
     if (current_buf_size == 0)
       break;   /* initial allocation must work */
 
-    size = size / 2;          /* else can retry smaller */
+    size = size / 2;
   }
 
   if (newbuffer == NULL)
@@ -1748,18 +1727,18 @@ int allocate_memory (void)
 /* they are all rather small, and typically don't need expansion */
 /* WE ASSUME THIS DOESN'T HAPPEN, SO WON'T BOTHER WITH UPDATESTATISTICS */
 #ifdef ALLOCATEHASH
-/*  n = 9767 * sizeof (twohalves);  *//* 60 kilo bytes */   
-/*  n = (hash_size + 267) * sizeof (twohalves); */  /* 60 kilo bytes */
-/*  n = (9767 + eqtb_extra) * sizeof (twohalves); */
+/*  n = 9767 * sizeof (two_halves);  *//* 60 kilo bytes */   
+/*  n = (hash_size + 267) * sizeof (two_halves); */  /* 60 kilo bytes */
+/*  n = (9767 + eqtb_extra) * sizeof (two_halves); */
 #ifdef SHORTHASH
-  n = (hash_size + 267 + eqtb_extra) * sizeof (htwohalves);   /* 95/Feb/19 */
-  zzzae = (htwohalves *) malloc (roundup(n));
+  n = (hash_size + 267 + eqtb_extra) * sizeof (htwo_halves);   /* 95/Feb/19 */
+  zzzae = (htwo_halves *) malloc (roundup(n));
 #else
-  n = (hash_size + 267 + eqtb_extra) * sizeof (twohalves);  /* 95/Feb/19 */
-  zzzae = (twohalves *) malloc (roundup(n));
+  n = (hash_size + 267 + eqtb_extra) * sizeof (two_halves);  /* 95/Feb/19 */
+  zzzae = (two_halves *) malloc (roundup(n));
 #endif
   if (trace_flag)  trace_memory("hash table", n);
-/*  zzzae = (twohalves *) malloc ((hash_size + 267) * sizeof (twohalves)); */
+/*  zzzae = (two_halves *) malloc ((hash_size + 267) * sizeof (two_halves)); */
   if (zzzae == NULL)
   {
     memory_error("hash table", n);
@@ -1899,7 +1878,7 @@ int allocate_memory (void)
   {
     trie_l = trie_r = trie_o = trie_hash = NULL; /* (trie_size + 1) * integer */
     trie_c = NULL;       /* (trie_size + 1) * char */
-    trie_taken = NULL;     /* (trie_size + 1) * bool */
+    trie_taken = NULL;     /* (trie_size + 1) * boolean */
   }
 #endif
 #ifdef PREALLOCHOLE
@@ -2068,7 +2047,7 @@ int free_memory (void)
   return 0;
 }
 
-bool prime (int x)
+boolean prime (int x)
 {
   int k;
   int sum = 1;    /* 1 + 3 + 5 + k = (k + 1) * (k + 1) / 4 */
@@ -2091,8 +2070,8 @@ bool prime (int x)
 }
 
 int quitflag  = 0;
-bool show_use = false;
-bool floating = false;
+boolean show_use = false;
+boolean floating = false;
 
 void complainarg (int c, char *s)
 {
@@ -2371,10 +2350,9 @@ void check_alloc_align (int flag)
 #endif
 }
 
-bool backwardflag       = false;              /* don't cripple all advanced features */
-bool shorten_file_name  = false;              /* don't shorten file names to 8+3 for DOS */
-bool usesourcedirectory = true;               /* use source file directory as local when WorkingDirectory is set */
-bool workingdirectory   = false;              /* if working directory set in ini */
+boolean backwardflag       = false;              /* don't cripple all advanced features */
+boolean shorten_file_name  = false;              /* don't shorten file names to 8+3 for DOS */
+boolean usesourcedirectory = true;               /* use source file directory as local when WorkingDirectory is set */             /* if working directory set in ini */
 
 /* cache to prevent allocating twice in a row */
 
@@ -2528,8 +2506,8 @@ int analyze_flag (int c, char *optarg)
       interaction = error_stop_mode; /* tex mode */
       break;
     case 'K':
-      backwardflag = true; /* 94/Jun/15 */
-      knuthify();         /* revert to `standard' Knuth TeX */
+      backwardflag = true;
+      knuthify(); /* revert to `standard' Knuth TeX */
       break;
     case 'L':
       c_style_flag = true; /* C style error msg 94/Mar/21 */
@@ -2537,12 +2515,6 @@ int analyze_flag (int c, char *optarg)
     case 'Z':
       show_tfm_flag = true; /* show TFM in log file 94/Jun/21 */
       break;
-    case 'c':
-      current_tfm = false; /* not look current dir for TFM */
-      break;
-    case 'C':
-      current_flag = false; /* not look current dir for files */
-      break;
     case 'M':
       show_missing = false; /* do not show missing 94/June/10 */
       break;
@@ -2564,9 +2536,6 @@ int analyze_flag (int c, char *optarg)
     case 'n':
       restrict_to_ascii = true; /* 0 - 127 1994/Jan/21 */
       break;
-    case '6':
-      workingdirectory = true; /* use source dir 98/Sep/29 */
-      break;
     case '7':
       usesourcedirectory = false; /* use working dir 98/Sep/29 */
       break;
@@ -2634,15 +2603,6 @@ int analyze_flag (int c, char *optarg)
     case 'Y':
       reorder_arg_flag = false; /* local */
       break;
-    case 'b':
-      test_dir_access = false; /* 94/Feb/10 */
-      break;
-    case 'D':
-      dir_method = false; /* 94/Feb/10 */
-      break;
-    case 'G':
-      file_method = false; /* 94/Feb/13 */
-      break;
 /* *********** following command line options take arguments **************  */
     case 'm':
       if (optarg == 0)
@@ -2878,7 +2838,6 @@ int init_commands (int ac, char **av)
   open_trace_flag   = false;
   trace_flag        = false;
   verbose_flag      = false;
-  heap_flag         = false;
   restrict_to_ascii = false;
   show_in_hex       = false; /* default is not to show as hex code ^^ 00/Jun/18 */
   show_in_dos       = false; /* default is not to translate to DOS 850 */ 
@@ -2892,11 +2851,6 @@ int init_commands (int ac, char **av)
   civilize_flag     = true;
   show_numeric      = true;
   show_missing      = true;
-  current_flag      = true;
-  current_tfm       = true;  /* search for TFMs in current dir as well */
-  test_dir_access   = true;  /* test if readable item is perhaps a sub-dir */
-  dir_method        = true;  /* in dir_p: _findfirst instead of use fopen (nul) */
-  file_method       = true;  /* use file_p (_findfirst) not readable (access) */
   c_style_flag      = false; /* use c-style error output */
   show_fmt_flag     = true;  /* show format file in log */
   show_tfm_flag     = false; /* don't show metric file in log */
@@ -2911,17 +2865,18 @@ int init_commands (int ac, char **av)
   allow_quoted_names    = true;  /* allow quoted names with spaces 98/Mar/15 */
   show_cs_names         = false; /* don't show csnames on start 98/Mar/31 */
   knuth_flag            = false; /* allow extensions to TeX */
-  cache_file_flag       = true;  /* default is to cache full file names 96/Nov/16 */
   full_file_name_flag   = true;  /* new default 2000 June 18 */
   save_strings_flag     = true;
   errout                = stdout; /* as opposed to stderr say --- used ??? */
   abort_flag            = 0;      // not yet hooked up ???
   err_level             = 0;      // not yet hooked up ???
   new_hyphen_prime      = 0;
+
 #ifdef VARIABLETRIESIZE
 /*  trie_size = default_trie_size; */
   trie_size = 0;
 #endif
+
   mem_extra_high = 0;
   mem_extra_low  = 0;
   mem_initex     = 0;
@@ -2947,11 +2902,6 @@ int init_commands (int ac, char **av)
     show_line(log_line, 0);
   }
 */
-/*  if we aren't including current directory in any directory lists */
-/*  then makes no sense to avoid them separately for TFM files ... */
-/*  (that is, the ./ is already omitted from the dir list in that case */
-  if (!current_flag && !current_tfm)
-    current_tfm = true;
 
   return 0;
 }
@@ -3197,7 +3147,7 @@ void deslash_all (int ac, char **av)
           if (trace_flag || debug_flag)
           {
             sprintf(log_line, "deslash: k %d argv[k] %s (argc %d)\n",
-              optind+1, av[optind+1], ac);
+              optind + 1, av[optind + 1], ac);
             show_line(log_line, 0);
           }
 
@@ -3205,7 +3155,7 @@ void deslash_all (int ac, char **av)
         }
 
         if (pseudo_tilde != 0 || pseudo_space != 0)
-          hidetwiddle (av[optind+1]);
+          hidetwiddle (av[optind + 1]);
       }
     }         
   }
@@ -3222,54 +3172,51 @@ void deslash_all (int ac, char **av)
 
 int main_init (int ac, char **av)
 {
-  char initbuffer[PATH_MAX];
   int k;
 
   kpse_set_program_name(av[0], NULL);
+  xputenv("engine", "yandytex");
 
-  if (sizeof(memory_word) != sizeof(integer) * 2)
+  if (sizeof(memory_word) != sizeof(halfword) * 2)
   {
     sprintf(log_line, "ERROR: Bad word size %d!\n", sizeof(memory_word));
     show_line(log_line, 1);
   }
 
   start_time = clock();
-  main_time = start_time;
-
-  initbuffer[0] = '\0';         /* paranoia 94/Apr/10 */
+  main_time  = start_time;
 
-/*  reset all allocatable memory pointers to NULL - in case we drop out */
+/* reset all allocatable memory pointers to NULL - in case we drop out */
   main_memory = NULL;
-  font_info = NULL;
-  str_pool = NULL;
-  str_start = NULL;
+  font_info   = NULL;
+  str_pool    = NULL;
+  str_start   = NULL;
 
 #ifdef ALLOCATESAVESTACK
   save_stack = NULL; 
 #endif
 
 #ifdef ALLOCATEBUFFER
-  buffer = NULL;
+  buffer           = NULL;
   current_buf_size = 0;
-  buffer = realloc_buffer (initial_buf_size);
+  buffer           = realloc_buffer (initial_buf_size);
 #endif
 
-  hyph_list = NULL;
-  hyph_word = NULL;
+  hyph_list  = NULL;
+  hyph_word  = NULL;
   trie_taken = NULL;
-  trie_hash = NULL;
-  trie_r = NULL;
-  trie_c = NULL;
-  trie_o = NULL;
-  trie_l = NULL;
-  trie_trc = NULL;
-  trie_tro = NULL;
-  trie_trl = NULL;
+  trie_hash  = NULL;
+  trie_r     = NULL;
+  trie_c     = NULL;
+  trie_o     = NULL;
+  trie_l     = NULL;
+  trie_trc   = NULL;
+  trie_tro   = NULL;
+  trie_trl   = NULL;
 
   log_opened = false;       /* so can tell whether opened */
   interaction = -1;         /* default state => 3 */
   missing_characters = 0;   /* none yet! */
-  workingdirectory = false; /* set from dviwindo.ini & command line */
   font_dimen_zero = true;   /* \fontdimen0 for checksum 98/Oct/5 */
   ignore_frozen = false;    /* default is not to ignore 98/Oct/5 */
   suppress_f_ligs = false;  /* default is not to ignore f-ligs */
@@ -3300,22 +3247,19 @@ int main_init (int ac, char **av)
   underfull_hbox    = 0;
   overfull_vbox     = 0;
   underfull_vbox    = 0;
-
-  closed_already = 0;
+  closed_already    = 0;
 
   if (trace_flag)
     show_line("Entering init (local)\n", 0);
 
-  probe_memory();             /* show top address */
-  ini_max_address = max_address;       /* initial max address */
+  probe_memory(); /* show top address */
+  ini_max_address = max_address; /* initial max address */
 
   if (trace_flag)
     show_maximums(stdout);
 
   initial_memory();
-
-  deslash_all(ac, av);    /* deslash and note if format specified */
-
+  deslash_all(ac, av); /* deslash and note if format specified */
   no_interrupts = 0;
 
   if (format_spec && mem_spec_flag)
@@ -3402,7 +3346,7 @@ int endit (int flag)
     if (total_pages > 0)
     {
       show_inter_val ((finish_time - main_time) / total_pages);
-      show_line(" sec per page", 0);
+      show_line(" sec per page.", 0);
     }
 
     show_line("\n", 0);
@@ -3417,7 +3361,7 @@ void print_cs_name (FILE *output, int h)
 
   memset(log_line, 0, sizeof(log_line));
 
-  textof = hash[h].v.RH;
+  textof = hash[h].rh;
 
   if (textof == 0)
     return;
@@ -3450,8 +3394,8 @@ int compare_cs (const void *cp1, const void *cp2)
 
   c1 = *(int *)cp1;
   c2 = *(int *)cp2;
-  textof1 = hash[c1].v.RH;
-  textof2 = hash[c2].v.RH;
+  textof1 = hash[c1].rh;
+  textof2 = hash[c2].rh;
   l1 = length(textof1); 
   l2 = length(textof2); 
   k1 = str_start[textof1]; 
@@ -3494,7 +3438,7 @@ void print_cs_names (FILE *output, int pass)
     if (pass == 1 && csused[h])
       continue;
 
-    if (hash[h].v.RH != 0)
+    if (hash[h].rh != 0)
     {
       if (pass == 0)
         csused[h] = 1;
@@ -3532,7 +3476,7 @@ void print_cs_names (FILE *output, int pass)
       if (pass == 1 && csused[h])
         continue;
 
-      if (hash[h].v.RH != 0)
+      if (hash[h].rh != 0)
         cnumtable[ccount++] = h;
     }