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