texinfo-commits
[Top][All Lists]
Advanced

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

branch master updated: * tp/Texinfo/XS/Makefile.am (libtexinfo_la_SOURCE


From: Patrice Dumas
Subject: branch master updated: * tp/Texinfo/XS/Makefile.am (libtexinfo_la_SOURCES) (IndicesXS_la_SOURCES, ConvertXS_la_SOURCES), tp/Texinfo/XS/main/manipulate_indices.c: move indices_in_conversion.c to main/ and rename as manipulate_indices.c.
Date: Wed, 31 Jan 2024 15:30:27 -0500

This is an automated email from the git hooks/post-receive script.

pertusus pushed a commit to branch master
in repository texinfo.

The following commit(s) were added to refs/heads/master by this push:
     new 01782183b3 * tp/Texinfo/XS/Makefile.am (libtexinfo_la_SOURCES) 
(IndicesXS_la_SOURCES, ConvertXS_la_SOURCES), 
tp/Texinfo/XS/main/manipulate_indices.c: move indices_in_conversion.c to main/ 
and rename as manipulate_indices.c.
01782183b3 is described below

commit 01782183b3cbeace432129e54178f1b396237758
Author: Patrice Dumas <pertusus@free.fr>
AuthorDate: Wed Jan 31 21:30:09 2024 +0100

    * tp/Texinfo/XS/Makefile.am (libtexinfo_la_SOURCES)
    (IndicesXS_la_SOURCES, ConvertXS_la_SOURCES),
    tp/Texinfo/XS/main/manipulate_indices.c: move indices_in_conversion.c
    to main/ and rename as manipulate_indices.c.
    
    * tp/Texinfo/Convert/HTML.pm (_NonXS_sort_index_entries),
    tp/Texinfo/Convert/IXIN.pm (output_ixin), tp/Texinfo/Convert/LaTeX.pm
    (_prepare_indices), tp/Texinfo/Convert/Plaintext.pm
    (process_printindex), tp/Texinfo/Document.pm (merged_indices),
    tp/init/chm.pm, tp/t/test_sort.t, tp/t/test_utils.pl: add
    merged_indices in Texinfo::Document to store and get merged indices in
    document.
    
    * tp/Texinfo/XS/convert/convert_html.c (html_sort_index_entries),
    tp/Texinfo/XS/main/converter_types.h, tp/Texinfo/XS/main/document.c
    (merged_indices, destroy_document_information_except_tree),
    tp/Texinfo/XS/main/document_types.h (MERGED_INDEX, MERGED_INDICES)
    (DOCUMENT), tp/Texinfo/XS/main/manipulate_indices.c (merge_indices)
    (destroy_merged_indices, setup_sortable_index_entries)
    (sort_indices_by_letter): add merged_indices in document to store and
    get merged indices in document.  Remove index_entries from CONVERTER.
    Move MERGED_INDEX to document_types.h, add MERGED_INDICES struct for a
    list of merged indices.
    
    * tp/Texinfo/Convert/HTML.pm (%XS_conversion_overrides)
    (_NonXS_sort_index_entries), tp/Texinfo/XS/convert/ConvertXS.xs,
    tp/Texinfo/XS/convert/convert_html.c: remove
    _XS_html_merge_index_entries and html_merge_index_entries.
---
 ChangeLog                                          | 31 +++++++++++
 tp/TODO                                            |  4 +-
 tp/Texinfo/Convert/HTML.pm                         |  9 +--
 tp/Texinfo/Convert/IXIN.pm                         |  2 +-
 tp/Texinfo/Convert/LaTeX.pm                        |  2 +-
 tp/Texinfo/Convert/Plaintext.pm                    |  2 +-
 tp/Texinfo/Document.pm                             | 13 +++++
 tp/Texinfo/XS/Makefile.am                          | 11 ++--
 tp/Texinfo/XS/convert/ConvertXS.xs                 | 12 +---
 tp/Texinfo/XS/convert/IndicesXS.xs                 |  2 +-
 tp/Texinfo/XS/convert/convert_html.c               | 22 +-------
 tp/Texinfo/XS/main/converter_types.h               |  7 ---
 tp/Texinfo/XS/main/document.c                      | 16 ++++++
 tp/Texinfo/XS/main/document.h                      |  2 +
 tp/Texinfo/XS/main/document_types.h                | 12 ++++
 .../manipulate_indices.c}                          | 64 +++++++++++++---------
 .../manipulate_indices.h}                          | 13 +++--
 tp/init/chm.pm                                     |  2 +-
 tp/t/test_sort.t                                   |  4 +-
 tp/t/test_utils.pl                                 |  3 +-
 20 files changed, 136 insertions(+), 97 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 15f39a6101..310c14d8b2 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,34 @@
