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


From: Patrice Dumas
Subject: branch master updated: * tp/Texinfo/Convert/Converter.pm (determine_files_and_directory) (_set_element_file, _top_node_filename, _set_pages_files) (create_destination_directory), tp/DebugTexinfo/DebugTree.pm, tp/Texinfo/Convert/DocBook.pm, tp/Texinfo/Convert/HTML.pm (_set_html_pages_files, _prepare_elements, _prepare_special_elements) (_default_format_frame_files, _do_jslicenses_file), tp/Texinfo/Convert/IXIN.pm, tp/Texinfo/Convert/Info.pm, tp/Texinfo/Convert/LaTeX.pm, tp/Texinfo/Convert/TexinfoSXML.pm, tp/Texin [...]
Date: Tue, 07 Sep 2021 11:17:46 -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 0203ca9  * tp/Texinfo/Convert/Converter.pm 
(determine_files_and_directory) (_set_element_file, _top_node_filename, 
_set_pages_files) (create_destination_directory), tp/DebugTexinfo/DebugTree.pm, 
tp/Texinfo/Convert/DocBook.pm, tp/Texinfo/Convert/HTML.pm 
(_set_html_pages_files, _prepare_elements, _prepare_special_elements) 
(_default_format_frame_files, _do_jslicenses_file), tp/Texinfo/Convert/IXIN.pm, 
tp/Texinfo/Convert/Info.pm, tp/Texinfo/Convert/LaTeX.pm, 
tp/Texinfo/Convert/Texin [...]
0203ca9 is described below

commit 0203ca906ee2279cba1f3d6cf5ca50a18356f16d
Author: Patrice Dumas <pertusus@free.fr>
AuthorDate: Tue Sep 7 17:17:35 2021 +0200

    * tp/Texinfo/Convert/Converter.pm (determine_files_and_directory)
    (_set_element_file, _top_node_filename, _set_pages_files)
    (create_destination_directory), tp/DebugTexinfo/DebugTree.pm,
    tp/Texinfo/Convert/DocBook.pm, tp/Texinfo/Convert/HTML.pm
    (_set_html_pages_files, _prepare_elements, _prepare_special_elements)
    (_default_format_frame_files, _do_jslicenses_file),
    tp/Texinfo/Convert/IXIN.pm, tp/Texinfo/Convert/Info.pm,
    tp/Texinfo/Convert/LaTeX.pm, tp/Texinfo/Convert/TexinfoSXML.pm,
    tp/Texinfo/Convert/TexinfoXML.pm, tp/Texinfo/Convert/Text.pm:
    in Texinfo::Convert::Converter rename _create_destination_directory() as
    create_destination_directory() and _set_outfile() as
    determine_files_and_directory().  Do not set anything directly
    in those methods, set if needed in the specific converters,
    instead return the file and directory names.  Pass those names
    directly to files called in output(), notably _set_element_file(),
    _top_node_filename() and _set_pages_files() instead of using the
    converter as a hash.  Rename _set_pages_files() as
    _set_html_pages_files() in Texinfo::Convert::HTML and pass the
    file names to this method and other methods called by output().
    
    * tp/Texinfo/Convert/Converter.pm (output_no_split): close output
    file.  This method is unused and untested.
---
 ChangeLog                         |  25 +++
 tp/DebugTexinfo/DebugTree.pm      |  18 ++-
 tp/Texinfo/Convert/Converter.pm   | 327 +++++++++++++++++++++++---------------
 tp/Texinfo/Convert/DocBook.pm     |  22 +--
 tp/Texinfo/Convert/HTML.pm        | 133 +++++++++-------
 tp/Texinfo/Convert/IXIN.pm        |  22 +--
 tp/Texinfo/Convert/Info.pm        |  80 +++++-----
 tp/Texinfo/Convert/LaTeX.pm       |  19 ++-
 tp/Texinfo/Convert/TexinfoSXML.pm |   9 +-
 tp/Texinfo/Convert/TexinfoXML.pm  |  31 ++--
 tp/Texinfo/Convert/Text.pm        |   3 +-
 tp/Texinfo/Structuring.pm         |   2 +-
 tp/t/91morecoverage.t             |   1 -
 13 files changed, 419 insertions(+), 273 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index c8cf22a..09b65ba 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,28 @@
+2021-09-07  Patrice Dumas  <pertusus@free.fr>
+
+       * tp/Texinfo/Convert/Converter.pm (determine_files_and_directory)
+       (_set_element_file, _top_node_filename, _set_pages_files)
+       (create_destination_directory), tp/DebugTexinfo/DebugTree.pm,
+       tp/Texinfo/Convert/DocBook.pm, tp/Texinfo/Convert/HTML.pm
+       (_set_html_pages_files, _prepare_elements, _prepare_special_elements)
+       (_default_format_frame_files, _do_jslicenses_file),
+       tp/Texinfo/Convert/IXIN.pm, tp/Texinfo/Convert/Info.pm,
+       tp/Texinfo/Convert/LaTeX.pm, tp/Texinfo/Convert/TexinfoSXML.pm,
+       tp/Texinfo/Convert/TexinfoXML.pm, tp/Texinfo/Convert/Text.pm:
+       in Texinfo::Convert::Converter rename _create_destination_directory() as
+       create_destination_directory() and _set_outfile() as
+       determine_files_and_directory().  Do not set anything directly
+       in those methods, set if needed in the specific converters,
+       instead return the file and directory names.  Pass those names
+       directly to files called in output(), notably _set_element_file(),
+       _top_node_filename() and _set_pages_files() instead of using the
+       converter as a hash.  Rename _set_pages_files() as
+       _set_html_pages_files() in Texinfo::Convert::HTML and pass the
+       file names to this method and other methods called by output().
+
+       * tp/Texinfo/Convert/Converter.pm (output_no_split): close output
+       file.  This method is unused and untested.
+
 2021-09-06  Patrice Dumas  <pertusus@free.fr>
 
        * tp/Texinfo/Convert/Converter.pm (_set_pages_files): do not use
diff --git a/tp/DebugTexinfo/DebugTree.pm b/tp/DebugTexinfo/DebugTree.pm
index d99fff2..aeeeade 100644
--- a/tp/DebugTexinfo/DebugTree.pm
+++ b/tp/DebugTexinfo/DebugTree.pm
@@ -52,19 +52,25 @@ sub output($$)
   my $self = shift;
   my $root = shift;
 
-
-  $self->_set_outfile();
-  return undef unless $self->_create_destination_directory();
+  my ($output_file, $destination_directory) = 
$self->determine_files_and_directory();
+  # REMARK for this format SPLIT does not means diverse files created
+  # so the way the directory is determined/created if there is already
+  # a file with the same name does not make sense for this format.
+  # Given that this format is only to be used for debugging, this is
+  # not an issue that really needs fixing.
+  my ($succeeded, $created_directory)
+    = $self->create_destination_directory($destination_directory);
+  return undef unless $succeeded;
 
   my $fh;
-  if (! $self->{'output_file'} eq '') {
+  if (! $output_file eq '') {
     $fh = Texinfo::Common::output_files_open_out(
                              $self->output_files_information(), $self,
-                                     $self->{'output_file'});
+                                     $output_file);
     if (!$fh) {
       $self->document_error($self,
            sprintf($self->__("could not open %s for writing: %s"),
-                                    $self->{'output_file'}, $!));
+                                    $output_file, $!));
       return undef;
     }
   }
