texinfo-commits
[Top][All Lists]
Advanced

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

branch master updated: * tp/Texinfo/Convert/HTML.pm (import) (_XS_prepar


From: Patrice Dumas
Subject: branch master updated: * tp/Texinfo/Convert/HTML.pm (import) (_XS_prepare_output_units_global_targets) (_prepare_output_units_global_targets, convert), tp/Texinfo/XS/convert/ConvertXS.xs (html_prepare_output_units_global_targets): rename prepare_output_units_global_targets as html_prepare_output_units_global_targets. Add an XS interface for html_prepare_output_units_global_targets for convert() in perl.
Date: Sun, 22 Oct 2023 18:30:21 -0400

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 1bcd68b3fd * tp/Texinfo/Convert/HTML.pm (import) 
(_XS_prepare_output_units_global_targets) 
(_prepare_output_units_global_targets, convert), 
tp/Texinfo/XS/convert/ConvertXS.xs (html_prepare_output_units_global_targets): 
rename prepare_output_units_global_targets as 
html_prepare_output_units_global_targets. Add an XS interface for 
html_prepare_output_units_global_targets for convert() in perl.
1bcd68b3fd is described below

commit 1bcd68b3fd2fca196bdbe236b3bf88e4221139e3
Author: Patrice Dumas <pertusus@free.fr>
AuthorDate: Mon Oct 23 00:30:21 2023 +0200

    * tp/Texinfo/Convert/HTML.pm (import)
    (_XS_prepare_output_units_global_targets)
    (_prepare_output_units_global_targets, convert),
    tp/Texinfo/XS/convert/ConvertXS.xs
    (html_prepare_output_units_global_targets): rename
    prepare_output_units_global_targets as
    html_prepare_output_units_global_targets. Add an XS interface for
    html_prepare_output_units_global_targets for convert() in perl.
    
    * tp/Texinfo/Convert/HTML.pm (import, _XS_translate_names)
    (_translate_names, convert), tp/Texinfo/XS/convert/ConvertXS.xs
    (html_translate_names), tp/Texinfo/XS/convert/convert_html.c
    (html_translate_names), tp/Texinfo/XS/convert/convert_html.c
    (html_prepare_conversion_units_targets): rename translate_names as
    html_translate_names, add a specific XS interface and remove from
    html_prepare_conversion_units_targets.
    
    * tp/Texinfo/Convert/HTML.pm (_sort_index_entries): reindent, comment
    out unused code.
---
 ChangeLog                            |  22 +++++
 tp/Texinfo/Convert/HTML.pm           | 162 +++++++++++++++++++++--------------
 tp/Texinfo/XS/convert/ConvertXS.xs   |  62 ++++++++++++++
 tp/Texinfo/XS/convert/convert_html.c |  22 ++---
 tp/Texinfo/XS/convert/convert_html.h |   8 ++
 5 files changed, 198 insertions(+), 78 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 912ad40fc4..b64eb8f5a4 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,25 @@
+2023-10-22  Patrice Dumas  <pertusus@free.fr>
+
+       * tp/Texinfo/Convert/HTML.pm (import)
+       (_XS_prepare_output_units_global_targets)
+       (_prepare_output_units_global_targets, convert),
+       tp/Texinfo/XS/convert/ConvertXS.xs
+       (html_prepare_output_units_global_targets): rename
+       prepare_output_units_global_targets as
+       html_prepare_output_units_global_targets. Add an XS interface for
+       html_prepare_output_units_global_targets for convert() in perl.
+
+       * tp/Texinfo/Convert/HTML.pm (import, _XS_translate_names)
+       (_translate_names, convert), tp/Texinfo/XS/convert/ConvertXS.xs
+       (html_translate_names), tp/Texinfo/XS/convert/convert_html.c
+       (html_translate_names), tp/Texinfo/XS/convert/convert_html.c
+       (html_prepare_conversion_units_targets): rename translate_names as
+       html_translate_names, add a specific XS interface and remove from
+       html_prepare_conversion_units_targets. 
+
+       * tp/Texinfo/Convert/HTML.pm (_sort_index_entries): reindent, comment
+       out unused code.
+
 2023-10-22  Patrice Dumas  <pertusus@free.fr>
 
        * info/Makefile.am: add AUTOMAKE_OPTIONS no-dist-built-sources to
diff --git a/tp/Texinfo/Convert/HTML.pm b/tp/Texinfo/Convert/HTML.pm
index 37c98b1ced..56de329566 100644
--- a/tp/Texinfo/Convert/HTML.pm
+++ b/tp/Texinfo/Convert/HTML.pm
@@ -112,6 +112,12 @@ sub import {
     Texinfo::XSLoader::override(
       "Texinfo::Convert::HTML::_XS_prepare_units_directions_files",
       "Texinfo::Convert::ConvertXS::html_prepare_units_directions_files");
+    Texinfo::XSLoader::override(
+      "Texinfo::Convert::HTML::_XS_prepare_output_units_global_targets",
+      "Texinfo::Convert::ConvertXS::html_prepare_output_units_global_targets");
+    Texinfo::XSLoader::override(
+      "Texinfo::Convert::HTML::_XS_translate_names",
+      "Texinfo::Convert::ConvertXS::html_translate_names");
 
     $module_loaded = 1;
   }
@@ -2300,9 +2306,24 @@ my %default_translated_directions_strings = (
   }
 );
 
