Mercurial > emacs
annotate admin/unidata/unidata-gen.el @ 104819:1468c5df344a
(diary-set-header, diary-live-p)
(diary-check-diary-file, diary-list-entries)
(diary-include-other-diary-files, diary-simple-display)
(diary-fancy-display, diary-print-entries)
(diary-mark-included-diary-files, diary-make-entry):
Don't call substitute-in-file-name on diary-file.
author | Glenn Morris <rgm@gnu.org> |
---|---|
date | Thu, 03 Sep 2009 06:34:19 +0000 |
parents | e1613d164d67 |
children | 5626ccae11ed |
rev | line source |
---|---|
90086 | 1 ;; unidata-gen.el -- Create files containing character property data. |
100971 | 2 ;; Copyright (C) 2005, 2006, 2007, 2008, 2009 |
90086 | 3 ;; National Institute of Advanced Industrial Science and Technology (AIST) |
4 ;; Registration Number H13PRO009 | |
5 | |
6 ;; This file is part of GNU Emacs. | |
7 | |
94829
aeac1d771ae4
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
94071
diff
changeset
|
8 ;; GNU Emacs is free software: you can redistribute it and/or modify |
90086 | 9 ;; it under the terms of the GNU General Public License as published by |
94829
aeac1d771ae4
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
94071
diff
changeset
|
10 ;; the Free Software Foundation, either version 3 of the License, or |
aeac1d771ae4
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
94071
diff
changeset
|
11 ;; (at your option) any later version. |
90086 | 12 |
13 ;; GNU Emacs is distributed in the hope that it will be useful, | |
14 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 ;; GNU General Public License for more details. | |
17 | |
18 ;; You should have received a copy of the GNU General Public License | |
94829
aeac1d771ae4
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
94071
diff
changeset
|
19 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. |
90086 | 20 |
21 ;;; Commentary: | |
22 | |
90162
88ca83396d15
Typo fixed in comments. Change
Kenichi Handa <handa@m17n.org>
parents:
90112
diff
changeset
|
23 ;; SPECIAL NOTICE |
88ca83396d15
Typo fixed in comments. Change
Kenichi Handa <handa@m17n.org>
parents:
90112
diff
changeset
|
24 ;; |
88ca83396d15
Typo fixed in comments. Change
Kenichi Handa <handa@m17n.org>
parents:
90112
diff
changeset
|
25 ;; This file must be byte-compilable/loadable by `temacs' and also |
88ca83396d15
Typo fixed in comments. Change
Kenichi Handa <handa@m17n.org>
parents:
90112
diff
changeset
|
26 ;; the entry function `unidata-gen-files' must be runnable by |
88ca83396d15
Typo fixed in comments. Change
Kenichi Handa <handa@m17n.org>
parents:
90112
diff
changeset
|
27 ;; `temacs'. |
88ca83396d15
Typo fixed in comments. Change
Kenichi Handa <handa@m17n.org>
parents:
90112
diff
changeset
|
28 |
90086 | 29 ;; FILES TO BE GENERATED |
30 ;; | |
90162
88ca83396d15
Typo fixed in comments. Change
Kenichi Handa <handa@m17n.org>
parents:
90112
diff
changeset
|
31 ;; The entry function `unidata-gen-files' generates these files in |
90086 | 32 ;; the current directory. |
33 ;; | |
34 ;; charprop.el | |
35 ;; It contains a series of forms of this format: | |
36 ;; (char-code-property-register PROP FILE) | |
37 ;; where PROP is a symbol representing a character property | |
90162
88ca83396d15
Typo fixed in comments. Change
Kenichi Handa <handa@m17n.org>
parents:
90112
diff
changeset
|
38 ;; (name, generic-category, etc), and FILE is a name of one of |
90086 | 39 ;; the following files. |
40 ;; | |
94071
03be13c38b12
(unidata-prop-alist): Fix typo in description of `numeric-value'.
Juanma Barranquero <lekktu@gmail.com>
parents:
91421
diff
changeset
|
41 ;; uni-name.el, uni-category.el, uni-combining.el, uni-bidi.el, |
03be13c38b12
(unidata-prop-alist): Fix typo in description of `numeric-value'.
Juanma Barranquero <lekktu@gmail.com>
parents:
91421
diff
changeset
|
42 ;; uni-decomposition.el, uni-decimal.el, uni-digit.el, uni-numeric.el, |
03be13c38b12
(unidata-prop-alist): Fix typo in description of `numeric-value'.
Juanma Barranquero <lekktu@gmail.com>
parents:
91421
diff
changeset
|
43 ;; uni-mirrored.el, uni-old-name.el, uni-comment.el, uni-uppercase.el, |
03be13c38b12
(unidata-prop-alist): Fix typo in description of `numeric-value'.
Juanma Barranquero <lekktu@gmail.com>
parents:
91421
diff
changeset
|
44 ;; uni-lowercase.el, uni-titlecase.el |
03be13c38b12
(unidata-prop-alist): Fix typo in description of `numeric-value'.
Juanma Barranquero <lekktu@gmail.com>
parents:
91421
diff
changeset
|
45 ;; They each contain a single form of this format: |
90086 | 46 ;; (char-code-property-register PROP CHAR-TABLE) |
47 ;; where PROP is the same as above, and CHAR-TABLE is a | |
90162
88ca83396d15
Typo fixed in comments. Change
Kenichi Handa <handa@m17n.org>
parents:
90112
diff
changeset
|
48 ;; char-table containing property values in a compressed format. |
90086 | 49 ;; |
50 ;; When they are installed in .../lisp/international/, the file | |
51 ;; "charprop.el" is preloaded in loadup.el. The other files are | |
52 ;; automatically loaded when the functions `get-char-code-property' | |
53 ;; and `put-char-code-property' are called. | |
54 ;; | |
55 ;; FORMAT OF A CHAR TABLE | |
56 ;; | |
57 ;; We want to make a file size containing a char-table small. We | |
58 ;; also want to load the file and get a property value fast. We | |
59 ;; also want to reduce the used memory after loading it. So, | |
60 ;; instead of naively storing a property value for each character in | |
61 ;; a char-table (and write it out into a file), we store compressed | |
62 ;; data in a char-table as below. | |
63 ;; | |
64 ;; If succeeding 128*N characters have the same property value, we | |
90162
88ca83396d15
Typo fixed in comments. Change
Kenichi Handa <handa@m17n.org>
parents:
90112
diff
changeset
|
65 ;; store that value for them. Otherwise, compress values for |
90086 | 66 ;; succeeding 128 characters into a single string and store it as a |
67 ;; value for those characters. The way of compression depends on a | |
68 ;; property. See the section "SIMPLE TABLE", "RUN-LENGTH TABLE", | |
69 ;; and "WORD-LIST TABLE". | |
70 | |
71 ;; The char table has four extra slots: | |
72 ;; 1st: property symbol | |
73 ;; 2nd: function to call to get a property value | |
74 ;; 3nd: function to call to put a property value | |
75 ;; 4th: function to call to get a description of a property value | |
76 ;; 5th: data referred by the above functions | |
77 | |
78 ;; List of elements of this form: | |
79 ;; (CHAR-or-RANGE PROP1 PROP2 ... PROPn) | |
80 ;; CHAR-or-RANGE: a character code or a cons of character codes | |
81 ;; PROPn: string representing the nth property value | |
82 | |
90174
f3973ae57d8b
(unidata-text-file): Delete it.
Kenichi Handa <handa@m17n.org>
parents:
90162
diff
changeset
|
83 (defvar unidata-list nil) |
f3973ae57d8b
(unidata-text-file): Delete it.
Kenichi Handa <handa@m17n.org>
parents:
90162
diff
changeset
|
84 |
f3973ae57d8b
(unidata-text-file): Delete it.
Kenichi Handa <handa@m17n.org>
parents:
90162
diff
changeset
|
85 (defun unidata-setup-list (unidata-text-file) |
90086 | 86 (let* ((table (list nil)) |
87 (tail table) | |
88 (block-names '(("^<CJK Ideograph" . CJK\ IDEOGRAPH) | |
89 ("^<Hangul Syllable" . HANGUL\ SYLLABLE) | |
90 ("^<.*Surrogate" . nil) | |
91 ("^<.*Private Use" . PRIVATE\ USE))) | |
92 val char name) | |
93 (or (file-readable-p unidata-text-file) | |
94 (error "File not readable: %s" unidata-text-file)) | |
95 (with-temp-buffer | |
90162
88ca83396d15
Typo fixed in comments. Change
Kenichi Handa <handa@m17n.org>
parents:
90112
diff
changeset
|
96 (insert-file-contents unidata-text-file) |
90086 | 97 (goto-char (point-min)) |
98 (condition-case nil | |
99 (while t | |
100 (setq val (read (current-buffer)) | |
101 char (car val) | |
102 name (cadr val)) | |
103 | |
104 ;; Check this kind of block. | |
105 ;; 4E00;<CJK Ideograph, First>;Lo;0;L;;;;;N;;;;; | |
106 ;; 9FA5;<CJK Ideograph, Last>;Lo;0;L;;;;;N;;;;; | |
107 (if (and (= (aref name 0) ?<) | |
108 (string-match ", First>$" name)) | |
109 (let ((first char) | |
110 (l block-names) | |
111 block-name) | |
112 (setq val (read (current-buffer)) | |
113 char (car val) | |
114 block-name (cadr val) | |
115 name nil) | |
116 (while l | |
117 (if (string-match (caar l) block-name) | |
118 (setq name (cdar l) l nil) | |
119 (setq l (cdr l)))) | |
120 (if (not name) | |
121 ;; As this is a surrogate pair range, ignore it. | |
122 (setq val nil) | |
123 (setcar val (cons first char)) | |
124 (setcar (cdr val) name)))) | |
125 | |
126 (when val | |
127 (setcdr tail (list val)) | |
128 (setq tail (cdr tail)))) | |
129 (error nil))) | |
90174
f3973ae57d8b
(unidata-text-file): Delete it.
Kenichi Handa <handa@m17n.org>
parents:
90162
diff
changeset
|
130 (setq unidata-list (cdr table)))) |
90086 | 131 |
132 ;; Alist of this form: | |
133 ;; (PROP INDEX GENERATOR FILENAME) | |
134 ;; PROP: character property | |
135 ;; INDEX: index to each element of unidata-list for PROP | |
136 ;; GENERATOR: function to generate a char-table | |
137 ;; FILENAME: filename to store the char-table | |
138 ;; DESCRIBER: function to call to get a description string of property value | |
139 | |
140 (defconst unidata-prop-alist | |
141 '((name | |
142 1 unidata-gen-table-name "uni-name.el" | |
143 "Unicode character name. | |
144 Property value is a string.") | |
145 (general-category | |
146 2 unidata-gen-table-symbol "uni-category.el" | |
147 "Unicode general category. | |
148 Property value is one of the following symbols: | |
149 Lu, Ll, Lt, Lm, Lo, Mn, Mc, Me, Nd, Nl, No, Pc, Pd, Ps, Pe, Pi, Pf, Po, | |
150 Sm, Sc, Sk, So, Zs, Zl, Zp, Cc, Cf, Cs, Co, Cn" | |
151 unidata-describe-general-category) | |
152 (canonical-combining-class | |
153 3 unidata-gen-table-integer "uni-combining.el" | |
154 "Unicode canonical combining class. | |
155 Property value is an integer." | |
156 unidata-describe-canonical-combining-class) | |
157 (bidi-class | |
158 4 unidata-gen-table-symbol "uni-bidi.el" | |
159 "Unicode bidi class. | |
160 Property value is one of the following symbols: | |
161 L, LRE, LRO, R, AL, RLE, RLO, PDF, EN, ES, ET, | |
162 AN, CS, NSM, BN, B, S, WS, ON" | |
163 unidata-describe-bidi-class) | |
164 (decomposition | |
165 5 unidata-gen-table-decomposition "uni-decomposition.el" | |
166 "Unicode decomposition mapping. | |
167 Property value is a list of characters. The first element may be | |
90162
88ca83396d15
Typo fixed in comments. Change
Kenichi Handa <handa@m17n.org>
parents:
90112
diff
changeset
|
168 one of these symbols representing compatibility formatting tag: |
100107
eff1b0128211
(unidata-prop-alist): Docstring for
Kenichi Handa <handa@m17n.org>
parents:
100094
diff
changeset
|
169 font, noBreak, initial, medial, final, isolated, circle, super, |
eff1b0128211
(unidata-prop-alist): Docstring for
Kenichi Handa <handa@m17n.org>
parents:
100094
diff
changeset
|
170 sub, vertical, wide, narrow, small, square, fraction, compat" |
90086 | 171 unidata-describe-decomposition) |
172 (decimal-digit-value | |
173 6 unidata-gen-table-integer "uni-decimal.el" | |
174 "Unicode numeric value (decimal digit). | |
175 Property value is an integer.") | |
176 (digit-value | |
177 7 unidata-gen-table-integer "uni-digit.el" | |
178 "Unicode numeric value (digit). | |
179 Property value is an integer.") | |
180 (numeric-value | |
100093
eae5b6774936
(unidata-prop-alist): Set `numric-value'
Kenichi Handa <handa@m17n.org>
parents:
94829
diff
changeset
|
181 8 unidata-gen-table-numeric "uni-numeric.el" |
90086 | 182 "Unicode numeric value (numeric). |
100094
c39e7dbb8896
(unidata-prop-alist): Docstring adjusted.
Kenichi Handa <handa@m17n.org>
parents:
100093
diff
changeset
|
183 Property value is an integer or a floating point.") |
90086 | 184 (mirrored |
185 9 unidata-gen-table-symbol "uni-mirrored.el" | |
186 "Unicode bidi mirrored flag. | |
187 Property value is a symbol `Y' or `N'.") | |
188 (old-name | |
189 10 unidata-gen-table-name "uni-old-name.el" | |
190 "Unicode old names as published in Unicode 1.0. | |
191 Property value is a string.") | |
192 (iso-10646-comment | |
193 11 unidata-gen-table-name "uni-comment.el" | |
194 "Unicode ISO 10646 comment. | |
195 Property value is a string.") | |
196 (uppercase | |
197 12 unidata-gen-table-character "uni-uppercase.el" | |
198 "Unicode simple uppercase mapping. | |
199 Property value is a character." | |
200 string) | |
201 (lowercase | |
202 13 unidata-gen-table-character "uni-lowercase.el" | |
203 "Unicode simple lowercase mapping. | |
204 Property value is a character." | |
205 string) | |
206 (titlecase | |
207 14 unidata-gen-table-character "uni-titlecase.el" | |
208 "Unicode simple titlecase mapping. | |
209 Property value is a character." | |
210 string))) | |
211 | |
212 ;; Functions to access the above data. | |
213 (defsubst unidata-prop-index (prop) (nth 1 (assq prop unidata-prop-alist))) | |
214 (defsubst unidata-prop-generator (prop) (nth 2 (assq prop unidata-prop-alist))) | |
215 (defsubst unidata-prop-file (prop) (nth 3 (assq prop unidata-prop-alist))) | |
216 (defsubst unidata-prop-docstring (prop) (nth 4 (assq prop unidata-prop-alist))) | |
217 (defsubst unidata-prop-describer (prop) (nth 5 (assq prop unidata-prop-alist))) | |
218 | |
219 | |
220 ;; SIMPLE TABLE | |
221 ;; | |
222 ;; If the type of character property value is character, and the | |
223 ;; values of succeeding character codes are usually different, we use | |
224 ;; a char-table described here to store such values. | |
225 ;; | |
226 ;; If succeeding 128 characters has no property, a char-table has the | |
227 ;; symbol t is for them. Otherwise a char-table has a string of the | |
228 ;; following format for them. | |
229 ;; | |
230 ;; The first character of the string is FIRST-INDEX. | |
231 ;; The Nth (N > 0) character of the string is a property value of the | |
90162
88ca83396d15
Typo fixed in comments. Change
Kenichi Handa <handa@m17n.org>
parents:
90112
diff
changeset
|
232 ;; character (BLOCK-HEAD + FIRST-INDEX + N - 1), where BLOCK-HEAD is |
90086 | 233 ;; the first of the characters in the block. |
234 ;; | |
235 ;; The 4th extra slot of a char-table is nil. | |
236 | |
237 (defun unidata-get-character (char val table) | |
238 (cond | |
239 ((characterp val) | |
240 val) | |
241 | |
242 ((stringp val) | |
243 (let* ((len (length val)) | |
244 (block-head (lsh (lsh char -7) 7)) | |
245 (vec (make-vector 128 nil)) | |
246 (first-index (aref val 0))) | |
247 (dotimes (i (1- len)) | |
248 (let ((elt (aref val (1+ i)))) | |
249 (if (> elt 0) | |
250 (aset vec (+ first-index i) elt)))) | |
251 (dotimes (i 128) | |
252 (aset table (+ block-head i) (aref vec i))) | |
253 (aref vec (- char block-head)))))) | |
254 | |
255 (defun unidata-put-character (char val table) | |
256 (or (characterp val) | |
257 (not val) | |
94071
03be13c38b12
(unidata-prop-alist): Fix typo in description of `numeric-value'.
Juanma Barranquero <lekktu@gmail.com>
parents:
91421
diff
changeset
|
258 (error "Not a character nor nil: %S" val)) |
90086 | 259 (let ((current-val (aref table char))) |
260 (unless (eq current-val val) | |
261 (if (stringp current-val) | |
262 (funcall (char-table-extra-slot table 1) char current-val table)) | |
263 (aset table char val)))) | |
264 | |
265 (defun unidata-gen-table-character (prop) | |
266 (let ((table (make-char-table 'char-code-property-table)) | |
267 (prop-idx (unidata-prop-index prop)) | |
268 (vec (make-vector 128 0)) | |
269 (tail unidata-list) | |
270 elt range val idx slot) | |
271 (set-char-table-range table (cons 0 (max-char)) t) | |
272 (while tail | |
273 (setq elt (car tail) tail (cdr tail)) | |
274 (setq range (car elt) | |
275 val (nth prop-idx elt)) | |
276 (if (= (length val) 0) | |
277 (setq val nil) | |
278 (setq val (string-to-number val 16))) | |
279 (if (consp range) | |
280 (if val | |
281 (set-char-table-range table range val)) | |
282 (let* ((start (lsh (lsh range -7) 7)) | |
283 (limit (+ start 127)) | |
284 first-index last-index) | |
285 (fillarray vec 0) | |
286 (if val | |
287 (aset vec (setq last-index (setq first-index (- range start))) | |
288 val)) | |
289 (while (and (setq elt (car tail) range (car elt)) | |
290 (integerp range) | |
291 (<= range limit)) | |
292 (setq val (nth prop-idx elt)) | |
293 (when (> (length val) 0) | |
294 (aset vec (setq last-index (- range start)) | |
295 (string-to-number val 16)) | |
296 (or first-index | |
297 (setq first-index last-index))) | |
298 (setq tail (cdr tail))) | |
299 (when first-index | |
300 (let ((str (string first-index)) | |
301 c) | |
302 (while (<= first-index last-index) | |
303 (setq str (format "%s%c" str (or (aref vec first-index) 0)) | |
304 first-index (1+ first-index))) | |
305 (set-char-table-range table (cons start limit) str)))))) | |
306 | |
307 (set-char-table-extra-slot table 0 prop) | |
308 (byte-compile 'unidata-get-character) | |
309 (byte-compile 'unidata-put-character) | |
310 (set-char-table-extra-slot table 1 (symbol-function 'unidata-get-character)) | |
311 (set-char-table-extra-slot table 2 (symbol-function 'unidata-put-character)) | |
312 | |
313 table)) | |
314 | |
315 | |
316 | |
317 ;; RUN-LENGTH TABLE | |
318 ;; | |
319 ;; If the type of character property value is symbol, integer, | |
320 ;; boolean, or character, we use a char-table described here to store | |
321 ;; the values. | |
322 ;; | |
323 ;; The 4th extra slot is a vector of property values (VAL-TABLE), and | |
324 ;; values for succeeding 128 characters are encoded into this | |
325 ;; character sequence: | |
326 ;; ( VAL-CODE RUN-LENGTH ? ) + | |
327 ;; where: | |
328 ;; VAL-CODE (0..127): | |
329 ;; (VAL-CODE - 1) is an index into VAL-TABLE. | |
330 ;; The value 0 means no-value. | |
331 ;; RUN-LENGTH (130..255): | |
332 ;; (RUN-LENGTH - 128) specifies how many characters have the same | |
333 ;; value. If omitted, it means 1. | |
334 | |
335 | |
336 ;; Return a symbol-type character property value of CHAR. VAL is the | |
337 ;; current value of (aref TABLE CHAR). | |
338 | |
339 (defun unidata-get-symbol (char val table) | |
340 (let ((val-table (char-table-extra-slot table 4))) | |
341 (cond ((symbolp val) | |
342 val) | |
343 ((stringp val) | |
344 (let ((first-char (lsh (lsh char -7) 7)) | |
345 (str val) | |
346 (len (length val)) | |
347 (idx 0) | |
348 this-val count) | |
349 (set-char-table-range table (cons first-char (+ first-char 127)) | |
350 nil) | |
351 (while (< idx len) | |
352 (setq val (aref str idx) idx (1+ idx) | |
353 count (if (< idx len) (aref str idx) 1)) | |
354 (setq val (and (> val 0) (aref val-table (1- val))) | |
355 count (if (< count 128) | |
356 1 | |
357 (prog1 (- count 128) (setq idx (1+ idx))))) | |
358 (dotimes (i count) | |
359 (if val | |
360 (aset table first-char val)) | |
361 (if (= first-char char) | |
362 (setq this-val val)) | |
363 (setq first-char (1+ first-char)))) | |
364 this-val)) | |
365 ((> val 0) | |
366 (aref val-table (1- val)))))) | |
94071
03be13c38b12
(unidata-prop-alist): Fix typo in description of `numeric-value'.
Juanma Barranquero <lekktu@gmail.com>
parents:
91421
diff
changeset
|
367 |
90086 | 368 ;; Return a integer-type character property value of CHAR. VAL is the |
369 ;; current value of (aref TABLE CHAR). | |
370 | |
371 (defun unidata-get-integer (char val table) | |
372 (let ((val-table (char-table-extra-slot table 4))) | |
373 (cond ((integerp val) | |
374 val) | |
375 ((stringp val) | |
376 (let ((first-char (lsh (lsh char -7) 7)) | |
377 (str val) | |
378 (len (length val)) | |
379 (idx 0) | |
380 this-val count) | |
381 (while (< idx len) | |
382 (setq val (aref str idx) idx (1+ idx) | |
383 count (if (< idx len) (aref str idx) 1)) | |
384 (setq val (and (> val 0) (aref val-table (1- val))) | |
385 count (if (< count 128) | |
386 1 | |
387 (prog1 (- count 128) (setq idx (1+ idx))))) | |
388 (dotimes (i count) | |
389 (aset table first-char val) | |
390 (if (= first-char char) | |
391 (setq this-val val)) | |
392 (setq first-char (1+ first-char)))) | |
393 this-val))))) | |
394 | |
100093
eae5b6774936
(unidata-prop-alist): Set `numric-value'
Kenichi Handa <handa@m17n.org>
parents:
94829
diff
changeset
|
395 ;; Return a numeric-type (integer or float) character property value |
eae5b6774936
(unidata-prop-alist): Set `numric-value'
Kenichi Handa <handa@m17n.org>
parents:
94829
diff
changeset
|
396 ;; of CHAR. VAL is the current value of (aref TABLE CHAR). |
eae5b6774936
(unidata-prop-alist): Set `numric-value'
Kenichi Handa <handa@m17n.org>
parents:
94829
diff
changeset
|
397 |
eae5b6774936
(unidata-prop-alist): Set `numric-value'
Kenichi Handa <handa@m17n.org>
parents:
94829
diff
changeset
|
398 (defun unidata-get-numeric (char val table) |
eae5b6774936
(unidata-prop-alist): Set `numric-value'
Kenichi Handa <handa@m17n.org>
parents:
94829
diff
changeset
|
399 (cond |
eae5b6774936
(unidata-prop-alist): Set `numric-value'
Kenichi Handa <handa@m17n.org>
parents:
94829
diff
changeset
|
400 ((numberp val) |
eae5b6774936
(unidata-prop-alist): Set `numric-value'
Kenichi Handa <handa@m17n.org>
parents:
94829
diff
changeset
|
401 val) |
eae5b6774936
(unidata-prop-alist): Set `numric-value'
Kenichi Handa <handa@m17n.org>
parents:
94829
diff
changeset
|
402 ((stringp val) |
eae5b6774936
(unidata-prop-alist): Set `numric-value'
Kenichi Handa <handa@m17n.org>
parents:
94829
diff
changeset
|
403 (let ((val-table (char-table-extra-slot table 4)) |
eae5b6774936
(unidata-prop-alist): Set `numric-value'
Kenichi Handa <handa@m17n.org>
parents:
94829
diff
changeset
|
404 (first-char (lsh (lsh char -7) 7)) |
eae5b6774936
(unidata-prop-alist): Set `numric-value'
Kenichi Handa <handa@m17n.org>
parents:
94829
diff
changeset
|
405 (str val) |
eae5b6774936
(unidata-prop-alist): Set `numric-value'
Kenichi Handa <handa@m17n.org>
parents:
94829
diff
changeset
|
406 (len (length val)) |
eae5b6774936
(unidata-prop-alist): Set `numric-value'
Kenichi Handa <handa@m17n.org>
parents:
94829
diff
changeset
|
407 (idx 0) |
eae5b6774936
(unidata-prop-alist): Set `numric-value'
Kenichi Handa <handa@m17n.org>
parents:
94829
diff
changeset
|
408 this-val count) |
eae5b6774936
(unidata-prop-alist): Set `numric-value'
Kenichi Handa <handa@m17n.org>
parents:
94829
diff
changeset
|
409 (while (< idx len) |
eae5b6774936
(unidata-prop-alist): Set `numric-value'
Kenichi Handa <handa@m17n.org>
parents:
94829
diff
changeset
|
410 (setq val (aref str idx) idx (1+ idx) |
eae5b6774936
(unidata-prop-alist): Set `numric-value'
Kenichi Handa <handa@m17n.org>
parents:
94829
diff
changeset
|
411 count (if (< idx len) (aref str idx) 1)) |
eae5b6774936
(unidata-prop-alist): Set `numric-value'
Kenichi Handa <handa@m17n.org>
parents:
94829
diff
changeset
|
412 (setq val (and (> val 0) (aref val-table (1- val))) |
eae5b6774936
(unidata-prop-alist): Set `numric-value'
Kenichi Handa <handa@m17n.org>
parents:
94829
diff
changeset
|
413 count (if (< count 128) |
eae5b6774936
(unidata-prop-alist): Set `numric-value'
Kenichi Handa <handa@m17n.org>
parents:
94829
diff
changeset
|
414 1 |
eae5b6774936
(unidata-prop-alist): Set `numric-value'
Kenichi Handa <handa@m17n.org>
parents:
94829
diff
changeset
|
415 (prog1 (- count 128) (setq idx (1+ idx))))) |
eae5b6774936
(unidata-prop-alist): Set `numric-value'
Kenichi Handa <handa@m17n.org>
parents:
94829
diff
changeset
|
416 (dotimes (i count) |
eae5b6774936
(unidata-prop-alist): Set `numric-value'
Kenichi Handa <handa@m17n.org>
parents:
94829
diff
changeset
|
417 (aset table first-char val) |
eae5b6774936
(unidata-prop-alist): Set `numric-value'
Kenichi Handa <handa@m17n.org>
parents:
94829
diff
changeset
|
418 (if (= first-char char) |
eae5b6774936
(unidata-prop-alist): Set `numric-value'
Kenichi Handa <handa@m17n.org>
parents:
94829
diff
changeset
|
419 (setq this-val val)) |
eae5b6774936
(unidata-prop-alist): Set `numric-value'
Kenichi Handa <handa@m17n.org>
parents:
94829
diff
changeset
|
420 (setq first-char (1+ first-char)))) |
eae5b6774936
(unidata-prop-alist): Set `numric-value'
Kenichi Handa <handa@m17n.org>
parents:
94829
diff
changeset
|
421 this-val)))) |
eae5b6774936
(unidata-prop-alist): Set `numric-value'
Kenichi Handa <handa@m17n.org>
parents:
94829
diff
changeset
|
422 |
90086 | 423 ;; Store VAL (symbol) as a character property value of CHAR in TABLE. |
424 | |
425 (defun unidata-put-symbol (char val table) | |
426 (or (symbolp val) | |
427 (error "Not a symbol: %S" val)) | |
428 (let ((current-val (aref table char))) | |
429 (unless (eq current-val val) | |
430 (if (stringp current-val) | |
431 (funcall (char-table-extra-slot table 1) char current-val table)) | |
432 (aset table char val)))) | |
433 | |
434 ;; Store VAL (integer) as a character property value of CHAR in TABLE. | |
435 | |
436 (defun unidata-put-integer (char val table) | |
437 (or (integerp val) | |
438 (not val) | |
439 (error "Not an integer nor nil: %S" val)) | |
440 (let ((current-val (aref table char))) | |
441 (unless (eq current-val val) | |
442 (if (stringp current-val) | |
443 (funcall (char-table-extra-slot table 1) char current-val table)) | |
444 (aset table char val)))) | |
445 | |
100093
eae5b6774936
(unidata-prop-alist): Set `numric-value'
Kenichi Handa <handa@m17n.org>
parents:
94829
diff
changeset
|
446 ;; Store VAL (integer or float) as a character property value of CHAR |
eae5b6774936
(unidata-prop-alist): Set `numric-value'
Kenichi Handa <handa@m17n.org>
parents:
94829
diff
changeset
|
447 ;; in TABLE. |
eae5b6774936
(unidata-prop-alist): Set `numric-value'
Kenichi Handa <handa@m17n.org>
parents:
94829
diff
changeset
|
448 |
eae5b6774936
(unidata-prop-alist): Set `numric-value'
Kenichi Handa <handa@m17n.org>
parents:
94829
diff
changeset
|
449 (defun unidata-put-numeric (char val table) |
eae5b6774936
(unidata-prop-alist): Set `numric-value'
Kenichi Handa <handa@m17n.org>
parents:
94829
diff
changeset
|
450 (or (numberp val) |
eae5b6774936
(unidata-prop-alist): Set `numric-value'
Kenichi Handa <handa@m17n.org>
parents:
94829
diff
changeset
|
451 (not val) |
eae5b6774936
(unidata-prop-alist): Set `numric-value'
Kenichi Handa <handa@m17n.org>
parents:
94829
diff
changeset
|
452 (error "Not a number nor nil: %S" val)) |
eae5b6774936
(unidata-prop-alist): Set `numric-value'
Kenichi Handa <handa@m17n.org>
parents:
94829
diff
changeset
|
453 (let ((current-val (aref table char))) |
eae5b6774936
(unidata-prop-alist): Set `numric-value'
Kenichi Handa <handa@m17n.org>
parents:
94829
diff
changeset
|
454 (unless (equal current-val val) |
eae5b6774936
(unidata-prop-alist): Set `numric-value'
Kenichi Handa <handa@m17n.org>
parents:
94829
diff
changeset
|
455 (if (stringp current-val) |
eae5b6774936
(unidata-prop-alist): Set `numric-value'
Kenichi Handa <handa@m17n.org>
parents:
94829
diff
changeset
|
456 (funcall (char-table-extra-slot table 1) char current-val table)) |
eae5b6774936
(unidata-prop-alist): Set `numric-value'
Kenichi Handa <handa@m17n.org>
parents:
94829
diff
changeset
|
457 (aset table char val)))) |
eae5b6774936
(unidata-prop-alist): Set `numric-value'
Kenichi Handa <handa@m17n.org>
parents:
94829
diff
changeset
|
458 |
90086 | 459 ;; Encode the character property value VAL into an integer value by |
460 ;; VAL-LIST. By side effect, VAL-LIST is modified. | |
461 ;; VAL-LIST has this form: | |
462 ;; (t (VAL1 . VAL-CODE1) (VAL2 . VAL-CODE2) ...) | |
463 ;; If VAL is one of VALn, just return VAL-CODEn. Otherwise, | |
464 ;; VAL-LIST is modified to this: | |
465 ;; (t (VAL . (1+ VAL-CODE1)) (VAL1 . VAL-CODE1) (VAL2 . VAL-CODE2) ...) | |
466 | |
467 (defun unidata-encode-val (val-list val) | |
100093
eae5b6774936
(unidata-prop-alist): Set `numric-value'
Kenichi Handa <handa@m17n.org>
parents:
94829
diff
changeset
|
468 (let ((slot (assoc val val-list)) |
90086 | 469 val-code) |
470 (if slot | |
471 (cdr slot) | |
472 (setq val-code (if (cdr val-list) (1+ (cdr (nth 1 val-list))) 1)) | |
473 (setcdr val-list (cons (cons val val-code) (cdr val-list))) | |
474 val-code))) | |
475 | |
476 ;; Generate a char-table for the character property PROP. | |
477 | |
478 (defun unidata-gen-table (prop val-func default-value) | |
479 (let ((table (make-char-table 'char-code-property-table)) | |
480 (prop-idx (unidata-prop-index prop)) | |
481 (val-list (list t)) | |
482 (vec (make-vector 128 0)) | |
483 tail elt range val val-code idx slot) | |
484 (set-char-table-range table (cons 0 (max-char)) default-value) | |
485 (setq tail unidata-list) | |
486 (while tail | |
487 (setq elt (car tail) tail (cdr tail)) | |
488 (setq range (car elt) | |
489 val (funcall val-func (nth prop-idx elt))) | |
490 (setq val-code (if val (unidata-encode-val val-list val))) | |
491 (if (consp range) | |
492 (if val-code | |
493 (set-char-table-range table range val)) | |
494 (let* ((start (lsh (lsh range -7) 7)) | |
495 (limit (+ start 127)) | |
496 str count new-val) | |
497 (fillarray vec 0) | |
498 (if val-code | |
499 (aset vec (- range start) val-code)) | |
500 (while (and (setq elt (car tail) range (car elt)) | |
501 (integerp range) | |
502 (<= range limit)) | |
503 (setq new-val (funcall val-func (nth prop-idx elt))) | |
504 (if (not (eq val new-val)) | |
505 (setq val new-val | |
506 val-code (if val (unidata-encode-val val-list val)))) | |
507 (if val-code | |
508 (aset vec (- range start) val-code)) | |
509 (setq tail (cdr tail))) | |
510 (setq str "" val-code -1 count 0) | |
511 (mapc #'(lambda (x) | |
512 (if (= val-code x) | |
513 (setq count (1+ count)) | |
514 (if (> count 2) | |
515 (setq str (concat str (string val-code | |
516 (+ count 128)))) | |
517 (if (= count 2) | |
518 (setq str (concat str (string val-code val-code))) | |
519 (if (= count 1) | |
520 (setq str (concat str (string val-code)))))) | |
521 (setq val-code x count 1))) | |
522 vec) | |
523 (if (= count 128) | |
524 (if val | |
525 (set-char-table-range table (cons start limit) val)) | |
526 (if (= val-code 0) | |
527 (set-char-table-range table (cons start limit) str) | |
528 (if (> count 2) | |
529 (setq str (concat str (string val-code (+ count 128)))) | |
530 (if (= count 2) | |
531 (setq str (concat str (string val-code val-code))) | |
532 (setq str (concat str (string val-code))))) | |
533 (set-char-table-range table (cons start limit) str)))))) | |
534 | |
535 (setq val-list (nreverse (cdr val-list))) | |
94071
03be13c38b12
(unidata-prop-alist): Fix typo in description of `numeric-value'.
Juanma Barranquero <lekktu@gmail.com>
parents:
91421
diff
changeset
|
536 (set-char-table-extra-slot table 0 prop) |
90086 | 537 (set-char-table-extra-slot table 4 (vconcat (mapcar 'car val-list))) |
538 table)) | |
539 | |
540 (defun unidata-gen-table-symbol (prop) | |
541 (let ((table (unidata-gen-table prop | |
542 #'(lambda (x) (and (> (length x) 0) | |
543 (intern x))) | |
544 0))) | |
545 (byte-compile 'unidata-get-symbol) | |
546 (byte-compile 'unidata-put-symbol) | |
547 (set-char-table-extra-slot table 1 (symbol-function 'unidata-get-symbol)) | |
548 (set-char-table-extra-slot table 2 (symbol-function 'unidata-put-symbol)) | |
549 table)) | |
550 | |
551 (defun unidata-gen-table-integer (prop) | |
552 (let ((table (unidata-gen-table prop | |
553 #'(lambda (x) (and (> (length x) 0) | |
554 (string-to-number x))) | |
555 t))) | |
556 (byte-compile 'unidata-get-integer) | |
557 (byte-compile 'unidata-put-integer) | |
558 (set-char-table-extra-slot table 1 (symbol-function 'unidata-get-integer)) | |
559 (set-char-table-extra-slot table 2 (symbol-function 'unidata-put-integer)) | |
560 table)) | |
561 | |
100093
eae5b6774936
(unidata-prop-alist): Set `numric-value'
Kenichi Handa <handa@m17n.org>
parents:
94829
diff
changeset
|
562 (defun unidata-gen-table-numeric (prop) |
eae5b6774936
(unidata-prop-alist): Set `numric-value'
Kenichi Handa <handa@m17n.org>
parents:
94829
diff
changeset
|
563 (let ((table (unidata-gen-table prop |
eae5b6774936
(unidata-prop-alist): Set `numric-value'
Kenichi Handa <handa@m17n.org>
parents:
94829
diff
changeset
|
564 #'(lambda (x) |
eae5b6774936
(unidata-prop-alist): Set `numric-value'
Kenichi Handa <handa@m17n.org>
parents:
94829
diff
changeset
|
565 (if (string-match "/" x) |
eae5b6774936
(unidata-prop-alist): Set `numric-value'
Kenichi Handa <handa@m17n.org>
parents:
94829
diff
changeset
|
566 (/ (float (string-to-number x)) |
eae5b6774936
(unidata-prop-alist): Set `numric-value'
Kenichi Handa <handa@m17n.org>
parents:
94829
diff
changeset
|
567 (string-to-number |
eae5b6774936
(unidata-prop-alist): Set `numric-value'
Kenichi Handa <handa@m17n.org>
parents:
94829
diff
changeset
|
568 (substring x (match-end 0)))) |
eae5b6774936
(unidata-prop-alist): Set `numric-value'
Kenichi Handa <handa@m17n.org>
parents:
94829
diff
changeset
|
569 (if (> (length x) 0) |
eae5b6774936
(unidata-prop-alist): Set `numric-value'
Kenichi Handa <handa@m17n.org>
parents:
94829
diff
changeset
|
570 (string-to-number x)))) |
eae5b6774936
(unidata-prop-alist): Set `numric-value'
Kenichi Handa <handa@m17n.org>
parents:
94829
diff
changeset
|
571 t))) |
eae5b6774936
(unidata-prop-alist): Set `numric-value'
Kenichi Handa <handa@m17n.org>
parents:
94829
diff
changeset
|
572 (byte-compile 'unidata-get-numeric) |
eae5b6774936
(unidata-prop-alist): Set `numric-value'
Kenichi Handa <handa@m17n.org>
parents:
94829
diff
changeset
|
573 (byte-compile 'unidata-put-numeric) |
eae5b6774936
(unidata-prop-alist): Set `numric-value'
Kenichi Handa <handa@m17n.org>
parents:
94829
diff
changeset
|
574 (set-char-table-extra-slot table 1 (symbol-function 'unidata-get-numeric)) |
eae5b6774936
(unidata-prop-alist): Set `numric-value'
Kenichi Handa <handa@m17n.org>
parents:
94829
diff
changeset
|
575 (set-char-table-extra-slot table 2 (symbol-function 'unidata-put-numeric)) |
eae5b6774936
(unidata-prop-alist): Set `numric-value'
Kenichi Handa <handa@m17n.org>
parents:
94829
diff
changeset
|
576 table)) |
eae5b6774936
(unidata-prop-alist): Set `numric-value'
Kenichi Handa <handa@m17n.org>
parents:
94829
diff
changeset
|
577 |
90086 | 578 |
579 ;; WORD-LIST TABLE | |
580 | |
581 ;; If the table is for `name' property, each character in the string | |
582 ;; is one of these: | |
583 ;; DIFF-HEAD-CODE (0, 1, or 2): | |
584 ;; specifies how to decode the following characters. | |
585 ;; WORD-CODE (3..#x7FF excluding '-', '0'..'9', 'A'..'Z'): | |
586 ;; specifies an index number into WORD-TABLE (see below) | |
587 ;; Otherwise (' ', '-', '0'..'9', 'A'..'Z'): | |
588 ;; specifies a literal word. | |
589 ;; | |
590 ;; The 4th slots is a vector: | |
591 ;; [ WORD-TABLE BLOCK-NAME HANGUL-JAMO-TABLE ] | |
592 ;; WORD-TABLE is a vector of word symbols. | |
593 ;; BLOCK-NAME is a vector of name symbols for a block of characters. | |
594 ;; HANGUL-JAMO-TABLE is `unidata-name-jamo-name-table'. | |
595 | |
596 ;; Return the difference of symbol list L1 and L2 in this form: | |
597 ;; (DIFF-HEAD SYM1 SYM2 ...) | |
598 ;; DIFF-HEAD is ((SAME-HEAD-LENGTH * 16) + SAME-TAIL-LENGTH). | |
599 ;; Ex: If L1 is (a b c d e f) and L2 is (a g h e f), this function | |
600 ;; returns ((+ (* 1 16) 2) g h). | |
601 ;; It means that we can get L2 from L1 by prepending the first element | |
602 ;; of L1 and appending the last 2 elements of L1 to the list (g h). | |
603 ;; If L1 and L2 don't have common elements at the head and tail, | |
604 ;; set DIFF-HEAD to -1 and SYM1 ... to the elements of L2. | |
605 | |
606 (defun unidata-word-list-diff (l1 l2) | |
607 (let ((beg 0) | |
608 (end 0) | |
609 (len1 (length l1)) | |
610 (len2 (length l2)) | |
611 result) | |
612 (when (< len1 16) | |
613 (while (and l1 (eq (car l1) (car l2))) | |
614 (setq beg (1+ beg) | |
615 l1 (cdr l1) len1 (1- len1) l2 (cdr l2) len2 (1- len2))) | |
94071
03be13c38b12
(unidata-prop-alist): Fix typo in description of `numeric-value'.
Juanma Barranquero <lekktu@gmail.com>
parents:
91421
diff
changeset
|
616 (while (and (< end len1) (< end len2) |
90086 | 617 (eq (nth (- len1 end 1) l1) (nth (- len2 end 1) l2))) |
618 (setq end (1+ end)))) | |
619 (if (= (+ beg end) 0) | |
620 (setq result (list -1)) | |
621 (setq result (list (+ (* beg 16) (+ beg (- len1 end)))))) | |
622 (while (< end len2) | |
623 (setcdr result (cons (nth (- len2 end 1) l2) (cdr result))) | |
624 (setq end (1+ end))) | |
625 result)) | |
626 | |
627 ;; Return a compressed form of the vector VEC. Each element of VEC is | |
628 ;; a list of symbols of which names can be concatenated to form a | |
629 ;; character name. This function changes those elements into | |
630 ;; compressed forms by utilizing the fact that diff of consecutive | |
631 ;; elements is usually small. | |
632 | |
633 (defun unidata-word-list-compress (vec) | |
634 (let (last-elt last-idx diff-head tail elt val) | |
635 (dotimes (i 128) | |
636 (setq elt (aref vec i)) | |
637 (when elt | |
638 (if (null last-elt) | |
639 (setq diff-head -1 | |
640 val (cons 0 elt)) | |
641 (setq val (unidata-word-list-diff last-elt elt)) | |
642 (if (= (car val) -1) | |
643 (setq diff-head -1 | |
644 val (cons 0 (cdr val))) | |
645 (if (eq diff-head (car val)) | |
646 (setq val (cons 2 (cdr val))) | |
647 (setq diff-head (car val)) | |
648 (if (>= diff-head 0) | |
649 (setq val (cons 1 val)))))) | |
650 (aset vec i val) | |
651 (setq last-idx i last-elt elt))) | |
652 (if (not last-idx) | |
653 (setq vec nil) | |
654 (if (< last-idx 127) | |
655 (let ((shorter (make-vector (1+ last-idx) nil))) | |
656 (dotimes (i (1+ last-idx)) | |
657 (aset shorter i (aref vec i))) | |
658 (setq vec shorter)))) | |
659 vec)) | |
660 | |
661 ;; Encode the word index IDX into a characters code that can be | |
662 ;; embedded in a string. | |
663 | |
664 (defsubst unidata-encode-word (idx) | |
665 ;; Exclude 0, 1, 2. | |
666 (+ idx 3)) | |
667 | |
668 ;; Decode the character code CODE (that is embedded in a string) into | |
669 ;; the corresponding word name by looking up WORD-TABLE. | |
670 | |
671 (defsubst unidata-decode-word (code word-table) | |
672 (setq code (- code 3)) | |
673 (if (< code (length word-table)) | |
674 (aref word-table code))) | |
675 | |
676 ;; Table of short transliterated name symbols of Hangul Jamo divided | |
677 ;; into Choseong, Jungseong, and Jongseong. | |
678 | |
679 (defconst unidata-name-jamo-name-table | |
680 [[G GG N D DD R M B BB S SS nil J JJ C K T P H] | |
681 [A AE YA YAE EO E YEO YE O WA WAE OE YO U WEO WE WI YU EU YI I] | |
682 [G GG GS N NJ NH D L LG LM LB LS LT LP LH M B BS S SS NG J C K T P H]]) | |
683 | |
684 ;; Return a name of CHAR. VAL is the current value of (aref TABLE | |
685 ;; CHAR). | |
686 | |
687 (defun unidata-get-name (char val table) | |
94071
03be13c38b12
(unidata-prop-alist): Fix typo in description of `numeric-value'.
Juanma Barranquero <lekktu@gmail.com>
parents:
91421
diff
changeset
|
688 (cond |
90086 | 689 ((stringp val) |
690 (if (> (aref val 0) 0) | |
691 val | |
692 (let* ((first-char (lsh (lsh char -7) 7)) | |
693 (word-table (aref (char-table-extra-slot table 4) 0)) | |
694 (i 1) | |
695 (len (length val)) | |
696 (vec (make-vector 128 nil)) | |
697 (idx 0) | |
698 (case-fold-search nil) | |
699 c word-list tail-list last-list word diff-head) | |
700 (while (< i len) | |
701 (setq c (aref val i)) | |
702 (if (< c 3) | |
703 (progn | |
704 (if (or word-list tail-list) | |
705 (aset vec idx | |
706 (setq last-list (nconc word-list tail-list)))) | |
707 (setq i (1+ i) idx (1+ idx) | |
708 word-list nil tail-list nil) | |
709 (if (> c 0) | |
710 (let ((l last-list)) | |
711 (if (= c 1) | |
712 (setq diff-head | |
713 (prog1 (aref val i) (setq i (1+ i))))) | |
714 (setq tail-list (nthcdr (% diff-head 16) last-list)) | |
715 (dotimes (i (/ diff-head 16)) | |
716 (setq word-list (nconc word-list (list (car l))) | |
717 l (cdr l)))))) | |
718 (setq word-list | |
94071
03be13c38b12
(unidata-prop-alist): Fix typo in description of `numeric-value'.
Juanma Barranquero <lekktu@gmail.com>
parents:
91421
diff
changeset
|
719 (nconc word-list |
90086 | 720 (list (symbol-name |
721 (unidata-decode-word c word-table)))) | |
722 i (1+ i)))) | |
723 (if (or word-list tail-list) | |
724 (aset vec idx (nconc word-list tail-list))) | |
725 (setq val nil) | |
726 (dotimes (i 128) | |
727 (setq c (+ first-char i)) | |
728 (let ((name (aref vec i))) | |
729 (if name | |
730 (let ((tail (cdr (setq name (copy-sequence name)))) | |
731 elt) | |
732 (while tail | |
733 (setq elt (car tail)) | |
734 (or (string= elt "-") | |
735 (progn | |
736 (setcdr tail (cons elt (cdr tail))) | |
737 (setcar tail " "))) | |
738 (setq tail (cddr tail))) | |
739 (setq name (apply 'concat name)))) | |
740 (aset table c name) | |
741 (if (= c char) | |
742 (setq val name)))) | |
743 val))) | |
744 | |
745 ((and (integerp val) (> val 0)) | |
746 (let* ((symbol-table (aref (char-table-extra-slot table 4) 1)) | |
747 (sym (aref symbol-table (1- val)))) | |
748 (cond ((eq sym 'HANGUL\ SYLLABLE) | |
749 (let ((jamo-name-table (aref (char-table-extra-slot table 4) 2))) | |
750 ;; SIndex = S - SBase | |
751 (setq char (- char #xAC00)) | |
752 (let ( ;; LIndex = SIndex / NCount | |
753 (L (/ char 588)) | |
754 ;; VIndex = (SIndex % NCount) * TCount | |
755 (V (/ (% char 588) 28)) | |
756 ;; TIndex = SIndex % TCount | |
757 (T (% char 28))) | |
94071
03be13c38b12
(unidata-prop-alist): Fix typo in description of `numeric-value'.
Juanma Barranquero <lekktu@gmail.com>
parents:
91421
diff
changeset
|
758 (format "HANGUL SYLLABLE %s%s%s" |
90112
eb1b00df002b
(unidata-get-name): Handle U+110B.
Kenichi Handa <handa@m17n.org>
parents:
90109
diff
changeset
|
759 ;; U+110B is nil in this table. |
eb1b00df002b
(unidata-get-name): Handle U+110B.
Kenichi Handa <handa@m17n.org>
parents:
90109
diff
changeset
|
760 (or (aref (aref jamo-name-table 0) L) "") |
90086 | 761 (aref (aref jamo-name-table 1) V) |
762 (if (= T 0) "" | |
763 (aref (aref jamo-name-table 2) (1- T))))))) | |
90109
790c49ba39db
(unidata-get-name): Handle "CJK IDEOGRAPH".
Kenichi Handa <handa@m17n.org>
parents:
90097
diff
changeset
|
764 ((eq sym 'CJK\ IDEOGRAPH) |
790c49ba39db
(unidata-get-name): Handle "CJK IDEOGRAPH".
Kenichi Handa <handa@m17n.org>
parents:
90097
diff
changeset
|
765 (format "%s-%04X" sym char)) |
90086 | 766 ((eq sym 'CJK\ COMPATIBILITY\ IDEOGRAPH) |
767 (format "%s-%04X" sym char)) | |
768 ((eq sym 'VARIATION\ SELECTOR) | |
769 (format "%s-%d" sym (+ (- char #xe0100) 17)))))))) | |
770 | |
771 ;; Store VAL as the name of CHAR in TABLE. | |
772 | |
773 (defun unidata-put-name (char val table) | |
774 (let ((current-val (aref table char))) | |
775 (if (and (stringp current-val) (= (aref current-val 0) 0)) | |
776 (funcall (char-table-extra-slot table 1) char current-val table)) | |
777 (aset table char val))) | |
778 | |
779 (defun unidata-get-decomposition (char val table) | |
780 (cond | |
781 ((consp val) | |
782 val) | |
783 | |
784 ((stringp val) | |
785 (if (> (aref val 0) 0) | |
786 val | |
787 (let* ((first-char (lsh (lsh char -7) 7)) | |
788 (word-table (char-table-extra-slot table 4)) | |
789 (i 1) | |
790 (len (length val)) | |
791 (vec (make-vector 128 nil)) | |
792 (idx 0) | |
793 (case-fold-search nil) | |
794 c word-list tail-list last-list word diff-head) | |
795 (while (< i len) | |
796 (setq c (aref val i)) | |
797 (if (< c 3) | |
798 (progn | |
799 (if (or word-list tail-list) | |
800 (aset vec idx | |
801 (setq last-list (nconc word-list tail-list)))) | |
802 (setq i (1+ i) idx (1+ idx) | |
803 word-list nil tail-list nil) | |
804 (if (> c 0) | |
805 (let ((l last-list)) | |
806 (if (= c 1) | |
807 (setq diff-head | |
808 (prog1 (aref val i) (setq i (1+ i))))) | |
809 (setq tail-list (nthcdr (% diff-head 16) last-list)) | |
810 (dotimes (i (/ diff-head 16)) | |
811 (setq word-list (nconc word-list (list (car l))) | |
812 l (cdr l)))))) | |
813 (setq word-list | |
94071
03be13c38b12
(unidata-prop-alist): Fix typo in description of `numeric-value'.
Juanma Barranquero <lekktu@gmail.com>
parents:
91421
diff
changeset
|
814 (nconc word-list |
90086 | 815 (list (or (unidata-decode-word c word-table) c))) |
816 i (1+ i)))) | |
817 (if (or word-list tail-list) | |
818 (aset vec idx (nconc word-list tail-list))) | |
819 (dotimes (i 128) | |
820 (aset table (+ first-char i) (aref vec i))) | |
90162
88ca83396d15
Typo fixed in comments. Change
Kenichi Handa <handa@m17n.org>
parents:
90112
diff
changeset
|
821 (aref vec (- char first-char))))) |
90086 | 822 |
90162
88ca83396d15
Typo fixed in comments. Change
Kenichi Handa <handa@m17n.org>
parents:
90112
diff
changeset
|
823 ;; Hangul syllable |
88ca83396d15
Typo fixed in comments. Change
Kenichi Handa <handa@m17n.org>
parents:
90112
diff
changeset
|
824 ((and (eq val 0) (>= char #xAC00) (<= char #xD7A3)) |
88ca83396d15
Typo fixed in comments. Change
Kenichi Handa <handa@m17n.org>
parents:
90112
diff
changeset
|
825 ;; SIndex = S (char) - SBase (#xAC00) |
88ca83396d15
Typo fixed in comments. Change
Kenichi Handa <handa@m17n.org>
parents:
90112
diff
changeset
|
826 (setq char (- char #xAC00)) |
88ca83396d15
Typo fixed in comments. Change
Kenichi Handa <handa@m17n.org>
parents:
90112
diff
changeset
|
827 (let (;; L = LBase + SIndex / NCount |
88ca83396d15
Typo fixed in comments. Change
Kenichi Handa <handa@m17n.org>
parents:
90112
diff
changeset
|
828 (L (+ #x1100 (/ char 588))) |
88ca83396d15
Typo fixed in comments. Change
Kenichi Handa <handa@m17n.org>
parents:
90112
diff
changeset
|
829 ;; V = VBase + (SIndex % NCount) * TCount |
88ca83396d15
Typo fixed in comments. Change
Kenichi Handa <handa@m17n.org>
parents:
90112
diff
changeset
|
830 (V (+ #x1161 (/ (% char 588) 28))) |
103033
0dd3b08296b6
(unidata-get-decomposition): Fix previous change.
Kenichi Handa <handa@m17n.org>
parents:
103009
diff
changeset
|
831 ;; LV = SBase + (SIndex / TCount) * TCount |
0dd3b08296b6
(unidata-get-decomposition): Fix previous change.
Kenichi Handa <handa@m17n.org>
parents:
103009
diff
changeset
|
832 (LV (+ #xAC00 (* (/ char 28) 28))) |
90162
88ca83396d15
Typo fixed in comments. Change
Kenichi Handa <handa@m17n.org>
parents:
90112
diff
changeset
|
833 ;; T = TBase + SIndex % TCount |
88ca83396d15
Typo fixed in comments. Change
Kenichi Handa <handa@m17n.org>
parents:
90112
diff
changeset
|
834 (T (+ #x11A7 (% char 28)))) |
90176
dfbe37c15be3
(unidata-get-decomposition): For Hangul
Kenichi Handa <handa@m17n.org>
parents:
90174
diff
changeset
|
835 (if (= T #x11A7) |
dfbe37c15be3
(unidata-get-decomposition): For Hangul
Kenichi Handa <handa@m17n.org>
parents:
90174
diff
changeset
|
836 (list L V) |
103009
96e8e1d84170
(unidata-get-decomposition): Adjust Hangle decomposition rule to
Kenichi Handa <handa@m17n.org>
parents:
102901
diff
changeset
|
837 (list LV T)))) |
90162
88ca83396d15
Typo fixed in comments. Change
Kenichi Handa <handa@m17n.org>
parents:
90112
diff
changeset
|
838 |
88ca83396d15
Typo fixed in comments. Change
Kenichi Handa <handa@m17n.org>
parents:
90112
diff
changeset
|
839 )) |
88ca83396d15
Typo fixed in comments. Change
Kenichi Handa <handa@m17n.org>
parents:
90112
diff
changeset
|
840 |
88ca83396d15
Typo fixed in comments. Change
Kenichi Handa <handa@m17n.org>
parents:
90112
diff
changeset
|
841 ;; Store VAL as the decomposition information of CHAR in TABLE. |
90086 | 842 |
843 (defun unidata-put-decomposition (char val table) | |
844 (let ((current-val (aref table char))) | |
845 (if (and (stringp current-val) (= (aref current-val 0) 0)) | |
846 (funcall (char-table-extra-slot table 1) char current-val table)) | |
847 (aset table char val))) | |
848 | |
849 ;; UnicodeData.txt contains these lines: | |
850 ;; 0000;<control>;Cc;0;BN;;;;;N;NULL;;;; | |
851 ;; ... | |
852 ;; 0020;SPACE;Zs;0;WS;;;;;N;;;;; | |
853 ;; ... | |
854 ;; The following command yields a file of about 96K bytes. | |
855 ;; % gawk -F ';' '{print $1,$2;}' < UnicodeData.txt | gzip > temp.gz | |
856 ;; With the following function, we can get a file of almost the same | |
857 ;; the size. | |
858 | |
859 ;; Generate a char-table for character names. | |
860 | |
861 (defun unidata-gen-table-word-list (prop val-func) | |
862 (let ((table (make-char-table 'char-code-property-table)) | |
863 (prop-idx (unidata-prop-index prop)) | |
864 (word-list (list nil)) | |
865 word-table | |
866 block-list block-word-table block-end | |
867 tail elt range val idx slot) | |
868 (set-char-table-range table (cons 0 (max-char)) 0) | |
869 (setq tail unidata-list) | |
870 (setq block-end -1) | |
871 (while tail | |
872 (setq elt (car tail) tail (cdr tail)) | |
873 (setq range (car elt) | |
874 val (funcall val-func (nth prop-idx elt))) | |
875 ;; Treat the sequence of "CJK COMPATIBILITY IDEOGRAPH-XXXX" and | |
876 ;; "VARIATION SELECTOR-XXX" as a block. | |
877 (if (and (consp val) (eq prop 'name) | |
878 (or (and (eq (car val) 'CJK) | |
879 (eq (nth 1 val) 'COMPATIBILITY)) | |
880 (and (>= range #xe0100) | |
881 (eq (car val) 'VARIATION) | |
882 (eq (nth 1 val) 'SELECTOR)))) | |
883 (let ((first (car val)) | |
884 (second (nth 1 val)) | |
885 (start range)) | |
886 (while (and (setq elt (car tail) range (car elt) | |
887 val (funcall val-func (nth prop-idx elt))) | |
888 (consp val) | |
889 (eq first (car val)) | |
890 (eq second (nth 1 val))) | |
891 (setq block-end range | |
892 tail (cdr tail))) | |
893 (setq range (cons start block-end) | |
894 val (if (eq first 'CJK) 'CJK\ COMPATIBILITY\ IDEOGRAPH | |
895 'VARIATION\ SELECTOR)))) | |
896 | |
897 (if (consp range) | |
898 (if val | |
899 (let ((slot (assq val block-list))) | |
900 (setq range (cons (car range) (cdr range))) | |
901 (setq block-end (cdr range)) | |
902 (if slot | |
903 (nconc slot (list range)) | |
904 (push (list val range) block-list)))) | |
905 (let* ((start (lsh (lsh range -7) 7)) | |
906 (limit (+ start 127)) | |
907 (first tail) | |
908 (vec (make-vector 128 nil)) | |
909 c name len) | |
910 (if (<= start block-end) | |
911 ;; START overlap with the previous block. | |
912 (aset table range (nth prop-idx elt)) | |
913 (if val | |
914 (aset vec (- range start) val)) | |
915 (while (and (setq elt (car tail) range (car elt)) | |
916 (integerp range) | |
917 (<= range limit)) | |
918 (setq val (funcall val-func (nth prop-idx elt))) | |
919 (if val | |
920 (aset vec (- range start) val)) | |
921 (setq tail (cdr tail))) | |
922 (setq vec (unidata-word-list-compress vec)) | |
923 (when vec | |
924 (dotimes (i (length vec)) | |
925 (dolist (elt (aref vec i)) | |
926 (if (symbolp elt) | |
927 (let ((slot (assq elt word-list))) | |
928 (if slot | |
929 (setcdr slot (1+ (cdr slot))) | |
930 (setcdr word-list | |
931 (cons (cons elt 1) (cdr word-list)))))))) | |
932 (set-char-table-range table (cons start limit) vec)))))) | |
933 (setq word-list (sort (cdr word-list) | |
934 #'(lambda (x y) (> (cdr x) (cdr y))))) | |
935 (setq tail word-list idx 0) | |
936 (while tail | |
937 (setcdr (car tail) (unidata-encode-word idx)) | |
938 (setq idx (1+ idx) tail (cdr tail))) | |
939 (setq word-table (make-vector (length word-list) nil)) | |
940 (setq idx 0) | |
941 (dolist (elt word-list) | |
942 (aset word-table idx (car elt)) | |
943 (setq idx (1+ idx))) | |
944 | |
945 (if (and (eq prop 'decomposition) | |
946 (> idx 32)) | |
90162
88ca83396d15
Typo fixed in comments. Change
Kenichi Handa <handa@m17n.org>
parents:
90112
diff
changeset
|
947 (error "Too many symbols in decomposition data")) |
90086 | 948 |
949 (dotimes (i (/ #x110000 128)) | |
950 (let* ((idx (* i 128)) | |
951 (vec (aref table idx))) | |
952 (when (vectorp vec) | |
953 (dotimes (i (length vec)) | |
954 (let ((tail (aref vec i)) | |
955 elt code) | |
956 (if (not tail) | |
957 (aset vec i "\0") | |
958 (while tail | |
959 (setq elt (car tail) | |
960 code (if (integerp elt) elt | |
961 (cdr (assq elt word-list)))) | |
962 (setcar tail (string code)) | |
963 (setq tail (cdr tail))) | |
964 (aset vec i (mapconcat 'identity (aref vec i) ""))))) | |
965 (set-char-table-range | |
966 table (cons idx (+ idx 127)) | |
967 (mapconcat 'identity vec ""))))) | |
968 | |
969 (setq block-word-table (make-vector (length block-list) nil)) | |
970 (setq idx 0) | |
971 (dolist (elt block-list) | |
972 (dolist (e (cdr elt)) | |
973 (set-char-table-range table e (1+ idx))) | |
974 (aset block-word-table idx (car elt)) | |
975 (setq idx (1+ idx))) | |
976 | |
977 (set-char-table-extra-slot table 0 prop) | |
978 (set-char-table-extra-slot table 4 (cons word-table block-word-table)) | |
979 table)) | |
980 | |
981 (defun unidata-split-name (str) | |
982 (if (symbolp str) | |
983 str | |
984 (let ((len (length str)) | |
985 (l nil) | |
986 (idx 0) | |
987 c) | |
988 (if (= len 0) | |
989 nil | |
990 (dotimes (i len) | |
991 (setq c (aref str i)) | |
992 (if (= c 32) | |
993 (setq l (cons (intern (substring str idx i)) l) | |
994 idx (1+ i)) | |
94071
03be13c38b12
(unidata-prop-alist): Fix typo in description of `numeric-value'.
Juanma Barranquero <lekktu@gmail.com>
parents:
91421
diff
changeset
|
995 (if (and (= c ?-) (< idx i) |
90086 | 996 (< (1+ i) len) (/= (aref str (1+ i)) 32)) |
997 (setq l (cons '- (cons (intern (substring str idx i)) l)) | |
998 idx (1+ i))))) | |
999 (nreverse (cons (intern (substring str idx)) l)))))) | |
1000 | |
1001 (defun unidata-gen-table-name (prop) | |
1002 (let* ((table (unidata-gen-table-word-list prop 'unidata-split-name)) | |
1003 (word-tables (char-table-extra-slot table 4))) | |
1004 (byte-compile 'unidata-get-name) | |
1005 (byte-compile 'unidata-put-name) | |
1006 (set-char-table-extra-slot table 1 (symbol-function 'unidata-get-name)) | |
1007 (set-char-table-extra-slot table 2 (symbol-function 'unidata-put-name)) | |
1008 | |
1009 (if (eq prop 'name) | |
1010 (set-char-table-extra-slot table 4 | |
1011 (vector (car word-tables) | |
1012 (cdr word-tables) | |
1013 unidata-name-jamo-name-table)) | |
1014 (set-char-table-extra-slot table 4 | |
1015 (vector (car word-tables)))) | |
1016 table)) | |
1017 | |
1018 (defun unidata-split-decomposition (str) | |
1019 (if (symbolp str) | |
1020 str | |
1021 (let ((len (length str)) | |
1022 (l nil) | |
1023 (idx 0) | |
1024 c) | |
1025 (if (= len 0) | |
1026 nil | |
1027 (dotimes (i len) | |
1028 (setq c (aref str i)) | |
1029 (if (= c 32) | |
1030 (setq l (if (= (aref str idx) ?<) | |
100107
eff1b0128211
(unidata-prop-alist): Docstring for
Kenichi Handa <handa@m17n.org>
parents:
100094
diff
changeset
|
1031 (cons (intern (substring str (1+ idx) (1- i))) l) |
90162
88ca83396d15
Typo fixed in comments. Change
Kenichi Handa <handa@m17n.org>
parents:
90112
diff
changeset
|
1032 (cons (string-to-number (substring str idx i) 16) l)) |
90086 | 1033 idx (1+ i)))) |
1034 (if (= (aref str idx) ?<) | |
100107
eff1b0128211
(unidata-prop-alist): Docstring for
Kenichi Handa <handa@m17n.org>
parents:
100094
diff
changeset
|
1035 (setq l (cons (intern (substring str (1+ idx) (1- len))) l)) |
90162
88ca83396d15
Typo fixed in comments. Change
Kenichi Handa <handa@m17n.org>
parents:
90112
diff
changeset
|
1036 (setq l (cons (string-to-number (substring str idx len) 16) l))) |
90086 | 1037 (nreverse l))))) |
1038 | |
1039 | |
1040 (defun unidata-gen-table-decomposition (prop) | |
1041 (let* ((table (unidata-gen-table-word-list prop 'unidata-split-decomposition)) | |
1042 (word-tables (char-table-extra-slot table 4))) | |
1043 (byte-compile 'unidata-get-decomposition) | |
1044 (byte-compile 'unidata-put-decomposition) | |
1045 (set-char-table-extra-slot table 1 | |
1046 (symbol-function 'unidata-get-decomposition)) | |
94071
03be13c38b12
(unidata-prop-alist): Fix typo in description of `numeric-value'.
Juanma Barranquero <lekktu@gmail.com>
parents:
91421
diff
changeset
|
1047 (set-char-table-extra-slot table 2 |
90086 | 1048 (symbol-function 'unidata-put-decomposition)) |
1049 (set-char-table-extra-slot table 4 (car word-tables)) | |
1050 table)) | |
1051 | |
1052 | |
1053 | |
1054 (defun unidata-describe-general-category (val) | |
1055 (cdr (assq val | |
1056 '((Lu . "Letter, Uppercase") | |
1057 (Ll . "Letter, Lowercase") | |
1058 (Lt . "Letter, Titlecase") | |
1059 (Lm . "Letter, Modifier") | |
1060 (Lo . "Letter, Other") | |
1061 (Mn . "Mark, Nonspacing") | |
1062 (Mc . "Mark, Spacing Combining") | |
1063 (Me . "Mark, Enclosing") | |
1064 (Nd . "Number, Decimal Digit") | |
1065 (Nl . "Number, Letter") | |
1066 (No . "Number, Other") | |
1067 (Pc . "Punctuation, Connector") | |
1068 (Pd . "Punctuation, Dash") | |
1069 (Ps . "Punctuation, Open") | |
1070 (Pe . "Punctuation, Close") | |
1071 (Pi . "Punctuation, Initial quote") | |
1072 (Pf . "Punctuation, Final quote") | |
1073 (Po . "Punctuation, Other") | |
1074 (Sm . "Symbol, Math") | |
1075 (Sc . "Symbol, Currency") | |
1076 (Sk . "Symbol, Modifier") | |
1077 (So . "Symbol, Other") | |
1078 (Zs . "Separator, Space") | |
1079 (Zl . "Separator, Line") | |
1080 (Zp . "Separator, Paragraph") | |
1081 (Cc . "Other, Control") | |
1082 (Cf . "Other, Format") | |
1083 (Cs . "Other, Surrogate") | |
1084 (Co . "Other, Private Use") | |
1085 (Cn . "Other, Not Assigned"))))) | |
1086 | |
1087 (defun unidata-describe-canonical-combining-class (val) | |
1088 (cdr (assq val | |
1089 '((0 . "Spacing, split, enclosing, reordrant, and Tibetan subjoined") | |
1090 (1 . "Overlays and interior") | |
1091 (7 . "Nuktas") | |
1092 (8 . "Hiragana/Katakana voicing marks") | |
1093 (9 . "Viramas") | |
1094 (10 . "Start of fixed position classes") | |
1095 (199 . "End of fixed position classes") | |
1096 (200 . "Below left attached") | |
1097 (202 . "Below attached") | |
1098 (204 . "Below right attached") | |
1099 (208 . "Left attached (reordrant around single base character)") | |
1100 (210 . "Right attached") | |
1101 (212 . "Above left attached") | |
1102 (214 . "Above attached") | |
1103 (216 . "Above right attached") | |
1104 (218 . "Below left") | |
1105 (220 . "Below") | |
1106 (222 . "Below right") | |
1107 (224 . "Left (reordrant around single base character)") | |
1108 (226 . "Right") | |
1109 (228 . "Above left") | |
1110 (230 . "Above") | |
1111 (232 . "Above right") | |
1112 (233 . "Double below") | |
1113 (234 . "Double above") | |
1114 (240 . "Below (iota subscript)"))))) | |
1115 | |
1116 (defun unidata-describe-bidi-class (val) | |
1117 (cdr (assq val | |
1118 '((L . "Left-to-Right") | |
1119 (LRE . "Left-to-Right Embedding") | |
1120 (LRO . "Left-to-Right Override") | |
1121 (R . "Right-to-Left") | |
1122 (AL . "Right-to-Left Arabic") | |
1123 (RLE . "Right-to-Left Embedding") | |
1124 (RLO . "Right-to-Left Override") | |
1125 (PDF . "Pop Directional Format") | |
1126 (EN . "European Number") | |
1127 (ES . "European Number Separator") | |
1128 (ET . "European Number Terminator") | |
1129 (AN . "Arabic Number") | |
1130 (CS . "Common Number Separator") | |
1131 (NSM . "Non-Spacing Mark") | |
1132 (BN . "Boundary Neutral") | |
1133 (B . "Paragraph Separator") | |
1134 (S . "Segment Separator") | |
1135 (WS . "Whitespace") | |
1136 (ON . "Other Neutrals"))))) | |
1137 | |
1138 (defun unidata-describe-decomposition (val) | |
102901
3c5ac8f47c5d
(unidata-describe-decomposition): Return
Kenichi Handa <handa@m17n.org>
parents:
100971
diff
changeset
|
1139 (mapconcat |
3c5ac8f47c5d
(unidata-describe-decomposition): Return
Kenichi Handa <handa@m17n.org>
parents:
100971
diff
changeset
|
1140 #'(lambda (x) |
3c5ac8f47c5d
(unidata-describe-decomposition): Return
Kenichi Handa <handa@m17n.org>
parents:
100971
diff
changeset
|
1141 (if (symbolp x) (symbol-name x) |
3c5ac8f47c5d
(unidata-describe-decomposition): Return
Kenichi Handa <handa@m17n.org>
parents:
100971
diff
changeset
|
1142 (concat (string ?') |
3c5ac8f47c5d
(unidata-describe-decomposition): Return
Kenichi Handa <handa@m17n.org>
parents:
100971
diff
changeset
|
1143 (compose-string (string x) 0 1 (string ?\t x ?\t)) |
3c5ac8f47c5d
(unidata-describe-decomposition): Return
Kenichi Handa <handa@m17n.org>
parents:
100971
diff
changeset
|
1144 (string ?')))) |
3c5ac8f47c5d
(unidata-describe-decomposition): Return
Kenichi Handa <handa@m17n.org>
parents:
100971
diff
changeset
|
1145 val " ")) |
90086 | 1146 |
1147 ;; Verify if we can retrieve correct values from the generated | |
1148 ;; char-tables. | |
1149 | |
1150 (defun unidata-check () | |
1151 (dolist (elt unidata-prop-alist) | |
1152 (let* ((prop (car elt)) | |
1153 (index (unidata-prop-index prop)) | |
1154 (generator (unidata-prop-generator prop)) | |
94071
03be13c38b12
(unidata-prop-alist): Fix typo in description of `numeric-value'.
Juanma Barranquero <lekktu@gmail.com>
parents:
91421
diff
changeset
|
1155 (table (progn |
90086 | 1156 (message "Generating %S table..." prop) |
1157 (funcall generator prop))) | |
1158 (decoder (char-table-extra-slot table 1)) | |
1159 (check #x400)) | |
1160 (dolist (e unidata-list) | |
1161 (let ((char (car e)) | |
1162 (val1 (nth index e)) | |
1163 val2) | |
1164 (if (and (stringp val1) (= (length val1) 0)) | |
1165 (setq val1 nil)) | |
1166 (unless (consp char) | |
1167 (setq val2 (funcall decoder char (aref table char) table)) | |
1168 (if val1 | |
1169 (cond ((eq generator 'unidata-gen-table-symbol) | |
1170 (setq val1 (intern val1))) | |
1171 ((eq generator 'unidata-gen-table-integer) | |
90162
88ca83396d15
Typo fixed in comments. Change
Kenichi Handa <handa@m17n.org>
parents:
90112
diff
changeset
|
1172 (setq val1 (string-to-number val1))) |
90086 | 1173 ((eq generator 'unidata-gen-table-character) |
90162
88ca83396d15
Typo fixed in comments. Change
Kenichi Handa <handa@m17n.org>
parents:
90112
diff
changeset
|
1174 (setq val1 (string-to-number val1 16))) |
90086 | 1175 ((eq generator 'unidata-gen-table-decomposition) |
1176 (setq val1 (unidata-split-decomposition val1))))) | |
1177 (when (>= char check) | |
1178 (message "%S %04X" prop check) | |
1179 (setq check (+ check #x400))) | |
1180 (or (equal val1 val2) | |
94071
03be13c38b12
(unidata-prop-alist): Fix typo in description of `numeric-value'.
Juanma Barranquero <lekktu@gmail.com>
parents:
91421
diff
changeset
|
1181 (insert (format "> %04X %S\n< %04X %S\n" |
90086 | 1182 char val1 char val2))) |
1183 (sit-for 0))))))) | |
1184 | |
1185 ;; The entry function. It generates files described in the header | |
1186 ;; comment of this file. | |
1187 | |
90174
f3973ae57d8b
(unidata-text-file): Delete it.
Kenichi Handa <handa@m17n.org>
parents:
90162
diff
changeset
|
1188 (defun unidata-gen-files (&optional unidata-text-file) |
f3973ae57d8b
(unidata-text-file): Delete it.
Kenichi Handa <handa@m17n.org>
parents:
90162
diff
changeset
|
1189 (or unidata-text-file |
f3973ae57d8b
(unidata-text-file): Delete it.
Kenichi Handa <handa@m17n.org>
parents:
90162
diff
changeset
|
1190 (setq unidata-text-file (car command-line-args-left) |
f3973ae57d8b
(unidata-text-file): Delete it.
Kenichi Handa <handa@m17n.org>
parents:
90162
diff
changeset
|
1191 command-line-args-left (cdr command-line-args-left))) |
f3973ae57d8b
(unidata-text-file): Delete it.
Kenichi Handa <handa@m17n.org>
parents:
90162
diff
changeset
|
1192 (unidata-setup-list unidata-text-file) |
91405
30275283f62d
(unidata-gen-files): Force unix line ends.
Jason Rumney <jasonr@gnu.org>
parents:
90176
diff
changeset
|
1193 (let ((coding-system-for-write 'utf-8-unix) |
90086 | 1194 (charprop-file "charprop.el")) |
1195 (with-temp-file charprop-file | |
1196 (insert ";; Automatically generated by unidata-gen.el.\n") | |
1197 (dolist (elt unidata-prop-alist) | |
1198 (let* ((prop (car elt)) | |
1199 (generator (unidata-prop-generator prop)) | |
1200 (file (unidata-prop-file prop)) | |
1201 (docstring (unidata-prop-docstring prop)) | |
1202 (describer (unidata-prop-describer prop)) | |
1203 table) | |
1204 ;; Filename in this comment line is extracted by sed in | |
1205 ;; Makefile. | |
1206 (insert (format ";; FILE: %s\n" file)) | |
1207 (insert (format "(define-char-code-property '%S %S\n %S)\n" | |
1208 prop file docstring)) | |
1209 (with-temp-file file | |
1210 (message "Generating %s..." file) | |
1211 (setq table (funcall generator prop)) | |
1212 (when describer | |
1213 (unless (subrp (symbol-function describer)) | |
1214 (byte-compile describer) | |
1215 (setq describer (symbol-function describer))) | |
1216 (set-char-table-extra-slot table 3 describer)) | |
103310
e1613d164d67
Add copyright header.
Chong Yidong <cyd@stupidchicken.com>
parents:
103033
diff
changeset
|
1217 (insert ";; Copyright (C) 1991-2009 Unicode, Inc. |
e1613d164d67
Add copyright header.
Chong Yidong <cyd@stupidchicken.com>
parents:
103033
diff
changeset
|
1218 ;; This file was generated from the Unicode data file at |
e1613d164d67
Add copyright header.
Chong Yidong <cyd@stupidchicken.com>
parents:
103033
diff
changeset
|
1219 ;; http://www.unicode.org/Public/UNIDATA/UnicodeData.txt. |
e1613d164d67
Add copyright header.
Chong Yidong <cyd@stupidchicken.com>
parents:
103033
diff
changeset
|
1220 ;; See lisp/international/README for the copyright and permission notice.\n" |
90086 | 1221 (format "(define-char-code-property '%S %S %S)\n" |
1222 prop table docstring) | |
90162
88ca83396d15
Typo fixed in comments. Change
Kenichi Handa <handa@m17n.org>
parents:
90112
diff
changeset
|
1223 ";; Local Variables:\n" |
90086 | 1224 ";; coding: utf-8\n" |
1225 ";; no-byte-compile: t\n" | |
1226 ";; End:\n\n" | |
1227 (format ";; %s ends here\n" file))))) | |
1228 (message "Writing %s..." charprop-file) | |
90162
88ca83396d15
Typo fixed in comments. Change
Kenichi Handa <handa@m17n.org>
parents:
90112
diff
changeset
|
1229 (insert ";; Local Variables:\n" |
90086 | 1230 ";; coding: utf-8\n" |
1231 ";; no-byte-compile: t\n" | |
1232 ";; End:\n\n" | |
1233 (format ";; %s ends here\n" charprop-file))))) | |
1234 | |
90162
88ca83396d15
Typo fixed in comments. Change
Kenichi Handa <handa@m17n.org>
parents:
90112
diff
changeset
|
1235 |
88ca83396d15
Typo fixed in comments. Change
Kenichi Handa <handa@m17n.org>
parents:
90112
diff
changeset
|
1236 |
90097
380964b11586
Changes from arch/CVS synchronization
Miles Bader <miles@gnu.org>
parents:
90086
diff
changeset
|
1237 ;; arch-tag: 961c862e-b821-447e-9b8a-bfbab9c2d525 |
90086 | 1238 ;;; unidata-gen.el ends here |