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