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,2016,2017,2018,2019 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
107 ?夨 ?夭 ?交 ?尣 ?壺 ?壹 ?㚔 ?奢 ?亢 ?夲 ; 400
110 (defun shuowen-radical (number)
111 (aref shuowen-radicals (1- number)))
113 (defvar char-db-file-coding-system 'utf-8-mcs-er)
115 (defvar char-db-ignored-attributes '(ideographic-products))
117 (defvar char-db-coded-charset-priority-list
215 ;; =>>>adobe-japan1-0
216 ;; =>>>adobe-japan1-1
217 ;; =>>>adobe-japan1-2
218 ;; =>>>adobe-japan1-3
219 ;; =>>>adobe-japan1-4
220 ;; =>>>adobe-japan1-5
221 ;; =>>>adobe-japan1-6
225 ;; =>>>hanyo-denshi/ja
226 ;; =>>>hanyo-denshi/jb
227 ;; =>>>hanyo-denshi/jc
228 ;; =>>>hanyo-denshi/ft
229 ;; =>>>hanyo-denshi/ib
230 ;; =>>>hanyo-denshi/hg
231 ;; =>>>hanyo-denshi/jt
232 ;; =>>>hanyo-denshi/ks
273 ;; =>ucs@hanyo-denshi
372 =>big5-cdp-itaiji-001
376 =>ucs-itaiji-001@iwds-1
386 ;;; @ char-db formatters
389 (defun char-db-make-char-spec (char)
391 (cond ((characterp char)
392 (cond ((and (setq ret (encode-char char '=ucs 'defined-only))
393 (not (and (<= #xE000 ret)(<= ret #xF8FF))))
394 (setq char-spec (list (cons '=ucs ret)))
395 (cond ((setq ret (get-char-attribute char 'name))
396 (setq char-spec (cons (cons 'name ret) char-spec))
398 ((setq ret (get-char-attribute char 'name*))
399 (setq char-spec (cons (cons 'name* ret) char-spec))
402 ((encode-char char '=mj 'defined-only)
404 (dolist (ccs (charset-list))
405 (if (and (or (eq ccs '=mj)
406 ;; (eq (charset-property ccs 'iso-ir) 177)
407 (string-match "=ucs@" (symbol-name ccs))
409 (setq ccs (charset-name ccs))
410 (null (assq ccs char-spec))
411 (setq ret (encode-char char ccs 'defined-only)))
412 (setq char-spec (cons (cons ccs ret) char-spec))))
414 ((encode-char char '==mj 'defined-only)
416 (dolist (ccs (charset-list))
417 (if (and (or (eq ccs '==mj)
418 ;; (eq (charset-property ccs 'iso-ir) 177)
419 (string-match "=ucs@" (symbol-name ccs))
421 (setq ccs (charset-name ccs))
422 (null (assq ccs char-spec))
423 (setq ret (encode-char char ccs 'defined-only)))
424 (setq char-spec (cons (cons ccs ret) char-spec))))
426 ((encode-char char '=adobe-japan1 'defined-only)
428 (dolist (ccs (charset-list))
429 (if (and (or (memq ccs
438 ;; (eq (charset-property ccs 'iso-ir) 177)
439 (string-match "=ucs@" (symbol-name ccs))
441 (setq ccs (charset-name ccs))
442 (null (assq ccs char-spec))
443 (setq ret (encode-char char ccs 'defined-only)))
444 (setq char-spec (cons (cons ccs ret) char-spec))))
446 ((encode-char char '==adobe-japan1 'defined-only)
448 (dolist (ccs (charset-list))
449 (if (and (or (memq ccs
458 ;; (eq (charset-property ccs 'iso-ir) 177)
459 (string-match "=ucs@" (symbol-name ccs))
461 (setq ccs (charset-name ccs))
462 (null (assq ccs char-spec))
463 (setq ret (encode-char char ccs 'defined-only)))
464 (setq char-spec (cons (cons ccs ret) char-spec))))
468 (let ((rest char-db-coded-charset-priority-list)
471 (setq ccs (charset-name
472 (find-charset (car rest))))
474 (encode-char char ccs
476 (throw 'tag (cons ccs ret)))
477 (setq rest (cdr rest))))))
478 (setq char-spec (list ret))
479 (dolist (ccs (delq (car ret) (charset-list)))
480 (if (and (or (charset-iso-final-char ccs)
487 (and (eq (charset-property ccs 'iso-ir) 177)
488 (not (eq (charset-name ccs) '=ucs@big5)))
489 ;; (string-match "=ucs@" (symbol-name ccs))
491 (setq ccs (charset-name ccs))
492 (null (assq ccs char-spec))
493 (setq ret (encode-char char ccs 'defined-only)))
494 (setq char-spec (cons (cons ccs ret) char-spec))))
496 (setq char-spec (split-char char)))
497 (cond ((setq ret (get-char-attribute char 'name))
498 (setq char-spec (cons (cons 'name ret) char-spec))
500 ((setq ret (get-char-attribute char 'name*))
501 (setq char-spec (cons (cons 'name* ret) char-spec))
504 ((setq ret (get-char-attribute
505 char 'ideographic-combination))
507 (cons (cons 'ideographic-combination ret)
514 (defun char-db-insert-char-spec (char &optional readable column
517 (setq column (current-column)))
518 (let (char-spec temp-char)
519 (setq char-spec (char-db-make-char-spec char))
520 (unless (or (characterp char) ; char
522 (setq char (find-char char-spec))
524 ;; define temporary character
525 ;; Current implementation is dirty.
526 (setq temp-char (define-char (cons '(ideograph-daikanwa . 0)
528 (remove-char-attribute temp-char 'ideograph-daikanwa)
529 (setq char temp-char))
530 (insert-char-attributes char
532 (union (mapcar #'car char-spec)
536 ;; undefine temporary character
537 ;; Current implementation is dirty.
538 (setq char-spec (char-attribute-alist temp-char))
540 (remove-char-attribute temp-char (car (car char-spec)))
541 (setq char-spec (cdr char-spec))))))
543 (defun char-db-insert-alist (alist &optional readable column)
545 (setq column (current-column)))
547 (concat "\n" (make-string (1+ column) ?\ )))
551 lbs cell rest separator)
554 (setq name (car (car alist))
555 value (cdr (car alist)))
556 (cond ((eq name 'char)
558 (if (setq ret (condition-case nil
566 (setq key (car (car value)))
567 ;; (if (find-charset key)
568 ;; (setq cal (cons key cal))
569 (setq al (cons key al))
571 (setq value (cdr value)))
572 (insert-char-attributes ret
576 (insert (prin1-to-string value)))
578 (insert line-breaking))
580 (insert (format "(%-18s " name))
581 (setq lbs (concat "\n" (make-string (current-column) ?\ )))
583 (setq cell (car value))
584 (if (and (consp cell)
586 (setq ret (condition-case nil
596 (setq key (car (car rest)))
597 ;; (if (find-charset key)
598 ;; (setq cal (cons key cal))
599 (setq al (cons key al))
601 (setq rest (cdr rest)))
604 (insert-char-attributes ret
608 (setq separator lbs))
611 (insert (prin1-to-string cell))
612 (setq separator " "))
613 (setq value (cdr value)))
615 (insert line-breaking))
617 (insert (format "(%-18s . %S)%s"
620 (setq alist (cdr alist))))
623 (defun char-db-insert-char-reference (plist &optional readable column)
625 (setq column (current-column)))
627 (concat "\n" (make-string (1+ column) ?\ )))
632 (setq name (pop plist))
633 (setq value (pop plist))
634 (cond ((eq name :char)
637 (cond ((numberp value)
638 (setq value (decode-char '=ucs value)))
640 ;; (setq value (or (find-char value)
643 (char-db-insert-char-spec value readable)
644 (insert line-breaking)
647 (insert (format "%s%s\t%d ; %c%s"
650 (ideographic-radical value)
654 (insert (format "%s%s\t%S" separator name value))
655 (setq separator line-breaking)))
659 (defun char-db-decode-isolated-char (ccs code-point)
662 (cond ((eq ccs 'arabic-iso8859-6)
663 (decode-char ccs code-point))
665 ;; (decode-builtin-char '==gt code-point))
666 ((and (memq ccs '(=gt-pj-1
677 (setq ret (decode-char ccs code-point))
678 (setq ret (encode-char ret '=gt 'defined-only)))
679 (decode-builtin-char '=gt ret))
681 (decode-builtin-char ccs code-point))))
683 (or (decode-char ccs code-point)
684 (define-char (list (cons ccs code-point)))))
685 ((and (<= 0 (char-int ret))
686 (<= (char-int ret) #x1F))
687 (decode-char '=ucs (+ #x2400 (char-int ret))))
688 ((= (char-int ret) #x7F)
692 (defvar char-db-convert-obsolete-format t)
694 (defun char-db-insert-ccs-feature (name value line-breaking)
700 ((memq name '(=>iwds-1
703 =shinjigen@1ed ==shinjigen@1ed
704 =shinjigen@rev ==shinjigen@rev
705 =shinjigen/+p@rev ==shinjigen/+p@rev
706 ===daikanwa/ho ==daikanwa/ho
707 =daikanwa/ho =>>daikanwa/ho =>daikanwa/ho))
708 "(%-18s . %04d)\t; %c")
709 ((eq name '=shinjigen@1ed/24pr)
710 "(%-18s . %04d)\t; %c")
714 ==daikanwa =daikanwa =>>daikanwa =>daikanwa
715 =daikanwa@rev1 =daikanwa@rev2
716 =daikanwa/+p ==daikanwa/+p ===daikanwa/+p
718 =daikanwa/+2p =>>daikanwa/+2p
723 =adobe-japan1-0 ==adobe-japan1-0 ===adobe-japan1-0
724 =adobe-japan1-1 ==adobe-japan1-1 ===adobe-japan1-1
725 =adobe-japan1-2 ==adobe-japan1-2 ===adobe-japan1-2
726 =adobe-japan1-3 ==adobe-japan1-3 ===adobe-japan1-3
727 =adobe-japan1-4 ==adobe-japan1-4 ===adobe-japan1-4
728 =adobe-japan1-5 ==adobe-japan1-5 ===adobe-japan1-5
729 =adobe-japan1-6 ==adobe-japan1-6 ===adobe-japan1-6
730 =>>adobe-japan1-0 =+>adobe-japan1-0
731 =>>adobe-japan1-1 =+>adobe-japan1-1
732 =>>adobe-japan1-2 =+>adobe-japan1-2
733 =>>adobe-japan1-3 =+>adobe-japan1-3
734 =>>adobe-japan1-4 =+>adobe-japan1-4
735 =>>adobe-japan1-5 =+>adobe-japan1-5
736 =>>adobe-japan1-6 =+>adobe-japan1-6
737 =>cbeta =cbeta =>>cbeta ==cbeta ===cbeta
738 =zinbun-oracle =>zinbun-oracle
739 =daijiten ==daijiten ===daijiten ==>daijiten
740 ===hng-jou ===hng-keg ===hng-dng ===hng-mam
741 ===hng-drt ===hng-kgk ===hng-myz ===hng-kda
742 ===hng-khi ===hng-khm ===hng-fhs ===hng-hok
743 ===hng-kyd ===hng-sok
744 ===hng-yhk ===hng-kak ===hng-kar ===hng-kae
745 ===hng-sys ===hng-tsu ===hng-tzj
746 ===hng-hos ===hng-nak ===hng-jhk
747 ===hng-hod ===hng-gok ===hng-ink ===hng-nto
748 ===hng-nkm ===hng-k24 ===hng-nkk
749 ===hng-kcc ===hng-kcj ===hng-kbk ===hng-sik
750 ===hng-skk ===hng-kyu ===hng-ksk ===hng-wan
751 ===hng-okd ===hng-wad ===hng-kmi
752 ===hng-zkd ===hng-doh ===hng-jyu
753 ===hng-tzs ===hng-kss ===hng-kyo
755 =shuowen-jiguge ===shuowen-jiguge4 ===shuowen-jiguge5))
756 ;; (string-match "^=adobe-" (symbol-name name))
758 "(%-18s . %05d)\t; %c")
759 ((memq name '(=hanyo-denshi/ks
760 ==hanyo-denshi/ks ===hanyo-denshi/ks
763 =mj ==mj ===mj =>>mj =>mj
765 "(%-18s . %06d)\t; %c")
766 ((memq name '(=hanyo-denshi/tk ==hanyo-denshi/tk))
767 "(%-18s . %08d)\t; %c")
768 ((>= (charset-dimension name) 2)
769 "(%-18s . #x%04X)\t; %c")
771 "(%-18s . #x%02X)\t; %c"))
773 (if (= (charset-iso-graphic-plane name) 1)
775 (cond ((= (charset-dimension name) 1)
777 ((= (charset-dimension name) 2)
779 ((= (charset-dimension name) 3)
783 (char-db-decode-isolated-char name value)))
784 (if (and (= (charset-chars name) 94)
785 (= (charset-dimension name) 2))
786 (insert (format " [%02d-%02d]"
787 (- (lsh value -8) 32)
788 (- (logand value 255) 32))))
791 (insert (format "(%-18s . %s)" name value))
793 (insert line-breaking))
795 (defun char-db-insert-relation-feature (char name value line-breaking
797 (insert (format "(%-18s%s " name line-breaking))
798 (let ((lbs (concat "\n" (make-string (current-column) ?\ )))
799 separator cell sources required-features
802 (setq cell (car value))
804 (setq cell (decode-char '=ucs cell)))
806 ((eq name '->subsumptive)
807 (when (or (not (some (lambda (atr)
808 (get-char-attribute cell atr))
809 char-db-ignored-attributes))
811 (encode-char cell ccs 'defined-only))
815 (let ((char-db-ignored-attributes
817 char-db-ignored-attributes)))
818 (insert-char-attributes cell readable nil nil 'for-sub-node))
819 (setq separator lbs))
824 char (intern (format "%s*sources" name))))
825 (setq required-features nil)
826 (dolist (source sources)
830 shinjigen shinjigen@1ed shinjigen@rev))
831 (setq required-features
832 (union required-features
844 =shinjigen/+p@rev))))
846 (setq required-features
847 (union required-features
852 ((find-charset (setq ret (intern (format "=%s" source))))
853 (setq required-features
854 (cons ret required-features)))
855 (t (setq required-features
856 (cons source required-features)))))
857 (cond ((string-match "@JP" (symbol-name name))
858 (setq required-features
859 (union required-features
867 ((string-match "@CN" (symbol-name name))
868 (setq required-features
869 (union required-features
876 (insert (format "%S" cell))
877 (char-db-insert-char-spec cell readable
880 (setq separator lbs))
884 (if (consp (car cell))
885 (char-db-insert-char-spec cell readable)
886 (char-db-insert-char-reference cell readable))
887 (setq separator lbs))
891 (insert (prin1-to-string cell))
892 (setq separator " ")))
893 (setq value (cdr value)))
895 (insert line-breaking)))
897 (defun insert-char-attributes (char &optional readable attributes column
900 (setq column (current-column)))
901 (let (name value ; has-long-ccs-name
905 (concat "\n" (make-string (1+ column) ?\ )))
906 lbs cell separator ret
908 dest-ccss ; sources required-features
913 (if (consp attributes)
915 (dolist (name attributes)
916 (unless (memq name char-db-ignored-attributes)
917 (if (find-charset name)
921 (dolist (name (char-attribute-list))
922 (unless (memq name char-db-ignored-attributes)
923 (if (find-charset name)
927 #'char-attribute-name<)))
929 (when (memq '<-subsumptive attributes)
930 (when (or readable (not for-sub-node))
931 (when (setq value (get-char-attribute char '<-subsumptive))
932 (char-db-insert-relation-feature char '<-subsumptive value
935 (setq attributes (delq '<-subsumptive attributes)))
936 (when (and (memq '<-denotational attributes)
937 (setq value (get-char-attribute char '<-denotational)))
938 (char-db-insert-relation-feature char '<-denotational value
941 (setq attributes (delq '<-denotational attributes)))
942 (when (and (memq '<-denotational@component attributes)
943 (setq value (get-char-attribute char '<-denotational@component)))
944 (char-db-insert-relation-feature char '<-denotational@component value
947 (setq attributes (delq '<-denotational@component attributes)))
948 (when (and (memq '<-denotational@usage attributes)
949 (setq value (get-char-attribute char '<-denotational@usage)))
950 (char-db-insert-relation-feature char '<-denotational@usage value
953 (setq attributes (delq '<-denotational@usage attributes)))
954 (when (and (memq 'name attributes)
955 (setq value (get-char-attribute char 'name)))
957 (if (> (+ (current-column) (length value)) 48)
960 value line-breaking))
961 (setq attributes (delq 'name attributes))
963 (when (and (memq 'name* attributes)
964 (setq value (get-char-attribute char 'name*)))
966 (if (> (+ (current-column) (length value)) 48)
969 value line-breaking))
970 (setq attributes (delq 'name* attributes))
972 (when (and (memq 'script attributes)
973 (setq value (get-char-attribute char 'script)))
974 (insert (format "(script\t\t%s)%s"
975 (mapconcat (function prin1-to-string)
978 (setq attributes (delq 'script attributes))
980 (dolist (name '(=>ucs =>ucs*))
981 (when (and (memq name attributes)
982 (setq value (get-char-attribute char name)))
983 (insert (format "(%-18s . #x%04X)\t; %c%s"
984 name value (decode-char '=ucs value)
986 (setq attributes (delq name attributes))))
987 (dolist (name '(=>ucs@gb =>ucs@big5))
988 (when (and (memq name attributes)
989 (setq value (get-char-attribute char name)))
990 (insert (format "(%-18s . #x%04X)\t; %c%s"
995 (symbol-name name) 2)))
998 (setq attributes (delq name attributes))
1000 ;; (dolist (name '(=>daikanwa))
1001 ;; (when (and (memq name attributes)
1002 ;; (setq value (get-char-attribute char name)))
1004 ;; (if (integerp value)
1005 ;; (format "(%-18s . %05d)\t; %c%s"
1006 ;; name value (decode-char '=daikanwa value)
1008 ;; (format "(%-18s %s)\t; %c%s"
1010 ;; (mapconcat (function prin1-to-string)
1012 ;; (char-representative-of-daikanwa char)
1014 ;; (setq attributes (delq name attributes))))
1015 (when (and (memq 'general-category attributes)
1016 (setq value (get-char-attribute char 'general-category)))
1018 "(general-category\t%s) ; %s%s"
1019 (mapconcat (lambda (cell)
1022 (cond ((rassoc value unidata-normative-category-alist)
1023 "Normative Category")
1024 ((rassoc value unidata-informative-category-alist)
1025 "Informative Category")
1027 "Unknown Category"))
1029 (setq attributes (delq 'general-category attributes))
1031 (when (and (memq 'bidi-category attributes)
1032 (setq value (get-char-attribute char 'bidi-category)))
1033 (insert (format "(bidi-category\t. %S)%s"
1036 (setq attributes (delq 'bidi-category attributes))
1038 (unless (or (not (memq 'mirrored attributes))
1039 (eq (setq value (get-char-attribute char 'mirrored 'empty))
1041 (insert (format "(mirrored\t\t. %S)%s"
1044 (setq attributes (delq 'mirrored attributes))
1047 ((and (memq 'decimal-digit-value attributes)
1048 (setq value (get-char-attribute char 'decimal-digit-value)))
1049 (insert (format "(decimal-digit-value . %S)%s"
1052 (setq attributes (delq 'decimal-digit-value attributes))
1053 (when (and (memq 'digit-value attributes)
1054 (setq value (get-char-attribute char 'digit-value)))
1055 (insert (format "(digit-value\t . %S)%s"
1058 (setq attributes (delq 'digit-value attributes))
1060 (when (and (memq 'numeric-value attributes)
1061 (setq value (get-char-attribute char 'numeric-value)))
1062 (insert (format "(numeric-value\t . %S)%s"
1065 (setq attributes (delq 'numeric-value attributes))
1069 (when (and (memq 'digit-value attributes)
1070 (setq value (get-char-attribute char 'digit-value)))
1071 (insert (format "(digit-value\t. %S)%s"
1074 (setq attributes (delq 'digit-value attributes))
1076 (when (and (memq 'numeric-value attributes)
1077 (setq value (get-char-attribute char 'numeric-value)))
1078 (insert (format "(numeric-value\t. %S)%s"
1081 (setq attributes (delq 'numeric-value attributes))
1083 (when (and (memq 'iso-10646-comment attributes)
1084 (setq value (get-char-attribute char 'iso-10646-comment)))
1085 (insert (format "(iso-10646-comment\t. %S)%s"
1088 (setq attributes (delq 'iso-10646-comment attributes))
1090 (when (and (memq 'morohashi-daikanwa attributes)
1091 (setq value (get-char-attribute char 'morohashi-daikanwa)))
1092 (insert (format "(morohashi-daikanwa\t%s)%s"
1093 (mapconcat (function prin1-to-string) value " ")
1095 (setq attributes (delq 'morohashi-daikanwa attributes))
1099 (when (and (memq 'ideographic-radical attributes)
1100 (setq value (get-char-attribute char 'ideographic-radical)))
1101 (setq radical value)
1102 (insert (format "(ideographic-radical . %S)\t; %c%s"
1104 (ideographic-radical radical)
1106 (setq attributes (delq 'ideographic-radical attributes))
1108 (when (and (memq 'shuowen-radical attributes)
1109 (setq value (get-char-attribute char 'shuowen-radical)))
1110 (insert (format "(shuowen-radical\t. %S)\t; %c%s"
1112 (shuowen-radical value)
1114 (setq attributes (delq 'shuowen-radical attributes))
1119 char-db-feature-domains
1121 (dolist (feature (char-attribute-list))
1122 (setq feature (symbol-name feature))
1124 "\\(radical\\|strokes\\)@\\([^@*]+\\)\\(\\*\\|$\\)"
1126 (setq domain (intern (match-string 2 feature)))
1127 (unless (memq domain dest)
1128 (setq dest (cons domain dest)))))
1129 (sort dest #'string<))))
1130 (setq key (intern (format "%s@%s" 'ideographic-radical domain)))
1131 (when (and (memq key attributes)
1132 (setq value (get-char-attribute char key)))
1133 (setq radical value)
1134 (insert (format "(%s . %S)\t; %c%s"
1137 (ideographic-radical radical)
1139 (setq attributes (delq key attributes))
1141 (setq key (intern (format "%s@%s" 'ideographic-strokes domain)))
1142 (when (and (memq key attributes)
1143 (setq value (get-char-attribute char key)))
1144 (setq strokes value)
1145 (insert (format "(%s . %S)%s"
1149 (setq attributes (delq key attributes))
1151 (setq key (intern (format "%s@%s" 'total-strokes domain)))
1152 (when (and (memq key attributes)
1153 (setq value (get-char-attribute char key)))
1154 (insert (format "(%s . %S)%s"
1158 (setq attributes (delq key attributes))
1160 (dolist (feature '(ideographic-radical
1163 (setq key (intern (format "%s@%s*sources" feature domain)))
1164 (when (and (memq key attributes)
1165 (setq value (get-char-attribute char key)))
1166 (insert (format "(%s%s" key line-breaking))
1167 (dolist (cell value)
1168 (insert (format " %s" cell)))
1170 (insert line-breaking)
1171 (setq attributes (delq key attributes))
1174 (when (and (memq 'ideographic-strokes attributes)
1175 (setq value (get-char-attribute char 'ideographic-strokes)))
1176 (setq strokes value)
1177 (insert (format "(ideographic-strokes . %S)%s"
1180 (setq attributes (delq 'ideographic-strokes attributes))
1182 (when (and (memq 'kangxi-radical attributes)
1183 (setq value (get-char-attribute char 'kangxi-radical)))
1184 (unless (eq value radical)
1185 (insert (format "(kangxi-radical\t . %S)\t; %c%s"
1187 (ideographic-radical value)
1190 (setq radical value)))
1191 (setq attributes (delq 'kangxi-radical attributes))
1193 (when (and (memq 'kangxi-strokes attributes)
1194 (setq value (get-char-attribute char 'kangxi-strokes)))
1195 (unless (eq value strokes)
1196 (insert (format "(kangxi-strokes\t . %S)%s"
1200 (setq strokes value)))
1201 (setq attributes (delq 'kangxi-strokes attributes))
1203 ;; (when (and (memq 'japanese-radical attributes)
1204 ;; (setq value (get-char-attribute char 'japanese-radical)))
1205 ;; (unless (eq value radical)
1206 ;; (insert (format "(japanese-radical\t . %S)\t; %c%s"
1208 ;; (ideographic-radical value)
1211 ;; (setq radical value)))
1212 ;; (setq attributes (delq 'japanese-radical attributes))
1214 (when (and (memq 'japanese-strokes attributes)
1215 (setq value (get-char-attribute char 'japanese-strokes)))
1216 (unless (eq value strokes)
1217 (insert (format "(japanese-strokes\t . %S)%s"
1221 (setq strokes value)))
1222 (setq attributes (delq 'japanese-strokes attributes))
1224 (when (and (memq 'cns-radical attributes)
1225 (setq value (get-char-attribute char 'cns-radical)))
1226 (insert (format "(cns-radical\t . %S)\t; %c%s"
1228 (ideographic-radical value)
1230 (setq attributes (delq 'cns-radical attributes))
1232 (when (and (memq 'cns-strokes attributes)
1233 (setq value (get-char-attribute char 'cns-strokes)))
1234 (unless (eq value strokes)
1235 (insert (format "(cns-strokes\t . %S)%s"
1239 (setq strokes value)))
1240 (setq attributes (delq 'cns-strokes attributes))
1242 ;; (when (and (memq 'ideographic- attributes)
1243 ;; (setq value (get-char-attribute char 'ideographic-)))
1244 ;; (insert "(ideographic- ")
1245 ;; (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1247 ;; (while (consp value)
1248 ;; (setq cell (car value))
1249 ;; (if (integerp cell)
1250 ;; (setq cell (decode-char '=ucs cell)))
1251 ;; (cond ((characterp cell)
1255 ;; (insert (format "%S" cell))
1256 ;; (char-db-insert-char-spec cell readable))
1257 ;; (setq separator lbs))
1261 ;; (if (consp (car cell))
1262 ;; (char-db-insert-char-spec cell readable)
1263 ;; (char-db-insert-char-reference cell readable))
1264 ;; (setq separator lbs))
1267 ;; (insert separator))
1268 ;; (insert (prin1-to-string cell))
1269 ;; (setq separator " ")))
1270 ;; (setq value (cdr value)))
1272 ;; (insert line-breaking)
1273 ;; (setq attributes (delq 'ideographic- attributes)))
1274 (when (and (memq 'total-strokes attributes)
1275 (setq value (get-char-attribute char 'total-strokes)))
1276 (insert (format "(total-strokes . %S)%s"
1279 (setq attributes (delq 'total-strokes attributes))
1281 ;; (when (and (memq '->ideograph attributes)
1282 ;; (setq value (get-char-attribute char '->ideograph)))
1283 ;; (insert (format "(->ideograph\t%s)%s"
1284 ;; (mapconcat (lambda (code)
1285 ;; (cond ((symbolp code)
1286 ;; (symbol-name code))
1288 ;; (format "#x%04X" code))
1291 ;; line-breaking code))))
1294 ;; (setq attributes (delq '->ideograph attributes))
1296 ;; (when (and (memq '->decomposition attributes)
1297 ;; (setq value (get-char-attribute char '->decomposition)))
1298 ;; (insert (format "(->decomposition\t%s)%s"
1299 ;; (mapconcat (lambda (code)
1300 ;; (cond ((symbolp code)
1301 ;; (symbol-name code))
1302 ;; ((characterp code)
1304 ;; (format "%S" code)
1309 ;; (format "#x%04X" code))
1311 ;; (format "%s%S" line-breaking code))))
1314 ;; (setq attributes (delq '->decomposition attributes))
1316 (if (equal (get-char-attribute char '->titlecase)
1317 (get-char-attribute char '->uppercase))
1318 (setq attributes (delq '->titlecase attributes)))
1319 (when (and (memq '->mojikyo attributes)
1320 (setq value (get-char-attribute char '->mojikyo)))
1321 (insert (format "(->mojikyo\t\t. %06d)\t; %c%s"
1322 value (decode-char 'mojikyo value)
1324 (setq attributes (delq '->mojikyo attributes))
1327 (dolist (ignored '(composition
1328 ->denotational <-subsumptive ->ucs-unified
1329 ;; ->ideographic-component-forms
1331 (setq attributes (delq ignored attributes))))
1333 (setq name (car attributes))
1334 (unless (eq (setq value (get-char-attribute char name 'value-is-empty))
1336 (cond ((setq ret (find-charset name))
1337 (setq name (charset-name ret))
1338 (when (not (memq name dest-ccss))
1339 (setq dest-ccss (cons name dest-ccss))
1340 (char-db-insert-ccs-feature name value line-breaking))
1342 ((string-match "^=>ucs@" (symbol-name name))
1343 (insert (format "(%-18s . #x%04X)\t; %c%s"
1344 name value (decode-char '=ucs value)
1347 ((eq name 'jisx0208-1978/4X)
1348 (insert (format "(%-18s . #x%04X)%s"
1354 (not (eq name '->subsumptive))
1355 (not (eq name '->uppercase))
1356 (not (eq name '->lowercase))
1357 (not (eq name '->titlecase))
1358 (not (eq name '->canonical))
1359 (not (eq name '->Bopomofo))
1360 (not (eq name '->mistakable))
1361 (not (eq name '->ideographic-variants))
1362 (null (get-char-attribute
1363 char (intern (format "%s*sources" name))))
1364 (not (string-match "\\*sources$" (symbol-name name)))
1365 (null (get-char-attribute
1366 char (intern (format "%s*note" name))))
1367 (not (string-match "\\*note$" (symbol-name name)))
1368 (or (eq name '<-identical)
1369 (eq name '<-uppercase)
1370 (eq name '<-lowercase)
1371 (eq name '<-titlecase)
1372 (eq name '<-canonical)
1373 (eq name '<-ideographic-variants)
1374 ;; (eq name '<-synonyms)
1375 (string-match "^<-synonyms" (symbol-name name))
1376 (eq name '<-mistakable)
1377 (when (string-match "^->" (symbol-name name))
1379 ((string-match "^->fullwidth" (symbol-name name))
1380 (not (and (consp value)
1381 (characterp (car value))
1383 (car value) '=ucs 'defined-only)))
1388 ((or (eq name 'ideographic-structure)
1389 (eq name 'ideographic-combination)
1390 ;; (eq name 'ideographic-)
1391 (eq name '=decomposition)
1392 (char-feature-base-name= '=decomposition name)
1393 (char-feature-base-name= '=>decomposition name)
1394 ;; (string-match "^=>*decomposition\\(@[^*]+\\)?$"
1395 ;; (symbol-name name))
1396 (string-match "^\\(->\\|<-\\)[^*]*$" (symbol-name name))
1397 (string-match "^\\(->\\|<-\\)[^*]*\\*sources$"
1400 (char-db-insert-relation-feature char name value
1403 ;; ((memq name '(ideograph=
1404 ;; original-ideograph-of
1405 ;; ancient-ideograph-of
1406 ;; vulgar-ideograph-of
1407 ;; wrong-ideograph-of
1408 ;; ;; simplified-ideograph-of
1409 ;; ideographic-variants
1410 ;; ;; ideographic-different-form-of
1412 ;; (insert (format "(%-18s%s " name line-breaking))
1413 ;; (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1415 ;; (while (consp value)
1416 ;; (setq cell (car value))
1417 ;; (if (and (consp cell)
1418 ;; (consp (car cell)))
1422 ;; (char-db-insert-alist cell readable)
1423 ;; (setq separator lbs))
1425 ;; (insert separator))
1426 ;; (insert (prin1-to-string cell))
1427 ;; (setq separator " "))
1428 ;; (setq value (cdr value)))
1430 ;; (insert line-breaking))
1432 (insert (format "(%-18s " name))
1433 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1435 (while (consp value)
1436 (setq cell (car value))
1437 (if (and (consp cell)
1439 (setq ret (condition-case nil
1447 (setq key (car (car rest)))
1448 (if (find-charset key)
1449 (setq cal (cons key cal))
1450 (setq al (cons key al)))
1451 (setq rest (cdr rest)))
1454 (insert-char-attributes ret
1458 (setq separator lbs))
1459 (setq ret (prin1-to-string cell))
1461 (if (< (+ (current-column)
1468 (setq separator " "))
1469 (setq value (cdr value)))
1471 (insert line-breaking))
1473 (insert (format "(%-18s" name))
1474 (setq ret (prin1-to-string value))
1475 (unless (< (+ (current-column)
1479 (insert line-breaking))
1480 (insert " . " ret ")" line-breaking)
1481 ;; (insert (format "(%-18s . %S)%s"
1486 (setq attributes (cdr attributes)))
1489 (defun insert-char-data (char &optional readable
1492 (narrow-to-region (point)(point))
1493 (insert "(define-char
1495 (insert-char-attributes char readable attributes)
1497 (goto-char (point-min))
1498 (while (re-search-forward "[ \t]+$" nil t)
1501 (goto-char (point-min))
1502 (while (re-search-forward "[ \t][ \t][ \t]*" nil t)
1503 (let ((column (current-column))
1504 (indent-tabs-mode t))
1505 (delete-region (match-beginning 0) (point))
1506 (indent-to column)))
1507 (goto-char (point-max))
1508 ;; (tabify (point-min)(point-max))
1511 (defun insert-char-data-with-variant (char &optional printable
1513 script excluded-script)
1514 (insert-char-data char printable)
1515 (let ((variants (char-variants char))
1518 (setq variants (sort variants #'<))
1519 (setq rest variants)
1520 (setq variants (cons char variants))
1522 (setq variant (car rest))
1523 (unless (get-char-attribute variant '<-subsumptive)
1524 (if (and (or (null script)
1525 (null (setq vs (get-char-attribute variant 'script)))
1527 (or (null excluded-script)
1528 (null (setq vs (get-char-attribute variant 'script)))
1529 (not (memq excluded-script vs))))
1530 (unless (and no-ucs-unified (get-char-attribute variant '=ucs))
1531 (insert-char-data variant printable)
1532 (if (setq ret (char-variants variant))
1534 (or (memq (car ret) variants)
1535 ;; (get-char-attribute (car ret) '<-subsumptive)
1536 (setq rest (nconc rest (list (car ret)))))
1537 (setq ret (cdr ret)))))))
1538 (setq rest (cdr rest)))))
1540 (defun insert-char-range-data (min max &optional script excluded-script)
1543 (while (<= code max)
1544 (setq char (decode-char '=ucs code))
1545 (if (encode-char char '=ucs 'defined-only)
1546 (insert-char-data-with-variant char nil 'no-ucs-unified
1547 script excluded-script))
1548 (setq code (1+ code)))))
1550 (defun write-char-range-data-to-file (min max file
1551 &optional script excluded-script)
1552 (let ((coding-system-for-write char-db-file-coding-system))
1554 (insert (format ";; -*- coding: %s -*-\n"
1555 char-db-file-coding-system))
1556 (insert-char-range-data min max script excluded-script)
1557 (write-region (point-min)(point-max) file))))
1559 (defvar what-character-original-window-configuration)
1562 (defun what-char-definition (char)
1563 (interactive (list (char-after)))
1564 (let ((buf (get-buffer-create "*Character Description*"))
1565 (the-buf (current-buffer))
1566 (win-conf (current-window-configuration)))
1568 (make-local-variable 'what-character-original-window-configuration)
1569 (setq what-character-original-window-configuration win-conf)
1570 (setq buffer-read-only nil)
1574 (insert-char-data-with-variant char 'printable)
1575 (unless (char-attribute-alist char)
1576 (insert (format ";; = %c\n"
1577 (let* ((rest (split-char char))
1581 (setq code (logior (lsh code 8)
1583 (decode-char ccs code)))))
1584 ;; (char-db-update-comment)
1585 (set-buffer-modified-p nil)
1586 (view-mode the-buf (lambda (buf)
1587 (set-window-configuration
1588 what-character-original-window-configuration)
1590 (goto-char (point-min)))
1592 (set-window-configuration
1593 what-character-original-window-configuration)
1594 (signal (car err) (cdr err)))))))
1600 (provide 'char-db-util)
1602 ;;; char-db-util.el ends here