[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[no subject]
From: |
Patrice Dumas |
Date: |
Sat, 25 Jan 2025 04:40:00 -0500 (EST) |
branch: master
commit 01da30d8e98ff9fb01fed8b9f795e2908c84d321
Author: Patrice Dumas <pertusus@free.fr>
AuthorDate: Sat Jan 25 10:21:34 2025 +0100
* tp/Texinfo/Convert/Text.pm (output): handle the case of output file
name not being set.
* tp/Texinfo/XS/convert/rawtext_converter_api.c (rawtext_output):
simplify caode in case of output file not set.
* tp/t/z_misc/raw_text_converter.t ($reference_result_text)
($converter_undef_outfile, test output with unsef outfile): add test
with outfile not set. Change in spacing.
---
ChangeLog | 12 +++++++++++
tp/Texinfo/Convert/Text.pm | 25 +++++++++++-----------
tp/Texinfo/XS/convert/rawtext_converter_api.c | 10 ++++-----
tp/t/z_misc/raw_text_converter.t | 30 +++++++++++++++++++++------
4 files changed, 53 insertions(+), 24 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index ef37077477..806ebbf7e5 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,15 @@
+2025-01-25 Patrice Dumas <pertusus@free.fr>
+
+ * tp/Texinfo/Convert/Text.pm (output): handle the case of output file
+ name not being set.
+
+ * tp/Texinfo/XS/convert/rawtext_converter_api.c (rawtext_output):
+ simplify caode in case of output file not set.
+
+ * tp/t/z_misc/raw_text_converter.t ($reference_result_text)
+ ($converter_undef_outfile, test output with unsef outfile): add test
+ with outfile not set. Change in spacing.
+
2025-01-24 Gavin Smith <gavinsmith0123@gmail.com>
* info/info.c (info_short_help): mark translations with N_
diff --git a/tp/Texinfo/Convert/Text.pm b/tp/Texinfo/Convert/Text.pm
index 800664c101..d25ac0d51a 100644
--- a/tp/Texinfo/Convert/Text.pm
+++ b/tp/Texinfo/Convert/Text.pm
@@ -1005,22 +1005,21 @@ sub output($$)
}
if (defined($outfile)) {
$outfile .= '.txt';
- }
- if (defined($self->{'SUBDIR'})) {
- # FIXME in theory here $outfile could be undef. Check if possible
- my $destination_directory = File::Spec->canonpath($self->{'SUBDIR'});
- my ($encoded_destination_directory, $destination_directory_encoding)
- = Texinfo::Convert::Utils::encoded_output_file_name($self,
+ if (defined($self->{'SUBDIR'})) {
+ my $destination_directory = File::Spec->canonpath($self->{'SUBDIR'});
+ my ($encoded_destination_directory, $destination_directory_encoding)
+ = Texinfo::Convert::Utils::encoded_output_file_name($self,
$destination_directory);
- if (! -d $encoded_destination_directory) {
- if (!mkdir($encoded_destination_directory, oct(755))) {
- warn sprintf(__(
- "could not create directory `%s': %s"),
- $destination_directory, $!)."\n";
- return undef;
+ if (! -d $encoded_destination_directory) {
+ if (!mkdir($encoded_destination_directory, oct(755))) {
+ warn sprintf(__(
+ "could not create directory `%s': %s"),
+ $destination_directory, $!)."\n";
+ return undef;
+ }
}
+ $outfile = join('/', ($destination_directory, $outfile));
}
- $outfile = join('/', ($destination_directory, $outfile));
}
} else {
$outfile = $self->{'OUTFILE'};
diff --git a/tp/Texinfo/XS/convert/rawtext_converter_api.c
b/tp/Texinfo/XS/convert/rawtext_converter_api.c
index 4d99cfbe2d..a9de807ec0 100644
--- a/tp/Texinfo/XS/convert/rawtext_converter_api.c
+++ b/tp/Texinfo/XS/convert/rawtext_converter_api.c
@@ -123,7 +123,6 @@ rawtext_output (CONVERTER *converter, DOCUMENT *document)
if (!converter->conf->OUTFILE.o.string)
{
char *basename_for_outfile = 0;
- char *basefile_for_outfile = 0;
if (setfilename)
{
basename_for_outfile = remove_extension (setfilename);
@@ -132,11 +131,12 @@ rawtext_output (CONVERTER *converter, DOCUMENT *document)
basename_for_outfile = strdup (input_basename);
if (basename_for_outfile)
- xasprintf (&basefile_for_outfile, "%s.txt", basename_for_outfile);
- free (basename_for_outfile);
-
- if (basefile_for_outfile)
{
+ char *basefile_for_outfile;
+
+ xasprintf (&basefile_for_outfile, "%s.txt", basename_for_outfile);
+ free (basename_for_outfile);
+
if (converter->conf->SUBDIR.o.string)
{
char *destination_directory
diff --git a/tp/t/z_misc/raw_text_converter.t b/tp/t/z_misc/raw_text_converter.t
index b3424bb3e5..5dc739daf0 100644
--- a/tp/t/z_misc/raw_text_converter.t
+++ b/tp/t/z_misc/raw_text_converter.t
@@ -5,9 +5,13 @@ use Texinfo::ModulePath (undef, undef, undef, 'updirs' => 3);
use Test::More;
-BEGIN { plan tests => 4; }
+BEGIN { plan tests => 5; }
use Texinfo::Parser;
+# The conversion to raw text is possibly done with XS, but the converter
+# itself is the Perl version as there is no XS interface for the Perl converter
+# functions even though there is a full implementation in C of a raw text
+# converter that can be used from C.
use Texinfo::Convert::Text;
ok(1);
@@ -38,7 +42,8 @@ my $result_text = $converter->convert($document);
# This also tests a situation where Texinfo::Structuring::sectioning_structure
# is not called. There are therefore no sectioning commands numbers.
-is ($result_text, "A top
+my $reference_result_text =
+"A top
*****
@@ -50,7 +55,8 @@ Chap
Conclusion
**********
-", 'test convert');
+";
+is($result_text, $reference_result_text, 'test convert');
#print STDERR "$result_text";
@@ -58,12 +64,24 @@ my $tree = $parser->parse_texi_line('@code{@bullet{}
something} ``@^a---');
my $result_line = $converter->convert_tree($tree);
-is ($result_line, "* something \"\x{00E2}--", 'test convert_tree');
+is($result_line, "* something \"\x{00E2}--", 'test convert_tree');
#print STDERR "RRR '$result_line'\n";
Texinfo::Convert::Text::set_options_code($converter);
my $result_code = $converter->convert_tree($tree);
Texinfo::Convert::Text::reset_options_code($converter);
-is ($result_code, "* something ``\x{00E2}---",
- 'test convert_tree in code context');
+is($result_code, "* something ``\x{00E2}---",
+ 'test convert_tree in code context');
+
+my $converter_undef_outfile = Texinfo::Convert::Text->converter({'TEST' => 1,
+ 'ASCII_GLYPH' => 1,
+ 'ENABLE_ENCODING' => 1,
+ # for the test, OUTFILE can be explicitly undef or not set
+ #'OUTFILE' => undef,
+ 'SUBDIR' => 'toto'});
+
+my $result_undef_outfile = $converter_undef_outfile->output($document);
+
+is($result_undef_outfile, $reference_result_text,
+ 'test output with unset outfile');