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