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,2019 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
217 ;; =>>>adobe-japan1-0
218 ;; =>>>adobe-japan1-1
219 ;; =>>>adobe-japan1-2
220 ;; =>>>adobe-japan1-3
221 ;; =>>>adobe-japan1-4
222 ;; =>>>adobe-japan1-5
223 ;; =>>>adobe-japan1-6
227 ;; =>>>hanyo-denshi/ja
228 ;; =>>>hanyo-denshi/jb
229 ;; =>>>hanyo-denshi/jc
230 ;; =>>>hanyo-denshi/ft
231 ;; =>>>hanyo-denshi/ib
232 ;; =>>>hanyo-denshi/hg
233 ;; =>>>hanyo-denshi/jt
234 ;; =>>>hanyo-denshi/ks
275 ;; =>ucs@hanyo-denshi
376 =>big5-cdp-itaiji-001
381 =>ucs@iwds-1/normalized
382 =>ucs-itaiji-001@iwds-1
392 ;;; @ char-db formatters
395 (defun char-db-make-char-spec (char)
397 (cond ((characterp char)
398 (cond ((and (setq ret (encode-char char '=ucs 'defined-only))
399 (not (and (<= #xE000 ret)(<= ret #xF8FF))))
400 (setq char-spec (list (cons '=ucs ret)))
401 (cond ((setq ret (get-char-attribute char 'name))
402 (setq char-spec (cons (cons 'name ret) char-spec))
404 ((setq ret (get-char-attribute char 'name*))
405 (setq char-spec (cons (cons 'name* ret) char-spec))
408 ((encode-char char '=mj 'defined-only)
410 (dolist (ccs (charset-list))
411 (if (and (or (eq ccs '=mj)
412 ;; (eq (charset-property ccs 'iso-ir) 177)
413 (string-match "=ucs@" (symbol-name ccs))
415 (setq ccs (charset-name ccs))
416 (null (assq ccs char-spec))
417 (setq ret (encode-char char ccs 'defined-only)))
418 (setq char-spec (cons (cons ccs ret) char-spec))))
420 ((encode-char char '==mj 'defined-only)
422 (dolist (ccs (charset-list))
423 (if (and (or (eq ccs '==mj)
424 ;; (eq (charset-property ccs 'iso-ir) 177)
425 (string-match "=ucs@" (symbol-name ccs))
427 (setq ccs (charset-name ccs))
428 (null (assq ccs char-spec))
429 (setq ret (encode-char char ccs 'defined-only)))
430 (setq char-spec (cons (cons ccs ret) char-spec))))
432 ((encode-char char '=adobe-japan1 'defined-only)
434 (dolist (ccs (charset-list))
435 (if (and (or (memq ccs
444 ;; (eq (charset-property ccs 'iso-ir) 177)
445 (string-match "=ucs@" (symbol-name ccs))
447 (setq ccs (charset-name ccs))
448 (null (assq ccs char-spec))
449 (setq ret (encode-char char ccs 'defined-only)))
450 (setq char-spec (cons (cons ccs ret) char-spec))))
452 ((encode-char char '==adobe-japan1 'defined-only)
454 (dolist (ccs (charset-list))
455 (if (and (or (memq ccs
464 ;; (eq (charset-property ccs 'iso-ir) 177)
465 (string-match "=ucs@" (symbol-name ccs))
467 (setq ccs (charset-name ccs))
468 (null (assq ccs char-spec))
469 (setq ret (encode-char char ccs 'defined-only)))
470 (setq char-spec (cons (cons ccs ret) char-spec))))
474 (let ((rest char-db-coded-charset-priority-list)
477 (setq ccs (charset-name
478 (find-charset (car rest))))
480 (encode-char char ccs
482 (throw 'tag (cons ccs ret)))
483 (setq rest (cdr rest))))))
484 (setq char-spec (list ret))
485 (dolist (ccs (delq (car ret) (charset-list)))
486 (if (and (or (charset-iso-final-char ccs)
493 (and (eq (charset-property ccs 'iso-ir) 177)
494 (not (eq (charset-name ccs) '=ucs@big5)))
495 ;; (string-match "=ucs@" (symbol-name ccs))
497 (setq ccs (charset-name ccs))
498 (null (assq ccs char-spec))
499 (setq ret (encode-char char ccs 'defined-only)))
500 (setq char-spec (cons (cons ccs ret) char-spec))))
502 (setq char-spec (split-char char)))
503 (cond ((setq ret (get-char-attribute char 'name))
504 (setq char-spec (cons (cons 'name ret) char-spec))
506 ((setq ret (get-char-attribute char 'name*))
507 (setq char-spec (cons (cons 'name* ret) char-spec))
510 ((setq ret (get-char-attribute
511 char 'ideographic-combination))
513 (cons (cons 'ideographic-combination ret)
520 (defun char-db-insert-char-spec (char &optional readable column
523 (setq column (current-column)))
524 (let (char-spec temp-char)
525 (setq char-spec (char-db-make-char-spec char))
526 (unless (or (characterp char) ; char
528 (setq char (find-char char-spec))
530 ;; define temporary character
531 ;; Current implementation is dirty.
532 (setq temp-char (define-char (cons '(ideograph-daikanwa . 0)
534 (remove-char-attribute temp-char 'ideograph-daikanwa)
535 (setq char temp-char))
536 (insert-char-attributes char
538 (union (mapcar #'car char-spec)
542 ;; undefine temporary character
543 ;; Current implementation is dirty.
544 (setq char-spec (char-attribute-alist temp-char))
546 (remove-char-attribute temp-char (car (car char-spec)))
547 (setq char-spec (cdr char-spec))))))
549 (defun char-db-insert-alist (alist &optional readable column)
551 (setq column (current-column)))
553 (concat "\n" (make-string (1+ column) ?\ )))
557 lbs cell rest separator)
560 (setq name (car (car alist))
561 value (cdr (car alist)))
562 (cond ((eq name 'char)
564 (if (setq ret (condition-case nil
572 (setq key (car (car value)))
573 ;; (if (find-charset key)
574 ;; (setq cal (cons key cal))
575 (setq al (cons key al))
577 (setq value (cdr value)))
578 (insert-char-attributes ret
582 (insert (prin1-to-string value)))
584 (insert line-breaking))
586 (insert (format "(%-18s " name))
587 (setq lbs (concat "\n" (make-string (current-column) ?\ )))
589 (setq cell (car value))
590 (if (and (consp cell)
592 (setq ret (condition-case nil
602 (setq key (car (car rest)))
603 ;; (if (find-charset key)
604 ;; (setq cal (cons key cal))
605 (setq al (cons key al))
607 (setq rest (cdr rest)))
610 (insert-char-attributes ret
614 (setq separator lbs))
617 (insert (prin1-to-string cell))
618 (setq separator " "))
619 (setq value (cdr value)))
621 (insert line-breaking))
623 (insert (format "(%-18s . %S)%s"
626 (setq alist (cdr alist))))
629 (defun char-db-insert-char-reference (plist &optional readable column)
631 (setq column (current-column)))
633 (concat "\n" (make-string (1+ column) ?\ )))
638 (setq name (pop plist))
639 (setq value (pop plist))
640 (cond ((eq name :char)
643 (cond ((numberp value)
644 (setq value (decode-char '=ucs value)))
646 ;; (setq value (or (find-char value)
649 (char-db-insert-char-spec value readable)
650 (insert line-breaking)
653 (insert (format "%s%s\t%d ; %c%s"
656 (ideographic-radical value)
660 (insert (format "%s%s\t%S" separator name value))
661 (setq separator line-breaking)))
665 (defun char-db-decode-isolated-char (ccs code-point)
668 (cond ((eq ccs 'arabic-iso8859-6)
669 (decode-char ccs code-point))
671 ;; (decode-builtin-char '==gt code-point))
672 ((and (memq ccs '(=gt-pj-1
683 (setq ret (decode-char ccs code-point))
684 (setq ret (encode-char ret '=gt 'defined-only)))
685 (decode-builtin-char '=gt ret))
687 (decode-builtin-char ccs code-point))))
689 (or (decode-char ccs code-point)
690 (define-char (list (cons ccs code-point)))))
691 ((and (<= 0 (char-int ret))
692 (<= (char-int ret) #x1F))
693 (decode-char '=ucs (+ #x2400 (char-int ret))))
694 ((= (char-int ret) #x7F)
698 (defvar char-db-convert-obsolete-format t)
700 (defun char-db-insert-ccs-feature (name value line-breaking)
706 ((memq name '(=>iwds-1
709 =shinjigen@1ed ==shinjigen@1ed
710 =shinjigen@rev ==shinjigen@rev
711 =shinjigen/+p@rev ==shinjigen/+p@rev
712 ===daikanwa/ho ==daikanwa/ho
713 =daikanwa/ho =>>daikanwa/ho =>daikanwa/ho))
714 "(%-18s . %04d)\t; %c")
715 ((eq name '=shinjigen@1ed/24pr)
716 "(%-18s . %04d)\t; %c")
720 ==daikanwa =daikanwa =>>daikanwa =>daikanwa
721 =daikanwa@rev1 =daikanwa@rev2
722 =daikanwa/+p ==daikanwa/+p ===daikanwa/+p
724 =daikanwa/+2p =>>daikanwa/+2p
729 =adobe-japan1-0 ==adobe-japan1-0 ===adobe-japan1-0
730 =adobe-japan1-1 ==adobe-japan1-1 ===adobe-japan1-1
731 =adobe-japan1-2 ==adobe-japan1-2 ===adobe-japan1-2
732 =adobe-japan1-3 ==adobe-japan1-3 ===adobe-japan1-3
733 =adobe-japan1-4 ==adobe-japan1-4 ===adobe-japan1-4
734 =adobe-japan1-5 ==adobe-japan1-5 ===adobe-japan1-5
735 =adobe-japan1-6 ==adobe-japan1-6 ===adobe-japan1-6
736 =>>adobe-japan1-0 =+>adobe-japan1-0
737 =>>adobe-japan1-1 =+>adobe-japan1-1
738 =>>adobe-japan1-2 =+>adobe-japan1-2
739 =>>adobe-japan1-3 =+>adobe-japan1-3
740 =>>adobe-japan1-4 =+>adobe-japan1-4
741 =>>adobe-japan1-5 =+>adobe-japan1-5
742 =>>adobe-japan1-6 =+>adobe-japan1-6
743 =>cbeta =cbeta =>>cbeta ==cbeta ===cbeta
744 =zinbun-oracle =>zinbun-oracle
745 =daijiten ==daijiten ===daijiten ==>daijiten
746 ===hng-jou ===hng-keg ===hng-dng ===hng-mam
747 ===hng-drt ===hng-kgk ===hng-myz ===hng-kda
748 ===hng-khi ===hng-khm ===hng-fhs ===hng-hok
749 ===hng-kyd ===hng-sok
750 ===hng-yhk ===hng-kak ===hng-kar ===hng-kae
751 ===hng-sys ===hng-tsu ===hng-tzj
752 ===hng-hos ===hng-kkh ===hng-nak ===hng-jhk
753 ===hng-hod ===hng-gok ===hng-ink ===hng-nto
754 ===hng-nkm ===hng-k24 ===hng-ini ===hng-nkk
755 ===hng-kcc ===hng-kcj ===hng-kbk ===hng-sik
756 ===hng-skk ===hng-kyu ===hng-ksk ===hng-wan
757 ===hng-okd ===hng-wad ===hng-kmi
758 ===hng-zkd ===hng-doh ===hng-jyu ===hng-tzs
759 ===hng-sai ===hng-kad ===hng-kss
760 ===hng-kyo ===hng-ykk ===hng-saa
761 ===hng-sab ===hng-wks ===hng-wke ===hng-smk
762 ===hng-sgs ===hng-sts
763 =shuowen-jiguge ===shuowen-jiguge4 ===shuowen-jiguge5))
764 ;; (string-match "^=adobe-" (symbol-name name))
766 "(%-18s . %05d)\t; %c")
767 ((memq name '(=hanyo-denshi/ks
768 ==hanyo-denshi/ks ===hanyo-denshi/ks
771 =mj ==mj ===mj =>>mj =>mj
773 "(%-18s . %06d)\t; %c")
774 ((memq name '(=hanyo-denshi/tk ==hanyo-denshi/tk))
775 "(%-18s . %08d)\t; %c")
776 ((>= (charset-dimension name) 2)
777 "(%-18s . #x%04X)\t; %c")
779 "(%-18s . #x%02X)\t; %c"))
781 (if (= (charset-iso-graphic-plane name) 1)
783 (cond ((= (charset-dimension name) 1)
785 ((= (charset-dimension name) 2)
787 ((= (charset-dimension name) 3)
791 (char-db-decode-isolated-char name value)))
792 (if (and (= (charset-chars name) 94)
793 (= (charset-dimension name) 2))
794 (insert (format " [%02d-%02d]"
795 (- (lsh value -8) 32)
796 (- (logand value 255) 32))))
799 (insert (format "(%-18s . %s)" name value))
801 (insert line-breaking))
803 (defun char-db-insert-relation-feature (char name value line-breaking
805 (insert (format "(%-18s%s " name line-breaking))
806 (let ((lbs (concat "\n" (make-string (current-column) ?\ )))
807 separator cell sources required-features
810 (setq cell (car value))
812 (setq cell (decode-char '=ucs cell)))
814 ((eq name '->subsumptive)
815 (when (or (not (some (lambda (atr)
816 (get-char-attribute cell atr))
817 char-db-ignored-attributes))
819 (encode-char cell ccs 'defined-only))
823 (let ((char-db-ignored-attributes
825 char-db-ignored-attributes)))
826 (insert-char-attributes cell readable nil nil 'for-sub-node))
827 (setq separator lbs))
832 char (intern (format "%s*sources" name))))
833 (setq required-features nil)
834 (dolist (source sources)
838 shinjigen shinjigen@1ed shinjigen@rev))
839 (setq required-features
840 (union required-features
852 =shinjigen/+p@rev))))
854 (setq required-features
855 (union required-features
860 ((find-charset (setq ret (intern (format "=%s" source))))
861 (setq required-features
862 (cons ret required-features)))
863 (t (setq required-features
864 (cons source required-features)))))
865 (cond ((string-match "@JP" (symbol-name name))
866 (setq required-features
867 (union required-features
875 ((string-match "@CN" (symbol-name name))
876 (setq required-features
877 (union required-features
884 (insert (format "%S" cell))
885 (char-db-insert-char-spec cell readable
888 (setq separator lbs))
892 (if (consp (car cell))
893 (char-db-insert-char-spec cell readable)
894 (char-db-insert-char-reference cell readable))
895 (setq separator lbs))
899 (insert (prin1-to-string cell))
900 (setq separator " ")))
901 (setq value (cdr value)))
903 (insert line-breaking)))
905 (defun insert-char-attributes (char &optional readable attributes column
908 (setq column (current-column)))
909 (let (name value ; has-long-ccs-name
913 (concat "\n" (make-string (1+ column) ?\ )))
914 lbs cell separator ret
916 dest-ccss ; sources required-features
921 (if (consp attributes)
923 (dolist (name attributes)
924 (unless (memq name char-db-ignored-attributes)
925 (if (find-charset name)
929 (dolist (name (char-attribute-list))
930 (unless (memq name char-db-ignored-attributes)
931 (if (find-charset name)
935 #'char-attribute-name<)))
937 (when (memq '<-subsumptive attributes)
938 (when (or readable (not for-sub-node))
939 (when (setq value (get-char-attribute char '<-subsumptive))
940 (char-db-insert-relation-feature char '<-subsumptive value
943 (setq attributes (delq '<-subsumptive attributes)))
944 (when (and (memq '<-denotational attributes)
945 (setq value (get-char-attribute char '<-denotational)))
946 (char-db-insert-relation-feature char '<-denotational value
949 (setq attributes (delq '<-denotational attributes)))
950 (when (and (memq '<-denotational@component attributes)
951 (setq value (get-char-attribute char '<-denotational@component)))
952 (char-db-insert-relation-feature char '<-denotational@component value
955 (setq attributes (delq '<-denotational@component attributes)))
956 (when (and (memq '<-denotational@usage attributes)
957 (setq value (get-char-attribute char '<-denotational@usage)))
958 (char-db-insert-relation-feature char '<-denotational@usage value
961 (setq attributes (delq '<-denotational@usage attributes)))
962 (when (and (memq 'name attributes)
963 (setq value (get-char-attribute char 'name)))
965 (if (> (+ (current-column) (length value)) 48)
968 value line-breaking))
969 (setq attributes (delq 'name attributes))
971 (when (and (memq 'name* attributes)
972 (setq value (get-char-attribute char 'name*)))
974 (if (> (+ (current-column) (length value)) 48)
977 value line-breaking))
978 (setq attributes (delq 'name* attributes))
980 (when (and (memq 'script attributes)
981 (setq value (get-char-attribute char 'script)))
982 (insert (format "(script\t\t%s)%s"
983 (mapconcat (function prin1-to-string)
986 (setq attributes (delq 'script attributes))
988 (dolist (name '(=>ucs =>ucs*))
989 (when (and (memq name attributes)
990 (setq value (get-char-attribute char name)))
991 (insert (format "(%-18s . #x%04X)\t; %c%s"
992 name value (decode-char '=ucs value)
994 (setq attributes (delq name attributes))))
995 (dolist (name '(=>ucs@gb =>ucs@big5))
996 (when (and (memq name attributes)
997 (setq value (get-char-attribute char name)))
998 (insert (format "(%-18s . #x%04X)\t; %c%s"
1000 (decode-char (intern
1003 (symbol-name name) 2)))
1006 (setq attributes (delq name attributes))
1008 ;; (dolist (name '(=>daikanwa))
1009 ;; (when (and (memq name attributes)
1010 ;; (setq value (get-char-attribute char name)))
1012 ;; (if (integerp value)
1013 ;; (format "(%-18s . %05d)\t; %c%s"
1014 ;; name value (decode-char '=daikanwa value)
1016 ;; (format "(%-18s %s)\t; %c%s"
1018 ;; (mapconcat (function prin1-to-string)
1020 ;; (char-representative-of-daikanwa char)
1022 ;; (setq attributes (delq name attributes))))
1023 (when (and (memq 'general-category attributes)
1024 (setq value (get-char-attribute char 'general-category)))
1026 "(general-category\t%s) ; %s%s"
1027 (mapconcat (lambda (cell)
1030 (cond ((rassoc value unidata-normative-category-alist)
1031 "Normative Category")
1032 ((rassoc value unidata-informative-category-alist)
1033 "Informative Category")
1035 "Unknown Category"))
1037 (setq attributes (delq 'general-category attributes))
1039 (when (and (memq 'bidi-category attributes)
1040 (setq value (get-char-attribute char 'bidi-category)))
1041 (insert (format "(bidi-category\t. %S)%s"
1044 (setq attributes (delq 'bidi-category attributes))
1046 (unless (or (not (memq 'mirrored attributes))
1047 (eq (setq value (get-char-attribute char 'mirrored 'empty))
1049 (insert (format "(mirrored\t\t. %S)%s"
1052 (setq attributes (delq 'mirrored attributes))
1055 ((and (memq 'decimal-digit-value attributes)
1056 (setq value (get-char-attribute char 'decimal-digit-value)))
1057 (insert (format "(decimal-digit-value . %S)%s"
1060 (setq attributes (delq 'decimal-digit-value attributes))
1061 (when (and (memq 'digit-value attributes)
1062 (setq value (get-char-attribute char 'digit-value)))
1063 (insert (format "(digit-value\t . %S)%s"
1066 (setq attributes (delq 'digit-value attributes))
1068 (when (and (memq 'numeric-value attributes)
1069 (setq value (get-char-attribute char 'numeric-value)))
1070 (insert (format "(numeric-value\t . %S)%s"
1073 (setq attributes (delq 'numeric-value attributes))
1077 (when (and (memq 'digit-value attributes)
1078 (setq value (get-char-attribute char 'digit-value)))
1079 (insert (format "(digit-value\t. %S)%s"
1082 (setq attributes (delq 'digit-value attributes))
1084 (when (and (memq 'numeric-value attributes)
1085 (setq value (get-char-attribute char 'numeric-value)))
1086 (insert (format "(numeric-value\t. %S)%s"
1089 (setq attributes (delq 'numeric-value attributes))
1091 (when (and (memq 'iso-10646-comment attributes)
1092 (setq value (get-char-attribute char 'iso-10646-comment)))
1093 (insert (format "(iso-10646-comment\t. %S)%s"
1096 (setq attributes (delq 'iso-10646-comment attributes))
1098 (when (and (memq 'morohashi-daikanwa attributes)
1099 (setq value (get-char-attribute char 'morohashi-daikanwa)))
1100 (insert (format "(morohashi-daikanwa\t%s)%s"
1101 (mapconcat (function prin1-to-string) value " ")
1103 (setq attributes (delq 'morohashi-daikanwa attributes))
1107 (when (and (memq 'ideographic-radical attributes)
1108 (setq value (get-char-attribute char 'ideographic-radical)))
1109 (setq radical value)
1110 (insert (format "(ideographic-radical . %S)\t; %c%s"
1112 (ideographic-radical radical)
1114 (setq attributes (delq 'ideographic-radical attributes))
1116 (when (and (memq 'shuowen-radical attributes)
1117 (setq value (get-char-attribute char 'shuowen-radical)))
1118 (insert (format "(shuowen-radical\t. %S)\t; %c%s"
1120 (shuowen-radical value)
1122 (setq attributes (delq 'shuowen-radical attributes))
1127 char-db-feature-domains
1129 (dolist (feature (char-attribute-list))
1130 (setq feature (symbol-name feature))
1132 "\\(radical\\|strokes\\)@\\([^@*]+\\)\\(\\*\\|$\\)"
1134 (setq domain (intern (match-string 2 feature)))
1135 (unless (memq domain dest)
1136 (setq dest (cons domain dest)))))
1137 (sort dest #'string<))))
1138 (setq key (intern (format "%s@%s" 'ideographic-radical domain)))
1139 (when (and (memq key attributes)
1140 (setq value (get-char-attribute char key)))
1141 (setq radical value)
1142 (insert (format "(%s . %S)\t; %c%s"
1145 (ideographic-radical radical)
1147 (setq attributes (delq key attributes))
1149 (setq key (intern (format "%s@%s" 'ideographic-strokes domain)))
1150 (when (and (memq key attributes)
1151 (setq value (get-char-attribute char key)))
1152 (setq strokes value)
1153 (insert (format "(%s . %S)%s"
1157 (setq attributes (delq key attributes))
1159 (setq key (intern (format "%s@%s" 'total-strokes domain)))
1160 (when (and (memq key attributes)
1161 (setq value (get-char-attribute char key)))
1162 (insert (format "(%s . %S)%s"
1166 (setq attributes (delq key attributes))
1168 (dolist (feature '(ideographic-radical
1171 (setq key (intern (format "%s@%s*sources" feature domain)))
1172 (when (and (memq key attributes)
1173 (setq value (get-char-attribute char key)))
1174 (insert (format "(%s%s" key line-breaking))
1175 (dolist (cell value)
1176 (insert (format " %s" cell)))
1178 (insert line-breaking)
1179 (setq attributes (delq key attributes))
1182 (when (and (memq 'ideographic-strokes attributes)
1183 (setq value (get-char-attribute char 'ideographic-strokes)))
1184 (setq strokes value)
1185 (insert (format "(ideographic-strokes . %S)%s"
1188 (setq attributes (delq 'ideographic-strokes attributes))
1190 (when (and (memq 'kangxi-radical attributes)
1191 (setq value (get-char-attribute char 'kangxi-radical)))
1192 (unless (eq value radical)
1193 (insert (format "(kangxi-radical\t . %S)\t; %c%s"
1195 (ideographic-radical value)
1198 (setq radical value)))
1199 (setq attributes (delq 'kangxi-radical attributes))
1201 (when (and (memq 'kangxi-strokes attributes)
1202 (setq value (get-char-attribute char 'kangxi-strokes)))
1203 (unless (eq value strokes)
1204 (insert (format "(kangxi-strokes\t . %S)%s"
1208 (setq strokes value)))
1209 (setq attributes (delq 'kangxi-strokes attributes))
1211 ;; (when (and (memq 'japanese-radical attributes)
1212 ;; (setq value (get-char-attribute char 'japanese-radical)))
1213 ;; (unless (eq value radical)
1214 ;; (insert (format "(japanese-radical\t . %S)\t; %c%s"
1216 ;; (ideographic-radical value)
1219 ;; (setq radical value)))
1220 ;; (setq attributes (delq 'japanese-radical attributes))
1222 (when (and (memq 'japanese-strokes attributes)
1223 (setq value (get-char-attribute char 'japanese-strokes)))
1224 (unless (eq value strokes)
1225 (insert (format "(japanese-strokes\t . %S)%s"
1229 (setq strokes value)))
1230 (setq attributes (delq 'japanese-strokes attributes))
1232 (when (and (memq 'cns-radical attributes)
1233 (setq value (get-char-attribute char 'cns-radical)))
1234 (insert (format "(cns-radical\t . %S)\t; %c%s"
1236 (ideographic-radical value)
1238 (setq attributes (delq 'cns-radical attributes))
1240 (when (and (memq 'cns-strokes attributes)
1241 (setq value (get-char-attribute char 'cns-strokes)))
1242 (unless (eq value strokes)
1243 (insert (format "(cns-strokes\t . %S)%s"
1247 (setq strokes value)))
1248 (setq attributes (delq 'cns-strokes attributes))
1250 ;; (when (and (memq 'ideographic- attributes)
1251 ;; (setq value (get-char-attribute char 'ideographic-)))
1252 ;; (insert "(ideographic- ")
1253 ;; (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1255 ;; (while (consp value)
1256 ;; (setq cell (car value))
1257 ;; (if (integerp cell)
1258 ;; (setq cell (decode-char '=ucs cell)))
1259 ;; (cond ((characterp cell)
1263 ;; (insert (format "%S" cell))
1264 ;; (char-db-insert-char-spec cell readable))
1265 ;; (setq separator lbs))
1269 ;; (if (consp (car cell))
1270 ;; (char-db-insert-char-spec cell readable)
1271 ;; (char-db-insert-char-reference cell readable))
1272 ;; (setq separator lbs))
1275 ;; (insert separator))
1276 ;; (insert (prin1-to-string cell))
1277 ;; (setq separator " ")))
1278 ;; (setq value (cdr value)))
1280 ;; (insert line-breaking)
1281 ;; (setq attributes (delq 'ideographic- attributes)))
1282 (when (and (memq 'total-strokes attributes)
1283 (setq value (get-char-attribute char 'total-strokes)))
1284 (insert (format "(total-strokes . %S)%s"
1287 (setq attributes (delq 'total-strokes attributes))
1289 ;; (when (and (memq '->ideograph attributes)
1290 ;; (setq value (get-char-attribute char '->ideograph)))
1291 ;; (insert (format "(->ideograph\t%s)%s"
1292 ;; (mapconcat (lambda (code)
1293 ;; (cond ((symbolp code)
1294 ;; (symbol-name code))
1296 ;; (format "#x%04X" code))
1299 ;; line-breaking code))))
1302 ;; (setq attributes (delq '->ideograph attributes))
1304 ;; (when (and (memq '->decomposition attributes)
1305 ;; (setq value (get-char-attribute char '->decomposition)))
1306 ;; (insert (format "(->decomposition\t%s)%s"
1307 ;; (mapconcat (lambda (code)
1308 ;; (cond ((symbolp code)
1309 ;; (symbol-name code))
1310 ;; ((characterp code)
1312 ;; (format "%S" code)
1317 ;; (format "#x%04X" code))
1319 ;; (format "%s%S" line-breaking code))))
1322 ;; (setq attributes (delq '->decomposition attributes))
1324 (if (equal (get-char-attribute char '->titlecase)
1325 (get-char-attribute char '->uppercase))
1326 (setq attributes (delq '->titlecase attributes)))
1327 (when (and (memq '->mojikyo attributes)
1328 (setq value (get-char-attribute char '->mojikyo)))
1329 (insert (format "(->mojikyo\t\t. %06d)\t; %c%s"
1330 value (decode-char 'mojikyo value)
1332 (setq attributes (delq '->mojikyo attributes))
1335 (dolist (ignored '(composition
1336 ->denotational <-subsumptive ->ucs-unified
1337 ;; ->ideographic-component-forms
1339 (setq attributes (delq ignored attributes))))
1341 (setq name (car attributes))
1342 (unless (eq (setq value (get-char-attribute char name 'value-is-empty))
1344 (cond ((setq ret (find-charset name))
1345 (setq name (charset-name ret))
1346 (when (not (memq name dest-ccss))
1347 (setq dest-ccss (cons name dest-ccss))
1348 (char-db-insert-ccs-feature name value line-breaking))
1350 ((string-match "^=>ucs@" (symbol-name name))
1351 (insert (format "(%-18s . #x%04X)\t; %c%s"
1352 name value (decode-char '=ucs value)
1355 ((eq name 'jisx0208-1978/4X)
1356 (insert (format "(%-18s . #x%04X)%s"
1362 (not (eq name '->subsumptive))
1363 (not (eq name '->uppercase))
1364 (not (eq name '->lowercase))
1365 (not (eq name '->titlecase))
1366 (not (eq name '->canonical))
1367 (not (eq name '->Bopomofo))
1368 (not (eq name '->mistakable))
1369 (not (eq name '->ideographic-variants))
1370 (null (get-char-attribute
1371 char (intern (format "%s*sources" name))))
1372 (not (string-match "\\*sources$" (symbol-name name)))
1373 (null (get-char-attribute
1374 char (intern (format "%s*note" name))))
1375 (not (string-match "\\*note$" (symbol-name name)))
1376 (or (eq name '<-identical)
1377 (eq name '<-uppercase)
1378 (eq name '<-lowercase)
1379 (eq name '<-titlecase)
1380 (eq name '<-canonical)
1381 (eq name '<-ideographic-variants)
1382 ;; (eq name '<-synonyms)
1383 (string-match "^<-synonyms" (symbol-name name))
1384 (eq name '<-mistakable)
1385 (when (string-match "^->" (symbol-name name))
1387 ((string-match "^->fullwidth" (symbol-name name))
1388 (not (and (consp value)
1389 (characterp (car value))
1391 (car value) '=ucs 'defined-only)))
1396 ((or (eq name 'ideographic-structure)
1397 (eq name 'ideographic-combination)
1398 ;; (eq name 'ideographic-)
1399 (eq name '=decomposition)
1400 (char-feature-base-name= '=decomposition name)
1401 (char-feature-base-name= '=>decomposition name)
1402 ;; (string-match "^=>*decomposition\\(@[^*]+\\)?$"
1403 ;; (symbol-name name))
1404 (string-match "^\\(->\\|<-\\)[^*]*$" (symbol-name name))
1405 (string-match "^\\(->\\|<-\\)[^*]*\\*sources$"
1408 (char-db-insert-relation-feature char name value
1411 ;; ((memq name '(ideograph=
1412 ;; original-ideograph-of
1413 ;; ancient-ideograph-of
1414 ;; vulgar-ideograph-of
1415 ;; wrong-ideograph-of
1416 ;; ;; simplified-ideograph-of
1417 ;; ideographic-variants
1418 ;; ;; ideographic-different-form-of
1420 ;; (insert (format "(%-18s%s " name line-breaking))
1421 ;; (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1423 ;; (while (consp value)
1424 ;; (setq cell (car value))
1425 ;; (if (and (consp cell)
1426 ;; (consp (car cell)))
1430 ;; (char-db-insert-alist cell readable)
1431 ;; (setq separator lbs))
1433 ;; (insert separator))
1434 ;; (insert (prin1-to-string cell))
1435 ;; (setq separator " "))
1436 ;; (setq value (cdr value)))
1438 ;; (insert line-breaking))
1440 (insert (format "(%-18s " name))
1441 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1443 (while (consp value)
1444 (setq cell (car value))
1445 (if (and (consp cell)
1447 (setq ret (condition-case nil
1455 (setq key (car (car rest)))
1456 (if (find-charset key)
1457 (setq cal (cons key cal))
1458 (setq al (cons key al)))
1459 (setq rest (cdr rest)))
1462 (insert-char-attributes ret
1466 (setq separator lbs))
1467 (setq ret (prin1-to-string cell))
1469 (if (< (+ (current-column)
1476 (setq separator " "))
1477 (setq value (cdr value)))
1479 (insert line-breaking))
1481 (insert (format "(%-18s" name))
1482 (setq ret (prin1-to-string value))
1483 (unless (< (+ (current-column)
1487 (insert line-breaking))
1488 (insert " . " ret ")" line-breaking)
1489 ;; (insert (format "(%-18s . %S)%s"
1494 (setq attributes (cdr attributes)))
1497 (defun insert-char-data (char &optional readable
1500 (narrow-to-region (point)(point))
1501 (insert "(define-char
1503 (insert-char-attributes char readable attributes)
1505 (goto-char (point-min))
1506 (while (re-search-forward "[ \t]+$" nil t)
1509 (goto-char (point-min))
1510 (while (re-search-forward "[ \t][ \t][ \t]*" nil t)
1511 (let ((column (current-column))
1512 (indent-tabs-mode t))
1513 (delete-region (match-beginning 0) (point))
1514 (indent-to column)))
1515 (goto-char (point-max))
1516 ;; (tabify (point-min)(point-max))
1519 (defun insert-char-data-with-variant (char &optional printable
1521 script excluded-script)
1522 (insert-char-data char printable)
1523 (let ((variants (char-variants char))
1526 (setq variants (sort variants #'<))
1527 (setq rest variants)
1528 (setq variants (cons char variants))
1530 (setq variant (car rest))
1531 (unless (get-char-attribute variant '<-subsumptive)
1532 (if (and (or (null script)
1533 (null (setq vs (get-char-attribute variant 'script)))
1535 (or (null excluded-script)
1536 (null (setq vs (get-char-attribute variant 'script)))
1537 (not (memq excluded-script vs))))
1538 (unless (and no-ucs-unified (get-char-attribute variant '=ucs))
1539 (insert-char-data variant printable)
1540 (if (setq ret (char-variants variant))
1542 (or (memq (car ret) variants)
1543 ;; (get-char-attribute (car ret) '<-subsumptive)
1544 (setq rest (nconc rest (list (car ret)))))
1545 (setq ret (cdr ret)))))))
1546 (setq rest (cdr rest)))))
1548 (defun insert-char-range-data (min max &optional script excluded-script)
1551 (while (<= code max)
1552 (setq char (decode-char '=ucs code))
1553 (if (encode-char char '=ucs 'defined-only)
1554 (insert-char-data-with-variant char nil 'no-ucs-unified
1555 script excluded-script))
1556 (setq code (1+ code)))))
1558 (defun write-char-range-data-to-file (min max file
1559 &optional script excluded-script)
1560 (let ((coding-system-for-write char-db-file-coding-system))
1562 (insert (format ";; -*- coding: %s -*-\n"
1563 char-db-file-coding-system))
1564 (insert-char-range-data min max script excluded-script)
1565 (write-region (point-min)(point-max) file))))
1567 (defvar what-character-original-window-configuration)
1570 (defun what-char-definition (char)
1571 (interactive (list (char-after)))
1572 (let ((buf (get-buffer-create "*Character Description*"))
1573 (the-buf (current-buffer))
1574 (win-conf (current-window-configuration)))
1576 (make-local-variable 'what-character-original-window-configuration)
1577 (setq what-character-original-window-configuration win-conf)
1578 (setq buffer-read-only nil)
1582 (insert-char-data-with-variant char 'printable)
1583 (unless (char-attribute-alist char)
1584 (insert (format ";; = %c\n"
1585 (let* ((rest (split-char char))
1589 (setq code (logior (lsh code 8)
1591 (decode-char ccs code)))))
1592 ;; (char-db-update-comment)
1593 (set-buffer-modified-p nil)
1594 (view-mode the-buf (lambda (buf)
1595 (set-window-configuration
1596 what-character-original-window-configuration)
1598 (goto-char (point-min)))
1600 (set-window-configuration
1601 what-character-original-window-configuration)
1602 (signal (car err) (cdr err)))))))
1608 (provide 'char-db-util)
1610 ;;; char-db-util.el ends here