source: git/src/gettexttomsg.pl @ cf686e0

RELEASE/1.2debug-cidebug-ci-sanitisersfaster-cavernlogstereowalls-datawalls-data-hanging-as-warning
Last change on this file since cf686e0 was 0dc5829, checked in by Olly Betts <olly@…>, 11 years ago

lib/,src/Makefile.am,src/gettexttomsg.pl: Eliminate po_codes and just
store the message numbers as the line number in a fake source
reference to file 'n'.

  • Property mode set to 100755
File size: 1.8 KB
Line 
1#!/usr/bin/perl -w
2
3#  gettexttomsg.pl
4#
5#  Copyright (C) 2001,2002,2005,2011,2012 Olly Betts
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
21require 5.008;
22use strict;
23
24my %revmsgs = ();
25
26my $msgno;
27open MSG, "../lib/survex.pot" or die $!;
28while (<MSG>) {
29    if (/^#: n:(\d+)$/) {
30        $msgno = $1;
31    } elsif (defined $msgno && /^msgid\s*"(.*)"/) {
32        $revmsgs{$1} = $msgno;
33        $msgno = undef;
34    }
35}
36close MSG;
37
38my $die = 0;
39
40while (<>) {
41    if (!/^\s*#/) {
42        while (/\\\n$/) {
43            $_ .= <>;
44        }
45        # very crude - doesn't know about comments, etc
46        s!\b_\("(.*?)"\)!replacement($1)!gse;
47    } elsif (/\s*#\s*define\s+_\(/) {
48        $_ = "#include \"message.h\"\n";
49    }
50    print;
51}
52
53if ($die) {
54    die "Not all messages found!\n";
55}
56
57sub replacement {
58    my $msg = shift;
59    $msg =~ s/\\\n//g;
60    my $msgno = "";
61    if (exists $revmsgs{$msg}) {
62        $msgno = $revmsgs{$msg};
63    } else {
64        my $tmp = $msg;
65        $tmp =~ s/`(.*?)'/“$1”/g;
66        $tmp =~ s/(\w)'(\w)/$1’$2/g;
67        if (exists $revmsgs{$tmp}) {
68            $msg = $tmp;
69            $msgno = $revmsgs{$msg};
70        } else {
71            if (!$die) {
72                print STDERR "Message(s) not found in message file:\n";
73                $die = 1;
74            }
75            print STDERR "'$msg'\n";
76        }
77    }
78    return "msg(/*$msg*/$msgno)";
79}
Note: See TracBrowser for help on using the repository browser.