(char-db-insert-ccs-feature): Rename `shinjigen-1', `shinjigen-2' and
[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@1ed
473                         =shinjigen@rev =shinjigen/+p@rev))
474            "(%-18s .  %04d)\t; %c")
475           ((eq name '=shinjigen@1ed/24pr)
476            "(%-18s . %04d)\t; %c")
477           ((or (memq name '(=daikanwa
478                             =daikanwa@rev1 =daikanwa@rev2
479                             =gt =gt-k =cbeta =zinbun-oracle))
480                (string-match "^=adobe-" (symbol-name name)))
481            "(%-18s . %05d)\t; %c")
482           ((eq name 'mojikyo)
483            "(%-18s . %06d)\t; %c")
484           ((>= (charset-dimension name) 2)
485            "(%-18s . #x%04X)\t; %c")
486           (t
487            "(%-18s . #x%02X)\t; %c"))
488     name
489     (if (= (charset-iso-graphic-plane name) 1)
490         (logior value
491                 (cond ((= (charset-dimension name) 1)
492                        #x80)
493                       ((= (charset-dimension name) 2)
494                        #x8080)
495                       ((= (charset-dimension name) 3)
496                        #x808080)
497                       (t 0)))
498       value)
499     (char-db-decode-isolated-char name value)))
500   (if (and (= (charset-chars name) 94)
501            (= (charset-dimension name) 2))
502       (insert (format " [%02d-%02d]"
503                       (- (lsh value -8) 32)
504                       (- (logand value 255) 32))))
505   (insert line-breaking))
506
507 (defun char-db-insert-relation-feature (char name value line-breaking
508                                              ccss readable)
509   (insert (format "(%-18s%s " name line-breaking))
510   (let ((lbs (concat "\n" (make-string (current-column) ?\ )))
511         separator cell sources required-features
512         ret)
513     (while (consp value)
514       (setq cell (car value))
515       (if (integerp cell)
516           (setq cell (decode-char '=ucs cell)))
517       (cond
518        ((eq name '->subsumptive)
519         (when (or (not (some (lambda (atr)
520                                (get-char-attribute cell atr))
521                              char-db-ignored-attributes))
522                   (some (lambda (ccs)
523                           (encode-char cell ccs 'defined-only))
524                         ccss))
525           (if separator
526               (insert lbs))
527           (let ((char-db-ignored-attributes
528                  (cons '<-subsumptive
529                        char-db-ignored-attributes)))
530             (insert-char-attributes cell readable))
531           (setq separator lbs))
532         )
533        ((characterp cell)
534         (setq sources
535               (get-char-attribute
536                char (intern (format "%s*sources" name))))
537         (setq required-features nil)
538         (dolist (source sources)
539           (cond
540            ((memq source '(JP JP/Jouyou shinjigen@1ed shinjigen@rev))
541             (setq required-features
542                   (union required-features
543                          '(=jis-x0208
544                            =jis-x0208@1990
545                            =jis-x0213-1-2000
546                            =jis-x0213-2-2000
547                            =jis-x0212
548                            =jis-x0208@1983
549                            =jis-x0208@1978))))
550            ((eq source 'CN)
551             (setq required-features
552                   (union required-features
553                          '(=gb2312
554                            =gb12345
555                            =iso-ir165)))))
556           (cond
557            ((find-charset (setq ret (intern (format "=%s" source))))
558             (setq required-features
559                   (cons ret required-features)))
560            (t (setq required-features
561                     (cons source required-features)))))
562         (cond ((string-match "@JP" (symbol-name name))
563                (setq required-features
564                      (union required-features
565                             '(=jis-x0208
566                               =jis-x0208@1990
567                               =jis-x0213-1-2000
568                               =jis-x0213-2-2000
569                               =jis-x0212
570                               =jis-x0208@1983
571                               =jis-x0208@1978))))
572               ((string-match "@CN" (symbol-name name))
573                (setq required-features
574                      (union required-features
575                             '(=gb2312
576                               =gb12345
577                               =iso-ir165)))))
578         (if separator
579             (insert lbs))
580         (if readable
581             (insert (format "%S" cell))
582           (char-db-insert-char-spec cell readable
583                                     nil
584                                     required-features))
585         (setq separator lbs))
586        ((consp cell)
587         (if separator
588             (insert lbs))
589         (if (consp (car cell))
590             (char-db-insert-char-spec cell readable)
591           (char-db-insert-char-reference cell readable))
592         (setq separator lbs))
593        (t
594         (if separator
595             (insert separator))
596         (insert (prin1-to-string cell))
597         (setq separator " ")))
598       (setq value (cdr value)))
599     (insert ")")
600     (insert line-breaking)))
601
602 (defun insert-char-attributes (char &optional readable attributes column)
603   (unless column
604     (setq column (current-column)))
605   (let (name value ; has-long-ccs-name
606         rest
607         radical strokes
608         (line-breaking
609          (concat "\n" (make-string (1+ column) ?\ )))
610         lbs cell separator ret
611         key al cal
612         dest-ccss ; sources required-features
613         ccss)
614     (let (atr-d)
615       (setq attributes
616             (sort (if attributes
617                       (if (consp attributes)
618                           (progn
619                             (dolist (name attributes)
620                               (unless (memq name char-db-ignored-attributes)
621                                 (if (find-charset name)
622                                     (push name ccss))
623                                 (push name atr-d)))
624                             atr-d))
625                     (dolist (name (char-attribute-list))
626                       (unless (memq name char-db-ignored-attributes)
627                         (if (find-charset name)
628                             (push name ccss))
629                         (push name atr-d)))
630                     atr-d)
631                   #'char-attribute-name<)))
632     (insert "(")
633     (when (memq '<-subsumptive attributes)
634       (when readable
635         (when (setq value (get-char-attribute char '<-subsumptive))
636           (char-db-insert-relation-feature char '<-subsumptive value
637                                            line-breaking
638                                            ccss readable)))
639       (setq attributes (delq '<-subsumptive attributes)))
640     (when (and (memq '<-denotational attributes)
641                (setq value (get-char-attribute char '<-denotational)))
642       (char-db-insert-relation-feature char '<-denotational value
643                                        line-breaking
644                                        ccss readable)
645       (setq attributes (delq '<-denotational attributes)))
646     (when (and (memq 'name attributes)
647                (setq value (get-char-attribute char 'name)))
648       (insert (format
649                (if (> (+ (current-column) (length value)) 48)
650                    "(name . %S)%s"
651                  "(name               . %S)%s")
652                value line-breaking))
653       (setq attributes (delq 'name attributes))
654       )
655     (when (and (memq 'name* attributes)
656                (setq value (get-char-attribute char 'name*)))
657       (insert (format
658                (if (> (+ (current-column) (length value)) 48)
659                    "(name* . %S)%s"
660                  "(name*              . %S)%s")
661                value line-breaking))
662       (setq attributes (delq 'name* attributes))
663       )
664     (when (and (memq 'script attributes)
665                (setq value (get-char-attribute char 'script)))
666       (insert (format "(script\t\t%s)%s"
667                       (mapconcat (function prin1-to-string)
668                                  value " ")
669                       line-breaking))
670       (setq attributes (delq 'script attributes))
671       )
672     (dolist (name '(=>ucs =>ucs*))
673       (when (and (memq name attributes)
674                  (setq value (get-char-attribute char name)))
675         (insert (format "(%-18s . #x%04X)\t; %c%s"
676                         name value (decode-char '=ucs value)
677                         line-breaking))
678         (setq attributes (delq name attributes))))
679     (dolist (name '(=>ucs@gb =>ucs@cns =>ucs@jis =>ucs@ks =>ucs@big5))
680       (when (and (memq name attributes)
681                  (setq value (get-char-attribute char name)))
682         (insert (format "(%-18s . #x%04X)\t; %c%s"
683                         name value
684                         (decode-char (intern
685                                       (concat "="
686                                               (substring
687                                                (symbol-name name) 2)))
688                                      value)
689                         line-breaking))
690         (setq attributes (delq name attributes))
691         ))
692     (dolist (name '(=>daikanwa))
693       (when (and (memq name attributes)
694                  (setq value (get-char-attribute char name)))
695         (insert
696          (if (integerp value)
697              (format "(%-18s . %05d)\t; %c%s"
698                      name value (decode-char '=daikanwa value)
699                      line-breaking)
700            (format "(%-18s %s)\t; %c%s"
701                    name
702                    (mapconcat (function prin1-to-string)
703                               value " ")
704                    (char-representative-of-daikanwa char)
705                    line-breaking)))
706         (setq attributes (delq name attributes))))
707     (when (and (memq 'general-category attributes)
708                (setq value (get-char-attribute char 'general-category)))
709       (insert (format
710                "(general-category\t%s) ; %s%s"
711                (mapconcat (lambda (cell)
712                             (format "%S" cell))
713                           value " ")
714                (cond ((rassoc value unidata-normative-category-alist)
715                       "Normative Category")
716                      ((rassoc value unidata-informative-category-alist)
717                       "Informative Category")
718                      (t
719                       "Unknown Category"))
720                line-breaking))
721       (setq attributes (delq 'general-category attributes))
722       )
723     (when (and (memq 'bidi-category attributes)
724                (setq value (get-char-attribute char 'bidi-category)))
725       (insert (format "(bidi-category\t. %S)%s"
726                       value
727                       line-breaking))
728       (setq attributes (delq 'bidi-category attributes))
729       )
730     (unless (or (not (memq 'mirrored attributes))
731                 (eq (setq value (get-char-attribute char 'mirrored 'empty))
732                     'empty))
733       (insert (format "(mirrored\t\t. %S)%s"
734                       value
735                       line-breaking))
736       (setq attributes (delq 'mirrored attributes))
737       )
738     (cond
739      ((and (memq 'decimal-digit-value attributes)
740            (setq value (get-char-attribute char 'decimal-digit-value)))
741       (insert (format "(decimal-digit-value . %S)%s"
742                       value
743                       line-breaking))
744       (setq attributes (delq 'decimal-digit-value attributes))
745       (when (and (memq 'digit-value attributes)
746                  (setq value (get-char-attribute char 'digit-value)))
747         (insert (format "(digit-value\t . %S)%s"
748                         value
749                         line-breaking))
750         (setq attributes (delq 'digit-value attributes))
751         )
752       (when (and (memq 'numeric-value attributes)
753                  (setq value (get-char-attribute char 'numeric-value)))
754         (insert (format "(numeric-value\t . %S)%s"
755                         value
756                         line-breaking))
757         (setq attributes (delq 'numeric-value attributes))
758         )
759       )
760      (t
761       (when (and (memq 'digit-value attributes)
762                  (setq value (get-char-attribute char 'digit-value)))
763         (insert (format "(digit-value\t. %S)%s"
764                         value
765                         line-breaking))
766         (setq attributes (delq 'digit-value attributes))
767         )
768       (when (and (memq 'numeric-value attributes)
769                  (setq value (get-char-attribute char 'numeric-value)))
770         (insert (format "(numeric-value\t. %S)%s"
771                         value
772                         line-breaking))
773         (setq attributes (delq 'numeric-value attributes))
774         )))
775     (when (and (memq 'iso-10646-comment attributes)
776                (setq value (get-char-attribute char 'iso-10646-comment)))
777       (insert (format "(iso-10646-comment\t. %S)%s"
778                       value
779                       line-breaking))
780       (setq attributes (delq 'iso-10646-comment attributes))
781       )
782     (when (and (memq 'morohashi-daikanwa attributes)
783                (setq value (get-char-attribute char 'morohashi-daikanwa)))
784       (insert (format "(morohashi-daikanwa\t%s)%s"
785                       (mapconcat (function prin1-to-string) value " ")
786                       line-breaking))
787       (setq attributes (delq 'morohashi-daikanwa attributes))
788       )
789     (setq radical nil
790           strokes nil)
791     (when (and (memq 'ideographic-radical attributes)
792                (setq value (get-char-attribute char 'ideographic-radical)))
793       (setq radical value)
794       (insert (format "(ideographic-radical . %S)\t; %c%s"
795                       radical
796                       (ideographic-radical radical)
797                       line-breaking))
798       (setq attributes (delq 'ideographic-radical attributes))
799       )
800     (when (and (memq 'shuowen-radical attributes)
801                (setq value (get-char-attribute char 'shuowen-radical)))
802       (insert (format "(shuowen-radical\t. %S)\t; %c%s"
803                       value
804                       (shuowen-radical value)
805                       line-breaking))
806       (setq attributes (delq 'shuowen-radical attributes))
807       )
808     (let (key)
809       (dolist (domain
810                (append
811                 char-db-feature-domains
812                 (let (dest domain)
813                   (dolist (feature (char-attribute-list))
814                     (setq feature (symbol-name feature))
815                     (when (string-match
816                            "\\(radical\\|strokes\\)@\\([^@*]+\\)\\(\\*\\|$\\)"
817                            feature)
818                       (setq domain (intern (match-string 2 feature)))
819                      (unless (memq domain dest)
820                        (setq dest (cons domain dest)))))
821                   (sort dest #'string<))))
822         (setq key (intern (format "%s@%s" 'ideographic-radical domain)))
823         (when (and (memq key attributes)
824                    (setq value (get-char-attribute char key)))
825           (setq radical value)
826           (insert (format "(%s . %S)\t; %c%s"
827                           key
828                           radical
829                           (ideographic-radical radical)
830                           line-breaking))
831           (setq attributes (delq key attributes))
832           )
833         (setq key (intern (format "%s@%s" 'ideographic-strokes domain)))
834         (when (and (memq key attributes)
835                    (setq value (get-char-attribute char key)))
836           (setq strokes value)
837           (insert (format "(%s . %S)%s"
838                           key
839                           strokes
840                           line-breaking))
841           (setq attributes (delq key attributes))
842           )
843         (setq key (intern (format "%s@%s" 'total-strokes domain)))
844         (when (and (memq key attributes)
845                    (setq value (get-char-attribute char key)))
846           (insert (format "(%s       . %S)%s"
847                           key
848                           value
849                           line-breaking))
850           (setq attributes (delq key attributes))
851           )
852         (dolist (feature '(ideographic-radical
853                            ideographic-strokes
854                            total-strokes))
855           (setq key (intern (format "%s@%s*sources" feature domain)))
856           (when (and (memq key attributes)
857                      (setq value (get-char-attribute char key)))
858             (insert (format "(%s%s" key line-breaking))
859             (dolist (cell value)
860               (insert (format " %s" cell)))
861             (insert ")")
862             (insert line-breaking)
863             (setq attributes (delq key attributes))
864             ))
865         ))
866     (when (and (memq 'ideographic-strokes attributes)
867                (setq value (get-char-attribute char 'ideographic-strokes)))
868       (setq strokes value)
869       (insert (format "(ideographic-strokes . %S)%s"
870                       strokes
871                       line-breaking))
872       (setq attributes (delq 'ideographic-strokes attributes))
873       )
874     (when (and (memq 'kangxi-radical attributes)
875                (setq value (get-char-attribute char 'kangxi-radical)))
876       (unless (eq value radical)
877         (insert (format "(kangxi-radical\t . %S)\t; %c%s"
878                         value
879                         (ideographic-radical value)
880                         line-breaking))
881         (or radical
882             (setq radical value)))
883       (setq attributes (delq 'kangxi-radical attributes))
884       )
885     (when (and (memq 'kangxi-strokes attributes)
886                (setq value (get-char-attribute char 'kangxi-strokes)))
887       (unless (eq value strokes)
888         (insert (format "(kangxi-strokes\t . %S)%s"
889                         value
890                         line-breaking))
891         (or strokes
892             (setq strokes value)))
893       (setq attributes (delq 'kangxi-strokes attributes))
894       )
895     (when (and (memq 'japanese-radical attributes)
896                (setq value (get-char-attribute char 'japanese-radical)))
897       (unless (eq value radical)
898         (insert (format "(japanese-radical\t . %S)\t; %c%s"
899                         value
900                         (ideographic-radical value)
901                         line-breaking))
902         (or radical
903             (setq radical value)))
904       (setq attributes (delq 'japanese-radical attributes))
905       )
906     (when (and (memq 'japanese-strokes attributes)
907                (setq value (get-char-attribute char 'japanese-strokes)))
908       (unless (eq value strokes)
909         (insert (format "(japanese-strokes\t . %S)%s"
910                         value
911                         line-breaking))
912         (or strokes
913             (setq strokes value)))
914       (setq attributes (delq 'japanese-strokes attributes))
915       )
916     (when (and (memq 'cns-radical attributes)
917                (setq value (get-char-attribute char 'cns-radical)))
918       (insert (format "(cns-radical\t . %S)\t; %c%s"
919                       value
920                       (ideographic-radical value)
921                       line-breaking))
922       (setq attributes (delq 'cns-radical attributes))
923       )
924     (when (and (memq 'cns-strokes attributes)
925                (setq value (get-char-attribute char 'cns-strokes)))
926       (unless (eq value strokes)
927         (insert (format "(cns-strokes\t . %S)%s"
928                         value
929                         line-breaking))
930         (or strokes
931             (setq strokes value)))
932       (setq attributes (delq 'cns-strokes attributes))
933       )
934     (when (and (memq 'shinjigen-1-radical attributes)
935                (setq value (get-char-attribute char 'shinjigen-1-radical)))
936       (unless (eq value radical)
937         (insert (format "(shinjigen-1-radical . %S)\t; %c%s"
938                         value
939                         (ideographic-radical value)
940                         line-breaking))
941         (or radical
942             (setq radical value)))
943       (setq attributes (delq 'shinjigen-1-radical attributes))
944       )
945     (when (and (memq 'ideographic- attributes)
946                (setq value (get-char-attribute char 'ideographic-)))
947       (insert "(ideographic-       ")
948       (setq lbs (concat "\n" (make-string (current-column) ?\ ))
949             separator nil)
950       (while (consp value)
951         (setq cell (car value))
952         (if (integerp cell)
953             (setq cell (decode-char '=ucs cell)))
954         (cond ((characterp cell)
955                (if separator
956                    (insert lbs))
957                (if readable
958                    (insert (format "%S" cell))
959                  (char-db-insert-char-spec cell readable))
960                (setq separator lbs))
961               ((consp cell)
962                (if separator
963                    (insert lbs))
964                (if (consp (car cell))
965                    (char-db-insert-char-spec cell readable)
966                  (char-db-insert-char-reference cell readable))
967                (setq separator lbs))
968               (t
969                (if separator
970                    (insert separator))
971                (insert (prin1-to-string cell))
972                (setq separator " ")))
973         (setq value (cdr value)))
974       (insert ")")
975       (insert line-breaking)
976       (setq attributes (delq 'ideographic- attributes)))
977     (when (and (memq 'total-strokes attributes)
978                (setq value (get-char-attribute char 'total-strokes)))
979       (insert (format "(total-strokes       . %S)%s"
980                       value
981                       line-breaking))
982       (setq attributes (delq 'total-strokes attributes))
983       )
984     (when (and (memq '->ideograph attributes)
985                (setq value (get-char-attribute char '->ideograph)))
986       (insert (format "(->ideograph\t%s)%s"
987                       (mapconcat (lambda (code)
988                                    (cond ((symbolp code)
989                                           (symbol-name code))
990                                          ((integerp code)
991                                           (format "#x%04X" code))
992                                          (t
993                                           (format "%s %S"
994                                                   line-breaking code))))
995                                  value " ")
996                       line-breaking))
997       (setq attributes (delq '->ideograph attributes))
998       )
999     ;; (when (and (memq '->decomposition attributes)
1000     ;;            (setq value (get-char-attribute char '->decomposition)))
1001     ;;   (insert (format "(->decomposition\t%s)%s"
1002     ;;                   (mapconcat (lambda (code)
1003     ;;                                (cond ((symbolp code)
1004     ;;                                       (symbol-name code))
1005     ;;                                      ((characterp code)
1006     ;;                                       (if readable
1007     ;;                                           (format "%S" code)
1008     ;;                                         (format "#x%04X"
1009     ;;                                                 (char-int code))
1010     ;;                                         ))
1011     ;;                                      ((integerp code)
1012     ;;                                       (format "#x%04X" code))
1013     ;;                                      (t
1014     ;;                                       (format "%s%S" line-breaking code))))
1015     ;;                              value " ")
1016     ;;                   line-breaking))
1017     ;;   (setq attributes (delq '->decomposition attributes))
1018     ;;   )
1019     (if (equal (get-char-attribute char '->titlecase)
1020                (get-char-attribute char '->uppercase))
1021         (setq attributes (delq '->titlecase attributes)))
1022     (when (and (memq '->mojikyo attributes)
1023                (setq value (get-char-attribute char '->mojikyo)))
1024       (insert (format "(->mojikyo\t\t. %06d)\t; %c%s"
1025                       value (decode-char 'mojikyo value)
1026                       line-breaking))
1027       (setq attributes (delq '->mojikyo attributes))
1028       )
1029     (when (and (memq 'hanyu-dazidian-vol attributes)
1030                (setq value (get-char-attribute char 'hanyu-dazidian-vol)))
1031       (insert (format "(hanyu-dazidian-vol  . %d)%s"
1032                       value line-breaking))
1033       (setq attributes (delq 'hanyu-dazidian-vol attributes))
1034       )
1035     (when (and (memq 'hanyu-dazidian-page attributes)
1036                (setq value (get-char-attribute char 'hanyu-dazidian-page)))
1037       (insert (format "(hanyu-dazidian-page . %d)%s"
1038                       value line-breaking))
1039       (setq attributes (delq 'hanyu-dazidian-page attributes))
1040       )
1041     (when (and (memq 'hanyu-dazidian-char attributes)
1042                (setq value (get-char-attribute char 'hanyu-dazidian-char)))
1043       (insert (format "(hanyu-dazidian-char . %d)%s"
1044                       value line-breaking))
1045       (setq attributes (delq 'hanyu-dazidian-char attributes))
1046       )
1047     (unless readable
1048       (dolist (ignored '(composition
1049                          ->denotational <-subsumptive ->ucs-unified
1050                          ->ideographic-component-forms))
1051         (setq attributes (delq ignored attributes))))
1052     (while attributes
1053       (setq name (car attributes))
1054       (if (setq value (get-char-attribute char name))
1055           (cond ((setq ret (find-charset name))
1056                  (setq name (charset-name ret))
1057                  (if (and (not (memq name dest-ccss))
1058                           (prog1
1059                               (setq value (get-char-attribute char name))
1060                             (setq dest-ccss (cons name dest-ccss))))
1061                      (char-db-insert-ccs-feature name value line-breaking))
1062                  )
1063                 ((string-match "^=>ucs@" (symbol-name name))
1064                  (insert (format "(%-18s . #x%04X)\t; %c%s"
1065                                  name value (decode-char '=ucs value)
1066                                  line-breaking))
1067                  )
1068                 ((eq name 'jisx0208-1978/4X)
1069                  (insert (format "(%-18s . #x%04X)%s"
1070                                  name value
1071                                  line-breaking))
1072                  )
1073                 ((and
1074                   (not readable)
1075                   (not (eq name '->subsumptive))
1076                   (not (eq name '->uppercase))
1077                   (not (eq name '->lowercase))
1078                   (not (eq name '->titlecase))
1079                   (not (eq name '->canonical))
1080                   (not (eq name '->Bopomofo))
1081                   (not (eq name '->mistakable))
1082                   (not (eq name '->ideographic-variants))
1083                   (null (get-char-attribute
1084                          char (intern (format "%s*sources" name))))
1085                   (not (string-match "\\*sources$" (symbol-name name)))
1086                   (null (get-char-attribute
1087                          char (intern (format "%s*note" name))))
1088                   (not (string-match "\\*note$" (symbol-name name)))
1089                   (or (eq name '<-identical)
1090                       (eq name '<-uppercase)
1091                       (eq name '<-lowercase)
1092                       (eq name '<-titlecase)
1093                       (eq name '<-canonical)
1094                       (eq name '<-ideographic-variants)
1095                       ;; (eq name '<-synonyms)
1096                       (string-match "^<-synonyms" (symbol-name name))
1097                       (eq name '<-mistakable)
1098                       (when (string-match "^->" (symbol-name name))
1099                         (cond
1100                          ((string-match "^->fullwidth" (symbol-name name))
1101                           (not (and (consp value)
1102                                     (characterp (car value))
1103                                     (encode-char
1104                                      (car value) '=ucs 'defined-only)))
1105                           )
1106                          (t)))
1107                       ))
1108                  )
1109                 ((or (eq name 'ideographic-structure)
1110                      (eq name 'ideographic-combination)
1111                      (eq name 'ideographic-)
1112                      (eq name '=decomposition)
1113                      (string-match "^=>decomposition" (symbol-name name))
1114                      (string-match "^\\(->\\|<-\\)[^*]*$" (symbol-name name))
1115                      (string-match "^\\(->\\|<-\\)[^*]*\\*sources$"
1116                                    (symbol-name name))
1117                      )
1118                  (char-db-insert-relation-feature char name value
1119                                                   line-breaking
1120                                                   ccss readable))
1121                 ((memq name '(ideograph=
1122                               original-ideograph-of
1123                               ancient-ideograph-of
1124                               vulgar-ideograph-of
1125                               wrong-ideograph-of
1126                               ;; simplified-ideograph-of
1127                               ideographic-variants
1128                               ;; ideographic-different-form-of
1129                               ))
1130                  (insert (format "(%-18s%s " name line-breaking))
1131                  (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1132                        separator nil)
1133                  (while (consp value)
1134                    (setq cell (car value))
1135                    (if (and (consp cell)
1136                             (consp (car cell)))
1137                        (progn
1138                          (if separator
1139                              (insert lbs))
1140                          (char-db-insert-alist cell readable)
1141                          (setq separator lbs))
1142                      (if separator
1143                          (insert separator))
1144                      (insert (prin1-to-string cell))
1145                      (setq separator " "))
1146                    (setq value (cdr value)))
1147                  (insert ")")
1148                  (insert line-breaking))
1149                 ((consp value)
1150                  (insert (format "(%-18s " name))
1151                  (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1152                        separator nil)
1153                  (while (consp value)
1154                    (setq cell (car value))
1155                    (if (and (consp cell)
1156                             (consp (car cell))
1157                             (setq ret (condition-case nil
1158                                           (find-char cell)
1159                                         (error nil))))
1160                        (progn
1161                          (setq rest cell
1162                                al nil
1163                                cal nil)
1164                          (while rest
1165                            (setq key (car (car rest)))
1166                            (if (find-charset key)
1167                                (setq cal (cons key cal))
1168                              (setq al (cons key al)))
1169                            (setq rest (cdr rest)))
1170                          (if separator
1171                              (insert lbs))
1172                          (insert-char-attributes ret
1173                                                  readable
1174                                                  al cal)
1175                          (setq separator lbs))
1176                      (setq ret (prin1-to-string cell))
1177                      (if separator
1178                          (if (< (+ (current-column)
1179                                    (length ret)
1180                                    (length separator))
1181                                 76)
1182                              (insert separator)
1183                            (insert lbs)))
1184                      (insert ret)
1185                      (setq separator " "))
1186                    (setq value (cdr value)))
1187                  (insert ")")
1188                  (insert line-breaking))
1189                 (t
1190                  (insert (format "(%-18s" name))
1191                  (setq ret (prin1-to-string value))
1192                  (unless (< (+ (current-column)
1193                                (length ret)
1194                                3)
1195                             76)
1196                    (insert line-breaking))
1197                  (insert " . " ret ")" line-breaking)
1198                  ;; (insert (format "(%-18s . %S)%s"
1199                  ;;                 name value
1200                  ;;                 line-breaking))
1201                  )
1202                 ))
1203       (setq attributes (cdr attributes)))
1204     (insert ")")))
1205
1206 (defun insert-char-data (char &optional readable
1207                               attributes)
1208   (save-restriction
1209     (narrow-to-region (point)(point))
1210     (insert "(define-char
1211   '")
1212     (insert-char-attributes char readable attributes)
1213     (insert ")\n")
1214     (goto-char (point-min))
1215     (while (re-search-forward "[ \t]+$" nil t)
1216       (replace-match ""))
1217     ;; from tabify.
1218     (goto-char (point-min))
1219     (while (re-search-forward "[ \t][ \t][ \t]*" nil t)
1220       (let ((column (current-column))
1221             (indent-tabs-mode t))
1222         (delete-region (match-beginning 0) (point))
1223         (indent-to column)))
1224     (goto-char (point-max))
1225     ;; (tabify (point-min)(point-max))
1226     ))
1227
1228 (defun insert-char-data-with-variant (char &optional printable
1229                                            no-ucs-unified
1230                                            script excluded-script)
1231   (insert-char-data char printable)
1232   (let ((variants (char-variants char))
1233         rest
1234         variant vs ret)
1235     (setq variants (sort variants #'<))
1236     (setq rest variants)
1237     (setq variants (cons char variants))
1238     (while rest
1239       (setq variant (car rest))
1240       (unless (get-char-attribute variant '<-subsumptive)
1241         (if (and (or (null script)
1242                      (null (setq vs (get-char-attribute variant 'script)))
1243                      (memq script vs))
1244                  (or (null excluded-script)
1245                      (null (setq vs (get-char-attribute variant 'script)))
1246                      (not (memq excluded-script vs))))
1247             (unless (and no-ucs-unified (get-char-attribute variant '=ucs))
1248               (insert-char-data variant printable)
1249               (if (setq ret (char-variants variant))
1250                   (while ret
1251                     (or (memq (car ret) variants)
1252                         ;; (get-char-attribute (car ret) '<-subsumptive)
1253                         (setq rest (nconc rest (list (car ret)))))
1254                     (setq ret (cdr ret)))))))
1255       (setq rest (cdr rest)))))
1256
1257 (defun insert-char-range-data (min max &optional script excluded-script)
1258   (let ((code min)
1259         char)
1260     (while (<= code max)
1261       (setq char (decode-char '=ucs code))
1262       (if (encode-char char '=ucs 'defined-only)
1263           (insert-char-data-with-variant char nil 'no-ucs-unified
1264                                          script excluded-script))
1265       (setq code (1+ code)))))
1266
1267 (defun write-char-range-data-to-file (min max file
1268                                           &optional script excluded-script)
1269   (let ((coding-system-for-write char-db-file-coding-system))
1270     (with-temp-buffer
1271       (insert (format ";; -*- coding: %s -*-\n"
1272                       char-db-file-coding-system))
1273       (insert-char-range-data min max script excluded-script)
1274       (write-region (point-min)(point-max) file))))
1275
1276 (defvar what-character-original-window-configuration)
1277
1278 ;;;###autoload
1279 (defun what-char-definition (char)
1280   (interactive (list (char-after)))
1281   (let ((buf (get-buffer-create "*Character Description*"))
1282         (the-buf (current-buffer))
1283         (win-conf (current-window-configuration)))
1284     (pop-to-buffer buf)
1285     (make-local-variable 'what-character-original-window-configuration)
1286     (setq what-character-original-window-configuration win-conf)
1287     (setq buffer-read-only nil)
1288     (erase-buffer)
1289     (condition-case err
1290         (progn
1291           (insert-char-data-with-variant char 'printable)
1292           (unless (char-attribute-alist char)
1293             (insert (format ";; = %c\n"
1294                             (let* ((rest (split-char char))
1295                                    (ccs (pop rest))
1296                                    (code (pop rest)))
1297                               (while rest
1298                                 (setq code (logior (lsh code 8)
1299                                                    (pop rest))))
1300                               (decode-char ccs code)))))
1301           ;; (char-db-update-comment)
1302           (set-buffer-modified-p nil)
1303           (view-mode the-buf (lambda (buf)
1304                                (set-window-configuration
1305                                 what-character-original-window-configuration)
1306                                ))
1307           (goto-char (point-min)))
1308       (error (progn
1309                (set-window-configuration
1310                 what-character-original-window-configuration)
1311                (signal (car err) (cdr err)))))))
1312
1313 (provide 'char-db-util)
1314
1315 ;;; char-db-util.el ends here