[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
branch master updated: * tp/Texinfo/Convert/HTML.pm (associate_pending_f
From: |
Patrice Dumas |
Subject: |
branch master updated: * tp/Texinfo/Convert/HTML.pm (associate_pending_formatted_inline_content): remove useless code. |
Date: |
Thu, 30 Nov 2023 18:22:13 -0500 |
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 d52e2311d0 * tp/Texinfo/Convert/HTML.pm
(associate_pending_formatted_inline_content): remove useless code.
d52e2311d0 is described below
commit d52e2311d0c667a0c6679e359ba80f62189ab894
Author: Patrice Dumas <pertusus@free.fr>
AuthorDate: Fri Dec 1 00:21:05 2023 +0100
* tp/Texinfo/Convert/HTML.pm
(associate_pending_formatted_inline_content): remove useless code.
* tp/Texinfo/Convert/HTML.pm
(register_pending_formatted_inline_content): do not register undef
inline_content.
* tp/Texinfo/Convert/HTML.pm
(cancel_pending_formatted_inline_content): fix prototype, simpler code
without intermediary array.
* tp/Texinfo/Convert/HTML.pm (%XS_conversion_overrides),
tp/Texinfo/XS/convert/ConvertXS.xs
(html_register_pending_formatted_inline_content)
(html_cancel_pending_formatted_inline_content)
(html_get_pending_formatted_inline_content)
(html_associate_pending_formatted_inline_content)
(html_get_associated_formatted_inline_content),
tp/Texinfo/XS/convert/convert_html.c
(html_register_pending_formatted_inline_content)
(html_cancel_pending_formatted_inline_content)
(html_get_pending_formatted_inline_content)
(html_associate_pending_formatted_inline_content)
(html_get_associated_formatted_inline_content),
tp/Texinfo/XS/main/converter_types.h (HTML_INLINE_CONTENT)
(HTML_INLINE_CONTENT_STACK, HTML_ASSOCIATED_INLINE_CONTENT)
(HTML_ASSOCIATED_INLINE_CONTENT_LIST, CONVERTER): implement
register_pending_formatted_inline_content,
cancel_pending_formatted_inline_content and
get_pending_formatted_inline_content in C and XS interface.
Implement associate_pending_formatted_inline_content and
get_associated_formatted_inline_content in C and XS interface.
---
ChangeLog | 35 ++++++++
tp/Texinfo/Convert/HTML.pm | 37 ++++++---
tp/Texinfo/XS/convert/ConvertXS.xs | 97 ++++++++++++++++++++++
tp/Texinfo/XS/convert/convert_html.c | 155 +++++++++++++++++++++++++++++++++++
tp/Texinfo/XS/convert/convert_html.h | 14 ++++
tp/Texinfo/XS/main/converter_types.h | 30 +++++++
6 files changed, 356 insertions(+), 12 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index d53cc4e2f7..765350d6bd 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,38 @@
+2023-11-30 Patrice Dumas <pertusus@free.fr>
+
+ * tp/Texinfo/Convert/HTML.pm
+ (associate_pending_formatted_inline_content): remove useless code.
+
+ * tp/Texinfo/Convert/HTML.pm
+ (register_pending_formatted_inline_content): do not register undef
+ inline_content.
+
+ * tp/Texinfo/Convert/HTML.pm
+ (cancel_pending_formatted_inline_content): fix prototype, simpler code
+ without intermediary array.
+
+ * tp/Texinfo/Convert/HTML.pm (%XS_conversion_overrides),
+ tp/Texinfo/XS/convert/ConvertXS.xs
+ (html_register_pending_formatted_inline_content)
+ (html_cancel_pending_formatted_inline_content)
+ (html_get_pending_formatted_inline_content)
+ (html_associate_pending_formatted_inline_content)
+ (html_get_associated_formatted_inline_content),
+ tp/Texinfo/XS/convert/convert_html.c
+ (html_register_pending_formatted_inline_content)
+ (html_cancel_pending_formatted_inline_content)
+ (html_get_pending_formatted_inline_content)
+ (html_associate_pending_formatted_inline_content)
+ (html_get_associated_formatted_inline_content),
+ tp/Texinfo/XS/main/converter_types.h (HTML_INLINE_CONTENT)
+ (HTML_INLINE_CONTENT_STACK, HTML_ASSOCIATED_INLINE_CONTENT)
+ (HTML_ASSOCIATED_INLINE_CONTENT_LIST, CONVERTER): implement
+ register_pending_formatted_inline_content,
+ cancel_pending_formatted_inline_content and
+ get_pending_formatted_inline_content in C and XS interface.
+ Implement associate_pending_formatted_inline_content and
+ get_associated_formatted_inline_content in C and XS interface.
+
2023-11-30 Gavin Smith <gavinsmith0123@gmail.com>
* tp/Texinfo/Convert/Plaintext.pm (format_contents):
diff --git a/tp/Texinfo/Convert/HTML.pm b/tp/Texinfo/Convert/HTML.pm
index 711bb357a9..ed14cf6814 100644
--- a/tp/Texinfo/Convert/HTML.pm
+++ b/tp/Texinfo/Convert/HTML.pm
@@ -134,6 +134,16 @@ my %XS_conversion_overrides = (
=> "Texinfo::Convert::ConvertXS::html_register_footnote",
"Texinfo::Convert::HTML::get_pending_footnotes",
=> "Texinfo::Convert::ConvertXS::html_get_pending_footnotes",
+ "Texinfo::Convert::HTML::register_pending_formatted_inline_content"
+ =>
"Texinfo::Convert::ConvertXS::html_register_pending_formatted_inline_content",
+ "Texinfo::Convert::HTML::cancel_pending_formatted_inline_content",
+ =>
"Texinfo::Convert::ConvertXS::html_cancel_pending_formatted_inline_content",
+ "Texinfo::Convert::HTML::get_pending_formatted_inline_content",
+ => "Texinfo::Convert::ConvertXS::html_get_pending_formatted_inline_content",
+ "Texinfo::Convert::HTML::associate_pending_formatted_inline_content"
+ =>
"Texinfo::Convert::ConvertXS::html_associate_pending_formatted_inline_content",
+ "Texinfo::Convert::HTML::get_associated_formatted_inline_content",
+ =>
"Texinfo::Convert::ConvertXS::html_get_associated_formatted_inline_content",
"Texinfo::Convert::HTML::_XS_get_index_entries_sorted_by_letter"
=> "Texinfo::Convert::ConvertXS::get_index_entries_sorted_by_letter",
"Texinfo::Convert::HTML::_XS_html_merge_index_entries"
@@ -1837,6 +1847,10 @@ sub register_pending_formatted_inline_content($$$)
my $category = shift;
my $inline_content = shift;
+ if (!defined($inline_content)) {
+ return;
+ }
+
if (not defined($self->{'pending_inline_content'})) {
$self->{'pending_inline_content'} = [];
}
@@ -1844,22 +1858,24 @@ sub register_pending_formatted_inline_content($$$)
}
# cancel only the first pending content for the category
-sub cancel_pending_formatted_inline_content($$$)
+sub cancel_pending_formatted_inline_content($$)
{
my $self = shift;
my $category = shift;
if (defined($self->{'pending_inline_content'})) {
- my @other_category_contents = ();
- while (@{$self->{'pending_inline_content'}}) {
- my $category_inline_content = pop @{$self->{'pending_inline_content'}};
- if ($category_inline_content->[0] eq $category) {
- push @{$self->{'pending_inline_content'}}, @other_category_contents;
- return $category_inline_content->[1];
+ my $pending_inline = $self->{'pending_inline_content'};
+ my $current_idx = scalar(@$pending_inline) - 1;
+ if ($current_idx >= 0) {
+ while ($current_idx >= 0) {
+ if ($pending_inline->[$current_idx]->[0] eq $category) {
+ my $removed = splice (@$pending_inline,
+ $current_idx, 1);
+ return $removed->[1];
+ }
+ $current_idx--;
}
- unshift @other_category_contents, $category_inline_content;
}
- push @{$self->{'pending_inline_content'}}, @other_category_contents;
}
return undef;
}
@@ -1889,9 +1905,6 @@ sub associate_pending_formatted_inline_content($$$) {
my $element = shift;
my $inline_content = shift;
- if (not $self->{'associated_inline_content'}->{$element}) {
- $self->{'associated_inline_content'}->{$element} = '';
- }
$self->{'associated_inline_content'}->{$element} .= $inline_content;
}
diff --git a/tp/Texinfo/XS/convert/ConvertXS.xs
b/tp/Texinfo/XS/convert/ConvertXS.xs
index 952c0e563f..724a5bde7c 100644
--- a/tp/Texinfo/XS/convert/ConvertXS.xs
+++ b/tp/Texinfo/XS/convert/ConvertXS.xs
@@ -512,7 +512,104 @@ html_get_pending_footnotes (SV *converter_in)
OUTPUT:
RETVAL
+void
+html_register_pending_formatted_inline_content (SV *converter_in, category,
...)
+ char *category = (char *)SvPVutf8_nolen($arg);
+ PROTOTYPE: $$$
+ PREINIT:
+ CONVERTER *self;
+ char *inline_content = 0;
+ CODE:
+ self = get_sv_converter (converter_in,
+ "html_register_pending_formatted_inline_content");
+ if (self)
+ {
+ if (items > 2 && SvOK(ST(2)))
+ inline_content = SvPVutf8_nolen (ST(2));
+ html_register_pending_formatted_inline_content (self,
+ category, inline_content);
+ }
+
+SV *
+html_cancel_pending_formatted_inline_content (SV *converter_in, category)
+ char *category = (char *)SvPVutf8_nolen($arg);
+ PREINIT:
+ CONVERTER *self;
+ char *inline_content = 0;
+ CODE:
+ self = get_sv_converter (converter_in,
+ "html_cancel_pending_formatted_inline_content");
+ if (self)
+ {
+ inline_content
+ = html_cancel_pending_formatted_inline_content (self, category);
+ }
+ if (inline_content)
+ {
+ RETVAL = newSVpv_utf8 (inline_content, 0);
+ free (inline_content);
+ }
+ else
+ RETVAL = newSV (0);
+ OUTPUT:
+ RETVAL
+
+SV *
+html_get_pending_formatted_inline_content (SV *converter_in)
+ PREINIT:
+ CONVERTER *self;
+ char *inline_content = 0;
+ CODE:
+ self = get_sv_converter (converter_in,
+ "html_get_pending_formatted_inline_content");
+ if (self)
+ {
+ inline_content = html_get_pending_formatted_inline_content (self);
+ }
+ if (inline_content)
+ {
+ RETVAL = newSVpv_utf8 (inline_content, 0);
+ free (inline_content);
+ }
+ else
+ RETVAL = newSV (0);
+ OUTPUT:
+ RETVAL
+
+void
+html_associate_pending_formatted_inline_content (SV *converter_in, SV
*element_sv, inline_content)
+ char *inline_content = (char *)SvPVutf8_nolen($arg);
+ PREINIT:
+ CONVERTER *self;
+ CODE:
+ self = get_sv_converter (converter_in,
+ "html_associate_pending_formatted_inline_content");
+ if (self)
+ {
+ html_associate_pending_formatted_inline_content (self,
+ 0, SvRV (element_sv), inline_content);
+ }
+
+SV *
+html_get_associated_formatted_inline_content (SV *converter_in, SV *element_sv)
+ PREINIT:
+ CONVERTER *self;
+ CODE:
+ self = get_sv_converter (converter_in,
+ "html_get_associated_formatted_inline_content");
+ if (self)
+ {
+ char *inline_content
+ = html_get_associated_formatted_inline_content (self,
+ 0, SvRV (element_sv));
+ RETVAL = newSVpv_utf8 (inline_content, 0);
+ free (inline_content);
+ }
+ else
+ RETVAL = newSV (0);
+ OUTPUT:
+ RETVAL
void
html_merge_index_entries (SV *converter_in)
diff --git a/tp/Texinfo/XS/convert/convert_html.c
b/tp/Texinfo/XS/convert/convert_html.c
index 3ad00a902b..63369f0c3b 100644
--- a/tp/Texinfo/XS/convert/convert_html.c
+++ b/tp/Texinfo/XS/convert/convert_html.c
@@ -709,6 +709,161 @@ destroy_pending_footnotes (HTML_PENDING_FOOTNOTE_STACK
*stack)
free (stack);
}
+void
+html_register_pending_formatted_inline_content (CONVERTER *self,
+ const char *category, const char *inline_content)
+{
+ HTML_INLINE_CONTENT *pending_content;
+ HTML_INLINE_CONTENT_STACK *stack;
+
+ if (!inline_content)
+ return;
+
+ stack = &self->pending_inline_content;
+ if (stack->top >= stack->space)
+ {
+ stack->stack
+ = realloc (stack->stack,
+ (stack->space += 5) * sizeof (HTML_INLINE_CONTENT));
+ }
+ pending_content = &stack->stack[stack->top];
+
+ pending_content->category = strdup (category);
+ pending_content->string = strdup (inline_content);
+
+ stack->top++;
+}
+
+/* cancel only the first pending content for the category */
+char *
+html_cancel_pending_formatted_inline_content (CONVERTER *self,
+ const char *category)
+{
+ HTML_INLINE_CONTENT_STACK *stack = &self->pending_inline_content;
+ if (stack->top)
+ {
+ size_t current_idx = stack->top - 1;
+ while (current_idx >= 0)
+ {
+ if (!strcmp (stack->stack[current_idx].category, category))
+ {
+ char *inline_content = stack->stack[current_idx].string;
+ free (stack->stack[current_idx].category);
+ if (current_idx < stack->top - 1)
+ {
+ memmove (&stack->stack[current_idx],
+ &stack->stack[current_idx+1],
+ sizeof (HTML_INLINE_CONTENT)
+ * (stack->top - (current_idx +1)));
+ }
+ stack->top--;
+ return inline_content;
+ }
+ }
+ }
+ return 0;
+}
+
+char *
+html_get_pending_formatted_inline_content (CONVERTER *self)
+{
+ HTML_INLINE_CONTENT_STACK *stack = &self->pending_inline_content;
+ if (stack->top)
+ {
+ TEXT result;
+ size_t i;
+ text_init (&result);
+ for (i = 0; i < stack->top; i++)
+ {
+ text_append (&result, stack->stack[i].string);
+ free (stack->stack[i].string);
+ free (stack->stack[i].category);
+ }
+ stack->top = 0;
+ return result.text;
+ }
+ else
+ return strdup ("");
+}
+
+/* API to associate inline content to an element, typically
+ paragraph or preformatted. Allows to associate the pending
+ content to the first inline element. */
+/* hv is used when called from perl, element when called from C */
+void
+html_associate_pending_formatted_inline_content (CONVERTER *self,
+ const ELEMENT *element,
+ const void *hv,
+ const char *inline_content)
+{
+ HTML_ASSOCIATED_INLINE_CONTENT_LIST *associated_content_list
+ = &self->associated_inline_content;
+ HTML_ASSOCIATED_INLINE_CONTENT *element_associated_content;
+ size_t i;
+ size_t element_associated_content_idx;
+ int empty_slot = 0;
+
+ for (i = 0; i < associated_content_list->number; i++)
+ {
+ if (associated_content_list->list[i].inline_content == 0)
+ {
+ empty_slot = 1;
+ element_associated_content_idx = i;
+ }
+ }
+
+ if (!empty_slot)
+ {
+ if (associated_content_list->number >= associated_content_list->space)
+ {
+ associated_content_list->list
+ = realloc (associated_content_list->list,
+ (associated_content_list->space += 5)
+ * sizeof (HTML_ASSOCIATED_INLINE_CONTENT));
+ }
+ element_associated_content_idx = associated_content_list->number;
+
+ associated_content_list->number++;
+ }
+ element_associated_content
+ = &associated_content_list->list[element_associated_content_idx];
+ element_associated_content->element = element;
+ element_associated_content->hv = hv;
+ element_associated_content->inline_content = strdup (inline_content);
+}
+
+/* hv is used when called from perl element when called from C */
+char *
+html_get_associated_formatted_inline_content (CONVERTER *self,
+ const ELEMENT *element,
+ void *hv)
+{
+ HTML_ASSOCIATED_INLINE_CONTENT_LIST *associated_content_list
+ = &self->associated_inline_content;
+ size_t i;
+ for (i = 0; i < associated_content_list->number; i++)
+ {
+ HTML_ASSOCIATED_INLINE_CONTENT *element_associated_content
+ = &associated_content_list->list[i];
+ if ((element && (element_associated_content->element == element
+ || (element->hv
+ && element_associated_content->hv == element->hv)))
+ || (hv && (element_associated_content->hv == hv
+ || (element_associated_content->element
+ && element_associated_content->element->hv == hv))))
+ {
+ char *result = element_associated_content->inline_content;
+ if (i == associated_content_list->number -1)
+ associated_content_list->number--;
+ else
+ memset (element_associated_content, 0,
+ sizeof (HTML_ASSOCIATED_INLINE_CONTENT));
+ return result;
+ }
+ }
+ return strdup ("");
+}
+
void
html_register_opened_section_level (CONVERTER *self, int level,
const char *close_string)
diff --git a/tp/Texinfo/XS/convert/convert_html.h
b/tp/Texinfo/XS/convert/convert_html.h
index eda6156699..6befce2a0e 100644
--- a/tp/Texinfo/XS/convert/convert_html.h
+++ b/tp/Texinfo/XS/convert/convert_html.h
@@ -44,6 +44,20 @@ void html_register_footnote (CONVERTER *self, const ELEMENT
*command,
HTML_PENDING_FOOTNOTE_STACK *html_get_pending_footnotes (CONVERTER *self);
void destroy_pending_footnotes (HTML_PENDING_FOOTNOTE_STACK *stack);
+void html_register_pending_formatted_inline_content (CONVERTER *self,
+ const char *category, const char *inline_content);
+char *html_cancel_pending_formatted_inline_content (CONVERTER *self,
+ const char *category);
+char *html_get_pending_formatted_inline_content (CONVERTER *self);
+
+void html_associate_pending_formatted_inline_content (CONVERTER *self,
+ const ELEMENT *element,
+ const void *hv,
+ const char *inline_content);
+char *html_get_associated_formatted_inline_content (CONVERTER *self,
+ const ELEMENT *element,
+ void *hv);
+
void html_merge_index_entries (CONVERTER *self);
void html_prepare_conversion_units (CONVERTER *self,
diff --git a/tp/Texinfo/XS/main/converter_types.h
b/tp/Texinfo/XS/main/converter_types.h
index 34f0b69e44..d9f4beaaba 100644
--- a/tp/Texinfo/XS/main/converter_types.h
+++ b/tp/Texinfo/XS/main/converter_types.h
@@ -510,6 +510,34 @@ typedef struct HTML_PENDING_FOOTNOTE_STACK {
HTML_PENDING_FOOTNOTE **stack;
} HTML_PENDING_FOOTNOTE_STACK;
+typedef struct HTML_INLINE_CONTENT {
+ char *category;
+ char *string;
+} HTML_INLINE_CONTENT;
+
+typedef struct HTML_INLINE_CONTENT_STACK {
+ size_t top;
+ size_t space;
+ HTML_INLINE_CONTENT *stack;
+} HTML_INLINE_CONTENT_STACK;
+
+/* there should be either a pointer to a C tree element in element,
+ if set from C, or a reference to a perl tree element in hv, if set
+ from perl */
+typedef struct HTML_ASSOCIATED_INLINE_CONTENT {
+ const ELEMENT *element;
+ /* perl element. This should be HV *hv,
+ but we don't want to include the Perl headers everywhere; */
+ const void *hv;
+ char *inline_content;
+} HTML_ASSOCIATED_INLINE_CONTENT;
+
+typedef struct HTML_ASSOCIATED_INLINE_CONTENT_LIST {
+ size_t number;
+ size_t space;
+ HTML_ASSOCIATED_INLINE_CONTENT *list;
+} HTML_ASSOCIATED_INLINE_CONTENT_LIST;
+
typedef struct CONVERTER {
int converter_descriptor;
/* perl converter. This should be HV *hv,
@@ -622,7 +650,9 @@ typedef struct CONVERTER {
CURRENT_FILE_INFO current_filename;
ELEMENT_LIST referred_command_stack;
HTML_SHARED_CONVERSION_STATE shared_conversion_state;
+ HTML_INLINE_CONTENT_STACK pending_inline_content;
HTML_PENDING_FOOTNOTE_STACK pending_footnotes;
+ HTML_ASSOCIATED_INLINE_CONTENT_LIST associated_inline_content;
/* state common with perl converter, not transmitted to perl */
int use_unicode_text;
} CONVERTER;
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- branch master updated: * tp/Texinfo/Convert/HTML.pm (associate_pending_formatted_inline_content): remove useless code.,
Patrice Dumas <=