+2024-01-31  Patrice Dumas  <pertusus@free.fr>
+
+       * tp/Texinfo/XS/Makefile.am (libtexinfo_la_SOURCES)
+       (IndicesXS_la_SOURCES, ConvertXS_la_SOURCES),
+       tp/Texinfo/XS/main/manipulate_indices.c: move indices_in_conversion.c
+       to main/ and rename as manipulate_indices.c.
+
+       * tp/Texinfo/Convert/HTML.pm (_NonXS_sort_index_entries),
+       tp/Texinfo/Convert/IXIN.pm (output_ixin), tp/Texinfo/Convert/LaTeX.pm
+       (_prepare_indices), tp/Texinfo/Convert/Plaintext.pm
+       (process_printindex), tp/Texinfo/Document.pm (merged_indices),
+       tp/init/chm.pm, tp/t/test_sort.t, tp/t/test_utils.pl: add
+       merged_indices in Texinfo::Document to store and get merged indices in
+       document.
+
+       * tp/Texinfo/XS/convert/convert_html.c (html_sort_index_entries),
+       tp/Texinfo/XS/main/converter_types.h, tp/Texinfo/XS/main/document.c
+       (merged_indices, destroy_document_information_except_tree),
+       tp/Texinfo/XS/main/document_types.h (MERGED_INDEX, MERGED_INDICES)
+       (DOCUMENT), tp/Texinfo/XS/main/manipulate_indices.c (merge_indices)
+       (destroy_merged_indices, setup_sortable_index_entries)
+       (sort_indices_by_letter): add merged_indices in document to store and
+       get merged indices in document.  Remove index_entries from CONVERTER.
+       Move MERGED_INDEX to document_types.h, add MERGED_INDICES struct for a
+       list of merged indices.
+
+       * tp/Texinfo/Convert/HTML.pm (%XS_conversion_overrides)
+       (_NonXS_sort_index_entries), tp/Texinfo/XS/convert/ConvertXS.xs,
+       tp/Texinfo/XS/convert/convert_html.c: remove
+       _XS_html_merge_index_entries and html_merge_index_entries.
+
 2024-01-31  Patrice Dumas  <pertusus@free.fr>
 
        * doc/texi2any_api.texi (Conversion General Information),
diff --git a/tp/TODO b/tp/TODO
index 0e68146feb..110c654bf9 100644
--- a/tp/TODO
+++ b/tp/TODO
@@ -65,9 +65,7 @@ Document *XS_EXTERNAL_FORMATTING *XS_EXTERNAL_CONVERSION?
 Delayed bugs
 ============
 
-Texinfo::Indices::merge_indices($indices_information); result should
-probably be stored in a document and actually be done on demand once for
-all the converters and cached.  Probably with an XS override.
+Add XS override for Document merged_indices?
 
 Sorting indices in C with strxfrm_l using the "en_US.utf-8" locale with
 LC_COLLATE_MASK is quite consistent with perl for number and letters, but
