texinfo-commits
[Top][All Lists]
Advanced

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

branch master updated: * doc/texi2any_api.texi (Conversion General Infor


From: Patrice Dumas
Subject: branch master updated: * doc/texi2any_api.texi (Conversion General Information), tp/Texinfo/Convert/HTML.pm (%available_converter_info) (_NonXS_sort_index_entries), tp/init/chm.pm (chm_init): remove 'index_entries' from the HTML general information API, it can easily be setup in user code.
Date: Wed, 31 Jan 2024 10:41:21 -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 2acdb832c4 * doc/texi2any_api.texi (Conversion General Information), 
tp/Texinfo/Convert/HTML.pm (%available_converter_info) 
(_NonXS_sort_index_entries), tp/init/chm.pm (chm_init): remove 'index_entries' 
from the HTML general information API, it can easily be setup in user code.
2acdb832c4 is described below

commit 2acdb832c475284ba80b48ee25f94b8ca29a5c85
Author: Patrice Dumas <pertusus@free.fr>
AuthorDate: Wed Jan 31 16:41:09 2024 +0100

    * doc/texi2any_api.texi (Conversion General Information),
    tp/Texinfo/Convert/HTML.pm (%available_converter_info)
    (_NonXS_sort_index_entries), tp/init/chm.pm (chm_init): remove
    'index_entries' from the HTML general information API, it can easily
    be setup in user code.
    
    * tp/Texinfo/XS/main/build_perl_info.c
    (build_sorted_indices_by_letter): add to be able to build Perl sorted
    indices from C data.
    
    * tp/Texinfo/Indices.pm (%XS_convert_overrides)
    (get_converter_indices_sorted_by_letter),
    tp/Texinfo/XS/convert/IndicesXS.xs
    (get_converter_indices_sorted_by_letter): add an XS interface to get
    indices sorted by letter from a converter.
    
    * tp/Texinfo/Convert/HTML.pm (get_info): get 'index_entries_by_letter'
    on demand from XS if not already set.
---
 ChangeLog                            |  21 +++++++
 doc/texi2any_api.texi                |   5 ++
 tp/TODO                              |   4 ++
 tp/Texinfo/Convert/HTML.pm           |  19 +++++-
 tp/Texinfo/Indices.pm                |  11 ++++
 tp/Texinfo/XS/convert/IndicesXS.xs   |  30 +++++++++
 tp/Texinfo/XS/main/build_perl_info.c | 116 +++++++++++++++++++++++++++++++++--
 tp/Texinfo/XS/main/build_perl_info.h |   6 +-
 tp/init/chm.pm                       |  12 +++-
 9 files changed, 215 insertions(+), 9 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 3bd112d0cc..15f39a6101 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,24 @@
+2024-01-31  Patrice Dumas  <pertusus@free.fr>
+
+       * doc/texi2any_api.texi (Conversion General Information),
+       tp/Texinfo/Convert/HTML.pm (%available_converter_info)
+       (_NonXS_sort_index_entries), tp/init/chm.pm (chm_init): remove
+       'index_entries' from the HTML general information API, it can easily
+       be setup in user code.
+
+       * tp/Texinfo/XS/main/build_perl_info.c
+       (build_sorted_indices_by_letter): add to be able to build Perl sorted
+       indices from C data.
+
+       * tp/Texinfo/Indices.pm (%XS_convert_overrides)
+       (get_converter_indices_sorted_by_letter),
+       tp/Texinfo/XS/convert/IndicesXS.xs
+       (get_converter_indices_sorted_by_letter): add an XS interface to get
+       indices sorted by letter from a converter.
+
+       * tp/Texinfo/Convert/HTML.pm (get_info): get 'index_entries_by_letter'
+       on demand from XS if not already set.
+
 2024-01-30  Patrice Dumas  <pertusus@free.fr>
 
        Add gnulib module for XS
diff --git a/doc/texi2any_api.texi b/doc/texi2any_api.texi
index 0bf8b2c78c..786aeeeb76 100644
--- a/doc/texi2any_api.texi
+++ b/doc/texi2any_api.texi
@@ -1853,9 +1853,14 @@ hash reference with format names as key and a true value 
as value if
 the format is expanded, according to command-line and init file
 information.
 
+@c remove from the API at leat temporary such as not to worry with
+@c that to sort out XS/nonXS interfaces for index_entries_by_letter
+@c which is actually used
+@ignore
 @item index_entries
 Information on indices taking into account merged indices.
 @xref{Texinfo::Structuring $merged_entries = 
merge_indices($index_names),,Texinfo::Structuring::merge_indices, 
texi2any_internals}.
+@end ignore
 
 @item index_entries_by_letter
 Index entries sorted by letter. @xref{Texinfo::Structuring 
($index_entries_sorted@comma{} $index_entries_sort_strings) = 
sort_indices($registrar@comma{} $configuration_information@comma{} 
$merged_index_entries@comma{} 
$sort_by_letter),,Texinfo::Structuring::sort_indices,texi2any_internals}.
diff --git a/tp/TODO b/tp/TODO
index ed9e3901dc..0e68146feb 100644
--- a/tp/TODO
+++ b/tp/TODO
@@ -65,6 +65,10 @@ 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.
+
 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
 leads to a different output than with Perl for non alphanumeric characters,
diff --git a/tp/Texinfo/Convert/HTML.pm b/tp/Texinfo/Convert/HTML.pm
index ccbc2473ad..aca925db19 100644
--- a/tp/Texinfo/Convert/HTML.pm
+++ b/tp/Texinfo/Convert/HTML.pm
@@ -2307,7 +2307,7 @@ my %available_converter_info;
 foreach my $converter_info ('copying_comment', 'current_filename',
    'destination_directory', 'document', 'document_name',
    'documentdescription_string', 'expanded_formats',
-   'index_entries', 'index_entries_by_letter', 'jslicenses',
+   'index_entries_by_letter', 'jslicenses',
    'line_break_element', 'non_breaking_space', 'paragraph_symbol',
    'simpletitle_command_name', 'simpletitle_tree',
    'title_string', 'title_tree', 'title_titlepage') {
@@ -2330,7 +2330,23 @@ sub get_info($$)
     }
   #} else {
   #  cluck();
+  } elsif ($converter_info eq 'index_entries_by_letter'
+           and $self->{'document'} and $self->{'converter_descriptor'}
+           and $XS_convert) {
+    my $indices_information;
+    if ($self->{'document'}) {
+      $indices_information = $self->{'document'}->indices_information();
+    }
+
+    if ($indices_information) {
+      $self->{'index_entries_by_letter'}
+       = Texinfo::Indices::get_converter_indices_sorted_by_letter($self,
+                                                       $indices_information);
+
+      return $self->{'index_entries_by_letter'};
+    }
   }
