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
|
#!../../miniperl
$UnicodeData = "UnicodeData-Latest.txt";
# Note: we try to keep filenames unique within first 8 chars. Using
# subdirectories for the following helps.
mkdir "In", 0777;
mkdir "Is", 0777;
mkdir "To", 0777;
mkdir "Eq", 0777;
@todo = (
# typical
['IsWord', '$cat =~ /^L[ulo]|^Nd/ or $code eq "005F"', ''],
['IsAlnum', '$cat =~ /^L[ulo]|^Nd/', ''],
['IsAlpha', '$cat =~ /^L[ulo]/', ''],
['IsSpace', '$cat =~ /^Z/ or $code lt "0020" and chr(hex $code) =~ /^\s/', ''],
['IsDigit', '$cat =~ /^Nd$/', ''],
['IsUpper', '$cat =~ /^Lu$/', ''],
['IsLower', '$cat =~ /^Ll$/', ''],
['IsASCII', 'hex $code <= 127', ''],
['IsCntrl', '$cat =~ /^C/', ''],
['IsGraph', '$cat =~ /^[^C]/ and $code ne "0020"', ''],
['IsPrint', '$cat =~ /^[^C]/', ''],
['IsPunct', '$cat =~ /^P/', ''],
['IsXDigit', '$code =~ /^00(3[0-9]|[46][1-6])$/', ''],
['ToUpper', '$up', '$up'],
['ToLower', '$down', '$down'],
['ToTitle', '$title', '$title'],
['ToDigit', '$dec ne ""', '$dec'],
# Name
['Name', '$name', '$name'],
# Category
['Category', '$cat', '$cat'],
# Normative
['IsM', '$cat =~ /^M/', ''], # Mark
['IsMn', '$cat eq "Mn"', ''], # Mark, Non-Spacing
['IsMc', '$cat eq "Mc"', ''], # Mark, Combining
['IsN', '$cat =~ /^N/', ''], # Number
['IsNd', '$cat eq "Nd"', ''], # Number, Decimal Digit
['IsNo', '$cat eq "No"', ''], # Number, Other
['IsZ', '$cat =~ /^Z/', ''], # Zeparator
['IsZs', '$cat eq "Zs"', ''], # Separator, Space
['IsZl', '$cat eq "Zl"', ''], # Separator, Line
['IsZp', '$cat eq "Zp"', ''], # Separator, Paragraph
['IsC', '$cat =~ /^C/', ''], # Crazy
['IsCc', '$cat eq "Cc"', ''], # Other, Control or Format
['IsCo', '$cat eq "Co"', ''], # Other, Private Use
['IsCn', '$cat eq "Cn"', ''], # Other, Not Assigned
# Informative
['IsL', '$cat =~ /^L/', ''], # Letter
['IsLu', '$cat eq "Lu"', ''], # Letter, Uppercase
['IsLl', '$cat eq "Ll"', ''], # Letter, Lowercase
['IsLt', '$cat eq "Lt"', ''], # Letter, Titlecase
['IsLm', '$cat eq "Lm"', ''], # Letter, Modifier
['IsLo', '$cat eq "Lo"', ''], # Letter, Other
['IsP', '$cat =~ /^P/', ''], # Punctuation
['IsPd', '$cat eq "Pd"', ''], # Punctuation, Dash
['IsPs', '$cat eq "Ps"', ''], # Punctuation, Open
['IsPe', '$cat eq "Pe"', ''], # Punctuation, Close
['IsPo', '$cat eq "Po"', ''], # Punctuation, Other
['IsS', '$cat =~ /^S/', ''], # Symbol
['IsSm', '$cat eq "Sm"', ''], # Symbol, Math
['IsSc', '$cat eq "Sc"', ''], # Symbol, Currency
['IsSo', '$cat eq "So"', ''], # Symbol, Other
# Combining class
['CombiningClass', '$comb', '$comb'],
# BIDIRECTIONAL PROPERTIES
['Bidirectional', '$bid', '$bid'],
# Strong types:
['IsBidiL', '$bid eq "L"', ''], # Left-Right; Most alphabetic,
# syllabic, and logographic
# characters (e.g., CJK
# ideographs)
['IsBidiR', '$bid eq "R"', ''], # Right-Left; Arabic, Hebrew,
# and punctuation specific to
# those scripts
# Weak types:
['IsBidiEN','$bid eq "EN"', ''], # European Number
['IsBidiES','$bid eq "ES"', ''], # European Number Separator
['IsBidiET','$bid eq "ET"', ''], # European Number Terminator
['IsBidiAN','$bid eq "AN"', ''], # Arabic Number
['IsBidiCS','$bid eq "CS"', ''], # Common Number Separator
# Separators:
['IsBidiB', '$bid eq "B"', ''], # Block Separator
['IsBidiS', '$bid eq "S"', ''], # Segment Separator
# Neutrals:
['IsBidiWS','$bid eq "WS"', ''], # Whitespace
['IsBidiON','$bid eq "ON"', ''], # Other Neutrals ; All other
# characters: punctuation,
# symbols
# Decomposition
['Decomposition', '$decomp', '$decomp'],
['IsDecoCanon', '$decomp && $decomp !~ /^</', ''],
['IsDecoCompat', '$decomp =~ /^</', ''],
['IsDCfont', '$decomp =~ /^<font>/', ''],
['IsDCnoBreak', '$decomp =~ /^<noBreak>/', ''],
['IsDCinitial', '$decomp =~ /^<initial>/', ''],
['IsDCinital', '$decomp =~ /^<medial>/', ''],
['IsDCfinal', '$decomp =~ /^<final>/', ''],
['IsDCisolated', '$decomp =~ /^<isolated>/', ''],
['IsDCcircle', '$decomp =~ /^<circle>/', ''],
['IsDCsuper', '$decomp =~ /^<super>/', ''],
['IsDCsub', '$decomp =~ /^<sub>/', ''],
['IsDCvertical', '$decomp =~ /^<vertical>/', ''],
['IsDCwide', '$decomp =~ /^<wide>/', ''],
['IsDCnarrow', '$decomp =~ /^<narrow>/', ''],
['IsDCsmall', '$decomp =~ /^<small>/', ''],
['IsDCsquare', '$decomp =~ /^<square>/', ''],
['IsDCcompat', '$decomp =~ /^<compat>/', ''],
# Number
['Number', '$num', '$num'],
# Mirrored
['IsMirrored', '$mir eq "Y"', ''],
# Arabic
['ArabLink', '1', '$link'],
['ArabLnkGrp', '1', '$linkgroup'],
# Jamo
['JamoShort', '1', '$short'],
# Syllables
['IsSylV', '$syl eq "V"', ''],
['IsSylU', '$syl eq "U"', ''],
['IsSylI', '$syl eq "I"', ''],
['IsSylA', '$syl eq "A"', ''],
['IsSylE', '$syl eq "E"', ''],
['IsSylC', '$syl eq "C"', ''],
['IsSylO', '$syl eq "O"', ''],
['IsSylWV', '$syl eq "V"', ''],
['IsSylWI', '$syl eq "I"', ''],
['IsSylWA', '$syl eq "A"', ''],
['IsSylWE', '$syl eq "E"', ''],
['IsSylWC', '$syl eq "C"', ''],
);
# This is not written for speed...
foreach $file (@todo) {
my ($table, $wanted, $val) = @$file;
next if @ARGV and not grep { $_ eq $table } @ARGV;
print $table,"\n";
if ($table =~ /^(Is|In|To)(.*)/) {
open(OUT, ">$1/$2.pl") or die "Can't create $1/$2.pl: $!\n";
}
else {
open(OUT, ">$table.pl") or die "Can't create $table.pl: $!\n";
}
print OUT <<"END";
return <<'END';
END
print OUT proplist($table, $wanted, $val);
print OUT "END\n";
close OUT;
}
# Must treat blocks specially.
exit if @ARGV and not grep { $_ eq Block } @ARGV;
print "Block\n";
open(UD, 'Blocks.txt') or die "Can't open blocks.txt: $!\n";
open(OUT, ">Block.pl") or die "Can't create $table.pl: $!\n";
print OUT <<"END";
return <<'END';
END
while (<UD>) {
next if /^#/;
next if /^$/;
chomp;
($code, $last, $name) = split(/; */);
if ($name) {
print OUT "$code $last $name\n";
$name =~ s/\s+//g;
open(BLOCK, ">In/$name.pl");
print BLOCK <<"END2";
return <<'END';
$code $last
END
END2
close BLOCK;
}
}
print OUT "END\n";
close OUT;
##################################################
sub proplist {
my ($table, $wanted, $val) = @_;
my @wanted;
my $out;
my $split;
if ($table =~ /^Arab/) {
open(UD, "ArabShap.txt") or warn "Can't open $table: $!";
$split = '($code, $name, $link, $linkgroup) = split(/; */);';
}
elsif ($table =~ /^Jamo/) {
open(UD, "Jamo-2.txt") or warn "Can't open $table: $!";
$split = '($code, $short, $name) = split(/; */); $code =~ s/^U\+//;';
}
elsif ($table =~ /^IsSyl/) {
open(UD, "syllables.txt") or warn "Can't open $table: $!";
$split = '($code, $short, $syl) = split(/; */); $code =~ s/^U\+//;';
}
else {
open(UD, $UnicodeData) or warn "Can't open $UnicodeData: $!";
$split = '($code, $name, $cat, $comb, $bid, $decomp, $dec, $dig, $num, $mir, $uni1,
$comment, $up, $down, $title) = split(/;/);';
}
if ($table =~ /^(?:To|Is)[A-Z]/) {
eval <<"END";
while (<UD>) {
next if /^#/;
next if /^\s/;
chop;
$split
if ($wanted) {
push(\@wanted, [hex \$code, hex $val, \$name =~ /, First>\$/]);
}
}
END
die $@ if $@;
while (@wanted) {
$beg = shift @wanted;
$last = $beg;
while (@wanted and $wanted[0]->[0] == $last->[0] + 1 and
(not $val or $wanted[0]->[1] == $last->[1] + 1)) {
$last = shift @wanted;
}
$out .= sprintf "%04x", $beg->[0];
if ($beg->[2]) {
$last = shift @wanted;
}
if ($beg == $last) {
$out .= "\t";
}
else {
$out .= sprintf "\t%04x", $last->[0];
}
$out .= sprintf "\t%04x", $beg->[1] if $val;
$out .= "\n";
}
}
else {
eval <<"END";
while (<UD>) {
next if /^#/;
next if /^\s*\$/;
chop;
$split
if ($wanted) {
push(\@wanted, [hex \$code, $val, \$name =~ /, First>\$/]);
}
}
END
die $@ if $@;
while (@wanted) {
$beg = shift @wanted;
$last = $beg;
while (@wanted and $wanted[0]->[0] == $last->[0] + 1 and
($wanted[0]->[1] eq $last->[1])) {
$last = shift @wanted;
}
$out .= sprintf "%04x", $beg->[0];
if ($beg->[2]) {
$last = shift @wanted;
}
if ($beg == $last) {
$out .= "\t";
}
else {
$out .= sprintf "\t%04x", $last->[0];
}
$out .= sprintf "\t%s\n", $beg->[1];
}
}
$out;
}
# Create the equivalence mappings.
open(UNICODEDATA, $UnicodeData) || die "$0: $UnicodeData: $!\n";
while (<UNICODEDATA>) {
($code, $name, $category, $decomposition) = (split /;/)[0,1,2,5];
$code{$name} = $code;
$name{$code} = $name;
next unless $category =~ /^L/ && $decomposition ne '';
$decomposition =~ s/^<\w+> //;
@decomposition = split(' ', $decomposition);
push @base, [ $code, $decomposition[0] ];
}
foreach my $b (@base) {
($code, $basecode) = @$b;
$base = $name{$basecode};
next unless exists $code{$base};
push @{$unicode{$code{$base}}}, $code;
# print "$code: $name{$code} -> $base\n",
}
@unicode = sort keys %unicode;
print "EqUnicode\n";
if (open(EQ_UNICODE, ">Eq/Unicode")) {
foreach my $c (@unicode) {
print EQ_UNICODE "$c @{$unicode{$c}}\n";
}
close EQ_UNICODE;
} else {
die "$0: failed to open Eq/Unicode for writing: $!\n";
}
print "EqLatin1\n";
if (open(EQ_LATIN1, ">Eq/Latin1")) {
foreach my $c (@unicode) {
last if hex($c) > 255;
my @c = grep { hex($_) <= 255 } @{$unicode{$c}};
next unless @c;
print EQ_LATIN1 "$c @c\n";
}
close EQ_LATIN1;
} else {
die "$0: failed to open Eq/Latin1 for writing: $!\n";
}
# eof
|