texinfo-commits
[Top][All Lists]
Advanced

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

[no subject]


From: Patrice Dumas
Date: Fri, 4 Oct 2024 06:06:17 -0400 (EDT)

branch: master
commit cf04ff578071bb44cc810f657c40c7eeeb136414
Author: Patrice Dumas <pertusus@free.fr>
AuthorDate: Sun Aug 11 09:14:04 2024 +0200

    * tp/Texinfo/XS/main/build_perl_info.c (add_formatted_error_messages),
    tp/Texinfo/XS/main/document_types.h (ERROR_MESSAGE_LIST),
    tp/Texinfo/XS/main/errors.c (message_list_line_formatted_message)
    (message_list_document_formatted_message): add error_nrs field in
    ERROR_MESSAGE_LIST and set it.  Use it in
    add_formatted_error_messages.
    
    * tp/Texinfo/XS/main/errors.c (error_message_text)
    (handle_error_messages): add handle_error_messages that adds file
    information to error messages and output them.
---
 ChangeLog                            |  13 ++++
 tp/Texinfo/XS/main/build_perl_info.c |   6 +-
 tp/Texinfo/XS/main/document_types.h  |   2 +
 tp/Texinfo/XS/main/errors.c          | 113 +++++++++++++++++++++++++++++++++--
 tp/Texinfo/XS/main/errors.h          |   4 ++
 5 files changed, 132 insertions(+), 6 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index ab670b014d..17c0e8791d 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,16 @@
+2024-08-11  Patrice Dumas  <pertusus@free.fr>
+
+       * tp/Texinfo/XS/main/build_perl_info.c (add_formatted_error_messages),
+       tp/Texinfo/XS/main/document_types.h (ERROR_MESSAGE_LIST),
+       tp/Texinfo/XS/main/errors.c (message_list_line_formatted_message)
+       (message_list_document_formatted_message): add error_nrs field in
+       ERROR_MESSAGE_LIST and set it.  Use it in
+       add_formatted_error_messages.
+
+       * tp/Texinfo/XS/main/errors.c (error_message_text)
+       (handle_error_messages): add handle_error_messages that adds file
+       information to error messages and output them.
+
 2024-08-11  Patrice Dumas  <pertusus@free.fr>
 
        * tp/t/test_parser_registrar.t: use is instead of ok when relevant.
