[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
branch master updated: * tp/Texinfo/Convert/Converter.pm (initialize_tre
From: |
Patrice Dumas |
Subject: |
branch master updated: * tp/Texinfo/Convert/Converter.pm (initialize_tree_units_files) (set_tree_unit_file, _set_tree_units_files, table_item_content_tree), tp/Texinfo/Convert/HTML.pm (_html_set_pages_files, output): add a function, initialize_tree_units_files to initialize hashes used in set_tree_unit_file and 'file_counters'. Add a file path argument to set_tree_unit_file and use the function to set file path when non split too. Initialize structures more explicitly. |
Date: |
Sun, 09 Oct 2022 08:02:08 -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 1abdf04b79 * tp/Texinfo/Convert/Converter.pm
(initialize_tree_units_files) (set_tree_unit_file, _set_tree_units_files,
table_item_content_tree), tp/Texinfo/Convert/HTML.pm (_html_set_pages_files,
output): add a function, initialize_tree_units_files to initialize hashes used
in set_tree_unit_file and 'file_counters'. Add a file path argument to
set_tree_unit_file and use the function to set file path when non split too.
Initialize structures more explicitly.
1abdf04b79 is described below
commit 1abdf04b793d9e8810053f1dc15cbcc4dec24998
Author: Patrice Dumas <pertusus@free.fr>
AuthorDate: Sun Oct 9 14:01:54 2022 +0200
* tp/Texinfo/Convert/Converter.pm (initialize_tree_units_files)
(set_tree_unit_file, _set_tree_units_files, table_item_content_tree),
tp/Texinfo/Convert/HTML.pm (_html_set_pages_files, output):
add a function, initialize_tree_units_files to initialize hashes used
in set_tree_unit_file and 'file_counters'. Add a file path argument
to set_tree_unit_file and use the function to set file path when non
split too. Initialize structures more explicitly.
* tp/Texinfo/Convert/Converter.pm (output): use a hash directly,
renamed as %files_filehandle from %files to associate filehandles.
---
ChangeLog | 13 ++++++
tp/TODO | 5 +++
tp/Texinfo/Convert/Converter.pm | 85 ++++++++++++++++++++++++++++--------
tp/Texinfo/Convert/HTML.pm | 35 ++++++++++-----
tp/Texinfo/XS/parsetexi/Parsetexi.pm | 3 ++
5 files changed, 110 insertions(+), 31 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 093bbea1a6..238305fb07 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,16 @@
+2022-10-09 Patrice Dumas <pertusus@free.fr>
+
+ * tp/Texinfo/Convert/Converter.pm (initialize_tree_units_files)
+ (set_tree_unit_file, _set_tree_units_files, table_item_content_tree),
+ tp/Texinfo/Convert/HTML.pm (_html_set_pages_files, output):
+ add a function, initialize_tree_units_files to initialize hashes used
+ in set_tree_unit_file and 'file_counters'. Add a file path argument
+ to set_tree_unit_file and use the function to set file path when non
+ split too. Initialize structures more explicitly.
+
+ * tp/Texinfo/Convert/Converter.pm (output): use a hash directly,
+ renamed as %files_filehandle from %files to associate filehandles.
+
2022-10-09 Patrice Dumas <pertusus@free.fr>
* tp/ext/*.pm, tp/init/*.pm: check that there is no incorrect
diff --git a/tp/TODO b/tp/TODO
index c47c5f8a1c..51061804e9 100644
--- a/tp/TODO
+++ b/tp/TODO
@@ -10,9 +10,14 @@ This is the todo list for texi2any
Before next release
===================
+check same keys for
global_unique document_settable_unique_at_commands
global document_settable_multiple_at_commands
+./contents//res_parser/double_contents_after_title_book_chapter/double_contents.2
+ texi2any: warning: could not read init file book.init
+
+
Add in_math (for /)?
Bugs
diff --git a/tp/Texinfo/Convert/Converter.pm b/tp/Texinfo/Convert/Converter.pm
index b031abf106..03ddcd3770 100644
--- a/tp/Texinfo/Convert/Converter.pm
+++ b/tp/Texinfo/Convert/Converter.pm
@@ -22,6 +22,9 @@ package Texinfo::Convert::Converter;
use 5.00405;
use strict;
+# To check if there is no erroneous autovivification
+#no autovivification qw(fetch delete exists store strict);
+
# for fileparse
use File::Basename;
# for file names portability
@@ -192,6 +195,7 @@ sub converter(;$)
$defaults{$key} = $all_converters_defaults{$key}
if (!exists($defaults{$key}));
}
+ $converter->{'conf'} = {};
foreach my $key (keys(%defaults)) {
if (Texinfo::Common::valid_customization_option($key)) {
$converter->{'conf'}->{$key} = $defaults{$key};
@@ -244,6 +248,7 @@ sub converter(;$)
# turn the array to a hash for speed. Not sure it really matters for such
# a small array.
my $expanded_formats = $converter->get_conf('EXPANDED_FORMATS');
+ $converter->{'expanded_formats_hash'} = {};
if (defined($expanded_formats)) {
foreach my $expanded_format (@{$converter->get_conf('EXPANDED_FORMATS')}) {
$converter->{'expanded_formats_hash'}->{$expanded_format} = 1;
@@ -355,7 +360,8 @@ sub output($$)
# Now do the output
my $fh;
my $output = '';
- if (!$tree_units or
!defined($tree_units->[0]->{'structure'}->{'unit_filename'})) {
+ if (!$tree_units or !$tree_units->[0]->{'structure'}
+ or !defined($tree_units->[0]->{'structure'}->{'unit_filename'})) {
# no page
my $outfile_name;
my $encoded_outfile_name;
@@ -423,14 +429,14 @@ sub output($$)
# output with pages
print STDERR "DO Elements with filenames\n"
if ($self->get_conf('DEBUG'));
- my %files;
+ my %files_filehandle;
foreach my $tree_unit (@$tree_units) {
my $tree_unit_filename = $tree_unit->{'structure'}->{'unit_filename'};
my $out_filepath = $self->{'out_filepaths'}->{$tree_unit_filename};
my $file_fh;
# open the file and output the elements
- if (!$files{$tree_unit_filename}->{'fh'}) {
+ if (!exists($files_filehandle{$tree_unit_filename})) {
my $error_message;
($file_fh, $error_message) = Texinfo::Common::output_files_open_out(
$self->output_files_information(), $self,
@@ -441,9 +447,9 @@ sub output($$)
$out_filepath, $error_message));
return undef;
}
- $files{$tree_unit_filename}->{'fh'} = $file_fh;
+ $files_filehandle{$tree_unit_filename} = $file_fh;
} else {
- $file_fh = $files{$tree_unit_filename}->{'fh'};
+ $file_fh = $files_filehandle{$tree_unit_filename};
}
my $tree_unit_text = $self->convert_tree($tree_unit);
print $file_fh $tree_unit_text;
@@ -739,13 +745,28 @@ sub node_information_filename($$)
return $filename;
}
+sub initialize_tree_units_files($)
+{
+ my $self = shift;
+
+ $self->{'out_filepaths'} = {};
+ $self->{'file_counters'} = {};
+
+ if ($self->get_conf('CASE_INSENSITIVE_FILENAMES')) {
+ $self->{'filenames'} = {};
+ }
+}
+
# sets out_filepaths converter state
-sub set_tree_unit_file($$$$)
+# $FILEPATH can be given explicitly, otherwise it is based on $FILENAME
+# and $DESTINATION_DIRECTORY
+sub set_tree_unit_file($$$$;$)
{
my $self = shift;
my $tree_unit = shift;
my $filename = shift;
my $destination_directory = shift;
+ my $filepath = shift;
if (!defined($filename)) {
cluck("set_tree_unit_file: filename not defined\n");
@@ -761,8 +782,26 @@ sub set_tree_unit_file($$$$)
$self->{'filenames'}->{lc($filename)} = $filename;
}
}
+ $tree_unit->{'structure'} = {} if (!($tree_unit->{'structure'}));
+ if (exists($tree_unit->{'structure'}->{'unit_filename'})) {
+ # FIXME happens for added elements, also no_monolithic, but probably also
+ # for added elements.
+ # 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'));
+ }
+ }
$tree_unit->{'structure'}->{'unit_filename'} = $filename;
- if (defined($destination_directory) and $destination_directory ne '') {
+ if (defined($filepath)) {
+ $self->{'out_filepaths'}->{$filename} = $filepath;
+ } elsif (defined($destination_directory) and $destination_directory ne '') {
$self->{'out_filepaths'}->{$filename} =
File::Spec->catfile($destination_directory, $filename);
} else {
@@ -816,7 +855,6 @@ sub _get_root_element($$)
}
# set file_counters converter state
-# sets out_filepaths converter state
sub _set_tree_units_files($$$$$$)
{
my $self = shift;
@@ -829,6 +867,8 @@ sub _set_tree_units_files($$$$$$)
# Ensure that the document has pages
return undef if (!defined($tree_units) or !@$tree_units);
+ $self->initialize_tree_units_files();
+
my $extension = '';
$extension = '.'.$self->get_conf('EXTENSION')
if (defined($self->get_conf('EXTENSION'))
@@ -836,10 +876,8 @@ sub _set_tree_units_files($$$$$$)
if (!$self->get_conf('SPLIT')) {
foreach my $tree_unit (@$tree_units) {
- if (!defined($tree_unit->{'structure'}->{'unit_filename'})) {
- $tree_unit->{'structure'}->{'unit_filename'} = $output_filename;
- $self->{'out_filepaths'}->{$output_filename} = $output_file;
- }
+ $self->set_tree_unit_file($tree_unit, $output_filename, undef,
+ $output_file);
}
} else {
my $node_top;
@@ -857,7 +895,8 @@ sub _set_tree_units_files($$$$$$)
my $previous_page;
foreach my $tree_unit (@$tree_units) {
# For Top node.
- next if (defined($tree_unit->{'structure'}->{'unit_filename'}));
+ next if ($tree_unit->{'structure'}
+ and defined($tree_unit->{'structure'}->{'unit_filename'}));
if (!$tree_unit->{'extra'}->{'first_in_page'}) {
cluck ("No first_in_page for $tree_unit\n");
}
@@ -916,11 +955,14 @@ sub _set_tree_units_files($$$$$$)
}
foreach my $tree_unit (@$tree_units) {
- $self->{'file_counters'}->{$tree_unit->{'structure'}->{'unit_filename'}}++;
+ my $tree_unit_filename = $tree_unit->{'structure'}->{'unit_filename'};
+ $self->{'file_counters'}->{$tree_unit_filename} = 0
+ if (!exists($self->{'file_counters'}->{$tree_unit_filename}));
+ $self->{'file_counters'}->{$tree_unit_filename}++;
print STDERR "Page $tree_unit "
.Texinfo::Structuring::root_or_external_element_cmd_texi($tree_unit)
- .":
$tree_unit->{'structure'}->{'unit_filename'}($self->{'file_counters'}->{$tree_unit->{'structure'}->{'unit_filename'}})\n"
- if ($self->get_conf('DEBUG'));
+ .":
$tree_unit_filename($self->{'file_counters'}->{$tree_unit_filename})\n"
+ if ($self->get_conf('DEBUG'));
}
}
@@ -1178,7 +1220,8 @@ sub float_name_caption($$)
my $prepended;
if ($type) {
if ($caption) {
- if (defined($element->{'structure'}->{'float_number'})) {
+ if ($element->{'structure'}
+ and defined($element->{'structure'}->{'float_number'})) {
$prepended = $self->gdt('{float_type} {float_number}: ',
{'float_type' => $type,
'float_number' => $element->{'structure'}->{'float_number'}});
@@ -1187,7 +1230,8 @@ sub float_name_caption($$)
{'float_type' => $type});
}
} else {
- if (defined($element->{'structure'}->{'float_number'})) {
+ if ($element->{'structure'}
+ and defined($element->{'structure'}->{'float_number'})) {
$prepended = $self->gdt("{float_type} {float_number}\n",
{'float_type' => $type,
'float_number' => $element->{'structure'}->{'float_number'}});
@@ -1196,7 +1240,8 @@ sub float_name_caption($$)
{'float_type' => $type});
}
}
- } elsif (defined($element->{'structure'}->{'float_number'})) {
+ } elsif ($element->{'structure'}
+ and defined($element->{'structure'}->{'float_number'})) {
if ($caption) {
$prepended = $self->gdt('{float_number}: ',
{'float_number' => $element->{'structure'}->{'float_number'}});
@@ -1252,10 +1297,12 @@ sub table_item_content_tree($$$)
'source_info' => $element->{'source_info'},
'parent' => $table_item_tree };
if ($table_command->{'extra'}->{'command_as_argument_kbd_code'}) {
+ $command->{'extra'} = {} if (!$command->{'extra'});
$command->{'extra'}->{'code'} = 1;
}
if ($command_as_argument->{'type'} eq 'definfoenclose_command') {
$command->{'type'} = $command_as_argument->{'type'};
+ $command->{'extra'} = {} if (!$command->{'extra'});
$command->{'extra'}->{'begin'} =
$command_as_argument->{'extra'}->{'begin'};
$command->{'extra'}->{'end'} = $command_as_argument->{'extra'}->{'end'};
}
diff --git a/tp/Texinfo/Convert/HTML.pm b/tp/Texinfo/Convert/HTML.pm
index 9b1a879ca2..8f39c6cb6d 100644
--- a/tp/Texinfo/Convert/HTML.pm
+++ b/tp/Texinfo/Convert/HTML.pm
@@ -7715,10 +7715,8 @@ sub _html_set_pages_files($$$$$$$$)
if (!$self->get_conf('SPLIT')) {
foreach my $tree_unit (@$tree_units) {
- if (!defined($tree_unit->{'structure'}->{'unit_filename'})) {
- $tree_unit->{'structure'}->{'unit_filename'} = $output_filename;
- $self->{'out_filepaths'}->{$output_filename} = $output_file;
- }
+ $self->set_tree_unit_file($tree_unit, $output_filename, undef,
+ $output_file);
}
} else {
my $node_top;
@@ -7811,11 +7809,14 @@ sub _html_set_pages_files($$$$$$$$)
$self->set_tree_unit_file($tree_unit, $filename, $destination_directory)
if (defined($filename));
}
- $self->{'file_counters'}->{$tree_unit->{'structure'}->{'unit_filename'}}++;
+ my $tree_unit_filename = $tree_unit->{'structure'}->{'unit_filename'};
+ $self->{'file_counters'}->{$tree_unit_filename} = 0
+ if (!exists($self->{'file_counters'}->{$tree_unit_filename}));
+ $self->{'file_counters'}->{$tree_unit_filename}++;
print STDERR "Page $tree_unit "
.Texinfo::Structuring::root_or_external_element_cmd_texi($tree_unit)
- .":
$tree_unit->{'structure'}->{'unit_filename'}($self->{'file_counters'}->{$tree_unit->{'structure'}->{'unit_filename'}})\n"
- if ($self->get_conf('DEBUG'));
+ .":
$tree_unit_filename($self->{'file_counters'}->{$tree_unit_filename})\n"
+ if ($self->get_conf('DEBUG'));
}
if ($special_elements) {
my $previous_tree_unit = $tree_units->[-1];
@@ -7823,10 +7824,14 @@ sub _html_set_pages_files($$$$$$$$)
my $filename
= $self->{'targets'}->{$special_element}->{'special_element_filename'};
if (defined($filename)) {
- $self->set_tree_unit_file($special_element, $filename,
$destination_directory);
-
$self->{'file_counters'}->{$special_element->{'structure'}->{'unit_filename'}}++;
- print STDERR "Special page $special_element:
$special_element->{'structure'}->{'unit_filename'}($self->{'file_counters'}->{$special_element->{'structure'}->{'unit_filename'}})\n"
- if ($self->get_conf('DEBUG'));
+ $self->set_tree_unit_file($special_element, $filename,
+ $destination_directory);
+ $self->{'file_counters'}->{$filename} = 0
+ if (!exists($self->{'file_counters'}->{$filename}));
+ $self->{'file_counters'}->{$filename}++;
+ print STDERR "Special page $special_element: "
+ ."$filename($self->{'file_counters'}->{$filename})\n"
+ if ($self->get_conf('DEBUG'));
}
$special_element->{'structure'}->{'unit_prev'} = $previous_tree_unit;
$previous_tree_unit->{'structure'}->{'unit_next'} = $special_element;
@@ -9303,6 +9308,8 @@ sub convert($$)
# Some information is not available yet.
$self->_reset_info();
+ # FIXME set_tree_unit_file is called in _prepare_conversion_tree_units
+ # but there should not be files if called with convert.
my ($tree_units, $special_elements)
= $self->_prepare_conversion_tree_units($root, undef, undef);
@@ -9578,6 +9585,9 @@ sub output($$)
# Some information is not available yet.
$self->_reset_info();
+ # FIXME set_tree_unit_file is called in _prepare_conversion_tree_units
+ # and may or most probably will be called again in _html_set_pages_files.
+ $self->initialize_tree_units_files();
# 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 ($tree_units, $special_elements)
@@ -9607,6 +9617,7 @@ sub output($$)
# This may only happen if not split.
if ($special_elements
and $tree_units and $tree_units->[0]
+ and $tree_units->[0]->{'structure'}
and defined($tree_units->[0]->{'structure'}->{'unit_filename'})) {
foreach my $special_element (@$special_elements) {
if (!defined($special_element->{'structure'}->{'unit_filename'})) {
@@ -9783,7 +9794,7 @@ sub output($$)
my $output = '';
- if (!$tree_units
+ if (!$tree_units or !$tree_units->[0]->{'structure'}
or !defined($tree_units->[0]->{'structure'}->{'unit_filename'})) {
my $fh;
my $encoded_no_page_out_filepath;
diff --git a/tp/Texinfo/XS/parsetexi/Parsetexi.pm
b/tp/Texinfo/XS/parsetexi/Parsetexi.pm
index 02c395fd60..3c87a0b202 100644
--- a/tp/Texinfo/XS/parsetexi/Parsetexi.pm
+++ b/tp/Texinfo/XS/parsetexi/Parsetexi.pm
@@ -49,6 +49,9 @@ use 5.00405;
use strict;
use warnings;
+# To check if there is no erroneous autovivification
+#no autovivification qw(fetch delete exists store strict);
+
use Storable qw(dclone); # standard in 5.007003
use Encode qw(decode);
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- branch master updated: * tp/Texinfo/Convert/Converter.pm (initialize_tree_units_files) (set_tree_unit_file, _set_tree_units_files, table_item_content_tree), tp/Texinfo/Convert/HTML.pm (_html_set_pages_files, output): add a function, initialize_tree_units_files to initialize hashes used in set_tree_unit_file and 'file_counters'. Add a file path argument to set_tree_unit_file and use the function to set file path when non split too. Initialize structures more explicitly.,
Patrice Dumas <=