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
201 ;; =>>>adobe-japan1-0
202 ;; =>>>adobe-japan1-1
203 ;; =>>>adobe-japan1-2
204 ;; =>>>adobe-japan1-3
205 ;; =>>>adobe-japan1-4
206 ;; =>>>adobe-japan1-5
207 ;; =>>>adobe-japan1-6
211 ;; =>>>hanyo-denshi/ja
212 ;; =>>>hanyo-denshi/jb
213 ;; =>>>hanyo-denshi/jc
214 ;; =>>>hanyo-denshi/ft
215 ;; =>>>hanyo-denshi/ib
216 ;; =>>>hanyo-denshi/hg
217 ;; =>>>hanyo-denshi/jt
218 ;; =>>>hanyo-denshi/ks
299 ;;; @ char-db formatters
302 (defun char-db-make-char-spec (char)
304 (cond ((characterp char)
305 (cond ((and (setq ret (encode-char char '=ucs 'defined-only))
306 (not (and (<= #xE000 ret)(<= ret #xF8FF))))
307 (setq char-spec (list (cons '=ucs ret)))
308 (cond ((setq ret (get-char-attribute char 'name))
309 (setq char-spec (cons (cons 'name ret) char-spec))
311 ((setq ret (get-char-attribute char 'name*))
312 (setq char-spec (cons (cons 'name* ret) char-spec))
315 ((encode-char char '=adobe-japan1 'defined-only)
317 (dolist (ccs (charset-list))
318 (if (and (or (memq ccs
327 ;; (eq (charset-property ccs 'iso-ir) 177)
328 (string-match "=ucs@" (symbol-name ccs))
330 (setq ccs (charset-name ccs))
331 (null (assq ccs char-spec))
332 (setq ret (encode-char char ccs 'defined-only)))
333 (setq char-spec (cons (cons ccs ret) char-spec))))
335 ((encode-char char '==adobe-japan1 'defined-only)
337 (dolist (ccs (charset-list))
338 (if (and (or (memq ccs
347 ;; (eq (charset-property ccs 'iso-ir) 177)
348 (string-match "=ucs@" (symbol-name ccs))
350 (setq ccs (charset-name ccs))
351 (null (assq ccs char-spec))
352 (setq ret (encode-char char ccs 'defined-only)))
353 (setq char-spec (cons (cons ccs ret) char-spec))))
357 (let ((rest char-db-coded-charset-priority-list)
360 (setq ccs (charset-name
361 (find-charset (car rest))))
363 (encode-char char ccs
365 (throw 'tag (cons ccs ret)))
366 (setq rest (cdr rest))))))
367 (setq char-spec (list ret))
368 (dolist (ccs (delq (car ret) (charset-list)))
369 (if (and (or (charset-iso-final-char ccs)
376 (eq (charset-property ccs 'iso-ir) 177)
377 ;; (string-match "=ucs@" (symbol-name ccs))
379 (setq ccs (charset-name ccs))
380 (null (assq ccs char-spec))
381 (setq ret (encode-char char ccs 'defined-only)))
382 (setq char-spec (cons (cons ccs ret) char-spec))))
384 (setq char-spec (split-char char)))
385 (cond ((setq ret (get-char-attribute char 'name))
386 (setq char-spec (cons (cons 'name ret) char-spec))
388 ((setq ret (get-char-attribute char 'name*))
389 (setq char-spec (cons (cons 'name* ret) char-spec))
392 ((setq ret (get-char-attribute
393 char 'ideographic-combination))
395 (cons (cons 'ideographic-combination ret)
402 (defun char-db-insert-char-spec (char &optional readable column
405 (setq column (current-column)))
406 (let (char-spec temp-char)
407 (setq char-spec (char-db-make-char-spec char))
408 (unless (or (characterp char) ; char
410 (setq char (find-char char-spec))
412 ;; define temporary character
413 ;; Current implementation is dirty.
414 (setq temp-char (define-char (cons '(ideograph-daikanwa . 0)
416 (remove-char-attribute temp-char 'ideograph-daikanwa)
417 (setq char temp-char))
418 (insert-char-attributes char
420 (union (mapcar #'car char-spec)
424 ;; undefine temporary character
425 ;; Current implementation is dirty.
426 (setq char-spec (char-attribute-alist temp-char))
428 (remove-char-attribute temp-char (car (car char-spec)))
429 (setq char-spec (cdr char-spec))))))
431 (defun char-db-insert-alist (alist &optional readable column)
433 (setq column (current-column)))
435 (concat "\n" (make-string (1+ column) ?\ )))
439 lbs cell rest separator)
442 (setq name (car (car alist))
443 value (cdr (car alist)))
444 (cond ((eq name 'char)
446 (if (setq ret (condition-case nil
454 (setq key (car (car value)))
455 ;; (if (find-charset key)
456 ;; (setq cal (cons key cal))
457 (setq al (cons key al))
459 (setq value (cdr value)))
460 (insert-char-attributes ret
464 (insert (prin1-to-string value)))
466 (insert line-breaking))
468 (insert (format "(%-18s " name))
469 (setq lbs (concat "\n" (make-string (current-column) ?\ )))
471 (setq cell (car value))
472 (if (and (consp cell)
474 (setq ret (condition-case nil
484 (setq key (car (car rest)))
485 ;; (if (find-charset key)
486 ;; (setq cal (cons key cal))
487 (setq al (cons key al))
489 (setq rest (cdr rest)))
492 (insert-char-attributes ret
496 (setq separator lbs))
499 (insert (prin1-to-string cell))
500 (setq separator " "))
501 (setq value (cdr value)))
503 (insert line-breaking))
505 (insert (format "(%-18s . %S)%s"
508 (setq alist (cdr alist))))
511 (defun char-db-insert-char-reference (plist &optional readable column)
513 (setq column (current-column)))
515 (concat "\n" (make-string (1+ column) ?\ )))
520 (setq name (pop plist))
521 (setq value (pop plist))
522 (cond ((eq name :char)
525 (cond ((numberp value)
526 (setq value (decode-char '=ucs value)))
528 ;; (setq value (or (find-char value)
531 (char-db-insert-char-spec value readable)
532 (insert line-breaking)
535 (insert (format "%s%s\t%d ; %c%s"
538 (ideographic-radical value)
542 (insert (format "%s%s\t%S" separator name value))
543 (setq separator line-breaking)))
547 (defun char-db-decode-isolated-char (ccs code-point)
550 (cond ((eq ccs 'arabic-iso8859-6)
551 (decode-char ccs code-point))
553 ;; (decode-builtin-char '==gt code-point))
554 ((and (memq ccs '(=gt-pj-1
565 (setq ret (decode-char ccs code-point))
566 (setq ret (encode-char ret '=gt 'defined-only)))
567 (decode-builtin-char '=gt ret))
569 (decode-builtin-char ccs code-point))))
570 (cond ((and (<= 0 (char-int ret))
571 (<= (char-int ret) #x1F))
572 (decode-char '=ucs (+ #x2400 (char-int ret))))
573 ((= (char-int ret) #x7F)
577 (defvar char-db-convert-obsolete-format t)
579 (defun char-db-insert-ccs-feature (name value line-breaking)
585 ((memq name '(==shinjigen
588 =shinjigen@rev =shinjigen/+p@rev
589 =daikanwa/ho =>>daikanwa/ho =>daikanwa/ho))
590 "(%-18s . %04d)\t; %c")
591 ((eq name '=shinjigen@1ed/24pr)
592 "(%-18s . %04d)\t; %c")
593 ((or (memq name '(==daikanwa
594 =daikanwa =>>daikanwa =>daikanwa
595 =daikanwa@rev1 =daikanwa@rev2
596 =daikanwa/+p =>>daikanwa/+p
597 =daikanwa/+2p =>>daikanwa/+2p
600 =gt-k ==gt-k =>>gt-k =>gt-k
601 =adobe-japan1-0 ==adobe-japan1-0 ; =>>>adobe-japan1-0
602 =adobe-japan1-1 ==adobe-japan1-1 ; =>>>adobe-japan1-1
603 =adobe-japan1-2 ==adobe-japan1-2 ; =>>>adobe-japan1-2
604 =adobe-japan1-3 ==adobe-japan1-3 ; =>>>adobe-japan1-3
605 =adobe-japan1-4 ==adobe-japan1-4 ; =>>>adobe-japan1-4
606 =adobe-japan1-5 ==adobe-japan1-5 ; =>>>adobe-japan1-5
607 =adobe-japan1-6 ==adobe-japan1-6 ; =>>>adobe-japan1-6
608 =>>adobe-japan1-0 =+>adobe-japan1-0
609 =>>adobe-japan1-1 =+>adobe-japan1-1
610 =>>adobe-japan1-2 =+>adobe-japan1-2
611 =>>adobe-japan1-3 =+>adobe-japan1-3
612 =>>adobe-japan1-4 =+>adobe-japan1-4
613 =>>adobe-japan1-5 =+>adobe-japan1-5
614 =>>adobe-japan1-6 =+>adobe-japan1-6
616 =zinbun-oracle =>zinbun-oracle))
617 ;; (string-match "^=adobe-" (symbol-name name))
619 "(%-18s . %05d)\t; %c")
620 ((memq name '(=hanyo-denshi/ks
621 ==hanyo-denshi/ks ; =>>>hanyo-denshi/ks
624 "(%-18s . %06d)\t; %c")
625 ((>= (charset-dimension name) 2)
626 "(%-18s . #x%04X)\t; %c")
628 "(%-18s . #x%02X)\t; %c"))
630 (if (= (charset-iso-graphic-plane name) 1)
632 (cond ((= (charset-dimension name) 1)
634 ((= (charset-dimension name) 2)
636 ((= (charset-dimension name) 3)
640 (char-db-decode-isolated-char name value)))
641 (if (and (= (charset-chars name) 94)
642 (= (charset-dimension name) 2))
643 (insert (format " [%02d-%02d]"
644 (- (lsh value -8) 32)
645 (- (logand value 255) 32))))
648 (insert (format "(%-18s . %s)" name value))
650 (insert line-breaking))
652 (defun char-db-insert-relation-feature (char name value line-breaking
654 (insert (format "(%-18s%s " name line-breaking))
655 (let ((lbs (concat "\n" (make-string (current-column) ?\ )))
656 separator cell sources required-features
659 (setq cell (car value))
661 (setq cell (decode-char '=ucs cell)))
663 ((eq name '->subsumptive)
664 (when (or (not (some (lambda (atr)
665 (get-char-attribute cell atr))
666 char-db-ignored-attributes))
668 (encode-char cell ccs 'defined-only))
672 (let ((char-db-ignored-attributes
674 char-db-ignored-attributes)))
675 (insert-char-attributes cell readable nil nil 'for-sub-node))
676 (setq separator lbs))
681 char (intern (format "%s*sources" name))))
682 (setq required-features nil)
683 (dolist (source sources)
687 shinjigen shinjigen@1ed shinjigen@rev))
688 (setq required-features
689 (union required-features
701 =shinjigen/+p@rev))))
703 (setq required-features
704 (union required-features
709 ((find-charset (setq ret (intern (format "=%s" source))))
710 (setq required-features
711 (cons ret required-features)))
712 (t (setq required-features
713 (cons source required-features)))))
714 (cond ((string-match "@JP" (symbol-name name))
715 (setq required-features
716 (union required-features
724 ((string-match "@CN" (symbol-name name))
725 (setq required-features
726 (union required-features
733 (insert (format "%S" cell))
734 (char-db-insert-char-spec cell readable
737 (setq separator lbs))
741 (if (consp (car cell))
742 (char-db-insert-char-spec cell readable)
743 (char-db-insert-char-reference cell readable))
744 (setq separator lbs))
748 (insert (prin1-to-string cell))
749 (setq separator " ")))
750 (setq value (cdr value)))
752 (insert line-breaking)))
754 (defun insert-char-attributes (char &optional readable attributes column
757 (setq column (current-column)))
758 (let (name value ; has-long-ccs-name
762 (concat "\n" (make-string (1+ column) ?\ )))
763 lbs cell separator ret
765 dest-ccss ; sources required-features
770 (if (consp attributes)
772 (dolist (name attributes)
773 (unless (memq name char-db-ignored-attributes)
774 (if (find-charset name)
778 (dolist (name (char-attribute-list))
779 (unless (memq name char-db-ignored-attributes)
780 (if (find-charset name)
784 #'char-attribute-name<)))
786 (when (memq '<-subsumptive attributes)
787 (when (or readable (not for-sub-node))
788 (when (setq value (get-char-attribute char '<-subsumptive))
789 (char-db-insert-relation-feature char '<-subsumptive value
792 (setq attributes (delq '<-subsumptive attributes)))
793 (when (and (memq '<-denotational attributes)
794 (setq value (get-char-attribute char '<-denotational)))
795 (char-db-insert-relation-feature char '<-denotational value
798 (setq attributes (delq '<-denotational attributes)))
799 (when (and (memq 'name attributes)
800 (setq value (get-char-attribute char 'name)))
802 (if (> (+ (current-column) (length value)) 48)
805 value line-breaking))
806 (setq attributes (delq 'name attributes))
808 (when (and (memq 'name* attributes)
809 (setq value (get-char-attribute char 'name*)))
811 (if (> (+ (current-column) (length value)) 48)
814 value line-breaking))
815 (setq attributes (delq 'name* attributes))
817 (when (and (memq 'script attributes)
818 (setq value (get-char-attribute char 'script)))
819 (insert (format "(script\t\t%s)%s"
820 (mapconcat (function prin1-to-string)
823 (setq attributes (delq 'script attributes))
825 (dolist (name '(=>ucs =>ucs*))
826 (when (and (memq name attributes)
827 (setq value (get-char-attribute char name)))
828 (insert (format "(%-18s . #x%04X)\t; %c%s"
829 name value (decode-char '=ucs value)
831 (setq attributes (delq name attributes))))
832 (dolist (name '(=>ucs@gb =>ucs@big5))
833 (when (and (memq name attributes)
834 (setq value (get-char-attribute char name)))
835 (insert (format "(%-18s . #x%04X)\t; %c%s"
840 (symbol-name name) 2)))
843 (setq attributes (delq name attributes))
845 ;; (dolist (name '(=>daikanwa))
846 ;; (when (and (memq name attributes)
847 ;; (setq value (get-char-attribute char name)))
849 ;; (if (integerp value)
850 ;; (format "(%-18s . %05d)\t; %c%s"
851 ;; name value (decode-char '=daikanwa value)
853 ;; (format "(%-18s %s)\t; %c%s"
855 ;; (mapconcat (function prin1-to-string)
857 ;; (char-representative-of-daikanwa char)
859 ;; (setq attributes (delq name attributes))))
860 (when (and (memq 'general-category attributes)
861 (setq value (get-char-attribute char 'general-category)))
863 "(general-category\t%s) ; %s%s"
864 (mapconcat (lambda (cell)
867 (cond ((rassoc value unidata-normative-category-alist)
868 "Normative Category")
869 ((rassoc value unidata-informative-category-alist)
870 "Informative Category")
874 (setq attributes (delq 'general-category attributes))
876 (when (and (memq 'bidi-category attributes)
877 (setq value (get-char-attribute char 'bidi-category)))
878 (insert (format "(bidi-category\t. %S)%s"
881 (setq attributes (delq 'bidi-category attributes))
883 (unless (or (not (memq 'mirrored attributes))
884 (eq (setq value (get-char-attribute char 'mirrored 'empty))
886 (insert (format "(mirrored\t\t. %S)%s"
889 (setq attributes (delq 'mirrored attributes))
892 ((and (memq 'decimal-digit-value attributes)
893 (setq value (get-char-attribute char 'decimal-digit-value)))
894 (insert (format "(decimal-digit-value . %S)%s"
897 (setq attributes (delq 'decimal-digit-value attributes))
898 (when (and (memq 'digit-value attributes)
899 (setq value (get-char-attribute char 'digit-value)))
900 (insert (format "(digit-value\t . %S)%s"
903 (setq attributes (delq 'digit-value attributes))
905 (when (and (memq 'numeric-value attributes)
906 (setq value (get-char-attribute char 'numeric-value)))
907 (insert (format "(numeric-value\t . %S)%s"
910 (setq attributes (delq 'numeric-value attributes))
914 (when (and (memq 'digit-value attributes)
915 (setq value (get-char-attribute char 'digit-value)))
916 (insert (format "(digit-value\t. %S)%s"
919 (setq attributes (delq 'digit-value attributes))
921 (when (and (memq 'numeric-value attributes)
922 (setq value (get-char-attribute char 'numeric-value)))
923 (insert (format "(numeric-value\t. %S)%s"
926 (setq attributes (delq 'numeric-value attributes))
928 (when (and (memq 'iso-10646-comment attributes)
929 (setq value (get-char-attribute char 'iso-10646-comment)))
930 (insert (format "(iso-10646-comment\t. %S)%s"
933 (setq attributes (delq 'iso-10646-comment attributes))
935 (when (and (memq 'morohashi-daikanwa attributes)
936 (setq value (get-char-attribute char 'morohashi-daikanwa)))
937 (insert (format "(morohashi-daikanwa\t%s)%s"
938 (mapconcat (function prin1-to-string) value " ")
940 (setq attributes (delq 'morohashi-daikanwa attributes))
944 (when (and (memq 'ideographic-radical attributes)
945 (setq value (get-char-attribute char 'ideographic-radical)))
947 (insert (format "(ideographic-radical . %S)\t; %c%s"
949 (ideographic-radical radical)
951 (setq attributes (delq 'ideographic-radical attributes))
953 (when (and (memq 'shuowen-radical attributes)
954 (setq value (get-char-attribute char 'shuowen-radical)))
955 (insert (format "(shuowen-radical\t. %S)\t; %c%s"
957 (shuowen-radical value)
959 (setq attributes (delq 'shuowen-radical attributes))
964 char-db-feature-domains
966 (dolist (feature (char-attribute-list))
967 (setq feature (symbol-name feature))
969 "\\(radical\\|strokes\\)@\\([^@*]+\\)\\(\\*\\|$\\)"
971 (setq domain (intern (match-string 2 feature)))
972 (unless (memq domain dest)
973 (setq dest (cons domain dest)))))
974 (sort dest #'string<))))
975 (setq key (intern (format "%s@%s" 'ideographic-radical domain)))
976 (when (and (memq key attributes)
977 (setq value (get-char-attribute char key)))
979 (insert (format "(%s . %S)\t; %c%s"
982 (ideographic-radical radical)
984 (setq attributes (delq key attributes))
986 (setq key (intern (format "%s@%s" 'ideographic-strokes domain)))
987 (when (and (memq key attributes)
988 (setq value (get-char-attribute char key)))
990 (insert (format "(%s . %S)%s"
994 (setq attributes (delq key attributes))
996 (setq key (intern (format "%s@%s" 'total-strokes domain)))
997 (when (and (memq key attributes)
998 (setq value (get-char-attribute char key)))
999 (insert (format "(%s . %S)%s"
1003 (setq attributes (delq key attributes))
1005 (dolist (feature '(ideographic-radical
1008 (setq key (intern (format "%s@%s*sources" feature domain)))
1009 (when (and (memq key attributes)
1010 (setq value (get-char-attribute char key)))
1011 (insert (format "(%s%s" key line-breaking))
1012 (dolist (cell value)
1013 (insert (format " %s" cell)))
1015 (insert line-breaking)
1016 (setq attributes (delq key attributes))
1019 (when (and (memq 'ideographic-strokes attributes)
1020 (setq value (get-char-attribute char 'ideographic-strokes)))
1021 (setq strokes value)
1022 (insert (format "(ideographic-strokes . %S)%s"
1025 (setq attributes (delq 'ideographic-strokes attributes))
1027 (when (and (memq 'kangxi-radical attributes)
1028 (setq value (get-char-attribute char 'kangxi-radical)))
1029 (unless (eq value radical)
1030 (insert (format "(kangxi-radical\t . %S)\t; %c%s"
1032 (ideographic-radical value)
1035 (setq radical value)))
1036 (setq attributes (delq 'kangxi-radical attributes))
1038 (when (and (memq 'kangxi-strokes attributes)
1039 (setq value (get-char-attribute char 'kangxi-strokes)))
1040 (unless (eq value strokes)
1041 (insert (format "(kangxi-strokes\t . %S)%s"
1045 (setq strokes value)))
1046 (setq attributes (delq 'kangxi-strokes attributes))
1048 (when (and (memq 'japanese-radical attributes)
1049 (setq value (get-char-attribute char 'japanese-radical)))
1050 (unless (eq value radical)
1051 (insert (format "(japanese-radical\t . %S)\t; %c%s"
1053 (ideographic-radical value)
1056 (setq radical value)))
1057 (setq attributes (delq 'japanese-radical attributes))
1059 (when (and (memq 'japanese-strokes attributes)
1060 (setq value (get-char-attribute char 'japanese-strokes)))
1061 (unless (eq value strokes)
1062 (insert (format "(japanese-strokes\t . %S)%s"
1066 (setq strokes value)))
1067 (setq attributes (delq 'japanese-strokes attributes))
1069 (when (and (memq 'cns-radical attributes)
1070 (setq value (get-char-attribute char 'cns-radical)))
1071 (insert (format "(cns-radical\t . %S)\t; %c%s"
1073 (ideographic-radical value)
1075 (setq attributes (delq 'cns-radical attributes))
1077 (when (and (memq 'cns-strokes attributes)
1078 (setq value (get-char-attribute char 'cns-strokes)))
1079 (unless (eq value strokes)
1080 (insert (format "(cns-strokes\t . %S)%s"
1084 (setq strokes value)))
1085 (setq attributes (delq 'cns-strokes attributes))
1087 ;; (when (and (memq 'shinjigen-1-radical attributes)
1088 ;; (setq value (get-char-attribute char 'shinjigen-1-radical)))
1089 ;; (unless (eq value radical)
1090 ;; (insert (format "(shinjigen-1-radical . %S)\t; %c%s"
1092 ;; (ideographic-radical value)
1095 ;; (setq radical value)))
1096 ;; (setq attributes (delq 'shinjigen-1-radical attributes))
1098 (when (and (memq 'ideographic- attributes)
1099 (setq value (get-char-attribute char 'ideographic-)))
1100 (insert "(ideographic- ")
1101 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1103 (while (consp value)
1104 (setq cell (car value))
1106 (setq cell (decode-char '=ucs cell)))
1107 (cond ((characterp cell)
1111 (insert (format "%S" cell))
1112 (char-db-insert-char-spec cell readable))
1113 (setq separator lbs))
1117 (if (consp (car cell))
1118 (char-db-insert-char-spec cell readable)
1119 (char-db-insert-char-reference cell readable))
1120 (setq separator lbs))
1124 (insert (prin1-to-string cell))
1125 (setq separator " ")))
1126 (setq value (cdr value)))
1128 (insert line-breaking)
1129 (setq attributes (delq 'ideographic- attributes)))
1130 (when (and (memq 'total-strokes attributes)
1131 (setq value (get-char-attribute char 'total-strokes)))
1132 (insert (format "(total-strokes . %S)%s"
1135 (setq attributes (delq 'total-strokes attributes))
1137 (when (and (memq '->ideograph attributes)
1138 (setq value (get-char-attribute char '->ideograph)))
1139 (insert (format "(->ideograph\t%s)%s"
1140 (mapconcat (lambda (code)
1141 (cond ((symbolp code)
1144 (format "#x%04X" code))
1147 line-breaking code))))
1150 (setq attributes (delq '->ideograph attributes))
1152 ;; (when (and (memq '->decomposition attributes)
1153 ;; (setq value (get-char-attribute char '->decomposition)))
1154 ;; (insert (format "(->decomposition\t%s)%s"
1155 ;; (mapconcat (lambda (code)
1156 ;; (cond ((symbolp code)
1157 ;; (symbol-name code))
1158 ;; ((characterp code)
1160 ;; (format "%S" code)
1165 ;; (format "#x%04X" code))
1167 ;; (format "%s%S" line-breaking code))))
1170 ;; (setq attributes (delq '->decomposition attributes))
1172 (if (equal (get-char-attribute char '->titlecase)
1173 (get-char-attribute char '->uppercase))
1174 (setq attributes (delq '->titlecase attributes)))
1175 (when (and (memq '->mojikyo attributes)
1176 (setq value (get-char-attribute char '->mojikyo)))
1177 (insert (format "(->mojikyo\t\t. %06d)\t; %c%s"
1178 value (decode-char 'mojikyo value)
1180 (setq attributes (delq '->mojikyo attributes))
1182 (when (and (memq 'hanyu-dazidian-vol attributes)
1183 (setq value (get-char-attribute char 'hanyu-dazidian-vol)))
1184 (insert (format "(hanyu-dazidian-vol . %d)%s"
1185 value line-breaking))
1186 (setq attributes (delq 'hanyu-dazidian-vol attributes))
1188 (when (and (memq 'hanyu-dazidian-page attributes)
1189 (setq value (get-char-attribute char 'hanyu-dazidian-page)))
1190 (insert (format "(hanyu-dazidian-page . %d)%s"
1191 value line-breaking))
1192 (setq attributes (delq 'hanyu-dazidian-page attributes))
1194 (when (and (memq 'hanyu-dazidian-char attributes)
1195 (setq value (get-char-attribute char 'hanyu-dazidian-char)))
1196 (insert (format "(hanyu-dazidian-char . %d)%s"
1197 value line-breaking))
1198 (setq attributes (delq 'hanyu-dazidian-char attributes))
1201 (dolist (ignored '(composition
1202 ->denotational <-subsumptive ->ucs-unified
1203 ->ideographic-component-forms))
1204 (setq attributes (delq ignored attributes))))
1206 (setq name (car attributes))
1207 (unless (eq (setq value (get-char-attribute char name 'value-is-empty))
1209 (cond ((setq ret (find-charset name))
1210 (setq name (charset-name ret))
1211 (when (not (memq name dest-ccss))
1212 (setq dest-ccss (cons name dest-ccss))
1213 (char-db-insert-ccs-feature name value line-breaking))
1215 ((string-match "^=>ucs@" (symbol-name name))
1216 (insert (format "(%-18s . #x%04X)\t; %c%s"
1217 name value (decode-char '=ucs value)
1220 ((eq name 'jisx0208-1978/4X)
1221 (insert (format "(%-18s . #x%04X)%s"
1227 (not (eq name '->subsumptive))
1228 (not (eq name '->uppercase))
1229 (not (eq name '->lowercase))
1230 (not (eq name '->titlecase))
1231 (not (eq name '->canonical))
1232 (not (eq name '->Bopomofo))
1233 (not (eq name '->mistakable))
1234 (not (eq name '->ideographic-variants))
1235 (null (get-char-attribute
1236 char (intern (format "%s*sources" name))))
1237 (not (string-match "\\*sources$" (symbol-name name)))
1238 (null (get-char-attribute
1239 char (intern (format "%s*note" name))))
1240 (not (string-match "\\*note$" (symbol-name name)))
1241 (or (eq name '<-identical)
1242 (eq name '<-uppercase)
1243 (eq name '<-lowercase)
1244 (eq name '<-titlecase)
1245 (eq name '<-canonical)
1246 (eq name '<-ideographic-variants)
1247 ;; (eq name '<-synonyms)
1248 (string-match "^<-synonyms" (symbol-name name))
1249 (eq name '<-mistakable)
1250 (when (string-match "^->" (symbol-name name))
1252 ((string-match "^->fullwidth" (symbol-name name))
1253 (not (and (consp value)
1254 (characterp (car value))
1256 (car value) '=ucs 'defined-only)))
1261 ((or (eq name 'ideographic-structure)
1262 (eq name 'ideographic-combination)
1263 (eq name 'ideographic-)
1264 (eq name '=decomposition)
1265 (char-feature-base-name= '=decomposition name)
1266 (char-feature-base-name= '=>decomposition name)
1267 ;; (string-match "^=>*decomposition\\(@[^*]+\\)?$"
1268 ;; (symbol-name name))
1269 (string-match "^\\(->\\|<-\\)[^*]*$" (symbol-name name))
1270 (string-match "^\\(->\\|<-\\)[^*]*\\*sources$"
1273 (char-db-insert-relation-feature char name value
1276 ((memq name '(ideograph=
1277 original-ideograph-of
1278 ancient-ideograph-of
1281 ;; simplified-ideograph-of
1282 ideographic-variants
1283 ;; ideographic-different-form-of
1285 (insert (format "(%-18s%s " name line-breaking))
1286 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1288 (while (consp value)
1289 (setq cell (car value))
1290 (if (and (consp cell)
1295 (char-db-insert-alist cell readable)
1296 (setq separator lbs))
1299 (insert (prin1-to-string cell))
1300 (setq separator " "))
1301 (setq value (cdr value)))
1303 (insert line-breaking))
1305 (insert (format "(%-18s " name))
1306 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1308 (while (consp value)
1309 (setq cell (car value))
1310 (if (and (consp cell)
1312 (setq ret (condition-case nil
1320 (setq key (car (car rest)))
1321 (if (find-charset key)
1322 (setq cal (cons key cal))
1323 (setq al (cons key al)))
1324 (setq rest (cdr rest)))
1327 (insert-char-attributes ret
1331 (setq separator lbs))
1332 (setq ret (prin1-to-string cell))
1334 (if (< (+ (current-column)
1341 (setq separator " "))
1342 (setq value (cdr value)))
1344 (insert line-breaking))
1346 (insert (format "(%-18s" name))
1347 (setq ret (prin1-to-string value))
1348 (unless (< (+ (current-column)
1352 (insert line-breaking))
1353 (insert " . " ret ")" line-breaking)
1354 ;; (insert (format "(%-18s . %S)%s"
1359 (setq attributes (cdr attributes)))
1362 (defun insert-char-data (char &optional readable
1365 (narrow-to-region (point)(point))
1366 (insert "(define-char
1368 (insert-char-attributes char readable attributes)
1370 (goto-char (point-min))
1371 (while (re-search-forward "[ \t]+$" nil t)
1374 (goto-char (point-min))
1375 (while (re-search-forward "[ \t][ \t][ \t]*" nil t)
1376 (let ((column (current-column))
1377 (indent-tabs-mode t))
1378 (delete-region (match-beginning 0) (point))
1379 (indent-to column)))
1380 (goto-char (point-max))
1381 ;; (tabify (point-min)(point-max))
1384 (defun insert-char-data-with-variant (char &optional printable
1386 script excluded-script)
1387 (insert-char-data char printable)
1388 (let ((variants (char-variants char))
1391 (setq variants (sort variants #'<))
1392 (setq rest variants)
1393 (setq variants (cons char variants))
1395 (setq variant (car rest))
1396 (unless (get-char-attribute variant '<-subsumptive)
1397 (if (and (or (null script)
1398 (null (setq vs (get-char-attribute variant 'script)))
1400 (or (null excluded-script)
1401 (null (setq vs (get-char-attribute variant 'script)))
1402 (not (memq excluded-script vs))))
1403 (unless (and no-ucs-unified (get-char-attribute variant '=ucs))
1404 (insert-char-data variant printable)
1405 (if (setq ret (char-variants variant))
1407 (or (memq (car ret) variants)
1408 ;; (get-char-attribute (car ret) '<-subsumptive)
1409 (setq rest (nconc rest (list (car ret)))))
1410 (setq ret (cdr ret)))))))
1411 (setq rest (cdr rest)))))
1413 (defun insert-char-range-data (min max &optional script excluded-script)
1416 (while (<= code max)
1417 (setq char (decode-char '=ucs code))
1418 (if (encode-char char '=ucs 'defined-only)
1419 (insert-char-data-with-variant char nil 'no-ucs-unified
1420 script excluded-script))
1421 (setq code (1+ code)))))
1423 (defun write-char-range-data-to-file (min max file
1424 &optional script excluded-script)
1425 (let ((coding-system-for-write char-db-file-coding-system))
1427 (insert (format ";; -*- coding: %s -*-\n"
1428 char-db-file-coding-system))
1429 (insert-char-range-data min max script excluded-script)
1430 (write-region (point-min)(point-max) file))))
1432 (defvar what-character-original-window-configuration)
1435 (defun what-char-definition (char)
1436 (interactive (list (char-after)))
1437 (let ((buf (get-buffer-create "*Character Description*"))
1438 (the-buf (current-buffer))
1439 (win-conf (current-window-configuration)))
1441 (make-local-variable 'what-character-original-window-configuration)
1442 (setq what-character-original-window-configuration win-conf)
1443 (setq buffer-read-only nil)
1447 (insert-char-data-with-variant char 'printable)
1448 (unless (char-attribute-alist char)
1449 (insert (format ";; = %c\n"
1450 (let* ((rest (split-char char))
1454 (setq code (logior (lsh code 8)
1456 (decode-char ccs code)))))
1457 ;; (char-db-update-comment)
1458 (set-buffer-modified-p nil)
1459 (view-mode the-buf (lambda (buf)
1460 (set-window-configuration
1461 what-character-original-window-configuration)
1463 (goto-char (point-min)))
1465 (set-window-configuration
1466 what-character-original-window-configuration)
1467 (signal (car err) (cdr err)))))))
1473 (provide 'char-db-util)
1475 ;;; char-db-util.el ends here