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 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
400 =>big5-cdp-itaiji-001
401 =>big5-cdp-itaiji-002
402 =>big5-cdp-itaiji-003
403 =>big5-cdp-itaiji-004
408 =>ucs@iwds-1/normalized
409 =>ucs-itaiji-001@iwds-1
410 =>ucs-itaiji-002@iwds-1
411 =>ucs-itaiji-006@iwds-1
422 ;;; @ char-db formatters
425 (defun char-db-make-char-spec (char)
427 (cond ((characterp char)
428 (cond ((and (setq ret (encode-char char '=ucs 'defined-only))
429 (not (and (<= #xE000 ret)(<= ret #xF8FF))))
430 (setq char-spec (list (cons '=ucs ret)))
431 (cond ((setq ret (get-char-attribute char 'name))
432 (setq char-spec (cons (cons 'name ret) char-spec))
434 ((setq ret (get-char-attribute char 'name*))
435 (setq char-spec (cons (cons 'name* ret) char-spec))
438 ((encode-char char '=mj 'defined-only)
440 (dolist (ccs (charset-list))
441 (if (and (or (eq ccs '=mj)
442 ;; (eq (charset-property ccs 'iso-ir) 177)
443 (string-match "=ucs@" (symbol-name ccs))
445 (setq ccs (charset-name ccs))
446 (null (assq ccs char-spec))
447 (setq ret (encode-char char ccs 'defined-only)))
448 (setq char-spec (cons (cons ccs 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 '=adobe-japan1 'defined-only)
464 (dolist (ccs (charset-list))
465 (if (and (or (memq ccs
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))))
504 (let ((rest char-db-coded-charset-priority-list)
507 (setq ccs (charset-name
508 (find-charset (car rest))))
510 (encode-char char ccs
512 (throw 'tag (cons ccs ret)))
513 (setq rest (cdr rest))))))
514 (setq char-spec (list ret))
515 (dolist (ccs (delq (car ret) (charset-list)))
516 (if (and (or (charset-iso-final-char ccs)
523 (and (eq (charset-property ccs 'iso-ir) 177)
524 (not (eq (charset-name ccs) '=ucs@big5)))
525 ;; (string-match "=ucs@" (symbol-name ccs))
527 (setq ccs (charset-name ccs))
528 (null (assq ccs char-spec))
529 (setq ret (encode-char char ccs 'defined-only)))
530 (setq char-spec (cons (cons ccs ret) char-spec))))
532 (setq char-spec (split-char char)))
533 (cond ((setq ret (get-char-attribute char 'name))
534 (setq char-spec (cons (cons 'name ret) char-spec))
536 ((setq ret (get-char-attribute char 'name*))
537 (setq char-spec (cons (cons 'name* ret) char-spec))
540 ((setq ret (get-char-attribute
541 char 'ideographic-combination))
543 (cons (cons 'ideographic-combination ret)
550 (defun char-db-insert-char-spec (char &optional readable column
553 (setq column (current-column)))
554 (let (char-spec temp-char)
555 (setq char-spec (char-db-make-char-spec char))
556 (unless (or (characterp char) ; char
558 (setq char (find-char char-spec))
560 ;; define temporary character
561 ;; Current implementation is dirty.
562 (setq temp-char (define-char (cons '(ideograph-daikanwa . 0)
564 (remove-char-attribute temp-char 'ideograph-daikanwa)
565 (setq char temp-char))
566 (insert-char-attributes char
568 (union (mapcar #'car char-spec)
572 ;; undefine temporary character
573 ;; Current implementation is dirty.
574 (setq char-spec (char-attribute-alist temp-char))
576 (remove-char-attribute temp-char (car (car char-spec)))
577 (setq char-spec (cdr char-spec))))))
579 (defun char-db-insert-alist (alist &optional readable column)
581 (setq column (current-column)))
583 (concat "\n" (make-string (1+ column) ?\ )))
587 lbs cell rest separator)
590 (setq name (car (car alist))
591 value (cdr (car alist)))
592 (cond ((eq name 'char)
594 (if (setq ret (condition-case nil
602 (setq key (car (car value)))
603 ;; (if (find-charset key)
604 ;; (setq cal (cons key cal))
605 (setq al (cons key al))
607 (setq value (cdr value)))
608 (insert-char-attributes ret
612 (insert (prin1-to-string value)))
614 (insert line-breaking))
616 (insert (format "(%-18s " name))
617 (setq lbs (concat "\n" (make-string (current-column) ?\ )))
619 (setq cell (car value))
620 (if (and (consp cell)
622 (setq ret (condition-case nil
632 (setq key (car (car rest)))
633 ;; (if (find-charset key)
634 ;; (setq cal (cons key cal))
635 (setq al (cons key al))
637 (setq rest (cdr rest)))
640 (insert-char-attributes ret
644 (setq separator lbs))
647 (insert (prin1-to-string cell))
648 (setq separator " "))
649 (setq value (cdr value)))
651 (insert line-breaking))
653 (insert (format "(%-18s . %S)%s"
656 (setq alist (cdr alist))))
659 (defun char-db-insert-char-reference (plist &optional readable column)
661 (setq column (current-column)))
663 (concat "\n" (make-string (1+ column) ?\ )))
668 (setq name (pop plist))
669 (setq value (pop plist))
670 (cond ((eq name :char)
673 (cond ((numberp value)
674 (setq value (decode-char '=ucs value)))
676 ;; (setq value (or (find-char value)
679 (char-db-insert-char-spec value readable)
680 (insert line-breaking)
683 (insert (format "%s%s\t%d ; %c%s"
686 (ideographic-radical value)
690 (insert (format "%s%s\t%S" separator name value))
691 (setq separator line-breaking)))
695 (defun char-db-decode-isolated-char (ccs code-point)
698 (cond ((eq ccs 'arabic-iso8859-6)
699 (decode-char ccs code-point))
701 ;; (decode-builtin-char '==gt code-point))
702 ((and (memq ccs '(=gt-pj-1
713 (setq ret (decode-char ccs code-point))
714 (setq ret (encode-char ret '=gt 'defined-only)))
715 (decode-builtin-char '=gt ret))
717 (decode-builtin-char ccs code-point))))
719 (or (decode-char ccs code-point)
720 (define-char (list (cons ccs code-point)))))
721 ((and (<= 0 (char-int ret))
722 (<= (char-int ret) #x1F))
723 (decode-char '=ucs (+ #x2400 (char-int ret))))
724 ((= (char-int ret) #x7F)
728 (defvar char-db-convert-obsolete-format t)
730 (defun char-db-insert-ccs-feature (name value line-breaking)
736 ((memq name '(=>iwds-1
739 =shinjigen@1ed ==shinjigen@1ed
740 =shinjigen@rev ==shinjigen@rev
741 =shinjigen/+p@rev ==shinjigen/+p@rev
742 ===daikanwa/ho ==daikanwa/ho
743 =daikanwa/ho =>>daikanwa/ho =>daikanwa/ho))
744 "(%-18s . %04d)\t; %c")
745 ((eq name '=shinjigen@1ed/24pr)
746 "(%-18s . %04d)\t; %c")
750 ==daikanwa =daikanwa =>>daikanwa =>daikanwa
751 =daikanwa@rev1 =daikanwa@rev2
752 =daikanwa/+p ==daikanwa/+p ===daikanwa/+p
754 =daikanwa/+2p =>>daikanwa/+2p
759 =adobe-japan1-0 ==adobe-japan1-0 ===adobe-japan1-0
760 =adobe-japan1-1 ==adobe-japan1-1 ===adobe-japan1-1
761 =adobe-japan1-2 ==adobe-japan1-2 ===adobe-japan1-2
762 =adobe-japan1-3 ==adobe-japan1-3 ===adobe-japan1-3
763 =adobe-japan1-4 ==adobe-japan1-4 ===adobe-japan1-4
764 =adobe-japan1-5 ==adobe-japan1-5 ===adobe-japan1-5
765 =adobe-japan1-6 ==adobe-japan1-6 ===adobe-japan1-6
766 =>>adobe-japan1-0 =+>adobe-japan1-0
767 =>>adobe-japan1-1 =+>adobe-japan1-1
768 =>>adobe-japan1-2 =+>adobe-japan1-2
769 =>>adobe-japan1-3 =+>adobe-japan1-3
770 =>>adobe-japan1-4 =+>adobe-japan1-4
771 =>>adobe-japan1-5 =+>adobe-japan1-5
772 =>>adobe-japan1-6 =+>adobe-japan1-6
773 =>cbeta =cbeta =>>cbeta ==cbeta ===cbeta
774 =zinbun-oracle =>zinbun-oracle
775 =daijiten ==daijiten ===daijiten ==>daijiten
776 ===hng-jou ===hng-keg ===hng-dng ===hng-mam
777 ===hng-drt ===hng-kgk ===hng-myz ===hng-kda
778 ===hng-khi ===hng-khm ===hng-fhs ===hng-hok
779 ===hng-kyd ===hng-sok
780 ===hng-yhk ===hng-kak ===hng-kar ===hng-kae
781 ===hng-sys ===hng-tsu ===hng-tzj
782 ===hng-hos ===hng-kkh ===hng-nak ===hng-jhk
783 ===hng-hod ===hng-gok ===hng-ink ===hng-nto
784 ===hng-nkm ===hng-k24 ===hng-ini ===hng-nkk
785 ===hng-kcc ===hng-kcj ===hng-kbk ===hng-sik
786 ===hng-skk ===hng-kyu ===hng-ksk ===hng-wan
787 ===hng-okd ===hng-wad ===hng-kmi
788 ===hng-zkd ===hng-doh ===hng-jyu ===hng-tzs
789 ===hng-sai ===hng-kad ===hng-kss
790 ===hng-kyo ===hng-ykk ===hng-saa
791 ===hng-sab ===hng-wks ===hng-wke ===hng-smk
792 ===hng-sgs ===hng-sts ===hng-kkd
793 =shuowen-jiguge ===shuowen-jiguge4 ===shuowen-jiguge5))
794 ;; (string-match "^=adobe-" (symbol-name name))
796 "(%-18s . %05d)\t; %c")
797 ((memq name '(=hanyo-denshi/ks
798 ==hanyo-denshi/ks ===hanyo-denshi/ks
801 =mj ==mj ===mj =>>mj =>mj
803 "(%-18s . %06d)\t; %c")
804 ((memq name '(=hanyo-denshi/tk ==hanyo-denshi/tk))
805 "(%-18s . %08d)\t; %c")
806 ((>= (charset-dimension name) 2)
807 "(%-18s . #x%04X)\t; %c")
809 "(%-18s . #x%02X)\t; %c"))
811 (if (= (charset-iso-graphic-plane name) 1)
813 (cond ((= (charset-dimension name) 1)
815 ((= (charset-dimension name) 2)
817 ((= (charset-dimension name) 3)
821 (char-db-decode-isolated-char name value)))
822 (if (and (= (charset-chars name) 94)
823 (= (charset-dimension name) 2))
824 (insert (format " [%02d-%02d]"
825 (- (lsh value -8) 32)
826 (- (logand value 255) 32))))
829 (insert (format "(%-18s . %s)" name value))
831 (insert line-breaking))
833 (defun char-db-insert-relation-feature (char name value line-breaking
835 (insert (format "(%-18s%s " name line-breaking))
836 (let ((lbs (concat "\n" (make-string (current-column) ?\ )))
837 separator cell sources required-features
840 (setq cell (car value))
842 (setq cell (decode-char '=ucs cell)))
844 ((eq name '->subsumptive)
845 (when (or (not (some (lambda (atr)
846 (get-char-attribute cell atr))
847 char-db-ignored-attributes))
849 (encode-char cell ccs 'defined-only))
853 (let ((char-db-ignored-attributes
855 char-db-ignored-attributes)))
856 (insert-char-attributes cell readable nil nil 'for-sub-node))
857 (setq separator lbs))
862 char (intern (format "%s*sources" name))))
863 (setq required-features nil)
864 (dolist (source sources)
868 shinjigen shinjigen@1ed shinjigen@rev))
869 (setq required-features
870 (union required-features
882 =shinjigen/+p@rev))))
884 (setq required-features
885 (union required-features
890 ((find-charset (setq ret (intern (format "=%s" source))))
891 (setq required-features
892 (cons ret required-features)))
893 (t (setq required-features
894 (cons source required-features)))))
895 (cond ((string-match "@JP" (symbol-name name))
896 (setq required-features
897 (union required-features
905 ((string-match "@CN" (symbol-name name))
906 (setq required-features
907 (union required-features
914 (insert (format "%S" cell))
915 (char-db-insert-char-spec cell readable
918 (setq separator lbs))
922 (if (consp (car cell))
923 (char-db-insert-char-spec cell readable)
924 (char-db-insert-char-reference cell readable))
925 (setq separator lbs))
929 (insert (prin1-to-string cell))
930 (setq separator " ")))
931 (setq value (cdr value)))
933 (insert line-breaking)))
935 (defun insert-char-attributes (char &optional readable attributes column
938 (setq column (current-column)))
939 (let (name value ; has-long-ccs-name
943 (concat "\n" (make-string (1+ column) ?\ )))
944 lbs cell separator ret
946 dest-ccss ; sources required-features
951 (if (consp attributes)
953 (dolist (name attributes)
954 (unless (memq name char-db-ignored-attributes)
955 (if (find-charset name)
959 (dolist (name (char-attribute-list))
960 (unless (memq name char-db-ignored-attributes)
961 (if (find-charset name)
965 #'char-attribute-name<)))
967 (when (memq '<-subsumptive attributes)
968 (when (or readable (not for-sub-node))
969 (when (setq value (get-char-attribute char '<-subsumptive))
970 (char-db-insert-relation-feature char '<-subsumptive value
973 (setq attributes (delq '<-subsumptive attributes)))
974 (when (and (memq '<-denotational attributes)
975 (setq value (get-char-attribute char '<-denotational)))
976 (char-db-insert-relation-feature char '<-denotational value
979 (setq attributes (delq '<-denotational attributes)))
980 (when (and (memq '<-denotational@component attributes)
981 (setq value (get-char-attribute char '<-denotational@component)))
982 (char-db-insert-relation-feature char '<-denotational@component value
985 (setq attributes (delq '<-denotational@component attributes)))
986 (when (and (memq '<-denotational@usage attributes)
987 (setq value (get-char-attribute char '<-denotational@usage)))
988 (char-db-insert-relation-feature char '<-denotational@usage value
991 (setq attributes (delq '<-denotational@usage attributes)))
992 (when (and (memq 'name attributes)
993 (setq value (get-char-attribute char 'name)))
995 (if (> (+ (current-column) (length value)) 48)
998 value line-breaking))
999 (setq attributes (delq 'name attributes))
1001 (when (and (memq 'name* attributes)
1002 (setq value (get-char-attribute char 'name*)))
1004 (if (> (+ (current-column) (length value)) 48)
1007 value line-breaking))
1008 (setq attributes (delq 'name* attributes))
1010 (when (and (memq 'script attributes)
1011 (setq value (get-char-attribute char 'script)))
1012 (insert (format "(script\t\t%s)%s"
1013 (mapconcat (function prin1-to-string)
1016 (setq attributes (delq 'script attributes))
1018 (dolist (name '(=>ucs =>ucs*))
1019 (when (and (memq name attributes)
1020 (setq value (get-char-attribute char name)))
1021 (insert (format "(%-18s . #x%04X)\t; %c%s"
1022 name value (decode-char '=ucs value)
1024 (setq attributes (delq name attributes))))
1025 (dolist (name '(=>ucs@gb =>ucs@big5))
1026 (when (and (memq name attributes)
1027 (setq value (get-char-attribute char name)))
1028 (insert (format "(%-18s . #x%04X)\t; %c%s"
1030 (decode-char (intern
1033 (symbol-name name) 2)))
1036 (setq attributes (delq name attributes))
1038 ;; (dolist (name '(=>daikanwa))
1039 ;; (when (and (memq name attributes)
1040 ;; (setq value (get-char-attribute char name)))
1042 ;; (if (integerp value)
1043 ;; (format "(%-18s . %05d)\t; %c%s"
1044 ;; name value (decode-char '=daikanwa value)
1046 ;; (format "(%-18s %s)\t; %c%s"
1048 ;; (mapconcat (function prin1-to-string)
1050 ;; (char-representative-of-daikanwa char)
1052 ;; (setq attributes (delq name attributes))))
1053 (when (and (memq 'general-category attributes)
1054 (setq value (get-char-attribute char 'general-category)))
1056 "(general-category\t%s) ; %s%s"
1057 (mapconcat (lambda (cell)
1060 (cond ((rassoc value unidata-normative-category-alist)
1061 "Normative Category")
1062 ((rassoc value unidata-informative-category-alist)
1063 "Informative Category")
1065 "Unknown Category"))
1067 (setq attributes (delq 'general-category attributes))
1069 (when (and (memq 'bidi-category attributes)
1070 (setq value (get-char-attribute char 'bidi-category)))
1071 (insert (format "(bidi-category\t. %S)%s"
1074 (setq attributes (delq 'bidi-category attributes))
1076 (unless (or (not (memq 'mirrored attributes))
1077 (eq (setq value (get-char-attribute char 'mirrored 'empty))
1079 (insert (format "(mirrored\t\t. %S)%s"
1082 (setq attributes (delq 'mirrored attributes))
1085 ((and (memq 'decimal-digit-value attributes)
1086 (setq value (get-char-attribute char 'decimal-digit-value)))
1087 (insert (format "(decimal-digit-value . %S)%s"
1090 (setq attributes (delq 'decimal-digit-value attributes))
1091 (when (and (memq 'digit-value attributes)
1092 (setq value (get-char-attribute char 'digit-value)))
1093 (insert (format "(digit-value\t . %S)%s"
1096 (setq attributes (delq 'digit-value attributes))
1098 (when (and (memq 'numeric-value attributes)
1099 (setq value (get-char-attribute char 'numeric-value)))
1100 (insert (format "(numeric-value\t . %S)%s"
1103 (setq attributes (delq 'numeric-value attributes))
1107 (when (and (memq 'digit-value attributes)
1108 (setq value (get-char-attribute char 'digit-value)))
1109 (insert (format "(digit-value\t. %S)%s"
1112 (setq attributes (delq 'digit-value attributes))
1114 (when (and (memq 'numeric-value attributes)
1115 (setq value (get-char-attribute char 'numeric-value)))
1116 (insert (format "(numeric-value\t. %S)%s"
1119 (setq attributes (delq 'numeric-value attributes))
1121 (when (and (memq 'iso-10646-comment attributes)
1122 (setq value (get-char-attribute char 'iso-10646-comment)))
1123 (insert (format "(iso-10646-comment\t. %S)%s"
1126 (setq attributes (delq 'iso-10646-comment attributes))
1128 (when (and (memq 'morohashi-daikanwa attributes)
1129 (setq value (get-char-attribute char 'morohashi-daikanwa)))
1130 (insert (format "(morohashi-daikanwa\t%s)%s"
1131 (mapconcat (function prin1-to-string) value " ")
1133 (setq attributes (delq 'morohashi-daikanwa attributes))
1137 (when (and (memq 'ideographic-radical attributes)
1138 (setq value (get-char-attribute char 'ideographic-radical)))
1139 (setq radical value)
1140 (insert (format "(ideographic-radical . %S)\t; %c%s"
1142 (ideographic-radical radical)
1144 (setq attributes (delq 'ideographic-radical attributes))
1146 (when (and (memq 'shuowen-radical attributes)
1147 (setq value (get-char-attribute char 'shuowen-radical)))
1148 (insert (format "(shuowen-radical\t. %S)\t; %c%s"
1150 (shuowen-radical value)
1152 (setq attributes (delq 'shuowen-radical attributes))
1157 char-db-feature-domains
1159 (dolist (feature (char-attribute-list))
1160 (setq feature (symbol-name feature))
1162 "\\(radical\\|strokes\\)@\\([^@*]+\\)\\(\\*\\|$\\)"
1164 (setq domain (intern (match-string 2 feature)))
1165 (unless (memq domain dest)
1166 (setq dest (cons domain dest)))))
1167 (sort dest #'string<))))
1168 (setq key (intern (format "%s@%s" 'ideographic-radical domain)))
1169 (when (and (memq key attributes)
1170 (setq value (get-char-attribute char key)))
1171 (setq radical value)
1172 (insert (format "(%s . %S)\t; %c%s"
1175 (ideographic-radical radical)
1177 (setq attributes (delq key attributes))
1179 (setq key (intern (format "%s@%s" 'ideographic-strokes domain)))
1180 (when (and (memq key attributes)
1181 (setq value (get-char-attribute char key)))
1182 (setq strokes value)
1183 (insert (format "(%s . %S)%s"
1187 (setq attributes (delq key attributes))
1189 (setq key (intern (format "%s@%s" 'total-strokes domain)))
1190 (when (and (memq key attributes)
1191 (setq value (get-char-attribute char key)))
1192 (insert (format "(%s . %S)%s"
1196 (setq attributes (delq key attributes))
1198 (dolist (feature '(ideographic-radical
1201 (setq key (intern (format "%s@%s*sources" feature domain)))
1202 (when (and (memq key attributes)
1203 (setq value (get-char-attribute char key)))
1204 (insert (format "(%s%s" key line-breaking))
1205 (dolist (cell value)
1206 (insert (format " %s" cell)))
1208 (insert line-breaking)
1209 (setq attributes (delq key attributes))
1212 (when (and (memq 'ideographic-strokes attributes)
1213 (setq value (get-char-attribute char 'ideographic-strokes)))
1214 (setq strokes value)
1215 (insert (format "(ideographic-strokes . %S)%s"
1218 (setq attributes (delq 'ideographic-strokes attributes))
1220 (when (and (memq 'kangxi-radical attributes)
1221 (setq value (get-char-attribute char 'kangxi-radical)))
1222 (unless (eq value radical)
1223 (insert (format "(kangxi-radical\t . %S)\t; %c%s"
1225 (ideographic-radical value)
1228 (setq radical value)))
1229 (setq attributes (delq 'kangxi-radical attributes))
1231 (when (and (memq 'kangxi-strokes attributes)
1232 (setq value (get-char-attribute char 'kangxi-strokes)))
1233 (unless (eq value strokes)
1234 (insert (format "(kangxi-strokes\t . %S)%s"
1238 (setq strokes value)))
1239 (setq attributes (delq 'kangxi-strokes attributes))
1241 ;; (when (and (memq 'japanese-radical attributes)
1242 ;; (setq value (get-char-attribute char 'japanese-radical)))
1243 ;; (unless (eq value radical)
1244 ;; (insert (format "(japanese-radical\t . %S)\t; %c%s"
1246 ;; (ideographic-radical value)
1249 ;; (setq radical value)))
1250 ;; (setq attributes (delq 'japanese-radical attributes))
1252 (when (and (memq 'japanese-strokes attributes)
1253 (setq value (get-char-attribute char 'japanese-strokes)))
1254 (unless (eq value strokes)
1255 (insert (format "(japanese-strokes\t . %S)%s"
1259 (setq strokes value)))
1260 (setq attributes (delq 'japanese-strokes attributes))
1262 (when (and (memq 'cns-radical attributes)
1263 (setq value (get-char-attribute char 'cns-radical)))
1264 (insert (format "(cns-radical\t . %S)\t; %c%s"
1266 (ideographic-radical value)
1268 (setq attributes (delq 'cns-radical attributes))
1270 (when (and (memq 'cns-strokes attributes)
1271 (setq value (get-char-attribute char 'cns-strokes)))
1272 (unless (eq value strokes)
1273 (insert (format "(cns-strokes\t . %S)%s"
1277 (setq strokes value)))
1278 (setq attributes (delq 'cns-strokes attributes))
1280 ;; (when (and (memq 'ideographic- attributes)
1281 ;; (setq value (get-char-attribute char 'ideographic-)))
1282 ;; (insert "(ideographic- ")
1283 ;; (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1285 ;; (while (consp value)
1286 ;; (setq cell (car value))
1287 ;; (if (integerp cell)
1288 ;; (setq cell (decode-char '=ucs cell)))
1289 ;; (cond ((characterp cell)
1293 ;; (insert (format "%S" cell))
1294 ;; (char-db-insert-char-spec cell readable))
1295 ;; (setq separator lbs))
1299 ;; (if (consp (car cell))
1300 ;; (char-db-insert-char-spec cell readable)
1301 ;; (char-db-insert-char-reference cell readable))
1302 ;; (setq separator lbs))
1305 ;; (insert separator))
1306 ;; (insert (prin1-to-string cell))
1307 ;; (setq separator " ")))
1308 ;; (setq value (cdr value)))
1310 ;; (insert line-breaking)
1311 ;; (setq attributes (delq 'ideographic- attributes)))
1312 (when (and (memq 'total-strokes attributes)
1313 (setq value (get-char-attribute char 'total-strokes)))
1314 (insert (format "(total-strokes . %S)%s"
1317 (setq attributes (delq 'total-strokes attributes))
1319 ;; (when (and (memq '->ideograph attributes)
1320 ;; (setq value (get-char-attribute char '->ideograph)))
1321 ;; (insert (format "(->ideograph\t%s)%s"
1322 ;; (mapconcat (lambda (code)
1323 ;; (cond ((symbolp code)
1324 ;; (symbol-name code))
1326 ;; (format "#x%04X" code))
1329 ;; line-breaking code))))
1332 ;; (setq attributes (delq '->ideograph attributes))
1334 ;; (when (and (memq '->decomposition attributes)
1335 ;; (setq value (get-char-attribute char '->decomposition)))
1336 ;; (insert (format "(->decomposition\t%s)%s"
1337 ;; (mapconcat (lambda (code)
1338 ;; (cond ((symbolp code)
1339 ;; (symbol-name code))
1340 ;; ((characterp code)
1342 ;; (format "%S" code)
1347 ;; (format "#x%04X" code))
1349 ;; (format "%s%S" line-breaking code))))
1352 ;; (setq attributes (delq '->decomposition attributes))
1354 (if (equal (get-char-attribute char '->titlecase)
1355 (get-char-attribute char '->uppercase))
1356 (setq attributes (delq '->titlecase attributes)))
1357 (when (and (memq '->mojikyo attributes)
1358 (setq value (get-char-attribute char '->mojikyo)))
1359 (insert (format "(->mojikyo\t\t. %06d)\t; %c%s"
1360 value (decode-char 'mojikyo value)
1362 (setq attributes (delq '->mojikyo attributes))
1365 (dolist (ignored '(composition
1366 ->denotational <-subsumptive ->ucs-unified
1367 ;; ->ideographic-component-forms
1369 (setq attributes (delq ignored attributes))))
1371 (setq name (car attributes))
1372 (unless (eq (setq value (get-char-attribute char name 'value-is-empty))
1374 (cond ((setq ret (find-charset name))
1375 (setq name (charset-name ret))
1376 (when (not (memq name dest-ccss))
1377 (setq dest-ccss (cons name dest-ccss))
1378 (char-db-insert-ccs-feature name value line-breaking))
1380 ((string-match "^=>ucs@" (symbol-name name))
1381 (insert (format "(%-18s . #x%04X)\t; %c%s"
1382 name value (decode-char '=ucs value)
1385 ((eq name 'jisx0208-1978/4X)
1386 (insert (format "(%-18s . #x%04X)%s"
1392 (not (eq name '->subsumptive))
1393 (not (eq name '->uppercase))
1394 (not (eq name '->lowercase))
1395 (not (eq name '->titlecase))
1396 (not (eq name '->canonical))
1397 (not (eq name '->Bopomofo))
1398 (not (eq name '->mistakable))
1399 (not (eq name '->ideographic-variants))
1400 (null (get-char-attribute
1401 char (intern (format "%s*sources" name))))
1402 (not (string-match "\\*sources$" (symbol-name name)))
1403 (null (get-char-attribute
1404 char (intern (format "%s*note" name))))
1405 (not (string-match "\\*note$" (symbol-name name)))
1406 (or (eq name '<-identical)
1407 (eq name '<-uppercase)
1408 (eq name '<-lowercase)
1409 (eq name '<-titlecase)
1410 (eq name '<-canonical)
1411 (eq name '<-ideographic-variants)
1412 ;; (eq name '<-synonyms)
1413 (string-match "^<-synonyms" (symbol-name name))
1414 (eq name '<-mistakable)
1415 (when (string-match "^->" (symbol-name name))
1417 ((string-match "^->fullwidth" (symbol-name name))
1418 (not (and (consp value)
1419 (characterp (car value))
1421 (car value) '=ucs 'defined-only)))
1426 ((or (eq name 'ideographic-structure)
1427 (eq name 'ideographic-structure@apparent)
1428 (eq name 'ideographic-structure@apparent/leftmost)
1429 (eq name 'ideographic-combination)
1430 ;; (eq name 'ideographic-)
1431 (eq name '=decomposition)
1432 (char-feature-base-name= '=decomposition name)
1433 (char-feature-base-name= '=>decomposition name)
1434 ;; (string-match "^=>*decomposition\\(@[^*]+\\)?$"
1435 ;; (symbol-name name))
1436 (string-match "^\\(->\\|<-\\)[^*]*$" (symbol-name name))
1437 (string-match "^\\(->\\|<-\\)[^*]*\\*sources$"
1440 (char-db-insert-relation-feature char name value
1443 ;; ((memq name '(ideograph=
1444 ;; original-ideograph-of
1445 ;; ancient-ideograph-of
1446 ;; vulgar-ideograph-of
1447 ;; wrong-ideograph-of
1448 ;; ;; simplified-ideograph-of
1449 ;; ideographic-variants
1450 ;; ;; ideographic-different-form-of
1452 ;; (insert (format "(%-18s%s " name line-breaking))
1453 ;; (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1455 ;; (while (consp value)
1456 ;; (setq cell (car value))
1457 ;; (if (and (consp cell)
1458 ;; (consp (car cell)))
1462 ;; (char-db-insert-alist cell readable)
1463 ;; (setq separator lbs))
1465 ;; (insert separator))
1466 ;; (insert (prin1-to-string cell))
1467 ;; (setq separator " "))
1468 ;; (setq value (cdr value)))
1470 ;; (insert line-breaking))
1472 (insert (format "(%-18s " name))
1473 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1475 (while (consp value)
1476 (setq cell (car value))
1477 (if (and (consp cell)
1479 (setq ret (condition-case nil
1487 (setq key (car (car rest)))
1488 (if (find-charset key)
1489 (setq cal (cons key cal))
1490 (setq al (cons key al)))
1491 (setq rest (cdr rest)))
1494 (insert-char-attributes ret
1498 (setq separator lbs))
1499 (setq ret (prin1-to-string cell))
1501 (if (< (+ (current-column)
1508 (setq separator " "))
1509 (setq value (cdr value)))
1511 (insert line-breaking))
1513 (insert (format "(%-18s" name))
1514 (setq ret (prin1-to-string value))
1515 (unless (< (+ (current-column)
1519 (insert line-breaking))
1520 (insert " . " ret ")" line-breaking)
1521 ;; (insert (format "(%-18s . %S)%s"
1526 (setq attributes (cdr attributes)))
1529 (defun insert-char-data (char &optional readable
1532 (narrow-to-region (point)(point))
1533 (insert "(define-char
1535 (insert-char-attributes char readable attributes)
1537 (goto-char (point-min))
1538 (while (re-search-forward "[ \t]+$" nil t)
1541 (goto-char (point-min))
1542 (while (re-search-forward "[ \t][ \t][ \t]*" nil t)
1543 (let ((column (current-column))
1544 (indent-tabs-mode t))
1545 (delete-region (match-beginning 0) (point))
1546 (indent-to column)))
1547 (goto-char (point-max))
1548 ;; (tabify (point-min)(point-max))
1551 (defun insert-char-data-with-variant (char &optional printable
1553 script excluded-script)
1554 (insert-char-data char printable)
1555 (let ((variants (char-variants char))
1558 (setq variants (sort variants #'<))
1559 (setq rest variants)
1560 (setq variants (cons char variants))
1562 (setq variant (car rest))
1563 (unless (get-char-attribute variant '<-subsumptive)
1564 (if (and (or (null script)
1565 (null (setq vs (get-char-attribute variant 'script)))
1567 (or (null excluded-script)
1568 (null (setq vs (get-char-attribute variant 'script)))
1569 (not (memq excluded-script vs))))
1570 (unless (and no-ucs-unified (get-char-attribute variant '=ucs))
1571 (insert-char-data variant printable)
1572 (if (setq ret (char-variants variant))
1574 (or (memq (car ret) variants)
1575 ;; (get-char-attribute (car ret) '<-subsumptive)
1576 (setq rest (nconc rest (list (car ret)))))
1577 (setq ret (cdr ret)))))))
1578 (setq rest (cdr rest)))))
1580 (defun insert-char-range-data (min max &optional script excluded-script)
1583 (while (<= code max)
1584 (setq char (decode-char '=ucs code))
1585 (if (encode-char char '=ucs 'defined-only)
1586 (insert-char-data-with-variant char nil 'no-ucs-unified
1587 script excluded-script))
1588 (setq code (1+ code)))))
1590 (defun write-char-range-data-to-file (min max file
1591 &optional script excluded-script)
1592 (let ((coding-system-for-write char-db-file-coding-system))
1594 (insert (format ";; -*- coding: %s -*-\n"
1595 char-db-file-coding-system))
1596 (insert-char-range-data min max script excluded-script)
1597 (write-region (point-min)(point-max) file))))
1599 (defvar what-character-original-window-configuration)
1602 (defun what-char-definition (char)
1603 (interactive (list (char-after)))
1604 (let ((buf (get-buffer-create "*Character Description*"))
1605 (the-buf (current-buffer))
1606 (win-conf (current-window-configuration)))
1608 (make-local-variable 'what-character-original-window-configuration)
1609 (setq what-character-original-window-configuration win-conf)
1610 (setq buffer-read-only nil)
1614 (insert-char-data-with-variant char 'printable)
1615 (unless (char-attribute-alist char)
1616 (insert (format ";; = %c\n"
1617 (let* ((rest (split-char char))
1621 (setq code (logior (lsh code 8)
1623 (decode-char ccs code)))))
1624 ;; (char-db-update-comment)
1625 (set-buffer-modified-p nil)
1626 (view-mode the-buf (lambda (buf)
1627 (set-window-configuration
1628 what-character-original-window-configuration)
1630 (goto-char (point-min)))
1632 (set-window-configuration
1633 what-character-original-window-configuration)
1634 (signal (car err) (cdr err)))))))
1640 (provide 'char-db-util)
1642 ;;; char-db-util.el ends here