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