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