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