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
332 ;;; @ char-db formatters
335 (defun char-db-make-char-spec (char)
337 (cond ((characterp char)
338 (cond ((and (setq ret (encode-char char '=ucs 'defined-only))
339 (not (and (<= #xE000 ret)(<= ret #xF8FF))))
340 (setq char-spec (list (cons '=ucs ret)))
341 (cond ((setq ret (get-char-attribute char 'name))
342 (setq char-spec (cons (cons 'name ret) char-spec))
344 ((setq ret (get-char-attribute char 'name*))
345 (setq char-spec (cons (cons 'name* ret) char-spec))
348 ((encode-char char '=mj 'defined-only)
350 (dolist (ccs (charset-list))
351 (if (and (or (eq ccs '=mj)
352 ;; (eq (charset-property ccs 'iso-ir) 177)
353 (string-match "=ucs@" (symbol-name ccs))
355 (setq ccs (charset-name ccs))
356 (null (assq ccs char-spec))
357 (setq ret (encode-char char ccs 'defined-only)))
358 (setq char-spec (cons (cons ccs ret) char-spec))))
360 ((encode-char char '==mj 'defined-only)
362 (dolist (ccs (charset-list))
363 (if (and (or (eq ccs '==mj)
364 ;; (eq (charset-property ccs 'iso-ir) 177)
365 (string-match "=ucs@" (symbol-name ccs))
367 (setq ccs (charset-name ccs))
368 (null (assq ccs char-spec))
369 (setq ret (encode-char char ccs 'defined-only)))
370 (setq char-spec (cons (cons ccs ret) char-spec))))
372 ((encode-char char '=adobe-japan1 'defined-only)
374 (dolist (ccs (charset-list))
375 (if (and (or (memq ccs
384 ;; (eq (charset-property ccs 'iso-ir) 177)
385 (string-match "=ucs@" (symbol-name ccs))
387 (setq ccs (charset-name ccs))
388 (null (assq ccs char-spec))
389 (setq ret (encode-char char ccs 'defined-only)))
390 (setq char-spec (cons (cons ccs ret) char-spec))))
392 ((encode-char char '==adobe-japan1 'defined-only)
394 (dolist (ccs (charset-list))
395 (if (and (or (memq ccs
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))))
414 (let ((rest char-db-coded-charset-priority-list)
417 (setq ccs (charset-name
418 (find-charset (car rest))))
420 (encode-char char ccs
422 (throw 'tag (cons ccs ret)))
423 (setq rest (cdr rest))))))
424 (setq char-spec (list ret))
425 (dolist (ccs (delq (car ret) (charset-list)))
426 (if (and (or (charset-iso-final-char ccs)
433 (eq (charset-property ccs 'iso-ir) 177)
434 ;; (string-match "=ucs@" (symbol-name ccs))
436 (setq ccs (charset-name ccs))
437 (null (assq ccs char-spec))
438 (setq ret (encode-char char ccs 'defined-only)))
439 (setq char-spec (cons (cons ccs ret) char-spec))))
441 (setq char-spec (split-char char)))
442 (cond ((setq ret (get-char-attribute char 'name))
443 (setq char-spec (cons (cons 'name ret) char-spec))
445 ((setq ret (get-char-attribute char 'name*))
446 (setq char-spec (cons (cons 'name* ret) char-spec))
449 ((setq ret (get-char-attribute
450 char 'ideographic-combination))
452 (cons (cons 'ideographic-combination ret)
459 (defun char-db-insert-char-spec (char &optional readable column
462 (setq column (current-column)))
463 (let (char-spec temp-char)
464 (setq char-spec (char-db-make-char-spec char))
465 (unless (or (characterp char) ; char
467 (setq char (find-char char-spec))
469 ;; define temporary character
470 ;; Current implementation is dirty.
471 (setq temp-char (define-char (cons '(ideograph-daikanwa . 0)
473 (remove-char-attribute temp-char 'ideograph-daikanwa)
474 (setq char temp-char))
475 (insert-char-attributes char
477 (union (mapcar #'car char-spec)
481 ;; undefine temporary character
482 ;; Current implementation is dirty.
483 (setq char-spec (char-attribute-alist temp-char))
485 (remove-char-attribute temp-char (car (car char-spec)))
486 (setq char-spec (cdr char-spec))))))
488 (defun char-db-insert-alist (alist &optional readable column)
490 (setq column (current-column)))
492 (concat "\n" (make-string (1+ column) ?\ )))
496 lbs cell rest separator)
499 (setq name (car (car alist))
500 value (cdr (car alist)))
501 (cond ((eq name 'char)
503 (if (setq ret (condition-case nil
511 (setq key (car (car value)))
512 ;; (if (find-charset key)
513 ;; (setq cal (cons key cal))
514 (setq al (cons key al))
516 (setq value (cdr value)))
517 (insert-char-attributes ret
521 (insert (prin1-to-string value)))
523 (insert line-breaking))
525 (insert (format "(%-18s " name))
526 (setq lbs (concat "\n" (make-string (current-column) ?\ )))
528 (setq cell (car value))
529 (if (and (consp cell)
531 (setq ret (condition-case nil
541 (setq key (car (car rest)))
542 ;; (if (find-charset key)
543 ;; (setq cal (cons key cal))
544 (setq al (cons key al))
546 (setq rest (cdr rest)))
549 (insert-char-attributes ret
553 (setq separator lbs))
556 (insert (prin1-to-string cell))
557 (setq separator " "))
558 (setq value (cdr value)))
560 (insert line-breaking))
562 (insert (format "(%-18s . %S)%s"
565 (setq alist (cdr alist))))
568 (defun char-db-insert-char-reference (plist &optional readable column)
570 (setq column (current-column)))
572 (concat "\n" (make-string (1+ column) ?\ )))
577 (setq name (pop plist))
578 (setq value (pop plist))
579 (cond ((eq name :char)
582 (cond ((numberp value)
583 (setq value (decode-char '=ucs value)))
585 ;; (setq value (or (find-char value)
588 (char-db-insert-char-spec value readable)
589 (insert line-breaking)
592 (insert (format "%s%s\t%d ; %c%s"
595 (ideographic-radical value)
599 (insert (format "%s%s\t%S" separator name value))
600 (setq separator line-breaking)))
604 (defun char-db-decode-isolated-char (ccs code-point)
607 (cond ((eq ccs 'arabic-iso8859-6)
608 (decode-char ccs code-point))
610 ;; (decode-builtin-char '==gt code-point))
611 ((and (memq ccs '(=gt-pj-1
622 (setq ret (decode-char ccs code-point))
623 (setq ret (encode-char ret '=gt 'defined-only)))
624 (decode-builtin-char '=gt ret))
626 (decode-builtin-char ccs code-point))))
628 (or (decode-char ccs code-point)
629 (define-char (list (cons ccs code-point)))))
630 ((and (<= 0 (char-int ret))
631 (<= (char-int ret) #x1F))
632 (decode-char '=ucs (+ #x2400 (char-int ret))))
633 ((= (char-int ret) #x7F)
637 (defvar char-db-convert-obsolete-format t)
639 (defun char-db-insert-ccs-feature (name value line-breaking)
645 ((memq name '(=>iwds-1
648 =shinjigen@1ed ==shinjigen@1ed
649 =shinjigen@rev ==shinjigen@rev
650 =shinjigen/+p@rev ==shinjigen/+p@rev
651 ===daikanwa/ho ==daikanwa/ho
652 =daikanwa/ho =>>daikanwa/ho =>daikanwa/ho))
653 "(%-18s . %04d)\t; %c")
654 ((eq name '=shinjigen@1ed/24pr)
655 "(%-18s . %04d)\t; %c")
656 ((or (memq name '(===daikanwa
657 ==daikanwa =daikanwa =>>daikanwa =>daikanwa
658 =daikanwa@rev1 =daikanwa@rev2
659 =daikanwa/+p ==daikanwa/+p ===daikanwa/+p
661 =daikanwa/+2p =>>daikanwa/+2p
666 =adobe-japan1-0 ==adobe-japan1-0 ===adobe-japan1-0
667 =adobe-japan1-1 ==adobe-japan1-1 ===adobe-japan1-1
668 =adobe-japan1-2 ==adobe-japan1-2 ===adobe-japan1-2
669 =adobe-japan1-3 ==adobe-japan1-3 ===adobe-japan1-3
670 =adobe-japan1-4 ==adobe-japan1-4 ===adobe-japan1-4
671 =adobe-japan1-5 ==adobe-japan1-5 ===adobe-japan1-5
672 =adobe-japan1-6 ==adobe-japan1-6 ===adobe-japan1-6
673 =>>adobe-japan1-0 =+>adobe-japan1-0
674 =>>adobe-japan1-1 =+>adobe-japan1-1
675 =>>adobe-japan1-2 =+>adobe-japan1-2
676 =>>adobe-japan1-3 =+>adobe-japan1-3
677 =>>adobe-japan1-4 =+>adobe-japan1-4
678 =>>adobe-japan1-5 =+>adobe-japan1-5
679 =>>adobe-japan1-6 =+>adobe-japan1-6
680 =>cbeta =cbeta =>>cbeta ==cbeta ===cbeta
681 =zinbun-oracle =>zinbun-oracle
682 ===hng-jou ===hng-keg ===hng-dng ===hng-mam
683 ===hng-drt ===hng-kgk ===hng-myz ===hng-kda
684 ===hng-khi ===hng-khm ===hng-sok
685 ===hng-yhk ===hng-kak
686 ===hng-sys ===hng-tsu
687 ===hng-hod ===hng-gok ===hng-nto
688 ===hng-nkm ===hng-k24
689 ===hng-kcj ===hng-kbk ===hng-sik
690 ===hng-skk ===hng-kyu ===hng-ksk ===hng-wan
692 ===hng-kss ===hng-kyo
694 ;; (string-match "^=adobe-" (symbol-name name))
696 "(%-18s . %05d)\t; %c")
697 ((memq name '(=hanyo-denshi/ks
698 ==hanyo-denshi/ks ===hanyo-denshi/ks
703 "(%-18s . %06d)\t; %c")
704 ((>= (charset-dimension name) 2)
705 "(%-18s . #x%04X)\t; %c")
707 "(%-18s . #x%02X)\t; %c"))
709 (if (= (charset-iso-graphic-plane name) 1)
711 (cond ((= (charset-dimension name) 1)
713 ((= (charset-dimension name) 2)
715 ((= (charset-dimension name) 3)
719 (char-db-decode-isolated-char name value)))
720 (if (and (= (charset-chars name) 94)
721 (= (charset-dimension name) 2))
722 (insert (format " [%02d-%02d]"
723 (- (lsh value -8) 32)
724 (- (logand value 255) 32))))
727 (insert (format "(%-18s . %s)" name value))
729 (insert line-breaking))
731 (defun char-db-insert-relation-feature (char name value line-breaking
733 (insert (format "(%-18s%s " name line-breaking))
734 (let ((lbs (concat "\n" (make-string (current-column) ?\ )))
735 separator cell sources required-features
738 (setq cell (car value))
740 (setq cell (decode-char '=ucs cell)))
742 ((eq name '->subsumptive)
743 (when (or (not (some (lambda (atr)
744 (get-char-attribute cell atr))
745 char-db-ignored-attributes))
747 (encode-char cell ccs 'defined-only))
751 (let ((char-db-ignored-attributes
753 char-db-ignored-attributes)))
754 (insert-char-attributes cell readable nil nil 'for-sub-node))
755 (setq separator lbs))
760 char (intern (format "%s*sources" name))))
761 (setq required-features nil)
762 (dolist (source sources)
766 shinjigen shinjigen@1ed shinjigen@rev))
767 (setq required-features
768 (union required-features
780 =shinjigen/+p@rev))))
782 (setq required-features
783 (union required-features
788 ((find-charset (setq ret (intern (format "=%s" source))))
789 (setq required-features
790 (cons ret required-features)))
791 (t (setq required-features
792 (cons source required-features)))))
793 (cond ((string-match "@JP" (symbol-name name))
794 (setq required-features
795 (union required-features
803 ((string-match "@CN" (symbol-name name))
804 (setq required-features
805 (union required-features
812 (insert (format "%S" cell))
813 (char-db-insert-char-spec cell readable
816 (setq separator lbs))
820 (if (consp (car cell))
821 (char-db-insert-char-spec cell readable)
822 (char-db-insert-char-reference cell readable))
823 (setq separator lbs))
827 (insert (prin1-to-string cell))
828 (setq separator " ")))
829 (setq value (cdr value)))
831 (insert line-breaking)))
833 (defun insert-char-attributes (char &optional readable attributes column
836 (setq column (current-column)))
837 (let (name value ; has-long-ccs-name
841 (concat "\n" (make-string (1+ column) ?\ )))
842 lbs cell separator ret
844 dest-ccss ; sources required-features
849 (if (consp attributes)
851 (dolist (name attributes)
852 (unless (memq name char-db-ignored-attributes)
853 (if (find-charset name)
857 (dolist (name (char-attribute-list))
858 (unless (memq name char-db-ignored-attributes)
859 (if (find-charset name)
863 #'char-attribute-name<)))
865 (when (memq '<-subsumptive attributes)
866 (when (or readable (not for-sub-node))
867 (when (setq value (get-char-attribute char '<-subsumptive))
868 (char-db-insert-relation-feature char '<-subsumptive value
871 (setq attributes (delq '<-subsumptive attributes)))
872 (when (and (memq '<-denotational attributes)
873 (setq value (get-char-attribute char '<-denotational)))
874 (char-db-insert-relation-feature char '<-denotational value
877 (setq attributes (delq '<-denotational attributes)))
878 (when (and (memq '<-denotational@component attributes)
879 (setq value (get-char-attribute char '<-denotational@component)))
880 (char-db-insert-relation-feature char '<-denotational@component value
883 (setq attributes (delq '<-denotational@component attributes)))
884 (when (and (memq 'name attributes)
885 (setq value (get-char-attribute char 'name)))
887 (if (> (+ (current-column) (length value)) 48)
890 value line-breaking))
891 (setq attributes (delq 'name attributes))
893 (when (and (memq 'name* attributes)
894 (setq value (get-char-attribute char 'name*)))
896 (if (> (+ (current-column) (length value)) 48)
899 value line-breaking))
900 (setq attributes (delq 'name* attributes))
902 (when (and (memq 'script attributes)
903 (setq value (get-char-attribute char 'script)))
904 (insert (format "(script\t\t%s)%s"
905 (mapconcat (function prin1-to-string)
908 (setq attributes (delq 'script attributes))
910 (dolist (name '(=>ucs =>ucs*))
911 (when (and (memq name attributes)
912 (setq value (get-char-attribute char name)))
913 (insert (format "(%-18s . #x%04X)\t; %c%s"
914 name value (decode-char '=ucs value)
916 (setq attributes (delq name attributes))))
917 (dolist (name '(=>ucs@gb =>ucs@big5))
918 (when (and (memq name attributes)
919 (setq value (get-char-attribute char name)))
920 (insert (format "(%-18s . #x%04X)\t; %c%s"
925 (symbol-name name) 2)))
928 (setq attributes (delq name attributes))
930 ;; (dolist (name '(=>daikanwa))
931 ;; (when (and (memq name attributes)
932 ;; (setq value (get-char-attribute char name)))
934 ;; (if (integerp value)
935 ;; (format "(%-18s . %05d)\t; %c%s"
936 ;; name value (decode-char '=daikanwa value)
938 ;; (format "(%-18s %s)\t; %c%s"
940 ;; (mapconcat (function prin1-to-string)
942 ;; (char-representative-of-daikanwa char)
944 ;; (setq attributes (delq name attributes))))
945 (when (and (memq 'general-category attributes)
946 (setq value (get-char-attribute char 'general-category)))
948 "(general-category\t%s) ; %s%s"
949 (mapconcat (lambda (cell)
952 (cond ((rassoc value unidata-normative-category-alist)
953 "Normative Category")
954 ((rassoc value unidata-informative-category-alist)
955 "Informative Category")
959 (setq attributes (delq 'general-category attributes))
961 (when (and (memq 'bidi-category attributes)
962 (setq value (get-char-attribute char 'bidi-category)))
963 (insert (format "(bidi-category\t. %S)%s"
966 (setq attributes (delq 'bidi-category attributes))
968 (unless (or (not (memq 'mirrored attributes))
969 (eq (setq value (get-char-attribute char 'mirrored 'empty))
971 (insert (format "(mirrored\t\t. %S)%s"
974 (setq attributes (delq 'mirrored attributes))
977 ((and (memq 'decimal-digit-value attributes)
978 (setq value (get-char-attribute char 'decimal-digit-value)))
979 (insert (format "(decimal-digit-value . %S)%s"
982 (setq attributes (delq 'decimal-digit-value attributes))
983 (when (and (memq 'digit-value attributes)
984 (setq value (get-char-attribute char 'digit-value)))
985 (insert (format "(digit-value\t . %S)%s"
988 (setq attributes (delq 'digit-value attributes))
990 (when (and (memq 'numeric-value attributes)
991 (setq value (get-char-attribute char 'numeric-value)))
992 (insert (format "(numeric-value\t . %S)%s"
995 (setq attributes (delq 'numeric-value attributes))
999 (when (and (memq 'digit-value attributes)
1000 (setq value (get-char-attribute char 'digit-value)))
1001 (insert (format "(digit-value\t. %S)%s"
1004 (setq attributes (delq 'digit-value attributes))
1006 (when (and (memq 'numeric-value attributes)
1007 (setq value (get-char-attribute char 'numeric-value)))
1008 (insert (format "(numeric-value\t. %S)%s"
1011 (setq attributes (delq 'numeric-value attributes))
1013 (when (and (memq 'iso-10646-comment attributes)
1014 (setq value (get-char-attribute char 'iso-10646-comment)))
1015 (insert (format "(iso-10646-comment\t. %S)%s"
1018 (setq attributes (delq 'iso-10646-comment attributes))
1020 (when (and (memq 'morohashi-daikanwa attributes)
1021 (setq value (get-char-attribute char 'morohashi-daikanwa)))
1022 (insert (format "(morohashi-daikanwa\t%s)%s"
1023 (mapconcat (function prin1-to-string) value " ")
1025 (setq attributes (delq 'morohashi-daikanwa attributes))
1029 (when (and (memq 'ideographic-radical attributes)
1030 (setq value (get-char-attribute char 'ideographic-radical)))
1031 (setq radical value)
1032 (insert (format "(ideographic-radical . %S)\t; %c%s"
1034 (ideographic-radical radical)
1036 (setq attributes (delq 'ideographic-radical attributes))
1038 (when (and (memq 'shuowen-radical attributes)
1039 (setq value (get-char-attribute char 'shuowen-radical)))
1040 (insert (format "(shuowen-radical\t. %S)\t; %c%s"
1042 (shuowen-radical value)
1044 (setq attributes (delq 'shuowen-radical attributes))
1049 char-db-feature-domains
1051 (dolist (feature (char-attribute-list))
1052 (setq feature (symbol-name feature))
1054 "\\(radical\\|strokes\\)@\\([^@*]+\\)\\(\\*\\|$\\)"
1056 (setq domain (intern (match-string 2 feature)))
1057 (unless (memq domain dest)
1058 (setq dest (cons domain dest)))))
1059 (sort dest #'string<))))
1060 (setq key (intern (format "%s@%s" 'ideographic-radical domain)))
1061 (when (and (memq key attributes)
1062 (setq value (get-char-attribute char key)))
1063 (setq radical value)
1064 (insert (format "(%s . %S)\t; %c%s"
1067 (ideographic-radical radical)
1069 (setq attributes (delq key attributes))
1071 (setq key (intern (format "%s@%s" 'ideographic-strokes domain)))
1072 (when (and (memq key attributes)
1073 (setq value (get-char-attribute char key)))
1074 (setq strokes value)
1075 (insert (format "(%s . %S)%s"
1079 (setq attributes (delq key attributes))
1081 (setq key (intern (format "%s@%s" 'total-strokes domain)))
1082 (when (and (memq key attributes)
1083 (setq value (get-char-attribute char key)))
1084 (insert (format "(%s . %S)%s"
1088 (setq attributes (delq key attributes))
1090 (dolist (feature '(ideographic-radical
1093 (setq key (intern (format "%s@%s*sources" feature domain)))
1094 (when (and (memq key attributes)
1095 (setq value (get-char-attribute char key)))
1096 (insert (format "(%s%s" key line-breaking))
1097 (dolist (cell value)
1098 (insert (format " %s" cell)))
1100 (insert line-breaking)
1101 (setq attributes (delq key attributes))
1104 (when (and (memq 'ideographic-strokes attributes)
1105 (setq value (get-char-attribute char 'ideographic-strokes)))
1106 (setq strokes value)
1107 (insert (format "(ideographic-strokes . %S)%s"
1110 (setq attributes (delq 'ideographic-strokes attributes))
1112 (when (and (memq 'kangxi-radical attributes)
1113 (setq value (get-char-attribute char 'kangxi-radical)))
1114 (unless (eq value radical)
1115 (insert (format "(kangxi-radical\t . %S)\t; %c%s"
1117 (ideographic-radical value)
1120 (setq radical value)))
1121 (setq attributes (delq 'kangxi-radical attributes))
1123 (when (and (memq 'kangxi-strokes attributes)
1124 (setq value (get-char-attribute char 'kangxi-strokes)))
1125 (unless (eq value strokes)
1126 (insert (format "(kangxi-strokes\t . %S)%s"
1130 (setq strokes value)))
1131 (setq attributes (delq 'kangxi-strokes attributes))
1133 (when (and (memq 'japanese-radical attributes)
1134 (setq value (get-char-attribute char 'japanese-radical)))
1135 (unless (eq value radical)
1136 (insert (format "(japanese-radical\t . %S)\t; %c%s"
1138 (ideographic-radical value)
1141 (setq radical value)))
1142 (setq attributes (delq 'japanese-radical attributes))
1144 (when (and (memq 'japanese-strokes attributes)
1145 (setq value (get-char-attribute char 'japanese-strokes)))
1146 (unless (eq value strokes)
1147 (insert (format "(japanese-strokes\t . %S)%s"
1151 (setq strokes value)))
1152 (setq attributes (delq 'japanese-strokes attributes))
1154 (when (and (memq 'cns-radical attributes)
1155 (setq value (get-char-attribute char 'cns-radical)))
1156 (insert (format "(cns-radical\t . %S)\t; %c%s"
1158 (ideographic-radical value)
1160 (setq attributes (delq 'cns-radical attributes))
1162 (when (and (memq 'cns-strokes attributes)
1163 (setq value (get-char-attribute char 'cns-strokes)))
1164 (unless (eq value strokes)
1165 (insert (format "(cns-strokes\t . %S)%s"
1169 (setq strokes value)))
1170 (setq attributes (delq 'cns-strokes attributes))
1172 ;; (when (and (memq 'shinjigen-1-radical attributes)
1173 ;; (setq value (get-char-attribute char 'shinjigen-1-radical)))
1174 ;; (unless (eq value radical)
1175 ;; (insert (format "(shinjigen-1-radical . %S)\t; %c%s"
1177 ;; (ideographic-radical value)
1180 ;; (setq radical value)))
1181 ;; (setq attributes (delq 'shinjigen-1-radical attributes))
1183 (when (and (memq 'ideographic- attributes)
1184 (setq value (get-char-attribute char 'ideographic-)))
1185 (insert "(ideographic- ")
1186 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1188 (while (consp value)
1189 (setq cell (car value))
1191 (setq cell (decode-char '=ucs cell)))
1192 (cond ((characterp cell)
1196 (insert (format "%S" cell))
1197 (char-db-insert-char-spec cell readable))
1198 (setq separator lbs))
1202 (if (consp (car cell))
1203 (char-db-insert-char-spec cell readable)
1204 (char-db-insert-char-reference cell readable))
1205 (setq separator lbs))
1209 (insert (prin1-to-string cell))
1210 (setq separator " ")))
1211 (setq value (cdr value)))
1213 (insert line-breaking)
1214 (setq attributes (delq 'ideographic- attributes)))
1215 (when (and (memq 'total-strokes attributes)
1216 (setq value (get-char-attribute char 'total-strokes)))
1217 (insert (format "(total-strokes . %S)%s"
1220 (setq attributes (delq 'total-strokes attributes))
1222 (when (and (memq '->ideograph attributes)
1223 (setq value (get-char-attribute char '->ideograph)))
1224 (insert (format "(->ideograph\t%s)%s"
1225 (mapconcat (lambda (code)
1226 (cond ((symbolp code)
1229 (format "#x%04X" code))
1232 line-breaking code))))
1235 (setq attributes (delq '->ideograph attributes))
1237 ;; (when (and (memq '->decomposition attributes)
1238 ;; (setq value (get-char-attribute char '->decomposition)))
1239 ;; (insert (format "(->decomposition\t%s)%s"
1240 ;; (mapconcat (lambda (code)
1241 ;; (cond ((symbolp code)
1242 ;; (symbol-name code))
1243 ;; ((characterp code)
1245 ;; (format "%S" code)
1250 ;; (format "#x%04X" code))
1252 ;; (format "%s%S" line-breaking code))))
1255 ;; (setq attributes (delq '->decomposition attributes))
1257 (if (equal (get-char-attribute char '->titlecase)
1258 (get-char-attribute char '->uppercase))
1259 (setq attributes (delq '->titlecase attributes)))
1260 (when (and (memq '->mojikyo attributes)
1261 (setq value (get-char-attribute char '->mojikyo)))
1262 (insert (format "(->mojikyo\t\t. %06d)\t; %c%s"
1263 value (decode-char 'mojikyo value)
1265 (setq attributes (delq '->mojikyo attributes))
1267 (when (and (memq 'hanyu-dazidian-vol attributes)
1268 (setq value (get-char-attribute char 'hanyu-dazidian-vol)))
1269 (insert (format "(hanyu-dazidian-vol . %d)%s"
1270 value line-breaking))
1271 (setq attributes (delq 'hanyu-dazidian-vol attributes))
1273 (when (and (memq 'hanyu-dazidian-page attributes)
1274 (setq value (get-char-attribute char 'hanyu-dazidian-page)))
1275 (insert (format "(hanyu-dazidian-page . %d)%s"
1276 value line-breaking))
1277 (setq attributes (delq 'hanyu-dazidian-page attributes))
1279 (when (and (memq 'hanyu-dazidian-char attributes)
1280 (setq value (get-char-attribute char 'hanyu-dazidian-char)))
1281 (insert (format "(hanyu-dazidian-char . %d)%s"
1282 value line-breaking))
1283 (setq attributes (delq 'hanyu-dazidian-char attributes))
1286 (dolist (ignored '(composition
1287 ->denotational <-subsumptive ->ucs-unified
1288 ->ideographic-component-forms))
1289 (setq attributes (delq ignored attributes))))
1291 (setq name (car attributes))
1292 (unless (eq (setq value (get-char-attribute char name 'value-is-empty))
1294 (cond ((setq ret (find-charset name))
1295 (setq name (charset-name ret))
1296 (when (not (memq name dest-ccss))
1297 (setq dest-ccss (cons name dest-ccss))
1298 (char-db-insert-ccs-feature name value line-breaking))
1300 ((string-match "^=>ucs@" (symbol-name name))
1301 (insert (format "(%-18s . #x%04X)\t; %c%s"
1302 name value (decode-char '=ucs value)
1305 ((eq name 'jisx0208-1978/4X)
1306 (insert (format "(%-18s . #x%04X)%s"
1312 (not (eq name '->subsumptive))
1313 (not (eq name '->uppercase))
1314 (not (eq name '->lowercase))
1315 (not (eq name '->titlecase))
1316 (not (eq name '->canonical))
1317 (not (eq name '->Bopomofo))
1318 (not (eq name '->mistakable))
1319 (not (eq name '->ideographic-variants))
1320 (null (get-char-attribute
1321 char (intern (format "%s*sources" name))))
1322 (not (string-match "\\*sources$" (symbol-name name)))
1323 (null (get-char-attribute
1324 char (intern (format "%s*note" name))))
1325 (not (string-match "\\*note$" (symbol-name name)))
1326 (or (eq name '<-identical)
1327 (eq name '<-uppercase)
1328 (eq name '<-lowercase)
1329 (eq name '<-titlecase)
1330 (eq name '<-canonical)
1331 (eq name '<-ideographic-variants)
1332 ;; (eq name '<-synonyms)
1333 (string-match "^<-synonyms" (symbol-name name))
1334 (eq name '<-mistakable)
1335 (when (string-match "^->" (symbol-name name))
1337 ((string-match "^->fullwidth" (symbol-name name))
1338 (not (and (consp value)
1339 (characterp (car value))
1341 (car value) '=ucs 'defined-only)))
1346 ((or (eq name 'ideographic-structure)
1347 (eq name 'ideographic-combination)
1348 (eq name 'ideographic-)
1349 (eq name '=decomposition)
1350 (char-feature-base-name= '=decomposition name)
1351 (char-feature-base-name= '=>decomposition name)
1352 ;; (string-match "^=>*decomposition\\(@[^*]+\\)?$"
1353 ;; (symbol-name name))
1354 (string-match "^\\(->\\|<-\\)[^*]*$" (symbol-name name))
1355 (string-match "^\\(->\\|<-\\)[^*]*\\*sources$"
1358 (char-db-insert-relation-feature char name value
1361 ((memq name '(ideograph=
1362 original-ideograph-of
1363 ancient-ideograph-of
1366 ;; simplified-ideograph-of
1367 ideographic-variants
1368 ;; ideographic-different-form-of
1370 (insert (format "(%-18s%s " name line-breaking))
1371 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1373 (while (consp value)
1374 (setq cell (car value))
1375 (if (and (consp cell)
1380 (char-db-insert-alist cell readable)
1381 (setq separator lbs))
1384 (insert (prin1-to-string cell))
1385 (setq separator " "))
1386 (setq value (cdr value)))
1388 (insert line-breaking))
1390 (insert (format "(%-18s " name))
1391 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1393 (while (consp value)
1394 (setq cell (car value))
1395 (if (and (consp cell)
1397 (setq ret (condition-case nil
1405 (setq key (car (car rest)))
1406 (if (find-charset key)
1407 (setq cal (cons key cal))
1408 (setq al (cons key al)))
1409 (setq rest (cdr rest)))
1412 (insert-char-attributes ret
1416 (setq separator lbs))
1417 (setq ret (prin1-to-string cell))
1419 (if (< (+ (current-column)
1426 (setq separator " "))
1427 (setq value (cdr value)))
1429 (insert line-breaking))
1431 (insert (format "(%-18s" name))
1432 (setq ret (prin1-to-string value))
1433 (unless (< (+ (current-column)
1437 (insert line-breaking))
1438 (insert " . " ret ")" line-breaking)
1439 ;; (insert (format "(%-18s . %S)%s"
1444 (setq attributes (cdr attributes)))
1447 (defun insert-char-data (char &optional readable
1450 (narrow-to-region (point)(point))
1451 (insert "(define-char
1453 (insert-char-attributes char readable attributes)
1455 (goto-char (point-min))
1456 (while (re-search-forward "[ \t]+$" nil t)
1459 (goto-char (point-min))
1460 (while (re-search-forward "[ \t][ \t][ \t]*" nil t)
1461 (let ((column (current-column))
1462 (indent-tabs-mode t))
1463 (delete-region (match-beginning 0) (point))
1464 (indent-to column)))
1465 (goto-char (point-max))
1466 ;; (tabify (point-min)(point-max))
1469 (defun insert-char-data-with-variant (char &optional printable
1471 script excluded-script)
1472 (insert-char-data char printable)
1473 (let ((variants (char-variants char))
1476 (setq variants (sort variants #'<))
1477 (setq rest variants)
1478 (setq variants (cons char variants))
1480 (setq variant (car rest))
1481 (unless (get-char-attribute variant '<-subsumptive)
1482 (if (and (or (null script)
1483 (null (setq vs (get-char-attribute variant 'script)))
1485 (or (null excluded-script)
1486 (null (setq vs (get-char-attribute variant 'script)))
1487 (not (memq excluded-script vs))))
1488 (unless (and no-ucs-unified (get-char-attribute variant '=ucs))
1489 (insert-char-data variant printable)
1490 (if (setq ret (char-variants variant))
1492 (or (memq (car ret) variants)
1493 ;; (get-char-attribute (car ret) '<-subsumptive)
1494 (setq rest (nconc rest (list (car ret)))))
1495 (setq ret (cdr ret)))))))
1496 (setq rest (cdr rest)))))
1498 (defun insert-char-range-data (min max &optional script excluded-script)
1501 (while (<= code max)
1502 (setq char (decode-char '=ucs code))
1503 (if (encode-char char '=ucs 'defined-only)
1504 (insert-char-data-with-variant char nil 'no-ucs-unified
1505 script excluded-script))
1506 (setq code (1+ code)))))
1508 (defun write-char-range-data-to-file (min max file
1509 &optional script excluded-script)
1510 (let ((coding-system-for-write char-db-file-coding-system))
1512 (insert (format ";; -*- coding: %s -*-\n"
1513 char-db-file-coding-system))
1514 (insert-char-range-data min max script excluded-script)
1515 (write-region (point-min)(point-max) file))))
1517 (defvar what-character-original-window-configuration)
1520 (defun what-char-definition (char)
1521 (interactive (list (char-after)))
1522 (let ((buf (get-buffer-create "*Character Description*"))
1523 (the-buf (current-buffer))
1524 (win-conf (current-window-configuration)))
1526 (make-local-variable 'what-character-original-window-configuration)
1527 (setq what-character-original-window-configuration win-conf)
1528 (setq buffer-read-only nil)
1532 (insert-char-data-with-variant char 'printable)
1533 (unless (char-attribute-alist char)
1534 (insert (format ";; = %c\n"
1535 (let* ((rest (split-char char))
1539 (setq code (logior (lsh code 8)
1541 (decode-char ccs code)))))
1542 ;; (char-db-update-comment)
1543 (set-buffer-modified-p nil)
1544 (view-mode the-buf (lambda (buf)
1545 (set-window-configuration
1546 what-character-original-window-configuration)
1548 (goto-char (point-min)))
1550 (set-window-configuration
1551 what-character-original-window-configuration)
1552 (signal (car err) (cdr err)))))))
1558 (provide 'char-db-util)
1560 ;;; char-db-util.el ends here