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