summaryrefslogtreecommitdiff
path: root/sal/textenc/generate/big5hkscs2001.pl
blob: a363e99f7e877c10a828e04cc58ee96794c173fc (plain)
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
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
#!/usr/bin/perl
#*************************************************************************
#
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
#
# Copyright 2000, 2010 Oracle and/or its affiliates.
#
# OpenOffice.org - a multi-platform office productivity suite
#
# This file is part of OpenOffice.org.
#
# OpenOffice.org is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License version 3
# only, as published by the Free Software Foundation.
#
# OpenOffice.org is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Lesser General Public License version 3 for more details
# (a copy is included in the LICENSE file that accompanied this code).
#
# You should have received a copy of the GNU Lesser General Public License
# version 3 along with OpenOffice.org.  If not, see
# <http://www.openoffice.org/license.html>
# for a copy of the LGPLv3 License.
#
#*************************************************************************

# The following files must be available in a ./input subdir:

# <http://www.info.gov.hk/digital21/eng/hkscs/download/big5-iso.txt>

# <http://www.unicode.org/Public/MAPPINGS/OBSOLETE/EASTASIA/OTHER/BIG5.TXT>:
#  "Unicode version: 1.1    Table version: 0.0d3    Date: 11 February 1994"
#  Only used to track Unicode characters that are mapped from both Big5 and
#  HKSCS.

# <http://www.unicode.org/Public/MAPPINGS/VENDORS/MICSFT/WINDOWS/CP950.TXT>:
#  "Unicode version: 2.0    Table version: 2.01    Date: 1/7/2000"
#  Only used to track Unicode characters that are mapped from both CP950 and
#  HKSCS.

$surrogates = 0; # set to 1 to allow mappings to Unicode beyond Plane 0

$id = "Big5Hkscs2001";

sub isValidUtf32
{
    my $utf32 = $_[0];
    return $utf32 >= 0 && $utf32 <= 0x10FFFF
           && !($utf32 >= 0xD800 && $utf32 <= 0xDFFF)
           && !($utf32 >= 0xFDD0 && $utf32 <= 0xFDEF)
           && ($utf32 & 0xFFFF) < 0xFFFE;
}

sub printUtf32
{
    my $utf32 = $_[0];
    return sprintf("U+%04X", $utf32);
}

sub isValidBig5
{
    my $big5 = $_[0];
    my $big5_row = $big5 >> 8;
    my $big5_column = $big5 & 0xFF;
    return $big5_row >= 0x81 && $big5_row <= 0xFE
           && ($big5_column >= 0x40 && $big5_column <= 0x7E
               || $big5_column >= 0xA1 && $big5_column <= 0xFE);
}

sub printBig5
{
    my $big5 = $_[0];
    return sprintf("%04X", $big5);
}

sub printStats
{
    my $used = $_[0];
    my $space = $_[1];
    return sprintf("%d/%d bytes (%.1f%%)",
                   $used,
                   $space,
                   $used * 100 / $space);
}

sub printSpaces
{
    my $column_width = $_[0];
    my $columns_per_line = $_[1];
    my $end = $_[2];
    $output = "";
    for ($i = int($end / $columns_per_line) * $columns_per_line;
         $i < $end;
         ++$i)
    {
        for ($j = 0; $j < $column_width; ++$j)
        {
            $output = $output . " ";
        }
    }
    return $output;
}

sub addMapping
{
    my $utf32 = $_[0];
    my $big5 = $_[1];
    my $comp = $_[2];

    $uni_plane = $utf32 >> 16;
    $uni_page = ($utf32 >> 8) & 0xFF;
    $uni_index = $utf32 & 0xFF;

    if (!defined($uni_plane_used[$uni_plane])
        || !defined($uni_page_used[$uni_plane][$uni_page])
        || !defined($uni_map[$uni_plane][$uni_page][$uni_index]))
    {
        $uni_map[$uni_plane][$uni_page][$uni_index] = $big5;
        $uni_plane_used[$uni_plane] = 1;
        $uni_page_used[$uni_plane][$uni_page] = 1;
        if ($comp != -1)
        {
            ++$compat[$comp];
        }
    }
    else
    {
        $big5_1 = $uni_map[$uni_plane][$uni_page][$uni_index];
        print "WARNING!  Mapping ", printUtf32($utf32), " to ",
              printBig5($big5_1), ", NOT ", ($comp ? "compat " : ""),
              printBig5($big5), "\n";
    }
}