-sub _translate_names($)
+sub _XS_translate_names($)
+{
+}
+
+sub _translate_names($;$)
 {
   my $self = shift;
+  my $do_XS = shift;
+
+  if ($do_XS and $self->{'converter_descriptor'}) {
+    my $encoded_conf = Texinfo::Common::encode_options($self->{'conf'});
+    my $encoded_converter
+             = {'converter_descriptor' => $self->{'converter_descriptor'},
+                'conf' => $encoded_conf,
+               };
+    _XS_translate_names($encoded_converter);
+  }
+
   print STDERR "\nTRANSLATE_NAMES encoding_name: "
     .$self->get_conf('OUTPUT_ENCODING_NAME')
     ." documentlanguage: ".$self->get_conf('documentlanguage')."\n"
@@ -9750,69 +9771,71 @@ sub _sort_index_entries($)
         = Texinfo::Structuring::merge_indices($indices_information);
     my $index_entries_sort_strings;
 
-    # see TODO in convert/indices_in_conversion.c sort_indices_by_letter,
-    # sorting letters requires a collation in C, so this cannot be done,
-    # even when starting from index_sortable_index_entries
-    if (0 and $self->{'converter_descriptor'}) {
-      my ($index_sortable_index_entries, $collator, 
$index_entries_sort_strings)
-       = Texinfo::Structuring::setup_sortable_index_entries ($self, $self,
-                            $merged_index_entries, $indices_information, 1, 1);
-      if ($index_sortable_index_entries) {
-        # encode and pass as arrays only, in reproducible order
-        my $index_encoded_sortable_entries = [];
-        foreach my $index_name (sort(keys(%$index_sortable_index_entries))) {
-          my $encoded_index_name = Encode::encode('UTF-8', $index_name);
-          my $encoded_sortable_entries = [];
-          foreach my $sortable_entry
-              (@{$index_sortable_index_entries->{$index_name}}) {
-            my $encoded_sortable_entry = {
-              'keys' => $sortable_entry->{'keys'},
-              'index_name'
-                => Encode::encode('UTF-8', $sortable_entry->{'index_name'}),
-              'number' => $sortable_entry->{'number'},
-              'entry_keys' => [],
-            };
-            foreach my $entry_key (@{$sortable_entry->{'entry_keys'}}) {
-              push @{$encoded_sortable_entry->{'entry_keys'}},
-                Encode::encode('UTF-8', $entry_key);
-            }
-            push @$encoded_sortable_entries, $encoded_sortable_entry;
-          }
-          push @{$index_encoded_sortable_entries},
-           [$encoded_index_name, $encoded_sortable_entries],
-        }
-        _XS_sort_sortable_index_entries_by_letter($self,
-                                    $index_encoded_sortable_entries);
-      }
-    }
+    ## see TODO in convert/indices_in_conversion.c sort_indices_by_letter,
+    ## sorting letters requires a collation in C, so this cannot be done,
+    ## even when starting from index_sortable_index_entries
+    #if ($self->{'converter_descriptor'}) {
+    #  my ($index_sortable_index_entries, $collator, 
$index_entries_sort_strings)
+    #   = Texinfo::Structuring::setup_sortable_index_entries ($self, $self,
+    #                        $merged_index_entries, $indices_information, 1, 
1);
+    #  if ($index_sortable_index_entries) {
+    #    # encode and pass as arrays only, in reproducible order
+    #    my $index_encoded_sortable_entries = [];
+    #    foreach my $index_name (sort(keys(%$index_sortable_index_entries))) {
+    #      my $encoded_index_name = Encode::encode('UTF-8', $index_name);
+    #      my $encoded_sortable_entries = [];
+    #      foreach my $sortable_entry
+    #          (@{$index_sortable_index_entries->{$index_name}}) {
+    #        my $encoded_sortable_entry = {
+    #          'keys' => $sortable_entry->{'keys'},
+    #          'index_name'
+    #            => Encode::encode('UTF-8', $sortable_entry->{'index_name'}),
+    #          'number' => $sortable_entry->{'number'},
+    #          'entry_keys' => [],
+    #        };
+    #        foreach my $entry_key (@{$sortable_entry->{'entry_keys'}}) {
+    #          push @{$encoded_sortable_entry->{'entry_keys'}},
+    #            Encode::encode('UTF-8', $entry_key);
+    #        }
+    #        push @$encoded_sortable_entries, $encoded_sortable_entry;
+    #      }
+    #      push @{$index_encoded_sortable_entries},
+    #       [$encoded_index_name, $encoded_sortable_entries],
+    #    }
+    #    _XS_sort_sortable_index_entries_by_letter($self,
+    #                                $index_encoded_sortable_entries);
+    #  }
+    #}
 
     ($self->{'index_entries_by_letter'}, $index_entries_sort_strings)
             = Texinfo::Structuring::sort_indices_by_letter($self,
                                     $self, $merged_index_entries,
                                     $indices_information);
     $self->{'index_entries'} = $merged_index_entries;
