summaryrefslogtreecommitdiffstats
path: root/unicode/mkbidi.pl
blob: 2e07fb5e0745683c49737fed7074bc6449b83584 (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
#! /usr/bin/perl
#
# Compile BidiBrackets.txt or BidiMirroring.txt into C array declarations.
#
# The array's structure is [firstchar, lastchar, property (BidiBrackets)]

use strict;
use warnings;

open(F, "<" . shift) || die;

my $extra = shift;

my $lastv;

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

    s/#.*//;

    my @w = split(/;/);

    s/^\s+// for @w;

    s/\s+$// for @w;

    next unless (scalar @w) >= 2;

    my ($code_point, $other_code_point, $other) = @w;

    eval "\$code_point=0x$code_point";
    eval "\$other_code_point=0x$other_code_point";

    die "Not sorted\n" if (defined $lastv) && $lastv >= $code_point;

    $lastv = $code_point;

    if ($extra)
    {
	print "UNICODE_BIDI_$other,\n";
    }
    else
    {
	print "{$code_point, $other_code_point},\n";
    }
}