texinfo-commits
[Top][All Lists]
Advanced

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

[no subject]


From: Patrice Dumas
Date: Wed, 6 Dec 2023 15:25:39 -0500 (EST)

branch: master
commit 778fd38591143a3df160f4c1e07fdba4e786712d
Author: Patrice Dumas <pertusus@free.fr>
AuthorDate: Tue Dec 5 15:19:49 2023 +0100

    * tp/Texinfo/XS/convert/call_html_perl_function.c
    (call_formatting_function_format_contents): command can be 0.
    
    * tp/Texinfo/XS/convert/convert_html.c (convert_heading_command):
    register menu tree to be built to perl.
    
    * tp/Texinfo/XS/structuring_transfo/structuring.c (print_down_menus):
    do not create menus when looking for them.
    
    * tp/Texinfo/XS/convert/convert_html.c
    (commands_internal_conversion_table): use convert_heading_command for
    all the heading commands.
    
    * tp/Texinfo/Convert/HTML.pm (_contents_inline_element),
    tp/Texinfo/XS/convert/convert_html.c (contents_inline_element): rename
    $command argument as $element and other $command as $unit_command.
    Rearrange code.
---
 ChangeLog                                       | 20 +++++++++++
 tp/Texinfo/Convert/HTML.pm                      | 17 +++++----
 tp/Texinfo/XS/convert/call_html_perl_function.c | 17 ++++++++-
 tp/Texinfo/XS/convert/convert_html.c            | 46 +++++++++++++++++++------
 tp/Texinfo/XS/structuring_transfo/structuring.c |  3 +-
 5 files changed, 80 insertions(+), 23 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index f22aa722fd..b4eb5c1623 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,23 @@
+2023-12-05  Patrice Dumas  <pertusus@free.fr>
+
+       * tp/Texinfo/XS/convert/call_html_perl_function.c
+       (call_formatting_function_format_contents): command can be 0.
+
+       * tp/Texinfo/XS/convert/convert_html.c (convert_heading_command):
+       register menu tree to be built to perl.
+
+       * tp/Texinfo/XS/structuring_transfo/structuring.c (print_down_menus):
+       do not create menus when looking for them.
+
+       * tp/Texinfo/XS/convert/convert_html.c
+       (commands_internal_conversion_table): use convert_heading_command for
+       all the heading commands.
+
+       * tp/Texinfo/Convert/HTML.pm (_contents_inline_element),
+       tp/Texinfo/XS/convert/convert_html.c (contents_inline_element): rename
+       $command argument as $element and other $command as $unit_command.
+       Rearrange code.
+
 2023-12-05  Patrice Dumas  <pertusus@free.fr>
 
        * tp/Texinfo/Convert/HTML.pm (_register_id, _id_is_registered)
