texinfo-commits
[Top][All Lists]
Advanced

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

[no subject]


From: Patrice Dumas
Date: Tue, 1 Oct 2024 11:57:57 -0400 (EDT)

branch: master
commit e2790094bf1e0daa6912b62562ca140ed6dbef30
Author: Patrice Dumas <pertusus@free.fr>
AuthorDate: Wed Jul 24 17:16:00 2024 +0200

    XS override for HTML::output
    
    * tp/Texinfo/XS/convert/convert_html.c (do_jslicenses_file): remove a
    spurious end of line.
    
    * tp/Texinfo/XS/convert/convert_html.c (html_do_js_files): rename
    do_js_files as html_do_js_files.
    
    * tp/Texinfo/XS/convert/convert_html.c (html_finish_output): add.
    
    * tp/Texinfo/Convert/HTML.pm (%XS_overrides),
    tp/Texinfo/XS/convert/ConvertXS.xs (html_output): add an XS override
    for output.
---
 ChangeLog                            |  16 +++++
 tp/TODO                              |   2 +
 tp/Texinfo/Convert/HTML.pm           |   7 +-
 tp/Texinfo/XS/convert/ConvertXS.xs   | 128 ++++++++++++++++++++++++++++++++++-
 tp/Texinfo/XS/convert/convert_html.c |  31 ++++++++-
 tp/Texinfo/XS/convert/convert_html.h |   5 ++
 6 files changed, 183 insertions(+), 6 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 7aa354c405..fa28e923bc 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -5,6 +5,22 @@
        (call_formatting_function_format_single_footnote): check and reset
        flags in build_html_formatting_state.
 
+2024-07-24  Patrice Dumas  <pertusus@free.fr>
+
+       XS override for HTML::output
+
+       * tp/Texinfo/XS/convert/convert_html.c (do_jslicenses_file): remove a
+       spurious end of line.
+
+       * tp/Texinfo/XS/convert/convert_html.c (html_do_js_files): rename
+       do_js_files as html_do_js_files.
+
+       * tp/Texinfo/XS/convert/convert_html.c (html_finish_output): add.
+
+       * tp/Texinfo/Convert/HTML.pm (%XS_overrides),
+       tp/Texinfo/XS/convert/ConvertXS.xs (html_output): add an XS override
+       for output.
+
 2024-07-24  Patrice Dumas  <pertusus@free.fr>
 
        * tp/Texinfo/XS/convert/ConvertXS.xs (html_prepare_conversion_units),
diff --git a/tp/TODO b/tp/TODO
index 3cdcbd0130..c5e1a4b162 100644
--- a/tp/TODO
+++ b/tp/TODO
@@ -852,6 +852,8 @@ valgrind --tool=callgrind perl -w texi2any.pl 
../doc/texinfo.texi --html
 valgrind --tool=callgrind --separate-callers=3 --separate-recs=10 perl -w 
texi2any.pl ../doc/texinfo.texi --html
 kcachegrind callgrind.out.XXXXXX
 
+This is obsolete with output overriding, although the distribution changed
+very little after reattributing the shares.
 For the Texinfo manual with full XS, in 2024, Perl uses 22% of the time
 (for html), now only for code hopefully called once.  The switch to
 global locales for setlocale calling that is needed for Perl takes also 4%.
diff --git a/tp/Texinfo/Convert/HTML.pm b/tp/Texinfo/Convert/HTML.pm
index d7f3b32faf..2df83c2d88 100644
--- a/tp/Texinfo/Convert/HTML.pm
+++ b/tp/Texinfo/Convert/HTML.pm
@@ -101,6 +101,10 @@ my %XS_overrides = (
 );
 
 my %XS_conversion_overrides = (
+  "Texinfo::Convert::HTML::output"
+   => "Texinfo::Convert::ConvertXS::html_output",
+
+  # following are not called when output and convert are overriden
   "Texinfo::Convert::HTML::_XS_format_setup"
    => "Texinfo::Convert::ConvertXS::html_format_setup",
   "Texinfo::Convert::HTML::_XS_html_converter_initialize"
@@ -13526,8 +13530,7 @@ sub _finish_output($$$$)
     return 0;
   }
 
