[Po4a-commits] "po4a/lib/Locale/Po4a LaTeX.pm, 1.16, 1.17 TeX.pm, 1.95, 1.96 Texinfo.pm, 1.9, 1.10"

Nicolas FRANCOIS nekral-guest at alioth.debian.org
Wed Sep 19 21:32:32 UTC 2007


Update of /cvsroot/po4a/po4a/lib/Locale/Po4a
In directory alioth:/tmp/cvs-serv20147/lib/Locale/Po4a

Modified Files:
	LaTeX.pm TeX.pm Texinfo.pm 
Log Message:
 * lib/Locale/Po4a/TeX.pm: Add a no_wrap argument to the command,
   environment (last argument) and translate_buffer functions (second
   argument, before the @environments).
   Currently, when $no_wrap equals 1 the no-wrap flag is forced.
   A value of 0 could force the removal of the no-wrap flag and undef
   could be used to specify that the current function can decide.
   These last 2 values are not differentiated currently.
 * lib/Locale/Po4a/TeX.pm: Fix debugging (do not display $t1.$t2,
   but $t1$t2).
 * lib/Locale/Po4a/LaTeX.pm: Add the no_wrap argument to the
   'documentclass' command function, and passe it to the
   generic_command function.
 * lib/Locale/Po4a/Texinfo.pm: Add a no_wrap argument to the
   command and environment function. Call translate_buffer with the
   additional no_wrap parameter and add a parameter to the customized
   translate_buffer functions (for the menu and ignore environments).
 * lib/Locale/Po4a/Texinfo.pm: (line_command): line_command does
   not need to add the command name to the list of no_wrap
   environment. It now uses the no_wrap argument of translate_buffer.


Index: Texinfo.pm
===================================================================
RCS file: /cvsroot/po4a/po4a/lib/Locale/Po4a/Texinfo.pm,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -d -r1.9 -r1.10
--- Texinfo.pm	16 Sep 2007 15:46:39 -0000	1.9
+++ Texinfo.pm	19 Sep 2007 21:32:30 -0000	1.10
@@ -192,13 +192,13 @@
             # paragraph.
             $paragraph .= $line."\n";
             if (length($paragraph)) {
-                ($t, @env) = translate_buffer($self,$paragraph, at env);
+                ($t, @env) = translate_buffer($self,$paragraph,undef, at env);
                 $self->pushline($t);
                 $paragraph="";
             }
         } elsif ($line =~ m/^\\input /) {
             if (length($paragraph)) {
-                ($t, @env) = translate_buffer($self,$paragraph, at env);
+                ($t, @env) = translate_buffer($self,$paragraph,undef, at env);
                 $self->pushline($t);
                 $paragraph="";
             }
@@ -212,7 +212,7 @@
                  and (defined $commands{$1})
                  and ($break_line{$1})) {
             if (length($paragraph)) {
-                ($t, @env) = translate_buffer($self,$paragraph, at env);
+                ($t, @env) = translate_buffer($self,$paragraph,undef, at env);
                 $self->pushline($t);
                 $paragraph="";
             }
@@ -223,7 +223,7 @@
                 $arg =~ s/\s*$//s;
                 @args= (" ", $arg);
             }
-            ($t, @env) = &{$commands{$1}}($self, $1, "", \@args, \@env);
+            ($t, @env) = &{$commands{$1}}($self, $1, "", \@args, \@env, 1);
             $self->pushline($t."\n");
         } else {
             # continue the same paragraph
@@ -236,7 +236,7 @@
     }
 
     if (length($paragraph)) {
-        ($t, @env) = translate_buffer($self,$paragraph, at env);
+        ($t, @env) = translate_buffer($self,$paragraph,undef, at env);
         $self->pushline($t);
         $paragraph="";
     }
