1 ;;; char-db-util.el --- Character Database utility -*- coding: utf-8-er; -*-
3 ;; Copyright (C) 1998,1999,2000,2001,2002,2003,2004,2005,2006,2007,
4 ;; 2008,2009,2010,2011,2012,2013,2014,2015,2016,2017,2018 MORIOKA Tomohiko.
6 ;; Author: MORIOKA Tomohiko <tomo@kanji.zinbun.kyoto-u.ac.jp>
7 ;; Keywords: CHISE, Character Database, ISO/IEC 10646, UCS, Unicode, MULE.
9 ;; This file is part of XEmacs CHISE.
11 ;; XEmacs CHISE is free software; you can redistribute it and/or
12 ;; modify it under the terms of the GNU General Public License as
13 ;; published by the Free Software Foundation; either version 2, or (at
14 ;; your option) any later version.
16 ;; XEmacs CHISE is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 ;; General Public License for more details.
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with XEmacs CHISE; see the file COPYING. If not, write to
23 ;; the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
24 ;; Boston, MA 02111-1307, USA.
29 (require 'ideograph-subr)
31 (defconst unidata-normative-category-alist
32 '(("Lu" letter uppercase)
33 ("Ll" letter lowercase)
34 ("Lt" letter titlecase)
35 ("Mn" mark non-spacing)
36 ("Mc" mark spacing-combining)
38 ("Nd" number decimal-digit)
41 ("Zs" separator space)
43 ("Zp" separator paragraph)
46 ("Cs" other surrogate)
47 ("Co" other private-use)
48 ("Cn" other not-assigned)))
50 (defconst unidata-informative-category-alist
51 '(("Lm" letter modifier)
53 ("Pc" punctuation connector)
54 ("Pd" punctuation dash)
55 ("Ps" punctuation open)
56 ("Pe" punctuation close)
57 ("Pi" punctuation initial-quote)
58 ("Pf" punctuation final-quote)
59 ("Po" punctuation other)
61 ("Sc" symbol currency)
62 ("Sk" symbol modifier)
66 (defconst shuowen-radicals
67 [?一 ?上 ?示 ?三 ?王 ?玉 ?玨 ?气 ?士 ?丨 ; 010
68 ?屮 ?艸 ?蓐 ?茻 ?小 ?八 ?釆 ?半 ?牛 ?犛 ; 020
69 ?告 ?口 ?凵 ?吅 ?哭 ?走 ?止 ?癶 ?步 ?此 ; 030
70 ?正 ?是 ?辵 ?彳 ?廴 ?㢟 ?行 ?齒 ?牙 ?足 ; 040
71 ?疋 ?品 ?龠 ?冊 ?㗊 ?舌 ?干 ?谷 ?只 ?㕯 ; 050
72 ?句 ?丩 ?古 ?十 ?卅 ?言 ?誩 ?音 ?䇂 ?丵 ; 060
73 ?菐 ?𠬞 ?𠬜 ?共 ?異 ?舁 ?𦥑 ?䢅 ?爨 ?革 ; 070
74 ?鬲 ?䰜 ?爪 ?𠃨 ?鬥 ?又 ?𠂇 ?㕜 ?支 ?𦘒 ; 080
75 ?聿 ?畫 ?隶 ?臤 ?臣 ?殳 ?殺 ?𠘧 ?寸 ?皮 ; 090
76 ?㼱 ?攴 ?敎 ?卜 ?用 ?爻 ?㸚 ?𥄎 ?目 ?䀠 ; 100
77 ?眉 ?盾 ?自 ?白 ?鼻 ?皕 ?習 ?羽 ?隹 ?奞 ; 110
78 ?萑 ?𦫳 ?苜 ?羊 ?羴 ?瞿 ?雔 ?雥 ?鳥 ?烏 ; 120
79 ?𠦒 ?冓 ?幺 ?𢆶 ?叀 ?玄 ?予 ?放 ?𠬪 ?𣦼 ; 130
80 ?歺 ?死 ?冎 ?骨 ?肉 ?筋 ?刀 ?刃 ?㓞 ?丰 ; 140
81 ?耒 ?𧢲 ?竹 ?箕 ?丌 ?左 ?工 ?㠭 ?巫 ?甘 ; 150
82 ?曰 ?乃 ?丂 ?可 ?兮 ?号 ?亏 ?旨 ?喜 ?壴 ; 160
83 ; ?旨 ?曰 ?乃 ?丂 ?可 ?兮 ?号 ?亏 ?喜 ?壴 ; 160
84 ?鼓 ?豈 ?豆 ?豊 ?豐 ?䖒 ?虍 ?虎 ?虤 ?皿 ; 170
85 ?𠙴 ?去 ?血 ?丶 ?丹 ?青 ?井 ?皀 ?鬯 ?食 ; 180
86 ?亼 ?會 ?倉 ?入 ?缶 ?矢 ?高 ?冂 ?𩫏 ?京 ; 190
87 ?亯 ?𣆪 ?畗 ?㐭 ?嗇 ?來 ?麥 ?夊 ?舛 ?䑞 ; 200
88 ?韋 ?弟 ?夂 ?久 ?桀 ?木 ?東 ?林 ?才 ?叒 ; 210
89 ?之 ?帀 ?出 ?𣎵 ?生 ?乇 ?𠂹 ?𠌶 ?華 ?𥝌 ; 220
90 ?稽 ?巢 ?桼 ?束 ?㯻 ?囗 ?員 ?貝 ?邑 ?𨛜 ; 230
91 ?日 ?旦 ?倝 ?㫃 ?冥 ?晶 ?月 ?有 ?明 ?囧 ; 240
92 ?夕 ?多 ?毌 ?𢎘 ?𣐺 ?卣 ?齊 ?朿 ?片 ?鼎 ; 250
93 ?克 ?彔 ?禾 ?秝 ?黍 ?香 ?米 ?毇 ?臼 ?凶 ; 260
94 ?𣎳 ?林 ?麻 ?尗 ?耑 ?韭 ?瓜 ?瓠 ?宀 ?宮 ; 270
95 ?呂 ?穴 ?㝱 ?𤕫 ?冖 ?𠔼 ?冃 ?㒳 ?网 ?襾 ; 280
96 ?巾 ?巿 ?帛 ?白 ?㡀 ?黹 ?人 ?𠤎 ?匕 ?从 ; 290
97 ?比 ?北 ?丘 ?㐺 ?𡈼 ?重 ?臥 ?身 ?㐆 ?衣 ; 300
98 ?裘 ?老 ?毛 ?毳 ?尸 ?尺 ?尾 ?履 ?舟 ?方 ; 310
99 ?儿 ?兄 ?兂 ?皃 ?𠑹 ?先 ?秃 ?見 ?覞 ?欠 ; 320
100 ?㱃 ?㳄 ?旡 ?頁 ?𦣻 ?面 ?丏 ?首 ?𥄉 ?須 ; 330
101 ?彡 ?彣 ?文 ?髟 ?后 ?司 ?卮 ?卩 ?印 ?色 ; 340
102 ?𠨍 ?辟 ?勹 ?包 ?茍 ?鬼 ?甶 ?厶 ?嵬 ?山 ; 350
103 ?屾 ?屵 ?广 ?厂 ?丸 ?危 ?石 ?長 ?勿 ?冄 ; 360
104 ?而 ?豕 ?㣇 ?彑 ?豚 ?豸 ?𤉡 ?易 ?象 ?馬 ; 370
105 ?𢊁 ?鹿 ?麤 ?㲋 ?兔 ?萈 ?犬 ?㹜 ?鼠 ?能 ; 380
106 ?熊 ?火 ?炎 ?黑 ?囪 ?焱 ?炙 ?赤 ?大 ?亦 ; 390
109 (defun shuowen-radical (number)
110 (aref shuowen-radicals (1- number)))
112 (defvar char-db-file-coding-system 'utf-8-mcs-er)
114 (defvar char-db-ignored-attributes '(ideographic-products))
116 (defvar char-db-coded-charset-priority-list
214 ;; =>>>adobe-japan1-0
215 ;; =>>>adobe-japan1-1
216 ;; =>>>adobe-japan1-2
217 ;; =>>>adobe-japan1-3
218 ;; =>>>adobe-japan1-4
219 ;; =>>>adobe-japan1-5
220 ;; =>>>adobe-japan1-6
224 ;; =>>>hanyo-denshi/ja
225 ;; =>>>hanyo-denshi/jb
226 ;; =>>>hanyo-denshi/jc
227 ;; =>>>hanyo-denshi/ft
228 ;; =>>>hanyo-denshi/ib
229 ;; =>>>hanyo-denshi/hg
230 ;; =>>>hanyo-denshi/jt
231 ;; =>>>hanyo-denshi/ks
271 ;; =>ucs@hanyo-denshi
369 =>big5-cdp-itaiji-001
373 =>ucs-itaiji-001@iwds-1
382 ;;; @ char-db formatters
385 (defun char-db-make-char-spec (char)
387 (cond ((characterp char)
388 (cond ((and (setq ret (encode-char char '=ucs 'defined-only))
389 (not (and (<= #xE000 ret)(<= ret #xF8FF))))
390 (setq char-spec (list (cons '=ucs ret)))
391 (cond ((setq ret (get-char-attribute char 'name))
392 (setq char-spec (cons (cons 'name ret) char-spec))
394 ((setq ret (get-char-attribute char 'name*))
395 (setq char-spec (cons (cons 'name* ret) char-spec))
398 ((encode-char char '=mj 'defined-only)
400 (dolist (ccs (charset-list))
401 (if (and (or (eq ccs '=mj)
402 ;; (eq (charset-property ccs 'iso-ir) 177)
403 (string-match "=ucs@" (symbol-name ccs))
405 (setq ccs (charset-name ccs))
406 (null (assq ccs char-spec))
407 (setq ret (encode-char char ccs 'defined-only)))
408 (setq char-spec (cons (cons ccs ret) char-spec))))
410 ((encode-char char '==mj 'defined-only)
412 (dolist (ccs (charset-list))
413 (if (and (or (eq ccs '==mj)
414 ;; (eq (charset-property ccs 'iso-ir) 177)
415 (string-match "=ucs@" (symbol-name ccs))
417 (setq ccs (charset-name ccs))
418 (null (assq ccs char-spec))
419 (setq ret (encode-char char ccs 'defined-only)))
420 (setq char-spec (cons (cons ccs ret) char-spec))))
422 ((encode-char char '=adobe-japan1 'defined-only)
424 (dolist (ccs (charset-list))
425 (if (and (or (memq ccs
434 ;; (eq (charset-property ccs 'iso-ir) 177)
435 (string-match "=ucs@" (symbol-name ccs))
437 (setq ccs (charset-name ccs))
438 (null (assq ccs char-spec))
439 (setq ret (encode-char char ccs 'defined-only)))
440 (setq char-spec (cons (cons ccs ret) char-spec))))
442 ((encode-char char '==adobe-japan1 'defined-only)
444 (dolist (ccs (charset-list))
445 (if (and (or (memq ccs
454 ;; (eq (charset-property ccs 'iso-ir) 177)
455 (string-match "=ucs@" (symbol-name ccs))
457 (setq ccs (charset-name ccs))
458 (null (assq ccs char-spec))
459 (setq ret (encode-char char ccs 'defined-only)))
460 (setq char-spec (cons (cons ccs ret) char-spec))))
464 (let ((rest char-db-coded-charset-priority-list)
467 (setq ccs (charset-name
468 (find-charset (car rest))))
470 (encode-char char ccs
472 (throw 'tag (cons ccs ret)))
473 (setq rest (cdr rest))))))
474 (setq char-spec (list ret))
475 (dolist (ccs (delq (car ret) (charset-list)))
476 (if (and (or (charset-iso-final-char ccs)
483 (and (eq (charset-property ccs 'iso-ir) 177)
484 (not (eq (charset-name ccs) '=ucs@big5)))
485 ;; (string-match "=ucs@" (symbol-name ccs))
487 (setq ccs (charset-name ccs))
488 (null (assq ccs char-spec))
489 (setq ret (encode-char char ccs 'defined-only)))
490 (setq char-spec (cons (cons ccs ret) char-spec))))
492 (setq char-spec (split-char char)))
493 (cond ((setq ret (get-char-attribute char 'name))
494 (setq char-spec (cons (cons 'name ret) char-spec))
496 ((setq ret (get-char-attribute char 'name*))
497 (setq char-spec (cons (cons 'name* ret) char-spec))
500 ((setq ret (get-char-attribute
501 char 'ideographic-combination))
503 (cons (cons 'ideographic-combination ret)
510 (defun char-db-insert-char-spec (char &optional readable column
513 (setq column (current-column)))
514 (let (char-spec temp-char)
515 (setq char-spec (char-db-make-char-spec char))
516 (unless (or (characterp char) ; char
518 (setq char (find-char char-spec))
520 ;; define temporary character
521 ;; Current implementation is dirty.
522 (setq temp-char (define-char (cons '(ideograph-daikanwa . 0)
524 (remove-char-attribute temp-char 'ideograph-daikanwa)
525 (setq char temp-char))
526 (insert-char-attributes char
528 (union (mapcar #'car char-spec)
532 ;; undefine temporary character
533 ;; Current implementation is dirty.
534 (setq char-spec (char-attribute-alist temp-char))
536 (remove-char-attribute temp-char (car (car char-spec)))
537 (setq char-spec (cdr char-spec))))))
539 (defun char-db-insert-alist (alist &optional readable column)
541 (setq column (current-column)))
543 (concat "\n" (make-string (1+ column) ?\ )))
547 lbs cell rest separator)
550 (setq name (car (car alist))
551 value (cdr (car alist)))
552 (cond ((eq name 'char)
554 (if (setq ret (condition-case nil
562 (setq key (car (car value)))
563 ;; (if (find-charset key)
564 ;; (setq cal (cons key cal))
565 (setq al (cons key al))
567 (setq value (cdr value)))
568 (insert-char-attributes ret
572 (insert (prin1-to-string value)))
574 (insert line-breaking))
576 (insert (format "(%-18s " name))
577 (setq lbs (concat "\n" (make-string (current-column) ?\ )))
579 (setq cell (car value))
580 (if (and (consp cell)
582 (setq ret (condition-case nil
592 (setq key (car (car rest)))
593 ;; (if (find-charset key)
594 ;; (setq cal (cons key cal))
595 (setq al (cons key al))
597 (setq rest (cdr rest)))
600 (insert-char-attributes ret
604 (setq separator lbs))
607 (insert (prin1-to-string cell))
608 (setq separator " "))
609 (setq value (cdr value)))
611 (insert line-breaking))
613 (insert (format "(%-18s . %S)%s"
616 (setq alist (cdr alist))))
619 (defun char-db-insert-char-reference (plist &optional readable column)
621 (setq column (current-column)))
623 (concat "\n" (make-string (1+ column) ?\ )))
628 (setq name (pop plist))
629 (setq value (pop plist))
630 (cond ((eq name :char)
633 (cond ((numberp value)
634 (setq value (decode-char '=ucs value)))
636 ;; (setq value (or (find-char value)
639 (char-db-insert-char-spec value readable)
640 (insert line-breaking)
643 (insert (format "%s%s\t%d ; %c%s"
646 (ideographic-radical value)
650 (insert (format "%s%s\t%S" separator name value))
651 (setq separator line-breaking)))
655 (defun char-db-decode-isolated-char (ccs code-point)
658 (cond ((eq ccs 'arabic-iso8859-6)
659 (decode-char ccs code-point))
661 ;; (decode-builtin-char '==gt code-point))
662 ((and (memq ccs '(=gt-pj-1
673 (setq ret (decode-char ccs code-point))
674 (setq ret (encode-char ret '=gt 'defined-only)))
675 (decode-builtin-char '=gt ret))
677 (decode-builtin-char ccs code-point))))
679 (or (decode-char ccs code-point)
680 (define-char (list (cons ccs code-point)))))
681 ((and (<= 0 (char-int ret))
682 (<= (char-int ret) #x1F))
683 (decode-char '=ucs (+ #x2400 (char-int ret))))
684 ((= (char-int ret) #x7F)
688 (defvar char-db-convert-obsolete-format t)
690 (defun char-db-insert-ccs-feature (name value line-breaking)
696 ((memq name '(=>iwds-1
699 =shinjigen@1ed ==shinjigen@1ed
700 =shinjigen@rev ==shinjigen@rev
701 =shinjigen/+p@rev ==shinjigen/+p@rev
702 ===daikanwa/ho ==daikanwa/ho
703 =daikanwa/ho =>>daikanwa/ho =>daikanwa/ho))
704 "(%-18s . %04d)\t; %c")
705 ((eq name '=shinjigen@1ed/24pr)
706 "(%-18s . %04d)\t; %c")
710 ==daikanwa =daikanwa =>>daikanwa =>daikanwa
711 =daikanwa@rev1 =daikanwa@rev2
712 =daikanwa/+p ==daikanwa/+p ===daikanwa/+p
714 =daikanwa/+2p =>>daikanwa/+2p
719 =adobe-japan1-0 ==adobe-japan1-0 ===adobe-japan1-0
720 =adobe-japan1-1 ==adobe-japan1-1 ===adobe-japan1-1
721 =adobe-japan1-2 ==adobe-japan1-2 ===adobe-japan1-2
722 =adobe-japan1-3 ==adobe-japan1-3 ===adobe-japan1-3
723 =adobe-japan1-4 ==adobe-japan1-4 ===adobe-japan1-4
724 =adobe-japan1-5 ==adobe-japan1-5 ===adobe-japan1-5
725 =adobe-japan1-6 ==adobe-japan1-6 ===adobe-japan1-6
726 =>>adobe-japan1-0 =+>adobe-japan1-0
727 =>>adobe-japan1-1 =+>adobe-japan1-1
728 =>>adobe-japan1-2 =+>adobe-japan1-2
729 =>>adobe-japan1-3 =+>adobe-japan1-3
730 =>>adobe-japan1-4 =+>adobe-japan1-4
731 =>>adobe-japan1-5 =+>adobe-japan1-5
732 =>>adobe-japan1-6 =+>adobe-japan1-6
733 =>cbeta =cbeta =>>cbeta ==cbeta ===cbeta
734 =zinbun-oracle =>zinbun-oracle
735 ===hng-jou ===hng-keg ===hng-dng ===hng-mam
736 ===hng-drt ===hng-kgk ===hng-myz ===hng-kda
737 ===hng-khi ===hng-khm ===hng-hok ===hng-kyd ===hng-sok
738 ===hng-yhk ===hng-kak ===hng-kar ===hng-kae
739 ===hng-sys ===hng-tsu ===hng-tzj
740 ===hng-hos ===hng-nak ===hng-jhk
741 ===hng-hod ===hng-gok ===hng-ink ===hng-nto
742 ===hng-nkm ===hng-k24 ===hng-nkk
743 ===hng-kcc ===hng-kcj ===hng-kbk ===hng-sik
744 ===hng-skk ===hng-kyu ===hng-ksk ===hng-wan
745 ===hng-okd ===hng-wad ===hng-kmi
746 ===hng-zkd ===hng-doh ===hng-jyu
747 ===hng-tzs ===hng-kss ===hng-kyo
749 ;; (string-match "^=adobe-" (symbol-name name))
751 "(%-18s . %05d)\t; %c")
752 ((memq name '(=hanyo-denshi/ks
753 ==hanyo-denshi/ks ===hanyo-denshi/ks
756 =mj ==mj ===mj =>>mj =>mj
758 "(%-18s . %06d)\t; %c")
759 ((memq name '(=hanyo-denshi/tk ==hanyo-denshi/tk))
760 "(%-18s . %08d)\t; %c")
761 ((>= (charset-dimension name) 2)
762 "(%-18s . #x%04X)\t; %c")
764 "(%-18s . #x%02X)\t; %c"))
766 (if (= (charset-iso-graphic-plane name) 1)
768 (cond ((= (charset-dimension name) 1)
770 ((= (charset-dimension name) 2)
772 ((= (charset-dimension name) 3)
776 (char-db-decode-isolated-char name value)))
777 (if (and (= (charset-chars name) 94)
778 (= (charset-dimension name) 2))
779 (insert (format " [%02d-%02d]"
780 (- (lsh value -8) 32)
781 (- (logand value 255) 32))))
784 (insert (format "(%-18s . %s)" name value))
786 (insert line-breaking))
788 (defun char-db-insert-relation-feature (char name value line-breaking
790 (insert (format "(%-18s%s " name line-breaking))
791 (let ((lbs (concat "\n" (make-string (current-column) ?\ )))
792 separator cell sources required-features
795 (setq cell (car value))
797 (setq cell (decode-char '=ucs cell)))
799 ((eq name '->subsumptive)
800 (when (or (not (some (lambda (atr)
801 (get-char-attribute cell atr))
802 char-db-ignored-attributes))
804 (encode-char cell ccs 'defined-only))
808 (let ((char-db-ignored-attributes
810 char-db-ignored-attributes)))
811 (insert-char-attributes cell readable nil nil 'for-sub-node))
812 (setq separator lbs))
817 char (intern (format "%s*sources" name))))
818 (setq required-features nil)
819 (dolist (source sources)
823 shinjigen shinjigen@1ed shinjigen@rev))
824 (setq required-features
825 (union required-features
837 =shinjigen/+p@rev))))
839 (setq required-features
840 (union required-features
845 ((find-charset (setq ret (intern (format "=%s" source))))
846 (setq required-features
847 (cons ret required-features)))
848 (t (setq required-features
849 (cons source required-features)))))
850 (cond ((string-match "@JP" (symbol-name name))
851 (setq required-features
852 (union required-features
860 ((string-match "@CN" (symbol-name name))
861 (setq required-features
862 (union required-features
869 (insert (format "%S" cell))
870 (char-db-insert-char-spec cell readable
873 (setq separator lbs))
877 (if (consp (car cell))
878 (char-db-insert-char-spec cell readable)
879 (char-db-insert-char-reference cell readable))
880 (setq separator lbs))
884 (insert (prin1-to-string cell))
885 (setq separator " ")))
886 (setq value (cdr value)))
888 (insert line-breaking)))
890 (defun insert-char-attributes (char &optional readable attributes column
893 (setq column (current-column)))
894 (let (name value ; has-long-ccs-name
898 (concat "\n" (make-string (1+ column) ?\ )))
899 lbs cell separator ret
901 dest-ccss ; sources required-features
906 (if (consp attributes)
908 (dolist (name attributes)
909 (unless (memq name char-db-ignored-attributes)
910 (if (find-charset name)
914 (dolist (name (char-attribute-list))
915 (unless (memq name char-db-ignored-attributes)
916 (if (find-charset name)
920 #'char-attribute-name<)))
922 (when (memq '<-subsumptive attributes)
923 (when (or readable (not for-sub-node))
924 (when (setq value (get-char-attribute char '<-subsumptive))
925 (char-db-insert-relation-feature char '<-subsumptive value
928 (setq attributes (delq '<-subsumptive attributes)))
929 (when (and (memq '<-denotational attributes)
930 (setq value (get-char-attribute char '<-denotational)))
931 (char-db-insert-relation-feature char '<-denotational value
934 (setq attributes (delq '<-denotational attributes)))
935 (when (and (memq '<-denotational@component attributes)
936 (setq value (get-char-attribute char '<-denotational@component)))
937 (char-db-insert-relation-feature char '<-denotational@component value
940 (setq attributes (delq '<-denotational@component attributes)))
941 (when (and (memq 'name attributes)
942 (setq value (get-char-attribute char 'name)))
944 (if (> (+ (current-column) (length value)) 48)
947 value line-breaking))
948 (setq attributes (delq 'name attributes))
950 (when (and (memq 'name* attributes)
951 (setq value (get-char-attribute char 'name*)))
953 (if (> (+ (current-column) (length value)) 48)
956 value line-breaking))
957 (setq attributes (delq 'name* attributes))
959 (when (and (memq 'script attributes)
960 (setq value (get-char-attribute char 'script)))
961 (insert (format "(script\t\t%s)%s"
962 (mapconcat (function prin1-to-string)
965 (setq attributes (delq 'script attributes))
967 (dolist (name '(=>ucs =>ucs*))
968 (when (and (memq name attributes)
969 (setq value (get-char-attribute char name)))
970 (insert (format "(%-18s . #x%04X)\t; %c%s"
971 name value (decode-char '=ucs value)
973 (setq attributes (delq name attributes))))
974 (dolist (name '(=>ucs@gb =>ucs@big5))
975 (when (and (memq name attributes)
976 (setq value (get-char-attribute char name)))
977 (insert (format "(%-18s . #x%04X)\t; %c%s"
982 (symbol-name name) 2)))
985 (setq attributes (delq name attributes))
987 ;; (dolist (name '(=>daikanwa))
988 ;; (when (and (memq name attributes)
989 ;; (setq value (get-char-attribute char name)))
991 ;; (if (integerp value)
992 ;; (format "(%-18s . %05d)\t; %c%s"
993 ;; name value (decode-char '=daikanwa value)
995 ;; (format "(%-18s %s)\t; %c%s"
997 ;; (mapconcat (function prin1-to-string)
999 ;; (char-representative-of-daikanwa char)
1001 ;; (setq attributes (delq name attributes))))
1002 (when (and (memq 'general-category attributes)
1003 (setq value (get-char-attribute char 'general-category)))
1005 "(general-category\t%s) ; %s%s"
1006 (mapconcat (lambda (cell)
1009 (cond ((rassoc value unidata-normative-category-alist)
1010 "Normative Category")
1011 ((rassoc value unidata-informative-category-alist)
1012 "Informative Category")
1014 "Unknown Category"))
1016 (setq attributes (delq 'general-category attributes))
1018 (when (and (memq 'bidi-category attributes)
1019 (setq value (get-char-attribute char 'bidi-category)))
1020 (insert (format "(bidi-category\t. %S)%s"
1023 (setq attributes (delq 'bidi-category attributes))
1025 (unless (or (not (memq 'mirrored attributes))
1026 (eq (setq value (get-char-attribute char 'mirrored 'empty))
1028 (insert (format "(mirrored\t\t. %S)%s"
1031 (setq attributes (delq 'mirrored attributes))
1034 ((and (memq 'decimal-digit-value attributes)
1035 (setq value (get-char-attribute char 'decimal-digit-value)))
1036 (insert (format "(decimal-digit-value . %S)%s"
1039 (setq attributes (delq 'decimal-digit-value attributes))
1040 (when (and (memq 'digit-value attributes)
1041 (setq value (get-char-attribute char 'digit-value)))
1042 (insert (format "(digit-value\t . %S)%s"
1045 (setq attributes (delq 'digit-value attributes))
1047 (when (and (memq 'numeric-value attributes)
1048 (setq value (get-char-attribute char 'numeric-value)))
1049 (insert (format "(numeric-value\t . %S)%s"
1052 (setq attributes (delq 'numeric-value attributes))
1056 (when (and (memq 'digit-value attributes)
1057 (setq value (get-char-attribute char 'digit-value)))
1058 (insert (format "(digit-value\t. %S)%s"
1061 (setq attributes (delq 'digit-value attributes))
1063 (when (and (memq 'numeric-value attributes)
1064 (setq value (get-char-attribute char 'numeric-value)))
1065 (insert (format "(numeric-value\t. %S)%s"
1068 (setq attributes (delq 'numeric-value attributes))
1070 (when (and (memq 'iso-10646-comment attributes)
1071 (setq value (get-char-attribute char 'iso-10646-comment)))
1072 (insert (format "(iso-10646-comment\t. %S)%s"
1075 (setq attributes (delq 'iso-10646-comment attributes))
1077 (when (and (memq 'morohashi-daikanwa attributes)
1078 (setq value (get-char-attribute char 'morohashi-daikanwa)))
1079 (insert (format "(morohashi-daikanwa\t%s)%s"
1080 (mapconcat (function prin1-to-string) value " ")
1082 (setq attributes (delq 'morohashi-daikanwa attributes))
1086 (when (and (memq 'ideographic-radical attributes)
1087 (setq value (get-char-attribute char 'ideographic-radical)))
1088 (setq radical value)
1089 (insert (format "(ideographic-radical . %S)\t; %c%s"
1091 (ideographic-radical radical)
1093 (setq attributes (delq 'ideographic-radical attributes))
1095 (when (and (memq 'shuowen-radical attributes)
1096 (setq value (get-char-attribute char 'shuowen-radical)))
1097 (insert (format "(shuowen-radical\t. %S)\t; %c%s"
1099 (shuowen-radical value)
1101 (setq attributes (delq 'shuowen-radical attributes))
1106 char-db-feature-domains
1108 (dolist (feature (char-attribute-list))
1109 (setq feature (symbol-name feature))
1111 "\\(radical\\|strokes\\)@\\([^@*]+\\)\\(\\*\\|$\\)"
1113 (setq domain (intern (match-string 2 feature)))
1114 (unless (memq domain dest)
1115 (setq dest (cons domain dest)))))
1116 (sort dest #'string<))))
1117 (setq key (intern (format "%s@%s" 'ideographic-radical domain)))
1118 (when (and (memq key attributes)
1119 (setq value (get-char-attribute char key)))
1120 (setq radical value)
1121 (insert (format "(%s . %S)\t; %c%s"
1124 (ideographic-radical radical)
1126 (setq attributes (delq key attributes))
1128 (setq key (intern (format "%s@%s" 'ideographic-strokes domain)))
1129 (when (and (memq key attributes)
1130 (setq value (get-char-attribute char key)))
1131 (setq strokes value)
1132 (insert (format "(%s . %S)%s"
1136 (setq attributes (delq key attributes))
1138 (setq key (intern (format "%s@%s" 'total-strokes domain)))
1139 (when (and (memq key attributes)
1140 (setq value (get-char-attribute char key)))
1141 (insert (format "(%s . %S)%s"
1145 (setq attributes (delq key attributes))
1147 (dolist (feature '(ideographic-radical
1150 (setq key (intern (format "%s@%s*sources" feature domain)))
1151 (when (and (memq key attributes)
1152 (setq value (get-char-attribute char key)))
1153 (insert (format "(%s%s" key line-breaking))
1154 (dolist (cell value)
1155 (insert (format " %s" cell)))
1157 (insert line-breaking)
1158 (setq attributes (delq key attributes))
1161 (when (and (memq 'ideographic-strokes attributes)
1162 (setq value (get-char-attribute char 'ideographic-strokes)))
1163 (setq strokes value)
1164 (insert (format "(ideographic-strokes . %S)%s"
1167 (setq attributes (delq 'ideographic-strokes attributes))
1169 (when (and (memq 'kangxi-radical attributes)
1170 (setq value (get-char-attribute char 'kangxi-radical)))
1171 (unless (eq value radical)
1172 (insert (format "(kangxi-radical\t . %S)\t; %c%s"
1174 (ideographic-radical value)
1177 (setq radical value)))
1178 (setq attributes (delq 'kangxi-radical attributes))
1180 (when (and (memq 'kangxi-strokes attributes)
1181 (setq value (get-char-attribute char 'kangxi-strokes)))
1182 (unless (eq value strokes)
1183 (insert (format "(kangxi-strokes\t . %S)%s"
1187 (setq strokes value)))
1188 (setq attributes (delq 'kangxi-strokes attributes))
1190 ;; (when (and (memq 'japanese-radical attributes)
1191 ;; (setq value (get-char-attribute char 'japanese-radical)))
1192 ;; (unless (eq value radical)
1193 ;; (insert (format "(japanese-radical\t . %S)\t; %c%s"
1195 ;; (ideographic-radical value)
1198 ;; (setq radical value)))
1199 ;; (setq attributes (delq 'japanese-radical attributes))
1201 (when (and (memq 'japanese-strokes attributes)
1202 (setq value (get-char-attribute char 'japanese-strokes)))
1203 (unless (eq value strokes)
1204 (insert (format "(japanese-strokes\t . %S)%s"
1208 (setq strokes value)))
1209 (setq attributes (delq 'japanese-strokes attributes))
1211 (when (and (memq 'cns-radical attributes)
1212 (setq value (get-char-attribute char 'cns-radical)))
1213 (insert (format "(cns-radical\t . %S)\t; %c%s"
1215 (ideographic-radical value)
1217 (setq attributes (delq 'cns-radical attributes))
1219 (when (and (memq 'cns-strokes attributes)
1220 (setq value (get-char-attribute char 'cns-strokes)))
1221 (unless (eq value strokes)
1222 (insert (format "(cns-strokes\t . %S)%s"
1226 (setq strokes value)))
1227 (setq attributes (delq 'cns-strokes attributes))
1229 ;; (when (and (memq 'shinjigen-1-radical attributes)
1230 ;; (setq value (get-char-attribute char 'shinjigen-1-radical)))
1231 ;; (unless (eq value radical)
1232 ;; (insert (format "(shinjigen-1-radical . %S)\t; %c%s"
1234 ;; (ideographic-radical value)
1237 ;; (setq radical value)))
1238 ;; (setq attributes (delq 'shinjigen-1-radical attributes))
1240 ;; (when (and (memq 'ideographic- attributes)
1241 ;; (setq value (get-char-attribute char 'ideographic-)))
1242 ;; (insert "(ideographic- ")
1243 ;; (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1245 ;; (while (consp value)
1246 ;; (setq cell (car value))
1247 ;; (if (integerp cell)
1248 ;; (setq cell (decode-char '=ucs cell)))
1249 ;; (cond ((characterp cell)
1253 ;; (insert (format "%S" cell))
1254 ;; (char-db-insert-char-spec cell readable))
1255 ;; (setq separator lbs))
1259 ;; (if (consp (car cell))
1260 ;; (char-db-insert-char-spec cell readable)
1261 ;; (char-db-insert-char-reference cell readable))
1262 ;; (setq separator lbs))
1265 ;; (insert separator))
1266 ;; (insert (prin1-to-string cell))
1267 ;; (setq separator " ")))
1268 ;; (setq value (cdr value)))
1270 ;; (insert line-breaking)
1271 ;; (setq attributes (delq 'ideographic- attributes)))
1272 (when (and (memq 'total-strokes attributes)
1273 (setq value (get-char-attribute char 'total-strokes)))
1274 (insert (format "(total-strokes . %S)%s"
1277 (setq attributes (delq 'total-strokes attributes))
1279 ;; (when (and (memq '->ideograph attributes)
1280 ;; (setq value (get-char-attribute char '->ideograph)))
1281 ;; (insert (format "(->ideograph\t%s)%s"
1282 ;; (mapconcat (lambda (code)
1283 ;; (cond ((symbolp code)
1284 ;; (symbol-name code))
1286 ;; (format "#x%04X" code))
1289 ;; line-breaking code))))
1292 ;; (setq attributes (delq '->ideograph attributes))
1294 ;; (when (and (memq '->decomposition attributes)
1295 ;; (setq value (get-char-attribute char '->decomposition)))
1296 ;; (insert (format "(->decomposition\t%s)%s"
1297 ;; (mapconcat (lambda (code)
1298 ;; (cond ((symbolp code)
1299 ;; (symbol-name code))
1300 ;; ((characterp code)
1302 ;; (format "%S" code)
1307 ;; (format "#x%04X" code))
1309 ;; (format "%s%S" line-breaking code))))
1312 ;; (setq attributes (delq '->decomposition attributes))
1314 (if (equal (get-char-attribute char '->titlecase)
1315 (get-char-attribute char '->uppercase))
1316 (setq attributes (delq '->titlecase attributes)))
1317 (when (and (memq '->mojikyo attributes)
1318 (setq value (get-char-attribute char '->mojikyo)))
1319 (insert (format "(->mojikyo\t\t. %06d)\t; %c%s"
1320 value (decode-char 'mojikyo value)
1322 (setq attributes (delq '->mojikyo attributes))
1324 ;; (when (and (memq 'hanyu-dazidian-vol attributes)
1325 ;; (setq value (get-char-attribute char 'hanyu-dazidian-vol)))
1326 ;; (insert (format "(hanyu-dazidian-vol . %d)%s"
1327 ;; value line-breaking))
1328 ;; (setq attributes (delq 'hanyu-dazidian-vol attributes))
1330 ;; (when (and (memq 'hanyu-dazidian-page attributes)
1331 ;; (setq value (get-char-attribute char 'hanyu-dazidian-page)))
1332 ;; (insert (format "(hanyu-dazidian-page . %d)%s"
1333 ;; value line-breaking))
1334 ;; (setq attributes (delq 'hanyu-dazidian-page attributes))
1336 ;; (when (and (memq 'hanyu-dazidian-char attributes)
1337 ;; (setq value (get-char-attribute char 'hanyu-dazidian-char)))
1338 ;; (insert (format "(hanyu-dazidian-char . %d)%s"
1339 ;; value line-breaking))
1340 ;; (setq attributes (delq 'hanyu-dazidian-char attributes))
1343 (dolist (ignored '(composition
1344 ->denotational <-subsumptive ->ucs-unified
1345 ->ideographic-component-forms))
1346 (setq attributes (delq ignored attributes))))
1348 (setq name (car attributes))
1349 (unless (eq (setq value (get-char-attribute char name 'value-is-empty))
1351 (cond ((setq ret (find-charset name))
1352 (setq name (charset-name ret))
1353 (when (not (memq name dest-ccss))
1354 (setq dest-ccss (cons name dest-ccss))
1355 (char-db-insert-ccs-feature name value line-breaking))
1357 ((string-match "^=>ucs@" (symbol-name name))
1358 (insert (format "(%-18s . #x%04X)\t; %c%s"
1359 name value (decode-char '=ucs value)
1362 ((eq name 'jisx0208-1978/4X)
1363 (insert (format "(%-18s . #x%04X)%s"
1369 (not (eq name '->subsumptive))
1370 (not (eq name '->uppercase))
1371 (not (eq name '->lowercase))
1372 (not (eq name '->titlecase))
1373 (not (eq name '->canonical))
1374 (not (eq name '->Bopomofo))
1375 (not (eq name '->mistakable))
1376 (not (eq name '->ideographic-variants))
1377 (null (get-char-attribute
1378 char (intern (format "%s*sources" name))))
1379 (not (string-match "\\*sources$" (symbol-name name)))
1380 (null (get-char-attribute
1381 char (intern (format "%s*note" name))))
1382 (not (string-match "\\*note$" (symbol-name name)))
1383 (or (eq name '<-identical)
1384 (eq name '<-uppercase)
1385 (eq name '<-lowercase)
1386 (eq name '<-titlecase)
1387 (eq name '<-canonical)
1388 (eq name '<-ideographic-variants)
1389 ;; (eq name '<-synonyms)
1390 (string-match "^<-synonyms" (symbol-name name))
1391 (eq name '<-mistakable)
1392 (when (string-match "^->" (symbol-name name))
1394 ((string-match "^->fullwidth" (symbol-name name))
1395 (not (and (consp value)
1396 (characterp (car value))
1398 (car value) '=ucs 'defined-only)))
1403 ((or (eq name 'ideographic-structure)
1404 (eq name 'ideographic-combination)
1405 ;; (eq name 'ideographic-)
1406 (eq name '=decomposition)
1407 (char-feature-base-name= '=decomposition name)
1408 (char-feature-base-name= '=>decomposition name)
1409 ;; (string-match "^=>*decomposition\\(@[^*]+\\)?$"
1410 ;; (symbol-name name))
1411 (string-match "^\\(->\\|<-\\)[^*]*$" (symbol-name name))
1412 (string-match "^\\(->\\|<-\\)[^*]*\\*sources$"
1415 (char-db-insert-relation-feature char name value
1418 ;; ((memq name '(ideograph=
1419 ;; original-ideograph-of
1420 ;; ancient-ideograph-of
1421 ;; vulgar-ideograph-of
1422 ;; wrong-ideograph-of
1423 ;; ;; simplified-ideograph-of
1424 ;; ideographic-variants
1425 ;; ;; ideographic-different-form-of
1427 ;; (insert (format "(%-18s%s " name line-breaking))
1428 ;; (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1430 ;; (while (consp value)
1431 ;; (setq cell (car value))
1432 ;; (if (and (consp cell)
1433 ;; (consp (car cell)))
1437 ;; (char-db-insert-alist cell readable)
1438 ;; (setq separator lbs))
1440 ;; (insert separator))
1441 ;; (insert (prin1-to-string cell))
1442 ;; (setq separator " "))
1443 ;; (setq value (cdr value)))
1445 ;; (insert line-breaking))
1447 (insert (format "(%-18s " name))
1448 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1450 (while (consp value)
1451 (setq cell (car value))
1452 (if (and (consp cell)
1454 (setq ret (condition-case nil
1462 (setq key (car (car rest)))
1463 (if (find-charset key)
1464 (setq cal (cons key cal))
1465 (setq al (cons key al)))
1466 (setq rest (cdr rest)))
1469 (insert-char-attributes ret
1473 (setq separator lbs))
1474 (setq ret (prin1-to-string cell))
1476 (if (< (+ (current-column)
1483 (setq separator " "))
1484 (setq value (cdr value)))
1486 (insert line-breaking))
1488 (insert (format "(%-18s" name))
1489 (setq ret (prin1-to-string value))
1490 (unless (< (+ (current-column)
1494 (insert line-breaking))
1495 (insert " . " ret ")" line-breaking)
1496 ;; (insert (format "(%-18s . %S)%s"
1501 (setq attributes (cdr attributes)))
1504 (defun insert-char-data (char &optional readable
1507 (narrow-to-region (point)(point))
1508 (insert "(define-char
1510 (insert-char-attributes char readable attributes)
1512 (goto-char (point-min))
1513 (while (re-search-forward "[ \t]+$" nil t)
1516 (goto-char (point-min))
1517 (while (re-search-forward "[ \t][ \t][ \t]*" nil t)
1518 (let ((column (current-column))
1519 (indent-tabs-mode t))
1520 (delete-region (match-beginning 0) (point))
1521 (indent-to column)))
1522 (goto-char (point-max))
1523 ;; (tabify (point-min)(point-max))
1526 (defun insert-char-data-with-variant (char &optional printable
1528 script excluded-script)
1529 (insert-char-data char printable)
1530 (let ((variants (char-variants char))
1533 (setq variants (sort variants #'<))
1534 (setq rest variants)
1535 (setq variants (cons char variants))
1537 (setq variant (car rest))
1538 (unless (get-char-attribute variant '<-subsumptive)
1539 (if (and (or (null script)
1540 (null (setq vs (get-char-attribute variant 'script)))
1542 (or (null excluded-script)
1543 (null (setq vs (get-char-attribute variant 'script)))
1544 (not (memq excluded-script vs))))
1545 (unless (and no-ucs-unified (get-char-attribute variant '=ucs))
1546 (insert-char-data variant printable)
1547 (if (setq ret (char-variants variant))
1549 (or (memq (car ret) variants)
1550 ;; (get-char-attribute (car ret) '<-subsumptive)
1551 (setq rest (nconc rest (list (car ret)))))
1552 (setq ret (cdr ret)))))))
1553 (setq rest (cdr rest)))))
1555 (defun insert-char-range-data (min max &optional script excluded-script)
1558 (while (<= code max)
1559 (setq char (decode-char '=ucs code))
1560 (if (encode-char char '=ucs 'defined-only)
1561 (insert-char-data-with-variant char nil 'no-ucs-unified
1562 script excluded-script))
1563 (setq code (1+ code)))))
1565 (defun write-char-range-data-to-file (min max file
1566 &optional script excluded-script)
1567 (let ((coding-system-for-write char-db-file-coding-system))
1569 (insert (format ";; -*- coding: %s -*-\n"
1570 char-db-file-coding-system))
1571 (insert-char-range-data min max script excluded-script)
1572 (write-region (point-min)(point-max) file))))
1574 (defvar what-character-original-window-configuration)
1577 (defun what-char-definition (char)
1578 (interactive (list (char-after)))
1579 (let ((buf (get-buffer-create "*Character Description*"))
1580 (the-buf (current-buffer))
1581 (win-conf (current-window-configuration)))
1583 (make-local-variable 'what-character-original-window-configuration)
1584 (setq what-character-original-window-configuration win-conf)
1585 (setq buffer-read-only nil)
1589 (insert-char-data-with-variant char 'printable)
1590 (unless (char-attribute-alist char)
1591 (insert (format ";; = %c\n"
1592 (let* ((rest (split-char char))
1596 (setq code (logior (lsh code 8)
1598 (decode-char ccs code)))))
1599 ;; (char-db-update-comment)
1600 (set-buffer-modified-p nil)
1601 (view-mode the-buf (lambda (buf)
1602 (set-window-configuration
1603 what-character-original-window-configuration)
1605 (goto-char (point-min)))
1607 (set-window-configuration
1608 what-character-original-window-configuration)
1609 (signal (car err) (cdr err)))))))
1615 (provide 'char-db-util)
1617 ;;; char-db-util.el ends here