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
412 =>big5-cdp-itaiji-001
413 =>big5-cdp-itaiji-002
414 =>big5-cdp-itaiji-003
415 =>big5-cdp-itaiji-004
416 =>big5-cdp-itaiji-005
417 =>big5-cdp-itaiji-006
422 =>ucs@iwds-1/normalized
423 =>ucs-itaiji-001@iwds-1
424 =>ucs-itaiji-002@iwds-1
425 =>ucs-itaiji-003@iwds-1
426 =>ucs-itaiji-006@iwds-1
439 ===chise-hdic-ktb-seal))
442 ;;; @ char-db formatters
445 (defun char-db-make-char-spec (char)
447 (cond ((characterp char)
448 (cond ((and (setq ret (encode-char char '=ucs 'defined-only))
449 (not (and (<= #xE000 ret)(<= ret #xF8FF))))
450 (setq char-spec (list (cons '=ucs ret)))
451 (cond ((setq ret (get-char-attribute char 'name))
452 (setq char-spec (cons (cons 'name ret) char-spec))
454 ((setq ret (get-char-attribute char 'name*))
455 (setq char-spec (cons (cons 'name* ret) char-spec))
458 ((encode-char char '=mj 'defined-only)
460 (dolist (ccs (charset-list))
461 (if (and (or (eq ccs '=mj)
462 ;; (eq (charset-property ccs 'iso-ir) 177)
463 (string-match "=ucs@" (symbol-name ccs))
465 (setq ccs (charset-name ccs))
466 (null (assq ccs char-spec))
467 (setq ret (encode-char char ccs 'defined-only)))
468 (setq char-spec (cons (cons ccs ret) char-spec))))
470 ((encode-char char '==mj 'defined-only)
472 (dolist (ccs (charset-list))
473 (if (and (or (eq ccs '==mj)
474 ;; (eq (charset-property ccs 'iso-ir) 177)
475 (string-match "=ucs@" (symbol-name ccs))
477 (setq ccs (charset-name ccs))
478 (null (assq ccs char-spec))
479 (setq ret (encode-char char ccs 'defined-only)))
480 (setq char-spec (cons (cons ccs ret) char-spec))))
482 ((encode-char char '=adobe-japan1 'defined-only)
484 (dolist (ccs (charset-list))
485 (if (and (or (memq ccs
494 ;; (eq (charset-property ccs 'iso-ir) 177)
495 (string-match "=ucs@" (symbol-name ccs))
497 (setq ccs (charset-name ccs))
498 (null (assq ccs char-spec))
499 (setq ret (encode-char char ccs 'defined-only)))
500 (setq char-spec (cons (cons ccs ret) char-spec))))
502 ((encode-char char '==adobe-japan1 'defined-only)
504 (dolist (ccs (charset-list))
505 (if (and (or (memq ccs
514 ;; (eq (charset-property ccs 'iso-ir) 177)
515 (string-match "=ucs@" (symbol-name ccs))
517 (setq ccs (charset-name ccs))
518 (null (assq ccs char-spec))
519 (setq ret (encode-char char ccs 'defined-only)))
520 (setq char-spec (cons (cons ccs ret) char-spec))))
524 (let ((rest char-db-coded-charset-priority-list)
527 (setq ccs (charset-name
528 (find-charset (car rest))))
530 (encode-char char ccs
532 (throw 'tag (cons ccs ret)))
533 (setq rest (cdr rest))))))
534 (setq char-spec (list ret))
535 (dolist (ccs (delq (car ret) (charset-list)))
536 (if (and (or (charset-iso-final-char ccs)
543 (and (eq (charset-property ccs 'iso-ir) 177)
544 (not (eq (charset-name ccs) '=ucs@big5)))
545 ;; (string-match "=ucs@" (symbol-name ccs))
547 (setq ccs (charset-name ccs))
548 (null (assq ccs char-spec))
549 (setq ret (encode-char char ccs 'defined-only)))
550 (setq char-spec (cons (cons ccs ret) char-spec))))
552 (setq char-spec (split-char char)))
553 (cond ((setq ret (get-char-attribute char 'name))
554 (setq char-spec (cons (cons 'name ret) char-spec))
556 ((setq ret (get-char-attribute char 'name*))
557 (setq char-spec (cons (cons 'name* ret) char-spec))
560 ((setq ret (get-char-attribute
561 char 'ideographic-combination))
563 (cons (cons 'ideographic-combination ret)
570 (defun char-db-insert-char-spec (char &optional readable column
573 (setq column (current-column)))
574 (let (char-spec temp-char)
575 (setq char-spec (char-db-make-char-spec char))
576 (unless (or (characterp char) ; char
578 (setq char (find-char char-spec))
580 ;; define temporary character
581 ;; Current implementation is dirty.
582 (setq temp-char (define-char (cons '(ideograph-daikanwa . 0)
584 (remove-char-attribute temp-char 'ideograph-daikanwa)
585 (setq char temp-char))
586 (insert-char-attributes char
588 (union (mapcar #'car char-spec)
592 ;; undefine temporary character
593 ;; Current implementation is dirty.
594 (setq char-spec (char-attribute-alist temp-char))
596 (remove-char-attribute temp-char (car (car char-spec)))
597 (setq char-spec (cdr char-spec))))))
599 (defun char-db-insert-alist (alist &optional readable column)
601 (setq column (current-column)))
603 (concat "\n" (make-string (1+ column) ?\ )))
607 lbs cell rest separator)
610 (setq name (car (car alist))
611 value (cdr (car alist)))
612 (cond ((eq name 'char)
614 (if (setq ret (condition-case nil
622 (setq key (car (car value)))
623 ;; (if (find-charset key)
624 ;; (setq cal (cons key cal))
625 (setq al (cons key al))
627 (setq value (cdr value)))
628 (insert-char-attributes ret
632 (insert (prin1-to-string value)))
634 (insert line-breaking))
636 (insert (format "(%-18s " name))
637 (setq lbs (concat "\n" (make-string (current-column) ?\ )))
639 (setq cell (car value))
640 (if (and (consp cell)
642 (setq ret (condition-case nil
652 (setq key (car (car rest)))
653 ;; (if (find-charset key)
654 ;; (setq cal (cons key cal))
655 (setq al (cons key al))
657 (setq rest (cdr rest)))
660 (insert-char-attributes ret
664 (setq separator lbs))
667 (insert (prin1-to-string cell))
668 (setq separator " "))
669 (setq value (cdr value)))
671 (insert line-breaking))
673 (insert (format "(%-18s . %S)%s"
676 (setq alist (cdr alist))))
679 (defun char-db-insert-char-reference (plist &optional readable column)
681 (setq column (current-column)))
683 (concat "\n" (make-string (1+ column) ?\ )))
688 (setq name (pop plist))
689 (setq value (pop plist))
690 (cond ((eq name :char)
693 (cond ((numberp value)
694 (setq value (decode-char '=ucs value)))
696 ;; (setq value (or (find-char value)
699 (char-db-insert-char-spec value readable)
700 (insert line-breaking)
703 (insert (format "%s%s\t%d ; %c%s"
706 (ideographic-radical value)
710 (insert (format "%s%s\t%S" separator name value))
711 (setq separator line-breaking)))
715 (defun char-db-decode-isolated-char (ccs code-point)
718 (cond ((eq ccs 'arabic-iso8859-6)
719 (decode-char ccs code-point))
721 ;; (decode-builtin-char '==gt code-point))
722 ((and (memq ccs '(=gt-pj-1
733 (setq ret (decode-char ccs code-point))
734 (setq ret (encode-char ret '=gt 'defined-only)))
735 (decode-builtin-char '=gt ret))
737 (decode-builtin-char ccs code-point))))
739 (or (decode-char ccs code-point)
740 (define-char (list (cons ccs code-point)))))
741 ((and (<= 0 (char-int ret))
742 (<= (char-int ret) #x1F))
743 (decode-char '=ucs (+ #x2400 (char-int ret))))
744 ((= (char-int ret) #x7F)
748 (defvar char-db-convert-obsolete-format t)
750 (defun char-db-insert-ccs-feature (name value line-breaking)
756 ((memq name '(=>iwds-1
759 =shinjigen@1ed ==shinjigen@1ed
760 =shinjigen@rev ==shinjigen@rev
761 =shinjigen/+p@rev ==shinjigen/+p@rev
762 ===daikanwa/ho ==daikanwa/ho
763 =daikanwa/ho =>>daikanwa/ho =>daikanwa/ho))
764 "(%-18s . %04d)\t; %c")
765 ((eq name '=shinjigen@1ed/24pr)
766 "(%-18s . %04d)\t; %c")
770 ==daikanwa =daikanwa =>>daikanwa =>daikanwa
771 =daikanwa@rev1 =daikanwa@rev2
772 =daikanwa/+p ==daikanwa/+p ===daikanwa/+p
774 =daikanwa/+2p =>>daikanwa/+2p
779 =adobe-japan1-0 ==adobe-japan1-0 ===adobe-japan1-0
780 =adobe-japan1-1 ==adobe-japan1-1 ===adobe-japan1-1
781 =adobe-japan1-2 ==adobe-japan1-2 ===adobe-japan1-2
782 =adobe-japan1-3 ==adobe-japan1-3 ===adobe-japan1-3
783 =adobe-japan1-4 ==adobe-japan1-4 ===adobe-japan1-4
784 =adobe-japan1-5 ==adobe-japan1-5 ===adobe-japan1-5
785 =adobe-japan1-6 ==adobe-japan1-6 ===adobe-japan1-6
786 =>>adobe-japan1-0 =+>adobe-japan1-0
787 =>>adobe-japan1-1 =+>adobe-japan1-1
788 =>>adobe-japan1-2 =+>adobe-japan1-2
789 =>>adobe-japan1-3 =+>adobe-japan1-3
790 =>>adobe-japan1-4 =+>adobe-japan1-4
791 =>>adobe-japan1-5 =+>adobe-japan1-5
792 =>>adobe-japan1-6 =+>adobe-japan1-6
793 =>cbeta =cbeta =>>cbeta ==cbeta ===cbeta
794 =zinbun-oracle =>zinbun-oracle
795 =daijiten ==daijiten ===daijiten ==>daijiten
796 ===hng-jou ===hng-keg ===hng-dng ===hng-mam
797 ===hng-drt ===hng-kgk ===hng-myz ===hng-kda
798 ===hng-khi ===hng-khm ===hng-fhs ===hng-hok
799 ===hng-kyd ===hng-sok
800 ===hng-yhk ===hng-kak ===hng-kar ===hng-kae
801 ===hng-sys ===hng-tsu ===hng-tzj
802 ===hng-hos ===hng-kkh ===hng-nak ===hng-jhk
803 ===hng-hod ===hng-gok ===hng-ink ===hng-nto
804 ===hng-nkm ===hng-k24 ===hng-ini ===hng-nkk
805 ===hng-kcc ===hng-kcj ===hng-kbk ===hng-sik
806 ===hng-skk ===hng-kyu ===hng-ksk ===hng-wan
807 ===hng-okd ===hng-wad ===hng-kmi
808 ===hng-zkd ===hng-doh ===hng-jyu ===hng-tzs
809 ===hng-sai ===hng-kad ===hng-kss
810 ===hng-kyo ===hng-ykk ===hng-saa
811 ===hng-sab ===hng-wks ===hng-wke ===hng-smk
812 ===hng-sgs ===hng-sts ===hng-kkd
813 =>shuowen-jiguge =shuowen-jiguge
814 ===shuowen-jiguge4 ===shuowen-jiguge5 ===shuowen-jiguge-A30))
815 ;; (string-match "^=adobe-" (symbol-name name))
817 "(%-18s . %05d)\t; %c")
818 ((memq name '(=hanyo-denshi/ks
819 ==hanyo-denshi/ks ===hanyo-denshi/ks
822 =mj ==mj ===mj =>>mj =>mj
824 "(%-18s . %06d)\t; %c")
825 ((memq name '(=hanyo-denshi/tk =>hanyo-denshi/tk ==hanyo-denshi/tk))
826 "(%-18s . %08d)\t; %c")
827 ((>= (charset-dimension name) 2)
828 "(%-18s . #x%04X)\t; %c")
830 "(%-18s . #x%02X)\t; %c"))
832 (if (= (charset-iso-graphic-plane name) 1)
834 (cond ((= (charset-dimension name) 1)
836 ((= (charset-dimension name) 2)
838 ((= (charset-dimension name) 3)
842 (char-db-decode-isolated-char name value)))
843 (if (and (= (charset-chars name) 94)
844 (= (charset-dimension name) 2))
845 (insert (format " [%02d-%02d]"
846 (- (lsh value -8) 32)
847 (- (logand value 255) 32))))
850 (insert (format "(%-18s . %s)" name value))
852 (insert line-breaking))
854 (defun char-db-insert-relation-feature (char name value line-breaking
856 (insert (format "(%-18s%s " name line-breaking))
857 (let ((lbs (concat "\n" (make-string (current-column) ?\ )))
858 separator cell sources required-features
861 (setq cell (car value))
863 (setq cell (decode-char '=ucs cell)))
865 ((eq name '->subsumptive)
866 (when (or (not (some (lambda (atr)
867 (get-char-attribute cell atr))
868 char-db-ignored-attributes))
870 (encode-char cell ccs 'defined-only))
874 (let ((char-db-ignored-attributes
876 char-db-ignored-attributes)))
877 (insert-char-attributes cell readable nil nil 'for-sub-node))
878 (setq separator lbs))
883 char (intern (format "%s*sources" name))))
884 (setq required-features nil)
885 (dolist (source sources)
889 shinjigen shinjigen@1ed shinjigen@rev))
890 (setq required-features
891 (union required-features
903 =shinjigen/+p@rev))))
905 (setq required-features
906 (union required-features
911 ((find-charset (setq ret (intern (format "=%s" source))))
912 (setq required-features
913 (cons ret required-features)))
914 (t (setq required-features
915 (cons source required-features)))))
916 (cond ((string-match "@JP" (symbol-name name))
917 (setq required-features
918 (union required-features
926 ((string-match "@CN" (symbol-name name))
927 (setq required-features
928 (union required-features
935 (insert (format "%S" cell))
936 (char-db-insert-char-spec cell readable
939 (setq separator lbs))
943 (if (consp (car cell))
944 (char-db-insert-char-spec cell readable)
945 (char-db-insert-char-reference cell readable))
946 (setq separator lbs))
950 (insert (prin1-to-string cell))
951 (setq separator " ")))
952 (setq value (cdr value)))
954 (insert line-breaking)))
956 (defun insert-char-attributes (char &optional readable attributes column
959 (setq column (current-column)))
960 (let (name value ; has-long-ccs-name
964 (concat "\n" (make-string (1+ column) ?\ )))
965 lbs cell separator ret
967 dest-ccss ; sources required-features
972 (if (consp attributes)
974 (dolist (name attributes)
975 (unless (memq name char-db-ignored-attributes)
976 (if (find-charset name)
980 (dolist (name (char-attribute-list))
981 (unless (memq name char-db-ignored-attributes)
982 (if (find-charset name)
986 #'char-attribute-name<)))
988 (when (memq '<-subsumptive attributes)
989 (when (or readable (not for-sub-node))
990 (when (setq value (get-char-attribute char '<-subsumptive))
991 (char-db-insert-relation-feature char '<-subsumptive value
994 (setq attributes (delq '<-subsumptive attributes)))
995 (when (and (memq '<-denotational attributes)
996 (setq value (get-char-attribute char '<-denotational)))
997 (char-db-insert-relation-feature char '<-denotational value
1000 (setq attributes (delq '<-denotational attributes)))
1001 (when (and (memq '<-denotational@component attributes)
1002 (setq value (get-char-attribute char '<-denotational@component)))
1003 (char-db-insert-relation-feature char '<-denotational@component value
1006 (setq attributes (delq '<-denotational@component attributes)))
1007 (when (and (memq '<-denotational@usage attributes)
1008 (setq value (get-char-attribute char '<-denotational@usage)))
1009 (char-db-insert-relation-feature char '<-denotational@usage value
1012 (setq attributes (delq '<-denotational@usage attributes)))
1013 (when (and (memq 'name attributes)
1014 (setq value (get-char-attribute char 'name)))
1016 (if (> (+ (current-column) (length value)) 48)
1019 value line-breaking))
1020 (setq attributes (delq 'name attributes))
1022 (when (and (memq 'name* attributes)
1023 (setq value (get-char-attribute char 'name*)))
1025 (if (> (+ (current-column) (length value)) 48)
1028 value line-breaking))
1029 (setq attributes (delq 'name* attributes))
1031 (when (and (memq 'script attributes)
1032 (setq value (get-char-attribute char 'script)))
1033 (insert (format "(script\t\t%s)%s"
1034 (mapconcat (function prin1-to-string)
1037 (setq attributes (delq 'script attributes))
1039 (dolist (name '(=>ucs =>ucs*))
1040 (when (and (memq name attributes)
1041 (setq value (get-char-attribute char name)))
1042 (insert (format "(%-18s . #x%04X)\t; %c%s"
1043 name value (decode-char '=ucs value)
1045 (setq attributes (delq name attributes))))
1046 (dolist (name '(=>ucs@gb =>ucs@big5))
1047 (when (and (memq name attributes)
1048 (setq value (get-char-attribute char name)))
1049 (insert (format "(%-18s . #x%04X)\t; %c%s"
1051 (decode-char (intern
1054 (symbol-name name) 2)))
1057 (setq attributes (delq name attributes))
1059 ;; (dolist (name '(=>daikanwa))
1060 ;; (when (and (memq name attributes)
1061 ;; (setq value (get-char-attribute char name)))
1063 ;; (if (integerp value)
1064 ;; (format "(%-18s . %05d)\t; %c%s"
1065 ;; name value (decode-char '=daikanwa value)
1067 ;; (format "(%-18s %s)\t; %c%s"
1069 ;; (mapconcat (function prin1-to-string)
1071 ;; (char-representative-of-daikanwa char)
1073 ;; (setq attributes (delq name attributes))))
1074 (when (and (memq 'general-category attributes)
1075 (setq value (get-char-attribute char 'general-category)))
1077 "(general-category\t%s) ; %s%s"
1078 (mapconcat (lambda (cell)
1081 (cond ((rassoc value unidata-normative-category-alist)
1082 "Normative Category")
1083 ((rassoc value unidata-informative-category-alist)
1084 "Informative Category")
1086 "Unknown Category"))
1088 (setq attributes (delq 'general-category attributes))
1090 (when (and (memq 'bidi-category attributes)
1091 (setq value (get-char-attribute char 'bidi-category)))
1092 (insert (format "(bidi-category\t. %S)%s"
1095 (setq attributes (delq 'bidi-category attributes))
1097 (unless (or (not (memq 'mirrored attributes))
1098 (eq (setq value (get-char-attribute char 'mirrored 'empty))
1100 (insert (format "(mirrored\t\t. %S)%s"
1103 (setq attributes (delq 'mirrored attributes))
1106 ((and (memq 'decimal-digit-value attributes)
1107 (setq value (get-char-attribute char 'decimal-digit-value)))
1108 (insert (format "(decimal-digit-value . %S)%s"
1111 (setq attributes (delq 'decimal-digit-value attributes))
1112 (when (and (memq 'digit-value attributes)
1113 (setq value (get-char-attribute char 'digit-value)))
1114 (insert (format "(digit-value\t . %S)%s"
1117 (setq attributes (delq 'digit-value attributes))
1119 (when (and (memq 'numeric-value attributes)
1120 (setq value (get-char-attribute char 'numeric-value)))
1121 (insert (format "(numeric-value\t . %S)%s"
1124 (setq attributes (delq 'numeric-value attributes))
1128 (when (and (memq 'digit-value attributes)
1129 (setq value (get-char-attribute char 'digit-value)))
1130 (insert (format "(digit-value\t. %S)%s"
1133 (setq attributes (delq 'digit-value attributes))
1135 (when (and (memq 'numeric-value attributes)
1136 (setq value (get-char-attribute char 'numeric-value)))
1137 (insert (format "(numeric-value\t. %S)%s"
1140 (setq attributes (delq 'numeric-value attributes))
1142 (when (and (memq 'iso-10646-comment attributes)
1143 (setq value (get-char-attribute char 'iso-10646-comment)))
1144 (insert (format "(iso-10646-comment\t. %S)%s"
1147 (setq attributes (delq 'iso-10646-comment attributes))
1149 (when (and (memq 'morohashi-daikanwa attributes)
1150 (setq value (get-char-attribute char 'morohashi-daikanwa)))
1151 (insert (format "(morohashi-daikanwa\t%s)%s"
1152 (mapconcat (function prin1-to-string) value " ")
1154 (setq attributes (delq 'morohashi-daikanwa attributes))
1158 (when (and (memq 'ideographic-radical attributes)
1159 (setq value (get-char-attribute char 'ideographic-radical)))
1160 (setq radical value)
1161 (insert (format "(ideographic-radical . %S)\t; %c%s"
1163 (ideographic-radical radical)
1165 (setq attributes (delq 'ideographic-radical attributes))
1167 (when (and (memq 'shuowen-radical attributes)
1168 (setq value (get-char-attribute char 'shuowen-radical)))
1169 (insert (format "(shuowen-radical\t. %S)\t; %c%s"
1171 (shuowen-radical value)
1173 (setq attributes (delq 'shuowen-radical attributes))
1178 char-db-feature-domains
1180 (dolist (feature (char-attribute-list))
1181 (setq feature (symbol-name feature))
1183 "\\(radical\\|strokes\\)@\\([^@*]+\\)\\(\\*\\|$\\)"
1185 (setq domain (intern (match-string 2 feature)))
1186 (unless (memq domain dest)
1187 (setq dest (cons domain dest)))))
1188 (sort dest #'string<))))
1189 (setq key (intern (format "%s@%s" 'ideographic-radical domain)))
1190 (when (and (memq key attributes)
1191 (setq value (get-char-attribute char key)))
1192 (setq radical value)
1193 (insert (format "(%s . %S)\t; %c%s"
1196 (ideographic-radical radical)
1198 (setq attributes (delq key attributes))
1200 (setq key (intern (format "%s@%s" 'ideographic-strokes domain)))
1201 (when (and (memq key attributes)
1202 (setq value (get-char-attribute char key)))
1203 (setq strokes value)
1204 (insert (format "(%s . %S)%s"
1208 (setq attributes (delq key attributes))
1210 (setq key (intern (format "%s@%s" 'total-strokes domain)))
1211 (when (and (memq key attributes)
1212 (setq value (get-char-attribute char key)))
1213 (insert (format "(%s . %S)%s"
1217 (setq attributes (delq key attributes))
1219 (dolist (feature '(ideographic-radical
1222 (setq key (intern (format "%s@%s*sources" feature domain)))
1223 (when (and (memq key attributes)
1224 (setq value (get-char-attribute char key)))
1225 (insert (format "(%s%s" key line-breaking))
1226 (dolist (cell value)
1227 (insert (format " %s" cell)))
1229 (insert line-breaking)
1230 (setq attributes (delq key attributes))
1233 (when (and (memq 'ideographic-strokes attributes)
1234 (setq value (get-char-attribute char 'ideographic-strokes)))
1235 (setq strokes value)
1236 (insert (format "(ideographic-strokes . %S)%s"
1239 (setq attributes (delq 'ideographic-strokes attributes))
1241 (when (and (memq 'kangxi-radical attributes)
1242 (setq value (get-char-attribute char 'kangxi-radical)))
1243 (unless (eq value radical)
1244 (insert (format "(kangxi-radical\t . %S)\t; %c%s"
1246 (ideographic-radical value)
1249 (setq radical value)))
1250 (setq attributes (delq 'kangxi-radical attributes))
1252 (when (and (memq 'kangxi-strokes attributes)
1253 (setq value (get-char-attribute char 'kangxi-strokes)))
1254 (unless (eq value strokes)
1255 (insert (format "(kangxi-strokes\t . %S)%s"
1259 (setq strokes value)))
1260 (setq attributes (delq 'kangxi-strokes attributes))
1262 ;; (when (and (memq 'japanese-radical attributes)
1263 ;; (setq value (get-char-attribute char 'japanese-radical)))
1264 ;; (unless (eq value radical)
1265 ;; (insert (format "(japanese-radical\t . %S)\t; %c%s"
1267 ;; (ideographic-radical value)
1270 ;; (setq radical value)))
1271 ;; (setq attributes (delq 'japanese-radical attributes))
1273 (when (and (memq 'japanese-strokes attributes)
1274 (setq value (get-char-attribute char 'japanese-strokes)))
1275 (unless (eq value strokes)
1276 (insert (format "(japanese-strokes\t . %S)%s"
1280 (setq strokes value)))
1281 (setq attributes (delq 'japanese-strokes attributes))
1283 (when (and (memq 'cns-radical attributes)
1284 (setq value (get-char-attribute char 'cns-radical)))
1285 (insert (format "(cns-radical\t . %S)\t; %c%s"
1287 (ideographic-radical value)
1289 (setq attributes (delq 'cns-radical attributes))
1291 (when (and (memq 'cns-strokes attributes)
1292 (setq value (get-char-attribute char 'cns-strokes)))
1293 (unless (eq value strokes)
1294 (insert (format "(cns-strokes\t . %S)%s"
1298 (setq strokes value)))
1299 (setq attributes (delq 'cns-strokes attributes))
1301 ;; (when (and (memq 'ideographic- attributes)
1302 ;; (setq value (get-char-attribute char 'ideographic-)))
1303 ;; (insert "(ideographic- ")
1304 ;; (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1306 ;; (while (consp value)
1307 ;; (setq cell (car value))
1308 ;; (if (integerp cell)
1309 ;; (setq cell (decode-char '=ucs cell)))
1310 ;; (cond ((characterp cell)
1314 ;; (insert (format "%S" cell))
1315 ;; (char-db-insert-char-spec cell readable))
1316 ;; (setq separator lbs))
1320 ;; (if (consp (car cell))
1321 ;; (char-db-insert-char-spec cell readable)
1322 ;; (char-db-insert-char-reference cell readable))
1323 ;; (setq separator lbs))
1326 ;; (insert separator))
1327 ;; (insert (prin1-to-string cell))
1328 ;; (setq separator " ")))
1329 ;; (setq value (cdr value)))
1331 ;; (insert line-breaking)
1332 ;; (setq attributes (delq 'ideographic- attributes)))
1333 (when (and (memq 'total-strokes attributes)
1334 (setq value (get-char-attribute char 'total-strokes)))
1335 (insert (format "(total-strokes . %S)%s"
1338 (setq attributes (delq 'total-strokes attributes))
1340 ;; (when (and (memq '->ideograph attributes)
1341 ;; (setq value (get-char-attribute char '->ideograph)))
1342 ;; (insert (format "(->ideograph\t%s)%s"
1343 ;; (mapconcat (lambda (code)
1344 ;; (cond ((symbolp code)
1345 ;; (symbol-name code))
1347 ;; (format "#x%04X" code))
1350 ;; line-breaking code))))
1353 ;; (setq attributes (delq '->ideograph attributes))
1355 ;; (when (and (memq '->decomposition attributes)
1356 ;; (setq value (get-char-attribute char '->decomposition)))
1357 ;; (insert (format "(->decomposition\t%s)%s"
1358 ;; (mapconcat (lambda (code)
1359 ;; (cond ((symbolp code)
1360 ;; (symbol-name code))
1361 ;; ((characterp code)
1363 ;; (format "%S" code)
1368 ;; (format "#x%04X" code))
1370 ;; (format "%s%S" line-breaking code))))
1373 ;; (setq attributes (delq '->decomposition attributes))
1375 (if (equal (get-char-attribute char '->titlecase)
1376 (get-char-attribute char '->uppercase))
1377 (setq attributes (delq '->titlecase attributes)))
1378 (when (and (memq '->mojikyo attributes)
1379 (setq value (get-char-attribute char '->mojikyo)))
1380 (insert (format "(->mojikyo\t\t. %06d)\t; %c%s"
1381 value (decode-char 'mojikyo value)
1383 (setq attributes (delq '->mojikyo attributes))
1386 (dolist (ignored '(composition
1387 ->denotational <-subsumptive ->ucs-unified
1388 ;; ->ideographic-component-forms
1390 (setq attributes (delq ignored attributes))))
1392 (setq name (car attributes))
1393 (unless (eq (setq value (get-char-attribute char name 'value-is-empty))
1395 (cond ((setq ret (find-charset name))
1396 (setq name (charset-name ret))
1397 (when (not (memq name dest-ccss))
1398 (setq dest-ccss (cons name dest-ccss))
1399 (char-db-insert-ccs-feature name value line-breaking))
1401 ((string-match "^=>ucs@" (symbol-name name))
1402 (insert (format "(%-18s . #x%04X)\t; %c%s"
1403 name value (decode-char '=ucs value)
1406 ((eq name 'jisx0208-1978/4X)
1407 (insert (format "(%-18s . #x%04X)%s"
1413 (not (eq name '->subsumptive))
1414 (not (eq name '->uppercase))
1415 (not (eq name '->lowercase))
1416 (not (eq name '->titlecase))
1417 (not (eq name '->canonical))
1418 (not (eq name '->Bopomofo))
1419 (not (eq name '->mistakable))
1420 (not (eq name '->ideographic-variants))
1421 (null (get-char-attribute
1422 char (intern (format "%s*sources" name))))
1423 (not (string-match "\\*sources$" (symbol-name name)))
1424 (null (get-char-attribute
1425 char (intern (format "%s*note" name))))
1426 (not (string-match "\\*note$" (symbol-name name)))
1427 (or (eq name '<-identical)
1428 (eq name '<-uppercase)
1429 (eq name '<-lowercase)
1430 (eq name '<-titlecase)
1431 (eq name '<-canonical)
1432 (eq name '<-ideographic-variants)
1433 ;; (eq name '<-synonyms)
1434 (string-match "^<-synonyms" (symbol-name name))
1435 (eq name '<-mistakable)
1436 (when (string-match "^->" (symbol-name name))
1438 ((string-match "^->fullwidth" (symbol-name name))
1439 (not (and (consp value)
1440 (characterp (car value))
1442 (car value) '=ucs 'defined-only)))
1447 ((or (eq name 'ideographic-structure)
1448 (eq name 'ideographic-structure@apparent)
1449 (eq name 'ideographic-structure@apparent/leftmost)
1450 (eq name 'ideographic-structure@apparent/rightmost)
1451 (eq name 'ideographic-combination)
1452 ;; (eq name 'ideographic-)
1453 (eq name '=decomposition)
1454 (char-feature-base-name= '=decomposition name)
1455 (char-feature-base-name= '=>decomposition name)
1456 ;; (string-match "^=>*decomposition\\(@[^*]+\\)?$"
1457 ;; (symbol-name name))
1458 (string-match "^\\(->\\|<-\\)[^*]*$" (symbol-name name))
1459 (string-match "^\\(->\\|<-\\)[^*]*\\*sources$"
1462 (char-db-insert-relation-feature char name value
1465 ;; ((memq name '(ideograph=
1466 ;; original-ideograph-of
1467 ;; ancient-ideograph-of
1468 ;; vulgar-ideograph-of
1469 ;; wrong-ideograph-of
1470 ;; ;; simplified-ideograph-of
1471 ;; ideographic-variants
1472 ;; ;; ideographic-different-form-of
1474 ;; (insert (format "(%-18s%s " name line-breaking))
1475 ;; (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1477 ;; (while (consp value)
1478 ;; (setq cell (car value))
1479 ;; (if (and (consp cell)
1480 ;; (consp (car cell)))
1484 ;; (char-db-insert-alist cell readable)
1485 ;; (setq separator lbs))
1487 ;; (insert separator))
1488 ;; (insert (prin1-to-string cell))
1489 ;; (setq separator " "))
1490 ;; (setq value (cdr value)))
1492 ;; (insert line-breaking))
1494 (insert (format "(%-18s " name))
1495 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1497 (while (consp value)
1498 (setq cell (car value))
1499 (if (and (consp cell)
1501 (setq ret (condition-case nil
1509 (setq key (car (car rest)))
1510 (if (find-charset key)
1511 (setq cal (cons key cal))
1512 (setq al (cons key al)))
1513 (setq rest (cdr rest)))
1516 (insert-char-attributes ret
1520 (setq separator lbs))
1521 (setq ret (prin1-to-string cell))
1523 (if (< (+ (current-column)
1530 (setq separator " "))
1531 (setq value (cdr value)))
1533 (insert line-breaking))
1535 (insert (format "(%-18s" name))
1536 (setq ret (prin1-to-string value))
1537 (unless (< (+ (current-column)
1541 (insert line-breaking))
1542 (insert " . " ret ")" line-breaking)
1543 ;; (insert (format "(%-18s . %S)%s"
1548 (setq attributes (cdr attributes)))
1551 (defun insert-char-data (char &optional readable
1554 (narrow-to-region (point)(point))
1555 (insert "(define-char
1557 (insert-char-attributes char readable attributes)
1559 (goto-char (point-min))
1560 (while (re-search-forward "[ \t]+$" nil t)
1563 (goto-char (point-min))
1564 (while (re-search-forward "[ \t][ \t][ \t]*" nil t)
1565 (let ((column (current-column))
1566 (indent-tabs-mode t))
1567 (delete-region (match-beginning 0) (point))
1568 (indent-to column)))
1569 (goto-char (point-max))
1570 ;; (tabify (point-min)(point-max))
1573 (defun insert-char-data-with-variant (char &optional printable
1575 script excluded-script)
1576 (insert-char-data char printable)
1577 (let ((variants (char-variants char))
1580 (setq variants (sort variants #'<))
1581 (setq rest variants)
1582 (setq variants (cons char variants))
1584 (setq variant (car rest))
1585 (unless (get-char-attribute variant '<-subsumptive)
1586 (if (and (or (null script)
1587 (null (setq vs (get-char-attribute variant 'script)))
1589 (or (null excluded-script)
1590 (null (setq vs (get-char-attribute variant 'script)))
1591 (not (memq excluded-script vs))))
1592 (unless (and no-ucs-unified (get-char-attribute variant '=ucs))
1593 (insert-char-data variant printable)
1594 (if (setq ret (char-variants variant))
1596 (or (memq (car ret) variants)
1597 ;; (get-char-attribute (car ret) '<-subsumptive)
1598 (setq rest (nconc rest (list (car ret)))))
1599 (setq ret (cdr ret)))))))
1600 (setq rest (cdr rest)))))
1602 (defun insert-char-range-data (min max &optional script excluded-script)
1605 (while (<= code max)
1606 (setq char (decode-char '=ucs code))
1607 (if (encode-char char '=ucs 'defined-only)
1608 (insert-char-data-with-variant char nil 'no-ucs-unified
1609 script excluded-script))
1610 (setq code (1+ code)))))
1612 (defun write-char-range-data-to-file (min max file
1613 &optional script excluded-script)
1614 (let ((coding-system-for-write char-db-file-coding-system))
1616 (insert (format ";; -*- coding: %s -*-\n"
1617 char-db-file-coding-system))
1618 (insert-char-range-data min max script excluded-script)
1619 (write-region (point-min)(point-max) file))))
1621 (defvar what-character-original-window-configuration)
1624 (defun what-char-definition (char)
1625 (interactive (list (char-after)))
1626 (let ((buf (get-buffer-create "*Character Description*"))
1627 (the-buf (current-buffer))
1628 (win-conf (current-window-configuration)))
1630 (make-local-variable 'what-character-original-window-configuration)
1631 (setq what-character-original-window-configuration win-conf)
1632 (setq buffer-read-only nil)
1636 (insert-char-data-with-variant char 'printable)
1637 (unless (char-attribute-alist char)
1638 (insert (format ";; = %c\n"
1639 (let* ((rest (split-char char))
1643 (setq code (logior (lsh code 8)
1645 (decode-char ccs code)))))
1646 ;; (char-db-update-comment)
1647 (set-buffer-modified-p nil)
1648 (view-mode the-buf (lambda (buf)
1649 (set-window-configuration
1650 what-character-original-window-configuration)
1652 (goto-char (point-min)))
1654 (set-window-configuration
1655 what-character-original-window-configuration)
1656 (signal (car err) (cdr err)))))))
1662 (provide 'char-db-util)
1664 ;;; char-db-util.el ends here