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