texinfo-commits
[Top][All Lists]
Advanced

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

texinfo/Pod-Simple-Texinfo Makefile.am pod2texi...


From: Patrice Dumas
Subject: texinfo/Pod-Simple-Texinfo Makefile.am pod2texi...
Date: Sat, 21 Jan 2012 22:39:34 +0000

CVSROOT:        /sources/texinfo
Module name:    texinfo
Changes by:     Patrice Dumas <pertusus>        12/01/21 22:39:34

Modified files:
        Pod-Simple-Texinfo: Makefile.am pod2texi.pl 
        Pod-Simple-Texinfo/lib/Pod/Simple: Texinfo.pm 
        Pod-Simple-Texinfo/t: Pod-Simple-Texinfo.t 
Added files:
        Pod-Simple-Texinfo: prove.sh 

Log message:
        Remove index entries from inside tags, instead put them before or after.
        
        Handle better end of lines.
        
        Add real tests.

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/texinfo/Pod-Simple-Texinfo/Makefile.am?cvsroot=texinfo&r1=1.1&r2=1.2
http://cvs.savannah.gnu.org/viewcvs/texinfo/Pod-Simple-Texinfo/pod2texi.pl?cvsroot=texinfo&r1=1.3&r2=1.4
http://cvs.savannah.gnu.org/viewcvs/texinfo/Pod-Simple-Texinfo/prove.sh?cvsroot=texinfo&rev=1.1
http://cvs.savannah.gnu.org/viewcvs/texinfo/Pod-Simple-Texinfo/lib/Pod/Simple/Texinfo.pm?cvsroot=texinfo&r1=1.3&r2=1.4
http://cvs.savannah.gnu.org/viewcvs/texinfo/Pod-Simple-Texinfo/t/Pod-Simple-Texinfo.t?cvsroot=texinfo&r1=1.1&r2=1.2

Patches:
Index: Makefile.am
===================================================================
RCS file: /sources/texinfo/texinfo/Pod-Simple-Texinfo/Makefile.am,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -b -r1.1 -r1.2
--- Makefile.am 19 Jan 2012 20:38:11 -0000      1.1
+++ Makefile.am 21 Jan 2012 22:39:33 -0000      1.2
@@ -3,7 +3,8 @@
 EXTRA_DIST = Changes \
  Makefile.PL \
  MANIFEST \
- t/Pod-Simple-Texinfo.t 
+ t/Pod-Simple-Texinfo.t \
+ $(TESTS)
 
 modulesdir = $(pkgdatadir)/Pod-Simple-Texinfo/Pod/Simple/
 
@@ -14,3 +15,4 @@
        sed -e 's,address@hidden@],$(datadir),g' $(srcdir)/$< >$@
        chmod a+x $@
 
+TESTS = prove.sh

Index: pod2texi.pl
===================================================================
RCS file: /sources/texinfo/texinfo/Pod-Simple-Texinfo/pod2texi.pl,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -b -r1.3 -r1.4
--- pod2texi.pl 20 Jan 2012 22:49:29 -0000      1.3
+++ pod2texi.pl 21 Jan 2012 22:39:33 -0000      1.4
@@ -91,6 +91,7 @@
 my @manuals;
 my @all_manual_names;
 
+# First gather all the manual names
 foreach my $file (@ARGV) {
   # not really used, only the manual name is used.
   my $parser = Pod::Simple::PullParserRun->new();
@@ -99,7 +100,7 @@
   if (defined($short_title) and $short_title =~ m/\S/) {
     push @manuals, $short_title;
     push @all_manual_names, $short_title;
-    #print STDERR "$short_title\n";
+    #print STDERR "NEW MANUAL: $short_title\n";
   } else {
     push @all_manual_names, undef;
   }

Index: lib/Pod/Simple/Texinfo.pm
===================================================================
RCS file: 
/sources/texinfo/texinfo/Pod-Simple-Texinfo/lib/Pod/Simple/Texinfo.pm,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -b -r1.3 -r1.4
--- lib/Pod/Simple/Texinfo.pm   20 Jan 2012 22:49:29 -0000      1.3
+++ lib/Pod/Simple/Texinfo.pm   21 Jan 2012 22:39:34 -0000      1.4
@@ -168,7 +168,7 @@
       }
     }
     if (defined($setfilename) and $setfilename =~ m/\S/) {
-      $setfilename = _protect_text($setfilename);
+      $setfilename = _protect_text($setfilename, 1);
       $setfilename .= '.info';
       print $fh "address@hidden $setfilename\n\n"
     }
