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