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