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
359 =>big5-cdp-itaiji-001
366 ;;; @ char-db formatters
369 (defun char-db-make-char-spec (char)
371 (cond ((characterp char)
372 (cond ((and (setq ret (encode-char char '=ucs 'defined-only))
373 (not (and (<= #xE000 ret)(<= ret #xF8FF))))
374 (setq char-spec (list (cons '=ucs ret)))
375 (cond ((setq ret (get-char-attribute char 'name))
376 (setq char-spec (cons (cons 'name ret) char-spec))
378 ((setq ret (get-char-attribute char 'name*))
379 (setq char-spec (cons (cons 'name* ret) char-spec))
382 ((encode-char char '=mj 'defined-only)
384 (dolist (ccs (charset-list))
385 (if (and (or (eq ccs '=mj)
386 ;; (eq (charset-property ccs 'iso-ir) 177)
387 (string-match "=ucs@" (symbol-name ccs))
389 (setq ccs (charset-name ccs))
390 (null (assq ccs char-spec))
391 (setq ret (encode-char char ccs 'defined-only)))
392 (setq char-spec (cons (cons ccs ret) char-spec))))
394 ((encode-char char '==mj 'defined-only)
396 (dolist (ccs (charset-list))
397 (if (and (or (eq ccs '==mj)
398 ;; (eq (charset-property ccs 'iso-ir) 177)
399 (string-match "=ucs@" (symbol-name ccs))
401 (setq ccs (charset-name ccs))
402 (null (assq ccs char-spec))
403 (setq ret (encode-char char ccs 'defined-only)))
404 (setq char-spec (cons (cons ccs ret) char-spec))))
406 ((encode-char char '=adobe-japan1 'defined-only)
408 (dolist (ccs (charset-list))
409 (if (and (or (memq ccs
418 ;; (eq (charset-property ccs 'iso-ir) 177)
419 (string-match "=ucs@" (symbol-name ccs))
421 (setq ccs (charset-name ccs))
422 (null (assq ccs char-spec))
423 (setq ret (encode-char char ccs 'defined-only)))
424 (setq char-spec (cons (cons ccs ret) char-spec))))
426 ((encode-char char '==adobe-japan1 'defined-only)
428 (dolist (ccs (charset-list))
429 (if (and (or (memq ccs
438 ;; (eq (charset-property ccs 'iso-ir) 177)
439 (string-match "=ucs@" (symbol-name ccs))
441 (setq ccs (charset-name ccs))
442 (null (assq ccs char-spec))
443 (setq ret (encode-char char ccs 'defined-only)))
444 (setq char-spec (cons (cons ccs ret) char-spec))))
448 (let ((rest char-db-coded-charset-priority-list)
451 (setq ccs (charset-name
452 (find-charset (car rest))))
454 (encode-char char ccs
456 (throw 'tag (cons ccs ret)))
457 (setq rest (cdr rest))))))
458 (setq char-spec (list ret))
459 (dolist (ccs (delq (car ret) (charset-list)))
460 (if (and (or (charset-iso-final-char ccs)
467 (eq (charset-property ccs 'iso-ir) 177)
468 ;; (string-match "=ucs@" (symbol-name ccs))
470 (setq ccs (charset-name ccs))
471 (null (assq ccs char-spec))
472 (setq ret (encode-char char ccs 'defined-only)))
473 (setq char-spec (cons (cons ccs ret) char-spec))))
475 (setq char-spec (split-char char)))
476 (cond ((setq ret (get-char-attribute char 'name))
477 (setq char-spec (cons (cons 'name ret) char-spec))
479 ((setq ret (get-char-attribute char 'name*))
480 (setq char-spec (cons (cons 'name* ret) char-spec))
483 ((setq ret (get-char-attribute
484 char 'ideographic-combination))
486 (cons (cons 'ideographic-combination ret)
493 (defun char-db-insert-char-spec (char &optional readable column
496 (setq column (current-column)))
497 (let (char-spec temp-char)
498 (setq char-spec (char-db-make-char-spec char))
499 (unless (or (characterp char) ; char
501 (setq char (find-char char-spec))
503 ;; define temporary character
504 ;; Current implementation is dirty.
505 (setq temp-char (define-char (cons '(ideograph-daikanwa . 0)
507 (remove-char-attribute temp-char 'ideograph-daikanwa)
508 (setq char temp-char))
509 (insert-char-attributes char
511 (union (mapcar #'car char-spec)
515 ;; undefine temporary character
516 ;; Current implementation is dirty.
517 (setq char-spec (char-attribute-alist temp-char))
519 (remove-char-attribute temp-char (car (car char-spec)))
520 (setq char-spec (cdr char-spec))))))
522 (defun char-db-insert-alist (alist &optional readable column)
524 (setq column (current-column)))
526 (concat "\n" (make-string (1+ column) ?\ )))
530 lbs cell rest separator)
533 (setq name (car (car alist))
534 value (cdr (car alist)))
535 (cond ((eq name 'char)
537 (if (setq ret (condition-case nil
545 (setq key (car (car value)))
546 ;; (if (find-charset key)
547 ;; (setq cal (cons key cal))
548 (setq al (cons key al))
550 (setq value (cdr value)))
551 (insert-char-attributes ret
555 (insert (prin1-to-string value)))
557 (insert line-breaking))
559 (insert (format "(%-18s " name))
560 (setq lbs (concat "\n" (make-string (current-column) ?\ )))
562 (setq cell (car value))
563 (if (and (consp cell)
565 (setq ret (condition-case nil
575 (setq key (car (car rest)))
576 ;; (if (find-charset key)
577 ;; (setq cal (cons key cal))
578 (setq al (cons key al))
580 (setq rest (cdr rest)))
583 (insert-char-attributes ret
587 (setq separator lbs))
590 (insert (prin1-to-string cell))
591 (setq separator " "))
592 (setq value (cdr value)))
594 (insert line-breaking))
596 (insert (format "(%-18s . %S)%s"
599 (setq alist (cdr alist))))
602 (defun char-db-insert-char-reference (plist &optional readable column)
604 (setq column (current-column)))
606 (concat "\n" (make-string (1+ column) ?\ )))
611 (setq name (pop plist))
612 (setq value (pop plist))
613 (cond ((eq name :char)
616 (cond ((numberp value)
617 (setq value (decode-char '=ucs value)))
619 ;; (setq value (or (find-char value)
622 (char-db-insert-char-spec value readable)
623 (insert line-breaking)
626 (insert (format "%s%s\t%d ; %c%s"
629 (ideographic-radical value)
633 (insert (format "%s%s\t%S" separator name value))
634 (setq separator line-breaking)))
638 (defun char-db-decode-isolated-char (ccs code-point)
641 (cond ((eq ccs 'arabic-iso8859-6)
642 (decode-char ccs code-point))
644 ;; (decode-builtin-char '==gt code-point))
645 ((and (memq ccs '(=gt-pj-1
656 (setq ret (decode-char ccs code-point))
657 (setq ret (encode-char ret '=gt 'defined-only)))
658 (decode-builtin-char '=gt ret))
660 (decode-builtin-char ccs code-point))))
662 (or (decode-char ccs code-point)
663 (define-char (list (cons ccs code-point)))))
664 ((and (<= 0 (char-int ret))
665 (<= (char-int ret) #x1F))
666 (decode-char '=ucs (+ #x2400 (char-int ret))))
667 ((= (char-int ret) #x7F)
671 (defvar char-db-convert-obsolete-format t)
673 (defun char-db-insert-ccs-feature (name value line-breaking)
679 ((memq name '(=>iwds-1
682 =shinjigen@1ed ==shinjigen@1ed
683 =shinjigen@rev ==shinjigen@rev
684 =shinjigen/+p@rev ==shinjigen/+p@rev
685 ===daikanwa/ho ==daikanwa/ho
686 =daikanwa/ho =>>daikanwa/ho =>daikanwa/ho))
687 "(%-18s . %04d)\t; %c")
688 ((eq name '=shinjigen@1ed/24pr)
689 "(%-18s . %04d)\t; %c")
693 ==daikanwa =daikanwa =>>daikanwa =>daikanwa
694 =daikanwa@rev1 =daikanwa@rev2
695 =daikanwa/+p ==daikanwa/+p ===daikanwa/+p
697 =daikanwa/+2p =>>daikanwa/+2p
702 =adobe-japan1-0 ==adobe-japan1-0 ===adobe-japan1-0
703 =adobe-japan1-1 ==adobe-japan1-1 ===adobe-japan1-1
704 =adobe-japan1-2 ==adobe-japan1-2 ===adobe-japan1-2
705 =adobe-japan1-3 ==adobe-japan1-3 ===adobe-japan1-3
706 =adobe-japan1-4 ==adobe-japan1-4 ===adobe-japan1-4
707 =adobe-japan1-5 ==adobe-japan1-5 ===adobe-japan1-5
708 =adobe-japan1-6 ==adobe-japan1-6 ===adobe-japan1-6
709 =>>adobe-japan1-0 =+>adobe-japan1-0
710 =>>adobe-japan1-1 =+>adobe-japan1-1
711 =>>adobe-japan1-2 =+>adobe-japan1-2
712 =>>adobe-japan1-3 =+>adobe-japan1-3
713 =>>adobe-japan1-4 =+>adobe-japan1-4
714 =>>adobe-japan1-5 =+>adobe-japan1-5
715 =>>adobe-japan1-6 =+>adobe-japan1-6
716 =>cbeta =cbeta =>>cbeta ==cbeta ===cbeta
717 =zinbun-oracle =>zinbun-oracle
718 ===hng-jou ===hng-keg ===hng-dng ===hng-mam
719 ===hng-drt ===hng-kgk ===hng-myz ===hng-kda
720 ===hng-khi ===hng-khm ===hng-hok ===hng-kyd ===hng-sok
721 ===hng-yhk ===hng-kak ===hng-kar ===hng-kae
722 ===hng-sys ===hng-tsu ===hng-tzj
723 ===hng-hos ===hng-nak ===hng-jhk
724 ===hng-hod ===hng-gok ===hng-ink ===hng-nto
725 ===hng-nkm ===hng-k24 ===hng-nkk
726 ===hng-kcc ===hng-kcj ===hng-kbk ===hng-sik
727 ===hng-skk ===hng-kyu ===hng-ksk ===hng-wan
728 ===hng-okd ===hng-wad ===hng-kmi
729 ===hng-zkd ===hng-doh ===hng-jyu
730 ===hng-tzs ===hng-kss ===hng-kyo
732 ;; (string-match "^=adobe-" (symbol-name name))
734 "(%-18s . %05d)\t; %c")
735 ((memq name '(=hanyo-denshi/ks
736 ==hanyo-denshi/ks ===hanyo-denshi/ks
739 =mj ==mj ===mj =>>mj =>mj
741 "(%-18s . %06d)\t; %c")
742 ((memq name '(=hanyo-denshi/tk ==hanyo-denshi/tk))
743 "(%-18s . %08d)\t; %c")
744 ((>= (charset-dimension name) 2)
745 "(%-18s . #x%04X)\t; %c")
747 "(%-18s . #x%02X)\t; %c"))
749 (if (= (charset-iso-graphic-plane name) 1)
751 (cond ((= (charset-dimension name) 1)
753 ((= (charset-dimension name) 2)
755 ((= (charset-dimension name) 3)
759 (char-db-decode-isolated-char name value)))
760 (if (and (= (charset-chars name) 94)
761 (= (charset-dimension name) 2))
762 (insert (format " [%02d-%02d]"
763 (- (lsh value -8) 32)
764 (- (logand value 255) 32))))
767 (insert (format "(%-18s . %s)" name value))
769 (insert line-breaking))
771 (defun char-db-insert-relation-feature (char name value line-breaking
773 (insert (format "(%-18s%s " name line-breaking))
774 (let ((lbs (concat "\n" (make-string (current-column) ?\ )))
775 separator cell sources required-features
777 (if (characterp value)
778 (setq value (list value)))
780 (setq cell (car value))
782 (setq cell (decode-char '=ucs cell)))
784 ((eq name '->subsumptive)
785 (when (or (not (some (lambda (atr)
786 (get-char-attribute cell atr))
787 char-db-ignored-attributes))
789 (encode-char cell ccs 'defined-only))
793 (let ((char-db-ignored-attributes
795 char-db-ignored-attributes)))
796 (insert-char-attributes cell readable nil nil 'for-sub-node))
797 (setq separator lbs))
802 char (intern (format "%s*sources" name))))
803 (setq required-features nil)
804 (dolist (source sources)
808 shinjigen shinjigen@1ed shinjigen@rev))
809 (setq required-features
810 (union required-features
822 =shinjigen/+p@rev))))
824 (setq required-features
825 (union required-features
830 ((find-charset (setq ret (intern (format "=%s" source))))
831 (setq required-features
832 (cons ret required-features)))
833 (t (setq required-features
834 (cons source required-features)))))
835 (cond ((string-match "@JP" (symbol-name name))
836 (setq required-features
837 (union required-features
845 ((string-match "@CN" (symbol-name name))
846 (setq required-features
847 (union required-features
854 (insert (format "%S" cell))
855 (char-db-insert-char-spec cell readable
858 (setq separator lbs))
862 (if (consp (car cell))
863 (char-db-insert-char-spec cell readable)
864 (char-db-insert-char-reference cell readable))
865 (setq separator lbs))
869 (insert (prin1-to-string cell))
870 (setq separator " ")))
871 (setq value (cdr value)))
873 (insert line-breaking)))
875 (defun insert-char-attributes (char &optional readable attributes column
878 (setq column (current-column)))
879 (let (name value ; has-long-ccs-name
883 (concat "\n" (make-string (1+ column) ?\ )))
884 lbs cell separator ret
886 dest-ccss ; sources required-features
891 (if (consp attributes)
893 (dolist (name attributes)
894 (unless (memq name char-db-ignored-attributes)
895 (if (find-charset name)
899 (dolist (name (char-attribute-list))
900 (unless (memq name char-db-ignored-attributes)
901 (if (find-charset name)
905 #'char-attribute-name<)))
907 (when (memq '<-subsumptive attributes)
908 (when (or readable (not for-sub-node))
909 (when (setq value (get-char-attribute char '<-subsumptive))
910 (char-db-insert-relation-feature char '<-subsumptive value
913 (setq attributes (delq '<-subsumptive attributes)))
914 (when (and (memq '<-denotational attributes)
915 (setq value (get-char-attribute char '<-denotational)))
916 (char-db-insert-relation-feature char '<-denotational value
919 (setq attributes (delq '<-denotational attributes)))
920 (when (and (memq '<-denotational@component attributes)
921 (setq value (get-char-attribute char '<-denotational@component)))
922 (char-db-insert-relation-feature char '<-denotational@component value
925 (setq attributes (delq '<-denotational@component attributes)))
926 (when (and (memq 'name attributes)
927 (setq value (get-char-attribute char 'name)))
929 (if (> (+ (current-column) (length value)) 48)
932 value line-breaking))
933 (setq attributes (delq 'name attributes))
935 (when (and (memq 'name* attributes)
936 (setq value (get-char-attribute char 'name*)))
938 (if (> (+ (current-column) (length value)) 48)
941 value line-breaking))
942 (setq attributes (delq 'name* attributes))
944 (when (and (memq 'script attributes)
945 (setq value (get-char-attribute char 'script)))
946 (insert (format "(script\t\t%s)%s"
947 (mapconcat (function prin1-to-string)
950 (setq attributes (delq 'script attributes))
952 (dolist (name '(=>ucs =>ucs*))
953 (when (and (memq name attributes)
954 (setq value (get-char-attribute char name)))
955 (insert (format "(%-18s . #x%04X)\t; %c%s"
956 name value (decode-char '=ucs value)
958 (setq attributes (delq name attributes))))
959 (dolist (name '(=>ucs@gb =>ucs@big5))
960 (when (and (memq name attributes)
961 (setq value (get-char-attribute char name)))
962 (insert (format "(%-18s . #x%04X)\t; %c%s"
967 (symbol-name name) 2)))
970 (setq attributes (delq name attributes))
972 ;; (dolist (name '(=>daikanwa))
973 ;; (when (and (memq name attributes)
974 ;; (setq value (get-char-attribute char name)))
976 ;; (if (integerp value)
977 ;; (format "(%-18s . %05d)\t; %c%s"
978 ;; name value (decode-char '=daikanwa value)
980 ;; (format "(%-18s %s)\t; %c%s"
982 ;; (mapconcat (function prin1-to-string)
984 ;; (char-representative-of-daikanwa char)
986 ;; (setq attributes (delq name attributes))))
987 (when (and (memq 'general-category attributes)
988 (setq value (get-char-attribute char 'general-category)))
990 "(general-category\t%s) ; %s%s"
991 (mapconcat (lambda (cell)
994 (cond ((rassoc value unidata-normative-category-alist)
995 "Normative Category")
996 ((rassoc value unidata-informative-category-alist)
997 "Informative Category")
1001 (setq attributes (delq 'general-category attributes))
1003 (when (and (memq 'bidi-category attributes)
1004 (setq value (get-char-attribute char 'bidi-category)))
1005 (insert (format "(bidi-category\t. %S)%s"
1008 (setq attributes (delq 'bidi-category attributes))
1010 (unless (or (not (memq 'mirrored attributes))
1011 (eq (setq value (get-char-attribute char 'mirrored 'empty))
1013 (insert (format "(mirrored\t\t. %S)%s"
1016 (setq attributes (delq 'mirrored attributes))
1019 ((and (memq 'decimal-digit-value attributes)
1020 (setq value (get-char-attribute char 'decimal-digit-value)))
1021 (insert (format "(decimal-digit-value . %S)%s"
1024 (setq attributes (delq 'decimal-digit-value attributes))
1025 (when (and (memq 'digit-value attributes)
1026 (setq value (get-char-attribute char 'digit-value)))
1027 (insert (format "(digit-value\t . %S)%s"
1030 (setq attributes (delq 'digit-value attributes))
1032 (when (and (memq 'numeric-value attributes)
1033 (setq value (get-char-attribute char 'numeric-value)))
1034 (insert (format "(numeric-value\t . %S)%s"
1037 (setq attributes (delq 'numeric-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))
1055 (when (and (memq 'iso-10646-comment attributes)
1056 (setq value (get-char-attribute char 'iso-10646-comment)))
1057 (insert (format "(iso-10646-comment\t. %S)%s"
1060 (setq attributes (delq 'iso-10646-comment attributes))
1062 (when (and (memq 'morohashi-daikanwa attributes)
1063 (setq value (get-char-attribute char 'morohashi-daikanwa)))
1064 (insert (format "(morohashi-daikanwa\t%s)%s"
1065 (mapconcat (function prin1-to-string) value " ")
1067 (setq attributes (delq 'morohashi-daikanwa attributes))
1071 (when (and (memq 'ideographic-radical attributes)
1072 (setq value (get-char-attribute char 'ideographic-radical)))
1073 (setq radical value)
1074 (insert (format "(ideographic-radical . %S)\t; %c%s"
1076 (ideographic-radical radical)
1078 (setq attributes (delq 'ideographic-radical attributes))
1080 (when (and (memq 'shuowen-radical attributes)
1081 (setq value (get-char-attribute char 'shuowen-radical)))
1082 (insert (format "(shuowen-radical\t. %S)\t; %c%s"
1084 (shuowen-radical value)
1086 (setq attributes (delq 'shuowen-radical attributes))
1091 char-db-feature-domains
1093 (dolist (feature (char-attribute-list))
1094 (setq feature (symbol-name feature))
1096 "\\(radical\\|strokes\\)@\\([^@*]+\\)\\(\\*\\|$\\)"
1098 (setq domain (intern (match-string 2 feature)))
1099 (unless (memq domain dest)
1100 (setq dest (cons domain dest)))))
1101 (sort dest #'string<))))
1102 (setq key (intern (format "%s@%s" 'ideographic-radical domain)))
1103 (when (and (memq key attributes)
1104 (setq value (get-char-attribute char key)))
1105 (setq radical value)
1106 (insert (format "(%s . %S)\t; %c%s"
1109 (ideographic-radical radical)
1111 (setq attributes (delq key attributes))
1113 (setq key (intern (format "%s@%s" 'ideographic-strokes domain)))
1114 (when (and (memq key attributes)
1115 (setq value (get-char-attribute char key)))
1116 (setq strokes value)
1117 (insert (format "(%s . %S)%s"
1121 (setq attributes (delq key attributes))
1123 (setq key (intern (format "%s@%s" 'total-strokes domain)))
1124 (when (and (memq key attributes)
1125 (setq value (get-char-attribute char key)))
1126 (insert (format "(%s . %S)%s"
1130 (setq attributes (delq key attributes))
1132 (dolist (feature '(ideographic-radical
1135 (setq key (intern (format "%s@%s*sources" feature domain)))
1136 (when (and (memq key attributes)
1137 (setq value (get-char-attribute char key)))
1138 (insert (format "(%s%s" key line-breaking))
1139 (dolist (cell value)
1140 (insert (format " %s" cell)))
1142 (insert line-breaking)
1143 (setq attributes (delq key attributes))
1146 (when (and (memq 'ideographic-strokes attributes)
1147 (setq value (get-char-attribute char 'ideographic-strokes)))
1148 (setq strokes value)
1149 (insert (format "(ideographic-strokes . %S)%s"
1152 (setq attributes (delq 'ideographic-strokes attributes))
1154 (when (and (memq 'kangxi-radical attributes)
1155 (setq value (get-char-attribute char 'kangxi-radical)))
1156 (unless (eq value radical)
1157 (insert (format "(kangxi-radical\t . %S)\t; %c%s"
1159 (ideographic-radical value)
1162 (setq radical value)))
1163 (setq attributes (delq 'kangxi-radical attributes))
1165 (when (and (memq 'kangxi-strokes attributes)
1166 (setq value (get-char-attribute char 'kangxi-strokes)))
1167 (unless (eq value strokes)
1168 (insert (format "(kangxi-strokes\t . %S)%s"
1172 (setq strokes value)))
1173 (setq attributes (delq 'kangxi-strokes attributes))
1175 ;; (when (and (memq 'japanese-radical attributes)
1176 ;; (setq value (get-char-attribute char 'japanese-radical)))
1177 ;; (unless (eq value radical)
1178 ;; (insert (format "(japanese-radical\t . %S)\t; %c%s"
1180 ;; (ideographic-radical value)
1183 ;; (setq radical value)))
1184 ;; (setq attributes (delq 'japanese-radical attributes))
1186 (when (and (memq 'japanese-strokes attributes)
1187 (setq value (get-char-attribute char 'japanese-strokes)))
1188 (unless (eq value strokes)
1189 (insert (format "(japanese-strokes\t . %S)%s"
1193 (setq strokes value)))
1194 (setq attributes (delq 'japanese-strokes attributes))
1196 (when (and (memq 'cns-radical attributes)
1197 (setq value (get-char-attribute char 'cns-radical)))
1198 (insert (format "(cns-radical\t . %S)\t; %c%s"
1200 (ideographic-radical value)
1202 (setq attributes (delq 'cns-radical attributes))
1204 (when (and (memq 'cns-strokes attributes)
1205 (setq value (get-char-attribute char 'cns-strokes)))
1206 (unless (eq value strokes)
1207 (insert (format "(cns-strokes\t . %S)%s"
1211 (setq strokes value)))
1212 (setq attributes (delq 'cns-strokes attributes))
1214 ;; (when (and (memq 'shinjigen-1-radical attributes)
1215 ;; (setq value (get-char-attribute char 'shinjigen-1-radical)))
1216 ;; (unless (eq value radical)
1217 ;; (insert (format "(shinjigen-1-radical . %S)\t; %c%s"
1219 ;; (ideographic-radical value)
1222 ;; (setq radical value)))
1223 ;; (setq attributes (delq 'shinjigen-1-radical attributes))
1225 ;; (when (and (memq 'ideographic- attributes)
1226 ;; (setq value (get-char-attribute char 'ideographic-)))
1227 ;; (insert "(ideographic- ")
1228 ;; (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1230 ;; (while (consp value)
1231 ;; (setq cell (car value))
1232 ;; (if (integerp cell)
1233 ;; (setq cell (decode-char '=ucs cell)))
1234 ;; (cond ((characterp cell)
1238 ;; (insert (format "%S" cell))
1239 ;; (char-db-insert-char-spec cell readable))
1240 ;; (setq separator lbs))
1244 ;; (if (consp (car cell))
1245 ;; (char-db-insert-char-spec cell readable)
1246 ;; (char-db-insert-char-reference cell readable))
1247 ;; (setq separator lbs))
1250 ;; (insert separator))
1251 ;; (insert (prin1-to-string cell))
1252 ;; (setq separator " ")))
1253 ;; (setq value (cdr value)))
1255 ;; (insert line-breaking)
1256 ;; (setq attributes (delq 'ideographic- attributes)))
1257 (when (and (memq 'total-strokes attributes)
1258 (setq value (get-char-attribute char 'total-strokes)))
1259 (insert (format "(total-strokes . %S)%s"
1262 (setq attributes (delq 'total-strokes attributes))
1264 ;; (when (and (memq '->ideograph attributes)
1265 ;; (setq value (get-char-attribute char '->ideograph)))
1266 ;; (insert (format "(->ideograph\t%s)%s"
1267 ;; (mapconcat (lambda (code)
1268 ;; (cond ((symbolp code)
1269 ;; (symbol-name code))
1271 ;; (format "#x%04X" code))
1274 ;; line-breaking code))))
1277 ;; (setq attributes (delq '->ideograph attributes))
1279 ;; (when (and (memq '->decomposition attributes)
1280 ;; (setq value (get-char-attribute char '->decomposition)))
1281 ;; (insert (format "(->decomposition\t%s)%s"
1282 ;; (mapconcat (lambda (code)
1283 ;; (cond ((symbolp code)
1284 ;; (symbol-name code))
1285 ;; ((characterp code)
1287 ;; (format "%S" code)
1292 ;; (format "#x%04X" code))
1294 ;; (format "%s%S" line-breaking code))))
1297 ;; (setq attributes (delq '->decomposition attributes))
1299 (if (equal (get-char-attribute char '->titlecase)
1300 (get-char-attribute char '->uppercase))
1301 (setq attributes (delq '->titlecase attributes)))
1302 (when (and (memq '->mojikyo attributes)
1303 (setq value (get-char-attribute char '->mojikyo)))
1304 (insert (format "(->mojikyo\t\t. %06d)\t; %c%s"
1305 value (decode-char 'mojikyo value)
1307 (setq attributes (delq '->mojikyo attributes))
1309 ;; (when (and (memq 'hanyu-dazidian-vol attributes)
1310 ;; (setq value (get-char-attribute char 'hanyu-dazidian-vol)))
1311 ;; (insert (format "(hanyu-dazidian-vol . %d)%s"
1312 ;; value line-breaking))
1313 ;; (setq attributes (delq 'hanyu-dazidian-vol attributes))
1315 ;; (when (and (memq 'hanyu-dazidian-page attributes)
1316 ;; (setq value (get-char-attribute char 'hanyu-dazidian-page)))
1317 ;; (insert (format "(hanyu-dazidian-page . %d)%s"
1318 ;; value line-breaking))
1319 ;; (setq attributes (delq 'hanyu-dazidian-page attributes))
1321 ;; (when (and (memq 'hanyu-dazidian-char attributes)
1322 ;; (setq value (get-char-attribute char 'hanyu-dazidian-char)))
1323 ;; (insert (format "(hanyu-dazidian-char . %d)%s"
1324 ;; value line-breaking))
1325 ;; (setq attributes (delq 'hanyu-dazidian-char attributes))
1328 (dolist (ignored '(composition
1329 ->denotational <-subsumptive ->ucs-unified
1330 ->ideographic-component-forms))
1331 (setq attributes (delq ignored attributes))))
1333 (setq name (car attributes))
1334 (unless (eq (setq value (get-char-attribute char name 'value-is-empty))
1336 (cond ((setq ret (find-charset name))
1337 (setq name (charset-name ret))
1338 (when (not (memq name dest-ccss))
1339 (setq dest-ccss (cons name dest-ccss))
1340 (char-db-insert-ccs-feature name value line-breaking))
1342 ((string-match "^=>ucs@" (symbol-name name))
1343 (insert (format "(%-18s . #x%04X)\t; %c%s"
1344 name value (decode-char '=ucs value)
1347 ((eq name 'jisx0208-1978/4X)
1348 (insert (format "(%-18s . #x%04X)%s"
1354 (not (eq name '->subsumptive))
1355 (not (eq name '->uppercase))
1356 (not (eq name '->lowercase))
1357 (not (eq name '->titlecase))
1358 (not (eq name '->canonical))
1359 (not (eq name '->Bopomofo))
1360 (not (eq name '->mistakable))
1361 (not (eq name '->ideographic-variants))
1362 (null (get-char-attribute
1363 char (intern (format "%s*sources" name))))
1364 (not (string-match "\\*sources$" (symbol-name name)))
1365 (null (get-char-attribute
1366 char (intern (format "%s*note" name))))
1367 (not (string-match "\\*note$" (symbol-name name)))
1368 (or (eq name '<-identical)
1369 (eq name '<-uppercase)
1370 (eq name '<-lowercase)
1371 (eq name '<-titlecase)
1372 (eq name '<-canonical)
1373 (eq name '<-ideographic-variants)
1374 ;; (eq name '<-synonyms)
1375 (string-match "^<-synonyms" (symbol-name name))
1376 (eq name '<-mistakable)
1377 (when (string-match "^->" (symbol-name name))
1379 ((string-match "^->fullwidth" (symbol-name name))
1380 (not (and (consp value)
1381 (characterp (car value))
1383 (car value) '=ucs 'defined-only)))
1388 ((or (eq name 'ideographic-structure)
1389 (eq name 'ideographic-combination)
1390 ;; (eq name 'ideographic-)
1391 (eq name '=decomposition)
1392 (char-feature-base-name= '=decomposition name)
1393 (char-feature-base-name= '=>decomposition name)
1394 ;; (string-match "^=>*decomposition\\(@[^*]+\\)?$"
1395 ;; (symbol-name name))
1396 (string-match "^\\(->\\|<-\\)[^*]*$" (symbol-name name))
1397 (string-match "^\\(->\\|<-\\)[^*]*\\*sources$"
1400 (char-db-insert-relation-feature char name value
1403 ;; ((memq name '(ideograph=
1404 ;; original-ideograph-of
1405 ;; ancient-ideograph-of
1406 ;; vulgar-ideograph-of
1407 ;; wrong-ideograph-of
1408 ;; ;; simplified-ideograph-of
1409 ;; ideographic-variants
1410 ;; ;; ideographic-different-form-of
1412 ;; (insert (format "(%-18s%s " name line-breaking))
1413 ;; (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1415 ;; (while (consp value)
1416 ;; (setq cell (car value))
1417 ;; (if (and (consp cell)
1418 ;; (consp (car cell)))
1422 ;; (char-db-insert-alist cell readable)
1423 ;; (setq separator lbs))
1425 ;; (insert separator))
1426 ;; (insert (prin1-to-string cell))
1427 ;; (setq separator " "))
1428 ;; (setq value (cdr value)))
1430 ;; (insert line-breaking))
1432 (insert (format "(%-18s " name))
1433 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1435 (while (consp value)
1436 (setq cell (car value))
1437 (if (and (consp cell)
1439 (setq ret (condition-case nil
1447 (setq key (car (car rest)))
1448 (if (find-charset key)
1449 (setq cal (cons key cal))
1450 (setq al (cons key al)))
1451 (setq rest (cdr rest)))
1454 (insert-char-attributes ret
1458 (setq separator lbs))
1459 (setq ret (prin1-to-string cell))
1461 (if (< (+ (current-column)
1468 (setq separator " "))
1469 (setq value (cdr value)))
1471 (insert line-breaking))
1473 (insert (format "(%-18s" name))
1474 (setq ret (prin1-to-string value))
1475 (unless (< (+ (current-column)
1479 (insert line-breaking))
1480 (insert " . " ret ")" line-breaking)
1481 ;; (insert (format "(%-18s . %S)%s"
1486 (setq attributes (cdr attributes)))
1489 (defun insert-char-data (char &optional readable
1492 (narrow-to-region (point)(point))
1493 (insert "(define-char
1495 (insert-char-attributes char readable attributes)
1497 (goto-char (point-min))
1498 (while (re-search-forward "[ \t]+$" nil t)
1501 (goto-char (point-min))
1502 (while (re-search-forward "[ \t][ \t][ \t]*" nil t)
1503 (let ((column (current-column))
1504 (indent-tabs-mode t))
1505 (delete-region (match-beginning 0) (point))
1506 (indent-to column)))
1507 (goto-char (point-max))
1508 ;; (tabify (point-min)(point-max))
1511 (defun insert-char-data-with-variant (char &optional printable
1513 script excluded-script)
1514 (insert-char-data char printable)
1515 (let ((variants (char-variants char))
1518 (setq variants (sort variants #'<))
1519 (setq rest variants)
1520 (setq variants (cons char variants))
1522 (setq variant (car rest))
1523 (unless (get-char-attribute variant '<-subsumptive)
1524 (if (and (or (null script)
1525 (null (setq vs (get-char-attribute variant 'script)))
1527 (or (null excluded-script)
1528 (null (setq vs (get-char-attribute variant 'script)))
1529 (not (memq excluded-script vs))))
1530 (unless (and no-ucs-unified (get-char-attribute variant '=ucs))
1531 (insert-char-data variant printable)
1532 (if (setq ret (char-variants variant))
1534 (or (memq (car ret) variants)
1535 ;; (get-char-attribute (car ret) '<-subsumptive)
1536 (setq rest (nconc rest (list (car ret)))))
1537 (setq ret (cdr ret)))))))
1538 (setq rest (cdr rest)))))
1540 (defun insert-char-range-data (min max &optional script excluded-script)
1543 (while (<= code max)
1544 (setq char (decode-char '=ucs code))
1545 (if (encode-char char '=ucs 'defined-only)
1546 (insert-char-data-with-variant char nil 'no-ucs-unified
1547 script excluded-script))
1548 (setq code (1+ code)))))
1550 (defun write-char-range-data-to-file (min max file
1551 &optional script excluded-script)
1552 (let ((coding-system-for-write char-db-file-coding-system))
1554 (insert (format ";; -*- coding: %s -*-\n"
1555 char-db-file-coding-system))
1556 (insert-char-range-data min max script excluded-script)
1557 (write-region (point-min)(point-max) file))))
1559 (defvar what-character-original-window-configuration)
1562 (defun what-char-definition (char)
1563 (interactive (list (char-after)))
1564 (let ((buf (get-buffer-create "*Character Description*"))
1565 (the-buf (current-buffer))
1566 (win-conf (current-window-configuration)))
1568 (make-local-variable 'what-character-original-window-configuration)
1569 (setq what-character-original-window-configuration win-conf)
1570 (setq buffer-read-only nil)
1574 (insert-char-data-with-variant char 'printable)
1575 (unless (char-attribute-alist char)
1576 (insert (format ";; = %c\n"
1577 (let* ((rest (split-char char))
1581 (setq code (logior (lsh code 8)
1583 (decode-char ccs code)))))
1584 ;; (char-db-update-comment)
1585 (set-buffer-modified-p nil)
1586 (view-mode the-buf (lambda (buf)
1587 (set-window-configuration
1588 what-character-original-window-configuration)
1590 (goto-char (point-min)))
1592 (set-window-configuration
1593 what-character-original-window-configuration)
1594 (signal (car err) (cdr err)))))))
1600 (provide 'char-db-util)
1602 ;;; char-db-util.el ends here