[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[no subject]
From: |
Patrice Dumas |
Date: |
Tue, 30 Apr 2024 14:13:59 -0400 (EDT) |
branch: master
commit 64eee9ddbae0e2daf741ebf600f4e8df9275d645
Author: Patrice Dumas <pertusus@free.fr>
AuthorDate: Tue Apr 30 20:12:30 2024 +0200
* tp/Texinfo/Convert/Converter.pm (_id_to_filename), tp/ext/epub3.pm
(epub_convert_image_command): handle BASEFILENAME_LENGTH being undef.
* tp/Texinfo/Convert/HTML.pm (_default_format_button),
tp/Texinfo/XS/convert/convert_html.c (html_default_format_button):
handle from_element_direction return being undef.
* tp/Texinfo/XS/convert/convert_html.c, tp/Texinfo/Convert/HTML.pm:
handle undefined SPLIT.
* tp/Texinfo/XS/convert/convert_html.c (from_element_direction):
handle TOP_NODE_UP being undef.
* tp/Texinfo/Convert/Plaintext.pm (converter_initialize): handle
undefined FILLCOLUMN.
* tp/ext/epub3.pm (epub_setup): use INFO_JS_DIR and JS_WEBLABELS_FILE
if defined, enven if the empty string or 0.
---
ChangeLog | 21 ++++++++++++++++
tp/Texinfo/Convert/Converter.pm | 10 ++++++--
tp/Texinfo/Convert/HTML.pm | 48 ++++++++++++++++++++----------------
tp/Texinfo/Convert/Plaintext.pm | 6 +++--
tp/Texinfo/XS/convert/convert_html.c | 24 ++++++++++++------
tp/Texinfo/options_data.txt | 5 +++-
tp/ext/epub3.pm | 33 ++++++++++++++++---------
7 files changed, 103 insertions(+), 44 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index fc3e34f886..0d6d4903f5 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,24 @@
+2024-04-30 Patrice Dumas <pertusus@free.fr>
+
+ * tp/Texinfo/Convert/Converter.pm (_id_to_filename), tp/ext/epub3.pm
+ (epub_convert_image_command): handle BASEFILENAME_LENGTH being undef.
+
+ * tp/Texinfo/Convert/HTML.pm (_default_format_button),
+ tp/Texinfo/XS/convert/convert_html.c (html_default_format_button):
+ handle from_element_direction return being undef.
+
+ * tp/Texinfo/XS/convert/convert_html.c, tp/Texinfo/Convert/HTML.pm:
+ handle undefined SPLIT.
+
+ * tp/Texinfo/XS/convert/convert_html.c (from_element_direction):
+ handle TOP_NODE_UP being undef.
+
+ * tp/Texinfo/Convert/Plaintext.pm (converter_initialize): handle
+ undefined FILLCOLUMN.
+
+ * tp/ext/epub3.pm (epub_setup): use INFO_JS_DIR and JS_WEBLABELS_FILE
+ if defined, enven if the empty string or 0.
+
2024-04-29 Patrice Dumas <pertusus@free.fr>
* tp/maintain/regenerate_C_options_info.pl: add a better BUG message
diff --git a/tp/Texinfo/Convert/Converter.pm b/tp/Texinfo/Convert/Converter.pm
index 05d2e61780..3eb589603d 100644
--- a/tp/Texinfo/Convert/Converter.pm
+++ b/tp/Texinfo/Convert/Converter.pm
@@ -789,7 +789,12 @@ sub _id_to_filename($$)
{
my $self = shift;
my $id = shift;
- return substr($id, 0, $self->get_conf('BASEFILENAME_LENGTH'));
+ my $basefilename_length = $self->get_conf('BASEFILENAME_LENGTH');
+ if (defined($basefilename_length) and $basefilename_length >= 0) {
+ return substr($id, 0, $basefilename_length);
+ } else {
+ return $id;
+ }
}
sub normalized_sectioning_command_filename($$)
@@ -826,7 +831,8 @@ sub node_information_filename($$$)
my $filename;
if (defined($normalized)) {
if ($self->get_conf('TRANSLITERATE_FILE_NAMES')) {
- $filename =
Texinfo::Convert::NodeNameNormalization::normalize_transliterate_texinfo(
+ $filename
+ = Texinfo::Convert::NodeNameNormalization::normalize_transliterate_texinfo(
{'contents' => $label_element->{'contents'}},
$no_unidecode);
} else {
diff --git a/tp/Texinfo/Convert/HTML.pm b/tp/Texinfo/Convert/HTML.pm
index e9d692792b..092928ee59 100644
--- a/tp/Texinfo/Convert/HTML.pm
+++ b/tp/Texinfo/Convert/HTML.pm
@@ -4389,7 +4389,7 @@ sub _default_format_button($$;$)
my $href = $self->from_element_direction($direction, 'href',
undef, undef,
$source_command);
my $text_formatted = $self->from_element_direction($direction, $text);
- if (defined($href)) {
+ if (defined($href) and defined($text_formatted)) {
my $anchor_attributes =
$self->_direction_href_attributes($direction);
$active = "<a
href=\"$href\"${anchor_attributes}>$text_formatted</a>";
} else {
@@ -4626,7 +4626,8 @@ sub _default_format_navigation_header($$$$)
$result .= '</td>
<td>
';
- } elsif ($self->get_conf('SPLIT') eq 'node' and $result ne '') {
+ } elsif ($self->get_conf('SPLIT')
+ and $self->get_conf('SPLIT') eq 'node' and $result ne '') {
$result .= $self->get_conf('DEFAULT_RULE')."\n";
}
return $result;
@@ -4682,8 +4683,9 @@ sub _default_format_element_header($$$$)
$self->get_conf('TOP_BUTTONS'), $cmdname, $command)
if ($self->get_conf('SPLIT') or $self->get_conf('HEADERS'));
} else {
+ my $split = $self->get_conf('SPLIT');
if ($first_in_page and !$self->get_conf('HEADERS')) {
- if ($self->get_conf('SPLIT') eq 'chapter') {
+ if ($split and $split eq 'chapter') {
$result
.= &{$self->formatting_function('format_navigation_header')}($self,
$self->get_conf('CHAPTER_BUTTONS'), $cmdname,
$command);
@@ -4691,7 +4693,7 @@ sub _default_format_element_header($$$$)
$result .= $self->get_conf('DEFAULT_RULE') ."\n"
if (defined($self->get_conf('DEFAULT_RULE'))
and !$self->get_conf('VERTICAL_HEAD_NAVIGATION'));
- } elsif ($self->get_conf('SPLIT') eq 'section') {
+ } elsif ($split and $split eq 'section') {
$result
.= &{$self->formatting_function('format_navigation_header')}($self,
$self->get_conf('SECTION_BUTTONS'), $cmdname,
$command);
@@ -4702,7 +4704,7 @@ sub _default_format_element_header($$$$)
$result
.= &{$self->formatting_function('format_navigation_header')}($self,
$self->get_conf('SECTION_BUTTONS'), $cmdname,
$command);
- } elsif($self->get_conf('HEADERS') or $self->get_conf('SPLIT') eq
'node') {
+ } elsif ($self->get_conf('HEADERS') or ($split and $split eq 'node')) {
# got to do this here, as it isn't done otherwise since
# navigation_header is not called
$result
@@ -8199,9 +8201,10 @@ sub _default_format_element_footer($$$$;$)
my $is_special = (defined($unit->{'unit_type'})
and $unit->{'unit_type'} eq 'special_unit');
+ my $split = $self->get_conf('SPLIT');
if (($end_page or $next_is_top or $next_is_special or $is_top)
and $self->get_conf('VERTICAL_HEAD_NAVIGATION')
- and ($self->get_conf('SPLIT') ne 'node'
+ and (!$split or $split ne 'node'
or $self->get_conf('HEADERS') or $is_special or $is_top)) {
$result .= "</td>
</tr>
@@ -8214,22 +8217,23 @@ sub _default_format_element_footer($$$$;$)
my $closed_strings = $self->close_registered_sections_level(0);
$result .= join('', @{$closed_strings});
+ my $split = $self->get_conf('SPLIT');
+
# setup buttons for navigation footer
if (($is_top or $is_special)
- and ($self->get_conf('SPLIT') ne '' or !$self->get_conf('MONOLITHIC'))
+ and ($split or !$self->get_conf('MONOLITHIC'))
and (($self->get_conf('HEADERS')
- or ($self->get_conf('SPLIT')
- and $self->get_conf('SPLIT') ne 'node')))) {
+ or ($split and $split ne 'node')))) {
if ($is_top) {
$buttons = $self->get_conf('TOP_FOOTER_BUTTONS');
} else {
$buttons = $self->get_conf('MISC_BUTTONS');
}
- } elsif ($self->get_conf('SPLIT') eq 'section') {
+ } elsif ($split and $split eq 'section') {
$buttons = $self->get_conf('SECTION_FOOTER_BUTTONS');
- } elsif ($self->get_conf('SPLIT') eq 'chapter') {
+ } elsif ($split and $split eq 'chapter') {
$buttons = $self->get_conf('CHAPTER_FOOTER_BUTTONS');
- } elsif ($self->get_conf('SPLIT') eq 'node') {
+ } elsif ($split and $split eq 'node') {
if ($self->get_conf('HEADERS')) {
my $no_footer_word_count;
if ($self->get_conf('WORDS_IN_PAGE')) {
@@ -8275,13 +8279,14 @@ sub _default_format_element_footer($$$$;$)
if ($buttons or !$end_page or $self->get_conf('PROGRAM_NAME_IN_FOOTER')) {
my $rule;
+ my $split = $self->get_conf('SPLIT');
if (!$end_page and ($is_top or $next_is_top or ($next_is_special
and !$is_special))) {
$rule = $self->get_conf('BIG_RULE');
} elsif (!$buttons or $is_top or $is_special
- or ($end_page and ($self->get_conf('SPLIT') eq 'chapter'
- or $self->get_conf('SPLIT') eq 'section'))
- or ($self->get_conf('SPLIT') eq 'node'
+ or ($end_page and $split
+ and ($split eq 'chapter' or $split eq 'section'))
+ or ($split and $split eq 'node'
and $self->get_conf('HEADERS'))) {
$rule = $self->get_conf('DEFAULT_RULE');
}
@@ -9052,9 +9057,10 @@ sub converter_initialize($)
# The main program warns if the specific command line option value is
# not known. We could add a warning here to catch mistakes in init
# files. Wait for user reports.
- if ($self->get_conf('SPLIT') and $self->get_conf('SPLIT') ne 'chapter'
- and $self->get_conf('SPLIT') ne 'section'
- and $self->get_conf('SPLIT') ne 'node') {
+ my $split = $self->get_conf('SPLIT');
+ if ($split and $split ne 'chapter'
+ and $split ne 'section'
+ and $split ne 'node') {
$self->force_conf('SPLIT', 'node');
}
@@ -10230,8 +10236,8 @@ sub _prepare_special_units($$)
if ((!defined($self->get_conf('DO_ABOUT'))
and scalar(@$output_units) > 1
- and ($self->get_conf('SPLIT') or $self->get_conf('HEADERS')))
- or ($self->get_conf('DO_ABOUT'))) {
+ and ($self->get_conf('SPLIT') or $self->get_conf('HEADERS')))
+ or ($self->get_conf('DO_ABOUT'))) {
$do_special{'about'} = 1;
}
@@ -10866,7 +10872,7 @@ sub _default_format_contents($$;$$)
#print STDERR "ROOT_LEVEL Max: $max_root_level, Min: $min_root_level\n";
my @toc_ul_classes;
push @toc_ul_classes, 'toc-numbered-mark'
- if ($self->get_conf('NUMBER_SECTIONS'));
+ if ($self->get_conf('NUMBER_SECTIONS'));
my $result = '';
if ($is_contents and !defined($self->get_conf('BEFORE_TOC_LINES'))
diff --git a/tp/Texinfo/Convert/Plaintext.pm b/tp/Texinfo/Convert/Plaintext.pm
index c9ad367ca7..fc881fd2d9 100644
--- a/tp/Texinfo/Convert/Plaintext.pm
+++ b/tp/Texinfo/Convert/Plaintext.pm
@@ -540,9 +540,11 @@ sub converter_initialize($)
} else {
$self->{'ascii_dashes_and_quotes'} = 0;
}
- if ($self->get_conf('FILLCOLUMN')) {
+ if (defined($self->get_conf('FILLCOLUMN'))) {
$self->{'fillcolumn'} = $self->get_conf('FILLCOLUMN');
- # else it's already set via the defaults
+ } else {
+ $self->{'fillcolumn'}
+ = $Texinfo::Options::converter_cmdline_options{'FILLCOLUMN'};
}
if ($self->get_conf('INFO_SPECIAL_CHARS_QUOTE')) {
diff --git a/tp/Texinfo/XS/convert/convert_html.c
b/tp/Texinfo/XS/convert/convert_html.c
index 5a5a511205..90d5f76854 100644
--- a/tp/Texinfo/XS/convert/convert_html.c
+++ b/tp/Texinfo/XS/convert/convert_html.c
@@ -4092,7 +4092,12 @@ from_element_direction (CONVERTER *self, int direction,
return strdup (self->conf->TOP_NODE_UP_URL.string);
else if (type == HTT_text || type == HTT_node
|| type == HTT_string || type == HTT_section)
- return strdup (self->conf->TOP_NODE_UP.string);
+ {
+ if (self->conf->TOP_NODE_UP.string)
+ return strdup (self->conf->TOP_NODE_UP.string);
+ else
+ return 0;
+ }
else
{
char *msg;
@@ -7486,7 +7491,7 @@ html_default_format_button (CONVERTER *self,
direction,
button->button_info->direction_information_type,
0, 0, 0);
- if (href)
+ if (href && text_formatted)
{
formatted_button->active
= direction_a (self, direction, href,
@@ -7846,7 +7851,8 @@ html_default_format_navigation_header (CONVERTER *self,
if (vertical)
text_append (result, "</td>\n<td>\n");
- else if (!strcmp (self->conf->SPLIT.string, "node")
+ else if (self->conf->SPLIT.string
+ && !strcmp (self->conf->SPLIT.string, "node")
&& result->end > result_text_index)
{
text_append (result, self->conf->DEFAULT_RULE.string);
@@ -7948,7 +7954,8 @@ html_default_format_element_header (CONVERTER *self,
{
if (first_in_page && self->conf->HEADERS.integer <= 0)
{
- if (!strcmp (self->conf->SPLIT.string, "chapter"))
+ if (self->conf->SPLIT.string
+ && !strcmp (self->conf->SPLIT.string, "chapter"))
{
format_navigation_header (self,
self->conf->CHAPTER_BUTTONS.buttons, cmdname, command,
@@ -7960,7 +7967,8 @@ html_default_format_element_header (CONVERTER *self,
text_append_n (result, "\n", 1);
}
}
- else if (!strcmp (self->conf->SPLIT.string, "section"))
+ else if (self->conf->SPLIT.string
+ && !strcmp (self->conf->SPLIT.string, "section"))
{
format_navigation_header (self,
self->conf->SECTION_BUTTONS.buttons, cmdname, command,
@@ -7975,7 +7983,8 @@ html_default_format_element_header (CONVERTER *self,
result);
}
else if (self->conf->HEADERS.integer > 0
- || !strcmp (self->conf->SPLIT.string, "node"))
+ || (self->conf->SPLIT.string
+ && !strcmp (self->conf->SPLIT.string, "node")))
{
/* got to do this here, as it isn't done otherwise since
navigation_header is not called */
@@ -8090,7 +8099,8 @@ html_default_format_element_footer (CONVERTER *self,
if ((end_page || next_is_top || next_is_special || is_top)
&& self->conf->VERTICAL_HEAD_NAVIGATION.integer > 0
- && (strcmp (self->conf->SPLIT.string, "node")
+ && (!self->conf->SPLIT.string || !strlen (self->conf->SPLIT.string)
+ || strcmp (self->conf->SPLIT.string, "node")
|| self->conf->HEADERS.integer > 0 || unit_type == OU_special_unit
|| is_top))
{
diff --git a/tp/Texinfo/options_data.txt b/tp/Texinfo/options_data.txt
index d0f72d8bc0..b56368c09f 100644
--- a/tp/Texinfo/options_data.txt
+++ b/tp/Texinfo/options_data.txt
@@ -20,7 +20,10 @@
# format is:
# option_name category default_value type
-# undef is special for default_value, it means undefined.
+# undef is special for default_value, it means undefined. What undefined
+# actually means depends on the variable. In could mean
+# * unset/false/empty string
+# * set to the default value, when an unset value does not make sense
# By chance, there is no space in default values for now, and therefore
# no need for quoting/escaping.
diff --git a/tp/ext/epub3.pm b/tp/ext/epub3.pm
index b72656557f..40e2b99bae 100644
--- a/tp/ext/epub3.pm
+++ b/tp/ext/epub3.pm
@@ -290,10 +290,20 @@ sub epub_convert_image_command($$$$)
my $protected_image_extension
=
Texinfo::Convert::NodeNameNormalization::transliterate_protect_file_name(
$image_extension);
- # -5 for the extension and -10 for $epub_file_nr
- my $cropped_image_basefile_name
- = substr($protected_image_basefile_name, 0,
- $self->get_conf('BASEFILENAME_LENGTH') - 15);
+ my $basefilename_length = $self->get_conf('BASEFILENAME_LENGTH');
+ my $cropped_image_basefile_name;
+ if (defined($basefilename_length) and $basefilename_length >= 0) {
+ if ($basefilename_length > 2 * 15) {
+ # -5 for the extension and -10 for $epub_file_nr
+ $basefilename_length -= 15;
+ } else {
+ $basefilename_length = $basefilename_length / 2;
+ }
+ $cropped_image_basefile_name
+ = substr($protected_image_basefile_name, 0, $basefilename_length);
+ } else {
+ $cropped_image_basefile_name = $protected_image_basefile_name;
+ }
my $destination_basefile_name =
$epub_file_nr.'-'.$cropped_image_basefile_name
. $protected_image_extension;
$epub_file_nr += 1;
@@ -469,7 +479,7 @@ sub epub_setup($)
}
$epub_info_js_dir_name = undef;
- if ($self->get_conf('INFO_JS_DIR')) {
+ if (defined($self->get_conf('INFO_JS_DIR'))) {
# re-set INFO_JS_DIR up to have the javascript and
# css files in a directory rooted at $epub_document_dir_name
$epub_info_js_dir_name = $self->get_conf('INFO_JS_DIR');
@@ -487,15 +497,16 @@ sub epub_setup($)
# TODO make sure it is SPLIT and set SPLIT if not?
}
+ my $split = $self->get_conf('SPLIT');
# determine main epub directory and directory for xhtml files,
# reset OUTFILE and SUBDIR to match with the epub directory
# for XHTML output
if (defined($self->get_conf('OUTFILE'))) {
$epub_outfile = $self->get_conf('OUTFILE');
- # if not undef, will be used as directory name in
+ # if not undef, OUTFILE will be used as directory name in
# determine_files_and_directory() which does not make sense
- if ($self->get_conf('SPLIT')) {
+ if ($split) {
$self->force_conf('OUTFILE', undef);
}
}
@@ -510,7 +521,7 @@ sub epub_setup($)
if (defined($self->get_conf('SUBDIR'))) {
$epub_destination_directory = File::Spec->catdir($self->get_conf('SUBDIR'),
$document_name . '_epub_package');
- } elsif ($self->get_conf('SPLIT')) {
+ } elsif ($split) {
$epub_destination_directory = $destination_directory;
} else {
$epub_destination_directory = $document_name . '_epub_package';
@@ -519,7 +530,7 @@ sub epub_setup($)
= File::Spec->catdir($epub_destination_directory,
$epub_document_dir_name, $epub_xhtml_dir);
# set for XHTML conversion
- if ($self->get_conf('SPLIT')) {
+ if ($split) {
$self->force_conf('SUBDIR', $epub_document_destination_directory);
$self->force_conf('OUTFILE', undef);
} else {
@@ -854,14 +865,14 @@ EOT
foreach my $output_filename (@epub_output_filenames) {
$id_count++;
my $properties_str = '';
- if ($self->get_conf('INFO_JS_DIR')) {
+ if (defined($self->get_conf('INFO_JS_DIR'))) {
$properties_str = ' properties="scripted"'
}
print $opf_fh " <item id=\"${spine_uid_str}${id_count}\" "
. "media-type=\"application/xhtml+xml\"
href=\"${epub_xhtml_dir}/${output_filename}\"${properties_str}/>\n";
}
my $js_weblabels_id;
- if ($self->get_conf('JS_WEBLABELS_FILE')) {
+ if (defined($self->get_conf('JS_WEBLABELS_FILE'))) {
my $js_weblabels_file_name = $self->get_conf('JS_WEBLABELS_FILE');
my $js_licenses_file_path =
File::Spec->catfile($epub_document_destination_directory,
$js_weblabels_file_name);