texinfo-commits
[Top][All Lists]
Advanced

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

[no subject]


From: Patrice Dumas
Date: Mon, 30 Sep 2024 12:29:38 -0400 (EDT)

branch: master
commit 5b8af8ecd2c4093ea85812d29f2d2ebbdb529a5b
Author: Patrice Dumas <pertusus@free.fr>
AuthorDate: Sat Jul 20 22:33:39 2024 +0200

    * tp/Texinfo/Convert/HTML.pm (_initialize_output_state)
    (conversion_initialization),
    tp/Texinfo/XS/convert/build_html_perl_state.c
    (build_directions_strings, html_pass_converter_output_state): build
    directions_strings from XS.  Move Perl code related to setting up
    directions_strings from conversion_initialization to
    _initialize_output_state.
---
 ChangeLog                                     |  10 +++
 tp/Texinfo/Convert/HTML.pm                    | 110 +++++++++++++-------------
 tp/Texinfo/XS/convert/build_html_perl_state.c |  66 ++++++++++++++++
 3 files changed, 130 insertions(+), 56 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index b48a954b36..c479c27e0b 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -3,6 +3,16 @@
        * tp/Texinfo/XS/Makefile.am (ConvertXS_la_SOURCES): remove
        convert_html.c to only use shared data in libtexinfo-convert.
 
+2024-07-20  Patrice Dumas  <pertusus@free.fr>
+
+       * tp/Texinfo/Convert/HTML.pm (_initialize_output_state)
+       (conversion_initialization),
+       tp/Texinfo/XS/convert/build_html_perl_state.c
+       (build_directions_strings, html_pass_converter_output_state): build
+       directions_strings from XS.  Move Perl code related to setting up
+       directions_strings from conversion_initialization to
+       _initialize_output_state.
+
 2024-07-20  Patrice Dumas  <pertusus@free.fr>
 
        * tp/Texinfo/XS/convert/convert_html.c (no_arg_formatted_cmd),
diff --git a/tp/Texinfo/Convert/HTML.pm b/tp/Texinfo/Convert/HTML.pm
index 4be6a5d314..acfcd6961c 100644
--- a/tp/Texinfo/Convert/HTML.pm
+++ b/tp/Texinfo/Convert/HTML.pm
@@ -12322,6 +12322,60 @@ sub _initialize_output_state($$)
     }
   }
 
+  # three types of direction strings:
+  # * strings not translated, already converted
+  # * strings translated
+  #   - strings already converted
+  #   - strings not already converted
+  $self->{'directions_strings'} = {};
+
+  # The strings not translated, already converted are
+  # initialized here and not with the converter because
+  # substitute_html_non_breaking_space is used and it depends on the document.
+  foreach my $string_type (keys(%default_converted_directions_strings)) {
+    $self->{'directions_strings'}->{$string_type} = {};
+    foreach my $direction
+            (keys(%{$default_converted_directions_strings{$string_type}})) {
+      $self->{'directions_strings'}->{$string_type}->{$direction} = {};
+      my $string_contexts;
+      if ($self->{'customized_direction_strings'}->{$string_type}
+          and $self->{'customized_direction_strings'}->{$string_type}
+                                                           ->{$direction}) {
+        if (defined($self->{'customized_direction_strings'}->{$string_type}
+                                              ->{$direction}->{'converted'})) {
+          $string_contexts
+            = $self->{'customized_direction_strings'}->{$string_type}
+                                          ->{$direction}->{'converted'};
+        } else {
+          $string_contexts = {'normal' => undef };
+        }
+      } else {
+        my $string
+          = $default_converted_directions_strings{$string_type}->{$direction};
+        $string_contexts = {'normal' => $string};
+      }
+      $string_contexts->{'string'} = $string_contexts->{'normal'}
+        if (not defined($string_contexts->{'string'}));
+      foreach my $context (keys(%$string_contexts)) {
+        if (defined($string_contexts->{$context})) {
+          $self->{'directions_strings'}->{$string_type}
+                                     ->{$direction}->{$context}
+            = $self->substitute_html_non_breaking_space(
+                                             $string_contexts->{$context});
+        } else {
+          $self->{'directions_strings'}->{$string_type}
+                                     ->{$direction}->{$context} = undef;
+        }
+      }
+    }
+  }
+
+  # direction strings
+  foreach my $string_type (keys(%default_translated_directions_strings)) {
+    # those will be determined from translatable strings
+    $self->{'directions_strings'}->{$string_type} = {};
+  };
+
   # to avoid infinite recursions when a section refers to itself, possibly
   # indirectly
   $self->{'referred_command_stack'} = [];
@@ -12416,66 +12470,10 @@ sub conversion_initialization($;$)
 
   $self->{'shared_conversion_state'} = {};
 
