texinfo-commits
[Top][All Lists]
Advanced

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

texinfo/Pod-Simple-Texinfo pod2texi.pl lib/Pod/...


From: Patrice Dumas
Subject: texinfo/Pod-Simple-Texinfo pod2texi.pl lib/Pod/...
Date: Sat, 04 Feb 2012 15:56:48 +0000

CVSROOT:        /sources/texinfo
Module name:    texinfo
Changes by:     Patrice Dumas <pertusus>        12/02/04 15:56:48

Modified files:
        Pod-Simple-Texinfo: pod2texi.pl 
        Pod-Simple-Texinfo/lib/Pod/Simple: Texinfo.pm 
        Pod-Simple-Texinfo/t: Pod-Simple-Texinfo.t 

Log message:
        Accept a texinfo sectioning command for --base-level.
        Improve formatting of refs.

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/texinfo/Pod-Simple-Texinfo/pod2texi.pl?cvsroot=texinfo&r1=1.6&r2=1.7
http://cvs.savannah.gnu.org/viewcvs/texinfo/Pod-Simple-Texinfo/lib/Pod/Simple/Texinfo.pm?cvsroot=texinfo&r1=1.8&r2=1.9
http://cvs.savannah.gnu.org/viewcvs/texinfo/Pod-Simple-Texinfo/t/Pod-Simple-Texinfo.t?cvsroot=texinfo&r1=1.5&r2=1.6

Patches:
Index: pod2texi.pl
===================================================================
RCS file: /sources/texinfo/texinfo/Pod-Simple-Texinfo/pod2texi.pl,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -b -r1.6 -r1.7
--- pod2texi.pl 28 Jan 2012 12:21:57 -0000      1.6
+++ pod2texi.pl 4 Feb 2012 15:56:48 -0000       1.7
@@ -37,6 +37,7 @@
   }
 }
 use Pod::Simple::Texinfo;
+use Texinfo::Common;
 
 {
 # A fake package to be able to use Pod::Simple::PullParser without generating
@@ -70,7 +71,7 @@
 manuals are standalone (the default).
 
 Options:
-    --base-level=NUM        level of the head1 commands.
+    --base-level=NUM|NAME   level of the head1 commands.
     --unnumbered-sections   use unumbered sections.
     --output=NAME           output to <NAME> for the first or the main manual
                             instead of standard out.
@@ -91,7 +92,16 @@
 This is free software: you are free to change and redistribute it.
 There is NO WARRANTY, to the extent permitted by law.\n"), '2012';
       exit 0;},
-  'base-level=i' => \$base_level,
+  'base-level=s' => sub {
+     if ($_[1] =~ /^[0-4]$/) {
+       $base_level = $_[1];
+     } elsif (defined($Texinfo::Common::command_structuring_level{$_[1]})) {
+       $base_level = $Texinfo::Common::command_structuring_level{$_[1]};
+     } else {
+       die sprintf(__("%s: wrong argument for --base-level.\n"), 
+                   $real_command_name);
+     }
+   },
   'unnumbered-sections!' => \$unnumbered_sections,
   'output|o=s' => \$output,
   'top=s' => \$top,
@@ -146,7 +156,8 @@
   if ($outfile eq '-') {
     $fh = *STDOUT;
   } else {
-    open (OUT, ">$outfile") or die "Open $outfile: $!\n";
+    open (OUT, ">$outfile") or die sprintf(__("%s: Open %s: %s.\n"), 
+                                          $real_command_name, $outfile, $!);
     $fh = *OUT;
   }
   # FIXME should use =encoding
@@ -163,7 +174,8 @@
   
   $new->parse_file($file);
   if ($outfile ne '-') {
-    close($fh) or die "Close $outfile: $!\n";
+    close($fh) or die sprintf (__("%s: Close %s: %s.\n"), 
+                               $real_command_name, $outfile, $!);
   }
   $file_nr++;
 }
