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 19:44:02 -0400 (EDT)

branch: master
commit f5188a163c9c9054c9fcdf31e4c8f05e6b0d8463
Author: Patrice Dumas <pertusus@free.fr>
AuthorDate: Sat Aug 17 14:50:05 2024 +0200

    * tp/maintain/regenerate_C_options_info.pl: setup
    txi_base_sorted_options sorted options information, to be able to find
    type and number of options, even without a converter.
    
    * tp/Texinfo/XS/convert/ConvertXS.xs (converter_defaults): use
    txi_base_sorted_options.
---
 ChangeLog                                |  9 +++++++++
 tp/Texinfo/XS/convert/ConvertXS.xs       | 16 +++++-----------
 tp/maintain/regenerate_C_options_info.pl | 26 ++++++++++++++++++++++++++
 3 files changed, 40 insertions(+), 11 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 2406f46f4e..24c8c15357 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2024-08-17  Patrice Dumas  <pertusus@free.fr>
+
+       * tp/maintain/regenerate_C_options_info.pl: setup
+       txi_base_sorted_options sorted options information, to be able to find
+       type and number of options, even without a converter.
+
+       * tp/Texinfo/XS/convert/ConvertXS.xs (converter_defaults): use
+       txi_base_sorted_options.
+
 2024-08-17  Patrice Dumas  <pertusus@free.fr>
 
        * tp/Texinfo/XS/convert/ConvertXS.xs (generic_converter_init),
diff --git a/tp/Texinfo/XS/convert/ConvertXS.xs 
b/tp/Texinfo/XS/convert/ConvertXS.xs
index 4d8e64f578..d2f23410b3 100644
--- a/tp/Texinfo/XS/convert/ConvertXS.xs
+++ b/tp/Texinfo/XS/convert/ConvertXS.xs
@@ -37,6 +37,8 @@
 #include "command_ids.h"
 #include "element_types.h"
 #include "tree_types.h"
+#include "option_types.h"
+#include "options_types.h"
 #include "converter_types.h"
 #include "builtin_commands.h"
 #include "errors.h"
@@ -113,15 +115,9 @@ converter_defaults (SV *converter_in, SV *conf_sv)
         CONVERTER_INITIALIZATION_INFO *conf;
         CONVERTER_INITIALIZATION_INFO *format_defaults;
         CONVERTER *self = 0;
-        /* we need sorted options to be able to find the type of options
-           in functions called from get_converter_info_from_sv*/
-        OPTIONS *options;
-        OPTION **sorted_options;
         const char *class_name;
         enum converter_format converter_format;
       CODE:
-        options = new_options ();
-        sorted_options = setup_sorted_options (options);
 
         if (SvOK (converter_in))
           {
@@ -138,12 +134,10 @@ converter_defaults (SV *converter_in, SV *conf_sv)
         converter_format
           = find_perl_converter_class_converter_format (class_name);
 
+        /* use txi_base_sorted_options static data to find the type of
+           options by name */
         conf = get_converter_info_from_sv (conf_sv, class_name, 0,
-                                           sorted_options);
-
-        free (sorted_options);
-        free_options (options);
-        free (options);
+                                           txi_base_sorted_options);
 
         format_defaults = converter_defaults (converter_format, conf);
 
diff --git a/tp/maintain/regenerate_C_options_info.pl 
b/tp/maintain/regenerate_C_options_info.pl
index 6d255d7a96..a65231dfd7 100755
--- a/tp/maintain/regenerate_C_options_info.pl
+++ b/tp/maintain/regenerate_C_options_info.pl
@@ -165,6 +165,9 @@ print HEADER "#undef PACKAGE_VERSION\n\n";
 
 print HEADER "#define TXI_OPTIONS_NR $options_nr\n\n";
 
+my $base_sorted_options_name = 'txi_base_sorted_options';
+print HEADER "extern OPTION 
*${base_sorted_options_name}\[TXI_OPTIONS_NR\];\n\n";
+
 print HEADER "typedef struct OPTIONS {\n";
 print HEADER "    size_t BIT_user_function_number;\n";
 
@@ -370,6 +373,29 @@ foreach my $command_name (@commands_order) {
 
 print CODE "};\n\n";
 
+# Sorted options by name.  Can be used to find the number and type.
+# First define the internal OPTION structures, in a second step set the
+# array.  Could not find a way to do it in one step.
+my $option_nr = 0;
+foreach my $option (sort(keys(%options))) {
+  $option_nr++;
+  my $option_info = $options{$option};
+  my ($category, $main_default, $type) = @$option_info;
+  print CODE "static OPTION _sorted_options_${option}_tmp = {GOT_${type}, 
\"$option\", $option_nr, 0, -1};  /* $category */\n";
+}
+
+print CODE "\n\n";
+
+print CODE "OPTION *${base_sorted_options_name}\[TXI_OPTIONS_NR\] = {\n";
+foreach my $option (sort(keys(%options))) {
+  $option_nr++;
+  my $option_info = $options{$option};
+  my ($category, $main_default, $type) = @$option_info;
+  #print CODE "{GOT_${type}, \"$option\", $option_nr, 0, -1},  /* $category 
*/\n";
+  print CODE "&_sorted_options_${option}_tmp,\n";
+}
+print CODE "};\n\n";
+
 close(CODE);
 
 open(OCDEF, ">$converter_defaults_code_file")



reply via email to

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