[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[no subject]
From: |
Patrice Dumas |
Date: |
Fri, 4 Oct 2024 05:59:37 -0400 (EDT) |
branch: master
commit b6c82b00b06692903e79bd806e5504a61d70221a
Author: Patrice Dumas <pertusus@free.fr>
AuthorDate: Sat Aug 10 20:38:20 2024 +0200
* tp/Texinfo/XS/main/utils.c (add_new_option_value): function to add
an option with values based on a list, without trying to find the
index in sorted options, for cases where options are found with their
names, in practice for parser options.
* tp/Texinfo/XS/convert/texinfo.c (txi_parser): pass an OPTIONS_LIST
and set parser options based on that list contents.
* tp/Texinfo/XS/teximakehtml.c (add_new_option_strlist_value)
(parser_EXPANDED_FORMATS, main): set parser options.
---
ChangeLog | 25 +++++++
tp/Texinfo/XS/convert/texinfo.c | 149 ++++++++++++++++++++++++++++++++++------
tp/Texinfo/XS/convert/texinfo.h | 3 +-
tp/Texinfo/XS/main/utils.c | 18 +++++
tp/Texinfo/XS/main/utils.h | 3 +
tp/Texinfo/XS/teximakehtml.c | 30 +++++++-
6 files changed, 206 insertions(+), 22 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index d14a325344..4082272827 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,16 @@
+2024-08-10 Patrice Dumas <pertusus@free.fr>
+
+ * tp/Texinfo/XS/main/utils.c (add_new_option_value): function to add
+ an option with values based on a list, without trying to find the
+ index in sorted options, for cases where options are found with their
+ names, in practice for parser options.
+
+ * tp/Texinfo/XS/convert/texinfo.c (txi_parser): pass an OPTIONS_LIST
+ and set parser options based on that list contents.
+
+ * tp/Texinfo/XS/teximakehtml.c (add_new_option_strlist_value)
+ (parser_EXPANDED_FORMATS, main): set parser options.
+
2024-08-10 Patrice Dumas <pertusus@free.fr>
* tp/Texinfo/XS/convert/texinfo.c (txi_parser),
@@ -57,6 +70,18 @@
tp/Texinfo/XS/convert/html_converter_init_options.h: move enum
BUTTON_special_unit_directions to create_buttons.h.
+2024-08-10 Patrice Dumas <pertusus@free.fr>
+
+ * tp/Texinfo/XS/convert/texinfo.c (txi_converter),
+ tp/Texinfo/XS/teximakehtml.c (main): create converter before
+ txi_converter such that it may be used to get sorted options.
+
+ * tp/Texinfo/XS/main/utils.c (options_list_add_option): rename
+ list_add_option as options_list_add_option.
+
+ * tp/Texinfo/XS/teximakehtml.c (main, add_button_option): demonstrate
+ passing button and other options to txi_converter.
+
2024-08-10 Patrice Dumas <pertusus@free.fr>
* tp/Texinfo/XS/convert/create_buttons.c (new_button_specification)
diff --git a/tp/Texinfo/XS/convert/texinfo.c b/tp/Texinfo/XS/convert/texinfo.c
index 90bac92f1d..85d43fd5dc 100644
--- a/tp/Texinfo/XS/convert/texinfo.c
+++ b/tp/Texinfo/XS/convert/texinfo.c
@@ -4,7 +4,7 @@
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
-
+
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
@@ -23,7 +23,7 @@
#include "document_types.h"
#include "api.h"
#include "conf.h"
-/* parse_file_path */
+/* parse_file_path */
#include "utils.h"
#include "document.h"
#include "translations.h"
@@ -45,35 +45,37 @@ txi_setup (const char *localesdir, int texinfo_uninstalled,
html_format_setup ();
}
-/* TODO should pass other options, in particular prepended and appended
- directories, and maybe OPTIONS_LIST
- for other options known by the parser */
void
txi_parser (const char *file_path, const char *locale_encoding,
- const char **expanded_formats, const VALUE_LIST *values)
+ const char **expanded_formats, const VALUE_LIST *values,
+ OPTIONS_LIST *options)
{
char *input_file_name_and_directory[2];
char *input_directory;
int i;
+ int debug = 0;
+ int includes_set = 0;
- reset_parser (0);
-
- if (file_path)
+ /* special case, we need to know if debug is set before calling
+ reset_parser */
+ if (options)
{
- parse_file_path (file_path, input_file_name_and_directory);
- input_directory = input_file_name_and_directory[1];
- free (input_file_name_and_directory[0]);
-
-
- if (strcmp (file_path, "."))
+ for (i = 0; i < options->number; i++)
{
- parser_conf_clear_INCLUDE_DIRECTORIES ();
- parser_conf_add_include_directory (input_directory);
- parser_conf_add_include_directory (".");
+ OPTION *option = options->list[i];
+ if (!strcmp (option->name, "DEBUG"))
+ {
+ if (option->o.integer >= 0)
+ debug = 1;
+ break;
+ }
}
- free (input_directory);
}
+ reset_parser (debug);
+
+ parser_conf_set_DEBUG (debug);
+
if (values)
{
parser_conf_reset_values ();
@@ -84,9 +86,116 @@ txi_parser (const char *file_path, const char
*locale_encoding,
}
}
+ /* set from arguments. Options override */
parser_conf_set_LOCALE_ENCODING (locale_encoding);
for (i = 0; expanded_formats[i]; i++)
parser_conf_add_expanded_format (expanded_formats[i]);
+
+ if (options)
+ {
+ for (i = 0; i < options->number; i++)
+ {
+ OPTION *option = options->list[i];
+ if (!strcmp (option->name, "INCLUDE_DIRECTORIES"))
+ {
+ includes_set = 1;
+ parser_conf_clear_INCLUDE_DIRECTORIES ();
+ if (option->o.strlist)
+ {
+ size_t j;
+ STRING_LIST *directories = option->o.strlist;
+ for (j = 0; j < directories->number; j++)
+ if (directories->list[j])
+ parser_conf_add_include_directory (directories->list[j]);
+ }
+ }
+ else if (!strcmp (option->name, "EXPANDED_FORMATS"))
+ {
+ parser_conf_clear_expanded_formats ();
+ if (option->o.strlist)
+ {
+ size_t j;
+ STRING_LIST *expanded_formats = option->o.strlist;
+ for (j = 0; j < expanded_formats->number; j++)
+ if (expanded_formats->list[j])
+ parser_conf_add_expanded_format
+ (expanded_formats->list[j]);
+ }
+ }
+ else if (!strcmp (option->name, "documentlanguage"))
+ {
+ if (option->o.string)
+ parser_conf_set_documentlanguage (option->o.string);
+ }
+ else if (!strcmp (option->name, "FORMAT_MENU"))
+ {
+ if (option->o.string && !strcmp (option->o.string, "menu"))
+ parser_conf_set_show_menu (1);
+ else
+ parser_conf_set_show_menu (0);
+ }
+ else if (!strcmp (option->name,
+ "IGNORE_SPACE_AFTER_BRACED_COMMAND_NAME"))
+ parser_conf_set_IGNORE_SPACE_AFTER_BRACED_COMMAND_NAME
+ (option->o.integer);
+ else if (!strcmp (option->name, "CPP_LINE_DIRECTIVES"))
+ parser_conf_set_CPP_LINE_DIRECTIVES (option->o.integer);
+ else if (!strcmp (option->name, "MAX_MACRO_CALL_NESTING"))
+ parser_conf_set_MAX_MACRO_CALL_NESTING (option->o.integer);
+ else if (!strcmp (option->name, "NO_INDEX"))
+ parser_conf_set_NO_INDEX (option->o.integer);
+ else if (!strcmp (option->name, "NO_USER_COMMANDS"))
+ parser_conf_set_NO_USER_COMMANDS (option->o.integer);
+ else if (!strcmp (option->name, "DOC_ENCODING_FOR_INPUT_FILE_NAME"))
+ parser_conf_set_DOC_ENCODING_FOR_INPUT_FILE_NAME
+ (option->o.integer);
+ else if (!strcmp (option->name, "INPUT_FILE_NAME_ENCODING"))
+ {
+ if (option->o.string)
+ parser_conf_set_INPUT_FILE_NAME_ENCODING (option->o.string);
+ }
+ else if (!strcmp (option->name, "LOCALE_ENCODING"))
+ {
+ if (option->o.string)
+ parser_conf_set_LOCALE_ENCODING (option->o.string);
+ }
+ else if (!strcmp (option->name, "COMMAND_LINE_ENCODING"))
+ {
+ if (option->o.string)
+ parser_conf_set_COMMAND_LINE_ENCODING (option->o.string);
+ }
+ else if (!strcmp (option->name, "accept_internalvalue"))
+ {
+ /* called from gdt, no need to store the parser configuration */
+ if (option->o.integer > 0)
+ parser_conf_set_accept_internalvalue (1);
+ /* $store_conf = 0; */
+ }
+ else if (strcmp (option->name, "DEBUG"))
+ {
+ fprintf (stderr, "ignoring parser configuration value \"%s\"\n",
+ option->name);
+ }
+ }
+ }
+
+ if (!includes_set)
+ {
+ if (file_path)
+ {
+ parse_file_path (file_path, input_file_name_and_directory);
+ input_directory = input_file_name_and_directory[1];
+ free (input_file_name_and_directory[0]);
+
+ if (strcmp (file_path, "."))
+ {
+ parser_conf_clear_INCLUDE_DIRECTORIES ();
+ parser_conf_add_include_directory (input_directory);
+ parser_conf_add_include_directory (".");
+ }
+ free (input_directory);
+ }
+ }
}
/* call all the structuring/transformations typically done for a document.
@@ -233,7 +342,7 @@ txi_html_output (CONVERTER *converter, DOCUMENT *document)
/* prepare conversion to HTML */
converter_set_document (converter, document);
-
+
html_initialize_output_state (converter, "_output");
status = html_setup_output (converter, paths);
diff --git a/tp/Texinfo/XS/convert/texinfo.h b/tp/Texinfo/XS/convert/texinfo.h
index 1dc681d5cb..2f3d181d91 100644
--- a/tp/Texinfo/XS/convert/texinfo.h
+++ b/tp/Texinfo/XS/convert/texinfo.h
@@ -32,7 +32,8 @@ void txi_setup (const char *localesdir, int
texinfo_uninstalled,
void
txi_parser (const char *file_path, const char *locale_encoding,
- const char **expanded_formats, const VALUE_LIST *values);
+ const char **expanded_formats, const VALUE_LIST *values,
+ OPTIONS_LIST *options);
void txi_complete_document (DOCUMENT *document, unsigned long flags,
int format_menu);
diff --git a/tp/Texinfo/XS/main/utils.c b/tp/Texinfo/XS/main/utils.c
index 5899f65b88..bf7c848a09 100644
--- a/tp/Texinfo/XS/main/utils.c
+++ b/tp/Texinfo/XS/main/utils.c
@@ -2160,6 +2160,24 @@ add_option_copy (OPTIONS_LIST *options_list, OPTION
**sorted_options,
return option;
}
+/* similar with new_option_string_value but in cases where there is no
+ sorted_options, and options are found with their names, in practice
+ for parser options */
+OPTION *
+add_new_option_value (OPTIONS_LIST *options_list,
+ enum global_option_type type, const char *name,
+ int int_value, const char *char_value)
+{
+ OPTION *option = new_option (type, name, 0);
+
+ option_set_conf (option, int_value, char_value);
+
+ options_list_add_option (options_list, option);
+
+ return option;
+}
+
+
void
copy_options_list (OPTIONS_LIST *options_list,
const OPTIONS_LIST *options_src, OPTION **sorted_options)
diff --git a/tp/Texinfo/XS/main/utils.h b/tp/Texinfo/XS/main/utils.h
index 7ccc64963e..6a7d8e1221 100644
--- a/tp/Texinfo/XS/main/utils.h
+++ b/tp/Texinfo/XS/main/utils.h
@@ -291,6 +291,9 @@ OPTION *add_option_string_value (OPTIONS_LIST *options_list,
const char *option_name, int int_value,
const char *char_value);
void options_list_add_option (OPTIONS_LIST *options_list, OPTION *option);
+OPTION *add_new_option_value (OPTIONS_LIST *options_list,
+ enum global_option_type type, const char *name,
+ int int_value, const char *char_value);
void copy_options_list (OPTIONS_LIST *options_list,
const OPTIONS_LIST *options_src, OPTION **sorted_options);
diff --git a/tp/Texinfo/XS/teximakehtml.c b/tp/Texinfo/XS/teximakehtml.c
index 1752191f9d..7b6f0142e1 100644
--- a/tp/Texinfo/XS/teximakehtml.c
+++ b/tp/Texinfo/XS/teximakehtml.c
@@ -95,12 +95,30 @@ add_button_option (OPTIONS_LIST *options_list, OPTION
**sorted_options,
options_list_add_option (options_list, option);
}
+static OPTION *
+add_new_option_strlist_value (OPTIONS_LIST *options_list,
+ enum global_option_type type, const char *name,
+ STRING_LIST *strlist)
+{
+ OPTION *option = new_option (type, name, 0);
+
+ option->o.strlist = strlist;
+
+ options_list_add_option (options_list, option);
+
+ return option;
+}
+
static const char *expanded_formats[] = {"html", 0};
static VALUE values_array[] = {
{"txicommandconditionals", "1"}
};
static const VALUE_LIST values = {1, 1, values_array};
+static char *parser_EXPANDED_FORMATS_array[] = {"HTML", "tex"};
+static STRING_LIST parser_EXPANDED_FORMATS
+ = {parser_EXPANDED_FORMATS_array, 2, 2};
+
int
main (int argc, char *argv[])
{
@@ -115,6 +133,7 @@ main (int argc, char *argv[])
CONVERTER *converter;
char *result;
BUTTON_SPECIFICATION_LIST *custom_node_footer_buttons;
+ OPTIONS_LIST parser_options;
OPTIONS_LIST convert_options;
/*
@@ -152,8 +171,17 @@ main (int argc, char *argv[])
/* Texinfo file parsing */
input_file_path = argv[1];
+ initialize_options_list (&parser_options, 2);
+ /*
+ add_new_option_value (&parser_options, GOT_integer,
+ "DEBUG", 1, 0);
+ */
+ add_new_option_strlist_value (&parser_options, GOT_char_string_list,
+ "EXPANDED_FORMATS", &parser_EXPANDED_FORMATS);
+
/* initialize parser */
- txi_parser (input_file_path, locale_encoding, expanded_formats, &values);
+ txi_parser (input_file_path, locale_encoding, expanded_formats, &values,
+ &parser_options);
/* Texinfo document tree parsing */
document_descriptor = parse_file (input_file_path, &status);