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