-  # undef status means an error occured, we should return immediately after
-  # calling $self->conversion_finalization() in that case.
+  # undef status means an error occured
   my $node_redirections_status = _node_redirections($self, $output_file,
                                $destination_directory, $files_source_info);
 
diff --git a/tp/Texinfo/XS/convert/ConvertXS.xs 
b/tp/Texinfo/XS/convert/ConvertXS.xs
index 65d2575192..1974478ad5 100644
--- a/tp/Texinfo/XS/convert/ConvertXS.xs
+++ b/tp/Texinfo/XS/convert/ConvertXS.xs
@@ -659,8 +659,132 @@ html_conversion_finalization (SV *converter_in)
              html_check_transfer_state_finalization (self);
            }
 
-#void
-#html_output (SV *converter_in, SV *document_id)
+SV *
+html_output (SV *converter_in, SV *document_in)
+      PREINIT:
+        CONVERTER *self;
+        char *paths[5];
+        int status;
+        char *result = 0;
+        int i;
+        const char *output_file;
+        const char *destination_directory;
+        const char *output_filename;
+        const char *document_name;
+        SV *output_units_sv;
+        SV *special_units_sv;
+        SV *associated_special_units_sv;
+      CODE:
+        /* html_conversion_initialization */
+        self = converter_set_document_from_sv (converter_in, document_in);
+
+        html_initialize_output_state (self, "_output");
+        /* could be useful if something from Perl is needed
+        html_conversion_initialization_sv (converter_in, self);
+         */
+
+        html_pass_conversion_initialization (self, converter_in, document_in);
+
+        /* html_setup_output */
+        status = html_setup_output (self, paths);
+        if (!status)
+          {
+            memset (paths, 0, 5 * sizeof (char *));
+            goto finalization;
+          }
+
+        html_pass_converter_setup_state (self, converter_in);
+
+        output_file = paths[0];
+        destination_directory = paths[1];
+        output_filename = paths[2];
+        document_name = paths[3];
+
+        /* html_prepare_conversion_units */
+        html_prepare_conversion_units (self);
+
+        html_pass_conversion_output_units (self, converter_in,
+                                     &output_units_sv, &special_units_sv,
+                                     &associated_special_units_sv);
+
+        /* calls Perl customization functions, so need to be done after
+            build_output_units_list calls to be able to retrieve Perl
+            output units references */
+        html_prepare_conversion_units_targets (self, self->document_name);
+
+        /* html_translate_names */
+        html_translate_names (self);
+        build_html_formatting_state (self);
+
+        /* html_prepare_units_directions_files */
+        html_prepare_units_directions_files (self,
+                   output_file, destination_directory, output_filename,
+                                document_name);
+
+        html_pass_units_directions_files (self, converter_in, output_units_sv,
+                                          special_units_sv,
+                                          associated_special_units_sv);
+
+        /* html_prepare_converted_output_info */
+        status = html_prepare_converted_output_info (self, output_file,
+                                                     output_filename);
+
+        if (!status)
+          goto finalization;
+
+        /* html_convert_output */
+        if (self->document)
+          {
+            result = html_convert_output (self, self->document->tree,
+                        output_file, destination_directory, output_filename,
+                        document_name);
+
+            build_html_formatting_state (self);
+
+            build_output_files_information (converter_in,
+                                            &self->output_files_information);
+          }
+
+        if (!result)
+          goto finalization;
+
+        if (strlen (result) && !strlen (output_file))
+          {
+            if (self->conf->TEST.o.integer <= 0 )
+              {
+    /* This case is unlikely to happen, as there is no output file
+       only if formatting is called as convert, which only happens in tests.
+     */
+                html_do_js_files (self);
+              }
+            goto finalization;
+          }
+
+        /* output to a file only */
+        free (result);
+        result = 0;
+
+        status = html_finish_output (self, output_file, destination_directory);
+
+      finalization:
+        for (i = 0; i < 5; i++)
+          {
+            free (paths[i]);
+          }
+        /* html_conversion_finalization */
+        html_conversion_finalization (self);
+
+        html_check_transfer_state_finalization (self);
+
+        if (result)
+          {
+            RETVAL = newSVpv_utf8 (result, 0);
+            free (result);
+          }
+        else
+          RETVAL = newSV (0);
+    OUTPUT:
+        RETVAL
 
 
 void
