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
378 =>ucs-itaiji-001@iwds-1
388 ;;; @ char-db formatters
391 (defun char-db-make-char-spec (char)
393 (cond ((characterp char)
394 (cond ((and (setq ret (encode-char char '=ucs 'defined-only))
395 (not (and (<= #xE000 ret)(<= ret #xF8FF))))
396 (setq char-spec (list (cons '=ucs ret)))
397 (cond ((setq ret (get-char-attribute char 'name))
398 (setq char-spec (cons (cons 'name ret) char-spec))
400 ((setq ret (get-char-attribute char 'name*))
401 (setq char-spec (cons (cons 'name* ret) char-spec))
404 ((encode-char char '=mj 'defined-only)
406 (dolist (ccs (charset-list))
407 (if (and (or (eq ccs '=mj)
408 ;; (eq (charset-property ccs 'iso-ir) 177)
409 (string-match "=ucs@" (symbol-name ccs))
411 (setq ccs (charset-name ccs))
412 (null (assq ccs char-spec))
413 (setq ret (encode-char char ccs 'defined-only)))
414 (setq char-spec (cons (cons ccs ret) char-spec))))
416 ((encode-char char '==mj 'defined-only)
418 (dolist (ccs (charset-list))
419 (if (and (or (eq ccs '==mj)
420 ;; (eq (charset-property ccs 'iso-ir) 177)
421 (string-match "=ucs@" (symbol-name ccs))
423 (setq ccs (charset-name ccs))
424 (null (assq ccs char-spec))
425 (setq ret (encode-char char ccs 'defined-only)))
426 (setq char-spec (cons (cons ccs ret) char-spec))))
428 ((encode-char char '=adobe-japan1 'defined-only)
430 (dolist (ccs (charset-list))
431 (if (and (or (memq ccs
440 ;; (eq (charset-property ccs 'iso-ir) 177)
441 (string-match "=ucs@" (symbol-name ccs))
443 (setq ccs (charset-name ccs))
444 (null (assq ccs char-spec))
445 (setq ret (encode-char char ccs 'defined-only)))
446 (setq char-spec (cons (cons ccs ret) char-spec))))
448 ((encode-char char '==adobe-japan1 'defined-only)
450 (dolist (ccs (charset-list))
451 (if (and (or (memq ccs
460 ;; (eq (charset-property ccs 'iso-ir) 177)
461 (string-match "=ucs@" (symbol-name ccs))
463 (setq ccs (charset-name ccs))
464 (null (assq ccs char-spec))
465 (setq ret (encode-char char ccs 'defined-only)))
466 (setq char-spec (cons (cons ccs ret) char-spec))))
470 (let ((rest char-db-coded-charset-priority-list)
473 (setq ccs (charset-name
474 (find-charset (car rest))))
476 (encode-char char ccs
478 (throw 'tag (cons ccs ret)))
479 (setq rest (cdr rest))))))
480 (setq char-spec (list ret))
481 (dolist (ccs (delq (car ret) (charset-list)))
482 (if (and (or (charset-iso-final-char ccs)
489 (and (eq (charset-property ccs 'iso-ir) 177)
490 (not (eq (charset-name ccs) '=ucs@big5)))
491 ;; (string-match "=ucs@" (symbol-name ccs))
493 (setq ccs (charset-name ccs))
494 (null (assq ccs char-spec))
495 (setq ret (encode-char char ccs 'defined-only)))
496 (setq char-spec (cons (cons ccs ret) char-spec))))
498 (setq char-spec (split-char char)))
499 (cond ((setq ret (get-char-attribute char 'name))
500 (setq char-spec (cons (cons 'name ret) char-spec))
502 ((setq ret (get-char-attribute char 'name*))
503 (setq char-spec (cons (cons 'name* ret) char-spec))
506 ((setq ret (get-char-attribute
507 char 'ideographic-combination))
509 (cons (cons 'ideographic-combination ret)
516 (defun char-db-insert-char-spec (char &optional readable column
519 (setq column (current-column)))
520 (let (char-spec temp-char)
521 (setq char-spec (char-db-make-char-spec char))
522 (unless (or (characterp char) ; char
524 (setq char (find-char char-spec))
526 ;; define temporary character
527 ;; Current implementation is dirty.
528 (setq temp-char (define-char (cons '(ideograph-daikanwa . 0)
530 (remove-char-attribute temp-char 'ideograph-daikanwa)
531 (setq char temp-char))
532 (insert-char-attributes char
534 (union (mapcar #'car char-spec)
538 ;; undefine temporary character
539 ;; Current implementation is dirty.
540 (setq char-spec (char-attribute-alist temp-char))
542 (remove-char-attribute temp-char (car (car char-spec)))
543 (setq char-spec (cdr char-spec))))))
545 (defun char-db-insert-alist (alist &optional readable column)
547 (setq column (current-column)))
549 (concat "\n" (make-string (1+ column) ?\ )))
553 lbs cell rest separator)
556 (setq name (car (car alist))
557 value (cdr (car alist)))
558 (cond ((eq name 'char)
560 (if (setq ret (condition-case nil
568 (setq key (car (car value)))
569 ;; (if (find-charset key)
570 ;; (setq cal (cons key cal))
571 (setq al (cons key al))
573 (setq value (cdr value)))
574 (insert-char-attributes ret
578 (insert (prin1-to-string value)))
580 (insert line-breaking))
582 (insert (format "(%-18s " name))
583 (setq lbs (concat "\n" (make-string (current-column) ?\ )))
585 (setq cell (car value))
586 (if (and (consp cell)
588 (setq ret (condition-case nil
598 (setq key (car (car rest)))
599 ;; (if (find-charset key)
600 ;; (setq cal (cons key cal))
601 (setq al (cons key al))
603 (setq rest (cdr rest)))
606 (insert-char-attributes ret
610 (setq separator lbs))
613 (insert (prin1-to-string cell))
614 (setq separator " "))
615 (setq value (cdr value)))
617 (insert line-breaking))
619 (insert (format "(%-18s . %S)%s"
622 (setq alist (cdr alist))))
625 (defun char-db-insert-char-reference (plist &optional readable column)
627 (setq column (current-column)))
629 (concat "\n" (make-string (1+ column) ?\ )))
634 (setq name (pop plist))
635 (setq value (pop plist))
636 (cond ((eq name :char)
639 (cond ((numberp value)
640 (setq value (decode-char '=ucs value)))
642 ;; (setq value (or (find-char value)
645 (char-db-insert-char-spec value readable)
646 (insert line-breaking)
649 (insert (format "%s%s\t%d ; %c%s"
652 (ideographic-radical value)
656 (insert (format "%s%s\t%S" separator name value))
657 (setq separator line-breaking)))
661 (defun char-db-decode-isolated-char (ccs code-point)
664 (cond ((eq ccs 'arabic-iso8859-6)
665 (decode-char ccs code-point))
667 ;; (decode-builtin-char '==gt code-point))
668 ((and (memq ccs '(=gt-pj-1
679 (setq ret (decode-char ccs code-point))
680 (setq ret (encode-char ret '=gt 'defined-only)))
681 (decode-builtin-char '=gt ret))
683 (decode-builtin-char ccs code-point))))
685 (or (decode-char ccs code-point)
686 (define-char (list (cons ccs code-point)))))
687 ((and (<= 0 (char-int ret))
688 (<= (char-int ret) #x1F))
689 (decode-char '=ucs (+ #x2400 (char-int ret))))
690 ((= (char-int ret) #x7F)
694 (defvar char-db-convert-obsolete-format t)
696 (defun char-db-insert-ccs-feature (name value line-breaking)
702 ((memq name '(=>iwds-1
705 =shinjigen@1ed ==shinjigen@1ed
706 =shinjigen@rev ==shinjigen@rev
707 =shinjigen/+p@rev ==shinjigen/+p@rev
708 ===daikanwa/ho ==daikanwa/ho
709 =daikanwa/ho =>>daikanwa/ho =>daikanwa/ho))
710 "(%-18s . %04d)\t; %c")
711 ((eq name '=shinjigen@1ed/24pr)
712 "(%-18s . %04d)\t; %c")
716 ==daikanwa =daikanwa =>>daikanwa =>daikanwa
717 =daikanwa@rev1 =daikanwa@rev2
718 =daikanwa/+p ==daikanwa/+p ===daikanwa/+p
720 =daikanwa/+2p =>>daikanwa/+2p
725 =adobe-japan1-0 ==adobe-japan1-0 ===adobe-japan1-0
726 =adobe-japan1-1 ==adobe-japan1-1 ===adobe-japan1-1
727 =adobe-japan1-2 ==adobe-japan1-2 ===adobe-japan1-2
728 =adobe-japan1-3 ==adobe-japan1-3 ===adobe-japan1-3
729 =adobe-japan1-4 ==adobe-japan1-4 ===adobe-japan1-4
730 =adobe-japan1-5 ==adobe-japan1-5 ===adobe-japan1-5
731 =adobe-japan1-6 ==adobe-japan1-6 ===adobe-japan1-6
732 =>>adobe-japan1-0 =+>adobe-japan1-0
733 =>>adobe-japan1-1 =+>adobe-japan1-1
734 =>>adobe-japan1-2 =+>adobe-japan1-2
735 =>>adobe-japan1-3 =+>adobe-japan1-3
736 =>>adobe-japan1-4 =+>adobe-japan1-4
737 =>>adobe-japan1-5 =+>adobe-japan1-5
738 =>>adobe-japan1-6 =+>adobe-japan1-6
739 =>cbeta =cbeta =>>cbeta ==cbeta ===cbeta
740 =zinbun-oracle =>zinbun-oracle
741 =daijiten ==daijiten ===daijiten ==>daijiten
742 ===hng-jou ===hng-keg ===hng-dng ===hng-mam
743 ===hng-drt ===hng-kgk ===hng-myz ===hng-kda
744 ===hng-khi ===hng-khm ===hng-fhs ===hng-hok
745 ===hng-kyd ===hng-sok
746 ===hng-yhk ===hng-kak ===hng-kar ===hng-kae
747 ===hng-sys ===hng-tsu ===hng-tzj
748 ===hng-hos ===hng-kkh ===hng-nak ===hng-jhk
749 ===hng-hod ===hng-gok ===hng-ink ===hng-nto
750 ===hng-nkm ===hng-k24 ===hng-ini ===hng-nkk
751 ===hng-kcc ===hng-kcj ===hng-kbk ===hng-sik
752 ===hng-skk ===hng-kyu ===hng-ksk ===hng-wan
753 ===hng-okd ===hng-wad ===hng-kmi
754 ===hng-zkd ===hng-doh ===hng-jyu ===hng-tzs
755 ===hng-sai ===hng-kad ===hng-kss
756 ===hng-kyo ===hng-ykk ===hng-saa
757 ===hng-sab ===hng-wks ===hng-wke ===hng-smk
758 ===hng-sgs ===hng-sts
759 =shuowen-jiguge ===shuowen-jiguge4 ===shuowen-jiguge5))
760 ;; (string-match "^=adobe-" (symbol-name name))
762 "(%-18s . %05d)\t; %c")
763 ((memq name '(=hanyo-denshi/ks
764 ==hanyo-denshi/ks ===hanyo-denshi/ks
767 =mj ==mj ===mj =>>mj =>mj
769 "(%-18s . %06d)\t; %c")
770 ((memq name '(=hanyo-denshi/tk ==hanyo-denshi/tk))
771 "(%-18s . %08d)\t; %c")
772 ((>= (charset-dimension name) 2)
773 "(%-18s . #x%04X)\t; %c")
775 "(%-18s . #x%02X)\t; %c"))
777 (if (= (charset-iso-graphic-plane name) 1)
779 (cond ((= (charset-dimension name) 1)
781 ((= (charset-dimension name) 2)
783 ((= (charset-dimension name) 3)
787 (char-db-decode-isolated-char name value)))
788 (if (and (= (charset-chars name) 94)
789 (= (charset-dimension name) 2))
790 (insert (format " [%02d-%02d]"
791 (- (lsh value -8) 32)
792 (- (logand value 255) 32))))
795 (insert (format "(%-18s . %s)" name value))
797 (insert line-breaking))
799 (defun char-db-insert-relation-feature (char name value line-breaking
801 (insert (format "(%-18s%s " name line-breaking))
802 (let ((lbs (concat "\n" (make-string (current-column) ?\ )))
803 separator cell sources required-features
806 (setq cell (car value))
808 (setq cell (decode-char '=ucs cell)))
810 ((eq name '->subsumptive)
811 (when (or (not (some (lambda (atr)
812 (get-char-attribute cell atr))
813 char-db-ignored-attributes))
815 (encode-char cell ccs 'defined-only))
819 (let ((char-db-ignored-attributes
821 char-db-ignored-attributes)))
822 (insert-char-attributes cell readable nil nil 'for-sub-node))
823 (setq separator lbs))
828 char (intern (format "%s*sources" name))))
829 (setq required-features nil)
830 (dolist (source sources)
834 shinjigen shinjigen@1ed shinjigen@rev))
835 (setq required-features
836 (union required-features
848 =shinjigen/+p@rev))))
850 (setq required-features
851 (union required-features
856 ((find-charset (setq ret (intern (format "=%s" source))))
857 (setq required-features
858 (cons ret required-features)))
859 (t (setq required-features
860 (cons source required-features)))))
861 (cond ((string-match "@JP" (symbol-name name))
862 (setq required-features
863 (union required-features
871 ((string-match "@CN" (symbol-name name))
872 (setq required-features
873 (union required-features
880 (insert (format "%S" cell))
881 (char-db-insert-char-spec cell readable
884 (setq separator lbs))
888 (if (consp (car cell))
889 (char-db-insert-char-spec cell readable)
890 (char-db-insert-char-reference cell readable))
891 (setq separator lbs))
895 (insert (prin1-to-string cell))
896 (setq separator " ")))
897 (setq value (cdr value)))
899 (insert line-breaking)))
901 (defun insert-char-attributes (char &optional readable attributes column
904 (setq column (current-column)))
905 (let (name value ; has-long-ccs-name
909 (concat "\n" (make-string (1+ column) ?\ )))
910 lbs cell separator ret
912 dest-ccss ; sources required-features
917 (if (consp attributes)
919 (dolist (name attributes)
920 (unless (memq name char-db-ignored-attributes)
921 (if (find-charset name)
925 (dolist (name (char-attribute-list))
926 (unless (memq name char-db-ignored-attributes)
927 (if (find-charset name)
931 #'char-attribute-name<)))
933 (when (memq '<-subsumptive attributes)
934 (when (or readable (not for-sub-node))
935 (when (setq value (get-char-attribute char '<-subsumptive))
936 (char-db-insert-relation-feature char '<-subsumptive value
939 (setq attributes (delq '<-subsumptive attributes)))
940 (when (and (memq '<-denotational attributes)
941 (setq value (get-char-attribute char '<-denotational)))
942 (char-db-insert-relation-feature char '<-denotational value
945 (setq attributes (delq '<-denotational attributes)))
946 (when (and (memq '<-denotational@component attributes)
947 (setq value (get-char-attribute char '<-denotational@component)))
948 (char-db-insert-relation-feature char '<-denotational@component value
951 (setq attributes (delq '<-denotational@component attributes)))
952 (when (and (memq '<-denotational@usage attributes)
953 (setq value (get-char-attribute char '<-denotational@usage)))
954 (char-db-insert-relation-feature char '<-denotational@usage value
957 (setq attributes (delq '<-denotational@usage attributes)))
958 (when (and (memq 'name attributes)
959 (setq value (get-char-attribute char 'name)))
961 (if (> (+ (current-column) (length value)) 48)
964 value line-breaking))
965 (setq attributes (delq 'name attributes))
967 (when (and (memq 'name* attributes)
968 (setq value (get-char-attribute char 'name*)))
970 (if (> (+ (current-column) (length value)) 48)
973 value line-breaking))
974 (setq attributes (delq 'name* attributes))
976 (when (and (memq 'script attributes)
977 (setq value (get-char-attribute char 'script)))
978 (insert (format "(script\t\t%s)%s"
979 (mapconcat (function prin1-to-string)
982 (setq attributes (delq 'script attributes))
984 (dolist (name '(=>ucs =>ucs*))
985 (when (and (memq name attributes)
986 (setq value (get-char-attribute char name)))
987 (insert (format "(%-18s . #x%04X)\t; %c%s"
988 name value (decode-char '=ucs value)
990 (setq attributes (delq name attributes))))
991 (dolist (name '(=>ucs@gb =>ucs@big5))
992 (when (and (memq name attributes)
993 (setq value (get-char-attribute char name)))
994 (insert (format "(%-18s . #x%04X)\t; %c%s"
999 (symbol-name name) 2)))
1002 (setq attributes (delq name attributes))
1004 ;; (dolist (name '(=>daikanwa))
1005 ;; (when (and (memq name attributes)
1006 ;; (setq value (get-char-attribute char name)))
1008 ;; (if (integerp value)
1009 ;; (format "(%-18s . %05d)\t; %c%s"
1010 ;; name value (decode-char '=daikanwa value)
1012 ;; (format "(%-18s %s)\t; %c%s"
1014 ;; (mapconcat (function prin1-to-string)
1016 ;; (char-representative-of-daikanwa char)
1018 ;; (setq attributes (delq name attributes))))
1019 (when (and (memq 'general-category attributes)
1020 (setq value (get-char-attribute char 'general-category)))
1022 "(general-category\t%s) ; %s%s"
1023 (mapconcat (lambda (cell)
1026 (cond ((rassoc value unidata-normative-category-alist)
1027 "Normative Category")
1028 ((rassoc value unidata-informative-category-alist)
1029 "Informative Category")
1031 "Unknown Category"))
1033 (setq attributes (delq 'general-category attributes))
1035 (when (and (memq 'bidi-category attributes)
1036 (setq value (get-char-attribute char 'bidi-category)))
1037 (insert (format "(bidi-category\t. %S)%s"
1040 (setq attributes (delq 'bidi-category attributes))
1042 (unless (or (not (memq 'mirrored attributes))
1043 (eq (setq value (get-char-attribute char 'mirrored 'empty))
1045 (insert (format "(mirrored\t\t. %S)%s"
1048 (setq attributes (delq 'mirrored attributes))
1051 ((and (memq 'decimal-digit-value attributes)
1052 (setq value (get-char-attribute char 'decimal-digit-value)))
1053 (insert (format "(decimal-digit-value . %S)%s"
1056 (setq attributes (delq 'decimal-digit-value attributes))
1057 (when (and (memq 'digit-value attributes)
1058 (setq value (get-char-attribute char 'digit-value)))
1059 (insert (format "(digit-value\t . %S)%s"
1062 (setq attributes (delq 'digit-value attributes))
1064 (when (and (memq 'numeric-value attributes)
1065 (setq value (get-char-attribute char 'numeric-value)))
1066 (insert (format "(numeric-value\t . %S)%s"
1069 (setq attributes (delq 'numeric-value attributes))
1073 (when (and (memq 'digit-value attributes)
1074 (setq value (get-char-attribute char 'digit-value)))
1075 (insert (format "(digit-value\t. %S)%s"
1078 (setq attributes (delq 'digit-value attributes))
1080 (when (and (memq 'numeric-value attributes)
1081 (setq value (get-char-attribute char 'numeric-value)))
1082 (insert (format "(numeric-value\t. %S)%s"
1085 (setq attributes (delq 'numeric-value attributes))
1087 (when (and (memq 'iso-10646-comment attributes)
1088 (setq value (get-char-attribute char 'iso-10646-comment)))
1089 (insert (format "(iso-10646-comment\t. %S)%s"
1092 (setq attributes (delq 'iso-10646-comment attributes))
1094 (when (and (memq 'morohashi-daikanwa attributes)
1095 (setq value (get-char-attribute char 'morohashi-daikanwa)))
1096 (insert (format "(morohashi-daikanwa\t%s)%s"
1097 (mapconcat (function prin1-to-string) value " ")
1099 (setq attributes (delq 'morohashi-daikanwa attributes))
1103 (when (and (memq 'ideographic-radical attributes)
1104 (setq value (get-char-attribute char 'ideographic-radical)))
1105 (setq radical value)
1106 (insert (format "(ideographic-radical . %S)\t; %c%s"
1108 (ideographic-radical radical)
1110 (setq attributes (delq 'ideographic-radical attributes))
1112 (when (and (memq 'shuowen-radical attributes)
1113 (setq value (get-char-attribute char 'shuowen-radical)))
1114 (insert (format "(shuowen-radical\t. %S)\t; %c%s"
1116 (shuowen-radical value)
1118 (setq attributes (delq 'shuowen-radical attributes))
1123 char-db-feature-domains
1125 (dolist (feature (char-attribute-list))
1126 (setq feature (symbol-name feature))
1128 "\\(radical\\|strokes\\)@\\([^@*]+\\)\\(\\*\\|$\\)"
1130 (setq domain (intern (match-string 2 feature)))
1131 (unless (memq domain dest)
1132 (setq dest (cons domain dest)))))
1133 (sort dest #'string<))))
1134 (setq key (intern (format "%s@%s" 'ideographic-radical domain)))
1135 (when (and (memq key attributes)
1136 (setq value (get-char-attribute char key)))
1137 (setq radical value)
1138 (insert (format "(%s . %S)\t; %c%s"
1141 (ideographic-radical radical)
1143 (setq attributes (delq key attributes))
1145 (setq key (intern (format "%s@%s" 'ideographic-strokes domain)))
1146 (when (and (memq key attributes)
1147 (setq value (get-char-attribute char key)))
1148 (setq strokes value)
1149 (insert (format "(%s . %S)%s"
1153 (setq attributes (delq key attributes))
1155 (setq key (intern (format "%s@%s" 'total-strokes domain)))
1156 (when (and (memq key attributes)
1157 (setq value (get-char-attribute char key)))
1158 (insert (format "(%s . %S)%s"
1162 (setq attributes (delq key attributes))
1164 (dolist (feature '(ideographic-radical
1167 (setq key (intern (format "%s@%s*sources" feature domain)))
1168 (when (and (memq key attributes)
1169 (setq value (get-char-attribute char key)))
1170 (insert (format "(%s%s" key line-breaking))
1171 (dolist (cell value)
1172 (insert (format " %s" cell)))
1174 (insert line-breaking)
1175 (setq attributes (delq key attributes))
1178 (when (and (memq 'ideographic-strokes attributes)
1179 (setq value (get-char-attribute char 'ideographic-strokes)))
1180 (setq strokes value)
1181 (insert (format "(ideographic-strokes . %S)%s"
1184 (setq attributes (delq 'ideographic-strokes attributes))
1186 (when (and (memq 'kangxi-radical attributes)
1187 (setq value (get-char-attribute char 'kangxi-radical)))
1188 (unless (eq value radical)
1189 (insert (format "(kangxi-radical\t . %S)\t; %c%s"
1191 (ideographic-radical value)
1194 (setq radical value)))
1195 (setq attributes (delq 'kangxi-radical attributes))
1197 (when (and (memq 'kangxi-strokes attributes)
1198 (setq value (get-char-attribute char 'kangxi-strokes)))
1199 (unless (eq value strokes)
1200 (insert (format "(kangxi-strokes\t . %S)%s"
1204 (setq strokes value)))
1205 (setq attributes (delq 'kangxi-strokes attributes))
1207 ;; (when (and (memq 'japanese-radical attributes)
1208 ;; (setq value (get-char-attribute char 'japanese-radical)))
1209 ;; (unless (eq value radical)
1210 ;; (insert (format "(japanese-radical\t . %S)\t; %c%s"
1212 ;; (ideographic-radical value)
1215 ;; (setq radical value)))
1216 ;; (setq attributes (delq 'japanese-radical attributes))
1218 (when (and (memq 'japanese-strokes attributes)
1219 (setq value (get-char-attribute char 'japanese-strokes)))
1220 (unless (eq value strokes)
1221 (insert (format "(japanese-strokes\t . %S)%s"
1225 (setq strokes value)))
1226 (setq attributes (delq 'japanese-strokes attributes))
1228 (when (and (memq 'cns-radical attributes)
1229 (setq value (get-char-attribute char 'cns-radical)))
1230 (insert (format "(cns-radical\t . %S)\t; %c%s"
1232 (ideographic-radical value)
1234 (setq attributes (delq 'cns-radical attributes))
1236 (when (and (memq 'cns-strokes attributes)
1237 (setq value (get-char-attribute char 'cns-strokes)))
1238 (unless (eq value strokes)
1239 (insert (format "(cns-strokes\t . %S)%s"
1243 (setq strokes value)))
1244 (setq attributes (delq 'cns-strokes attributes))
1246 ;; (when (and (memq 'ideographic- attributes)
1247 ;; (setq value (get-char-attribute char 'ideographic-)))
1248 ;; (insert "(ideographic- ")
1249 ;; (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1251 ;; (while (consp value)
1252 ;; (setq cell (car value))
1253 ;; (if (integerp cell)
1254 ;; (setq cell (decode-char '=ucs cell)))
1255 ;; (cond ((characterp cell)
1259 ;; (insert (format "%S" cell))
1260 ;; (char-db-insert-char-spec cell readable))
1261 ;; (setq separator lbs))
1265 ;; (if (consp (car cell))
1266 ;; (char-db-insert-char-spec cell readable)
1267 ;; (char-db-insert-char-reference cell readable))
1268 ;; (setq separator lbs))
1271 ;; (insert separator))
1272 ;; (insert (prin1-to-string cell))
1273 ;; (setq separator " ")))
1274 ;; (setq value (cdr value)))
1276 ;; (insert line-breaking)
1277 ;; (setq attributes (delq 'ideographic- attributes)))
1278 (when (and (memq 'total-strokes attributes)
1279 (setq value (get-char-attribute char 'total-strokes)))
1280 (insert (format "(total-strokes . %S)%s"
1283 (setq attributes (delq 'total-strokes attributes))
1285 ;; (when (and (memq '->ideograph attributes)
1286 ;; (setq value (get-char-attribute char '->ideograph)))
1287 ;; (insert (format "(->ideograph\t%s)%s"
1288 ;; (mapconcat (lambda (code)
1289 ;; (cond ((symbolp code)
1290 ;; (symbol-name code))
1292 ;; (format "#x%04X" code))
1295 ;; line-breaking code))))
1298 ;; (setq attributes (delq '->ideograph attributes))
1300 ;; (when (and (memq '->decomposition attributes)
1301 ;; (setq value (get-char-attribute char '->decomposition)))
1302 ;; (insert (format "(->decomposition\t%s)%s"
1303 ;; (mapconcat (lambda (code)
1304 ;; (cond ((symbolp code)
1305 ;; (symbol-name code))
1306 ;; ((characterp code)
1308 ;; (format "%S" code)
1313 ;; (format "#x%04X" code))
1315 ;; (format "%s%S" line-breaking code))))
1318 ;; (setq attributes (delq '->decomposition attributes))
1320 (if (equal (get-char-attribute char '->titlecase)
1321 (get-char-attribute char '->uppercase))
1322 (setq attributes (delq '->titlecase attributes)))
1323 (when (and (memq '->mojikyo attributes)
1324 (setq value (get-char-attribute char '->mojikyo)))
1325 (insert (format "(->mojikyo\t\t. %06d)\t; %c%s"
1326 value (decode-char 'mojikyo value)
1328 (setq attributes (delq '->mojikyo attributes))
1331 (dolist (ignored '(composition
1332 ->denotational <-subsumptive ->ucs-unified
1333 ;; ->ideographic-component-forms
1335 (setq attributes (delq ignored attributes))))
1337 (setq name (car attributes))
1338 (unless (eq (setq value (get-char-attribute char name 'value-is-empty))
1340 (cond ((setq ret (find-charset name))
1341 (setq name (charset-name ret))
1342 (when (not (memq name dest-ccss))
1343 (setq dest-ccss (cons name dest-ccss))
1344 (char-db-insert-ccs-feature name value line-breaking))
1346 ((string-match "^=>ucs@" (symbol-name name))
1347 (insert (format "(%-18s . #x%04X)\t; %c%s"
1348 name value (decode-char '=ucs value)
1351 ((eq name 'jisx0208-1978/4X)
1352 (insert (format "(%-18s . #x%04X)%s"
1358 (not (eq name '->subsumptive))
1359 (not (eq name '->uppercase))
1360 (not (eq name '->lowercase))
1361 (not (eq name '->titlecase))
1362 (not (eq name '->canonical))
1363 (not (eq name '->Bopomofo))
1364 (not (eq name '->mistakable))
1365 (not (eq name '->ideographic-variants))
1366 (null (get-char-attribute
1367 char (intern (format "%s*sources" name))))
1368 (not (string-match "\\*sources$" (symbol-name name)))
1369 (null (get-char-attribute
1370 char (intern (format "%s*note" name))))
1371 (not (string-match "\\*note$" (symbol-name name)))
1372 (or (eq name '<-identical)
1373 (eq name '<-uppercase)
1374 (eq name '<-lowercase)
1375 (eq name '<-titlecase)
1376 (eq name '<-canonical)
1377 (eq name '<-ideographic-variants)
1378 ;; (eq name '<-synonyms)
1379 (string-match "^<-synonyms" (symbol-name name))
1380 (eq name '<-mistakable)
1381 (when (string-match "^->" (symbol-name name))
1383 ((string-match "^->fullwidth" (symbol-name name))
1384 (not (and (consp value)
1385 (characterp (car value))
1387 (car value) '=ucs 'defined-only)))
1392 ((or (eq name 'ideographic-structure)
1393 (eq name 'ideographic-combination)
1394 ;; (eq name 'ideographic-)
1395 (eq name '=decomposition)
1396 (char-feature-base-name= '=decomposition name)
1397 (char-feature-base-name= '=>decomposition name)
1398 ;; (string-match "^=>*decomposition\\(@[^*]+\\)?$"
1399 ;; (symbol-name name))
1400 (string-match "^\\(->\\|<-\\)[^*]*$" (symbol-name name))
1401 (string-match "^\\(->\\|<-\\)[^*]*\\*sources$"
1404 (char-db-insert-relation-feature char name value
1407 ;; ((memq name '(ideograph=
1408 ;; original-ideograph-of
1409 ;; ancient-ideograph-of
1410 ;; vulgar-ideograph-of
1411 ;; wrong-ideograph-of
1412 ;; ;; simplified-ideograph-of
1413 ;; ideographic-variants
1414 ;; ;; ideographic-different-form-of
1416 ;; (insert (format "(%-18s%s " name line-breaking))
1417 ;; (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1419 ;; (while (consp value)
1420 ;; (setq cell (car value))
1421 ;; (if (and (consp cell)
1422 ;; (consp (car cell)))
1426 ;; (char-db-insert-alist cell readable)
1427 ;; (setq separator lbs))
1429 ;; (insert separator))
1430 ;; (insert (prin1-to-string cell))
1431 ;; (setq separator " "))
1432 ;; (setq value (cdr value)))
1434 ;; (insert line-breaking))
1436 (insert (format "(%-18s " name))
1437 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1439 (while (consp value)
1440 (setq cell (car value))
1441 (if (and (consp cell)
1443 (setq ret (condition-case nil
1451 (setq key (car (car rest)))
1452 (if (find-charset key)
1453 (setq cal (cons key cal))
1454 (setq al (cons key al)))
1455 (setq rest (cdr rest)))
1458 (insert-char-attributes ret
1462 (setq separator lbs))
1463 (setq ret (prin1-to-string cell))
1465 (if (< (+ (current-column)
1472 (setq separator " "))
1473 (setq value (cdr value)))
1475 (insert line-breaking))
1477 (insert (format "(%-18s" name))
1478 (setq ret (prin1-to-string value))
1479 (unless (< (+ (current-column)
1483 (insert line-breaking))
1484 (insert " . " ret ")" line-breaking)
1485 ;; (insert (format "(%-18s . %S)%s"
1490 (setq attributes (cdr attributes)))
1493 (defun insert-char-data (char &optional readable
1496 (narrow-to-region (point)(point))
1497 (insert "(define-char
1499 (insert-char-attributes char readable attributes)
1501 (goto-char (point-min))
1502 (while (re-search-forward "[ \t]+$" nil t)
1505 (goto-char (point-min))
1506 (while (re-search-forward "[ \t][ \t][ \t]*" nil t)
1507 (let ((column (current-column))
1508 (indent-tabs-mode t))
1509 (delete-region (match-beginning 0) (point))
1510 (indent-to column)))
1511 (goto-char (point-max))
1512 ;; (tabify (point-min)(point-max))
1515 (defun insert-char-data-with-variant (char &optional printable
1517 script excluded-script)
1518 (insert-char-data char printable)
1519 (let ((variants (char-variants char))
1522 (setq variants (sort variants #'<))
1523 (setq rest variants)
1524 (setq variants (cons char variants))
1526 (setq variant (car rest))
1527 (unless (get-char-attribute variant '<-subsumptive)
1528 (if (and (or (null script)
1529 (null (setq vs (get-char-attribute variant 'script)))
1531 (or (null excluded-script)
1532 (null (setq vs (get-char-attribute variant 'script)))
1533 (not (memq excluded-script vs))))
1534 (unless (and no-ucs-unified (get-char-attribute variant '=ucs))
1535 (insert-char-data variant printable)
1536 (if (setq ret (char-variants variant))
1538 (or (memq (car ret) variants)
1539 ;; (get-char-attribute (car ret) '<-subsumptive)
1540 (setq rest (nconc rest (list (car ret)))))
1541 (setq ret (cdr ret)))))))
1542 (setq rest (cdr rest)))))
1544 (defun insert-char-range-data (min max &optional script excluded-script)
1547 (while (<= code max)
1548 (setq char (decode-char '=ucs code))
1549 (if (encode-char char '=ucs 'defined-only)
1550 (insert-char-data-with-variant char nil 'no-ucs-unified
1551 script excluded-script))
1552 (setq code (1+ code)))))
1554 (defun write-char-range-data-to-file (min max file
1555 &optional script excluded-script)
1556 (let ((coding-system-for-write char-db-file-coding-system))
1558 (insert (format ";; -*- coding: %s -*-\n"
1559 char-db-file-coding-system))
1560 (insert-char-range-data min max script excluded-script)
1561 (write-region (point-min)(point-max) file))))
1563 (defvar what-character-original-window-configuration)
1566 (defun what-char-definition (char)
1567 (interactive (list (char-after)))
1568 (let ((buf (get-buffer-create "*Character Description*"))
1569 (the-buf (current-buffer))
1570 (win-conf (current-window-configuration)))
1572 (make-local-variable 'what-character-original-window-configuration)
1573 (setq what-character-original-window-configuration win-conf)
1574 (setq buffer-read-only nil)
1578 (insert-char-data-with-variant char 'printable)
1579 (unless (char-attribute-alist char)
1580 (insert (format ";; = %c\n"
1581 (let* ((rest (split-char char))
1585 (setq code (logior (lsh code 8)
1587 (decode-char ccs code)))))
1588 ;; (char-db-update-comment)
1589 (set-buffer-modified-p nil)
1590 (view-mode the-buf (lambda (buf)
1591 (set-window-configuration
1592 what-character-original-window-configuration)
1594 (goto-char (point-min)))
1596 (set-window-configuration
1597 what-character-original-window-configuration)
1598 (signal (car err) (cdr err)))))))
1604 (provide 'char-db-util)
1606 ;;; char-db-util.el ends here