64 |
## Convert the text UnicodeData file from www.unicode.org into a Java |
## Convert the text UnicodeData file from www.unicode.org into a Java |
65 |
## interface with string constants holding the compressed information. |
## interface with string constants holding the compressed information. |
66 |
## |
## |
67 |
@TYPECODES = qw(Cn Lu Ll Lt Lm Lo Mn Me Mc Nd Nl No Zs Zl Zp Cc Cf |
my @TYPECODES = qw(Cn Lu Ll Lt Lm Lo Mn Me Mc Nd Nl No Zs Zl Zp Cc Cf |
68 |
SKIPPED Co Cs Pd Ps Pe Pc Po Sm Sc Sk So Pi Pf); |
SKIPPED Co Cs Pd Ps Pe Pc Po Sm Sc Sk So Pi Pf); |
69 |
@DIRCODES = qw(L R AL EN ES ET AN CS NSM BN B S WS ON LRE LRO RLE RLO PDF); |
my @DIRCODES = qw(L R AL EN ES ET AN CS NSM BN B S WS ON LRE LRO RLE RLO PDF); |
70 |
|
|
71 |
$NOBREAK_FLAG = 32; |
my $NOBREAK_FLAG = 32; |
72 |
$MIRRORED_FLAG = 64; |
my $MIRRORED_FLAG = 64; |
73 |
|
|
74 |
my @info = (); |
my @info = (); |
75 |
my $titlecase = ""; |
my $titlecase = ""; |
161 |
my %charhash = (); |
my %charhash = (); |
162 |
my @charinfo = (); |
my @charinfo = (); |
163 |
|
|
164 |
for $ch (0 .. 0xffff) { |
for my $ch (0 .. 0xffff) { |
165 |
print "." unless $count++ % 0x1000; |
print "." unless $count++ % 0x1000; |
166 |
if (! defined $info[$ch]) { |
if (! defined $info[$ch]) { |
167 |
$info[$ch] = pack("n5", 0, -1, 0, 0, -1); |
$info[$ch] = pack("n5", 0, -1, 0, 0, -1); |
179 |
my $bestshift; |
my $bestshift; |
180 |
my $bestest = 1000000; |
my $bestest = 1000000; |
181 |
my $bestblkstr; |
my $bestblkstr; |
182 |
die "Too many unique character entrie: $charlen\n" if $charlen > 512; |
die "Too many unique character entries: $charlen\n" if $charlen > 512; |
183 |
print "\nUnique character entries: $charlen\n"; |
print "\nUnique character entries: $charlen\n"; |
184 |
|
|
185 |
for $i (3 .. 8) { |
for my $i (3 .. 8) { |
186 |
my $blksize = 1 << $i; |
my $blksize = 1 << $i; |
187 |
my %blocks = (); |
my %blocks = (); |
188 |
my @blkarray = (); |
my @blkarray = (); |
265 |
} |
} |
266 |
|
|
267 |
die "Unexpected $blocklen" if length($blockstr) != 2 * $blocklen; |
die "Unexpected $blocklen" if length($blockstr) != 2 * $blocklen; |
268 |
my $estimate = 2 * $blocklen + (0x20000 >> $i) + 8 * $charlen; |
my $estimate = 2 * $blocklen + (0x20000 >> $i); |
269 |
|
|
270 |
printf " after merge %5d: %6d bytes\n", $blocklen, $estimate; |
printf " after merge %5d: %6d bytes\n", $blocklen, $estimate; |
271 |
if ($estimate < $bestest) { |
if ($estimate < $bestest) { |
277 |
|
|
278 |
my @blocks; |
my @blocks; |
279 |
my $blksize = 1 << $bestshift; |
my $blksize = 1 << $bestshift; |
280 |
for ($j = 0; $j < 0x10000; $j += $blksize) { |
for (my $j = 0; $j < 0x10000; $j += $blksize) { |
281 |
my $blkkey = substr $info, 2 * $j, 2 * $blksize; |
my $blkkey = substr $info, 2 * $j, 2 * $blksize; |
282 |
my $index = index $bestblkstr, $blkkey; |
my $index = index $bestblkstr, $blkkey; |
283 |
while ($index & 1) { |
while ($index & 1) { |
284 |
die "not found: $j" if $index == -1; |
die "not found: $j" if $index == -1; |
285 |
$index = index $bestblkstr, $blkkey, $index + 1; |
$index = index $bestblkstr, $blkkey, $index + 1; |
286 |
} |
} |
287 |
push @blocks, ($index / 2); |
push @blocks, ($index / 2 - $j) & 0xffff; |
288 |
} |
} |
289 |
|
|
290 |
# Phase 3: Generate the file |
# Phase 3: Generate the file |
294 |
if length($bestblkstr) > 0xffff / 3; |
if length($bestblkstr) > 0xffff / 3; |
295 |
{ |
{ |
296 |
print "Generating $ARGV[1] with shift of $bestshift"; |
print "Generating $ARGV[1] with shift of $bestshift"; |
297 |
|
my ($i, $j); |
298 |
|
|
299 |
open OUTPUT, "> $ARGV[1]" or die "Failed creating output file: $!\n"; |
open OUTPUT, "> $ARGV[1]" or die "Failed creating output file: $!\n"; |
300 |
print OUTPUT <<EOF; |
print OUTPUT <<EOF; |
301 |
/* gnu/java/lang/CharData -- Database for java.lang.Character Unicode info |
/* gnu/java/lang/CharData -- Database for java.lang.Character Unicode info |
364 |
public interface CharData |
public interface CharData |
365 |
{ |
{ |
366 |
/** |
/** |
367 |
* The character shift amount to look up the block offset. In other |
* The character shift amount to look up the block offset. In other words, |
368 |
* words, <code>BLOCKS.value[ch >> SHIFT] + (ch & ~(-1 << SHIFT))</code> |
* <code>(char) (BLOCKS.value[ch >> SHIFT] + ch)</code> is the index where |
369 |
* is the index where <code>ch</code> is described in <code>DATA</code>. |
* <code>ch</code> is described in <code>DATA</code>. |
370 |
*/ |
*/ |
371 |
int SHIFT = $bestshift; |
int SHIFT = $bestshift; |
372 |
|
|
373 |
/** |
/** |
374 |
* The mapping of character blocks to their location in <code>DATA</code>. |
* The mapping of character blocks to their location in <code>DATA</code>. |
375 |
|
* Each entry has been adjusted so that the 16-bit sum with the desired |
376 |
|
* character gives the actual index into <code>DATA</code>. |
377 |
*/ |
*/ |
378 |
String BLOCKS |
String BLOCKS |
379 |
EOF |
EOF |