diff --git a/tp/Texinfo/Convert/HTML.pm b/tp/Texinfo/Convert/HTML.pm
index aca925db19..16f7802de9 100644
--- a/tp/Texinfo/Convert/HTML.pm
+++ b/tp/Texinfo/Convert/HTML.pm
@@ -265,8 +265,6 @@ my %XS_conversion_overrides = (
 
   "Texinfo::Convert::HTML::_XS_get_index_entries_sorted_by_letter"
    => "Texinfo::Convert::ConvertXS::get_index_entries_sorted_by_letter",
-  "Texinfo::Convert::HTML::_XS_html_merge_index_entries"
-   => "Texinfo::Convert::ConvertXS::html_merge_index_entries",
   "Texinfo::Convert::HTML::_XS_only_sort_index_entries"
    => "Texinfo::Convert::ConvertXS::html_sort_index_entries",
   "Texinfo::Convert::HTML::_prepare_conversion_units"
@@ -10295,10 +10293,6 @@ sub _XS_get_index_entries_sorted_by_letter($$)
 {
 }
 
-sub _XS_html_merge_index_entries($)
-{
-}
-
 sub _NonXS_sort_index_entries($)
 {
   my $self = shift;
@@ -10311,7 +10305,7 @@ sub _NonXS_sort_index_entries($)
   if ($indices_information) {
 
     my $merged_index_entries
-        = Texinfo::Indices::merge_indices($indices_information);
+        = $self->{'document'}->merged_indices();
     my $index_entries_sort_strings;
 
     ($self->{'index_entries_by_letter'}, $index_entries_sort_strings)
@@ -10323,7 +10317,6 @@ sub _NonXS_sort_index_entries($)
     if ($self->{'converter_descriptor'} and $XS_convert) {
       _XS_get_index_entries_sorted_by_letter($self,
                                  $self->{'index_entries_by_letter'});
-      _XS_html_merge_index_entries($self);
     }
   }
 }
diff --git a/tp/Texinfo/Convert/IXIN.pm b/tp/Texinfo/Convert/IXIN.pm
index a7936e71b3..879485c5c3 100644
--- a/tp/Texinfo/Convert/IXIN.pm
+++ b/tp/Texinfo/Convert/IXIN.pm
@@ -708,7 +708,7 @@ sub output_ixin($$)
 
   if ($indices_information) {
     my $merged_index_entries
-        = Texinfo::Indices::merge_indices($indices_information);
+        = $self->{'document'}->merged_indices();
     my ($entries, $index_entries_sort_strings)
       = Texinfo::Indices::sort_indices_by_index(undef, $self,
                                            $merged_index_entries,
diff --git a/tp/Texinfo/Convert/LaTeX.pm b/tp/Texinfo/Convert/LaTeX.pm
index 2171d0891c..09a4fb6c3d 100644
--- a/tp/Texinfo/Convert/LaTeX.pm
+++ b/tp/Texinfo/Convert/LaTeX.pm
@@ -957,7 +957,7 @@ sub _prepare_indices($)
     $self->{'index_formatting_text_options'}
       = Texinfo::Indices::setup_index_entry_keys_formatting($self);
     my $merged_index_entries
-        = Texinfo::Indices::merge_indices($indices_information);
+        = $self->{'document'}->merged_indices();
     # select non empty indices
     if ($merged_index_entries) {
       $self->{'index_entries'} = {};
diff --git a/tp/Texinfo/Convert/Plaintext.pm b/tp/Texinfo/Convert/Plaintext.pm
index 9273a04a90..a08248a867 100644
--- a/tp/Texinfo/Convert/Plaintext.pm
+++ b/tp/Texinfo/Convert/Plaintext.pm
@@ -1519,7 +1519,7 @@ sub process_printindex($$;$)
   if (!defined($self->{'index_entries'}) and $indices_information) {
 
     my $merged_index_entries
-      = Texinfo::Indices::merge_indices($indices_information);
+      = $self->{'document'}->merged_indices();
     my $index_entries_sort_strings;
     ($self->{'index_entries'}, $index_entries_sort_strings)
       = Texinfo::Indices::sort_indices_by_index(undef, $self,
diff --git a/tp/Texinfo/Document.pm b/tp/Texinfo/Document.pm
index 50c109e9e6..ec984315ba 100644
--- a/tp/Texinfo/Document.pm
+++ b/tp/Texinfo/Document.pm
@@ -191,6 +191,19 @@ sub sections_list($)
   return $self->{'sections_list'};
 }
 
+sub merged_indices($)
+{
+  my $self = shift;
+
+  if ($self->{'indices'}) {
+    if (!$self->{'merged_indices'}) {
+      $self->{'merged_indices'}
+        = Texinfo::Indices::merge_indices($self->{'indices'});
+    }
+  }
+  return $self->{'merged_indices'};
+}
+
 # only set if the Texinfo::Document object has been set up by XS code.
 sub document_descriptor($)
 {
diff --git a/tp/Texinfo/XS/Makefile.am b/tp/Texinfo/XS/Makefile.am
index f46c533123..5738269bbb 100644
--- a/tp/Texinfo/XS/Makefile.am
+++ b/tp/Texinfo/XS/Makefile.am
@@ -157,6 +157,8 @@ libtexinfo_la_SOURCES= \
                      main/translations.h \
                      main/document.c \
                      main/document.h \
+                     main/manipulate_indices.h \
+                     main/manipulate_indices.c \
                      main/output_unit.c \
                      main/output_unit.h \
                      parsetexi/api.c \
@@ -372,14 +374,11 @@ nodist_IndicesXS_la_SOURCES = \
                     convert/IndicesXS.c
 CLEANFILES += \
                     convert/IndicesXS.c
-IndicesXS_la_SOURCES = \
-                    convert/indices_in_conversion.h \
-                    convert/indices_in_conversion.c
 
 EXTRA_DIST += convert/IndicesXS.xs
 
 # locate include files under out-of-source builds.
-IndicesXS_la_CPPFLAGS = -I$(srcdir)/main -I$(srcdir)/convert $(AM_CPPFLAGS) 
$(GNULIB_CPPFLAGS) $(XSLIBS_CPPFLAGS)
+IndicesXS_la_CPPFLAGS = -I$(srcdir)/main $(AM_CPPFLAGS) $(GNULIB_CPPFLAGS) 
$(XSLIBS_CPPFLAGS)
 IndicesXS_la_CFLAGS = $(XSLIBS_CFLAGS)
 IndicesXS_la_LIBADD = libtexinfoxs.la libtexinfo.la 
$(top_builddir)/gnulib/lib/libgnu.la
 IndicesXS_la_LDFLAGS = $(XSLIBS_LDFLAGS) $(LTLIBICONV) $(LTLIBUNISTRING)
@@ -403,9 +402,7 @@ ConvertXS_la_SOURCES = \
                        convert/converter.h \
                        convert/converter.c \
                        convert/convert_html.h \
-                       convert/convert_html.c \
-                       convert/indices_in_conversion.h \
-                       convert/indices_in_conversion.c
+                       convert/convert_html.c
 
 EXTRA_DIST += convert/ConvertXS.xs
 
diff --git a/tp/Texinfo/XS/convert/ConvertXS.xs 
b/tp/Texinfo/XS/convert/ConvertXS.xs
index 750ed03878..42a9179379 100644
--- a/tp/Texinfo/XS/convert/ConvertXS.xs
+++ b/tp/Texinfo/XS/convert/ConvertXS.xs
@@ -39,7 +39,7 @@
 #include "errors.h"
 #include "convert_to_text.h"
 #include "convert_to_texinfo.h"
-#include "indices_in_conversion.h"
+#include "manipulate_indices.h"
 #include "command_stack.h"
 #include "document.h"
 #include "get_perl_info.h"
@@ -1689,16 +1689,6 @@ html_check_htmlxref_already_warned (SV *converter_in, 
manual_name, SV *source_in
     OUTPUT:
          RETVAL
 
-void
-html_merge_index_entries (SV *converter_in)
-      PREINIT:
-         CONVERTER *self;
-     CODE:
-         self = get_sv_converter (converter_in,
-                                  "html_merge_index_entries");
-         if (self)
-           html_merge_index_entries (self);
-
 void
 html_sort_index_entries (SV *converter_in)
       PREINIT:
diff --git a/tp/Texinfo/XS/convert/IndicesXS.xs 
b/tp/Texinfo/XS/convert/IndicesXS.xs
index 440d4bd827..c701377171 100644
--- a/tp/Texinfo/XS/convert/IndicesXS.xs
+++ b/tp/Texinfo/XS/convert/IndicesXS.xs
@@ -37,7 +37,7 @@
 #include "utils.h"
  */
 #include "document.h"
-#include "indices_in_conversion.h"
+#include "manipulate_indices.h"
 #include "get_perl_info.h"
 /* for newSVpv_utf8 */
 #include "build_perl_info.h"
diff --git a/tp/Texinfo/XS/convert/convert_html.c 
b/tp/Texinfo/XS/convert/convert_html.c
index f9baefb3ee..926e921b49 100644
--- a/tp/Texinfo/XS/convert/convert_html.c
+++ b/tp/Texinfo/XS/convert/convert_html.c
@@ -42,7 +42,7 @@
 #include "output_unit.h"
 #include "converter.h"
 #include "node_name_normalization.h"
-#include "indices_in_conversion.h"
+#include "manipulate_indices.h"
 #include "convert_to_texinfo.h"
 #include "translations.h"
 #include "convert_utils.h"
@@ -4669,27 +4669,16 @@ get_copiable_anchor (CONVERTER *self, const char *id)
   return 0;
 }
 
-void
-html_merge_index_entries (CONVERTER *self)
-{
-  if (self->document->index_names)
-    {
-      INDEX **index_names = self->document->index_names;
-      MERGED_INDEX *merged_index_entries = merge_indices (index_names);
-      self->index_entries = merged_index_entries;
-    }
-}
-
 void
 html_sort_index_entries (CONVERTER *self)
 {
-  html_merge_index_entries (self);
+  MERGED_INDICES *merged_indices = merge_indices (self->document->index_names);
 
   if (self->document->index_names)
     {
       self->index_entries_by_letter
         = sort_indices_by_letter (&self->error_messages, self->conf,
-                                  self->index_entries,
+                                  merged_indices,
                                   self->document->index_names);
     }
 }
@@ -16649,11 +16638,6 @@ html_reset_converter (CONVERTER *self)
       self->added_title_tree = 0;
     }
 
-  if (self->index_entries)
-    {
-      destroy_merged_indices (self->index_entries);
-      self->index_entries = 0;
-    }
   if (self->index_entries_by_letter)
     {
       destroy_indices_sorted_by_letter (self->index_entries_by_letter);
diff --git a/tp/Texinfo/XS/main/converter_types.h 
b/tp/Texinfo/XS/main/converter_types.h
index a3264fc5f0..4cbef7253d 100644
--- a/tp/Texinfo/XS/main/converter_types.h
+++ b/tp/Texinfo/XS/main/converter_types.h
@@ -317,12 +317,6 @@ typedef struct HTML_SHARED_CONVERSION_STATE {
     /* formatted_nodedescriptions */
 } HTML_SHARED_CONVERSION_STATE;
 
-typedef struct MERGED_INDEX {
-    char *name;
-    INDEX_ENTRY *index_entries;
-    size_t entries_number;
-} MERGED_INDEX;
-
 typedef struct LETTER_INDEX_ENTRIES {
     char *letter;
     INDEX_ENTRY **entries;
@@ -691,7 +685,6 @@ typedef struct CONVERTER {
     STRING_LIST small_strings;
 
     DOCUMENT *document;
-    MERGED_INDEX *index_entries;
     INDEX_SORTED_BY_LETTER *index_entries_by_letter;
     int document_units_descriptor;
 
diff --git a/tp/Texinfo/XS/main/document.c b/tp/Texinfo/XS/main/document.c
index 026a939e66..e72e6e9ed7 100644
--- a/tp/Texinfo/XS/main/document.c
+++ b/tp/Texinfo/XS/main/document.c
@@ -31,6 +31,7 @@
 /* for delete_global_info and wipe_index */
 #include "utils.h"
 #include "convert_to_text.h"
+#include "manipulate_indices.h"
 #include "document.h"
 
 /* note that each time the document list is reallocated, pointers
@@ -133,6 +134,19 @@ register_document_options (DOCUMENT *document, OPTIONS 
*options)
   document->options = options;
 }
 
+const MERGED_INDICES *
+merged_indices (DOCUMENT *document)
+{
+  if (document->index_names)
+    {
+      if (!document->merged_indices)
+        {
+          document->merged_indices = merge_indices (document->index_names);
+        }
+    }
+  return document->merged_indices;
+}
+
 void
 register_document_convert_index_text_options (DOCUMENT *document,
                                               TEXT_OPTIONS *text_options)
@@ -175,6 +189,8 @@ destroy_document_information_except_tree (DOCUMENT 
*document)
         }
       if (document->convert_index_text_options)
         destroy_text_options (document->convert_index_text_options);
+      if (document->merged_indices)
+        destroy_merged_indices (document->merged_indices);
     }
 }
 
diff --git a/tp/Texinfo/XS/main/document.h b/tp/Texinfo/XS/main/document.h
index f9dbd64e06..6cb843a838 100644
--- a/tp/Texinfo/XS/main/document.h
+++ b/tp/Texinfo/XS/main/document.h
@@ -35,6 +35,8 @@ void register_document_options (DOCUMENT *document, OPTIONS 
*options);
 void register_document_convert_index_text_options (DOCUMENT *document,
                                          struct TEXT_OPTIONS *text_options);
 
+const MERGED_INDICES *merged_indices (DOCUMENT *document);
+
 void remove_document_descriptor (int document_descriptor);
 TREE_AND_STRINGS *unregister_document_descriptor_tree (int 
document_descriptor);
 void clear_document_errors (int document_descriptor);
diff --git a/tp/Texinfo/XS/main/document_types.h 
b/tp/Texinfo/XS/main/document_types.h
index 56cbfd449c..cb69e2e462 100644
--- a/tp/Texinfo/XS/main/document_types.h
+++ b/tp/Texinfo/XS/main/document_types.h
@@ -66,10 +66,22 @@ typedef struct GLOBAL_INFO {
     char *input_perl_encoding;
 } GLOBAL_INFO;
 
+typedef struct MERGED_INDEX {
+    char *name;
+    INDEX_ENTRY *index_entries;
+    size_t entries_number;
+} MERGED_INDEX;
+
+typedef struct MERGED_INDICES {
+    size_t number;
+    MERGED_INDEX *indices;
+} MERGED_INDICES;
+
 typedef struct DOCUMENT {
     int descriptor;
     ELEMENT *tree;
     INDEX **index_names;
+    MERGED_INDICES *merged_indices;
     FLOAT_RECORD_LIST *floats;
     LISTOFFLOATS_TYPE_LIST *listoffloats;
     ELEMENT_LIST *internal_references;
diff --git a/tp/Texinfo/XS/convert/indices_in_conversion.c 
b/tp/Texinfo/XS/main/manipulate_indices.c
similarity index 94%
rename from tp/Texinfo/XS/convert/indices_in_conversion.c
rename to tp/Texinfo/XS/main/manipulate_indices.c
index 271d93daca..50c05ea9fe 100644
--- a/tp/Texinfo/XS/convert/indices_in_conversion.c
+++ b/tp/Texinfo/XS/main/manipulate_indices.c
@@ -23,6 +23,7 @@
 #include "unistr.h"
 
 #include "tree_types.h"
+#include "document_types.h"
 #include "converter_types.h"
 #include "utils.h"
 #include "extra.h"
@@ -31,19 +32,26 @@
 #include "unicode.h"
 #include "convert_to_text.h"
 #include "convert_to_texinfo.h"
-#include "indices_in_conversion.h"
+#include "manipulate_indices.h"
 
 /* corresponding perl code in Texinfo::Indices */
 
-MERGED_INDEX *
+MERGED_INDICES *
 merge_indices (INDEX **index_names)
 {
   size_t merged_indices_space = 4;
   size_t merged_indices_number = 0;
   INDEX **i, *idx;
-  MERGED_INDEX *merged_indices
+
+  if (!index_names)
+    return 0;
+
+  MERGED_INDEX *merged_indices_list
     = (MERGED_INDEX *) malloc (sizeof (MERGED_INDEX) * merged_indices_space);
 
+  MERGED_INDICES *merged_indices
+    = (MERGED_INDICES *) malloc (sizeof (MERGED_INDICES));
+
   for (i = index_names; (idx = *i); i++)
     {
       if (idx->index_entries && idx->entries_number)
@@ -62,9 +70,9 @@ merge_indices (INDEX **index_names)
 
           for (j = 0; j < merged_indices_number; j++)
             {
-              if (!strcmp (merged_indices[j].name, in_idx_name))
+              if (!strcmp (merged_indices_list[j].name, in_idx_name))
                 {
-                  merged_idx = &merged_indices[j];
+                  merged_idx = &merged_indices_list[j];
                   break;
                 }
             }
@@ -74,11 +82,11 @@ merge_indices (INDEX **index_names)
               if (merged_indices_number == merged_indices_space)
                 {
                   merged_indices_space += 5;
-                  merged_indices
-                   = realloc (merged_indices, merged_indices_space
+                  merged_indices_list
+                   = realloc (merged_indices_list, merged_indices_space
                                                 * sizeof (MERGED_INDEX));
                 }
-              merged_idx = &merged_indices[merged_indices_number];
+              merged_idx = &merged_indices_list[merged_indices_number];
               merged_idx->name = in_idx_name;
               merged_idx->entries_number = ultimate_idx->entries_number;
               merged_idx->index_entries
@@ -101,21 +109,27 @@ merge_indices (INDEX **index_names)
         }
     }
   /* set to the final size, including a trailing MERGED_INDEX filled with 0 */
-  merged_indices = realloc (merged_indices,
+  merged_indices_list = realloc (merged_indices_list,
                             (merged_indices_number +1) * sizeof 
(MERGED_INDEX));
-  memset (&merged_indices[merged_indices_number], 0, sizeof (MERGED_INDEX));
+  memset (&merged_indices_list[merged_indices_number], 0,
+          sizeof (MERGED_INDEX));
+
+  merged_indices->indices = merged_indices_list;
+  merged_indices->number = merged_indices_number;
+
   return merged_indices;
 }
 
 void
-destroy_merged_indices (MERGED_INDEX *merged_indices)
+destroy_merged_indices (MERGED_INDICES *merged_indices)
 {
-  MERGED_INDEX *index;
+  size_t i;
 
-  for (index = merged_indices; index->name; index++)
+  for (i = 0; i < merged_indices->number; i++)
     {
-      free (index->index_entries);
+      free (merged_indices->indices[i].index_entries);
     }
+  free (merged_indices->indices);
   free (merged_indices);
 }
 
@@ -274,10 +288,9 @@ index_entry_element_sort_string_key (INDEX_ENTRY 
*main_entry,
 
 INDICES_SORTABLE_ENTRIES *
 setup_sortable_index_entries (ERROR_MESSAGE_LIST *error_messages,
-                      OPTIONS *options, MERGED_INDEX *index_entries,
+                      OPTIONS *options, MERGED_INDICES *merged_indices,
                       INDEX **indices_information, locale_t *collation_locale)
 {
-  size_t indices_nr;
   size_t i;
   TEXT_OPTIONS *convert_text_options
     = setup_index_entry_keys_formatting (options);
@@ -292,24 +305,21 @@ setup_sortable_index_entries (ERROR_MESSAGE_LIST 
*error_messages,
   #endif
   #endif
 
-  for (indices_nr = 0; index_entries[indices_nr].name; indices_nr++)
-    {}
-
-  if (indices_nr == 0)
+  if (merged_indices->number <= 0)
     return 0;
 
   INDICES_SORTABLE_ENTRIES *indices_sortable_entries
     = (INDICES_SORTABLE_ENTRIES *) malloc (sizeof (INDICES_SORTABLE_ENTRIES));
 
-  indices_sortable_entries->number = indices_nr;
+  indices_sortable_entries->number = merged_indices->number;
   indices_sortable_entries->indices = (INDEX_SORTABLE_ENTRIES *)
-    malloc (indices_nr * sizeof (INDEX_SORTABLE_ENTRIES));
+    malloc (merged_indices->number * sizeof (INDEX_SORTABLE_ENTRIES));
   memset (indices_sortable_entries->indices, 0,
-          indices_nr * sizeof (INDEX_SORTABLE_ENTRIES));
+          merged_indices->number * sizeof (INDEX_SORTABLE_ENTRIES));
 
-  for (i = 0; i < indices_nr; i++)
+  for (i = 0; i < merged_indices->number; i++)
     {
-      MERGED_INDEX *index = &index_entries[i];
+      MERGED_INDEX *index = &merged_indices->indices[i];
       INDEX_SORTABLE_ENTRIES *sortable_index_entries
         = &indices_sortable_entries->indices[i];
       if (index->entries_number > 0)
@@ -551,7 +561,7 @@ compare_sortable_index_entry (const void *a, const void *b)
 
 INDEX_SORTED_BY_LETTER *
 sort_indices_by_letter (ERROR_MESSAGE_LIST *error_messages,
-                        OPTIONS *options, MERGED_INDEX *index_entries,
+                        OPTIONS *options, MERGED_INDICES *merged_indices,
                               INDEX **indices_information)
 {
   size_t i;
@@ -560,7 +570,7 @@ sort_indices_by_letter (ERROR_MESSAGE_LIST *error_messages,
   static INDEX_LETTERS_SORTABLE_ENTRIES index_letters_sortable_entries;
 
   INDICES_SORTABLE_ENTRIES *indices_sortable_entries
-    = setup_sortable_index_entries (error_messages, options, index_entries,
+    = setup_sortable_index_entries (error_messages, options, merged_indices,
                                     indices_information, &collation_locale);
 
   if (!indices_sortable_entries || indices_sortable_entries->number <= 0)
diff --git a/tp/Texinfo/XS/convert/indices_in_conversion.h 
b/tp/Texinfo/XS/main/manipulate_indices.h
similarity index 81%
rename from tp/Texinfo/XS/convert/indices_in_conversion.h
rename to tp/Texinfo/XS/main/manipulate_indices.h
index f69142c7cf..14f500527c 100644
--- a/tp/Texinfo/XS/convert/indices_in_conversion.h
+++ b/tp/Texinfo/XS/main/manipulate_indices.h
@@ -1,8 +1,9 @@
-/* indices_in_conversion.h - definitions for indices_in_conversion.c */
-#ifndef INDICES_IN_CONVERSION_H
-#define INDICES_IN_CONVERSION_H
+/* manipulate_indices.h - definitions for manipulate_indices.c */
+#ifndef MANIPULATE_INDICES_H
+#define MANIPULATE_INDICES_H
 
 #include "tree_types.h"
+#include "document_types.h"
 #include "convert_to_text.h"
 
 typedef struct SORTABLE_INDEX_SUBENTRY {
@@ -31,8 +32,8 @@ typedef struct INDICES_SORTABLE_ENTRIES {
     INDEX_SORTABLE_ENTRIES *indices;
 } INDICES_SORTABLE_ENTRIES;
 
-MERGED_INDEX *merge_indices (INDEX **index_names);
-void destroy_merged_indices (MERGED_INDEX *merged_indices);
+MERGED_INDICES *merge_indices (INDEX **index_names);
+void destroy_merged_indices (MERGED_INDICES *merged_indices);
 
 void destroy_indices_sorted_by_letter (
          INDEX_SORTED_BY_LETTER *indices_entries_by_letter);
@@ -47,6 +48,6 @@ char *index_entry_element_sort_string (INDEX_ENTRY 
*main_entry,
 
 INDEX_SORTED_BY_LETTER *sort_indices_by_letter (
                         ERROR_MESSAGE_LIST *error_messages,
-                        OPTIONS *options, MERGED_INDEX *index_entries,
+                        OPTIONS *options, MERGED_INDICES *merged_indices,
                               INDEX **indices_information);
 #endif
diff --git a/tp/init/chm.pm b/tp/init/chm.pm
index b569b9e120..903d0c4b9f 100644
--- a/tp/init/chm.pm
+++ b/tp/init/chm.pm
@@ -250,7 +250,7 @@ sub chm_init($)
   my $index_entries;
   if ($indices_information) {
     my $merged_index_entries
-        = Texinfo::Indices::merge_indices($indices_information);
+        = $self->{'document'}->merged_indices();
 
     my $index_entries_sort_strings;
     ($index_entries, $index_entries_sort_strings)
diff --git a/tp/t/test_sort.t b/tp/t/test_sort.t
index 10e53f4e2e..51b225e446 100644
--- a/tp/t/test_sort.t
+++ b/tp/t/test_sort.t
@@ -46,7 +46,7 @@ $tree = $document->tree();
 
 my $registrar = $parser->registered_errors();
 my $indices_information = $document->indices_information();
-my $index_entries = Texinfo::Indices::merge_indices($indices_information);
+my $index_entries = $document->merged_indices();
 my $main_configuration = Texinfo::MainConfig::new({'ENABLE_ENCODING' => 1});
 Texinfo::Common::set_output_encodings($main_configuration, $document);
 $main_configuration->{'document_descriptor'}
@@ -126,7 +126,7 @@ $tree = $document->tree();
 
 $registrar = $parser->registered_errors();
 $indices_information = $document->indices_information();
-$index_entries = Texinfo::Indices::merge_indices($indices_information);
+$index_entries = $document->merged_indices();
 $main_configuration->{'document_descriptor'}
   = $document->document_descriptor();
 ($sorted_index_entries, $index_entries_sort_strings)
diff --git a/tp/t/test_utils.pl b/tp/t/test_utils.pl
index 6a356f2033..1de6b427d6 100644
--- a/tp/t/test_utils.pl
+++ b/tp/t/test_utils.pl
@@ -1165,8 +1165,7 @@ sub test($$)
 
   my $indices_information = $document->indices_information();
   # FIXME maybe it would be good to compare $merged_index_entries?
-  my $merged_index_entries
-     = Texinfo::Indices::merge_indices($indices_information);
+  my $merged_index_entries = $document->merged_indices();
 
   # only print indices information if it differs from the default
   # indices



reply via email to

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