| 1 |
#!/usr/bin/perl |
| 2 |
# $Id: mes-list-expand.pl,v 1.1 2009-12-27 16:25:15 Stevan_White Exp $ |
| 3 |
# |
| 4 |
# Expand MES ranges, as available in CEN documents, into simple list |
| 5 |
# of character codes. |
| 6 |
|
| 7 |
# Unicode table |
| 8 |
$tblfile = "/usr/local/share/unicode/UnicodeData-Latest.txt"; |
| 9 |
# Array size |
| 10 |
$#table = 65535; |
| 11 |
|
| 12 |
# Read in complete Unicode table for the named entities |
| 13 |
open(TABLE, "<$tblfile") || die "Cannot find $tblfile\n"; |
| 14 |
while (<TABLE>) { |
| 15 |
($code,$name) = split(/[;\n]/, $_, 9999); |
| 16 |
$table[hex($code)] = $name; |
| 17 |
} |
| 18 |
close(TABLE); |
| 19 |
|
| 20 |
if ($#ARGV >= 0) { |
| 21 |
open(RANGE, $ARGV[0]); |
| 22 |
} else { |
| 23 |
open(RANGE, "<stdin"); |
| 24 |
} |
| 25 |
while (<RANGE>) { |
| 26 |
if (/^\#.*/) { |
| 27 |
next; |
| 28 |
} else { |
| 29 |
($page,$codes) = split(/[\t]/, $_, 9999); |
| 30 |
chomp $codes; |
| 31 |
@range = split(/ /, $codes, 9999); |
| 32 |
for ($i = 0; $i <= $#range; $i++) { |
| 33 |
if (length($range[$i]) == 2) { |
| 34 |
$code = 256*hex($page) + hex($range[$i]); |
| 35 |
printf("%04X:%s\n", $code, $table[$code]); |
| 36 |
} else { |
| 37 |
($lower,$upper) = split(/-/, $range[$i], 9999); |
| 38 |
for ($j = hex($lower); $j <= hex($upper); $j++) { |
| 39 |
$code = 256*hex($page) + $j; |
| 40 |
printf("%04X:%s\n", $code, $table[$code]); |
| 41 |
} |
| 42 |
} |
| 43 |
} |
| 44 |
} |
| 45 |
} |