[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
branch master updated: * tp/Texinfo/Common.pm (output_files_initialize),
From: |
Patrice Dumas |
Subject: |
branch master updated: * tp/Texinfo/Common.pm (output_files_initialize), tp/Texinfo/Convert/Converter.pm (converter), tp/Texinfo/Convert/Text.pm (output), tp/texi2any.pl: add output_files_initialize() to initialize the structures of the output files API. |
Date: |
Wed, 28 Sep 2022 13:48:10 -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 ffa3aead15 * tp/Texinfo/Common.pm (output_files_initialize),
tp/Texinfo/Convert/Converter.pm (converter), tp/Texinfo/Convert/Text.pm
(output), tp/texi2any.pl: add output_files_initialize() to initialize the
structures of the output files API.
ffa3aead15 is described below
commit ffa3aead15320a1245d1c6effcfd6cc12dd8a3fd
Author: Patrice Dumas <pertusus@free.fr>
AuthorDate: Wed Sep 28 19:48:01 2022 +0200
* tp/Texinfo/Common.pm (output_files_initialize),
tp/Texinfo/Convert/Converter.pm (converter),
tp/Texinfo/Convert/Text.pm (output), tp/texi2any.pl: add
output_files_initialize() to initialize the structures of the output
files API.
* tp/Texinfo/Common.pm (parse_node_manual, set_global_document_command)
(set_output_encodings, modify_tree): avoid erroneous autovivification,
initialize more cleanly.
---
ChangeLog | 12 ++++++++
tp/Texinfo/Common.pm | 61 +++++++++++++++++++++++++++--------------
tp/Texinfo/Convert/Converter.pm | 2 +-
tp/Texinfo/Convert/Text.pm | 2 +-
tp/texi2any.pl | 7 +++--
5 files changed, 59 insertions(+), 25 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 90e59168d6..9daf2319ad 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,15 @@
+2022-09-28 Patrice Dumas <pertusus@free.fr>
+
+ * tp/Texinfo/Common.pm (output_files_initialize),
+ tp/Texinfo/Convert/Converter.pm (converter),
+ tp/Texinfo/Convert/Text.pm (output), tp/texi2any.pl: add
+ output_files_initialize() to initialize the structures of the output
+ files API.
+
+ * tp/Texinfo/Common.pm (parse_node_manual, set_global_document_command)
+ (set_output_encodings, modify_tree): avoid erroneous autovivification,
+ initialize more cleanly.
+
2022-09-28 Patrice Dumas <pertusus@free.fr>
* tp/Texinfo/Transformations.pm (set_menus_node_directions): handle
diff --git a/tp/Texinfo/Common.pm b/tp/Texinfo/Common.pm
index 4923b54cba..8e85b18877 100644
--- a/tp/Texinfo/Common.pm
+++ b/tp/Texinfo/Common.pm
@@ -21,6 +21,8 @@
package Texinfo::Common;
use strict;
+# To check if there is no erroneous autovivification
+#no autovivification qw(fetch delete exists store strict);
# for unicode/layer support in binmode
# for binmode documented as pushing :utf8 on top of :encoding
@@ -677,7 +679,7 @@ our %index_names = (
foreach my $index (keys(%index_names)) {
$index_names{$index}->{'name'} = $index;
- $index_names{$index}->{'contained_indices'}->{$index} = 1;
+ $index_names{$index}->{'contained_indices'} = {$index => 1};
}
our %default_index_commands;
@@ -1235,6 +1237,13 @@ sub locate_init_file($$$)
# API to open, set encoding and register files.
# In general $SELF is stored as $converter->{'output_files'}
# and should be accessed through $converter->output_files_information();
+
+# TODO next three functions not documented anywhere, probably relevant to
document
+# both in POD and in HTML Customization API.
+sub output_files_initialize
+{
+ return {'unclosed_files' => {}, 'opened_files' => []};
+}
#
# All the opened files are registered, except for stdout,
# and the closing of files should be registered too with
@@ -1247,9 +1256,6 @@ sub locate_init_file($$$)
# $OUTPUT_ENCODING argument overrides the output encoding.
# returns the opened filehandle, or undef if opening failed,
# and the $! error message or undef if opening succeeded.
-#
-# TODO next two functions not documented anywhere, probably relevant to
document
-# both in POD and in HTML Customization API.
sub output_files_open_out($$$;$$)
{
my $self = shift;
@@ -1498,6 +1504,7 @@ sub parse_node_manual($)
my ($end_paren, $spaces_after);
if ($contents[0] and $contents[0]->{'text'} and $contents[0]->{'text'} =~
/^\(/) {
+ $manual = [];
# remove the leading ( from @contents, it is not in manual_content.
my $braces_count = 1;
if ($contents[0]->{'text'} ne '(') {
@@ -1542,15 +1549,21 @@ sub parse_node_manual($)
}
}
}
- if ($braces_count == 0) {
- $result->{'manual_content'} = $manual if (defined($manual));
- } else {
+ if ($braces_count != 0) {
# unclosed brace, reset @contents
@contents = @{$label_contents_container->{'contents'}};
+ $manual = undef;
}
}
+ my $node_content;
if (scalar(@contents) > 0) {
- $result->{'node_content'} = \@contents;
+ $node_content = \@contents;
+ }
+
+ if (($manual and scalar(@$manual)) or $node_content) {
+ $result = {};
+ $result->{'node_content'} = $node_content if ($node_content);
+ $result->{'manual_content'} = $manual if ($manual and scalar(@$manual));
}
# Return the contents array in which all the elements in 'manual_content'
@@ -1733,7 +1746,8 @@ sub set_global_document_command($$$$)
}
my $element;
- if (defined($global_commands_information->{$global_command})
+ if ($global_commands_information
+ and defined($global_commands_information->{$global_command})
and ref($global_commands_information->{$global_command}) eq 'ARRAY') {
if ($command_location eq 'last') {
$element = $global_commands_information->{$global_command}->[-1];
@@ -1755,7 +1769,8 @@ sub set_global_document_command($$$$)
}
}
}
- } elsif (defined($global_commands_information->{$global_command})) {
+ } elsif ($global_commands_information
+ and defined($global_commands_information->{$global_command})) {
# unique command, first, preamble and last are the same
$element = $global_commands_information->{$global_command};
set_informative_command_value($self, $element);
@@ -1770,7 +1785,8 @@ sub set_output_encodings($$)
$customization_information->set_conf('OUTPUT_ENCODING_NAME',
$parser_information->{'input_encoding_name'})
- if ($parser_information->{'input_encoding_name'});
+ if ($parser_information
+ and $parser_information->{'input_encoding_name'});
if (!$customization_information->get_conf('OUTPUT_PERL_ENCODING')
and $customization_information->get_conf('OUTPUT_ENCODING_NAME')) {
my $perl_encoding
@@ -2284,7 +2300,7 @@ sub _substitute_references($$$)
my $index = 0;
foreach my $child (@{$new->{$key}}) {
_substitute_references($child, $current->{$key}->[$index],
- $reference_associations);
+ $reference_associations);
$index++;
}
}
@@ -2313,7 +2329,6 @@ sub _substitute_references($$$)
#print STDERR "Done [$command_or_type]: $key\n";
} else {
if (ref($current->{'extra'}->{$key}) eq 'ARRAY') {
-
#print STDERR "Array $command_or_type -> $key\n";
$new->{'extra'}->{$key} = _substitute_references_in_array(
$current->{'extra'}->{$key}, $reference_associations,
@@ -2321,12 +2336,13 @@ sub _substitute_references($$$)
} else {
if (($current->{'cmdname'}
and ($current->{'cmdname'} eq 'listoffloats'
- or $current->{'cmdname'} eq 'float')
+ or $current->{'cmdname'} eq 'float')
and $key eq 'type')
- or ($key eq 'index_entry')
- or ($current->{'type'}
- and $current->{'type'} eq 'menu_entry'
- and $key eq 'menu_entry_node')) {
+ or ($key eq 'index_entry')
+ or ($current->{'type'}
+ and $current->{'type'} eq 'menu_entry'
+ and $key eq 'menu_entry_node')) {
+ $new->{'extra'}->{$key} = {};
foreach my $type_key (keys(%{$current->{'extra'}->{$key}})) {
if (ref($current->{'extra'}->{$key}->{$type_key}) eq '') {
$new->{'extra'}->{$key}->{$type_key}
@@ -2341,7 +2357,8 @@ sub _substitute_references($$$)
$reference_associations,
"[$command_or_type]{$key}{$type_key}");
} elsif ($key eq 'index_entry' and $type_key eq
'index_ignore_chars') {
- $new->{'extra'}->{$key}->{$type_key} = {
%{$current->{'extra'}->{$key}->{$type_key}} };
+ $new->{'extra'}->{$key}->{$type_key}
+ = { %{$current->{'extra'}->{$key}->{$type_key}} };
} else {
print STDERR "Not substituting [$command_or_type]{$key}:
$type_key\n";
}
@@ -2385,6 +2402,9 @@ sub modify_tree($$;$)
my $argument = shift;
#print STDERR "modify_tree tree: $tree\n";
+ # TODO warn?
+ return undef if (!$tree or ref($tree) ne 'HASH');
+
if ($tree->{'args'}) {
my @args = @{$tree->{'args'}};
for (my $i = 0; $i <= $#args; $i++) {
@@ -2719,7 +2739,8 @@ sub register_label($$$)
# cluck("BUG: register_label \$targets_list not an ARRAY reference\n");
#}
push @{$targets_list}, $current;
- if ($label->{'node_content'}) {
+ if ($label and $label->{'node_content'}) {
+ #$current->{'extra'} = {} if (!$current->{'extra'});
$current->{'extra'}->{'node_content'} = $label->{'node_content'};
}
}
diff --git a/tp/Texinfo/Convert/Converter.pm b/tp/Texinfo/Convert/Converter.pm
index 2be74f4912..f777f8fbcc 100644
--- a/tp/Texinfo/Convert/Converter.pm
+++ b/tp/Texinfo/Convert/Converter.pm
@@ -252,7 +252,7 @@ sub converter(;$)
# used for output files information, to register opened
# and not closed files. Accessed through output_files_information()
- $converter->{'output_files'} = {};
+ $converter->{'output_files'} = Texinfo::Common::output_files_initialize();
$converter->Texinfo::Report::new();
diff --git a/tp/Texinfo/Convert/Text.pm b/tp/Texinfo/Convert/Text.pm
index e4bd87c3cf..bf9ebfc071 100644
--- a/tp/Texinfo/Convert/Text.pm
+++ b/tp/Texinfo/Convert/Text.pm
@@ -800,7 +800,7 @@ sub output($$)
}
}
my $fh;
- $self->{'output_files'} = {};
+ $self->{'output_files'} = Texinfo::Common::output_files_initialize();
my ($encoded_outfile, $outfile_encoding);
if (defined($outfile)) {
($encoded_outfile, $outfile_encoding)
diff --git a/tp/texi2any.pl b/tp/texi2any.pl
index f70342c3f7..121e22352c 100755
--- a/tp/texi2any.pl
+++ b/tp/texi2any.pl
@@ -1423,7 +1423,7 @@ while(@input_files) {
#print STDERR "$texinfo_text\n";
my $encoded_macro_expand_file_name = get_conf('MACRO_EXPAND');
my $macro_expand_file_name =
_decode_input($encoded_macro_expand_file_name);
- my $macro_expand_files_information = {};
+ my $macro_expand_files_information =
Texinfo::Common::output_files_initialize();;
my ($macro_expand_fh, $error_message) =
Texinfo::Common::output_files_open_out(
$macro_expand_files_information,
$main_configuration,
$encoded_macro_expand_file_name);
@@ -1627,7 +1627,8 @@ while(@input_files) {
my $encoded_internal_links_file_name = get_conf('INTERNAL_LINKS');
my $internal_links_file_name
= _decode_input($encoded_internal_links_file_name);
- my $internal_links_files_information = {};
+ my $internal_links_files_information
+ = Texinfo::Common::output_files_initialize();
my ($internal_links_fh, $error_message)
= Texinfo::Common::output_files_open_out(
$internal_links_files_information, $converter,
@@ -1678,7 +1679,7 @@ while(@input_files) {
my ($encoded_sort_element_count_file_name, $path_encoding)
= Texinfo::Common::encode_file_name($sort_element_count_file_name,
$input_perl_encoding);
- my $sort_elem_files_information = {};
+ my $sort_elem_files_information =
Texinfo::Common::output_files_initialize();
# FIXME using $converter here for the configuration is
# not right, should be changed by something not associated
# with the converter but to the main program or file. parser
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- branch master updated: * tp/Texinfo/Common.pm (output_files_initialize), tp/Texinfo/Convert/Converter.pm (converter), tp/Texinfo/Convert/Text.pm (output), tp/texi2any.pl: add output_files_initialize() to initialize the structures of the output files API.,
Patrice Dumas <=