(U+37AE): Use U-000206A4 instead of <IDEOGRAPHIC ITERATION MARK> in
[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,2007,
4 ;;   2008,2009,2010,2011,2012,2013,2014,2015,2016,2017 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 ;  ?旨 ?曰 ?乃 ?丂 ?可 ?兮 ?号 ?亏 ?喜 ?壴 ; 160
84    ?鼓 ?豈 ?豆 ?豊 ?豐 ?䖒 ?虍 ?虎 ?虤 ?皿 ; 170
85    ?𠙴 ?去 ?血 ?丶 ?丹 ?青 ?井 ?皀 ?鬯 ?食 ; 180
86    ?亼 ?會 ?倉 ?入 ?缶 ?矢 ?高 ?冂 ?𩫏 ?京 ; 190
87    ?亯 ?𣆪 ?畗 ?㐭 ?嗇 ?來 ?麥 ?夊 ?舛 ?䑞 ; 200
88    ?韋 ?弟 ?夂 ?久 ?桀 ?木 ?東 ?林 ?才 ?叒 ; 210
89    ?之 ?帀 ?出 ?𣎵 ?生 ?乇 ?𠂹 ?𠌶 ?華 ?𥝌 ; 220
90    ?稽 ?巢 ?桼 ?束 ?㯻 ?囗 ?員 ?貝 ?邑 ?𨛜 ; 230
91    ?日 ?旦 ?倝 ?㫃 ?冥 ?晶 ?月 ?有 ?明 ?囧 ; 240
92    ?夕 ?多 ?毌 ?𢎘 ?𣐺 ?卣 ?齊 ?朿 ?片 ?鼎 ; 250
93    ?克 ?彔 ?禾 ?秝 ?黍 ?香 ?米 ?毇 ?臼 ?凶 ; 260
94    ?𣎳 ?林 ?麻 ?尗 ?耑 ?韭 ?瓜 ?瓠 ?宀 ?宮 ; 270
95    ?呂 ?穴 ?㝱 ?𤕫 ?冖 ?𠔼 ?冃 ?㒳 ?网 ?襾 ; 280
96    ?巾 ?巿 ?帛 ?白 ?㡀 ?黹 ?人 ?𠤎 ?匕 ?从 ; 290
97    ?比 ?北 ?丘 ?㐺 ?𡈼 ?重 ?臥 ?身 ?㐆 ?衣 ; 300
98    ?裘 ?老 ?毛 ?毳 ?尸 ?尺 ?尾 ?履 ?舟 ?方 ; 310
99    ?儿 ?兄 ?兂 ?皃 ?𠑹 ?先 ?秃 ?見 ?覞 ?欠 ; 320
100    ?㱃 ?㳄 ?旡 ?頁 ?𦣻 ?面 ?丏 ?首 ?𥄉 ?須 ; 330
101    ?彡 ?彣 ?文 ?髟 ?后 ?司 ?卮 ?卩 ?印 ?色 ; 340
102    ?𠨍 ?辟 ?勹 ?包 ?茍 ?鬼 ?甶 ?厶 ?嵬 ?山 ; 350
103    ?屾 ?屵 ?广 ?厂 ?丸 ?危 ?石 ?長 ?勿 ?冄 ; 360
104    ?而 ?豕 ?㣇 ?彑 ?豚 ?豸 ?𤉡 ?易 ?象 ?馬 ; 370
105    ?𢊁 ?鹿 ?麤 ?㲋 ?兔 ?萈 ?犬 ?㹜 ?鼠 ?能 ; 380
106    ?熊 ?火 ?炎 ?黑 ?囪 ?焱 ?炙 ?赤 ?大 ?亦 ; 390
107    ])
108
109 (defun shuowen-radical (number)
110   (aref shuowen-radicals (1- number)))
111
112 (defvar char-db-file-coding-system 'utf-8-mcs-er)
113
114 (defvar char-db-ignored-attributes '(ideographic-products))
115
116 (defvar char-db-coded-charset-priority-list
117   '(ascii
118     control-1
119     latin-iso8859-1
120     latin-iso8859-2
121     latin-iso8859-3
122     latin-iso8859-4
123     latin-iso8859-9
124     latin-jisx0201
125     cyrillic-iso8859-5
126     greek-iso8859-7
127     thai-tis620
128     ;; =mj
129     ;; =adobe-japan1-0
130     ;; =adobe-japan1-1
131     ;; =adobe-japan1-2
132     ;; =adobe-japan1-3
133     ;; =adobe-japan1-4
134     ;; =adobe-japan1-5
135     ;; =adobe-japan1-6
136     =jis-x0208
137     =jis-x0208@1978
138     =jis-x0208@1983
139     japanese-jisx0212
140     chinese-gb2312
141     =jis-x0208@1990
142     chinese-cns11643-1
143     chinese-cns11643-2
144     chinese-cns11643-3
145     chinese-cns11643-4
146     chinese-cns11643-5
147     chinese-cns11643-6
148     chinese-cns11643-7
149     =jis-x0213-1
150     =jis-x0213-1@2000
151     =jis-x0213-1@2004
152     =jis-x0213-2
153     korean-ksc5601
154     chinese-isoir165
155     katakana-jisx0201
156     hebrew-iso8859-8
157     chinese-gb12345
158     latin-viscii
159     ethiopic-ucs
160     =big5-cdp
161     =hanyo-denshi/ja
162     =hanyo-denshi/jb
163     =hanyo-denshi/jc
164     =hanyo-denshi/jd
165     =hanyo-denshi/ft
166     =hanyo-denshi/ia
167     =hanyo-denshi/ib
168     =hanyo-denshi/hg
169     =hanyo-denshi/jt
170     =hanyo-denshi/ks
171     =hanyo-denshi/tk
172     ;; ==mj
173     ;; ==adobe-japan1-0
174     ;; ==adobe-japan1-1
175     ;; ==adobe-japan1-2
176     ;; ==adobe-japan1-3
177     ;; ==adobe-japan1-4
178     ;; ==adobe-japan1-5
179     ;; ==adobe-japan1-6
180     ==jis-x0208
181     ==jis-x0213-1
182     ==jis-x0213-2
183     ==jis-x0212
184     ==hanyo-denshi/ja
185     ==hanyo-denshi/jb
186     ==hanyo-denshi/jc
187     ==hanyo-denshi/ft
188     ==hanyo-denshi/ia
189     ==hanyo-denshi/ib
190     ==hanyo-denshi/hg
191     ==hanyo-denshi/jt
192     ==hanyo-denshi/ks
193     ==hanyo-denshi/tk
194     =gt
195     =gt-k
196     =daikanwa
197     =daikanwa@rev2
198     =daikanwa@rev1
199     =daikanwa/+p
200     ==daikanwa
201     =cbeta
202     ideograph-hanziku-1
203     ideograph-hanziku-2
204     ideograph-hanziku-3
205     ideograph-hanziku-4
206     ideograph-hanziku-5
207     ideograph-hanziku-6
208     ideograph-hanziku-7
209     ideograph-hanziku-8
210     ideograph-hanziku-9
211     ideograph-hanziku-10
212     ideograph-hanziku-11
213     ideograph-hanziku-12
214     ;; =>>>adobe-japan1-0
215     ;; =>>>adobe-japan1-1
216     ;; =>>>adobe-japan1-2
217     ;; =>>>adobe-japan1-3
218     ;; =>>>adobe-japan1-4
219     ;; =>>>adobe-japan1-5
220     ;; =>>>adobe-japan1-6
221     ;; =>>>jis-x0208
222     ;; =>>>jis-x0213-1
223     ;; =>>>jis-x0213-2
224     ;; =>>>hanyo-denshi/ja
225     ;; =>>>hanyo-denshi/jb
226     ;; =>>>hanyo-denshi/jc
227     ;; =>>>hanyo-denshi/ft
228     ;; =>>>hanyo-denshi/ib
229     ;; =>>>hanyo-denshi/hg
230     ;; =>>>hanyo-denshi/jt
231     ;; =>>>hanyo-denshi/ks
232     ;; =>>>gt
233     =>>adobe-japan1-0
234     =>>adobe-japan1-1
235     =>>adobe-japan1-2
236     =>>adobe-japan1-3
237     =>>adobe-japan1-4
238     =>>adobe-japan1-5
239     =>>adobe-japan1-6
240     =>>jis-x0208
241     =>>jis-x0213-1
242     =>>jis-x0213-1@2000
243     =>>jis-x0213-1@2004
244     =>>jis-x0213-2
245     =>>jis-x0208@1978
246     =>>hanyo-denshi/ft
247     =>>hanyo-denshi/jt
248     =>>hanyo-denshi/ks
249     =>>gt
250     =>>daikanwa
251     =>>cbeta
252     =+>jis-x0208
253     =+>jis-x0213-1
254     =+>jis-x0213-2
255     =+>adobe-japan1-0
256     =+>adobe-japan1-1
257     =+>adobe-japan1-2
258     =+>adobe-japan1-3
259     =+>adobe-japan1-4
260     =+>adobe-japan1-5
261     =+>adobe-japan1-6
262     =+>jis-x0208@1978
263     =>jis-x0208
264     =>jis-x0208@1997
265     =>jis-x0213-1
266     =>jis-x0213-1@2000
267     =>jis-x0213-1@2004
268     =>jis-x0213-2
269     ==>ucs@bucs
270     =>iwds-1
271     =>ucs@hanyo-denshi
272     =>ucs@iso
273     =>ucs@unicode
274     =>ucs@jis
275     =>ucs@cns
276     =>ucs@ks
277     =+>ucs@iso
278     =+>ucs@unicode
279     =+>ucs@jis
280     =+>ucs@jis/1990
281     =+>ucs@cns
282     =+>ucs@ks
283     =>>ucs@iso
284     =>>ucs@unicode
285     =>>ucs@jis
286     =>>ucs@cns
287     =>>>ucs@iso
288     =>>>ucs@unicode
289     ==ucs@iso
290     ==ucs@unicode
291     ;; ==ucs@cns
292     ==gb2312
293     ==ks-x1001
294     ==cns11643-1
295     ==cns11643-2
296     ==cns11643-3
297     ==cns11643-4
298     ==cns11643-5
299     ==cns11643-6
300     ==cns11643-7
301     ==gt
302     ==jis-x0208@1990
303     ;; ==jis-x0208@1983
304     ==jis-x0208@1978
305     ==gt-k
306     =ucs@iso
307     =ucs@unicode
308     =ucs@cns
309     ==big5-cdp
310     ==cbeta
311     =>>big5-cdp
312     =>>gt-k
313     =+>gt
314     =>gt
315     =>mj
316     =>big5-cdp
317     =>daikanwa
318     =>daikanwa/ho
319     =>cns11643-5
320     =>cns11643-7
321     =big5
322     =big5-eten
323     =>gt-k
324     =zinbun-oracle
325     =>zinbun-oracle
326     =ruimoku-v6
327     =>>ruimoku-v6
328     ==ruimoku-v6
329     =jef-china3
330     =>cbeta
331     =shinjigen
332     =ucs-var-001
333     =ucs-var-002
334     =ucs-var-003
335     =ucs-var-004
336     =ucs-var-005
337     =ucs-var-006
338     =ucs-var-008
339     =ucs-var-010
340     =ucs-itaiji-001
341     =ucs-itaiji-002
342     =ucs-itaiji-003
343     =ucs-itaiji-004
344     =ucs-itaiji-005
345     =ucs-itaiji-006
346     =ucs-itaiji-007
347     =ucs-itaiji-008
348     =ucs-itaiji-009
349     =ucs-itaiji-011
350     =>ucs-itaiji-001
351     =>ucs-itaiji-002
352     =>ucs-itaiji-003
353     =>ucs-itaiji-005
354     =>ucs-itaiji-006
355     =>ucs-itaiji-007
356     =big5-cdp-var-001
357     =big5-cdp-var-002
358     =big5-cdp-var-003
359     =big5-cdp-var-004
360     =big5-cdp-var-005
361     =big5-cdp-itaiji-001
362     =big5-cdp-itaiji-002
363     =big5-cdp-itaiji-003
364     =>big5-cdp-itaiji-001
365     =>ucs@iwds-1
366     =>ucs@component
367     ==ucs@gb
368     =ucs@JP/hanazono))
369
370
371 ;;; @ char-db formatters
372 ;;;
373
374 (defun char-db-make-char-spec (char)
375   (let (ret char-spec)
376     (cond ((characterp char)
377            (cond ((and (setq ret (encode-char char '=ucs 'defined-only))
378                        (not (and (<= #xE000 ret)(<= ret #xF8FF))))
379                   (setq char-spec (list (cons '=ucs ret)))
380                   (cond ((setq ret (get-char-attribute char 'name))
381                          (setq char-spec (cons (cons 'name ret) char-spec))
382                          )
383                         ((setq ret (get-char-attribute char 'name*))
384                          (setq char-spec (cons (cons 'name* ret) char-spec))
385                          ))
386                   )
387                  ((encode-char char '=mj 'defined-only)
388                   (setq char-spec nil)
389                   (dolist (ccs (charset-list))
390                     (if (and (or (eq ccs '=mj)
391                                  ;; (eq (charset-property ccs 'iso-ir) 177)
392                                  (string-match "=ucs@" (symbol-name ccs))
393                                  )
394                              (setq ccs (charset-name ccs))
395                              (null (assq ccs char-spec))
396                              (setq ret (encode-char char ccs 'defined-only)))
397                         (setq char-spec (cons (cons ccs ret) char-spec))))
398                   )
399                  ((encode-char char '==mj 'defined-only)
400                   (setq char-spec nil)
401                   (dolist (ccs (charset-list))
402                     (if (and (or (eq ccs '==mj)
403                                  ;; (eq (charset-property ccs 'iso-ir) 177)
404                                  (string-match "=ucs@" (symbol-name ccs))
405                                  )
406                              (setq ccs (charset-name ccs))
407                              (null (assq ccs char-spec))
408                              (setq ret (encode-char char ccs 'defined-only)))
409                         (setq char-spec (cons (cons ccs ret) char-spec))))
410                   )
411                  ((encode-char char '=adobe-japan1 'defined-only)
412                   (setq char-spec nil)
413                   (dolist (ccs (charset-list))
414                     (if (and (or (memq ccs
415                                        '(=adobe-japan1-0
416                                          =adobe-japan1-1
417                                          =adobe-japan1-2
418                                          =adobe-japan1-3
419                                          =adobe-japan1-4
420                                          =adobe-japan1-5
421                                          =adobe-japan1-6
422                                          ))
423                                  ;; (eq (charset-property ccs 'iso-ir) 177)
424                                  (string-match "=ucs@" (symbol-name ccs))
425                                  )
426                              (setq ccs (charset-name ccs))
427                              (null (assq ccs char-spec))
428                              (setq ret (encode-char char ccs 'defined-only)))
429                         (setq char-spec (cons (cons ccs ret) char-spec))))
430                   )
431                  ((encode-char char '==adobe-japan1 'defined-only)
432                   (setq char-spec nil)
433                   (dolist (ccs (charset-list))
434                     (if (and (or (memq ccs
435                                        '(==adobe-japan1-0
436                                          ==adobe-japan1-1
437                                          ==adobe-japan1-2
438                                          ==adobe-japan1-3
439                                          ==adobe-japan1-4
440                                          ==adobe-japan1-5
441                                          ==adobe-japan1-6
442                                          ))
443                                  ;; (eq (charset-property ccs 'iso-ir) 177)
444                                  (string-match "=ucs@" (symbol-name ccs))
445                                  )
446                              (setq ccs (charset-name ccs))
447                              (null (assq ccs char-spec))
448                              (setq ret (encode-char char ccs 'defined-only)))
449                         (setq char-spec (cons (cons ccs ret) char-spec))))
450                   )
451                  ((setq ret
452                         (catch 'tag
453                           (let ((rest char-db-coded-charset-priority-list)
454                                 ccs)
455                             (while rest
456                               (setq ccs (charset-name
457                                          (find-charset (car rest))))
458                               (if (setq ret
459                                         (encode-char char ccs
460                                                      'defined-only))
461                                   (throw 'tag (cons ccs ret)))
462                               (setq rest (cdr rest))))))
463                   (setq char-spec (list ret))
464                   (dolist (ccs (delq (car ret) (charset-list)))
465                     (if (and (or (charset-iso-final-char ccs)
466                                  (memq ccs
467                                        '(=daikanwa
468                                          =daikanwa@rev2
469                                          ;; =gt-k
470                                          =jis-x0208@1997
471                                          ))
472                                  (eq (charset-property ccs 'iso-ir) 177)
473                                  ;; (string-match "=ucs@" (symbol-name ccs))
474                                  )
475                              (setq ccs (charset-name ccs))
476                              (null (assq ccs char-spec))
477                              (setq ret (encode-char char ccs 'defined-only)))
478                         (setq char-spec (cons (cons ccs ret) char-spec))))
479                   (if (null char-spec)
480                       (setq char-spec (split-char char)))
481                   (cond ((setq ret (get-char-attribute char 'name))
482                          (setq char-spec (cons (cons 'name ret) char-spec))
483                          )
484                         ((setq ret (get-char-attribute char 'name*))
485                          (setq char-spec (cons (cons 'name* ret) char-spec))
486                          ))
487                   )
488                  ((setq ret (get-char-attribute
489                              char 'ideographic-combination))
490                   (setq char-spec
491                         (cons (cons 'ideographic-combination ret)
492                               char-spec))
493                   ))
494            char-spec)
495           ((consp char)
496            char))))
497     
498 (defun char-db-insert-char-spec (char &optional readable column
499                                       required-features)
500   (unless column
501     (setq column (current-column)))
502   (let (char-spec temp-char)
503     (setq char-spec (char-db-make-char-spec char))
504     (unless (or (characterp char) ; char
505                 (condition-case nil
506                     (setq char (find-char char-spec))
507                   (error nil)))
508       ;; define temporary character
509       ;;   Current implementation is dirty.
510       (setq temp-char (define-char (cons '(ideograph-daikanwa . 0)
511                                          char-spec)))
512       (remove-char-attribute temp-char 'ideograph-daikanwa)
513       (setq char temp-char))
514     (insert-char-attributes char
515                             readable
516                             (union (mapcar #'car char-spec)
517                                    required-features)
518                             nil 'for-sub-node)
519     (when temp-char
520       ;; undefine temporary character
521       ;;   Current implementation is dirty.
522       (setq char-spec (char-attribute-alist temp-char))
523       (while char-spec
524         (remove-char-attribute temp-char (car (car char-spec)))
525         (setq char-spec (cdr char-spec))))))
526
527 (defun char-db-insert-alist (alist &optional readable column)
528   (unless column
529     (setq column (current-column)))
530   (let ((line-breaking
531          (concat "\n" (make-string (1+ column) ?\ )))
532         name value
533         ret al ; cal
534         key
535         lbs cell rest separator)
536     (insert "(")
537     (while alist
538       (setq name (car (car alist))
539             value (cdr (car alist)))
540       (cond ((eq name 'char)
541              (insert "(char . ")
542              (if (setq ret (condition-case nil
543                                (find-char value)
544                              (error nil)))
545                  (progn
546                    (setq al nil
547                          ;; cal nil
548                          )
549                    (while value
550                      (setq key (car (car value)))
551                      ;; (if (find-charset key)
552                      ;;     (setq cal (cons key cal))
553                      (setq al (cons key al))
554                      ;; )
555                      (setq value (cdr value)))
556                    (insert-char-attributes ret
557                                            readable
558                                            (or al 'none) ; cal
559                                            nil 'for-sub-node))
560                (insert (prin1-to-string value)))
561              (insert ")")
562              (insert line-breaking))
563             ((consp value)
564              (insert (format "(%-18s " name))
565              (setq lbs (concat "\n" (make-string (current-column) ?\ )))
566              (while (consp value)
567                (setq cell (car value))
568                (if (and (consp cell)
569                         (consp (car cell))
570                         (setq ret (condition-case nil
571                                       (find-char cell)
572                                     (error nil)))
573                         )
574                    (progn
575                      (setq rest cell
576                            al nil
577                            ;; cal nil
578                            )
579                      (while rest
580                        (setq key (car (car rest)))
581                        ;; (if (find-charset key)
582                        ;;     (setq cal (cons key cal))
583                        (setq al (cons key al))
584                        ;; )
585                        (setq rest (cdr rest)))
586                      (if separator
587                          (insert lbs))
588                      (insert-char-attributes ret
589                                              readable
590                                              al ; cal
591                                              nil 'for-sub-node)
592                      (setq separator lbs))
593                  (if separator
594                      (insert separator))
595                  (insert (prin1-to-string cell))
596                  (setq separator " "))
597                (setq value (cdr value)))
598              (insert ")")
599              (insert line-breaking))
600             (t
601              (insert (format "(%-18s . %S)%s"
602                              name value
603                              line-breaking))))
604       (setq alist (cdr alist))))
605   (insert ")"))
606
607 (defun char-db-insert-char-reference (plist &optional readable column)
608   (unless column
609     (setq column (current-column)))
610   (let ((line-breaking
611          (concat "\n" (make-string (1+ column) ?\ )))
612         (separator "")
613         name value)
614     (insert "(")
615     (while plist
616       (setq name (pop plist))
617       (setq value (pop plist))
618       (cond ((eq name :char)
619              (insert separator)
620              (insert ":char\t")
621              (cond ((numberp value)
622                     (setq value (decode-char '=ucs value)))
623                    ;; ((consp value)
624                    ;;  (setq value (or (find-char value)
625                    ;;                  value)))
626                    )
627              (char-db-insert-char-spec value readable)
628              (insert line-breaking)
629              (setq separator ""))
630             ((eq name :radical)
631              (insert (format "%s%s\t%d ; %c%s"
632                              separator
633                              name value
634                              (ideographic-radical value)
635                              line-breaking))
636              (setq separator ""))
637             (t
638              (insert (format "%s%s\t%S" separator name value))
639              (setq separator line-breaking)))
640       ))
641   (insert ")"))
642
643 (defun char-db-decode-isolated-char (ccs code-point)
644   (let (ret)
645     (setq ret
646           (cond ((eq ccs 'arabic-iso8859-6)
647                  (decode-char ccs code-point))
648                 ;; ((eq ccs '=gt)
649                 ;;  (decode-builtin-char '==gt code-point))
650                 ((and (memq ccs '(=gt-pj-1
651                                   =gt-pj-2
652                                   =gt-pj-3
653                                   =gt-pj-4
654                                   =gt-pj-5
655                                   =gt-pj-6
656                                   =gt-pj-7
657                                   =gt-pj-8
658                                   =gt-pj-9
659                                   =gt-pj-10
660                                   =gt-pj-11))
661                       (setq ret (decode-char ccs code-point))
662                       (setq ret (encode-char ret '=gt 'defined-only)))
663                  (decode-builtin-char '=gt ret))
664                 (t
665                  (decode-builtin-char ccs code-point))))
666     (cond ((null ret)
667            (or (decode-char ccs code-point)
668                (define-char (list (cons ccs code-point)))))
669           ((and (<= 0 (char-int ret))
670                 (<= (char-int ret) #x1F))
671            (decode-char '=ucs (+ #x2400 (char-int ret))))
672           ((= (char-int ret) #x7F)
673            ?\u2421)
674           (t ret))))
675
676 (defvar char-db-convert-obsolete-format t)
677
678 (defun char-db-insert-ccs-feature (name value line-breaking)
679   (cond
680    ((integerp value)
681     (insert
682      (format
683       (cond
684        ((memq name '(=>iwds-1
685                      ==shinjigen
686                      =shinjigen
687                      =shinjigen@1ed ==shinjigen@1ed
688                      =shinjigen@rev ==shinjigen@rev
689                      =shinjigen/+p@rev ==shinjigen/+p@rev
690                      ===daikanwa/ho ==daikanwa/ho
691                      =daikanwa/ho =>>daikanwa/ho =>daikanwa/ho))
692         "(%-18s .  %04d)\t; %c")
693        ((eq name '=shinjigen@1ed/24pr)
694         "(%-18s . %04d)\t; %c")
695        ((or
696          (memq name
697                '(===daikanwa
698                  ==daikanwa =daikanwa =>>daikanwa =>daikanwa
699                  =daikanwa@rev1 =daikanwa@rev2
700                  =daikanwa/+p ==daikanwa/+p ===daikanwa/+p
701                  =>>daikanwa/+p
702                  =daikanwa/+2p =>>daikanwa/+2p
703                  =gt ==gt ===gt
704                  =>>gt =+>gt =>gt
705                  =gt-k ==gt-k ===gt-k
706                  =>>gt-k =>gt-k
707                  =adobe-japan1-0 ==adobe-japan1-0 ===adobe-japan1-0
708                  =adobe-japan1-1 ==adobe-japan1-1 ===adobe-japan1-1
709                  =adobe-japan1-2 ==adobe-japan1-2 ===adobe-japan1-2
710                  =adobe-japan1-3 ==adobe-japan1-3 ===adobe-japan1-3
711                  =adobe-japan1-4 ==adobe-japan1-4 ===adobe-japan1-4
712                  =adobe-japan1-5 ==adobe-japan1-5 ===adobe-japan1-5
713                  =adobe-japan1-6 ==adobe-japan1-6 ===adobe-japan1-6
714                  =>>adobe-japan1-0 =+>adobe-japan1-0
715                  =>>adobe-japan1-1 =+>adobe-japan1-1
716                  =>>adobe-japan1-2 =+>adobe-japan1-2
717                  =>>adobe-japan1-3 =+>adobe-japan1-3
718                  =>>adobe-japan1-4 =+>adobe-japan1-4
719                  =>>adobe-japan1-5 =+>adobe-japan1-5
720                  =>>adobe-japan1-6 =+>adobe-japan1-6
721                  =>cbeta =cbeta =>>cbeta ==cbeta ===cbeta
722                  =zinbun-oracle =>zinbun-oracle
723                  ===hng-jou ===hng-keg ===hng-dng ===hng-mam
724                  ===hng-drt ===hng-kgk ===hng-myz ===hng-kda
725                  ===hng-khi ===hng-khm ===hng-hok ===hng-kyd ===hng-sok
726                  ===hng-yhk ===hng-kak ===hng-kar ===hng-kae
727                  ===hng-sys ===hng-tsu ===hng-tzj
728                  ===hng-hos ===hng-nak ===hng-jhk
729                  ===hng-hod ===hng-gok ===hng-ink ===hng-nto
730                  ===hng-nkm ===hng-k24 ===hng-nkk
731                  ===hng-kcc ===hng-kcj ===hng-kbk ===hng-sik
732                  ===hng-skk ===hng-kyu ===hng-ksk ===hng-wan
733                  ===hng-okd ===hng-wad ===hng-kmi
734                  ===hng-zkd ===hng-doh ===hng-jyu
735                  ===hng-tzs ===hng-kss ===hng-kyo
736                  ===hng-smk))
737          ;; (string-match "^=adobe-" (symbol-name name))
738          )
739         "(%-18s . %05d)\t; %c")
740        ((memq name '(=hanyo-denshi/ks
741                      ==hanyo-denshi/ks ===hanyo-denshi/ks
742                      =>>hanyo-denshi/ks
743                      =koseki ==koseki
744                      =mj ==mj ===mj =>>mj =>mj
745                      =zihai mojikyo))
746         "(%-18s . %06d)\t; %c")
747        ((memq name '(=hanyo-denshi/tk ==hanyo-denshi/tk))
748         "(%-18s . %08d)\t; %c")
749        ((>= (charset-dimension name) 2)
750         "(%-18s . #x%04X)\t; %c")
751        (t
752         "(%-18s . #x%02X)\t; %c"))
753       name
754       (if (= (charset-iso-graphic-plane name) 1)
755           (logior value
756                   (cond ((= (charset-dimension name) 1)
757                          #x80)
758                         ((= (charset-dimension name) 2)
759                          #x8080)
760                         ((= (charset-dimension name) 3)
761                          #x808080)
762                         (t 0)))
763         value)
764       (char-db-decode-isolated-char name value)))
765     (if (and (= (charset-chars name) 94)
766              (= (charset-dimension name) 2))
767         (insert (format " [%02d-%02d]"
768                         (- (lsh value -8) 32)
769                         (- (logand value 255) 32))))
770     )
771    (t
772     (insert (format "(%-18s . %s)" name value))
773     ))
774   (insert line-breaking))
775
776 (defun char-db-insert-relation-feature (char name value line-breaking
777                                              ccss readable)
778   (insert (format "(%-18s%s " name line-breaking))
779   (let ((lbs (concat "\n" (make-string (current-column) ?\ )))
780         separator cell sources required-features
781         ret)
782     (while (consp value)
783       (setq cell (car value))
784       (if (integerp cell)
785           (setq cell (decode-char '=ucs cell)))
786       (cond
787        ((eq name '->subsumptive)
788         (when (or (not (some (lambda (atr)
789                                (get-char-attribute cell atr))
790                              char-db-ignored-attributes))
791                   (some (lambda (ccs)
792                           (encode-char cell ccs 'defined-only))
793                         ccss))
794           (if separator
795               (insert lbs))
796           (let ((char-db-ignored-attributes
797                  (cons '<-subsumptive
798                        char-db-ignored-attributes)))
799             (insert-char-attributes cell readable nil nil 'for-sub-node))
800           (setq separator lbs))
801         )
802        ((characterp cell)
803         (setq sources
804               (get-char-attribute
805                char (intern (format "%s*sources" name))))
806         (setq required-features nil)
807         (dolist (source sources)
808           (cond
809            ((memq source '(JP
810                            JP/Jouyou
811                            shinjigen shinjigen@1ed shinjigen@rev))
812             (setq required-features
813                   (union required-features
814                          '(=jis-x0208
815                            =jis-x0208@1990
816                            =jis-x0213-1@2000
817                            =jis-x0213-1@2004
818                            =jis-x0213-2
819                            =jis-x0212
820                            =jis-x0208@1983
821                            =jis-x0208@1978
822                            =shinjigen
823                            =shinjigen@1ed
824                            =shinjigen@rev
825                            =shinjigen/+p@rev))))
826            ((eq source 'CN)
827             (setq required-features
828                   (union required-features
829                          '(=gb2312
830                            =gb12345
831                            =iso-ir165)))))
832           (cond
833            ((find-charset (setq ret (intern (format "=%s" source))))
834             (setq required-features
835                   (cons ret required-features)))
836            (t (setq required-features
837                     (cons source required-features)))))
838         (cond ((string-match "@JP" (symbol-name name))
839                (setq required-features
840                      (union required-features
841                             '(=jis-x0208
842                               =jis-x0208@1990
843                               =jis-x0213-1-2000
844                               =jis-x0213-2-2000
845                               =jis-x0212
846                               =jis-x0208@1983
847                               =jis-x0208@1978))))
848               ((string-match "@CN" (symbol-name name))
849                (setq required-features
850                      (union required-features
851                             '(=gb2312
852                               =gb12345
853                               =iso-ir165)))))
854         (if separator
855             (insert lbs))
856         (if readable
857             (insert (format "%S" cell))
858           (char-db-insert-char-spec cell readable
859                                     nil
860                                     required-features))
861         (setq separator lbs))
862        ((consp cell)
863         (if separator
864             (insert lbs))
865         (if (consp (car cell))
866             (char-db-insert-char-spec cell readable)
867           (char-db-insert-char-reference cell readable))
868         (setq separator lbs))
869        (t
870         (if separator
871             (insert separator))
872         (insert (prin1-to-string cell))
873         (setq separator " ")))
874       (setq value (cdr value)))
875     (insert ")")
876     (insert line-breaking)))
877
878 (defun insert-char-attributes (char &optional readable attributes column
879                                     for-sub-node)
880   (unless column
881     (setq column (current-column)))
882   (let (name value ; has-long-ccs-name
883         rest
884         radical strokes
885         (line-breaking
886          (concat "\n" (make-string (1+ column) ?\ )))
887         lbs cell separator ret
888         key al cal
889         dest-ccss ; sources required-features
890         ccss)
891     (let (atr-d)
892       (setq attributes
893             (sort (if attributes
894                       (if (consp attributes)
895                           (progn
896                             (dolist (name attributes)
897                               (unless (memq name char-db-ignored-attributes)
898                                 (if (find-charset name)
899                                     (push name ccss))
900                                 (push name atr-d)))
901                             atr-d))
902                     (dolist (name (char-attribute-list))
903                       (unless (memq name char-db-ignored-attributes)
904                         (if (find-charset name)
905                             (push name ccss))
906                         (push name atr-d)))
907                     atr-d)
908                   #'char-attribute-name<)))
909     (insert "(")
910     (when (memq '<-subsumptive attributes)
911       (when (or readable (not for-sub-node))
912         (when (setq value (get-char-attribute char '<-subsumptive))
913           (char-db-insert-relation-feature char '<-subsumptive value
914                                            line-breaking
915                                            ccss readable)))
916       (setq attributes (delq '<-subsumptive attributes)))
917     (when (and (memq '<-denotational attributes)
918                (setq value (get-char-attribute char '<-denotational)))
919       (char-db-insert-relation-feature char '<-denotational value
920                                        line-breaking
921                                        ccss readable)
922       (setq attributes (delq '<-denotational attributes)))
923     (when (and (memq '<-denotational@component attributes)
924                (setq value (get-char-attribute char '<-denotational@component)))
925       (char-db-insert-relation-feature char '<-denotational@component value
926                                        line-breaking
927                                        ccss readable)
928       (setq attributes (delq '<-denotational@component attributes)))
929     (when (and (memq 'name attributes)
930                (setq value (get-char-attribute char 'name)))
931       (insert (format
932                (if (> (+ (current-column) (length value)) 48)
933                    "(name . %S)%s"
934                  "(name               . %S)%s")
935                value line-breaking))
936       (setq attributes (delq 'name attributes))
937       )
938     (when (and (memq 'name* attributes)
939                (setq value (get-char-attribute char 'name*)))
940       (insert (format
941                (if (> (+ (current-column) (length value)) 48)
942                    "(name* . %S)%s"
943                  "(name*              . %S)%s")
944                value line-breaking))
945       (setq attributes (delq 'name* attributes))
946       )
947     (when (and (memq 'script attributes)
948                (setq value (get-char-attribute char 'script)))
949       (insert (format "(script\t\t%s)%s"
950                       (mapconcat (function prin1-to-string)
951                                  value " ")
952                       line-breaking))
953       (setq attributes (delq 'script attributes))
954       )
955     (dolist (name '(=>ucs =>ucs*))
956       (when (and (memq name attributes)
957                  (setq value (get-char-attribute char name)))
958         (insert (format "(%-18s . #x%04X)\t; %c%s"
959                         name value (decode-char '=ucs value)
960                         line-breaking))
961         (setq attributes (delq name attributes))))
962     (dolist (name '(=>ucs@gb =>ucs@big5))
963       (when (and (memq name attributes)
964                  (setq value (get-char-attribute char name)))
965         (insert (format "(%-18s . #x%04X)\t; %c%s"
966                         name value
967                         (decode-char (intern
968                                       (concat "="
969                                               (substring
970                                                (symbol-name name) 2)))
971                                      value)
972                         line-breaking))
973         (setq attributes (delq name attributes))
974         ))
975     ;; (dolist (name '(=>daikanwa))
976     ;;   (when (and (memq name attributes)
977     ;;              (setq value (get-char-attribute char name)))
978     ;;     (insert
979     ;;      (if (integerp value)
980     ;;          (format "(%-18s . %05d)\t; %c%s"
981     ;;                  name value (decode-char '=daikanwa value)
982     ;;                  line-breaking)
983     ;;        (format "(%-18s %s)\t; %c%s"
984     ;;                name
985     ;;                (mapconcat (function prin1-to-string)
986     ;;                           value " ")
987     ;;                (char-representative-of-daikanwa char)
988     ;;                line-breaking)))
989     ;;     (setq attributes (delq name attributes))))
990     (when (and (memq 'general-category attributes)
991                (setq value (get-char-attribute char 'general-category)))
992       (insert (format
993                "(general-category\t%s) ; %s%s"
994                (mapconcat (lambda (cell)
995                             (format "%S" cell))
996                           value " ")
997                (cond ((rassoc value unidata-normative-category-alist)
998                       "Normative Category")
999                      ((rassoc value unidata-informative-category-alist)
1000                       "Informative Category")
1001                      (t
1002                       "Unknown Category"))
1003                line-breaking))
1004       (setq attributes (delq 'general-category attributes))
1005       )
1006     (when (and (memq 'bidi-category attributes)
1007                (setq value (get-char-attribute char 'bidi-category)))
1008       (insert (format "(bidi-category\t. %S)%s"
1009                       value
1010                       line-breaking))
1011       (setq attributes (delq 'bidi-category attributes))
1012       )
1013     (unless (or (not (memq 'mirrored attributes))
1014                 (eq (setq value (get-char-attribute char 'mirrored 'empty))
1015                     'empty))
1016       (insert (format "(mirrored\t\t. %S)%s"
1017                       value
1018                       line-breaking))
1019       (setq attributes (delq 'mirrored attributes))
1020       )
1021     (cond
1022      ((and (memq 'decimal-digit-value attributes)
1023            (setq value (get-char-attribute char 'decimal-digit-value)))
1024       (insert (format "(decimal-digit-value . %S)%s"
1025                       value
1026                       line-breaking))
1027       (setq attributes (delq 'decimal-digit-value attributes))
1028       (when (and (memq 'digit-value attributes)
1029                  (setq value (get-char-attribute char 'digit-value)))
1030         (insert (format "(digit-value\t . %S)%s"
1031                         value
1032                         line-breaking))
1033         (setq attributes (delq 'digit-value attributes))
1034         )
1035       (when (and (memq 'numeric-value attributes)
1036                  (setq value (get-char-attribute char 'numeric-value)))
1037         (insert (format "(numeric-value\t . %S)%s"
1038                         value
1039                         line-breaking))
1040         (setq attributes (delq 'numeric-value attributes))
1041         )
1042       )
1043      (t
1044       (when (and (memq 'digit-value attributes)
1045                  (setq value (get-char-attribute char 'digit-value)))
1046         (insert (format "(digit-value\t. %S)%s"
1047                         value
1048                         line-breaking))
1049         (setq attributes (delq 'digit-value attributes))
1050         )
1051       (when (and (memq 'numeric-value attributes)
1052                  (setq value (get-char-attribute char 'numeric-value)))
1053         (insert (format "(numeric-value\t. %S)%s"
1054                         value
1055                         line-breaking))
1056         (setq attributes (delq 'numeric-value attributes))
1057         )))
1058     (when (and (memq 'iso-10646-comment attributes)
1059                (setq value (get-char-attribute char 'iso-10646-comment)))
1060       (insert (format "(iso-10646-comment\t. %S)%s"
1061                       value
1062                       line-breaking))
1063       (setq attributes (delq 'iso-10646-comment attributes))
1064       )
1065     (when (and (memq 'morohashi-daikanwa attributes)
1066                (setq value (get-char-attribute char 'morohashi-daikanwa)))
1067       (insert (format "(morohashi-daikanwa\t%s)%s"
1068                       (mapconcat (function prin1-to-string) value " ")
1069                       line-breaking))
1070       (setq attributes (delq 'morohashi-daikanwa attributes))
1071       )
1072     (setq radical nil
1073           strokes nil)
1074     (when (and (memq 'ideographic-radical attributes)
1075                (setq value (get-char-attribute char 'ideographic-radical)))
1076       (setq radical value)
1077       (insert (format "(ideographic-radical . %S)\t; %c%s"
1078                       radical
1079                       (ideographic-radical radical)
1080                       line-breaking))
1081       (setq attributes (delq 'ideographic-radical attributes))
1082       )
1083     (when (and (memq 'shuowen-radical attributes)
1084                (setq value (get-char-attribute char 'shuowen-radical)))
1085       (insert (format "(shuowen-radical\t. %S)\t; %c%s"
1086                       value
1087                       (shuowen-radical value)
1088                       line-breaking))
1089       (setq attributes (delq 'shuowen-radical attributes))
1090       )
1091     (let (key)
1092       (dolist (domain
1093                (append
1094                 char-db-feature-domains
1095                 (let (dest domain)
1096                   (dolist (feature (char-attribute-list))
1097                     (setq feature (symbol-name feature))
1098                     (when (string-match
1099                            "\\(radical\\|strokes\\)@\\([^@*]+\\)\\(\\*\\|$\\)"
1100                            feature)
1101                       (setq domain (intern (match-string 2 feature)))
1102                      (unless (memq domain dest)
1103                        (setq dest (cons domain dest)))))
1104                   (sort dest #'string<))))
1105         (setq key (intern (format "%s@%s" 'ideographic-radical domain)))
1106         (when (and (memq key attributes)
1107                    (setq value (get-char-attribute char key)))
1108           (setq radical value)
1109           (insert (format "(%s . %S)\t; %c%s"
1110                           key
1111                           radical
1112                           (ideographic-radical radical)
1113                           line-breaking))
1114           (setq attributes (delq key attributes))
1115           )
1116         (setq key (intern (format "%s@%s" 'ideographic-strokes domain)))
1117         (when (and (memq key attributes)
1118                    (setq value (get-char-attribute char key)))
1119           (setq strokes value)
1120           (insert (format "(%s . %S)%s"
1121                           key
1122                           strokes
1123                           line-breaking))
1124           (setq attributes (delq key attributes))
1125           )
1126         (setq key (intern (format "%s@%s" 'total-strokes domain)))
1127         (when (and (memq key attributes)
1128                    (setq value (get-char-attribute char key)))
1129           (insert (format "(%s       . %S)%s"
1130                           key
1131                           value
1132                           line-breaking))
1133           (setq attributes (delq key attributes))
1134           )
1135         (dolist (feature '(ideographic-radical
1136                            ideographic-strokes
1137                            total-strokes))
1138           (setq key (intern (format "%s@%s*sources" feature domain)))
1139           (when (and (memq key attributes)
1140                      (setq value (get-char-attribute char key)))
1141             (insert (format "(%s%s" key line-breaking))
1142             (dolist (cell value)
1143               (insert (format " %s" cell)))
1144             (insert ")")
1145             (insert line-breaking)
1146             (setq attributes (delq key attributes))
1147             ))
1148         ))
1149     (when (and (memq 'ideographic-strokes attributes)
1150                (setq value (get-char-attribute char 'ideographic-strokes)))
1151       (setq strokes value)
1152       (insert (format "(ideographic-strokes . %S)%s"
1153                       strokes
1154                       line-breaking))
1155       (setq attributes (delq 'ideographic-strokes attributes))
1156       )
1157     (when (and (memq 'kangxi-radical attributes)
1158                (setq value (get-char-attribute char 'kangxi-radical)))
1159       (unless (eq value radical)
1160         (insert (format "(kangxi-radical\t . %S)\t; %c%s"
1161                         value
1162                         (ideographic-radical value)
1163                         line-breaking))
1164         (or radical
1165             (setq radical value)))
1166       (setq attributes (delq 'kangxi-radical attributes))
1167       )
1168     (when (and (memq 'kangxi-strokes attributes)
1169                (setq value (get-char-attribute char 'kangxi-strokes)))
1170       (unless (eq value strokes)
1171         (insert (format "(kangxi-strokes\t . %S)%s"
1172                         value
1173                         line-breaking))
1174         (or strokes
1175             (setq strokes value)))
1176       (setq attributes (delq 'kangxi-strokes attributes))
1177       )
1178     ;; (when (and (memq 'japanese-radical attributes)
1179     ;;            (setq value (get-char-attribute char 'japanese-radical)))
1180     ;;   (unless (eq value radical)
1181     ;;     (insert (format "(japanese-radical\t . %S)\t; %c%s"
1182     ;;                     value
1183     ;;                     (ideographic-radical value)
1184     ;;                     line-breaking))
1185     ;;     (or radical
1186     ;;         (setq radical value)))
1187     ;;   (setq attributes (delq 'japanese-radical attributes))
1188     ;;   )
1189     (when (and (memq 'japanese-strokes attributes)
1190                (setq value (get-char-attribute char 'japanese-strokes)))
1191       (unless (eq value strokes)
1192         (insert (format "(japanese-strokes\t . %S)%s"
1193                         value
1194                         line-breaking))
1195         (or strokes
1196             (setq strokes value)))
1197       (setq attributes (delq 'japanese-strokes attributes))
1198       )
1199     (when (and (memq 'cns-radical attributes)
1200                (setq value (get-char-attribute char 'cns-radical)))
1201       (insert (format "(cns-radical\t . %S)\t; %c%s"
1202                       value
1203                       (ideographic-radical value)
1204                       line-breaking))
1205       (setq attributes (delq 'cns-radical attributes))
1206       )
1207     (when (and (memq 'cns-strokes attributes)
1208                (setq value (get-char-attribute char 'cns-strokes)))
1209       (unless (eq value strokes)
1210         (insert (format "(cns-strokes\t . %S)%s"
1211                         value
1212                         line-breaking))
1213         (or strokes
1214             (setq strokes value)))
1215       (setq attributes (delq 'cns-strokes attributes))
1216       )
1217     ;; (when (and (memq 'shinjigen-1-radical attributes)
1218     ;;            (setq value (get-char-attribute char 'shinjigen-1-radical)))
1219     ;;   (unless (eq value radical)
1220     ;;     (insert (format "(shinjigen-1-radical . %S)\t; %c%s"
1221     ;;                     value
1222     ;;                     (ideographic-radical value)
1223     ;;                     line-breaking))
1224     ;;     (or radical
1225     ;;         (setq radical value)))
1226     ;;   (setq attributes (delq 'shinjigen-1-radical attributes))
1227     ;;   )
1228     ;; (when (and (memq 'ideographic- attributes)
1229     ;;            (setq value (get-char-attribute char 'ideographic-)))
1230     ;;   (insert "(ideographic-       ")
1231     ;;   (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1232     ;;         separator nil)
1233     ;;   (while (consp value)
1234     ;;     (setq cell (car value))
1235     ;;     (if (integerp cell)
1236     ;;         (setq cell (decode-char '=ucs cell)))
1237     ;;     (cond ((characterp cell)
1238     ;;            (if separator
1239     ;;                (insert lbs))
1240     ;;            (if readable
1241     ;;                (insert (format "%S" cell))
1242     ;;              (char-db-insert-char-spec cell readable))
1243     ;;            (setq separator lbs))
1244     ;;           ((consp cell)
1245     ;;            (if separator
1246     ;;                (insert lbs))
1247     ;;            (if (consp (car cell))
1248     ;;                (char-db-insert-char-spec cell readable)
1249     ;;              (char-db-insert-char-reference cell readable))
1250     ;;            (setq separator lbs))
1251     ;;           (t
1252     ;;            (if separator
1253     ;;                (insert separator))
1254     ;;            (insert (prin1-to-string cell))
1255     ;;            (setq separator " ")))
1256     ;;     (setq value (cdr value)))
1257     ;;   (insert ")")
1258     ;;   (insert line-breaking)
1259     ;;   (setq attributes (delq 'ideographic- attributes)))
1260     (when (and (memq 'total-strokes attributes)
1261                (setq value (get-char-attribute char 'total-strokes)))
1262       (insert (format "(total-strokes       . %S)%s"
1263                       value
1264                       line-breaking))
1265       (setq attributes (delq 'total-strokes attributes))
1266       )
1267     ;; (when (and (memq '->ideograph attributes)
1268     ;;            (setq value (get-char-attribute char '->ideograph)))
1269     ;;   (insert (format "(->ideograph\t%s)%s"
1270     ;;                   (mapconcat (lambda (code)
1271     ;;                                (cond ((symbolp code)
1272     ;;                                       (symbol-name code))
1273     ;;                                      ((integerp code)
1274     ;;                                       (format "#x%04X" code))
1275     ;;                                      (t
1276     ;;                                       (format "%s %S"
1277     ;;                                               line-breaking code))))
1278     ;;                              value " ")
1279     ;;                   line-breaking))
1280     ;;   (setq attributes (delq '->ideograph attributes))
1281     ;;   )
1282     ;; (when (and (memq '->decomposition attributes)
1283     ;;            (setq value (get-char-attribute char '->decomposition)))
1284     ;;   (insert (format "(->decomposition\t%s)%s"
1285     ;;                   (mapconcat (lambda (code)
1286     ;;                                (cond ((symbolp code)
1287     ;;                                       (symbol-name code))
1288     ;;                                      ((characterp code)
1289     ;;                                       (if readable
1290     ;;                                           (format "%S" code)
1291     ;;                                         (format "#x%04X"
1292     ;;                                                 (char-int code))
1293     ;;                                         ))
1294     ;;                                      ((integerp code)
1295     ;;                                       (format "#x%04X" code))
1296     ;;                                      (t
1297     ;;                                       (format "%s%S" line-breaking code))))
1298     ;;                              value " ")
1299     ;;                   line-breaking))
1300     ;;   (setq attributes (delq '->decomposition attributes))
1301     ;;   )
1302     (if (equal (get-char-attribute char '->titlecase)
1303                (get-char-attribute char '->uppercase))
1304         (setq attributes (delq '->titlecase attributes)))
1305     (when (and (memq '->mojikyo attributes)
1306                (setq value (get-char-attribute char '->mojikyo)))
1307       (insert (format "(->mojikyo\t\t. %06d)\t; %c%s"
1308                       value (decode-char 'mojikyo value)
1309                       line-breaking))
1310       (setq attributes (delq '->mojikyo attributes))
1311       )
1312     ;; (when (and (memq 'hanyu-dazidian-vol attributes)
1313     ;;            (setq value (get-char-attribute char 'hanyu-dazidian-vol)))
1314     ;;   (insert (format "(hanyu-dazidian-vol  . %d)%s"
1315     ;;                   value line-breaking))
1316     ;;   (setq attributes (delq 'hanyu-dazidian-vol attributes))
1317     ;;   )
1318     ;; (when (and (memq 'hanyu-dazidian-page attributes)
1319     ;;            (setq value (get-char-attribute char 'hanyu-dazidian-page)))
1320     ;;   (insert (format "(hanyu-dazidian-page . %d)%s"
1321     ;;                   value line-breaking))
1322     ;;   (setq attributes (delq 'hanyu-dazidian-page attributes))
1323     ;;   )
1324     ;; (when (and (memq 'hanyu-dazidian-char attributes)
1325     ;;            (setq value (get-char-attribute char 'hanyu-dazidian-char)))
1326     ;;   (insert (format "(hanyu-dazidian-char . %d)%s"
1327     ;;                   value line-breaking))
1328     ;;   (setq attributes (delq 'hanyu-dazidian-char attributes))
1329     ;;   )
1330     (unless readable
1331       (dolist (ignored '(composition
1332                          ->denotational <-subsumptive ->ucs-unified
1333                          ->ideographic-component-forms))
1334         (setq attributes (delq ignored attributes))))
1335     (while attributes
1336       (setq name (car attributes))
1337       (unless (eq (setq value (get-char-attribute char name 'value-is-empty))
1338                   'value-is-empty)
1339         (cond ((setq ret (find-charset name))
1340                (setq name (charset-name ret))
1341                (when (not (memq name dest-ccss))
1342                  (setq dest-ccss (cons name dest-ccss))
1343                  (char-db-insert-ccs-feature name value line-breaking))
1344                )
1345               ((string-match "^=>ucs@" (symbol-name name))
1346                (insert (format "(%-18s . #x%04X)\t; %c%s"
1347                                name value (decode-char '=ucs value)
1348                                line-breaking))
1349                )
1350               ((eq name 'jisx0208-1978/4X)
1351                (insert (format "(%-18s . #x%04X)%s"
1352                                name value
1353                                line-breaking))
1354                )
1355               ((and
1356                 (not readable)
1357                 (not (eq name '->subsumptive))
1358                 (not (eq name '->uppercase))
1359                 (not (eq name '->lowercase))
1360                 (not (eq name '->titlecase))
1361                 (not (eq name '->canonical))
1362                 (not (eq name '->Bopomofo))
1363                 (not (eq name '->mistakable))
1364                 (not (eq name '->ideographic-variants))
1365                 (null (get-char-attribute
1366                        char (intern (format "%s*sources" name))))
1367                 (not (string-match "\\*sources$" (symbol-name name)))
1368                 (null (get-char-attribute
1369                        char (intern (format "%s*note" name))))
1370                 (not (string-match "\\*note$" (symbol-name name)))
1371                 (or (eq name '<-identical)
1372                     (eq name '<-uppercase)
1373                     (eq name '<-lowercase)
1374                     (eq name '<-titlecase)
1375                     (eq name '<-canonical)
1376                     (eq name '<-ideographic-variants)
1377                     ;; (eq name '<-synonyms)
1378                     (string-match "^<-synonyms" (symbol-name name))
1379                     (eq name '<-mistakable)
1380                     (when (string-match "^->" (symbol-name name))
1381                       (cond
1382                        ((string-match "^->fullwidth" (symbol-name name))
1383                         (not (and (consp value)
1384                                   (characterp (car value))
1385                                   (encode-char
1386                                    (car value) '=ucs 'defined-only)))
1387                         )
1388                        (t)))
1389                     ))
1390                )
1391               ((or (eq name 'ideographic-structure)
1392                    (eq name 'ideographic-combination)
1393                    ;; (eq name 'ideographic-)
1394                    (eq name '=decomposition)
1395                    (char-feature-base-name= '=decomposition name)
1396                    (char-feature-base-name= '=>decomposition name)
1397                    ;; (string-match "^=>*decomposition\\(@[^*]+\\)?$"
1398                    ;;               (symbol-name name))
1399                    (string-match "^\\(->\\|<-\\)[^*]*$" (symbol-name name))
1400                    (string-match "^\\(->\\|<-\\)[^*]*\\*sources$"
1401                                  (symbol-name name))
1402                    )
1403                (char-db-insert-relation-feature char name value
1404                                                 line-breaking
1405                                                 ccss readable))
1406               ;; ((memq name '(ideograph=
1407               ;;               original-ideograph-of
1408               ;;               ancient-ideograph-of
1409               ;;               vulgar-ideograph-of
1410               ;;               wrong-ideograph-of
1411               ;;               ;; simplified-ideograph-of
1412               ;;               ideographic-variants
1413               ;;               ;; ideographic-different-form-of
1414               ;;               ))
1415               ;;  (insert (format "(%-18s%s " name line-breaking))
1416               ;;  (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1417               ;;        separator nil)
1418               ;;  (while (consp value)
1419               ;;    (setq cell (car value))
1420               ;;    (if (and (consp cell)
1421               ;;             (consp (car cell)))
1422               ;;        (progn
1423               ;;          (if separator
1424               ;;              (insert lbs))
1425               ;;          (char-db-insert-alist cell readable)
1426               ;;          (setq separator lbs))
1427               ;;      (if separator
1428               ;;          (insert separator))
1429               ;;      (insert (prin1-to-string cell))
1430               ;;      (setq separator " "))
1431               ;;    (setq value (cdr value)))
1432               ;;  (insert ")")
1433               ;;  (insert line-breaking))
1434               ((consp value)
1435                (insert (format "(%-18s " name))
1436                (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1437                      separator nil)
1438                (while (consp value)
1439                  (setq cell (car value))
1440                  (if (and (consp cell)
1441                           (consp (car cell))
1442                           (setq ret (condition-case nil
1443                                         (find-char cell)
1444                                       (error nil))))
1445                      (progn
1446                        (setq rest cell
1447                              al nil
1448                              cal nil)
1449                        (while rest
1450                          (setq key (car (car rest)))
1451                          (if (find-charset key)
1452                              (setq cal (cons key cal))
1453                            (setq al (cons key al)))
1454                          (setq rest (cdr rest)))
1455                        (if separator
1456                            (insert lbs))
1457                        (insert-char-attributes ret
1458                                                readable
1459                                                al ; cal
1460                                                nil 'for-sub-node)
1461                        (setq separator lbs))
1462                    (setq ret (prin1-to-string cell))
1463                    (if separator
1464                        (if (< (+ (current-column)
1465                                  (length ret)
1466                                  (length separator))
1467                               76)
1468                            (insert separator)
1469                          (insert lbs)))
1470                    (insert ret)
1471                    (setq separator " "))
1472                  (setq value (cdr value)))
1473                (insert ")")
1474                (insert line-breaking))
1475               (t
1476                (insert (format "(%-18s" name))
1477                (setq ret (prin1-to-string value))
1478                (unless (< (+ (current-column)
1479                              (length ret)
1480                              3)
1481                           76)
1482                  (insert line-breaking))
1483                (insert " . " ret ")" line-breaking)
1484                ;; (insert (format "(%-18s . %S)%s"
1485                ;;                 name value
1486                ;;                 line-breaking))
1487                )
1488               ))
1489       (setq attributes (cdr attributes)))
1490     (insert ")")))
1491
1492 (defun insert-char-data (char &optional readable
1493                               attributes)
1494   (save-restriction
1495     (narrow-to-region (point)(point))
1496     (insert "(define-char
1497   '")
1498     (insert-char-attributes char readable attributes)
1499     (insert ")\n")
1500     (goto-char (point-min))
1501     (while (re-search-forward "[ \t]+$" nil t)
1502       (replace-match ""))
1503     ;; from tabify.
1504     (goto-char (point-min))
1505     (while (re-search-forward "[ \t][ \t][ \t]*" nil t)
1506       (let ((column (current-column))
1507             (indent-tabs-mode t))
1508         (delete-region (match-beginning 0) (point))
1509         (indent-to column)))
1510     (goto-char (point-max))
1511     ;; (tabify (point-min)(point-max))
1512     ))
1513
1514 (defun insert-char-data-with-variant (char &optional printable
1515                                            no-ucs-unified
1516                                            script excluded-script)
1517   (insert-char-data char printable)
1518   (let ((variants (char-variants char))
1519         rest
1520         variant vs ret)
1521     (setq variants (sort variants #'<))
1522     (setq rest variants)
1523     (setq variants (cons char variants))
1524     (while rest
1525       (setq variant (car rest))
1526       (unless (get-char-attribute variant '<-subsumptive)
1527         (if (and (or (null script)
1528                      (null (setq vs (get-char-attribute variant 'script)))
1529                      (memq script vs))
1530                  (or (null excluded-script)
1531                      (null (setq vs (get-char-attribute variant 'script)))
1532                      (not (memq excluded-script vs))))
1533             (unless (and no-ucs-unified (get-char-attribute variant '=ucs))
1534               (insert-char-data variant printable)
1535               (if (setq ret (char-variants variant))
1536                   (while ret
1537                     (or (memq (car ret) variants)
1538                         ;; (get-char-attribute (car ret) '<-subsumptive)
1539                         (setq rest (nconc rest (list (car ret)))))
1540                     (setq ret (cdr ret)))))))
1541       (setq rest (cdr rest)))))
1542
1543 (defun insert-char-range-data (min max &optional script excluded-script)
1544   (let ((code min)
1545         char)
1546     (while (<= code max)
1547       (setq char (decode-char '=ucs code))
1548       (if (encode-char char '=ucs 'defined-only)
1549           (insert-char-data-with-variant char nil 'no-ucs-unified
1550                                          script excluded-script))
1551       (setq code (1+ code)))))
1552
1553 (defun write-char-range-data-to-file (min max file
1554                                           &optional script excluded-script)
1555   (let ((coding-system-for-write char-db-file-coding-system))
1556     (with-temp-buffer
1557       (insert (format ";; -*- coding: %s -*-\n"
1558                       char-db-file-coding-system))
1559       (insert-char-range-data min max script excluded-script)
1560       (write-region (point-min)(point-max) file))))
1561
1562 (defvar what-character-original-window-configuration)
1563
1564 ;;;###autoload
1565 (defun what-char-definition (char)
1566   (interactive (list (char-after)))
1567   (let ((buf (get-buffer-create "*Character Description*"))
1568         (the-buf (current-buffer))
1569         (win-conf (current-window-configuration)))
1570     (pop-to-buffer buf)
1571     (make-local-variable 'what-character-original-window-configuration)
1572     (setq what-character-original-window-configuration win-conf)
1573     (setq buffer-read-only nil)
1574     (erase-buffer)
1575     (condition-case err
1576         (progn
1577           (insert-char-data-with-variant char 'printable)
1578           (unless (char-attribute-alist char)
1579             (insert (format ";; = %c\n"
1580                             (let* ((rest (split-char char))
1581                                    (ccs (pop rest))
1582                                    (code (pop rest)))
1583                               (while rest
1584                                 (setq code (logior (lsh code 8)
1585                                                    (pop rest))))
1586                               (decode-char ccs code)))))
1587           ;; (char-db-update-comment)
1588           (set-buffer-modified-p nil)
1589           (view-mode the-buf (lambda (buf)
1590                                (set-window-configuration
1591                                 what-character-original-window-configuration)
1592                                ))
1593           (goto-char (point-min)))
1594       (error (progn
1595                (set-window-configuration
1596                 what-character-original-window-configuration)
1597                (signal (car err) (cdr err)))))))
1598
1599
1600 ;;; @ end
1601 ;;;
1602
1603 (provide 'char-db-util)
1604
1605 ;;; char-db-util.el ends here