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