-  # three types of direction strings:
-  # * strings not translated, already converted
-  # * strings translated
-  #   - strings already converted
-  #   - strings not already converted
-  $self->{'directions_strings'} = {};
-
-  # The strings not translated, already converted are
-  # initialized here and not with the converter because
-  # substitute_html_non_breaking_space is used and it depends on the document.
-  foreach my $string_type (keys(%default_converted_directions_strings)) {
-    $self->{'directions_strings'}->{$string_type} = {};
-    foreach my $direction
-            (keys(%{$default_converted_directions_strings{$string_type}})) {
-      $self->{'directions_strings'}->{$string_type}->{$direction} = {};
-      my $string_contexts;
-      if ($self->{'customized_direction_strings'}->{$string_type}
-          and $self->{'customized_direction_strings'}->{$string_type}
-                                                           ->{$direction}) {
-        if (defined($self->{'customized_direction_strings'}->{$string_type}
-                                              ->{$direction}->{'converted'})) {
-          $string_contexts
-            = $self->{'customized_direction_strings'}->{$string_type}
-                                          ->{$direction}->{'converted'};
-        } else {
-          $string_contexts = {'normal' => undef };
-        }
-      } else {
-        my $string
-          = $default_converted_directions_strings{$string_type}->{$direction};
-        $string_contexts = {'normal' => $string};
-      }
-      $string_contexts->{'string'} = $string_contexts->{'normal'}
-        if (not defined($string_contexts->{'string'}));
-      foreach my $context (keys(%$string_contexts)) {
-        if (defined($string_contexts->{$context})) {
-          $self->{'directions_strings'}->{$string_type}
-                                     ->{$direction}->{$context}
-            = $self->substitute_html_non_breaking_space(
-                                             $string_contexts->{$context});
-        } else {
-          $self->{'directions_strings'}->{$string_type}
-                                     ->{$direction}->{$context} = undef;
-        }
-      }
-    }
-  }
-
   $self->{'multiple_pass'} = [];
 
   $self->_initialize_output_state('_convert');
 
-  # direction strings
-  foreach my $string_type (keys(%default_translated_directions_strings)) {
-    # those will be determined from translatable strings
-    $self->{'directions_strings'}->{$string_type} = {};
-  };
-
-  # directions
-
   # for global directions always set, and for directions to special elements,
   # only filled if special elements are actually used.
   $self->{'global_units_directions'} = {};
diff --git a/tp/Texinfo/XS/convert/build_html_perl_state.c 
b/tp/Texinfo/XS/convert/build_html_perl_state.c
index 5a45dc56e2..94887039ef 100644
--- a/tp/Texinfo/XS/convert/build_html_perl_state.c
+++ b/tp/Texinfo/XS/convert/build_html_perl_state.c
@@ -139,6 +139,68 @@ build_no_arg_commands_formatting (const CONVERTER 
*converter)
   return newRV_noinc ((SV *) no_arg_commands_formatting_hv);
 }
 
+SV *
+build_directions_strings (const CONVERTER *converter)
+{
+  HV *directions_strings_hv;
+  enum direction_string_type DS_type;
+  int nr_string_directions;
+  int nr_dir_str_contexts = TDS_context_string +1;
+
+  dTHX;
+
+  nr_string_directions = NON_SPECIAL_DIRECTIONS_NR - FIRSTINFILE_NR
+                     + converter->special_unit_varieties.number;
+
+  directions_strings_hv = newHV ();
+
+  for (DS_type = 0; DS_type < TDS_TYPE_MAX_NR; DS_type++)
+    {
+      int i;
+      const char *type_name = direction_string_type_names[DS_type];
+
+      HV *direction_hv = newHV ();
+
+      hv_store (directions_strings_hv, type_name,
+                strlen (type_name), newRV_noinc ((SV *) direction_hv), 0);
+
+      /* those will be determined from translatable strings */
+      if (DS_type < TDS_TRANSLATED_MAX_NR)
+        continue;
+
+      for (i = 0; i < nr_string_directions; i++)
+        {
+          int j;
+          const char *direction_name;
+          HV *context_hv = newHV ();
+
+          if (i < FIRSTINFILE_MIN_IDX)
+            direction_name = html_button_direction_names[i];
+          else
+            direction_name
+              = converter->special_unit_info[SUI_type_direction]
+                                   [i - FIRSTINFILE_MIN_IDX];
+
+          hv_store (direction_hv, direction_name, strlen (direction_name),
+                    newRV_noinc ((SV *) context_hv), 0);
+
+          for (j = 0; j < nr_dir_str_contexts; j++)
+            {
+              const char *context_name
+                = direction_string_context_names[j];
+              if (converter->directions_strings[DS_type][i][j])
+                {
+                  hv_store (context_hv, context_name, strlen (context_name),
+                           newSVpv_utf8 (
+                          converter->directions_strings[DS_type][i][j], 0), 0);
+                }
+            }
+        }
+    }
+
+  return newRV_noinc ((SV *) directions_strings_hv);
+}
+
 
 #define STORE(key, sv) hv_store (converter_hv, key, strlen (key), sv, 0)
 #define STORE_INFO(key, sv) hv_store (converter_info_hv, key, strlen (key), 
sv, 0)
@@ -156,6 +218,7 @@ html_pass_converter_output_state (SV *converter_sv, const 
CONVERTER *converter)
   SV *line_break_element_sv;
   SV **expanded_formats_sv;
   SV *no_arg_commands_formatting_sv;
+  SV *directions_strings_sv;
 
   dTHX;
 
@@ -200,6 +263,9 @@ html_pass_converter_output_state (SV *converter_sv, const 
CONVERTER *converter)
   no_arg_commands_formatting_sv = build_no_arg_commands_formatting (converter);
   STORE("no_arg_commands_formatting", no_arg_commands_formatting_sv);
 
+  directions_strings_sv = build_directions_strings (converter);
+  STORE("directions_strings", directions_strings_sv);
+
 #undef STORE
 #undef STORE_INFO
 }



reply via email to

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