5 # Copyright (C) 2001,2002,2005,2011,2012,2014,2015 Olly Betts
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.
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.
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
27 open MSG
, "../lib/survex.pot" or die $!;
31 } elsif (defined $msgno && /^msgid\s*"(.*)"/) {
32 $revmsgs{$1} = $msgno;
40 my $suppress_argc_argv_unused_warnings = 0;
43 # Helper so we can just eval preprocessor expressions.
44 sub pp_defined
{ exists $macro{$_[0]} // 0 }
48 # defined is a built-in function in Perl.
49 s/\bdefined\b/pp_defined/g;
57 if (m!^#\s*(\w+)\s*(.*?)\s*(?:/[/*].*)?$!) {
58 my ($directive, $cond) = ($1, $2);
59 if ($directive eq 'endif') {
60 if (@conditionals == 0) {
61 die "$ARGV:$.: Unmatched #endif\n";
63 $active = pop @conditionals;
64 } elsif ($directive eq 'else') {
65 if (@conditionals == 0) {
66 die "$ARGV:$.: Unmatched #else\n";
68 $active = (!$active) && $conditionals[-1];
69 } elsif ($directive eq 'ifdef') {
70 push @conditionals, $active;
71 $active &&= pp_defined
($cond);
72 } elsif ($directive eq 'ifndef') {
73 push @conditionals, $active;
74 $active &&= !pp_defined
($cond);
75 } elsif ($directive eq 'if') {
76 push @conditionals, $active;
77 $active &&= pp_eval
($cond);
79 if ($directive eq 'define') {
80 $cond =~ /^(\w+)\s*(.*)/;
83 eval "sub $1 { q($2) }";
84 } elsif ($directive eq 'undef') {
99 if ($suppress_argc_argv_unused_warnings && /^{/) {
100 $suppress_argc_argv_unused_warnings = 0;
101 print "$_ (void)argc;\n (void)argv;\n";
105 if (/^_getopt_initialize\b/) {
106 $suppress_argc_argv_unused_warnings = 1;
111 # very crude - doesn't know about comments, etc
112 s!\b_\("(.*?)"\)!replacement($1)!gse;
113 } elsif (/\s*#\s*define\s+_\(/) {
114 $_ = "#include \"message.h\"\n";
120 die "Not all messages found!\n";
127 if (exists $revmsgs{$msg}) {
128 $msgno = $revmsgs{$msg};
131 $tmp =~ s/`(.*?)'/“$1”/g;
132 $tmp =~ s/(\w)'(\w)/$1’$2/g;
133 if (exists $revmsgs{$tmp}) {
135 $msgno = $revmsgs{$msg};
138 print STDERR
"Message(s) not found in message file:\n";
141 print STDERR
"'$msg'\n";
144 return "msg(/*$msg*/$msgno)";