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