~ubuntu-branches/ubuntu/vivid/intltool/vivid

« back to all changes in this revision

Viewing changes to intltool-update.in

  • Committer: Bazaar Package Importer
  • Author(s): Sebastian Dröge
  • Date: 2008-06-04 08:33:24 UTC
  • mfrom: (1.2.16 upstream) (4.1.1 lenny)
  • Revision ID: james.westby@ubuntu.com-20080604083324-t4s3ng5hxxnnsbxi
Tags: 0.40.0-1
New upstream release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!@INTLTOOL_PERL@ -w
 
2
# -*- Mode: perl; indent-tabs-mode: nil; c-basic-offset: 4  -*-
 
3
 
 
4
#
 
5
#  The Intltool Message Updater
 
6
#
 
7
#  Copyright (C) 2000-2003 Free Software Foundation.
 
8
#
 
9
#  Intltool is free software; you can redistribute it and/or
 
10
#  modify it under the terms of the GNU General Public License 
 
11
#  version 2 published by the Free Software Foundation.
 
12
#
 
13
#  Intltool is distributed in the hope that it will be useful,
 
14
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
15
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
16
#  General Public License for more details.
 
17
#
 
18
#  You should have received a copy of the GNU General Public License
 
19
#  along with this program; if not, write to the Free Software
 
20
#  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 
21
#
 
22
#  As a special exception to the GNU General Public License, if you
 
23
#  distribute this file as part of a program that contains a
 
24
#  configuration script generated by Autoconf, you may include it under
 
25
#  the same distribution terms that you use for the rest of that program.
 
26
#
 
27
#  Authors: Kenneth Christiansen <kenneth@gnu.org>
 
28
#           Maciej Stachowiak
 
29
#           Darin Adler <darin@bentspoon.com>
 
30
 
 
31
## Release information
 
32
my $PROGRAM = "intltool-update";
 
33
my $VERSION = "@VERSION@";
 
34
my $PACKAGE = "@PACKAGE@";
 
35
 
 
36
## Loaded modules
 
37
use strict;
 
38
use Getopt::Long;
 
39
use Cwd;
 
40
use File::Copy;
 
41
use File::Find;
 
42
 
 
43
## Scalars used by the option stuff
 
44
my $HELP_ARG       = 0;
 
45
my $VERSION_ARG    = 0;
 
46
my $DIST_ARG       = 0;
 
47
my $POT_ARG        = 0;
 
48
my $HEADERS_ARG    = 0;
 
49
my $MAINTAIN_ARG   = 0;
 
50
my $REPORT_ARG     = 0;
 
51
my $VERBOSE        = 0;
 
52
my $GETTEXT_PACKAGE = "";
 
53
my $OUTPUT_FILE    = "";
 
54
 
 
55
my @languages;
 
56
my %varhash = ();
 
57
my %po_files_by_lang = ();
 
58
 
 
59
# Regular expressions to categorize file types.
 
60
# FIXME: Please check if the following is correct
 
61
 
 
62
my $xml_support =
 
63
"xml(?:\\.in)*|".       # http://www.w3.org/XML/ (Note: .in is not required)
 
64
"ui|".                  # Bonobo specific - User Interface desc. files
 
65
"lang|".                # ?
 
66
"glade2?(?:\\.in)*|".   # Glade specific - User Interface desc. files (Note: .in is not required)
 
67
"scm(?:\\.in)*|".       # ? (Note: .in is not required)
 
68
"oaf(?:\\.in)+|".       # DEPRECATED: Replaces by Bonobo .server files 
 
69
"etspec|".              # ?
 
70
"server(?:\\.in)+|".    # Bonobo specific
 
71
"sheet(?:\\.in)+|".     # ?
 
72
"schemas(?:\\.in)+|".   # GConf specific
 
73
"pong(?:\\.in)+|".      # DEPRECATED: PONG is not used [by GNOME] any longer.
 
74
"kbd(?:\\.in)+|".       # GOK specific. 
 
75
"policy(?:\\.in)+";     # PolicyKit files
 
76
 
 
77
my $ini_support =
 
78
"icon(?:\\.in)+|".      # http://www.freedesktop.org/Standards/icon-theme-spec
 
79
"desktop(?:\\.in)+|".   # http://www.freedesktop.org/Standards/menu-spec
 
80
"caves(?:\\.in)+|".     # GNOME Games specific
 
81
"directory(?:\\.in)+|". # http://www.freedesktop.org/Standards/menu-spec
 
82
"soundlist(?:\\.in)+|". # GNOME specific
 
83
"keys(?:\\.in)+|".      # GNOME Mime database specific
 
84
"theme(?:\\.in)+|".     # http://www.freedesktop.org/Standards/icon-theme-spec
 
85
"service(?:\\.in)+";    # DBus specific
 
86
 
 
87
my $buildin_gettext_support = 
 
88
"c|y|cs|cc|cpp|c\\+\\+|h|hh|gob|py";
 
89
 
 
90
## Always flush buffer when printing
 
91
$| = 1;
 
92
 
 
93
## Sometimes the source tree will be rooted somewhere else.
 
94
my $SRCDIR = $ENV{"srcdir"} || ".";
 
95
my $POTFILES_in;
 
96
 
 
97
$POTFILES_in = "<$SRCDIR/POTFILES.in";
 
98
 
 
99
my $devnull = ($^O eq 'MSWin32' ? 'NUL:' : '/dev/null');
 
100
 
 
101
## Handle options
 
102
GetOptions 
 
103
(
 
104
 "help"                => \$HELP_ARG,
 
105
 "version"             => \$VERSION_ARG,
 
106
 "dist|d"              => \$DIST_ARG,
 
107
 "pot|p"               => \$POT_ARG,
 
108
 "headers|s"           => \$HEADERS_ARG,
 
109
 "maintain|m"          => \$MAINTAIN_ARG,
 
110
 "report|r"            => \$REPORT_ARG,
 
111
 "verbose|x"           => \$VERBOSE,
 
112
 "gettext-package|g=s" => \$GETTEXT_PACKAGE,
 
113
 "output-file|o=s"     => \$OUTPUT_FILE,
 
114
 ) or &Console_WriteError_InvalidOption;
 
115
 
 
116
&Console_Write_IntltoolHelp if $HELP_ARG;
 
117
&Console_Write_IntltoolVersion if $VERSION_ARG;
 
118
 
 
119
my $arg_count = ($DIST_ARG > 0)
 
120
    + ($POT_ARG > 0)
 
121
    + ($HEADERS_ARG > 0)
 
122
    + ($MAINTAIN_ARG > 0)
 
