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-003@iwds-1
412 =>ucs-itaiji-006@iwds-1
425 ;;; @ char-db formatters
428 (defun char-db-make-char-spec (char)
430 (cond ((characterp char)
431 (cond ((and (setq ret (encode-char char '=ucs 'defined-only))
432 (not (and (<= #xE000 ret)(<= ret #xF8FF))))
433 (setq char-spec (list (cons '=ucs ret)))
434 (cond ((setq ret (get-char-attribute char 'name))
435 (setq char-spec (cons (cons 'name ret) char-spec))
437 ((setq ret (get-char-attribute char 'name*))
438 (setq char-spec (cons (cons 'name* ret) char-spec))
441 ((encode-char char '=mj 'defined-only)
443 (dolist (ccs (charset-list))
444 (if (and (or (eq ccs '=mj)
445 ;; (eq (charset-property ccs 'iso-ir) 177)
446 (string-match "=ucs@" (symbol-name ccs))
448 (setq ccs (charset-name ccs))
449 (null (assq ccs char-spec))
450 (setq ret (encode-char char ccs 'defined-only)))
451 (setq char-spec (cons (cons ccs ret) char-spec))))
453 ((encode-char char '==mj 'defined-only)
455 (dolist (ccs (charset-list))
456 (if (and (or (eq ccs '==mj)
457 ;; (eq (charset-property ccs 'iso-ir) 177)
458 (string-match "=ucs@" (symbol-name ccs))
460 (setq ccs (charset-name ccs))
461 (null (assq ccs char-spec))
462 (setq ret (encode-char char ccs 'defined-only)))
463 (setq char-spec (cons (cons ccs ret) char-spec))))
465 ((encode-char char '=adobe-japan1 'defined-only)
467 (dolist (ccs (charset-list))
468 (if (and (or (memq ccs
477 ;; (eq (charset-property ccs 'iso-ir) 177)
478 (string-match "=ucs@" (symbol-name ccs))
480 (setq ccs (charset-name ccs))
481 (null (assq ccs char-spec))
482 (setq ret (encode-char char ccs 'defined-only)))
483 (setq char-spec (cons (cons ccs ret) char-spec))))
485 ((encode-char char '==adobe-japan1 'defined-only)
487 (dolist (ccs (charset-list))
488 (if (and (or (memq ccs
497 ;; (eq (charset-property ccs 'iso-ir) 177)
498 (string-match "=ucs@" (symbol-name ccs))
500 (setq ccs (charset-name ccs))
501 (null (assq ccs char-spec))
502 (setq ret (encode-char char ccs 'defined-only)))
503 (setq char-spec (cons (cons ccs ret) char-spec))))
507 (let ((rest char-db-coded-charset-priority-list)
510 (setq ccs (charset-name
511 (find-charset (car rest))))
513 (encode-char char ccs
515 (throw 'tag (cons ccs ret)))
516 (setq rest (cdr rest))))))
517 (setq char-spec (list ret))
518 (dolist (ccs (delq (car ret) (charset-list)))
519 (if (and (or (charset-iso-final-char ccs)
526 (and (eq (charset-property ccs 'iso-ir) 177)
527 (not (eq (charset-name ccs) '=ucs@big5)))
528 ;; (string-match "=ucs@" (symbol-name ccs))
530 (setq ccs (charset-name ccs))
531 (null (assq ccs char-spec))
532 (setq ret (encode-char char ccs 'defined-only)))
533 (setq char-spec (cons (cons ccs ret) char-spec))))
535 (setq char-spec (split-char char)))
536 (cond ((setq ret (get-char-attribute char 'name))
537 (setq char-spec (cons (cons 'name ret) char-spec))
539 ((setq ret (get-char-attribute char 'name*))
540 (setq char-spec (cons (cons 'name* ret) char-spec))
543 ((setq ret (get-char-attribute
544 char 'ideographic-combination))
546 (cons (cons 'ideographic-combination ret)
553 (defun char-db-insert-char-spec (char &optional readable column
556 (setq column (current-column)))
557 (let (char-spec temp-char)
558 (setq char-spec (char-db-make-char-spec char))
559 (unless (or (characterp char) ; char
561 (setq char (find-char char-spec))
563 ;; define temporary character
564 ;; Current implementation is dirty.
565 (setq temp-char (define-char (cons '(ideograph-daikanwa . 0)
567 (remove-char-attribute temp-char 'ideograph-daikanwa)
568 (setq char temp-char))
569 (insert-char-attributes char
571 (union (mapcar #'car char-spec)
575 ;; undefine temporary character
576 ;; Current implementation is dirty.
577 (setq char-spec (char-attribute-alist temp-char))
579 (remove-char-attribute temp-char (car (car char-spec)))
580 (setq char-spec (cdr char-spec))))))
582 (defun char-db-insert-alist (alist &optional readable column)
584 (setq column (current-column)))
586 (concat "\n" (make-string (1+ column) ?\ )))
590 lbs cell rest separator)
593 (setq name (car (car alist))
594 value (cdr (car alist)))
595 (cond ((eq name 'char)
597 (if (setq ret (condition-case nil
605 (setq key (car (car value)))
606 ;; (if (find-charset key)
607 ;; (setq cal (cons key cal))
608 (setq al (cons key al))
610 (setq value (cdr value)))
611 (insert-char-attributes ret
615 (insert (prin1-to-string value)))
617 (insert line-breaking))
619 (insert (format "(%-18s " name))
620 (setq lbs (concat "\n" (make-string (current-column) ?\ )))
622 (setq cell (car value))
623 (if (and (consp cell)
625 (setq ret (condition-case nil
635 (setq key (car (car rest)))
636 ;; (if (find-charset key)
637 ;; (setq cal (cons key cal))
638 (setq al (cons key al))
640 (setq rest (cdr rest)))
643 (insert-char-attributes ret
647 (setq separator lbs))
650 (insert (prin1-to-string cell))
651 (setq separator " "))
652 (setq value (cdr value)))
654 (insert line-breaking))
656 (insert (format "(%-18s . %S)%s"
659 (setq alist (cdr alist))))
662 (defun char-db-insert-char-reference (plist &optional readable column)
664 (setq column (current-column)))
666 (concat "\n" (make-string (1+ column) ?\ )))
671 (setq name (pop plist))
672 (setq value (pop plist))
673 (cond ((eq name :char)
676 (cond ((numberp value)
677 (setq value (decode-char '=ucs value)))
679 ;; (setq value (or (find-char value)
682 (char-db-insert-char-spec value readable)
683 (insert line-breaking)
686 (insert (format "%s%s\t%d ; %c%s"
689 (ideographic-radical value)
693 (insert (format "%s%s\t%S" separator name value))
694 (setq separator line-breaking)))
698 (defun char-db-decode-isolated-char (ccs code-point)
701 (cond ((eq ccs 'arabic-iso8859-6)
702 (decode-char ccs code-point))
704 ;; (decode-builtin-char '==gt code-point))
705 ((and (memq ccs '(=gt-pj-1
716 (setq ret (decode-char ccs code-point))
717 (setq ret (encode-char ret '=gt 'defined-only)))
718 (decode-builtin-char '=gt ret))
720 (decode-builtin-char ccs code-point))))
722 (or (decode-char ccs code-point)
723 (define-char (list (cons ccs code-point)))))
724 ((and (<= 0 (char-int ret))
725 (<= (char-int ret) #x1F))
726 (decode-char '=ucs (+ #x2400 (char-int ret))))
727 ((= (char-int ret) #x7F)
731 (defvar char-db-convert-obsolete-format t)
733 (defun char-db-insert-ccs-feature (name value line-breaking)
739 ((memq name '(=>iwds-1
742 =shinjigen@1ed ==shinjigen@1ed
743 =shinjigen@rev ==shinjigen@rev
744 =shinjigen/+p@rev ==shinjigen/+p@rev
745 ===daikanwa/ho ==daikanwa/ho
746 =daikanwa/ho =>>daikanwa/ho =>daikanwa/ho))
747 "(%-18s . %04d)\t; %c")
748 ((eq name '=shinjigen@1ed/24pr)
749 "(%-18s . %04d)\t; %c")
753 ==daikanwa =daikanwa =>>daikanwa =>daikanwa
754 =daikanwa@rev1 =daikanwa@rev2
755 =daikanwa/+p ==daikanwa/+p ===daikanwa/+p
757 =daikanwa/+2p =>>daikanwa/+2p
762 =adobe-japan1-0 ==adobe-japan1-0 ===adobe-japan1-0
763 =adobe-japan1-1 ==adobe-japan1-1 ===adobe-japan1-1
764 =adobe-japan1-2 ==adobe-japan1-2 ===adobe-japan1-2
765 =adobe-japan1-3 ==adobe-japan1-3 ===adobe-japan1-3
766 =adobe-japan1-4 ==adobe-japan1-4 ===adobe-japan1-4
767 =adobe-japan1-5 ==adobe-japan1-5 ===adobe-japan1-5
768 =adobe-japan1-6 ==adobe-japan1-6 ===adobe-japan1-6
769 =>>adobe-japan1-0 =+>adobe-japan1-0
770 =>>adobe-japan1-1 =+>adobe-japan1-1
771 =>>adobe-japan1-2 =+>adobe-japan1-2
772 =>>adobe-japan1-3 =+>adobe-japan1-3
773 =>>adobe-japan1-4 =+>adobe-japan1-4
774 =>>adobe-japan1-5 =+>adobe-japan1-5
775 =>>adobe-japan1-6 =+>adobe-japan1-6
776 =>cbeta =cbeta =>>cbeta ==cbeta ===cbeta
777 =zinbun-oracle =>zinbun-oracle
778 =daijiten ==daijiten ===daijiten ==>daijiten
779 ===hng-jou ===hng-keg ===hng-dng ===hng-mam
780 ===hng-drt ===hng-kgk ===hng-myz ===hng-kda
781 ===hng-khi ===hng-khm ===hng-fhs ===hng-hok
782 ===hng-kyd ===hng-sok
783 ===hng-yhk ===hng-kak ===hng-kar ===hng-kae
784 ===hng-sys ===hng-tsu ===hng-tzj
785 ===hng-hos ===hng-kkh ===hng-nak ===hng-jhk
786 ===hng-hod ===hng-gok ===hng-ink ===hng-nto
787 ===hng-nkm ===hng-k24 ===hng-ini ===hng-nkk
788 ===hng-kcc ===hng-kcj ===hng-kbk ===hng-sik
789 ===hng-skk ===hng-kyu ===hng-ksk ===hng-wan
790 ===hng-okd ===hng-wad ===hng-kmi
791 ===hng-zkd ===hng-doh ===hng-jyu ===hng-tzs
792 ===hng-sai ===hng-kad ===hng-kss
793 ===hng-kyo ===hng-ykk ===hng-saa
794 ===hng-sab ===hng-wks ===hng-wke ===hng-smk
795 ===hng-sgs ===hng-sts ===hng-kkd
796 =shuowen-jiguge ===shuowen-jiguge4 ===shuowen-jiguge5))
797 ;; (string-match "^=adobe-" (symbol-name name))
799 "(%-18s . %05d)\t; %c")
800 ((memq name '(=hanyo-denshi/ks
801 ==hanyo-denshi/ks ===hanyo-denshi/ks
804 =mj ==mj ===mj =>>mj =>mj
806 "(%-18s . %06d)\t; %c")
807 ((memq name '(=hanyo-denshi/tk ==hanyo-denshi/tk))
808 "(%-18s . %08d)\t; %c")
809 ((>= (charset-dimension name) 2)
810 "(%-18s . #x%04X)\t; %c")
812 "(%-18s . #x%02X)\t; %c"))
814 (if (= (charset-iso-graphic-plane name) 1)
816 (cond ((= (charset-dimension name) 1)
818 ((= (charset-dimension name) 2)
820 ((= (charset-dimension name) 3)
824 (char-db-decode-isolated-char name value)))
825 (if (and (= (charset-chars name) 94)
826 (= (charset-dimension name) 2))
827 (insert (format " [%02d-%02d]"
828 (- (lsh value -8) 32)
829 (- (logand value 255) 32))))
832 (insert (format "(%-18s . %s)" name value))
834 (insert line-breaking))
836 (defun char-db-insert-relation-feature (char name value line-breaking
838 (insert (format "(%-18s%s " name line-breaking))
839 (let ((lbs (concat "\n" (make-string (current-column) ?\ )))
840 separator cell sources required-features
843 (setq cell (car value))
845 (setq cell (decode-char '=ucs cell)))
847 ((eq name '->subsumptive)
848 (when (or (not (some (lambda (atr)
849 (get-char-attribute cell atr))
850 char-db-ignored-attributes))
852 (encode-char cell ccs 'defined-only))
856 (let ((char-db-ignored-attributes
858 char-db-ignored-attributes)))
859 (insert-char-attributes cell readable nil nil 'for-sub-node))
860 (setq separator lbs))
865 char (intern (format "%s*sources" name))))
866 (setq required-features nil)
867 (dolist (source sources)
871 shinjigen shinjigen@1ed shinjigen@rev))
872 (setq required-features
873 (union required-features
885 =shinjigen/+p@rev))))
887 (setq required-features
888 (union required-features
893 ((find-charset (setq ret (intern (format "=%s" source))))
894 (setq required-features
895 (cons ret required-features)))
896 (t (setq required-features
897 (cons source required-features)))))
898 (cond ((string-match "@JP" (symbol-name name))
899 (setq required-features
900 (union required-features
908 ((string-match "@CN" (symbol-name name))
909 (setq required-features
910 (union required-features
917 (insert (format "%S" cell))
918 (char-db-insert-char-spec cell readable
921 (setq separator lbs))
925 (if (consp (car cell))
926 (char-db-insert-char-spec cell readable)
927 (char-db-insert-char-reference cell readable))
928 (setq separator lbs))
932 (insert (prin1-to-string cell))
933 (setq separator " ")))
934 (setq value (cdr value)))
936 (insert line-breaking)))
938 (defun insert-char-attributes (char &optional readable attributes column
941 (setq column (current-column)))
942 (let (name value ; has-long-ccs-name
946 (concat "\n" (make-string (1+ column) ?\ )))
947 lbs cell separator ret
949 dest-ccss ; sources required-features
954 (if (consp attributes)
956 (dolist (name attributes)
957 (unless (memq name char-db-ignored-attributes)
958 (if (find-charset name)
962 (dolist (name (char-attribute-list))
963 (unless (memq name char-db-ignored-attributes)
964 (if (find-charset name)
968 #'char-attribute-name<)))
970 (when (memq '<-subsumptive attributes)
971 (when (or readable (not for-sub-node))
972 (when (setq value (get-char-attribute char '<-subsumptive))
973 (char-db-insert-relation-feature char '<-subsumptive value
976 (setq attributes (delq '<-subsumptive attributes)))
977 (when (and (memq '<-denotational attributes)
978 (setq value (get-char-attribute char '<-denotational)))
979 (char-db-insert-relation-feature char '<-denotational value
982 (setq attributes (delq '<-denotational attributes)))
983 (when (and (memq '<-denotational@component attributes)
984 (setq value (get-char-attribute char '<-denotational@component)))
985 (char-db-insert-relation-feature char '<-denotational@component value
988 (setq attributes (delq '<-denotational@component attributes)))
989 (when (and (memq '<-denotational@usage attributes)
990 (setq value (get-char-attribute char '<-denotational@usage)))
991 (char-db-insert-relation-feature char '<-denotational@usage value
994 (setq attributes (delq '<-denotational@usage attributes)))
995 (when (and (memq 'name attributes)
996 (setq value (get-char-attribute char 'name)))
998 (if (> (+ (current-column) (length value)) 48)
1001 value line-breaking))
1002 (setq attributes (delq 'name attributes))
1004 (when (and (memq 'name* attributes)
1005 (setq value (get-char-attribute char 'name*)))
1007 (if (> (+ (current-column) (length value)) 48)
1010 value line-breaking))
1011 (setq attributes (delq 'name* attributes))
1013 (when (and (memq 'script attributes)
1014 (setq value (get-char-attribute char 'script)))
1015 (insert (format "(script\t\t%s)%s"
1016 (mapconcat (function prin1-to-string)
1019 (setq attributes (delq 'script attributes))
1021 (dolist (name '(=>ucs =>ucs*))
1022 (when (and (memq name attributes)
1023 (setq value (get-char-attribute char name)))
1024 (insert (format "(%-18s . #x%04X)\t; %c%s"
1025 name value (decode-char '=ucs value)
1027 (setq attributes (delq name attributes))))
1028 (dolist (name '(=>ucs@gb =>ucs@big5))
1029 (when (and (memq name attributes)
1030 (setq value (get-char-attribute char name)))
1031 (insert (format "(%-18s . #x%04X)\t; %c%s"
1033 (decode-char (intern
1036 (symbol-name name) 2)))
1039 (setq attributes (delq name attributes))
1041 ;; (dolist (name '(=>daikanwa))
1042 ;; (when (and (memq name attributes)
1043 ;; (setq value (get-char-attribute char name)))
1045 ;; (if (integerp value)
1046 ;; (format "(%-18s . %05d)\t; %c%s"
1047 ;; name value (decode-char '=daikanwa value)
1049 ;; (format "(%-18s %s)\t; %c%s"
1051 ;; (mapconcat (function prin1-to-string)
1053 ;; (char-representative-of-daikanwa char)
1055 ;; (setq attributes (delq name attributes))))
1056 (when (and (memq 'general-category attributes)
1057 (setq value (get-char-attribute char 'general-category)))
1059 "(general-category\t%s) ; %s%s"
1060 (mapconcat (lambda (cell)
1063 (cond ((rassoc value unidata-normative-category-alist)
1064 "Normative Category")
1065 ((rassoc value unidata-informative-category-alist)
1066 "Informative Category")
1068 "Unknown Category"))
1070 (setq attributes (delq 'general-category attributes))
1072 (when (and (memq 'bidi-category attributes)
1073 (setq value (get-char-attribute char 'bidi-category)))
1074 (insert (format "(bidi-category\t. %S)%s"
1077 (setq attributes (delq 'bidi-category attributes))
1079 (unless (or (not (memq 'mirrored attributes))
1080 (eq (setq value (get-char-attribute char 'mirrored 'empty))
1082 (insert (format "(mirrored\t\t. %S)%s"
1085 (setq attributes (delq 'mirrored attributes))
1088 ((and (memq 'decimal-digit-value attributes)
1089 (setq value (get-char-attribute char 'decimal-digit-value)))
1090 (insert (format "(decimal-digit-value . %S)%s"
1093 (setq attributes (delq 'decimal-digit-value attributes))
1094 (when (and (memq 'digit-value attributes)
1095 (setq value (get-char-attribute char 'digit-value)))
1096 (insert (format "(digit-value\t . %S)%s"
1099 (setq attributes (delq 'digit-value attributes))
1101 (when (and (memq 'numeric-value attributes)
1102 (setq value (get-char-attribute char 'numeric-value)))
1103 (insert (format "(numeric-value\t . %S)%s"
1106 (setq attributes (delq 'numeric-value attributes))
1110 (when (and (memq 'digit-value attributes)
1111 (setq value (get-char-attribute char 'digit-value)))
1112 (insert (format "(digit-value\t. %S)%s"
1115 (setq attributes (delq 'digit-value attributes))
1117 (when (and (memq 'numeric-value attributes)
1118 (setq value (get-char-attribute char 'numeric-value)))
1119 (insert (format "(numeric-value\t. %S)%s"
1122 (setq attributes (delq 'numeric-value attributes))
1124 (when (and (memq 'iso-10646-comment attributes)
1125 (setq value (get-char-attribute char 'iso-10646-comment)))
1126 (insert (format "(iso-10646-comment\t. %S)%s"
1129 (setq attributes (delq 'iso-10646-comment attributes))
1131 (when (and (memq 'morohashi-daikanwa attributes)
1132 (setq value (get-char-attribute char 'morohashi-daikanwa)))
1133 (insert (format "(morohashi-daikanwa\t%s)%s"
1134 (mapconcat (function prin1-to-string) value " ")
1136 (setq attributes (delq 'morohashi-daikanwa attributes))
1140 (when (and (memq 'ideographic-radical attributes)
1141 (setq value (get-char-attribute char 'ideographic-radical)))
1142 (setq radical value)
1143 (insert (format "(ideographic-radical . %S)\t; %c%s"
1145 (ideographic-radical radical)
1147 (setq attributes (delq 'ideographic-radical attributes))
1149 (when (and (memq 'shuowen-radical attributes)
1150 (setq value (get-char-attribute char 'shuowen-radical)))
1151 (insert (format "(shuowen-radical\t. %S)\t; %c%s"
1153 (shuowen-radical value)
1155 (setq attributes (delq 'shuowen-radical attributes))
1160 char-db-feature-domains
1162 (dolist (feature (char-attribute-list))
1163 (setq feature (symbol-name feature))
1165 "\\(radical\\|strokes\\)@\\([^@*]+\\)\\(\\*\\|$\\)"
1167 (setq domain (intern (match-string 2 feature)))
1168 (unless (memq domain dest)
1169 (setq dest (cons domain dest)))))
1170 (sort dest #'string<))))
1171 (setq key (intern (format "%s@%s" 'ideographic-radical domain)))
1172 (when (and (memq key attributes)
1173 (setq value (get-char-attribute char key)))
1174 (setq radical value)
1175 (insert (format "(%s . %S)\t; %c%s"
1178 (ideographic-radical radical)
1180 (setq attributes (delq key attributes))
1182 (setq key (intern (format "%s@%s" 'ideographic-strokes domain)))
1183 (when (and (memq key attributes)
1184 (setq value (get-char-attribute char key)))
1185 (setq strokes value)
1186 (insert (format "(%s . %S)%s"
1190 (setq attributes (delq key attributes))
1192 (setq key (intern (format "%s@%s" 'total-strokes domain)))
1193 (when (and (memq key attributes)
1194 (setq value (get-char-attribute char key)))
1195 (insert (format "(%s . %S)%s"
1199 (setq attributes (delq key attributes))
1201 (dolist (feature '(ideographic-radical
1204 (setq key (intern (format "%s@%s*sources" feature domain)))
1205 (when (and (memq key attributes)
1206 (setq value (get-char-attribute char key)))
1207 (insert (format "(%s%s" key line-breaking))
1208 (dolist (cell value)
1209 (insert (format " %s" cell)))
1211 (insert line-breaking)
1212 (setq attributes (delq key attributes))
1215 (when (and (memq 'ideographic-strokes attributes)
1216 (setq value (get-char-attribute char 'ideographic-strokes)))
1217 (setq strokes value)
1218 (insert (format "(ideographic-strokes . %S)%s"
1221 (setq attributes (delq 'ideographic-strokes attributes))
1223 (when (and (memq 'kangxi-radical attributes)
1224 (setq value (get-char-attribute char 'kangxi-radical)))
1225 (unless (eq value radical)
1226 (insert (format "(kangxi-radical\t . %S)\t; %c%s"
1228 (ideographic-radical value)
1231 (setq radical value)))
1232 (setq attributes (delq 'kangxi-radical attributes))
1234 (when (and (memq 'kangxi-strokes attributes)
1235 (setq value (get-char-attribute char 'kangxi-strokes)))
1236 (unless (eq value strokes)
1237 (insert (format "(kangxi-strokes\t . %S)%s"
1241 (setq strokes value)))
1242 (setq attributes (delq 'kangxi-strokes attributes))
1244 ;; (when (and (memq 'japanese-radical attributes)
1245 ;; (setq value (get-char-attribute char 'japanese-radical)))
1246 ;; (unless (eq value radical)
1247 ;; (insert (format "(japanese-radical\t . %S)\t; %c%s"
1249 ;; (ideographic-radical value)
1252 ;; (setq radical value)))
1253 ;; (setq attributes (delq 'japanese-radical attributes))
1255 (when (and (memq 'japanese-strokes attributes)
1256 (setq value (get-char-attribute char 'japanese-strokes)))
1257 (unless (eq value strokes)
1258 (insert (format "(japanese-strokes\t . %S)%s"
1262 (setq strokes value)))
1263 (setq attributes (delq 'japanese-strokes attributes))
1265 (when (and (memq 'cns-radical attributes)
1266 (setq value (get-char-attribute char 'cns-radical)))
1267 (insert (format "(cns-radical\t . %S)\t; %c%s"
1269 (ideographic-radical value)
1271 (setq attributes (delq 'cns-radical attributes))
1273 (when (and (memq 'cns-strokes attributes)
1274 (setq value (get-char-attribute char 'cns-strokes)))
1275 (unless (eq value strokes)
1276 (insert (format "(cns-strokes\t . %S)%s"
1280 (setq strokes value)))
1281 (setq attributes (delq 'cns-strokes attributes))
1283 ;; (when (and (memq 'ideographic- attributes)
1284 ;; (setq value (get-char-attribute char 'ideographic-)))
1285 ;; (insert "(ideographic- ")
1286 ;; (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1288 ;; (while (consp value)
1289 ;; (setq cell (car value))
1290 ;; (if (integerp cell)
1291 ;; (setq cell (decode-char '=ucs cell)))
1292 ;; (cond ((characterp cell)
1296 ;; (insert (format "%S" cell))
1297 ;; (char-db-insert-char-spec cell readable))
1298 ;; (setq separator lbs))
1302 ;; (if (consp (car cell))
1303 ;; (char-db-insert-char-spec cell readable)
1304 ;; (char-db-insert-char-reference cell readable))
1305 ;; (setq separator lbs))
1308 ;; (insert separator))
1309 ;; (insert (prin1-to-string cell))
1310 ;; (setq separator " ")))
1311 ;; (setq value (cdr value)))
1313 ;; (insert line-breaking)
1314 ;; (setq attributes (delq 'ideographic- attributes)))
1315 (when (and (memq 'total-strokes attributes)
1316 (setq value (get-char-attribute char 'total-strokes)))
1317 (insert (format "(total-strokes . %S)%s"
1320 (setq attributes (delq 'total-strokes attributes))
1322 ;; (when (and (memq '->ideograph attributes)
1323 ;; (setq value (get-char-attribute char '->ideograph)))
1324 ;; (insert (format "(->ideograph\t%s)%s"
1325 ;; (mapconcat (lambda (code)
1326 ;; (cond ((symbolp code)
1327 ;; (symbol-name code))
1329 ;; (format "#x%04X" code))
1332 ;; line-breaking code))))
1335 ;; (setq attributes (delq '->ideograph attributes))
1337 ;; (when (and (memq '->decomposition attributes)
1338 ;; (setq value (get-char-attribute char '->decomposition)))
1339 ;; (insert (format "(->decomposition\t%s)%s"
1340 ;; (mapconcat (lambda (code)
1341 ;; (cond ((symbolp code)
1342 ;; (symbol-name code))
1343 ;; ((characterp code)
1345 ;; (format "%S" code)
1350 ;; (format "#x%04X" code))
1352 ;; (format "%s%S" line-breaking code))))
1355 ;; (setq attributes (delq '->decomposition attributes))
1357 (if (equal (get-char-attribute char '->titlecase)
1358 (get-char-attribute char '->uppercase))
1359 (setq attributes (delq '->titlecase attributes)))
1360 (when (and (memq '->mojikyo attributes)
1361 (setq value (get-char-attribute char '->mojikyo)))
1362 (insert (format "(->mojikyo\t\t. %06d)\t; %c%s"
1363 value (decode-char 'mojikyo value)
1365 (setq attributes (delq '->mojikyo attributes))
1368 (dolist (ignored '(composition
1369 ->denotational <-subsumptive ->ucs-unified
1370 ;; ->ideographic-component-forms
1372 (setq attributes (delq ignored attributes))))
1374 (setq name (car attributes))
1375 (unless (eq (setq value (get-char-attribute char name 'value-is-empty))
1377 (cond ((setq ret (find-charset name))
1378 (setq name (charset-name ret))
1379 (when (not (memq name dest-ccss))
1380 (setq dest-ccss (cons name dest-ccss))
1381 (char-db-insert-ccs-feature name value line-breaking))
1383 ((string-match "^=>ucs@" (symbol-name name))
1384 (insert (format "(%-18s . #x%04X)\t; %c%s"
1385 name value (decode-char '=ucs value)
1388 ((eq name 'jisx0208-1978/4X)
1389 (insert (format "(%-18s . #x%04X)%s"
1395 (not (eq name '->subsumptive))
1396 (not (eq name '->uppercase))
1397 (not (eq name '->lowercase))
1398 (not (eq name '->titlecase))
1399 (not (eq name '->canonical))
1400 (not (eq name '->Bopomofo))
1401 (not (eq name '->mistakable))
1402 (not (eq name '->ideographic-variants))
1403 (null (get-char-attribute
1404 char (intern (format "%s*sources" name))))
1405 (not (string-match "\\*sources$" (symbol-name name)))
1406 (null (get-char-attribute
1407 char (intern (format "%s*note" name))))
1408 (not (string-match "\\*note$" (symbol-name name)))
1409 (or (eq name '<-identical)
1410 (eq name '<-uppercase)
1411 (eq name '<-lowercase)
1412 (eq name '<-titlecase)
1413 (eq name '<-canonical)
1414 (eq name '<-ideographic-variants)
1415 ;; (eq name '<-synonyms)
1416 (string-match "^<-synonyms" (symbol-name name))
1417 (eq name '<-mistakable)
1418 (when (string-match "^->" (symbol-name name))
1420 ((string-match "^->fullwidth" (symbol-name name))
1421 (not (and (consp value)
1422 (characterp (car value))
1424 (car value) '=ucs 'defined-only)))
1429 ((or (eq name 'ideographic-structure)
1430 (eq name 'ideographic-structure@apparent)
1431 (eq name 'ideographic-structure@apparent/leftmost)
1432 (eq name 'ideographic-combination)
1433 ;; (eq name 'ideographic-)
1434 (eq name '=decomposition)
1435 (char-feature-base-name= '=decomposition name)
1436 (char-feature-base-name= '=>decomposition name)
1437 ;; (string-match "^=>*decomposition\\(@[^*]+\\)?$"
1438 ;; (symbol-name name))
1439 (string-match "^\\(->\\|<-\\)[^*]*$" (symbol-name name))
1440 (string-match "^\\(->\\|<-\\)[^*]*\\*sources$"
1443 (char-db-insert-relation-feature char name value
1446 ;; ((memq name '(ideograph=
1447 ;; original-ideograph-of
1448 ;; ancient-ideograph-of
1449 ;; vulgar-ideograph-of
1450 ;; wrong-ideograph-of
1451 ;; ;; simplified-ideograph-of
1452 ;; ideographic-variants
1453 ;; ;; ideographic-different-form-of
1455 ;; (insert (format "(%-18s%s " name line-breaking))
1456 ;; (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1458 ;; (while (consp value)
1459 ;; (setq cell (car value))
1460 ;; (if (and (consp cell)
1461 ;; (consp (car cell)))
1465 ;; (char-db-insert-alist cell readable)
1466 ;; (setq separator lbs))
1468 ;; (insert separator))
1469 ;; (insert (prin1-to-string cell))
1470 ;; (setq separator " "))
1471 ;; (setq value (cdr value)))
1473 ;; (insert line-breaking))
1475 (insert (format "(%-18s " name))
1476 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1478 (while (consp value)
1479 (setq cell (car value))
1480 (if (and (consp cell)
1482 (setq ret (condition-case nil
1490 (setq key (car (car rest)))
1491 (if (find-charset key)
1492 (setq cal (cons key cal))
1493 (setq al (cons key al)))
1494 (setq rest (cdr rest)))
1497 (insert-char-attributes ret
1501 (setq separator lbs))
1502 (setq ret (prin1-to-string cell))
1504 (if (< (+ (current-column)
1511 (setq separator " "))
1512 (setq value (cdr value)))
1514 (insert line-breaking))
1516 (insert (format "(%-18s" name))
1517 (setq ret (prin1-to-string value))
1518 (unless (< (+ (current-column)
1522 (insert line-breaking))
1523 (insert " . " ret ")" line-breaking)
1524 ;; (insert (format "(%-18s . %S)%s"
1529 (setq attributes (cdr attributes)))
1532 (defun insert-char-data (char &optional readable
1535 (narrow-to-region (point)(point))
1536 (insert "(define-char
1538 (insert-char-attributes char readable attributes)
1540 (goto-char (point-min))
1541 (while (re-search-forward "[ \t]+$" nil t)
1544 (goto-char (point-min))
1545 (while (re-search-forward "[ \t][ \t][ \t]*" nil t)
1546 (let ((column (current-column))
1547 (indent-tabs-mode t))
1548 (delete-region (match-beginning 0) (point))
1549 (indent-to column)))
1550 (goto-char (point-max))
1551 ;; (tabify (point-min)(point-max))
1554 (defun insert-char-data-with-variant (char &optional printable
1556 script excluded-script)
1557 (insert-char-data char printable)
1558 (let ((variants (char-variants char))
1561 (setq variants (sort variants #'<))
1562 (setq rest variants)
1563 (setq variants (cons char variants))
1565 (setq variant (car rest))
1566 (unless (get-char-attribute variant '<-subsumptive)
1567 (if (and (or (null script)
1568 (null (setq vs (get-char-attribute variant 'script)))
1570 (or (null excluded-script)
1571 (null (setq vs (get-char-attribute variant 'script)))
1572 (not (memq excluded-script vs))))
1573 (unless (and no-ucs-unified (get-char-attribute variant '=ucs))
1574 (insert-char-data variant printable)
1575 (if (setq ret (char-variants variant))
1577 (or (memq (car ret) variants)
1578 ;; (get-char-attribute (car ret) '<-subsumptive)
1579 (setq rest (nconc rest (list (car ret)))))
1580 (setq ret (cdr ret)))))))
1581 (setq rest (cdr rest)))))
1583 (defun insert-char-range-data (min max &optional script excluded-script)
1586 (while (<= code max)
1587 (setq char (decode-char '=ucs code))
1588 (if (encode-char char '=ucs 'defined-only)
1589 (insert-char-data-with-variant char nil 'no-ucs-unified
1590 script excluded-script))
1591 (setq code (1+ code)))))
1593 (defun write-char-range-data-to-file (min max file
1594 &optional script excluded-script)
1595 (let ((coding-system-for-write char-db-file-coding-system))
1597 (insert (format ";; -*- coding: %s -*-\n"
1598 char-db-file-coding-system))
1599 (insert-char-range-data min max script excluded-script)
1600 (write-region (point-min)(point-max) file))))
1602 (defvar what-character-original-window-configuration)
1605 (defun what-char-definition (char)
1606 (interactive (list (char-after)))
1607 (let ((buf (get-buffer-create "*Character Description*"))
1608 (the-buf (current-buffer))
1609 (win-conf (current-window-configuration)))
1611 (make-local-variable 'what-character-original-window-configuration)
1612 (setq what-character-original-window-configuration win-conf)
1613 (setq buffer-read-only nil)
1617 (insert-char-data-with-variant char 'printable)
1618 (unless (char-attribute-alist char)
1619 (insert (format ";; = %c\n"
1620 (let* ((rest (split-char char))
1624 (setq code (logior (lsh code 8)
1626 (decode-char ccs code)))))
1627 ;; (char-db-update-comment)
1628 (set-buffer-modified-p nil)
1629 (view-mode the-buf (lambda (buf)
1630 (set-window-configuration
1631 what-character-original-window-configuration)
1633 (goto-char (point-min)))
1635 (set-window-configuration
1636 what-character-original-window-configuration)
1637 (signal (car err) (cdr err)))))))
1643 (provide 'char-db-util)
1645 ;;; char-db-util.el ends here