-
Notifications
You must be signed in to change notification settings - Fork 0
/
posubst.in
73 lines (69 loc) · 1.48 KB
/
posubst.in
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#!@PERL@
# gettext message substitute
#
use strict;
use warnings;
my $po_dir='po';
my $lang='@POLANG@';
my %msg = ();
my $msgid = '';
my $charset = "UTF-8";
my $charset_code = "WC_CES_UTF_8";
open(PO, "$po_dir/$lang.po") or die "cannot open $po_dir/$lang.po, $!";
while (<PO>) {
if (/^msgid\s*"(.*)"/) {
$msgid = $1;
next;
}
if (/^msgstr\s*"(.*)"/) {
$msg{$msgid} = $1;
next;
}
if (/^"Content-Type: text\/plain; charset=(.*)\\n"/) {
$charset = $1;
next;
}
}
close(PO);
open(CL, "charset-list") or die "cannot open charset-list, $!";
while (<CL>) {
my @l = split;
if ($l[0] eq $charset) {
$charset_code = $l[1];
last;
}
}
close(CL);
my @src = grep {/\.c$/} @ARGV;
my @tmp = ();
foreach my $src (@src) {
open(SRC0, $src) or die "cannot open $src, $!";
push(@tmp, ".$src");
open(SRC1, ">.$src") or die "cannot create .$src, $!";
while (<SRC0>) {
s/^static\s*wc_ces\s*(\S+)\s*=\s*(WC_CES_\S+)\s*;\s*\/\*\s*FIXME: charset of source code \*\//static wc_ces $1 = $charset_code; \/* FIXME: charset of source code *\//;
s/(N?_\(")([^"]*)("\))/$1 . ($msg{$2} || $2) . $3/ge;
print SRC1 $_;
}
close(SRC0);
close(SRC1);
}
map {s/(.*\.c)$/.$1/} @ARGV;
my $err = 0;
system @ARGV;
if ($? == -1) {
print "failed to execute: $!\n";
$err = 125;
}
elsif ($? & 127) {
printf "child died with signal %d\n", ($? & 127);
$err = 125;
}
else {
$err = $? >> 8;
if ($err != 0) {
printf "child exited with value %d\n", $err;
}
}
unlink @tmp;
exit $err;