texinfo-commits
[Top][All Lists]
Advanced

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

[no subject]


From: Patrice Dumas
Date: Sat, 19 Oct 2024 14:55:41 -0400 (EDT)

branch: master
commit c5f2a786f72a1cabd76250a5d5d0358c8c297108
Author: Patrice Dumas <pertusus@free.fr>
AuthorDate: Sat Oct 19 20:50:58 2024 +0200

    * tp/Texinfo/XS/convert/converter.c
    (destroy_converter_initialization_info),
    tp/Texinfo/XS/main/converter_types.h (CONVERTER_INITIALIZATION_INFO):
    add OPTIONS options field and free it, in case a direct access to an
    OPTIONS structure is needed.
    
    * tp/Texinfo/XS/convert/texinfo.c (txi_converter_format_defaults): add
    to get default options based on a customization list and a format
    string, also setting the returned CONVERTER_INITIALIZATION_INFO
    options field.
    
    * tp/Texinfo/XS/convert/converter.c: move converter_set_document below
    convert API functions.
    
    * tp/Texinfo/XS/teximakehtml.c (main): add cmdline_options for options
    common for parser and converter.  Add some code in comments using
    txi_converter_format_defaults.  Move code around.
---
 ChangeLog                            | 20 ++++++++++++++++
 tp/Texinfo/XS/convert/converter.c    | 46 ++++++++++++++++++++----------------
 tp/Texinfo/XS/convert/texinfo.c      | 43 +++++++++++++++++++++++++++++++--
 tp/Texinfo/XS/convert/texinfo.h      |  4 ++++
 tp/Texinfo/XS/main/converter_types.h |  3 +++
 tp/Texinfo/XS/teximakehtml.c         | 34 ++++++++++++++++++++------
 6 files changed, 121 insertions(+), 29 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index ba91f3999a..79768d9aea 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -32,6 +32,26 @@
        This means files from libtoolize and gettextize should be
        copied under tp/Texinfo/XS/m4, not tp/Texinfo/XS/gnulib/m4.
 
+2024-10-19  Patrice Dumas  <pertusus@free.fr>
+
+       * tp/Texinfo/XS/convert/converter.c
+       (destroy_converter_initialization_info),
+       tp/Texinfo/XS/main/converter_types.h (CONVERTER_INITIALIZATION_INFO):
+       add OPTIONS options field and free it, in case a direct access to an
+       OPTIONS structure is needed.
+
+       * tp/Texinfo/XS/convert/texinfo.c (txi_converter_format_defaults): add
+       to get default options based on a customization list and a format
+       string, also setting the returned CONVERTER_INITIALIZATION_INFO
+       options field.
+
+       * tp/Texinfo/XS/convert/converter.c: move converter_set_document below
+       convert API functions.
+
+       * tp/Texinfo/XS/teximakehtml.c (main): add cmdline_options for options
+       common for parser and converter.  Add some code in comments using
+       txi_converter_format_defaults.  Move code around.
+
 2024-10-19  Patrice Dumas  <pertusus@free.fr>
 
        * tp/Texinfo/Common.pm: change in comments.
diff --git a/tp/Texinfo/XS/convert/converter.c 
b/tp/Texinfo/XS/convert/converter.c
index 7ca8187f69..fd29d299e6 100644
--- a/tp/Texinfo/XS/convert/converter.c
+++ b/tp/Texinfo/XS/convert/converter.c
@@ -390,6 +390,12 @@ destroy_converter_initialization_info 
(CONVERTER_INITIALIZATION_INFO *init_info)
   if (init_info->translated_commands)
     destroy_translated_commands (init_info->translated_commands);
 
+  if (init_info->options)
+    {
+      free_options (init_info->options);
+      free (init_info->options);
+    }
+
   free_options_list (&init_info->conf);
 
   free_strings_list (&init_info->non_valid_customization);
@@ -406,7 +412,7 @@ copy_converter_initialization_info 
(CONVERTER_INITIALIZATION_INFO *dst_info,
   copy_options_list (&dst_info->conf, &src_info->conf);
 }
 
