texinfo-commits
[Top][All Lists]
Advanced

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

branch master updated: * tp/Texinfo/Common.pm (open_out, output_files_op


From: Patrice Dumas
Subject: branch master updated: * tp/Texinfo/Common.pm (open_out, output_files_open_out) (output_files_register_closed, output_files_opened_files) (output_files_unclosed_files), tp/Texinfo/Convert/Converter.pm (register_close_file, converter) (converter_opened_files, converter_unclosed_files, output_files_information) tp/DebugTexinfo/DebugTree.pm, tp/Texinfo/Convert/DocBook.pm, tp/Texinfo/Convert/HTML.pm, tp/Texinfo/Convert/LaTeX.pm, tp/Texinfo/Convert/TexinfoXML.pm, tp/Texinfo/Convert/Text.pm, tp/init/chm.pm, tp/texi2an [...]
Date: Tue, 31 Aug 2021 12:13:43 -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 48ddcbf  * tp/Texinfo/Common.pm (open_out, output_files_open_out) 
(output_files_register_closed, output_files_opened_files) 
(output_files_unclosed_files), tp/Texinfo/Convert/Converter.pm 
(register_close_file, converter) (converter_opened_files, 
converter_unclosed_files, output_files_information) 
tp/DebugTexinfo/DebugTree.pm, tp/Texinfo/Convert/DocBook.pm, 
tp/Texinfo/Convert/HTML.pm, tp/Texinfo/Convert/LaTeX.pm, 
tp/Texinfo/Convert/TexinfoXML.pm, tp/Texinfo/Convert/Text.pm, tp/init [...]
48ddcbf is described below

commit 48ddcbf47e4c723165619bd77c7d35e4cd7a28c8
Author: Patrice Dumas <pertusus@free.fr>
AuthorDate: Tue Aug 31 18:13:18 2021 +0200

    * tp/Texinfo/Common.pm (open_out, output_files_open_out)
    (output_files_register_closed, output_files_opened_files)
    (output_files_unclosed_files),
    tp/Texinfo/Convert/Converter.pm (register_close_file, converter)
    (converter_opened_files, converter_unclosed_files, output_files_information)
    tp/DebugTexinfo/DebugTree.pm, tp/Texinfo/Convert/DocBook.pm,
    tp/Texinfo/Convert/HTML.pm, tp/Texinfo/Convert/LaTeX.pm,
    tp/Texinfo/Convert/TexinfoXML.pm, tp/Texinfo/Convert/Text.pm,
    tp/init/chm.pm, tp/texi2any.pl:
    move the opened output file registration API completly to
    Texinfo::Common, renaming open_out() as output_files_open_out()
    and moving converter_unclosed_files(), register_close_file()
    converter_opened_files() from Convert::Converter to
    Texinfo::Common renaming as output_files_unclosed_files(),
    output_files_register_closed() and output_files_opened_files().
    Pass a hash reference, initialized in Convert::Converter::converter
    to the API functions rather than a full converter.  Access
    this hash reference through output_files_information() defined in
    Convert::Converter.
---
 ChangeLog                        | 22 +++++++++++++++++++
 tp/DebugTexinfo/DebugTree.pm     |  4 +++-
 tp/Texinfo/Common.pm             | 45 +++++++++++++++++++++++++++++++++------
 tp/Texinfo/Convert/Converter.pm  | 46 ++++++++++++++++------------------------
 tp/Texinfo/Convert/DocBook.pm    |  7 ++++--
 tp/Texinfo/Convert/HTML.pm       | 38 ++++++++++++++++++++++-----------
 tp/Texinfo/Convert/IXIN.pm       |  7 ++++--
 tp/Texinfo/Convert/Info.pm       | 24 ++++++++++++++-------
 tp/Texinfo/Convert/LaTeX.pm      |  7 ++++--
 tp/Texinfo/Convert/TexinfoXML.pm |  7 ++++--
 tp/Texinfo/Convert/Text.pm       | 18 ++++++----------
 tp/init/chm.pm                   | 18 ++++++++++------
 tp/t/test_utils.pl               |  4 +++-
 tp/texi2any.pl                   | 34 ++++++++++++++++++++---------
 14 files changed, 190 insertions(+), 91 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index c731514..a2c312b 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,27 @@
 2021-08-31  Patrice Dumas  <pertusus@free.fr>
 
+       * tp/Texinfo/Common.pm (open_out, output_files_open_out)
+       (output_files_register_closed, output_files_opened_files)
+       (output_files_unclosed_files),
+       tp/Texinfo/Convert/Converter.pm (register_close_file, converter)
+       (converter_opened_files, converter_unclosed_files, 
output_files_information)
+       tp/DebugTexinfo/DebugTree.pm, tp/Texinfo/Convert/DocBook.pm,
+       tp/Texinfo/Convert/HTML.pm, tp/Texinfo/Convert/LaTeX.pm,
+       tp/Texinfo/Convert/TexinfoXML.pm, tp/Texinfo/Convert/Text.pm,
+       tp/init/chm.pm, tp/texi2any.pl:
+       move the opened output file registration API completly to
+       Texinfo::Common, renaming open_out() as output_files_open_out()
+       and moving converter_unclosed_files(), register_close_file()
+       converter_opened_files() from Convert::Converter to 
+       Texinfo::Common renaming as output_files_unclosed_files(),
+       output_files_register_closed() and output_files_opened_files().
+       Pass a hash reference, initialized in Convert::Converter::converter
+       to the API functions rather than a full converter.  Access 
+       this hash reference through output_files_information() defined in
+       Convert::Converter.
+
+2021-08-31  Patrice Dumas  <pertusus@free.fr>
+
        * tp/Texinfo/Structuring.pm (sectioning_structure, nodes_tree),
        tp/Texinfo/Convert/Converter.pm (%all_converters_defaults)
        (converter), Pod-Simple-Texinfo/pod2texi.pl, texi2any.pl:
diff --git a/tp/DebugTexinfo/DebugTree.pm b/tp/DebugTexinfo/DebugTree.pm
index 31153da..d99fff2 100644
--- a/tp/DebugTexinfo/DebugTree.pm
+++ b/tp/DebugTexinfo/DebugTree.pm
@@ -58,7 +58,9 @@ sub output($$)
 
   my $fh;
   if (! $self->{'output_file'} eq '') {
-    $fh = $self->Texinfo::Common::open_out ($self->{'output_file'});
+    $fh = Texinfo::Common::output_files_open_out(
+                             $self->output_files_information(), $self,
+                                     $self->{'output_file'});
     if (!$fh) {
       $self->document_error($self,
            sprintf($self->__("could not open %s for writing: %s"),
diff --git a/tp/Texinfo/Common.pm b/tp/Texinfo/Common.pm
index de468dc..7e2764a 100644
--- a/tp/Texinfo/Common.pm
+++ b/tp/Texinfo/Common.pm
@@ -1125,21 +1125,25 @@ sub locate_include_file($$)
   return $file;
 }
 
-sub open_out($$;$$)
+
+# internal API to open and register files.  In general $self is
+# stored as $converter->{'output_files'} and should be accessed
+# through $converter->output_files_information();
+sub output_files_open_out($$$;$)
 {
   my $self = shift;
+  my $configuration_informations = shift;
   my $file = shift;
-  my $encoding = shift;
   my $use_binmode = shift;
 
-  if (!defined($encoding) and $self 
-      and defined($self->get_conf('OUTPUT_PERL_ENCODING'))) {
-    $encoding = $self->get_conf('OUTPUT_PERL_ENCODING');
+  my $encoding;
+  if (defined($configuration_informations->get_conf('OUTPUT_PERL_ENCODING'))) {
+    $encoding = $configuration_informations->get_conf('OUTPUT_PERL_ENCODING');
   }
 
   if ($file eq '-') {
     binmode(STDOUT) if $use_binmode;
-    binmode(STDOUT, ":encoding($encoding)") if ($encoding);
+    binmode(STDOUT, ":encoding($encoding)") if (defined($encoding));
     if ($self) {
       $self->{'unclosed_files'}->{$file} = \*STDOUT;
     }
@@ -1170,6 +1174,35 @@ sub open_out($$;$$)
   return $filehandle;
 }
 
+sub output_files_register_closed($$)
+{
+  my $self = shift;
+  my $filename = shift;
+  if ($self->{'unclosed_files'}->{$filename}) {
+    delete $self->{'unclosed_files'}->{$filename};
+  } else {
+    cluck "$filename not opened\n";
+  }
+}
+
+sub output_files_opened_files($)
+{
+  my $self = shift;
+  if (defined($self->{'opened_files'})) {
+    return @{$self->{'opened_files'}};
+  } else {
+    return ();
+  }
+}
+
+sub output_files_unclosed_files($)
+{
+  my $self = shift;
+  return $self->{'unclosed_files'};
+}
+# end of output_files API
+
+
 sub warn_unknown_language($) {
   my $lang = shift;
 
diff --git a/tp/Texinfo/Convert/Converter.pm b/tp/Texinfo/Convert/Converter.pm
index 99e4e45..d9d0945 100644
--- a/tp/Texinfo/Convert/Converter.pm
+++ b/tp/Texinfo/Convert/Converter.pm
@@ -162,17 +162,6 @@ sub _informative_command($$)
   }
 }
 
-sub register_close_file($$)
-{
-  my $self = shift;
-  my $filename = shift;
-  if ($self->{'unclosed_files'}->{$filename}) {
-    delete $self->{'unclosed_files'}->{$filename};
-  } else {
-    cluck "$filename not opened\n";
-  }
-}
-
 sub converter(;$)
 {
   my $class = shift;
@@ -260,6 +249,10 @@ sub converter(;$)
     $converter->{'expanded_formats_hash'}->{$expanded_format} = 1;
   }
 
+  # used for output files information, to register opened
+  # and not closed files.  Accessed through output_files_information()
+  $converter->{'output_files'} = {};
+
   require Texinfo::Report;
   # 'require' here instead of 'use' at top of file to cut down run time of 
   # 'texi2any --help'
@@ -271,20 +264,10 @@ sub converter(;$)
   return $converter;
 }
 
-sub converter_unclosed_files($)
+sub output_files_information($)
 {
   my $self = shift;
-  return $self->{'unclosed_files'};
-}
-
-sub converter_opened_files($)
-{
-  my $self = shift;
-  if (defined($self->{'opened_files'})) {
-    return @{$self->{'opened_files'}};
-  } else {
-    return ();
-  }
+  return $self->{'output_files'};
 }
 
 sub _set_global_multiple_commands($;$)
@@ -787,7 +770,8 @@ sub output($$)
       }
       print STDERR "DO No pages, output in $outfile\n"
         if ($self->get_conf('DEBUG'));
-      $fh = $self->Texinfo::Common::open_out($outfile);
+      $fh = Texinfo::Common::output_files_open_out(
+                    $self->output_files_information(), $self, $outfile);
       if (!$fh) {
         $self->document_error($self,
                  sprintf(__("could not open %s for writing: %s"),
@@ -809,7 +793,8 @@ sub output($$)
     }
     # NOTE do not close STDOUT now to avoid a perl warning.
     if ($fh and $outfile ne '-') {
-      $self->register_close_file($outfile);
+      Texinfo::Common::output_files_register_closed(
+                  $self->output_files_information(), $outfile);
       if (!close($fh)) {
         $self->document_error($self,
                  sprintf(__("error on closing %s: %s"),
@@ -827,7 +812,9 @@ sub output($$)
       my $file_fh;
       # open the file and output the elements
       if (!$files{$element->{'filename'}}->{'fh'}) {
-        $file_fh = 
$self->Texinfo::Common::open_out($element->{'out_filename'});
+        $file_fh = Texinfo::Common::output_files_open_out(
+                             $self->output_files_information(), $self,
+                             $element->{'out_filename'});
         if (!$file_fh) {
           $self->document_error($self,
                 sprintf(__("could not open %s for writing: %s"),
@@ -844,7 +831,8 @@ sub output($$)
       if ($self->{'file_counters'}->{$element->{'filename'}} == 0) {
         # NOTE do not close STDOUT here to avoid a perl warning
         if ($element->{'out_filename'} ne '-') {
-          $self->register_close_file($element->{'out_filename'});
+          Texinfo::Common::output_files_register_closed(
+            $self->output_files_information(), $element->{'out_filename'});
           if (!close($file_fh)) {
             $self->document_error($self,
                      sprintf(__("error on closing %s: %s"),
@@ -1104,7 +1092,9 @@ sub output_no_split($$)
   
   my $fh;
   if (! $self->{'output_file'} eq '') {
-    $fh = $self->Texinfo::Common::open_out($self->{'output_file'});
+    $fh = Texinfo::Common::output_files_open_out(
+                             $self->output_files_information(), $self,
+                                     $self->{'output_file'});
     if (!$fh) {
       $self->document_error($self,
                sprintf(__("could not open %s for writing: %s"),
diff --git a/tp/Texinfo/Convert/DocBook.pm b/tp/Texinfo/Convert/DocBook.pm
index 61924d4..14ab6a0 100644
--- a/tp/Texinfo/Convert/DocBook.pm
+++ b/tp/Texinfo/Convert/DocBook.pm
@@ -312,7 +312,9 @@ sub output($$)
 
   my $fh;
   if (! $self->{'output_file'} eq '') {
-    $fh = $self->Texinfo::Common::open_out ($self->{'output_file'});
+    $fh = Texinfo::Common::output_files_open_out(
+                             $self->output_files_information(), $self,
+                             $self->{'output_file'});
     if (!$fh) {
       $self->document_error($self,
            sprintf(__("could not open %s for writing: %s"),
@@ -349,7 +351,8 @@ sub output($$)
   $result .= $self->convert_document_sections($root, $fh);
   $result .= $self->_output_text("</book>\n", $fh);
   if ($fh and $self->{'output_file'} ne '-') {
-    $self->register_close_file($self->{'output_file'});
+    Texinfo::Common::output_files_register_closed(
+                  $self->output_files_information(), $self->{'output_file'});
     if (!close ($fh)) {
       $self->document_error($self,
             sprintf(__("error on closing %s: %s"),
diff --git a/tp/Texinfo/Convert/HTML.pm b/tp/Texinfo/Convert/HTML.pm
index 5876c9f..f65ed78 100644
--- a/tp/Texinfo/Convert/HTML.pm
+++ b/tp/Texinfo/Convert/HTML.pm
@@ -7076,10 +7076,12 @@ __("cannot use absolute path or URL `%s' for 
JS_WEBLABELS_FILE when generating w
   }
   my $license_file = File::Spec->catdir($self->{'destination_directory'},
                                         $path);
-  my $fh = $self->Texinfo::Common::open_out($license_file);
+  my $fh = Texinfo::Common::output_files_open_out(
+                 $self->output_files_information(), $self, $license_file);
   if (defined($fh)) {
     print $fh $a;
-    $self->register_close_file($license_file);
+    Texinfo::Common::output_files_register_closed(
+                  $self->output_files_information(), $license_file);
     if (!close ($fh)) {
       $self->document_error($self,
                sprintf(__("error on closing %s: %s"),
@@ -7116,7 +7118,8 @@ sub _default_format_frame_files($)
     $toc_frame_outfile = $toc_frame_file;
   }
   
-  my $frame_fh = $self->Texinfo::Common::open_out($frame_outfile);
+  my $frame_fh = Texinfo::Common::output_files_open_out(
+                     $self->output_files_information(), $self, $frame_outfile);
   if (defined($frame_fh)) {
     my $doctype = $self->get_conf('FRAMESET_DOCTYPE');
     my $top_file = '';
@@ -7136,7 +7139,8 @@ $doctype
 </html>
 EOT
 
-    $self->register_close_file($frame_outfile);
+    Texinfo::Common::output_files_register_closed(
+                  $self->output_files_information(), $frame_outfile);
     if (!close ($frame_fh)) {
       $self->document_error($self,
           sprintf(__("error on closing frame file %s: %s"),
@@ -7150,7 +7154,8 @@ EOT
     return 0;
   }
 
-  my $toc_frame_fh = $self->Texinfo::Common::open_out($toc_frame_outfile);
+  my $toc_frame_fh = Texinfo::Common::output_files_open_out(
+                      $self->output_files_information(), $self, 
$toc_frame_outfile);
   if (defined($toc_frame_fh)) {
 
     my $header = &{$self->{'format_begin_file'}}($self, $toc_frame_file, 
undef);
@@ -7162,7 +7167,8 @@ EOT
     print $toc_frame_fh $shortcontents;
     print $toc_frame_fh "</body></html>\n";
 
-    $self->register_close_file($toc_frame_outfile);
+    Texinfo::Common::output_files_register_closed(
+                  $self->output_files_information(), $toc_frame_outfile);
     if (!close ($toc_frame_fh)) {
       $self->document_error($self,
             sprintf(__("error on closing TOC frame file %s: %s"),
@@ -7610,7 +7616,8 @@ sub output($$)
       } else {
         $outfile = $self->{'output_file'};
       }
-      $fh = $self->Texinfo::Common::open_out($outfile);
+      $fh = Texinfo::Common::output_files_open_out(
+              $self->output_files_information(), $self,$outfile);
       if (!$fh) {
         $self->document_error($self,
               sprintf(__("could not open %s for writing: %s"),
@@ -7639,7 +7646,8 @@ sub output($$)
 
     # NOTE do not close STDOUT now to avoid a perl warning.
     if ($fh and $outfile ne '-') {
-      $self->register_close_file($outfile);
+      Texinfo::Common::output_files_register_closed(
+                  $self->output_files_information(), $outfile);
       if (!close($fh)) {
         $self->document_error($self,
               sprintf(__("error on closing %s: %s"),
@@ -7684,7 +7692,9 @@ sub output($$)
       }
 
       if (!$files{$element->{'filename'}}->{'fh'}) {
-        $file_fh = 
$self->Texinfo::Common::open_out($element->{'out_filename'});
+        $file_fh = Texinfo::Common::output_files_open_out(
+                         $self->output_files_information(), $self,
+                         $element->{'out_filename'});
         if (!$file_fh) {
           $self->document_error($self,
                sprintf(__("could not open %s for writing: %s"),
@@ -7706,7 +7716,8 @@ sub output($$)
 
         # NOTE do not close STDOUT here to avoid a perl warning
         if ($element->{'out_filename'} ne '-') {
-          $self->register_close_file($element->{'out_filename'});
+          Texinfo::Common::output_files_register_closed(
+             $self->output_files_information(), $element->{'out_filename'});
           if (!close($file_fh)) {
             $self->document_error($self,
                        sprintf(__("error on closing %s: %s"),
@@ -7792,14 +7803,17 @@ sub output($$)
         } else {
           $out_filename = $node_filename;
         }
-        my $file_fh = $self->Texinfo::Common::open_out($out_filename);
+        my $file_fh = Texinfo::Common::output_files_open_out(
+                             $self->output_files_information(), $self,
+                             $out_filename);
         if (!$file_fh) {
          $self->document_error($self, sprintf(__(
                                     "could not open %s for writing: %s"),
                                     $out_filename, $!));
         } else {
           print $file_fh $redirection_page;
-          $self->register_close_file($out_filename);
+          Texinfo::Common::output_files_register_closed(
+                  $self->output_files_information(), $out_filename);
           if (!close ($file_fh)) {
             $self->document_error($self, sprintf(__(
                              "error on closing redirection node file %s: %s"),
diff --git a/tp/Texinfo/Convert/IXIN.pm b/tp/Texinfo/Convert/IXIN.pm
index 296f743..cc5a453 100644
--- a/tp/Texinfo/Convert/IXIN.pm
+++ b/tp/Texinfo/Convert/IXIN.pm
@@ -281,7 +281,9 @@ sub output_ixin($$)
 
   my $fh;
   if (! $self->{'output_file'} eq '') {
-    $fh = $self->Texinfo::Common::open_out($self->{'output_file'});
+    $fh = Texinfo::Common::output_files_open_out(
+                             $self->output_files_information(), $self,
+                             $self->{'output_file'});
     if (!$fh) {
       $self->document_error($self,
                 sprintf(__("could not open %s for writing: %s"),
@@ -905,7 +907,8 @@ sub output_ixin($$)
   $output .= $self->_output_text($blobs, $fh);
 
   if ($fh and $self->{'output_file'} ne '-') {
-    $self->register_close_file($self->{'output_file'});
+    Texinfo::Common::output_files_register_closed(
+                  $self->output_files_information(), $self->{'output_file'});
     if (!close ($fh)) {
       $self->document_error($self,
                 sprintf(__("error on closing %s: %s"),
diff --git a/tp/Texinfo/Convert/Info.pm b/tp/Texinfo/Convert/Info.pm
index 20d5bfb..acddf4a 100644
--- a/tp/Texinfo/Convert/Info.pm
+++ b/tp/Texinfo/Convert/Info.pm
@@ -155,7 +155,8 @@ sub output($)
           $close_error = $!;
         }
         if ($out_file_nr == 1) {
-          $self->register_close_file($self->{'output_file'});
+          Texinfo::Common::output_files_register_closed(
+             $self->output_files_information(), $self->{'output_file'});
           if (defined($close_error)) {
             $self->document_error($self,
                   sprintf(__("error on closing %s: %s"),
@@ -183,7 +184,9 @@ sub output($)
                                  $complete_header_bytes];
           #print STDERR join(' --> ', @{$indirect_files[-1]}) ."\n";
         } else {
-          $self->register_close_file($self->{'output_file'}.'-'.$out_file_nr);
+          Texinfo::Common::output_files_register_closed(
+                           $self->output_files_information(),
+                           $self->{'output_file'}.'-'.$out_file_nr);
           if (defined($close_error)) {
             $self->document_error($self,
                   sprintf(__("error on closing %s: %s"),
@@ -212,7 +215,8 @@ sub output($)
   }
   my $tag_text = '';
   if ($out_file_nr > 1) {
-    $self->register_close_file($self->{'output_file'}.'-'.$out_file_nr);
+    Texinfo::Common::output_files_register_closed(
+      $self->output_files_information(), 
$self->{'output_file'}.'-'.$out_file_nr);
     if (!close ($fh)) {
       $self->document_error($self,
                sprintf(__("error on closing %s: %s"),
@@ -276,7 +280,8 @@ sub output($)
     # reopened after closing STDOUT.  So closing STDOUT is handled by the
     # caller.
     unless ($self->{'output_file'} eq '-') {
-      $self->register_close_file($self->{'output_file'});
+      Texinfo::Common::output_files_register_closed(
+         $self->output_files_information(), $self->{'output_file'});
       if (!close ($fh)) {
         $self->document_error($self,
                   sprintf(__("error on closing %s: %s"),
@@ -289,14 +294,17 @@ sub output($)
   return $result;
 }
 
-# Wrapper around Texinfo::Common::open_out.  Open the file with any CR-LF
-# conversion disabled.  We need this for tag tables to be correct under
-# MS-Windows.   Return filehandle or undef on failure.
+# Wrapper around Texinfo::Common::output_files_open_out.  Open the file
+# with any CR-LF conversion disabled.  We need this for tag tables to
+# be correct under MS-Windows.   Return filehandle or undef on failure.
 sub _open_info_file($$)
 {
   my $self = shift;
   my $filename = shift;
-  my $fh = $self->Texinfo::Common::open_out($filename, undef, 'use_binmode');
+  my $fh = Texinfo::Common::output_files_open_out(
+                             $self->output_files_information(), $self,
+                             $filename, 'use_binmode');
+
   if (!$fh) {
     $self->document_error($self, sprintf(
         __("could not open %s for writing: %s"),
diff --git a/tp/Texinfo/Convert/LaTeX.pm b/tp/Texinfo/Convert/LaTeX.pm
index 8c33efe..d92a72e 100644
--- a/tp/Texinfo/Convert/LaTeX.pm
+++ b/tp/Texinfo/Convert/LaTeX.pm
@@ -885,7 +885,9 @@ sub output($$)
 
   my $fh;
   if (! $self->{'output_file'} eq '') {
-    $fh = $self->Texinfo::Common::open_out ($self->{'output_file'});
+    $fh = Texinfo::Common::output_files_open_out(
+                             $self->output_files_information(), $self,
+                             $self->{'output_file'});
     if (!$fh) {
       $self->document_error($self,
              sprintf(__("could not open %s for writing: %s"),
@@ -975,7 +977,8 @@ sub output($$)
 
   #print $result;
   if ($fh and $self->{'output_file'} ne '-') {
-    $self->register_close_file($self->{'output_file'});
+    Texinfo::Common::output_files_register_closed(
+                  $self->output_files_information(), $self->{'output_file'});
     if (!close ($fh)) {
       $self->document_error($self,
                    sprintf(__("error on closing %s: %s"),
diff --git a/tp/Texinfo/Convert/TexinfoXML.pm b/tp/Texinfo/Convert/TexinfoXML.pm
index 49708ed..6828e43 100644
--- a/tp/Texinfo/Convert/TexinfoXML.pm
+++ b/tp/Texinfo/Convert/TexinfoXML.pm
@@ -457,7 +457,9 @@ sub output($$)
 
   my $fh;
   if (! $self->{'output_file'} eq '') {
-    $fh = $self->Texinfo::Common::open_out($self->{'output_file'});
+    $fh = Texinfo::Common::output_files_open_out(
+                             $self->output_files_information(), $self,
+                             $self->{'output_file'});
     if (!$fh) {
       $self->document_error(sprintf(__("could not open %s for writing: %s"),
                                     $self->{'output_file'}, $!));
@@ -476,7 +478,8 @@ sub output($$)
   }
   $result .= $self->_output_text($self->close_element('texinfo')."\n", $fh);
   if ($fh and $self->{'output_file'} ne '-') {
-    $self->register_close_file($self->{'output_file'});
+    Texinfo::Common::output_files_register_closed(
+                  $self->output_files_information(), $self->{'output_file'});
     if (!close ($fh)) {
       $self->document_error(sprintf(__("error on closing %s: %s"),
                                     $self->{'output_file'}, $!));
diff --git a/tp/Texinfo/Convert/Text.pm b/tp/Texinfo/Convert/Text.pm
index 2288a0b..4cba7b5 100644
--- a/tp/Texinfo/Convert/Text.pm
+++ b/tp/Texinfo/Convert/Text.pm
@@ -710,14 +710,20 @@ sub output($$)
     $outfile = $self->{'OUTFILE'};
   }
   my $fh;
+  $self->{'output_files'} = {};
   if (defined($outfile)) {
-    $fh = $self->Texinfo::Common::open_out($outfile);
+    $fh = Texinfo::Common::output_files_open_out(
+                             $self->{'output_files'}, $self,
+                             $outfile);
     return undef if (!$fh);
   }
   my %options = $self->Texinfo::Common::_convert_text_options();
   my $result = _convert($tree, \%options);
   if ($fh) {
     print $fh $result;
+    # it is cleaner to follow the API (but not really useful)
+    Texinfo::Common::output_files_register_closed(
+                  $self->{'output_files'}, $outfile);
     return undef if (!close($fh));
     $result = '';
   }
@@ -737,16 +743,6 @@ sub errors()
   return undef;
 }
 
-sub converter_unclosed_files()
-{
-  return undef;
-}
-
-sub converter_opened_files()
-{
-  return ();
-}
-
 sub converter_defaults()
 {
   return ();
diff --git a/tp/init/chm.pm b/tp/init/chm.pm
index add3537..72d4a2c 100644
--- a/tp/init/chm.pm
+++ b/tp/init/chm.pm
@@ -217,7 +217,8 @@ sub chm_init($)
 
   my $hhk_filename = $document_name . ".hhk";
   my $hhk_file = File::Spec->catfile($outdir, $hhk_filename);
-  my $hhk_fh = Texinfo::Common::open_out($self, $hhk_file);
+  my $hhk_fh = Texinfo::Common::output_files_open_out(
+                      $self->output_files_information(), $self, $hhk_file);
   if (!defined($hhk_fh)) {
     $self->document_error($self,
          sprintf(__("chm.pm: could not open %s for writing: %s\n"), 
@@ -264,7 +265,8 @@ sub chm_init($)
     }
   }
   print $hhk_fh "</BODY>\n</HTML>\n";
-  delete $self->{'unclosed_files'}->{$hhk_file};
+  Texinfo::Common::output_files_register_closed(
+    $self->output_files_information(), $hhk_file);
   if (!close ($hhk_fh)) {
     $self->document_error($self,
            sprintf(__("chm.pm: error on closing %s: %s"),
@@ -274,7 +276,8 @@ sub chm_init($)
 
   my $hhc_filename = $document_name . ".hhc";
   my $hhc_file = File::Spec->catfile($outdir, $hhc_filename);
-  my $hhc_fh = Texinfo::Common::open_out($self, $hhc_file);
+  my $hhc_fh = Texinfo::Common::output_files_open_out(
+                      $self->output_files_information(), $self, $hhc_file);
   # Not sure $! is still valid
   if (!defined($hhc_fh)) {
     $self->document_error($self,
@@ -336,7 +339,8 @@ sub chm_init($)
     }
   }
   print $hhc_fh "</HTML>\n</BODY>\n";
-  delete $self->{'unclosed_files'}->{$hhc_file};
+  Texinfo::Common::output_files_register_closed(
+    $self->output_files_information(), $hhc_file);
   if (!close ($hhc_fh)) {
     $self->document_error($self,
            sprintf(__("chm.pm: error on closing %s: %s"),
@@ -346,7 +350,8 @@ sub chm_init($)
 
   my $hhp_filename = $document_name . ".hhp";
   my $hhp_file = File::Spec->catfile($outdir, $hhp_filename);
-  my $hhp_fh = Texinfo::Common::open_out($self, $hhp_file);
+  my $hhp_fh = Texinfo::Common::output_files_open_out(
+                      $self->output_files_information(), $self, $hhp_file);
   # Not sure $! is still valid
   if (!defined($hhp_fh)) {
     $self->document_error(
@@ -399,7 +404,8 @@ EOT
     }
   }
 
-  delete $self->{'unclosed_files'}->{$hhp_file};
+  Texinfo::Common::output_files_register_closed(
+    $self->output_files_information(), $hhp_file);
   if (!close ($hhp_fh)) {
     $self->document_error($self,
          sprintf(__("chm.pm: error on closing %s: %s"),
diff --git a/tp/t/test_utils.pl b/tp/t/test_utils.pl
index 2699e48..583def2 100644
--- a/tp/t/test_utils.pl
+++ b/tp/t/test_utils.pl
@@ -527,7 +527,9 @@ sub set_converter_option_defaults($$$)
 sub close_files($)
 {
   my $converter = shift;
-  my $converter_unclosed_files = $converter->converter_unclosed_files();
+  my $converter_unclosed_files
+       = Texinfo::Common::output_files_unclosed_files(
+                               $converter->output_files_information());
   if ($converter_unclosed_files) {
     foreach my $unclosed_file (keys(%$converter_unclosed_files)) {
       if (!close($converter_unclosed_files->{$unclosed_file})) {
diff --git a/tp/texi2any.pl b/tp/texi2any.pl
index 2255755..5cafed6 100755
--- a/tp/texi2any.pl
+++ b/tp/texi2any.pl
@@ -1170,6 +1170,7 @@ die sprintf(__("%s: missing file argument.\n"), 
$real_command_name)
    .sprintf(__("Try `%s --help' for more information.\n"), $real_command_name)
      unless (scalar(@input_files) >= 1);
 
+my $files_information = {};
 my $file_number = -1;
 my @opened_files = ();
 my %unclosed_files;
@@ -1254,17 +1255,18 @@ while(@input_files) {
     my $texinfo_text = Texinfo::Convert::Texinfo::convert_to_texinfo($tree);
     #print STDERR "$texinfo_text\n";
     my $macro_expand_file = get_conf('MACRO_EXPAND');
-    my $macro_expand_fh = Texinfo::Common::open_out($parser, 
$macro_expand_file);
-
+    my $macro_expand_fh = Texinfo::Common::output_files_open_out(
+                            $files_information, $parser, $macro_expand_file);
     my $error_macro_expand_file;
     if (defined($macro_expand_fh)) {
       print $macro_expand_fh $texinfo_text;
+      Texinfo::Common::output_files_register_closed($files_information,
+                                                    $macro_expand_file);
       if (!close($macro_expand_fh)) {
         document_warn(sprintf(__("error on closing macro expand file %s: 
%s\n"), 
                               $macro_expand_file, $!));
         $error_macro_expand_file = 1;
       }
-      
$parser->Texinfo::Convert::Converter::register_close_file($macro_expand_file);
     } else {
       document_warn(sprintf(__("could not open %s for writing: %s\n"), 
                             $macro_expand_file, $!));
@@ -1401,9 +1403,12 @@ while(@input_files) {
 
   my $converter = 
&{$formats_table{$format}->{'converter'}}($converter_options);
   $converter->output($tree);
-  push @opened_files, $converter->converter_opened_files();
+  push @opened_files, Texinfo::Common::output_files_opened_files(
+                              $converter->output_files_information());
   handle_errors($converter, $error_count, \@opened_files);
-  my $converter_unclosed_files = $converter->converter_unclosed_files();
+  my $converter_unclosed_files
+       = Texinfo::Common::output_files_unclosed_files(
+                               $converter->output_files_information());
   if ($converter_unclosed_files) {
     foreach my $unclosed_file (keys(%$converter_unclosed_files)) {
       if ($unclosed_file eq '-') {
@@ -1427,7 +1432,8 @@ while(@input_files) {
     # always create a file, even if empty.
     $internal_links_text = '' if (!defined($internal_links_text));
     my $internal_links_file = get_conf('INTERNAL_LINKS');
-    my $internal_links_fh = Texinfo::Common::open_out($converter, 
+    my $internal_links_fh = Texinfo::Common::output_files_open_out(
+                              $converter->output_files_information(), 
$converter,
                                              $internal_links_file);
     my $error_internal_links_file;
     if (defined ($internal_links_fh)) {
@@ -1438,7 +1444,8 @@ while(@input_files) {
                       $real_command_name, $internal_links_file, $!));
         $error_internal_links_file = 1;
       }
-      $converter->register_close_file($internal_links_file);
+      Texinfo::Common::output_files_register_closed(
+              $converter->output_files_information(), $internal_links_file);
     } else {
       warn(sprintf(__("%s: could not open %s for writing: %s\n"), 
                       $real_command_name, $internal_links_file, $!));
@@ -1460,8 +1467,13 @@ while(@input_files) {
                $converter_element_count_file, $tree, $use_sections,
                              get_conf('SORT_ELEMENT_COUNT_WORDS'));
 
-    my $sort_element_count_file = get_conf('SORT_ELEMENT_COUNT'); 
-    my $sort_element_count_fh = Texinfo::Common::open_out($converter, 
+    my $sort_element_count_file = get_conf('SORT_ELEMENT_COUNT');
+    # FIXME using $converter here for the configuration is
+    # not right, should be changed by something not associated
+    # with the converter but to the main program or file. parser
+    # is not much better
+    my $sort_element_count_fh = Texinfo::Common::output_files_open_out(
+                                        $files_information, $converter,
                                              $sort_element_count_file);
     my $error_sort_element_count_file;
     if (defined ($sort_element_count_fh)) {
@@ -1472,7 +1484,8 @@ while(@input_files) {
                       $real_command_name, $sort_element_count_file, $!));
         $error_sort_element_count_file = 1;
       }
-      $converter->register_close_file($sort_element_count_file);
+      Texinfo::Common::output_files_register_closed($files_information,
+                                              $sort_element_count_file);
     } else {
       warn(sprintf(__("%s: could not open %s for writing: %s\n"), 
                     $real_command_name, $sort_element_count_file, $!));
@@ -1485,6 +1498,7 @@ while(@input_files) {
   }
 }
 
+# FIXME use $files_information?
 foreach my $unclosed_file (keys(%unclosed_files)) {
   if (!close($unclosed_files{$unclosed_file})) {
     warn(sprintf(__("%s: error on closing %s: %s\n"), 



reply via email to

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