Sync up with r21-4-21-chise-0_24-5.
[chise/xemacs-chise.git] / lisp / utf-2000 / char-db-util.el
1 ;;; char-db-util.el --- Character Database utility -*- coding: utf-8-er; -*-
2
3 ;; Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006,
4 ;;   2007, 2008 MORIOKA Tomohiko.
5
6 ;; Author: MORIOKA Tomohiko <tomo@kanji.zinbun.kyoto-u.ac.jp>
7 ;; Keywords: CHISE, Character Database, ISO/IEC 10646, UCS, Unicode, MULE.
8
9 ;; This file is part of XEmacs CHISE.
10
11 ;; XEmacs CHISE is free software; you can redistribute it and/or
12 ;; modify it under the terms of the GNU General Public License as
13 ;; published by the Free Software Foundation; either version 2, or (at
14 ;; your option) any later version.
15
16 ;; XEmacs CHISE is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
19 ;; General Public License for more details.
20
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with XEmacs CHISE; see the file COPYING.  If not, write to
23 ;; the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
24 ;; Boston, MA 02111-1307, USA.
25
26 ;;; Code:
27
28 (require 'alist)
29
30 (defconst unidata-normative-category-alist
31   '(("Lu" letter        uppercase)
32     ("Ll" letter        lowercase)
33     ("Lt" letter        titlecase)
34     ("Mn" mark          non-spacing)
35     ("Mc" mark          spacing-combining)
36     ("Me" mark          enclosing)
37     ("Nd" number        decimal-digit)
38     ("Nl" number        letter)
39     ("No" number        other)
40     ("Zs" separator     space)
41     ("Zl" separator     line)
42     ("Zp" separator     paragraph)
43     ("Cc" other         control)
44     ("Cf" other         format)
45     ("Cs" other         surrogate)
46     ("Co" other         private-use)
47     ("Cn" other         not-assigned)))
48
49 (defconst unidata-informative-category-alist
50   '(("Lm" letter        modifier)
51     ("Lo" letter        other)
52     ("Pc" punctuation   connector)
53     ("Pd" punctuation   dash)
54     ("Ps" punctuation   open)
55     ("Pe" punctuation   close)
56     ("Pi" punctuation   initial-quote)
57     ("Pf" punctuation   final-quote)
58     ("Po" punctuation   other)
59     ("Sm" symbol        math)
60     ("Sc" symbol        currency)
61     ("Sk" symbol        modifier)
62     ("So" symbol        other)
63     ))
64
65 (defconst ideographic-radicals
66   (let ((v (make-vector 215 nil))
67         (i 1))
68     (while (< i 215)
69       (aset v i (decode-char '=ucs (+ #x2EFF i)))
70       (setq i (1+ i)))
71     v))
72
73 (defun ideographic-radical (number)
74   (aref ideographic-radicals number))
75
76 (defconst shuowen-radicals
77   [?一 ?上 ?示 ?三 ?王 ?玉 ?玨 ?气 ?士 ?丨 ; 010
78    ?屮 ?艸 ?蓐 ?茻 ?小 ?八 ?釆 ?半 ?牛 ?犛 ; 020
79    ?告 ?口 ?凵 ?吅 ?哭 ?走 ?止 ?癶 ?步 ?此 ; 030
80    ?正 ?是 ?辵 ?彳 ?廴 ?㢟 ?行 ?齒 ?牙 ?足 ; 040
81    ?疋 ?品 ?龠 ?冊 ?㗊 ?舌 ?干 ?谷 ?只 ?㕯 ; 050
82    ?句 ?丩 ?古 ?十 ?卅 ?言 ?誩 ?音 ?䇂 ?丵 ; 060
83    ?菐 ?𠬞 ?廾 ?共 ?異 ?舁 ?𦥑 ?䢅 ?爨 ?革 ; 070
84    ?鬲 ?䰜 ?爪 ?𠃨 ?鬥 ?又 ?𠂇 ?㕜 ?支 ?𦘒 ; 080
85    ?聿 ?畫 ?隶 ?臤 ?臣 ?殳 ?殺 ?𠘧 ?寸 ?皮 ; 090
86    ?㼱 ?攴 ?敎 ?卜 ?用 ?爻 ?㸚 ?𥄎 ?目 ?䀠 ; 100
87    ?眉 ?盾 ?自 ?白 ?鼻 ?皕 ?習 ?羽 ?隹 ?奞 ; 110
88    ?萑 ?𦫳 ?苜 ?羊 ?羴 ?瞿 ?雔 ?雥 ?鳥 ?烏 ; 120
89    ?𠦒 ?冓 ?幺 ?𢆶 ?叀 ?玄 ?予 ?放 ?𠬪 ?𣦼 ; 130
90    ?歺 ?死 ?冎 ?骨 ?肉 ?筋 ?刀 ?刃 ?㓞 ?丰 ; 140
91    ?耒 ?𧢲 ?竹 ?箕 ?丌 ?左 ?工 ?㠭 ?巫 ?甘 ; 150
92    ?曰 ?乃 ?丂 ?可 ?兮 ?号 ?亏 ?旨 ?喜 ?壴 ; 160
93    ?鼓 ?豈 ?豆 ?豊 ?豐 ?䖒 ?虍 ?虎 ?虤 ?皿 ; 170
94    ?𠙴 ?去 ?血 ?丶 ?丹 ?青 ?井 ?皀 ?鬯 ?食 ; 180
95    ?亼 ?會 ?倉 ?入 ?缶 ?矢 ?高 ?冂 ?𩫏 ?京 ; 190
96    ?亯 ?𣆪 ?畗 ?㐭 ?嗇 ?來 ?麥 ?夊 ?舛 ?䑞 ; 200
97    ?韋 ?弟 ?夂 ?久 ?桀 ?木 ?東 ?林 ?才 ?叒 ; 210
98    ?之 ?帀 ?出 ?𣎵 ?生 ?乇 ?𠂹 ?𠌶 ?華 ?𥝌 ; 220
99    ?稽 ?巢 ?桼 ?束 ?㯻 ?囗 ?員 ?貝 ?邑 ?𨛜 ; 230
100    ?日 ?旦 ?倝 ?㫃 ?冥 ?晶 ?月 ?有 ?明 ?囧 ; 240
101    ?夕 ?多 ?毌 ?𢎘 ?𣐺 ?卣 ?齊 ?朿 ?片 ?鼎 ; 250
102    ?克 ?彔 ?禾 ?秝 ?黍 ?香 ?米 ?毇 ?臼 ?凶 ; 260
103    ?𣎳 ?林 ?麻 ?尗 ?耑 ?韭 ?瓜 ?瓠 ?宀 ?宮 ; 270
104    ?呂 ?穴 ?㝱 ?𤕫 ?冖 ?𠔼 ?冃 ?㒳 ?网 ?襾 ; 280
105    ?巾 ?巿 ?帛 ?白 ?㡀 ?黹 ?人 ?𠤎 ?匕 ?从 ; 290
106    ])
107
108 (defun shuowen-radical (number)
109   (aref shuowen-radicals (1- number)))
110
111 (defvar char-db-file-coding-system 'utf-8-mcs-er)
112
113 (defvar char-db-feature-domains
114   '(ucs ucs/compat daikanwa cns gt jis jis/alt jis/a jis/b
115         jis-x0212 jis-x0213 cdp shinjigen misc unknown))
116
117 (defvar char-db-ignored-attributes '(ideographic-products))
118
119 (defun char-attribute-name< (ka kb)
120   (cond
121    ((eq '->denotational kb)
122     t)
123    ((eq '->subsumptive kb)
124     (not (eq '->denotational ka)))
125    ((eq '->denotational ka)
126     nil)
127    ((eq '->subsumptive ka)
128     nil)
129    ((and (symbolp ka)
130          (string-match "^->" (symbol-name ka)))
131     (cond ((and (symbolp kb)
132                 (string-match "^->" (symbol-name kb)))
133            (string< (symbol-name ka)
134                     (symbol-name kb))
135            ))
136     )
137    ((and (symbolp kb)
138          (string-match "^->" (symbol-name kb)))
139     t)
140    ((and (symbolp ka)
141          (string-match "^<-" (symbol-name ka)))
142     (cond ((symbolp kb)
143            (cond ((string-match "^<-" (symbol-name kb))
144                   (string< (symbol-name ka)
145                            (symbol-name kb))
146                   )
147                  ;; ((string-match "^->" (symbol-name kb))
148                  ;;  t)
149                  )))
150     )
151    ((and (symbolp kb)
152          (string-match "^<-" (symbol-name kb)))
153     t
154     ;; (not (string-match "^->" (symbol-name ka)))
155     )
156    ((find-charset ka)
157     (if (find-charset kb)
158         (if (or (<= (charset-id ka) 1)
159                 (and (charset-final ka)
160                      (>= (charset-final ka) ?@)))
161             (if (or (<= (charset-id kb) 1)
162                     (and (charset-final kb)
163                          (>= (charset-final kb) ?@)))
164                 (cond
165                  ((= (charset-dimension ka)
166                      (charset-dimension kb))
167                   (if (and (<= (charset-id ka) 1)
168                            (<= (charset-id kb) 1))
169                       (> (charset-id ka)(charset-id kb))
170                     (if (and (charset-final ka)
171                              (charset-final kb))
172                         (cond
173                          ((= (charset-final ka)(charset-final kb))
174                           (if (<= (charset-id ka) 1)
175                               (if (<= (charset-id kb) 1)
176                                   (> (charset-id ka)(charset-id kb))
177                                 t)
178                             (if (<= (charset-id kb) 1)
179                                 nil
180                               (< (charset-id ka)(charset-id kb))))
181                           )
182                          ((< (charset-final ka)(charset-final kb))
183                           ))
184                       (if (<= (charset-id ka) 1)
185                           (if (<= (charset-id kb) 1)
186                               (> (charset-id ka)(charset-id kb))
187                             t)
188                         (if (<= (charset-id kb) 1)
189                             nil
190                           (cond ((and (charset-final ka)
191                                       (>= (charset-final ka) ?@))
192                                  t)
193                                 ((and (charset-final kb)
194                                       (>= (charset-final kb) ?@))
195                                  nil)
196                                 (t
197                                  (< (charset-id ka)(charset-id kb))
198                                  ))))))
199                   )
200                  (t
201                   (> (charset-dimension ka)
202                      (charset-dimension kb))
203                   ))
204               t)
205           (if (or (<= (charset-id kb) 1)
206                   (and (charset-final kb)
207                        (>= (charset-final kb) ?@)))
208               nil
209             (< (charset-id ka)(charset-id kb))))
210       nil))
211    ((find-charset kb)
212     t)
213    ((symbolp ka)
214     (cond ((symbolp kb)
215            (string< (symbol-name ka)
216                     (symbol-name kb)))
217           (t)))
218    ((symbolp kb)
219     nil)))
220
221 (defvar char-db-coded-charset-priority-list
222   '(ascii
223     control-1
224     latin-iso8859-1
225     latin-iso8859-2
226     latin-iso8859-3
227     latin-iso8859-4
228     latin-iso8859-9
229     latin-jisx0201
230     cyrillic-iso8859-5
231     greek-iso8859-7
232     thai-tis620
233     =jis-x0208
234     =jis-x0208@1978
235     =jis-x0208@1983
236     japanese-jisx0212
237     chinese-gb2312
238     =jis-x0208@1990
239     chinese-cns11643-1
240     chinese-cns11643-2
241     chinese-cns11643-3
242     chinese-cns11643-4
243     chinese-cns11643-5
244     chinese-cns11643-6
245     chinese-cns11643-7
246     =jis-x0213-1-2000
247     =jis-x0213-2-2000
248     korean-ksc5601
249     chinese-isoir165
250     katakana-jisx0201
251     hebrew-iso8859-8
252     chinese-gb12345
253     latin-viscii
254     ethiopic-ucs
255     =big5-cdp
256     =gt
257     ideograph-daikanwa-2
258     ideograph-daikanwa
259     =cbeta
260     ideograph-hanziku-1
261     ideograph-hanziku-2
262     ideograph-hanziku-3
263     ideograph-hanziku-4
264     ideograph-hanziku-5
265     ideograph-hanziku-6
266     ideograph-hanziku-7
267     ideograph-hanziku-8
268     ideograph-hanziku-9
269     ideograph-hanziku-10
270     ideograph-hanziku-11
271     ideograph-hanziku-12
272     =gt-k
273     =ucs@iso
274     =ucs@unicode
275     =big5
276     =big5-eten
277     =jis-x0208@1997
278     =zinbun-oracle
279     =ruimoku-v6
280     =jef-china3))
281
282 (defun char-db-make-char-spec (char)
283   (let (ret char-spec)
284     (cond ((characterp char)
285            (cond ((and (setq ret (encode-char char '=ucs 'defined-only))
286                        (not (and (<= #xE000 ret)(<= ret #xF8FF))))
287                   (setq char-spec (list (cons '=ucs ret)))
288                   (cond ((setq ret (get-char-attribute char 'name))
289                          (setq char-spec (cons (cons 'name ret) char-spec))
290                          )
291                         ((setq ret (get-char-attribute char 'name*))
292                          (setq char-spec (cons (cons 'name* ret) char-spec))
293                          ))
294                   )
295                  ((setq ret
296                         (catch 'tag
297                           (let ((rest char-db-coded-charset-priority-list)
298                                 ccs)
299                             (while rest
300                               (setq ccs (charset-name
301                                          (find-charset (car rest))))
302                               (if (setq ret
303                                         (encode-char char ccs
304                                                      'defined-only))
305                                   (throw 'tag (cons ccs ret)))
306                               (setq rest (cdr rest))))))
307                   (setq char-spec (list ret))
308                   (dolist (ccs (delq (car ret) (charset-list)))
309                     (if (and (or (charset-iso-final-char ccs)
310                                  (memq ccs
311                                        '(=daikanwa
312                                          =daikanwa@rev2
313                                          ;; =gt-k
314                                          =jis-x0208@1997
315                                          )))
316                              (setq ccs (charset-name ccs))
317                              (null (assq ccs char-spec))
318                              (setq ret (encode-char char ccs 'defined-only)))
319                         (setq char-spec (cons (cons ccs ret) char-spec))))
320                   (if (null char-spec)
321                       (setq char-spec (split-char char)))
322                   (cond ((setq ret (get-char-attribute char 'name))
323                          (setq char-spec (cons (cons 'name ret) char-spec))
324                          )
325                         ((setq ret (get-char-attribute char 'name*))
326                          (setq char-spec (cons (cons 'name* ret) char-spec))
327                          ))
328                   ))
329            char-spec)
330           ((consp char)
331            char))))
332     
333 (defun char-db-insert-char-spec (char &optional readable column
334                                       required-features)
335   (unless column
336     (setq column (current-column)))
337   (let (char-spec temp-char)
338     (setq char-spec (char-db-make-char-spec char))
339     (unless (or (characterp char) ; char
340                 (condition-case nil
341                     (setq char (find-char char-spec))
342                   (error nil)))
343       ;; define temporary character
344       ;;   Current implementation is dirty.
345       (setq temp-char (define-char (cons '(ideograph-daikanwa . 0)
346                                          char-spec)))
347       (remove-char-attribute temp-char 'ideograph-daikanwa)
348       (setq char temp-char))
349     (insert-char-attributes char
350                             readable
351                             (union (mapcar #'car char-spec)
352                                    required-features))
353     (when temp-char
354       ;; undefine temporary character
355       ;;   Current implementation is dirty.
356       (setq char-spec (char-attribute-alist temp-char))
357       (while char-spec
358         (remove-char-attribute temp-char (car (car char-spec)))
359         (setq char-spec (cdr char-spec))))))
360
361 (defun char-db-insert-alist (alist &optional readable column)
362   (unless column
363     (setq column (current-column)))
364   (let ((line-breaking
365          (concat "\n" (make-string (1+ column) ?\ )))
366         name value
367         ret al ; cal
368         key
369         lbs cell rest separator)
370     (insert "(")
371     (while alist
372       (setq name (car (car alist))
373             value (cdr (car alist)))
374       (cond ((eq name 'char)
375              (insert "(char . ")
376              (if (setq ret (condition-case nil
377                                (find-char value)
378                              (error nil)))
379                  (progn
380                    (setq al nil
381                          ;; cal nil
382                          )
383                    (while value
384                      (setq key (car (car value)))
385                      ;; (if (find-charset key)
386                      ;;     (setq cal (cons key cal))
387                      (setq al (cons key al))
388                      ;; )
389                      (setq value (cdr value)))
390                    (insert-char-attributes ret
391                                            readable
392                                            (or al 'none) ; cal
393                                            ))
394                (insert (prin1-to-string value)))
395              (insert ")")
396              (insert line-breaking))
397             ((consp value)
398              (insert (format "(%-18s " name))
399              (setq lbs (concat "\n" (make-string (current-column) ?\ )))
400              (while (consp value)
401                (setq cell (car value))
402                (if (and (consp cell)
403                         (consp (car cell))
404                         (setq ret (condition-case nil
405                                       (find-char cell)
406                                     (error nil)))
407                         )
408                    (progn
409                      (setq rest cell
410                            al nil
411                            ;; cal nil
412                            )
413                      (while rest
414                        (setq key (car (car rest)))
415                        ;; (if (find-charset key)
416                        ;;     (setq cal (cons key cal))
417                        (setq al (cons key al))
418                        ;; )
419                        (setq rest (cdr rest)))
420                      (if separator
421                          (insert lbs))
422                      (insert-char-attributes ret
423                                              readable
424                                              al ; cal
425                                              )
426                      (setq separator lbs))
427                  (if separator
428                      (insert separator))
429                  (insert (prin1-to-string cell))
430                  (setq separator " "))
431                (setq value (cdr value)))
432              (insert ")")
433              (insert line-breaking))
434             (t
435              (insert (format "(%-18s . %S)%s"
436                              name value
437                              line-breaking))))
438       (setq alist (cdr alist))))
439   (insert ")"))
440
441 (defun char-db-insert-char-reference (plist &optional readable column)
442   (unless column
443     (setq column (current-column)))
444   (let ((line-breaking
445          (concat "\n" (make-string (1+ column) ?\ )))
446         (separator "")
447         name value)
448     (insert "(")
449     (while plist
450       (setq name (pop plist))
451       (setq value (pop plist))
452       (cond ((eq name :char)
453              (insert separator)
454              (insert ":char\t")
455              (cond ((numberp value)
456                     (setq value (decode-char '=ucs value)))
457                    ;; ((consp value)
458                    ;;  (setq value (or (find-char value)
459                    ;;                  value)))
460                    )
461              (char-db-insert-char-spec value readable)
462              (insert line-breaking)
463              (setq separator ""))
464             ((eq name :radical)
465              (insert (format "%s%s\t%d ; %c%s"
466                              separator
467                              name value
468                              (ideographic-radical value)
469                              line-breaking))
470              (setq separator ""))
471             (t
472              (insert (format "%s%s\t%S" separator name value))
473              (setq separator line-breaking)))
474       ))
475   (insert ")"))
476
477 (defun char-db-decode-isolated-char (ccs code-point)
478   (let (ret)
479     (setq ret
480           (cond ((eq ccs 'arabic-iso8859-6)
481                  (decode-char ccs code-point))
482                 ((and (memq ccs '(=gt-pj-1
483                                   =gt-pj-2
484                                   =gt-pj-3
485                                   =gt-pj-4
486                                   =gt-pj-5
487                                   =gt-pj-6
488                                   =gt-pj-7
489                                   =gt-pj-8
490                                   =gt-pj-9
491                                   =gt-pj-10
492                                   =gt-pj-11))
493                       (setq ret (decode-char ccs code-point))
494                       (setq ret (encode-char ret '=gt 'defined-only)))
495                  (decode-builtin-char '=gt ret))
496                 (t
497                  (decode-builtin-char ccs code-point))))
498     (cond ((and (<= 0 (char-int ret))
499                 (<= (char-int ret) #x1F))
500            (decode-char '=ucs (+ #x2400 (char-int ret))))
501           ((= (char-int ret) #x7F)
502            ?\u2421)
503           (t ret))))
504
505 (defvar char-db-convert-obsolete-format t)
506
507 (defun char-db-insert-ccs-feature (name value line-breaking)
508   (insert
509    (format
510     (cond ((memq name '(=shinjigen
511                         =shinjigen@1ed
512                         =shinjigen@rev =shinjigen/+p@rev))
513            "(%-18s .  %04d)\t; %c")
514           ((eq name '=shinjigen@1ed/24pr)
515            "(%-18s . %04d)\t; %c")
516           ((or (memq name '(=daikanwa
517                             =daikanwa@rev1 =daikanwa@rev2
518                             =gt =gt-k =cbeta =zinbun-oracle))
519                (string-match "^=adobe-" (symbol-name name)))
520            "(%-18s . %05d)\t; %c")
521           ((eq name 'mojikyo)
522            "(%-18s . %06d)\t; %c")
523           ((>= (charset-dimension name) 2)
524            "(%-18s . #x%04X)\t; %c")
525           (t
526            "(%-18s . #x%02X)\t; %c"))
527     name
528     (if (= (charset-iso-graphic-plane name) 1)
529         (logior value
530                 (cond ((= (charset-dimension name) 1)
531                        #x80)
532                       ((= (charset-dimension name) 2)
533                        #x8080)
534                       ((= (charset-dimension name) 3)
535                        #x808080)
536                       (t 0)))
537       value)
538     (char-db-decode-isolated-char name value)))
539   (if (and (= (charset-chars name) 94)
540            (= (charset-dimension name) 2))
541       (insert (format " [%02d-%02d]"
542                       (- (lsh value -8) 32)
543                       (- (logand value 255) 32))))
544   (insert line-breaking))
545
546 (defun char-db-insert-relation-feature (char name value line-breaking
547                                              ccss readable)
548   (insert (format "(%-18s%s " name line-breaking))
549   (let ((lbs (concat "\n" (make-string (current-column) ?\ )))
550         separator cell sources required-features
551         ret)
552     (while (consp value)
553       (setq cell (car value))
554       (if (integerp cell)
555           (setq cell (decode-char '=ucs cell)))
556       (cond
557        ((eq name '->subsumptive)
558         (when (or (not (some (lambda (atr)
559                                (get-char-attribute cell atr))
560                              char-db-ignored-attributes))
561                   (some (lambda (ccs)
562                           (encode-char cell ccs 'defined-only))
563                         ccss))
564           (if separator
565               (insert lbs))
566           (let ((char-db-ignored-attributes
567                  (cons '<-subsumptive
568                        char-db-ignored-attributes)))
569             (insert-char-attributes cell readable))
570           (setq separator lbs))
571         )
572        ((characterp cell)
573         (setq sources
574               (get-char-attribute
575                char (intern (format "%s*sources" name))))
576         (setq required-features nil)
577         (dolist (source sources)
578           (cond
579            ((memq source '(JP
580                            JP/Jouyou
581                            shinjigen shinjigen@1ed shinjigen@rev))
582             (setq required-features
583                   (union required-features
584                          '(=jis-x0208
585                            =jis-x0208@1990
586                            =jis-x0213-1-2000
587                            =jis-x0213-2-2000
588                            =jis-x0212
589                            =jis-x0208@1983
590                            =jis-x0208@1978
591                            =shinjigen))))
592            ((eq source 'CN)
593             (setq required-features
594                   (union required-features
595                          '(=gb2312
596                            =gb12345
597                            =iso-ir165)))))
598           (cond
599            ((find-charset (setq ret (intern (format "=%s" source))))
600             (setq required-features
601                   (cons ret required-features)))
602            (t (setq required-features
603                     (cons source required-features)))))
604         (cond ((string-match "@JP" (symbol-name name))
605                (setq required-features
606                      (union required-features
607                             '(=jis-x0208
608                               =jis-x0208@1990
609                               =jis-x0213-1-2000
610                               =jis-x0213-2-2000
611                               =jis-x0212
612                               =jis-x0208@1983
613                               =jis-x0208@1978))))
614               ((string-match "@CN" (symbol-name name))
615                (setq required-features
616                      (union required-features
617                             '(=gb2312
618                               =gb12345
619                               =iso-ir165)))))
620         (if separator
621             (insert lbs))
622         (if readable
623             (insert (format "%S" cell))
624           (char-db-insert-char-spec cell readable
625                                     nil
626                                     required-features))
627         (setq separator lbs))
628        ((consp cell)
629         (if separator
630             (insert lbs))
631         (if (consp (car cell))
632             (char-db-insert-char-spec cell readable)
633           (char-db-insert-char-reference cell readable))
634         (setq separator lbs))
635        (t
636         (if separator
637             (insert separator))
638         (insert (prin1-to-string cell))
639         (setq separator " ")))
640       (setq value (cdr value)))
641     (insert ")")
642     (insert line-breaking)))
643
644 (defun insert-char-attributes (char &optional readable attributes column)
645   (unless column
646     (setq column (current-column)))
647   (let (name value ; has-long-ccs-name
648         rest
649         radical strokes
650         (line-breaking
651          (concat "\n" (make-string (1+ column) ?\ )))
652         lbs cell separator ret
653         key al cal
654         dest-ccss ; sources required-features
655         ccss)
656     (let (atr-d)
657       (setq attributes
658             (sort (if attributes
659                       (if (consp attributes)
660                           (progn
661                             (dolist (name attributes)
662                               (unless (memq name char-db-ignored-attributes)
663                                 (if (find-charset name)
664                                     (push name ccss))
665                                 (push name atr-d)))
666                             atr-d))
667                     (dolist (name (char-attribute-list))
668                       (unless (memq name char-db-ignored-attributes)
669                         (if (find-charset name)
670                             (push name ccss))
671                         (push name atr-d)))
672                     atr-d)
673                   #'char-attribute-name<)))
674     (insert "(")
675     (when (memq '<-subsumptive attributes)
676       (when readable
677         (when (setq value (get-char-attribute char '<-subsumptive))
678           (char-db-insert-relation-feature char '<-subsumptive value
679                                            line-breaking
680                                            ccss readable)))
681       (setq attributes (delq '<-subsumptive attributes)))
682     (when (and (memq '<-denotational attributes)
683                (setq value (get-char-attribute char '<-denotational)))
684       (char-db-insert-relation-feature char '<-denotational value
685                                        line-breaking
686                                        ccss readable)
687       (setq attributes (delq '<-denotational attributes)))
688     (when (and (memq 'name attributes)
689                (setq value (get-char-attribute char 'name)))
690       (insert (format
691                (if (> (+ (current-column) (length value)) 48)
692                    "(name . %S)%s"
693                  "(name               . %S)%s")
694                value line-breaking))
695       (setq attributes (delq 'name attributes))
696       )
697     (when (and (memq 'name* attributes)
698                (setq value (get-char-attribute char 'name*)))
699       (insert (format
700                (if (> (+ (current-column) (length value)) 48)
701                    "(name* . %S)%s"
702                  "(name*              . %S)%s")
703                value line-breaking))
704       (setq attributes (delq 'name* attributes))
705       )
706     (when (and (memq 'script attributes)
707                (setq value (get-char-attribute char 'script)))
708       (insert (format "(script\t\t%s)%s"
709                       (mapconcat (function prin1-to-string)
710                                  value " ")
711                       line-breaking))
712       (setq attributes (delq 'script attributes))
713       )
714     (dolist (name '(=>ucs =>ucs*))
715       (when (and (memq name attributes)
716                  (setq value (get-char-attribute char name)))
717         (insert (format "(%-18s . #x%04X)\t; %c%s"
718                         name value (decode-char '=ucs value)
719                         line-breaking))
720         (setq attributes (delq name attributes))))
721     (dolist (name '(=>ucs@gb =>ucs@cns =>ucs@jis =>ucs@ks =>ucs@big5))
722       (when (and (memq name attributes)
723                  (setq value (get-char-attribute char name)))
724         (insert (format "(%-18s . #x%04X)\t; %c%s"
725                         name value
726                         (decode-char (intern
727                                       (concat "="
728                                               (substring
729                                                (symbol-name name) 2)))
730                                      value)
731                         line-breaking))
732         (setq attributes (delq name attributes))
733         ))
734     (dolist (name '(=>daikanwa))
735       (when (and (memq name attributes)
736                  (setq value (get-char-attribute char name)))
737         (insert
738          (if (integerp value)
739              (format "(%-18s . %05d)\t; %c%s"
740                      name value (decode-char '=daikanwa value)
741                      line-breaking)
742            (format "(%-18s %s)\t; %c%s"
743                    name
744                    (mapconcat (function prin1-to-string)
745                               value " ")
746                    (char-representative-of-daikanwa char)
747                    line-breaking)))
748         (setq attributes (delq name attributes))))
749     (when (and (memq 'general-category attributes)
750                (setq value (get-char-attribute char 'general-category)))
751       (insert (format
752                "(general-category\t%s) ; %s%s"
753                (mapconcat (lambda (cell)
754                             (format "%S" cell))
755                           value " ")
756                (cond ((rassoc value unidata-normative-category-alist)
757                       "Normative Category")
758                      ((rassoc value unidata-informative-category-alist)
759                       "Informative Category")
760                      (t
761                       "Unknown Category"))
762                line-breaking))
763       (setq attributes (delq 'general-category attributes))
764       )
765     (when (and (memq 'bidi-category attributes)
766                (setq value (get-char-attribute char 'bidi-category)))
767       (insert (format "(bidi-category\t. %S)%s"
768                       value
769                       line-breaking))
770       (setq attributes (delq 'bidi-category attributes))
771       )
772     (unless (or (not (memq 'mirrored attributes))
773                 (eq (setq value (get-char-attribute char 'mirrored 'empty))
774                     'empty))
775       (insert (format "(mirrored\t\t. %S)%s"
776                       value
777                       line-breaking))
778       (setq attributes (delq 'mirrored attributes))
779       )
780     (cond
781      ((and (memq 'decimal-digit-value attributes)
782            (setq value (get-char-attribute char 'decimal-digit-value)))
783       (insert (format "(decimal-digit-value . %S)%s"
784                       value
785                       line-breaking))
786       (setq attributes (delq 'decimal-digit-value attributes))
787       (when (and (memq 'digit-value attributes)
788                  (setq value (get-char-attribute char 'digit-value)))
789         (insert (format "(digit-value\t . %S)%s"
790                         value
791                         line-breaking))
792         (setq attributes (delq 'digit-value attributes))
793         )
794       (when (and (memq 'numeric-value attributes)
795                  (setq value (get-char-attribute char 'numeric-value)))
796         (insert (format "(numeric-value\t . %S)%s"
797                         value
798                         line-breaking))
799         (setq attributes (delq 'numeric-value attributes))
800         )
801       )
802      (t
803       (when (and (memq 'digit-value attributes)
804                  (setq value (get-char-attribute char 'digit-value)))
805         (insert (format "(digit-value\t. %S)%s"
806                         value
807                         line-breaking))
808         (setq attributes (delq 'digit-value attributes))
809         )
810       (when (and (memq 'numeric-value attributes)
811                  (setq value (get-char-attribute char 'numeric-value)))
812         (insert (format "(numeric-value\t. %S)%s"
813                         value
814                         line-breaking))
815         (setq attributes (delq 'numeric-value attributes))
816         )))
817     (when (and (memq 'iso-10646-comment attributes)
818                (setq value (get-char-attribute char 'iso-10646-comment)))
819       (insert (format "(iso-10646-comment\t. %S)%s"
820                       value
821                       line-breaking))
822       (setq attributes (delq 'iso-10646-comment attributes))
823       )
824     (when (and (memq 'morohashi-daikanwa attributes)
825                (setq value (get-char-attribute char 'morohashi-daikanwa)))
826       (insert (format "(morohashi-daikanwa\t%s)%s"
827                       (mapconcat (function prin1-to-string) value " ")
828                       line-breaking))
829       (setq attributes (delq 'morohashi-daikanwa attributes))
830       )
831     (setq radical nil
832           strokes nil)
833     (when (and (memq 'ideographic-radical attributes)
834                (setq value (get-char-attribute char 'ideographic-radical)))
835       (setq radical value)
836       (insert (format "(ideographic-radical . %S)\t; %c%s"
837                       radical
838                       (ideographic-radical radical)
839                       line-breaking))
840       (setq attributes (delq 'ideographic-radical attributes))
841       )
842     (when (and (memq 'shuowen-radical attributes)
843                (setq value (get-char-attribute char 'shuowen-radical)))
844       (insert (format "(shuowen-radical\t. %S)\t; %c%s"
845                       value
846                       (shuowen-radical value)
847                       line-breaking))
848       (setq attributes (delq 'shuowen-radical attributes))
849       )
850     (let (key)
851       (dolist (domain
852                (append
853                 char-db-feature-domains
854                 (let (dest domain)
855                   (dolist (feature (char-attribute-list))
856                     (setq feature (symbol-name feature))
857                     (when (string-match
858                            "\\(radical\\|strokes\\)@\\([^@*]+\\)\\(\\*\\|$\\)"
859                            feature)
860                       (setq domain (intern (match-string 2 feature)))
861                      (unless (memq domain dest)
862                        (setq dest (cons domain dest)))))
863                   (sort dest #'string<))))
864         (setq key (intern (format "%s@%s" 'ideographic-radical domain)))
865         (when (and (memq key attributes)
866                    (setq value (get-char-attribute char key)))
867           (setq radical value)
868           (insert (format "(%s . %S)\t; %c%s"
869                           key
870                           radical
871                           (ideographic-radical radical)
872                           line-breaking))
873           (setq attributes (delq key attributes))
874           )
875         (setq key (intern (format "%s@%s" 'ideographic-strokes domain)))
876         (when (and (memq key attributes)
877                    (setq value (get-char-attribute char key)))
878           (setq strokes value)
879           (insert (format "(%s . %S)%s"
880                           key
881                           strokes
882                           line-breaking))
883           (setq attributes (delq key attributes))
884           )
885         (setq key (intern (format "%s@%s" 'total-strokes domain)))
886         (when (and (memq key attributes)
887                    (setq value (get-char-attribute char key)))
888           (insert (format "(%s       . %S)%s"
889                           key
890                           value
891                           line-breaking))
892           (setq attributes (delq key attributes))
893           )
894         (dolist (feature '(ideographic-radical
895                            ideographic-strokes
896                            total-strokes))
897           (setq key (intern (format "%s@%s*sources" feature domain)))
898           (when (and (memq key attributes)
899                      (setq value (get-char-attribute char key)))
900             (insert (format "(%s%s" key line-breaking))
901             (dolist (cell value)
902               (insert (format " %s" cell)))
903             (insert ")")
904             (insert line-breaking)
905             (setq attributes (delq key attributes))
906             ))
907         ))
908     (when (and (memq 'ideographic-strokes attributes)
909                (setq value (get-char-attribute char 'ideographic-strokes)))
910       (setq strokes value)
911       (insert (format "(ideographic-strokes . %S)%s"
912                       strokes
913                       line-breaking))
914       (setq attributes (delq 'ideographic-strokes attributes))
915       )
916     (when (and (memq 'kangxi-radical attributes)
917                (setq value (get-char-attribute char 'kangxi-radical)))
918       (unless (eq value radical)
919         (insert (format "(kangxi-radical\t . %S)\t; %c%s"
920                         value
921                         (ideographic-radical value)
922                         line-breaking))
923         (or radical
924             (setq radical value)))
925       (setq attributes (delq 'kangxi-radical attributes))
926       )
927     (when (and (memq 'kangxi-strokes attributes)
928                (setq value (get-char-attribute char 'kangxi-strokes)))
929       (unless (eq value strokes)
930         (insert (format "(kangxi-strokes\t . %S)%s"
931                         value
932                         line-breaking))
933         (or strokes
934             (setq strokes value)))
935       (setq attributes (delq 'kangxi-strokes attributes))
936       )
937     (when (and (memq 'japanese-radical attributes)
938                (setq value (get-char-attribute char 'japanese-radical)))
939       (unless (eq value radical)
940         (insert (format "(japanese-radical\t . %S)\t; %c%s"
941                         value
942                         (ideographic-radical value)
943                         line-breaking))
944         (or radical
945             (setq radical value)))
946       (setq attributes (delq 'japanese-radical attributes))
947       )
948     (when (and (memq 'japanese-strokes attributes)
949                (setq value (get-char-attribute char 'japanese-strokes)))
950       (unless (eq value strokes)
951         (insert (format "(japanese-strokes\t . %S)%s"
952                         value
953                         line-breaking))
954         (or strokes
955             (setq strokes value)))
956       (setq attributes (delq 'japanese-strokes attributes))
957       )
958     (when (and (memq 'cns-radical attributes)
959                (setq value (get-char-attribute char 'cns-radical)))
960       (insert (format "(cns-radical\t . %S)\t; %c%s"
961                       value
962                       (ideographic-radical value)
963                       line-breaking))
964       (setq attributes (delq 'cns-radical attributes))
965       )
966     (when (and (memq 'cns-strokes attributes)
967                (setq value (get-char-attribute char 'cns-strokes)))
968       (unless (eq value strokes)
969         (insert (format "(cns-strokes\t . %S)%s"
970                         value
971                         line-breaking))
972         (or strokes
973             (setq strokes value)))
974       (setq attributes (delq 'cns-strokes attributes))
975       )
976     (when (and (memq 'shinjigen-1-radical attributes)
977                (setq value (get-char-attribute char 'shinjigen-1-radical)))
978       (unless (eq value radical)
979         (insert (format "(shinjigen-1-radical . %S)\t; %c%s"
980                         value
981                         (ideographic-radical value)
982                         line-breaking))
983         (or radical
984             (setq radical value)))
985       (setq attributes (delq 'shinjigen-1-radical attributes))
986       )
987     (when (and (memq 'ideographic- attributes)
988                (setq value (get-char-attribute char 'ideographic-)))
989       (insert "(ideographic-       ")
990       (setq lbs (concat "\n" (make-string (current-column) ?\ ))
991             separator nil)
992       (while (consp value)
993         (setq cell (car value))
994         (if (integerp cell)
995             (setq cell (decode-char '=ucs cell)))
996         (cond ((characterp cell)
997                (if separator
998                    (insert lbs))
999                (if readable
1000                    (insert (format "%S" cell))
1001                  (char-db-insert-char-spec cell readable))
1002                (setq separator lbs))
1003               ((consp cell)
1004                (if separator
1005                    (insert lbs))
1006                (if (consp (car cell))
1007                    (char-db-insert-char-spec cell readable)
1008                  (char-db-insert-char-reference cell readable))
1009                (setq separator lbs))
1010               (t
1011                (if separator
1012                    (insert separator))
1013                (insert (prin1-to-string cell))
1014                (setq separator " ")))
1015         (setq value (cdr value)))
1016       (insert ")")
1017       (insert line-breaking)
1018       (setq attributes (delq 'ideographic- attributes)))
1019     (when (and (memq 'total-strokes attributes)
1020                (setq value (get-char-attribute char 'total-strokes)))
1021       (insert (format "(total-strokes       . %S)%s"
1022                       value
1023                       line-breaking))
1024       (setq attributes (delq 'total-strokes attributes))
1025       )
1026     (when (and (memq '->ideograph attributes)
1027                (setq value (get-char-attribute char '->ideograph)))
1028       (insert (format "(->ideograph\t%s)%s"
1029                       (mapconcat (lambda (code)
1030                                    (cond ((symbolp code)
1031                                           (symbol-name code))
1032                                          ((integerp code)
1033                                           (format "#x%04X" code))
1034                                          (t
1035                                           (format "%s %S"
1036                                                   line-breaking code))))
1037                                  value " ")
1038                       line-breaking))
1039       (setq attributes (delq '->ideograph attributes))
1040       )
1041     ;; (when (and (memq '->decomposition attributes)
1042     ;;            (setq value (get-char-attribute char '->decomposition)))
1043     ;;   (insert (format "(->decomposition\t%s)%s"
1044     ;;                   (mapconcat (lambda (code)
1045     ;;                                (cond ((symbolp code)
1046     ;;                                       (symbol-name code))
1047     ;;                                      ((characterp code)
1048     ;;                                       (if readable
1049     ;;                                           (format "%S" code)
1050     ;;                                         (format "#x%04X"
1051     ;;                                                 (char-int code))
1052     ;;                                         ))
1053     ;;                                      ((integerp code)
1054     ;;                                       (format "#x%04X" code))
1055     ;;                                      (t
1056     ;;                                       (format "%s%S" line-breaking code))))
1057     ;;                              value " ")
1058     ;;                   line-breaking))
1059     ;;   (setq attributes (delq '->decomposition attributes))
1060     ;;   )
1061     (if (equal (get-char-attribute char '->titlecase)
1062                (get-char-attribute char '->uppercase))
1063         (setq attributes (delq '->titlecase attributes)))
1064     (when (and (memq '->mojikyo attributes)
1065                (setq value (get-char-attribute char '->mojikyo)))
1066       (insert (format "(->mojikyo\t\t. %06d)\t; %c%s"
1067                       value (decode-char 'mojikyo value)
1068                       line-breaking))
1069       (setq attributes (delq '->mojikyo attributes))
1070       )
1071     (when (and (memq 'hanyu-dazidian-vol attributes)
1072                (setq value (get-char-attribute char 'hanyu-dazidian-vol)))
1073       (insert (format "(hanyu-dazidian-vol  . %d)%s"
1074                       value line-breaking))
1075       (setq attributes (delq 'hanyu-dazidian-vol attributes))
1076       )
1077     (when (and (memq 'hanyu-dazidian-page attributes)
1078                (setq value (get-char-attribute char 'hanyu-dazidian-page)))
1079       (insert (format "(hanyu-dazidian-page . %d)%s"
1080                       value line-breaking))
1081       (setq attributes (delq 'hanyu-dazidian-page attributes))
1082       )
1083     (when (and (memq 'hanyu-dazidian-char attributes)
1084                (setq value (get-char-attribute char 'hanyu-dazidian-char)))
1085       (insert (format "(hanyu-dazidian-char . %d)%s"
1086                       value line-breaking))
1087       (setq attributes (delq 'hanyu-dazidian-char attributes))
1088       )
1089     (unless readable
1090       (dolist (ignored '(composition
1091                          ->denotational <-subsumptive ->ucs-unified
1092                          ->ideographic-component-forms))
1093         (setq attributes (delq ignored attributes))))
1094     (while attributes
1095       (setq name (car attributes))
1096       (if (setq value (get-char-attribute char name))
1097           (cond ((setq ret (find-charset name))
1098                  (setq name (charset-name ret))
1099                  (if (and (not (memq name dest-ccss))
1100                           (prog1
1101                               (setq value (get-char-attribute char name))
1102                             (setq dest-ccss (cons name dest-ccss))))
1103                      (char-db-insert-ccs-feature name value line-breaking))
1104                  )
1105                 ((string-match "^=>ucs@" (symbol-name name))
1106                  (insert (format "(%-18s . #x%04X)\t; %c%s"
1107                                  name value (decode-char '=ucs value)
1108                                  line-breaking))
1109                  )
1110                 ((eq name 'jisx0208-1978/4X)
1111                  (insert (format "(%-18s . #x%04X)%s"
1112                                  name value
1113                                  line-breaking))
1114                  )
1115                 ((and
1116                   (not readable)
1117                   (not (eq name '->subsumptive))
1118                   (not (eq name '->uppercase))
1119                   (not (eq name '->lowercase))
1120                   (not (eq name '->titlecase))
1121                   (not (eq name '->canonical))
1122                   (not (eq name '->Bopomofo))
1123                   (not (eq name '->mistakable))
1124                   (not (eq name '->ideographic-variants))
1125                   (null (get-char-attribute
1126                          char (intern (format "%s*sources" name))))
1127                   (not (string-match "\\*sources$" (symbol-name name)))
1128                   (null (get-char-attribute
1129                          char (intern (format "%s*note" name))))
1130                   (not (string-match "\\*note$" (symbol-name name)))
1131                   (or (eq name '<-identical)
1132                       (eq name '<-uppercase)
1133                       (eq name '<-lowercase)
1134                       (eq name '<-titlecase)
1135                       (eq name '<-canonical)
1136                       (eq name '<-ideographic-variants)
1137                       ;; (eq name '<-synonyms)
1138                       (string-match "^<-synonyms" (symbol-name name))
1139                       (eq name '<-mistakable)
1140                       (when (string-match "^->" (symbol-name name))
1141                         (cond
1142                          ((string-match "^->fullwidth" (symbol-name name))
1143                           (not (and (consp value)
1144                                     (characterp (car value))
1145                                     (encode-char
1146                                      (car value) '=ucs 'defined-only)))
1147                           )
1148                          (t)))
1149                       ))
1150                  )
1151                 ((or (eq name 'ideographic-structure)
1152                      (eq name 'ideographic-combination)
1153                      (eq name 'ideographic-)
1154                      (eq name '=decomposition)
1155                      (string-match "^=>decomposition" (symbol-name name))
1156                      (string-match "^\\(->\\|<-\\)[^*]*$" (symbol-name name))
1157                      (string-match "^\\(->\\|<-\\)[^*]*\\*sources$"
1158                                    (symbol-name name))
1159                      )
1160                  (char-db-insert-relation-feature char name value
1161                                                   line-breaking
1162                                                   ccss readable))
1163                 ((memq name '(ideograph=
1164                               original-ideograph-of
1165                               ancient-ideograph-of
1166                               vulgar-ideograph-of
1167                               wrong-ideograph-of
1168                               ;; simplified-ideograph-of
1169                               ideographic-variants
1170                               ;; ideographic-different-form-of
1171                               ))
1172                  (insert (format "(%-18s%s " name line-breaking))
1173                  (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1174                        separator nil)
1175                  (while (consp value)
1176                    (setq cell (car value))
1177                    (if (and (consp cell)
1178                             (consp (car cell)))
1179                        (progn
1180                          (if separator
1181                              (insert lbs))
1182                          (char-db-insert-alist cell readable)
1183                          (setq separator lbs))
1184                      (if separator
1185                          (insert separator))
1186                      (insert (prin1-to-string cell))
1187                      (setq separator " "))
1188                    (setq value (cdr value)))
1189                  (insert ")")
1190                  (insert line-breaking))
1191                 ((consp value)
1192                  (insert (format "(%-18s " name))
1193                  (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1194                        separator nil)
1195                  (while (consp value)
1196                    (setq cell (car value))
1197                    (if (and (consp cell)
1198                             (consp (car cell))
1199                             (setq ret (condition-case nil
1200                                           (find-char cell)
1201                                         (error nil))))
1202                        (progn
1203                          (setq rest cell
1204                                al nil
1205                                cal nil)
1206                          (while rest
1207                            (setq key (car (car rest)))
1208                            (if (find-charset key)
1209                                (setq cal (cons key cal))
1210                              (setq al (cons key al)))
1211                            (setq rest (cdr rest)))
1212                          (if separator
1213                              (insert lbs))
1214                          (insert-char-attributes ret
1215                                                  readable
1216                                                  al cal)
1217                          (setq separator lbs))
1218                      (setq ret (prin1-to-string cell))
1219                      (if separator
1220                          (if (< (+ (current-column)
1221                                    (length ret)
1222                                    (length separator))
1223                                 76)
1224                              (insert separator)
1225                            (insert lbs)))
1226                      (insert ret)
1227                      (setq separator " "))
1228                    (setq value (cdr value)))
1229                  (insert ")")
1230                  (insert line-breaking))
1231                 (t
1232                  (insert (format "(%-18s" name))
1233                  (setq ret (prin1-to-string value))
1234                  (unless (< (+ (current-column)
1235                                (length ret)
1236                                3)
1237                             76)
1238                    (insert line-breaking))
1239                  (insert " . " ret ")" line-breaking)
1240                  ;; (insert (format "(%-18s . %S)%s"
1241                  ;;                 name value
1242                  ;;                 line-breaking))
1243                  )
1244                 ))
1245       (setq attributes (cdr attributes)))
1246     (insert ")")))
1247
1248 (defun insert-char-data (char &optional readable
1249                               attributes)
1250   (save-restriction
1251     (narrow-to-region (point)(point))
1252     (insert "(define-char
1253   '")
1254     (insert-char-attributes char readable attributes)
1255     (insert ")\n")
1256     (goto-char (point-min))
1257     (while (re-search-forward "[ \t]+$" nil t)
1258       (replace-match ""))
1259     ;; from tabify.
1260     (goto-char (point-min))
1261     (while (re-search-forward "[ \t][ \t][ \t]*" nil t)
1262       (let ((column (current-column))
1263             (indent-tabs-mode t))
1264         (delete-region (match-beginning 0) (point))
1265         (indent-to column)))
1266     (goto-char (point-max))
1267     ;; (tabify (point-min)(point-max))
1268     ))
1269
1270 (defun insert-char-data-with-variant (char &optional printable
1271                                            no-ucs-unified
1272                                            script excluded-script)
1273   (insert-char-data char printable)
1274   (let ((variants (char-variants char))
1275         rest
1276         variant vs ret)
1277     (setq variants (sort variants #'<))
1278     (setq rest variants)
1279     (setq variants (cons char variants))
1280     (while rest
1281       (setq variant (car rest))
1282       (unless (get-char-attribute variant '<-subsumptive)
1283         (if (and (or (null script)
1284                      (null (setq vs (get-char-attribute variant 'script)))
1285                      (memq script vs))
1286                  (or (null excluded-script)
1287                      (null (setq vs (get-char-attribute variant 'script)))
1288                      (not (memq excluded-script vs))))
1289             (unless (and no-ucs-unified (get-char-attribute variant '=ucs))
1290               (insert-char-data variant printable)
1291               (if (setq ret (char-variants variant))
1292                   (while ret
1293                     (or (memq (car ret) variants)
1294                         ;; (get-char-attribute (car ret) '<-subsumptive)
1295                         (setq rest (nconc rest (list (car ret)))))
1296                     (setq ret (cdr ret)))))))
1297       (setq rest (cdr rest)))))
1298
1299 (defun insert-char-range-data (min max &optional script excluded-script)
1300   (let ((code min)
1301         char)
1302     (while (<= code max)
1303       (setq char (decode-char '=ucs code))
1304       (if (encode-char char '=ucs 'defined-only)
1305           (insert-char-data-with-variant char nil 'no-ucs-unified
1306                                          script excluded-script))
1307       (setq code (1+ code)))))
1308
1309 (defun write-char-range-data-to-file (min max file
1310                                           &optional script excluded-script)
1311   (let ((coding-system-for-write char-db-file-coding-system))
1312     (with-temp-buffer
1313       (insert (format ";; -*- coding: %s -*-\n"
1314                       char-db-file-coding-system))
1315       (insert-char-range-data min max script excluded-script)
1316       (write-region (point-min)(point-max) file))))
1317
1318 (defvar what-character-original-window-configuration)
1319
1320 ;;;###autoload
1321 (defun what-char-definition (char)
1322   (interactive (list (char-after)))
1323   (let ((buf (get-buffer-create "*Character Description*"))
1324         (the-buf (current-buffer))
1325         (win-conf (current-window-configuration)))
1326     (pop-to-buffer buf)
1327     (make-local-variable 'what-character-original-window-configuration)
1328     (setq what-character-original-window-configuration win-conf)
1329     (setq buffer-read-only nil)
1330     (erase-buffer)
1331     (condition-case err
1332         (progn
1333           (insert-char-data-with-variant char 'printable)
1334           (unless (char-attribute-alist char)
1335             (insert (format ";; = %c\n"
1336                             (let* ((rest (split-char char))
1337                                    (ccs (pop rest))
1338                                    (code (pop rest)))
1339                               (while rest
1340                                 (setq code (logior (lsh code 8)
1341                                                    (pop rest))))
1342                               (decode-char ccs code)))))
1343           ;; (char-db-update-comment)
1344           (set-buffer-modified-p nil)
1345           (view-mode the-buf (lambda (buf)
1346                                (set-window-configuration
1347                                 what-character-original-window-configuration)
1348                                ))
1349           (goto-char (point-min)))
1350       (error (progn
1351                (set-window-configuration
1352                 what-character-original-window-configuration)
1353                (signal (car err) (cdr err)))))))
1354
1355 (provide 'char-db-util)
1356
1357 ;;; char-db-util.el ends here