texinfo-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[no subject]


From: Patrice Dumas
Date: Mon, 13 Nov 2023 16:08:41 -0500 (EST)

branch: master
commit 48aee2d29ee50bab2ae1e141635a1dff88818c56
Author: Patrice Dumas <pertusus@free.fr>
AuthorDate: Mon Nov 13 21:46:54 2023 +0100

    * tp/Texinfo/XS/main/convert_to_text.c (ascii_accents_internal),
    tp/Texinfo/XS/main/convert_utils.c (find_innermost_accent_contents),
    tp/Texinfo/XS/main/convert_utils.h, tp/Texinfo/XS/main/unicode.c
    (format_eight_bit_accents_stack, encoded_accents)
    (format_unicode_accents_stack_internal), tp/Texinfo/XS/main/utils.c
    (push_stack_element, pop_stack_element, destroy_accent_stack),
    tp/Texinfo/XS/main/utils.h (ELEMENT_STACK, ACCENTS_STACK): move
    ACCENTS_STACK and destroy_accent_stack to main/utils.c.  Add a stack
    for elements, with elements unmodifed (const), in main/utils.c.  Use
    that stack for accent commands.
---
 ChangeLog                            | 13 +++++++++++++
 tp/Texinfo/XS/main/convert_to_text.c |  6 +++---
 tp/Texinfo/XS/main/convert_utils.c   | 15 +++------------
 tp/Texinfo/XS/main/convert_utils.h   |  8 +-------
 tp/Texinfo/XS/main/unicode.c         | 22 +++++++++++-----------
 tp/Texinfo/XS/main/unicode.h         |  2 +-
 tp/Texinfo/XS/main/utils.c           | 36 ++++++++++++++++++++++++++++++++++++
 tp/Texinfo/XS/main/utils.h           | 15 +++++++++++++++
 8 files changed, 83 insertions(+), 34 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index cef0918478..668923ff42 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -5,6 +5,19 @@
        * tp/Texinfo/XS:
        Run "gnulib-tool --add-import uchar".
 
+2023-11-13  Patrice Dumas  <pertusus@free.fr>
+
+       * tp/Texinfo/XS/main/convert_to_text.c (ascii_accents_internal),
+       tp/Texinfo/XS/main/convert_utils.c (find_innermost_accent_contents),
+       tp/Texinfo/XS/main/convert_utils.h, tp/Texinfo/XS/main/unicode.c
+       (format_eight_bit_accents_stack, encoded_accents)
+       (format_unicode_accents_stack_internal), tp/Texinfo/XS/main/utils.c
+       (push_stack_element, pop_stack_element, destroy_accent_stack),
+       tp/Texinfo/XS/main/utils.h (ELEMENT_STACK, ACCENTS_STACK): move
+       ACCENTS_STACK and destroy_accent_stack to main/utils.c.  Add a stack
+       for elements, with elements unmodifed (const), in main/utils.c.  Use
+       that stack for accent commands.
+
 2023-11-13  Patrice Dumas  <pertusus@free.fr>
 
        * tp/Texinfo/XS/main/convert_to_texinfo.c
diff --git a/tp/Texinfo/XS/main/convert_to_text.c 
b/tp/Texinfo/XS/main/convert_to_text.c
index d174cd2762..d157fad0f0 100644
--- a/tp/Texinfo/XS/main/convert_to_text.c
+++ b/tp/Texinfo/XS/main/convert_to_text.c
@@ -81,7 +81,7 @@ ascii_accent (const char *text, const ELEMENT *command, int 
set_case)
 }
 
 char *
