texinfo-commits
[Top][All Lists]
Advanced

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

[no subject]


From: Patrice Dumas
Date: Sun, 7 Aug 2022 17:33:22 -0400 (EDT)

branch: master
commit 530c94224cb790b108b3b483f39f5d8d858f217c
Author: Patrice Dumas <pertusus@free.fr>
AuthorDate: Sun Aug 7 23:33:01 2022 +0200

    Init file loading errors and warning interface setup and use
    
    * tp/Texinfo/Config.pm (@init_file_loading_messages)
    (GNUT_load_init_file, texinfo_register_init_loading_error)
    (texinfo_register_init_loading_warning): replace
    texinfo_register_init_loading_failure by two functions,
    texinfo_register_init_loading_error and
    texinfo_register_init_loading_warning to be able to register
    errors and warnings.
    Use a stack, @init_file_loading_messages to be sure to separate
    each init file loading messages even if an init file loads another.
    
    * tp/init/highlight_syntax.pm: get the available languages upon
    loading and use texinfo_register_init_loading_error and
    texinfo_register_init_loading_warning for errors and warnings.
---
 ChangeLog                   | 18 +++++++++++++++++
 tp/Texinfo/Config.pm        | 48 +++++++++++++++++++++++++++++++++++----------
 tp/init/highlight_syntax.pm | 27 +++++++++++--------------
 3 files changed, 67 insertions(+), 26 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index f3b67da913..9b92695233 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,21 @@
+2022-08-07  Patrice Dumas  <pertusus@free.fr>
+
+       Init file loading errors and warning interface setup and use
+
+       * tp/Texinfo/Config.pm (@init_file_loading_messages)
+       (GNUT_load_init_file, texinfo_register_init_loading_error)
+       (texinfo_register_init_loading_warning): replace
+       texinfo_register_init_loading_failure by two functions,
+       texinfo_register_init_loading_error and
+       texinfo_register_init_loading_warning to be able to register
+       errors and warnings.
+       Use a stack, @init_file_loading_messages to be sure to separate
+       each init file loading messages even if an init file loads another.
+
+       * tp/init/highlight_syntax.pm: get the available languages upon
+       loading and use texinfo_register_init_loading_error and
+       texinfo_register_init_loading_warning for errors and warnings.
+
 2022-08-07  Patrice Dumas  <pertusus@free.fr>
 
        Do not keep EPUB container directory in the default case
diff --git a/tp/Texinfo/Config.pm b/tp/Texinfo/Config.pm
index a3e8eb06bb..9badbafb71 100644
--- a/tp/Texinfo/Config.pm
+++ b/tp/Texinfo/Config.pm
@@ -116,14 +116,15 @@ sub _GNUT_document_warn($) {
   chomp ($text);
   warn(_GNUT_encode_message(
         sprintf(__p("program name: warning: warning_message",
-                   "%s: warning: %s\n"), $real_command_name, $text)));
+                   "%s: warning: %s"), $real_command_name, $text)."\n"));
 }
 
