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