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