[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[no subject]
From: |
Patrice Dumas |
Date: |
Sat, 18 Nov 2023 03:10:58 -0500 (EST) |
branch: master
commit bbe793d935a64f1b148e8e5e8fa08c80dc5b0c45
Author: Patrice Dumas <pertusus@free.fr>
AuthorDate: Fri Nov 17 20:05:56 2023 +0100
* tp/Texinfo/XS/main/element_types.awk,
tp/Texinfo/XS/main/converter_types.h (CONVERTER): output code defining
TXI_TREE_TYPES_NUMBER to the number of tree element types. Update
codes that used the last type instead.
* tp/Texinfo/XS/convert/get_html_perl_info.c
(html_converter_initialize_sv), tp/Texinfo/XS/main/builtin_commands.c
(TYPE_INDEX, type_name_index, compare_type_index_fn)
(set_element_type_name_info, find_element_type),
tp/Texinfo/XS/convert/ConvertXS.xs (init): prepare a list of element
types names and type number in set_element_type_name_info and sort.
Called from init in ConvertXS.xs. Add find_element_type to find the
type of a type name and use it in html_converter_initialize_sv.
---
ChangeLog | 16 +++++++++
tp/Texinfo/XS/convert/ConvertXS.xs | 15 ++++++++-
tp/Texinfo/XS/convert/convert_html.c | 6 ++--
tp/Texinfo/XS/convert/get_html_perl_info.c | 23 ++++---------
tp/Texinfo/XS/main/builtin_commands.c | 53 ++++++++++++++++++++++++++++++
tp/Texinfo/XS/main/builtin_commands.h | 4 +++
tp/Texinfo/XS/main/converter_types.h | 14 ++++----
tp/Texinfo/XS/main/element_types.awk | 6 ++++
tp/Texinfo/XS/main/element_types.h | 2 ++
tp/Texinfo/XS/main/element_types.txt | 3 --
10 files changed, 111 insertions(+), 31 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index ea678446d0..5abddfcb2f 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -15,6 +15,22 @@
for varying numbers of times tdestroy_recurse appears in the stack
trace.
+2023-11-17 Patrice Dumas <pertusus@free.fr>
+
+ * tp/Texinfo/XS/main/element_types.awk,
+ tp/Texinfo/XS/main/converter_types.h (CONVERTER): output code defining
+ TXI_TREE_TYPES_NUMBER to the number of tree element types. Update
+ codes that used the last type instead.
+
+ * tp/Texinfo/XS/convert/get_html_perl_info.c
+ (html_converter_initialize_sv), tp/Texinfo/XS/main/builtin_commands.c
+ (TYPE_INDEX, type_name_index, compare_type_index_fn)
+ (set_element_type_name_info, find_element_type),
+ tp/Texinfo/XS/convert/ConvertXS.xs (init): prepare a list of element
+ types names and type number in set_element_type_name_info and sort.
+ Called from init in ConvertXS.xs. Add find_element_type to find the
+ type of a type name and use it in html_converter_initialize_sv.
+
2023-11-17 Patrice Dumas <pertusus@free.fr>
* tp/Texinfo/XS/main/command_stack.c (top_integer_stack): use correct
diff --git a/tp/Texinfo/XS/convert/ConvertXS.xs
b/tp/Texinfo/XS/convert/ConvertXS.xs
index d7e2e41f06..87ae6e88ad 100644
--- a/tp/Texinfo/XS/convert/ConvertXS.xs
+++ b/tp/Texinfo/XS/convert/ConvertXS.xs
@@ -51,7 +51,20 @@ MODULE = Texinfo::Convert::ConvertXS PACKAGE =
Texinfo::Convert::ConvertXS
# they are enabled, and they can/may need to be overriden in a declaration
PROTOTYPES: ENABLE
-void set_conf(SV *converter_in, conf, SV *value)
+# Called from Texinfo::XSLoader.pm. The arguments are not actually used.
+# file path, can be in any encoding
+# int texinfo_uninstalled
+# char *builddir = (char *)SvPVbyte_nolen($arg);
+int
+init (...)
+ CODE:
+ set_element_type_name_info ();
+ RETVAL = 1;
+ OUTPUT:
+ RETVAL
+
+void
+set_conf(SV *converter_in, conf, SV *value)
char *conf = (char *)SvPVbyte_nolen($arg);
PREINIT:
CONVERTER *self;
diff --git a/tp/Texinfo/XS/convert/convert_html.c
b/tp/Texinfo/XS/convert/convert_html.c
index 98c8fe654f..a8012f0459 100644
--- a/tp/Texinfo/XS/convert/convert_html.c
+++ b/tp/Texinfo/XS/convert/convert_html.c
@@ -2970,7 +2970,7 @@ html_converter_initialize (CONVERTER *self)
self->command_special_variety_name_index[i].index = number - 1;
}
- for (i = 0; i < ET_special_unit_element+1; i++)
+ for (i = 0; i < TXI_TREE_TYPES_NUMBER; i++)
{
self->type_conversion_function[i]
= register_type_conversion_function(i, &self->types_conversion[i]);
@@ -3156,7 +3156,7 @@ html_destroy (CONVERTER *self)
free (self->special_unit_info_tree[i]);
}
- for (i = 1; i < ET_special_unit_element+1; i++)
+ for (i = 1; i < TXI_TREE_TYPES_NUMBER; i++)
{
free (self->pre_class_types[i]);
}
@@ -3178,7 +3178,7 @@ html_destroy (CONVERTER *self)
}
}
- for (i = 0; i < ET_special_unit_element+1; i++)
+ for (i = 0; i < TXI_TREE_TYPES_NUMBER; i++)
{
free (self->type_conversion_function[i]);
free (self->css_string_type_conversion_function[i]);
diff --git a/tp/Texinfo/XS/convert/get_html_perl_info.c
b/tp/Texinfo/XS/convert/get_html_perl_info.c
index c8e75f48aa..8c9aaa3d72 100644
--- a/tp/Texinfo/XS/convert/get_html_perl_info.c
+++ b/tp/Texinfo/XS/convert/get_html_perl_info.c
@@ -299,7 +299,7 @@ html_converter_initialize_sv (SV *converter_sv,
types_conversion_hv = (HV *)SvRV (*types_conversion_sv);
default_types_conversion_hv = (HV *)SvRV (default_types_conversion);
- for (i = 0; i < ET_special_unit_element+1; i++)
+ for (i = 0; i < TXI_TREE_TYPES_NUMBER; i++)
{
char *ref_name;
if (i == 0)
@@ -326,8 +326,8 @@ html_converter_initialize_sv (SV *converter_sv,
specific references */
memcpy (&converter->css_string_types_conversion,
&converter->types_conversion,
- (ET_special_unit_element+1) * sizeof (FORMATTING_REFERENCE));
- for (i = 0; i < ET_special_unit_element+1; i++)
+ (TXI_TREE_TYPES_NUMBER) * sizeof (FORMATTING_REFERENCE));
+ for (i = 0; i < TXI_TREE_TYPES_NUMBER; i++)
{
char *ref_name;
if (i == 0)
@@ -452,7 +452,7 @@ html_converter_initialize_sv (SV *converter_sv,
in the default case. If this is needed more, a qsort/bfind
could be used, but the overhead could probably only be
justified if finding the type index happens more often */
- for (j = 1; j < ET_special_unit_element+1; j++)
+ for (j = 1; j < TXI_TREE_TYPES_NUMBER; j++)
{
if (!strcmp (element_type_names[j], type_name))
{
@@ -491,20 +491,9 @@ html_converter_initialize_sv (SV *converter_sv,
&type_name, &retlen);
if (SvOK (pre_class_sv))
{
- enum element_type type = ET_NONE;
char *pre_class = SvPV_nolen (pre_class_sv);
- /* this is not very efficient, but should be done only once
- in the default case. If this is needed more, a qsort/bfind
- could be used, but the overhead could probably only be
- justified if finding the type index happens more often */
- for (j = 1; j < ET_special_unit_element+1; j++)
- {
- if (!strcmp (element_type_names[j], type_name))
- {
- type = j;
- break;
- }
- }
+ enum element_type type = find_element_type (type_name);
+
if (type == ET_NONE)
{
fprintf (stderr, "ERROR: %s: pre class type not found\n",
diff --git a/tp/Texinfo/XS/main/builtin_commands.c
b/tp/Texinfo/XS/main/builtin_commands.c
index adb75442e4..e71b4342c3 100644
--- a/tp/Texinfo/XS/main/builtin_commands.c
+++ b/tp/Texinfo/XS/main/builtin_commands.c
@@ -20,6 +20,7 @@
#include <stdio.h>
#include "command_ids.h"
+#include "element_types.h"
#include "tree_types.h"
#include "extra.h"
#include "debug.h"
@@ -119,3 +120,55 @@ element_builtin_data_cmd (const ELEMENT *e)
return element_builtin_cmd (e);
}
+typedef struct TYPE_INDEX {
+ enum element_type type;
+ char *name;
+} TYPE_INDEX;
+
+/* -1 because ET_NONE == 0 has no name */
+static TYPE_INDEX type_name_index[TXI_TREE_TYPES_NUMBER -1];
+
+static int
+compare_type_index_fn (const void *a, const void *b)
+{
+ const TYPE_INDEX *ta = (TYPE_INDEX *) a;
+ const TYPE_INDEX *tb = (TYPE_INDEX *) b;
+
+ return strcmp (ta->name, tb->name);
+}
+
+void
+set_element_type_name_info ()
+{
+ int i;
+ for (i = 1; i < TXI_TREE_TYPES_NUMBER; i++)
+ {
+ type_name_index[i-1].name = element_type_names[i];
+ type_name_index[i-1].type = i;
+ }
+
+ qsort (type_name_index, TXI_TREE_TYPES_NUMBER -1, sizeof(TYPE_INDEX),
+ compare_type_index_fn);
+
+ /*
+ for (i = 0; i < TXI_TREE_TYPES_NUMBER -1; i++)
+ {
+ fprintf (stderr, "TT %s %d\n", type_name_index[i].name,
type_name_index[i].type);
+ }
+ */
+}
+
+enum element_type
+find_element_type (char *type_name)
+{
+ TYPE_INDEX *result;
+ static TYPE_INDEX searched_type;
+ searched_type.name = type_name;
+ result = (TYPE_INDEX *) bsearch (&searched_type, type_name_index,
+ TXI_TREE_TYPES_NUMBER -1, sizeof(TYPE_INDEX),
+ compare_type_index_fn);
+ if (result)
+ return result->type;
+ else
+ return 0;
+}
diff --git a/tp/Texinfo/XS/main/builtin_commands.h
b/tp/Texinfo/XS/main/builtin_commands.h
index f20d8f58a5..3f905b303f 100644
--- a/tp/Texinfo/XS/main/builtin_commands.h
+++ b/tp/Texinfo/XS/main/builtin_commands.h
@@ -162,4 +162,8 @@ enum command_id element_builtin_data_cmd (const ELEMENT *e);
#define INTERNAL_brace -1
#define INTERNAL_line -2
+/* following related to element types */
+void set_element_type_name_info ();
+enum element_type find_element_type (char *type_name);
+
#endif
diff --git a/tp/Texinfo/XS/main/converter_types.h
b/tp/Texinfo/XS/main/converter_types.h
index 875c66df5a..2dde4cddbf 100644
--- a/tp/Texinfo/XS/main/converter_types.h
+++ b/tp/Texinfo/XS/main/converter_types.h
@@ -391,8 +391,8 @@ typedef struct CONVERTER {
/* HTML specific */
/* set for a converter */
COMMAND_ID_LIST no_arg_formatted_cmd;
- int code_types[ET_special_unit_element+1];
- char *pre_class_types[ET_special_unit_element+1];
+ int code_types[TXI_TREE_TYPES_NUMBER];
+ char *pre_class_types[TXI_TREE_TYPES_NUMBER];
int upper_case[BUILTIN_CMD_NUMBER];
STRING_WITH_LEN special_character[SC_non_breaking_space+1];
STRING_WITH_LEN line_break_element;
@@ -403,9 +403,9 @@ typedef struct CONVERTER {
FORMATTING_REFERENCE commands_open[BUILTIN_CMD_NUMBER];
FORMATTING_REFERENCE commands_conversion[BUILTIN_CMD_NUMBER];
FORMATTING_REFERENCE css_string_commands_conversion[BUILTIN_CMD_NUMBER];
- FORMATTING_REFERENCE types_open[ET_special_unit_element+1];
- FORMATTING_REFERENCE types_conversion[ET_special_unit_element+1];
- FORMATTING_REFERENCE
css_string_types_conversion[ET_special_unit_element+1];
+ FORMATTING_REFERENCE types_open[TXI_TREE_TYPES_NUMBER];
+ FORMATTING_REFERENCE types_conversion[TXI_TREE_TYPES_NUMBER];
+ FORMATTING_REFERENCE css_string_types_conversion[TXI_TREE_TYPES_NUMBER];
FORMATTING_REFERENCE output_units_conversion[OU_special_unit+1];
STRING_LIST special_unit_varieties;
char **special_unit_info[SUI_type_heading+1];
@@ -414,8 +414,8 @@ typedef struct CONVERTER {
CONVERTER because it uses the CONVERTER in a function pointer
argument prototype, which does not seems to be possible with
incomplete types */
- struct TYPE_CONVERSION_FUNCTION
*type_conversion_function[ET_special_unit_element+1];
- struct TYPE_CONVERSION_FUNCTION
*css_string_type_conversion_function[ET_special_unit_element+1];
+ struct TYPE_CONVERSION_FUNCTION
*type_conversion_function[TXI_TREE_TYPES_NUMBER];
+ struct TYPE_CONVERSION_FUNCTION
*css_string_type_conversion_function[TXI_TREE_TYPES_NUMBER];
struct COMMAND_CONVERSION_FUNCTION
*command_conversion_function[BUILTIN_CMD_NUMBER];
struct COMMAND_CONVERSION_FUNCTION
*css_string_command_conversion_function[BUILTIN_CMD_NUMBER];
/* set for a converter, modified in a document */
diff --git a/tp/Texinfo/XS/main/element_types.awk
b/tp/Texinfo/XS/main/element_types.awk
index e744569cfe..d5780da137 100644
--- a/tp/Texinfo/XS/main/element_types.awk
+++ b/tp/Texinfo/XS/main/element_types.awk
@@ -31,14 +31,20 @@ BEGIN {
!/^$/ && !/^#/ {
print "ET_" $1 "," > ETH
array = array "\"" $1 "\",\n"
+
+ last_type = "ET_" $1
}
+
END {
print "};" > ETH
print > ETH
+ print "#define TXI_TREE_TYPES_NUMBER (" last_type " +1)" > ETH
+ print > ETH
print "extern char *element_type_names[];" > ETH
print "#endif" > ETH
+
print "char *element_type_names[] = {" > ETC
print "0," > ETC
print array > ETC
diff --git a/tp/Texinfo/XS/main/element_types.h
b/tp/Texinfo/XS/main/element_types.h
index dcb3e3a511..2dcfb0d682 100644
--- a/tp/Texinfo/XS/main/element_types.h
+++ b/tp/Texinfo/XS/main/element_types.h
@@ -81,5 +81,7 @@ ET__string,
ET_special_unit_element,
};
+#define TXI_TREE_TYPES_NUMBER (ET_special_unit_element +1)
+
extern char *element_type_names[];
#endif
diff --git a/tp/Texinfo/XS/main/element_types.txt
b/tp/Texinfo/XS/main/element_types.txt
index 327493d08a..66760cc2fe 100644
--- a/tp/Texinfo/XS/main/element_types.txt
+++ b/tp/Texinfo/XS/main/element_types.txt
@@ -113,8 +113,5 @@ _converted
_string
# not in parser, for virtual element associated to special output units
-# the corresponding type is often used in code to determine the number of
-# element types, so it would be a good idea to keep special_unit_element
-# last.
special_unit_element