diff --git a/tp/Texinfo/Convert/Converter.pm b/tp/Texinfo/Convert/Converter.pm
index 581a814..8bcb32b 100644
--- a/tp/Texinfo/Convert/Converter.pm
+++ b/tp/Texinfo/Convert/Converter.pm
@@ -356,7 +356,7 @@ sub set_conf($$$)
 sub force_conf($$$)
 {
   my $self = shift;
-  my $conf = shift; 
+  my $conf = shift;
   my $value = shift;
   if (!Texinfo::Common::valid_option($conf)) {
     die "ABUG: unknown option $conf\n";
@@ -368,27 +368,28 @@ sub force_conf($$$)
 
 my $STDIN_DOCU_NAME = 'stdin';
 
-sub _set_outfile($$$)
+sub determine_files_and_directory($)
 {
   my $self = shift;
 
   # determine input file base name
-  my $input_basename;
+  my $input_basefile;
   if (defined($self->{'parser_info'}->{'input_file_name'})) {
     my ($directories, $suffix);
-    ($input_basename, $directories, $suffix) 
+    ($input_basefile, $directories, $suffix)
        = fileparse($self->{'parser_info'}->{'input_file_name'});
   } else {
     # This could happen if called on a piece of texinfo
-    $input_basename = '';
+    $input_basefile = '';
   }
-  $self->{'input_basename'} = $input_basename;
-  if ($input_basename eq '-') {
-    $input_basename = $STDIN_DOCU_NAME 
+
+  my $input_basename;
+  if ($input_basefile eq '-') {
+    $input_basename = $STDIN_DOCU_NAME;
   } else {
+    $input_basename = $input_basefile;
     $input_basename =~ s/\.te?x(i|info)?$//;
   }
-  $self->{'input_basename_name'} = $input_basename;
 
   my $setfilename;
   if (defined($self->get_conf('setfilename'))) {
@@ -399,87 +400,93 @@ sub _set_outfile($$$)
      $setfilename = $self->{'extra'}->{'setfilename'}->{'extra'}->{'text_arg'}
   }
 
+  my $input_basename_for_outfile = $input_basename;
+  my $setfilename_for_outfile = $setfilename;
   # PREFIX overrides both setfilename and the input file base name
   if (defined($self->get_conf('PREFIX'))) {
-    $setfilename = undef;
-    $input_basename = $self->get_conf('PREFIX');
+    $setfilename_for_outfile = undef;
+    $input_basename_for_outfile = $self->get_conf('PREFIX');
   }
 
-  # the name of the document, which is more or less the basename, without 
-  # extension
-  my $document_name;
+  # the document path, in general the outfile without
+  # extension and can be set from setfilename if outfile is not set
+  my $document_path;
   # determine output file and output file name
-  my $outfile;
+  my $output_file;
   if (!defined($self->get_conf('OUTFILE'))) {
-    if (defined($setfilename) and !$self->get_conf('NO_USE_SETFILENAME')) {
-      $outfile = $setfilename;
-      $document_name = $setfilename;
-      $document_name =~ s/\.[^\.]*$//;
+    if (defined($setfilename_for_outfile) and 
!$self->get_conf('NO_USE_SETFILENAME')) {
+      $output_file = $setfilename_for_outfile;
+      $document_path = $setfilename_for_outfile;
+      $document_path =~ s/\.[^\.]*$//;
       if (!$self->get_conf('USE_SETFILENAME_EXTENSION')) {
-        $outfile =~ s/\.[^\.]*$//;
-        $outfile .= '.'.$self->get_conf('EXTENSION') 
-          if (defined($self->get_conf('EXTENSION')) 
+        $output_file =~ s/\.[^\.]*$//;
+        $output_file .= '.'.$self->get_conf('EXTENSION')
+          if (defined($self->get_conf('EXTENSION'))
               and $self->get_conf('EXTENSION') ne '');
       }
-    } elsif ($input_basename ne '') {
-      $outfile = $input_basename;
-      $document_name = $input_basename;
-      $outfile .= '.'.$self->get_conf('EXTENSION') 
-        if (defined($self->get_conf('EXTENSION')) 
+    } elsif ($input_basename_for_outfile ne '') {
+      $output_file = $input_basename_for_outfile;
+      $document_path = $input_basename_for_outfile;
+      $output_file .= '.'.$self->get_conf('EXTENSION')
+        if (defined($self->get_conf('EXTENSION'))
             and $self->get_conf('EXTENSION') ne '');
     } else {
-      $outfile = '';
-      $document_name = $outfile;
+      $output_file = '';
+      $document_path = $output_file;
     }
-    if (defined($self->get_conf('SUBDIR')) and $outfile ne '') {
+    if (defined($self->get_conf('SUBDIR')) and $output_file ne '') {
       my $dir = File::Spec->canonpath($self->get_conf('SUBDIR'));
-      $outfile = File::Spec->catfile($dir, $outfile);
+      $output_file = File::Spec->catfile($dir, $output_file);
     }
   } else {
-    $document_name = $self->get_conf('OUTFILE');
-    $document_name =~ s/\.[^\.]*$//;
-    $outfile = $self->get_conf('OUTFILE');
-  }
-
-  # the output file without directories part.
-  my $output_filename = $outfile;
-  # this is a case that should happen rarely: one wants to get 
-  # the result in a string and there is a setfilename.
-  if ($outfile eq '' and defined($setfilename)
+    $document_path = $self->get_conf('OUTFILE');
+    $document_path =~ s/\.[^\.]*$//;
+    $output_file = $self->get_conf('OUTFILE');
+  }
+
+  # the output file path, in general same as the outfile but can be
+  # set from setfilename if outfile is not set.
+  my $output_filepath = $output_file;
+  # in this case one wants to get the result in a string and there
+  # is a setfilename.  The setfilename is used to get something.
+  # This happens in the test suite.
+  if ($output_file eq '' and defined($setfilename_for_outfile)
       and !$self->get_conf('NO_USE_SETFILENAME')) {
-    $output_filename = $setfilename;
-    $document_name = $setfilename;
-    $document_name =~ s/\.[^\.]*$//;
+    $output_filepath = $setfilename_for_outfile;
+    $document_path = $setfilename_for_outfile;
+    $document_path =~ s/\.[^\.]*$//;
   }
-  my ($directories, $suffix);
+
+  # $document_name is the name of the document, which is the output
+  # file basename, $output_filename, without extension.
+  my ($document_name, $output_filename, $directories, $suffix);
   # We may be handling setfilename there, so it is not obvious that we
-  # want to use fileparse and not consider unixish separators.  However, 
-  # if this is setfilename, it should be a simple file name, so it 
+  # want to use fileparse and not consider unixish separators.  However,
+  # if this is setfilename, it should be a simple file name, so it
   # should hopefully be harmless to use fileparse
-  ($document_name, $directories, $suffix) = fileparse($document_name);
-  $self->{'document_name'} = $document_name;
-  ($output_filename, $directories, $suffix) = fileparse($output_filename);
-  $self->{'output_filename'} = $output_filename;
+  ($document_name, $directories, $suffix) = fileparse($document_path);
+  ($output_filename, $directories, $suffix) = fileparse($output_filepath);
+  my $destination_directory;
   if ($self->get_conf('SPLIT')) {
     if (defined($self->get_conf('OUTFILE'))) {
-      $self->{'destination_directory'} = $self->get_conf('OUTFILE');
+      $destination_directory = $self->get_conf('OUTFILE');
     } elsif (defined($self->get_conf('SUBDIR'))) {
-      $self->{'destination_directory'} = $self->get_conf('SUBDIR');
+      $destination_directory = $self->get_conf('SUBDIR');
     } else {
-      $self->{'destination_directory'} = $document_name;
+      $destination_directory = $document_name;
     }
   } else {
-    my ($out_filename, $output_dir, $suffix) = fileparse($outfile);
+    my ($out_filename, $output_dir, $suffix) = fileparse($output_file);
     if ($output_dir ne '') {
-      $self->{'destination_directory'} = $output_dir;
+      $destination_directory = $output_dir;
     }
   }
-  if (defined($self->{'destination_directory'}) 
-      and $self->{'destination_directory'} ne '') {
-    $self->{'destination_directory'} 
-      = File::Spec->canonpath($self->{'destination_directory'});
+  if (defined($destination_directory)
+      and $destination_directory ne '') {
+    $destination_directory = File::Spec->canonpath($destination_directory);
   }
-  $self->{'output_file'} = $outfile;
+  return ($output_file, $destination_directory, $output_filename,
+          $document_name, $input_basefile);
 }
 
 sub _id_to_filename($$)
@@ -537,11 +544,12 @@ sub _node_filename($$)
   return $filename;
 }
 
-sub _set_element_file($$$)
+sub _set_element_file($$$$)
 {
   my $self = shift;
   my $element = shift;
   my $filename = shift;
+  my $destination_directory = shift;
 
   if (!defined($filename)) {
     cluck("_set_element_file: filename not defined\n");
@@ -558,18 +566,18 @@ sub _set_element_file($$$)
     }
   }
   $element->{'filename'} = $filename;
-  if (defined($self->{'destination_directory'}) 
-      and $self->{'destination_directory'} ne '') {
+  if (defined($destination_directory) and $destination_directory ne '') {
     $element->{'out_filename'} = 
-      File::Spec->catfile($self->{'destination_directory'}, $filename);
+      File::Spec->catfile($destination_directory, $filename);
   } else {
     $element->{'out_filename'} = $filename;
   }
 }
 
-sub _top_node_filename($)
+sub _top_node_filename($$)
 {
   my $self = shift;
+  my $document_name = shift;
 
   my $top_node_filename;
   if (defined($self->get_conf('TOP_FILE')) 
@@ -581,7 +589,7 @@ sub _top_node_filename($)
       if (defined($self->get_conf('EXTENSION'))
             and $self->get_conf('EXTENSION') ne '');
 
-    $top_node_filename = $self->{'document_name'};
+    $top_node_filename = $document_name;
     if (defined($top_node_filename)) {
       $top_node_filename .= $extension;
     }
@@ -611,10 +619,14 @@ sub _get_element($$)
   }
 }
 
-sub _set_pages_files($$)
+sub _set_pages_files($$$$$$)
 {
   my $self = shift;
   my $elements = shift;
+  my $output_file = shift;
+  my $destination_directory = shift;
+  my $output_filename = shift;
+  my $document_name = shift;
 
   # Ensure that the document has pages
   return undef if (!defined($elements) or !@$elements);
@@ -627,20 +639,21 @@ sub _set_pages_files($$)
   if (!$self->get_conf('SPLIT')) {
     foreach my $element (@$elements) {
       if (!defined($element->{'filename'})) {
-        $element->{'filename'} = $self->{'output_filename'};
-        $element->{'out_filename'} = $self->{'output_file'};
+        $element->{'filename'} = $output_filename;
+        $element->{'out_filename'} = $output_file;
       }
     }
   } else {
     my $node_top;
     $node_top = $self->{'labels'}->{'Top'} if ($self->{'labels'});
   
-    my $top_node_filename = $self->_top_node_filename();
+    my $top_node_filename = $self->_top_node_filename($document_name);
     # first determine the top node file name.
     if ($node_top and defined($top_node_filename)) {
       my ($node_top_element) = $self->_get_element($node_top);
       die "BUG: No element for top node" if (!defined($node_top));
-      $self->_set_element_file($node_top_element, $top_node_filename);
+      $self->_set_element_file($node_top_element, $top_node_filename,
+                               $destination_directory);
     }
     my $file_nr = 0;
     my $previous_page;
@@ -664,7 +677,8 @@ sub _set_pages_files($$)
               $node_filename = $self->_node_filename($root_command->{'extra'});
             }
             $node_filename .= $extension;
-            $self->_set_element_file($file_element, $node_filename);
+            $self->_set_element_file($file_element, $node_filename,
+                                     $destination_directory);
             last;
           }
         }
@@ -674,21 +688,25 @@ sub _set_pages_files($$)
           if ($command) {
             if ($command->{'cmdname'} eq 'top' and !$node_top
                 and defined($top_node_filename)) {
-              $self->_set_element_file($file_element, $top_node_filename);
+              $self->_set_element_file($file_element, $top_node_filename,
+                                       $destination_directory);
             } else {
               my ($normalized_name, $filename) 
                  = $self->_sectioning_command_normalized_filename($command);
-              $self->_set_element_file($file_element, $filename)
+              $self->_set_element_file($file_element, $filename,
+                                       $destination_directory);
             }
           } else {
             # when everything else has failed
             if ($file_nr == 0 and !$node_top 
                 and defined($top_node_filename)) {
-              $self->_set_element_file($file_element, $top_node_filename);
+              $self->_set_element_file($file_element, $top_node_filename,
+                                       $destination_directory);
             } else {
-              my $filename = $self->{'document_name'} . "_$file_nr";
+              my $filename = $document_name . "_$file_nr";
               $filename .= $extension;
-              $self->_set_element_file($element, $filename);
+              $self->_set_element_file($element, $filename,
+                                       $destination_directory);
             }
             $file_nr++;
           }
@@ -708,6 +726,9 @@ sub _set_pages_files($$)
   }
 }
 
+# In general, converters override this method, but simple
+# converters can use it.  It is used for the plaintext
+# output format.
 sub output($$)
 {
   my $self = shift;
@@ -730,8 +751,11 @@ sub output($$)
     $self->set_conf('NODE_FILES', 1);
   }
 
-  $self->_set_outfile();
-  return undef unless $self->_create_destination_directory();
+  my ($output_file, $destination_directory, $output_filename,
+                  $document_name) = $self->determine_files_and_directory();
+  my ($succeeded, $created_directory)
+    = $self->create_destination_directory($destination_directory);
+  return undef unless $succeeded;
 
   if ($self->get_conf('USE_NODES')) {
     $elements = Texinfo::Structuring::split_by_node($root);
@@ -742,8 +766,9 @@ sub output($$)
   Texinfo::Structuring::split_pages($elements, $self->get_conf('SPLIT'));
 
   # determine file names associated with the different pages
-  if ($self->{'output_file'} ne '') {
-    $self->_set_pages_files($elements);
+  if ($output_file ne '') {
+    $self->_set_pages_files($elements, $output_file, $destination_directory,
+                            $output_filename, $document_name);
   }
 
   #print STDERR "$elements $elements->[0]->{'filename'}\n";
@@ -754,16 +779,14 @@ sub output($$)
   if (!$elements or !defined($elements->[0]->{'filename'})) {
     # no page
     my $outfile;
-    if ($self->{'output_file'} ne '') {
+    if ($output_file ne '') {
       if ($self->get_conf('SPLIT')) {
-        $outfile = $self->_top_node_filename();
-        if (defined($self->{'destination_directory'}) 
-            and $self->{'destination_directory'} ne '') {
-          $outfile = File::Spec->catfile($self->{'destination_directory'}, 
-                                         $outfile);
+        $outfile = $self->_top_node_filename($document_name);
+        if (defined($created_directory) and $created_directory ne '') {
+          $outfile = File::Spec->catfile($created_directory, $outfile);
         }
       } else {
-        $outfile = $self->{'output_file'};
+        $outfile = $output_file;
       }
       print STDERR "DO No pages, output in $outfile\n"
         if ($self->get_conf('DEBUG'));
@@ -798,7 +821,7 @@ sub output($$)
                                       $outfile, $!));
       }
     }
-    return $output if ($self->{'output_file'} eq '');
+    return $output if ($output_file eq '');
   } else {
     # output with pages
     print STDERR "DO Elements with filenames\n"
@@ -894,37 +917,39 @@ if (0) {
   );
 }
 
-sub _create_destination_directory($)
+sub create_destination_directory($$)
 {
   my $self = shift;
-  if (defined($self->{'destination_directory'})
-      and ! -d $self->{'destination_directory'}) {
-    if (!mkdir($self->{'destination_directory'}, oct(755))) {
+  my $destination_directory = shift;
+
+  if (defined($destination_directory)
+      and ! -d $destination_directory) {
+    if (!mkdir($destination_directory, oct(755))) {
       if ($self->get_conf('SPLIT') 
-          and $self->get_conf('EXTENSION') 
+          and $self->get_conf('EXTENSION')
           and $self->get_conf('EXTENSION') ne '') {
         my ($volume, $directories, $file) 
-           = File::Spec->splitpath($self->{'destination_directory'}, 1);
+           = File::Spec->splitpath($destination_directory, 1);
         my $new_directory = File::Spec->catpath($volume, 
                  $directories . '.' . $self->get_conf('EXTENSION'), $file);
         if (! -d $new_directory) {
           if (!mkdir($new_directory, oct(755))) {
             $self->document_error($self, sprintf(__(
               "could not create directories `%s' or `%s': %s"), 
-              $self->{'destination_directory'}, $new_directory, $!));
-            return undef;
+              $destination_directory, $new_directory, $!));
+            return (0, $destination_directory);
           }
         }
-        $self->{'destination_directory'} = $new_directory;
+        $destination_directory = $new_directory;
       } else {
         $self->document_error($self, sprintf(__(
              "could not create directory `%s': %s"), 
-             $self->{'destination_directory'}, $!));
-        return undef;
+             $destination_directory, $!));
+        return (0, $destination_directory);
       }
     }
   }
-  return 1;
+  return (1, $destination_directory);
 }
 
 sub txt_image_text($$$)
@@ -1172,33 +1197,48 @@ sub _level_corrected_section($$)
   return $command;
 }
 
-# generic output method
+# generic output method, not used anywhere.
+# FIXME remove?
 sub output_no_split($$)
 {
   my $self = shift;
   my $root = shift;
 
-  $self->_set_outfile();
-  return undef unless $self->_create_destination_directory();
+  my ($output_file, $destination_directory) = 
$self->determine_files_and_directory();
+  my ($succeeded, $created_directory)
+    = $self->create_destination_directory($destination_directory);
+  return undef unless $succeeded;
   
   my $fh;
-  if (! $self->{'output_file'} eq '') {
+  if (! $output_file eq '') {
     $fh = Texinfo::Common::output_files_open_out(
                              $self->output_files_information(), $self,
-                                     $self->{'output_file'});
+                                     $output_file);
     if (!$fh) {
       $self->document_error($self,
                sprintf(__("could not open %s for writing: %s"),
-                                    $self->{'output_file'}, $!));
+                                    $output_file, $!));
       return undef;
     }
   }
 
+  my $result = '';
   if ($self->get_conf('USE_NODES')) {
-    return $self->convert_document_nodes($root, $fh);
+    $result .= $self->convert_document_nodes($root, $fh);
   } else {
-    return $self->convert_document_sections($root, $fh);
+    $result .= $self->convert_document_sections($root, $fh);
   }
+
+  if ($fh and $output_file ne '-') {
+    Texinfo::Common::output_files_register_closed(
+                  $self->output_files_information(), $output_file);
+    if (!close ($fh)) {
+      $self->document_error($self,
+            sprintf(__("error on closing %s: %s"),
+                                    $output_file, $!));
+    }
+  }
+  return $result;
 }
 
 # output fo $fh if defined, otherwise return the text.