+  return undef;
 }
 
 # This function should be used in formatting functions when some
@@ -10302,7 +10318,6 @@ sub _NonXS_sort_index_entries($)
             = Texinfo::Indices::sort_indices_by_letter(undef, $self,
                                                $merged_index_entries,
                                                $indices_information);
-    $self->{'index_entries'} = $merged_index_entries;
 
     # pass sorted index entries to XS for a reproducible sorting.
     if ($self->{'converter_descriptor'} and $XS_convert) {
diff --git a/tp/Texinfo/Indices.pm b/tp/Texinfo/Indices.pm
index c1be210186..012b251027 100644
--- a/tp/Texinfo/Indices.pm
+++ b/tp/Texinfo/Indices.pm
@@ -80,6 +80,8 @@ my %XS_convert_overrides = (
     => "Texinfo::IndicesXS::index_entry_element_sort_string",
   "Texinfo::Indices::setup_index_entry_keys_formatting",
     => "Texinfo::IndicesXS::setup_index_entry_keys_formatting",
+  "Texinfo::Indices::get_converter_indices_sorted_by_letter"
+    => "Texinfo::IndicesXS::get_converter_indices_sorted_by_letter",
 
 );
 
@@ -598,6 +600,15 @@ sub sort_indices_by_letter($$$$;$)
   return ($sorted_index_entries, $index_entries_sort_strings);
 }
 
