~ubuntu-branches/ubuntu/warty/gnome-vfs2/warty

« back to all changes in this revision

Viewing changes to intltool-update.in

  • Committer: Bazaar Package Importer
  • Author(s): Sebastien Bacher
  • Date: 2004-10-11 16:04:46 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20041011160446-lc0ervct24rylahc
Tags: 2.8.2-0ubuntu1
* New upstream release:
  - performance increase in gnome-vfs-volume-monitor.
  - make folders open with components, to make run-dialog work for folders.
  - add support for additional headers to http backend (Warty: #2163).
  - default to the workgroup specified in smb.conf for network://.
* debian/patches/13_ssl_crash.patch:
  - removed, these changes are in the new version.
* debian/patches/14_default-workgroup.patch:
  - removed, these changes are in the new version.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
#!@INTLTOOL_PERL@ -w
 
2
# -*- Mode: perl; indent-tabs-mode: nil; c-basic-offset: 4  -*-
2
3
 
3
4
#
4
5
#  The Intltool Message Updater
5
6
#
6
 
#  Copyright (C) 2000-2002 Free Software Foundation.
 
7
#  Copyright (C) 2000-2003 Free Software Foundation.
7
8
#
8
9
#  Intltool is free software; you can redistribute it and/or
9
10
#  modify it under the terms of the GNU General Public License 
29
30
 
30
31
## Release information
31
32
my $PROGRAM = "intltool-update";
32
 
my $VERSION = "0.18";
 
33
my $VERSION = "0.31.1";
33
34
my $PACKAGE = "intltool";
34
35
 
35
36
## Loaded modules
49
50
my $REPORT_ARG     = 0;
50
51
my $VERBOSE        = 0;
51
52
my $GETTEXT_PACKAGE = "";
 
53
my $OUTPUT_FILE    = "";
52
54
 
53
55
my @languages;
 
56
my %varhash = ();
54
57
my %po_files_by_lang = ();
55
58
 
56
59
# Regular expressions to categorize file types.
57
60
# FIXME: Please check if the following is correct
58
61
 
59
 
my $xml_extension =
60
 
"xml(\.in)*|".          # .in is not required
61
 
"ui|".
62
 
"glade2?(\.in)*|".      # .in is not required
63
 
"scm(\.in)*|".          # .in is not required
64
 
"oaf(\.in)+|".
65
 
"etspec|".
66
 
"sheet(\.in)+|".
67
 
"pong(\.in)+";
68
 
 
69
 
my $ini_extension =
70
 
"desktop(\.in)+|".
71
 
"caves(\.in)+|". 
72
 
"directory(\.in)+|".
73
 
"soundlist(\.in)+|".
74
 
"keys(\.in)+|".
75
 
"server(\.in)+";
76
 
 
77
 
## Always print as the first thing
 
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
 
 
76
my $ini_support =
 
77
"desktop(?:\\.in)+|".   # http://www.freedesktop.org/Standards/menu-spec
 
78
"caves(?:\\.in)+|".     # GNOME Games specific
 
79
"directory(?:\\.in)+|". # http://www.freedesktop.org/Standards/menu-spec
 
80
"soundlist(?:\\.in)+|". # GNOME specific
 
81
"keys(?:\\.in)+|".      # GNOME Mime database specific
 
82
"theme(?:\\.in)+";      # http://www.freedesktop.org/Standards/icon-theme-spec
 
83
 
 
84
my $buildin_gettext_support = 
 
85
"c|y|cs|cc|cpp|c\\+\\+|h|hh|gob|py";
 
86
 
 
87
## Always flush buffer when printing
78
88
$| = 1;
79
89
 
 
90
## Sometimes the source tree will be rooted somewhere else.
 
91
my $SRCDIR = ".";
 
92
my $POTFILES_in;
 
93
 
 
94
$SRCDIR = $ENV{"srcdir"} if $ENV{"srcdir"};
 
95
$POTFILES_in = "<$SRCDIR/POTFILES.in";
 
96
 
80
97
## Handle options
81
98
GetOptions 
82
99
(
89
106
 "report|r"            => \$REPORT_ARG,
90
107
 "verbose|x"           => \$VERBOSE,
91
108
 "gettext-package|g=s" => \$GETTEXT_PACKAGE,
92
 
 ) or &print_error_invalid_option;
 
109
 "output-file|o=s"     => \$OUTPUT_FILE,
 
110
 ) or &Console_WriteError_InvalidOption;
93
111
 
94
 
&print_help if $HELP_ARG;
95
 
&print_version if $VERSION_ARG;
 
112
&Console_Write_IntltoolHelp if $HELP_ARG;
 
113
&Console_Write_IntltoolVersion if $VERSION_ARG;
96
114
 
97
115
my $arg_count = ($DIST_ARG > 0)
98
116
    + ($POT_ARG > 0)
99
117
    + ($HEADERS_ARG > 0)
100
118
    + ($MAINTAIN_ARG > 0)
101
119
    + ($REPORT_ARG > 0);
102
 
&print_help if $arg_count > 1;
 
120
 
 
121
&Console_Write_IntltoolHelp if $arg_count > 1;
103
122
 
104
123
# --version and --help don't require a module name
105
 
my $MODULE = $GETTEXT_PACKAGE || &find_package_name;
106
 
 
107
 
