texinfo-commits
[Top][All Lists]
Advanced

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

branch master updated: * tp/Texinfo/XS/convert/call_html_perl_function.c


From: Patrice Dumas
Subject: branch master updated: * tp/Texinfo/XS/convert/call_html_perl_function.c (call_stage_handler), tp/Texinfo/XS/convert/convert_html.c (html_stage_handler_stage_type_names, run_stage_handlers), tp/Texinfo/XS/convert/get_html_perl_info.c (html_converter_initialize_sv), tp/Texinfo/XS/main/converter_types.h (enum html_stage_handler_stage_type, HTML_STAGE_HANDLER_INFO) (HTML_STAGE_HANDLER_INFO_LIST, CONVERTER): get stage handlers from Perl and put them in HTML_STAGE_HANDLER_INFO_LIST structure in converter. Add run_st [...]
Date: Sun, 29 Sep 2024 14:59:22 -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 5def9f47f2 * tp/Texinfo/XS/convert/call_html_perl_function.c 
(call_stage_handler), tp/Texinfo/XS/convert/convert_html.c 
(html_stage_handler_stage_type_names, run_stage_handlers), 
tp/Texinfo/XS/convert/get_html_perl_info.c (html_converter_initialize_sv), 
tp/Texinfo/XS/main/converter_types.h (enum html_stage_handler_stage_type, 
HTML_STAGE_HANDLER_INFO) (HTML_STAGE_HANDLER_INFO_LIST, CONVERTER): get stage 
handlers from Perl and put them in HTML_STAGE_HANDLER_INFO_LIST structure in c 
[...]
5def9f47f2 is described below

commit 5def9f47f2c17103d1d8d40805ed7896649a9581
Author: Patrice Dumas <pertusus@free.fr>
AuthorDate: Sun Jul 7 00:22:45 2024 +0200

    * tp/Texinfo/XS/convert/call_html_perl_function.c
    (call_stage_handler), tp/Texinfo/XS/convert/convert_html.c
    (html_stage_handler_stage_type_names, run_stage_handlers),
    tp/Texinfo/XS/convert/get_html_perl_info.c
    (html_converter_initialize_sv), tp/Texinfo/XS/main/converter_types.h
    (enum html_stage_handler_stage_type, HTML_STAGE_HANDLER_INFO)
    (HTML_STAGE_HANDLER_INFO_LIST, CONVERTER): get stage handlers from
    Perl and put them in HTML_STAGE_HANDLER_INFO_LIST structure in
    converter.  Add run_stage_handlers and call_stage_handler to call Perl
    registered stage handlers references.
---
 ChangeLog                                       | 13 ++++
 tp/Texinfo/XS/convert/build_html_perl_state.c   |  1 +
 tp/Texinfo/XS/convert/call_html_perl_function.c | 59 ++++++++++++++++
 tp/Texinfo/XS/convert/call_html_perl_function.h |  2 +
 tp/Texinfo/XS/convert/convert_html.c            | 60 ++++++++++++++++
 tp/Texinfo/XS/convert/convert_html.h            |  2 +
 tp/Texinfo/XS/convert/get_html_perl_info.c      | 93 +++++++++++++++++++++++++
 tp/Texinfo/XS/main/converter_types.h            | 26 +++++++
 tp/Texinfo/XS/main/get_perl_info.c              |  4 +-
 9 files changed, 258 insertions(+), 2 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 23ca062655..3b2e34299a 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,16 @@
