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