(char-db-insert-ccs-feature): Add settings for
[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, 2010, 2011 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 'chise-subr)
29 (require 'ideograph-subr)
30
31 (defconst unidata-normative-category-alist
32   '(("Lu" letter        uppercase)
33     ("Ll" letter        lowercase)
34     ("Lt" letter        titlecase)
35     ("Mn" mark          non-spacing)
36     ("Mc" mark          spacing-combining)
37     ("Me" mark          enclosing)
38     ("Nd" number        decimal-digit)
39     ("Nl" number        letter)
40     ("No" number        other)
41     ("Zs" separator     space)
42     ("Zl" separator     line)
43     ("Zp" separator     paragraph)
44     ("Cc" other         control)
45     ("Cf" other         format)
46     ("Cs" other         surrogate)
47     ("Co" other         private-use)
48     ("Cn" other         not-assigned)))
49
50 (defconst unidata-informative-category-alist
51   '(("Lm" letter        modifier)
52     ("Lo" letter        other)
53     ("Pc" punctuation   connector)
54     ("Pd" punctuation   dash)
55     ("Ps" punctuation   open)
56     ("Pe" punctuation   close)
57     ("Pi" punctuation   initial-quote)
58     ("Pf" punctuation   final-quote)
59     ("Po" punctuation   other)
60     ("Sm" symbol        math)
61     ("Sc" symbol        currency)
62     ("Sk" symbol        modifier)
63     ("So" symbol        other)
64     ))
65
66 (defconst shuowen-radicals
67   [?一 ?上 ?示 ?三 ?王 ?玉 ?玨 ?气 ?士 ?丨 ; 010
68    ?屮 ?艸 ?蓐 ?茻 ?小 ?八 ?釆 ?半 ?牛 ?犛 ; 020
69    ?告 ?口 ?凵 ?吅 ?哭 ?走 ?止 ?癶 ?步 ?此 ; 030
70    ?正 ?是 ?辵 ?彳 ?廴 ?㢟 ?行 ?齒 ?牙 ?足 ; 040
71    ?疋 ?品 ?龠 ?冊 ?㗊 ?舌 ?干 ?谷 ?只 ?㕯 ; 050
72    ?句 ?丩 ?古 ?十 ?卅 ?言 ?誩 ?音 ?䇂 ?丵 ; 060
73    ?菐 ?𠬞 ?𠬜 ?共 ?異 ?舁 ?𦥑 ?䢅 ?爨 ?革 ; 070
74    ?鬲 ?䰜 ?爪 ?𠃨 ?鬥 ?又 ?𠂇 ?㕜 ?支 ?𦘒 ; 080
75    ?聿 ?畫 ?隶 ?臤 ?臣 ?殳 ?殺 ?𠘧 ?寸 ?皮 ; 090
76    ?㼱 ?攴 ?敎 ?卜 ?用 ?爻 ?㸚 ?𥄎 ?目 ?䀠 ; 100
77    ?眉 ?盾 ?自 ?白 ?鼻 ?皕 ?習 ?羽 ?隹 ?奞 ; 110
78    ?萑 ?𦫳 ?苜 ?羊 ?羴 ?瞿 ?雔 ?雥 ?鳥 ?烏 ; 120
79    ?𠦒 ?冓 ?幺 ?𢆶 ?叀 ?玄 ?予 ?放 ?𠬪 ?𣦼 ; 130
80    ?歺 ?死 ?冎 ?骨 ?肉 ?筋 ?刀 ?刃 ?㓞 ?丰 ; 140
81    ?耒 ?𧢲 ?竹 ?箕 ?丌 ?左 ?工 ?㠭 ?巫 ?甘 ; 150
82    ?旨 ?曰 ?乃 ?丂 ?可 ?兮 ?号 ?亏 ?喜 ?壴 ; 160
83    ?鼓 ?豈 ?豆 ?豊 ?豐 ?䖒 ?虍 ?虎 ?虤 ?皿 ; 170
84    ?𠙴 ?去 ?血 ?丶 ?丹 ?青 ?井 ?皀 ?鬯 ?食 ; 180
85    ?亼 ?會 ?倉 ?入 ?缶 ?矢 ?高 ?冂 ?𩫏 ?京 ; 190
86    ?亯 ?𣆪 ?畗 ?㐭 ?嗇 ?來 ?麥 ?夊 ?舛 ?䑞 ; 200
87    ?韋 ?弟 ?夂 ?久 ?桀 ?木 ?東 ?林 ?才 ?叒 ; 210
88    ?之 ?帀 ?出 ?𣎵 ?生 ?乇 ?𠂹 ?𠌶 ?華 ?𥝌 ; 220
89    ?稽 ?巢 ?桼 ?束 ?㯻 ?囗 ?員 ?貝 ?邑 ?𨛜 ; 230
90    ?日 ?旦 ?倝 ?㫃 ?冥 ?晶 ?月 ?有 ?明 ?囧 ; 240
91    ?夕 ?多 ?毌 ?𢎘 ?𣐺 ?卣 ?齊 ?朿 ?片 ?鼎 ; 250
92    ?克 ?彔 ?禾 ?秝 ?黍 ?香 ?米 ?毇 ?臼 ?凶 ; 260
93    ?𣎳 ?林 ?麻 ?尗 ?耑 ?韭 ?瓜 ?瓠 ?宀 ?宮 ; 270
94    ?呂 ?穴 ?㝱 ?𤕫 ?冖 ?𠔼 ?冃 ?㒳 ?网 ?襾 ; 280
95    ?巾 ?巿 ?帛 ?白 ?㡀 ?黹 ?人 ?𠤎 ?匕 ?从 ; 290
96    ])
97
98 (defun shuowen-radical (number)
99   (aref shuowen-radicals (1- number)))
100
101 (defvar char-db-file-coding-system 'utf-8-mcs-er)
102
103 (defvar char-db-ignored-attributes '(ideographic-products))
104
105 (defvar char-db-coded-charset-priority-list
106   '(ascii
107     control-1
108     latin-iso8859-1
109     latin-iso8859-2
110     latin-iso8859-3
111     latin-iso8859-4
112     latin-iso8859-9
113     latin-jisx0201
114     cyrillic-iso8859-5
115     greek-iso8859-7
116     thai-tis620
117     =jis-x0208
118     =jis-x0208@1978
119     =jis-x0208@1983
120     japanese-jisx0212
121     chinese-gb2312
122     =jis-x0208@1990
123     chinese-cns11643-1
124     chinese-cns11643-2
125     chinese-cns11643-3
126     chinese-cns11643-4
127     chinese-cns11643-5
128     chinese-cns11643-6
129     chinese-cns11643-7
130     =jis-x0213-1
131     =jis-x0213-1@2000
132     =jis-x0213-1@2004
133     =jis-x0213-2
134     korean-ksc5601
135     chinese-isoir165
136     katakana-jisx0201
137     hebrew-iso8859-8
138     chinese-gb12345
139     latin-viscii
140     ethiopic-ucs
141     =big5-cdp
142     =gt
143     =adobe-japan1-0
144     =adobe-japan1-1
145     =adobe-japan1-2
146     =adobe-japan1-3
147     =adobe-japan1-4
148     =adobe-japan1-5
149     =adobe-japan1-6
150     =hanyo-denshi/ja
151     =hanyo-denshi/jb
152     =hanyo-denshi/jc
153     =hanyo-denshi/jd
154     =hanyo-denshi/ft
155     =hanyo-denshi/ia
156     =hanyo-denshi/ib
157     =hanyo-denshi/hg
158     =hanyo-denshi/jt
159     =hanyo-denshi/ks
160     =daikanwa
161     =daikanwa@rev2
162     =daikanwa@rev1
163     =cbeta
164     =gt-k
165     ideograph-hanziku-1
166     ideograph-hanziku-2
167     ideograph-hanziku-3
168     ideograph-hanziku-4
169     ideograph-hanziku-5
170     ideograph-hanziku-6
171     ideograph-hanziku-7
172     ideograph-hanziku-8
173     ideograph-hanziku-9
174     ideograph-hanziku-10
175     ideograph-hanziku-11
176     ideograph-hanziku-12
177     =>>>jis-x0208
178     =>>>jis-x0213-1
179     =>>>jis-x0213-2
180     =>>>gt
181     =>>>adobe-japan1
182     =>>jis-x0208
183     =>>jis-x0213-1
184     =>>jis-x0213-1@2000
185     =>>jis-x0213-1@2004
186     =>>jis-x0213-2
187     =>>jis-x0208@1978
188     =>>hanyo-denshi/ft
189     =>>hanyo-denshi/ks
190     =>>gt
191     =>>daikanwa
192     =>>adobe-japan1
193     =+>jis-x0208
194     =+>jis-x0213-1
195     =+>jis-x0213-2
196     =+>jis-x0208@1978
197     =+>adobe-japan1
198     =>jis-x0208
199     =>jis-x0208@1997
200     =>jis-x0213-1
201     =>jis-x0213-1@2000
202     =>jis-x0213-1@2004
203     =>jis-x0213-2
204     ==>ucs@bucs
205     =>ucs@iso
206     =>ucs@unicode
207     =>ucs@jis
208     =>ucs@cns
209     =>ucs@ks
210     =+>ucs@unicode
211     =+>ucs@jis
212     =+>ucs@jis/1990
213     =+>ucs@cns
214     =+>ucs@ks
215     =>>ucs@iso
216     =>>ucs@unicode
217     =>>ucs@jis
218     =>>ucs@cns
219     =>>>ucs@iso
220     =>>>ucs@unicode
221     =ucs@iso
222     =ucs@unicode
223     =>>big5-cdp
224     =>>gt-k
225     =+>gt
226     =>gt
227     =>big5-cdp
228     =>daikanwa
229     =>cns11643-7
230     =big5
231     =big5-eten
232     =>gt-k
233     =zinbun-oracle
234     =>zinbun-oracle
235     =ruimoku-v6
236     =>>ruimoku-v6
237     =jef-china3
238     =shinjigen))
239
240
241 ;;; @ char-db formatters
242 ;;;
243
244 (defun char-db-make-char-spec (char)
245   (let (ret char-spec)
246     (cond ((characterp char)
247            (cond ((and (setq ret (encode-char char '=ucs 'defined-only))
248                        (not (and (<= #xE000 ret)(<= ret #xF8FF))))
249                   (setq char-spec (list (cons '=ucs ret)))
250                   (cond ((setq ret (get-char-attribute char 'name))
251                          (setq char-spec (cons (cons 'name ret) char-spec))
252                          )
253                         ((setq ret (get-char-attribute char 'name*))
254                          (setq char-spec (cons (cons 'name* ret) char-spec))
255                          ))
256                   )
257                  ((setq ret
258                         (catch 'tag
259                           (let ((rest char-db-coded-charset-priority-list)
260                                 ccs)
261                             (while rest
262                               (setq ccs (charset-name
263                                          (find-charset (car rest))))
264                               (if (setq ret
265                                         (encode-char char ccs
266                                                      'defined-only))
267                                   (throw 'tag (cons ccs ret)))
268                               (setq rest (cdr rest))))))
269                   (setq char-spec (list ret))
270                   (dolist (ccs (delq (car ret) (charset-list)))
271                     (if (and (or (charset-iso-final-char ccs)
272                                  (memq ccs
273                                        '(=daikanwa
274                                          =daikanwa@rev2
275                                          ;; =gt-k
276                                          =jis-x0208@1997
277                                          ))
278                                  (string-match "=ucs@" (symbol-name ccs)))
279                              (setq ccs (charset-name ccs))
280                              (null (assq ccs char-spec))
281                              (setq ret (encode-char char ccs 'defined-only)))
282                         (setq char-spec (cons (cons ccs ret) char-spec))))
283                   (if (null char-spec)
284                       (setq char-spec (split-char char)))
285                   (cond ((setq ret (get-char-attribute char 'name))
286                          (setq char-spec (cons (cons 'name ret) char-spec))
287                          )
288                         ((setq ret (get-char-attribute char 'name*))
289                          (setq char-spec (cons (cons 'name* ret) char-spec))
290                          ))
291                   )
292                  ((setq ret (get-char-attribute
293                              char 'ideographic-combination))
294                   (setq char-spec
295                         (cons (cons 'ideographic-combination ret)
296                               char-spec))
297                   ))
298            char-spec)
299           ((consp char)
300            char))))
301     
302 (defun char-db-insert-char-spec (char &optional readable column
303                                       required-features)
304   (unless column
305     (setq column (current-column)))
306   (let (char-spec temp-char)
307     (setq char-spec (char-db-make-char-spec char))
308     (unless (or (characterp char) ; char
309                 (condition-case nil
310                     (setq char (find-char char-spec))
311                   (error nil)))
312       ;; define temporary character
313       ;;   Current implementation is dirty.
314       (setq temp-char (define-char (cons '(ideograph-daikanwa . 0)
315                                          char-spec)))
316       (remove-char-attribute temp-char 'ideograph-daikanwa)
317       (setq char temp-char))
318     (insert-char-attributes char
319                             readable
320                             (union (mapcar #'car char-spec)
321                                    required-features)
322                             nil 'for-sub-node)
323     (when temp-char
324       ;; undefine temporary character
325       ;;   Current implementation is dirty.
326       (setq char-spec (char-attribute-alist temp-char))
327       (while char-spec
328         (remove-char-attribute temp-char (car (car char-spec)))
329         (setq char-spec (cdr char-spec))))))
330
331 (defun char-db-insert-alist (alist &optional readable column)
332   (unless column
333     (setq column (current-column)))
334   (let ((line-breaking
335          (concat "\n" (make-string (1+ column) ?\ )))
336         name value
337         ret al ; cal
338         key
339         lbs cell rest separator)
340     (insert "(")
341     (while alist
342       (setq name (car (car alist))
343             value (cdr (car alist)))
344       (cond ((eq name 'char)
345              (insert "(char . ")
346              (if (setq ret (condition-case nil
347                                (find-char value)
348                              (error nil)))
349                  (progn
350                    (setq al nil
351                          ;; cal nil
352                          )
353                    (while value
354                      (setq key (car (car value)))
355                      ;; (if (find-charset key)
356                      ;;     (setq cal (cons key cal))
357                      (setq al (cons key al))
358                      ;; )
359                      (setq value (cdr value)))
360                    (insert-char-attributes ret
361                                            readable
362                                            (or al 'none) ; cal
363                                            nil 'for-sub-node))
364                (insert (prin1-to-string value)))
365              (insert ")")
366              (insert line-breaking))
367             ((consp value)
368              (insert (format "(%-18s " name))
369              (setq lbs (concat "\n" (make-string (current-column) ?\ )))
370              (while (consp value)
371                (setq cell (car value))
372                (if (and (consp cell)
373                         (consp (car cell))
374                         (setq ret (condition-case nil
375                                       (find-char cell)
376                                     (error nil)))
377                         )
378                    (progn
379                      (setq rest cell
380                            al nil
381                            ;; cal nil
382                            )
383                      (while rest
384                        (setq key (car (car rest)))
385                        ;; (if (find-charset key)
386                        ;;     (setq cal (cons key cal))
387                        (setq al (cons key al))
388                        ;; )
389                        (setq rest (cdr rest)))
390                      (if separator
391                          (insert lbs))
392                      (insert-char-attributes ret
393                                              readable
394                                              al ; cal
395                                              nil 'for-sub-node)
396                      (setq separator lbs))
397                  (if separator
398                      (insert separator))
399                  (insert (prin1-to-string cell))
400                  (setq separator " "))
401                (setq value (cdr value)))
402              (insert ")")
403              (insert line-breaking))
404             (t
405              (insert (format "(%-18s . %S)%s"
406                              name value
407                              line-breaking))))
408       (setq alist (cdr alist))))
409   (insert ")"))
410
411 (defun char-db-insert-char-reference (plist &optional readable column)
412   (unless column
413     (setq column (current-column)))
414   (let ((line-breaking
415          (concat "\n" (make-string (1+ column) ?\ )))
416         (separator "")
417         name value)
418     (insert "(")
419     (while plist
420       (setq name (pop plist))
421       (setq value (pop plist))
422       (cond ((eq name :char)
423              (insert separator)
424              (insert ":char\t")
425              (cond ((numberp value)
426                     (setq value (decode-char '=ucs value)))
427                    ;; ((consp value)
428                    ;;  (setq value (or (find-char value)
429                    ;;                  value)))
430                    )
431              (char-db-insert-char-spec value readable)
432              (insert line-breaking)
433              (setq separator ""))
434             ((eq name :radical)
435              (insert (format "%s%s\t%d ; %c%s"
436                              separator
437                              name value
438                              (ideographic-radical value)
439                              line-breaking))
440              (setq separator ""))
441             (t
442              (insert (format "%s%s\t%S" separator name value))
443              (setq separator line-breaking)))
444       ))
445   (insert ")"))
446
447 (defun char-db-decode-isolated-char (ccs code-point)
448   (let (ret)
449     (setq ret
450           (cond ((eq ccs 'arabic-iso8859-6)
451                  (decode-char ccs code-point))
452                 ((and (memq ccs '(=gt-pj-1
453                                   =gt-pj-2
454                                   =gt-pj-3
455                                   =gt-pj-4
456                                   =gt-pj-5
457                                   =gt-pj-6
458                                   =gt-pj-7
459                                   =gt-pj-8
460                                   =gt-pj-9
461                                   =gt-pj-10
462                                   =gt-pj-11))
463                       (setq ret (decode-char ccs code-point))
464                       (setq ret (encode-char ret '=gt 'defined-only)))
465                  (decode-builtin-char '=gt ret))
466                 (t
467                  (decode-builtin-char ccs code-point))))
468     (cond ((and (<= 0 (char-int ret))
469                 (<= (char-int ret) #x1F))
470            (decode-char '=ucs (+ #x2400 (char-int ret))))
471           ((= (char-int ret) #x7F)
472            ?\u2421)
473           (t ret))))
474
475 (defvar char-db-convert-obsolete-format t)
476
477 (defun char-db-insert-ccs-feature (name value line-breaking)
478   (cond
479    ((integerp value)
480     (insert
481      (format
482       (cond
483        ((memq name '(=shinjigen
484                      =shinjigen@1ed
485                      =shinjigen@rev =shinjigen/+p@rev
486                      =daikanwa/ho))
487         "(%-18s .  %04d)\t; %c")
488        ((eq name '=shinjigen@1ed/24pr)
489         "(%-18s . %04d)\t; %c")
490        ((or (memq name '(=daikanwa =>>daikanwa =>daikanwa
491                          =daikanwa@rev1 =daikanwa@rev2
492                          =daikanwa/+p =daikanwa/+2p
493                          =gt =>>>gt =>>gt =+>gt =>gt
494                          =gt-k =>>gt-k =>gt-k
495                          =adobe-japan1-0 =>>>adobe-japan1-0 =>>adobe-japan1-0
496                          =adobe-japan1-1 =>>>adobe-japan1-1 =>>adobe-japan1-1
497                          =adobe-japan1-2 =>>>adobe-japan1-2 =>>adobe-japan1-2
498                          =adobe-japan1-3 =>>>adobe-japan1-3 =>>adobe-japan1-3
499                          =adobe-japan1-4 =>>>adobe-japan1-4 =>>adobe-japan1-4
500                          =adobe-japan1-5 =>>>adobe-japan1-5 =>>adobe-japan1-5
501                          =adobe-japan1-6 =>>>adobe-japan1-6 =>>adobe-japan1-6
502                          =+>adobe-japan1
503                          =cbeta =>>cbeta
504                          =zinbun-oracle =>zinbun-oracle))
505             ;; (string-match "^=adobe-" (symbol-name name))
506             )
507         "(%-18s . %05d)\t; %c")
508        ((memq name '(=hanyo-denshi/ks =>>hanyo-denshi/ks mojikyo))
509         "(%-18s . %06d)\t; %c")
510        ((>= (charset-dimension name) 2)
511         "(%-18s . #x%04X)\t; %c")
512        (t
513         "(%-18s . #x%02X)\t; %c"))
514       name
515       (if (= (charset-iso-graphic-plane name) 1)
516           (logior value
517                   (cond ((= (charset-dimension name) 1)
518                          #x80)
519                         ((= (charset-dimension name) 2)
520                          #x8080)
521                         ((= (charset-dimension name) 3)
522                          #x808080)
523                         (t 0)))
524         value)
525       (char-db-decode-isolated-char name value)))
526     (if (and (= (charset-chars name) 94)
527              (= (charset-dimension name) 2))
528         (insert (format " [%02d-%02d]"
529                         (- (lsh value -8) 32)
530                         (- (logand value 255) 32))))
531     )
532    (t
533     (insert (format "(%-18s . %s)" name value))
534     ))
535   (insert line-breaking))
536
537 (defun char-db-insert-relation-feature (char name value line-breaking
538                                              ccss readable)
539   (insert (format "(%-18s%s " name line-breaking))
540   (let ((lbs (concat "\n" (make-string (current-column) ?\ )))
541         separator cell sources required-features
542         ret)
543     (while (consp value)
544       (setq cell (car value))
545       (if (integerp cell)
546           (setq cell (decode-char '=ucs cell)))
547       (cond
548        ((eq name '->subsumptive)
549         (when (or (not (some (lambda (atr)
550                                (get-char-attribute cell atr))
551                              char-db-ignored-attributes))
552                   (some (lambda (ccs)
553                           (encode-char cell ccs 'defined-only))
554                         ccss))
555           (if separator
556               (insert lbs))
557           (let ((char-db-ignored-attributes
558                  (cons '<-subsumptive
559                        char-db-ignored-attributes)))
560             (insert-char-attributes cell readable nil nil 'for-sub-node))
561           (setq separator lbs))
562         )
563        ((characterp cell)
564         (setq sources
565               (get-char-attribute
566                char (intern (format "%s*sources" name))))
567         (setq required-features nil)
568         (dolist (source sources)
569           (cond
570            ((memq source '(JP
571                            JP/Jouyou
572                            shinjigen shinjigen@1ed shinjigen@rev))
573             (setq required-features
574                   (union required-features
575                          '(=jis-x0208
576                            =jis-x0208@1990
577                            =jis-x0213-1@2000
578                            =jis-x0213-1@2004
579                            =jis-x0213-2
580                            =jis-x0212
581                            =jis-x0208@1983
582                            =jis-x0208@1978
583                            =shinjigen))))
584            ((eq source 'CN)
585             (setq required-features
586                   (union required-features
587                          '(=gb2312
588                            =gb12345
589                            =iso-ir165)))))
590           (cond
591            ((find-charset (setq ret (intern (format "=%s" source))))
592             (setq required-features
593                   (cons ret required-features)))
594            (t (setq required-features
595                     (cons source required-features)))))
596         (cond ((string-match "@JP" (symbol-name name))
597                (setq required-features
598                      (union required-features
599                             '(=jis-x0208
600                               =jis-x0208@1990
601                               =jis-x0213-1-2000
602                               =jis-x0213-2-2000
603                               =jis-x0212
604                               =jis-x0208@1983
605                               =jis-x0208@1978))))
606               ((string-match "@CN" (symbol-name name))
607                (setq required-features
608                      (union required-features
609                             '(=gb2312
610                               =gb12345
611                               =iso-ir165)))))
612         (if separator
613             (insert lbs))
614         (if readable
615             (insert (format "%S" cell))
616           (char-db-insert-char-spec cell readable
617                                     nil
618                                     required-features))
619         (setq separator lbs))
620        ((consp cell)
621         (if separator
622             (insert lbs))
623         (if (consp (car cell))
624             (char-db-insert-char-spec cell readable)
625           (char-db-insert-char-reference cell readable))
626         (setq separator lbs))
627        (t
628         (if separator
629             (insert separator))
630         (insert (prin1-to-string cell))
631         (setq separator " ")))
632       (setq value (cdr value)))
633     (insert ")")
634     (insert line-breaking)))
635
636 (defun insert-char-attributes (char &optional readable attributes column
637                                     for-sub-node)
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 (or readable (not for-sub-node))
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@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       (unless (eq (setq value (get-char-attribute char name 'value-is-empty))
1090                   'value-is-empty)
1091         (cond ((setq ret (find-charset name))
1092                (setq name (charset-name ret))
1093                (when (not (memq name dest-ccss))
1094                  (setq dest-ccss (cons name dest-ccss))
1095                  (char-db-insert-ccs-feature name value line-breaking))
1096                )
1097               ((string-match "^=>ucs@" (symbol-name name))
1098                (insert (format "(%-18s . #x%04X)\t; %c%s"
1099                                name value (decode-char '=ucs value)
1100                                line-breaking))
1101                )
1102               ((eq name 'jisx0208-1978/4X)
1103                (insert (format "(%-18s . #x%04X)%s"
1104                                name value
1105                                line-breaking))
1106                )
1107               ((and
1108                 (not readable)
1109                 (not (eq name '->subsumptive))
1110                 (not (eq name '->uppercase))
1111                 (not (eq name '->lowercase))
1112                 (not (eq name '->titlecase))
1113                 (not (eq name '->canonical))
1114                 (not (eq name '->Bopomofo))
1115                 (not (eq name '->mistakable))
1116                 (not (eq name '->ideographic-variants))
1117                 (null (get-char-attribute
1118                        char (intern (format "%s*sources" name))))
1119                 (not (string-match "\\*sources$" (symbol-name name)))
1120                 (null (get-char-attribute
1121                        char (intern (format "%s*note" name))))
1122                 (not (string-match "\\*note$" (symbol-name name)))
1123                 (or (eq name '<-identical)
1124                     (eq name '<-uppercase)
1125                     (eq name '<-lowercase)
1126                     (eq name '<-titlecase)
1127                     (eq name '<-canonical)
1128                     (eq name '<-ideographic-variants)
1129                     ;; (eq name '<-synonyms)
1130                     (string-match "^<-synonyms" (symbol-name name))
1131                     (eq name '<-mistakable)
1132                     (when (string-match "^->" (symbol-name name))
1133                       (cond
1134                        ((string-match "^->fullwidth" (symbol-name name))
1135                         (not (and (consp value)
1136                                   (characterp (car value))
1137                                   (encode-char
1138                                    (car value) '=ucs 'defined-only)))
1139                         )
1140                        (t)))
1141                     ))
1142                )
1143               ((or (eq name 'ideographic-structure)
1144                    (eq name 'ideographic-combination)
1145                    (eq name 'ideographic-)
1146                    (eq name '=decomposition)
1147                    (char-feature-base-name= '=decomposition name)
1148                    (char-feature-base-name= '=>decomposition name)
1149                    ;; (string-match "^=>*decomposition\\(@[^*]+\\)?$"
1150                    ;;               (symbol-name name))
1151                    (string-match "^\\(->\\|<-\\)[^*]*$" (symbol-name name))
1152                    (string-match "^\\(->\\|<-\\)[^*]*\\*sources$"
1153                                  (symbol-name name))
1154                    )
1155                (char-db-insert-relation-feature char name value
1156                                                 line-breaking
1157                                                 ccss readable))
1158               ((memq name '(ideograph=
1159                             original-ideograph-of
1160                             ancient-ideograph-of
1161                             vulgar-ideograph-of
1162                             wrong-ideograph-of
1163                             ;; simplified-ideograph-of
1164                             ideographic-variants
1165                             ;; ideographic-different-form-of
1166                             ))
1167                (insert (format "(%-18s%s " name line-breaking))
1168                (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1169                      separator nil)
1170                (while (consp value)
1171                  (setq cell (car value))
1172                  (if (and (consp cell)
1173                           (consp (car cell)))
1174                      (progn
1175                        (if separator
1176                            (insert lbs))
1177                        (char-db-insert-alist cell readable)
1178                        (setq separator lbs))
1179                    (if separator
1180                        (insert separator))
1181                    (insert (prin1-to-string cell))
1182                    (setq separator " "))
1183                  (setq value (cdr value)))
1184                (insert ")")
1185                (insert line-breaking))
1186               ((consp value)
1187                (insert (format "(%-18s " name))
1188                (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1189                      separator nil)
1190                (while (consp value)
1191                  (setq cell (car value))
1192                  (if (and (consp cell)
1193                           (consp (car cell))
1194                           (setq ret (condition-case nil
1195                                         (find-char cell)
1196                                       (error nil))))
1197                      (progn
1198                        (setq rest cell
1199                              al nil
1200                              cal nil)
1201                        (while rest
1202                          (setq key (car (car rest)))
1203                          (if (find-charset key)
1204                              (setq cal (cons key cal))
1205                            (setq al (cons key al)))
1206                          (setq rest (cdr rest)))
1207                        (if separator
1208                            (insert lbs))
1209                        (insert-char-attributes ret
1210                                                readable
1211                                                al ; cal
1212                                                nil 'for-sub-node)
1213                        (setq separator lbs))
1214                    (setq ret (prin1-to-string cell))
1215                    (if separator
1216                        (if (< (+ (current-column)
1217                                  (length ret)
1218                                  (length separator))
1219                               76)
1220                            (insert separator)
1221                          (insert lbs)))
1222                    (insert ret)
1223                    (setq separator " "))
1224                  (setq value (cdr value)))
1225                (insert ")")
1226                (insert line-breaking))
1227               (t
1228                (insert (format "(%-18s" name))
1229                (setq ret (prin1-to-string value))
1230                (unless (< (+ (current-column)
1231                              (length ret)
1232                              3)
1233                           76)
1234                  (insert line-breaking))
1235                (insert " . " ret ")" line-breaking)
1236                ;; (insert (format "(%-18s . %S)%s"
1237                ;;                 name value
1238                ;;                 line-breaking))
1239                )
1240               ))
1241       (setq attributes (cdr attributes)))
1242     (insert ")")))
1243
1244 (defun insert-char-data (char &optional readable
1245                               attributes)
1246   (save-restriction
1247     (narrow-to-region (point)(point))
1248     (insert "(define-char
1249   '")
1250     (insert-char-attributes char readable attributes)
1251     (insert ")\n")
1252     (goto-char (point-min))
1253     (while (re-search-forward "[ \t]+$" nil t)
1254       (replace-match ""))
1255     ;; from tabify.
1256     (goto-char (point-min))
1257     (while (re-search-forward "[ \t][ \t][ \t]*" nil t)
1258       (let ((column (current-column))
1259             (indent-tabs-mode t))
1260         (delete-region (match-beginning 0) (point))
1261         (indent-to column)))
1262     (goto-char (point-max))
1263     ;; (tabify (point-min)(point-max))
1264     ))
1265
1266 (defun insert-char-data-with-variant (char &optional printable
1267                                            no-ucs-unified
1268                                            script excluded-script)
1269   (insert-char-data char printable)
1270   (let ((variants (char-variants char))
1271         rest
1272         variant vs ret)
1273     (setq variants (sort variants #'<))
1274     (setq rest variants)
1275     (setq variants (cons char variants))
1276     (while rest
1277       (setq variant (car rest))
1278       (unless (get-char-attribute variant '<-subsumptive)
1279         (if (and (or (null script)
1280                      (null (setq vs (get-char-attribute variant 'script)))
1281                      (memq script vs))
1282                  (or (null excluded-script)
1283                      (null (setq vs (get-char-attribute variant 'script)))
1284                      (not (memq excluded-script vs))))
1285             (unless (and no-ucs-unified (get-char-attribute variant '=ucs))
1286               (insert-char-data variant printable)
1287               (if (setq ret (char-variants variant))
1288                   (while ret
1289                     (or (memq (car ret) variants)
1290                         ;; (get-char-attribute (car ret) '<-subsumptive)
1291                         (setq rest (nconc rest (list (car ret)))))
1292                     (setq ret (cdr ret)))))))
1293       (setq rest (cdr rest)))))
1294
1295 (defun insert-char-range-data (min max &optional script excluded-script)
1296   (let ((code min)
1297         char)
1298     (while (<= code max)
1299       (setq char (decode-char '=ucs code))
1300       (if (encode-char char '=ucs 'defined-only)
1301           (insert-char-data-with-variant char nil 'no-ucs-unified
1302                                          script excluded-script))
1303       (setq code (1+ code)))))
1304
1305 (defun write-char-range-data-to-file (min max file
1306                                           &optional script excluded-script)
1307   (let ((coding-system-for-write char-db-file-coding-system))
1308     (with-temp-buffer
1309       (insert (format ";; -*- coding: %s -*-\n"
1310                       char-db-file-coding-system))
1311       (insert-char-range-data min max script excluded-script)
1312       (write-region (point-min)(point-max) file))))
1313
1314 (defvar what-character-original-window-configuration)
1315
1316 ;;;###autoload
1317 (defun what-char-definition (char)
1318   (interactive (list (char-after)))
1319   (let ((buf (get-buffer-create "*Character Description*"))
1320         (the-buf (current-buffer))
1321         (win-conf (current-window-configuration)))
1322     (pop-to-buffer buf)
1323     (make-local-variable 'what-character-original-window-configuration)
1324     (setq what-character-original-window-configuration win-conf)
1325     (setq buffer-read-only nil)
1326     (erase-buffer)
1327     (condition-case err
1328         (progn
1329           (insert-char-data-with-variant char 'printable)
1330           (unless (char-attribute-alist char)
1331             (insert (format ";; = %c\n"
1332                             (let* ((rest (split-char char))
1333                                    (ccs (pop rest))
1334                                    (code (pop rest)))
1335                               (while rest
1336                                 (setq code (logior (lsh code 8)
1337                                                    (pop rest))))
1338                               (decode-char ccs code)))))
1339           ;; (char-db-update-comment)
1340           (set-buffer-modified-p nil)
1341           (view-mode the-buf (lambda (buf)
1342                                (set-window-configuration
1343                                 what-character-original-window-configuration)
1344                                ))
1345           (goto-char (point-min)))
1346       (error (progn
1347                (set-window-configuration
1348                 what-character-original-window-configuration)
1349                (signal (car err) (cdr err)))))))
1350
1351
1352 ;;; @ end
1353 ;;;
1354
1355 (provide 'char-db-util)
1356
1357 ;;; char-db-util.el ends here