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