+# Perl version should not be called, only used for the XS override.
+sub get_converter_indices_sorted_by_letter($$)
+{
+  my $converter = shift;
+  my $indices_information = shift;
+
+  return undef;
+}
+
 sub merge_indices($)
 {
   my $indices_information = shift;
diff --git a/tp/Texinfo/XS/convert/IndicesXS.xs 
b/tp/Texinfo/XS/convert/IndicesXS.xs
index 94bd73e1ee..440d4bd827 100644
--- a/tp/Texinfo/XS/convert/IndicesXS.xs
+++ b/tp/Texinfo/XS/convert/IndicesXS.xs
@@ -154,3 +154,33 @@ index_entry_element_sort_string (SV 
*customization_info_sv, SV *main_entry_sv, S
     OUTPUT:
          RETVAL
 
+SV *
+get_converter_indices_sorted_by_letter (SV *converter_sv, SV 
*indices_information)
+     PREINIT:
+        CONVERTER *self;
+     CODE:
+        self = get_sv_converter (converter_sv, "get_indices_sorted_by_letter");
+        if (self)
+          {
+            RETVAL
+             = build_sorted_indices_by_letter (self->index_entries_by_letter,
+                                               indices_information);
+          }
+        else
+          RETVAL = newSV (0);
+    OUTPUT:
+         RETVAL
+
+
+#void
+#sort_indices_by_letter (SV *registrar, SV *customization_information, SV 
*index_entries, SV *indices_information, ...)
+#     PROTOTYPE: $$$$;$
+#     PREINIT:
+#         SV *sorted_index_entries_sv;
+#      PPCODE:
+#         sorted_index_entries_sv = build_sorted_indices_by_letter (
+#
+#         EXTEND(SP, 2);
+#         PUSHs(sv_2mortal(sorted_index_entries_sv));
+#         PUSHs(sv_2mortal(result_sv));
+
diff --git a/tp/Texinfo/XS/main/build_perl_info.c 
b/tp/Texinfo/XS/main/build_perl_info.c
index 9dcc6f7b87..4977e7a594 100644
--- a/tp/Texinfo/XS/main/build_perl_info.c
+++ b/tp/Texinfo/XS/main/build_perl_info.c
@@ -1532,6 +1532,16 @@ build_output_units_list (size_t output_units_descriptor)
   return newRV_noinc ((SV *) av_output_units);
 }
 