123
    + ($REPORT_ARG > 0);
 
124
 
 
125
&Console_Write_IntltoolHelp if $arg_count > 1;
 
126
 
 
127
my $MODULE = $GETTEXT_PACKAGE || FindPackageName() || "unknown";
 
128
 
 
129
if ($POT_ARG)
 
130
{
 
131
    &GenerateHeaders;
 
132
    &GeneratePOTemplate;
 
133
}
 
134
elsif ($HEADERS_ARG)
 
135
{
 
136
    &GenerateHeaders;
 
137
}
 
138
elsif ($MAINTAIN_ARG)
 
139
{
 
140
    &FindLeftoutFiles;
 
141
}
 
142
elsif ($REPORT_ARG)
 
143
{
 
144
    &GenerateHeaders;
 
145
    &GeneratePOTemplate;
 
146
    &Console_Write_CoverageReport;
 
147
}
 
148
elsif ((defined $ARGV[0]) && $ARGV[0] =~ /^[a-z]/)
 
149
{
 
150
    my $lang = $ARGV[0];
 
151
 
 
152
    ## Report error if the language file supplied
 
153
    ## to the command line is non-existent
 
154
    &Console_WriteError_NotExisting("$SRCDIR/$lang.po")
 
155
        if ! -s "$SRCDIR/$lang.po";
 
156
 
 
157
    if (!$DIST_ARG)
 
158
    {
 
159
        print "Working, please wait..." if $VERBOSE;
 
160
        &GenerateHeaders;
 
161
        &GeneratePOTemplate;
 
162
    }
 
163
    &POFile_Update ($lang, $OUTPUT_FILE);
 
164
    &Console_Write_TranslationStatus ($lang, $OUTPUT_FILE);
 
165
 
166
else 
 
167
{
 
168
    &Console_Write_IntltoolHelp;
 
169
}
 
170
 
 
171
exit;
 
172
 
 
173
#########
 
174
 
 
175
sub Console_Write_IntltoolVersion
 
176
{
 
177
    print <<_EOF_;
 
178
${PROGRAM} (${PACKAGE}) $VERSION
 
179
Written by Kenneth Christiansen, Maciej Stachowiak, and Darin Adler.
 
180
 
 
181
Copyright (C) 2000-2003 Free Software Foundation, Inc.
 
182
This is free software; see the source for copying conditions.  There is NO
 
183
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 
184
_EOF_
 
185
    exit;
 
186
}
 
187
 
 
188
sub Console_Write_IntltoolHelp
 
189
{
 
190
    print <<_EOF_;
 
191
Usage: ${PROGRAM} [OPTION]... LANGCODE
 
192
Updates PO template files and merge them with the translations.
 
193
 
 
194
Mode of operation (only one is allowed):
 
195
  -p, --pot                   generate the PO template only
 
196
  -s, --headers               generate the header files in POTFILES.in
 
197
  -m, --maintain              search for left out files from POTFILES.in
 
198
  -r, --report                display a status report for the module
 
199
  -d, --dist                  merge LANGCODE.po with existing PO template
 
200
 
 
201
Extra options:
 
202
  -g, --gettext-package=NAME  override PO template name, useful with --pot
 
203
  -o, --output-file=FILE      write merged translation to FILE
 
204
  -x, --verbose               display lots of feedback
 
205
      --help                  display this help and exit
 
206
      --version               output version information and exit
 
207
 
 
208
Examples of use:
 
209
${PROGRAM} --pot    just create a new PO template
 
210
${PROGRAM} xy       create new PO template and merge xy.po with it
 
211
 
 
212
Report bugs to http://bugzilla.gnome.org/ (product name "$PACKAGE")
 
213
or send email to <xml-i18n-tools\@gnome.org>.
 
214
_EOF_
 
215
    exit;
 
216
}
 
217
 
 
218
sub echo_n
 
219
{
 
220
    my $str = shift;
 
221
    my $ret = `echo "$str"`;
 
222
 
 
223
    $ret =~ s/\n$//; # do we need the "s" flag?
 
224
 
 
225
    return $ret;
 
226
}
 
227
 
 
228
sub POFile_DetermineType ($) 
 
229
{
 
230
   my $type = $_;
 
231
   my $gettext_type;
 
232
 
 
233
   my $xml_regex     = "(?:" . $xml_support . ")";
 
234
   my $ini_regex     = "(?:" . $ini_support . ")";
 
235
   my $buildin_regex = "(?:" . $buildin_gettext_support . ")";
 
236
 
 
237
   if ($type =~ /\[type: gettext\/([^\]].*)]/) 
 
238
   {
 
239
        $gettext_type=$1;
 
240
   }
 
241
   elsif ($type =~ /schemas(\.in)+$/) 
 
242
   {
 
243
        $gettext_type="schemas";
 
244
   }
 
245
   elsif ($type =~ /glade2?(\.in)*$/) 
 
246
   {
 
247
       $gettext_type="glade";
 
248
   }
 
249
   elsif ($type =~ /scm(\.in)*$/) 
 
250
   {
 
251
       $gettext_type="scheme";
 
252
   }
 
253
   elsif ($type =~ /keys(\.in)+$/) 
 
254
   {
 
255
       $gettext_type="keys";
 
256
   }
 
257
 
 
258
   # bucket types
 
259
 
 
260
   elsif ($type =~ /$xml_regex$/) 
 
261
   {
 
262
       $gettext_type="xml";
 
263
   }
 
264
   elsif ($type =~ /$ini_regex$/) 
 
265
   { 
 
266
       $gettext_type="ini";
 
267
   }
 
268
   elsif ($type =~ /$buildin_regex$/) 
 
269
   {
 
270
       $gettext_type="buildin";
 
271
   }
 
272
   else
 
273
   { 
 
274
       $gettext_type="unknown"; 
 
275
   }
 
276
 
 
277
   return "gettext\/$gettext_type";
 
278
}
 
279
 
 
280
sub TextFile_DetermineEncoding ($) 
 
281
{
 
282
    my $gettext_code="UTF-8"; # All files are UTF-8 by default
 
283
    my $filetype=`file $_ | cut -d ' ' -f 2`;
 
284
 
 
285
    if ($? eq "0")
 
286
    {
 
287
        if ($filetype =~ /^(ISO|UTF)/)
 
288
        {
 
289
            chomp ($gettext_code = $filetype);
 
290
        }
 
291
        elsif ($filetype =~ /^XML/)
 
292
        {
 
293
            $gettext_code="UTF-8"; # We asume that .glade and other .xml files are UTF-8
 
294
        }
 
295
    }
 
296
 
 
297
    return $gettext_code;
 
298
}
 
