OSDN Git Service

memcpy and memmove.
authormaqiyuan <maqiyuan@users.sourceforge.jp>
Tue, 15 Apr 2014 17:34:11 +0000 (01:34 +0800)
committermaqiyuan <maqiyuan@users.sourceforge.jp>
Tue, 15 Apr 2014 17:34:11 +0000 (01:34 +0800)
src/texsourc/itex.c
src/texsourc/local.c
src/texsourc/tex3.c
src/texsourc/tex4.c
src/texsourc/yandy_pool.c

index 46ddac0..4e48eb7 100644 (file)
@@ -2535,9 +2535,10 @@ lab1:     /* get here directly if ready_already already set ... */
       selector = no_print;
     else
       selector = term_only;
-     if ((cur_input.loc_field < cur_input.limit_field) &&
-       (eqtb[(hash_size + 1883) + buffer[cur_input.loc_field]].hh.v.RH != 0))
-       start_input();
+
+    if ((cur_input.loc_field < cur_input.limit_field) &&
+      (eqtb[(hash_size + 1883) + buffer[cur_input.loc_field]].hh.v.RH != 0))
+      start_input();
   }
 
 /*  show font TFMs frozen into format file */
@@ -3033,12 +3034,14 @@ lab30:
   }
 #endif
   g = load_pool_strings(pool_size - stringvacancies);
+
   if (g == 0)
   {
     fprintf(stdout , "%s\n",  "! You have to increase POOLSIZE." );
     Result = false;
     return Result;
   }
+
   Result = true;
   return Result;
 }
@@ -3086,31 +3089,30 @@ void sort_avail (void)
 /*****************APTEX********************/
 str_number make_string_pool (char *s)
 {
-  while (*s != '\0') {
-    append_char(*s);
-    incr(s);
-  }
+  int slen = strlen(s);
+  memcpy(str_pool + pool_ptr, s, slen);
+  pool_ptr += slen;
   return (make_string());
 }