+2024-07-06  Patrice Dumas  <pertusus@free.fr>
+
+       * tp/Texinfo/XS/convert/call_html_perl_function.c
+       (call_stage_handler), tp/Texinfo/XS/convert/convert_html.c
+       (html_stage_handler_stage_type_names, run_stage_handlers),
+       tp/Texinfo/XS/convert/get_html_perl_info.c
+       (html_converter_initialize_sv), tp/Texinfo/XS/main/converter_types.h
+       (enum html_stage_handler_stage_type, HTML_STAGE_HANDLER_INFO)
+       (HTML_STAGE_HANDLER_INFO_LIST, CONVERTER): get stage handlers from
+       Perl and put them in HTML_STAGE_HANDLER_INFO_LIST structure in
+       converter.  Add run_stage_handlers and call_stage_handler to call Perl
+       registered stage handlers references.
+
 2024-07-06  Patrice Dumas  <pertusus@free.fr>
 
        * tp/Texinfo/XS/main/utils.h, tp/Texinfo/XS/convert/convert_html.h:
diff --git a/tp/Texinfo/XS/convert/build_html_perl_state.c 
b/tp/Texinfo/XS/convert/build_html_perl_state.c
index 148e1f6b9a..1c8531ffbd 100644
--- a/tp/Texinfo/XS/convert/build_html_perl_state.c
+++ b/tp/Texinfo/XS/convert/build_html_perl_state.c
@@ -45,6 +45,7 @@
 #include "build_perl_info.h"
 /* for NAMED_STRING_ELEMENT_LIST */
 #include "translations.h"
+/* also for html_argument_formatting_type_names */
 #include "convert_html.h"
 #include "build_html_perl_state.h"
 
diff --git a/tp/Texinfo/XS/convert/call_html_perl_function.c 
b/tp/Texinfo/XS/convert/call_html_perl_function.c
index e00680e497..0039e996e7 100644
--- a/tp/Texinfo/XS/convert/call_html_perl_function.c
+++ b/tp/Texinfo/XS/convert/call_html_perl_function.c
@@ -2451,6 +2451,65 @@ call_latex_convert_to_latex_math (CONVERTER *self, const 
ELEMENT *element)
   return result;
 }
 
+int
+call_stage_handler (CONVERTER *self, void *stage_handler_sv,
+                    const char *stage_name)
+{
+  int count;
+  SV *document_sv = 0;
+  SV *result_sv;
+  int status;
+
+  dTHX;
+
+  if (self->document)
+    {
+      SV **document_ref_sv = hv_fetch (self->hv, "document",
+                                       strlen ("document"), 0);
+      if (document_ref_sv && *document_ref_sv)
+        {
+          document_sv = *document_ref_sv;
+          SvREFCNT_inc (document_sv);
+        }
+    }
+
+  if (!document_sv)
+    document_sv = newSV (0);
+
+  dSP;
+
+  ENTER;
+  SAVETMPS;
+
+  PUSHMARK(SP);
+  EXTEND(SP, 3);
+
+  PUSHs(sv_2mortal (newRV_inc (self->hv)));
+  PUSHs(sv_2mortal (document_sv));
+  PUSHs(sv_2mortal (newSVpv (stage_name, 0)));
+
+  PUTBACK;
+
+  count = call_sv ((SV *) stage_handler_sv,
+                   G_SCALAR);
+
+  SPAGAIN;
+
+  if (count != 1)
+    croak ("call_stage_handler should return 1 item\n");
+
+
+  result_sv = POPs;
+  status = (int) SvIV (result_sv);
+
+  PUTBACK;
+
+  FREETMPS;
+  LEAVE;
+
+  return status;
+}
+
 
 /* Interface with Perl hash map for registered ids */
 
diff --git a/tp/Texinfo/XS/convert/call_html_perl_function.h 
b/tp/Texinfo/XS/convert/call_html_perl_function.h
index 9fc9545115..614b57e923 100644
--- a/tp/Texinfo/XS/convert/call_html_perl_function.h
+++ b/tp/Texinfo/XS/convert/call_html_perl_function.h
@@ -148,6 +148,8 @@ FORMATTED_BUTTON_INFO *call_button_direction_function 
(CONVERTER *self,
                              void *formatting_reference_sv,
                              int direction, const ELEMENT *element);
 
+int call_stage_handler (CONVERTER *self, void *stage_handler_sv,
+                        const char *stage_name);
 
 char *call_latex_convert_to_latex_math (CONVERTER *self,
                                         const ELEMENT *element);