-ascii_accents_internal (const char *text, const ELEMENT_LIST *stack,
+ascii_accents_internal (const char *text, const ELEMENT_STACK *stack,
                         int set_case)
 {
   char *result;
@@ -92,9 +92,9 @@ ascii_accents_internal (const char *text, const ELEMENT_LIST 
*stack,
   else
     result = strdup (text);
 
-  for (i = stack->number - 1; i >= 0; i--)
+  for (i = stack->top - 1; i >= 0; i--)
     {
-      const ELEMENT *accent_command = stack->list[i];
+      const ELEMENT *accent_command = stack->stack[i];
       char *formatted_accent = ascii_accent (result, accent_command, set_case);
       free (result);
       result = formatted_accent;
diff --git a/tp/Texinfo/XS/main/convert_utils.c 
b/tp/Texinfo/XS/main/convert_utils.c
index e06804d8e2..80f587761a 100644
--- a/tp/Texinfo/XS/main/convert_utils.c
+++ b/tp/Texinfo/XS/main/convert_utils.c
@@ -52,9 +52,9 @@ element_associated_processing_encoding (const ELEMENT 
*element)
 }
 
 ACCENTS_STACK *
-find_innermost_accent_contents (ELEMENT *element)
+find_innermost_accent_contents (const ELEMENT *element)
 {
-  ELEMENT *current = element;
+  const ELEMENT *current = element;
   ELEMENT *argument = 0;
   ACCENTS_STACK *accent_stack = (ACCENTS_STACK *)
          malloc (sizeof (ACCENTS_STACK));
@@ -68,7 +68,7 @@ find_innermost_accent_contents (ELEMENT *element)
       /* the following can happen if called with a bad tree */
       if (!current->cmd || !(builtin_command_flags(current) & CF_accent))
         return accent_stack;
-      add_to_element_list (&accent_stack->stack, current);
+      push_stack_element (&accent_stack->stack, current);
       /* A bogus accent, that may happen */
       if (current->args.number <= 0)
         return accent_stack;
@@ -108,15 +108,6 @@ find_innermost_accent_contents (ELEMENT *element)
   return accent_stack;
 }
 
-void
-destroy_accent_stack (ACCENTS_STACK *accent_stack)
-{
-  free (accent_stack->stack.list);
-  if (accent_stack->argument)
-    destroy_element (accent_stack->argument);
-  free (accent_stack);
-}
-
 /*
  TEXT can be indented, however this can only happen for
  *heading headings, which are not numbered.  If it was not the case,
diff --git a/tp/Texinfo/XS/main/convert_utils.h 
b/tp/Texinfo/XS/main/convert_utils.h
index 51dbb77c7d..f7e5c6a78f 100644
--- a/tp/Texinfo/XS/main/convert_utils.h
+++ b/tp/Texinfo/XS/main/convert_utils.h
@@ -11,11 +11,6 @@
 
 extern char *convert_utils_month_name[12];
 
-typedef struct ACCENTS_STACK {
-    ELEMENT_LIST stack;
-    ELEMENT *argument;
-} ACCENTS_STACK;
-
 typedef struct PARSED_DEF {
     ELEMENT *name;
     ELEMENT *class;
@@ -24,8 +19,7 @@ typedef struct PARSED_DEF {
     ELEMENT *args;
 } PARSED_DEF;
 
-ACCENTS_STACK *find_innermost_accent_contents (ELEMENT *element);
-void destroy_accent_stack (ACCENTS_STACK *accent_stack);
+ACCENTS_STACK *find_innermost_accent_contents (const ELEMENT *element);
 
 char *add_heading_number (OPTIONS *options, const ELEMENT *current, char *text,
                           int numbered);
diff --git a/tp/Texinfo/XS/main/unicode.c b/tp/Texinfo/XS/main/unicode.c
index b6eb061586..66378f6543 100644
--- a/tp/Texinfo/XS/main/unicode.c
+++ b/tp/Texinfo/XS/main/unicode.c
@@ -28,8 +28,8 @@
 
 #include "tree_types.h"
 #include "text.h"
-/* for xasprintf */
 #include "errors.h"
+/* for xasprintf */
 #include "utils.h"
 #include "unicode.h"
 
@@ -172,7 +172,7 @@ compare_strings (const void *a, const void *b)
 }
 
 char *
-format_eight_bit_accents_stack (const char *text, const ELEMENT_LIST *stack,
+format_eight_bit_accents_stack (const char *text, const ELEMENT_STACK *stack,
   int encoding_index,
   char *(*format_accent)(const char *text, const ELEMENT *element, int 
set_case),
   int set_case)
@@ -181,7 +181,7 @@ format_eight_bit_accents_stack (const char *text, const 
ELEMENT_LIST *stack,
   char *result = strdup (text);
   char *prev_eight_bit;
   char *new_eight_bit;
-  int const stack_nr = stack->number;
+  int const stack_nr = stack->top;
   char **results_stack
      = malloc ((stack_nr +1) * sizeof (char *));
 
@@ -191,7 +191,7 @@ format_eight_bit_accents_stack (const char *text, const 
ELEMENT_LIST *stack,
 
   for (i = stack_nr -1; i >= 0; i--)
     {
-      const ELEMENT *accent_command = stack->list[i];
+      const ELEMENT *accent_command = stack->stack[i];
       results_stack[i] = unicode_accent (results_stack[i+1],
                                          accent_command);
       if (!results_stack[i])
@@ -272,7 +272,7 @@ format_eight_bit_accents_stack (const char *text, const 
ELEMENT_LIST *stack,
     #    underbar.
     */
       if (!strcmp (new_eight_bit, prev_eight_bit)
-          && !(stack->list[j]->cmd == CM_dotless
+          && !(stack->stack[j]->cmd == CM_dotless
                && !strcmp (results_stack[j], "i")))
         break;
       free (result);
@@ -290,7 +290,7 @@ format_eight_bit_accents_stack (const char *text, const 
ELEMENT_LIST *stack,
    */
   for (; j >= 0; j--)
     {
-      ELEMENT *accent_command = stack->list[j];
+      const ELEMENT *accent_command = stack->stack[j];
       char *formatted_result
           = (*format_accent) (result, accent_command, set_case);
       free (result);
@@ -309,16 +309,16 @@ format_eight_bit_accents_stack (const char *text, const 
ELEMENT_LIST *stack,
 /* FIXME converter in perl for (*format_accent), see encoded_accents comment*/
 char *
 format_unicode_accents_stack_internal (const char *text,
-  const ELEMENT_LIST *stack,
+  const ELEMENT_STACK *stack,
   char *(*format_accent)(const char *text, const ELEMENT *element, int 
set_case),
   int set_case)
 {
   int i;
   char *result = strdup (text);
 
-  for (i = stack->number - 1; i >= 0; i--)
+  for (i = stack->top - 1; i >= 0; i--)
     {
-      const ELEMENT *accent_command = stack->list[i];
+      const ELEMENT *accent_command = stack->stack[i];
       char *formatted_result = unicode_accent (result, accent_command);
       if (formatted_result)
         {
@@ -338,7 +338,7 @@ format_unicode_accents_stack_internal (const char *text,
 
   for (; i >= 0; i--)
     {
-      const ELEMENT *accent_command = stack->list[i];
+      const ELEMENT *accent_command = stack->stack[i];
       char *formatted_result
           = (*format_accent) (result, accent_command, set_case);
       free (result);
@@ -351,7 +351,7 @@ format_unicode_accents_stack_internal (const char *text,
    directly and through functions.  It is not clear whether it is
    actually used in perl, nor if it could be useful in C */
 char *
-encoded_accents (const char *text, const ELEMENT_LIST *stack,
+encoded_accents (const char *text, const ELEMENT_STACK *stack,
   const char *encoding,
   char *(*format_accent)(const char *text, const ELEMENT *element, int 
set_case),
   int set_case)
diff --git a/tp/Texinfo/XS/main/unicode.h b/tp/Texinfo/XS/main/unicode.h
index b5f7f28bfd..df7121bfa5 100644
--- a/tp/Texinfo/XS/main/unicode.h
+++ b/tp/Texinfo/XS/main/unicode.h
@@ -25,7 +25,7 @@ char *normalize_NFC (const char *text);
 char *normalize_NFKD (const char *text);
 char *unicode_accent (const char *text, const ELEMENT *e);
 
-char *encoded_accents (const char *text, const ELEMENT_LIST *stack,
+char *encoded_accents (const char *text, const ELEMENT_STACK *stack,
   const char *encoding,
   char *(*format_accent)(const char *text, const ELEMENT *element, int 
set_case),
   int set_case);
diff --git a/tp/Texinfo/XS/main/utils.c b/tp/Texinfo/XS/main/utils.c
index 4dc393b305..feaab149fe 100644
--- a/tp/Texinfo/XS/main/utils.c
+++ b/tp/Texinfo/XS/main/utils.c
@@ -1064,6 +1064,42 @@ new_options (void)
 }
 
 
+/* accents/elements stacks */
+void
+push_stack_element (ELEMENT_STACK *stack, const ELEMENT *e)
+{
+  if (stack->top >= stack->space)
+    {
+      stack->stack
+        = realloc (stack->stack,
+                   (stack->space += 5) * sizeof (ELEMENT *));
+    }
+
+  stack->stack[stack->top] = e;
+  stack->top++;
+}
+
+/* currently unused */
+const ELEMENT *
+pop_stack_element (ELEMENT_STACK *stack)
+{
+  if (stack->top == 0)
+    fatal ("element stack empty");
+
+  stack->top--;
+  return stack->stack[stack->top +1];
+}
+
+void
+destroy_accent_stack (ACCENTS_STACK *accent_stack)
+{
+  free (accent_stack->stack.stack);
+  if (accent_stack->argument)
+    destroy_element (accent_stack->argument);
+  free (accent_stack);
+}
+
+
 /* misc functions used in general in structuring and in conversion */
 
 /* corresponding perl function in Common.pm */
diff --git a/tp/Texinfo/XS/main/utils.h b/tp/Texinfo/XS/main/utils.h
index 3e578ea723..a32e2d69da 100644
--- a/tp/Texinfo/XS/main/utils.h
+++ b/tp/Texinfo/XS/main/utils.h
@@ -195,6 +195,17 @@ typedef struct HTML_ARGS_FORMATTED {
     HTML_ARG_FORMATTED *args;
 } HTML_ARGS_FORMATTED;
 
+typedef struct ELEMENT_STACK {
+    const ELEMENT **stack;
+    size_t top;
+    size_t space;
+} ELEMENT_STACK;
+
+typedef struct ACCENTS_STACK {
+    ELEMENT_STACK stack;
+    ELEMENT *argument;
+} ACCENTS_STACK;
+
 
 int xasprintf (char **ptr, const char *template, ...);
 
@@ -231,6 +242,10 @@ void add_string (const char *string, STRING_LIST 
*strings_list);
 void merge_strings (STRING_LIST *strings_list, STRING_LIST *merged_strings);
 size_t find_string (STRING_LIST *strings_list, const char *string);
 
+void push_stack_element (ELEMENT_STACK *stack, const ELEMENT *e);
+const ELEMENT *pop_stack_element (ELEMENT_STACK *stack);
+void destroy_accent_stack (ACCENTS_STACK *accent_stack);
+
 void wipe_index (INDEX *idx);
 void wipe_index_names (INDEX **index_names);
 



reply via email to

[Prev in Thread] Current Thread [Next in Thread]