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, 27 Dec 2024 04:41:59 -0500 (EST)

branch: master
commit 26fb4b9c3dfe4a59219c7a897ad95bc25096b26f
Author: Patrice Dumas <pertusus@free.fr>
AuthorDate: Thu Dec 26 13:43:05 2024 +0100

    * tp/Texinfo/XS/convert/converter.c (converter_format_data)
    (converter_converter), tp/Texinfo/XS/convert/converter.h
    (CONVERTER_FORMAT_DATA): add converter_converter field in
    CONVERTER_FORMAT_DATA and use it in converter_converter to be able to
    do a different converter initialization for a format.
    
    * tp/Texinfo/XS/convert/converter.c (set_converter_init_information),
    tp/texi2any.pl: handle NULL/undef converter_defaults return.
---
 ChangeLog                         | 13 +++++++++-
 tp/Texinfo/XS/convert/converter.c | 50 +++++++++++++++++++++++++++------------
 tp/Texinfo/XS/convert/converter.h |  9 +++++--
 tp/Texinfo/XS/convert/texinfo.c   | 14 ++++++++---
 tp/Texinfo/XS/texi2any.c          |  4 +---
 tp/texi2any.pl                    |  4 +++-
 6 files changed, 69 insertions(+), 25 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 1d338c63bb..9e6a995648 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+2024-12-26  Patrice Dumas  <pertusus@free.fr>
+
+       * tp/Texinfo/XS/convert/converter.c (converter_format_data)
+       (converter_converter), tp/Texinfo/XS/convert/converter.h
+       (CONVERTER_FORMAT_DATA): add converter_converter field in
+       CONVERTER_FORMAT_DATA and use it in converter_converter to be able to
+       do a different converter initialization for a format.
+
+       * tp/Texinfo/XS/convert/converter.c (set_converter_init_information),
+       tp/texi2any.pl: handle NULL/undef converter_defaults return.
+
 2024-12-25  Patrice Dumas  <pertusus@free.fr>
 
        PlainTexinfo converter in C
@@ -55,7 +66,7 @@
        * tp/Texinfo/XS/texi2any.c (main): set program_file to be "texi2any"
        if TEST is set.
 
-       * tp/Texinfo/XS/texi2any.c (main): if FORMAT_MENU is not set a all,
+       * tp/Texinfo/XS/texi2any.c (main): if FORMAT_MENU is not set at all,
        consider that menus are to be checked.
 
 2024-12-25  Patrice Dumas  <pertusus@free.fr>
