1 |
#!/usr/bin/perl |
2 |
|
3 |
binmode STDIN; |
4 |
binmode STDOUT; |
5 |
undef $/; |
6 |
$text = <STDIN>; |
7 |
if ($ARGV[0] eq "-jis") { |
8 |
$text =~ s/EUC/JIS/g; |
9 |
$text =~ s/euc-jp/iso-2022-jp/g; |
10 |
$text =~ s#([\241-\376])([\241-\376])# |
11 |
"\033\$B".pack("cc",ord($1)&127,ord($2)&127)."\033(B"#eg; |
12 |
# The language name (the only thing before the STRFTIME_* strings) |
13 |
# shouldn't have its %'s escaped; all other strings should, because |
14 |
# they go through sprintf(). |
15 |
$pos = index($text, "STRFTIME"); |
16 |
$pos = length($text) if $pos == 0; |
17 |
$t1 = substr($text, 0, $pos); |
18 |
$t2 = substr($text, $pos, length($text)-$pos); |
19 |
$t2 =~ s#(\033\$B.)%(\033\(B)#\1%%\2#g; |
20 |
$t2 =~ s#(\033\$B)%(.\033\(B)#\1%%\2#g; |
21 |
$text = $t1 . $t2; |
22 |
$text =~ s#\033\(B\033\$B##g; |
23 |
} elsif ($ARGV[0] eq "-sjis") { |
24 |
$text =~ s/EUC/SJIS/g; |
25 |
$text =~ s/euc-jp/shift_jis/g; |
26 |
$text =~ s#([\241-\376])([\241-\376])# |
27 |
$x = 0201+(ord($1)-0241)/2; |
28 |
$y = 0100+(ord($2)-0241)+((ord($1)-0241)%2)*94; |
29 |
$x += 0100 if $x >= 0240; |
30 |
$y++ if $y >= 0177; |
31 |
pack("cc",$x,$y)#eg; |
32 |
} |
33 |
print $text; |