-/* Next three functions are not called from Perl as the Perl equivalent
+/* Next five functions are not called from Perl as the Perl equivalent
    functions are already called (and possibly overriden).  Inheritance
    in Perl is replaced by dispatching using a table here.
 
@@ -489,25 +495,6 @@ converter_converter (enum converter_format format,
   return converter;
 }
 
-void
-converter_set_document (CONVERTER *converter, DOCUMENT *document)
-{
-   /*
-  if (document)
-    {
-      fprintf (stderr, "XS|CONVERTER %d: Document %d\n",
-           converter->converter_descriptor, document->descriptor);
-    }
-    */
-
-  converter->document = document;
-
-  set_output_encoding (converter->conf, converter->document);
-
-  converter->convert_text_options
-    = copy_converter_options_for_convert_text (converter);
-}
-
 char *
 converter_output (CONVERTER *self, DOCUMENT *document)
 {
@@ -544,6 +531,25 @@ converter_convert (CONVERTER *self, DOCUMENT *document)
   return 0;
 }
 
+void
+converter_set_document (CONVERTER *converter, DOCUMENT *document)
+{
+   /*
+  if (document)
+    {
+      fprintf (stderr, "XS|CONVERTER %d: Document %d\n",
+           converter->converter_descriptor, document->descriptor);
+    }
+    */
+
+  converter->document = document;
+
+  set_output_encoding (converter->conf, converter->document);
+
+  converter->convert_text_options
+    = copy_converter_options_for_convert_text (converter);
+}
+
 
 
 /* result to be freed */
diff --git a/tp/Texinfo/XS/convert/texinfo.c b/tp/Texinfo/XS/convert/texinfo.c
index b29991ceea..a6435e1889 100644
--- a/tp/Texinfo/XS/convert/texinfo.c
+++ b/tp/Texinfo/XS/convert/texinfo.c
@@ -44,7 +44,8 @@
 #include "html_converter_api.h"
 #include "texinfo.h"
 
-/* initialization of the library for parsing and conversion. */
+/* initialization of the library for parsing and conversion (generic),
+   to be called once */
 void
 txi_general_setup (const char *localesdir, int texinfo_uninstalled,
                  const char *tp_builddir,
@@ -59,7 +60,8 @@ txi_general_setup (const char *localesdir, int 
texinfo_uninstalled,
                    converterdatadir, top_srcdir);
 }
 
-/* to be called once (per output format) */
+/* initialization of the library for a specific output format, to be
+   called once */
 void
 txi_converter_output_format_setup (const char *format_str)
 {
@@ -70,6 +72,43 @@ txi_converter_output_format_setup (const char *format_str)
     html_format_setup ();
 }
 
+/* This function should be used to get information on an output format
+   defaults, taking into account CUSTOMIZATIONS.  It is not needed
+   for converter initialization, as similar code is already called.
+   Similar to Texinfo::Convert::XXXX->converter_defaults($options)
+ */
+CONVERTER_INITIALIZATION_INFO *
+txi_converter_format_defaults (const char *format_str,
+                               OPTIONS_LIST *customizations)
+{
+  enum converter_format converter_format
+    = find_format_name_converter_format (format_str);
+  CONVERTER_INITIALIZATION_INFO *conf = new_converter_initialization_info ();
+  CONVERTER_INITIALIZATION_INFO *format_defaults;
+  OPTION **format_defaults_sorted_options;
+
+  if (customizations)
+    {
+      copy_options_list (&conf->conf, customizations);
+    }
+
+  format_defaults = converter_defaults (converter_format, conf);
+
+  destroy_converter_initialization_info (conf);
+
+  /* also set options structure for a direct access */
+  format_defaults->options = new_options ();
+  format_defaults_sorted_options
+    = new_sorted_options (format_defaults->options);
+  number_options_list (&format_defaults->conf, format_defaults_sorted_options);
+  copy_numbered_options_list_options (format_defaults->options,
+                                      format_defaults_sorted_options,
+                                      &format_defaults->conf, 0);
+  free (format_defaults_sorted_options);
+
+  return format_defaults;
+}
+
 /* parser initialization, similar to Texinfo::Parser::parser in Perl.
    Also sets INCLUDE_DIRECTORIES minimally if not specified in options.
    The implementation is similar to parsetexi/Parsetexi.pm on purpose. */
