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