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