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 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247
|
#!/usr/bin/perl
# -*- perl -*-
use Getopt::Std;
getopt('cm');
if (defined($opt_c)) {
$config_file = $opt_c;
} else {
$config_file = "/etc/chinese.conf";
}
if (defined($opt_m)) {
$multitab_file = $opt_m;
} else {
$multitab_file = "/etc/multitab";
}
$chsys = $ARGV[0];
if (!defined($chsys)) {
warn "Chinese system path not specified";
print <<END;
Usage: $0 [-c config_file] chsys_path
-c config_file specifies the chdrv configuration file
(default: /etc/chinese.conf)
-m multitab_file specifies the chdrv input methods configuration file
(default: /etc/multitab)
chsys_path specifies the chdrv Chinese system path
END
exit 1;
}
open(FD,"$config_file") || die("Failed to open $config_file");
system("rm ${chsys}/config");
open(DAT,">>${chsys}/config");
while(<FD>)
{
if (/^\s*#/) {loop;}
if ( /^\s*BEGIN[ \t]*([a-zA-Z0-9]*)/)
{
print "Parse $1 block\n";
if ($1 eq "WINDOW") {&translate_window($ARGV[0]);}
elsif ($1 eq "INPUT") {&translate_input($ARGV[0]);}
elsif ($1 eq "FONT") {&translate_font($ARGV[0]);}
elsif ($1 eq "ENV") {&translate_env($ARGV[0]);}
elsif ($1 eq "OTHER") {&translate_other($ARGV[0]);}
else
{
print STDERR "Error block $1 encounter\n";
while(<FD>) {if (/END/) {last;}}
}
}
}
sub translate_window
{
local($path) = @_;
$sizex = 80;
$sizey = 29;
$fc = 1;
$bc = 0;
$sc = 7;
while(<FD>)
{
if ( /^#/) {loop;}
if ( /SIZE\s*([0-9]*)\s*([0-9]*)/)
{
print DAT "SIZE=$1,$2\n";
}
elsif ( /FORECOLOR\s*([0-9]*)/)
{
print DAT "FORECOLOR=$1\n";
}
elsif ( /BACKCOLOR\s*([0-9]*)/)
{
print DAT "BACKCOLOR=$1\n";
}
elsif ( /SYSTEMCOLOR\s*([0-9]*)/)
{
print DAT "SYSTEMCOLOR=$1\n";
}
elsif ( /SYSTEMBACK\s*([0-9]*)/)
{
print DAT "SYSTEMBACK=$1\n";
}
elsif (/COLORTABLE\s*([0-9 ]*)/)
{
print DAT "COLORTABLE=$1\n";
}
elsif ( /END/)
{
last;
}
}
}
sub translate_input
{
local($path) = @_;
open(MULTITAB,">$multitab_file");
$i = 1;
while(<FD>)
{
if ( /^#/) {loop;}
if ( /PHONETIC[ \t]*([^ \t\n]*)/)
{
$ENV{'PHONETIC_TABLE'} = $1;
}
elsif ( /MULTI[ \t]*([^ \t\n]*)/)
{
printf MULTITAB "$i $1\n";
$i++;
}
elsif ( /END/)
{ last;}
else
{
print STDERR "error line $_";
}
}
close(MULTITAB);
}
sub translate_font
{
local($path) = @_;
while(<FD>)
{
if ( /^#/)
{loop;}
if ( /STYLE[ \t]*([^ \t\n]*)/)
{
if ($1 eq "HBF")
{ $ishbf = 1;}
else
{ $ishbf = 0;}
last;
}
else
{
print STDERR "The first line of font block must be STYLE\n";
}
}
open(FONT,">${path}kcfont");
$has_ascii = 0;
if ($ishbf)
{print FONT "!!!HBF\n";}
while(<FD>)
{
if ( /^\#/) {loop;}
if ( /ASCII[ \t]*([^ \t]*)[ \t]*([0-9]*)[ \t]*([0-9]*)/)
{
if ($has_ascii)
{ print STDERR "Duplicte ASCII\n";}
else
{
print FONT "$1 $2 $3\n";
}
$has_ascii = 1;
}
elsif( /CFONT[ \t]*([^ \t]*)[ \t]*([0-9]*)[ \t]*([0-9]*)/)
{
if ($ishbf)
{loop;}
if ($has_ascii == 0)
{ print STDERR "Must has ASCII before FONT\n";}
print FONT "$1 $2 $3\n";
$_ = <FD>;
print FONT $_;
}
elsif ( /HBF[ \t]*([^ \t\n]*)/)
{
if ($ishbf) {print FONT "$1\n";}
}
elsif ( /HBFPATH[ \t]*([^ \t\n]*)/)
{
print EXEC "export CFONTDIR=$1\n";
}
elsif ( /PFONT([DKLM])[ \t]*([^ \t\n]*)/)
{
if ($1 eq "L")
{system "ln -sf $2 cn24l.hbf";}
elsif ($1 eq "K")
{system "ln -sf $2 cn24k.hbf";}
elsif ($1 eq "M")
{system "ln -sf $2 cn24m.hbf";}
elsif ($1 eq "D")
{system "ln -sf $2 cn24j.hbf";}
}
elsif ( /END/)
{last;}
}
close(FONT);
}
sub translate_env
{
local($path) = @_;
open(PRO,">${path}ch_profile");
while(<FD>)
{
if (/END/)
{last;}
print PRO $_;
}
close(PRO);
chmod(755,"${path}ch_profile");
}
sub translate_other
{
while(<FD>)
{
if (/^\s*#/) { next;}
if (/ETMODE\s*(\w*)/)
{
if ($1 == "on") { print DAT "ETMODE = on";}
elsif ($1 == "off") { print DAT "ETMODE = off";}
else { print stderr "ETMODE invalid\n";}
}
elsif (/GRDR\s*(\w*)/)
{
print DAT "GRDR=$1\n";
}
elsif (/VT\s*(\w*)/)
{
print DAT "VT=$1\n";
}
elsif (/BLANK_TIME\s*([0-9]*)/)
{
print stderr "feature not implement now\n";
print DAT "BLANK_TIME=$1\n";
}
elsif (/LOGINPROGRAM\s*([^\n]*)/)
{
print DAT "LOGINPROGRAM=$1\n";
}
elsif (/END/)
{
last;
}
else
{
print stderr "error command : $_\n";
}
}
}
|