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 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
214 ;; =>>>adobe-japan1-0
215 ;; =>>>adobe-japan1-1
216 ;; =>>>adobe-japan1-2
217 ;; =>>>adobe-japan1-3
218 ;; =>>>adobe-japan1-4
219 ;; =>>>adobe-japan1-5
220 ;; =>>>adobe-japan1-6
224 ;; =>>>hanyo-denshi/ja
225 ;; =>>>hanyo-denshi/jb
226 ;; =>>>hanyo-denshi/jc
227 ;; =>>>hanyo-denshi/ft
228 ;; =>>>hanyo-denshi/ib
229 ;; =>>>hanyo-denshi/hg
230 ;; =>>>hanyo-denshi/jt
231 ;; =>>>hanyo-denshi/ks
271 ;; =>ucs@hanyo-denshi
369 =>big5-cdp-itaiji-001
373 =>ucs-itaiji-001@iwds-1
383 ;;; @ char-db formatters
386 (defun char-db-make-char-spec (char)
388 (cond ((characterp char)
389 (cond ((and (setq ret (encode-char char '=ucs 'defined-only))
390 (not (and (<= #xE000 ret)(<= ret #xF8FF))))
391 (setq char-spec (list (cons '=ucs ret)))
392 (cond ((setq ret (get-char-attribute char 'name))
393 (setq char-spec (cons (cons 'name ret) char-spec))
395 ((setq ret (get-char-attribute char 'name*))
396 (setq char-spec (cons (cons 'name* ret) char-spec))
399 ((encode-char char '=mj 'defined-only)
401 (dolist (ccs (charset-list))
402 (if (and (or (eq ccs '=mj)
403 ;; (eq (charset-property ccs 'iso-ir) 177)
404 (string-match "=ucs@" (symbol-name ccs))
406 (setq ccs (charset-name ccs))
407 (null (assq ccs char-spec))
408 (setq ret (encode-char char ccs 'defined-only)))
409 (setq char-spec (cons (cons ccs ret) char-spec))))
411 ((encode-char char '==mj 'defined-only)
413 (dolist (ccs (charset-list))
414 (if (and (or (eq ccs '==mj)
415 ;; (eq (charset-property ccs 'iso-ir) 177)
416 (string-match "=ucs@" (symbol-name ccs))
418 (setq ccs (charset-name ccs))
419 (null (assq ccs char-spec))
420 (setq ret (encode-char char ccs 'defined-only)))
421 (setq char-spec (cons (cons ccs ret) char-spec))))
423 ((encode-char char '=adobe-japan1 'defined-only)
425 (dolist (ccs (charset-list))
426 (if (and (or (memq ccs
435 ;; (eq (charset-property ccs 'iso-ir) 177)
436 (string-match "=ucs@" (symbol-name ccs))
438 (setq ccs (charset-name ccs))
439 (null (assq ccs char-spec))
440 (setq ret (encode-char char ccs 'defined-only)))
441 (setq char-spec (cons (cons ccs ret) char-spec))))
443 ((encode-char char '==adobe-japan1 'defined-only)
445 (dolist (ccs (charset-list))
446 (if (and (or (memq ccs
455 ;; (eq (charset-property ccs 'iso-ir) 177)
456 (string-match "=ucs@" (symbol-name ccs))
458 (setq ccs (charset-name ccs))
459 (null (assq ccs char-spec))
460 (setq ret (encode-char char ccs 'defined-only)))
461 (setq char-spec (cons (cons ccs ret) char-spec))))
465 (let ((rest char-db-coded-charset-priority-list)
468 (setq ccs (charset-name
469 (find-charset (car rest))))
471 (encode-char char ccs
473 (throw 'tag (cons ccs ret)))
474 (setq rest (cdr rest))))))
475 (setq char-spec (list ret))
476 (dolist (ccs (delq (car ret) (charset-list)))
477 (if (and (or (charset-iso-final-char ccs)
484 (and (eq (charset-property ccs 'iso-ir) 177)
485 (not (eq (charset-name ccs) '=ucs@big5)))
486 ;; (string-match "=ucs@" (symbol-name ccs))
488 (setq ccs (charset-name ccs))
489 (null (assq ccs char-spec))
490 (setq ret (encode-char char ccs 'defined-only)))
491 (setq char-spec (cons (cons ccs ret) char-spec))))
493 (setq char-spec (split-char char)))
494 (cond ((setq ret (get-char-attribute char 'name))
495 (setq char-spec (cons (cons 'name ret) char-spec))
497 ((setq ret (get-char-attribute char 'name*))
498 (setq char-spec (cons (cons 'name* ret) char-spec))
501 ((setq ret (get-char-attribute
502 char 'ideographic-combination))
504 (cons (cons 'ideographic-combination ret)
511 (defun char-db-insert-char-spec (char &optional readable column
514 (setq column (current-column)))
515 (let (char-spec temp-char)
516 (setq char-spec (char-db-make-char-spec char))
517 (unless (or (characterp char) ; char
519 (setq char (find-char char-spec))
521 ;; define temporary character
522 ;; Current implementation is dirty.
523 (setq temp-char (define-char (cons '(ideograph-daikanwa . 0)
525 (remove-char-attribute temp-char 'ideograph-daikanwa)
526 (setq char temp-char))
527 (insert-char-attributes char
529 (union (mapcar #'car char-spec)
533 ;; undefine temporary character
534 ;; Current implementation is dirty.
535 (setq char-spec (char-attribute-alist temp-char))
537 (remove-char-attribute temp-char (car (car char-spec)))
538 (setq char-spec (cdr char-spec))))))
540 (defun char-db-insert-alist (alist &optional readable column)
542 (setq column (current-column)))
544 (concat "\n" (make-string (1+ column) ?\ )))
548 lbs cell rest separator)
551 (setq name (car (car alist))
552 value (cdr (car alist)))
553 (cond ((eq name 'char)
555 (if (setq ret (condition-case nil
563 (setq key (car (car value)))
564 ;; (if (find-charset key)
565 ;; (setq cal (cons key cal))
566 (setq al (cons key al))
568 (setq value (cdr value)))
569 (insert-char-attributes ret
573 (insert (prin1-to-string value)))
575 (insert line-breaking))
577 (insert (format "(%-18s " name))
578 (setq lbs (concat "\n" (make-string (current-column) ?\ )))
580 (setq cell (car value))
581 (if (and (consp cell)
583 (setq ret (condition-case nil
593 (setq key (car (car rest)))
594 ;; (if (find-charset key)
595 ;; (setq cal (cons key cal))
596 (setq al (cons key al))
598 (setq rest (cdr rest)))
601 (insert-char-attributes ret
605 (setq separator lbs))
608 (insert (prin1-to-string cell))
609 (setq separator " "))
610 (setq value (cdr value)))
612 (insert line-breaking))
614 (insert (format "(%-18s . %S)%s"
617 (setq alist (cdr alist))))
620 (defun char-db-insert-char-reference (plist &optional readable column)
622 (setq column (current-column)))
624 (concat "\n" (make-string (1+ column) ?\ )))
629 (setq name (pop plist))
630 (setq value (pop plist))
631 (cond ((eq name :char)
634 (cond ((numberp value)
635 (setq value (decode-char '=ucs value)))
637 ;; (setq value (or (find-char value)
640 (char-db-insert-char-spec value readable)
641 (insert line-breaking)
644 (insert (format "%s%s\t%d ; %c%s"
647 (ideographic-radical value)
651 (insert (format "%s%s\t%S" separator name value))
652 (setq separator line-breaking)))
656 (defun char-db-decode-isolated-char (ccs code-point)
659 (cond ((eq ccs 'arabic-iso8859-6)
660 (decode-char ccs code-point))
662 ;; (decode-builtin-char '==gt code-point))
663 ((and (memq ccs '(=gt-pj-1
674 (setq ret (decode-char ccs code-point))
675 (setq ret (encode-char ret '=gt 'defined-only)))
676 (decode-builtin-char '=gt ret))
678 (decode-builtin-char ccs code-point))))
680 (or (decode-char ccs code-point)
681 (define-char (list (cons ccs code-point)))))
682 ((and (<= 0 (char-int ret))
683 (<= (char-int ret) #x1F))
684 (decode-char '=ucs (+ #x2400 (char-int ret))))
685 ((= (char-int ret) #x7F)
689 (defvar char-db-convert-obsolete-format t)
691 (defun char-db-insert-ccs-feature (name value line-breaking)
697 ((memq name '(=>iwds-1
700 =shinjigen@1ed ==shinjigen@1ed
701 =shinjigen@rev ==shinjigen@rev
702 =shinjigen/+p@rev ==shinjigen/+p@rev
703 ===daikanwa/ho ==daikanwa/ho
704 =daikanwa/ho =>>daikanwa/ho =>daikanwa/ho))
705 "(%-18s . %04d)\t; %c")
706 ((eq name '=shinjigen@1ed/24pr)
707 "(%-18s . %04d)\t; %c")
711 ==daikanwa =daikanwa =>>daikanwa =>daikanwa
712 =daikanwa@rev1 =daikanwa@rev2
713 =daikanwa/+p ==daikanwa/+p ===daikanwa/+p
715 =daikanwa/+2p =>>daikanwa/+2p
720 =adobe-japan1-0 ==adobe-japan1-0 ===adobe-japan1-0
721 =adobe-japan1-1 ==adobe-japan1-1 ===adobe-japan1-1
722 =adobe-japan1-2 ==adobe-japan1-2 ===adobe-japan1-2
723 =adobe-japan1-3 ==adobe-japan1-3 ===adobe-japan1-3
724 =adobe-japan1-4 ==adobe-japan1-4 ===adobe-japan1-4
725 =adobe-japan1-5 ==adobe-japan1-5 ===adobe-japan1-5
726 =adobe-japan1-6 ==adobe-japan1-6 ===adobe-japan1-6
727 =>>adobe-japan1-0 =+>adobe-japan1-0
728 =>>adobe-japan1-1 =+>adobe-japan1-1
729 =>>adobe-japan1-2 =+>adobe-japan1-2
730 =>>adobe-japan1-3 =+>adobe-japan1-3
731 =>>adobe-japan1-4 =+>adobe-japan1-4
732 =>>adobe-japan1-5 =+>adobe-japan1-5
733 =>>adobe-japan1-6 =+>adobe-japan1-6
734 =>cbeta =cbeta =>>cbeta ==cbeta ===cbeta
735 =zinbun-oracle =>zinbun-oracle
736 ===hng-jou ===hng-keg ===hng-dng ===hng-mam
737 ===hng-drt ===hng-kgk ===hng-myz ===hng-kda
738 ===hng-khi ===hng-khm ===hng-hok ===hng-kyd ===hng-sok
739 ===hng-yhk ===hng-kak ===hng-kar ===hng-kae
740 ===hng-sys ===hng-tsu ===hng-tzj
741 ===hng-hos ===hng-nak ===hng-jhk
742 ===hng-hod ===hng-gok ===hng-ink ===hng-nto
743 ===hng-nkm ===hng-k24 ===hng-nkk
744 ===hng-kcc ===hng-kcj ===hng-kbk ===hng-sik
745 ===hng-skk ===hng-kyu ===hng-ksk ===hng-wan
746 ===hng-okd ===hng-wad ===hng-kmi
747 ===hng-zkd ===hng-doh ===hng-jyu
748 ===hng-tzs ===hng-kss ===hng-kyo
750 ;; (string-match "^=adobe-" (symbol-name name))
752 "(%-18s . %05d)\t; %c")
753 ((memq name '(=hanyo-denshi/ks
754 ==hanyo-denshi/ks ===hanyo-denshi/ks
757 =mj ==mj ===mj =>>mj =>mj
759 "(%-18s . %06d)\t; %c")
760 ((memq name '(=hanyo-denshi/tk ==hanyo-denshi/tk))
761 "(%-18s . %08d)\t; %c")
762 ((>= (charset-dimension name) 2)
763 "(%-18s . #x%04X)\t; %c")
765 "(%-18s . #x%02X)\t; %c"))
767 (if (= (charset-iso-graphic-plane name) 1)
769 (cond ((= (charset-dimension name) 1)
771 ((= (charset-dimension name) 2)
773 ((= (charset-dimension name) 3)
777 (char-db-decode-isolated-char name value)))
778 (if (and (= (charset-chars name) 94)
779 (= (charset-dimension name) 2))
780 (insert (format " [%02d-%02d]"
781 (- (lsh value -8) 32)
782 (- (logand value 255) 32))))
785 (insert (format "(%-18s . %s)" name value))
787 (insert line-breaking))
789 (defun char-db-insert-relation-feature (char name value line-breaking
791 (insert (format "(%-18s%s " name line-breaking))
792 (let ((lbs (concat "\n" (make-string (current-column) ?\ )))
793 separator cell sources required-features
796 (setq cell (car value))
798 (setq cell (decode-char '=ucs cell)))
800 ((eq name '->subsumptive)
801 (when (or (not (some (lambda (atr)
802 (get-char-attribute cell atr))
803 char-db-ignored-attributes))
805 (encode-char cell ccs 'defined-only))
809 (let ((char-db-ignored-attributes
811 char-db-ignored-attributes)))
812 (insert-char-attributes cell readable nil nil 'for-sub-node))
813 (setq separator lbs))
818 char (intern (format "%s*sources" name))))
819 (setq required-features nil)
820 (dolist (source sources)
824 shinjigen shinjigen@1ed shinjigen@rev))
825 (setq required-features
826 (union required-features
838 =shinjigen/+p@rev))))
840 (setq required-features
841 (union required-features
846 ((find-charset (setq ret (intern (format "=%s" source))))
847 (setq required-features
848 (cons ret required-features)))
849 (t (setq required-features
850 (cons source required-features)))))
851 (cond ((string-match "@JP" (symbol-name name))
852 (setq required-features
853 (union required-features
861 ((string-match "@CN" (symbol-name name))
862 (setq required-features
863 (union required-features
870 (insert (format "%S" cell))
871 (char-db-insert-char-spec cell readable
874 (setq separator lbs))
878 (if (consp (car cell))
879 (char-db-insert-char-spec cell readable)
880 (char-db-insert-char-reference cell readable))
881 (setq separator lbs))
885 (insert (prin1-to-string cell))
886 (setq separator " ")))
887 (setq value (cdr value)))
889 (insert line-breaking)))
891 (defun insert-char-attributes (char &optional readable attributes column
894 (setq column (current-column)))
895 (let (name value ; has-long-ccs-name
899 (concat "\n" (make-string (1+ column) ?\ )))
900 lbs cell separator ret
902 dest-ccss ; sources required-features
907 (if (consp attributes)
909 (dolist (name attributes)
910 (unless (memq name char-db-ignored-attributes)
911 (if (find-charset name)
915 (dolist (name (char-attribute-list))
916 (unless (memq name char-db-ignored-attributes)
917 (if (find-charset name)
921 #'char-attribute-name<)))
923 (when (memq '<-subsumptive attributes)
924 (when (or readable (not for-sub-node))
925 (when (setq value (get-char-attribute char '<-subsumptive))
926 (char-db-insert-relation-feature char '<-subsumptive value
929 (setq attributes (delq '<-subsumptive attributes)))
930 (when (and (memq '<-denotational attributes)
931 (setq value (get-char-attribute char '<-denotational)))
932 (char-db-insert-relation-feature char '<-denotational value
935 (setq attributes (delq '<-denotational attributes)))
936 (when (and (memq '<-denotational@component attributes)
937 (setq value (get-char-attribute char '<-denotational@component)))
938 (char-db-insert-relation-feature char '<-denotational@component value
941 (setq attributes (delq '<-denotational@component attributes)))
942 (when (and (memq 'name attributes)
943 (setq value (get-char-attribute char 'name)))
945 (if (> (+ (current-column) (length value)) 48)
948 value line-breaking))
949 (setq attributes (delq 'name attributes))
951 (when (and (memq 'name* attributes)
952 (setq value (get-char-attribute char 'name*)))
954 (if (> (+ (current-column) (length value)) 48)
957 value line-breaking))
958 (setq attributes (delq 'name* attributes))
960 (when (and (memq 'script attributes)
961 (setq value (get-char-attribute char 'script)))
962 (insert (format "(script\t\t%s)%s"
963 (mapconcat (function prin1-to-string)
966 (setq attributes (delq 'script attributes))
968 (dolist (name '(=>ucs =>ucs*))
969 (when (and (memq name attributes)
970 (setq value (get-char-attribute char name)))
971 (insert (format "(%-18s . #x%04X)\t; %c%s"
972 name value (decode-char '=ucs value)
974 (setq attributes (delq name attributes))))
975 (dolist (name '(=>ucs@gb =>ucs@big5))
976 (when (and (memq name attributes)
977 (setq value (get-char-attribute char name)))
978 (insert (format "(%-18s . #x%04X)\t; %c%s"
983 (symbol-name name) 2)))
986 (setq attributes (delq name attributes))
988 ;; (dolist (name '(=>daikanwa))
989 ;; (when (and (memq name attributes)
990 ;; (setq value (get-char-attribute char name)))
992 ;; (if (integerp value)
993 ;; (format "(%-18s . %05d)\t; %c%s"
994 ;; name value (decode-char '=daikanwa value)
996 ;; (format "(%-18s %s)\t; %c%s"
998 ;; (mapconcat (function prin1-to-string)
1000 ;; (char-representative-of-daikanwa char)
1002 ;; (setq attributes (delq name attributes))))
1003 (when (and (memq 'general-category attributes)
1004 (setq value (get-char-attribute char 'general-category)))
1006 "(general-category\t%s) ; %s%s"
1007 (mapconcat (lambda (cell)
1010 (cond ((rassoc value unidata-normative-category-alist)
1011 "Normative Category")
1012 ((rassoc value unidata-informative-category-alist)
1013 "Informative Category")
1015 "Unknown Category"))
1017 (setq attributes (delq 'general-category attributes))
1019 (when (and (memq 'bidi-category attributes)
1020 (setq value (get-char-attribute char 'bidi-category)))
1021 (insert (format "(bidi-category\t. %S)%s"
1024 (setq attributes (delq 'bidi-category attributes))
1026 (unless (or (not (memq 'mirrored attributes))
1027 (eq (setq value (get-char-attribute char 'mirrored 'empty))
1029 (insert (format "(mirrored\t\t. %S)%s"
1032 (setq attributes (delq 'mirrored attributes))
1035 ((and (memq 'decimal-digit-value attributes)
1036 (setq value (get-char-attribute char 'decimal-digit-value)))
1037 (insert (format "(decimal-digit-value . %S)%s"
1040 (setq attributes (delq 'decimal-digit-value attributes))
1041 (when (and (memq 'digit-value attributes)
1042 (setq value (get-char-attribute char 'digit-value)))
1043 (insert (format "(digit-value\t . %S)%s"
1046 (setq attributes (delq 'digit-value attributes))
1048 (when (and (memq 'numeric-value attributes)
1049 (setq value (get-char-attribute char 'numeric-value)))
1050 (insert (format "(numeric-value\t . %S)%s"
1053 (setq attributes (delq 'numeric-value attributes))
1057 (when (and (memq 'digit-value attributes)
1058 (setq value (get-char-attribute char 'digit-value)))
1059 (insert (format "(digit-value\t. %S)%s"
1062 (setq attributes (delq 'digit-value attributes))
1064 (when (and (memq 'numeric-value attributes)
1065 (setq value (get-char-attribute char 'numeric-value)))
1066 (insert (format "(numeric-value\t. %S)%s"
1069 (setq attributes (delq 'numeric-value attributes))
1071 (when (and (memq 'iso-10646-comment attributes)
1072 (setq value (get-char-attribute char 'iso-10646-comment)))
1073 (insert (format "(iso-10646-comment\t. %S)%s"
1076 (setq attributes (delq 'iso-10646-comment attributes))
1078 (when (and (memq 'morohashi-daikanwa attributes)
1079 (setq value (get-char-attribute char 'morohashi-daikanwa)))
1080 (insert (format "(morohashi-daikanwa\t%s)%s"
1081 (mapconcat (function prin1-to-string) value " ")
1083 (setq attributes (delq 'morohashi-daikanwa attributes))
1087 (when (and (memq 'ideographic-radical attributes)
1088 (setq value (get-char-attribute char 'ideographic-radical)))
1089 (setq radical value)
1090 (insert (format "(ideographic-radical . %S)\t; %c%s"
1092 (ideographic-radical radical)
1094 (setq attributes (delq 'ideographic-radical attributes))
1096 (when (and (memq 'shuowen-radical attributes)
1097 (setq value (get-char-attribute char 'shuowen-radical)))
1098 (insert (format "(shuowen-radical\t. %S)\t; %c%s"
1100 (shuowen-radical value)
1102 (setq attributes (delq 'shuowen-radical attributes))
1107 char-db-feature-domains
1109 (dolist (feature (char-attribute-list))
1110 (setq feature (symbol-name feature))
1112 "\\(radical\\|strokes\\)@\\([^@*]+\\)\\(\\*\\|$\\)"
1114 (setq domain (intern (match-string 2 feature)))
1115 (unless (memq domain dest)
1116 (setq dest (cons domain dest)))))
1117 (sort dest #'string<))))
1118 (setq key (intern (format "%s@%s" 'ideographic-radical domain)))
1119 (when (and (memq key attributes)
1120 (setq value (get-char-attribute char key)))
1121 (setq radical value)
1122 (insert (format "(%s . %S)\t; %c%s"
1125 (ideographic-radical radical)
1127 (setq attributes (delq key attributes))
1129 (setq key (intern (format "%s@%s" 'ideographic-strokes domain)))
1130 (when (and (memq key attributes)
1131 (setq value (get-char-attribute char key)))
1132 (setq strokes value)
1133 (insert (format "(%s . %S)%s"
1137 (setq attributes (delq key attributes))
1139 (setq key (intern (format "%s@%s" 'total-strokes domain)))
1140 (when (and (memq key attributes)
1141 (setq value (get-char-attribute char key)))
1142 (insert (format "(%s . %S)%s"
1146 (setq attributes (delq key attributes))
1148 (dolist (feature '(ideographic-radical
1151 (setq key (intern (format "%s@%s*sources" feature domain)))
1152 (when (and (memq key attributes)
1153 (setq value (get-char-attribute char key)))
1154 (insert (format "(%s%s" key line-breaking))
1155 (dolist (cell value)
1156 (insert (format " %s" cell)))
1158 (insert line-breaking)
1159 (setq attributes (delq key attributes))
1162 (when (and (memq 'ideographic-strokes attributes)
1163 (setq value (get-char-attribute char 'ideographic-strokes)))
1164 (setq strokes value)
1165 (insert (format "(ideographic-strokes . %S)%s"
1168 (setq attributes (delq 'ideographic-strokes attributes))
1170 (when (and (memq 'kangxi-radical attributes)
1171 (setq value (get-char-attribute char 'kangxi-radical)))
1172 (unless (eq value radical)
1173 (insert (format "(kangxi-radical\t . %S)\t; %c%s"
1175 (ideographic-radical value)
1178 (setq radical value)))
1179 (setq attributes (delq 'kangxi-radical attributes))
1181 (when (and (memq 'kangxi-strokes attributes)
1182 (setq value (get-char-attribute char 'kangxi-strokes)))
1183 (unless (eq value strokes)
1184 (insert (format "(kangxi-strokes\t . %S)%s"
1188 (setq strokes value)))
1189 (setq attributes (delq 'kangxi-strokes attributes))
1191 ;; (when (and (memq 'japanese-radical attributes)
1192 ;; (setq value (get-char-attribute char 'japanese-radical)))
1193 ;; (unless (eq value radical)
1194 ;; (insert (format "(japanese-radical\t . %S)\t; %c%s"
1196 ;; (ideographic-radical value)
1199 ;; (setq radical value)))
1200 ;; (setq attributes (delq 'japanese-radical attributes))
1202 (when (and (memq 'japanese-strokes attributes)
1203 (setq value (get-char-attribute char 'japanese-strokes)))
1204 (unless (eq value strokes)
1205 (insert (format "(japanese-strokes\t . %S)%s"
1209 (setq strokes value)))
1210 (setq attributes (delq 'japanese-strokes attributes))
1212 (when (and (memq 'cns-radical attributes)
1213 (setq value (get-char-attribute char 'cns-radical)))
1214 (insert (format "(cns-radical\t . %S)\t; %c%s"
1216 (ideographic-radical value)
1218 (setq attributes (delq 'cns-radical attributes))
1220 (when (and (memq 'cns-strokes attributes)
1221 (setq value (get-char-attribute char 'cns-strokes)))
1222 (unless (eq value strokes)
1223 (insert (format "(cns-strokes\t . %S)%s"
1227 (setq strokes value)))
1228 (setq attributes (delq 'cns-strokes attributes))
1230 ;; (when (and (memq 'shinjigen-1-radical attributes)
1231 ;; (setq value (get-char-attribute char 'shinjigen-1-radical)))
1232 ;; (unless (eq value radical)
1233 ;; (insert (format "(shinjigen-1-radical . %S)\t; %c%s"
1235 ;; (ideographic-radical value)
1238 ;; (setq radical value)))
1239 ;; (setq attributes (delq 'shinjigen-1-radical attributes))
1241 ;; (when (and (memq 'ideographic- attributes)
1242 ;; (setq value (get-char-attribute char 'ideographic-)))
1243 ;; (insert "(ideographic- ")
1244 ;; (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1246 ;; (while (consp value)
1247 ;; (setq cell (car value))
1248 ;; (if (integerp cell)
1249 ;; (setq cell (decode-char '=ucs cell)))
1250 ;; (cond ((characterp cell)
1254 ;; (insert (format "%S" cell))
1255 ;; (char-db-insert-char-spec cell readable))
1256 ;; (setq separator lbs))
1260 ;; (if (consp (car cell))
1261 ;; (char-db-insert-char-spec cell readable)
1262 ;; (char-db-insert-char-reference cell readable))
1263 ;; (setq separator lbs))
1266 ;; (insert separator))
1267 ;; (insert (prin1-to-string cell))
1268 ;; (setq separator " ")))
1269 ;; (setq value (cdr value)))
1271 ;; (insert line-breaking)
1272 ;; (setq attributes (delq 'ideographic- attributes)))
1273 (when (and (memq 'total-strokes attributes)
1274 (setq value (get-char-attribute char 'total-strokes)))
1275 (insert (format "(total-strokes . %S)%s"
1278 (setq attributes (delq 'total-strokes attributes))
1280 ;; (when (and (memq '->ideograph attributes)
1281 ;; (setq value (get-char-attribute char '->ideograph)))
1282 ;; (insert (format "(->ideograph\t%s)%s"
1283 ;; (mapconcat (lambda (code)
1284 ;; (cond ((symbolp code)
1285 ;; (symbol-name code))
1287 ;; (format "#x%04X" code))
1290 ;; line-breaking code))))
1293 ;; (setq attributes (delq '->ideograph attributes))
1295 ;; (when (and (memq '->decomposition attributes)
1296 ;; (setq value (get-char-attribute char '->decomposition)))
1297 ;; (insert (format "(->decomposition\t%s)%s"
1298 ;; (mapconcat (lambda (code)
1299 ;; (cond ((symbolp code)
1300 ;; (symbol-name code))
1301 ;; ((characterp code)
1303 ;; (format "%S" code)
1308 ;; (format "#x%04X" code))
1310 ;; (format "%s%S" line-breaking code))))
1313 ;; (setq attributes (delq '->decomposition attributes))
1315 (if (equal (get-char-attribute char '->titlecase)
1316 (get-char-attribute char '->uppercase))
1317 (setq attributes (delq '->titlecase attributes)))
1318 (when (and (memq '->mojikyo attributes)
1319 (setq value (get-char-attribute char '->mojikyo)))
1320 (insert (format "(->mojikyo\t\t. %06d)\t; %c%s"
1321 value (decode-char 'mojikyo value)
1323 (setq attributes (delq '->mojikyo attributes))
1325 ;; (when (and (memq 'hanyu-dazidian-vol attributes)
1326 ;; (setq value (get-char-attribute char 'hanyu-dazidian-vol)))
1327 ;; (insert (format "(hanyu-dazidian-vol . %d)%s"
1328 ;; value line-breaking))
1329 ;; (setq attributes (delq 'hanyu-dazidian-vol attributes))
1331 ;; (when (and (memq 'hanyu-dazidian-page attributes)
1332 ;; (setq value (get-char-attribute char 'hanyu-dazidian-page)))
1333 ;; (insert (format "(hanyu-dazidian-page . %d)%s"
1334 ;; value line-breaking))
1335 ;; (setq attributes (delq 'hanyu-dazidian-page attributes))
1337 ;; (when (and (memq 'hanyu-dazidian-char attributes)
1338 ;; (setq value (get-char-attribute char 'hanyu-dazidian-char)))
1339 ;; (insert (format "(hanyu-dazidian-char . %d)%s"
1340 ;; value line-breaking))
1341 ;; (setq attributes (delq 'hanyu-dazidian-char attributes))
1344 (dolist (ignored '(composition
1345 ->denotational <-subsumptive ->ucs-unified
1346 ->ideographic-component-forms))
1347 (setq attributes (delq ignored attributes))))
1349 (setq name (car attributes))
1350 (unless (eq (setq value (get-char-attribute char name 'value-is-empty))
1352 (cond ((setq ret (find-charset name))
1353 (setq name (charset-name ret))
1354 (when (not (memq name dest-ccss))
1355 (setq dest-ccss (cons name dest-ccss))
1356 (char-db-insert-ccs-feature name value line-breaking))
1358 ((string-match "^=>ucs@" (symbol-name name))
1359 (insert (format "(%-18s . #x%04X)\t; %c%s"
1360 name value (decode-char '=ucs value)
1363 ((eq name 'jisx0208-1978/4X)
1364 (insert (format "(%-18s . #x%04X)%s"
1370 (not (eq name '->subsumptive))
1371 (not (eq name '->uppercase))
1372 (not (eq name '->lowercase))
1373 (not (eq name '->titlecase))
1374 (not (eq name '->canonical))
1375 (not (eq name '->Bopomofo))
1376 (not (eq name '->mistakable))
1377 (not (eq name '->ideographic-variants))
1378 (null (get-char-attribute
1379 char (intern (format "%s*sources" name))))
1380 (not (string-match "\\*sources$" (symbol-name name)))
1381 (null (get-char-attribute
1382 char (intern (format "%s*note" name))))
1383 (not (string-match "\\*note$" (symbol-name name)))
1384 (or (eq name '<-identical)
1385 (eq name '<-uppercase)
1386 (eq name '<-lowercase)
1387 (eq name '<-titlecase)
1388 (eq name '<-canonical)
1389 (eq name '<-ideographic-variants)
1390 ;; (eq name '<-synonyms)
1391 (string-match "^<-synonyms" (symbol-name name))
1392 (eq name '<-mistakable)
1393 (when (string-match "^->" (symbol-name name))
1395 ((string-match "^->fullwidth" (symbol-name name))
1396 (not (and (consp value)
1397 (characterp (car value))
1399 (car value) '=ucs 'defined-only)))
1404 ((or (eq name 'ideographic-structure)
1405 (eq name 'ideographic-combination)
1406 ;; (eq name 'ideographic-)
1407 (eq name '=decomposition)
1408 (char-feature-base-name= '=decomposition name)
1409 (char-feature-base-name= '=>decomposition name)
1410 ;; (string-match "^=>*decomposition\\(@[^*]+\\)?$"
1411 ;; (symbol-name name))
1412 (string-match "^\\(->\\|<-\\)[^*]*$" (symbol-name name))
1413 (string-match "^\\(->\\|<-\\)[^*]*\\*sources$"
1416 (char-db-insert-relation-feature char name value
1419 ;; ((memq name '(ideograph=
1420 ;; original-ideograph-of
1421 ;; ancient-ideograph-of
1422 ;; vulgar-ideograph-of
1423 ;; wrong-ideograph-of
1424 ;; ;; simplified-ideograph-of
1425 ;; ideographic-variants
1426 ;; ;; ideographic-different-form-of
1428 ;; (insert (format "(%-18s%s " name line-breaking))
1429 ;; (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1431 ;; (while (consp value)
1432 ;; (setq cell (car value))
1433 ;; (if (and (consp cell)
1434 ;; (consp (car cell)))
1438 ;; (char-db-insert-alist cell readable)
1439 ;; (setq separator lbs))
1441 ;; (insert separator))
1442 ;; (insert (prin1-to-string cell))
1443 ;; (setq separator " "))
1444 ;; (setq value (cdr value)))
1446 ;; (insert line-breaking))
1448 (insert (format "(%-18s " name))
1449 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1451 (while (consp value)
1452 (setq cell (car value))
1453 (if (and (consp cell)
1455 (setq ret (condition-case nil
1463 (setq key (car (car rest)))
1464 (if (find-charset key)
1465 (setq cal (cons key cal))
1466 (setq al (cons key al)))
1467 (setq rest (cdr rest)))
1470 (insert-char-attributes ret
1474 (setq separator lbs))
1475 (setq ret (prin1-to-string cell))
1477 (if (< (+ (current-column)
1484 (setq separator " "))
1485 (setq value (cdr value)))
1487 (insert line-breaking))
1489 (insert (format "(%-18s" name))
1490 (setq ret (prin1-to-string value))
1491 (unless (< (+ (current-column)
1495 (insert line-breaking))
1496 (insert " . " ret ")" line-breaking)
1497 ;; (insert (format "(%-18s . %S)%s"
1502 (setq attributes (cdr attributes)))
1505 (defun insert-char-data (char &optional readable
1508 (narrow-to-region (point)(point))
1509 (insert "(define-char
1511 (insert-char-attributes char readable attributes)
1513 (goto-char (point-min))
1514 (while (re-search-forward "[ \t]+$" nil t)
1517 (goto-char (point-min))
1518 (while (re-search-forward "[ \t][ \t][ \t]*" nil t)
1519 (let ((column (current-column))
1520 (indent-tabs-mode t))
1521 (delete-region (match-beginning 0) (point))
1522 (indent-to column)))
1523 (goto-char (point-max))
1524 ;; (tabify (point-min)(point-max))
1527 (defun insert-char-data-with-variant (char &optional printable
1529 script excluded-script)
1530 (insert-char-data char printable)
1531 (let ((variants (char-variants char))
1534 (setq variants (sort variants #'<))
1535 (setq rest variants)
1536 (setq variants (cons char variants))
1538 (setq variant (car rest))
1539 (unless (get-char-attribute variant '<-subsumptive)
1540 (if (and (or (null script)
1541 (null (setq vs (get-char-attribute variant 'script)))
1543 (or (null excluded-script)
1544 (null (setq vs (get-char-attribute variant 'script)))
1545 (not (memq excluded-script vs))))
1546 (unless (and no-ucs-unified (get-char-attribute variant '=ucs))
1547 (insert-char-data variant printable)
1548 (if (setq ret (char-variants variant))
1550 (or (memq (car ret) variants)
1551 ;; (get-char-attribute (car ret) '<-subsumptive)
1552 (setq rest (nconc rest (list (car ret)))))
1553 (setq ret (cdr ret)))))))
1554 (setq rest (cdr rest)))))
1556 (defun insert-char-range-data (min max &optional script excluded-script)
1559 (while (<= code max)
1560 (setq char (decode-char '=ucs code))
1561 (if (encode-char char '=ucs 'defined-only)
1562 (insert-char-data-with-variant char nil 'no-ucs-unified
1563 script excluded-script))
1564 (setq code (1+ code)))))
1566 (defun write-char-range-data-to-file (min max file
1567 &optional script excluded-script)
1568 (let ((coding-system-for-write char-db-file-coding-system))
1570 (insert (format ";; -*- coding: %s -*-\n"
1571 char-db-file-coding-system))
1572 (insert-char-range-data min max script excluded-script)
1573 (write-region (point-min)(point-max) file))))
1575 (defvar what-character-original-window-configuration)
1578 (defun what-char-definition (char)
1579 (interactive (list (char-after)))
1580 (let ((buf (get-buffer-create "*Character Description*"))
1581 (the-buf (current-buffer))
1582 (win-conf (current-window-configuration)))
1584 (make-local-variable 'what-character-original-window-configuration)
1585 (setq what-character-original-window-configuration win-conf)
1586 (setq buffer-read-only nil)
1590 (insert-char-data-with-variant char 'printable)
1591 (unless (char-attribute-alist char)
1592 (insert (format ";; = %c\n"
1593 (let* ((rest (split-char char))
1597 (setq code (logior (lsh code 8)
1599 (decode-char ccs code)))))
1600 ;; (char-db-update-comment)
1601 (set-buffer-modified-p nil)
1602 (view-mode the-buf (lambda (buf)
1603 (set-window-configuration
1604 what-character-original-window-configuration)
1606 (goto-char (point-min)))
1608 (set-window-configuration
1609 what-character-original-window-configuration)
1610 (signal (car err) (cdr err)))))))
1616 (provide 'char-db-util)
1618 ;;; char-db-util.el ends here