2 # -*- Mode: perl; indent-tabs-mode: nil; c-basic-offset: 4 -*-
4 # Intltool .desktop, .directory Prepare Tool
6 # Copyright (C) 2001 Free Software Foundation.
8 # Intltool is free software; you can redistribute it and/or
9 # modify it under the terms of the GNU General Public License as
10 # published by the Free Software Foundation; either version 2 of the
11 # License, or (at your option) any later version.
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.
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.
22 # Author(s): Gediminas Paulauskas <menesis@delfi.lt>
23 # Kenneth Christiansen <kenneth@gnu.org>
25 ## Release information
26 my $PROGRAM = "intltool-prepare";
27 my $PACKAGE = "@PACKAGE@";
28 my $VERSION = "@VERSION@";
35 ## Scalars used by the option stuff
37 my $VERSION_ARG = "0";
45 my $desktop_extension = "(desktop|soundlist|keys|directory)";
47 my $keywords = "Name|Comment|GenericName|SwallowTitle|description";
49 ## Always print as the first thing
54 "help|h" => \$HELP_ARG,
55 "version|v" => \$VERSION_ARG,
56 "verbose|x" => \$VERBOSE
60 ## Use the supplied arguments
62 ## This section will check for the different options.
64 sub split_on_argument {
81 print "Working, please wait...\n" if (! $VERBOSE);
93 ${PROGRAM} ${PACKAGE} $VERSION
94 Written by Gediminas Paulauskas <menesis\@delfi.lt>, 2000.
96 Copyright (C) 2000 Free Software Foundation, Inc.
97 This is free software; see the source for copying conditions. There is NO
98 warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
106 Usage: ${PROGRAM} [OPTION] KEYWORD...
107 Automates preparation steps before software make use of intltool.
108 KEYWORD is a list of additional key other than "Name", "Comment"
111 -h, --help shows this help page
112 -v, --version shows the version
113 -x, --verbose show lots of feedback
115 Report bugs to http://bugs.launchpad.net/intltool
122 ## Handle invalid arguments
123 ## my $opt = $ARGV[0];
124 ## print "$PROGRAM: invalid option -- $opt\n";
125 print STDERR "Try `$PROGRAM --help' for more information.\n";
132 foreach $arg (@ARGV) {
133 $keywords .= "|$arg";
139 open FILE, ">>po/POTFILES.in";
141 foreach my $desktop (@desktop_files) {
142 next if contains("po/POTFILES.in", "$desktop.in");
143 # Print explanation comment only once
145 print FILE "# files added by intltool-prepare\n";
148 print FILE "$desktop.in\n";
155 foreach $file (@desktop_files) {
163 my ($msgid, $line, $lang);
165 print "Rescuing translations from $filename ...\n" if $VERBOSE;
167 open ORIG, "<$filename";
169 ENTRY: while (<ORIG>) {
173 if (($entry =~ /^($keywords)=(.*)$/) ||
174 ($entry =~ /^(\s*description)=(.*)$/)) {
176 $msgid =~ s/\\/\\\\/g;
177 $msgid =~ s/\"/\\"/g;
178 } elsif (($entry =~ /^($keywords)\[(.*?)\]=(.*)$/) ||
179 ($entry =~ /^(\s*\[)(.*?)\]description=(.*)$/)) {
183 $msgstr =~ s/\\/\\\\/g;
184 $msgstr =~ s/"/\\"/g;
187 if ((-s "po/$lang.po") &&
188 (contains("po/$lang.po", "msgid \"$msgid\""))) {
192 open POFILE, ">>po/$lang.po";
194 print POFILE "\n#: $filename.in:$line\n";
195 print POFILE "msgid \"$msgid\"\n";
196 print POFILE "msgstr \"$msgstr\"\n";
206 foreach my $full (@desktop_files) {
209 print "Generating empty $new ...\n" if $VERBOSE;
215 (/^($keywords)\[.*?\]=.*$/) ||
216 (/^\s*\[(.*?)\]description=.*$/)
218 if (/^($keywords)=.*$/) {
220 } elsif (/^(\s*)(description=.*)$/) {
230 unless ($all eq ' ') {
231 print "*** Please add these files to CVS by following command: ***\n"
240 foreach $file (@desktop_files) {
241 $file =~ /^(.*\/)?(.+?\.$desktop_extension$)$/;
243 $ign = "$1.cvsignore";
249 next if contains($ign, $basename);
251 print "Appending $basename to $ign\n" if $VERBOSE;
253 print FILE "$basename\n";
257 unless ($all eq ' ') {
258 print "*** Please remove files from CVS by following command: ***\n"
259 . "cvs remove -f$all\n";
266 foreach $file (@desktop_files) {
267 my ($makefile, $line);
269 $file =~ /^(.*\/)?(.+?\.$desktop_extension$)$/;
271 $makefile = "$1Makefile.am";
273 $makefile = "Makefile.am";
276 print "Fixing $basename entry in $makefile\n" if $VERBOSE;
278 open MAKE, $makefile;
279 open NEWMAKE, ">$makefile.new";
281 while ($line = <MAKE>) {
282 $extra = 1 if $line =~ /^EXTRA_DIST/;
284 if (($line =~ /$basename/) &&
285 !($line =~ /$basename\.in/)) {
286 $line =~ s/$basename/$basename\.in/;
288 $extra = 0 unless $line =~ /\\\s*$/
290 if ($line =~ /^(\w+)_DATA\s*=\s*$basename\s*$/) {
292 $line =~ s/^$name\_DATA/$name\_in_files/;
293 $line =~ s/$basename/$basename\.in/;
294 $basename =~ /\.($desktop_extension)$/;
296 $line .= "$name\_DATA = \$($name\_in_files:.$ext.in=.$ext)\n";
298 if (!contains($makefile, "\@INTLTOOL_$ext\_RULE\@")) {
299 $line .= "\@INTLTOOL_$ext\_RULE\@\n";
306 rename "$makefile.new", $makefile;
312 my ($name, $str) = @_;
316 return 1 if $_ eq $str;
321 sub find_desktop_files
324 print "Found these interesting files:\n";
326 print "Finding interesting files...";
328 find (\&wanted, '.');
329 print "done\n" unless $VERBOSE;
334 if (/\.$desktop_extension$/) {
335 my $file = $File::Find::name;
337 push @desktop_files, $file;
338 print "$file\n" if $VERBOSE;
342 # vim: ts=4 sw=4 expandtab