texinfo-commits
[Top][All Lists]
Advanced

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

[no subject]


From: Patrice Dumas
Date: Sun, 29 Sep 2024 09:11:51 -0400 (EDT)

branch: master
commit 9d8a003169dde0b9e92baec85c641a3014166844
Author: Patrice Dumas <pertusus@free.fr>
AuthorDate: Sat Jun 29 21:17:49 2024 +0200

    * tp/Texinfo/XS/main/tree.c (remove_from_const_element_list): add.
    
    * tp/Texinfo/XS/parsetexi/handle_commands.c (handle_block_command),
    tp/Texinfo/XS/structuring_transfo/transformations.c
    (reassociate_to_node, prepend_new_menu_in_node_section)
    (complete_node_menu, regenerate_master_menu): use extra_load for menus
    extra information. Remove const by casting in menu generation code
    since elements are modified when tree is transformed.
---
 ChangeLog                                          | 11 +++++++
 tp/Texinfo/XS/convert/convert_html.c               |  2 +-
 tp/Texinfo/XS/main/manipulate_tree.c               |  2 +-
 tp/Texinfo/XS/main/tree.c                          | 19 ++++++++++++
 tp/Texinfo/XS/main/tree.h                          |  2 ++
 tp/Texinfo/XS/parsetexi/handle_commands.c          |  6 ++--
 tp/Texinfo/XS/structuring_transfo/structuring.c    | 36 +++++++++++-----------
 tp/Texinfo/XS/structuring_transfo/structuring.h    |  2 +-
 .../XS/structuring_transfo/transformations.c       | 35 +++++++++++----------
 9 files changed, 75 insertions(+), 40 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index e25d1d6a60..715f1fd41d 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+2024-06-29  Patrice Dumas  <pertusus@free.fr>
+
+       * tp/Texinfo/XS/main/tree.c (remove_from_const_element_list): add.
+
+       * tp/Texinfo/XS/parsetexi/handle_commands.c (handle_block_command),
+       tp/Texinfo/XS/structuring_transfo/transformations.c
+       (reassociate_to_node, prepend_new_menu_in_node_section)
+       (complete_node_menu, regenerate_master_menu): use extra_load for menus
+       extra information. Remove const by casting in menu generation code
+       since elements are modified when tree is transformed.
+
 2024-06-29  Patrice Dumas  <pertusus@free.fr>
 
        * tp/Texinfo/XS/main/build_perl_info.c (build_perl_array): rename e as
