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
217 ;; =>>>adobe-japan1-0
218 ;; =>>>adobe-japan1-1
219 ;; =>>>adobe-japan1-2
220 ;; =>>>adobe-japan1-3
221 ;; =>>>adobe-japan1-4
222 ;; =>>>adobe-japan1-5
223 ;; =>>>adobe-japan1-6
227 ;; =>>>hanyo-denshi/ja
228 ;; =>>>hanyo-denshi/jb
229 ;; =>>>hanyo-denshi/jc
230 ;; =>>>hanyo-denshi/ft
231 ;; =>>>hanyo-denshi/ib
232 ;; =>>>hanyo-denshi/hg
233 ;; =>>>hanyo-denshi/jt
234 ;; =>>>hanyo-denshi/ks
275 ;; =>ucs@hanyo-denshi
378 =>big5-cdp-itaiji-001
379 =>big5-cdp-itaiji-003
384 =>ucs@iwds-1/normalized
385 =>ucs-itaiji-001@iwds-1
386 =>ucs-itaiji-002@iwds-1
396 ;;; @ char-db formatters
399 (defun char-db-make-char-spec (char)
401 (cond ((characterp char)
402 (cond ((and (setq ret (encode-char char '=ucs 'defined-only))
403 (not (and (<= #xE000 ret)(<= ret #xF8FF))))
404 (setq char-spec (list (cons '=ucs ret)))
405 (cond ((setq ret (get-char-attribute char 'name))
406 (setq char-spec (cons (cons 'name ret) char-spec))
408 ((setq ret (get-char-attribute char 'name*))
409 (setq char-spec (cons (cons 'name* ret) char-spec))
412 ((encode-char char '=mj 'defined-only)
414 (dolist (ccs (charset-list))
415 (if (and (or (eq ccs '=mj)
416 ;; (eq (charset-property ccs 'iso-ir) 177)
417 (string-match "=ucs@" (symbol-name ccs))
419 (setq ccs (charset-name ccs))
420 (null (assq ccs char-spec))
421 (setq ret (encode-char char ccs 'defined-only)))
422 (setq char-spec (cons (cons ccs ret) char-spec))))
424 ((encode-char char '==mj 'defined-only)
426 (dolist (ccs (charset-list))
427 (if (and (or (eq ccs '==mj)
428 ;; (eq (charset-property ccs 'iso-ir) 177)
429 (string-match "=ucs@" (symbol-name ccs))
431 (setq ccs (charset-name ccs))
432 (null (assq ccs char-spec))
433 (setq ret (encode-char char ccs 'defined-only)))
434 (setq char-spec (cons (cons ccs ret) char-spec))))
436 ((encode-char char '=adobe-japan1 'defined-only)
438 (dolist (ccs (charset-list))
439 (if (and (or (memq ccs
448 ;; (eq (charset-property ccs 'iso-ir) 177)
449 (string-match "=ucs@" (symbol-name ccs))
451 (setq ccs (charset-name ccs))
452 (null (assq ccs char-spec))
453 (setq ret (encode-char char ccs 'defined-only)))
454 (setq char-spec (cons (cons ccs ret) char-spec))))
456 ((encode-char char '==adobe-japan1 'defined-only)
458 (dolist (ccs (charset-list))
459 (if (and (or (memq ccs
468 ;; (eq (charset-property ccs 'iso-ir) 177)
469 (string-match "=ucs@" (symbol-name ccs))
471 (setq ccs (charset-name ccs))
472 (null (assq ccs char-spec))
473 (setq ret (encode-char char ccs 'defined-only)))
474 (setq char-spec (cons (cons ccs ret) char-spec))))
478 (let ((rest char-db-coded-charset-priority-list)
481 (setq ccs (charset-name
482 (find-charset (car rest))))
484 (encode-char char ccs
486 (throw 'tag (cons ccs ret)))
487 (setq rest (cdr rest))))))
488 (setq char-spec (list ret))
489 (dolist (ccs (delq (car ret) (charset-list)))
490 (if (and (or (charset-iso-final-char ccs)
497 (and (eq (charset-property ccs 'iso-ir) 177)
498 (not (eq (charset-name ccs) '=ucs@big5)))
499 ;; (string-match "=ucs@" (symbol-name ccs))
501 (setq ccs (charset-name ccs))
502 (null (assq ccs char-spec))
503 (setq ret (encode-char char ccs 'defined-only)))
504 (setq char-spec (cons (cons ccs ret) char-spec))))
506 (setq char-spec (split-char char)))
507 (cond ((setq ret (get-char-attribute char 'name))
508 (setq char-spec (cons (cons 'name ret) char-spec))
510 ((setq ret (get-char-attribute char 'name*))
511 (setq char-spec (cons (cons 'name* ret) char-spec))
514 ((setq ret (get-char-attribute
515 char 'ideographic-combination))
517 (cons (cons 'ideographic-combination ret)
524 (defun char-db-insert-char-spec (char &optional readable column
527 (setq column (current-column)))
528 (let (char-spec temp-char)
529 (setq char-spec (char-db-make-char-spec char))
530 (unless (or (characterp char) ; char
532 (setq char (find-char char-spec))
534 ;; define temporary character
535 ;; Current implementation is dirty.
536 (setq temp-char (define-char (cons '(ideograph-daikanwa . 0)
538 (remove-char-attribute temp-char 'ideograph-daikanwa)
539 (setq char temp-char))
540 (insert-char-attributes char
542 (union (mapcar #'car char-spec)
546 ;; undefine temporary character
547 ;; Current implementation is dirty.
548 (setq char-spec (char-attribute-alist temp-char))
550 (remove-char-attribute temp-char (car (car char-spec)))
551 (setq char-spec (cdr char-spec))))))
553 (defun char-db-insert-alist (alist &optional readable column)
555 (setq column (current-column)))
557 (concat "\n" (make-string (1+ column) ?\ )))
561 lbs cell rest separator)
564 (setq name (car (car alist))
565 value (cdr (car alist)))
566 (cond ((eq name 'char)
568 (if (setq ret (condition-case nil
576 (setq key (car (car value)))
577 ;; (if (find-charset key)
578 ;; (setq cal (cons key cal))
579 (setq al (cons key al))
581 (setq value (cdr value)))
582 (insert-char-attributes ret
586 (insert (prin1-to-string value)))
588 (insert line-breaking))
590 (insert (format "(%-18s " name))
591 (setq lbs (concat "\n" (make-string (current-column) ?\ )))
593 (setq cell (car value))
594 (if (and (consp cell)
596 (setq ret (condition-case nil
606 (setq key (car (car rest)))
607 ;; (if (find-charset key)
608 ;; (setq cal (cons key cal))
609 (setq al (cons key al))
611 (setq rest (cdr rest)))
614 (insert-char-attributes ret
618 (setq separator lbs))
621 (insert (prin1-to-string cell))
622 (setq separator " "))
623 (setq value (cdr value)))
625 (insert line-breaking))
627 (insert (format "(%-18s . %S)%s"
630 (setq alist (cdr alist))))
633 (defun char-db-insert-char-reference (plist &optional readable column)
635 (setq column (current-column)))
637 (concat "\n" (make-string (1+ column) ?\ )))
642 (setq name (pop plist))
643 (setq value (pop plist))
644 (cond ((eq name :char)
647 (cond ((numberp value)
648 (setq value (decode-char '=ucs value)))
650 ;; (setq value (or (find-char value)
653 (char-db-insert-char-spec value readable)
654 (insert line-breaking)
657 (insert (format "%s%s\t%d ; %c%s"
660 (ideographic-radical value)
664 (insert (format "%s%s\t%S" separator name value))
665 (setq separator line-breaking)))
669 (defun char-db-decode-isolated-char (ccs code-point)
672 (cond ((eq ccs 'arabic-iso8859-6)
673 (decode-char ccs code-point))
675 ;; (decode-builtin-char '==gt code-point))
676 ((and (memq ccs '(=gt-pj-1
687 (setq ret (decode-char ccs code-point))
688 (setq ret (encode-char ret '=gt 'defined-only)))
689 (decode-builtin-char '=gt ret))
691 (decode-builtin-char ccs code-point))))
693 (or (decode-char ccs code-point)
694 (define-char (list (cons ccs code-point)))))
695 ((and (<= 0 (char-int ret))
696 (<= (char-int ret) #x1F))
697 (decode-char '=ucs (+ #x2400 (char-int ret))))
698 ((= (char-int ret) #x7F)
702 (defvar char-db-convert-obsolete-format t)
704 (defun char-db-insert-ccs-feature (name value line-breaking)
710 ((memq name '(=>iwds-1
713 =shinjigen@1ed ==shinjigen@1ed
714 =shinjigen@rev ==shinjigen@rev
715 =shinjigen/+p@rev ==shinjigen/+p@rev
716 ===daikanwa/ho ==daikanwa/ho
717 =daikanwa/ho =>>daikanwa/ho =>daikanwa/ho))
718 "(%-18s . %04d)\t; %c")
719 ((eq name '=shinjigen@1ed/24pr)
720 "(%-18s . %04d)\t; %c")
724 ==daikanwa =daikanwa =>>daikanwa =>daikanwa
725 =daikanwa@rev1 =daikanwa@rev2
726 =daikanwa/+p ==daikanwa/+p ===daikanwa/+p
728 =daikanwa/+2p =>>daikanwa/+2p
733 =adobe-japan1-0 ==adobe-japan1-0 ===adobe-japan1-0
734 =adobe-japan1-1 ==adobe-japan1-1 ===adobe-japan1-1
735 =adobe-japan1-2 ==adobe-japan1-2 ===adobe-japan1-2
736 =adobe-japan1-3 ==adobe-japan1-3 ===adobe-japan1-3
737 =adobe-japan1-4 ==adobe-japan1-4 ===adobe-japan1-4
738 =adobe-japan1-5 ==adobe-japan1-5 ===adobe-japan1-5
739 =adobe-japan1-6 ==adobe-japan1-6 ===adobe-japan1-6
740 =>>adobe-japan1-0 =+>adobe-japan1-0
741 =>>adobe-japan1-1 =+>adobe-japan1-1
742 =>>adobe-japan1-2 =+>adobe-japan1-2
743 =>>adobe-japan1-3 =+>adobe-japan1-3
744 =>>adobe-japan1-4 =+>adobe-japan1-4
745 =>>adobe-japan1-5 =+>adobe-japan1-5
746 =>>adobe-japan1-6 =+>adobe-japan1-6
747 =>cbeta =cbeta =>>cbeta ==cbeta ===cbeta
748 =zinbun-oracle =>zinbun-oracle
749 =daijiten ==daijiten ===daijiten ==>daijiten
750 ===hng-jou ===hng-keg ===hng-dng ===hng-mam
751 ===hng-drt ===hng-kgk ===hng-myz ===hng-kda
752 ===hng-khi ===hng-khm ===hng-fhs ===hng-hok
753 ===hng-kyd ===hng-sok
754 ===hng-yhk ===hng-kak ===hng-kar ===hng-kae
755 ===hng-sys ===hng-tsu ===hng-tzj
756 ===hng-hos ===hng-kkh ===hng-nak ===hng-jhk
757 ===hng-hod ===hng-gok ===hng-ink ===hng-nto
758 ===hng-nkm ===hng-k24 ===hng-ini ===hng-nkk
759 ===hng-kcc ===hng-kcj ===hng-kbk ===hng-sik
760 ===hng-skk ===hng-kyu ===hng-ksk ===hng-wan
761 ===hng-okd ===hng-wad ===hng-kmi
762 ===hng-zkd ===hng-doh ===hng-jyu ===hng-tzs
763 ===hng-sai ===hng-kad ===hng-kss
764 ===hng-kyo ===hng-ykk ===hng-saa
765 ===hng-sab ===hng-wks ===hng-wke ===hng-smk
766 ===hng-sgs ===hng-sts
767 =shuowen-jiguge ===shuowen-jiguge4 ===shuowen-jiguge5))
768 ;; (string-match "^=adobe-" (symbol-name name))
770 "(%-18s . %05d)\t; %c")
771 ((memq name '(=hanyo-denshi/ks
772 ==hanyo-denshi/ks ===hanyo-denshi/ks
775 =mj ==mj ===mj =>>mj =>mj
777 "(%-18s . %06d)\t; %c")
778 ((memq name '(=hanyo-denshi/tk ==hanyo-denshi/tk))
779 "(%-18s . %08d)\t; %c")
780 ((>= (charset-dimension name) 2)
781 "(%-18s . #x%04X)\t; %c")
783 "(%-18s . #x%02X)\t; %c"))
785 (if (= (charset-iso-graphic-plane name) 1)
787 (cond ((= (charset-dimension name) 1)
789 ((= (charset-dimension name) 2)
791 ((= (charset-dimension name) 3)
795 (char-db-decode-isolated-char name value)))
796 (if (and (= (charset-chars name) 94)
797 (= (charset-dimension name) 2))
798 (insert (format " [%02d-%02d]"
799 (- (lsh value -8) 32)
800 (- (logand value 255) 32))))
803 (insert (format "(%-18s . %s)" name value))
805 (insert line-breaking))
807 (defun char-db-insert-relation-feature (char name value line-breaking
809 (insert (format "(%-18s%s " name line-breaking))
810 (let ((lbs (concat "\n" (make-string (current-column) ?\ )))
811 separator cell sources required-features
814 (setq cell (car value))
816 (setq cell (decode-char '=ucs cell)))
818 ((eq name '->subsumptive)
819 (when (or (not (some (lambda (atr)
820 (get-char-attribute cell atr))
821 char-db-ignored-attributes))
823 (encode-char cell ccs 'defined-only))
827 (let ((char-db-ignored-attributes
829 char-db-ignored-attributes)))
830 (insert-char-attributes cell readable nil nil 'for-sub-node))
831 (setq separator lbs))
836 char (intern (format "%s*sources" name))))
837 (setq required-features nil)
838 (dolist (source sources)
842 shinjigen shinjigen@1ed shinjigen@rev))
843 (setq required-features
844 (union required-features
856 =shinjigen/+p@rev))))
858 (setq required-features
859 (union required-features
864 ((find-charset (setq ret (intern (format "=%s" source))))
865 (setq required-features
866 (cons ret required-features)))
867 (t (setq required-features
868 (cons source required-features)))))
869 (cond ((string-match "@JP" (symbol-name name))
870 (setq required-features
871 (union required-features
879 ((string-match "@CN" (symbol-name name))
880 (setq required-features
881 (union required-features
888 (insert (format "%S" cell))
889 (char-db-insert-char-spec cell readable
892 (setq separator lbs))
896 (if (consp (car cell))
897 (char-db-insert-char-spec cell readable)
898 (char-db-insert-char-reference cell readable))
899 (setq separator lbs))
903 (insert (prin1-to-string cell))
904 (setq separator " ")))
905 (setq value (cdr value)))
907 (insert line-breaking)))
909 (defun insert-char-attributes (char &optional readable attributes column
912 (setq column (current-column)))
913 (let (name value ; has-long-ccs-name
917 (concat "\n" (make-string (1+ column) ?\ )))
918 lbs cell separator ret
920 dest-ccss ; sources required-features
925 (if (consp attributes)
927 (dolist (name attributes)
928 (unless (memq name char-db-ignored-attributes)
929 (if (find-charset name)
933 (dolist (name (char-attribute-list))
934 (unless (memq name char-db-ignored-attributes)
935 (if (find-charset name)
939 #'char-attribute-name<)))
941 (when (memq '<-subsumptive attributes)
942 (when (or readable (not for-sub-node))
943 (when (setq value (get-char-attribute char '<-subsumptive))
944 (char-db-insert-relation-feature char '<-subsumptive value
947 (setq attributes (delq '<-subsumptive attributes)))
948 (when (and (memq '<-denotational attributes)
949 (setq value (get-char-attribute char '<-denotational)))
950 (char-db-insert-relation-feature char '<-denotational value
953 (setq attributes (delq '<-denotational attributes)))
954 (when (and (memq '<-denotational@component attributes)
955 (setq value (get-char-attribute char '<-denotational@component)))
956 (char-db-insert-relation-feature char '<-denotational@component value
959 (setq attributes (delq '<-denotational@component attributes)))
960 (when (and (memq '<-denotational@usage attributes)
961 (setq value (get-char-attribute char '<-denotational@usage)))
962 (char-db-insert-relation-feature char '<-denotational@usage value
965 (setq attributes (delq '<-denotational@usage attributes)))
966 (when (and (memq 'name attributes)
967 (setq value (get-char-attribute char 'name)))
969 (if (> (+ (current-column) (length value)) 48)
972 value line-breaking))
973 (setq attributes (delq 'name attributes))
975 (when (and (memq 'name* attributes)
976 (setq value (get-char-attribute char 'name*)))
978 (if (> (+ (current-column) (length value)) 48)
981 value line-breaking))
982 (setq attributes (delq 'name* attributes))
984 (when (and (memq 'script attributes)
985 (setq value (get-char-attribute char 'script)))
986 (insert (format "(script\t\t%s)%s"
987 (mapconcat (function prin1-to-string)
990 (setq attributes (delq 'script attributes))
992 (dolist (name '(=>ucs =>ucs*))
993 (when (and (memq name attributes)
994 (setq value (get-char-attribute char name)))
995 (insert (format "(%-18s . #x%04X)\t; %c%s"
996 name value (decode-char '=ucs value)
998 (setq attributes (delq name attributes))))
999 (dolist (name '(=>ucs@gb =>ucs@big5))
1000 (when (and (memq name attributes)
1001 (setq value (get-char-attribute char name)))
1002 (insert (format "(%-18s . #x%04X)\t; %c%s"
1004 (decode-char (intern
1007 (symbol-name name) 2)))
1010 (setq attributes (delq name attributes))
1012 ;; (dolist (name '(=>daikanwa))
1013 ;; (when (and (memq name attributes)
1014 ;; (setq value (get-char-attribute char name)))
1016 ;; (if (integerp value)
1017 ;; (format "(%-18s . %05d)\t; %c%s"
1018 ;; name value (decode-char '=daikanwa value)
1020 ;; (format "(%-18s %s)\t; %c%s"
1022 ;; (mapconcat (function prin1-to-string)
1024 ;; (char-representative-of-daikanwa char)
1026 ;; (setq attributes (delq name attributes))))
1027 (when (and (memq 'general-category attributes)
1028 (setq value (get-char-attribute char 'general-category)))
1030 "(general-category\t%s) ; %s%s"
1031 (mapconcat (lambda (cell)
1034 (cond ((rassoc value unidata-normative-category-alist)
1035 "Normative Category")
1036 ((rassoc value unidata-informative-category-alist)
1037 "Informative Category")
1039 "Unknown Category"))
1041 (setq attributes (delq 'general-category attributes))
1043 (when (and (memq 'bidi-category attributes)
1044 (setq value (get-char-attribute char 'bidi-category)))
1045 (insert (format "(bidi-category\t. %S)%s"
1048 (setq attributes (delq 'bidi-category attributes))
1050 (unless (or (not (memq 'mirrored attributes))
1051 (eq (setq value (get-char-attribute char 'mirrored 'empty))
1053 (insert (format "(mirrored\t\t. %S)%s"
1056 (setq attributes (delq 'mirrored attributes))
1059 ((and (memq 'decimal-digit-value attributes)
1060 (setq value (get-char-attribute char 'decimal-digit-value)))
1061 (insert (format "(decimal-digit-value . %S)%s"
1064 (setq attributes (delq 'decimal-digit-value attributes))
1065 (when (and (memq 'digit-value attributes)
1066 (setq value (get-char-attribute char 'digit-value)))
1067 (insert (format "(digit-value\t . %S)%s"
1070 (setq attributes (delq 'digit-value attributes))
1072 (when (and (memq 'numeric-value attributes)
1073 (setq value (get-char-attribute char 'numeric-value)))
1074 (insert (format "(numeric-value\t . %S)%s"
1077 (setq attributes (delq 'numeric-value attributes))
1081 (when (and (memq 'digit-value attributes)
1082 (setq value (get-char-attribute char 'digit-value)))
1083 (insert (format "(digit-value\t. %S)%s"
1086 (setq attributes (delq 'digit-value attributes))
1088 (when (and (memq 'numeric-value attributes)
1089 (setq value (get-char-attribute char 'numeric-value)))
1090 (insert (format "(numeric-value\t. %S)%s"
1093 (setq attributes (delq 'numeric-value attributes))
1095 (when (and (memq 'iso-10646-comment attributes)
1096 (setq value (get-char-attribute char 'iso-10646-comment)))
1097 (insert (format "(iso-10646-comment\t. %S)%s"
1100 (setq attributes (delq 'iso-10646-comment attributes))
1102 (when (and (memq 'morohashi-daikanwa attributes)
1103 (setq value (get-char-attribute char 'morohashi-daikanwa)))
1104 (insert (format "(morohashi-daikanwa\t%s)%s"
1105 (mapconcat (function prin1-to-string) value " ")
1107 (setq attributes (delq 'morohashi-daikanwa attributes))
1111 (when (and (memq 'ideographic-radical attributes)
1112 (setq value (get-char-attribute char 'ideographic-radical)))
1113 (setq radical value)
1114 (insert (format "(ideographic-radical . %S)\t; %c%s"
1116 (ideographic-radical radical)
1118 (setq attributes (delq 'ideographic-radical attributes))
1120 (when (and (memq 'shuowen-radical attributes)
1121 (setq value (get-char-attribute char 'shuowen-radical)))
1122 (insert (format "(shuowen-radical\t. %S)\t; %c%s"
1124 (shuowen-radical value)
1126 (setq attributes (delq 'shuowen-radical attributes))
1131 char-db-feature-domains
1133 (dolist (feature (char-attribute-list))
1134 (setq feature (symbol-name feature))
1136 "\\(radical\\|strokes\\)@\\([^@*]+\\)\\(\\*\\|$\\)"
1138 (setq domain (intern (match-string 2 feature)))
1139 (unless (memq domain dest)
1140 (setq dest (cons domain dest)))))
1141 (sort dest #'string<))))
1142 (setq key (intern (format "%s@%s" 'ideographic-radical domain)))
1143 (when (and (memq key attributes)
1144 (setq value (get-char-attribute char key)))
1145 (setq radical value)
1146 (insert (format "(%s . %S)\t; %c%s"
1149 (ideographic-radical radical)
1151 (setq attributes (delq key attributes))
1153 (setq key (intern (format "%s@%s" 'ideographic-strokes domain)))
1154 (when (and (memq key attributes)
1155 (setq value (get-char-attribute char key)))
1156 (setq strokes value)
1157 (insert (format "(%s . %S)%s"
1161 (setq attributes (delq key attributes))
1163 (setq key (intern (format "%s@%s" 'total-strokes domain)))
1164 (when (and (memq key attributes)
1165 (setq value (get-char-attribute char key)))
1166 (insert (format "(%s . %S)%s"
1170 (setq attributes (delq key attributes))
1172 (dolist (feature '(ideographic-radical
1175 (setq key (intern (format "%s@%s*sources" feature domain)))
1176 (when (and (memq key attributes)
1177 (setq value (get-char-attribute char key)))
1178 (insert (format "(%s%s" key line-breaking))
1179 (dolist (cell value)
1180 (insert (format " %s" cell)))
1182 (insert line-breaking)
1183 (setq attributes (delq key attributes))
1186 (when (and (memq 'ideographic-strokes attributes)
1187 (setq value (get-char-attribute char 'ideographic-strokes)))
1188 (setq strokes value)
1189 (insert (format "(ideographic-strokes . %S)%s"
1192 (setq attributes (delq 'ideographic-strokes attributes))
1194 (when (and (memq 'kangxi-radical attributes)
1195 (setq value (get-char-attribute char 'kangxi-radical)))
1196 (unless (eq value radical)
1197 (insert (format "(kangxi-radical\t . %S)\t; %c%s"
1199 (ideographic-radical value)
1202 (setq radical value)))
1203 (setq attributes (delq 'kangxi-radical attributes))
1205 (when (and (memq 'kangxi-strokes attributes)
1206 (setq value (get-char-attribute char 'kangxi-strokes)))
1207 (unless (eq value strokes)
1208 (insert (format "(kangxi-strokes\t . %S)%s"
1212 (setq strokes value)))
1213 (setq attributes (delq 'kangxi-strokes attributes))
1215 ;; (when (and (memq 'japanese-radical attributes)
1216 ;; (setq value (get-char-attribute char 'japanese-radical)))
1217 ;; (unless (eq value radical)
1218 ;; (insert (format "(japanese-radical\t . %S)\t; %c%s"
1220 ;; (ideographic-radical value)
1223 ;; (setq radical value)))
1224 ;; (setq attributes (delq 'japanese-radical attributes))
1226 (when (and (memq 'japanese-strokes attributes)
1227 (setq value (get-char-attribute char 'japanese-strokes)))
1228 (unless (eq value strokes)
1229 (insert (format "(japanese-strokes\t . %S)%s"
1233 (setq strokes value)))
1234 (setq attributes (delq 'japanese-strokes attributes))
1236 (when (and (memq 'cns-radical attributes)
1237 (setq value (get-char-attribute char 'cns-radical)))
1238 (insert (format "(cns-radical\t . %S)\t; %c%s"
1240 (ideographic-radical value)
1242 (setq attributes (delq 'cns-radical attributes))
1244 (when (and (memq 'cns-strokes attributes)
1245 (setq value (get-char-attribute char 'cns-strokes)))
1246 (unless (eq value strokes)
1247 (insert (format "(cns-strokes\t . %S)%s"
1251 (setq strokes value)))
1252 (setq attributes (delq 'cns-strokes attributes))
1254 ;; (when (and (memq 'ideographic- attributes)
1255 ;; (setq value (get-char-attribute char 'ideographic-)))
1256 ;; (insert "(ideographic- ")
1257 ;; (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1259 ;; (while (consp value)
1260 ;; (setq cell (car value))
1261 ;; (if (integerp cell)
1262 ;; (setq cell (decode-char '=ucs cell)))
1263 ;; (cond ((characterp cell)
1267 ;; (insert (format "%S" cell))
1268 ;; (char-db-insert-char-spec cell readable))
1269 ;; (setq separator lbs))
1273 ;; (if (consp (car cell))
1274 ;; (char-db-insert-char-spec cell readable)
1275 ;; (char-db-insert-char-reference cell readable))
1276 ;; (setq separator lbs))
1279 ;; (insert separator))
1280 ;; (insert (prin1-to-string cell))
1281 ;; (setq separator " ")))
1282 ;; (setq value (cdr value)))
1284 ;; (insert line-breaking)
1285 ;; (setq attributes (delq 'ideographic- attributes)))
1286 (when (and (memq 'total-strokes attributes)
1287 (setq value (get-char-attribute char 'total-strokes)))
1288 (insert (format "(total-strokes . %S)%s"
1291 (setq attributes (delq 'total-strokes attributes))
1293 ;; (when (and (memq '->ideograph attributes)
1294 ;; (setq value (get-char-attribute char '->ideograph)))
1295 ;; (insert (format "(->ideograph\t%s)%s"
1296 ;; (mapconcat (lambda (code)
1297 ;; (cond ((symbolp code)
1298 ;; (symbol-name code))
1300 ;; (format "#x%04X" code))
1303 ;; line-breaking code))))
1306 ;; (setq attributes (delq '->ideograph attributes))
1308 ;; (when (and (memq '->decomposition attributes)
1309 ;; (setq value (get-char-attribute char '->decomposition)))
1310 ;; (insert (format "(->decomposition\t%s)%s"
1311 ;; (mapconcat (lambda (code)
1312 ;; (cond ((symbolp code)
1313 ;; (symbol-name code))
1314 ;; ((characterp code)
1316 ;; (format "%S" code)
1321 ;; (format "#x%04X" code))
1323 ;; (format "%s%S" line-breaking code))))
1326 ;; (setq attributes (delq '->decomposition attributes))
1328 (if (equal (get-char-attribute char '->titlecase)
1329 (get-char-attribute char '->uppercase))
1330 (setq attributes (delq '->titlecase attributes)))
1331 (when (and (memq '->mojikyo attributes)
1332 (setq value (get-char-attribute char '->mojikyo)))
1333 (insert (format "(->mojikyo\t\t. %06d)\t; %c%s"
1334 value (decode-char 'mojikyo value)
1336 (setq attributes (delq '->mojikyo attributes))
1339 (dolist (ignored '(composition
1340 ->denotational <-subsumptive ->ucs-unified
1341 ;; ->ideographic-component-forms
1343 (setq attributes (delq ignored attributes))))
1345 (setq name (car attributes))
1346 (unless (eq (setq value (get-char-attribute char name 'value-is-empty))
1348 (cond ((setq ret (find-charset name))
1349 (setq name (charset-name ret))
1350 (when (not (memq name dest-ccss))
1351 (setq dest-ccss (cons name dest-ccss))
1352 (char-db-insert-ccs-feature name value line-breaking))
1354 ((string-match "^=>ucs@" (symbol-name name))
1355 (insert (format "(%-18s . #x%04X)\t; %c%s"
1356 name value (decode-char '=ucs value)
1359 ((eq name 'jisx0208-1978/4X)
1360 (insert (format "(%-18s . #x%04X)%s"
1366 (not (eq name '->subsumptive))
1367 (not (eq name '->uppercase))
1368 (not (eq name '->lowercase))
1369 (not (eq name '->titlecase))
1370 (not (eq name '->canonical))
1371 (not (eq name '->Bopomofo))
1372 (not (eq name '->mistakable))
1373 (not (eq name '->ideographic-variants))
1374 (null (get-char-attribute
1375 char (intern (format "%s*sources" name))))
1376 (not (string-match "\\*sources$" (symbol-name name)))
1377 (null (get-char-attribute
1378 char (intern (format "%s*note" name))))
1379 (not (string-match "\\*note$" (symbol-name name)))
1380 (or (eq name '<-identical)
1381 (eq name '<-uppercase)
1382 (eq name '<-lowercase)
1383 (eq name '<-titlecase)
1384 (eq name '<-canonical)
1385 (eq name '<-ideographic-variants)
1386 ;; (eq name '<-synonyms)
1387 (string-match "^<-synonyms" (symbol-name name))
1388 (eq name '<-mistakable)
1389 (when (string-match "^->" (symbol-name name))
1391 ((string-match "^->fullwidth" (symbol-name name))
1392 (not (and (consp value)
1393 (characterp (car value))
1395 (car value) '=ucs 'defined-only)))
1400 ((or (eq name 'ideographic-structure)
1401 (eq name 'ideographic-combination)
1402 ;; (eq name 'ideographic-)
1403 (eq name '=decomposition)
1404 (char-feature-base-name= '=decomposition name)
1405 (char-feature-base-name= '=>decomposition name)
1406 ;; (string-match "^=>*decomposition\\(@[^*]+\\)?$"
1407 ;; (symbol-name name))
1408 (string-match "^\\(->\\|<-\\)[^*]*$" (symbol-name name))
1409 (string-match "^\\(->\\|<-\\)[^*]*\\*sources$"
1412 (char-db-insert-relation-feature char name value
1415 ;; ((memq name '(ideograph=
1416 ;; original-ideograph-of
1417 ;; ancient-ideograph-of
1418 ;; vulgar-ideograph-of
1419 ;; wrong-ideograph-of
1420 ;; ;; simplified-ideograph-of
1421 ;; ideographic-variants
1422 ;; ;; ideographic-different-form-of
1424 ;; (insert (format "(%-18s%s " name line-breaking))
1425 ;; (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1427 ;; (while (consp value)
1428 ;; (setq cell (car value))
1429 ;; (if (and (consp cell)
1430 ;; (consp (car cell)))
1434 ;; (char-db-insert-alist cell readable)
1435 ;; (setq separator lbs))
1437 ;; (insert separator))
1438 ;; (insert (prin1-to-string cell))
1439 ;; (setq separator " "))
1440 ;; (setq value (cdr value)))
1442 ;; (insert line-breaking))
1444 (insert (format "(%-18s " name))
1445 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1447 (while (consp value)
1448 (setq cell (car value))
1449 (if (and (consp cell)
1451 (setq ret (condition-case nil
1459 (setq key (car (car rest)))
1460 (if (find-charset key)
1461 (setq cal (cons key cal))
1462 (setq al (cons key al)))
1463 (setq rest (cdr rest)))
1466 (insert-char-attributes ret
1470 (setq separator lbs))
1471 (setq ret (prin1-to-string cell))
1473 (if (< (+ (current-column)
1480 (setq separator " "))
1481 (setq value (cdr value)))
1483 (insert line-breaking))
1485 (insert (format "(%-18s" name))
1486 (setq ret (prin1-to-string value))
1487 (unless (< (+ (current-column)
1491 (insert line-breaking))
1492 (insert " . " ret ")" line-breaking)
1493 ;; (insert (format "(%-18s . %S)%s"
1498 (setq attributes (cdr attributes)))
1501 (defun insert-char-data (char &optional readable
1504 (narrow-to-region (point)(point))
1505 (insert "(define-char
1507 (insert-char-attributes char readable attributes)
1509 (goto-char (point-min))
1510 (while (re-search-forward "[ \t]+$" nil t)
1513 (goto-char (point-min))
1514 (while (re-search-forward "[ \t][ \t][ \t]*" nil t)
1515 (let ((column (current-column))
1516 (indent-tabs-mode t))
1517 (delete-region (match-beginning 0) (point))
1518 (indent-to column)))
1519 (goto-char (point-max))
1520 ;; (tabify (point-min)(point-max))
1523 (defun insert-char-data-with-variant (char &optional printable
1525 script excluded-script)
1526 (insert-char-data char printable)
1527 (let ((variants (char-variants char))
1530 (setq variants (sort variants #'<))
1531 (setq rest variants)
1532 (setq variants (cons char variants))
1534 (setq variant (car rest))
1535 (unless (get-char-attribute variant '<-subsumptive)
1536 (if (and (or (null script)
1537 (null (setq vs (get-char-attribute variant 'script)))
1539 (or (null excluded-script)
1540 (null (setq vs (get-char-attribute variant 'script)))
1541 (not (memq excluded-script vs))))
1542 (unless (and no-ucs-unified (get-char-attribute variant '=ucs))
1543 (insert-char-data variant printable)
1544 (if (setq ret (char-variants variant))
1546 (or (memq (car ret) variants)
1547 ;; (get-char-attribute (car ret) '<-subsumptive)
1548 (setq rest (nconc rest (list (car ret)))))
1549 (setq ret (cdr ret)))))))
1550 (setq rest (cdr rest)))))
1552 (defun insert-char-range-data (min max &optional script excluded-script)
1555 (while (<= code max)
1556 (setq char (decode-char '=ucs code))
1557 (if (encode-char char '=ucs 'defined-only)
1558 (insert-char-data-with-variant char nil 'no-ucs-unified
1559 script excluded-script))
1560 (setq code (1+ code)))))
1562 (defun write-char-range-data-to-file (min max file
1563 &optional script excluded-script)
1564 (let ((coding-system-for-write char-db-file-coding-system))
1566 (insert (format ";; -*- coding: %s -*-\n"
1567 char-db-file-coding-system))
1568 (insert-char-range-data min max script excluded-script)
1569 (write-region (point-min)(point-max) file))))
1571 (defvar what-character-original-window-configuration)
1574 (defun what-char-definition (char)
1575 (interactive (list (char-after)))
1576 (let ((buf (get-buffer-create "*Character Description*"))
1577 (the-buf (current-buffer))
1578 (win-conf (current-window-configuration)))
1580 (make-local-variable 'what-character-original-window-configuration)
1581 (setq what-character-original-window-configuration win-conf)
1582 (setq buffer-read-only nil)
1586 (insert-char-data-with-variant char 'printable)
1587 (unless (char-attribute-alist char)
1588 (insert (format ";; = %c\n"
1589 (let* ((rest (split-char char))
1593 (setq code (logior (lsh code 8)
1595 (decode-char ccs code)))))
1596 ;; (char-db-update-comment)
1597 (set-buffer-modified-p nil)
1598 (view-mode the-buf (lambda (buf)
1599 (set-window-configuration
1600 what-character-original-window-configuration)
1602 (goto-char (point-min)))
1604 (set-window-configuration
1605 what-character-original-window-configuration)
1606 (signal (car err) (cdr err)))))))
1612 (provide 'char-db-util)
1614 ;;; char-db-util.el ends here