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 MORIOKA Tomohiko.
6 ;; Author: MORIOKA Tomohiko <tomo@kanji.zinbun.kyoto-u.ac.jp>
7 ;; Keywords: CHISE, Character Database, ISO/IEC 10646, UCS, Unicode, MULE.
9 ;; This file is part of XEmacs CHISE.
11 ;; XEmacs CHISE is free software; you can redistribute it and/or
12 ;; modify it under the terms of the GNU General Public License as
13 ;; published by the Free Software Foundation; either version 2, or (at
14 ;; your option) any later version.
16 ;; XEmacs CHISE is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 ;; General Public License for more details.
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with XEmacs CHISE; see the file COPYING. If not, write to
23 ;; the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
24 ;; Boston, MA 02111-1307, USA.
29 (require 'ideograph-subr)
31 (defconst unidata-normative-category-alist
32 '(("Lu" letter uppercase)
33 ("Ll" letter lowercase)
34 ("Lt" letter titlecase)
35 ("Mn" mark non-spacing)
36 ("Mc" mark spacing-combining)
38 ("Nd" number decimal-digit)
41 ("Zs" separator space)
43 ("Zp" separator paragraph)
46 ("Cs" other surrogate)
47 ("Co" other private-use)
48 ("Cn" other not-assigned)))
50 (defconst unidata-informative-category-alist
51 '(("Lm" letter modifier)
53 ("Pc" punctuation connector)
54 ("Pd" punctuation dash)
55 ("Ps" punctuation open)
56 ("Pe" punctuation close)
57 ("Pi" punctuation initial-quote)
58 ("Pf" punctuation final-quote)
59 ("Po" punctuation other)
61 ("Sc" symbol currency)
62 ("Sk" symbol modifier)
66 (defconst shuowen-radicals
67 [?一 ?上 ?示 ?三 ?王 ?玉 ?玨 ?气 ?士 ?丨 ; 010
68 ?屮 ?艸 ?蓐 ?茻 ?小 ?八 ?釆 ?半 ?牛 ?犛 ; 020
69 ?告 ?口 ?凵 ?吅 ?哭 ?走 ?止 ?癶 ?步 ?此 ; 030
70 ?正 ?是 ?辵 ?彳 ?廴 ?㢟 ?行 ?齒 ?牙 ?足 ; 040
71 ?疋 ?品 ?龠 ?冊 ?㗊 ?舌 ?干 ?𧮫 ?只 ?㕯 ; 050
72 ?句 ?丩 ?古 ?十 ?卅 ?言 ?誩 ?音 ?䇂 ?丵 ; 060
73 ?菐 ?廾 ?𠬜 ?共 ?異 ?舁 ?𦥑 ?䢅 ?爨 ?革 ; 070
74 ?鬲 ?䰜 ?爪 ?𠃨 ?鬥 ?又 ?𠂇 ?史 ?支 ?𦘒 ; 080
75 ?聿 ?畫 ?隶 ?臤 ?臣 ?殳 ?殺 ?𠘧 ?寸 ?皮 ; 090
76 ?㼱 ?攴 ?敎 ?卜 ?用 ?爻 ?㸚 ?𥄎 ?目 ?䀠 ; 100
77 ?眉 ?盾 ?自 ?白 ?鼻 ?皕 ?習 ?羽 ?隹 ?奞 ; 110
78 ?雈 ?𦫳 ?𥄕 ?羊 ?羴 ?瞿 ?雔 ?雥 ?鳥 ?烏 ; 120
79 ?𠦒 ?冓 ?幺 ?𢆶 ?叀 ?玄 ?予 ?放 ?𠬪 ?𣦼 ; 130
80 ?歺 ?死 ?冎 ?骨 ?肉 ?筋 ?刀 ?刃 ?㓞 ?丯 ; 140
81 ?耒 ?角 ?竹 ?箕 ?丌 ?左 ?工 ?㠭 ?巫 ?甘 ; 150
82 ?曰 ?乃 ?丂 ?可 ?兮 ?号 ?亏 ?旨 ?喜 ?壴 ; 160
83 ; ?旨 ?曰 ?乃 ?丂 ?可 ?兮 ?号 ?亏 ?喜 ?壴 ; 160
84 ?鼓 ?豈 ?豆 ?豊 ?豐 ?䖒 ?虍 ?虎 ?虤 ?皿 ; 170
85 ?𠙴 ?去 ?血 ?丶 ?丹 ?青 ?井 ?皀 ?鬯 ?食 ; 180
86 ?亼 ?會 ?倉 ?入 ?缶 ?矢 ?高 ?冂 ?𩫏 ?京 ; 190
87 ?亯 ?𣆪 ?畗 ?㐭 ?嗇 ?來 ?麥 ?夊 ?舛 ?䑞 ; 200
88 ?韋 ?弟 ?夂 ?久 ?桀 ?木 ?東 ?林 ?才 ?叒 ; 210
89 ?之 ?帀 ?出 ?𣎵 ?生 ?乇 ?𠂹 ?𠌶 ?華 ?𥝌 ; 220
90 ?稽 ?巢 ?桼 ?束 ?㯻 ?囗 ?員 ?貝 ?邑 ?𨛜 ; 230
91 ?日 ?旦 ?倝 ?㫃 ?冥 ?晶 ?月 ?有 ?明 ?囧 ; 240
92 ?夕 ?多 ?毌 ?𢎘 ?𣐺 ?𠧪 ?齊 ?朿 ?片 ?鼎 ; 250
93 ?克 ?彔 ?禾 ?秝 ?黍 ?香 ?米 ?毇 ?臼 ?凶 ; 260
94 ?𣎳 ?𣏟 ?麻 ?尗 ?耑 ?韭 ?瓜 ?瓠 ?宀 ?宮 ; 270
95 ?呂 ?穴 ?㝱 ?疒 ?冖 ?𠔼 ?冃 ?㒳 ?网 ?襾 ; 280
96 ?巾 ?巿 ?帛 ?白 ?㡀 ?黹 ?人 ?𠤎 ?匕 ?从 ; 290
97 ?比 ?北 ?丘 ?㐺 ?𡈼 ?重 ?臥 ?身 ?㐆 ?衣 ; 300
98 ?裘 ?老 ?毛 ?毳 ?尸 ?尺 ?尾 ?履 ?舟 ?方 ; 310
99 ?儿 ?兄 ?兂 ?皃 ?𠑹 ?先 ?秃 ?見 ?覞 ?欠 ; 320
100 ?㱃 ?㳄 ?旡 ?頁 ?𦣻 ?面 ?丏 ?首 ?𥄉 ?須 ; 330
101 ?彡 ?彣 ?文 ?髟 ?后 ?司 ?卮 ?卩 ?印 ?色 ; 340
102 ?𠨍 ?辟 ?勹 ?包 ?茍 ?鬼 ?甶 ?厶 ?嵬 ?山 ; 350
103 ?屾 ?屵 ?广 ?厂 ?丸 ?危 ?石 ?長 ?勿 ?冄 ; 360
104 ?而 ?豕 ?㣇 ?彑 ?豚 ?豸 ?𤉡 ?易 ?象 ?馬 ; 370
105 ?𢊁 ?鹿 ?麤 ?㲋 ?兔 ?萈 ?犬 ?㹜 ?鼠 ?能 ; 380
106 ?熊 ?火 ?炎 ?黑 ?囪 ?焱 ?炙 ?赤 ?大 ?亦 ; 390
107 ?夨 ?夭 ?交 ?尣 ?壺 ?壹 ?㚔 ?奢 ?亢 ?夲 ; 400
110 (defun shuowen-radical (number)
111 (aref shuowen-radicals (1- number)))
113 (defvar char-db-file-coding-system 'utf-8-mcs-er)
115 (defvar char-db-ignored-attributes '(ideographic-products))
117 (defvar char-db-coded-charset-priority-list
215 ;; =>>>adobe-japan1-0
216 ;; =>>>adobe-japan1-1
217 ;; =>>>adobe-japan1-2
218 ;; =>>>adobe-japan1-3
219 ;; =>>>adobe-japan1-4
220 ;; =>>>adobe-japan1-5
221 ;; =>>>adobe-japan1-6
225 ;; =>>>hanyo-denshi/ja
226 ;; =>>>hanyo-denshi/jb
227 ;; =>>>hanyo-denshi/jc
228 ;; =>>>hanyo-denshi/ft
229 ;; =>>>hanyo-denshi/ib
230 ;; =>>>hanyo-denshi/hg
231 ;; =>>>hanyo-denshi/jt
232 ;; =>>>hanyo-denshi/ks
272 ;; =>ucs@hanyo-denshi
370 =>big5-cdp-itaiji-001
374 =>ucs-itaiji-001@iwds-1
384 ;;; @ char-db formatters
387 (defun char-db-make-char-spec (char)
389 (cond ((characterp char)
390 (cond ((and (setq ret (encode-char char '=ucs 'defined-only))
391 (not (and (<= #xE000 ret)(<= ret #xF8FF))))
392 (setq char-spec (list (cons '=ucs ret)))
393 (cond ((setq ret (get-char-attribute char 'name))
394 (setq char-spec (cons (cons 'name ret) char-spec))
396 ((setq ret (get-char-attribute char 'name*))
397 (setq char-spec (cons (cons 'name* ret) char-spec))
400 ((encode-char char '=mj 'defined-only)
402 (dolist (ccs (charset-list))
403 (if (and (or (eq ccs '=mj)
404 ;; (eq (charset-property ccs 'iso-ir) 177)
405 (string-match "=ucs@" (symbol-name ccs))
407 (setq ccs (charset-name ccs))
408 (null (assq ccs char-spec))
409 (setq ret (encode-char char ccs 'defined-only)))
410 (setq char-spec (cons (cons ccs ret) char-spec))))
412 ((encode-char char '==mj 'defined-only)
414 (dolist (ccs (charset-list))
415 (if (and (or (eq ccs '==mj)
416 ;; (eq (charset-property ccs 'iso-ir) 177)
417 (string-match "=ucs@" (symbol-name ccs))
419 (setq ccs (charset-name ccs))
420 (null (assq ccs char-spec))
421 (setq ret (encode-char char ccs 'defined-only)))
422 (setq char-spec (cons (cons ccs ret) char-spec))))
424 ((encode-char char '=adobe-japan1 'defined-only)
426 (dolist (ccs (charset-list))
427 (if (and (or (memq ccs
436 ;; (eq (charset-property ccs 'iso-ir) 177)
437 (string-match "=ucs@" (symbol-name ccs))
439 (setq ccs (charset-name ccs))
440 (null (assq ccs char-spec))
441 (setq ret (encode-char char ccs 'defined-only)))
442 (setq char-spec (cons (cons ccs ret) char-spec))))
444 ((encode-char char '==adobe-japan1 'defined-only)
446 (dolist (ccs (charset-list))
447 (if (and (or (memq ccs
456 ;; (eq (charset-property ccs 'iso-ir) 177)
457 (string-match "=ucs@" (symbol-name ccs))
459 (setq ccs (charset-name ccs))
460 (null (assq ccs char-spec))
461 (setq ret (encode-char char ccs 'defined-only)))
462 (setq char-spec (cons (cons ccs ret) char-spec))))
466 (let ((rest char-db-coded-charset-priority-list)
469 (setq ccs (charset-name
470 (find-charset (car rest))))
472 (encode-char char ccs
474 (throw 'tag (cons ccs ret)))
475 (setq rest (cdr rest))))))
476 (setq char-spec (list ret))
477 (dolist (ccs (delq (car ret) (charset-list)))
478 (if (and (or (charset-iso-final-char ccs)
485 (and (eq (charset-property ccs 'iso-ir) 177)
486 (not (eq (charset-name ccs) '=ucs@big5)))
487 ;; (string-match "=ucs@" (symbol-name ccs))
489 (setq ccs (charset-name ccs))
490 (null (assq ccs char-spec))
491 (setq ret (encode-char char ccs 'defined-only)))
492 (setq char-spec (cons (cons ccs ret) char-spec))))
494 (setq char-spec (split-char char)))
495 (cond ((setq ret (get-char-attribute char 'name))
496 (setq char-spec (cons (cons 'name ret) char-spec))
498 ((setq ret (get-char-attribute char 'name*))
499 (setq char-spec (cons (cons 'name* ret) char-spec))
502 ((setq ret (get-char-attribute
503 char 'ideographic-combination))
505 (cons (cons 'ideographic-combination ret)
512 (defun char-db-insert-char-spec (char &optional readable column
515 (setq column (current-column)))
516 (let (char-spec temp-char)
517 (setq char-spec (char-db-make-char-spec char))
518 (unless (or (characterp char) ; char
520 (setq char (find-char char-spec))
522 ;; define temporary character
523 ;; Current implementation is dirty.
524 (setq temp-char (define-char (cons '(ideograph-daikanwa . 0)
526 (remove-char-attribute temp-char 'ideograph-daikanwa)
527 (setq char temp-char))
528 (insert-char-attributes char
530 (union (mapcar #'car char-spec)
534 ;; undefine temporary character
535 ;; Current implementation is dirty.
536 (setq char-spec (char-attribute-alist temp-char))
538 (remove-char-attribute temp-char (car (car char-spec)))
539 (setq char-spec (cdr char-spec))))))
541 (defun char-db-insert-alist (alist &optional readable column)
543 (setq column (current-column)))
545 (concat "\n" (make-string (1+ column) ?\ )))
549 lbs cell rest separator)
552 (setq name (car (car alist))
553 value (cdr (car alist)))
554 (cond ((eq name 'char)
556 (if (setq ret (condition-case nil
564 (setq key (car (car value)))
565 ;; (if (find-charset key)
566 ;; (setq cal (cons key cal))
567 (setq al (cons key al))
569 (setq value (cdr value)))
570 (insert-char-attributes ret
574 (insert (prin1-to-string value)))
576 (insert line-breaking))
578 (insert (format "(%-18s " name))
579 (setq lbs (concat "\n" (make-string (current-column) ?\ )))
581 (setq cell (car value))
582 (if (and (consp cell)
584 (setq ret (condition-case nil
594 (setq key (car (car rest)))
595 ;; (if (find-charset key)
596 ;; (setq cal (cons key cal))
597 (setq al (cons key al))
599 (setq rest (cdr rest)))
602 (insert-char-attributes ret
606 (setq separator lbs))
609 (insert (prin1-to-string cell))
610 (setq separator " "))
611 (setq value (cdr value)))
613 (insert line-breaking))
615 (insert (format "(%-18s . %S)%s"
618 (setq alist (cdr alist))))
621 (defun char-db-insert-char-reference (plist &optional readable column)
623 (setq column (current-column)))
625 (concat "\n" (make-string (1+ column) ?\ )))
630 (setq name (pop plist))
631 (setq value (pop plist))
632 (cond ((eq name :char)
635 (cond ((numberp value)
636 (setq value (decode-char '=ucs value)))
638 ;; (setq value (or (find-char value)
641 (char-db-insert-char-spec value readable)
642 (insert line-breaking)
645 (insert (format "%s%s\t%d ; %c%s"
648 (ideographic-radical value)
652 (insert (format "%s%s\t%S" separator name value))
653 (setq separator line-breaking)))
657 (defun char-db-decode-isolated-char (ccs code-point)
660 (cond ((eq ccs 'arabic-iso8859-6)
661 (decode-char ccs code-point))
663 ;; (decode-builtin-char '==gt code-point))
664 ((and (memq ccs '(=gt-pj-1
675 (setq ret (decode-char ccs code-point))
676 (setq ret (encode-char ret '=gt 'defined-only)))
677 (decode-builtin-char '=gt ret))
679 (decode-builtin-char ccs code-point))))
681 (or (decode-char ccs code-point)
682 (define-char (list (cons ccs code-point)))))
683 ((and (<= 0 (char-int ret))
684 (<= (char-int ret) #x1F))
685 (decode-char '=ucs (+ #x2400 (char-int ret))))
686 ((= (char-int ret) #x7F)
690 (defvar char-db-convert-obsolete-format t)
692 (defun char-db-insert-ccs-feature (name value line-breaking)
698 ((memq name '(=>iwds-1
701 =shinjigen@1ed ==shinjigen@1ed
702 =shinjigen@rev ==shinjigen@rev
703 =shinjigen/+p@rev ==shinjigen/+p@rev
704 ===daikanwa/ho ==daikanwa/ho
705 =daikanwa/ho =>>daikanwa/ho =>daikanwa/ho))
706 "(%-18s . %04d)\t; %c")
707 ((eq name '=shinjigen@1ed/24pr)
708 "(%-18s . %04d)\t; %c")
712 ==daikanwa =daikanwa =>>daikanwa =>daikanwa
713 =daikanwa@rev1 =daikanwa@rev2
714 =daikanwa/+p ==daikanwa/+p ===daikanwa/+p
716 =daikanwa/+2p =>>daikanwa/+2p
721 =adobe-japan1-0 ==adobe-japan1-0 ===adobe-japan1-0
722 =adobe-japan1-1 ==adobe-japan1-1 ===adobe-japan1-1
723 =adobe-japan1-2 ==adobe-japan1-2 ===adobe-japan1-2
724 =adobe-japan1-3 ==adobe-japan1-3 ===adobe-japan1-3
725 =adobe-japan1-4 ==adobe-japan1-4 ===adobe-japan1-4
726 =adobe-japan1-5 ==adobe-japan1-5 ===adobe-japan1-5
727 =adobe-japan1-6 ==adobe-japan1-6 ===adobe-japan1-6
728 =>>adobe-japan1-0 =+>adobe-japan1-0
729 =>>adobe-japan1-1 =+>adobe-japan1-1
730 =>>adobe-japan1-2 =+>adobe-japan1-2
731 =>>adobe-japan1-3 =+>adobe-japan1-3
732 =>>adobe-japan1-4 =+>adobe-japan1-4
733 =>>adobe-japan1-5 =+>adobe-japan1-5
734 =>>adobe-japan1-6 =+>adobe-japan1-6
735 =>cbeta =cbeta =>>cbeta ==cbeta ===cbeta
736 =zinbun-oracle =>zinbun-oracle
737 =daijiten ==daijiten ===daijiten
738 ===hng-jou ===hng-keg ===hng-dng ===hng-mam
739 ===hng-drt ===hng-kgk ===hng-myz ===hng-kda
740 ===hng-khi ===hng-khm ===hng-hok ===hng-kyd ===hng-sok
741 ===hng-yhk ===hng-kak ===hng-kar ===hng-kae
742 ===hng-sys ===hng-tsu ===hng-tzj
743 ===hng-hos ===hng-nak ===hng-jhk
744 ===hng-hod ===hng-gok ===hng-ink ===hng-nto
745 ===hng-nkm ===hng-k24 ===hng-nkk
746 ===hng-kcc ===hng-kcj ===hng-kbk ===hng-sik
747 ===hng-skk ===hng-kyu ===hng-ksk ===hng-wan
748 ===hng-okd ===hng-wad ===hng-kmi
749 ===hng-zkd ===hng-doh ===hng-jyu
750 ===hng-tzs ===hng-kss ===hng-kyo
752 =shuowen-jiguge ===shuowen-jiguge4 ===shuowen-jiguge5))
753 ;; (string-match "^=adobe-" (symbol-name name))
755 "(%-18s . %05d)\t; %c")
756 ((memq name '(=hanyo-denshi/ks
757 ==hanyo-denshi/ks ===hanyo-denshi/ks
760 =mj ==mj ===mj =>>mj =>mj
762 "(%-18s . %06d)\t; %c")
763 ((memq name '(=hanyo-denshi/tk ==hanyo-denshi/tk))
764 "(%-18s . %08d)\t; %c")
765 ((>= (charset-dimension name) 2)
766 "(%-18s . #x%04X)\t; %c")
768 "(%-18s . #x%02X)\t; %c"))
770 (if (= (charset-iso-graphic-plane name) 1)
772 (cond ((= (charset-dimension name) 1)
774 ((= (charset-dimension name) 2)
776 ((= (charset-dimension name) 3)
780 (char-db-decode-isolated-char name value)))
781 (if (and (= (charset-chars name) 94)
782 (= (charset-dimension name) 2))
783 (insert (format " [%02d-%02d]"
784 (- (lsh value -8) 32)
785 (- (logand value 255) 32))))
788 (insert (format "(%-18s . %s)" name value))
790 (insert line-breaking))
792 (defun char-db-insert-relation-feature (char name value line-breaking
794 (insert (format "(%-18s%s " name line-breaking))
795 (let ((lbs (concat "\n" (make-string (current-column) ?\ )))
796 separator cell sources required-features
799 (setq cell (car value))
801 (setq cell (decode-char '=ucs cell)))
803 ((eq name '->subsumptive)
804 (when (or (not (some (lambda (atr)
805 (get-char-attribute cell atr))
806 char-db-ignored-attributes))
808 (encode-char cell ccs 'defined-only))
812 (let ((char-db-ignored-attributes
814 char-db-ignored-attributes)))
815 (insert-char-attributes cell readable nil nil 'for-sub-node))
816 (setq separator lbs))
821 char (intern (format "%s*sources" name))))
822 (setq required-features nil)
823 (dolist (source sources)
827 shinjigen shinjigen@1ed shinjigen@rev))
828 (setq required-features
829 (union required-features
841 =shinjigen/+p@rev))))
843 (setq required-features
844 (union required-features
849 ((find-charset (setq ret (intern (format "=%s" source))))
850 (setq required-features
851 (cons ret required-features)))
852 (t (setq required-features
853 (cons source required-features)))))
854 (cond ((string-match "@JP" (symbol-name name))
855 (setq required-features
856 (union required-features
864 ((string-match "@CN" (symbol-name name))
865 (setq required-features
866 (union required-features
873 (insert (format "%S" cell))
874 (char-db-insert-char-spec cell readable
877 (setq separator lbs))
881 (if (consp (car cell))
882 (char-db-insert-char-spec cell readable)
883 (char-db-insert-char-reference cell readable))
884 (setq separator lbs))
888 (insert (prin1-to-string cell))
889 (setq separator " ")))
890 (setq value (cdr value)))
892 (insert line-breaking)))
894 (defun insert-char-attributes (char &optional readable attributes column
897 (setq column (current-column)))
898 (let (name value ; has-long-ccs-name
902 (concat "\n" (make-string (1+ column) ?\ )))
903 lbs cell separator ret
905 dest-ccss ; sources required-features
910 (if (consp attributes)
912 (dolist (name attributes)
913 (unless (memq name char-db-ignored-attributes)
914 (if (find-charset name)
918 (dolist (name (char-attribute-list))
919 (unless (memq name char-db-ignored-attributes)
920 (if (find-charset name)
924 #'char-attribute-name<)))
926 (when (memq '<-subsumptive attributes)
927 (when (or readable (not for-sub-node))
928 (when (setq value (get-char-attribute char '<-subsumptive))
929 (char-db-insert-relation-feature char '<-subsumptive value
932 (setq attributes (delq '<-subsumptive attributes)))
933 (when (and (memq '<-denotational attributes)
934 (setq value (get-char-attribute char '<-denotational)))
935 (char-db-insert-relation-feature char '<-denotational value
938 (setq attributes (delq '<-denotational attributes)))
939 (when (and (memq '<-denotational@component attributes)
940 (setq value (get-char-attribute char '<-denotational@component)))
941 (char-db-insert-relation-feature char '<-denotational@component value
944 (setq attributes (delq '<-denotational@component attributes)))
945 (when (and (memq 'name attributes)
946 (setq value (get-char-attribute char 'name)))
948 (if (> (+ (current-column) (length value)) 48)
951 value line-breaking))
952 (setq attributes (delq 'name attributes))
954 (when (and (memq 'name* attributes)
955 (setq value (get-char-attribute char 'name*)))
957 (if (> (+ (current-column) (length value)) 48)
960 value line-breaking))
961 (setq attributes (delq 'name* attributes))
963 (when (and (memq 'script attributes)
964 (setq value (get-char-attribute char 'script)))
965 (insert (format "(script\t\t%s)%s"
966 (mapconcat (function prin1-to-string)
969 (setq attributes (delq 'script attributes))
971 (dolist (name '(=>ucs =>ucs*))
972 (when (and (memq name attributes)
973 (setq value (get-char-attribute char name)))
974 (insert (format "(%-18s . #x%04X)\t; %c%s"
975 name value (decode-char '=ucs value)
977 (setq attributes (delq name attributes))))
978 (dolist (name '(=>ucs@gb =>ucs@big5))
979 (when (and (memq name attributes)
980 (setq value (get-char-attribute char name)))
981 (insert (format "(%-18s . #x%04X)\t; %c%s"
986 (symbol-name name) 2)))
989 (setq attributes (delq name attributes))
991 ;; (dolist (name '(=>daikanwa))
992 ;; (when (and (memq name attributes)
993 ;; (setq value (get-char-attribute char name)))
995 ;; (if (integerp value)
996 ;; (format "(%-18s . %05d)\t; %c%s"
997 ;; name value (decode-char '=daikanwa value)
999 ;; (format "(%-18s %s)\t; %c%s"
1001 ;; (mapconcat (function prin1-to-string)
1003 ;; (char-representative-of-daikanwa char)
1005 ;; (setq attributes (delq name attributes))))
1006 (when (and (memq 'general-category attributes)
1007 (setq value (get-char-attribute char 'general-category)))
1009 "(general-category\t%s) ; %s%s"
1010 (mapconcat (lambda (cell)
1013 (cond ((rassoc value unidata-normative-category-alist)
1014 "Normative Category")
1015 ((rassoc value unidata-informative-category-alist)
1016 "Informative Category")
1018 "Unknown Category"))
1020 (setq attributes (delq 'general-category attributes))
1022 (when (and (memq 'bidi-category attributes)
1023 (setq value (get-char-attribute char 'bidi-category)))
1024 (insert (format "(bidi-category\t. %S)%s"
1027 (setq attributes (delq 'bidi-category attributes))
1029 (unless (or (not (memq 'mirrored attributes))
1030 (eq (setq value (get-char-attribute char 'mirrored 'empty))
1032 (insert (format "(mirrored\t\t. %S)%s"
1035 (setq attributes (delq 'mirrored attributes))
1038 ((and (memq 'decimal-digit-value attributes)
1039 (setq value (get-char-attribute char 'decimal-digit-value)))
1040 (insert (format "(decimal-digit-value . %S)%s"
1043 (setq attributes (delq 'decimal-digit-value attributes))
1044 (when (and (memq 'digit-value attributes)
1045 (setq value (get-char-attribute char 'digit-value)))
1046 (insert (format "(digit-value\t . %S)%s"
1049 (setq attributes (delq 'digit-value attributes))
1051 (when (and (memq 'numeric-value attributes)
1052 (setq value (get-char-attribute char 'numeric-value)))
1053 (insert (format "(numeric-value\t . %S)%s"
1056 (setq attributes (delq 'numeric-value attributes))
1060 (when (and (memq 'digit-value attributes)
1061 (setq value (get-char-attribute char 'digit-value)))
1062 (insert (format "(digit-value\t. %S)%s"
1065 (setq attributes (delq 'digit-value attributes))
1067 (when (and (memq 'numeric-value attributes)
1068 (setq value (get-char-attribute char 'numeric-value)))
1069 (insert (format "(numeric-value\t. %S)%s"
1072 (setq attributes (delq 'numeric-value attributes))
1074 (when (and (memq 'iso-10646-comment attributes)
1075 (setq value (get-char-attribute char 'iso-10646-comment)))
1076 (insert (format "(iso-10646-comment\t. %S)%s"
1079 (setq attributes (delq 'iso-10646-comment attributes))
1081 (when (and (memq 'morohashi-daikanwa attributes)
1082 (setq value (get-char-attribute char 'morohashi-daikanwa)))
1083 (insert (format "(morohashi-daikanwa\t%s)%s"
1084 (mapconcat (function prin1-to-string) value " ")
1086 (setq attributes (delq 'morohashi-daikanwa attributes))
1090 (when (and (memq 'ideographic-radical attributes)
1091 (setq value (get-char-attribute char 'ideographic-radical)))
1092 (setq radical value)
1093 (insert (format "(ideographic-radical . %S)\t; %c%s"
1095 (ideographic-radical radical)
1097 (setq attributes (delq 'ideographic-radical attributes))
1099 (when (and (memq 'shuowen-radical attributes)
1100 (setq value (get-char-attribute char 'shuowen-radical)))
1101 (insert (format "(shuowen-radical\t. %S)\t; %c%s"
1103 (shuowen-radical value)
1105 (setq attributes (delq 'shuowen-radical attributes))
1110 char-db-feature-domains
1112 (dolist (feature (char-attribute-list))
1113 (setq feature (symbol-name feature))
1115 "\\(radical\\|strokes\\)@\\([^@*]+\\)\\(\\*\\|$\\)"
1117 (setq domain (intern (match-string 2 feature)))
1118 (unless (memq domain dest)
1119 (setq dest (cons domain dest)))))
1120 (sort dest #'string<))))
1121 (setq key (intern (format "%s@%s" 'ideographic-radical domain)))
1122 (when (and (memq key attributes)
1123 (setq value (get-char-attribute char key)))
1124 (setq radical value)
1125 (insert (format "(%s . %S)\t; %c%s"
1128 (ideographic-radical radical)
1130 (setq attributes (delq key attributes))
1132 (setq key (intern (format "%s@%s" 'ideographic-strokes domain)))
1133 (when (and (memq key attributes)
1134 (setq value (get-char-attribute char key)))
1135 (setq strokes value)
1136 (insert (format "(%s . %S)%s"
1140 (setq attributes (delq key attributes))
1142 (setq key (intern (format "%s@%s" 'total-strokes domain)))
1143 (when (and (memq key attributes)
1144 (setq value (get-char-attribute char key)))
1145 (insert (format "(%s . %S)%s"
1149 (setq attributes (delq key attributes))
1151 (dolist (feature '(ideographic-radical
1154 (setq key (intern (format "%s@%s*sources" feature domain)))
1155 (when (and (memq key attributes)
1156 (setq value (get-char-attribute char key)))
1157 (insert (format "(%s%s" key line-breaking))
1158 (dolist (cell value)
1159 (insert (format " %s" cell)))
1161 (insert line-breaking)
1162 (setq attributes (delq key attributes))
1165 (when (and (memq 'ideographic-strokes attributes)
1166 (setq value (get-char-attribute char 'ideographic-strokes)))
1167 (setq strokes value)
1168 (insert (format "(ideographic-strokes . %S)%s"
1171 (setq attributes (delq 'ideographic-strokes attributes))
1173 (when (and (memq 'kangxi-radical attributes)
1174 (setq value (get-char-attribute char 'kangxi-radical)))
1175 (unless (eq value radical)
1176 (insert (format "(kangxi-radical\t . %S)\t; %c%s"
1178 (ideographic-radical value)
1181 (setq radical value)))
1182 (setq attributes (delq 'kangxi-radical attributes))
1184 (when (and (memq 'kangxi-strokes attributes)
1185 (setq value (get-char-attribute char 'kangxi-strokes)))
1186 (unless (eq value strokes)
1187 (insert (format "(kangxi-strokes\t . %S)%s"
1191 (setq strokes value)))
1192 (setq attributes (delq 'kangxi-strokes attributes))
1194 ;; (when (and (memq 'japanese-radical attributes)
1195 ;; (setq value (get-char-attribute char 'japanese-radical)))
1196 ;; (unless (eq value radical)
1197 ;; (insert (format "(japanese-radical\t . %S)\t; %c%s"
1199 ;; (ideographic-radical value)
1202 ;; (setq radical value)))
1203 ;; (setq attributes (delq 'japanese-radical attributes))
1205 (when (and (memq 'japanese-strokes attributes)
1206 (setq value (get-char-attribute char 'japanese-strokes)))
1207 (unless (eq value strokes)
1208 (insert (format "(japanese-strokes\t . %S)%s"
1212 (setq strokes value)))
1213 (setq attributes (delq 'japanese-strokes attributes))
1215 (when (and (memq 'cns-radical attributes)
1216 (setq value (get-char-attribute char 'cns-radical)))
1217 (insert (format "(cns-radical\t . %S)\t; %c%s"
1219 (ideographic-radical value)
1221 (setq attributes (delq 'cns-radical attributes))
1223 (when (and (memq 'cns-strokes attributes)
1224 (setq value (get-char-attribute char 'cns-strokes)))
1225 (unless (eq value strokes)
1226 (insert (format "(cns-strokes\t . %S)%s"
1230 (setq strokes value)))
1231 (setq attributes (delq 'cns-strokes attributes))
1233 ;; (when (and (memq 'shinjigen-1-radical attributes)
1234 ;; (setq value (get-char-attribute char 'shinjigen-1-radical)))
1235 ;; (unless (eq value radical)
1236 ;; (insert (format "(shinjigen-1-radical . %S)\t; %c%s"
1238 ;; (ideographic-radical value)
1241 ;; (setq radical value)))
1242 ;; (setq attributes (delq 'shinjigen-1-radical attributes))
1244 ;; (when (and (memq 'ideographic- attributes)
1245 ;; (setq value (get-char-attribute char 'ideographic-)))
1246 ;; (insert "(ideographic- ")
1247 ;; (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1249 ;; (while (consp value)
1250 ;; (setq cell (car value))
1251 ;; (if (integerp cell)
1252 ;; (setq cell (decode-char '=ucs cell)))
1253 ;; (cond ((characterp cell)
1257 ;; (insert (format "%S" cell))
1258 ;; (char-db-insert-char-spec cell readable))
1259 ;; (setq separator lbs))
1263 ;; (if (consp (car cell))
1264 ;; (char-db-insert-char-spec cell readable)
1265 ;; (char-db-insert-char-reference cell readable))
1266 ;; (setq separator lbs))
1269 ;; (insert separator))
1270 ;; (insert (prin1-to-string cell))
1271 ;; (setq separator " ")))
1272 ;; (setq value (cdr value)))
1274 ;; (insert line-breaking)
1275 ;; (setq attributes (delq 'ideographic- attributes)))
1276 (when (and (memq 'total-strokes attributes)
1277 (setq value (get-char-attribute char 'total-strokes)))
1278 (insert (format "(total-strokes . %S)%s"
1281 (setq attributes (delq 'total-strokes attributes))
1283 ;; (when (and (memq '->ideograph attributes)
1284 ;; (setq value (get-char-attribute char '->ideograph)))
1285 ;; (insert (format "(->ideograph\t%s)%s"
1286 ;; (mapconcat (lambda (code)
1287 ;; (cond ((symbolp code)
1288 ;; (symbol-name code))
1290 ;; (format "#x%04X" code))
1293 ;; line-breaking code))))
1296 ;; (setq attributes (delq '->ideograph attributes))
1298 ;; (when (and (memq '->decomposition attributes)
1299 ;; (setq value (get-char-attribute char '->decomposition)))
1300 ;; (insert (format "(->decomposition\t%s)%s"
1301 ;; (mapconcat (lambda (code)
1302 ;; (cond ((symbolp code)
1303 ;; (symbol-name code))
1304 ;; ((characterp code)
1306 ;; (format "%S" code)
1311 ;; (format "#x%04X" code))
1313 ;; (format "%s%S" line-breaking code))))
1316 ;; (setq attributes (delq '->decomposition attributes))
1318 (if (equal (get-char-attribute char '->titlecase)
1319 (get-char-attribute char '->uppercase))
1320 (setq attributes (delq '->titlecase attributes)))
1321 (when (and (memq '->mojikyo attributes)
1322 (setq value (get-char-attribute char '->mojikyo)))
1323 (insert (format "(->mojikyo\t\t. %06d)\t; %c%s"
1324 value (decode-char 'mojikyo value)
1326 (setq attributes (delq '->mojikyo attributes))
1328 ;; (when (and (memq 'hanyu-dazidian-vol attributes)
1329 ;; (setq value (get-char-attribute char 'hanyu-dazidian-vol)))
1330 ;; (insert (format "(hanyu-dazidian-vol . %d)%s"
1331 ;; value line-breaking))
1332 ;; (setq attributes (delq 'hanyu-dazidian-vol attributes))
1334 ;; (when (and (memq 'hanyu-dazidian-page attributes)
1335 ;; (setq value (get-char-attribute char 'hanyu-dazidian-page)))
1336 ;; (insert (format "(hanyu-dazidian-page . %d)%s"
1337 ;; value line-breaking))
1338 ;; (setq attributes (delq 'hanyu-dazidian-page attributes))
1340 ;; (when (and (memq 'hanyu-dazidian-char attributes)
1341 ;; (setq value (get-char-attribute char 'hanyu-dazidian-char)))
1342 ;; (insert (format "(hanyu-dazidian-char . %d)%s"
1343 ;; value line-breaking))
1344 ;; (setq attributes (delq 'hanyu-dazidian-char attributes))
1347 (dolist (ignored '(composition
1348 ->denotational <-subsumptive ->ucs-unified
1349 ->ideographic-component-forms))
1350 (setq attributes (delq ignored attributes))))
1352 (setq name (car attributes))
1353 (unless (eq (setq value (get-char-attribute char name 'value-is-empty))
1355 (cond ((setq ret (find-charset name))
1356 (setq name (charset-name ret))
1357 (when (not (memq name dest-ccss))
1358 (setq dest-ccss (cons name dest-ccss))
1359 (char-db-insert-ccs-feature name value line-breaking))
1361 ((string-match "^=>ucs@" (symbol-name name))
1362 (insert (format "(%-18s . #x%04X)\t; %c%s"
1363 name value (decode-char '=ucs value)
1366 ((eq name 'jisx0208-1978/4X)
1367 (insert (format "(%-18s . #x%04X)%s"
1373 (not (eq name '->subsumptive))
1374 (not (eq name '->uppercase))
1375 (not (eq name '->lowercase))
1376 (not (eq name '->titlecase))
1377 (not (eq name '->canonical))
1378 (not (eq name '->Bopomofo))
1379 (not (eq name '->mistakable))
1380 (not (eq name '->ideographic-variants))
1381 (null (get-char-attribute
1382 char (intern (format "%s*sources" name))))
1383 (not (string-match "\\*sources$" (symbol-name name)))
1384 (null (get-char-attribute
1385 char (intern (format "%s*note" name))))
1386 (not (string-match "\\*note$" (symbol-name name)))
1387 (or (eq name '<-identical)
1388 (eq name '<-uppercase)
1389 (eq name '<-lowercase)
1390 (eq name '<-titlecase)
1391 (eq name '<-canonical)
1392 (eq name '<-ideographic-variants)
1393 ;; (eq name '<-synonyms)
1394 (string-match "^<-synonyms" (symbol-name name))
1395 (eq name '<-mistakable)
1396 (when (string-match "^->" (symbol-name name))
1398 ((string-match "^->fullwidth" (symbol-name name))
1399 (not (and (consp value)
1400 (characterp (car value))
1402 (car value) '=ucs 'defined-only)))
1407 ((or (eq name 'ideographic-structure)
1408 (eq name 'ideographic-combination)
1409 ;; (eq name 'ideographic-)
1410 (eq name '=decomposition)
1411 (char-feature-base-name= '=decomposition name)
1412 (char-feature-base-name= '=>decomposition name)
1413 ;; (string-match "^=>*decomposition\\(@[^*]+\\)?$"
1414 ;; (symbol-name name))
1415 (string-match "^\\(->\\|<-\\)[^*]*$" (symbol-name name))
1416 (string-match "^\\(->\\|<-\\)[^*]*\\*sources$"
1419 (char-db-insert-relation-feature char name value
1422 ;; ((memq name '(ideograph=
1423 ;; original-ideograph-of
1424 ;; ancient-ideograph-of
1425 ;; vulgar-ideograph-of
1426 ;; wrong-ideograph-of
1427 ;; ;; simplified-ideograph-of
1428 ;; ideographic-variants
1429 ;; ;; ideographic-different-form-of
1431 ;; (insert (format "(%-18s%s " name line-breaking))
1432 ;; (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1434 ;; (while (consp value)
1435 ;; (setq cell (car value))
1436 ;; (if (and (consp cell)
1437 ;; (consp (car cell)))
1441 ;; (char-db-insert-alist cell readable)
1442 ;; (setq separator lbs))
1444 ;; (insert separator))
1445 ;; (insert (prin1-to-string cell))
1446 ;; (setq separator " "))
1447 ;; (setq value (cdr value)))
1449 ;; (insert line-breaking))
1451 (insert (format "(%-18s " name))
1452 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1454 (while (consp value)
1455 (setq cell (car value))
1456 (if (and (consp cell)
1458 (setq ret (condition-case nil
1466 (setq key (car (car rest)))
1467 (if (find-charset key)
1468 (setq cal (cons key cal))
1469 (setq al (cons key al)))
1470 (setq rest (cdr rest)))
1473 (insert-char-attributes ret
1477 (setq separator lbs))
1478 (setq ret (prin1-to-string cell))
1480 (if (< (+ (current-column)
1487 (setq separator " "))
1488 (setq value (cdr value)))
1490 (insert line-breaking))
1492 (insert (format "(%-18s" name))
1493 (setq ret (prin1-to-string value))
1494 (unless (< (+ (current-column)
1498 (insert line-breaking))
1499 (insert " . " ret ")" line-breaking)
1500 ;; (insert (format "(%-18s . %S)%s"
1505 (setq attributes (cdr attributes)))
1508 (defun insert-char-data (char &optional readable
1511 (narrow-to-region (point)(point))
1512 (insert "(define-char
1514 (insert-char-attributes char readable attributes)
1516 (goto-char (point-min))
1517 (while (re-search-forward "[ \t]+$" nil t)
1520 (goto-char (point-min))
1521 (while (re-search-forward "[ \t][ \t][ \t]*" nil t)
1522 (let ((column (current-column))
1523 (indent-tabs-mode t))
1524 (delete-region (match-beginning 0) (point))
1525 (indent-to column)))
1526 (goto-char (point-max))
1527 ;; (tabify (point-min)(point-max))
1530 (defun insert-char-data-with-variant (char &optional printable
1532 script excluded-script)
1533 (insert-char-data char printable)
1534 (let ((variants (char-variants char))
1537 (setq variants (sort variants #'<))
1538 (setq rest variants)
1539 (setq variants (cons char variants))
1541 (setq variant (car rest))
1542 (unless (get-char-attribute variant '<-subsumptive)
1543 (if (and (or (null script)
1544 (null (setq vs (get-char-attribute variant 'script)))
1546 (or (null excluded-script)
1547 (null (setq vs (get-char-attribute variant 'script)))
1548 (not (memq excluded-script vs))))
1549 (unless (and no-ucs-unified (get-char-attribute variant '=ucs))
1550 (insert-char-data variant printable)
1551 (if (setq ret (char-variants variant))
1553 (or (memq (car ret) variants)
1554 ;; (get-char-attribute (car ret) '<-subsumptive)
1555 (setq rest (nconc rest (list (car ret)))))
1556 (setq ret (cdr ret)))))))
1557 (setq rest (cdr rest)))))
1559 (defun insert-char-range-data (min max &optional script excluded-script)
1562 (while (<= code max)
1563 (setq char (decode-char '=ucs code))
1564 (if (encode-char char '=ucs 'defined-only)
1565 (insert-char-data-with-variant char nil 'no-ucs-unified
1566 script excluded-script))
1567 (setq code (1+ code)))))
1569 (defun write-char-range-data-to-file (min max file
1570 &optional script excluded-script)
1571 (let ((coding-system-for-write char-db-file-coding-system))
1573 (insert (format ";; -*- coding: %s -*-\n"
1574 char-db-file-coding-system))
1575 (insert-char-range-data min max script excluded-script)
1576 (write-region (point-min)(point-max) file))))
1578 (defvar what-character-original-window-configuration)
1581 (defun what-char-definition (char)
1582 (interactive (list (char-after)))
1583 (let ((buf (get-buffer-create "*Character Description*"))
1584 (the-buf (current-buffer))
1585 (win-conf (current-window-configuration)))
1587 (make-local-variable 'what-character-original-window-configuration)
1588 (setq what-character-original-window-configuration win-conf)
1589 (setq buffer-read-only nil)
1593 (insert-char-data-with-variant char 'printable)
1594 (unless (char-attribute-alist char)
1595 (insert (format ";; = %c\n"
1596 (let* ((rest (split-char char))
1600 (setq code (logior (lsh code 8)
1602 (decode-char ccs code)))))
1603 ;; (char-db-update-comment)
1604 (set-buffer-modified-p nil)
1605 (view-mode the-buf (lambda (buf)
1606 (set-window-configuration
1607 what-character-original-window-configuration)
1609 (goto-char (point-min)))
1611 (set-window-configuration
1612 what-character-original-window-configuration)
1613 (signal (car err) (cdr err)))))))
1619 (provide 'char-db-util)
1621 ;;; char-db-util.el ends here