if ($DIST_ARG) {
108
 
    if ($ARGV[0] =~ /^[a-z]/){
109
 
        &update_po_file ($ARGV[0]);
110
 
        &print_status ($ARGV[0]);
111
 
    } else {
112
 
        &print_help;
113
 
    }
114
 
} elsif ($POT_ARG) {
115
 
    &generate_headers;
116
 
    &generate_po_template;
117
 
} elsif ($HEADERS_ARG) {
118
 
    &generate_headers;
119
 
} elsif ($MAINTAIN_ARG) {
120
 
    &find_leftout_files;
121
 
} elsif ($REPORT_ARG) {
122
 
    &print_report;
123
 
} else {
124
 
    if ($ARGV[0] =~ /^[a-z]/) {
125
 
        &main ($ARGV[0]);
126
 
    } else {
127
 
        &print_help;
128
 
    }
 
124
my $MODULE = $GETTEXT_PACKAGE || &FindPackageName;
 
125
 
 
126
if ($POT_ARG)
 
127
{
 
128
    &GenerateHeaders;
 
129
    &GeneratePOTemplate;
 
130
}
 
131
elsif ($HEADERS_ARG)
 
132
{
 
133
    &GenerateHeaders;
 
134
}
 
135
elsif ($MAINTAIN_ARG)
 
136
{
 
137
    &FindLeftoutFiles;
 
138
}
 
139
elsif ($REPORT_ARG)
 
140
{
 
141
    &GenerateHeaders;
 
142
    &GeneratePOTemplate;
 
143
    &Console_Write_CoverageReport;
 
144
}
 
145
elsif ((defined $ARGV[0]) && $ARGV[0] =~ /^[a-z]/)
 
146
{
 
147
    my $lang = $ARGV[0];
 
148
 
 
149
    ## Report error if the language file supplied
 
150
    ## to the command line is non-existent
 
151
    &Console_WriteError_NotExisting("$lang.po") if ! -s "$lang.po";
 
152
 
 
153
    if (!$DIST_ARG)
 
154
    {
 
155
        print "Working, please wait..." if $VERBOSE;
 
156
        &GenerateHeaders;
 
157
        &GeneratePOTemplate;
 
158
    }
 
159
    &POFile_Update ($lang, $OUTPUT_FILE);
 
160
    &Console_Write_TranslationStatus ($lang, $OUTPUT_FILE);
 
161
 
162
else 
 
163
{
 
164
    &Console_Write_IntltoolHelp;
129
165
}
130
166
 
131
167
exit;
132
168
 
133
169
#########
134
170
 
135
 
sub print_version
136
 
{
137
 
    ## Print version information
138
 
    print "${PROGRAM} (${PACKAGE}) $VERSION\n";
139
 
    print "Written by Kenneth Christiansen, Maciej Stachowiak, and Darin Adler.\n\n";
140
 
    print "Copyright (C) 2000-2002 Free Software Foundation, Inc.\n";
141
 
    print "This is free software; see the source for copying conditions.  There is NO\n";
142
 
    print "warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n";
143
 
    exit;
144
 
}
145
 
 
146
 
sub print_help
147
 
{
148
 
    ## Print usage information
149
 
    print "Usage: ${PROGRAM} [OPTIONS] ...LANGCODE\n";
150
 
    print "Updates PO template files and merge them with the translations.\n\n";
151
 
    print "  -p, --pot              generate the PO template only\n";
152
 
    print "  -s, --headers          generate the header files in POTFILES.in\n";
153
 
    print "  -m, --maintain         search for left out files from POTFILES.in\n";
154
 
    print "  -r, --report           display a status report for the module.\n";
155
 
    print "  -x, --verbose          display lots of feedback\n";
156
 
    print "      --help             display this help and exit\n";
157
 
    print "      --version          output version information and exit\n";
158
 
    print "\nExamples of use:\n";
159
 
    print "${PROGRAM} --pot    just creates a new PO template from the source\n";
160
 
    print "${PROGRAM} da       created new PO template and updated the da.po file\n\n";
161
 
    print "Report bugs to bugzilla.gnome.org, module 'intltool'.\n";
162
 
    exit;
163
 
}
164
 
 
165
 
sub main
166
 
{
167
 
    my ($lang) = @_;
168
 
 
169
 
    ## Report error if the language file supplied
170
 
    ## to the command line is non-existent
171
 
    &print_error_not_existing("$lang.po") if ! -s "$lang.po";
172
 
 
173
 
    print "Working, please wait..." unless $VERBOSE;
174
 
    &generate_headers;
175
 
    &generate_po_template;
176
 
    &update_po_file ($lang);
177
 
    &print_status ($lang);
178
 
}
179
 
 
180
 
sub determine_type ($) 
 
171
sub Console_Write_IntltoolVersion
 
172
{
 
173
    print <<_EOF_;
 
174
${PROGRAM} (${PACKAGE}) $VERSION
 
175
Written by Kenneth Christiansen, Maciej Stachowiak, and Darin Adler.
 
176
 
 
177
Copyright (C) 2000-2003 Free Software Foundation, Inc.
 
178
This is free software; see the source for copying conditions.  There is NO
 
179
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 
180
_EOF_
 
181
    exit;
 
182
}
 
183
 
 
184
sub Console_Write_IntltoolHelp
 
185
{
 
186
    print <<_EOF_;
 
187
Usage: ${PROGRAM} [OPTION]... LANGCODE
 
188
Updates PO template files and merge them with the translations.
 
189
 
 
190
Mode of operation (only one is allowed):
 
191
  -p, --pot                   generate the PO template only
 
192
  -s, --headers               generate the header files in POTFILES.in
 
193
  -m, --maintain              search for left out files from POTFILES.in
 
194
  -r, --report                display a status report for the module
 
195
  -d, --dist                  merge LANGCODE.po with existing PO template
 
196
 
 
197
Extra options:
 
198
  -g, --gettext-package=NAME  override PO template name, useful with --pot
 
199
  -o, --output-file=FILE      write merged translation to FILE
 
200
  -x, --verbose               display lots of feedback
 
201
      --help                  display this help and exit
 
202
      --version               output version information and exit
 
203
 
 
204
Examples of use:
 
205
${PROGRAM} --pot    just create a new PO template
 
206
${PROGRAM} xy       create new PO template and merge xy.po with it
 
207
 
 
208
Report bugs to http://bugzilla.gnome.org/ (product name "$PACKAGE")
 
209
or send email to <xml-i18n-tools\@gnome.org>.
 
210
_EOF_
 
211
    exit;
 
212
}
 
213
 
 
214
sub POFile_DetermineType ($) 
181
215
{
182
216
   my $type = $_;
183
217
   my $gettext_type;
184
218
 
185
 
   # FIXME: Use $xml_extentions, and maybe do all this even nicer
186
 
   my $xml_regex = 
187
 
       "(?:xml(\.in)*|ui|oaf(?:\.in)+|server(?:\.in)+|sheet(?:\.in)+|".
188
 
       "pong(?:\.in)+|etspec)";
189
 
   my $ini_regex =
190
 
       "(?:desktop(?:\.in)+|caves(?:\.in)+|directory(?:\.in)+|".
191
 
       "soundlist(?:\.in)+)";
192
 
 
193
 
   if ($type =~ /\[type: gettext\/([^\]].*)]/) {
194
 
        $gettext_type=$1;
195
 
   }
196
 
   elsif ($type =~ /$xml_regex$/) {
197
 
        $gettext_type="xml";
198
 
   }
199
 
   elsif ($type =~ /glade2?(\.in)*$/) {
200
 
        $gettext_type="glade";
201
 
   }
202
 
   elsif ($type =~ /$ini_regex$/) { 
203
 
        $gettext_type="ini";
204
 
   }
205
 
   elsif ($type =~ /scm(\.in)*$/) {
206
 
        $gettext_type="scheme";
207
 
   }
208
 
   elsif ($type =~ /keys(\.in)+$/) {
209
 
        $gettext_type="keys";
210
 
   }
211
 
   else { $gettext_type=""; }
 
219
   my $xml_regex     = "(?:" . $xml_support . ")";
 
220
   my $ini_regex     = "(?:" . $ini_support . ")";
 
221
   my $buildin_regex = "(?:" . $buildin_gettext_support . ")";
 
222
 
 
223
   if ($type =~ /\[type: gettext\/([^\]].*)]/) 
 
224
   {
 
225
        $gettext_type=$1;
 
226
   }
 
227
   elsif ($type =~ /schemas(\.in)+$/) 
 
228
   {
 
229
        $gettext_type="schemas";
 
230
   }
 
231
   elsif ($type =~ /glade2?(\.in)*$/) 
 
232
   {
 
233
       $gettext_type="glade";
 
234
   }
 
235
   elsif ($type =~ /scm(\.in)*$/) 
 
236
   {
 
237
       $gettext_type="scheme";
 
238
   }
 
239
   elsif ($type =~ /keys(\.in)+$/) 
 
240
   {
 
241
       $gettext_type="keys";
 
242
   }
 
243
 
 
244
   # bucket types
 
245
 
 
246
   elsif ($type =~ /$xml_regex$/) 
 
247
   {
 
248
       $gettext_type="xml";
 
249
   }
 
250
   elsif ($type =~ /$ini_regex$/) 
 
251
   { 
 
252
       $gettext_type="ini";
 
253
   }
 
254
   elsif ($type =~ /$buildin_regex$/) 
 
255
   {
 
256
       $gettext_type="buildin";
 
257
   }
 
258
   else
 
259
   { 
 
260
       $gettext_type="unknown"; 
 
261
   }
212
262
 
213
263
   return "gettext\/$gettext_type";
214
264
}
215
265
 
