[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
branch master updated: * tp/Texinfo/Convert/HTML.pm (_html_convert_outpu
From: |
Patrice Dumas |
Subject: |
branch master updated: * tp/Texinfo/Convert/HTML.pm (_html_convert_output), tp/Texinfo/XS/convert/convert_html.c (html_convert_output): only consider two cases for filenames, no filenames if output_file is the empty string '', filenames otherwise. |
Date: |
Thu, 02 Nov 2023 05:47:51 -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 50fb0e9812 * tp/Texinfo/Convert/HTML.pm (_html_convert_output),
tp/Texinfo/XS/convert/convert_html.c (html_convert_output): only consider two
cases for filenames, no filenames if output_file is the empty string '',
filenames otherwise.
50fb0e9812 is described below
commit 50fb0e9812011252449e5622e2fc122ae79da46a
Author: Patrice Dumas <pertusus@free.fr>
AuthorDate: Thu Nov 2 10:47:43 2023 +0100
* tp/Texinfo/Convert/HTML.pm (_html_convert_output),
tp/Texinfo/XS/convert/convert_html.c (html_convert_output): only
consider two cases for filenames, no filenames if output_file is the
empty string '', filenames otherwise.
* tp/Texinfo/Convert/HTML.pm (_html_convert_output, import)
(_XS_html_prepare_title_titlepage, _prepare_title_titlepage, convert),
tp/Texinfo/XS/convert/ConvertXS.xs (html_prepare_title_titlepage),
tp/Texinfo/XS/convert/convert_html.c (html_prepare_title_titlepage)
(html_convert_output): separate setting titlepage from main
conversion, removing code from html_convert_output to put it in
*_prepare_title_titlepage, replacing html_convert_init and
_XS_html_convert_init for convert.
* tp/Texinfo/XS/main/call_perl_function.c
(call_formatting_function_format_title_titlepage): call
build_html_formatting_state if needed.
---
ChangeLog | 20 +++++
tp/Texinfo/Convert/HTML.pm | 148 ++++++++++++--------------------
tp/Texinfo/XS/convert/ConvertXS.xs | 41 ++++++---
tp/Texinfo/XS/convert/convert_html.c | 82 ++++++------------
tp/Texinfo/XS/convert/convert_html.h | 3 +-
tp/Texinfo/XS/main/call_perl_function.c | 6 ++
6 files changed, 141 insertions(+), 159 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 4474101095..3c3b32a2e5 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,23 @@
+2023-11-02 Patrice Dumas <pertusus@free.fr>
+
+ * tp/Texinfo/Convert/HTML.pm (_html_convert_output),
+ tp/Texinfo/XS/convert/convert_html.c (html_convert_output): only
+ consider two cases for filenames, no filenames if output_file is the
+ empty string '', filenames otherwise.
+
+ * tp/Texinfo/Convert/HTML.pm (_html_convert_output, import)
+ (_XS_html_prepare_title_titlepage, _prepare_title_titlepage, convert),
+ tp/Texinfo/XS/convert/ConvertXS.xs (html_prepare_title_titlepage),
+ tp/Texinfo/XS/convert/convert_html.c (html_prepare_title_titlepage)
+ (html_convert_output): separate setting titlepage from main
+ conversion, removing code from html_convert_output to put it in
+ *_prepare_title_titlepage, replacing html_convert_init and
+ _XS_html_convert_init for convert.
+
+ * tp/Texinfo/XS/main/call_perl_function.c
+ (call_formatting_function_format_title_titlepage): call
+ build_html_formatting_state if needed.
+
2023-11-01 Patrice Dumas <pertusus@free.fr>
* tp/Makefile.tres, tp/t/languages.t
diff --git a/tp/Texinfo/Convert/HTML.pm b/tp/Texinfo/Convert/HTML.pm
index 8859416628..44bdd4571c 100644
--- a/tp/Texinfo/Convert/HTML.pm
+++ b/tp/Texinfo/Convert/HTML.pm
@@ -125,8 +125,8 @@ sub import {
"Texinfo::Convert::HTML::_XS_translate_names",
"Texinfo::Convert::ConvertXS::html_translate_names");
Texinfo::XSLoader::override(
- "Texinfo::Convert::HTML::_XS_html_convert_init",
- "Texinfo::Convert::ConvertXS::html_convert_init");
+ "Texinfo::Convert::HTML::_XS_html_prepare_title_titlepage",
+ "Texinfo::Convert::ConvertXS::html_prepare_title_titlepage");
Texinfo::XSLoader::override(
"Texinfo::Convert::HTML::_XS_html_convert_convert",
"Texinfo::Convert::ConvertXS::html_convert_convert");
@@ -11062,6 +11062,41 @@ sub _XS_html_convert_convert($$$$)
{
}
+sub _XS_html_prepare_title_titlepage($$$$)
+{
+}
+
+sub _prepare_title_titlepage($$$$)
+{
+ my $self = shift;
+ my $output_units = shift;
+ my $output_file = shift;
+ my $output_filename = shift;
+
+ if ($self->{'converter_descriptor'} and $XS_convert) {
+ my $encoded_output_filename = Encode::encode('UTF-8', $output_filename);
+ my $encoded_output_file = Encode::encode('UTF-8', $output_file);
+ _XS_html_prepare_title_titlepage($self, $output_units,
+ $encoded_output_file, $encoded_output_filename);
+ return;
+ }
+
+ # set file name to be the first file name for formatting of title page.
+ # The title page prepared here is thus only fit to be used in the first
+ # output unit.
+ if ($output_file ne '') {
+ $self->{'current_filename'}
+ = $output_units->[0]->{'unit_filename'};
+ } else {
+ $self->{'current_filename'} = $output_filename;
+ }
+
+ # title
+ $self->{'title_titlepage'}
+ = &{$self->formatting_function('format_title_titlepage')}($self);
+ $self->{'current_filename'} = undef;
+}
+
sub convert($$)
{
my $self = shift;
@@ -11074,9 +11109,6 @@ sub convert($$)
$self->_initialize_output_state();
- # needed for CSS rules gathering
- $self->{'current_filename'} = '';
-
# the presence of contents elements in the document is used in diverse
# places, set it once for all here
my @contents_elements_options
@@ -11131,16 +11163,7 @@ sub convert($$)
# title. Not often set in the default case, as convert() is only
# used in the *.t tests, and a title requires both simpletitle_tree
# and SHOW_TITLE set, with the default formatting function.
- if ($self->{'converter_descriptor'} and $XS_convert) {
- # FIXME distinguish failure and no title? Could actually use
- # undef for failure, as without title, return an empty string.
- my $title_titlepage =
- _XS_html_convert_init($encoded_converter);
- $self->{'title_titlepage'} = $title_titlepage;
- } else {
- $self->{'title_titlepage'}
- = &{$self->formatting_function('format_title_titlepage')}($self);
- }
+ $self->_prepare_title_titlepage($output_units, '', '');
# complete information should be available.
$self->_reset_info();
@@ -11151,6 +11174,8 @@ sub convert($$)
return $XS_result;
}
+ $self->{'current_filename'} = '';
+
if (!defined($output_units)) {
print STDERR "\nC NO UNIT\n" if ($self->get_conf('DEBUG'));
$result = $self->_convert($root, 'convert no unit');
@@ -11168,6 +11193,7 @@ sub convert($$)
$unit_nr++;
}
}
+ $self->{'current_filename'} = undef;
return $result;
}
@@ -11437,75 +11463,17 @@ sub _html_convert_output($$$$$$$$)
= Encode::encode('UTF-8', $destination_directory);
my $encoded_output_filename = Encode::encode('UTF-8', $output_filename);
- my $XS_result
+ my $XS_text_output
= _XS_html_convert_output ($encoded_converter,
$root, $output_units, $special_units,
$encoded_output_file,
$encoded_destination_directory, $encoded_output_filename,
$encoded_document_name);
- return $XS_result;
+ return $XS_text_output;
}
my $text_output = '';
-
- # determine first file name
- if (!$output_units
- or !defined($output_units->[0]->{'unit_filename'})) {
- # no page
- # NOTE there are always output units. There is always a file if files
- # are setup, so this situation can only arise with output_file equal to ''
- # as in that case files are not setup at all.
- if ($output_file ne '') {
- # This should not be possible.
- my $no_page_output_filename;
- if ($self->get_conf('SPLIT')) {
- $no_page_output_filename = $self->top_node_filename($document_name);
- $self->set_file_path($no_page_output_filename, $destination_directory);
- } else {
- $no_page_output_filename = $output_filename;
- $self->set_file_path($no_page_output_filename, undef, $output_file);
- }
-
- $self->{'current_filename'} = $no_page_output_filename;
- } else {
- $self->{'current_filename'} = $output_filename;
- }
- } else {
- $self->{'current_filename'}
- = $output_units->[0]->{'unit_filename'};
- }
- # title
- $self->{'title_titlepage'}
- = &{$self->formatting_function('format_title_titlepage')}($self);
-
- # complete information should be available.
- $self->_reset_info();
-
- if (!$output_units
- or !defined($output_units->[0]->{'unit_filename'})) {
- my $fh;
- my $encoded_no_page_out_filepath;
- my $no_page_out_filepath;
- # current_filename eq '' and no output files should be the only
- # possibility, see comment above.
- if ($self->{'current_filename'} ne ''
- and $self->{'out_filepaths'}
- and defined($self->{'out_filepaths'}->{$self->{'current_filename'}})) {
- my $path_encoding;
- $no_page_out_filepath
- = $self->{'out_filepaths'}->{$self->{'current_filename'}};
- ($encoded_no_page_out_filepath, $path_encoding)
- = $self->encoded_output_file_name($no_page_out_filepath);
- my $error_message;
- ($fh, $error_message) = Texinfo::Common::output_files_open_out(
- $self->output_files_information(), $self,
- $encoded_no_page_out_filepath);
- if (!$fh) {
- $self->document_error($self,
- sprintf(__("could not open %s for writing: %s"),
- $no_page_out_filepath, $error_message));
- return undef;
- }
- }
+ if ($output_file eq '') {
+ $self->{'current_filename'} = $output_filename;
my $body = '';
if ($output_units and @$output_units) {
my $unit_nr = 0;
@@ -11533,20 +11501,10 @@ sub _html_convert_output($$$$$$$$)
my $file_beginning
= &{$self->formatting_function('format_begin_file')}($self,
$output_filename, undef);
- $text_output .= $self->write_or_return($file_beginning, $fh);
- $text_output .= $self->write_or_return($body, $fh);
- $text_output .= $self->write_or_return($file_end, $fh);
-
- # NOTE do not close STDOUT now to avoid a perl warning.
- if ($fh and $no_page_out_filepath ne '-') {
- Texinfo::Common::output_files_register_closed(
- $self->output_files_information(), $encoded_no_page_out_filepath);
- if (!close($fh)) {
- $self->document_error($self,
- sprintf(__("error on closing %s: %s"),
- $no_page_out_filepath, $!));
- }
- }
+ $text_output .= $file_beginning;
+ $text_output .= $body;
+ $text_output .= $file_end;
+
$self->{'current_filename'} = undef;
} else {
# output with pages
@@ -11912,10 +11870,18 @@ sub output($$)
# Some information is not available yet.
$self->_reset_info();
+
my $init_status = $self->run_stage_handlers($root, 'init');
return undef unless ($init_status < $handler_fatal_error_level
and $init_status > -$handler_fatal_error_level);
+
+ $self->_prepare_title_titlepage($output_units, $output_file,
+ $output_filename);
+
+ # complete information should be available.
+ $self->_reset_info();
+
# conversion
my $text_output = $self->_html_convert_output($root, $output_units,
$special_units, $output_file, $destination_directory,
diff --git a/tp/Texinfo/XS/convert/ConvertXS.xs
b/tp/Texinfo/XS/convert/ConvertXS.xs
index ca5dcd3788..f0187f17d3 100644
--- a/tp/Texinfo/XS/convert/ConvertXS.xs
+++ b/tp/Texinfo/XS/convert/ConvertXS.xs
@@ -320,21 +320,40 @@ html_translate_names (SV *converter_in)
}
-SV *
-html_convert_init (SV *converter_in)
+void
+html_prepare_title_titlepage (SV *converter_in, SV *output_units_in,
output_file, output_filename)
+ char *output_file = (char *)SvPVbyte_nolen($arg);
+ char *output_filename = (char *)SvPVbyte_nolen($arg);
PREINIT:
CONVERTER *self = 0;
+ int output_units_descriptor = 0;
CODE:
- /* TODO error? Return undef if not found? */
+ /* TODO error? */
self = get_sv_converter (converter_in, 0);
- html_convert_init (self);
- if (self->title_titlepage)
- RETVAL = newSVpv_utf8 (self->title_titlepage, 0);
- else
- /* should never happen as a string is always returned, possibly empty */
- RETVAL = newSV(0);
- OUTPUT:
- RETVAL
+ if (SvOK (output_units_in))
+ output_units_descriptor
+ = get_sv_output_units_descriptor (output_units_in,
+ "html_prepare_title_titlepage output units");
+
+ if (self)
+ {
+ html_prepare_title_titlepage (self, output_units_descriptor,
+ output_file, output_filename);
+ if (self->modified_state)
+ {
+ build_html_formatting_state (self, self->modified_state);
+ self->modified_state = 0;
+ }
+ /* should always happen as a string is always returned, possibly empty */
+ if (self->title_titlepage)
+ {
+ HV *converter_hv = (HV *) SvRV (converter_in);
+ SV *title_titlepage_sv
+ = newSVpv_utf8 (self->title_titlepage, 0);
+ hv_store (converter_hv, "title_titlepage",
+ strlen ("title_titlepage"), title_titlepage_sv, 0);
+ }
+ }
SV *
html_convert_convert (SV *converter_in, SV *tree_in, SV *output_units_in, SV
*special_units_in)
diff --git a/tp/Texinfo/XS/convert/convert_html.c
b/tp/Texinfo/XS/convert/convert_html.c
index 2d00429795..e21221c149 100644
--- a/tp/Texinfo/XS/convert/convert_html.c
+++ b/tp/Texinfo/XS/convert/convert_html.c
@@ -2023,15 +2023,6 @@ html_prepare_units_directions_files (CONVERTER *self,
return files_source_info;
}
-/* init phase for conversion for convert() */
-void
-html_convert_init (CONVERTER *self)
-{
- char *title_titlepage
- = call_formatting_function_format_title_titlepage (self);
- self->title_titlepage = title_titlepage;
-}
-
static char *
command_conversion (CONVERTER *self, enum command_id cmd,
ELEMENT *element, HTML_ARGS_FORMATTED *args_formatted,
@@ -3746,6 +3737,28 @@ convert_output_output_unit_internal (CONVERTER *self,
return 1;
}
+void
+html_prepare_title_titlepage (CONVERTER *self, int output_units_descriptor,
+ char *output_file, char *output_filename)
+{
+ char *title_titlepage;
+ OUTPUT_UNIT_LIST *output_units
+ = retrieve_output_units (output_units_descriptor);
+
+ if (strlen (output_file))
+ self->current_filename = output_units->list[0]->unit_filename;
+ else
+ self->current_filename = output_filename;
+
+ self->modified_state |= HMSF_current_filename;
+
+ title_titlepage
+ = call_formatting_function_format_title_titlepage (self);
+ self->title_titlepage = title_titlepage;
+ self->current_filename = 0;
+ self->modified_state |= HMSF_current_filename;
+}
+
char *
html_convert_output (CONVERTER *self, ELEMENT *root,
int output_units_descriptor,
@@ -3756,7 +3769,6 @@ html_convert_output (CONVERTER *self, ELEMENT *root,
int status = 1;
TEXT result;
TEXT text; /* reused for all the output units */
- char *title_titlepage;
OUTPUT_UNIT_LIST *output_units
= retrieve_output_units (output_units_descriptor);
@@ -3768,59 +3780,17 @@ html_convert_output (CONVERTER *self, ELEMENT *root,
text_append (&result, "");
- /* determine first file name */
- if (!output_units || !output_units->number
- || !output_units->list[0]->unit_filename)
- {
- /* no page */
- /* NOTE there are always output units. There is always a file if files
- are setup, so this situation can only arise with output_file equal to ''
- as in that case files are not setup at all. */
- if (strlen (output_file))
- {
- /* This should not be possible. */
- char *no_page_output_filename = 0;
- int filename_to_be_freed = 0;
- if (self->conf->SPLIT && strlen (self->conf->SPLIT))
- {
- no_page_output_filename = top_node_filename (self,
document_name);
- filename_to_be_freed = 1;
- set_file_path (self, no_page_output_filename, 0,
- destination_directory);
- }
- else
- {
- no_page_output_filename = output_filename;
- set_file_path (self, no_page_output_filename, output_file,
- destination_directory);
- }
- self->current_filename = no_page_output_filename;
- if (filename_to_be_freed)
- free (no_page_output_filename);
- }
- else
- self->current_filename = output_filename;
- }
- else
- self->current_filename = output_units->list[0]->unit_filename;
-
- self->modified_state |= HMSF_current_filename;
-
- title_titlepage
- = call_formatting_function_format_title_titlepage (self);
- self->title_titlepage = title_titlepage;
-
- if (!output_units || !output_units->number
- || !output_units->list[0]->unit_filename)
+ if (!strlen (output_file))
{
char *file_end;
char *file_beginning;
+ self->current_filename = output_filename;
+ self->modified_state |= HMSF_current_filename;
+
text_append (&text, "");
- /* in perl there is code for a case that should not be possible,
- with current_filename ne '' here. This code is no present here */
if (output_units && output_units->number)
{
int unit_nr = 0;
diff --git a/tp/Texinfo/XS/convert/convert_html.h
b/tp/Texinfo/XS/convert/convert_html.h
index d1d84c091e..978b3c68b3 100644
--- a/tp/Texinfo/XS/convert/convert_html.h
+++ b/tp/Texinfo/XS/convert/convert_html.h
@@ -34,7 +34,8 @@ void html_prepare_output_units_global_targets (CONVERTER
*self,
void html_translate_names (CONVERTER *self);
-void html_convert_init (CONVERTER *self);
+void html_prepare_title_titlepage (CONVERTER *self, int
output_units_descriptor,
+ char *output_file, char *output_filename);
char *html_convert_convert (CONVERTER *self, ELEMENT *root,
int output_units_descriptor,
diff --git a/tp/Texinfo/XS/main/call_perl_function.c
b/tp/Texinfo/XS/main/call_perl_function.c
index 6a313a0476..24d3072026 100644
--- a/tp/Texinfo/XS/main/call_perl_function.c
+++ b/tp/Texinfo/XS/main/call_perl_function.c
@@ -498,6 +498,12 @@ call_formatting_function_format_title_titlepage (CONVERTER
*self)
formatting_reference
= self->formatting_references[FR_format_title_titlepage].sv_reference;
+ if (self->modified_state)
+ {
+ build_html_formatting_state (self, self->modified_state);
+ self->modified_state = 0;
+ }
+
dSP;
ENTER;
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- branch master updated: * tp/Texinfo/Convert/HTML.pm (_html_convert_output), tp/Texinfo/XS/convert/convert_html.c (html_convert_output): only consider two cases for filenames, no filenames if output_file is the empty string '', filenames otherwise.,
Patrice Dumas <=