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/texinfo.c (txi_set_base_d


From: Patrice Dumas
Subject: branch master updated: * tp/Texinfo/XS/convert/texinfo.c (txi_set_base_default_options) (txi_converter_setup), tp/Texinfo/XS/teximakehtml.c (main): do not set options independent of converter format in txi_converter_setup, add txi_set_base_default_options for that, and call it early, before getting command-line options. In txi_set_base_default_options, also call add_program_cmdline_options_defaults and add_program_customization_options_defaults to set the same defaults as in texi2any.
Date: Mon, 23 Dec 2024 17:37:13 -0500

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 63f62e4d14 * tp/Texinfo/XS/convert/texinfo.c 
(txi_set_base_default_options) (txi_converter_setup), 
tp/Texinfo/XS/teximakehtml.c (main): do not set options independent of 
converter format in txi_converter_setup, add txi_set_base_default_options for 
that, and call it early, before getting command-line options.  In 
txi_set_base_default_options, also call add_program_cmdline_options_defaults 
and add_program_customization_options_defaults to set the same defaults as in 
texi2any.
63f62e4d14 is described below

commit 63f62e4d1412aaaf14ad6de90dde0bdbf20305a1
Author: Patrice Dumas <pertusus@free.fr>
AuthorDate: Wed Dec 4 23:29:47 2024 +0100

    * tp/Texinfo/XS/convert/texinfo.c (txi_set_base_default_options)
    (txi_converter_setup), tp/Texinfo/XS/teximakehtml.c (main): do not set
    options independent of converter format in txi_converter_setup, add
    txi_set_base_default_options for that, and call it early, before
    getting command-line options.  In txi_set_base_default_options, also
    call add_program_cmdline_options_defaults and
    add_program_customization_options_defaults to set the same defaults
    as in texi2any.
    
    * tp/Texinfo/XS/convert/texinfo.c
    (txi_config_set_customization_default),
    tp/Texinfo/XS/main/customization_options.c
    (option_number_in_option_list, options_list_add_option_number): add
    option_number_in_option_list based on options_list_add_option_number.
    Add txi_config_set_customization_default to set program option if not
    already set as command line option.
    
    * tp/Texinfo/XS/teximakehtml.c (main): call
    txi_config_set_customization_default to set FORMAT_MENU based on
    converter customization option taking into account cmdline_options.
    Set convert_options based on program_options and cmdline_options.
---
 ChangeLog                                  |  36 ++++++++--
 tp/Texinfo/XS/convert/texinfo.c            | 103 +++++++++++++++++++----------
 tp/Texinfo/XS/convert/texinfo.h            |   9 ++-
 tp/Texinfo/XS/main/customization_options.c |  24 ++++---
 tp/Texinfo/XS/main/customization_options.h |   1 +
 tp/Texinfo/XS/teximakehtml.c               |  82 ++++++++++++++---------
 6 files changed, 172 insertions(+), 83 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 059dd036e6..0df8e9f834 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,33 @@
+2024-12-04  Patrice Dumas  <pertusus@free.fr>
+
+       * tp/Texinfo/XS/convert/texinfo.c (txi_set_base_default_options)
+       (txi_converter_setup), tp/Texinfo/XS/teximakehtml.c (main): do not set
+       options independent of converter format in txi_converter_setup, add
+       txi_set_base_default_options for that, and call it early, before
+       getting command-line options.  In txi_set_base_default_options, also
+       call add_program_cmdline_options_defaults and
+       add_program_customization_options_defaults to set the same defaults
+       as in texi2any.
+
+       * tp/Texinfo/XS/convert/texinfo.c
+       (txi_config_set_customization_default),
+       tp/Texinfo/XS/main/customization_options.c
+       (option_number_in_option_list, options_list_add_option_number): add
+       option_number_in_option_list based on options_list_add_option_number.
+       Add txi_config_set_customization_default to set program option if not
+       already set as command line option.
+
+       * tp/Texinfo/XS/teximakehtml.c (main): call
+       txi_config_set_customization_default to set FORMAT_MENU based on
+       converter customization option taking into account cmdline_options.
+       Set convert_options based on program_options and cmdline_options.
+
+2024-12-04  Patrice Dumas  <pertusus@free.fr>
+
+       * tp/Texinfo/Config.pm (texinfo_set_from_init_file)
+       (GNUT_set_customization_default): consistently use exists to determine
+       if cmdline_options or init_files_options are set, and not defined.
+
 2024-12-23  Patrice Dumas  <pertusus@free.fr>
 
        * tp/Texinfo/Convert/HTML.pm (_convert_menu_entry_type),
@@ -567,12 +597,6 @@
 
        * doc/texinfo-tex-test.texi (Images) [dvi output]: disable.
 
-2024-12-04  Patrice Dumas  <pertusus@free.fr>
-
-       * tp/Texinfo/Config.pm (texinfo_set_from_init_file)
-       (GNUT_set_customization_default): consistently use exists to determine
-       if cmdline_options or init_files_options are set, and not defined.
-
 2024-12-04  Patrice Dumas  <pertusus@free.fr>
 
        * tp/Texinfo/XS/teximakehtml.c: include langinfo.h and call
diff --git a/tp/Texinfo/XS/convert/texinfo.c b/tp/Texinfo/XS/convert/texinfo.c
index 2705a8b39f..82c451503d 100644
--- a/tp/Texinfo/XS/convert/texinfo.c
+++ b/tp/Texinfo/XS/convert/texinfo.c
@@ -30,6 +30,7 @@
 
 #include "document_types.h"
 #include "option_types.h"
+#include "options_defaults.h"
 #include "api.h"
 #include "conf.h"
 #include "errors.h"
@@ -80,6 +81,59 @@ txi_general_setup (int texinfo_uninstalled, const char 
*converterdatadir,
                    top_srcdir);
 }
 
