1 ;;; char-db-util.el --- Character Database utility -*- coding: utf-8-er; -*-
3 ;; Copyright (C) 1998,1999,2000,2001,2002,2003,2004,2005,2006,2007,
4 ;; 2008,2009,2010,2011,2012,2013,2014,2015,2016,2017,2018 MORIOKA Tomohiko.
6 ;; Author: MORIOKA Tomohiko <tomo@kanji.zinbun.kyoto-u.ac.jp>
7 ;; Keywords: CHISE, Character Database, ISO/IEC 10646, UCS, Unicode, MULE.
9 ;; This file is part of XEmacs CHISE.
11 ;; XEmacs CHISE is free software; you can redistribute it and/or
12 ;; modify it under the terms of the GNU General Public License as
13 ;; published by the Free Software Foundation; either version 2, or (at
14 ;; your option) any later version.
16 ;; XEmacs CHISE is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 ;; General Public License for more details.
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with XEmacs CHISE; see the file COPYING. If not, write to
23 ;; the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
24 ;; Boston, MA 02111-1307, USA.
29 (require 'ideograph-subr)
31 (defconst unidata-normative-category-alist
32 '(("Lu" letter uppercase)
33 ("Ll" letter lowercase)
34 ("Lt" letter titlecase)
35 ("Mn" mark non-spacing)
36 ("Mc" mark spacing-combining)
38 ("Nd" number decimal-digit)
41 ("Zs" separator space)
43 ("Zp" separator paragraph)
46 ("Cs" other surrogate)
47 ("Co" other private-use)
48 ("Cn" other not-assigned)))
50 (defconst unidata-informative-category-alist
51 '(("Lm" letter modifier)
53 ("Pc" punctuation connector)
54 ("Pd" punctuation dash)
55 ("Ps" punctuation open)
56 ("Pe" punctuation close)
57 ("Pi" punctuation initial-quote)
58 ("Pf" punctuation final-quote)
59 ("Po" punctuation other)
61 ("Sc" symbol currency)
62 ("Sk" symbol modifier)
66 (defconst shuowen-radicals
67 [?一 ?上 ?示 ?三 ?王 ?玉 ?玨 ?气 ?士 ?丨 ; 010
68 ?屮 ?艸 ?蓐 ?茻 ?小 ?八 ?釆 ?半 ?牛 ?犛 ; 020
69 ?告 ?口 ?凵 ?吅 ?哭 ?走 ?止 ?癶 ?步 ?此 ; 030
70 ?正 ?是 ?辵 ?彳 ?廴 ?㢟 ?行 ?齒 ?牙 ?足 ; 040
71 ?疋 ?品 ?龠 ?冊 ?㗊 ?舌 ?干 ?𧮫 ?只 ?㕯 ; 050
72 ?句 ?丩 ?古 ?十 ?卅 ?言 ?誩 ?音 ?䇂 ?丵 ; 060
73 ?菐 ?廾 ?𠬜 ?共 ?異 ?舁 ?𦥑 ?䢅 ?爨 ?革 ; 070
74 ?鬲 ?䰜 ?爪 ?𠃨 ?鬥 ?又 ?𠂇 ?史 ?支 ?𦘒 ; 080
75 ?聿 ?畫 ?隶 ?臤 ?臣 ?殳 ?殺 ?𠘧 ?寸 ?皮 ; 090
76 ?㼱 ?攴 ?敎 ?卜 ?用 ?爻 ?㸚 ?𥄎 ?目 ?䀠 ; 100
77 ?眉 ?盾 ?自 ?白 ?鼻 ?皕 ?習 ?羽 ?隹 ?奞 ; 110
78 ?雈 ?𦫳 ?𥄕 ?羊 ?羴 ?瞿 ?雔 ?雥 ?鳥 ?烏 ; 120
79 ?𠦒 ?冓 ?幺 ?𢆶 ?叀 ?玄 ?予 ?放 ?𠬪 ?𣦼 ; 130
80 ?歺 ?死 ?冎 ?骨 ?肉 ?筋 ?刀 ?刃 ?㓞 ?丯 ; 140
81 ?耒 ?角 ?竹 ?箕 ?丌 ?左 ?工 ?㠭 ?巫 ?甘 ; 150
82 ?曰 ?乃 ?丂 ?可 ?兮 ?号 ?亏 ?旨 ?喜 ?壴 ; 160
83 ; ?旨 ?曰 ?乃 ?丂 ?可 ?兮 ?号 ?亏 ?喜 ?壴 ; 160
84 ?鼓 ?豈 ?豆 ?豊 ?豐 ?䖒 ?虍 ?虎 ?虤 ?皿 ; 170
85 ?𠙴 ?去 ?血 ?丶 ?丹 ?青 ?井 ?皀 ?鬯 ?食 ; 180
86 ?亼 ?會 ?倉 ?入 ?缶 ?矢 ?高 ?冂 ?𩫏 ?京 ; 190
87 ?亯 ?𣆪 ?畗 ?㐭 ?嗇 ?來 ?麥 ?夊 ?舛 ?䑞 ; 200
88 ?韋 ?弟 ?夂 ?久 ?桀 ?木 ?東 ?林 ?才 ?叒 ; 210
89 ?之 ?帀 ?出 ?𣎵 ?生 ?乇 ?𠂹 ?𠌶 ?華 ?𥝌 ; 220
90 ?稽 ?巢 ?桼 ?束 ?㯻 ?囗 ?員 ?貝 ?邑 ?𨛜 ; 230
91 ?日 ?旦 ?倝 ?㫃 ?冥 ?晶 ?月 ?有 ?明 ?囧 ; 240
92 ?夕 ?多 ?毌 ?𢎘 ?𣐺 ?𠧪 ?齊 ?朿 ?片 ?鼎 ; 250
93 ?克 ?彔 ?禾 ?秝 ?黍 ?香 ?米 ?毇 ?臼 ?凶 ; 260
94 ?𣎳 ?𣏟 ?麻 ?尗 ?耑 ?韭 ?瓜 ?瓠 ?宀 ?宮 ; 270
95 ?呂 ?穴 ?㝱 ?疒 ?冖 ?𠔼 ?冃 ?㒳 ?网 ?襾 ; 280
96 ?巾 ?巿 ?帛 ?白 ?㡀 ?黹 ?人 ?𠤎 ?匕 ?从 ; 290
97 ?比 ?北 ?丘 ?㐺 ?𡈼 ?重 ?臥 ?身 ?㐆 ?衣 ; 300
98 ?裘 ?老 ?毛 ?毳 ?尸 ?尺 ?尾 ?履 ?舟 ?方 ; 310
99 ?儿 ?兄 ?兂 ?皃 ?𠑹 ?先 ?秃 ?見 ?覞 ?欠 ; 320
100 ?㱃 ?㳄 ?旡 ?頁 ?𦣻 ?面 ?丏 ?首 ?𥄉 ?須 ; 330
101 ?彡 ?彣 ?文 ?髟 ?后 ?司 ?卮 ?卩 ?印 ?色 ; 340
102 ?𠨍 ?辟 ?勹 ?包 ?茍 ?鬼 ?甶 ?厶 ?嵬 ?山 ; 350
103 ?屾 ?屵 ?广 ?厂 ?丸 ?危 ?石 ?長 ?勿 ?冄 ; 360
104 ?而 ?豕 ?㣇 ?彑 ?豚 ?豸 ?𤉡 ?易 ?象 ?馬 ; 370
105 ?𢊁 ?鹿 ?麤 ?㲋 ?兔 ?萈 ?犬 ?㹜 ?鼠 ?能 ; 380
106 ?熊 ?火 ?炎 ?黑 ?囪 ?焱 ?炙 ?赤 ?大 ?亦 ; 390
107 ?夨 ?夭 ?交 ?尣 ?壺 ?壹 ?㚔 ?奢 ?亢 ?夲 ; 400
110 (defun shuowen-radical (number)
111 (aref shuowen-radicals (1- number)))
113 (defvar char-db-file-coding-system 'utf-8-mcs-er)
115 (defvar char-db-ignored-attributes '(ideographic-products))
117 (defvar char-db-coded-charset-priority-list
215 ;; =>>>adobe-japan1-0
216 ;; =>>>adobe-japan1-1
217 ;; =>>>adobe-japan1-2
218 ;; =>>>adobe-japan1-3
219 ;; =>>>adobe-japan1-4
220 ;; =>>>adobe-japan1-5
221 ;; =>>>adobe-japan1-6
225 ;; =>>>hanyo-denshi/ja
226 ;; =>>>hanyo-denshi/jb
227 ;; =>>>hanyo-denshi/jc
228 ;; =>>>hanyo-denshi/ft
229 ;; =>>>hanyo-denshi/ib
230 ;; =>>>hanyo-denshi/hg
231 ;; =>>>hanyo-denshi/jt
232 ;; =>>>hanyo-denshi/ks
272 ;; =>ucs@hanyo-denshi
370 =>big5-cdp-itaiji-001
374 =>ucs-itaiji-001@iwds-1
384 ;;; @ char-db formatters
387 (defun char-db-make-char-spec (char)
389 (cond ((characterp char)
390 (cond ((and (setq ret (encode-char char '=ucs 'defined-only))
391 (not (and (<= #xE000 ret)(<= ret #xF8FF))))
392 (setq char-spec (list (cons '=ucs ret)))
393 (cond ((setq ret (get-char-attribute char 'name))
394 (setq char-spec (cons (cons 'name ret) char-spec))
396 ((setq ret (get-char-attribute char 'name*))
397 (setq char-spec (cons (cons 'name* ret) char-spec))
400 ((encode-char char '=mj 'defined-only)
402 (dolist (ccs (charset-list))
403 (if (and (or (eq ccs '=mj)
404 ;; (eq (charset-property ccs 'iso-ir) 177)
405 (string-match "=ucs@" (symbol-name ccs))
407 (setq ccs (charset-name ccs))
408 (null (assq ccs char-spec))
409 (setq ret (encode-char char ccs 'defined-only)))
410 (setq char-spec (cons (cons ccs ret) char-spec))))
412 ((encode-char char '==mj 'defined-only)
414 (dolist (ccs (charset-list))
415 (if (and (or (eq ccs '==mj)
416 ;; (eq (charset-property ccs 'iso-ir) 177)
417 (string-match "=ucs@" (symbol-name ccs))
419 (setq ccs (charset-name ccs))
420 (null (assq ccs char-spec))
421 (setq ret (encode-char char ccs 'defined-only)))
422 (setq char-spec (cons (cons ccs ret) char-spec))))
424 ((encode-char char '=adobe-japan1 'defined-only)
426 (dolist (ccs (charset-list))
427 (if (and (or (memq ccs
436 ;; (eq (charset-property ccs 'iso-ir) 177)
437 (string-match "=ucs@" (symbol-name ccs))
439 (setq ccs (charset-name ccs))
440 (null (assq ccs char-spec))
441 (setq ret (encode-char char ccs 'defined-only)))
442 (setq char-spec (cons (cons ccs ret) char-spec))))
444 ((encode-char char '==adobe-japan1 'defined-only)
446 (dolist (ccs (charset-list))
447 (if (and (or (memq ccs
456 ;; (eq (charset-property ccs 'iso-ir) 177)
457 (string-match "=ucs@" (symbol-name ccs))
459 (setq ccs (charset-name ccs))
460 (null (assq ccs char-spec))
461 (setq ret (encode-char char ccs 'defined-only)))
462 (setq char-spec (cons (cons ccs ret) char-spec))))
466 (let ((rest char-db-coded-charset-priority-list)
469 (setq ccs (charset-name
470 (find-charset (car rest))))
472 (encode-char char ccs
474 (throw 'tag (cons ccs ret)))
475 (setq rest (cdr rest))))))
476 (setq char-spec (list ret))
477 (dolist (ccs (delq (car ret) (charset-list)))
478 (if (and (or (charset-iso-final-char ccs)
485 (and (eq (charset-property ccs 'iso-ir) 177)
486 (not (eq (charset-name ccs) '=ucs@big5)))
487 ;; (string-match "=ucs@" (symbol-name ccs))
489 (setq ccs (charset-name ccs))
490 (null (assq ccs char-spec))
491 (setq ret (encode-char char ccs 'defined-only)))
492 (setq char-spec (cons (cons ccs ret) char-spec))))
494 (setq char-spec (split-char char)))
495 (cond ((setq ret (get-char-attribute char 'name))
496 (setq char-spec (cons (cons 'name ret) char-spec))
498 ((setq ret (get-char-attribute char 'name*))
499 (setq char-spec (cons (cons 'name* ret) char-spec))
502 ((setq ret (get-char-attribute
503 char 'ideographic-combination))
505 (cons (cons 'ideographic-combination ret)
512 (defun char-db-insert-char-spec (char &optional readable column
515 (setq column (current-column)))
516 (let (char-spec temp-char)
517 (setq char-spec (char-db-make-char-spec char))
518 (unless (or (characterp char) ; char
520 (setq char (find-char char-spec))
522 ;; define temporary character
523 ;; Current implementation is dirty.
524 (setq temp-char (define-char (cons '(ideograph-daikanwa . 0)
526 (remove-char-attribute temp-char 'ideograph-daikanwa)
527 (setq char temp-char))
528 (insert-char-attributes char
530 (union (mapcar #'car char-spec)
534 ;; undefine temporary character
535 ;; Current implementation is dirty.
536 (setq char-spec (char-attribute-alist temp-char))
538 (remove-char-attribute temp-char (car (car char-spec)))
539 (setq char-spec (cdr char-spec))))))
541 (defun char-db-insert-alist (alist &optional readable column)
543 (setq column (current-column)))
545 (concat "\n" (make-string (1+ column) ?\ )))
549 lbs cell rest separator)
552 (setq name (car (car alist))
553 value (cdr (car alist)))
554 (cond ((eq name 'char)
556 (if (setq ret (condition-case nil
564 (setq key (car (car value)))
565 ;; (if (find-charset key)
566 ;; (setq cal (cons key cal))
567 (setq al (cons key al))
569 (setq value (cdr value)))
570 (insert-char-attributes ret
574 (insert (prin1-to-string value)))
576 (insert line-breaking))
578 (insert (format "(%-18s " name))
579 (setq lbs (concat "\n" (make-string (current-column) ?\ )))
581 (setq cell (car value))
582 (if (and (consp cell)
584 (setq ret (condition-case nil
594 (setq key (car (car rest)))
595 ;; (if (find-charset key)
596 ;; (setq cal (cons key cal))
597 (setq al (cons key al))
599 (setq rest (cdr rest)))
602 (insert-char-attributes ret
606 (setq separator lbs))
609 (insert (prin1-to-string cell))
610 (setq separator " "))
611 (setq value (cdr value)))
613 (insert line-breaking))
615 (insert (format "(%-18s . %S)%s"
618 (setq alist (cdr alist))))
621 (defun char-db-insert-char-reference (plist &optional readable column)
623 (setq column (current-column)))
625 (concat "\n" (make-string (1+ column) ?\ )))
630 (setq name (pop plist))
631 (setq value (pop plist))
632 (cond ((eq name :char)
635 (cond ((numberp value)
636 (setq value (decode-char '=ucs value)))
638 ;; (setq value (or (find-char value)
641 (char-db-insert-char-spec value readable)
642 (insert line-breaking)
645 (insert (format "%s%s\t%d ; %c%s"
648 (ideographic-radical value)
652 (insert (format "%s%s\t%S" separator name value))
653 (setq separator line-breaking)))
657 (defun char-db-decode-isolated-char (ccs code-point)
660 (cond ((eq ccs 'arabic-iso8859-6)
661 (decode-char ccs code-point))
663 ;; (decode-builtin-char '==gt code-point))
664 ((and (memq ccs '(=gt-pj-1
675 (setq ret (decode-char ccs code-point))
676 (setq ret (encode-char ret '=gt 'defined-only)))
677 (decode-builtin-char '=gt ret))
679 (decode-builtin-char ccs code-point))))
681 (or (decode-char ccs code-point)
682 (define-char (list (cons ccs code-point)))))
683 ((and (<= 0 (char-int ret))
684 (<= (char-int ret) #x1F))
685 (decode-char '=ucs (+ #x2400 (char-int ret))))
686 ((= (char-int ret) #x7F)
690 (defvar char-db-convert-obsolete-format t)
692 (defun char-db-insert-ccs-feature (name value line-breaking)
698 ((memq name '(=>iwds-1
701 =shinjigen@1ed ==shinjigen@1ed
702 =shinjigen@rev ==shinjigen@rev
703 =shinjigen/+p@rev ==shinjigen/+p@rev
704 ===daikanwa/ho ==daikanwa/ho
705 =daikanwa/ho =>>daikanwa/ho =>daikanwa/ho))
706 "(%-18s . %04d)\t; %c")
707 ((eq name '=shinjigen@1ed/24pr)
708 "(%-18s . %04d)\t; %c")
712 ==daikanwa =daikanwa =>>daikanwa =>daikanwa
713 =daikanwa@rev1 =daikanwa@rev2
714 =daikanwa/+p ==daikanwa/+p ===daikanwa/+p
716 =daikanwa/+2p =>>daikanwa/+2p
721 =adobe-japan1-0 ==adobe-japan1-0 ===adobe-japan1-0
722 =adobe-japan1-1 ==adobe-japan1-1 ===adobe-japan1-1
723 =adobe-japan1-2 ==adobe-japan1-2 ===adobe-japan1-2
724 =adobe-japan1-3 ==adobe-japan1-3 ===adobe-japan1-3
725 =adobe-japan1-4 ==adobe-japan1-4 ===adobe-japan1-4
726 =adobe-japan1-5 ==adobe-japan1-5 ===adobe-japan1-5
727 =adobe-japan1-6 ==adobe-japan1-6 ===adobe-japan1-6
728 =>>adobe-japan1-0 =+>adobe-japan1-0
729 =>>adobe-japan1-1 =+>adobe-japan1-1
730 =>>adobe-japan1-2 =+>adobe-japan1-2
731 =>>adobe-japan1-3 =+>adobe-japan1-3
732 =>>adobe-japan1-4 =+>adobe-japan1-4
733 =>>adobe-japan1-5 =+>adobe-japan1-5
734 =>>adobe-japan1-6 =+>adobe-japan1-6
735 =>cbeta =cbeta =>>cbeta ==cbeta ===cbeta
736 =zinbun-oracle =>zinbun-oracle
737 ===hng-jou ===hng-keg ===hng-dng ===hng-mam
738 ===hng-drt ===hng-kgk ===hng-myz ===hng-kda
739 ===hng-khi ===hng-khm ===hng-hok ===hng-kyd ===hng-sok
740 ===hng-yhk ===hng-kak ===hng-kar ===hng-kae
741 ===hng-sys ===hng-tsu ===hng-tzj
742 ===hng-hos ===hng-nak ===hng-jhk
743 ===hng-hod ===hng-gok ===hng-ink ===hng-nto
744 ===hng-nkm ===hng-k24 ===hng-nkk
745 ===hng-kcc ===hng-kcj ===hng-kbk ===hng-sik
746 ===hng-skk ===hng-kyu ===hng-ksk ===hng-wan
747 ===hng-okd ===hng-wad ===hng-kmi
748 ===hng-zkd ===hng-doh ===hng-jyu
749 ===hng-tzs ===hng-kss ===hng-kyo
751 =shuowen-jiguge ===shuowen-jiguge4 ===shuowen-jiguge5))
752 ;; (string-match "^=adobe-" (symbol-name name))
754 "(%-18s . %05d)\t; %c")
755 ((memq name '(=hanyo-denshi/ks
756 ==hanyo-denshi/ks ===hanyo-denshi/ks
759 =mj ==mj ===mj =>>mj =>mj
761 "(%-18s . %06d)\t; %c")
762 ((memq name '(=hanyo-denshi/tk ==hanyo-denshi/tk))
763 "(%-18s . %08d)\t; %c")
764 ((>= (charset-dimension name) 2)
765 "(%-18s . #x%04X)\t; %c")
767 "(%-18s . #x%02X)\t; %c"))
769 (if (= (charset-iso-graphic-plane name) 1)
771 (cond ((= (charset-dimension name) 1)
773 ((= (charset-dimension name) 2)
775 ((= (charset-dimension name) 3)
779 (char-db-decode-isolated-char name value)))
780 (if (and (= (charset-chars name) 94)
781 (= (charset-dimension name) 2))
782 (insert (format " [%02d-%02d]"
783 (- (lsh value -8) 32)
784 (- (logand value 255) 32))))
787 (insert (format "(%-18s . %s)" name value))
789 (insert line-breaking))
791 (defun char-db-insert-relation-feature (char name value line-breaking
793 (insert (format "(%-18s%s " name line-breaking))
794 (let ((lbs (concat "\n" (make-string (current-column) ?\ )))
795 separator cell sources required-features
798 (setq cell (car value))
800 (setq cell (decode-char '=ucs cell)))
802 ((eq name '->subsumptive)
803 (when (or (not (some (lambda (atr)
804 (get-char-attribute cell atr))
805 char-db-ignored-attributes))
807 (encode-char cell ccs 'defined-only))
811 (let ((char-db-ignored-attributes
813 char-db-ignored-attributes)))
814 (insert-char-attributes cell readable nil nil 'for-sub-node))
815 (setq separator lbs))
820 char (intern (format "%s*sources" name))))
821 (setq required-features nil)
822 (dolist (source sources)
826 shinjigen shinjigen@1ed shinjigen@rev))
827 (setq required-features
828 (union required-features
840 =shinjigen/+p@rev))))
842 (setq required-features
843 (union required-features
848 ((find-charset (setq ret (intern (format "=%s" source))))
849 (setq required-features
850 (cons ret required-features)))
851 (t (setq required-features
852 (cons source required-features)))))
853 (cond ((string-match "@JP" (symbol-name name))
854 (setq required-features
855 (union required-features
863 ((string-match "@CN" (symbol-name name))
864 (setq required-features
865 (union required-features
872 (insert (format "%S" cell))
873 (char-db-insert-char-spec cell readable
876 (setq separator lbs))
880 (if (consp (car cell))
881 (char-db-insert-char-spec cell readable)
882 (char-db-insert-char-reference cell readable))
883 (setq separator lbs))
887 (insert (prin1-to-string cell))
888 (setq separator " ")))
889 (setq value (cdr value)))
891 (insert line-breaking)))
893 (defun insert-char-attributes (char &optional readable attributes column
896 (setq column (current-column)))
897 (let (name value ; has-long-ccs-name
901 (concat "\n" (make-string (1+ column) ?\ )))
902 lbs cell separator ret
904 dest-ccss ; sources required-features
909 (if (consp attributes)
911 (dolist (name attributes)
912 (unless (memq name char-db-ignored-attributes)
913 (if (find-charset name)
917 (dolist (name (char-attribute-list))
918 (unless (memq name char-db-ignored-attributes)
919 (if (find-charset name)
923 #'char-attribute-name<)))
925 (when (memq '<-subsumptive attributes)
926 (when (or readable (not for-sub-node))
927 (when (setq value (get-char-attribute char '<-subsumptive))
928 (char-db-insert-relation-feature char '<-subsumptive value
931 (setq attributes (delq '<-subsumptive attributes)))
932 (when (and (memq '<-denotational attributes)
933 (setq value (get-char-attribute char '<-denotational)))
934 (char-db-insert-relation-feature char '<-denotational value
937 (setq attributes (delq '<-denotational attributes)))
938 (when (and (memq '<-denotational@component attributes)
939 (setq value (get-char-attribute char '<-denotational@component)))
940 (char-db-insert-relation-feature char '<-denotational@component value
943 (setq attributes (delq '<-denotational@component attributes)))
944 (when (and (memq 'name attributes)
945 (setq value (get-char-attribute char 'name)))
947 (if (> (+ (current-column) (length value)) 48)
950 value line-breaking))
951 (setq attributes (delq 'name attributes))
953 (when (and (memq 'name* attributes)
954 (setq value (get-char-attribute char 'name*)))
956 (if (> (+ (current-column) (length value)) 48)
959 value line-breaking))
960 (setq attributes (delq 'name* attributes))
962 (when (and (memq 'script attributes)
963 (setq value (get-char-attribute char 'script)))
964 (insert (format "(script\t\t%s)%s"
965 (mapconcat (function prin1-to-string)
968 (setq attributes (delq 'script attributes))
970 (dolist (name '(=>ucs =>ucs*))
971 (when (and (memq name attributes)
972 (setq value (get-char-attribute char name)))
973 (insert (format "(%-18s . #x%04X)\t; %c%s"
974 name value (decode-char '=ucs value)
976 (setq attributes (delq name attributes))))
977 (dolist (name '(=>ucs@gb =>ucs@big5))
978 (when (and (memq name attributes)
979 (setq value (get-char-attribute char name)))
980 (insert (format "(%-18s . #x%04X)\t; %c%s"
985 (symbol-name name) 2)))
988 (setq attributes (delq name attributes))
990 ;; (dolist (name '(=>daikanwa))
991 ;; (when (and (memq name attributes)
992 ;; (setq value (get-char-attribute char name)))
994 ;; (if (integerp value)
995 ;; (format "(%-18s . %05d)\t; %c%s"
996 ;; name value (decode-char '=daikanwa value)
998 ;; (format "(%-18s %s)\t; %c%s"
1000 ;; (mapconcat (function prin1-to-string)
1002 ;; (char-representative-of-daikanwa char)
1004 ;; (setq attributes (delq name attributes))))
1005 (when (and (memq 'general-category attributes)
1006 (setq value (get-char-attribute char 'general-category)))
1008 "(general-category\t%s) ; %s%s"
1009 (mapconcat (lambda (cell)
1012 (cond ((rassoc value unidata-normative-category-alist)
1013 "Normative Category")
1014 ((rassoc value unidata-informative-category-alist)
1015 "Informative Category")
1017 "Unknown Category"))
1019 (setq attributes (delq 'general-category attributes))
1021 (when (and (memq 'bidi-category attributes)
1022 (setq value (get-char-attribute char 'bidi-category)))
1023 (insert (format "(bidi-category\t. %S)%s"
1026 (setq attributes (delq 'bidi-category attributes))
1028 (unless (or (not (memq 'mirrored attributes))
1029 (eq (setq value (get-char-attribute char 'mirrored 'empty))
1031 (insert (format "(mirrored\t\t. %S)%s"
1034 (setq attributes (delq 'mirrored attributes))
1037 ((and (memq 'decimal-digit-value attributes)
1038 (setq value (get-char-attribute char 'decimal-digit-value)))
1039 (insert (format "(decimal-digit-value . %S)%s"
1042 (setq attributes (delq 'decimal-digit-value attributes))
1043 (when (and (memq 'digit-value attributes)
1044 (setq value (get-char-attribute char 'digit-value)))
1045 (insert (format "(digit-value\t . %S)%s"
1048 (setq attributes (delq 'digit-value attributes))
1050 (when (and (memq 'numeric-value attributes)
1051 (setq value (get-char-attribute char 'numeric-value)))
1052 (insert (format "(numeric-value\t . %S)%s"
1055 (setq attributes (delq 'numeric-value attributes))
1059 (when (and (memq 'digit-value attributes)
1060 (setq value (get-char-attribute char 'digit-value)))
1061 (insert (format "(digit-value\t. %S)%s"
1064 (setq attributes (delq 'digit-value attributes))
1066 (when (and (memq 'numeric-value attributes)
1067 (setq value (get-char-attribute char 'numeric-value)))
1068 (insert (format "(numeric-value\t. %S)%s"
1071 (setq attributes (delq 'numeric-value attributes))
1073 (when (and (memq 'iso-10646-comment attributes)
1074 (setq value (get-char-attribute char 'iso-10646-comment)))
1075 (insert (format "(iso-10646-comment\t. %S)%s"
1078 (setq attributes (delq 'iso-10646-comment attributes))
1080 (when (and (memq 'morohashi-daikanwa attributes)
1081 (setq value (get-char-attribute char 'morohashi-daikanwa)))
1082 (insert (format "(morohashi-daikanwa\t%s)%s"
1083 (mapconcat (function prin1-to-string) value " ")
1085 (setq attributes (delq 'morohashi-daikanwa attributes))
1089 (when (and (memq 'ideographic-radical attributes)
1090 (setq value (get-char-attribute char 'ideographic-radical)))
1091 (setq radical value)
1092 (insert (format "(ideographic-radical . %S)\t; %c%s"
1094 (ideographic-radical radical)
1096 (setq attributes (delq 'ideographic-radical attributes))
1098 (when (and (memq 'shuowen-radical attributes)
1099 (setq value (get-char-attribute char 'shuowen-radical)))
1100 (insert (format "(shuowen-radical\t. %S)\t; %c%s"
1102 (shuowen-radical value)
1104 (setq attributes (delq 'shuowen-radical attributes))
1109 char-db-feature-domains
1111 (dolist (feature (char-attribute-list))
1112 (setq feature (symbol-name feature))
1114 "\\(radical\\|strokes\\)@\\([^@*]+\\)\\(\\*\\|$\\)"
1116 (setq domain (intern (match-string 2 feature)))
1117 (unless (memq domain dest)
1118 (setq dest (cons domain dest)))))
1119 (sort dest #'string<))))
1120 (setq key (intern (format "%s@%s" 'ideographic-radical domain)))
1121 (when (and (memq key attributes)
1122 (setq value (get-char-attribute char key)))
1123 (setq radical value)
1124 (insert (format "(%s . %S)\t; %c%s"
1127 (ideographic-radical radical)
1129 (setq attributes (delq key attributes))
1131 (setq key (intern (format "%s@%s" 'ideographic-strokes domain)))
1132 (when (and (memq key attributes)
1133 (setq value (get-char-attribute char key)))
1134 (setq strokes value)
1135 (insert (format "(%s . %S)%s"
1139 (setq attributes (delq key attributes))
1141 (setq key (intern (format "%s@%s" 'total-strokes domain)))
1142 (when (and (memq key attributes)
1143 (setq value (get-char-attribute char key)))
1144 (insert (format "(%s . %S)%s"
1148 (setq attributes (delq key attributes))
1150 (dolist (feature '(ideographic-radical
1153 (setq key (intern (format "%s@%s*sources" feature domain)))
1154 (when (and (memq key attributes)
1155 (setq value (get-char-attribute char key)))
1156 (insert (format "(%s%s" key line-breaking))
1157 (dolist (cell value)
1158 (insert (format " %s" cell)))
1160 (insert line-breaking)
1161 (setq attributes (delq key attributes))
1164 (when (and (memq 'ideographic-strokes attributes)
1165 (setq value (get-char-attribute char 'ideographic-strokes)))
1166 (setq strokes value)
1167 (insert (format "(ideographic-strokes . %S)%s"
1170 (setq attributes (delq 'ideographic-strokes attributes))
1172 (when (and (memq 'kangxi-radical attributes)
1173 (setq value (get-char-attribute char 'kangxi-radical)))
1174 (unless (eq value radical)
1175 (insert (format "(kangxi-radical\t . %S)\t; %c%s"
1177 (ideographic-radical value)
1180 (setq radical value)))
1181 (setq attributes (delq 'kangxi-radical attributes))
1183 (when (and (memq 'kangxi-strokes attributes)
1184 (setq value (get-char-attribute char 'kangxi-strokes)))
1185 (unless (eq value strokes)
1186 (insert (format "(kangxi-strokes\t . %S)%s"
1190 (setq strokes value)))
1191 (setq attributes (delq 'kangxi-strokes attributes))
1193 ;; (when (and (memq 'japanese-radical attributes)
1194 ;; (setq value (get-char-attribute char 'japanese-radical)))
1195 ;; (unless (eq value radical)
1196 ;; (insert (format "(japanese-radical\t . %S)\t; %c%s"
1198 ;; (ideographic-radical value)
1201 ;; (setq radical value)))
1202 ;; (setq attributes (delq 'japanese-radical attributes))
1204 (when (and (memq 'japanese-strokes attributes)
1205 (setq value (get-char-attribute char 'japanese-strokes)))
1206 (unless (eq value strokes)
1207 (insert (format "(japanese-strokes\t . %S)%s"
1211 (setq strokes value)))
1212 (setq attributes (delq 'japanese-strokes attributes))
1214 (when (and (memq 'cns-radical attributes)
1215 (setq value (get-char-attribute char 'cns-radical)))
1216 (insert (format "(cns-radical\t . %S)\t; %c%s"
1218 (ideographic-radical value)
1220 (setq attributes (delq 'cns-radical attributes))
1222 (when (and (memq 'cns-strokes attributes)
1223 (setq value (get-char-attribute char 'cns-strokes)))
1224 (unless (eq value strokes)
1225 (insert (format "(cns-strokes\t . %S)%s"
1229 (setq strokes value)))
1230 (setq attributes (delq 'cns-strokes attributes))
1232 ;; (when (and (memq 'shinjigen-1-radical attributes)
1233 ;; (setq value (get-char-attribute char 'shinjigen-1-radical)))
1234 ;; (unless (eq value radical)
1235 ;; (insert (format "(shinjigen-1-radical . %S)\t; %c%s"
1237 ;; (ideographic-radical value)
1240 ;; (setq radical value)))
1241 ;; (setq attributes (delq 'shinjigen-1-radical attributes))
1243 ;; (when (and (memq 'ideographic- attributes)
1244 ;; (setq value (get-char-attribute char 'ideographic-)))
1245 ;; (insert "(ideographic- ")
1246 ;; (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1248 ;; (while (consp value)
1249 ;; (setq cell (car value))
1250 ;; (if (integerp cell)
1251 ;; (setq cell (decode-char '=ucs cell)))
1252 ;; (cond ((characterp cell)
1256 ;; (insert (format "%S" cell))
1257 ;; (char-db-insert-char-spec cell readable))
1258 ;; (setq separator lbs))
1262 ;; (if (consp (car cell))
1263 ;; (char-db-insert-char-spec cell readable)
1264 ;; (char-db-insert-char-reference cell readable))
1265 ;; (setq separator lbs))
1268 ;; (insert separator))
1269 ;; (insert (prin1-to-string cell))
1270 ;; (setq separator " ")))
1271 ;; (setq value (cdr value)))
1273 ;; (insert line-breaking)
1274 ;; (setq attributes (delq 'ideographic- attributes)))
1275 (when (and (memq 'total-strokes attributes)
1276 (setq value (get-char-attribute char 'total-strokes)))
1277 (insert (format "(total-strokes . %S)%s"
1280 (setq attributes (delq 'total-strokes attributes))
1282 ;; (when (and (memq '->ideograph attributes)
1283 ;; (setq value (get-char-attribute char '->ideograph)))
1284 ;; (insert (format "(->ideograph\t%s)%s"
1285 ;; (mapconcat (lambda (code)
1286 ;; (cond ((symbolp code)
1287 ;; (symbol-name code))
1289 ;; (format "#x%04X" code))
1292 ;; line-breaking code))))
1295 ;; (setq attributes (delq '->ideograph attributes))
1297 ;; (when (and (memq '->decomposition attributes)
1298 ;; (setq value (get-char-attribute char '->decomposition)))
1299 ;; (insert (format "(->decomposition\t%s)%s"
1300 ;; (mapconcat (lambda (code)
1301 ;; (cond ((symbolp code)
1302 ;; (symbol-name code))
1303 ;; ((characterp code)
1305 ;; (format "%S" code)
1310 ;; (format "#x%04X" code))
1312 ;; (format "%s%S" line-breaking code))))
1315 ;; (setq attributes (delq '->decomposition attributes))
1317 (if (equal (get-char-attribute char '->titlecase)
1318 (get-char-attribute char '->uppercase))
1319 (setq attributes (delq '->titlecase attributes)))
1320 (when (and (memq '->mojikyo attributes)
1321 (setq value (get-char-attribute char '->mojikyo)))
1322 (insert (format "(->mojikyo\t\t. %06d)\t; %c%s"
1323 value (decode-char 'mojikyo value)
1325 (setq attributes (delq '->mojikyo attributes))
1327 ;; (when (and (memq 'hanyu-dazidian-vol attributes)
1328 ;; (setq value (get-char-attribute char 'hanyu-dazidian-vol)))
1329 ;; (insert (format "(hanyu-dazidian-vol . %d)%s"
1330 ;; value line-breaking))
1331 ;; (setq attributes (delq 'hanyu-dazidian-vol attributes))
1333 ;; (when (and (memq 'hanyu-dazidian-page attributes)
1334 ;; (setq value (get-char-attribute char 'hanyu-dazidian-page)))
1335 ;; (insert (format "(hanyu-dazidian-page . %d)%s"
1336 ;; value line-breaking))
1337 ;; (setq attributes (delq 'hanyu-dazidian-page attributes))
1339 ;; (when (and (memq 'hanyu-dazidian-char attributes)
1340 ;; (setq value (get-char-attribute char 'hanyu-dazidian-char)))
1341 ;; (insert (format "(hanyu-dazidian-char . %d)%s"
1342 ;; value line-breaking))
1343 ;; (setq attributes (delq 'hanyu-dazidian-char attributes))
1346 (dolist (ignored '(composition
1347 ->denotational <-subsumptive ->ucs-unified
1348 ->ideographic-component-forms))
1349 (setq attributes (delq ignored attributes))))
1351 (setq name (car attributes))
1352 (unless (eq (setq value (get-char-attribute char name 'value-is-empty))
1354 (cond ((setq ret (find-charset name))
1355 (setq name (charset-name ret))
1356 (when (not (memq name dest-ccss))
1357 (setq dest-ccss (cons name dest-ccss))
1358 (char-db-insert-ccs-feature name value line-breaking))
1360 ((string-match "^=>ucs@" (symbol-name name))
1361 (insert (format "(%-18s . #x%04X)\t; %c%s"
1362 name value (decode-char '=ucs value)
1365 ((eq name 'jisx0208-1978/4X)
1366 (insert (format "(%-18s . #x%04X)%s"
1372 (not (eq name '->subsumptive))
1373 (not (eq name '->uppercase))
1374 (not (eq name '->lowercase))
1375 (not (eq name '->titlecase))
1376 (not (eq name '->canonical))
1377 (not (eq name '->Bopomofo))
1378 (not (eq name '->mistakable))
1379 (not (eq name '->ideographic-variants))
1380 (null (get-char-attribute
1381 char (intern (format "%s*sources" name))))
1382 (not (string-match "\\*sources$" (symbol-name name)))
1383 (null (get-char-attribute
1384 char (intern (format "%s*note" name))))
1385 (not (string-match "\\*note$" (symbol-name name)))
1386 (or (eq name '<-identical)
1387 (eq name '<-uppercase)
1388 (eq name '<-lowercase)
1389 (eq name '<-titlecase)
1390 (eq name '<-canonical)
1391 (eq name '<-ideographic-variants)
1392 ;; (eq name '<-synonyms)
1393 (string-match "^<-synonyms" (symbol-name name))
1394 (eq name '<-mistakable)
1395 (when (string-match "^->" (symbol-name name))
1397 ((string-match "^->fullwidth" (symbol-name name))
1398 (not (and (consp value)
1399 (characterp (car value))
1401 (car value) '=ucs 'defined-only)))
1406 ((or (eq name 'ideographic-structure)
1407 (eq name 'ideographic-combination)
1408 ;; (eq name 'ideographic-)
1409 (eq name '=decomposition)
1410 (char-feature-base-name= '=decomposition name)
1411 (char-feature-base-name= '=>decomposition name)
1412 ;; (string-match "^=>*decomposition\\(@[^*]+\\)?$"
1413 ;; (symbol-name name))
1414 (string-match "^\\(->\\|<-\\)[^*]*$" (symbol-name name))
1415 (string-match "^\\(->\\|<-\\)[^*]*\\*sources$"
1418 (char-db-insert-relation-feature char name value
1421 ;; ((memq name '(ideograph=
1422 ;; original-ideograph-of
1423 ;; ancient-ideograph-of
1424 ;; vulgar-ideograph-of
1425 ;; wrong-ideograph-of
1426 ;; ;; simplified-ideograph-of
1427 ;; ideographic-variants
1428 ;; ;; ideographic-different-form-of
1430 ;; (insert (format "(%-18s%s " name line-breaking))
1431 ;; (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1433 ;; (while (consp value)
1434 ;; (setq cell (car value))
1435 ;; (if (and (consp cell)
1436 ;; (consp (car cell)))
1440 ;; (char-db-insert-alist cell readable)
1441 ;; (setq separator lbs))
1443 ;; (insert separator))
1444 ;; (insert (prin1-to-string cell))
1445 ;; (setq separator " "))
1446 ;; (setq value (cdr value)))
1448 ;; (insert line-breaking))
1450 (insert (format "(%-18s " name))
1451 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1453 (while (consp value)
1454 (setq cell (car value))
1455 (if (and (consp cell)
1457 (setq ret (condition-case nil
1465 (setq key (car (car rest)))
1466 (if (find-charset key)
1467 (setq cal (cons key cal))
1468 (setq al (cons key al)))
1469 (setq rest (cdr rest)))
1472 (insert-char-attributes ret
1476 (setq separator lbs))
1477 (setq ret (prin1-to-string cell))
1479 (if (< (+ (current-column)
1486 (setq separator " "))
1487 (setq value (cdr value)))
1489 (insert line-breaking))
1491 (insert (format "(%-18s" name))
1492 (setq ret (prin1-to-string value))
1493 (unless (< (+ (current-column)
1497 (insert line-breaking))
1498 (insert " . " ret ")" line-breaking)
1499 ;; (insert (format "(%-18s . %S)%s"
1504 (setq attributes (cdr attributes)))
1507 (defun insert-char-data (char &optional readable
1510 (narrow-to-region (point)(point))
1511 (insert "(define-char
1513 (insert-char-attributes char readable attributes)
1515 (goto-char (point-min))
1516 (while (re-search-forward "[ \t]+$" nil t)
1519 (goto-char (point-min))
1520 (while (re-search-forward "[ \t][ \t][ \t]*" nil t)
1521 (let ((column (current-column))
1522 (indent-tabs-mode t))
1523 (delete-region (match-beginning 0) (point))
1524 (indent-to column)))
1525 (goto-char (point-max))
1526 ;; (tabify (point-min)(point-max))
1529 (defun insert-char-data-with-variant (char &optional printable
1531 script excluded-script)
1532 (insert-char-data char printable)
1533 (let ((variants (char-variants char))
1536 (setq variants (sort variants #'<))
1537 (setq rest variants)
1538 (setq variants (cons char variants))
1540 (setq variant (car rest))
1541 (unless (get-char-attribute variant '<-subsumptive)
1542 (if (and (or (null script)
1543 (null (setq vs (get-char-attribute variant 'script)))
1545 (or (null excluded-script)
1546 (null (setq vs (get-char-attribute variant 'script)))
1547 (not (memq excluded-script vs))))
1548 (unless (and no-ucs-unified (get-char-attribute variant '=ucs))
1549 (insert-char-data variant printable)
1550 (if (setq ret (char-variants variant))
1552 (or (memq (car ret) variants)
1553 ;; (get-char-attribute (car ret) '<-subsumptive)
1554 (setq rest (nconc rest (list (car ret)))))
1555 (setq ret (cdr ret)))))))
1556 (setq rest (cdr rest)))))
1558 (defun insert-char-range-data (min max &optional script excluded-script)
1561 (while (<= code max)
1562 (setq char (decode-char '=ucs code))
1563 (if (encode-char char '=ucs 'defined-only)
1564 (insert-char-data-with-variant char nil 'no-ucs-unified
1565 script excluded-script))
1566 (setq code (1+ code)))))
1568 (defun write-char-range-data-to-file (min max file
1569 &optional script excluded-script)
1570 (let ((coding-system-for-write char-db-file-coding-system))
1572 (insert (format ";; -*- coding: %s -*-\n"
1573 char-db-file-coding-system))
1574 (insert-char-range-data min max script excluded-script)
1575 (write-region (point-min)(point-max) file))))
1577 (defvar what-character-original-window-configuration)
1580 (defun what-char-definition (char)
1581 (interactive (list (char-after)))
1582 (let ((buf (get-buffer-create "*Character Description*"))
1583 (the-buf (current-buffer))
1584 (win-conf (current-window-configuration)))
1586 (make-local-variable 'what-character-original-window-configuration)
1587 (setq what-character-original-window-configuration win-conf)
1588 (setq buffer-read-only nil)
1592 (insert-char-data-with-variant char 'printable)
1593 (unless (char-attribute-alist char)
1594 (insert (format ";; = %c\n"
1595 (let* ((rest (split-char char))
1599 (setq code (logior (lsh code 8)
1601 (decode-char ccs code)))))
1602 ;; (char-db-update-comment)
1603 (set-buffer-modified-p nil)
1604 (view-mode the-buf (lambda (buf)
1605 (set-window-configuration
1606 what-character-original-window-configuration)
1608 (goto-char (point-min)))
1610 (set-window-configuration
1611 what-character-original-window-configuration)
1612 (signal (car err) (cdr err)))))))
1618 (provide 'char-db-util)
1620 ;;; char-db-util.el ends here