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:18 -0400 (EDT)

branch: master
commit b15a6fa1d247870b1a379e5c4eb06dca47773ccb
Author: Patrice Dumas <pertusus@free.fr>
AuthorDate: Sun Aug 11 10:15:48 2024 +0200

    * tp/Texinfo/XS/convert/texinfo.c (txi_converter)
    (txi_converter_initialize), tp/Texinfo/XS/teximakehtml.c (main):
    rename txi_converter as txi_converter_initialize and readd
    txi_converter that just creates a converter and returns it, hiding the
    converter descriptor.
    
    * tp/Texinfo/XS/convert/texinfo.c (txi_parse_texi_file)
    (txi_remove_document): add wrappers hiding the document descriptor.
    
    * tp/Texinfo/XS/teximakehtml.c (main): use txi_parse_texi_file and
    txi_remove_document.
---
 ChangeLog                       | 14 ++++++++++++++
 tp/Texinfo/XS/convert/texinfo.c | 34 +++++++++++++++++++++++++++++-----
 tp/Texinfo/XS/convert/texinfo.h | 12 ++++++++----
 tp/Texinfo/XS/teximakehtml.c    | 21 +++++++--------------
 4 files changed, 58 insertions(+), 23 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 84e266e52c..3eb54bac60 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,17 @@
+2024-08-11  Patrice Dumas  <pertusus@free.fr>
+
+       * tp/Texinfo/XS/convert/texinfo.c (txi_converter)
+       (txi_converter_initialize), tp/Texinfo/XS/teximakehtml.c (main):
+       rename txi_converter as txi_converter_initialize and readd
+       txi_converter that just creates a converter and returns it, hiding the
+       converter descriptor.
+
+       * tp/Texinfo/XS/convert/texinfo.c (txi_parse_texi_file)
+       (txi_remove_document): add wrappers hiding the document descriptor.
+
+       * tp/Texinfo/XS/teximakehtml.c (main): use txi_parse_texi_file and
+       txi_remove_document.
+
 2024-08-11  Patrice Dumas  <pertusus@free.fr>
 
        * tp/Texinfo/XS/teximakehtml.c (add_new_option_strlist_value): copy
diff --git a/tp/Texinfo/XS/convert/texinfo.c b/tp/Texinfo/XS/convert/texinfo.c
index 9ecf24cf7c..b3eea5d62d 100644
--- a/tp/Texinfo/XS/convert/texinfo.c
+++ b/tp/Texinfo/XS/convert/texinfo.c
@@ -268,11 +268,22 @@ txi_complete_document (DOCUMENT *document, unsigned long 
flags,
                                          document->options);
 }
 
-/* converter initialization. Similar to Texinfo::Convert::X::converter */
+/* converter creation, similar to the very first part of
+   Texinfo::Convert::Converter::converter and generic parts of
+   _generic_converter_init */
+CONVERTER *
+txi_converter (void)
+{
+  size_t converter_descriptor = new_converter ();
+  return retrieve_converter (converter_descriptor);
+}
+
+/* converter initialization. Similar to $converter->converter_defaults(),
+   _generic_converter_init and $converter->converter_initialize() calls */
 void