@@ -1756,21 +1796,12 @@ see L<Texinfo::Convert::Utils>.
 
 =over
 
-=item $converter->get_conf($option_string)
-
-Returns the value of the Texinfo configuration option I<$option_string>.
-
-=item $converter->set_conf($option_string, $value)
-
-Set the Texinfo configuration option I<$option_string> to I<$value> if
-not set as a converter option.
-
-=item $converter->force_conf($option_string, $value)
+=item $result = $converter->convert_accents($accent_command, \&format_accents, 
$in_upper_case)
 
-Set the Texinfo configuration option I<$option_string> to I<$value>.
-This should rarely be used, but the purpose of this method is to be able
-to revert a configuration that is always wrong for a given output
-format, like the splitting for example.
+I<$accent_command> is an accent command, which may have other accent
+commands nested.  The function returns the accents formatted either
+as encoded letters, or formatted using I<\&format_accents>.
+If I<$in_upper_case> is set, the result should be uppercased.
 
 =item $result = $converter->convert_document_sections($root, $file_handler)
 
@@ -1779,12 +1810,32 @@ calls C<convert_tree> on the elements.  If the optional 
I<$file_handler>
 is given in argument, the result are output in I<$file_handler>, otherwise
 the resulting string is returned.
 
-=item $result = $converter->convert_accents($accent_command, \&format_accents, 
$in_upper_case)
-
-I<$accent_command> is an accent command, which may have other accent
-commands nested.  The function returns the accents formatted either
-as encoded letters, or formatted using I<\&format_accents>.
-If I<$in_upper_case> is set, the result should be uppercased.
+=item ($succeeded, $created_directory) = 
$converter->create_destination_directory($destination_directory)
+
+Create destination directory.  I<$succeeded> is true if the creation
+was successful or uneeded, false otherwise.  I<$created_directory>
+is the directory actually created, which can be different from
+C<$destination_directory> if C<$destination_directory> already
+exists as a file, output is split and there is an extension.
+
+=item ($output_file, $destination_directory, $output_filename, $document_name, 
$input_basefile) = $converter->determine_files_and_directory()
+
+Determine output file and directory, as well as names related to files.  The
+result depends on the presence of C<@setfilename>, on the Texinfo input file
+name, and on customization options such as OUTPUT, SUBDIR or SPLIT, as 
described
+in the Texinfo manual.
+
+C<$output_file> is mainly relevant when not split and should be used as the
+output file name.  In general, if not split and C<$output_file> is an empty
+string, it means that text should be returned by the converter instead of being
+written to an output file.  This is used in the test suite.
+C<$destination_directory> is either the directory C<$output_file> is in, or if
+split, the directory where the files should be created.  C<$output_filename>
+is, in general, the file name portion of C<$output_file> (without directory)
+but can also be set based on C<@setfilename>, in particular when
+C<$output_file> is an empty string. C<$document_name> is C<$output_filename>
+without extension.  C<$input_basefile> is based on the input texinfo file name,
+with the file name portion only (without directory).
 
 =item ($caption, $prepended) = $converter->float_name_caption ($float)
 
