texinfo-commits
[Top][All Lists]
Advanced

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

branch master updated: * tp/Texinfo/Transformations.pm (fill_gaps_in_sec


From: Patrice Dumas
Subject: branch master updated: * tp/Texinfo/Transformations.pm (fill_gaps_in_sectioning), tp/Texinfo/XS/structuring_transfo/StructuringTransfoXS.xs (fill_gaps_in_sectioning), tp/Texinfo/XS/structuring_transfo/transformations.c (fill_gaps_in_sectioning): new optional Texinfo tree argument for fill_gaps_in_sectioning to use for all the added commands headings instead of an empty @asis.
Date: Sun, 26 Nov 2023 16:24:59 -0500

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 c7565d99e5 * tp/Texinfo/Transformations.pm (fill_gaps_in_sectioning), 
tp/Texinfo/XS/structuring_transfo/StructuringTransfoXS.xs 
(fill_gaps_in_sectioning), tp/Texinfo/XS/structuring_transfo/transformations.c 
(fill_gaps_in_sectioning): new optional Texinfo tree argument for 
fill_gaps_in_sectioning to use for all the added commands headings instead of 
an empty @asis.
c7565d99e5 is described below

commit c7565d99e5832a326d3179db3e8e1a6349fa28cf
Author: Patrice Dumas <pertusus@free.fr>
AuthorDate: Sun Nov 26 22:20:42 2023 +0100

    * tp/Texinfo/Transformations.pm (fill_gaps_in_sectioning),
    tp/Texinfo/XS/structuring_transfo/StructuringTransfoXS.xs
    (fill_gaps_in_sectioning),
    tp/Texinfo/XS/structuring_transfo/transformations.c
    (fill_gaps_in_sectioning): new optional Texinfo tree argument for
    fill_gaps_in_sectioning to use for all the added commands headings
    instead of an empty @asis.
    
    * Pod-Simple-Texinfo/pod2texi.pl,
    Pod-Simple-Texinfo/manual_tests/reference_Th1.texi,
    Pod-Simple-Texinfo/manual_tests/reference_sectioning_gap.texi:
    setup a Texinfo tree with the manual name to use as
    fill_gaps_in_sectioning argument if the sectioning base level is > 0.
    
    * Pod-Simple-Texinfo/manual_tests/manual_sectioning_gap_test.sh,
    manual_tests/Module1.pod, manual_tests/Module2.pod,
    manual_tests/reference_includes/
    manual_tests/reference_modules_main.texi: new manual test with two
    modules.
---
 ChangeLog                                          | 22 +++++++++
 Pod-Simple-Texinfo/manual_tests/Module1.pod        |  7 +++
 Pod-Simple-Texinfo/manual_tests/Module2.pod        |  7 +++
 .../manual_tests/manual_sectioning_gap_test.sh     |  5 ++
 Pod-Simple-Texinfo/manual_tests/reference_Th1.texi |  2 +-
 .../manual_tests/reference_includes/Module1.texi   | 17 +++++++
 .../manual_tests/reference_includes/Module2.texi   | 17 +++++++
 .../manual_tests/reference_modules_main.texi       | 49 ++++++++++++++++++++
 .../manual_tests/reference_sectioning_gap.texi     |  2 +-
 Pod-Simple-Texinfo/pod2texi.pl                     | 53 ++++------------------
 tp/TODO                                            |  5 --
 tp/Texinfo/Transformations.pm                      | 26 ++++++++---
 .../XS/structuring_transfo/StructuringTransfoXS.xs | 14 +++++-
 .../XS/structuring_transfo/transformations.c       | 23 +++++++---
 .../XS/structuring_transfo/transformations.h       |  3 +-
 15 files changed, 185 insertions(+), 67 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 719f14278f..334dc50bcc 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,25 @@
+2023-11-26  Patrice Dumas  <pertusus@free.fr>
+
+       * tp/Texinfo/Transformations.pm (fill_gaps_in_sectioning),
+       tp/Texinfo/XS/structuring_transfo/StructuringTransfoXS.xs
+       (fill_gaps_in_sectioning),
+       tp/Texinfo/XS/structuring_transfo/transformations.c
+       (fill_gaps_in_sectioning): new optional Texinfo tree argument for
+       fill_gaps_in_sectioning to use for all the added commands headings
+       instead of an empty @asis.
+
+       * Pod-Simple-Texinfo/pod2texi.pl,
+       Pod-Simple-Texinfo/manual_tests/reference_Th1.texi,
+       Pod-Simple-Texinfo/manual_tests/reference_sectioning_gap.texi:
+       setup a Texinfo tree with the manual name to use as
+       fill_gaps_in_sectioning argument if the sectioning base level is > 0.
+
+       * Pod-Simple-Texinfo/manual_tests/manual_sectioning_gap_test.sh,
+       manual_tests/Module1.pod, manual_tests/Module2.pod,
+       manual_tests/reference_includes/
+       manual_tests/reference_modules_main.texi: new manual test with two
+       modules.
+
 2023-11-26  Gavin Smith <gavinsmith0123@gmail.com>
 
        No 'first_indent_length' option for new_formatter
diff --git a/Pod-Simple-Texinfo/manual_tests/Module1.pod 
b/Pod-Simple-Texinfo/manual_tests/Module1.pod
new file mode 100644
index 0000000000..b7e658dcdf
--- /dev/null
+++ b/Pod-Simple-Texinfo/manual_tests/Module1.pod
@@ -0,0 +1,7 @@
+=head1 NAME
+
+Module1 - The one
+
+=head1 DESCRIPTION
+
+=head3 Mod
diff --git a/Pod-Simple-Texinfo/manual_tests/Module2.pod 
b/Pod-Simple-Texinfo/manual_tests/Module2.pod
new file mode 100644
index 0000000000..c361f91325
--- /dev/null
+++ b/Pod-Simple-Texinfo/manual_tests/Module2.pod
@@ -0,0 +1,7 @@
+=head1 NAME
+
+Module2 - The two
+
+=head1 DESCRIPTION
+
+=head3 Mod
diff --git a/Pod-Simple-Texinfo/manual_tests/manual_sectioning_gap_test.sh 
b/Pod-Simple-Texinfo/manual_tests/manual_sectioning_gap_test.sh
index 1829f87cff..f90cc168a0 100755
--- a/Pod-Simple-Texinfo/manual_tests/manual_sectioning_gap_test.sh
+++ b/Pod-Simple-Texinfo/manual_tests/manual_sectioning_gap_test.sh
@@ -8,3 +8,8 @@
 ./pod2texi.pl --base-level=2 manual_tests/sectioning_gap.pod | diff -u 
manual_tests/reference_sectioning_gap.texi -
 diff -u manual_tests/reference_Th1.texi Th1.texi
 rm -f Th1.texi
+
+./pod2texi.pl --base-level=section --subdir=manual_tests/includes 
manual_tests/Module1.pod manual_tests/Module2.pod | diff -u 
manual_tests/reference_modules_main.texi -
+diff -u -r manual_tests/reference_includes manual_tests/includes
+rm -rf manual_tests/includes
+
diff --git a/Pod-Simple-Texinfo/manual_tests/reference_Th1.texi 
b/Pod-Simple-Texinfo/manual_tests/reference_Th1.texi
index 5feecccf90..b6cd57ff64 100644
--- a/Pod-Simple-Texinfo/manual_tests/reference_Th1.texi
+++ b/Pod-Simple-Texinfo/manual_tests/reference_Th1.texi
@@ -5,7 +5,7 @@
 @section Th1
 
 @node Th1 1
-@unnumberedsubsec @asis{}
+@unnumberedsubsec Th1
 
 @node Th1 Th3
 @subsubsection Th3
diff --git a/Pod-Simple-Texinfo/manual_tests/reference_includes/Module1.texi 
b/Pod-Simple-Texinfo/manual_tests/reference_includes/Module1.texi
new file mode 100644
index 0000000000..c7ecdd70b3
--- /dev/null
+++ b/Pod-Simple-Texinfo/manual_tests/reference_includes/Module1.texi
@@ -0,0 +1,17 @@
+@node Module1
+@chapter Module1
+
+@node Module1 NAME
+@section Module1 NAME
+
+Module1 - The one
+
+@node Module1 DESCRIPTION
+@section Module1 DESCRIPTION
+
+@node Module1 1
+@unnumberedsubsec Module1
+
+@node Module1 Mod
+@subsubsection Mod
+
diff --git a/Pod-Simple-Texinfo/manual_tests/reference_includes/Module2.texi 
b/Pod-Simple-Texinfo/manual_tests/reference_includes/Module2.texi
new file mode 100644
index 0000000000..54b470ad9f
--- /dev/null
+++ b/Pod-Simple-Texinfo/manual_tests/reference_includes/Module2.texi
@@ -0,0 +1,17 @@
+@node Module2
+@chapter Module2
+
+@node Module2 NAME
+@section Module2 NAME
+
+Module2 - The two
+
+@node Module2 DESCRIPTION
+@section Module2 DESCRIPTION
+
+@node Module2 1
+@unnumberedsubsec Module2
+
+@node Module2 Mod
+@subsubsection Mod
+
diff --git a/Pod-Simple-Texinfo/manual_tests/reference_modules_main.texi 
b/Pod-Simple-Texinfo/manual_tests/reference_modules_main.texi
new file mode 100644
index 0000000000..75243c7820
--- /dev/null
+++ b/Pod-Simple-Texinfo/manual_tests/reference_modules_main.texi
@@ -0,0 +1,49 @@
+\input texinfo
+@settitle top
+@shorttitlepage top
+@headings on
+
+@contents
+
+@node Top
+@top top
+
+@menu
+* Module1::
+* Module2::
+
+@detailmenu
+ --- The Detailed Node Listing ---
+
+Module1
+
+* Module1 NAME::
+* Module1 DESCRIPTION::
+
+Module1 DESCRIPTION
+
+* Module1 1::
+
+Module1
+
+* Module1 Mod::
+
+Module2
+
+* Module2 NAME::
+* Module2 DESCRIPTION::
+
+Module2 DESCRIPTION
+
+* Module2 1::
+
+Module2
+
+* Module2 Mod::
+@end detailmenu
+@end menu
+
+@include manual_tests/includes/Module1.texi
+@include manual_tests/includes/Module2.texi
+
+@bye
diff --git a/Pod-Simple-Texinfo/manual_tests/reference_sectioning_gap.texi 
b/Pod-Simple-Texinfo/manual_tests/reference_sectioning_gap.texi
index 76cf15b403..a6250d8357 100644
--- a/Pod-Simple-Texinfo/manual_tests/reference_sectioning_gap.texi
+++ b/Pod-Simple-Texinfo/manual_tests/reference_sectioning_gap.texi
@@ -22,7 +22,7 @@ Th1
 
 * Th1 1::
 
-@asis{}
+Th1
 
 * Th1 Th3::
 @end detailmenu
diff --git a/Pod-Simple-Texinfo/pod2texi.pl b/Pod-Simple-Texinfo/pod2texi.pl
index bc54e401ac..9a74d170dc 100755
--- a/Pod-Simple-Texinfo/pod2texi.pl
+++ b/Pod-Simple-Texinfo/pod2texi.pl
@@ -292,55 +292,20 @@ sub _parsed_manual_tree($$$$$)
   my $identifier_target = $document->labels_information();
 
   if ($fill_gaps_in_sectioning) {
-    Texinfo::Transformations::fill_gaps_in_sectioning($tree);
-    # there should already be nodes associated with other sections.  Therefore
-    # new nodes should only be created for the added sections.
+    my $commands_heading_content;
+    if ($self->texinfo_sectioning_base_level() > 0) {
+      my $manual_texi = Pod::Simple::Texinfo::_protect_text(
+             $self->texinfo_short_title(), 1, 1);
+      $commands_heading_content
+        = Texinfo::Parser::parse_texi_line(undef, $manual_texi);
+    }
+    Texinfo::Transformations::fill_gaps_in_sectioning($tree,
+                                                      
$commands_heading_content);
     if ($section_nodes) {
-      # FIXME the following code does not work when using XS code only:
-      # * $added_nodes is undef.  Could be modified.
-      # * the entries deleted in identifier_target are not deleted in XS.
-      #   Important?
-      # * the perl tree is directly modified to change the first node argument.
-      #   No clear way to add to XS.  Would need a way to add an API to modify
-      #   a node name, but it is not generally useful.
-      # * Texinfo::Document::register_label_element has no XS override
       my $added_nodes
         = Texinfo::Transformations::insert_nodes_for_sectioning_commands(
                                            $document, $registrar, 
$texi_parser);
       $document = Texinfo::Document::rebuild_document($document);
-      if ($self and $self->texinfo_sectioning_base_level() > 0) {
-        # prepend the manual name
-        foreach my $node (@$added_nodes) {
-          # First remove the old normalized entry
-          # FIXME should go through an API
-          delete $identifier_target->{$node->{'extra'}->{'normalized'}};
-
-          # prepare the new node Texinfo name and parse it to a Texinfo tree
-          my $node_texi = Texinfo::Convert::Texinfo::convert_to_texinfo(
-                                                      $node->{'args'}->[0]);
-          # We could have kept the asis, too, it is kept when !section_nodes
-          $node_texi =~ s/^\s*(\@asis\{\})?\s*//;
-          # complete with manual name
-          # FIXME _node_name is an internal function of Pod::Simple::Texinfo
-          # used, it is wrong to use it here.
-          my $complete_node_name = $self->_node_name($node_texi);
-          my $completed_node_tree
-            = Texinfo::Parser::parse_texi_line(undef, $complete_node_name);
-          # now recreate node arg
-          $completed_node_tree->{'type'} = 'line_arg';
-          $completed_node_tree->{'info'} = {'spaces_after_argument'
-                                                => {'text' => "\n"}};
-          $node->{'args'}->[0] = $completed_node_tree;
-
-          my $normalized_node_name
-           = Texinfo::Convert::NodeNameNormalization::convert_to_identifier(
-                                                        $completed_node_tree);
-          $node->{'extra'}->{'normalized'} = $normalized_node_name;
-
-          Texinfo::Document::register_label_element($document, $node,
-                                                    $registrar, $texi_parser);
-        }
-      }
     }
   }
   Texinfo::Structuring::sectioning_structure($tree, $registrar, $texi_parser);
diff --git a/tp/TODO b/tp/TODO
index 74a4c4bc07..4d469f92dd 100644
--- a/tp/TODO
+++ b/tp/TODO
@@ -24,11 +24,6 @@ contexts should be back to where they were before perl was 
called.  The code
 in C already registers what changed compared to last time perl was called,
 only applying that should be good.
 
-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
-Not a priority.
-
 Bugs
 ====
 
diff --git a/tp/Texinfo/Transformations.pm b/tp/Texinfo/Transformations.pm
index 4252f819b9..c0378fa782 100644
--- a/tp/Texinfo/Transformations.pm
+++ b/tp/Texinfo/Transformations.pm
@@ -127,9 +127,10 @@ sub _correct_level($$;$)
   }
 }
 
