[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[no subject]
From: |
Patrice Dumas |
Date: |
Fri, 2 Feb 2024 16:40:41 -0500 (EST) |
branch: master
commit 1e0da02e45bb42ce1e945cd106d12d14645e3a6a
Author: Patrice Dumas <pertusus@free.fr>
AuthorDate: Fri Feb 2 22:30:38 2024 +0100
* tp/Texinfo/XS/main/document.c
(unregister_document_merge_with_document),
tp/Texinfo/XS/main/translations.c (gdt_tree): add based on gdt_tree
code.
* tp/Texinfo/XS/convert/convert_html.c (html_gdt, html_gdt_tree)
(html_cdt_tree): redo functions based on new codes.
---
ChangeLog | 10 ++++++
tp/Texinfo/XS/convert/convert_html.c | 67 +++++++++++++++---------------------
tp/Texinfo/XS/main/document.c | 30 ++++++++++++++++
tp/Texinfo/XS/main/document.h | 2 ++
tp/Texinfo/XS/main/translations.c | 30 ++++------------
5 files changed, 76 insertions(+), 63 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index e2d7d9f6cb..1b81be0f70 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2024-02-02 Patrice Dumas <pertusus@free.fr>
+
+ * tp/Texinfo/XS/main/document.c
+ (unregister_document_merge_with_document),
+ tp/Texinfo/XS/main/translations.c (gdt_tree): add based on gdt_tree
+ code.
+
+ * tp/Texinfo/XS/convert/convert_html.c (html_gdt, html_gdt_tree)
+ (html_cdt_tree): redo functions based on new codes.
+
2024-02-02 Patrice Dumas <pertusus@free.fr>
* tp/Texinfo/XS/main/translations.c (replace_convert_substrings):
diff --git a/tp/Texinfo/XS/convert/convert_html.c
b/tp/Texinfo/XS/convert/convert_html.c
index cf5863386a..c8a1b612dc 100644
--- a/tp/Texinfo/XS/convert/convert_html.c
+++ b/tp/Texinfo/XS/convert/convert_html.c
@@ -591,66 +591,55 @@ html_translate_string (CONVERTER *self, const char
*string,
}
/* returns a document descriptor. */
+/* same as gdt with html_translate_string called instead of translate_string */
int
-html_cdt (const char *string, CONVERTER *self, const char *lang,
+html_gdt (const char *string, CONVERTER *self, const char *lang,
NAMED_STRING_ELEMENT_LIST *replaced_substrings,
const char *translation_context)
{
+ OPTIONS *options = self->conf;
int debug_level = 0;
- char *translated_string;
int document_descriptor;
- translated_string = html_translate_string (self, string, lang,
- translation_context);
+ char *translated_string = html_translate_string (self, string, lang,
+ translation_context);
- if (self->conf && self->conf->DEBUG.integer >= 0)
- debug_level = self->conf->DEBUG.integer;
+ if (options && options->DEBUG.integer >= 0)
+ debug_level = options->DEBUG.integer;
- document_descriptor
- = replace_convert_substrings (translated_string,
+ document_descriptor = replace_convert_substrings (translated_string,
replaced_substrings, debug_level);
free (translated_string);
return document_descriptor;
}
-/* a copy and paste of cdt_tree with html_cdt instead of cdt */
+/* same as gdt_tree with html_gdt called instead of gdt */
ELEMENT *
-html_cdt_tree (const char *string, CONVERTER *self,
- NAMED_STRING_ELEMENT_LIST *replaced_substrings,
+html_gdt_tree (const char *string, CONVERTER *self,
+ const char *lang, NAMED_STRING_ELEMENT_LIST
*replaced_substrings,
const char *translation_context)
{
- ELEMENT *tree;
- int cdt_document_descriptor;
- const char *lang = 0;
-
- if (self->conf->documentlanguage.string)
- lang = self->conf->documentlanguage.string;
+ DOCUMENT *document = self->document;
- cdt_document_descriptor = html_cdt (string, self, lang, replaced_substrings,
- translation_context);
- TREE_AND_STRINGS *tree_and_strings
- = unregister_document_descriptor_tree (cdt_document_descriptor);
+ int gdt_document_descriptor = html_gdt (string, self, lang,
+ replaced_substrings, translation_context);
- tree = tree_and_strings->tree;
+ ELEMENT *tree
+ = unregister_document_merge_with_document (gdt_document_descriptor,
+ document);
+ return tree;
+}
- if (tree_and_strings->small_strings)
- {
- /* this is very unlikely, as small strings correspond to file names and
- macro names, while we are parsing a simple string */
- if (tree_and_strings->small_strings->number)
- {
- if (self->document)
- merge_strings (self->document->small_strings,
- tree_and_strings->small_strings);
- else
- fatal ("html_cdt_tree no document but small_strings");
- }
- free (tree_and_strings->small_strings->list);
- free (tree_and_strings->small_strings);
- }
- free (tree_and_strings);
+/* same as cdt_tree with html_gdt_tree called instead of gdt_tree */
+ELEMENT *
+html_cdt_tree (const char *string, CONVERTER *self,
+ NAMED_STRING_ELEMENT_LIST *replaced_substrings,
+ const char *translation_context)
+{
+ const char *lang = self->conf->documentlanguage.string;
- return tree;
+ return html_gdt_tree (string, self, lang,
+ replaced_substrings, translation_context);
}
char *
diff --git a/tp/Texinfo/XS/main/document.c b/tp/Texinfo/XS/main/document.c
index 0c1f71ecc9..75ea68080d 100644
--- a/tp/Texinfo/XS/main/document.c
+++ b/tp/Texinfo/XS/main/document.c
@@ -245,6 +245,36 @@ unregister_document_descriptor_tree (int
document_descriptor)
return tree_and_strings;
}
+/* destroy everything except for the tree and merge small string to
+ DOCUMENT */
+ELEMENT *
+unregister_document_merge_with_document (int document_descriptor,
+ DOCUMENT *document)
+{
+ TREE_AND_STRINGS *tree_and_strings
+ = unregister_document_descriptor_tree (document_descriptor);
+
+ ELEMENT *tree = tree_and_strings->tree;
+
+ if (tree_and_strings->small_strings)
+ {
+ if (tree_and_strings->small_strings->number)
+ {
+ if (document)
+ merge_strings (document->small_strings,
+ tree_and_strings->small_strings);
+ else
+ fatal ("unregister_document_merge_with_document "
+ "no document but small_strings");
+ }
+ free (tree_and_strings->small_strings->list);
+ free (tree_and_strings->small_strings);
+ }
+ free (tree_and_strings);
+
+ return tree;
+}
+
void
clear_document_errors (int document_descriptor)
{
diff --git a/tp/Texinfo/XS/main/document.h b/tp/Texinfo/XS/main/document.h
index 398345b0e0..cfd685db21 100644
--- a/tp/Texinfo/XS/main/document.h
+++ b/tp/Texinfo/XS/main/document.h
@@ -39,6 +39,8 @@ const MERGED_INDICES *document_merged_indices (DOCUMENT
*document);
void remove_document_descriptor (int document_descriptor);
TREE_AND_STRINGS *unregister_document_descriptor_tree (int
document_descriptor);
+ELEMENT *unregister_document_merge_with_document (int document_descriptor,
+ DOCUMENT *document);
void clear_document_errors (int document_descriptor);
#endif
diff --git a/tp/Texinfo/XS/main/translations.c
b/tp/Texinfo/XS/main/translations.c
index 4640fe654c..644fcb4175 100644
--- a/tp/Texinfo/XS/main/translations.c
+++ b/tp/Texinfo/XS/main/translations.c
@@ -531,14 +531,15 @@ gdt (const char *string, OPTIONS *options, const char
*lang,
const char *translation_context)
{
int debug_level = 0;
+ int document_descriptor;
+
char *translated_string = translate_string (string, lang,
translation_context);
if (options && options->DEBUG.integer >= 0)
debug_level = options->DEBUG.integer;
- int document_descriptor
- = replace_convert_substrings (translated_string,
+ document_descriptor = replace_convert_substrings (translated_string,
replaced_substrings, debug_level);
free (translated_string);
return document_descriptor;
@@ -553,30 +554,11 @@ gdt_tree (const char *string, DOCUMENT *document, OPTIONS
*options,
const char *lang, NAMED_STRING_ELEMENT_LIST *replaced_substrings,
const char *translation_context)
{
- ELEMENT *tree;
int gdt_document_descriptor = gdt (string, options, lang,
replaced_substrings, translation_context);
- TREE_AND_STRINGS *tree_and_strings
- = unregister_document_descriptor_tree (gdt_document_descriptor);
-
- tree = tree_and_strings->tree;
-
- if (tree_and_strings->small_strings)
- {
- /* this is very unlikely, as small strings correspond to file names and
- macro names, while we are parsing a simple string */
- if (tree_and_strings->small_strings->number)
- {
- if (document)
- merge_strings (document->small_strings,
- tree_and_strings->small_strings);
- else
- fatal ("gdt_tree no document but small_strings");
- }
- free (tree_and_strings->small_strings->list);
- free (tree_and_strings->small_strings);
- }
- free (tree_and_strings);
+ ELEMENT *tree
+ = unregister_document_merge_with_document (gdt_document_descriptor,
+ document);
return tree;
}