source: git/src/gettexttomsg.pl@ e3a2b41

RELEASE/1.2 debug-ci debug-ci-sanitisers faster-cavernlog log-select main stereo stereo-2025 walls-data walls-data-hanging-as-warning warn-only-for-hanging-survey
Last change on this file since e3a2b41 was 9fe9323, checked in by Olly Betts <olly@…>, 12 years ago

src/gettexttomsg.pl: Fix typo in generated code to suppress compiler
warnings, added since last release.

  • Property mode set to 100755
File size: 2.1 KB
Line 
1#!/usr/bin/perl -w
2
3# gettexttomsg.pl
4#
5# Copyright (C) 2001,2002,2005,2011,2012,2014 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
40my $suppress_argc_argv_unused_warnings = 0;
41while (<>) {
42 if ($suppress_argc_argv_unused_warnings && /^{/) {
43 $suppress_argc_argv_unused_warnings = 0;
44 print "$_ (void)argc;\n (void)argv;\n";
45 next;
46 }
47
48 if (/^_getopt_initialize\b/) {
49 $suppress_argc_argv_unused_warnings = 1;
50 } elsif (!/^\s*#/) {
51 while (/\\\n$/) {
52 $_ .= <>;
53 }
54 # very crude - doesn't know about comments, etc
55 s!\b_\("(.*?)"\)!replacement($1)!gse;
56 } elsif (/\s*#\s*define\s+_\(/) {
57 $_ = "#include \"message.h\"\n";
58 }
59 print;
60}
61
62if ($die) {
63 die "Not all messages found!\n";
64}
65
66sub replacement {
67 my $msg = shift;
68 $msg =~ s/\\\n//g;
69 my $msgno = "";
70 if (exists $revmsgs{$msg}) {
71 $msgno = $revmsgs{$msg};
72 } else {
73 my $tmp = $msg;
74 $tmp =~ s/`(.*?)'/“$1”/g;
75 $tmp =~ s/(\w)'(\w)/$1’$2/g;
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";
85 }
86 }
87 return "msg(/*$msg*/$msgno)";
88}
Note: See TracBrowser for help on using the repository browser.