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