+static void
+err_add_option_value (OPTIONS_LIST *options_list, const char *option_name,
+                      int int_value, const char *char_value)
+{
+  if (!add_option_value (options_list, option_name,
+                         int_value, char_value))
+    fprintf (stderr, "BUG: error setting %s\n", option_name);
+}
+
+/* similar to texi2any setting customization variables independent of
+   conversion format */
+void
+txi_set_base_default_options (OPTIONS_LIST *main_program_set_options,
+                              const char *locale_encoding,
+                              const char *program_file)
+{
+  const char *configured_version = PACKAGE_VERSION_CONFIG;
+  const char *configured_package = PACKAGE_CONFIG;
+  const char *configured_name = PACKAGE_NAME_CONFIG;
+  const char *configured_url = PACKAGE_URL_CONFIG;
+  const char *configured_name_version
+    = PACKAGE_NAME_CONFIG " " PACKAGE_VERSION_CONFIG;
+
+  initialize_options_list (main_program_set_options);
+
+  /* similar to options coming from texi2any */
+  err_add_option_value (main_program_set_options, "PROGRAM", 0, program_file);
+#define set_configured_information(varname,varvalue) \
+    err_add_option_value (main_program_set_options, #varname, 0, varvalue);
+  set_configured_information(PACKAGE_VERSION, configured_version)
+  set_configured_information(PACKAGE, configured_package)
+  set_configured_information(PACKAGE_NAME, configured_name)
+  set_configured_information(PACKAGE_AND_VERSION, configured_name_version)
+  set_configured_information(PACKAGE_URL, configured_url)
+#undef set_configured_information
+
+  err_add_option_value (main_program_set_options, "COMMAND_LINE_ENCODING", 0,
+                        locale_encoding);
+  err_add_option_value (main_program_set_options, "MESSAGE_ENCODING", 0,
+                        locale_encoding);
+  err_add_option_value (main_program_set_options, "LOCALE_ENCODING", 0,
+                        locale_encoding);
+  /* filled here because it is the best we have in C */
+  err_add_option_value (main_program_set_options,
+                        "XS_STRXFRM_COLLATION_LOCALE", 0,
+                        "en_US");
+
+  /* same as Texinfo::Common::default_main_program_customization_options */
+  /* in general transmitted to converters as default */
+  add_program_cmdline_options_defaults (main_program_set_options);
+  add_program_customization_options_defaults (main_program_set_options);
+}
+
 /* initialization of the library for a specific output format, to be
    called once */
 void
@@ -326,22 +380,11 @@ txi_complete_document (DOCUMENT *document, unsigned long 
flags,
                                          document->options);
 }
 
