(o-UU+95B7): Unify o-CU+2F9F0 and A-CU+2F9F0 instead of o-IU+2F9F0 and
[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                            =shinjigen@1ed
643                            =shinjigen@rev
644                            =shinjigen/+p@rev))))
645            ((eq source 'CN)
646             (setq required-features
647                   (union required-features
648                          '(=gb2312
649                            =gb12345
650                            =iso-ir165)))))
651           (cond
652            ((find-charset (setq ret (intern (format "=%s" source))))
653             (setq required-features
654                   (cons ret required-features)))
655            (t (setq required-features
656                     (cons source required-features)))))
657         (cond ((string-match "@JP" (symbol-name name))
658                (setq required-features
659                      (union required-features
660                             '(=jis-x0208
661                               =jis-x0208@1990
662                               =jis-x0213-1-2000
663                               =jis-x0213-2-2000
664                               =jis-x0212
665                               =jis-x0208@1983
666                               =jis-x0208@1978))))
667               ((string-match "@CN" (symbol-name name))
668                (setq required-features
669                      (union required-features
670                             '(=gb2312
671                               =gb12345
672                               =iso-ir165)))))
673         (if separator
674             (insert lbs))
675         (if readable
676             (insert (format "%S" cell))
677           (char-db-insert-char-spec cell readable
678                                     nil
679                                     required-features))
680         (setq separator lbs))
681        ((consp cell)
682         (if separator
683             (insert lbs))
684         (if (consp (car cell))
685             (char-db-insert-char-spec cell readable)
686           (char-db-insert-char-reference cell readable))
687         (setq separator lbs))
688        (t
689         (if separator
690             (insert separator))
691         (insert (prin1-to-string cell))
692         (setq separator " ")))
693       (setq value (cdr value)))
694     (insert ")")
695     (insert line-breaking)))
696
697 (defun insert-char-attributes (char &optional readable attributes column
698                                     for-sub-node)
699   (unless column
700     (setq column (current-column)))
701   (let (name value ; has-long-ccs-name
702         rest
703         radical strokes
704         (line-breaking
705          (concat "\n" (make-string (1+ column) ?\ )))
706         lbs cell separator ret
707         key al cal
708         dest-ccss ; sources required-features
709         ccss)
710     (let (atr-d)
711       (setq attributes
712             (sort (if attributes
713                       (if (consp attributes)
714                           (progn
715                             (dolist (name attributes)
716                               (unless (memq name char-db-ignored-attributes)
717                                 (if (find-charset name)
718                                     (push name ccss))
719                                 (push name atr-d)))
720                             atr-d))
721                     (dolist (name (char-attribute-list))
722                       (unless (memq name char-db-ignored-attributes)
723                         (if (find-charset name)
724                             (push name ccss))
725                         (push name atr-d)))
726                     atr-d)
727                   #'char-attribute-name<)))
728     (insert "(")
729     (when (memq '<-subsumptive attributes)
730       (when (or readable (not for-sub-node))
731         (when (setq value (get-char-attribute char '<-subsumptive))
732           (char-db-insert-relation-feature char '<-subsumptive value
733                                            line-breaking
734                                            ccss readable)))
735       (setq attributes (delq '<-subsumptive attributes)))
736     (when (and (memq '<-denotational attributes)
737                (setq value (get-char-attribute char '<-denotational)))
738       (char-db-insert-relation-feature char '<-denotational value
739                                        line-breaking
740                                        ccss readable)
741       (setq attributes (delq '<-denotational attributes)))
742     (when (and (memq 'name attributes)
743                (setq value (get-char-attribute char 'name)))
744       (insert (format
745                (if (> (+ (current-column) (length value)) 48)
746                    "(name . %S)%s"
747                  "(name               . %S)%s")
748                value line-breaking))
749       (setq attributes (delq 'name attributes))
750       )
751     (when (and (memq 'name* attributes)
752                (setq value (get-char-attribute char 'name*)))
753       (insert (format
754                (if (> (+ (current-column) (length value)) 48)
755                    "(name* . %S)%s"
756                  "(name*              . %S)%s")
757                value line-breaking))
758       (setq attributes (delq 'name* attributes))
759       )
760     (when (and (memq 'script attributes)
761                (setq value (get-char-attribute char 'script)))
762       (insert (format "(script\t\t%s)%s"
763                       (mapconcat (function prin1-to-string)
764                                  value " ")
765                       line-breaking))
766       (setq attributes (delq 'script attributes))
767       )
768     (dolist (name '(=>ucs =>ucs*))
769       (when (and (memq name attributes)
770                  (setq value (get-char-attribute char name)))
771         (insert (format "(%-18s . #x%04X)\t; %c%s"
772                         name value (decode-char '=ucs value)
773                         line-breaking))
774         (setq attributes (delq name attributes))))
775     (dolist (name '(=>ucs@gb =>ucs@big5))
776       (when (and (memq name attributes)
777                  (setq value (get-char-attribute char name)))
778         (insert (format "(%-18s . #x%04X)\t; %c%s"
779                         name value
780                         (decode-char (intern
781                                       (concat "="
782                                               (substring
783                                                (symbol-name name) 2)))
784                                      value)
785                         line-breaking))
786         (setq attributes (delq name attributes))
787         ))
788     ;; (dolist (name '(=>daikanwa))
789     ;;   (when (and (memq name attributes)
790     ;;              (setq value (get-char-attribute char name)))
791     ;;     (insert
792     ;;      (if (integerp value)
793     ;;          (format "(%-18s . %05d)\t; %c%s"
794     ;;                  name value (decode-char '=daikanwa value)
795     ;;                  line-breaking)
796     ;;        (format "(%-18s %s)\t; %c%s"
797     ;;                name
798     ;;                (mapconcat (function prin1-to-string)
799     ;;                           value " ")
800     ;;                (char-representative-of-daikanwa char)
801     ;;                line-breaking)))
802     ;;     (setq attributes (delq name attributes))))
803     (when (and (memq 'general-category attributes)
804                (setq value (get-char-attribute char 'general-category)))
805       (insert (format
806                "(general-category\t%s) ; %s%s"
807                (mapconcat (lambda (cell)
808                             (format "%S" cell))
809                           value " ")
810                (cond ((rassoc value unidata-normative-category-alist)
811                       "Normative Category")
812                      ((rassoc value unidata-informative-category-alist)
813                       "Informative Category")
814                      (t
815                       "Unknown Category"))
816                line-breaking))
817       (setq attributes (delq 'general-category attributes))
818       )
819     (when (and (memq 'bidi-category attributes)
820                (setq value (get-char-attribute char 'bidi-category)))
821       (insert (format "(bidi-category\t. %S)%s"
822                       value
823                       line-breaking))
824       (setq attributes (delq 'bidi-category attributes))
825       )
826     (unless (or (not (memq 'mirrored attributes))
827                 (eq (setq value (get-char-attribute char 'mirrored 'empty))
828                     'empty))
829       (insert (format "(mirrored\t\t. %S)%s"
830                       value
831                       line-breaking))
832       (setq attributes (delq 'mirrored attributes))
833       )
834     (cond
835      ((and (memq 'decimal-digit-value attributes)
836            (setq value (get-char-attribute char 'decimal-digit-value)))
837       (insert (format "(decimal-digit-value . %S)%s"
838                       value
839                       line-breaking))
840       (setq attributes (delq 'decimal-digit-value attributes))
841       (when (and (memq 'digit-value attributes)
842                  (setq value (get-char-attribute char 'digit-value)))
843         (insert (format "(digit-value\t . %S)%s"
844                         value
845                         line-breaking))
846         (setq attributes (delq 'digit-value attributes))
847         )
848       (when (and (memq 'numeric-value attributes)
849                  (setq value (get-char-attribute char 'numeric-value)))
850         (insert (format "(numeric-value\t . %S)%s"
851                         value
852                         line-breaking))
853         (setq attributes (delq 'numeric-value attributes))
854         )
855       )
856      (t
857       (when (and (memq 'digit-value attributes)
858                  (setq value (get-char-attribute char 'digit-value)))
859         (insert (format "(digit-value\t. %S)%s"
860                         value
861                         line-breaking))
862         (setq attributes (delq 'digit-value attributes))
863         )
864       (when (and (memq 'numeric-value attributes)
865                  (setq value (get-char-attribute char 'numeric-value)))
866         (insert (format "(numeric-value\t. %S)%s"
867                         value
868                         line-breaking))
869         (setq attributes (delq 'numeric-value attributes))
870         )))
871     (when (and (memq 'iso-10646-comment attributes)
872                (setq value (get-char-attribute char 'iso-10646-comment)))
873       (insert (format "(iso-10646-comment\t. %S)%s"
874                       value
875                       line-breaking))
876       (setq attributes (delq 'iso-10646-comment attributes))
877       )
878     (when (and (memq 'morohashi-daikanwa attributes)
879                (setq value (get-char-attribute char 'morohashi-daikanwa)))
880       (insert (format "(morohashi-daikanwa\t%s)%s"
881                       (mapconcat (function prin1-to-string) value " ")
882                       line-breaking))
883       (setq attributes (delq 'morohashi-daikanwa attributes))
884       )
885     (setq radical nil
886           strokes nil)
887     (when (and (memq 'ideographic-radical attributes)
888                (setq value (get-char-attribute char 'ideographic-radical)))
889       (setq radical value)
890       (insert (format "(ideographic-radical . %S)\t; %c%s"
891                       radical
892                       (ideographic-radical radical)
893                       line-breaking))
894       (setq attributes (delq 'ideographic-radical attributes))
895       )
896     (when (and (memq 'shuowen-radical attributes)
897                (setq value (get-char-attribute char 'shuowen-radical)))
898       (insert (format "(shuowen-radical\t. %S)\t; %c%s"
899                       value
900                       (shuowen-radical value)
901                       line-breaking))
902       (setq attributes (delq 'shuowen-radical attributes))
903       )
904     (let (key)
905       (dolist (domain
906                (append
907                 char-db-feature-domains
908                 (let (dest domain)
909                   (dolist (feature (char-attribute-list))
910                     (setq feature (symbol-name feature))
911                     (when (string-match
912                            "\\(radical\\|strokes\\)@\\([^@*]+\\)\\(\\*\\|$\\)"
913                            feature)
914                       (setq domain (intern (match-string 2 feature)))
915                      (unless (memq domain dest)
916                        (setq dest (cons domain dest)))))
917                   (sort dest #'string<))))
918         (setq key (intern (format "%s@%s" 'ideographic-radical domain)))
919         (when (and (memq key attributes)
920                    (setq value (get-char-attribute char key)))
921           (setq radical value)
922           (insert (format "(%s . %S)\t; %c%s"
923                           key
924                           radical
925                           (ideographic-radical radical)
926                           line-breaking))
927           (setq attributes (delq key attributes))
928           )
929         (setq key (intern (format "%s@%s" 'ideographic-strokes domain)))
930         (when (and (memq key attributes)
931                    (setq value (get-char-attribute char key)))
932           (setq strokes value)
933           (insert (format "(%s . %S)%s"
934                           key
935                           strokes
936                           line-breaking))
937           (setq attributes (delq key attributes))
938           )
939         (setq key (intern (format "%s@%s" 'total-strokes domain)))
940         (when (and (memq key attributes)
941                    (setq value (get-char-attribute char key)))
942           (insert (format "(%s       . %S)%s"
943                           key
944                           value
945                           line-breaking))
946           (setq attributes (delq key attributes))
947           )
948         (dolist (feature '(ideographic-radical
949                            ideographic-strokes
950                            total-strokes))
951           (setq key (intern (format "%s@%s*sources" feature domain)))
952           (when (and (memq key attributes)
953                      (setq value (get-char-attribute char key)))
954             (insert (format "(%s%s" key line-breaking))
955             (dolist (cell value)
956               (insert (format " %s" cell)))
957             (insert ")")
958             (insert line-breaking)
959             (setq attributes (delq key attributes))
960             ))
961         ))
962     (when (and (memq 'ideographic-strokes attributes)
963                (setq value (get-char-attribute char 'ideographic-strokes)))
964       (setq strokes value)
965       (insert (format "(ideographic-strokes . %S)%s"
966                       strokes
967                       line-breaking))
968       (setq attributes (delq 'ideographic-strokes attributes))
969       )
970     (when (and (memq 'kangxi-radical attributes)
971                (setq value (get-char-attribute char 'kangxi-radical)))
972       (unless (eq value radical)
973         (insert (format "(kangxi-radical\t . %S)\t; %c%s"
974                         value
975                         (ideographic-radical value)
976                         line-breaking))
977         (or radical
978             (setq radical value)))
979       (setq attributes (delq 'kangxi-radical attributes))
980       )
981     (when (and (memq 'kangxi-strokes attributes)
982                (setq value (get-char-attribute char 'kangxi-strokes)))
983       (unless (eq value strokes)
984         (insert (format "(kangxi-strokes\t . %S)%s"
985                         value
986                         line-breaking))
987         (or strokes
988             (setq strokes value)))
989       (setq attributes (delq 'kangxi-strokes attributes))
990       )
991     (when (and (memq 'japanese-radical attributes)
992                (setq value (get-char-attribute char 'japanese-radical)))
993       (unless (eq value radical)
994         (insert (format "(japanese-radical\t . %S)\t; %c%s"
995                         value
996                         (ideographic-radical value)
997                         line-breaking))
998         (or radical
999             (setq radical value)))
1000       (setq attributes (delq 'japanese-radical attributes))
1001       )
1002     (when (and (memq 'japanese-strokes attributes)
1003                (setq value (get-char-attribute char 'japanese-strokes)))
1004       (unless (eq value strokes)
1005         (insert (format "(japanese-strokes\t . %S)%s"
1006                         value
1007                         line-breaking))
1008         (or strokes
1009             (setq strokes value)))
1010       (setq attributes (delq 'japanese-strokes attributes))
1011       )
1012     (when (and (memq 'cns-radical attributes)
1013                (setq value (get-char-attribute char 'cns-radical)))
1014       (insert (format "(cns-radical\t . %S)\t; %c%s"
1015                       value
1016                       (ideographic-radical value)
1017                       line-breaking))
1018       (setq attributes (delq 'cns-radical attributes))
1019       )
1020     (when (and (memq 'cns-strokes attributes)
1021                (setq value (get-char-attribute char 'cns-strokes)))
1022       (unless (eq value strokes)
1023         (insert (format "(cns-strokes\t . %S)%s"
1024                         value
1025                         line-breaking))
1026         (or strokes
1027             (setq strokes value)))
1028       (setq attributes (delq 'cns-strokes attributes))
1029       )
1030     ;; (when (and (memq 'shinjigen-1-radical attributes)
1031     ;;            (setq value (get-char-attribute char 'shinjigen-1-radical)))
1032     ;;   (unless (eq value radical)
1033     ;;     (insert (format "(shinjigen-1-radical . %S)\t; %c%s"
1034     ;;                     value
1035     ;;                     (ideographic-radical value)
1036     ;;                     line-breaking))
1037     ;;     (or radical
1038     ;;         (setq radical value)))
1039     ;;   (setq attributes (delq 'shinjigen-1-radical attributes))
1040     ;;   )
1041     (when (and (memq 'ideographic- attributes)
1042                (setq value (get-char-attribute char 'ideographic-)))
1043       (insert "(ideographic-       ")
1044       (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1045             separator nil)
1046       (while (consp value)
1047         (setq cell (car value))
1048         (if (integerp cell)
1049             (setq cell (decode-char '=ucs cell)))
1050         (cond ((characterp cell)
1051                (if separator
1052                    (insert lbs))
1053                (if readable
1054                    (insert (format "%S" cell))
1055                  (char-db-insert-char-spec cell readable))
1056                (setq separator lbs))
1057               ((consp cell)
1058                (if separator
1059                    (insert lbs))
1060                (if (consp (car cell))
1061                    (char-db-insert-char-spec cell readable)
1062                  (char-db-insert-char-reference cell readable))
1063                (setq separator lbs))
1064               (t
1065                (if separator
1066                    (insert separator))
1067                (insert (prin1-to-string cell))
1068                (setq separator " ")))
1069         (setq value (cdr value)))
1070       (insert ")")
1071       (insert line-breaking)
1072       (setq attributes (delq 'ideographic- attributes)))
1073     (when (and (memq 'total-strokes attributes)
1074                (setq value (get-char-attribute char 'total-strokes)))
1075       (insert (format "(total-strokes       . %S)%s"
1076                       value
1077                       line-breaking))
1078       (setq attributes (delq 'total-strokes attributes))
1079       )
1080     (when (and (memq '->ideograph attributes)
1081                (setq value (get-char-attribute char '->ideograph)))
1082       (insert (format "(->ideograph\t%s)%s"
1083                       (mapconcat (lambda (code)
1084                                    (cond ((symbolp code)
1085                                           (symbol-name code))
1086                                          ((integerp code)
1087                                           (format "#x%04X" code))
1088                                          (t
1089                                           (format "%s %S"
1090                                                   line-breaking code))))
1091                                  value " ")
1092                       line-breaking))
1093       (setq attributes (delq '->ideograph attributes))
1094       )
1095     ;; (when (and (memq '->decomposition attributes)
1096     ;;            (setq value (get-char-attribute char '->decomposition)))
1097     ;;   (insert (format "(->decomposition\t%s)%s"
1098     ;;                   (mapconcat (lambda (code)
1099     ;;                                (cond ((symbolp code)
1100     ;;                                       (symbol-name code))
1101     ;;                                      ((characterp code)
1102     ;;                                       (if readable
1103     ;;                                           (format "%S" code)
1104     ;;                                         (format "#x%04X"
1105     ;;                                                 (char-int code))
1106     ;;                                         ))
1107     ;;                                      ((integerp code)
1108     ;;                                       (format "#x%04X" code))
1109     ;;                                      (t
1110     ;;                                       (format "%s%S" line-breaking code))))
1111     ;;                              value " ")
1112     ;;                   line-breaking))
1113     ;;   (setq attributes (delq '->decomposition attributes))
1114     ;;   )
1115     (if (equal (get-char-attribute char '->titlecase)
1116                (get-char-attribute char '->uppercase))
1117         (setq attributes (delq '->titlecase attributes)))
1118     (when (and (memq '->mojikyo attributes)
1119                (setq value (get-char-attribute char '->mojikyo)))
1120       (insert (format "(->mojikyo\t\t. %06d)\t; %c%s"
1121                       value (decode-char 'mojikyo value)
1122                       line-breaking))
1123       (setq attributes (delq '->mojikyo attributes))
1124       )
1125     (when (and (memq 'hanyu-dazidian-vol attributes)
1126                (setq value (get-char-attribute char 'hanyu-dazidian-vol)))
1127       (insert (format "(hanyu-dazidian-vol  . %d)%s"
1128                       value line-breaking))
1129       (setq attributes (delq 'hanyu-dazidian-vol attributes))
1130       )
1131     (when (and (memq 'hanyu-dazidian-page attributes)
1132                (setq value (get-char-attribute char 'hanyu-dazidian-page)))
1133       (insert (format "(hanyu-dazidian-page . %d)%s"
1134                       value line-breaking))
1135       (setq attributes (delq 'hanyu-dazidian-page attributes))
1136       )
1137     (when (and (memq 'hanyu-dazidian-char attributes)
1138                (setq value (get-char-attribute char 'hanyu-dazidian-char)))
1139       (insert (format "(hanyu-dazidian-char . %d)%s"
1140                       value line-breaking))
1141       (setq attributes (delq 'hanyu-dazidian-char attributes))
1142       )
1143     (unless readable
1144       (dolist (ignored '(composition
1145                          ->denotational <-subsumptive ->ucs-unified
1146                          ->ideographic-component-forms))
1147         (setq attributes (delq ignored attributes))))
1148     (while attributes
1149       (setq name (car attributes))
1150       (unless (eq (setq value (get-char-attribute char name 'value-is-empty))
1151                   'value-is-empty)
1152         (cond ((setq ret (find-charset name))
1153                (setq name (charset-name ret))
1154                (when (not (memq name dest-ccss))
1155                  (setq dest-ccss (cons name dest-ccss))
1156                  (char-db-insert-ccs-feature name value line-breaking))
1157                )
1158               ((string-match "^=>ucs@" (symbol-name name))
1159                (insert (format "(%-18s . #x%04X)\t; %c%s"
1160                                name value (decode-char '=ucs value)
1161                                line-breaking))
1162                )
1163               ((eq name 'jisx0208-1978/4X)
1164                (insert (format "(%-18s . #x%04X)%s"
1165                                name value
1166                                line-breaking))
1167                )
1168               ((and
1169                 (not readable)
1170                 (not (eq name '->subsumptive))
1171                 (not (eq name '->uppercase))
1172                 (not (eq name '->lowercase))
1173                 (not (eq name '->titlecase))
1174                 (not (eq name '->canonical))
1175                 (not (eq name '->Bopomofo))
1176                 (not (eq name '->mistakable))
1177                 (not (eq name '->ideographic-variants))
1178                 (null (get-char-attribute
1179                        char (intern (format "%s*sources" name))))
1180                 (not (string-match "\\*sources$" (symbol-name name)))
1181                 (null (get-char-attribute
1182                        char (intern (format "%s*note" name))))
1183                 (not (string-match "\\*note$" (symbol-name name)))
1184                 (or (eq name '<-identical)
1185                     (eq name '<-uppercase)
1186                     (eq name '<-lowercase)
1187                     (eq name '<-titlecase)
1188                     (eq name '<-canonical)
1189                     (eq name '<-ideographic-variants)
1190                     ;; (eq name '<-synonyms)
1191                     (string-match "^<-synonyms" (symbol-name name))
1192                     (eq name '<-mistakable)
1193                     (when (string-match "^->" (symbol-name name))
1194                       (cond
1195                        ((string-match "^->fullwidth" (symbol-name name))
1196                         (not (and (consp value)
1197                                   (characterp (car value))
1198                                   (encode-char
1199                                    (car value) '=ucs 'defined-only)))
1200                         )
1201                        (t)))
1202                     ))
1203                )
1204               ((or (eq name 'ideographic-structure)
1205                    (eq name 'ideographic-combination)
1206                    (eq name 'ideographic-)
1207                    (eq name '=decomposition)
1208                    (char-feature-base-name= '=decomposition name)
1209                    (char-feature-base-name= '=>decomposition name)
1210                    ;; (string-match "^=>*decomposition\\(@[^*]+\\)?$"
1211                    ;;               (symbol-name name))
1212                    (string-match "^\\(->\\|<-\\)[^*]*$" (symbol-name name))
1213                    (string-match "^\\(->\\|<-\\)[^*]*\\*sources$"
1214                                  (symbol-name name))
1215                    )
1216                (char-db-insert-relation-feature char name value
1217                                                 line-breaking
1218                                                 ccss readable))
1219               ((memq name '(ideograph=
1220                             original-ideograph-of
1221                             ancient-ideograph-of
1222                             vulgar-ideograph-of
1223                             wrong-ideograph-of
1224                             ;; simplified-ideograph-of
1225                             ideographic-variants
1226                             ;; ideographic-different-form-of
1227                             ))
1228                (insert (format "(%-18s%s " name line-breaking))
1229                (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1230                      separator nil)
1231                (while (consp value)
1232                  (setq cell (car value))
1233                  (if (and (consp cell)
1234                           (consp (car cell)))
1235                      (progn
1236                        (if separator
1237                            (insert lbs))
1238                        (char-db-insert-alist cell readable)
1239                        (setq separator lbs))
1240                    (if separator
1241                        (insert separator))
1242                    (insert (prin1-to-string cell))
1243                    (setq separator " "))
1244                  (setq value (cdr value)))
1245                (insert ")")
1246                (insert line-breaking))
1247               ((consp value)
1248                (insert (format "(%-18s " name))
1249                (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1250                      separator nil)
1251                (while (consp value)
1252                  (setq cell (car value))
1253                  (if (and (consp cell)
1254                           (consp (car cell))
1255                           (setq ret (condition-case nil
1256                                         (find-char cell)
1257                                       (error nil))))
1258                      (progn
1259                        (setq rest cell
1260                              al nil
1261                              cal nil)
1262                        (while rest
1263                          (setq key (car (car rest)))
1264                          (if (find-charset key)
1265                              (setq cal (cons key cal))
1266                            (setq al (cons key al)))
1267                          (setq rest (cdr rest)))
1268                        (if separator
1269                            (insert lbs))
1270                        (insert-char-attributes ret
1271                                                readable
1272                                                al ; cal
1273                                                nil 'for-sub-node)
1274                        (setq separator lbs))
1275                    (setq ret (prin1-to-string cell))
1276                    (if separator
1277                        (if (< (+ (current-column)
1278                                  (length ret)
1279                                  (length separator))
1280                               76)
1281                            (insert separator)
1282                          (insert lbs)))
1283                    (insert ret)
1284                    (setq separator " "))
1285                  (setq value (cdr value)))
1286                (insert ")")
1287                (insert line-breaking))
1288               (t
1289                (insert (format "(%-18s" name))
1290                (setq ret (prin1-to-string value))
1291                (unless (< (+ (current-column)
1292                              (length ret)
1293                              3)
1294                           76)
1295                  (insert line-breaking))
1296                (insert " . " ret ")" line-breaking)
1297                ;; (insert (format "(%-18s . %S)%s"
1298                ;;                 name value
1299                ;;                 line-breaking))
1300                )
1301               ))
1302       (setq attributes (cdr attributes)))
1303     (insert ")")))
1304
1305 (defun insert-char-data (char &optional readable
1306                               attributes)
1307   (save-restriction
1308     (narrow-to-region (point)(point))
1309     (insert "(define-char
1310   '")
1311     (insert-char-attributes char readable attributes)
1312     (insert ")\n")
1313     (goto-char (point-min))
1314     (while (re-search-forward "[ \t]+$" nil t)
1315       (replace-match ""))
1316     ;; from tabify.
1317     (goto-char (point-min))
1318     (while (re-search-forward "[ \t][ \t][ \t]*" nil t)
1319       (let ((column (current-column))
1320             (indent-tabs-mode t))
1321         (delete-region (match-beginning 0) (point))
1322         (indent-to column)))
1323     (goto-char (point-max))
1324     ;; (tabify (point-min)(point-max))
1325     ))
1326
1327 (defun insert-char-data-with-variant (char &optional printable
1328                                            no-ucs-unified
1329                                            script excluded-script)
1330   (insert-char-data char printable)
1331   (let ((variants (char-variants char))
1332         rest
1333         variant vs ret)
1334     (setq variants (sort variants #'<))
1335     (setq rest variants)
1336     (setq variants (cons char variants))
1337     (while rest
1338       (setq variant (car rest))
1339       (unless (get-char-attribute variant '<-subsumptive)
1340         (if (and (or (null script)
1341                      (null (setq vs (get-char-attribute variant 'script)))
1342                      (memq script vs))
1343                  (or (null excluded-script)
1344                      (null (setq vs (get-char-attribute variant 'script)))
1345                      (not (memq excluded-script vs))))
1346             (unless (and no-ucs-unified (get-char-attribute variant '=ucs))
1347               (insert-char-data variant printable)
1348               (if (setq ret (char-variants variant))
1349                   (while ret
1350                     (or (memq (car ret) variants)
1351                         ;; (get-char-attribute (car ret) '<-subsumptive)
1352                         (setq rest (nconc rest (list (car ret)))))
1353                     (setq ret (cdr ret)))))))
1354       (setq rest (cdr rest)))))
1355
1356 (defun insert-char-range-data (min max &optional script excluded-script)
1357   (let ((code min)
1358         char)
1359     (while (<= code max)
1360       (setq char (decode-char '=ucs code))
1361       (if (encode-char char '=ucs 'defined-only)
1362           (insert-char-data-with-variant char nil 'no-ucs-unified
1363                                          script excluded-script))
1364       (setq code (1+ code)))))
1365
1366 (defun write-char-range-data-to-file (min max file
1367                                           &optional script excluded-script)
1368   (let ((coding-system-for-write char-db-file-coding-system))
1369     (with-temp-buffer
1370       (insert (format ";; -*- coding: %s -*-\n"
1371                       char-db-file-coding-system))
1372       (insert-char-range-data min max script excluded-script)
1373       (write-region (point-min)(point-max) file))))
1374
1375 (defvar what-character-original-window-configuration)
1376
1377 ;;;###autoload
1378 (defun what-char-definition (char)
1379   (interactive (list (char-after)))
1380   (let ((buf (get-buffer-create "*Character Description*"))
1381         (the-buf (current-buffer))
1382         (win-conf (current-window-configuration)))
1383     (pop-to-buffer buf)
1384     (make-local-variable 'what-character-original-window-configuration)
1385     (setq what-character-original-window-configuration win-conf)
1386     (setq buffer-read-only nil)
1387     (erase-buffer)
1388     (condition-case err
1389         (progn
1390           (insert-char-data-with-variant char 'printable)
1391           (unless (char-attribute-alist char)
1392             (insert (format ";; = %c\n"
1393                             (let* ((rest (split-char char))
1394                                    (ccs (pop rest))
1395                                    (code (pop rest)))
1396                               (while rest
1397                                 (setq code (logior (lsh code 8)
1398                                                    (pop rest))))
1399                               (decode-char ccs code)))))
1400           ;; (char-db-update-comment)
1401           (set-buffer-modified-p nil)
1402           (view-mode the-buf (lambda (buf)
1403                                (set-window-configuration
1404                                 what-character-original-window-configuration)
1405                                ))
1406           (goto-char (point-min)))
1407       (error (progn
1408                (set-window-configuration
1409                 what-character-original-window-configuration)
1410                (signal (car err) (cdr err)))))))
1411
1412
1413 ;;; @ end
1414 ;;;
1415
1416 (provide 'char-db-util)
1417
1418 ;;; char-db-util.el ends here