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

branch: master
commit f86f1f0c9354ea34d0130a4401c28bc8e2057357
Author: Patrice Dumas <pertusus@free.fr>
AuthorDate: Sun Aug 11 14:09:47 2024 +0200

    * tp/Texinfo/XS/Makefile.am (libtexinfo_la_SOURCES),
    tp/Texinfo/XS/main/utils.c,
    tp/Texinfo/XS/main/customization_options.c: move functions related to
    customization options out ot utils.c to the new to
    main/customization_options.c file.
---
 ChangeLog                                          |   8 +
 tp/Texinfo/XS/Makefile.am                          |   2 +
 tp/Texinfo/XS/convert/convert_html.c               |   1 +
 tp/Texinfo/XS/convert/converter.c                  |   1 +
 tp/Texinfo/XS/convert/converters_defaults.c        |   2 +-
 tp/Texinfo/XS/convert/get_converter_perl_info.c    |   2 +-
 .../XS/convert/html_converter_init_options.c       |   4 +-
 tp/Texinfo/XS/convert/texinfo.c                    |   7 +-
 tp/Texinfo/XS/main/build_perl_info.c               |   2 +
 tp/Texinfo/XS/main/convert_to_text.c               |   1 +
 tp/Texinfo/XS/main/customization_options.c         | 535 +++++++++++++++++++++
 tp/Texinfo/XS/main/customization_options.h         |  63 +++
 tp/Texinfo/XS/main/document.c                      |   1 +
 tp/Texinfo/XS/main/get_perl_info.c                 |   1 +
 tp/Texinfo/XS/main/utils.c                         | 508 -------------------
 tp/Texinfo/XS/main/utils.h                         |  46 +-
 tp/Texinfo/XS/teximakehtml.c                       |   1 +
 tp/maintain/regenerate_C_options_info.pl           |   6 +-
 18 files changed, 634 insertions(+), 557 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 8b99d0264c..ea65a8c625 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2024-08-11  Patrice Dumas  <pertusus@free.fr>
+
+       * tp/Texinfo/XS/Makefile.am (libtexinfo_la_SOURCES),
+       tp/Texinfo/XS/main/utils.c,
+       tp/Texinfo/XS/main/customization_options.c: move functions related to
+       customization options out ot utils.c to the new to
+       main/customization_options.c file.
+
 2024-08-11  Patrice Dumas  <pertusus@free.fr>
 
        * tp/Texinfo/XS/convert/convert_html.c (html_free_converter),
diff --git a/tp/Texinfo/XS/Makefile.am b/tp/Texinfo/XS/Makefile.am
index 8289a55170..4d45079a87 100644
--- a/tp/Texinfo/XS/Makefile.am
+++ b/tp/Texinfo/XS/Makefile.am
@@ -135,6 +135,8 @@ C_libtexinfo_sources = \
                      main/convert_to_text.h \
                      main/convert_utils.c \
                      main/convert_utils.h \
+                     main/customization_options.c \
+                     main/customization_options.h \
                      main/conversion_data.c \
                      main/conversion_data.h \
                      main/floats.c \
diff --git a/tp/Texinfo/XS/convert/convert_html.c 
b/tp/Texinfo/XS/convert/convert_html.c
index 300367874e..658b910a2b 100644
--- a/tp/Texinfo/XS/convert/convert_html.c
+++ b/tp/Texinfo/XS/convert/convert_html.c
@@ -42,6 +42,7 @@
 #include "command_stack.h"
 #include "errors.h"
 #include "utils.h"
+#include "customization_options.h"
 #include "extra.h"
 #include "targets.h"
 #include "debug.h"
diff --git a/tp/Texinfo/XS/convert/converter.c 
b/tp/Texinfo/XS/convert/converter.c
index af32234382..793ed5c8f4 100644
--- a/tp/Texinfo/XS/convert/converter.c
+++ b/tp/Texinfo/XS/convert/converter.c
@@ -45,6 +45,7 @@
 /* for COMMAND_OPTION_DEFAULT ACCENTS_STACK
    fatal xasprintf get_command_option ... */
 #include "utils.h"
+#include "customization_options.h"
 #include "errors.h"
 #include "builtin_commands.h"
 /* also for cmd_text data */
diff --git a/tp/Texinfo/XS/convert/converters_defaults.c 
b/tp/Texinfo/XS/convert/converters_defaults.c
index 362928513f..8df7df7f40 100644
--- a/tp/Texinfo/XS/convert/converters_defaults.c
+++ b/tp/Texinfo/XS/convert/converters_defaults.c
@@ -3,7 +3,7 @@
 #include <config.h>
 
 #include "options_types.h"
-#include "utils.h"
+#include "customization_options.h"
 #include "converters_defaults.h"
 
 
diff --git a/tp/Texinfo/XS/convert/get_converter_perl_info.c 
b/tp/Texinfo/XS/convert/get_converter_perl_info.c
index 863b41d7df..fb490e3ff1 100644
--- a/tp/Texinfo/XS/convert/get_converter_perl_info.c
+++ b/tp/Texinfo/XS/convert/get_converter_perl_info.c
@@ -36,7 +36,7 @@
 #include "converter_types.h"
 #include "builtin_commands.h"
 #include "utils.h"
-#include "builtin_commands.h"
+#include "customization_options.h"
 #include "convert_to_text.h"
 #include "get_perl_info.h"
 #include "converter.h"
diff --git a/tp/Texinfo/XS/convert/html_converter_init_options.c 
b/tp/Texinfo/XS/convert/html_converter_init_options.c
index 554efadbd3..956aeadda4 100644
--- a/tp/Texinfo/XS/convert/html_converter_init_options.c
+++ b/tp/Texinfo/XS/convert/html_converter_init_options.c
@@ -22,8 +22,10 @@
 #include "option_types.h"
 #include "converter_types.h"
 #include "converters_defaults.h"
-/* option_force_conf */
+/* html_get_direction_index html_free_button_specification_list */
 #include "utils.h"
+/* option_force_conf */
+#include "customization_options.h"
 #include "create_buttons.h"
 #include "html_converter_init_options.h"
 