-void primitive_s (char * s, quarterword c, halfword o)
+void primitive_s (char * str, quarterword c, halfword o)
 {
   pool_pointer k, l;
   small_number j;
-  str_number prim_str;
+  str_number s;
 
-  if (s[1] = '\0')
-    cur_val = s[0] + single_base;
+  s = make_string_pool(str);
+
+  if (s < 256)
+    cur_val = str[0] + single_base;
   else
   {
-    prim_str = make_string_pool(s);
-    k = str_start[prim_str];
-    l = str_start[prim_str + 1] - k;
-    printf("*************************: %d---%d", str_start[prim_str], str_start[prim_str+1]);
+    k = str_start[s];
+    l = str_start[s + 1] - k;
     for (j = 0; j < l; incr(j))
       buffer[j] = str_pool[k + j];
     cur_val = id_lookup(0, l);
     flush_string();
-    hash[cur_val].v.RH = prim_str;
+    hash[cur_val].v.RH = s;
   }
   eq_level(cur_val) = level_one;
   eq_type(cur_val) = c;
@@ -3947,7 +3949,7 @@ lab32:
 void init_prim (void)
 {
   no_new_control_sequence = false;
-  //primitive_s("lineskip", assign_glue, glue_base + line_skip_code);
+  //primitive(make_string_pool("lineskip"), assign_glue, glue_base + line_skip_code);
   primitive(373, assign_glue, glue_base + line_skip_code);          /* lineskip */
   primitive(374, assign_glue, glue_base + baseline_skip_code);      /* baselineskip */
   primitive(375, assign_glue, glue_base + par_skip_code);           /* parskip */
index 87cfbeb..a3a844e 100644 (file)
@@ -3682,8 +3682,10 @@ int init (int ac, char **av)
 
   probe_memory();             /* show top address */
   ini_max_address = max_address;       /* initial max address */
+
   if (trace_flag)
     show_maximums(stdout);
+
 #ifdef HEAPWALK
   if (heap_flag)
     (void) heap_dump(stdout, 1);
@@ -3707,6 +3709,7 @@ int init (int ac, char **av)
 
 /*   following is more or less useless since most all things not yet alloc */
    check_alloc_align(trace_flag);    /* sanity check 1994/Jan/8 */
+
 #ifdef HEAPSHOW
    if (trace_flag) showaddresses();  /* debugging only 1996/Jan/20 */
 #endif
@@ -3796,11 +3799,9 @@ int endit (int flag)
 /*    show_inter_val(main_time, finish_time); */
     show_inter_val(finish_time - main_time);
     show_line(" processing) ", 0);
+
     if (total_pages > 0)
     {
-/*      msec = (finish_time - main_time) * 1000 / (CLK_TCK * total_pages); */
-/*      sprintf(log_line, " %d.%d sec per page", msec / 1000, msec % 1000); */
-/*      sprintf(log_line, " %d.%03d sec per page", msec / 1000, msec % 1000); */
       show_inter_val ((finish_time - main_time) / total_pages);
       show_line(" sec per page", 0);
     }
@@ -3816,57 +3817,37 @@ int endit (int flag)
 
 /* addition 98/Mar/31 print_csnames Frank Mittelbach */
 
-int textcolumn;
-
 #define MAXCOLUMN 78
 
 void print_cs_name (FILE *output, int h)
 {
   int c, textof, n;
-  char *s;
-  
+
+  memset(log_line, 0, sizeof(log_line));
+
   textof = hash[h].v.RH;
 
   if (textof == 0)
-    return;  /* ignore if text() == 0 */
+    return;
 
+  c = sprintf(log_line, "(%d), ", h);
   n = length(textof);
 
-  if (textcolumn != 0)
-  {
-    sprintf(log_line, ", ");
-    if (output != NULL)
-      fprintf(output, log_line);
-    else
-      show_line(log_line, 0);
-    textcolumn += 2;
-  }
+  memmove(log_line + c, str_pool + str_start[textof], n);
+  memmove(log_line + c + n, "\n", 2);
 
-  if (textcolumn + n + 2 >= MAXCOLUMN)
-  {
-    sprintf(log_line, "\n");
-    if (output == stderr)
-      show_line(log_line, 1);
-    else
-      if (output == stdout)
-        show_line(log_line, 0);
-      else
-        fputs(log_line, output);
-    textcolumn=0;
-  }
-  s = log_line;
-  for (c = str_start[textof]; c < str_start[textof+1]; c++)
-  {
-    *s++ = str_pool[c];
-  }
   if (output == stderr)
+  {
     show_line(log_line, 1);
+  }
   else
+  {
     if (output == stdout)
       show_line(log_line, 0);
     else
       fprintf(output, log_line);
-  textcolumn += n;
+  }
+
 }
 
 int compare_strn (int, int, int, int); /* in tex9.c */
@@ -3893,87 +3874,106 @@ char *csused=NULL;
 
 /* Allocate table of indeces to allow sorting on csname */
 /* Allocate flags to remember which ones already listed at start */
-
+/* pass = 0 --> fmt */
+/* pass = 1 --> after */
 void print_cs_names (FILE *output, int pass)
 {
   int h, k, ccount, repeatflag;
   int *cnumtable;
-  int nfcs = hash_base + hash_size + hash_extra;  /* frozen_control_sequence */
+  int nfcs = frozen_control_sequence;
 
   if (pass == 0 && csused == NULL)
   {
     csused = (char *) malloc (nfcs);
 
     if (csused == NULL)
-      return; 
+      return;
+
 #ifdef USEMEMSET
-    memset(csused, 0, nfcs); 
+    memset(csused, 0, nfcs);
 #else
     for (h = 0; h < (hash_size + 780); h++)
       csused[h] = 0;
 #endif
   }
 
-  ccount=0;
+  ccount = 0;
 
   for (h = hash_base + 1; h < nfcs; h++)
   {
     if (pass == 1 && csused[h])
       continue;
+
     if (hash[h].v.RH != 0)
     {
       if (pass == 0)
         csused[h] = 1;
+
       ccount++;
     }
   }
 
-  sprintf(log_line, "\n%d %s multiletter control sequences:\n\n",
+  sprintf(log_line, "\n%d %s multiletter control sequences:\n",
       ccount, (pass == 1) ? "new" : "");
+
   if (output == stderr)
+  {
     show_line(log_line, 1);
+  }
   else
+  {
     if (output == stdout)
       show_line(log_line, 0);
     else
       fprintf(output, log_line);
+  }
 
   if (ccount > 0) /* don't bother to get into trouble */
   {
-    textcolumn=0;
     cnumtable = (int *) malloc (ccount * sizeof(int));
 
     if (cnumtable == NULL)
       return;
 
-    ccount=0;
+    ccount = 0;
 /*    for (h = 515; h < (hash_size + 780); h++) { */
     for (h = hash_base + 1; h < nfcs; h++)
     {
       if (pass == 1 && csused[h])
         continue;
+
       if (hash[h].v.RH != 0)
         cnumtable[ccount++] = h;
     }
 
-    qsort ((void *)cnumtable, ccount, sizeof (int), &compare_cs);
+    //qsort ((void *)cnumtable, ccount, sizeof (int), &compare_cs);
 
     repeatflag = 0;
+
     for (k = 0; k < ccount; k++)
     {
       h = cnumtable[k];
+
       if (pass == 1 && csused[h])
         continue;
+
       print_cs_name(output, h);
     }
+
     sprintf(log_line, "\n");
+
     if (output == stderr)
+    {
       show_line(log_line, 1);
+    }
     else
+    {
       if (output == stdout)
         show_line(log_line, 0);
       else
         fprintf(output, log_line);
+    }
+
     free((void *)cnumtable);
   }
 
@@ -4003,7 +4003,8 @@ int compare_strn (int k1, int l1, int k2, int l2)
 {
   int c1, c2;
 /*  while (l1-- > 0 && l2-- > 0) { */
-  while (l1 > 0 && l2 > 0) {
+  while (l1 > 0 && l2 > 0)
+  {
     c1 = str_pool[k1];
     c2 = str_pool[k2];
 /*    sprintf(log_line, "%c%d%c%d ", c1, l1, c2, l2); */
index 5370392..c53b801 100644 (file)
@@ -1018,19 +1018,23 @@ void read_toks_(integer n, halfword r)
   {
     q = get_avail();
     mem[p].hh.v.RH = q;
-    mem[q].hh.v.LH = 3584;
+    mem[q].hh.v.LH = end_match_token;
     p = q;
   }
+
   if ((n < 0) || (n > 15))
     m = 16;
   else
     m = n;
+
   s = align_state;
   align_state = 1000000L;
+
   do {
     begin_file_reading();
     cur_input.name_field = m + 1;
-    if (read_open[m] == 2)
+
+    if (read_open[m] == closed)
       if (interaction > nonstop_mode)
         if (n < 0)
         {
@@ -1806,22 +1810,29 @@ void scan_file_name (void)
 {
   name_in_progress = true;
   begin_name();
-  do {
-    get_x_token(); 
-  } while (!(cur_cmd != spacer));
+
+  do
+    {
+      get_x_token(); 
+    }
+  while (!(cur_cmd != spacer));
+
   quoted_file_name = 0;         /* 98/March/15 */
-  if (allow_quoted_names)
-  {       /* check whether quoted name */
+
+  if (allow_quoted_names) /* check whether quoted name */
+  {
     if (cur_chr == '"')
     {
       quoted_file_name = 1;
       get_x_token();
     }
   }
-  while (true) {
-    if ((cur_cmd > other_char)||(cur_chr > 255)) 
+
+  while (true)
+  {
+    if ((cur_cmd > other_char) || (cur_chr > 255)) 
     {
-      back_input();  /* not a character put it back and leave */
+      back_input(); /* not a character put it back and leave */
       goto lab30; 
     } 
 /* *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** */
@@ -1832,6 +1843,7 @@ void scan_file_name (void)
 /* *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** */
     if (!more_name(cur_chr))    /* up to next white space */
       goto lab30;
+
     get_x_token();
   }
 lab30:
@@ -1852,10 +1864,13 @@ void pack_job_name_(str_number s)
 /* show TEXINPUTS=... or format specific  */
 /* only show this if name was not fully qualified ? */
 void show_tex_inputs (void)
-{     /* 98/Jan/28 */
+{
   char *s, *t, *v;
+
   s = "TEXINPUTS";        /* default */
-  if (format_specific) {
+
+  if (format_specific)
+  {
     s = format_name;                /* try specific */
     if (grabenv(s) == NULL) s = "TEXINPUTS";  /* no format specific */
   }
@@ -1864,14 +1879,20 @@ void show_tex_inputs (void)
 
   print_nl("  ");
   print_char(' ');
-  print_char(40);   /*(*/
+  print_char('(');
   t = s;
-  while (*t > '\0') print_char(*t++);
+
+  while (*t > '\0')
+    print_char(*t++);
+
   print_char('=');
   v = grabenv(s);
-  if (v != NULL) {
+
+  if (v != NULL)
+  {
     t = v;
-    while (*t > '\0') print_char(*t++);
+    while (*t > '\0')
+      print_char(*t++);
   }
   print_char(')');
 }
@@ -1881,30 +1902,38 @@ void show_tex_inputs (void)
 void prompt_file_name_(str_number s, str_number e)/*  s - what can't be found, e - default */ 
 {
   integer k;
+
   if (interaction == scroll_mode);
+
   if (s == 781)
     print_err("I can't find file `");
   else
     print_err("I can't write on file `");
+
   print_file_name(cur_name, cur_area, cur_ext);
   print_string("'.");
-  if (s == 781)
-  {   /* input file name */
-    if (cur_area == 335)
-    {    /* "" only if path not specified */
+
+  if (s == 781) /* input file name */
+  {
+    if (cur_area == 335) /* "" only if path not specified */
+    {
       if (show_texinput_flag)
         show_tex_inputs();
     }
   }
+
   if (e == 785)    /* .tex */
     show_context();
+
   print_nl("Please type another ");
   print(s);
+
   if (interaction < 2)
   {
     fatal_error("*** (job aborted, file error in nonstop mode)");
     return;     // abort_flag set
   }
+
   if (!knuth_flag)
 #ifdef _WINDOWS
     show_line(" (or ^z to exit)", 0);
@@ -1924,14 +1953,16 @@ void prompt_file_name_(str_number s, str_number e)/*  s - what can't be found, e
       incr(k);
 /* *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** */
     quoted_file_name = 0;         /* 98/March/15 */
-    if (allow_quoted_names && k < last)
-    { /* check whether quoted name */
+
+    if (allow_quoted_names && k < last) /* check whether quoted name */
+    {
       if (buffer[k]== '"')
       {
         quoted_file_name = 1;
         incr(k);
       }
     }
+
     while (true) {
       if (k == last)
         goto lab30;
@@ -1966,8 +1997,11 @@ void open_log_file (void)
 
   if (job_name == 0)
     job_name = 790;   /* default:  texput */
+
   pack_job_name(791); /* .log */
-  while (!a_open_out(log_file)) {
+
+  while (!a_open_out(log_file))
+  {
     selector = term_only;
     prompt_file_name(793, 791); /* transcript file name  texput */
   }
index 24503a1..ae9e036 100644 (file)
@@ -472,6 +472,7 @@ void special_out_(halfword p)
 #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 */
index 586c14b..0daa3f9 100644 (file)
@@ -16,6 +16,7 @@
 #pragma warning(disable:4127) // conditional expression is constant
 
 #include <setjmp.h>
+#include <time.h>
 
 #define EXTERN extern
 
@@ -1066,20 +1067,41 @@ static const char *pool_file_arr[] =
 
 int load_pool_strings (integer spare_size)
 {
-  const char *s;
+  //const char *s;
   str_number g = 0;
   int i = 0;
-  int j = 0;
+  //int j = 0;
+  int k = 0;
   int l;
+
+  for (k = 0; k < sizeof(pool_file_arr) / sizeof(char *) - 1; ++k)
+  {
+    l = strlen(pool_file_arr[k]);
+    i += l;
+
+    if (i >= spare_size)
+      return 0;
+
+    memcpy(str_pool + pool_ptr, pool_file_arr[k], l);
+
+    pool_ptr += l;
+
+    g = make_string();
+  }
+/*
   while ((s = pool_file_arr[j++]))
   {
     l = strlen (s);
     i += l;
+
     if (i >= spare_size)
       return 0;
+
     while (l-- > 0)
       str_pool[pool_ptr++] = *s++;
+
     g = make_string();
   }
+  */
   return g;
 }