From a399dcefad193fc21ef2dc1fe31d07686ab2da46 Mon Sep 17 00:00:00 2001 From: acli Date: Wed, 25 Feb 2004 03:37:27 +0000 Subject: [PATCH] Benedict wants some message at the end that says success or failure. It's a good idea too. --- misc/translator/VerboseWarnings.pm | 32 ++++++++++++++++++++++++++++-- misc/translator/tmpl_process3.pl | 28 +++++++++++++++++--------- misc/translator/xgettext.pl | 2 ++ 3 files changed, 51 insertions(+), 11 deletions(-) diff --git a/misc/translator/VerboseWarnings.pm b/misc/translator/VerboseWarnings.pm index 7a3aad4c0b..910d745e54 100644 --- a/misc/translator/VerboseWarnings.pm +++ b/misc/translator/VerboseWarnings.pm @@ -25,20 +25,31 @@ $VERSION = 0.01; @ISA = qw(Exporter); @EXPORT_OK = qw( &pedantic_p + &warn_additional &warn_normal &warn_pedantic + &error_additional &error_normal ); +%EXPORT_TAGS = ( + 'warn' => [ 'warn_additional', 'warn_normal', 'warn_pedantic' ], + 'die' => [ 'error_additional', 'error_normal' ], +); ############################################################################### use vars qw( $appName $input $input_abbr $pedantic_p $pedantic_tag ); +use vars qw( $warned $erred ); sub set_application_name ($) { my($s) = @_; $appName = $& if !defined $appName && $s =~ /[^\/]+$/; } +sub application_name () { + return $appName; +} + sub set_input_file_name ($) { my($s) = @_; $input = $s; @@ -70,13 +81,19 @@ sub construct_warn_prefix ($$) { return "$appName: $prefix: " . (defined $lc? "$input_abbr: line $lc: ": defined $input_abbr? "$input_abbr: ": ''); } -sub warn_normal ($$) { +sub warn_additional ($$) { my($msg, $lc) = @_; my $prefix = construct_warn_prefix('Warning', $lc); $msg .= "\n" unless $msg =~ /\n$/s; warn "$prefix$msg"; } +sub warn_normal ($$) { + my($msg, $lc) = @_; + $warned += 1; + warn_additional($msg, $lc); +} + sub warn_pedantic ($$$) { my($msg, $lc, $flag) = @_; my $prefix = construct_warn_prefix("Warning$pedantic_tag", $lc); @@ -87,13 +104,24 @@ sub warn_pedantic ($$$) { warn $prefix."Further similar negligible warnings will not be reported, use --pedantic for details\n" unless $$flag; $$flag = 1; } + $warned += 1; } -sub error_normal ($$) { +sub error_additional ($$) { my($msg, $lc) = @_; my $prefix = construct_warn_prefix('ERROR', $lc); $msg .= "\n" unless $msg =~ /\n$/s; warn "$prefix$msg"; } +sub error_normal ($$) { + my($msg, $lc) = @_; + $erred += 1; + error_additional($msg, $lc); +} + +sub warned () { + return $warned; # number of times warned +} + ############################################################################### diff --git a/misc/translator/tmpl_process3.pl b/misc/translator/tmpl_process3.pl index 6942351081..345d6fdcaf 100755 --- a/misc/translator/tmpl_process3.pl +++ b/misc/translator/tmpl_process3.pl @@ -16,7 +16,7 @@ use Getopt::Long; use Locale::PO; use File::Temp qw( :POSIX ); use TmplTokenizer; -use VerboseWarnings qw( error_normal warn_normal ); +use VerboseWarnings qw( :warn :die ); ############################################################################### @@ -149,11 +149,13 @@ Create or update PO files from templates, or install translated templates. --help Display this help and exit The -o option is ignored for the "create" and "update" actions. +Try `perldoc $0' for perhaps more information. EOF exit($exitcode); } ############################################################################### + sub usage_error (;$) { for my $msg (split(/\n/, $_[0])) { print STDERR "$msg\n"; @@ -240,6 +242,7 @@ if (!defined $charset_in) { } my $xgettext = './xgettext.pl'; # actual text extractor script +my $st; if ($action eq 'create') { # updates the list. As the list is empty, every entry will be added @@ -255,9 +258,9 @@ if ($action eq 'create') { } close $tmph; # Generate the specified po file ($str_file) - my $st = system ($xgettext, '-s', '-f', $tmpfile, '-o', $str_file); + $st = system ($xgettext, '-s', '-f', $tmpfile, '-o', $str_file); warn_normal "Text extraction failed: $xgettext: $!\n", undef if $st != 0; - unlink $tmpfile || warn_normal "$tmpfile: unlink failed: $!\n", undef; +# unlink $tmpfile || warn_normal "$tmpfile: unlink failed: $!\n", undef; } elsif ($action eq 'update') { my($tmph1, $tmpfile1) = tmpnam(); @@ -269,7 +272,7 @@ if ($action eq 'create') { } close $tmph1; # Generate the temporary file that acts as /.pot - my $st = system($xgettext, '-s', '-f', $tmpfile1, '-o', $tmpfile2, + $st = system($xgettext, '-s', '-f', $tmpfile1, '-o', $tmpfile2, '--po-mode', (defined $charset_in? ('-I', $charset_in): ()), (defined $charset_out? ('-O', $charset_out): ())); @@ -277,13 +280,13 @@ if ($action eq 'create') { # Merge the temporary "pot file" with the specified po file ($str_file) # FIXME: msgmerge(1) is a Unix dependency # FIXME: need to check the return value - system('msgmerge', '-U', '-s', $str_file, $tmpfile2); + $st = system('msgmerge', '-U', '-s', $str_file, $tmpfile2); } else { - warn_normal "Text extraction failed: $xgettext: $!\n", undef; - warn_normal "Will not run msgmerge\n", undef; + error_normal "Text extraction failed: $xgettext: $!\n", undef; + error_additional "Will not run msgmerge\n", undef; } - unlink $tmpfile1 || warn_normal "$tmpfile1: unlink failed: $!\n", undef; - unlink $tmpfile2 || warn_normal "$tmpfile2: unlink failed: $!\n", undef; +# unlink $tmpfile1 || warn_normal "$tmpfile1: unlink failed: $!\n", undef; +# unlink $tmpfile2 || warn_normal "$tmpfile2: unlink failed: $!\n", undef; } elsif ($action eq 'install') { if(!defined($out_dir)) { @@ -328,6 +331,13 @@ if ($action eq 'create') { } else { usage_error('Unknown action specified.'); } + +if ($st == 0) { + printf "The %s seems to be successful, with %d warning(s).\n", + $action, VerboseWarnings::warned; +} else { + printf "%s FAILED.\n", "\u$action"; +} exit 0; ############################################################################### diff --git a/misc/translator/xgettext.pl b/misc/translator/xgettext.pl index 18d75e84b3..74d436013f 100755 --- a/misc/translator/xgettext.pl +++ b/misc/translator/xgettext.pl @@ -236,6 +236,8 @@ Output details: Informative output: --help Display this help and exit + +Try `perldoc $0' for perhaps more information. EOF exit($exitcode); } -- 2.39.5