(A-U+5934-itaiji-001): New abstract node.
[chise/xemacs-chise.git] / lisp / utf-2000 / char-db-util.el
1 ;;; char-db-util.el --- Character Database utility -*- coding: utf-8-er; -*-
2
3 ;; Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007,
4 ;;   2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019,
5 ;;   2020, 2021, 2022, 2023, 2024 MORIOKA Tomohiko.
6
7 ;; Author: MORIOKA Tomohiko <tomo@kanji.zinbun.kyoto-u.ac.jp>
8 ;; Keywords: CHISE, Character Database, ISO/IEC 10646, UCS, Unicode, MULE.
9
10 ;; This file is part of XEmacs CHISE.
11
12 ;; XEmacs CHISE is free software; you can redistribute it and/or
13 ;; modify it under the terms of the GNU General Public License as
14 ;; published by the Free Software Foundation; either version 2, or (at
15 ;; your option) any later version.
16
17 ;; XEmacs CHISE is distributed in the hope that it will be useful,
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
20 ;; General Public License for more details.
21
22 ;; You should have received a copy of the GNU General Public License
23 ;; along with XEmacs CHISE; see the file COPYING.  If not, write to
24 ;; the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
25 ;; Boston, MA 02111-1307, USA.
26
27 ;;; Code:
28
29 (require 'chise-subr)
30 (require 'ideograph-subr)
31
32 (defconst unidata-normative-category-alist
33   '(("Lu" letter        uppercase)
34     ("Ll" letter        lowercase)
35     ("Lt" letter        titlecase)
36     ("Mn" mark          non-spacing)
37     ("Mc" mark          spacing-combining)
38     ("Me" mark          enclosing)
39     ("Nd" number        decimal-digit)
40     ("Nl" number        letter)
41     ("No" number        other)
42     ("Zs" separator     space)
43     ("Zl" separator     line)
44     ("Zp" separator     paragraph)
45     ("Cc" other         control)
46     ("Cf" other         format)
47     ("Cs" other         surrogate)
48     ("Co" other         private-use)
49     ("Cn" other         not-assigned)))
50
51 (defconst unidata-informative-category-alist
52   '(("Lm" letter        modifier)
53     ("Lo" letter        other)
54     ("Pc" punctuation   connector)
55     ("Pd" punctuation   dash)
56     ("Ps" punctuation   open)
57     ("Pe" punctuation   close)
58     ("Pi" punctuation   initial-quote)
59     ("Pf" punctuation   final-quote)
60     ("Po" punctuation   other)
61     ("Sm" symbol        math)
62     ("Sc" symbol        currency)
63     ("Sk" symbol        modifier)
64     ("So" symbol        other)
65     ))
66
67 (defconst shuowen-radicals
68   [?一 ?上 ?示 ?三 ?王 ?玉 ?玨 ?气 ?士 ?丨 ; 010
69    ?屮 ?艸 ?蓐 ?茻 ?小 ?八 ?釆 ?半 ?牛 ?犛 ; 020
70    ?告 ?口 ?凵 ?吅 ?哭 ?走 ?止 ?癶 ?步 ?此 ; 030
71    ?正 ?是 ?辵 ?彳 ?廴 ?㢟 ?行 ?齒 ?牙 ?足 ; 040
72    ?疋 ?品 ?龠 ?冊 ?㗊 ?舌 ?干 ?𧮫 ?只 ?㕯 ; 050
73    ?句 ?丩 ?古 ?十 ?卅 ?言 ?誩 ?音 ?䇂 ?丵 ; 060
74    ?菐 ?𠬞 ?𠬜 ?共 ?異 ?舁 ?𦥑 ?䢅 ?爨 ?革 ; 070
75    ?鬲 ?䰜 ?爪 ?𠃨 ?鬥 ?又 ?𠂇 ?史 ?支 ?𦘒 ; 080
76    ?聿 ?畫 ?隶 ?臤 ?臣 ?殳 ?殺 ?𠘧 ?寸 ?皮 ; 090
77    ?㼱 ?攴 ?敎 ?卜 ?用 ?爻 ?㸚 ?𥄎 ?目 ?䀠 ; 100
78    ?眉 ?盾 ?自 ?白 ?鼻 ?皕 ?習 ?羽 ?隹 ?奞 ; 110
79    ?雈 ?𦫳 ?𥄕 ?羊 ?羴 ?瞿 ?雔 ?雥 ?鳥 ?烏 ; 120
80    ?𠦒 ?冓 ?幺 ?𢆶 ?叀 ?玄 ?予 ?放 ?𠬪 ?𣦼 ; 130
81    ?歺 ?死 ?冎 ?骨 ?肉 ?筋 ?刀 ?刃 ?㓞 ?丯 ; 140
82    ?耒 ?角 ?竹 ?箕 ?丌 ?左 ?工 ?㠭 ?巫 ?甘 ; 150
83    ?曰 ?乃 ?丂 ?可 ?兮 ?号 ?亏 ?旨 ?喜 ?壴 ; 160
84 ;  ?旨 ?曰 ?乃 ?丂 ?可 ?兮 ?号 ?亏 ?喜 ?壴 ; 160
85    ?鼓 ?豈 ?豆 ?豊 ?豐 ?䖒 ?虍 ?虎 ?虤 ?皿 ; 170
86    ?𠙴 ?去 ?血 ?丶 ?丹 ?青 ?井 ?皀 ?鬯 ?食 ; 180
87    ?亼 ?會 ?倉 ?入 ?缶 ?矢 ?高 ?冂 ?𩫏 ?京 ; 190
88    ?亯 ?𣆪 ?畗 ?㐭 ?嗇 ?來 ?麥 ?夊 ?舛 ?䑞 ; 200
89    ?韋 ?弟 ?夂 ?久 ?桀 ?木 ?東 ?林 ?才 ?叒 ; 210
90    ?之 ?帀 ?出 ?𣎵 ?生 ?乇 ?𠂹 ?𠌶 ?華 ?𥝌 ; 220
91    ?稽 ?巢 ?桼 ?束 ?㯻 ?囗 ?員 ?貝 ?邑 ?𨛜 ; 230
92    ?日 ?旦 ?倝 ?㫃 ?冥 ?晶 ?月 ?有 ?明 ?囧 ; 240
93    ?夕 ?多 ?毌 ?𢎘 ?𣐺 ?卣 ?齊 ?朿 ?片 ?鼎 ; 250
94    ?克 ?彔 ?禾 ?秝 ?黍 ?香 ?米 ?毇 ?臼 ?凶 ; 260
95    ?𣎳 ?𣏟 ?麻 ?尗 ?耑 ?韭 ?瓜 ?瓠 ?宀 ?宮 ; 270
96    ?呂 ?穴 ?㝱 ?疒 ?冖 ?𠔼 ?冃 ?㒳 ?网 ?襾 ; 280
97    ?巾 ?巿 ?帛 ?白 ?㡀 ?黹 ?人 ?𠤎 ?匕 ?从 ; 290
98    ?比 ?北 ?丘 ?㐺 ?𡈼 ?重 ?臥 ?身 ?㐆 ?衣 ; 300
99    ?裘 ?老 ?毛 ?毳 ?尸 ?尺 ?尾 ?履 ?舟 ?方 ; 310
100    ?儿 ?兄 ?兂 ?皃 ?𠑹 ?先 ?秃 ?見 ?覞 ?欠 ; 320
101    ?㱃 ?㳄 ?旡 ?頁 ?𦣻 ?面 ?丏 ?首 ?𥄉 ?須 ; 330
102    ?彡 ?彣 ?文 ?髟 ?后 ?司 ?卮 ?卩 ?印 ?色 ; 340
103    ?𠨍 ?辟 ?勹 ?包 ?茍 ?鬼 ?甶 ?厶 ?嵬 ?山 ; 350
104    ?屾 ?屵 ?广 ?厂 ?丸 ?危 ?石 ?長 ?勿 ?冄 ; 360
105    ?而 ?豕 ?㣇 ?彑 ?豚 ?豸 ?𤉡 ?易 ?象 ?馬 ; 370
106    ?𢊁 ?鹿 ?麤 ?㲋 ?兔 ?萈 ?犬 ?㹜 ?鼠 ?能 ; 380
107    ?熊 ?火 ?炎 ?黑 ?囪 ?焱 ?炙 ?赤 ?大 ?亦 ; 390
108    ?夨 ?夭 ?交 ?尣 ?壺 ?壹 ?㚔 ?奢 ?亢 ?夲 ; 400
109    ?夰 ?亣 ?夫 ?立 ?竝 ?囟 ?思 ?心 ?惢 ?水 ; 410
110    ?沝 ?瀕 ?𡿨 ?巜 ?川 ?泉 ?灥 ?永 ?𠂢 ?谷 ; 420
111    ?仌 ?雨 ?雲 ?魚 ?𩺰 ?燕 ?龍 ?飛 ?非 ?卂 ; 430
112    ?𠃉 ?不 ?至 ?西 ?鹵 ?鹽 ?戶 ?門 ?耳 ?𦣝 ; 440
113    ?手 ?𠦬 ?女 ?毋 ?民 ?丿 ?𠂆 ?乁 ?氏 ?氐 ; 450
114    ?戈 ?戉 ?我 ?亅 ?琴 ?𠃊 ?亡 ?匸 ?匚 ?曲 ; 460
115    ?甾 ?瓦 ?弓 ?弜 ?弦 ?系 ?糸 ?素 ?絲 ?率 ; 470
116    ?虫 ?䖵 ?蟲 ?風 ?它 ?龜 ?黽 ?卵 ?二 ?土 ; 480
117    ?垚 ?堇 ?里 ?田 ?畕 ?黃 ?男 ?力 ?劦 ?金 ; 490
118    ?幵 ?勺 ?几 ?且 ?斤 ?斗 ?矛 ?車 ?𠂤 ?𨸏 ; 500
119    ?𨺅 ?厽 ?四 ?宁 ?叕 ?亞 ?五 ?六 ?七 ?九 ; 510
120    ?禸 ?嘼 ?甲 ?乙 ?丙 ?丁 ?戊 ?己 ?巴 ?庚 ; 520
121    ?辛 ?辡 ?壬 ?癸 ?子 ?了 ?孨 ?𠫓 ?丑 ?寅 ; 530
122    ?卯 ?辰 ?巳 ?午 ?未 ?申 ?酉 ?酋 ?戌 ?亥 ; 540
123    ])
124
125 (defun shuowen-radical (number)
126   (aref shuowen-radicals (1- number)))
127
128 (defvar char-db-file-coding-system 'utf-8-mcs-er)
129
130 (defvar char-db-ignored-attributes '(ideographic-products))
131
132 (defvar char-db-coded-charset-priority-list
133   '(ascii
134     control-1
135     latin-iso8859-1
136     latin-iso8859-2
137     latin-iso8859-3
138     latin-iso8859-4
139     latin-iso8859-9
140     latin-jisx0201
141     cyrillic-iso8859-5
142     greek-iso8859-7
143     thai-tis620
144     ;; =mj
145     ;; =adobe-japan1-0
146     ;; =adobe-japan1-1
147     ;; =adobe-japan1-2
148     ;; =adobe-japan1-3
149     ;; =adobe-japan1-4
150     ;; =adobe-japan1-5
151     ;; =adobe-japan1-6
152     =jis-x0208
153     =jis-x0208@1978
154     =jis-x0208@1983
155     japanese-jisx0212
156     chinese-gb2312
157     =jis-x0208@1990
158     chinese-cns11643-1
159     chinese-cns11643-2
160     chinese-cns11643-3
161     chinese-cns11643-4
162     chinese-cns11643-5
163     chinese-cns11643-6
164     chinese-cns11643-7
165     =jis-x0213-1
166     =jis-x0213-1@2000
167     =jis-x0213-1@2004
168     =jis-x0213-2
169     korean-ksc5601
170     chinese-isoir165
171     katakana-jisx0201
172     hebrew-iso8859-8
173     chinese-gb12345
174     latin-viscii
175     ethiopic-ucs
176     =big5-cdp
177     =hanyo-denshi/ja
178     =hanyo-denshi/jb
179     =hanyo-denshi/jc
180     =hanyo-denshi/jd
181     =hanyo-denshi/ft
182     =hanyo-denshi/ia
183     =hanyo-denshi/ib
184     =hanyo-denshi/hg
185     =hanyo-denshi/ip
186     =hanyo-denshi/jt
187     =hanyo-denshi/ks
188     =hanyo-denshi/tk
189     ;; ==mj
190     ;; ==adobe-japan1-0
191     ;; ==adobe-japan1-1
192     ;; ==adobe-japan1-2
193     ;; ==adobe-japan1-3
194     ;; ==adobe-japan1-4
195     ;; ==adobe-japan1-5
196     ;; ==adobe-japan1-6
197     ==jis-x0208
198     ==jis-x0213-1
199     ==jis-x0213-2
200     ==jis-x0212
201     ==hanyo-denshi/ja
202     ==hanyo-denshi/jb
203     ==hanyo-denshi/jc
204     ==hanyo-denshi/ft
205     ==hanyo-denshi/ia
206     ==hanyo-denshi/ib
207     ==hanyo-denshi/hg
208     ==hanyo-denshi/jt
209     ==hanyo-denshi/ks
210     ==hanyo-denshi/tk
211     =gt
212     =gt-k
213     =daikanwa
214     =daijiten
215     =daikanwa@rev2
216     =daikanwa@rev1
217     =daikanwa/+p
218     =daikanwa/ho
219     ==daikanwa
220     ==daijiten
221     =cbeta
222     ideograph-hanziku-1
223     ideograph-hanziku-2
224     ideograph-hanziku-3
225     ideograph-hanziku-4
226     ideograph-hanziku-5
227     ideograph-hanziku-6
228     ideograph-hanziku-7
229     ideograph-hanziku-8
230     ideograph-hanziku-9
231     ideograph-hanziku-10
232     ideograph-hanziku-11
233     ideograph-hanziku-12
234     ;; =>>>adobe-japan1-0
235     ;; =>>>adobe-japan1-1
236     ;; =>>>adobe-japan1-2
237     ;; =>>>adobe-japan1-3
238     ;; =>>>adobe-japan1-4
239     ;; =>>>adobe-japan1-5
240     ;; =>>>adobe-japan1-6
241     ;; =>>>jis-x0208
242     ;; =>>>jis-x0213-1
243     ;; =>>>jis-x0213-2
244     ;; =>>>hanyo-denshi/ja
245     ;; =>>>hanyo-denshi/jb
246     ;; =>>>hanyo-denshi/jc
247     ;; =>>>hanyo-denshi/ft
248     ;; =>>>hanyo-denshi/ib
249     ;; =>>>hanyo-denshi/hg
250     ;; =>>>hanyo-denshi/jt
251     ;; =>>>hanyo-denshi/ks
252     ;; =>>>gt
253     =>>mj
254     =>>adobe-japan1-0
255     =>>adobe-japan1-1
256     =>>adobe-japan1-2
257     =>>adobe-japan1-3
258     =>>adobe-japan1-4
259     =>>adobe-japan1-5
260     =>>adobe-japan1-6
261     =>>jis-x0208
262     =>>jis-x0213-1
263     =>>jis-x0213-1@2000
264     =>>jis-x0213-1@2004
265     =>>jis-x0213-2
266     =>>jis-x0208@1978
267     =>>hanyo-denshi/ft
268     =>>hanyo-denshi/jt
269     =>>hanyo-denshi/ks
270     =>>gt
271     =>>daikanwa
272     =>>cbeta
273     =+>jis-x0208
274     =+>jis-x0213-1
275     =+>jis-x0213-2
276     =+>adobe-japan1-0
277     =+>adobe-japan1-1
278     =+>adobe-japan1-2
279     =+>adobe-japan1-3
280     =+>adobe-japan1-4
281     =+>adobe-japan1-5
282     =+>adobe-japan1-6
283     =+>jis-x0208@1978
284     =>jis-x0208
285     =>jis-x0208@1997
286     =>jis-x0213-1
287     =>jis-x0213-1@2000
288     =>jis-x0213-1@2004
289     =>jis-x0213-2
290     ==>ucs@bucs
291     ==>daijiten
292     ;; =>ucs@hanyo-denshi
293     =>ucs@iso
294     =>ucs@unicode
295     =>ucs@jis
296     =>ucs@cns
297     =>ucs@ks
298     =+>ucs@iso
299     =+>ucs@unicode
300     =+>ucs@jis
301     =+>ucs@jis/1990
302     =+>ucs@cns
303     =+>ucs@ks
304     =>>ucs@iso
305     =>>ucs@unicode
306     =>>ucs@jis
307     =>>ucs@JP
308     =>>ucs@cns
309     =>>>ucs@iso
310     =>>>ucs@unicode
311     ==ucs@iso
312     ==ucs@unicode
313     ;; ==ucs@cns
314     ==gb2312
315     ==ks-x1001
316     ==cns11643-1
317     ==cns11643-2
318     ==cns11643-3
319     ==cns11643-4
320     ==cns11643-5
321     ==cns11643-6
322     ==cns11643-7
323     ==gt
324     ==jis-x0208@1990
325     ;; ==jis-x0208@1983
326     ==jis-x0208@1978
327     ==gt-k
328     =ucs@iso
329     =ucs@unicode
330     =ucs@cns
331     ==big5-cdp
332     ==cbeta
333     =>>big5-cdp
334     =>>gt-k
335     =+>gt
336     =+>big5-cdp
337     =>big5-cdp
338     =>big5-cdp@iwds-1
339     =>mj
340     =>hanyo-denshi/tk
341     =>iwds-1
342     =big5
343     =big5-eten
344     =zinbun-oracle
345     =>zinbun-oracle
346     =ruimoku-v6
347     =>>ruimoku-v6
348     ==ruimoku-v6
349     =>ruimoku-v6
350     =jef-china3
351     =shinjigen
352     =>cns11643-5
353     =>cns11643-7
354     =>gt
355     =>gt-k
356     =>daikanwa
357     =>daikanwa/ho
358     =>cbeta
359     =ucs-var-001
360     =ucs-var-002
361     =ucs-var-003
362     =ucs-var-004
363     =ucs-var-005
364     =ucs-var-006
365     =ucs-var-007
366     =ucs-var-008
367     =ucs-var-010
368     =ucs-itaiji-001
369     =ucs-itaiji-002
370     =ucs-itaiji-003
371     =ucs-itaiji-004
372     =ucs-itaiji-005
373     =ucs-itaiji-006
374     =ucs-itaiji-007
375     =ucs-itaiji-008
376     =ucs-itaiji-009
377     =ucs-itaiji-010
378     =ucs-itaiji-011
379     =ucs-itaiji-012
380     =ucs-itaiji-013
381     =ucs-itaiji-014
382     =ucs-itaiji-015
383     =ucs-itaiji-016
384     =ucs-itaiji-018
385     =+>ucs-var-003
386     =>ucs-itaiji-001
387     =>ucs-itaiji-002
388     =>ucs-itaiji-003
389     =>ucs-itaiji-004
390     =>ucs-itaiji-005
391     =>ucs-itaiji-006
392     =>ucs-itaiji-007
393     =>ucs-itaiji-008
394     =>ucs-itaiji-009
395     =>ucs-itaiji-010
396     =>ucs-itaiji-011
397     =>ucs-itaiji-012
398     =>ucs-itaiji-014
399     =>ucs-itaiji-015
400     =>ucs-itaiji-016
401     =>ucs-var-001
402     =big5-cdp-var-001
403     =big5-cdp-var-002
404     =big5-cdp-var-003
405     =big5-cdp-var-004
406     =big5-cdp-var-005
407     =big5-cdp-var-007
408     =big5-cdp-var-008
409     =big5-cdp-var-010
410     =big5-cdp-itaiji-001
411     =big5-cdp-itaiji-002
412     =big5-cdp-itaiji-003
413     =big5-cdp-itaiji-004
414     =big5-cdp-itaiji-005
415     =>big5-cdp-itaiji-001
416     =>big5-cdp-itaiji-002
417     =>big5-cdp-itaiji-003
418     =>big5-cdp-itaiji-004
419     =>big5-cdp-itaiji-005
420     =>big5-cdp-itaiji-006
421     =>big5-cdp-var-001
422     =>ucs@iwds-1
423     =>ucs@cognate
424     =>ucs@component
425     =>ucs@iwds-1/normalized
426     =>ucs-itaiji-001@iwds-1
427     =>ucs-itaiji-002@iwds-1
428     =>ucs-itaiji-003@iwds-1
429     =>ucs-itaiji-006@iwds-1
430     =>big5-cdp@component
431     =>big5-cdp@cognate
432     ==ucs@gb
433     =ucs@gb
434     ==ucs-var-002
435     ==ucs-itaiji-002
436     =ucs@JP/hanazono
437     =koseki
438     =shuowen-jiguge
439     =>shuowen-jiguge
440     ===shuowen-jiguge5
441     ===shuowen-jiguge4
442     ===chise-hdic-ktb-seal))
443
444
445 ;;; @ char-db formatters
446 ;;;
447
448 (defun char-db-make-char-spec (char)
449   (let (ret char-spec)
450     (cond ((characterp char)
451            (cond ((and (setq ret (encode-char char '=ucs 'defined-only))
452                        (not (and (<= #xE000 ret)(<= ret #xF8FF))))
453                   (setq char-spec (list (cons '=ucs ret)))
454                   (cond ((and (not (and (<= #xE0100 ret)(<= ret #xE01EF)))
455                               (setq ret (get-char-attribute char 'name)))
456                          (setq char-spec (cons (cons 'name ret) char-spec))
457                          )
458                         ((setq ret (get-char-attribute char 'name*))
459                          (setq char-spec (cons (cons 'name* ret) char-spec))
460                          ))
461                   )
462                  ((encode-char char '=mj 'defined-only)
463                   (setq char-spec nil)
464                   (dolist (ccs (charset-list))
465                     (if (and (or (eq ccs '=mj)
466                                  ;; (eq (charset-property ccs 'iso-ir) 177)
467                                  (string-match "=ucs@" (symbol-name ccs))
468                                  )
469                              (setq ccs (charset-name ccs))
470                              (null (assq ccs char-spec))
471                              (setq ret (encode-char char ccs 'defined-only)))
472                         (setq char-spec (cons (cons ccs ret) char-spec))))
473                   )
474                  ((encode-char char '==mj 'defined-only)
475                   (setq char-spec nil)
476                   (dolist (ccs (charset-list))
477                     (if (and (or (eq ccs '==mj)
478                                  ;; (eq (charset-property ccs 'iso-ir) 177)
479                                  (string-match "=ucs@" (symbol-name ccs))
480                                  )
481                              (setq ccs (charset-name ccs))
482                              (null (assq ccs char-spec))
483                              (setq ret (encode-char char ccs 'defined-only)))
484                         (setq char-spec (cons (cons ccs ret) char-spec))))
485                   )
486                  ((encode-char char '=adobe-japan1 'defined-only)
487                   (setq char-spec nil)
488                   (dolist (ccs (charset-list))
489                     (if (and (or (memq ccs
490                                        '(=adobe-japan1-0
491                                          =adobe-japan1-1
492                                          =adobe-japan1-2
493                                          =adobe-japan1-3
494                                          =adobe-japan1-4
495                                          =adobe-japan1-5
496                                          =adobe-japan1-6
497                                          ))
498                                  ;; (eq (charset-property ccs 'iso-ir) 177)
499                                  (string-match "=ucs@" (symbol-name ccs))
500                                  )
501                              (setq ccs (charset-name ccs))
502                              (null (assq ccs char-spec))
503                              (setq ret (encode-char char ccs 'defined-only)))
504                         (setq char-spec (cons (cons ccs ret) char-spec))))
505                   )
506                  ((encode-char char '==adobe-japan1 'defined-only)
507                   (setq char-spec nil)
508                   (dolist (ccs (charset-list))
509                     (if (and (or (memq ccs
510                                        '(==adobe-japan1-0
511                                          ==adobe-japan1-1
512                                          ==adobe-japan1-2
513                                          ==adobe-japan1-3
514                                          ==adobe-japan1-4
515                                          ==adobe-japan1-5
516                                          ==adobe-japan1-6
517                                          ))
518                                  ;; (eq (charset-property ccs 'iso-ir) 177)
519                                  (string-match "=ucs@" (symbol-name ccs))
520                                  )
521                              (setq ccs (charset-name ccs))
522                              (null (assq ccs char-spec))
523                              (setq ret (encode-char char ccs 'defined-only)))
524                         (setq char-spec (cons (cons ccs ret) char-spec))))
525                   )
526                  ((setq ret
527                         (catch 'tag
528                           (let ((rest char-db-coded-charset-priority-list)
529                                 ccs)
530                             (while rest
531                               (setq ccs (charset-name
532                                          (find-charset (car rest))))
533                               (if (setq ret
534                                         (encode-char char ccs
535                                                      'defined-only))
536                                   (throw 'tag (cons ccs ret)))
537                               (setq rest (cdr rest))))))
538                   (setq char-spec (list ret))
539                   (dolist (ccs (delq (car ret) (charset-list)))
540                     (if (and (or (charset-iso-final-char ccs)
541                                  (memq ccs
542                                        '(=daikanwa
543                                          =daikanwa@rev2
544                                          ;; =gt-k
545                                          =jis-x0208@1997
546                                          ))
547                                  (and (eq (charset-property ccs 'iso-ir) 177)
548                                       (not (eq (charset-name ccs) '=ucs@big5)))
549                                  ;; (string-match "=ucs@" (symbol-name ccs))
550                                  )
551                              (setq ccs (charset-name ccs))
552                              (null (assq ccs char-spec))
553                              (setq ret (encode-char char ccs 'defined-only)))
554                         (setq char-spec (cons (cons ccs ret) char-spec))))
555                   (if (null char-spec)
556                       (setq char-spec (split-char char)))
557                   (cond ((setq ret (get-char-attribute char 'name))
558                          (setq char-spec (cons (cons 'name ret) char-spec))
559                          )
560                         ((setq ret (get-char-attribute char 'name*))
561                          (setq char-spec (cons (cons 'name* ret) char-spec))
562                          ))
563                   )
564                  ((setq ret (get-char-attribute
565                              char 'ideographic-combination))
566                   (setq char-spec
567                         (cons (cons 'ideographic-combination ret)
568                               char-spec))
569                   ))
570            char-spec)
571           ((consp char)
572            char))))
573     
574 (defun char-db-insert-char-spec (char &optional readable column
575                                       required-features)
576   (unless column
577     (setq column (current-column)))
578   (let (char-spec temp-char)
579     (setq char-spec (char-db-make-char-spec char))
580     (unless (or (characterp char) ; char
581                 (condition-case nil
582                     (setq char (find-char char-spec))
583                   (error nil)))
584       ;; define temporary character
585       ;;   Current implementation is dirty.
586       (setq temp-char (define-char (cons '(ideograph-daikanwa . 0)
587                                          char-spec)))
588       (remove-char-attribute temp-char 'ideograph-daikanwa)
589       (setq char temp-char))
590     (insert-char-attributes char
591                             readable
592                             (union (mapcar #'car char-spec)
593                                    required-features)
594                             nil 'for-sub-node)
595     (when temp-char
596       ;; undefine temporary character
597       ;;   Current implementation is dirty.
598       (setq char-spec (char-attribute-alist temp-char))
599       (while char-spec
600         (remove-char-attribute temp-char (car (car char-spec)))
601         (setq char-spec (cdr char-spec))))))
602
603 (defun char-db-insert-alist (alist &optional readable column)
604   (unless column
605     (setq column (current-column)))
606   (let ((line-breaking
607          (concat "\n" (make-string (1+ column) ?\ )))
608         name value
609         ret al ; cal
610         key
611         lbs cell rest separator)
612     (insert "(")
613     (while alist
614       (setq name (car (car alist))
615             value (cdr (car alist)))
616       (cond ((eq name 'char)
617              (insert "(char . ")
618              (if (setq ret (condition-case nil
619                                (find-char value)
620                              (error nil)))
621                  (progn
622                    (setq al nil
623                          ;; cal nil
624                          )
625                    (while value
626                      (setq key (car (car value)))
627                      ;; (if (find-charset key)
628                      ;;     (setq cal (cons key cal))
629                      (setq al (cons key al))
630                      ;; )
631                      (setq value (cdr value)))
632                    (insert-char-attributes ret
633                                            readable
634                                            (or al 'none) ; cal
635                                            nil 'for-sub-node))
636                (insert (prin1-to-string value)))
637              (insert ")")
638              (insert line-breaking))
639             ((consp value)
640              (insert (format "(%-18s " name))
641              (setq lbs (concat "\n" (make-string (current-column) ?\ )))
642              (while (consp value)
643                (setq cell (car value))
644                (if (and (consp cell)
645                         (consp (car cell))
646                         (setq ret (condition-case nil
647                                       (find-char cell)
648                                     (error nil)))
649                         )
650                    (progn
651                      (setq rest cell
652                            al nil
653                            ;; cal nil
654                            )
655                      (while rest
656                        (setq key (car (car rest)))
657                        ;; (if (find-charset key)
658                        ;;     (setq cal (cons key cal))
659                        (setq al (cons key al))
660                        ;; )
661                        (setq rest (cdr rest)))
662                      (if separator
663                          (insert lbs))
664                      (insert-char-attributes ret
665                                              readable
666                                              al ; cal
667                                              nil 'for-sub-node)
668                      (setq separator lbs))
669                  (if separator
670                      (insert separator))
671                  (insert (prin1-to-string cell))
672                  (setq separator " "))
673                (setq value (cdr value)))
674              (insert ")")
675              (insert line-breaking))
676             (t
677              (insert (format "(%-18s . %S)%s"
678                              name value
679                              line-breaking))))
680       (setq alist (cdr alist))))
681   (insert ")"))
682
683 (defun char-db-insert-char-reference (plist &optional readable column)
684   (unless column
685     (setq column (current-column)))
686   (let ((line-breaking
687          (concat "\n" (make-string (1+ column) ?\ )))
688         (separator "")
689         name value)
690     (insert "(")
691     (while plist
692       (setq name (pop plist))
693       (setq value (pop plist))
694       (cond ((eq name :char)
695              (insert separator)
696              (insert ":char\t")
697              (cond ((numberp value)
698                     (setq value (decode-char '=ucs value)))
699                    ;; ((consp value)
700                    ;;  (setq value (or (find-char value)
701                    ;;                  value)))
702                    )
703              (char-db-insert-char-spec value readable)
704              (insert line-breaking)
705              (setq separator ""))
706             ((eq name :radical)
707              (insert (format "%s%s\t%d ; %c%s"
708                              separator
709                              name value
710                              (ideographic-radical value)
711                              line-breaking))
712              (setq separator ""))
713             (t
714              (insert (format "%s%s\t%S" separator name value))
715              (setq separator line-breaking)))
716       ))
717   (insert ")"))
718
719 (defun char-db-decode-isolated-char (ccs code-point)
720   (let (ret)
721     (setq ret
722           (cond ((eq ccs 'arabic-iso8859-6)
723                  (decode-char ccs code-point))
724                 ;; ((eq ccs '=gt)
725                 ;;  (decode-builtin-char '==gt code-point))
726                 ((and (memq ccs '(=gt-pj-1
727                                   =gt-pj-2
728                                   =gt-pj-3
729                                   =gt-pj-4
730                                   =gt-pj-5
731                                   =gt-pj-6
732                                   =gt-pj-7
733                                   =gt-pj-8
734                                   =gt-pj-9
735                                   =gt-pj-10
736                                   =gt-pj-11))
737                       (setq ret (decode-char ccs code-point))
738                       (setq ret (encode-char ret '=gt 'defined-only)))
739                  (decode-builtin-char '=gt ret))
740                 (t
741                  (decode-builtin-char ccs code-point))))
742     (cond ((null ret)
743            (or (decode-char ccs code-point)
744                (define-char (list (cons ccs code-point)))))
745           ((and (<= 0 (char-int ret))
746                 (<= (char-int ret) #x1F))
747            (decode-char '=ucs (+ #x2400 (char-int ret))))
748           ((= (char-int ret) #x7F)
749            ?\u2421)
750           (t ret))))
751
752 (defvar char-db-convert-obsolete-format t)
753
754 (defun char-db-insert-ccs-feature (name value line-breaking)
755   (cond
756    ((integerp value)
757     (insert
758      (format
759       (cond
760        ((memq name '(=>iwds-1
761                      ==shinjigen
762                      =shinjigen
763                      =shinjigen@1ed ==shinjigen@1ed
764                      =shinjigen@rev ==shinjigen@rev
765                      =shinjigen/+p@rev ==shinjigen/+p@rev
766                      ===daikanwa/ho ==daikanwa/ho
767                      =daikanwa/ho =>>daikanwa/ho =>daikanwa/ho))
768         "(%-18s .  %04d)\t; %c")
769        ((eq name '=shinjigen@1ed/24pr)
770         "(%-18s . %04d)\t; %c")
771        ((or
772          (memq name
773                '(===daikanwa
774                  ==daikanwa =daikanwa =>>daikanwa =>daikanwa
775                  =daikanwa@rev1 =daikanwa@rev2
776                  =daikanwa/+p ==daikanwa/+p ===daikanwa/+p
777                  =>>daikanwa/+p
778                  =daikanwa/+2p =>>daikanwa/+2p
779                  =gt ==gt ===gt
780                  =>>gt =+>gt =>gt
781                  =gt-k ==gt-k ===gt-k
782                  =>>gt-k =>gt-k
783                  =adobe-japan1-0 ==adobe-japan1-0 ===adobe-japan1-0
784                  =adobe-japan1-1 ==adobe-japan1-1 ===adobe-japan1-1
785                  =adobe-japan1-2 ==adobe-japan1-2 ===adobe-japan1-2
786                  =adobe-japan1-3 ==adobe-japan1-3 ===adobe-japan1-3
787                  =adobe-japan1-4 ==adobe-japan1-4 ===adobe-japan1-4
788                  =adobe-japan1-5 ==adobe-japan1-5 ===adobe-japan1-5
789                  =adobe-japan1-6 ==adobe-japan1-6 ===adobe-japan1-6
790                  =>>adobe-japan1-0 =+>adobe-japan1-0
791                  =>>adobe-japan1-1 =+>adobe-japan1-1
792                  =>>adobe-japan1-2 =+>adobe-japan1-2
793                  =>>adobe-japan1-3 =+>adobe-japan1-3
794                  =>>adobe-japan1-4 =+>adobe-japan1-4
795                  =>>adobe-japan1-5 =+>adobe-japan1-5
796                  =>>adobe-japan1-6 =+>adobe-japan1-6
797                  =>cbeta =cbeta =>>cbeta ==cbeta ===cbeta
798                  =zinbun-oracle =>zinbun-oracle
799                  =daijiten ==daijiten ===daijiten ==>daijiten
800                  ===hng-jou ===hng-keg ===hng-dng ===hng-mam
801                  ===hng-drt ===hng-kgk ===hng-myz ===hng-kda
802                  ===hng-khi ===hng-khm ===hng-fhs ===hng-hok
803                  ===hng-kyd ===hng-sok
804                  ===hng-yhk ===hng-kak ===hng-kar ===hng-kae
805                  ===hng-sys ===hng-tsu ===hng-tzj
806                  ===hng-hos ===hng-kkh ===hng-nak ===hng-jhk
807                  ===hng-hod ===hng-gok ===hng-ink ===hng-nto
808                  ===hng-nkm ===hng-k24 ===hng-ini ===hng-nkk
809                  ===hng-kcc ===hng-kcj ===hng-kbk ===hng-sik
810                  ===hng-skk ===hng-kyu ===hng-ksk ===hng-wan
811                  ===hng-okd ===hng-wad ===hng-kmi
812                  ===hng-zkd ===hng-doh ===hng-jyu ===hng-tzs
813                  ===hng-sai ===hng-kad ===hng-kss
814                  ===hng-kyo ===hng-ykk ===hng-saa
815                  ===hng-sab ===hng-wks ===hng-wke ===hng-smk
816                  ===hng-sgs ===hng-sts ===hng-kkd
817                  =>shuowen-jiguge =shuowen-jiguge
818                  ===shuowen-jiguge4 ===shuowen-jiguge5 ===shuowen-jiguge-A30))
819          ;; (string-match "^=adobe-" (symbol-name name))
820          )
821         "(%-18s . %05d)\t; %c")
822        ((memq name '(=hanyo-denshi/ks
823                      ==hanyo-denshi/ks ===hanyo-denshi/ks
824                      =>>hanyo-denshi/ks
825                      =koseki ==koseki
826                      =mj ==mj ===mj =>>mj =>mj
827                      =zihai mojikyo))
828         "(%-18s . %06d)\t; %c")
829        ((memq name '(=hanyo-denshi/tk =>hanyo-denshi/tk ==hanyo-denshi/tk))
830         "(%-18s . %08d)\t; %c")
831        ((>= (charset-dimension name) 2)
832         "(%-18s . #x%04X)\t; %c")
833        (t
834         "(%-18s . #x%02X)\t; %c"))
835       name
836       (if (= (charset-iso-graphic-plane name) 1)
837           (logior value
838                   (cond ((= (charset-dimension name) 1)
839                          #x80)
840                         ((= (charset-dimension name) 2)
841                          #x8080)
842                         ((= (charset-dimension name) 3)
843                          #x808080)
844                         (t 0)))
845         value)
846       (char-db-decode-isolated-char name value)))
847     (if (and (= (charset-chars name) 94)
848              (= (charset-dimension name) 2))
849         (insert (format " [%02d-%02d]"
850                         (- (lsh value -8) 32)
851                         (- (logand value 255) 32))))
852     )
853    (t
854     (insert (format "(%-18s . %s)" name value))
855     ))
856   (insert line-breaking))
857
858 (defun char-db-insert-relation-feature (char name value line-breaking
859                                              ccss readable)
860   (insert (format "(%-18s%s " name line-breaking))
861   (let ((lbs (concat "\n" (make-string (current-column) ?\ )))
862         separator cell sources required-features
863         ret)
864     (while (consp value)
865       (setq cell (car value))
866       (if (integerp cell)
867           (setq cell (decode-char '=ucs cell)))
868       (cond
869        ((eq name '->subsumptive)
870         (when (or (not (some (lambda (atr)
871                                (get-char-attribute cell atr))
872                              char-db-ignored-attributes))
873                   (some (lambda (ccs)
874                           (encode-char cell ccs 'defined-only))
875                         ccss))
876           (if separator
877               (insert lbs))
878           (let ((char-db-ignored-attributes
879                  (cons '<-subsumptive
880                        char-db-ignored-attributes)))
881             (insert-char-attributes cell readable nil nil 'for-sub-node))
882           (setq separator lbs))
883         )
884        ((characterp cell)
885         (setq sources
886               (get-char-attribute
887                char (intern (format "%s*sources" name))))
888         (setq required-features nil)
889         (dolist (source sources)
890           (cond
891            ((memq source '(JP
892                            JP/Jouyou
893                            shinjigen shinjigen@1ed shinjigen@rev))
894             (setq required-features
895                   (union required-features
896                          '(=jis-x0208
897                            =jis-x0208@1990
898                            =jis-x0213-1@2000
899                            =jis-x0213-1@2004
900                            =jis-x0213-2
901                            =jis-x0212
902                            =jis-x0208@1983
903                            =jis-x0208@1978
904                            =shinjigen
905                            =shinjigen@1ed
906                            =shinjigen@rev
907                            =shinjigen/+p@rev))))
908            ((eq source 'CN)
909             (setq required-features
910                   (union required-features
911                          '(=gb2312
912                            =gb12345
913                            =iso-ir165)))))
914           (cond
915            ((find-charset (setq ret (intern (format "=%s" source))))
916             (setq required-features
917                   (cons ret required-features)))
918            (t (setq required-features
919                     (cons source required-features)))))
920         (cond ((string-match "@JP" (symbol-name name))
921                (setq required-features
922                      (union required-features
923                             '(=jis-x0208
924                               =jis-x0208@1990
925                               =jis-x0213-1-2000
926                               =jis-x0213-2-2000
927                               =jis-x0212
928                               =jis-x0208@1983
929                               =jis-x0208@1978))))
930               ((string-match "@CN" (symbol-name name))
931                (setq required-features
932                      (union required-features
933                             '(=gb2312
934                               =gb12345
935                               =iso-ir165)))))
936         (if separator
937             (insert lbs))
938         (if readable
939             (insert (format "%S" cell))
940           (char-db-insert-char-spec cell readable
941                                     nil
942                                     required-features))
943         (setq separator lbs))
944        ((consp cell)
945         (if separator
946             (insert lbs))
947         (if (consp (car cell))
948             (char-db-insert-char-spec cell readable)
949           (char-db-insert-char-reference cell readable))
950         (setq separator lbs))
951        (t
952         (if separator
953             (insert separator))
954         (insert (prin1-to-string cell))
955         (setq separator " ")))
956       (setq value (cdr value)))
957     (insert ")")
958     (insert line-breaking)))
959
960 (defun insert-char-attributes (char &optional readable attributes column
961                                     for-sub-node)
962   (unless column
963     (setq column (current-column)))
964   (let (name value ; has-long-ccs-name
965         rest
966         radical strokes
967         (line-breaking
968          (concat "\n" (make-string (1+ column) ?\ )))
969         lbs cell separator ret
970         key al cal
971         dest-ccss ; sources required-features
972         ccss)
973     (let (atr-d)
974       (setq attributes
975             (sort (if attributes
976                       (if (consp attributes)
977                           (progn
978                             (dolist (name attributes)
979                               (unless (memq name char-db-ignored-attributes)
980                                 (if (find-charset name)
981                                     (push name ccss))
982                                 (push name atr-d)))
983                             atr-d))
984                     (dolist (name (char-attribute-list))
985                       (unless (memq name char-db-ignored-attributes)
986                         (if (find-charset name)
987                             (push name ccss))
988                         (push name atr-d)))
989                     atr-d)
990                   #'char-attribute-name<)))
991     (insert "(")
992     (when (memq '<-subsumptive attributes)
993       (when (or readable (not for-sub-node))
994         (when (setq value (get-char-attribute char '<-subsumptive))
995           (char-db-insert-relation-feature char '<-subsumptive value
996                                            line-breaking
997                                            ccss readable)))
998       (setq attributes (delq '<-subsumptive attributes)))
999     (when (and (memq '<-denotational attributes)
1000                (setq value (get-char-attribute char '<-denotational)))
1001       (char-db-insert-relation-feature char '<-denotational value
1002                                        line-breaking
1003                                        ccss readable)
1004       (setq attributes (delq '<-denotational attributes)))
1005     (when (and (memq '<-denotational@component attributes)
1006                (setq value (get-char-attribute char '<-denotational@component)))
1007       (char-db-insert-relation-feature char '<-denotational@component value
1008                                        line-breaking
1009                                        ccss readable)
1010       (setq attributes (delq '<-denotational@component attributes)))
1011     (when (and (memq '<-denotational@usage attributes)
1012                (setq value (get-char-attribute char '<-denotational@usage)))
1013       (char-db-insert-relation-feature char '<-denotational@usage value
1014                                        line-breaking
1015                                        ccss readable)
1016       (setq attributes (delq '<-denotational@usage attributes)))
1017     (when (and (memq 'name attributes)
1018                (setq value (get-char-attribute char 'name)))
1019       (insert (format
1020                (if (> (+ (current-column) (length value)) 48)
1021                    "(name . %S)%s"
1022                  "(name               . %S)%s")
1023                value line-breaking))
1024       (setq attributes (delq 'name attributes))
1025       )
1026     (when (and (memq 'name* attributes)
1027                (setq value (get-char-attribute char 'name*)))
1028       (insert (format
1029                (if (> (+ (current-column) (length value)) 48)
1030                    "(name* . %S)%s"
1031                  "(name*              . %S)%s")
1032                value line-breaking))
1033       (setq attributes (delq 'name* attributes))
1034       )
1035     (when (and (memq 'script attributes)
1036                (setq value (get-char-attribute char 'script)))
1037       (insert (format "(script\t\t%s)%s"
1038                       (mapconcat (function prin1-to-string)
1039                                  value " ")
1040                       line-breaking))
1041       (setq attributes (delq 'script attributes))
1042       )
1043     (dolist (name '(=>ucs =>ucs*))
1044       (when (and (memq name attributes)
1045                  (setq value (get-char-attribute char name)))
1046         (insert (format "(%-18s . #x%04X)\t; %c%s"
1047                         name value (decode-char '=ucs value)
1048                         line-breaking))
1049         (setq attributes (delq name attributes))))
1050     (dolist (name '(=>ucs@gb =>ucs@big5))
1051       (when (and (memq name attributes)
1052                  (setq value (get-char-attribute char name)))
1053         (insert (format "(%-18s . #x%04X)\t; %c%s"
1054                         name value
1055                         (decode-char (intern
1056                                       (concat "="
1057                                               (substring
1058                                                (symbol-name name) 2)))
1059                                      value)
1060                         line-breaking))
1061         (setq attributes (delq name attributes))
1062         ))
1063     ;; (dolist (name '(=>daikanwa))
1064     ;;   (when (and (memq name attributes)
1065     ;;              (setq value (get-char-attribute char name)))
1066     ;;     (insert
1067     ;;      (if (integerp value)
1068     ;;          (format "(%-18s . %05d)\t; %c%s"
1069     ;;                  name value (decode-char '=daikanwa value)
1070     ;;                  line-breaking)
1071     ;;        (format "(%-18s %s)\t; %c%s"
1072     ;;                name
1073     ;;                (mapconcat (function prin1-to-string)
1074     ;;                           value " ")
1075     ;;                (char-representative-of-daikanwa char)
1076     ;;                line-breaking)))
1077     ;;     (setq attributes (delq name attributes))))
1078     (when (and (memq 'general-category attributes)
1079                (setq value (get-char-attribute char 'general-category)))
1080       (insert (format
1081                "(general-category\t%s) ; %s%s"
1082                (mapconcat (lambda (cell)
1083                             (format "%S" cell))
1084                           value " ")
1085                (cond ((rassoc value unidata-normative-category-alist)
1086                       "Normative Category")
1087                      ((rassoc value unidata-informative-category-alist)
1088                       "Informative Category")
1089                      (t
1090                       "Unknown Category"))
1091                line-breaking))
1092       (setq attributes (delq 'general-category attributes))
1093       )
1094     (when (and (memq 'bidi-category attributes)
1095                (setq value (get-char-attribute char 'bidi-category)))
1096       (insert (format "(bidi-category\t. %S)%s"
1097                       value
1098                       line-breaking))
1099       (setq attributes (delq 'bidi-category attributes))
1100       )
1101     (unless (or (not (memq 'mirrored attributes))
1102                 (eq (setq value (get-char-attribute char 'mirrored 'empty))
1103                     'empty))
1104       (insert (format "(mirrored\t\t. %S)%s"
1105                       value
1106                       line-breaking))
1107       (setq attributes (delq 'mirrored attributes))
1108       )
1109     (cond
1110      ((and (memq 'decimal-digit-value attributes)
1111            (setq value (get-char-attribute char 'decimal-digit-value)))
1112       (insert (format "(decimal-digit-value . %S)%s"
1113                       value
1114                       line-breaking))
1115       (setq attributes (delq 'decimal-digit-value attributes))
1116       (when (and (memq 'digit-value attributes)
1117                  (setq value (get-char-attribute char 'digit-value)))
1118         (insert (format "(digit-value\t . %S)%s"
1119                         value
1120                         line-breaking))
1121         (setq attributes (delq 'digit-value attributes))
1122         )
1123       (when (and (memq 'numeric-value attributes)
1124                  (setq value (get-char-attribute char 'numeric-value)))
1125         (insert (format "(numeric-value\t . %S)%s"
1126                         value
1127                         line-breaking))
1128         (setq attributes (delq 'numeric-value attributes))
1129         )
1130       )
1131      (t
1132       (when (and (memq 'digit-value attributes)
1133                  (setq value (get-char-attribute char 'digit-value)))
1134         (insert (format "(digit-value\t. %S)%s"
1135                         value
1136                         line-breaking))
1137         (setq attributes (delq 'digit-value attributes))
1138         )
1139       (when (and (memq 'numeric-value attributes)
1140                  (setq value (get-char-attribute char 'numeric-value)))
1141         (insert (format "(numeric-value\t. %S)%s"
1142                         value
1143                         line-breaking))
1144         (setq attributes (delq 'numeric-value attributes))
1145         )))
1146     (when (and (memq 'iso-10646-comment attributes)
1147                (setq value (get-char-attribute char 'iso-10646-comment)))
1148       (insert (format "(iso-10646-comment\t. %S)%s"
1149                       value
1150                       line-breaking))
1151       (setq attributes (delq 'iso-10646-comment attributes))
1152       )
1153     (when (and (memq 'morohashi-daikanwa attributes)
1154                (setq value (get-char-attribute char 'morohashi-daikanwa)))
1155       (insert (format "(morohashi-daikanwa\t%s)%s"
1156                       (mapconcat (function prin1-to-string) value " ")
1157                       line-breaking))
1158       (setq attributes (delq 'morohashi-daikanwa attributes))
1159       )
1160     (setq radical nil
1161           strokes nil)
1162     (when (and (memq 'ideographic-radical attributes)
1163                (setq value (get-char-attribute char 'ideographic-radical)))
1164       (setq radical value)
1165       (insert (format "(ideographic-radical . %S)\t; %c%s"
1166                       radical
1167                       (ideographic-radical radical)
1168                       line-breaking))
1169       (setq attributes (delq 'ideographic-radical attributes))
1170       )
1171     (when (and (memq 'shuowen-radical attributes)
1172                (setq value (get-char-attribute char 'shuowen-radical)))
1173       (insert (format "(shuowen-radical\t. %S)\t; %c%s"
1174                       value
1175                       (shuowen-radical value)
1176                       line-breaking))
1177       (setq attributes (delq 'shuowen-radical attributes))
1178       )
1179     (let (key)
1180       (dolist (domain
1181                (append
1182                 char-db-feature-domains
1183                 (let (dest domain)
1184                   (dolist (feature (char-attribute-list))
1185                     (setq feature (symbol-name feature))
1186                     (when (string-match
1187                            "\\(radical\\|strokes\\)@\\([^@*]+\\)\\(\\*\\|$\\)"
1188                            feature)
1189                       (setq domain (intern (match-string 2 feature)))
1190                      (unless (memq domain dest)
1191                        (setq dest (cons domain dest)))))
1192                   (sort dest #'string<))))
1193         (setq key (intern (format "%s@%s" 'ideographic-radical domain)))
1194         (when (and (memq key attributes)
1195                    (setq value (get-char-attribute char key)))
1196           (setq radical value)
1197           (insert (format "(%s . %S)\t; %c%s"
1198                           key
1199                           radical
1200                           (ideographic-radical radical)
1201                           line-breaking))
1202           (setq attributes (delq key attributes))
1203           )
1204         (setq key (intern (format "%s@%s" 'ideographic-strokes domain)))
1205         (when (and (memq key attributes)
1206                    (setq value (get-char-attribute char key)))
1207           (setq strokes value)
1208           (insert (format "(%s . %S)%s"
1209                           key
1210                           strokes
1211                           line-breaking))
1212           (setq attributes (delq key attributes))
1213           )
1214         (setq key (intern (format "%s@%s" 'total-strokes domain)))
1215         (when (and (memq key attributes)
1216                    (setq value (get-char-attribute char key)))
1217           (insert (format "(%s       . %S)%s"
1218                           key
1219                           value
1220                           line-breaking))
1221           (setq attributes (delq key attributes))
1222           )
1223         (dolist (feature '(ideographic-radical
1224                            ideographic-strokes
1225                            total-strokes))
1226           (setq key (intern (format "%s@%s*sources" feature domain)))
1227           (when (and (memq key attributes)
1228                      (setq value (get-char-attribute char key)))
1229             (insert (format "(%s%s" key line-breaking))
1230             (dolist (cell value)
1231               (insert (format " %s" cell)))
1232             (insert ")")
1233             (insert line-breaking)
1234             (setq attributes (delq key attributes))
1235             ))
1236         ))
1237     (when (and (memq 'ideographic-strokes attributes)
1238                (setq value (get-char-attribute char 'ideographic-strokes)))
1239       (setq strokes value)
1240       (insert (format "(ideographic-strokes . %S)%s"
1241                       strokes
1242                       line-breaking))
1243       (setq attributes (delq 'ideographic-strokes attributes))
1244       )
1245     (when (and (memq 'kangxi-radical attributes)
1246                (setq value (get-char-attribute char 'kangxi-radical)))
1247       (unless (eq value radical)
1248         (insert (format "(kangxi-radical\t . %S)\t; %c%s"
1249                         value
1250                         (ideographic-radical value)
1251                         line-breaking))
1252         (or radical
1253             (setq radical value)))
1254       (setq attributes (delq 'kangxi-radical attributes))
1255       )
1256     (when (and (memq 'kangxi-strokes attributes)
1257                (setq value (get-char-attribute char 'kangxi-strokes)))
1258       (unless (eq value strokes)
1259         (insert (format "(kangxi-strokes\t . %S)%s"
1260                         value
1261                         line-breaking))
1262         (or strokes
1263             (setq strokes value)))
1264       (setq attributes (delq 'kangxi-strokes attributes))
1265       )
1266     ;; (when (and (memq 'japanese-radical attributes)
1267     ;;            (setq value (get-char-attribute char 'japanese-radical)))
1268     ;;   (unless (eq value radical)
1269     ;;     (insert (format "(japanese-radical\t . %S)\t; %c%s"
1270     ;;                     value
1271     ;;                     (ideographic-radical value)
1272     ;;                     line-breaking))
1273     ;;     (or radical
1274     ;;         (setq radical value)))
1275     ;;   (setq attributes (delq 'japanese-radical attributes))
1276     ;;   )
1277     (when (and (memq 'japanese-strokes attributes)
1278                (setq value (get-char-attribute char 'japanese-strokes)))
1279       (unless (eq value strokes)
1280         (insert (format "(japanese-strokes\t . %S)%s"
1281                         value
1282                         line-breaking))
1283         (or strokes
1284             (setq strokes value)))
1285       (setq attributes (delq 'japanese-strokes attributes))
1286       )
1287     (when (and (memq 'cns-radical attributes)
1288                (setq value (get-char-attribute char 'cns-radical)))
1289       (insert (format "(cns-radical\t . %S)\t; %c%s"
1290                       value
1291                       (ideographic-radical value)
1292                       line-breaking))
1293       (setq attributes (delq 'cns-radical attributes))
1294       )
1295     (when (and (memq 'cns-strokes attributes)
1296                (setq value (get-char-attribute char 'cns-strokes)))
1297       (unless (eq value strokes)
1298         (insert (format "(cns-strokes\t . %S)%s"
1299                         value
1300                         line-breaking))
1301         (or strokes
1302             (setq strokes value)))
1303       (setq attributes (delq 'cns-strokes attributes))
1304       )
1305     ;; (when (and (memq 'ideographic- attributes)
1306     ;;            (setq value (get-char-attribute char 'ideographic-)))
1307     ;;   (insert "(ideographic-       ")
1308     ;;   (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1309     ;;         separator nil)
1310     ;;   (while (consp value)
1311     ;;     (setq cell (car value))
1312     ;;     (if (integerp cell)
1313     ;;         (setq cell (decode-char '=ucs cell)))
1314     ;;     (cond ((characterp cell)
1315     ;;            (if separator
1316     ;;                (insert lbs))
1317     ;;            (if readable
1318     ;;                (insert (format "%S" cell))
1319     ;;              (char-db-insert-char-spec cell readable))
1320     ;;            (setq separator lbs))
1321     ;;           ((consp cell)
1322     ;;            (if separator
1323     ;;                (insert lbs))
1324     ;;            (if (consp (car cell))
1325     ;;                (char-db-insert-char-spec cell readable)
1326     ;;              (char-db-insert-char-reference cell readable))
1327     ;;            (setq separator lbs))
1328     ;;           (t
1329     ;;            (if separator
1330     ;;                (insert separator))
1331     ;;            (insert (prin1-to-string cell))
1332     ;;            (setq separator " ")))
1333     ;;     (setq value (cdr value)))
1334     ;;   (insert ")")
1335     ;;   (insert line-breaking)
1336     ;;   (setq attributes (delq 'ideographic- attributes)))
1337     (when (and (memq 'total-strokes attributes)
1338                (setq value (get-char-attribute char 'total-strokes)))
1339       (insert (format "(total-strokes       . %S)%s"
1340                       value
1341                       line-breaking))
1342       (setq attributes (delq 'total-strokes attributes))
1343       )
1344     ;; (when (and (memq '->ideograph attributes)
1345     ;;            (setq value (get-char-attribute char '->ideograph)))
1346     ;;   (insert (format "(->ideograph\t%s)%s"
1347     ;;                   (mapconcat (lambda (code)
1348     ;;                                (cond ((symbolp code)
1349     ;;                                       (symbol-name code))
1350     ;;                                      ((integerp code)
1351     ;;                                       (format "#x%04X" code))
1352     ;;                                      (t
1353     ;;                                       (format "%s %S"
1354     ;;                                               line-breaking code))))
1355     ;;                              value " ")
1356     ;;                   line-breaking))
1357     ;;   (setq attributes (delq '->ideograph attributes))
1358     ;;   )
1359     ;; (when (and (memq '->decomposition attributes)
1360     ;;            (setq value (get-char-attribute char '->decomposition)))
1361     ;;   (insert (format "(->decomposition\t%s)%s"
1362     ;;                   (mapconcat (lambda (code)
1363     ;;                                (cond ((symbolp code)
1364     ;;                                       (symbol-name code))
1365     ;;                                      ((characterp code)
1366     ;;                                       (if readable
1367     ;;                                           (format "%S" code)
1368     ;;                                         (format "#x%04X"
1369     ;;                                                 (char-int code))
1370     ;;                                         ))
1371     ;;                                      ((integerp code)
1372     ;;                                       (format "#x%04X" code))
1373     ;;                                      (t
1374     ;;                                       (format "%s%S" line-breaking code))))
1375     ;;                              value " ")
1376     ;;                   line-breaking))
1377     ;;   (setq attributes (delq '->decomposition attributes))
1378     ;;   )
1379     (if (equal (get-char-attribute char '->titlecase)
1380                (get-char-attribute char '->uppercase))
1381         (setq attributes (delq '->titlecase attributes)))
1382     (when (and (memq '->mojikyo attributes)
1383                (setq value (get-char-attribute char '->mojikyo)))
1384       (insert (format "(->mojikyo\t\t. %06d)\t; %c%s"
1385                       value (decode-char 'mojikyo value)
1386                       line-breaking))
1387       (setq attributes (delq '->mojikyo attributes))
1388       )
1389     (unless readable
1390       (dolist (ignored '(composition
1391                          ->denotational <-subsumptive ->ucs-unified
1392                          ;; ->ideographic-component-forms
1393                          ))
1394         (setq attributes (delq ignored attributes))))
1395     (while attributes
1396       (setq name (car attributes))
1397       (unless (eq (setq value (get-char-attribute char name 'value-is-empty))
1398                   'value-is-empty)
1399         (cond ((setq ret (find-charset name))
1400                (setq name (charset-name ret))
1401                (when (not (memq name dest-ccss))
1402                  (setq dest-ccss (cons name dest-ccss))
1403                  (char-db-insert-ccs-feature name value line-breaking))
1404                )
1405               ((string-match "^=>ucs@" (symbol-name name))
1406                (insert (format "(%-18s . #x%04X)\t; %c%s"
1407                                name value (decode-char '=ucs value)
1408                                line-breaking))
1409                )
1410               ((eq name 'jisx0208-1978/4X)
1411                (insert (format "(%-18s . #x%04X)%s"
1412                                name value
1413                                line-breaking))
1414                )
1415               ((and
1416                 (not readable)
1417                 (not (eq name '->subsumptive))
1418                 (not (eq name '->uppercase))
1419                 (not (eq name '->lowercase))
1420                 (not (eq name '->titlecase))
1421                 (not (eq name '->canonical))
1422                 (not (eq name '->Bopomofo))
1423                 (not (eq name '->mistakable))
1424                 (not (eq name '->ideographic-variants))
1425                 (null (get-char-attribute
1426                        char (intern (format "%s*sources" name))))
1427                 (not (string-match "\\*sources$" (symbol-name name)))
1428                 (null (get-char-attribute
1429                        char (intern (format "%s*note" name))))
1430                 (not (string-match "\\*note$" (symbol-name name)))
1431                 (or (eq name '<-identical)
1432                     (eq name '<-uppercase)
1433                     (eq name '<-lowercase)
1434                     (eq name '<-titlecase)
1435                     (eq name '<-canonical)
1436                     (eq name '<-ideographic-variants)
1437                     ;; (eq name '<-synonyms)
1438                     (string-match "^<-synonyms" (symbol-name name))
1439                     (eq name '<-mistakable)
1440                     (when (string-match "^->" (symbol-name name))
1441                       (cond
1442                        ((string-match "^->fullwidth" (symbol-name name))
1443                         (not (and (consp value)
1444                                   (characterp (car value))
1445                                   (encode-char
1446                                    (car value) '=ucs 'defined-only)))
1447                         )
1448                        (t)))
1449                     ))
1450                )
1451               ((or (eq name 'ideographic-structure)
1452                    (eq name 'ideographic-structure@apparent)
1453                    (eq name 'ideographic-structure@apparent/leftmost)
1454                    (eq name 'ideographic-structure@apparent/rightmost)
1455                    (eq name 'ideographic-combination)
1456                    ;; (eq name 'ideographic-)
1457                    (eq name '=decomposition)
1458                    (char-feature-base-name= '=decomposition name)
1459                    (char-feature-base-name= '=>decomposition name)
1460                    ;; (string-match "^=>*decomposition\\(@[^*]+\\)?$"
1461                    ;;               (symbol-name name))
1462                    (string-match "^\\(->\\|<-\\)[^*]*$" (symbol-name name))
1463                    (string-match "^\\(->\\|<-\\)[^*]*\\*sources$"
1464                                  (symbol-name name))
1465                    )
1466                (char-db-insert-relation-feature char name value
1467                                                 line-breaking
1468                                                 ccss readable))
1469               ;; ((memq name '(ideograph=
1470               ;;               original-ideograph-of
1471               ;;               ancient-ideograph-of
1472               ;;               vulgar-ideograph-of
1473               ;;               wrong-ideograph-of
1474               ;;               ;; simplified-ideograph-of
1475               ;;               ideographic-variants
1476               ;;               ;; ideographic-different-form-of
1477               ;;               ))
1478               ;;  (insert (format "(%-18s%s " name line-breaking))
1479               ;;  (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1480               ;;        separator nil)
1481               ;;  (while (consp value)
1482               ;;    (setq cell (car value))
1483               ;;    (if (and (consp cell)
1484               ;;             (consp (car cell)))
1485               ;;        (progn
1486               ;;          (if separator
1487               ;;              (insert lbs))
1488               ;;          (char-db-insert-alist cell readable)
1489               ;;          (setq separator lbs))
1490               ;;      (if separator
1491               ;;          (insert separator))
1492               ;;      (insert (prin1-to-string cell))
1493               ;;      (setq separator " "))
1494               ;;    (setq value (cdr value)))
1495               ;;  (insert ")")
1496               ;;  (insert line-breaking))
1497               ((consp value)
1498                (insert (format "(%-18s " name))
1499                (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1500                      separator nil)
1501                (while (consp value)
1502                  (setq cell (car value))
1503                  (if (and (consp cell)
1504                           (consp (car cell))
1505                           (setq ret (condition-case nil
1506                                         (find-char cell)
1507                                       (error nil))))
1508                      (progn
1509                        (setq rest cell
1510                              al nil
1511                              cal nil)
1512                        (while rest
1513                          (setq key (car (car rest)))
1514                          (if (find-charset key)
1515                              (setq cal (cons key cal))
1516                            (setq al (cons key al)))
1517                          (setq rest (cdr rest)))
1518                        (if separator
1519                            (insert lbs))
1520                        (insert-char-attributes ret
1521                                                readable
1522                                                al ; cal
1523                                                nil 'for-sub-node)
1524                        (setq separator lbs))
1525                    (setq ret (prin1-to-string cell))
1526                    (if separator
1527                        (if (< (+ (current-column)
1528                                  (length ret)
1529                                  (length separator))
1530                               76)
1531                            (insert separator)
1532                          (insert lbs)))
1533                    (insert ret)
1534                    (setq separator " "))
1535                  (setq value (cdr value)))
1536                (insert ")")
1537                (insert line-breaking))
1538               (t
1539                (insert (format "(%-18s" name))
1540                (setq ret (prin1-to-string value))
1541                (unless (< (+ (current-column)
1542                              (length ret)
1543                              3)
1544                           76)
1545                  (insert line-breaking))
1546                (insert " . " ret ")" line-breaking)
1547                ;; (insert (format "(%-18s . %S)%s"
1548                ;;                 name value
1549                ;;                 line-breaking))
1550                )
1551               ))
1552       (setq attributes (cdr attributes)))
1553     (insert ")")))
1554
1555 (defun insert-char-data (char &optional readable
1556                               attributes)
1557   (save-restriction
1558     (narrow-to-region (point)(point))
1559     (insert "(define-char
1560   '")
1561     (insert-char-attributes char readable attributes)
1562     (insert ")\n")
1563     (goto-char (point-min))
1564     (while (re-search-forward "[ \t]+$" nil t)
1565       (replace-match ""))
1566     ;; from tabify.
1567     (goto-char (point-min))
1568     (while (re-search-forward "[ \t][ \t][ \t]*" nil t)
1569       (let ((column (current-column))
1570             (indent-tabs-mode t))
1571         (delete-region (match-beginning 0) (point))
1572         (indent-to column)))
1573     (goto-char (point-max))
1574     ;; (tabify (point-min)(point-max))
1575     ))
1576
1577 (defun insert-char-data-with-variant (char &optional printable
1578                                            no-ucs-unified
1579                                            script excluded-script)
1580   (insert-char-data char printable)
1581   (let ((variants (char-variants char))
1582         rest
1583         variant vs ret)
1584     (setq variants (sort variants #'<))
1585     (setq rest variants)
1586     (setq variants (cons char variants))
1587     (while rest
1588       (setq variant (car rest))
1589       (unless (get-char-attribute variant '<-subsumptive)
1590         (if (and (or (null script)
1591                      (null (setq vs (get-char-attribute variant 'script)))
1592                      (memq script vs))
1593                  (or (null excluded-script)
1594                      (null (setq vs (get-char-attribute variant 'script)))
1595                      (not (memq excluded-script vs))))
1596             (unless (and no-ucs-unified (get-char-attribute variant '=ucs))
1597               (insert-char-data variant printable)
1598               (if (setq ret (char-variants variant))
1599                   (while ret
1600                     (or (memq (car ret) variants)
1601                         ;; (get-char-attribute (car ret) '<-subsumptive)
1602                         (setq rest (nconc rest (list (car ret)))))
1603                     (setq ret (cdr ret)))))))
1604       (setq rest (cdr rest)))))
1605
1606 (defun insert-char-range-data (min max &optional script excluded-script)
1607   (let ((code min)
1608         char)
1609     (while (<= code max)
1610       (setq char (decode-char '=ucs code))
1611       (if (encode-char char '=ucs 'defined-only)
1612           (insert-char-data-with-variant char nil 'no-ucs-unified
1613                                          script excluded-script))
1614       (setq code (1+ code)))))
1615
1616 (defun write-char-range-data-to-file (min max file
1617                                           &optional script excluded-script)
1618   (let ((coding-system-for-write char-db-file-coding-system))
1619     (with-temp-buffer
1620       (insert (format ";; -*- coding: %s -*-\n"
1621                       char-db-file-coding-system))
1622       (insert-char-range-data min max script excluded-script)
1623       (write-region (point-min)(point-max) file))))
1624
1625 (defvar what-character-original-window-configuration)
1626
1627 ;;;###autoload
1628 (defun what-char-definition (char)
1629   (interactive (list (char-after)))
1630   (let ((buf (get-buffer-create "*Character Description*"))
1631         (the-buf (current-buffer))
1632         (win-conf (current-window-configuration)))
1633     (pop-to-buffer buf)
1634     (make-local-variable 'what-character-original-window-configuration)
1635     (setq what-character-original-window-configuration win-conf)
1636     (setq buffer-read-only nil)
1637     (erase-buffer)
1638     (condition-case err
1639         (progn
1640           (insert-char-data-with-variant char 'printable)
1641           (unless (char-attribute-alist char)
1642             (insert (format ";; = %c\n"
1643                             (let* ((rest (split-char char))
1644                                    (ccs (pop rest))
1645                                    (code (pop rest)))
1646                               (while rest
1647                                 (setq code (logior (lsh code 8)
1648                                                    (pop rest))))
1649                               (decode-char ccs code)))))
1650           ;; (char-db-update-comment)
1651           (set-buffer-modified-p nil)
1652           (view-mode the-buf (lambda (buf)
1653                                (set-window-configuration
1654                                 what-character-original-window-configuration)
1655                                ))
1656           (goto-char (point-min)))
1657       (error (progn
1658                (set-window-configuration
1659                 what-character-original-window-configuration)
1660                (signal (car err) (cdr err)))))))
1661
1662
1663 ;;; @ end
1664 ;;;
1665
1666 (provide 'char-db-util)
1667
1668 ;;; char-db-util.el ends here