-txi_converter (CONVERTER *converter,
-               const char *format, const char *locale_encoding,
-               const char *program_file, OPTIONS_LIST *customizations)
+txi_converter_initialize (CONVERTER *converter,
+                          const char *format, const char *locale_encoding,
+                   const char *program_file, OPTIONS_LIST *customizations)
 {
   enum converter_format converter_format = find_format_data_index (format);
   CONVERTER_INITIALIZATION_INFO *format_defaults;
@@ -427,7 +438,20 @@ txi_html_output (CONVERTER *converter, DOCUMENT *document)
 
 
 
-/* functions for high level interface hiding some defails of the data */
+/* high level interface hiding some details of the data */
+
+DOCUMENT *
+txi_parse_texi_file (const char *input_file_path, int *status)
+{
+  size_t document_descriptor = parse_file (input_file_path, status);
+  return retrieve_document (document_descriptor);
+}
+
+void
+txi_remove_document (DOCUMENT *document)
+{
+  remove_document_descriptor (document->descriptor);
+}
 
 size_t
 txi_handle_parser_error_messages (DOCUMENT *document, int no_warn,
diff --git a/tp/Texinfo/XS/convert/texinfo.h b/tp/Texinfo/XS/convert/texinfo.h
index efa0d70bbc..ae0cabf270 100644
--- a/tp/Texinfo/XS/convert/texinfo.h
+++ b/tp/Texinfo/XS/convert/texinfo.h
@@ -34,13 +34,15 @@ void txi_parser (const char *file_path, const char 
*locale_encoding,
                 const char **expanded_formats, const VALUE_LIST *values,
                 OPTIONS_LIST *options);
 
+DOCUMENT *txi_parse_texi_file (const char *input_file_path, int *status);
+
 void txi_complete_document (DOCUMENT *document, unsigned long flags,
                             int format_menu);
 
-void txi_converter (CONVERTER *converter,
-                    const char *format, const char *locale_encoding,
-                    const char *program_file, OPTIONS_LIST *customizations);
-
+CONVERTER *txi_converter (void);
+void txi_converter_initialize (CONVERTER *converter,
+                               const char *format, const char *locale_encoding,
+                       const char *program_file, OPTIONS_LIST *customizations);
 
 char *txi_html_output (CONVERTER *converter, DOCUMENT *document);
 
@@ -54,4 +56,6 @@ size_t txi_handle_converter_error_messages (CONVERTER 
*converter, int no_warn,
                                           int use_filename,
                                           const char *message_encoding);
 
+void txi_remove_document (DOCUMENT *document);
+
 #endif
diff --git a/tp/Texinfo/XS/teximakehtml.c b/tp/Texinfo/XS/teximakehtml.c
index 6d9e8558c7..3ce79a83a0 100644
--- a/tp/Texinfo/XS/teximakehtml.c
+++ b/tp/Texinfo/XS/teximakehtml.c
@@ -29,15 +29,11 @@
 
 #include "document_types.h"
 #include "converter_types.h"
-#include "errors.h"
 /* parse_file_path */
 #include "utils.h"
 /*
 #include "convert_to_texinfo.h"
  */
-/* retrieve_document remove_document_descriptor */
-#include "document.h"
-#include "converter.h"
 #include "create_buttons.h"
 #include "convert_html.h"
 #include "texinfo.h"
@@ -62,6 +58,7 @@ add_button_option (OPTIONS_LIST *options_list, OPTION 
**sorted_options,
   options_list_add_option (options_list, option);
 }
 
+/* this function is quite generic, it could be added to utils.c */
 static OPTION *
 add_new_option_strlist_value (OPTIONS_LIST *options_list,
                   enum global_option_type type, const char *name,
@@ -95,9 +92,7 @@ main (int argc, char *argv[])
   int status;
   char *program_file_name_and_directory[2];
   char *program_file;
-  size_t document_descriptor = 0;
   DOCUMENT *document;
-  size_t converter_descriptor;
   CONVERTER *converter;
   char *result;
   BUTTON_SPECIFICATION_LIST *custom_node_footer_buttons;
@@ -156,13 +151,12 @@ main (int argc, char *argv[])
   free_options_list (&parser_options);
 
   /* Texinfo document tree parsing */
-  document_descriptor = parse_file (input_file_path, &status);
-  document = retrieve_document (document_descriptor);
+  document = txi_parse_texi_file (input_file_path, &status);
 
   if (status)
     {
       txi_handle_parser_error_messages (document, 0, 1, locale_encoding);
-      remove_document_descriptor (document_descriptor);
+      txi_remove_document (document);
       exit (1);
     }
 
@@ -189,8 +183,7 @@ main (int argc, char *argv[])
   errors_count += errors_nr;
 
   /* create converter and generic converter initializations */
-  converter_descriptor = new_converter ();
-  converter = retrieve_converter (converter_descriptor);
+  converter = txi_converter();
 
   initialize_options_list (&convert_options, 2);
   /* customize buttons.  This is a bit silly to use link buttons for
@@ -205,8 +198,8 @@ main (int argc, char *argv[])
                            "TEST", 1, 0);
 
   /* setup converter */
-  txi_converter (converter, "html", locale_encoding, program_file,
-                             &convert_options);
+  txi_converter_initialize (converter, "html", locale_encoding, program_file,
+                            &convert_options);
 
   free_options_list (&convert_options);
   free (program_file);
@@ -223,7 +216,7 @@ main (int argc, char *argv[])
   /* destroy converter */
   html_free_converter (converter);
   /* destroy document */
-  remove_document_descriptor (document_descriptor);
+  txi_remove_document (document);
 
   if (errors_count > 0)
     exit (1);



reply via email to

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