[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[no subject]
From: |
Patrice Dumas |
Date: |
Wed, 6 Dec 2023 15:25:38 -0500 (EST) |
branch: master
commit 704600f97483f4b01cbb49dc49695e3b338d9725
Author: Patrice Dumas <pertusus@free.fr>
AuthorDate: Tue Dec 5 10:36:31 2023 +0100
* tp/Texinfo/Convert/HTML.pm (_register_id, _id_is_registered)
(%XS_conversion_overrides), tp/Texinfo/XS/convert/ConvertXS.xs
(html_register_id, html_id_is_registered): access 'seen_ids' through
functions, _register_id and _id_is_registered. Add overrides for
those functions.
---
ChangeLog | 8 +++++++
tp/Texinfo/Convert/HTML.pm | 46 +++++++++++++++++++++++++++++---------
tp/Texinfo/XS/convert/ConvertXS.xs | 25 +++++++++++++++++++++
3 files changed, 68 insertions(+), 11 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 2490f6f1f0..f22aa722fd 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2023-12-05 Patrice Dumas <pertusus@free.fr>
+
+ * tp/Texinfo/Convert/HTML.pm (_register_id, _id_is_registered)
+ (%XS_conversion_overrides), tp/Texinfo/XS/convert/ConvertXS.xs
+ (html_register_id, html_id_is_registered): access 'seen_ids' through
+ functions, _register_id and _id_is_registered. Add overrides for
+ those functions.
+
2023-12-05 Patrice Dumas <pertusus@free.fr>
* tp/Texinfo/Convert/HTML.pm (_unique_target)
diff --git a/tp/Texinfo/Convert/HTML.pm b/tp/Texinfo/Convert/HTML.pm
index c0352a26cf..ceaf7b33fb 100644
--- a/tp/Texinfo/Convert/HTML.pm
+++ b/tp/Texinfo/Convert/HTML.pm
@@ -119,6 +119,11 @@ my %XS_conversion_overrides = (
"Texinfo::Convert::HTML::_finalize_output_state"
=> "Texinfo::Convert::ConvertXS::html_finalize_output_state",
+ "Texinfo::Convert::HTML::_register_id"
+ => "Texinfo::Convert::ConvertXS::html_register_id",
+ "Texinfo::Convert::HTML::_id_is_registered"
+ => "Texinfo::Convert::ConvertXS::html_id_is_registered",
+
"Texinfo::Convert::HTML::_open_command_update_context"
=> "Texinfo::Convert::ConvertXS::html_open_command_update_context",
"Texinfo::Convert::HTML::_convert_command_update_context",
@@ -9027,13 +9032,31 @@ sub _normalized_label_id_file($$$)
return ($filename, $target);
}
+sub _register_id($$)
+{
+ my $self = shift;
+ my $id = shift;
+ $self->{'seen_ids'}->{$id} = 1;
+}
+
+sub _id_is_registered($$)
+{
+ my $self = shift;
+ my $id = shift;
+ if ($self->{'seen_ids'}->{$id}) {
+ return 1;
+ } else {
+ return 0;
+ }
+}
+
sub _unique_target($$)
{
my $self = shift;
my $target_base = shift;
my $nr=1;
my $target = $target_base;
- while ($self->{'seen_ids'}->{$target}) {
+ while (_id_is_registered($self, $target)) {
$target = $target_base.'-'.$nr;
$nr++;
# Avoid integer overflow
@@ -9095,17 +9118,17 @@ sub _new_sectioning_command_target($$)
'target' => $target,
'section_filename' => $filename,
};
- $self->{'seen_ids'}->{$target} = 1;
+ _register_id($self, $target);
if (defined($target_contents)) {
$self->{'targets'}->{$command}->{'contents_target'} = $target_contents;
- $self->{'seen_ids'}->{$target_contents} = 1;
+ _register_id($self, $target_contents);
} else {
$self->{'targets'}->{$command}->{'contents_target'} = '';
}
if (defined($target_shortcontents)) {
$self->{'targets'}->{$command}->{'shortcontents_target'}
= $target_shortcontents;
- $self->{'seen_ids'}->{$target_shortcontents} = 1;
+ _register_id($self, $target_shortcontents);
} else {
$self->{'targets'}->{$command}->{'shortcontents_target'} = '';
}
@@ -9166,7 +9189,7 @@ sub _set_root_commands_targets_node_files($)
}
$self->{'targets'}->{$target_element} = {'target' => $target,
'node_filename' => $node_filename};
- $self->{'seen_ids'}->{$target} = 1;
+ _register_id($self, $target);
}
}
@@ -9860,7 +9883,7 @@ sub _set_special_units_targets_files($$$)
$self->{'targets'}->{$unit_command} = {'target' => $target,
'special_unit_filename' => $filename,
};
- $self->{'seen_ids'}->{$target} = 1;
+ _register_id($self, $target);
}
}
@@ -9906,7 +9929,7 @@ sub _prepare_associated_special_units_targets($$)
my $command_target = {'target' => $target};
$self->{'targets'}->{$unit_command} = $command_target;
if (defined($target)) {
- $self->{'seen_ids'}->{$target} = 1;
+ _register_id($self, $target);
}
if (defined ($filename)) {
$command_target->{'special_unit_filename'}
@@ -10072,7 +10095,7 @@ sub _prepare_index_entries_targets($)
$normalize_index_element, $no_unidecode);
my $target_base = "index-" . $region .$normalized_index;
my $target = _unique_target($self, $target_base);
- $self->{'seen_ids'}->{$target} = 1;
+ _register_id($self, $target);
my $target_element = $main_entry_element;
$target_element = $index_entry->{'entry_associated_element'}
if ($index_entry->{'entry_associated_element'});
@@ -10098,15 +10121,16 @@ sub _prepare_footnotes_targets($)
my $footid = $footid_base.$nr;
# anchor for the location of the @footnote in the document
my $docid = $docid_base.$nr;
- while ($self->{'seen_ids'}->{$docid} or $self->{'seen_ids'}->{$footid}) {
+ while (_id_is_registered($self, $docid)
+ or _id_is_registered($self, $footid)) {
$nr++;
$footid = $footid_base.$nr;
$docid = $docid_base.$nr;
# Avoid integer overflow
die if ($nr == 0);
}
- $self->{'seen_ids'}->{$footid} = 1;
- $self->{'seen_ids'}->{$docid} = 1;
+ _register_id($self, $footid);
+ _register_id($self, $docid);
$self->{'targets'}->{$footnote} = { 'target' => $footid };
$self->{'special_targets'}->{'footnote_location'}->{$footnote}
= { 'target' => $docid };
diff --git a/tp/Texinfo/XS/convert/ConvertXS.xs
b/tp/Texinfo/XS/convert/ConvertXS.xs
index 870dfab5f2..e5e50afad1 100644
--- a/tp/Texinfo/XS/convert/ConvertXS.xs
+++ b/tp/Texinfo/XS/convert/ConvertXS.xs
@@ -228,6 +228,31 @@ html_finalize_output_state (SV *converter_in)
html_check_transfer_state_finalization (self);
}
+void
+html_register_id (SV *converter_in, id)
+ char *id = (char *)SvPVutf8_nolen($arg);
+ PREINIT:
+ CONVERTER *self;
+ CODE:
+ self = get_sv_converter (converter_in, "html_register_id");
+ if (self)
+ /* note that we do not care about having the same id twice */
+ add_string (id, &self->seen_ids);
+
+
+int html_id_is_registered (SV *converter_in, id)
+ char *id = (char *)SvPVutf8_nolen($arg);
+ PREINIT:
+ CONVERTER *self;
+ int found = 0;
+ CODE:
+ self = get_sv_converter (converter_in, "html_id_is_registered");
+ if (self)
+ found = find_string (&self->seen_ids, id);
+ RETVAL = found;
+ OUTPUT:
+ RETVAL
+
void
html_new_document_context (SV *converter_in, char *context_name, ...)
PROTOTYPE: $$;$$
- master updated (649b0b3021 -> d6d18fe56e), Patrice Dumas, 2023/12/06
- [no subject],
Patrice Dumas <=
- [no subject], Patrice Dumas, 2023/12/06
- [no subject], Patrice Dumas, 2023/12/06
- [no subject], Patrice Dumas, 2023/12/06
- [no subject], Patrice Dumas, 2023/12/06
- [no subject], Patrice Dumas, 2023/12/06