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