texinfo-commits
[Top][All Lists]
Advanced

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

[no subject]


From: Patrice Dumas
Date: Wed, 2 Oct 2024 14:43:08 -0400 (EDT)

branch: master
commit 4db7214396401cab030f9444fb73533c0cece3f9
Author: Patrice Dumas <pertusus@free.fr>
AuthorDate: Sat Aug 3 20:13:28 2024 +0200

    * tp/Texinfo/XS/convert/ConvertXS.xs,
    tp/Texinfo/XS/main/get_perl_info.c: remove reset_output_init_conf and
    copy_converter_conf_sv.
    
    * tp/maintain/regenerate_C_options_info.pl: rename generated
    get_sv_option as get_options_key_sv_option.
    
    * tp/Texinfo/XS/main/get_perl_info.c (get_sv_option)
    (get_sorted_options_key_sv_option): add get_sv_option function
    that sets an OPTION based on a Perl SV, for all the types of options.
    Add get_sorted_options_key_sv_option that finds an option using sorted
    options and then sets it with Perl SV.
    
    * tp/Texinfo/XS/main/get_perl_info.c (get_sv_options)
    (init_copy_sv_options): add a sorted_options argument to
    get_sv_options and use get_sorted_options_key_sv_option.  Change
    init_copy_sv_options to set sorted options too and optionally get them
    back.  Update callers.
    
    * tp/Texinfo/XS/main/DocumentXS.xs (register_document_options),
    tp/Texinfo/XS/main/document.c (register_document_options),
    tp/Texinfo/XS/main/document.h (DOCUMENT): add and set sorted_options
    field in DOCUMENT;
    
    * tp/Texinfo/XS/main/utils.c (free_option, initialize_option): always
    the same order with integer then char.
---
 ChangeLog                                       |  29 +++++
 tp/Texinfo/XS/convert/ConvertXS.xs              |   4 -
 tp/Texinfo/XS/convert/get_converter_perl_info.c |   7 +-
 tp/Texinfo/XS/convert/get_converter_perl_info.h |   1 -
 tp/Texinfo/XS/main/DocumentXS.xs                |   6 +-
 tp/Texinfo/XS/main/document.c                   |   4 +-
 tp/Texinfo/XS/main/document.h                   |   3 +-
 tp/Texinfo/XS/main/document_types.h             |   2 +
 tp/Texinfo/XS/main/get_perl_info.c              | 143 +++++++++++++++++++-----
 tp/Texinfo/XS/main/get_perl_info.h              |  13 +--
 tp/Texinfo/XS/main/utils.c                      |  15 +--
 tp/maintain/regenerate_C_options_info.pl        |   3 +-
 12 files changed, 175 insertions(+), 55 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 45077f55fd..a793088019 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,32 @@
+2024-08-03  Patrice Dumas  <pertusus@free.fr>
+
+       * tp/Texinfo/XS/convert/ConvertXS.xs,
+       tp/Texinfo/XS/main/get_perl_info.c: remove reset_output_init_conf and
+       copy_converter_conf_sv.
+
+       * tp/maintain/regenerate_C_options_info.pl: rename generated
+       get_sv_option as get_options_key_sv_option.
+
+       * tp/Texinfo/XS/main/get_perl_info.c (get_sv_option)
+       (get_sorted_options_key_sv_option): add get_sv_option function
+       that sets an OPTION based on a Perl SV, for all the types of options.
+       Add get_sorted_options_key_sv_option that finds an option using sorted
+       options and then sets it with Perl SV.
+
+       * tp/Texinfo/XS/main/get_perl_info.c (get_sv_options)
+       (init_copy_sv_options): add a sorted_options argument to
+       get_sv_options and use get_sorted_options_key_sv_option.  Change
+       init_copy_sv_options to set sorted options too and optionally get them
+       back.  Update callers.
+
+       * tp/Texinfo/XS/main/DocumentXS.xs (register_document_options),
+       tp/Texinfo/XS/main/document.c (register_document_options),
+       tp/Texinfo/XS/main/document.h (DOCUMENT): add and set sorted_options
+       field in DOCUMENT;
+
+       * tp/Texinfo/XS/main/utils.c (free_option, initialize_option): always
+       the same order with integer then char.
+
 2024-10-02  Patrice Dumas  <pertusus@free.fr>
 
        * doc/texinfo.texi (HTML Xref Configuration):