-my @init_file_loading_errors;
+my @init_file_loading_messages;
 # called from texi2any.pl main program.
 # eval $FILE in the Texinfo::Config namespace. $FILE should be a binary string.
 sub GNUT_load_init_file($) {
   my $file = shift;
+  push @init_file_loading_messages, [];
   eval { require($file) ;};
   my $e = $@;
   if ($e ne '') {
@@ -134,19 +135,46 @@ sub GNUT_load_init_file($) {
     _GNUT_document_warn(sprintf(__("error loading %s: %s"),
                 _GNUT_decode_input($file), $e));
   }
-  for my $error (@init_file_loading_errors) {
-    warn sprintf(__("error loading %s: %s"),
-                _GNUT_decode_input($file), $error)."\n";
+  my $file_loading_messages = pop @init_file_loading_messages;
+  my $error_nr = 0;
+  for my $error (@{$file_loading_messages}) {
+    my $type = $error->{'type'};
+    my $message = $error->{'text'};
+    chomp($message);
+    if ($type eq 'error') {
+      $error_nr += 1;
+      warn(_GNUT_encode_message(
+              sprintf(__p("init file: error_message",
+                     "%s: %s"),
+                 _GNUT_decode_input($file), $message)."\n"));
+    } else {
+      if (not texinfo_get_conf('NO_WARN')) {
+        warn(_GNUT_encode_message(
+              sprintf(__p("init file: warning: warning_message",
+                          "%s: warning: %s"),
+                         _GNUT_decode_input($file), $message)."\n"));
+      }
+    }
   }
-  if (scalar(@init_file_loading_errors)) {
+  if ($error_nr > 0 and !texinfo_get_conf('FORCE')) {
     exit 1;
   }
 }
 
-# called from init files in case of errors.
-sub texinfo_register_init_loading_failure($) {
-  my $error = shift;
-  push @init_file_loading_errors, $error;
+# called from init files in case of errors at loading.
+# TODO document
+sub texinfo_register_init_loading_error($) {
+  my $message = shift;
+  push @{$init_file_loading_messages[-1]}, {'type' => 'error',
+                                            'text' => $message};
+}
+
+# called from init files in case for warnings during loading.
+# TODO document
+sub texinfo_register_init_loading_warning($) {
+  my $message = shift;
+  push @{$init_file_loading_messages[-1]}, {'type' => 'warning',
+                                            'text' => $message};
 }
 
 # L2H removed in 2021
diff --git a/tp/init/highlight_syntax.pm b/tp/init/highlight_syntax.pm
index 64f28d41a4..3d5a3a09f6 100644
--- a/tp/init/highlight_syntax.pm
+++ b/tp/init/highlight_syntax.pm
@@ -70,16 +70,15 @@ my $highlight_out_dir;
 
 my %highlighted_languages_list;
 
-sub _get_highlighted_languages($)
-{
-  my $self = shift;
-
-  my $cmd = 'source-highlight --lang-list';
-  if (not(open(HIGHLIGHT_LANG_LIST, '-|', $cmd))) {
-    $self->document_warn($self, sprintf(__(
-                         'highlight_syntax.pm: command failed: %s'), $cmd));
-    return 0;
-  }
+# FIXME open shows an error message if the file is not found
+# which is a duplicate with the texinfo_register_init_loading_error
+# registered message, which is better
+# Can't exec "source-highlight": No such file or directory at 
./init/highlight_syntax.pm line 74
+my $cmd = 'source-highlight --lang-list';
+if (not(open(HIGHLIGHT_LANG_LIST, '-|', $cmd))) {
+  texinfo_register_init_loading_error(
+        sprintf(__('%s: %s'), $cmd, $!));
+} else {
   my $line;
   while (defined($line = <HIGHLIGHT_LANG_LIST>)) {
     chomp($line);
@@ -87,13 +86,11 @@ sub _get_highlighted_languages($)
        my $language = $1;
        $highlighted_languages_list{$language} = 1;
     } else {
-      $self->document_warn($self, sprintf(__(
-                         'highlight_syntax.pm: %s: %s: cannot parse language 
line'), 
-                          $cmd, $line));
+      texinfo_register_init_loading_warning(sprintf(__(
+                        '%s: %s: cannot parse language line'), $cmd, $line))
     }
   }
   close(HIGHLIGHT_LANG_LIST);
-  return 1;
 }
 
 sub _get_language($$$)
@@ -142,8 +139,6 @@ sub highlight_process($$)
   return 1 if (defined($self->get_conf('OUTFILE'))
         and $Texinfo::Common::null_device_file{$self->get_conf('OUTFILE')});
 
-  return 0 if (not _get_highlighted_languages($self));
-
   my $document_name = $self->get_info('document_name');
   my $highlight_basename = "${document_name}_highlight";
 



reply via email to

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