@@ -172,7 +184,8 @@
 if ($base_level > 0) {
   my $fh;
   if ($output ne '-') {
-    open (OUT, ">$output") or die "Open $output: $!\n";
+    open (OUT, ">$output") or die sprintf(__("%s: Open %s: %s.\n"), 
+                                          $real_command_name, $output, $!);
     $fh = *OUT;
   } else {
     $fh = *STDOUT;
@@ -188,6 +201,7 @@
   print $fh "address@hidden Top\n";
   # not escaped on purpose, user may want to use @-commands
   print $fh "address@hidden $top\n\n";
+  print $fh "address@hidden";
   foreach my $include (@included) {
     my $file = $include->[1];
     print $fh "address@hidden ".Pod::Simple::Texinfo::_protect_text 
($file)."\n";
@@ -195,12 +209,14 @@
   print $fh "address@hidden";
   
   if ($output ne '-') {
-    close($fh) or die "Close $output: $!\n";
+    close($fh) or die sprintf (__("%s: Close %s: %s.\n"), 
+                               $real_command_name, $output, $!);
   }
 }
 
 if (defined($output) and $output eq '-') {
-  close (STDOUT) or die "Close stdout: $!\n";
+  close(STDOUT) or die sprintf (__("%s: Close stdout: %s.\n"), 
+                               $real_command_name, $!);
 }
 
 1;
@@ -225,12 +241,19 @@
 
 =over
 
-=item B<--base-level>=I<NUM>
+=item B<--base-level>=I<NUM|NAME>
 
-Sets the level of the head1 commands.  1 is for the @chapter/@unnumbered 
-level.  If set to 0, the head1 commands level is still 1, but the output 
-manual is considered to be a standalone manual.  If not 0, the pod file is 
-rendered as a fragment of a Texinfo manual.
+Sets the level of the head1 commands.  It may be an integer or a Texinfo
+sectioning command.  If it is a Texinfo sectioning command the corresponding
+level is used.  If the resulting level is 1, this corresponds to 
address@hidden/@unnumbered level.  If set to 0, the head1 commands level is 
+still 1, but the output manual is considered to be a standalone manual.
+
+If the level is not 0, the pod file is rendered as a fragment of a 
+Texinfo manual.  In that case, each pod file has an additional sectioning
+command one level above the head1 commands level added for the whole
+file.  Therefore if you want to have each pod file as a chapter, you should
+use C<section> as the base level.
 
 =item B<--output>=I<NAME>
 

Index: lib/Pod/Simple/Texinfo.pm
===================================================================
RCS file: 
/sources/texinfo/texinfo/Pod-Simple-Texinfo/lib/Pod/Simple/Texinfo.pm,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -b -r1.8 -r1.9
--- lib/Pod/Simple/Texinfo.pm   3 Feb 2012 17:48:25 -0000       1.8
+++ lib/Pod/Simple/Texinfo.pm   4 Feb 2012 15:56:48 -0000       1.9
@@ -253,16 +253,6 @@
   return Texinfo::Convert::Texinfo::convert($tree);
 }
 
-sub _is_title($)
-{
-# Regexp from Pod::Simple::PullParser
-  my $title = shift;
-  return ($title =~ m/^(NAME | TITLE | VERSION | AUTHORS? | DESCRIPTION | 
SYNOPSIS
-             | COPYRIGHT | LICENSE | NOTES? | FUNCTIONS? | METHODS?
-             | CAVEATS? | BUGS? | SEE\ ALSO | SWITCHES | ENVIRONMENT)$/sx);
-
-}
-
 sub _section_manual_to_node_name($$$)
 {
   my $self = shift;
@@ -270,8 +260,7 @@
   my $section = shift;
   my $base_level = shift;
 
-  if (defined($manual) and $base_level > 0
-      and _is_title($section)) {
+  if (defined($manual) and $base_level > 0) {
     return "$manual $section";
   } else {
     return $section;
@@ -424,8 +413,8 @@
         if ($tagname eq 'L') {
           my $linktype = $token->attr('type');
           my $content_implicit = $token->attr('content-implicit');
-          #print STDERR " L: $linktype";
-          my ($url_arg, $texinfo_node, $texinfo_manual);
+          #print STDERR " L: $linktype\n";
+          my ($url_arg, $texinfo_node, $texinfo_manual, $texinfo_section);
           if ($linktype eq 'man') {
             # NOTE: the .'' is here to force the $token->attr to ba a real
             # string and not an object.
@@ -453,8 +442,7 @@
             }
             $replacement_arg = _protect_text($replacement_arg);
             _output($fh, address@hidden, "address@hidden,, $replacement_arg}");
-          } else {
-            if ($linktype eq 'url') {
+          } elsif ($linktype eq 'url') {
               # NOTE: the .'' is here to force the $token->attr to be a real
               # string and not an object.
               $url_arg = _protect_comma(_protect_text($token->attr('to').''));
@@ -463,35 +451,51 @@
               my $section = $token->attr('section');
               $manual .= '' if (defined($manual));
               $section .= '' if (defined($section));
-              #print STDERR "$manual/$section\n";
+            if (0) {
+              my $section_text = 'UNDEF'; 
+              if (defined($section)) {
+                $section_text = $section;
+              }
+              my $manual_text = 'UNDEF';
+              if (defined($manual)) {
+                $manual_text = $manual;
+              } 
+              print STDERR "L: $linktype $manual_text/$section_text\n";
+            }
               if (defined($manual)) {
                 if (! defined($section) or $section !~ m/\S/) {
                   if ($self->{'texinfo_internal_pod_manuals_hash'}->{$manual}) 
{
                     $section = 'NAME';
-                  } else {
-                    $section = 'Top';
                   }
                 }
                 if ($self->{'texinfo_internal_pod_manuals_hash'}->{$manual}) {
                   $texinfo_node =
-                   $self->_section_manual_to_node_name($manual, $section, 1);
+                 $self->_section_manual_to_node_name($manual, $section, 
+                                     $self->texinfo_sectioning_base_level);
                 } else {
                   $texinfo_manual = 
_protect_text(_pod_title_to_file_name($manual));
+                if (defined($section)) {
                   $texinfo_node = $section;
+                } else {
+                  $texinfo_node = '';
+                }
                 }
               } elsif (defined($section) and $section =~ m/\S/) {
-                $texinfo_node = $section;
+              $texinfo_node =
+               $self->_section_manual_to_node_name(
+                                     $self->{'texinfo_short_title'}, $section, 
+                                     $self->texinfo_sectioning_base_level);
+              $texinfo_section = _normalize_texinfo_name(
+                 _protect_comma(_protect_text($section)), 'section');
               }
-              $texinfo_node = 'Top' if (!defined($texinfo_node));
               $texinfo_node = _normalize_texinfo_name(
-                                 _protect_text($texinfo_node), 'anchor');
-              #$texinfo_node = _protect_comma(_protect_text($texinfo_node));
-            }
+                    _protect_comma(_protect_text($texinfo_node)), 'anchor');
+
             # for pod, 'to' is the pod manual name.  Then 'section' is the 
             # section.
           }
           push @format_stack, [$linktype, $content_implicit, $url_arg, 
-                               $texinfo_manual, $texinfo_node];
+                               $texinfo_manual, $texinfo_node, 
$texinfo_section];
           #if (defined($to)) {
           #  print STDERR " | $to\n";
           #} else { 
@@ -574,7 +578,7 @@
         } elsif ($tagname eq 'L') {
           my $format = pop @format_stack;
           my ($linktype, $content_implicit, $url_arg, 
-              $texinfo_manual, $texinfo_node) = @$format;
+              $texinfo_manual, $texinfo_node, $texinfo_section) = @$format;
           if ($linktype ne 'man') {
             my $explanation;
             if (defined($result) and $result =~ m/\S/ and !$content_implicit) {
@@ -595,13 +599,19 @@
                          "address@hidden,$explanation,, $texinfo_manual}");
               } elsif (defined($explanation)) {
                 _output($fh, address@hidden,
-                       "address@hidden, $explanation}");
+                       "address@hidden,$explanation,$explanation}");
+              } else {
+                if (defined($texinfo_section) 
+                    and $texinfo_section ne $texinfo_node) {
+                  _output($fh, address@hidden,
+                           "address@hidden,, $texinfo_section}");
               } else {
                 _output($fh, address@hidden,
                          "address@hidden");
               }
             }
           }
