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
330 ;;; @ char-db formatters
333 (defun char-db-make-char-spec (char)
335 (cond ((characterp char)
336 (cond ((and (setq ret (encode-char char '=ucs 'defined-only))
337 (not (and (<= #xE000 ret)(<= ret #xF8FF))))
338 (setq char-spec (list (cons '=ucs ret)))
339 (cond ((setq ret (get-char-attribute char 'name))
340 (setq char-spec (cons (cons 'name ret) char-spec))
342 ((setq ret (get-char-attribute char 'name*))
343 (setq char-spec (cons (cons 'name* ret) char-spec))
346 ((encode-char char '=mj 'defined-only)
348 (dolist (ccs (charset-list))
349 (if (and (or (eq ccs '=mj)
350 ;; (eq (charset-property ccs 'iso-ir) 177)
351 (string-match "=ucs@" (symbol-name ccs))
353 (setq ccs (charset-name ccs))
354 (null (assq ccs char-spec))
355 (setq ret (encode-char char ccs 'defined-only)))
356 (setq char-spec (cons (cons ccs ret) char-spec))))
358 ((encode-char char '==mj 'defined-only)
360 (dolist (ccs (charset-list))
361 (if (and (or (eq ccs '==mj)
362 ;; (eq (charset-property ccs 'iso-ir) 177)
363 (string-match "=ucs@" (symbol-name ccs))
365 (setq ccs (charset-name ccs))
366 (null (assq ccs char-spec))
367 (setq ret (encode-char char ccs 'defined-only)))
368 (setq char-spec (cons (cons ccs ret) char-spec))))
370 ((encode-char char '=adobe-japan1 'defined-only)
372 (dolist (ccs (charset-list))
373 (if (and (or (memq ccs
382 ;; (eq (charset-property ccs 'iso-ir) 177)
383 (string-match "=ucs@" (symbol-name ccs))
385 (setq ccs (charset-name ccs))
386 (null (assq ccs char-spec))
387 (setq ret (encode-char char ccs 'defined-only)))
388 (setq char-spec (cons (cons ccs ret) char-spec))))
390 ((encode-char char '==adobe-japan1 'defined-only)
392 (dolist (ccs (charset-list))
393 (if (and (or (memq ccs
402 ;; (eq (charset-property ccs 'iso-ir) 177)
403 (string-match "=ucs@" (symbol-name ccs))
405 (setq ccs (charset-name ccs))
406 (null (assq ccs char-spec))
407 (setq ret (encode-char char ccs 'defined-only)))
408 (setq char-spec (cons (cons ccs ret) char-spec))))
412 (let ((rest char-db-coded-charset-priority-list)
415 (setq ccs (charset-name
416 (find-charset (car rest))))
418 (encode-char char ccs
420 (throw 'tag (cons ccs ret)))
421 (setq rest (cdr rest))))))
422 (setq char-spec (list ret))
423 (dolist (ccs (delq (car ret) (charset-list)))
424 (if (and (or (charset-iso-final-char ccs)
431 (eq (charset-property ccs 'iso-ir) 177)
432 ;; (string-match "=ucs@" (symbol-name ccs))
434 (setq ccs (charset-name ccs))
435 (null (assq ccs char-spec))
436 (setq ret (encode-char char ccs 'defined-only)))
437 (setq char-spec (cons (cons ccs ret) char-spec))))
439 (setq char-spec (split-char char)))
440 (cond ((setq ret (get-char-attribute char 'name))
441 (setq char-spec (cons (cons 'name ret) char-spec))
443 ((setq ret (get-char-attribute char 'name*))
444 (setq char-spec (cons (cons 'name* ret) char-spec))
447 ((setq ret (get-char-attribute
448 char 'ideographic-combination))
450 (cons (cons 'ideographic-combination ret)
457 (defun char-db-insert-char-spec (char &optional readable column
460 (setq column (current-column)))
461 (let (char-spec temp-char)
462 (setq char-spec (char-db-make-char-spec char))
463 (unless (or (characterp char) ; char
465 (setq char (find-char char-spec))
467 ;; define temporary character
468 ;; Current implementation is dirty.
469 (setq temp-char (define-char (cons '(ideograph-daikanwa . 0)
471 (remove-char-attribute temp-char 'ideograph-daikanwa)
472 (setq char temp-char))
473 (insert-char-attributes char
475 (union (mapcar #'car char-spec)
479 ;; undefine temporary character
480 ;; Current implementation is dirty.
481 (setq char-spec (char-attribute-alist temp-char))
483 (remove-char-attribute temp-char (car (car char-spec)))
484 (setq char-spec (cdr char-spec))))))
486 (defun char-db-insert-alist (alist &optional readable column)
488 (setq column (current-column)))
490 (concat "\n" (make-string (1+ column) ?\ )))
494 lbs cell rest separator)
497 (setq name (car (car alist))
498 value (cdr (car alist)))
499 (cond ((eq name 'char)
501 (if (setq ret (condition-case nil
509 (setq key (car (car value)))
510 ;; (if (find-charset key)
511 ;; (setq cal (cons key cal))
512 (setq al (cons key al))
514 (setq value (cdr value)))
515 (insert-char-attributes ret
519 (insert (prin1-to-string value)))
521 (insert line-breaking))
523 (insert (format "(%-18s " name))
524 (setq lbs (concat "\n" (make-string (current-column) ?\ )))
526 (setq cell (car value))
527 (if (and (consp cell)
529 (setq ret (condition-case nil
539 (setq key (car (car rest)))
540 ;; (if (find-charset key)
541 ;; (setq cal (cons key cal))
542 (setq al (cons key al))
544 (setq rest (cdr rest)))
547 (insert-char-attributes ret
551 (setq separator lbs))
554 (insert (prin1-to-string cell))
555 (setq separator " "))
556 (setq value (cdr value)))
558 (insert line-breaking))
560 (insert (format "(%-18s . %S)%s"
563 (setq alist (cdr alist))))
566 (defun char-db-insert-char-reference (plist &optional readable column)
568 (setq column (current-column)))
570 (concat "\n" (make-string (1+ column) ?\ )))
575 (setq name (pop plist))
576 (setq value (pop plist))
577 (cond ((eq name :char)
580 (cond ((numberp value)
581 (setq value (decode-char '=ucs value)))
583 ;; (setq value (or (find-char value)
586 (char-db-insert-char-spec value readable)
587 (insert line-breaking)
590 (insert (format "%s%s\t%d ; %c%s"
593 (ideographic-radical value)
597 (insert (format "%s%s\t%S" separator name value))
598 (setq separator line-breaking)))
602 (defun char-db-decode-isolated-char (ccs code-point)
605 (cond ((eq ccs 'arabic-iso8859-6)
606 (decode-char ccs code-point))
608 ;; (decode-builtin-char '==gt code-point))
609 ((and (memq ccs '(=gt-pj-1
620 (setq ret (decode-char ccs code-point))
621 (setq ret (encode-char ret '=gt 'defined-only)))
622 (decode-builtin-char '=gt ret))
624 (decode-builtin-char ccs code-point))))
626 (or (decode-char ccs code-point)
627 (define-char (list (cons ccs code-point)))))
628 ((and (<= 0 (char-int ret))
629 (<= (char-int ret) #x1F))
630 (decode-char '=ucs (+ #x2400 (char-int ret))))
631 ((= (char-int ret) #x7F)
635 (defvar char-db-convert-obsolete-format t)
637 (defun char-db-insert-ccs-feature (name value line-breaking)
643 ((memq name '(=>iwds-1
646 =shinjigen@1ed ==shinjigen@1ed
647 =shinjigen@rev ==shinjigen@rev
648 =shinjigen/+p@rev ==shinjigen/+p@rev
649 ===daikanwa/ho ==daikanwa/ho
650 =daikanwa/ho =>>daikanwa/ho =>daikanwa/ho))
651 "(%-18s . %04d)\t; %c")
652 ((eq name '=shinjigen@1ed/24pr)
653 "(%-18s . %04d)\t; %c")
654 ((or (memq name '(===daikanwa
655 ==daikanwa =daikanwa =>>daikanwa =>daikanwa
656 =daikanwa@rev1 =daikanwa@rev2
657 =daikanwa/+p ==daikanwa/+p ===daikanwa/+p
659 =daikanwa/+2p =>>daikanwa/+2p
664 =adobe-japan1-0 ==adobe-japan1-0 ===adobe-japan1-0
665 =adobe-japan1-1 ==adobe-japan1-1 ===adobe-japan1-1
666 =adobe-japan1-2 ==adobe-japan1-2 ===adobe-japan1-2
667 =adobe-japan1-3 ==adobe-japan1-3 ===adobe-japan1-3
668 =adobe-japan1-4 ==adobe-japan1-4 ===adobe-japan1-4
669 =adobe-japan1-5 ==adobe-japan1-5 ===adobe-japan1-5
670 =adobe-japan1-6 ==adobe-japan1-6 ===adobe-japan1-6
671 =>>adobe-japan1-0 =+>adobe-japan1-0
672 =>>adobe-japan1-1 =+>adobe-japan1-1
673 =>>adobe-japan1-2 =+>adobe-japan1-2
674 =>>adobe-japan1-3 =+>adobe-japan1-3
675 =>>adobe-japan1-4 =+>adobe-japan1-4
676 =>>adobe-japan1-5 =+>adobe-japan1-5
677 =>>adobe-japan1-6 =+>adobe-japan1-6
678 =>cbeta =cbeta =>>cbeta ==cbeta ===cbeta
679 =zinbun-oracle =>zinbun-oracle
681 ;; (string-match "^=adobe-" (symbol-name name))
683 "(%-18s . %05d)\t; %c")
684 ((memq name '(=hanyo-denshi/ks
685 ==hanyo-denshi/ks ===hanyo-denshi/ks
690 "(%-18s . %06d)\t; %c")
691 ((>= (charset-dimension name) 2)
692 "(%-18s . #x%04X)\t; %c")
694 "(%-18s . #x%02X)\t; %c"))
696 (if (= (charset-iso-graphic-plane name) 1)
698 (cond ((= (charset-dimension name) 1)
700 ((= (charset-dimension name) 2)
702 ((= (charset-dimension name) 3)
706 (char-db-decode-isolated-char name value)))
707 (if (and (= (charset-chars name) 94)
708 (= (charset-dimension name) 2))
709 (insert (format " [%02d-%02d]"
710 (- (lsh value -8) 32)
711 (- (logand value 255) 32))))
714 (insert (format "(%-18s . %s)" name value))
716 (insert line-breaking))
718 (defun char-db-insert-relation-feature (char name value line-breaking
720 (insert (format "(%-18s%s " name line-breaking))
721 (let ((lbs (concat "\n" (make-string (current-column) ?\ )))
722 separator cell sources required-features
725 (setq cell (car value))
727 (setq cell (decode-char '=ucs cell)))
729 ((eq name '->subsumptive)
730 (when (or (not (some (lambda (atr)
731 (get-char-attribute cell atr))
732 char-db-ignored-attributes))
734 (encode-char cell ccs 'defined-only))
738 (let ((char-db-ignored-attributes
740 char-db-ignored-attributes)))
741 (insert-char-attributes cell readable nil nil 'for-sub-node))
742 (setq separator lbs))
747 char (intern (format "%s*sources" name))))
748 (setq required-features nil)
749 (dolist (source sources)
753 shinjigen shinjigen@1ed shinjigen@rev))
754 (setq required-features
755 (union required-features
767 =shinjigen/+p@rev))))
769 (setq required-features
770 (union required-features
775 ((find-charset (setq ret (intern (format "=%s" source))))
776 (setq required-features
777 (cons ret required-features)))
778 (t (setq required-features
779 (cons source required-features)))))
780 (cond ((string-match "@JP" (symbol-name name))
781 (setq required-features
782 (union required-features
790 ((string-match "@CN" (symbol-name name))
791 (setq required-features
792 (union required-features
799 (insert (format "%S" cell))
800 (char-db-insert-char-spec cell readable
803 (setq separator lbs))
807 (if (consp (car cell))
808 (char-db-insert-char-spec cell readable)
809 (char-db-insert-char-reference cell readable))
810 (setq separator lbs))
814 (insert (prin1-to-string cell))
815 (setq separator " ")))
816 (setq value (cdr value)))
818 (insert line-breaking)))
820 (defun insert-char-attributes (char &optional readable attributes column
823 (setq column (current-column)))
824 (let (name value ; has-long-ccs-name
828 (concat "\n" (make-string (1+ column) ?\ )))
829 lbs cell separator ret
831 dest-ccss ; sources required-features
836 (if (consp attributes)
838 (dolist (name attributes)
839 (unless (memq name char-db-ignored-attributes)
840 (if (find-charset name)
844 (dolist (name (char-attribute-list))
845 (unless (memq name char-db-ignored-attributes)
846 (if (find-charset name)
850 #'char-attribute-name<)))
852 (when (memq '<-subsumptive attributes)
853 (when (or readable (not for-sub-node))
854 (when (setq value (get-char-attribute char '<-subsumptive))
855 (char-db-insert-relation-feature char '<-subsumptive value
858 (setq attributes (delq '<-subsumptive attributes)))
859 (when (and (memq '<-denotational attributes)
860 (setq value (get-char-attribute char '<-denotational)))
861 (char-db-insert-relation-feature char '<-denotational value
864 (setq attributes (delq '<-denotational attributes)))
865 (when (and (memq '<-denotational@component attributes)
866 (setq value (get-char-attribute char '<-denotational@component)))
867 (char-db-insert-relation-feature char '<-denotational@component value
870 (setq attributes (delq '<-denotational@component attributes)))
871 (when (and (memq 'name attributes)
872 (setq value (get-char-attribute char 'name)))
874 (if (> (+ (current-column) (length value)) 48)
877 value line-breaking))
878 (setq attributes (delq 'name attributes))
880 (when (and (memq 'name* attributes)
881 (setq value (get-char-attribute char 'name*)))
883 (if (> (+ (current-column) (length value)) 48)
886 value line-breaking))
887 (setq attributes (delq 'name* attributes))
889 (when (and (memq 'script attributes)
890 (setq value (get-char-attribute char 'script)))
891 (insert (format "(script\t\t%s)%s"
892 (mapconcat (function prin1-to-string)
895 (setq attributes (delq 'script attributes))
897 (dolist (name '(=>ucs =>ucs*))
898 (when (and (memq name attributes)
899 (setq value (get-char-attribute char name)))
900 (insert (format "(%-18s . #x%04X)\t; %c%s"
901 name value (decode-char '=ucs value)
903 (setq attributes (delq name attributes))))
904 (dolist (name '(=>ucs@gb =>ucs@big5))
905 (when (and (memq name attributes)
906 (setq value (get-char-attribute char name)))
907 (insert (format "(%-18s . #x%04X)\t; %c%s"
912 (symbol-name name) 2)))
915 (setq attributes (delq name attributes))
917 ;; (dolist (name '(=>daikanwa))
918 ;; (when (and (memq name attributes)
919 ;; (setq value (get-char-attribute char name)))
921 ;; (if (integerp value)
922 ;; (format "(%-18s . %05d)\t; %c%s"
923 ;; name value (decode-char '=daikanwa value)
925 ;; (format "(%-18s %s)\t; %c%s"
927 ;; (mapconcat (function prin1-to-string)
929 ;; (char-representative-of-daikanwa char)
931 ;; (setq attributes (delq name attributes))))
932 (when (and (memq 'general-category attributes)
933 (setq value (get-char-attribute char 'general-category)))
935 "(general-category\t%s) ; %s%s"
936 (mapconcat (lambda (cell)
939 (cond ((rassoc value unidata-normative-category-alist)
940 "Normative Category")
941 ((rassoc value unidata-informative-category-alist)
942 "Informative Category")
946 (setq attributes (delq 'general-category attributes))
948 (when (and (memq 'bidi-category attributes)
949 (setq value (get-char-attribute char 'bidi-category)))
950 (insert (format "(bidi-category\t. %S)%s"
953 (setq attributes (delq 'bidi-category attributes))
955 (unless (or (not (memq 'mirrored attributes))
956 (eq (setq value (get-char-attribute char 'mirrored 'empty))
958 (insert (format "(mirrored\t\t. %S)%s"
961 (setq attributes (delq 'mirrored attributes))
964 ((and (memq 'decimal-digit-value attributes)
965 (setq value (get-char-attribute char 'decimal-digit-value)))
966 (insert (format "(decimal-digit-value . %S)%s"
969 (setq attributes (delq 'decimal-digit-value attributes))
970 (when (and (memq 'digit-value attributes)
971 (setq value (get-char-attribute char 'digit-value)))
972 (insert (format "(digit-value\t . %S)%s"
975 (setq attributes (delq 'digit-value attributes))
977 (when (and (memq 'numeric-value attributes)
978 (setq value (get-char-attribute char 'numeric-value)))
979 (insert (format "(numeric-value\t . %S)%s"
982 (setq attributes (delq 'numeric-value attributes))
986 (when (and (memq 'digit-value attributes)
987 (setq value (get-char-attribute char 'digit-value)))
988 (insert (format "(digit-value\t. %S)%s"
991 (setq attributes (delq 'digit-value attributes))
993 (when (and (memq 'numeric-value attributes)
994 (setq value (get-char-attribute char 'numeric-value)))
995 (insert (format "(numeric-value\t. %S)%s"
998 (setq attributes (delq 'numeric-value attributes))
1000 (when (and (memq 'iso-10646-comment attributes)
1001 (setq value (get-char-attribute char 'iso-10646-comment)))
1002 (insert (format "(iso-10646-comment\t. %S)%s"
1005 (setq attributes (delq 'iso-10646-comment attributes))
1007 (when (and (memq 'morohashi-daikanwa attributes)
1008 (setq value (get-char-attribute char 'morohashi-daikanwa)))
1009 (insert (format "(morohashi-daikanwa\t%s)%s"
1010 (mapconcat (function prin1-to-string) value " ")
1012 (setq attributes (delq 'morohashi-daikanwa attributes))
1016 (when (and (memq 'ideographic-radical attributes)
1017 (setq value (get-char-attribute char 'ideographic-radical)))
1018 (setq radical value)
1019 (insert (format "(ideographic-radical . %S)\t; %c%s"
1021 (ideographic-radical radical)
1023 (setq attributes (delq 'ideographic-radical attributes))
1025 (when (and (memq 'shuowen-radical attributes)
1026 (setq value (get-char-attribute char 'shuowen-radical)))
1027 (insert (format "(shuowen-radical\t. %S)\t; %c%s"
1029 (shuowen-radical value)
1031 (setq attributes (delq 'shuowen-radical attributes))
1036 char-db-feature-domains
1038 (dolist (feature (char-attribute-list))
1039 (setq feature (symbol-name feature))
1041 "\\(radical\\|strokes\\)@\\([^@*]+\\)\\(\\*\\|$\\)"
1043 (setq domain (intern (match-string 2 feature)))
1044 (unless (memq domain dest)
1045 (setq dest (cons domain dest)))))
1046 (sort dest #'string<))))
1047 (setq key (intern (format "%s@%s" 'ideographic-radical domain)))
1048 (when (and (memq key attributes)
1049 (setq value (get-char-attribute char key)))
1050 (setq radical value)
1051 (insert (format "(%s . %S)\t; %c%s"
1054 (ideographic-radical radical)
1056 (setq attributes (delq key attributes))
1058 (setq key (intern (format "%s@%s" 'ideographic-strokes domain)))
1059 (when (and (memq key attributes)
1060 (setq value (get-char-attribute char key)))
1061 (setq strokes value)
1062 (insert (format "(%s . %S)%s"
1066 (setq attributes (delq key attributes))
1068 (setq key (intern (format "%s@%s" 'total-strokes domain)))
1069 (when (and (memq key attributes)
1070 (setq value (get-char-attribute char key)))
1071 (insert (format "(%s . %S)%s"
1075 (setq attributes (delq key attributes))
1077 (dolist (feature '(ideographic-radical
1080 (setq key (intern (format "%s@%s*sources" feature domain)))
1081 (when (and (memq key attributes)
1082 (setq value (get-char-attribute char key)))
1083 (insert (format "(%s%s" key line-breaking))
1084 (dolist (cell value)
1085 (insert (format " %s" cell)))
1087 (insert line-breaking)
1088 (setq attributes (delq key attributes))
1091 (when (and (memq 'ideographic-strokes attributes)
1092 (setq value (get-char-attribute char 'ideographic-strokes)))
1093 (setq strokes value)
1094 (insert (format "(ideographic-strokes . %S)%s"
1097 (setq attributes (delq 'ideographic-strokes attributes))
1099 (when (and (memq 'kangxi-radical attributes)
1100 (setq value (get-char-attribute char 'kangxi-radical)))
1101 (unless (eq value radical)
1102 (insert (format "(kangxi-radical\t . %S)\t; %c%s"
1104 (ideographic-radical value)
1107 (setq radical value)))
1108 (setq attributes (delq 'kangxi-radical attributes))
1110 (when (and (memq 'kangxi-strokes attributes)
1111 (setq value (get-char-attribute char 'kangxi-strokes)))
1112 (unless (eq value strokes)
1113 (insert (format "(kangxi-strokes\t . %S)%s"
1117 (setq strokes value)))
1118 (setq attributes (delq 'kangxi-strokes attributes))
1120 (when (and (memq 'japanese-radical attributes)
1121 (setq value (get-char-attribute char 'japanese-radical)))
1122 (unless (eq value radical)
1123 (insert (format "(japanese-radical\t . %S)\t; %c%s"
1125 (ideographic-radical value)
1128 (setq radical value)))
1129 (setq attributes (delq 'japanese-radical attributes))
1131 (when (and (memq 'japanese-strokes attributes)
1132 (setq value (get-char-attribute char 'japanese-strokes)))
1133 (unless (eq value strokes)
1134 (insert (format "(japanese-strokes\t . %S)%s"
1138 (setq strokes value)))
1139 (setq attributes (delq 'japanese-strokes attributes))
1141 (when (and (memq 'cns-radical attributes)
1142 (setq value (get-char-attribute char 'cns-radical)))
1143 (insert (format "(cns-radical\t . %S)\t; %c%s"
1145 (ideographic-radical value)
1147 (setq attributes (delq 'cns-radical attributes))
1149 (when (and (memq 'cns-strokes attributes)
1150 (setq value (get-char-attribute char 'cns-strokes)))
1151 (unless (eq value strokes)
1152 (insert (format "(cns-strokes\t . %S)%s"
1156 (setq strokes value)))
1157 (setq attributes (delq 'cns-strokes attributes))
1159 ;; (when (and (memq 'shinjigen-1-radical attributes)
1160 ;; (setq value (get-char-attribute char 'shinjigen-1-radical)))
1161 ;; (unless (eq value radical)
1162 ;; (insert (format "(shinjigen-1-radical . %S)\t; %c%s"
1164 ;; (ideographic-radical value)
1167 ;; (setq radical value)))
1168 ;; (setq attributes (delq 'shinjigen-1-radical attributes))
1170 (when (and (memq 'ideographic- attributes)
1171 (setq value (get-char-attribute char 'ideographic-)))
1172 (insert "(ideographic- ")
1173 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1175 (while (consp value)
1176 (setq cell (car value))
1178 (setq cell (decode-char '=ucs cell)))
1179 (cond ((characterp cell)
1183 (insert (format "%S" cell))
1184 (char-db-insert-char-spec cell readable))
1185 (setq separator lbs))
1189 (if (consp (car cell))
1190 (char-db-insert-char-spec cell readable)
1191 (char-db-insert-char-reference cell readable))
1192 (setq separator lbs))
1196 (insert (prin1-to-string cell))
1197 (setq separator " ")))
1198 (setq value (cdr value)))
1200 (insert line-breaking)
1201 (setq attributes (delq 'ideographic- attributes)))
1202 (when (and (memq 'total-strokes attributes)
1203 (setq value (get-char-attribute char 'total-strokes)))
1204 (insert (format "(total-strokes . %S)%s"
1207 (setq attributes (delq 'total-strokes attributes))
1209 (when (and (memq '->ideograph attributes)
1210 (setq value (get-char-attribute char '->ideograph)))
1211 (insert (format "(->ideograph\t%s)%s"
1212 (mapconcat (lambda (code)
1213 (cond ((symbolp code)
1216 (format "#x%04X" code))
1219 line-breaking code))))
1222 (setq attributes (delq '->ideograph attributes))
1224 ;; (when (and (memq '->decomposition attributes)
1225 ;; (setq value (get-char-attribute char '->decomposition)))
1226 ;; (insert (format "(->decomposition\t%s)%s"
1227 ;; (mapconcat (lambda (code)
1228 ;; (cond ((symbolp code)
1229 ;; (symbol-name code))
1230 ;; ((characterp code)
1232 ;; (format "%S" code)
1237 ;; (format "#x%04X" code))
1239 ;; (format "%s%S" line-breaking code))))
1242 ;; (setq attributes (delq '->decomposition attributes))
1244 (if (equal (get-char-attribute char '->titlecase)
1245 (get-char-attribute char '->uppercase))
1246 (setq attributes (delq '->titlecase attributes)))
1247 (when (and (memq '->mojikyo attributes)
1248 (setq value (get-char-attribute char '->mojikyo)))
1249 (insert (format "(->mojikyo\t\t. %06d)\t; %c%s"
1250 value (decode-char 'mojikyo value)
1252 (setq attributes (delq '->mojikyo attributes))
1254 (when (and (memq 'hanyu-dazidian-vol attributes)
1255 (setq value (get-char-attribute char 'hanyu-dazidian-vol)))
1256 (insert (format "(hanyu-dazidian-vol . %d)%s"
1257 value line-breaking))
1258 (setq attributes (delq 'hanyu-dazidian-vol attributes))
1260 (when (and (memq 'hanyu-dazidian-page attributes)
1261 (setq value (get-char-attribute char 'hanyu-dazidian-page)))
1262 (insert (format "(hanyu-dazidian-page . %d)%s"
1263 value line-breaking))
1264 (setq attributes (delq 'hanyu-dazidian-page attributes))
1266 (when (and (memq 'hanyu-dazidian-char attributes)
1267 (setq value (get-char-attribute char 'hanyu-dazidian-char)))
1268 (insert (format "(hanyu-dazidian-char . %d)%s"
1269 value line-breaking))
1270 (setq attributes (delq 'hanyu-dazidian-char attributes))
1273 (dolist (ignored '(composition
1274 ->denotational <-subsumptive ->ucs-unified
1275 ->ideographic-component-forms))
1276 (setq attributes (delq ignored attributes))))
1278 (setq name (car attributes))
1279 (unless (eq (setq value (get-char-attribute char name 'value-is-empty))
1281 (cond ((setq ret (find-charset name))
1282 (setq name (charset-name ret))
1283 (when (not (memq name dest-ccss))
1284 (setq dest-ccss (cons name dest-ccss))
1285 (char-db-insert-ccs-feature name value line-breaking))
1287 ((string-match "^=>ucs@" (symbol-name name))
1288 (insert (format "(%-18s . #x%04X)\t; %c%s"
1289 name value (decode-char '=ucs value)
1292 ((eq name 'jisx0208-1978/4X)
1293 (insert (format "(%-18s . #x%04X)%s"
1299 (not (eq name '->subsumptive))
1300 (not (eq name '->uppercase))
1301 (not (eq name '->lowercase))
1302 (not (eq name '->titlecase))
1303 (not (eq name '->canonical))
1304 (not (eq name '->Bopomofo))
1305 (not (eq name '->mistakable))
1306 (not (eq name '->ideographic-variants))
1307 (null (get-char-attribute
1308 char (intern (format "%s*sources" name))))
1309 (not (string-match "\\*sources$" (symbol-name name)))
1310 (null (get-char-attribute
1311 char (intern (format "%s*note" name))))
1312 (not (string-match "\\*note$" (symbol-name name)))
1313 (or (eq name '<-identical)
1314 (eq name '<-uppercase)
1315 (eq name '<-lowercase)
1316 (eq name '<-titlecase)
1317 (eq name '<-canonical)
1318 (eq name '<-ideographic-variants)
1319 ;; (eq name '<-synonyms)
1320 (string-match "^<-synonyms" (symbol-name name))
1321 (eq name '<-mistakable)
1322 (when (string-match "^->" (symbol-name name))
1324 ((string-match "^->fullwidth" (symbol-name name))
1325 (not (and (consp value)
1326 (characterp (car value))
1328 (car value) '=ucs 'defined-only)))
1333 ((or (eq name 'ideographic-structure)
1334 (eq name 'ideographic-combination)
1335 (eq name 'ideographic-)
1336 (eq name '=decomposition)
1337 (char-feature-base-name= '=decomposition name)
1338 (char-feature-base-name= '=>decomposition name)
1339 ;; (string-match "^=>*decomposition\\(@[^*]+\\)?$"
1340 ;; (symbol-name name))
1341 (string-match "^\\(->\\|<-\\)[^*]*$" (symbol-name name))
1342 (string-match "^\\(->\\|<-\\)[^*]*\\*sources$"
1345 (char-db-insert-relation-feature char name value
1348 ((memq name '(ideograph=
1349 original-ideograph-of
1350 ancient-ideograph-of
1353 ;; simplified-ideograph-of
1354 ideographic-variants
1355 ;; ideographic-different-form-of
1357 (insert (format "(%-18s%s " name line-breaking))
1358 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1360 (while (consp value)
1361 (setq cell (car value))
1362 (if (and (consp cell)
1367 (char-db-insert-alist cell readable)
1368 (setq separator lbs))
1371 (insert (prin1-to-string cell))
1372 (setq separator " "))
1373 (setq value (cdr value)))
1375 (insert line-breaking))
1377 (insert (format "(%-18s " name))
1378 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1380 (while (consp value)
1381 (setq cell (car value))
1382 (if (and (consp cell)
1384 (setq ret (condition-case nil
1392 (setq key (car (car rest)))
1393 (if (find-charset key)
1394 (setq cal (cons key cal))
1395 (setq al (cons key al)))
1396 (setq rest (cdr rest)))
1399 (insert-char-attributes ret
1403 (setq separator lbs))
1404 (setq ret (prin1-to-string cell))
1406 (if (< (+ (current-column)
1413 (setq separator " "))
1414 (setq value (cdr value)))
1416 (insert line-breaking))
1418 (insert (format "(%-18s" name))
1419 (setq ret (prin1-to-string value))
1420 (unless (< (+ (current-column)
1424 (insert line-breaking))
1425 (insert " . " ret ")" line-breaking)
1426 ;; (insert (format "(%-18s . %S)%s"
1431 (setq attributes (cdr attributes)))
1434 (defun insert-char-data (char &optional readable
1437 (narrow-to-region (point)(point))
1438 (insert "(define-char
1440 (insert-char-attributes char readable attributes)
1442 (goto-char (point-min))
1443 (while (re-search-forward "[ \t]+$" nil t)
1446 (goto-char (point-min))
1447 (while (re-search-forward "[ \t][ \t][ \t]*" nil t)
1448 (let ((column (current-column))
1449 (indent-tabs-mode t))
1450 (delete-region (match-beginning 0) (point))
1451 (indent-to column)))
1452 (goto-char (point-max))
1453 ;; (tabify (point-min)(point-max))
1456 (defun insert-char-data-with-variant (char &optional printable
1458 script excluded-script)
1459 (insert-char-data char printable)
1460 (let ((variants (char-variants char))
1463 (setq variants (sort variants #'<))
1464 (setq rest variants)
1465 (setq variants (cons char variants))
1467 (setq variant (car rest))
1468 (unless (get-char-attribute variant '<-subsumptive)
1469 (if (and (or (null script)
1470 (null (setq vs (get-char-attribute variant 'script)))
1472 (or (null excluded-script)
1473 (null (setq vs (get-char-attribute variant 'script)))
1474 (not (memq excluded-script vs))))
1475 (unless (and no-ucs-unified (get-char-attribute variant '=ucs))
1476 (insert-char-data variant printable)
1477 (if (setq ret (char-variants variant))
1479 (or (memq (car ret) variants)
1480 ;; (get-char-attribute (car ret) '<-subsumptive)
1481 (setq rest (nconc rest (list (car ret)))))
1482 (setq ret (cdr ret)))))))
1483 (setq rest (cdr rest)))))
1485 (defun insert-char-range-data (min max &optional script excluded-script)
1488 (while (<= code max)
1489 (setq char (decode-char '=ucs code))
1490 (if (encode-char char '=ucs 'defined-only)
1491 (insert-char-data-with-variant char nil 'no-ucs-unified
1492 script excluded-script))
1493 (setq code (1+ code)))))
1495 (defun write-char-range-data-to-file (min max file
1496 &optional script excluded-script)
1497 (let ((coding-system-for-write char-db-file-coding-system))
1499 (insert (format ";; -*- coding: %s -*-\n"
1500 char-db-file-coding-system))
1501 (insert-char-range-data min max script excluded-script)
1502 (write-region (point-min)(point-max) file))))
1504 (defvar what-character-original-window-configuration)
1507 (defun what-char-definition (char)
1508 (interactive (list (char-after)))
1509 (let ((buf (get-buffer-create "*Character Description*"))
1510 (the-buf (current-buffer))
1511 (win-conf (current-window-configuration)))
1513 (make-local-variable 'what-character-original-window-configuration)
1514 (setq what-character-original-window-configuration win-conf)
1515 (setq buffer-read-only nil)
1519 (insert-char-data-with-variant char 'printable)
1520 (unless (char-attribute-alist char)
1521 (insert (format ";; = %c\n"
1522 (let* ((rest (split-char char))
1526 (setq code (logior (lsh code 8)
1528 (decode-char ccs code)))))
1529 ;; (char-db-update-comment)
1530 (set-buffer-modified-p nil)
1531 (view-mode the-buf (lambda (buf)
1532 (set-window-configuration
1533 what-character-original-window-configuration)
1535 (goto-char (point-min)))
1537 (set-window-configuration
1538 what-character-original-window-configuration)
1539 (signal (car err) (cdr err)))))))
1545 (provide 'char-db-util)
1547 ;;; char-db-util.el ends here