-sub fill_gaps_in_sectioning($)
+sub fill_gaps_in_sectioning($;$)
 {
   my $root = shift;
+  my $commands_heading_content = shift;
 
   my $contents_nr = scalar(@{$root->{'contents'}});
 
@@ -183,11 +184,19 @@ sub fill_gaps_in_sectioning($)
                         'info' => {'spaces_after_argument'
                                                  => {'text' => "\n",}}};
         $new_section->{'args'} = [$line_arg];
-        my $asis_command = {'cmdname' => 'asis',
-                            'parent' => $line_arg};
-        $line_arg->{'contents'} = [$asis_command];
-        $asis_command->{'args'} = [{'type' => 'brace_command_arg',
-                                    'parent' => $asis_command}];
+        my $line_content;
+        if ($commands_heading_content) {
+          $line_content
+            = Texinfo::Common::copy_contentsNonXS($commands_heading_content);
+          $line_content->{'parent'} = $line_arg;
+        } else {
+          my $asis_command = {'cmdname' => 'asis',
+                              'parent' => $line_arg};
+          $asis_command->{'args'} = [{'type' => 'brace_command_arg',
+                                      'parent' => $asis_command}];
+          $line_content = $asis_command;
+        }
+        $line_arg->{'contents'} = [$line_content];
         $new_section->{'contents'} = [{'type' => 'empty_line',
                                        'text' => "\n",
                                        'parent' => $new_section}];