diff --git a/tp/Texinfo/XS/convert/converter.c 
b/tp/Texinfo/XS/convert/converter.c
index 86fda331ed..089e40fe13 100644
--- a/tp/Texinfo/XS/convert/converter.c
+++ b/tp/Texinfo/XS/convert/converter.c
@@ -70,10 +70,10 @@
 /* Should be kept in sync with enum converter_format
    and TXI_CONVERSION_FORMAT_NR */
 CONVERTER_FORMAT_DATA converter_format_data[] = {
-  {"html", "Texinfo::Convert::HTML", &html_converter_defaults,
+  {"html", "Texinfo::Convert::HTML", 0, &html_converter_defaults,
    &html_converter_initialize, &html_output, &html_convert, 0,
    &html_reset_converter, &html_free_converter},
-  {"plaintexinfo", "Texinfo::Convert::PlainTexinfo",
+  {"plaintexinfo", "Texinfo::Convert::PlainTexinfo", 0,
    &plaintexinfo_converter_defaults, 0, &plaintexinfo_output,
    &plaintexinfo_convert, &plaintexinfo_convert_tree, 0, 0},
 };
@@ -288,6 +288,8 @@ init_generic_converter (CONVERTER *self)
   self->translated_commands[0].translation = strdup ("error@arrow{}");
 }
 
+/* Allocate a converter without any initialization such as to leave
+   open the choice of functions used to setup the converter */
 /* descriptor starts at 1, 0 is not found or an error */
 size_t
 new_converter (enum converter_format format)
@@ -401,17 +403,24 @@ apply_converter_info (CONVERTER *converter,
  */
 void
 set_converter_init_information (CONVERTER *converter,
-                            CONVERTER_INITIALIZATION_INFO *format_defaults,
-                            const CONVERTER_INITIALIZATION_INFO *user_conf)
+                       const CONVERTER_INITIALIZATION_INFO *format_defaults,
+                       const CONVERTER_INITIALIZATION_INFO *user_conf)
 {
   init_generic_converter (converter);
 
-  apply_converter_info (converter, format_defaults, 0);
+  if (format_defaults)
+    {
+      apply_converter_info (converter, format_defaults, 0);
 
-  /* Also keep format_defaults options as an OPTIONS structure */
-  converter->format_defaults_conf = new_options ();
-  copy_options (converter->format_defaults_conf,
-                format_defaults->conf.options);
+      /* Also keep format_defaults options as an OPTIONS structure */
+      /* TODO not done in Perl.  Used in later codes, so probably done
+         differently, to be checked, maybe linked with the comment
+         just below on converter_init_conf.
+        */
+      converter->format_defaults_conf = new_options ();
+      copy_options (converter->format_defaults_conf,
+                    format_defaults->conf.options);
+    }
 
   if (user_conf)
     apply_converter_info (converter, user_conf, 1);
@@ -539,19 +548,30 @@ CONVERTER *
 converter_converter (enum converter_format format,
                      const CONVERTER_INITIALIZATION_INFO *user_conf)
 {
-  CONVERTER_INITIALIZATION_INFO *format_defaults;
-
   size_t converter_descriptor = new_converter (format);
   CONVERTER *converter = retrieve_converter (converter_descriptor);
 
-  format_defaults = converter_defaults (converter->format, user_conf);
+  if (converter->format != COF_none
+      && converter_format_data[converter->format].converter_converter)
+    {/* corresponds, in Perl, to a converter not inheriting
+        Texinfo::Convert::Converter, such as the Text converter to rawtext */
+      void (* format_converter_converter) (CONVERTER *self,
+                         const CONVERTER_INITIALIZATION_INFO *user_conf)
+        = converter_format_data[converter->format].converter_converter;
+      format_converter_converter (converter, user_conf);
+    }
+  else
+    {
+      CONVERTER_INITIALIZATION_INFO *format_defaults;
 
-  set_converter_init_information (converter, format_defaults, user_conf);
+      format_defaults = converter_defaults (converter->format, user_conf);
 
-  destroy_converter_initialization_info (format_defaults);
+      set_converter_init_information (converter, format_defaults, user_conf);
 
-  converter_initialize (converter);
+      destroy_converter_initialization_info (format_defaults);
 
+      converter_initialize (converter);
+    }
   return converter;
 }
 
diff --git a/tp/Texinfo/XS/convert/converter.h 
b/tp/Texinfo/XS/convert/converter.h
index b9de51872a..6b8aa8af7d 100644
--- a/tp/Texinfo/XS/convert/converter.h
+++ b/tp/Texinfo/XS/convert/converter.h
@@ -93,6 +93,11 @@ typedef struct PATHS_INFORMATION {
 typedef struct CONVERTER_FORMAT_DATA {
     const char *default_format;
     const char *perl_converter_class;
+    /* replaces the default converter initialization sequence
+       (in Perl corresponds to a converter redefining the converter method) */
+    void (* converter_converter) (CONVERTER *self,
+                            const CONVERTER_INITIALIZATION_INFO *conf);
+    /* next two are used if converter_converter is NULL */
     CONVERTER_INITIALIZATION_INFO *
        (* converter_defaults) (enum converter_format format,
                                const CONVERTER_INITIALIZATION_INFO *conf);
@@ -138,8 +143,8 @@ CONVERTER *retrieve_converter (size_t converter_descriptor);
 size_t new_converter (enum converter_format format);
 
 void set_converter_init_information (CONVERTER *converter,
-                            CONVERTER_INITIALIZATION_INFO *format_defaults,
-                            const CONVERTER_INITIALIZATION_INFO *user_conf);
+                        const CONVERTER_INITIALIZATION_INFO *format_defaults,
+                        const CONVERTER_INITIALIZATION_INFO *user_conf);
 
 CONVERTER_INITIALIZATION_INFO *converter_defaults (
                     enum converter_format converter_format,
diff --git a/tp/Texinfo/XS/convert/texinfo.c b/tp/Texinfo/XS/convert/texinfo.c
index aa331315fc..a17ab745f7 100644
--- a/tp/Texinfo/XS/convert/texinfo.c
+++ b/tp/Texinfo/XS/convert/texinfo.c
@@ -32,6 +32,8 @@
 #include "option_types.h"
 #include "options_defaults.h"
 #include "api.h"
+/* fatal */
+#include "base_utils.h"
 #include "conf.h"
 #include "errors.h"
 /* parse_file_path messages_and_encodings_setup */
@@ -147,8 +149,7 @@ txi_customization_loading_setup (int embedded_interpreter,
 {
   const char *load_txi_modules_basename = "load_txi_modules";
   if (embedded_interpreter)
-    {/* setup paths here to avoid memory management as much as possible
-        in Perl C */
+    {
       char *load_modules_path;
       int status;
       if (conversion_paths_info.texinfo_uninstalled)
@@ -162,7 +163,14 @@ txi_customization_loading_setup (int embedded_interpreter,
       status = call_init_perl (argc_ref, argv_ref, env_ref, load_modules_path);
       /* status < 0 means no functioning call_init_perl */
       if (status > 0)
-        fprintf (stderr, "ERROR: call_init_perl status: %d\n", status);
+        {
+          char *message;
+          /* unexpected failure, no point continuing, the output needs
+             the interpreter and libperl will segfault */
+          xasprintf (&message, "call_init_perl status: %d", status);
+          fatal (message);
+          free (message);
+        }
       else if (status < 0)
         fprintf (stderr, "WARNING: no embedded interpreter available\n");
       free (load_modules_path);
diff --git a/tp/Texinfo/XS/texi2any.c b/tp/Texinfo/XS/texi2any.c
index c642b227ac..2eb6d3fe4d 100644
--- a/tp/Texinfo/XS/texi2any.c
+++ b/tp/Texinfo/XS/texi2any.c
@@ -1850,9 +1850,7 @@ main (int argc, char *argv[], char *env[])
 
   format_menu_option_nr = program_options.options->FORMAT_MENU.number;
 
-  /* in Perl the presence of a module in format specification is used to
-     determine if there are format defaults.  Here check if format_defaults
-     is set */
+  /* Converters may set format_defaults to NULL (Text converter) */
   if (format_defaults)
     {
       if (format_defaults->conf.options->FORMAT_MENU.o.string)
diff --git a/tp/texi2any.pl b/tp/texi2any.pl
index e0f3ec9dfe..af729e33bc 100755
--- a/tp/texi2any.pl
+++ b/tp/texi2any.pl
@@ -1617,7 +1617,9 @@ if 
(defined($formats_table{$converted_format}->{'module'})) {
   # possibly different customization variable values.
   my $converter_defaults
      = $converter_class->converter_defaults($cmdline_options);
-  if (defined($converter_defaults->{'FORMAT_MENU'})) {
+  # some converters may return undef for $converter_defaults (Text for example)
+  if ($converter_defaults
+      and defined($converter_defaults->{'FORMAT_MENU'})) {
     # could be done for other customization options
     set_main_program_default('FORMAT_MENU',
                              $converter_defaults->{'FORMAT_MENU'});



reply via email to

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