texinfo-commits
[Top][All Lists]
Advanced

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

branch master updated: * tp/Texinfo/Convert/Converter.pm (encode_convert


From: Patrice Dumas
Subject: branch master updated: * tp/Texinfo/Convert/Converter.pm (encode_converter_document), tp/Texinfo/XS/main/get_perl_info.c (set_translated_commands) (html_converter_initialize_sv): encode strings in XS, not in perl.
Date: Sun, 05 Nov 2023 16:58:59 -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 08803f05a3 * tp/Texinfo/Convert/Converter.pm 
(encode_converter_document), tp/Texinfo/XS/main/get_perl_info.c 
(set_translated_commands) (html_converter_initialize_sv): encode strings in XS, 
not in perl.
08803f05a3 is described below

commit 08803f05a32386b1c6682e7723c9034063b29e39
Author: Patrice Dumas <pertusus@free.fr>
AuthorDate: Sun Nov 5 22:58:51 2023 +0100

    * tp/Texinfo/Convert/Converter.pm (encode_converter_document),
    tp/Texinfo/XS/main/get_perl_info.c (set_translated_commands)
    (html_converter_initialize_sv): encode strings in XS, not in perl.
---
 ChangeLog                          |  6 ++++
 tp/Texinfo/Convert/Converter.pm    | 74 +++++++++-----------------------------
 tp/Texinfo/XS/main/get_perl_info.c | 12 +++----
 3 files changed, 29 insertions(+), 63 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index a77e645408..ebbbcb4738 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2023-11-05  Patrice Dumas  <pertusus@free.fr>
+
+       * tp/Texinfo/Convert/Converter.pm (encode_converter_document),
+       tp/Texinfo/XS/main/get_perl_info.c (set_translated_commands)
+       (html_converter_initialize_sv): encode strings in XS, not in perl.
+
 2023-11-05  Patrice Dumas  <pertusus@free.fr>
 
        * tp/Texinfo/XS/main/get_perl_info.c, tp/Texinfo/XS/main/utils.h:
diff --git a/tp/Texinfo/Convert/Converter.pm b/tp/Texinfo/Convert/Converter.pm
index bd27c40b49..04538d4dd0 100644
--- a/tp/Texinfo/Convert/Converter.pm
+++ b/tp/Texinfo/Convert/Converter.pm
@@ -455,7 +455,7 @@ sub output($$)
 
 ###############################################################
 # XS Interface for a document to be converted.
-# Select and encode to UTF-8 to pass to the XS code
+# Select to pass to the XS code
 # TODO document?
 # To be called for initialization
 sub encode_converter_document($)
@@ -469,81 +469,41 @@ sub encode_converter_document($)
      'formatting_function',
      'types_open', 'types_conversion', 'commands_open', 'commands_conversion',
      'output_units_conversion', 'code_types', 'pre_class_types',
-     'converter_init_conf') {
+     'converter_init_conf', 'translated_commands',
+     'no_arg_commands_formatting') {
     if ($self->{$variable}) {
       $result->{$variable} = $self->{$variable};
     }
   }
 
