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