texinfo-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

branch master updated: * tp/Texinfo/Convert/Text.pm (converter_line_erro


From: Patrice Dumas
Subject: branch master updated: * tp/Texinfo/Convert/Text.pm (converter_line_error) (converter_document_warn, get_converter_errors): implement the functions needed in Texinfo::Convert::Utils::expand_verbatiminclude to get the error messages by using the Texinfo::Convert::Converter code.
Date: Mon, 30 Dec 2024 00:01:38 -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 920f16ba64 * tp/Texinfo/Convert/Text.pm (converter_line_error) 
(converter_document_warn, get_converter_errors): implement the functions needed 
in Texinfo::Convert::Utils::expand_verbatiminclude to get the error messages by 
using the Texinfo::Convert::Converter code.
920f16ba64 is described below

commit 920f16ba644ec87b97257040d0102ec362909971
Author: Patrice Dumas <pertusus@free.fr>
AuthorDate: Mon Dec 30 05:55:32 2024 +0100

    * tp/Texinfo/Convert/Text.pm (converter_line_error)
    (converter_document_warn, get_converter_errors): implement the
    functions needed in Texinfo::Convert::Utils::expand_verbatiminclude to
    get the error messages by using the Texinfo::Convert::Converter code.
    
    * tp/Texinfo/XS/convert/ConvertXS.xs (text_convert_tree),
    tp/Texinfo/XS/main/convert_to_text.c (destroy_text_options)
    (convert_to_text_internal), tp/Texinfo/XS/main/convert_to_text.h
    (TEXT_OPTIONS): add ERROR_MESSAGE_LIST error_messages field to
    TEXT_OPTIONS.  Use if for verbatiminclude if there is no associated
    converter, be it text or other output converter, which means that we
    are in C callde from Perl Text Converter.  Pass the error_messages
    information back to Perl.
    
    * tp/Texinfo/Convert/Text.pm (import): use a hash to specify overriden
    functions.
---
 ChangeLog                                          | 19 ++++++
 tp/Texinfo/Convert/Text.pm                         | 70 ++++++++++++++++++----
 tp/Texinfo/XS/convert/ConvertXS.xs                 | 19 ++++++
 tp/Texinfo/XS/main/convert_to_text.c               | 10 +++-
 tp/Texinfo/XS/main/convert_to_text.h               |  3 +
 tp/tests/encoded/list-of-tests                     |  4 +-
 .../os%c3%a9_utf8_no_setfilename.2                 |  1 +
 .../non_ascii_test_rawtext/os%c3%a9_utf8.2         |  1 +
 .../verbatiminclude_names_latin1.2                 |  1 +
 .../verbatiminclude_names_latin1.2                 |  2 +
 10 files changed, 115 insertions(+), 15 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index f464121421..7a4628d246 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,22 @@
+2024-12-30  Patrice Dumas  <pertusus@free.fr>
+
+       * tp/Texinfo/Convert/Text.pm (converter_line_error)
+       (converter_document_warn, get_converter_errors): implement the
+       functions needed in Texinfo::Convert::Utils::expand_verbatiminclude to
+       get the error messages by using the Texinfo::Convert::Converter code.
+
+       * tp/Texinfo/XS/convert/ConvertXS.xs (text_convert_tree),
+       tp/Texinfo/XS/main/convert_to_text.c (destroy_text_options)
+       (convert_to_text_internal), tp/Texinfo/XS/main/convert_to_text.h
+       (TEXT_OPTIONS): add ERROR_MESSAGE_LIST error_messages field to
+       TEXT_OPTIONS.  Use if for verbatiminclude if there is no associated
+       converter, be it text or other output converter, which means that we
+       are in C callde from Perl Text Converter.  Pass the error_messages
+       information back to Perl.
+
+       * tp/Texinfo/Convert/Text.pm (import): use a hash to specify overriden
+       functions.
+
 2024-12-30  Gavin Smith <gavinsmith0123@gmail.com>
 
        * tp/tests/run_parser_all.sh (post_process_output):
diff --git a/tp/Texinfo/Convert/Text.pm b/tp/Texinfo/Convert/Text.pm
index 344619d744..3c0ce9d8db 100644
--- a/tp/Texinfo/Convert/Text.pm
+++ b/tp/Texinfo/Convert/Text.pm
@@ -35,6 +35,7 @@ use Encode qw(decode);
 use Texinfo::Convert::ConvertXS;
 use Texinfo::XSLoader;
 
+use Texinfo::Report;
 use Texinfo::Commands;
 use Texinfo::Common;
 use Texinfo::Convert::Unicode;
@@ -57,19 +58,37 @@ our $VERSION = '7.2';
 
 my $XS_convert = Texinfo::XSLoader::XS_convert_enabled();
 
+my %XS_overrides = (
+  # We do not override directly convert_to_text, we must check at runtime
+  # that the document tree was stored by the XS parser.
+  "Texinfo::Convert::Text::_convert_tree_with_XS"
+   => "Texinfo::Convert::ConvertXS::text_convert_tree",
+  "Texinfo::Convert::Text::destroy"
+   => "Texinfo::Convert::ConvertXS::destroy",
+
+
+  # if the output or convert functions are overriden the following
+  # should probably be overriden using that kind of function
+  #"Texinfo::Convert::Text::get_converter_errors"
+  # => "Texinfo::Convert::ConvertXS::get_converter_errors",
+
+  # Probably no use overriding, as if XS/C is used they are only
+  # called from C
+  #"Texinfo::Convert::Text::converter_line_error"
+  # => "Texinfo::Convert::ConvertXS::converter_line_error",
+  #"Texinfo::Convert::Text::converter_document_warn"
+  # => "Texinfo::Convert::ConvertXS::converter_document_warn",
+);
+
 our $module_loaded = 0;
 sub import {
   if (!$module_loaded) {
     if ($XS_convert) {
-      # We do not simply override, we must check at runtime
-      # that the document tree was stored by the XS parser.
-      Texinfo::XSLoader::override(
-        "Texinfo::Convert::Text::_convert_tree_with_XS",
-        "Texinfo::Convert::ConvertXS::text_convert_tree");
-      Texinfo::XSLoader::override(
-       "Texinfo::Convert::Text::destroy",
-       "Texinfo::Convert::ConvertXS::destroy");
+      foreach my $sub (keys(%XS_overrides)) {
+        Texinfo::XSLoader::override($sub, $XS_overrides{$sub});
+      }
     }
+
     $module_loaded = 1;
   }
   # The usual import method
@@ -851,7 +870,8 @@ sub convert_to_text($;$)
 }
 
 
-# Implement the converters API, but as simply as possible
+# Implement the converters API simply.  The POD documentation does not
+# cover this possibility for doing the conversion.
 # initialization
 sub converter($;$)
 {
@@ -1081,17 +1101,43 @@ sub set_conf($$$)
   return 1;
 }
 
-sub converter_line_error()
+# used in Texinfo::Convert::Utils::expand_verbatiminclude
+sub converter_line_error($$$;$)
 {
+  my $self = shift;
+  my $text = shift;
+  my $error_location_info = shift;
+  my $continuation = shift;
+
+  my $message = Texinfo::Report::format_line_message('error', $text,
+                                 $error_location_info, $continuation,
+                                            $self->get_conf('DEBUG'));
+  push @{$self->{'error_warning_messages'}}, $message;
 }
 
-sub converter_document_warn()
+# used in Texinfo::Convert::Utils::expand_verbatiminclude
+sub converter_document_warn($$;$)
 {
+  my $self = shift;
+  my $text = shift;
+  my $continuation = shift;
+
+  my $program_name;
+
+  if ($self->get_conf('PROGRAM') && $self->get_conf('PROGRAM') ne '') {
+    $program_name = $self->get_conf('PROGRAM');
+  }
+
+  my $message
+      = Texinfo::Report::format_document_message('warning', $text,
+                                        $program_name, $continuation);
+  push @{$self->{'error_warning_messages'}}, $message;
 }
 
 sub get_converter_errors($)
 {
-  return undef;
+  my $self = shift;
+  return $self->{'error_warning_messages'};
 }
 
 sub converter_defaults()
diff --git a/tp/Texinfo/XS/convert/ConvertXS.xs 
b/tp/Texinfo/XS/convert/ConvertXS.xs
index 10953f96fa..7a46d96f5f 100644
--- a/tp/Texinfo/XS/convert/ConvertXS.xs
+++ b/tp/Texinfo/XS/convert/ConvertXS.xs
@@ -734,6 +734,25 @@ text_convert_tree (SV *options_in, SV *tree_in)
 
             result = convert_to_text (document->tree, text_options);
 
+            /* in case we were called from a text converter, pass the
+               error messages.  If not called from a Perl converter they
+               probably will be ignored, but the errors should only come
+               from errors with @verbatiminclude in case there is not already
+               a converter to get the errors, which should only happen with
+               a text converter */
+            if (text_options->error_messages.number > 0
+                && SvOK (options_in))
+              {
+                const char* key = "error_warning_messages";
+                AV *errors_av
+                   = build_errors (text_options->error_messages.list,
+                                      text_options->error_messages.number);
+                HV *options_hv = (HV *) SvRV (options_in);
+                hv_store (options_hv, key, strlen (key),
+                          newRV_noinc ((SV *) errors_av), 0);
+                wipe_error_message_list (&text_options->error_messages);
+              }
+
             destroy_text_options (text_options);
             RETVAL = newSVpv_utf8 (result, 0);
             non_perl_free (result);
diff --git a/tp/Texinfo/XS/main/convert_to_text.c 
b/tp/Texinfo/XS/main/convert_to_text.c
index f2eb9bf92c..77c394f731 100644
--- a/tp/Texinfo/XS/main/convert_to_text.c
+++ b/tp/Texinfo/XS/main/convert_to_text.c
@@ -36,6 +36,8 @@
 #include "customization_options.h"
 #include "utils.h"
 #include "unicode.h"
+/* wipe_error_message_list */
+#include "errors.h"
 /* for PARSED_DEF cdt_tree find_innermost_accent_contents add_heading_number
    translated_command_tree ... */
 #include "convert_utils.h"
@@ -80,6 +82,11 @@ destroy_text_options (TEXT_OPTIONS *text_options)
       free_options (text_options->self_converter_options);
       free (text_options->self_converter_options);
     }
