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
374 =>big5-cdp-itaiji-001
379 =>ucs-itaiji-001@iwds-1
389 ;;; @ char-db formatters
392 (defun char-db-make-char-spec (char)
394 (cond ((characterp char)
395 (cond ((and (setq ret (encode-char char '=ucs 'defined-only))
396 (not (and (<= #xE000 ret)(<= ret #xF8FF))))
397 (setq char-spec (list (cons '=ucs ret)))
398 (cond ((setq ret (get-char-attribute char 'name))
399 (setq char-spec (cons (cons 'name ret) char-spec))
401 ((setq ret (get-char-attribute char 'name*))
402 (setq char-spec (cons (cons 'name* ret) char-spec))
405 ((encode-char char '=mj 'defined-only)
407 (dolist (ccs (charset-list))
408 (if (and (or (eq ccs '=mj)
409 ;; (eq (charset-property ccs 'iso-ir) 177)
410 (string-match "=ucs@" (symbol-name ccs))
412 (setq ccs (charset-name ccs))
413 (null (assq ccs char-spec))
414 (setq ret (encode-char char ccs 'defined-only)))
415 (setq char-spec (cons (cons ccs ret) char-spec))))
417 ((encode-char char '==mj 'defined-only)
419 (dolist (ccs (charset-list))
420 (if (and (or (eq ccs '==mj)
421 ;; (eq (charset-property ccs 'iso-ir) 177)
422 (string-match "=ucs@" (symbol-name ccs))
424 (setq ccs (charset-name ccs))
425 (null (assq ccs char-spec))
426 (setq ret (encode-char char ccs 'defined-only)))
427 (setq char-spec (cons (cons ccs ret) char-spec))))
429 ((encode-char char '=adobe-japan1 'defined-only)
431 (dolist (ccs (charset-list))
432 (if (and (or (memq ccs
441 ;; (eq (charset-property ccs 'iso-ir) 177)
442 (string-match "=ucs@" (symbol-name ccs))
444 (setq ccs (charset-name ccs))
445 (null (assq ccs char-spec))
446 (setq ret (encode-char char ccs 'defined-only)))
447 (setq char-spec (cons (cons ccs ret) char-spec))))
449 ((encode-char char '==adobe-japan1 'defined-only)
451 (dolist (ccs (charset-list))
452 (if (and (or (memq ccs
461 ;; (eq (charset-property ccs 'iso-ir) 177)
462 (string-match "=ucs@" (symbol-name ccs))
464 (setq ccs (charset-name ccs))
465 (null (assq ccs char-spec))
466 (setq ret (encode-char char ccs 'defined-only)))
467 (setq char-spec (cons (cons ccs ret) char-spec))))
471 (let ((rest char-db-coded-charset-priority-list)
474 (setq ccs (charset-name
475 (find-charset (car rest))))
477 (encode-char char ccs
479 (throw 'tag (cons ccs ret)))
480 (setq rest (cdr rest))))))
481 (setq char-spec (list ret))
482 (dolist (ccs (delq (car ret) (charset-list)))
483 (if (and (or (charset-iso-final-char ccs)
490 (and (eq (charset-property ccs 'iso-ir) 177)
491 (not (eq (charset-name ccs) '=ucs@big5)))
492 ;; (string-match "=ucs@" (symbol-name ccs))
494 (setq ccs (charset-name ccs))
495 (null (assq ccs char-spec))
496 (setq ret (encode-char char ccs 'defined-only)))
497 (setq char-spec (cons (cons ccs ret) char-spec))))
499 (setq char-spec (split-char char)))
500 (cond ((setq ret (get-char-attribute char 'name))
501 (setq char-spec (cons (cons 'name ret) char-spec))
503 ((setq ret (get-char-attribute char 'name*))
504 (setq char-spec (cons (cons 'name* ret) char-spec))
507 ((setq ret (get-char-attribute
508 char 'ideographic-combination))
510 (cons (cons 'ideographic-combination ret)
517 (defun char-db-insert-char-spec (char &optional readable column
520 (setq column (current-column)))
521 (let (char-spec temp-char)
522 (setq char-spec (char-db-make-char-spec char))
523 (unless (or (characterp char) ; char
525 (setq char (find-char char-spec))
527 ;; define temporary character
528 ;; Current implementation is dirty.
529 (setq temp-char (define-char (cons '(ideograph-daikanwa . 0)
531 (remove-char-attribute temp-char 'ideograph-daikanwa)
532 (setq char temp-char))
533 (insert-char-attributes char
535 (union (mapcar #'car char-spec)
539 ;; undefine temporary character
540 ;; Current implementation is dirty.
541 (setq char-spec (char-attribute-alist temp-char))
543 (remove-char-attribute temp-char (car (car char-spec)))
544 (setq char-spec (cdr char-spec))))))
546 (defun char-db-insert-alist (alist &optional readable column)
548 (setq column (current-column)))
550 (concat "\n" (make-string (1+ column) ?\ )))
554 lbs cell rest separator)
557 (setq name (car (car alist))
558 value (cdr (car alist)))
559 (cond ((eq name 'char)
561 (if (setq ret (condition-case nil
569 (setq key (car (car value)))
570 ;; (if (find-charset key)
571 ;; (setq cal (cons key cal))
572 (setq al (cons key al))
574 (setq value (cdr value)))
575 (insert-char-attributes ret
579 (insert (prin1-to-string value)))
581 (insert line-breaking))
583 (insert (format "(%-18s " name))
584 (setq lbs (concat "\n" (make-string (current-column) ?\ )))
586 (setq cell (car value))
587 (if (and (consp cell)
589 (setq ret (condition-case nil
599 (setq key (car (car rest)))
600 ;; (if (find-charset key)
601 ;; (setq cal (cons key cal))
602 (setq al (cons key al))
604 (setq rest (cdr rest)))
607 (insert-char-attributes ret
611 (setq separator lbs))
614 (insert (prin1-to-string cell))
615 (setq separator " "))
616 (setq value (cdr value)))
618 (insert line-breaking))
620 (insert (format "(%-18s . %S)%s"
623 (setq alist (cdr alist))))
626 (defun char-db-insert-char-reference (plist &optional readable column)
628 (setq column (current-column)))
630 (concat "\n" (make-string (1+ column) ?\ )))
635 (setq name (pop plist))
636 (setq value (pop plist))
637 (cond ((eq name :char)
640 (cond ((numberp value)
641 (setq value (decode-char '=ucs value)))
643 ;; (setq value (or (find-char value)
646 (char-db-insert-char-spec value readable)
647 (insert line-breaking)
650 (insert (format "%s%s\t%d ; %c%s"
653 (ideographic-radical value)
657 (insert (format "%s%s\t%S" separator name value))
658 (setq separator line-breaking)))
662 (defun char-db-decode-isolated-char (ccs code-point)
665 (cond ((eq ccs 'arabic-iso8859-6)
666 (decode-char ccs code-point))
668 ;; (decode-builtin-char '==gt code-point))
669 ((and (memq ccs '(=gt-pj-1
680 (setq ret (decode-char ccs code-point))
681 (setq ret (encode-char ret '=gt 'defined-only)))
682 (decode-builtin-char '=gt ret))
684 (decode-builtin-char ccs code-point))))
686 (or (decode-char ccs code-point)
687 (define-char (list (cons ccs code-point)))))
688 ((and (<= 0 (char-int ret))
689 (<= (char-int ret) #x1F))
690 (decode-char '=ucs (+ #x2400 (char-int ret))))
691 ((= (char-int ret) #x7F)
695 (defvar char-db-convert-obsolete-format t)
697 (defun char-db-insert-ccs-feature (name value line-breaking)
703 ((memq name '(=>iwds-1
706 =shinjigen@1ed ==shinjigen@1ed
707 =shinjigen@rev ==shinjigen@rev
708 =shinjigen/+p@rev ==shinjigen/+p@rev
709 ===daikanwa/ho ==daikanwa/ho
710 =daikanwa/ho =>>daikanwa/ho =>daikanwa/ho))
711 "(%-18s . %04d)\t; %c")
712 ((eq name '=shinjigen@1ed/24pr)
713 "(%-18s . %04d)\t; %c")
717 ==daikanwa =daikanwa =>>daikanwa =>daikanwa
718 =daikanwa@rev1 =daikanwa@rev2
719 =daikanwa/+p ==daikanwa/+p ===daikanwa/+p
721 =daikanwa/+2p =>>daikanwa/+2p
726 =adobe-japan1-0 ==adobe-japan1-0 ===adobe-japan1-0
727 =adobe-japan1-1 ==adobe-japan1-1 ===adobe-japan1-1
728 =adobe-japan1-2 ==adobe-japan1-2 ===adobe-japan1-2
729 =adobe-japan1-3 ==adobe-japan1-3 ===adobe-japan1-3
730 =adobe-japan1-4 ==adobe-japan1-4 ===adobe-japan1-4
731 =adobe-japan1-5 ==adobe-japan1-5 ===adobe-japan1-5
732 =adobe-japan1-6 ==adobe-japan1-6 ===adobe-japan1-6
733 =>>adobe-japan1-0 =+>adobe-japan1-0
734 =>>adobe-japan1-1 =+>adobe-japan1-1
735 =>>adobe-japan1-2 =+>adobe-japan1-2
736 =>>adobe-japan1-3 =+>adobe-japan1-3
737 =>>adobe-japan1-4 =+>adobe-japan1-4
738 =>>adobe-japan1-5 =+>adobe-japan1-5
739 =>>adobe-japan1-6 =+>adobe-japan1-6
740 =>cbeta =cbeta =>>cbeta ==cbeta ===cbeta
741 =zinbun-oracle =>zinbun-oracle
742 =daijiten ==daijiten ===daijiten ==>daijiten
743 ===hng-jou ===hng-keg ===hng-dng ===hng-mam
744 ===hng-drt ===hng-kgk ===hng-myz ===hng-kda
745 ===hng-khi ===hng-khm ===hng-fhs ===hng-hok
746 ===hng-kyd ===hng-sok
747 ===hng-yhk ===hng-kak ===hng-kar ===hng-kae
748 ===hng-sys ===hng-tsu ===hng-tzj
749 ===hng-hos ===hng-kkh ===hng-nak ===hng-jhk
750 ===hng-hod ===hng-gok ===hng-ink ===hng-nto
751 ===hng-nkm ===hng-k24 ===hng-ini ===hng-nkk
752 ===hng-kcc ===hng-kcj ===hng-kbk ===hng-sik
753 ===hng-skk ===hng-kyu ===hng-ksk ===hng-wan
754 ===hng-okd ===hng-wad ===hng-kmi
755 ===hng-zkd ===hng-doh ===hng-jyu ===hng-tzs
756 ===hng-sai ===hng-kad ===hng-kss
757 ===hng-kyo ===hng-ykk ===hng-saa
758 ===hng-sab ===hng-wks ===hng-wke ===hng-smk
759 ===hng-sgs ===hng-sts
760 =shuowen-jiguge ===shuowen-jiguge4 ===shuowen-jiguge5))
761 ;; (string-match "^=adobe-" (symbol-name name))
763 "(%-18s . %05d)\t; %c")
764 ((memq name '(=hanyo-denshi/ks
765 ==hanyo-denshi/ks ===hanyo-denshi/ks
768 =mj ==mj ===mj =>>mj =>mj
770 "(%-18s . %06d)\t; %c")
771 ((memq name '(=hanyo-denshi/tk ==hanyo-denshi/tk))
772 "(%-18s . %08d)\t; %c")
773 ((>= (charset-dimension name) 2)
774 "(%-18s . #x%04X)\t; %c")
776 "(%-18s . #x%02X)\t; %c"))
778 (if (= (charset-iso-graphic-plane name) 1)
780 (cond ((= (charset-dimension name) 1)
782 ((= (charset-dimension name) 2)
784 ((= (charset-dimension name) 3)
788 (char-db-decode-isolated-char name value)))
789 (if (and (= (charset-chars name) 94)
790 (= (charset-dimension name) 2))
791 (insert (format " [%02d-%02d]"
792 (- (lsh value -8) 32)
793 (- (logand value 255) 32))))
796 (insert (format "(%-18s . %s)" name value))
798 (insert line-breaking))
800 (defun char-db-insert-relation-feature (char name value line-breaking
802 (insert (format "(%-18s%s " name line-breaking))
803 (let ((lbs (concat "\n" (make-string (current-column) ?\ )))
804 separator cell sources required-features
807 (setq cell (car value))
809 (setq cell (decode-char '=ucs cell)))
811 ((eq name '->subsumptive)
812 (when (or (not (some (lambda (atr)
813 (get-char-attribute cell atr))
814 char-db-ignored-attributes))
816 (encode-char cell ccs 'defined-only))
820 (let ((char-db-ignored-attributes
822 char-db-ignored-attributes)))
823 (insert-char-attributes cell readable nil nil 'for-sub-node))
824 (setq separator lbs))
829 char (intern (format "%s*sources" name))))
830 (setq required-features nil)
831 (dolist (source sources)
835 shinjigen shinjigen@1ed shinjigen@rev))
836 (setq required-features
837 (union required-features
849 =shinjigen/+p@rev))))
851 (setq required-features
852 (union required-features
857 ((find-charset (setq ret (intern (format "=%s" source))))
858 (setq required-features
859 (cons ret required-features)))
860 (t (setq required-features
861 (cons source required-features)))))
862 (cond ((string-match "@JP" (symbol-name name))
863 (setq required-features
864 (union required-features
872 ((string-match "@CN" (symbol-name name))
873 (setq required-features
874 (union required-features
881 (insert (format "%S" cell))
882 (char-db-insert-char-spec cell readable
885 (setq separator lbs))
889 (if (consp (car cell))
890 (char-db-insert-char-spec cell readable)
891 (char-db-insert-char-reference cell readable))
892 (setq separator lbs))
896 (insert (prin1-to-string cell))
897 (setq separator " ")))
898 (setq value (cdr value)))
900 (insert line-breaking)))
902 (defun insert-char-attributes (char &optional readable attributes column
905 (setq column (current-column)))
906 (let (name value ; has-long-ccs-name
910 (concat "\n" (make-string (1+ column) ?\ )))
911 lbs cell separator ret
913 dest-ccss ; sources required-features
918 (if (consp attributes)
920 (dolist (name attributes)
921 (unless (memq name char-db-ignored-attributes)
922 (if (find-charset name)
926 (dolist (name (char-attribute-list))
927 (unless (memq name char-db-ignored-attributes)
928 (if (find-charset name)
932 #'char-attribute-name<)))
934 (when (memq '<-subsumptive attributes)
935 (when (or readable (not for-sub-node))
936 (when (setq value (get-char-attribute char '<-subsumptive))
937 (char-db-insert-relation-feature char '<-subsumptive value
940 (setq attributes (delq '<-subsumptive attributes)))
941 (when (and (memq '<-denotational attributes)
942 (setq value (get-char-attribute char '<-denotational)))
943 (char-db-insert-relation-feature char '<-denotational value
946 (setq attributes (delq '<-denotational attributes)))
947 (when (and (memq '<-denotational@component attributes)
948 (setq value (get-char-attribute char '<-denotational@component)))
949 (char-db-insert-relation-feature char '<-denotational@component value
952 (setq attributes (delq '<-denotational@component attributes)))
953 (when (and (memq '<-denotational@usage attributes)
954 (setq value (get-char-attribute char '<-denotational@usage)))
955 (char-db-insert-relation-feature char '<-denotational@usage value
958 (setq attributes (delq '<-denotational@usage attributes)))
959 (when (and (memq 'name attributes)
960 (setq value (get-char-attribute char 'name)))
962 (if (> (+ (current-column) (length value)) 48)
965 value line-breaking))
966 (setq attributes (delq 'name attributes))
968 (when (and (memq 'name* attributes)
969 (setq value (get-char-attribute char 'name*)))
971 (if (> (+ (current-column) (length value)) 48)
974 value line-breaking))
975 (setq attributes (delq 'name* attributes))
977 (when (and (memq 'script attributes)
978 (setq value (get-char-attribute char 'script)))
979 (insert (format "(script\t\t%s)%s"
980 (mapconcat (function prin1-to-string)
983 (setq attributes (delq 'script attributes))
985 (dolist (name '(=>ucs =>ucs*))
986 (when (and (memq name attributes)
987 (setq value (get-char-attribute char name)))
988 (insert (format "(%-18s . #x%04X)\t; %c%s"
989 name value (decode-char '=ucs value)
991 (setq attributes (delq name attributes))))
992 (dolist (name '(=>ucs@gb =>ucs@big5))
993 (when (and (memq name attributes)
994 (setq value (get-char-attribute char name)))
995 (insert (format "(%-18s . #x%04X)\t; %c%s"
1000 (symbol-name name) 2)))
1003 (setq attributes (delq name attributes))
1005 ;; (dolist (name '(=>daikanwa))
1006 ;; (when (and (memq name attributes)
1007 ;; (setq value (get-char-attribute char name)))
1009 ;; (if (integerp value)
1010 ;; (format "(%-18s . %05d)\t; %c%s"
1011 ;; name value (decode-char '=daikanwa value)
1013 ;; (format "(%-18s %s)\t; %c%s"
1015 ;; (mapconcat (function prin1-to-string)
1017 ;; (char-representative-of-daikanwa char)
1019 ;; (setq attributes (delq name attributes))))
1020 (when (and (memq 'general-category attributes)
1021 (setq value (get-char-attribute char 'general-category)))
1023 "(general-category\t%s) ; %s%s"
1024 (mapconcat (lambda (cell)
1027 (cond ((rassoc value unidata-normative-category-alist)
1028 "Normative Category")
1029 ((rassoc value unidata-informative-category-alist)
1030 "Informative Category")
1032 "Unknown Category"))
1034 (setq attributes (delq 'general-category attributes))
1036 (when (and (memq 'bidi-category attributes)
1037 (setq value (get-char-attribute char 'bidi-category)))
1038 (insert (format "(bidi-category\t. %S)%s"
1041 (setq attributes (delq 'bidi-category attributes))
1043 (unless (or (not (memq 'mirrored attributes))
1044 (eq (setq value (get-char-attribute char 'mirrored 'empty))
1046 (insert (format "(mirrored\t\t. %S)%s"
1049 (setq attributes (delq 'mirrored attributes))
1052 ((and (memq 'decimal-digit-value attributes)
1053 (setq value (get-char-attribute char 'decimal-digit-value)))
1054 (insert (format "(decimal-digit-value . %S)%s"
1057 (setq attributes (delq 'decimal-digit-value attributes))
1058 (when (and (memq 'digit-value attributes)
1059 (setq value (get-char-attribute char 'digit-value)))
1060 (insert (format "(digit-value\t . %S)%s"
1063 (setq attributes (delq 'digit-value attributes))
1065 (when (and (memq 'numeric-value attributes)
1066 (setq value (get-char-attribute char 'numeric-value)))
1067 (insert (format "(numeric-value\t . %S)%s"
1070 (setq attributes (delq 'numeric-value attributes))
1074 (when (and (memq 'digit-value attributes)
1075 (setq value (get-char-attribute char 'digit-value)))
1076 (insert (format "(digit-value\t. %S)%s"
1079 (setq attributes (delq 'digit-value attributes))
1081 (when (and (memq 'numeric-value attributes)
1082 (setq value (get-char-attribute char 'numeric-value)))
1083 (insert (format "(numeric-value\t. %S)%s"
1086 (setq attributes (delq 'numeric-value attributes))
1088 (when (and (memq 'iso-10646-comment attributes)
1089 (setq value (get-char-attribute char 'iso-10646-comment)))
1090 (insert (format "(iso-10646-comment\t. %S)%s"
1093 (setq attributes (delq 'iso-10646-comment attributes))
1095 (when (and (memq 'morohashi-daikanwa attributes)
1096 (setq value (get-char-attribute char 'morohashi-daikanwa)))
1097 (insert (format "(morohashi-daikanwa\t%s)%s"
1098 (mapconcat (function prin1-to-string) value " ")
1100 (setq attributes (delq 'morohashi-daikanwa attributes))
1104 (when (and (memq 'ideographic-radical attributes)
1105 (setq value (get-char-attribute char 'ideographic-radical)))
1106 (setq radical value)
1107 (insert (format "(ideographic-radical . %S)\t; %c%s"
1109 (ideographic-radical radical)
1111 (setq attributes (delq 'ideographic-radical attributes))
1113 (when (and (memq 'shuowen-radical attributes)
1114 (setq value (get-char-attribute char 'shuowen-radical)))
1115 (insert (format "(shuowen-radical\t. %S)\t; %c%s"
1117 (shuowen-radical value)
1119 (setq attributes (delq 'shuowen-radical attributes))
1124 char-db-feature-domains
1126 (dolist (feature (char-attribute-list))
1127 (setq feature (symbol-name feature))
1129 "\\(radical\\|strokes\\)@\\([^@*]+\\)\\(\\*\\|$\\)"
1131 (setq domain (intern (match-string 2 feature)))
1132 (unless (memq domain dest)
1133 (setq dest (cons domain dest)))))
1134 (sort dest #'string<))))
1135 (setq key (intern (format "%s@%s" 'ideographic-radical domain)))
1136 (when (and (memq key attributes)
1137 (setq value (get-char-attribute char key)))
1138 (setq radical value)
1139 (insert (format "(%s . %S)\t; %c%s"
1142 (ideographic-radical radical)
1144 (setq attributes (delq key attributes))
1146 (setq key (intern (format "%s@%s" 'ideographic-strokes domain)))
1147 (when (and (memq key attributes)
1148 (setq value (get-char-attribute char key)))
1149 (setq strokes value)
1150 (insert (format "(%s . %S)%s"
1154 (setq attributes (delq key attributes))
1156 (setq key (intern (format "%s@%s" 'total-strokes domain)))
1157 (when (and (memq key attributes)
1158 (setq value (get-char-attribute char key)))
1159 (insert (format "(%s . %S)%s"
1163 (setq attributes (delq key attributes))
1165 (dolist (feature '(ideographic-radical
1168 (setq key (intern (format "%s@%s*sources" feature domain)))
1169 (when (and (memq key attributes)
1170 (setq value (get-char-attribute char key)))
1171 (insert (format "(%s%s" key line-breaking))
1172 (dolist (cell value)
1173 (insert (format " %s" cell)))
1175 (insert line-breaking)
1176 (setq attributes (delq key attributes))
1179 (when (and (memq 'ideographic-strokes attributes)
1180 (setq value (get-char-attribute char 'ideographic-strokes)))
1181 (setq strokes value)
1182 (insert (format "(ideographic-strokes . %S)%s"
1185 (setq attributes (delq 'ideographic-strokes attributes))
1187 (when (and (memq 'kangxi-radical attributes)
1188 (setq value (get-char-attribute char 'kangxi-radical)))
1189 (unless (eq value radical)
1190 (insert (format "(kangxi-radical\t . %S)\t; %c%s"
1192 (ideographic-radical value)
1195 (setq radical value)))
1196 (setq attributes (delq 'kangxi-radical attributes))
1198 (when (and (memq 'kangxi-strokes attributes)
1199 (setq value (get-char-attribute char 'kangxi-strokes)))
1200 (unless (eq value strokes)
1201 (insert (format "(kangxi-strokes\t . %S)%s"
1205 (setq strokes value)))
1206 (setq attributes (delq 'kangxi-strokes attributes))
1208 ;; (when (and (memq 'japanese-radical attributes)
1209 ;; (setq value (get-char-attribute char 'japanese-radical)))
1210 ;; (unless (eq value radical)
1211 ;; (insert (format "(japanese-radical\t . %S)\t; %c%s"
1213 ;; (ideographic-radical value)
1216 ;; (setq radical value)))
1217 ;; (setq attributes (delq 'japanese-radical attributes))
1219 (when (and (memq 'japanese-strokes attributes)
1220 (setq value (get-char-attribute char 'japanese-strokes)))
1221 (unless (eq value strokes)
1222 (insert (format "(japanese-strokes\t . %S)%s"
1226 (setq strokes value)))
1227 (setq attributes (delq 'japanese-strokes attributes))
1229 (when (and (memq 'cns-radical attributes)
1230 (setq value (get-char-attribute char 'cns-radical)))
1231 (insert (format "(cns-radical\t . %S)\t; %c%s"
1233 (ideographic-radical value)
1235 (setq attributes (delq 'cns-radical attributes))
1237 (when (and (memq 'cns-strokes attributes)
1238 (setq value (get-char-attribute char 'cns-strokes)))
1239 (unless (eq value strokes)
1240 (insert (format "(cns-strokes\t . %S)%s"
1244 (setq strokes value)))
1245 (setq attributes (delq 'cns-strokes attributes))
1247 ;; (when (and (memq 'ideographic- attributes)
1248 ;; (setq value (get-char-attribute char 'ideographic-)))
1249 ;; (insert "(ideographic- ")
1250 ;; (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1252 ;; (while (consp value)
1253 ;; (setq cell (car value))
1254 ;; (if (integerp cell)
1255 ;; (setq cell (decode-char '=ucs cell)))
1256 ;; (cond ((characterp cell)
1260 ;; (insert (format "%S" cell))
1261 ;; (char-db-insert-char-spec cell readable))
1262 ;; (setq separator lbs))
1266 ;; (if (consp (car cell))
1267 ;; (char-db-insert-char-spec cell readable)
1268 ;; (char-db-insert-char-reference cell readable))
1269 ;; (setq separator lbs))
1272 ;; (insert separator))
1273 ;; (insert (prin1-to-string cell))
1274 ;; (setq separator " ")))
1275 ;; (setq value (cdr value)))
1277 ;; (insert line-breaking)
1278 ;; (setq attributes (delq 'ideographic- attributes)))
1279 (when (and (memq 'total-strokes attributes)
1280 (setq value (get-char-attribute char 'total-strokes)))
1281 (insert (format "(total-strokes . %S)%s"
1284 (setq attributes (delq 'total-strokes attributes))
1286 ;; (when (and (memq '->ideograph attributes)
1287 ;; (setq value (get-char-attribute char '->ideograph)))
1288 ;; (insert (format "(->ideograph\t%s)%s"
1289 ;; (mapconcat (lambda (code)
1290 ;; (cond ((symbolp code)
1291 ;; (symbol-name code))
1293 ;; (format "#x%04X" code))
1296 ;; line-breaking code))))
1299 ;; (setq attributes (delq '->ideograph attributes))
1301 ;; (when (and (memq '->decomposition attributes)
1302 ;; (setq value (get-char-attribute char '->decomposition)))
1303 ;; (insert (format "(->decomposition\t%s)%s"
1304 ;; (mapconcat (lambda (code)
1305 ;; (cond ((symbolp code)
1306 ;; (symbol-name code))
1307 ;; ((characterp code)
1309 ;; (format "%S" code)
1314 ;; (format "#x%04X" code))
1316 ;; (format "%s%S" line-breaking code))))
1319 ;; (setq attributes (delq '->decomposition attributes))
1321 (if (equal (get-char-attribute char '->titlecase)
1322 (get-char-attribute char '->uppercase))
1323 (setq attributes (delq '->titlecase attributes)))
1324 (when (and (memq '->mojikyo attributes)
1325 (setq value (get-char-attribute char '->mojikyo)))
1326 (insert (format "(->mojikyo\t\t. %06d)\t; %c%s"
1327 value (decode-char 'mojikyo value)
1329 (setq attributes (delq '->mojikyo attributes))
1332 (dolist (ignored '(composition
1333 ->denotational <-subsumptive ->ucs-unified
1334 ;; ->ideographic-component-forms
1336 (setq attributes (delq ignored attributes))))
1338 (setq name (car attributes))
1339 (unless (eq (setq value (get-char-attribute char name 'value-is-empty))
1341 (cond ((setq ret (find-charset name))
1342 (setq name (charset-name ret))
1343 (when (not (memq name dest-ccss))
1344 (setq dest-ccss (cons name dest-ccss))
1345 (char-db-insert-ccs-feature name value line-breaking))
1347 ((string-match "^=>ucs@" (symbol-name name))
1348 (insert (format "(%-18s . #x%04X)\t; %c%s"
1349 name value (decode-char '=ucs value)
1352 ((eq name 'jisx0208-1978/4X)
1353 (insert (format "(%-18s . #x%04X)%s"
1359 (not (eq name '->subsumptive))
1360 (not (eq name '->uppercase))
1361 (not (eq name '->lowercase))
1362 (not (eq name '->titlecase))
1363 (not (eq name '->canonical))
1364 (not (eq name '->Bopomofo))
1365 (not (eq name '->mistakable))
1366 (not (eq name '->ideographic-variants))
1367 (null (get-char-attribute
1368 char (intern (format "%s*sources" name))))
1369 (not (string-match "\\*sources$" (symbol-name name)))
1370 (null (get-char-attribute
1371 char (intern (format "%s*note" name))))
1372 (not (string-match "\\*note$" (symbol-name name)))
1373 (or (eq name '<-identical)
1374 (eq name '<-uppercase)
1375 (eq name '<-lowercase)
1376 (eq name '<-titlecase)
1377 (eq name '<-canonical)
1378 (eq name '<-ideographic-variants)
1379 ;; (eq name '<-synonyms)
1380 (string-match "^<-synonyms" (symbol-name name))
1381 (eq name '<-mistakable)
1382 (when (string-match "^->" (symbol-name name))
1384 ((string-match "^->fullwidth" (symbol-name name))
1385 (not (and (consp value)
1386 (characterp (car value))
1388 (car value) '=ucs 'defined-only)))
1393 ((or (eq name 'ideographic-structure)
1394 (eq name 'ideographic-combination)
1395 ;; (eq name 'ideographic-)
1396 (eq name '=decomposition)
1397 (char-feature-base-name= '=decomposition name)
1398 (char-feature-base-name= '=>decomposition name)
1399 ;; (string-match "^=>*decomposition\\(@[^*]+\\)?$"
1400 ;; (symbol-name name))
1401 (string-match "^\\(->\\|<-\\)[^*]*$" (symbol-name name))
1402 (string-match "^\\(->\\|<-\\)[^*]*\\*sources$"
1405 (char-db-insert-relation-feature char name value
1408 ;; ((memq name '(ideograph=
1409 ;; original-ideograph-of
1410 ;; ancient-ideograph-of
1411 ;; vulgar-ideograph-of
1412 ;; wrong-ideograph-of
1413 ;; ;; simplified-ideograph-of
1414 ;; ideographic-variants
1415 ;; ;; ideographic-different-form-of
1417 ;; (insert (format "(%-18s%s " name line-breaking))
1418 ;; (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1420 ;; (while (consp value)
1421 ;; (setq cell (car value))
1422 ;; (if (and (consp cell)
1423 ;; (consp (car cell)))
1427 ;; (char-db-insert-alist cell readable)
1428 ;; (setq separator lbs))
1430 ;; (insert separator))
1431 ;; (insert (prin1-to-string cell))
1432 ;; (setq separator " "))
1433 ;; (setq value (cdr value)))
1435 ;; (insert line-breaking))
1437 (insert (format "(%-18s " name))
1438 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1440 (while (consp value)
1441 (setq cell (car value))
1442 (if (and (consp cell)
1444 (setq ret (condition-case nil
1452 (setq key (car (car rest)))
1453 (if (find-charset key)
1454 (setq cal (cons key cal))
1455 (setq al (cons key al)))
1456 (setq rest (cdr rest)))
1459 (insert-char-attributes ret
1463 (setq separator lbs))
1464 (setq ret (prin1-to-string cell))
1466 (if (< (+ (current-column)
1473 (setq separator " "))
1474 (setq value (cdr value)))
1476 (insert line-breaking))
1478 (insert (format "(%-18s" name))
1479 (setq ret (prin1-to-string value))
1480 (unless (< (+ (current-column)
1484 (insert line-breaking))
1485 (insert " . " ret ")" line-breaking)
1486 ;; (insert (format "(%-18s . %S)%s"
1491 (setq attributes (cdr attributes)))
1494 (defun insert-char-data (char &optional readable
1497 (narrow-to-region (point)(point))
1498 (insert "(define-char
1500 (insert-char-attributes char readable attributes)
1502 (goto-char (point-min))
1503 (while (re-search-forward "[ \t]+$" nil t)
1506 (goto-char (point-min))
1507 (while (re-search-forward "[ \t][ \t][ \t]*" nil t)
1508 (let ((column (current-column))
1509 (indent-tabs-mode t))
1510 (delete-region (match-beginning 0) (point))
1511 (indent-to column)))
1512 (goto-char (point-max))
1513 ;; (tabify (point-min)(point-max))
1516 (defun insert-char-data-with-variant (char &optional printable
1518 script excluded-script)
1519 (insert-char-data char printable)
1520 (let ((variants (char-variants char))
1523 (setq variants (sort variants #'<))
1524 (setq rest variants)
1525 (setq variants (cons char variants))
1527 (setq variant (car rest))
1528 (unless (get-char-attribute variant '<-subsumptive)
1529 (if (and (or (null script)
1530 (null (setq vs (get-char-attribute variant 'script)))
1532 (or (null excluded-script)
1533 (null (setq vs (get-char-attribute variant 'script)))
1534 (not (memq excluded-script vs))))
1535 (unless (and no-ucs-unified (get-char-attribute variant '=ucs))
1536 (insert-char-data variant printable)
1537 (if (setq ret (char-variants variant))
1539 (or (memq (car ret) variants)
1540 ;; (get-char-attribute (car ret) '<-subsumptive)
1541 (setq rest (nconc rest (list (car ret)))))
1542 (setq ret (cdr ret)))))))
1543 (setq rest (cdr rest)))))
1545 (defun insert-char-range-data (min max &optional script excluded-script)
1548 (while (<= code max)
1549 (setq char (decode-char '=ucs code))
1550 (if (encode-char char '=ucs 'defined-only)
1551 (insert-char-data-with-variant char nil 'no-ucs-unified
1552 script excluded-script))
1553 (setq code (1+ code)))))
1555 (defun write-char-range-data-to-file (min max file
1556 &optional script excluded-script)
1557 (let ((coding-system-for-write char-db-file-coding-system))
1559 (insert (format ";; -*- coding: %s -*-\n"
1560 char-db-file-coding-system))
1561 (insert-char-range-data min max script excluded-script)
1562 (write-region (point-min)(point-max) file))))
1564 (defvar what-character-original-window-configuration)
1567 (defun what-char-definition (char)
1568 (interactive (list (char-after)))
1569 (let ((buf (get-buffer-create "*Character Description*"))
1570 (the-buf (current-buffer))
1571 (win-conf (current-window-configuration)))
1573 (make-local-variable 'what-character-original-window-configuration)
1574 (setq what-character-original-window-configuration win-conf)
1575 (setq buffer-read-only nil)
1579 (insert-char-data-with-variant char 'printable)
1580 (unless (char-attribute-alist char)
1581 (insert (format ";; = %c\n"
1582 (let* ((rest (split-char char))
1586 (setq code (logior (lsh code 8)
1588 (decode-char ccs code)))))
1589 ;; (char-db-update-comment)
1590 (set-buffer-modified-p nil)
1591 (view-mode the-buf (lambda (buf)
1592 (set-window-configuration
1593 what-character-original-window-configuration)
1595 (goto-char (point-min)))
1597 (set-window-configuration
1598 what-character-original-window-configuration)
1599 (signal (car err) (cdr err)))))))
1605 (provide 'char-db-util)
1607 ;;; char-db-util.el ends here