[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
branch master updated: * tp/Texinfo/Convert/HTML.pm (_default_format_tit
From: |
Patrice Dumas |
Subject: |
branch master updated: * tp/Texinfo/Convert/HTML.pm (_default_format_title_titlepage): avoid intermediary variables. |
Date: |
Sat, 09 Dec 2023 14:15:29 -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 9912740c1f * tp/Texinfo/Convert/HTML.pm
(_default_format_title_titlepage): avoid intermediary variables.
9912740c1f is described below
commit 9912740c1fa69d55dbfbd4b88c3470273a91e609
Author: Patrice Dumas <pertusus@free.fr>
AuthorDate: Sat Dec 9 20:15:20 2023 +0100
* tp/Texinfo/Convert/HTML.pm (_default_format_title_titlepage): avoid
intermediary variables.
* tp/Texinfo/Convert/HTML.pm (_prepare_simpletitle, convert, output):
add _prepare_simpletitle.
* tp/Texinfo/Convert/HTML.pm (%XS_conversion_overrides),
tp/Texinfo/XS/convert/ConvertXS.xs (html_prepare_simpletitle),
tp/Texinfo/XS/convert/convert_html.c (html_prepare_simpletitle),
tp/Texinfo/XS/main/converter_types.h (CONVERTER): implement
html_prepare_simpletitle and an XS interface.
* tp/Texinfo/XS/convert/call_html_perl_function.c
(call_formatting_function_format_titlepage),
tp/Texinfo/XS/convert/convert_html.c (contents_shortcontents_in_title)
(format_titlepage, html_default_format_title_titlepage)
(format_title_titlepage, html_prepare_title_titlepage): have
format_title_titlepage return a char *. Add
contents_shortcontents_in_title,
call_formatting_function_format_titlepage and format_titlepage.
Implement html_default_format_title_titlepage in C.
---
ChangeLog | 24 ++++
tp/Texinfo/Convert/HTML.pm | 54 ++++-----
tp/Texinfo/XS/convert/ConvertXS.xs | 21 ++++
tp/Texinfo/XS/convert/call_html_perl_function.c | 55 +++++++++
tp/Texinfo/XS/convert/call_html_perl_function.h | 2 +
tp/Texinfo/XS/convert/convert_html.c | 146 +++++++++++++++++++++---
tp/Texinfo/XS/convert/convert_html.h | 1 +
tp/Texinfo/XS/main/converter_types.h | 2 +
tp/Texinfo/XS/main/utils.h | 2 +
9 files changed, 262 insertions(+), 45 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index c65e95fa1d..ec69885e19 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,27 @@
+2023-12-09 Patrice Dumas <pertusus@free.fr>
+
+ * tp/Texinfo/Convert/HTML.pm (_default_format_title_titlepage): avoid
+ intermediary variables.
+
+ * tp/Texinfo/Convert/HTML.pm (_prepare_simpletitle, convert, output):
+ add _prepare_simpletitle.
+
+ * tp/Texinfo/Convert/HTML.pm (%XS_conversion_overrides),
+ tp/Texinfo/XS/convert/ConvertXS.xs (html_prepare_simpletitle),
+ tp/Texinfo/XS/convert/convert_html.c (html_prepare_simpletitle),
+ tp/Texinfo/XS/main/converter_types.h (CONVERTER): implement
+ html_prepare_simpletitle and an XS interface.
+
+ * tp/Texinfo/XS/convert/call_html_perl_function.c
+ (call_formatting_function_format_titlepage),
+ tp/Texinfo/XS/convert/convert_html.c (contents_shortcontents_in_title)
+ (format_titlepage, html_default_format_title_titlepage)
+ (format_title_titlepage, html_prepare_title_titlepage): have
+ format_title_titlepage return a char *. Add
+ contents_shortcontents_in_title,
+ call_formatting_function_format_titlepage and format_titlepage.
+ Implement html_default_format_title_titlepage in C.
+
2023-12-09 Patrice Dumas <pertusus@free.fr>
* tp/Texinfo/XS/convert/convert_html.c
diff --git a/tp/Texinfo/Convert/HTML.pm b/tp/Texinfo/Convert/HTML.pm
index e16b46c03c..b75f43eb21 100644
--- a/tp/Texinfo/Convert/HTML.pm
+++ b/tp/Texinfo/Convert/HTML.pm
@@ -118,6 +118,8 @@ my %XS_conversion_overrides = (
=> "Texinfo::Convert::ConvertXS::html_initialize_output_state",
"Texinfo::Convert::HTML::_finalize_output_state"
=> "Texinfo::Convert::ConvertXS::html_finalize_output_state",
+ "Texinfo::Convert::HTML::_prepare_simpletitle"
+ => "Texinfo::Convert::ConvertXS::html_prepare_simpletitle",
"Texinfo::Convert::HTML::_register_id"
=> "Texinfo::Convert::ConvertXS::html_register_id",
@@ -7483,11 +7485,11 @@ sub _default_format_title_titlepage($)
{
my $self = shift;
- my $result = '';
if ($self->get_conf('SHOW_TITLE')) {
if ($self->get_conf('USE_TITLEPAGE_FOR_TITLE')) {
- $result .= &{$self->formatting_function('format_titlepage')}($self);
+ return &{$self->formatting_function('format_titlepage')}($self);
} else {
+ my $result = '';
my $simpletitle_tree = $self->get_info('simpletitle_tree');
if ($simpletitle_tree) {
my $simpletitle_command_name =
$self->get_info('simpletitle_command_name');
@@ -7498,9 +7500,10 @@ sub _default_format_title_titlepage($)
[$simpletitle_command_name], $title_text, 0);
}
$result .= $self->_contents_shortcontents_in_title();
+ return $result;
}
}
- return $result;
+ return '';
}
# Function for converting special output units
@@ -11325,6 +11328,22 @@ sub _html_convert_convert($$$$)
return $result;
}
+sub _prepare_simpletitle($)
+{
+ my $self = shift;
+ foreach my $simpletitle_command ('settitle', 'shorttitlepage') {
+ if ($self->{'global_commands'}->{$simpletitle_command}) {
+ my $command = $self->{'global_commands'}->{$simpletitle_command};
+ next if (!$command->{'args'} or !$command->{'args'}->[0]
+ or !$command->{'args'}->[0]->{'contents'}
+ or !scalar(@{$command->{'args'}->[0]->{'contents'}}));
+ $self->{'simpletitle_tree'} = $command->{'args'}->[0];
+ $self->{'simpletitle_command_name'} = $simpletitle_command;
+ last;
+ }
+ }
+}
+
sub convert($$)
{
my $self = shift;
@@ -11369,18 +11388,8 @@ sub convert($$)
# setup untranslated strings
$self->_translate_names();
- # FIXME duplicate of code in output()
- foreach my $simpletitle_command ('settitle', 'shorttitlepage') {
- if ($self->{'global_commands'}->{$simpletitle_command}) {
- my $command = $self->{'global_commands'}->{$simpletitle_command};
- next if (!$command->{'args'} or !$command->{'args'}->[0]
- or !$command->{'args'}->[0]->{'contents'}
- or !scalar(@{$command->{'args'}->[0]->{'contents'}}));
- $self->{'simpletitle_tree'} = $command->{'args'}->[0];
- $self->{'simpletitle_command_name'} = $simpletitle_command;
- last;
- }
- }
+ $self->_prepare_simpletitle();
+
$self->_reset_info();
# title. Not often set in the default case, as convert() is only
@@ -11980,6 +11989,9 @@ sub output($$)
# prepare title. fulltitle uses more possibility than simpletitle for
# title, including @-commands found in @titlepage only. Therefore
# simpletitle is more in line with what makeinfo in C did.
+
+ $self->_prepare_simpletitle();
+
my $fulltitle;
foreach my $fulltitle_command('settitle', 'title', 'shorttitlepage', 'top') {
if ($self->{'global_commands'}->{$fulltitle_command}) {
@@ -12002,18 +12014,6 @@ sub output($$)
->{'args'}->[0]->{'contents'}}) {
$fulltitle = $self->{'global_commands'}->{'titlefont'}->[0];
}
- # prepare simpletitle
- foreach my $simpletitle_command ('settitle', 'shorttitlepage') {
- if ($self->{'global_commands'}->{$simpletitle_command}) {
- my $command = $self->{'global_commands'}->{$simpletitle_command};
- next if (!$command->{'args'} or !$command->{'args'}->[0]
- or !$command->{'args'}->[0]->{'contents'}
- or !scalar(@{$command->{'args'}->[0]->{'contents'}}));
- $self->{'simpletitle_tree'} = $command->{'args'}->[0];
- $self->{'simpletitle_command_name'} = $simpletitle_command;
- last;
- }
- }
my $html_title_string;
if ($fulltitle) {
diff --git a/tp/Texinfo/XS/convert/ConvertXS.xs
b/tp/Texinfo/XS/convert/ConvertXS.xs
index 6eeab45870..2a0aa6ceb6 100644
--- a/tp/Texinfo/XS/convert/ConvertXS.xs
+++ b/tp/Texinfo/XS/convert/ConvertXS.xs
@@ -1125,6 +1125,27 @@ html_translate_names (SV *converter_in)
self->modified_state = 0;
}
+void
+html_prepare_simpletitle (SV *converter_in)
+ PREINIT:
+ CONVERTER *self = 0;
+ CODE:
+ self = get_sv_converter (converter_in, "html_prepare_simpletitle");
+ if (self)
+ {
+ html_prepare_simpletitle (self);
+ if (self->simpletitle_tree)
+ {
+ HV *converter_hv = (HV *) SvRV (converter_in);
+ hv_store (converter_hv, "simpletitle_tree",
+ strlen ("simpletitle_tree"),
+ newRV_inc ((SV *) self->simpletitle_tree->hv), 0);
+ hv_store (converter_hv, "simpletitle_command_name",
+ strlen ("simpletitle_command_name"),
+ newSVpv (builtin_command_name (self->simpletitle_cmd), 0),
0);
+ }
+ }
+
void
html_prepare_title_titlepage (SV *converter_in, SV *output_units_in,
output_file, output_filename)
diff --git a/tp/Texinfo/XS/convert/call_html_perl_function.c
b/tp/Texinfo/XS/convert/call_html_perl_function.c
index 3001956f65..98b8206903 100644
--- a/tp/Texinfo/XS/convert/call_html_perl_function.c
+++ b/tp/Texinfo/XS/convert/call_html_perl_function.c
@@ -694,7 +694,62 @@ call_file_id_setting_external_target_non_split_name
(CONVERTER *self,
+char *
+call_formatting_function_format_titlepage (CONVERTER *self,
+ const FORMATTING_REFERENCE *formatting_reference)
+{
+ int count;
+ char *result;
+ char *result_ret;
+ STRLEN len;
+ SV *result_sv;
+ SV *formatting_reference_sv;
+
+ dTHX;
+
+ if (!self->hv)
+ return 0;
+
+ formatting_reference_sv = formatting_reference->sv_reference;
+
+ if (self->modified_state)
+ {
+ build_html_formatting_state (self, self->modified_state);
+ self->modified_state = 0;
+ }
+
+ dSP;
+
+ ENTER;
+ SAVETMPS;
+ PUSHMARK(SP);
+ EXTEND(SP, 1);
+
+ PUSHs(sv_2mortal (newRV_inc (self->hv)));
+ PUTBACK;
+
+ count = call_sv (formatting_reference_sv,
+ G_SCALAR);
+
+ SPAGAIN;
+
+ if (count != 1)
+ croak("format_titlepage should return 1 item\n");
+
+ result_sv = POPs;
+ result_ret = SvPVutf8 (result_sv, len);
+ result = strdup (result_ret);
+
+ PUTBACK;
+
+ FREETMPS;
+ LEAVE;
+
+ get_shared_conversion_state (self);
+
+ return result;
+}
char *
call_formatting_function_format_title_titlepage (CONVERTER *self,
diff --git a/tp/Texinfo/XS/convert/call_html_perl_function.h
b/tp/Texinfo/XS/convert/call_html_perl_function.h
index c0cfd69369..f4e3c1d196 100644
--- a/tp/Texinfo/XS/convert/call_html_perl_function.h
+++ b/tp/Texinfo/XS/convert/call_html_perl_function.h
@@ -54,6 +54,8 @@ TARGET_FILENAME
*call_file_id_setting_external_target_non_split_name
const char *normalized, const ELEMENT *element,
const char *target, const char *file);
+char *call_formatting_function_format_titlepage (CONVERTER *self,
+ const FORMATTING_REFERENCE *formatting_reference);
char *call_formatting_function_format_title_titlepage (CONVERTER *self,
const FORMATTING_REFERENCE *formatting_reference);
char *call_formatting_function_format_protect_text (CONVERTER *self,
diff --git a/tp/Texinfo/XS/convert/convert_html.c
b/tp/Texinfo/XS/convert/convert_html.c
index e824d0f851..027da911bd 100644
--- a/tp/Texinfo/XS/convert/convert_html.c
+++ b/tp/Texinfo/XS/convert/convert_html.c
@@ -5397,20 +5397,6 @@ format_heading_text (CONVERTER *self, const enum
command_id cmd,
}
}
-void
-format_title_titlepage (CONVERTER *self, TEXT *result)
-{
- FORMATTING_REFERENCE *formatting_reference
- = &self->current_formatting_references[FR_format_title_titlepage];
- {
- char *title_titlepage
- = call_formatting_function_format_title_titlepage (self,
-
formatting_reference);
- text_append (result, title_titlepage);
- free (title_titlepage);
- }
-}
-
void
format_element_footer (CONVERTER *self,
const enum output_unit_type unit_type,
@@ -6678,6 +6664,112 @@ contents_inline_element (CONVERTER *self, const enum
command_id cmd,
return 0;
}
+void
+contents_shortcontents_in_title (CONVERTER *self, TEXT *result)
+{
+ if (self->document->sections_list
+ && self->document->sections_list->number > 0
+ && !strcmp (self->conf->CONTENTS_OUTPUT_LOCATION, "after_title"))
+ {
+ enum command_id contents_cmds[2] = {CM_shortcontents, CM_contents};
+ int i;
+ for (i = 0; i < 2; i++)
+ {
+ int contents_set = 0;
+ enum command_id cmd = contents_cmds[i];
+ COMMAND_OPTION_REF *contents_option_ref
+ = get_command_option (self->conf, cmd);
+ if (*(contents_option_ref->int_ref) > 0)
+ contents_set = 1;
+ free (contents_option_ref);
+ if (contents_set)
+ {
+ char *contents_text
+ = contents_inline_element (self, cmd, 0);
+ if (contents_text)
+ {
+ text_append (result, contents_text);
+ text_append (result, self->conf->DEFAULT_RULE);
+ text_append_n (result, "\n", 1);
+ free (contents_text);
+ }
+ }
+ }
+ }
+}
+
+char *
+format_titlepage (CONVERTER *self)
+{
+ FORMATTING_REFERENCE *formatting_reference
+ = &self->current_formatting_references[FR_format_titlepage];
+/*
+ if (formatting_reference->status == FRS_status_default_set)
+ {
+ return html_default_format_titlepage (self);
+ }
+ else
+ */
+ {
+ return call_formatting_function_format_titlepage (self,
+ formatting_reference);
+ }
+}
+
+char *
+html_default_format_title_titlepage (CONVERTER *self)
+{
+ if (self->conf->SHOW_TITLE > 0)
+ {
+ if (self->conf->USE_TITLEPAGE_FOR_TITLE)
+ {
+ return format_titlepage (self);
+ }
+ else
+ {
+ TEXT result;
+ text_init (&result);
+ text_append (&result, "");
+ if (self->simpletitle_tree)
+ {
+ char *title_text;
+ char *context_str;
+ STRING_LIST *classes;
+ enum command_id cmd = self->simpletitle_cmd;
+ classes = (STRING_LIST *) malloc (sizeof (STRING_LIST));
+ memset (classes, 0, sizeof (STRING_LIST));
+ add_string (builtin_command_name (cmd), classes);
+ xasprintf (&context_str, "%s simpletitle",
+ builtin_command_name (cmd));
+ title_text
+ = convert_tree_new_formatting_context (self,
+ self->simpletitle_tree, context_str, 0, 0, 0);
+ format_heading_text (self, cmd, classes, title_text,
+ 0, 0, 0, 0, &result);
+ destroy_strings_list (classes);
+ }
+ contents_shortcontents_in_title (self, &result);
+ }
+ }
+ return strdup ("");
+}
+
+char *
+format_title_titlepage (CONVERTER *self)
+{
+ FORMATTING_REFERENCE *formatting_reference
+ = &self->current_formatting_references[FR_format_title_titlepage];
+ if (formatting_reference->status == FRS_status_default_set)
+ {
+ return html_default_format_title_titlepage (self);
+ }
+ else
+ {
+ return call_formatting_function_format_title_titlepage (self,
+ formatting_reference);
+ }
+}
+
/* NOTE these switches are not done in perl, so the only perl functions
that can be callled are perl functions that do not call
formatting/conversion
functions or the formatting/conversion functions for HTML will be used. */
@@ -7740,6 +7832,27 @@ special_unit_body_formatting_external (CONVERTER *self,
output_unit, result);
}
+const static enum command_id simpletitle_cmds[] =
+ {CM_settitle, CM_shorttitlepage, 0};
+
+void
+html_prepare_simpletitle (CONVERTER *self)
+{
+ int i;
+ for (i = 0; simpletitle_cmds[i]; i++)
+ {
+ enum command_id cmd = simpletitle_cmds[i];
+ ELEMENT *command
+ = get_cmd_global_uniq_command (self->document->global_commands, cmd);
+ if (command && command->args.number > 0
+ && command->args.list[0]->contents.number > 0)
+ {
+ self->simpletitle_tree = command->args.list[0];
+ self->simpletitle_cmd = cmd;
+ }
+ }
+}
+
void
reset_translated_special_unit_info_tree (CONVERTER *self)
{
@@ -9969,7 +10082,6 @@ html_prepare_title_titlepage (CONVERTER *self, int
output_units_descriptor,
{
OUTPUT_UNIT_LIST *output_units
= retrieve_output_units (output_units_descriptor);
- TEXT title_titlepage;
if (strlen (output_file))
{
@@ -9988,9 +10100,7 @@ html_prepare_title_titlepage (CONVERTER *self, int
output_units_descriptor,
self->modified_state |= HMSF_current_filename;
- text_init (&title_titlepage);
- format_title_titlepage (self, &title_titlepage);
- self->title_titlepage = title_titlepage.text;
+ self->title_titlepage = format_title_titlepage (self);
memset (&self->current_filename, 0, sizeof (FILE_NUMBER_NAME));
self->modified_state |= HMSF_current_filename;
}
diff --git a/tp/Texinfo/XS/convert/convert_html.h
b/tp/Texinfo/XS/convert/convert_html.h
index a3af23ab68..796a77024a 100644
--- a/tp/Texinfo/XS/convert/convert_html.h
+++ b/tp/Texinfo/XS/convert/convert_html.h
@@ -118,6 +118,7 @@ void html_prepare_output_units_global_targets (CONVERTER
*self,
void html_translate_names (CONVERTER *self);
+void html_prepare_simpletitle (CONVERTER *self);
void html_prepare_title_titlepage (CONVERTER *self, int
output_units_descriptor,
char *output_file, char *output_filename);
diff --git a/tp/Texinfo/XS/main/converter_types.h
b/tp/Texinfo/XS/main/converter_types.h
index 4b18fb524d..7661a59f5f 100644
--- a/tp/Texinfo/XS/main/converter_types.h
+++ b/tp/Texinfo/XS/main/converter_types.h
@@ -682,6 +682,8 @@ typedef struct CONVERTER {
size_t *special_unit_file_indices; /* same for special output units */
PAGES_CSS_LIST page_css;
HTMLXREF_MANUAL_ELEMENT_WARNED_LIST check_htmlxref_already_warned;
+ ELEMENT *simpletitle_tree;
+ enum command_id simpletitle_cmd;
/* state only in C converter */
unsigned long modified_state; /* specifies which perl state to rebuild */
diff --git a/tp/Texinfo/XS/main/utils.h b/tp/Texinfo/XS/main/utils.h
index e2ed603440..fdd4860b25 100644
--- a/tp/Texinfo/XS/main/utils.h
+++ b/tp/Texinfo/XS/main/utils.h
@@ -242,6 +242,8 @@ ELEMENT *set_global_document_command (GLOBAL_COMMANDS
*global_commands,
enum command_location command_location);
ELEMENT_LIST *get_cmd_global_multi_command (GLOBAL_COMMANDS
*global_commands_ref,
enum command_id cmd);
+ELEMENT *get_cmd_global_uniq_command (GLOBAL_COMMANDS *global_commands_ref,
+ enum command_id cmd);
void html_free_button_specification_list (BUTTON_SPECIFICATION_LIST *buttons);
#endif
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- branch master updated: * tp/Texinfo/Convert/HTML.pm (_default_format_title_titlepage): avoid intermediary variables.,
Patrice Dumas <=