texinfo-commits
[Top][All Lists]
Advanced

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

[no subject]


From: Patrice Dumas
Date: Sat, 23 Dec 2023 11:41:50 -0500 (EST)

branch: master
commit 04b158662059a7949e582a0908a5e40822e38004
Author: Patrice Dumas <pertusus@free.fr>
AuthorDate: Sat Dec 23 16:21:27 2023 +0100

    * tp/Texinfo/Common.pm (_relate_index_entries_to_table_items_in),
    tp/Texinfo/XS/main/tree_types.h (INDEX_ENTRY_AND_INDEX),
    tp/Texinfo/XS/structuring_transfo/transformations.c
    (lookup_index_entry, relate_index_entries_to_table_items_in): add an
    extra associated_index_entry reference to the index entry information
    in the item reassociated to an index entry.
---
 ChangeLog                                          |  9 +++++++
 tp/Texinfo/Common.pm                               |  6 +++++
 tp/Texinfo/XS/main/tree_types.h                    |  1 +
 .../XS/structuring_transfo/transformations.c       | 28 ++++++++++++++++------
 .../index_entries_relate_to_item_transformation.pl |  6 +++++
 tp/t/results/xtable/item_index_transformation.pl   | 24 +++++++++++++++++++
 6 files changed, 67 insertions(+), 7 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index ec275f306e..feec871926 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2023-12-23  Patrice Dumas  <pertusus@free.fr>
+
+       * tp/Texinfo/Common.pm (_relate_index_entries_to_table_items_in),
+       tp/Texinfo/XS/main/tree_types.h (INDEX_ENTRY_AND_INDEX),
+       tp/Texinfo/XS/structuring_transfo/transformations.c
+       (lookup_index_entry, relate_index_entries_to_table_items_in): add an
+       extra associated_index_entry reference to the index entry information
+       in the item reassociated to an index entry.
+
 2023-12-23  Patrice Dumas  <pertusus@free.fr>
 
        * tp/Texinfo/XS/convert/convert_html.c (compare_footnote_id)
diff --git a/tp/Texinfo/Common.pm b/tp/Texinfo/Common.pm
index 4e06b22294..494bb9dbce 100644
--- a/tp/Texinfo/Common.pm
+++ b/tp/Texinfo/Common.pm
@@ -2420,11 +2420,13 @@ sub _relate_index_entries_to_table_items_in($$)
       # the term itself.
 
       my $index_entry;
