texinfo-commits
[Top][All Lists]
Advanced

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

branch master updated: * tp/Texinfo/Convert/HTML.pm (_html_set_pages_fil


From: Patrice Dumas
Subject: branch master updated: * tp/Texinfo/Convert/HTML.pm (_html_set_pages_files): call set_tree_unit_file only once per tree unit, gather file names and file paths in a hash.
Date: Mon, 10 Oct 2022 03:37:37 -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 e0d420bf10 * tp/Texinfo/Convert/HTML.pm (_html_set_pages_files): call 
set_tree_unit_file only once per tree unit, gather file names and file paths in 
a hash.
e0d420bf10 is described below

commit e0d420bf10d0b12fe057015b0395f876d5507f6e
Author: Patrice Dumas <pertusus@free.fr>
AuthorDate: Mon Oct 10 09:37:26 2022 +0200

    * tp/Texinfo/Convert/HTML.pm (_html_set_pages_files): call
    set_tree_unit_file only once per tree unit, gather file names and
    file paths in a hash.
    
    * tp/Texinfo/Convert/HTML.pm (tree_unit_file_name), tp/init/book.pm:
    allow to customize both the file name and the file path.
---
 ChangeLog                          |  9 ++++++
 doc/customization_api.texi         | 13 +++++---
 tp/TODO                            |  2 --
 tp/Texinfo/Convert/Converter.pm    |  5 ++-
 tp/Texinfo/Convert/HTML.pm         | 62 ++++++++++++++++++++------------------
 tp/init/book.pm                    | 11 +++++--
 tp/t/init/misc_file_collision.init |  7 +++--
 7 files changed, 65 insertions(+), 44 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index b186f1f531..7a4bf6ed0c 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2022-10-10  Patrice Dumas  <pertusus@free.fr>
+
+       * tp/Texinfo/Convert/HTML.pm (_html_set_pages_files): call
+       set_tree_unit_file only once per tree unit, gather file names and
+       file paths in a hash.
+
+       * tp/Texinfo/Convert/HTML.pm (tree_unit_file_name), tp/init/book.pm:
+       allow to customize both the file name and the file path.
+
 2022-10-09  Patrice Dumas  <pertusus@free.fr>
 
        * tp/Texinfo/Convert/HTML.pm (_html_set_pages_files)
diff --git a/doc/customization_api.texi b/doc/customization_api.texi
index b24eb237d7..ec134b0f23 100644
--- a/doc/customization_api.texi
+++ b/doc/customization_api.texi
@@ -1792,12 +1792,17 @@ customize the file names associated with each element 
unit, and the name of
 the file associated with the special elements (@pxref{Output Element
 Units}).
 
-@deftypefn {Function Reference} @var{$file} tree_unit_file_name 
(@var{$converter}, @
-                                      @var{\%unit_element}, @var{$file_name})
+@deftypefn {Function Reference} {(@var{$file}, @var{$path})} 
tree_unit_file_name (@var{$converter}, @
+                  @var{\%unit_element}, @var{$file_name}, @var{$file_path})
 @var{$converter} is a converter object.  @var{\%unit_element} is the Texinfo
 element corresponding to the unit element.  @var{$file_name} is the file
-name that has been already set.  The function should return the file name for
-the unit element (@var{$file}).
+name that has been already set.  @var{$file_path} is the file path that has
+been already set.  @var{$file_path} is @samp{undef} if the file is relative to
+the output directory, which is the case if the output is split.  The
+function should return the file name for the unit element, @var{$file}, and the
+file path for the unit element, @var{$path}, which should be @samp{undef} if
+the file path is to be constructed by putting @var{$file} in the destination
+directory.
 @end deftypefn
 
 In the user defined functions, the information that a unit element
diff --git a/tp/TODO b/tp/TODO
index fc1583294e..7b28791e14 100644
--- a/tp/TODO
+++ b/tp/TODO
@@ -14,8 +14,6 @@ check same keys for
 global_unique document_settable_unique_at_commands
 global document_settable_multiple_at_commands
 
-FIXME in set_tree_unit_file
-
 Add in_math (for /)?
 
 Bugs
diff --git a/tp/Texinfo/Convert/Converter.pm b/tp/Texinfo/Convert/Converter.pm
index 7b6dd700ea..5b486993bb 100644
--- a/tp/Texinfo/Convert/Converter.pm
+++ b/tp/Texinfo/Convert/Converter.pm
@@ -783,14 +783,13 @@ sub set_tree_unit_file($$$$;$)
     }
   }
   $tree_unit->{'structure'} = {} if (!($tree_unit->{'structure'}));
