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 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
347 =>big5-cdp-itaiji-001
359 ;;; @ char-db formatters
362 (defun char-db-make-char-spec (char)
364 (cond ((characterp char)
365 (cond ((and (setq ret (encode-char char '=ucs 'defined-only))
366 (not (and (<= #xE000 ret)(<= ret #xF8FF))))
367 (setq char-spec (list (cons '=ucs ret)))
368 (cond ((setq ret (get-char-attribute char 'name))
369 (setq char-spec (cons (cons 'name ret) char-spec))
371 ((setq ret (get-char-attribute char 'name*))
372 (setq char-spec (cons (cons 'name* ret) char-spec))
375 ((encode-char char '=mj 'defined-only)
377 (dolist (ccs (charset-list))
378 (if (and (or (eq ccs '=mj)
379 ;; (eq (charset-property ccs 'iso-ir) 177)
380 (string-match "=ucs@" (symbol-name ccs))
382 (setq ccs (charset-name ccs))
383 (null (assq ccs char-spec))
384 (setq ret (encode-char char ccs 'defined-only)))
385 (setq char-spec (cons (cons ccs ret) char-spec))))
387 ((encode-char char '==mj 'defined-only)
389 (dolist (ccs (charset-list))
390 (if (and (or (eq ccs '==mj)
391 ;; (eq (charset-property ccs 'iso-ir) 177)
392 (string-match "=ucs@" (symbol-name ccs))
394 (setq ccs (charset-name ccs))
395 (null (assq ccs char-spec))
396 (setq ret (encode-char char ccs 'defined-only)))
397 (setq char-spec (cons (cons ccs ret) char-spec))))
399 ((encode-char char '=adobe-japan1 'defined-only)
401 (dolist (ccs (charset-list))
402 (if (and (or (memq ccs
411 ;; (eq (charset-property ccs 'iso-ir) 177)
412 (string-match "=ucs@" (symbol-name ccs))
414 (setq ccs (charset-name ccs))
415 (null (assq ccs char-spec))
416 (setq ret (encode-char char ccs 'defined-only)))
417 (setq char-spec (cons (cons ccs ret) char-spec))))
419 ((encode-char char '==adobe-japan1 'defined-only)
421 (dolist (ccs (charset-list))
422 (if (and (or (memq ccs
431 ;; (eq (charset-property ccs 'iso-ir) 177)
432 (string-match "=ucs@" (symbol-name ccs))
434 (setq ccs (charset-name ccs))
435 (null (assq ccs char-spec))
436 (setq ret (encode-char char ccs 'defined-only)))
437 (setq char-spec (cons (cons ccs ret) char-spec))))
441 (let ((rest char-db-coded-charset-priority-list)
444 (setq ccs (charset-name
445 (find-charset (car rest))))
447 (encode-char char ccs
449 (throw 'tag (cons ccs ret)))
450 (setq rest (cdr rest))))))
451 (setq char-spec (list ret))
452 (dolist (ccs (delq (car ret) (charset-list)))
453 (if (and (or (charset-iso-final-char ccs)
460 (eq (charset-property ccs 'iso-ir) 177)
461 ;; (string-match "=ucs@" (symbol-name ccs))
463 (setq ccs (charset-name ccs))
464 (null (assq ccs char-spec))
465 (setq ret (encode-char char ccs 'defined-only)))
466 (setq char-spec (cons (cons ccs ret) char-spec))))
468 (setq char-spec (split-char char)))
469 (cond ((setq ret (get-char-attribute char 'name))
470 (setq char-spec (cons (cons 'name ret) char-spec))
472 ((setq ret (get-char-attribute char 'name*))
473 (setq char-spec (cons (cons 'name* ret) char-spec))
476 ((setq ret (get-char-attribute
477 char 'ideographic-combination))
479 (cons (cons 'ideographic-combination ret)
486 (defun char-db-insert-char-spec (char &optional readable column
489 (setq column (current-column)))
490 (let (char-spec temp-char)
491 (setq char-spec (char-db-make-char-spec char))
492 (unless (or (characterp char) ; char
494 (setq char (find-char char-spec))
496 ;; define temporary character
497 ;; Current implementation is dirty.
498 (setq temp-char (define-char (cons '(ideograph-daikanwa . 0)
500 (remove-char-attribute temp-char 'ideograph-daikanwa)
501 (setq char temp-char))
502 (insert-char-attributes char
504 (union (mapcar #'car char-spec)
508 ;; undefine temporary character
509 ;; Current implementation is dirty.
510 (setq char-spec (char-attribute-alist temp-char))
512 (remove-char-attribute temp-char (car (car char-spec)))
513 (setq char-spec (cdr char-spec))))))
515 (defun char-db-insert-alist (alist &optional readable column)
517 (setq column (current-column)))
519 (concat "\n" (make-string (1+ column) ?\ )))
523 lbs cell rest separator)
526 (setq name (car (car alist))
527 value (cdr (car alist)))
528 (cond ((eq name 'char)
530 (if (setq ret (condition-case nil
538 (setq key (car (car value)))
539 ;; (if (find-charset key)
540 ;; (setq cal (cons key cal))
541 (setq al (cons key al))
543 (setq value (cdr value)))
544 (insert-char-attributes ret
548 (insert (prin1-to-string value)))
550 (insert line-breaking))
552 (insert (format "(%-18s " name))
553 (setq lbs (concat "\n" (make-string (current-column) ?\ )))
555 (setq cell (car value))
556 (if (and (consp cell)
558 (setq ret (condition-case nil
568 (setq key (car (car rest)))
569 ;; (if (find-charset key)
570 ;; (setq cal (cons key cal))
571 (setq al (cons key al))
573 (setq rest (cdr rest)))
576 (insert-char-attributes ret
580 (setq separator lbs))
583 (insert (prin1-to-string cell))
584 (setq separator " "))
585 (setq value (cdr value)))
587 (insert line-breaking))
589 (insert (format "(%-18s . %S)%s"
592 (setq alist (cdr alist))))
595 (defun char-db-insert-char-reference (plist &optional readable column)
597 (setq column (current-column)))
599 (concat "\n" (make-string (1+ column) ?\ )))
604 (setq name (pop plist))
605 (setq value (pop plist))
606 (cond ((eq name :char)
609 (cond ((numberp value)
610 (setq value (decode-char '=ucs value)))
612 ;; (setq value (or (find-char value)
615 (char-db-insert-char-spec value readable)
616 (insert line-breaking)
619 (insert (format "%s%s\t%d ; %c%s"
622 (ideographic-radical value)
626 (insert (format "%s%s\t%S" separator name value))
627 (setq separator line-breaking)))
631 (defun char-db-decode-isolated-char (ccs code-point)
634 (cond ((eq ccs 'arabic-iso8859-6)
635 (decode-char ccs code-point))
637 ;; (decode-builtin-char '==gt code-point))
638 ((and (memq ccs '(=gt-pj-1
649 (setq ret (decode-char ccs code-point))
650 (setq ret (encode-char ret '=gt 'defined-only)))
651 (decode-builtin-char '=gt ret))
653 (decode-builtin-char ccs code-point))))
655 (or (decode-char ccs code-point)
656 (define-char (list (cons ccs code-point)))))
657 ((and (<= 0 (char-int ret))
658 (<= (char-int ret) #x1F))
659 (decode-char '=ucs (+ #x2400 (char-int ret))))
660 ((= (char-int ret) #x7F)
664 (defvar char-db-convert-obsolete-format t)
666 (defun char-db-insert-ccs-feature (name value line-breaking)
672 ((memq name '(=>iwds-1
675 =shinjigen@1ed ==shinjigen@1ed
676 =shinjigen@rev ==shinjigen@rev
677 =shinjigen/+p@rev ==shinjigen/+p@rev
678 ===daikanwa/ho ==daikanwa/ho
679 =daikanwa/ho =>>daikanwa/ho =>daikanwa/ho))
680 "(%-18s . %04d)\t; %c")
681 ((eq name '=shinjigen@1ed/24pr)
682 "(%-18s . %04d)\t; %c")
686 ==daikanwa =daikanwa =>>daikanwa =>daikanwa
687 =daikanwa@rev1 =daikanwa@rev2
688 =daikanwa/+p ==daikanwa/+p ===daikanwa/+p
690 =daikanwa/+2p =>>daikanwa/+2p
695 =adobe-japan1-0 ==adobe-japan1-0 ===adobe-japan1-0
696 =adobe-japan1-1 ==adobe-japan1-1 ===adobe-japan1-1
697 =adobe-japan1-2 ==adobe-japan1-2 ===adobe-japan1-2
698 =adobe-japan1-3 ==adobe-japan1-3 ===adobe-japan1-3
699 =adobe-japan1-4 ==adobe-japan1-4 ===adobe-japan1-4
700 =adobe-japan1-5 ==adobe-japan1-5 ===adobe-japan1-5
701 =adobe-japan1-6 ==adobe-japan1-6 ===adobe-japan1-6
702 =>>adobe-japan1-0 =+>adobe-japan1-0
703 =>>adobe-japan1-1 =+>adobe-japan1-1
704 =>>adobe-japan1-2 =+>adobe-japan1-2
705 =>>adobe-japan1-3 =+>adobe-japan1-3
706 =>>adobe-japan1-4 =+>adobe-japan1-4
707 =>>adobe-japan1-5 =+>adobe-japan1-5
708 =>>adobe-japan1-6 =+>adobe-japan1-6
709 =>cbeta =cbeta =>>cbeta ==cbeta ===cbeta
710 =zinbun-oracle =>zinbun-oracle
711 ===hng-jou ===hng-keg ===hng-dng ===hng-mam
712 ===hng-drt ===hng-kgk ===hng-myz ===hng-kda
713 ===hng-khi ===hng-khm ===hng-hok ===hng-kyd ===hng-sok
714 ===hng-yhk ===hng-kak ===hng-kar ===hng-kae
715 ===hng-sys ===hng-tsu ===hng-tzj
716 ===hng-hos ===hng-nak ===hng-jhk
717 ===hng-hod ===hng-gok ===hng-ink ===hng-nto
718 ===hng-nkm ===hng-k24 ===hng-nkk
719 ===hng-kcc ===hng-kcj ===hng-kbk ===hng-sik
720 ===hng-skk ===hng-kyu ===hng-ksk ===hng-wan
721 ===hng-okd ===hng-wad ===hng-kmi
722 ===hng-zkd ===hng-doh ===hng-jyu
723 ===hng-tzs ===hng-kss ===hng-kyo
725 ;; (string-match "^=adobe-" (symbol-name name))
727 "(%-18s . %05d)\t; %c")
728 ((memq name '(=hanyo-denshi/ks
729 ==hanyo-denshi/ks ===hanyo-denshi/ks
732 =mj ==mj ===mj =>>mj =>mj
734 "(%-18s . %06d)\t; %c")
735 ((memq name '(=hanyo-denshi/tk ==hanyo-denshi/tk))
736 "(%-18s . %08d)\t; %c")
737 ((>= (charset-dimension name) 2)
738 "(%-18s . #x%04X)\t; %c")
740 "(%-18s . #x%02X)\t; %c"))
742 (if (= (charset-iso-graphic-plane name) 1)
744 (cond ((= (charset-dimension name) 1)
746 ((= (charset-dimension name) 2)
748 ((= (charset-dimension name) 3)
752 (char-db-decode-isolated-char name value)))
753 (if (and (= (charset-chars name) 94)
754 (= (charset-dimension name) 2))
755 (insert (format " [%02d-%02d]"
756 (- (lsh value -8) 32)
757 (- (logand value 255) 32))))
760 (insert (format "(%-18s . %s)" name value))
762 (insert line-breaking))
764 (defun char-db-insert-relation-feature (char name value line-breaking
766 (insert (format "(%-18s%s " name line-breaking))
767 (let ((lbs (concat "\n" (make-string (current-column) ?\ )))
768 separator cell sources required-features
770 (if (characterp value)
771 (setq value (list value)))
773 (setq cell (car value))
775 (setq cell (decode-char '=ucs cell)))
777 ((eq name '->subsumptive)
778 (when (or (not (some (lambda (atr)
779 (get-char-attribute cell atr))
780 char-db-ignored-attributes))
782 (encode-char cell ccs 'defined-only))
786 (let ((char-db-ignored-attributes
788 char-db-ignored-attributes)))
789 (insert-char-attributes cell readable nil nil 'for-sub-node))
790 (setq separator lbs))
795 char (intern (format "%s*sources" name))))
796 (setq required-features nil)
797 (dolist (source sources)
801 shinjigen shinjigen@1ed shinjigen@rev))
802 (setq required-features
803 (union required-features
815 =shinjigen/+p@rev))))
817 (setq required-features
818 (union required-features
823 ((find-charset (setq ret (intern (format "=%s" source))))
824 (setq required-features
825 (cons ret required-features)))
826 (t (setq required-features
827 (cons source required-features)))))
828 (cond ((string-match "@JP" (symbol-name name))
829 (setq required-features
830 (union required-features
838 ((string-match "@CN" (symbol-name name))
839 (setq required-features
840 (union required-features
847 (insert (format "%S" cell))
848 (char-db-insert-char-spec cell readable
851 (setq separator lbs))
855 (if (consp (car cell))
856 (char-db-insert-char-spec cell readable)
857 (char-db-insert-char-reference cell readable))
858 (setq separator lbs))
862 (insert (prin1-to-string cell))
863 (setq separator " ")))
864 (setq value (cdr value)))
866 (insert line-breaking)))
868 (defun insert-char-attributes (char &optional readable attributes column
871 (setq column (current-column)))
872 (let (name value ; has-long-ccs-name
876 (concat "\n" (make-string (1+ column) ?\ )))
877 lbs cell separator ret
879 dest-ccss ; sources required-features
884 (if (consp attributes)
886 (dolist (name attributes)
887 (unless (memq name char-db-ignored-attributes)
888 (if (find-charset name)
892 (dolist (name (char-attribute-list))
893 (unless (memq name char-db-ignored-attributes)
894 (if (find-charset name)
898 #'char-attribute-name<)))
900 (when (memq '<-subsumptive attributes)
901 (when (or readable (not for-sub-node))
902 (when (setq value (get-char-attribute char '<-subsumptive))
903 (char-db-insert-relation-feature char '<-subsumptive value
906 (setq attributes (delq '<-subsumptive attributes)))
907 (when (and (memq '<-denotational attributes)
908 (setq value (get-char-attribute char '<-denotational)))
909 (char-db-insert-relation-feature char '<-denotational value
912 (setq attributes (delq '<-denotational attributes)))
913 (when (and (memq '<-denotational@component attributes)
914 (setq value (get-char-attribute char '<-denotational@component)))
915 (char-db-insert-relation-feature char '<-denotational@component value
918 (setq attributes (delq '<-denotational@component attributes)))
919 (when (and (memq 'name attributes)
920 (setq value (get-char-attribute char 'name)))
922 (if (> (+ (current-column) (length value)) 48)
925 value line-breaking))
926 (setq attributes (delq 'name attributes))
928 (when (and (memq 'name* attributes)
929 (setq value (get-char-attribute char 'name*)))
931 (if (> (+ (current-column) (length value)) 48)
934 value line-breaking))
935 (setq attributes (delq 'name* attributes))
937 (when (and (memq 'script attributes)
938 (setq value (get-char-attribute char 'script)))
939 (insert (format "(script\t\t%s)%s"
940 (mapconcat (function prin1-to-string)
943 (setq attributes (delq 'script attributes))
945 (dolist (name '(=>ucs =>ucs*))
946 (when (and (memq name attributes)
947 (setq value (get-char-attribute char name)))
948 (insert (format "(%-18s . #x%04X)\t; %c%s"
949 name value (decode-char '=ucs value)
951 (setq attributes (delq name attributes))))
952 (dolist (name '(=>ucs@gb =>ucs@big5))
953 (when (and (memq name attributes)
954 (setq value (get-char-attribute char name)))
955 (insert (format "(%-18s . #x%04X)\t; %c%s"
960 (symbol-name name) 2)))
963 (setq attributes (delq name attributes))
965 ;; (dolist (name '(=>daikanwa))
966 ;; (when (and (memq name attributes)
967 ;; (setq value (get-char-attribute char name)))
969 ;; (if (integerp value)
970 ;; (format "(%-18s . %05d)\t; %c%s"
971 ;; name value (decode-char '=daikanwa value)
973 ;; (format "(%-18s %s)\t; %c%s"
975 ;; (mapconcat (function prin1-to-string)
977 ;; (char-representative-of-daikanwa char)
979 ;; (setq attributes (delq name attributes))))
980 (when (and (memq 'general-category attributes)
981 (setq value (get-char-attribute char 'general-category)))
983 "(general-category\t%s) ; %s%s"
984 (mapconcat (lambda (cell)
987 (cond ((rassoc value unidata-normative-category-alist)
988 "Normative Category")
989 ((rassoc value unidata-informative-category-alist)
990 "Informative Category")
994 (setq attributes (delq 'general-category attributes))
996 (when (and (memq 'bidi-category attributes)
997 (setq value (get-char-attribute char 'bidi-category)))
998 (insert (format "(bidi-category\t. %S)%s"
1001 (setq attributes (delq 'bidi-category attributes))
1003 (unless (or (not (memq 'mirrored attributes))
1004 (eq (setq value (get-char-attribute char 'mirrored 'empty))
1006 (insert (format "(mirrored\t\t. %S)%s"
1009 (setq attributes (delq 'mirrored attributes))
1012 ((and (memq 'decimal-digit-value attributes)
1013 (setq value (get-char-attribute char 'decimal-digit-value)))
1014 (insert (format "(decimal-digit-value . %S)%s"
1017 (setq attributes (delq 'decimal-digit-value attributes))
1018 (when (and (memq 'digit-value attributes)
1019 (setq value (get-char-attribute char 'digit-value)))
1020 (insert (format "(digit-value\t . %S)%s"
1023 (setq attributes (delq 'digit-value attributes))
1025 (when (and (memq 'numeric-value attributes)
1026 (setq value (get-char-attribute char 'numeric-value)))
1027 (insert (format "(numeric-value\t . %S)%s"
1030 (setq attributes (delq 'numeric-value attributes))
1034 (when (and (memq 'digit-value attributes)
1035 (setq value (get-char-attribute char 'digit-value)))
1036 (insert (format "(digit-value\t. %S)%s"
1039 (setq attributes (delq 'digit-value attributes))
1041 (when (and (memq 'numeric-value attributes)
1042 (setq value (get-char-attribute char 'numeric-value)))
1043 (insert (format "(numeric-value\t. %S)%s"
1046 (setq attributes (delq 'numeric-value attributes))
1048 (when (and (memq 'iso-10646-comment attributes)
1049 (setq value (get-char-attribute char 'iso-10646-comment)))
1050 (insert (format "(iso-10646-comment\t. %S)%s"
1053 (setq attributes (delq 'iso-10646-comment attributes))
1055 (when (and (memq 'morohashi-daikanwa attributes)
1056 (setq value (get-char-attribute char 'morohashi-daikanwa)))
1057 (insert (format "(morohashi-daikanwa\t%s)%s"
1058 (mapconcat (function prin1-to-string) value " ")
1060 (setq attributes (delq 'morohashi-daikanwa attributes))
1064 (when (and (memq 'ideographic-radical attributes)
1065 (setq value (get-char-attribute char 'ideographic-radical)))
1066 (setq radical value)
1067 (insert (format "(ideographic-radical . %S)\t; %c%s"
1069 (ideographic-radical radical)
1071 (setq attributes (delq 'ideographic-radical attributes))
1073 (when (and (memq 'shuowen-radical attributes)
1074 (setq value (get-char-attribute char 'shuowen-radical)))
1075 (insert (format "(shuowen-radical\t. %S)\t; %c%s"
1077 (shuowen-radical value)
1079 (setq attributes (delq 'shuowen-radical attributes))
1084 char-db-feature-domains
1086 (dolist (feature (char-attribute-list))
1087 (setq feature (symbol-name feature))
1089 "\\(radical\\|strokes\\)@\\([^@*]+\\)\\(\\*\\|$\\)"
1091 (setq domain (intern (match-string 2 feature)))
1092 (unless (memq domain dest)
1093 (setq dest (cons domain dest)))))
1094 (sort dest #'string<))))
1095 (setq key (intern (format "%s@%s" 'ideographic-radical domain)))
1096 (when (and (memq key attributes)
1097 (setq value (get-char-attribute char key)))
1098 (setq radical value)
1099 (insert (format "(%s . %S)\t; %c%s"
1102 (ideographic-radical radical)
1104 (setq attributes (delq key attributes))
1106 (setq key (intern (format "%s@%s" 'ideographic-strokes domain)))
1107 (when (and (memq key attributes)
1108 (setq value (get-char-attribute char key)))
1109 (setq strokes value)
1110 (insert (format "(%s . %S)%s"
1114 (setq attributes (delq key attributes))
1116 (setq key (intern (format "%s@%s" 'total-strokes domain)))
1117 (when (and (memq key attributes)
1118 (setq value (get-char-attribute char key)))
1119 (insert (format "(%s . %S)%s"
1123 (setq attributes (delq key attributes))
1125 (dolist (feature '(ideographic-radical
1128 (setq key (intern (format "%s@%s*sources" feature domain)))
1129 (when (and (memq key attributes)
1130 (setq value (get-char-attribute char key)))
1131 (insert (format "(%s%s" key line-breaking))
1132 (dolist (cell value)
1133 (insert (format " %s" cell)))
1135 (insert line-breaking)
1136 (setq attributes (delq key attributes))
1139 (when (and (memq 'ideographic-strokes attributes)
1140 (setq value (get-char-attribute char 'ideographic-strokes)))
1141 (setq strokes value)
1142 (insert (format "(ideographic-strokes . %S)%s"
1145 (setq attributes (delq 'ideographic-strokes attributes))
1147 (when (and (memq 'kangxi-radical attributes)
1148 (setq value (get-char-attribute char 'kangxi-radical)))
1149 (unless (eq value radical)
1150 (insert (format "(kangxi-radical\t . %S)\t; %c%s"
1152 (ideographic-radical value)
1155 (setq radical value)))
1156 (setq attributes (delq 'kangxi-radical attributes))
1158 (when (and (memq 'kangxi-strokes attributes)
1159 (setq value (get-char-attribute char 'kangxi-strokes)))
1160 (unless (eq value strokes)
1161 (insert (format "(kangxi-strokes\t . %S)%s"
1165 (setq strokes value)))
1166 (setq attributes (delq 'kangxi-strokes attributes))
1168 ;; (when (and (memq 'japanese-radical attributes)
1169 ;; (setq value (get-char-attribute char 'japanese-radical)))
1170 ;; (unless (eq value radical)
1171 ;; (insert (format "(japanese-radical\t . %S)\t; %c%s"
1173 ;; (ideographic-radical value)
1176 ;; (setq radical value)))
1177 ;; (setq attributes (delq 'japanese-radical attributes))
1179 (when (and (memq 'japanese-strokes attributes)
1180 (setq value (get-char-attribute char 'japanese-strokes)))
1181 (unless (eq value strokes)
1182 (insert (format "(japanese-strokes\t . %S)%s"
1186 (setq strokes value)))
1187 (setq attributes (delq 'japanese-strokes attributes))
1189 (when (and (memq 'cns-radical attributes)
1190 (setq value (get-char-attribute char 'cns-radical)))
1191 (insert (format "(cns-radical\t . %S)\t; %c%s"
1193 (ideographic-radical value)
1195 (setq attributes (delq 'cns-radical attributes))
1197 (when (and (memq 'cns-strokes attributes)
1198 (setq value (get-char-attribute char 'cns-strokes)))
1199 (unless (eq value strokes)
1200 (insert (format "(cns-strokes\t . %S)%s"
1204 (setq strokes value)))
1205 (setq attributes (delq 'cns-strokes attributes))
1207 ;; (when (and (memq 'shinjigen-1-radical attributes)
1208 ;; (setq value (get-char-attribute char 'shinjigen-1-radical)))
1209 ;; (unless (eq value radical)
1210 ;; (insert (format "(shinjigen-1-radical . %S)\t; %c%s"
1212 ;; (ideographic-radical value)
1215 ;; (setq radical value)))
1216 ;; (setq attributes (delq 'shinjigen-1-radical attributes))
1218 ;; (when (and (memq 'ideographic- attributes)
1219 ;; (setq value (get-char-attribute char 'ideographic-)))
1220 ;; (insert "(ideographic- ")
1221 ;; (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1223 ;; (while (consp value)
1224 ;; (setq cell (car value))
1225 ;; (if (integerp cell)
1226 ;; (setq cell (decode-char '=ucs cell)))
1227 ;; (cond ((characterp cell)
1231 ;; (insert (format "%S" cell))
1232 ;; (char-db-insert-char-spec cell readable))
1233 ;; (setq separator lbs))
1237 ;; (if (consp (car cell))
1238 ;; (char-db-insert-char-spec cell readable)
1239 ;; (char-db-insert-char-reference cell readable))
1240 ;; (setq separator lbs))
1243 ;; (insert separator))
1244 ;; (insert (prin1-to-string cell))
1245 ;; (setq separator " ")))
1246 ;; (setq value (cdr value)))
1248 ;; (insert line-breaking)
1249 ;; (setq attributes (delq 'ideographic- attributes)))
1250 (when (and (memq 'total-strokes attributes)
1251 (setq value (get-char-attribute char 'total-strokes)))
1252 (insert (format "(total-strokes . %S)%s"
1255 (setq attributes (delq 'total-strokes attributes))
1257 ;; (when (and (memq '->ideograph attributes)
1258 ;; (setq value (get-char-attribute char '->ideograph)))
1259 ;; (insert (format "(->ideograph\t%s)%s"
1260 ;; (mapconcat (lambda (code)
1261 ;; (cond ((symbolp code)
1262 ;; (symbol-name code))
1264 ;; (format "#x%04X" code))
1267 ;; line-breaking code))))
1270 ;; (setq attributes (delq '->ideograph attributes))
1272 ;; (when (and (memq '->decomposition attributes)
1273 ;; (setq value (get-char-attribute char '->decomposition)))
1274 ;; (insert (format "(->decomposition\t%s)%s"
1275 ;; (mapconcat (lambda (code)
1276 ;; (cond ((symbolp code)
1277 ;; (symbol-name code))
1278 ;; ((characterp code)
1280 ;; (format "%S" code)
1285 ;; (format "#x%04X" code))
1287 ;; (format "%s%S" line-breaking code))))
1290 ;; (setq attributes (delq '->decomposition attributes))
1292 (if (equal (get-char-attribute char '->titlecase)
1293 (get-char-attribute char '->uppercase))
1294 (setq attributes (delq '->titlecase attributes)))
1295 (when (and (memq '->mojikyo attributes)
1296 (setq value (get-char-attribute char '->mojikyo)))
1297 (insert (format "(->mojikyo\t\t. %06d)\t; %c%s"
1298 value (decode-char 'mojikyo value)
1300 (setq attributes (delq '->mojikyo attributes))
1302 ;; (when (and (memq 'hanyu-dazidian-vol attributes)
1303 ;; (setq value (get-char-attribute char 'hanyu-dazidian-vol)))
1304 ;; (insert (format "(hanyu-dazidian-vol . %d)%s"
1305 ;; value line-breaking))
1306 ;; (setq attributes (delq 'hanyu-dazidian-vol attributes))
1308 ;; (when (and (memq 'hanyu-dazidian-page attributes)
1309 ;; (setq value (get-char-attribute char 'hanyu-dazidian-page)))
1310 ;; (insert (format "(hanyu-dazidian-page . %d)%s"
1311 ;; value line-breaking))
1312 ;; (setq attributes (delq 'hanyu-dazidian-page attributes))
1314 ;; (when (and (memq 'hanyu-dazidian-char attributes)
1315 ;; (setq value (get-char-attribute char 'hanyu-dazidian-char)))
1316 ;; (insert (format "(hanyu-dazidian-char . %d)%s"
1317 ;; value line-breaking))
1318 ;; (setq attributes (delq 'hanyu-dazidian-char attributes))
1321 (dolist (ignored '(composition
1322 ->denotational <-subsumptive ->ucs-unified
1323 ->ideographic-component-forms))
1324 (setq attributes (delq ignored attributes))))
1326 (setq name (car attributes))
1327 (unless (eq (setq value (get-char-attribute char name 'value-is-empty))
1329 (cond ((setq ret (find-charset name))
1330 (setq name (charset-name ret))
1331 (when (not (memq name dest-ccss))
1332 (setq dest-ccss (cons name dest-ccss))
1333 (char-db-insert-ccs-feature name value line-breaking))
1335 ((string-match "^=>ucs@" (symbol-name name))
1336 (insert (format "(%-18s . #x%04X)\t; %c%s"
1337 name value (decode-char '=ucs value)
1340 ((eq name 'jisx0208-1978/4X)
1341 (insert (format "(%-18s . #x%04X)%s"
1347 (not (eq name '->subsumptive))
1348 (not (eq name '->uppercase))
1349 (not (eq name '->lowercase))
1350 (not (eq name '->titlecase))
1351 (not (eq name '->canonical))
1352 (not (eq name '->Bopomofo))
1353 (not (eq name '->mistakable))
1354 (not (eq name '->ideographic-variants))
1355 (null (get-char-attribute
1356 char (intern (format "%s*sources" name))))
1357 (not (string-match "\\*sources$" (symbol-name name)))
1358 (null (get-char-attribute
1359 char (intern (format "%s*note" name))))
1360 (not (string-match "\\*note$" (symbol-name name)))
1361 (or (eq name '<-identical)
1362 (eq name '<-uppercase)
1363 (eq name '<-lowercase)
1364 (eq name '<-titlecase)
1365 (eq name '<-canonical)
1366 (eq name '<-ideographic-variants)
1367 ;; (eq name '<-synonyms)
1368 (string-match "^<-synonyms" (symbol-name name))
1369 (eq name '<-mistakable)
1370 (when (string-match "^->" (symbol-name name))
1372 ((string-match "^->fullwidth" (symbol-name name))
1373 (not (and (consp value)
1374 (characterp (car value))
1376 (car value) '=ucs 'defined-only)))
1381 ((or (eq name 'ideographic-structure)
1382 (eq name 'ideographic-combination)
1383 ;; (eq name 'ideographic-)
1384 (eq name '=decomposition)
1385 (char-feature-base-name= '=decomposition name)
1386 (char-feature-base-name= '=>decomposition name)
1387 ;; (string-match "^=>*decomposition\\(@[^*]+\\)?$"
1388 ;; (symbol-name name))
1389 (string-match "^\\(->\\|<-\\)[^*]*$" (symbol-name name))
1390 (string-match "^\\(->\\|<-\\)[^*]*\\*sources$"
1393 (char-db-insert-relation-feature char name value
1396 ;; ((memq name '(ideograph=
1397 ;; original-ideograph-of
1398 ;; ancient-ideograph-of
1399 ;; vulgar-ideograph-of
1400 ;; wrong-ideograph-of
1401 ;; ;; simplified-ideograph-of
1402 ;; ideographic-variants
1403 ;; ;; ideographic-different-form-of
1405 ;; (insert (format "(%-18s%s " name line-breaking))
1406 ;; (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1408 ;; (while (consp value)
1409 ;; (setq cell (car value))
1410 ;; (if (and (consp cell)
1411 ;; (consp (car cell)))
1415 ;; (char-db-insert-alist cell readable)
1416 ;; (setq separator lbs))
1418 ;; (insert separator))
1419 ;; (insert (prin1-to-string cell))
1420 ;; (setq separator " "))
1421 ;; (setq value (cdr value)))
1423 ;; (insert line-breaking))
1425 (insert (format "(%-18s " name))
1426 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1428 (while (consp value)
1429 (setq cell (car value))
1430 (if (and (consp cell)
1432 (setq ret (condition-case nil
1440 (setq key (car (car rest)))
1441 (if (find-charset key)
1442 (setq cal (cons key cal))
1443 (setq al (cons key al)))
1444 (setq rest (cdr rest)))
1447 (insert-char-attributes ret
1451 (setq separator lbs))
1452 (setq ret (prin1-to-string cell))
1454 (if (< (+ (current-column)
1461 (setq separator " "))
1462 (setq value (cdr value)))
1464 (insert line-breaking))
1466 (insert (format "(%-18s" name))
1467 (setq ret (prin1-to-string value))
1468 (unless (< (+ (current-column)
1472 (insert line-breaking))
1473 (insert " . " ret ")" line-breaking)
1474 ;; (insert (format "(%-18s . %S)%s"
1479 (setq attributes (cdr attributes)))
1482 (defun insert-char-data (char &optional readable
1485 (narrow-to-region (point)(point))
1486 (insert "(define-char
1488 (insert-char-attributes char readable attributes)
1490 (goto-char (point-min))
1491 (while (re-search-forward "[ \t]+$" nil t)
1494 (goto-char (point-min))
1495 (while (re-search-forward "[ \t][ \t][ \t]*" nil t)
1496 (let ((column (current-column))
1497 (indent-tabs-mode t))
1498 (delete-region (match-beginning 0) (point))
1499 (indent-to column)))
1500 (goto-char (point-max))
1501 ;; (tabify (point-min)(point-max))
1504 (defun insert-char-data-with-variant (char &optional printable
1506 script excluded-script)
1507 (insert-char-data char printable)
1508 (let ((variants (char-variants char))
1511 (setq variants (sort variants #'<))
1512 (setq rest variants)
1513 (setq variants (cons char variants))
1515 (setq variant (car rest))
1516 (unless (get-char-attribute variant '<-subsumptive)
1517 (if (and (or (null script)
1518 (null (setq vs (get-char-attribute variant 'script)))
1520 (or (null excluded-script)
1521 (null (setq vs (get-char-attribute variant 'script)))
1522 (not (memq excluded-script vs))))
1523 (unless (and no-ucs-unified (get-char-attribute variant '=ucs))
1524 (insert-char-data variant printable)
1525 (if (setq ret (char-variants variant))
1527 (or (memq (car ret) variants)
1528 ;; (get-char-attribute (car ret) '<-subsumptive)
1529 (setq rest (nconc rest (list (car ret)))))
1530 (setq ret (cdr ret)))))))
1531 (setq rest (cdr rest)))))
1533 (defun insert-char-range-data (min max &optional script excluded-script)
1536 (while (<= code max)
1537 (setq char (decode-char '=ucs code))
1538 (if (encode-char char '=ucs 'defined-only)
1539 (insert-char-data-with-variant char nil 'no-ucs-unified
1540 script excluded-script))
1541 (setq code (1+ code)))))
1543 (defun write-char-range-data-to-file (min max file
1544 &optional script excluded-script)
1545 (let ((coding-system-for-write char-db-file-coding-system))
1547 (insert (format ";; -*- coding: %s -*-\n"
1548 char-db-file-coding-system))
1549 (insert-char-range-data min max script excluded-script)
1550 (write-region (point-min)(point-max) file))))
1552 (defvar what-character-original-window-configuration)
1555 (defun what-char-definition (char)
1556 (interactive (list (char-after)))
1557 (let ((buf (get-buffer-create "*Character Description*"))
1558 (the-buf (current-buffer))
1559 (win-conf (current-window-configuration)))
1561 (make-local-variable 'what-character-original-window-configuration)
1562 (setq what-character-original-window-configuration win-conf)
1563 (setq buffer-read-only nil)
1567 (insert-char-data-with-variant char 'printable)
1568 (unless (char-attribute-alist char)
1569 (insert (format ";; = %c\n"
1570 (let* ((rest (split-char char))
1574 (setq code (logior (lsh code 8)
1576 (decode-char ccs code)))))
1577 ;; (char-db-update-comment)
1578 (set-buffer-modified-p nil)
1579 (view-mode the-buf (lambda (buf)
1580 (set-window-configuration
1581 what-character-original-window-configuration)
1583 (goto-char (point-min)))
1585 (set-window-configuration
1586 what-character-original-window-configuration)
1587 (signal (car err) (cdr err)))))))
1593 (provide 'char-db-util)
1595 ;;; char-db-util.el ends here