ispman/locale xgettext.pl,1.2,1.3
Joerg Delker <[email protected]>
| Newsgroups | gmane.comp.isp.ispman.cvs |
|---|---|
| Message-ID | <[email protected]> |
Update of /cvsroot/ispman/ispman/locale
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv30799/locale
Modified Files:
xgettext.pl
Log Message:
code reformatting by perltidy conforming perl style guide
Index: xgettext.pl
===================================================================
RCS file: /cvsroot/ispman/ispman/locale/xgettext.pl,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- xgettext.pl 24 Apr 2003 20:35:09 -0000 1.2
+++ xgettext.pl 30 May 2004 23:35:39 -0000 1.3
@@ -1,7 +1,8 @@
#!/usr/bin/perl
eval 'exec /usr/bin/perl -S $0 ${1+"$@"}'
- if 0; # not running under some shell
+ if 0; # not running under some shell
+
# $File: //member/autrijus/Locale-Maketext-Lexicon/bin/xgettext.pl $ $Author$
# $Revision$ $Change: 4414 $ $DateTime: 2003/02/22 01:33:00 $
@@ -17,7 +18,7 @@
use constant QUO2 => 4;
use constant QUO3 => 5;
-$::interop = 0; # whether to interoperate with GNU gettext
+$::interop = 0; # whether to interoperate with GNU gettext
=head1 NAME
@@ -73,38 +74,39 @@
=cut
-my (%file, %Lexicon, %opts);
-my ($PO, $out);
+my ( %file, %Lexicon, %opts );
+my ( $PO, $out );
# options as above. Values in %opts
-getopts('huo:', \%opts)
+getopts( 'huo:', \%opts )
or pod2usage( -verbose => 1, -exitval => 1 );
$opts{h} and pod2usage( -verbose => 2, -exitval => 0 );
$PO = $opts{o} || "messages.po";
#@ARGV = ('-') unless @ARGV;
[email protected]= `find ../ispman-web/cgi-bin/tmpl/ -type f` ;
[email protected] = `find ../ispman-web/cgi-bin/tmpl/ -type f`;
-if (-r $PO) {
+if ( -r $PO ) {
open LEXICON, $PO or die $!;
while (<LEXICON>) {
- if (1 .. /^$/) { $out .= $_; next }
- last;
+ if ( 1 .. /^$/ ) { $out .= $_; next }
+ last;
}
1 while chomp $out;
require Locale::Maketext::Lexicon::Gettext;
%Lexicon = map {
- if ($opts{u}) {
- s/\\/\\\\/g;
- s/\"/\\"/g;
- s/((?<!~)(?:~~)*)\[_(\d+)\]/$1%$2/g;
- s/((?<!~)(?:~~)*)\[([A-Za-z#*]\w*),([^\]]+)\]/"$1%$2(".escape($3).")"/eg;
- s/~([\~\[\]])/$1/g;
- }
- $_;
+ if ( $opts{u} )
+ {
+ s/\\/\\\\/g;
+ s/\"/\\"/g;
+ s/((?<!~)(?:~~)*)\[_(\d+)\]/$1%$2/g;
+s/((?<!~)(?:~~)*)\[([A-Za-z#*]\w*),([^\]]+)\]/"$1%$2(".escape($3).")"/eg;
+ s/~([\~\[\]])/$1/g;
+ }
+ $_;
} %{ Locale::Maketext::Lexicon::Gettext->parse(<LEXICON>) };
close LEXICON;
delete $Lexicon{''};
@@ -115,86 +117,100 @@
undef $/;
foreach my $file (@ARGV) {
- next if ($file=~/\.po$/i); # Don't parse po files
- next if ($file=~/\.cvsignore$/i); # Don't parse cvs ignore files
- next if ($file=~/\/CVS\//i); # Don't parse CVS files
- next if ($file=~/\.ldif$/i); # Don't parse ldif files
- next if ($file=~/\.schema/i); # Don't parse schema files
- next if ($file=~/\.(gif|jpg|css)$/i); # Don't parse these files
+ next if ( $file =~ /\.po$/i ); # Don't parse po files
+ next if ( $file =~ /\.cvsignore$/i ); # Don't parse cvs ignore files
+ next if ( $file =~ /\/CVS\//i ); # Don't parse CVS files
+ next if ( $file =~ /\.ldif$/i ); # Don't parse ldif files
+ next if ( $file =~ /\.schema/i ); # Don't parse schema files
+ next if ( $file =~ /\.(gif|jpg|css)$/i ); # Don't parse these files
my $filename = $file;
- open _, $file or die $!; $_ = <_>; $filename =~ s!^./!!;
+ open _, $file or die $!;
+ $_ = <_>;
+ $filename =~ s!^./!!;
- my $line = 1; pos($_) = 0;
+ my $line = 1;
+ pos($_) = 0;
# Perl source file
- my ($state,$str,$vars)=(0);
+ my ( $state, $str, $vars ) = (0);
pos($_) = 0;
- my $orig = 1 + (() = ((my $__ = $_) =~ /\n/g));
+ my $orig = 1 + ( () = ( ( my $__ = $_ ) =~ /\n/g ) );
PARSER: {
- $_ = substr($_, pos($_)) if (pos($_));
- my $line = $orig - (() = ((my $__ = $_) =~ /\n/g));
- # maketext or loc or _
- $state == NUL &&
- m/\b(__?|loc|x)/gcx && do { $state = BEG; redo; };
- $state == BEG && m/^([\s\t\n]*)/gcx && do { redo; };
- # begin ()
- $state == BEG && m/^([\S\(]) /gcx && do {
- $state = ( ($1 eq '(') ? PAR : NUL) ;
- redo;
- };
- # begin or end of string
- $state == PAR && m/^(\') /gcx && do { $state = QUO1; redo; };
- $state == QUO1 && m/^([^\']+)/gcx && do { $str.=$1; redo; };
- $state == QUO1 && m/^\' /gcx && do { $state = PAR; redo; };
+ $_ = substr( $_, pos($_) ) if ( pos($_) );
+ my $line = $orig - ( () = ( ( my $__ = $_ ) =~ /\n/g ) );
- $state == PAR && m/^\" /gcx && do { $state = QUO2; redo; };
- $state == QUO2 && m/^([^\"]+)/gcx && do { $str.=$1; redo; };
- $state == QUO2 && m/^\" /gcx && do { $state = PAR; redo; };
+ # maketext or loc or _
+ $state == NUL
+ && m/\b(__?|loc|x)/gcx
+ && do { $state = BEG; redo; };
+ $state == BEG && m/^([\s\t\n]*)/gcx && do { redo; };
- $state == PAR && m/^\` /gcx && do { $state = QUO3; redo; };
- $state == QUO3 && m/^([^\`]*)/gcx && do { $str.=$1; redo; };
- $state == QUO3 && m/^\` /gcx && do { $state = PAR; redo; };
+ # begin ()
+ $state == BEG && m/^([\S\(]) /gcx && do {
+ $state = ( ( $1 eq '(' ) ? PAR : NUL );
+ redo;
+ };
- # end ()
- $state == PAR && m/^[\)]/gcx
- && do {
- $state = NUL;
- $vars =~ s/[\n\r]//g if ($vars);
- push @{$file{$str}}, [ $filename, $line - (() = $str =~ /\n/g), $vars] if ($str);
- undef $str; undef $vars;
- redo;
- };
+ # begin or end of string
+ $state == PAR && m/^(\') /gcx && do { $state = QUO1; redo; };
+ $state == QUO1 && m/^([^\']+)/gcx && do { $str .= $1; redo; };
+ $state == QUO1 && m/^\' /gcx && do { $state = PAR; redo; };
- # a line of vars
- $state == PAR && m/^([^\)]*)/gcx && do { $vars.=$1."\n"; redo; };
+ $state == PAR && m/^\" /gcx && do { $state = QUO2; redo; };
+ $state == QUO2 && m/^([^\"]+)/gcx && do { $str .= $1; redo; };
+ $state == QUO2 && m/^\" /gcx && do { $state = PAR; redo; };
+
+ $state == PAR && m/^\` /gcx && do { $state = QUO3; redo; };
+ $state == QUO3 && m/^([^\`]*)/gcx && do { $str .= $1; redo; };
+ $state == QUO3 && m/^\` /gcx && do { $state = PAR; redo; };
+
+ # end ()
+ $state == PAR
+ && m/^[\)]/gcx
+ && do {
+ $state = NUL;
+ $vars =~ s/[\n\r]//g if ($vars);
+ push @{ $file{$str} },
+ [ $filename, $line - ( () = $str =~ /\n/g ), $vars ]
+ if ($str);
+ undef $str;
+ undef $vars;
+ redo;
+ };
+
+ # a line of vars
+ $state == PAR && m/^([^\)]*)/gcx && do { $vars .= $1 . "\n"; redo; };
}
}
-foreach my $str (sort keys %file) {
- my $ostr = $str;
+foreach my $str ( sort keys %file ) {
+ my $ostr = $str;
my $entry = $file{$str};
- my $lexi = $Lexicon{$ostr};
+ my $lexi = $Lexicon{$ostr};
- $str =~ s/\\/\\\\/g;
- $str =~ s/\"/\\"/g;
+ $str =~ s/\\/\\\\/g;
+ $str =~ s/\"/\\"/g;
$lexi =~ s/\\/\\\\/g;
$lexi =~ s/\"/\\"/g;
- unless ($opts{u}) {
- $str =~ s/((?<!~)(?:~~)*)\[_(\d+)\]/$1%$2/g;
- $str =~ s/((?<!~)(?:~~)*)\[([A-Za-z#*]\w*)([^\]]+)\]/"$1%$2(".escape($3).")"/eg;
- $str =~ s/~([\~\[\]])/$1/g;
- $lexi =~ s/((?<!~)(?:~~)*)\[_(\d+)\]/$1%$2/g;
- $lexi =~ s/((?<!~)(?:~~)*)\[([A-Za-z#*]\w*)([^\]]+)\]/"$1%$2(".escape($3).")"/eg;
- $lexi =~ s/~([\~\[\]])/$1/g;
+ unless ( $opts{u} ) {
+ $str =~ s/((?<!~)(?:~~)*)\[_(\d+)\]/$1%$2/g;
+ $str =~
+s/((?<!~)(?:~~)*)\[([A-Za-z#*]\w*)([^\]]+)\]/"$1%$2(".escape($3).")"/eg;
+ $str =~ s/~([\~\[\]])/$1/g;
+ $lexi =~ s/((?<!~)(?:~~)*)\[_(\d+)\]/$1%$2/g;
+ $lexi =~
+s/((?<!~)(?:~~)*)\[([A-Za-z#*]\w*)([^\]]+)\]/"$1%$2(".escape($3).")"/eg;
+ $lexi =~ s/~([\~\[\]])/$1/g;
}
$Lexicon{$str} ||= '';
next if $ostr eq $str;
$Lexicon{$str} ||= $lexi;
- delete $file{$ostr}; delete $Lexicon{$ostr};
+ delete $file{$ostr};
+ delete $Lexicon{$ostr};
$file{$str} = $entry;
}
@@ -219,40 +235,44 @@
"Content-Transfer-Encoding: 8bit\n"
.
-foreach my $entry (sort keys %Lexicon) {
- my %f = (map { ( "$_->[0]:$_->[1]" => 1 ) } @{$file{$entry}});
- my $f = join(' ', sort keys %f);
+foreach my $entry ( sort keys %Lexicon ) {
+ my %f = ( map { ( "$_->[0]:$_->[1]" => 1 ) } @{ $file{$entry} } );
+ my $f = join( ' ', sort keys %f );
$f = " $f" if length $f;
my $nospace = $entry;
$nospace =~ s/ +$//;
- if (!$Lexicon{$entry} and $Lexicon{$nospace}) {
- $Lexicon{$entry} = $Lexicon{$nospace} . (' ' x (length($entry) - length($nospace)));
+ if ( !$Lexicon{$entry} and $Lexicon{$nospace} ) {
+ $Lexicon{$entry} =
+ $Lexicon{$nospace} . ( ' ' x ( length($entry) - length($nospace) ) );
}
my %seen;
print "\n#:$f\n";
- foreach my $entry ( grep { $_->[2] } @{$file{$entry}} ) {
- my ($file, $line, $var) = @{$entry};
- $var =~ s/^\s*,\s*//; $var =~ s/\s*$//;
- print "#. ($var)\n" unless !length($var) or $seen{$var}++;
+ foreach my $entry ( grep { $_->[2] } @{ $file{$entry} } ) {
+ my ( $file, $line, $var ) = @{$entry};
+ $var =~ s/^\s*,\s*//;
+ $var =~ s/\s*$//;
+ print "#. ($var)\n" unless !length($var) or $seen{$var}++;
}
print "#, maketext-format" if $::interop and /%(?:\d|\w+\([^\)]*\))/;
- print "msgid "; output($entry);
- print "msgstr "; output($Lexicon{$entry});
+ print "msgid ";
+ output($entry);
+ print "msgstr ";
+ output( $Lexicon{$entry} );
}
sub output {
my $str = shift;
- if ($str =~ /\n/) {
- print "\"\"\n";
- print "\"$_\"\n" foreach split(/\n/, $str, -1);
+ if ( $str =~ /\n/ ) {
+ print "\"\"\n";
+ print "\"$_\"\n" foreach split( /\n/, $str, -1 );
}
else {
- print "\"$str\"\n"
+ print "\"$str\"\n";
}
}
@@ -290,3 +310,4 @@
See L<http://www.perl.com/perl/misc/Artistic.html>
=cut
+
-------------------------------------------------------
This SF.Net email is sponsored by: Oracle 10g
Get certified on the hottest thing ever to hit the market... Oracle 10g.
Take an Oracle 10g class now, and we'll give you the exam FREE.
http://ads.osdn.com/?ad_id=3149&alloc_id=8166&op=click