texinfo-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

branch master updated: * tp/Texinfo/XS/main/utils.h, tp/Texinfo/XS/main/


From: Patrice Dumas
Subject: branch master updated: * tp/Texinfo/XS/main/utils.h, tp/Texinfo/XS/main/converter_types.h (HTML_ARGUMENTS_FORMATTED_FORMAT_TYPE, HTML_ARGS_FORMATTED) (HTML_ARG_FORMATTED): move from utils.h to converter_types.h.
Date: Wed, 15 Nov 2023 11:05:04 -0500

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 be244396d8 * tp/Texinfo/XS/main/utils.h, 
tp/Texinfo/XS/main/converter_types.h (HTML_ARGUMENTS_FORMATTED_FORMAT_TYPE, 
HTML_ARGS_FORMATTED) (HTML_ARG_FORMATTED): move from utils.h to 
converter_types.h.
be244396d8 is described below

commit be244396d8381ab368847adc4b8e3f3ca163e04f
Author: Patrice Dumas <pertusus@free.fr>
AuthorDate: Wed Nov 15 17:04:56 2023 +0100

    * tp/Texinfo/XS/main/utils.h, tp/Texinfo/XS/main/converter_types.h
    (HTML_ARGUMENTS_FORMATTED_FORMAT_TYPE, HTML_ARGS_FORMATTED)
    (HTML_ARG_FORMATTED): move from utils.h to converter_types.h.
    
    * tp/Texinfo/XS/convert/convert_html.c (command_conversion_external)
    (type_conversion_external, register_type_conversion_function)
    (register_command_conversion_function, html_converter_initialize)
    (html_initialize_output_state, html_destroy, html_convert_css_string)
    (convert_to_html_internal), tp/Texinfo/XS/main/converter_types.h
    (CONVERTER, TYPE_CONVERSION_FUNCTION, COMMAND_CONVERSION_FUNCTION):
    use directly function references to convert types and commands, in
    order to be able to replace functions calling perl by C functions.
    Rename type_conversion as type_conversion_external and
    command_conversion as command_conversion_external.
---
 ChangeLog                                  |  17 ++++
 tp/Texinfo/Convert/HTML.pm                 |   6 +-
 tp/Texinfo/XS/convert/convert_html.c       | 153 ++++++++++++++++++++++-------
 tp/Texinfo/XS/convert/get_html_perl_info.c |   4 +-
 tp/Texinfo/XS/main/converter_types.h       |  63 +++++++++++-
 tp/Texinfo/XS/main/utils.h                 |  27 -----
 6 files changed, 200 insertions(+), 70 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 5412d7ecc5..3312c45b47 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,20 @@