+          }
         } elsif ($tagname eq 'X') {
           my $next_token = $self->get_token();
           if ($next_token) {

Index: t/Pod-Simple-Texinfo.t
===================================================================
RCS file: /sources/texinfo/texinfo/Pod-Simple-Texinfo/t/Pod-Simple-Texinfo.t,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -b -r1.5 -r1.6
--- t/Pod-Simple-Texinfo.t      3 Feb 2012 17:48:25 -0000       1.5
+++ t/Pod-Simple-Texinfo.t      4 Feb 2012 15:56:48 -0000       1.6
@@ -6,7 +6,7 @@
 # change 'tests => 1' to 'tests => last_test_to_print';
 
 use Test::More;
-BEGIN { plan tests => 11 };
+BEGIN { plan tests => 12 };
 use Pod::Simple::Texinfo;
 ok(1); # If we made it this far, we're ok.
 
@@ -143,10 +143,10 @@
 =item a L<pod2latex|pod2latex>
 
 ', '@table @asis
address@hidden a @ref{Top, pod2text,, pod2text}
address@hidden a @ref{, pod2text,, pod2text}
 @anchor{a }
 
address@hidden a @ref{Top, pod2latex,, pod2latex}
address@hidden a @ref{, pod2latex,, pod2latex}
 @anchor{a  1}
 
 @end table
@@ -158,12 +158,34 @@
 
 ', 'comma in head1');
 
+run_test('=head1 a, b
+
+=over
+
+=item c, d
+
+=back
+
+L</a, b>. L</c, d>.
+', '@chapter a, b
address@hidden@comma{} b}
+
address@hidden @asis
address@hidden c, d
address@hidden@comma{} d}
+
address@hidden table
+
address@hidden@comma{} b}. @address@hidden d}.
+
+', 'comma in refs');
+
 run_test('=head1 (man) t
 
 L</(man) t>', '@chapter (man) t
 @address@hidden(}man) t}
 
address@hidden@asis{(}man) t}
address@hidden@asis{(}man) t,, (man) t}
 
 ', 'node beginning with a parenthesis');
 



reply via email to

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