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 (encoded_input_


From: Patrice Dumas
Subject: branch master updated: * tp/Texinfo/Convert/Converter.pm (encoded_input_file_name), tp/Texinfo/Convert/Utils.pm (expand_verbatiminclude) (encoded_input_file_name): put encoded_input_file_name in Texinfo::Convert::Utils, and make encoded_input_file_name in Texinfo::Convert::Converter a wrapper around it. Add an optional argument to encoded_input_file_name to specify the input file encoding. Use encoded_input_file_name in expand_verbatiminclude with the optional argument.
Date: Sun, 16 Jul 2023 13:19:17 -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 9924631c67 * tp/Texinfo/Convert/Converter.pm 
(encoded_input_file_name), tp/Texinfo/Convert/Utils.pm (expand_verbatiminclude) 
(encoded_input_file_name): put encoded_input_file_name in 
Texinfo::Convert::Utils, and make encoded_input_file_name in 
Texinfo::Convert::Converter a wrapper around it.  Add an optional argument to 
encoded_input_file_name to specify the input file encoding.  Use 
encoded_input_file_name in expand_verbatiminclude with the optional argument.
9924631c67 is described below

commit 9924631c671ba2729d2f423a87bd82e7479a3644
Author: Patrice Dumas <pertusus@free.fr>
AuthorDate: Sun Jul 16 19:19:03 2023 +0200

    * tp/Texinfo/Convert/Converter.pm (encoded_input_file_name),
    tp/Texinfo/Convert/Utils.pm (expand_verbatiminclude)
    (encoded_input_file_name): put encoded_input_file_name in
    Texinfo::Convert::Utils, and make encoded_input_file_name in
    Texinfo::Convert::Converter a wrapper around it.  Add an optional
    argument to encoded_input_file_name to specify the input file
    encoding.  Use encoded_input_file_name in expand_verbatiminclude
    with the optional argument.
    
    * tp/texi2any.pl: initialize correctly the converter used when
    SORT_ELEMENT_COUNT is set.  Use the converter more consistently to
    find customization variables and methods.
---
 ChangeLog                       | 15 +++++++++++
 tp/Texinfo/Convert/Converter.pm | 32 +++++++++++------------
 tp/Texinfo/Convert/Utils.pm     | 57 +++++++++++++++++++++++++++++------------
 tp/texi2any.pl                  | 50 +++++++++++++++++++++++-------------
 4 files changed, 103 insertions(+), 51 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index b4a8a51332..529f91e293 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,18 @@
+2023-07-16  Patrice Dumas  <pertusus@free.fr>
+
+       * tp/Texinfo/Convert/Converter.pm (encoded_input_file_name),
+       tp/Texinfo/Convert/Utils.pm (expand_verbatiminclude)
+       (encoded_input_file_name): put encoded_input_file_name in
+       Texinfo::Convert::Utils, and make encoded_input_file_name in
+       Texinfo::Convert::Converter a wrapper around it.  Add an optional
+       argument to encoded_input_file_name to specify the input file
+       encoding.  Use encoded_input_file_name in expand_verbatiminclude
+       with the optional argument.
+
+       * tp/texi2any.pl: initialize correctly the converter used when
+       SORT_ELEMENT_COUNT is set.  Use the converter more consistently to
+       find customization variables and methods.
+
 2023-07-16  Patrice Dumas  <pertusus@free.fr>
 
        * tp/t/test_utils.pl (test): OUTPUT_PERL_ENCODING should always be set
diff --git a/tp/Texinfo/Convert/Converter.pm b/tp/Texinfo/Convert/Converter.pm
index ee4dec6847..4e0a5fd89d 100644
--- a/tp/Texinfo/Convert/Converter.pm
+++ b/tp/Texinfo/Convert/Converter.pm
@@ -1176,24 +1176,16 @@ sub present_bug_message($$;$)
 }
 
 # Reverse the decoding of the file name from the input encoding.
