[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[no subject]
From: |
Patrice Dumas |
Date: |
Sat, 24 Feb 2024 11:03:43 -0500 (EST) |
branch: master
commit 1959e8670455837d36bb4c21e300e1efd1d12b27
Author: Patrice Dumas <pertusus@free.fr>
AuthorDate: Sat Feb 24 13:34:43 2024 +0100
* tp/Texinfo/XS/main/extra.c (add_extra_contents): replace the input
list argument by no_lookup. If not set, first check that the array
does not exist before creating it. Update callers.
---
ChangeLog | 6 ++++++
tp/Texinfo/XS/main/extra.c | 23 ++++++++++++++++------
tp/Texinfo/XS/main/extra.h | 2 +-
tp/Texinfo/XS/parsetexi/handle_commands.c | 8 ++------
tp/Texinfo/XS/structuring_transfo/structuring.c | 9 ++++-----
.../XS/structuring_transfo/transformations.c | 8 ++------
6 files changed, 32 insertions(+), 24 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index b89ecb7509..7d01fa4a41 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2024-02-24 Patrice Dumas <pertusus@free.fr>
+
+ * tp/Texinfo/XS/main/extra.c (add_extra_contents): replace the input
+ list argument by no_lookup. If not set, first check that the array
+ does not exist before creating it. Update callers.
+
2024-02-24 Patrice Dumas <pertusus@free.fr>
* tp/Texinfo/XS/main/extra.c (add_extra_directions): check if the
diff --git a/tp/Texinfo/XS/main/extra.c b/tp/Texinfo/XS/main/extra.c
index eed4c0c8c1..16e06a7d58 100644
--- a/tp/Texinfo/XS/main/extra.c
+++ b/tp/Texinfo/XS/main/extra.c
@@ -101,16 +101,27 @@ add_info_element_oot (ELEMENT *e, char *key, ELEMENT
*value)
}
/* Add an extra key that is a reference to an array of other
- elements (for example, 'section_childs'). */
+ elements (for example, 'section_childs').
+ Check if it already exists, unless NO_LOOKUP is set
+ if the caller knows that the array has not been set
+ already.
+*/
ELEMENT_LIST *
-add_extra_contents (ELEMENT *e, const char *key, ELEMENT_LIST *value)
+add_extra_contents (ELEMENT *e, const char *key, int no_lookup)
{
- if (!value)
- value = new_list ();
+ ELEMENT_LIST *n_list;
+ if (!no_lookup)
+ {
+ ELEMENT_LIST *e_list = lookup_extra_contents (e, key);
+ if (e_list)
+ return e_list;
+ }
+
+ n_list = new_list ();
KEY_PAIR *k = get_associated_info_key (&e->extra_info, key,
extra_contents);
- k->list = value;
- return value;
+ k->list = n_list;
+ return n_list;
}
/* Holds 3 elements corresponding to directions in enum directions.
diff --git a/tp/Texinfo/XS/main/extra.h b/tp/Texinfo/XS/main/extra.h
index c398471f61..c1cccedb26 100644
--- a/tp/Texinfo/XS/main/extra.h
+++ b/tp/Texinfo/XS/main/extra.h
@@ -22,7 +22,7 @@
void add_extra_element (ELEMENT *e, const char *key, ELEMENT *value);
void add_extra_element_oot (ELEMENT *e, char *key, ELEMENT *value);
ELEMENT_LIST *add_extra_contents (ELEMENT *e, const char *key,
- ELEMENT_LIST *value);
+ int no_lookup);
void add_extra_container (ELEMENT *e, char *key, ELEMENT *value);
const ELEMENT_LIST *add_extra_directions (ELEMENT *e, const char *key);
void add_extra_text (ELEMENT *e, char *key, ELEMENT *value);
diff --git a/tp/Texinfo/XS/parsetexi/handle_commands.c
b/tp/Texinfo/XS/parsetexi/handle_commands.c
index 8d5411394d..dc77c6ce93 100644
--- a/tp/Texinfo/XS/parsetexi/handle_commands.c
+++ b/tp/Texinfo/XS/parsetexi/handle_commands.c
@@ -940,9 +940,7 @@ handle_line_command (ELEMENT *current, char **line_inout,
else if (parent->cmd == CM_quotation
|| parent->cmd == CM_smallquotation)
{
- ELEMENT_LIST *l = lookup_extra_contents (parent, "authors");
- if (!l)
- l = add_extra_contents (parent, "authors", 0);
+ ELEMENT_LIST *l = add_extra_contents (parent, "authors", 0);
add_to_element_list (l, current);
add_extra_element (current, "quotation", parent);
found = 1; break;
@@ -1120,9 +1118,7 @@ handle_block_command (ELEMENT *current, char **line_inout,
else
{
ELEMENT_LIST *l
- = lookup_extra_contents (current_node, "menus");
- if (!l)
- l = add_extra_contents (current_node, "menus", 0);
+ = add_extra_contents (current_node, "menus", 0);
add_to_element_list (l, block);
}
}
diff --git a/tp/Texinfo/XS/structuring_transfo/structuring.c
b/tp/Texinfo/XS/structuring_transfo/structuring.c
index 0e103372bb..adeaa555f8 100644
--- a/tp/Texinfo/XS/structuring_transfo/structuring.c
+++ b/tp/Texinfo/XS/structuring_transfo/structuring.c
@@ -131,7 +131,8 @@ sectioning_structure (DOCUMENT *document)
{
const ELEMENT_LIST *section_directions
= add_extra_directions (content, "section_directions");
- ELEMENT_LIST *section_childs = new_list ();
+ ELEMENT_LIST *section_childs
+ = add_extra_contents (previous_section, "section_childs", 1);
if (level - prev_section_level > 1)
{
message_list_command_error (error_messages, options, content,
@@ -140,8 +141,6 @@ sectioning_structure (DOCUMENT *document)
level = prev_section_level + 1;
}
add_to_element_list (section_childs, content);
- add_extra_contents (previous_section, "section_childs",
- section_childs);
section_directions->list[D_up] = previous_section;
/*
if the up is unnumbered, the number information has to be kept,
@@ -265,13 +264,13 @@ sectioning_structure (DOCUMENT *document)
}
else
{
- ELEMENT_LIST *sec_root_childs = new_list ();
sec_root = new_element (ET_NONE);
+ ELEMENT_LIST *sec_root_childs
+ = add_extra_contents (sec_root, "section_childs", 1);
/* first section determines the level of the root. It is
typically -1 when there is a @top. */
add_extra_integer (sec_root, "section_level", level -1);
add_to_element_list (sec_root_childs, content);
- add_extra_contents (sec_root, "section_childs", sec_root_childs);
/*
in the tree as an out of tree element in extra */
add_extra_element_oot (content, "sectioning_root", sec_root);
diff --git a/tp/Texinfo/XS/structuring_transfo/transformations.c
b/tp/Texinfo/XS/structuring_transfo/transformations.c
index a98f09558f..049e317e88 100644
--- a/tp/Texinfo/XS/structuring_transfo/transformations.c
+++ b/tp/Texinfo/XS/structuring_transfo/transformations.c
@@ -720,9 +720,7 @@ reassociate_to_node (const char *type, ELEMENT *current,
void *argument)
}
}
}
- added_node_menus = lookup_extra_contents (added_node, "menus");
- if (!added_node_menus)
- added_node_menus = add_extra_contents (added_node, "menus", 0);
+ added_node_menus = add_extra_contents (added_node, "menus", 0);
add_to_element_list (added_node_menus, current);
}
else
@@ -908,9 +906,7 @@ prepend_new_menu_in_node_section (ELEMENT * node, ELEMENT
*section,
ELEMENT *current_menu)
{
ELEMENT *empty_line = new_element (ET_empty_line);
- ELEMENT_LIST *menus = lookup_extra_contents (node, "menus");
- if (!menus)
- menus = add_extra_contents (node, "menus", 0);
+ ELEMENT_LIST *menus = add_extra_contents (node, "menus", 0);
add_to_element_contents (section, current_menu);
text_append (&empty_line->text, "\n");