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,
5 ;; 2020, 2021, 2022, 2023 MORIOKA Tomohiko.
7 ;; Author: MORIOKA Tomohiko <tomo@kanji.zinbun.kyoto-u.ac.jp>
8 ;; Keywords: CHISE, Character Database, ISO/IEC 10646, UCS, Unicode, MULE.
10 ;; This file is part of XEmacs CHISE.
12 ;; XEmacs CHISE is free software; you can redistribute it and/or
13 ;; modify it under the terms of the GNU General Public License as
14 ;; published by the Free Software Foundation; either version 2, or (at
15 ;; your option) any later version.
17 ;; XEmacs CHISE is distributed in the hope that it will be useful,
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 ;; General Public License for more details.
22 ;; You should have received a copy of the GNU General Public License
23 ;; along with XEmacs CHISE; see the file COPYING. If not, write to
24 ;; the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
25 ;; Boston, MA 02111-1307, USA.
30 (require 'ideograph-subr)
32 (defconst unidata-normative-category-alist
33 '(("Lu" letter uppercase)
34 ("Ll" letter lowercase)
35 ("Lt" letter titlecase)
36 ("Mn" mark non-spacing)
37 ("Mc" mark spacing-combining)
39 ("Nd" number decimal-digit)
42 ("Zs" separator space)
44 ("Zp" separator paragraph)
47 ("Cs" other surrogate)
48 ("Co" other private-use)
49 ("Cn" other not-assigned)))
51 (defconst unidata-informative-category-alist
52 '(("Lm" letter modifier)
54 ("Pc" punctuation connector)
55 ("Pd" punctuation dash)
56 ("Ps" punctuation open)
57 ("Pe" punctuation close)
58 ("Pi" punctuation initial-quote)
59 ("Pf" punctuation final-quote)
60 ("Po" punctuation other)
62 ("Sc" symbol currency)
63 ("Sk" symbol modifier)
67 (defconst shuowen-radicals
68 [?一 ?上 ?示 ?三 ?王 ?玉 ?玨 ?气 ?士 ?丨 ; 010
69 ?屮 ?艸 ?蓐 ?茻 ?小 ?八 ?釆 ?半 ?牛 ?犛 ; 020
70 ?告 ?口 ?凵 ?吅 ?哭 ?走 ?止 ?癶 ?步 ?此 ; 030
71 ?正 ?是 ?辵 ?彳 ?廴 ?㢟 ?行 ?齒 ?牙 ?足 ; 040
72 ?疋 ?品 ?龠 ?冊 ?㗊 ?舌 ?干 ?𧮫 ?只 ?㕯 ; 050
73 ?句 ?丩 ?古 ?十 ?卅 ?言 ?誩 ?音 ?䇂 ?丵 ; 060
74 ?菐 ?𠬞 ?𠬜 ?共 ?異 ?舁 ?𦥑 ?䢅 ?爨 ?革 ; 070
75 ?鬲 ?䰜 ?爪 ?𠃨 ?鬥 ?又 ?𠂇 ?史 ?支 ?𦘒 ; 080
76 ?聿 ?畫 ?隶 ?臤 ?臣 ?殳 ?殺 ?𠘧 ?寸 ?皮 ; 090
77 ?㼱 ?攴 ?敎 ?卜 ?用 ?爻 ?㸚 ?𥄎 ?目 ?䀠 ; 100
78 ?眉 ?盾 ?自 ?白 ?鼻 ?皕 ?習 ?羽 ?隹 ?奞 ; 110
79 ?雈 ?𦫳 ?𥄕 ?羊 ?羴 ?瞿 ?雔 ?雥 ?鳥 ?烏 ; 120
80 ?𠦒 ?冓 ?幺 ?𢆶 ?叀 ?玄 ?予 ?放 ?𠬪 ?𣦼 ; 130
81 ?歺 ?死 ?冎 ?骨 ?肉 ?筋 ?刀 ?刃 ?㓞 ?丯 ; 140
82 ?耒 ?角 ?竹 ?箕 ?丌 ?左 ?工 ?㠭 ?巫 ?甘 ; 150
83 ?曰 ?乃 ?丂 ?可 ?兮 ?号 ?亏 ?旨 ?喜 ?壴 ; 160
84 ; ?旨 ?曰 ?乃 ?丂 ?可 ?兮 ?号 ?亏 ?喜 ?壴 ; 160
85 ?鼓 ?豈 ?豆 ?豊 ?豐 ?䖒 ?虍 ?虎 ?虤 ?皿 ; 170
86 ?𠙴 ?去 ?血 ?丶 ?丹 ?青 ?井 ?皀 ?鬯 ?食 ; 180
87 ?亼 ?會 ?倉 ?入 ?缶 ?矢 ?高 ?冂 ?𩫏 ?京 ; 190
88 ?亯 ?𣆪 ?畗 ?㐭 ?嗇 ?來 ?麥 ?夊 ?舛 ?䑞 ; 200
89 ?韋 ?弟 ?夂 ?久 ?桀 ?木 ?東 ?林 ?才 ?叒 ; 210
90 ?之 ?帀 ?出 ?𣎵 ?生 ?乇 ?𠂹 ?𠌶 ?華 ?𥝌 ; 220
91 ?稽 ?巢 ?桼 ?束 ?㯻 ?囗 ?員 ?貝 ?邑 ?𨛜 ; 230
92 ?日 ?旦 ?倝 ?㫃 ?冥 ?晶 ?月 ?有 ?明 ?囧 ; 240
93 ?夕 ?多 ?毌 ?𢎘 ?𣐺 ?卣 ?齊 ?朿 ?片 ?鼎 ; 250
94 ?克 ?彔 ?禾 ?秝 ?黍 ?香 ?米 ?毇 ?臼 ?凶 ; 260
95 ?𣎳 ?𣏟 ?麻 ?尗 ?耑 ?韭 ?瓜 ?瓠 ?宀 ?宮 ; 270
96 ?呂 ?穴 ?㝱 ?疒 ?冖 ?𠔼 ?冃 ?㒳 ?网 ?襾 ; 280
97 ?巾 ?巿 ?帛 ?白 ?㡀 ?黹 ?人 ?𠤎 ?匕 ?从 ; 290
98 ?比 ?北 ?丘 ?㐺 ?𡈼 ?重 ?臥 ?身 ?㐆 ?衣 ; 300
99 ?裘 ?老 ?毛 ?毳 ?尸 ?尺 ?尾 ?履 ?舟 ?方 ; 310
100 ?儿 ?兄 ?兂 ?皃 ?𠑹 ?先 ?秃 ?見 ?覞 ?欠 ; 320
101 ?㱃 ?㳄 ?旡 ?頁 ?𦣻 ?面 ?丏 ?首 ?𥄉 ?須 ; 330
102 ?彡 ?彣 ?文 ?髟 ?后 ?司 ?卮 ?卩 ?印 ?色 ; 340
103 ?𠨍 ?辟 ?勹 ?包 ?茍 ?鬼 ?甶 ?厶 ?嵬 ?山 ; 350
104 ?屾 ?屵 ?广 ?厂 ?丸 ?危 ?石 ?長 ?勿 ?冄 ; 360
105 ?而 ?豕 ?㣇 ?彑 ?豚 ?豸 ?𤉡 ?易 ?象 ?馬 ; 370
106 ?𢊁 ?鹿 ?麤 ?㲋 ?兔 ?萈 ?犬 ?㹜 ?鼠 ?能 ; 380
107 ?熊 ?火 ?炎 ?黑 ?囪 ?焱 ?炙 ?赤 ?大 ?亦 ; 390
108 ?夨 ?夭 ?交 ?尣 ?壺 ?壹 ?㚔 ?奢 ?亢 ?夲 ; 400
109 ?夰 ?亣 ?夫 ?立 ?竝 ?囟 ?思 ?心 ?惢 ?水 ; 410
110 ?沝 ?瀕 ?𡿨 ?巜 ?川 ?泉 ?灥 ?永 ?𠂢 ?谷 ; 420
111 ?仌 ?雨 ?雲 ?魚 ?𩺰 ?燕 ?龍 ?飛 ?非 ?卂 ; 430
112 ?𠃉 ?不 ?至 ?西 ?鹵 ?鹽 ?戶 ?門 ?耳 ?𦣝 ; 440
113 ?手 ?𠦬 ?女 ?毋 ?民 ?丿 ?𠂆 ?乁 ?氏 ?氐 ; 450
114 ?戈 ?戉 ?我 ?亅 ?琴 ?𠃊 ?亡 ?匸 ?匚 ?曲 ; 460
115 ?甾 ?瓦 ?弓 ?弜 ?弦 ?系 ?糸 ?素 ?絲 ?率 ; 470
116 ?虫 ?䖵 ?蟲 ?風 ?它 ?龜 ?黽 ?卵 ?二 ?土 ; 480
117 ?垚 ?堇 ?里 ?田 ?畕 ?黃 ?男 ?力 ?劦 ?金 ; 490
118 ?幵 ?勺 ?几 ?且 ?斤 ?斗 ?矛 ?車 ?𠂤 ?𨸏 ; 500
119 ?𨺅 ?厽 ?四 ?宁 ?叕 ?亞 ?五 ?六 ?七 ?九 ; 510
120 ?禸 ?嘼 ?甲 ?乙 ?丙 ?丁 ?戊 ?己 ?巴 ?庚 ; 520
121 ?辛 ?辡 ?壬 ?癸 ?子 ?了 ?孨 ?𠫓 ?丑 ?寅 ; 530
122 ?卯 ?辰 ?巳 ?午 ?未 ?申 ?酉 ?酋 ?戌 ?亥 ; 540
125 (defun shuowen-radical (number)
126 (aref shuowen-radicals (1- number)))
128 (defvar char-db-file-coding-system 'utf-8-mcs-er)
130 (defvar char-db-ignored-attributes '(ideographic-products))
132 (defvar char-db-coded-charset-priority-list
234 ;; =>>>adobe-japan1-0
235 ;; =>>>adobe-japan1-1
236 ;; =>>>adobe-japan1-2
237 ;; =>>>adobe-japan1-3
238 ;; =>>>adobe-japan1-4
239 ;; =>>>adobe-japan1-5
240 ;; =>>>adobe-japan1-6
244 ;; =>>>hanyo-denshi/ja
245 ;; =>>>hanyo-denshi/jb
246 ;; =>>>hanyo-denshi/jc
247 ;; =>>>hanyo-denshi/ft
248 ;; =>>>hanyo-denshi/ib
249 ;; =>>>hanyo-denshi/hg
250 ;; =>>>hanyo-denshi/jt
251 ;; =>>>hanyo-denshi/ks
292 ;; =>ucs@hanyo-denshi
413 =>big5-cdp-itaiji-001
414 =>big5-cdp-itaiji-002
415 =>big5-cdp-itaiji-003
416 =>big5-cdp-itaiji-004
417 =>big5-cdp-itaiji-005
418 =>big5-cdp-itaiji-006
423 =>ucs@iwds-1/normalized
424 =>ucs-itaiji-001@iwds-1
425 =>ucs-itaiji-002@iwds-1
426 =>ucs-itaiji-003@iwds-1
427 =>ucs-itaiji-006@iwds-1
440 ===chise-hdic-ktb-seal))
443 ;;; @ char-db formatters
446 (defun char-db-make-char-spec (char)
448 (cond ((characterp char)
449 (cond ((and (setq ret (encode-char char '=ucs 'defined-only))
450 (not (and (<= #xE000 ret)(<= ret #xF8FF))))
451 (setq char-spec (list (cons '=ucs ret)))
452 (cond ((setq ret (get-char-attribute char 'name))
453 (setq char-spec (cons (cons 'name ret) char-spec))
455 ((setq ret (get-char-attribute char 'name*))
456 (setq char-spec (cons (cons 'name* ret) char-spec))
459 ((encode-char char '=mj 'defined-only)
461 (dolist (ccs (charset-list))
462 (if (and (or (eq ccs '=mj)
463 ;; (eq (charset-property ccs 'iso-ir) 177)
464 (string-match "=ucs@" (symbol-name ccs))
466 (setq ccs (charset-name ccs))
467 (null (assq ccs char-spec))
468 (setq ret (encode-char char ccs 'defined-only)))
469 (setq char-spec (cons (cons ccs ret) char-spec))))
471 ((encode-char char '==mj 'defined-only)
473 (dolist (ccs (charset-list))
474 (if (and (or (eq ccs '==mj)
475 ;; (eq (charset-property ccs 'iso-ir) 177)
476 (string-match "=ucs@" (symbol-name ccs))
478 (setq ccs (charset-name ccs))
479 (null (assq ccs char-spec))
480 (setq ret (encode-char char ccs 'defined-only)))
481 (setq char-spec (cons (cons ccs ret) char-spec))))
483 ((encode-char char '=adobe-japan1 'defined-only)
485 (dolist (ccs (charset-list))
486 (if (and (or (memq ccs
495 ;; (eq (charset-property ccs 'iso-ir) 177)
496 (string-match "=ucs@" (symbol-name ccs))
498 (setq ccs (charset-name ccs))
499 (null (assq ccs char-spec))
500 (setq ret (encode-char char ccs 'defined-only)))
501 (setq char-spec (cons (cons ccs ret) char-spec))))
503 ((encode-char char '==adobe-japan1 'defined-only)
505 (dolist (ccs (charset-list))
506 (if (and (or (memq ccs
515 ;; (eq (charset-property ccs 'iso-ir) 177)
516 (string-match "=ucs@" (symbol-name ccs))
518 (setq ccs (charset-name ccs))
519 (null (assq ccs char-spec))
520 (setq ret (encode-char char ccs 'defined-only)))
521 (setq char-spec (cons (cons ccs ret) char-spec))))
525 (let ((rest char-db-coded-charset-priority-list)
528 (setq ccs (charset-name
529 (find-charset (car rest))))
531 (encode-char char ccs
533 (throw 'tag (cons ccs ret)))
534 (setq rest (cdr rest))))))
535 (setq char-spec (list ret))
536 (dolist (ccs (delq (car ret) (charset-list)))
537 (if (and (or (charset-iso-final-char ccs)
544 (and (eq (charset-property ccs 'iso-ir) 177)
545 (not (eq (charset-name ccs) '=ucs@big5)))
546 ;; (string-match "=ucs@" (symbol-name ccs))
548 (setq ccs (charset-name ccs))
549 (null (assq ccs char-spec))
550 (setq ret (encode-char char ccs 'defined-only)))
551 (setq char-spec (cons (cons ccs ret) char-spec))))
553 (setq char-spec (split-char char)))
554 (cond ((setq ret (get-char-attribute char 'name))
555 (setq char-spec (cons (cons 'name ret) char-spec))
557 ((setq ret (get-char-attribute char 'name*))
558 (setq char-spec (cons (cons 'name* ret) char-spec))
561 ((setq ret (get-char-attribute
562 char 'ideographic-combination))
564 (cons (cons 'ideographic-combination ret)
571 (defun char-db-insert-char-spec (char &optional readable column
574 (setq column (current-column)))
575 (let (char-spec temp-char)
576 (setq char-spec (char-db-make-char-spec char))
577 (unless (or (characterp char) ; char
579 (setq char (find-char char-spec))
581 ;; define temporary character
582 ;; Current implementation is dirty.
583 (setq temp-char (define-char (cons '(ideograph-daikanwa . 0)
585 (remove-char-attribute temp-char 'ideograph-daikanwa)
586 (setq char temp-char))
587 (insert-char-attributes char
589 (union (mapcar #'car char-spec)
593 ;; undefine temporary character
594 ;; Current implementation is dirty.
595 (setq char-spec (char-attribute-alist temp-char))
597 (remove-char-attribute temp-char (car (car char-spec)))
598 (setq char-spec (cdr char-spec))))))
600 (defun char-db-insert-alist (alist &optional readable column)
602 (setq column (current-column)))
604 (concat "\n" (make-string (1+ column) ?\ )))
608 lbs cell rest separator)
611 (setq name (car (car alist))
612 value (cdr (car alist)))
613 (cond ((eq name 'char)
615 (if (setq ret (condition-case nil
623 (setq key (car (car value)))
624 ;; (if (find-charset key)
625 ;; (setq cal (cons key cal))
626 (setq al (cons key al))
628 (setq value (cdr value)))
629 (insert-char-attributes ret
633 (insert (prin1-to-string value)))
635 (insert line-breaking))
637 (insert (format "(%-18s " name))
638 (setq lbs (concat "\n" (make-string (current-column) ?\ )))
640 (setq cell (car value))
641 (if (and (consp cell)
643 (setq ret (condition-case nil
653 (setq key (car (car rest)))
654 ;; (if (find-charset key)
655 ;; (setq cal (cons key cal))
656 (setq al (cons key al))
658 (setq rest (cdr rest)))
661 (insert-char-attributes ret
665 (setq separator lbs))
668 (insert (prin1-to-string cell))
669 (setq separator " "))
670 (setq value (cdr value)))
672 (insert line-breaking))
674 (insert (format "(%-18s . %S)%s"
677 (setq alist (cdr alist))))
680 (defun char-db-insert-char-reference (plist &optional readable column)
682 (setq column (current-column)))
684 (concat "\n" (make-string (1+ column) ?\ )))
689 (setq name (pop plist))
690 (setq value (pop plist))
691 (cond ((eq name :char)
694 (cond ((numberp value)
695 (setq value (decode-char '=ucs value)))
697 ;; (setq value (or (find-char value)
700 (char-db-insert-char-spec value readable)
701 (insert line-breaking)
704 (insert (format "%s%s\t%d ; %c%s"
707 (ideographic-radical value)
711 (insert (format "%s%s\t%S" separator name value))
712 (setq separator line-breaking)))
716 (defun char-db-decode-isolated-char (ccs code-point)
719 (cond ((eq ccs 'arabic-iso8859-6)
720 (decode-char ccs code-point))
722 ;; (decode-builtin-char '==gt code-point))
723 ((and (memq ccs '(=gt-pj-1
734 (setq ret (decode-char ccs code-point))
735 (setq ret (encode-char ret '=gt 'defined-only)))
736 (decode-builtin-char '=gt ret))
738 (decode-builtin-char ccs code-point))))
740 (or (decode-char ccs code-point)
741 (define-char (list (cons ccs code-point)))))
742 ((and (<= 0 (char-int ret))
743 (<= (char-int ret) #x1F))
744 (decode-char '=ucs (+ #x2400 (char-int ret))))
745 ((= (char-int ret) #x7F)
749 (defvar char-db-convert-obsolete-format t)
751 (defun char-db-insert-ccs-feature (name value line-breaking)
757 ((memq name '(=>iwds-1
760 =shinjigen@1ed ==shinjigen@1ed
761 =shinjigen@rev ==shinjigen@rev
762 =shinjigen/+p@rev ==shinjigen/+p@rev
763 ===daikanwa/ho ==daikanwa/ho
764 =daikanwa/ho =>>daikanwa/ho =>daikanwa/ho))
765 "(%-18s . %04d)\t; %c")
766 ((eq name '=shinjigen@1ed/24pr)
767 "(%-18s . %04d)\t; %c")
771 ==daikanwa =daikanwa =>>daikanwa =>daikanwa
772 =daikanwa@rev1 =daikanwa@rev2
773 =daikanwa/+p ==daikanwa/+p ===daikanwa/+p
775 =daikanwa/+2p =>>daikanwa/+2p
780 =adobe-japan1-0 ==adobe-japan1-0 ===adobe-japan1-0
781 =adobe-japan1-1 ==adobe-japan1-1 ===adobe-japan1-1
782 =adobe-japan1-2 ==adobe-japan1-2 ===adobe-japan1-2
783 =adobe-japan1-3 ==adobe-japan1-3 ===adobe-japan1-3
784 =adobe-japan1-4 ==adobe-japan1-4 ===adobe-japan1-4
785 =adobe-japan1-5 ==adobe-japan1-5 ===adobe-japan1-5
786 =adobe-japan1-6 ==adobe-japan1-6 ===adobe-japan1-6
787 =>>adobe-japan1-0 =+>adobe-japan1-0
788 =>>adobe-japan1-1 =+>adobe-japan1-1
789 =>>adobe-japan1-2 =+>adobe-japan1-2
790 =>>adobe-japan1-3 =+>adobe-japan1-3
791 =>>adobe-japan1-4 =+>adobe-japan1-4
792 =>>adobe-japan1-5 =+>adobe-japan1-5
793 =>>adobe-japan1-6 =+>adobe-japan1-6
794 =>cbeta =cbeta =>>cbeta ==cbeta ===cbeta
795 =zinbun-oracle =>zinbun-oracle
796 =daijiten ==daijiten ===daijiten ==>daijiten
797 ===hng-jou ===hng-keg ===hng-dng ===hng-mam
798 ===hng-drt ===hng-kgk ===hng-myz ===hng-kda
799 ===hng-khi ===hng-khm ===hng-fhs ===hng-hok
800 ===hng-kyd ===hng-sok
801 ===hng-yhk ===hng-kak ===hng-kar ===hng-kae
802 ===hng-sys ===hng-tsu ===hng-tzj
803 ===hng-hos ===hng-kkh ===hng-nak ===hng-jhk
804 ===hng-hod ===hng-gok ===hng-ink ===hng-nto
805 ===hng-nkm ===hng-k24 ===hng-ini ===hng-nkk
806 ===hng-kcc ===hng-kcj ===hng-kbk ===hng-sik
807 ===hng-skk ===hng-kyu ===hng-ksk ===hng-wan
808 ===hng-okd ===hng-wad ===hng-kmi
809 ===hng-zkd ===hng-doh ===hng-jyu ===hng-tzs
810 ===hng-sai ===hng-kad ===hng-kss
811 ===hng-kyo ===hng-ykk ===hng-saa
812 ===hng-sab ===hng-wks ===hng-wke ===hng-smk
813 ===hng-sgs ===hng-sts ===hng-kkd
814 =>shuowen-jiguge =shuowen-jiguge
815 ===shuowen-jiguge4 ===shuowen-jiguge5 ===shuowen-jiguge-A30))
816 ;; (string-match "^=adobe-" (symbol-name name))
818 "(%-18s . %05d)\t; %c")
819 ((memq name '(=hanyo-denshi/ks
820 ==hanyo-denshi/ks ===hanyo-denshi/ks
823 =mj ==mj ===mj =>>mj =>mj
825 "(%-18s . %06d)\t; %c")
826 ((memq name '(=hanyo-denshi/tk =>hanyo-denshi/tk ==hanyo-denshi/tk))
827 "(%-18s . %08d)\t; %c")
828 ((>= (charset-dimension name) 2)
829 "(%-18s . #x%04X)\t; %c")
831 "(%-18s . #x%02X)\t; %c"))
833 (if (= (charset-iso-graphic-plane name) 1)
835 (cond ((= (charset-dimension name) 1)
837 ((= (charset-dimension name) 2)
839 ((= (charset-dimension name) 3)
843 (char-db-decode-isolated-char name value)))
844 (if (and (= (charset-chars name) 94)
845 (= (charset-dimension name) 2))
846 (insert (format " [%02d-%02d]"
847 (- (lsh value -8) 32)
848 (- (logand value 255) 32))))
851 (insert (format "(%-18s . %s)" name value))
853 (insert line-breaking))
855 (defun char-db-insert-relation-feature (char name value line-breaking
857 (insert (format "(%-18s%s " name line-breaking))
858 (let ((lbs (concat "\n" (make-string (current-column) ?\ )))
859 separator cell sources required-features
862 (setq cell (car value))
864 (setq cell (decode-char '=ucs cell)))
866 ((eq name '->subsumptive)
867 (when (or (not (some (lambda (atr)
868 (get-char-attribute cell atr))
869 char-db-ignored-attributes))
871 (encode-char cell ccs 'defined-only))
875 (let ((char-db-ignored-attributes
877 char-db-ignored-attributes)))
878 (insert-char-attributes cell readable nil nil 'for-sub-node))
879 (setq separator lbs))
884 char (intern (format "%s*sources" name))))
885 (setq required-features nil)
886 (dolist (source sources)
890 shinjigen shinjigen@1ed shinjigen@rev))
891 (setq required-features
892 (union required-features
904 =shinjigen/+p@rev))))
906 (setq required-features
907 (union required-features
912 ((find-charset (setq ret (intern (format "=%s" source))))
913 (setq required-features
914 (cons ret required-features)))
915 (t (setq required-features
916 (cons source required-features)))))
917 (cond ((string-match "@JP" (symbol-name name))
918 (setq required-features
919 (union required-features
927 ((string-match "@CN" (symbol-name name))
928 (setq required-features
929 (union required-features
936 (insert (format "%S" cell))
937 (char-db-insert-char-spec cell readable
940 (setq separator lbs))
944 (if (consp (car cell))
945 (char-db-insert-char-spec cell readable)
946 (char-db-insert-char-reference cell readable))
947 (setq separator lbs))
951 (insert (prin1-to-string cell))
952 (setq separator " ")))
953 (setq value (cdr value)))
955 (insert line-breaking)))
957 (defun insert-char-attributes (char &optional readable attributes column
960 (setq column (current-column)))
961 (let (name value ; has-long-ccs-name
965 (concat "\n" (make-string (1+ column) ?\ )))
966 lbs cell separator ret
968 dest-ccss ; sources required-features
973 (if (consp attributes)
975 (dolist (name attributes)
976 (unless (memq name char-db-ignored-attributes)
977 (if (find-charset name)
981 (dolist (name (char-attribute-list))
982 (unless (memq name char-db-ignored-attributes)
983 (if (find-charset name)
987 #'char-attribute-name<)))
989 (when (memq '<-subsumptive attributes)
990 (when (or readable (not for-sub-node))
991 (when (setq value (get-char-attribute char '<-subsumptive))
992 (char-db-insert-relation-feature char '<-subsumptive value
995 (setq attributes (delq '<-subsumptive attributes)))
996 (when (and (memq '<-denotational attributes)
997 (setq value (get-char-attribute char '<-denotational)))
998 (char-db-insert-relation-feature char '<-denotational value
1001 (setq attributes (delq '<-denotational attributes)))
1002 (when (and (memq '<-denotational@component attributes)
1003 (setq value (get-char-attribute char '<-denotational@component)))
1004 (char-db-insert-relation-feature char '<-denotational@component value
1007 (setq attributes (delq '<-denotational@component attributes)))
1008 (when (and (memq '<-denotational@usage attributes)
1009 (setq value (get-char-attribute char '<-denotational@usage)))
1010 (char-db-insert-relation-feature char '<-denotational@usage value
1013 (setq attributes (delq '<-denotational@usage attributes)))
1014 (when (and (memq 'name attributes)
1015 (setq value (get-char-attribute char 'name)))
1017 (if (> (+ (current-column) (length value)) 48)
1020 value line-breaking))
1021 (setq attributes (delq 'name attributes))
1023 (when (and (memq 'name* attributes)
1024 (setq value (get-char-attribute char 'name*)))
1026 (if (> (+ (current-column) (length value)) 48)
1029 value line-breaking))
1030 (setq attributes (delq 'name* attributes))
1032 (when (and (memq 'script attributes)
1033 (setq value (get-char-attribute char 'script)))
1034 (insert (format "(script\t\t%s)%s"
1035 (mapconcat (function prin1-to-string)
1038 (setq attributes (delq 'script attributes))
1040 (dolist (name '(=>ucs =>ucs*))
1041 (when (and (memq name attributes)
1042 (setq value (get-char-attribute char name)))
1043 (insert (format "(%-18s . #x%04X)\t; %c%s"
1044 name value (decode-char '=ucs value)
1046 (setq attributes (delq name attributes))))
1047 (dolist (name '(=>ucs@gb =>ucs@big5))
1048 (when (and (memq name attributes)
1049 (setq value (get-char-attribute char name)))
1050 (insert (format "(%-18s . #x%04X)\t; %c%s"
1052 (decode-char (intern
1055 (symbol-name name) 2)))
1058 (setq attributes (delq name attributes))
1060 ;; (dolist (name '(=>daikanwa))
1061 ;; (when (and (memq name attributes)
1062 ;; (setq value (get-char-attribute char name)))
1064 ;; (if (integerp value)
1065 ;; (format "(%-18s . %05d)\t; %c%s"
1066 ;; name value (decode-char '=daikanwa value)
1068 ;; (format "(%-18s %s)\t; %c%s"
1070 ;; (mapconcat (function prin1-to-string)
1072 ;; (char-representative-of-daikanwa char)
1074 ;; (setq attributes (delq name attributes))))
1075 (when (and (memq 'general-category attributes)
1076 (setq value (get-char-attribute char 'general-category)))
1078 "(general-category\t%s) ; %s%s"
1079 (mapconcat (lambda (cell)
1082 (cond ((rassoc value unidata-normative-category-alist)
1083 "Normative Category")
1084 ((rassoc value unidata-informative-category-alist)
1085 "Informative Category")
1087 "Unknown Category"))
1089 (setq attributes (delq 'general-category attributes))
1091 (when (and (memq 'bidi-category attributes)
1092 (setq value (get-char-attribute char 'bidi-category)))
1093 (insert (format "(bidi-category\t. %S)%s"
1096 (setq attributes (delq 'bidi-category attributes))
1098 (unless (or (not (memq 'mirrored attributes))
1099 (eq (setq value (get-char-attribute char 'mirrored 'empty))
1101 (insert (format "(mirrored\t\t. %S)%s"
1104 (setq attributes (delq 'mirrored attributes))
1107 ((and (memq 'decimal-digit-value attributes)
1108 (setq value (get-char-attribute char 'decimal-digit-value)))
1109 (insert (format "(decimal-digit-value . %S)%s"
1112 (setq attributes (delq 'decimal-digit-value attributes))
1113 (when (and (memq 'digit-value attributes)
1114 (setq value (get-char-attribute char 'digit-value)))
1115 (insert (format "(digit-value\t . %S)%s"
1118 (setq attributes (delq 'digit-value attributes))
1120 (when (and (memq 'numeric-value attributes)
1121 (setq value (get-char-attribute char 'numeric-value)))
1122 (insert (format "(numeric-value\t . %S)%s"
1125 (setq attributes (delq 'numeric-value attributes))
1129 (when (and (memq 'digit-value attributes)
1130 (setq value (get-char-attribute char 'digit-value)))
1131 (insert (format "(digit-value\t. %S)%s"
1134 (setq attributes (delq 'digit-value attributes))
1136 (when (and (memq 'numeric-value attributes)
1137 (setq value (get-char-attribute char 'numeric-value)))
1138 (insert (format "(numeric-value\t. %S)%s"
1141 (setq attributes (delq 'numeric-value attributes))
1143 (when (and (memq 'iso-10646-comment attributes)
1144 (setq value (get-char-attribute char 'iso-10646-comment)))
1145 (insert (format "(iso-10646-comment\t. %S)%s"
1148 (setq attributes (delq 'iso-10646-comment attributes))
1150 (when (and (memq 'morohashi-daikanwa attributes)
1151 (setq value (get-char-attribute char 'morohashi-daikanwa)))
1152 (insert (format "(morohashi-daikanwa\t%s)%s"
1153 (mapconcat (function prin1-to-string) value " ")
1155 (setq attributes (delq 'morohashi-daikanwa attributes))
1159 (when (and (memq 'ideographic-radical attributes)
1160 (setq value (get-char-attribute char 'ideographic-radical)))
1161 (setq radical value)
1162 (insert (format "(ideographic-radical . %S)\t; %c%s"
1164 (ideographic-radical radical)
1166 (setq attributes (delq 'ideographic-radical attributes))
1168 (when (and (memq 'shuowen-radical attributes)
1169 (setq value (get-char-attribute char 'shuowen-radical)))
1170 (insert (format "(shuowen-radical\t. %S)\t; %c%s"
1172 (shuowen-radical value)
1174 (setq attributes (delq 'shuowen-radical attributes))
1179 char-db-feature-domains
1181 (dolist (feature (char-attribute-list))
1182 (setq feature (symbol-name feature))
1184 "\\(radical\\|strokes\\)@\\([^@*]+\\)\\(\\*\\|$\\)"
1186 (setq domain (intern (match-string 2 feature)))
1187 (unless (memq domain dest)
1188 (setq dest (cons domain dest)))))
1189 (sort dest #'string<))))
1190 (setq key (intern (format "%s@%s" 'ideographic-radical domain)))
1191 (when (and (memq key attributes)
1192 (setq value (get-char-attribute char key)))
1193 (setq radical value)
1194 (insert (format "(%s . %S)\t; %c%s"
1197 (ideographic-radical radical)
1199 (setq attributes (delq key attributes))
1201 (setq key (intern (format "%s@%s" 'ideographic-strokes domain)))
1202 (when (and (memq key attributes)
1203 (setq value (get-char-attribute char key)))
1204 (setq strokes value)
1205 (insert (format "(%s . %S)%s"
1209 (setq attributes (delq key attributes))
1211 (setq key (intern (format "%s@%s" 'total-strokes domain)))
1212 (when (and (memq key attributes)
1213 (setq value (get-char-attribute char key)))
1214 (insert (format "(%s . %S)%s"
1218 (setq attributes (delq key attributes))
1220 (dolist (feature '(ideographic-radical
1223 (setq key (intern (format "%s@%s*sources" feature domain)))
1224 (when (and (memq key attributes)
1225 (setq value (get-char-attribute char key)))
1226 (insert (format "(%s%s" key line-breaking))
1227 (dolist (cell value)
1228 (insert (format " %s" cell)))
1230 (insert line-breaking)
1231 (setq attributes (delq key attributes))
1234 (when (and (memq 'ideographic-strokes attributes)
1235 (setq value (get-char-attribute char 'ideographic-strokes)))
1236 (setq strokes value)
1237 (insert (format "(ideographic-strokes . %S)%s"
1240 (setq attributes (delq 'ideographic-strokes attributes))
1242 (when (and (memq 'kangxi-radical attributes)
1243 (setq value (get-char-attribute char 'kangxi-radical)))
1244 (unless (eq value radical)
1245 (insert (format "(kangxi-radical\t . %S)\t; %c%s"
1247 (ideographic-radical value)
1250 (setq radical value)))
1251 (setq attributes (delq 'kangxi-radical attributes))
1253 (when (and (memq 'kangxi-strokes attributes)
1254 (setq value (get-char-attribute char 'kangxi-strokes)))
1255 (unless (eq value strokes)
1256 (insert (format "(kangxi-strokes\t . %S)%s"
1260 (setq strokes value)))
1261 (setq attributes (delq 'kangxi-strokes attributes))
1263 ;; (when (and (memq 'japanese-radical attributes)
1264 ;; (setq value (get-char-attribute char 'japanese-radical)))
1265 ;; (unless (eq value radical)
1266 ;; (insert (format "(japanese-radical\t . %S)\t; %c%s"
1268 ;; (ideographic-radical value)
1271 ;; (setq radical value)))
1272 ;; (setq attributes (delq 'japanese-radical attributes))
1274 (when (and (memq 'japanese-strokes attributes)
1275 (setq value (get-char-attribute char 'japanese-strokes)))
1276 (unless (eq value strokes)
1277 (insert (format "(japanese-strokes\t . %S)%s"
1281 (setq strokes value)))
1282 (setq attributes (delq 'japanese-strokes attributes))
1284 (when (and (memq 'cns-radical attributes)
1285 (setq value (get-char-attribute char 'cns-radical)))
1286 (insert (format "(cns-radical\t . %S)\t; %c%s"
1288 (ideographic-radical value)
1290 (setq attributes (delq 'cns-radical attributes))
1292 (when (and (memq 'cns-strokes attributes)
1293 (setq value (get-char-attribute char 'cns-strokes)))
1294 (unless (eq value strokes)
1295 (insert (format "(cns-strokes\t . %S)%s"
1299 (setq strokes value)))
1300 (setq attributes (delq 'cns-strokes attributes))
1302 ;; (when (and (memq 'ideographic- attributes)
1303 ;; (setq value (get-char-attribute char 'ideographic-)))
1304 ;; (insert "(ideographic- ")
1305 ;; (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1307 ;; (while (consp value)
1308 ;; (setq cell (car value))
1309 ;; (if (integerp cell)
1310 ;; (setq cell (decode-char '=ucs cell)))
1311 ;; (cond ((characterp cell)
1315 ;; (insert (format "%S" cell))
1316 ;; (char-db-insert-char-spec cell readable))
1317 ;; (setq separator lbs))
1321 ;; (if (consp (car cell))
1322 ;; (char-db-insert-char-spec cell readable)
1323 ;; (char-db-insert-char-reference cell readable))
1324 ;; (setq separator lbs))
1327 ;; (insert separator))
1328 ;; (insert (prin1-to-string cell))
1329 ;; (setq separator " ")))
1330 ;; (setq value (cdr value)))
1332 ;; (insert line-breaking)
1333 ;; (setq attributes (delq 'ideographic- attributes)))
1334 (when (and (memq 'total-strokes attributes)
1335 (setq value (get-char-attribute char 'total-strokes)))
1336 (insert (format "(total-strokes . %S)%s"
1339 (setq attributes (delq 'total-strokes attributes))
1341 ;; (when (and (memq '->ideograph attributes)
1342 ;; (setq value (get-char-attribute char '->ideograph)))
1343 ;; (insert (format "(->ideograph\t%s)%s"
1344 ;; (mapconcat (lambda (code)
1345 ;; (cond ((symbolp code)
1346 ;; (symbol-name code))
1348 ;; (format "#x%04X" code))
1351 ;; line-breaking code))))
1354 ;; (setq attributes (delq '->ideograph attributes))
1356 ;; (when (and (memq '->decomposition attributes)
1357 ;; (setq value (get-char-attribute char '->decomposition)))
1358 ;; (insert (format "(->decomposition\t%s)%s"
1359 ;; (mapconcat (lambda (code)
1360 ;; (cond ((symbolp code)
1361 ;; (symbol-name code))
1362 ;; ((characterp code)
1364 ;; (format "%S" code)
1369 ;; (format "#x%04X" code))
1371 ;; (format "%s%S" line-breaking code))))
1374 ;; (setq attributes (delq '->decomposition attributes))
1376 (if (equal (get-char-attribute char '->titlecase)
1377 (get-char-attribute char '->uppercase))
1378 (setq attributes (delq '->titlecase attributes)))
1379 (when (and (memq '->mojikyo attributes)
1380 (setq value (get-char-attribute char '->mojikyo)))
1381 (insert (format "(->mojikyo\t\t. %06d)\t; %c%s"
1382 value (decode-char 'mojikyo value)
1384 (setq attributes (delq '->mojikyo attributes))
1387 (dolist (ignored '(composition
1388 ->denotational <-subsumptive ->ucs-unified
1389 ;; ->ideographic-component-forms
1391 (setq attributes (delq ignored attributes))))
1393 (setq name (car attributes))
1394 (unless (eq (setq value (get-char-attribute char name 'value-is-empty))
1396 (cond ((setq ret (find-charset name))
1397 (setq name (charset-name ret))
1398 (when (not (memq name dest-ccss))
1399 (setq dest-ccss (cons name dest-ccss))
1400 (char-db-insert-ccs-feature name value line-breaking))
1402 ((string-match "^=>ucs@" (symbol-name name))
1403 (insert (format "(%-18s . #x%04X)\t; %c%s"
1404 name value (decode-char '=ucs value)
1407 ((eq name 'jisx0208-1978/4X)
1408 (insert (format "(%-18s . #x%04X)%s"
1414 (not (eq name '->subsumptive))
1415 (not (eq name '->uppercase))
1416 (not (eq name '->lowercase))
1417 (not (eq name '->titlecase))
1418 (not (eq name '->canonical))
1419 (not (eq name '->Bopomofo))
1420 (not (eq name '->mistakable))
1421 (not (eq name '->ideographic-variants))
1422 (null (get-char-attribute
1423 char (intern (format "%s*sources" name))))
1424 (not (string-match "\\*sources$" (symbol-name name)))
1425 (null (get-char-attribute
1426 char (intern (format "%s*note" name))))
1427 (not (string-match "\\*note$" (symbol-name name)))
1428 (or (eq name '<-identical)
1429 (eq name '<-uppercase)
1430 (eq name '<-lowercase)
1431 (eq name '<-titlecase)
1432 (eq name '<-canonical)
1433 (eq name '<-ideographic-variants)
1434 ;; (eq name '<-synonyms)
1435 (string-match "^<-synonyms" (symbol-name name))
1436 (eq name '<-mistakable)
1437 (when (string-match "^->" (symbol-name name))
1439 ((string-match "^->fullwidth" (symbol-name name))
1440 (not (and (consp value)
1441 (characterp (car value))
1443 (car value) '=ucs 'defined-only)))
1448 ((or (eq name 'ideographic-structure)
1449 (eq name 'ideographic-structure@apparent)
1450 (eq name 'ideographic-structure@apparent/leftmost)
1451 (eq name 'ideographic-structure@apparent/rightmost)
1452 (eq name 'ideographic-combination)
1453 ;; (eq name 'ideographic-)
1454 (eq name '=decomposition)
1455 (char-feature-base-name= '=decomposition name)
1456 (char-feature-base-name= '=>decomposition name)
1457 ;; (string-match "^=>*decomposition\\(@[^*]+\\)?$"
1458 ;; (symbol-name name))
1459 (string-match "^\\(->\\|<-\\)[^*]*$" (symbol-name name))
1460 (string-match "^\\(->\\|<-\\)[^*]*\\*sources$"
1463 (char-db-insert-relation-feature char name value
1466 ;; ((memq name '(ideograph=
1467 ;; original-ideograph-of
1468 ;; ancient-ideograph-of
1469 ;; vulgar-ideograph-of
1470 ;; wrong-ideograph-of
1471 ;; ;; simplified-ideograph-of
1472 ;; ideographic-variants
1473 ;; ;; ideographic-different-form-of
1475 ;; (insert (format "(%-18s%s " name line-breaking))
1476 ;; (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1478 ;; (while (consp value)
1479 ;; (setq cell (car value))
1480 ;; (if (and (consp cell)
1481 ;; (consp (car cell)))
1485 ;; (char-db-insert-alist cell readable)
1486 ;; (setq separator lbs))
1488 ;; (insert separator))
1489 ;; (insert (prin1-to-string cell))
1490 ;; (setq separator " "))
1491 ;; (setq value (cdr value)))
1493 ;; (insert line-breaking))
1495 (insert (format "(%-18s " name))
1496 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1498 (while (consp value)
1499 (setq cell (car value))
1500 (if (and (consp cell)
1502 (setq ret (condition-case nil
1510 (setq key (car (car rest)))
1511 (if (find-charset key)
1512 (setq cal (cons key cal))
1513 (setq al (cons key al)))
1514 (setq rest (cdr rest)))
1517 (insert-char-attributes ret
1521 (setq separator lbs))
1522 (setq ret (prin1-to-string cell))
1524 (if (< (+ (current-column)
1531 (setq separator " "))
1532 (setq value (cdr value)))
1534 (insert line-breaking))
1536 (insert (format "(%-18s" name))
1537 (setq ret (prin1-to-string value))
1538 (unless (< (+ (current-column)
1542 (insert line-breaking))
1543 (insert " . " ret ")" line-breaking)
1544 ;; (insert (format "(%-18s . %S)%s"
1549 (setq attributes (cdr attributes)))
1552 (defun insert-char-data (char &optional readable
1555 (narrow-to-region (point)(point))
1556 (insert "(define-char
1558 (insert-char-attributes char readable attributes)
1560 (goto-char (point-min))
1561 (while (re-search-forward "[ \t]+$" nil t)
1564 (goto-char (point-min))
1565 (while (re-search-forward "[ \t][ \t][ \t]*" nil t)
1566 (let ((column (current-column))
1567 (indent-tabs-mode t))
1568 (delete-region (match-beginning 0) (point))
1569 (indent-to column)))
1570 (goto-char (point-max))
1571 ;; (tabify (point-min)(point-max))
1574 (defun insert-char-data-with-variant (char &optional printable
1576 script excluded-script)
1577 (insert-char-data char printable)
1578 (let ((variants (char-variants char))
1581 (setq variants (sort variants #'<))
1582 (setq rest variants)
1583 (setq variants (cons char variants))
1585 (setq variant (car rest))
1586 (unless (get-char-attribute variant '<-subsumptive)
1587 (if (and (or (null script)
1588 (null (setq vs (get-char-attribute variant 'script)))
1590 (or (null excluded-script)
1591 (null (setq vs (get-char-attribute variant 'script)))
1592 (not (memq excluded-script vs))))
1593 (unless (and no-ucs-unified (get-char-attribute variant '=ucs))
1594 (insert-char-data variant printable)
1595 (if (setq ret (char-variants variant))
1597 (or (memq (car ret) variants)
1598 ;; (get-char-attribute (car ret) '<-subsumptive)
1599 (setq rest (nconc rest (list (car ret)))))
1600 (setq ret (cdr ret)))))))
1601 (setq rest (cdr rest)))))
1603 (defun insert-char-range-data (min max &optional script excluded-script)
1606 (while (<= code max)
1607 (setq char (decode-char '=ucs code))
1608 (if (encode-char char '=ucs 'defined-only)
1609 (insert-char-data-with-variant char nil 'no-ucs-unified
1610 script excluded-script))
1611 (setq code (1+ code)))))
1613 (defun write-char-range-data-to-file (min max file
1614 &optional script excluded-script)
1615 (let ((coding-system-for-write char-db-file-coding-system))
1617 (insert (format ";; -*- coding: %s -*-\n"
1618 char-db-file-coding-system))
1619 (insert-char-range-data min max script excluded-script)
1620 (write-region (point-min)(point-max) file))))
1622 (defvar what-character-original-window-configuration)
1625 (defun what-char-definition (char)
1626 (interactive (list (char-after)))
1627 (let ((buf (get-buffer-create "*Character Description*"))
1628 (the-buf (current-buffer))
1629 (win-conf (current-window-configuration)))
1631 (make-local-variable 'what-character-original-window-configuration)
1632 (setq what-character-original-window-configuration win-conf)
1633 (setq buffer-read-only nil)
1637 (insert-char-data-with-variant char 'printable)
1638 (unless (char-attribute-alist char)
1639 (insert (format ";; = %c\n"
1640 (let* ((rest (split-char char))
1644 (setq code (logior (lsh code 8)
1646 (decode-char ccs code)))))
1647 ;; (char-db-update-comment)
1648 (set-buffer-modified-p nil)
1649 (view-mode the-buf (lambda (buf)
1650 (set-window-configuration
1651 what-character-original-window-configuration)
1653 (goto-char (point-min)))
1655 (set-window-configuration
1656 what-character-original-window-configuration)
1657 (signal (car err) (cdr err)))))))
1663 (provide 'char-db-util)
1665 ;;; char-db-util.el ends here