summaryrefslogtreecommitdiffstats
path: root/unicode/mkbidiclass.pl
blob: 5c902a746d7b269d461a975f5f014c89426e1dde (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
#! /usr/bin/perl
#
# Compile DerivedBidiClass.txt into C array declarations.
#
# The array's structure is [firstchar, lastchar, class], giving the
# Bidi Class for unicode character range firstchar-lastchar.
#
# The ranges are sorted in numerical order.
#
# An array gets generated for each block of 4096 unicode characters.
#
# Finally, two arrays get declared: a pointer to an array for each 4096
# unicode character block, and the number of elements in the array.

use strict;
use warnings;
use mkcommon;

my $obj=mkcommon->new;

open(F, "<DerivedBidiClass.txt") || die;

my @table;

while (defined($_=<F>))
{
    chomp;

    next unless /^([0-9A-F]+)(\.\.([0-9A-F]+))?\s*\;\s*([^\s#]+)\s*/;

    my $f=$1;
    my $l=$3;
    my $t=$4;

    $l=$f unless $l;

    eval "\$f=0x$f";
    eval "\$l=0x$l";

    push @table, [$f, $l, $t];
}

#my $prevl = -1;

grep {
    #if ($prevl + 1 < $$_[0])
    #{
    #	$obj->range($prevl+1, $$_[0]-1, "UNICODE_BIDI_TYPE_$$_[2]");
    #}
    #$prevl = $$_[1];
    $obj->range($$_[0], $$_[1], "UNICODE_BIDI_TYPE_$$_[2]");
} sort { $$a[0] <=> $$b[0] } @table;

$obj->output;