texinfo-commits
[Top][All Lists]
Advanced

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

[no subject]


From: Patrice Dumas
Date: Fri, 27 Oct 2023 12:57:48 -0400 (EDT)

branch: master
commit 5fd083b102f188c79d3ba91c1dd2e8069e37826b
Author: Patrice Dumas <pertusus@free.fr>
AuthorDate: Fri Oct 27 18:35:08 2023 +0200

    * tp/Texinfo/Convert/HTML.pm (import): load conversion overrides only
    if TEXINFO_XS_CONVERT is set.
    
    * tp/Texinfo/Convert/HTML.pm (convert): return result with XS such
    that there is no double conversion.
---
 ChangeLog                          |  8 ++++
 tp/Texinfo/Convert/HTML.pm         | 26 +++++++------
 tp/Texinfo/XS/main/command_stack.c | 80 ++++++++++++++++++++++++++++++++++++++
 tp/Texinfo/XS/main/command_stack.h | 35 +++++++++++++++++
 4 files changed, 138 insertions(+), 11 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 67f4c11d3f..7afe0d0c36 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2023-10-27  Patrice Dumas  <pertusus@free.fr>
+
+       * tp/Texinfo/Convert/HTML.pm (import): load conversion overrides only
+       if TEXINFO_XS_CONVERT is set.
+
+       * tp/Texinfo/Convert/HTML.pm (convert): return result with XS such
+       that there is no double conversion.
+
 2023-10-25  Patrice Dumas  <pertusus@free.fr>
 
        * tp/t/test_tree_copy.t: skip copy_tree call if with XS as there is no
diff --git a/tp/Texinfo/Convert/HTML.pm b/tp/Texinfo/Convert/HTML.pm
index 1099187716..bdd495e48d 100644
--- a/tp/Texinfo/Convert/HTML.pm
+++ b/tp/Texinfo/Convert/HTML.pm
@@ -94,36 +94,40 @@ sub import {
       "Texinfo::Convert::HTML::_entity_text",
       "Texinfo::MiscXS::entity_text");
 
