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 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
365 =>big5-cdp-itaiji-001
373 ;;; @ char-db formatters
376 (defun char-db-make-char-spec (char)
378 (cond ((characterp char)
379 (cond ((and (setq ret (encode-char char '=ucs 'defined-only))
380 (not (and (<= #xE000 ret)(<= ret #xF8FF))))
381 (setq char-spec (list (cons '=ucs ret)))
382 (cond ((setq ret (get-char-attribute char 'name))
383 (setq char-spec (cons (cons 'name ret) char-spec))
385 ((setq ret (get-char-attribute char 'name*))
386 (setq char-spec (cons (cons 'name* ret) char-spec))
389 ((encode-char char '=mj 'defined-only)
391 (dolist (ccs (charset-list))
392 (if (and (or (eq ccs '=mj)
393 ;; (eq (charset-property ccs 'iso-ir) 177)
394 (string-match "=ucs@" (symbol-name ccs))
396 (setq ccs (charset-name ccs))
397 (null (assq ccs char-spec))
398 (setq ret (encode-char char ccs 'defined-only)))
399 (setq char-spec (cons (cons ccs ret) char-spec))))
401 ((encode-char char '==mj 'defined-only)
403 (dolist (ccs (charset-list))
404 (if (and (or (eq ccs '==mj)
405 ;; (eq (charset-property ccs 'iso-ir) 177)
406 (string-match "=ucs@" (symbol-name ccs))
408 (setq ccs (charset-name ccs))
409 (null (assq ccs char-spec))
410 (setq ret (encode-char char ccs 'defined-only)))
411 (setq char-spec (cons (cons ccs ret) char-spec))))
413 ((encode-char char '=adobe-japan1 'defined-only)
415 (dolist (ccs (charset-list))
416 (if (and (or (memq ccs
425 ;; (eq (charset-property ccs 'iso-ir) 177)
426 (string-match "=ucs@" (symbol-name ccs))
428 (setq ccs (charset-name ccs))
429 (null (assq ccs char-spec))
430 (setq ret (encode-char char ccs 'defined-only)))
431 (setq char-spec (cons (cons ccs ret) char-spec))))
433 ((encode-char char '==adobe-japan1 'defined-only)
435 (dolist (ccs (charset-list))
436 (if (and (or (memq ccs
445 ;; (eq (charset-property ccs 'iso-ir) 177)
446 (string-match "=ucs@" (symbol-name ccs))
448 (setq ccs (charset-name ccs))
449 (null (assq ccs char-spec))
450 (setq ret (encode-char char ccs 'defined-only)))
451 (setq char-spec (cons (cons ccs ret) char-spec))))
455 (let ((rest char-db-coded-charset-priority-list)
458 (setq ccs (charset-name
459 (find-charset (car rest))))
461 (encode-char char ccs
463 (throw 'tag (cons ccs ret)))
464 (setq rest (cdr rest))))))
465 (setq char-spec (list ret))
466 (dolist (ccs (delq (car ret) (charset-list)))
467 (if (and (or (charset-iso-final-char ccs)
474 (eq (charset-property ccs 'iso-ir) 177)
475 ;; (string-match "=ucs@" (symbol-name ccs))
477 (setq ccs (charset-name ccs))
478 (null (assq ccs char-spec))
479 (setq ret (encode-char char ccs 'defined-only)))
480 (setq char-spec (cons (cons ccs ret) char-spec))))
482 (setq char-spec (split-char char)))
483 (cond ((setq ret (get-char-attribute char 'name))
484 (setq char-spec (cons (cons 'name ret) char-spec))
486 ((setq ret (get-char-attribute char 'name*))
487 (setq char-spec (cons (cons 'name* ret) char-spec))
490 ((setq ret (get-char-attribute
491 char 'ideographic-combination))
493 (cons (cons 'ideographic-combination ret)
500 (defun char-db-insert-char-spec (char &optional readable column
503 (setq column (current-column)))
504 (let (char-spec temp-char)
505 (setq char-spec (char-db-make-char-spec char))
506 (unless (or (characterp char) ; char
508 (setq char (find-char char-spec))
510 ;; define temporary character
511 ;; Current implementation is dirty.
512 (setq temp-char (define-char (cons '(ideograph-daikanwa . 0)
514 (remove-char-attribute temp-char 'ideograph-daikanwa)
515 (setq char temp-char))
516 (insert-char-attributes char
518 (union (mapcar #'car char-spec)
522 ;; undefine temporary character
523 ;; Current implementation is dirty.
524 (setq char-spec (char-attribute-alist temp-char))
526 (remove-char-attribute temp-char (car (car char-spec)))
527 (setq char-spec (cdr char-spec))))))
529 (defun char-db-insert-alist (alist &optional readable column)
531 (setq column (current-column)))
533 (concat "\n" (make-string (1+ column) ?\ )))
537 lbs cell rest separator)
540 (setq name (car (car alist))
541 value (cdr (car alist)))
542 (cond ((eq name 'char)
544 (if (setq ret (condition-case nil
552 (setq key (car (car value)))
553 ;; (if (find-charset key)
554 ;; (setq cal (cons key cal))
555 (setq al (cons key al))
557 (setq value (cdr value)))
558 (insert-char-attributes ret
562 (insert (prin1-to-string value)))
564 (insert line-breaking))
566 (insert (format "(%-18s " name))
567 (setq lbs (concat "\n" (make-string (current-column) ?\ )))
569 (setq cell (car value))
570 (if (and (consp cell)
572 (setq ret (condition-case nil
582 (setq key (car (car rest)))
583 ;; (if (find-charset key)
584 ;; (setq cal (cons key cal))
585 (setq al (cons key al))
587 (setq rest (cdr rest)))
590 (insert-char-attributes ret
594 (setq separator lbs))
597 (insert (prin1-to-string cell))
598 (setq separator " "))
599 (setq value (cdr value)))
601 (insert line-breaking))
603 (insert (format "(%-18s . %S)%s"
606 (setq alist (cdr alist))))
609 (defun char-db-insert-char-reference (plist &optional readable column)
611 (setq column (current-column)))
613 (concat "\n" (make-string (1+ column) ?\ )))
618 (setq name (pop plist))
619 (setq value (pop plist))
620 (cond ((eq name :char)
623 (cond ((numberp value)
624 (setq value (decode-char '=ucs value)))
626 ;; (setq value (or (find-char value)
629 (char-db-insert-char-spec value readable)
630 (insert line-breaking)
633 (insert (format "%s%s\t%d ; %c%s"
636 (ideographic-radical value)
640 (insert (format "%s%s\t%S" separator name value))
641 (setq separator line-breaking)))
645 (defun char-db-decode-isolated-char (ccs code-point)
648 (cond ((eq ccs 'arabic-iso8859-6)
649 (decode-char ccs code-point))
651 ;; (decode-builtin-char '==gt code-point))
652 ((and (memq ccs '(=gt-pj-1
663 (setq ret (decode-char ccs code-point))
664 (setq ret (encode-char ret '=gt 'defined-only)))
665 (decode-builtin-char '=gt ret))
667 (decode-builtin-char ccs code-point))))
669 (or (decode-char ccs code-point)
670 (define-char (list (cons ccs code-point)))))
671 ((and (<= 0 (char-int ret))
672 (<= (char-int ret) #x1F))
673 (decode-char '=ucs (+ #x2400 (char-int ret))))
674 ((= (char-int ret) #x7F)
678 (defvar char-db-convert-obsolete-format t)
680 (defun char-db-insert-ccs-feature (name value line-breaking)
686 ((memq name '(=>iwds-1
689 =shinjigen@1ed ==shinjigen@1ed
690 =shinjigen@rev ==shinjigen@rev
691 =shinjigen/+p@rev ==shinjigen/+p@rev
692 ===daikanwa/ho ==daikanwa/ho
693 =daikanwa/ho =>>daikanwa/ho =>daikanwa/ho))
694 "(%-18s . %04d)\t; %c")
695 ((eq name '=shinjigen@1ed/24pr)
696 "(%-18s . %04d)\t; %c")
700 ==daikanwa =daikanwa =>>daikanwa =>daikanwa
701 =daikanwa@rev1 =daikanwa@rev2
702 =daikanwa/+p ==daikanwa/+p ===daikanwa/+p
704 =daikanwa/+2p =>>daikanwa/+2p
709 =adobe-japan1-0 ==adobe-japan1-0 ===adobe-japan1-0
710 =adobe-japan1-1 ==adobe-japan1-1 ===adobe-japan1-1
711 =adobe-japan1-2 ==adobe-japan1-2 ===adobe-japan1-2
712 =adobe-japan1-3 ==adobe-japan1-3 ===adobe-japan1-3
713 =adobe-japan1-4 ==adobe-japan1-4 ===adobe-japan1-4
714 =adobe-japan1-5 ==adobe-japan1-5 ===adobe-japan1-5
715 =adobe-japan1-6 ==adobe-japan1-6 ===adobe-japan1-6
716 =>>adobe-japan1-0 =+>adobe-japan1-0
717 =>>adobe-japan1-1 =+>adobe-japan1-1
718 =>>adobe-japan1-2 =+>adobe-japan1-2
719 =>>adobe-japan1-3 =+>adobe-japan1-3
720 =>>adobe-japan1-4 =+>adobe-japan1-4
721 =>>adobe-japan1-5 =+>adobe-japan1-5
722 =>>adobe-japan1-6 =+>adobe-japan1-6
723 =>cbeta =cbeta =>>cbeta ==cbeta ===cbeta
724 =zinbun-oracle =>zinbun-oracle
725 ===hng-jou ===hng-keg ===hng-dng ===hng-mam
726 ===hng-drt ===hng-kgk ===hng-myz ===hng-kda
727 ===hng-khi ===hng-khm ===hng-hok ===hng-kyd ===hng-sok
728 ===hng-yhk ===hng-kak ===hng-kar ===hng-kae
729 ===hng-sys ===hng-tsu ===hng-tzj
730 ===hng-hos ===hng-nak ===hng-jhk
731 ===hng-hod ===hng-gok ===hng-ink ===hng-nto
732 ===hng-nkm ===hng-k24 ===hng-nkk
733 ===hng-kcc ===hng-kcj ===hng-kbk ===hng-sik
734 ===hng-skk ===hng-kyu ===hng-ksk ===hng-wan
735 ===hng-okd ===hng-wad ===hng-kmi
736 ===hng-zkd ===hng-doh ===hng-jyu
737 ===hng-tzs ===hng-kss ===hng-kyo
739 ;; (string-match "^=adobe-" (symbol-name name))
741 "(%-18s . %05d)\t; %c")
742 ((memq name '(=hanyo-denshi/ks
743 ==hanyo-denshi/ks ===hanyo-denshi/ks
746 =mj ==mj ===mj =>>mj =>mj
748 "(%-18s . %06d)\t; %c")
749 ((memq name '(=hanyo-denshi/tk ==hanyo-denshi/tk))
750 "(%-18s . %08d)\t; %c")
751 ((>= (charset-dimension name) 2)
752 "(%-18s . #x%04X)\t; %c")
754 "(%-18s . #x%02X)\t; %c"))
756 (if (= (charset-iso-graphic-plane name) 1)
758 (cond ((= (charset-dimension name) 1)
760 ((= (charset-dimension name) 2)
762 ((= (charset-dimension name) 3)
766 (char-db-decode-isolated-char name value)))
767 (if (and (= (charset-chars name) 94)
768 (= (charset-dimension name) 2))
769 (insert (format " [%02d-%02d]"
770 (- (lsh value -8) 32)
771 (- (logand value 255) 32))))
774 (insert (format "(%-18s . %s)" name value))
776 (insert line-breaking))
778 (defun char-db-insert-relation-feature (char name value line-breaking
780 (insert (format "(%-18s%s " name line-breaking))
781 (let ((lbs (concat "\n" (make-string (current-column) ?\ )))
782 separator cell sources required-features
785 (setq cell (car value))
787 (setq cell (decode-char '=ucs cell)))
789 ((eq name '->subsumptive)
790 (when (or (not (some (lambda (atr)
791 (get-char-attribute cell atr))
792 char-db-ignored-attributes))
794 (encode-char cell ccs 'defined-only))
798 (let ((char-db-ignored-attributes
800 char-db-ignored-attributes)))
801 (insert-char-attributes cell readable nil nil 'for-sub-node))
802 (setq separator lbs))
807 char (intern (format "%s*sources" name))))
808 (setq required-features nil)
809 (dolist (source sources)
813 shinjigen shinjigen@1ed shinjigen@rev))
814 (setq required-features
815 (union required-features
827 =shinjigen/+p@rev))))
829 (setq required-features
830 (union required-features
835 ((find-charset (setq ret (intern (format "=%s" source))))
836 (setq required-features
837 (cons ret required-features)))
838 (t (setq required-features
839 (cons source required-features)))))
840 (cond ((string-match "@JP" (symbol-name name))
841 (setq required-features
842 (union required-features
850 ((string-match "@CN" (symbol-name name))
851 (setq required-features
852 (union required-features
859 (insert (format "%S" cell))
860 (char-db-insert-char-spec cell readable
863 (setq separator lbs))
867 (if (consp (car cell))
868 (char-db-insert-char-spec cell readable)
869 (char-db-insert-char-reference cell readable))
870 (setq separator lbs))
874 (insert (prin1-to-string cell))
875 (setq separator " ")))
876 (setq value (cdr value)))
878 (insert line-breaking)))
880 (defun insert-char-attributes (char &optional readable attributes column
883 (setq column (current-column)))
884 (let (name value ; has-long-ccs-name
888 (concat "\n" (make-string (1+ column) ?\ )))
889 lbs cell separator ret
891 dest-ccss ; sources required-features
896 (if (consp attributes)
898 (dolist (name attributes)
899 (unless (memq name char-db-ignored-attributes)
900 (if (find-charset name)
904 (dolist (name (char-attribute-list))
905 (unless (memq name char-db-ignored-attributes)
906 (if (find-charset name)
910 #'char-attribute-name<)))
912 (when (memq '<-subsumptive attributes)
913 (when (or readable (not for-sub-node))
914 (when (setq value (get-char-attribute char '<-subsumptive))
915 (char-db-insert-relation-feature char '<-subsumptive value
918 (setq attributes (delq '<-subsumptive attributes)))
919 (when (and (memq '<-denotational attributes)
920 (setq value (get-char-attribute char '<-denotational)))
921 (char-db-insert-relation-feature char '<-denotational value
924 (setq attributes (delq '<-denotational attributes)))
925 (when (and (memq '<-denotational@component attributes)
926 (setq value (get-char-attribute char '<-denotational@component)))
927 (char-db-insert-relation-feature char '<-denotational@component value
930 (setq attributes (delq '<-denotational@component attributes)))
931 (when (and (memq 'name attributes)
932 (setq value (get-char-attribute char 'name)))
934 (if (> (+ (current-column) (length value)) 48)
937 value line-breaking))
938 (setq attributes (delq 'name attributes))
940 (when (and (memq 'name* attributes)
941 (setq value (get-char-attribute char 'name*)))
943 (if (> (+ (current-column) (length value)) 48)
946 value line-breaking))
947 (setq attributes (delq 'name* attributes))
949 (when (and (memq 'script attributes)
950 (setq value (get-char-attribute char 'script)))
951 (insert (format "(script\t\t%s)%s"
952 (mapconcat (function prin1-to-string)
955 (setq attributes (delq 'script attributes))
957 (dolist (name '(=>ucs =>ucs*))
958 (when (and (memq name attributes)
959 (setq value (get-char-attribute char name)))
960 (insert (format "(%-18s . #x%04X)\t; %c%s"
961 name value (decode-char '=ucs value)
963 (setq attributes (delq name attributes))))
964 (dolist (name '(=>ucs@gb =>ucs@big5))
965 (when (and (memq name attributes)
966 (setq value (get-char-attribute char name)))
967 (insert (format "(%-18s . #x%04X)\t; %c%s"
972 (symbol-name name) 2)))
975 (setq attributes (delq name attributes))
977 ;; (dolist (name '(=>daikanwa))
978 ;; (when (and (memq name attributes)
979 ;; (setq value (get-char-attribute char name)))
981 ;; (if (integerp value)
982 ;; (format "(%-18s . %05d)\t; %c%s"
983 ;; name value (decode-char '=daikanwa value)
985 ;; (format "(%-18s %s)\t; %c%s"
987 ;; (mapconcat (function prin1-to-string)
989 ;; (char-representative-of-daikanwa char)
991 ;; (setq attributes (delq name attributes))))
992 (when (and (memq 'general-category attributes)
993 (setq value (get-char-attribute char 'general-category)))
995 "(general-category\t%s) ; %s%s"
996 (mapconcat (lambda (cell)
999 (cond ((rassoc value unidata-normative-category-alist)
1000 "Normative Category")
1001 ((rassoc value unidata-informative-category-alist)
1002 "Informative Category")
1004 "Unknown Category"))
1006 (setq attributes (delq 'general-category attributes))
1008 (when (and (memq 'bidi-category attributes)
1009 (setq value (get-char-attribute char 'bidi-category)))
1010 (insert (format "(bidi-category\t. %S)%s"
1013 (setq attributes (delq 'bidi-category attributes))
1015 (unless (or (not (memq 'mirrored attributes))
1016 (eq (setq value (get-char-attribute char 'mirrored 'empty))
1018 (insert (format "(mirrored\t\t. %S)%s"
1021 (setq attributes (delq 'mirrored attributes))
1024 ((and (memq 'decimal-digit-value attributes)
1025 (setq value (get-char-attribute char 'decimal-digit-value)))
1026 (insert (format "(decimal-digit-value . %S)%s"
1029 (setq attributes (delq 'decimal-digit-value attributes))
1030 (when (and (memq 'digit-value attributes)
1031 (setq value (get-char-attribute char 'digit-value)))
1032 (insert (format "(digit-value\t . %S)%s"
1035 (setq attributes (delq 'digit-value attributes))
1037 (when (and (memq 'numeric-value attributes)
1038 (setq value (get-char-attribute char 'numeric-value)))
1039 (insert (format "(numeric-value\t . %S)%s"
1042 (setq attributes (delq 'numeric-value attributes))
1046 (when (and (memq 'digit-value attributes)
1047 (setq value (get-char-attribute char 'digit-value)))
1048 (insert (format "(digit-value\t. %S)%s"
1051 (setq attributes (delq 'digit-value attributes))
1053 (when (and (memq 'numeric-value attributes)
1054 (setq value (get-char-attribute char 'numeric-value)))
1055 (insert (format "(numeric-value\t. %S)%s"
1058 (setq attributes (delq 'numeric-value attributes))
1060 (when (and (memq 'iso-10646-comment attributes)
1061 (setq value (get-char-attribute char 'iso-10646-comment)))
1062 (insert (format "(iso-10646-comment\t. %S)%s"
1065 (setq attributes (delq 'iso-10646-comment attributes))
1067 (when (and (memq 'morohashi-daikanwa attributes)
1068 (setq value (get-char-attribute char 'morohashi-daikanwa)))
1069 (insert (format "(morohashi-daikanwa\t%s)%s"
1070 (mapconcat (function prin1-to-string) value " ")
1072 (setq attributes (delq 'morohashi-daikanwa attributes))
1076 (when (and (memq 'ideographic-radical attributes)
1077 (setq value (get-char-attribute char 'ideographic-radical)))
1078 (setq radical value)
1079 (insert (format "(ideographic-radical . %S)\t; %c%s"
1081 (ideographic-radical radical)
1083 (setq attributes (delq 'ideographic-radical attributes))
1085 (when (and (memq 'shuowen-radical attributes)
1086 (setq value (get-char-attribute char 'shuowen-radical)))
1087 (insert (format "(shuowen-radical\t. %S)\t; %c%s"
1089 (shuowen-radical value)
1091 (setq attributes (delq 'shuowen-radical attributes))
1096 char-db-feature-domains
1098 (dolist (feature (char-attribute-list))
1099 (setq feature (symbol-name feature))
1101 "\\(radical\\|strokes\\)@\\([^@*]+\\)\\(\\*\\|$\\)"
1103 (setq domain (intern (match-string 2 feature)))
1104 (unless (memq domain dest)
1105 (setq dest (cons domain dest)))))
1106 (sort dest #'string<))))
1107 (setq key (intern (format "%s@%s" 'ideographic-radical domain)))
1108 (when (and (memq key attributes)
1109 (setq value (get-char-attribute char key)))
1110 (setq radical value)
1111 (insert (format "(%s . %S)\t; %c%s"
1114 (ideographic-radical radical)
1116 (setq attributes (delq key attributes))
1118 (setq key (intern (format "%s@%s" 'ideographic-strokes domain)))
1119 (when (and (memq key attributes)
1120 (setq value (get-char-attribute char key)))
1121 (setq strokes value)
1122 (insert (format "(%s . %S)%s"
1126 (setq attributes (delq key attributes))
1128 (setq key (intern (format "%s@%s" 'total-strokes domain)))
1129 (when (and (memq key attributes)
1130 (setq value (get-char-attribute char key)))
1131 (insert (format "(%s . %S)%s"
1135 (setq attributes (delq key attributes))
1137 (dolist (feature '(ideographic-radical
1140 (setq key (intern (format "%s@%s*sources" feature domain)))
1141 (when (and (memq key attributes)
1142 (setq value (get-char-attribute char key)))
1143 (insert (format "(%s%s" key line-breaking))
1144 (dolist (cell value)
1145 (insert (format " %s" cell)))
1147 (insert line-breaking)
1148 (setq attributes (delq key attributes))
1151 (when (and (memq 'ideographic-strokes attributes)
1152 (setq value (get-char-attribute char 'ideographic-strokes)))
1153 (setq strokes value)
1154 (insert (format "(ideographic-strokes . %S)%s"
1157 (setq attributes (delq 'ideographic-strokes attributes))
1159 (when (and (memq 'kangxi-radical attributes)
1160 (setq value (get-char-attribute char 'kangxi-radical)))
1161 (unless (eq value radical)
1162 (insert (format "(kangxi-radical\t . %S)\t; %c%s"
1164 (ideographic-radical value)
1167 (setq radical value)))
1168 (setq attributes (delq 'kangxi-radical attributes))
1170 (when (and (memq 'kangxi-strokes attributes)
1171 (setq value (get-char-attribute char 'kangxi-strokes)))
1172 (unless (eq value strokes)
1173 (insert (format "(kangxi-strokes\t . %S)%s"
1177 (setq strokes value)))
1178 (setq attributes (delq 'kangxi-strokes attributes))
1180 ;; (when (and (memq 'japanese-radical attributes)
1181 ;; (setq value (get-char-attribute char 'japanese-radical)))
1182 ;; (unless (eq value radical)
1183 ;; (insert (format "(japanese-radical\t . %S)\t; %c%s"
1185 ;; (ideographic-radical value)
1188 ;; (setq radical value)))
1189 ;; (setq attributes (delq 'japanese-radical attributes))
1191 (when (and (memq 'japanese-strokes attributes)
1192 (setq value (get-char-attribute char 'japanese-strokes)))
1193 (unless (eq value strokes)
1194 (insert (format "(japanese-strokes\t . %S)%s"
1198 (setq strokes value)))
1199 (setq attributes (delq 'japanese-strokes attributes))
1201 (when (and (memq 'cns-radical attributes)
1202 (setq value (get-char-attribute char 'cns-radical)))
1203 (insert (format "(cns-radical\t . %S)\t; %c%s"
1205 (ideographic-radical value)
1207 (setq attributes (delq 'cns-radical attributes))
1209 (when (and (memq 'cns-strokes attributes)
1210 (setq value (get-char-attribute char 'cns-strokes)))
1211 (unless (eq value strokes)
1212 (insert (format "(cns-strokes\t . %S)%s"
1216 (setq strokes value)))
1217 (setq attributes (delq 'cns-strokes attributes))
1219 ;; (when (and (memq 'shinjigen-1-radical attributes)
1220 ;; (setq value (get-char-attribute char 'shinjigen-1-radical)))
1221 ;; (unless (eq value radical)
1222 ;; (insert (format "(shinjigen-1-radical . %S)\t; %c%s"
1224 ;; (ideographic-radical value)
1227 ;; (setq radical value)))
1228 ;; (setq attributes (delq 'shinjigen-1-radical attributes))
1230 ;; (when (and (memq 'ideographic- attributes)
1231 ;; (setq value (get-char-attribute char 'ideographic-)))
1232 ;; (insert "(ideographic- ")
1233 ;; (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1235 ;; (while (consp value)
1236 ;; (setq cell (car value))
1237 ;; (if (integerp cell)
1238 ;; (setq cell (decode-char '=ucs cell)))
1239 ;; (cond ((characterp cell)
1243 ;; (insert (format "%S" cell))
1244 ;; (char-db-insert-char-spec cell readable))
1245 ;; (setq separator lbs))
1249 ;; (if (consp (car cell))
1250 ;; (char-db-insert-char-spec cell readable)
1251 ;; (char-db-insert-char-reference cell readable))
1252 ;; (setq separator lbs))
1255 ;; (insert separator))
1256 ;; (insert (prin1-to-string cell))
1257 ;; (setq separator " ")))
1258 ;; (setq value (cdr value)))
1260 ;; (insert line-breaking)
1261 ;; (setq attributes (delq 'ideographic- attributes)))
1262 (when (and (memq 'total-strokes attributes)
1263 (setq value (get-char-attribute char 'total-strokes)))
1264 (insert (format "(total-strokes . %S)%s"
1267 (setq attributes (delq 'total-strokes attributes))
1269 ;; (when (and (memq '->ideograph attributes)
1270 ;; (setq value (get-char-attribute char '->ideograph)))
1271 ;; (insert (format "(->ideograph\t%s)%s"
1272 ;; (mapconcat (lambda (code)
1273 ;; (cond ((symbolp code)
1274 ;; (symbol-name code))
1276 ;; (format "#x%04X" code))
1279 ;; line-breaking code))))
1282 ;; (setq attributes (delq '->ideograph attributes))
1284 ;; (when (and (memq '->decomposition attributes)
1285 ;; (setq value (get-char-attribute char '->decomposition)))
1286 ;; (insert (format "(->decomposition\t%s)%s"
1287 ;; (mapconcat (lambda (code)
1288 ;; (cond ((symbolp code)
1289 ;; (symbol-name code))
1290 ;; ((characterp code)
1292 ;; (format "%S" code)
1297 ;; (format "#x%04X" code))
1299 ;; (format "%s%S" line-breaking code))))
1302 ;; (setq attributes (delq '->decomposition attributes))
1304 (if (equal (get-char-attribute char '->titlecase)
1305 (get-char-attribute char '->uppercase))
1306 (setq attributes (delq '->titlecase attributes)))
1307 (when (and (memq '->mojikyo attributes)
1308 (setq value (get-char-attribute char '->mojikyo)))
1309 (insert (format "(->mojikyo\t\t. %06d)\t; %c%s"
1310 value (decode-char 'mojikyo value)
1312 (setq attributes (delq '->mojikyo attributes))
1314 ;; (when (and (memq 'hanyu-dazidian-vol attributes)
1315 ;; (setq value (get-char-attribute char 'hanyu-dazidian-vol)))
1316 ;; (insert (format "(hanyu-dazidian-vol . %d)%s"
1317 ;; value line-breaking))
1318 ;; (setq attributes (delq 'hanyu-dazidian-vol attributes))
1320 ;; (when (and (memq 'hanyu-dazidian-page attributes)
1321 ;; (setq value (get-char-attribute char 'hanyu-dazidian-page)))
1322 ;; (insert (format "(hanyu-dazidian-page . %d)%s"
1323 ;; value line-breaking))
1324 ;; (setq attributes (delq 'hanyu-dazidian-page attributes))
1326 ;; (when (and (memq 'hanyu-dazidian-char attributes)
1327 ;; (setq value (get-char-attribute char 'hanyu-dazidian-char)))
1328 ;; (insert (format "(hanyu-dazidian-char . %d)%s"
1329 ;; value line-breaking))
1330 ;; (setq attributes (delq 'hanyu-dazidian-char attributes))
1333 (dolist (ignored '(composition
1334 ->denotational <-subsumptive ->ucs-unified
1335 ->ideographic-component-forms))
1336 (setq attributes (delq ignored attributes))))
1338 (setq name (car attributes))
1339 (unless (eq (setq value (get-char-attribute char name 'value-is-empty))
1341 (cond ((setq ret (find-charset name))
1342 (setq name (charset-name ret))
1343 (when (not (memq name dest-ccss))
1344 (setq dest-ccss (cons name dest-ccss))
1345 (char-db-insert-ccs-feature name value line-breaking))
1347 ((string-match "^=>ucs@" (symbol-name name))
1348 (insert (format "(%-18s . #x%04X)\t; %c%s"
1349 name value (decode-char '=ucs value)
1352 ((eq name 'jisx0208-1978/4X)
1353 (insert (format "(%-18s . #x%04X)%s"
1359 (not (eq name '->subsumptive))
1360 (not (eq name '->uppercase))
1361 (not (eq name '->lowercase))
1362 (not (eq name '->titlecase))
1363 (not (eq name '->canonical))
1364 (not (eq name '->Bopomofo))
1365 (not (eq name '->mistakable))
1366 (not (eq name '->ideographic-variants))
1367 (null (get-char-attribute
1368 char (intern (format "%s*sources" name))))
1369 (not (string-match "\\*sources$" (symbol-name name)))
1370 (null (get-char-attribute
1371 char (intern (format "%s*note" name))))
1372 (not (string-match "\\*note$" (symbol-name name)))
1373 (or (eq name '<-identical)
1374 (eq name '<-uppercase)
1375 (eq name '<-lowercase)
1376 (eq name '<-titlecase)
1377 (eq name '<-canonical)
1378 (eq name '<-ideographic-variants)
1379 ;; (eq name '<-synonyms)
1380 (string-match "^<-synonyms" (symbol-name name))
1381 (eq name '<-mistakable)
1382 (when (string-match "^->" (symbol-name name))
1384 ((string-match "^->fullwidth" (symbol-name name))
1385 (not (and (consp value)
1386 (characterp (car value))
1388 (car value) '=ucs 'defined-only)))
1393 ((or (eq name 'ideographic-structure)
1394 (eq name 'ideographic-combination)
1395 ;; (eq name 'ideographic-)
1396 (eq name '=decomposition)
1397 (char-feature-base-name= '=decomposition name)
1398 (char-feature-base-name= '=>decomposition name)
1399 ;; (string-match "^=>*decomposition\\(@[^*]+\\)?$"
1400 ;; (symbol-name name))
1401 (string-match "^\\(->\\|<-\\)[^*]*$" (symbol-name name))
1402 (string-match "^\\(->\\|<-\\)[^*]*\\*sources$"
1405 (char-db-insert-relation-feature char name value
1408 ;; ((memq name '(ideograph=
1409 ;; original-ideograph-of
1410 ;; ancient-ideograph-of
1411 ;; vulgar-ideograph-of
1412 ;; wrong-ideograph-of
1413 ;; ;; simplified-ideograph-of
1414 ;; ideographic-variants
1415 ;; ;; ideographic-different-form-of
1417 ;; (insert (format "(%-18s%s " name line-breaking))
1418 ;; (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1420 ;; (while (consp value)
1421 ;; (setq cell (car value))
1422 ;; (if (and (consp cell)
1423 ;; (consp (car cell)))
1427 ;; (char-db-insert-alist cell readable)
1428 ;; (setq separator lbs))
1430 ;; (insert separator))
1431 ;; (insert (prin1-to-string cell))
1432 ;; (setq separator " "))
1433 ;; (setq value (cdr value)))
1435 ;; (insert line-breaking))
1437 (insert (format "(%-18s " name))
1438 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1440 (while (consp value)
1441 (setq cell (car value))
1442 (if (and (consp cell)
1444 (setq ret (condition-case nil
1452 (setq key (car (car rest)))
1453 (if (find-charset key)
1454 (setq cal (cons key cal))
1455 (setq al (cons key al)))
1456 (setq rest (cdr rest)))
1459 (insert-char-attributes ret
1463 (setq separator lbs))
1464 (setq ret (prin1-to-string cell))
1466 (if (< (+ (current-column)
1473 (setq separator " "))
1474 (setq value (cdr value)))
1476 (insert line-breaking))
1478 (insert (format "(%-18s" name))
1479 (setq ret (prin1-to-string value))
1480 (unless (< (+ (current-column)
1484 (insert line-breaking))
1485 (insert " . " ret ")" line-breaking)
1486 ;; (insert (format "(%-18s . %S)%s"
1491 (setq attributes (cdr attributes)))
1494 (defun insert-char-data (char &optional readable
1497 (narrow-to-region (point)(point))
1498 (insert "(define-char
1500 (insert-char-attributes char readable attributes)
1502 (goto-char (point-min))
1503 (while (re-search-forward "[ \t]+$" nil t)
1506 (goto-char (point-min))
1507 (while (re-search-forward "[ \t][ \t][ \t]*" nil t)
1508 (let ((column (current-column))
1509 (indent-tabs-mode t))
1510 (delete-region (match-beginning 0) (point))
1511 (indent-to column)))
1512 (goto-char (point-max))
1513 ;; (tabify (point-min)(point-max))
1516 (defun insert-char-data-with-variant (char &optional printable
1518 script excluded-script)
1519 (insert-char-data char printable)
1520 (let ((variants (char-variants char))
1523 (setq variants (sort variants #'<))
1524 (setq rest variants)
1525 (setq variants (cons char variants))
1527 (setq variant (car rest))
1528 (unless (get-char-attribute variant '<-subsumptive)
1529 (if (and (or (null script)
1530 (null (setq vs (get-char-attribute variant 'script)))
1532 (or (null excluded-script)
1533 (null (setq vs (get-char-attribute variant 'script)))
1534 (not (memq excluded-script vs))))
1535 (unless (and no-ucs-unified (get-char-attribute variant '=ucs))
1536 (insert-char-data variant printable)
1537 (if (setq ret (char-variants variant))
1539 (or (memq (car ret) variants)
1540 ;; (get-char-attribute (car ret) '<-subsumptive)
1541 (setq rest (nconc rest (list (car ret)))))
1542 (setq ret (cdr ret)))))))
1543 (setq rest (cdr rest)))))
1545 (defun insert-char-range-data (min max &optional script excluded-script)
1548 (while (<= code max)
1549 (setq char (decode-char '=ucs code))
1550 (if (encode-char char '=ucs 'defined-only)
1551 (insert-char-data-with-variant char nil 'no-ucs-unified
1552 script excluded-script))
1553 (setq code (1+ code)))))
1555 (defun write-char-range-data-to-file (min max file
1556 &optional script excluded-script)
1557 (let ((coding-system-for-write char-db-file-coding-system))
1559 (insert (format ";; -*- coding: %s -*-\n"
1560 char-db-file-coding-system))
1561 (insert-char-range-data min max script excluded-script)
1562 (write-region (point-min)(point-max) file))))
1564 (defvar what-character-original-window-configuration)
1567 (defun what-char-definition (char)
1568 (interactive (list (char-after)))
1569 (let ((buf (get-buffer-create "*Character Description*"))
1570 (the-buf (current-buffer))
1571 (win-conf (current-window-configuration)))
1573 (make-local-variable 'what-character-original-window-configuration)
1574 (setq what-character-original-window-configuration win-conf)
1575 (setq buffer-read-only nil)
1579 (insert-char-data-with-variant char 'printable)
1580 (unless (char-attribute-alist char)
1581 (insert (format ";; = %c\n"
1582 (let* ((rest (split-char char))
1586 (setq code (logior (lsh code 8)
1588 (decode-char ccs code)))))
1589 ;; (char-db-update-comment)
1590 (set-buffer-modified-p nil)
1591 (view-mode the-buf (lambda (buf)
1592 (set-window-configuration
1593 what-character-original-window-configuration)
1595 (goto-char (point-min)))
1597 (set-window-configuration
1598 what-character-original-window-configuration)
1599 (signal (car err) (cdr err)))))))
1605 (provide 'char-db-util)
1607 ;;; char-db-util.el ends here