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