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