+  if (text_options->error_messages.number)
+    fprintf (stderr,
+             "WARNING: destroy_text_options error messages ignored: %zu\n",
+             text_options->error_messages.number);
+  wipe_error_message_list (&text_options->error_messages);
   free (text_options);
 }
 
@@ -982,6 +989,7 @@ convert_to_text_internal (const ELEMENT *element, 
TEXT_OPTIONS *text_options,
                                        0, element);
               } else {
                 GLOBAL_INFO *global_information = 0;
+                error_messages = &text_options->error_messages;
                 if (text_options->document_descriptor) {
                   DOCUMENT *document
                     = retrieve_document (text_options->document_descriptor);
@@ -989,7 +997,7 @@ convert_to_text_internal (const ELEMENT *element, 
TEXT_OPTIONS *text_options,
                     global_information = &document->global_info;
                 }
                 verbatim_include_verbatim
-                  = expand_verbatiminclude (0,
+                  = expand_verbatiminclude (error_messages,
                                 text_options->self_converter_options,
                                         global_information, element);
               }
diff --git a/tp/Texinfo/XS/main/convert_to_text.h 
b/tp/Texinfo/XS/main/convert_to_text.h
index f36d9b48f9..257b256ade 100644
--- a/tp/Texinfo/XS/main/convert_to_text.h
+++ b/tp/Texinfo/XS/main/convert_to_text.h
@@ -30,6 +30,9 @@ typedef struct TEXT_OPTIONS {
       in which case other_options is set */
     OPTIONS *self_converter_options; /* text converter options available
                                         as the OPTIONS structure */
+    ERROR_MESSAGE_LIST error_messages; /* used if there is a Perl text
+                              converter, XS is used and there is no C
+                              converter */
     size_t document_descriptor;
 } TEXT_OPTIONS;
 
diff --git a/tp/tests/encoded/list-of-tests b/tp/tests/encoded/list-of-tests
index b8748b3090..3e1823919d 100644
--- a/tp/tests/encoded/list-of-tests
+++ b/tp/tests/encoded/list-of-tests
@@ -57,9 +57,9 @@ verbatiminclude_names_latin1_html 
verbatiminclude_names_latin1.texi --html -c ME
 
 verbatiminclude_names_latin1_html_explicit_encoding 
verbatiminclude_names_latin1.texi --html -c INPUT_FILE_NAME_ENCODING=UTF-8 -c 
MESSAGE_ENCODING=UTF-8 -D 'neednonasciifilenames Need non-ASCII file names'
 
-verbatiminclude_names_latin1_rawtext verbatiminclude_names_latin1.texi -c 
TEXINFO_OUTPUT_FORMAT=rawtext -D 'neednonasciifilenames Need non-ASCII file 
names'
+verbatiminclude_names_latin1_rawtext verbatiminclude_names_latin1.texi -c 
TEXINFO_OUTPUT_FORMAT=rawtext -c MESSAGE_ENCODING=UTF-8 -D 
'neednonasciifilenames Need non-ASCII file names'
 
-verbatiminclude_names_latin1_explicit_encoding_rawtext 
verbatiminclude_names_latin1.texi -c TEXINFO_OUTPUT_FORMAT=rawtext -c 
INPUT_FILE_NAME_ENCODING=UTF-8 -D 'neednonasciifilenames Need non-ASCII file 
names'
+verbatiminclude_names_latin1_explicit_encoding_rawtext 
verbatiminclude_names_latin1.texi -c TEXINFO_OUTPUT_FORMAT=rawtext -c 
INPUT_FILE_NAME_ENCODING=UTF-8 -c MESSAGE_ENCODING=UTF-8 -D 
'neednonasciifilenames Need non-ASCII file names'
 
 # test that a file with some latin1 characters, typically used for person names
 # but no declared encoding does not give a result that is too bad, and lead
diff --git 
a/tp/tests/encoded/res_parser/non_ascii_no_setfilename_test_rawtext/os%c3%a9_utf8_no_setfilename.2
 
b/tp/tests/encoded/res_parser/non_ascii_no_setfilename_test_rawtext/os%c3%a9_utf8_no_setfilename.2
index 0f23833d61..2fc1ef1c93 100644
--- 
a/tp/tests/encoded/res_parser/non_ascii_no_setfilename_test_rawtext/os%c3%a9_utf8_no_setfilename.2
+++ 
b/tp/tests/encoded/res_parser/non_ascii_no_setfilename_test_rawtext/os%c3%a9_utf8_no_setfilename.2
@@ -1,2 +1,3 @@
 osé_utf8_no_setfilename.texi:13: warning: undefined flag: vùr
 osé_utf8_no_setfilename.texi:24: @include: could not find not_existïng.téxi
+osé_utf8_no_setfilename.texi:28: @verbatiminclude: could not find 
vi_not_existïng.téxi
diff --git a/tp/tests/encoded/res_parser/non_ascii_test_rawtext/os%c3%a9_utf8.2 
b/tp/tests/encoded/res_parser/non_ascii_test_rawtext/os%c3%a9_utf8.2
index 657b8b0938..27caf658b6 100644
--- a/tp/tests/encoded/res_parser/non_ascii_test_rawtext/os%c3%a9_utf8.2
+++ b/tp/tests/encoded/res_parser/non_ascii_test_rawtext/os%c3%a9_utf8.2
@@ -1,2 +1,3 @@
 osé_utf8.texi:15: warning: undefined flag: vùr
 osé_utf8.texi:26: @include: could not find not_existïng.téxi
+osé_utf8.texi:30: @verbatiminclude: could not find vi_not_existïng.téxi
diff --git 
a/tp/tests/encoded/res_parser/verbatiminclude_names_latin1_explicit_encoding_rawtext/verbatiminclude_names_latin1.2
 
b/tp/tests/encoded/res_parser/verbatiminclude_names_latin1_explicit_encoding_rawtext/verbatiminclude_names_latin1.2
index e69de29bb2..4d68bf4af9 100644
--- 
a/tp/tests/encoded/res_parser/verbatiminclude_names_latin1_explicit_encoding_rawtext/verbatiminclude_names_latin1.2
+++ 
b/tp/tests/encoded/res_parser/verbatiminclude_names_latin1_explicit_encoding_rawtext/verbatiminclude_names_latin1.2
@@ -0,0 +1 @@
+verbatiminclude_names_latin1.texi:20: @verbatiminclude: could not find 
vi_not_existïng.téxi
diff --git 
a/tp/tests/encoded/res_parser/verbatiminclude_names_latin1_rawtext/verbatiminclude_names_latin1.2
 
b/tp/tests/encoded/res_parser/verbatiminclude_names_latin1_rawtext/verbatiminclude_names_latin1.2
index e69de29bb2..69e86f93c2 100644
--- 
a/tp/tests/encoded/res_parser/verbatiminclude_names_latin1_rawtext/verbatiminclude_names_latin1.2
+++ 
b/tp/tests/encoded/res_parser/verbatiminclude_names_latin1_rawtext/verbatiminclude_names_latin1.2
@@ -0,0 +1,2 @@
+verbatiminclude_names_latin1.texi:18: @verbatiminclude: could not find 
included_akçentêd.texi
+verbatiminclude_names_latin1.texi:20: @verbatiminclude: could not find 
vi_not_existïng.téxi



reply via email to

[Prev in Thread] Current Thread [Next in Thread]