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