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