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