1 ;;; char-db-util.el --- Character Database utility -*- coding: utf-8-er; -*-
3 ;; Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006,
4 ;; 2007, 2008 MORIOKA Tomohiko.
6 ;; Author: MORIOKA Tomohiko <tomo@kanji.zinbun.kyoto-u.ac.jp>
7 ;; Keywords: CHISE, Character Database, ISO/IEC 10646, UCS, Unicode, MULE.
9 ;; This file is part of XEmacs CHISE.
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.
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.
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.
30 (defconst unidata-normative-category-alist
31 '(("Lu" letter uppercase)
32 ("Ll" letter lowercase)
33 ("Lt" letter titlecase)
34 ("Mn" mark non-spacing)
35 ("Mc" mark spacing-combining)
37 ("Nd" number decimal-digit)
40 ("Zs" separator space)
42 ("Zp" separator paragraph)
45 ("Cs" other surrogate)
46 ("Co" other private-use)
47 ("Cn" other not-assigned)))
49 (defconst unidata-informative-category-alist
50 '(("Lm" letter modifier)
52 ("Pc" punctuation connector)
53 ("Pd" punctuation dash)
54 ("Ps" punctuation open)
55 ("Pe" punctuation close)
56 ("Pi" punctuation initial-quote)
57 ("Pf" punctuation final-quote)
58 ("Po" punctuation other)
60 ("Sc" symbol currency)
61 ("Sk" symbol modifier)
65 (defconst ideographic-radicals
66 (let ((v (make-vector 215 nil))
69 (aset v i (decode-char '=ucs (+ #x2EFF i)))
73 (defun ideographic-radical (number)
74 (aref ideographic-radicals number))
76 (defconst shuowen-radicals
77 [?一 ?上 ?示 ?三 ?王 ?玉 ?玨 ?气 ?士 ?丨 ; 010
78 ?屮 ?艸 ?蓐 ?茻 ?小 ?八 ?釆 ?半 ?牛 ?犛 ; 020
79 ?告 ?口 ?凵 ?吅 ?哭 ?走 ?止 ?癶 ?步 ?此 ; 030
80 ?正 ?是 ?辵 ?彳 ?廴 ?㢟 ?行 ?齒 ?牙 ?足 ; 040
81 ?疋 ?品 ?龠 ?冊 ?㗊 ?舌 ?干 ?谷 ?只 ?㕯 ; 050
82 ?句 ?丩 ?古 ?十 ?卅 ?言 ?誩 ?音 ?䇂 ?丵 ; 060
83 ?菐 ?𠬞 ?廾 ?共 ?異 ?舁 ?𦥑 ?䢅 ?爨 ?革 ; 070
84 ?鬲 ?䰜 ?爪 ?𠃨 ?鬥 ?又 ?𠂇 ?㕜 ?支 ?𦘒 ; 080
85 ?聿 ?畫 ?隶 ?臤 ?臣 ?殳 ?殺 ?𠘧 ?寸 ?皮 ; 090
86 ?㼱 ?攴 ?敎 ?卜 ?用 ?爻 ?㸚 ?𥄎 ?目 ?䀠 ; 100
87 ?眉 ?盾 ?自 ?白 ?鼻 ?皕 ?習 ?羽 ?隹 ?奞 ; 110
88 ?萑 ?𦫳 ?苜 ?羊 ?羴 ?瞿 ?雔 ?雥 ?鳥 ?烏 ; 120
89 ?𠦒 ?冓 ?幺 ?𢆶 ?叀 ?玄 ?予 ?放 ?𠬪 ?𣦼 ; 130
90 ?歺 ?死 ?冎 ?骨 ?肉 ?筋 ?刀 ?刃 ?㓞 ?丰 ; 140
91 ?耒 ?𧢲 ?竹 ?箕 ?丌 ?左 ?工 ?㠭 ?巫 ?甘 ; 150
92 ?曰 ?乃 ?丂 ?可 ?兮 ?号 ?亏 ?旨 ?喜 ?壴 ; 160
93 ?鼓 ?豈 ?豆 ?豊 ?豐 ?䖒 ?虍 ?虎 ?虤 ?皿 ; 170
94 ?𠙴 ?去 ?血 ?丶 ?丹 ?青 ?井 ?皀 ?鬯 ?食 ; 180
95 ?亼 ?會 ?倉 ?入 ?缶 ?矢 ?高 ?冂 ?𩫏 ?京 ; 190
96 ?亯 ?𣆪 ?畗 ?㐭 ?嗇 ?來 ?麥 ?夊 ?舛 ?䑞 ; 200
97 ?韋 ?弟 ?夂 ?久 ?桀 ?木 ?東 ?林 ?才 ?叒 ; 210
98 ?之 ?帀 ?出 ?𣎵 ?生 ?乇 ?𠂹 ?𠌶 ?華 ?𥝌 ; 220
99 ?稽 ?巢 ?桼 ?束 ?㯻 ?囗 ?員 ?貝 ?邑 ?𨛜 ; 230
100 ?日 ?旦 ?倝 ?㫃 ?冥 ?晶 ?月 ?有 ?明 ?囧 ; 240
101 ?夕 ?多 ?毌 ?𢎘 ?𣐺 ?卣 ?齊 ?朿 ?片 ?鼎 ; 250
102 ?克 ?彔 ?禾 ?秝 ?黍 ?香 ?米 ?毇 ?臼 ?凶 ; 260
103 ?𣎳 ?林 ?麻 ?尗 ?耑 ?韭 ?瓜 ?瓠 ?宀 ?宮 ; 270
104 ?呂 ?穴 ?㝱 ?𤕫 ?冖 ?𠔼 ?冃 ?㒳 ?网 ?襾 ; 280
105 ?巾 ?巿 ?帛 ?白 ?㡀 ?黹 ?人 ?𠤎 ?匕 ?从 ; 290
108 (defun shuowen-radical (number)
109 (aref shuowen-radicals (1- number)))
111 (defvar char-db-file-coding-system 'utf-8-mcs-er)
113 (defvar char-db-feature-domains
114 '(ucs ucs/compat daikanwa cns gt jis jis/alt jis/a jis/b
115 jis-x0212 jis-x0213 cdp shinjigen misc unknown))
117 (defvar char-db-ignored-attributes '(ideographic-products))
119 (defun char-attribute-name< (ka kb)
121 ((eq '->denotational kb)
123 ((eq '->subsumptive kb)
124 (not (eq '->denotational ka)))
125 ((eq '->denotational ka)
127 ((eq '->subsumptive ka)
130 (string-match "^->" (symbol-name ka)))
131 (cond ((and (symbolp kb)
132 (string-match "^->" (symbol-name kb)))
133 (string< (symbol-name ka)
138 (string-match "^->" (symbol-name kb)))
141 (string-match "^<-" (symbol-name ka)))
143 (cond ((string-match "^<-" (symbol-name kb))
144 (string< (symbol-name ka)
147 ;; ((string-match "^->" (symbol-name kb))
152 (string-match "^<-" (symbol-name kb)))
154 ;; (not (string-match "^->" (symbol-name ka)))
157 (if (find-charset kb)
158 (if (or (<= (charset-id ka) 1)
159 (and (charset-final ka)
160 (>= (charset-final ka) ?@)))
161 (if (or (<= (charset-id kb) 1)
162 (and (charset-final kb)
163 (>= (charset-final kb) ?@)))
165 ((= (charset-dimension ka)
166 (charset-dimension kb))
167 (if (and (<= (charset-id ka) 1)
168 (<= (charset-id kb) 1))
169 (> (charset-id ka)(charset-id kb))
170 (if (and (charset-final ka)
173 ((= (charset-final ka)(charset-final kb))
174 (if (<= (charset-id ka) 1)
175 (if (<= (charset-id kb) 1)
176 (> (charset-id ka)(charset-id kb))
178 (if (<= (charset-id kb) 1)
180 (< (charset-id ka)(charset-id kb))))
182 ((< (charset-final ka)(charset-final kb))
184 (if (<= (charset-id ka) 1)
185 (if (<= (charset-id kb) 1)
186 (> (charset-id ka)(charset-id kb))
188 (if (<= (charset-id kb) 1)
190 (cond ((and (charset-final ka)
191 (>= (charset-final ka) ?@))
193 ((and (charset-final kb)
194 (>= (charset-final kb) ?@))
197 (< (charset-id ka)(charset-id kb))
201 (> (charset-dimension ka)
202 (charset-dimension kb))
205 (if (or (<= (charset-id kb) 1)
206 (and (charset-final kb)
207 (>= (charset-final kb) ?@)))
209 (< (charset-id ka)(charset-id kb))))
215 (string< (symbol-name ka)
221 (defvar char-db-coded-charset-priority-list
282 (defun char-db-make-char-spec (char)
284 (cond ((characterp char)
285 (cond ((and (setq ret (encode-char char '=ucs 'defined-only))
286 (not (and (<= #xE000 ret)(<= ret #xF8FF))))
287 (setq char-spec (list (cons '=ucs ret)))
288 (cond ((setq ret (get-char-attribute char 'name))
289 (setq char-spec (cons (cons 'name ret) char-spec))
291 ((setq ret (get-char-attribute char 'name*))
292 (setq char-spec (cons (cons 'name* ret) char-spec))
297 (let ((rest char-db-coded-charset-priority-list)
300 (setq ccs (charset-name
301 (find-charset (car rest))))
303 (encode-char char ccs
305 (throw 'tag (cons ccs ret)))
306 (setq rest (cdr rest))))))
307 (setq char-spec (list ret))
308 (dolist (ccs (delq (car ret) (charset-list)))
309 (if (and (or (charset-iso-final-char ccs)
316 (setq ccs (charset-name ccs))
317 (null (assq ccs char-spec))
318 (setq ret (encode-char char ccs 'defined-only)))
319 (setq char-spec (cons (cons ccs ret) char-spec))))
321 (setq char-spec (split-char char)))
322 (cond ((setq ret (get-char-attribute char 'name))
323 (setq char-spec (cons (cons 'name ret) char-spec))
325 ((setq ret (get-char-attribute char 'name*))
326 (setq char-spec (cons (cons 'name* ret) char-spec))
333 (defun char-db-insert-char-spec (char &optional readable column
336 (setq column (current-column)))
337 (let (char-spec temp-char)
338 (setq char-spec (char-db-make-char-spec char))
339 (unless (or (characterp char) ; char
341 (setq char (find-char char-spec))
343 ;; define temporary character
344 ;; Current implementation is dirty.
345 (setq temp-char (define-char (cons '(ideograph-daikanwa . 0)
347 (remove-char-attribute temp-char 'ideograph-daikanwa)
348 (setq char temp-char))
349 (insert-char-attributes char
351 (union (mapcar #'car char-spec)
354 ;; undefine temporary character
355 ;; Current implementation is dirty.
356 (setq char-spec (char-attribute-alist temp-char))
358 (remove-char-attribute temp-char (car (car char-spec)))
359 (setq char-spec (cdr char-spec))))))
361 (defun char-db-insert-alist (alist &optional readable column)
363 (setq column (current-column)))
365 (concat "\n" (make-string (1+ column) ?\ )))
369 lbs cell rest separator)
372 (setq name (car (car alist))
373 value (cdr (car alist)))
374 (cond ((eq name 'char)
376 (if (setq ret (condition-case nil
384 (setq key (car (car value)))
385 ;; (if (find-charset key)
386 ;; (setq cal (cons key cal))
387 (setq al (cons key al))
389 (setq value (cdr value)))
390 (insert-char-attributes ret
394 (insert (prin1-to-string value)))
396 (insert line-breaking))
398 (insert (format "(%-18s " name))
399 (setq lbs (concat "\n" (make-string (current-column) ?\ )))
401 (setq cell (car value))
402 (if (and (consp cell)
404 (setq ret (condition-case nil
414 (setq key (car (car rest)))
415 ;; (if (find-charset key)
416 ;; (setq cal (cons key cal))
417 (setq al (cons key al))
419 (setq rest (cdr rest)))
422 (insert-char-attributes ret
426 (setq separator lbs))
429 (insert (prin1-to-string cell))
430 (setq separator " "))
431 (setq value (cdr value)))
433 (insert line-breaking))
435 (insert (format "(%-18s . %S)%s"
438 (setq alist (cdr alist))))
441 (defun char-db-insert-char-reference (plist &optional readable column)
443 (setq column (current-column)))
445 (concat "\n" (make-string (1+ column) ?\ )))
450 (setq name (pop plist))
451 (setq value (pop plist))
452 (cond ((eq name :char)
455 (cond ((numberp value)
456 (setq value (decode-char '=ucs value)))
458 ;; (setq value (or (find-char value)
461 (char-db-insert-char-spec value readable)
462 (insert line-breaking)
465 (insert (format "%s%s\t%d ; %c%s"
468 (ideographic-radical value)
472 (insert (format "%s%s\t%S" separator name value))
473 (setq separator line-breaking)))
477 (defun char-db-decode-isolated-char (ccs code-point)
480 (cond ((eq ccs 'arabic-iso8859-6)
481 (decode-char ccs code-point))
482 ((and (memq ccs '(=gt-pj-1
493 (setq ret (decode-char ccs code-point))
494 (setq ret (encode-char ret '=gt 'defined-only)))
495 (decode-builtin-char '=gt ret))
497 (decode-builtin-char ccs code-point))))
498 (cond ((and (<= 0 (char-int ret))
499 (<= (char-int ret) #x1F))
500 (decode-char '=ucs (+ #x2400 (char-int ret))))
501 ((= (char-int ret) #x7F)
505 (defvar char-db-convert-obsolete-format t)
507 (defun char-db-insert-ccs-feature (name value line-breaking)
510 (cond ((memq name '(=shinjigen
512 =shinjigen@rev =shinjigen/+p@rev))
513 "(%-18s . %04d)\t; %c")
514 ((eq name '=shinjigen@1ed/24pr)
515 "(%-18s . %04d)\t; %c")
516 ((or (memq name '(=daikanwa
517 =daikanwa@rev1 =daikanwa@rev2
518 =gt =gt-k =cbeta =zinbun-oracle))
519 (string-match "^=adobe-" (symbol-name name)))
520 "(%-18s . %05d)\t; %c")
522 "(%-18s . %06d)\t; %c")
523 ((>= (charset-dimension name) 2)
524 "(%-18s . #x%04X)\t; %c")
526 "(%-18s . #x%02X)\t; %c"))
528 (if (= (charset-iso-graphic-plane name) 1)
530 (cond ((= (charset-dimension name) 1)
532 ((= (charset-dimension name) 2)
534 ((= (charset-dimension name) 3)
538 (char-db-decode-isolated-char name value)))
539 (if (and (= (charset-chars name) 94)
540 (= (charset-dimension name) 2))
541 (insert (format " [%02d-%02d]"
542 (- (lsh value -8) 32)
543 (- (logand value 255) 32))))
544 (insert line-breaking))
546 (defun char-db-insert-relation-feature (char name value line-breaking
548 (insert (format "(%-18s%s " name line-breaking))
549 (let ((lbs (concat "\n" (make-string (current-column) ?\ )))
550 separator cell sources required-features
553 (setq cell (car value))
555 (setq cell (decode-char '=ucs cell)))
557 ((eq name '->subsumptive)
558 (when (or (not (some (lambda (atr)
559 (get-char-attribute cell atr))
560 char-db-ignored-attributes))
562 (encode-char cell ccs 'defined-only))
566 (let ((char-db-ignored-attributes
568 char-db-ignored-attributes)))
569 (insert-char-attributes cell readable))
570 (setq separator lbs))
575 char (intern (format "%s*sources" name))))
576 (setq required-features nil)
577 (dolist (source sources)
581 shinjigen shinjigen@1ed shinjigen@rev))
582 (setq required-features
583 (union required-features
593 (setq required-features
594 (union required-features
599 ((find-charset (setq ret (intern (format "=%s" source))))
600 (setq required-features
601 (cons ret required-features)))
602 (t (setq required-features
603 (cons source required-features)))))
604 (cond ((string-match "@JP" (symbol-name name))
605 (setq required-features
606 (union required-features
614 ((string-match "@CN" (symbol-name name))
615 (setq required-features
616 (union required-features
623 (insert (format "%S" cell))
624 (char-db-insert-char-spec cell readable
627 (setq separator lbs))
631 (if (consp (car cell))
632 (char-db-insert-char-spec cell readable)
633 (char-db-insert-char-reference cell readable))
634 (setq separator lbs))
638 (insert (prin1-to-string cell))
639 (setq separator " ")))
640 (setq value (cdr value)))
642 (insert line-breaking)))
644 (defun insert-char-attributes (char &optional readable attributes column)
646 (setq column (current-column)))
647 (let (name value ; has-long-ccs-name
651 (concat "\n" (make-string (1+ column) ?\ )))
652 lbs cell separator ret
654 dest-ccss ; sources required-features
659 (if (consp attributes)
661 (dolist (name attributes)
662 (unless (memq name char-db-ignored-attributes)
663 (if (find-charset name)
667 (dolist (name (char-attribute-list))
668 (unless (memq name char-db-ignored-attributes)
669 (if (find-charset name)
673 #'char-attribute-name<)))
675 (when (memq '<-subsumptive attributes)
677 (when (setq value (get-char-attribute char '<-subsumptive))
678 (char-db-insert-relation-feature char '<-subsumptive value
681 (setq attributes (delq '<-subsumptive attributes)))
682 (when (and (memq '<-denotational attributes)
683 (setq value (get-char-attribute char '<-denotational)))
684 (char-db-insert-relation-feature char '<-denotational value
687 (setq attributes (delq '<-denotational attributes)))
688 (when (and (memq 'name attributes)
689 (setq value (get-char-attribute char 'name)))
691 (if (> (+ (current-column) (length value)) 48)
694 value line-breaking))
695 (setq attributes (delq 'name attributes))
697 (when (and (memq 'name* attributes)
698 (setq value (get-char-attribute char 'name*)))
700 (if (> (+ (current-column) (length value)) 48)
703 value line-breaking))
704 (setq attributes (delq 'name* attributes))
706 (when (and (memq 'script attributes)
707 (setq value (get-char-attribute char 'script)))
708 (insert (format "(script\t\t%s)%s"
709 (mapconcat (function prin1-to-string)
712 (setq attributes (delq 'script attributes))
714 (dolist (name '(=>ucs =>ucs*))
715 (when (and (memq name attributes)
716 (setq value (get-char-attribute char name)))
717 (insert (format "(%-18s . #x%04X)\t; %c%s"
718 name value (decode-char '=ucs value)
720 (setq attributes (delq name attributes))))
721 (dolist (name '(=>ucs@gb =>ucs@cns =>ucs@jis =>ucs@ks =>ucs@big5))
722 (when (and (memq name attributes)
723 (setq value (get-char-attribute char name)))
724 (insert (format "(%-18s . #x%04X)\t; %c%s"
729 (symbol-name name) 2)))
732 (setq attributes (delq name attributes))
734 (dolist (name '(=>daikanwa))
735 (when (and (memq name attributes)
736 (setq value (get-char-attribute char name)))
739 (format "(%-18s . %05d)\t; %c%s"
740 name value (decode-char '=daikanwa value)
742 (format "(%-18s %s)\t; %c%s"
744 (mapconcat (function prin1-to-string)
746 (char-representative-of-daikanwa char)
748 (setq attributes (delq name attributes))))
749 (when (and (memq 'general-category attributes)
750 (setq value (get-char-attribute char 'general-category)))
752 "(general-category\t%s) ; %s%s"
753 (mapconcat (lambda (cell)
756 (cond ((rassoc value unidata-normative-category-alist)
757 "Normative Category")
758 ((rassoc value unidata-informative-category-alist)
759 "Informative Category")
763 (setq attributes (delq 'general-category attributes))
765 (when (and (memq 'bidi-category attributes)
766 (setq value (get-char-attribute char 'bidi-category)))
767 (insert (format "(bidi-category\t. %S)%s"
770 (setq attributes (delq 'bidi-category attributes))
772 (unless (or (not (memq 'mirrored attributes))
773 (eq (setq value (get-char-attribute char 'mirrored 'empty))
775 (insert (format "(mirrored\t\t. %S)%s"
778 (setq attributes (delq 'mirrored attributes))
781 ((and (memq 'decimal-digit-value attributes)
782 (setq value (get-char-attribute char 'decimal-digit-value)))
783 (insert (format "(decimal-digit-value . %S)%s"
786 (setq attributes (delq 'decimal-digit-value attributes))
787 (when (and (memq 'digit-value attributes)
788 (setq value (get-char-attribute char 'digit-value)))
789 (insert (format "(digit-value\t . %S)%s"
792 (setq attributes (delq 'digit-value attributes))
794 (when (and (memq 'numeric-value attributes)
795 (setq value (get-char-attribute char 'numeric-value)))
796 (insert (format "(numeric-value\t . %S)%s"
799 (setq attributes (delq 'numeric-value attributes))
803 (when (and (memq 'digit-value attributes)
804 (setq value (get-char-attribute char 'digit-value)))
805 (insert (format "(digit-value\t. %S)%s"
808 (setq attributes (delq 'digit-value attributes))
810 (when (and (memq 'numeric-value attributes)
811 (setq value (get-char-attribute char 'numeric-value)))
812 (insert (format "(numeric-value\t. %S)%s"
815 (setq attributes (delq 'numeric-value attributes))
817 (when (and (memq 'iso-10646-comment attributes)
818 (setq value (get-char-attribute char 'iso-10646-comment)))
819 (insert (format "(iso-10646-comment\t. %S)%s"
822 (setq attributes (delq 'iso-10646-comment attributes))
824 (when (and (memq 'morohashi-daikanwa attributes)
825 (setq value (get-char-attribute char 'morohashi-daikanwa)))
826 (insert (format "(morohashi-daikanwa\t%s)%s"
827 (mapconcat (function prin1-to-string) value " ")
829 (setq attributes (delq 'morohashi-daikanwa attributes))
833 (when (and (memq 'ideographic-radical attributes)
834 (setq value (get-char-attribute char 'ideographic-radical)))
836 (insert (format "(ideographic-radical . %S)\t; %c%s"
838 (ideographic-radical radical)
840 (setq attributes (delq 'ideographic-radical attributes))
842 (when (and (memq 'shuowen-radical attributes)
843 (setq value (get-char-attribute char 'shuowen-radical)))
844 (insert (format "(shuowen-radical\t. %S)\t; %c%s"
846 (shuowen-radical value)
848 (setq attributes (delq 'shuowen-radical attributes))
853 char-db-feature-domains
855 (dolist (feature (char-attribute-list))
856 (setq feature (symbol-name feature))
858 "\\(radical\\|strokes\\)@\\([^@*]+\\)\\(\\*\\|$\\)"
860 (setq domain (intern (match-string 2 feature)))
861 (unless (memq domain dest)
862 (setq dest (cons domain dest)))))
863 (sort dest #'string<))))
864 (setq key (intern (format "%s@%s" 'ideographic-radical domain)))
865 (when (and (memq key attributes)
866 (setq value (get-char-attribute char key)))
868 (insert (format "(%s . %S)\t; %c%s"
871 (ideographic-radical radical)
873 (setq attributes (delq key attributes))
875 (setq key (intern (format "%s@%s" 'ideographic-strokes domain)))
876 (when (and (memq key attributes)
877 (setq value (get-char-attribute char key)))
879 (insert (format "(%s . %S)%s"
883 (setq attributes (delq key attributes))
885 (setq key (intern (format "%s@%s" 'total-strokes domain)))
886 (when (and (memq key attributes)
887 (setq value (get-char-attribute char key)))
888 (insert (format "(%s . %S)%s"
892 (setq attributes (delq key attributes))
894 (dolist (feature '(ideographic-radical
897 (setq key (intern (format "%s@%s*sources" feature domain)))
898 (when (and (memq key attributes)
899 (setq value (get-char-attribute char key)))
900 (insert (format "(%s%s" key line-breaking))
902 (insert (format " %s" cell)))
904 (insert line-breaking)
905 (setq attributes (delq key attributes))
908 (when (and (memq 'ideographic-strokes attributes)
909 (setq value (get-char-attribute char 'ideographic-strokes)))
911 (insert (format "(ideographic-strokes . %S)%s"
914 (setq attributes (delq 'ideographic-strokes attributes))
916 (when (and (memq 'kangxi-radical attributes)
917 (setq value (get-char-attribute char 'kangxi-radical)))
918 (unless (eq value radical)
919 (insert (format "(kangxi-radical\t . %S)\t; %c%s"
921 (ideographic-radical value)
924 (setq radical value)))
925 (setq attributes (delq 'kangxi-radical attributes))
927 (when (and (memq 'kangxi-strokes attributes)
928 (setq value (get-char-attribute char 'kangxi-strokes)))
929 (unless (eq value strokes)
930 (insert (format "(kangxi-strokes\t . %S)%s"
934 (setq strokes value)))
935 (setq attributes (delq 'kangxi-strokes attributes))
937 (when (and (memq 'japanese-radical attributes)
938 (setq value (get-char-attribute char 'japanese-radical)))
939 (unless (eq value radical)
940 (insert (format "(japanese-radical\t . %S)\t; %c%s"
942 (ideographic-radical value)
945 (setq radical value)))
946 (setq attributes (delq 'japanese-radical attributes))
948 (when (and (memq 'japanese-strokes attributes)
949 (setq value (get-char-attribute char 'japanese-strokes)))
950 (unless (eq value strokes)
951 (insert (format "(japanese-strokes\t . %S)%s"
955 (setq strokes value)))
956 (setq attributes (delq 'japanese-strokes attributes))
958 (when (and (memq 'cns-radical attributes)
959 (setq value (get-char-attribute char 'cns-radical)))
960 (insert (format "(cns-radical\t . %S)\t; %c%s"
962 (ideographic-radical value)
964 (setq attributes (delq 'cns-radical attributes))
966 (when (and (memq 'cns-strokes attributes)
967 (setq value (get-char-attribute char 'cns-strokes)))
968 (unless (eq value strokes)
969 (insert (format "(cns-strokes\t . %S)%s"
973 (setq strokes value)))
974 (setq attributes (delq 'cns-strokes attributes))
976 (when (and (memq 'shinjigen-1-radical attributes)
977 (setq value (get-char-attribute char 'shinjigen-1-radical)))
978 (unless (eq value radical)
979 (insert (format "(shinjigen-1-radical . %S)\t; %c%s"
981 (ideographic-radical value)
984 (setq radical value)))
985 (setq attributes (delq 'shinjigen-1-radical attributes))
987 (when (and (memq 'ideographic- attributes)
988 (setq value (get-char-attribute char 'ideographic-)))
989 (insert "(ideographic- ")
990 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
993 (setq cell (car value))
995 (setq cell (decode-char '=ucs cell)))
996 (cond ((characterp cell)
1000 (insert (format "%S" cell))
1001 (char-db-insert-char-spec cell readable))
1002 (setq separator lbs))
1006 (if (consp (car cell))
1007 (char-db-insert-char-spec cell readable)
1008 (char-db-insert-char-reference cell readable))
1009 (setq separator lbs))
1013 (insert (prin1-to-string cell))
1014 (setq separator " ")))
1015 (setq value (cdr value)))
1017 (insert line-breaking)
1018 (setq attributes (delq 'ideographic- attributes)))
1019 (when (and (memq 'total-strokes attributes)
1020 (setq value (get-char-attribute char 'total-strokes)))
1021 (insert (format "(total-strokes . %S)%s"
1024 (setq attributes (delq 'total-strokes attributes))
1026 (when (and (memq '->ideograph attributes)
1027 (setq value (get-char-attribute char '->ideograph)))
1028 (insert (format "(->ideograph\t%s)%s"
1029 (mapconcat (lambda (code)
1030 (cond ((symbolp code)
1033 (format "#x%04X" code))
1036 line-breaking code))))
1039 (setq attributes (delq '->ideograph attributes))
1041 ;; (when (and (memq '->decomposition attributes)
1042 ;; (setq value (get-char-attribute char '->decomposition)))
1043 ;; (insert (format "(->decomposition\t%s)%s"
1044 ;; (mapconcat (lambda (code)
1045 ;; (cond ((symbolp code)
1046 ;; (symbol-name code))
1047 ;; ((characterp code)
1049 ;; (format "%S" code)
1054 ;; (format "#x%04X" code))
1056 ;; (format "%s%S" line-breaking code))))
1059 ;; (setq attributes (delq '->decomposition attributes))
1061 (if (equal (get-char-attribute char '->titlecase)
1062 (get-char-attribute char '->uppercase))
1063 (setq attributes (delq '->titlecase attributes)))
1064 (when (and (memq '->mojikyo attributes)
1065 (setq value (get-char-attribute char '->mojikyo)))
1066 (insert (format "(->mojikyo\t\t. %06d)\t; %c%s"
1067 value (decode-char 'mojikyo value)
1069 (setq attributes (delq '->mojikyo attributes))
1071 (when (and (memq 'hanyu-dazidian-vol attributes)
1072 (setq value (get-char-attribute char 'hanyu-dazidian-vol)))
1073 (insert (format "(hanyu-dazidian-vol . %d)%s"
1074 value line-breaking))
1075 (setq attributes (delq 'hanyu-dazidian-vol attributes))
1077 (when (and (memq 'hanyu-dazidian-page attributes)
1078 (setq value (get-char-attribute char 'hanyu-dazidian-page)))
1079 (insert (format "(hanyu-dazidian-page . %d)%s"
1080 value line-breaking))
1081 (setq attributes (delq 'hanyu-dazidian-page attributes))
1083 (when (and (memq 'hanyu-dazidian-char attributes)
1084 (setq value (get-char-attribute char 'hanyu-dazidian-char)))
1085 (insert (format "(hanyu-dazidian-char . %d)%s"
1086 value line-breaking))
1087 (setq attributes (delq 'hanyu-dazidian-char attributes))
1090 (dolist (ignored '(composition
1091 ->denotational <-subsumptive ->ucs-unified
1092 ->ideographic-component-forms))
1093 (setq attributes (delq ignored attributes))))
1095 (setq name (car attributes))
1096 (if (setq value (get-char-attribute char name))
1097 (cond ((setq ret (find-charset name))
1098 (setq name (charset-name ret))
1099 (if (and (not (memq name dest-ccss))
1101 (setq value (get-char-attribute char name))
1102 (setq dest-ccss (cons name dest-ccss))))
1103 (char-db-insert-ccs-feature name value line-breaking))
1105 ((string-match "^=>ucs@" (symbol-name name))
1106 (insert (format "(%-18s . #x%04X)\t; %c%s"
1107 name value (decode-char '=ucs value)
1110 ((eq name 'jisx0208-1978/4X)
1111 (insert (format "(%-18s . #x%04X)%s"
1117 (not (eq name '->subsumptive))
1118 (not (eq name '->uppercase))
1119 (not (eq name '->lowercase))
1120 (not (eq name '->titlecase))
1121 (not (eq name '->canonical))
1122 (not (eq name '->Bopomofo))
1123 (not (eq name '->mistakable))
1124 (not (eq name '->ideographic-variants))
1125 (null (get-char-attribute
1126 char (intern (format "%s*sources" name))))
1127 (not (string-match "\\*sources$" (symbol-name name)))
1128 (null (get-char-attribute
1129 char (intern (format "%s*note" name))))
1130 (not (string-match "\\*note$" (symbol-name name)))
1131 (or (eq name '<-identical)
1132 (eq name '<-uppercase)
1133 (eq name '<-lowercase)
1134 (eq name '<-titlecase)
1135 (eq name '<-canonical)
1136 (eq name '<-ideographic-variants)
1137 ;; (eq name '<-synonyms)
1138 (string-match "^<-synonyms" (symbol-name name))
1139 (eq name '<-mistakable)
1140 (when (string-match "^->" (symbol-name name))
1142 ((string-match "^->fullwidth" (symbol-name name))
1143 (not (and (consp value)
1144 (characterp (car value))
1146 (car value) '=ucs 'defined-only)))
1151 ((or (eq name 'ideographic-structure)
1152 (eq name 'ideographic-combination)
1153 (eq name 'ideographic-)
1154 (eq name '=decomposition)
1155 (string-match "^=>decomposition" (symbol-name name))
1156 (string-match "^\\(->\\|<-\\)[^*]*$" (symbol-name name))
1157 (string-match "^\\(->\\|<-\\)[^*]*\\*sources$"
1160 (char-db-insert-relation-feature char name value
1163 ((memq name '(ideograph=
1164 original-ideograph-of
1165 ancient-ideograph-of
1168 ;; simplified-ideograph-of
1169 ideographic-variants
1170 ;; ideographic-different-form-of
1172 (insert (format "(%-18s%s " name line-breaking))
1173 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1175 (while (consp value)
1176 (setq cell (car value))
1177 (if (and (consp cell)
1182 (char-db-insert-alist cell readable)
1183 (setq separator lbs))
1186 (insert (prin1-to-string cell))
1187 (setq separator " "))
1188 (setq value (cdr value)))
1190 (insert line-breaking))
1192 (insert (format "(%-18s " name))
1193 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1195 (while (consp value)
1196 (setq cell (car value))
1197 (if (and (consp cell)
1199 (setq ret (condition-case nil
1207 (setq key (car (car rest)))
1208 (if (find-charset key)
1209 (setq cal (cons key cal))
1210 (setq al (cons key al)))
1211 (setq rest (cdr rest)))
1214 (insert-char-attributes ret
1217 (setq separator lbs))
1218 (setq ret (prin1-to-string cell))
1220 (if (< (+ (current-column)
1227 (setq separator " "))
1228 (setq value (cdr value)))
1230 (insert line-breaking))
1232 (insert (format "(%-18s" name))
1233 (setq ret (prin1-to-string value))
1234 (unless (< (+ (current-column)
1238 (insert line-breaking))
1239 (insert " . " ret ")" line-breaking)
1240 ;; (insert (format "(%-18s . %S)%s"
1245 (setq attributes (cdr attributes)))
1248 (defun insert-char-data (char &optional readable
1251 (narrow-to-region (point)(point))
1252 (insert "(define-char
1254 (insert-char-attributes char readable attributes)
1256 (goto-char (point-min))
1257 (while (re-search-forward "[ \t]+$" nil t)
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))
1270 (defun insert-char-data-with-variant (char &optional printable
1272 script excluded-script)
1273 (insert-char-data char printable)
1274 (let ((variants (char-variants char))
1277 (setq variants (sort variants #'<))
1278 (setq rest variants)
1279 (setq variants (cons char variants))
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)))
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))
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)))))
1299 (defun insert-char-range-data (min max &optional script excluded-script)
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)))))
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))
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))))
1318 (defvar what-character-original-window-configuration)
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)))
1327 (make-local-variable 'what-character-original-window-configuration)
1328 (setq what-character-original-window-configuration win-conf)
1329 (setq buffer-read-only nil)
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))
1340 (setq code (logior (lsh code 8)
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)
1349 (goto-char (point-min)))
1351 (set-window-configuration
1352 what-character-original-window-configuration)
1353 (signal (car err) (cdr err)))))))
1355 (provide 'char-db-util)
1357 ;;; char-db-util.el ends here