| 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 |
use 5.8.0; |
|---|
| 29 |
|
|---|
| 30 |
|
|---|
| 31 |
use strict; |
|---|
| 32 |
|
|---|
| 33 |
|
|---|
| 34 |
use utf8; |
|---|
| 35 |
use open ':utf8'; |
|---|
| 36 |
binmode(STDOUT, ":utf8"); |
|---|
| 37 |
|
|---|
| 38 |
|
|---|
| 39 |
require "newgetopt.pl"; |
|---|
| 40 |
|
|---|
| 41 |
my ( |
|---|
| 42 |
$this_script, |
|---|
| 43 |
$opt_debug, |
|---|
| 44 |
$opt_file, |
|---|
| 45 |
$out_line, |
|---|
| 46 |
); |
|---|
| 47 |
|
|---|
| 48 |
|
|---|
| 49 |
$this_script = $0; |
|---|
| 50 |
$this_script =~ s|^.*/([^/]*)|$1|; |
|---|
| 51 |
|
|---|
| 52 |
|
|---|
| 53 |
&get_args(); |
|---|
| 54 |
|
|---|
| 55 |
if (! $opt_file ) |
|---|
| 56 |
{ |
|---|
| 57 |
print "ERROR($this_script): Specify input file to process with '-file' option\n"; |
|---|
| 58 |
&usage(1); |
|---|
| 59 |
} |
|---|
| 60 |
|
|---|
| 61 |
open (INFILE, "< $opt_file") or die "Can't open $opt_file - $! \n"; |
|---|
| 62 |
|
|---|
| 63 |
while (<INFILE>) |
|---|
| 64 |
{ |
|---|
| 65 |
$out_line .= &shape_line($_); |
|---|
| 66 |
} |
|---|
| 67 |
print $out_line; |
|---|
| 68 |
|
|---|
| 69 |
exit(0); |
|---|
| 70 |
|
|---|
| 71 |
|
|---|
| 72 |
|
|---|
| 73 |
|
|---|
| 74 |
|
|---|
| 75 |
|
|---|
| 76 |
|
|---|
| 77 |
sub shape_line |
|---|
| 78 |
{ |
|---|
| 79 |
my ($line) = @_; |
|---|
| 80 |
|
|---|
| 81 |
use constant ISOLATED => 0; |
|---|
| 82 |
use constant INITIAL => 1; |
|---|
| 83 |
use constant MEDIAL => 2; |
|---|
| 84 |
use constant FINAL => 3; |
|---|
| 85 |
|
|---|
| 86 |
my ( |
|---|
| 87 |
@char, |
|---|
| 88 |
$cur, |
|---|
| 89 |
$prev, |
|---|
| 90 |
$next, |
|---|
| 91 |
$index, |
|---|
| 92 |
$prev_index, |
|---|
| 93 |
$next_index, |
|---|
| 94 |
$out, |
|---|
| 95 |
$str, |
|---|
| 96 |
); |
|---|
| 97 |
|
|---|
| 98 |
|
|---|
| 99 |
|
|---|
| 100 |
my %map = ( |
|---|
| 101 |
"621" => ["FE80", 0, 0, 0], |
|---|
| 102 |
"622" => ["FE81", 0, 0, "FE82"], |
|---|
| 103 |
"623" => ["FE83", 0, 0, "FE84"], |
|---|
| 104 |
"624" => ["FE85", 0, 0, "FE86"], |
|---|
| 105 |
"625" => ["FE87", 0, 0, "FE88"], |
|---|
| 106 |
"626" => ["FE89", "FE8B", "FE8C", "FE8A"], |
|---|
| 107 |
"627" => ["FE8D", 0, 0, "FE8E"], |
|---|
| 108 |
"628" => ["FE8F", "FE91", "FE92", "FE90"], |
|---|
| 109 |
"629" => ["FE93", 0, 0, "FE94"], |
|---|
| 110 |
"62A" => ["FE95", "FE97", "FE98", "FE96"], |
|---|
| 111 |
"62B" => ["FE99", "FE9B", "FE9C", "FE9A"], |
|---|
| 112 |
"62C" => ["FE9D", "FE9F", "FEA0", "FE9E"], |
|---|
| 113 |
"62D" => ["FEA1", "FEA3", "FEA4", "FEA2"], |
|---|
| 114 |
"62E" => ["FEA5", "FEA7", "FEA8", "FEA6"], |
|---|
| 115 |
"62F" => ["FEA9", 0, 0, "FEAA"], |
|---|
| 116 |
"630" => ["FEAB", 0, 0, "FEAC"], |
|---|
| 117 |
"631" => ["FEAD", 0, 0, "FEAE"], |
|---|
| 118 |
"632" => ["FEAF", 0, 0, "FEB0"], |
|---|
| 119 |
"633" => ["FEB1", "FEB3", "FEB4", "FEB2"], |
|---|
| 120 |
"634" => ["FEB5", "FEB7", "FEB8", "FEB6"], |
|---|
| 121 |
"635" => ["FEB9", "FEBB", "FEBC", "FEBA"], |
|---|
| 122 |
"636" => ["FEBD", "FEBF", "FEC0", "FEBE"], |
|---|
| 123 |
"637" => ["FEC1", "FEC3", "FEC4", "FEC2"], |
|---|
| 124 |
"638" => ["FEC5", "FEC7", "FEC8", "FEC6"], |
|---|
| 125 |
"639" => ["FEC9", "FECB", "FECC", "FECA"], |
|---|
| 126 |
"63A" => ["FECD", "FECF", "FED0", "FECE"], |
|---|
| 127 |
"640" => [ "640", 0, 0, 0], |
|---|
| 128 |
"641" => ["FED1", "FED3", "FED4", "FED2"], |
|---|
| 129 |
"642" => ["FED5", "FED7", "FED8", "FED6"], |
|---|
| 130 |
"643" => ["FED9", "FEDB", "FEDC", "FEDA"], |
|---|
| 131 |
"644" => ["FEDD", "FEDF", "FEE0", "FEDE"], |
|---|
| 132 |
"645" => ["FEE1", "FEE3", "FEE4", "FEE2"], |
|---|
| 133 |
"646" => ["FEE5", "FEE7", "FEE8", "FEE6"], |
|---|
| 134 |
"647" => ["FEE9", "FEEB", "FEEC", "FEEA"], |
|---|
| 135 |
"648" => ["FEED", 0, 0, "FEEE"], |
|---|
| 136 |
"649" => ["FEEF", 0, 0, "FEF0"], |
|---|
| 137 |
"64A" => ["FEF1", "FEF3", "FEF4", "FEF2"], |
|---|
| 138 |
|
|---|
| 139 |
"644622" => ["FEF5", 0, 0, "FEF6"], |
|---|
| 140 |
"644623" => ["FEF7", 0, 0, "FEF8"], |
|---|
| 141 |
"644625" => ["FEF9", 0, 0, "FEFA"], |
|---|
| 142 |
"644627" => ["FEFB", 0, 0, "FEFC"], |
|---|
| 143 |
|
|---|
| 144 |
|
|---|
| 145 |
|
|---|
| 146 |
|
|---|
| 147 |
|
|---|
| 148 |
"67E" => [ "FB58", "FB58", "FB59", "FB57" ], |
|---|
| 149 |
"686" => [ "FB7A", "FB7C", "FB7D", "FB7B" ], |
|---|
| 150 |
"6AF" => [ "FB92", "FB94", "FB95", "FB93" ], |
|---|
| 151 |
"6CC" => [ "FBFC", "FBFE", "FBFF", "FBFD" ], |
|---|
| 152 |
); |
|---|
| 153 |
|
|---|
| 154 |
my %special_is_next = ( "640" => 1 ); |
|---|
| 155 |
my %special_is_comb1 = ( "644" => 1 ); |
|---|
| 156 |
my %special_is_comb2 = ( |
|---|
| 157 |
"622" => 1, |
|---|
| 158 |
"623" => 1, |
|---|
| 159 |
"625" => 1, |
|---|
| 160 |
"627" => 1, |
|---|
| 161 |
); |
|---|
| 162 |
|
|---|
| 163 |
my %special_is_composing = ( |
|---|
| 164 |
"64B" => 1, |
|---|
| 165 |
"64C" => 1, |
|---|
| 166 |
"64D" => 1, |
|---|
| 167 |
"64E" => 1, |
|---|
| 168 |
"64F" => 1, |
|---|
| 169 |
"650" => 1, |
|---|
| 170 |
"651" => 1, |
|---|
| 171 |
"652" => 1, |
|---|
| 172 |
"653" => 1, |
|---|
| 173 |
"654" => 1, |
|---|
| 174 |
"655" => 1, |
|---|
| 175 |
"670" => 1, |
|---|
| 176 |
"6D6" => 1, |
|---|
| 177 |
"6D7" => 1, |
|---|
| 178 |
"6D8" => 1, |
|---|
| 179 |
"6D9" => 1, |
|---|
| 180 |
"6DA" => 1, |
|---|
| 181 |
"6DB" => 1, |
|---|
| 182 |
"6DC" => 1, |
|---|
| 183 |
|
|---|
| 184 |
|
|---|
| 185 |
|
|---|
| 186 |
"6DF" => 1, |
|---|
| 187 |
"6E0" => 1, |
|---|
| 188 |
"6E1" => 1, |
|---|
| 189 |
"6E2" => 1, |
|---|
| 190 |
"6E3" => 1, |
|---|
| 191 |
"6E4" => 1, |
|---|
| 192 |
"6E7" => 1, |
|---|
| 193 |
"6E8" => 1, |
|---|
| 194 |
"6EA" => 1, |
|---|
| 195 |
"6EB" => 1, |
|---|
| 196 |
"6EC" => 1, |
|---|
| 197 |
"6ED" => 1, |
|---|
| 198 |
); |
|---|
| 199 |
|
|---|
| 200 |
@char = split ("", $line); |
|---|
| 201 |
|
|---|
| 202 |
for ($index = 0; $index <= $ |
|---|
| 203 |
{ |
|---|
| 204 |
$cur = unpack("U", $char[$index]); |
|---|
| 205 |
$cur = sprintf "\U%x\E", $cur; |
|---|
| 206 |
if ( $opt_debug ) |
|---|
| 207 |
{ |
|---|
| 208 |
print "---- $index ----\n"; |
|---|
| 209 |
print "NOW - $cur \n"; |
|---|
| 210 |
} |
|---|
| 211 |
if ( defined $map{$cur} ) |
|---|
| 212 |
{ |
|---|
| 213 |
|
|---|
| 214 |
$prev_index = $index; |
|---|
| 215 |
|
|---|
| 216 |
PREV_CHECK: |
|---|
| 217 |
{ |
|---|
| 218 |
$prev_index--; |
|---|
| 219 |
$prev = unpack("U", $char[$prev_index]); |
|---|
| 220 |
$prev = sprintf "\U%x\E", $prev; |
|---|
| 221 |
if ( $opt_debug ) |
|---|
| 222 |
{ |
|---|
| 223 |
print "prev - $prev \n"; |
|---|
| 224 |
} |
|---|
| 225 |
|
|---|
| 226 |
|
|---|
| 227 |
if ( $special_is_composing{$prev} ) |
|---|
| 228 |
{ |
|---|
| 229 |
redo PREV_CHECK; |
|---|
| 230 |
} |
|---|
| 231 |
} |
|---|
| 232 |
|
|---|
| 233 |
if ( |
|---|
| 234 |
($index == 0) || |
|---|
| 235 |
!defined $map{$prev} || |
|---|
| 236 |
(!$map{$prev}[INITIAL] && |
|---|
| 237 |
!$map{$prev}[MEDIAL] |
|---|
| 238 |
) |
|---|
| 239 |
) |
|---|
| 240 |
{ |
|---|
| 241 |
|
|---|
| 242 |
if ( $opt_debug ) |
|---|
| 243 |
{ |
|---|
| 244 |
print "prev not defined \n"; |
|---|
| 245 |
} |
|---|
| 246 |
undef $prev; |
|---|
| 247 |
} |
|---|
| 248 |
|
|---|
| 249 |
|
|---|
| 250 |
$next_index = $index; |
|---|
| 251 |
|
|---|
| 252 |
NEXT_CHECK: |
|---|
| 253 |
{ |
|---|
| 254 |
$next_index++; |
|---|
| 255 |
$next = unpack("U", $char[$next_index]); |
|---|
| 256 |
$next = sprintf "\U%x\E", $next; |
|---|
| 257 |
if ( $opt_debug ) |
|---|
| 258 |
{ |
|---|
| 259 |
print "next - $next \n"; |
|---|
| 260 |
} |
|---|
| 261 |
|
|---|
| 262 |
|
|---|
| 263 |
if ( $special_is_composing{$next} ) |
|---|
| 264 |
{ |
|---|
| 265 |
redo NEXT_CHECK; |
|---|
| 266 |
} |
|---|
| 267 |
} |
|---|
| 268 |
|
|---|
| 269 |
if ( |
|---|
| 270 |
($index == $ |
|---|
| 271 |
!defined $map{$next} || |
|---|
| 272 |
(!$map{$next}[MEDIAL] && |
|---|
| 273 |
!$map{$next}[FINAL] && |
|---|
| 274 |
!$special_is_next{$next} |
|---|
| 275 |
) |
|---|
| 276 |
) |
|---|
| 277 |
{ |
|---|
| 278 |
|
|---|
| 279 |
if ( $opt_debug ) |
|---|
| 280 |
{ |
|---|
| 281 |
print "next not defined \n"; |
|---|
| 282 |
} |
|---|
| 283 |
undef $next; |
|---|
| 284 |
} |
|---|
| 285 |
|
|---|
| 286 |
|
|---|
| 287 |
if ( $special_is_comb1{$cur} ) |
|---|
| 288 |
{ |
|---|
| 289 |
if (defined $next ) |
|---|
| 290 |
{ |
|---|
| 291 |
if ( $special_is_comb2{$next} ) |
|---|
| 292 |
{ |
|---|
| 293 |
$out = ( (defined $prev) ? $map{"$cur$next"}[FINAL] : $map{"$cur$next"}[ISOLATED] ); |
|---|
| 294 |
$str .= pack("U", hex($out)); |
|---|
| 295 |
if ( $opt_debug ) |
|---|
| 296 |
{ |
|---|
| 297 |
print "Got me a complex - use $out ($str)\n"; |
|---|
| 298 |
} |
|---|
| 299 |
$index++; |
|---|
| 300 |
next; |
|---|
| 301 |
} |
|---|
| 302 |
} |
|---|
| 303 |
} |
|---|
| 304 |
|
|---|
| 305 |
|
|---|
| 306 |
if ( (defined $prev) && (defined $next) ) |
|---|
| 307 |
{ |
|---|
| 308 |
|
|---|
| 309 |
if ( $out = $map{$cur}[MEDIAL] ) |
|---|
| 310 |
{ |
|---|
| 311 |
$str .= pack("U", hex($out)); |
|---|
| 312 |
if ( $opt_debug ) |
|---|
| 313 |
{ |
|---|
| 314 |
print "Got prev & next - use $out ($str)\n"; |
|---|
| 315 |
} |
|---|
| 316 |
next; |
|---|
| 317 |
} |
|---|
| 318 |
} |
|---|
| 319 |
|
|---|
| 320 |
|
|---|
| 321 |
if ( (defined $prev) ) |
|---|
| 322 |
{ |
|---|
| 323 |
if ( $out = $map{$cur}[FINAL] ) |
|---|
| 324 |
{ |
|---|
| 325 |
$str .= pack("U", hex($out)); |
|---|
| 326 |
if ( $opt_debug ) |
|---|
| 327 |
{ |
|---|
| 328 |
print "Got prev - use $out ($str)\n"; |
|---|
| 329 |
} |
|---|
| 330 |
next; |
|---|
| 331 |
} |
|---|
| 332 |
} |
|---|
| 333 |
|
|---|
| 334 |
|
|---|
| 335 |
if ( (defined $next) ) |
|---|
| 336 |
{ |
|---|
| 337 |
if ( $out = $map{$cur}[INITIAL] ) |
|---|
| 338 |
{ |
|---|
| 339 |
$str .= pack("U", hex($out)); |
|---|
| 340 |
if ( $opt_debug ) |
|---|
| 341 |
{ |
|---|
| 342 |
print "Got next - use $out ($str)\n"; |
|---|
| 343 |
} |
|---|
| 344 |
next; |
|---|
| 345 |
} |
|---|
| 346 |
} |
|---|
| 347 |
|
|---|
| 348 |
|
|---|
| 349 |
$out = $map{$cur}[ISOLATED]; |
|---|
| 350 |
$str .= pack("U", hex($out)); |
|---|
| 351 |
if ( $opt_debug ) |
|---|
| 352 |
{ |
|---|
| 353 |
print "Got nothing - use $out ($str)\n"; |
|---|
| 354 |
} |
|---|
| 355 |
} |
|---|
| 356 |
else |
|---|
| 357 |
{ |
|---|
| 358 |
$str .= pack("U", hex($cur)); |
|---|
| 359 |
} |
|---|
| 360 |
} |
|---|
| 361 |
|
|---|
| 362 |
if ( $opt_debug ) |
|---|
| 363 |
{ |
|---|
| 364 |
print "return - $str \n"; |
|---|
| 365 |
} |
|---|
| 366 |
return ($str); |
|---|
| 367 |
} |
|---|
| 368 |
|
|---|
| 369 |
|
|---|
| 370 |
|
|---|
| 371 |
sub usage |
|---|
| 372 |
{ |
|---|
| 373 |
my ($die_after) = @_; |
|---|
| 374 |
|
|---|
| 375 |
print "Usage: $this_script <-file filename> [-debug] \n"; |
|---|
| 376 |
if ( $die_after ) { exit(5); } |
|---|
| 377 |
} |
|---|
| 378 |
|
|---|
| 379 |
|
|---|
| 380 |
|
|---|
| 381 |
sub get_args |
|---|
| 382 |
{ |
|---|
| 383 |
&NGetOpt ( |
|---|
| 384 |
"debug" => \$opt_debug, |
|---|
| 385 |
"file=s" => \$opt_file, |
|---|
| 386 |
) || ( $? = 257, die "Invalid argument\n" ); |
|---|
| 387 |
} |
|---|