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
197 ;; =>>>adobe-japan1-0
198 ;; =>>>adobe-japan1-1
199 ;; =>>>adobe-japan1-2
200 ;; =>>>adobe-japan1-3
201 ;; =>>>adobe-japan1-4
202 ;; =>>>adobe-japan1-5
203 ;; =>>>adobe-japan1-6
207 ;; =>>>hanyo-denshi/ja
208 ;; =>>>hanyo-denshi/jb
209 ;; =>>>hanyo-denshi/jc
210 ;; =>>>hanyo-denshi/ft
211 ;; =>>>hanyo-denshi/ib
212 ;; =>>>hanyo-denshi/hg
213 ;; =>>>hanyo-denshi/jt
214 ;; =>>>hanyo-denshi/ks
304 ;;; @ char-db formatters
307 (defun char-db-make-char-spec (char)
309 (cond ((characterp char)
310 (cond ((and (setq ret (encode-char char '=ucs 'defined-only))
311 (not (and (<= #xE000 ret)(<= ret #xF8FF))))
312 (setq char-spec (list (cons '=ucs ret)))
313 (cond ((setq ret (get-char-attribute char 'name))
314 (setq char-spec (cons (cons 'name ret) char-spec))
316 ((setq ret (get-char-attribute char 'name*))
317 (setq char-spec (cons (cons 'name* ret) char-spec))
320 ((encode-char char '=adobe-japan1 'defined-only)
322 (dolist (ccs (charset-list))
323 (if (and (or (memq ccs
332 ;; (eq (charset-property ccs 'iso-ir) 177)
333 (string-match "=ucs@" (symbol-name ccs))
335 (setq ccs (charset-name ccs))
336 (null (assq ccs char-spec))
337 (setq ret (encode-char char ccs 'defined-only)))
338 (setq char-spec (cons (cons ccs ret) char-spec))))
340 ((encode-char char '==adobe-japan1 'defined-only)
342 (dolist (ccs (charset-list))
343 (if (and (or (memq ccs
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))))
362 (let ((rest char-db-coded-charset-priority-list)
365 (setq ccs (charset-name
366 (find-charset (car rest))))
368 (encode-char char ccs
370 (throw 'tag (cons ccs ret)))
371 (setq rest (cdr rest))))))
372 (setq char-spec (list ret))
373 (dolist (ccs (delq (car ret) (charset-list)))
374 (if (and (or (charset-iso-final-char ccs)
381 (eq (charset-property ccs 'iso-ir) 177)
382 ;; (string-match "=ucs@" (symbol-name ccs))
384 (setq ccs (charset-name ccs))
385 (null (assq ccs char-spec))
386 (setq ret (encode-char char ccs 'defined-only)))
387 (setq char-spec (cons (cons ccs ret) char-spec))))
389 (setq char-spec (split-char char)))
390 (cond ((setq ret (get-char-attribute char 'name))
391 (setq char-spec (cons (cons 'name ret) char-spec))
393 ((setq ret (get-char-attribute char 'name*))
394 (setq char-spec (cons (cons 'name* ret) char-spec))
397 ((setq ret (get-char-attribute
398 char 'ideographic-combination))
400 (cons (cons 'ideographic-combination ret)
407 (defun char-db-insert-char-spec (char &optional readable column
410 (setq column (current-column)))
411 (let (char-spec temp-char)
412 (setq char-spec (char-db-make-char-spec char))
413 (unless (or (characterp char) ; char
415 (setq char (find-char char-spec))
417 ;; define temporary character
418 ;; Current implementation is dirty.
419 (setq temp-char (define-char (cons '(ideograph-daikanwa . 0)
421 (remove-char-attribute temp-char 'ideograph-daikanwa)
422 (setq char temp-char))
423 (insert-char-attributes char
425 (union (mapcar #'car char-spec)
429 ;; undefine temporary character
430 ;; Current implementation is dirty.
431 (setq char-spec (char-attribute-alist temp-char))
433 (remove-char-attribute temp-char (car (car char-spec)))
434 (setq char-spec (cdr char-spec))))))
436 (defun char-db-insert-alist (alist &optional readable column)
438 (setq column (current-column)))
440 (concat "\n" (make-string (1+ column) ?\ )))
444 lbs cell rest separator)
447 (setq name (car (car alist))
448 value (cdr (car alist)))
449 (cond ((eq name 'char)
451 (if (setq ret (condition-case nil
459 (setq key (car (car value)))
460 ;; (if (find-charset key)
461 ;; (setq cal (cons key cal))
462 (setq al (cons key al))
464 (setq value (cdr value)))
465 (insert-char-attributes ret
469 (insert (prin1-to-string value)))
471 (insert line-breaking))
473 (insert (format "(%-18s " name))
474 (setq lbs (concat "\n" (make-string (current-column) ?\ )))
476 (setq cell (car value))
477 (if (and (consp cell)
479 (setq ret (condition-case nil
489 (setq key (car (car rest)))
490 ;; (if (find-charset key)
491 ;; (setq cal (cons key cal))
492 (setq al (cons key al))
494 (setq rest (cdr rest)))
497 (insert-char-attributes ret
501 (setq separator lbs))
504 (insert (prin1-to-string cell))
505 (setq separator " "))
506 (setq value (cdr value)))
508 (insert line-breaking))
510 (insert (format "(%-18s . %S)%s"
513 (setq alist (cdr alist))))
516 (defun char-db-insert-char-reference (plist &optional readable column)
518 (setq column (current-column)))
520 (concat "\n" (make-string (1+ column) ?\ )))
525 (setq name (pop plist))
526 (setq value (pop plist))
527 (cond ((eq name :char)
530 (cond ((numberp value)
531 (setq value (decode-char '=ucs value)))
533 ;; (setq value (or (find-char value)
536 (char-db-insert-char-spec value readable)
537 (insert line-breaking)
540 (insert (format "%s%s\t%d ; %c%s"
543 (ideographic-radical value)
547 (insert (format "%s%s\t%S" separator name value))
548 (setq separator line-breaking)))
552 (defun char-db-decode-isolated-char (ccs code-point)
555 (cond ((eq ccs 'arabic-iso8859-6)
556 (decode-char ccs code-point))
558 ;; (decode-builtin-char '==gt code-point))
559 ((and (memq ccs '(=gt-pj-1
570 (setq ret (decode-char ccs code-point))
571 (setq ret (encode-char ret '=gt 'defined-only)))
572 (decode-builtin-char '=gt ret))
574 (decode-builtin-char ccs code-point))))
575 (cond ((and (<= 0 (char-int ret))
576 (<= (char-int ret) #x1F))
577 (decode-char '=ucs (+ #x2400 (char-int ret))))
578 ((= (char-int ret) #x7F)
582 (defvar char-db-convert-obsolete-format t)
584 (defun char-db-insert-ccs-feature (name value line-breaking)
590 ((memq name '(==shinjigen
593 =shinjigen@rev =shinjigen/+p@rev
594 =daikanwa/ho =>>daikanwa/ho =>daikanwa/ho))
595 "(%-18s . %04d)\t; %c")
596 ((eq name '=shinjigen@1ed/24pr)
597 "(%-18s . %04d)\t; %c")
598 ((or (memq name '(==daikanwa
599 =daikanwa =>>daikanwa =>daikanwa
600 =daikanwa@rev1 =daikanwa@rev2
601 =daikanwa/+p =>>daikanwa/+p
602 =daikanwa/+2p =>>daikanwa/+2p
605 =gt-k ==gt-k =>>gt-k =>gt-k
606 =adobe-japan1-0 ==adobe-japan1-0 ; =>>>adobe-japan1-0
607 =adobe-japan1-1 ==adobe-japan1-1 ; =>>>adobe-japan1-1
608 =adobe-japan1-2 ==adobe-japan1-2 ; =>>>adobe-japan1-2
609 =adobe-japan1-3 ==adobe-japan1-3 ; =>>>adobe-japan1-3
610 =adobe-japan1-4 ==adobe-japan1-4 ; =>>>adobe-japan1-4
611 =adobe-japan1-5 ==adobe-japan1-5 ; =>>>adobe-japan1-5
612 =adobe-japan1-6 ==adobe-japan1-6 ; =>>>adobe-japan1-6
613 =>>adobe-japan1-0 =+>adobe-japan1-0
614 =>>adobe-japan1-1 =+>adobe-japan1-1
615 =>>adobe-japan1-2 =+>adobe-japan1-2
616 =>>adobe-japan1-3 =+>adobe-japan1-3
617 =>>adobe-japan1-4 =+>adobe-japan1-4
618 =>>adobe-japan1-5 =+>adobe-japan1-5
619 =>>adobe-japan1-6 =+>adobe-japan1-6
621 =zinbun-oracle =>zinbun-oracle))
622 ;; (string-match "^=adobe-" (symbol-name name))
624 "(%-18s . %05d)\t; %c")
625 ((memq name '(=hanyo-denshi/ks
626 ==hanyo-denshi/ks ; =>>>hanyo-denshi/ks
629 "(%-18s . %06d)\t; %c")
630 ((>= (charset-dimension name) 2)
631 "(%-18s . #x%04X)\t; %c")
633 "(%-18s . #x%02X)\t; %c"))
635 (if (= (charset-iso-graphic-plane name) 1)
637 (cond ((= (charset-dimension name) 1)
639 ((= (charset-dimension name) 2)
641 ((= (charset-dimension name) 3)
645 (char-db-decode-isolated-char name value)))
646 (if (and (= (charset-chars name) 94)
647 (= (charset-dimension name) 2))
648 (insert (format " [%02d-%02d]"
649 (- (lsh value -8) 32)
650 (- (logand value 255) 32))))
653 (insert (format "(%-18s . %s)" name value))
655 (insert line-breaking))
657 (defun char-db-insert-relation-feature (char name value line-breaking
659 (insert (format "(%-18s%s " name line-breaking))
660 (let ((lbs (concat "\n" (make-string (current-column) ?\ )))
661 separator cell sources required-features
664 (setq cell (car value))
666 (setq cell (decode-char '=ucs cell)))
668 ((eq name '->subsumptive)
669 (when (or (not (some (lambda (atr)
670 (get-char-attribute cell atr))
671 char-db-ignored-attributes))
673 (encode-char cell ccs 'defined-only))
677 (let ((char-db-ignored-attributes
679 char-db-ignored-attributes)))
680 (insert-char-attributes cell readable nil nil 'for-sub-node))
681 (setq separator lbs))
686 char (intern (format "%s*sources" name))))
687 (setq required-features nil)
688 (dolist (source sources)
692 shinjigen shinjigen@1ed shinjigen@rev))
693 (setq required-features
694 (union required-features
706 =shinjigen/+p@rev))))
708 (setq required-features
709 (union required-features
714 ((find-charset (setq ret (intern (format "=%s" source))))
715 (setq required-features
716 (cons ret required-features)))
717 (t (setq required-features
718 (cons source required-features)))))
719 (cond ((string-match "@JP" (symbol-name name))
720 (setq required-features
721 (union required-features
729 ((string-match "@CN" (symbol-name name))
730 (setq required-features
731 (union required-features
738 (insert (format "%S" cell))
739 (char-db-insert-char-spec cell readable
742 (setq separator lbs))
746 (if (consp (car cell))
747 (char-db-insert-char-spec cell readable)
748 (char-db-insert-char-reference cell readable))
749 (setq separator lbs))
753 (insert (prin1-to-string cell))
754 (setq separator " ")))
755 (setq value (cdr value)))
757 (insert line-breaking)))
759 (defun insert-char-attributes (char &optional readable attributes column
762 (setq column (current-column)))
763 (let (name value ; has-long-ccs-name
767 (concat "\n" (make-string (1+ column) ?\ )))
768 lbs cell separator ret
770 dest-ccss ; sources required-features
775 (if (consp attributes)
777 (dolist (name attributes)
778 (unless (memq name char-db-ignored-attributes)
779 (if (find-charset name)
783 (dolist (name (char-attribute-list))
784 (unless (memq name char-db-ignored-attributes)
785 (if (find-charset name)
789 #'char-attribute-name<)))
791 (when (memq '<-subsumptive attributes)
792 (when (or readable (not for-sub-node))
793 (when (setq value (get-char-attribute char '<-subsumptive))
794 (char-db-insert-relation-feature char '<-subsumptive value
797 (setq attributes (delq '<-subsumptive attributes)))
798 (when (and (memq '<-denotational attributes)
799 (setq value (get-char-attribute char '<-denotational)))
800 (char-db-insert-relation-feature char '<-denotational value
803 (setq attributes (delq '<-denotational attributes)))
804 (when (and (memq 'name attributes)
805 (setq value (get-char-attribute char 'name)))
807 (if (> (+ (current-column) (length value)) 48)
810 value line-breaking))
811 (setq attributes (delq 'name attributes))
813 (when (and (memq 'name* attributes)
814 (setq value (get-char-attribute char 'name*)))
816 (if (> (+ (current-column) (length value)) 48)
819 value line-breaking))
820 (setq attributes (delq 'name* attributes))
822 (when (and (memq 'script attributes)
823 (setq value (get-char-attribute char 'script)))
824 (insert (format "(script\t\t%s)%s"
825 (mapconcat (function prin1-to-string)
828 (setq attributes (delq 'script attributes))
830 (dolist (name '(=>ucs =>ucs*))
831 (when (and (memq name attributes)
832 (setq value (get-char-attribute char name)))
833 (insert (format "(%-18s . #x%04X)\t; %c%s"
834 name value (decode-char '=ucs value)
836 (setq attributes (delq name attributes))))
837 (dolist (name '(=>ucs@gb =>ucs@big5))
838 (when (and (memq name attributes)
839 (setq value (get-char-attribute char name)))
840 (insert (format "(%-18s . #x%04X)\t; %c%s"
845 (symbol-name name) 2)))
848 (setq attributes (delq name attributes))
850 ;; (dolist (name '(=>daikanwa))
851 ;; (when (and (memq name attributes)
852 ;; (setq value (get-char-attribute char name)))
854 ;; (if (integerp value)
855 ;; (format "(%-18s . %05d)\t; %c%s"
856 ;; name value (decode-char '=daikanwa value)
858 ;; (format "(%-18s %s)\t; %c%s"
860 ;; (mapconcat (function prin1-to-string)
862 ;; (char-representative-of-daikanwa char)
864 ;; (setq attributes (delq name attributes))))
865 (when (and (memq 'general-category attributes)
866 (setq value (get-char-attribute char 'general-category)))
868 "(general-category\t%s) ; %s%s"
869 (mapconcat (lambda (cell)
872 (cond ((rassoc value unidata-normative-category-alist)
873 "Normative Category")
874 ((rassoc value unidata-informative-category-alist)
875 "Informative Category")
879 (setq attributes (delq 'general-category attributes))
881 (when (and (memq 'bidi-category attributes)
882 (setq value (get-char-attribute char 'bidi-category)))
883 (insert (format "(bidi-category\t. %S)%s"
886 (setq attributes (delq 'bidi-category attributes))
888 (unless (or (not (memq 'mirrored attributes))
889 (eq (setq value (get-char-attribute char 'mirrored 'empty))
891 (insert (format "(mirrored\t\t. %S)%s"
894 (setq attributes (delq 'mirrored attributes))
897 ((and (memq 'decimal-digit-value attributes)
898 (setq value (get-char-attribute char 'decimal-digit-value)))
899 (insert (format "(decimal-digit-value . %S)%s"
902 (setq attributes (delq 'decimal-digit-value attributes))
903 (when (and (memq 'digit-value attributes)
904 (setq value (get-char-attribute char 'digit-value)))
905 (insert (format "(digit-value\t . %S)%s"
908 (setq attributes (delq 'digit-value attributes))
910 (when (and (memq 'numeric-value attributes)
911 (setq value (get-char-attribute char 'numeric-value)))
912 (insert (format "(numeric-value\t . %S)%s"
915 (setq attributes (delq 'numeric-value attributes))
919 (when (and (memq 'digit-value attributes)
920 (setq value (get-char-attribute char 'digit-value)))
921 (insert (format "(digit-value\t. %S)%s"
924 (setq attributes (delq 'digit-value attributes))
926 (when (and (memq 'numeric-value attributes)
927 (setq value (get-char-attribute char 'numeric-value)))
928 (insert (format "(numeric-value\t. %S)%s"
931 (setq attributes (delq 'numeric-value attributes))
933 (when (and (memq 'iso-10646-comment attributes)
934 (setq value (get-char-attribute char 'iso-10646-comment)))
935 (insert (format "(iso-10646-comment\t. %S)%s"
938 (setq attributes (delq 'iso-10646-comment attributes))
940 (when (and (memq 'morohashi-daikanwa attributes)
941 (setq value (get-char-attribute char 'morohashi-daikanwa)))
942 (insert (format "(morohashi-daikanwa\t%s)%s"
943 (mapconcat (function prin1-to-string) value " ")
945 (setq attributes (delq 'morohashi-daikanwa attributes))
949 (when (and (memq 'ideographic-radical attributes)
950 (setq value (get-char-attribute char 'ideographic-radical)))
952 (insert (format "(ideographic-radical . %S)\t; %c%s"
954 (ideographic-radical radical)
956 (setq attributes (delq 'ideographic-radical attributes))
958 (when (and (memq 'shuowen-radical attributes)
959 (setq value (get-char-attribute char 'shuowen-radical)))
960 (insert (format "(shuowen-radical\t. %S)\t; %c%s"
962 (shuowen-radical value)
964 (setq attributes (delq 'shuowen-radical attributes))
969 char-db-feature-domains
971 (dolist (feature (char-attribute-list))
972 (setq feature (symbol-name feature))
974 "\\(radical\\|strokes\\)@\\([^@*]+\\)\\(\\*\\|$\\)"
976 (setq domain (intern (match-string 2 feature)))
977 (unless (memq domain dest)
978 (setq dest (cons domain dest)))))
979 (sort dest #'string<))))
980 (setq key (intern (format "%s@%s" 'ideographic-radical domain)))
981 (when (and (memq key attributes)
982 (setq value (get-char-attribute char key)))
984 (insert (format "(%s . %S)\t; %c%s"
987 (ideographic-radical radical)
989 (setq attributes (delq key attributes))
991 (setq key (intern (format "%s@%s" 'ideographic-strokes domain)))
992 (when (and (memq key attributes)
993 (setq value (get-char-attribute char key)))
995 (insert (format "(%s . %S)%s"
999 (setq attributes (delq key attributes))
1001 (setq key (intern (format "%s@%s" 'total-strokes domain)))
1002 (when (and (memq key attributes)
1003 (setq value (get-char-attribute char key)))
1004 (insert (format "(%s . %S)%s"
1008 (setq attributes (delq key attributes))
1010 (dolist (feature '(ideographic-radical
1013 (setq key (intern (format "%s@%s*sources" feature domain)))
1014 (when (and (memq key attributes)
1015 (setq value (get-char-attribute char key)))
1016 (insert (format "(%s%s" key line-breaking))
1017 (dolist (cell value)
1018 (insert (format " %s" cell)))
1020 (insert line-breaking)
1021 (setq attributes (delq key attributes))
1024 (when (and (memq 'ideographic-strokes attributes)
1025 (setq value (get-char-attribute char 'ideographic-strokes)))
1026 (setq strokes value)
1027 (insert (format "(ideographic-strokes . %S)%s"
1030 (setq attributes (delq 'ideographic-strokes attributes))
1032 (when (and (memq 'kangxi-radical attributes)
1033 (setq value (get-char-attribute char 'kangxi-radical)))
1034 (unless (eq value radical)
1035 (insert (format "(kangxi-radical\t . %S)\t; %c%s"
1037 (ideographic-radical value)
1040 (setq radical value)))
1041 (setq attributes (delq 'kangxi-radical attributes))
1043 (when (and (memq 'kangxi-strokes attributes)
1044 (setq value (get-char-attribute char 'kangxi-strokes)))
1045 (unless (eq value strokes)
1046 (insert (format "(kangxi-strokes\t . %S)%s"
1050 (setq strokes value)))
1051 (setq attributes (delq 'kangxi-strokes attributes))
1053 (when (and (memq 'japanese-radical attributes)
1054 (setq value (get-char-attribute char 'japanese-radical)))
1055 (unless (eq value radical)
1056 (insert (format "(japanese-radical\t . %S)\t; %c%s"
1058 (ideographic-radical value)
1061 (setq radical value)))
1062 (setq attributes (delq 'japanese-radical attributes))
1064 (when (and (memq 'japanese-strokes attributes)
1065 (setq value (get-char-attribute char 'japanese-strokes)))
1066 (unless (eq value strokes)
1067 (insert (format "(japanese-strokes\t . %S)%s"
1071 (setq strokes value)))
1072 (setq attributes (delq 'japanese-strokes attributes))
1074 (when (and (memq 'cns-radical attributes)
1075 (setq value (get-char-attribute char 'cns-radical)))
1076 (insert (format "(cns-radical\t . %S)\t; %c%s"
1078 (ideographic-radical value)
1080 (setq attributes (delq 'cns-radical attributes))
1082 (when (and (memq 'cns-strokes attributes)
1083 (setq value (get-char-attribute char 'cns-strokes)))
1084 (unless (eq value strokes)
1085 (insert (format "(cns-strokes\t . %S)%s"
1089 (setq strokes value)))
1090 (setq attributes (delq 'cns-strokes attributes))
1092 ;; (when (and (memq 'shinjigen-1-radical attributes)
1093 ;; (setq value (get-char-attribute char 'shinjigen-1-radical)))
1094 ;; (unless (eq value radical)
1095 ;; (insert (format "(shinjigen-1-radical . %S)\t; %c%s"
1097 ;; (ideographic-radical value)
1100 ;; (setq radical value)))
1101 ;; (setq attributes (delq 'shinjigen-1-radical attributes))
1103 (when (and (memq 'ideographic- attributes)
1104 (setq value (get-char-attribute char 'ideographic-)))
1105 (insert "(ideographic- ")
1106 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1108 (while (consp value)
1109 (setq cell (car value))
1111 (setq cell (decode-char '=ucs cell)))
1112 (cond ((characterp cell)
1116 (insert (format "%S" cell))
1117 (char-db-insert-char-spec cell readable))
1118 (setq separator lbs))
1122 (if (consp (car cell))
1123 (char-db-insert-char-spec cell readable)
1124 (char-db-insert-char-reference cell readable))
1125 (setq separator lbs))
1129 (insert (prin1-to-string cell))
1130 (setq separator " ")))
1131 (setq value (cdr value)))
1133 (insert line-breaking)
1134 (setq attributes (delq 'ideographic- attributes)))
1135 (when (and (memq 'total-strokes attributes)
1136 (setq value (get-char-attribute char 'total-strokes)))
1137 (insert (format "(total-strokes . %S)%s"
1140 (setq attributes (delq 'total-strokes attributes))
1142 (when (and (memq '->ideograph attributes)
1143 (setq value (get-char-attribute char '->ideograph)))
1144 (insert (format "(->ideograph\t%s)%s"
1145 (mapconcat (lambda (code)
1146 (cond ((symbolp code)
1149 (format "#x%04X" code))
1152 line-breaking code))))
1155 (setq attributes (delq '->ideograph attributes))
1157 ;; (when (and (memq '->decomposition attributes)
1158 ;; (setq value (get-char-attribute char '->decomposition)))
1159 ;; (insert (format "(->decomposition\t%s)%s"
1160 ;; (mapconcat (lambda (code)
1161 ;; (cond ((symbolp code)
1162 ;; (symbol-name code))
1163 ;; ((characterp code)
1165 ;; (format "%S" code)
1170 ;; (format "#x%04X" code))
1172 ;; (format "%s%S" line-breaking code))))
1175 ;; (setq attributes (delq '->decomposition attributes))
1177 (if (equal (get-char-attribute char '->titlecase)
1178 (get-char-attribute char '->uppercase))
1179 (setq attributes (delq '->titlecase attributes)))
1180 (when (and (memq '->mojikyo attributes)
1181 (setq value (get-char-attribute char '->mojikyo)))
1182 (insert (format "(->mojikyo\t\t. %06d)\t; %c%s"
1183 value (decode-char 'mojikyo value)
1185 (setq attributes (delq '->mojikyo attributes))
1187 (when (and (memq 'hanyu-dazidian-vol attributes)
1188 (setq value (get-char-attribute char 'hanyu-dazidian-vol)))
1189 (insert (format "(hanyu-dazidian-vol . %d)%s"
1190 value line-breaking))
1191 (setq attributes (delq 'hanyu-dazidian-vol attributes))
1193 (when (and (memq 'hanyu-dazidian-page attributes)
1194 (setq value (get-char-attribute char 'hanyu-dazidian-page)))
1195 (insert (format "(hanyu-dazidian-page . %d)%s"
1196 value line-breaking))
1197 (setq attributes (delq 'hanyu-dazidian-page attributes))
1199 (when (and (memq 'hanyu-dazidian-char attributes)
1200 (setq value (get-char-attribute char 'hanyu-dazidian-char)))
1201 (insert (format "(hanyu-dazidian-char . %d)%s"
1202 value line-breaking))
1203 (setq attributes (delq 'hanyu-dazidian-char attributes))
1206 (dolist (ignored '(composition
1207 ->denotational <-subsumptive ->ucs-unified
1208 ->ideographic-component-forms))
1209 (setq attributes (delq ignored attributes))))
1211 (setq name (car attributes))
1212 (unless (eq (setq value (get-char-attribute char name 'value-is-empty))
1214 (cond ((setq ret (find-charset name))
1215 (setq name (charset-name ret))
1216 (when (not (memq name dest-ccss))
1217 (setq dest-ccss (cons name dest-ccss))
1218 (char-db-insert-ccs-feature name value line-breaking))
1220 ((string-match "^=>ucs@" (symbol-name name))
1221 (insert (format "(%-18s . #x%04X)\t; %c%s"
1222 name value (decode-char '=ucs value)
1225 ((eq name 'jisx0208-1978/4X)
1226 (insert (format "(%-18s . #x%04X)%s"
1232 (not (eq name '->subsumptive))
1233 (not (eq name '->uppercase))
1234 (not (eq name '->lowercase))
1235 (not (eq name '->titlecase))
1236 (not (eq name '->canonical))
1237 (not (eq name '->Bopomofo))
1238 (not (eq name '->mistakable))
1239 (not (eq name '->ideographic-variants))
1240 (null (get-char-attribute
1241 char (intern (format "%s*sources" name))))
1242 (not (string-match "\\*sources$" (symbol-name name)))
1243 (null (get-char-attribute
1244 char (intern (format "%s*note" name))))
1245 (not (string-match "\\*note$" (symbol-name name)))
1246 (or (eq name '<-identical)
1247 (eq name '<-uppercase)
1248 (eq name '<-lowercase)
1249 (eq name '<-titlecase)
1250 (eq name '<-canonical)
1251 (eq name '<-ideographic-variants)
1252 ;; (eq name '<-synonyms)
1253 (string-match "^<-synonyms" (symbol-name name))
1254 (eq name '<-mistakable)
1255 (when (string-match "^->" (symbol-name name))
1257 ((string-match "^->fullwidth" (symbol-name name))
1258 (not (and (consp value)
1259 (characterp (car value))
1261 (car value) '=ucs 'defined-only)))
1266 ((or (eq name 'ideographic-structure)
1267 (eq name 'ideographic-combination)
1268 (eq name 'ideographic-)
1269 (eq name '=decomposition)
1270 (char-feature-base-name= '=decomposition name)
1271 (char-feature-base-name= '=>decomposition name)
1272 ;; (string-match "^=>*decomposition\\(@[^*]+\\)?$"
1273 ;; (symbol-name name))
1274 (string-match "^\\(->\\|<-\\)[^*]*$" (symbol-name name))
1275 (string-match "^\\(->\\|<-\\)[^*]*\\*sources$"
1278 (char-db-insert-relation-feature char name value
1281 ((memq name '(ideograph=
1282 original-ideograph-of
1283 ancient-ideograph-of
1286 ;; simplified-ideograph-of
1287 ideographic-variants
1288 ;; ideographic-different-form-of
1290 (insert (format "(%-18s%s " name line-breaking))
1291 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1293 (while (consp value)
1294 (setq cell (car value))
1295 (if (and (consp cell)
1300 (char-db-insert-alist cell readable)
1301 (setq separator lbs))
1304 (insert (prin1-to-string cell))
1305 (setq separator " "))
1306 (setq value (cdr value)))
1308 (insert line-breaking))
1310 (insert (format "(%-18s " name))
1311 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1313 (while (consp value)
1314 (setq cell (car value))
1315 (if (and (consp cell)
1317 (setq ret (condition-case nil
1325 (setq key (car (car rest)))
1326 (if (find-charset key)
1327 (setq cal (cons key cal))
1328 (setq al (cons key al)))
1329 (setq rest (cdr rest)))
1332 (insert-char-attributes ret
1336 (setq separator lbs))
1337 (setq ret (prin1-to-string cell))
1339 (if (< (+ (current-column)
1346 (setq separator " "))
1347 (setq value (cdr value)))
1349 (insert line-breaking))
1351 (insert (format "(%-18s" name))
1352 (setq ret (prin1-to-string value))
1353 (unless (< (+ (current-column)
1357 (insert line-breaking))
1358 (insert " . " ret ")" line-breaking)
1359 ;; (insert (format "(%-18s . %S)%s"
1364 (setq attributes (cdr attributes)))
1367 (defun insert-char-data (char &optional readable
1370 (narrow-to-region (point)(point))
1371 (insert "(define-char
1373 (insert-char-attributes char readable attributes)
1375 (goto-char (point-min))
1376 (while (re-search-forward "[ \t]+$" nil t)
1379 (goto-char (point-min))
1380 (while (re-search-forward "[ \t][ \t][ \t]*" nil t)
1381 (let ((column (current-column))
1382 (indent-tabs-mode t))
1383 (delete-region (match-beginning 0) (point))
1384 (indent-to column)))
1385 (goto-char (point-max))
1386 ;; (tabify (point-min)(point-max))
1389 (defun insert-char-data-with-variant (char &optional printable
1391 script excluded-script)
1392 (insert-char-data char printable)
1393 (let ((variants (char-variants char))
1396 (setq variants (sort variants #'<))
1397 (setq rest variants)
1398 (setq variants (cons char variants))
1400 (setq variant (car rest))
1401 (unless (get-char-attribute variant '<-subsumptive)
1402 (if (and (or (null script)
1403 (null (setq vs (get-char-attribute variant 'script)))
1405 (or (null excluded-script)
1406 (null (setq vs (get-char-attribute variant 'script)))
1407 (not (memq excluded-script vs))))
1408 (unless (and no-ucs-unified (get-char-attribute variant '=ucs))
1409 (insert-char-data variant printable)
1410 (if (setq ret (char-variants variant))
1412 (or (memq (car ret) variants)
1413 ;; (get-char-attribute (car ret) '<-subsumptive)
1414 (setq rest (nconc rest (list (car ret)))))
1415 (setq ret (cdr ret)))))))
1416 (setq rest (cdr rest)))))
1418 (defun insert-char-range-data (min max &optional script excluded-script)
1421 (while (<= code max)
1422 (setq char (decode-char '=ucs code))
1423 (if (encode-char char '=ucs 'defined-only)
1424 (insert-char-data-with-variant char nil 'no-ucs-unified
1425 script excluded-script))
1426 (setq code (1+ code)))))
1428 (defun write-char-range-data-to-file (min max file
1429 &optional script excluded-script)
1430 (let ((coding-system-for-write char-db-file-coding-system))
1432 (insert (format ";; -*- coding: %s -*-\n"
1433 char-db-file-coding-system))
1434 (insert-char-range-data min max script excluded-script)
1435 (write-region (point-min)(point-max) file))))
1437 (defvar what-character-original-window-configuration)
1440 (defun what-char-definition (char)
1441 (interactive (list (char-after)))
1442 (let ((buf (get-buffer-create "*Character Description*"))
1443 (the-buf (current-buffer))
1444 (win-conf (current-window-configuration)))
1446 (make-local-variable 'what-character-original-window-configuration)
1447 (setq what-character-original-window-configuration win-conf)
1448 (setq buffer-read-only nil)
1452 (insert-char-data-with-variant char 'printable)
1453 (unless (char-attribute-alist char)
1454 (insert (format ";; = %c\n"
1455 (let* ((rest (split-char char))
1459 (setq code (logior (lsh code 8)
1461 (decode-char ccs code)))))
1462 ;; (char-db-update-comment)
1463 (set-buffer-modified-p nil)
1464 (view-mode the-buf (lambda (buf)
1465 (set-window-configuration
1466 what-character-original-window-configuration)
1468 (goto-char (point-min)))
1470 (set-window-configuration
1471 what-character-original-window-configuration)
1472 (signal (car err) (cdr err)))))))
1478 (provide 'char-db-util)
1480 ;;; char-db-util.el ends here