[a580dc1] | 1 | #!/usr/bin/perl -w |
---|
[68d7dfc] | 2 | |
---|
| 3 | # gettexttomsg.pl |
---|
| 4 | # |
---|
[845dff3] | 5 | # Copyright (C) 2001,2002,2005,2011,2012,2014 Olly Betts |
---|
[68d7dfc] | 6 | # |
---|
| 7 | # This program is free software; you can redistribute it and/or modify |
---|
| 8 | # it under the terms of the GNU General Public License as published by |
---|
| 9 | # the Free Software Foundation; either version 2 of the License, or |
---|
| 10 | # (at your option) any later version. |
---|
| 11 | # |
---|
| 12 | # This program is distributed in the hope that it will be useful, |
---|
| 13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
| 15 | # GNU General Public License for more details. |
---|
| 16 | # |
---|
| 17 | # You should have received a copy of the GNU General Public License |
---|
| 18 | # along with this program; if not, write to the Free Software |
---|
| 19 | # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
---|
| 20 | |
---|
[6432368] | 21 | require 5.008; |
---|
[a580dc1] | 22 | use strict; |
---|
| 23 | |
---|
| 24 | my %revmsgs = (); |
---|
| 25 | |
---|
[0dc5829] | 26 | my $msgno; |
---|
| 27 | open MSG, "../lib/survex.pot" or die $!; |
---|
[a580dc1] | 28 | while (<MSG>) { |
---|
[0dc5829] | 29 | if (/^#: n:(\d+)$/) { |
---|
| 30 | $msgno = $1; |
---|
| 31 | } elsif (defined $msgno && /^msgid\s*"(.*)"/) { |
---|
| 32 | $revmsgs{$1} = $msgno; |
---|
| 33 | $msgno = undef; |
---|
[c930b7f] | 34 | } |
---|
[a580dc1] | 35 | } |
---|
[0dc5829] | 36 | close MSG; |
---|
[a580dc1] | 37 | |
---|
| 38 | my $die = 0; |
---|
| 39 | |
---|
[845dff3] | 40 | my $suppress_argc_argv_unused_warnings = 0; |
---|
[a580dc1] | 41 | while (<>) { |
---|
[845dff3] | 42 | if ($suppress_argc_argv_unused_warnings && /^{/) { |
---|
| 43 | $suppress_argc_argv_unused_warnings = 0; |
---|
[9fe9323] | 44 | print "$_ (void)argc;\n (void)argv;\n"; |
---|
[845dff3] | 45 | next; |
---|
| 46 | } |
---|
| 47 | |
---|
| 48 | if (/^_getopt_initialize\b/) { |
---|
| 49 | $suppress_argc_argv_unused_warnings = 1; |
---|
| 50 | } elsif (!/^\s*#/) { |
---|
[a580dc1] | 51 | while (/\\\n$/) { |
---|
| 52 | $_ .= <>; |
---|
| 53 | } |
---|
| 54 | # very crude - doesn't know about comments, etc |
---|
[c40038a] | 55 | s!\b_\("(.*?)"\)!replacement($1)!gse; |
---|
[a580dc1] | 56 | } elsif (/\s*#\s*define\s+_\(/) { |
---|
| 57 | $_ = "#include \"message.h\"\n"; |
---|
| 58 | } |
---|
| 59 | print; |
---|
| 60 | } |
---|
| 61 | |
---|
| 62 | if ($die) { |
---|
| 63 | die "Not all messages found!\n"; |
---|
| 64 | } |
---|
| 65 | |
---|
[c40038a] | 66 | sub replacement { |
---|
[a580dc1] | 67 | my $msg = shift; |
---|
| 68 | $msg =~ s/\\\n//g; |
---|
[c40038a] | 69 | my $msgno = ""; |
---|
| 70 | if (exists $revmsgs{$msg}) { |
---|
| 71 | $msgno = $revmsgs{$msg}; |
---|
| 72 | } else { |
---|
[0804fbe] | 73 | my $tmp = $msg; |
---|
[ee7511a] | 74 | $tmp =~ s/`(.*?)'/“$1”/g; |
---|
| 75 | $tmp =~ s/(\w)'(\w)/$1’$2/g; |
---|
[0804fbe] | 76 | if (exists $revmsgs{$tmp}) { |
---|
| 77 | $msg = $tmp; |
---|
| 78 | $msgno = $revmsgs{$msg}; |
---|
| 79 | } else { |
---|
| 80 | if (!$die) { |
---|
| 81 | print STDERR "Message(s) not found in message file:\n"; |
---|
| 82 | $die = 1; |
---|
| 83 | } |
---|
| 84 | print STDERR "'$msg'\n"; |
---|
[a580dc1] | 85 | } |
---|
| 86 | } |
---|
[c40038a] | 87 | return "msg(/*$msg*/$msgno)"; |
---|
[a580dc1] | 88 | } |
---|