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
271 ;; =>ucs@hanyo-denshi
366 =>big5-cdp-itaiji-001
376 ;;; @ char-db formatters
379 (defun char-db-make-char-spec (char)
381 (cond ((characterp char)
382 (cond ((and (setq ret (encode-char char '=ucs 'defined-only))
383 (not (and (<= #xE000 ret)(<= ret #xF8FF))))
384 (setq char-spec (list (cons '=ucs ret)))
385 (cond ((setq ret (get-char-attribute char 'name))
386 (setq char-spec (cons (cons 'name ret) char-spec))
388 ((setq ret (get-char-attribute char 'name*))
389 (setq char-spec (cons (cons 'name* ret) char-spec))
392 ((encode-char char '=mj 'defined-only)
394 (dolist (ccs (charset-list))
395 (if (and (or (eq ccs '=mj)
396 ;; (eq (charset-property ccs 'iso-ir) 177)
397 (string-match "=ucs@" (symbol-name ccs))
399 (setq ccs (charset-name ccs))
400 (null (assq ccs char-spec))
401 (setq ret (encode-char char ccs 'defined-only)))
402 (setq char-spec (cons (cons ccs ret) char-spec))))
404 ((encode-char char '==mj 'defined-only)
406 (dolist (ccs (charset-list))
407 (if (and (or (eq ccs '==mj)
408 ;; (eq (charset-property ccs 'iso-ir) 177)
409 (string-match "=ucs@" (symbol-name ccs))
411 (setq ccs (charset-name ccs))
412 (null (assq ccs char-spec))
413 (setq ret (encode-char char ccs 'defined-only)))
414 (setq char-spec (cons (cons ccs ret) char-spec))))
416 ((encode-char char '=adobe-japan1 'defined-only)
418 (dolist (ccs (charset-list))
419 (if (and (or (memq ccs
428 ;; (eq (charset-property ccs 'iso-ir) 177)
429 (string-match "=ucs@" (symbol-name ccs))
431 (setq ccs (charset-name ccs))
432 (null (assq ccs char-spec))
433 (setq ret (encode-char char ccs 'defined-only)))
434 (setq char-spec (cons (cons ccs ret) char-spec))))
436 ((encode-char char '==adobe-japan1 'defined-only)
438 (dolist (ccs (charset-list))
439 (if (and (or (memq ccs
448 ;; (eq (charset-property ccs 'iso-ir) 177)
449 (string-match "=ucs@" (symbol-name ccs))
451 (setq ccs (charset-name ccs))
452 (null (assq ccs char-spec))
453 (setq ret (encode-char char ccs 'defined-only)))
454 (setq char-spec (cons (cons ccs ret) char-spec))))
458 (let ((rest char-db-coded-charset-priority-list)
461 (setq ccs (charset-name
462 (find-charset (car rest))))
464 (encode-char char ccs
466 (throw 'tag (cons ccs ret)))
467 (setq rest (cdr rest))))))
468 (setq char-spec (list ret))
469 (dolist (ccs (delq (car ret) (charset-list)))
470 (if (and (or (charset-iso-final-char ccs)
477 (eq (charset-property ccs 'iso-ir) 177)
478 ;; (string-match "=ucs@" (symbol-name ccs))
480 (setq ccs (charset-name ccs))
481 (null (assq ccs char-spec))
482 (setq ret (encode-char char ccs 'defined-only)))
483 (setq char-spec (cons (cons ccs ret) char-spec))))
485 (setq char-spec (split-char char)))
486 (cond ((setq ret (get-char-attribute char 'name))
487 (setq char-spec (cons (cons 'name ret) char-spec))
489 ((setq ret (get-char-attribute char 'name*))
490 (setq char-spec (cons (cons 'name* ret) char-spec))
493 ((setq ret (get-char-attribute
494 char 'ideographic-combination))
496 (cons (cons 'ideographic-combination ret)
503 (defun char-db-insert-char-spec (char &optional readable column
506 (setq column (current-column)))
507 (let (char-spec temp-char)
508 (setq char-spec (char-db-make-char-spec char))
509 (unless (or (characterp char) ; char
511 (setq char (find-char char-spec))
513 ;; define temporary character
514 ;; Current implementation is dirty.
515 (setq temp-char (define-char (cons '(ideograph-daikanwa . 0)
517 (remove-char-attribute temp-char 'ideograph-daikanwa)
518 (setq char temp-char))
519 (insert-char-attributes char
521 (union (mapcar #'car char-spec)
525 ;; undefine temporary character
526 ;; Current implementation is dirty.
527 (setq char-spec (char-attribute-alist temp-char))
529 (remove-char-attribute temp-char (car (car char-spec)))
530 (setq char-spec (cdr char-spec))))))
532 (defun char-db-insert-alist (alist &optional readable column)
534 (setq column (current-column)))
536 (concat "\n" (make-string (1+ column) ?\ )))
540 lbs cell rest separator)
543 (setq name (car (car alist))
544 value (cdr (car alist)))
545 (cond ((eq name 'char)
547 (if (setq ret (condition-case nil
555 (setq key (car (car value)))
556 ;; (if (find-charset key)
557 ;; (setq cal (cons key cal))
558 (setq al (cons key al))
560 (setq value (cdr value)))
561 (insert-char-attributes ret
565 (insert (prin1-to-string value)))
567 (insert line-breaking))
569 (insert (format "(%-18s " name))
570 (setq lbs (concat "\n" (make-string (current-column) ?\ )))
572 (setq cell (car value))
573 (if (and (consp cell)
575 (setq ret (condition-case nil
585 (setq key (car (car rest)))
586 ;; (if (find-charset key)
587 ;; (setq cal (cons key cal))
588 (setq al (cons key al))
590 (setq rest (cdr rest)))
593 (insert-char-attributes ret
597 (setq separator lbs))
600 (insert (prin1-to-string cell))
601 (setq separator " "))
602 (setq value (cdr value)))
604 (insert line-breaking))
606 (insert (format "(%-18s . %S)%s"
609 (setq alist (cdr alist))))
612 (defun char-db-insert-char-reference (plist &optional readable column)
614 (setq column (current-column)))
616 (concat "\n" (make-string (1+ column) ?\ )))
621 (setq name (pop plist))
622 (setq value (pop plist))
623 (cond ((eq name :char)
626 (cond ((numberp value)
627 (setq value (decode-char '=ucs value)))
629 ;; (setq value (or (find-char value)
632 (char-db-insert-char-spec value readable)
633 (insert line-breaking)
636 (insert (format "%s%s\t%d ; %c%s"
639 (ideographic-radical value)
643 (insert (format "%s%s\t%S" separator name value))
644 (setq separator line-breaking)))
648 (defun char-db-decode-isolated-char (ccs code-point)
651 (cond ((eq ccs 'arabic-iso8859-6)
652 (decode-char ccs code-point))
654 ;; (decode-builtin-char '==gt code-point))
655 ((and (memq ccs '(=gt-pj-1
666 (setq ret (decode-char ccs code-point))
667 (setq ret (encode-char ret '=gt 'defined-only)))
668 (decode-builtin-char '=gt ret))
670 (decode-builtin-char ccs code-point))))
672 (or (decode-char ccs code-point)
673 (define-char (list (cons ccs code-point)))))
674 ((and (<= 0 (char-int ret))
675 (<= (char-int ret) #x1F))
676 (decode-char '=ucs (+ #x2400 (char-int ret))))
677 ((= (char-int ret) #x7F)
681 (defvar char-db-convert-obsolete-format t)
683 (defun char-db-insert-ccs-feature (name value line-breaking)
689 ((memq name '(=>iwds-1
692 =shinjigen@1ed ==shinjigen@1ed
693 =shinjigen@rev ==shinjigen@rev
694 =shinjigen/+p@rev ==shinjigen/+p@rev
695 ===daikanwa/ho ==daikanwa/ho
696 =daikanwa/ho =>>daikanwa/ho =>daikanwa/ho))
697 "(%-18s . %04d)\t; %c")
698 ((eq name '=shinjigen@1ed/24pr)
699 "(%-18s . %04d)\t; %c")
703 ==daikanwa =daikanwa =>>daikanwa =>daikanwa
704 =daikanwa@rev1 =daikanwa@rev2
705 =daikanwa/+p ==daikanwa/+p ===daikanwa/+p
707 =daikanwa/+2p =>>daikanwa/+2p
712 =adobe-japan1-0 ==adobe-japan1-0 ===adobe-japan1-0
713 =adobe-japan1-1 ==adobe-japan1-1 ===adobe-japan1-1
714 =adobe-japan1-2 ==adobe-japan1-2 ===adobe-japan1-2
715 =adobe-japan1-3 ==adobe-japan1-3 ===adobe-japan1-3
716 =adobe-japan1-4 ==adobe-japan1-4 ===adobe-japan1-4
717 =adobe-japan1-5 ==adobe-japan1-5 ===adobe-japan1-5
718 =adobe-japan1-6 ==adobe-japan1-6 ===adobe-japan1-6
719 =>>adobe-japan1-0 =+>adobe-japan1-0
720 =>>adobe-japan1-1 =+>adobe-japan1-1
721 =>>adobe-japan1-2 =+>adobe-japan1-2
722 =>>adobe-japan1-3 =+>adobe-japan1-3
723 =>>adobe-japan1-4 =+>adobe-japan1-4
724 =>>adobe-japan1-5 =+>adobe-japan1-5
725 =>>adobe-japan1-6 =+>adobe-japan1-6
726 =>cbeta =cbeta =>>cbeta ==cbeta ===cbeta
727 =zinbun-oracle =>zinbun-oracle
728 ===hng-jou ===hng-keg ===hng-dng ===hng-mam
729 ===hng-drt ===hng-kgk ===hng-myz ===hng-kda
730 ===hng-khi ===hng-khm ===hng-hok ===hng-kyd ===hng-sok
731 ===hng-yhk ===hng-kak ===hng-kar ===hng-kae
732 ===hng-sys ===hng-tsu ===hng-tzj
733 ===hng-hos ===hng-nak ===hng-jhk
734 ===hng-hod ===hng-gok ===hng-ink ===hng-nto
735 ===hng-nkm ===hng-k24 ===hng-nkk
736 ===hng-kcc ===hng-kcj ===hng-kbk ===hng-sik
737 ===hng-skk ===hng-kyu ===hng-ksk ===hng-wan
738 ===hng-okd ===hng-wad ===hng-kmi
739 ===hng-zkd ===hng-doh ===hng-jyu
740 ===hng-tzs ===hng-kss ===hng-kyo
742 ;; (string-match "^=adobe-" (symbol-name name))
744 "(%-18s . %05d)\t; %c")
745 ((memq name '(=hanyo-denshi/ks
746 ==hanyo-denshi/ks ===hanyo-denshi/ks
749 =mj ==mj ===mj =>>mj =>mj
751 "(%-18s . %06d)\t; %c")
752 ((memq name '(=hanyo-denshi/tk ==hanyo-denshi/tk))
753 "(%-18s . %08d)\t; %c")
754 ((>= (charset-dimension name) 2)
755 "(%-18s . #x%04X)\t; %c")
757 "(%-18s . #x%02X)\t; %c"))
759 (if (= (charset-iso-graphic-plane name) 1)
761 (cond ((= (charset-dimension name) 1)
763 ((= (charset-dimension name) 2)
765 ((= (charset-dimension name) 3)
769 (char-db-decode-isolated-char name value)))
770 (if (and (= (charset-chars name) 94)
771 (= (charset-dimension name) 2))
772 (insert (format " [%02d-%02d]"
773 (- (lsh value -8) 32)
774 (- (logand value 255) 32))))
777 (insert (format "(%-18s . %s)" name value))
779 (insert line-breaking))
781 (defun char-db-insert-relation-feature (char name value line-breaking
783 (insert (format "(%-18s%s " name line-breaking))
784 (let ((lbs (concat "\n" (make-string (current-column) ?\ )))
785 separator cell sources required-features
787 (if (characterp value)
788 (setq value (list value)))
790 (setq cell (car value))
792 (setq cell (decode-char '=ucs cell)))
794 ((eq name '->subsumptive)
795 (when (or (not (some (lambda (atr)
796 (get-char-attribute cell atr))
797 char-db-ignored-attributes))
799 (encode-char cell ccs 'defined-only))
803 (let ((char-db-ignored-attributes
805 char-db-ignored-attributes)))
806 (insert-char-attributes cell readable nil nil 'for-sub-node))
807 (setq separator lbs))
812 char (intern (format "%s*sources" name))))
813 (setq required-features nil)
814 (dolist (source sources)
818 shinjigen shinjigen@1ed shinjigen@rev))
819 (setq required-features
820 (union required-features
832 =shinjigen/+p@rev))))
834 (setq required-features
835 (union required-features
840 ((find-charset (setq ret (intern (format "=%s" source))))
841 (setq required-features
842 (cons ret required-features)))
843 (t (setq required-features
844 (cons source required-features)))))
845 (cond ((string-match "@JP" (symbol-name name))
846 (setq required-features
847 (union required-features
855 ((string-match "@CN" (symbol-name name))
856 (setq required-features
857 (union required-features
864 (insert (format "%S" cell))
865 (char-db-insert-char-spec cell readable
868 (setq separator lbs))
872 (if (consp (car cell))
873 (char-db-insert-char-spec cell readable)
874 (char-db-insert-char-reference cell readable))
875 (setq separator lbs))
879 (insert (prin1-to-string cell))
880 (setq separator " ")))
881 (setq value (cdr value)))
883 (insert line-breaking)))
885 (defun insert-char-attributes (char &optional readable attributes column
888 (setq column (current-column)))
889 (let (name value ; has-long-ccs-name
893 (concat "\n" (make-string (1+ column) ?\ )))
894 lbs cell separator ret
896 dest-ccss ; sources required-features
901 (if (consp attributes)
903 (dolist (name attributes)
904 (unless (memq name char-db-ignored-attributes)
905 (if (find-charset name)
909 (dolist (name (char-attribute-list))
910 (unless (memq name char-db-ignored-attributes)
911 (if (find-charset name)
915 #'char-attribute-name<)))
917 (when (memq '<-subsumptive attributes)
918 (when (or readable (not for-sub-node))
919 (when (setq value (get-char-attribute char '<-subsumptive))
920 (char-db-insert-relation-feature char '<-subsumptive value
923 (setq attributes (delq '<-subsumptive attributes)))
924 (when (and (memq '<-denotational attributes)
925 (setq value (get-char-attribute char '<-denotational)))
926 (char-db-insert-relation-feature char '<-denotational value
929 (setq attributes (delq '<-denotational attributes)))
930 (when (and (memq '<-denotational@component attributes)
931 (setq value (get-char-attribute char '<-denotational@component)))
932 (char-db-insert-relation-feature char '<-denotational@component value
935 (setq attributes (delq '<-denotational@component attributes)))
936 (when (and (memq 'name attributes)
937 (setq value (get-char-attribute char 'name)))
939 (if (> (+ (current-column) (length value)) 48)
942 value line-breaking))
943 (setq attributes (delq 'name attributes))
945 (when (and (memq 'name* attributes)
946 (setq value (get-char-attribute char 'name*)))
948 (if (> (+ (current-column) (length value)) 48)
951 value line-breaking))
952 (setq attributes (delq 'name* attributes))
954 (when (and (memq 'script attributes)
955 (setq value (get-char-attribute char 'script)))
956 (insert (format "(script\t\t%s)%s"
957 (mapconcat (function prin1-to-string)
960 (setq attributes (delq 'script attributes))
962 (dolist (name '(=>ucs =>ucs*))
963 (when (and (memq name attributes)
964 (setq value (get-char-attribute char name)))
965 (insert (format "(%-18s . #x%04X)\t; %c%s"
966 name value (decode-char '=ucs value)
968 (setq attributes (delq name attributes))))
969 (dolist (name '(=>ucs@gb =>ucs@big5))
970 (when (and (memq name attributes)
971 (setq value (get-char-attribute char name)))
972 (insert (format "(%-18s . #x%04X)\t; %c%s"
977 (symbol-name name) 2)))
980 (setq attributes (delq name attributes))
982 ;; (dolist (name '(=>daikanwa))
983 ;; (when (and (memq name attributes)
984 ;; (setq value (get-char-attribute char name)))
986 ;; (if (integerp value)
987 ;; (format "(%-18s . %05d)\t; %c%s"
988 ;; name value (decode-char '=daikanwa value)
990 ;; (format "(%-18s %s)\t; %c%s"
992 ;; (mapconcat (function prin1-to-string)
994 ;; (char-representative-of-daikanwa char)
996 ;; (setq attributes (delq name attributes))))
997 (when (and (memq 'general-category attributes)
998 (setq value (get-char-attribute char 'general-category)))
1000 "(general-category\t%s) ; %s%s"
1001 (mapconcat (lambda (cell)
1004 (cond ((rassoc value unidata-normative-category-alist)
1005 "Normative Category")
1006 ((rassoc value unidata-informative-category-alist)
1007 "Informative Category")
1009 "Unknown Category"))
1011 (setq attributes (delq 'general-category attributes))
1013 (when (and (memq 'bidi-category attributes)
1014 (setq value (get-char-attribute char 'bidi-category)))
1015 (insert (format "(bidi-category\t. %S)%s"
1018 (setq attributes (delq 'bidi-category attributes))
1020 (unless (or (not (memq 'mirrored attributes))
1021 (eq (setq value (get-char-attribute char 'mirrored 'empty))
1023 (insert (format "(mirrored\t\t. %S)%s"
1026 (setq attributes (delq 'mirrored attributes))
1029 ((and (memq 'decimal-digit-value attributes)
1030 (setq value (get-char-attribute char 'decimal-digit-value)))
1031 (insert (format "(decimal-digit-value . %S)%s"
1034 (setq attributes (delq 'decimal-digit-value attributes))
1035 (when (and (memq 'digit-value attributes)
1036 (setq value (get-char-attribute char 'digit-value)))
1037 (insert (format "(digit-value\t . %S)%s"
1040 (setq attributes (delq 'digit-value attributes))
1042 (when (and (memq 'numeric-value attributes)
1043 (setq value (get-char-attribute char 'numeric-value)))
1044 (insert (format "(numeric-value\t . %S)%s"
1047 (setq attributes (delq 'numeric-value attributes))
1051 (when (and (memq 'digit-value attributes)
1052 (setq value (get-char-attribute char 'digit-value)))
1053 (insert (format "(digit-value\t. %S)%s"
1056 (setq attributes (delq 'digit-value attributes))
1058 (when (and (memq 'numeric-value attributes)
1059 (setq value (get-char-attribute char 'numeric-value)))
1060 (insert (format "(numeric-value\t. %S)%s"
1063 (setq attributes (delq 'numeric-value attributes))
1065 (when (and (memq 'iso-10646-comment attributes)
1066 (setq value (get-char-attribute char 'iso-10646-comment)))
1067 (insert (format "(iso-10646-comment\t. %S)%s"
1070 (setq attributes (delq 'iso-10646-comment attributes))
1072 (when (and (memq 'morohashi-daikanwa attributes)
1073 (setq value (get-char-attribute char 'morohashi-daikanwa)))
1074 (insert (format "(morohashi-daikanwa\t%s)%s"
1075 (mapconcat (function prin1-to-string) value " ")
1077 (setq attributes (delq 'morohashi-daikanwa attributes))
1081 (when (and (memq 'ideographic-radical attributes)
1082 (setq value (get-char-attribute char 'ideographic-radical)))
1083 (setq radical value)
1084 (insert (format "(ideographic-radical . %S)\t; %c%s"
1086 (ideographic-radical radical)
1088 (setq attributes (delq 'ideographic-radical attributes))
1090 (when (and (memq 'shuowen-radical attributes)
1091 (setq value (get-char-attribute char 'shuowen-radical)))
1092 (insert (format "(shuowen-radical\t. %S)\t; %c%s"
1094 (shuowen-radical value)
1096 (setq attributes (delq 'shuowen-radical attributes))
1101 char-db-feature-domains
1103 (dolist (feature (char-attribute-list))
1104 (setq feature (symbol-name feature))
1106 "\\(radical\\|strokes\\)@\\([^@*]+\\)\\(\\*\\|$\\)"
1108 (setq domain (intern (match-string 2 feature)))
1109 (unless (memq domain dest)
1110 (setq dest (cons domain dest)))))
1111 (sort dest #'string<))))
1112 (setq key (intern (format "%s@%s" 'ideographic-radical domain)))
1113 (when (and (memq key attributes)
1114 (setq value (get-char-attribute char key)))
1115 (setq radical value)
1116 (insert (format "(%s . %S)\t; %c%s"
1119 (ideographic-radical radical)
1121 (setq attributes (delq key attributes))
1123 (setq key (intern (format "%s@%s" 'ideographic-strokes domain)))
1124 (when (and (memq key attributes)
1125 (setq value (get-char-attribute char key)))
1126 (setq strokes value)
1127 (insert (format "(%s . %S)%s"
1131 (setq attributes (delq key attributes))
1133 (setq key (intern (format "%s@%s" 'total-strokes domain)))
1134 (when (and (memq key attributes)
1135 (setq value (get-char-attribute char key)))
1136 (insert (format "(%s . %S)%s"
1140 (setq attributes (delq key attributes))
1142 (dolist (feature '(ideographic-radical
1145 (setq key (intern (format "%s@%s*sources" feature domain)))
1146 (when (and (memq key attributes)
1147 (setq value (get-char-attribute char key)))
1148 (insert (format "(%s%s" key line-breaking))
1149 (dolist (cell value)
1150 (insert (format " %s" cell)))
1152 (insert line-breaking)
1153 (setq attributes (delq key attributes))
1156 (when (and (memq 'ideographic-strokes attributes)
1157 (setq value (get-char-attribute char 'ideographic-strokes)))
1158 (setq strokes value)
1159 (insert (format "(ideographic-strokes . %S)%s"
1162 (setq attributes (delq 'ideographic-strokes attributes))
1164 (when (and (memq 'kangxi-radical attributes)
1165 (setq value (get-char-attribute char 'kangxi-radical)))
1166 (unless (eq value radical)
1167 (insert (format "(kangxi-radical\t . %S)\t; %c%s"
1169 (ideographic-radical value)
1172 (setq radical value)))
1173 (setq attributes (delq 'kangxi-radical attributes))
1175 (when (and (memq 'kangxi-strokes attributes)
1176 (setq value (get-char-attribute char 'kangxi-strokes)))
1177 (unless (eq value strokes)
1178 (insert (format "(kangxi-strokes\t . %S)%s"
1182 (setq strokes value)))
1183 (setq attributes (delq 'kangxi-strokes attributes))
1185 ;; (when (and (memq 'japanese-radical attributes)
1186 ;; (setq value (get-char-attribute char 'japanese-radical)))
1187 ;; (unless (eq value radical)
1188 ;; (insert (format "(japanese-radical\t . %S)\t; %c%s"
1190 ;; (ideographic-radical value)
1193 ;; (setq radical value)))
1194 ;; (setq attributes (delq 'japanese-radical attributes))
1196 (when (and (memq 'japanese-strokes attributes)
1197 (setq value (get-char-attribute char 'japanese-strokes)))
1198 (unless (eq value strokes)
1199 (insert (format "(japanese-strokes\t . %S)%s"
1203 (setq strokes value)))
1204 (setq attributes (delq 'japanese-strokes attributes))
1206 (when (and (memq 'cns-radical attributes)
1207 (setq value (get-char-attribute char 'cns-radical)))
1208 (insert (format "(cns-radical\t . %S)\t; %c%s"
1210 (ideographic-radical value)
1212 (setq attributes (delq 'cns-radical attributes))
1214 (when (and (memq 'cns-strokes attributes)
1215 (setq value (get-char-attribute char 'cns-strokes)))
1216 (unless (eq value strokes)
1217 (insert (format "(cns-strokes\t . %S)%s"
1221 (setq strokes value)))
1222 (setq attributes (delq 'cns-strokes attributes))
1224 ;; (when (and (memq 'shinjigen-1-radical attributes)
1225 ;; (setq value (get-char-attribute char 'shinjigen-1-radical)))
1226 ;; (unless (eq value radical)
1227 ;; (insert (format "(shinjigen-1-radical . %S)\t; %c%s"
1229 ;; (ideographic-radical value)
1232 ;; (setq radical value)))
1233 ;; (setq attributes (delq 'shinjigen-1-radical attributes))
1235 ;; (when (and (memq 'ideographic- attributes)
1236 ;; (setq value (get-char-attribute char 'ideographic-)))
1237 ;; (insert "(ideographic- ")
1238 ;; (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1240 ;; (while (consp value)
1241 ;; (setq cell (car value))
1242 ;; (if (integerp cell)
1243 ;; (setq cell (decode-char '=ucs cell)))
1244 ;; (cond ((characterp cell)
1248 ;; (insert (format "%S" cell))
1249 ;; (char-db-insert-char-spec cell readable))
1250 ;; (setq separator lbs))
1254 ;; (if (consp (car cell))
1255 ;; (char-db-insert-char-spec cell readable)
1256 ;; (char-db-insert-char-reference cell readable))
1257 ;; (setq separator lbs))
1260 ;; (insert separator))
1261 ;; (insert (prin1-to-string cell))
1262 ;; (setq separator " ")))
1263 ;; (setq value (cdr value)))
1265 ;; (insert line-breaking)
1266 ;; (setq attributes (delq 'ideographic- attributes)))
1267 (when (and (memq 'total-strokes attributes)
1268 (setq value (get-char-attribute char 'total-strokes)))
1269 (insert (format "(total-strokes . %S)%s"
1272 (setq attributes (delq 'total-strokes attributes))
1274 ;; (when (and (memq '->ideograph attributes)
1275 ;; (setq value (get-char-attribute char '->ideograph)))
1276 ;; (insert (format "(->ideograph\t%s)%s"
1277 ;; (mapconcat (lambda (code)
1278 ;; (cond ((symbolp code)
1279 ;; (symbol-name code))
1281 ;; (format "#x%04X" code))
1284 ;; line-breaking code))))
1287 ;; (setq attributes (delq '->ideograph attributes))
1289 ;; (when (and (memq '->decomposition attributes)
1290 ;; (setq value (get-char-attribute char '->decomposition)))
1291 ;; (insert (format "(->decomposition\t%s)%s"
1292 ;; (mapconcat (lambda (code)
1293 ;; (cond ((symbolp code)
1294 ;; (symbol-name code))
1295 ;; ((characterp code)
1297 ;; (format "%S" code)
1302 ;; (format "#x%04X" code))
1304 ;; (format "%s%S" line-breaking code))))
1307 ;; (setq attributes (delq '->decomposition attributes))
1309 (if (equal (get-char-attribute char '->titlecase)
1310 (get-char-attribute char '->uppercase))
1311 (setq attributes (delq '->titlecase attributes)))
1312 (when (and (memq '->mojikyo attributes)
1313 (setq value (get-char-attribute char '->mojikyo)))
1314 (insert (format "(->mojikyo\t\t. %06d)\t; %c%s"
1315 value (decode-char 'mojikyo value)
1317 (setq attributes (delq '->mojikyo attributes))
1319 ;; (when (and (memq 'hanyu-dazidian-vol attributes)
1320 ;; (setq value (get-char-attribute char 'hanyu-dazidian-vol)))
1321 ;; (insert (format "(hanyu-dazidian-vol . %d)%s"
1322 ;; value line-breaking))
1323 ;; (setq attributes (delq 'hanyu-dazidian-vol attributes))
1325 ;; (when (and (memq 'hanyu-dazidian-page attributes)
1326 ;; (setq value (get-char-attribute char 'hanyu-dazidian-page)))
1327 ;; (insert (format "(hanyu-dazidian-page . %d)%s"
1328 ;; value line-breaking))
1329 ;; (setq attributes (delq 'hanyu-dazidian-page attributes))
1331 ;; (when (and (memq 'hanyu-dazidian-char attributes)
1332 ;; (setq value (get-char-attribute char 'hanyu-dazidian-char)))
1333 ;; (insert (format "(hanyu-dazidian-char . %d)%s"
1334 ;; value line-breaking))
1335 ;; (setq attributes (delq 'hanyu-dazidian-char attributes))
1338 (dolist (ignored '(composition
1339 ->denotational <-subsumptive ->ucs-unified
1340 ->ideographic-component-forms))
1341 (setq attributes (delq ignored attributes))))
1343 (setq name (car attributes))
1344 (unless (eq (setq value (get-char-attribute char name 'value-is-empty))
1346 (cond ((setq ret (find-charset name))
1347 (setq name (charset-name ret))
1348 (when (not (memq name dest-ccss))
1349 (setq dest-ccss (cons name dest-ccss))
1350 (char-db-insert-ccs-feature name value line-breaking))
1352 ((string-match "^=>ucs@" (symbol-name name))
1353 (insert (format "(%-18s . #x%04X)\t; %c%s"
1354 name value (decode-char '=ucs value)
1357 ((eq name 'jisx0208-1978/4X)
1358 (insert (format "(%-18s . #x%04X)%s"
1364 (not (eq name '->subsumptive))
1365 (not (eq name '->uppercase))
1366 (not (eq name '->lowercase))
1367 (not (eq name '->titlecase))
1368 (not (eq name '->canonical))
1369 (not (eq name '->Bopomofo))
1370 (not (eq name '->mistakable))
1371 (not (eq name '->ideographic-variants))
1372 (null (get-char-attribute
1373 char (intern (format "%s*sources" name))))
1374 (not (string-match "\\*sources$" (symbol-name name)))
1375 (null (get-char-attribute
1376 char (intern (format "%s*note" name))))
1377 (not (string-match "\\*note$" (symbol-name name)))
1378 (or (eq name '<-identical)
1379 (eq name '<-uppercase)
1380 (eq name '<-lowercase)
1381 (eq name '<-titlecase)
1382 (eq name '<-canonical)
1383 (eq name '<-ideographic-variants)
1384 ;; (eq name '<-synonyms)
1385 (string-match "^<-synonyms" (symbol-name name))
1386 (eq name '<-mistakable)
1387 (when (string-match "^->" (symbol-name name))
1389 ((string-match "^->fullwidth" (symbol-name name))
1390 (not (and (consp value)
1391 (characterp (car value))
1393 (car value) '=ucs 'defined-only)))
1398 ((or (eq name 'ideographic-structure)
1399 (eq name 'ideographic-combination)
1400 ;; (eq name 'ideographic-)
1401 (eq name '=decomposition)
1402 (char-feature-base-name= '=decomposition name)
1403 (char-feature-base-name= '=>decomposition name)
1404 ;; (string-match "^=>*decomposition\\(@[^*]+\\)?$"
1405 ;; (symbol-name name))
1406 (string-match "^\\(->\\|<-\\)[^*]*$" (symbol-name name))
1407 (string-match "^\\(->\\|<-\\)[^*]*\\*sources$"
1410 (char-db-insert-relation-feature char name value
1413 ;; ((memq name '(ideograph=
1414 ;; original-ideograph-of
1415 ;; ancient-ideograph-of
1416 ;; vulgar-ideograph-of
1417 ;; wrong-ideograph-of
1418 ;; ;; simplified-ideograph-of
1419 ;; ideographic-variants
1420 ;; ;; ideographic-different-form-of
1422 ;; (insert (format "(%-18s%s " name line-breaking))
1423 ;; (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1425 ;; (while (consp value)
1426 ;; (setq cell (car value))
1427 ;; (if (and (consp cell)
1428 ;; (consp (car cell)))
1432 ;; (char-db-insert-alist cell readable)
1433 ;; (setq separator lbs))
1435 ;; (insert separator))
1436 ;; (insert (prin1-to-string cell))
1437 ;; (setq separator " "))
1438 ;; (setq value (cdr value)))
1440 ;; (insert line-breaking))
1442 (insert (format "(%-18s " name))
1443 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1445 (while (consp value)
1446 (setq cell (car value))
1447 (if (and (consp cell)
1449 (setq ret (condition-case nil
1457 (setq key (car (car rest)))
1458 (if (find-charset key)
1459 (setq cal (cons key cal))
1460 (setq al (cons key al)))
1461 (setq rest (cdr rest)))
1464 (insert-char-attributes ret
1468 (setq separator lbs))
1469 (setq ret (prin1-to-string cell))
1471 (if (< (+ (current-column)
1478 (setq separator " "))
1479 (setq value (cdr value)))
1481 (insert line-breaking))
1483 (insert (format "(%-18s" name))
1484 (setq ret (prin1-to-string value))
1485 (unless (< (+ (current-column)
1489 (insert line-breaking))
1490 (insert " . " ret ")" line-breaking)
1491 ;; (insert (format "(%-18s . %S)%s"
1496 (setq attributes (cdr attributes)))
1499 (defun insert-char-data (char &optional readable
1502 (narrow-to-region (point)(point))
1503 (insert "(define-char
1505 (insert-char-attributes char readable attributes)
1507 (goto-char (point-min))
1508 (while (re-search-forward "[ \t]+$" nil t)
1511 (goto-char (point-min))
1512 (while (re-search-forward "[ \t][ \t][ \t]*" nil t)
1513 (let ((column (current-column))
1514 (indent-tabs-mode t))
1515 (delete-region (match-beginning 0) (point))
1516 (indent-to column)))
1517 (goto-char (point-max))
1518 ;; (tabify (point-min)(point-max))
1521 (defun insert-char-data-with-variant (char &optional printable
1523 script excluded-script)
1524 (insert-char-data char printable)
1525 (let ((variants (char-variants char))
1528 (setq variants (sort variants #'<))
1529 (setq rest variants)
1530 (setq variants (cons char variants))
1532 (setq variant (car rest))
1533 (unless (get-char-attribute variant '<-subsumptive)
1534 (if (and (or (null script)
1535 (null (setq vs (get-char-attribute variant 'script)))
1537 (or (null excluded-script)
1538 (null (setq vs (get-char-attribute variant 'script)))
1539 (not (memq excluded-script vs))))
1540 (unless (and no-ucs-unified (get-char-attribute variant '=ucs))
1541 (insert-char-data variant printable)
1542 (if (setq ret (char-variants variant))
1544 (or (memq (car ret) variants)
1545 ;; (get-char-attribute (car ret) '<-subsumptive)
1546 (setq rest (nconc rest (list (car ret)))))
1547 (setq ret (cdr ret)))))))
1548 (setq rest (cdr rest)))))
1550 (defun insert-char-range-data (min max &optional script excluded-script)
1553 (while (<= code max)
1554 (setq char (decode-char '=ucs code))
1555 (if (encode-char char '=ucs 'defined-only)
1556 (insert-char-data-with-variant char nil 'no-ucs-unified
1557 script excluded-script))
1558 (setq code (1+ code)))))
1560 (defun write-char-range-data-to-file (min max file
1561 &optional script excluded-script)
1562 (let ((coding-system-for-write char-db-file-coding-system))
1564 (insert (format ";; -*- coding: %s -*-\n"
1565 char-db-file-coding-system))
1566 (insert-char-range-data min max script excluded-script)
1567 (write-region (point-min)(point-max) file))))
1569 (defvar what-character-original-window-configuration)
1572 (defun what-char-definition (char)
1573 (interactive (list (char-after)))
1574 (let ((buf (get-buffer-create "*Character Description*"))
1575 (the-buf (current-buffer))
1576 (win-conf (current-window-configuration)))
1578 (make-local-variable 'what-character-original-window-configuration)
1579 (setq what-character-original-window-configuration win-conf)
1580 (setq buffer-read-only nil)
1584 (insert-char-data-with-variant char 'printable)
1585 (unless (char-attribute-alist char)
1586 (insert (format ";; = %c\n"
1587 (let* ((rest (split-char char))
1591 (setq code (logior (lsh code 8)
1593 (decode-char ccs code)))))
1594 ;; (char-db-update-comment)
1595 (set-buffer-modified-p nil)
1596 (view-mode the-buf (lambda (buf)
1597 (set-window-configuration
1598 what-character-original-window-configuration)
1600 (goto-char (point-min)))
1602 (set-window-configuration
1603 what-character-original-window-configuration)
1604 (signal (car err) (cdr err)))))))
1610 (provide 'char-db-util)
1612 ;;; char-db-util.el ends here