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
401 =>big5-cdp-itaiji-001
402 =>big5-cdp-itaiji-002
403 =>big5-cdp-itaiji-003
404 =>big5-cdp-itaiji-004
409 =>ucs@iwds-1/normalized
410 =>ucs-itaiji-001@iwds-1
411 =>ucs-itaiji-002@iwds-1
412 =>ucs-itaiji-003@iwds-1
413 =>ucs-itaiji-006@iwds-1
426 ;;; @ char-db formatters
429 (defun char-db-make-char-spec (char)
431 (cond ((characterp char)
432 (cond ((and (setq ret (encode-char char '=ucs 'defined-only))
433 (not (and (<= #xE000 ret)(<= ret #xF8FF))))
434 (setq char-spec (list (cons '=ucs ret)))
435 (cond ((setq ret (get-char-attribute char 'name))
436 (setq char-spec (cons (cons 'name ret) char-spec))
438 ((setq ret (get-char-attribute char 'name*))
439 (setq char-spec (cons (cons 'name* ret) char-spec))
442 ((encode-char char '=mj 'defined-only)
444 (dolist (ccs (charset-list))
445 (if (and (or (eq ccs '=mj)
446 ;; (eq (charset-property ccs 'iso-ir) 177)
447 (string-match "=ucs@" (symbol-name ccs))
449 (setq ccs (charset-name ccs))
450 (null (assq ccs char-spec))
451 (setq ret (encode-char char ccs 'defined-only)))
452 (setq char-spec (cons (cons ccs ret) char-spec))))
454 ((encode-char char '==mj 'defined-only)
456 (dolist (ccs (charset-list))
457 (if (and (or (eq ccs '==mj)
458 ;; (eq (charset-property ccs 'iso-ir) 177)
459 (string-match "=ucs@" (symbol-name ccs))
461 (setq ccs (charset-name ccs))
462 (null (assq ccs char-spec))
463 (setq ret (encode-char char ccs 'defined-only)))
464 (setq char-spec (cons (cons ccs ret) char-spec))))
466 ((encode-char char '=adobe-japan1 'defined-only)
468 (dolist (ccs (charset-list))
469 (if (and (or (memq ccs
478 ;; (eq (charset-property ccs 'iso-ir) 177)
479 (string-match "=ucs@" (symbol-name ccs))
481 (setq ccs (charset-name ccs))
482 (null (assq ccs char-spec))
483 (setq ret (encode-char char ccs 'defined-only)))
484 (setq char-spec (cons (cons ccs ret) char-spec))))
486 ((encode-char char '==adobe-japan1 'defined-only)
488 (dolist (ccs (charset-list))
489 (if (and (or (memq ccs
498 ;; (eq (charset-property ccs 'iso-ir) 177)
499 (string-match "=ucs@" (symbol-name ccs))
501 (setq ccs (charset-name ccs))
502 (null (assq ccs char-spec))
503 (setq ret (encode-char char ccs 'defined-only)))
504 (setq char-spec (cons (cons ccs ret) char-spec))))
508 (let ((rest char-db-coded-charset-priority-list)
511 (setq ccs (charset-name
512 (find-charset (car rest))))
514 (encode-char char ccs
516 (throw 'tag (cons ccs ret)))
517 (setq rest (cdr rest))))))
518 (setq char-spec (list ret))
519 (dolist (ccs (delq (car ret) (charset-list)))
520 (if (and (or (charset-iso-final-char ccs)
527 (and (eq (charset-property ccs 'iso-ir) 177)
528 (not (eq (charset-name ccs) '=ucs@big5)))
529 ;; (string-match "=ucs@" (symbol-name ccs))
531 (setq ccs (charset-name ccs))
532 (null (assq ccs char-spec))
533 (setq ret (encode-char char ccs 'defined-only)))
534 (setq char-spec (cons (cons ccs ret) char-spec))))
536 (setq char-spec (split-char char)))
537 (cond ((setq ret (get-char-attribute char 'name))
538 (setq char-spec (cons (cons 'name ret) char-spec))
540 ((setq ret (get-char-attribute char 'name*))
541 (setq char-spec (cons (cons 'name* ret) char-spec))
544 ((setq ret (get-char-attribute
545 char 'ideographic-combination))
547 (cons (cons 'ideographic-combination ret)
554 (defun char-db-insert-char-spec (char &optional readable column
557 (setq column (current-column)))
558 (let (char-spec temp-char)
559 (setq char-spec (char-db-make-char-spec char))
560 (unless (or (characterp char) ; char
562 (setq char (find-char char-spec))
564 ;; define temporary character
565 ;; Current implementation is dirty.
566 (setq temp-char (define-char (cons '(ideograph-daikanwa . 0)
568 (remove-char-attribute temp-char 'ideograph-daikanwa)
569 (setq char temp-char))
570 (insert-char-attributes char
572 (union (mapcar #'car char-spec)
576 ;; undefine temporary character
577 ;; Current implementation is dirty.
578 (setq char-spec (char-attribute-alist temp-char))
580 (remove-char-attribute temp-char (car (car char-spec)))
581 (setq char-spec (cdr char-spec))))))
583 (defun char-db-insert-alist (alist &optional readable column)
585 (setq column (current-column)))
587 (concat "\n" (make-string (1+ column) ?\ )))
591 lbs cell rest separator)
594 (setq name (car (car alist))
595 value (cdr (car alist)))
596 (cond ((eq name 'char)
598 (if (setq ret (condition-case nil
606 (setq key (car (car value)))
607 ;; (if (find-charset key)
608 ;; (setq cal (cons key cal))
609 (setq al (cons key al))
611 (setq value (cdr value)))
612 (insert-char-attributes ret
616 (insert (prin1-to-string value)))
618 (insert line-breaking))
620 (insert (format "(%-18s " name))
621 (setq lbs (concat "\n" (make-string (current-column) ?\ )))
623 (setq cell (car value))
624 (if (and (consp cell)
626 (setq ret (condition-case nil
636 (setq key (car (car rest)))
637 ;; (if (find-charset key)
638 ;; (setq cal (cons key cal))
639 (setq al (cons key al))
641 (setq rest (cdr rest)))
644 (insert-char-attributes ret
648 (setq separator lbs))
651 (insert (prin1-to-string cell))
652 (setq separator " "))
653 (setq value (cdr value)))
655 (insert line-breaking))
657 (insert (format "(%-18s . %S)%s"
660 (setq alist (cdr alist))))
663 (defun char-db-insert-char-reference (plist &optional readable column)
665 (setq column (current-column)))
667 (concat "\n" (make-string (1+ column) ?\ )))
672 (setq name (pop plist))
673 (setq value (pop plist))
674 (cond ((eq name :char)
677 (cond ((numberp value)
678 (setq value (decode-char '=ucs value)))
680 ;; (setq value (or (find-char value)
683 (char-db-insert-char-spec value readable)
684 (insert line-breaking)
687 (insert (format "%s%s\t%d ; %c%s"
690 (ideographic-radical value)
694 (insert (format "%s%s\t%S" separator name value))
695 (setq separator line-breaking)))
699 (defun char-db-decode-isolated-char (ccs code-point)
702 (cond ((eq ccs 'arabic-iso8859-6)
703 (decode-char ccs code-point))
705 ;; (decode-builtin-char '==gt code-point))
706 ((and (memq ccs '(=gt-pj-1
717 (setq ret (decode-char ccs code-point))
718 (setq ret (encode-char ret '=gt 'defined-only)))
719 (decode-builtin-char '=gt ret))
721 (decode-builtin-char ccs code-point))))
723 (or (decode-char ccs code-point)
724 (define-char (list (cons ccs code-point)))))
725 ((and (<= 0 (char-int ret))
726 (<= (char-int ret) #x1F))
727 (decode-char '=ucs (+ #x2400 (char-int ret))))
728 ((= (char-int ret) #x7F)
732 (defvar char-db-convert-obsolete-format t)
734 (defun char-db-insert-ccs-feature (name value line-breaking)
740 ((memq name '(=>iwds-1
743 =shinjigen@1ed ==shinjigen@1ed
744 =shinjigen@rev ==shinjigen@rev
745 =shinjigen/+p@rev ==shinjigen/+p@rev
746 ===daikanwa/ho ==daikanwa/ho
747 =daikanwa/ho =>>daikanwa/ho =>daikanwa/ho))
748 "(%-18s . %04d)\t; %c")
749 ((eq name '=shinjigen@1ed/24pr)
750 "(%-18s . %04d)\t; %c")
754 ==daikanwa =daikanwa =>>daikanwa =>daikanwa
755 =daikanwa@rev1 =daikanwa@rev2
756 =daikanwa/+p ==daikanwa/+p ===daikanwa/+p
758 =daikanwa/+2p =>>daikanwa/+2p
763 =adobe-japan1-0 ==adobe-japan1-0 ===adobe-japan1-0
764 =adobe-japan1-1 ==adobe-japan1-1 ===adobe-japan1-1
765 =adobe-japan1-2 ==adobe-japan1-2 ===adobe-japan1-2
766 =adobe-japan1-3 ==adobe-japan1-3 ===adobe-japan1-3
767 =adobe-japan1-4 ==adobe-japan1-4 ===adobe-japan1-4
768 =adobe-japan1-5 ==adobe-japan1-5 ===adobe-japan1-5
769 =adobe-japan1-6 ==adobe-japan1-6 ===adobe-japan1-6
770 =>>adobe-japan1-0 =+>adobe-japan1-0
771 =>>adobe-japan1-1 =+>adobe-japan1-1
772 =>>adobe-japan1-2 =+>adobe-japan1-2
773 =>>adobe-japan1-3 =+>adobe-japan1-3
774 =>>adobe-japan1-4 =+>adobe-japan1-4
775 =>>adobe-japan1-5 =+>adobe-japan1-5
776 =>>adobe-japan1-6 =+>adobe-japan1-6
777 =>cbeta =cbeta =>>cbeta ==cbeta ===cbeta
778 =zinbun-oracle =>zinbun-oracle
779 =daijiten ==daijiten ===daijiten ==>daijiten
780 ===hng-jou ===hng-keg ===hng-dng ===hng-mam
781 ===hng-drt ===hng-kgk ===hng-myz ===hng-kda
782 ===hng-khi ===hng-khm ===hng-fhs ===hng-hok
783 ===hng-kyd ===hng-sok
784 ===hng-yhk ===hng-kak ===hng-kar ===hng-kae
785 ===hng-sys ===hng-tsu ===hng-tzj
786 ===hng-hos ===hng-kkh ===hng-nak ===hng-jhk
787 ===hng-hod ===hng-gok ===hng-ink ===hng-nto
788 ===hng-nkm ===hng-k24 ===hng-ini ===hng-nkk
789 ===hng-kcc ===hng-kcj ===hng-kbk ===hng-sik
790 ===hng-skk ===hng-kyu ===hng-ksk ===hng-wan
791 ===hng-okd ===hng-wad ===hng-kmi
792 ===hng-zkd ===hng-doh ===hng-jyu ===hng-tzs
793 ===hng-sai ===hng-kad ===hng-kss
794 ===hng-kyo ===hng-ykk ===hng-saa
795 ===hng-sab ===hng-wks ===hng-wke ===hng-smk
796 ===hng-sgs ===hng-sts ===hng-kkd
797 =shuowen-jiguge ===shuowen-jiguge4 ===shuowen-jiguge5))
798 ;; (string-match "^=adobe-" (symbol-name name))
800 "(%-18s . %05d)\t; %c")
801 ((memq name '(=hanyo-denshi/ks
802 ==hanyo-denshi/ks ===hanyo-denshi/ks
805 =mj ==mj ===mj =>>mj =>mj
807 "(%-18s . %06d)\t; %c")
808 ((memq name '(=hanyo-denshi/tk ==hanyo-denshi/tk))
809 "(%-18s . %08d)\t; %c")
810 ((>= (charset-dimension name) 2)
811 "(%-18s . #x%04X)\t; %c")
813 "(%-18s . #x%02X)\t; %c"))
815 (if (= (charset-iso-graphic-plane name) 1)
817 (cond ((= (charset-dimension name) 1)
819 ((= (charset-dimension name) 2)
821 ((= (charset-dimension name) 3)
825 (char-db-decode-isolated-char name value)))
826 (if (and (= (charset-chars name) 94)
827 (= (charset-dimension name) 2))
828 (insert (format " [%02d-%02d]"
829 (- (lsh value -8) 32)
830 (- (logand value 255) 32))))
833 (insert (format "(%-18s . %s)" name value))
835 (insert line-breaking))
837 (defun char-db-insert-relation-feature (char name value line-breaking
839 (insert (format "(%-18s%s " name line-breaking))
840 (let ((lbs (concat "\n" (make-string (current-column) ?\ )))
841 separator cell sources required-features
844 (setq cell (car value))
846 (setq cell (decode-char '=ucs cell)))
848 ((eq name '->subsumptive)
849 (when (or (not (some (lambda (atr)
850 (get-char-attribute cell atr))
851 char-db-ignored-attributes))
853 (encode-char cell ccs 'defined-only))
857 (let ((char-db-ignored-attributes
859 char-db-ignored-attributes)))
860 (insert-char-attributes cell readable nil nil 'for-sub-node))
861 (setq separator lbs))
866 char (intern (format "%s*sources" name))))
867 (setq required-features nil)
868 (dolist (source sources)
872 shinjigen shinjigen@1ed shinjigen@rev))
873 (setq required-features
874 (union required-features
886 =shinjigen/+p@rev))))
888 (setq required-features
889 (union required-features
894 ((find-charset (setq ret (intern (format "=%s" source))))
895 (setq required-features
896 (cons ret required-features)))
897 (t (setq required-features
898 (cons source required-features)))))
899 (cond ((string-match "@JP" (symbol-name name))
900 (setq required-features
901 (union required-features
909 ((string-match "@CN" (symbol-name name))
910 (setq required-features
911 (union required-features
918 (insert (format "%S" cell))
919 (char-db-insert-char-spec cell readable
922 (setq separator lbs))
926 (if (consp (car cell))
927 (char-db-insert-char-spec cell readable)
928 (char-db-insert-char-reference cell readable))
929 (setq separator lbs))
933 (insert (prin1-to-string cell))
934 (setq separator " ")))
935 (setq value (cdr value)))
937 (insert line-breaking)))
939 (defun insert-char-attributes (char &optional readable attributes column
942 (setq column (current-column)))
943 (let (name value ; has-long-ccs-name
947 (concat "\n" (make-string (1+ column) ?\ )))
948 lbs cell separator ret
950 dest-ccss ; sources required-features
955 (if (consp attributes)
957 (dolist (name attributes)
958 (unless (memq name char-db-ignored-attributes)
959 (if (find-charset name)
963 (dolist (name (char-attribute-list))
964 (unless (memq name char-db-ignored-attributes)
965 (if (find-charset name)
969 #'char-attribute-name<)))
971 (when (memq '<-subsumptive attributes)
972 (when (or readable (not for-sub-node))
973 (when (setq value (get-char-attribute char '<-subsumptive))
974 (char-db-insert-relation-feature char '<-subsumptive value
977 (setq attributes (delq '<-subsumptive attributes)))
978 (when (and (memq '<-denotational attributes)
979 (setq value (get-char-attribute char '<-denotational)))
980 (char-db-insert-relation-feature char '<-denotational value
983 (setq attributes (delq '<-denotational attributes)))
984 (when (and (memq '<-denotational@component attributes)
985 (setq value (get-char-attribute char '<-denotational@component)))
986 (char-db-insert-relation-feature char '<-denotational@component value
989 (setq attributes (delq '<-denotational@component attributes)))
990 (when (and (memq '<-denotational@usage attributes)
991 (setq value (get-char-attribute char '<-denotational@usage)))
992 (char-db-insert-relation-feature char '<-denotational@usage value
995 (setq attributes (delq '<-denotational@usage attributes)))
996 (when (and (memq 'name attributes)
997 (setq value (get-char-attribute char 'name)))
999 (if (> (+ (current-column) (length value)) 48)
1002 value line-breaking))
1003 (setq attributes (delq 'name 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 'script attributes)
1015 (setq value (get-char-attribute char 'script)))
1016 (insert (format "(script\t\t%s)%s"
1017 (mapconcat (function prin1-to-string)
1020 (setq attributes (delq 'script attributes))
1022 (dolist (name '(=>ucs =>ucs*))
1023 (when (and (memq name attributes)
1024 (setq value (get-char-attribute char name)))
1025 (insert (format "(%-18s . #x%04X)\t; %c%s"
1026 name value (decode-char '=ucs value)
1028 (setq attributes (delq name attributes))))
1029 (dolist (name '(=>ucs@gb =>ucs@big5))
1030 (when (and (memq name attributes)
1031 (setq value (get-char-attribute char name)))
1032 (insert (format "(%-18s . #x%04X)\t; %c%s"
1034 (decode-char (intern
1037 (symbol-name name) 2)))
1040 (setq attributes (delq name attributes))
1042 ;; (dolist (name '(=>daikanwa))
1043 ;; (when (and (memq name attributes)
1044 ;; (setq value (get-char-attribute char name)))
1046 ;; (if (integerp value)
1047 ;; (format "(%-18s . %05d)\t; %c%s"
1048 ;; name value (decode-char '=daikanwa value)
1050 ;; (format "(%-18s %s)\t; %c%s"
1052 ;; (mapconcat (function prin1-to-string)
1054 ;; (char-representative-of-daikanwa char)
1056 ;; (setq attributes (delq name attributes))))
1057 (when (and (memq 'general-category attributes)
1058 (setq value (get-char-attribute char 'general-category)))
1060 "(general-category\t%s) ; %s%s"
1061 (mapconcat (lambda (cell)
1064 (cond ((rassoc value unidata-normative-category-alist)
1065 "Normative Category")
1066 ((rassoc value unidata-informative-category-alist)
1067 "Informative Category")
1069 "Unknown Category"))
1071 (setq attributes (delq 'general-category attributes))
1073 (when (and (memq 'bidi-category attributes)
1074 (setq value (get-char-attribute char 'bidi-category)))
1075 (insert (format "(bidi-category\t. %S)%s"
1078 (setq attributes (delq 'bidi-category attributes))
1080 (unless (or (not (memq 'mirrored attributes))
1081 (eq (setq value (get-char-attribute char 'mirrored 'empty))
1083 (insert (format "(mirrored\t\t. %S)%s"
1086 (setq attributes (delq 'mirrored attributes))
1089 ((and (memq 'decimal-digit-value attributes)
1090 (setq value (get-char-attribute char 'decimal-digit-value)))
1091 (insert (format "(decimal-digit-value . %S)%s"
1094 (setq attributes (delq 'decimal-digit-value attributes))
1095 (when (and (memq 'digit-value attributes)
1096 (setq value (get-char-attribute char 'digit-value)))
1097 (insert (format "(digit-value\t . %S)%s"
1100 (setq attributes (delq 'digit-value attributes))
1102 (when (and (memq 'numeric-value attributes)
1103 (setq value (get-char-attribute char 'numeric-value)))
1104 (insert (format "(numeric-value\t . %S)%s"
1107 (setq attributes (delq 'numeric-value attributes))
1111 (when (and (memq 'digit-value attributes)
1112 (setq value (get-char-attribute char 'digit-value)))
1113 (insert (format "(digit-value\t. %S)%s"
1116 (setq attributes (delq 'digit-value attributes))
1118 (when (and (memq 'numeric-value attributes)
1119 (setq value (get-char-attribute char 'numeric-value)))
1120 (insert (format "(numeric-value\t. %S)%s"
1123 (setq attributes (delq 'numeric-value attributes))
1125 (when (and (memq 'iso-10646-comment attributes)
1126 (setq value (get-char-attribute char 'iso-10646-comment)))
1127 (insert (format "(iso-10646-comment\t. %S)%s"
1130 (setq attributes (delq 'iso-10646-comment attributes))
1132 (when (and (memq 'morohashi-daikanwa attributes)
1133 (setq value (get-char-attribute char 'morohashi-daikanwa)))
1134 (insert (format "(morohashi-daikanwa\t%s)%s"
1135 (mapconcat (function prin1-to-string) value " ")
1137 (setq attributes (delq 'morohashi-daikanwa attributes))
1141 (when (and (memq 'ideographic-radical attributes)
1142 (setq value (get-char-attribute char 'ideographic-radical)))
1143 (setq radical value)
1144 (insert (format "(ideographic-radical . %S)\t; %c%s"
1146 (ideographic-radical radical)
1148 (setq attributes (delq 'ideographic-radical attributes))
1150 (when (and (memq 'shuowen-radical attributes)
1151 (setq value (get-char-attribute char 'shuowen-radical)))
1152 (insert (format "(shuowen-radical\t. %S)\t; %c%s"
1154 (shuowen-radical value)
1156 (setq attributes (delq 'shuowen-radical attributes))
1161 char-db-feature-domains
1163 (dolist (feature (char-attribute-list))
1164 (setq feature (symbol-name feature))
1166 "\\(radical\\|strokes\\)@\\([^@*]+\\)\\(\\*\\|$\\)"
1168 (setq domain (intern (match-string 2 feature)))
1169 (unless (memq domain dest)
1170 (setq dest (cons domain dest)))))
1171 (sort dest #'string<))))
1172 (setq key (intern (format "%s@%s" 'ideographic-radical domain)))
1173 (when (and (memq key attributes)
1174 (setq value (get-char-attribute char key)))
1175 (setq radical value)
1176 (insert (format "(%s . %S)\t; %c%s"
1179 (ideographic-radical radical)
1181 (setq attributes (delq key attributes))
1183 (setq key (intern (format "%s@%s" 'ideographic-strokes domain)))
1184 (when (and (memq key attributes)
1185 (setq value (get-char-attribute char key)))
1186 (setq strokes value)
1187 (insert (format "(%s . %S)%s"
1191 (setq attributes (delq key attributes))
1193 (setq key (intern (format "%s@%s" 'total-strokes domain)))
1194 (when (and (memq key attributes)
1195 (setq value (get-char-attribute char key)))
1196 (insert (format "(%s . %S)%s"
1200 (setq attributes (delq key attributes))
1202 (dolist (feature '(ideographic-radical
1205 (setq key (intern (format "%s@%s*sources" feature domain)))
1206 (when (and (memq key attributes)
1207 (setq value (get-char-attribute char key)))
1208 (insert (format "(%s%s" key line-breaking))
1209 (dolist (cell value)
1210 (insert (format " %s" cell)))
1212 (insert line-breaking)
1213 (setq attributes (delq key attributes))
1216 (when (and (memq 'ideographic-strokes attributes)
1217 (setq value (get-char-attribute char 'ideographic-strokes)))
1218 (setq strokes value)
1219 (insert (format "(ideographic-strokes . %S)%s"
1222 (setq attributes (delq 'ideographic-strokes attributes))
1224 (when (and (memq 'kangxi-radical attributes)
1225 (setq value (get-char-attribute char 'kangxi-radical)))
1226 (unless (eq value radical)
1227 (insert (format "(kangxi-radical\t . %S)\t; %c%s"
1229 (ideographic-radical value)
1232 (setq radical value)))
1233 (setq attributes (delq 'kangxi-radical attributes))
1235 (when (and (memq 'kangxi-strokes attributes)
1236 (setq value (get-char-attribute char 'kangxi-strokes)))
1237 (unless (eq value strokes)
1238 (insert (format "(kangxi-strokes\t . %S)%s"
1242 (setq strokes value)))
1243 (setq attributes (delq 'kangxi-strokes attributes))
1245 ;; (when (and (memq 'japanese-radical attributes)
1246 ;; (setq value (get-char-attribute char 'japanese-radical)))
1247 ;; (unless (eq value radical)
1248 ;; (insert (format "(japanese-radical\t . %S)\t; %c%s"
1250 ;; (ideographic-radical value)
1253 ;; (setq radical value)))
1254 ;; (setq attributes (delq 'japanese-radical attributes))
1256 (when (and (memq 'japanese-strokes attributes)
1257 (setq value (get-char-attribute char 'japanese-strokes)))
1258 (unless (eq value strokes)
1259 (insert (format "(japanese-strokes\t . %S)%s"
1263 (setq strokes value)))
1264 (setq attributes (delq 'japanese-strokes attributes))
1266 (when (and (memq 'cns-radical attributes)
1267 (setq value (get-char-attribute char 'cns-radical)))
1268 (insert (format "(cns-radical\t . %S)\t; %c%s"
1270 (ideographic-radical value)
1272 (setq attributes (delq 'cns-radical attributes))
1274 (when (and (memq 'cns-strokes attributes)
1275 (setq value (get-char-attribute char 'cns-strokes)))
1276 (unless (eq value strokes)
1277 (insert (format "(cns-strokes\t . %S)%s"
1281 (setq strokes value)))
1282 (setq attributes (delq 'cns-strokes attributes))
1284 ;; (when (and (memq 'ideographic- attributes)
1285 ;; (setq value (get-char-attribute char 'ideographic-)))
1286 ;; (insert "(ideographic- ")
1287 ;; (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1289 ;; (while (consp value)
1290 ;; (setq cell (car value))
1291 ;; (if (integerp cell)
1292 ;; (setq cell (decode-char '=ucs cell)))
1293 ;; (cond ((characterp cell)
1297 ;; (insert (format "%S" cell))
1298 ;; (char-db-insert-char-spec cell readable))
1299 ;; (setq separator lbs))
1303 ;; (if (consp (car cell))
1304 ;; (char-db-insert-char-spec cell readable)
1305 ;; (char-db-insert-char-reference cell readable))
1306 ;; (setq separator lbs))
1309 ;; (insert separator))
1310 ;; (insert (prin1-to-string cell))
1311 ;; (setq separator " ")))
1312 ;; (setq value (cdr value)))
1314 ;; (insert line-breaking)
1315 ;; (setq attributes (delq 'ideographic- attributes)))
1316 (when (and (memq 'total-strokes attributes)
1317 (setq value (get-char-attribute char 'total-strokes)))
1318 (insert (format "(total-strokes . %S)%s"
1321 (setq attributes (delq 'total-strokes attributes))
1323 ;; (when (and (memq '->ideograph attributes)
1324 ;; (setq value (get-char-attribute char '->ideograph)))
1325 ;; (insert (format "(->ideograph\t%s)%s"
1326 ;; (mapconcat (lambda (code)
1327 ;; (cond ((symbolp code)
1328 ;; (symbol-name code))
1330 ;; (format "#x%04X" code))
1333 ;; line-breaking code))))
1336 ;; (setq attributes (delq '->ideograph attributes))
1338 ;; (when (and (memq '->decomposition attributes)
1339 ;; (setq value (get-char-attribute char '->decomposition)))
1340 ;; (insert (format "(->decomposition\t%s)%s"
1341 ;; (mapconcat (lambda (code)
1342 ;; (cond ((symbolp code)
1343 ;; (symbol-name code))
1344 ;; ((characterp code)
1346 ;; (format "%S" code)
1351 ;; (format "#x%04X" code))
1353 ;; (format "%s%S" line-breaking code))))
1356 ;; (setq attributes (delq '->decomposition attributes))
1358 (if (equal (get-char-attribute char '->titlecase)
1359 (get-char-attribute char '->uppercase))
1360 (setq attributes (delq '->titlecase attributes)))
1361 (when (and (memq '->mojikyo attributes)
1362 (setq value (get-char-attribute char '->mojikyo)))
1363 (insert (format "(->mojikyo\t\t. %06d)\t; %c%s"
1364 value (decode-char 'mojikyo value)
1366 (setq attributes (delq '->mojikyo attributes))
1369 (dolist (ignored '(composition
1370 ->denotational <-subsumptive ->ucs-unified
1371 ;; ->ideographic-component-forms
1373 (setq attributes (delq ignored attributes))))
1375 (setq name (car attributes))
1376 (unless (eq (setq value (get-char-attribute char name 'value-is-empty))
1378 (cond ((setq ret (find-charset name))
1379 (setq name (charset-name ret))
1380 (when (not (memq name dest-ccss))
1381 (setq dest-ccss (cons name dest-ccss))
1382 (char-db-insert-ccs-feature name value line-breaking))
1384 ((string-match "^=>ucs@" (symbol-name name))
1385 (insert (format "(%-18s . #x%04X)\t; %c%s"
1386 name value (decode-char '=ucs value)
1389 ((eq name 'jisx0208-1978/4X)
1390 (insert (format "(%-18s . #x%04X)%s"
1396 (not (eq name '->subsumptive))
1397 (not (eq name '->uppercase))
1398 (not (eq name '->lowercase))
1399 (not (eq name '->titlecase))
1400 (not (eq name '->canonical))
1401 (not (eq name '->Bopomofo))
1402 (not (eq name '->mistakable))
1403 (not (eq name '->ideographic-variants))
1404 (null (get-char-attribute
1405 char (intern (format "%s*sources" name))))
1406 (not (string-match "\\*sources$" (symbol-name name)))
1407 (null (get-char-attribute
1408 char (intern (format "%s*note" name))))
1409 (not (string-match "\\*note$" (symbol-name name)))
1410 (or (eq name '<-identical)
1411 (eq name '<-uppercase)
1412 (eq name '<-lowercase)
1413 (eq name '<-titlecase)
1414 (eq name '<-canonical)
1415 (eq name '<-ideographic-variants)
1416 ;; (eq name '<-synonyms)
1417 (string-match "^<-synonyms" (symbol-name name))
1418 (eq name '<-mistakable)
1419 (when (string-match "^->" (symbol-name name))
1421 ((string-match "^->fullwidth" (symbol-name name))
1422 (not (and (consp value)
1423 (characterp (car value))
1425 (car value) '=ucs 'defined-only)))
1430 ((or (eq name 'ideographic-structure)
1431 (eq name 'ideographic-structure@apparent)
1432 (eq name 'ideographic-structure@apparent/leftmost)
1433 (eq name 'ideographic-combination)
1434 ;; (eq name 'ideographic-)
1435 (eq name '=decomposition)
1436 (char-feature-base-name= '=decomposition name)
1437 (char-feature-base-name= '=>decomposition name)
1438 ;; (string-match "^=>*decomposition\\(@[^*]+\\)?$"
1439 ;; (symbol-name name))
1440 (string-match "^\\(->\\|<-\\)[^*]*$" (symbol-name name))
1441 (string-match "^\\(->\\|<-\\)[^*]*\\*sources$"
1444 (char-db-insert-relation-feature char name value
1447 ;; ((memq name '(ideograph=
1448 ;; original-ideograph-of
1449 ;; ancient-ideograph-of
1450 ;; vulgar-ideograph-of
1451 ;; wrong-ideograph-of
1452 ;; ;; simplified-ideograph-of
1453 ;; ideographic-variants
1454 ;; ;; ideographic-different-form-of
1456 ;; (insert (format "(%-18s%s " name line-breaking))
1457 ;; (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1459 ;; (while (consp value)
1460 ;; (setq cell (car value))
1461 ;; (if (and (consp cell)
1462 ;; (consp (car cell)))
1466 ;; (char-db-insert-alist cell readable)
1467 ;; (setq separator lbs))
1469 ;; (insert separator))
1470 ;; (insert (prin1-to-string cell))
1471 ;; (setq separator " "))
1472 ;; (setq value (cdr value)))
1474 ;; (insert line-breaking))
1476 (insert (format "(%-18s " name))
1477 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1479 (while (consp value)
1480 (setq cell (car value))
1481 (if (and (consp cell)
1483 (setq ret (condition-case nil
1491 (setq key (car (car rest)))
1492 (if (find-charset key)
1493 (setq cal (cons key cal))
1494 (setq al (cons key al)))
1495 (setq rest (cdr rest)))
1498 (insert-char-attributes ret
1502 (setq separator lbs))
1503 (setq ret (prin1-to-string cell))
1505 (if (< (+ (current-column)
1512 (setq separator " "))
1513 (setq value (cdr value)))
1515 (insert line-breaking))
1517 (insert (format "(%-18s" name))
1518 (setq ret (prin1-to-string value))
1519 (unless (< (+ (current-column)
1523 (insert line-breaking))
1524 (insert " . " ret ")" line-breaking)
1525 ;; (insert (format "(%-18s . %S)%s"
1530 (setq attributes (cdr attributes)))
1533 (defun insert-char-data (char &optional readable
1536 (narrow-to-region (point)(point))
1537 (insert "(define-char
1539 (insert-char-attributes char readable attributes)
1541 (goto-char (point-min))
1542 (while (re-search-forward "[ \t]+$" nil t)
1545 (goto-char (point-min))
1546 (while (re-search-forward "[ \t][ \t][ \t]*" nil t)
1547 (let ((column (current-column))
1548 (indent-tabs-mode t))
1549 (delete-region (match-beginning 0) (point))
1550 (indent-to column)))
1551 (goto-char (point-max))
1552 ;; (tabify (point-min)(point-max))
1555 (defun insert-char-data-with-variant (char &optional printable
1557 script excluded-script)
1558 (insert-char-data char printable)
1559 (let ((variants (char-variants char))
1562 (setq variants (sort variants #'<))
1563 (setq rest variants)
1564 (setq variants (cons char variants))
1566 (setq variant (car rest))
1567 (unless (get-char-attribute variant '<-subsumptive)
1568 (if (and (or (null script)
1569 (null (setq vs (get-char-attribute variant 'script)))
1571 (or (null excluded-script)
1572 (null (setq vs (get-char-attribute variant 'script)))
1573 (not (memq excluded-script vs))))
1574 (unless (and no-ucs-unified (get-char-attribute variant '=ucs))
1575 (insert-char-data variant printable)
1576 (if (setq ret (char-variants variant))
1578 (or (memq (car ret) variants)
1579 ;; (get-char-attribute (car ret) '<-subsumptive)
1580 (setq rest (nconc rest (list (car ret)))))
1581 (setq ret (cdr ret)))))))
1582 (setq rest (cdr rest)))))
1584 (defun insert-char-range-data (min max &optional script excluded-script)
1587 (while (<= code max)
1588 (setq char (decode-char '=ucs code))
1589 (if (encode-char char '=ucs 'defined-only)
1590 (insert-char-data-with-variant char nil 'no-ucs-unified
1591 script excluded-script))
1592 (setq code (1+ code)))))
1594 (defun write-char-range-data-to-file (min max file
1595 &optional script excluded-script)
1596 (let ((coding-system-for-write char-db-file-coding-system))
1598 (insert (format ";; -*- coding: %s -*-\n"
1599 char-db-file-coding-system))
1600 (insert-char-range-data min max script excluded-script)
1601 (write-region (point-min)(point-max) file))))
1603 (defvar what-character-original-window-configuration)
1606 (defun what-char-definition (char)
1607 (interactive (list (char-after)))
1608 (let ((buf (get-buffer-create "*Character Description*"))
1609 (the-buf (current-buffer))
1610 (win-conf (current-window-configuration)))
1612 (make-local-variable 'what-character-original-window-configuration)
1613 (setq what-character-original-window-configuration win-conf)
1614 (setq buffer-read-only nil)
1618 (insert-char-data-with-variant char 'printable)
1619 (unless (char-attribute-alist char)
1620 (insert (format ";; = %c\n"
1621 (let* ((rest (split-char char))
1625 (setq code (logior (lsh code 8)
1627 (decode-char ccs code)))))
1628 ;; (char-db-update-comment)
1629 (set-buffer-modified-p nil)
1630 (view-mode the-buf (lambda (buf)
1631 (set-window-configuration
1632 what-character-original-window-configuration)
1634 (goto-char (point-min)))
1636 (set-window-configuration
1637 what-character-original-window-configuration)
1638 (signal (car err) (cdr err)))))))
1644 (provide 'char-db-util)
1646 ;;; char-db-util.el ends here