Add `=decomposition@cid' for some Adobe-Japan1 characters.
[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, 2009, 2010, 2011, 2012, 2013 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     =+>adobe-japan1-0
218     =+>adobe-japan1-1
219     =+>adobe-japan1-2
220     =+>adobe-japan1-3
221     =+>adobe-japan1-4
222     =+>adobe-japan1-5
223     =+>adobe-japan1-6
224     =+>jis-x0208@1978
225     =>jis-x0208
226     =>jis-x0208@1997
227     =>jis-x0213-1
228     =>jis-x0213-1@2000
229     =>jis-x0213-1@2004
230     =>jis-x0213-2
231     ==>ucs@bucs
232     =>ucs@iso
233     =>ucs@unicode
234     =>ucs@jis
235     =>ucs@cns
236     =>ucs@ks
237     =+>ucs@iso
238     =+>ucs@unicode
239     =+>ucs@jis
240     =+>ucs@jis/1990
241     =+>ucs@cns
242     =+>ucs@ks
243     =>>ucs@iso
244     =>>ucs@unicode
245     =>>ucs@jis
246     =>>ucs@cns
247     =>>>ucs@iso
248     =>>>ucs@unicode
249     =ucs@iso
250     =ucs@unicode
251     =>>big5-cdp
252     =>>gt-k
253     =+>gt
254     =>gt
255     =>big5-cdp
256     =>daikanwa
257     =>daikanwa/ho
258     =>cns11643-7
259     =big5
260     =big5-eten
261     =>gt-k
262     =zinbun-oracle
263     =>zinbun-oracle
264     =ruimoku-v6
265     =>>ruimoku-v6
266     =jef-china3
267     =shinjigen
268     =big5-cdp-var-3
269     =big5-cdp-var-5))
270
271
272 ;;; @ char-db formatters
273 ;;;
274
275 (defun char-db-make-char-spec (char)
276   (let (ret char-spec)
277     (cond ((characterp char)
278            (cond ((and (setq ret (encode-char char '=ucs 'defined-only))
279                        (not (and (<= #xE000 ret)(<= ret #xF8FF))))
280                   (setq char-spec (list (cons '=ucs ret)))
281                   (cond ((setq ret (get-char-attribute char 'name))
282                          (setq char-spec (cons (cons 'name ret) char-spec))
283                          )
284                         ((setq ret (get-char-attribute char 'name*))
285                          (setq char-spec (cons (cons 'name* ret) char-spec))
286                          ))
287                   )
288                  ((encode-char char '=adobe-japan1 'defined-only)
289                   (setq char-spec nil)
290                   (dolist (ccs (charset-list))
291                     (if (and (or (memq ccs
292                                        '(=adobe-japan1-0
293                                          =adobe-japan1-1
294                                          =adobe-japan1-2
295                                          =adobe-japan1-3
296                                          =adobe-japan1-4
297                                          =adobe-japan1-5
298                                          =adobe-japan1-6
299                                          ))
300                                  ;; (eq (charset-property ccs 'iso-ir) 177)
301                                  (string-match "=ucs@" (symbol-name ccs))
302                                  )
303                              (setq ccs (charset-name ccs))
304                              (null (assq ccs char-spec))
305                              (setq ret (encode-char char ccs 'defined-only)))
306                         (setq char-spec (cons (cons ccs ret) char-spec))))
307                   )
308                  ((setq ret
309                         (catch 'tag
310                           (let ((rest char-db-coded-charset-priority-list)
311                                 ccs)
312                             (while rest
313                               (setq ccs (charset-name
314                                          (find-charset (car rest))))
315                               (if (setq ret
316                                         (encode-char char ccs
317                                                      'defined-only))
318                                   (throw 'tag (cons ccs ret)))
319                               (setq rest (cdr rest))))))
320                   (setq char-spec (list ret))
321                   (dolist (ccs (delq (car ret) (charset-list)))
322                     (if (and (or (charset-iso-final-char ccs)
323                                  (memq ccs
324                                        '(=daikanwa
325                                          =daikanwa@rev2
326                                          ;; =gt-k
327                                          =jis-x0208@1997
328                                          ))
329                                  (eq (charset-property ccs 'iso-ir) 177)
330                                  ;; (string-match "=ucs@" (symbol-name ccs))
331                                  )
332                              (setq ccs (charset-name ccs))
333                              (null (assq ccs char-spec))
334                              (setq ret (encode-char char ccs 'defined-only)))
335                         (setq char-spec (cons (cons ccs ret) char-spec))))
336                   (if (null char-spec)
337                       (setq char-spec (split-char char)))
338                   (cond ((setq ret (get-char-attribute char 'name))
339                          (setq char-spec (cons (cons 'name ret) char-spec))
340                          )
341                         ((setq ret (get-char-attribute char 'name*))
342                          (setq char-spec (cons (cons 'name* ret) char-spec))
343                          ))
344                   )
345                  ((setq ret (get-char-attribute
346                              char 'ideographic-combination))
347                   (setq char-spec
348                         (cons (cons 'ideographic-combination ret)
349                               char-spec))
350                   ))
351            char-spec)
352           ((consp char)
353            char))))
354     
355 (defun char-db-insert-char-spec (char &optional readable column
356                                       required-features)
357   (unless column
358     (setq column (current-column)))
359   (let (char-spec temp-char)
360     (setq char-spec (char-db-make-char-spec char))
361     (unless (or (characterp char) ; char
362                 (condition-case nil
363                     (setq char (find-char char-spec))
364                   (error nil)))
365       ;; define temporary character
366       ;;   Current implementation is dirty.
367       (setq temp-char (define-char (cons '(ideograph-daikanwa . 0)
368                                          char-spec)))
369       (remove-char-attribute temp-char 'ideograph-daikanwa)
370       (setq char temp-char))
371     (insert-char-attributes char
372                             readable
373                             (union (mapcar #'car char-spec)
374                                    required-features)
375                             nil 'for-sub-node)
376     (when temp-char
377       ;; undefine temporary character
378       ;;   Current implementation is dirty.
379       (setq char-spec (char-attribute-alist temp-char))
380       (while char-spec
381         (remove-char-attribute temp-char (car (car char-spec)))
382         (setq char-spec (cdr char-spec))))))
383
384 (defun char-db-insert-alist (alist &optional readable column)
385   (unless column
386     (setq column (current-column)))
387   (let ((line-breaking
388          (concat "\n" (make-string (1+ column) ?\ )))
389         name value
390         ret al ; cal
391         key
392         lbs cell rest separator)
393     (insert "(")
394     (while alist
395       (setq name (car (car alist))
396             value (cdr (car alist)))
397       (cond ((eq name 'char)
398              (insert "(char . ")
399              (if (setq ret (condition-case nil
400                                (find-char value)
401                              (error nil)))
402                  (progn
403                    (setq al nil
404                          ;; cal nil
405                          )
406                    (while value
407                      (setq key (car (car value)))
408                      ;; (if (find-charset key)
409                      ;;     (setq cal (cons key cal))
410                      (setq al (cons key al))
411                      ;; )
412                      (setq value (cdr value)))
413                    (insert-char-attributes ret
414                                            readable
415                                            (or al 'none) ; cal
416                                            nil 'for-sub-node))
417                (insert (prin1-to-string value)))
418              (insert ")")
419              (insert line-breaking))
420             ((consp value)
421              (insert (format "(%-18s " name))
422              (setq lbs (concat "\n" (make-string (current-column) ?\ )))
423              (while (consp value)
424                (setq cell (car value))
425                (if (and (consp cell)
426                         (consp (car cell))
427                         (setq ret (condition-case nil
428                                       (find-char cell)
429                                     (error nil)))
430                         )
431                    (progn
432                      (setq rest cell
433                            al nil
434                            ;; cal nil
435                            )
436                      (while rest
437                        (setq key (car (car rest)))
438                        ;; (if (find-charset key)
439                        ;;     (setq cal (cons key cal))
440                        (setq al (cons key al))
441                        ;; )
442                        (setq rest (cdr rest)))
443                      (if separator
444                          (insert lbs))
445                      (insert-char-attributes ret
446                                              readable
447                                              al ; cal
448                                              nil 'for-sub-node)
449                      (setq separator lbs))
450                  (if separator
451                      (insert separator))
452                  (insert (prin1-to-string cell))
453                  (setq separator " "))
454                (setq value (cdr value)))
455              (insert ")")
456              (insert line-breaking))
457             (t
458              (insert (format "(%-18s . %S)%s"
459                              name value
460                              line-breaking))))
461       (setq alist (cdr alist))))
462   (insert ")"))
463
464 (defun char-db-insert-char-reference (plist &optional readable column)
465   (unless column
466     (setq column (current-column)))
467   (let ((line-breaking
468          (concat "\n" (make-string (1+ column) ?\ )))
469         (separator "")
470         name value)
471     (insert "(")
472     (while plist
473       (setq name (pop plist))
474       (setq value (pop plist))
475       (cond ((eq name :char)
476              (insert separator)
477              (insert ":char\t")
478              (cond ((numberp value)
479                     (setq value (decode-char '=ucs value)))
480                    ;; ((consp value)
481                    ;;  (setq value (or (find-char value)
482                    ;;                  value)))
483                    )
484              (char-db-insert-char-spec value readable)
485              (insert line-breaking)
486              (setq separator ""))
487             ((eq name :radical)
488              (insert (format "%s%s\t%d ; %c%s"
489                              separator
490                              name value
491                              (ideographic-radical value)
492                              line-breaking))
493              (setq separator ""))
494             (t
495              (insert (format "%s%s\t%S" separator name value))
496              (setq separator line-breaking)))
497       ))
498   (insert ")"))
499
500 (defun char-db-decode-isolated-char (ccs code-point)
501   (let (ret)
502     (setq ret
503           (cond ((eq ccs 'arabic-iso8859-6)
504                  (decode-char ccs code-point))
505                 ((and (memq ccs '(=gt-pj-1
506                                   =gt-pj-2
507                                   =gt-pj-3
508                                   =gt-pj-4
509                                   =gt-pj-5
510                                   =gt-pj-6
511                                   =gt-pj-7
512                                   =gt-pj-8
513                                   =gt-pj-9
514                                   =gt-pj-10
515                                   =gt-pj-11))
516                       (setq ret (decode-char ccs code-point))
517                       (setq ret (encode-char ret '=gt 'defined-only)))
518                  (decode-builtin-char '=gt ret))
519                 (t
520                  (decode-builtin-char ccs code-point))))
521     (cond ((and (<= 0 (char-int ret))
522                 (<= (char-int ret) #x1F))
523            (decode-char '=ucs (+ #x2400 (char-int ret))))
524           ((= (char-int ret) #x7F)
525            ?\u2421)
526           (t ret))))
527
528 (defvar char-db-convert-obsolete-format t)
529
530 (defun char-db-insert-ccs-feature (name value line-breaking)
531   (cond
532    ((integerp value)
533     (insert
534      (format
535       (cond
536        ((memq name '(=shinjigen
537                      =shinjigen@1ed
538                      =shinjigen@rev =shinjigen/+p@rev
539                      =daikanwa/ho =>>daikanwa/ho =>daikanwa/ho))
540         "(%-18s .  %04d)\t; %c")
541        ((eq name '=shinjigen@1ed/24pr)
542         "(%-18s . %04d)\t; %c")
543        ((or (memq name '(=daikanwa =>>daikanwa =>daikanwa
544                          =daikanwa@rev1 =daikanwa@rev2
545                          =daikanwa/+p =>>daikanwa/+p
546                          =daikanwa/+2p =>>daikanwa/+2p
547                          =gt =>>>gt =>>gt =+>gt =>gt
548                          =gt-k =>>gt-k =>gt-k
549                          =adobe-japan1-0 =>>>adobe-japan1-0
550                          =adobe-japan1-1 =>>>adobe-japan1-1
551                          =adobe-japan1-2 =>>>adobe-japan1-2
552                          =adobe-japan1-3 =>>>adobe-japan1-3
553                          =adobe-japan1-4 =>>>adobe-japan1-4
554                          =adobe-japan1-5 =>>>adobe-japan1-5
555                          =adobe-japan1-6 =>>>adobe-japan1-6
556                          =>>adobe-japan1-0 =+>adobe-japan1-0
557                          =>>adobe-japan1-1 =+>adobe-japan1-1
558                          =>>adobe-japan1-2 =+>adobe-japan1-2
559                          =>>adobe-japan1-3 =+>adobe-japan1-3
560                          =>>adobe-japan1-4 =+>adobe-japan1-4
561                          =>>adobe-japan1-5 =+>adobe-japan1-5
562                          =>>adobe-japan1-6 =+>adobe-japan1-6
563                          =cbeta =>>cbeta
564                          =zinbun-oracle =>zinbun-oracle))
565             ;; (string-match "^=adobe-" (symbol-name name))
566             )
567         "(%-18s . %05d)\t; %c")
568        ((memq name '(=hanyo-denshi/ks
569                      =>>>hanyo-denshi/ks =>>hanyo-denshi/ks
570                      =zihai mojikyo))
571         "(%-18s . %06d)\t; %c")
572        ((>= (charset-dimension name) 2)
573         "(%-18s . #x%04X)\t; %c")
574        (t
575         "(%-18s . #x%02X)\t; %c"))
576       name
577       (if (= (charset-iso-graphic-plane name) 1)
578           (logior value
579                   (cond ((= (charset-dimension name) 1)
580                          #x80)
581                         ((= (charset-dimension name) 2)
582                          #x8080)
583                         ((= (charset-dimension name) 3)
584                          #x808080)
585                         (t 0)))
586         value)
587       (char-db-decode-isolated-char name value)))
588     (if (and (= (charset-chars name) 94)
589              (= (charset-dimension name) 2))
590         (insert (format " [%02d-%02d]"
591                         (- (lsh value -8) 32)
592                         (- (logand value 255) 32))))
593     )
594    (t
595     (insert (format "(%-18s . %s)" name value))
596     ))
597   (insert line-breaking))
598
599 (defun char-db-insert-relation-feature (char name value line-breaking
600                                              ccss readable)
601   (insert (format "(%-18s%s " name line-breaking))
602   (let ((lbs (concat "\n" (make-string (current-column) ?\ )))
603         separator cell sources required-features
604         ret)
605     (while (consp value)
606       (setq cell (car value))
607       (if (integerp cell)
608           (setq cell (decode-char '=ucs cell)))
609       (cond
610        ((eq name '->subsumptive)
611         (when (or (not (some (lambda (atr)
612                                (get-char-attribute cell atr))
613                              char-db-ignored-attributes))
614                   (some (lambda (ccs)
615                           (encode-char cell ccs 'defined-only))
616                         ccss))
617           (if separator
618               (insert lbs))
619           (let ((char-db-ignored-attributes
620                  (cons '<-subsumptive
621                        char-db-ignored-attributes)))
622             (insert-char-attributes cell readable nil nil 'for-sub-node))
623           (setq separator lbs))
624         )
625        ((characterp cell)
626         (setq sources
627               (get-char-attribute
628                char (intern (format "%s*sources" name))))
629         (setq required-features nil)
630         (dolist (source sources)
631           (cond
632            ((memq source '(JP
633                            JP/Jouyou
634                            shinjigen shinjigen@1ed shinjigen@rev))
635             (setq required-features
636                   (union required-features
637                          '(=jis-x0208
638                            =jis-x0208@1990
639                            =jis-x0213-1@2000
640                            =jis-x0213-1@2004
641                            =jis-x0213-2
642                            =jis-x0212
643                            =jis-x0208@1983
644                            =jis-x0208@1978
645                            =shinjigen
646                            =shinjigen@1ed
647                            =shinjigen@rev
648                            =shinjigen/+p@rev))))
649            ((eq source 'CN)
650             (setq required-features
651                   (union required-features
652                          '(=gb2312
653                            =gb12345
654                            =iso-ir165)))))
655           (cond
656            ((find-charset (setq ret (intern (format "=%s" source))))
657             (setq required-features
658                   (cons ret required-features)))
659            (t (setq required-features
660                     (cons source required-features)))))
661         (cond ((string-match "@JP" (symbol-name name))
662                (setq required-features
663                      (union required-features
664                             '(=jis-x0208
665                               =jis-x0208@1990
666                               =jis-x0213-1-2000
667                               =jis-x0213-2-2000
668                               =jis-x0212
669                               =jis-x0208@1983
670                               =jis-x0208@1978))))
671               ((string-match "@CN" (symbol-name name))
672                (setq required-features
673                      (union required-features
674                             '(=gb2312
675                               =gb12345
676                               =iso-ir165)))))
677         (if separator
678             (insert lbs))
679         (if readable
680             (insert (format "%S" cell))
681           (char-db-insert-char-spec cell readable
682                                     nil
683                                     required-features))
684         (setq separator lbs))
685        ((consp cell)
686         (if separator
687             (insert lbs))
688         (if (consp (car cell))
689             (char-db-insert-char-spec cell readable)
690           (char-db-insert-char-reference cell readable))
691         (setq separator lbs))
692        (t
693         (if separator
694             (insert separator))
695         (insert (prin1-to-string cell))
696         (setq separator " ")))
697       (setq value (cdr value)))
698     (insert ")")
699     (insert line-breaking)))
700
701 (defun insert-char-attributes (char &optional readable attributes column
702                                     for-sub-node)
703   (unless column
704     (setq column (current-column)))
705   (let (name value ; has-long-ccs-name
706         rest
707         radical strokes
708         (line-breaking
709          (concat "\n" (make-string (1+ column) ?\ )))
710         lbs cell separator ret
711         key al cal
712         dest-ccss ; sources required-features
713         ccss)
714     (let (atr-d)
715       (setq attributes
716             (sort (if attributes
717                       (if (consp attributes)
718                           (progn
719                             (dolist (name attributes)
720                               (unless (memq name char-db-ignored-attributes)
721                                 (if (find-charset name)
722                                     (push name ccss))
723                                 (push name atr-d)))
724                             atr-d))
725                     (dolist (name (char-attribute-list))
726                       (unless (memq name char-db-ignored-attributes)
727                         (if (find-charset name)
728                             (push name ccss))
729                         (push name atr-d)))
730                     atr-d)
731                   #'char-attribute-name<)))
732     (insert "(")
733     (when (memq '<-subsumptive attributes)
734       (when (or readable (not for-sub-node))
735         (when (setq value (get-char-attribute char '<-subsumptive))
736           (char-db-insert-relation-feature char '<-subsumptive value
737                                            line-breaking
738                                            ccss readable)))
739       (setq attributes (delq '<-subsumptive attributes)))
740     (when (and (memq '<-denotational attributes)
741                (setq value (get-char-attribute char '<-denotational)))
742       (char-db-insert-relation-feature char '<-denotational value
743                                        line-breaking
744                                        ccss readable)
745       (setq attributes (delq '<-denotational attributes)))
746     (when (and (memq 'name attributes)
747                (setq value (get-char-attribute char 'name)))
748       (insert (format
749                (if (> (+ (current-column) (length value)) 48)
750                    "(name . %S)%s"
751                  "(name               . %S)%s")
752                value line-breaking))
753       (setq attributes (delq 'name attributes))
754       )
755     (when (and (memq 'name* attributes)
756                (setq value (get-char-attribute char 'name*)))
757       (insert (format
758                (if (> (+ (current-column) (length value)) 48)
759                    "(name* . %S)%s"
760                  "(name*              . %S)%s")
761                value line-breaking))
762       (setq attributes (delq 'name* attributes))
763       )
764     (when (and (memq 'script attributes)
765                (setq value (get-char-attribute char 'script)))
766       (insert (format "(script\t\t%s)%s"
767                       (mapconcat (function prin1-to-string)
768                                  value " ")
769                       line-breaking))
770       (setq attributes (delq 'script attributes))
771       )
772     (dolist (name '(=>ucs =>ucs*))
773       (when (and (memq name attributes)
774                  (setq value (get-char-attribute char name)))
775         (insert (format "(%-18s . #x%04X)\t; %c%s"
776                         name value (decode-char '=ucs value)
777                         line-breaking))
778         (setq attributes (delq name attributes))))
779     (dolist (name '(=>ucs@gb =>ucs@big5))
780       (when (and (memq name attributes)
781                  (setq value (get-char-attribute char name)))
782         (insert (format "(%-18s . #x%04X)\t; %c%s"
783                         name value
784                         (decode-char (intern
785                                       (concat "="
786                                               (substring
787                                                (symbol-name name) 2)))
788                                      value)
789                         line-breaking))
790         (setq attributes (delq name attributes))
791         ))
792     ;; (dolist (name '(=>daikanwa))
793     ;;   (when (and (memq name attributes)
794     ;;              (setq value (get-char-attribute char name)))
795     ;;     (insert
796     ;;      (if (integerp value)
797     ;;          (format "(%-18s . %05d)\t; %c%s"
798     ;;                  name value (decode-char '=daikanwa value)
799     ;;                  line-breaking)
800     ;;        (format "(%-18s %s)\t; %c%s"
801     ;;                name
802     ;;                (mapconcat (function prin1-to-string)
803     ;;                           value " ")
804     ;;                (char-representative-of-daikanwa char)
805     ;;                line-breaking)))
806     ;;     (setq attributes (delq name attributes))))
807     (when (and (memq 'general-category attributes)
808                (setq value (get-char-attribute char 'general-category)))
809       (insert (format
810                "(general-category\t%s) ; %s%s"
811                (mapconcat (lambda (cell)
812                             (format "%S" cell))
813                           value " ")
814                (cond ((rassoc value unidata-normative-category-alist)
815                       "Normative Category")
816                      ((rassoc value unidata-informative-category-alist)
817                       "Informative Category")
818                      (t
819                       "Unknown Category"))
820                line-breaking))
821       (setq attributes (delq 'general-category attributes))
822       )
823     (when (and (memq 'bidi-category attributes)
824                (setq value (get-char-attribute char 'bidi-category)))
825       (insert (format "(bidi-category\t. %S)%s"
826                       value
827                       line-breaking))
828       (setq attributes (delq 'bidi-category attributes))
829       )
830     (unless (or (not (memq 'mirrored attributes))
831                 (eq (setq value (get-char-attribute char 'mirrored 'empty))
832                     'empty))
833       (insert (format "(mirrored\t\t. %S)%s"
834                       value
835                       line-breaking))
836       (setq attributes (delq 'mirrored attributes))
837       )
838     (cond
839      ((and (memq 'decimal-digit-value attributes)
840            (setq value (get-char-attribute char 'decimal-digit-value)))
841       (insert (format "(decimal-digit-value . %S)%s"
842                       value
843                       line-breaking))
844       (setq attributes (delq 'decimal-digit-value attributes))
845       (when (and (memq 'digit-value attributes)
846                  (setq value (get-char-attribute char 'digit-value)))
847         (insert (format "(digit-value\t . %S)%s"
848                         value
849                         line-breaking))
850         (setq attributes (delq 'digit-value attributes))
851         )
852       (when (and (memq 'numeric-value attributes)
853                  (setq value (get-char-attribute char 'numeric-value)))
854         (insert (format "(numeric-value\t . %S)%s"
855                         value
856                         line-breaking))
857         (setq attributes (delq 'numeric-value attributes))
858         )
859       )
860      (t
861       (when (and (memq 'digit-value attributes)
862                  (setq value (get-char-attribute char 'digit-value)))
863         (insert (format "(digit-value\t. %S)%s"
864                         value
865                         line-breaking))
866         (setq attributes (delq 'digit-value attributes))
867         )
868       (when (and (memq 'numeric-value attributes)
869                  (setq value (get-char-attribute char 'numeric-value)))
870         (insert (format "(numeric-value\t. %S)%s"
871                         value
872                         line-breaking))
873         (setq attributes (delq 'numeric-value attributes))
874         )))
875     (when (and (memq 'iso-10646-comment attributes)
876                (setq value (get-char-attribute char 'iso-10646-comment)))
877       (insert (format "(iso-10646-comment\t. %S)%s"
878                       value
879                       line-breaking))
880       (setq attributes (delq 'iso-10646-comment attributes))
881       )
882     (when (and (memq 'morohashi-daikanwa attributes)
883                (setq value (get-char-attribute char 'morohashi-daikanwa)))
884       (insert (format "(morohashi-daikanwa\t%s)%s"
885                       (mapconcat (function prin1-to-string) value " ")
886                       line-breaking))
887       (setq attributes (delq 'morohashi-daikanwa attributes))
888       )
889     (setq radical nil
890           strokes nil)
891     (when (and (memq 'ideographic-radical attributes)
892                (setq value (get-char-attribute char 'ideographic-radical)))
893       (setq radical value)
894       (insert (format "(ideographic-radical . %S)\t; %c%s"
895                       radical
896                       (ideographic-radical radical)
897                       line-breaking))
898       (setq attributes (delq 'ideographic-radical attributes))
899       )
900     (when (and (memq 'shuowen-radical attributes)
901                (setq value (get-char-attribute char 'shuowen-radical)))
902       (insert (format "(shuowen-radical\t. %S)\t; %c%s"
903                       value
904                       (shuowen-radical value)
905                       line-breaking))
906       (setq attributes (delq 'shuowen-radical attributes))
907       )
908     (let (key)
909       (dolist (domain
910                (append
911                 char-db-feature-domains
912                 (let (dest domain)
913                   (dolist (feature (char-attribute-list))
914                     (setq feature (symbol-name feature))
915                     (when (string-match
916                            "\\(radical\\|strokes\\)@\\([^@*]+\\)\\(\\*\\|$\\)"
917                            feature)
918                       (setq domain (intern (match-string 2 feature)))
919                      (unless (memq domain dest)
920                        (setq dest (cons domain dest)))))
921                   (sort dest #'string<))))
922         (setq key (intern (format "%s@%s" 'ideographic-radical domain)))
923         (when (and (memq key attributes)
924                    (setq value (get-char-attribute char key)))
925           (setq radical value)
926           (insert (format "(%s . %S)\t; %c%s"
927                           key
928                           radical
929                           (ideographic-radical radical)
930                           line-breaking))
931           (setq attributes (delq key attributes))
932           )
933         (setq key (intern (format "%s@%s" 'ideographic-strokes domain)))
934         (when (and (memq key attributes)
935                    (setq value (get-char-attribute char key)))
936           (setq strokes value)
937           (insert (format "(%s . %S)%s"
938                           key
939                           strokes
940                           line-breaking))
941           (setq attributes (delq key attributes))
942           )
943         (setq key (intern (format "%s@%s" 'total-strokes domain)))
944         (when (and (memq key attributes)
945                    (setq value (get-char-attribute char key)))
946           (insert (format "(%s       . %S)%s"
947                           key
948                           value
949                           line-breaking))
950           (setq attributes (delq key attributes))
951           )
952         (dolist (feature '(ideographic-radical
953                            ideographic-strokes
954                            total-strokes))
955           (setq key (intern (format "%s@%s*sources" feature domain)))
956           (when (and (memq key attributes)
957                      (setq value (get-char-attribute char key)))
958             (insert (format "(%s%s" key line-breaking))
959             (dolist (cell value)
960               (insert (format " %s" cell)))
961             (insert ")")
962             (insert line-breaking)
963             (setq attributes (delq key attributes))
964             ))
965         ))
966     (when (and (memq 'ideographic-strokes attributes)
967                (setq value (get-char-attribute char 'ideographic-strokes)))
968       (setq strokes value)
969       (insert (format "(ideographic-strokes . %S)%s"
970                       strokes
971                       line-breaking))
972       (setq attributes (delq 'ideographic-strokes attributes))
973       )
974     (when (and (memq 'kangxi-radical attributes)
975                (setq value (get-char-attribute char 'kangxi-radical)))
976       (unless (eq value radical)
977         (insert (format "(kangxi-radical\t . %S)\t; %c%s"
978                         value
979                         (ideographic-radical value)
980                         line-breaking))
981         (or radical
982             (setq radical value)))
983       (setq attributes (delq 'kangxi-radical attributes))
984       )
985     (when (and (memq 'kangxi-strokes attributes)
986                (setq value (get-char-attribute char 'kangxi-strokes)))
987       (unless (eq value strokes)
988         (insert (format "(kangxi-strokes\t . %S)%s"
989                         value
990                         line-breaking))
991         (or strokes
992             (setq strokes value)))
993       (setq attributes (delq 'kangxi-strokes attributes))
994       )
995     (when (and (memq 'japanese-radical attributes)
996                (setq value (get-char-attribute char 'japanese-radical)))
997       (unless (eq value radical)
998         (insert (format "(japanese-radical\t . %S)\t; %c%s"
999                         value
1000                         (ideographic-radical value)
1001                         line-breaking))
1002         (or radical
1003             (setq radical value)))
1004       (setq attributes (delq 'japanese-radical attributes))
1005       )
1006     (when (and (memq 'japanese-strokes attributes)
1007                (setq value (get-char-attribute char 'japanese-strokes)))
1008       (unless (eq value strokes)
1009         (insert (format "(japanese-strokes\t . %S)%s"
1010                         value
1011                         line-breaking))
1012         (or strokes
1013             (setq strokes value)))
1014       (setq attributes (delq 'japanese-strokes attributes))
1015       )
1016     (when (and (memq 'cns-radical attributes)
1017                (setq value (get-char-attribute char 'cns-radical)))
1018       (insert (format "(cns-radical\t . %S)\t; %c%s"
1019                       value
1020                       (ideographic-radical value)
1021                       line-breaking))
1022       (setq attributes (delq 'cns-radical attributes))
1023       )
1024     (when (and (memq 'cns-strokes attributes)
1025                (setq value (get-char-attribute char 'cns-strokes)))
1026       (unless (eq value strokes)
1027         (insert (format "(cns-strokes\t . %S)%s"
1028                         value
1029                         line-breaking))
1030         (or strokes
1031             (setq strokes value)))
1032       (setq attributes (delq 'cns-strokes attributes))
1033       )
1034     ;; (when (and (memq 'shinjigen-1-radical attributes)
1035     ;;            (setq value (get-char-attribute char 'shinjigen-1-radical)))
1036     ;;   (unless (eq value radical)
1037     ;;     (insert (format "(shinjigen-1-radical . %S)\t; %c%s"
1038     ;;                     value
1039     ;;                     (ideographic-radical value)
1040     ;;                     line-breaking))
1041     ;;     (or radical
1042     ;;         (setq radical value)))
1043     ;;   (setq attributes (delq 'shinjigen-1-radical attributes))
1044     ;;   )
1045     (when (and (memq 'ideographic- attributes)
1046                (setq value (get-char-attribute char 'ideographic-)))
1047       (insert "(ideographic-       ")
1048       (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1049             separator nil)
1050       (while (consp value)
1051         (setq cell (car value))
1052         (if (integerp cell)
1053             (setq cell (decode-char '=ucs cell)))
1054         (cond ((characterp cell)
1055                (if separator
1056                    (insert lbs))
1057                (if readable
1058                    (insert (format "%S" cell))
1059                  (char-db-insert-char-spec cell readable))
1060                (setq separator lbs))
1061               ((consp cell)
1062                (if separator
1063                    (insert lbs))
1064                (if (consp (car cell))
1065                    (char-db-insert-char-spec cell readable)
1066                  (char-db-insert-char-reference cell readable))
1067                (setq separator lbs))
1068               (t
1069                (if separator
1070                    (insert separator))
1071                (insert (prin1-to-string cell))
1072                (setq separator " ")))
1073         (setq value (cdr value)))
1074       (insert ")")
1075       (insert line-breaking)
1076       (setq attributes (delq 'ideographic- attributes)))
1077     (when (and (memq 'total-strokes attributes)
1078                (setq value (get-char-attribute char 'total-strokes)))
1079       (insert (format "(total-strokes       . %S)%s"
1080                       value
1081                       line-breaking))
1082       (setq attributes (delq 'total-strokes attributes))
1083       )
1084     (when (and (memq '->ideograph attributes)
1085                (setq value (get-char-attribute char '->ideograph)))
1086       (insert (format "(->ideograph\t%s)%s"
1087                       (mapconcat (lambda (code)
1088                                    (cond ((symbolp code)
1089                                           (symbol-name code))
1090                                          ((integerp code)
1091                                           (format "#x%04X" code))
1092                                          (t
1093                                           (format "%s %S"
1094                                                   line-breaking code))))
1095                                  value " ")
1096                       line-breaking))
1097       (setq attributes (delq '->ideograph attributes))
1098       )
1099     ;; (when (and (memq '->decomposition attributes)
1100     ;;            (setq value (get-char-attribute char '->decomposition)))
1101     ;;   (insert (format "(->decomposition\t%s)%s"
1102     ;;                   (mapconcat (lambda (code)
1103     ;;                                (cond ((symbolp code)
1104     ;;                                       (symbol-name code))
1105     ;;                                      ((characterp code)
1106     ;;                                       (if readable
1107     ;;                                           (format "%S" code)
1108     ;;                                         (format "#x%04X"
1109     ;;                                                 (char-int code))
1110     ;;                                         ))
1111     ;;                                      ((integerp code)
1112     ;;                                       (format "#x%04X" code))
1113     ;;                                      (t
1114     ;;                                       (format "%s%S" line-breaking code))))
1115     ;;                              value " ")
1116     ;;                   line-breaking))
1117     ;;   (setq attributes (delq '->decomposition attributes))
1118     ;;   )
1119     (if (equal (get-char-attribute char '->titlecase)
1120                (get-char-attribute char '->uppercase))
1121         (setq attributes (delq '->titlecase attributes)))
1122     (when (and (memq '->mojikyo attributes)
1123                (setq value (get-char-attribute char '->mojikyo)))
1124       (insert (format "(->mojikyo\t\t. %06d)\t; %c%s"
1125                       value (decode-char 'mojikyo value)
1126                       line-breaking))
1127       (setq attributes (delq '->mojikyo attributes))
1128       )
1129     (when (and (memq 'hanyu-dazidian-vol attributes)
1130                (setq value (get-char-attribute char 'hanyu-dazidian-vol)))
1131       (insert (format "(hanyu-dazidian-vol  . %d)%s"
1132                       value line-breaking))
1133       (setq attributes (delq 'hanyu-dazidian-vol attributes))
1134       )
1135     (when (and (memq 'hanyu-dazidian-page attributes)
1136                (setq value (get-char-attribute char 'hanyu-dazidian-page)))
1137       (insert (format "(hanyu-dazidian-page . %d)%s"
1138                       value line-breaking))
1139       (setq attributes (delq 'hanyu-dazidian-page attributes))
1140       )
1141     (when (and (memq 'hanyu-dazidian-char attributes)
1142                (setq value (get-char-attribute char 'hanyu-dazidian-char)))
1143       (insert (format "(hanyu-dazidian-char . %d)%s"
1144                       value line-breaking))
1145       (setq attributes (delq 'hanyu-dazidian-char attributes))
1146       )
1147     (unless readable
1148       (dolist (ignored '(composition
1149                          ->denotational <-subsumptive ->ucs-unified
1150                          ->ideographic-component-forms))
1151         (setq attributes (delq ignored attributes))))
1152     (while attributes
1153       (setq name (car attributes))
1154       (unless (eq (setq value (get-char-attribute char name 'value-is-empty))
1155                   'value-is-empty)
1156         (cond ((setq ret (find-charset name))
1157                (setq name (charset-name ret))
1158                (when (not (memq name dest-ccss))
1159                  (setq dest-ccss (cons name dest-ccss))
1160                  (char-db-insert-ccs-feature name value line-breaking))
1161                )
1162               ((string-match "^=>ucs@" (symbol-name name))
1163                (insert (format "(%-18s . #x%04X)\t; %c%s"
1164                                name value (decode-char '=ucs value)
1165                                line-breaking))
1166                )
1167               ((eq name 'jisx0208-1978/4X)
1168                (insert (format "(%-18s . #x%04X)%s"
1169                                name value
1170                                line-breaking))
1171                )
1172               ((and
1173                 (not readable)
1174                 (not (eq name '->subsumptive))
1175                 (not (eq name '->uppercase))
1176                 (not (eq name '->lowercase))
1177                 (not (eq name '->titlecase))
1178                 (not (eq name '->canonical))
1179                 (not (eq name '->Bopomofo))
1180                 (not (eq name '->mistakable))
1181                 (not (eq name '->ideographic-variants))
1182                 (null (get-char-attribute
1183                        char (intern (format "%s*sources" name))))
1184                 (not (string-match "\\*sources$" (symbol-name name)))
1185                 (null (get-char-attribute
1186                        char (intern (format "%s*note" name))))
1187                 (not (string-match "\\*note$" (symbol-name name)))
1188                 (or (eq name '<-identical)
1189                     (eq name '<-uppercase)
1190                     (eq name '<-lowercase)
1191                     (eq name '<-titlecase)
1192                     (eq name '<-canonical)
1193                     (eq name '<-ideographic-variants)
1194                     ;; (eq name '<-synonyms)
1195                     (string-match "^<-synonyms" (symbol-name name))
1196                     (eq name '<-mistakable)
1197                     (when (string-match "^->" (symbol-name name))
1198                       (cond
1199                        ((string-match "^->fullwidth" (symbol-name name))
1200                         (not (and (consp value)
1201                                   (characterp (car value))
1202                                   (encode-char
1203                                    (car value) '=ucs 'defined-only)))
1204                         )
1205                        (t)))
1206                     ))
1207                )
1208               ((or (eq name 'ideographic-structure)
1209                    (eq name 'ideographic-combination)
1210                    (eq name 'ideographic-)
1211                    (eq name '=decomposition)
1212                    (char-feature-base-name= '=decomposition name)
1213                    (char-feature-base-name= '=>decomposition name)
1214                    ;; (string-match "^=>*decomposition\\(@[^*]+\\)?$"
1215                    ;;               (symbol-name name))
1216                    (string-match "^\\(->\\|<-\\)[^*]*$" (symbol-name name))
1217                    (string-match "^\\(->\\|<-\\)[^*]*\\*sources$"
1218                                  (symbol-name name))
1219                    )
1220                (char-db-insert-relation-feature char name value
1221                                                 line-breaking
1222                                                 ccss readable))
1223               ((memq name '(ideograph=
1224                             original-ideograph-of
1225                             ancient-ideograph-of
1226                             vulgar-ideograph-of
1227                             wrong-ideograph-of
1228                             ;; simplified-ideograph-of
1229                             ideographic-variants
1230                             ;; ideographic-different-form-of
1231                             ))
1232                (insert (format "(%-18s%s " name line-breaking))
1233                (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1234                      separator nil)
1235                (while (consp value)
1236                  (setq cell (car value))
1237                  (if (and (consp cell)
1238                           (consp (car cell)))
1239                      (progn
1240                        (if separator
1241                            (insert lbs))
1242                        (char-db-insert-alist cell readable)
1243                        (setq separator lbs))
1244                    (if separator
1245                        (insert separator))
1246                    (insert (prin1-to-string cell))
1247                    (setq separator " "))
1248                  (setq value (cdr value)))
1249                (insert ")")
1250                (insert line-breaking))
1251               ((consp value)
1252                (insert (format "(%-18s " name))
1253                (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1254                      separator nil)
1255                (while (consp value)
1256                  (setq cell (car value))
1257                  (if (and (consp cell)
1258                           (consp (car cell))
1259                           (setq ret (condition-case nil
1260                                         (find-char cell)
1261                                       (error nil))))
1262                      (progn
1263                        (setq rest cell
1264                              al nil
1265                              cal nil)
1266                        (while rest
1267                          (setq key (car (car rest)))
1268                          (if (find-charset key)
1269                              (setq cal (cons key cal))
1270                            (setq al (cons key al)))
1271                          (setq rest (cdr rest)))
1272                        (if separator
1273                            (insert lbs))
1274                        (insert-char-attributes ret
1275                                                readable
1276                                                al ; cal
1277                                                nil 'for-sub-node)
1278                        (setq separator lbs))
1279                    (setq ret (prin1-to-string cell))
1280                    (if separator
1281                        (if (< (+ (current-column)
1282                                  (length ret)
1283                                  (length separator))
1284                               76)
1285                            (insert separator)
1286                          (insert lbs)))
1287                    (insert ret)
1288                    (setq separator " "))
1289                  (setq value (cdr value)))
1290                (insert ")")
1291                (insert line-breaking))
1292               (t
1293                (insert (format "(%-18s" name))
1294                (setq ret (prin1-to-string value))
1295                (unless (< (+ (current-column)
1296                              (length ret)
1297                              3)
1298                           76)
1299                  (insert line-breaking))
1300                (insert " . " ret ")" line-breaking)
1301                ;; (insert (format "(%-18s . %S)%s"
1302                ;;                 name value
1303                ;;                 line-breaking))
1304                )
1305               ))
1306       (setq attributes (cdr attributes)))
1307     (insert ")")))
1308
1309 (defun insert-char-data (char &optional readable
1310                               attributes)
1311   (save-restriction
1312     (narrow-to-region (point)(point))
1313     (insert "(define-char
1314   '")
1315     (insert-char-attributes char readable attributes)
1316     (insert ")\n")
1317     (goto-char (point-min))
1318     (while (re-search-forward "[ \t]+$" nil t)
1319       (replace-match ""))
1320     ;; from tabify.
1321     (goto-char (point-min))
1322     (while (re-search-forward "[ \t][ \t][ \t]*" nil t)
1323       (let ((column (current-column))
1324             (indent-tabs-mode t))
1325         (delete-region (match-beginning 0) (point))
1326         (indent-to column)))
1327     (goto-char (point-max))
1328     ;; (tabify (point-min)(point-max))
1329     ))
1330
1331 (defun insert-char-data-with-variant (char &optional printable
1332                                            no-ucs-unified
1333                                            script excluded-script)
1334   (insert-char-data char printable)
1335   (let ((variants (char-variants char))
1336         rest
1337         variant vs ret)
1338     (setq variants (sort variants #'<))
1339     (setq rest variants)
1340     (setq variants (cons char variants))
1341     (while rest
1342       (setq variant (car rest))
1343       (unless (get-char-attribute variant '<-subsumptive)
1344         (if (and (or (null script)
1345                      (null (setq vs (get-char-attribute variant 'script)))
1346                      (memq script vs))
1347                  (or (null excluded-script)
1348                      (null (setq vs (get-char-attribute variant 'script)))
1349                      (not (memq excluded-script vs))))
1350             (unless (and no-ucs-unified (get-char-attribute variant '=ucs))
1351               (insert-char-data variant printable)
1352               (if (setq ret (char-variants variant))
1353                   (while ret
1354                     (or (memq (car ret) variants)
1355                         ;; (get-char-attribute (car ret) '<-subsumptive)
1356                         (setq rest (nconc rest (list (car ret)))))
1357                     (setq ret (cdr ret)))))))
1358       (setq rest (cdr rest)))))
1359
1360 (defun insert-char-range-data (min max &optional script excluded-script)
1361   (let ((code min)
1362         char)
1363     (while (<= code max)
1364       (setq char (decode-char '=ucs code))
1365       (if (encode-char char '=ucs 'defined-only)
1366           (insert-char-data-with-variant char nil 'no-ucs-unified
1367                                          script excluded-script))
1368       (setq code (1+ code)))))
1369
1370 (defun write-char-range-data-to-file (min max file
1371                                           &optional script excluded-script)
1372   (let ((coding-system-for-write char-db-file-coding-system))
1373     (with-temp-buffer
1374       (insert (format ";; -*- coding: %s -*-\n"
1375                       char-db-file-coding-system))
1376       (insert-char-range-data min max script excluded-script)
1377       (write-region (point-min)(point-max) file))))
1378
1379 (defvar what-character-original-window-configuration)
1380
1381 ;;;###autoload
1382 (defun what-char-definition (char)
1383   (interactive (list (char-after)))
1384   (let ((buf (get-buffer-create "*Character Description*"))
1385         (the-buf (current-buffer))
1386         (win-conf (current-window-configuration)))
1387     (pop-to-buffer buf)
1388     (make-local-variable 'what-character-original-window-configuration)
1389     (setq what-character-original-window-configuration win-conf)
1390     (setq buffer-read-only nil)
1391     (erase-buffer)
1392     (condition-case err
1393         (progn
1394           (insert-char-data-with-variant char 'printable)
1395           (unless (char-attribute-alist char)
1396             (insert (format ";; = %c\n"
1397                             (let* ((rest (split-char char))
1398                                    (ccs (pop rest))
1399                                    (code (pop rest)))
1400                               (while rest
1401                                 (setq code (logior (lsh code 8)
1402                                                    (pop rest))))
1403                               (decode-char ccs code)))))
1404           ;; (char-db-update-comment)
1405           (set-buffer-modified-p nil)
1406           (view-mode the-buf (lambda (buf)
1407                                (set-window-configuration
1408                                 what-character-original-window-configuration)
1409                                ))
1410           (goto-char (point-min)))
1411       (error (progn
1412                (set-window-configuration
1413                 what-character-original-window-configuration)
1414                (signal (car err) (cdr err)))))))
1415
1416
1417 ;;; @ end
1418 ;;;
1419
1420 (provide 'char-db-util)
1421
1422 ;;; char-db-util.el ends here