diff --git a/tp/Texinfo/Convert/HTML.pm b/tp/Texinfo/Convert/HTML.pm
index ceaf7b33fb..fb43cdcbeb 100644
--- a/tp/Texinfo/Convert/HTML.pm
+++ b/tp/Texinfo/Convert/HTML.pm
@@ -6304,11 +6304,12 @@ sub _contents_inline_element($$$)
 {
   my $self = shift;
   my $cmdname = shift;
-  my $command = shift;
+  # undef unless called from @-command formatting function
+  my $element = shift;
 
   print STDERR "CONTENTS_INLINE $cmdname\n" if ($self->get_conf('DEBUG'));
   my $content = &{$self->formatting_function('format_contents')}($self,
-                                                          $cmdname, $command);
+                                                          $cmdname, $element);
   if ($content) {
     my ($special_unit_variety, $special_unit, $class_base,
         $special_unit_direction)
@@ -6317,25 +6318,22 @@ sub _contents_inline_element($$$)
     my $result = $self->html_attribute_class('div', ["element-${class_base}"]);
     my $heading;
     if ($special_unit) {
-      my $command = $special_unit->{'unit_command'};
-      my $id = $self->command_id($command);
+      my $unit_command = $special_unit->{'unit_command'};
+      my $id = $self->command_id($unit_command);
       if (defined($id) and $id ne '') {
         $result .= " id=\"$id\"";
       }
-      $heading = $self->command_text($command);
-      $heading = '' if (!defined($heading));
+      $heading = $self->command_text($unit_command);
     } else {
       # happens when called as convert() and not output()
-      #cluck "$cmdname special element not defined";
       my $heading_tree = $self->special_unit_info('heading_tree',
                                              $special_unit_variety);
       if (defined($heading_tree)) {
         $heading = $self->convert_tree($heading_tree,
                                        "convert $cmdname special heading");
-      } else {
-        $heading = '';
       }
     }
+    $heading = '' if (!defined($heading));
     $result .= ">\n";
     $result .= &{$self->formatting_function('format_heading_text')}($self,
                                   $cmdname, [$class_base.'-heading'], $heading,
@@ -10359,6 +10357,7 @@ sub _default_format_contents($$;$$)
 {
   my $self = shift;
   my $cmdname = shift;
+  # unused
   my $command = shift;
   my $filename = shift;
 
diff --git a/tp/Texinfo/XS/convert/call_html_perl_function.c 
b/tp/Texinfo/XS/convert/call_html_perl_function.c
index 35edb15597..39fbd72baa 100644
--- a/tp/Texinfo/XS/convert/call_html_perl_function.c
+++ b/tp/Texinfo/XS/convert/call_html_perl_function.c
@@ -37,6 +37,7 @@
 #include "extra.h"
 /* for newSVpv_utf8 build_texinfo_tree */
 #include "build_perl_info.h"
+#include "debug.h"
 #include "build_html_perl_state.h"
 #include "call_html_perl_function.h"
 
@@ -1291,6 +1292,7 @@ call_formatting_function_format_contents (CONVERTER *self,
   char *result = 0;
   char *result_ret;
   STRLEN len;
+  SV *command_sv;
   SV *result_sv;
   SV *formatting_reference_sv;
 
@@ -1311,6 +1313,11 @@ call_formatting_function_format_contents (CONVERTER 
*self,
 
   build_tree_to_build (&self->tree_to_build);
 
+  if (command)
+    command_sv = newRV_inc (command->hv);
+  else
+    command_sv = newSV (0);
+
   dSP;
 
   ENTER;
@@ -1321,7 +1328,7 @@ call_formatting_function_format_contents (CONVERTER *self,
 
   PUSHs(sv_2mortal (newRV_inc (self->hv)));
   PUSHs(sv_2mortal (newSVpv (cmdname, 0)));
-  PUSHs(sv_2mortal (newRV_inc (command->hv)));
+  PUSHs(sv_2mortal (command_sv));
   PUSHs(sv_2mortal (newSVpv (filename, 0)));
   PUTBACK;
 
@@ -1575,6 +1582,14 @@ call_types_conversion (CONVERTER *self, const enum 
element_type type,
       self->modified_state = 0;
     }
 
+  if (!element->hv)
+    {
+      char *element_str = print_element_debug (element, 0);
+      fprintf (stderr, "BUG: no hv: %p %s\n", element, element_str);
+      free (element_str);
+      abort ();
+    }
+
   dSP;
 
   ENTER;
diff --git a/tp/Texinfo/XS/convert/convert_html.c 
b/tp/Texinfo/XS/convert/convert_html.c
index d50e55abc1..98db9c9e9d 100644
--- a/tp/Texinfo/XS/convert/convert_html.c
+++ b/tp/Texinfo/XS/convert/convert_html.c
@@ -3187,7 +3187,7 @@ static char *html_command_text_type_name[] = {
   "text", "text_nonumber", "string", "string_nonumber"
 };
 
-/* cached, not to be freed */
+/* to be freed by caller */
 char *
 html_command_text (CONVERTER *self, const ELEMENT *command,
                    const enum html_command_text_type type)
@@ -4838,9 +4838,10 @@ convert_w_command (CONVERTER *self, const enum 
command_id cmd,
     }
 }
 
+/* command is NULL unless called from @-command formatting function */
 static char *
 contents_inline_element (CONVERTER *self, const enum command_id cmd,
-                         const ELEMENT *command)
+                         const ELEMENT *element)
 {
   char *content;
 
@@ -4848,7 +4849,7 @@ contents_inline_element (CONVERTER *self, const enum 
command_id cmd,
     fprintf (stderr, "CONTENTS_INLINE %s\n", builtin_command_name (cmd));
 
   content = call_formatting_function_format_contents (self,
-                        builtin_command_name (cmd), command, 0);
+                        builtin_command_name (cmd), element, 0);
   if (content && strlen (content))
     {
       int j;
@@ -4893,13 +4894,11 @@ contents_inline_element (CONVERTER *self, const enum 
command_id cmd,
 
               if (special_unit)
                 {
-                  ELEMENT *command = special_unit->unit_command;
-                  char *id = html_command_id (self, command);
+                  ELEMENT *unit_command = special_unit->unit_command;
+                  char *id = html_command_id (self, unit_command);
                   if (id && strlen (id))
                     text_printf (&result, " id=\"%s\"", id);
-                  heading = html_command_text (self, command, 0);
-                  if (!heading)
-                    heading = strdup ("");
+                  heading = html_command_text (self, unit_command, 0);
                 }
               else
                 { /* happens when called as convert() and not output() */
@@ -4922,6 +4921,8 @@ contents_inline_element (CONVERTER *self, const enum 
command_id cmd,
               add_string (class, classes);
               free (class);
 
+              if (!heading)
+                heading = strdup ("");
               formatted_heading
                = call_formatting_function_format_heading_text (self, 0, 
classes,
                             heading, self->conf->CHAPTER_HEADER_LEVEL, 0, 0, 
0);
@@ -5125,15 +5126,18 @@ convert_heading_command (CONVERTER *self, const enum 
command_id cmd,
               ELEMENT_LIST *menus = lookup_extra_contents (node, "menus", 0);
               if (!menus && automatic_directions)
                 {
+                  /* FIXME setup a TREE_ADDED_ELEMENTS */
                   ELEMENT *menu_node
                    = new_complete_menu_master_menu (self->conf,
                              self->document->identifiers_target, node);
 
-                  /* FIXME probably need to rebuild menu_node tree */
                   if (menu_node)
                     {
+                      add_to_element_list (&self->tree_to_build, menu_node);
                       convert_to_html_internal (self, menu_node,
                                                 &mini_toc_or_auto_menu, 0);
+                      remove_element_from_list (&self->tree_to_build,
+                                                menu_node);
                     }
                 }
             }
@@ -5496,14 +5500,34 @@ convert_contents_command (CONVERTER *self, const enum 
command_id cmd,
 /* associate command to the C function implementing the conversion */
 static COMMAND_INTERNAL_CONVERSION commands_internal_conversion_table[] = {
   {CM_w, &convert_w_command},
+
   {CM_contents, &convert_contents_command},
   {CM_shortcontents, &convert_contents_command},
   {CM_summarycontents, &convert_contents_command},
+
   {CM_node, convert_heading_command},
+  {CM_top, convert_heading_command},
+  {CM_chapter, convert_heading_command},
+  {CM_unnumbered, convert_heading_command},
+  {CM_chapheading, convert_heading_command},
+  {CM_appendix, convert_heading_command},
   {CM_section, convert_heading_command},
-  /*
+  {CM_unnumberedsec, convert_heading_command},
   {CM_heading, convert_heading_command},
-   */
+  {CM_appendixsec, convert_heading_command},
+  {CM_subsection, convert_heading_command},
+  {CM_unnumberedsubsec, convert_heading_command},
+  {CM_subheading, convert_heading_command},
+  {CM_appendixsubsec, convert_heading_command},
+  {CM_subsubsection, convert_heading_command},
+  {CM_unnumberedsubsubsec, convert_heading_command},
+  {CM_subsubheading, convert_heading_command},
+  {CM_appendixsubsubsec, convert_heading_command},
+  {CM_part, convert_heading_command},
+  {CM_appendixsection, convert_heading_command},
+  {CM_majorheading, convert_heading_command},
+  {CM_centerchap, convert_heading_command},
+
   {0, 0},
 };
 
diff --git a/tp/Texinfo/XS/structuring_transfo/structuring.c 
b/tp/Texinfo/XS/structuring_transfo/structuring.c
index a054a1a61f..b407e114dc 100644
--- a/tp/Texinfo/XS/structuring_transfo/structuring.c
+++ b/tp/Texinfo/XS/structuring_transfo/structuring.c
@@ -1808,7 +1808,7 @@ print_down_menus(ELEMENT *node, LABEL_LIST 
*identifiers_target,
 {
   ELEMENT_LIST *master_menu_contents = new_list ();
   ELEMENT_LIST *menus;
-  ELEMENT_LIST *node_menus = lookup_extra_contents (node, "menus", 1);
+  ELEMENT_LIST *node_menus = lookup_extra_contents (node, "menus", 0);
   ELEMENT_LIST *node_children;
   int i;
 
@@ -1817,7 +1817,6 @@ print_down_menus(ELEMENT *node, LABEL_LIST 
*identifiers_target,
   else
     {
       ELEMENT *current_menu = new_complete_node_menu (node, use_sections);
-      node_menus = 0;
       if (current_menu)
         {
           menus = new_list ();



reply via email to

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