-    Texinfo::XSLoader::override(
+    if (defined $ENV{TEXINFO_XS_CONVERT}
+        and $ENV{TEXINFO_XS_CONVERT} eq '1') {
+
+      Texinfo::XSLoader::override(
       "Texinfo::Convert::HTML::_XS_converter_initialize",
       "Texinfo::Convert::ConvertXS::html_converter_initialize_sv");
-    Texinfo::XSLoader::override(
+      Texinfo::XSLoader::override(
       "Texinfo::Convert::HTML::_XS_initialize_output_state",
       "Texinfo::Convert::ConvertXS::html_initialize_output_state");
-    Texinfo::XSLoader::override(
+      Texinfo::XSLoader::override(
       "Texinfo::Convert::HTML::_XS_sort_sortable_index_entries_by_letter",
       "Texinfo::Convert::ConvertXS::sort_sortable_index_entries_by_letter");
-    Texinfo::XSLoader::override(
+      Texinfo::XSLoader::override(
       "Texinfo::Convert::HTML::_XS_get_index_entries_sorted_by_letter",
       "Texinfo::Convert::ConvertXS::get_index_entries_sorted_by_letter");
-    Texinfo::XSLoader::override(
+      Texinfo::XSLoader::override(
       "Texinfo::Convert::HTML::_XS_prepare_conversion_units",
       "Texinfo::Convert::ConvertXS::html_prepare_conversion_units");
-    Texinfo::XSLoader::override(
+      Texinfo::XSLoader::override(
       "Texinfo::Convert::HTML::_XS_prepare_units_directions_files",
       "Texinfo::Convert::ConvertXS::html_prepare_units_directions_files");
-    Texinfo::XSLoader::override(
+      Texinfo::XSLoader::override(
       "Texinfo::Convert::HTML::_XS_prepare_output_units_global_targets",
       "Texinfo::Convert::ConvertXS::html_prepare_output_units_global_targets");
-    Texinfo::XSLoader::override(
+      Texinfo::XSLoader::override(
       "Texinfo::Convert::HTML::_XS_translate_names",
       "Texinfo::Convert::ConvertXS::html_translate_names");
-    Texinfo::XSLoader::override(
+      Texinfo::XSLoader::override(
       "Texinfo::Convert::HTML::_XS_html_convert_init",
       "Texinfo::Convert::ConvertXS::html_convert_init");
-    Texinfo::XSLoader::override(
+      Texinfo::XSLoader::override(
       "Texinfo::Convert::HTML::_XS_html_convert_convert",
       "Texinfo::Convert::ConvertXS::html_convert_convert");
+    }
 
     $module_loaded = 1;
   }
@@ -7535,7 +7539,6 @@ sub _new_document_context($;$$)
           {'context' => $context,
            'formatting_context' => [{'context_name' => $context}],
            'composition_context' => [''],
-           'formats' => [],
            'monospace' => [0],
            'document_global_context' => $document_global_context,
            'block_commands' => [],
@@ -11117,6 +11120,7 @@ sub convert($$)
   if ($self->{'converter_descriptor'}) {
     my $XS_result = _XS_html_convert_convert ($encoded_converter, $root,
                                               $output_units, $special_units);
+    return $XS_result;
   }
 
   if (!defined($output_units)) {
diff --git a/tp/Texinfo/XS/main/command_stack.c 
b/tp/Texinfo/XS/main/command_stack.c
new file mode 100644
index 0000000000..478167aa66
--- /dev/null
+++ b/tp/Texinfo/XS/main/command_stack.c
@@ -0,0 +1,80 @@
+/* Copyright 2010-2023 Free Software Foundation, Inc.
+
+   This program is free software: you can redistribute it and/or modify
+   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
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>. */
+
+#include <config.h>
+#include <stdlib.h>
+
+#include "tree_types.h"
+#include "command_ids.h"
+#include "utils.h"
+#include "command_stack.h"
+
+/* Generic command stack functions */
+
+void
+reset_command_stack (COMMAND_STACK *stack)
+{
+  stack->top = 0;
+  stack->space = 0;
+  free (stack->stack);
+  stack->stack = 0;
+}
+
+void
+push_command (COMMAND_STACK *stack, enum command_id cmd)
+{
+  if (stack->top >= stack->space)
+    {
+      stack->stack
+        = realloc (stack->stack,
+                   (stack->space += 5) * sizeof (enum command_id));
+    }
+
+  stack->stack[stack->top] = cmd;
+  stack->top++;
+}
+
+enum command_id
+pop_command (COMMAND_STACK *stack)
+{
+  if (stack->top == 0)
+    fatal ("command stack empty");
+
+  return stack->stack[--stack->top];
+}
+
+enum command_id
+top_command (COMMAND_STACK *stack)
+{
+  if (stack->top == 0)
+    fatal ("command stack empty for top");
+
+  return stack->stack[stack->top - 1];
+}
+
+enum command_id
+current_context_command (void)
+{
+  int i;
+
+  if (top == 0)
+    return CM_NONE;
+  for (i = top -1; i >= 0; i--)
+    {
+      if (command_stack.stack[i] != CM_NONE)
+        return command_stack.stack[i];
+    }
+  return CM_NONE;
+}
diff --git a/tp/Texinfo/XS/main/command_stack.h 
b/tp/Texinfo/XS/main/command_stack.h
new file mode 100644
index 0000000000..f9e5287c57
--- /dev/null
+++ b/tp/Texinfo/XS/main/command_stack.h
@@ -0,0 +1,35 @@
+/* command_stack.h - declarations for command_stack.c */
+#ifndef COMMAND_STACK_H
+#define COMMAND_STACK_H
+/* Copyright 2010-2023 Free Software Foundation, Inc.
+
+   This program is free software: you can redistribute it and/or modify
+   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
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>. */
+
+#include <stddef.h>
+
+#include "tree_types.h"
+
+typedef struct {
+    enum command_id *stack;
+    size_t top;   /* One above last pushed context. */
+    size_t space;
+} COMMAND_STACK;
+
+void reset_command_stack (COMMAND_STACK *stack);
+void push_command (COMMAND_STACK *stack, enum command_id cmd);
+enum command_id pop_command (COMMAND_STACK *stack);
+enum command_id top_command (COMMAND_STACK *stack);
+enum command_id current_context_command (void);
+
+#endif



reply via email to

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