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
421 ;;; @ char-db formatters
424 (defun char-db-make-char-spec (char)
426 (cond ((characterp char)
427 (cond ((and (setq ret (encode-char char '=ucs 'defined-only))
428 (not (and (<= #xE000 ret)(<= ret #xF8FF))))
429 (setq char-spec (list (cons '=ucs ret)))
430 (cond ((setq ret (get-char-attribute char 'name))
431 (setq char-spec (cons (cons 'name ret) char-spec))
433 ((setq ret (get-char-attribute char 'name*))
434 (setq char-spec (cons (cons 'name* ret) char-spec))
437 ((encode-char char '=mj 'defined-only)
439 (dolist (ccs (charset-list))
440 (if (and (or (eq ccs '=mj)
441 ;; (eq (charset-property ccs 'iso-ir) 177)
442 (string-match "=ucs@" (symbol-name ccs))
444 (setq ccs (charset-name ccs))
445 (null (assq ccs char-spec))
446 (setq ret (encode-char char ccs 'defined-only)))
447 (setq char-spec (cons (cons ccs ret) char-spec))))
449 ((encode-char char '==mj 'defined-only)
451 (dolist (ccs (charset-list))
452 (if (and (or (eq ccs '==mj)
453 ;; (eq (charset-property ccs 'iso-ir) 177)
454 (string-match "=ucs@" (symbol-name ccs))
456 (setq ccs (charset-name ccs))
457 (null (assq ccs char-spec))
458 (setq ret (encode-char char ccs 'defined-only)))
459 (setq char-spec (cons (cons ccs ret) char-spec))))
461 ((encode-char char '=adobe-japan1 'defined-only)
463 (dolist (ccs (charset-list))
464 (if (and (or (memq ccs
473 ;; (eq (charset-property ccs 'iso-ir) 177)
474 (string-match "=ucs@" (symbol-name ccs))
476 (setq ccs (charset-name ccs))
477 (null (assq ccs char-spec))
478 (setq ret (encode-char char ccs 'defined-only)))
479 (setq char-spec (cons (cons ccs ret) char-spec))))
481 ((encode-char char '==adobe-japan1 'defined-only)
483 (dolist (ccs (charset-list))
484 (if (and (or (memq ccs
493 ;; (eq (charset-property ccs 'iso-ir) 177)
494 (string-match "=ucs@" (symbol-name ccs))
496 (setq ccs (charset-name ccs))
497 (null (assq ccs char-spec))
498 (setq ret (encode-char char ccs 'defined-only)))
499 (setq char-spec (cons (cons ccs ret) char-spec))))
503 (let ((rest char-db-coded-charset-priority-list)
506 (setq ccs (charset-name
507 (find-charset (car rest))))
509 (encode-char char ccs
511 (throw 'tag (cons ccs ret)))
512 (setq rest (cdr rest))))))
513 (setq char-spec (list ret))
514 (dolist (ccs (delq (car ret) (charset-list)))
515 (if (and (or (charset-iso-final-char ccs)
522 (and (eq (charset-property ccs 'iso-ir) 177)
523 (not (eq (charset-name ccs) '=ucs@big5)))
524 ;; (string-match "=ucs@" (symbol-name ccs))
526 (setq ccs (charset-name ccs))
527 (null (assq ccs char-spec))
528 (setq ret (encode-char char ccs 'defined-only)))
529 (setq char-spec (cons (cons ccs ret) char-spec))))
531 (setq char-spec (split-char char)))
532 (cond ((setq ret (get-char-attribute char 'name))
533 (setq char-spec (cons (cons 'name ret) char-spec))
535 ((setq ret (get-char-attribute char 'name*))
536 (setq char-spec (cons (cons 'name* ret) char-spec))
539 ((setq ret (get-char-attribute
540 char 'ideographic-combination))
542 (cons (cons 'ideographic-combination ret)
549 (defun char-db-insert-char-spec (char &optional readable column
552 (setq column (current-column)))
553 (let (char-spec temp-char)
554 (setq char-spec (char-db-make-char-spec char))
555 (unless (or (characterp char) ; char
557 (setq char (find-char char-spec))
559 ;; define temporary character
560 ;; Current implementation is dirty.
561 (setq temp-char (define-char (cons '(ideograph-daikanwa . 0)
563 (remove-char-attribute temp-char 'ideograph-daikanwa)
564 (setq char temp-char))
565 (insert-char-attributes char
567 (union (mapcar #'car char-spec)
571 ;; undefine temporary character
572 ;; Current implementation is dirty.
573 (setq char-spec (char-attribute-alist temp-char))
575 (remove-char-attribute temp-char (car (car char-spec)))
576 (setq char-spec (cdr char-spec))))))
578 (defun char-db-insert-alist (alist &optional readable column)
580 (setq column (current-column)))
582 (concat "\n" (make-string (1+ column) ?\ )))
586 lbs cell rest separator)
589 (setq name (car (car alist))
590 value (cdr (car alist)))
591 (cond ((eq name 'char)
593 (if (setq ret (condition-case nil
601 (setq key (car (car value)))
602 ;; (if (find-charset key)
603 ;; (setq cal (cons key cal))
604 (setq al (cons key al))
606 (setq value (cdr value)))
607 (insert-char-attributes ret
611 (insert (prin1-to-string value)))
613 (insert line-breaking))
615 (insert (format "(%-18s " name))
616 (setq lbs (concat "\n" (make-string (current-column) ?\ )))
618 (setq cell (car value))
619 (if (and (consp cell)
621 (setq ret (condition-case nil
631 (setq key (car (car rest)))
632 ;; (if (find-charset key)
633 ;; (setq cal (cons key cal))
634 (setq al (cons key al))
636 (setq rest (cdr rest)))
639 (insert-char-attributes ret
643 (setq separator lbs))
646 (insert (prin1-to-string cell))
647 (setq separator " "))
648 (setq value (cdr value)))
650 (insert line-breaking))
652 (insert (format "(%-18s . %S)%s"
655 (setq alist (cdr alist))))
658 (defun char-db-insert-char-reference (plist &optional readable column)
660 (setq column (current-column)))
662 (concat "\n" (make-string (1+ column) ?\ )))
667 (setq name (pop plist))
668 (setq value (pop plist))
669 (cond ((eq name :char)
672 (cond ((numberp value)
673 (setq value (decode-char '=ucs value)))
675 ;; (setq value (or (find-char value)
678 (char-db-insert-char-spec value readable)
679 (insert line-breaking)
682 (insert (format "%s%s\t%d ; %c%s"
685 (ideographic-radical value)
689 (insert (format "%s%s\t%S" separator name value))
690 (setq separator line-breaking)))
694 (defun char-db-decode-isolated-char (ccs code-point)
697 (cond ((eq ccs 'arabic-iso8859-6)
698 (decode-char ccs code-point))
700 ;; (decode-builtin-char '==gt code-point))
701 ((and (memq ccs '(=gt-pj-1
712 (setq ret (decode-char ccs code-point))
713 (setq ret (encode-char ret '=gt 'defined-only)))
714 (decode-builtin-char '=gt ret))
716 (decode-builtin-char ccs code-point))))
718 (or (decode-char ccs code-point)
719 (define-char (list (cons ccs code-point)))))
720 ((and (<= 0 (char-int ret))
721 (<= (char-int ret) #x1F))
722 (decode-char '=ucs (+ #x2400 (char-int ret))))
723 ((= (char-int ret) #x7F)
727 (defvar char-db-convert-obsolete-format t)
729 (defun char-db-insert-ccs-feature (name value line-breaking)
735 ((memq name '(=>iwds-1
738 =shinjigen@1ed ==shinjigen@1ed
739 =shinjigen@rev ==shinjigen@rev
740 =shinjigen/+p@rev ==shinjigen/+p@rev
741 ===daikanwa/ho ==daikanwa/ho
742 =daikanwa/ho =>>daikanwa/ho =>daikanwa/ho))
743 "(%-18s . %04d)\t; %c")
744 ((eq name '=shinjigen@1ed/24pr)
745 "(%-18s . %04d)\t; %c")
749 ==daikanwa =daikanwa =>>daikanwa =>daikanwa
750 =daikanwa@rev1 =daikanwa@rev2
751 =daikanwa/+p ==daikanwa/+p ===daikanwa/+p
753 =daikanwa/+2p =>>daikanwa/+2p
758 =adobe-japan1-0 ==adobe-japan1-0 ===adobe-japan1-0
759 =adobe-japan1-1 ==adobe-japan1-1 ===adobe-japan1-1
760 =adobe-japan1-2 ==adobe-japan1-2 ===adobe-japan1-2
761 =adobe-japan1-3 ==adobe-japan1-3 ===adobe-japan1-3
762 =adobe-japan1-4 ==adobe-japan1-4 ===adobe-japan1-4
763 =adobe-japan1-5 ==adobe-japan1-5 ===adobe-japan1-5
764 =adobe-japan1-6 ==adobe-japan1-6 ===adobe-japan1-6
765 =>>adobe-japan1-0 =+>adobe-japan1-0
766 =>>adobe-japan1-1 =+>adobe-japan1-1
767 =>>adobe-japan1-2 =+>adobe-japan1-2
768 =>>adobe-japan1-3 =+>adobe-japan1-3
769 =>>adobe-japan1-4 =+>adobe-japan1-4
770 =>>adobe-japan1-5 =+>adobe-japan1-5
771 =>>adobe-japan1-6 =+>adobe-japan1-6
772 =>cbeta =cbeta =>>cbeta ==cbeta ===cbeta
773 =zinbun-oracle =>zinbun-oracle
774 =daijiten ==daijiten ===daijiten ==>daijiten
775 ===hng-jou ===hng-keg ===hng-dng ===hng-mam
776 ===hng-drt ===hng-kgk ===hng-myz ===hng-kda
777 ===hng-khi ===hng-khm ===hng-fhs ===hng-hok
778 ===hng-kyd ===hng-sok
779 ===hng-yhk ===hng-kak ===hng-kar ===hng-kae
780 ===hng-sys ===hng-tsu ===hng-tzj
781 ===hng-hos ===hng-kkh ===hng-nak ===hng-jhk
782 ===hng-hod ===hng-gok ===hng-ink ===hng-nto
783 ===hng-nkm ===hng-k24 ===hng-ini ===hng-nkk
784 ===hng-kcc ===hng-kcj ===hng-kbk ===hng-sik
785 ===hng-skk ===hng-kyu ===hng-ksk ===hng-wan
786 ===hng-okd ===hng-wad ===hng-kmi
787 ===hng-zkd ===hng-doh ===hng-jyu ===hng-tzs
788 ===hng-sai ===hng-kad ===hng-kss
789 ===hng-kyo ===hng-ykk ===hng-saa
790 ===hng-sab ===hng-wks ===hng-wke ===hng-smk
791 ===hng-sgs ===hng-sts ===hng-kkd
792 =shuowen-jiguge ===shuowen-jiguge4 ===shuowen-jiguge5))
793 ;; (string-match "^=adobe-" (symbol-name name))
795 "(%-18s . %05d)\t; %c")
796 ((memq name '(=hanyo-denshi/ks
797 ==hanyo-denshi/ks ===hanyo-denshi/ks
800 =mj ==mj ===mj =>>mj =>mj
802 "(%-18s . %06d)\t; %c")
803 ((memq name '(=hanyo-denshi/tk ==hanyo-denshi/tk))
804 "(%-18s . %08d)\t; %c")
805 ((>= (charset-dimension name) 2)
806 "(%-18s . #x%04X)\t; %c")
808 "(%-18s . #x%02X)\t; %c"))
810 (if (= (charset-iso-graphic-plane name) 1)
812 (cond ((= (charset-dimension name) 1)
814 ((= (charset-dimension name) 2)
816 ((= (charset-dimension name) 3)
820 (char-db-decode-isolated-char name value)))
821 (if (and (= (charset-chars name) 94)
822 (= (charset-dimension name) 2))
823 (insert (format " [%02d-%02d]"
824 (- (lsh value -8) 32)
825 (- (logand value 255) 32))))
828 (insert (format "(%-18s . %s)" name value))
830 (insert line-breaking))
832 (defun char-db-insert-relation-feature (char name value line-breaking
834 (insert (format "(%-18s%s " name line-breaking))
835 (let ((lbs (concat "\n" (make-string (current-column) ?\ )))
836 separator cell sources required-features
839 (setq cell (car value))
841 (setq cell (decode-char '=ucs cell)))
843 ((eq name '->subsumptive)
844 (when (or (not (some (lambda (atr)
845 (get-char-attribute cell atr))
846 char-db-ignored-attributes))
848 (encode-char cell ccs 'defined-only))
852 (let ((char-db-ignored-attributes
854 char-db-ignored-attributes)))
855 (insert-char-attributes cell readable nil nil 'for-sub-node))
856 (setq separator lbs))
861 char (intern (format "%s*sources" name))))
862 (setq required-features nil)
863 (dolist (source sources)
867 shinjigen shinjigen@1ed shinjigen@rev))
868 (setq required-features
869 (union required-features
881 =shinjigen/+p@rev))))
883 (setq required-features
884 (union required-features
889 ((find-charset (setq ret (intern (format "=%s" source))))
890 (setq required-features
891 (cons ret required-features)))
892 (t (setq required-features
893 (cons source required-features)))))
894 (cond ((string-match "@JP" (symbol-name name))
895 (setq required-features
896 (union required-features
904 ((string-match "@CN" (symbol-name name))
905 (setq required-features
906 (union required-features
913 (insert (format "%S" cell))
914 (char-db-insert-char-spec cell readable
917 (setq separator lbs))
921 (if (consp (car cell))
922 (char-db-insert-char-spec cell readable)
923 (char-db-insert-char-reference cell readable))
924 (setq separator lbs))
928 (insert (prin1-to-string cell))
929 (setq separator " ")))
930 (setq value (cdr value)))
932 (insert line-breaking)))
934 (defun insert-char-attributes (char &optional readable attributes column
937 (setq column (current-column)))
938 (let (name value ; has-long-ccs-name
942 (concat "\n" (make-string (1+ column) ?\ )))
943 lbs cell separator ret
945 dest-ccss ; sources required-features
950 (if (consp attributes)
952 (dolist (name attributes)
953 (unless (memq name char-db-ignored-attributes)
954 (if (find-charset name)
958 (dolist (name (char-attribute-list))
959 (unless (memq name char-db-ignored-attributes)
960 (if (find-charset name)
964 #'char-attribute-name<)))
966 (when (memq '<-subsumptive attributes)
967 (when (or readable (not for-sub-node))
968 (when (setq value (get-char-attribute char '<-subsumptive))
969 (char-db-insert-relation-feature char '<-subsumptive value
972 (setq attributes (delq '<-subsumptive attributes)))
973 (when (and (memq '<-denotational attributes)
974 (setq value (get-char-attribute char '<-denotational)))
975 (char-db-insert-relation-feature char '<-denotational value
978 (setq attributes (delq '<-denotational attributes)))
979 (when (and (memq '<-denotational@component attributes)
980 (setq value (get-char-attribute char '<-denotational@component)))
981 (char-db-insert-relation-feature char '<-denotational@component value
984 (setq attributes (delq '<-denotational@component attributes)))
985 (when (and (memq '<-denotational@usage attributes)
986 (setq value (get-char-attribute char '<-denotational@usage)))
987 (char-db-insert-relation-feature char '<-denotational@usage value
990 (setq attributes (delq '<-denotational@usage attributes)))
991 (when (and (memq 'name attributes)
992 (setq value (get-char-attribute char 'name)))
994 (if (> (+ (current-column) (length value)) 48)
997 value line-breaking))
998 (setq attributes (delq 'name attributes))
1000 (when (and (memq 'name* attributes)
1001 (setq value (get-char-attribute char 'name*)))
1003 (if (> (+ (current-column) (length value)) 48)
1006 value line-breaking))
1007 (setq attributes (delq 'name* attributes))
1009 (when (and (memq 'script attributes)
1010 (setq value (get-char-attribute char 'script)))
1011 (insert (format "(script\t\t%s)%s"
1012 (mapconcat (function prin1-to-string)
1015 (setq attributes (delq 'script attributes))
1017 (dolist (name '(=>ucs =>ucs*))
1018 (when (and (memq name attributes)
1019 (setq value (get-char-attribute char name)))
1020 (insert (format "(%-18s . #x%04X)\t; %c%s"
1021 name value (decode-char '=ucs value)
1023 (setq attributes (delq name attributes))))
1024 (dolist (name '(=>ucs@gb =>ucs@big5))
1025 (when (and (memq name attributes)
1026 (setq value (get-char-attribute char name)))
1027 (insert (format "(%-18s . #x%04X)\t; %c%s"
1029 (decode-char (intern
1032 (symbol-name name) 2)))
1035 (setq attributes (delq name attributes))
1037 ;; (dolist (name '(=>daikanwa))
1038 ;; (when (and (memq name attributes)
1039 ;; (setq value (get-char-attribute char name)))
1041 ;; (if (integerp value)
1042 ;; (format "(%-18s . %05d)\t; %c%s"
1043 ;; name value (decode-char '=daikanwa value)
1045 ;; (format "(%-18s %s)\t; %c%s"
1047 ;; (mapconcat (function prin1-to-string)
1049 ;; (char-representative-of-daikanwa char)
1051 ;; (setq attributes (delq name attributes))))
1052 (when (and (memq 'general-category attributes)
1053 (setq value (get-char-attribute char 'general-category)))
1055 "(general-category\t%s) ; %s%s"
1056 (mapconcat (lambda (cell)
1059 (cond ((rassoc value unidata-normative-category-alist)
1060 "Normative Category")
1061 ((rassoc value unidata-informative-category-alist)
1062 "Informative Category")
1064 "Unknown Category"))
1066 (setq attributes (delq 'general-category attributes))
1068 (when (and (memq 'bidi-category attributes)
1069 (setq value (get-char-attribute char 'bidi-category)))
1070 (insert (format "(bidi-category\t. %S)%s"
1073 (setq attributes (delq 'bidi-category attributes))
1075 (unless (or (not (memq 'mirrored attributes))
1076 (eq (setq value (get-char-attribute char 'mirrored 'empty))
1078 (insert (format "(mirrored\t\t. %S)%s"
1081 (setq attributes (delq 'mirrored attributes))
1084 ((and (memq 'decimal-digit-value attributes)
1085 (setq value (get-char-attribute char 'decimal-digit-value)))
1086 (insert (format "(decimal-digit-value . %S)%s"
1089 (setq attributes (delq 'decimal-digit-value attributes))
1090 (when (and (memq 'digit-value attributes)
1091 (setq value (get-char-attribute char 'digit-value)))
1092 (insert (format "(digit-value\t . %S)%s"
1095 (setq attributes (delq 'digit-value attributes))
1097 (when (and (memq 'numeric-value attributes)
1098 (setq value (get-char-attribute char 'numeric-value)))
1099 (insert (format "(numeric-value\t . %S)%s"
1102 (setq attributes (delq 'numeric-value attributes))
1106 (when (and (memq 'digit-value attributes)
1107 (setq value (get-char-attribute char 'digit-value)))
1108 (insert (format "(digit-value\t. %S)%s"
1111 (setq attributes (delq 'digit-value attributes))
1113 (when (and (memq 'numeric-value attributes)
1114 (setq value (get-char-attribute char 'numeric-value)))
1115 (insert (format "(numeric-value\t. %S)%s"
1118 (setq attributes (delq 'numeric-value attributes))
1120 (when (and (memq 'iso-10646-comment attributes)
1121 (setq value (get-char-attribute char 'iso-10646-comment)))
1122 (insert (format "(iso-10646-comment\t. %S)%s"
1125 (setq attributes (delq 'iso-10646-comment attributes))
1127 (when (and (memq 'morohashi-daikanwa attributes)
1128 (setq value (get-char-attribute char 'morohashi-daikanwa)))
1129 (insert (format "(morohashi-daikanwa\t%s)%s"
1130 (mapconcat (function prin1-to-string) value " ")
1132 (setq attributes (delq 'morohashi-daikanwa attributes))
1136 (when (and (memq 'ideographic-radical attributes)
1137 (setq value (get-char-attribute char 'ideographic-radical)))
1138 (setq radical value)
1139 (insert (format "(ideographic-radical . %S)\t; %c%s"
1141 (ideographic-radical radical)
1143 (setq attributes (delq 'ideographic-radical attributes))
1145 (when (and (memq 'shuowen-radical attributes)
1146 (setq value (get-char-attribute char 'shuowen-radical)))
1147 (insert (format "(shuowen-radical\t. %S)\t; %c%s"
1149 (shuowen-radical value)
1151 (setq attributes (delq 'shuowen-radical attributes))
1156 char-db-feature-domains
1158 (dolist (feature (char-attribute-list))
1159 (setq feature (symbol-name feature))
1161 "\\(radical\\|strokes\\)@\\([^@*]+\\)\\(\\*\\|$\\)"
1163 (setq domain (intern (match-string 2 feature)))
1164 (unless (memq domain dest)
1165 (setq dest (cons domain dest)))))
1166 (sort dest #'string<))))
1167 (setq key (intern (format "%s@%s" 'ideographic-radical domain)))
1168 (when (and (memq key attributes)
1169 (setq value (get-char-attribute char key)))
1170 (setq radical value)
1171 (insert (format "(%s . %S)\t; %c%s"
1174 (ideographic-radical radical)
1176 (setq attributes (delq key attributes))
1178 (setq key (intern (format "%s@%s" 'ideographic-strokes domain)))
1179 (when (and (memq key attributes)
1180 (setq value (get-char-attribute char key)))
1181 (setq strokes value)
1182 (insert (format "(%s . %S)%s"
1186 (setq attributes (delq key attributes))
1188 (setq key (intern (format "%s@%s" 'total-strokes domain)))
1189 (when (and (memq key attributes)
1190 (setq value (get-char-attribute char key)))
1191 (insert (format "(%s . %S)%s"
1195 (setq attributes (delq key attributes))
1197 (dolist (feature '(ideographic-radical
1200 (setq key (intern (format "%s@%s*sources" feature domain)))
1201 (when (and (memq key attributes)
1202 (setq value (get-char-attribute char key)))
1203 (insert (format "(%s%s" key line-breaking))
1204 (dolist (cell value)
1205 (insert (format " %s" cell)))
1207 (insert line-breaking)
1208 (setq attributes (delq key attributes))
1211 (when (and (memq 'ideographic-strokes attributes)
1212 (setq value (get-char-attribute char 'ideographic-strokes)))
1213 (setq strokes value)
1214 (insert (format "(ideographic-strokes . %S)%s"
1217 (setq attributes (delq 'ideographic-strokes attributes))
1219 (when (and (memq 'kangxi-radical attributes)
1220 (setq value (get-char-attribute char 'kangxi-radical)))
1221 (unless (eq value radical)
1222 (insert (format "(kangxi-radical\t . %S)\t; %c%s"
1224 (ideographic-radical value)
1227 (setq radical value)))
1228 (setq attributes (delq 'kangxi-radical attributes))
1230 (when (and (memq 'kangxi-strokes attributes)
1231 (setq value (get-char-attribute char 'kangxi-strokes)))
1232 (unless (eq value strokes)
1233 (insert (format "(kangxi-strokes\t . %S)%s"
1237 (setq strokes value)))
1238 (setq attributes (delq 'kangxi-strokes attributes))
1240 ;; (when (and (memq 'japanese-radical attributes)
1241 ;; (setq value (get-char-attribute char 'japanese-radical)))
1242 ;; (unless (eq value radical)
1243 ;; (insert (format "(japanese-radical\t . %S)\t; %c%s"
1245 ;; (ideographic-radical value)
1248 ;; (setq radical value)))
1249 ;; (setq attributes (delq 'japanese-radical attributes))
1251 (when (and (memq 'japanese-strokes attributes)
1252 (setq value (get-char-attribute char 'japanese-strokes)))
1253 (unless (eq value strokes)
1254 (insert (format "(japanese-strokes\t . %S)%s"
1258 (setq strokes value)))
1259 (setq attributes (delq 'japanese-strokes attributes))
1261 (when (and (memq 'cns-radical attributes)
1262 (setq value (get-char-attribute char 'cns-radical)))
1263 (insert (format "(cns-radical\t . %S)\t; %c%s"
1265 (ideographic-radical value)
1267 (setq attributes (delq 'cns-radical attributes))
1269 (when (and (memq 'cns-strokes attributes)
1270 (setq value (get-char-attribute char 'cns-strokes)))
1271 (unless (eq value strokes)
1272 (insert (format "(cns-strokes\t . %S)%s"
1276 (setq strokes value)))
1277 (setq attributes (delq 'cns-strokes attributes))
1279 ;; (when (and (memq 'ideographic- attributes)
1280 ;; (setq value (get-char-attribute char 'ideographic-)))
1281 ;; (insert "(ideographic- ")
1282 ;; (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1284 ;; (while (consp value)
1285 ;; (setq cell (car value))
1286 ;; (if (integerp cell)
1287 ;; (setq cell (decode-char '=ucs cell)))
1288 ;; (cond ((characterp cell)
1292 ;; (insert (format "%S" cell))
1293 ;; (char-db-insert-char-spec cell readable))
1294 ;; (setq separator lbs))
1298 ;; (if (consp (car cell))
1299 ;; (char-db-insert-char-spec cell readable)
1300 ;; (char-db-insert-char-reference cell readable))
1301 ;; (setq separator lbs))
1304 ;; (insert separator))
1305 ;; (insert (prin1-to-string cell))
1306 ;; (setq separator " ")))
1307 ;; (setq value (cdr value)))
1309 ;; (insert line-breaking)
1310 ;; (setq attributes (delq 'ideographic- attributes)))
1311 (when (and (memq 'total-strokes attributes)
1312 (setq value (get-char-attribute char 'total-strokes)))
1313 (insert (format "(total-strokes . %S)%s"
1316 (setq attributes (delq 'total-strokes attributes))
1318 ;; (when (and (memq '->ideograph attributes)
1319 ;; (setq value (get-char-attribute char '->ideograph)))
1320 ;; (insert (format "(->ideograph\t%s)%s"
1321 ;; (mapconcat (lambda (code)
1322 ;; (cond ((symbolp code)
1323 ;; (symbol-name code))
1325 ;; (format "#x%04X" code))
1328 ;; line-breaking code))))
1331 ;; (setq attributes (delq '->ideograph attributes))
1333 ;; (when (and (memq '->decomposition attributes)
1334 ;; (setq value (get-char-attribute char '->decomposition)))
1335 ;; (insert (format "(->decomposition\t%s)%s"
1336 ;; (mapconcat (lambda (code)
1337 ;; (cond ((symbolp code)
1338 ;; (symbol-name code))
1339 ;; ((characterp code)
1341 ;; (format "%S" code)
1346 ;; (format "#x%04X" code))
1348 ;; (format "%s%S" line-breaking code))))
1351 ;; (setq attributes (delq '->decomposition attributes))
1353 (if (equal (get-char-attribute char '->titlecase)
1354 (get-char-attribute char '->uppercase))
1355 (setq attributes (delq '->titlecase attributes)))
1356 (when (and (memq '->mojikyo attributes)
1357 (setq value (get-char-attribute char '->mojikyo)))
1358 (insert (format "(->mojikyo\t\t. %06d)\t; %c%s"
1359 value (decode-char 'mojikyo value)
1361 (setq attributes (delq '->mojikyo attributes))
1364 (dolist (ignored '(composition
1365 ->denotational <-subsumptive ->ucs-unified
1366 ;; ->ideographic-component-forms
1368 (setq attributes (delq ignored attributes))))
1370 (setq name (car attributes))
1371 (unless (eq (setq value (get-char-attribute char name 'value-is-empty))
1373 (cond ((setq ret (find-charset name))
1374 (setq name (charset-name ret))
1375 (when (not (memq name dest-ccss))
1376 (setq dest-ccss (cons name dest-ccss))
1377 (char-db-insert-ccs-feature name value line-breaking))
1379 ((string-match "^=>ucs@" (symbol-name name))
1380 (insert (format "(%-18s . #x%04X)\t; %c%s"
1381 name value (decode-char '=ucs value)
1384 ((eq name 'jisx0208-1978/4X)
1385 (insert (format "(%-18s . #x%04X)%s"
1391 (not (eq name '->subsumptive))
1392 (not (eq name '->uppercase))
1393 (not (eq name '->lowercase))
1394 (not (eq name '->titlecase))
1395 (not (eq name '->canonical))
1396 (not (eq name '->Bopomofo))
1397 (not (eq name '->mistakable))
1398 (not (eq name '->ideographic-variants))
1399 (null (get-char-attribute
1400 char (intern (format "%s*sources" name))))
1401 (not (string-match "\\*sources$" (symbol-name name)))
1402 (null (get-char-attribute
1403 char (intern (format "%s*note" name))))
1404 (not (string-match "\\*note$" (symbol-name name)))
1405 (or (eq name '<-identical)
1406 (eq name '<-uppercase)
1407 (eq name '<-lowercase)
1408 (eq name '<-titlecase)
1409 (eq name '<-canonical)
1410 (eq name '<-ideographic-variants)
1411 ;; (eq name '<-synonyms)
1412 (string-match "^<-synonyms" (symbol-name name))
1413 (eq name '<-mistakable)
1414 (when (string-match "^->" (symbol-name name))
1416 ((string-match "^->fullwidth" (symbol-name name))
1417 (not (and (consp value)
1418 (characterp (car value))
1420 (car value) '=ucs 'defined-only)))
1425 ((or (eq name 'ideographic-structure)
1426 (eq name 'ideographic-structure@apparent)
1427 (eq name 'ideographic-combination)
1428 ;; (eq name 'ideographic-)
1429 (eq name '=decomposition)
1430 (char-feature-base-name= '=decomposition name)
1431 (char-feature-base-name= '=>decomposition name)
1432 ;; (string-match "^=>*decomposition\\(@[^*]+\\)?$"
1433 ;; (symbol-name name))
1434 (string-match "^\\(->\\|<-\\)[^*]*$" (symbol-name name))
1435 (string-match "^\\(->\\|<-\\)[^*]*\\*sources$"
1438 (char-db-insert-relation-feature char name value
1441 ;; ((memq name '(ideograph=
1442 ;; original-ideograph-of
1443 ;; ancient-ideograph-of
1444 ;; vulgar-ideograph-of
1445 ;; wrong-ideograph-of
1446 ;; ;; simplified-ideograph-of
1447 ;; ideographic-variants
1448 ;; ;; ideographic-different-form-of
1450 ;; (insert (format "(%-18s%s " name line-breaking))
1451 ;; (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1453 ;; (while (consp value)
1454 ;; (setq cell (car value))
1455 ;; (if (and (consp cell)
1456 ;; (consp (car cell)))
1460 ;; (char-db-insert-alist cell readable)
1461 ;; (setq separator lbs))
1463 ;; (insert separator))
1464 ;; (insert (prin1-to-string cell))
1465 ;; (setq separator " "))
1466 ;; (setq value (cdr value)))
1468 ;; (insert line-breaking))
1470 (insert (format "(%-18s " name))
1471 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1473 (while (consp value)
1474 (setq cell (car value))
1475 (if (and (consp cell)
1477 (setq ret (condition-case nil
1485 (setq key (car (car rest)))
1486 (if (find-charset key)
1487 (setq cal (cons key cal))
1488 (setq al (cons key al)))
1489 (setq rest (cdr rest)))
1492 (insert-char-attributes ret
1496 (setq separator lbs))
1497 (setq ret (prin1-to-string cell))
1499 (if (< (+ (current-column)
1506 (setq separator " "))
1507 (setq value (cdr value)))
1509 (insert line-breaking))
1511 (insert (format "(%-18s" name))
1512 (setq ret (prin1-to-string value))
1513 (unless (< (+ (current-column)
1517 (insert line-breaking))
1518 (insert " . " ret ")" line-breaking)
1519 ;; (insert (format "(%-18s . %S)%s"
1524 (setq attributes (cdr attributes)))
1527 (defun insert-char-data (char &optional readable
1530 (narrow-to-region (point)(point))
1531 (insert "(define-char
1533 (insert-char-attributes char readable attributes)
1535 (goto-char (point-min))
1536 (while (re-search-forward "[ \t]+$" nil t)
1539 (goto-char (point-min))
1540 (while (re-search-forward "[ \t][ \t][ \t]*" nil t)
1541 (let ((column (current-column))
1542 (indent-tabs-mode t))
1543 (delete-region (match-beginning 0) (point))
1544 (indent-to column)))
1545 (goto-char (point-max))
1546 ;; (tabify (point-min)(point-max))
1549 (defun insert-char-data-with-variant (char &optional printable
1551 script excluded-script)
1552 (insert-char-data char printable)
1553 (let ((variants (char-variants char))
1556 (setq variants (sort variants #'<))
1557 (setq rest variants)
1558 (setq variants (cons char variants))
1560 (setq variant (car rest))
1561 (unless (get-char-attribute variant '<-subsumptive)
1562 (if (and (or (null script)
1563 (null (setq vs (get-char-attribute variant 'script)))
1565 (or (null excluded-script)
1566 (null (setq vs (get-char-attribute variant 'script)))
1567 (not (memq excluded-script vs))))
1568 (unless (and no-ucs-unified (get-char-attribute variant '=ucs))
1569 (insert-char-data variant printable)
1570 (if (setq ret (char-variants variant))
1572 (or (memq (car ret) variants)
1573 ;; (get-char-attribute (car ret) '<-subsumptive)
1574 (setq rest (nconc rest (list (car ret)))))
1575 (setq ret (cdr ret)))))))
1576 (setq rest (cdr rest)))))
1578 (defun insert-char-range-data (min max &optional script excluded-script)
1581 (while (<= code max)
1582 (setq char (decode-char '=ucs code))
1583 (if (encode-char char '=ucs 'defined-only)
1584 (insert-char-data-with-variant char nil 'no-ucs-unified
1585 script excluded-script))
1586 (setq code (1+ code)))))
1588 (defun write-char-range-data-to-file (min max file
1589 &optional script excluded-script)
1590 (let ((coding-system-for-write char-db-file-coding-system))
1592 (insert (format ";; -*- coding: %s -*-\n"
1593 char-db-file-coding-system))
1594 (insert-char-range-data min max script excluded-script)
1595 (write-region (point-min)(point-max) file))))
1597 (defvar what-character-original-window-configuration)
1600 (defun what-char-definition (char)
1601 (interactive (list (char-after)))
1602 (let ((buf (get-buffer-create "*Character Description*"))
1603 (the-buf (current-buffer))
1604 (win-conf (current-window-configuration)))
1606 (make-local-variable 'what-character-original-window-configuration)
1607 (setq what-character-original-window-configuration win-conf)
1608 (setq buffer-read-only nil)
1612 (insert-char-data-with-variant char 'printable)
1613 (unless (char-attribute-alist char)
1614 (insert (format ";; = %c\n"
1615 (let* ((rest (split-char char))
1619 (setq code (logior (lsh code 8)
1621 (decode-char ccs code)))))
1622 ;; (char-db-update-comment)
1623 (set-buffer-modified-p nil)
1624 (view-mode the-buf (lambda (buf)
1625 (set-window-configuration
1626 what-character-original-window-configuration)
1628 (goto-char (point-min)))
1630 (set-window-configuration
1631 what-character-original-window-configuration)
1632 (signal (car err) (cdr err)))))))
1638 (provide 'char-db-util)
1640 ;;; char-db-util.el ends here