diff --git a/tp/Texinfo/XS/convert/convert_html.c 
b/tp/Texinfo/XS/convert/convert_html.c
index 668ea9db0f..867a83ac4e 100644
--- a/tp/Texinfo/XS/convert/convert_html.c
+++ b/tp/Texinfo/XS/convert/convert_html.c
@@ -10449,7 +10449,7 @@ convert_heading_command (CONVERTER *self, const enum 
command_id cmd,
           if (node)
             {
               int automatic_directions = (node->e.c->args.number <= 1);
-              const ELEMENT_LIST *menus = lookup_extra_contents (node,
+              const CONST_ELEMENT_LIST *menus = lookup_extra_load (node,
                                                               AI_key_menus);
               if (!menus && automatic_directions)
                 {
diff --git a/tp/Texinfo/XS/main/manipulate_tree.c 
b/tp/Texinfo/XS/main/manipulate_tree.c
index f6b4aefde6..fc29028e18 100644
--- a/tp/Texinfo/XS/main/manipulate_tree.c
+++ b/tp/Texinfo/XS/main/manipulate_tree.c
@@ -1113,7 +1113,7 @@ normalized_entry_associated_internal_node (const ELEMENT 
*entry,
 const ELEMENT *
 first_menu_node (const ELEMENT *node, const LABEL_LIST *identifiers_target)
 {
-  const ELEMENT_LIST *menus = lookup_extra_contents (node, AI_key_menus);
+  const CONST_ELEMENT_LIST *menus = lookup_extra_load (node, AI_key_menus);
   if (menus)
     {
       int i;
diff --git a/tp/Texinfo/XS/main/tree.c b/tp/Texinfo/XS/main/tree.c
index 0649deae51..5d7d330376 100644
--- a/tp/Texinfo/XS/main/tree.c
+++ b/tp/Texinfo/XS/main/tree.c
@@ -519,6 +519,25 @@ remove_from_element_list (ELEMENT_LIST *list, int where)
   return removed;
 }
 
+const ELEMENT *
+remove_from_const_element_list (CONST_ELEMENT_LIST *list, int where)
+{
+  const ELEMENT *removed;
+
+  if (where < 0)
+    where = list->number + where;
+
+  if (where < 0 || where > list->number -1)
+    fatal ("element list index out of bounds");
+
+  removed = list->list[where];
+  if (where < list->number - 1)
+    memmove (&list->list[where], &list->list[where + 1],
+             (list->number - (where+1)) * sizeof (ELEMENT *));
+  list->number--;
+  return removed;
+}
+
 ELEMENT *
 remove_from_contents (ELEMENT *parent, int where)
 {
diff --git a/tp/Texinfo/XS/main/tree.h b/tp/Texinfo/XS/main/tree.h
index d1222cdee7..37fa561638 100644
--- a/tp/Texinfo/XS/main/tree.h
+++ b/tp/Texinfo/XS/main/tree.h
@@ -33,6 +33,8 @@ void insert_list_slice_into_args (ELEMENT *to, int where, 
ELEMENT_LIST *from,
                                       int start, int end);
 void list_set_empty_contents (ELEMENT_LIST *e_list, int n);
 ELEMENT *remove_from_element_list (ELEMENT_LIST *list, int where);
+const ELEMENT *remove_from_const_element_list (CONST_ELEMENT_LIST *list,
+                                               int where);
 ELEMENT *remove_from_contents (ELEMENT *parent, int where);
 ELEMENT *remove_from_args (ELEMENT *parent, int where);
 void remove_slice_from_contents (ELEMENT *parent, int start, int end);
diff --git a/tp/Texinfo/XS/parsetexi/handle_commands.c 
b/tp/Texinfo/XS/parsetexi/handle_commands.c
index eee8746bdc..0a9bcde013 100644
--- a/tp/Texinfo/XS/parsetexi/handle_commands.c
+++ b/tp/Texinfo/XS/parsetexi/handle_commands.c
@@ -1095,9 +1095,9 @@ handle_block_command (ELEMENT *current, const char 
**line_inout,
                 line_warn ("@menu in invalid context");
               else
                 {
-                  ELEMENT_LIST *l
-                    = add_extra_contents (current_node, AI_key_menus, 0);
-                  add_to_element_list (l, block);
+                  CONST_ELEMENT_LIST *l
+                    = add_extra_load (current_node, AI_key_menus, 0);
+                  add_to_const_element_list (l, block);
                 }
             }
         }
diff --git a/tp/Texinfo/XS/structuring_transfo/structuring.c 
b/tp/Texinfo/XS/structuring_transfo/structuring.c
index 1f622b9567..76c6fe6c26 100644
--- a/tp/Texinfo/XS/structuring_transfo/structuring.c
+++ b/tp/Texinfo/XS/structuring_transfo/structuring.c
@@ -616,7 +616,7 @@ check_nodes_are_referenced (DOCUMENT *document)
       int is_target = (node->flags & EF_is_target);
       const ELEMENT * const *node_directions = lookup_extra_directions (node,
                                                    AI_key_node_directions);
-      const ELEMENT_LIST *menus = lookup_extra_contents (node, AI_key_menus);
+      const CONST_ELEMENT_LIST *menus = lookup_extra_load (node, AI_key_menus);
 
       if (is_target)
         nr_nodes_to_find++;
@@ -640,7 +640,7 @@ check_nodes_are_referenced (DOCUMENT *document)
           int j;
           for (j = 0; j < menus->number; j++)
             {
-              ELEMENT *menu = menus->list[j];
+              const ELEMENT *menu = menus->list[j];
               int k;
               for (k = 0; k < menu->e.c->contents.number; k++)
                 {
@@ -833,7 +833,7 @@ set_menus_node_directions (DOCUMENT *document)
     {
       int j;
       const ELEMENT *node = nodes_list->list[i];
-      const ELEMENT_LIST *menus = lookup_extra_contents (node, AI_key_menus);
+      const CONST_ELEMENT_LIST *menus = lookup_extra_load (node, AI_key_menus);
 
       if (!menus)
         continue;
@@ -1074,7 +1074,7 @@ complete_node_tree_with_menus (DOCUMENT *document)
                                                   node_direction_section, d);
                       if (direction_associated_node)
                         {
-                          const ELEMENT_LIST *menus = 0;
+                          const CONST_ELEMENT_LIST *menus = 0;
                           const ELEMENT * const *section_directions
                             = lookup_extra_directions (node_direction_section,
                                                    AI_key_section_directions);
@@ -1088,7 +1088,7 @@ complete_node_tree_with_menus (DOCUMENT *document)
                                                      AI_key_associated_node);
                               if (up_node)
                                 menus
-                                = lookup_extra_contents (up_node, 
AI_key_menus);
+                                = lookup_extra_load (up_node, AI_key_menus);
                             }
 
                           if (menus
@@ -1255,8 +1255,8 @@ complete_node_tree_with_menus (DOCUMENT *document)
               const ELEMENT *manual_content = lookup_extra_container (up_node,
                                                        AI_key_manual_content);
               int is_target = (node->flags & EF_is_target);
-              const ELEMENT_LIST *menus
-                   = lookup_extra_contents (up_node, AI_key_menus);
+              const CONST_ELEMENT_LIST *menus
+                   = lookup_extra_load (up_node, AI_key_menus);
 
               /* No check if node up is an external manual */
               if (!manual_content
@@ -1946,8 +1946,8 @@ print_down_menus (const ELEMENT *node, ELEMENT_STACK 
*up_nodes,
                   int use_sections)
 {
   ELEMENT_LIST *master_menu_contents = new_list ();
-  ELEMENT_LIST *menus;
-  ELEMENT_LIST *node_menus = lookup_extra_contents (node, AI_key_menus);
+  CONST_ELEMENT_LIST *menus;
+  CONST_ELEMENT_LIST *node_menus = lookup_extra_load (node, AI_key_menus);
   ELEMENT_LIST *node_children;
   ELEMENT *new_current_menu = 0;
   int i;
@@ -1961,8 +1961,8 @@ print_down_menus (const ELEMENT *node, ELEMENT_STACK 
*up_nodes,
       new_current_menu = new_complete_node_menu (node, 0, 0, use_sections);
       if (new_current_menu)
         {
-          menus = new_list ();
-          add_to_element_list (menus, new_current_menu);
+          menus = new_const_element_list ();
+          add_to_const_element_list (menus, new_current_menu);
         }
       else
         return master_menu_contents;
@@ -1972,7 +1972,7 @@ print_down_menus (const ELEMENT *node, ELEMENT_STACK 
*up_nodes,
 
   for (i = 0; i < menus->number; i++)
     {
-      ELEMENT *menu = menus->list[i];
+      const ELEMENT *menu = menus->list[i];
       int j;
       for (j = 0; j < menu->e.c->contents.number; j++)
         {
@@ -1992,7 +1992,7 @@ print_down_menus (const ELEMENT *node, ELEMENT_STACK 
*up_nodes,
     }
 
   if (!node_menus)
-    destroy_list (menus);
+    destroy_const_element_list (menus);
 
   if (new_current_menu)
     destroy_element_and_children (new_current_menu);
@@ -2028,7 +2028,7 @@ print_down_menus (const ELEMENT *node, ELEMENT_STACK 
*up_nodes,
       /* now recurse in the children */
       for (i = 0; i < node_children->number; i++)
         {
-          ELEMENT *child = node_children->list[i];
+          const ELEMENT *child = node_children->list[i];
           ELEMENT_LIST *child_menu_content;
           const char *normalized_child
             = lookup_extra_string (child, AI_key_normalized);
@@ -2085,7 +2085,7 @@ ELEMENT *
 new_detailmenu (ERROR_MESSAGE_LIST *error_messages,
                 const OPTIONS *options,
                 const LABEL_LIST *identifiers_target,
-                const ELEMENT_LIST *menus, int use_sections)
+                const CONST_ELEMENT_LIST *menus, int use_sections)
 {
   /* only holds contents here, will add spaces and end in
      new_block_command */
@@ -2193,13 +2193,13 @@ new_complete_menu_master_menu (ERROR_MESSAGE_LIST 
*error_messages,
       if (normalized && !strcmp (normalized, "Top")
           && associated_section && associated_section->e.c->cmd == CM_top)
         {
-          ELEMENT_LIST *menus = new_list ();
+          CONST_ELEMENT_LIST *menus = new_const_element_list ();
           ELEMENT *detailmenu;
 
-          add_to_element_list (menus, menu_node);
+          add_to_const_element_list (menus, menu_node);
           detailmenu = new_detailmenu (error_messages, options,
                                        identifiers_target, menus, 0);
-          destroy_list (menus);
+          destroy_const_element_list (menus);
 
           if (detailmenu)
             {
diff --git a/tp/Texinfo/XS/structuring_transfo/structuring.h 
b/tp/Texinfo/XS/structuring_transfo/structuring.h
index b7ad00fc94..9b1d50f4d5 100644
--- a/tp/Texinfo/XS/structuring_transfo/structuring.h
+++ b/tp/Texinfo/XS/structuring_transfo/structuring.h
@@ -24,7 +24,7 @@ void new_block_command (ELEMENT *element);
 ELEMENT *new_detailmenu (ERROR_MESSAGE_LIST *error_messages,
                  const OPTIONS *options,
                  const LABEL_LIST *identifiers_target,
-                 const ELEMENT_LIST *menus, int use_sections);
+                 const CONST_ELEMENT_LIST *menus, int use_sections);
 ELEMENT *new_complete_menu_master_menu (ERROR_MESSAGE_LIST *error_messages,
                                const OPTIONS *options,
                                const LABEL_LIST *identifiers_target,
diff --git a/tp/Texinfo/XS/structuring_transfo/transformations.c 
b/tp/Texinfo/XS/structuring_transfo/transformations.c
index 31195ada25..dba875068d 100644
--- a/tp/Texinfo/XS/structuring_transfo/transformations.c
+++ b/tp/Texinfo/XS/structuring_transfo/transformations.c
@@ -697,11 +697,11 @@ reassociate_to_node (const char *type, ELEMENT *current, 
void *argument)
   if (type_data[current->type].flags & TF_at_command
       && current->e.c->cmd == CM_menu)
     {
-      ELEMENT_LIST *added_node_menus;
+      CONST_ELEMENT_LIST *added_node_menus;
       if (previous_node)
         {
-          ELEMENT_LIST *menus
-            = lookup_extra_contents (previous_node, AI_key_menus);
+          CONST_ELEMENT_LIST *menus
+            = lookup_extra_load (previous_node, AI_key_menus);
           int previous_idx = -1;
           if (menus)
             {
@@ -721,18 +721,18 @@ reassociate_to_node (const char *type, ELEMENT *current, 
void *argument)
           else
             {
               /* removed element should be current */
-              remove_from_element_list (menus, previous_idx);
+              remove_from_const_element_list (menus, previous_idx);
               if (menus->number <= 0)
                 {
                   KEY_PAIR *k = lookup_extra (previous_node, AI_key_menus);
                   k->key = AI_key_none;
                   k->type = extra_deleted;
-                  destroy_list (menus);
+                  destroy_const_element_list (menus);
                 }
             }
         }
-      added_node_menus = add_extra_contents (added_node, AI_key_menus, 0);
-      add_to_element_list (added_node_menus, current);
+      added_node_menus = add_extra_load (added_node, AI_key_menus, 0);
+      add_to_const_element_list (added_node_menus, current);
     }
   /* what is really important is to avoid commands without extra information,
      such as text, though it is even better to be precise */
@@ -931,13 +931,13 @@ prepend_new_menu_in_node_section (ELEMENT *node, ELEMENT 
*section,
                                   ELEMENT *current_menu)
 {
   ELEMENT *empty_line = new_text_element (ET_empty_line);
-  ELEMENT_LIST *menus = add_extra_contents (node, AI_key_menus, 0);
+  CONST_ELEMENT_LIST *menus = add_extra_load (node, AI_key_menus, 0);
 
   add_to_element_contents (section, current_menu);
   text_append (empty_line->e.text, "\n");
   add_to_element_contents (section, empty_line);
 
-  add_to_element_list (menus, current_menu);
+  add_to_const_element_list (menus, current_menu);
 }
 
 typedef struct EXISTING_ENTRY {
@@ -962,7 +962,7 @@ complete_node_menu (ELEMENT *node, int use_sections)
       ELEMENT *current_menu = 0;
 
       int i;
-      const ELEMENT_LIST *menus = lookup_extra_contents (node, AI_key_menus);
+      const CONST_ELEMENT_LIST *menus = lookup_extra_load (node, AI_key_menus);
 
       if (menus)
         {
@@ -971,7 +971,8 @@ complete_node_menu (ELEMENT *node, int use_sections)
 
           for (i = 0; i < menus->number; i++)
             {
-              ELEMENT *menu = menus->list[i];
+              /* cast to remove the const, as the menu is to be modified */
+              ELEMENT *menu = (ELEMENT *)menus->list[i];
               int j;
               for (j = 0; j < menu->e.c->contents.number; j++)
                 {
@@ -1136,7 +1137,7 @@ complete_tree_nodes_missing_menu (DOCUMENT *document, int 
use_sections)
   for (i = 0; i < non_automatic_nodes->number; i++)
     {
       ELEMENT *node = non_automatic_nodes->list[i];
-      const ELEMENT_LIST *menus = lookup_extra_contents (node, AI_key_menus);
+      const CONST_ELEMENT_LIST *menus = lookup_extra_load (node, AI_key_menus);
       if (!(menus && menus->number > 0))
         {
           ELEMENT *section = lookup_extra_element (node,
@@ -1159,7 +1160,7 @@ regenerate_master_menu (DOCUMENT *document, int 
use_sections)
   const LABEL_LIST *identifiers_target = &document->identifiers_target;
 
   const ELEMENT *top_node = find_identifier_target (identifiers_target, "Top");
-  const ELEMENT_LIST *menus;
+  const CONST_ELEMENT_LIST *menus;
   ELEMENT *new_detailmenu_e;
   ELEMENT *last_menu;
   const ELEMENT *last_content;
@@ -1168,7 +1169,7 @@ regenerate_master_menu (DOCUMENT *document, int 
use_sections)
 
   if (top_node)
     {
-      menus = lookup_extra_contents (top_node, AI_key_menus);
+      menus = lookup_extra_load (top_node, AI_key_menus);
       if (!menus || (menus->number <= 0))
         return 0;
     }
@@ -1188,7 +1189,8 @@ regenerate_master_menu (DOCUMENT *document, int 
use_sections)
   for (i = 0; i < menus->number; i++)
     {
       int detailmenu_index = 0;
-      ELEMENT *menu = menus->list[i];
+      /* cast to remove const to be able to replace the detailmenu */
+      ELEMENT *menu = (ELEMENT *)menus->list[i];
       for (detailmenu_index = 0; detailmenu_index < menu->e.c->contents.number;
            detailmenu_index++)
         {
@@ -1240,7 +1242,8 @@ regenerate_master_menu (DOCUMENT *document, int 
use_sections)
         }
     }
 
-  last_menu = menus->list[menus->number -1];
+  /* cast to remove const, as the detailmenu will be inserted in this menu */
+  last_menu = (ELEMENT *)menus->list[menus->number -1];
   index = last_menu->e.c->contents.number;
   last_content = last_contents_child (last_menu);
   /* In a regular setting the last content is @end, but here we also



reply via email to

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