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