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