posubst.in (1187B)
1 #!@PERL@ 2 # gettext message substitute 3 # 4 $po_dir='po'; 5 $lang='@POLANG@'; 6 %msg = (); 7 $msgid = ''; 8 $charset = "UTF-8"; 9 $charset_code = "WC_CES_UTF_8"; 10 open(PO, "$po_dir/$lang.po") or die "cannot open $po_dir/$lang.po, $!"; 11 while (<PO>) { 12 if (/^msgid\s*"(.*)"/) { 13 $msgid = $1; 14 next; 15 } 16 if (/^msgstr\s*"(.*)"/) { 17 $msg{$msgid} = $1; 18 next; 19 } 20 if (/^"Content-Type: text\/plain; charset=(.*)\\n"/) { 21 $charset = $1; 22 next; 23 } 24 } 25 close(PO); 26 open(CL, "charset-list") or die "cannot open charset-list, $!"; 27 while (<CL>) { 28 @l = split; 29 if ($l[0] eq $charset) { 30 $charset_code = $l[1]; 31 last; 32 } 33 } 34 close(CL); 35 36 @src = grep {/\.c$/} @ARGV; 37 @tmp = (); 38 foreach $src (@src) { 39 open(SRC0, $src) or die "cannot open $src, $!"; 40 push(@tmp, ".$src"); 41 open(SRC1, ">.$src") or die "cannot create .$src, $!"; 42 while (<SRC0>) { 43 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 *\//; 44 s/(N?_\(")([^"]*)("\))/$1 . ($msg{$2} || $2) . $3/ge; 45 print SRC1 $_; 46 } 47 close(SRC0); 48 close(SRC1); 49 } 50 51 map {s/(.*\.c)$/.$1/} @ARGV; 52 system @ARGV; 53 unlink @tmp;