@@ -1799,6 +1850,22 @@ I<$float> is a texinfo tree C<@float> element.  This 
function
 returns the type and number of the float as a texinfo tree with
 translations.
 
+=item $converter->force_conf($option_string, $value)
+
+Set the Texinfo configuration option I<$option_string> to I<$value>.
+This should rarely be used, but the purpose of this method is to be able
+to revert a configuration that is always wrong for a given output
+format, like the splitting for example.
+
+=item $converter->get_conf($option_string)
+
+Returns the value of the Texinfo configuration option I<$option_string>.
+
+=item $converter->set_conf($option_string, $value)
+
+Set the Texinfo configuration option I<$option_string> to I<$value> if
+not set as a converter option.
+
 =back
 
 Other C<Texinfo::Convert::Converter> methods target conversion to XML:
diff --git a/tp/Texinfo/Convert/DocBook.pm b/tp/Texinfo/Convert/DocBook.pm
index cd39ab4..aad124e 100644
--- a/tp/Texinfo/Convert/DocBook.pm
+++ b/tp/Texinfo/Convert/DocBook.pm
@@ -302,18 +302,21 @@ sub output($$)
   my $self = shift;
   my $root = shift;
 
-  $self->_set_outfile();
-  return undef unless $self->_create_destination_directory();
+  my ($output_file, $destination_directory, $output_filename)
+    = $self->determine_files_and_directory();
+  my ($succeeded, $created_directory)
+    = $self->create_destination_directory($destination_directory);
+  return undef unless $succeeded;
 
   my $fh;
-  if (! $self->{'output_file'} eq '') {
+  if (! $output_file eq '') {
     $fh = Texinfo::Common::output_files_open_out(
                              $self->output_files_information(), $self,
-                             $self->{'output_file'});
+                             $output_file);
     if (!$fh) {
       $self->document_error($self,
            sprintf(__("could not open %s for writing: %s"),
-                                    $self->{'output_file'}, $!));
+                                    $output_file, $!));
       return undef;
     }
   }
@@ -325,8 +328,7 @@ sub output($$)
   }
 
   my $id;
-  if ($self->{'output_file'} ne '') {
-    my $output_filename = $self->{'output_filename'};
+  if ($output_file ne '') {
     $id = " id=\"".$self->xml_protect_text($output_filename)."\"";
   } else {
     $id = '';
@@ -351,13 +353,13 @@ sub output($$)
   $result .= $self->_output_text($header, $fh);
   $result .= $self->convert_document_sections($root, $fh);
   $result .= $self->_output_text("</book>\n", $fh);
-  if ($fh and $self->{'output_file'} ne '-') {
+  if ($fh and $output_file ne '-') {
     Texinfo::Common::output_files_register_closed(
-                  $self->output_files_information(), $self->{'output_file'});
+                  $self->output_files_information(), $output_file);
     if (!close ($fh)) {
       $self->document_error($self,
             sprintf(__("error on closing %s: %s"),
-                                    $self->{'output_file'}, $!));
+                                    $output_file, $!));
     }
   }
   return $result;
diff --git a/tp/Texinfo/Convert/HTML.pm b/tp/Texinfo/Convert/HTML.pm
index 49d7c62..7b917fd 100644
--- a/tp/Texinfo/Convert/HTML.pm
+++ b/tp/Texinfo/Convert/HTML.pm
@@ -5703,11 +5703,15 @@ sub _get_element($$;$)
   }
 }
 
-sub _set_pages_files($$)
+sub _set_html_pages_files($$$$$$$$)
 {
   my $self = shift;
   my $elements = shift;
   my $special_elements = shift;
+  my $output_file = shift;
+  my $destination_directory = shift;
+  my $output_filename = shift;
+  my $document_name = shift;
 
   # Ensure that the document has pages
   return undef if (!defined($elements) or !@$elements);
@@ -5720,22 +5724,21 @@ sub _set_pages_files($$)
   if (!$self->get_conf('SPLIT')) {
     foreach my $element (@$elements) {
       if (!defined($element->{'filename'})) {
-        $element->{'filename'} = $self->{'output_filename'};
-        $element->{'out_filename'} = $self->{'output_file'};
+        $element->{'filename'} = $output_filename;
+        $element->{'out_filename'} = $output_file;
       }
     }
   } else {
     my $node_top;
-    #my $section_top;
     $node_top = $self->{'labels'}->{'Top'} if ($self->{'labels'});
-    #$section_top = $self->{'extra'}->{'top'} if ($self->{'extra'});
   
-    my $top_node_filename = $self->_top_node_filename();
+    my $top_node_filename = $self->_top_node_filename($document_name);
     # first determine the top node file name.
     if ($node_top and defined($top_node_filename)) {
       my ($node_top_element) = $self->_get_element($node_top);
       die "BUG: No element for top node" if (!defined($node_top));
-      $self->_set_element_file($node_top_element, $top_node_filename);
+      $self->_set_element_file($node_top_element, $top_node_filename,
+                               $destination_directory);
     }
     my $file_nr = 0;
     my $previous_page;
@@ -5768,7 +5771,8 @@ sub _set_pages_files($$)
               $node_filename 
                 = $self->{'targets'}->{$root_command}->{'node_filename'};
             }
-            $self->_set_element_file($file_element, $node_filename);
+            $self->_set_element_file($file_element, $node_filename,
+                                     $destination_directory);
             last;
           }
         }
