summaryrefslogtreecommitdiffstats
path: root/scripts/msgsearch
blob: e6d9de53fb28e1906066c8bf8602337448a132e1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
#! /usr/bin/env perl
eval 'exec perl -S $0 ${1+"$@"}'
    if $running_under_some_shell;

# Copyright 2002, 2003, 2004 by Martin Quinson (mquinson#debian.org)
#
# This program is free software; you can redistribute it and/or modify it
# under the terms of GPL v2.0 or later (see COPYING).


=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. It can be seen as a
generalization of msggrep allowing you to use OR between different
categories.

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 (mquinson#debian.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 v2.0 or later (see COPYING file).

=cut

use 5.16.0;
use strict;
use warnings;

use Getopt::Long qw(GetOptions);

use Locale::Po4a::Po;
use Locale::Po4a::Common;

use Pod::Usage qw(pod2usage);

textdomain('po4a');

sub show_version {
    Locale::Po4a::Common::show_version("msgsearch");
    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;