diff --git a/tp/Texinfo/XS/convert/ConvertXS.xs 
b/tp/Texinfo/XS/convert/ConvertXS.xs
index 7c932cbfd7..6980124e08 100644
--- a/tp/Texinfo/XS/convert/ConvertXS.xs
+++ b/tp/Texinfo/XS/convert/ConvertXS.xs
@@ -2362,10 +2362,6 @@ html_check_htmlxref_already_warned (SV *converter_in, 
manual_name, SV *source_in
     OUTPUT:
          RETVAL
 
-# currently unused
-void
-reset_output_init_conf (SV *sv_in)
-
 #  my ($output_units, $special_units, $associated_special_units)
 #    = $self->_prepare_conversion_units($document, $document_name);
 void
diff --git a/tp/Texinfo/XS/convert/get_converter_perl_info.c 
b/tp/Texinfo/XS/convert/get_converter_perl_info.c
index 8addf5d0d3..5a162a9510 100644
--- a/tp/Texinfo/XS/convert/get_converter_perl_info.c
+++ b/tp/Texinfo/XS/convert/get_converter_perl_info.c
@@ -219,7 +219,8 @@ converter_initialize_sv (SV *converter_sv, CONVERTER 
*converter,
       SV **converted_format_sv;
       HV *format_defaults_hv = (HV *)SvRV (format_defaults);
 
-      get_sv_options (format_defaults, converter->conf, converter, 0);
+      get_sv_options (format_defaults, converter->conf,
+                      converter->sorted_options, converter, 0);
 
 #define FETCH(key) key##_sv = hv_fetch (format_defaults_hv, #key, strlen 
(#key), 0);
       FETCH(output_format)
@@ -250,8 +251,8 @@ converter_initialize_sv (SV *converter_sv, CONVERTER 
*converter,
           char *key;
           I32 retlen;
           SV *value = hv_iternextsv (conf_hv, &key, &retlen);
-          int status
-            = get_sv_option (converter->conf, key, value, 0, converter);
+          int status = get_sorted_options_key_sv_option (converter->conf,
+                        converter->sorted_options, key, value, 0, converter);
 
           /*
           fprintf (stderr, "CONF: format %s: set %s: %d\n",
diff --git a/tp/Texinfo/XS/convert/get_converter_perl_info.h 
b/tp/Texinfo/XS/convert/get_converter_perl_info.h
index 1d7dc5e8db..1a540318f8 100644
--- a/tp/Texinfo/XS/convert/get_converter_perl_info.h
+++ b/tp/Texinfo/XS/convert/get_converter_perl_info.h
@@ -12,7 +12,6 @@ struct TEXT_OPTIONS;
 CONVERTER *get_sv_converter (SV *sv_in, const char *warn_string);
 void converter_initialize_sv (SV *converter_sv, CONVERTER *converter,
                               SV *format_defaults, SV *conf);
-void reset_output_init_conf (SV *sv_in);
 CONVERTER *converter_set_document_from_sv (SV *converter_in, SV *document_in);
 
 struct TEXT_OPTIONS *copy_sv_options_for_convert_text (SV *sv_in);
diff --git a/tp/Texinfo/XS/main/DocumentXS.xs b/tp/Texinfo/XS/main/DocumentXS.xs
index 9a204e8ddb..ad2d1b4a09 100644
--- a/tp/Texinfo/XS/main/DocumentXS.xs
+++ b/tp/Texinfo/XS/main/DocumentXS.xs
@@ -158,8 +158,10 @@ register_document_options (SV *document_in, SV 
*sv_options_in)
                                              "set_document_options");
         if (document)
           {
-            OPTIONS *options = init_copy_sv_options (sv_options_in, 0, 0);
-            register_document_options (document, options);
+            OPTION **sorted_options;
+            OPTIONS *options = init_copy_sv_options (sv_options_in, 0, 0,
+                                                     &sorted_options);
+            register_document_options (document, options, sorted_options);
           }
 
 SV *
diff --git a/tp/Texinfo/XS/main/document.c b/tp/Texinfo/XS/main/document.c
index 32c131af22..48cf3b289f 100644
--- a/tp/Texinfo/XS/main/document.c
+++ b/tp/Texinfo/XS/main/document.c
@@ -115,9 +115,11 @@ register_document_sections_list (DOCUMENT *document,
 }
 
 void
-register_document_options (DOCUMENT *document, OPTIONS *options)
+register_document_options (DOCUMENT *document, OPTIONS *options,
+                           OPTION **sorted_options)
 {
   document->options = options;
+  document->sorted_options = sorted_options;
 }
 
 const MERGED_INDICES *
diff --git a/tp/Texinfo/XS/main/document.h b/tp/Texinfo/XS/main/document.h
index af50299644..1050d8e059 100644
--- a/tp/Texinfo/XS/main/document.h
+++ b/tp/Texinfo/XS/main/document.h
@@ -18,7 +18,8 @@ void register_document_nodes_list (DOCUMENT *document,
                                    CONST_ELEMENT_LIST *nodes_list);
 void register_document_sections_list (DOCUMENT *document,
                                       CONST_ELEMENT_LIST *sections_list);
-void register_document_options (DOCUMENT *document, OPTIONS *options);
+void register_document_options (DOCUMENT *document, OPTIONS *options,
+                                OPTION **sorted_options);
 void register_document_convert_index_text_options (DOCUMENT *document,
                                          struct TEXT_OPTIONS *text_options);
 
diff --git a/tp/Texinfo/XS/main/document_types.h 
b/tp/Texinfo/XS/main/document_types.h
index 4deee2c936..2bdf5b1acf 100644
--- a/tp/Texinfo/XS/main/document_types.h
+++ b/tp/Texinfo/XS/main/document_types.h
@@ -20,6 +20,7 @@
 #include <stddef.h>
 
 #include "tree_types.h"
+#include "option_types.h"
 #include "global_commands_types.h"
 /*
 #include "options_types.h"
@@ -217,6 +218,7 @@ typedef struct DOCUMENT {
     CONST_ELEMENT_LIST *nodes_list;
     CONST_ELEMENT_LIST *sections_list;
     struct OPTIONS *options; /* for options used in structuring */
+    OPTION **sorted_options;
     struct TEXT_OPTIONS *convert_index_text_options; /* for index
                                        sorting without converter */
     INDICES_SORT_STRINGS *indices_sort_strings;
diff --git a/tp/Texinfo/XS/main/get_perl_info.c 
b/tp/Texinfo/XS/main/get_perl_info.c
index a927a7b26c..dae4c50b52 100644
--- a/tp/Texinfo/XS/main/get_perl_info.c
+++ b/tp/Texinfo/XS/main/get_perl_info.c
@@ -379,9 +379,108 @@ get_line_message (CONVERTER *self, enum error_type type, 
int continuation,
   non_perl_free (source_info);
 }
 
+static int
+get_sv_option (OPTION *option, SV *value, int force,
+               OPTIONS *options, const CONVERTER *converter)
+{
+  dTHX;
+
+  if (force <= 0 && option->configured > 0)
+    return -1;
+
+  switch (option->type)
+    {
+      case GOT_integer:
+        if (SvOK (value))
+          {
+            if (looks_like_number (value))
+            option->o.integer = SvIV (value);
+        else
+          {
+            fprintf (stderr, "BUG: %s: not an integer: %s\n",
+                     option->name, SvPVutf8_nolen (value));
+              option->o.integer = -1;
+              return -3;
+            }
+          }
+        else
+          option->o.integer = -1;
+
+        break;
+
+      case GOT_char:
+        non_perl_free (option->o.string);
+        if (SvOK (value))
+          option->o.string = non_perl_strdup (SvPVutf8_nolen (value));
+        else
+          option->o.string = 0;
+        break;
+
+      case GOT_bytes:
+        non_perl_free (option->o.string);
+        if (SvOK (value))
+          option->o.string = non_perl_strdup (SvPVbyte_nolen (value));
+        else
+          option->o.string = 0;
+        break;
+
+      case GOT_bytes_string_list:
+        clear_strings_list (option->o.strlist);
+        add_svav_to_string_list (value, option->o.strlist, svt_byte);
+        break;
+
+      case GOT_file_string_list:
+        clear_strings_list (option->o.strlist);
+        add_svav_to_string_list (value, option->o.strlist, svt_dir);
+        break;
+
+      case GOT_char_string_list:
+        clear_strings_list (option->o.strlist);
+        add_svav_to_string_list (value, option->o.strlist, svt_char);
+        break;
+
+      case GOT_buttons:
+        if (option->o.buttons)
+          {
+            options->BIT_user_function_number
+               -= option->o.buttons->BIT_user_function_number;
+            html_free_button_specification_list (option->o.buttons);
+          }
+
+        option->o.buttons
+           = html_get_button_specification_list (converter, value);
+        if (option->o.buttons)
+          options->BIT_user_function_number
+            += option->o.buttons->BIT_user_function_number;
+        break;
+
+      case GOT_icons:
+        html_free_direction_icons (option->o.icons);
+        html_get_direction_icons_sv (converter, option->o.icons, value);
+
+        break;
+
+      default:
+        break;
+    }
+
+  return 0;
+}
+
+
+int get_sorted_options_key_sv_option (OPTIONS *options, OPTION 
**sorted_options,
+                                      const char *key, SV *value,
+                                      int force, const CONVERTER *converter)
+{
+  OPTION *option = find_option_string (sorted_options, key);
+  if (option)
+    return get_sv_option (option, value, force, options, converter);
+  return -2;
+}
+
 void
-get_sv_options (SV *sv, OPTIONS *options, CONVERTER *converter,
-                int force)
+get_sv_options (SV *sv, OPTIONS *options, OPTION **sorted_options,
+                CONVERTER *converter, int force)
 {
   I32 hv_number;
   I32 i;
@@ -398,39 +497,25 @@ get_sv_options (SV *sv, OPTIONS *options, CONVERTER 
*converter,
       I32 retlen;
       SV *value = hv_iternextsv (hv, &key, &retlen);
 
-      get_sv_option (options, key, value, force, converter);
+      get_sorted_options_key_sv_option (options, sorted_options, key,
+                                        value, force, converter);
     }
 }
 
 OPTIONS *
-init_copy_sv_options (SV *sv_in, CONVERTER *converter, int force)
+init_copy_sv_options (SV *sv_in, CONVERTER *converter, int force,
+                      OPTION ***sorted_options_out)
 {
   OPTIONS *options = new_options ();
-  get_sv_options (sv_in, options, converter, force);
+  OPTION **sorted_options = setup_sorted_options (options);
+  get_sv_options (sv_in, options, sorted_options, converter, force);
+  if (sorted_options_out)
+    *sorted_options_out = sorted_options;
+  else
+    free (sorted_options);
   return options;
 }
 
-void
-copy_converter_conf_sv (HV *hv, CONVERTER *converter,
-                        OPTIONS **conf, const char *conf_key, int force)
-{
-  SV **conf_sv;
-
-  dTHX;
-
-  conf_sv = hv_fetch (hv, conf_key, strlen (conf_key), 0);
-
-  if (conf_sv && SvOK(*conf_sv))
-    {
-      if (*conf)
-        clear_options (*conf);
-      else
-        *conf = new_options ();
-
-      get_sv_options (*conf_sv, *conf, converter, force);
-    }
-}
-
 INDEX_ENTRY *
 find_index_entry_sv (const SV *index_entry_sv, INDEX_LIST *indices_info,
                      const char *warn_string, const INDEX **entry_idx,
@@ -695,7 +780,8 @@ set_sv_conf (CONVERTER *converter, const char *conf, SV 
*value)
 {
   if (converter->conf)
     {
-      int status = get_sv_option (converter->conf, conf, value, 0, converter);
+      int status = get_sorted_options_key_sv_option (converter->conf,
+                       converter->sorted_options, conf, value, 0, converter);
       if (status == 0)
         return 1;
     }
@@ -710,7 +796,8 @@ void
 force_sv_conf (CONVERTER *converter, const char *conf, SV *value)
 {
   if (converter->conf)
-    get_sv_option (converter->conf, conf, value, 1, converter);
+    get_sorted_options_key_sv_option (converter->conf,
+                       converter->sorted_options, conf, value, 1, converter);
 }
 
 /* output format specific */
diff --git a/tp/Texinfo/XS/main/get_perl_info.h 
b/tp/Texinfo/XS/main/get_perl_info.h
index bccd435f7f..6102b8228f 100644
--- a/tp/Texinfo/XS/main/get_perl_info.h
+++ b/tp/Texinfo/XS/main/get_perl_info.h
@@ -19,16 +19,16 @@
   -2: unknown
   -3: type error
  */
-int get_sv_option (OPTIONS *options, const char *key, SV *value,
-                   int force, const CONVERTER *converter);
+int get_options_key_sv_option (OPTIONS *options, const char *key, SV *value,
+                               int force, const CONVERTER *converter);
 void html_fill_options (OPTIONS *options, const CONVERTER *converter);
 
 /* in options_init_free.c */
 void set_option_key_configured (OPTIONS *options, const char *key,
                                 int configured);
 
-void get_sv_options (SV *sv, OPTIONS *options, CONVERTER *converter,
-                     int force);
+void get_sv_options (SV *sv, OPTIONS *options, OPTION **sorted_options,
+                     CONVERTER *converter, int force);
 void set_translated_commands (CONVERTER *converter, HV *hv_in);
 
 DOCUMENT *get_sv_tree_document (SV *tree_in, char *warn_string);
@@ -47,9 +47,8 @@ void add_svav_to_string_list (const SV *sv, STRING_LIST 
*string_list,
 SOURCE_INFO *get_source_info (SV *source_info_sv);
 void get_line_message (CONVERTER *self, enum error_type type, int continuation,
                        SV *error_location_info, const char *message);
-OPTIONS *init_copy_sv_options (SV *sv_in, CONVERTER *converter, int force);
-void copy_converter_conf_sv (HV *hv, CONVERTER *converter,
-                             OPTIONS **conf, const char *conf_key, int force);
+OPTIONS *init_copy_sv_options (SV *sv_in, CONVERTER *converter, int force,
+                               OPTION ***sorted_options_out);
 int set_sv_conf (CONVERTER *converter, const char *conf, SV *value);
 void force_sv_conf (CONVERTER *converter, const char *conf, SV *value);
 
diff --git a/tp/Texinfo/XS/main/utils.c b/tp/Texinfo/XS/main/utils.c
index e07b8f66bf..98de8ee7cd 100644
--- a/tp/Texinfo/XS/main/utils.c
+++ b/tp/Texinfo/XS/main/utils.c
@@ -1784,6 +1784,9 @@ free_option (OPTION *option)
 {
   switch (option->type)
     {
+      case GOT_integer:
+        break;
+
       case GOT_char:
       case GOT_bytes:
         free (option->o.string);
@@ -1804,7 +1807,6 @@ free_option (OPTION *option)
         free (option->o.icons);
         break;
 
-      case GOT_integer:
       default:
         break;
     }
@@ -1823,17 +1825,17 @@ initialize_option (OPTION *option, enum 
global_option_type type,
         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_char:
-      case GOT_bytes:
-        option->o.string = 0;
-        break;
-
       case GOT_buttons:
         option->o.buttons = 0;
         break;
@@ -1987,7 +1989,6 @@ 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);
diff --git a/tp/maintain/regenerate_C_options_info.pl 
b/tp/maintain/regenerate_C_options_info.pl
index aef48e94fd..ab09462432 100755
--- a/tp/maintain/regenerate_C_options_info.pl
+++ b/tp/maintain/regenerate_C_options_info.pl
@@ -449,8 +449,9 @@ print GET '#include "utils.h"'."\n";
 print GET '#include "get_perl_info.h"'."\n";
 print GET '#include "build_perl_info.h"'."\n\n";
 
+# unused
 print GET 'int
-get_sv_option (OPTIONS *options, const char *key, SV *value, int force, const 
CONVERTER *converter)
+get_options_key_sv_option (OPTIONS *options, const char *key, SV *value, int 
force, const CONVERTER *converter)
 {
   dTHX;
 



reply via email to

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