texinfo-commits
[Top][All Lists]
Advanced

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

branch master updated: * tp/Texinfo/XS/convert/ConvertXS.xs (text_conver


From: Patrice Dumas
Subject: branch master updated: * tp/Texinfo/XS/convert/ConvertXS.xs (text_convert_tree): handle an undefined options_in.
Date: Mon, 15 Jan 2024 18:09:36 -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 9f23312f3c * tp/Texinfo/XS/convert/ConvertXS.xs (text_convert_tree): 
handle an undefined options_in.
9f23312f3c is described below

commit 9f23312f3c0d3df5871148408960cb99725dbc71
Author: Patrice Dumas <pertusus@free.fr>
AuthorDate: Tue Jan 16 00:09:40 2024 +0100

    * tp/Texinfo/XS/convert/ConvertXS.xs (text_convert_tree): handle an
    undefined options_in.
    
    * tp/Texinfo/Convert/Text.pm (_initialize_options_encoding)
    (copy_options_for_convert_text, converter): do not use
    copy_options_for_convert_text in converter to setup text options, as
    the options are very similar to converter options, even if they are of
    a different nature.  Add _initialize_options_encoding to setup
    enable_encoding both for converter and in
    copy_options_for_convert_text.
---
 ChangeLog                          | 13 ++++++++
 tp/Texinfo/Convert/LaTeX.pm        |  2 +-
 tp/Texinfo/Convert/Text.pm         | 64 +++++++++++++++++++++++++-------------
 tp/Texinfo/XS/convert/ConvertXS.xs |  8 +++--
 4 files changed, 63 insertions(+), 24 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 8976c5262d..d84d65be9b 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,16 @@
+2024-01-15  Patrice Dumas  <pertusus@free.fr>
+
+       * tp/Texinfo/XS/convert/ConvertXS.xs (text_convert_tree): handle an
+       undefined options_in.
+
+       * tp/Texinfo/Convert/Text.pm (_initialize_options_encoding)
+       (copy_options_for_convert_text, converter): do not use
+       copy_options_for_convert_text in converter to setup text options, as
+       the options are very similar to converter options, even if they are of
+       a different nature.  Add _initialize_options_encoding to setup
+       enable_encoding both for converter and in
+       copy_options_for_convert_text.
+
 2024-01-15  Gavin Smith <gavinsmith0123@gmail.com>
 
        * tp/Texinfo/Convert/Info.pm (output): Rename a variable
diff --git a/tp/Texinfo/Convert/LaTeX.pm b/tp/Texinfo/Convert/LaTeX.pm
index 2a67f16b84..d40a5f3ac5 100644
--- a/tp/Texinfo/Convert/LaTeX.pm
+++ b/tp/Texinfo/Convert/LaTeX.pm
@@ -1108,7 +1108,7 @@ sub output($$)
       }
     }
   }
-  # nothing after Top node the end, mark that Top node is ignored
+  # nothing after Top node at the end, mark that Top node is ignored
   # in a container that can be used to mark that content should not
   # be ignored anymore.
   if ($in_top_node) {
diff --git a/tp/Texinfo/Convert/Text.pm b/tp/Texinfo/Convert/Text.pm
index 120e71b23c..abd7898dc8 100644
--- a/tp/Texinfo/Convert/Text.pm
+++ b/tp/Texinfo/Convert/Text.pm
@@ -210,6 +210,17 @@ foreach my $type ('ignorable_spaces_after_command',
 
 my @text_indicator_converter_options = ('NUMBER_SECTIONS', 'ASCII_GLYPH', 
'TEST');
 
+sub _initialize_options_encoding($$)
+{
+  my $self = shift;
+  my $options = shift;
+
+  if ($self->get_conf('ENABLE_ENCODING')
+       and defined($self->get_conf('OUTPUT_ENCODING_NAME'))) {
+    $options->{'enabled_encoding'} = $self->get_conf('OUTPUT_ENCODING_NAME');
+  }
+}
+
 # TODO not documented.  Document?
 # $SELF is an object implementing get_conf, in general a converter.
 # Setup options as used by Texinfo::Convert::Text::convert_to_text
@@ -221,10 +232,8 @@ sub copy_options_for_convert_text($;$)
   my $self = shift;
   my $options_in = shift;
   my %options;
-  if ($self->get_conf('ENABLE_ENCODING')
-       and $self->get_conf('OUTPUT_ENCODING_NAME')) {
-    $options{'enabled_encoding'} = $self->get_conf('OUTPUT_ENCODING_NAME');
-  }
+
+  _initialize_options_encoding($self, \%options);
 
   foreach my $option (@text_indicator_converter_options) {
     my $conf = $self->get_conf($option);
@@ -234,7 +243,13 @@ sub copy_options_for_convert_text($;$)
       $options{$option} = 0;
     }
   }
-  $options{'expanded_formats'} = $self->{'expanded_formats'};
+  my $expanded_formats = $self->get_conf('EXPANDED_FORMATS');
+  if ($expanded_formats) {
+    $options{'expanded_formats'} = {};
+    foreach my $expanded_format(@$expanded_formats) {
+      $options{'expanded_formats'}->{$expanded_format} = 1;
+    }
+  }
   # for locate_include_file
   $options{'INCLUDE_DIRECTORIES'} = $self->get_conf('INCLUDE_DIRECTORIES');
 
@@ -822,16 +837,15 @@ sub convert_to_text($;$)
   }
 
   #print STDERR "CONVERT\n";
