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