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