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
|
#! perl
use version;
my $CONSTANTS_H = '';
my $LBCLASSES = '';
my @attr = split /,/, shift @ARGV;
foreach my $attr (@attr) {
my $OMIT;
my @classes;
my $datafile;
if ($attr eq 'lb') {
$OMIT = qr{AI|CJ|SA|SG|XX|...};
@classes = qw{BK CR LF NL SP
OP CL CP QU GL NS EX SY IS PR PO NU AL HL ID IN HY BA BB B2 ZW CM
WJ H2 H3 JL JV JT RI CB
SG AI SA XX};
$datafile = 'LineBreak';
} elsif ($attr eq 'ea') {
$OMIT = undef;
@classes = qw{Z Na N A W H F};
$datafile = 'EastAsianWidth';
} elsif ($attr eq 'sc') {
$OMIT = undef;
@classes = qw(Common Inherited Unknown Han Hangul);
$datafile = 'Scripts';
} elsif ($attr eq 'gb') {
$OMIT = undef;
@classes = qw(CR LF Control Extend Prepend SpacingMark L V T LV LVT Other);
$datafile = 'GraphemeBreakProperty';
} else {
die "Unknown attr $attr\n";
}
my @versions = sort { cmpversion($a, $b) } @ARGV;
my %classes = map { ($_ => '') } @classes;
foreach my $version (@versions) {
#my $vernum = version->new($version)->numify;
my %Virama = ();
#if (6.001000 <= $vernum) {
open my $ucd, '<', "UnicodeData-$version.txt" or die $!;
while (<$ucd>) {
chomp $_;
s/\s*#.*$//;
next unless /\S/;
my ($code, $name, $gc, $ccc) = split /;/;
$code = hex("0x$code");
$Virama{$code} = 1 if $ccc+0 == 9;
}
close $ucd;
#}
my %SA = ();
foreach my $ext ('custom', 'txt') {
open LB, '<', "LineBreak-$version.$ext" or next;
while (<LB>) {
chomp $_;
s/\s*#.*$//;
next unless /\S/;
my ($code, $prop) = split /;/;
$code = hex("0x$code");
$SA{$code} = 1 if $prop eq 'SA';
}
close LB;
}
# read new classes from rules.
if ($attr eq 'lb') {
unless (open RULES, '<', "Rules-$version.txt") {
die $!;
}
while (<RULES>) {
chomp $_;
s/#.*//;
next unless /\S/;
foreach my $c (m/(\b[A-Z][0-9A-Z]\b)/g) {
unless (defined $classes{$c}) {
push @classes, $c;
$classes{$c} = $version;
}
}
}
close RULES;
}
# read new classes from data.
foreach my $data (("$datafile-$version.txt",
"$datafile-$version.custom")) {
unless (open DATA, '<', $data) {
die $! unless $data =~ /\.custom$/;
next;
}
while (<DATA>) {
chomp $_;
s/\s*#.*//;
next unless /\S/;
my ($ucs, $c) = split /;\s*/, $_;
next unless $ucs;
my ($beg, $end) = split /\.\./, $ucs;
my ($beg, $end) = split /\.\./, $ucs;
$end ||= $beg;
$beg = hex("0x$beg");
$end = hex("0x$end");
next unless $c =~ /^\w+$/;
foreach my $chr (($beg..$end)) {
# limit to SA
next if $attr eq 'sc' and !$SA{$chr};
# Extended GCB property value for virama (consonant joiner)
my $ec;
if ($attr eq 'gb' and $Virama{$chr}) {
$ec = ['Virama', 'OtherLetter'];
} else {
$ec = [$c];
}
foreach my $c (@$ec) {
unless (defined $classes{$c}) {
push @classes, $c;
$classes{$c} = $version;
}
}
}
}
close DATA;
}
my @indexedclasses;
if ($OMIT) {
@indexedclasses = grep(!/$OMIT/, @classes);
@classes = (@indexedclasses, grep(/$OMIT/, @classes));
} else {
@indexedclasses = @classes;
}
$indexedclasses{$attr} ||= {};
$indexedclasses{$attr}->{$version} = [@indexedclasses];
}
my $i;
for ($i = 0; $i <= $#classes; $i++) {
$CONSTANTS_H .= "#define ".uc($attr)."_$classes[$i] ((propval_t)$i)\n";
}
$CONSTANTS_H .= "\n";
}
open CONSTANTS_H, '>', '../include/sombok_constants.h' or die $!;
print CONSTANTS_H <<"EOF";
/*
* This file is automatically generated. DON'T EDIT THIS FILE MANUALLY.
*/
#ifndef _SOMBOK_CONSTANTS_H_
$CONSTANTS_H
#define _SOMBOK_CONSTANTS_H_
#endif /* _SOMBOK_CONSTANTS_H_ */
EOF
close CONSTANTS_H;
$LBCLASSES .= "\%indexedclasses = (\n";
foreach my $attr (@attr) {
$LBCLASSES .= " '$attr' => {\n";
foreach my $version (sort { cmpversion($a, $b) }
keys %{$indexedclasses{$attr}}) {
$LBCLASSES .= " '$version' => [qw(".
join(' ', @{$indexedclasses{$attr}->{$version}}).
")],\n";
}
$LBCLASSES .= " },\n";
}
$LBCLASSES .= ");\n\n1;\n";
open LBCLASSES, '>', 'LBCLASSES' or die $!;
print LBCLASSES $LBCLASSES;
close LBCLASSES;
sub cmpversion {
my $x = sprintf '%03d.%03d.%03d', split /\D+/, shift;
my $y = sprintf '%03d.%03d.%03d', split /\D+/, shift;
return $x cmp $y;
}
|