299
 
 
300
sub isNotValidMissing
 
301
{
 
302
    my ($file) = @_;
 
303
 
 
304
    return if $file =~ /^\{arch\}\/.*$/;
 
305
    return if $file =~ /^$varhash{"PACKAGE"}-$varhash{"VERSION"}\/.*$/;
 
306
}
 
307
 
 
308
sub FindLeftoutFiles
 
309
{
 
310
    my (@buf_i18n_plain,
 
311
        @buf_i18n_xml,
 
312
        @buf_i18n_xml_unmarked,
 
313
        @buf_i18n_ini,
 
314
        @buf_potfiles,
 
315
        @buf_potfiles_ignore,
 
316
        @buf_allfiles,
 
317
        @buf_allfiles_sorted,
 
318
        @buf_potfiles_sorted,
 
319
        @buf_potfiles_ignore_sorted
 
320
    );
 
321
 
 
322
    ## Search and find all translatable files
 
323
    find sub { 
 
324
        push @buf_i18n_plain,        "$File::Find::name" if /\.($buildin_gettext_support)$/;
 
325
        push @buf_i18n_xml,          "$File::Find::name" if /\.($xml_support)$/;
 
326
        push @buf_i18n_ini,          "$File::Find::name" if /\.($ini_support)$/;
 
327
        push @buf_i18n_xml_unmarked, "$File::Find::name" if /\.(schemas(\.in)+)$/;
 
328
        }, "..";
 
329
    find sub { 
 
330
        push @buf_i18n_plain,        "$File::Find::name" if /\.($buildin_gettext_support)$/;
 
331
        push @buf_i18n_xml,          "$File::Find::name" if /\.($xml_support)$/;
 
332
        push @buf_i18n_ini,          "$File::Find::name" if /\.($ini_support)$/;
 
333
        push @buf_i18n_xml_unmarked, "$File::Find::name" if /\.(schemas(\.in)+)$/;
 
334
        }, "$SRCDIR/.." if "$SRCDIR" ne ".";
 
335
 
 
336
    open POTFILES, $POTFILES_in or die "$PROGRAM:  there's no POTFILES.in!\n";
 
337
    @buf_potfiles = grep !/^(#|\s*$)/, <POTFILES>;
 
338
    close POTFILES;
 
339
 
 
340
    foreach (@buf_potfiles) {
 
341
        s/^\[.*]\s*//;
 
342
    }
 
343
 
 
344
    print "Searching for missing translatable files...\n" if $VERBOSE;
 
345
 
 
346
    ## Check if we should ignore some found files, when
 
347
    ## comparing with POTFILES.in
 
348
    foreach my $ignore ("POTFILES.skip", "POTFILES.ignore")
 
349
    {
 
350
        (-s "$SRCDIR/$ignore") or next;
 
351
 
 
352
        if ("$ignore" eq "POTFILES.ignore")
 
353
        {
 
354
            print "The usage of POTFILES.ignore is deprecated. Please consider moving the\n".
 
355
                  "content of this file to POTFILES.skip.\n";
 
356
        }
 
357
 
 
358
        print "Found $ignore: Ignoring files...\n" if $VERBOSE;
 
359
        open FILE, "<$SRCDIR/$ignore" or die "ERROR: Failed to open $SRCDIR/$ignore!\n";
 
360
            
 
361
        while (<FILE>)
 
362
        {
 
363
            next if (/^$/);
 
364
            next if (/^(#|\s*$)/);
 
365
 
 
366
            my $skipdir = "../$_";
 
367
            $skipdir = "$SRCDIR/../$_" if "$SRCDIR" ne ".";
 
368
            $skipdir =~ s/\n//g;
 
369
 
 
370
            my @dirignored;
 
371
 
 
372
            if (-d "$skipdir")
 
373
            {
 
374
                find sub {
 
375
                    push @dirignored, "$File::Find::name" if /\.($buildin_gettext_support)$/;
 
376
                    push @dirignored, "$File::Find::name" if /\.($xml_support)$/;
 
377
                    push @dirignored, "$File::Find::name" if /\.($ini_support)$/;
 
378
                    push @dirignored, "$File::Find::name" if /\.(schemas(\.in)+)$/;
 
379
                }, "$skipdir";
 
380
                foreach my $ignored (@dirignored)
 
381
                {
 
382
                    $ignored =~ s/^$SRCDIR\///g;
 
383
                    $ignored =~ s/^..\///g;
 
384
                    $ignored =~ s/$/\n/g;
 
385
                    push @buf_potfiles_ignore, $ignored;
 
386
                }
 
387
                next;
 
388
            }
 
389
            push @buf_potfiles_ignore, $_;
 
390
        }
 
391
        close FILE;
 
392
 
 
393
        @buf_potfiles_ignore_sorted = sort (@buf_potfiles_ignore);
 
394
    }
 
395
 
 
396
    foreach my $file (@buf_i18n_plain)
 
397
    {
 
398
        my $in_comment = 0;
 
399
        my $in_macro = 0;
 
400
 
 
401
        open FILE, "<$file";
 
402
        while (<FILE>)
 
403
        {
 
404
            # Handle continued multi-line comment.
 
405
            if ($in_comment)
 
406
            {
 
407
                next unless s-.*\*/--;
 
408
                $in_comment = 0;
 
409
            }
 
410
 
 
411
            # Handle continued macro.
 
412
            if ($in_macro)
 
413
            {
 
414
                $in_macro = 0 unless /\\$/;
 
415
                next;
 
416
            }
 
417
 
 
418
            # Handle start of macro (or any preprocessor directive).
 
419
            if (/^\s*\#/)
 
420
            {
 
421
                $in_macro = 1 if /^([^\\]|\\.)*\\$/;
 
422
                next;
 
423
            }
 
424
 
 
425
            # Handle comments and quoted text.
 
426
            while (m-(/\*|//|\'|\")-) # \' and \" keep emacs perl mode happy
 
427
            {
 
428
                my $match = $1;
 
429
                if ($match eq "/*")
 
430
                {
 
431
                    if (!s-/\*.*?\*/--)
 
432
                    {
 
433
                        s-/\*.*--;
 
434
                        $in_comment = 1;
 
435
                    }
 
436
                }
 
437
                elsif ($match eq "//")
 
438
                {
 
439
                    s-//.*--;
 
440
                }
 
441
                else # ' or "
 
442
                {
 
443
                    if (!s-$match([^\\]|\\.)*?$match-QUOTEDTEXT-)
 
444
                    {
 
445
                        warn "mismatched quotes at line $. in $file\n";
 
446
                        s-$match.*--;
 
447
                    }
 
448
                }
 
449
            }       
 
450
 
 
451
            if (/\w\.GetString *\(QUOTEDTEXT/)
 
452
            {
 
453
                if (defined isNotValidMissing (unpack("x3 A*", $file))) {
 
454
                    ## Remove the first 3 chars and add newline
 
455
                    push @buf_allfiles, unpack("x3 A*", $file) . "\n";
 
456
                }
 
457
                last;
 
458
            }
 
459
 
 
460
            ## C_ N_ Q_ and _ are the macros defined in gi8n.h
 
461
            if (/[CNQ]?_ *\(QUOTEDTEXT/)
 
462
            {
 
463
                if (defined isNotValidMissing (unpack("x3 A*", $file))) {
 
464
                    ## Remove the first 3 chars and add newline
 
465
                    push @buf_allfiles, unpack("x3 A*", $file) . "\n";
 
466
                }
 
467
                last;
 
468
            }
 
469
        }
 
470
        close FILE;
 
471
    }
 
472
 
 
473
    foreach my $file (@buf_i18n_xml) 
 
474
    {
 
475
        open FILE, "<$file";
 
476
        
 
477
        while (<FILE>) 
 
478
        {
 
479
            # FIXME: share the pattern matching code with intltool-extract
 
480
            if (/\s_[-A-Za-z0-9._:]+\s*=\s*\"([^"]+)\"/ || /<_[^>]+>/ || /translatable=\"yes\"/)
 
481
            {
 
482
                if (defined isNotValidMissing (unpack("x3 A*", $file))) {
 
483
                    push @buf_allfiles, unpack("x3 A*", $file) . "\n";
 
484
                }
 
485
                last;
 
486
            }
 
487
        }
 
488
        close FILE;
 
489
    }
 
490
 
 
491
    foreach my $file (@buf_i18n_ini)
 
492
    {
 
493
        open FILE, "<$file";
 
494
        while (<FILE>) 
 
495
        {
 
496
            if (/_(.*)=/)
 
497
            {
 
498
                if (defined isNotValidMissing (unpack("x3 A*", $file))) {
 
499
                    push @buf_allfiles, unpack("x3 A*", $file) . "\n";
 
500
                }
 
501
                last;
 
502
            }
 
503
        }
 
504
        close FILE;
 
505
    }
 
506
 
 
507
    foreach my $file (@buf_i18n_xml_unmarked)
 
508
    {
 
509
        if (defined isNotValidMissing (unpack("x3 A*", $file))) {
 
510
            push @buf_allfiles, unpack("x3 A*", $file) . "\n";
 
511
        }
 
512
    }
 
513
 
 
514
 
 
515
    @buf_allfiles_sorted = sort (@buf_allfiles);
 
516
    @buf_potfiles_sorted = sort (@buf_potfiles);
 
517
 
 
518
    my %in2;
 
519
    foreach (@buf_potfiles_sorted) 
 
520
    {
 
521
        s#^$SRCDIR/../##;
 
522
        s#^$SRCDIR/##;
 
523
        $in2{$_} = 1;
 
524
    }
 
525
 
 
526
    foreach (@buf_potfiles_ignore_sorted) 
 
527
    {
 
528
        s#^$SRCDIR/../##;
 
529
        s#^$SRCDIR/##;
 
530
        $in2{$_} = 1;
 
531
    }
 
532
 
 
533
    my @result;
 
534
 
 
535
    foreach (@buf_allfiles_sorted)
 
536
    {
 
537
        my $dummy = $_;
 
538
        my $srcdir = $SRCDIR;
 
539
 
 
540
        $srcdir =~ s#^../##;
 
541
        $dummy =~ s#^$srcdir/../##;
 
542
        $dummy =~ s#^$srcdir/##;
 
543
        $dummy =~ s#_build/##;
 
544
        if (!exists($in2{$dummy}))
 
545
        {
 
546
            push @result, $dummy
 
547
        }
 
548
    }
 
549
 
 
550
    my @buf_potfiles_notexist;
 
551
 
 
552
    foreach (@buf_potfiles_sorted)
 
553
    {
 
554
        chomp (my $dummy = $_);
 
555
        if ("$dummy" ne "" and !(-f "$SRCDIR/../$dummy" or -f "../$dummy"))
 
556
        {
 
557
            push @buf_potfiles_notexist, $_;
 
558
        }
 
559
    }
 
560
 
 
561
    ## Save file with information about the files missing
 
562
    ## if any, and give information about this procedure.
 
563
    if (@result + @buf_potfiles_notexist > 0)
 
564
    {
 
565
        if (@result) 
 
566
        {
 
567
            print "\n" if $VERBOSE;
 
568
            unlink "missing";
 
569
            open OUT, ">missing";
 
570
            print OUT @result;
 
571
            close OUT;
 
572
            warn "\e[1mThe following files contain translations and are currently not in use. Please\e[0m\n".
 
573
                 "\e[1mconsider adding these to the POTFILES.in file, located in the po/ directory.\e[0m\n\n";
 
574
            print STDERR @result, "\n";
 
575
            warn "If some of these files are left out on purpose then please add them to\n".
 
576
                 "POTFILES.skip instead of POTFILES.in. A file \e[1m'missing'\e[0m containing this list\n".
 
577
                 "of left out files has been written in the current directory.\n";
 
578
        }
 
579
        if (@buf_potfiles_notexist)
 
580
        {
 
581
            unlink "notexist";
 
582
            open OUT, ">notexist";
 
583
            print OUT @buf_potfiles_notexist;
 
584
            close OUT;
 
585
            warn "\n" if ($VERBOSE or @result);
 
586
            warn "\e[1mThe following files do not exist anymore:\e[0m\n\n";
 
587
            warn @buf_potfiles_notexist, "\n";
 
588
            warn "Please remove them from POTFILES.in. A file \e[1m'notexist'\e[0m\n".
 
589
                 "containing this list of absent files has been written in the current directory.\n";
 
590
        }
 
591
    }
 
592
 
 
593
    ## If there is nothing to complain about, notify the user
 
594
    else {
 
595
        print "\nAll files containing translations are present in POTFILES.in.\n" if $VERBOSE;
 
596
    }
 
597
}
 
598
 
 
599
sub Console_WriteError_InvalidOption
 
600
{
 
601
    ## Handle invalid arguments
 
602
    print STDERR "Try `${PROGRAM} --help' for more information.\n";
 
603
    exit 1;
 
604
}
 
605
 
 
606
sub isProgramInPath
 
607
{
 
608
    my ($file) = @_;
 
609
    # If either a file exists, or when run it returns 0 exit status
 
610
    return 1 if ((-x $file) or (system("$file --version >$devnull") == 0));
 
611
    return 0;
 
612
}
 
613
 
 
614
sub isGNUGettextTool
 
615
{
 
616
    my ($file) = @_;
 
617
    # Check that we are using GNU gettext tools
 
618
    if (isProgramInPath ($file))
 
619
    {
 
620
        my $version = `$file --version`;
 
621
        return 1 if ($version =~ m/.*\(GNU .*\).*/);
 
622
    }
 
623
    return 0;
 
624
}
 
625
 
 
626
sub GenerateHeaders
 
627
{
 
628
    my $EXTRACT = $ENV{"INTLTOOL_EXTRACT"} || "intltool-extract";
 
629
 
 
630
    ## Generate the .h header files, so we can allow glade and
 
631
    ## xml translation support
 
632
    if (! isProgramInPath ("$EXTRACT"))
 
633
    {
 
634
        print STDERR "\n *** The intltool-extract script wasn't found!"
 
635
             ."\n *** Without it, intltool-update can not generate files.\n";
 
636
        exit;
 
637
    }
 
638
    else
 
639
    {
 
640
        open (FILE, $POTFILES_in) or die "$PROGRAM: POTFILES.in not found.\n";
 
641
        
 
642
        while (<FILE>) 
 
643
        {
 
644
           chomp;
 
645
           next if /^\[\s*encoding/;
 
646
 
 
647
           ## Find xml files in POTFILES.in and generate the
 
648
           ## files with help from the extract script
 
649
 
 
650
           my $gettext_type= &POFile_DetermineType ($1);
 
651
 
 
652
           if (/\.($xml_support|$ini_support)$/ || /^\[/)
 
653
           {
 
654
               s/^\[[^\[].*]\s*//;
 
655
 
 
656
               my $filename = "../$_";
 
657
 
 
658
               if ($VERBOSE)
 
659
               {
 
660
                   system ($EXTRACT, "--update", "--srcdir=$SRCDIR",
 
661
                           "--type=$gettext_type", $filename);
 
662
               } 
 
663
               else 
 
664
               {
 
665
                   system ($EXTRACT, "--update", "--type=$gettext_type", 
 
666
                           "--srcdir=$SRCDIR", "--quiet", $filename);
 
667
               }
 
668
           }
 
669
       }
 
670
       close FILE;
 
671
   }
 
672
}
 
673
 
 
674
#
 
675
# Generate .pot file from POTFILES.in
 
676
#
 
677
sub GeneratePOTemplate
 
678
{
 
679
    my $XGETTEXT = $ENV{"XGETTEXT"} || "xgettext";
 
680
    my $XGETTEXT_ARGS = $ENV{"XGETTEXT_ARGS"} || '';
 
681
    chomp $XGETTEXT;
 
682
 
 
683
    if (! isGNUGettextTool ("$XGETTEXT"))
 
684
    {
 
685
        print STDERR " *** GNU xgettext is not found on this system!\n".
 
686
                     " *** Without it, intltool-update can not extract strings.\n";
 
687
        exit;
 
688
    }
 
689
 
 
690
    print "Building $MODULE.pot...\n" if $VERBOSE;
 
691
 
 
692
    open INFILE, $POTFILES_in;
 
693
    unlink "POTFILES.in.temp";
 
694
    open OUTFILE, ">POTFILES.in.temp" or die("Cannot open POTFILES.in.temp for writing");
 
695
 
 
696
    my $gettext_support_nonascii = 0;
 
697
 
 
698
    # checks for GNU gettext >= 0.12
 
699
    my $dummy = `$XGETTEXT --version --from-code=UTF-8 >$devnull 2>$devnull`;
 
700
    if ($? == 0)
 
701
    {
 
702
        $gettext_support_nonascii = 1;
 
703
    }
 
704
    else
 
705
    {
 
706
        # require gnu gettext >= 0.12
 
707
        die "$PROGRAM: GNU gettext >= 0.12 is required for intltool\n";
 
708
    }
 
709
 
 
710
    my $encoding = "UTF-8";
 
711
    my $forced_gettext_code;
 
712
    my @temp_headers;
 
713
    my $encoding_problem_is_reported = 0;
 
714
 
 
715
    while (<INFILE>) 
 
716
    {
 
717
        next if (/^#/ or /^\s*$/);
 
718
 
 
719
        chomp;
 
720
 
 
721
        my $gettext_code;
 
722
 
 
723
        if (/^\[\s*encoding:\s*(.*)\s*\]/)
 
724
        {
 
725
            $forced_gettext_code=$1;
 
726
        }
 
727
        elsif (/\.($xml_support|$ini_support)$/ || /^\[/)
 
728
        {
 
729
            s/^\[.*]\s*//;
 
730
            print OUTFILE "../$_.h\n";
 
731
            push @temp_headers, "../$_.h";
 
732
            $gettext_code = &TextFile_DetermineEncoding ("../$_.h") if ($gettext_support_nonascii and not defined $forced_gettext_code);
 
733
        } 
 
734
        else 
 
735
        {
 
736
            print OUTFILE "$SRCDIR/../$_\n";
 
737
            $gettext_code = &TextFile_DetermineEncoding ("$SRCDIR/../$_") if ($gettext_support_nonascii and not defined $forced_gettext_code);
 
738
        }
 
739
 
 
740
        next if (! $gettext_support_nonascii);
 
741
 
 
742
        if (defined $forced_gettext_code)
 
743
        {
 
744
            $encoding=$forced_gettext_code;
 
745
        }
 
746
        elsif (defined $gettext_code and "$encoding" ne "$gettext_code")
 
747
        {
 
748
            if ($encoding eq "ASCII")
 
749
            {
 
750
                $encoding=$gettext_code;
 
751
            }
 
752
            elsif ($gettext_code ne "ASCII")
 
753
            {
 
754
                # Only report once because the message is quite long
 
755
                if (! $encoding_problem_is_reported)
 
756
                {
 
757
                    print STDERR "WARNING: You should use the same file encoding for all your project files,\n".
 
758
                                 "         but $PROGRAM thinks that most of the source files are in\n".
 
759
                                 "         $encoding encoding, while \"$_\" is (likely) in\n".
 
760
                                 "         $gettext_code encoding. If you are sure that all translatable strings\n".
 
761
                                 "         are in same encoding (say UTF-8), please \e[1m*prepend*\e[0m the following\n".
 
762
                                 "         line to POTFILES.in:\n\n".
 
763
                                 "                 [encoding: UTF-8]\n\n".
 
764
                                 "         and make sure that configure.in/ac checks for $PACKAGE >= 0.27 .\n".
 
765
                                 "(such warning message will only be reported once.)\n";
 
766
                    $encoding_problem_is_reported = 1;
 
767
                }
 
768
            }
 
769
        }
 
770
    }
 
771
 
 
772
    close OUTFILE;
 
773
    close INFILE;
 
774
 
 
775
    unlink "$MODULE.pot";
 
776
    my @xgettext_argument=("$XGETTEXT",
 
777
                           "--add-comments",
 
778
                           "--directory\=.",
 
779
                           "--default-domain\=$MODULE",
 
780
                           "--flag\=g_strdup_printf:1:c-format",
 
781
                           "--flag\=g_string_printf:2:c-format",
 
782
                           "--flag\=g_string_append_printf:2:c-format",
 
783
                           "--flag\=g_error_new:3:c-format",
 
784
                           "--flag\=g_set_error:4:c-format",
 
785
                           "--flag\=g_markup_printf_escaped:1:c-format",
 
786
                           "--flag\=g_log:3:c-format",
 
787
                           "--flag\=g_print:1:c-format",
 
788
                           "--flag\=g_printerr:1:c-format",
 
789
                           "--flag\=g_printf:1:c-format",
 
790
                           "--flag\=g_fprintf:2:c-format",
 
791
                           "--flag\=g_sprintf:2:c-format",
 
792
                           "--flag\=g_snprintf:3:c-format",
 
793
                           "--flag\=g_scanner_error:2:c-format",
 
794
                           "--flag\=g_scanner_warn:2:c-format",
 
795
                           "--output\=$MODULE\.pot",
 
796
                           "--files-from\=\.\/POTFILES\.in\.temp");
 
797
    my $XGETTEXT_KEYWORDS = &FindPOTKeywords;
 
798
    push @xgettext_argument, $XGETTEXT_KEYWORDS;
 
799
    my $MSGID_BUGS_ADDRESS = &FindMakevarsBugAddress;
 
800
    push @xgettext_argument, "--msgid-bugs-address\=\"$MSGID_BUGS_ADDRESS\"" if $MSGID_BUGS_ADDRESS;
 
801
    push @xgettext_argument, "--from-code\=$encoding" if ($gettext_support_nonascii);
 
802
    push @xgettext_argument, $XGETTEXT_ARGS if $XGETTEXT_ARGS;
 
803
    my $xgettext_command = join ' ', @xgettext_argument;
 
804
 
 
805
    # intercept xgettext error message
 
806
    print "Running $xgettext_command\n" if $VERBOSE;
 
807
    my $xgettext_error_msg = `$xgettext_command 2>\&1`;
 
808
    my $command_failed = $?;
 
809
 
 
810
    unlink "POTFILES.in.temp";
 
811
 
 
812
    print "Removing generated header (.h) files..." if $VERBOSE;
 
813
    unlink foreach (@temp_headers);
 
814
    print "done.\n" if $VERBOSE;
 
815
 
 
816
    if (! $command_failed)
 
817
    {
 
818
        if (! -e "$MODULE.pot")
 
819
        {
 
820
            print "None of the files in POTFILES.in contain strings marked for translation.\n" if $VERBOSE;
 
821
        }
 
822
        else
 
823
        {
 
824
            print "Wrote $MODULE.pot\n" if $VERBOSE;
 
825
        }
 
826
    }
 
827
    else
 
828
    {
 
829
        if ($xgettext_error_msg =~ /--from-code/)
 
830
        {
 
831
            my $errlocation = "unknown";
 
832
 
 
833
            if ($xgettext_error_msg =~ /Non-ASCII string at (.*)\..*/)
 
834
            {
 
835
                $errlocation = $1;
 
836
            }
 
837
            print STDERR "ERROR: xgettext failed to generate PO tempalte file because the following     \n".
 
838
                         "       file contains strings marked for translation, not encoded in UTF-8.    \n".
 
839
                         "       Please ensure all strings marked for translation are UTF-8 encoded.  \n\n".
 
840
                         "           $errlocation\n\n";
 
841
        }
 
842
        else
 
843
        {
 
844
            print STDERR "$xgettext_error_msg";
 
845
            if (-e "$MODULE.pot")
 
846
            {
 
847
                # is this possible?
 
848
                print STDERR "ERROR: xgettext failed but still managed to generate PO template file.\n".
 
849
                             "       Please consult error message above if there is any.\n";
 
850
            }
 
851
            else
 
852
            {
 
853
                print STDERR "ERROR: xgettext failed to generate PO template file. Please consult\n".
 
854
                             "       error message above if there is any.\n";
 
855
            }
 
856
        }
 
857
        exit (1);
 
858
    }
 
859
}
 
860
 
 
861
sub POFile_Update
 
862
{
 
863
    -f "$MODULE.pot" or die "$PROGRAM: $MODULE.pot does not exist.\n";
 
864
 
 
865
    my $MSGMERGE = $ENV{"MSGMERGE"} || "msgmerge";
 
866
    my ($lang, $outfile) = @_;
 
867
 
 
868
    if (! isGNUGettextTool ("$MSGMERGE"))
 
869
    {
 
870
        print STDERR " *** GNU msgmerge is not found on this system!\n".
 
871
                     " *** Without it, intltool-update can not extract strings.\n";
 
872
        exit;
 
873
    }
 
874
 
 
875
    print "Merging $SRCDIR/$lang.po with $MODULE.pot..." if $VERBOSE;
 
876
 
 
877
    my $infile = "$SRCDIR/$lang.po";
 
878
    $outfile = "$SRCDIR/$lang.po" if ($outfile eq "");
 
879
 
 
880
    # I think msgmerge won't overwrite old file if merge is not successful
 
881
    system ("$MSGMERGE", "-o", $outfile, $infile, "$MODULE.pot");
 
882
}
 
883
 
 
884
sub Console_WriteError_NotExisting
 
885
{
 
886
    my ($file) = @_;
 
887
 
 
888
    ## Report error if supplied language file is non-existing
 
889
    print STDERR "$PROGRAM: $file does not exist!\n";
 
890
    print STDERR "Try '$PROGRAM --help' for more information.\n";
 
891
    exit;
 
892
}
 
893
 
 
894
sub GatherPOFiles
 
895
{
 
896
    my @po_files = glob ("./*.po");
 
897
 
 
898
    @languages = map (&POFile_GetLanguage, @po_files);
 
899
 
 
900
    foreach my $lang (@languages) 
 
901
    {
 
902
        $po_files_by_lang{$lang} = shift (@po_files);
 
903
    }
 
904
}
 
905
 
 
906
sub POFile_GetLanguage ($)
 
907
{
 
908
    s/^(.*\/)?(.+)\.po$/$2/;
 
909
    return $_;
 
910
}
 
911
 
 
912
sub Console_Write_TranslationStatus
 
913
{
 
914
    my ($lang, $output_file) = @_;
 
915
    my $MSGFMT = $ENV{"MSGFMT"} || "msgfmt";
 
916
 
 
917
    if (! isGNUGettextTool ("$MSGFMT"))
 
918
    {
 
919
        print STDERR " *** GNU msgfmt is not found on this system!\n".
 
920
                     " *** Without it, intltool-update can not extract strings.\n";
 
921
        exit;
 
922
    }
 
923
 
 
924
    $output_file = "$SRCDIR/$lang.po" if ($output_file eq "");
 
925
 
 
926
    system ("$MSGFMT", "-o", "$devnull", "--verbose", $output_file);
 
927
}
 
928
 
 
929
sub Console_Write_CoverageReport
 
930
{
 
931
    my $MSGFMT = $ENV{"MSGFMT"} || "msgfmt";
 
932
 
 
933
    if (! isGNUGettextTool ("$MSGFMT"))
 
934
    {
 
935
        print STDERR " *** GNU msgfmt is not found on this system!\n".
 
936
                     " *** Without it, intltool-update can not extract strings.\n";
 
937
        exit;
 
938
    }
 
939
 
 
940
    &GatherPOFiles;
 
941
 
 
942
    foreach my $lang (@languages) 
 
943
    {
 
944
        print STDERR "$lang: ";
 
945
        &POFile_Update ($lang, "");
 
946
    }
 
947
 
 
948
    print STDERR "\n\n * Current translation support in $MODULE \n\n";
 
949
 
 
950
    foreach my $lang (@languages)
 
951
    {
 
952
        print STDERR "$lang: ";
 
953
        system ("$MSGFMT", "-o", "$devnull", "--verbose", "$SRCDIR/$lang.po");
 
954
    }
 
955
}
 
956
 
 
957
sub SubstituteVariable
 
958
{
 
959
    my ($str) = @_;
 
960
    
 
961
    # always need to rewind file whenever it has been accessed
 
962
    seek (CONF, 0, 0);
 
963
 
 
964
    # cache each variable. varhash is global to we can add
 
965
    # variables elsewhere.
 
966
    while (<CONF>)
 
967
    {
 
968
        if (/^(\w+)=(.*)$/)
 
969
        {
 
970
            ($varhash{$1} = $2) =~  s/^["'](.*)["']$/$1/;
 
971
        }
 
972
    }
 
973
    
 
974
    if ($str =~ /^(.*)\${?([A-Z_]+)}?(.*)$/)
 
975
    {
 
976
        my $rest = $3;
 
977
        my $untouched = $1;
 
978
        my $sub = "";
 
979
        # Ignore recursive definitions of variables
 
980
        $sub = $varhash{$2} if defined $varhash{$2} and $varhash{$2} !~ /\${?$2}?/;
 
981
 
 
982
        return SubstituteVariable ("$untouched$sub$rest");
 
983
    }
 
984
    
 
985
    # We're using Perl backticks ` and "echo -n" here in order to 
 
986
    # expand any shell escapes (such as backticks themselves) in every variable
 
987
    return echo_n ($str);
 
988
}
 
989
 
 
990
sub CONF_Handle_Open
 
991
{
 
992
    my $base_dirname = getcwd();
 
993
    $base_dirname =~ s@.*/@@;
 
994
 
 
995
    my ($conf_in, $src_dir);
 
996
 
 
997
    if ($base_dirname =~ /^po(-.+)?$/) 
 
998
    {
 
999
        if (-f "Makevars") 
 
1000
        {
 
1001
            my $makefile_source;
 
1002
 
 
1003
            local (*IN);
 
1004
            open (IN, "<Makevars") || die "can't open Makevars: $!";
 
1005
 
 
1006
            while (<IN>) 
 
1007
            {
 
1008
                if (/^top_builddir[ \t]*=/) 
 
1009
                {
 
1010
                    $src_dir = $_;
 
1011
                    $src_dir =~ s/^top_builddir[ \t]*=[ \t]*([^ \t\n\r]*)/$1/;
 
1012
 
 
1013
                    chomp $src_dir;
 
1014
                    if (-f "$src_dir" . "/configure.ac") {
 
1015
                        $conf_in = "$src_dir" . "/configure.ac" . "\n";
 
1016
                    } else {
 
1017
                        $conf_in = "$src_dir" . "/configure.in" . "\n";
 
1018
                    }
 
1019
                    last;
 
1020
                }
 
1021
            }
 
1022
            close IN;
 
1023
 
 
1024
            $conf_in || die "Cannot find top_builddir in Makevars.";
 
1025
        }
 
1026
        elsif (-f "$SRCDIR/../configure.ac") 
 
1027
        {
 
1028
            $conf_in = "$SRCDIR/../configure.ac";
 
1029
        } 
 
1030
        elsif (-f "$SRCDIR/../configure.in") 
 
1031
        {
 
1032
            $conf_in = "$SRCDIR/../configure.in";
 
1033
        } 
 
1034
        else 
 
1035
        {
 
1036
            my $makefile_source;
 
1037
 
 
1038
            local (*IN);
 
1039
            open (IN, "<Makefile") || return;
 
1040
 
 
1041
            while (<IN>) 
 
1042
            {
 
1043
                if (/^top_srcdir[ \t]*=/) 
 
1044
                {
 
1045
                    $src_dir = $_;                  
 
1046
                    $src_dir =~ s/^top_srcdir[ \t]*=[ \t]*([^ \t\n\r]*)/$1/;
 
1047
 
 
1048
                    chomp $src_dir;
 
1049
                    $conf_in = "$src_dir" . "/configure.in" . "\n";
 
1050
 
 
1051
                    last;
 
1052
                }
 
1053
            }
 
1054
            close IN;
 
1055
 
 
1056
            $conf_in || die "Cannot find top_srcdir in Makefile.";
 
1057
        }
 
1058
 
 
1059
        open (CONF, "<$conf_in");
 
1060
    }
 
1061
    else
 
1062
    {
 
1063
        print STDERR "$PROGRAM: Unable to proceed.\n" .
 
1064
                     "Make sure to run this script inside the po directory.\n";
 
1065
        exit;
 
1066
    }
 
1067
}
 
1068
 
 
1069
sub FindPackageName
 
1070
{
 
1071
    my $version;
 
1072
    my $domain = &FindMakevarsDomain;
 
1073
    my $name = $domain || "untitled";
 
1074
 
 
1075
    &CONF_Handle_Open;
 
1076
 
 
1077
    my $conf_source; {
 
1078
        local (*IN);
 
1079
        open (IN, "<&CONF") || return $name;
 
1080
        seek (IN, 0, 0);
 
1081
        local $/; # slurp mode
 
1082
        $conf_source = <IN>;
 
1083
        close IN;
 
1084
    }
 
1085
 
 
1086
    # priority for getting package name:
 
1087
    # 1. GETTEXT_PACKAGE
 
1088
    # 2. first argument of AC_INIT (with >= 2 arguments)
 
1089
    # 3. first argument of AM_INIT_AUTOMAKE (with >= 2 argument)
 
1090
 
 
1091
    # /^AM_INIT_AUTOMAKE\([\s\[]*([^,\)\s\]]+)/m 
 
1092
    # the \s makes this not work, why?
 
1093
    if ($conf_source =~ /^AM_INIT_AUTOMAKE\(([^,\)]+),([^,\)]+)/m)
 
1094
    {
 
1095
        ($name, $version) = ($1, $2);
 
1096
        $name    =~ s/[\[\]\s]//g;
 
1097
        $version =~ s/[\[\]\s]//g;
 
1098
        $name    =~ s/\(+$//g;
 
1099
        $version =~ s/\(+$//g;
 
1100
 
 
1101
        $varhash{"PACKAGE_NAME"} = $name if (not $name =~ /\${?AC_PACKAGE_NAME}?/);
 
1102
        $varhash{"PACKAGE"} = $name if (not $name =~ /\${?PACKAGE}?/);
 
1103
        $varhash{"PACKAGE_VERSION"} = $version if (not $name =~ /\${?AC_PACKAGE_VERSION}?/);
 
1104
        $varhash{"VERSION"} = $version if (not $name =~ /\${?VERSION}?/);
 
1105
    }
 
1106
    
 
1107
    if ($conf_source =~ /^AC_INIT\(([^,\)]+),([^,\)]+)/m) 
 
1108
    {
 
1109
        ($name, $version) = ($1, $2);
 
1110
        $name    =~ s/[\[\]\s]//g;
 
1111
        $version =~ s/[\[\]\s]//g;
 
1112
        $name    =~ s/\(+$//g;
 
1113
        $version =~ s/\(+$//g;
 
1114
 
 
1115
        $varhash{"PACKAGE_NAME"} = $name if (not $name =~ /\${?AC_PACKAGE_NAME}?/);
 
1116
        $varhash{"PACKAGE"} = $name if (not $name =~ /\${?PACKAGE}?/);
 
1117
        $varhash{"PACKAGE_VERSION"} = $version if (not $name =~ /\${?AC_PACKAGE_VERSION}?/);
 
1118
        $varhash{"VERSION"} = $version if (not $name =~ /\${?VERSION}?/);
 
1119
    }
 
1120
 
 
1121
    # \s makes this not work, why?
 
1122
    $name = $1 if $conf_source =~ /^GETTEXT_PACKAGE=\[?([^\n\]]+)/m;
 
1123
    
 
1124
    # m4 macros AC_PACKAGE_NAME, AC_PACKAGE_VERSION etc. have same value
 
1125
    # as corresponding $PACKAGE_NAME, $PACKAGE_VERSION etc. shell variables.
 
1126
    $name =~ s/\bAC_PACKAGE_/\$PACKAGE_/g;
 
1127
 
 
1128
    $name = $domain if $domain;
 
1129
 
 
1130
    $name = SubstituteVariable ($name);
 
1131
    $name =~ s/^["'](.*)["']$/$1/;
 
1132
 
 
1133
    return $name if $name;
 
1134
}
 
1135
 
 
1136
 
 
1137
sub FindPOTKeywords
 
1138
{
 
1139
 
 
1140
    my $keywords = "--keyword\=\_ --keyword\=N\_ --keyword\=U\_ --keyword\=Q\_";
 
1141
    my $varname = "XGETTEXT_OPTIONS";
 
1142
    my $make_source; {
 
1143
        local (*IN);
 
1144
        open (IN, "<Makevars") || (open(IN, "<Makefile.in.in") && ($varname = "XGETTEXT_KEYWORDS")) || return $keywords;
 
1145
        seek (IN, 0, 0);
 
1146
        local $/; # slurp mode
 
1147
        $make_source = <IN>;
 
1148
        close IN;
 
1149
    }
 
1150
 
 
1151
    # unwrap lines split with a trailing \
 
1152
    $make_source =~  s/\\ $ \n/ /mxg;
 
1153
    $keywords = $1 if $make_source =~ /^$varname[ ]*=\[?([^\n\]]+)/m;
 
1154
    
 
1155
    return $keywords;
 
1156
}
 
1157
 
 
1158
sub FindMakevarsDomain
 
1159
{
 
1160
 
 
1161
    my $domain = "";
 
1162
    my $makevars_source; { 
 
1163
        local (*IN);
 
1164
        open (IN, "<Makevars") || return $domain;
 
1165
        seek (IN, 0, 0);
 
1166
        local $/; # slurp mode
 
1167
        $makevars_source = <IN>;
 
1168
        close IN;
 
1169
    }
 
1170
 
 
1171
    $domain = $1 if $makevars_source =~ /^DOMAIN[ ]*=\[?([^\n\]\$]+)/m;
 
1172
    $domain =~ s/^\s+//;
 
1173
    $domain =~ s/\s+$//;
 
1174
    
 
1175
    return $domain;
 
1176
}
 
1177
 
 
1178
sub FindMakevarsBugAddress
 
1179
{
 
1180
 
 
1181
    my $address = "";
 
1182
    my $makevars_source; { 
 
1183
        local (*IN);
 
1184
        open (IN, "<Makevars") || return undef;
 
1185
        seek (IN, 0, 0);
 
1186
        local $/; # slurp mode
 
1187
        $makevars_source = <IN>;
 
1188
        close IN;
 
1189
    }
 
1190
 
 
1191
    $address = $1 if $makevars_source =~ /^MSGID_BUGS_ADDRESS[ ]*=\[?([^\n\]\$]+)/m;
 
1192
    $address =~ s/^\s+//;
 
1193
    $address =~ s/\s+$//;
 
1194
    
 
1195
    return $address;
 
1196
}