[Po4a-devel][CVS] po4a msgsearch,NONE,1.1

Martin Quinson po4a-devel@lists.alioth.debian.org
Mon, 02 Aug 2004 09:35:41 +0000


Update of /cvsroot/po4a/po4a
In directory haydn:/tmp/cvs-serv23510

Added Files:
	msgsearch 
Log Message:
Implement a tool I dream of since a long time: msgsearch, which allows you to filter out some messages of the po file and put them in another

--- NEW FILE: msgsearch ---
#! /usr/bin/perl
eval 'exec /usr/bin/perl -S $0 ${1+"$@"}'
    if $running_under_some_shell;

# $Id: msgsearch,v 1.1 2004/08/02 09:35:39 mquinson-guest Exp $
#
# Copyright 2002, 2003, 2004 by Martin Quinson <Martin.Quinson@ens-lyon.fr>
#
# This program is free software; you can redistribute it and/or modify it
# under the terms of GPL (see COPYING).

my $VERSION=$Locale::Po4a::TransTractor::VERSION;

=head1 NAME

msgsearch - Extract some messages of a po file based on several criteron

=head1 SYNOPSIS

msgsearch [-dhvV] -i E<lt>inputE<gt> -o E<lt>outputE<gt> E<lt>filterE<gt>

=head1 DESCRIPTION

msgsearch is an handy tool to extract some messages of a po file. Selection
depend on the file the message where extracted from, on the flags attached
to the message or even on their actual content.

The used filters are very similar to the LDAP ones:

=over

=item * (E<lt>fieldE<gt>=argument)
   
The EQ operator returns true (and thus select the message for
extraction) if and only if the value of the E<lt>fieldE<gt> is equal to the
string used as argument. The argument are Perl regular expression, so if 
you want to get an equality (and not a substring search), you have to use ^value$.

Existing fields are:

=over

=item - msgid

The actual content of the message.

=item - msgstr

The actual content of the translation.

=item - reference

The location of the message in the file where it was extracted from. It is a
space separated list of positions, each ones being of the syntax
E<gt>fileE<lt>:E<gt>line numberE<lt>.

=item - comment

Comment added manually (by the translators). 

=item - automatic

Comment automatically added by the string extraction program. See the
I<--add-comments> option of the B<xgettext> program for more information.

=item - flags

space-separated list of all defined flags for this entry.

Valid flags are: c-text, python-text, lisp-text, elisp-text, librep-text,
smalltalk-text, java-text, awk-text, object-pascal-text, ycp-text,
tcl-text, wrap, no-wrap and fuzzy.

See the gettext documentation for their meaning.

=back

=item * (!E<lt>expressionE<gt>)

The NOT operator returns true if the sub-E<lt>expressionE<gt> return false.

=item * (&E<lt>expression1E<gt>E<lt>expression2E<gt>...E<lt>expressionNE<gt>)

The AND operator returns true when all the sub-expression return true. It
return false if at least one of them return false.

=item * (|E<lt>expression1E<gt>E<lt>expression2E<gt>...E<lt>expressionNE<gt>)

The OR operator returns true when at least one of the sub-expression return
true. It return false if all of them return false. 

=head1 OPTIONS

=over 4

=item -h, --help

Show a short help message.

=item -V, --version

Displays the version of the script and exits.

=item -i, --input

Input file. By default, files are taken from the standard input.

=item -o, --output

Output file. By default, files are sent on the standard output.

=item -v, --verbose

Increase the verbosity of the program.

=back

=head1 SEE ALSO

This tool is part of the po4a project, even if it can well prove useful in
other contexts. See L<po4a(7)> for more information about the motivations of
the po4a project, and the other tools developed in that framework.

=head1 AUTHORS

 Martin Quinson <martin.quinson,tuxfamily.org>

=head1 COPYRIGHT AND LICENSE

Copyright 2004 by SPI, inc.

This program is free software; you may redistribute it and/or modify it
under the terms of GPL (see COPYING file).

=cut

use 5.006;
use strict;
use warnings;

use Getopt::Long qw(GetOptions);

use Locale::Po4a::Po;

use Pod::Usage qw(pod2usage);

use Locale::gettext;
use POSIX;     # Needed for setlocale()

setlocale(LC_MESSAGES, "");
textdomain('po4a');

sub show_version {
    print sprintf(gettext(
          "%s version %s.\n".
          "written by Martin Quinson and Denis Barbier.\n\n".
          "Copyright (C) 2002, 2003, 2004 Software of Public Interest, Inc.\n".
          "This is free software; see source code for copying\n".
          "conditions. There is NO warranty; not even for\n".
          "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE."
          ), "msgsearch", $VERSION)."\n";
    exit 0;
}

my ($help,@verbose,$input,$output);
$help = 0;
@verbose = ();
$input = '-';
$output = '-';

Getopt::Long::config('bundling', 'no_getopt_compat', 'no_auto_abbrev');
GetOptions(
	'input|i=s'	=> \$input,
	'output|o=s'	=> \$output,
        'help|h'        => \$help,
        'verbose|v'     => \@verbose,
        'version|V'     => \&show_version
) || pod2usage(1);
$input eq '-' || -e $input || die sprintf(gettext("msgsearch: File '%s' does not exist")."\n",$input);
my $verbose = scalar @verbose;

# Argument check
$help && pod2usage (0);
my $filter = shift(@ARGV) || pod2usage(1);


my $poin = Locale::Po4a::Po->new();
# All following function croak on problem
print STDERR gettext("Read $input")."\n" if $verbose;
$poin->read($input); 

print STDERR gettext("Filter")."\n" if $verbose;
my $poout = $poin->filter($filter);

print STDERR gettext("Write result to $output")."\n" if $verbose;
$poout->write($output);
0;