+  if (!defined($options)) {
+    $options = {};
+  } elsif (!ref($options)) {
+    confess("convert_to_text options not a ref\n");
+  }
   # this is needed for locate_include_file which uses
   # $configurations_information->get_conf() and thus requires a blessed
   # reference.
-  $options = {} if (!defined($options));
-  if (defined($options)) {
-    if (!ref($options)) {
-      confess("convert_to_text options not a ref\n");
-    }
-    bless $options;
-  }
+  bless $options, "Texinfo::Convert::Text";
 
   # Interface with XS converter.
   if ($XS_convert and defined($root->{'tree_document_descriptor'})) {
@@ -857,7 +871,6 @@ sub converter($;$)
     #print STDERR "CTe ".join("|", sort(keys(%{$conf})))."\n";
   }
 
-  my $expanded_formats = $converter->{'EXPANDED_FORMATS'};
   if ($converter->{'document'}) {
     $converter->{'document_info'}
        = $converter->{'document'}->global_information();
@@ -865,6 +878,8 @@ sub converter($;$)
        = $converter->{'document'}->global_commands_information();
     delete $converter->{'document'};
   }
+
+  my $expanded_formats = $converter->{'EXPANDED_FORMATS'};
   if ($expanded_formats) {
     $converter->{'expanded_formats'} = {};
     foreach my $expanded_format(@$expanded_formats) {
@@ -876,12 +891,25 @@ sub converter($;$)
                                         $converter->{'document_info'})
     if ($converter->{'document_info'});
 
+  # Text options and converter are of different nature.
+  # It could have been possible to set up the options by calling
+  # copy_options_for_convert_text on $self.
+  # However, since the option keys are very similar between the converter
+  # and text options and expanded_formats is already set in the converter,
+  # we use the converter object as text options and we call
+  # _initialize_options_encoding for the only option that is set up
+  # based on other customization options.
+  # Also, we need a blessed reference as get_conf can be called on the options,
+  # using the converter brings that too.
+  _initialize_options_encoding($converter, $converter);
+
   return $converter;
 }
 
 # This function is not called in anywhere in Texinfo code, it is implemented
 # to be in line with Texinfo::Convert::Converter documentation on functions
 # defined for a converter.
+# TODO set options with $self if defined?
 sub convert_tree($$)
 {
   my $self = shift;
@@ -1002,14 +1030,8 @@ sub output($$)
       return undef;
     }
   }
-  # mostly relevant for 'enabled_encoding', other options should be the same.
-  my $options = copy_options_for_convert_text($self);
-  # remove $self Text converter without translation nor error reporting.
-  delete $options->{'converter'};
-  # Some functions call $self->get_conf(), so the options need to be a blessed
-  # reference, merge specific Text options with $self (possibly
-  # overwriting/ignoring but values should be the same).
-  %$self = (%$self, %$options);
+
+  # We use $self as text options, see the comment in converter.
 
   my $result;
   # Interface with XS converter.
diff --git a/tp/Texinfo/XS/convert/ConvertXS.xs 
b/tp/Texinfo/XS/convert/ConvertXS.xs
index baa63fb51c..e5cdeeec9c 100644
--- a/tp/Texinfo/XS/convert/ConvertXS.xs
+++ b/tp/Texinfo/XS/convert/ConvertXS.xs
@@ -311,8 +311,12 @@ text_convert_tree (SV *options_in, SV *tree_in)
         if (document)
           {
             char *result;
-            TEXT_OPTIONS *text_options
-               = copy_sv_options_for_convert_text (options_in);
+            TEXT_OPTIONS *text_options;
+
+            if (SvOK (options_in))
+              text_options = copy_sv_options_for_convert_text (options_in);
+            else
+              text_options = new_text_options ();
 
             text_options->document_descriptor = document->descriptor;
 



reply via email to

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