+  # This should never happen, set_tree_unit_file is called once per
+  # tree unit.
   if (exists($tree_unit->{'structure'}->{'unit_filename'})) {
-    # FIXME happens in navigation_test_misc_file_collision, to investigate
     if ($tree_unit->{'structure'}->{'unit_filename'} eq $filename) {
       print STDERR "set_tree_unit_file: already set: $filename\n"
-         #if (1);
          if ($self->get_conf('DEBUG'));
     } else {
-      # happens in HTML if the user changes the file names
       print STDERR  "set_tree_unit_file: unit_filename reset: "
         .$tree_unit->{'structure'}->{'unit_filename'}.", $filename\n"
            if ($self->get_conf('DEBUG'));
diff --git a/tp/Texinfo/Convert/HTML.pm b/tp/Texinfo/Convert/HTML.pm
index 4a31ea24fc..773cfef13f 100644
--- a/tp/Texinfo/Convert/HTML.pm
+++ b/tp/Texinfo/Convert/HTML.pm
@@ -7786,35 +7786,33 @@ sub _html_set_pages_files($$$$$$$$)
             if (defined($self->get_conf('EXTENSION'))
                 and $self->get_conf('EXTENSION') ne '');
 
+  my %unit_file_name_paths;
   if (!$self->get_conf('SPLIT')) {
     foreach my $tree_unit (@$tree_units) {
-      $self->set_tree_unit_file($tree_unit, $output_filename, undef,
-                                $output_file);
+      $unit_file_name_paths{$tree_unit} = [$output_filename, $output_file];
     }
   } else {
     my $node_top;
     $node_top = $self->{'labels'}->{'Top'} if ($self->{'labels'});
   
     my $top_node_filename = $self->top_node_filename($document_name);
+    my $node_top_tree_unit;
     # first determine the top node file name.
     if ($node_top and defined($top_node_filename)) {
       my ($node_top_tree_unit) = $self->_html_get_tree_root_element($node_top);
-      die "BUG: No element for top node" if (!defined($node_top));
-      $self->set_tree_unit_file($node_top_tree_unit, $top_node_filename,
-                               $destination_directory);
+      die "BUG: No element for top node" if (!defined($node_top_tree_unit));
+      $unit_file_name_paths{$node_top_tree_unit} = [$top_node_filename, undef];
     }
     my $file_nr = 0;
     my $previous_page;
     foreach my $tree_unit (@$tree_units) {
       # For Top node.
-      next if ($tree_unit->{'structure'}
-               and defined($tree_unit->{'structure'}->{'unit_filename'}));
-      if (!$tree_unit->{'extra'}->{'first_in_page'}) {
+      next if (exists($unit_file_name_paths{$tree_unit}));
+      my $file_tree_unit = $tree_unit->{'extra'}->{'first_in_page'};
+      if (!$file_tree_unit) {
         cluck ("No first_in_page for $tree_unit\n");
       }
-      if (not $tree_unit->{'extra'}->{'first_in_page'}->{'structure'}
-          or not 
defined($tree_unit->{'extra'}->{'first_in_page'}->{'structure'}->{'unit_filename'}))
 {
-        my $file_tree_unit = $tree_unit->{'extra'}->{'first_in_page'};
+      if (not exists($unit_file_name_paths{$file_tree_unit})) {
         foreach my $root_command (@{$file_tree_unit->{'contents'}}) {
           if ($root_command->{'cmdname'}
               and $root_command->{'cmdname'} eq 'node') {
@@ -7836,55 +7834,59 @@ sub _html_set_pages_files($$$$$$$$)
               $node_filename
                 = $self->{'targets'}->{$root_command}->{'node_filename'};
             }
-            $self->set_tree_unit_file($file_tree_unit, $node_filename,
-                                      $destination_directory);
+            $unit_file_name_paths{$file_tree_unit} = [$node_filename, undef];
             last;
           }
         }
-        if (not $file_tree_unit->{'structure'}
-            or not defined($file_tree_unit->{'structure'}->{'unit_filename'})) 
{
+        if (not defined($unit_file_name_paths{$file_tree_unit})) {
           # use section to do the file name if there is no node
           my $command = $self->tree_unit_element_command($file_tree_unit);
           if ($command) {
             if ($command->{'cmdname'} eq 'top' and !$node_top
                 and defined($top_node_filename)) {
-              $self->set_tree_unit_file($file_tree_unit, $top_node_filename,
-                                        $destination_directory);
+              $unit_file_name_paths{$file_tree_unit}
+                                     = [$top_node_filename, undef];
             } else {
-              $self->set_tree_unit_file($file_tree_unit,
-                 $self->{'targets'}->{$command}->{'section_filename'},
-                                        $destination_directory);
+              $unit_file_name_paths{$file_tree_unit}
+                = [$self->{'targets'}->{$command}->{'section_filename'}, 
undef];
             }
           } else {
             # when everything else has failed
             if ($file_nr == 0 and !$node_top
                 and defined($top_node_filename)) {
-              $self->set_tree_unit_file($file_tree_unit, $top_node_filename,
-                                        $destination_directory);
+              $unit_file_name_paths{$file_tree_unit}
+                                      = [$top_node_filename, undef];
             } else {
               my $filename = $document_name . "_$file_nr";
               $filename .= $extension;
-              $self->set_tree_unit_file($tree_unit, $filename,
-                                        $destination_directory);
+              $unit_file_name_paths{$file_tree_unit} = [$filename, undef];
             }
             $file_nr++;
           }
         }
       }
-      $tree_unit->{'structure'}->{'unit_filename'}
-         = 
$tree_unit->{'extra'}->{'first_in_page'}->{'structure'}->{'unit_filename'};
+      if (not exists($unit_file_name_paths{$tree_unit})) {
+        $unit_file_name_paths{$tree_unit}
+           = $unit_file_name_paths{$file_tree_unit}
+      }
     }
   }
 
   foreach my $tree_unit (@$tree_units) {
+    my ($filename, $filepath) = @{$unit_file_name_paths{$tree_unit}};
     if (defined($self->{'file_id_setting'}->{'tree_unit_file_name'})) {
       # NOTE the information that it is associated with @top or @node Top
       # may be determined with $self->element_is_tree_unit_top($tree_unit);
-      my $filename = &{$self->{'file_id_setting'}->{'tree_unit_file_name'}}(
-               $self, $tree_unit, 
$tree_unit->{'structure'}->{'unit_filename'});
-      $self->set_tree_unit_file($tree_unit, $filename, $destination_directory)
-         if (defined($filename));
+      my ($user_filename, $user_filepath)
+         = &{$self->{'file_id_setting'}->{'tree_unit_file_name'}}(
+               $self, $tree_unit, $filename, $filepath);
+      if (defined($user_filename)) {
+        $filename = $user_filename;
+        $filepath = $user_filepath;
+      }
     }
+    $self->set_tree_unit_file($tree_unit, $filename, $destination_directory,
+                              $filepath);
     my $tree_unit_filename = $tree_unit->{'structure'}->{'unit_filename'};
     $self->{'file_counters'}->{$tree_unit_filename} = 0
        if (!exists($self->{'file_counters'}->{$tree_unit_filename}));
diff --git a/tp/init/book.pm b/tp/init/book.pm
index d2124611b8..f7258c01b8 100644
--- a/tp/init/book.pm
+++ b/tp/init/book.pm
@@ -395,13 +395,18 @@ foreach my $command 
(keys(%Texinfo::Commands::sectioning_heading_commands),
                                 \&book_convert_heading_command);
 }
 
-sub book_element_file_name($$$)
+sub book_element_file_name($$$$)
 {
   my $converter = shift;
   my $element = shift;
   my $filename = shift;
+  my $filepath = shift;
 
-  return undef if (!$converter->get_conf('SPLIT'));
+  return (undef, undef) if (!$converter->get_conf('SPLIT'));
+
+  # should only happen if ! SPLIT, so should be redundant with the
+  # condition above
+  return ($filename, $filepath) if (defined($filepath));
 
   if (defined($book_previous_default_filename)
       and ($filename eq $book_previous_default_filename)) {
@@ -433,7 +438,7 @@ sub book_element_file_name($$$)
   }
   $book_previous_default_filename = $filename;
   $book_previous_file_name = $new_file_name;
-  return $new_file_name;
+  return ($new_file_name, $filepath);
 }
 
 texinfo_register_file_id_setting_function('tree_unit_file_name',
diff --git a/tp/t/init/misc_file_collision.init 
b/tp/t/init/misc_file_collision.init
index 45efa97a31..318c1b910f 100644
--- a/tp/t/init/misc_file_collision.init
+++ b/tp/t/init/misc_file_collision.init
@@ -3,11 +3,14 @@ use strict;
 texinfo_register_file_id_setting_function('tree_unit_file_name',
                                           \&test_misc_file_name);
 
-sub test_misc_file_name($$$)
+sub test_misc_file_name($$$$)
 {
   my $converter = shift;
   my $element = shift;
   my $filename = shift;
+  my $filepath = shift;
+
+  return ($filename, $filepath) if (defined($filepath));
 
   if ($converter->element_is_tree_unit_top($element)
       or ($converter->{'tree_units'}->[2]
@@ -17,7 +20,7 @@ sub test_misc_file_name($$$)
     $filename = "${prefix}_abt"
       . ((defined($extension)) ? ".$extension" : '');
   }
-  return $filename;
+  return ($filename, $filepath);
 }
 
 texinfo_set_from_init_file('DO_ABOUT', 1);



reply via email to

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