@@ -245,7 +245,8 @@
 sub line_command {
     my $self = shift;
     my ($command,$variant,$args,$env) = (shift,shift,shift,shift);
-    print "line_command($command,$variant,@$args,@$env)="
+    my $no_wrap = shift;
+    print "line_command($command,$variant,@$args,@$env,$no_wrap)="
         if ($debug{'commands'});
 
     my $translated = $ESCAPE.$command;
@@ -253,20 +254,8 @@
     if (defined $line and length $line) {
         if (    defined $translate_line_command{$command}
             and $translate_line_command{$command}) {
-            my $no_wrap = 0;
-            foreach (split(' ', $no_wrap_environments)) {
-                if ($command eq $_) {
-                    $no_wrap = 1;
-                    last;
-                }
-            }
-            if ($no_wrap == 0) {
-                $no_wrap_environments .= " $command";
-            }
-            my ($t, $e) = $self->translate_buffer($line,@$env,$command);
-            if ($no_wrap == 0) {
-                $no_wrap_environments =~ s/ $command$//s;
-            }
+            # $no_wrap could be forced to 1, but it should already be set
+            my ($t,$e) = $self->translate_buffer($line,$no_wrap,@$env,$command);
             $translated .= " ".$t;
         } else {
             $translated .= " ".$line;
@@ -278,8 +267,8 @@
 }
 
 sub translate_buffer_menu {
-    my ($self,$buffer, at env) = (shift,shift, at _);
-    print STDERR "translate_buffer_menu($buffer, at env)="
+    my ($self,$buffer,$no_wrap, at env) = (shift,shift,shift, at _);
+    print STDERR "translate_buffer_menu($buffer,$no_wrap, at env)="
         if ($debug{'translate_buffer'});
 
     my $translated_buffer = "";
@@ -292,10 +281,12 @@
     while ($buffer =~ m/^(.*?)((?:\n|^)\* )(.*)$/s) {
         my $sep = $2;
         $buffer = $3;
-        my($t, @e) = $self->translate_buffer_menuentry($1, @env, "menuentry");
+        my($t, @e) = $self->translate_buffer_menuentry($1, $no_wrap,
+                                                       @env, "menuentry");
         $translated_buffer .= $t.$sep;
     }
-    my($t, @e) = $self->translate_buffer_menuentry($buffer, @env, "menuentry");
+    my($t, @e) = $self->translate_buffer_menuentry($buffer, $no_wrap,
+                                                   @env, "menuentry");
     $translated_buffer .= $t;
 
     $translated_buffer .= $spaces;
@@ -311,8 +302,8 @@
 my $menu_width = 78;
 my $menu_sep_width = 30;
 sub translate_buffer_menuentry {
-    my ($self,$buffer, at env) = (shift,shift, at _);
-    print STDERR "translate_buffer_menuentry($buffer, at env)="
+    my ($self,$buffer,$no_wrap, at env) = (shift,shift,shift, at _);
+    print STDERR "translate_buffer_menuentry($buffer,$no_wrap, at env)="
         if ($debug{'translate_buffer'});
 
     my $translated_buffer = "";
@@ -320,14 +311,14 @@
     if (   $buffer =~ m/^(.*?)(::)\s+(.*)$/s
         or $buffer =~ m/^(.*?: .*?)(\.)\s+(.*)$/s) {
         my ($name, $sep, $description) = ($1, $2, $3);
-        my ($t, @e) = $self->translate_buffer($name, @env);
+        my ($t, @e) = $self->translate_buffer($name, $no_wrap, @env);
         $translated_buffer = $t.$sep."  ";
         my $l = length($translated_buffer) + 2;
         if ($l < $menu_sep_width-1) {
             $translated_buffer .= ' 'x($menu_sep_width-1-$l);
             $l = $menu_sep_width-1;
         }
-        ($t, @e) = $self->translate_buffer($description, @env);
+        ($t, @e) = $self->translate_buffer($description, $no_wrap, @env);
         $t =~ s/\n//sg;
         $t = Locale::Po4a::Po::wrap($t, $menu_width-$l-2);
         my $spaces = ' 'x($l+2);
@@ -335,7 +326,7 @@
         $translated_buffer .= $t;
     } else {
 # FIXME: no-wrap if a line start by a space
-        my ($t, @e) = $self->translate_buffer($buffer, @env);
+        my ($t, @e) = $self->translate_buffer($buffer, $no_wrap, @env);
         $translated_buffer = $t;
     }
 
@@ -345,8 +336,8 @@
 }
 
 sub translate_buffer_ignore {
-    my ($self,$buffer, at env) = (shift,shift, at _);
-    print STDERR "translate_buffer_ignore($buffer, at env);\n"
+    my ($self,$buffer,$no_wrap, at env) = (shift,shift,shift, at _);
+    print STDERR "translate_buffer_ignore($buffer,$no_wrap, at env);\n"
         if ($debug{'translate_buffer'});
     return ($buffer, at env);
 }
@@ -419,7 +410,8 @@
 $commands{'node'} = sub {
     my $self = shift;
     my ($command,$variant,$args,$env) = (shift,shift,shift,shift);
-    print "node($command,$variant,@$args,@$env)="
+    my $no_wrap = shift;
+    print "node($command,$variant,@$args,@$env,$no_wrap)="
         if ($debug{'commands'});
 
     my $translated = $ESCAPE.$command;
@@ -428,7 +420,7 @@
         my @pointers = split (/, */, $line);
         my @t;
         foreach (@pointers) {
-           push @t, $self->translate($_, $self->{ref}, $command, "wrap" => 0);
+            push @t, $self->translate($_, $self->{ref}, $command, "wrap" => 0);
         }
         $translated .= " ".join(", ", @t);
     }
@@ -441,11 +433,12 @@
 sub environment_command {
     my $self = shift;
     my ($command,$variant,$args,$env) = (shift,shift,shift,shift);
-    print "environment_command($command,$variant,@$args,@$env)="
+    my $no_wrap = shift;
+    print "environment_command($command,$variant,@$args,@$env,$no_wrap)="
         if ($debug{'commands'});
     my ($t, at e)=("",());
 
-    ($t, @e) = generic_command($self,$command,$variant,$args,$env);
+    ($t, @e) = generic_command($self,$command,$variant,$args,$env,$no_wrap);
     @e = (@$env, $command);
 
     print "($t, at e)\n"
@@ -456,11 +449,12 @@
 sub environment_line_command {
     my $self = shift;
     my ($command,$variant,$args,$env) = (shift,shift,shift,shift);
-    print "environment_command_line($command,$variant,@$args,@$env)="
+    my $no_wrap = shift;
+    print "environment_command_line($command,$variant,@$args,@$env,$no_wrap)="
         if ($debug{'commands'});
     my ($t, at e)=("",());
 
-    ($t, @e) = line_command($self,$command,$variant,$args,$env);
+    ($t, @e) = line_command($self,$command,$variant,$args,$env,$no_wrap);
     @e = (@$env, $command);
 
     print "($t, at e)\n"
@@ -526,7 +520,6 @@
 # be used as verbatim. (Expressions.texi)
 
 # TODO: @include @ignore
-# TODO: special function for the indexes
 
 # TBC: node Indices
 

Index: TeX.pm
===================================================================
RCS file: /cvsroot/po4a/po4a/lib/Locale/Po4a/TeX.pm,v
retrieving revision 1.95
retrieving revision 1.96
diff -u -d -r1.95 -r1.96
--- TeX.pm	16 Sep 2007 13:32:52 -0000	1.95
+++ TeX.pm	19 Sep 2007 21:32:30 -0000	1.96
@@ -636,14 +636,15 @@
 
 our %translate_buffer_env = ();
 sub translate_buffer {
-    my ($self,$buffer, at env) = (shift,shift, at _);
+    my ($self,$buffer,$no_wrap, at env) = (shift,shift,shift, at _);
 
     if (@env and defined $translate_buffer_env{$env[-1]}) {
-        return &{$translate_buffer_env{$env[-1]}}($self,$buffer, @env);
+        return &{$translate_buffer_env{$env[-1]}}($self,$buffer,$no_wrap, at env);
     }
 
-    print STDERR "translate_buffer($buffer, at env)="
+    print STDERR "translate_buffer($buffer,$no_wrap, at env)="
         if ($debug{'translate_buffer'});
+
     my ($command,$variant) = ("","");
     my $args;
     my $translated_buffer = "";
@@ -667,8 +668,8 @@
                                        $env[-1],
                                        "wrap" => 0);
             }
-            ($t2, @env) = translate_buffer($self, $end, @env);
-            print STDERR "($t1.$t2, at env)\n"
+            ($t2, @env) = translate_buffer($self, $end, $no_wrap, @env);
+            print STDERR "($t1$t2, at env)\n"
                 if ($debug{'translate_buffer'});
             return ($t1.$t2, @env);
         } else {
@@ -684,10 +685,10 @@
     if ($buffer =~ /^($RE_VERBATIM\n?)(.*)$/s and length $2) {
         my ($begin, $end) = ($1, $2);
         my ($t1, $t2) = ("", "");
-        ($t1, @env) = translate_buffer($self, $begin, @env);
-        ($t2, @env) = translate_buffer($self, $end,   @env);
+        ($t1, @env) = translate_buffer($self, $begin, $no_wrap, @env);
+        ($t2, @env) = translate_buffer($self, $end,   $no_wrap, @env);
 
-        print STDERR "($t1.$t2, at env)\n"
+        print STDERR "($t1$t2, at env)\n"
             if ($debug{'translate_buffer'});
         return ($t1.$t2, @env);
     }
@@ -702,10 +703,10 @@
         my ($begin, $end) = ($1, $2);
         my ($t1, $t2) = ("", "");
         if (is_closed($begin)) {
-            ($t1, @env) = translate_buffer($self, $begin, @env);
-            ($t2, @env) = translate_buffer($self, $end,   @env);
+            ($t1, @env) = translate_buffer($self, $begin, $no_wrap, @env);
+            ($t2, @env) = translate_buffer($self, $end,   $no_wrap, @env);
 
-            print STDERR "($t1.$t2, at env)\n"
+            print STDERR "($t1$t2, at env)\n"
                 if ($debug{'translate_buffer'});
             return ($t1.$t2, @env);
         }
@@ -759,7 +760,7 @@
             # with the content of each argument that need a translation.
             if (defined ($commands{$command})) {
                 ($t, at env) = &{$commands{$command}}($self,$command,$variant,
-                                                   $args,\@env);
+                                                   $args,\@env,$no_wrap);
                 $translated_buffer .= $spaces.$t;
                 # Handle spaces after a command.
                 $spaces = "";
@@ -819,7 +820,7 @@
             $buf_begin .= $begin;
             if (is_closed($buf_begin)) {
                 my $t = "";
-                ($t, @env) = translate_buffer($self, $buf_begin, @env);
+                ($t, @env) = translate_buffer($self,$buf_begin,$no_wrap, at env);
                 $translated_buffer .= $t.$sep;
                 $buf_begin = "";
             } else {
@@ -843,6 +844,7 @@
                 }
             }
         }
+        $wrap = 0 if (defined $no_wrap and $no_wrap == 1);
         # Keep spaces at the end of the buffer.
         my $spaces = "";
         if ($buffer =~ /^(.*?)(\s+)$/s) {
@@ -864,7 +866,7 @@
         my $spaces  = shift @trailing_commands;
         if (defined ($commands{$command})) {
             ($t, at env) = &{$commands{$command}}($self,$command,$variant,
-                                               $args,\@env);
+                                               $args,\@env,$no_wrap);
             $translated_buffer .= $t.$spaces;
         } else {
             die wrap_ref_mod($self->{ref},
@@ -1170,7 +1172,7 @@
             # paragraph.
             $paragraph .= $line."\n";
             if (length($paragraph)) {
-                ($t, @env) = translate_buffer($self,$paragraph, at env);
+                ($t, @env) = translate_buffer($self,$paragraph,undef, at env);
                 $self->pushline($t);
                 $paragraph="";
                 @comments = ();
@@ -1186,7 +1188,7 @@
     }
 
     if (length($paragraph)) {
-        ($t, @env) = translate_buffer($self,$paragraph, at env);
+        ($t, @env) = translate_buffer($self,$paragraph,undef, at env);
         $self->pushline($t);
         $paragraph="";
     }
@@ -1258,7 +1260,8 @@
 $commands{'begin'}= sub {
     my $self = shift;
     my ($command,$variant,$args,$env) = (shift,shift,shift,shift);
-    print "begin($command,$variant,@$args,@$env)="
+    my $no_wrap = shift;
+    print "begin($command,$variant,@$args,@$env,$no_wrap)="
         if ($debug{'commands'} || $debug{'environments'});
     my ($t, at e) = ("",());
 
@@ -1269,7 +1272,7 @@
 
     if (defined($envir) && defined($environments{$envir})) {
         ($t, @e) = &{$environments{$envir}}($self,$command,$variant,
-                                            $args,$env);
+                                            $args,$env,$no_wrap);
     } else {
         die wrap_ref_mod($self->{ref}, "po4a::tex",
                      dgettext("po4a", "unknown environment: '%s'"),
@@ -1286,7 +1289,8 @@
 $commands{'end'}= sub {
     my $self = shift;
     my ($command,$variant,$args,$env) = (shift,shift,shift,shift);
-    print "end($command,$variant,@$args,@$env)="
+    my $no_wrap = shift;
+    print "end($command,$variant,@$args,@$env,$no_wrap)="
         if ($debug{'commands'} || $debug{'environments'});
 
     # verify that this environment was the last pushed environment.
@@ -1300,7 +1304,7 @@
         pop @$env;
     }
 
-    my ($t, at e) = generic_command($self,$command,$variant,$args,$env);
+    my ($t, at e) = generic_command($self,$command,$variant,$args,$env,$no_wrap);
 
     print "($t, @$env)\n"
         if ($debug{'commands'} || $debug{'environments'});
@@ -1311,8 +1315,10 @@
 sub generic_command {
     my $self = shift;
     my ($command,$variant,$args,$env) = (shift,shift,shift,shift);
-    print "generic_command($command,$variant,@$args,@$env)="
+    my $no_wrap = shift;
+    print "generic_command($command,$variant,@$args,@$env,$no_wrap)="
         if ($debug{'commands'} || $debug{'environments'});
+
     my ($t, at e)=("",());
     my $translated = "";
 
@@ -1361,7 +1367,7 @@
                                  $command, $reason);
             }
             if ($have_to_be_translated) {
-                ($t, @e) = translate_buffer($self,$opt,(@$env,$command.$type."#".$count.$type_end{$type}));
+                ($t, @e) = translate_buffer($self,$opt,$no_wrap,(@$env,$command.$type."#".$count.$type_end{$type}));
             } else {
                 $t = $opt;
             }
@@ -1377,9 +1383,11 @@
             $tmp .= $type.$opt.$type_end{$type};
         }
         @e = @$env;
+        my $wrap = 1;
+        $wrap = 0 if $no_wrap == 1;
         $translated = $self->translate($tmp,$self->{ref},
                                        @e?$e[-1]:"Plain text",
-                                       "wrap" => 1);
+                                       "wrap" => $wrap);
     }
 
     print "($translated, @$env)\n"
@@ -1423,7 +1431,8 @@
 sub generic_environment {
     my $self = shift;
     my ($command,$variant,$args,$env) = (shift,shift,shift,shift);
-    print "generic_environment($command,$variant,$args,$env)="
+    my $no_wrap = shift;
+    print "generic_environment($command,$variant,$args,$env,$no_wrap)="
         if ($debug{'environments'});
     my ($t, at e)=("",());
     my $translated = "";
@@ -1474,7 +1483,7 @@
             }
 
             if ($have_to_be_translated) {
-                ($t, @e) = translate_buffer($self,$opt,(@$env,$new_env.$type."#".$count.$type_end{$type}));
+                ($t, @e) = translate_buffer($self,$opt,$no_wrap,(@$env,$new_env.$type."#".$count.$type_end{$type}));
             } else {
                 $t = $opt;
             }
@@ -1491,9 +1500,11 @@
             $buf .= $type.$opt.$type_end{$type};
         }
         @e = @$env;
+        my $wrap = 1;
+        $wrap = 0 if $no_wrap == 1;
         $translated = $self->translate($buf,$self->{ref},
                                        @e?$e[-1]:"Plain text",
-                                       "wrap" => 1);
+                                       "wrap" => $wrap);
     }
     @e = (@$env, $new_env);
 

Index: LaTeX.pm
===================================================================
RCS file: /cvsroot/po4a/po4a/lib/Locale/Po4a/LaTeX.pm,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -d -r1.16 -r1.17
--- LaTeX.pm	7 Aug 2007 18:31:18 -0000	1.16
+++ LaTeX.pm	19 Sep 2007 21:32:30 -0000	1.17
@@ -111,13 +111,14 @@
 $commands{'documentclass'} = sub {
     my $self = shift;
     my ($command,$variant,$args,$env) = (shift,shift,shift,shift);
+    my $no_wrap = shift;
 
     # Only try to parse the file.  We don't want to fail or parse this file
     # if it is a standard documentclass.
     my $name = ($args->[0] eq '[')? $args->[3]: $args->[1];
     parse_definition_file($self, $name.".cls", 1);
 
-    my ($t, at e) = generic_command($self,$command,$variant,$args,$env);
+    my ($t, at e) = generic_command($self,$command,$variant,$args,$env,$no_wrap);
 
     return ($t, @$env);
 };




More information about the Po4a-commits mailing list