+      my $index_element;
       foreach my $content (@{$term->{'contents'}}) {
         if ($content->{'type'}
             and $content->{'type'} eq 'index_entry_command') {
           if (!$index_entry) {
             my $index_info;
+            $index_element = $content;
             ($index_entry, $index_info)
               = Texinfo::Common::lookup_index_entry(
                               $content->{'extra'}->{'index_entry'},
@@ -2437,6 +2439,10 @@ sub _relate_index_entries_to_table_items_in($$)
           # This is better than overwriting 'entry_element', which
           # holds important information.
           $index_entry->{'entry_associated_element'} = $item;
+          # also add a reference from element to index entry in index
+          $item->{'extra'} = {} if (!$item->{'extra'});
+          $item->{'extra'}->{'associated_index_entry'}
+             = [@{$index_element->{'extra'}->{'index_entry'}}];
           last;
         }
       }
diff --git a/tp/Texinfo/XS/main/tree_types.h b/tp/Texinfo/XS/main/tree_types.h
index bd3e746726..b82ec24fbe 100644
--- a/tp/Texinfo/XS/main/tree_types.h
+++ b/tp/Texinfo/XS/main/tree_types.h
@@ -260,6 +260,7 @@ typedef struct INDEX {
 typedef struct INDEX_ENTRY_AND_INDEX {
     INDEX *index;
     INDEX_ENTRY *index_entry;
+    int entry_number;
 } INDEX_ENTRY_AND_INDEX;
 
 /* See parse_node_manual function. */
diff --git a/tp/Texinfo/XS/structuring_transfo/transformations.c 
b/tp/Texinfo/XS/structuring_transfo/transformations.c
index 303f129d8b..a6d8c02452 100644
--- a/tp/Texinfo/XS/structuring_transfo/transformations.c
+++ b/tp/Texinfo/XS/structuring_transfo/transformations.c
@@ -64,8 +64,9 @@ lookup_index_entry (ELEMENT *index_entry_info, INDEX 
**indices_information)
   if (!index_info)
     return 0;
 
-  result = malloc (sizeof (INDEX_ENTRY_AND_INDEX));
+  result = (INDEX_ENTRY_AND_INDEX *) malloc (sizeof (INDEX_ENTRY_AND_INDEX));
   result->index = index_info;
+  result->entry_number = entry_number;
   result->index_entry = 0;
   if (index_info->entries_number && entry_number <= index_info->entries_number)
     {
@@ -369,7 +370,7 @@ relate_index_entries_to_table_items_in (ELEMENT *table,
         }
       if (term->type == ET_table_term)
         {
-          INDEX_ENTRY *index_entry = 0;
+          INDEX_ENTRY_AND_INDEX *entry_idx_info = 0;
           int j;
          /*
          Relate the first index_entry_command in the 'table_term' to
@@ -380,7 +381,7 @@ relate_index_entries_to_table_items_in (ELEMENT *table,
               ELEMENT *content = term->contents.list[j];
               if (content->type == ET_index_entry_command)
                 {
-                  if (!index_entry)
+                  if (!entry_idx_info)
                     {
                       INDEX_ENTRY_AND_INDEX *idx_info;
                       ELEMENT *index_entry_info = lookup_extra_element 
(content,
@@ -388,8 +389,9 @@ relate_index_entries_to_table_items_in (ELEMENT *table,
                       idx_info = lookup_index_entry (index_entry_info,
                                                      indices_information);
                       if (idx_info->index_entry)
-                        index_entry = idx_info->index_entry;
-                      free (idx_info);
+                        entry_idx_info = idx_info;
+                      else
+                        free (idx_info);
                    }
                 }
               /* the command in the tree is CM_item, not CM_item_LINE */
@@ -398,13 +400,25 @@ relate_index_entries_to_table_items_in (ELEMENT *table,
                   if (!item)
                     item = content;
                 }
-              if (item && index_entry)
+              if (item && entry_idx_info)
                 {
+                  ELEMENT *index_entry_command = new_element (ET_NONE);
+                  ELEMENT *e = new_element (ET_NONE);
                  /*
                   This is better than overwriting 'entry_element', which
                   holds important information.
                   */
-                  index_entry->entry_associated_element = item;
+                  entry_idx_info->index_entry->entry_associated_element = item;
+              /* also add a reference from element to index entry in index */
+                  text_append (&e->text, entry_idx_info->index->name);
+                  add_to_element_contents (index_entry_command, e);
+                  e = new_element (ET_NONE);
+                  add_extra_integer (e, "integer",
+                                     entry_idx_info->entry_number);
+                  add_to_element_contents (index_entry_command, e);
+                  add_extra_misc_args (item, "associated_index_entry",
+                                       index_entry_command);
+                  free (entry_idx_info);
                   break;
                 }
             }
diff --git 
a/tp/t/results/transformations/index_entries_relate_to_item_transformation.pl 
b/tp/t/results/transformations/index_entries_relate_to_item_transformation.pl
index beb660565b..adbc5f4c38 100644
--- 
a/tp/t/results/transformations/index_entries_relate_to_item_transformation.pl
+++ 
b/tp/t/results/transformations/index_entries_relate_to_item_transformation.pl
@@ -322,6 +322,12 @@ 
$result_trees{'index_entries_relate_to_item_transformation'} = {
                         }
                       ],
                       'cmdname' => 'item',
+                      'extra' => {
+                        'associated_index_entry' => [
+                          'cp',
+                          1
+                        ]
+                      },
                       'info' => {
                         'spaces_before_argument' => {
                           'text' => ' '
diff --git a/tp/t/results/xtable/item_index_transformation.pl 
b/tp/t/results/xtable/item_index_transformation.pl
index 9508ef9e60..3d91b2df01 100644
--- a/tp/t/results/xtable/item_index_transformation.pl
+++ b/tp/t/results/xtable/item_index_transformation.pl
@@ -218,6 +218,12 @@ $result_trees{'item_index_transformation'} = {
                         }
                       ],
                       'cmdname' => 'item',
+                      'extra' => {
+                        'associated_index_entry' => [
+                          'cp',
+                          2
+                        ]
+                      },
                       'info' => {
                         'spaces_before_argument' => {
                           'text' => ' '
@@ -517,6 +523,12 @@ $result_trees{'item_index_transformation'} = {
                         }
                       ],
                       'cmdname' => 'item',
+                      'extra' => {
+                        'associated_index_entry' => [
+                          'cp',
+                          4
+                        ]
+                      },
                       'info' => {
                         'spaces_before_argument' => {
                           'text' => ' '
@@ -816,6 +828,12 @@ $result_trees{'item_index_transformation'} = {
                         }
                       ],
                       'cmdname' => 'item',
+                      'extra' => {
+                        'associated_index_entry' => [
+                          'cp',
+                          6
+                        ]
+                      },
                       'info' => {
                         'spaces_before_argument' => {
                           'text' => ' '
@@ -1139,6 +1157,12 @@ $result_trees{'item_index_transformation'} = {
                         }
                       ],
                       'cmdname' => 'item',
+                      'extra' => {
+                        'associated_index_entry' => [
+                          'cp',
+                          8
+                        ]
+                      },
                       'info' => {
                         'spaces_before_argument' => {
                           'text' => ' '



reply via email to

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