-sub encoded_input_file_name($$)
+# A wrapper around Texinfo::Utils::encoded_input_file_name() that
+# can be called in converters through an objet oriented syntax.
+sub encoded_input_file_name($$;$)
 {
   my $self = shift;
   my $file_name = shift;
+  my $input_file_encoding = shift;
 
-  my $encoding;
-  my $input_file_name_encoding = $self->get_conf('INPUT_FILE_NAME_ENCODING');
-  if ($input_file_name_encoding) {
-    $encoding = $input_file_name_encoding;
-  } elsif ($self->get_conf('DOC_ENCODING_FOR_INPUT_FILE_NAME')) {
-    $encoding = $self->{'parser_info'}->{'input_perl_encoding'}
-      if ($self->{'parser_info'}
-        and defined($self->{'parser_info'}->{'input_perl_encoding'}));
-  } else {
-    $encoding = $self->get_conf('LOCALE_ENCODING');
-  }
-
-  return Texinfo::Common::encode_file_name($file_name, $encoding);
+  return Texinfo::Convert::Utils::encoded_input_file_name($self, $file_name,
+                                                          
$input_file_encoding);
 }
 
 # A wrapper around Texinfo::Utils::encoded_output_file_name() that
@@ -2065,20 +2057,26 @@ with the file name portion only (without directory).
 
 The strings returned are text strings.
 
-=item ($encoded_name, $encoding) = 
$converter->encoded_input_file_name($character_string_name)
+=item ($encoded_name, $encoding) = 
$converter->encoded_input_file_name($character_string_name, 
$input_file_encoding)
 
 =item ($encoded_name, $encoding) = 
$converter->encoded_output_file_name($character_string_name)
 X<C<encoded_input_file_name>> X<C<encoded_output_file_name>>
 
-Encode I<$character_string_name> in the same way as other file name are
+Encode I<$character_string_name> in the same way as other file names are
 encoded in the converter, based on customization variables, and possibly
 on the input file encoding.  Return the encoded name and the encoding
 used to encode the name.  The C<encoded_input_file_name> and
 C<encoded_output_file_name> functions use different customization variables to
 determine the encoding.
 
+The <$input_file_encoding> argument is optional.  If set, it is used for
+the input file encoding.  It is useful if there is more precise information
+on the input file encoding where the file name appeared.
+
 Note that C<encoded_output_file_name> is a wrapper around the
-function with the same name in L<<< 
Texinfo::Convert::Utils::encoded_output_file_name|Texinfo::Convert::Utils/($encoded_name,
 $encoding) = $converter->encoded_output_file_name($converter, 
$character_string_name) >>>.
+function with the same name in L<<< 
Texinfo::Convert::Utils::encoded_output_file_name|Texinfo::Convert::Utils/($encoded_name,
 $encoding) = $converter->encoded_output_file_name($converter, 
$character_string_name) >>>,
+and C<encoded_input_file_name> is a wrapper around the
+function with the same name in L<<< 
Texinfo::Convert::Utils::encoded_input_file_name|Texinfo::Convert::Utils/($encoded_name,
 $encoding) = $converter->encoded_input_file_name($converter, 
$character_string_name, $input_file_encoding) >>>.
 
 =item ($caption, $prepended) = $converter->float_name_caption($float)
 X<C<float_name_caption>>
diff --git a/tp/Texinfo/Convert/Utils.pm b/tp/Texinfo/Convert/Utils.pm
index 336d5317a4..16c9d0ed17 100644
--- a/tp/Texinfo/Convert/Utils.pm
+++ b/tp/Texinfo/Convert/Utils.pm
@@ -239,19 +239,9 @@ sub expand_verbatiminclude($$$)
 
   my $input_encoding = 
Texinfo::Common::element_extra_encoding_for_perl($current);
 
