1#! @PERL@
2#                                                         -*- Perl -*-
3# Copyright (C) 2000  Motoyuki Kasahara
4#
5# This program is free software; you can redistribute it and/or modify
6# it under the terms of the GNU General Public License as published by
7# the Free Software Foundation; either version 2, or (at your option)
8# any later version.
9#
10# This program is distributed in the hope that it will be useful,
11# but WITHOUT ANY WARRANTY; without even the implied warranty of
12# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13# GNU General Public License for more details.
14
15if (@ARGV != 1) {
16    die "Usage: $0 po-file\n";
17}
18$file_name = $ARGV[0];
19
20#
21# Read the old message file.
22#
23if (!open(FILE, $file_name)) {
24    die "$0: failed to open the file, $!: $file_name\n";
25}
26
27$msgid = '';
28while (<FILE>) {
29    next if /^\#/;
30    chop if /\n/;
31    if (/^msgid:(.*)/) {
32	$msgid = $1;
33	if ($msgid eq '') {
34	    warn "$file_name:$.: msgid is empty\n";
35	    next;
36	} elsif (defined($old_messages{$msgid})) {
37	    warn "$file_name:$.: msgid redefined: $msgid";
38	    next;
39	}
40	$old_messages{$msgid} = '';
41
42    } elsif (/^msgstr:(.*)/) {
43	$msgstr = $1;
44	if ($msgid eq '') {
45	    warn "$file_name:$.: msgid is empty\n";
46	    next;
47	} elsif ($msgstr eq '') {
48	    warn "$file_name:$.: msgstr is empty\n";
49	    next;
50	}
51	$fixed_msgid = $msgid;
52	$fixed_msgid =~ s/ /\\ /g;
53	$old_messages{$msgid} = $msgstr;
54	print "set messages($fixed_msgid) \"$msgstr\"\n";
55    }
56}
57close(FILE);
58