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