-    if ($self->{'converter_descriptor'})
-      {
-        my $encoded_index_entries_by_letter = [];
-        if ($self->{'index_entries_by_letter'}) {
-          foreach my $index_name
-              (sort(keys(%{$self->{'index_entries_by_letter'}}))) {
-            my $letter_entries
-              = $self->{'index_entries_by_letter'}->{$index_name};
-            my $encoded_index_by_letters = [];
-            foreach my $letter_entry (@$letter_entries) {
-              my $letter = $letter_entry->{'letter'};
-              push @$encoded_index_by_letters,
-                [Encode::encode('UTF-8', $letter), $letter_entry->{'entries'}];
-            }
-            push @$encoded_index_entries_by_letter,
-                   [Encode::encode('UTF-8', $index_name),
-                    $encoded_index_by_letters];
+
+    # pass sorted index entries to XS for a reproducible sorting.
+    if ($self->{'converter_descriptor'}) {
+      # encode. Also setup list of lists for easier import of data in C.
+      my $encoded_index_entries_by_letter = [];
+      if ($self->{'index_entries_by_letter'}) {
+        foreach my $index_name
+            (sort(keys(%{$self->{'index_entries_by_letter'}}))) {
+          my $letter_entries
+            = $self->{'index_entries_by_letter'}->{$index_name};
+          my $encoded_index_by_letters = [];
+          foreach my $letter_entry (@$letter_entries) {
+            my $letter = $letter_entry->{'letter'};
+            push @$encoded_index_by_letters,
+              [Encode::encode('UTF-8', $letter), $letter_entry->{'entries'}];
           }
+          push @$encoded_index_entries_by_letter,
+                 [Encode::encode('UTF-8', $index_name),
+                  $encoded_index_by_letters];
         }
-        _XS_get_index_entries_sorted_by_letter($self,
-                                 $encoded_index_entries_by_letter);
       }
+      _XS_get_index_entries_sorted_by_letter($self,
+                                 $encoded_index_entries_by_letter);
+    }
   }
 }
 
@@ -10990,8 +11013,11 @@ sub _initialize_output_state($)
     if ($self->get_conf('CHECK_HTMLXREF'));
 }
 
