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