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