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 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
109 (defun shuowen-radical (number)
110 (aref shuowen-radicals (1- number)))
112 (defvar char-db-file-coding-system 'utf-8-mcs-er)
114 (defvar char-db-ignored-attributes '(ideographic-products))
116 (defvar char-db-coded-charset-priority-list
210 ;; =>>>adobe-japan1-0
211 ;; =>>>adobe-japan1-1
212 ;; =>>>adobe-japan1-2
213 ;; =>>>adobe-japan1-3
214 ;; =>>>adobe-japan1-4
215 ;; =>>>adobe-japan1-5
216 ;; =>>>adobe-japan1-6
220 ;; =>>>hanyo-denshi/ja
221 ;; =>>>hanyo-denshi/jb
222 ;; =>>>hanyo-denshi/jc
223 ;; =>>>hanyo-denshi/ft
224 ;; =>>>hanyo-denshi/ib
225 ;; =>>>hanyo-denshi/hg
226 ;; =>>>hanyo-denshi/jt
227 ;; =>>>hanyo-denshi/ks
331 ;;; @ char-db formatters
334 (defun char-db-make-char-spec (char)
336 (cond ((characterp char)
337 (cond ((and (setq ret (encode-char char '=ucs 'defined-only))
338 (not (and (<= #xE000 ret)(<= ret #xF8FF))))
339 (setq char-spec (list (cons '=ucs ret)))
340 (cond ((setq ret (get-char-attribute char 'name))
341 (setq char-spec (cons (cons 'name ret) char-spec))
343 ((setq ret (get-char-attribute char 'name*))
344 (setq char-spec (cons (cons 'name* ret) char-spec))
347 ((encode-char char '=mj 'defined-only)
349 (dolist (ccs (charset-list))
350 (if (and (or (eq ccs '=mj)
351 ;; (eq (charset-property ccs 'iso-ir) 177)
352 (string-match "=ucs@" (symbol-name ccs))
354 (setq ccs (charset-name ccs))
355 (null (assq ccs char-spec))
356 (setq ret (encode-char char ccs 'defined-only)))
357 (setq char-spec (cons (cons ccs ret) char-spec))))
359 ((encode-char char '==mj 'defined-only)
361 (dolist (ccs (charset-list))
362 (if (and (or (eq ccs '==mj)
363 ;; (eq (charset-property ccs 'iso-ir) 177)
364 (string-match "=ucs@" (symbol-name ccs))
366 (setq ccs (charset-name ccs))
367 (null (assq ccs char-spec))
368 (setq ret (encode-char char ccs 'defined-only)))
369 (setq char-spec (cons (cons ccs ret) char-spec))))
371 ((encode-char char '=adobe-japan1 'defined-only)
373 (dolist (ccs (charset-list))
374 (if (and (or (memq ccs
383 ;; (eq (charset-property ccs 'iso-ir) 177)
384 (string-match "=ucs@" (symbol-name ccs))
386 (setq ccs (charset-name ccs))
387 (null (assq ccs char-spec))
388 (setq ret (encode-char char ccs 'defined-only)))
389 (setq char-spec (cons (cons ccs ret) char-spec))))
391 ((encode-char char '==adobe-japan1 'defined-only)
393 (dolist (ccs (charset-list))
394 (if (and (or (memq ccs
403 ;; (eq (charset-property ccs 'iso-ir) 177)
404 (string-match "=ucs@" (symbol-name ccs))
406 (setq ccs (charset-name ccs))
407 (null (assq ccs char-spec))
408 (setq ret (encode-char char ccs 'defined-only)))
409 (setq char-spec (cons (cons ccs ret) char-spec))))
413 (let ((rest char-db-coded-charset-priority-list)
416 (setq ccs (charset-name
417 (find-charset (car rest))))
419 (encode-char char ccs
421 (throw 'tag (cons ccs ret)))
422 (setq rest (cdr rest))))))
423 (setq char-spec (list ret))
424 (dolist (ccs (delq (car ret) (charset-list)))
425 (if (and (or (charset-iso-final-char ccs)
432 (eq (charset-property ccs 'iso-ir) 177)
433 ;; (string-match "=ucs@" (symbol-name ccs))
435 (setq ccs (charset-name ccs))
436 (null (assq ccs char-spec))
437 (setq ret (encode-char char ccs 'defined-only)))
438 (setq char-spec (cons (cons ccs ret) char-spec))))
440 (setq char-spec (split-char char)))
441 (cond ((setq ret (get-char-attribute char 'name))
442 (setq char-spec (cons (cons 'name ret) char-spec))
444 ((setq ret (get-char-attribute char 'name*))
445 (setq char-spec (cons (cons 'name* ret) char-spec))
448 ((setq ret (get-char-attribute
449 char 'ideographic-combination))
451 (cons (cons 'ideographic-combination ret)
458 (defun char-db-insert-char-spec (char &optional readable column
461 (setq column (current-column)))
462 (let (char-spec temp-char)
463 (setq char-spec (char-db-make-char-spec char))
464 (unless (or (characterp char) ; char
466 (setq char (find-char char-spec))
468 ;; define temporary character
469 ;; Current implementation is dirty.
470 (setq temp-char (define-char (cons '(ideograph-daikanwa . 0)
472 (remove-char-attribute temp-char 'ideograph-daikanwa)
473 (setq char temp-char))
474 (insert-char-attributes char
476 (union (mapcar #'car char-spec)
480 ;; undefine temporary character
481 ;; Current implementation is dirty.
482 (setq char-spec (char-attribute-alist temp-char))
484 (remove-char-attribute temp-char (car (car char-spec)))
485 (setq char-spec (cdr char-spec))))))
487 (defun char-db-insert-alist (alist &optional readable column)
489 (setq column (current-column)))
491 (concat "\n" (make-string (1+ column) ?\ )))
495 lbs cell rest separator)
498 (setq name (car (car alist))
499 value (cdr (car alist)))
500 (cond ((eq name 'char)
502 (if (setq ret (condition-case nil
510 (setq key (car (car value)))
511 ;; (if (find-charset key)
512 ;; (setq cal (cons key cal))
513 (setq al (cons key al))
515 (setq value (cdr value)))
516 (insert-char-attributes ret
520 (insert (prin1-to-string value)))
522 (insert line-breaking))
524 (insert (format "(%-18s " name))
525 (setq lbs (concat "\n" (make-string (current-column) ?\ )))
527 (setq cell (car value))
528 (if (and (consp cell)
530 (setq ret (condition-case nil
540 (setq key (car (car rest)))
541 ;; (if (find-charset key)
542 ;; (setq cal (cons key cal))
543 (setq al (cons key al))
545 (setq rest (cdr rest)))
548 (insert-char-attributes ret
552 (setq separator lbs))
555 (insert (prin1-to-string cell))
556 (setq separator " "))
557 (setq value (cdr value)))
559 (insert line-breaking))
561 (insert (format "(%-18s . %S)%s"
564 (setq alist (cdr alist))))
567 (defun char-db-insert-char-reference (plist &optional readable column)
569 (setq column (current-column)))
571 (concat "\n" (make-string (1+ column) ?\ )))
576 (setq name (pop plist))
577 (setq value (pop plist))
578 (cond ((eq name :char)
581 (cond ((numberp value)
582 (setq value (decode-char '=ucs value)))
584 ;; (setq value (or (find-char value)
587 (char-db-insert-char-spec value readable)
588 (insert line-breaking)
591 (insert (format "%s%s\t%d ; %c%s"
594 (ideographic-radical value)
598 (insert (format "%s%s\t%S" separator name value))
599 (setq separator line-breaking)))
603 (defun char-db-decode-isolated-char (ccs code-point)
606 (cond ((eq ccs 'arabic-iso8859-6)
607 (decode-char ccs code-point))
609 ;; (decode-builtin-char '==gt code-point))
610 ((and (memq ccs '(=gt-pj-1
621 (setq ret (decode-char ccs code-point))
622 (setq ret (encode-char ret '=gt 'defined-only)))
623 (decode-builtin-char '=gt ret))
625 (decode-builtin-char ccs code-point))))
627 (or (decode-char ccs code-point)
628 (define-char (list (cons ccs code-point)))))
629 ((and (<= 0 (char-int ret))
630 (<= (char-int ret) #x1F))
631 (decode-char '=ucs (+ #x2400 (char-int ret))))
632 ((= (char-int ret) #x7F)
636 (defvar char-db-convert-obsolete-format t)
638 (defun char-db-insert-ccs-feature (name value line-breaking)
644 ((memq name '(=>iwds-1
647 =shinjigen@1ed ==shinjigen@1ed
648 =shinjigen@rev ==shinjigen@rev
649 =shinjigen/+p@rev ==shinjigen/+p@rev
650 ===daikanwa/ho ==daikanwa/ho
651 =daikanwa/ho =>>daikanwa/ho =>daikanwa/ho))
652 "(%-18s . %04d)\t; %c")
653 ((eq name '=shinjigen@1ed/24pr)
654 "(%-18s . %04d)\t; %c")
655 ((or (memq name '(===daikanwa
656 ==daikanwa =daikanwa =>>daikanwa =>daikanwa
657 =daikanwa@rev1 =daikanwa@rev2
658 =daikanwa/+p ==daikanwa/+p ===daikanwa/+p
660 =daikanwa/+2p =>>daikanwa/+2p
665 =adobe-japan1-0 ==adobe-japan1-0 ===adobe-japan1-0
666 =adobe-japan1-1 ==adobe-japan1-1 ===adobe-japan1-1
667 =adobe-japan1-2 ==adobe-japan1-2 ===adobe-japan1-2
668 =adobe-japan1-3 ==adobe-japan1-3 ===adobe-japan1-3
669 =adobe-japan1-4 ==adobe-japan1-4 ===adobe-japan1-4
670 =adobe-japan1-5 ==adobe-japan1-5 ===adobe-japan1-5
671 =adobe-japan1-6 ==adobe-japan1-6 ===adobe-japan1-6
672 =>>adobe-japan1-0 =+>adobe-japan1-0
673 =>>adobe-japan1-1 =+>adobe-japan1-1
674 =>>adobe-japan1-2 =+>adobe-japan1-2
675 =>>adobe-japan1-3 =+>adobe-japan1-3
676 =>>adobe-japan1-4 =+>adobe-japan1-4
677 =>>adobe-japan1-5 =+>adobe-japan1-5
678 =>>adobe-japan1-6 =+>adobe-japan1-6
679 =>cbeta =cbeta =>>cbeta ==cbeta ===cbeta
680 =zinbun-oracle =>zinbun-oracle
681 ===hng-jou ===hng-keg
682 ===hng-khi ===hng-khm ===hng-kak
683 ===hng-sys ===hng-tsu
684 ===hng-hod ===hng-gok ===hng-k24
685 ===hng-kcj ===hng-kbk ===hng-sik
686 ===hng-skk ===hng-kyu ===hng-ksk ===hng-wan
687 ===hng-kss ===hng-kyo
689 ;; (string-match "^=adobe-" (symbol-name name))
691 "(%-18s . %05d)\t; %c")
692 ((memq name '(=hanyo-denshi/ks
693 ==hanyo-denshi/ks ===hanyo-denshi/ks
698 "(%-18s . %06d)\t; %c")
699 ((>= (charset-dimension name) 2)
700 "(%-18s . #x%04X)\t; %c")
702 "(%-18s . #x%02X)\t; %c"))
704 (if (= (charset-iso-graphic-plane name) 1)
706 (cond ((= (charset-dimension name) 1)
708 ((= (charset-dimension name) 2)
710 ((= (charset-dimension name) 3)
714 (char-db-decode-isolated-char name value)))
715 (if (and (= (charset-chars name) 94)
716 (= (charset-dimension name) 2))
717 (insert (format " [%02d-%02d]"
718 (- (lsh value -8) 32)
719 (- (logand value 255) 32))))
722 (insert (format "(%-18s . %s)" name value))
724 (insert line-breaking))
726 (defun char-db-insert-relation-feature (char name value line-breaking
728 (insert (format "(%-18s%s " name line-breaking))
729 (let ((lbs (concat "\n" (make-string (current-column) ?\ )))
730 separator cell sources required-features
733 (setq cell (car value))
735 (setq cell (decode-char '=ucs cell)))
737 ((eq name '->subsumptive)
738 (when (or (not (some (lambda (atr)
739 (get-char-attribute cell atr))
740 char-db-ignored-attributes))
742 (encode-char cell ccs 'defined-only))
746 (let ((char-db-ignored-attributes
748 char-db-ignored-attributes)))
749 (insert-char-attributes cell readable nil nil 'for-sub-node))
750 (setq separator lbs))
755 char (intern (format "%s*sources" name))))
756 (setq required-features nil)
757 (dolist (source sources)
761 shinjigen shinjigen@1ed shinjigen@rev))
762 (setq required-features
763 (union required-features
775 =shinjigen/+p@rev))))
777 (setq required-features
778 (union required-features
783 ((find-charset (setq ret (intern (format "=%s" source))))
784 (setq required-features
785 (cons ret required-features)))
786 (t (setq required-features
787 (cons source required-features)))))
788 (cond ((string-match "@JP" (symbol-name name))
789 (setq required-features
790 (union required-features
798 ((string-match "@CN" (symbol-name name))
799 (setq required-features
800 (union required-features
807 (insert (format "%S" cell))
808 (char-db-insert-char-spec cell readable
811 (setq separator lbs))
815 (if (consp (car cell))
816 (char-db-insert-char-spec cell readable)
817 (char-db-insert-char-reference cell readable))
818 (setq separator lbs))
822 (insert (prin1-to-string cell))
823 (setq separator " ")))
824 (setq value (cdr value)))
826 (insert line-breaking)))
828 (defun insert-char-attributes (char &optional readable attributes column
831 (setq column (current-column)))
832 (let (name value ; has-long-ccs-name
836 (concat "\n" (make-string (1+ column) ?\ )))
837 lbs cell separator ret
839 dest-ccss ; sources required-features
844 (if (consp attributes)
846 (dolist (name attributes)
847 (unless (memq name char-db-ignored-attributes)
848 (if (find-charset name)
852 (dolist (name (char-attribute-list))
853 (unless (memq name char-db-ignored-attributes)
854 (if (find-charset name)
858 #'char-attribute-name<)))
860 (when (memq '<-subsumptive attributes)
861 (when (or readable (not for-sub-node))
862 (when (setq value (get-char-attribute char '<-subsumptive))
863 (char-db-insert-relation-feature char '<-subsumptive value
866 (setq attributes (delq '<-subsumptive attributes)))
867 (when (and (memq '<-denotational attributes)
868 (setq value (get-char-attribute char '<-denotational)))
869 (char-db-insert-relation-feature char '<-denotational value
872 (setq attributes (delq '<-denotational attributes)))
873 (when (and (memq '<-denotational@component attributes)
874 (setq value (get-char-attribute char '<-denotational@component)))
875 (char-db-insert-relation-feature char '<-denotational@component value
878 (setq attributes (delq '<-denotational@component attributes)))
879 (when (and (memq 'name attributes)
880 (setq value (get-char-attribute char 'name)))
882 (if (> (+ (current-column) (length value)) 48)
885 value line-breaking))
886 (setq attributes (delq 'name attributes))
888 (when (and (memq 'name* attributes)
889 (setq value (get-char-attribute char 'name*)))
891 (if (> (+ (current-column) (length value)) 48)
894 value line-breaking))
895 (setq attributes (delq 'name* attributes))
897 (when (and (memq 'script attributes)
898 (setq value (get-char-attribute char 'script)))
899 (insert (format "(script\t\t%s)%s"
900 (mapconcat (function prin1-to-string)
903 (setq attributes (delq 'script attributes))
905 (dolist (name '(=>ucs =>ucs*))
906 (when (and (memq name attributes)
907 (setq value (get-char-attribute char name)))
908 (insert (format "(%-18s . #x%04X)\t; %c%s"
909 name value (decode-char '=ucs value)
911 (setq attributes (delq name attributes))))
912 (dolist (name '(=>ucs@gb =>ucs@big5))
913 (when (and (memq name attributes)
914 (setq value (get-char-attribute char name)))
915 (insert (format "(%-18s . #x%04X)\t; %c%s"
920 (symbol-name name) 2)))
923 (setq attributes (delq name attributes))
925 ;; (dolist (name '(=>daikanwa))
926 ;; (when (and (memq name attributes)
927 ;; (setq value (get-char-attribute char name)))
929 ;; (if (integerp value)
930 ;; (format "(%-18s . %05d)\t; %c%s"
931 ;; name value (decode-char '=daikanwa value)
933 ;; (format "(%-18s %s)\t; %c%s"
935 ;; (mapconcat (function prin1-to-string)
937 ;; (char-representative-of-daikanwa char)
939 ;; (setq attributes (delq name attributes))))
940 (when (and (memq 'general-category attributes)
941 (setq value (get-char-attribute char 'general-category)))
943 "(general-category\t%s) ; %s%s"
944 (mapconcat (lambda (cell)
947 (cond ((rassoc value unidata-normative-category-alist)
948 "Normative Category")
949 ((rassoc value unidata-informative-category-alist)
950 "Informative Category")
954 (setq attributes (delq 'general-category attributes))
956 (when (and (memq 'bidi-category attributes)
957 (setq value (get-char-attribute char 'bidi-category)))
958 (insert (format "(bidi-category\t. %S)%s"
961 (setq attributes (delq 'bidi-category attributes))
963 (unless (or (not (memq 'mirrored attributes))
964 (eq (setq value (get-char-attribute char 'mirrored 'empty))
966 (insert (format "(mirrored\t\t. %S)%s"
969 (setq attributes (delq 'mirrored attributes))
972 ((and (memq 'decimal-digit-value attributes)
973 (setq value (get-char-attribute char 'decimal-digit-value)))
974 (insert (format "(decimal-digit-value . %S)%s"
977 (setq attributes (delq 'decimal-digit-value attributes))
978 (when (and (memq 'digit-value attributes)
979 (setq value (get-char-attribute char 'digit-value)))
980 (insert (format "(digit-value\t . %S)%s"
983 (setq attributes (delq 'digit-value attributes))
985 (when (and (memq 'numeric-value attributes)
986 (setq value (get-char-attribute char 'numeric-value)))
987 (insert (format "(numeric-value\t . %S)%s"
990 (setq attributes (delq 'numeric-value attributes))
994 (when (and (memq 'digit-value attributes)
995 (setq value (get-char-attribute char 'digit-value)))
996 (insert (format "(digit-value\t. %S)%s"
999 (setq attributes (delq 'digit-value attributes))
1001 (when (and (memq 'numeric-value attributes)
1002 (setq value (get-char-attribute char 'numeric-value)))
1003 (insert (format "(numeric-value\t. %S)%s"
1006 (setq attributes (delq 'numeric-value attributes))
1008 (when (and (memq 'iso-10646-comment attributes)
1009 (setq value (get-char-attribute char 'iso-10646-comment)))
1010 (insert (format "(iso-10646-comment\t. %S)%s"
1013 (setq attributes (delq 'iso-10646-comment attributes))
1015 (when (and (memq 'morohashi-daikanwa attributes)
1016 (setq value (get-char-attribute char 'morohashi-daikanwa)))
1017 (insert (format "(morohashi-daikanwa\t%s)%s"
1018 (mapconcat (function prin1-to-string) value " ")
1020 (setq attributes (delq 'morohashi-daikanwa attributes))
1024 (when (and (memq 'ideographic-radical attributes)
1025 (setq value (get-char-attribute char 'ideographic-radical)))
1026 (setq radical value)
1027 (insert (format "(ideographic-radical . %S)\t; %c%s"
1029 (ideographic-radical radical)
1031 (setq attributes (delq 'ideographic-radical attributes))
1033 (when (and (memq 'shuowen-radical attributes)
1034 (setq value (get-char-attribute char 'shuowen-radical)))
1035 (insert (format "(shuowen-radical\t. %S)\t; %c%s"
1037 (shuowen-radical value)
1039 (setq attributes (delq 'shuowen-radical attributes))
1044 char-db-feature-domains
1046 (dolist (feature (char-attribute-list))
1047 (setq feature (symbol-name feature))
1049 "\\(radical\\|strokes\\)@\\([^@*]+\\)\\(\\*\\|$\\)"
1051 (setq domain (intern (match-string 2 feature)))
1052 (unless (memq domain dest)
1053 (setq dest (cons domain dest)))))
1054 (sort dest #'string<))))
1055 (setq key (intern (format "%s@%s" 'ideographic-radical domain)))
1056 (when (and (memq key attributes)
1057 (setq value (get-char-attribute char key)))
1058 (setq radical value)
1059 (insert (format "(%s . %S)\t; %c%s"
1062 (ideographic-radical radical)
1064 (setq attributes (delq key attributes))
1066 (setq key (intern (format "%s@%s" 'ideographic-strokes domain)))
1067 (when (and (memq key attributes)
1068 (setq value (get-char-attribute char key)))
1069 (setq strokes value)
1070 (insert (format "(%s . %S)%s"
1074 (setq attributes (delq key attributes))
1076 (setq key (intern (format "%s@%s" 'total-strokes domain)))
1077 (when (and (memq key attributes)
1078 (setq value (get-char-attribute char key)))
1079 (insert (format "(%s . %S)%s"
1083 (setq attributes (delq key attributes))
1085 (dolist (feature '(ideographic-radical
1088 (setq key (intern (format "%s@%s*sources" feature domain)))
1089 (when (and (memq key attributes)
1090 (setq value (get-char-attribute char key)))
1091 (insert (format "(%s%s" key line-breaking))
1092 (dolist (cell value)
1093 (insert (format " %s" cell)))
1095 (insert line-breaking)
1096 (setq attributes (delq key attributes))
1099 (when (and (memq 'ideographic-strokes attributes)
1100 (setq value (get-char-attribute char 'ideographic-strokes)))
1101 (setq strokes value)
1102 (insert (format "(ideographic-strokes . %S)%s"
1105 (setq attributes (delq 'ideographic-strokes attributes))
1107 (when (and (memq 'kangxi-radical attributes)
1108 (setq value (get-char-attribute char 'kangxi-radical)))
1109 (unless (eq value radical)
1110 (insert (format "(kangxi-radical\t . %S)\t; %c%s"
1112 (ideographic-radical value)
1115 (setq radical value)))
1116 (setq attributes (delq 'kangxi-radical attributes))
1118 (when (and (memq 'kangxi-strokes attributes)
1119 (setq value (get-char-attribute char 'kangxi-strokes)))
1120 (unless (eq value strokes)
1121 (insert (format "(kangxi-strokes\t . %S)%s"
1125 (setq strokes value)))
1126 (setq attributes (delq 'kangxi-strokes attributes))
1128 (when (and (memq 'japanese-radical attributes)
1129 (setq value (get-char-attribute char 'japanese-radical)))
1130 (unless (eq value radical)
1131 (insert (format "(japanese-radical\t . %S)\t; %c%s"
1133 (ideographic-radical value)
1136 (setq radical value)))
1137 (setq attributes (delq 'japanese-radical attributes))
1139 (when (and (memq 'japanese-strokes attributes)
1140 (setq value (get-char-attribute char 'japanese-strokes)))
1141 (unless (eq value strokes)
1142 (insert (format "(japanese-strokes\t . %S)%s"
1146 (setq strokes value)))
1147 (setq attributes (delq 'japanese-strokes attributes))
1149 (when (and (memq 'cns-radical attributes)
1150 (setq value (get-char-attribute char 'cns-radical)))
1151 (insert (format "(cns-radical\t . %S)\t; %c%s"
1153 (ideographic-radical value)
1155 (setq attributes (delq 'cns-radical attributes))
1157 (when (and (memq 'cns-strokes attributes)
1158 (setq value (get-char-attribute char 'cns-strokes)))
1159 (unless (eq value strokes)
1160 (insert (format "(cns-strokes\t . %S)%s"
1164 (setq strokes value)))
1165 (setq attributes (delq 'cns-strokes attributes))
1167 ;; (when (and (memq 'shinjigen-1-radical attributes)
1168 ;; (setq value (get-char-attribute char 'shinjigen-1-radical)))
1169 ;; (unless (eq value radical)
1170 ;; (insert (format "(shinjigen-1-radical . %S)\t; %c%s"
1172 ;; (ideographic-radical value)
1175 ;; (setq radical value)))
1176 ;; (setq attributes (delq 'shinjigen-1-radical attributes))
1178 (when (and (memq 'ideographic- attributes)
1179 (setq value (get-char-attribute char 'ideographic-)))
1180 (insert "(ideographic- ")
1181 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1183 (while (consp value)
1184 (setq cell (car value))
1186 (setq cell (decode-char '=ucs cell)))
1187 (cond ((characterp cell)
1191 (insert (format "%S" cell))
1192 (char-db-insert-char-spec cell readable))
1193 (setq separator lbs))
1197 (if (consp (car cell))
1198 (char-db-insert-char-spec cell readable)
1199 (char-db-insert-char-reference cell readable))
1200 (setq separator lbs))
1204 (insert (prin1-to-string cell))
1205 (setq separator " ")))
1206 (setq value (cdr value)))
1208 (insert line-breaking)
1209 (setq attributes (delq 'ideographic- attributes)))
1210 (when (and (memq 'total-strokes attributes)
1211 (setq value (get-char-attribute char 'total-strokes)))
1212 (insert (format "(total-strokes . %S)%s"
1215 (setq attributes (delq 'total-strokes attributes))
1217 (when (and (memq '->ideograph attributes)
1218 (setq value (get-char-attribute char '->ideograph)))
1219 (insert (format "(->ideograph\t%s)%s"
1220 (mapconcat (lambda (code)
1221 (cond ((symbolp code)
1224 (format "#x%04X" code))
1227 line-breaking code))))
1230 (setq attributes (delq '->ideograph attributes))
1232 ;; (when (and (memq '->decomposition attributes)
1233 ;; (setq value (get-char-attribute char '->decomposition)))
1234 ;; (insert (format "(->decomposition\t%s)%s"
1235 ;; (mapconcat (lambda (code)
1236 ;; (cond ((symbolp code)
1237 ;; (symbol-name code))
1238 ;; ((characterp code)
1240 ;; (format "%S" code)
1245 ;; (format "#x%04X" code))
1247 ;; (format "%s%S" line-breaking code))))
1250 ;; (setq attributes (delq '->decomposition attributes))
1252 (if (equal (get-char-attribute char '->titlecase)
1253 (get-char-attribute char '->uppercase))
1254 (setq attributes (delq '->titlecase attributes)))
1255 (when (and (memq '->mojikyo attributes)
1256 (setq value (get-char-attribute char '->mojikyo)))
1257 (insert (format "(->mojikyo\t\t. %06d)\t; %c%s"
1258 value (decode-char 'mojikyo value)
1260 (setq attributes (delq '->mojikyo attributes))
1262 (when (and (memq 'hanyu-dazidian-vol attributes)
1263 (setq value (get-char-attribute char 'hanyu-dazidian-vol)))
1264 (insert (format "(hanyu-dazidian-vol . %d)%s"
1265 value line-breaking))
1266 (setq attributes (delq 'hanyu-dazidian-vol attributes))
1268 (when (and (memq 'hanyu-dazidian-page attributes)
1269 (setq value (get-char-attribute char 'hanyu-dazidian-page)))
1270 (insert (format "(hanyu-dazidian-page . %d)%s"
1271 value line-breaking))
1272 (setq attributes (delq 'hanyu-dazidian-page attributes))
1274 (when (and (memq 'hanyu-dazidian-char attributes)
1275 (setq value (get-char-attribute char 'hanyu-dazidian-char)))
1276 (insert (format "(hanyu-dazidian-char . %d)%s"
1277 value line-breaking))
1278 (setq attributes (delq 'hanyu-dazidian-char attributes))
1281 (dolist (ignored '(composition
1282 ->denotational <-subsumptive ->ucs-unified
1283 ->ideographic-component-forms))
1284 (setq attributes (delq ignored attributes))))
1286 (setq name (car attributes))
1287 (unless (eq (setq value (get-char-attribute char name 'value-is-empty))
1289 (cond ((setq ret (find-charset name))
1290 (setq name (charset-name ret))
1291 (when (not (memq name dest-ccss))
1292 (setq dest-ccss (cons name dest-ccss))
1293 (char-db-insert-ccs-feature name value line-breaking))
1295 ((string-match "^=>ucs@" (symbol-name name))
1296 (insert (format "(%-18s . #x%04X)\t; %c%s"
1297 name value (decode-char '=ucs value)
1300 ((eq name 'jisx0208-1978/4X)
1301 (insert (format "(%-18s . #x%04X)%s"
1307 (not (eq name '->subsumptive))
1308 (not (eq name '->uppercase))
1309 (not (eq name '->lowercase))
1310 (not (eq name '->titlecase))
1311 (not (eq name '->canonical))
1312 (not (eq name '->Bopomofo))
1313 (not (eq name '->mistakable))
1314 (not (eq name '->ideographic-variants))
1315 (null (get-char-attribute
1316 char (intern (format "%s*sources" name))))
1317 (not (string-match "\\*sources$" (symbol-name name)))
1318 (null (get-char-attribute
1319 char (intern (format "%s*note" name))))
1320 (not (string-match "\\*note$" (symbol-name name)))
1321 (or (eq name '<-identical)
1322 (eq name '<-uppercase)
1323 (eq name '<-lowercase)
1324 (eq name '<-titlecase)
1325 (eq name '<-canonical)
1326 (eq name '<-ideographic-variants)
1327 ;; (eq name '<-synonyms)
1328 (string-match "^<-synonyms" (symbol-name name))
1329 (eq name '<-mistakable)
1330 (when (string-match "^->" (symbol-name name))
1332 ((string-match "^->fullwidth" (symbol-name name))
1333 (not (and (consp value)
1334 (characterp (car value))
1336 (car value) '=ucs 'defined-only)))
1341 ((or (eq name 'ideographic-structure)
1342 (eq name 'ideographic-combination)
1343 (eq name 'ideographic-)
1344 (eq name '=decomposition)
1345 (char-feature-base-name= '=decomposition name)
1346 (char-feature-base-name= '=>decomposition name)
1347 ;; (string-match "^=>*decomposition\\(@[^*]+\\)?$"
1348 ;; (symbol-name name))
1349 (string-match "^\\(->\\|<-\\)[^*]*$" (symbol-name name))
1350 (string-match "^\\(->\\|<-\\)[^*]*\\*sources$"
1353 (char-db-insert-relation-feature char name value
1356 ((memq name '(ideograph=
1357 original-ideograph-of
1358 ancient-ideograph-of
1361 ;; simplified-ideograph-of
1362 ideographic-variants
1363 ;; ideographic-different-form-of
1365 (insert (format "(%-18s%s " name line-breaking))
1366 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1368 (while (consp value)
1369 (setq cell (car value))
1370 (if (and (consp cell)
1375 (char-db-insert-alist cell readable)
1376 (setq separator lbs))
1379 (insert (prin1-to-string cell))
1380 (setq separator " "))
1381 (setq value (cdr value)))
1383 (insert line-breaking))
1385 (insert (format "(%-18s " name))
1386 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1388 (while (consp value)
1389 (setq cell (car value))
1390 (if (and (consp cell)
1392 (setq ret (condition-case nil
1400 (setq key (car (car rest)))
1401 (if (find-charset key)
1402 (setq cal (cons key cal))
1403 (setq al (cons key al)))
1404 (setq rest (cdr rest)))
1407 (insert-char-attributes ret
1411 (setq separator lbs))
1412 (setq ret (prin1-to-string cell))
1414 (if (< (+ (current-column)
1421 (setq separator " "))
1422 (setq value (cdr value)))
1424 (insert line-breaking))
1426 (insert (format "(%-18s" name))
1427 (setq ret (prin1-to-string value))
1428 (unless (< (+ (current-column)
1432 (insert line-breaking))
1433 (insert " . " ret ")" line-breaking)
1434 ;; (insert (format "(%-18s . %S)%s"
1439 (setq attributes (cdr attributes)))
1442 (defun insert-char-data (char &optional readable
1445 (narrow-to-region (point)(point))
1446 (insert "(define-char
1448 (insert-char-attributes char readable attributes)
1450 (goto-char (point-min))
1451 (while (re-search-forward "[ \t]+$" nil t)
1454 (goto-char (point-min))
1455 (while (re-search-forward "[ \t][ \t][ \t]*" nil t)
1456 (let ((column (current-column))
1457 (indent-tabs-mode t))
1458 (delete-region (match-beginning 0) (point))
1459 (indent-to column)))
1460 (goto-char (point-max))
1461 ;; (tabify (point-min)(point-max))
1464 (defun insert-char-data-with-variant (char &optional printable
1466 script excluded-script)
1467 (insert-char-data char printable)
1468 (let ((variants (char-variants char))
1471 (setq variants (sort variants #'<))
1472 (setq rest variants)
1473 (setq variants (cons char variants))
1475 (setq variant (car rest))
1476 (unless (get-char-attribute variant '<-subsumptive)
1477 (if (and (or (null script)
1478 (null (setq vs (get-char-attribute variant 'script)))
1480 (or (null excluded-script)
1481 (null (setq vs (get-char-attribute variant 'script)))
1482 (not (memq excluded-script vs))))
1483 (unless (and no-ucs-unified (get-char-attribute variant '=ucs))
1484 (insert-char-data variant printable)
1485 (if (setq ret (char-variants variant))
1487 (or (memq (car ret) variants)
1488 ;; (get-char-attribute (car ret) '<-subsumptive)
1489 (setq rest (nconc rest (list (car ret)))))
1490 (setq ret (cdr ret)))))))
1491 (setq rest (cdr rest)))))
1493 (defun insert-char-range-data (min max &optional script excluded-script)
1496 (while (<= code max)
1497 (setq char (decode-char '=ucs code))
1498 (if (encode-char char '=ucs 'defined-only)
1499 (insert-char-data-with-variant char nil 'no-ucs-unified
1500 script excluded-script))
1501 (setq code (1+ code)))))
1503 (defun write-char-range-data-to-file (min max file
1504 &optional script excluded-script)
1505 (let ((coding-system-for-write char-db-file-coding-system))
1507 (insert (format ";; -*- coding: %s -*-\n"
1508 char-db-file-coding-system))
1509 (insert-char-range-data min max script excluded-script)
1510 (write-region (point-min)(point-max) file))))
1512 (defvar what-character-original-window-configuration)
1515 (defun what-char-definition (char)
1516 (interactive (list (char-after)))
1517 (let ((buf (get-buffer-create "*Character Description*"))
1518 (the-buf (current-buffer))
1519 (win-conf (current-window-configuration)))
1521 (make-local-variable 'what-character-original-window-configuration)
1522 (setq what-character-original-window-configuration win-conf)
1523 (setq buffer-read-only nil)
1527 (insert-char-data-with-variant char 'printable)
1528 (unless (char-attribute-alist char)
1529 (insert (format ";; = %c\n"
1530 (let* ((rest (split-char char))
1534 (setq code (logior (lsh code 8)
1536 (decode-char ccs code)))))
1537 ;; (char-db-update-comment)
1538 (set-buffer-modified-p nil)
1539 (view-mode the-buf (lambda (buf)
1540 (set-window-configuration
1541 what-character-original-window-configuration)
1543 (goto-char (point-min)))
1545 (set-window-configuration
1546 what-character-original-window-configuration)
1547 (signal (car err) (cdr err)))))))
1553 (provide 'char-db-util)
1555 ;;; char-db-util.el ends here