Lines 22-28
use VerboseWarnings qw( :warn :die );
Link Here
|
22 |
|
22 |
|
23 |
############################################################################### |
23 |
############################################################################### |
24 |
|
24 |
|
25 |
use vars qw( @in_dirs @filenames $str_file $out_dir $quiet ); |
25 |
use vars qw( @in_dirs @filenames @match @nomatch $str_file $out_dir $quiet ); |
26 |
use vars qw( @excludes $exclude_regex ); |
26 |
use vars qw( @excludes $exclude_regex ); |
27 |
use vars qw( $recursive_p ); |
27 |
use vars qw( $recursive_p ); |
28 |
use vars qw( $pedantic_p ); |
28 |
use vars qw( $pedantic_p ); |
Lines 133-139
sub text_replace (**) {
Link Here
|
133 |
} |
133 |
} |
134 |
|
134 |
|
135 |
sub listfiles { |
135 |
sub listfiles { |
136 |
my($dir, $type, $action, $filenames) = @_; |
136 |
my($dir, $type, $action) = @_; |
|
|
137 |
my $filenames = join ('|', @filenames); # used to update strings from this file |
138 |
my $match = join ('|', @match); # use only this files |
139 |
my $nomatch = join ('|', @nomatch); # do no use this files |
137 |
my @it = (); |
140 |
my @it = (); |
138 |
if (opendir(DIR, $dir)) { |
141 |
if (opendir(DIR, $dir)) { |
139 |
my @dirent = readdir DIR; # because DIR is shared when recursing |
142 |
my @dirent = readdir DIR; # because DIR is shared when recursing |
Lines 144-155
sub listfiles {
Link Here
|
144 |
|| (defined $exclude_regex && $dirent =~ /^(?:$exclude_regex)$/)) { |
147 |
|| (defined $exclude_regex && $dirent =~ /^(?:$exclude_regex)$/)) { |
145 |
; |
148 |
; |
146 |
} elsif (-f $path) { |
149 |
} elsif (-f $path) { |
147 |
my $basename = basename $path; |
150 |
my $basename = fileparse( $path ); |
148 |
push @it, $path |
151 |
push @it, $path |
149 |
if ( not @$filenames or ( grep { $path =~ /$_/ } @$filenames ) ) |
152 |
if ( not @filenames or $basename =~ /($filenames)/i ) |
150 |
and (!defined $type || $dirent =~ /\.(?:$type)$/) || $action eq 'install'; |
153 |
and ( not @match or $basename =~ /($match)/i ) # files to include |
|
|
154 |
and ( not @nomatch or $basename !~ /($nomatch)/i ) # files not to include |
155 |
and (!defined $type || $dirent =~ /\.(?:$type)$/) || $action eq 'install'; |
151 |
} elsif (-d $path && $recursive_p) { |
156 |
} elsif (-d $path && $recursive_p) { |
152 |
push @it, listfiles($path, $type, $action, $filenames); |
157 |
push @it, listfiles($path, $type, $action); |
153 |
} |
158 |
} |
154 |
} |
159 |
} |
155 |
} else { |
160 |
} else { |
Lines 167-173
sub mkdir_recursive ($) {
Link Here
|
167 |
my ($prefix, $basename) = ($dir =~ /\/([^\/]+)$/s)? ($`, $1): ('.', $dir); |
172 |
my ($prefix, $basename) = ($dir =~ /\/([^\/]+)$/s)? ($`, $1): ('.', $dir); |
168 |
mkdir_recursive($prefix) if $prefix ne '.' && !-d $prefix; |
173 |
mkdir_recursive($prefix) if $prefix ne '.' && !-d $prefix; |
169 |
if (!-d $dir) { |
174 |
if (!-d $dir) { |
170 |
print STDERR "Making directory $dir..." unless $quiet; |
175 |
print STDERR "Making directory $dir...\n" unless $quiet; |
171 |
# creates with rwxrwxr-x permissions |
176 |
# creates with rwxrwxr-x permissions |
172 |
mkdir($dir, 0775) || warn_normal "$dir: $!", undef; |
177 |
mkdir($dir, 0775) || warn_normal "$dir: $!", undef; |
173 |
} |
178 |
} |
Lines 192-202
Create or update PO files from templates, or install translated templates.
Link Here
|
192 |
--pedantic-warnings Issue warnings even for detected problems |
197 |
--pedantic-warnings Issue warnings even for detected problems |
193 |
which are likely to be harmless |
198 |
which are likely to be harmless |
194 |
-r, --recursive SOURCE in the -i option is a directory |
199 |
-r, --recursive SOURCE in the -i option is a directory |
195 |
-f, --filename=FILE FILE is a specific filaneme. |
200 |
-f, --filename=FILE FILE is a specific filename or part of it. |
196 |
If given, only these files will be processed. |
201 |
If given, only these files will be processed. |
|
|
202 |
On update only relevant strings will be updated. |
203 |
-m, --match=FILE FILE is a specific filename or part of it. |
204 |
If given, only these files will be processed. |
205 |
-n, --nomatch=FILE FILE is a specific filename or part of it. |
206 |
If given, these files will not be processed. |
197 |
-s, --str-file=FILE Specify FILE as the translation (po) file |
207 |
-s, --str-file=FILE Specify FILE as the translation (po) file |
198 |
for input (install) or output (create, update) |
208 |
for input (install) or output (create, update) |
199 |
-x, --exclude=REGEXP Exclude files matching the given REGEXP |
209 |
-x, --exclude=REGEXP Exclude dirs matching the given REGEXP |
200 |
--help Display this help and exit |
210 |
--help Display this help and exit |
201 |
-q, --quiet no output to screen (except for errors) |
211 |
-q, --quiet no output to screen (except for errors) |
202 |
|
212 |
|
Lines 221-226
sub usage_error (;$) {
Link Here
|
221 |
GetOptions( |
231 |
GetOptions( |
222 |
'input|i=s' => \@in_dirs, |
232 |
'input|i=s' => \@in_dirs, |
223 |
'filename|f=s' => \@filenames, |
233 |
'filename|f=s' => \@filenames, |
|
|
234 |
'match|m=s' => \@match, |
235 |
'nomatch|n=s' => \@nomatch, |
224 |
'outputdir|o=s' => \$out_dir, |
236 |
'outputdir|o=s' => \$out_dir, |
225 |
'recursive|r' => \$recursive_p, |
237 |
'recursive|r' => \$recursive_p, |
226 |
'str-file|s=s' => \$str_file, |
238 |
'str-file|s=s' => \$str_file, |
Lines 266-272
for my $fn ( @filenames ) {
Link Here
|
266 |
} |
278 |
} |
267 |
for my $in_dir ( @in_dirs ) { |
279 |
for my $in_dir ( @in_dirs ) { |
268 |
$in_dir =~ s/\/$//; # strips the trailing / if any |
280 |
$in_dir =~ s/\/$//; # strips the trailing / if any |
269 |
@in_files = ( @in_files, listfiles($in_dir, $type, $action, \@filenames) ); |
281 |
@in_files = ( @in_files, listfiles($in_dir, $type, $action)); |
270 |
} |
282 |
} |
271 |
|
283 |
|
272 |
# restores the string list from file |
284 |
# restores the string list from file |
273 |
- |
|
|