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