# Build mappings to track Unicode characters that are mapped from both Big5/
# CP950 and HKSCS:
{
    $filename = "BIG5.TXT";
    open IN, ("input/" . $filename) or die "Cannot read " . $filename;
    while (<IN>)
    {
        if (/(0x[0-9A-F][0-9A-F][0-9A-F][0-9A-F])[ \t]+(0x[0-9A-F]+)[ \t]+\#.*$/)
        {
            $big5 = oct($1);
            $utf32 = oct($2);
            isValidBig5($big5)
                or die "Bad Big5 char " . printBig5($big5);
            isValidUtf32($utf32)
                or die "Bad UTF32 char " . printUtf32($utf32);
            if ($utf32 != 0xFFFD)
            {
                if (defined($underlying_big5[$utf32]))
                {
                    print "WARNING!  In ", $filename, ", both ",
                          printBig5($underlying_big5[$utf32]), " and ",
                          printBig5($big5), " map to ", printUtf32($utf32),
                          "\n";
                }
                else
                {
                    $underlying_big5[$utf32] = $big5;
                }
            }
        }
    }
    close IN;

    $filename = "CP950.TXT";
    open IN, ("input/" . $filename) or die "Cannot read " . $filename;
    while (<IN>)
    {
        if (/(0x[0-9A-F][0-9A-F][0-9A-F][0-9A-F])[ \t]+(0x[0-9A-F]+)[ \t]+\#.*$/)
        {
            $big5 = oct($1);
            $utf32 = oct($2);
            isValidBig5($big5)
                or die "Bad Big5 char " . printBig5($big5);
            isValidUtf32($utf32)
                or die "Bad UTF32 char " . printUtf32($utf32);
            if (defined($underlying_cp950[$utf32]))
            {
                print "WARNING!  In ", $filename, ", both ",
                      printBig5($underlying_cp950[$utf32]), " and ",
                      printBig5($big5), " map to ", printUtf32($utf32), "\n";
            }
            else
            {
                $underlying_cp950[$utf32] = $big5;
            }
        }
    }
    close IN;
}

# The following are mapped by the underlying RTL_TEXTENCODING_BIG5 to some
# nonstandard Unicode points, so they are explicitly mentioned here to map
# to the standard Unicode PUA points.  (In the other direction, the unofficial
# mappings from Unicode to RTL_TEXTENCODING_BIG5 C6A1--C7FE are harmless,
# since all Unicode characters involved are already covered by the official
# Big5-HKSCS mappings.)
$big5_map[0xC6][0xCF] = 0xF6E0; addMapping(0xF6E0, 0xC6CF, -1);
$big5_map[0xC6][0xD3] = 0xF6E4; addMapping(0xF6E4, 0xC6D3, -1);
$big5_map[0xC6][0xD5] = 0xF6E6; addMapping(0xF6E6, 0xC6D5, -1);
$big5_map[0xC6][0xD7] = 0xF6E8; addMapping(0xF6E8, 0xC6D7, -1);
$big5_map[0xC6][0xDE] = 0xF6EF; addMapping(0xF6EF, 0xC6DE, -1);
$big5_map[0xC6][0xDF] = 0xF6F0; addMapping(0xF6F0, 0xC6DF, -1);

# The following implements the mapping of Big5-HKSCS compatibility points
# (GCCS characters unified with other HKSCS characters) to Unicode.  In the
# other direction, characters from Unicode's PUA will map to these Big5-HKSCS
# compatibility points.  (See the first list in <http://www.info.gov.hk/
# digital21/eng/hkscs/download/big5cmp.txt>.)
$big5_map[0x8E][0x69] = 0x7BB8;
$big5_map[0x8E][0x6F] = 0x7C06;
$big5_map[0x8E][0x7E] = 0x7CCE;
$big5_map[0x8E][0xAB] = 0x7DD2;
$big5_map[0x8E][0xB4] = 0x7E1D;
$big5_map[0x8E][0xCD] = 0x8005;
$big5_map[0x8E][0xD0] = 0x8028;
$big5_map[0x8F][0x57] = 0x83C1;
$big5_map[0x8F][0x69] = 0x84A8;
$big5_map[0x8F][0x6E] = 0x840F;
$big5_map[0x8F][0xCB] = 0x89A6;
$big5_map[0x8F][0xCC] = 0x89A9;
$big5_map[0x8F][0xFE] = 0x8D77;
$big5_map[0x90][0x6D] = 0x90FD;
$big5_map[0x90][0x7A] = 0x92B9;
$big5_map[0x90][0xDC] = 0x975C;
$big5_map[0x90][0xF1] = 0x97FF;
$big5_map[0x91][0xBF] = 0x9F16;
$big5_map[0x92][0x44] = 0x8503;
$big5_map[0x92][0xAF] = 0x5159;
$big5_map[0x92][0xB0] = 0x515B;
$big5_map[0x92][0xB1] = 0x515D;
$big5_map[0x92][0xB2] = 0x515E;
$big5_map[0x92][0xC8] = 0x936E;
$big5_map[0x92][0xD1] = 0x7479;
$big5_map[0x94][0x47] = 0x6D67;
$big5_map[0x94][0xCA] = 0x799B;
$big5_map[0x95][0xD9] = 0x9097;
$big5_map[0x96][0x44] = 0x975D;
$big5_map[0x96][0xED] = 0x701E;
$big5_map[0x96][0xFC] = 0x5B28;
$big5_map[0x9B][0x76] = 0x7201;
$big5_map[0x9B][0x78] = 0x77D7;
$big5_map[0x9B][0x7B] = 0x7E87;
$big5_map[0x9B][0xC6] = 0x99D6;
$big5_map[0x9B][0xDE] = 0x91D4;
$big5_map[0x9B][0xEC] = 0x60DE;
$big5_map[0x9B][0xF6] = 0x6FB6;
$big5_map[0x9C][0x42] = 0x8F36;
$big5_map[0x9C][0x53] = 0x4FBB;
$big5_map[0x9C][0x62] = 0x71DF;
$big5_map[0x9C][0x68] = 0x9104;
$big5_map[0x9C][0x6B] = 0x9DF0;
$big5_map[0x9C][0x77] = 0x83CF;
$big5_map[0x9C][0xBC] = 0x5C10;
$big5_map[0x9C][0xBD] = 0x79E3;
$big5_map[0x9C][0xD0] = 0x5A67;
$big5_map[0x9D][0x57] = 0x8F0B;
$big5_map[0x9D][0x5A] = 0x7B51;
$big5_map[0x9D][0xC4] = 0x62D0;
$big5_map[0x9E][0xA9] = 0x6062;
$big5_map[0x9E][0xEF] = 0x75F9;
$big5_map[0x9E][0xFD] = 0x6C4A;
$big5_map[0x9F][0x60] = 0x9B2E;
$big5_map[0x9F][0x66] = 0x9F17;
$big5_map[0x9F][0xCB] = 0x50ED;
$big5_map[0x9F][0xD8] = 0x5F0C;
$big5_map[0xA0][0x63] = 0x880F;
$big5_map[0xA0][0x77] = 0x62CE;
$big5_map[0xA0][0xD5] = 0x7468;
$big5_map[0xA0][0xDF] = 0x7162;
$big5_map[0xA0][0xE4] = 0x7250;
$big5_map[0xFA][0x5F] = 0x5029;
$big5_map[0xFA][0x66] = 0x507D;
$big5_map[0xFA][0xBD] = 0x5305;
$big5_map[0xFA][0xC5] = 0x5344;
$big5_map[0xFA][0xD5] = 0x537F;
$big5_map[0xFB][0x48] = 0x5605;
$big5_map[0xFB][0xB8] = 0x5A77;
$big5_map[0xFB][0xF3] = 0x5E75;
$big5_map[0xFB][0xF9] = 0x5ED0;
$big5_map[0xFC][0x4F] = 0x5F58;
$big5_map[0xFC][0x6C] = 0x60A4;
$big5_map[0xFC][0xB9] = 0x6490;
$big5_map[0xFC][0xE2] = 0x6674;
$big5_map[0xFC][0xF1] = 0x675E;
$big5_map[0xFD][0xB7] = 0x6C9C;
$big5_map[0xFD][0xB8] = 0x6E1D;
$big5_map[0xFD][0xBB] = 0x6E2F;
$big5_map[0xFD][0xF1] = 0x716E;
$big5_map[0xFE][0x52] = 0x732A;
$big5_map[0xFE][0x6F] = 0x745C;
$big5_map[0xFE][0xAA] = 0x74E9;
$big5_map[0xFE][0xDD] = 0x7809;

$pua = 0;
$compat[0] = 0; # 1993
$compat[1] = 0; # 2000
$compat[2] = 0; # 2001

$filename = "big5-iso.txt";
open IN, ("input/" . $filename) or die "Cannot read " . $filename;
while (<IN>)
{
    if (/^([0-9A-F]+) +([0-9A-F]+) +([0-9A-F]+) +([0-9A-F]+)$/)
    {
        $big5 = oct("0x" . $1);
        $utf32_1993 = oct("0x" . $2);
        $utf32_2000 = oct("0x" . $3);
        $utf32_2001 = oct("0x" . $4);
        isValidBig5($big5)
            or die "Bad Big5 char " . printBig5($big5);
        isValidUtf32($utf32_1993)
            or die "Bad UTF32 char " . printUtf32($utf32_1993);
        isValidUtf32($utf32_2000)
            or die "Bad UTF32 char " . printUtf32($utf32_2000);
        isValidUtf32($utf32_2001)
            or die "Bad UTF32 char " . printUtf32($utf32_2001);

        $utf32 = $surrogates ? $utf32_2001 : $utf32_2000;

        if (defined($underlying_big5[$utf32])
            || defined($underlying_cp950[$utf32]))
        {
            if (defined($underlying_big5[$utf32])
                && defined($underlying_cp950[$utf32])
                && $underlying_big5[$utf32] == $underlying_cp950[$utf32]
                && $underlying_big5[$utf32] == $big5
                ||
                defined($underlying_big5[$utf32])
                && !defined($underlying_cp950[$utf32])
                && $underlying_big5[$utf32] == $big5
                ||
                !defined($underlying_big5[$utf32])
                && defined($underlying_cp950[$utf32])
                && $underlying_cp950[$utf32] == $big5)
            {
                # ignore

                # Depending on real underlying mapping (cf.
                # ../convertbig5hkscs.tab), it would be possible to save some
                # table space by dropping those HKSCS code points that are
                # already covered by the underlying mapping.
            }
            else
            {
                print "XXX mapping underlying";
                if (defined($underlying_big5[$utf32])
                    && defined($underlying_cp950[$utf32])
                    && $underlying_big5[$utf32] == $underlying_cp950[$utf32])
                {
                    print " Big5/CP950 ", printBig5($underlying_big5[$utf32]);
                }
                else
                {
                    if (defined($underlying_big5[$utf32]))
                    {
                        print " Big5 ", printBig5($underlying_big5[$utf32]);
                    }
                    if (defined($underlying_cp950[$utf32]))
                    {
                        print " CP950 ", printBig5($underlying_cp950[$utf32]);
                    }
                }
                print " and HKSCS ", printBig5($big5), " to ",
                      printUtf32($utf32), "\n";
            }
        }

        if ($utf32 >= 0xE000 && $utf32 <= 0xF8FF)
        {
            ++$pua;
        }

        $big5_row = $big5 >> 8;
        $big5_column = $big5 & 0xFF;
        if (defined($big5_map[$big5_row][$big5_column]))
        {
            die "Bad Big5 mapping " . printBig5($big5);
        }
        $big5_map[$big5_row][$big5_column] = $utf32;

        addMapping($utf32, $big5, -1);

        if ($utf32_2001 != $utf32)
        {
            addMapping($utf32_2001, $big5, 2);
        }
        if ($utf32_2000 != $utf32 && $utf32_2000 != $utf32_2001)
        {
            addMapping($utf32_2000, $big5, 1);
        }
        if ($utf32_1993 != $utf32 && $utf32_1993 != $utf32_2000
            && $utf32_1993 != $utf32_2001)
        {
            addMapping($utf32_1993, $big5, 0);
        }
    }
}
close IN;

print $pua, " mappings to PUA\n";
print $compat[0], " 1993 compatibility mappings\n" if ($compat[0] != 0);
print $compat[1], " 2000 compatibility mappings\n" if ($compat[1] != 0);
print $compat[2], " 2001 compatibility mappings\n" if ($compat[2] != 0);

if (defined($uni_plane_used[0]) && defined($uni_page_used[0][0]))
{
    for ($utf32 = 0; $utf32 <= 0x7F; ++$utf32)
    {
        if (defined($uni_map[0][0][$uni_index]))
        {
            $big5 = $uni_map[0][0][$utf32];
            die "Mapping " . printUtf32($utf32) . " to " . printBig5($big5);
        }
    }
}

$filename = lc($id) . ".tab";
open OUT, ("> " . $filename) or die "Cannot write " . $filename;

{
    $filename = lc($id). ".pl";
    open IN, $filename or die "Cannot read ". $filename;
    $first = 1;
    while (<IN>)
    {
        if (/^\#!.*$/)
        {
        }
        elsif (/^\#(\*.*)$/)
        {
            if ($first == 1)
            {
                print OUT "/", $1, "\n";
                $first = 0;
            }
            else
            {
                print OUT " ", substr($1, 0, length($1) - 1), "/\n";
            }
        }
        elsif (/^\# (.*)$/)
        {
            print OUT " *", $1, "\n";
        }
        elsif (/^\#(.*)$/)
        {
            print OUT " *", $1, "\n";
        }
        else
        {
            goto done;
        }
    }
  done:
}

print OUT "\n",
          "#ifndef _SAL_TYPES_H_\n",
          "#include \"sal/types.h\"\n",
          "#endif\n",
          "\n";

print OUT "static sal_uInt16 const aImpl", $id, "ToUnicodeData[] = {\n";
$big5_data_index = 0;
$big5_rows = 0;
$big5_chars = 0;
for ($big5_row = 0; $big5_row <= 255; ++$big5_row)
{
    $big5_row_first = -1;
    for ($big5_column = 0; $big5_column <= 255; ++$big5_column)
    {
        if (defined($big5_map[$big5_row][$big5_column]))
        {
            if ($big5_row_first == -1)
            {
                $big5_row_first = $big5_column;
            }
            $big5_row_last = $big5_column;
        }
    }
    if ($big5_row_first != -1)
    {
        $big5_data_offsets[$big5_row] = $big5_data_index;
        ++$big5_rows;
        print OUT " /* row ", $big5_row, " */\n";

        $big5_row_surrogates_first = -1;
        $big5_row_chars = 0;
        $big5_row_surrogates = 0;

        print OUT "  ", $big5_row_first, " | (", $big5_row_last,
                  " << 8), /* first, last */\n";
        ++$big5_data_index;

        print OUT "  ", printSpaces(7, 10, $big5_row_first);
        $bol = 0;
        for ($big5_column = $big5_row_first;
             $big5_column <= $big5_row_last;
             ++$big5_column)
        {
            if ($bol == 1)
            {
                print OUT "  ";
                $bol = 0;
            }
            if (defined($big5_map[$big5_row][$big5_column]))
            {
                $utf32 = $big5_map[$big5_row][$big5_column];
                ++$big5_row_chars;
                if ($utf32 <= 0xFFFF)
                {
                    printf OUT "0x%04X,", $utf32;
                }
                else
                {
                    ++$big5_row_surrogates;
                    printf OUT "0x%04X,",
                               (0xD800 | (($utf32 - 0x10000) >> 10));
                    if ($big5_row_surrogates_first == -1)
                    {
                        $big5_row_surrogates_first = $big5_column;
                    }
                    $big5_row_surrogates_last = $big5_column;
                }
            }
            else
            {
                printf OUT "0xffff,";
            }
            ++$big5_data_index;
            if ($big5_column % 10 == 9)
            {
                print OUT "\n";
                $bol = 1;
            }
        }
        if ($bol == 0)
        {
            print OUT "\n";
        }

        if ($big5_row_surrogates_first != -1)
        {
            print OUT "  ", $big5_row_surrogates_first,
                      ", /* first low-surrogate */\n";
            ++$big5_data_index;

            print OUT "  ", printSpaces(7, 10, $big5_row_surrogates_first);
            $bol = 0;
            for ($big5_column = $big5_row_surrogates_first;
                 $big5_column <= $big5_row_surrogates_last;
                 ++$big5_column)
            {
                if ($bol == 1)
                {
                    print OUT "  ";
                    $bol = 0;
                }
                $utf32 = 0;
                if (defined($big5_map[$big5_row][$big5_column]))
                {
                    $utf32 = $big5_map[$big5_row][$big5_column];
                }
                if ($utf32 <= 0xFFFF)
                {
                    printf OUT "     0,";
                }
                else
                {
                    printf OUT "0x%04X,",
                               (0xDC00 | (($utf32 - 0x10000) & 0x3FF));
                }
                ++$big5_data_index;
                if ($big5_column % 10 == 9)
                {
                    print OUT "\n";
                    $bol = 1;
                }
            }
            if ($bol == 0)
            {
                print OUT "\n";
            }
        }

        $big5_chars += $big5_row_chars;
        $big5_data_space[$big5_row]
            = ($big5_data_index - $big5_data_offsets[$big5_row]) * 2;
        $big5_data_used[$big5_row]
            = (1 + $big5_row_chars + ($big5_row_surrogates == 0 ?
                                          0 : 1 + $big5_row_surrogates))
                  * 2;
    }
    else
    {
        print OUT " /* row ", $big5_row, ": --- */\n";
        $big5_data_offsets[$big5_row] = -1;
    }
}
print OUT "};\n\n";
print "big5 rows = ", $big5_rows, ", chars = ", $big5_chars, "\n";

print OUT "static sal_Int32 const aImpl", $id, "ToUnicodeRowOffsets[] = {\n";
$big5_rowoffsets_used = 0;
for ($big5_row = 0; $big5_row <= 255; ++$big5_row)
{
    if ($big5_data_offsets[$big5_row] == -1)
    {
        print OUT "  -1, /* row ", $big5_row, " */\n";
    }
    else
    {
        print OUT "  ",
                  $big5_data_offsets[$big5_row],
                  ", /* row ",
                  $big5_row,
                  "; ",
                  printStats($big5_data_used[$big5_row],
                             $big5_data_space[$big5_row]),
                  " */\n";
        $big5_rowoffsets_used += 4;
    }
}
print OUT "};\n\n";

print OUT "static sal_uInt16 const aImplUnicodeTo", $id, "Data[] = {\n";
$uni_data_index = 0;
for ($uni_plane = 0; $uni_plane <= 16; ++$uni_plane)
{
    if (defined($uni_plane_used[$uni_plane]))
    {
        for ($uni_page = 0; $uni_page <= 255; ++$uni_page)
        {
            if (defined($uni_page_used[$uni_plane][$uni_page]))
            {
                $uni_data_offsets[$uni_plane][$uni_page] = $uni_data_index;
                print OUT " /* plane ", $uni_plane, ", page ", $uni_page,
                          " */\n";

                $uni_page_first = -1;
                for ($uni_index = 0; $uni_index <= 255; ++$uni_index)
                {
                    if (defined($uni_map[$uni_plane][$uni_page][$uni_index]))
                    {
                        if ($uni_page_first == -1)
                        {
                            $uni_page_first = $uni_index;
                        }
                        $uni_page_last = $uni_index;
                    }
                }

                $uni_data_used[$uni_plane][$uni_page] = 0;

                print OUT "  ", $uni_page_first, " | (", $uni_page_last,
                          " << 8), /* first, last */\n";
                ++$uni_data_index;
                $uni_data_used[$uni_plane][$uni_page] += 2;

                print OUT "  ", printSpaces(7, 10, $uni_page_first);
                $bol = 0;
                for ($uni_index = $uni_page_first;
                     $uni_index <= $uni_page_last;
                     ++$uni_index)
                {
                    if ($bol == 1)
                    {
                        print OUT "  ";
                        $bol = 0;
                    }
                    if (defined($uni_map[$uni_plane][$uni_page][$uni_index]))
                    {
                        $big5 = $uni_map[$uni_plane][$uni_page][$uni_index];
                        printf OUT "0x%04X,", $big5;
                        $uni_data_used[$uni_plane][$uni_page] += 2;
                    }
                    else
                    {
                        print OUT "     0,";
                    }
                    ++$uni_data_index;
                    if ($uni_index % 10 == 9)
                    {
                        print OUT "\n";
                        $bol = 1;
                    }
                }
                if ($bol == 0)
                {
                    print OUT "\n";
                }

                $uni_data_space[$uni_plane][$uni_page]
                    = ($uni_data_index
                       - $uni_data_offsets[$uni_plane][$uni_page]) * 2;
            }
            else
            {
                $uni_data_offsets[$uni_plane][$uni_page] = -1;
                print OUT " /* plane ", $uni_plane, ", page ", $uni_page,
                          ": --- */\n";
            }
        }
    }
    else
    {
        print OUT " /* plane ", $uni_plane, ": --- */\n";
    }
}
print OUT "};\n\n";

print OUT "static sal_Int32 const aImplUnicodeTo", $id, "PageOffsets[] = {\n";
for ($uni_plane = 0; $uni_plane <= 16; ++$uni_plane)
{
    if (defined($uni_plane_used[$uni_plane]))
    {
        $uni_pageoffsets_used[$uni_plane] = 0;
        $uni_data_used_sum[$uni_plane] = 0;
        $uni_data_space_sum[$uni_plane] = 0;
        for ($uni_page = 0; $uni_page <= 255; ++$uni_page)
        {
            $offset = $uni_data_offsets[$uni_plane][$uni_page];
            if ($offset == -1)
            {
                print OUT "  -1, /* plane ",
                          $uni_plane,
                          ", page ",
                          $uni_page,
                          " */\n";
            }
            else
            {
                print OUT "  ",
                          $offset,
                          ", /* plane ",
                          $uni_plane,
                          ", page ",
                          $uni_page,
                          "; ",
                          printStats($uni_data_used[$uni_plane][$uni_page],
                                     $uni_data_space[$uni_plane][$uni_page]),
                          " */\n";
                $uni_pageoffsets_used[$uni_plane] += 4;
                $uni_data_used_sum[$uni_plane]
                    += $uni_data_used[$uni_plane][$uni_page];
                $uni_data_space_sum[$uni_plane]
                    += $uni_data_space[$uni_plane][$uni_page];
            }
        }
    }
    else
    {
        print OUT "  /* plane ", $uni_plane, ": --- */\n";
    }
}
print OUT "};\n\n";

print OUT "static sal_Int32 const aImplUnicodeTo",
          $id,
          "PlaneOffsets[] = {\n";
$uni_page_offset = 0;
$uni_planeoffsets_used = 0;
$uni_pageoffsets_used_sum = 0;
$uni_pageoffsets_space_sum = 0;
$uni_data_used_sum2 = 0;
$uni_data_space_sum2 = 0;
for ($uni_plane = 0; $uni_plane <= 16; ++$uni_plane)
{
    if (defined ($uni_plane_used[$uni_plane]))
    {
        print OUT "  ",
                  $uni_page_offset++,
                  " * 256, /* plane ",
                  $uni_plane,
                  "; ",
                  printStats($uni_pageoffsets_used[$uni_plane], 256 * 4),
                  ", ",
                  printStats($uni_data_used_sum[$uni_plane],
                             $uni_data_space_sum[$uni_plane]),
                  " */\n";
        $uni_planeoffsets_used += 4;
        $uni_pageoffsets_used_sum += $uni_pageoffsets_used[$uni_plane];
        $uni_pageoffsets_space_sum += 256 * 4;
        $uni_data_used_sum2 += $uni_data_used_sum[$uni_plane];
        $uni_data_space_sum2 += $uni_data_space_sum[$uni_plane];
    }
    else
    {
        print OUT "  -1, /* plane ", $uni_plane, " */\n";
    }
}
print OUT " /* ",
          printStats($uni_planeoffsets_used, 17 * 4),
          ", ",
          printStats($uni_pageoffsets_used_sum, $uni_pageoffsets_space_sum),
          ", ",
          printStats($uni_data_used_sum2, $uni_data_space_sum2),
          " */\n};\n";

close OUT;