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