1 ;;; char-db-util.el --- Character Database utility -*- coding: utf-8-er; -*-
3 ;; Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006,
4 ;; 2007, 2008, 2009, 2010, 2011, 2012, 2013 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
100 (defun shuowen-radical (number)
101 (aref shuowen-radicals (1- number)))
103 (defvar char-db-file-coding-system 'utf-8-mcs-er)
105 (defvar char-db-ignored-attributes '(ideographic-products))
107 (defvar char-db-coded-charset-priority-list
198 ;; =>>>adobe-japan1-0
199 ;; =>>>adobe-japan1-1
200 ;; =>>>adobe-japan1-2
201 ;; =>>>adobe-japan1-3
202 ;; =>>>adobe-japan1-4
203 ;; =>>>adobe-japan1-5
204 ;; =>>>adobe-japan1-6
208 ;; =>>>hanyo-denshi/ja
209 ;; =>>>hanyo-denshi/jb
210 ;; =>>>hanyo-denshi/jc
211 ;; =>>>hanyo-denshi/ft
212 ;; =>>>hanyo-denshi/ib
213 ;; =>>>hanyo-denshi/hg
214 ;; =>>>hanyo-denshi/jt
215 ;; =>>>hanyo-denshi/ks
305 ;;; @ char-db formatters
308 (defun char-db-make-char-spec (char)
310 (cond ((characterp char)
311 (cond ((and (setq ret (encode-char char '=ucs 'defined-only))
312 (not (and (<= #xE000 ret)(<= ret #xF8FF))))
313 (setq char-spec (list (cons '=ucs ret)))
314 (cond ((setq ret (get-char-attribute char 'name))
315 (setq char-spec (cons (cons 'name ret) char-spec))
317 ((setq ret (get-char-attribute char 'name*))
318 (setq char-spec (cons (cons 'name* ret) char-spec))
321 ((encode-char char '=adobe-japan1 'defined-only)
323 (dolist (ccs (charset-list))
324 (if (and (or (memq ccs
333 ;; (eq (charset-property ccs 'iso-ir) 177)
334 (string-match "=ucs@" (symbol-name ccs))
336 (setq ccs (charset-name ccs))
337 (null (assq ccs char-spec))
338 (setq ret (encode-char char ccs 'defined-only)))
339 (setq char-spec (cons (cons ccs ret) char-spec))))
341 ((encode-char char '==adobe-japan1 'defined-only)
343 (dolist (ccs (charset-list))
344 (if (and (or (memq ccs
353 ;; (eq (charset-property ccs 'iso-ir) 177)
354 (string-match "=ucs@" (symbol-name ccs))
356 (setq ccs (charset-name ccs))
357 (null (assq ccs char-spec))
358 (setq ret (encode-char char ccs 'defined-only)))
359 (setq char-spec (cons (cons ccs ret) char-spec))))
363 (let ((rest char-db-coded-charset-priority-list)
366 (setq ccs (charset-name
367 (find-charset (car rest))))
369 (encode-char char ccs
371 (throw 'tag (cons ccs ret)))
372 (setq rest (cdr rest))))))
373 (setq char-spec (list ret))
374 (dolist (ccs (delq (car ret) (charset-list)))
375 (if (and (or (charset-iso-final-char 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 (setq char-spec (split-char char)))
391 (cond ((setq ret (get-char-attribute char 'name))
392 (setq char-spec (cons (cons 'name ret) char-spec))
394 ((setq ret (get-char-attribute char 'name*))
395 (setq char-spec (cons (cons 'name* ret) char-spec))
398 ((setq ret (get-char-attribute
399 char 'ideographic-combination))
401 (cons (cons 'ideographic-combination ret)
408 (defun char-db-insert-char-spec (char &optional readable column
411 (setq column (current-column)))
412 (let (char-spec temp-char)
413 (setq char-spec (char-db-make-char-spec char))
414 (unless (or (characterp char) ; char
416 (setq char (find-char char-spec))
418 ;; define temporary character
419 ;; Current implementation is dirty.
420 (setq temp-char (define-char (cons '(ideograph-daikanwa . 0)
422 (remove-char-attribute temp-char 'ideograph-daikanwa)
423 (setq char temp-char))
424 (insert-char-attributes char
426 (union (mapcar #'car char-spec)
430 ;; undefine temporary character
431 ;; Current implementation is dirty.
432 (setq char-spec (char-attribute-alist temp-char))
434 (remove-char-attribute temp-char (car (car char-spec)))
435 (setq char-spec (cdr char-spec))))))
437 (defun char-db-insert-alist (alist &optional readable column)
439 (setq column (current-column)))
441 (concat "\n" (make-string (1+ column) ?\ )))
445 lbs cell rest separator)
448 (setq name (car (car alist))
449 value (cdr (car alist)))
450 (cond ((eq name 'char)
452 (if (setq ret (condition-case nil
460 (setq key (car (car value)))
461 ;; (if (find-charset key)
462 ;; (setq cal (cons key cal))
463 (setq al (cons key al))
465 (setq value (cdr value)))
466 (insert-char-attributes ret
470 (insert (prin1-to-string value)))
472 (insert line-breaking))
474 (insert (format "(%-18s " name))
475 (setq lbs (concat "\n" (make-string (current-column) ?\ )))
477 (setq cell (car value))
478 (if (and (consp cell)
480 (setq ret (condition-case nil
490 (setq key (car (car rest)))
491 ;; (if (find-charset key)
492 ;; (setq cal (cons key cal))
493 (setq al (cons key al))
495 (setq rest (cdr rest)))
498 (insert-char-attributes ret
502 (setq separator lbs))
505 (insert (prin1-to-string cell))
506 (setq separator " "))
507 (setq value (cdr value)))
509 (insert line-breaking))
511 (insert (format "(%-18s . %S)%s"
514 (setq alist (cdr alist))))
517 (defun char-db-insert-char-reference (plist &optional readable column)
519 (setq column (current-column)))
521 (concat "\n" (make-string (1+ column) ?\ )))
526 (setq name (pop plist))
527 (setq value (pop plist))
528 (cond ((eq name :char)
531 (cond ((numberp value)
532 (setq value (decode-char '=ucs value)))
534 ;; (setq value (or (find-char value)
537 (char-db-insert-char-spec value readable)
538 (insert line-breaking)
541 (insert (format "%s%s\t%d ; %c%s"
544 (ideographic-radical value)
548 (insert (format "%s%s\t%S" separator name value))
549 (setq separator line-breaking)))
553 (defun char-db-decode-isolated-char (ccs code-point)
556 (cond ((eq ccs 'arabic-iso8859-6)
557 (decode-char ccs code-point))
559 ;; (decode-builtin-char '==gt code-point))
560 ((and (memq ccs '(=gt-pj-1
571 (setq ret (decode-char ccs code-point))
572 (setq ret (encode-char ret '=gt 'defined-only)))
573 (decode-builtin-char '=gt ret))
575 (decode-builtin-char ccs code-point))))
576 (cond ((and (<= 0 (char-int ret))
577 (<= (char-int ret) #x1F))
578 (decode-char '=ucs (+ #x2400 (char-int ret))))
579 ((= (char-int ret) #x7F)
583 (defvar char-db-convert-obsolete-format t)
585 (defun char-db-insert-ccs-feature (name value line-breaking)
591 ((memq name '(==shinjigen
593 =shinjigen@1ed ==shinjigen@1ed
594 =shinjigen@rev ==shinjigen@rev
595 =shinjigen/+p@rev ==shinjigen/+p@rev
597 =daikanwa/ho =>>daikanwa/ho =>daikanwa/ho))
598 "(%-18s . %04d)\t; %c")
599 ((eq name '=shinjigen@1ed/24pr)
600 "(%-18s . %04d)\t; %c")
601 ((or (memq name '(==daikanwa
602 =daikanwa =>>daikanwa =>daikanwa
603 =daikanwa@rev1 =daikanwa@rev2
604 =daikanwa/+p ==daikanwa/+p =>>daikanwa/+p
605 =daikanwa/+2p =>>daikanwa/+2p
608 =gt-k ==gt-k =>>gt-k =>gt-k
609 =adobe-japan1-0 ==adobe-japan1-0 ; =>>>adobe-japan1-0
610 =adobe-japan1-1 ==adobe-japan1-1 ; =>>>adobe-japan1-1
611 =adobe-japan1-2 ==adobe-japan1-2 ; =>>>adobe-japan1-2
612 =adobe-japan1-3 ==adobe-japan1-3 ; =>>>adobe-japan1-3
613 =adobe-japan1-4 ==adobe-japan1-4 ; =>>>adobe-japan1-4
614 =adobe-japan1-5 ==adobe-japan1-5 ; =>>>adobe-japan1-5
615 =adobe-japan1-6 ==adobe-japan1-6 ; =>>>adobe-japan1-6
616 =>>adobe-japan1-0 =+>adobe-japan1-0
617 =>>adobe-japan1-1 =+>adobe-japan1-1
618 =>>adobe-japan1-2 =+>adobe-japan1-2
619 =>>adobe-japan1-3 =+>adobe-japan1-3
620 =>>adobe-japan1-4 =+>adobe-japan1-4
621 =>>adobe-japan1-5 =+>adobe-japan1-5
622 =>>adobe-japan1-6 =+>adobe-japan1-6
624 =zinbun-oracle =>zinbun-oracle))
625 ;; (string-match "^=adobe-" (symbol-name name))
627 "(%-18s . %05d)\t; %c")
628 ((memq name '(=hanyo-denshi/ks
629 ==hanyo-denshi/ks ; =>>>hanyo-denshi/ks
632 "(%-18s . %06d)\t; %c")
633 ((>= (charset-dimension name) 2)
634 "(%-18s . #x%04X)\t; %c")
636 "(%-18s . #x%02X)\t; %c"))
638 (if (= (charset-iso-graphic-plane name) 1)
640 (cond ((= (charset-dimension name) 1)
642 ((= (charset-dimension name) 2)
644 ((= (charset-dimension name) 3)
648 (char-db-decode-isolated-char name value)))
649 (if (and (= (charset-chars name) 94)
650 (= (charset-dimension name) 2))
651 (insert (format " [%02d-%02d]"
652 (- (lsh value -8) 32)
653 (- (logand value 255) 32))))
656 (insert (format "(%-18s . %s)" name value))
658 (insert line-breaking))
660 (defun char-db-insert-relation-feature (char name value line-breaking
662 (insert (format "(%-18s%s " name line-breaking))
663 (let ((lbs (concat "\n" (make-string (current-column) ?\ )))
664 separator cell sources required-features
667 (setq cell (car value))
669 (setq cell (decode-char '=ucs cell)))
671 ((eq name '->subsumptive)
672 (when (or (not (some (lambda (atr)
673 (get-char-attribute cell atr))
674 char-db-ignored-attributes))
676 (encode-char cell ccs 'defined-only))
680 (let ((char-db-ignored-attributes
682 char-db-ignored-attributes)))
683 (insert-char-attributes cell readable nil nil 'for-sub-node))
684 (setq separator lbs))
689 char (intern (format "%s*sources" name))))
690 (setq required-features nil)
691 (dolist (source sources)
695 shinjigen shinjigen@1ed shinjigen@rev))
696 (setq required-features
697 (union required-features
709 =shinjigen/+p@rev))))
711 (setq required-features
712 (union required-features
717 ((find-charset (setq ret (intern (format "=%s" source))))
718 (setq required-features
719 (cons ret required-features)))
720 (t (setq required-features
721 (cons source required-features)))))
722 (cond ((string-match "@JP" (symbol-name name))
723 (setq required-features
724 (union required-features
732 ((string-match "@CN" (symbol-name name))
733 (setq required-features
734 (union required-features
741 (insert (format "%S" cell))
742 (char-db-insert-char-spec cell readable
745 (setq separator lbs))
749 (if (consp (car cell))
750 (char-db-insert-char-spec cell readable)
751 (char-db-insert-char-reference cell readable))
752 (setq separator lbs))
756 (insert (prin1-to-string cell))
757 (setq separator " ")))
758 (setq value (cdr value)))
760 (insert line-breaking)))
762 (defun insert-char-attributes (char &optional readable attributes column
765 (setq column (current-column)))
766 (let (name value ; has-long-ccs-name
770 (concat "\n" (make-string (1+ column) ?\ )))
771 lbs cell separator ret
773 dest-ccss ; sources required-features
778 (if (consp attributes)
780 (dolist (name attributes)
781 (unless (memq name char-db-ignored-attributes)
782 (if (find-charset name)
786 (dolist (name (char-attribute-list))
787 (unless (memq name char-db-ignored-attributes)
788 (if (find-charset name)
792 #'char-attribute-name<)))
794 (when (memq '<-subsumptive attributes)
795 (when (or readable (not for-sub-node))
796 (when (setq value (get-char-attribute char '<-subsumptive))
797 (char-db-insert-relation-feature char '<-subsumptive value
800 (setq attributes (delq '<-subsumptive attributes)))
801 (when (and (memq '<-denotational attributes)
802 (setq value (get-char-attribute char '<-denotational)))
803 (char-db-insert-relation-feature char '<-denotational value
806 (setq attributes (delq '<-denotational attributes)))
807 (when (and (memq 'name attributes)
808 (setq value (get-char-attribute char 'name)))
810 (if (> (+ (current-column) (length value)) 48)
813 value line-breaking))
814 (setq attributes (delq 'name attributes))
816 (when (and (memq 'name* attributes)
817 (setq value (get-char-attribute char 'name*)))
819 (if (> (+ (current-column) (length value)) 48)
822 value line-breaking))
823 (setq attributes (delq 'name* attributes))
825 (when (and (memq 'script attributes)
826 (setq value (get-char-attribute char 'script)))
827 (insert (format "(script\t\t%s)%s"
828 (mapconcat (function prin1-to-string)
831 (setq attributes (delq 'script attributes))
833 (dolist (name '(=>ucs =>ucs*))
834 (when (and (memq name attributes)
835 (setq value (get-char-attribute char name)))
836 (insert (format "(%-18s . #x%04X)\t; %c%s"
837 name value (decode-char '=ucs value)
839 (setq attributes (delq name attributes))))
840 (dolist (name '(=>ucs@gb =>ucs@big5))
841 (when (and (memq name attributes)
842 (setq value (get-char-attribute char name)))
843 (insert (format "(%-18s . #x%04X)\t; %c%s"
848 (symbol-name name) 2)))
851 (setq attributes (delq name attributes))
853 ;; (dolist (name '(=>daikanwa))
854 ;; (when (and (memq name attributes)
855 ;; (setq value (get-char-attribute char name)))
857 ;; (if (integerp value)
858 ;; (format "(%-18s . %05d)\t; %c%s"
859 ;; name value (decode-char '=daikanwa value)
861 ;; (format "(%-18s %s)\t; %c%s"
863 ;; (mapconcat (function prin1-to-string)
865 ;; (char-representative-of-daikanwa char)
867 ;; (setq attributes (delq name attributes))))
868 (when (and (memq 'general-category attributes)
869 (setq value (get-char-attribute char 'general-category)))
871 "(general-category\t%s) ; %s%s"
872 (mapconcat (lambda (cell)
875 (cond ((rassoc value unidata-normative-category-alist)
876 "Normative Category")
877 ((rassoc value unidata-informative-category-alist)
878 "Informative Category")
882 (setq attributes (delq 'general-category attributes))
884 (when (and (memq 'bidi-category attributes)
885 (setq value (get-char-attribute char 'bidi-category)))
886 (insert (format "(bidi-category\t. %S)%s"
889 (setq attributes (delq 'bidi-category attributes))
891 (unless (or (not (memq 'mirrored attributes))
892 (eq (setq value (get-char-attribute char 'mirrored 'empty))
894 (insert (format "(mirrored\t\t. %S)%s"
897 (setq attributes (delq 'mirrored attributes))
900 ((and (memq 'decimal-digit-value attributes)
901 (setq value (get-char-attribute char 'decimal-digit-value)))
902 (insert (format "(decimal-digit-value . %S)%s"
905 (setq attributes (delq 'decimal-digit-value attributes))
906 (when (and (memq 'digit-value attributes)
907 (setq value (get-char-attribute char 'digit-value)))
908 (insert (format "(digit-value\t . %S)%s"
911 (setq attributes (delq 'digit-value attributes))
913 (when (and (memq 'numeric-value attributes)
914 (setq value (get-char-attribute char 'numeric-value)))
915 (insert (format "(numeric-value\t . %S)%s"
918 (setq attributes (delq 'numeric-value attributes))
922 (when (and (memq 'digit-value attributes)
923 (setq value (get-char-attribute char 'digit-value)))
924 (insert (format "(digit-value\t. %S)%s"
927 (setq attributes (delq 'digit-value attributes))
929 (when (and (memq 'numeric-value attributes)
930 (setq value (get-char-attribute char 'numeric-value)))
931 (insert (format "(numeric-value\t. %S)%s"
934 (setq attributes (delq 'numeric-value attributes))
936 (when (and (memq 'iso-10646-comment attributes)
937 (setq value (get-char-attribute char 'iso-10646-comment)))
938 (insert (format "(iso-10646-comment\t. %S)%s"
941 (setq attributes (delq 'iso-10646-comment attributes))
943 (when (and (memq 'morohashi-daikanwa attributes)
944 (setq value (get-char-attribute char 'morohashi-daikanwa)))
945 (insert (format "(morohashi-daikanwa\t%s)%s"
946 (mapconcat (function prin1-to-string) value " ")
948 (setq attributes (delq 'morohashi-daikanwa attributes))
952 (when (and (memq 'ideographic-radical attributes)
953 (setq value (get-char-attribute char 'ideographic-radical)))
955 (insert (format "(ideographic-radical . %S)\t; %c%s"
957 (ideographic-radical radical)
959 (setq attributes (delq 'ideographic-radical attributes))
961 (when (and (memq 'shuowen-radical attributes)
962 (setq value (get-char-attribute char 'shuowen-radical)))
963 (insert (format "(shuowen-radical\t. %S)\t; %c%s"
965 (shuowen-radical value)
967 (setq attributes (delq 'shuowen-radical attributes))
972 char-db-feature-domains
974 (dolist (feature (char-attribute-list))
975 (setq feature (symbol-name feature))
977 "\\(radical\\|strokes\\)@\\([^@*]+\\)\\(\\*\\|$\\)"
979 (setq domain (intern (match-string 2 feature)))
980 (unless (memq domain dest)
981 (setq dest (cons domain dest)))))
982 (sort dest #'string<))))
983 (setq key (intern (format "%s@%s" 'ideographic-radical domain)))
984 (when (and (memq key attributes)
985 (setq value (get-char-attribute char key)))
987 (insert (format "(%s . %S)\t; %c%s"
990 (ideographic-radical radical)
992 (setq attributes (delq key attributes))
994 (setq key (intern (format "%s@%s" 'ideographic-strokes domain)))
995 (when (and (memq key attributes)
996 (setq value (get-char-attribute char key)))
998 (insert (format "(%s . %S)%s"
1002 (setq attributes (delq key attributes))
1004 (setq key (intern (format "%s@%s" 'total-strokes domain)))
1005 (when (and (memq key attributes)
1006 (setq value (get-char-attribute char key)))
1007 (insert (format "(%s . %S)%s"
1011 (setq attributes (delq key attributes))
1013 (dolist (feature '(ideographic-radical
1016 (setq key (intern (format "%s@%s*sources" feature domain)))
1017 (when (and (memq key attributes)
1018 (setq value (get-char-attribute char key)))
1019 (insert (format "(%s%s" key line-breaking))
1020 (dolist (cell value)
1021 (insert (format " %s" cell)))
1023 (insert line-breaking)
1024 (setq attributes (delq key attributes))
1027 (when (and (memq 'ideographic-strokes attributes)
1028 (setq value (get-char-attribute char 'ideographic-strokes)))
1029 (setq strokes value)
1030 (insert (format "(ideographic-strokes . %S)%s"
1033 (setq attributes (delq 'ideographic-strokes attributes))
1035 (when (and (memq 'kangxi-radical attributes)
1036 (setq value (get-char-attribute char 'kangxi-radical)))
1037 (unless (eq value radical)
1038 (insert (format "(kangxi-radical\t . %S)\t; %c%s"
1040 (ideographic-radical value)
1043 (setq radical value)))
1044 (setq attributes (delq 'kangxi-radical attributes))
1046 (when (and (memq 'kangxi-strokes attributes)
1047 (setq value (get-char-attribute char 'kangxi-strokes)))
1048 (unless (eq value strokes)
1049 (insert (format "(kangxi-strokes\t . %S)%s"
1053 (setq strokes value)))
1054 (setq attributes (delq 'kangxi-strokes attributes))
1056 (when (and (memq 'japanese-radical attributes)
1057 (setq value (get-char-attribute char 'japanese-radical)))
1058 (unless (eq value radical)
1059 (insert (format "(japanese-radical\t . %S)\t; %c%s"
1061 (ideographic-radical value)
1064 (setq radical value)))
1065 (setq attributes (delq 'japanese-radical attributes))
1067 (when (and (memq 'japanese-strokes attributes)
1068 (setq value (get-char-attribute char 'japanese-strokes)))
1069 (unless (eq value strokes)
1070 (insert (format "(japanese-strokes\t . %S)%s"
1074 (setq strokes value)))
1075 (setq attributes (delq 'japanese-strokes attributes))
1077 (when (and (memq 'cns-radical attributes)
1078 (setq value (get-char-attribute char 'cns-radical)))
1079 (insert (format "(cns-radical\t . %S)\t; %c%s"
1081 (ideographic-radical value)
1083 (setq attributes (delq 'cns-radical attributes))
1085 (when (and (memq 'cns-strokes attributes)
1086 (setq value (get-char-attribute char 'cns-strokes)))
1087 (unless (eq value strokes)
1088 (insert (format "(cns-strokes\t . %S)%s"
1092 (setq strokes value)))
1093 (setq attributes (delq 'cns-strokes attributes))
1095 ;; (when (and (memq 'shinjigen-1-radical attributes)
1096 ;; (setq value (get-char-attribute char 'shinjigen-1-radical)))
1097 ;; (unless (eq value radical)
1098 ;; (insert (format "(shinjigen-1-radical . %S)\t; %c%s"
1100 ;; (ideographic-radical value)
1103 ;; (setq radical value)))
1104 ;; (setq attributes (delq 'shinjigen-1-radical attributes))
1106 (when (and (memq 'ideographic- attributes)
1107 (setq value (get-char-attribute char 'ideographic-)))
1108 (insert "(ideographic- ")
1109 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1111 (while (consp value)
1112 (setq cell (car value))
1114 (setq cell (decode-char '=ucs cell)))
1115 (cond ((characterp cell)
1119 (insert (format "%S" cell))
1120 (char-db-insert-char-spec cell readable))
1121 (setq separator lbs))
1125 (if (consp (car cell))
1126 (char-db-insert-char-spec cell readable)
1127 (char-db-insert-char-reference cell readable))
1128 (setq separator lbs))
1132 (insert (prin1-to-string cell))
1133 (setq separator " ")))
1134 (setq value (cdr value)))
1136 (insert line-breaking)
1137 (setq attributes (delq 'ideographic- attributes)))
1138 (when (and (memq 'total-strokes attributes)
1139 (setq value (get-char-attribute char 'total-strokes)))
1140 (insert (format "(total-strokes . %S)%s"
1143 (setq attributes (delq 'total-strokes attributes))
1145 (when (and (memq '->ideograph attributes)
1146 (setq value (get-char-attribute char '->ideograph)))
1147 (insert (format "(->ideograph\t%s)%s"
1148 (mapconcat (lambda (code)
1149 (cond ((symbolp code)
1152 (format "#x%04X" code))
1155 line-breaking code))))
1158 (setq attributes (delq '->ideograph attributes))
1160 ;; (when (and (memq '->decomposition attributes)
1161 ;; (setq value (get-char-attribute char '->decomposition)))
1162 ;; (insert (format "(->decomposition\t%s)%s"
1163 ;; (mapconcat (lambda (code)
1164 ;; (cond ((symbolp code)
1165 ;; (symbol-name code))
1166 ;; ((characterp code)
1168 ;; (format "%S" code)
1173 ;; (format "#x%04X" code))
1175 ;; (format "%s%S" line-breaking code))))
1178 ;; (setq attributes (delq '->decomposition attributes))
1180 (if (equal (get-char-attribute char '->titlecase)
1181 (get-char-attribute char '->uppercase))
1182 (setq attributes (delq '->titlecase attributes)))
1183 (when (and (memq '->mojikyo attributes)
1184 (setq value (get-char-attribute char '->mojikyo)))
1185 (insert (format "(->mojikyo\t\t. %06d)\t; %c%s"
1186 value (decode-char 'mojikyo value)
1188 (setq attributes (delq '->mojikyo attributes))
1190 (when (and (memq 'hanyu-dazidian-vol attributes)
1191 (setq value (get-char-attribute char 'hanyu-dazidian-vol)))
1192 (insert (format "(hanyu-dazidian-vol . %d)%s"
1193 value line-breaking))
1194 (setq attributes (delq 'hanyu-dazidian-vol attributes))
1196 (when (and (memq 'hanyu-dazidian-page attributes)
1197 (setq value (get-char-attribute char 'hanyu-dazidian-page)))
1198 (insert (format "(hanyu-dazidian-page . %d)%s"
1199 value line-breaking))
1200 (setq attributes (delq 'hanyu-dazidian-page attributes))
1202 (when (and (memq 'hanyu-dazidian-char attributes)
1203 (setq value (get-char-attribute char 'hanyu-dazidian-char)))
1204 (insert (format "(hanyu-dazidian-char . %d)%s"
1205 value line-breaking))
1206 (setq attributes (delq 'hanyu-dazidian-char attributes))
1209 (dolist (ignored '(composition
1210 ->denotational <-subsumptive ->ucs-unified
1211 ->ideographic-component-forms))
1212 (setq attributes (delq ignored attributes))))
1214 (setq name (car attributes))
1215 (unless (eq (setq value (get-char-attribute char name 'value-is-empty))
1217 (cond ((setq ret (find-charset name))
1218 (setq name (charset-name ret))
1219 (when (not (memq name dest-ccss))
1220 (setq dest-ccss (cons name dest-ccss))
1221 (char-db-insert-ccs-feature name value line-breaking))
1223 ((string-match "^=>ucs@" (symbol-name name))
1224 (insert (format "(%-18s . #x%04X)\t; %c%s"
1225 name value (decode-char '=ucs value)
1228 ((eq name 'jisx0208-1978/4X)
1229 (insert (format "(%-18s . #x%04X)%s"
1235 (not (eq name '->subsumptive))
1236 (not (eq name '->uppercase))
1237 (not (eq name '->lowercase))
1238 (not (eq name '->titlecase))
1239 (not (eq name '->canonical))
1240 (not (eq name '->Bopomofo))
1241 (not (eq name '->mistakable))
1242 (not (eq name '->ideographic-variants))
1243 (null (get-char-attribute
1244 char (intern (format "%s*sources" name))))
1245 (not (string-match "\\*sources$" (symbol-name name)))
1246 (null (get-char-attribute
1247 char (intern (format "%s*note" name))))
1248 (not (string-match "\\*note$" (symbol-name name)))
1249 (or (eq name '<-identical)
1250 (eq name '<-uppercase)
1251 (eq name '<-lowercase)
1252 (eq name '<-titlecase)
1253 (eq name '<-canonical)
1254 (eq name '<-ideographic-variants)
1255 ;; (eq name '<-synonyms)
1256 (string-match "^<-synonyms" (symbol-name name))
1257 (eq name '<-mistakable)
1258 (when (string-match "^->" (symbol-name name))
1260 ((string-match "^->fullwidth" (symbol-name name))
1261 (not (and (consp value)
1262 (characterp (car value))
1264 (car value) '=ucs 'defined-only)))
1269 ((or (eq name 'ideographic-structure)
1270 (eq name 'ideographic-combination)
1271 (eq name 'ideographic-)
1272 (eq name '=decomposition)
1273 (char-feature-base-name= '=decomposition name)
1274 (char-feature-base-name= '=>decomposition name)
1275 ;; (string-match "^=>*decomposition\\(@[^*]+\\)?$"
1276 ;; (symbol-name name))
1277 (string-match "^\\(->\\|<-\\)[^*]*$" (symbol-name name))
1278 (string-match "^\\(->\\|<-\\)[^*]*\\*sources$"
1281 (char-db-insert-relation-feature char name value
1284 ((memq name '(ideograph=
1285 original-ideograph-of
1286 ancient-ideograph-of
1289 ;; simplified-ideograph-of
1290 ideographic-variants
1291 ;; ideographic-different-form-of
1293 (insert (format "(%-18s%s " name line-breaking))
1294 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1296 (while (consp value)
1297 (setq cell (car value))
1298 (if (and (consp cell)
1303 (char-db-insert-alist cell readable)
1304 (setq separator lbs))
1307 (insert (prin1-to-string cell))
1308 (setq separator " "))
1309 (setq value (cdr value)))
1311 (insert line-breaking))
1313 (insert (format "(%-18s " name))
1314 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1316 (while (consp value)
1317 (setq cell (car value))
1318 (if (and (consp cell)
1320 (setq ret (condition-case nil
1328 (setq key (car (car rest)))
1329 (if (find-charset key)
1330 (setq cal (cons key cal))
1331 (setq al (cons key al)))
1332 (setq rest (cdr rest)))
1335 (insert-char-attributes ret
1339 (setq separator lbs))
1340 (setq ret (prin1-to-string cell))
1342 (if (< (+ (current-column)
1349 (setq separator " "))
1350 (setq value (cdr value)))
1352 (insert line-breaking))
1354 (insert (format "(%-18s" name))
1355 (setq ret (prin1-to-string value))
1356 (unless (< (+ (current-column)
1360 (insert line-breaking))
1361 (insert " . " ret ")" line-breaking)
1362 ;; (insert (format "(%-18s . %S)%s"
1367 (setq attributes (cdr attributes)))
1370 (defun insert-char-data (char &optional readable
1373 (narrow-to-region (point)(point))
1374 (insert "(define-char
1376 (insert-char-attributes char readable attributes)
1378 (goto-char (point-min))
1379 (while (re-search-forward "[ \t]+$" nil t)
1382 (goto-char (point-min))
1383 (while (re-search-forward "[ \t][ \t][ \t]*" nil t)
1384 (let ((column (current-column))
1385 (indent-tabs-mode t))
1386 (delete-region (match-beginning 0) (point))
1387 (indent-to column)))
1388 (goto-char (point-max))
1389 ;; (tabify (point-min)(point-max))
1392 (defun insert-char-data-with-variant (char &optional printable
1394 script excluded-script)
1395 (insert-char-data char printable)
1396 (let ((variants (char-variants char))
1399 (setq variants (sort variants #'<))
1400 (setq rest variants)
1401 (setq variants (cons char variants))
1403 (setq variant (car rest))
1404 (unless (get-char-attribute variant '<-subsumptive)
1405 (if (and (or (null script)
1406 (null (setq vs (get-char-attribute variant 'script)))
1408 (or (null excluded-script)
1409 (null (setq vs (get-char-attribute variant 'script)))
1410 (not (memq excluded-script vs))))
1411 (unless (and no-ucs-unified (get-char-attribute variant '=ucs))
1412 (insert-char-data variant printable)
1413 (if (setq ret (char-variants variant))
1415 (or (memq (car ret) variants)
1416 ;; (get-char-attribute (car ret) '<-subsumptive)
1417 (setq rest (nconc rest (list (car ret)))))
1418 (setq ret (cdr ret)))))))
1419 (setq rest (cdr rest)))))
1421 (defun insert-char-range-data (min max &optional script excluded-script)
1424 (while (<= code max)
1425 (setq char (decode-char '=ucs code))
1426 (if (encode-char char '=ucs 'defined-only)
1427 (insert-char-data-with-variant char nil 'no-ucs-unified
1428 script excluded-script))
1429 (setq code (1+ code)))))
1431 (defun write-char-range-data-to-file (min max file
1432 &optional script excluded-script)
1433 (let ((coding-system-for-write char-db-file-coding-system))
1435 (insert (format ";; -*- coding: %s -*-\n"
1436 char-db-file-coding-system))
1437 (insert-char-range-data min max script excluded-script)
1438 (write-region (point-min)(point-max) file))))
1440 (defvar what-character-original-window-configuration)
1443 (defun what-char-definition (char)
1444 (interactive (list (char-after)))
1445 (let ((buf (get-buffer-create "*Character Description*"))
1446 (the-buf (current-buffer))
1447 (win-conf (current-window-configuration)))
1449 (make-local-variable 'what-character-original-window-configuration)
1450 (setq what-character-original-window-configuration win-conf)
1451 (setq buffer-read-only nil)
1455 (insert-char-data-with-variant char 'printable)
1456 (unless (char-attribute-alist char)
1457 (insert (format ";; = %c\n"
1458 (let* ((rest (split-char char))
1462 (setq code (logior (lsh code 8)
1464 (decode-char ccs code)))))
1465 ;; (char-db-update-comment)
1466 (set-buffer-modified-p nil)
1467 (view-mode the-buf (lambda (buf)
1468 (set-window-configuration
1469 what-character-original-window-configuration)
1471 (goto-char (point-min)))
1473 (set-window-configuration
1474 what-character-original-window-configuration)
1475 (signal (car err) (cdr err)))))))
1481 (provide 'char-db-util)
1483 ;;; char-db-util.el ends here