1 ;;; char-db-util.el --- Character Database utility -*- coding: utf-8-er; -*-
3 ;; Copyright (C) 1998,1999,2000,2001,2002,2003,2004,2005,2006,2007,
4 ;; 2008,2009,2010,2011,2012,2013,2014,2015 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.
29 (require 'ideograph-subr)
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)
38 ("Nd" number decimal-digit)
41 ("Zs" separator space)
43 ("Zp" separator paragraph)
46 ("Cs" other surrogate)
47 ("Co" other private-use)
48 ("Cn" other not-assigned)))
50 (defconst unidata-informative-category-alist
51 '(("Lm" letter modifier)
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)
61 ("Sc" symbol currency)
62 ("Sk" symbol modifier)
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 ; ?旨 ?曰 ?乃 ?丂 ?可 ?兮 ?号 ?亏 ?喜 ?壴 ; 160
84 ?鼓 ?豈 ?豆 ?豊 ?豐 ?䖒 ?虍 ?虎 ?虤 ?皿 ; 170
85 ?𠙴 ?去 ?血 ?丶 ?丹 ?青 ?井 ?皀 ?鬯 ?食 ; 180
86 ?亼 ?會 ?倉 ?入 ?缶 ?矢 ?高 ?冂 ?𩫏 ?京 ; 190
87 ?亯 ?𣆪 ?畗 ?㐭 ?嗇 ?來 ?麥 ?夊 ?舛 ?䑞 ; 200
88 ?韋 ?弟 ?夂 ?久 ?桀 ?木 ?東 ?林 ?才 ?叒 ; 210
89 ?之 ?帀 ?出 ?𣎵 ?生 ?乇 ?𠂹 ?𠌶 ?華 ?𥝌 ; 220
90 ?稽 ?巢 ?桼 ?束 ?㯻 ?囗 ?員 ?貝 ?邑 ?𨛜 ; 230
91 ?日 ?旦 ?倝 ?㫃 ?冥 ?晶 ?月 ?有 ?明 ?囧 ; 240
92 ?夕 ?多 ?毌 ?𢎘 ?𣐺 ?卣 ?齊 ?朿 ?片 ?鼎 ; 250
93 ?克 ?彔 ?禾 ?秝 ?黍 ?香 ?米 ?毇 ?臼 ?凶 ; 260
94 ?𣎳 ?林 ?麻 ?尗 ?耑 ?韭 ?瓜 ?瓠 ?宀 ?宮 ; 270
95 ?呂 ?穴 ?㝱 ?𤕫 ?冖 ?𠔼 ?冃 ?㒳 ?网 ?襾 ; 280
96 ?巾 ?巿 ?帛 ?白 ?㡀 ?黹 ?人 ?𠤎 ?匕 ?从 ; 290
97 ?比 ?北 ?丘 ?㐺 ?𡈼 ?重 ?臥 ?身 ?㐆 ?衣 ; 300
98 ?裘 ?老 ?毛 ?毳 ?尸 ?尺 ?尾 ?履 ?舟 ?方 ; 310
99 ?儿 ?兄 ?兂 ?皃 ?𠑹 ?先 ?秃 ?見 ?覞 ?欠 ; 320
100 ?㱃 ?㳄 ?旡 ?頁 ?𦣻 ?面 ?丏 ?首 ?𥄉 ?須 ; 330
101 ?彡 ?彣 ?文 ?髟 ?后 ?司 ?卮 ?卩 ?印 ?色 ; 340
102 ?𠨍 ?辟 ?勹 ?包 ?茍 ?鬼 ?甶 ?厶 ?嵬 ?山 ; 350
103 ?屾 ?屵 ?广 ?厂 ?丸 ?危 ?石 ?長 ?勿 ?冄 ; 360
104 ?而 ?豕 ?㣇 ?彑 ?豚 ?豸 ?𤉡 ?易 ?象 ?馬 ; 370
105 ?𢊁 ?鹿 ?麤 ?㲋 ?兔 ?萈 ?犬 ?㹜 ?鼠 ?能 ; 380
106 ?熊 ?火 ?炎 ?黑 ?囪 ?焱 ?炙 ?赤 ?大 ?亦 ; 390
109 (defun shuowen-radical (number)
110 (aref shuowen-radicals (1- number)))
112 (defvar char-db-file-coding-system 'utf-8-mcs-er)
114 (defvar char-db-ignored-attributes '(ideographic-products))
116 (defvar char-db-coded-charset-priority-list
210 ;; =>>>adobe-japan1-0
211 ;; =>>>adobe-japan1-1
212 ;; =>>>adobe-japan1-2
213 ;; =>>>adobe-japan1-3
214 ;; =>>>adobe-japan1-4
215 ;; =>>>adobe-japan1-5
216 ;; =>>>adobe-japan1-6
220 ;; =>>>hanyo-denshi/ja
221 ;; =>>>hanyo-denshi/jb
222 ;; =>>>hanyo-denshi/jc
223 ;; =>>>hanyo-denshi/ft
224 ;; =>>>hanyo-denshi/ib
225 ;; =>>>hanyo-denshi/hg
226 ;; =>>>hanyo-denshi/jt
227 ;; =>>>hanyo-denshi/ks
330 ;;; @ char-db formatters
333 (defun char-db-make-char-spec (char)
335 (cond ((characterp char)
336 (cond ((and (setq ret (encode-char char '=ucs 'defined-only))
337 (not (and (<= #xE000 ret)(<= ret #xF8FF))))
338 (setq char-spec (list (cons '=ucs ret)))
339 (cond ((setq ret (get-char-attribute char 'name))
340 (setq char-spec (cons (cons 'name ret) char-spec))
342 ((setq ret (get-char-attribute char 'name*))
343 (setq char-spec (cons (cons 'name* ret) char-spec))
346 ((encode-char char '=mj 'defined-only)
348 (dolist (ccs (charset-list))
349 (if (and (or (eq ccs '=mj)
350 ;; (eq (charset-property ccs 'iso-ir) 177)
351 (string-match "=ucs@" (symbol-name ccs))
353 (setq ccs (charset-name ccs))
354 (null (assq ccs char-spec))
355 (setq ret (encode-char char ccs 'defined-only)))
356 (setq char-spec (cons (cons ccs ret) char-spec))))
358 ((encode-char char '==mj 'defined-only)
360 (dolist (ccs (charset-list))
361 (if (and (or (eq ccs '==mj)
362 ;; (eq (charset-property ccs 'iso-ir) 177)
363 (string-match "=ucs@" (symbol-name ccs))
365 (setq ccs (charset-name ccs))
366 (null (assq ccs char-spec))
367 (setq ret (encode-char char ccs 'defined-only)))
368 (setq char-spec (cons (cons ccs ret) char-spec))))
370 ((encode-char char '=adobe-japan1 'defined-only)
372 (dolist (ccs (charset-list))
373 (if (and (or (memq ccs
382 ;; (eq (charset-property ccs 'iso-ir) 177)
383 (string-match "=ucs@" (symbol-name ccs))
385 (setq ccs (charset-name ccs))
386 (null (assq ccs char-spec))
387 (setq ret (encode-char char ccs 'defined-only)))
388 (setq char-spec (cons (cons ccs ret) char-spec))))
390 ((encode-char char '==adobe-japan1 'defined-only)
392 (dolist (ccs (charset-list))
393 (if (and (or (memq ccs
402 ;; (eq (charset-property ccs 'iso-ir) 177)
403 (string-match "=ucs@" (symbol-name ccs))
405 (setq ccs (charset-name ccs))
406 (null (assq ccs char-spec))
407 (setq ret (encode-char char ccs 'defined-only)))
408 (setq char-spec (cons (cons ccs ret) char-spec))))
412 (let ((rest char-db-coded-charset-priority-list)
415 (setq ccs (charset-name
416 (find-charset (car rest))))
418 (encode-char char ccs
420 (throw 'tag (cons ccs ret)))
421 (setq rest (cdr rest))))))
422 (setq char-spec (list ret))
423 (dolist (ccs (delq (car ret) (charset-list)))
424 (if (and (or (charset-iso-final-char ccs)
431 (eq (charset-property ccs 'iso-ir) 177)
432 ;; (string-match "=ucs@" (symbol-name ccs))
434 (setq ccs (charset-name ccs))
435 (null (assq ccs char-spec))
436 (setq ret (encode-char char ccs 'defined-only)))
437 (setq char-spec (cons (cons ccs ret) char-spec))))
439 (setq char-spec (split-char char)))
440 (cond ((setq ret (get-char-attribute char 'name))
441 (setq char-spec (cons (cons 'name ret) char-spec))
443 ((setq ret (get-char-attribute char 'name*))
444 (setq char-spec (cons (cons 'name* ret) char-spec))
447 ((setq ret (get-char-attribute
448 char 'ideographic-combination))
450 (cons (cons 'ideographic-combination ret)
457 (defun char-db-insert-char-spec (char &optional readable column
460 (setq column (current-column)))
461 (let (char-spec temp-char)
462 (setq char-spec (char-db-make-char-spec char))
463 (unless (or (characterp char) ; char
465 (setq char (find-char char-spec))
467 ;; define temporary character
468 ;; Current implementation is dirty.
469 (setq temp-char (define-char (cons '(ideograph-daikanwa . 0)
471 (remove-char-attribute temp-char 'ideograph-daikanwa)
472 (setq char temp-char))
473 (insert-char-attributes char
475 (union (mapcar #'car char-spec)
479 ;; undefine temporary character
480 ;; Current implementation is dirty.
481 (setq char-spec (char-attribute-alist temp-char))
483 (remove-char-attribute temp-char (car (car char-spec)))
484 (setq char-spec (cdr char-spec))))))
486 (defun char-db-insert-alist (alist &optional readable column)
488 (setq column (current-column)))
490 (concat "\n" (make-string (1+ column) ?\ )))
494 lbs cell rest separator)
497 (setq name (car (car alist))
498 value (cdr (car alist)))
499 (cond ((eq name 'char)
501 (if (setq ret (condition-case nil
509 (setq key (car (car value)))
510 ;; (if (find-charset key)
511 ;; (setq cal (cons key cal))
512 (setq al (cons key al))
514 (setq value (cdr value)))
515 (insert-char-attributes ret
519 (insert (prin1-to-string value)))
521 (insert line-breaking))
523 (insert (format "(%-18s " name))
524 (setq lbs (concat "\n" (make-string (current-column) ?\ )))
526 (setq cell (car value))
527 (if (and (consp cell)
529 (setq ret (condition-case nil
539 (setq key (car (car rest)))
540 ;; (if (find-charset key)
541 ;; (setq cal (cons key cal))
542 (setq al (cons key al))
544 (setq rest (cdr rest)))
547 (insert-char-attributes ret
551 (setq separator lbs))
554 (insert (prin1-to-string cell))
555 (setq separator " "))
556 (setq value (cdr value)))
558 (insert line-breaking))
560 (insert (format "(%-18s . %S)%s"
563 (setq alist (cdr alist))))
566 (defun char-db-insert-char-reference (plist &optional readable column)
568 (setq column (current-column)))
570 (concat "\n" (make-string (1+ column) ?\ )))
575 (setq name (pop plist))
576 (setq value (pop plist))
577 (cond ((eq name :char)
580 (cond ((numberp value)
581 (setq value (decode-char '=ucs value)))
583 ;; (setq value (or (find-char value)
586 (char-db-insert-char-spec value readable)
587 (insert line-breaking)
590 (insert (format "%s%s\t%d ; %c%s"
593 (ideographic-radical value)
597 (insert (format "%s%s\t%S" separator name value))
598 (setq separator line-breaking)))
602 (defun char-db-decode-isolated-char (ccs code-point)
605 (cond ((eq ccs 'arabic-iso8859-6)
606 (decode-char ccs code-point))
608 ;; (decode-builtin-char '==gt code-point))
609 ((and (memq ccs '(=gt-pj-1
620 (setq ret (decode-char ccs code-point))
621 (setq ret (encode-char ret '=gt 'defined-only)))
622 (decode-builtin-char '=gt ret))
624 (decode-builtin-char ccs code-point))))
626 (or (decode-char ccs code-point)
627 (define-char (list (cons ccs code-point)))))
628 ((and (<= 0 (char-int ret))
629 (<= (char-int ret) #x1F))
630 (decode-char '=ucs (+ #x2400 (char-int ret))))
631 ((= (char-int ret) #x7F)
635 (defvar char-db-convert-obsolete-format t)
637 (defun char-db-insert-ccs-feature (name value line-breaking)
643 ((memq name '(=>iwds-1
646 =shinjigen@1ed ==shinjigen@1ed
647 =shinjigen@rev ==shinjigen@rev
648 =shinjigen/+p@rev ==shinjigen/+p@rev
649 ===daikanwa/ho ==daikanwa/ho
650 =daikanwa/ho =>>daikanwa/ho =>daikanwa/ho))
651 "(%-18s . %04d)\t; %c")
652 ((eq name '=shinjigen@1ed/24pr)
653 "(%-18s . %04d)\t; %c")
654 ((or (memq name '(===daikanwa
655 ==daikanwa =daikanwa =>>daikanwa =>daikanwa
656 =daikanwa@rev1 =daikanwa@rev2
657 =daikanwa/+p ==daikanwa/+p ===daikanwa/+p
659 =daikanwa/+2p =>>daikanwa/+2p
664 =adobe-japan1-0 ==adobe-japan1-0 ===adobe-japan1-0
665 =adobe-japan1-1 ==adobe-japan1-1 ===adobe-japan1-1
666 =adobe-japan1-2 ==adobe-japan1-2 ===adobe-japan1-2
667 =adobe-japan1-3 ==adobe-japan1-3 ===adobe-japan1-3
668 =adobe-japan1-4 ==adobe-japan1-4 ===adobe-japan1-4
669 =adobe-japan1-5 ==adobe-japan1-5 ===adobe-japan1-5
670 =adobe-japan1-6 ==adobe-japan1-6 ===adobe-japan1-6
671 =>>adobe-japan1-0 =+>adobe-japan1-0
672 =>>adobe-japan1-1 =+>adobe-japan1-1
673 =>>adobe-japan1-2 =+>adobe-japan1-2
674 =>>adobe-japan1-3 =+>adobe-japan1-3
675 =>>adobe-japan1-4 =+>adobe-japan1-4
676 =>>adobe-japan1-5 =+>adobe-japan1-5
677 =>>adobe-japan1-6 =+>adobe-japan1-6
678 =>cbeta =cbeta =>>cbeta ==cbeta ===cbeta
679 =zinbun-oracle =>zinbun-oracle))
680 ;; (string-match "^=adobe-" (symbol-name name))
682 "(%-18s . %05d)\t; %c")
683 ((memq name '(=hanyo-denshi/ks
684 ==hanyo-denshi/ks ===hanyo-denshi/ks
689 "(%-18s . %06d)\t; %c")
690 ((>= (charset-dimension name) 2)
691 "(%-18s . #x%04X)\t; %c")
693 "(%-18s . #x%02X)\t; %c"))
695 (if (= (charset-iso-graphic-plane name) 1)
697 (cond ((= (charset-dimension name) 1)
699 ((= (charset-dimension name) 2)
701 ((= (charset-dimension name) 3)
705 (char-db-decode-isolated-char name value)))
706 (if (and (= (charset-chars name) 94)
707 (= (charset-dimension name) 2))
708 (insert (format " [%02d-%02d]"
709 (- (lsh value -8) 32)
710 (- (logand value 255) 32))))
713 (insert (format "(%-18s . %s)" name value))
715 (insert line-breaking))
717 (defun char-db-insert-relation-feature (char name value line-breaking
719 (insert (format "(%-18s%s " name line-breaking))
720 (let ((lbs (concat "\n" (make-string (current-column) ?\ )))
721 separator cell sources required-features
724 (setq cell (car value))
726 (setq cell (decode-char '=ucs cell)))
728 ((eq name '->subsumptive)
729 (when (or (not (some (lambda (atr)
730 (get-char-attribute cell atr))
731 char-db-ignored-attributes))
733 (encode-char cell ccs 'defined-only))
737 (let ((char-db-ignored-attributes
739 char-db-ignored-attributes)))
740 (insert-char-attributes cell readable nil nil 'for-sub-node))
741 (setq separator lbs))
746 char (intern (format "%s*sources" name))))
747 (setq required-features nil)
748 (dolist (source sources)
752 shinjigen shinjigen@1ed shinjigen@rev))
753 (setq required-features
754 (union required-features
766 =shinjigen/+p@rev))))
768 (setq required-features
769 (union required-features
774 ((find-charset (setq ret (intern (format "=%s" source))))
775 (setq required-features
776 (cons ret required-features)))
777 (t (setq required-features
778 (cons source required-features)))))
779 (cond ((string-match "@JP" (symbol-name name))
780 (setq required-features
781 (union required-features
789 ((string-match "@CN" (symbol-name name))
790 (setq required-features
791 (union required-features
798 (insert (format "%S" cell))
799 (char-db-insert-char-spec cell readable
802 (setq separator lbs))
806 (if (consp (car cell))
807 (char-db-insert-char-spec cell readable)
808 (char-db-insert-char-reference cell readable))
809 (setq separator lbs))
813 (insert (prin1-to-string cell))
814 (setq separator " ")))
815 (setq value (cdr value)))
817 (insert line-breaking)))
819 (defun insert-char-attributes (char &optional readable attributes column
822 (setq column (current-column)))
823 (let (name value ; has-long-ccs-name
827 (concat "\n" (make-string (1+ column) ?\ )))
828 lbs cell separator ret
830 dest-ccss ; sources required-features
835 (if (consp attributes)
837 (dolist (name attributes)
838 (unless (memq name char-db-ignored-attributes)
839 (if (find-charset name)
843 (dolist (name (char-attribute-list))
844 (unless (memq name char-db-ignored-attributes)
845 (if (find-charset name)
849 #'char-attribute-name<)))
851 (when (memq '<-subsumptive attributes)
852 (when (or readable (not for-sub-node))
853 (when (setq value (get-char-attribute char '<-subsumptive))
854 (char-db-insert-relation-feature char '<-subsumptive value
857 (setq attributes (delq '<-subsumptive attributes)))
858 (when (and (memq '<-denotational attributes)
859 (setq value (get-char-attribute char '<-denotational)))
860 (char-db-insert-relation-feature char '<-denotational value
863 (setq attributes (delq '<-denotational attributes)))
864 (when (and (memq '<-denotational@component attributes)
865 (setq value (get-char-attribute char '<-denotational@component)))
866 (char-db-insert-relation-feature char '<-denotational@component value
869 (setq attributes (delq '<-denotational@component attributes)))
870 (when (and (memq 'name attributes)
871 (setq value (get-char-attribute char 'name)))
873 (if (> (+ (current-column) (length value)) 48)
876 value line-breaking))
877 (setq attributes (delq 'name attributes))
879 (when (and (memq 'name* attributes)
880 (setq value (get-char-attribute char 'name*)))
882 (if (> (+ (current-column) (length value)) 48)
885 value line-breaking))
886 (setq attributes (delq 'name* attributes))
888 (when (and (memq 'script attributes)
889 (setq value (get-char-attribute char 'script)))
890 (insert (format "(script\t\t%s)%s"
891 (mapconcat (function prin1-to-string)
894 (setq attributes (delq 'script attributes))
896 (dolist (name '(=>ucs =>ucs*))
897 (when (and (memq name attributes)
898 (setq value (get-char-attribute char name)))
899 (insert (format "(%-18s . #x%04X)\t; %c%s"
900 name value (decode-char '=ucs value)
902 (setq attributes (delq name attributes))))
903 (dolist (name '(=>ucs@gb =>ucs@big5))
904 (when (and (memq name attributes)
905 (setq value (get-char-attribute char name)))
906 (insert (format "(%-18s . #x%04X)\t; %c%s"
911 (symbol-name name) 2)))
914 (setq attributes (delq name attributes))
916 ;; (dolist (name '(=>daikanwa))
917 ;; (when (and (memq name attributes)
918 ;; (setq value (get-char-attribute char name)))
920 ;; (if (integerp value)
921 ;; (format "(%-18s . %05d)\t; %c%s"
922 ;; name value (decode-char '=daikanwa value)
924 ;; (format "(%-18s %s)\t; %c%s"
926 ;; (mapconcat (function prin1-to-string)
928 ;; (char-representative-of-daikanwa char)
930 ;; (setq attributes (delq name attributes))))
931 (when (and (memq 'general-category attributes)
932 (setq value (get-char-attribute char 'general-category)))
934 "(general-category\t%s) ; %s%s"
935 (mapconcat (lambda (cell)
938 (cond ((rassoc value unidata-normative-category-alist)
939 "Normative Category")
940 ((rassoc value unidata-informative-category-alist)
941 "Informative Category")
945 (setq attributes (delq 'general-category attributes))
947 (when (and (memq 'bidi-category attributes)
948 (setq value (get-char-attribute char 'bidi-category)))
949 (insert (format "(bidi-category\t. %S)%s"
952 (setq attributes (delq 'bidi-category attributes))
954 (unless (or (not (memq 'mirrored attributes))
955 (eq (setq value (get-char-attribute char 'mirrored 'empty))
957 (insert (format "(mirrored\t\t. %S)%s"
960 (setq attributes (delq 'mirrored attributes))
963 ((and (memq 'decimal-digit-value attributes)
964 (setq value (get-char-attribute char 'decimal-digit-value)))
965 (insert (format "(decimal-digit-value . %S)%s"
968 (setq attributes (delq 'decimal-digit-value attributes))
969 (when (and (memq 'digit-value attributes)
970 (setq value (get-char-attribute char 'digit-value)))
971 (insert (format "(digit-value\t . %S)%s"
974 (setq attributes (delq 'digit-value attributes))
976 (when (and (memq 'numeric-value attributes)
977 (setq value (get-char-attribute char 'numeric-value)))
978 (insert (format "(numeric-value\t . %S)%s"
981 (setq attributes (delq 'numeric-value attributes))
985 (when (and (memq 'digit-value attributes)
986 (setq value (get-char-attribute char 'digit-value)))
987 (insert (format "(digit-value\t. %S)%s"
990 (setq attributes (delq 'digit-value attributes))
992 (when (and (memq 'numeric-value attributes)
993 (setq value (get-char-attribute char 'numeric-value)))
994 (insert (format "(numeric-value\t. %S)%s"
997 (setq attributes (delq 'numeric-value attributes))
999 (when (and (memq 'iso-10646-comment attributes)
1000 (setq value (get-char-attribute char 'iso-10646-comment)))
1001 (insert (format "(iso-10646-comment\t. %S)%s"
1004 (setq attributes (delq 'iso-10646-comment attributes))
1006 (when (and (memq 'morohashi-daikanwa attributes)
1007 (setq value (get-char-attribute char 'morohashi-daikanwa)))
1008 (insert (format "(morohashi-daikanwa\t%s)%s"
1009 (mapconcat (function prin1-to-string) value " ")
1011 (setq attributes (delq 'morohashi-daikanwa attributes))
1015 (when (and (memq 'ideographic-radical attributes)
1016 (setq value (get-char-attribute char 'ideographic-radical)))
1017 (setq radical value)
1018 (insert (format "(ideographic-radical . %S)\t; %c%s"
1020 (ideographic-radical radical)
1022 (setq attributes (delq 'ideographic-radical attributes))
1024 (when (and (memq 'shuowen-radical attributes)
1025 (setq value (get-char-attribute char 'shuowen-radical)))
1026 (insert (format "(shuowen-radical\t. %S)\t; %c%s"
1028 (shuowen-radical value)
1030 (setq attributes (delq 'shuowen-radical attributes))
1035 char-db-feature-domains
1037 (dolist (feature (char-attribute-list))
1038 (setq feature (symbol-name feature))
1040 "\\(radical\\|strokes\\)@\\([^@*]+\\)\\(\\*\\|$\\)"
1042 (setq domain (intern (match-string 2 feature)))
1043 (unless (memq domain dest)
1044 (setq dest (cons domain dest)))))
1045 (sort dest #'string<))))
1046 (setq key (intern (format "%s@%s" 'ideographic-radical domain)))
1047 (when (and (memq key attributes)
1048 (setq value (get-char-attribute char key)))
1049 (setq radical value)
1050 (insert (format "(%s . %S)\t; %c%s"
1053 (ideographic-radical radical)
1055 (setq attributes (delq key attributes))
1057 (setq key (intern (format "%s@%s" 'ideographic-strokes domain)))
1058 (when (and (memq key attributes)
1059 (setq value (get-char-attribute char key)))
1060 (setq strokes value)
1061 (insert (format "(%s . %S)%s"
1065 (setq attributes (delq key attributes))
1067 (setq key (intern (format "%s@%s" 'total-strokes domain)))
1068 (when (and (memq key attributes)
1069 (setq value (get-char-attribute char key)))
1070 (insert (format "(%s . %S)%s"
1074 (setq attributes (delq key attributes))
1076 (dolist (feature '(ideographic-radical
1079 (setq key (intern (format "%s@%s*sources" feature domain)))
1080 (when (and (memq key attributes)
1081 (setq value (get-char-attribute char key)))
1082 (insert (format "(%s%s" key line-breaking))
1083 (dolist (cell value)
1084 (insert (format " %s" cell)))
1086 (insert line-breaking)
1087 (setq attributes (delq key attributes))
1090 (when (and (memq 'ideographic-strokes attributes)
1091 (setq value (get-char-attribute char 'ideographic-strokes)))
1092 (setq strokes value)
1093 (insert (format "(ideographic-strokes . %S)%s"
1096 (setq attributes (delq 'ideographic-strokes attributes))
1098 (when (and (memq 'kangxi-radical attributes)
1099 (setq value (get-char-attribute char 'kangxi-radical)))
1100 (unless (eq value radical)
1101 (insert (format "(kangxi-radical\t . %S)\t; %c%s"
1103 (ideographic-radical value)
1106 (setq radical value)))
1107 (setq attributes (delq 'kangxi-radical attributes))
1109 (when (and (memq 'kangxi-strokes attributes)
1110 (setq value (get-char-attribute char 'kangxi-strokes)))
1111 (unless (eq value strokes)
1112 (insert (format "(kangxi-strokes\t . %S)%s"
1116 (setq strokes value)))
1117 (setq attributes (delq 'kangxi-strokes attributes))
1119 (when (and (memq 'japanese-radical attributes)
1120 (setq value (get-char-attribute char 'japanese-radical)))
1121 (unless (eq value radical)
1122 (insert (format "(japanese-radical\t . %S)\t; %c%s"
1124 (ideographic-radical value)
1127 (setq radical value)))
1128 (setq attributes (delq 'japanese-radical attributes))
1130 (when (and (memq 'japanese-strokes attributes)
1131 (setq value (get-char-attribute char 'japanese-strokes)))
1132 (unless (eq value strokes)
1133 (insert (format "(japanese-strokes\t . %S)%s"
1137 (setq strokes value)))
1138 (setq attributes (delq 'japanese-strokes attributes))
1140 (when (and (memq 'cns-radical attributes)
1141 (setq value (get-char-attribute char 'cns-radical)))
1142 (insert (format "(cns-radical\t . %S)\t; %c%s"
1144 (ideographic-radical value)
1146 (setq attributes (delq 'cns-radical attributes))
1148 (when (and (memq 'cns-strokes attributes)
1149 (setq value (get-char-attribute char 'cns-strokes)))
1150 (unless (eq value strokes)
1151 (insert (format "(cns-strokes\t . %S)%s"
1155 (setq strokes value)))
1156 (setq attributes (delq 'cns-strokes attributes))
1158 ;; (when (and (memq 'shinjigen-1-radical attributes)
1159 ;; (setq value (get-char-attribute char 'shinjigen-1-radical)))
1160 ;; (unless (eq value radical)
1161 ;; (insert (format "(shinjigen-1-radical . %S)\t; %c%s"
1163 ;; (ideographic-radical value)
1166 ;; (setq radical value)))
1167 ;; (setq attributes (delq 'shinjigen-1-radical attributes))
1169 (when (and (memq 'ideographic- attributes)
1170 (setq value (get-char-attribute char 'ideographic-)))
1171 (insert "(ideographic- ")
1172 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1174 (while (consp value)
1175 (setq cell (car value))
1177 (setq cell (decode-char '=ucs cell)))
1178 (cond ((characterp cell)
1182 (insert (format "%S" cell))
1183 (char-db-insert-char-spec cell readable))
1184 (setq separator lbs))
1188 (if (consp (car cell))
1189 (char-db-insert-char-spec cell readable)
1190 (char-db-insert-char-reference cell readable))
1191 (setq separator lbs))
1195 (insert (prin1-to-string cell))
1196 (setq separator " ")))
1197 (setq value (cdr value)))
1199 (insert line-breaking)
1200 (setq attributes (delq 'ideographic- attributes)))
1201 (when (and (memq 'total-strokes attributes)
1202 (setq value (get-char-attribute char 'total-strokes)))
1203 (insert (format "(total-strokes . %S)%s"
1206 (setq attributes (delq 'total-strokes attributes))
1208 (when (and (memq '->ideograph attributes)
1209 (setq value (get-char-attribute char '->ideograph)))
1210 (insert (format "(->ideograph\t%s)%s"
1211 (mapconcat (lambda (code)
1212 (cond ((symbolp code)
1215 (format "#x%04X" code))
1218 line-breaking code))))
1221 (setq attributes (delq '->ideograph attributes))
1223 ;; (when (and (memq '->decomposition attributes)
1224 ;; (setq value (get-char-attribute char '->decomposition)))
1225 ;; (insert (format "(->decomposition\t%s)%s"
1226 ;; (mapconcat (lambda (code)
1227 ;; (cond ((symbolp code)
1228 ;; (symbol-name code))
1229 ;; ((characterp code)
1231 ;; (format "%S" code)
1236 ;; (format "#x%04X" code))
1238 ;; (format "%s%S" line-breaking code))))
1241 ;; (setq attributes (delq '->decomposition attributes))
1243 (if (equal (get-char-attribute char '->titlecase)
1244 (get-char-attribute char '->uppercase))
1245 (setq attributes (delq '->titlecase attributes)))
1246 (when (and (memq '->mojikyo attributes)
1247 (setq value (get-char-attribute char '->mojikyo)))
1248 (insert (format "(->mojikyo\t\t. %06d)\t; %c%s"
1249 value (decode-char 'mojikyo value)
1251 (setq attributes (delq '->mojikyo attributes))
1253 (when (and (memq 'hanyu-dazidian-vol attributes)
1254 (setq value (get-char-attribute char 'hanyu-dazidian-vol)))
1255 (insert (format "(hanyu-dazidian-vol . %d)%s"
1256 value line-breaking))
1257 (setq attributes (delq 'hanyu-dazidian-vol attributes))
1259 (when (and (memq 'hanyu-dazidian-page attributes)
1260 (setq value (get-char-attribute char 'hanyu-dazidian-page)))
1261 (insert (format "(hanyu-dazidian-page . %d)%s"
1262 value line-breaking))
1263 (setq attributes (delq 'hanyu-dazidian-page attributes))
1265 (when (and (memq 'hanyu-dazidian-char attributes)
1266 (setq value (get-char-attribute char 'hanyu-dazidian-char)))
1267 (insert (format "(hanyu-dazidian-char . %d)%s"
1268 value line-breaking))
1269 (setq attributes (delq 'hanyu-dazidian-char attributes))
1272 (dolist (ignored '(composition
1273 ->denotational <-subsumptive ->ucs-unified
1274 ->ideographic-component-forms))
1275 (setq attributes (delq ignored attributes))))
1277 (setq name (car attributes))
1278 (unless (eq (setq value (get-char-attribute char name 'value-is-empty))
1280 (cond ((setq ret (find-charset name))
1281 (setq name (charset-name ret))
1282 (when (not (memq name dest-ccss))
1283 (setq dest-ccss (cons name dest-ccss))
1284 (char-db-insert-ccs-feature name value line-breaking))
1286 ((string-match "^=>ucs@" (symbol-name name))
1287 (insert (format "(%-18s . #x%04X)\t; %c%s"
1288 name value (decode-char '=ucs value)
1291 ((eq name 'jisx0208-1978/4X)
1292 (insert (format "(%-18s . #x%04X)%s"
1298 (not (eq name '->subsumptive))
1299 (not (eq name '->uppercase))
1300 (not (eq name '->lowercase))
1301 (not (eq name '->titlecase))
1302 (not (eq name '->canonical))
1303 (not (eq name '->Bopomofo))
1304 (not (eq name '->mistakable))
1305 (not (eq name '->ideographic-variants))
1306 (null (get-char-attribute
1307 char (intern (format "%s*sources" name))))
1308 (not (string-match "\\*sources$" (symbol-name name)))
1309 (null (get-char-attribute
1310 char (intern (format "%s*note" name))))
1311 (not (string-match "\\*note$" (symbol-name name)))
1312 (or (eq name '<-identical)
1313 (eq name '<-uppercase)
1314 (eq name '<-lowercase)
1315 (eq name '<-titlecase)
1316 (eq name '<-canonical)
1317 (eq name '<-ideographic-variants)
1318 ;; (eq name '<-synonyms)
1319 (string-match "^<-synonyms" (symbol-name name))
1320 (eq name '<-mistakable)
1321 (when (string-match "^->" (symbol-name name))
1323 ((string-match "^->fullwidth" (symbol-name name))
1324 (not (and (consp value)
1325 (characterp (car value))
1327 (car value) '=ucs 'defined-only)))
1332 ((or (eq name 'ideographic-structure)
1333 (eq name 'ideographic-combination)
1334 (eq name 'ideographic-)
1335 (eq name '=decomposition)
1336 (char-feature-base-name= '=decomposition name)
1337 (char-feature-base-name= '=>decomposition name)
1338 ;; (string-match "^=>*decomposition\\(@[^*]+\\)?$"
1339 ;; (symbol-name name))
1340 (string-match "^\\(->\\|<-\\)[^*]*$" (symbol-name name))
1341 (string-match "^\\(->\\|<-\\)[^*]*\\*sources$"
1344 (char-db-insert-relation-feature char name value
1347 ((memq name '(ideograph=
1348 original-ideograph-of
1349 ancient-ideograph-of
1352 ;; simplified-ideograph-of
1353 ideographic-variants
1354 ;; ideographic-different-form-of
1356 (insert (format "(%-18s%s " name line-breaking))
1357 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1359 (while (consp value)
1360 (setq cell (car value))
1361 (if (and (consp cell)
1366 (char-db-insert-alist cell readable)
1367 (setq separator lbs))
1370 (insert (prin1-to-string cell))
1371 (setq separator " "))
1372 (setq value (cdr value)))
1374 (insert line-breaking))
1376 (insert (format "(%-18s " name))
1377 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1379 (while (consp value)
1380 (setq cell (car value))
1381 (if (and (consp cell)
1383 (setq ret (condition-case nil
1391 (setq key (car (car rest)))
1392 (if (find-charset key)
1393 (setq cal (cons key cal))
1394 (setq al (cons key al)))
1395 (setq rest (cdr rest)))
1398 (insert-char-attributes ret
1402 (setq separator lbs))
1403 (setq ret (prin1-to-string cell))
1405 (if (< (+ (current-column)
1412 (setq separator " "))
1413 (setq value (cdr value)))
1415 (insert line-breaking))
1417 (insert (format "(%-18s" name))
1418 (setq ret (prin1-to-string value))
1419 (unless (< (+ (current-column)
1423 (insert line-breaking))
1424 (insert " . " ret ")" line-breaking)
1425 ;; (insert (format "(%-18s . %S)%s"
1430 (setq attributes (cdr attributes)))
1433 (defun insert-char-data (char &optional readable
1436 (narrow-to-region (point)(point))
1437 (insert "(define-char
1439 (insert-char-attributes char readable attributes)
1441 (goto-char (point-min))
1442 (while (re-search-forward "[ \t]+$" nil t)
1445 (goto-char (point-min))
1446 (while (re-search-forward "[ \t][ \t][ \t]*" nil t)
1447 (let ((column (current-column))
1448 (indent-tabs-mode t))
1449 (delete-region (match-beginning 0) (point))
1450 (indent-to column)))
1451 (goto-char (point-max))
1452 ;; (tabify (point-min)(point-max))
1455 (defun insert-char-data-with-variant (char &optional printable
1457 script excluded-script)
1458 (insert-char-data char printable)
1459 (let ((variants (char-variants char))
1462 (setq variants (sort variants #'<))
1463 (setq rest variants)
1464 (setq variants (cons char variants))
1466 (setq variant (car rest))
1467 (unless (get-char-attribute variant '<-subsumptive)
1468 (if (and (or (null script)
1469 (null (setq vs (get-char-attribute variant 'script)))
1471 (or (null excluded-script)
1472 (null (setq vs (get-char-attribute variant 'script)))
1473 (not (memq excluded-script vs))))
1474 (unless (and no-ucs-unified (get-char-attribute variant '=ucs))
1475 (insert-char-data variant printable)
1476 (if (setq ret (char-variants variant))
1478 (or (memq (car ret) variants)
1479 ;; (get-char-attribute (car ret) '<-subsumptive)
1480 (setq rest (nconc rest (list (car ret)))))
1481 (setq ret (cdr ret)))))))
1482 (setq rest (cdr rest)))))
1484 (defun insert-char-range-data (min max &optional script excluded-script)
1487 (while (<= code max)
1488 (setq char (decode-char '=ucs code))
1489 (if (encode-char char '=ucs 'defined-only)
1490 (insert-char-data-with-variant char nil 'no-ucs-unified
1491 script excluded-script))
1492 (setq code (1+ code)))))
1494 (defun write-char-range-data-to-file (min max file
1495 &optional script excluded-script)
1496 (let ((coding-system-for-write char-db-file-coding-system))
1498 (insert (format ";; -*- coding: %s -*-\n"
1499 char-db-file-coding-system))
1500 (insert-char-range-data min max script excluded-script)
1501 (write-region (point-min)(point-max) file))))
1503 (defvar what-character-original-window-configuration)
1506 (defun what-char-definition (char)
1507 (interactive (list (char-after)))
1508 (let ((buf (get-buffer-create "*Character Description*"))
1509 (the-buf (current-buffer))
1510 (win-conf (current-window-configuration)))
1512 (make-local-variable 'what-character-original-window-configuration)
1513 (setq what-character-original-window-configuration win-conf)
1514 (setq buffer-read-only nil)
1518 (insert-char-data-with-variant char 'printable)
1519 (unless (char-attribute-alist char)
1520 (insert (format ";; = %c\n"
1521 (let* ((rest (split-char char))
1525 (setq code (logior (lsh code 8)
1527 (decode-char ccs code)))))
1528 ;; (char-db-update-comment)
1529 (set-buffer-modified-p nil)
1530 (view-mode the-buf (lambda (buf)
1531 (set-window-configuration
1532 what-character-original-window-configuration)
1534 (goto-char (point-min)))
1536 (set-window-configuration
1537 what-character-original-window-configuration)
1538 (signal (car err) (cdr err)))))))
1544 (provide 'char-db-util)
1546 ;;; char-db-util.el ends here