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