-
Notifications
You must be signed in to change notification settings - Fork 0
/
generator.php
175 lines (163 loc) · 4.56 KB
/
generator.php
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
<?php
require_once 'init.php';
require_once 'char-utils.php';
require_once 'lookup-lib.php';
$files = scandir('data/.');
$files = array_filter($files, function ($fileName) {
return $fileName[0] !== '.' && $fileName !== 'canonicalize.txt' && $fileName !== 'processed.txt' && $fileName !== 'other.txt' && substr($fileName, -4) === '.txt';
});
$error = false;
$seen = [];
$data = [];
$components = [];
foreach ($files as $file) {
$lines = file('data/' . $file);
if ($lines[0][0] !== '#') {
echo '<div class=info>Skipped ' . htmlspecialchars($file) . '.</div>';
echo '<pre style="font-size:10px;border-left:3px solid #ccc;padding-left:5px">' . implode("", $lines) . '</pre>';
continue;
}
foreach ($lines as $line) {
$line = trim($line);
if ($line === '') continue;
if ($line[0] === '#') {
$titleName = trim(substr($line, 1));
if (substr($titleName, 0, 5) === 'hkcs_') {
$components[$file][] = $titleName;
}
continue;
}
list($codepoint, $char, $ids) = explode("\t", $line, 3);
$usv = hexdec(substr($codepoint, 2));
if (isset($seen[$codepoint]) && $seen[$codepoint] !== $line) {
$warning = 'Warning: ' . $codepoint . ' in ' . $file . ' has entry ' . $line . ', expected ' . $seen[$codepoint];
echo "<div class=warning>$warning</div>";
fwrite(STDERR, "$warning\n");
$error = true;
}
$seen[$codepoint] = $line;
$data[$codepoint] = $line;
}
}
uksort($data, function ($a, $b) {
return getShiftedUSV($a) - getShiftedUSV($b);
});
$ids = '';
foreach ($data as $line) {
$ids .= trim($line) . "\r\n";
}
file_put_contents('./release/ids.txt', $ids);
file_put_contents('./processed.txt', json_encode($components));
if (php_sapi_name() === "cli") {
return;
}
?>
<title>Release Generator</title>
<style>
body{font:16px Arial, sans-serif}
td, th{border:1px solid #999;padding:2px 5px;text-align:left}
</style>
<p>Total <?=count($data)?> rows</p>
<div style="display:grid;grid-template-columns:1fr 1fr">
<div>
<?
$chunks = array_chunk($data, 100);
foreach ($chunks as $i => $chunk) {
if ($i > 100) break;
?>
<table style="border-collapse:collapse">
<?
foreach ($chunk as $line) {
list($codepoint, $char, $ids) = explode("\t", $line, 3);
$ids = str_replace('⺫', '⺫(目)', $ids);
$ids = str_replace('⺲', '⺲(𦉰)', $ids);
?>
<tr>
<th><?=$codepoint?></th>
<td><?=$char?></td>
<td><?=htmlspecialchars($ids)?></td>
</tr>
<?
}
?>
</table>
<?
}
?>
</div>
<div>
<table style="border-collapse:collapse">
<?
for ($i = 0x4E00; $i <= 0x9FFF; $i++) {
if (isset($data['U+' . strtoupper(dechex($i))])) {
continue;
} else {
$codepoint = 'U+' . strtoupper(dechex($i));
$char = codepointToChar($codepoint);
$ids = '???';
}
?>
<tr <? if ($ids === '???') echo 'style="background:#fff"'; else echo 'style="background:#eee;color:#999"'; ?>>
<th><?=$codepoint?></th>
<td><?=$char?></td>
<td><?=htmlspecialchars($ids)?></td>
</tr>
<?
}
$missing = [];
for ($i = 0x3400; $i <= 0x9FFF; $i++) {
continue;
if (isset($data['U+' . strtoupper(dechex($i))])) {
continue;
} else {
$missing[] = 'U+' . strtoupper(dechex($i));
$codepoint = 'U+' . strtoupper(dechex($i));
$char = codepointToChar($codepoint);
$ids = '???';
try {
$db = new DB();
$glyph = $db->getGlyph('hkcs_m' . dechex($i));
$idsList = $glyph->tryConvertToIDS();
$idsList = preg_split('//u', $idsList, null, PREG_SPLIT_NO_EMPTY);
$ids = '';
foreach ($idsList as $c) {
$related = 'u' . strtolower(substr(charToCodepoint($c), 2)) . '.txt';
if (file_exists($related)) {
$ids .= '!!';
}
$ids .= '<a target=_blank href="lookup.php?char='.$c.'">' . $c . '</a> ';
}
} catch (Exception $e) {
}
}
?>
<tr <? if (true) echo 'style="background:#fff"'; else echo 'style="background:#eee;color:#999"'; ?>>
<th><?=$codepoint?></th>
<td><a target=_blank href="lookup.php?char=<?=$char?>"><?=$char?></a></td>
<td><?=($ids)?></td>
</tr>
<?
}
for ($i = 0x9E00; $i < 0x9F00; $i++) {
if (isset($data['U+' . strtoupper(dechex($i))])) {
$line = $data['U+' . strtoupper(dechex($i))];
list($codepoint, $char, $ids) = explode("\t", $line, 3);
$ids = str_replace('⺫', '⺫(目)', $ids);
$ids = str_replace('⺲', '⺲(𦉰)', $ids);
} else {
$codepoint = 'U+' . strtoupper(dechex($i));
$char = codepointToChar($codepoint);
$ids = '???';
}
?>
<tr <? if ($ids === '???') echo 'style="background:#fff"'; else echo 'style="background:#eee;color:#999"'; ?>>
<th><?=$codepoint?></th>
<td><?=$char?></td>
<td><?=htmlspecialchars($ids)?></td>
</tr>
<?
}
?>
</table>
</div>
</div>