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