-  if ($self->{'translated_commands'}) {
-    my $encoded_translated_commands = {};
-    foreach my $cmdname (keys(%{$self->{'translated_commands'}})) {
-      $encoded_translated_commands->{$cmdname}
-        = Encode::encode('UTF-8', $self->{'translated_commands'}->{$cmdname});
+  if ($self->{'special_unit_info'}) {
+    # information that does not need to be translated
+    $result->{'special_unit_info'} = 
Storable::dclone($self->{'special_unit_info'});
+    # information needing translation, simplify the structure to
+    # be more like non-translated special_unit_info information
+    if ($self->{'translated_special_unit_info'}) {
+      foreach my $tree_type (keys(%{$self->{'translated_special_unit_info'}})) 
{
+        my $type = $self->{'translated_special_unit_info'}->{$tree_type}->[0];
+        my $variety_strings
+          = $self->{'translated_special_unit_info'}->{$tree_type}->[1];
+        # we do not need both tree type and string type to pass to XS,
+        # pass only the string type $type and associated varieties information
+        $result->{'special_unit_info'}->{$type} = $variety_strings;
+      }
     }
-    $result->{'translated_commands'} = $encoded_translated_commands;
-  }
 
-  # HTML specific
-  if ($self->{'special_unit_info'}) {
     # to help the XS code to set arrays of C structures, already prepare
     # a list of special units varieties.
     my %all_special_unit_varieties;
-    # only ascii, no need for encoding
-    $result->{'special_unit_info'} = 
Storable::dclone($self->{'special_unit_info'});
     foreach my $type (keys(%{$result->{'special_unit_info'}})) {
       foreach my $special_unit_variety
             (keys (%{$result->{'special_unit_info'}->{$type}})) {
         $all_special_unit_varieties{$special_unit_variety} = 1;
       }
     }
-
-    if ($self->{'translated_special_unit_info'}) {
-      # could have encoded characters from user init files
-      foreach my $tree_type (keys(%{$self->{'translated_special_unit_info'}})) 
{
-        my $type = $self->{'translated_special_unit_info'}->{$tree_type}->[0];
-        my $variety_strings
-          = $self->{'translated_special_unit_info'}->{$tree_type}->[1];
-        # simplify the structure, as we do not need both tree and
-        # string to pass to XS
-        $result->{'special_unit_info'}->{$type} = {};
-        foreach my $special_unit_variety (keys (%$variety_strings)) {
-          $all_special_unit_varieties{$special_unit_variety} = 1;
-          $result->{'special_unit_info'}->{$type}
-             ->{$special_unit_variety} = Encode::encode('UTF-8',
-                                   $variety_strings->{$special_unit_variety});
-        }
-      }
-    }
     $result->{'sorted_special_unit_varieties'}
       = [sort(keys(%all_special_unit_varieties))];
   }
-  if ($self->{'no_arg_commands_formatting'}) {
-    my $encoded_no_arg_commands_formatting = {};
-    foreach my $cmdname (keys(%{$self->{'no_arg_commands_formatting'}})) {
-      $encoded_no_arg_commands_formatting->{$cmdname} = {};
-      my $format_contexts = $self->{'no_arg_commands_formatting'}->{$cmdname};
-      foreach my $context (keys(%$format_contexts)) {
-        my $spec = $format_contexts->{$context};
-        $encoded_no_arg_commands_formatting->{$cmdname}->{$context} = {};
-        my $encoded_spec
-            = $encoded_no_arg_commands_formatting->{$cmdname}->{$context};
-        foreach my $key ('element', 'unset') {
-          if (exists($spec->{$key})) {
-            $encoded_spec->{$key} = $spec->{$key};
-          }
-        }
-        foreach my $key ('text', 'translated_converted',
-                         'translated_to_convert') {
-          if (exists($spec->{$key})) {
-            $encoded_spec->{$key} = Encode::encode('UTF-8', $spec->{$key});
-          }
-        }
-      }
-    }
-    $result->{'no_arg_commands_formatting'}
-      = $encoded_no_arg_commands_formatting;
-  }
 
   return $result;
 }
diff --git a/tp/Texinfo/XS/main/get_perl_info.c 
b/tp/Texinfo/XS/main/get_perl_info.c
index a5723060a5..ed0278c147 100644
--- a/tp/Texinfo/XS/main/get_perl_info.c
+++ b/tp/Texinfo/XS/main/get_perl_info.c
@@ -398,7 +398,7 @@ set_translated_commands (CONVERTER *converter, HV *hv_in)
                 fprintf (stderr, "ERROR: %s: no translated command\n", 
cmdname);
               else
                 {
-                  char *tmp_spec = (char *) SvPVbyte_nolen (translation_sv);
+                  char *tmp_spec = (char *) SvPVutf8_nolen (translation_sv);
                   TRANSLATED_COMMAND *translated_command;
 
                   converter->translated_commands[i] = (TRANSLATED_COMMAND *)
@@ -805,7 +805,7 @@ html_converter_initialize_sv (SV *sv_in, SV 
*default_formatting_references,
                       if (SvOK (*info_type_variety_sv))
                         {
                           char *value
-                            = (char *) SvPVbyte_nolen (*info_type_variety_sv);
+                            = (char *) SvPVutf8_nolen (*info_type_variety_sv);
                           converter->special_unit_info[j][k] = strdup (value);
                         }
                       else
@@ -1016,7 +1016,7 @@ html_converter_initialize_sv (SV *sv_in, SV 
*default_formatting_references,
                               if (!strcmp (key, "element"))
                                 {
                                   char *tmp_spec
-                                    = (char *) SvPVbyte_nolen (spec_sv);
+                                    = (char *) SvPVutf8_nolen (spec_sv);
                                   format_spec->element = strdup (tmp_spec);
                                 }
                               else if (!strcmp (key, "unset"))
@@ -1024,20 +1024,20 @@ html_converter_initialize_sv (SV *sv_in, SV 
*default_formatting_references,
                               else if (!strcmp (key, "text"))
                                 {
                                   char *tmp_spec
-                                    = (char *) SvPVbyte_nolen (spec_sv);
+                                    = (char *) SvPVutf8_nolen (spec_sv);
                                   format_spec->text = strdup (tmp_spec);
                                 }
                               else if (!strcmp (key, "translated_converted"))
                                 {
                                   char *tmp_spec
-                                    = (char *) SvPVbyte_nolen (spec_sv);
+                                    = (char *) SvPVutf8_nolen (spec_sv);
                                   format_spec->translated_converted
                                     = strdup (tmp_spec);
                                 }
                               else if (!strcmp (key, "translated_to_convert"))
                                 {
                                   char *tmp_spec
-                                    = (char *) SvPVbyte_nolen (spec_sv);
+                                    = (char *) SvPVutf8_nolen (spec_sv);
                                   format_spec->translated_to_convert
                                     = strdup (tmp_spec);
                                 }



reply via email to

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