diff --git a/tp/Texinfo/XS/main/build_perl_info.c 
b/tp/Texinfo/XS/main/build_perl_info.c
index cb1d1fbd0a..1fd7ca9cdd 100644
--- a/tp/Texinfo/XS/main/build_perl_info.c
+++ b/tp/Texinfo/XS/main/build_perl_info.c
@@ -1227,6 +1227,7 @@ add_formatted_error_messages (const ERROR_MESSAGE_LIST 
*error_messages,
   if (errors_warnings_sv && SvOK (*errors_warnings_sv))
     {
       int error_nrs = 0;
+      /* initialize number of errors from the existing errors in Perl */
       if (error_nrs_sv && SvOK (*error_nrs_sv))
         {
           error_nrs = SvIV (*error_nrs_sv);
@@ -1244,6 +1245,7 @@ add_formatted_error_messages (const ERROR_MESSAGE_LIST 
*error_messages,
         }
       else
         {
+          /* add errors from error_messages */
           AV *av = (AV *)SvRV (*errors_warnings_sv);
 
           for (i = 0; i < error_messages->number; i++)
@@ -1251,11 +1253,11 @@ add_formatted_error_messages (const ERROR_MESSAGE_LIST 
*error_messages,
               const ERROR_MESSAGE error_msg = error_messages->list[i];
               SV *sv = convert_error (error_msg);
 
-              if (error_msg.type == MSG_error && !error_msg.continuation)
-                error_nrs++;
               av_push (av, sv);
             }
 
+          error_nrs += error_messages->error_nrs;
+
           if (error_nrs)
             {
               if (error_nrs_sv && SvOK (*error_nrs_sv))
diff --git a/tp/Texinfo/XS/main/document_types.h 
b/tp/Texinfo/XS/main/document_types.h
index 7f411f105e..a63a1034f6 100644
--- a/tp/Texinfo/XS/main/document_types.h
+++ b/tp/Texinfo/XS/main/document_types.h
@@ -65,6 +65,8 @@ typedef struct ERROR_MESSAGE_LIST {
     ERROR_MESSAGE *list;
     size_t number;
     size_t space;
+    /* number of messages of type error that are not continuations */
+    size_t error_nrs;
 } ERROR_MESSAGE_LIST;
 
 typedef struct KEY_STRING_PAIR {
diff --git a/tp/Texinfo/XS/main/errors.c b/tp/Texinfo/XS/main/errors.c
index a434cd8923..10ac84b733 100644
--- a/tp/Texinfo/XS/main/errors.c
+++ b/tp/Texinfo/XS/main/errors.c
@@ -52,7 +52,11 @@ reallocate_error_messages (ERROR_MESSAGE_LIST 
*error_messages)
   return error_message;
 }
 
-/* only directly used for messages passed from perl */
+/* only directly used for messages passed from Perl */
+/* Format and register a message.  The file information present in
+   CMD_SOURCE_INFO is not included in the message, because the file name
+   should be in the input encoding while the message is in UTF-8, encoding
+   the message and adding the file information is left for later */
 void
 message_list_line_formatted_message (ERROR_MESSAGE_LIST *error_messages,
                            enum error_type type, int continuation,
@@ -91,14 +95,21 @@ message_list_line_formatted_message (ERROR_MESSAGE_LIST 
*error_messages,
                        pgettext ("Texinfo source file error in macro",
                                  "%s (possibly involving @%s)"),
                        error_message->message, 
error_message->source_info.macro);
+          if (!continuation)
+            error_messages->error_nrs++;
         }
 #else
       if (type == MSG_warning)
         text_printf (&error_line, "warning: %s (possibly involving @%s)",
                      error_message->message, error_message->source_info.macro);
       else
-        text_printf (&error_line, "%s (possibly involving @%s)",
-                     error_message->message, error_message->source_info.macro);
+        {
+          text_printf (&error_line, "%s (possibly involving @%s)",
+                    error_message->message, error_message->source_info.macro);
+
+          if (!continuation)
+            error_messages->error_nrs++;
+        }
 #endif
     }
   else
@@ -115,7 +126,12 @@ message_list_line_formatted_message (ERROR_MESSAGE_LIST 
*error_messages,
 #endif
         }
       else
-        text_printf (&error_line, "%s", error_message->message);
+        {
+          text_printf (&error_line, "%s", error_message->message);
+
+          if (!continuation)
+            error_messages->error_nrs++;
+        }
     }
   text_append (&error_line, "\n");
 
@@ -153,6 +169,7 @@ vmessage_list_line_error (ERROR_MESSAGE_LIST 
*error_messages,
   free (message);
 }
 
+/* Format and register a message. */
 void
 message_list_document_formatted_message (ERROR_MESSAGE_LIST *error_messages,
                                          const OPTIONS *conf,
@@ -189,6 +206,9 @@ message_list_document_formatted_message (ERROR_MESSAGE_LIST 
*error_messages,
         {
           text_printf (&error_line, "%s: %s",
                        conf->PROGRAM.o.string, error_message->message);
+
+          if (!continuation)
+            error_messages->error_nrs++;
         }
     }
   else
@@ -208,6 +228,9 @@ message_list_document_formatted_message (ERROR_MESSAGE_LIST 
*error_messages,
       else
         {
           text_append (&error_line, error_message->message);
+
+          if (!continuation)
+            error_messages->error_nrs++;
         }
     }
   text_append (&error_line, "\n");
@@ -338,6 +361,51 @@ message_list_document_warn (ERROR_MESSAGE_LIST 
*error_messages,
                                         format, v);
 }
 
+/* setup error message by adding file information and converting the
+   error line to message encoding */
+/* if USE_FILENAME is set, remove file information directories */
+static void
+error_message_text (const ERROR_MESSAGE *error_msg, int use_filename,
+                    ENCODING_CONVERSION *conversion, TEXT *text)
+{
+  if (error_msg->source_info.file_name)
+    {
+      if (use_filename)
+        {
+          char *file_name_and_directory[2];
+          parse_file_path (error_msg->source_info.file_name,
+                           file_name_and_directory);
+
+          text_append (text, file_name_and_directory[0]);
+
+          free (file_name_and_directory[0]);
+          free (file_name_and_directory[1]);
+        }
+      else
+        text_append (text, error_msg->source_info.file_name);
+
+      text_append_n (text, ":", 1);
+    }
+  if (error_msg->source_info.line_nr > 0)
+    {
+      text_printf (text, "%d:", error_msg->source_info.line_nr);
+    }
+
+  if (text->end > 0)
+    text_append_n (text, " ", 1);
+
+  if (conversion)
+    {
+      char *encoded = encode_with_iconv (conversion->iconv,
+                                         error_msg->error_line,
+                                         &error_msg->source_info);
+      text_append (text, encoded);
+      free (encoded);
+    }
+  else
+    text_append (text, error_msg->error_line);
+}
+
 static void
 wipe_error_messages (ERROR_MESSAGE_LIST *error_messages)
 {
@@ -363,3 +431,40 @@ clear_error_message_list (ERROR_MESSAGE_LIST 
*error_messages)
   wipe_error_messages (error_messages);
   error_messages->number = 0;
 }
+
+/* add file information to message and print out.  Similar to texi2any.pl
+   handle_errors.  Used from C only */
+size_t
+handle_error_messages (ERROR_MESSAGE_LIST *error_messages,
+                       int no_warn, int use_filename,
+                       const char *message_encoding)
+{
+  TEXT text;
+  ENCODING_CONVERSION *conversion = 0;
+  size_t i;
+  size_t error_nrs = error_messages->error_nrs;
+
+  if (message_encoding)
+    conversion = get_encoding_conversion (message_encoding,
+                                          &output_conversions);
+
+  text_init (&text);
+
+  for (i = 0; i < error_messages->number; i++)
+    {
+      const ERROR_MESSAGE *error_msg = &error_messages->list[i];
+      if (error_msg->type == MSG_warning && no_warn)
+        continue;
+
+      text_reset (&text);
+      error_message_text (error_msg, use_filename, conversion, &text);
+      fprintf (stderr, "%s", text.text);
+    }
+
+  free (text.text);
+
+  clear_error_message_list (error_messages);
+
+  return error_nrs;
+}
+
diff --git a/tp/Texinfo/XS/main/errors.h b/tp/Texinfo/XS/main/errors.h
index 6d3607262d..cfaa345da2 100644
--- a/tp/Texinfo/XS/main/errors.h
+++ b/tp/Texinfo/XS/main/errors.h
@@ -2,6 +2,7 @@
 #ifndef ERRORS_H
 #define ERRORS_H
 
+#include <stddef.h>
 #include <stdarg.h>
 
 #include "tree_types.h"
@@ -52,4 +53,7 @@ void vmessage_list_command_warn (ERROR_MESSAGE_LIST 
*error_messages,
                             const OPTIONS *conf,
                             const ELEMENT *e, const char *format, va_list v);
 
+size_t handle_error_messages (ERROR_MESSAGE_LIST *error_messages,
+                              int no_warn, int use_filename,
+                              const char *message_encoding);
 #endif



reply via email to

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