[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[no subject]
From: |
Patrice Dumas |
Date: |
Sat, 5 Oct 2024 06:08:23 -0400 (EDT) |
branch: master
commit d64002f0bb45c3642fdc9f0d1466e2929820a65d
Author: Patrice Dumas <pertusus@free.fr>
AuthorDate: Sat Aug 31 23:04:28 2024 +0200
* tp/Texinfo/Convert/Converter.pm: reorder functions, add more
sections in file.
---
ChangeLog | 5 +
tp/Texinfo/Convert/Converter.pm | 489 +++++++++++++++++++++-------------------
2 files changed, 263 insertions(+), 231 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index ed14ca37dd..012eb17ab7 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2024-08-31 Patrice Dumas <pertusus@free.fr>
+
+ * tp/Texinfo/Convert/Converter.pm: reorder functions, add more
+ sections in file.
+
2024-08-31 Patrice Dumas <pertusus@free.fr>
Changes in POD, TODO.
diff --git a/tp/Texinfo/Convert/Converter.pm b/tp/Texinfo/Convert/Converter.pm
index fc24000803..231f902da5 100644
--- a/tp/Texinfo/Convert/Converter.pm
+++ b/tp/Texinfo/Convert/Converter.pm
@@ -439,6 +439,22 @@ sub destroy($)
{
}
+sub XS_get_unclosed_stream($$)
+{
+ return undef;
+}
+
+sub output_files_information($)
+{
+ my $self = shift;
+ return $self->{'output_files'};
+}
+
+
+
+
+# translations
+
sub cdt($$;$$)
{
my ($self, $string, $replaced_substrings, $translation_context) = @_;
@@ -467,6 +483,10 @@ sub pcdt($$;$$)
return $self->cdt($string, $replaced_substrings, $translation_context);
}
+
+
+# errors and warnings
+
sub converter_line_error($$$;$)
{
my $self = shift;
@@ -535,6 +555,8 @@ sub get_converter_errors($)
return $self->{'error_warning_messages'};
}
+
+
###############################################################
# Implementation of the customization API that is used in many
# Texinfo modules
@@ -583,182 +605,15 @@ sub force_conf($$$)
return 1;
}
-sub output_files_information($)
-{
- my $self = shift;
- return $self->{'output_files'};
-}
-
-
-####################################################################
-# Useful functions. Those in this section are used in the module and can
-# also be used in other Converter modules.
-
-# output fo $fh if defined, otherwise return the text.
-sub write_or_return($$$)
-{
- my $self = shift;
- my $text = shift;
- my $fh = shift;
- if ($fh) {
- print $fh $text;
- return '';
- } else {
- return $text;
- }
-}
-
-my $STDIN_DOCU_NAME = 'stdin';
-
-# this requires a document, and is, in general, used in output(), therefore
-# a document need to be associated to the converter, not only a tree.
-sub determine_files_and_directory($$)
-{
- my $self = shift;
- my $output_format = shift;
-
- # determine input file base name
- my $input_basefile;
- my $document_info;
-
- if ($self->{'document'}) {
- $document_info = $self->{'document'}->global_information();
- }
-
- if ($document_info and defined($document_info->{'input_file_name'})) {
- # 'input_file_name' is not decoded, as it is derived from input
- # file which is not decoded either. We want to return only
- # decoded character strings such that they can easily be mixed
- # with other character strings, so we decode here.
- my $input_file_name_bytes = $document_info->{'input_file_name'};
- my $encoding = $self->get_conf('COMMAND_LINE_ENCODING');
- my $input_file_name;
- if (defined($encoding)) {
- $input_file_name = decode($encoding, $input_file_name_bytes, sub { '?'
});
- # use '?' as replacement character rather than U+FFFD in case it
- # is re-encoded to an encoding without this character
- } else {
- $input_file_name = $input_file_name_bytes;
- }
- # FIXME $input_file_name is already the base file name. Not clear how
- # this is useful.
- my ($directories, $suffix);
- ($input_basefile, $directories, $suffix) = fileparse($input_file_name);
- } else {
- # This could happen if called on a piece of Texinfo and not a full manual.
- $input_basefile = '';
- }
-
- my $input_basename;
- if ($input_basefile eq '-') {
- $input_basename = $STDIN_DOCU_NAME;
- } else {
- $input_basename = $input_basefile;
- $input_basename =~ s/\.te?x(i|info)?$//;
- }
-
- my $setfilename;
- if (defined($self->get_conf('setfilename'))) {
- $setfilename = $self->get_conf('setfilename');
- } elsif ($document_info and defined($document_info->{'setfilename'})) {
- $setfilename = $document_info->{'setfilename'};
- }
-
- my $input_basename_for_outfile = $input_basename;
- my $setfilename_for_outfile = $setfilename;
- # PREFIX overrides both setfilename and the input file base name
- if (defined($self->get_conf('PREFIX'))) {
- $setfilename_for_outfile = undef;
- $input_basename_for_outfile = $self->get_conf('PREFIX');
- }
-
- # the document path, in general the outfile without
- # extension and can be set from setfilename if outfile is not set
- my $document_path;
- # determine output file and output file name
- my $output_file;
- if (!defined($self->get_conf('OUTFILE'))) {
- if (defined($setfilename_for_outfile)) {
- $document_path = $setfilename_for_outfile;
- $document_path =~ s/\.[^\.]*$//;
- if (!$self->get_conf('USE_SETFILENAME_EXTENSION')) {
- $output_file = $document_path;
- $output_file .= '.'.$self->get_conf('EXTENSION')
- if (defined($self->get_conf('EXTENSION'))
- and $self->get_conf('EXTENSION') ne '');
- } else {
- $output_file = $setfilename_for_outfile;
- }
- } elsif ($input_basename_for_outfile ne '') {
- $output_file = $input_basename_for_outfile;
- $document_path = $input_basename_for_outfile;
- $output_file .= '.'.$self->get_conf('EXTENSION')
- if (defined($self->get_conf('EXTENSION'))
- and $self->get_conf('EXTENSION') ne '');
- } else {
- $output_file = '';
- $document_path = $output_file;
- }
- if (defined($self->get_conf('SUBDIR')) and $output_file ne '') {
- my $dir = File::Spec->canonpath($self->get_conf('SUBDIR'));
- $output_file = File::Spec->catfile($dir, $output_file);
- }
- } else {
- $document_path = $self->get_conf('OUTFILE');
- $document_path =~ s/\.[^\.]*$//;
- $output_file = $self->get_conf('OUTFILE');
- }
-
- # the output file path, in general same as the outfile but can be
- # set from setfilename if outfile is not set.
- my $output_filepath = $output_file;
- # in this case one wants to get the result in a string and there
- # is a setfilename. The setfilename is used to get something.
- # This happens in the test suite.
- if ($output_file eq '' and defined($setfilename_for_outfile)) {
- $output_filepath = $setfilename_for_outfile;
- $document_path = $setfilename_for_outfile;
- $document_path =~ s/\.[^\.]*$//;
- }
+
- # $document_name is the name of the document, which is the output
- # file basename, $output_filename, without extension.
- my ($document_name, $output_filename, $directories, $suffix);
- # We may be handling setfilename there, so it is not obvious that we
- # want to use fileparse and not consider unixish separators. However,
- # if this is setfilename, it should be a simple file name, so it
- # should hopefully be harmless to use fileparse
- ($document_name, $directories, $suffix) = fileparse($document_path);
- ($output_filename, $directories, $suffix) = fileparse($output_filepath);
- my $destination_directory;
- if ($self->get_conf('SPLIT')) {
- if (defined($self->get_conf('OUTFILE'))) {
- $destination_directory = $self->get_conf('OUTFILE');
- } elsif (defined($self->get_conf('SUBDIR'))) {
- $destination_directory = $self->get_conf('SUBDIR');
- } else {
- $destination_directory = $document_name;
- if (defined($output_format) and $output_format ne '') {
- $destination_directory .= '_'.$output_format;
- }
- }
- } else {
- # $output_file_filename is not used, but $output_filename should be
- # the same as long as $output_file is the same as $output_filepath
- # which is the case except if $output_file is ''.
- # Note that fileparse may return a string for the directory part even
- # for a relative file without directory, ie
- # myfile.html -> $output_dir = './'
- # In that case the $destination_directory will never be ''.
- my ($output_file_filename, $output_dir, $suffix) = fileparse($output_file);
- $destination_directory = $output_dir;
- }
- if ($destination_directory ne '') {
- $destination_directory = File::Spec->canonpath($destination_directory);
- }
- return ($output_file, $destination_directory, $output_filename,
- $document_name, $input_basefile);
-}
+#####################################################################
+# Elements and output units file names
+#
+# - default file names setting for sectioning commands and nodes
+# - output units files API
+# - set_output_units_files, which uses both default file names setting
+# and output units files API
sub _id_to_filename($$)
{
@@ -823,6 +678,25 @@ sub node_information_filename($$$)
return $filename;
}
+sub top_node_filename($$)
+{
+ my $self = shift;
+ my $document_name = shift;
+
+ if (defined($self->get_conf('TOP_FILE'))
+ and $self->get_conf('TOP_FILE') ne '') {
+ return $self->get_conf('TOP_FILE');
+ } elsif (defined($document_name)) {
+ my $top_node_filename = $document_name;
+ if (defined($self->get_conf('EXTENSION'))
+ and $self->get_conf('EXTENSION') ne '') {
+ $top_node_filename .= '.'.$self->get_conf('EXTENSION')
+ }
+ return $top_node_filename
+ }
+ return undef;
+}
+
sub initialize_output_units_files($)
{
my $self = shift;
@@ -952,25 +826,6 @@ sub set_file_path($$$;$)
$self->{'out_filepaths'}->{$filename} = $filepath;
}
-sub top_node_filename($$)
-{
- my $self = shift;
- my $document_name = shift;
-
- if (defined($self->get_conf('TOP_FILE'))
- and $self->get_conf('TOP_FILE') ne '') {
- return $self->get_conf('TOP_FILE');
- } elsif (defined($document_name)) {
- my $top_node_filename = $document_name;
- if (defined($self->get_conf('EXTENSION'))
- and $self->get_conf('EXTENSION') ne '') {
- $top_node_filename .= '.'.$self->get_conf('EXTENSION')
- }
- return $top_node_filename
- }
- return undef;
-}
-
sub _get_root_element($$)
{
my $self = shift;
@@ -1118,6 +973,14 @@ sub set_output_units_files($$$$$$)
}
}
+
+
+#############################################################
+# useful methods for Converters.
+# First methods are also used in this module.
+
+# Generic/overall document methods
+
sub create_destination_directory($$$)
{
my $self = shift;
@@ -1136,9 +999,171 @@ sub create_destination_directory($$$)
return 1;
}
+# output fo $fh if defined, otherwise return the text.
+sub write_or_return($$$)
+{
+ my $self = shift;
+ my $text = shift;
+ my $fh = shift;
+ if ($fh) {
+ print $fh $text;
+ return '';
+ } else {
+ return $text;
+ }
+}
-#############################################################
-# useful methods for Converters.
+my $STDIN_DOCU_NAME = 'stdin';
+
+# this requires a document, and is, in general, used in output(), therefore
+# a document need to be associated to the converter, not only a tree.
+sub determine_files_and_directory($$)
+{
+ my $self = shift;
+ my $output_format = shift;
+
+ # determine input file base name
+ my $input_basefile;
+ my $document_info;
+
+ if ($self->{'document'}) {
+ $document_info = $self->{'document'}->global_information();
+ }
+
+ if ($document_info and defined($document_info->{'input_file_name'})) {
+ # 'input_file_name' is not decoded, as it is derived from input
+ # file which is not decoded either. We want to return only
+ # decoded character strings such that they can easily be mixed
+ # with other character strings, so we decode here.
+ my $input_file_name_bytes = $document_info->{'input_file_name'};
+ my $encoding = $self->get_conf('COMMAND_LINE_ENCODING');
+ my $input_file_name;
+ if (defined($encoding)) {
+ $input_file_name = decode($encoding, $input_file_name_bytes, sub { '?'
});
+ # use '?' as replacement character rather than U+FFFD in case it
+ # is re-encoded to an encoding without this character
+ } else {
+ $input_file_name = $input_file_name_bytes;
+ }
+ # FIXME $input_file_name is already the base file name. Not clear how
+ # this is useful.
+ my ($directories, $suffix);
+ ($input_basefile, $directories, $suffix) = fileparse($input_file_name);
+ } else {
+ # This could happen if called on a piece of Texinfo and not a full manual.
+ $input_basefile = '';
+ }
+
+ my $input_basename;
+ if ($input_basefile eq '-') {
+ $input_basename = $STDIN_DOCU_NAME;
+ } else {
+ $input_basename = $input_basefile;
+ $input_basename =~ s/\.te?x(i|info)?$//;
+ }
+
+ my $setfilename;
+ if (defined($self->get_conf('setfilename'))) {
+ $setfilename = $self->get_conf('setfilename');
+ } elsif ($document_info and defined($document_info->{'setfilename'})) {
+ $setfilename = $document_info->{'setfilename'};
+ }
+
+ my $input_basename_for_outfile = $input_basename;
+ my $setfilename_for_outfile = $setfilename;
+ # PREFIX overrides both setfilename and the input file base name
+ if (defined($self->get_conf('PREFIX'))) {
+ $setfilename_for_outfile = undef;
+ $input_basename_for_outfile = $self->get_conf('PREFIX');
+ }
+
+ # the document path, in general the outfile without
+ # extension and can be set from setfilename if outfile is not set
+ my $document_path;
+ # determine output file and output file name
+ my $output_file;
+ if (!defined($self->get_conf('OUTFILE'))) {
+ if (defined($setfilename_for_outfile)) {
+ $document_path = $setfilename_for_outfile;
+ $document_path =~ s/\.[^\.]*$//;
+ if (!$self->get_conf('USE_SETFILENAME_EXTENSION')) {
+ $output_file = $document_path;
+ $output_file .= '.'.$self->get_conf('EXTENSION')
+ if (defined($self->get_conf('EXTENSION'))
+ and $self->get_conf('EXTENSION') ne '');
+ } else {
+ $output_file = $setfilename_for_outfile;
+ }
+ } elsif ($input_basename_for_outfile ne '') {
+ $output_file = $input_basename_for_outfile;
+ $document_path = $input_basename_for_outfile;
+ $output_file .= '.'.$self->get_conf('EXTENSION')
+ if (defined($self->get_conf('EXTENSION'))
+ and $self->get_conf('EXTENSION') ne '');
+ } else {
+ $output_file = '';
+ $document_path = $output_file;
+ }
+ if (defined($self->get_conf('SUBDIR')) and $output_file ne '') {
+ my $dir = File::Spec->canonpath($self->get_conf('SUBDIR'));
+ $output_file = File::Spec->catfile($dir, $output_file);
+ }
+ } else {
+ $document_path = $self->get_conf('OUTFILE');
+ $document_path =~ s/\.[^\.]*$//;
+ $output_file = $self->get_conf('OUTFILE');
+ }
+
+ # the output file path, in general same as the outfile but can be
+ # set from setfilename if outfile is not set.
+ my $output_filepath = $output_file;
+ # in this case one wants to get the result in a string and there
+ # is a setfilename. The setfilename is used to get something.
+ # This happens in the test suite.
+ if ($output_file eq '' and defined($setfilename_for_outfile)) {
+ $output_filepath = $setfilename_for_outfile;
+ $document_path = $setfilename_for_outfile;
+ $document_path =~ s/\.[^\.]*$//;
+ }
+
+ # $document_name is the name of the document, which is the output
+ # file basename, $output_filename, without extension.
+ my ($document_name, $output_filename, $directories, $suffix);
+ # We may be handling setfilename there, so it is not obvious that we
+ # want to use fileparse and not consider unixish separators. However,
+ # if this is setfilename, it should be a simple file name, so it
+ # should hopefully be harmless to use fileparse
+ ($document_name, $directories, $suffix) = fileparse($document_path);
+ ($output_filename, $directories, $suffix) = fileparse($output_filepath);
+ my $destination_directory;
+ if ($self->get_conf('SPLIT')) {
+ if (defined($self->get_conf('OUTFILE'))) {
+ $destination_directory = $self->get_conf('OUTFILE');
+ } elsif (defined($self->get_conf('SUBDIR'))) {
+ $destination_directory = $self->get_conf('SUBDIR');
+ } else {
+ $destination_directory = $document_name;
+ if (defined($output_format) and $output_format ne '') {
+ $destination_directory .= '_'.$output_format;
+ }
+ }
+ } else {
+ # $output_file_filename is not used, but $output_filename should be
+ # the same as long as $output_file is the same as $output_filepath
+ # which is the case except if $output_file is ''.
+ # Note that fileparse may return a string for the directory part even
+ # for a relative file without directory, ie
+ # myfile.html -> $output_dir = './'
+ # In that case the $destination_directory will never be ''.
+ my ($output_file_filename, $output_dir, $suffix) = fileparse($output_file);
+ $destination_directory = $output_dir;
+ }
+ if ($destination_directory ne '') {
+ $destination_directory = File::Spec->canonpath($destination_directory);
+ }
+ return ($output_file, $destination_directory, $output_filename,
+ $document_name, $input_basefile);
+}
# determine the default, with $INIT_CONF if set, or the default common
# to all the converters
@@ -1278,6 +1303,39 @@ sub encoded_output_file_name($$)
return Texinfo::Convert::Utils::encoded_output_file_name($self, $file_name);
}
+# This is used when the formatted text has no comment nor new line, but
+# one want to add the comment or new line from the original arg
+sub format_comment_or_return_end_line($$)
+{
+ my $self = shift;
+ my $element = shift;
+
+ my $end_line;
+
+ my $comment = $element->{'args'}->[-1]->{'info'}->{'comment_at_end'}
+ if $element->{'args'} and $element->{'args'}->[-1]->{'info'};
+
+ if ($comment) {
+ $end_line = $self->convert_tree($comment);
+ } elsif ($element->{'args'} and $element->{'args'}->[-1]->{'info'}
+ and $element->{'args'}->[-1]->{'info'}->{'spaces_after_argument'}) {
+ my $text = $element->{'args'}->[-1]
+ ->{'info'}->{'spaces_after_argument'}->{'text'};
+ if (chomp($text)) {
+ $end_line = "\n";
+ } else {
+ $end_line = '';
+ }
+ } else {
+ $end_line = '';
+ }
+ return $end_line;
+}
+
+
+
+# Specific elements formatting helper functions
+
sub txt_image_text($$$)
{
my ($self, $element, $basefile) = @_;
@@ -1327,7 +1385,6 @@ sub txt_image_text($$$)
return undef, undef;
}
-
sub float_type_number($$)
{
my $self = shift;
@@ -1413,35 +1470,6 @@ sub float_name_caption($$)
return ($caption_element, $prepended);
}
-# This is used when the formatted text has no comment nor new line, but
-# one want to add the comment or new line from the original arg
-sub format_comment_or_return_end_line($$)
-{
- my $self = shift;
- my $element = shift;
-
- my $end_line;
-
- my $comment = $element->{'args'}->[-1]->{'info'}->{'comment_at_end'}
- if $element->{'args'} and $element->{'args'}->[-1]->{'info'};
-
- if ($comment) {
- $end_line = $self->convert_tree($comment);
- } elsif ($element->{'args'} and $element->{'args'}->[-1]->{'info'}
- and $element->{'args'}->[-1]->{'info'}->{'spaces_after_argument'}) {
- my $text = $element->{'args'}->[-1]
- ->{'info'}->{'spaces_after_argument'}->{'text'};
- if (chomp($text)) {
- $end_line = "\n";
- } else {
- $end_line = '';
- }
- } else {
- $end_line = '';
- }
- return $end_line;
-}
-
sub table_item_content_tree($$)
{
my $self = shift;
@@ -1611,6 +1639,10 @@ sub get_converter_indices_sorted_by_index($)
return undef;
}
+
+
+# sort_element_counts code
+
sub _count_converted_text($$)
{
my $converted_text = shift;
@@ -1679,11 +1711,6 @@ sub sort_element_counts($$;$$)
return (\@sorted_name_counts_array, $result);
}
-sub XS_get_unclosed_stream($$)
-{
- return undef;
-}
-
########################################################################