-  my $encoding;
-  my $input_file_name_encoding
-     = $customization_information->get_conf('INPUT_FILE_NAME_ENCODING');
-  if ($input_file_name_encoding) {
-    $encoding = $input_file_name_encoding;
-  } elsif 
($customization_information->get_conf('DOC_ENCODING_FOR_INPUT_FILE_NAME')) {
-    $encoding = $input_encoding;
-  } else {
-    $encoding = $customization_information->get_conf('LOCALE_ENCODING');
-  }
-
   my ($file_name, $file_name_encoding)
-      = Texinfo::Common::encode_file_name($file_name_text, $encoding);
+      = encoded_input_file_name($customization_information,
+                                $file_name_text, $input_encoding);
 
   my $file = Texinfo::Common::locate_include_file($customization_information,
                                                   $file_name);
@@ -366,6 +356,33 @@ sub encoded_output_file_name($$)
   return Texinfo::Common::encode_file_name($file_name, $encoding);
 }
 
+# this requires a converter argument
+# Reverse the decoding of the file name from the input encoding.
+sub encoded_input_file_name($$;$)
+{
+  my $self = shift;
+  my $file_name = shift;
+  my $input_file_encoding = shift;
+
+  my $encoding;
+  my $input_file_name_encoding = $self->get_conf('INPUT_FILE_NAME_ENCODING');
+  if ($input_file_name_encoding) {
+    $encoding = $input_file_name_encoding;
+  } elsif ($self->get_conf('DOC_ENCODING_FOR_INPUT_FILE_NAME')) {
+    if (defined($input_file_encoding)) {
+      $encoding = $input_file_encoding;
+    } else {
+      $encoding = $self->{'parser_info'}->{'input_perl_encoding'}
+        if ($self->{'parser_info'}
+          and defined($self->{'parser_info'}->{'input_perl_encoding'}));
+    }
+  } else {
+    $encoding = $self->get_conf('LOCALE_ENCODING');
+  }
+
+  return Texinfo::Common::encode_file_name($file_name, $encoding);
+}
+
 # this requires a converter argument.  It is defined here, in order
 # to hide from the caller the 'translated_commands' converter key
 # that is set by Texinfo::Convert::Converter.  This is especially
@@ -449,16 +466,24 @@ I<$def_line> taking the class into account, if there is 
one.
 If I<$converter> is not defined, the resulting string won't be
 translated.
 
+=item ($encoded_name, $encoding) = 
$converter->encoded_input_file_name($converter, $character_string_name, 
$input_file_encoding)
+
 =item ($encoded_name, $encoding) = 
$converter->encoded_output_file_name($converter, $character_string_name)
-X<C<encoded_output_file_name>>
+X<C<encoded_input_file_name>> X<C<encoded_output_file_name>>
 
-Encode I<$character_string_name> in the same way as other file name are
-encoded in converters, based on customization variables, and possibly
+Encode I<$character_string_name> in the same way as other file names are
+encoded in the converter, based on customization variables, and possibly
 on the input file encoding.  Return the encoded name and the encoding
-used to encode the name.  The I<$converter> argument is not optional
+used to encode the name.  The C<encoded_input_file_name> and
+C<encoded_output_file_name> functions use different customization variables to
+determine the encoding.  The I<$converter> argument is not optional
 and is used both to access to customization variables and to access to parser
 information.
 
+The <$input_file_encoding> argument is optional.  If set, it is used for
+the input file encoding.  It is useful if there is more precise information
+on the input file encoding where the file name appeared.
+
 =item $tree = expand_today($converter)
 X<C<expand_today>>
 
