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