diff --git a/tp/Texinfo/XS/convert/convert_html.c 
b/tp/Texinfo/XS/convert/convert_html.c
index e0f78eab02..b9d9ba4613 100644
--- a/tp/Texinfo/XS/convert/convert_html.c
+++ b/tp/Texinfo/XS/convert/convert_html.c
@@ -150,6 +150,12 @@ const char *html_argument_formatting_type_names[] = {
   #undef html_aft_type
 };
 
+const char *html_stage_handler_stage_type_names[] = {
+  #define html_hsht_type(name) #name,
+   HTML_STAGE_HANDLER_STAGE_TYPE
+  #undef html_hsht_type
+};
+
 const char *special_unit_info_type_names[SUI_type_heading + 1] =
 {
   #define sui_type(name) #name,
@@ -2281,6 +2287,60 @@ set_root_commands_targets_node_files (CONVERTER *self)
     }
 }
 
+int
+run_stage_handlers (CONVERTER *self, enum html_stage_handler_stage_type stage)
+{
+  size_t i;
+  HTML_STAGE_HANDLER_INFO_LIST *stage_handlers
+    = &self->html_stage_handlers[stage];
+
+  if (stage_handlers->number > 0)
+    {
+      const char *stage_name = html_stage_handler_stage_type_names[stage];
+
+      for (i = 0; i < stage_handlers->number; i++)
+        {
+          int call_status;
+          HTML_STAGE_HANDLER_INFO *stage_handler
+            = &stage_handlers->list[i];
+
+          if (self->conf->DEBUG.o.integer > 0)
+            fprintf (stderr, "RUN handler %zu: stage %s, priority %s\n",
+                     i +1, stage_name, stage_handler->priority);
+
+          if (stage_handler->sv)
+            {
+              call_status = call_stage_handler (self, stage_handler->sv,
+                                                stage_name);
+              if (call_status != 0)
+                {
+                  if (call_status < 0)
+                    {
+                      message_list_document_error (&self->error_messages,
+                                                   self->conf, 0,
+                              "handler %d of stage %s priority %s failed",
+                              (int) i+1, stage_name, stage_handler->priority);
+                    }
+                  else
+                    {
+                   /* the handler is supposed to have output an error message
+                      already if $status > 0 */
+                      if (self->conf->DEBUG.o.integer > 0
+                          || self->conf->VERBOSE.o.integer > 0)
+                        {
+                          fprintf (stderr,
+                                   "FAIL handler %zu: stage %s, priority %s\n",
+                                   i +1, stage_name, stage_handler->priority);
+                        }
+                    }
+                  return call_status;
+                }
+            }
+        }
+    }
+  return 0;
+}
+
 /* to be inlined in text parsing codes */
 #define OTXI_PROTECT_XML_FORM_FEED_CASES(var) \
         OTXI_PROTECT_XML_CASES(var) \
diff --git a/tp/Texinfo/XS/convert/convert_html.h 
b/tp/Texinfo/XS/convert/convert_html.h
index 3ff512011c..ab0369d561 100644
--- a/tp/Texinfo/XS/convert/convert_html.h
+++ b/tp/Texinfo/XS/convert/convert_html.h
@@ -37,6 +37,8 @@ extern const char *direction_string_context_names[];
 
 extern const char *count_elements_in_filename_type_names[];
 
+extern const char *html_stage_handler_stage_type_names[];
+
 void html_format_init (void);
 
 void html_converter_initialize (CONVERTER *self);
