[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
branch master updated: * tp/Texinfo/XS/main/customization_options.c (cop
From: |
Patrice Dumas |
Subject: |
branch master updated: * tp/Texinfo/XS/main/customization_options.c (copy_numbered_options_list_options): rename copy_options_list_options to copy_numbered_options_list_options. Update callers. |
Date: |
Fri, 04 Oct 2024 19:28:09 -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 461705a499 * tp/Texinfo/XS/main/customization_options.c
(copy_numbered_options_list_options): rename copy_options_list_options to
copy_numbered_options_list_options. Update callers.
461705a499 is described below
commit 461705a4993756f6bfd68f962d969d63c9f367bd
Author: Patrice Dumas <pertusus@free.fr>
AuthorDate: Fri Aug 16 14:26:46 2024 +0200
* tp/Texinfo/XS/main/customization_options.c
(copy_numbered_options_list_options): rename copy_options_list_options
to copy_numbered_options_list_options. Update callers.
* tp/Texinfo/XS/main/customization_options.c (add_option_copy)
(copy_options_list): remove sorted_options argument, it is not used.
* tp/Texinfo/XS/convert/ConvertXS.xs (generic_converter_init),
tp/Texinfo/XS/convert/get_converter_perl_info.c
(get_or_create_sv_converter): add get_or_create_sv_converter with code
mostly from generic_converter_init, to setup a new converter only if
there was not one already.
* tp/Texinfo/XS/convert/converter.c (set_converter_init_information):
do not call CONVERTER_FORMAT_DATA converter_defaults in
set_converter_init_information. It is better not to call it here as
it is not called in _generic_converter_init, it should better be done
in an overriden converter_defaults or a C only function.
* tp/Texinfo/XS/main/customization_options.c (number_options_list):
add to number options in list, typically if they were set without a
converter (without sorted options) and options with nembers are
expected.
* tp/Texinfo/XS/convert/converter.c (converter_format_data)
(copy_converter_initialization_info, converter_defaults)
(converter_initialize, converter_converter),
tp/Texinfo/XS/convert/html_converter_api.c
(html_converter_initialize),
tp/Texinfo/XS/convert/html_converter_init_options.c
(html_converter_defaults): add a converter_converter function to have
an interface similar to the Perl converter interface. Add
converter_initialize and converter_defaults to dispatch to format
specific functions. Get specific format defaults as
converter_defaults return. Set/update HTML functions for this change.
* tp/Texinfo/XS/convert/texinfo.c (txi_converter): call
converter_converter.
* tp/Texinfo/XS/convert/texinfo.c (txi_converter_setup): add based on
former txi_converter_initialize but updated to match the changes in
converter interface.
* tp/Texinfo/XS/teximakehtml.c (add_new_button_option, main): setup
customizations as a list without converter. Use txi_converter_setup.
* tp/Texinfo/XS/convert/ConvertXS.xs (html_converter_defaults):
prepare XS override for HTML converter_defaults, using
get_or_create_sv_converter and html_converter_defaults. Do not use
it, though, as it should work when called from a converter, but not
from a class.
---
ChangeLog | 68 +++++++++--
tp/Texinfo/Convert/HTML.pm | 3 +
tp/Texinfo/XS/convert/ConvertXS.xs | 79 +++++++------
tp/Texinfo/XS/convert/converter.c | 125 ++++++++++++++++-----
tp/Texinfo/XS/convert/converter.h | 6 +-
tp/Texinfo/XS/convert/get_converter_perl_info.c | 50 ++++++++-
tp/Texinfo/XS/convert/get_converter_perl_info.h | 6 +
tp/Texinfo/XS/convert/html_converter_api.c | 12 ++
tp/Texinfo/XS/convert/html_converter_api.h | 4 +-
.../XS/convert/html_converter_init_options.c | 14 ++-
.../XS/convert/html_converter_init_options.h | 2 +-
tp/Texinfo/XS/convert/texinfo.c | 89 +++++----------
tp/Texinfo/XS/convert/texinfo.h | 13 ++-
tp/Texinfo/XS/main/customization_options.c | 40 +++++--
tp/Texinfo/XS/main/customization_options.h | 6 +-
tp/Texinfo/XS/teximakehtml.c | 34 ++++--
16 files changed, 394 insertions(+), 157 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 19e6dbaba5..914eaf6912 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,12 +1,56 @@
-2024-10-04 Patrice Dumas <pertusus@free.fr>
+2024-08-16 Patrice Dumas <pertusus@free.fr>
- * tp/Texinfo/XS/convert/convert_html.c,
- tp/Texinfo/XS/convert/format_html.c (html_command_description): move
- html_command_description to format_html.c.
+ * tp/Texinfo/XS/main/customization_options.c
+ (copy_numbered_options_list_options): rename copy_options_list_options
+ to copy_numbered_options_list_options. Update callers.
- * tp/Texinfo/XS/convert/format_html.c (html_default_format_begin_file)
- (html_default_format_node_redirection_page)
- (html_default_format_special_body_about): fix function names.
+ * tp/Texinfo/XS/main/customization_options.c (add_option_copy)
+ (copy_options_list): remove sorted_options argument, it is not used.
+
+ * tp/Texinfo/XS/convert/ConvertXS.xs (generic_converter_init),
+ tp/Texinfo/XS/convert/get_converter_perl_info.c
+ (get_or_create_sv_converter): add get_or_create_sv_converter with code
+ mostly from generic_converter_init, to setup a new converter only if
+ there was not one already.
+
+ * tp/Texinfo/XS/convert/converter.c (set_converter_init_information):
+ do not call CONVERTER_FORMAT_DATA converter_defaults in
+ set_converter_init_information. It is better not to call it here as
+ it is not called in _generic_converter_init, it should better be done
+ in an overriden converter_defaults or a C only function.
+
+ * tp/Texinfo/XS/main/customization_options.c (number_options_list):
+ add to number options in list, typically if they were set without a
+ converter (without sorted options) and options with nembers are
+ expected.
+
+ * tp/Texinfo/XS/convert/converter.c (converter_format_data)
+ (copy_converter_initialization_info, converter_defaults)
+ (converter_initialize, converter_converter),
+ tp/Texinfo/XS/convert/html_converter_api.c
+ (html_converter_initialize),
+ tp/Texinfo/XS/convert/html_converter_init_options.c
+ (html_converter_defaults): add a converter_converter function to have
+ an interface similar to the Perl converter interface. Add
+ converter_initialize and converter_defaults to dispatch to format
+ specific functions. Get specific format defaults as
+ converter_defaults return. Set/update HTML functions for this change.
+
+ * tp/Texinfo/XS/convert/texinfo.c (txi_converter): call
+ converter_converter.
+
+ * tp/Texinfo/XS/convert/texinfo.c (txi_converter_setup): add based on
+ former txi_converter_initialize but updated to match the changes in
+ converter interface.
+
+ * tp/Texinfo/XS/teximakehtml.c (add_new_button_option, main): setup
+ customizations as a list without converter. Use txi_converter_setup.
+
+ * tp/Texinfo/XS/convert/ConvertXS.xs (html_converter_defaults):
+ prepare XS override for HTML converter_defaults, using
+ get_or_create_sv_converter and html_converter_defaults. Do not use
+ it, though, as it should work when called from a converter, but not
+ from a class.
2024-08-15 Patrice Dumas <pertusus@free.fr>
@@ -74,6 +118,16 @@
rename convert_tree_append as html_convert_tree_append. Update
callers.
+2024-10-04 Patrice Dumas <pertusus@free.fr>
+
+ * tp/Texinfo/XS/convert/convert_html.c,
+ tp/Texinfo/XS/convert/format_html.c (html_command_description): move
+ html_command_description to format_html.c.
+
+ * tp/Texinfo/XS/convert/format_html.c (html_default_format_begin_file)
+ (html_default_format_node_redirection_page)
+ (html_default_format_special_body_about): fix function names.
+
2024-08-15 Patrice Dumas <pertusus@free.fr>
* tp/Texinfo/XS/convert/html_converter_types.h: declare
diff --git a/tp/Texinfo/Convert/HTML.pm b/tp/Texinfo/Convert/HTML.pm
index 069b82d0ac..0920485906 100644
--- a/tp/Texinfo/Convert/HTML.pm
+++ b/tp/Texinfo/Convert/HTML.pm
@@ -103,6 +103,9 @@ my %XS_overrides = (
);
my %XS_conversion_overrides = (
+# not ready to be called as Texinfo::Convert::HTML->converter_defaults
+# "Texinfo::Convert::HTML::converter_defaults"
+# => "Texinfo::Convert::ConvertXS::html_converter_defaults",
"Texinfo::Convert::HTML::output"
=> "Texinfo::Convert::ConvertXS::html_output",
"Texinfo::Convert::HTML::convert"
diff --git a/tp/Texinfo/XS/convert/ConvertXS.xs
b/tp/Texinfo/XS/convert/ConvertXS.xs
index 2968b3e1fc..764727d073 100644
--- a/tp/Texinfo/XS/convert/ConvertXS.xs
+++ b/tp/Texinfo/XS/convert/ConvertXS.xs
@@ -95,34 +95,59 @@ init (int texinfo_uninstalled, SV *pkgdatadir_sv, SV
*tp_builddir_sv, SV *top_sr
OUTPUT:
RETVAL
+SV *
+html_converter_defaults (SV *converter_in, SV *conf_sv)
+ PREINIT:
+ HV *format_defaults_hv;
+ HV *converter_hv;
+ CONVERTER *self;
+ CONVERTER_INITIALIZATION_INFO *conf;
+ /* int has_conf; */
+ CODE:
+ /* FIXME if SvROK (converter_in) == 0, the Perl method should have
+ been called like Texinfo::Convert::HTML->converter_defaults
+ (from texi2any). In that case, the options should be returned
+ even though there is no converter */
+
+ self = get_or_create_sv_converter (converter_in, 0);
+
+ conf = new_converter_initialization_info ();
+ /* FIXME check where/if converted_format is set */
+ /* conf->converted_format = strdup ("html"); */
+
+ /*
+ has_conf =
+ */
+ get_converter_info_from_sv (conf_sv, 0, self,
+ self->sorted_options, conf);
+ html_converter_defaults (self, conf);
+
+ destroy_converter_initialization_info (conf);
+
+ converter_hv = (HV *)SvRV (converter_in);
+ hv_store (converter_hv, "converter_descriptor",
+ strlen ("converter_descriptor"),
+ newSViv ((IV)self->converter_descriptor), 0);
+
+ /* return empty options, such that when run through
+ generic_converter_init -> set_converter_init_information nothing
+ more is set, as the defaults have already been set by
+ html_converter_defaults */
+ format_defaults_hv = newHV ();
+ RETVAL = newRV_noinc ((SV *) format_defaults_hv);
+ OUTPUT:
+ RETVAL
+
# NOTE not sure what the scope of class is. When tested, valgrind did not
# complain.
void
generic_converter_init (SV *converter_in, const char *class, SV
*format_defaults_sv, SV *conf_sv=0)
PREINIT:
- size_t converter_descriptor;
CONVERTER *self;
CONVERTER_INITIALIZATION_INFO *format_defaults;
CONVERTER_INITIALIZATION_INFO *conf;
- enum converter_format converter_format = COF_none;
- int i;
CODE:
- /* determine the converter format, if handled in C */
- for (i =0; i < TXI_CONVERSION_FORMAT_NR; i++)
- {
- if (!strcmp (converter_format_data[i].perl_converter_class, class))
- {
- converter_format = i;
- break;
- }
- }
-
- converter_descriptor = new_converter (converter_format,
- CONVF_perl_hashmap);
- /*
- CONVF_string_list);
- */
- self = retrieve_converter (converter_descriptor);
+ self = get_or_create_sv_converter (converter_in, class);
format_defaults = new_converter_initialization_info ();
conf = new_converter_initialization_info ();
@@ -131,7 +156,7 @@ generic_converter_init (SV *converter_in, const char
*class, SV *format_defaults
format_defaults_sv,
conf_sv, format_defaults, conf);
- set_converter_init_information (self, converter_format,
+ set_converter_init_information (self, self->format,
format_defaults, conf);
destroy_converter_initialization_info (format_defaults);
@@ -654,20 +679,6 @@ html_converter_get_customization_sv (SV *converter_in, SV
*default_formatting_re
/* fill options with C only information not associated with Perl data */
html_fill_options_directions (self->conf, self);
-# do nothing as everything is already set in C
-# $converter, $conf
-SV *
-html_converter_defaults (...)
- PROTOTYPE: $$
- PREINIT:
- HV *format_defaults_hv;
- CODE:
- format_defaults_hv = newHV ();
- RETVAL = newRV_noinc ((SV *) format_defaults_hv);
- OUTPUT:
- RETVAL
-
-
# Following XS functions are called in Perl output and convert functions
# allowing to override functions separately.
# They are not actually called since output and convert are overriden.
diff --git a/tp/Texinfo/XS/convert/converter.c
b/tp/Texinfo/XS/convert/converter.c
index a1a13fdbe4..2c81259505 100644
--- a/tp/Texinfo/XS/convert/converter.c
+++ b/tp/Texinfo/XS/convert/converter.c
@@ -66,7 +66,7 @@
Same purpose as inherited methods in Texinfo::Convert::Converter */
CONVERTER_FORMAT_DATA converter_format_data[] = {
{"html", "Texinfo::Convert::HTML", &html_converter_defaults,
- /* &html_converter_initialize */ 0, &html_reset_converter,
+ &html_converter_initialize, &html_reset_converter,
&html_free_converter},
};
@@ -294,7 +294,8 @@ static void
apply_converter_info (CONVERTER *converter,
CONVERTER_INITIALIZATION_INFO *init_info, int set_configured)
{
- copy_options_list_options (converter->conf, converter->sorted_options,
+ copy_numbered_options_list_options (converter->conf,
+ converter->sorted_options,
&init_info->conf, set_configured);
if (init_info->output_format)
@@ -316,9 +317,8 @@ apply_converter_info (CONVERTER *converter,
}
}
-/* apply format_defaults and user_conf initialization information and call
- format specific options setting and initialization functions.
- Correspond to Perl _generic_converter_init.
+/* apply format_defaults and user_conf initialization information.
+ Corresponds to Perl _generic_converter_init.
*/
void
set_converter_init_information (CONVERTER *converter,
@@ -326,16 +326,11 @@ set_converter_init_information (CONVERTER *converter,
CONVERTER_INITIALIZATION_INFO *format_defaults,
CONVERTER_INITIALIZATION_INFO *user_conf)
{
- apply_converter_info (converter, format_defaults, 0);
-
- if (converter_format != COF_none
- && converter_format_data[converter_format].converter_defaults)
- {
- void (* format_converter_defaults) (CONVERTER *self,
- CONVERTER_INITIALIZATION_INFO *conf)
- = converter_format_data[converter_format].converter_defaults;
- format_converter_defaults (converter, user_conf);
- }
+ /* the case of format_defaults not set should correspond to
+ format_defaults C functions that sets the converter conf and return
+ 0 */
+ if (format_defaults)
+ apply_converter_info (converter, format_defaults, 0);
apply_converter_info (converter, user_conf, 1);
@@ -355,16 +350,6 @@ set_converter_init_information (CONVERTER *converter,
converter->output_format,
converter->converted_format);
*/
-
- /*
- if (converter_format != COF_none
- && converter_format_data[converter_format].converter_initialize)
- {
- void (* format_converter_initialize) (CONVERTER *self)
- = converter_format_data[converter_format].converter_initialize;
- format_converter_initialize (converter);
- }
- */
}
CONVERTER_INITIALIZATION_INFO *
@@ -391,6 +376,96 @@ destroy_converter_initialization_info
(CONVERTER_INITIALIZATION_INFO *init_info)
free (init_info);
}
+static void
+copy_converter_initialization_info (CONVERTER_INITIALIZATION_INFO *dst_info,
+ const CONVERTER_INITIALIZATION_INFO *src_info)
+{
+ if (src_info->converted_format)
+ {
+ free (dst_info->converted_format);
+ dst_info->converted_format = strdup (src_info->converted_format);
+ }
+ if (src_info->output_format)
+ {
+ free (dst_info->output_format);
+ dst_info->output_format = strdup (src_info->output_format);
+ }
+
+ copy_strings (&dst_info->non_valid_customization,
+ &src_info->non_valid_customization);
+
+ copy_options_list (&dst_info->conf, &src_info->conf);
+}
+
+/* Next three functions are not called from Perl as the Perl equivalent
+ functions are already called (and possibly overriden). Inheritance
+ in Perl is replaced by dispatching using a table here.
+
+ converter_initialize cannot be overriden fully in HTML because Perl
+ code is needed to setup customization in Perl. Therefore, there is
+ no prospect of overriding converter_initialize fully, and therefore
+ of overridding converter_converter. Those functions are only meant
+ for pure C.
+ */
+/* corresponds to Perl $converter->converter_defaults() Converter */
+static CONVERTER_INITIALIZATION_INFO *
+converter_defaults (CONVERTER *converter,
+ CONVERTER_INITIALIZATION_INFO *user_conf)
+{
+ if (converter->format != COF_none
+ && converter_format_data[converter->format].converter_defaults)
+ {
+ CONVERTER_INITIALIZATION_INFO *
+ (* format_converter_defaults) (CONVERTER *self,
+ CONVERTER_INITIALIZATION_INFO *conf)
+ = converter_format_data[converter->format].converter_defaults;
+ return format_converter_defaults (converter, user_conf);
+ }
+ return 0;
+}
+
+/* corresponds to Perl $converter->converter_initialize() Converter */
+static void
+converter_initialize (CONVERTER *converter)
+{
+ if (converter->format != COF_none
+ && converter_format_data[converter->format].converter_initialize)
+ {
+ void (* format_converter_initialize) (CONVERTER *self)
+ = converter_format_data[converter->format].converter_initialize;
+ format_converter_initialize (converter);
+ }
+}
+
+/* Texinfo::Convert::XXXX->converter($conf) in Perl */
+CONVERTER *
+converter_converter (enum converter_format format,
+ const CONVERTER_INITIALIZATION_INFO *input_user_conf)
+{
+ CONVERTER_INITIALIZATION_INFO *format_defaults;
+ size_t converter_descriptor = new_converter (format, CONVF_string_list);
+ CONVERTER *converter = retrieve_converter (converter_descriptor);
+
+ CONVERTER_INITIALIZATION_INFO *user_conf
+ = new_converter_initialization_info ();
+ copy_converter_initialization_info (user_conf, input_user_conf);
+ number_options_list (&user_conf->conf, converter->sorted_options);
+
+ format_defaults = converter_defaults (converter, user_conf);
+
+ set_converter_init_information (converter, format, format_defaults,
+ user_conf);
+
+ if (format_defaults)
+ destroy_converter_initialization_info (format_defaults);
+
+ destroy_converter_initialization_info (user_conf);
+
+ converter_initialize (converter);
+
+ return converter;
+}
+
void
converter_set_document (CONVERTER *converter, DOCUMENT *document)
{
diff --git a/tp/Texinfo/XS/convert/converter.h
b/tp/Texinfo/XS/convert/converter.h
index e527baa615..2ce209178e 100644
--- a/tp/Texinfo/XS/convert/converter.h
+++ b/tp/Texinfo/XS/convert/converter.h
@@ -93,7 +93,8 @@ typedef struct PATHS_INFORMATION {
typedef struct CONVERTER_FORMAT_DATA {
const char *default_format;
const char *perl_converter_class;
- void (* converter_defaults) (CONVERTER *self,
+ CONVERTER_INITIALIZATION_INFO *
+ (* converter_defaults) (CONVERTER *self,
CONVERTER_INITIALIZATION_INFO *conf);
void (* converter_initialize) (CONVERTER *self);
void (* converter_reset) (CONVERTER *self);
@@ -132,6 +133,9 @@ void set_converter_init_information (CONVERTER *converter,
CONVERTER_INITIALIZATION_INFO *format_defaults,
CONVERTER_INITIALIZATION_INFO *user_conf);
+CONVERTER *converter_converter (enum converter_format format,
+ const CONVERTER_INITIALIZATION_INFO *user_conf);
+
CONVERTER_INITIALIZATION_INFO *new_converter_initialization_info (void);
void destroy_converter_initialization_info (
CONVERTER_INITIALIZATION_INFO *defaults);
diff --git a/tp/Texinfo/XS/convert/get_converter_perl_info.c
b/tp/Texinfo/XS/convert/get_converter_perl_info.c
index 1a1d88f07c..7f060e38f0 100644
--- a/tp/Texinfo/XS/convert/get_converter_perl_info.c
+++ b/tp/Texinfo/XS/convert/get_converter_perl_info.c
@@ -74,6 +74,54 @@ get_sv_converter (SV *sv_in, const char *warn_string)
return converter;
}
+CONVERTER *
+get_or_create_sv_converter (SV *converter_in, const char *input_class)
+{
+ size_t converter_descriptor = 0;
+ CONVERTER *converter = 0;
+
+ dTHX;
+
+ converter = get_sv_converter (converter_in, 0);
+ if (!converter)
+ {
+ HV *stash;
+ const char *class = 0;
+ enum converter_format converter_format = COF_none;
+ int i;
+
+ if (input_class)
+ class = input_class;
+ else
+ {
+ stash = SvSTASH (SvRV (converter_in));
+ class = HvNAME (stash);
+ }
+
+ if (class)
+ {
+ /* determine the converter format, if handled in C */
+ for (i =0; i < TXI_CONVERSION_FORMAT_NR; i++)
+ {
+ if (!strcmp (converter_format_data[i].perl_converter_class,
+ class))
+ {
+ converter_format = i;
+ break;
+ }
+ }
+ }
+
+ converter_descriptor = new_converter (converter_format,
+ CONVF_perl_hashmap);
+ /*
+ CONVF_string_list);
+ */
+ converter = retrieve_converter (converter_descriptor);
+ }
+ return converter;
+}
+
CONVERTER *
converter_set_document_from_sv (SV *converter_in, SV *document_in)
{
@@ -196,7 +244,7 @@ new_option_from_sv (SV *option_sv, CONVERTER *converter,
/* class is Perl converter class for warning message in case the class
cannot be found otherwise */
-static int
+int
get_converter_info_from_sv (SV *conf_sv, const char *class,
CONVERTER *converter,
OPTION **sorted_options,
diff --git a/tp/Texinfo/XS/convert/get_converter_perl_info.h
b/tp/Texinfo/XS/convert/get_converter_perl_info.h
index 3879a46510..b641ecef27 100644
--- a/tp/Texinfo/XS/convert/get_converter_perl_info.h
+++ b/tp/Texinfo/XS/convert/get_converter_perl_info.h
@@ -11,6 +11,12 @@
#include "convert_to_text.h"
CONVERTER *get_sv_converter (SV *sv_in, const char *warn_string);
+CONVERTER *get_or_create_sv_converter (SV *converter_in,
+ const char *input_class);
+int get_converter_info_from_sv (SV *conf_sv, const char *class,
+ CONVERTER *converter,
+ OPTION **sorted_options,
+ CONVERTER_INITIALIZATION_INFO *initialization_info);
int converter_get_info_from_sv (SV *converter_sv, const char *class,
CONVERTER *converter,
SV *format_defaults_sv, SV *conf_sv,
diff --git a/tp/Texinfo/XS/convert/html_converter_api.c
b/tp/Texinfo/XS/convert/html_converter_api.c
index 1515a696b3..7f8d3bad90 100644
--- a/tp/Texinfo/XS/convert/html_converter_api.c
+++ b/tp/Texinfo/XS/convert/html_converter_api.c
@@ -25,6 +25,18 @@
#include "converter.h"
#include "html_converter_api.h"
+/* similar to Texinfo::Convert::HTML->converter_initialize */
+void
+html_converter_initialize (CONVERTER *converter)
+{
+ html_converter_initialize_beginning (converter);
+
+ html_converter_init_special_unit (converter);
+ html_converter_customize (converter);
+
+ html_fill_options_directions (converter->conf, converter);
+}
+
/* similar to Texinfo::Convert::HTML->output */
char *
html_output (CONVERTER *converter, DOCUMENT *document)
diff --git a/tp/Texinfo/XS/convert/html_converter_api.h
b/tp/Texinfo/XS/convert/html_converter_api.h
index 3829c85b02..0df111ef49 100644
--- a/tp/Texinfo/XS/convert/html_converter_api.h
+++ b/tp/Texinfo/XS/convert/html_converter_api.h
@@ -28,7 +28,7 @@
void html_format_setup (void);
/* in html_converter_init_options.c */
-void html_converter_defaults (CONVERTER *self,
+CONVERTER_INITIALIZATION_INFO *html_converter_defaults (CONVERTER *self,
CONVERTER_INITIALIZATION_INFO *format_defaults);
void html_converter_initialize_beginning (CONVERTER *self);
@@ -96,6 +96,8 @@ void html_free_converter (CONVERTER *self);
/* implemented in html_converter_api.c using above functions */
+void html_converter_initialize (CONVERTER *converter);
+
char *html_output (CONVERTER *converter, DOCUMENT *document);
char *html_convert (CONVERTER *converter, DOCUMENT *document);
diff --git a/tp/Texinfo/XS/convert/html_converter_init_options.c
b/tp/Texinfo/XS/convert/html_converter_init_options.c
index bcc3a5986c..f77c1387cf 100644
--- a/tp/Texinfo/XS/convert/html_converter_init_options.c
+++ b/tp/Texinfo/XS/convert/html_converter_init_options.c
@@ -27,6 +27,8 @@
/* option_force_conf */
#include "customization_options.h"
#include "create_buttons.h"
+/* new_converter_initialization_info */
+#include "converter.h"
#include "html_converter_init_options.h"
/* HTML converter options setting and initialization. Not with format
@@ -132,10 +134,17 @@ set_texi2html_default_buttons_specifications (CONVERTER
*self)
new_directions_list_buttons_specifications (self, T2H_SECTION_BUTTONS));
}
-void
+/* TODO we directly set the converter conf, so the conf list of
+ returned format_defaults is not set. This should work,
+ but this is not the spirit of the corresponding Perl API */
+CONVERTER_INITIALIZATION_INFO *
html_converter_defaults (CONVERTER *self,
CONVERTER_INITIALIZATION_INFO *conf)
{
+ CONVERTER_INITIALIZATION_INFO *format_defaults
+ = new_converter_initialization_info ();
+ format_defaults->converted_format = strdup ("html");
+
set_html_regular_options_defaults (self->conf);
set_html_default_buttons_specifications (self);
@@ -153,12 +162,13 @@ html_converter_defaults (CONVERTER *self,
{
set_texi2html_regular_options_defaults (self->conf);
set_texi2html_default_buttons_specifications (self);
- return;
+ return format_defaults;
}
break;
}
}
}
+ return format_defaults;
}
/* this code corresponds to the Perl converter_initialize code, only for
diff --git a/tp/Texinfo/XS/convert/html_converter_init_options.h
b/tp/Texinfo/XS/convert/html_converter_init_options.h
index e6c42e4d84..56519ab0af 100644
--- a/tp/Texinfo/XS/convert/html_converter_init_options.h
+++ b/tp/Texinfo/XS/convert/html_converter_init_options.h
@@ -5,7 +5,7 @@
#include "option_types.h"
#include "converter_types.h"
-void html_converter_defaults (CONVERTER *self,
+CONVERTER_INITIALIZATION_INFO *html_converter_defaults (CONVERTER *self,
CONVERTER_INITIALIZATION_INFO *format_defaults);
void html_converter_initialize_beginning (CONVERTER *self);
diff --git a/tp/Texinfo/XS/convert/texinfo.c b/tp/Texinfo/XS/convert/texinfo.c
index 45914d6b6c..f83acd3390 100644
--- a/tp/Texinfo/XS/convert/texinfo.c
+++ b/tp/Texinfo/XS/convert/texinfo.c
@@ -269,99 +269,70 @@ txi_complete_document (DOCUMENT *document, unsigned long
flags,
document->options);
}
-/* converter creation, similar to the very first part of
- Texinfo::Convert::Converter::converter and generic parts of
- _generic_converter_init, + some customization options settings
- that are done in Perl directly in texi2any.pl.
- */
CONVERTER *
-txi_converter (enum converter_format format)
+txi_converter (enum converter_format format,
+ CONVERTER_INITIALIZATION_INFO *user_conf)
{
- size_t converter_descriptor = new_converter (format, CONVF_string_list);
- return retrieve_converter (converter_descriptor);
+ return converter_converter (format, user_conf);
}
-/* converter initialization. Similar to $converter->converter_defaults(),
- _generic_converter_init and $converter->converter_initialize() calls */
-void
-txi_converter_initialize (CONVERTER *converter,
- const char *output_format,
- const char *converted_format,
- const char *locale_encoding,
- const char *program_file, OPTIONS_LIST *customizations)
+/* converter setup. Similar to an initialization of converter
+ from texi2any */
+CONVERTER *
+txi_converter_setup (const char *format_str,
+ const char *output_format,
+ const char *locale_encoding,
+ const char *program_file, OPTIONS_LIST *customizations)
{
- enum converter_format converter_format = converter->format;
- CONVERTER_INITIALIZATION_INFO *format_defaults;
+ enum converter_format converter_format
+ = find_format_data_index (format_str);
CONVERTER_INITIALIZATION_INFO *conf;
- const char *format;
-
- if (converter_format == COF_none)
- return;
+ CONVERTER *self;
- format = converter_format_data[converter_format].default_format;
+ conf = new_converter_initialization_info ();
/* prepare specific information for the converter */
- format_defaults = new_converter_initialization_info ();
- if (converted_format)
- format_defaults->converted_format = strdup (converted_format);
- else
- format_defaults->converted_format = strdup (format);
if (output_format)
- format_defaults->output_format = strdup (output_format);
+ conf->output_format = strdup (output_format);
else
- format_defaults->output_format = strdup (format);
+ conf->output_format = strdup (format_str);
- conf = new_converter_initialization_info ();
initialize_options_list (&conf->conf, 10);
- add_option_string_value (&conf->conf, converter->sorted_options,
+ /* similar to options coming from texi2any */
+ add_new_option_value (&conf->conf, GOT_char, "PROGRAM", 0,
+ program_file);
/*
*/
- "PROGRAM", 0, program_file);
/* comment the line above and uncomment below to compare with
texi2any output
- "PROGRAM", 0, "texi2any");
- add_option_string_value (&conf->conf, converter->sorted_options,
+ "texi2any");
+ add_new_option_value (&conf->conf, GOT_char,
"PACKAGE_AND_VERSION", 0, "Texinfo 7.1.90+dev");
*/
- add_option_string_value (&conf->conf, converter->sorted_options,
+ add_new_option_value (&conf->conf, GOT_char,
"COMMAND_LINE_ENCODING", 0, locale_encoding);
- add_option_string_value (&conf->conf, converter->sorted_options,
+ add_new_option_value (&conf->conf, GOT_char,
"MESSAGE_ENCODING", 0, locale_encoding);
- add_option_string_value (&conf->conf, converter->sorted_options,
+ add_new_option_value (&conf->conf, GOT_char,
"LOCALE_ENCODING", 0, locale_encoding);
/* filled here because it is the best we have in C */
- add_option_string_value (&conf->conf, converter->sorted_options,
+ add_new_option_value (&conf->conf, GOT_char,
"XS_STRXFRM_COLLATION_LOCALE", 0, "en_US");
/*
- add_option_string_value (&conf->conf, converter->sorted_options,
+ add_new_option_value (&conf->conf, GOT_integer,
"DEBUG", 1, 0);
*/
+
if (customizations)
{
- copy_options_list (&conf->conf, customizations,
- converter->sorted_options);
+ copy_options_list (&conf->conf, customizations);
}
- /* pass information to the converter and format specific initialization */
- set_converter_init_information (converter, converter_format,
- format_defaults, conf);
-
- switch (converter_format)
- {
- case COF_html:
- html_converter_initialize_beginning (converter);
- html_converter_init_special_unit (converter);
- html_converter_customize (converter);
-
- html_fill_options_directions (converter->conf, converter);
- break;
- default:
- break;
- }
+ self = converter_converter (converter_format, conf);
- destroy_converter_initialization_info (format_defaults);
destroy_converter_initialization_info (conf);
+ return self;
}
diff --git a/tp/Texinfo/XS/convert/texinfo.h b/tp/Texinfo/XS/convert/texinfo.h
index 31f21528fd..5ffd458af3 100644
--- a/tp/Texinfo/XS/convert/texinfo.h
+++ b/tp/Texinfo/XS/convert/texinfo.h
@@ -39,12 +39,13 @@ DOCUMENT *txi_parse_texi_file (const char *input_file_path,
int *status);
void txi_complete_document (DOCUMENT *document, unsigned long flags,
int format_menu);
-CONVERTER *txi_converter (enum converter_format format);
-void txi_converter_initialize (CONVERTER *converter,
- const char *output_format,
- const char *converted_format,
- const char *locale_encoding,
- const char *program_file, OPTIONS_LIST *customizations);
+CONVERTER *txi_converter (enum converter_format format,
+ CONVERTER_INITIALIZATION_INFO *conf);
+CONVERTER *
+txi_converter_setup (const char *converter_format,
+ const char *output_format,
+ const char *locale_encoding,
+ const char *program_file, OPTIONS_LIST *customizations);
char *txi_html_output (CONVERTER *converter, DOCUMENT *document);
diff --git a/tp/Texinfo/XS/main/customization_options.c
b/tp/Texinfo/XS/main/customization_options.c
index 13955b9562..144e840736 100644
--- a/tp/Texinfo/XS/main/customization_options.c
+++ b/tp/Texinfo/XS/main/customization_options.c
@@ -390,9 +390,12 @@ initialize_options_list (OPTIONS_LIST *options_list,
size_t number)
}
/* copy OPTIONS_LIST options to an OPTIONS structure, using the sorted options
- to find the struct fields. */
+ to find the struct fields. The source options numbers need to be set
+ already.
+ */
void
-copy_options_list_options (OPTIONS *options, OPTION **sorted_options,
+copy_numbered_options_list_options (OPTIONS *options,
+ OPTION **sorted_options,
OPTIONS_LIST *options_list, int set_configured)
{
size_t i;
@@ -475,8 +478,7 @@ add_option_string_value (OPTIONS_LIST *options_list, OPTION
**sorted_options,
}
OPTION *
-add_option_copy (OPTIONS_LIST *options_list, OPTION **sorted_options,
- const OPTION *src_option)
+add_option_copy (OPTIONS_LIST *options_list, const OPTION *src_option)
{
OPTION *option
= new_option (src_option->type, src_option->name, src_option->number);
@@ -489,7 +491,7 @@ add_option_copy (OPTIONS_LIST *options_list, OPTION
**sorted_options,
}
/* similar with new_option_string_value but in cases where there is no
- sorted_options, and options are found with their names, in practice
+ sorted_options, and options are found with their names, for example
for parser options */
OPTION *
add_new_option_value (OPTIONS_LIST *options_list,
@@ -507,18 +509,40 @@ add_new_option_value (OPTIONS_LIST *options_list,
void
-copy_options_list (OPTIONS_LIST *options_list,
- const OPTIONS_LIST *options_src, OPTION **sorted_options)
+copy_options_list (OPTIONS_LIST *options_list, const OPTIONS_LIST *options_src)
{
size_t i;
if (options_src)
{
for (i = 0; i < options_src->number; i++)
- add_option_copy (options_list, sorted_options, options_src->list[i]);
+ add_option_copy (options_list, options_src->list[i]);
}
}
+void
+number_options_list (OPTIONS_LIST *options_list, OPTION **sorted_options)
+{
+ size_t i;
+
+ for (i = 0; i < options_list->number; i++)
+ {
+ OPTION *option = options_list->list[i];
+ if (!option->number)
+ {
+ const OPTION *ref_option
+ = find_option_string (sorted_options, option->name);
+ if (ref_option)
+ option->number = ref_option->number;
+ else
+ fprintf (stderr, "ERROR: could not find option: %s\n",
+ option->name);
+ }
+ }
+}
+
+
+
void
free_options_list (OPTIONS_LIST *options_list)
{
diff --git a/tp/Texinfo/XS/main/customization_options.h
b/tp/Texinfo/XS/main/customization_options.h
index 4e972ee396..886261103a 100644
--- a/tp/Texinfo/XS/main/customization_options.h
+++ b/tp/Texinfo/XS/main/customization_options.h
@@ -28,7 +28,8 @@ void clear_options (OPTIONS *options);
void free_options (OPTIONS *options);
void copy_options (OPTIONS *destination, const OPTIONS *source);
-void copy_options_list_options (OPTIONS *options, OPTION **sorted_options,
+void copy_numbered_options_list_options (OPTIONS *options,
+ OPTION **sorted_options,
OPTIONS_LIST *options_list, int
set_configured);
void initialize_options_list (OPTIONS_LIST *options_list, size_t number);
void free_options_list (OPTIONS_LIST *options_list);
@@ -58,6 +59,7 @@ OPTION *add_new_option_value (OPTIONS_LIST *options_list,
int int_value, const char *char_value);
void copy_options_list (OPTIONS_LIST *options_list,
- const OPTIONS_LIST *options_src, OPTION **sorted_options);
+ const OPTIONS_LIST *options_src);
+void number_options_list (OPTIONS_LIST *options_list, OPTION **sorted_options);
#endif
diff --git a/tp/Texinfo/XS/teximakehtml.c b/tp/Texinfo/XS/teximakehtml.c
index 2912d14663..1d3e2983c2 100644
--- a/tp/Texinfo/XS/teximakehtml.c
+++ b/tp/Texinfo/XS/teximakehtml.c
@@ -40,8 +40,8 @@
#define LOCALEDIR DATADIR "/locale"
-/* this function is generic, it could be added to customization_options.c */
-static void
+/* these functions are generic, could be added to customization_options.c */
+void
add_button_option (OPTIONS_LIST *options_list, OPTION **sorted_options,
const char *option_name,
BUTTON_SPECIFICATION_LIST *buttons)
@@ -58,6 +58,19 @@ add_button_option (OPTIONS_LIST *options_list, OPTION
**sorted_options,
options_list_add_option (options_list, option);
}
+static OPTION *
+add_new_button_option (OPTIONS_LIST *options_list, const char *option_name,
+ BUTTON_SPECIFICATION_LIST *buttons)
+{
+ OPTION *option = new_option (GOT_buttons, option_name, 0);
+
+ option->o.buttons = buttons;
+
+ options_list_add_option (options_list, option);
+
+ return option;
+}
+
/* this function or a variation could be added to customization_options.c */
static OPTION *
add_new_option_strlist_value (OPTIONS_LIST *options_list,
@@ -182,28 +195,29 @@ main (int argc, char *argv[])
= txi_handle_document_error_messages (document, 0, 1, locale_encoding);
errors_count += errors_nr;
- /* create converter and generic converter initializations */
- converter = txi_converter (COF_html);
+ /* conversion intitialization */
initialize_options_list (&convert_options, 2);
+
/* customize buttons. This is a bit silly to use link buttons for
footer, it is for the demonstration */
custom_node_footer_buttons = new_base_links_buttons (0);
- add_button_option (&convert_options, converter->sorted_options,
+ add_new_button_option (&convert_options,
"NODE_FOOTER_BUTTONS", custom_node_footer_buttons);
- add_option_string_value (&convert_options, converter->sorted_options,
+ add_new_option_value (&convert_options, GOT_integer,
"PROGRAM_NAME_IN_FOOTER", 1, 0);
/* this is set to help with comparison with previous invokations */
- add_option_string_value (&convert_options, converter->sorted_options,
+ add_new_option_value (&convert_options, GOT_integer,
"TEST", 1, 0);
- /* setup converter */
- txi_converter_initialize (converter, 0, 0, locale_encoding, program_file,
- &convert_options);
+ converter = txi_converter_setup ("html", "html", locale_encoding,
+ program_file, &convert_options);
free_options_list (&convert_options);
free (program_file);
+
+ /* conversion */
/* return value can be NULL in case of errors or an empty string, but
not anything else as parse_file is used with a file */
result = txi_html_output (converter, document);
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- branch master updated: * tp/Texinfo/XS/main/customization_options.c (copy_numbered_options_list_options): rename copy_options_list_options to copy_numbered_options_list_options. Update callers.,
Patrice Dumas <=