@@ -5778,20 +5782,24 @@ sub _set_pages_files($$)
           if ($command) {
             if ($command->{'cmdname'} eq 'top' and !$node_top
                 and defined($top_node_filename)) {
-              $self->_set_element_file($file_element, $top_node_filename);
+              $self->_set_element_file($file_element, $top_node_filename,
+                                       $destination_directory);
             } else {
               $self->_set_element_file($file_element,
-                 $self->{'targets'}->{$command}->{'section_filename'});
+                 $self->{'targets'}->{$command}->{'section_filename'},
+                                       $destination_directory);
             }
           } else {
             # when everything else has failed
             if ($file_nr == 0 and !$node_top 
                 and defined($top_node_filename)) {
-              $self->_set_element_file($file_element, $top_node_filename);
+              $self->_set_element_file($file_element, $top_node_filename,
+                                       $destination_directory);
             } else {
-              my $filename = $self->{'document_name'} . "_$file_nr";
+              my $filename = $document_name . "_$file_nr";
               $filename .= $extension;
-              $self->_set_element_file($element, $filename);
+              $self->_set_element_file($element, $filename,
+                                       $destination_directory);
             }
             $file_nr++;
           }
@@ -5810,7 +5818,8 @@ sub _set_pages_files($$)
       # may be determined with $self->element_is_top($element);
       my $filename = &$Texinfo::Config::element_file_name($self, $element, 
                                                           
$element->{'filename'});
-      $self->_set_element_file($element, $filename) if (defined($filename));
+      $self->_set_element_file($element, $filename, $destination_directory)
+         if (defined($filename));
     }
     $self->{'file_counters'}->{$element->{'filename'}}++;
     print STDERR "Page $element 