diff --git a/tp/Texinfo/XS/convert/get_html_perl_info.c 
b/tp/Texinfo/XS/convert/get_html_perl_info.c
index 06c73e3593..3bc30ccfa0 100644
--- a/tp/Texinfo/XS/convert/get_html_perl_info.c
+++ b/tp/Texinfo/XS/convert/get_html_perl_info.c
@@ -152,6 +152,7 @@ html_converter_initialize_sv (SV *converter_sv,
   SV **sorted_special_unit_varieties_sv;
   SV **accent_entities_sv;
   SV **style_commands_formatting_sv;
+  SV **stage_handlers_sv;
   SV **types_open_sv;
   SV **types_conversion_sv;
   SV **commands_open_sv;
@@ -391,6 +392,7 @@ html_converter_initialize_sv (SV *converter_sv,
   memcpy (&converter->css_string_types_conversion,
           &converter->types_conversion,
       (TXI_TREE_TYPES_NUMBER) * sizeof (FORMATTING_REFERENCE));
+
   for (i = 0; i < TXI_TREE_TYPES_NUMBER; i++)
     {
       char *ref_name;
@@ -824,6 +826,97 @@ html_converter_initialize_sv (SV *converter_sv,
         }
     }
 
+  FETCH(stage_handlers)
+
+  if (stage_handlers_sv)
+    {
+      I32 hv_number;
+      I32 i;
+
+      HV *stage_handlers_hv
+        = (HV *)SvRV (*stage_handlers_sv);
+
+      hv_number = hv_iterinit (stage_handlers_hv);
+
+      for (i = 0; i < hv_number; i++)
+        {
+          int j;
+          enum html_stage_handler_stage_type stage = HSHT_type_none;
+          char *stage_name;
+          I32 retlen;
+          SV *stage_sv = hv_iternextsv (stage_handlers_hv,
+                                        &stage_name, &retlen);
+          for (j = 0; j < HSHT_type_finish +1; j++)
+            {
+              if (!strcmp (stage_name, html_stage_handler_stage_type_names[j]))
+                {
+                  stage = j;
+                  break;
+                }
+            }
+          if (stage == HSHT_type_none)
+            {
+              fprintf (stderr, "ERROR: %s: unknown handler stage\n",
+                               stage_name);
+              break;
+            }
+
+          if (SvOK (stage_sv))
+            {
+              size_t k;
+              AV *stage_av = (AV *)SvRV (stage_sv);
+              HTML_STAGE_HANDLER_INFO_LIST *stage_handler_list
+                = &converter->html_stage_handlers[stage];
+              SSize_t stage_handlers_info_nr = av_top_index (stage_av) +1;
+
+              stage_handler_list->number = stage_handlers_info_nr;
+              stage_handler_list->list = (HTML_STAGE_HANDLER_INFO *)
+                 malloc (sizeof (HTML_STAGE_HANDLER_INFO)
+                                                  * stage_handlers_info_nr);
+
+              for (k = 0; k < stage_handlers_info_nr; k++)
+                {
+                  HTML_STAGE_HANDLER_INFO *handler_info
+                        = &stage_handler_list->list[k];
+                  SV **stage_info_sv = av_fetch (stage_av, k, 0);
+                  memset (handler_info, 0, sizeof (HTML_STAGE_HANDLER_INFO));
+
+                  if (stage_info_sv && SvOK (*stage_info_sv))
+                    {
+                      AV *stage_info_av = (AV *)SvRV (*stage_info_sv);
+                      SV **handler_sv;
+                      SV **priority_sv;
+
+                      SSize_t stage_info_nr = av_top_index (stage_info_av) +1;
+                      if (stage_info_nr != 2)
+                        {
+                          fprintf (stderr,
+                            "BUG: %s: %zu: stage handler info need 2 item: 
%zu\n",
+                                   stage_name, k, stage_info_nr);
+                          continue;
+                        }
+                      handler_sv = av_fetch (stage_info_av, 0, 0);
+                      if (handler_sv && SvOK (*handler_sv))
+                        {
+                          handler_info->sv = *handler_sv;
+                        }
+                      priority_sv = av_fetch (stage_info_av, 1, 0);
+                      if (priority_sv && SvOK (*priority_sv))
+                        {
+                          const char *priority
+                            = (char *) SvPVutf8_nolen (*priority_sv);
+                          handler_info->priority = non_perl_strdup (priority);
+                        }
+                       /*
+                      fprintf (stderr, "REGISTER handler %s: %s %p\n", 
stage_name,
+                               handler_info->priority, handler_info->sv);
+                        */
+                    }
+                }
+            }
+        }
+    }
+
   html_converter_initialize (converter);
 
   /* at that point, the format specific informations, in particular the number
diff --git a/tp/Texinfo/XS/main/converter_types.h 
b/tp/Texinfo/XS/main/converter_types.h
index de889205fd..2667dad13c 100644
--- a/tp/Texinfo/XS/main/converter_types.h
+++ b/tp/Texinfo/XS/main/converter_types.h
@@ -219,6 +219,20 @@ enum htmlxref_split_type {
    htmlxref_split_type_chapter,
 };
 
+#define HTML_STAGE_HANDLER_STAGE_TYPE \
+  html_hsht_type(setup) \
+  html_hsht_type(structure) \
+  html_hsht_type(init) \
+  html_hsht_type(finish)
+
+enum html_stage_handler_stage_type {
+   HSHT_type_none = -1,
+
+   #define html_hsht_type(name) HSHT_type_##name,
+    HTML_STAGE_HANDLER_STAGE_TYPE
+   #undef html_hsht_type
+};
+
 typedef struct {
     enum command_id *stack;
     size_t top;   /* One above last pushed command. */
@@ -713,6 +727,17 @@ typedef struct FILE_ASSOCIATED_INFO_LIST {
     FILE_ASSOCIATED_INFO *list;
 } FILE_ASSOCIATED_INFO_LIST;
 
+typedef struct HTML_STAGE_HANDLER_INFO {
+    /* Perl function reference */
+    void *sv;
+    char *priority;
+} HTML_STAGE_HANDLER_INFO;
+
+typedef struct HTML_STAGE_HANDLER_INFO_LIST {
+    size_t number;
+    HTML_STAGE_HANDLER_INFO *list;
+} HTML_STAGE_HANDLER_INFO_LIST;
+
 typedef struct CONVERTER {
     int converter_descriptor;
   /* perl converter. This should be HV *hv,
@@ -789,6 +814,7 @@ typedef struct CONVERTER {
     OUTPUT_UNIT_CONVERSION_FUNCTION 
output_unit_conversion_function[OU_special_unit+1];
     SPECIAL_UNIT_BODY_FORMATTING *special_unit_body_formatting;
     HTML_DIRECTION_STRING_TRANSLATED 
*translated_direction_strings[TDS_TRANSLATED_MAX_NR];
+    HTML_STAGE_HANDLER_INFO_LIST html_stage_handlers[HSHT_type_finish +1];
     /* set for a converter, modified in a document */
     HTML_COMMAND_CONVERSION 
html_command_conversion[BUILTIN_CMD_NUMBER][HCC_type_css_string+1];
     char ***directions_strings[TDS_TYPE_MAX_NR];
diff --git a/tp/Texinfo/XS/main/get_perl_info.c 
b/tp/Texinfo/XS/main/get_perl_info.c
index 702a47cce7..82d8f99635 100644
--- a/tp/Texinfo/XS/main/get_perl_info.c
+++ b/tp/Texinfo/XS/main/get_perl_info.c
@@ -281,7 +281,7 @@ void
 add_svav_to_string_list (const SV *sv, STRING_LIST *string_list,
                          enum sv_string_type type)
 {
-  int i;
+  size_t i;
   SSize_t strings_nr;
 
   dTHX;
@@ -293,7 +293,7 @@ add_svav_to_string_list (const SV *sv, STRING_LIST 
*string_list,
   strings_nr = av_top_index (av) +1;
   for (i = 0; i < strings_nr; i++)
     {
-      SV** string_sv = av_fetch (av, i, 0);
+      SV **string_sv = av_fetch (av, i, 0);
       if (string_sv)
         {
           const char *string;



reply via email to

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