@@ -964,7 +973,7 @@ C<$add_section_names_in_entries> argument is set, a menu 
entry
 name is added using the section name.  This function should be
 called after L<sectioning_structure|Texinfo::Structuring/$sections_list = 
sectioning_structure($tree, $registrar, $customization_information)>.
 
-=item $added_sections = fill_gaps_in_sectioning($tree)
+=item $added_sections = fill_gaps_in_sectioning($tree, 
$commands_heading_content)
 X<C<fill_gaps_in_sectioning>>
 
 This function adds empty C<@unnumbered> and similar commands in a tree
@@ -974,6 +983,9 @@ root, which is modified by adding the new sectioning 
commands. An array
 reference is returned, containing the added sectioning commands, or
 undef if there was no sectioning command at all in the tree root.
 
+In the default case, the added sectioning commands headings are empty.  It is
+possible to use instead the I<$commands_heading_tree> Texinfo tree element.
+
 If the sectioning commands are lowered or raised (with C<@raisesections>,
 C<@lowersection>) the tree may be modified with C<@raisesections> or
 C<@lowersection> added to some tree elements.
diff --git a/tp/Texinfo/XS/structuring_transfo/StructuringTransfoXS.xs 
b/tp/Texinfo/XS/structuring_transfo/StructuringTransfoXS.xs
index 944c4b4102..73cedd1499 100644
--- a/tp/Texinfo/XS/structuring_transfo/StructuringTransfoXS.xs
+++ b/tp/Texinfo/XS/structuring_transfo/StructuringTransfoXS.xs
@@ -48,7 +48,8 @@ MODULE = Texinfo::StructTransfXS      PACKAGE = 
Texinfo::StructTransfXS
 PROTOTYPES: ENABLE
 
 void
