texinfo-commits
[Top][All Lists]
Advanced

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

branch master updated: * tp/Texinfo/XS/Makefile.am (libtexinfo_la_SOURCE


From: Patrice Dumas
Subject: branch master updated: * tp/Texinfo/XS/Makefile.am (libtexinfo_la_SOURCES), tp/Texinfo/XS/main/converter_types.h: move definitions of types related to document and converter to a separate file, converter_types.h, to avoid issues with include order.
Date: Sun, 29 Oct 2023 16:37:47 -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 4937f5bd33 * tp/Texinfo/XS/Makefile.am (libtexinfo_la_SOURCES), 
tp/Texinfo/XS/main/converter_types.h: move definitions of types related to 
document and converter to a separate file, converter_types.h, to avoid issues 
with include order.
4937f5bd33 is described below

commit 4937f5bd333609b4533d801afe3ddcb72f629fa8
Author: Patrice Dumas <pertusus@free.fr>
AuthorDate: Sun Oct 29 21:35:25 2023 +0100

    * tp/Texinfo/XS/Makefile.am (libtexinfo_la_SOURCES),
    tp/Texinfo/XS/main/converter_types.h: move definitions of types
    related to document and converter to a separate file,
    converter_types.h, to avoid issues with include order.
    
    * tp/Texinfo/XS/main/command_stack.c (top_html_formatting_context)
    (top_document_context), tp/Texinfo/XS/convert/convert_html.c: move
    top_html_formatting_context and top_document_context out of
    convert_html.c to tp/Texinfo/XS/main/command_stack.c.
    
    * tp/Texinfo/XS/convert/ConvertXS.xs (html_translate_names)
    (html_convert_convert), tp/Texinfo/XS/convert/convert_html.c
    (html_new_document_context, html_pop_document_context)
    (convert_tree_new_formatting_context, convert_to_html_internal)
    (convert_output_unit), tp/Texinfo/XS/main/build_perl_info.c
    (build_html_formatting_context_ctx, build_html_formatting_context)
    (build_html_document_context, build_html_formatting_context_stack)
    (build_html_composition_context_stack)
    (build_html_preformatted_classes_stack, build_html_monospace_stack)
    (build_html_block_commands_stack, build_html_document_context_ctx)
    (build_html_formatting_state), tp/Texinfo/XS/main/call_perl_function.c
    (call_types_conversion, call_types_open, call_commands_conversion)
    (call_commands_open): use modified_state to hold information on the
    state that needs to be reset before calling perl code, using flags
    with name HMSF_*. Add the flags variable as argument of
    build_html_formatting_state. Add functions for more fine grained
    rebuilt of formatting state.
---
 ChangeLog                                          |  30 ++
 tp/TODO                                            |   5 -
 tp/Texinfo/XS/Makefile.am                          |   1 +
 tp/Texinfo/XS/convert/ConvertXS.xs                 |   4 +-
 tp/Texinfo/XS/convert/convert_html.c               | 157 ++++----
 tp/Texinfo/XS/main/build_perl_info.c               | 404 ++++++++++++++------
 tp/Texinfo/XS/main/build_perl_info.h               |   2 +-
 tp/Texinfo/XS/main/call_perl_function.c            |  10 +-
 tp/Texinfo/XS/main/command_stack.c                 |  21 ++
 tp/Texinfo/XS/main/command_stack.h                 |  51 +--
 tp/Texinfo/XS/main/convert_to_text.h               |   2 +-
 tp/Texinfo/XS/main/convert_utils.h                 |   1 +
 tp/Texinfo/XS/main/{utils.h => converter_types.h}  | 420 +++++----------------
 tp/Texinfo/XS/main/document.h                      |  22 +-
 tp/Texinfo/XS/main/errors.c                        |   1 +
 tp/Texinfo/XS/main/errors.h                        |   1 +
 tp/Texinfo/XS/main/utils.h                         | 339 +----------------
 .../XS/structuring_transfo/transformations.c       |   1 +
 18 files changed, 555 insertions(+), 917 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 7c4e83705a..3cafa9a9e1 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -38,6 +38,36 @@
        * info/infomap.c (DOT_INFOKEY_FILE): Provide definition with
        leading period.
 
+2023-10-29  Patrice Dumas  <pertusus@free.fr>
+
+       * tp/Texinfo/XS/Makefile.am (libtexinfo_la_SOURCES),
+       tp/Texinfo/XS/main/converter_types.h: move definitions of types
+       related to document and converter to a separate file,
+       converter_types.h, to avoid issues with include order.
+
+       * tp/Texinfo/XS/main/command_stack.c (top_html_formatting_context)
+       (top_document_context), tp/Texinfo/XS/convert/convert_html.c: move
+       top_html_formatting_context and top_document_context out of
+       convert_html.c to tp/Texinfo/XS/main/command_stack.c.
+
+       * tp/Texinfo/XS/convert/ConvertXS.xs (html_translate_names)
+       (html_convert_convert), tp/Texinfo/XS/convert/convert_html.c
+       (html_new_document_context, html_pop_document_context)
+       (convert_tree_new_formatting_context, convert_to_html_internal)
+       (convert_output_unit), tp/Texinfo/XS/main/build_perl_info.c
+       (build_html_formatting_context_ctx, build_html_formatting_context)
+       (build_html_document_context, build_html_formatting_context_stack)
+       (build_html_composition_context_stack)
+       (build_html_preformatted_classes_stack, build_html_monospace_stack)
+       (build_html_block_commands_stack, build_html_document_context_ctx)
+       (build_html_formatting_state), tp/Texinfo/XS/main/call_perl_function.c
+       (call_types_conversion, call_types_open, call_commands_conversion)
+       (call_commands_open): use modified_state to hold information on the
+       state that needs to be reset before calling perl code, using flags
+       with name HMSF_*. Add the flags variable as argument of
+       build_html_formatting_state. Add functions for more fine grained
+       rebuilt of formatting state.
+
 2023-10-29  Patrice Dumas  <pertusus@free.fr>
 
        Regular tree structure for @value with flag not found
diff --git a/tp/TODO b/tp/TODO
index e8dbab44e0..bd437824cb 100644
--- a/tp/TODO
+++ b/tp/TODO
@@ -28,11 +28,6 @@ Document that Texinfo::Structuring::rebuild_document or
 Texinfo::Structuring::rebuild_tree should be called after tree modifications
 if the parser is XS but converters are perl.
 
-More fine grained determination of what needs to be rebuilt in converter,
-mostly for document and formatting state instead of one indicator
-self->modified_state, could imagine giving the index of the document context
-that needs to be redone or done, or even more fine grained.
-
 the code in _parsed_manual_tree in Pod-Simple-Texinfo/pod2texi.pl
 does not work perfectly with XS.  See FIXME in the code.  Tested in
 ./manual_tests/manual_sectioning_gap_test.sh
diff --git a/tp/Texinfo/XS/Makefile.am b/tp/Texinfo/XS/Makefile.am
index c2cdf4bfcb..d9cc023fff 100644
--- a/tp/Texinfo/XS/Makefile.am
+++ b/tp/Texinfo/XS/Makefile.am
@@ -149,6 +149,7 @@ libtexinfo_la_SOURCES= \
                      main/targets.h \
                      main/utils.c \
                      main/utils.h \
+                     main/converter_types.h \
                      main/unicode.c \
                      main/unicode.h \
                      main/translations.c \
diff --git a/tp/Texinfo/XS/convert/ConvertXS.xs 
b/tp/Texinfo/XS/convert/ConvertXS.xs
index c4caa7c8eb..70dd40c03d 100644
--- a/tp/Texinfo/XS/convert/ConvertXS.xs
+++ b/tp/Texinfo/XS/convert/ConvertXS.xs
@@ -315,7 +315,7 @@ html_translate_names (SV *converter_in)
 
          if (self->modified_state)
            {
-             build_html_formatting_state (self);
+             build_html_formatting_state (self, self->modified_state);
              self->modified_state = 0;
            }
 
@@ -362,7 +362,7 @@ html_convert_convert (SV *converter_in, SV *tree_in, SV 
*output_units_in, SV *sp
                                         special_units_descriptor);
          if (self->modified_state)
            {
-             build_html_formatting_state (self);
+             build_html_formatting_state (self, self->modified_state);
              self->modified_state = 0;
            }
          RETVAL = newSVpv_utf8 (result, 0);
diff --git a/tp/Texinfo/XS/convert/convert_html.c 
b/tp/Texinfo/XS/convert/convert_html.c
index 505dff5ba4..961c4cd05c 100644
--- a/tp/Texinfo/XS/convert/convert_html.c
+++ b/tp/Texinfo/XS/convert/convert_html.c
@@ -21,8 +21,11 @@
 #include "global_commands_types.h"
 #include "tree_types.h"
 #include "element_types.h"
+#include "converter_types.h"
 #include "tree.h"
 #include "builtin_commands.h"
+#include "command_stack.h"
+#include "errors.h"
 #include "utils.h"
 #include "extra.h"
 #include "targets.h"
@@ -2099,15 +2102,6 @@ push_html_formatting_context 
(HTML_FORMATTING_CONTEXT_STACK *stack,
   stack->top++;
 }
 
-static HTML_FORMATTING_CONTEXT *
-top_html_formatting_context (HTML_FORMATTING_CONTEXT_STACK *stack)
-{
-  if (stack->top == 0)
-    fatal ("HTML formatting context stack empty for top");
-
-  return &stack->stack[stack->top - 1];
-}
-
 static void
 pop_html_formatting_context (HTML_FORMATTING_CONTEXT_STACK *stack)
 {
@@ -2135,7 +2129,7 @@ html_new_document_context (CONVERTER *self,
   stack->stack[stack->top].context = strdup (context_name);
   stack->stack[stack->top].document_global_context = document_global_context;
 
-  push_style_no_code (&stack->stack[stack->top].monospace_context);
+  push_style_no_code (&stack->stack[stack->top].monospace);
   push_command_or_type (&stack->stack[stack->top].composition_context,
                         0, 0);
   if (block_command)
@@ -2144,7 +2138,7 @@ html_new_document_context (CONVERTER *self,
   if (document_global_context)
     {
       self->document_global_context++;
-      self->modified_state++;
+      self->modified_state |= HMSF_converter_state;
     }
 
   push_html_formatting_context (&stack->stack[stack->top].formatting_context,
@@ -2165,7 +2159,7 @@ html_pop_document_context (CONVERTER *self)
   document_ctx = &stack->stack[stack->top -1];
 
   free (document_ctx->context);
-  free (document_ctx->monospace_context.stack);
+  free (document_ctx->monospace.stack);
   free (document_ctx->composition_context.stack);
   if (document_ctx->block_commands.top > 0)
     pop_command (&document_ctx->block_commands);
@@ -2176,23 +2170,12 @@ html_pop_document_context (CONVERTER *self)
   if (document_ctx->document_global_context)
     {
       self->document_global_context--;
-      self->modified_state++;
+      self->modified_state |= HMSF_converter_state;
     }
 
   stack->top--;
 }
 
-static HTML_DOCUMENT_CONTEXT *
-top_document_context (CONVERTER *self)
-{
-  HTML_DOCUMENT_CONTEXT_STACK *stack = &self->html_document_context;
-
-  if (stack->top == 0)
-    fatal ("HTML document context stack empty for top");
-
-  return &stack->stack[stack->top - 1];
-}
-
 /* most of the initialization is done by html_converter_initialize_sv
    in get_perl_info, the initialization that do not require information
    from perl is done here */
@@ -2314,12 +2297,14 @@ convert_tree_new_formatting_context (CONVERTER *self, 
ELEMENT *tree,
       html_new_document_context (self, context_string,
                                  document_global_context, block_cmd);
       text_printf (&context_string_str, "C(%s)", context_string);
+      self->modified_state |= HMSF_document_context;
     }
 
   if (multiple_pass)
     {
       self->ignore_notice++;
       push_string_stack_string (&self->multiple_pass, multiple_pass);
+      self->modified_state |= HMSF_multiple_pass | HMSF_converter_state;
       multiple_pass_str = "|M";
     }
 
@@ -2327,7 +2312,6 @@ convert_tree_new_formatting_context (CONVERTER *self, 
ELEMENT *tree,
     fprintf (stderr, "new_fmt_ctx %s%s\n", context_string_str.text,
                                            multiple_pass_str);
 
-  self->modified_state++;
   xasprintf (&explanation, "new_fmt_ctx %s", context_string_str.text);
   result = convert_tree (self, tree, explanation);
 
@@ -2335,16 +2319,18 @@ convert_tree_new_formatting_context (CONVERTER *self, 
ELEMENT *tree,
   free (context_string_str.text);
 
   if (context_string)
-    html_pop_document_context (self);
+    {
+      html_pop_document_context (self);
+      self->modified_state |= HMSF_document_context;
+    }
 
   if (multiple_pass)
     {
-      self->ignore_notice++;
+      self->ignore_notice--;
       pop_string_stack (&self->multiple_pass);
+      self->modified_state |= HMSF_multiple_pass | HMSF_converter_state;
     }
 
-  self->modified_state++;
-
   return result;
 }
 
@@ -2768,7 +2754,7 @@ convert_to_html_internal (CONVERTER *self, ELEMENT 
*element,
       if (builtin_command_data[data_cmd].flags & CF_root)
         {
           self->current_root_command = element;
-          self->modified_state++;
+          self->modified_state |= HMSF_current_root;
         }
 
       if (self->commands_conversion[cmd].status)
@@ -2785,7 +2771,7 @@ convert_to_html_internal (CONVERTER *self, ELEMENT 
*element,
             {
               html_new_document_context (self,
                                builtin_command_data[data_cmd].cmdname, 0, 0);
-              self->modified_state++;
+              self->modified_state |= HMSF_document_context;
 
             }
           top_document_ctx = top_document_context (self);
@@ -2795,7 +2781,7 @@ convert_to_html_internal (CONVERTER *self, ELEMENT 
*element,
               push_html_formatting_context (
                          &top_document_ctx->formatting_context,
                          html_commands_data[cmd].format_context);
-              self->modified_state++;
+              self->modified_state |= HMSF_formatting_context;
             }
 
           top_formating_ctx
@@ -2804,55 +2790,55 @@ convert_to_html_internal (CONVERTER *self, ELEMENT 
*element,
           if (builtin_command_data[data_cmd].flags & CF_block)
             {
               push_command (&top_document_ctx->block_commands, data_cmd);
-              self->modified_state++;
+              self->modified_state |= HMSF_block_commands;
             }
 
           if (html_commands_data[data_cmd].flags & HF_composition_context)
             {
               push_command_or_type (&top_document_ctx->composition_context,
                                     cmd, 0);
-              self->modified_state++;
+              self->modified_state |= HMSF_composition_context;
             }
 
           if (html_commands_data[data_cmd].flags & HF_pre_class)
             {
               push_string_stack_string 
(&top_document_ctx->preformatted_classes,
                                         
html_commands_data[data_cmd].pre_class);
-              self->modified_state++;
+              self->modified_state |= HMSF_preformatted_classes;
             }
 
           if (html_commands_data[data_cmd].flags & HF_format_raw)
             {
               top_document_ctx->raw_ctx++;
-              self->modified_state++;
+              self->modified_state |= HMSF_top_document_ctx;
             }
           else if (data_cmd == CM_verbatim)
             {
               top_document_ctx->verbatim_ctx++;
-              self->modified_state++;
+              self->modified_state |= HMSF_top_document_ctx;
             }
 
           if (builtin_command_data[data_cmd].other_flags & CF_brace_code
               || builtin_command_data[data_cmd].flags & CF_preformatted_code)
             {
-              push_monospace (&top_document_ctx->monospace_context);
-              self->modified_state++;
+              push_monospace (&top_document_ctx->monospace);
+              self->modified_state |= HMSF_monospace;
             }
           else if (builtin_command_data[data_cmd].flags & CF_brace
                    && builtin_command_data[data_cmd].data == 
BRACE_style_no_code)
             {
-              push_style_no_code (&top_document_ctx->monospace_context);
-              self->modified_state++;
+              push_style_no_code (&top_document_ctx->monospace);
+              self->modified_state |= HMSF_monospace;
             }
           else if (html_commands_data[data_cmd].flags & HF_upper_case)
             {
               top_formating_ctx->upper_case_ctx++;
-              self->modified_state++;
+              self->modified_state |= HMSF_top_formatting_context;
             }
           else if (builtin_command_data[data_cmd].flags & CF_math)
             {
               top_document_ctx->math_ctx++;
-              self->modified_state++;
+              self->modified_state |= HMSF_top_document_ctx;
              /*
         $convert_to_latex = 1 if ($self->get_conf('CONVERT_TO_LATEX_IN_MATH'));
               */
@@ -2860,12 +2846,12 @@ convert_to_html_internal (CONVERTER *self, ELEMENT 
*element,
           if (cmd == CM_verb)
             {
               top_formating_ctx->space_protected++;
-              self->modified_state++;
+              self->modified_state |= HMSF_top_formatting_context;
             }
           else if (cmd == CM_w)
             {
               top_formating_ctx->no_break++;
-              self->modified_state++;
+              self->modified_state |= HMSF_top_formatting_context;
             }
 
           if (self->commands_open[cmd].status)
@@ -2982,14 +2968,14 @@ convert_to_html_internal (CONVERTER *self, ELEMENT 
*element,
                           text_reset (&formatted_arg);
                           xasprintf (&explanation, "%s A[%d]monospace",
                                                    command_type.text, arg_idx);
-                          push_monospace 
(&top_document_ctx->monospace_context);
-                          self->modified_state++;
+                          push_monospace (&top_document_ctx->monospace);
+                          self->modified_state |= HMSF_monospace;
 
                           convert_to_html_internal (self, arg, &formatted_arg,
                                                     explanation);
                           pop_monospace_context
-                              (&top_document_ctx->monospace_context);
-                          self->modified_state++;
+                              (&top_document_ctx->monospace);
+                          self->modified_state |= HMSF_monospace;
 
                           free (explanation);
                           arg_formatted->formatted[AFT_type_monospace]
@@ -3003,7 +2989,7 @@ convert_to_html_internal (CONVERTER *self, ELEMENT 
*element,
                                                      0, 0);
                           string_document_ctx = top_document_context (self);
                           string_document_ctx->string_ctx++;
-                          self->modified_state++;
+                          self->modified_state |= HMSF_document_context;
                           xasprintf (&explanation, "%s A[%d]string",
                                                    command_type.text, arg_idx);
                           convert_to_html_internal (self, arg, &formatted_arg,
@@ -3011,7 +2997,7 @@ convert_to_html_internal (CONVERTER *self, ELEMENT 
*element,
 
                           free (explanation);
                           html_pop_document_context (self);
-                          self->modified_state++;
+                          self->modified_state |= HMSF_document_context;
                           arg_formatted->formatted[AFT_type_string]
                            = strdup (formatted_arg.text);
                         }
@@ -3023,8 +3009,8 @@ convert_to_html_internal (CONVERTER *self, ELEMENT 
*element,
                                                      0, 0);
                           string_document_ctx = top_document_context (self);
                           string_document_ctx->string_ctx++;
-                          push_monospace 
(&string_document_ctx->monospace_context);
-                          self->modified_state++;
+                          push_monospace (&string_document_ctx->monospace);
+                          self->modified_state |= HMSF_document_context;
                           xasprintf (&explanation, "%s A[%d]monospacestring",
                                                    command_type.text, arg_idx);
                           convert_to_html_internal (self, arg, &formatted_arg,
@@ -3032,9 +3018,9 @@ convert_to_html_internal (CONVERTER *self, ELEMENT 
*element,
 
                           free (explanation);
                           pop_monospace_context
-                              (&string_document_ctx->monospace_context);
+                              (&string_document_ctx->monospace);
                           html_pop_document_context (self);
-                          self->modified_state++;
+                          self->modified_state |= HMSF_document_context;
                           arg_formatted->formatted[AFT_type_monospacestring]
                            = strdup (formatted_arg.text);
                         }
@@ -3086,7 +3072,7 @@ convert_to_html_internal (CONVERTER *self, ELEMENT 
*element,
                         {
                           text_reset (&formatted_arg);
                           top_document_ctx->raw_ctx++;
-                          self->modified_state++;
+                          self->modified_state |= HMSF_top_document_ctx;
                           xasprintf (&explanation, "%s A[%d]raw",
                                                    command_type.text, arg_idx);
                           convert_to_html_internal (self, arg, &formatted_arg,
@@ -3094,7 +3080,7 @@ convert_to_html_internal (CONVERTER *self, ELEMENT 
*element,
 
                           free (explanation);
                           top_document_ctx->raw_ctx--;
-                          self->modified_state++;
+                          self->modified_state |= HMSF_top_document_ctx;
                           arg_formatted->formatted[AFT_type_raw]
                             = strdup (formatted_arg.text);
                         }
@@ -3106,24 +3092,24 @@ convert_to_html_internal (CONVERTER *self, ELEMENT 
*element,
           if (html_commands_data[data_cmd].flags & HF_composition_context)
             {
               pop_command_or_type (&top_document_ctx->composition_context);
-              self->modified_state++;
+              self->modified_state |= HMSF_composition_context;
             }
 
           if (html_commands_data[data_cmd].flags & HF_pre_class)
             {
               pop_string_stack (&top_document_ctx->preformatted_classes);
-              self->modified_state++;
+              self->modified_state |= HMSF_preformatted_classes;
             }
 
           if (cmd == CM_verb)
             {
               top_formating_ctx->space_protected--;
-              self->modified_state++;
+              self->modified_state |= HMSF_top_formatting_context;
             }
           else if (cmd == CM_w)
             {
               top_formating_ctx->no_break--;
-              self->modified_state++;
+              self->modified_state |= HMSF_top_formatting_context;
             }
 
           if (builtin_command_data[data_cmd].flags & CF_preformatted_code
@@ -3131,56 +3117,56 @@ convert_to_html_internal (CONVERTER *self, ELEMENT 
*element,
                   && builtin_command_data[data_cmd].data == 
BRACE_style_no_code)
               || builtin_command_data[data_cmd].other_flags & CF_brace_code)
             {
-              pop_monospace_context (&top_document_ctx->monospace_context);
-              self->modified_state++;
+              pop_monospace_context (&top_document_ctx->monospace);
+              self->modified_state |= HMSF_monospace;
             }
           else if (html_commands_data[data_cmd].flags & HF_upper_case)
             {
               top_formating_ctx->upper_case_ctx--;
-              self->modified_state++;
+              self->modified_state |= HMSF_top_formatting_context;
             }
 
           else if (builtin_command_data[data_cmd].flags & CF_math)
             {
               top_document_ctx->math_ctx--;
-              self->modified_state++;
+              self->modified_state |= HMSF_top_document_ctx;
             }
 
           if (html_commands_data[data_cmd].flags & HF_format_raw)
             {
               top_document_ctx->raw_ctx--;
-              self->modified_state++;
+              self->modified_state |= HMSF_top_document_ctx;
             }
           else if (data_cmd == CM_verbatim)
             {
               top_document_ctx->verbatim_ctx--;
-              self->modified_state++;
+              self->modified_state |= HMSF_top_document_ctx;
             }
 
           if (builtin_command_data[data_cmd].flags & CF_block)
             {
               pop_command (&top_document_ctx->block_commands);
-              self->modified_state++;
+              self->modified_state |= HMSF_block_commands;
             }
 
           if (html_commands_data[data_cmd].flags & HF_format_context)
             {
               pop_html_formatting_context (
                          &top_document_ctx->formatting_context);
-              self->modified_state++;
+              self->modified_state |= HMSF_formatting_context;
             }
 
           if (builtin_command_data[data_cmd].flags & CF_brace
               && builtin_command_data[data_cmd].data == BRACE_context)
             {
               html_pop_document_context (self);
-              self->modified_state++;
+              self->modified_state |= HMSF_document_context;
             }
 
           if (element->cmd == CM_node)
             {
               self->current_node = element;
-              self->modified_state++;
+              self->modified_state |= HMSF_current_node;
             }
 
           /* args are formatted, now format the command itself */
@@ -3213,7 +3199,7 @@ convert_to_html_internal (CONVERTER *self, ELEMENT 
*element,
           if (builtin_command_data[data_cmd].flags & CF_root)
             {
               self->current_root_command = 0;
-              self->modified_state++;
+              self->modified_state |= HMSF_current_root;
             }
           goto out;
         }
@@ -3221,7 +3207,7 @@ convert_to_html_internal (CONVERTER *self, ELEMENT 
*element,
       if (builtin_command_data[data_cmd].flags & CF_root)
         {
           self->current_root_command = 0;
-          self->modified_state++;
+          self->modified_state |= HMSF_current_root;
         }
     }
   else if (element->type)
@@ -3248,12 +3234,12 @@ convert_to_html_internal (CONVERTER *self, ELEMENT 
*element,
       if (type == ET_paragraph)
         {
           top_formating_ctx->paragraph_number++;
-          self->modified_state++;
+          self->modified_state |= HMSF_top_formatting_context;
         }
       else if (type == ET_preformatted || type == ET_rawpreformatted)
         {
           top_formating_ctx->preformatted_number++;
-          self->modified_state++;
+          self->modified_state |= HMSF_top_formatting_context;
         }
       else if (self->pre_class_types[type])
         {
@@ -3261,19 +3247,20 @@ convert_to_html_internal (CONVERTER *self, ELEMENT 
*element,
                                     self->pre_class_types[type]);
           push_command_or_type (&top_document_ctx->composition_context,
                                 0, type);
-          self->modified_state++;
+          self->modified_state |= HMSF_preformatted_classes
+                                  | HMSF_composition_context;
         }
 
       if (self->code_types[type])
         {
-          push_monospace (&top_document_ctx->monospace_context);
-          self->modified_state++;
+          push_monospace (&top_document_ctx->monospace);
+          self->modified_state |= HMSF_monospace;
         }
 
       if (type == ET__string)
         {
           top_document_ctx->string_ctx++;
-          self->modified_state++;
+          self->modified_state |= HMSF_top_document_ctx;
         }
 
       text_init (&content_formatted);
@@ -3322,21 +3309,21 @@ convert_to_html_internal (CONVERTER *self, ELEMENT 
*element,
 
       if (self->code_types[type])
         {
-          pop_monospace_context (&top_document_ctx->monospace_context);
-          self->modified_state++;
+          pop_monospace_context (&top_document_ctx->monospace);
+          self->modified_state |= HMSF_monospace;
         }
 
       if (type == ET__string)
         {
           top_document_ctx->string_ctx--;
-          self->modified_state++;
+          self->modified_state |= HMSF_top_document_ctx;
         }
 
       if (self->pre_class_types[type])
         {
           pop_string_stack (&top_document_ctx->preformatted_classes);
           pop_command_or_type (&top_document_ctx->composition_context);
-          self->modified_state++;
+          self->modified_state |= HMSF_composition_context;
         }
 
       if (self->conf->DEBUG > 0)
@@ -3432,7 +3419,7 @@ convert_output_unit (CONVERTER *self, OUTPUT_UNIT 
*output_unit,
     }
 
   self->current_output_unit = output_unit;
-  self->modified_state++;
+  self->modified_state |= HMSF_current_output_unit;
 
   text_init (&content_formatted);
   text_append (&content_formatted, "");
@@ -3468,7 +3455,7 @@ convert_output_unit (CONVERTER *self, OUTPUT_UNIT 
*output_unit,
   free (content_formatted.text);
 
   self->current_output_unit = 0;
-  self->modified_state++;
+  self->modified_state |= HMSF_current_output_unit;
 
   if (self->conf->DEBUG > 0)
     fprintf (stderr, "UNIT (%s) => `%s'\n", output_unit_type_names[unit_type],
diff --git a/tp/Texinfo/XS/main/build_perl_info.c 
b/tp/Texinfo/XS/main/build_perl_info.c
index dfe3d8a31a..4a8ff6a678 100644
--- a/tp/Texinfo/XS/main/build_perl_info.c
+++ b/tp/Texinfo/XS/main/build_perl_info.c
@@ -37,9 +37,12 @@
 #include "global_commands_types.h"
 #include "tree_types.h"
 #include "command_ids.h"
-#include "tree.h"
 #include "element_types.h"
-/* for GLOBAL_INFO ERROR_MESSAGE fatal output_unit_type_names CONVERTER */
+/* for GLOBAL_INFO ERROR_MESSAGE CONVERTER */
+#include "converter_types.h"
+#include "tree.h"
+/* for fatal output_unit_type_names
+   HMSF_* */
 #include "utils.h"
 /* for debugging */
 #include "debug.h"
@@ -1829,18 +1832,13 @@ build_out_filepaths (FILE_NAME_PATH_COUNTER_LIST 
*output_unit_files)
   return newRV_noinc ((SV *) hv);
 }
 
-HV *
-build_html_formatting_context (HTML_FORMATTING_CONTEXT *formatting_context)
+void
+build_html_formatting_context_ctx (HV *hv,
+                                   HTML_FORMATTING_CONTEXT *formatting_context)
 {
-  HV *hv;
-
   dTHX;
 
-  hv = newHV ();
-
 #define STORE(key, value) hv_store (hv, key, strlen (key), value, 0)
-
-  STORE("context_name", newSVpv (formatting_context->context_name, 0));
 #define STORE_INT(name) STORE(#name, newSViv (formatting_context->name))
   STORE_INT(preformatted_number);
   STORE_INT(paragraph_number);
@@ -1851,59 +1849,63 @@ build_html_formatting_context (HTML_FORMATTING_CONTEXT 
*formatting_context)
 #define STORE_CTX(name) STORE(#name, newSViv (formatting_context->name##_ctx))
   STORE_CTX(upper_case);
 #undef STORE_CTX
-
-#undef STORE
-  return hv;
 }
 
 HV *
-build_html_document_context (HTML_DOCUMENT_CONTEXT *document_context)
+build_html_formatting_context (HTML_FORMATTING_CONTEXT *formatting_context)
 {
-  int i;
   HV *hv;
-  AV *monospace_context_av;
-  AV *composition_context_av;
-  AV *block_commands_av;
-  AV *formatting_context_av;
-  AV *preformatted_classes_av;
 
   dTHX;
 
   hv = newHV ();
-  monospace_context_av = newAV ();
-  composition_context_av = newAV ();
-  block_commands_av = newAV ();
-  formatting_context_av = newAV ();
-  preformatted_classes_av = newAV ();
-
 
 #define STORE(key, value) hv_store (hv, key, strlen (key), value, 0)
 
-  STORE ("context", newSVpv_utf8 (document_context->context, 0));
+  STORE("context_name", newSVpv (formatting_context->context_name, 0));
 
-#define STORE_CTX(name) STORE(#name, newSViv (document_context->name##_ctx))
-  STORE_CTX(string);
-  STORE_CTX(raw);
-  STORE_CTX(verbatim);
-  STORE_CTX(math);
-#undef STORE_CTX
-  STORE ("document_global_context",
-         newSVpv_utf8 (document_context->document_global_context, 0));
+#undef STORE
+  build_html_formatting_context_ctx (hv, formatting_context);
+
+  return hv;
+}
+
+AV *
+build_html_formatting_context_stack (
+      HTML_FORMATTING_CONTEXT_STACK *formatting_context_stack)
+{
+  int i;
+  AV *formatting_context_av;
 
-  for (i = 0; i < document_context->monospace_context.top; i++)
+  dTHX;
+
+  formatting_context_av = newAV ();
+  for (i = 0; i < formatting_context_stack->top; i++)
     {
-      enum monospace_context context
-        = document_context->monospace_context.stack[i];
-      av_push (monospace_context_av, newSViv (context));
+      HTML_FORMATTING_CONTEXT *formatting_context
+        = &formatting_context_stack->stack[i];
+      HV *context_hv = build_html_formatting_context (formatting_context);
+      av_push (formatting_context_av, newRV_noinc ((SV *) context_hv));
     }
+  return formatting_context_av;
+}
+
+AV *
+build_html_composition_context_stack
+          (COMMAND_OR_TYPE_STACK *composition_context_stack)
+{
+  AV *composition_context_av;
+  int i;
+
+  dTHX;
 
-  STORE ("monospace", newRV_noinc ((SV *) monospace_context_av));
+  composition_context_av = newAV ();
 
-  for (i = 0; i < document_context->composition_context.top; i++)
+  for (i = 0; i < composition_context_stack->top; i++)
     {
       char *context_str = 0;
       COMMAND_OR_TYPE *context
-        = &document_context->composition_context.stack[i];
+        = &composition_context_stack->stack[i];
       if (context->variety == CTV_type_type)
         context_str = element_type_names[context->type];
       else if (context->variety == CTV_type_command)
@@ -1912,30 +1914,120 @@ build_html_document_context (HTML_DOCUMENT_CONTEXT 
*document_context)
         context_str = "";
       av_push (composition_context_av, newSVpv (context_str, 0));
     }
-  STORE ("composition_context", newRV_noinc ((SV *) composition_context_av));
+  return composition_context_av;
+}
+
+AV *
+build_html_preformatted_classes_stack
+          (STRING_STACK *preformatted_classes_stack)
+{
+  AV *preformatted_classes_av;
+  int i;
+
+  dTHX;
+
+  preformatted_classes_av = newAV ();
 
-  for (i = 0; i < document_context->block_commands.top; i++)
+  for (i = 0; i < preformatted_classes_stack->top; i++)
     {
-      enum command_id cmd = document_context->block_commands.stack[i];
-      char *context_str = builtin_command_data[cmd].cmdname;
-      av_push (block_commands_av, newSVpv (context_str, 0));
+      char *context_str = preformatted_classes_stack->stack[i];
+      av_push (preformatted_classes_av, newSVpv (context_str, 0));
     }
-  STORE ("block_commands", newRV_noinc ((SV *) block_commands_av));
+  return preformatted_classes_av;
+}
+
+AV *
+build_html_monospace_stack (MONOSPACE_CONTEXT_STACK *monospace_stack)
+{
+  AV *monospace_av;
+  int i;
+
+  dTHX;
+
+  monospace_av = newAV ();
 
-  for (i = 0; i < document_context->preformatted_classes.top; i++)
+  for (i = 0; i < monospace_stack->top; i++)
     {
-      char *context_str = document_context->preformatted_classes.stack[i];
-      av_push (preformatted_classes_av, newSVpv (context_str, 0));
+      enum monospace_context context
+        = monospace_stack->stack[i];
+      av_push (monospace_av, newSViv (context));
     }
-  STORE ("preformatted_classes", newRV_noinc ((SV *) preformatted_classes_av));
+  return monospace_av;
+}
+
+AV *
+build_html_block_commands_stack (COMMAND_STACK *block_commands_stack)
+{
+  AV *block_commands_av;
+  int i;
 
-  for (i = 0; i < document_context->formatting_context.top; i++)
+  dTHX;
+
+  block_commands_av = newAV ();
+
+  for (i = 0; i < block_commands_stack->top; i++)
     {
-      HTML_FORMATTING_CONTEXT *formatting_context
-        = &document_context->formatting_context.stack[i];
-      HV *context_hv = build_html_formatting_context (formatting_context);
-      av_push (formatting_context_av, newRV_noinc ((SV *) context_hv));
+      enum command_id cmd = block_commands_stack->stack[i];
+      char *context_str = builtin_command_data[cmd].cmdname;
+      av_push (block_commands_av, newSVpv (context_str, 0));
     }
+  return block_commands_av;
+}
+
+void
+build_html_document_context_ctx (HV *hv,
+                                 HTML_DOCUMENT_CONTEXT *document_context)
+{
+  dTHX;
+
+#define STORE(key, value) hv_store (hv, key, strlen (key), value, 0)
+#define STORE_CTX(name) STORE(#name, newSViv (document_context->name##_ctx))
+  STORE_CTX(string);
+  STORE_CTX(raw);
+  STORE_CTX(verbatim);
+  STORE_CTX(math);
+#undef STORE_CTX
+#undef STORE
+}
+
+HV *
+build_html_document_context (HTML_DOCUMENT_CONTEXT *document_context)
+{
+  HV *hv;
+  AV *monospace_av;
+  AV *composition_context_av;
+  AV *block_commands_av;
+  AV *formatting_context_av;
+  AV *preformatted_classes_av;
+
+  dTHX;
+
+  hv = newHV ();
+
+#define STORE(key, value) hv_store (hv, key, strlen (key), value, 0)
+
+  STORE ("context", newSVpv_utf8 (document_context->context, 0));
+  STORE ("document_global_context",
+         newSVpv_utf8 (document_context->document_global_context, 0));
+
+  monospace_av = build_html_monospace_stack (
+                                &document_context->monospace);
+  STORE ("monospace", newRV_noinc ((SV *) monospace_av));
+
+  composition_context_av = build_html_composition_context_stack (
+                                &document_context->composition_context);
+  STORE ("composition_context", newRV_noinc ((SV *) composition_context_av));
+
+  block_commands_av = build_html_block_commands_stack
+                              (&document_context->block_commands);
+  STORE ("block_commands", newRV_noinc ((SV *) block_commands_av));
+
+  preformatted_classes_av = build_html_preformatted_classes_stack
+                               (&document_context->preformatted_classes);
+  STORE ("preformatted_classes", newRV_noinc ((SV *) preformatted_classes_av));
+
+  formatting_context_av = build_html_formatting_context_stack
+                               (&document_context->formatting_context);
   STORE ("formatting_context", newRV_noinc ((SV *) formatting_context_av));
 
 #undef STORE
@@ -1944,15 +2036,17 @@ build_html_document_context (HTML_DOCUMENT_CONTEXT 
*document_context)
 
 /* there is no need to return anything. */
 SV *
-build_html_formatting_state (CONVERTER *converter)
+build_html_formatting_state (CONVERTER *converter, unsigned long flags)
 {
   HV *hv;
   SV **document_context_sv;
   AV *document_context_av;
   SV **multiple_pass_sv;
   AV *multiple_pass_av;
+  /*
   SV **files_information_sv;
   HV *files_information_hv;
+   */
   int i;
 
   dTHX;
@@ -1963,77 +2057,164 @@ build_html_formatting_state (CONVERTER *converter)
   hv = converter->hv;
 
 #define STORE(key, value) hv_store (hv, key, strlen (key), value, 0)
-  STORE("document_global_context",
+
+  if (flags & HMSF_converter_state)
+    {
+      STORE("document_global_context",
         newSViv (converter->document_global_context));
 
-  STORE("ignore_notice",
+      STORE("ignore_notice",
         newSViv (converter->ignore_notice));
+    }
 
-  if (!converter->current_root_command)
-    STORE("current_root_command", newSV (0));
-  else
-    STORE("current_root_command",
-       newRV_inc ((SV *) converter->current_root_command->hv));
-
-  if (!converter->current_node)
-    STORE("current_node", newSV (0));
-  else
-    STORE("current_node",
-       newRV_inc ((SV *) converter->current_node->hv));
-
-  if (!converter->current_output_unit)
-    STORE("current_output_unit", newSV (0));
-  else
-    STORE("current_output_unit",
-       newRV_inc ((SV *) converter->current_output_unit->hv));
-
-  if (!converter->current_filename)
-    STORE("current_filename", newSV (0));
-  else
-    STORE("current_filename", newSVpv_utf8 (converter->current_filename, 0));
-
-  document_context_sv = hv_fetch (hv, "document_context",
-                                  strlen ("document_context"), 0);
+  if (flags & HMSF_current_root)
+    {
+      if (!converter->current_root_command)
+        STORE("current_root_command", newSV (0));
+      else
+        STORE("current_root_command",
+          newRV_inc ((SV *) converter->current_root_command->hv));
+    }
 
-  if (!document_context_sv)
+  if (flags & HMSF_current_node)
     {
-      document_context_av = newAV ();
-      STORE("document_context", newRV_noinc ((SV *) document_context_av));
+      if (!converter->current_node)
+        STORE("current_node", newSV (0));
+      else
+        STORE("current_node",
+           newRV_inc ((SV *) converter->current_node->hv));
     }
-  else
+  if (flags & HMSF_current_output_unit)
     {
-      document_context_av = (AV *) SvRV (*document_context_sv);
-      av_clear (document_context_av);
+      if (!converter->current_output_unit)
+        STORE("current_output_unit", newSV (0));
+      else
+        STORE("current_output_unit",
+           newRV_inc ((SV *) converter->current_output_unit->hv));
     }
-
-  for (i = 0; i < converter->html_document_context.top; i++)
+  if (flags & HMSF_current_filename)
     {
-      HTML_DOCUMENT_CONTEXT *document_context
-        = &converter->html_document_context.stack[i];
-      HV *document_context_hv = build_html_document_context (document_context);
-      av_push (document_context_av, newRV_noinc ((SV *) document_context_hv));
+      if (!converter->current_filename)
+        STORE("current_filename", newSV (0));
+      else
+        STORE("current_filename",
+          newSVpv_utf8 (converter->current_filename, 0));
     }
 
-  multiple_pass_sv = hv_fetch (hv, "multiple_pass",
-                                  strlen ("multiple_pass"), 0);
-
-  if (!multiple_pass_sv)
+  if (flags & HMSF_document_context)
     {
-      multiple_pass_av = newAV ();
-      STORE("multiple_pass", newRV_noinc ((SV *) multiple_pass_av));
+      document_context_sv = hv_fetch (hv, "document_context",
+                                      strlen ("document_context"), 0);
+
+      if (!document_context_sv)
+        {
+          document_context_av = newAV ();
+          STORE("document_context", newRV_noinc ((SV *) document_context_av));
+        }
+       else
+        {
+          document_context_av = (AV *) SvRV (*document_context_sv);
+          av_clear (document_context_av);
+        }
+
+      for (i = 0; i < converter->html_document_context.top; i++)
+        {
+          HTML_DOCUMENT_CONTEXT *document_context
+            = &converter->html_document_context.stack[i];
+          HV *document_context_hv = build_html_document_context 
(document_context);
+          av_push (document_context_av, newRV_noinc ((SV *) 
document_context_hv));
+        }
     }
-  else
-    {
-      multiple_pass_av = (AV *) SvRV (*multiple_pass_sv);
-      av_clear (multiple_pass_av);
+  else if (flags & (HMSF_formatting_context | HMSF_composition_context
+                    | HMSF_preformatted_classes | HMSF_block_commands
+                    | HMSF_monospace | HMSF_top_document_ctx
+                    | HMSF_top_formatting_context))
+    {
+      HTML_DOCUMENT_CONTEXT *top_document_ctx
+         = top_document_context (converter);
+      SSize_t top_document_context_idx;
+      SV **top_document_context_sv;
+      HV *top_document_context_hv;
+      AV *formatting_context_av;
+      AV *composition_context_av;
+      AV *preformatted_classes_av;
+      AV *block_commands_av;
+      AV *monospace_av;
+
+      document_context_sv = hv_fetch (hv, "document_context",
+                                      strlen ("document_context"), 0);
+      document_context_av = (AV *) SvRV (*document_context_sv);
+      top_document_context_idx = av_top_index (document_context_av);
+      top_document_context_sv = av_fetch (document_context_av,
+                                          top_document_context_idx, 0);
+
+      top_document_context_hv = (HV *) SvRV (*top_document_context_sv);
+#define build_context(name) \
+      if (flags & HMSF_##name) \
+        { \
+          name##_av = build_html_##name##_stack(  \
+                                   &top_document_ctx->name);    \
+          hv_store (top_document_context_hv, #name,             \
+                                    strlen (#name),               \
+                         newRV_noinc ((SV *) name##_av), 0);    \
+        }
+  build_context(formatting_context)
+  build_context(composition_context)
+  build_context(preformatted_classes)
+  build_context(block_commands)
+  build_context(monospace)
+#undef build_context
+
+      if (flags & HMSF_top_document_ctx)
+        build_html_document_context_ctx (top_document_context_hv,
+                                         top_document_ctx);
+
+      if (!(flags & HMSF_formatting_context)
+          && flags & HMSF_top_formatting_context)
+        {
+          HTML_FORMATTING_CONTEXT *top_formatting_ctx
+         = top_html_formatting_context (&top_document_ctx->formatting_context);
+          SSize_t top_formatting_context_idx;
+          SV **top_formatting_context_sv;
+          HV *top_formatting_context_hv;
+
+          SV **formatting_context_sv = hv_fetch (top_document_context_hv,
+                                            "formatting_context",
+                                         strlen ("formatting_context"), 0);
+          formatting_context_av = (AV *) SvRV (*formatting_context_sv);
+          top_formatting_context_idx = av_top_index (formatting_context_av);
+          top_formatting_context_sv = av_fetch (formatting_context_av,
+                                          top_formatting_context_idx, 0);
+          top_formatting_context_hv = (HV *) SvRV (*top_formatting_context_sv);
+          build_html_formatting_context_ctx (top_formatting_context_hv,
+                                             top_formatting_ctx);
+        }
     }
 
-  for (i = 0; i < converter->multiple_pass.top; i++)
+  if (flags & HMSF_multiple_pass)
     {
-      char *multiple_pass_str = converter->multiple_pass.stack[i];
-      av_push (multiple_pass_av, newSVpv_utf8(multiple_pass_str, 0));
+      multiple_pass_sv = hv_fetch (hv, "multiple_pass",
+                                   strlen ("multiple_pass"), 0);
+
+      if (!multiple_pass_sv)
+        {
+          multiple_pass_av = newAV ();
+          STORE("multiple_pass", newRV_noinc ((SV *) multiple_pass_av));
+        }
+      else
+        {
+          multiple_pass_av = (AV *) SvRV (*multiple_pass_sv);
+          av_clear (multiple_pass_av);
+        }
+
+      for (i = 0; i < converter->multiple_pass.top; i++)
+        {
+          char *multiple_pass_str = converter->multiple_pass.stack[i];
+          av_push (multiple_pass_av, newSVpv_utf8(multiple_pass_str, 0));
+        }
     }
 
+  /*
   files_information_sv = hv_fetch (hv, "files_information",
                                   strlen ("files_information"), 0);
 
@@ -2044,11 +2225,10 @@ build_html_formatting_state (CONVERTER *converter)
     }
   else
     {
-      /* TODO
       files_information_hv = (HV *) SvRV (*files_information_sv);
       hv_clear (files_information_av);
-       */
     }
+  */
 
 #undef STORE
 
diff --git a/tp/Texinfo/XS/main/build_perl_info.h 
b/tp/Texinfo/XS/main/build_perl_info.h
index cac8446ecf..3fb9e1197b 100644
--- a/tp/Texinfo/XS/main/build_perl_info.h
+++ b/tp/Texinfo/XS/main/build_perl_info.h
@@ -50,7 +50,7 @@ SV *build_filenames (FILE_NAME_PATH_COUNTER_LIST 
*output_unit_files);
 SV *build_file_counters (FILE_NAME_PATH_COUNTER_LIST *output_unit_files);
 SV *build_out_filepaths (FILE_NAME_PATH_COUNTER_LIST *output_unit_files);
 
-SV *build_html_formatting_state (CONVERTER *converter);
+SV *build_html_formatting_state (CONVERTER *converter, unsigned long flags);
 
 SV *build_html_command_formatted_args (HTML_ARGS_FORMATTED *args_formatted);
 #endif
diff --git a/tp/Texinfo/XS/main/call_perl_function.c 
b/tp/Texinfo/XS/main/call_perl_function.c
index cf1f9c9dc9..029cde7ae6 100644
--- a/tp/Texinfo/XS/main/call_perl_function.c
+++ b/tp/Texinfo/XS/main/call_perl_function.c
@@ -556,7 +556,7 @@ call_types_conversion (CONVERTER *self, enum element_type 
type,
 
   if (self->modified_state)
     {
-      build_html_formatting_state (self);
+      build_html_formatting_state (self, self->modified_state);
       self->modified_state = 0;
     }
 
@@ -625,7 +625,7 @@ call_types_open (CONVERTER *self, enum element_type type,
 
   if (self->modified_state)
     {
-      build_html_formatting_state (self);
+      build_html_formatting_state (self, self->modified_state);
       self->modified_state = 0;
     }
 
@@ -697,7 +697,7 @@ call_commands_conversion (CONVERTER *self, enum command_id 
cmd,
 
   if (self->modified_state)
     {
-      build_html_formatting_state (self);
+      build_html_formatting_state (self, self->modified_state);
       self->modified_state = 0;
     }
 
@@ -773,7 +773,7 @@ call_commands_open (CONVERTER *self, enum command_id cmd,
 
   if (self->modified_state)
     {
-      build_html_formatting_state (self);
+      build_html_formatting_state (self, self->modified_state);
       self->modified_state = 0;
     }
 
@@ -841,7 +841,7 @@ call_output_units_conversion (CONVERTER *self,
 
   if (self->modified_state)
     {
-      build_html_formatting_state (self);
+      build_html_formatting_state (self, self->modified_state);
       self->modified_state = 0;
     }
 
diff --git a/tp/Texinfo/XS/main/command_stack.c 
b/tp/Texinfo/XS/main/command_stack.c
index 8a02a42efc..bca18ef1f9 100644
--- a/tp/Texinfo/XS/main/command_stack.c
+++ b/tp/Texinfo/XS/main/command_stack.c
@@ -198,3 +198,24 @@ top_monospace_context (MONOSPACE_CONTEXT_STACK *stack)
   return stack->stack[stack->top - 1];
 }
 
+/* HTML specific but also used to build perl */
+HTML_DOCUMENT_CONTEXT *
+top_document_context (CONVERTER *self)
+{
+  HTML_DOCUMENT_CONTEXT_STACK *stack = &self->html_document_context;
+
+  if (stack->top == 0)
+    fatal ("HTML document context stack empty for top");
+
+  return &stack->stack[stack->top - 1];
+}
+
+HTML_FORMATTING_CONTEXT *
+top_html_formatting_context (HTML_FORMATTING_CONTEXT_STACK *stack)
+{
+  if (stack->top == 0)
+    fatal ("HTML formatting context stack empty for top");
+
+  return &stack->stack[stack->top - 1];
+}
+
diff --git a/tp/Texinfo/XS/main/command_stack.h 
b/tp/Texinfo/XS/main/command_stack.h
index 0a5b3bf20d..cae30f6202 100644
--- a/tp/Texinfo/XS/main/command_stack.h
+++ b/tp/Texinfo/XS/main/command_stack.h
@@ -20,70 +20,29 @@
 
 #include "tree_types.h"
 #include "element_types.h"
-
-enum command_type_variety {
-   CTV_type_none,
-   CTV_type_command,
-   CTV_type_type,
-};
-
-enum monospace_context {
-   MONO_ctx_off,
-   MONO_ctx_on,
-};
-
-typedef struct {
-    enum command_id *stack;
-    size_t top;   /* One above last pushed command. */
-    size_t space;
-} COMMAND_STACK;
+#include "converter_types.h"
 
 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);
 
-/* either a type or a command id */
-typedef struct {
-    enum command_type_variety variety;
-    union {
-      enum command_id cmd;
-      enum element_type type;
-    };
-} COMMAND_OR_TYPE;
-
-typedef struct {
-    COMMAND_OR_TYPE *stack;
-    size_t top;   /* One above last pushed command. */
-    size_t space;
-} COMMAND_OR_TYPE_STACK;
-
 void push_command_or_type (COMMAND_OR_TYPE_STACK *stack, enum command_id cmd,
                            enum element_type type);
 void pop_command_or_type (COMMAND_OR_TYPE_STACK *stack);
 COMMAND_OR_TYPE *top_command_or_type (COMMAND_OR_TYPE_STACK *stack);
 
-
-typedef struct {
-    char **stack;
-    size_t top;   /* One above last pushed command. */
-    size_t space;
-} STRING_STACK;
-
 void push_string_stack_string (STRING_STACK *stack, char *string);
 void pop_string_stack (STRING_STACK *stack);
 char *top_string_stack (STRING_STACK *stack);
 
-
-typedef struct {
-    enum monospace_context *stack;
-    size_t top;   /* One above last pushed. */
-    size_t space;
-} MONOSPACE_CONTEXT_STACK;
-
 void push_monospace (MONOSPACE_CONTEXT_STACK *stack);
 void push_style_no_code (MONOSPACE_CONTEXT_STACK *stack);
 enum monospace_context pop_monospace_context (MONOSPACE_CONTEXT_STACK *stack);
 enum monospace_context top_monospace_context (MONOSPACE_CONTEXT_STACK *stack);
 
+HTML_DOCUMENT_CONTEXT *top_document_context (CONVERTER *self);
+
+HTML_FORMATTING_CONTEXT *top_html_formatting_context
+                         (HTML_FORMATTING_CONTEXT_STACK *stack);
 #endif
diff --git a/tp/Texinfo/XS/main/convert_to_text.h 
b/tp/Texinfo/XS/main/convert_to_text.h
index 9dc258863e..d403b3cdf1 100644
--- a/tp/Texinfo/XS/main/convert_to_text.h
+++ b/tp/Texinfo/XS/main/convert_to_text.h
@@ -4,7 +4,7 @@
 
 #include "options_types.h"
 #include "tree_types.h"
-#include "utils.h"
+#include "converter_types.h"
 
 typedef struct TEXT_OPTIONS {
     int set_case; /* sc and lc */
diff --git a/tp/Texinfo/XS/main/convert_utils.h 
b/tp/Texinfo/XS/main/convert_utils.h
index 09004ca76b..64bcd1d443 100644
--- a/tp/Texinfo/XS/main/convert_utils.h
+++ b/tp/Texinfo/XS/main/convert_utils.h
@@ -4,6 +4,7 @@
 
 #include "options_types.h"
 #include "tree_types.h"
+#include "converter_types.h"
 #include "convert_to_text.h"
 #include "utils.h"
 
diff --git a/tp/Texinfo/XS/main/utils.h b/tp/Texinfo/XS/main/converter_types.h
similarity index 55%
copy from tp/Texinfo/XS/main/utils.h
copy to tp/Texinfo/XS/main/converter_types.h
index 898c11a296..f12c37b2e8 100644
--- a/tp/Texinfo/XS/main/utils.h
+++ b/tp/Texinfo/XS/main/converter_types.h
@@ -1,6 +1,6 @@
-/* utils.h - declarations for utils.c */
-#ifndef UTILS_H
-#define UTILS_H
+/* converter_types.h - declarations of types used in many places */
+#ifndef CONVERTER_TYPES_H
+#define CONVERTER_TYPES_H
 
 /* Copyright 2010-2023 Free Software Foundation, Inc.
 
@@ -18,146 +18,35 @@
    along with this program.  If not, see <http://www.gnu.org/licenses/>. */
 
 #include <stddef.h>
-#include <iconv.h>
 
+#include "tree_types.h"
+#include "element_types.h"
 #include "options_types.h"
 #include "global_commands_types.h"
-#include "tree_types.h"
-#include "command_ids.h"
-#include "command_stack.h"
-#include "builtin_commands.h"
-
-extern const char *whitespace_chars;
-extern const char *digit_chars;
-extern enum command_id level_to_structuring_command[][5];
-extern int command_structuring_level[];
-
-extern const char *direction_names[];
-extern const char *direction_texts[];
-extern const size_t directions_length;
-
-extern const char *output_unit_type_names[];
-
-extern const char *command_location_names[];
-
-extern char *html_conversion_context_type_names[];
-extern char *html_global_unit_direction_names[];
-
-extern char *html_formatting_reference_names[];
-extern char *html_css_string_formatting_reference_names[];
 
 enum error_type { MSG_error, MSG_warning,
                   MSG_document_error, MSG_document_warning };
 
-typedef struct {
-    char *message;
-    char *error_line;
-    enum error_type type;
-    int continuation;
-    SOURCE_INFO source_info;
-} ERROR_MESSAGE;
-
-typedef struct {
-    ERROR_MESSAGE *list;
-    size_t number;
-    size_t space;
-} ERROR_MESSAGE_LIST;
-
-typedef struct {
-    char *encoding_name;
-    iconv_t iconv;
-} ENCODING_CONVERSION;
-
-typedef struct {
-    ENCODING_CONVERSION *list;
-    size_t number;
-    size_t space;
-    int direction;  /* if > 0 converts from the encodings to UTF-8 */
-} ENCODING_CONVERSION_LIST;
-
-extern ENCODING_CONVERSION_LIST output_conversions;
-extern ENCODING_CONVERSION_LIST input_conversions;
-
-typedef struct expanded_format {
-    char *format;
-    int expandedp;
-} EXPANDED_FORMAT;
-
-typedef struct GLOBAL_INFO {
-    char *input_file_name;
-    char *input_directory;
-    char *input_encoding_name;
-    int sections_level_modifier;
-    ELEMENT dircategory_direntry; /* an array of elements */
-    /* Ignored characters for index sort key */
-    IGNORED_CHARS ignored_chars;
-} GLOBAL_INFO;
-
-enum global_option_command_type {
-   GO_NONE,
-   GO_int,
-   GO_char,
+enum formatting_reference_status {
+   FRS_status_none,
+   FRS_status_default_set,        /* default is set, no customization (or
+                                     customization is the same as default) */
+   FRS_status_customization_set,  /* customization is set, no default, or
+                                     not the same as default */
+   FRS_status_ignored,            /* explicitely ignored. Only used for
+                                     types_conversion and commands_conversion
+                                   */
 };
 
-/* definitions for table of defaults for options corresponding to commands */
-typedef struct COMMAND_OPTION_DEFAULT {
-    enum global_option_command_type type;
-    int value;
-    char *string;
-} COMMAND_OPTION_DEFAULT;
-
-extern COMMAND_OPTION_DEFAULT command_option_default_table[];
-
-/* return type of get_command_option */
-typedef struct COMMAND_OPTION_REF {
-    enum global_option_command_type type;
-    union {
-      int *int_ref;
-      char **char_ref;
-    };
-} COMMAND_OPTION_REF;
+enum command_type_variety {
+   CTV_type_none,
+   CTV_type_command,
+   CTV_type_type,
+};
 
-/* similar to COMMAND_OPTION_REF but for values only */
-typedef struct COMMAND_OPTION_VALUE {
-    enum global_option_command_type type;
-    union {
-      int int_value;
-      char *char_value;
-    };
-} COMMAND_OPTION_VALUE;
-
-#define SMALL_BLOC_COMMANDS_LIST \
-    smbc_command_name(example)\
-    smbc_command_name(display) \
-    smbc_command_name(format) \
-    smbc_command_name(lisp) \
-    smbc_command_name(quotation) \
-    smbc_command_name(indentedblock)
-
-extern const enum command_id small_block_associated_command[][2];
-
-/* CONVERTER and associated types needed for set_global_document_command */
-/* see Texinfo::HTML _prepare_output_units_global_targets
-
-   NOTE the special output units names are not actually used, the
-   special output units direction names are obtained from the perl input
-   and stored in special_unit_info and put later on in
-   special_units_direction_name
- */
-#define HTML_GLOBAL_DIRECTIONS_LIST \
-   hgdt_name(First) \
-   hgdt_name(Top) \
-   hgdt_name(Index) \
-   hgdt_name(Last) \
-   hgdt_name(About) \
-   hgdt_name(Contents) \
-   hgdt_name(Overview) \
-   hgdt_name(Footnotes)
-
-enum global_unit_direction {
-  #define hgdt_name(name) D_ ## name,
-   HTML_GLOBAL_DIRECTIONS_LIST
-  #undef hgdt_name
+enum monospace_context {
+   MONO_ctx_off,
+   MONO_ctx_on,
 };
 
 #define SUI_TYPES_LIST \
@@ -179,13 +68,6 @@ enum special_unit_info_tree {
    SUIT_type_heading,
 };
 
-enum command_location {
-   CL_before,
-   CL_last,
-   CL_preamble,
-   CL_preamble_or_first,
-};
-
 enum special_target_type {
    ST_footnote_location,
 };
@@ -207,20 +89,6 @@ enum direction_string {
   #undef tds_type
 };
 
-#define HCC_CONTEXT_TYPES_LIST \
-  cctx_type(normal) \
-  cctx_type(preformatted) \
-  cctx_type(string) \
-  cctx_type(css_string) \
-  cctx_type(code) \
-  cctx_type(math)
-
-enum conversion_context {
-  #define cctx_type(name) HCC_type_## name,
-   HCC_CONTEXT_TYPES_LIST
-  #undef cctx_type
-};
-
 /* %default_formatting_references + %default_css_string_formatting_references
    in Texinfo::HTML */
 #define HTML_FORMATTING_REFERENCES_LIST \
@@ -262,19 +130,85 @@ enum html_css_string_formatting_reference {
   #undef html_fr_reference
 };
 
-enum formatting_reference_status {
-   FRS_status_none,
-   FRS_status_default_set,        /* default is set, no customization (or
-                                     customization is the same as default) */
-   FRS_status_customization_set,  /* customization is set, no default, or
-                                     not the same as default */
-   FRS_status_ignored,            /* explicitely ignored. Only used for
-                                     types_conversion and commands_conversion
-                                   */
-};
+typedef struct {
+    enum command_id *stack;
+    size_t top;   /* One above last pushed command. */
+    size_t space;
+} COMMAND_STACK;
+
+/* either a type or a command id */
+typedef struct {
+    enum command_type_variety variety;
+    union {
+      enum command_id cmd;
+      enum element_type type;
+    };
+} COMMAND_OR_TYPE;
+
+typedef struct {
+    COMMAND_OR_TYPE *stack;
+    size_t top;   /* One above last pushed command. */
+    size_t space;
+} COMMAND_OR_TYPE_STACK;
+
+typedef struct {
+    char **stack;
+    size_t top;   /* One above last pushed command. */
+    size_t space;
+} STRING_STACK;
+
+typedef struct {
+    enum monospace_context *stack;
+    size_t top;   /* One above last pushed. */
+    size_t space;
+} MONOSPACE_CONTEXT_STACK;
+
+typedef struct {
+    char *message;
+    char *error_line;
+    enum error_type type;
+    int continuation;
+    SOURCE_INFO source_info;
+} ERROR_MESSAGE;
+
+typedef struct {
+    ERROR_MESSAGE *list;
+    size_t number;
+    size_t space;
+} ERROR_MESSAGE_LIST;
+
+typedef struct GLOBAL_INFO {
+    char *input_file_name;
+    char *input_directory;
+    char *input_encoding_name;
+    int sections_level_modifier;
+    ELEMENT dircategory_direntry; /* an array of elements */
+    /* Ignored characters for index sort key */
+    IGNORED_CHARS ignored_chars;
+} GLOBAL_INFO;
+
+typedef struct DOCUMENT {
+    int descriptor;
+    ELEMENT *tree;
+    INDEX **index_names;
+    FLOAT_RECORD_LIST *floats;
+    FLOAT_RECORD_LIST *listoffloats;
+    ELEMENT_LIST *internal_references;
+    LABEL_LIST *labels_list;
+    LABEL_LIST *identifiers_target;
+    GLOBAL_INFO *global_info;
+    GLOBAL_COMMANDS *global_commands;
+    STRING_LIST *small_strings;
+    ELEMENT *nodes_list; /* nodes in contents of this element */
+    ELEMENT *sections_list; /* sections in contents of this element */
+    ERROR_MESSAGE_LIST *error_messages;
+    OPTIONS *options; /* for options used in structuring */
+} DOCUMENT;
 
-/* down here because it requires error data from before */
-#include "document.h"
+typedef struct expanded_format {
+    char *format;
+    int expandedp;
+} EXPANDED_FORMAT;
 
 typedef struct VARIETY_DIRECTION_INDEX {
     char *special_unit_variety;
@@ -396,7 +330,7 @@ typedef struct HTML_DOCUMENT_CONTEXT {
     int verbatim_ctx;
     int math_ctx;
     char *document_global_context;
-    MONOSPACE_CONTEXT_STACK monospace_context;
+    MONOSPACE_CONTEXT_STACK monospace;
     COMMAND_OR_TYPE_STACK composition_context;
     COMMAND_STACK block_commands;
     HTML_FORMATTING_CONTEXT_STACK formatting_context;
@@ -458,7 +392,7 @@ typedef struct CONVERTER {
     FORMATTING_REFERENCE output_units_conversion[OU_special_unit+1];
 
     /* state only in C converter */
-    int modified_state; /* to determine if perl data should be rebuilt */
+    unsigned long modified_state; /* to determine if perl data should be 
rebuilt */
     ELEMENT *tree_to_build; /* C tree that needs to be built to perl before
                                calling perl functions on it */
 
@@ -474,154 +408,4 @@ typedef struct CONVERTER {
     char *current_filename;
 } CONVERTER;
 
-typedef struct TARGET_FILENAME {
-    char *target;
-    char *filename;
-} TARGET_FILENAME;
-
-typedef struct TARGET_CONTENTS_FILENAME {
-    char *target;
-    char *filename;
-    char *target_contents;
-    char *target_shortcontents;
-} TARGET_CONTENTS_FILENAME;
-
-typedef struct FILE_SOURCE_INFO {
-    char *filename;
-    char *type;
-    char *name;
-    ELEMENT *element;
-    char *path;
-} FILE_SOURCE_INFO;
-
-typedef struct FILE_SOURCE_INFO_LIST {
-    size_t number;
-    size_t space;
-    FILE_SOURCE_INFO *list;
-} FILE_SOURCE_INFO_LIST;
-
-/* used in get_perl_info and indices_in_conversion, in unfinished code */
-/* TODO remove? */
-typedef struct KEY_ALPHA {
-    char *key;
-    int alpha;
-} KEY_ALPHA;
-
-typedef struct SORTABLE_ENTRY {
-    char *index_name;
-    size_t keys_number;
-    KEY_ALPHA *keys;
-    char **entry_keys;
-    int number;
-} SORTABLE_ENTRY;
-
-typedef struct INDEX_SORTABLE_ENTRIES {
-    char *name;
-    size_t number;
-    SORTABLE_ENTRY *sortable_entries;
-} INDEX_SORTABLE_ENTRIES;
-
-#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 {
-    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;
-
-
-int xasprintf (char **ptr, const char *template, ...);
-
-void fatal (char *);
-void bug (char *);
-
-int isascii_alnum (int c);
-int isascii_alpha (int c);
-int isascii_digit (int c);
-int isascii_lower (int c);
-int isascii_upper (int c);
-size_t count_multibyte (const char *text);
-char *to_upper_or_lower_multibyte (const char *text, int lower_or_upper);
-int width_multibyte (const char *text);
-
-void delete_global_info (GLOBAL_INFO *global_info_ref);
-void delete_global_commands (GLOBAL_COMMANDS *global_commands_ref);
-
-char *normalize_encoding_name (char *text, int *possible_encoding);
-ELEMENT *item_line_parent (ELEMENT *current);
-ELEMENT *get_label_element (ELEMENT *e);
-INDEX *indices_info_index_by_name (INDEX **indices_information, char *name);
-INDEX *ultimate_index (INDEX *index);
-char *read_flag_name (char **ptr);
-int section_level (ELEMENT *section);
-char *collapse_spaces (char *text);
-char *parse_line_directive (char *line, int *retval, int *out_line_no);
-int is_content_empty (ELEMENT *tree, int do_not_ignore_index_entries);
-
-void clear_strings_list (STRING_LIST *include_dirs_list);
-void free_strings_list (STRING_LIST *strings);
-void destroy_strings_list (STRING_LIST *strings);
-void add_string (char *string, STRING_LIST *strings_list);
-void merge_strings (STRING_LIST *strings_list, STRING_LIST *merged_strings);
-
-void wipe_index (INDEX *idx);
-void wipe_index_names (INDEX **index_names);
-
-OPTIONS *new_options (void);
-void free_options (OPTIONS *options);
-COMMAND_OPTION_REF *get_command_option (OPTIONS *options, enum command_id cmd);
-
-
-void add_include_directory (char *filename, STRING_LIST *include_dirs_list);
-char *locate_include_file (char *filename, STRING_LIST *include_dirs_list);
-
-ENCODING_CONVERSION *get_encoding_conversion (char *encoding,
-                                    ENCODING_CONVERSION_LIST *encodings_list);
-char *encode_with_iconv (iconv_t our_iconv,  char *s, SOURCE_INFO 
*source_info);
-void reset_encoding_list (ENCODING_CONVERSION_LIST *encodings_list);
-char *decode_string (char *input_string, char *encoding, int *status,
-                     SOURCE_INFO *source_info);
-char *encode_string (char *input_string, char *encoding, int *status,
-                     SOURCE_INFO *source_info);
-
-EXPANDED_FORMAT *new_expanded_formats (char *format);
-void clear_expanded_formats (EXPANDED_FORMAT *formats);
-void add_expanded_format (EXPANDED_FORMAT *formats, char *format);
-int format_expanded_p (EXPANDED_FORMAT *formats, char *format);
-
-ELEMENT *trim_spaces_comment_from_content (ELEMENT *element);
-
-char *enumerate_item_representation (char *specification, int number);
-
-CONVERTER *new_converter (void);
-
-ELEMENT *get_global_document_command (GLOBAL_COMMANDS *global_commands,
-                                      enum command_id cmd,
-                                      enum command_location command_location);
-char *informative_command_value (ELEMENT *element);
-ELEMENT *set_global_document_command (CONVERTER *self, enum command_id cmd,
-                                      enum command_location command_location);
-ELEMENT *get_cmd_global_command (GLOBAL_COMMANDS *global_commands_ref,
-                                 enum command_id cmd);
 #endif
diff --git a/tp/Texinfo/XS/main/document.h b/tp/Texinfo/XS/main/document.h
index 6bb7402cf2..bb043be3c9 100644
--- a/tp/Texinfo/XS/main/document.h
+++ b/tp/Texinfo/XS/main/document.h
@@ -7,28 +7,10 @@
 #include "options_types.h"
 #include "global_commands_types.h"
 #include "tree_types.h"
+/* for ERROR_MESSAGE_LIST */
+#include "converter_types.h"
 /* for GLOBAL_INFO */
 #include "utils.h"
-/* for ERROR_MESSAGE_LIST */
-#include "errors.h"
-
-typedef struct DOCUMENT {
-    int descriptor;
-    ELEMENT *tree;
-    INDEX **index_names;
-    FLOAT_RECORD_LIST *floats;
-    FLOAT_RECORD_LIST *listoffloats;
-    ELEMENT_LIST *internal_references;
-    LABEL_LIST *labels_list;
-    LABEL_LIST *identifiers_target;
-    GLOBAL_INFO *global_info;
-    GLOBAL_COMMANDS *global_commands;
-    STRING_LIST *small_strings;
-    ELEMENT *nodes_list; /* nodes in contents of this element */
-    ELEMENT *sections_list; /* sections in contents of this element */
-    ERROR_MESSAGE_LIST *error_messages;
-    OPTIONS *options; /* for options used in structuring */
-} DOCUMENT;
 
 typedef struct TREE_AND_STRINGS {
     ELEMENT *tree;
diff --git a/tp/Texinfo/XS/main/errors.c b/tp/Texinfo/XS/main/errors.c
index 66b5e8bacf..8fdede63e5 100644
--- a/tp/Texinfo/XS/main/errors.c
+++ b/tp/Texinfo/XS/main/errors.c
@@ -29,6 +29,7 @@
 /* also for xvasprintf */
 #include "text.h"
 #include "debug.h"
+#include "converter_types.h"
 #include "errors.h"
 
 
diff --git a/tp/Texinfo/XS/main/errors.h b/tp/Texinfo/XS/main/errors.h
index e226ce8103..72c067a1fd 100644
--- a/tp/Texinfo/XS/main/errors.h
+++ b/tp/Texinfo/XS/main/errors.h
@@ -5,6 +5,7 @@
 #include <stdarg.h>
 
 #include "tree_types.h"
+#include "converter_types.h"
 #include "utils.h"
 
 void line_error (char *format, ...);
diff --git a/tp/Texinfo/XS/main/utils.h b/tp/Texinfo/XS/main/utils.h
index 898c11a296..aef863fb44 100644
--- a/tp/Texinfo/XS/main/utils.h
+++ b/tp/Texinfo/XS/main/utils.h
@@ -24,7 +24,7 @@
 #include "global_commands_types.h"
 #include "tree_types.h"
 #include "command_ids.h"
-#include "command_stack.h"
+#include "converter_types.h"
 #include "builtin_commands.h"
 
 extern const char *whitespace_chars;
@@ -46,23 +46,6 @@ extern char *html_global_unit_direction_names[];
 extern char *html_formatting_reference_names[];
 extern char *html_css_string_formatting_reference_names[];
 
-enum error_type { MSG_error, MSG_warning,
-                  MSG_document_error, MSG_document_warning };
-
-typedef struct {
-    char *message;
-    char *error_line;
-    enum error_type type;
-    int continuation;
-    SOURCE_INFO source_info;
-} ERROR_MESSAGE;
-
-typedef struct {
-    ERROR_MESSAGE *list;
-    size_t number;
-    size_t space;
-} ERROR_MESSAGE_LIST;
-
 typedef struct {
     char *encoding_name;
     iconv_t iconv;
@@ -78,21 +61,6 @@ typedef struct {
 extern ENCODING_CONVERSION_LIST output_conversions;
 extern ENCODING_CONVERSION_LIST input_conversions;
 
-typedef struct expanded_format {
-    char *format;
-    int expandedp;
-} EXPANDED_FORMAT;
-
-typedef struct GLOBAL_INFO {
-    char *input_file_name;
-    char *input_directory;
-    char *input_encoding_name;
-    int sections_level_modifier;
-    ELEMENT dircategory_direntry; /* an array of elements */
-    /* Ignored characters for index sort key */
-    IGNORED_CHARS ignored_chars;
-} GLOBAL_INFO;
-
 enum global_option_command_type {
    GO_NONE,
    GO_int,
@@ -160,25 +128,6 @@ enum global_unit_direction {
   #undef hgdt_name
 };
 
-#define SUI_TYPES_LIST \
-  sui_type(class) \
-  sui_type(direction) \
-  sui_type(order) \
-  sui_type(file_string) \
-  sui_type(target) \
-  sui_type(heading)
-
-enum special_unit_info_type {
-  #define sui_type(name) SUI_type_ ## name,
-   SUI_TYPES_LIST
-  #undef sui_type
-};
-
-/* translated from corresponding SUI_type* */
-enum special_unit_info_tree {
-   SUIT_type_heading,
-};
-
 enum command_location {
    CL_before,
    CL_last,
@@ -186,27 +135,6 @@ enum command_location {
    CL_preamble_or_first,
 };
 
-enum special_target_type {
-   ST_footnote_location,
-};
-
-#define TDS_TRANSLATED_TYPES_LIST \
-  tds_type(button) \
-  tds_type(description) \
-  tds_type(text)
-
-#define TDS_NON_TRANSLATED_TYPES_LIST \
-  tds_type(accesskey) \
-  tds_type(example) \
-  tds_type(rel)
-
-enum direction_string {
-  #define tds_type(name) TDS_type_ ## name,
-   TDS_TRANSLATED_TYPES_LIST
-   TDS_NON_TRANSLATED_TYPES_LIST
-  #undef tds_type
-};
-
 #define HCC_CONTEXT_TYPES_LIST \
   cctx_type(normal) \
   cctx_type(preformatted) \
@@ -221,259 +149,26 @@ enum conversion_context {
   #undef cctx_type
 };
 
-/* %default_formatting_references + %default_css_string_formatting_references
-   in Texinfo::HTML */
-#define HTML_FORMATTING_REFERENCES_LIST \
-  html_fr_reference(format_begin_file) \
-  html_fr_reference(format_button) \
-  html_fr_reference(format_button_icon_img) \
-  html_fr_reference(format_css_lines) \
-  html_fr_reference(format_comment) \
-  html_fr_reference(format_contents) \
-  html_fr_reference(format_element_header) \
-  html_fr_reference(format_element_footer) \
-  html_fr_reference(format_end_file) \
-  html_fr_reference(format_footnotes_segment) \
-  html_fr_reference(format_footnotes_sequence) \
-  html_fr_reference(format_heading_text) \
-  html_fr_reference(format_navigation_header) \
-  html_fr_reference(format_navigation_panel) \
-  html_fr_reference(format_node_redirection_page) \
-  html_fr_reference(format_program_string) \
-  html_fr_reference(format_protect_text) \
-  html_fr_reference(format_separate_anchor) \
-  html_fr_reference(format_titlepage) \
-  html_fr_reference(format_title_titlepage) \
-  html_fr_reference(format_translate_message_tree) \
-  html_fr_reference(format_translate_message_string) \
-
-#define HTML_CSS_FORMATTING_REFERENCES_LIST \
-  html_fr_reference(format_protect_text)
-
-enum html_formatting_reference {
-  #define html_fr_reference(name) FR_## name,
-   HTML_FORMATTING_REFERENCES_LIST
-  #undef html_fr_reference
-};
-
-enum html_css_string_formatting_reference {
-  #define html_fr_reference(name) CSSFR_## name,
-   HTML_CSS_FORMATTING_REFERENCES_LIST
-  #undef html_fr_reference
-};
-
-enum formatting_reference_status {
-   FRS_status_none,
-   FRS_status_default_set,        /* default is set, no customization (or
-                                     customization is the same as default) */
-   FRS_status_customization_set,  /* customization is set, no default, or
-                                     not the same as default */
-   FRS_status_ignored,            /* explicitely ignored. Only used for
-                                     types_conversion and commands_conversion
-                                   */
-};
+/* HTML modified state flags */
+#define HMSF_current_root            0x0001
+#define HMSF_document_context        0x0002
+#define HMSF_formatting_context      0x0004
+#define HMSF_composition_context     0x0008
+#define HMSF_preformatted_classes    0x0010
+#define HMSF_block_commands          0x0020
+#define HMSF_monospace               0x0040
+#define HMSF_top_formatting_context  0x0080
+/* for the integer variables in top document context */
+#define HMSF_top_document_ctx        0x0100
+#define HMSF_current_node            0x0200
+#define HMSF_current_output_unit     0x0400
+#define HMSF_current_filename        0x0800
+#define HMSF_converter_state         0x1000
+#define HMSF_multiple_pass           0x2000
 
 /* down here because it requires error data from before */
 #include "document.h"
 
-typedef struct VARIETY_DIRECTION_INDEX {
-    char *special_unit_variety;
-    int direction_index;
-} VARIETY_DIRECTION_INDEX;
-
-typedef struct HTML_TARGET {
-    ELEMENT *element;
-    char *target;
-    char *special_unit_filename;
-    char *node_filename;
-    char *section_filename;
-    char *contents_target;
-    char *shortcontents_target;
-
-    char *text;
-    ELEMENT *tree;
-    ELEMENT *tree_nonumber;
-    char *string;
-} HTML_TARGET;
-
-typedef struct HTML_TARGET_LIST {
-    size_t number;
-    size_t space;
-    HTML_TARGET *list;
-} HTML_TARGET_LIST;
-
-typedef struct MERGED_INDEX {
-    char *name;
-    INDEX_ENTRY *index_entries;
-    size_t index_number;
-} MERGED_INDEX;
-
-typedef struct LETTER_INDEX_ENTRIES {
-    char *letter;
-    INDEX_ENTRY **entries;
-    size_t number;
-} LETTER_INDEX_ENTRIES;
-
-typedef struct INDEX_SORTED_BY_LETTER {
-    char *name;
-    LETTER_INDEX_ENTRIES *letter_entries;
-    size_t number;
-} INDEX_SORTED_BY_LETTER;
-
-typedef struct HTML_COMMAND_CONVERSION {
-    char *element;
-    int quote; /* for style commands formatting only */
-    /* following is only for no arg command formatting */
-    int unset;
-    char *text;
-    ELEMENT *tree;
-    char *translated_converted;
-    char *translated_to_convert;
-} HTML_COMMAND_CONVERSION;
-
-typedef struct COMMAND_ID_LIST {
-    size_t number;
-    enum command_id *list;
-} COMMAND_ID_LIST;
-
-typedef struct TRANSLATED_COMMAND {
-    enum command_id cmd;
-    char *translation;
-} TRANSLATED_COMMAND;
-
-typedef struct FILE_NAME_PATH {
-    char *filename;
-    char *filepath;
-} FILE_NAME_PATH;
-
-typedef struct FILE_NAME_PATH_COUNTER {
-    char *filename;
-    char *normalized_filename;
-    char *filepath;
-    int counter;
-    int elements_in_file_count; /* only used in HTML, corresponds to
-                                   'elements_in_file_count' */
-} FILE_NAME_PATH_COUNTER;
-
-typedef struct FILE_NAME_PATH_COUNTER_LIST {
-    size_t number;
-    size_t space;
-    FILE_NAME_PATH_COUNTER *list;
-} FILE_NAME_PATH_COUNTER_LIST;
-
-typedef struct SPECIAL_UNIT_DIRECTION {
-    OUTPUT_UNIT *output_unit;
-    char *direction;
-} SPECIAL_UNIT_DIRECTION;
-
-typedef struct FORMATTING_REFERENCE {
-/* perl references. This should be SV *sv_*,
-   but we don't want to include the Perl headers everywhere; */
-    void *sv_reference;
-    void *sv_default;
-    enum formatting_reference_status status;
-} FORMATTING_REFERENCE;
-
-typedef struct HTML_FORMATTING_CONTEXT {
-    char *context_name;
-    int preformatted_number;
-    int paragraph_number;
-    int upper_case_ctx;
-    int space_protected;
-    int no_break;
-} HTML_FORMATTING_CONTEXT;
-
-typedef struct HTML_FORMATTING_CONTEXT_STACK {
-    HTML_FORMATTING_CONTEXT *stack;
-    size_t top;   /* One above last pushed context. */
-    size_t space;
-} HTML_FORMATTING_CONTEXT_STACK;
-
-typedef struct HTML_DOCUMENT_CONTEXT {
-    char *context;
-    int string_ctx;
-    int raw_ctx;
-    int verbatim_ctx;
-    int math_ctx;
-    char *document_global_context;
-    MONOSPACE_CONTEXT_STACK monospace_context;
-    COMMAND_OR_TYPE_STACK composition_context;
-    COMMAND_STACK block_commands;
-    HTML_FORMATTING_CONTEXT_STACK formatting_context;
-    STRING_STACK preformatted_classes;
-} HTML_DOCUMENT_CONTEXT;
-
-typedef struct HTML_DOCUMENT_CONTEXT_STACK {
-    HTML_DOCUMENT_CONTEXT *stack;
-    size_t top;   /* One above last pushed context. */
-    size_t space;
-} HTML_DOCUMENT_CONTEXT_STACK;
-
-typedef struct CONVERTER {
-    int converter_descriptor;
-    OPTIONS *conf;
-    OPTIONS *init_conf;
-    struct DOCUMENT *document;
-    int document_units_descriptor;
-
-    ERROR_MESSAGE_LIST *error_messages;
-    MERGED_INDEX **index_entries;
-    INDEX_SORTED_BY_LETTER **index_entries_by_letter;
-    TRANSLATED_COMMAND **translated_commands;
-    EXPANDED_FORMAT *expanded_formats;
-
-  /* output unit files API */
-    FILE_NAME_PATH_COUNTER_LIST *output_unit_files;
-
-  /* perl converter. This should be HV *hv,
-     but we don't want to include the Perl headers everywhere; */
-    void *hv;
-
-  /* maybe HTML specific */
-    char *title_titlepage;
-
-  /* HTML specific */
-    OUTPUT_UNIT **global_units_directions;
-    SPECIAL_UNIT_DIRECTION **special_units_direction_name;
-    char **special_unit_info[SUI_type_heading+1];
-    ELEMENT **special_unit_info_tree[SUIT_type_heading+1];
-    STRING_LIST *special_unit_varieties;
-    VARIETY_DIRECTION_INDEX **varieties_direction_index;
-    STRING_LIST *seen_ids;
-    HTML_TARGET_LIST *html_targets;
-    HTML_TARGET_LIST *html_special_targets[ST_footnote_location+1];
-    char **directions_strings[TDS_type_rel+1];
-    HTML_COMMAND_CONVERSION **html_command_conversion[BUILTIN_CMD_NUMBER];
-    COMMAND_ID_LIST *no_arg_formatted_cmd;
-    int code_types[ET_special_unit_element+1];
-    char *pre_class_types[ET_special_unit_element+1];
-    FORMATTING_REFERENCE
-           formatting_references[FR_format_translate_message_string+1];
-    FORMATTING_REFERENCE
-           css_string_formatting_references[CSSFR_format_protect_text+1];
-    FORMATTING_REFERENCE commands_open[BUILTIN_CMD_NUMBER];
-    FORMATTING_REFERENCE commands_conversion[BUILTIN_CMD_NUMBER];
-    FORMATTING_REFERENCE types_open[ET_special_unit_element+1];
-    FORMATTING_REFERENCE types_conversion[ET_special_unit_element+1];
-    FORMATTING_REFERENCE output_units_conversion[OU_special_unit+1];
-
-    /* state only in C converter */
-    int modified_state; /* to determine if perl data should be rebuilt */
-    ELEMENT *tree_to_build; /* C tree that needs to be built to perl before
-                               calling perl functions on it */
-
-
-    /* state common with perl converter */
-    int document_global_context;
-    int ignore_notice;
-    ELEMENT *current_root_command;
-    ELEMENT *current_node;
-    OUTPUT_UNIT *current_output_unit;
-    HTML_DOCUMENT_CONTEXT_STACK html_document_context;
-    STRING_STACK multiple_pass;
-    char *current_filename;
-} CONVERTER;
-
 typedef struct TARGET_FILENAME {
     char *target;
     char *filename;
diff --git a/tp/Texinfo/XS/structuring_transfo/transformations.c 
b/tp/Texinfo/XS/structuring_transfo/transformations.c
index 95e492a0d8..95c9c4f2b9 100644
--- a/tp/Texinfo/XS/structuring_transfo/transformations.c
+++ b/tp/Texinfo/XS/structuring_transfo/transformations.c
@@ -33,6 +33,7 @@
 #include "tree.h"
 #include "builtin_commands.h"
 #include "extra.h"
+#include "errors.h"
 #include "debug.h"
 #include "utils.h"
 /* for copy_contents normalized_menu_entry_internal_node */



reply via email to

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