1 ;;; char-db-util.el --- Character Database utility -*- coding: utf-8-er; -*-
3 ;; Copyright (C) 1998,1999,2000,2001,2002,2003,2004,2005,2006,2007,
4 ;; 2008,2009,2010,2011,2012,2013,2014,2015,2016 MORIOKA Tomohiko.
6 ;; Author: MORIOKA Tomohiko <tomo@kanji.zinbun.kyoto-u.ac.jp>
7 ;; Keywords: CHISE, Character Database, ISO/IEC 10646, UCS, Unicode, MULE.
9 ;; This file is part of XEmacs CHISE.
11 ;; XEmacs CHISE is free software; you can redistribute it and/or
12 ;; modify it under the terms of the GNU General Public License as
13 ;; published by the Free Software Foundation; either version 2, or (at
14 ;; your option) any later version.
16 ;; XEmacs CHISE is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 ;; General Public License for more details.
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with XEmacs CHISE; see the file COPYING. If not, write to
23 ;; the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
24 ;; Boston, MA 02111-1307, USA.
29 (require 'ideograph-subr)
31 (defconst unidata-normative-category-alist
32 '(("Lu" letter uppercase)
33 ("Ll" letter lowercase)
34 ("Lt" letter titlecase)
35 ("Mn" mark non-spacing)
36 ("Mc" mark spacing-combining)
38 ("Nd" number decimal-digit)
41 ("Zs" separator space)
43 ("Zp" separator paragraph)
46 ("Cs" other surrogate)
47 ("Co" other private-use)
48 ("Cn" other not-assigned)))
50 (defconst unidata-informative-category-alist
51 '(("Lm" letter modifier)
53 ("Pc" punctuation connector)
54 ("Pd" punctuation dash)
55 ("Ps" punctuation open)
56 ("Pe" punctuation close)
57 ("Pi" punctuation initial-quote)
58 ("Pf" punctuation final-quote)
59 ("Po" punctuation other)
61 ("Sc" symbol currency)
62 ("Sk" symbol modifier)
66 (defconst shuowen-radicals
67 [?一 ?上 ?示 ?三 ?王 ?玉 ?玨 ?气 ?士 ?丨 ; 010
68 ?屮 ?艸 ?蓐 ?茻 ?小 ?八 ?釆 ?半 ?牛 ?犛 ; 020
69 ?告 ?口 ?凵 ?吅 ?哭 ?走 ?止 ?癶 ?步 ?此 ; 030
70 ?正 ?是 ?辵 ?彳 ?廴 ?㢟 ?行 ?齒 ?牙 ?足 ; 040
71 ?疋 ?品 ?龠 ?冊 ?㗊 ?舌 ?干 ?谷 ?只 ?㕯 ; 050
72 ?句 ?丩 ?古 ?十 ?卅 ?言 ?誩 ?音 ?䇂 ?丵 ; 060
73 ?菐 ?𠬞 ?𠬜 ?共 ?異 ?舁 ?𦥑 ?䢅 ?爨 ?革 ; 070
74 ?鬲 ?䰜 ?爪 ?𠃨 ?鬥 ?又 ?𠂇 ?㕜 ?支 ?𦘒 ; 080
75 ?聿 ?畫 ?隶 ?臤 ?臣 ?殳 ?殺 ?𠘧 ?寸 ?皮 ; 090
76 ?㼱 ?攴 ?敎 ?卜 ?用 ?爻 ?㸚 ?𥄎 ?目 ?䀠 ; 100
77 ?眉 ?盾 ?自 ?白 ?鼻 ?皕 ?習 ?羽 ?隹 ?奞 ; 110
78 ?萑 ?𦫳 ?苜 ?羊 ?羴 ?瞿 ?雔 ?雥 ?鳥 ?烏 ; 120
79 ?𠦒 ?冓 ?幺 ?𢆶 ?叀 ?玄 ?予 ?放 ?𠬪 ?𣦼 ; 130
80 ?歺 ?死 ?冎 ?骨 ?肉 ?筋 ?刀 ?刃 ?㓞 ?丰 ; 140
81 ?耒 ?𧢲 ?竹 ?箕 ?丌 ?左 ?工 ?㠭 ?巫 ?甘 ; 150
82 ?曰 ?乃 ?丂 ?可 ?兮 ?号 ?亏 ?旨 ?喜 ?壴 ; 160
83 ; ?旨 ?曰 ?乃 ?丂 ?可 ?兮 ?号 ?亏 ?喜 ?壴 ; 160
84 ?鼓 ?豈 ?豆 ?豊 ?豐 ?䖒 ?虍 ?虎 ?虤 ?皿 ; 170
85 ?𠙴 ?去 ?血 ?丶 ?丹 ?青 ?井 ?皀 ?鬯 ?食 ; 180
86 ?亼 ?會 ?倉 ?入 ?缶 ?矢 ?高 ?冂 ?𩫏 ?京 ; 190
87 ?亯 ?𣆪 ?畗 ?㐭 ?嗇 ?來 ?麥 ?夊 ?舛 ?䑞 ; 200
88 ?韋 ?弟 ?夂 ?久 ?桀 ?木 ?東 ?林 ?才 ?叒 ; 210
89 ?之 ?帀 ?出 ?𣎵 ?生 ?乇 ?𠂹 ?𠌶 ?華 ?𥝌 ; 220
90 ?稽 ?巢 ?桼 ?束 ?㯻 ?囗 ?員 ?貝 ?邑 ?𨛜 ; 230
91 ?日 ?旦 ?倝 ?㫃 ?冥 ?晶 ?月 ?有 ?明 ?囧 ; 240
92 ?夕 ?多 ?毌 ?𢎘 ?𣐺 ?卣 ?齊 ?朿 ?片 ?鼎 ; 250
93 ?克 ?彔 ?禾 ?秝 ?黍 ?香 ?米 ?毇 ?臼 ?凶 ; 260
94 ?𣎳 ?林 ?麻 ?尗 ?耑 ?韭 ?瓜 ?瓠 ?宀 ?宮 ; 270
95 ?呂 ?穴 ?㝱 ?𤕫 ?冖 ?𠔼 ?冃 ?㒳 ?网 ?襾 ; 280
96 ?巾 ?巿 ?帛 ?白 ?㡀 ?黹 ?人 ?𠤎 ?匕 ?从 ; 290
97 ?比 ?北 ?丘 ?㐺 ?𡈼 ?重 ?臥 ?身 ?㐆 ?衣 ; 300
98 ?裘 ?老 ?毛 ?毳 ?尸 ?尺 ?尾 ?履 ?舟 ?方 ; 310
99 ?儿 ?兄 ?兂 ?皃 ?𠑹 ?先 ?秃 ?見 ?覞 ?欠 ; 320
100 ?㱃 ?㳄 ?旡 ?頁 ?𦣻 ?面 ?丏 ?首 ?𥄉 ?須 ; 330
101 ?彡 ?彣 ?文 ?髟 ?后 ?司 ?卮 ?卩 ?印 ?色 ; 340
102 ?𠨍 ?辟 ?勹 ?包 ?茍 ?鬼 ?甶 ?厶 ?嵬 ?山 ; 350
103 ?屾 ?屵 ?广 ?厂 ?丸 ?危 ?石 ?長 ?勿 ?冄 ; 360
104 ?而 ?豕 ?㣇 ?彑 ?豚 ?豸 ?𤉡 ?易 ?象 ?馬 ; 370
105 ?𢊁 ?鹿 ?麤 ?㲋 ?兔 ?萈 ?犬 ?㹜 ?鼠 ?能 ; 380
106 ?熊 ?火 ?炎 ?黑 ?囪 ?焱 ?炙 ?赤 ?大 ?亦 ; 390
109 (defun shuowen-radical (number)
110 (aref shuowen-radicals (1- number)))
112 (defvar char-db-file-coding-system 'utf-8-mcs-er)
114 (defvar char-db-ignored-attributes '(ideographic-products))
116 (defvar char-db-coded-charset-priority-list
212 ;; =>>>adobe-japan1-0
213 ;; =>>>adobe-japan1-1
214 ;; =>>>adobe-japan1-2
215 ;; =>>>adobe-japan1-3
216 ;; =>>>adobe-japan1-4
217 ;; =>>>adobe-japan1-5
218 ;; =>>>adobe-japan1-6
222 ;; =>>>hanyo-denshi/ja
223 ;; =>>>hanyo-denshi/jb
224 ;; =>>>hanyo-denshi/jc
225 ;; =>>>hanyo-denshi/ft
226 ;; =>>>hanyo-denshi/ib
227 ;; =>>>hanyo-denshi/hg
228 ;; =>>>hanyo-denshi/jt
229 ;; =>>>hanyo-denshi/ks
345 =>big5-cdp-itaiji-001
357 ;;; @ char-db formatters
360 (defun char-db-make-char-spec (char)
362 (cond ((characterp char)
363 (cond ((and (setq ret (encode-char char '=ucs 'defined-only))
364 (not (and (<= #xE000 ret)(<= ret #xF8FF))))
365 (setq char-spec (list (cons '=ucs ret)))
366 (cond ((setq ret (get-char-attribute char 'name))
367 (setq char-spec (cons (cons 'name ret) char-spec))
369 ((setq ret (get-char-attribute char 'name*))
370 (setq char-spec (cons (cons 'name* ret) char-spec))
373 ((encode-char char '=mj 'defined-only)
375 (dolist (ccs (charset-list))
376 (if (and (or (eq ccs '=mj)
377 ;; (eq (charset-property ccs 'iso-ir) 177)
378 (string-match "=ucs@" (symbol-name ccs))
380 (setq ccs (charset-name ccs))
381 (null (assq ccs char-spec))
382 (setq ret (encode-char char ccs 'defined-only)))
383 (setq char-spec (cons (cons ccs ret) char-spec))))
385 ((encode-char char '==mj 'defined-only)
387 (dolist (ccs (charset-list))
388 (if (and (or (eq ccs '==mj)
389 ;; (eq (charset-property ccs 'iso-ir) 177)
390 (string-match "=ucs@" (symbol-name ccs))
392 (setq ccs (charset-name ccs))
393 (null (assq ccs char-spec))
394 (setq ret (encode-char char ccs 'defined-only)))
395 (setq char-spec (cons (cons ccs ret) char-spec))))
397 ((encode-char char '=adobe-japan1 'defined-only)
399 (dolist (ccs (charset-list))
400 (if (and (or (memq ccs
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 '==adobe-japan1 'defined-only)
419 (dolist (ccs (charset-list))
420 (if (and (or (memq ccs
429 ;; (eq (charset-property ccs 'iso-ir) 177)
430 (string-match "=ucs@" (symbol-name ccs))
432 (setq ccs (charset-name ccs))
433 (null (assq ccs char-spec))
434 (setq ret (encode-char char ccs 'defined-only)))
435 (setq char-spec (cons (cons ccs ret) char-spec))))
439 (let ((rest char-db-coded-charset-priority-list)
442 (setq ccs (charset-name
443 (find-charset (car rest))))
445 (encode-char char ccs
447 (throw 'tag (cons ccs ret)))
448 (setq rest (cdr rest))))))
449 (setq char-spec (list ret))
450 (dolist (ccs (delq (car ret) (charset-list)))
451 (if (and (or (charset-iso-final-char ccs)
458 (eq (charset-property ccs 'iso-ir) 177)
459 ;; (string-match "=ucs@" (symbol-name ccs))
461 (setq ccs (charset-name ccs))
462 (null (assq ccs char-spec))
463 (setq ret (encode-char char ccs 'defined-only)))
464 (setq char-spec (cons (cons ccs ret) char-spec))))
466 (setq char-spec (split-char char)))
467 (cond ((setq ret (get-char-attribute char 'name))
468 (setq char-spec (cons (cons 'name ret) char-spec))
470 ((setq ret (get-char-attribute char 'name*))
471 (setq char-spec (cons (cons 'name* ret) char-spec))
474 ((setq ret (get-char-attribute
475 char 'ideographic-combination))
477 (cons (cons 'ideographic-combination ret)
484 (defun char-db-insert-char-spec (char &optional readable column
487 (setq column (current-column)))
488 (let (char-spec temp-char)
489 (setq char-spec (char-db-make-char-spec char))
490 (unless (or (characterp char) ; char
492 (setq char (find-char char-spec))
494 ;; define temporary character
495 ;; Current implementation is dirty.
496 (setq temp-char (define-char (cons '(ideograph-daikanwa . 0)
498 (remove-char-attribute temp-char 'ideograph-daikanwa)
499 (setq char temp-char))
500 (insert-char-attributes char
502 (union (mapcar #'car char-spec)
506 ;; undefine temporary character
507 ;; Current implementation is dirty.
508 (setq char-spec (char-attribute-alist temp-char))
510 (remove-char-attribute temp-char (car (car char-spec)))
511 (setq char-spec (cdr char-spec))))))
513 (defun char-db-insert-alist (alist &optional readable column)
515 (setq column (current-column)))
517 (concat "\n" (make-string (1+ column) ?\ )))
521 lbs cell rest separator)
524 (setq name (car (car alist))
525 value (cdr (car alist)))
526 (cond ((eq name 'char)
528 (if (setq ret (condition-case nil
536 (setq key (car (car value)))
537 ;; (if (find-charset key)
538 ;; (setq cal (cons key cal))
539 (setq al (cons key al))
541 (setq value (cdr value)))
542 (insert-char-attributes ret
546 (insert (prin1-to-string value)))
548 (insert line-breaking))
550 (insert (format "(%-18s " name))
551 (setq lbs (concat "\n" (make-string (current-column) ?\ )))
553 (setq cell (car value))
554 (if (and (consp cell)
556 (setq ret (condition-case nil
566 (setq key (car (car rest)))
567 ;; (if (find-charset key)
568 ;; (setq cal (cons key cal))
569 (setq al (cons key al))
571 (setq rest (cdr rest)))
574 (insert-char-attributes ret
578 (setq separator lbs))
581 (insert (prin1-to-string cell))
582 (setq separator " "))
583 (setq value (cdr value)))
585 (insert line-breaking))
587 (insert (format "(%-18s . %S)%s"
590 (setq alist (cdr alist))))
593 (defun char-db-insert-char-reference (plist &optional readable column)
595 (setq column (current-column)))
597 (concat "\n" (make-string (1+ column) ?\ )))
602 (setq name (pop plist))
603 (setq value (pop plist))
604 (cond ((eq name :char)
607 (cond ((numberp value)
608 (setq value (decode-char '=ucs value)))
610 ;; (setq value (or (find-char value)
613 (char-db-insert-char-spec value readable)
614 (insert line-breaking)
617 (insert (format "%s%s\t%d ; %c%s"
620 (ideographic-radical value)
624 (insert (format "%s%s\t%S" separator name value))
625 (setq separator line-breaking)))
629 (defun char-db-decode-isolated-char (ccs code-point)
632 (cond ((eq ccs 'arabic-iso8859-6)
633 (decode-char ccs code-point))
635 ;; (decode-builtin-char '==gt code-point))
636 ((and (memq ccs '(=gt-pj-1
647 (setq ret (decode-char ccs code-point))
648 (setq ret (encode-char ret '=gt 'defined-only)))
649 (decode-builtin-char '=gt ret))
651 (decode-builtin-char ccs code-point))))
653 (or (decode-char ccs code-point)
654 (define-char (list (cons ccs code-point)))))
655 ((and (<= 0 (char-int ret))
656 (<= (char-int ret) #x1F))
657 (decode-char '=ucs (+ #x2400 (char-int ret))))
658 ((= (char-int ret) #x7F)
662 (defvar char-db-convert-obsolete-format t)
664 (defun char-db-insert-ccs-feature (name value line-breaking)
670 ((memq name '(=>iwds-1
673 =shinjigen@1ed ==shinjigen@1ed
674 =shinjigen@rev ==shinjigen@rev
675 =shinjigen/+p@rev ==shinjigen/+p@rev
676 ===daikanwa/ho ==daikanwa/ho
677 =daikanwa/ho =>>daikanwa/ho =>daikanwa/ho))
678 "(%-18s . %04d)\t; %c")
679 ((eq name '=shinjigen@1ed/24pr)
680 "(%-18s . %04d)\t; %c")
684 ==daikanwa =daikanwa =>>daikanwa =>daikanwa
685 =daikanwa@rev1 =daikanwa@rev2
686 =daikanwa/+p ==daikanwa/+p ===daikanwa/+p
688 =daikanwa/+2p =>>daikanwa/+2p
693 =adobe-japan1-0 ==adobe-japan1-0 ===adobe-japan1-0
694 =adobe-japan1-1 ==adobe-japan1-1 ===adobe-japan1-1
695 =adobe-japan1-2 ==adobe-japan1-2 ===adobe-japan1-2
696 =adobe-japan1-3 ==adobe-japan1-3 ===adobe-japan1-3
697 =adobe-japan1-4 ==adobe-japan1-4 ===adobe-japan1-4
698 =adobe-japan1-5 ==adobe-japan1-5 ===adobe-japan1-5
699 =adobe-japan1-6 ==adobe-japan1-6 ===adobe-japan1-6
700 =>>adobe-japan1-0 =+>adobe-japan1-0
701 =>>adobe-japan1-1 =+>adobe-japan1-1
702 =>>adobe-japan1-2 =+>adobe-japan1-2
703 =>>adobe-japan1-3 =+>adobe-japan1-3
704 =>>adobe-japan1-4 =+>adobe-japan1-4
705 =>>adobe-japan1-5 =+>adobe-japan1-5
706 =>>adobe-japan1-6 =+>adobe-japan1-6
707 =>cbeta =cbeta =>>cbeta ==cbeta ===cbeta
708 =zinbun-oracle =>zinbun-oracle
709 ===hng-jou ===hng-keg ===hng-dng ===hng-mam
710 ===hng-drt ===hng-kgk ===hng-myz ===hng-kda
711 ===hng-khi ===hng-khm ===hng-hok ===hng-kyd ===hng-sok
712 ===hng-yhk ===hng-kak ===hng-kar ===hng-kae
713 ===hng-sys ===hng-tsu ===hng-tzj
714 ===hng-hos ===hng-nak ===hng-jhk
715 ===hng-hod ===hng-gok ===hng-ink ===hng-nto
716 ===hng-nkm ===hng-k24 ===hng-nkk
717 ===hng-kcc ===hng-kcj ===hng-kbk ===hng-sik
718 ===hng-skk ===hng-kyu ===hng-ksk ===hng-wan
719 ===hng-okd ===hng-wad ===hng-kmi
720 ===hng-zkd ===hng-doh ===hng-jyu
721 ===hng-tzs ===hng-kss ===hng-kyo
723 ;; (string-match "^=adobe-" (symbol-name name))
725 "(%-18s . %05d)\t; %c")
726 ((memq name '(=hanyo-denshi/ks
727 ==hanyo-denshi/ks ===hanyo-denshi/ks
730 =mj ==mj ===mj =>>mj =>mj
732 "(%-18s . %06d)\t; %c")
733 ((memq name '(=hanyo-denshi/tk ==hanyo-denshi/tk))
734 "(%-18s . %08d)\t; %c")
735 ((>= (charset-dimension name) 2)
736 "(%-18s . #x%04X)\t; %c")
738 "(%-18s . #x%02X)\t; %c"))
740 (if (= (charset-iso-graphic-plane name) 1)
742 (cond ((= (charset-dimension name) 1)
744 ((= (charset-dimension name) 2)
746 ((= (charset-dimension name) 3)
750 (char-db-decode-isolated-char name value)))
751 (if (and (= (charset-chars name) 94)
752 (= (charset-dimension name) 2))
753 (insert (format " [%02d-%02d]"
754 (- (lsh value -8) 32)
755 (- (logand value 255) 32))))
758 (insert (format "(%-18s . %s)" name value))
760 (insert line-breaking))
762 (defun char-db-insert-relation-feature (char name value line-breaking
764 (insert (format "(%-18s%s " name line-breaking))
765 (let ((lbs (concat "\n" (make-string (current-column) ?\ )))
766 separator cell sources required-features
768 (if (characterp value)
769 (setq value (list value)))
771 (setq cell (car value))
773 (setq cell (decode-char '=ucs cell)))
775 ((eq name '->subsumptive)
776 (when (or (not (some (lambda (atr)
777 (get-char-attribute cell atr))
778 char-db-ignored-attributes))
780 (encode-char cell ccs 'defined-only))
784 (let ((char-db-ignored-attributes
786 char-db-ignored-attributes)))
787 (insert-char-attributes cell readable nil nil 'for-sub-node))
788 (setq separator lbs))
793 char (intern (format "%s*sources" name))))
794 (setq required-features nil)
795 (dolist (source sources)
799 shinjigen shinjigen@1ed shinjigen@rev))
800 (setq required-features
801 (union required-features
813 =shinjigen/+p@rev))))
815 (setq required-features
816 (union required-features
821 ((find-charset (setq ret (intern (format "=%s" source))))
822 (setq required-features
823 (cons ret required-features)))
824 (t (setq required-features
825 (cons source required-features)))))
826 (cond ((string-match "@JP" (symbol-name name))
827 (setq required-features
828 (union required-features
836 ((string-match "@CN" (symbol-name name))
837 (setq required-features
838 (union required-features
845 (insert (format "%S" cell))
846 (char-db-insert-char-spec cell readable
849 (setq separator lbs))
853 (if (consp (car cell))
854 (char-db-insert-char-spec cell readable)
855 (char-db-insert-char-reference cell readable))
856 (setq separator lbs))
860 (insert (prin1-to-string cell))
861 (setq separator " ")))
862 (setq value (cdr value)))
864 (insert line-breaking)))
866 (defun insert-char-attributes (char &optional readable attributes column
869 (setq column (current-column)))
870 (let (name value ; has-long-ccs-name
874 (concat "\n" (make-string (1+ column) ?\ )))
875 lbs cell separator ret
877 dest-ccss ; sources required-features
882 (if (consp attributes)
884 (dolist (name attributes)
885 (unless (memq name char-db-ignored-attributes)
886 (if (find-charset name)
890 (dolist (name (char-attribute-list))
891 (unless (memq name char-db-ignored-attributes)
892 (if (find-charset name)
896 #'char-attribute-name<)))
898 (when (memq '<-subsumptive attributes)
899 (when (or readable (not for-sub-node))
900 (when (setq value (get-char-attribute char '<-subsumptive))
901 (char-db-insert-relation-feature char '<-subsumptive value
904 (setq attributes (delq '<-subsumptive attributes)))
905 (when (and (memq '<-denotational attributes)
906 (setq value (get-char-attribute char '<-denotational)))
907 (char-db-insert-relation-feature char '<-denotational value
910 (setq attributes (delq '<-denotational attributes)))
911 (when (and (memq '<-denotational@component attributes)
912 (setq value (get-char-attribute char '<-denotational@component)))
913 (char-db-insert-relation-feature char '<-denotational@component value
916 (setq attributes (delq '<-denotational@component attributes)))
917 (when (and (memq 'name attributes)
918 (setq value (get-char-attribute char 'name)))
920 (if (> (+ (current-column) (length value)) 48)
923 value line-breaking))
924 (setq attributes (delq 'name attributes))
926 (when (and (memq 'name* attributes)
927 (setq value (get-char-attribute char 'name*)))
929 (if (> (+ (current-column) (length value)) 48)
932 value line-breaking))
933 (setq attributes (delq 'name* attributes))
935 (when (and (memq 'script attributes)
936 (setq value (get-char-attribute char 'script)))
937 (insert (format "(script\t\t%s)%s"
938 (mapconcat (function prin1-to-string)
941 (setq attributes (delq 'script attributes))
943 (dolist (name '(=>ucs =>ucs*))
944 (when (and (memq name attributes)
945 (setq value (get-char-attribute char name)))
946 (insert (format "(%-18s . #x%04X)\t; %c%s"
947 name value (decode-char '=ucs value)
949 (setq attributes (delq name attributes))))
950 (dolist (name '(=>ucs@gb =>ucs@big5))
951 (when (and (memq name attributes)
952 (setq value (get-char-attribute char name)))
953 (insert (format "(%-18s . #x%04X)\t; %c%s"
958 (symbol-name name) 2)))
961 (setq attributes (delq name attributes))
963 ;; (dolist (name '(=>daikanwa))
964 ;; (when (and (memq name attributes)
965 ;; (setq value (get-char-attribute char name)))
967 ;; (if (integerp value)
968 ;; (format "(%-18s . %05d)\t; %c%s"
969 ;; name value (decode-char '=daikanwa value)
971 ;; (format "(%-18s %s)\t; %c%s"
973 ;; (mapconcat (function prin1-to-string)
975 ;; (char-representative-of-daikanwa char)
977 ;; (setq attributes (delq name attributes))))
978 (when (and (memq 'general-category attributes)
979 (setq value (get-char-attribute char 'general-category)))
981 "(general-category\t%s) ; %s%s"
982 (mapconcat (lambda (cell)
985 (cond ((rassoc value unidata-normative-category-alist)
986 "Normative Category")
987 ((rassoc value unidata-informative-category-alist)
988 "Informative Category")
992 (setq attributes (delq 'general-category attributes))
994 (when (and (memq 'bidi-category attributes)
995 (setq value (get-char-attribute char 'bidi-category)))
996 (insert (format "(bidi-category\t. %S)%s"
999 (setq attributes (delq 'bidi-category attributes))
1001 (unless (or (not (memq 'mirrored attributes))
1002 (eq (setq value (get-char-attribute char 'mirrored 'empty))
1004 (insert (format "(mirrored\t\t. %S)%s"
1007 (setq attributes (delq 'mirrored attributes))
1010 ((and (memq 'decimal-digit-value attributes)
1011 (setq value (get-char-attribute char 'decimal-digit-value)))
1012 (insert (format "(decimal-digit-value . %S)%s"
1015 (setq attributes (delq 'decimal-digit-value attributes))
1016 (when (and (memq 'digit-value attributes)
1017 (setq value (get-char-attribute char 'digit-value)))
1018 (insert (format "(digit-value\t . %S)%s"
1021 (setq attributes (delq 'digit-value attributes))
1023 (when (and (memq 'numeric-value attributes)
1024 (setq value (get-char-attribute char 'numeric-value)))
1025 (insert (format "(numeric-value\t . %S)%s"
1028 (setq attributes (delq 'numeric-value attributes))
1032 (when (and (memq 'digit-value attributes)
1033 (setq value (get-char-attribute char 'digit-value)))
1034 (insert (format "(digit-value\t. %S)%s"
1037 (setq attributes (delq 'digit-value attributes))
1039 (when (and (memq 'numeric-value attributes)
1040 (setq value (get-char-attribute char 'numeric-value)))
1041 (insert (format "(numeric-value\t. %S)%s"
1044 (setq attributes (delq 'numeric-value attributes))
1046 (when (and (memq 'iso-10646-comment attributes)
1047 (setq value (get-char-attribute char 'iso-10646-comment)))
1048 (insert (format "(iso-10646-comment\t. %S)%s"
1051 (setq attributes (delq 'iso-10646-comment attributes))
1053 (when (and (memq 'morohashi-daikanwa attributes)
1054 (setq value (get-char-attribute char 'morohashi-daikanwa)))
1055 (insert (format "(morohashi-daikanwa\t%s)%s"
1056 (mapconcat (function prin1-to-string) value " ")
1058 (setq attributes (delq 'morohashi-daikanwa attributes))
1062 (when (and (memq 'ideographic-radical attributes)
1063 (setq value (get-char-attribute char 'ideographic-radical)))
1064 (setq radical value)
1065 (insert (format "(ideographic-radical . %S)\t; %c%s"
1067 (ideographic-radical radical)
1069 (setq attributes (delq 'ideographic-radical attributes))
1071 (when (and (memq 'shuowen-radical attributes)
1072 (setq value (get-char-attribute char 'shuowen-radical)))
1073 (insert (format "(shuowen-radical\t. %S)\t; %c%s"
1075 (shuowen-radical value)
1077 (setq attributes (delq 'shuowen-radical attributes))
1082 char-db-feature-domains
1084 (dolist (feature (char-attribute-list))
1085 (setq feature (symbol-name feature))
1087 "\\(radical\\|strokes\\)@\\([^@*]+\\)\\(\\*\\|$\\)"
1089 (setq domain (intern (match-string 2 feature)))
1090 (unless (memq domain dest)
1091 (setq dest (cons domain dest)))))
1092 (sort dest #'string<))))
1093 (setq key (intern (format "%s@%s" 'ideographic-radical domain)))
1094 (when (and (memq key attributes)
1095 (setq value (get-char-attribute char key)))
1096 (setq radical value)
1097 (insert (format "(%s . %S)\t; %c%s"
1100 (ideographic-radical radical)
1102 (setq attributes (delq key attributes))
1104 (setq key (intern (format "%s@%s" 'ideographic-strokes domain)))
1105 (when (and (memq key attributes)
1106 (setq value (get-char-attribute char key)))
1107 (setq strokes value)
1108 (insert (format "(%s . %S)%s"
1112 (setq attributes (delq key attributes))
1114 (setq key (intern (format "%s@%s" 'total-strokes domain)))
1115 (when (and (memq key attributes)
1116 (setq value (get-char-attribute char key)))
1117 (insert (format "(%s . %S)%s"
1121 (setq attributes (delq key attributes))
1123 (dolist (feature '(ideographic-radical
1126 (setq key (intern (format "%s@%s*sources" feature domain)))
1127 (when (and (memq key attributes)
1128 (setq value (get-char-attribute char key)))
1129 (insert (format "(%s%s" key line-breaking))
1130 (dolist (cell value)
1131 (insert (format " %s" cell)))
1133 (insert line-breaking)
1134 (setq attributes (delq key attributes))
1137 (when (and (memq 'ideographic-strokes attributes)
1138 (setq value (get-char-attribute char 'ideographic-strokes)))
1139 (setq strokes value)
1140 (insert (format "(ideographic-strokes . %S)%s"
1143 (setq attributes (delq 'ideographic-strokes attributes))
1145 (when (and (memq 'kangxi-radical attributes)
1146 (setq value (get-char-attribute char 'kangxi-radical)))
1147 (unless (eq value radical)
1148 (insert (format "(kangxi-radical\t . %S)\t; %c%s"
1150 (ideographic-radical value)
1153 (setq radical value)))
1154 (setq attributes (delq 'kangxi-radical attributes))
1156 (when (and (memq 'kangxi-strokes attributes)
1157 (setq value (get-char-attribute char 'kangxi-strokes)))
1158 (unless (eq value strokes)
1159 (insert (format "(kangxi-strokes\t . %S)%s"
1163 (setq strokes value)))
1164 (setq attributes (delq 'kangxi-strokes attributes))
1166 ;; (when (and (memq 'japanese-radical attributes)
1167 ;; (setq value (get-char-attribute char 'japanese-radical)))
1168 ;; (unless (eq value radical)
1169 ;; (insert (format "(japanese-radical\t . %S)\t; %c%s"
1171 ;; (ideographic-radical value)
1174 ;; (setq radical value)))
1175 ;; (setq attributes (delq 'japanese-radical attributes))
1177 (when (and (memq 'japanese-strokes attributes)
1178 (setq value (get-char-attribute char 'japanese-strokes)))
1179 (unless (eq value strokes)
1180 (insert (format "(japanese-strokes\t . %S)%s"
1184 (setq strokes value)))
1185 (setq attributes (delq 'japanese-strokes attributes))
1187 (when (and (memq 'cns-radical attributes)
1188 (setq value (get-char-attribute char 'cns-radical)))
1189 (insert (format "(cns-radical\t . %S)\t; %c%s"
1191 (ideographic-radical value)
1193 (setq attributes (delq 'cns-radical attributes))
1195 (when (and (memq 'cns-strokes attributes)
1196 (setq value (get-char-attribute char 'cns-strokes)))
1197 (unless (eq value strokes)
1198 (insert (format "(cns-strokes\t . %S)%s"
1202 (setq strokes value)))
1203 (setq attributes (delq 'cns-strokes attributes))
1205 ;; (when (and (memq 'shinjigen-1-radical attributes)
1206 ;; (setq value (get-char-attribute char 'shinjigen-1-radical)))
1207 ;; (unless (eq value radical)
1208 ;; (insert (format "(shinjigen-1-radical . %S)\t; %c%s"
1210 ;; (ideographic-radical value)
1213 ;; (setq radical value)))
1214 ;; (setq attributes (delq 'shinjigen-1-radical attributes))
1216 ;; (when (and (memq 'ideographic- attributes)
1217 ;; (setq value (get-char-attribute char 'ideographic-)))
1218 ;; (insert "(ideographic- ")
1219 ;; (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1221 ;; (while (consp value)
1222 ;; (setq cell (car value))
1223 ;; (if (integerp cell)
1224 ;; (setq cell (decode-char '=ucs cell)))
1225 ;; (cond ((characterp cell)
1229 ;; (insert (format "%S" cell))
1230 ;; (char-db-insert-char-spec cell readable))
1231 ;; (setq separator lbs))
1235 ;; (if (consp (car cell))
1236 ;; (char-db-insert-char-spec cell readable)
1237 ;; (char-db-insert-char-reference cell readable))
1238 ;; (setq separator lbs))
1241 ;; (insert separator))
1242 ;; (insert (prin1-to-string cell))
1243 ;; (setq separator " ")))
1244 ;; (setq value (cdr value)))
1246 ;; (insert line-breaking)
1247 ;; (setq attributes (delq 'ideographic- attributes)))
1248 (when (and (memq 'total-strokes attributes)
1249 (setq value (get-char-attribute char 'total-strokes)))
1250 (insert (format "(total-strokes . %S)%s"
1253 (setq attributes (delq 'total-strokes attributes))
1255 ;; (when (and (memq '->ideograph attributes)
1256 ;; (setq value (get-char-attribute char '->ideograph)))
1257 ;; (insert (format "(->ideograph\t%s)%s"
1258 ;; (mapconcat (lambda (code)
1259 ;; (cond ((symbolp code)
1260 ;; (symbol-name code))
1262 ;; (format "#x%04X" code))
1265 ;; line-breaking code))))
1268 ;; (setq attributes (delq '->ideograph attributes))
1270 ;; (when (and (memq '->decomposition attributes)
1271 ;; (setq value (get-char-attribute char '->decomposition)))
1272 ;; (insert (format "(->decomposition\t%s)%s"
1273 ;; (mapconcat (lambda (code)
1274 ;; (cond ((symbolp code)
1275 ;; (symbol-name code))
1276 ;; ((characterp code)
1278 ;; (format "%S" code)
1283 ;; (format "#x%04X" code))
1285 ;; (format "%s%S" line-breaking code))))
1288 ;; (setq attributes (delq '->decomposition attributes))
1290 (if (equal (get-char-attribute char '->titlecase)
1291 (get-char-attribute char '->uppercase))
1292 (setq attributes (delq '->titlecase attributes)))
1293 (when (and (memq '->mojikyo attributes)
1294 (setq value (get-char-attribute char '->mojikyo)))
1295 (insert (format "(->mojikyo\t\t. %06d)\t; %c%s"
1296 value (decode-char 'mojikyo value)
1298 (setq attributes (delq '->mojikyo attributes))
1300 ;; (when (and (memq 'hanyu-dazidian-vol attributes)
1301 ;; (setq value (get-char-attribute char 'hanyu-dazidian-vol)))
1302 ;; (insert (format "(hanyu-dazidian-vol . %d)%s"
1303 ;; value line-breaking))
1304 ;; (setq attributes (delq 'hanyu-dazidian-vol attributes))
1306 ;; (when (and (memq 'hanyu-dazidian-page attributes)
1307 ;; (setq value (get-char-attribute char 'hanyu-dazidian-page)))
1308 ;; (insert (format "(hanyu-dazidian-page . %d)%s"
1309 ;; value line-breaking))
1310 ;; (setq attributes (delq 'hanyu-dazidian-page attributes))
1312 ;; (when (and (memq 'hanyu-dazidian-char attributes)
1313 ;; (setq value (get-char-attribute char 'hanyu-dazidian-char)))
1314 ;; (insert (format "(hanyu-dazidian-char . %d)%s"
1315 ;; value line-breaking))
1316 ;; (setq attributes (delq 'hanyu-dazidian-char attributes))
1319 (dolist (ignored '(composition
1320 ->denotational <-subsumptive ->ucs-unified
1321 ->ideographic-component-forms))
1322 (setq attributes (delq ignored attributes))))
1324 (setq name (car attributes))
1325 (unless (eq (setq value (get-char-attribute char name 'value-is-empty))
1327 (cond ((setq ret (find-charset name))
1328 (setq name (charset-name ret))
1329 (when (not (memq name dest-ccss))
1330 (setq dest-ccss (cons name dest-ccss))
1331 (char-db-insert-ccs-feature name value line-breaking))
1333 ((string-match "^=>ucs@" (symbol-name name))
1334 (insert (format "(%-18s . #x%04X)\t; %c%s"
1335 name value (decode-char '=ucs value)
1338 ((eq name 'jisx0208-1978/4X)
1339 (insert (format "(%-18s . #x%04X)%s"
1345 (not (eq name '->subsumptive))
1346 (not (eq name '->uppercase))
1347 (not (eq name '->lowercase))
1348 (not (eq name '->titlecase))
1349 (not (eq name '->canonical))
1350 (not (eq name '->Bopomofo))
1351 (not (eq name '->mistakable))
1352 (not (eq name '->ideographic-variants))
1353 (null (get-char-attribute
1354 char (intern (format "%s*sources" name))))
1355 (not (string-match "\\*sources$" (symbol-name name)))
1356 (null (get-char-attribute
1357 char (intern (format "%s*note" name))))
1358 (not (string-match "\\*note$" (symbol-name name)))
1359 (or (eq name '<-identical)
1360 (eq name '<-uppercase)
1361 (eq name '<-lowercase)
1362 (eq name '<-titlecase)
1363 (eq name '<-canonical)
1364 (eq name '<-ideographic-variants)
1365 ;; (eq name '<-synonyms)
1366 (string-match "^<-synonyms" (symbol-name name))
1367 (eq name '<-mistakable)
1368 (when (string-match "^->" (symbol-name name))
1370 ((string-match "^->fullwidth" (symbol-name name))
1371 (not (and (consp value)
1372 (characterp (car value))
1374 (car value) '=ucs 'defined-only)))
1379 ((or (eq name 'ideographic-structure)
1380 (eq name 'ideographic-combination)
1381 ;; (eq name 'ideographic-)
1382 (eq name '=decomposition)
1383 (char-feature-base-name= '=decomposition name)
1384 (char-feature-base-name= '=>decomposition name)
1385 ;; (string-match "^=>*decomposition\\(@[^*]+\\)?$"
1386 ;; (symbol-name name))
1387 (string-match "^\\(->\\|<-\\)[^*]*$" (symbol-name name))
1388 (string-match "^\\(->\\|<-\\)[^*]*\\*sources$"
1391 (char-db-insert-relation-feature char name value
1394 ;; ((memq name '(ideograph=
1395 ;; original-ideograph-of
1396 ;; ancient-ideograph-of
1397 ;; vulgar-ideograph-of
1398 ;; wrong-ideograph-of
1399 ;; ;; simplified-ideograph-of
1400 ;; ideographic-variants
1401 ;; ;; ideographic-different-form-of
1403 ;; (insert (format "(%-18s%s " name line-breaking))
1404 ;; (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1406 ;; (while (consp value)
1407 ;; (setq cell (car value))
1408 ;; (if (and (consp cell)
1409 ;; (consp (car cell)))
1413 ;; (char-db-insert-alist cell readable)
1414 ;; (setq separator lbs))
1416 ;; (insert separator))
1417 ;; (insert (prin1-to-string cell))
1418 ;; (setq separator " "))
1419 ;; (setq value (cdr value)))
1421 ;; (insert line-breaking))
1423 (insert (format "(%-18s " name))
1424 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1426 (while (consp value)
1427 (setq cell (car value))
1428 (if (and (consp cell)
1430 (setq ret (condition-case nil
1438 (setq key (car (car rest)))
1439 (if (find-charset key)
1440 (setq cal (cons key cal))
1441 (setq al (cons key al)))
1442 (setq rest (cdr rest)))
1445 (insert-char-attributes ret
1449 (setq separator lbs))
1450 (setq ret (prin1-to-string cell))
1452 (if (< (+ (current-column)
1459 (setq separator " "))
1460 (setq value (cdr value)))
1462 (insert line-breaking))
1464 (insert (format "(%-18s" name))
1465 (setq ret (prin1-to-string value))
1466 (unless (< (+ (current-column)
1470 (insert line-breaking))
1471 (insert " . " ret ")" line-breaking)
1472 ;; (insert (format "(%-18s . %S)%s"
1477 (setq attributes (cdr attributes)))
1480 (defun insert-char-data (char &optional readable
1483 (narrow-to-region (point)(point))
1484 (insert "(define-char
1486 (insert-char-attributes char readable attributes)
1488 (goto-char (point-min))
1489 (while (re-search-forward "[ \t]+$" nil t)
1492 (goto-char (point-min))
1493 (while (re-search-forward "[ \t][ \t][ \t]*" nil t)
1494 (let ((column (current-column))
1495 (indent-tabs-mode t))
1496 (delete-region (match-beginning 0) (point))
1497 (indent-to column)))
1498 (goto-char (point-max))
1499 ;; (tabify (point-min)(point-max))
1502 (defun insert-char-data-with-variant (char &optional printable
1504 script excluded-script)
1505 (insert-char-data char printable)
1506 (let ((variants (char-variants char))
1509 (setq variants (sort variants #'<))
1510 (setq rest variants)
1511 (setq variants (cons char variants))
1513 (setq variant (car rest))
1514 (unless (get-char-attribute variant '<-subsumptive)
1515 (if (and (or (null script)
1516 (null (setq vs (get-char-attribute variant 'script)))
1518 (or (null excluded-script)
1519 (null (setq vs (get-char-attribute variant 'script)))
1520 (not (memq excluded-script vs))))
1521 (unless (and no-ucs-unified (get-char-attribute variant '=ucs))
1522 (insert-char-data variant printable)
1523 (if (setq ret (char-variants variant))
1525 (or (memq (car ret) variants)
1526 ;; (get-char-attribute (car ret) '<-subsumptive)
1527 (setq rest (nconc rest (list (car ret)))))
1528 (setq ret (cdr ret)))))))
1529 (setq rest (cdr rest)))))
1531 (defun insert-char-range-data (min max &optional script excluded-script)
1534 (while (<= code max)
1535 (setq char (decode-char '=ucs code))
1536 (if (encode-char char '=ucs 'defined-only)
1537 (insert-char-data-with-variant char nil 'no-ucs-unified
1538 script excluded-script))
1539 (setq code (1+ code)))))
1541 (defun write-char-range-data-to-file (min max file
1542 &optional script excluded-script)
1543 (let ((coding-system-for-write char-db-file-coding-system))
1545 (insert (format ";; -*- coding: %s -*-\n"
1546 char-db-file-coding-system))
1547 (insert-char-range-data min max script excluded-script)
1548 (write-region (point-min)(point-max) file))))
1550 (defvar what-character-original-window-configuration)
1553 (defun what-char-definition (char)
1554 (interactive (list (char-after)))
1555 (let ((buf (get-buffer-create "*Character Description*"))
1556 (the-buf (current-buffer))
1557 (win-conf (current-window-configuration)))
1559 (make-local-variable 'what-character-original-window-configuration)
1560 (setq what-character-original-window-configuration win-conf)
1561 (setq buffer-read-only nil)
1565 (insert-char-data-with-variant char 'printable)
1566 (unless (char-attribute-alist char)
1567 (insert (format ";; = %c\n"
1568 (let* ((rest (split-char char))
1572 (setq code (logior (lsh code 8)
1574 (decode-char ccs code)))))
1575 ;; (char-db-update-comment)
1576 (set-buffer-modified-p nil)
1577 (view-mode the-buf (lambda (buf)
1578 (set-window-configuration
1579 what-character-original-window-configuration)
1581 (goto-char (point-min)))
1583 (set-window-configuration
1584 what-character-original-window-configuration)
1585 (signal (car err) (cdr err)))))))
1591 (provide 'char-db-util)
1593 ;;; char-db-util.el ends here