#!/usr/bin/perl -pi

# $Id: totw.pl,v 1.23 2000/12/24 09:53:39 foka Exp $

$0 =~ m|to(..)\.pl$|;
my $sublang = $1;
my $SUBLANG = uc($sublang);

s|^(<HTML lang="zh)">|$1-$SUBLANG">|;
s/(\.zh)(?=\.(?:gif|jpg|png))/$1-$sublang/g;
s|^<A href=".*">(&#20013;&#25991;&nbsp;.+$SUBLANG.+)</A>(?=&nbsp;)|<B>$1</B>|;

s/µ¡¤f¨t²Î/µøµ¡¨t²Î/g;
s/ªA°È¾¹/¦øªA¾¹/g;
s/³n¥ó¥](?!¸Ë|¬A)/®M¥ó/g;
s/¶l(»¼|¥ó)¦Cªí/³q«H½×¾Â/g;
s/Ãè¹³(¯¸(ÂI)?)?/¬M®g¯¸¥x/g;
# s/Ãè¹³((ºô)?¯¸)/¬M®g$1/g;
s/ºôµ¸¹ï¶H¼Ò«¬Àô¹Ò/ºôµ¸ª«¥ó¼Ò«¬Àô¹Ò/g;

s/«æ±Ï½L/±Ï´©ºÏºÐ/g;
s/(¤Þ¾É|±Ò°Ê)½L/±Ò°ÊºÏºÐ/g;
s/¦w¸Ë½L/¦w¸ËºÏºÐ/g;

s/¤å¥»¤å¥ó/¯Â¤å¦rÀÉ/g;
s/µo¥¬¨t²Î/µo¦æ®M¥ó/g;
s/Åé¨tµ²ºc/¬[ºc/g;
s/·½¥N½X/­ì©l½X/g;
s/¸É¤B¤å¥ó/­×¸ÉÀÉ®×/g;
s/¦r¸`/¦ì¤¸²Õ/g;
s/®Ú¨t²ÎºÏ½L/¥DºÏ·Þ/g;
s/®Ú¤å¥ó¨t²Î/¥D¤å¥ó¨t²Î/g;
s/®Ú¥Ø¿ý/¥D¥Ø¿ý/g;
s/µw¥ó/µwÅé/g;
s/¥´¶}/¶}±Ò/g;
s/¤À°Ï/¤À³Î/g;

# 1 while (s/^((?:[\x00-\x7f]|[\x80-\xff].)*)¡§/$1¡u/);
# 1 while (s/^((?:[\x00-\x7f]|[\x80-\xff].)*)¡¨/$1¡v/);
1 while (s/^((?:[\x00-\x7f]|[\x80-\xff].)*(³n|µw|¥ú|ºÏ))½L/$1ºÐ/);


1 while (s/^((?:[\x00-\x7f]|[\x80-\xff].)*)­pºâ¾÷/$1¹q¸£/);
1 while (s/^((?:[\x00-\x7f]|[\x80-\xff].)*)¤º®Ö/$1®Ö¤ß/);
1 while (s/^((?:[\x00-\x7f]|[\x80-\xff].)*)¤º¦s/$1°O¾ÐÅé/);
1 while (s/^((?:[\x00-\x7f]|[\x80-\xff].)*)¤A¤Ó(?=ºô)/$1¥H¤Ó/);
1 while (s/^((?:[\x00-\x7f]|[\x80-\xff].)*)¦rÅé/$1¦r«¬/);
1 while (s/^((?:[\x00-\x7f]|[\x80-\xff].)*)«á¥x/$1­I´º/);
1 while (s/^((?:[\x00-\x7f]|[\x80-\xff].)*)µæ³æ/$1¿ï³æ/);
1 while (s/^((?:[\x00-\x7f]|[\x80-\xff].)*)¥ú¼Ð/$1´å¼Ð/);
1 while (s/^((?:[\x00-\x7f]|[\x80-\xff].)*)¹«¼Ð/$1·Æ¹«/);
1 while (s/^((?:[\x00-\x7f]|[\x80-\xff].)*)¯¸ÂI/$1¯¸¥x/);
1 while (s/^((?:[\x00-\x7f]|[\x80-\xff].)*)¬É­±/$1¤¶­±/);
1 while (s/^((?:[\x00-\x7f]|[\x80-\xff].)*)¸}¥»/$1½Z¥»/);
1 while (s/^((?:[\x00-\x7f]|[\x80-\xff].)*)«Ì¹õ/$1¿Ã¹õ/);
1 while (s/^((?:[\x00-\x7f]|[\x80-\xff].)*)¤åÀÉ(?!®×)/$1¤å¥ó/);
1 while (s/^((?:[\x00-\x7f]|[\x80-\xff].)*)µ{§Ç/$1µ{¦¡/);

1 while (s/^((?:[\x00-\x7f]|[\x80-\xff].)*)³q¹L/$1³z¹L/);

1 while (s/^((?:[\x00-\x7f]|[\x80-\xff].)*)³nÅX/$1³nºÐ¾÷/);
1 while (s/^((?:[\x00-\x7f]|[\x80-\xff].)*)¦^¨®Áä/$1 ENTER Áä/);
1 while (s/^((?:[\x00-\x7f]|[\x80-\xff].)*)¤å¥ó/$1ÀÉ®×/);
1 while (s/^((?:[\x00-\x7f]|[\x80-\xff].)*)¤åÀÉ(?!®×)/$1¤å¥ó/);



if ($sublang eq 'hk') {
    s/§@·~¨t²Î/¾Þ§@¨t²Î/g;
#    s/¸Uºûºô/¥þ²y¸ê°Tºô/g;
    s/¥þ²y¸ê°Tºô/¸Uºûºô/g;
    s/ºô»Úºô(?=¸ô|µ¸)/¤¬Ápºô/g;
    1 while (s/^((?:[\x00-\x7f]|[\x80-\xff].)*)ºô¸ô/$1ºôµ¸/);
    1 while (s/^((?:[\x00-\x7f]|[\x80-\xff].)*)¨Ï¥ÎªÌ/$1¥Î¤á/);
    1 while (s/^((?:[\x00-\x7f]|[\x80-\xff].)*)­pµe/$1­p¹º/);
#   1 while (s/^((?:[\x00-\x7f]|[\x80-\xff].)*)³s(?=Ã´|µ¸)/$1Áp/);
    1 while (s/^((?:[\x00-\x7f]|[\x80-\xff].)*)³s(?=µ¸)/$1Áp/);
    1 while (s/^((?:[\x00-\x7f]|[\x80-\xff].)*(³n|µw))Åé/$1¥ó/);
    1 while (s/^((?:[\x00-\x7f]|[\x80-\xff].)*)¦C¦L/$1¥´¦L/);
    1 while (s/^((?:[\x00-\x7f]|[\x80-\xff].)*)¦Lªí¾÷/$1¥´¦L¾÷/);
}

if ($sublang eq 'tw') {
    s/¾Þ§@¨t²Î/§@·~¨t²Î/g;
    s/¸Uºûºô/¥þ²y¸ê°Tºô/g;
    s/¤¬Ápºô/ºô»Úºô¸ô/g;
    1 while (s/^((?:[\x00-\x7f]|[\x80-\xff].)*)ºôµ¸/$1ºô¸ô/);
    1 while (s/^((?:[\x00-\x7f]|[\x80-\xff].)*)¥Î¤á/$1¨Ï¥ÎªÌ/);
    1 while (s/^((?:[\x00-\x7f]|[\x80-\xff].)*)­p¹º/$1­pµe/);
    1 while (s/^((?:[\x00-\x7f]|[\x80-\xff].)*)Áp(?=Ã´|µ¸)/$1³s/);
    1 while (s/^((?:[\x00-\x7f]|[\x80-\xff].)*(³n|µw))¥ó/$1Åé/);
    1 while (s/^((?:[\x00-\x7f]|[\x80-\xff].)*)¥´¦L¾÷/$1¦Lªí¾÷/);
    1 while (s/^((?:[\x00-\x7f]|[\x80-\xff].)*)¥´¦L/$1¦C¦L/);
}

s/§Y´¡§Y¥Î/ÀH´¡§Y¥Î/g;
s/µ¡¤f¨t²Î/µøµ¡¨t²Î/g;
s/X~µ¡¤f/X~µøµ¡/g;
1 while (s/^((?:[\x00-\x7f]|[\x80-\xff].)*)µ¡¤f/$1µøµ¡/);
s/¼Æ¾Ú®w/¸ê®Æ®w/g;


# ¥Í©È¦³¤Hªº¹q¸£Åª¤£¨ì¡uùØ¡v¦r¡C
1 while (s/^((?:[\x00-\x7f]|[\x80-\xff].)*)ùØ/$1¸Ì/);
