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