(char-db-insert-ccs-feature): Add setting for `=>>>gt'.
[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     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                             =cbeta =zinbun-oracle =>zinbun-oracle))
476                (string-match "^=adobe-" (symbol-name name)))
477            "(%-18s . %05d)\t; %c")
478           ((memq name '(=hanyo-denshi/ks =>>hanyo-denshi/ks mojikyo))
479            "(%-18s . %06d)\t; %c")
480           ((>= (charset-dimension name) 2)
481            "(%-18s . #x%04X)\t; %c")
482           (t
483            "(%-18s . #x%02X)\t; %c"))
484     name
485     (if (= (charset-iso-graphic-plane name) 1)
486         (logior value
487                 (cond ((= (charset-dimension name) 1)
488                        #x80)
489                       ((= (charset-dimension name) 2)
490                        #x8080)
491                       ((= (charset-dimension name) 3)
492                        #x808080)
493                       (t 0)))
494       value)
495     (char-db-decode-isolated-char name value)))
496   (if (and (= (charset-chars name) 94)
497            (= (charset-dimension name) 2))
498       (insert (format " [%02d-%02d]"
499                       (- (lsh value -8) 32)
500                       (- (logand value 255) 32))))
501   (insert line-breaking))
502
503 (defun char-db-insert-relation-feature (char name value line-breaking
504                                              ccss readable)
505   (insert (format "(%-18s%s " name line-breaking))
506   (let ((lbs (concat "\n" (make-string (current-column) ?\ )))
507         separator cell sources required-features
508         ret)
509     (while (consp value)
510       (setq cell (car value))
511       (if (integerp cell)
512           (setq cell (decode-char '=ucs cell)))
513       (cond
514        ((eq name '->subsumptive)
515         (when (or (not (some (lambda (atr)
516                                (get-char-attribute cell atr))
517                              char-db-ignored-attributes))
518                   (some (lambda (ccs)
519                           (encode-char cell ccs 'defined-only))
520                         ccss))
521           (if separator
522               (insert lbs))
523           (let ((char-db-ignored-attributes
524                  (cons '<-subsumptive
525                        char-db-ignored-attributes)))
526             (insert-char-attributes cell readable))
527           (setq separator lbs))
528         )
529        ((characterp cell)
530         (setq sources
531               (get-char-attribute
532                char (intern (format "%s*sources" name))))
533         (setq required-features nil)
534         (dolist (source sources)
535           (cond
536            ((memq source '(JP
537                            JP/Jouyou
538                            shinjigen shinjigen@1ed shinjigen@rev))
539             (setq required-features
540                   (union required-features
541                          '(=jis-x0208
542                            =jis-x0208@1990
543                            =jis-x0213-1@2000
544                            =jis-x0213-1@2004
545                            =jis-x0213-2
546                            =jis-x0212
547                            =jis-x0208@1983
548                            =jis-x0208@1978
549                            =shinjigen))))
550            ((eq source 'CN)
551             (setq required-features
552                   (union required-features
553                          '(=gb2312
554                            =gb12345
555                            =iso-ir165)))))
556           (cond
557            ((find-charset (setq ret (intern (format "=%s" source))))
558             (setq required-features
559                   (cons ret required-features)))
560            (t (setq required-features
561                     (cons source required-features)))))
562         (cond ((string-match "@JP" (symbol-name name))
563                (setq required-features
564                      (union required-features
565                             '(=jis-x0208
566                               =jis-x0208@1990
567                               =jis-x0213-1-2000
568                               =jis-x0213-2-2000
569                               =jis-x0212
570                               =jis-x0208@1983
571                               =jis-x0208@1978))))
572               ((string-match "@CN" (symbol-name name))
573                (setq required-features
574                      (union required-features
575                             '(=gb2312
576                               =gb12345
577                               =iso-ir165)))))
578         (if separator
579             (insert lbs))
580         (if readable
581             (insert (format "%S" cell))
582           (char-db-insert-char-spec cell readable
583                                     nil
584                                     required-features))
585         (setq separator lbs))
586        ((consp cell)
587         (if separator
588             (insert lbs))
589         (if (consp (car cell))
590             (char-db-insert-char-spec cell readable)
591           (char-db-insert-char-reference cell readable))
592         (setq separator lbs))
593        (t
594         (if separator
595             (insert separator))
596         (insert (prin1-to-string cell))
597         (setq separator " ")))
598       (setq value (cdr value)))
599     (insert ")")
600     (insert line-breaking)))
601
602 (defun insert-char-attributes (char &optional readable attributes column)
603   (unless column
604     (setq column (current-column)))
605   (let (name value ; has-long-ccs-name
606         rest
607         radical strokes
608         (line-breaking
609          (concat "\n" (make-string (1+ column) ?\ )))
610         lbs cell separator ret
611         key al cal
612         dest-ccss ; sources required-features
613         ccss)
614     (let (atr-d)
615       (setq attributes
616             (sort (if attributes
617                       (if (consp attributes)
618                           (progn
619                             (dolist (name attributes)
620                               (unless (memq name char-db-ignored-attributes)
621                                 (if (find-charset name)
622                                     (push name ccss))
623                                 (push name atr-d)))
624                             atr-d))
625                     (dolist (name (char-attribute-list))
626                       (unless (memq name char-db-ignored-attributes)
627                         (if (find-charset name)
628                             (push name ccss))
629                         (push name atr-d)))
630                     atr-d)
631                   #'char-attribute-name<)))
632     (insert "(")
633     (when (memq '<-subsumptive attributes)
634       (when readable
635         (when (setq value (get-char-attribute char '<-subsumptive))
636           (char-db-insert-relation-feature char '<-subsumptive value
637                                            line-breaking
638                                            ccss readable)))
639       (setq attributes (delq '<-subsumptive attributes)))
640     (when (and (memq '<-denotational attributes)
641                (setq value (get-char-attribute char '<-denotational)))
642       (char-db-insert-relation-feature char '<-denotational value
643                                        line-breaking
644                                        ccss readable)
645       (setq attributes (delq '<-denotational attributes)))
646     (when (and (memq 'name attributes)
647                (setq value (get-char-attribute char 'name)))
648       (insert (format
649                (if (> (+ (current-column) (length value)) 48)
650                    "(name . %S)%s"
651                  "(name               . %S)%s")
652                value line-breaking))
653       (setq attributes (delq 'name attributes))
654       )
655     (when (and (memq 'name* attributes)
656                (setq value (get-char-attribute char 'name*)))
657       (insert (format
658                (if (> (+ (current-column) (length value)) 48)
659                    "(name* . %S)%s"
660                  "(name*              . %S)%s")
661                value line-breaking))
662       (setq attributes (delq 'name* attributes))
663       )
664     (when (and (memq 'script attributes)
665                (setq value (get-char-attribute char 'script)))
666       (insert (format "(script\t\t%s)%s"
667                       (mapconcat (function prin1-to-string)
668                                  value " ")
669                       line-breaking))
670       (setq attributes (delq 'script attributes))
671       )
672     (dolist (name '(=>ucs =>ucs*))
673       (when (and (memq name attributes)
674                  (setq value (get-char-attribute char name)))
675         (insert (format "(%-18s . #x%04X)\t; %c%s"
676                         name value (decode-char '=ucs value)
677                         line-breaking))
678         (setq attributes (delq name attributes))))
679     (dolist (name '(=>ucs@gb =>ucs@big5))
680       (when (and (memq name attributes)
681                  (setq value (get-char-attribute char name)))
682         (insert (format "(%-18s . #x%04X)\t; %c%s"
683                         name value
684                         (decode-char (intern
685                                       (concat "="
686                                               (substring
687                                                (symbol-name name) 2)))
688                                      value)
689                         line-breaking))
690         (setq attributes (delq name attributes))
691         ))
692     ;; (dolist (name '(=>daikanwa))
693     ;;   (when (and (memq name attributes)
694     ;;              (setq value (get-char-attribute char name)))
695     ;;     (insert
696     ;;      (if (integerp value)
697     ;;          (format "(%-18s . %05d)\t; %c%s"
698     ;;                  name value (decode-char '=daikanwa value)
699     ;;                  line-breaking)
700     ;;        (format "(%-18s %s)\t; %c%s"
701     ;;                name
702     ;;                (mapconcat (function prin1-to-string)
703     ;;                           value " ")
704     ;;                (char-representative-of-daikanwa char)
705     ;;                line-breaking)))
706     ;;     (setq attributes (delq name attributes))))
707     (when (and (memq 'general-category attributes)
708                (setq value (get-char-attribute char 'general-category)))
709       (insert (format
710                "(general-category\t%s) ; %s%s"
711                (mapconcat (lambda (cell)
712                             (format "%S" cell))
713                           value " ")
714                (cond ((rassoc value unidata-normative-category-alist)
715                       "Normative Category")
716                      ((rassoc value unidata-informative-category-alist)
717                       "Informative Category")
718                      (t
719                       "Unknown Category"))
720                line-breaking))
721       (setq attributes (delq 'general-category attributes))
722       )
723     (when (and (memq 'bidi-category attributes)
724                (setq value (get-char-attribute char 'bidi-category)))
725       (insert (format "(bidi-category\t. %S)%s"
726                       value
727                       line-breaking))
728       (setq attributes (delq 'bidi-category attributes))
729       )
730     (unless (or (not (memq 'mirrored attributes))
731                 (eq (setq value (get-char-attribute char 'mirrored 'empty))
732                     'empty))
733       (insert (format "(mirrored\t\t. %S)%s"
734                       value
735                       line-breaking))
736       (setq attributes (delq 'mirrored attributes))
737       )
738     (cond
739      ((and (memq 'decimal-digit-value attributes)
740            (setq value (get-char-attribute char 'decimal-digit-value)))
741       (insert (format "(decimal-digit-value . %S)%s"
742                       value
743                       line-breaking))
744       (setq attributes (delq 'decimal-digit-value attributes))
745       (when (and (memq 'digit-value attributes)
746                  (setq value (get-char-attribute char 'digit-value)))
747         (insert (format "(digit-value\t . %S)%s"
748                         value
749                         line-breaking))
750         (setq attributes (delq 'digit-value attributes))
751         )
752       (when (and (memq 'numeric-value attributes)
753                  (setq value (get-char-attribute char 'numeric-value)))
754         (insert (format "(numeric-value\t . %S)%s"
755                         value
756                         line-breaking))
757         (setq attributes (delq 'numeric-value attributes))
758         )
759       )
760      (t
761       (when (and (memq 'digit-value attributes)
762                  (setq value (get-char-attribute char 'digit-value)))
763         (insert (format "(digit-value\t. %S)%s"
764                         value
765                         line-breaking))
766         (setq attributes (delq 'digit-value attributes))
767         )
768       (when (and (memq 'numeric-value attributes)
769                  (setq value (get-char-attribute char 'numeric-value)))
770         (insert (format "(numeric-value\t. %S)%s"
771                         value
772                         line-breaking))
773         (setq attributes (delq 'numeric-value attributes))
774         )))
775     (when (and (memq 'iso-10646-comment attributes)
776                (setq value (get-char-attribute char 'iso-10646-comment)))
777       (insert (format "(iso-10646-comment\t. %S)%s"
778                       value
779                       line-breaking))
780       (setq attributes (delq 'iso-10646-comment attributes))
781       )
782     (when (and (memq 'morohashi-daikanwa attributes)
783                (setq value (get-char-attribute char 'morohashi-daikanwa)))
784       (insert (format "(morohashi-daikanwa\t%s)%s"
785                       (mapconcat (function prin1-to-string) value " ")
786                       line-breaking))
787       (setq attributes (delq 'morohashi-daikanwa attributes))
788       )
789     (setq radical nil
790           strokes nil)
791     (when (and (memq 'ideographic-radical attributes)
792                (setq value (get-char-attribute char 'ideographic-radical)))
793       (setq radical value)
794       (insert (format "(ideographic-radical . %S)\t; %c%s"
795                       radical
796                       (ideographic-radical radical)
797                       line-breaking))
798       (setq attributes (delq 'ideographic-radical attributes))
799       )
800     (when (and (memq 'shuowen-radical attributes)
801                (setq value (get-char-attribute char 'shuowen-radical)))
802       (insert (format "(shuowen-radical\t. %S)\t; %c%s"
803                       value
804                       (shuowen-radical value)
805                       line-breaking))
806       (setq attributes (delq 'shuowen-radical attributes))
807       )
808     (let (key)
809       (dolist (domain
810                (append
811                 char-db-feature-domains
812                 (let (dest domain)
813                   (dolist (feature (char-attribute-list))
814                     (setq feature (symbol-name feature))
815                     (when (string-match
816                            "\\(radical\\|strokes\\)@\\([^@*]+\\)\\(\\*\\|$\\)"
817                            feature)
818                       (setq domain (intern (match-string 2 feature)))
819                      (unless (memq domain dest)
820                        (setq dest (cons domain dest)))))
821                   (sort dest #'string<))))
822         (setq key (intern (format "%s@%s" 'ideographic-radical domain)))
823         (when (and (memq key attributes)
824                    (setq value (get-char-attribute char key)))
825           (setq radical value)
826           (insert (format "(%s . %S)\t; %c%s"
827                           key
828                           radical
829                           (ideographic-radical radical)
830                           line-breaking))
831           (setq attributes (delq key attributes))
832           )
833         (setq key (intern (format "%s@%s" 'ideographic-strokes domain)))
834         (when (and (memq key attributes)
835                    (setq value (get-char-attribute char key)))
836           (setq strokes value)
837           (insert (format "(%s . %S)%s"
838                           key
839                           strokes
840                           line-breaking))
841           (setq attributes (delq key attributes))
842           )
843         (setq key (intern (format "%s@%s" 'total-strokes domain)))
844         (when (and (memq key attributes)
845                    (setq value (get-char-attribute char key)))
846           (insert (format "(%s       . %S)%s"
847                           key
848                           value
849                           line-breaking))
850           (setq attributes (delq key attributes))
851           )
852         (dolist (feature '(ideographic-radical
853                            ideographic-strokes
854                            total-strokes))
855           (setq key (intern (format "%s@%s*sources" feature domain)))
856           (when (and (memq key attributes)
857                      (setq value (get-char-attribute char key)))
858             (insert (format "(%s%s" key line-breaking))
859             (dolist (cell value)
860               (insert (format " %s" cell)))
861             (insert ")")
862             (insert line-breaking)
863             (setq attributes (delq key attributes))
864             ))
865         ))
866     (when (and (memq 'ideographic-strokes attributes)
867                (setq value (get-char-attribute char 'ideographic-strokes)))
868       (setq strokes value)
869       (insert (format "(ideographic-strokes . %S)%s"
870                       strokes
871                       line-breaking))
872       (setq attributes (delq 'ideographic-strokes attributes))
873       )
874     (when (and (memq 'kangxi-radical attributes)
875                (setq value (get-char-attribute char 'kangxi-radical)))
876       (unless (eq value radical)
877         (insert (format "(kangxi-radical\t . %S)\t; %c%s"
878                         value
879                         (ideographic-radical value)
880                         line-breaking))
881         (or radical
882             (setq radical value)))
883       (setq attributes (delq 'kangxi-radical attributes))
884       )
885     (when (and (memq 'kangxi-strokes attributes)
886                (setq value (get-char-attribute char 'kangxi-strokes)))
887       (unless (eq value strokes)
888         (insert (format "(kangxi-strokes\t . %S)%s"
889                         value
890                         line-breaking))
891         (or strokes
892             (setq strokes value)))
893       (setq attributes (delq 'kangxi-strokes attributes))
894       )
895     (when (and (memq 'japanese-radical attributes)
896                (setq value (get-char-attribute char 'japanese-radical)))
897       (unless (eq value radical)
898         (insert (format "(japanese-radical\t . %S)\t; %c%s"
899                         value
900                         (ideographic-radical value)
901                         line-breaking))
902         (or radical
903             (setq radical value)))
904       (setq attributes (delq 'japanese-radical attributes))
905       )
906     (when (and (memq 'japanese-strokes attributes)
907                (setq value (get-char-attribute char 'japanese-strokes)))
908       (unless (eq value strokes)
909         (insert (format "(japanese-strokes\t . %S)%s"
910                         value
911                         line-breaking))
912         (or strokes
913             (setq strokes value)))
914       (setq attributes (delq 'japanese-strokes attributes))
915       )
916     (when (and (memq 'cns-radical attributes)
917                (setq value (get-char-attribute char 'cns-radical)))
918       (insert (format "(cns-radical\t . %S)\t; %c%s"
919                       value
920                       (ideographic-radical value)
921                       line-breaking))
922       (setq attributes (delq 'cns-radical attributes))
923       )
924     (when (and (memq 'cns-strokes attributes)
925                (setq value (get-char-attribute char 'cns-strokes)))
926       (unless (eq value strokes)
927         (insert (format "(cns-strokes\t . %S)%s"
928                         value
929                         line-breaking))
930         (or strokes
931             (setq strokes value)))
932       (setq attributes (delq 'cns-strokes attributes))
933       )
934     (when (and (memq 'shinjigen-1-radical attributes)
935                (setq value (get-char-attribute char 'shinjigen-1-radical)))
936       (unless (eq value radical)
937         (insert (format "(shinjigen-1-radical . %S)\t; %c%s"
938                         value
939                         (ideographic-radical value)
940                         line-breaking))
941         (or radical
942             (setq radical value)))
943       (setq attributes (delq 'shinjigen-1-radical attributes))
944       )
945     (when (and (memq 'ideographic- attributes)
946                (setq value (get-char-attribute char 'ideographic-)))
947       (insert "(ideographic-       ")
948       (setq lbs (concat "\n" (make-string (current-column) ?\ ))
949             separator nil)
950       (while (consp value)
951         (setq cell (car value))
952         (if (integerp cell)
953             (setq cell (decode-char '=ucs cell)))
954         (cond ((characterp cell)
955                (if separator
956                    (insert lbs))
957                (if readable
958                    (insert (format "%S" cell))
959                  (char-db-insert-char-spec cell readable))
960                (setq separator lbs))
961               ((consp cell)
962                (if separator
963                    (insert lbs))
964                (if (consp (car cell))
965                    (char-db-insert-char-spec cell readable)
966                  (char-db-insert-char-reference cell readable))
967                (setq separator lbs))
968               (t
969                (if separator
970                    (insert separator))
971                (insert (prin1-to-string cell))
972                (setq separator " ")))
973         (setq value (cdr value)))
974       (insert ")")
975       (insert line-breaking)
976       (setq attributes (delq 'ideographic- attributes)))
977     (when (and (memq 'total-strokes attributes)
978                (setq value (get-char-attribute char 'total-strokes)))
979       (insert (format "(total-strokes       . %S)%s"
980                       value
981                       line-breaking))
982       (setq attributes (delq 'total-strokes attributes))
983       )
984     (when (and (memq '->ideograph attributes)
985                (setq value (get-char-attribute char '->ideograph)))
986       (insert (format "(->ideograph\t%s)%s"
987                       (mapconcat (lambda (code)
988                                    (cond ((symbolp code)
989                                           (symbol-name code))
990                                          ((integerp code)
991                                           (format "#x%04X" code))
992                                          (t
993                                           (format "%s %S"
994                                                   line-breaking code))))
995                                  value " ")
996                       line-breaking))
997       (setq attributes (delq '->ideograph attributes))
998       )
999     ;; (when (and (memq '->decomposition attributes)
1000     ;;            (setq value (get-char-attribute char '->decomposition)))
1001     ;;   (insert (format "(->decomposition\t%s)%s"
1002     ;;                   (mapconcat (lambda (code)
1003     ;;                                (cond ((symbolp code)
1004     ;;                                       (symbol-name code))
1005     ;;                                      ((characterp code)
1006     ;;                                       (if readable
1007     ;;                                           (format "%S" code)
1008     ;;                                         (format "#x%04X"
1009     ;;                                                 (char-int code))
1010     ;;                                         ))
1011     ;;                                      ((integerp code)
1012     ;;                                       (format "#x%04X" code))
1013     ;;                                      (t
1014     ;;                                       (format "%s%S" line-breaking code))))
1015     ;;                              value " ")
1016     ;;                   line-breaking))
1017     ;;   (setq attributes (delq '->decomposition attributes))
1018     ;;   )
1019     (if (equal (get-char-attribute char '->titlecase)
1020                (get-char-attribute char '->uppercase))
1021         (setq attributes (delq '->titlecase attributes)))
1022     (when (and (memq '->mojikyo attributes)
1023                (setq value (get-char-attribute char '->mojikyo)))
1024       (insert (format "(->mojikyo\t\t. %06d)\t; %c%s"
1025                       value (decode-char 'mojikyo value)
1026                       line-breaking))
1027       (setq attributes (delq '->mojikyo attributes))
1028       )
1029     (when (and (memq 'hanyu-dazidian-vol attributes)
1030                (setq value (get-char-attribute char 'hanyu-dazidian-vol)))
1031       (insert (format "(hanyu-dazidian-vol  . %d)%s"
1032                       value line-breaking))
1033       (setq attributes (delq 'hanyu-dazidian-vol attributes))
1034       )
1035     (when (and (memq 'hanyu-dazidian-page attributes)
1036                (setq value (get-char-attribute char 'hanyu-dazidian-page)))
1037       (insert (format "(hanyu-dazidian-page . %d)%s"
1038                       value line-breaking))
1039       (setq attributes (delq 'hanyu-dazidian-page attributes))
1040       )
1041     (when (and (memq 'hanyu-dazidian-char attributes)
1042                (setq value (get-char-attribute char 'hanyu-dazidian-char)))
1043       (insert (format "(hanyu-dazidian-char . %d)%s"
1044                       value line-breaking))
1045       (setq attributes (delq 'hanyu-dazidian-char attributes))
1046       )
1047     (unless readable
1048       (dolist (ignored '(composition
1049                          ->denotational <-subsumptive ->ucs-unified
1050                          ->ideographic-component-forms))
1051         (setq attributes (delq ignored attributes))))
1052     (while attributes
1053       (setq name (car attributes))
1054       (if (setq value (get-char-attribute char name))
1055           (cond ((setq ret (find-charset name))
1056                  (setq name (charset-name ret))
1057                  (if (and (not (memq name dest-ccss))
1058                           (prog1
1059                               (setq value (get-char-attribute char name))
1060                             (setq dest-ccss (cons name dest-ccss))))
1061                      (char-db-insert-ccs-feature name value line-breaking))
1062                  )
1063                 ((string-match "^=>ucs@" (symbol-name name))
1064                  (insert (format "(%-18s . #x%04X)\t; %c%s"
1065                                  name value (decode-char '=ucs value)
1066                                  line-breaking))
1067                  )
1068                 ((eq name 'jisx0208-1978/4X)
1069                  (insert (format "(%-18s . #x%04X)%s"
1070                                  name value
1071                                  line-breaking))
1072                  )
1073                 ((and
1074                   (not readable)
1075                   (not (eq name '->subsumptive))
1076                   (not (eq name '->uppercase))
1077                   (not (eq name '->lowercase))
1078                   (not (eq name '->titlecase))
1079                   (not (eq name '->canonical))
1080                   (not (eq name '->Bopomofo))
1081                   (not (eq name '->mistakable))
1082                   (not (eq name '->ideographic-variants))
1083                   (null (get-char-attribute
1084                          char (intern (format "%s*sources" name))))
1085                   (not (string-match "\\*sources$" (symbol-name name)))
1086                   (null (get-char-attribute
1087                          char (intern (format "%s*note" name))))
1088                   (not (string-match "\\*note$" (symbol-name name)))
1089                   (or (eq name '<-identical)
1090                       (eq name '<-uppercase)
1091                       (eq name '<-lowercase)
1092                       (eq name '<-titlecase)
1093                       (eq name '<-canonical)
1094                       (eq name '<-ideographic-variants)
1095                       ;; (eq name '<-synonyms)
1096                       (string-match "^<-synonyms" (symbol-name name))
1097                       (eq name '<-mistakable)
1098                       (when (string-match "^->" (symbol-name name))
1099                         (cond
1100                          ((string-match "^->fullwidth" (symbol-name name))
1101                           (not (and (consp value)
1102                                     (characterp (car value))
1103                                     (encode-char
1104                                      (car value) '=ucs 'defined-only)))
1105                           )
1106                          (t)))
1107                       ))
1108                  )
1109                 ((or (eq name 'ideographic-structure)
1110                      (eq name 'ideographic-combination)
1111                      (eq name 'ideographic-)
1112                      (eq name '=decomposition)
1113                      (string-match "^=>*decomposition\\(@[^*]+\\)?$"
1114                                    (symbol-name name))
1115                      (string-match "^\\(->\\|<-\\)[^*]*$" (symbol-name name))
1116                      (string-match "^\\(->\\|<-\\)[^*]*\\*sources$"
1117                                    (symbol-name name))
1118                      )
1119                  (char-db-insert-relation-feature char name value
1120                                                   line-breaking
1121                                                   ccss readable))
1122                 ((memq name '(ideograph=
1123                               original-ideograph-of
1124                               ancient-ideograph-of
1125                               vulgar-ideograph-of
1126                               wrong-ideograph-of
1127                               ;; simplified-ideograph-of
1128                               ideographic-variants
1129                               ;; ideographic-different-form-of
1130                               ))
1131                  (insert (format "(%-18s%s " name line-breaking))
1132                  (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1133                        separator nil)
1134                  (while (consp value)
1135                    (setq cell (car value))
1136                    (if (and (consp cell)
1137                             (consp (car cell)))
1138                        (progn
1139                          (if separator
1140                              (insert lbs))
1141                          (char-db-insert-alist cell readable)
1142                          (setq separator lbs))
1143                      (if separator
1144                          (insert separator))
1145                      (insert (prin1-to-string cell))
1146                      (setq separator " "))
1147                    (setq value (cdr value)))
1148                  (insert ")")
1149                  (insert line-breaking))
1150                 ((consp value)
1151                  (insert (format "(%-18s " name))
1152                  (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1153                        separator nil)
1154                  (while (consp value)
1155                    (setq cell (car value))
1156                    (if (and (consp cell)
1157                             (consp (car cell))
1158                             (setq ret (condition-case nil
1159                                           (find-char cell)
1160                                         (error nil))))
1161                        (progn
1162                          (setq rest cell
1163                                al nil
1164                                cal nil)
1165                          (while rest
1166                            (setq key (car (car rest)))
1167                            (if (find-charset key)
1168                                (setq cal (cons key cal))
1169                              (setq al (cons key al)))
1170                            (setq rest (cdr rest)))
1171                          (if separator
1172                              (insert lbs))
1173                          (insert-char-attributes ret
1174                                                  readable
1175                                                  al cal)
1176                          (setq separator lbs))
1177                      (setq ret (prin1-to-string cell))
1178                      (if separator
1179                          (if (< (+ (current-column)
1180                                    (length ret)
1181                                    (length separator))
1182                                 76)
1183                              (insert separator)
1184                            (insert lbs)))
1185                      (insert ret)
1186                      (setq separator " "))
1187                    (setq value (cdr value)))
1188                  (insert ")")
1189                  (insert line-breaking))
1190                 (t
1191                  (insert (format "(%-18s" name))
1192                  (setq ret (prin1-to-string value))
1193                  (unless (< (+ (current-column)
1194                                (length ret)
1195                                3)
1196                             76)
1197                    (insert line-breaking))
1198                  (insert " . " ret ")" line-breaking)
1199                  ;; (insert (format "(%-18s . %S)%s"
1200                  ;;                 name value
1201                  ;;                 line-breaking))
1202                  )
1203                 ))
1204       (setq attributes (cdr attributes)))
1205     (insert ")")))
1206
1207 (defun insert-char-data (char &optional readable
1208                               attributes)
1209   (save-restriction
1210     (narrow-to-region (point)(point))
1211     (insert "(define-char
1212   '")
1213     (insert-char-attributes char readable attributes)
1214     (insert ")\n")
1215     (goto-char (point-min))
1216     (while (re-search-forward "[ \t]+$" nil t)
1217       (replace-match ""))
1218     ;; from tabify.
1219     (goto-char (point-min))
1220     (while (re-search-forward "[ \t][ \t][ \t]*" nil t)
1221       (let ((column (current-column))
1222             (indent-tabs-mode t))
1223         (delete-region (match-beginning 0) (point))
1224         (indent-to column)))
1225     (goto-char (point-max))
1226     ;; (tabify (point-min)(point-max))
1227     ))
1228
1229 (defun insert-char-data-with-variant (char &optional printable
1230                                            no-ucs-unified
1231                                            script excluded-script)
1232   (insert-char-data char printable)
1233   (let ((variants (char-variants char))
1234         rest
1235         variant vs ret)
1236     (setq variants (sort variants #'<))
1237     (setq rest variants)
1238     (setq variants (cons char variants))
1239     (while rest
1240       (setq variant (car rest))
1241       (unless (get-char-attribute variant '<-subsumptive)
1242         (if (and (or (null script)
1243                      (null (setq vs (get-char-attribute variant 'script)))
1244                      (memq script vs))
1245                  (or (null excluded-script)
1246                      (null (setq vs (get-char-attribute variant 'script)))
1247                      (not (memq excluded-script vs))))
1248             (unless (and no-ucs-unified (get-char-attribute variant '=ucs))
1249               (insert-char-data variant printable)
1250               (if (setq ret (char-variants variant))
1251                   (while ret
1252                     (or (memq (car ret) variants)
1253                         ;; (get-char-attribute (car ret) '<-subsumptive)
1254                         (setq rest (nconc rest (list (car ret)))))
1255                     (setq ret (cdr ret)))))))
1256       (setq rest (cdr rest)))))
1257
1258 (defun insert-char-range-data (min max &optional script excluded-script)
1259   (let ((code min)
1260         char)
1261     (while (<= code max)
1262       (setq char (decode-char '=ucs code))
1263       (if (encode-char char '=ucs 'defined-only)
1264           (insert-char-data-with-variant char nil 'no-ucs-unified
1265                                          script excluded-script))
1266       (setq code (1+ code)))))
1267
1268 (defun write-char-range-data-to-file (min max file
1269                                           &optional script excluded-script)
1270   (let ((coding-system-for-write char-db-file-coding-system))
1271     (with-temp-buffer
1272       (insert (format ";; -*- coding: %s -*-\n"
1273                       char-db-file-coding-system))
1274       (insert-char-range-data min max script excluded-script)
1275       (write-region (point-min)(point-max) file))))
1276
1277 (defvar what-character-original-window-configuration)
1278
1279 ;;;###autoload
1280 (defun what-char-definition (char)
1281   (interactive (list (char-after)))
1282   (let ((buf (get-buffer-create "*Character Description*"))
1283         (the-buf (current-buffer))
1284         (win-conf (current-window-configuration)))
1285     (pop-to-buffer buf)
1286     (make-local-variable 'what-character-original-window-configuration)
1287     (setq what-character-original-window-configuration win-conf)
1288     (setq buffer-read-only nil)
1289     (erase-buffer)
1290     (condition-case err
1291         (progn
1292           (insert-char-data-with-variant char 'printable)
1293           (unless (char-attribute-alist char)
1294             (insert (format ";; = %c\n"
1295                             (let* ((rest (split-char char))
1296                                    (ccs (pop rest))
1297                                    (code (pop rest)))
1298                               (while rest
1299                                 (setq code (logior (lsh code 8)
1300                                                    (pop rest))))
1301                               (decode-char ccs code)))))
1302           ;; (char-db-update-comment)
1303           (set-buffer-modified-p nil)
1304           (view-mode the-buf (lambda (buf)
1305                                (set-window-configuration
1306                                 what-character-original-window-configuration)
1307                                ))
1308           (goto-char (point-min)))
1309       (error (progn
1310                (set-window-configuration
1311                 what-character-original-window-configuration)
1312                (signal (car err) (cdr err)))))))
1313
1314
1315 ;;; @ end
1316 ;;;
1317
1318 (provide 'char-db-util)
1319
1320 ;;; char-db-util.el ends here