diff --git a/tp/Texinfo/XS/convert/texinfo.c b/tp/Texinfo/XS/convert/texinfo.c
index a1a451b6ac..4d359039f6 100644
--- a/tp/Texinfo/XS/convert/texinfo.c
+++ b/tp/Texinfo/XS/convert/texinfo.c
@@ -32,6 +32,7 @@
 #include "errors.h"
 /* parse_file_path */
 #include "utils.h"
+#include "customization_options.h"
 #include "document.h"
 #include "translations.h"
 #include "structuring.h"
@@ -270,7 +271,9 @@ txi_complete_document (DOCUMENT *document, unsigned long 
flags,
 
 /* converter creation, similar to the very first part of
    Texinfo::Convert::Converter::converter and generic parts of
-   _generic_converter_init */
+   _generic_converter_init, + some customization options settings
+   that are done in Perl directly in texi2any.pl.
+ */
 CONVERTER *
 txi_converter (enum converter_format format)
 {
@@ -323,11 +326,11 @@ txi_converter_initialize (CONVERTER *converter,
    */
   add_option_string_value (&conf->conf, converter->sorted_options,
                     "COMMAND_LINE_ENCODING", 0, locale_encoding);
-  /* this option is not used, it is filled to mimic texi2any */
   add_option_string_value (&conf->conf, converter->sorted_options,
                     "MESSAGE_ENCODING", 0, locale_encoding);
   add_option_string_value (&conf->conf, converter->sorted_options,
                     "LOCALE_ENCODING", 0, locale_encoding);
+  /* filled here because it is the best we have in C */
   add_option_string_value (&conf->conf, converter->sorted_options,
                     "XS_STRXFRM_COLLATION_LOCALE", 0, "en_US");
   /*
diff --git a/tp/Texinfo/XS/main/build_perl_info.c 
b/tp/Texinfo/XS/main/build_perl_info.c
index 1fd7ca9cdd..553f9efd2f 100644
--- a/tp/Texinfo/XS/main/build_perl_info.c
+++ b/tp/Texinfo/XS/main/build_perl_info.c
@@ -51,6 +51,8 @@
    direction_names expanded_formats_number output_unit_type_names
    informative_command_value get_global_document_command */
 #include "utils.h"
+/* find_option_string */
+#include "customization_options.h"
 /* for debugging */
 #include "debug.h"
 /* for clear_error_message_list */
diff --git a/tp/Texinfo/XS/main/convert_to_text.c 
b/tp/Texinfo/XS/main/convert_to_text.c
index 5a22a5ef55..5a9f49cd4c 100644
--- a/tp/Texinfo/XS/main/convert_to_text.c
+++ b/tp/Texinfo/XS/main/convert_to_text.c
@@ -33,6 +33,7 @@
 #include "tree.h"
 #include "extra.h"
 #include "builtin_commands.h"
+#include "customization_options.h"
 #include "utils.h"
 #include "unicode.h"
 /* for PARSED_DEF cdt_tree find_innermost_accent_contents add_heading_number
diff --git a/tp/Texinfo/XS/main/customization_options.c 
b/tp/Texinfo/XS/main/customization_options.c
new file mode 100644
index 0000000000..65af7ced63
--- /dev/null
+++ b/tp/Texinfo/XS/main/customization_options.c
@@ -0,0 +1,535 @@
+/* Copyright 2010-2024 Free Software Foundation, Inc.
+
+   This program is free software: you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation, either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>. */
+
+#include <config.h>
+
+#include <stdlib.h>
+#include <string.h>
+
+#include "option_types.h"
+#include "options_types.h"
+#include "converter_types.h"
+#include "api_to_perl.h"
+#include "utils.h"
+#include "customization_options.h"
+
+
+/* options and converters */
+OPTIONS *
+new_options (void)
+{
+  OPTIONS *options = (OPTIONS *) malloc (sizeof (OPTIONS));
+  memset (options, 0, sizeof (OPTIONS));
+  initialize_options (options);
+  return options;
+}
+
+static int
+compare_option_str (const void *a, const void *b)
+{
+  const OPTION **opt_a = (const OPTION **) a;
+  const OPTION **opt_b = (const OPTION **) b;
+
+  return strcmp ((*opt_a)->name, (*opt_b)->name);
+}
+
+/* sort options and set the index in the option structure to the index in
+   the sorted array */
+OPTION **
+setup_sorted_options (OPTIONS *options)
+{
+  size_t i;
+  OPTION **sorted_options = setup_sortable_options (options);
+  qsort (sorted_options, TXI_OPTIONS_NR, sizeof (OPTION *), 
compare_option_str);
+
+  for (i = 0; i < TXI_OPTIONS_NR; i++)
+    {
+      sorted_options[i]->number = i + 1;
+    }
+
+  return sorted_options;
+}
+
+OPTION *
+find_option_string (OPTION **sorted_options, const char *name)
+{
+  static OPTION option_key;
+  OPTION *option_ref = &option_key;
+  OPTION **result;
+
+  option_key.name = name;
+  result = (OPTION **)bsearch (&option_ref, sorted_options, TXI_OPTIONS_NR,
+                               sizeof (OPTION *), compare_option_str);
+  if (result)
+    return *result;
+  else
+    return 0;
+}
+
+void
+clear_option (OPTION *option)
+{
+  switch (option->type)
+    {
+      case GOT_char:
+      case GOT_bytes:
+        free (option->o.string);
+        option->o.string = 0;
+        break;
+
+      case GOT_bytes_string_list:
+      case GOT_file_string_list:
+      case GOT_char_string_list:
+        clear_strings_list (option->o.strlist);
+        break;
+
+      case GOT_buttons:
+        html_free_button_specification_list (option->o.buttons);
+        option->o.buttons = 0;
+        break;
+
+      case GOT_icons:
+        html_clear_direction_icons (option->o.icons);
+        break;
+
+      case GOT_integer:
+        option->o.integer = -1;
+
+      default:
+        break;
+    }
+}
+
+/* option is not supposed to be accessed again */
+void
+free_option (OPTION *option)
+{
+  switch (option->type)
+    {
+      case GOT_integer:
+        break;
+
+      case GOT_char:
+      case GOT_bytes:
+        free (option->o.string);
+        break;
+
+      case GOT_bytes_string_list:
+      case GOT_file_string_list:
+      case GOT_char_string_list:
+        destroy_strings_list (option->o.strlist);
+        break;
+
+      case GOT_buttons:
+        html_free_button_specification_list (option->o.buttons);
+        break;
+
+      case GOT_icons:
+        html_free_direction_icons (option->o.icons);
+        free (option->o.icons);
+        break;
+
+      default:
+        break;
+    }
+}
+
+void
+initialize_option (OPTION *option, enum global_option_type type,
+                   const char *name)
+{
+  option->type = type;
+  option->name = name;
+  option->number = 0;
+  switch (type)
+    {
+      case GOT_integer:
+        option->o.integer = -1;
+        break;
+
+      case GOT_char:
+      case GOT_bytes:
+        option->o.string = 0;
+        break;
+
+      case GOT_bytes_string_list:
+      case GOT_file_string_list:
+      case GOT_char_string_list:
+        option->o.strlist = new_string_list ();
+        break;
+
+      case GOT_buttons:
+        option->o.buttons = 0;
+        break;
+
+      case GOT_icons:
+        option->o.icons = (DIRECTION_ICON_LIST *)
+                          malloc (sizeof (DIRECTION_ICON_LIST));
+        memset (option->o.icons, 0, sizeof (DIRECTION_ICON_LIST));
+        break;
+
+      default:
+        break;
+    }
+}
+
+/* only for strings and integers */
+static void
+option_set_conf_internal (OPTION *option, int int_value, const char 
*char_value)
+{
+  switch (option->type)
+    {
+      case GOT_integer:
+        option->o.integer = int_value;
+        break;
+      case GOT_char:
+      case GOT_bytes:
+        free (option->o.string);
+        if (!char_value)
+          option->o.string = 0;
+        else
+          option->o.string = strdup (char_value);
+        break;
+
+      default:
+        fprintf (stderr, "BUG: set_conf type not handled: %d\n",
+                 option->type);
+    }
+}
+
+int
+option_set_conf (OPTION *option, int int_value, const char *char_value)
+{
+  if (option->configured > 0)
+    return 0;
+  option_set_conf_internal (option, int_value, char_value);
+  return 1;
+}
+
+void
+option_force_conf (OPTION *option, int int_value, const char *char_value)
+{
+  option_set_conf_internal (option, int_value, char_value);
+}
+
+void
+copy_option (OPTION *destination, const OPTION *source)
+{
+  switch (source->type)
+    {
+      case GOT_integer:
+        destination->o.integer = source->o.integer;
+        break;
+
+      case GOT_char:
+      case GOT_bytes:
+        free (destination->o.string);
+        if (!source->o.string)
+          destination->o.string = 0;
+        else
+          destination->o.string = strdup (source->o.string);
+        break;
+
+      case GOT_bytes_string_list:
+      case GOT_file_string_list:
+      case GOT_char_string_list:
+        clear_strings_list (destination->o.strlist);
+        copy_strings (destination->o.strlist, source->o.strlist);
+        break;
+
+      case GOT_icons:
+        {
+          DIRECTION_ICON_LIST *dest_icons = destination->o.icons;
+          DIRECTION_ICON_LIST *source_icons = source->o.icons;
+          html_free_direction_icons (dest_icons);
+          if (source_icons)
+            {
+              dest_icons->number = source_icons->number;
+              dest_icons->sv = source_icons->sv;
+              register_perl_data (dest_icons->sv);
+              if (dest_icons->number)
+                {
+                  size_t i;
+                  dest_icons->list = (char **) malloc
+                               (dest_icons->number * sizeof (char *));
+                  for (i = 0; i < dest_icons->number; i++)
+                    {
+                      if (!source_icons->list[i])
+                        dest_icons->list[i] = 0;
+                      else
+                        dest_icons->list[i] = strdup (source_icons->list[i]);
+                    }
+                }
+            }
+        }
+        break;
+
+      case GOT_buttons:
+        { /* Note that the caller should adjust BIT_user_function_number
+             of the options holding the buttons */
+          html_free_button_specification_list (destination->o.buttons);
+          destination->o.buttons = 0;
+          if (source->o.buttons)
+            {
+              size_t i;
+              BUTTON_SPECIFICATION_LIST *result;
+              BUTTON_SPECIFICATION_LIST *s_buttons = source->o.buttons;
+              result = (BUTTON_SPECIFICATION_LIST *)
+                malloc (sizeof (BUTTON_SPECIFICATION_LIST));
+
+              result->BIT_user_function_number
+                = s_buttons->BIT_user_function_number;
+              result->number = s_buttons->number;
+
+              result->av = s_buttons->av;
+              if (result->av)
+                register_perl_data (result->av);
+
+              result->list = (BUTTON_SPECIFICATION *)
+                 malloc (result->number * sizeof (BUTTON_SPECIFICATION));
+              memset (result->list, 0,
+                  result->number * sizeof (BUTTON_SPECIFICATION));
+              for (i = 0; i < result->number; i++)
+                {
+                  BUTTON_SPECIFICATION *button = &result->list[i];
+                  BUTTON_SPECIFICATION *s_button = &s_buttons->list[i];
+
+                  button->sv = s_button->sv;
+                  /* need to increase the counter, as it is decreased upon
+                     destroying the button */
+                  if (button->sv)
+                    register_perl_data (button->sv);
+                  button->type = s_button->type;
+                  if (button->type == BST_function)
+                    button->b.sv_reference = s_button->b.sv_reference;
+                  else if (button->type == BST_external_string)
+                    button->b.sv_string = s_button->b.sv_string;
+                  else if (button->type == BST_string)
+                    button->b.string = strdup (s_button->b.string);
+                  else if (button->type == BST_direction)
+                    button->b.direction = s_button->b.direction;
+                  else if (button->type == BST_direction_info)
+                    {
+                      BUTTON_SPECIFICATION_INFO *s_button_spec
+                        = s_button->b.button_info;
+                      BUTTON_SPECIFICATION_INFO *button_spec
+                        = (BUTTON_SPECIFICATION_INFO *)
+                         malloc (sizeof (BUTTON_SPECIFICATION_INFO));
+                      memset (button_spec, 0,
+                              sizeof (BUTTON_SPECIFICATION_INFO));
+                      button->b.button_info = button_spec;
+                      button_spec->type = s_button_spec->type;
+                      button_spec->direction = s_button_spec->direction;
+                      if (button_spec->type == BIT_function)
+                        {
+                          button_spec->bi.button_function.type
+                            = s_button_spec->bi.button_function.type;
+                          button_spec->bi.button_function.sv_reference
+                            = s_button_spec->bi.button_function.sv_reference;
+                        }
+                      else if (button_spec->type == BIT_external_string)
+                        button_spec->bi.sv_string
+                          = s_button_spec->bi.sv_string;
+                      else if (button_spec->type == BIT_string)
+                        button_spec->bi.string
+                          = strdup (s_button_spec->bi.string);
+                      else /* BIT_selected_direction_information_type
+                            and BIT_href_direction_information_type */
+                        button_spec->bi.direction_information_type
+                          = s_button_spec->bi.direction_information_type;
+                    }
+                }
+              destination->o.buttons = result;
+            }
+        }
+        break;
+
+      default:
+        fprintf (stderr, "BUG: copy_option type not handled: %d\n",
+                source->type);
+    }
+}
+
+void
+set_sorted_option_key_configured (OPTION **sorted_options, const char *key,
+                                  int configured)
+{
+  if (configured > 0)
+    {
+      OPTION *option = find_option_string (sorted_options, key);
+
+      if (option)
+        option->configured = configured;
+    }
+}
+
+void
+initialize_options_list (OPTIONS_LIST *options_list, size_t number)
+{
+  options_list->number = 0;
+  options_list->space = number;
+  if (number > 0)
+    {
+      options_list->list = (OPTION **) malloc (sizeof (OPTION *) * number);
+      memset (options_list->list, 0, sizeof (OPTION *) * number);
+    }
+  else
+    options_list->list = 0;
+}
+
+/* copy OPTIONS_LIST options to an OPTIONS structure, using the sorted options
+   to find the struct fields. */
+void
+copy_options_list_options (OPTIONS *options, OPTION **sorted_options,
+                           OPTIONS_LIST *options_list, int set_configured)
+{
+  size_t i;
+
+  for (i = 0; i < options_list->number; i++)
+    {
+      OPTION *src_option = options_list->list[i];
+      if (src_option->number > 0)
+        {
+          size_t index = src_option->number - 1;
+          OPTION *dst_option = sorted_options[index];
+
+          copy_option (dst_option, src_option);
+
+          if (dst_option->type == GOT_buttons
+              && dst_option->o.buttons && options)
+            options->BIT_user_function_number
+               += dst_option->o.buttons->BIT_user_function_number;
+
+          if (set_configured)
+            dst_option->configured = 1;
+        }
+    }
+}
+
+/* note that the value in union o is not initialized */
+OPTION *
+new_option (enum global_option_type type, const char *name, size_t number)
+{
+  OPTION *option = (OPTION *) malloc (sizeof (OPTION));
+
+  initialize_option (option, type, name);
+  option->number = number;
+  option->configured = 0;
+
+  return option;
+}
+
+static OPTION *
+new_option_string_value (OPTION **sorted_options,
+                         const char *option_name, int int_value,
+                         const char *char_value)
+{
+  OPTION *option;
+  const OPTION *ref_option = find_option_string (sorted_options, option_name);
+  if (!ref_option)
+    return 0;
+
+  option = new_option (ref_option->type, ref_option->name, ref_option->number);
+
+  option_set_conf (option, int_value, char_value);
+
+  return option;
+}
+
+void
+options_list_add_option (OPTIONS_LIST *options_list, OPTION *option)
+{
+  if (options_list->number >= options_list->space)
+    {
+      options_list->list = realloc (options_list->list,
+              (options_list->space += 5) * sizeof (OPTION *));
+    }
+  options_list->list[options_list->number] = option;
+  options_list->number++;
+}
+
+OPTION *
+add_option_string_value (OPTIONS_LIST *options_list, OPTION **sorted_options,
+                         const char *option_name, int int_value,
+                         const char *char_value)
+{
+  OPTION *option = new_option_string_value (sorted_options, option_name,
+                                            int_value, char_value);
+
+  if (option)
+    options_list_add_option (options_list, option);
+
+  return option;
+}
+
+OPTION *
+add_option_copy (OPTIONS_LIST *options_list, OPTION **sorted_options,
+                 const OPTION *src_option)
+{
+  OPTION *option
+    = new_option (src_option->type, src_option->name, src_option->number);
+
+  copy_option (option, src_option);
+
+  options_list_add_option (options_list, option);
+
+  return option;
+}
+
+/* similar with new_option_string_value but in cases where there is no
+   sorted_options, and options are found with their names, in practice
+   for parser options */
+OPTION *
+add_new_option_value (OPTIONS_LIST *options_list,
+                  enum global_option_type type, const char *name,
+                  int int_value, const char *char_value)
+{
+  OPTION *option = new_option (type, name, 0);
+
+  option_set_conf (option, int_value, char_value);
+
+  options_list_add_option (options_list, option);
+
+  return option;
+}
+
+
+void
+copy_options_list (OPTIONS_LIST *options_list,
+                   const OPTIONS_LIST *options_src, OPTION **sorted_options)
+{
+  size_t i;
+
+  if (options_src > 0)
+    {
+      for (i = 0; i < options_src->number; i++)
+        add_option_copy (options_list, sorted_options, options_src->list[i]);
+    }
+}
+
+void
+free_options_list (OPTIONS_LIST *options_list)
+{
+  size_t i;
+
+  for (i = 0; i < options_list->number; i++)
+    {
+      free_option (options_list->list[i]);
+      free (options_list->list[i]);
+    }
+
+  free (options_list->list);
+}
+
diff --git a/tp/Texinfo/XS/main/customization_options.h 
b/tp/Texinfo/XS/main/customization_options.h
new file mode 100644
index 0000000000..4e972ee396
--- /dev/null
+++ b/tp/Texinfo/XS/main/customization_options.h
@@ -0,0 +1,63 @@
+/* customization_options.h - declarations for customization_options.c */
+#ifndef CUSTOMIZATION_OPTIONS_H
+#define CUSTOMIZATION_OPTIONS_H
+
+/* Copyright 2010-2024 Free Software Foundation, Inc.
+
+   This program is free software: you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation, either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>. */
+
+#include "option_types.h"
+#include "options_types.h"
+#include "converter_types.h"
+
+/* in options_init_free.c */
+void initialize_options (OPTIONS *options);
+OPTION **setup_sortable_options (OPTIONS *options);
+void clear_options (OPTIONS *options);
+void free_options (OPTIONS *options);
+void copy_options (OPTIONS *destination, const OPTIONS *source);
+
+void copy_options_list_options (OPTIONS *options, OPTION **sorted_options,
+                                OPTIONS_LIST *options_list, int 
set_configured);
+void initialize_options_list (OPTIONS_LIST *options_list, size_t number);
+void free_options_list (OPTIONS_LIST *options_list);
+
+OPTIONS *new_options (void);
+OPTION **setup_sorted_options (OPTIONS *options);
+OPTION *find_option_string (OPTION **sorted_options, const char *name);
+void set_sorted_option_key_configured (OPTION **sorted_options,
+                                       const char *key, int configured);
+
+void initialize_option (OPTION *option, enum global_option_type type,
+                        const char *name);
+OPTION *new_option (enum global_option_type type, const char *name,
+                    size_t number);
+void clear_option (OPTION *option);
+void free_option (OPTION *option);
+void copy_option (OPTION *destination, const OPTION *source);
+int option_set_conf (OPTION *option, int int_value, const char *char_value);
+void option_force_conf (OPTION *option, int int_value, const char *char_value);
+OPTION *add_option_string_value (OPTIONS_LIST *options_list,
+                         OPTION **sorted_options,
+                         const char *option_name, int int_value,
+                         const char *char_value);
+void options_list_add_option (OPTIONS_LIST *options_list, OPTION *option);
+OPTION *add_new_option_value (OPTIONS_LIST *options_list,
+                  enum global_option_type type, const char *name,
+                  int int_value, const char *char_value);
+
+void copy_options_list (OPTIONS_LIST *options_list,
+                   const OPTIONS_LIST *options_src, OPTION **sorted_options);
+
+#endif
diff --git a/tp/Texinfo/XS/main/document.c b/tp/Texinfo/XS/main/document.c
index 79e5d67445..4e0cfc5e0c 100644
--- a/tp/Texinfo/XS/main/document.c
+++ b/tp/Texinfo/XS/main/document.c
@@ -29,6 +29,7 @@
 #include "debug.h"
 /* for delete_global_info and wipe_index */
 #include "utils.h"
+#include "customization_options.h"
 #include "floats.h"
 #include "manipulate_indices.h"
 #include "convert_to_text.h"
diff --git a/tp/Texinfo/XS/main/get_perl_info.c 
b/tp/Texinfo/XS/main/get_perl_info.c
index 4b6ae369a9..b5cb113e1b 100644
--- a/tp/Texinfo/XS/main/get_perl_info.c
+++ b/tp/Texinfo/XS/main/get_perl_info.c
@@ -39,6 +39,7 @@
 #include "builtin_commands.h"
 #include "debug.h"
 #include "utils.h"
+#include "customization_options.h"
 #include "errors.h"
 #include "targets.h"
 #include "parser_conf.h"
diff --git a/tp/Texinfo/XS/main/utils.c b/tp/Texinfo/XS/main/utils.c
index bf7c848a09..50cb31ae9d 100644
--- a/tp/Texinfo/XS/main/utils.c
+++ b/tp/Texinfo/XS/main/utils.c
@@ -1697,514 +1697,6 @@ html_get_direction_index (const CONVERTER *converter, 
const char *direction)
   return -1;
 }
 
-
-/* options and converters */
-OPTIONS *
-new_options (void)
-{
-  OPTIONS *options = (OPTIONS *) malloc (sizeof (OPTIONS));
-  memset (options, 0, sizeof (OPTIONS));
-  initialize_options (options);
-  return options;
-}
-
-static int
-compare_option_str (const void *a, const void *b)
-{
-  const OPTION **opt_a = (const OPTION **) a;
-  const OPTION **opt_b = (const OPTION **) b;
-
-  return strcmp ((*opt_a)->name, (*opt_b)->name);
-}
-
-/* sort options and set the index in the option structure to the index in
-   the sorted array */
-OPTION **
-setup_sorted_options (OPTIONS *options)
-{
-  size_t i;
-  OPTION **sorted_options = setup_sortable_options (options);
-  qsort (sorted_options, TXI_OPTIONS_NR, sizeof (OPTION *), 
compare_option_str);
-
-  for (i = 0; i < TXI_OPTIONS_NR; i++)
-    {
-      sorted_options[i]->number = i + 1;
-    }
-
-  return sorted_options;
-}
-
-OPTION *
-find_option_string (OPTION **sorted_options, const char *name)
-{
-  static OPTION option_key;
-  OPTION *option_ref = &option_key;
-  OPTION **result;
-
-  option_key.name = name;
-  result = (OPTION **)bsearch (&option_ref, sorted_options, TXI_OPTIONS_NR,
-                               sizeof (OPTION *), compare_option_str);
-  if (result)
-    return *result;
-  else
-    return 0;
-}
-
-void
-clear_option (OPTION *option)
-{
-  switch (option->type)
-    {
-      case GOT_char:
-      case GOT_bytes:
-        free (option->o.string);
-        option->o.string = 0;
-        break;
-
-      case GOT_bytes_string_list:
-      case GOT_file_string_list:
-      case GOT_char_string_list:
-        clear_strings_list (option->o.strlist);
-        break;
-
-      case GOT_buttons:
-        html_free_button_specification_list (option->o.buttons);
-        option->o.buttons = 0;
-        break;
-
-      case GOT_icons:
-        html_clear_direction_icons (option->o.icons);
-        break;
-
-      case GOT_integer:
-        option->o.integer = -1;
-
-      default:
-        break;
-    }
-}
-
-/* option is not supposed to be accessed again */
-void
-free_option (OPTION *option)
-{
-  switch (option->type)
-    {
-      case GOT_integer:
-        break;
-
-      case GOT_char:
-      case GOT_bytes:
-        free (option->o.string);
-        break;
-
-      case GOT_bytes_string_list:
-      case GOT_file_string_list:
-      case GOT_char_string_list:
-        destroy_strings_list (option->o.strlist);
-        break;
-
-      case GOT_buttons:
-        html_free_button_specification_list (option->o.buttons);
-        break;
-
-      case GOT_icons:
-        html_free_direction_icons (option->o.icons);
-        free (option->o.icons);
-        break;
-
-      default:
-        break;
-    }
-}
-
-void
-initialize_option (OPTION *option, enum global_option_type type,
-                   const char *name)
-{
-  option->type = type;
-  option->name = name;
-  option->number = 0;
-  switch (type)
-    {
-      case GOT_integer:
-        option->o.integer = -1;
-        break;
-
-      case GOT_char:
-      case GOT_bytes:
-        option->o.string = 0;
-        break;
-
-      case GOT_bytes_string_list:
-      case GOT_file_string_list:
-      case GOT_char_string_list:
-        option->o.strlist = new_string_list ();
-        break;
-
-      case GOT_buttons:
-        option->o.buttons = 0;
-        break;
-
-      case GOT_icons:
-        option->o.icons = (DIRECTION_ICON_LIST *)
-                          malloc (sizeof (DIRECTION_ICON_LIST));
-        memset (option->o.icons, 0, sizeof (DIRECTION_ICON_LIST));
-        break;
-
-      default:
-        break;
-    }
-}
-
-/* only for strings and integers */
-static void
-option_set_conf_internal (OPTION *option, int int_value, const char 
*char_value)
-{
-  switch (option->type)
-    {
-      case GOT_integer:
-        option->o.integer = int_value;
-        break;
-      case GOT_char:
-      case GOT_bytes:
-        free (option->o.string);
-        if (!char_value)
-          option->o.string = 0;
-        else
-          option->o.string = strdup (char_value);
-        break;
-
-      default:
-        fprintf (stderr, "BUG: set_conf type not handled: %d\n",
-                 option->type);
-    }
-}
-
-int
-option_set_conf (OPTION *option, int int_value, const char *char_value)
-{
-  if (option->configured > 0)
-    return 0;
-  option_set_conf_internal (option, int_value, char_value);
-  return 1;
-}
-
-void
-option_force_conf (OPTION *option, int int_value, const char *char_value)
-{
-  option_set_conf_internal (option, int_value, char_value);
-}
-
-void
-copy_option (OPTION *destination, const OPTION *source)
-{
-  switch (source->type)
-    {
-      case GOT_integer:
-        destination->o.integer = source->o.integer;
-        break;
-
-      case GOT_char:
-      case GOT_bytes:
-        free (destination->o.string);
-        if (!source->o.string)
-          destination->o.string = 0;
-        else
-          destination->o.string = strdup (source->o.string);
-        break;
-
-      case GOT_bytes_string_list:
-      case GOT_file_string_list:
-      case GOT_char_string_list:
-        clear_strings_list (destination->o.strlist);
-        copy_strings (destination->o.strlist, source->o.strlist);
-        break;
-
-      case GOT_icons:
-        {
-          DIRECTION_ICON_LIST *dest_icons = destination->o.icons;
-          DIRECTION_ICON_LIST *source_icons = source->o.icons;
-          html_free_direction_icons (dest_icons);
-          if (source_icons)
-            {
-              dest_icons->number = source_icons->number;
-              dest_icons->sv = source_icons->sv;
-              register_perl_data (dest_icons->sv);
-              if (dest_icons->number)
-                {
-                  size_t i;
-                  dest_icons->list = (char **) malloc
-                               (dest_icons->number * sizeof (char *));
-                  for (i = 0; i < dest_icons->number; i++)
-                    {
-                      if (!source_icons->list[i])
-                        dest_icons->list[i] = 0;
-                      else
-                        dest_icons->list[i] = strdup (source_icons->list[i]);
-                    }
-                }
-            }
-        }
-        break;
-
-      case GOT_buttons:
-        { /* Note that the caller should adjust BIT_user_function_number
-             of the options holding the buttons */
-          html_free_button_specification_list (destination->o.buttons);
-          destination->o.buttons = 0;
-          if (source->o.buttons)
-            {
-              size_t i;
-              BUTTON_SPECIFICATION_LIST *result;
-              BUTTON_SPECIFICATION_LIST *s_buttons = source->o.buttons;
-              result = (BUTTON_SPECIFICATION_LIST *)
-                malloc (sizeof (BUTTON_SPECIFICATION_LIST));
-
-              result->BIT_user_function_number
-                = s_buttons->BIT_user_function_number;
-              result->number = s_buttons->number;
-
-              result->av = s_buttons->av;
-              if (result->av)
-                register_perl_data (result->av);
-
-              result->list = (BUTTON_SPECIFICATION *)
-                 malloc (result->number * sizeof (BUTTON_SPECIFICATION));
-              memset (result->list, 0,
-                  result->number * sizeof (BUTTON_SPECIFICATION));
-              for (i = 0; i < result->number; i++)
-                {
-                  BUTTON_SPECIFICATION *button = &result->list[i];
-                  BUTTON_SPECIFICATION *s_button = &s_buttons->list[i];
-
-                  button->sv = s_button->sv;
-                  /* need to increase the counter, as it is decreased upon
-                     destroying the button */
-                  if (button->sv)
-                    register_perl_data (button->sv);
-                  button->type = s_button->type;
-                  if (button->type == BST_function)
-                    button->b.sv_reference = s_button->b.sv_reference;
-                  else if (button->type == BST_external_string)
-                    button->b.sv_string = s_button->b.sv_string;
-                  else if (button->type == BST_string)
-                    button->b.string = strdup (s_button->b.string);
-                  else if (button->type == BST_direction)
-                    button->b.direction = s_button->b.direction;
-                  else if (button->type == BST_direction_info)
-                    {
-                      BUTTON_SPECIFICATION_INFO *s_button_spec
-                        = s_button->b.button_info;
-                      BUTTON_SPECIFICATION_INFO *button_spec
-                        = (BUTTON_SPECIFICATION_INFO *)
-                         malloc (sizeof (BUTTON_SPECIFICATION_INFO));
-                      memset (button_spec, 0,
-                              sizeof (BUTTON_SPECIFICATION_INFO));
-                      button->b.button_info = button_spec;
-                      button_spec->type = s_button_spec->type;
-                      button_spec->direction = s_button_spec->direction;
-                      if (button_spec->type == BIT_function)
-                        {
-                          button_spec->bi.button_function.type
-                            = s_button_spec->bi.button_function.type;
-                          button_spec->bi.button_function.sv_reference
-                            = s_button_spec->bi.button_function.sv_reference;
-                        }
-                      else if (button_spec->type == BIT_external_string)
-                        button_spec->bi.sv_string
-                          = s_button_spec->bi.sv_string;
-                      else if (button_spec->type == BIT_string)
-                        button_spec->bi.string
-                          = strdup (s_button_spec->bi.string);
-                      else /* BIT_selected_direction_information_type
-                            and BIT_href_direction_information_type */
-                        button_spec->bi.direction_information_type
-                          = s_button_spec->bi.direction_information_type;
-                    }
-                }
-              destination->o.buttons = result;
-            }
-        }
-        break;
-
-      default:
-        fprintf (stderr, "BUG: copy_option type not handled: %d\n",
-                source->type);
-    }
-}
-
-void
-set_sorted_option_key_configured (OPTION **sorted_options, const char *key,
-                                  int configured)
-{
-  if (configured > 0)
-    {
-      OPTION *option = find_option_string (sorted_options, key);
-
-      if (option)
-        option->configured = configured;
-    }
-}
-
-void
-initialize_options_list (OPTIONS_LIST *options_list, size_t number)
-{
-  options_list->number = 0;
-  options_list->space = number;
-  if (number > 0)
-    {
-      options_list->list = (OPTION **) malloc (sizeof (OPTION *) * number);
-      memset (options_list->list, 0, sizeof (OPTION *) * number);
-    }
-  else
-    options_list->list = 0;
-}
-
-/* copy OPTIONS_LIST options to an OPTIONS structure, using the sorted options
-   to find the struct fields. */
-void
-copy_options_list_options (OPTIONS *options, OPTION **sorted_options,
-                           OPTIONS_LIST *options_list, int set_configured)
-{
-  size_t i;
-
-  for (i = 0; i < options_list->number; i++)
-    {
-      OPTION *src_option = options_list->list[i];
-      if (src_option->number > 0)
-        {
-          size_t index = src_option->number - 1;
-          OPTION *dst_option = sorted_options[index];
-
-          copy_option (dst_option, src_option);
-
-          if (dst_option->type == GOT_buttons
-              && dst_option->o.buttons && options)
-            options->BIT_user_function_number
-               += dst_option->o.buttons->BIT_user_function_number;
-
-          if (set_configured)
-            dst_option->configured = 1;
-        }
-    }
-}
-
-/* note that the value in union o is not initialized */
-OPTION *
-new_option (enum global_option_type type, const char *name, size_t number)
-{
-  OPTION *option = (OPTION *) malloc (sizeof (OPTION));
-
-  initialize_option (option, type, name);
-  option->number = number;
-  option->configured = 0;
-
-  return option;
-}
-
-static OPTION *
-new_option_string_value (OPTION **sorted_options,
-                         const char *option_name, int int_value,
-                         const char *char_value)
-{
-  OPTION *option;
-  const OPTION *ref_option = find_option_string (sorted_options, option_name);
-  if (!ref_option)
-    return 0;
-
-  option = new_option (ref_option->type, ref_option->name, ref_option->number);
-
-  option_set_conf (option, int_value, char_value);
-
-  return option;
-}
-
-void
-options_list_add_option (OPTIONS_LIST *options_list, OPTION *option)
-{
-  if (options_list->number >= options_list->space)
-    {
-      options_list->list = realloc (options_list->list,
-              (options_list->space += 5) * sizeof (OPTION *));
-    }
-  options_list->list[options_list->number] = option;
-  options_list->number++;
-}
-
-OPTION *
-add_option_string_value (OPTIONS_LIST *options_list, OPTION **sorted_options,
-                         const char *option_name, int int_value,
-                         const char *char_value)
-{
-  OPTION *option = new_option_string_value (sorted_options, option_name,
-                                            int_value, char_value);
-
-  if (option)
-    options_list_add_option (options_list, option);
-
-  return option;
-}
-
-OPTION *
-add_option_copy (OPTIONS_LIST *options_list, OPTION **sorted_options,
-                 const OPTION *src_option)
-{
-  OPTION *option
-    = new_option (src_option->type, src_option->name, src_option->number);
-
-  copy_option (option, src_option);
-
-  options_list_add_option (options_list, option);
-
-  return option;
-}
-
-/* similar with new_option_string_value but in cases where there is no
-   sorted_options, and options are found with their names, in practice
-   for parser options */
-OPTION *
-add_new_option_value (OPTIONS_LIST *options_list,
-                  enum global_option_type type, const char *name,
-                  int int_value, const char *char_value)
-{
-  OPTION *option = new_option (type, name, 0);
-
-  option_set_conf (option, int_value, char_value);
-
-  options_list_add_option (options_list, option);
-
-  return option;
-}
-
-
-void
-copy_options_list (OPTIONS_LIST *options_list,
-                   const OPTIONS_LIST *options_src, OPTION **sorted_options)
-{
-  size_t i;
-
-  if (options_src > 0)
-    {
-      for (i = 0; i < options_src->number; i++)
-        add_option_copy (options_list, sorted_options, options_src->list[i]);
-    }
-}
-
-void
-free_options_list (OPTIONS_LIST *options_list)
-{
-  size_t i;
-
-  for (i = 0; i < options_list->number; i++)
-    {
-      free_option (options_list->list[i]);
-      free (options_list->list[i]);
-    }
-
-  free (options_list->list);
-}
-
 
 
 void
diff --git a/tp/Texinfo/XS/main/utils.h b/tp/Texinfo/XS/main/utils.h
index 6a7d8e1221..5a967f206c 100644
--- a/tp/Texinfo/XS/main/utils.h
+++ b/tp/Texinfo/XS/main/utils.h
@@ -205,30 +205,11 @@ void destroy_accent_stack (ACCENTS_STACK *accent_stack);
 void wipe_index (INDEX *idx);
 void free_indices_info (INDEX_LIST *indices_info);
 
-/* in options_init_free.c */
-void initialize_options (OPTIONS *options);
-OPTION **setup_sortable_options (OPTIONS *options);
-void clear_options (OPTIONS *options);
-void free_options (OPTIONS *options);
-void copy_options (OPTIONS *destination, const OPTIONS *source);
-void html_fill_options_directions (OPTIONS *options, const CONVERTER 
*converter);
-
-void copy_options_list_options (OPTIONS *options, OPTION **sorted_options,
-                                OPTIONS_LIST *options_list, int 
set_configured);
-void initialize_options_list (OPTIONS_LIST *options_list, size_t number);
-void free_options_list (OPTIONS_LIST *options_list);
-void html_fill_button_directions_specification_list (const CONVERTER 
*converter,
-                                              BUTTON_SPECIFICATION_LIST 
*buttons);
-
-OPTIONS *new_options (void);
-OPTION **setup_sorted_options (OPTIONS *options);
-OPTION *find_option_string (OPTION **sorted_options, const char *name);
-void set_sorted_option_key_configured (OPTION **sorted_options,
-                                       const char *key, int configured);
-
 void set_output_encoding (OPTIONS *customization_information,
                           DOCUMENT *document);
+/* in options_init_free.c */
 OPTION *get_command_option (OPTIONS *options, enum command_id cmd);
+void html_fill_options_directions (OPTIONS *options, const CONVERTER 
*converter);
 
 void add_include_directory (const char *filename,
                             STRING_LIST *include_dirs_list);
@@ -271,33 +252,14 @@ const ELEMENT *get_cmd_global_uniq_command (
                                     const GLOBAL_COMMANDS *global_commands_ref,
                                     enum command_id cmd);
 
+void html_fill_button_directions_specification_list (const CONVERTER 
*converter,
+                                              BUTTON_SPECIFICATION_LIST 
*buttons);
 void html_free_button_specification_list (BUTTON_SPECIFICATION_LIST *buttons);
 void html_clear_direction_icons (DIRECTION_ICON_LIST *direction_icons);
 void html_free_direction_icons (DIRECTION_ICON_LIST *direction_icons);
 int html_get_direction_index (const CONVERTER *converter,
                               const char *direction);
 
-void initialize_option (OPTION *option, enum global_option_type type,
-                        const char *name);
-OPTION *new_option (enum global_option_type type, const char *name,
-                    size_t number);
-void clear_option (OPTION *option);
-void free_option (OPTION *option);
-void copy_option (OPTION *destination, const OPTION *source);
-int option_set_conf (OPTION *option, int int_value, const char *char_value);
-void option_force_conf (OPTION *option, int int_value, const char *char_value);
-OPTION *add_option_string_value (OPTIONS_LIST *options_list,
-                         OPTION **sorted_options,
-                         const char *option_name, int int_value,
-                         const char *char_value);
-void options_list_add_option (OPTIONS_LIST *options_list, OPTION *option);
-OPTION *add_new_option_value (OPTIONS_LIST *options_list,
-                  enum global_option_type type, const char *name,
-                  int int_value, const char *char_value);
-
-void copy_options_list (OPTIONS_LIST *options_list,
-                   const OPTIONS_LIST *options_src, OPTION **sorted_options);
-
 TARGET_FILENAME *new_target_filename (void);
 TARGET_CONTENTS_FILENAME *new_target_contents_filename (void);
 FILE_NAME_PATH *new_file_name_path (void);
diff --git a/tp/Texinfo/XS/teximakehtml.c b/tp/Texinfo/XS/teximakehtml.c
index 0afd1d0c0b..8d4d270b16 100644
--- a/tp/Texinfo/XS/teximakehtml.c
+++ b/tp/Texinfo/XS/teximakehtml.c
@@ -31,6 +31,7 @@
 #include "converter_types.h"
 /* parse_file_path */
 #include "utils.h"
+#include "customization_options.h"
 /*
 #include "convert_to_texinfo.h"
  */
diff --git a/tp/maintain/regenerate_C_options_info.pl 
b/tp/maintain/regenerate_C_options_info.pl
index e593b5864e..4a0920b10f 100755
--- a/tp/maintain/regenerate_C_options_info.pl
+++ b/tp/maintain/regenerate_C_options_info.pl
@@ -193,7 +193,9 @@ print CODE '#include <string.h>'."\n\n";
 print CODE '#include "option_types.h"'."\n";
 print CODE '#include "options_types.h"'."\n";
 print CODE '#include "converter_types.h"'."\n";
-print CODE '#include "utils.h"'."\n\n";
+# for html_fill_button_directions_specification_list
+print CODE '#include "main/utils.h"'."\n";
+print CODE '#include "customization_options.h"'."\n\n";
 
 print CODE "void\ninitialize_options (OPTIONS *options)\n{\n";
 print CODE "  options->BIT_user_function_number = 0;\n";
@@ -378,7 +380,7 @@ print OCDEF "/* Automatically generated from $program_name 
*/\n\n";
 print OCDEF '#include <config.h>'."\n\n";
 
 print OCDEF '#include "options_types.h"'."\n";
-print OCDEF '#include "utils.h"'."\n";
+print OCDEF '#include "customization_options.h"'."\n";
 print OCDEF '#include "converters_defaults.h"'."\n\n";
 
 open(OHDEF, ">$converter_defaults_header_file")



reply via email to

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