#!/usr/bin/perl

use strict;
use warnings;
use utf8;

my $src_file = "Blocks.txt";
my $fname_out = "unicode_block.tbl";

open(FILE, $src_file) || die "Cannot open $src_file.";
open(OUT, ">:crlf:utf8", $fname_out) || die "Cannot open $fname_out.";
print OUT "// this file was generated by get_block_table.pl\n";

my $v = <FILE>;
chop($v);
print OUT "// $v\n";
$v = <FILE>;
chop($v);
print OUT "// $v\n";

my $ostart = -1;
my $otype = "";
my $oend = 0;
my $type;
while(my $a = <FILE>) {
	if ($a =~ /^([0-9A-F]+)\.\.([0-9A-F]+); ([- 0-9A-Za-z]+)/) {
		my $start = hex $1;
		my $end = hex $2;
		my $name = $3;
		printf(OUT "{ 0x%06x, 0x%06x, \"$name\" },\n", $start, $end);
	} else {
		next;
	}
}