diff --git a/tp/Texinfo/XS/convert/texinfo.h b/tp/Texinfo/XS/convert/texinfo.h
index cd82d439b9..52dc65dd69 100644
--- a/tp/Texinfo/XS/convert/texinfo.h
+++ b/tp/Texinfo/XS/convert/texinfo.h
@@ -29,6 +29,10 @@ void txi_general_setup (const char *localesdir, int 
texinfo_uninstalled,
 
 void txi_converter_output_format_setup (const char *format_str);
 
+CONVERTER_INITIALIZATION_INFO *txi_converter_format_defaults (
+                               const char *format_str,
+                               OPTIONS_LIST *customizations);
+
 void txi_parser (const char *file_path, const char *locale_encoding,
                 const char **expanded_formats, const VALUE_LIST *values,
                 OPTIONS_LIST *options);
diff --git a/tp/Texinfo/XS/main/converter_types.h 
b/tp/Texinfo/XS/main/converter_types.h
index dcd8b28a1a..c8329ebde0 100644
--- a/tp/Texinfo/XS/main/converter_types.h
+++ b/tp/Texinfo/XS/main/converter_types.h
@@ -767,6 +767,9 @@ typedef struct CONVERTER_INITIALIZATION_INFO {
     OPTIONS_LIST conf;
     /* gather strings that are not customization options */
     STRING_LIST non_valid_customization;
+  /* can be used for direct access to OPTIONS structure if needed, but
+     should be NULL in many cases */
+    OPTIONS *options;
 } CONVERTER_INITIALIZATION_INFO;
 
 typedef struct CONVERTER {
diff --git a/tp/Texinfo/XS/teximakehtml.c b/tp/Texinfo/XS/teximakehtml.c
index 583958250b..a886518ec7 100644
--- a/tp/Texinfo/XS/teximakehtml.c
+++ b/tp/Texinfo/XS/teximakehtml.c
@@ -106,10 +106,13 @@ main (int argc, char *argv[])
   BUTTON_SPECIFICATION_LIST *custom_node_footer_buttons;
   OPTIONS_LIST parser_options;
   OPTIONS_LIST convert_options;
+  /* not really cmdline_options but options common to parser and converter */
+  OPTIONS_LIST cmdline_options;
   size_t errors_count = 0;
   size_t errors_nr;
   STRING_LIST texinfo_language_config_dirs;
   STRING_LIST converter_texinfo_language_config_dirs;
+  CONVERTER_INITIALIZATION_INFO *format_defaults;
   char *home_dir;
   const char *curdir = ".";
 
@@ -131,6 +134,12 @@ main (int argc, char *argv[])
 
   locale_encoding = nl_langinfo (CODESET);
 
+  initialize_options_list (&cmdline_options, 2);
+  /*
+  add_new_option_value (&cmdline_options, GOT_integer,
+                           "DEBUG", 1, 0);
+   */
+
   while (1)
     {
       int option_character;
@@ -183,16 +192,28 @@ main (int argc, char *argv[])
   if (strlen (DATADIR))
     add_string (DATADIR "/texinfo", &texinfo_language_config_dirs);
 
+  /*
+   if ($^O eq 'MSWin32') {
+     $main_program_set_options->{'DOC_ENCODING_FOR_INPUT_FILE_NAME'} = 0;
+   }
+  */
 
   txi_general_setup (LOCALEDIR, 0, 0, 0, 0);
 
-/*
- if ($^O eq 'MSWin32') {
-  $main_program_set_options->{'DOC_ENCODING_FOR_INPUT_FILE_NAME'} = 0;
-}
-*/
+  txi_converter_output_format_setup ("html");
 
+  /*
+  add_new_option_value (&cmdline_options, GOT_integer,
+                        "TEXI2HTML", 1, 0);
+   */
+
+  /* FORMAT_MENU for parser should be set based on converter_defaults taking 
into
+     account cmdline_options in case TEXI2HTML is set
+  format_defaults = txi_converter_format_defaults ("html", &cmdline_options);
+  fprintf (stderr, "FORMAT_MENU %s\n", 
format_defaults->options->FORMAT_MENU.o.string);
+   */
 
+  /* TODO add cmdline_options filtering in only parser options */
   initialize_options_list (&parser_options, 2);
   /*
   add_new_option_value (&parser_options, GOT_integer,
@@ -209,6 +230,7 @@ main (int argc, char *argv[])
                             "EXPANDED_FORMATS", &parser_EXPANDED_FORMATS);
     }
 
+
   /* Texinfo file parsing */
   input_file_path = argv[optind];
 
@@ -250,8 +272,6 @@ main (int argc, char *argv[])
     = txi_handle_document_error_messages (document, 0, 1, locale_encoding);
   errors_count += errors_nr;
 
-  txi_converter_output_format_setup ("html");
-
   /* conversion initialization */
   initialize_options_list (&convert_options, 2);
 



reply via email to

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