-fill_gaps_in_sectioning (SV *tree_in)
+fill_gaps_in_sectioning (SV *tree_in, ...)
+    PROTOTYPE: $;$
     PREINIT:
         ELEMENT_LIST *added_sections;
         DOCUMENT *document;
@@ -56,7 +57,16 @@ fill_gaps_in_sectioning (SV *tree_in)
         document = get_sv_tree_document (tree_in, "fill_gaps_in_sectioning");
         if (document)
           {
-            added_sections = fill_gaps_in_sectioning (document->tree);
+            ELEMENT *commands_heading_content = 0;
+            if (items > 1 && SvOK(ST(1)))
+              {
+                DOCUMENT *commands_heading_document
+                   = get_sv_tree_document (ST(1), 0);
+                if (commands_heading_document)
+                  commands_heading_content = commands_heading_document->tree;
+              }
+            added_sections = fill_gaps_in_sectioning (document->tree,
+                                                   commands_heading_content);
             /* cannot easily be used as it does not match with perl tree.
                Also the return would not be usable as error status */
             destroy_list (added_sections);
diff --git a/tp/Texinfo/XS/structuring_transfo/transformations.c 
b/tp/Texinfo/XS/structuring_transfo/transformations.c
index 36c88dff92..1d6f3ad6de 100644
--- a/tp/Texinfo/XS/structuring_transfo/transformations.c
+++ b/tp/Texinfo/XS/structuring_transfo/transformations.c
@@ -282,7 +282,7 @@ correct_level (ELEMENT *section, ELEMENT *parent, int 
modifier)
 }
 
 ELEMENT_LIST *
