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
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
598 =gt ==gt =>>>gt =>>gt =+>gt =>gt
599 =gt-k ==gt-k =>>gt-k =>gt-k
600 =adobe-japan1-0 ==adobe-japan1-0 =>>>adobe-japan1-0
601 =adobe-japan1-1 ==adobe-japan1-1 =>>>adobe-japan1-1
602 =adobe-japan1-2 ==adobe-japan1-2 =>>>adobe-japan1-2
603 =adobe-japan1-3 ==adobe-japan1-3 =>>>adobe-japan1-3
604 =adobe-japan1-4 ==adobe-japan1-4 =>>>adobe-japan1-4
605 =adobe-japan1-5 ==adobe-japan1-5 =>>>adobe-japan1-5
606 =adobe-japan1-6 ==adobe-japan1-6 =>>>adobe-japan1-6
607 =>>adobe-japan1-0 =+>adobe-japan1-0
608 =>>adobe-japan1-1 =+>adobe-japan1-1
609 =>>adobe-japan1-2 =+>adobe-japan1-2
610 =>>adobe-japan1-3 =+>adobe-japan1-3
611 =>>adobe-japan1-4 =+>adobe-japan1-4
612 =>>adobe-japan1-5 =+>adobe-japan1-5
613 =>>adobe-japan1-6 =+>adobe-japan1-6
615 =zinbun-oracle =>zinbun-oracle))
616 ;; (string-match "^=adobe-" (symbol-name name))
618 "(%-18s . %05d)\t; %c")
619 ((memq name '(=hanyo-denshi/ks
620 ==hanyo-denshi/ks =>>>hanyo-denshi/ks =>>hanyo-denshi/ks
622 "(%-18s . %06d)\t; %c")
623 ((>= (charset-dimension name) 2)
624 "(%-18s . #x%04X)\t; %c")
626 "(%-18s . #x%02X)\t; %c"))
628 (if (= (charset-iso-graphic-plane name) 1)
630 (cond ((= (charset-dimension name) 1)
632 ((= (charset-dimension name) 2)
634 ((= (charset-dimension name) 3)
638 (char-db-decode-isolated-char name value)))
639 (if (and (= (charset-chars name) 94)
640 (= (charset-dimension name) 2))
641 (insert (format " [%02d-%02d]"
642 (- (lsh value -8) 32)
643 (- (logand value 255) 32))))
646 (insert (format "(%-18s . %s)" name value))
648 (insert line-breaking))
650 (defun char-db-insert-relation-feature (char name value line-breaking
652 (insert (format "(%-18s%s " name line-breaking))
653 (let ((lbs (concat "\n" (make-string (current-column) ?\ )))
654 separator cell sources required-features
657 (setq cell (car value))
659 (setq cell (decode-char '=ucs cell)))
661 ((eq name '->subsumptive)
662 (when (or (not (some (lambda (atr)
663 (get-char-attribute cell atr))
664 char-db-ignored-attributes))
666 (encode-char cell ccs 'defined-only))
670 (let ((char-db-ignored-attributes
672 char-db-ignored-attributes)))
673 (insert-char-attributes cell readable nil nil 'for-sub-node))
674 (setq separator lbs))
679 char (intern (format "%s*sources" name))))
680 (setq required-features nil)
681 (dolist (source sources)
685 shinjigen shinjigen@1ed shinjigen@rev))
686 (setq required-features
687 (union required-features
699 =shinjigen/+p@rev))))
701 (setq required-features
702 (union required-features
707 ((find-charset (setq ret (intern (format "=%s" source))))
708 (setq required-features
709 (cons ret required-features)))
710 (t (setq required-features
711 (cons source required-features)))))
712 (cond ((string-match "@JP" (symbol-name name))
713 (setq required-features
714 (union required-features
722 ((string-match "@CN" (symbol-name name))
723 (setq required-features
724 (union required-features
731 (insert (format "%S" cell))
732 (char-db-insert-char-spec cell readable
735 (setq separator lbs))
739 (if (consp (car cell))
740 (char-db-insert-char-spec cell readable)
741 (char-db-insert-char-reference cell readable))
742 (setq separator lbs))
746 (insert (prin1-to-string cell))
747 (setq separator " ")))
748 (setq value (cdr value)))
750 (insert line-breaking)))
752 (defun insert-char-attributes (char &optional readable attributes column
755 (setq column (current-column)))
756 (let (name value ; has-long-ccs-name
760 (concat "\n" (make-string (1+ column) ?\ )))
761 lbs cell separator ret
763 dest-ccss ; sources required-features
768 (if (consp attributes)
770 (dolist (name attributes)
771 (unless (memq name char-db-ignored-attributes)
772 (if (find-charset name)
776 (dolist (name (char-attribute-list))
777 (unless (memq name char-db-ignored-attributes)
778 (if (find-charset name)
782 #'char-attribute-name<)))
784 (when (memq '<-subsumptive attributes)
785 (when (or readable (not for-sub-node))
786 (when (setq value (get-char-attribute char '<-subsumptive))
787 (char-db-insert-relation-feature char '<-subsumptive value
790 (setq attributes (delq '<-subsumptive attributes)))
791 (when (and (memq '<-denotational attributes)
792 (setq value (get-char-attribute char '<-denotational)))
793 (char-db-insert-relation-feature char '<-denotational value
796 (setq attributes (delq '<-denotational attributes)))
797 (when (and (memq 'name attributes)
798 (setq value (get-char-attribute char 'name)))
800 (if (> (+ (current-column) (length value)) 48)
803 value line-breaking))
804 (setq attributes (delq 'name attributes))
806 (when (and (memq 'name* attributes)
807 (setq value (get-char-attribute char 'name*)))
809 (if (> (+ (current-column) (length value)) 48)
812 value line-breaking))
813 (setq attributes (delq 'name* attributes))
815 (when (and (memq 'script attributes)
816 (setq value (get-char-attribute char 'script)))
817 (insert (format "(script\t\t%s)%s"
818 (mapconcat (function prin1-to-string)
821 (setq attributes (delq 'script attributes))
823 (dolist (name '(=>ucs =>ucs*))
824 (when (and (memq name attributes)
825 (setq value (get-char-attribute char name)))
826 (insert (format "(%-18s . #x%04X)\t; %c%s"
827 name value (decode-char '=ucs value)
829 (setq attributes (delq name attributes))))
830 (dolist (name '(=>ucs@gb =>ucs@big5))
831 (when (and (memq name attributes)
832 (setq value (get-char-attribute char name)))
833 (insert (format "(%-18s . #x%04X)\t; %c%s"
838 (symbol-name name) 2)))
841 (setq attributes (delq name attributes))
843 ;; (dolist (name '(=>daikanwa))
844 ;; (when (and (memq name attributes)
845 ;; (setq value (get-char-attribute char name)))
847 ;; (if (integerp value)
848 ;; (format "(%-18s . %05d)\t; %c%s"
849 ;; name value (decode-char '=daikanwa value)
851 ;; (format "(%-18s %s)\t; %c%s"
853 ;; (mapconcat (function prin1-to-string)
855 ;; (char-representative-of-daikanwa char)
857 ;; (setq attributes (delq name attributes))))
858 (when (and (memq 'general-category attributes)
859 (setq value (get-char-attribute char 'general-category)))
861 "(general-category\t%s) ; %s%s"
862 (mapconcat (lambda (cell)
865 (cond ((rassoc value unidata-normative-category-alist)
866 "Normative Category")
867 ((rassoc value unidata-informative-category-alist)
868 "Informative Category")
872 (setq attributes (delq 'general-category attributes))
874 (when (and (memq 'bidi-category attributes)
875 (setq value (get-char-attribute char 'bidi-category)))
876 (insert (format "(bidi-category\t. %S)%s"
879 (setq attributes (delq 'bidi-category attributes))
881 (unless (or (not (memq 'mirrored attributes))
882 (eq (setq value (get-char-attribute char 'mirrored 'empty))
884 (insert (format "(mirrored\t\t. %S)%s"
887 (setq attributes (delq 'mirrored attributes))
890 ((and (memq 'decimal-digit-value attributes)
891 (setq value (get-char-attribute char 'decimal-digit-value)))
892 (insert (format "(decimal-digit-value . %S)%s"
895 (setq attributes (delq 'decimal-digit-value attributes))
896 (when (and (memq 'digit-value attributes)
897 (setq value (get-char-attribute char 'digit-value)))
898 (insert (format "(digit-value\t . %S)%s"
901 (setq attributes (delq 'digit-value attributes))
903 (when (and (memq 'numeric-value attributes)
904 (setq value (get-char-attribute char 'numeric-value)))
905 (insert (format "(numeric-value\t . %S)%s"
908 (setq attributes (delq 'numeric-value attributes))
912 (when (and (memq 'digit-value attributes)
913 (setq value (get-char-attribute char 'digit-value)))
914 (insert (format "(digit-value\t. %S)%s"
917 (setq attributes (delq 'digit-value attributes))
919 (when (and (memq 'numeric-value attributes)
920 (setq value (get-char-attribute char 'numeric-value)))
921 (insert (format "(numeric-value\t. %S)%s"
924 (setq attributes (delq 'numeric-value attributes))
926 (when (and (memq 'iso-10646-comment attributes)
927 (setq value (get-char-attribute char 'iso-10646-comment)))
928 (insert (format "(iso-10646-comment\t. %S)%s"
931 (setq attributes (delq 'iso-10646-comment attributes))
933 (when (and (memq 'morohashi-daikanwa attributes)
934 (setq value (get-char-attribute char 'morohashi-daikanwa)))
935 (insert (format "(morohashi-daikanwa\t%s)%s"
936 (mapconcat (function prin1-to-string) value " ")
938 (setq attributes (delq 'morohashi-daikanwa attributes))
942 (when (and (memq 'ideographic-radical attributes)
943 (setq value (get-char-attribute char 'ideographic-radical)))
945 (insert (format "(ideographic-radical . %S)\t; %c%s"
947 (ideographic-radical radical)
949 (setq attributes (delq 'ideographic-radical attributes))
951 (when (and (memq 'shuowen-radical attributes)
952 (setq value (get-char-attribute char 'shuowen-radical)))
953 (insert (format "(shuowen-radical\t. %S)\t; %c%s"
955 (shuowen-radical value)
957 (setq attributes (delq 'shuowen-radical attributes))
962 char-db-feature-domains
964 (dolist (feature (char-attribute-list))
965 (setq feature (symbol-name feature))
967 "\\(radical\\|strokes\\)@\\([^@*]+\\)\\(\\*\\|$\\)"
969 (setq domain (intern (match-string 2 feature)))
970 (unless (memq domain dest)
971 (setq dest (cons domain dest)))))
972 (sort dest #'string<))))
973 (setq key (intern (format "%s@%s" 'ideographic-radical domain)))
974 (when (and (memq key attributes)
975 (setq value (get-char-attribute char key)))
977 (insert (format "(%s . %S)\t; %c%s"
980 (ideographic-radical radical)
982 (setq attributes (delq key attributes))
984 (setq key (intern (format "%s@%s" 'ideographic-strokes domain)))
985 (when (and (memq key attributes)
986 (setq value (get-char-attribute char key)))
988 (insert (format "(%s . %S)%s"
992 (setq attributes (delq key attributes))
994 (setq key (intern (format "%s@%s" 'total-strokes domain)))
995 (when (and (memq key attributes)
996 (setq value (get-char-attribute char key)))
997 (insert (format "(%s . %S)%s"
1001 (setq attributes (delq key attributes))
1003 (dolist (feature '(ideographic-radical
1006 (setq key (intern (format "%s@%s*sources" feature domain)))
1007 (when (and (memq key attributes)
1008 (setq value (get-char-attribute char key)))
1009 (insert (format "(%s%s" key line-breaking))
1010 (dolist (cell value)
1011 (insert (format " %s" cell)))
1013 (insert line-breaking)
1014 (setq attributes (delq key attributes))
1017 (when (and (memq 'ideographic-strokes attributes)
1018 (setq value (get-char-attribute char 'ideographic-strokes)))
1019 (setq strokes value)
1020 (insert (format "(ideographic-strokes . %S)%s"
1023 (setq attributes (delq 'ideographic-strokes attributes))
1025 (when (and (memq 'kangxi-radical attributes)
1026 (setq value (get-char-attribute char 'kangxi-radical)))
1027 (unless (eq value radical)
1028 (insert (format "(kangxi-radical\t . %S)\t; %c%s"
1030 (ideographic-radical value)
1033 (setq radical value)))
1034 (setq attributes (delq 'kangxi-radical attributes))
1036 (when (and (memq 'kangxi-strokes attributes)
1037 (setq value (get-char-attribute char 'kangxi-strokes)))
1038 (unless (eq value strokes)
1039 (insert (format "(kangxi-strokes\t . %S)%s"
1043 (setq strokes value)))
1044 (setq attributes (delq 'kangxi-strokes attributes))
1046 (when (and (memq 'japanese-radical attributes)
1047 (setq value (get-char-attribute char 'japanese-radical)))
1048 (unless (eq value radical)
1049 (insert (format "(japanese-radical\t . %S)\t; %c%s"
1051 (ideographic-radical value)
1054 (setq radical value)))
1055 (setq attributes (delq 'japanese-radical attributes))
1057 (when (and (memq 'japanese-strokes attributes)
1058 (setq value (get-char-attribute char 'japanese-strokes)))
1059 (unless (eq value strokes)
1060 (insert (format "(japanese-strokes\t . %S)%s"
1064 (setq strokes value)))
1065 (setq attributes (delq 'japanese-strokes attributes))
1067 (when (and (memq 'cns-radical attributes)
1068 (setq value (get-char-attribute char 'cns-radical)))
1069 (insert (format "(cns-radical\t . %S)\t; %c%s"
1071 (ideographic-radical value)
1073 (setq attributes (delq 'cns-radical attributes))
1075 (when (and (memq 'cns-strokes attributes)
1076 (setq value (get-char-attribute char 'cns-strokes)))
1077 (unless (eq value strokes)
1078 (insert (format "(cns-strokes\t . %S)%s"
1082 (setq strokes value)))
1083 (setq attributes (delq 'cns-strokes attributes))
1085 ;; (when (and (memq 'shinjigen-1-radical attributes)
1086 ;; (setq value (get-char-attribute char 'shinjigen-1-radical)))
1087 ;; (unless (eq value radical)
1088 ;; (insert (format "(shinjigen-1-radical . %S)\t; %c%s"
1090 ;; (ideographic-radical value)
1093 ;; (setq radical value)))
1094 ;; (setq attributes (delq 'shinjigen-1-radical attributes))
1096 (when (and (memq 'ideographic- attributes)
1097 (setq value (get-char-attribute char 'ideographic-)))
1098 (insert "(ideographic- ")
1099 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1101 (while (consp value)
1102 (setq cell (car value))
1104 (setq cell (decode-char '=ucs cell)))
1105 (cond ((characterp cell)
1109 (insert (format "%S" cell))
1110 (char-db-insert-char-spec cell readable))
1111 (setq separator lbs))
1115 (if (consp (car cell))
1116 (char-db-insert-char-spec cell readable)
1117 (char-db-insert-char-reference cell readable))
1118 (setq separator lbs))
1122 (insert (prin1-to-string cell))
1123 (setq separator " ")))
1124 (setq value (cdr value)))
1126 (insert line-breaking)
1127 (setq attributes (delq 'ideographic- attributes)))
1128 (when (and (memq 'total-strokes attributes)
1129 (setq value (get-char-attribute char 'total-strokes)))
1130 (insert (format "(total-strokes . %S)%s"
1133 (setq attributes (delq 'total-strokes attributes))
1135 (when (and (memq '->ideograph attributes)
1136 (setq value (get-char-attribute char '->ideograph)))
1137 (insert (format "(->ideograph\t%s)%s"
1138 (mapconcat (lambda (code)
1139 (cond ((symbolp code)
1142 (format "#x%04X" code))
1145 line-breaking code))))
1148 (setq attributes (delq '->ideograph attributes))
1150 ;; (when (and (memq '->decomposition attributes)
1151 ;; (setq value (get-char-attribute char '->decomposition)))
1152 ;; (insert (format "(->decomposition\t%s)%s"
1153 ;; (mapconcat (lambda (code)
1154 ;; (cond ((symbolp code)
1155 ;; (symbol-name code))
1156 ;; ((characterp code)
1158 ;; (format "%S" code)
1163 ;; (format "#x%04X" code))
1165 ;; (format "%s%S" line-breaking code))))
1168 ;; (setq attributes (delq '->decomposition attributes))
1170 (if (equal (get-char-attribute char '->titlecase)
1171 (get-char-attribute char '->uppercase))
1172 (setq attributes (delq '->titlecase attributes)))
1173 (when (and (memq '->mojikyo attributes)
1174 (setq value (get-char-attribute char '->mojikyo)))
1175 (insert (format "(->mojikyo\t\t. %06d)\t; %c%s"
1176 value (decode-char 'mojikyo value)
1178 (setq attributes (delq '->mojikyo attributes))
1180 (when (and (memq 'hanyu-dazidian-vol attributes)
1181 (setq value (get-char-attribute char 'hanyu-dazidian-vol)))
1182 (insert (format "(hanyu-dazidian-vol . %d)%s"
1183 value line-breaking))
1184 (setq attributes (delq 'hanyu-dazidian-vol attributes))
1186 (when (and (memq 'hanyu-dazidian-page attributes)
1187 (setq value (get-char-attribute char 'hanyu-dazidian-page)))
1188 (insert (format "(hanyu-dazidian-page . %d)%s"
1189 value line-breaking))
1190 (setq attributes (delq 'hanyu-dazidian-page attributes))
1192 (when (and (memq 'hanyu-dazidian-char attributes)
1193 (setq value (get-char-attribute char 'hanyu-dazidian-char)))
1194 (insert (format "(hanyu-dazidian-char . %d)%s"
1195 value line-breaking))
1196 (setq attributes (delq 'hanyu-dazidian-char attributes))
1199 (dolist (ignored '(composition
1200 ->denotational <-subsumptive ->ucs-unified
1201 ->ideographic-component-forms))
1202 (setq attributes (delq ignored attributes))))
1204 (setq name (car attributes))
1205 (unless (eq (setq value (get-char-attribute char name 'value-is-empty))
1207 (cond ((setq ret (find-charset name))
1208 (setq name (charset-name ret))
1209 (when (not (memq name dest-ccss))
1210 (setq dest-ccss (cons name dest-ccss))
1211 (char-db-insert-ccs-feature name value line-breaking))
1213 ((string-match "^=>ucs@" (symbol-name name))
1214 (insert (format "(%-18s . #x%04X)\t; %c%s"
1215 name value (decode-char '=ucs value)
1218 ((eq name 'jisx0208-1978/4X)
1219 (insert (format "(%-18s . #x%04X)%s"
1225 (not (eq name '->subsumptive))
1226 (not (eq name '->uppercase))
1227 (not (eq name '->lowercase))
1228 (not (eq name '->titlecase))
1229 (not (eq name '->canonical))
1230 (not (eq name '->Bopomofo))
1231 (not (eq name '->mistakable))
1232 (not (eq name '->ideographic-variants))
1233 (null (get-char-attribute
1234 char (intern (format "%s*sources" name))))
1235 (not (string-match "\\*sources$" (symbol-name name)))
1236 (null (get-char-attribute
1237 char (intern (format "%s*note" name))))
1238 (not (string-match "\\*note$" (symbol-name name)))
1239 (or (eq name '<-identical)
1240 (eq name '<-uppercase)
1241 (eq name '<-lowercase)
1242 (eq name '<-titlecase)
1243 (eq name '<-canonical)
1244 (eq name '<-ideographic-variants)
1245 ;; (eq name '<-synonyms)
1246 (string-match "^<-synonyms" (symbol-name name))
1247 (eq name '<-mistakable)
1248 (when (string-match "^->" (symbol-name name))
1250 ((string-match "^->fullwidth" (symbol-name name))
1251 (not (and (consp value)
1252 (characterp (car value))
1254 (car value) '=ucs 'defined-only)))
1259 ((or (eq name 'ideographic-structure)
1260 (eq name 'ideographic-combination)
1261 (eq name 'ideographic-)
1262 (eq name '=decomposition)
1263 (char-feature-base-name= '=decomposition name)
1264 (char-feature-base-name= '=>decomposition name)
1265 ;; (string-match "^=>*decomposition\\(@[^*]+\\)?$"
1266 ;; (symbol-name name))
1267 (string-match "^\\(->\\|<-\\)[^*]*$" (symbol-name name))
1268 (string-match "^\\(->\\|<-\\)[^*]*\\*sources$"
1271 (char-db-insert-relation-feature char name value
1274 ((memq name '(ideograph=
1275 original-ideograph-of
1276 ancient-ideograph-of
1279 ;; simplified-ideograph-of
1280 ideographic-variants
1281 ;; ideographic-different-form-of
1283 (insert (format "(%-18s%s " name line-breaking))
1284 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1286 (while (consp value)
1287 (setq cell (car value))
1288 (if (and (consp cell)
1293 (char-db-insert-alist cell readable)
1294 (setq separator lbs))
1297 (insert (prin1-to-string cell))
1298 (setq separator " "))
1299 (setq value (cdr value)))
1301 (insert line-breaking))
1303 (insert (format "(%-18s " name))
1304 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1306 (while (consp value)
1307 (setq cell (car value))
1308 (if (and (consp cell)
1310 (setq ret (condition-case nil
1318 (setq key (car (car rest)))
1319 (if (find-charset key)
1320 (setq cal (cons key cal))
1321 (setq al (cons key al)))
1322 (setq rest (cdr rest)))
1325 (insert-char-attributes ret
1329 (setq separator lbs))
1330 (setq ret (prin1-to-string cell))
1332 (if (< (+ (current-column)
1339 (setq separator " "))
1340 (setq value (cdr value)))
1342 (insert line-breaking))
1344 (insert (format "(%-18s" name))
1345 (setq ret (prin1-to-string value))
1346 (unless (< (+ (current-column)
1350 (insert line-breaking))
1351 (insert " . " ret ")" line-breaking)
1352 ;; (insert (format "(%-18s . %S)%s"
1357 (setq attributes (cdr attributes)))
1360 (defun insert-char-data (char &optional readable
1363 (narrow-to-region (point)(point))
1364 (insert "(define-char
1366 (insert-char-attributes char readable attributes)
1368 (goto-char (point-min))
1369 (while (re-search-forward "[ \t]+$" nil t)
1372 (goto-char (point-min))
1373 (while (re-search-forward "[ \t][ \t][ \t]*" nil t)
1374 (let ((column (current-column))
1375 (indent-tabs-mode t))
1376 (delete-region (match-beginning 0) (point))
1377 (indent-to column)))
1378 (goto-char (point-max))
1379 ;; (tabify (point-min)(point-max))
1382 (defun insert-char-data-with-variant (char &optional printable
1384 script excluded-script)
1385 (insert-char-data char printable)
1386 (let ((variants (char-variants char))
1389 (setq variants (sort variants #'<))
1390 (setq rest variants)
1391 (setq variants (cons char variants))
1393 (setq variant (car rest))
1394 (unless (get-char-attribute variant '<-subsumptive)
1395 (if (and (or (null script)
1396 (null (setq vs (get-char-attribute variant 'script)))
1398 (or (null excluded-script)
1399 (null (setq vs (get-char-attribute variant 'script)))
1400 (not (memq excluded-script vs))))
1401 (unless (and no-ucs-unified (get-char-attribute variant '=ucs))
1402 (insert-char-data variant printable)
1403 (if (setq ret (char-variants variant))
1405 (or (memq (car ret) variants)
1406 ;; (get-char-attribute (car ret) '<-subsumptive)
1407 (setq rest (nconc rest (list (car ret)))))
1408 (setq ret (cdr ret)))))))
1409 (setq rest (cdr rest)))))
1411 (defun insert-char-range-data (min max &optional script excluded-script)
1414 (while (<= code max)
1415 (setq char (decode-char '=ucs code))
1416 (if (encode-char char '=ucs 'defined-only)
1417 (insert-char-data-with-variant char nil 'no-ucs-unified
1418 script excluded-script))
1419 (setq code (1+ code)))))
1421 (defun write-char-range-data-to-file (min max file
1422 &optional script excluded-script)
1423 (let ((coding-system-for-write char-db-file-coding-system))
1425 (insert (format ";; -*- coding: %s -*-\n"
1426 char-db-file-coding-system))
1427 (insert-char-range-data min max script excluded-script)
1428 (write-region (point-min)(point-max) file))))
1430 (defvar what-character-original-window-configuration)
1433 (defun what-char-definition (char)
1434 (interactive (list (char-after)))
1435 (let ((buf (get-buffer-create "*Character Description*"))
1436 (the-buf (current-buffer))
1437 (win-conf (current-window-configuration)))
1439 (make-local-variable 'what-character-original-window-configuration)
1440 (setq what-character-original-window-configuration win-conf)
1441 (setq buffer-read-only nil)
1445 (insert-char-data-with-variant char 'printable)
1446 (unless (char-attribute-alist char)
1447 (insert (format ";; = %c\n"
1448 (let* ((rest (split-char char))
1452 (setq code (logior (lsh code 8)
1454 (decode-char ccs code)))))
1455 ;; (char-db-update-comment)
1456 (set-buffer-modified-p nil)
1457 (view-mode the-buf (lambda (buf)
1458 (set-window-configuration
1459 what-character-original-window-configuration)
1461 (goto-char (point-min)))
1463 (set-window-configuration
1464 what-character-original-window-configuration)
1465 (signal (car err) (cdr err)))))))
1471 (provide 'char-db-util)
1473 ;;; char-db-util.el ends here