-# FIXME determine more formally what difference in navigation header is
-# supposed to be compared to output and add tests.
+
+sub _XS_prepare_output_units_global_targets($$$$)
+{
+}
+
 sub convert($$)
 {
   my $self = shift;
@@ -11006,7 +11032,7 @@ sub convert($$)
   # needed for CSS rules gathering
   $self->{'current_filename'} = '';
 
-  # call before _prepare_conversion_units, which calls _translate_names.
+  # call before _prepare_conversion_units.
   # Some information is not available yet.
   $self->_reset_info();
 
@@ -11019,12 +11045,20 @@ sub convert($$)
   # global targets when called as convert, but the Top global
   # unit directions is often referred to in code, so at least this
   # global target needs to be setup.
-  $self->_prepare_output_units_global_targets($output_units,
-                                              $special_units,
-                                              $associated_special_units);
+  if ($self->{'converter_descriptor'}) {
+    my $encoded_converter = $self->encode_converter_for_output();
+    my $global_units_directions =
+      _XS_prepare_output_units_global_targets($encoded_converter,
+           $output_units, $special_units, $associated_special_units);
+    $self->{'global_units_directions'} = $global_units_directions;
+  } else {
+    $self->_prepare_output_units_global_targets($output_units,
+                                                $special_units,
+                                                $associated_special_units);
+  }
 
   # setup untranslated strings
-  $self->_translate_names();
+  $self->_translate_names(1);
 
   # title
   $self->{'title_titlepage'}
@@ -11371,7 +11405,7 @@ sub output($$)
     = $self->_prepare_conversion_units($root, $document_name);
 
   # setup untranslated strings
-  $self->_translate_names();
+  $self->_translate_names(1);
 
   my %files_source_info
     = $self->_prepare_units_directions_files($output_units, $special_units,
@@ -11396,7 +11430,7 @@ sub output($$)
                   'lang="' . $preamble_document_language . '"');
 
   if ($default_document_language ne $preamble_document_language) {
-    $self->_translate_names();
+    $self->_translate_names(1);
   }
 
   # prepare title.  fulltitle uses more possibility than simpletitle for
diff --git a/tp/Texinfo/XS/convert/ConvertXS.xs 
b/tp/Texinfo/XS/convert/ConvertXS.xs
index 1f31df210d..4a3aae2582 100644
--- a/tp/Texinfo/XS/convert/ConvertXS.xs
+++ b/tp/Texinfo/XS/convert/ConvertXS.xs
@@ -251,4 +251,66 @@ html_prepare_units_directions_files (SV *converter_in, SV 
*output_units_in, SV *
          PUSHs(sv_2mortal(file_counters_sv));
          PUSHs(sv_2mortal(out_filepaths_sv));
 
+SV *
+html_prepare_output_units_global_targets (SV *converter_in, SV 
*output_units_in, SV *special_units_in, SV *associated_special_units_in)
+  PREINIT:
+         CONVERTER *self = 0;
+         int output_units_descriptor = 0;
+         int special_units_descriptor = 0;
+         int associated_special_units_descriptor = 0;
+     CODE:
+         /* add warn string? */
+         self = get_sv_converter (converter_in, 0);
+         if (SvOK (output_units_in))
+           output_units_descriptor
+             = get_sv_output_units_descriptor (output_units_in,
+                         "html_prepare_output_units_global_targets output 
units");
+         if (SvOK (special_units_in))
+           special_units_descriptor
+             = get_sv_output_units_descriptor (special_units_in,
+                        "html_prepare_output_units_global_targets special 
units");
+         if (SvOK (associated_special_units_in))
+           associated_special_units_descriptor
+             = get_sv_output_units_descriptor (associated_special_units_in,
+             "html_prepare_output_units_global_targets associated special 
units");
 
+         html_prepare_output_units_global_targets (self,
+                output_units_descriptor, special_units_descriptor,
+                associated_special_units_descriptor);
+
+         rebuild_output_units_list (output_units_in, output_units_descriptor);
+         rebuild_output_units_list (special_units_in, 
special_units_descriptor);
+         rebuild_output_units_list (associated_special_units_in,
+                                    associated_special_units_descriptor);
+
+         RETVAL
+           = build_html_global_units_directions (self->global_units_directions,
+                                          self->special_units_direction_name);
+    OUTPUT:
+        RETVAL
+
+
+void
+html_translate_names (SV *converter_in)
+  PREINIT:
+         CONVERTER *self = 0;
+         HV *hv_in;
+         SV **converter_options_sv;
+     CODE:
+         self = get_sv_converter (converter_in, 0);
+         /* that kind of code could be in get_perl_info too */
+         hv_in = (HV *)SvRV (converter_in);
+         converter_options_sv = hv_fetch (hv_in, "conf",
+                                   strlen ("conf"), 0);
+
+         if (converter_options_sv)
+           {
+             if (self->conf)
+               free_options (self->conf);
+             free (self->conf);
+
+             self->conf
+              = copy_sv_options (*converter_options_sv);
+           }
+
+         html_translate_names (self);
diff --git a/tp/Texinfo/XS/convert/convert_html.c 
b/tp/Texinfo/XS/convert/convert_html.c
index 26b26f93e9..c67319165d 100644
--- a/tp/Texinfo/XS/convert/convert_html.c
+++ b/tp/Texinfo/XS/convert/convert_html.c
@@ -321,8 +321,8 @@ complete_no_arg_commands_formatting (CONVERTER *self, enum 
command_id cmd,
                                                   HCC_type_string, translate);
 }
 
-static void
-translate_names (CONVERTER *self)
+void
+html_translate_names (CONVERTER *self)
 {
   int j;
   STRING_LIST *special_unit_varieties = self->special_unit_varieties;
@@ -1459,21 +1459,15 @@ html_prepare_conversion_units_targets (CONVERTER *self,
 
   prepare_index_entries_targets (self);
   prepare_footnotes_targets (self);
-
-  /* not related to targets, but practical to do here and not in
-     XS interface file to avoid defining translate_names as a global
-     function */
-  /* setup untranslated strings */
-  translate_names (self);
 }
 
 /* Associate output units to the global targets, First, Last, Top, Index.
    and special output units */
-static void
-prepare_output_units_global_targets (CONVERTER *self,
-                                     int output_units_descriptor,
-                                     int special_units_descriptor,
-                                     int associated_special_units_descriptor)
+void
+html_prepare_output_units_global_targets (CONVERTER *self,
+                                        int output_units_descriptor,
+                                        int special_units_descriptor,
+                                        int 
associated_special_units_descriptor)
 {
   int i;
   int all_special_units_nr = 0;
@@ -2135,7 +2129,7 @@ html_prepare_units_directions_files (CONVERTER *self,
   OUTPUT_UNIT_LIST *associated_special_units
     = retrieve_output_units (associated_special_units_descriptor);
 
-  prepare_output_units_global_targets (self, output_units_descriptor,
+  html_prepare_output_units_global_targets (self, output_units_descriptor,
                                              special_units_descriptor,
                                        associated_special_units_descriptor);
 
diff --git a/tp/Texinfo/XS/convert/convert_html.h 
b/tp/Texinfo/XS/convert/convert_html.h
index dd6c0acf99..17438b6c15 100644
--- a/tp/Texinfo/XS/convert/convert_html.h
+++ b/tp/Texinfo/XS/convert/convert_html.h
@@ -22,6 +22,14 @@ FILE_SOURCE_INFO_LIST * html_prepare_units_directions_files 
(CONVERTER *self,
           int special_units_descriptor, int 
associated_special_units_descriptor,
           char *output_file, char *destination_directory, char 
*output_filename,
           char *document_name);
+
+void html_prepare_output_units_global_targets (CONVERTER *self,
+                                        int output_units_descriptor,
+                                        int special_units_descriptor,
+                                        int 
associated_special_units_descriptor);
+
+void html_translate_names (CONVERTER *self);
+
 /*
 char *html_convert (CONVERTER *self);
 */



reply via email to

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