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