(char-db-coded-charset-priority-list): Add `==daikanwa'.
[chise/xemacs-chise.git.1] / lisp / utf-2000 / char-db-util.el
1 ;;; char-db-util.el --- Character Database utility -*- coding: utf-8-er; -*-
2
3 ;; Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006,
4 ;;   2007, 2008, 2009, 2010, 2011, 2012, 2013 MORIOKA Tomohiko.
5
6 ;; Author: MORIOKA Tomohiko <tomo@kanji.zinbun.kyoto-u.ac.jp>
7 ;; Keywords: CHISE, Character Database, ISO/IEC 10646, UCS, Unicode, MULE.
8
9 ;; This file is part of XEmacs CHISE.
10
11 ;; XEmacs CHISE is free software; you can redistribute it and/or
12 ;; modify it under the terms of the GNU General Public License as
13 ;; published by the Free Software Foundation; either version 2, or (at
14 ;; your option) any later version.
15
16 ;; XEmacs CHISE is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
19 ;; General Public License for more details.
20
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with XEmacs CHISE; see the file COPYING.  If not, write to
23 ;; the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
24 ;; Boston, MA 02111-1307, USA.
25
26 ;;; Code:
27
28 (require 'chise-subr)
29 (require 'ideograph-subr)
30
31 (defconst unidata-normative-category-alist
32   '(("Lu" letter        uppercase)
33     ("Ll" letter        lowercase)
34     ("Lt" letter        titlecase)
35     ("Mn" mark          non-spacing)
36     ("Mc" mark          spacing-combining)
37     ("Me" mark          enclosing)
38     ("Nd" number        decimal-digit)
39     ("Nl" number        letter)
40     ("No" number        other)
41     ("Zs" separator     space)
42     ("Zl" separator     line)
43     ("Zp" separator     paragraph)
44     ("Cc" other         control)
45     ("Cf" other         format)
46     ("Cs" other         surrogate)
47     ("Co" other         private-use)
48     ("Cn" other         not-assigned)))
49
50 (defconst unidata-informative-category-alist
51   '(("Lm" letter        modifier)
52     ("Lo" letter        other)
53     ("Pc" punctuation   connector)
54     ("Pd" punctuation   dash)
55     ("Ps" punctuation   open)
56     ("Pe" punctuation   close)
57     ("Pi" punctuation   initial-quote)
58     ("Pf" punctuation   final-quote)
59     ("Po" punctuation   other)
60     ("Sm" symbol        math)
61     ("Sc" symbol        currency)
62     ("Sk" symbol        modifier)
63     ("So" symbol        other)
64     ))
65
66 (defconst shuowen-radicals
67   [?一 ?上 ?示 ?三 ?王 ?玉 ?玨 ?气 ?士 ?丨 ; 010
68    ?屮 ?艸 ?蓐 ?茻 ?小 ?八 ?釆 ?半 ?牛 ?犛 ; 020
69    ?告 ?口 ?凵 ?吅 ?哭 ?走 ?止 ?癶 ?步 ?此 ; 030
70    ?正 ?是 ?辵 ?彳 ?廴 ?㢟 ?行 ?齒 ?牙 ?足 ; 040
71    ?疋 ?品 ?龠 ?冊 ?㗊 ?舌 ?干 ?谷 ?只 ?㕯 ; 050
72    ?句 ?丩 ?古 ?十 ?卅 ?言 ?誩 ?音 ?䇂 ?丵 ; 060
73    ?菐 ?𠬞 ?𠬜 ?共 ?異 ?舁 ?𦥑 ?䢅 ?爨 ?革 ; 070
74    ?鬲 ?䰜 ?爪 ?𠃨 ?鬥 ?又 ?𠂇 ?㕜 ?支 ?𦘒 ; 080
75    ?聿 ?畫 ?隶 ?臤 ?臣 ?殳 ?殺 ?𠘧 ?寸 ?皮 ; 090
76    ?㼱 ?攴 ?敎 ?卜 ?用 ?爻 ?㸚 ?𥄎 ?目 ?䀠 ; 100
77    ?眉 ?盾 ?自 ?白 ?鼻 ?皕 ?習 ?羽 ?隹 ?奞 ; 110
78    ?萑 ?𦫳 ?苜 ?羊 ?羴 ?瞿 ?雔 ?雥 ?鳥 ?烏 ; 120
79    ?𠦒 ?冓 ?幺 ?𢆶 ?叀 ?玄 ?予 ?放 ?𠬪 ?𣦼 ; 130
80    ?歺 ?死 ?冎 ?骨 ?肉 ?筋 ?刀 ?刃 ?㓞 ?丰 ; 140
81    ?耒 ?𧢲 ?竹 ?箕 ?丌 ?左 ?工 ?㠭 ?巫 ?甘 ; 150
82    ?曰 ?乃 ?丂 ?可 ?兮 ?号 ?亏 ?旨 ?喜 ?壴 ; 160
83 ;  ?旨 ?曰 ?乃 ?丂 ?可 ?兮 ?号 ?亏 ?喜 ?壴 ; 160
84    ?鼓 ?豈 ?豆 ?豊 ?豐 ?䖒 ?虍 ?虎 ?虤 ?皿 ; 170
85    ?𠙴 ?去 ?血 ?丶 ?丹 ?青 ?井 ?皀 ?鬯 ?食 ; 180
86    ?亼 ?會 ?倉 ?入 ?缶 ?矢 ?高 ?冂 ?𩫏 ?京 ; 190
87    ?亯 ?𣆪 ?畗 ?㐭 ?嗇 ?來 ?麥 ?夊 ?舛 ?䑞 ; 200
88    ?韋 ?弟 ?夂 ?久 ?桀 ?木 ?東 ?林 ?才 ?叒 ; 210
89    ?之 ?帀 ?出 ?𣎵 ?生 ?乇 ?𠂹 ?𠌶 ?華 ?𥝌 ; 220
90    ?稽 ?巢 ?桼 ?束 ?㯻 ?囗 ?員 ?貝 ?邑 ?𨛜 ; 230
91    ?日 ?旦 ?倝 ?㫃 ?冥 ?晶 ?月 ?有 ?明 ?囧 ; 240
92    ?夕 ?多 ?毌 ?𢎘 ?𣐺 ?卣 ?齊 ?朿 ?片 ?鼎 ; 250
93    ?克 ?彔 ?禾 ?秝 ?黍 ?香 ?米 ?毇 ?臼 ?凶 ; 260
94    ?𣎳 ?林 ?麻 ?尗 ?耑 ?韭 ?瓜 ?瓠 ?宀 ?宮 ; 270
95    ?呂 ?穴 ?㝱 ?𤕫 ?冖 ?𠔼 ?冃 ?㒳 ?网 ?襾 ; 280
96    ?巾 ?巿 ?帛 ?白 ?㡀 ?黹 ?人 ?𠤎 ?匕 ?从 ; 290
97    ?比 ?北 ?丘 ?㐺 ?𡈼 ?重 ?臥 ?身 ?㐆 ?衣 ; 300
98    ])
99
100 (defun shuowen-radical (number)
101   (aref shuowen-radicals (1- number)))
102
103 (defvar char-db-file-coding-system 'utf-8-mcs-er)
104
105 (defvar char-db-ignored-attributes '(ideographic-products))
106
107 (defvar char-db-coded-charset-priority-list
108   '(ascii
109     control-1
110     latin-iso8859-1
111     latin-iso8859-2
112     latin-iso8859-3
113     latin-iso8859-4
114     latin-iso8859-9
115     latin-jisx0201
116     cyrillic-iso8859-5
117     greek-iso8859-7
118     thai-tis620
119     =adobe-japan1-0
120     =adobe-japan1-1
121     =adobe-japan1-2
122     =adobe-japan1-3
123     =adobe-japan1-4
124     =adobe-japan1-5
125     =adobe-japan1-6
126     =jis-x0208
127     =jis-x0208@1978
128     =jis-x0208@1983
129     japanese-jisx0212
130     chinese-gb2312
131     =jis-x0208@1990
132     chinese-cns11643-1
133     chinese-cns11643-2
134     chinese-cns11643-3
135     chinese-cns11643-4
136     chinese-cns11643-5
137     chinese-cns11643-6
138     chinese-cns11643-7
139     =jis-x0213-1
140     =jis-x0213-1@2000
141     =jis-x0213-1@2004
142     =jis-x0213-2
143     korean-ksc5601
144     chinese-isoir165
145     katakana-jisx0201
146     hebrew-iso8859-8
147     chinese-gb12345
148     latin-viscii
149     ethiopic-ucs
150     =big5-cdp
151     =hanyo-denshi/ja
152     =hanyo-denshi/jb
153     =hanyo-denshi/jc
154     =hanyo-denshi/jd
155     =hanyo-denshi/ft
156     =hanyo-denshi/ia
157     =hanyo-denshi/ib
158     =hanyo-denshi/hg
159     =hanyo-denshi/jt
160     =hanyo-denshi/ks
161     =gt
162     =gt-k
163     ==adobe-japan1-0
164     ==adobe-japan1-1
165     ==adobe-japan1-2
166     ==adobe-japan1-3
167     ==adobe-japan1-4
168     ==adobe-japan1-5
169     ==adobe-japan1-6
170     ==jis-x0208
171     ==jis-x0213-1
172     ==jis-x0213-2
173     ==hanyo-denshi/ja
174     ==hanyo-denshi/jb
175     ==hanyo-denshi/jc
176     ==hanyo-denshi/ft
177     ==hanyo-denshi/ib
178     ==hanyo-denshi/hg
179     ==hanyo-denshi/jt
180     ==hanyo-denshi/ks
181     =daikanwa
182     =daikanwa@rev2
183     =daikanwa@rev1
184     ==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
594                      =shinjigen@rev ==shinjigen@rev
595                      =shinjigen/+p@rev
596                      =daikanwa/ho =>>daikanwa/ho =>daikanwa/ho))
597         "(%-18s .  %04d)\t; %c")
598        ((eq name '=shinjigen@1ed/24pr)
599         "(%-18s . %04d)\t; %c")
600        ((or (memq name '(==daikanwa
601                          =daikanwa =>>daikanwa =>daikanwa
602                          =daikanwa@rev1 =daikanwa@rev2
603                          =daikanwa/+p ==daikanwa/+p =>>daikanwa/+p
604                          =daikanwa/+2p =>>daikanwa/+2p
605                          =gt ==gt ; =>>>gt
606                          =>>gt =+>gt =>gt
607                          =gt-k ==gt-k =>>gt-k =>gt-k
608                          =adobe-japan1-0 ==adobe-japan1-0 ; =>>>adobe-japan1-0
609                          =adobe-japan1-1 ==adobe-japan1-1 ; =>>>adobe-japan1-1
610                          =adobe-japan1-2 ==adobe-japan1-2 ; =>>>adobe-japan1-2
611                          =adobe-japan1-3 ==adobe-japan1-3 ; =>>>adobe-japan1-3
612                          =adobe-japan1-4 ==adobe-japan1-4 ; =>>>adobe-japan1-4
613                          =adobe-japan1-5 ==adobe-japan1-5 ; =>>>adobe-japan1-5
614                          =adobe-japan1-6 ==adobe-japan1-6 ; =>>>adobe-japan1-6
615                          =>>adobe-japan1-0 =+>adobe-japan1-0
616                          =>>adobe-japan1-1 =+>adobe-japan1-1
617                          =>>adobe-japan1-2 =+>adobe-japan1-2
618                          =>>adobe-japan1-3 =+>adobe-japan1-3
619                          =>>adobe-japan1-4 =+>adobe-japan1-4
620                          =>>adobe-japan1-5 =+>adobe-japan1-5
621                          =>>adobe-japan1-6 =+>adobe-japan1-6
622                          =cbeta =>>cbeta
623                          =zinbun-oracle =>zinbun-oracle))
624             ;; (string-match "^=adobe-" (symbol-name name))
625             )
626         "(%-18s . %05d)\t; %c")
627        ((memq name '(=hanyo-denshi/ks
628                      ==hanyo-denshi/ks ; =>>>hanyo-denshi/ks
629                      =>>hanyo-denshi/ks
630                      =zihai mojikyo))
631         "(%-18s . %06d)\t; %c")
632        ((>= (charset-dimension name) 2)
633         "(%-18s . #x%04X)\t; %c")
634        (t
635         "(%-18s . #x%02X)\t; %c"))
636       name
637       (if (= (charset-iso-graphic-plane name) 1)
638           (logior value
639                   (cond ((= (charset-dimension name) 1)
640                          #x80)
641                         ((= (charset-dimension name) 2)
642                          #x8080)
643                         ((= (charset-dimension name) 3)
644                          #x808080)
645                         (t 0)))
646         value)
647       (char-db-decode-isolated-char name value)))
648     (if (and (= (charset-chars name) 94)
649              (= (charset-dimension name) 2))
650         (insert (format " [%02d-%02d]"
651                         (- (lsh value -8) 32)
652                         (- (logand value 255) 32))))
653     )
654    (t
655     (insert (format "(%-18s . %s)" name value))
656     ))
657   (insert line-breaking))
658
659 (defun char-db-insert-relation-feature (char name value line-breaking
660                                              ccss readable)
661   (insert (format "(%-18s%s " name line-breaking))
662   (let ((lbs (concat "\n" (make-string (current-column) ?\ )))
663         separator cell sources required-features
664         ret)
665     (while (consp value)
666       (setq cell (car value))
667       (if (integerp cell)
668           (setq cell (decode-char '=ucs cell)))
669       (cond
670        ((eq name '->subsumptive)
671         (when (or (not (some (lambda (atr)
672                                (get-char-attribute cell atr))
673                              char-db-ignored-attributes))
674                   (some (lambda (ccs)
675                           (encode-char cell ccs 'defined-only))
676                         ccss))
677           (if separator
678               (insert lbs))
679           (let ((char-db-ignored-attributes
680                  (cons '<-subsumptive
681                        char-db-ignored-attributes)))
682             (insert-char-attributes cell readable nil nil 'for-sub-node))
683           (setq separator lbs))
684         )
685        ((characterp cell)
686         (setq sources
687               (get-char-attribute
688                char (intern (format "%s*sources" name))))
689         (setq required-features nil)
690         (dolist (source sources)
691           (cond
692            ((memq source '(JP
693                            JP/Jouyou
694                            shinjigen shinjigen@1ed shinjigen@rev))
695             (setq required-features
696                   (union required-features
697                          '(=jis-x0208
698                            =jis-x0208@1990
699                            =jis-x0213-1@2000
700                            =jis-x0213-1@2004
701                            =jis-x0213-2
702                            =jis-x0212
703                            =jis-x0208@1983
704                            =jis-x0208@1978
705                            =shinjigen
706                            =shinjigen@1ed
707                            =shinjigen@rev
708                            =shinjigen/+p@rev))))
709            ((eq source 'CN)
710             (setq required-features
711                   (union required-features
712                          '(=gb2312
713                            =gb12345
714                            =iso-ir165)))))
715           (cond
716            ((find-charset (setq ret (intern (format "=%s" source))))
717             (setq required-features
718                   (cons ret required-features)))
719            (t (setq required-features
720                     (cons source required-features)))))
721         (cond ((string-match "@JP" (symbol-name name))
722                (setq required-features
723                      (union required-features
724                             '(=jis-x0208
725                               =jis-x0208@1990
726                               =jis-x0213-1-2000
727                               =jis-x0213-2-2000
728                               =jis-x0212
729                               =jis-x0208@1983
730                               =jis-x0208@1978))))
731               ((string-match "@CN" (symbol-name name))
732                (setq required-features
733                      (union required-features
734                             '(=gb2312
735                               =gb12345
736                               =iso-ir165)))))
737         (if separator
738             (insert lbs))
739         (if readable
740             (insert (format "%S" cell))
741           (char-db-insert-char-spec cell readable
742                                     nil
743                                     required-features))
744         (setq separator lbs))
745        ((consp cell)
746         (if separator
747             (insert lbs))
748         (if (consp (car cell))
749             (char-db-insert-char-spec cell readable)
750           (char-db-insert-char-reference cell readable))
751         (setq separator lbs))
752        (t
753         (if separator
754             (insert separator))
755         (insert (prin1-to-string cell))
756         (setq separator " ")))
757       (setq value (cdr value)))
758     (insert ")")
759     (insert line-breaking)))
760
761 (defun insert-char-attributes (char &optional readable attributes column
762                                     for-sub-node)
763   (unless column
764     (setq column (current-column)))
765   (let (name value ; has-long-ccs-name
766         rest
767         radical strokes
768         (line-breaking
769          (concat "\n" (make-string (1+ column) ?\ )))
770         lbs cell separator ret
771         key al cal
772         dest-ccss ; sources required-features
773         ccss)
774     (let (atr-d)
775       (setq attributes
776             (sort (if attributes
777                       (if (consp attributes)
778                           (progn
779                             (dolist (name attributes)
780                               (unless (memq name char-db-ignored-attributes)
781                                 (if (find-charset name)
782                                     (push name ccss))
783                                 (push name atr-d)))
784                             atr-d))
785                     (dolist (name (char-attribute-list))
786                       (unless (memq name char-db-ignored-attributes)
787                         (if (find-charset name)
788                             (push name ccss))
789                         (push name atr-d)))
790                     atr-d)
791                   #'char-attribute-name<)))
792     (insert "(")
793     (when (memq '<-subsumptive attributes)
794       (when (or readable (not for-sub-node))
795         (when (setq value (get-char-attribute char '<-subsumptive))
796           (char-db-insert-relation-feature char '<-subsumptive value
797                                            line-breaking
798                                            ccss readable)))
799       (setq attributes (delq '<-subsumptive attributes)))
800     (when (and (memq '<-denotational attributes)
801                (setq value (get-char-attribute char '<-denotational)))
802       (char-db-insert-relation-feature char '<-denotational value
803                                        line-breaking
804                                        ccss readable)
805       (setq attributes (delq '<-denotational attributes)))
806     (when (and (memq 'name attributes)
807                (setq value (get-char-attribute char 'name)))
808       (insert (format
809                (if (> (+ (current-column) (length value)) 48)
810                    "(name . %S)%s"
811                  "(name               . %S)%s")
812                value line-breaking))
813       (setq attributes (delq 'name attributes))
814       )
815     (when (and (memq 'name* attributes)
816                (setq value (get-char-attribute char 'name*)))
817       (insert (format
818                (if (> (+ (current-column) (length value)) 48)
819                    "(name* . %S)%s"
820                  "(name*              . %S)%s")
821                value line-breaking))
822       (setq attributes (delq 'name* attributes))
823       )
824     (when (and (memq 'script attributes)
825                (setq value (get-char-attribute char 'script)))
826       (insert (format "(script\t\t%s)%s"
827                       (mapconcat (function prin1-to-string)
828                                  value " ")
829                       line-breaking))
830       (setq attributes (delq 'script attributes))
831       )
832     (dolist (name '(=>ucs =>ucs*))
833       (when (and (memq name attributes)
834                  (setq value (get-char-attribute char name)))
835         (insert (format "(%-18s . #x%04X)\t; %c%s"
836                         name value (decode-char '=ucs value)
837                         line-breaking))
838         (setq attributes (delq name attributes))))
839     (dolist (name '(=>ucs@gb =>ucs@big5))
840       (when (and (memq name attributes)
841                  (setq value (get-char-attribute char name)))
842         (insert (format "(%-18s . #x%04X)\t; %c%s"
843                         name value
844                         (decode-char (intern
845                                       (concat "="
846                                               (substring
847                                                (symbol-name name) 2)))
848                                      value)
849                         line-breaking))
850         (setq attributes (delq name attributes))
851         ))
852     ;; (dolist (name '(=>daikanwa))
853     ;;   (when (and (memq name attributes)
854     ;;              (setq value (get-char-attribute char name)))
855     ;;     (insert
856     ;;      (if (integerp value)
857     ;;          (format "(%-18s . %05d)\t; %c%s"
858     ;;                  name value (decode-char '=daikanwa value)
859     ;;                  line-breaking)
860     ;;        (format "(%-18s %s)\t; %c%s"
861     ;;                name
862     ;;                (mapconcat (function prin1-to-string)
863     ;;                           value " ")
864     ;;                (char-representative-of-daikanwa char)
865     ;;                line-breaking)))
866     ;;     (setq attributes (delq name attributes))))
867     (when (and (memq 'general-category attributes)
868                (setq value (get-char-attribute char 'general-category)))
869       (insert (format
870                "(general-category\t%s) ; %s%s"
871                (mapconcat (lambda (cell)
872                             (format "%S" cell))
873                           value " ")
874                (cond ((rassoc value unidata-normative-category-alist)
875                       "Normative Category")
876                      ((rassoc value unidata-informative-category-alist)
877                       "Informative Category")
878                      (t
879                       "Unknown Category"))
880                line-breaking))
881       (setq attributes (delq 'general-category attributes))
882       )
883     (when (and (memq 'bidi-category attributes)
884                (setq value (get-char-attribute char 'bidi-category)))
885       (insert (format "(bidi-category\t. %S)%s"
886                       value
887                       line-breaking))
888       (setq attributes (delq 'bidi-category attributes))
889       )
890     (unless (or (not (memq 'mirrored attributes))
891                 (eq (setq value (get-char-attribute char 'mirrored 'empty))
892                     'empty))
893       (insert (format "(mirrored\t\t. %S)%s"
894                       value
895                       line-breaking))
896       (setq attributes (delq 'mirrored attributes))
897       )
898     (cond
899      ((and (memq 'decimal-digit-value attributes)
900            (setq value (get-char-attribute char 'decimal-digit-value)))
901       (insert (format "(decimal-digit-value . %S)%s"
902                       value
903                       line-breaking))
904       (setq attributes (delq 'decimal-digit-value attributes))
905       (when (and (memq 'digit-value attributes)
906                  (setq value (get-char-attribute char 'digit-value)))
907         (insert (format "(digit-value\t . %S)%s"
908                         value
909                         line-breaking))
910         (setq attributes (delq 'digit-value attributes))
911         )
912       (when (and (memq 'numeric-value attributes)
913                  (setq value (get-char-attribute char 'numeric-value)))
914         (insert (format "(numeric-value\t . %S)%s"
915                         value
916                         line-breaking))
917         (setq attributes (delq 'numeric-value attributes))
918         )
919       )
920      (t
921       (when (and (memq 'digit-value attributes)
922                  (setq value (get-char-attribute char 'digit-value)))
923         (insert (format "(digit-value\t. %S)%s"
924                         value
925                         line-breaking))
926         (setq attributes (delq 'digit-value attributes))
927         )
928       (when (and (memq 'numeric-value attributes)
929                  (setq value (get-char-attribute char 'numeric-value)))
930         (insert (format "(numeric-value\t. %S)%s"
931                         value
932                         line-breaking))
933         (setq attributes (delq 'numeric-value attributes))
934         )))
935     (when (and (memq 'iso-10646-comment attributes)
936                (setq value (get-char-attribute char 'iso-10646-comment)))
937       (insert (format "(iso-10646-comment\t. %S)%s"
938                       value
939                       line-breaking))
940       (setq attributes (delq 'iso-10646-comment attributes))
941       )
942     (when (and (memq 'morohashi-daikanwa attributes)
943                (setq value (get-char-attribute char 'morohashi-daikanwa)))
944       (insert (format "(morohashi-daikanwa\t%s)%s"
945                       (mapconcat (function prin1-to-string) value " ")
946                       line-breaking))
947       (setq attributes (delq 'morohashi-daikanwa attributes))
948       )
949     (setq radical nil
950           strokes nil)
951     (when (and (memq 'ideographic-radical attributes)
952                (setq value (get-char-attribute char 'ideographic-radical)))
953       (setq radical value)
954       (insert (format "(ideographic-radical . %S)\t; %c%s"
955                       radical
956                       (ideographic-radical radical)
957                       line-breaking))
958       (setq attributes (delq 'ideographic-radical attributes))
959       )
960     (when (and (memq 'shuowen-radical attributes)
961                (setq value (get-char-attribute char 'shuowen-radical)))
962       (insert (format "(shuowen-radical\t. %S)\t; %c%s"
963                       value
964                       (shuowen-radical value)
965                       line-breaking))
966       (setq attributes (delq 'shuowen-radical attributes))
967       )
968     (let (key)
969       (dolist (domain
970                (append
971                 char-db-feature-domains
972                 (let (dest domain)
973                   (dolist (feature (char-attribute-list))
974                     (setq feature (symbol-name feature))
975                     (when (string-match
976                            "\\(radical\\|strokes\\)@\\([^@*]+\\)\\(\\*\\|$\\)"
977                            feature)
978                       (setq domain (intern (match-string 2 feature)))
979                      (unless (memq domain dest)
980                        (setq dest (cons domain dest)))))
981                   (sort dest #'string<))))
982         (setq key (intern (format "%s@%s" 'ideographic-radical domain)))
983         (when (and (memq key attributes)
984                    (setq value (get-char-attribute char key)))
985           (setq radical value)
986           (insert (format "(%s . %S)\t; %c%s"
987                           key
988                           radical
989                           (ideographic-radical radical)
990                           line-breaking))
991           (setq attributes (delq key attributes))
992           )
993         (setq key (intern (format "%s@%s" 'ideographic-strokes domain)))
994         (when (and (memq key attributes)
995                    (setq value (get-char-attribute char key)))
996           (setq strokes value)
997           (insert (format "(%s . %S)%s"
998                           key
999                           strokes
1000                           line-breaking))
1001           (setq attributes (delq key attributes))
1002           )
1003         (setq key (intern (format "%s@%s" 'total-strokes domain)))
1004         (when (and (memq key attributes)
1005                    (setq value (get-char-attribute char key)))
1006           (insert (format "(%s       . %S)%s"
1007                           key
1008                           value
1009                           line-breaking))
1010           (setq attributes (delq key attributes))
1011           )
1012         (dolist (feature '(ideographic-radical
1013                            ideographic-strokes
1014                            total-strokes))
1015           (setq key (intern (format "%s@%s*sources" feature domain)))
1016           (when (and (memq key attributes)
1017                      (setq value (get-char-attribute char key)))
1018             (insert (format "(%s%s" key line-breaking))
1019             (dolist (cell value)
1020               (insert (format " %s" cell)))
1021             (insert ")")
1022             (insert line-breaking)
1023             (setq attributes (delq key attributes))
1024             ))
1025         ))
1026     (when (and (memq 'ideographic-strokes attributes)
1027                (setq value (get-char-attribute char 'ideographic-strokes)))
1028       (setq strokes value)
1029       (insert (format "(ideographic-strokes . %S)%s"
1030                       strokes
1031                       line-breaking))
1032       (setq attributes (delq 'ideographic-strokes attributes))
1033       )
1034     (when (and (memq 'kangxi-radical attributes)
1035                (setq value (get-char-attribute char 'kangxi-radical)))
1036       (unless (eq value radical)
1037         (insert (format "(kangxi-radical\t . %S)\t; %c%s"
1038                         value
1039                         (ideographic-radical value)
1040                         line-breaking))
1041         (or radical
1042             (setq radical value)))
1043       (setq attributes (delq 'kangxi-radical attributes))
1044       )
1045     (when (and (memq 'kangxi-strokes attributes)
1046                (setq value (get-char-attribute char 'kangxi-strokes)))
1047       (unless (eq value strokes)
1048         (insert (format "(kangxi-strokes\t . %S)%s"
1049                         value
1050                         line-breaking))
1051         (or strokes
1052             (setq strokes value)))
1053       (setq attributes (delq 'kangxi-strokes attributes))
1054       )
1055     (when (and (memq 'japanese-radical attributes)
1056                (setq value (get-char-attribute char 'japanese-radical)))
1057       (unless (eq value radical)
1058         (insert (format "(japanese-radical\t . %S)\t; %c%s"
1059                         value
1060                         (ideographic-radical value)
1061                         line-breaking))
1062         (or radical
1063             (setq radical value)))
1064       (setq attributes (delq 'japanese-radical attributes))
1065       )
1066     (when (and (memq 'japanese-strokes attributes)
1067                (setq value (get-char-attribute char 'japanese-strokes)))
1068       (unless (eq value strokes)
1069         (insert (format "(japanese-strokes\t . %S)%s"
1070                         value
1071                         line-breaking))
1072         (or strokes
1073             (setq strokes value)))
1074       (setq attributes (delq 'japanese-strokes attributes))
1075       )
1076     (when (and (memq 'cns-radical attributes)
1077                (setq value (get-char-attribute char 'cns-radical)))
1078       (insert (format "(cns-radical\t . %S)\t; %c%s"
1079                       value
1080                       (ideographic-radical value)
1081                       line-breaking))
1082       (setq attributes (delq 'cns-radical attributes))
1083       )
1084     (when (and (memq 'cns-strokes attributes)
1085                (setq value (get-char-attribute char 'cns-strokes)))
1086       (unless (eq value strokes)
1087         (insert (format "(cns-strokes\t . %S)%s"
1088                         value
1089                         line-breaking))
1090         (or strokes
1091             (setq strokes value)))
1092       (setq attributes (delq 'cns-strokes attributes))
1093       )
1094     ;; (when (and (memq 'shinjigen-1-radical attributes)
1095     ;;            (setq value (get-char-attribute char 'shinjigen-1-radical)))
1096     ;;   (unless (eq value radical)
1097     ;;     (insert (format "(shinjigen-1-radical . %S)\t; %c%s"
1098     ;;                     value
1099     ;;                     (ideographic-radical value)
1100     ;;                     line-breaking))
1101     ;;     (or radical
1102     ;;         (setq radical value)))
1103     ;;   (setq attributes (delq 'shinjigen-1-radical attributes))
1104     ;;   )
1105     (when (and (memq 'ideographic- attributes)
1106                (setq value (get-char-attribute char 'ideographic-)))
1107       (insert "(ideographic-       ")
1108       (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1109             separator nil)
1110       (while (consp value)
1111         (setq cell (car value))
1112         (if (integerp cell)
1113             (setq cell (decode-char '=ucs cell)))
1114         (cond ((characterp cell)
1115                (if separator
1116                    (insert lbs))
1117                (if readable
1118                    (insert (format "%S" cell))
1119                  (char-db-insert-char-spec cell readable))
1120                (setq separator lbs))
1121               ((consp cell)
1122                (if separator
1123                    (insert lbs))
1124                (if (consp (car cell))
1125                    (char-db-insert-char-spec cell readable)
1126                  (char-db-insert-char-reference cell readable))
1127                (setq separator lbs))
1128               (t
1129                (if separator
1130                    (insert separator))
1131                (insert (prin1-to-string cell))
1132                (setq separator " ")))
1133         (setq value (cdr value)))
1134       (insert ")")
1135       (insert line-breaking)
1136       (setq attributes (delq 'ideographic- attributes)))
1137     (when (and (memq 'total-strokes attributes)
1138                (setq value (get-char-attribute char 'total-strokes)))
1139       (insert (format "(total-strokes       . %S)%s"
1140                       value
1141                       line-breaking))
1142       (setq attributes (delq 'total-strokes attributes))
1143       )
1144     (when (and (memq '->ideograph attributes)
1145                (setq value (get-char-attribute char '->ideograph)))
1146       (insert (format "(->ideograph\t%s)%s"
1147                       (mapconcat (lambda (code)
1148                                    (cond ((symbolp code)
1149                                           (symbol-name code))
1150                                          ((integerp code)
1151                                           (format "#x%04X" code))
1152                                          (t
1153                                           (format "%s %S"
1154                                                   line-breaking code))))
1155                                  value " ")
1156                       line-breaking))
1157       (setq attributes (delq '->ideograph attributes))
1158       )
1159     ;; (when (and (memq '->decomposition attributes)
1160     ;;            (setq value (get-char-attribute char '->decomposition)))
1161     ;;   (insert (format "(->decomposition\t%s)%s"
1162     ;;                   (mapconcat (lambda (code)
1163     ;;                                (cond ((symbolp code)
1164     ;;                                       (symbol-name code))
1165     ;;                                      ((characterp code)
1166     ;;                                       (if readable
1167     ;;                                           (format "%S" code)
1168     ;;                                         (format "#x%04X"
1169     ;;                                                 (char-int code))
1170     ;;                                         ))
1171     ;;                                      ((integerp code)
1172     ;;                                       (format "#x%04X" code))
1173     ;;                                      (t
1174     ;;                                       (format "%s%S" line-breaking code))))
1175     ;;                              value " ")
1176     ;;                   line-breaking))
1177     ;;   (setq attributes (delq '->decomposition attributes))
1178     ;;   )
1179     (if (equal (get-char-attribute char '->titlecase)
1180                (get-char-attribute char '->uppercase))
1181         (setq attributes (delq '->titlecase attributes)))
1182     (when (and (memq '->mojikyo attributes)
1183                (setq value (get-char-attribute char '->mojikyo)))
1184       (insert (format "(->mojikyo\t\t. %06d)\t; %c%s"
1185                       value (decode-char 'mojikyo value)
1186                       line-breaking))
1187       (setq attributes (delq '->mojikyo attributes))
1188       )
1189     (when (and (memq 'hanyu-dazidian-vol attributes)
1190                (setq value (get-char-attribute char 'hanyu-dazidian-vol)))
1191       (insert (format "(hanyu-dazidian-vol  . %d)%s"
1192                       value line-breaking))
1193       (setq attributes (delq 'hanyu-dazidian-vol attributes))
1194       )
1195     (when (and (memq 'hanyu-dazidian-page attributes)
1196                (setq value (get-char-attribute char 'hanyu-dazidian-page)))
1197       (insert (format "(hanyu-dazidian-page . %d)%s"
1198                       value line-breaking))
1199       (setq attributes (delq 'hanyu-dazidian-page attributes))
1200       )
1201     (when (and (memq 'hanyu-dazidian-char attributes)
1202                (setq value (get-char-attribute char 'hanyu-dazidian-char)))
1203       (insert (format "(hanyu-dazidian-char . %d)%s"
1204                       value line-breaking))
1205       (setq attributes (delq 'hanyu-dazidian-char attributes))
1206       )
1207     (unless readable
1208       (dolist (ignored '(composition
1209                          ->denotational <-subsumptive ->ucs-unified
1210                          ->ideographic-component-forms))
1211         (setq attributes (delq ignored attributes))))
1212     (while attributes
1213       (setq name (car attributes))
1214       (unless (eq (setq value (get-char-attribute char name 'value-is-empty))
1215                   'value-is-empty)
1216         (cond ((setq ret (find-charset name))
1217                (setq name (charset-name ret))
1218                (when (not (memq name dest-ccss))
1219                  (setq dest-ccss (cons name dest-ccss))
1220                  (char-db-insert-ccs-feature name value line-breaking))
1221                )
1222               ((string-match "^=>ucs@" (symbol-name name))
1223                (insert (format "(%-18s . #x%04X)\t; %c%s"
1224                                name value (decode-char '=ucs value)
1225                                line-breaking))
1226                )
1227               ((eq name 'jisx0208-1978/4X)
1228                (insert (format "(%-18s . #x%04X)%s"
1229                                name value
1230                                line-breaking))
1231                )
1232               ((and
1233                 (not readable)
1234                 (not (eq name '->subsumptive))
1235                 (not (eq name '->uppercase))
1236                 (not (eq name '->lowercase))
1237                 (not (eq name '->titlecase))
1238                 (not (eq name '->canonical))
1239                 (not (eq name '->Bopomofo))
1240                 (not (eq name '->mistakable))
1241                 (not (eq name '->ideographic-variants))
1242                 (null (get-char-attribute
1243                        char (intern (format "%s*sources" name))))
1244                 (not (string-match "\\*sources$" (symbol-name name)))
1245                 (null (get-char-attribute
1246                        char (intern (format "%s*note" name))))
1247                 (not (string-match "\\*note$" (symbol-name name)))
1248                 (or (eq name '<-identical)
1249                     (eq name '<-uppercase)
1250                     (eq name '<-lowercase)
1251                     (eq name '<-titlecase)
1252                     (eq name '<-canonical)
1253                     (eq name '<-ideographic-variants)
1254                     ;; (eq name '<-synonyms)
1255                     (string-match "^<-synonyms" (symbol-name name))
1256                     (eq name '<-mistakable)
1257                     (when (string-match "^->" (symbol-name name))
1258                       (cond
1259                        ((string-match "^->fullwidth" (symbol-name name))
1260                         (not (and (consp value)
1261                                   (characterp (car value))
1262                                   (encode-char
1263                                    (car value) '=ucs 'defined-only)))
1264                         )
1265                        (t)))
1266                     ))
1267                )
1268               ((or (eq name 'ideographic-structure)
1269                    (eq name 'ideographic-combination)
1270                    (eq name 'ideographic-)
1271                    (eq name '=decomposition)
1272                    (char-feature-base-name= '=decomposition name)
1273                    (char-feature-base-name= '=>decomposition name)
1274                    ;; (string-match "^=>*decomposition\\(@[^*]+\\)?$"
1275                    ;;               (symbol-name name))
1276                    (string-match "^\\(->\\|<-\\)[^*]*$" (symbol-name name))
1277                    (string-match "^\\(->\\|<-\\)[^*]*\\*sources$"
1278                                  (symbol-name name))
1279                    )
1280                (char-db-insert-relation-feature char name value
1281                                                 line-breaking
1282                                                 ccss readable))
1283               ((memq name '(ideograph=
1284                             original-ideograph-of
1285                             ancient-ideograph-of
1286                             vulgar-ideograph-of
1287                             wrong-ideograph-of
1288                             ;; simplified-ideograph-of
1289                             ideographic-variants
1290                             ;; ideographic-different-form-of
1291                             ))
1292                (insert (format "(%-18s%s " name line-breaking))
1293                (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1294                      separator nil)
1295                (while (consp value)
1296                  (setq cell (car value))
1297                  (if (and (consp cell)
1298                           (consp (car cell)))
1299                      (progn
1300                        (if separator
1301                            (insert lbs))
1302                        (char-db-insert-alist cell readable)
1303                        (setq separator lbs))
1304                    (if separator
1305                        (insert separator))
1306                    (insert (prin1-to-string cell))
1307                    (setq separator " "))
1308                  (setq value (cdr value)))
1309                (insert ")")
1310                (insert line-breaking))
1311               ((consp value)
1312                (insert (format "(%-18s " name))
1313                (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1314                      separator nil)
1315                (while (consp value)
1316                  (setq cell (car value))
1317                  (if (and (consp cell)
1318                           (consp (car cell))
1319                           (setq ret (condition-case nil
1320                                         (find-char cell)
1321                                       (error nil))))
1322                      (progn
1323                        (setq rest cell
1324                              al nil
1325                              cal nil)
1326                        (while rest
1327                          (setq key (car (car rest)))
1328                          (if (find-charset key)
1329                              (setq cal (cons key cal))
1330                            (setq al (cons key al)))
1331                          (setq rest (cdr rest)))
1332                        (if separator
1333                            (insert lbs))
1334                        (insert-char-attributes ret
1335                                                readable
1336                                                al ; cal
1337                                                nil 'for-sub-node)
1338                        (setq separator lbs))
1339                    (setq ret (prin1-to-string cell))
1340                    (if separator
1341                        (if (< (+ (current-column)
1342                                  (length ret)
1343                                  (length separator))
1344                               76)
1345                            (insert separator)
1346                          (insert lbs)))
1347                    (insert ret)
1348                    (setq separator " "))
1349                  (setq value (cdr value)))
1350                (insert ")")
1351                (insert line-breaking))
1352               (t
1353                (insert (format "(%-18s" name))
1354                (setq ret (prin1-to-string value))
1355                (unless (< (+ (current-column)
1356                              (length ret)
1357                              3)
1358                           76)
1359                  (insert line-breaking))
1360                (insert " . " ret ")" line-breaking)
1361                ;; (insert (format "(%-18s . %S)%s"
1362                ;;                 name value
1363                ;;                 line-breaking))
1364                )
1365               ))
1366       (setq attributes (cdr attributes)))
1367     (insert ")")))
1368
1369 (defun insert-char-data (char &optional readable
1370                               attributes)
1371   (save-restriction
1372     (narrow-to-region (point)(point))
1373     (insert "(define-char
1374   '")
1375     (insert-char-attributes char readable attributes)
1376     (insert ")\n")
1377     (goto-char (point-min))
1378     (while (re-search-forward "[ \t]+$" nil t)
1379       (replace-match ""))
1380     ;; from tabify.
1381     (goto-char (point-min))
1382     (while (re-search-forward "[ \t][ \t][ \t]*" nil t)
1383       (let ((column (current-column))
1384             (indent-tabs-mode t))
1385         (delete-region (match-beginning 0) (point))
1386         (indent-to column)))
1387     (goto-char (point-max))
1388     ;; (tabify (point-min)(point-max))
1389     ))
1390
1391 (defun insert-char-data-with-variant (char &optional printable
1392                                            no-ucs-unified
1393                                            script excluded-script)
1394   (insert-char-data char printable)
1395   (let ((variants (char-variants char))
1396         rest
1397         variant vs ret)
1398     (setq variants (sort variants #'<))
1399     (setq rest variants)
1400     (setq variants (cons char variants))
1401     (while rest
1402       (setq variant (car rest))
1403       (unless (get-char-attribute variant '<-subsumptive)
1404         (if (and (or (null script)
1405                      (null (setq vs (get-char-attribute variant 'script)))
1406                      (memq script vs))
1407                  (or (null excluded-script)
1408                      (null (setq vs (get-char-attribute variant 'script)))
1409                      (not (memq excluded-script vs))))
1410             (unless (and no-ucs-unified (get-char-attribute variant '=ucs))
1411               (insert-char-data variant printable)
1412               (if (setq ret (char-variants variant))
1413                   (while ret
1414                     (or (memq (car ret) variants)
1415                         ;; (get-char-attribute (car ret) '<-subsumptive)
1416                         (setq rest (nconc rest (list (car ret)))))
1417                     (setq ret (cdr ret)))))))
1418       (setq rest (cdr rest)))))
1419
1420 (defun insert-char-range-data (min max &optional script excluded-script)
1421   (let ((code min)
1422         char)
1423     (while (<= code max)
1424       (setq char (decode-char '=ucs code))
1425       (if (encode-char char '=ucs 'defined-only)
1426           (insert-char-data-with-variant char nil 'no-ucs-unified
1427                                          script excluded-script))
1428       (setq code (1+ code)))))
1429
1430 (defun write-char-range-data-to-file (min max file
1431                                           &optional script excluded-script)
1432   (let ((coding-system-for-write char-db-file-coding-system))
1433     (with-temp-buffer
1434       (insert (format ";; -*- coding: %s -*-\n"
1435                       char-db-file-coding-system))
1436       (insert-char-range-data min max script excluded-script)
1437       (write-region (point-min)(point-max) file))))
1438
1439 (defvar what-character-original-window-configuration)
1440
1441 ;;;###autoload
1442 (defun what-char-definition (char)
1443   (interactive (list (char-after)))
1444   (let ((buf (get-buffer-create "*Character Description*"))
1445         (the-buf (current-buffer))
1446         (win-conf (current-window-configuration)))
1447     (pop-to-buffer buf)
1448     (make-local-variable 'what-character-original-window-configuration)
1449     (setq what-character-original-window-configuration win-conf)
1450     (setq buffer-read-only nil)
1451     (erase-buffer)
1452     (condition-case err
1453         (progn
1454           (insert-char-data-with-variant char 'printable)
1455           (unless (char-attribute-alist char)
1456             (insert (format ";; = %c\n"
1457                             (let* ((rest (split-char char))
1458                                    (ccs (pop rest))
1459                                    (code (pop rest)))
1460                               (while rest
1461                                 (setq code (logior (lsh code 8)
1462                                                    (pop rest))))
1463                               (decode-char ccs code)))))
1464           ;; (char-db-update-comment)
1465           (set-buffer-modified-p nil)
1466           (view-mode the-buf (lambda (buf)
1467                                (set-window-configuration
1468                                 what-character-original-window-configuration)
1469                                ))
1470           (goto-char (point-min)))
1471       (error (progn
1472                (set-window-configuration
1473                 what-character-original-window-configuration)
1474                (signal (car err) (cdr err)))))))
1475
1476
1477 ;;; @ end
1478 ;;;
1479
1480 (provide 'char-db-util)
1481
1482 ;;; char-db-util.el ends here