@@ -177,38 +177,60 @@
 
     my $title = $self->get_title();
     if (defined($title) and $title =~ m/\S/) {
-      print $fh "address@hidden "._protect_text($title)."\n\n";
+      print $fh "address@hidden "._protect_text($title, 1)."\n\n";
     }
     print $fh "address@hidden Top\n";
     if (defined($self->{'texinfo_short_title'})) {
-       print $fh "address@hidden 
"._protect_text($self->{'texinfo_short_title'})."\n\n";
+       print $fh "address@hidden 
"._protect_text($self->{'texinfo_short_title'}, 1)."\n\n";
     }
   } elsif (defined($self->{'texinfo_short_title'})
            and $self->texinfo_add_upper_sectioning_command) {
       my $level = $self->texinfo_sectioning_base_level() - 1;
       print $fh "address@hidden>{'texinfo_sectioning_commands'}->[$level] "
-         ._protect_text($self->{'texinfo_short_title'})."\n\n";
+         ._protect_text($self->{'texinfo_short_title'}, 1)."\n\n";
   }
 }
 
 
-sub _output($$$)
+sub _output($$$;$)
 {
   my $fh = shift;
   my $accumulated_stack = shift;
   my $text = shift;
+  my $out = shift;
 
   if (scalar(@$accumulated_stack)) {
-    $accumulated_stack->[-1] .= $text;
+    if ($out) {
+      $accumulated_stack->[-1]->{'out'} .= $text;
+    } else {
+      $accumulated_stack->[-1]->{'text'} .= $text;
+    }
   } else {
     print $fh $text;
   }
 }
 
-sub _protect_text($)
+sub _begin_context($$)
+{
+  my $accumulated_stack = shift;
+  my $tag = shift;
+  push @$accumulated_stack, {'text' => '', 'tag' => $tag, 
+                             'out' => ''};
+}
+
+sub _end_context($)
+{
+  my $accumulated_stack = shift;
+  my $previous_context = pop @$accumulated_stack;
+  return ($previous_context->{'text'}, $previous_context->{'out'});
+}
+
+sub _protect_text($;$)
 {
   my $text = shift;
+  my $remove_new_lines = shift;
   cluck if (!defined($text));
+  $text =~ s/\n/ /g if ($remove_new_lines);
   $text =~ s/(address@hidden)/address@hidden/g;
   return $text;
 }
@@ -260,6 +282,7 @@
   my $self = shift;
   my $texinfo_node_name = shift;
 
+  chomp $texinfo_node_name;
   $texinfo_node_name 
      = $self->_section_manual_to_node_name($self->{'texinfo_short_title'},
                                           $texinfo_node_name,
@@ -313,6 +336,7 @@
 );
 
 my %environment_commands = (
+  'Verbatim' => 'verbatim',
   'over-text' => 'table @asis',
   'over-bullet' => 'itemize',
   'over-number' => 'enumerate',
@@ -326,6 +350,16 @@
   'encoding' => 'documentencoding'
 );
 
+foreach my $tag (keys(%head_commands_level)) {
+  $line_commands{$tag} = 1;
+}
+
+my %tags_index_before;
+my %context_tags;
+foreach my $context_tag (keys(%line_commands), 'L', 'X', 'Para') {
+  $context_tags{$context_tag} = 1;
+}
+
 # do not appear as parsed token
 # E entity/character
 sub _convert_pod($)