-fill_gaps_in_sectioning (ELEMENT *root)
+fill_gaps_in_sectioning (ELEMENT *root, ELEMENT *commands_heading_content)
 {
   ELEMENT_LIST *added_sections = new_list ();
   int idx_current_section = -1;
@@ -325,12 +325,11 @@ fill_gaps_in_sectioning (ELEMENT *root)
           correct_level (next_section, current_section, 1);
           while (next_section_level - current_section_level > 1)
             {
+              ELEMENT *line_content;
               ELEMENT *new_section = new_element (ET_NONE);
               ELEMENT *spaces_before_argument = new_element (ET_NONE);
               ELEMENT *line_arg = new_element (ET_line_arg);
               ELEMENT *spaces_after_argument = new_element (ET_NONE);
-              ELEMENT *asis_command = new_element (ET_NONE);
-              ELEMENT *brace_command_arg = new_element (ET_brace_command_arg);
               ELEMENT *empty_line = new_element (ET_empty_line);
 
               current_section_level++;
@@ -347,9 +346,21 @@ fill_gaps_in_sectioning (ELEMENT *root)
                                     spaces_after_argument);
               add_to_element_args (new_section, line_arg);
 
-              asis_command->cmd = CM_asis;
-              add_to_element_contents (line_arg, asis_command);
-              add_to_element_args (asis_command, brace_command_arg);
+              if (commands_heading_content)
+                {
+                  line_content = copy_contents (commands_heading_content,
+                                                ET_NONE);
+                }
+              else
+                {
+                  ELEMENT *asis_command = new_element (ET_NONE);
+                  ELEMENT *brace_command_arg
+                    = new_element (ET_brace_command_arg);
+                  asis_command->cmd = CM_asis;
+                  add_to_element_args (asis_command, brace_command_arg);
+                  line_content = asis_command;
+                }
+              add_to_element_contents (line_arg, line_content);
 
               text_append (&empty_line->text, "\n");
               add_to_element_contents (new_section, empty_line);
diff --git a/tp/Texinfo/XS/structuring_transfo/transformations.h 
b/tp/Texinfo/XS/structuring_transfo/transformations.h
index 505c4c966a..7f136b4117 100644
--- a/tp/Texinfo/XS/structuring_transfo/transformations.h
+++ b/tp/Texinfo/XS/structuring_transfo/transformations.h
@@ -5,7 +5,8 @@
 #include "tree_types.h"
 #include "document_types.h"
 
-ELEMENT_LIST *fill_gaps_in_sectioning (ELEMENT *root);
+ELEMENT_LIST *fill_gaps_in_sectioning (ELEMENT *root,
+                                   ELEMENT *commands_heading_content);
 void relate_index_entries_to_table_items_in_tree (ELEMENT *tree,
                                     INDEX **indices_information);
 void move_index_entries_after_items_in_tree (ELEMENT *tree);



reply via email to

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