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 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
233 ;; =>>>adobe-japan1-0
234 ;; =>>>adobe-japan1-1
235 ;; =>>>adobe-japan1-2
236 ;; =>>>adobe-japan1-3
237 ;; =>>>adobe-japan1-4
238 ;; =>>>adobe-japan1-5
239 ;; =>>>adobe-japan1-6
243 ;; =>>>hanyo-denshi/ja
244 ;; =>>>hanyo-denshi/jb
245 ;; =>>>hanyo-denshi/jc
246 ;; =>>>hanyo-denshi/ft
247 ;; =>>>hanyo-denshi/ib
248 ;; =>>>hanyo-denshi/hg
249 ;; =>>>hanyo-denshi/jt
250 ;; =>>>hanyo-denshi/ks
290 ;; =>ucs@hanyo-denshi
407 =>big5-cdp-itaiji-001
408 =>big5-cdp-itaiji-002
409 =>big5-cdp-itaiji-003
410 =>big5-cdp-itaiji-004
415 =>ucs@iwds-1/normalized
416 =>ucs-itaiji-001@iwds-1
417 =>ucs-itaiji-002@iwds-1
418 =>ucs-itaiji-003@iwds-1
419 =>ucs-itaiji-006@iwds-1
434 ;;; @ char-db formatters
437 (defun char-db-make-char-spec (char)
439 (cond ((characterp char)
440 (cond ((and (setq ret (encode-char char '=ucs 'defined-only))
441 (not (and (<= #xE000 ret)(<= ret #xF8FF))))
442 (setq char-spec (list (cons '=ucs ret)))
443 (cond ((setq ret (get-char-attribute char 'name))
444 (setq char-spec (cons (cons 'name ret) char-spec))
446 ((setq ret (get-char-attribute char 'name*))
447 (setq char-spec (cons (cons 'name* ret) char-spec))
450 ((encode-char char '=mj 'defined-only)
452 (dolist (ccs (charset-list))
453 (if (and (or (eq ccs '=mj)
454 ;; (eq (charset-property ccs 'iso-ir) 177)
455 (string-match "=ucs@" (symbol-name ccs))
457 (setq ccs (charset-name ccs))
458 (null (assq ccs char-spec))
459 (setq ret (encode-char char ccs 'defined-only)))
460 (setq char-spec (cons (cons ccs ret) char-spec))))
462 ((encode-char char '==mj 'defined-only)
464 (dolist (ccs (charset-list))
465 (if (and (or (eq ccs '==mj)
466 ;; (eq (charset-property ccs 'iso-ir) 177)
467 (string-match "=ucs@" (symbol-name ccs))
469 (setq ccs (charset-name ccs))
470 (null (assq ccs char-spec))
471 (setq ret (encode-char char ccs 'defined-only)))
472 (setq char-spec (cons (cons ccs ret) char-spec))))
474 ((encode-char char '=adobe-japan1 'defined-only)
476 (dolist (ccs (charset-list))
477 (if (and (or (memq ccs
486 ;; (eq (charset-property ccs 'iso-ir) 177)
487 (string-match "=ucs@" (symbol-name ccs))
489 (setq ccs (charset-name ccs))
490 (null (assq ccs char-spec))
491 (setq ret (encode-char char ccs 'defined-only)))
492 (setq char-spec (cons (cons ccs ret) char-spec))))
494 ((encode-char char '==adobe-japan1 'defined-only)
496 (dolist (ccs (charset-list))
497 (if (and (or (memq ccs
506 ;; (eq (charset-property ccs 'iso-ir) 177)
507 (string-match "=ucs@" (symbol-name ccs))
509 (setq ccs (charset-name ccs))
510 (null (assq ccs char-spec))
511 (setq ret (encode-char char ccs 'defined-only)))
512 (setq char-spec (cons (cons ccs ret) char-spec))))
516 (let ((rest char-db-coded-charset-priority-list)
519 (setq ccs (charset-name
520 (find-charset (car rest))))
522 (encode-char char ccs
524 (throw 'tag (cons ccs ret)))
525 (setq rest (cdr rest))))))
526 (setq char-spec (list ret))
527 (dolist (ccs (delq (car ret) (charset-list)))
528 (if (and (or (charset-iso-final-char ccs)
535 (and (eq (charset-property ccs 'iso-ir) 177)
536 (not (eq (charset-name ccs) '=ucs@big5)))
537 ;; (string-match "=ucs@" (symbol-name ccs))
539 (setq ccs (charset-name ccs))
540 (null (assq ccs char-spec))
541 (setq ret (encode-char char ccs 'defined-only)))
542 (setq char-spec (cons (cons ccs ret) char-spec))))
544 (setq char-spec (split-char char)))
545 (cond ((setq ret (get-char-attribute char 'name))
546 (setq char-spec (cons (cons 'name ret) char-spec))
548 ((setq ret (get-char-attribute char 'name*))
549 (setq char-spec (cons (cons 'name* ret) char-spec))
552 ((setq ret (get-char-attribute
553 char 'ideographic-combination))
555 (cons (cons 'ideographic-combination ret)
562 (defun char-db-insert-char-spec (char &optional readable column
565 (setq column (current-column)))
566 (let (char-spec temp-char)
567 (setq char-spec (char-db-make-char-spec char))
568 (unless (or (characterp char) ; char
570 (setq char (find-char char-spec))
572 ;; define temporary character
573 ;; Current implementation is dirty.
574 (setq temp-char (define-char (cons '(ideograph-daikanwa . 0)
576 (remove-char-attribute temp-char 'ideograph-daikanwa)
577 (setq char temp-char))
578 (insert-char-attributes char
580 (union (mapcar #'car char-spec)
584 ;; undefine temporary character
585 ;; Current implementation is dirty.
586 (setq char-spec (char-attribute-alist temp-char))
588 (remove-char-attribute temp-char (car (car char-spec)))
589 (setq char-spec (cdr char-spec))))))
591 (defun char-db-insert-alist (alist &optional readable column)
593 (setq column (current-column)))
595 (concat "\n" (make-string (1+ column) ?\ )))
599 lbs cell rest separator)
602 (setq name (car (car alist))
603 value (cdr (car alist)))
604 (cond ((eq name 'char)
606 (if (setq ret (condition-case nil
614 (setq key (car (car value)))
615 ;; (if (find-charset key)
616 ;; (setq cal (cons key cal))
617 (setq al (cons key al))
619 (setq value (cdr value)))
620 (insert-char-attributes ret
624 (insert (prin1-to-string value)))
626 (insert line-breaking))
628 (insert (format "(%-18s " name))
629 (setq lbs (concat "\n" (make-string (current-column) ?\ )))
631 (setq cell (car value))
632 (if (and (consp cell)
634 (setq ret (condition-case nil
644 (setq key (car (car rest)))
645 ;; (if (find-charset key)
646 ;; (setq cal (cons key cal))
647 (setq al (cons key al))
649 (setq rest (cdr rest)))
652 (insert-char-attributes ret
656 (setq separator lbs))
659 (insert (prin1-to-string cell))
660 (setq separator " "))
661 (setq value (cdr value)))
663 (insert line-breaking))
665 (insert (format "(%-18s . %S)%s"
668 (setq alist (cdr alist))))
671 (defun char-db-insert-char-reference (plist &optional readable column)
673 (setq column (current-column)))
675 (concat "\n" (make-string (1+ column) ?\ )))
680 (setq name (pop plist))
681 (setq value (pop plist))
682 (cond ((eq name :char)
685 (cond ((numberp value)
686 (setq value (decode-char '=ucs value)))
688 ;; (setq value (or (find-char value)
691 (char-db-insert-char-spec value readable)
692 (insert line-breaking)
695 (insert (format "%s%s\t%d ; %c%s"
698 (ideographic-radical value)
702 (insert (format "%s%s\t%S" separator name value))
703 (setq separator line-breaking)))
707 (defun char-db-decode-isolated-char (ccs code-point)
710 (cond ((eq ccs 'arabic-iso8859-6)
711 (decode-char ccs code-point))
713 ;; (decode-builtin-char '==gt code-point))
714 ((and (memq ccs '(=gt-pj-1
725 (setq ret (decode-char ccs code-point))
726 (setq ret (encode-char ret '=gt 'defined-only)))
727 (decode-builtin-char '=gt ret))
729 (decode-builtin-char ccs code-point))))
731 (or (decode-char ccs code-point)
732 (define-char (list (cons ccs code-point)))))
733 ((and (<= 0 (char-int ret))
734 (<= (char-int ret) #x1F))
735 (decode-char '=ucs (+ #x2400 (char-int ret))))
736 ((= (char-int ret) #x7F)
740 (defvar char-db-convert-obsolete-format t)
742 (defun char-db-insert-ccs-feature (name value line-breaking)
748 ((memq name '(=>iwds-1
751 =shinjigen@1ed ==shinjigen@1ed
752 =shinjigen@rev ==shinjigen@rev
753 =shinjigen/+p@rev ==shinjigen/+p@rev
754 ===daikanwa/ho ==daikanwa/ho
755 =daikanwa/ho =>>daikanwa/ho =>daikanwa/ho))
756 "(%-18s . %04d)\t; %c")
757 ((eq name '=shinjigen@1ed/24pr)
758 "(%-18s . %04d)\t; %c")
762 ==daikanwa =daikanwa =>>daikanwa =>daikanwa
763 =daikanwa@rev1 =daikanwa@rev2
764 =daikanwa/+p ==daikanwa/+p ===daikanwa/+p
766 =daikanwa/+2p =>>daikanwa/+2p
771 =adobe-japan1-0 ==adobe-japan1-0 ===adobe-japan1-0
772 =adobe-japan1-1 ==adobe-japan1-1 ===adobe-japan1-1
773 =adobe-japan1-2 ==adobe-japan1-2 ===adobe-japan1-2
774 =adobe-japan1-3 ==adobe-japan1-3 ===adobe-japan1-3
775 =adobe-japan1-4 ==adobe-japan1-4 ===adobe-japan1-4
776 =adobe-japan1-5 ==adobe-japan1-5 ===adobe-japan1-5
777 =adobe-japan1-6 ==adobe-japan1-6 ===adobe-japan1-6
778 =>>adobe-japan1-0 =+>adobe-japan1-0
779 =>>adobe-japan1-1 =+>adobe-japan1-1
780 =>>adobe-japan1-2 =+>adobe-japan1-2
781 =>>adobe-japan1-3 =+>adobe-japan1-3
782 =>>adobe-japan1-4 =+>adobe-japan1-4
783 =>>adobe-japan1-5 =+>adobe-japan1-5
784 =>>adobe-japan1-6 =+>adobe-japan1-6
785 =>cbeta =cbeta =>>cbeta ==cbeta ===cbeta
786 =zinbun-oracle =>zinbun-oracle
787 =daijiten ==daijiten ===daijiten ==>daijiten
788 ===hng-jou ===hng-keg ===hng-dng ===hng-mam
789 ===hng-drt ===hng-kgk ===hng-myz ===hng-kda
790 ===hng-khi ===hng-khm ===hng-fhs ===hng-hok
791 ===hng-kyd ===hng-sok
792 ===hng-yhk ===hng-kak ===hng-kar ===hng-kae
793 ===hng-sys ===hng-tsu ===hng-tzj
794 ===hng-hos ===hng-kkh ===hng-nak ===hng-jhk
795 ===hng-hod ===hng-gok ===hng-ink ===hng-nto
796 ===hng-nkm ===hng-k24 ===hng-ini ===hng-nkk
797 ===hng-kcc ===hng-kcj ===hng-kbk ===hng-sik
798 ===hng-skk ===hng-kyu ===hng-ksk ===hng-wan
799 ===hng-okd ===hng-wad ===hng-kmi
800 ===hng-zkd ===hng-doh ===hng-jyu ===hng-tzs
801 ===hng-sai ===hng-kad ===hng-kss
802 ===hng-kyo ===hng-ykk ===hng-saa
803 ===hng-sab ===hng-wks ===hng-wke ===hng-smk
804 ===hng-sgs ===hng-sts ===hng-kkd
805 =>shuowen-jiguge =shuowen-jiguge
806 ===shuowen-jiguge4 ===shuowen-jiguge5))
807 ;; (string-match "^=adobe-" (symbol-name name))
809 "(%-18s . %05d)\t; %c")
810 ((memq name '(=hanyo-denshi/ks
811 ==hanyo-denshi/ks ===hanyo-denshi/ks
814 =mj ==mj ===mj =>>mj =>mj
816 "(%-18s . %06d)\t; %c")
817 ((memq name '(=hanyo-denshi/tk =>hanyo-denshi/tk ==hanyo-denshi/tk))
818 "(%-18s . %08d)\t; %c")
819 ((>= (charset-dimension name) 2)
820 "(%-18s . #x%04X)\t; %c")
822 "(%-18s . #x%02X)\t; %c"))
824 (if (= (charset-iso-graphic-plane name) 1)
826 (cond ((= (charset-dimension name) 1)
828 ((= (charset-dimension name) 2)
830 ((= (charset-dimension name) 3)
834 (char-db-decode-isolated-char name value)))
835 (if (and (= (charset-chars name) 94)
836 (= (charset-dimension name) 2))
837 (insert (format " [%02d-%02d]"
838 (- (lsh value -8) 32)
839 (- (logand value 255) 32))))
842 (insert (format "(%-18s . %s)" name value))
844 (insert line-breaking))
846 (defun char-db-insert-relation-feature (char name value line-breaking
848 (insert (format "(%-18s%s " name line-breaking))
849 (let ((lbs (concat "\n" (make-string (current-column) ?\ )))
850 separator cell sources required-features
853 (setq cell (car value))
855 (setq cell (decode-char '=ucs cell)))
857 ((eq name '->subsumptive)
858 (when (or (not (some (lambda (atr)
859 (get-char-attribute cell atr))
860 char-db-ignored-attributes))
862 (encode-char cell ccs 'defined-only))
866 (let ((char-db-ignored-attributes
868 char-db-ignored-attributes)))
869 (insert-char-attributes cell readable nil nil 'for-sub-node))
870 (setq separator lbs))
875 char (intern (format "%s*sources" name))))
876 (setq required-features nil)
877 (dolist (source sources)
881 shinjigen shinjigen@1ed shinjigen@rev))
882 (setq required-features
883 (union required-features
895 =shinjigen/+p@rev))))
897 (setq required-features
898 (union required-features
903 ((find-charset (setq ret (intern (format "=%s" source))))
904 (setq required-features
905 (cons ret required-features)))
906 (t (setq required-features
907 (cons source required-features)))))
908 (cond ((string-match "@JP" (symbol-name name))
909 (setq required-features
910 (union required-features
918 ((string-match "@CN" (symbol-name name))
919 (setq required-features
920 (union required-features
927 (insert (format "%S" cell))
928 (char-db-insert-char-spec cell readable
931 (setq separator lbs))
935 (if (consp (car cell))
936 (char-db-insert-char-spec cell readable)
937 (char-db-insert-char-reference cell readable))
938 (setq separator lbs))
942 (insert (prin1-to-string cell))
943 (setq separator " ")))
944 (setq value (cdr value)))
946 (insert line-breaking)))
948 (defun insert-char-attributes (char &optional readable attributes column
951 (setq column (current-column)))
952 (let (name value ; has-long-ccs-name
956 (concat "\n" (make-string (1+ column) ?\ )))
957 lbs cell separator ret
959 dest-ccss ; sources required-features
964 (if (consp attributes)
966 (dolist (name attributes)
967 (unless (memq name char-db-ignored-attributes)
968 (if (find-charset name)
972 (dolist (name (char-attribute-list))
973 (unless (memq name char-db-ignored-attributes)
974 (if (find-charset name)
978 #'char-attribute-name<)))
980 (when (memq '<-subsumptive attributes)
981 (when (or readable (not for-sub-node))
982 (when (setq value (get-char-attribute char '<-subsumptive))
983 (char-db-insert-relation-feature char '<-subsumptive value
986 (setq attributes (delq '<-subsumptive attributes)))
987 (when (and (memq '<-denotational attributes)
988 (setq value (get-char-attribute char '<-denotational)))
989 (char-db-insert-relation-feature char '<-denotational value
992 (setq attributes (delq '<-denotational attributes)))
993 (when (and (memq '<-denotational@component attributes)
994 (setq value (get-char-attribute char '<-denotational@component)))
995 (char-db-insert-relation-feature char '<-denotational@component value
998 (setq attributes (delq '<-denotational@component attributes)))
999 (when (and (memq '<-denotational@usage attributes)
1000 (setq value (get-char-attribute char '<-denotational@usage)))
1001 (char-db-insert-relation-feature char '<-denotational@usage value
1004 (setq attributes (delq '<-denotational@usage attributes)))
1005 (when (and (memq 'name attributes)
1006 (setq value (get-char-attribute char 'name)))
1008 (if (> (+ (current-column) (length value)) 48)
1011 value line-breaking))
1012 (setq attributes (delq 'name 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 'script attributes)
1024 (setq value (get-char-attribute char 'script)))
1025 (insert (format "(script\t\t%s)%s"
1026 (mapconcat (function prin1-to-string)
1029 (setq attributes (delq 'script attributes))
1031 (dolist (name '(=>ucs =>ucs*))
1032 (when (and (memq name attributes)
1033 (setq value (get-char-attribute char name)))
1034 (insert (format "(%-18s . #x%04X)\t; %c%s"
1035 name value (decode-char '=ucs value)
1037 (setq attributes (delq name attributes))))
1038 (dolist (name '(=>ucs@gb =>ucs@big5))
1039 (when (and (memq name attributes)
1040 (setq value (get-char-attribute char name)))
1041 (insert (format "(%-18s . #x%04X)\t; %c%s"
1043 (decode-char (intern
1046 (symbol-name name) 2)))
1049 (setq attributes (delq name attributes))
1051 ;; (dolist (name '(=>daikanwa))
1052 ;; (when (and (memq name attributes)
1053 ;; (setq value (get-char-attribute char name)))
1055 ;; (if (integerp value)
1056 ;; (format "(%-18s . %05d)\t; %c%s"
1057 ;; name value (decode-char '=daikanwa value)
1059 ;; (format "(%-18s %s)\t; %c%s"
1061 ;; (mapconcat (function prin1-to-string)
1063 ;; (char-representative-of-daikanwa char)
1065 ;; (setq attributes (delq name attributes))))
1066 (when (and (memq 'general-category attributes)
1067 (setq value (get-char-attribute char 'general-category)))
1069 "(general-category\t%s) ; %s%s"
1070 (mapconcat (lambda (cell)
1073 (cond ((rassoc value unidata-normative-category-alist)
1074 "Normative Category")
1075 ((rassoc value unidata-informative-category-alist)
1076 "Informative Category")
1078 "Unknown Category"))
1080 (setq attributes (delq 'general-category attributes))
1082 (when (and (memq 'bidi-category attributes)
1083 (setq value (get-char-attribute char 'bidi-category)))
1084 (insert (format "(bidi-category\t. %S)%s"
1087 (setq attributes (delq 'bidi-category attributes))
1089 (unless (or (not (memq 'mirrored attributes))
1090 (eq (setq value (get-char-attribute char 'mirrored 'empty))
1092 (insert (format "(mirrored\t\t. %S)%s"
1095 (setq attributes (delq 'mirrored attributes))
1098 ((and (memq 'decimal-digit-value attributes)
1099 (setq value (get-char-attribute char 'decimal-digit-value)))
1100 (insert (format "(decimal-digit-value . %S)%s"
1103 (setq attributes (delq 'decimal-digit-value attributes))
1104 (when (and (memq 'digit-value attributes)
1105 (setq value (get-char-attribute char 'digit-value)))
1106 (insert (format "(digit-value\t . %S)%s"
1109 (setq attributes (delq 'digit-value attributes))
1111 (when (and (memq 'numeric-value attributes)
1112 (setq value (get-char-attribute char 'numeric-value)))
1113 (insert (format "(numeric-value\t . %S)%s"
1116 (setq attributes (delq 'numeric-value attributes))
1120 (when (and (memq 'digit-value attributes)
1121 (setq value (get-char-attribute char 'digit-value)))
1122 (insert (format "(digit-value\t. %S)%s"
1125 (setq attributes (delq 'digit-value attributes))
1127 (when (and (memq 'numeric-value attributes)
1128 (setq value (get-char-attribute char 'numeric-value)))
1129 (insert (format "(numeric-value\t. %S)%s"
1132 (setq attributes (delq 'numeric-value attributes))
1134 (when (and (memq 'iso-10646-comment attributes)
1135 (setq value (get-char-attribute char 'iso-10646-comment)))
1136 (insert (format "(iso-10646-comment\t. %S)%s"
1139 (setq attributes (delq 'iso-10646-comment attributes))
1141 (when (and (memq 'morohashi-daikanwa attributes)
1142 (setq value (get-char-attribute char 'morohashi-daikanwa)))
1143 (insert (format "(morohashi-daikanwa\t%s)%s"
1144 (mapconcat (function prin1-to-string) value " ")
1146 (setq attributes (delq 'morohashi-daikanwa attributes))
1150 (when (and (memq 'ideographic-radical attributes)
1151 (setq value (get-char-attribute char 'ideographic-radical)))
1152 (setq radical value)
1153 (insert (format "(ideographic-radical . %S)\t; %c%s"
1155 (ideographic-radical radical)
1157 (setq attributes (delq 'ideographic-radical attributes))
1159 (when (and (memq 'shuowen-radical attributes)
1160 (setq value (get-char-attribute char 'shuowen-radical)))
1161 (insert (format "(shuowen-radical\t. %S)\t; %c%s"
1163 (shuowen-radical value)
1165 (setq attributes (delq 'shuowen-radical attributes))
1170 char-db-feature-domains
1172 (dolist (feature (char-attribute-list))
1173 (setq feature (symbol-name feature))
1175 "\\(radical\\|strokes\\)@\\([^@*]+\\)\\(\\*\\|$\\)"
1177 (setq domain (intern (match-string 2 feature)))
1178 (unless (memq domain dest)
1179 (setq dest (cons domain dest)))))
1180 (sort dest #'string<))))
1181 (setq key (intern (format "%s@%s" 'ideographic-radical domain)))
1182 (when (and (memq key attributes)
1183 (setq value (get-char-attribute char key)))
1184 (setq radical value)
1185 (insert (format "(%s . %S)\t; %c%s"
1188 (ideographic-radical radical)
1190 (setq attributes (delq key attributes))
1192 (setq key (intern (format "%s@%s" 'ideographic-strokes domain)))
1193 (when (and (memq key attributes)
1194 (setq value (get-char-attribute char key)))
1195 (setq strokes value)
1196 (insert (format "(%s . %S)%s"
1200 (setq attributes (delq key attributes))
1202 (setq key (intern (format "%s@%s" 'total-strokes domain)))
1203 (when (and (memq key attributes)
1204 (setq value (get-char-attribute char key)))
1205 (insert (format "(%s . %S)%s"
1209 (setq attributes (delq key attributes))
1211 (dolist (feature '(ideographic-radical
1214 (setq key (intern (format "%s@%s*sources" feature domain)))
1215 (when (and (memq key attributes)
1216 (setq value (get-char-attribute char key)))
1217 (insert (format "(%s%s" key line-breaking))
1218 (dolist (cell value)
1219 (insert (format " %s" cell)))
1221 (insert line-breaking)
1222 (setq attributes (delq key attributes))
1225 (when (and (memq 'ideographic-strokes attributes)
1226 (setq value (get-char-attribute char 'ideographic-strokes)))
1227 (setq strokes value)
1228 (insert (format "(ideographic-strokes . %S)%s"
1231 (setq attributes (delq 'ideographic-strokes attributes))
1233 (when (and (memq 'kangxi-radical attributes)
1234 (setq value (get-char-attribute char 'kangxi-radical)))
1235 (unless (eq value radical)
1236 (insert (format "(kangxi-radical\t . %S)\t; %c%s"
1238 (ideographic-radical value)
1241 (setq radical value)))
1242 (setq attributes (delq 'kangxi-radical attributes))
1244 (when (and (memq 'kangxi-strokes attributes)
1245 (setq value (get-char-attribute char 'kangxi-strokes)))
1246 (unless (eq value strokes)
1247 (insert (format "(kangxi-strokes\t . %S)%s"
1251 (setq strokes value)))
1252 (setq attributes (delq 'kangxi-strokes attributes))
1254 ;; (when (and (memq 'japanese-radical attributes)
1255 ;; (setq value (get-char-attribute char 'japanese-radical)))
1256 ;; (unless (eq value radical)
1257 ;; (insert (format "(japanese-radical\t . %S)\t; %c%s"
1259 ;; (ideographic-radical value)
1262 ;; (setq radical value)))
1263 ;; (setq attributes (delq 'japanese-radical attributes))
1265 (when (and (memq 'japanese-strokes attributes)
1266 (setq value (get-char-attribute char 'japanese-strokes)))
1267 (unless (eq value strokes)
1268 (insert (format "(japanese-strokes\t . %S)%s"
1272 (setq strokes value)))
1273 (setq attributes (delq 'japanese-strokes attributes))
1275 (when (and (memq 'cns-radical attributes)
1276 (setq value (get-char-attribute char 'cns-radical)))
1277 (insert (format "(cns-radical\t . %S)\t; %c%s"
1279 (ideographic-radical value)
1281 (setq attributes (delq 'cns-radical attributes))
1283 (when (and (memq 'cns-strokes attributes)
1284 (setq value (get-char-attribute char 'cns-strokes)))
1285 (unless (eq value strokes)
1286 (insert (format "(cns-strokes\t . %S)%s"
1290 (setq strokes value)))
1291 (setq attributes (delq 'cns-strokes attributes))
1293 ;; (when (and (memq 'ideographic- attributes)
1294 ;; (setq value (get-char-attribute char 'ideographic-)))
1295 ;; (insert "(ideographic- ")
1296 ;; (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1298 ;; (while (consp value)
1299 ;; (setq cell (car value))
1300 ;; (if (integerp cell)
1301 ;; (setq cell (decode-char '=ucs cell)))
1302 ;; (cond ((characterp cell)
1306 ;; (insert (format "%S" cell))
1307 ;; (char-db-insert-char-spec cell readable))
1308 ;; (setq separator lbs))
1312 ;; (if (consp (car cell))
1313 ;; (char-db-insert-char-spec cell readable)
1314 ;; (char-db-insert-char-reference cell readable))
1315 ;; (setq separator lbs))
1318 ;; (insert separator))
1319 ;; (insert (prin1-to-string cell))
1320 ;; (setq separator " ")))
1321 ;; (setq value (cdr value)))
1323 ;; (insert line-breaking)
1324 ;; (setq attributes (delq 'ideographic- attributes)))
1325 (when (and (memq 'total-strokes attributes)
1326 (setq value (get-char-attribute char 'total-strokes)))
1327 (insert (format "(total-strokes . %S)%s"
1330 (setq attributes (delq 'total-strokes attributes))
1332 ;; (when (and (memq '->ideograph attributes)
1333 ;; (setq value (get-char-attribute char '->ideograph)))
1334 ;; (insert (format "(->ideograph\t%s)%s"
1335 ;; (mapconcat (lambda (code)
1336 ;; (cond ((symbolp code)
1337 ;; (symbol-name code))
1339 ;; (format "#x%04X" code))
1342 ;; line-breaking code))))
1345 ;; (setq attributes (delq '->ideograph attributes))
1347 ;; (when (and (memq '->decomposition attributes)
1348 ;; (setq value (get-char-attribute char '->decomposition)))
1349 ;; (insert (format "(->decomposition\t%s)%s"
1350 ;; (mapconcat (lambda (code)
1351 ;; (cond ((symbolp code)
1352 ;; (symbol-name code))
1353 ;; ((characterp code)
1355 ;; (format "%S" code)
1360 ;; (format "#x%04X" code))
1362 ;; (format "%s%S" line-breaking code))))
1365 ;; (setq attributes (delq '->decomposition attributes))
1367 (if (equal (get-char-attribute char '->titlecase)
1368 (get-char-attribute char '->uppercase))
1369 (setq attributes (delq '->titlecase attributes)))
1370 (when (and (memq '->mojikyo attributes)
1371 (setq value (get-char-attribute char '->mojikyo)))
1372 (insert (format "(->mojikyo\t\t. %06d)\t; %c%s"
1373 value (decode-char 'mojikyo value)
1375 (setq attributes (delq '->mojikyo attributes))
1378 (dolist (ignored '(composition
1379 ->denotational <-subsumptive ->ucs-unified
1380 ;; ->ideographic-component-forms
1382 (setq attributes (delq ignored attributes))))
1384 (setq name (car attributes))
1385 (unless (eq (setq value (get-char-attribute char name 'value-is-empty))
1387 (cond ((setq ret (find-charset name))
1388 (setq name (charset-name ret))
1389 (when (not (memq name dest-ccss))
1390 (setq dest-ccss (cons name dest-ccss))
1391 (char-db-insert-ccs-feature name value line-breaking))
1393 ((string-match "^=>ucs@" (symbol-name name))
1394 (insert (format "(%-18s . #x%04X)\t; %c%s"
1395 name value (decode-char '=ucs value)
1398 ((eq name 'jisx0208-1978/4X)
1399 (insert (format "(%-18s . #x%04X)%s"
1405 (not (eq name '->subsumptive))
1406 (not (eq name '->uppercase))
1407 (not (eq name '->lowercase))
1408 (not (eq name '->titlecase))
1409 (not (eq name '->canonical))
1410 (not (eq name '->Bopomofo))
1411 (not (eq name '->mistakable))
1412 (not (eq name '->ideographic-variants))
1413 (null (get-char-attribute
1414 char (intern (format "%s*sources" name))))
1415 (not (string-match "\\*sources$" (symbol-name name)))
1416 (null (get-char-attribute
1417 char (intern (format "%s*note" name))))
1418 (not (string-match "\\*note$" (symbol-name name)))
1419 (or (eq name '<-identical)
1420 (eq name '<-uppercase)
1421 (eq name '<-lowercase)
1422 (eq name '<-titlecase)
1423 (eq name '<-canonical)
1424 (eq name '<-ideographic-variants)
1425 ;; (eq name '<-synonyms)
1426 (string-match "^<-synonyms" (symbol-name name))
1427 (eq name '<-mistakable)
1428 (when (string-match "^->" (symbol-name name))
1430 ((string-match "^->fullwidth" (symbol-name name))
1431 (not (and (consp value)
1432 (characterp (car value))
1434 (car value) '=ucs 'defined-only)))
1439 ((or (eq name 'ideographic-structure)
1440 (eq name 'ideographic-structure@apparent)
1441 (eq name 'ideographic-structure@apparent/leftmost)
1442 (eq name 'ideographic-combination)
1443 ;; (eq name 'ideographic-)
1444 (eq name '=decomposition)
1445 (char-feature-base-name= '=decomposition name)
1446 (char-feature-base-name= '=>decomposition name)
1447 ;; (string-match "^=>*decomposition\\(@[^*]+\\)?$"
1448 ;; (symbol-name name))
1449 (string-match "^\\(->\\|<-\\)[^*]*$" (symbol-name name))
1450 (string-match "^\\(->\\|<-\\)[^*]*\\*sources$"
1453 (char-db-insert-relation-feature char name value
1456 ;; ((memq name '(ideograph=
1457 ;; original-ideograph-of
1458 ;; ancient-ideograph-of
1459 ;; vulgar-ideograph-of
1460 ;; wrong-ideograph-of
1461 ;; ;; simplified-ideograph-of
1462 ;; ideographic-variants
1463 ;; ;; ideographic-different-form-of
1465 ;; (insert (format "(%-18s%s " name line-breaking))
1466 ;; (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1468 ;; (while (consp value)
1469 ;; (setq cell (car value))
1470 ;; (if (and (consp cell)
1471 ;; (consp (car cell)))
1475 ;; (char-db-insert-alist cell readable)
1476 ;; (setq separator lbs))
1478 ;; (insert separator))
1479 ;; (insert (prin1-to-string cell))
1480 ;; (setq separator " "))
1481 ;; (setq value (cdr value)))
1483 ;; (insert line-breaking))
1485 (insert (format "(%-18s " name))
1486 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1488 (while (consp value)
1489 (setq cell (car value))
1490 (if (and (consp cell)
1492 (setq ret (condition-case nil
1500 (setq key (car (car rest)))
1501 (if (find-charset key)
1502 (setq cal (cons key cal))
1503 (setq al (cons key al)))
1504 (setq rest (cdr rest)))
1507 (insert-char-attributes ret
1511 (setq separator lbs))
1512 (setq ret (prin1-to-string cell))
1514 (if (< (+ (current-column)
1521 (setq separator " "))
1522 (setq value (cdr value)))
1524 (insert line-breaking))
1526 (insert (format "(%-18s" name))
1527 (setq ret (prin1-to-string value))
1528 (unless (< (+ (current-column)
1532 (insert line-breaking))
1533 (insert " . " ret ")" line-breaking)
1534 ;; (insert (format "(%-18s . %S)%s"
1539 (setq attributes (cdr attributes)))
1542 (defun insert-char-data (char &optional readable
1545 (narrow-to-region (point)(point))
1546 (insert "(define-char
1548 (insert-char-attributes char readable attributes)
1550 (goto-char (point-min))
1551 (while (re-search-forward "[ \t]+$" nil t)
1554 (goto-char (point-min))
1555 (while (re-search-forward "[ \t][ \t][ \t]*" nil t)
1556 (let ((column (current-column))
1557 (indent-tabs-mode t))
1558 (delete-region (match-beginning 0) (point))
1559 (indent-to column)))
1560 (goto-char (point-max))
1561 ;; (tabify (point-min)(point-max))
1564 (defun insert-char-data-with-variant (char &optional printable
1566 script excluded-script)
1567 (insert-char-data char printable)
1568 (let ((variants (char-variants char))
1571 (setq variants (sort variants #'<))
1572 (setq rest variants)
1573 (setq variants (cons char variants))
1575 (setq variant (car rest))
1576 (unless (get-char-attribute variant '<-subsumptive)
1577 (if (and (or (null script)
1578 (null (setq vs (get-char-attribute variant 'script)))
1580 (or (null excluded-script)
1581 (null (setq vs (get-char-attribute variant 'script)))
1582 (not (memq excluded-script vs))))
1583 (unless (and no-ucs-unified (get-char-attribute variant '=ucs))
1584 (insert-char-data variant printable)
1585 (if (setq ret (char-variants variant))
1587 (or (memq (car ret) variants)
1588 ;; (get-char-attribute (car ret) '<-subsumptive)
1589 (setq rest (nconc rest (list (car ret)))))
1590 (setq ret (cdr ret)))))))
1591 (setq rest (cdr rest)))))
1593 (defun insert-char-range-data (min max &optional script excluded-script)
1596 (while (<= code max)
1597 (setq char (decode-char '=ucs code))
1598 (if (encode-char char '=ucs 'defined-only)
1599 (insert-char-data-with-variant char nil 'no-ucs-unified
1600 script excluded-script))
1601 (setq code (1+ code)))))
1603 (defun write-char-range-data-to-file (min max file
1604 &optional script excluded-script)
1605 (let ((coding-system-for-write char-db-file-coding-system))
1607 (insert (format ";; -*- coding: %s -*-\n"
1608 char-db-file-coding-system))
1609 (insert-char-range-data min max script excluded-script)
1610 (write-region (point-min)(point-max) file))))
1612 (defvar what-character-original-window-configuration)
1615 (defun what-char-definition (char)
1616 (interactive (list (char-after)))
1617 (let ((buf (get-buffer-create "*Character Description*"))
1618 (the-buf (current-buffer))
1619 (win-conf (current-window-configuration)))
1621 (make-local-variable 'what-character-original-window-configuration)
1622 (setq what-character-original-window-configuration win-conf)
1623 (setq buffer-read-only nil)
1627 (insert-char-data-with-variant char 'printable)
1628 (unless (char-attribute-alist char)
1629 (insert (format ";; = %c\n"
1630 (let* ((rest (split-char char))
1634 (setq code (logior (lsh code 8)
1636 (decode-char ccs code)))))
1637 ;; (char-db-update-comment)
1638 (set-buffer-modified-p nil)
1639 (view-mode the-buf (lambda (buf)
1640 (set-window-configuration
1641 what-character-original-window-configuration)
1643 (goto-char (point-min)))
1645 (set-window-configuration
1646 what-character-original-window-configuration)
1647 (signal (car err) (cdr err)))))))
1653 (provide 'char-db-util)
1655 ;;; char-db-util.el ends here