@@ -344,28 +378,8 @@
     #print STDERR $token->dump()."\n";
     if ($type eq 'start') {
       my $tagname = $token->tagname();
-      if ($head_commands_level{$tagname} or $tagname eq 'item-text') {
-        push @accumulated_output, '';
-      } elsif ($tag_commands{$tagname}) {
-        _output($fh, address@hidden, "address@hidden");
-      } elsif ($tagname eq 'Verbatim') {
-        _output($fh, address@hidden, '@verbatim'."\n");
-        push @format_stack, 'verbatim';
-      } elsif ($environment_commands{$tagname}) {
-        _output($fh, address@hidden, "address@hidden");
-      } elsif ($tagname eq 'for') {
-        my $target = $token->attr('target');
-        push @format_stack, $target;
-        if ($self->{'texinfo_raw_format_commands'}->{$target}) {
-          _output($fh, address@hidden, 
-             "address@hidden>{'texinfo_raw_format_commands'}->{$target}\n");
-        } elsif ($self->{'texinfo_if_format_commands'}->{$target}) {
-          _output($fh, address@hidden, 
-             "address@hidden>{'texinfo_if_format_commands'}->{$target}\n");
-        }
-      } elsif ($line_commands{$tagname}) {
-        _output($fh, address@hidden,"address@hidden ");
-      } elsif ($tagname eq 'L') {
+      if ($context_tags{$tagname}) {
+        if ($tagname eq 'L') {
         my $linktype = $token->attr('type');
         my $content_implicit = $token->attr('content-implicit');
         #print STDERR " L: $linktype";
@@ -428,7 +442,6 @@
           # for pod, 'to' is the pod manual name.  Then 'section' is the 
           # section.
         }
-        push @accumulated_output, '';
         push @format_stack, [$linktype, $content_implicit, $url_arg, 
                              $texinfo_manual, $texinfo_node];
         #if (defined($to)) {
@@ -437,8 +450,25 @@
         #  print STDERR "\n";
         #}
         #print STDERR $token->dump."\n";
-      } elsif ($tagname eq 'X') {
-        _output($fh, address@hidden, "address@hidden ");
+        }
+        _begin_context(address@hidden, $tagname);
+      } elsif ($tag_commands{$tagname}) {
+        _output($fh, address@hidden, "address@hidden");
+      } elsif ($environment_commands{$tagname}) {
+        _output($fh, address@hidden, "address@hidden");
+        if ($tagname eq 'Verbatim') {
+          push @format_stack, 'verbatim';
+        }
+      } elsif ($tagname eq 'for') {
+        my $target = $token->attr('target');
+        push @format_stack, $target;
+        if ($self->{'texinfo_raw_format_commands'}->{$target}) {
+          _output($fh, address@hidden, 
+             "address@hidden>{'texinfo_raw_format_commands'}->{$target}\n");
+        } elsif ($self->{'texinfo_if_format_commands'}->{$target}) {
+          _output($fh, address@hidden, 
+             "address@hidden>{'texinfo_if_format_commands'}->{$target}\n");
+        }
       }
     } elsif ($type eq 'text') {
       my $text;
@@ -450,63 +480,30 @@
         $text = $token->text();
       }
       _output($fh, address@hidden, $text);
