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