[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[no subject]
From: |
Patrice Dumas |
Date: |
Sun, 22 Oct 2023 05:36:42 -0400 (EDT) |
branch: master
commit 359344fbd0cc69966162c3e3e1a9af005da4ad32
Author: Patrice Dumas <pertusus@free.fr>
AuthorDate: Sun Oct 22 11:36:30 2023 +0200
* doc/texi2any_api.texi (Customizing Output File Names),
tp/Texinfo/Convert/HTML.pm (_get_top_unit, unit_is_top_output_unit)
(_prepare_output_units_global_targets),
tp/Texinfo/XS/convert/convert_html.c (get_top_unit)
(prepare_output_units_global_targets): add get_top_unit, based on
_prepare_output_units_global_targets code, to find the top unit, with
output_units set as an optional argument, such that if not set, the
first output unit is not considered as a top output unit. Use
_get_top_unit in unit_is_top_output_unit, without output_units
argument.
* tp/t/init/misc_file_collision.init: add variables to distinguish
input and output, no functional change.
---
ChangeLog | 16 +++++++++++
doc/texi2any_api.texi | 3 +-
tp/Texinfo/Convert/HTML.pm | 56 ++++++++++++++++++++----------------
tp/Texinfo/XS/convert/convert_html.c | 33 +++++++++++++++------
tp/t/init/misc_file_collision.init | 11 ++++---
5 files changed, 80 insertions(+), 39 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 474bbf70eb..c3bdd50532 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -5,6 +5,22 @@
doing it in add_text instead (as is done in the corresponding
XS code).
+2023-10-21 Patrice Dumas <pertusus@free.fr>
+
+ * doc/texi2any_api.texi (Customizing Output File Names),
+ tp/Texinfo/Convert/HTML.pm (_get_top_unit, unit_is_top_output_unit)
+ (_prepare_output_units_global_targets),
+ tp/Texinfo/XS/convert/convert_html.c (get_top_unit)
+ (prepare_output_units_global_targets): add get_top_unit, based on
+ _prepare_output_units_global_targets code, to find the top unit, with
+ output_units set as an optional argument, such that if not set, the
+ first output unit is not considered as a top output unit. Use
+ _get_top_unit in unit_is_top_output_unit, without output_units
+ argument.
+
+ * tp/t/init/misc_file_collision.init: add variables to distinguish
+ input and output, no functional change.
+
2023-10-21 Patrice Dumas <pertusus@free.fr>
* tp/Texinfo/XS/convert/converter.c,
diff --git a/doc/texi2any_api.texi b/doc/texi2any_api.texi
index c0136f1cb9..a95cfade07 100644
--- a/doc/texi2any_api.texi
+++ b/doc/texi2any_api.texi
@@ -1930,8 +1930,7 @@ in the destination directory.
@end deftypefn
In the user defined functions, the information that an output unit
-is associated with @code{@@top} or @code{@@node Top} or more generally
-considered to be the Top element may be determined with
+is associated with @code{@@top} or @code{@@node Top} may be determined with:
@example
$converter->unit_is_top_output_unit(\%output_unit);
@end example
diff --git a/tp/Texinfo/Convert/HTML.pm b/tp/Texinfo/Convert/HTML.pm
index 94320bcf88..8ff6497fd9 100644
--- a/tp/Texinfo/Convert/HTML.pm
+++ b/tp/Texinfo/Convert/HTML.pm
@@ -1571,17 +1571,42 @@ sub special_unit_info($$$) {
# API for misc conversion and formatting functions
+# if $OUTPUT_UNITS is defined, the first output unit is used if a proper
+# top output unit is not found.
+sub _get_top_unit($;$)
+{
+ my $self = shift;
+ my $output_units = shift;
+
+ my $node_top;
+ $node_top = $self->{'identifiers_target'}->{'Top'}
+ if ($self->{'identifiers_target'});
+ my $section_top;
+ $section_top = $self->{'global_commands'}->{'top'}
+ if ($self->{'global_commands'});
+ if ($section_top) {
+ return $section_top->{'associated_unit'};
+ } elsif ($node_top) {
+ my $top_output_unit = $node_top->{'associated_unit'};
+ if (!$top_output_unit) {
+ die "No associated unit for node_top: "
+ .Texinfo::Common::debug_print_element($node_top, 1);
+ }
+ return $top_output_unit;
+ } elsif (defined($output_units)) {
+ return $output_units->[0];
+ }
+ return undef;
+}
+
# it is considered 'top' only if element corresponds to @top or
# element is a node
sub unit_is_top_output_unit($$)
{
my $self = shift;
my $output_unit = shift;
- my $top_output_unit = $self->global_direction_unit('Top');
- return (defined($top_output_unit) and $top_output_unit eq $output_unit
- and $output_unit->{'unit_command'}
- and ($output_unit->{'unit_command'}->{'cmdname'} eq 'node'
- or $output_unit->{'unit_command'}->{'cmdname'} eq 'top'));
+ my $top_output_unit = _get_top_unit($self);
+ return (defined($top_output_unit) and $top_output_unit eq $output_unit);
}
my %default_formatting_references;
@@ -9619,25 +9644,8 @@ sub _prepare_output_units_global_targets($$$$)
$self->{'global_units_directions'}->{'First'} = $output_units->[0];
$self->{'global_units_directions'}->{'Last'} = $output_units->[-1];
- my $node_top;
- $node_top = $self->{'identifiers_target'}->{'Top'}
- if ($self->{'identifiers_target'});
- my $section_top;
- $section_top = $self->{'global_commands'}->{'top'}
- if ($self->{'global_commands'});
- if ($section_top) {
- $self->{'global_units_directions'}->{'Top'}
- = $section_top->{'associated_unit'};
- } elsif ($node_top) {
- my $top_output_unit = $node_top->{'associated_unit'};
- if (!$top_output_unit) {
- die "No associated unit for node_top: "
- .Texinfo::Common::debug_print_element($node_top, 1);
- }
- $self->{'global_units_directions'}->{'Top'} = $top_output_unit;
- } else {
- $self->{'global_units_directions'}->{'Top'} = $output_units->[0];
- }
+ $self->{'global_units_directions'}->{'Top'}
+ = _get_top_unit($self, $output_units);
# It is always the first printindex, even if it is not output (for example
# it is in @copying and @titlepage, which are certainly wrong constructs).
diff --git a/tp/Texinfo/XS/convert/convert_html.c
b/tp/Texinfo/XS/convert/convert_html.c
index e8b24539b2..33c40757b3 100644
--- a/tp/Texinfo/XS/convert/convert_html.c
+++ b/tp/Texinfo/XS/convert/convert_html.c
@@ -42,6 +42,27 @@ typedef struct ROOT_AND_UNIT {
ELEMENT *root;
} ROOT_AND_UNIT;
+/*
+ if OUTPUT_UNITS is defined, the first output unit is used if a proper
+ top output unit is not found.
+ */
+static OUTPUT_UNIT *
+get_top_unit (DOCUMENT *document, OUTPUT_UNIT_LIST *output_units)
+{
+ ELEMENT *node_top = find_identifier_target
+ (document->identifiers_target, "Top");
+ ELEMENT *section_top = document->global_commands->top;
+
+ if (section_top)
+ return section_top->associated_unit;
+ else if (node_top)
+ return node_top->associated_unit;
+ else if (output_units)
+ return output_units->list[0];
+
+ return 0;
+}
+
/*
If FIND_CONTAINER is set, the element that holds the command output
is found, otherwise the element that holds the command is found. This is
@@ -1457,9 +1478,8 @@ prepare_output_units_global_targets (CONVERTER *self,
int s = 0;
OUTPUT_UNIT_LIST *output_units
= retrieve_output_units (output_units_descriptor);
- ELEMENT *node_top = find_identifier_target
- (self->document->identifiers_target, "Top");
- ELEMENT *section_top = self->document->global_commands->top;
+
+ OUTPUT_UNIT *top_output_unit = get_top_unit (self->document, output_units);
int special_output_units_lists[2] = {special_units_descriptor,
associated_special_units_descriptor};
@@ -1468,12 +1488,7 @@ prepare_output_units_global_targets (CONVERTER *self,
self->global_units_directions[D_Last]
= output_units->list[output_units->number - 1];
- if (section_top)
- self->global_units_directions[D_Top] = section_top->associated_unit;
- else if (node_top)
- self->global_units_directions[D_Top] = node_top->associated_unit;
- else
- self->global_units_directions[D_Top] = output_units->list[0];
+ self->global_units_directions[D_Top] = top_output_unit;
/* It is always the first printindex, even if it is not output (for example
it is in @copying and @titlepage, which are certainly wrong constructs).
diff --git a/tp/t/init/misc_file_collision.init
b/tp/t/init/misc_file_collision.init
index bd1ed30938..7dbeaf8d43 100644
--- a/tp/t/init/misc_file_collision.init
+++ b/tp/t/init/misc_file_collision.init
@@ -7,11 +7,12 @@ sub test_misc_file_name($$$$)
{
my $converter = shift;
my $output_unit = shift;
- my $filename = shift;
- my $filepath = shift;
+ my $input_filename = shift;
+ my $input_filepath = shift;
- return ($filename, $filepath) if (defined($filepath));
+ return ($input_filename, $input_filepath) if (defined($input_filepath));
+ my $filename;
if ($converter->unit_is_top_output_unit($output_unit)
or ($converter->{'document_units'}->[2]
and $converter->{'document_units'}->[2] eq $output_unit)) {
@@ -19,8 +20,10 @@ sub test_misc_file_name($$$$)
my $prefix = $converter->{'document_name'};
$filename = "${prefix}_abt"
. ((defined($extension)) ? ".$extension" : '');
+ } else {
+ $filename = $input_filename;
}
- return ($filename, $filepath);
+ return ($filename, $input_filepath);
}
texinfo_set_from_init_file('DO_ABOUT', 1);