-      my $next_token = $self->get_token();
-      if ($next_token) {
-        if ($next_token->type() eq 'start' and $next_token->tagname() eq 'X') {
-          print $fh "\n";
-        }
-        $self->unget_token($next_token);
-      }
     } elsif ($type eq 'end') {
       my $tagname = $token->tagname();
-      my $result;
+      if ($context_tags{$tagname}) {
+        my ($result, $out) = _end_context(address@hidden);
+        if ($line_commands{$tagname}) {
+          my $command;
+          if ($head_commands_level{$tagname}) {
+            $command = $self->{'texinfo_head_commands'}->{$tagname};
+          } elsif ($line_commands{$tagname}) {
+            $command = $line_commands{$tagname};
+          }
+
       if ($head_commands_level{$tagname} or $tagname eq 'item-text') {
-        my $command_result = pop @accumulated_output;
-        my $node_name = _prepare_anchor ($self, $command_result);
+            chomp ($result);
+            $result =~ s/\n/ /g;
+            my $node_name = _prepare_anchor ($self, $result);
         #print $fh "address@hidden $node_name\n";
-        if ($head_commands_level{$tagname}) {
-          my $command;
-          $command 
-            = $self->{'texinfo_head_commands'}->{$tagname};
-          _output($fh, address@hidden, "address@hidden $command_result\n");
-        } else {
-          _output($fh, address@hidden, 
-                  "address@hidden $command_result\n");
+            $result .= "address@hidden";
         }
-        _output($fh, address@hidden, "address@hidden");
-        _output($fh, address@hidden, "\n") if ($head_commands_level{$tagname});
+          _output($fh, address@hidden, "address@hidden $result\n$out\n");
       } elsif ($tagname eq 'Para') {
-        _output($fh, address@hidden, "\n\n");
-        #my $next_token = $self->get_token();
-        #if ($next_token) {
-        #  if ($next_token->type() ne 'start' 
-        #      or $next_token->tagname() ne 'Para') {
-        #    print $fh "\n";
-        #  }
-        #  $self->unget_token($next_token);
-        #}
-      } elsif ($tag_commands{$tagname}) {
-        _output($fh, address@hidden, "}");
-      } elsif ($tagname eq 'Verbatim') {
-        pop @format_stack;
-        _output($fh, address@hidden, "\n".'@end verbatim'."\n\n");
-      } elsif ($environment_commands{$tagname}) {
-        my $tag = $environment_commands{$tagname};
-        $tag =~ s/ .*//;
-        _output($fh, address@hidden, "address@hidden $tag\n\n");
-      } elsif ($tagname eq 'for') {
-        my $target = pop @format_stack;
-        if ($self->{'texinfo_raw_format_commands'}->{$target}) {
-          _output($fh, address@hidden, 
-                  "address@hidden 
$self->{'texinfo_raw_format_commands'}->{$target}\n");
-        } elsif ($self->{'texinfo_if_format_commands'}->{$target}) {
-          _output($fh, address@hidden, 
-                  "address@hidden 
if$self->{'texinfo_if_format_commands'}->{$target}\n");
-        }
-      } elsif ($line_commands{$tagname}) {
-        _output($fh, address@hidden, "\n");
+          _output($fh, address@hidden, "$out$result\n\n");
       } elsif ($tagname eq 'L') {
-        my $result = pop @accumulated_output;
+          my ($result, $postponed) = _end_context(address@hidden);
         my $format = pop @format_stack;
         my ($linktype, $content_implicit, $url_arg, 
             $texinfo_manual, $texinfo_node) = @$format;
@@ -530,7 +527,7 @@
                        "address@hidden,$explanation,, $texinfo_manual}");
             } elsif (defined($explanation)) {
               _output($fh, address@hidden,
-                       "address@hidden,$explanation}");
+                       "address@hidden, $explanation}");
             } else {
               _output($fh, address@hidden,
                        "address@hidden");
@@ -541,10 +538,37 @@
         my $next_token = $self->get_token();
         if ($next_token) {
           if ($next_token->type() eq 'text') {
-            _output($fh, address@hidden, "\n");
+              my $next_text = $next_token->text;
+              $next_text =~ s/^\s*//;
+              $next_token->text($next_text);
+              #_output($fh, address@hidden, "\n");
           }
           $self->unget_token($next_token);
         }
+          chomp ($result);
+          $result =~ s/\n/ /g;
+          $result .= "\n";
+          _output($fh, address@hidden, "address@hidden $result", 1);
+        }
+      } elsif ($tag_commands{$tagname}) {
+        _output($fh, address@hidden, "}");
+      } elsif ($environment_commands{$tagname}) {
+        if ($tagname eq 'Verbatim') {
+          pop @format_stack;
+          _output($fh, address@hidden, "\n");
+        }
+        my $tag = $environment_commands{$tagname};
+        $tag =~ s/ .*//;
+        _output($fh, address@hidden, "address@hidden $tag\n\n");
+      } elsif ($tagname eq 'for') {
+        my $target = pop @format_stack;
+        if ($self->{'texinfo_raw_format_commands'}->{$target}) {
+          _output($fh, address@hidden, 
+                  "address@hidden 
$self->{'texinfo_raw_format_commands'}->{$target}\n");
+        } elsif ($self->{'texinfo_if_format_commands'}->{$target}) {
+          _output($fh, address@hidden, 
+                  "address@hidden 
if$self->{'texinfo_if_format_commands'}->{$target}\n");
+        }
       }
     }
   }

Index: t/Pod-Simple-Texinfo.t
===================================================================
RCS file: /sources/texinfo/texinfo/Pod-Simple-Texinfo/t/Pod-Simple-Texinfo.t,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -b -r1.1 -r1.2
--- t/Pod-Simple-Texinfo.t      19 Jan 2012 20:03:13 -0000      1.1
+++ t/Pod-Simple-Texinfo.t      21 Jan 2012 22:39:34 -0000      1.2
@@ -6,10 +6,100 @@
 # change 'tests => 1' to 'tests => last_test_to_print';
 
 use Test::More;
-BEGIN { plan tests => 1 };
+BEGIN { plan tests => 4 };
 use Pod::Simple::Texinfo;
 ok(1); # If we made it this far, we're ok.
 
 #########################
 
+sub run_test($$$)
+{
+  my $in = shift;
+  my $out = shift;
+  my $name = shift;
+
+  my $parser = Pod::Simple::Texinfo->new();
+  $parser->set_source(\$in);
+  my $result;
+  $parser->output_string(\$result);
+  $parser->bare_output(1);
+  $parser->run();
+  if (defined($out)) {
+    is ($result, $out, $name);
+  } else {
+    print "$name:\n";
+    print STDERR $result;
+  }
+}
+
+run_test ('=head1 T
+X<aaa>
+',
+'@chapter T
address@hidden
address@hidden aaa
+
+', 'index in head');
+
+run_test ('=head1 T
+
+Para X<bb>
+in para X<cc>  
+qtil X<ff> ggg
+n X<ww> X<ff> C<aa>.
+C<JJ> X<tt>.
+X<-r>X<+p>
+X<fff>
+X<WWW>
+I<GG>X<DD>C<MM>.
+',
+'@chapter T
address@hidden
+
address@hidden bb
address@hidden cc
address@hidden ff
address@hidden ww
address@hidden ff
address@hidden tt
address@hidden -r
address@hidden +p
address@hidden fff
address@hidden WWW
address@hidden DD
+Para in para qtil ggg
+n @code{aa}.
address@hidden .
address@hidden@code{MM}.
+
+', 'index in paragaph');
+
+run_test('=over
+
+=item a
+X<it> b
+
+=item c
+X<C<code>>
+
+Para
+
+=back
+',
+'@table @asis
address@hidden a b
address@hidden b}
address@hidden it
+
address@hidden c
address@hidden
address@hidden @code{code}
+
+Para
+
address@hidden table
+
+', 'index in item-text');
+
+1;
 

Index: prove.sh
===================================================================
RCS file: prove.sh
diff -N prove.sh
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ prove.sh    21 Jan 2012 22:39:33 -0000      1.1
@@ -0,0 +1,10 @@
+#! /bin/sh
+
+if [ z"$srcdir" = 'z' ]; then
+  srcdir='.'
+fi
+
+tpdir=$srcdir/../tp
+
+prove -I "$tpdir" -I "$tpdir"/maintain/lib/Unicode-EastAsianWidth/lib/ -I 
"$tpdir"/maintain/lib/libintl-perl/lib -I 
"$tpdir"/maintain/lib/Text-Unidecode/lib/ -I "$srcdir"/lib "$srcdir"/t/*.t
+#prove -I "$tpdir" -I "$srcdir"/lib "$srcdir"/t/*.t



reply via email to

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