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