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