-static void
-err_add_option_value (OPTIONS_LIST *options_list, const char *option_name,
-                      int int_value, const char *char_value)
-{
-  if (!add_option_value (options_list, option_name,
-                         int_value, char_value))
-    fprintf (stderr, "BUG: error setting %s\n", option_name);
-}
-
 /* converter setup. Similar to an initialization of converter
    in texi2any */
 CONVERTER *
 txi_converter_setup (const char *format_str,
                      const char *output_format,
-                     const char *locale_encoding,
-                     const char *program_file,
                      const STRING_LIST *texinfo_language_config_dirs_in,
                      OPTIONS_LIST *customizations)
 {
@@ -349,12 +392,6 @@ txi_converter_setup (const char *format_str,
     = find_format_name_converter_format (format_str);
   CONVERTER_INITIALIZATION_INFO *conf;
   CONVERTER *self;
-  const char *configured_version = PACKAGE_VERSION_CONFIG;
-  const char *configured_package = PACKAGE_CONFIG;
-  const char *configured_name = PACKAGE_NAME_CONFIG;
-  const char *configured_url = PACKAGE_URL_CONFIG;
-  const char *configured_name_version
-    = PACKAGE_NAME_CONFIG " " PACKAGE_VERSION_CONFIG;
   STRING_LIST *texinfo_language_config_dirs = new_string_list ();
 
   conf = new_converter_initialization_info ();
@@ -372,25 +409,6 @@ txi_converter_setup (const char *format_str,
     copy_strings (texinfo_language_config_dirs,
                   texinfo_language_config_dirs_in);
 
-
-  /* similar to options coming from texi2any */
-  err_add_option_value (&conf->conf, "PROGRAM", 0, program_file);
-#define set_configured_information(varname,varvalue) \
-    err_add_option_value (&conf->conf, #varname, 0, varvalue);
-  set_configured_information(PACKAGE_VERSION, configured_version)
-  set_configured_information(PACKAGE, configured_package)
-  set_configured_information(PACKAGE_NAME, configured_name)
-  set_configured_information(PACKAGE_AND_VERSION, configured_name_version)
-  set_configured_information(PACKAGE_URL, configured_url)
-#undef set_configured_information
-
-  err_add_option_value (&conf->conf, "COMMAND_LINE_ENCODING", 0,
-                        locale_encoding);
-  err_add_option_value (&conf->conf, "MESSAGE_ENCODING", 0, locale_encoding);
-  err_add_option_value (&conf->conf, "LOCALE_ENCODING", 0, locale_encoding);
-  /* filled here because it is the best we have in C */
-  err_add_option_value (&conf->conf, "XS_STRXFRM_COLLATION_LOCALE", 0,
-                        "en_US");
   /*
   err_add_option_value (&conf->conf, "DEBUG", 1, 0);
    */
@@ -491,3 +509,16 @@ txi_handle_converter_error_messages (CONVERTER *converter, 
int no_warn,
   return handle_error_messages (&converter->error_messages, no_warn,
                          use_filename, message_encoding);
 }
+
+/* Texinfo::Config */
+int
+txi_config_set_customization_default (OPTIONS_LIST *options_defaults,
+                         OPTIONS_LIST *cmdline_options, const OPTION *option)
+{
+  if (option_number_in_option_list (cmdline_options, option->number))
+    return 0;
+
+  options_list_add_option_number (options_defaults, option->number, 1);
+  copy_option (options_defaults->sorted_options[option->number -1], option);
+  return 1;
+}
diff --git a/tp/Texinfo/XS/convert/texinfo.h b/tp/Texinfo/XS/convert/texinfo.h
index b98bef94ee..94a32a4799 100644
--- a/tp/Texinfo/XS/convert/texinfo.h
+++ b/tp/Texinfo/XS/convert/texinfo.h
@@ -6,6 +6,7 @@
 
 #include "document_types.h"
 #include "converter_types.h"
+#include "option_types.h"
 
 /* document structuring and transformations selection flags */
 #define STTF_relate_index_entries_to_table_items    0x0001
@@ -26,6 +27,10 @@ void txi_general_setup (int texinfo_uninstalled,
                    const char *converterdatadir, const char *tp_builddir,
                    const char *top_srcdir);
 
+void txi_set_base_default_options (OPTIONS_LIST *options,
+                                   const char *locale_encoding,
+                                   const char *program_file);
+
 void txi_converter_output_format_setup (const char *format_str);
 
 CONVERTER_INITIALIZATION_INFO *txi_converter_format_defaults (
@@ -43,8 +48,6 @@ void txi_complete_document (DOCUMENT *document, unsigned long 
flags,
 
 CONVERTER *txi_converter_setup (const char *converter_format,
                      const char *output_format,
-                     const char *locale_encoding,
-                     const char *program_file,
                      const STRING_LIST *texinfo_language_config_dirs,
                      OPTIONS_LIST *customizations);
 
@@ -66,4 +69,6 @@ void txi_document_remove (DOCUMENT *document);
 void txi_converter_reset (CONVERTER *converter);
 void txi_converter_destroy (CONVERTER *converter);
 
+int txi_config_set_customization_default (OPTIONS_LIST *options_defaults,
+                         OPTIONS_LIST *cmdline_options, const OPTION *option);
 #endif
diff --git a/tp/Texinfo/XS/main/customization_options.c 
b/tp/Texinfo/XS/main/customization_options.c
index af7165430d..21640a17e0 100644
--- a/tp/Texinfo/XS/main/customization_options.c
+++ b/tp/Texinfo/XS/main/customization_options.c
@@ -426,20 +426,28 @@ free_options_list (OPTIONS_LIST *options_list)
   free (options_list->options);
 }
 
+int
+option_number_in_option_list (OPTIONS_LIST *options_list, size_t number)
+{
+  size_t i;
+
+  for (i = 0; i < options_list->number; i++)
+    {
+      size_t option_nr = options_list->list[i];
+      if (number == option_nr)
+        return 1;
+    }
+  return 0;
+}
+
 void
 options_list_add_option_number (OPTIONS_LIST *options_list,
                                 size_t number, int check_duplicates)
 {
-  size_t i;
-
   if (check_duplicates)
     {
-      for (i = 0; i < options_list->number; i++)
-        {
-          size_t option_nr = options_list->list[i];
-          if (number == option_nr)
-            return;
-        }
+      if (option_number_in_option_list (options_list, number))
+        return;
     }
 
   if (options_list->number >= options_list->space)
diff --git a/tp/Texinfo/XS/main/customization_options.h 
b/tp/Texinfo/XS/main/customization_options.h
index 5b033ee317..a5184e9c57 100644
--- a/tp/Texinfo/XS/main/customization_options.h
+++ b/tp/Texinfo/XS/main/customization_options.h
@@ -58,6 +58,7 @@ void copy_option (OPTION *destination, const OPTION *source);
 
 void initialize_options_list (OPTIONS_LIST *options_list);
 void free_options_list (OPTIONS_LIST *options_list);
+int option_number_in_option_list (OPTIONS_LIST *options_list, size_t number);
 void options_list_add_option_number (OPTIONS_LIST *options_list,
                                      size_t number, int check_duplicates);
 void copy_options_list (OPTIONS_LIST *options_list,
diff --git a/tp/Texinfo/XS/teximakehtml.c b/tp/Texinfo/XS/teximakehtml.c
index 6fd7263a87..ca6410f19c 100644
--- a/tp/Texinfo/XS/teximakehtml.c
+++ b/tp/Texinfo/XS/teximakehtml.c
@@ -91,7 +91,8 @@ 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 common to parser and converter */
+  OPTIONS_LIST program_options;
   OPTIONS_LIST cmdline_options;
   size_t errors_count = 0;
   size_t errors_nr;
@@ -150,8 +151,9 @@ main (int argc, char *argv[])
   }
    */
 
-
-  initialize_options_list (&cmdline_options);
+  /* program_options corresponds to main_program_set_options in texi2any */
+  txi_set_base_default_options (&program_options, locale_encoding,
+                                program_file);
 
   /*
    if ($^O eq 'MSWin32') {
@@ -160,7 +162,7 @@ main (int argc, char *argv[])
   */
 
   /*
-  add_new_option_value (&cmdline_options, GOT_integer,
+  add_new_option_value (&program_options, GOT_integer,
                            "DEBUG", 1, 0);
    */
 
@@ -184,6 +186,8 @@ main (int argc, char *argv[])
   if (strlen (DATADIR))
     add_string (DATADIR "/texinfo", &texinfo_language_config_dirs);
 
+  /* TODO set from command line */
+  initialize_options_list (&cmdline_options);
 
   while (1)
     {
@@ -223,19 +227,52 @@ main (int argc, char *argv[])
   if (optind >= argc)
     exit (EXIT_FAILURE);
 
+  if (run_mode == TEXIMAKEHTML_mode_test
+      || run_mode == TEXIMAKEHTML_mode_mimick_test)
+    {
+      /* this is set to help with comparison with previous invokations */
+      add_option_value (&program_options, "TEST", 1, 0);
+    }
+
+  if (program_options.options->TEST.o.integer > 0)
+    {
+      add_option_value (&program_options, "PACKAGE_VERSION", 0, "");
+      add_option_value (&program_options, "PACKAGE", 0, "texinfo");
+      add_option_value (&program_options, "PACKAGE_NAME", 0, "GNU Texinfo");
+      add_option_value (&program_options, "PACKAGE_AND_VERSION", 0,
+                                          "texinfo");
+      add_option_value (&program_options, "PACKAGE_URL", 0,
+                                     "https://www.gnu.org/software/texinfo/";);
+      add_option_value (&program_options, "PROGRAM", 0, "texi2any");
+    }
   txi_converter_output_format_setup ("html");
 
   /*
   add_option_value (&cmdline_options, "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);
+  /*
+  For now, FORMAT_MENU is the only variable that can be set from converter
+  defaults for the main program structuring and for the parser.
+   */
+  /*
+   $cmdline_options is passed to have command line settings, here
+   in practice TEXI2HTML set, for conversion to HTML to select
+   possibly different customization variable values.
    */
+  format_defaults = txi_converter_format_defaults ("html", &cmdline_options);
 
-  /* TODO add cmdline_options filtering in only parser options */
+  if (format_defaults->conf.options->FORMAT_MENU.o.string != 0)
+    {
+      /*
+      fprintf (stderr, "FORMAT_MENU %s\n",
+           format_defaults->conf.options->FORMAT_MENU.o.string);
+       */
+      txi_config_set_customization_default (&program_options, &cmdline_options,
+                                 &format_defaults->conf.options->FORMAT_MENU);
+    }
+
+  /* TODO add program_options filtering in only parser options */
   initialize_options_list (&parser_options);
   /*
   add_option_value (&parser_options, "DEBUG", 1, 0);
@@ -295,27 +332,10 @@ main (int argc, char *argv[])
 
   /* conversion initialization */
   initialize_options_list (&convert_options);
+  copy_options_list (&convert_options, &program_options, 0);
+  copy_options_list (&convert_options, &cmdline_options, 1);
 
-  if (run_mode == TEXIMAKEHTML_mode_test
-      || run_mode == TEXIMAKEHTML_mode_mimick_test)
-    {
-      /* this is set to help with comparison with previous invokations */
-      add_option_value (&convert_options, "TEST", 1, 0);
-
-      add_option_value (&convert_options, "PACKAGE_VERSION", 0, "");
-      add_option_value (&convert_options, "PACKAGE", 0, "texinfo");
-      add_option_value (&convert_options, "PACKAGE_NAME", 0, "GNU Texinfo");
-      add_option_value (&convert_options, "PACKAGE_AND_VERSION", 0,
-                                          "texinfo");
-      add_option_value (&convert_options, "PACKAGE_URL", 0,
-                                     "https://www.gnu.org/software/texinfo/";);
-      add_option_value (&convert_options, "PROGRAM", 0, "texi2any");
-
-      /*
-      add_option_value (&convert_options, "DEBUG", 1, 0);
-       */
-    }
-  else if (run_mode == TEXIMAKEHTML_mode_demo)
+  if (run_mode == TEXIMAKEHTML_mode_demo)
     {
       /* customize buttons.  It is a bit silly to use link buttons for
          footer, it is for the demonstration */
@@ -337,6 +357,7 @@ main (int argc, char *argv[])
       free (program_file);
       program_file = strdup ("texi2any");
 
+      add_option_value (&convert_options, "PROGRAM", 0, program_file);
       add_option_value (&convert_options, "PACKAGE_VERSION", 0,
                         configured_version);
       add_option_value (&convert_options, "PACKAGE_AND_VERSION", 0,
@@ -356,8 +377,7 @@ main (int argc, char *argv[])
   copy_strings (&converter_texinfo_language_config_dirs,
                 &texinfo_language_config_dirs);
 
-  converter = txi_converter_setup ("html", "html", locale_encoding,
-                                   program_file,
+  converter = txi_converter_setup ("html", "html",
                                    &converter_texinfo_language_config_dirs,
                                    &convert_options);
 



reply via email to

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