diff --git a/tp/texi2any.pl b/tp/texi2any.pl
index cf95015dd1..593f7c4896 100755
--- a/tp/texi2any.pl
+++ b/tp/texi2any.pl
@@ -1441,10 +1441,6 @@ while(@input_files) {
   my $main_configuration = Texinfo::MainConfig::new();
 
   my $parser_information = $parser->global_information();
-  my $input_perl_encoding;
-  if (defined($parser_information->{'input_perl_encoding'})) {
-    $input_perl_encoding = $parser_information->{'input_perl_encoding'};
-  }
   # encoding is needed for output files
   # encoding and documentlanguage are needed for gdt() in 
regenerate_master_menu
   Texinfo::Common::set_output_encodings($main_configuration, 
$parser_information);
@@ -1626,9 +1622,9 @@ while(@input_files) {
                             %$file_cmdline_options,
                           };
 
-  # NOTE nothing set in $main_configuration is passed, which is
-  # clean, the Converters can find that information in $converter_options,
-  # determine it themselves or use their defaults.
+  # NOTE nothing set in $main_configuration is passed directly, which is
+  # clean, the Converters already have that information in $converter_options,
+  # can determine it themselves or use their defaults.
   # It could be possible to pass some information if it allows
   # for instance to have some consistent information for Structuring
   # and Converters.
@@ -1711,27 +1707,45 @@ while(@input_files) {
   }
   if (defined(get_conf('SORT_ELEMENT_COUNT')) and $file_number == 0) {
     require Texinfo::Convert::TextContent;
+    my $sort_element_converter_options = { %$main_program_default_options,
+                                           %$init_files_options,
+                                           %$file_cmdline_options,
+                                         };
+
+    $sort_element_converter_options->{'parser'} = $parser;
+    $sort_element_converter_options->{'structuring'} = $structure_information;
+    # This is not clear that this is correct.  On the one hand it could
+    # be more consistent with the formatting to have nothing here or a
+    # format corresponding to Texinfo::Convert::TextContent.  On the other
+    # hand, the information of the format could be useful.  Not very
+    # important as long as this information is not used.
+    $sort_element_converter_options->{'converted_format'} = $converted_format;
+    $sort_element_converter_options->{'language_config_dirs'} = 
\@language_config_dirs;
+    unshift @{$sort_element_converter_options->{'INCLUDE_DIRECTORIES'}},
+            @prepended_include_directories;
+
     my $converter_element_count
-      = Texinfo::Convert::TextContent->converter($converter_options);
+      = 
Texinfo::Convert::TextContent->converter($sort_element_converter_options);
+
     # here could be $format or $converted_format.  Since $converted_format
     # is used above for ->{'nodes_tree'}, use it here again.
-    my $use_sections = (! $formats_table{$converted_format}->{'nodes_tree'}
-                        or (defined($converter->get_conf('USE_NODES'))
-                            and !$converter->get_conf('USE_NODES')));
+    my $use_sections
+        = (! $formats_table{$converted_format}->{'nodes_tree'}
+           or (defined($converter_element_count->get_conf('USE_NODES'))
+                       and !$converter_element_count->get_conf('USE_NODES')));
     my ($sorted_name_counts_array, $sort_element_count_text)
-        = Texinfo::Convert::Converter::sort_element_counts(
-               $converter_element_count, $tree, $use_sections,
-                             get_conf('SORT_ELEMENT_COUNT_WORDS'));
+        = $converter_element_count->sort_element_counts($tree, $use_sections,
+                                             
get_conf('SORT_ELEMENT_COUNT_WORDS'));
 
     my $sort_element_count_file_name = get_conf('SORT_ELEMENT_COUNT');
     my ($encoded_sort_element_count_file_name, $path_encoding)
-       = Texinfo::Common::encode_file_name($sort_element_count_file_name,
-                                           $input_perl_encoding);
+       = $converter_element_count->encoded_output_file_name(
+                                             $sort_element_count_file_name);
     my $sort_elem_files_information = 
Texinfo::Common::output_files_initialize();
     my ($sort_element_count_fh, $error_message)
                 = Texinfo::Common::output_files_open_out(
-                             $sort_elem_files_information, $main_configuration,
-                                    $encoded_sort_element_count_file_name);
+                        $sort_elem_files_information, $converter_element_count,
+                                          
$encoded_sort_element_count_file_name);
     my $error_sort_element_count_file;
     if (defined ($sort_element_count_fh)) {
       print $sort_element_count_fh $sort_element_count_text;



reply via email to

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