+2023-11-15  Patrice Dumas  <pertusus@free.fr>
+
+       * tp/Texinfo/XS/main/utils.h, tp/Texinfo/XS/main/converter_types.h
+       (HTML_ARGUMENTS_FORMATTED_FORMAT_TYPE, HTML_ARGS_FORMATTED)
+       (HTML_ARG_FORMATTED): move from utils.h to converter_types.h.
+
+       * tp/Texinfo/XS/convert/convert_html.c (command_conversion_external)
+       (type_conversion_external, register_type_conversion_function)
+       (register_command_conversion_function, html_converter_initialize)
+       (html_initialize_output_state, html_destroy, html_convert_css_string)
+       (convert_to_html_internal), tp/Texinfo/XS/main/converter_types.h
+       (CONVERTER, TYPE_CONVERSION_FUNCTION, COMMAND_CONVERSION_FUNCTION):
+       use directly function references to convert types and commands, in
+       order to be able to replace functions calling perl by C functions.
+       Rename type_conversion as type_conversion_external and
+       command_conversion as command_conversion_external.
+
 2023-11-15  Patrice Dumas  <pertusus@free.fr>
 
        * doc/texi2any_api.texi (Simple Output Customization for Simple
diff --git a/tp/Texinfo/Convert/HTML.pm b/tp/Texinfo/Convert/HTML.pm
index 481a990022..3aa0782ef9 100644
--- a/tp/Texinfo/Convert/HTML.pm
+++ b/tp/Texinfo/Convert/HTML.pm
@@ -11024,8 +11024,8 @@ sub _initialize_output_state($$)
 
   # targets and directions
 
-  # used for diverse elements: tree units, indices, footnotes, special
-  # elements, contents elements...
+  # used for diverse tree elements: nodes and sectioning commands, indices,
+  # footnotes, special output units elements...
   $self->{'targets'} = {};
   $self->{'seen_ids'} = {};
 
@@ -11561,7 +11561,7 @@ sub _html_convert_output($$$$$$$$)
 
 # Main function for outputting a manual in HTML.
 # $SELF is the output converter object of class Texinfo::Convert::HTML (this
-# module), and $DOCUMENT is the Texinfo parsed document from the parser.
+# module), and $DOCUMENT is the parsed document from the parser and structuring
 sub output($$)
 {
   my $self = shift;
diff --git a/tp/Texinfo/XS/convert/convert_html.c 
b/tp/Texinfo/XS/convert/convert_html.c
index e1e798a182..4a449ac190 100644
--- a/tp/Texinfo/XS/convert/convert_html.c
+++ b/tp/Texinfo/XS/convert/convert_html.c
@@ -2406,7 +2406,7 @@ protect_text_no_iso_entities (const char *text, TEXT 
*result)
 #undef ADDN
 
 static char *
-command_conversion (CONVERTER *self, enum command_id cmd,
+command_conversion_external (CONVERTER *self, enum command_id cmd,
                     const ELEMENT *element, HTML_ARGS_FORMATTED 
*args_formatted,
                     char *content)
 {
@@ -2420,7 +2420,7 @@ command_conversion (CONVERTER *self, enum command_id cmd,
    */
 
   FORMATTING_REFERENCE *formatting_reference
-    = &self->current_commands_conversion[cmd];
+    = self->current_commands_conversion_function[cmd]->formatting_reference;
 
   if (formatting_reference->status > 0)
     return call_commands_conversion (self, cmd, formatting_reference,
@@ -2439,14 +2439,11 @@ command_open (CONVERTER *self, enum command_id cmd, 
const ELEMENT *element)
 }
 
 static char *
-type_conversion (CONVERTER *self, enum element_type type,
-                 const ELEMENT *element, char *content)
+type_conversion_external (CONVERTER *self, enum element_type type,
+                          const ELEMENT *element, char *content)
 {
-  /* TODO call a C function if status is FRS_status_default_set
-     maybe putting function references in an array */
-
   FORMATTING_REFERENCE *formatting_reference
-    = &self->current_types_conversion[type];
+    = self->current_types_conversion_function[type]->formatting_reference;
 
   if (formatting_reference->status > 0)
     return call_types_conversion (self, type, formatting_reference,
@@ -2655,6 +2652,54 @@ html_format_init ()
   html_commands_data[CM_float].flags |= HF_composition_context;
 }
 
+TYPE_CONVERSION_FUNCTION *
+register_type_conversion_function (enum element_type type,
+                         FORMATTING_REFERENCE *formatting_reference)
+{
+  TYPE_CONVERSION_FUNCTION *result = 0;
+  if (formatting_reference->status > 0)
+    {
+      result = (TYPE_CONVERSION_FUNCTION *)
+        malloc (sizeof (TYPE_CONVERSION_FUNCTION));
+      result->status = formatting_reference->status;
+      if (formatting_reference->status != FRS_status_ignored)
+        {
+          result->type_conversion = &type_conversion_external;
+          result->formatting_reference = formatting_reference;
+        }
+      else
+        {
+          result->type_conversion = 0;
+          result->formatting_reference = 0;
+        }
+    }
+  return result;
+}
+
+COMMAND_CONVERSION_FUNCTION *
+register_command_conversion_function (enum command_id cmd,
+                         FORMATTING_REFERENCE *formatting_reference)
+{
+  COMMAND_CONVERSION_FUNCTION *result = 0;
+  if (formatting_reference->status > 0)
+    {
+       result = (COMMAND_CONVERSION_FUNCTION *)
+         malloc (sizeof (COMMAND_CONVERSION_FUNCTION));
+       result->status = formatting_reference->status;
+       if (formatting_reference->status != FRS_status_ignored)
+         {
+           result->command_conversion = &command_conversion_external;
+           result->formatting_reference = formatting_reference;
+         }
+       else
+         {
+           result->command_conversion = 0;
+           result->formatting_reference = 0;
+         }
+    }
+  return result;
+}
+
 /* most of the initialization is done by html_converter_initialize_sv
    in get_perl_info, the initialization that do not require information
    directly from perl data is done here.  This is called after information
@@ -2704,6 +2749,24 @@ html_converter_initialize (CONVERTER *self)
       self->command_special_variety_name_index[i].cmd = cmd;
       self->command_special_variety_name_index[i].index = number - 1;
     }
+
+  for (i = 0; i < ET_special_unit_element+1; i++)
+    {
+      self->type_conversion_function[i]
+        = register_type_conversion_function(i, &self->types_conversion[i]);
+      self->css_string_type_conversion_function[i]
+        = register_type_conversion_function(i,
+             &self->css_string_types_conversion[i]);
+    }
+
+  for (i = 0; i < BUILTIN_CMD_NUMBER; i++)
+    {
+      self->command_conversion_function[i]
+        = register_command_conversion_function(i, 
&self->commands_conversion[i]);
+      self->css_string_command_conversion_function[i]
+        = register_command_conversion_function(i,
+             &self->css_string_commands_conversion[i]);
+    }
 }
 
 void
@@ -2741,8 +2804,9 @@ html_initialize_output_state (CONVERTER *self, char 
*context)
 
 
   self->current_formatting_references = &self->formatting_references[0];
-  self->current_commands_conversion = &self->commands_conversion[0];
-  self->current_types_conversion = &self->types_conversion[0];
+  self->current_commands_conversion_function
+     = &self->command_conversion_function[0];
+  self->current_types_conversion_function = &self->type_conversion_function[0];
 
   /* FIXME now done through HTML _initialize_output_state, would need
      to readd when the HTML function is overriden
@@ -2879,6 +2943,18 @@ html_destroy (CONVERTER *self)
         }
     }
 
+  for (i = 0; i < ET_special_unit_element+1; i++)
+    {
+      free (self->type_conversion_function[i]);
+      free (self->css_string_type_conversion_function[i]);
+    }
+
+  for (i = 0; i < BUILTIN_CMD_NUMBER; i++)
+    {
+      free (self->command_conversion_function[i]);
+      free (self->css_string_command_conversion_function[i]);
+    }
+
   free (self->no_arg_formatted_cmd.list);
 
   free (self->no_arg_formatted_cmd_translated.list);
@@ -2962,17 +3038,17 @@ html_convert_css_string (CONVERTER *self, const ELEMENT 
*element, char *explanat
 
   FORMATTING_REFERENCE *saved_formatting_references
      = self->current_formatting_references;
-  FORMATTING_REFERENCE *saved_commands_conversion
-     = self->current_commands_conversion;
-  FORMATTING_REFERENCE *saved_types_conversion
-     = self->current_types_conversion;
+  COMMAND_CONVERSION_FUNCTION **saved_commands_conversion_function
+     = self->current_commands_conversion_function;
+  TYPE_CONVERSION_FUNCTION **saved_types_conversion_function
+     = self->current_types_conversion_function;
 
   self->current_formatting_references
     = &self->css_string_formatting_references[0];
-  self->current_commands_conversion
-    = &self->css_string_commands_conversion[0];
-  self->current_types_conversion
-    = &self->css_string_types_conversion[0];
+  self->current_commands_conversion_function
+    = &self->css_string_command_conversion_function[0];
+  self->current_types_conversion_function
+    = &self->css_string_type_conversion_function[0];
 
   html_new_document_context (self, "css_string", 0, 0);
   top_document_ctx = html_top_document_context (self);
@@ -2983,8 +3059,9 @@ html_convert_css_string (CONVERTER *self, const ELEMENT 
*element, char *explanat
   html_pop_document_context (self);
 
   self->current_formatting_references = saved_formatting_references;
-  self->current_commands_conversion = saved_commands_conversion;
-  self->current_types_conversion = saved_types_conversion;
+  self->current_commands_conversion_function
+    = saved_commands_conversion_function;
+  self->current_types_conversion_function = saved_types_conversion_function;
 
   return result;
 }
@@ -3358,9 +3435,13 @@ convert_to_html_internal (CONVERTER *self, const ELEMENT 
*element,
     }
 
   if ((element->type
-       && self->current_types_conversion[element->type].status == 
FRS_status_ignored)
+       && self->current_types_conversion_function[element->type]
+       && self->current_types_conversion_function[element->type]->status
+                                                         == FRS_status_ignored)
       || (cmd
-          && self->current_commands_conversion[cmd].status == 
FRS_status_ignored))
+          && self->current_commands_conversion_function[cmd]
+          && self->current_commands_conversion_function[cmd]->status
+                                                         == 
FRS_status_ignored))
     {
       if (self->conf->DEBUG > 0)
         {
@@ -3393,8 +3474,9 @@ convert_to_html_internal (CONVERTER *self, const ELEMENT 
*element,
         }
       else
         {
-          char *conv_text = type_conversion (self, ET_text, element,
-                                             element->text.text);
+          char *conv_text
+            = 
(*self->current_types_conversion_function[ET_text]->type_conversion)
+                           (self, ET_text, element, element->text.text);
           if (conv_text)
             {
               text_append (&text_result, conv_text);
@@ -3432,7 +3514,7 @@ convert_to_html_internal (CONVERTER *self, const ELEMENT 
*element,
           self->modified_state |= HMSF_current_root;
         }
 
-      if (self->current_commands_conversion[cmd].status)
+      if (self->current_commands_conversion_function[cmd])
         {
           int convert_to_latex = 0;
           HTML_ARGS_FORMATTED *args_formatted = 0;
@@ -3846,11 +3928,11 @@ convert_to_html_internal (CONVERTER *self, const 
ELEMENT *element,
             }
 
           /* args are formatted, now format the command itself */
-          if (self->current_commands_conversion[cmd].status)
+          if (self->current_commands_conversion_function[cmd])
             {
-              char *conv_str = command_conversion (self, cmd,
-                                                   element, args_formatted,
-                                                   content_formatted.text);
+              char *conv_str
+        = 
(*self->current_commands_conversion_function[cmd]->command_conversion)
+                   (self, cmd, element, args_formatted, 
content_formatted.text);
               if (conv_str)
                 {
                   ADD(conv_str);
@@ -3970,11 +4052,11 @@ convert_to_html_internal (CONVERTER *self, const 
ELEMENT *element,
             }
         }
 
-      if (self->current_types_conversion[type].status)
+      if (self->current_types_conversion_function[type])
         {
           char *conversion_result
-                    = type_conversion (self, type, element,
-                                       content_formatted.text);
+            = (*self->current_types_conversion_function[type]->type_conversion)
+               (self, type, element, content_formatted.text);
           if (conversion_result)
             {
               text_append (&type_result, conversion_result);
@@ -4048,11 +4130,12 @@ convert_to_html_internal (CONVERTER *self, const 
ELEMENT *element,
     {
       if (self->conf->DEBUG > 0)
         fprintf (stderr, "UNNAMED empty\n");
-      if (self->current_types_conversion[0].status
-          && self->current_types_conversion[0].status != FRS_status_ignored)
+      if (self->current_types_conversion_function[0]
+          && self->current_types_conversion_function[0]->type_conversion)
         {
           char *conversion_result
-                    = type_conversion (self, 0, element, "");
+            = (*self->current_types_conversion_function[0]->type_conversion)
+                           (self, 0, element, "");
           if (conversion_result)
             {
               ADD(conversion_result);
diff --git a/tp/Texinfo/XS/convert/get_html_perl_info.c 
b/tp/Texinfo/XS/convert/get_html_perl_info.c
index f8217abc79..c8e75f48aa 100644
--- a/tp/Texinfo/XS/convert/get_html_perl_info.c
+++ b/tp/Texinfo/XS/convert/get_html_perl_info.c
@@ -102,8 +102,8 @@ register_formatting_reference_with_default (char 
*type_string,
         formatting_reference->status = FRS_status_ignored;
     }
    /*
-  fprintf (stderr, "register: %s %d '%s'\n", type_string,
-           formatting_reference->status, ref_name);
+  fprintf (stderr, "register: %s %d '%s' %p\n", type_string,
+           formatting_reference->status, ref_name, formatting_reference);
     */
 }
 
diff --git a/tp/Texinfo/XS/main/converter_types.h 
b/tp/Texinfo/XS/main/converter_types.h
index bc62a9a3e3..3657e2c115 100644
--- a/tp/Texinfo/XS/main/converter_types.h
+++ b/tp/Texinfo/XS/main/converter_types.h
@@ -134,6 +134,23 @@ enum html_formatting_reference {
   #undef html_fr_reference
 };
 
+#define HTML_ARGUMENTS_FORMATTED_FORMAT_TYPE \
+  html_aft_type(none) \
+  html_aft_type(normal) \
+  html_aft_type(string) \
+  html_aft_type(monospace) \
+  html_aft_type(monospacetext) \
+  html_aft_type(monospacestring) \
+  html_aft_type(filenametext) \
+  html_aft_type(url) \
+  html_aft_type(raw)
+
+enum html_argument_formatting_type {
+   #define html_aft_type(name) AFT_type_##name,
+    HTML_ARGUMENTS_FORMATTED_FORMAT_TYPE
+   #undef html_aft_type
+};
+
 typedef struct {
     enum command_id *stack;
     size_t top;   /* One above last pushed command. */
@@ -378,7 +395,15 @@ typedef struct CONVERTER {
     FORMATTING_REFERENCE output_units_conversion[OU_special_unit+1];
     STRING_LIST special_unit_varieties;
     char **special_unit_info[SUI_type_heading+1];
-
+    /* in the next line we use a pointer and not directly the structure
+       because the type is incomplete, the structure is defined after the
+       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 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 */
     HTML_COMMAND_CONVERSION 
html_command_conversion[BUILTIN_CMD_NUMBER][HCC_type_css_string+1];
 
@@ -415,8 +440,8 @@ typedef struct CONVERTER {
     /* next three allow to switch from normal HTML formatting to css strings
        formatting */
     FORMATTING_REFERENCE *current_formatting_references;
-    FORMATTING_REFERENCE *current_commands_conversion;
-    FORMATTING_REFERENCE *current_types_conversion;
+    struct TYPE_CONVERSION_FUNCTION **current_types_conversion_function;
+    struct COMMAND_CONVERSION_FUNCTION **current_commands_conversion_function;
 
     /* state common with perl converter */
     int document_global_context;
@@ -429,6 +454,38 @@ typedef struct CONVERTER {
     char *current_filename;
 } CONVERTER;
 
+typedef struct TYPE_CONVERSION_FUNCTION {
+    enum formatting_reference_status status;
+    /* points to the perl formatting reference if it is used for
+       conversion */
+    FORMATTING_REFERENCE *formatting_reference;
+    /* the function used for conversion, either a function that calls
+       the perl function in formatting_reference, or another C function */
+    char * (* type_conversion) (CONVERTER *self, enum element_type type, const 
ELEMENT *element, char *content);
+} TYPE_CONVERSION_FUNCTION;
+
+typedef struct HTML_ARG_FORMATTED {
+    const ELEMENT *tree;
+    char *formatted[AFT_type_raw+1];
+} HTML_ARG_FORMATTED;
+
+typedef struct HTML_ARGS_FORMATTED {
+    size_t number;
+    HTML_ARG_FORMATTED *args;
+} HTML_ARGS_FORMATTED;
+
+typedef struct COMMAND_CONVERSION_FUNCTION {
+    enum formatting_reference_status status;
+    /* points to the perl formatting reference if it is used for
+       conversion */
+    FORMATTING_REFERENCE *formatting_reference;
+    /* the function used for conversion, either a function that calls
+       the perl function in formatting_reference, or another C function */
+    char * (* command_conversion) (CONVERTER *self, enum command_id cmd,
+                                   const ELEMENT *element, HTML_ARGS_FORMATTED 
*args_formatted,
+                                   char *content);
+} COMMAND_CONVERSION_FUNCTION;
+
 typedef struct TRANSLATED_SUI_ASSOCIATION {
     enum special_unit_info_tree tree_type;
     enum special_unit_info_type string_type;
diff --git a/tp/Texinfo/XS/main/utils.h b/tp/Texinfo/XS/main/utils.h
index 93952bc1d9..cfca2f7170 100644
--- a/tp/Texinfo/XS/main/utils.h
+++ b/tp/Texinfo/XS/main/utils.h
@@ -166,35 +166,8 @@ typedef struct FILE_SOURCE_INFO_LIST {
     FILE_SOURCE_INFO *list;
 } FILE_SOURCE_INFO_LIST;
 
-#define HTML_ARGUMENTS_FORMATTED_FORMAT_TYPE \
-  html_aft_type(none) \
-  html_aft_type(normal) \
-  html_aft_type(string) \
-  html_aft_type(monospace) \
-  html_aft_type(monospacetext) \
-  html_aft_type(monospacestring) \
-  html_aft_type(filenametext) \
-  html_aft_type(url) \
-  html_aft_type(raw)
-
-enum html_argument_formatting_type {
-   #define html_aft_type(name) AFT_type_##name,
-    HTML_ARGUMENTS_FORMATTED_FORMAT_TYPE
-   #undef html_aft_type
-};
-
 extern const char *html_argument_formatting_type_names[];
 
-typedef struct HTML_ARG_FORMATTED {
-    const ELEMENT *tree;
-    char *formatted[AFT_type_raw+1];
-} HTML_ARG_FORMATTED;
-
-typedef struct HTML_ARGS_FORMATTED {
-    size_t number;
-    HTML_ARG_FORMATTED *args;
-} HTML_ARGS_FORMATTED;
-
 typedef struct ELEMENT_STACK {
     const ELEMENT **stack;
     size_t top;



reply via email to

[Prev in Thread] Current Thread [Next in Thread]