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