[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
branch master updated: * tp/Texinfo/XS/main/utils.c (compare_option_str,
From: |
Patrice Dumas |
Subject: |
branch master updated: * tp/Texinfo/XS/main/utils.c (compare_option_str, initialize_option), tp/maintain/regenerate_C_options_info.pl: add option name in initialize_option and in generated initialize_options. |
Date: |
Wed, 02 Oct 2024 12:19:19 -0400 |
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 0e658d60c7 * tp/Texinfo/XS/main/utils.c (compare_option_str,
initialize_option), tp/maintain/regenerate_C_options_info.pl: add option name
in initialize_option and in generated initialize_options.
0e658d60c7 is described below
commit 0e658d60c733980d6bc162b79bc7c5dbf4174b84
Author: Patrice Dumas <pertusus@free.fr>
AuthorDate: Sat Aug 3 17:31:40 2024 +0200
* tp/Texinfo/XS/main/utils.c (compare_option_str, initialize_option),
tp/maintain/regenerate_C_options_info.pl: add option name in
initialize_option and in generated initialize_options.
* tp/maintain/regenerate_C_options_info.pl: generate TXI_OPTIONS_NR.
Generate setup_sortable_options that sets up an array of OPTIONS
OPTION fields.
* p/Texinfo/XS/convert/converter.c (init_generic_converter)
(free_generic_converter), tp/Texinfo/XS/main/converter_types.h
(CONVERTER), tp/Texinfo/XS/main/utils.c (setup_sorted_options),
tp/Texinfo/XS/main/option_types.h (OPTION): setup sorted_options field
in converter with the sorted options of conf.
* tp/Texinfo/XS/main/utils.c (find_option_string): add a function to
use bsearch to find an option by name in a sorted options array.
---
ChangeLog | 19 ++++++++++++++
tp/Texinfo/XS/convert/converter.c | 4 +++
tp/Texinfo/XS/main/converter_types.h | 2 ++
tp/Texinfo/XS/main/option_types.h | 3 +++
tp/Texinfo/XS/main/utils.c | 44 +++++++++++++++++++++++++++++++-
tp/Texinfo/XS/main/utils.h | 6 ++++-
tp/maintain/regenerate_C_options_info.pl | 25 +++++++++++++++++-
7 files changed, 100 insertions(+), 3 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index b8264246fe..0e8ad74f6f 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,22 @@
+2024-08-03 Patrice Dumas <pertusus@free.fr>
+
+ * tp/Texinfo/XS/main/utils.c (compare_option_str, initialize_option),
+ tp/maintain/regenerate_C_options_info.pl: add option name in
+ initialize_option and in generated initialize_options.
+
+ * tp/maintain/regenerate_C_options_info.pl: generate TXI_OPTIONS_NR.
+ Generate setup_sortable_options that sets up an array of OPTIONS
+ OPTION fields.
+
+ * p/Texinfo/XS/convert/converter.c (init_generic_converter)
+ (free_generic_converter), tp/Texinfo/XS/main/converter_types.h
+ (CONVERTER), tp/Texinfo/XS/main/utils.c (setup_sorted_options),
+ tp/Texinfo/XS/main/option_types.h (OPTION): setup sorted_options field
+ in converter with the sorted options of conf.
+
+ * tp/Texinfo/XS/main/utils.c (find_option_string): add a function to
+ use bsearch to find an option by name in a sorted options array.
+
2024-08-03 Patrice Dumas <pertusus@free.fr>
* tp/Texinfo/XS/convert/converter.c (enum conversion_output_format)
diff --git a/tp/Texinfo/XS/convert/converter.c
b/tp/Texinfo/XS/convert/converter.c
index 940f0e6e31..38aa5aa61c 100644
--- a/tp/Texinfo/XS/convert/converter.c
+++ b/tp/Texinfo/XS/convert/converter.c
@@ -190,6 +190,7 @@ static void
init_generic_converter (CONVERTER *self)
{
self->conf = new_options ();
+ self->sorted_options = setup_sorted_options (self->conf);
set_converter_cmdline_regular_defaults (self->conf);
set_converter_customization_regular_defaults (self->conf);
@@ -1537,6 +1538,9 @@ free_generic_converter (CONVERTER *self)
free_options (self->init_conf);
free (self->init_conf);
+ if (self->sorted_options)
+ free (self->sorted_options);
+
if (self->conf)
free_options (self->conf);
free (self->conf);
diff --git a/tp/Texinfo/XS/main/converter_types.h
b/tp/Texinfo/XS/main/converter_types.h
index 1df9ea1616..9263d2e8ee 100644
--- a/tp/Texinfo/XS/main/converter_types.h
+++ b/tp/Texinfo/XS/main/converter_types.h
@@ -749,6 +749,8 @@ typedef struct CONVERTER {
OPTIONS *conf;
OPTIONS *init_conf;
+ /* an array containing the fields of conf ordered by name */
+ OPTION **sorted_options;
char *output_format;
char *converted_format;
EXPANDED_FORMAT *expanded_formats;
diff --git a/tp/Texinfo/XS/main/option_types.h
b/tp/Texinfo/XS/main/option_types.h
index 3099938da0..c716c43002 100644
--- a/tp/Texinfo/XS/main/option_types.h
+++ b/tp/Texinfo/XS/main/option_types.h
@@ -157,6 +157,9 @@ typedef struct DIRECTION_ICON_LIST {
typedef struct OPTION {
enum global_option_type type;
const char *name;
+ /* index in sorted options array */
+ /* starts at 1 to use 0 for unset */
+ size_t number;
int configured;
union {
int integer;
diff --git a/tp/Texinfo/XS/main/utils.c b/tp/Texinfo/XS/main/utils.c
index 93a778b0e2..1fed3945a3 100644
--- a/tp/Texinfo/XS/main/utils.c
+++ b/tp/Texinfo/XS/main/utils.c
@@ -1702,6 +1702,45 @@ new_options (void)
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);
+ return *result;
+}
+
void
clear_option (OPTION *option)
{
@@ -1769,9 +1808,12 @@ free_option (OPTION *option)
}
void
-initialize_option (OPTION *option, enum global_option_type type)
+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:
diff --git a/tp/Texinfo/XS/main/utils.h b/tp/Texinfo/XS/main/utils.h
index a64e89f1aa..f54f73c10d 100644
--- a/tp/Texinfo/XS/main/utils.h
+++ b/tp/Texinfo/XS/main/utils.h
@@ -207,12 +207,15 @@ 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);
OPTIONS *new_options (void);
+OPTION **setup_sorted_options (OPTIONS *options);
+OPTION *find_option_string (OPTION **sorted_options, const char *name);
void set_output_encoding (OPTIONS *customization_information,
DOCUMENT *document);
OPTION *get_command_option (OPTIONS *options, enum command_id cmd);
@@ -264,7 +267,8 @@ 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);
+void initialize_option (OPTION *option, enum global_option_type type,
+ const char *name);
void clear_option (OPTION *option);
void free_option (OPTION *option);
void copy_option (OPTION *destination, const OPTION *source);
diff --git a/tp/maintain/regenerate_C_options_info.pl
b/tp/maintain/regenerate_C_options_info.pl
index db04cb74c0..563913a4d7 100755
--- a/tp/maintain/regenerate_C_options_info.pl
+++ b/tp/maintain/regenerate_C_options_info.pl
@@ -30,6 +30,8 @@ my %commands_options;
my %options;
+my $options_nr = 0;
+
while (<STDIN>) {
if (not (/^#/ or /^ *$/)) {
if (/^([^ ]+) +([^ ]+) +([^ ]+) +(.+)$/) {
@@ -47,6 +49,7 @@ while (<STDIN>) {
$commands_options{$option} = [$category, $value, $type];
}
$options{$option} = [$category, $value, $type];
+ $options_nr++;
} else {
warn "ERROR: unexpected line: $_";
}
@@ -160,6 +163,8 @@ print HEADER "#undef PACKAGE_NAME\n";
print HEADER "#undef PACKAGE_URL\n";
print HEADER "#undef PACKAGE_VERSION\n\n";
+print HEADER "#define TXI_OPTIONS_NR $options_nr\n\n";
+
print HEADER "typedef struct OPTIONS {\n";
print HEADER " size_t BIT_user_function_number;\n";
@@ -185,6 +190,7 @@ print CODE '#include <config.h>'."\n\n";
print CODE '#include <stdlib.h>'."\n";
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";
@@ -196,11 +202,28 @@ foreach my $category (sort(keys(%option_categories))) {
print CODE "\n/* ${category} */\n\n";
foreach my $option_info (@{$option_categories{$category}}) {
my ($option, $value, $type) = @$option_info;
- print CODE " initialize_option (&options->$option, GOT_$type);\n";
+ print CODE " initialize_option (&options->$option, GOT_$type,
\"$option\");\n";
}
}
+
print CODE "}\n\n";
+print CODE "OPTION **\nsetup_sortable_options (OPTIONS *options)\n{\n";
+print CODE " OPTION **result = (OPTION **)\n"
+ ." malloc (sizeof (OPTION *) * TXI_OPTIONS_NR);\n\n";
+my $index = 0;
+foreach my $category (sort(keys(%option_categories))) {
+ print CODE "\n/* ${category} */\n\n";
+ foreach my $option_info (@{$option_categories{$category}}) {
+ my ($option, $value, $type) = @$option_info;
+ print CODE " result[$index] = &options->$option;\n";
+ $index++;
+ }
+}
+
+print CODE "\n return result;\n"
+."}\n\n";
+
print CODE "void\nfree_options (OPTIONS *options)\n{\n";
foreach my $category (sort(keys(%option_categories))) {
print CODE "\n/* ${category} */\n\n";
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- branch master updated: * tp/Texinfo/XS/main/utils.c (compare_option_str, initialize_option), tp/maintain/regenerate_C_options_info.pl: add option name in initialize_option and in generated initialize_options.,
Patrice Dumas <=