".Texinfo::Structuring::_print_element_command_texi($element).": 
$element->{'filename'}($self->{'file_counters'}->{$element->{'filename'}})\n"
@@ -5822,7 +5831,7 @@ sub _set_pages_files($$)
       my $filename 
        = $self->{'targets'}->{$element}->{'misc_filename'};
       if (defined($filename)) {
-        $self->_set_element_file($element, $filename);
+        $self->_set_element_file($element, $filename, $destination_directory);
         $self->{'file_counters'}->{$element->{'filename'}}++;
         print STDERR "Special page $element: 
$element->{'filename'}($self->{'file_counters'}->{$element->{'filename'}})\n"
           if ($self->get_conf('DEBUG'));
@@ -5840,10 +5849,12 @@ my @contents_elements_options = grep 
{Texinfo::Common::valid_option($_)}
 # $ROOT is a parsed Texinfo tree.  Return a list of the "elements" we need to
 # output in the HTML file(s).  Each "element" is what can go in one HTML file,
 # such as the content between @node lines in the Texinfo source.
-sub _prepare_elements($$)
+sub _prepare_elements($$$$)
 {
   my $self = shift;
   my $root = shift;
+  my $destination_directory = shift;
+  my $document_name = shift;
 
   my $elements;
 
@@ -5870,7 +5881,8 @@ sub _prepare_elements($$)
   # Do that before the other elements, to be sure that special page ids
   # are registered before elements id are.
   my $special_elements 
-    = $self->_prepare_special_elements($elements);
+    = $self->_prepare_special_elements($elements, $destination_directory,
+                                       $document_name);
   $self->set_global_document_commands(0, \@conf_for_special_elements);
 
   $self->{'special_elements'} = $special_elements 
@@ -5890,10 +5902,12 @@ sub _prepare_elements($$)
   return ($elements, $special_elements);
 }
 
-sub _prepare_special_elements($$)
+sub _prepare_special_elements($$$$)
 {
   my $self = shift;
   my $elements = shift;
+  my $destination_directory = shift;
+  my $document_name = shift;
 
   my %do_special;
   # FIXME let the user decide how @*contents are treated?
@@ -5940,7 +5954,7 @@ sub _prepare_special_elements($$)
     my $target = $self->{'misc_elements_targets'}->{$type};
     my $default_filename;
     if ($self->get_conf('SPLIT') or !$self->get_conf('MONOLITHIC')) {
-      $default_filename = $self->{'document_name'}.
+      $default_filename = $document_name.
         $self->{'misc_pages_file_string'}->{$type};
       $default_filename .= '.'.$extension if (defined($extension));
     } else {
@@ -5967,7 +5981,7 @@ sub _prepare_special_elements($$)
     if ($self->get_conf('SPLIT') or !$self->get_conf('MONOLITHIC')
         or (defined($filename) ne defined($default_filename))
         or (defined($filename) and $filename ne $default_filename)) {
-      $self->_set_element_file($element, $filename);
+      $self->_set_element_file($element, $filename, $destination_directory);
       print STDERR "NEW page for $type ($filename)\n" if 
($self->get_conf('DEBUG'));
     }
     $self->{'targets'}->{$element} = {'target' => $target,
@@ -5978,7 +5992,7 @@ sub _prepare_special_elements($$)
   if ($self->get_conf('FRAMES')) {
     foreach my $type (keys(%{$self->{'frame_pages_file_string'}})) {
       my $default_filename;
-      $default_filename = $self->{'document_name'}.
+      $default_filename = $document_name.
         $self->{'frame_pages_file_string'}->{$type};
       $default_filename .= '.'.$extension if (defined($extension));
 
@@ -7062,6 +7076,7 @@ EOT
 
 sub _do_jslicenses_file {
   my $self = shift;
+  my $destination_directory = shift;
 
   my $setting = $self->get_conf('JS_WEBLABELS');
   my $path = $self->get_conf('JS_WEBLABELS_FILE');
@@ -7095,7 +7110,7 @@ sub _do_jslicenses_file {
 __("cannot use absolute path or URL `%s' for JS_WEBLABELS_FILE when generating 
web labels file"), $path));
     return;
   }
-  my $license_file = File::Spec->catdir($self->{'destination_directory'},
+  my $license_file = File::Spec->catdir($destination_directory,
                                         $path);
   my $fh = Texinfo::Common::output_files_open_out(
                  $self->output_files_information(), $self, $license_file);
@@ -7115,15 +7130,15 @@ __("cannot use absolute path or URL `%s' for 
JS_WEBLABELS_FILE when generating w
   }
 }
 
-sub _default_format_frame_files($)
+sub _default_format_frame_files($$)
 {
   my $self = shift;
+  my $destination_directory = shift;
 
   my $frame_file = $self->{'frame_pages_filenames'}->{'Frame'};
   my $frame_outfile;
-  if (defined($self->{'destination_directory'}) 
-      and $self->{'destination_directory'} ne '') {
-    $frame_outfile = File::Spec->catfile($self->{'destination_directory'}, 
+  if (defined($destination_directory) and $destination_directory ne '') {
+    $frame_outfile = File::Spec->catfile($destination_directory,
                                          $frame_file);
   } else {
     $frame_outfile = $frame_file;
@@ -7131,9 +7146,8 @@ sub _default_format_frame_files($)
   
   my $toc_frame_file = $self->{'frame_pages_filenames'}->{'Toc_Frame'};
   my $toc_frame_outfile;
-  if (defined($self->{'destination_directory'}) 
-      and $self->{'destination_directory'} ne '') {
-    $toc_frame_outfile = File::Spec->catfile($self->{'destination_directory'}, 
+  if (defined($destination_directory) and $destination_directory ne '') {
+    $toc_frame_outfile = File::Spec->catfile($destination_directory,
                                              $toc_frame_file);
   } else {
     $toc_frame_outfile = $toc_frame_file;
@@ -7224,8 +7238,13 @@ sub convert($$)
   my $result = '';
 
   # This should return undef if called on a tree without node or sections.
+  #
+  # FIXME the document_name and destination_directory arguments are undef.
+  # If a converter is reused, it could be possible to set before and reuse
+  # here something like $self->{'document_name'}
+  # but it is unclear if it is correct or not.
   my ($elements, $special_elements) 
-    = $self->_prepare_elements($root);
+    = $self->_prepare_elements($root, undef, undef);
 
   $self->_prepare_index_entries();
   $self->_prepare_footnotes();
@@ -7366,19 +7385,29 @@ sub output($$)
 
   # this sets OUTFILE, to be used if not split, but also
   # 'destination_directory' and 'output_filename' that are useful when split.
-  $self->_set_outfile();
-  return undef unless $self->_create_destination_directory();
+  my ($output_file, $destination_directory, $output_filename,
+              $document_name) = $self->determine_files_and_directory();
+  my ($succeeded, $created_directory)
+    = $self->create_destination_directory($destination_directory);
+  return undef unless $succeeded;
+
+  # set for init files
+  # FIXME use an api
+  $self->{'document_name'} = $document_name;
+  $self->{'destination_directory'} = $created_directory;
 
   # Get the list of "elements" to be processed, i.e. nodes or sections.
   # This should return undef if called on a tree without node or sections.
-  my ($elements, $special_elements) = $self->_prepare_elements($root);
+  my ($elements, $special_elements)
+    = $self->_prepare_elements($root, $destination_directory, $document_name);
 
   Texinfo::Structuring::split_pages($elements, $self->get_conf('SPLIT'));
 
   # determine file names associated with the different pages, and setup
   # the counters for special element pages.
-  if ($self->{'output_file'} ne '') {
-    $self->_set_pages_files($elements, $special_elements);
+  if ($output_file ne '') {
+    $self->_set_html_pages_files($elements, $special_elements, $output_file,
+                  $destination_directory, $output_filename, $document_name);
   }
 
   $self->_prepare_contents_elements();
@@ -7513,7 +7542,7 @@ sub output($$)
   return undef unless($init_status);
 
   if ($self->get_conf('FRAMES')) {
-    my $status = &{$self->{'format_frame_files'}}($self);
+    my $status = &{$self->{'format_frame_files'}}($self, $created_directory);
     return undef if (!$status);
   }
 
@@ -7568,19 +7597,17 @@ sub output($$)
   if (!$elements or !defined($elements->[0]->{'filename'})) {
     # no page
     my $outfile;
-    if ($self->{'output_file'} ne '') {
+    if ($output_file ne '') {
       if ($self->get_conf('SPLIT')) {
-        $outfile = $self->_top_node_filename();
-        if (defined($self->{'destination_directory'}) 
-            and $self->{'destination_directory'} ne '') {
-          $outfile = File::Spec->catfile($self->{'destination_directory'}, 
-                                         $outfile);
+        $outfile = $self->_top_node_filename($document_name);
+        if (defined($created_directory) and $created_directory ne '') {
+          $outfile = File::Spec->catfile($created_directory, $outfile);
         }
       } else {
-        $outfile = $self->{'output_file'};
+        $outfile = $output_file;
       }
       $fh = Texinfo::Common::output_files_open_out(
-              $self->output_files_information(), $self,$outfile);
+              $self->output_files_information(), $self, $outfile);
       if (!$fh) {
         $self->document_error($self,
               sprintf(__("could not open %s for writing: %s"),
@@ -7588,7 +7615,7 @@ sub output($$)
         return undef;
       }
     }
-    $self->{'current_filename'} = $self->{'output_filename'};
+    $self->{'current_filename'} = $output_filename;
 
     my $body = '';
     if ($elements and @$elements) {
@@ -7601,8 +7628,7 @@ sub output($$)
       $body .= $self->_convert($root);
     }
 
-    my $header = &{$self->{'format_begin_file'}}($self, 
-                                           $self->{'output_filename'}, undef);
+    my $header = &{$self->{'format_begin_file'}}($self, $output_filename, 
undef);
     $output .= $self->_output_text($header, $fh);
     $output .= $self->_output_text($body, $fh);
     $output .= $self->_output_text(&{$self->{'format_end_file'}}($self), $fh);
@@ -7617,7 +7643,7 @@ sub output($$)
                                       $outfile, $!));
       }
     }
-    return $output if ($self->{'output_file'} eq '');
+    return $output if ($output_file eq '');
   } else {
     # output with pages
     print STDERR "DO Elements with filenames\n"
@@ -7691,7 +7717,7 @@ sub output($$)
       }
     }
     if ($self->get_conf('INFO_JS_DIR')) {
-      my $jsdir = File::Spec->catdir($self->{'destination_directory'}, 
+      my $jsdir = File::Spec->catdir($created_directory,
                                      $self->get_conf('INFO_JS_DIR'));
       if (!-d $jsdir) {
         if (-f $jsdir) {
@@ -7723,7 +7749,7 @@ sub output($$)
   }
 
   if (%{$self->{'jslicenses'}}) {
-    $self->_do_jslicenses_file();
+    $self->_do_jslicenses_file($created_directory);
   }
 
   my $finish_status = $self->run_stage_handlers($root, 'finish');
@@ -7736,7 +7762,7 @@ sub output($$)
   # do node redirection pages
   $self->{'current_filename'} = undef;
   if ($self->get_conf('NODE_FILES') 
-      and $self->{'labels'} and $self->{'output_file'} ne '') {
+      and $self->{'labels'} and $output_file ne '') {
     foreach my $label (sort(keys (%{$self->{'labels'}}))) {
       my $node = $self->{'labels'}->{$label};
       my $target = $self->_get_target($node);
@@ -7759,9 +7785,8 @@ sub output($$)
         my $redirection_page 
           = &{$self->{'format_node_redirection_page'}}($self, $node);
         my $out_filename;
-        if (defined($self->{'destination_directory'}) 
-            and $self->{'destination_directory'} ne '') {
-          $out_filename = 
File::Spec->catfile($self->{'destination_directory'}, 
+        if (defined($created_directory) and $created_directory ne '') {
+          $out_filename = File::Spec->catfile($created_directory,
                                               $node_filename);
         } else {
           $out_filename = $node_filename;
diff --git a/tp/Texinfo/Convert/IXIN.pm b/tp/Texinfo/Convert/IXIN.pm
index 25ce675..1987d66 100644
--- a/tp/Texinfo/Convert/IXIN.pm
+++ b/tp/Texinfo/Convert/IXIN.pm
@@ -267,18 +267,20 @@ sub output_ixin($$)
   my $self = shift;
   my $root = shift;
 
-  $self->_set_outfile();
-  return undef unless $self->_create_destination_directory();
+  my ($outfile, $destination_directory) = 
$self->determine_files_and_directory();
+  my ($succeeded, $created_directory)
+    = $self->create_destination_directory($destination_directory);
+  return undef unless $succeeded;
 
   my $fh;
-  if (! $self->{'output_file'} eq '') {
+  if (! $output_file eq '') {
     $fh = Texinfo::Common::output_files_open_out(
                              $self->output_files_information(), $self,
-                             $self->{'output_file'});
+                             $output_file);
     if (!$fh) {
       $self->document_error($self,
                 sprintf(__("could not open %s for writing: %s"),
-                                    $self->{'output_file'}, $!));
+                                    $output_file, $!));
       return undef;
     }
   }
@@ -292,9 +294,9 @@ sub output_ixin($$)
   $result .= $self->ixin_open_element('xid');
 
   my $output_file = $self->ixin_none_element('filename');
-  if ($self->{'output_file'} ne '') {
+  if ($output_file ne '') {
     $result .= $self->ixin_list_element('filename', 
-                           ['name', $self->{'output_file'}]);
+                           ['name', $output_file]);
   }
   my $lang = $self->get_conf('documentlanguage');
   #my $lang_code = $lang;
@@ -901,13 +903,13 @@ sub output_ixin($$)
   $output .= $self->_output_text($document_output, $fh);
   $output .= $self->_output_text($blobs, $fh);
 
-  if ($fh and $self->{'output_file'} ne '-') {
+  if ($fh and $output_file ne '-') {
     Texinfo::Common::output_files_register_closed(
-                  $self->output_files_information(), $self->{'output_file'});
+                  $self->output_files_information(), $output_file);
     if (!close ($fh)) {
       $self->document_error($self,
                 sprintf(__("error on closing %s: %s"),
-                                    $self->{'output_file'}, $!));
+                                    $output_file, $!));
     }
   }
   return $output;
diff --git a/tp/Texinfo/Convert/Info.pm b/tp/Texinfo/Convert/Info.pm
index 0c5fdd2..8b8237a 100644
--- a/tp/Texinfo/Convert/Info.pm
+++ b/tp/Texinfo/Convert/Info.pm
@@ -57,34 +57,41 @@ sub output($)
 
   my $result;
 
-  $self->_set_outfile();
-  $self->{'input_basename'} = $STDIN_DOCU_NAME if ($self->{'input_basename'} 
eq '-');
+  my ($output_file, $destination_directory, $output_filename,
+     $document_name, $input_basefile) = $self->determine_files_and_directory();
+  my ($succeeded, $created_directory)
+    = $self->create_destination_directory($destination_directory);
+  return undef unless $succeeded;
+
+  # for format_node
+  $self->{'output_filename'} = $output_filename;
+
+  $input_basefile = $STDIN_DOCU_NAME if ($input_basefile eq '-');
 
   # no splitting when writing to the null device or to stdout
-  if ($Texinfo::Common::null_device_file{$self->{'output_file'}} 
-       or $self->{'output_file'} eq '-') {
+  if ($Texinfo::Common::null_device_file{$output_file}
+       or $output_file eq '-') {
     $self->force_conf('SPLIT_SIZE', undef);
   }
 
   push @{$self->{'count_context'}}, {'lines' => 0, 'bytes' => 0,
                                      'locations' => []};
-  my $header = $self->_info_header();
+  my $header = $self->_info_header($input_basefile, $output_filename);
   # header + text between setfilename and first node
   my $complete_header = $header;
 
   pop @{$self->{'count_context'}};
-  return undef unless $self->_create_destination_directory();
 
   my $header_bytes = Texinfo::Convert::Plaintext::count_bytes($self, $header);
   my $complete_header_bytes = $header_bytes;
   my $elements = Texinfo::Structuring::split_by_node($root);
 
   my $fh;
-  if (! $self->{'output_file'} eq '') {
+  if (! $output_file eq '') {
     if ($self->get_conf('VERBOSE')) {
-      print STDERR "Output file $self->{'output_file'}\n";
+      print STDERR "Output file $output_file\n";
     }
-    $fh = _open_info_file($self, $self->{'output_file'});
+    $fh = _open_info_file($self, $output_file);
     if (!$fh) {
       return undef;
     }
@@ -149,41 +156,40 @@ sub output($)
         }
         if ($out_file_nr == 1) {
           Texinfo::Common::output_files_register_closed(
-             $self->output_files_information(), $self->{'output_file'});
+             $self->output_files_information(), $output_file);
           if (defined($close_error)) {
             $self->document_error($self,
                   sprintf(__("error on closing %s: %s"),
-                                  $self->{'output_file'}, $close_error));
+                                  $output_file, $close_error));
             return undef;
           }
           if ($self->get_conf('VERBOSE')) {
             print STDERR "Renaming first output file as ".
-                  $self->{'output_file'}.'-'.$out_file_nr."\n";
+                  $output_file.'-'.$out_file_nr."\n";
           }
-          unless (rename($self->{'output_file'}, 
-                         $self->{'output_file'}.'-'.$out_file_nr)) {
+          unless (rename($output_file, $output_file.'-'.$out_file_nr)) {
             $self->document_error($self,
                   sprintf(__("rename %s failed: %s"),
-                                         $self->{'output_file'}, $!));
+                                         $output_file, $!));
             return undef;
           }
           # remove the main file from opened files since it was renamed
           # and add the file with a number.
-          @{$self->{'opened_files'}} = grep {$_ ne $self->{'output_file'}}
+          @{$self->{'opened_files'}} = grep {$_ ne $output_file}
                @{$self->{'opened_files'}};
           push @{$self->{'opened_files'}}, 
-                   $self->{'output_file'}.'-'.$out_file_nr;
-          push @indirect_files, [$self->{'output_filename'}.'-'.$out_file_nr,
+                   $output_file.'-'.$out_file_nr;
+          push @indirect_files, [$output_filename.'-'.$out_file_nr,
                                  $complete_header_bytes];
           #print STDERR join(' --> ', @{$indirect_files[-1]}) ."\n";
         } else {
           Texinfo::Common::output_files_register_closed(
                            $self->output_files_information(),
-                           $self->{'output_file'}.'-'.$out_file_nr);
+                           $output_file.'-'.$out_file_nr);
           if (defined($close_error)) {
             $self->document_error($self,
                   sprintf(__("error on closing %s: %s"),
-                                  $self->{'output_file'}.'-'.$out_file_nr, 
+                                  $output_file.'-'.$out_file_nr,
                                   $close_error));
             return undef;
           }
@@ -191,16 +197,16 @@ sub output($)
         $out_file_nr++;
         if ($self->get_conf('VERBOSE')) {
           print STDERR "New output file ".
-                $self->{'output_file'}.'-'.$out_file_nr."\n";
+                $output_file.'-'.$out_file_nr."\n";
         }
-        $fh = _open_info_file($self, $self->{'output_file'}.'-'.$out_file_nr); 
+        $fh = _open_info_file($self, $output_file.'-'.$out_file_nr);
         if (!$fh) {
           return undef;
         }
         print $fh $complete_header;
         $self->update_count_context();
         $self->{'count_context'}->[-1]->{'bytes'} += $complete_header_bytes;
-        push @indirect_files, [$self->{'output_filename'}.'-'.$out_file_nr,
+        push @indirect_files, [$output_filename.'-'.$out_file_nr,
                                $self->{'count_context'}->[-1]->{'bytes'}];
         #print STDERR join(' --> ', @{$indirect_files[-1]}) ."\n";
       }
@@ -209,17 +215,17 @@ sub output($)
   my $tag_text = '';
   if ($out_file_nr > 1) {
     Texinfo::Common::output_files_register_closed(
-      $self->output_files_information(), 
$self->{'output_file'}.'-'.$out_file_nr);
+      $self->output_files_information(), $output_file.'-'.$out_file_nr);
     if (!close ($fh)) {
       $self->document_error($self,
                sprintf(__("error on closing %s: %s"),
-                            $self->{'output_file'}.'-'.$out_file_nr, $!));
+                            $output_file.'-'.$out_file_nr, $!));
       return undef;
     }
     if ($self->get_conf('VERBOSE')) {
-      print STDERR "Outputing the split manual file $self->{'output_file'}\n";
+      print STDERR "Outputing the split manual file $output_file\n";
     }
-    $fh = _open_info_file($self, $self->{'output_file'});
+    $fh = _open_info_file($self, $output_file);
     if (!$fh) {
       return undef;
     }
@@ -272,13 +278,13 @@ sub output($)
     # 'Filehandle STDOUT reopened as FH only for input' if there are files
     # reopened after closing STDOUT.  So closing STDOUT is handled by the
     # caller.
-    unless ($self->{'output_file'} eq '-') {
+    unless ($output_file eq '-') {
       Texinfo::Common::output_files_register_closed(
-         $self->output_files_information(), $self->{'output_file'});
+         $self->output_files_information(), $output_file);
       if (!close ($fh)) {
         $self->document_error($self,
                   sprintf(__("error on closing %s: %s"),
-                              $self->{'output_file'}, $!));
+                              $output_file, $!));
       }
     }
   } else {
@@ -307,14 +313,16 @@ sub _open_info_file($$)
   return $fh;
 }
 
-sub _info_header($)
+sub _info_header($$$)
 {
   my $self = shift;
+  my $input_basefile = shift;
+  my $output_filename = shift;
 
   my $paragraph = Texinfo::Convert::Paragraph->new();
   my $result = add_text($paragraph, "This is ");
   # This ensures that spaces in file are kept.
-  $result .= add_next($paragraph, $self->{'output_filename'});
+  $result .= add_next($paragraph, $output_filename);
   my $program = $self->get_conf('PROGRAM');
   my $version = $self->get_conf('PACKAGE_VERSION');
   if (defined($program) and $program ne '') {
@@ -323,7 +331,7 @@ sub _info_header($)
   } else {
     $result .= add_text($paragraph, ", produced from ");
   }
-  $result .= add_next($paragraph, $self->{'input_basename'});
+  $result .= add_next($paragraph, $input_basefile);
   $result .= add_text($paragraph, '.');
   $result .= Texinfo::Convert::Paragraph::end($paragraph);
   $result .= "\n";
@@ -417,11 +425,11 @@ sub format_node($$)
     $self->{'first_node_done'} = 1;
   }
 
-  # May happen when only converting a fragment
-  my $output_filename = $self->{'output_filename'};
+  my $output_filename;
   if (defined($self->{'output_filename'})) {
     $output_filename = $self->{'output_filename'};
   } else {
+    # May happen when only converting a fragment
     $output_filename = '';
   }
 
@@ -508,7 +516,7 @@ sub format_image($$)
         # use the basename and not the file found.  It is agreed that it is
         # better, since in any case the files are moved.
         $image_file = $basefile.$extension;
-        last; 
+        last;
       }
     }
     my ($text, $width) = $self->txt_image_text($root, $basefile);
diff --git a/tp/Texinfo/Convert/LaTeX.pm b/tp/Texinfo/Convert/LaTeX.pm
index aa1bb66..37b86ce 100644
--- a/tp/Texinfo/Convert/LaTeX.pm
+++ b/tp/Texinfo/Convert/LaTeX.pm
@@ -865,18 +865,21 @@ sub output($$)
 {
   my ($self, $root) = @_;
 
-  $self->_set_outfile();
-  return undef unless $self->_create_destination_directory();
+  my ($output_file, $destination_directory, $output_filename)
+    = $self->determine_files_and_directory();
+  my ($succeeded, $created_directory)
+    = $self->create_destination_directory($destination_directory);
+  return undef unless $succeeded;
 
   my $fh;
-  if (! $self->{'output_file'} eq '') {
+  if (! $output_file eq '') {
     $fh = Texinfo::Common::output_files_open_out(
                              $self->output_files_information(), $self,
-                             $self->{'output_file'});
+                             $output_file);
     if (!$fh) {
       $self->document_error($self,
              sprintf(__("could not open %s for writing: %s"),
-                                    $self->{'output_file'}, $!));
+                                    $output_file, $!));
       return undef;
     }
   }
@@ -961,13 +964,13 @@ sub output($$)
   $result .= $self->_output_text($self->_latex_footer(), $fh);
 
   #print $result;
-  if ($fh and $self->{'output_file'} ne '-') {
+  if ($fh and $output_file ne '-') {
     Texinfo::Common::output_files_register_closed(
-                  $self->output_files_information(), $self->{'output_file'});
+                  $self->output_files_information(), $output_file);
     if (!close ($fh)) {
       $self->document_error($self,
                    sprintf(__("error on closing %s: %s"),
-                                    $self->{'output_file'}, $!));
+                                    $output_file, $!));
     }
   }
   return $result;
diff --git a/tp/Texinfo/Convert/TexinfoSXML.pm 
b/tp/Texinfo/Convert/TexinfoSXML.pm
index db06dbb..d40baf3 100644
--- a/tp/Texinfo/Convert/TexinfoSXML.pm
+++ b/tp/Texinfo/Convert/TexinfoSXML.pm
@@ -158,17 +158,20 @@ sub format_text($$)
 }
 
 # output format specific
-sub format_header($)
+sub format_header($$$)
 {
   my $self = shift;
+  my $output_file = shift;
+  my $output_filename = shift;
+
   my $header = '';
   my $encoding = '';
   if ($self->get_conf('OUTPUT_ENCODING_NAME')
       and $self->get_conf('OUTPUT_ENCODING_NAME') ne 'utf-8') {
     $encoding = $self->get_conf('OUTPUT_ENCODING_NAME');
   }
-  if ($self->{'output_file'} ne '') {
-    my $output_filename = $self->{'output_filename'};
+  if ($output_file ne '') {
+    my $output_filename = $output_filename;
   }
   return $header;
 }
diff --git a/tp/Texinfo/Convert/TexinfoXML.pm b/tp/Texinfo/Convert/TexinfoXML.pm
index 2a19434..5381eb4 100644
--- a/tp/Texinfo/Convert/TexinfoXML.pm
+++ b/tp/Texinfo/Convert/TexinfoXML.pm
@@ -247,9 +247,12 @@ sub format_text($$)
 }
 
 # output format specific
-sub format_header($)
+sub format_header($$$)
 {
   my $self = shift;
+  my $output_file = shift;
+  my $output_filename = shift;
+
   my $encoding = '';
   if ($self->get_conf('OUTPUT_ENCODING_NAME')
       and $self->get_conf('OUTPUT_ENCODING_NAME') ne 'utf-8') {
@@ -263,8 +266,7 @@ sub format_header($)
   my $header =  "<?xml version=\"1.0\"${encoding}?>".'
 <!DOCTYPE texinfo PUBLIC "-//GNU//DTD TexinfoML V'.$texinfo_dtd_version.'//EN" 
"http://www.gnu.org/software/texinfo/dtd/'.$texinfo_dtd_version.'/texinfo.dtd">
 '. $self->open_element('texinfo')."\n";
-  if ($self->{'output_file'} ne '') {
-    my $output_filename = $self->{'output_filename'};
+  if ($output_file ne '') {
     $header .= $self->open_element('filename',['file', $output_filename])
              .$self->close_element('filename')."\n";
   }
@@ -441,35 +443,40 @@ sub output($$)
   my $self = shift;
   my $root = shift;
 
-  $self->_set_outfile();
-  return undef unless $self->_create_destination_directory();
+  my ($output_file, $destination_directory, $output_filename)
+       = $self->determine_files_and_directory();
+  my ($succeeded, $created_directory)
+    = $self->create_destination_directory($destination_directory);
+  return undef unless $succeeded;
+
 
   my $fh;
-  if (! $self->{'output_file'} eq '') {
+  if (! $output_file eq '') {
     $fh = Texinfo::Common::output_files_open_out(
                              $self->output_files_information(), $self,
-                             $self->{'output_file'});
+                             $output_file);
     if (!$fh) {
       $self->document_error(sprintf(__("could not open %s for writing: %s"),
-                                    $self->{'output_file'}, $!));
+                                    $output_file, $!));
       return undef;
     }
   }
 
   my $result = '';
-  $result .= $self->_output_text($self->format_header(), $fh);
+  $result .= $self->_output_text(
+       $self->format_header($output_file, $output_filename), $fh);
   if ($self->get_conf('USE_NODES')) {
     $result .= $self->convert_document_nodes($root, $fh);
   } else {
     $result .= $self->convert_document_sections($root, $fh);
   }
   $result .= $self->_output_text($self->close_element('texinfo')."\n", $fh);
-  if ($fh and $self->{'output_file'} ne '-') {
+  if ($fh and $output_file ne '-') {
     Texinfo::Common::output_files_register_closed(
-                  $self->output_files_information(), $self->{'output_file'});
+                  $self->output_files_information(), $output_file);
     if (!close ($fh)) {
       $self->document_error(sprintf(__("error on closing %s: %s"),
-                                    $self->{'output_file'}, $!));
+                                    $output_file, $!));
     }
   }
 
diff --git a/tp/Texinfo/Convert/Text.pm b/tp/Texinfo/Convert/Text.pm
index 67929b3..909dd84 100644
--- a/tp/Texinfo/Convert/Text.pm
+++ b/tp/Texinfo/Convert/Text.pm
@@ -200,7 +200,7 @@ sub ascii_accents($$;$)
 
 # Same as ascii_accent, but with a converter as first argument to be consistent
 # with calling conventions of fallback accent formatting functions given
-# to convert_accents/encoded_accents
+# to Convert::Converter::convert_accents() or 
Convert::Unicode::encoded_accents()
 sub ascii_accent_fallback($$$)
 {
   my $converter = shift;
@@ -713,7 +713,6 @@ sub output($$)
     # This could happen if called on a piece of texinfo
     $input_basename = '';
   }
-  $self->{'input_basename'} = $input_basename;
   $input_basename = $STDIN_DOCU_NAME if ($input_basename eq '-');
   $input_basename =~ s/\.te?x(i|info)?$//;
 
diff --git a/tp/Texinfo/Structuring.pm b/tp/Texinfo/Structuring.pm
index 8c30264..dfce63c 100644
--- a/tp/Texinfo/Structuring.pm
+++ b/tp/Texinfo/Structuring.pm
@@ -1926,7 +1926,7 @@ described in details in L<Texinfo::Parser/index_entries>.
 Returns the texinfo tree corresponding to a block command named
 C<$command_name> with contents C<$content> and parent in tree C<$parent>.
 
-=item $new_menu new_complete_node_menu($node, $use_sections)
+=item $new_menu = new_complete_node_menu($node, $use_sections)
 
 Returns a texinfo tree menu for node C<$node>, pointing to the children
 of the node obtained with the sectioning structure.  If C<$use_sections>
diff --git a/tp/t/91morecoverage.t b/tp/t/91morecoverage.t
index e44b2bd..976174d 100644
--- a/tp/t/91morecoverage.t
+++ b/tp/t/91morecoverage.t
@@ -1,4 +1,3 @@
-# $Id: 02coverage.t 8055 2018-08-13 11:41:21Z gavin $
 use strict;
 
 use lib '.';



reply via email to

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