216
 
sub find_leftout_files
 
266
sub TextFile_DetermineEncoding ($) 
 
267
{
 
268
    my $gettext_code="ASCII"; # All files are ASCII by default
 
269
    my $filetype=`file $_ | cut -d ' ' -f 2`;
 
270
 
 
271
    if ($? eq "0")
 
272
    {
 
273
        if ($filetype =~ /^(ISO|UTF)/)
 
274
        {
 
275
            chomp ($gettext_code = $filetype);
 
276
        }
 
277
        elsif ($filetype =~ /^XML/)
 
278
        {
 
279
            $gettext_code="UTF-8"; # We asume that .glade and other .xml files are UTF-8
 
280
        }
 
281
    }
 
282
 
 
283
    return $gettext_code;
 
284
}
 
285
 
 
286
 
 
287
sub FindLeftoutFiles
217
288
{
218
289
    my (@buf_i18n_plain,
219
290
        @buf_i18n_xml,
 
291
        @buf_i18n_xml_unmarked,
220
292
        @buf_i18n_ini,
221
293
        @buf_potfiles,
222
294
        @buf_potfiles_ignore,
227
299
 
228
300
    ## Search and find all translatable files
229
301
    find sub { 
230
 
        push @buf_i18n_plain, "$File::Find::name" if /\.(c|y|cc|cpp|c\+\+|h|gob)$/ 
231
 
        }, "..";
232
 
    find sub { 
233
 
        push @buf_i18n_xml, "$File::Find::name" if /\.($xml_extension)$/ 
234
 
        }, "..";
235
 
    find sub {
236
 
        push @buf_i18n_ini, "$File::Find::name" if /\.($ini_extension)$/ 
237
 
        }, "..";
238
 
 
239
 
    open POTFILES, "POTFILES.in" || die "$PROGRAM:  there's no POTFILES.in!\n";
240
 
 
241
 
    @buf_potfiles = grep /^[^#]/, <POTFILES>;
242
 
                            
 
302
        push @buf_i18n_plain,        "$File::Find::name" if /\.($buildin_gettext_support)$/;
 
303
        push @buf_i18n_xml,          "$File::Find::name" if /\.($xml_support)$/;
 
304
        push @buf_i18n_ini,          "$File::Find::name" if /\.($ini_support)$/;
 
305
        push @buf_i18n_xml_unmarked, "$File::Find::name" if /\.(schemas(\.in)+)$/;
 
306
        }, "..";
 
307
 
 
308
 
 
309
    open POTFILES, $POTFILES_in or die "$PROGRAM:  there's no POTFILES.in!\n";
 
310
    @buf_potfiles = grep !/^(#|\s*$)/, <POTFILES>;
 
311
    close POTFILES;
 
312
 
 
313
    foreach (@buf_potfiles) {
 
314
        s/^\[.*]\s*//;
 
315
    }
 
316
 
243
317
    print "Searching for missing translatable files...\n" if $VERBOSE;
244
318
 
245
319
    ## Check if we should ignore some found files, when
246
320
    ## comparing with POTFILES.in
247
 
    foreach my $ignore ("POTFILES.skip", "POTFILES.ignore") {
248
 
        if (-s $ignore) {
249
 
            open FILE, $ignore;
250
 
            while (<FILE>) {
251
 
                if (/^[^#]/){
252
 
                    push @buf_potfiles_ignore, $_;
253
 
                }
254
 
            }
255
 
            print "Found $ignore: Ignoring files...\n" if $VERBOSE;
256
 
            @buf_potfiles = (@buf_potfiles_ignore, @buf_potfiles);
257
 
        }
 
321
    foreach my $ignore ("POTFILES.skip", "POTFILES.ignore")
 
322
    {
 
323
        (-s $ignore) or next;
 
324
 
 
325
        if ("$ignore" eq "POTFILES.ignore")
 
326
        {
 
327
            print "The usage of POTFILES.ignore is deprecated. Please consider moving the\n".
 
328
                  "content of this file to POTFILES.skip.\n";
 
329
        }
 
330
 
 
331
        print "Found $ignore: Ignoring files...\n" if $VERBOSE;
 
332
        open FILE, "<$ignore" or die "ERROR: Failed to open $ignore!\n";
 
333
            
 
334
        while (<FILE>)
 
335
        {
 
336
            push @buf_potfiles_ignore, $_ unless /^(#|\s*$)/;
 
337
        }
 
338
        close FILE;
 
339
 
 
340
        @buf_potfiles = (@buf_potfiles_ignore, @buf_potfiles);
258
341
    }
259
342
 
260
343
    foreach my $file (@buf_i18n_plain)
261
 
      {
262
 
        my $in_comment = 0;
 
344
    {
 
345
        my $in_comment = 0;
263
346
        my $in_macro = 0;
264
347
 
265
 
        open FILE, "<$file";
266
 
        while (<FILE>)
267
 
          {
 
348
        open FILE, "<$file";
 
349
        while (<FILE>)
 
350
        {
268
351
            # Handle continued multi-line comment.
269
352
            if ($in_comment)
270
 
              {
 
353
            {
271
354
                next unless s-.*\*/--;
272
355
                $in_comment = 0;
273
 
              }
 
356
            }
274
357
 
275
358
            # Handle continued macro.
276
359
            if ($in_macro)
277
 
              {
 
360
            {
278
361
                $in_macro = 0 unless /\\$/;
279
362
                next;
280
 
              }
 
363
            }
281
364
 
282
365
            # Handle start of macro (or any preprocessor directive).
283
366
            if (/^\s*\#/)
284
 
              {
 
367
            {
285
368
                $in_macro = 1 if /^([^\\]|\\.)*\\$/;
286
369
                next;
287
 
              }
 
370
            }
288
371
 
289
372
            # Handle comments and quoted text.
290
373
            while (m-(/\*|//|\'|\")-) # \' and \" keep emacs perl mode happy
291
 
              {
 
374
            {
292
375
                my $match = $1;
293
376
                if ($match eq "/*")
294
 
                  {
 
377
                {
295
378
                    if (!s-/\*.*?\*/--)
296
 
                      {
 
379
                    {
297
380
                        s-/\*.*--;
298
381
                        $in_comment = 1;
299
 
                      }
300
 
                  }
 
382
                    }
 
383
                }
301
384
                elsif ($match eq "//")
302
 
                  {
 
385
                {
303
386
                    s-//.*--;
304
 
                  }
 
387
                }
305
388
                else # ' or "
306
 
                  {
 
389
                {
307
390
                    if (!s-$match([^\\]|\\.)*?$match-QUOTEDTEXT-)
308
 
                      {
 
391
                    {
309
392
                        warn "mismatched quotes at line $. in $file\n";
310
393
                        s-$match.*--;
311
 
                      }
312
 
                  }
313
 
              }
314
 
        
 
394
                    }
 
395
                }
 
396
            }       
 
397
 
 
398
            if (/\.GetString ?\(QUOTEDTEXT/)
 
399
            {
 
400
                ## Remove the first 3 chars and add newline
 
401
                push @buf_allfiles, unpack("x3 A*", $file) . "\n";
 
402
                last;
 
403
            }
315
404
 
316
405
            if (/_\(QUOTEDTEXT/)
317
 
              {
 
406
            {
318
407
                ## Remove the first 3 chars and add newline
319
408
                push @buf_allfiles, unpack("x3 A*", $file) . "\n";
320
409
                last;
321
 
              }
322
 
          }
323
 
        close FILE;
324
 
      }
325
 
 
326
 
    foreach my $file (@buf_i18n_xml) {
327
 
        open FILE, "<$file";
328
 
        while (<FILE>) {
329
 
            if (/\s_(.*)=\"/){
330
 
                push @buf_allfiles, unpack("x3 A*", $file) . "\n";
331
 
                last;
332
 
            }
333
 
        }
334
 
    }
335
 
 
336
 
    foreach my $file (@buf_i18n_ini){
337
 
        open FILE, "<$file";
338
 
        while (<FILE>) {
339
 
            if (/_(.*)=/){
340
 
                push @buf_allfiles, unpack("x3 A*", $file) . "\n";
341
 
                last;
342
 
            }
343
 
        }
344
 
    }
 
410
            }
 
411
        }
 
412
        close FILE;
 
413
    }
 
414
 
 
415
    foreach my $file (@buf_i18n_xml) 
 
416
    {
 
417
        open FILE, "<$file";
 
418
        
 
419
        while (<FILE>) 
 
420
        {
 
421
            # FIXME: share the pattern matching code with intltool-extract
 
422
            if (/\s_(.*)=\"/ || /<_[^>]+>/ || /translatable=\"yes\"/)
 
423
            {
 
424
                push @buf_allfiles, unpack("x3 A*", $file) . "\n";
 
425
                last;
 
426
            }
 
427
        }
 
428
        close FILE;
 
429
    }
 
430
 
 
431
    foreach my $file (@buf_i18n_ini)
 
432
    {
 
433
        open FILE, "<$file";
 
434
        while (<FILE>) 
 
435
        {
 
436
            if (/_(.*)=/)
 
437
            {
 
438
                push @buf_allfiles, unpack("x3 A*", $file) . "\n";
 
439
                last;
 
440
            }
 
441
        }
 
442
        close FILE;
 
443
    }
 
444
 
 
445
    foreach my $file (@buf_i18n_xml_unmarked)
 
446
    {
 
447
        push @buf_allfiles, unpack("x3 A*", $file) . "\n";
 
448
    }
 
449
 
345
450
 
346
451
    @buf_allfiles_sorted = sort (@buf_allfiles);
347
452
    @buf_potfiles_sorted = sort (@buf_potfiles);
348
453
 
349
454
    my %in2;
350
 
    foreach (@buf_potfiles_sorted) {
351
 
        $in2{$_} = 1;
 
455
    foreach (@buf_potfiles_sorted) 
 
456
    {
 
457
        $in2{$_} = 1;
352
458
    }
353
459
 
354
460
    my @result;
355
461
 
356
 
    foreach (@buf_allfiles_sorted){
357
 
        if (!exists($in2{$_})){
358
 
            push @result, $_
359
 
        }
 
462
    foreach (@buf_allfiles_sorted)
 
463
    {
 
464
        if (!exists($in2{$_}))
 
465
        {
 
466
            push @result, $_
 
467
        }
 
468
    }
 
469
 
 
470
    my @buf_potfiles_notexist;
 
471
 
 
472
    foreach (@buf_potfiles_sorted)
 
473
    {
 
474
        chomp (my $dummy = $_);
 
475
        if ("$dummy" ne "" and ! -f "../$dummy")
 
476
        {
 
477
            push @buf_potfiles_notexist, $_;
 
478
        }
360
479
    }
361
480
 
362
481
    ## Save file with information about the files missing
363
482
    ## if any, and give information about this procedure.
364
 
    if (@result) {
365
 
        print "\n" if $VERBOSE;
366
 
        open OUT, ">missing";
367
 
        print OUT @result;
368
 
        print "The following files contain translations and are currently not in use. Please\n";
369
 
        print "consider adding these to the POTFILES.in file, located in the po/ directory.\n\n";
370
 
        print @result, "\n";
371
 
        print "If some of these files are left out on purpose then please add them to\n";
372
 
        print "POTFILES.skip instead of POTFILES.in. A file 'missing' containing this list\n";
373
 
        print "of left out files has been written in the current directory.\n";
 
483
    if (@result + @buf_potfiles_notexist > 0)
 
484
    {
 
485
        if (@result) 
 
486
        {
 
487
            print "\n" if $VERBOSE;
 
488
            unlink "missing";
 
489
            open OUT, ">missing";
 
490
            print OUT @result;
 
491
            close OUT;
 
492
            warn "\e[1mThe following files contain translations and are currently not in use. Please\e[0m\n".
 
493
                 "\e[1mconsider adding these to the POTFILES.in file, located in the po/ directory.\e[0m\n\n";
 
494
            print STDERR @result, "\n";
 
495
            warn "If some of these files are left out on purpose then please add them to\n".
 
496
                 "POTFILES.skip instead of POTFILES.in. A file \e[1m'missing'\e[0m containing this list\n".
 
497
                 "of left out files has been written in the current directory.\n";
 
498
        }
 
499
        if (@buf_potfiles_notexist)
 
500
        {
 
501
            unlink "notexist";
 
502
            open OUT, ">notexist";
 
503
            print OUT @buf_potfiles_notexist;
 
504
            close OUT;
 
505
            warn "\n" if ($VERBOSE or @result);
 
506
            warn "\e[1mThe following files do not exist anymore:\e[0m\n\n";
 
507
            warn @buf_potfiles_notexist, "\n";
 
508
            warn "Please remove them from POTFILES.in or POTFILES.skip. A file \e[1m'notexist'\e[0m\n".
 
509
                 "containing this list of absent files has been written in the current directory.\n";
 
510
        }
374
511
    }
375
512
 
376
513
    ## If there is nothing to complain about, notify the user
377
514
    else {
378
 
        print "\nAll files containing translations are present in POTFILES.in.\n";
 
515
        print "\nAll files containing translations are present in POTFILES.in.\n" if $VERBOSE;
379
516
    }
380
517
}
381
518
 
382
 
sub print_error_invalid_option
 
519
sub Console_WriteError_InvalidOption
383
520
{
384
521
    ## Handle invalid arguments
385
 
    print "Try `${PROGRAM} --help' for more information.\n";
 
522
    print STDERR "Try `${PROGRAM} --help' for more information.\n";
386
523
    exit 1;
387
524
}
388
525
 
389
 
sub generate_headers
 
526
sub GenerateHeaders
390
527
{
391
528
    my $EXTRACT = `which intltool-extract 2>/dev/null`;
392
529
    chomp $EXTRACT;
395
532
 
396
533
    ## Generate the .h header files, so we can allow glade and
397
534
    ## xml translation support
398
 
    if (! -s $EXTRACT)
 
535
    if (! -x "$EXTRACT")
399
536
    {
400
 
        print "\n *** The intltool-extract script wasn't found!"
 
537
        print STDERR "\n *** The intltool-extract script wasn't found!"
401
538
             ."\n *** Without it, intltool-update can not generate files.\n";
402
539
        exit;
403
540
    }
404
541
    else
405
542
    {
406
 
        open FILE, "<POTFILES.in";
407
 
        while (<FILE>) {
408
 
           chomp;
409
 
 
410
 
           ## Find xml files in POTFILES.in and generate the
411
 
           ## files with help from the extract script
412
 
 
413
 
           my $gettext_type= &determine_type ($1);
414
 
 
415
 
           if (/\.($xml_extension|$ini_extension)$/ || /^\[/){
416
 
               $_ =~ s/^\[[^\[].*]\s*//;
417
 
               my $filename = "../$_";
418
 
 
419
 
               if ($VERBOSE){
420
 
                   system($EXTRACT, "--update", "--type=$gettext_type", $filename);
421
 
               } else {
422
 
                   system($EXTRACT, "--update", "--type=$gettext_type", "--quiet", $filename);
423
 
               }
424
 
           }
 
543
        open (FILE, $POTFILES_in) or die "$PROGRAM: POTFILES.in not found.\n";
 
544
        
 
545
        while (<FILE>) 
 
546
        {
 
547
           chomp;
 
548
           next if /^\[\s*encoding/;
 
549
 
 
550
           ## Find xml files in POTFILES.in and generate the
 
551
           ## files with help from the extract script
 
552
 
 
553
           my $gettext_type= &POFile_DetermineType ($1);
 
554
 
 
555
           if (/\.($xml_support|$ini_support)$/ || /^\[/)
 
556
           {
 
557
               s/^\[[^\[].*]\s*//;
 
558
 
 
559
               my $filename = "../$_";
 
560
 
 
561
               if ($VERBOSE)
 
562
               {
 
563
                   system ($EXTRACT, "--update", "--srcdir=$SRCDIR",
 
564
                           "--type=$gettext_type", $filename);
 
565
               } 
 
566
               else 
 
567
               {
 
568
                   system ($EXTRACT, "--update", "--type=$gettext_type", 
 
569
                           "--srcdir=$SRCDIR", "--quiet", $filename);
 
570
               }
 
571
           }
425
572
       }
426
573
       close FILE;
427
574
   }
428
575
}
429
576
 
430
 
sub generate_po_template
 
577
#
 
578
# Generate .pot file from POTFILES.in
 
579
#
 
580
sub GeneratePOTemplate
431
581
{
432
 
    ## Generate the potfiles from the POTFILES.in file
433
 
 
434
 
    print "Building the $MODULE.pot...\n" if $VERBOSE;
435
 
 
436
 
    move ("POTFILES.in", "POTFILES.in.old");
437
 
 
438
 
    open INFILE, "<POTFILES.in.old";
439
 
    open OUTFILE, ">POTFILES.in";
440
 
    while (<INFILE>) {
441
 
        s/\.($xml_extension|$ini_extension)$/$&.h/;
442
 
        s/^\[.*]\s*(.*)/$1.h/;
443
 
        print OUTFILE $_;
444
 
    }
 
582
    my $XGETTEXT = `which xgettext 2>/dev/null`;
 
583
    my $XGETTEXT_ARGS = '';
 
584
    chomp $XGETTEXT;
 
585
 
 
586
    $XGETTEXT = $ENV{"XGETTEXT"} if $ENV{"XGETTEXT"};
 
587
    $XGETTEXT_ARGS = $ENV{"XGETTEXT_ARGS"} if $ENV{"XGETTEXT_ARGS"};
 
588
 
 
589
    if (! -x $XGETTEXT)
 
590
    {
 
591
        print STDERR " *** xgettext is not found on this system!\n".
 
592
                     " *** Without it, intltool-update can not extract strings.\n";
 
593
        exit;
 
594
    }
 
595
 
 
596
    print "Building $MODULE.pot...\n" if $VERBOSE;
 
597
 
 
598
    open INFILE, $POTFILES_in;
 
599
    unlink "POTFILES.in.temp";
 
600
    open OUTFILE, ">POTFILES.in.temp";
 
601
 
 
602
    my $gettext_support_nonascii = 0;
 
603
 
 
604
    # checks for GNU gettext >= 0.12
 
605
    my $dummy = `$XGETTEXT --version --from-code=UTF-8 >/dev/null 2>/dev/null`;
 
606
    if ($? == 0)
 
607
    {
 
608
        $gettext_support_nonascii = 1;
 
609
    }
 
610
    else
 
611
    {
 
612
        # urge everybody to upgrade gettext
 
613
        print STDERR "WARNING: This version of gettext does not support extracting non-ASCII\n".
 
614
                     "         strings. That means you should install a version of gettext\n".
 
615
                     "         that supports non-ASCII strings (such as GNU gettext >= 0.12),\n".
 
616
                     "         or have to let non-ASCII strings untranslated. (If there is any)\n";
 
617
    }
 
618
 
 
619
    my $encoding = "ASCII";
 
620
    my $forced_gettext_code;
 
621
    my @temp_headers;
 
622
    my $encoding_problem_is_reported = 0;
 
623
 
 
624
    while (<INFILE>) 
 
625
    {
 
626
        next if (/^#/ or /^\s*$/);
 
627
 
 
628
        chomp;
 
629
 
 
630
        my $gettext_code;
 
631
 
 
632
        if (/^\[\s*encoding:\s*(.*)\s*\]/)
 
633
        {
 
634
            $forced_gettext_code=$1;
 
635
        }
 
636
        elsif (/\.($xml_support|$ini_support)$/ || /^\[/)
 
637
        {
 
638
            s/^\[.*]\s*//;
 
639
            print OUTFILE "$_.h\n";
 
640
            push @temp_headers, "../$_.h";
 
641
            $gettext_code = &TextFile_DetermineEncoding ("../$_.h") if ($gettext_support_nonascii and not defined $forced_gettext_code);
 
642
        } 
 
643
        else 
 
644
        {
 
645
            if ($SRCDIR eq ".") {
 
646
                print OUTFILE "$_\n";
 
647
            } else {
 
648
                print OUTFILE "$SRCDIR/../$_\n";
 
649
            }
 
650
            $gettext_code = &TextFile_DetermineEncoding ("../$_") if ($gettext_support_nonascii and not defined $forced_gettext_code);
 
651
        }
 
652
 
 
653
        next if (! $gettext_support_nonascii);
 
654
 
 
655
        if (defined $forced_gettext_code)
 
656
        {
 
657
            $encoding=$forced_gettext_code;
 
658
        }
 
659
        elsif (defined $gettext_code and "$encoding" ne "$gettext_code")
 
660
        {
 
661
            if ($encoding eq "ASCII")
 
662
            {
 
663
                $encoding=$gettext_code;
 
664
            }
 
665
            elsif ($gettext_code ne "ASCII")
 
666
            {
 
667
                # Only report once because the message is quite long
 
668
                if (! $encoding_problem_is_reported)
 
669
                {
 
670
                    print STDERR "WARNING: You should use the same file encoding for all your project files,\n".
 
671
                                 "         but $PROGRAM thinks that most of the source files are in\n".
 
672
                                 "         $encoding encoding, while \"$_\" is (likely) in\n".
 
673
                                 "         $gettext_code encoding. If you are sure that all translatable strings\n".
 
674
                                 "         are in same encoding (say UTF-8), please \e[1m*prepend*\e[0m the following\n".
 
675
                                 "         line to POTFILES.in:\n\n".
 
676
                                 "                 [encoding: UTF-8]\n\n".
 
677
                                 "         and make sure that configure.in/ac checks for $PACKAGE >= 0.27 .\n".
 
678
                                 "(such warning message will only be reported once.)\n";
 
679
                    $encoding_problem_is_reported = 1;
 
680
                }
 
681
            }
 
682
        }
 
683
    }
 
684
 
445
685
    close OUTFILE;
446
686
    close INFILE;
447
687
 
448
 
    system ("xgettext", "--default-domain\=$MODULE", 
449
 
                        "--directory\=\.\.",
450
 
                        "--add-comments", 
451
 
                        "--keyword\=\_", 
452
 
                        "--keyword\=N\_", 
453
 
                        "--keyword\=U\_",
454
 
                        "--files-from\=\.\/POTFILES\.in");
455
 
 
456
 
    -e "$MODULE.po" || die "$PROGRAM: $MODULE.po does not exist.\n";
457
 
    system ("rm", "-f", "$MODULE.pot");
458
 
    move ("$MODULE.po", "$MODULE.pot") || die "$PROGRAM: couldn't move $MODULE.po to $MODULE.pot.\n";
459
 
 
460
 
    print "Wrote $MODULE.pot\n" if $VERBOSE;
461
 
 
462
 
    move ("POTFILES.in.old", "POTFILES.in");
 
688
    unlink "$MODULE.pot";
 
689
    my @xgettext_argument=("$XGETTEXT",
 
690
                           "--add-comments",
 
691
                           "--directory\=\.\.",
 
692
                           "--output\=$MODULE\.pot",
 
693
                           "--files-from\=\.\/POTFILES\.in\.temp");
 
694
    my $XGETTEXT_KEYWORDS = &FindPOTKeywords;
 
695
    push @xgettext_argument, $XGETTEXT_KEYWORDS;
 
696
    push @xgettext_argument, "--from-code\=$encoding" if ($gettext_support_nonascii);
 
697
    push @xgettext_argument, $XGETTEXT_ARGS if $XGETTEXT_ARGS;
 
698
    my $xgettext_command = join ' ', @xgettext_argument;
 
699
 
 
700
    # intercept xgettext error message
 
701
    print "Running $xgettext_command\n" if $VERBOSE;
 
702
    my $xgettext_error_msg = `$xgettext_command 2>\&1`;
 
703
    my $command_failed = $?;
 
704
 
 
705
    unlink "POTFILES.in.temp";
463
706
 
464
707
    print "Removing generated header (.h) files..." if $VERBOSE;
465
 
 
466
 
    open FILE, "<POTFILES.in";
467
 
 
468
 
    while (<FILE>)
469
 
    {
470
 
        chomp;
471
 
        unlink "../$_.h" if /\.($xml_extension|$ini_extension)$/;
472
 
    }
473
 
 
474
 
    close FILE;
475
 
    print "done\n" if $VERBOSE;
 
708
    unlink foreach (@temp_headers);
 
709
    print "done.\n" if $VERBOSE;
 
710
 
 
711
    if (! $command_failed)
 
712
    {
 
713
        if (! -e "$MODULE.pot")
 
714
        {
 
715
            print "None of the files in POTFILES.in contain strings marked for translation.\n" if $VERBOSE;
 
716
        }
 
717
        else
 
718
        {
 
719
            print "Wrote $MODULE.pot\n" if $VERBOSE;
 
720
        }
 
721
    }
 
722
    else
 
723
    {
 
724
        if ($xgettext_error_msg =~ /--from-code/)
 
725
        {
 
726
            # replace non-ASCII error message with a more useful one.
 
727
            print STDERR "ERROR: xgettext failed to generate PO template file because there is non-ASCII\n".
 
728
                         "       string marked for translation. Please make sure that all strings marked\n".
 
729
                         "       for translation are in uniform encoding (say UTF-8), then \e[1m*prepend*\e[0m the\n".
 
730
                         "       following line to POTFILES.in and rerun $PROGRAM:\n\n".
 
731
                         "           [encoding: UTF-8]\n\n";
 
732
        }
 
733
        else
 
734
        {
 
735
            print STDERR "$xgettext_error_msg";
 
736
            if (-e "$MODULE.pot")
 
737
            {
 
738
                # is this possible?
 
739
                print STDERR "ERROR: xgettext failed but still managed to generate PO template file.\n".
 
740
                             "       Please consult error message above if there is any.\n";
 
741
            }
 
742
            else
 
743
            {
 
744
                print STDERR "ERROR: xgettext failed to generate PO template file. Please consult\n".
 
745
                             "       error message above if there is any.\n";
 
746
            }
 
747
        }
 
748
        exit (1);
 
749
    }
476
750
}
477
751
 
478
 
sub update_po_file
 
752
sub POFile_Update
479
753
{
480
 
    my ($lang) = @_;
 
754
    -f "$MODULE.pot" or die "$PROGRAM: $MODULE.pot does not exist.\n";
 
755
 
 
756
    my ($lang, $outfile) = @_;
481
757
 
482
758
    print "Merging $lang.po with $MODULE.pot..." if $VERBOSE;
483
759
 
484
 
    copy ("$lang.po", "$lang.po.old") || die "copy failed: $!";
 
760
    my $infile = "$lang.po";
 
761
    $outfile = "$lang.po" if ($outfile eq "");
485
762
 
486
 
    # Perform merge, remove backup file and the "messages" trash file 
487
 
    # generated by gettext
488
 
    system ("msgmerge", "$lang.po.old", "$MODULE.pot", "-o", "$lang.po");
489
 
    unlink "$lang.po.old";
490
 
    unlink "messages";
 
763
    # I think msgmerge won't overwrite old file if merge is not successful
 
764
    system ("msgmerge", "-o", $outfile, $infile, "$MODULE.pot");
491
765
}
492
766
 
493
 
sub print_error_not_existing
 
767
sub Console_WriteError_NotExisting
494
768
{
495
769
    my ($file) = @_;
496
770
 
497
771
    ## Report error if supplied language file is non-existing
498
 
    print "$PROGRAM: $file does not exist!\n";
499
 
    print "Try '$PROGRAM --help' for more information.\n";
 
772
    print STDERR "$PROGRAM: $file does not exist!\n";
 
773
    print STDERR "Try '$PROGRAM --help' for more information.\n";
500
774
    exit;
501
775
}
502
776
 
503
 
sub gather_po_files
 
777
sub GatherPOFiles
504
778
{
505
779
    my @po_files = glob ("./*.po");
506
780
 
507
 
    @languages = map (&po_file2lang, @po_files);
 
781
    @languages = map (&POFile_GetLanguage, @po_files);
508
782
 
509
 
    foreach my $lang (@languages) {
 
783
    foreach my $lang (@languages) 
 
784
    {
510
785
        $po_files_by_lang{$lang} = shift (@po_files);
511
786
    }
512
787
}
513
788
 
514
 
sub po_file2lang ($)
515
 
{
516
 
    my $tmp = $_;
517
 
    $tmp =~ s/^.*\/(.*)\.po$/$1/;
518
 
    return $tmp;
519
 
}
520
 
 
521
 
sub print_status
522
 
{
523
 
    my ($lang) = @_;
524
 
 
525
 
    system ("msgfmt", "--statistics", "$lang.po");
526
 
    print "\n";
527
 
}
528
 
 
529
 
sub print_report
530
 
{
531
 
    &generate_headers;
532
 
    &generate_po_template;
533
 
    &gather_po_files;
534
 
 
535
 
    foreach my $lang (@languages) {
 
789
sub POFile_GetLanguage ($)
 
790
{
 
791
    s/^(.*\/)?(.+)\.po$/$2/;
 
792
    return $_;
 
793
}
 
794
 
 
795
sub Console_Write_TranslationStatus
 
796
{
 
797
    my ($lang, $output_file) = @_;
 
798
 
 
799
    $output_file = "$lang.po" if ($output_file eq "");
 
800
 
 
801
    system ("msgfmt", "-o", "/dev/null", "--statistics", $output_file);
 
802
}
 
803
 
 
804
sub Console_Write_CoverageReport
 
805
{
 
806
    &GatherPOFiles;
 
807
 
 
808
    foreach my $lang (@languages) 
 
809
    {
536
810
        print "$lang: ";
537
 
        &update_po_file ($lang);
 
811
        &POFile_Update ($lang, "");
538
812
    }
539
813
 
540
814
    print "\n\n * Current translation support in $MODULE \n\n";
541
815
 
542
 
    foreach my $lang (@languages){
543
 
        print "$lang: ";
544
 
        system ("msgfmt", "--statistics", "$lang.po");
545
 
    }
546
 
}
547
 
 
548
 
sub find_package_name
 
816
    foreach my $lang (@languages)
 
817
    {
 
818
        print "$lang: ";
 
819
        system ("msgfmt", "-o", "/dev/null", "--statistics", "$lang.po");
 
820
    }
 
821
}
 
822
 
 
823
sub SubstituteVariable
 
824
{
 
825
    my ($str) = @_;
 
826
    
 
827
    # always need to rewind file whenever it has been accessed
 
828
    seek (CONF, 0, 0);
 
829
 
 
830
    # cache each variable. varhash is global to we can add
 
831
    # variables elsewhere.
 
832
    while (<CONF>)
 
833
    {
 
834
        if (/^(\w+)=(.*)$/)
 
835
        {
 
836
            ($varhash{$1} = $2) =~  s/^["'](.*)["']$/$1)/;
 
837
        }
 
838
    }
 
839
    
 
840
    if ($str =~ /^(.*)\${?([A-Z_]+)}?(.*)$/)
 
841
    {
 
842
        my $rest = $3;
 
843
        my $untouched = $1;
 
844
        my $sub = $varhash{$2};
 
845
        
 
846
        return SubstituteVariable ("$untouched$sub$rest");
 
847
    }
 
848
    return $str;
 
849
}
 
850
 
 
851
sub CONF_Handle_Open
549
852
{
550
853
    my $base_dirname = getcwd();
551
854
    $base_dirname =~ s@.*/@@;
552
855
 
553
856
    my ($conf_in, $src_dir);
554
857
 
555
 
    if ($base_dirname =~ /^po(-.+)?$/) {
556
 
        if (-f "../configure.in") {
557
 
            $conf_in = "../configure.in";
558
 
        } else {
 
858
    if ($base_dirname =~ /^po(-.+)?$/) 
 
859
    {
 
860
        if (-f "Makevars") 
 
861
        {
559
862
            my $makefile_source;
 
863
 
560
864
            local (*IN);
561
 
            open IN, "<Makefile" || die "can't open Makefile: $!";
 
865
            open (IN, "<Makevars") || die "can't open Makevars: $!";
562
866
 
563
 
            while (<IN>) {
564
 
                if (/^top_srcdir[ \t]*=/) {
 
867
            while (<IN>) 
 
868
            {
 
869
                if (/^top_builddir[ \t]*=/) 
 
870
                {
565
871
                    $src_dir = $_;
566
 
                    # print "${src_dir}\n";
567
 
 
 
872
                    $src_dir =~ s/^top_builddir[ \t]*=[ \t]*([^ \t\n\r]*)/$1/;
 
873
 
 
874
                    chomp $src_dir;
 
875
                    if (-f "$src_dir" . "/configure.ac") {
 
876
                        $conf_in = "$src_dir" . "/configure.ac" . "\n";
 
877
                    } else {
 
878
                        $conf_in = "$src_dir" . "/configure.in" . "\n";
 
879
                    }
 
880
                    last;
 
881
                }
 
882
            }
 
883
            close IN;
 
884
 
 
885
            $conf_in || die "Cannot find top_builddir in Makevars.";
 
886
        }
 
887
        elsif (-f "../configure.ac") 
 
888
        {
 
889
            $conf_in = "../configure.ac";
 
890
        } 
 
891
        elsif (-f "../configure.in") 
 
892
        {
 
893
            $conf_in = "../configure.in";
 
894
        } 
 
895
        else 
 
896
        {
 
897
            my $makefile_source;
 
898
 
 
899
            local (*IN);
 
900
            open (IN, "<Makefile") || return;
 
901
 
 
902
            while (<IN>) 
 
903
            {
 
904
                if (/^top_srcdir[ \t]*=/) 
 
905
                {
 
906
                    $src_dir = $_;                  
568
907
                    $src_dir =~ s/^top_srcdir[ \t]*=[ \t]*([^ \t\n\r]*)/$1/;
569
 
                    # print "${src_dir}\n";
 
908
 
570
909
                    chomp $src_dir;
571
910
                    $conf_in = "$src_dir" . "/configure.in" . "\n";
 
911
 
572
912
                    last;
573
913
                }
574
914
            }
575
 
            $conf_in || die "Cannot find top_srcdir in Makefile."
576
 
        }
577
 
 
578
 
        my $conf_source; {
579
 
           local (*IN);
580
 
           local $/; # slurp mode
581
 
           open (IN, "<$conf_in") || die "can't open $conf_in: $!";
582
 
           $conf_source = <IN>;
583
 
        }
584
 
 
585
 
        my $name = "";
586
 
        $name = $1 if $conf_source =~ /^AM_INIT_AUTOMAKE\(([^,\)]+)/m;
587
 
        $name = $1 if $conf_source =~ /^GETTEXT_PACKAGE=(\S+)/m;
588
 
        if ($name =~ /^[\$](\S+)/) {
589
 
            return $1 if $conf_source =~ /^\s*$1=(\S*)/m;
590
 
        }
591
 
        return $name if $name;
592
 
    }
593
 
 
594
 
    print "$PROGRAM: Unable to determine package name.\n" .
595
 
          "Make sure to run this script inside the po directory.\n";
596
 
    exit;
 
915
            close IN;
 
916
 
 
917
            $conf_in || die "Cannot find top_srcdir in Makefile.";
 
918
        }
 
919
 
 
920
        open (CONF, "<$conf_in");
 
921
    }
 
922
    else
 
923
    {
 
924
        print STDERR "$PROGRAM: Unable to proceed.\n" .
 
925
                     "Make sure to run this script inside the po directory.\n";
 
926
        exit;
 
927
    }
 
928
}
 
929
 
 
930
sub FindPackageName
 
931
{
 
932
    my $version;
 
933
    my $domain = &FindMakevarsDomain;
 
934
    my $name = $domain || "untitled";
 
935
 
 
936
    &CONF_Handle_Open;
 
937
 
 
938
    my $conf_source; {
 
939
        local (*IN);
 
940
        open (IN, "<&CONF") || return $name;
 
941
        seek (IN, 0, 0);
 
942
        local $/; # slurp mode
 
943
        $conf_source = <IN>;
 
944
        close IN;
 
945
    }
 
946
 
 
947
    # priority for getting package name:
 
948
    # 1. GETTEXT_PACKAGE
 
949
    # 2. first argument of AC_INIT (with >= 2 arguments)
 
950
    # 3. first argument of AM_INIT_AUTOMAKE (with >= 2 argument)
 
951
 
 
952
    # /^AM_INIT_AUTOMAKE\([\s\[]*([^,\)\s\]]+)/m 
 
953
    # the \s makes this not work, why?
 
954
    if ($conf_source =~ /^AM_INIT_AUTOMAKE\(([^,\)]+),([^,\)]+)/m)
 
955
    {
 
956
        ($name, $version) = ($1, $2);
 
957
        ($varhash{"AC_PACKAGE_NAME"} = $name) =~ s/[\[\]\s]//g;
 
958
        ($varhash{"PACKAGE"} = $name) =~ s/[\[\]\s]//g;
 
959
        ($varhash{"AC_PACKAGE_VERSION"} = $version) =~ s/[\[\]\s]//g;
 
960
        ($varhash{"VERSION"} = $version) =~ s/[\[\]\s]//g;
 
961
   }
 
962
    
 
963
    if ($conf_source =~ /^AC_INIT\(([^,\)]+),([^,\)]+)/m) 
 
964
    {
 
965
        ($name, $version) = ($1, $2);
 
966
        ($varhash{"AC_PACKAGE_NAME"} = $name) =~ s/[\[\]\s]//g;
 
967
        ($varhash{"PACKAGE"} = $name) =~ s/[\[\]\s]//g;
 
968
        ($varhash{"AC_PACKAGE_VERSION"} = $version) =~ s/[\[\]\s]//g;
 
969
        ($varhash{"VERSION"} = $version) =~ s/[\[\]\s]//g;
 
970
    }
 
971
 
 
972
    # \s makes this not work, why?
 
973
    $name = $1 if $conf_source =~ /^GETTEXT_PACKAGE=\[?([^\n\]]+)/m;
 
974
    
 
975
    # prepend '$' to auto* internal variables, usually they are
 
976
    # used in configure.in/ac without the '$'
 
977
    $name =~ s/AC_/\$AC_/g;
 
978
    $name =~ s/\$\$/\$/g;
 
979
 
 
980
    $name = $domain if $domain;
 
981
 
 
982
    $name = SubstituteVariable ($name);
 
983
    $name =~ s/^["'](.*)["']$/$1/;
 
984
 
 
985
    return $name if $name;
 
986
}
 
987
 
 
988
 
 
989
sub FindPOTKeywords
 
990
{
 
991
 
 
992
    my $keywords = "--keyword\=\_ --keyword\=N\_ --keyword\=U\_";
 
993
    my $varname = "XGETTEXT_OPTIONS";
 
994
    my $make_source; {
 
995
        local (*IN);
 
996
        open (IN, "<Makevars") || (open(IN, "<Makefile.in.in") && ($varname = "XGETTEXT_KEYWORDS")) || return $keywords;
 
997
        seek (IN, 0, 0);
 
998
        local $/; # slurp mode
 
999
        $make_source = <IN>;
 
1000
        close IN;
 
1001
    }
 
1002
 
 
1003
    $keywords = $1 if $make_source =~ /^$varname[ ]*=\[?([^\n\]]+)/m;
 
1004
    
 
1005
    return $keywords;
 
1006
}
 
1007
 
 
1008
sub FindMakevarsDomain
 
1009
{
 
1010
 
 
1011
    my $domain = "";
 
1012
    my $makevars_source; { 
 
1013
        local (*IN);
 
1014
        open (IN, "<Makevars") || return $domain;
 
1015
        seek (IN, 0, 0);
 
1016
        local $/; # slurp mode
 
1017
        $makevars_source = <IN>;
 
1018
        close IN;
 
1019
    }
 
1020
 
 
1021
    $domain = $1 if $makevars_source =~ /^DOMAIN[ ]*=\[?([^\n\]]+)/m;
 
1022
    $domain =~ s/^\s+//;
 
1023
    $domain =~ s/\s+$//;
 
1024
    
 
1025
    return $domain;
597
1026
}