diff --git a/tp/Texinfo/XS/convert/convert_html.c 
b/tp/Texinfo/XS/convert/convert_html.c
index b27bc86f4d..fc63d7a4db 100644
--- a/tp/Texinfo/XS/convert/convert_html.c
+++ b/tp/Texinfo/XS/convert/convert_html.c
@@ -20803,7 +20803,7 @@ do_jslicenses_file (CONVERTER *self)
     = root_html_element_attributes_string (self);
   if (!root_html_element_attributes)
     root_html_element_attributes = strdup ("");
-  text_printf (&result, "<html%s>\n", root_html_element_attributes);
+  text_printf (&result, "<html%s>", root_html_element_attributes);
   free (root_html_element_attributes);
   text_append (&result, "<head><title>jslicense labels</title></head>\n"
  "<body>\n"
@@ -20893,7 +20893,7 @@ do_jslicenses_file (CONVERTER *self)
 static const char *js_files[4] = {"info.js", "modernizr.js", "info.css", 0};
 
 void
-do_js_files (CONVERTER *self)
+html_do_js_files (CONVERTER *self)
 {
   const char *destination_directory = self->destination_directory;
 
@@ -21445,3 +21445,30 @@ html_node_redirections (CONVERTER *self,
 
   return redirection_files_done;
 }
+
+int
+html_finish_output (CONVERTER *self, const char *output_file,
+                    const char *destination_directory)
+{
+  int finish_handler_status;
+  int handler_fatal_error_level
+     = self->conf->HANDLER_FATAL_ERROR_LEVEL.o.integer;
+  int node_redirections_status;
+
+  html_do_js_files (self);
+
+  finish_handler_status = run_stage_handlers (self, HSHT_type_finish);
+
+  if (finish_handler_status < handler_fatal_error_level
+      && finish_handler_status > -handler_fatal_error_level)
+    {}
+  else
+    return 0;
+
+  node_redirections_status = html_node_redirections (self, output_file,
+                                                     destination_directory);
+  if (node_redirections_status < 0)
+    return 0;
+
+  return 1;
+}
diff --git a/tp/Texinfo/XS/convert/convert_html.h 
b/tp/Texinfo/XS/convert/convert_html.h
index b85af597b4..38e51e4309 100644
--- a/tp/Texinfo/XS/convert/convert_html.h
+++ b/tp/Texinfo/XS/convert/convert_html.h
@@ -247,12 +247,17 @@ char *html_convert_output (CONVERTER *self, const ELEMENT 
*root,
                            const char *output_filename,
                            const char *document_name);
 
+void html_do_js_files (CONVERTER *self);
+
 char *html_prepare_node_redirection_page (CONVERTER *self,
                                           const ELEMENT *element,
                                           const char *filename);
 int html_node_redirections (CONVERTER *self,
             const char *output_file, const char *destination_directory);
 
+int html_finish_output (CONVERTER *self, const char *output_file,
+                        const char *destination_directory);
+
 void html_check_transfer_state_finalization (CONVERTER *self);
 void html_free_converter (CONVERTER *self);
 void html_reset_converter (CONVERTER *self);



reply via email to

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