+SV *
+get_conf (CONVERTER *converter, const char *option_name)
+{
+  dTHX;
+
+  if (converter->conf)
+    return build_sv_option (converter->conf, option_name, converter);
+  return newSV (0);
+}
+
 /* add C messages to a Texinfo::Report object, like
    Texinfo::Report::add_formatted_message does.
    TODO it could replace the calls to add_formatted_message
@@ -1913,13 +1923,111 @@ build_expanded_formats (EXPANDED_FORMAT 
*expanded_formats)
 }
 
 SV *
-get_conf (CONVERTER *converter, const char *conf)
+build_sorted_indices_by_letter (
+                      INDEX_SORTED_BY_LETTER *index_entries_by_letter,
+                      SV *indices_information)
 {
+  HV *indices_hv;
+  HV *indices_information_hv;
+  INDEX_SORTED_BY_LETTER *idx;
+
   dTHX;
 
-  if (converter->conf)
-    return build_sv_option (converter->conf, conf, converter);
-  return newSV (0);
+  if (!index_entries_by_letter)
+    return newSV (0);
+
+  indices_information_hv = (HV *) SvRV (indices_information);
+
+  indices_hv = newHV ();
+
+  for (idx = index_entries_by_letter; idx->name; idx++)
+    {
+      AV *sorted_letters_av;
+      size_t i;
+
+      if (idx->letter_number <= 0)
+        continue;
+
+      sorted_letters_av = newAV ();
+
+      hv_store (indices_hv, idx->name, strlen (idx->name),
+                newRV_noinc ((SV *)sorted_letters_av), 0);
+
+      for (i = 0; i < idx->letter_number; i++)
+        {
+          size_t j;
+          HV *letter_hv = newHV ();
+          AV *entries_av = newAV ();
+          LETTER_INDEX_ENTRIES *letter = &idx->letter_entries[i];
+
+          hv_store (letter_hv, "letter", strlen ("letter"),
+                    newSVpv_utf8 (letter->letter, 0), 0);
+
+          hv_store (letter_hv, "entries", strlen ("entries"),
+                    newRV_noinc ((SV *)entries_av), 0);
+
+          av_push (sorted_letters_av, newRV_noinc ((SV *)letter_hv));
+
+          for (j = 0; j < letter->entries_number; j++)
+            {
+              INDEX_ENTRY *entry = letter->entries[j];
+              char *index_name = entry->index_name;
+              int entry_number = entry->number;
+              SV **index_info_sv;
+              SV *index_entry_sv = 0;
+
+              index_info_sv = hv_fetch (indices_information_hv, index_name,
+                                        strlen (index_name), 0);
+              if (!index_info_sv)
+                {
+                  fprintf (stderr,
+                       "BUG: build_sorted_indices_by_letter: "
+                       "%s: %s: entry %zu index %s not found\n",
+                           idx->name, letter->letter, j, index_name);
+                }
+              else
+                {
+                  HV *index_info_hv = (HV *) SvRV (*index_info_sv);
+                  SV **index_info_index_entries_sv = hv_fetch (index_info_hv,
+                         "index_entries", strlen ("index_entries"), 0);
+
+                  if (!index_info_index_entries_sv)
+                    {
+                      fprintf (stderr,
+                       "BUG: build_sorted_indices_by_letter: "
+                 "%s: %s: entry %zu index %s 'index_entries' not found\n",
+                         idx->name, letter->letter, j, index_name);
+                    }
+                  else
+                    {
+                      AV *index_info_entries_av
+                          = (AV *) SvRV (*index_info_index_entries_sv);
+
+                      SV **index_entry_info_sv = av_fetch 
(index_info_entries_av,
+                                                         entry_number -1, 0);
+
+                      if (!index_entry_info_sv)
+                        {
+                          fprintf (stderr,
+                             "BUG: build_sorted_indices_by_letter: "
+                             "%s: %s: entry %zu: %d in %s not found\n",
+                                idx->name, letter->letter, j,
+                                entry_number, index_name);
+                        }
+                      else
+                        index_entry_sv = *index_entry_info_sv;
+                    }
+                }
+
+              if (index_entry_sv)
+                {
+                  SvREFCNT_inc (index_entry_sv);
+                  av_push (entries_av, index_entry_sv);
+                }
+            }
+        }
+    }
+  return newRV_noinc ((SV *)indices_hv);
 }
 
 SV *
diff --git a/tp/Texinfo/XS/main/build_perl_info.h 
b/tp/Texinfo/XS/main/build_perl_info.h
index 007acd80ba..5941261d79 100644
--- a/tp/Texinfo/XS/main/build_perl_info.h
+++ b/tp/Texinfo/XS/main/build_perl_info.h
@@ -53,8 +53,12 @@ void pass_output_unit_files (SV *converter_sv,
 void build_output_files_information (SV *converter_sv,
                    OUTPUT_FILES_INFORMATION *output_files_information);
 
+SV *build_sorted_indices_by_letter (
+                      INDEX_SORTED_BY_LETTER *index_entries_by_letter,
+                      SV *indices_information);
+
 SV *html_build_direction_icons (CONVERTER *converter,
                             DIRECTION_ICON_LIST *direction_icons);
-SV *get_conf (CONVERTER *converter, const char *conf);
+SV *get_conf (CONVERTER *converter, const char *option_name);
 
 #endif
diff --git a/tp/init/chm.pm b/tp/init/chm.pm
index 1cabfeea51..b569b9e120 100644
--- a/tp/init/chm.pm
+++ b/tp/init/chm.pm
@@ -247,10 +247,18 @@ sub chm_init($)
     $sections_list = $document->sections_list();
   }
 
-  my ($index_entries, $index_entries_sort_strings)
+  my $index_entries;
+  if ($indices_information) {
+    my $merged_index_entries
+        = Texinfo::Indices::merge_indices($indices_information);
+
+    my $index_entries_sort_strings;
+    ($index_entries, $index_entries_sort_strings)
        = Texinfo::Indices::sort_indices_by_index(undef, $self,
-                             $self->get_info('index_entries'),
+                             $merged_index_entries,
                              $indices_information);
+  }
+
   if ($index_entries) {
     foreach my $index_name (sort(keys(%$index_entries))) {
       foreach my $index_entry_ref (@{$index_entries->{$index_name}}) {



reply via email to

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