[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
branch master updated: * tp/Texinfo/Structuring.pm (sort_indices), tp/Te
From: |
Patrice Dumas |
Subject: |
branch master updated: * tp/Texinfo/Structuring.pm (sort_indices), tp/Texinfo/Convert/HTML.pm, tp/Texinfo/Convert/IXIN.pm, tp/Texinfo/Convert/Plaintext.pm, tp/init/chm.pm: merge sort_indices_by_letter() in sort_indices(). Merge do_index_keys() in sort_indices() too. Sort using especially created lists with entries informations. Do not use entry 'key' at all. Return keys used to sort entries as a hash reference. |
Date: |
Sat, 04 Sep 2021 16:18:42 -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 aa210c0 * tp/Texinfo/Structuring.pm (sort_indices),
tp/Texinfo/Convert/HTML.pm, tp/Texinfo/Convert/IXIN.pm,
tp/Texinfo/Convert/Plaintext.pm, tp/init/chm.pm: merge sort_indices_by_letter()
in sort_indices(). Merge do_index_keys() in sort_indices() too. Sort using
especially created lists with entries informations. Do not use entry 'key' at
all. Return keys used to sort entries as a hash reference.
aa210c0 is described below
commit aa210c0f806dc5766b7c7e14fb2afc00a7a2da50
Author: Patrice Dumas <pertusus@free.fr>
AuthorDate: Sat Sep 4 22:16:11 2021 +0200
* tp/Texinfo/Structuring.pm (sort_indices),
tp/Texinfo/Convert/HTML.pm, tp/Texinfo/Convert/IXIN.pm,
tp/Texinfo/Convert/Plaintext.pm, tp/init/chm.pm:
merge sort_indices_by_letter() in sort_indices().
Merge do_index_keys() in sort_indices() too. Sort using
especially created lists with entries informations. Do not
use entry 'key' at all. Return keys used to sort entries as
a hash reference.
---
ChangeLog | 11 ++++
tp/Texinfo/Convert/HTML.pm | 7 ++-
tp/Texinfo/Convert/IXIN.pm | 4 +-
tp/Texinfo/Convert/Plaintext.pm | 5 +-
tp/Texinfo/Structuring.pm | 120 ++++++++++++++++++----------------------
tp/init/chm.pm | 6 +-
tp/t/test_sort.t | 16 +++---
tp/t/test_utils.pl | 37 +++++++------
8 files changed, 105 insertions(+), 101 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 253b5f2..f8c790c 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -10,6 +10,17 @@
2021-09-04 Patrice Dumas <pertusus@free.fr>
+ * tp/Texinfo/Structuring.pm (sort_indices),
+ tp/Texinfo/Convert/HTML.pm, tp/Texinfo/Convert/IXIN.pm,
+ tp/Texinfo/Convert/Plaintext.pm, tp/init/chm.pm:
+ merge sort_indices_by_letter() in sort_indices().
+ Merge do_index_keys() in sort_indices() too. Sort using
+ especially created lists with entries informations. Do not
+ use entry 'key' at all. Return keys used to sort entries as
+ a hash reference.
+
+2021-09-04 Patrice Dumas <pertusus@free.fr>
+
* tp/Texinfo/Config.pm (Texinfo::MainConfig::new):
bless module hash and not input hash. Return explicitly the
blessed hashes.
diff --git a/tp/Texinfo/Convert/HTML.pm b/tp/Texinfo/Convert/HTML.pm
index 37b7244..7e886e4 100644
--- a/tp/Texinfo/Convert/HTML.pm
+++ b/tp/Texinfo/Convert/HTML.pm
@@ -6121,9 +6121,10 @@ sub _prepare_index_entries($)
$self->{'index_names'} = $index_names;
my $merged_index_entries
= Texinfo::Structuring::merge_indices($index_names);
- $self->{'index_entries_by_letter'}
- = Texinfo::Structuring::sort_indices_by_letter ($self->{'parser'}, $self,
- $self, $merged_index_entries, $index_names);
+ my $index_entries_keys;
+ ($self->{'index_entries_by_letter'}, $index_entries_keys)
+ = Texinfo::Structuring::sort_indices($self->{'parser'}, $self,
+ $self, $merged_index_entries, 'by_letter');
$self->{'index_entries'} = $merged_index_entries;
foreach my $index_name (sort(keys(%$index_names))) {
diff --git a/tp/Texinfo/Convert/IXIN.pm b/tp/Texinfo/Convert/IXIN.pm
index 9dbe131..b2d883f 100644
--- a/tp/Texinfo/Convert/IXIN.pm
+++ b/tp/Texinfo/Convert/IXIN.pm
@@ -612,9 +612,9 @@ sub output_ixin($$)
my $index_names = $self->{'parser'}->indices_information();
my $merged_index_entries
= Texinfo::Structuring::merge_indices($index_names);
- my $entries
+ my ($entries, $index_entries_keys)
= $self->Texinfo::Structuring::sort_indices($self->{'parser'}, $self,
- $self, $merged_index_entries, $index_names);
+ $self, $merged_index_entries);
# first do the dts_text as the counts are needed for the dts index
foreach my $index_name (sort(keys(%$entries))) {
my $dts_text_result = '';
diff --git a/tp/Texinfo/Convert/Plaintext.pm b/tp/Texinfo/Convert/Plaintext.pm
index 080a020..13cc761 100644
--- a/tp/Texinfo/Convert/Plaintext.pm
+++ b/tp/Texinfo/Convert/Plaintext.pm
@@ -1192,9 +1192,10 @@ sub _printindex_formatted($$;$)
my $index_names = $self->{'parser'}->indices_information();
my $merged_index_entries
= Texinfo::Structuring::merge_indices($index_names);
- $self->{'index_entries'}
+ my $index_entries_keys;
+ ($self->{'index_entries'}, $index_entries_keys)
= Texinfo::Structuring::sort_indices($self->{'parser'}, $self, $self,
- $merged_index_entries, $index_names);
+ $merged_index_entries);
$self->{'index_names'} = $index_names;
}
if (!$self->{'index_entries'} or !$self->{'index_entries'}->{$index_name}
diff --git a/tp/Texinfo/Structuring.pm b/tp/Texinfo/Structuring.pm
index 6816948..a1aa792 100644
--- a/tp/Texinfo/Structuring.pm
+++ b/tp/Texinfo/Structuring.pm
@@ -1634,15 +1634,15 @@ sub index_key($$$$;$)
my $options = shift;
my $ignore_chars = shift;
- my $converter_options = {%$options};
- $converter_options->{'code'} = $main_entry->{'in_code'};
+ my $convert_to_text_options = {%$options};
+ $convert_to_text_options->{'code'} = $main_entry->{'in_code'};
my $entry_key;
if (defined($sortas)) {
$entry_key = $sortas;
} else {
$entry_key = Texinfo::Convert::Text::convert_to_text(
- $entry_tree_element, $converter_options);
+ $entry_tree_element, $convert_to_text_options);
# FIXME do that for sortas too?
if (defined($ignore_chars) and $ignore_chars ne '') {
$entry_key =~ s/[$ignore_chars]//g;
@@ -1656,75 +1656,61 @@ sub index_key($$$$;$)
return $entry_key;
}
-# Go through all the index entries and set 'key', the sort key, on
-# each one.
-sub do_index_keys($$$$)
+sub sort_indices($$$$;$)
{
my $self = shift;
my $registrar = shift;
my $configuration_informations = shift;
- my $index_names = shift;
+ my $index_entries = shift;
+ my $sort_by_letter = shift;
my ($options, $ignore_chars) = setup_index_entry_keys_formatting($self,
$configuration_informations);
-
- foreach my $index_name (keys(%$index_names)) {
- foreach my $entry (@{$index_names->{$index_name}->{'index_entries'}}) {
- $entry->{'key'} = index_key($entry, {'contents' => $entry->{'content'}},
+ my $sorted_index_entries;
+ my $index_entry_keys = {};
+ foreach my $index_name (keys(%$index_entries)) {
+ # used if not $sort_by_letter
+ my $sortable_index_entries = [];
+ # used if $sort_by_letter
+ my $index_letter_hash;
+ foreach my $entry (@{$index_entries->{$index_name}}) {
+ my $entry_key = index_key($entry, {'contents' => $entry->{'content'}},
$entry->{'sortas'}, $options, $ignore_chars);
- if ($entry->{'key'} !~ /\S/) {
+ $index_entry_keys->{$entry} = $entry_key;
+ $entry->{'key'} = $entry_key;
+ if ($entry_key !~ /\S/) {
$registrar->line_warn($configuration_informations,
sprintf(__("empty index key in \@%s"),
$entry->{'index_at_command'}),
$entry->{'command'}->{'line_nr'});
- }
- }
- }
-}
-
-sub sort_indices($$$$$)
-{
- my $self = shift;
- my $registrar = shift;
- my $configuration_informations = shift;
- my $index_entries = shift;
- my $index_names = shift;
-
- my $sorted_index_entries;
- do_index_keys($self, $registrar, $configuration_informations, $index_names);
- foreach my $index_name (keys(%$index_entries)) {
- @{$sorted_index_entries->{$index_name}} =
- sort _sort_index_entries
- grep {$_->{'key'} =~ /\S/} @{$index_entries->{$index_name}};
- }
- return $sorted_index_entries;
-}
-
-sub sort_indices_by_letter($$$$$)
-{
- my $self = shift;
- my $registrar = shift;
- my $configuration_informations = shift;
- my $index_entries = shift;
- my $index_names = shift;
+ } else {
+ my $sortable_entry = {'entry' => $entry, 'key' => $entry_key,
+ 'number' => $entry->{'number'},
+ 'index_at_command' => $entry->{'index_at_command'}};
- my $indices_sorted_by_letters;
- do_index_keys($self, $registrar, $configuration_informations, $index_names);
- foreach my $index_name (keys(%$index_entries)) {
- my $index_letter_hash;
- foreach my $index_entry (@{$index_entries->{$index_name}}) {
- next if ($index_entry->{'key'} !~ /\S/);
- my $letter = uc(substr($index_entry->{'key'}, 0, 1));
- push @{$index_letter_hash->{$letter}}, $index_entry;
+ if ($sort_by_letter) {
+ my $letter = uc(substr($entry_key, 0, 1));
+ push @{$index_letter_hash->{$letter}}, $sortable_entry;
+ } else {
+ push @{$sortable_index_entries}, $sortable_entry;
+ }
+ }
}
- foreach my $letter (sort _sort_string (keys %$index_letter_hash)) {
- my @sorted_letter_entries
- = sort _sort_index_entries_in_letter @{$index_letter_hash->{$letter}};
- push @{$indices_sorted_by_letters->{$index_name}},
- { 'letter' => $letter, 'entries' => \@sorted_letter_entries };
+ if ($sort_by_letter) {
+ foreach my $letter (sort _sort_string (keys %$index_letter_hash)) {
+ my @sorted_letter_entries
+ = map {$_->{'entry'}}
+ sort _sort_index_entries_in_letter
@{$index_letter_hash->{$letter}};
+ push @{$sorted_index_entries->{$index_name}},
+ { 'letter' => $letter, 'entries' => \@sorted_letter_entries };
+ }
+ } else {
+ @{$sorted_index_entries->{$index_name}} =
+ map {$_->{'entry'}}
+ sort _sort_index_entries @{$sortable_index_entries};
}
}
- return $indices_sorted_by_letters;
+ return $sorted_index_entries, $index_entry_keys;
}
sub merge_indices($)
@@ -1762,7 +1748,7 @@ Texinfo::Structuring - information on Texinfo::Parser tree
use Texinfo::Structuring qw(sectioning_structure nodes_tree number_floats
associate_internal_references split_by_node split_by_section split_pages
- merge_indices sort_indices_by_letter sort_indices elements_directions
+ merge_indices sort_indices elements_directions
elements_file_directions);
# $tree is a Texinfo document tree. $parser is a Texinfo::Parser object.
my $registrar = $parser->registered_errors();
@@ -1793,11 +1779,11 @@ Texinfo::Structuring - information on Texinfo::Parser
tree
= merge_indices($index_names);
my $index_entries_sorted;
if ($sort_by_letter) {
- $index_entries_sorted = sort_indices_by_letter($parser, $parser, $parser,
- $merged_index_entries, $index_names);
+ $index_entries_sorted = sort_indices($parser, $parser, $parser,
+ $merged_index_entries, 'by_letter');
} else {
$index_entries_sorted = sort_indices($parser, $parser, $parser,
- $merged_index_entries, $index_names);
+ $merged_index_entries);
}
@@ -1828,7 +1814,7 @@ set direction related to files, provided files are
associated with
elements by the user.
C<merge_indices> may be used to merge indices, which may be sorted
-with C<sort_indices> or C<sort_indices_by_letter> to sort by letters.
+with C<sort_indices>.
=head1 METHODS
@@ -2116,12 +2102,11 @@ The I<$merged_entries> returned is a hash reference
whose
keys are the index names and values arrays of index entry structures
described in details in L<Texinfo::Parser/index_entries>.
-=item $index_entries_sorted = sort_indices_by_letter($parser, $registrar,
$configuration_informations, $merged_index_entries, $index_names)
+=item ($index_entries_sorted, $index_entry_keys) = sort_indices($parser,
$registrar, $configuration_informations, $merged_index_entries, $sort_by_letter)
-=item $index_entries_sorted = sort_indices($parser, $registrar,
$configuration_informations, $merged_index_entries, $index_names)
-
-These functions first sets a plain text key for each index entry, used for
-sorting. In both cases, a hash reference with index names as keys is returned.
+If C<$sort_by_letter> is set, sort by letter, otherwise sort all
+entries together. In both cases, a hash reference with index names
+as keys C<$index_entries_sorted> is returned.
When sorting by letter, an array reference of letter hash references is
associated with each index name. Each letter hash reference has two
@@ -2131,6 +2116,9 @@ reference of sorted index entries beginning with the
letter.
When simply sorting, the array of the sorted index entries is associated
with the index name.
+C<$index_entry_keys> is a hash reference associating the index entries
+with the key that were used to sort them.
+
Register errors in C<$registrar>.
=back
diff --git a/tp/init/chm.pm b/tp/init/chm.pm
index 8479b9f..f11f50f 100644
--- a/tp/init/chm.pm
+++ b/tp/init/chm.pm
@@ -242,9 +242,9 @@ sub chm_init($)
}
print $hhk_fh "</OBJECT>\n";
- my $index_entries = Texinfo::Structuring::sort_indices($self->{'parser'},
- $self, $self, $self->{'index_entries'},
- $self->{'index_names'});
+ my ($index_entries, $index_entries_keys)
+ = Texinfo::Structuring::sort_indices($self->{'parser'},
+ $self, $self, $self->{'index_entries'});
if ($index_entries) {
foreach my $index_name (sort(keys(%$index_entries))) {
foreach my $index_entry_ref (@{$index_entries->{$index_name}}) {
diff --git a/tp/t/test_sort.t b/tp/t/test_sort.t
index 888ddbe..604470f 100644
--- a/tp/t/test_sort.t
+++ b/tp/t/test_sort.t
@@ -48,13 +48,13 @@ my $parser_informations = $parser->global_informations();
# holding only configuration that is not a parser
$parser->{'OUTPUT_ENCODING_NAME'} =
$parser_informations->{'input_encoding_name'};
$parser->{'ENABLE_ENCODING'} = 1;
-my $sorted_index_entries
+my ($sorted_index_entries, $index_entries_keys)
= Texinfo::Structuring::sort_indices($parser, $registrar, $parser,
- $index_entries, $index_names);
+ $index_entries);
my @entries = ();
foreach my $entry (@{$sorted_index_entries->{'cp'}}) {
- push @entries, $entry->{'key'};
+ push @entries, $index_entries_keys->{$entry};
}
use utf8;
@@ -64,9 +64,9 @@ my @entries_ref = ('!', '"', 'aaaaaaaaaaaa', 'e', 'E', 'ł',
'ẽ');
cmp_deeply (\@entries, \@entries_ref, 'sorted index entries');
-my $sorted_index_entries_by_letter
- = Texinfo::Structuring::sort_indices_by_letter($parser, $parser, $parser,
- $index_entries, $index_names);
+my ($sorted_index_entries_by_letter, $by_letter_index_entries_keys)
+ = Texinfo::Structuring::sort_indices($parser, $parser, $parser,
+ $index_entries, 'by_letter');
my @letter_entries_ref = (
{'!' => [ '!' ]},
@@ -79,11 +79,11 @@ my @letter_entries_ref = (
my @letter_entries;
foreach my $letter (@{$sorted_index_entries_by_letter->{'cp'}}) {
- #my $letter_entry = {'letter' => $letter->{'letter'}};
my $letter_entry = {};
push @letter_entries, $letter_entry;
foreach my $entry (@{$letter->{'entries'}}) {
- push @{$letter_entry->{$letter->{'letter'}}}, $entry->{'key'};
+ push @{$letter_entry->{$letter->{'letter'}}},
+ $by_letter_index_entries_keys->{$entry};
}
}
diff --git a/tp/t/test_utils.pl b/tp/t/test_utils.pl
index 0348faa..b20c264 100644
--- a/tp/t/test_utils.pl
+++ b/tp/t/test_utils.pl
@@ -784,23 +784,23 @@ sub test($$)
delete $parser_options->{'test_split'};
}
- # register that there is a tree transformation to do
- # in addition to passing to converter.
- my $simple_menus;
+ # this is a Structuring phase option, but also needed
+ # by converter, so set to converter, and use converter option
+ # to check for the option
if ($parser_options->{'SIMPLE_MENU'}) {
- $simple_menus = 1;
- if (!defined($converter_options->{'SIMPLE_MENU'})) {
- $converter_options->{'SIMPLE_MENU'} = 1;
- }
+ $converter_options->{'SIMPLE_MENU'} = 1;
delete $parser_options->{'SIMPLE_MENU'};
}
# always set FORMAT_MENU to menu, which is the default for parser
my $added_main_configurations = {'FORMAT_MENU' => 'menu'};
- if ($parser_options->{'CHECK_NORMAL_MENU_STRUCTURE'}) {
- $added_main_configurations->{'CHECK_NORMAL_MENU_STRUCTURE'}
- = $parser_options->{'CHECK_NORMAL_MENU_STRUCTURE'};
- delete $parser_options->{'CHECK_NORMAL_MENU_STRUCTURE'};
+ foreach my $structuring_option (('CHECK_NORMAL_MENU_STRUCTURE',
+ 'ENABLE_ENCODING')) {
+ if ($parser_options->{$structuring_option}) {
+ $added_main_configurations->{$structuring_option}
+ = $parser_options->{$structuring_option};
+ delete $parser_options->{$structuring_option};
+ }
}
my %todos;
@@ -854,8 +854,11 @@ sub test($$)
} else {
$result = $parser->parse_texi_file($test_file);
}
- my $registrar = $parser->registered_errors();
my $parser_informations = $parser->global_informations();
+
+ Texinfo::Common::set_output_encodings($main_configuration,
$parser_informations);
+
+ my $registrar = $parser->registered_errors();
my ($labels, $targets_list, $nodes_list) = $parser->labels_information();
my $refs = $parser->internal_references_information();
Texinfo::Structuring::associate_internal_references($registrar,
@@ -907,14 +910,14 @@ sub test($$)
$indices->{'index_names'} = $trimmed_index_names
unless (Data::Compare::Compare($trimmed_index_names,
$initial_index_names));
- my $sorted_index_entries;
+ my ($sorted_index_entries, $index_entries_keys);
if ($merged_index_entries) {
- $sorted_index_entries
- = Texinfo::Structuring::sort_indices_by_letter($parser, $registrar,
+ ($sorted_index_entries, $index_entries_keys)
+ = Texinfo::Structuring::sort_indices($parser, $registrar,
$main_configuration,
- $merged_index_entries, $index_names);
+ $merged_index_entries, 'by_letter');
}
- if ($simple_menus) {
+ if ($converter_options->{'SIMPLE_MENU'}) {
# require instead of use for speed when this module is not needed
require Texinfo::Transformations;
Texinfo::Transformations::set_menus_to_simple_menu($nodes_list);
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- branch master updated: * tp/Texinfo/Structuring.pm (sort_indices), tp/Texinfo/Convert/HTML.pm, tp/Texinfo/Convert/IXIN.pm, tp/Texinfo/Convert/Plaintext.pm, tp/init/chm.pm: merge sort_indices_by_letter() in sort_indices(). Merge do_index_keys() in sort_indices() too. Sort using especially created lists with entries informations. Do not use entry 'key' at all. Return keys used to sort entries as a hash reference.,
Patrice Dumas <=