texinfo-commits
[Top][All Lists]
Advanced

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

branch master updated: * tp/Texinfo/XS/convert/converter.c (find_format_


From: Patrice Dumas
Subject: branch master updated: * tp/Texinfo/XS/convert/converter.c (find_format_data_index), tp/Texinfo/XS/convert/converter.h (CONVERTER_FORMAT_DATA), tp/Texinfo/XS/main/converter_types.h (enum converter_format) (CONVERTER): move enum converter_format to converter_types.h, add an enum converter_format format field to CONVERTER. Rename CONVERTER_FORMAT_DATA output_format as default_format.
Date: Fri, 04 Oct 2024 06:08:06 -0400

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 594fef199e * tp/Texinfo/XS/convert/converter.c 
(find_format_data_index), tp/Texinfo/XS/convert/converter.h 
(CONVERTER_FORMAT_DATA), tp/Texinfo/XS/main/converter_types.h (enum 
converter_format) (CONVERTER): move enum converter_format to converter_types.h, 
add an enum converter_format format field to CONVERTER.  Rename 
CONVERTER_FORMAT_DATA output_format as default_format.
594fef199e is described below

commit 594fef199eeea938d49369f96a74ff7b162f5895
Author: Patrice Dumas <pertusus@free.fr>
AuthorDate: Sun Aug 11 12:11:50 2024 +0200

    * tp/Texinfo/XS/convert/converter.c (find_format_data_index),
    tp/Texinfo/XS/convert/converter.h (CONVERTER_FORMAT_DATA),
    tp/Texinfo/XS/main/converter_types.h (enum converter_format)
    (CONVERTER): move enum converter_format to converter_types.h, add an
    enum converter_format format field to CONVERTER.  Rename
    CONVERTER_FORMAT_DATA output_format as default_format.
    
    * tp/Texinfo/XS/convert/ConvertXS.xs (generic_converter_init),
    tp/Texinfo/XS/convert/converter.c (new_converter),
    tp/Texinfo/XS/convert/get_converter_perl_info.c
    (get_converter_info_from_sv, converter_get_info_from_sv),
    tp/Texinfo/XS/convert/texinfo.c (txi_converter)
    (txi_converter_initialize), tp/Texinfo/XS/teximakehtml.c (main): pass
    an enum converter_format to new_converter to set the CONVERTER
    converter_format early.  Determine the converter_format in
    ConvertXS.xs and not in converter_get_info_from_sv.  Have
    converter_get_info_from_sv return its status.  Get class from
    converter_format_data in get_converter_info_from_sv if possible.
    Add enum converter_format argument to txi_converter.
    Remove txi_converter_initialize format argument, add output_format and
    converted_format arguments.  If they are not set, take the default
    from format_defaults based on converter->format.
---
 ChangeLog                                       | 25 +++++++++++++++++
 tp/Texinfo/XS/convert/ConvertXS.xs              | 22 +++++++++++----
 tp/Texinfo/XS/convert/converter.c               |  6 ++--
 tp/Texinfo/XS/convert/converter.h               |  9 ++----
 tp/Texinfo/XS/convert/get_converter_perl_info.c | 37 ++++++++++---------------
 tp/Texinfo/XS/convert/get_converter_perl_info.h | 10 +++----
 tp/Texinfo/XS/convert/texinfo.c                 | 23 +++++++++++----
 tp/Texinfo/XS/convert/texinfo.h                 |  6 ++--
 tp/Texinfo/XS/main/converter_types.h            |  8 ++++++
 tp/Texinfo/XS/teximakehtml.c                    |  4 +--
 10 files changed, 96 insertions(+), 54 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 3eb54bac60..033f6e6996 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,28 @@
+2024-08-11  Patrice Dumas  <pertusus@free.fr>
+
+       * tp/Texinfo/XS/convert/converter.c (find_format_data_index),
+       tp/Texinfo/XS/convert/converter.h (CONVERTER_FORMAT_DATA),
+       tp/Texinfo/XS/main/converter_types.h (enum converter_format)
+       (CONVERTER): move enum converter_format to converter_types.h, add an
+       enum converter_format format field to CONVERTER.  Rename
+       CONVERTER_FORMAT_DATA output_format as default_format.
+
+       * tp/Texinfo/XS/convert/ConvertXS.xs (generic_converter_init),
+       tp/Texinfo/XS/convert/converter.c (new_converter),
+       tp/Texinfo/XS/convert/get_converter_perl_info.c
+       (get_converter_info_from_sv, converter_get_info_from_sv),
+       tp/Texinfo/XS/convert/texinfo.c (txi_converter)
+       (txi_converter_initialize), tp/Texinfo/XS/teximakehtml.c (main): pass
+       an enum converter_format to new_converter to set the CONVERTER
+       converter_format early.  Determine the converter_format in
+       ConvertXS.xs and not in converter_get_info_from_sv.  Have
+       converter_get_info_from_sv return its status.  Get class from
+       converter_format_data in get_converter_info_from_sv if possible.
+       Add enum converter_format argument to txi_converter.
+       Remove txi_converter_initialize format argument, add output_format and
+       converted_format arguments.  If they are not set, take the default
+       from format_defaults based on converter->format.
+
 2024-08-11  Patrice Dumas  <pertusus@free.fr>
 
        * tp/Texinfo/XS/convert/texinfo.c (txi_converter)
diff --git a/tp/Texinfo/XS/convert/ConvertXS.xs 
b/tp/Texinfo/XS/convert/ConvertXS.xs
index abe92036bb..4d8f8a66f5 100644
--- a/tp/Texinfo/XS/convert/ConvertXS.xs
+++ b/tp/Texinfo/XS/convert/ConvertXS.xs
@@ -101,18 +101,28 @@ generic_converter_init (SV *converter_in, const char 
*class, SV *format_defaults
          CONVERTER *self;
          CONVERTER_INITIALIZATION_INFO *format_defaults;
          CONVERTER_INITIALIZATION_INFO *conf;
-         enum converter_format converter_format;
+         enum converter_format converter_format = COF_none;
+         int i;
       CODE:
-         converter_descriptor = new_converter ();
+         /* determine the converter format, if handled in C */
+         for (i =0; i < TXI_CONVERSION_FORMAT_NR; i++)
+           {
+             if (!strcmp (converter_format_data[i].perl_converter_class, 
class))
+               {
+                 converter_format = i;
+                 break;
+               }
+           }
+
+         converter_descriptor = new_converter (converter_format);
          self = retrieve_converter (converter_descriptor);
 
          format_defaults = new_converter_initialization_info ();
          conf = new_converter_initialization_info ();
 
-         converter_format
-           = converter_get_info_from_sv (converter_in, class, self,
-                                         format_defaults_sv,
-                                         conf_sv, format_defaults, conf, 0);
+         converter_get_info_from_sv (converter_in, class, self,
+                                    format_defaults_sv,
+                                    conf_sv, format_defaults, conf);
 
          set_converter_init_information (self, converter_format,
                                          format_defaults, conf);
diff --git a/tp/Texinfo/XS/convert/converter.c 
b/tp/Texinfo/XS/convert/converter.c
index fc1fb16b1e..9b0e5db159 100644
--- a/tp/Texinfo/XS/convert/converter.c
+++ b/tp/Texinfo/XS/convert/converter.c
@@ -175,7 +175,7 @@ find_format_data_index (const char *format)
   int i;
 
   for (i = 0; i < TXI_CONVERSION_FORMAT_NR; i++)
-    if (!strcmp (converter_format_data[i].output_format, format))
+    if (!strcmp (converter_format_data[i].default_format, format))
       return i;
 
   return COF_none;
@@ -220,7 +220,7 @@ init_generic_converter (CONVERTER *self)
 
 /* descriptor starts at 1, 0 is not found or an error */
 size_t
-new_converter (void)
+new_converter (enum converter_format format)
 {
   size_t converter_index;
   int slot_found = 0;
@@ -250,6 +250,8 @@ new_converter (void)
   registered_converter = (CONVERTER *) malloc (sizeof (CONVERTER));
   memset (registered_converter, 0, sizeof (CONVERTER));
 
+  registered_converter->format = format;
+
   init_generic_converter (registered_converter);
 
   converter_list[converter_index] = registered_converter;
diff --git a/tp/Texinfo/XS/convert/converter.h 
b/tp/Texinfo/XS/convert/converter.h
index 84445e18fe..e6e261aabd 100644
--- a/tp/Texinfo/XS/convert/converter.h
+++ b/tp/Texinfo/XS/convert/converter.h
@@ -66,11 +66,6 @@
             } \
           break;
 
-enum converter_format {
-   COF_none = -1,
-   COF_html,
-};
-
 #define TXI_CONVERSION_FORMAT_NR (COF_html +1)
 
 typedef struct FLOAT_CAPTION_PREPENDED_ELEMENT {
@@ -96,7 +91,7 @@ typedef struct PATHS_INFORMATION {
 } PATHS_INFORMATION;
 
 typedef struct CONVERTER_FORMAT_DATA {
-    const char *output_format;
+    const char *default_format;
     const char *perl_converter_class;
     void (* converter_defaults) (CONVERTER *self,
                                CONVERTER_INITIALIZATION_INFO *conf);
@@ -128,7 +123,7 @@ void converter_setup (int texinfo_uninstalled, const char 
*tp_builddir,
 enum converter_format find_format_data_index (const char *format);
 
 CONVERTER *retrieve_converter (int converter_descriptor);
-size_t new_converter (void);
+size_t new_converter (enum converter_format format);
 void unregister_converter_descriptor (int converter_descriptor);
 
 void set_converter_init_information (CONVERTER *converter,
diff --git a/tp/Texinfo/XS/convert/get_converter_perl_info.c 
b/tp/Texinfo/XS/convert/get_converter_perl_info.c
index d48279dcaa..863b41d7df 100644
--- a/tp/Texinfo/XS/convert/get_converter_perl_info.c
+++ b/tp/Texinfo/XS/convert/get_converter_perl_info.c
@@ -194,7 +194,8 @@ new_option_from_sv (SV *option_sv, CONVERTER *converter,
   return option;
 }
 
-/* class is Perl converter class for warning message */
+/* class is Perl converter class for warning message in case the class
+   cannot be found otherwise */
 static int
 get_converter_info_from_sv (SV *conf_sv, const char *class,
                             CONVERTER *converter,
@@ -259,8 +260,15 @@ get_converter_info_from_sv (SV *conf_sv, const char *class,
                     }
                   else
                     {
-                      fprintf (stderr, "%s: %s not a possible configuration\n",
-                                       class, key);
+                      const char *class_name;
+                      if (converter->format >= 0)
+                        class_name
+              = converter_format_data[converter->format].perl_converter_class;
+                       else
+                        class_name = class;
+                      fprintf (stderr,
+                               "%s: %s not a possible configuration\n",
+                               class_name, key);
                     }
                 }
               else
@@ -275,21 +283,16 @@ get_converter_info_from_sv (SV *conf_sv, const char 
*class,
   return 0;
 }
 
-/* CLASS is the perl converter class.  It could also be taken from
-   the object */
-enum converter_format
+int
 converter_get_info_from_sv (SV *converter_sv, const char *class,
                             CONVERTER *converter,
                             SV *format_defaults_sv, SV *conf_sv,
                             CONVERTER_INITIALIZATION_INFO *format_defaults,
-                            CONVERTER_INITIALIZATION_INFO *conf,
-                            int *status)
+                            CONVERTER_INITIALIZATION_INFO *conf)
 {
   HV *converter_hv;
   int has_format_defaults;
   int has_conf;
-  int i;
-  enum converter_format converter_format = COF_none;
 
   dTHX;
 
@@ -297,16 +300,6 @@ converter_get_info_from_sv (SV *converter_sv, const char 
*class,
 
   converter->hv = converter_hv;
 
-  /* determine the converter format, if handled in C */
-  for (i =0; i < TXI_CONVERSION_FORMAT_NR; i++)
-    {
-      if (!strcmp (converter_format_data[i].perl_converter_class, class))
-        {
-          converter_format = i;
-          break;
-        }
-    }
-
   has_format_defaults
     = get_converter_info_from_sv (format_defaults_sv, class, converter,
                               converter->sorted_options, format_defaults);
@@ -327,9 +320,7 @@ converter_get_info_from_sv (SV *converter_sv, const char 
*class,
                    has_conf);
     */
 
-  if (status)
-    *status = has_format_defaults + has_conf;
-  return converter_format;
+  return has_format_defaults + has_conf;
 }
 
 void
diff --git a/tp/Texinfo/XS/convert/get_converter_perl_info.h 
b/tp/Texinfo/XS/convert/get_converter_perl_info.h
index b7af9fb802..3879a46510 100644
--- a/tp/Texinfo/XS/convert/get_converter_perl_info.h
+++ b/tp/Texinfo/XS/convert/get_converter_perl_info.h
@@ -11,13 +11,11 @@
 #include "convert_to_text.h"
 
 CONVERTER *get_sv_converter (SV *sv_in, const char *warn_string);
-enum converter_format converter_get_info_from_sv (SV *converter_sv,
-                            const char *class,
-                            CONVERTER *converter,
-                            SV *format_defaults_sv, SV *conf_sv,
+int converter_get_info_from_sv (SV *converter_sv, const char *class,
+                                CONVERTER *converter,
+                                SV *format_defaults_sv, SV *conf_sv,
                             CONVERTER_INITIALIZATION_INFO *format_defaults,
-                            CONVERTER_INITIALIZATION_INFO *conf,
-                            int *status);
+                            CONVERTER_INITIALIZATION_INFO *conf);
 CONVERTER *converter_set_document_from_sv (SV *converter_in, SV *document_in);
 
 TEXT_OPTIONS *copy_sv_options_for_convert_text (SV *sv_in);
diff --git a/tp/Texinfo/XS/convert/texinfo.c b/tp/Texinfo/XS/convert/texinfo.c
index b3eea5d62d..a1a451b6ac 100644
--- a/tp/Texinfo/XS/convert/texinfo.c
+++ b/tp/Texinfo/XS/convert/texinfo.c
@@ -272,9 +272,9 @@ txi_complete_document (DOCUMENT *document, unsigned long 
flags,
    Texinfo::Convert::Converter::converter and generic parts of
    _generic_converter_init */
 CONVERTER *
-txi_converter (void)
+txi_converter (enum converter_format format)
 {
-  size_t converter_descriptor = new_converter ();
+  size_t converter_descriptor = new_converter (format);
   return retrieve_converter (converter_descriptor);
 }
 
@@ -282,20 +282,31 @@ txi_converter (void)
    _generic_converter_init and $converter->converter_initialize() calls */
 void
 txi_converter_initialize (CONVERTER *converter,
-                          const char *format, const char *locale_encoding,
+                          const char *output_format,
+                          const char *converted_format,
+                          const char *locale_encoding,
                    const char *program_file, OPTIONS_LIST *customizations)
 {
-  enum converter_format converter_format = find_format_data_index (format);
+  enum converter_format converter_format = converter->format;
   CONVERTER_INITIALIZATION_INFO *format_defaults;
   CONVERTER_INITIALIZATION_INFO *conf;
+  const char *format;
 
   if (converter_format == COF_none)
     return;
 
+  format = converter_format_data[converter_format].default_format;
+
   /* prepare specific information for the converter */
   format_defaults = new_converter_initialization_info ();
-  format_defaults->converted_format = strdup (format);
-  format_defaults->output_format = strdup (format);
+  if (converted_format)
+    format_defaults->converted_format = strdup (converted_format);
+  else
+    format_defaults->converted_format = strdup (format);
+  if (output_format)
+    format_defaults->output_format = strdup (output_format);
+  else
+    format_defaults->output_format = strdup (format);
 
   conf = new_converter_initialization_info ();
   initialize_options_list (&conf->conf, 10);
diff --git a/tp/Texinfo/XS/convert/texinfo.h b/tp/Texinfo/XS/convert/texinfo.h
index ae0cabf270..9541be699c 100644
--- a/tp/Texinfo/XS/convert/texinfo.h
+++ b/tp/Texinfo/XS/convert/texinfo.h
@@ -39,9 +39,11 @@ DOCUMENT *txi_parse_texi_file (const char *input_file_path, 
int *status);
 void txi_complete_document (DOCUMENT *document, unsigned long flags,
                             int format_menu);
 
-CONVERTER *txi_converter (void);
+CONVERTER *txi_converter (enum converter_format format);
 void txi_converter_initialize (CONVERTER *converter,
-                               const char *format, const char *locale_encoding,
+                               const char *output_format,
+                               const char *converted_format,
+                               const char *locale_encoding,
                        const char *program_file, OPTIONS_LIST *customizations);
 
 char *txi_html_output (CONVERTER *converter, DOCUMENT *document);
diff --git a/tp/Texinfo/XS/main/converter_types.h 
b/tp/Texinfo/XS/main/converter_types.h
index 77b70e89ea..9e68ed4036 100644
--- a/tp/Texinfo/XS/main/converter_types.h
+++ b/tp/Texinfo/XS/main/converter_types.h
@@ -32,6 +32,11 @@
 /* for interdependency with convert_to_text.h */
 struct TEXT_OPTIONS;
 
+enum converter_format {
+   COF_none = -1,
+   COF_html,
+};
+
 /* for string information passing to/from perl */
 enum sv_string_type {
    svt_byte,
@@ -748,6 +753,9 @@ typedef struct CONVERTER {
      but we don't want to include the Perl headers everywhere; */
     void *hv;
 
+  /* this is the type of the converter, not of the output.  (Similar to
+     a module name in Perl) */
+    enum converter_format format;
     OPTIONS *conf;
     OPTIONS *init_conf;
     /* an array containing the fields of conf ordered by name */
diff --git a/tp/Texinfo/XS/teximakehtml.c b/tp/Texinfo/XS/teximakehtml.c
index 3ce79a83a0..0afd1d0c0b 100644
--- a/tp/Texinfo/XS/teximakehtml.c
+++ b/tp/Texinfo/XS/teximakehtml.c
@@ -183,7 +183,7 @@ main (int argc, char *argv[])
   errors_count += errors_nr;
 
   /* create converter and generic converter initializations */
-  converter = txi_converter();
+  converter = txi_converter (COF_html);
 
   initialize_options_list (&convert_options, 2);
   /* customize buttons.  This is a bit silly to use link buttons for
@@ -198,7 +198,7 @@ main (int argc, char *argv[])
                            "TEST", 1, 0);
 
   /* setup converter */
-  txi_converter_initialize (converter, "html", locale_encoding, program_file,
+  txi_converter_initialize (converter, 0, 0, locale_encoding, program_file,
                             &convert_options);
 
   free_options_list (&convert_options);



reply via email to

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