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 ?鼓 ?豈 ?豆 ?豊 ?豐 ?䖒 ?虍 ?虎 ?虤 ?皿 ; 170
84 ?𠙴 ?去 ?血 ?丶 ?丹 ?青 ?井 ?皀 ?鬯 ?食 ; 180
85 ?亼 ?會 ?倉 ?入 ?缶 ?矢 ?高 ?冂 ?𩫏 ?京 ; 190
86 ?亯 ?𣆪 ?畗 ?㐭 ?嗇 ?來 ?麥 ?夊 ?舛 ?䑞 ; 200
87 ?韋 ?弟 ?夂 ?久 ?桀 ?木 ?東 ?林 ?才 ?叒 ; 210
88 ?之 ?帀 ?出 ?𣎵 ?生 ?乇 ?𠂹 ?𠌶 ?華 ?𥝌 ; 220
89 ?稽 ?巢 ?桼 ?束 ?㯻 ?囗 ?員 ?貝 ?邑 ?𨛜 ; 230
90 ?日 ?旦 ?倝 ?㫃 ?冥 ?晶 ?月 ?有 ?明 ?囧 ; 240
91 ?夕 ?多 ?毌 ?𢎘 ?𣐺 ?卣 ?齊 ?朿 ?片 ?鼎 ; 250
92 ?克 ?彔 ?禾 ?秝 ?黍 ?香 ?米 ?毇 ?臼 ?凶 ; 260
93 ?𣎳 ?林 ?麻 ?尗 ?耑 ?韭 ?瓜 ?瓠 ?宀 ?宮 ; 270
94 ?呂 ?穴 ?㝱 ?𤕫 ?冖 ?𠔼 ?冃 ?㒳 ?网 ?襾 ; 280
95 ?巾 ?巿 ?帛 ?白 ?㡀 ?黹 ?人 ?𠤎 ?匕 ?从 ; 290
98 (defun shuowen-radical (number)
99 (aref shuowen-radicals (1- number)))
101 (defvar char-db-file-coding-system 'utf-8-mcs-er)
103 (defvar char-db-ignored-attributes '(ideographic-products))
105 (defvar char-db-coded-charset-priority-list
272 ;;; @ char-db formatters
275 (defun char-db-make-char-spec (char)
277 (cond ((characterp char)
278 (cond ((and (setq ret (encode-char char '=ucs 'defined-only))
279 (not (and (<= #xE000 ret)(<= ret #xF8FF))))
280 (setq char-spec (list (cons '=ucs ret)))
281 (cond ((setq ret (get-char-attribute char 'name))
282 (setq char-spec (cons (cons 'name ret) char-spec))
284 ((setq ret (get-char-attribute char 'name*))
285 (setq char-spec (cons (cons 'name* ret) char-spec))
288 ((encode-char char '=adobe-japan1 'defined-only)
290 (dolist (ccs (charset-list))
291 (if (and (or (memq ccs
300 ;; (eq (charset-property ccs 'iso-ir) 177)
301 (string-match "=ucs@" (symbol-name ccs))
303 (setq ccs (charset-name ccs))
304 (null (assq ccs char-spec))
305 (setq ret (encode-char char ccs 'defined-only)))
306 (setq char-spec (cons (cons ccs ret) char-spec))))
310 (let ((rest char-db-coded-charset-priority-list)
313 (setq ccs (charset-name
314 (find-charset (car rest))))
316 (encode-char char ccs
318 (throw 'tag (cons ccs ret)))
319 (setq rest (cdr rest))))))
320 (setq char-spec (list ret))
321 (dolist (ccs (delq (car ret) (charset-list)))
322 (if (and (or (charset-iso-final-char ccs)
329 (eq (charset-property ccs 'iso-ir) 177)
330 ;; (string-match "=ucs@" (symbol-name ccs))
332 (setq ccs (charset-name ccs))
333 (null (assq ccs char-spec))
334 (setq ret (encode-char char ccs 'defined-only)))
335 (setq char-spec (cons (cons ccs ret) char-spec))))
337 (setq char-spec (split-char char)))
338 (cond ((setq ret (get-char-attribute char 'name))
339 (setq char-spec (cons (cons 'name ret) char-spec))
341 ((setq ret (get-char-attribute char 'name*))
342 (setq char-spec (cons (cons 'name* ret) char-spec))
345 ((setq ret (get-char-attribute
346 char 'ideographic-combination))
348 (cons (cons 'ideographic-combination ret)
355 (defun char-db-insert-char-spec (char &optional readable column
358 (setq column (current-column)))
359 (let (char-spec temp-char)
360 (setq char-spec (char-db-make-char-spec char))
361 (unless (or (characterp char) ; char
363 (setq char (find-char char-spec))
365 ;; define temporary character
366 ;; Current implementation is dirty.
367 (setq temp-char (define-char (cons '(ideograph-daikanwa . 0)
369 (remove-char-attribute temp-char 'ideograph-daikanwa)
370 (setq char temp-char))
371 (insert-char-attributes char
373 (union (mapcar #'car char-spec)
377 ;; undefine temporary character
378 ;; Current implementation is dirty.
379 (setq char-spec (char-attribute-alist temp-char))
381 (remove-char-attribute temp-char (car (car char-spec)))
382 (setq char-spec (cdr char-spec))))))
384 (defun char-db-insert-alist (alist &optional readable column)
386 (setq column (current-column)))
388 (concat "\n" (make-string (1+ column) ?\ )))
392 lbs cell rest separator)
395 (setq name (car (car alist))
396 value (cdr (car alist)))
397 (cond ((eq name 'char)
399 (if (setq ret (condition-case nil
407 (setq key (car (car value)))
408 ;; (if (find-charset key)
409 ;; (setq cal (cons key cal))
410 (setq al (cons key al))
412 (setq value (cdr value)))
413 (insert-char-attributes ret
417 (insert (prin1-to-string value)))
419 (insert line-breaking))
421 (insert (format "(%-18s " name))
422 (setq lbs (concat "\n" (make-string (current-column) ?\ )))
424 (setq cell (car value))
425 (if (and (consp cell)
427 (setq ret (condition-case nil
437 (setq key (car (car rest)))
438 ;; (if (find-charset key)
439 ;; (setq cal (cons key cal))
440 (setq al (cons key al))
442 (setq rest (cdr rest)))
445 (insert-char-attributes ret
449 (setq separator lbs))
452 (insert (prin1-to-string cell))
453 (setq separator " "))
454 (setq value (cdr value)))
456 (insert line-breaking))
458 (insert (format "(%-18s . %S)%s"
461 (setq alist (cdr alist))))
464 (defun char-db-insert-char-reference (plist &optional readable column)
466 (setq column (current-column)))
468 (concat "\n" (make-string (1+ column) ?\ )))
473 (setq name (pop plist))
474 (setq value (pop plist))
475 (cond ((eq name :char)
478 (cond ((numberp value)
479 (setq value (decode-char '=ucs value)))
481 ;; (setq value (or (find-char value)
484 (char-db-insert-char-spec value readable)
485 (insert line-breaking)
488 (insert (format "%s%s\t%d ; %c%s"
491 (ideographic-radical value)
495 (insert (format "%s%s\t%S" separator name value))
496 (setq separator line-breaking)))
500 (defun char-db-decode-isolated-char (ccs code-point)
503 (cond ((eq ccs 'arabic-iso8859-6)
504 (decode-char ccs code-point))
505 ((and (memq ccs '(=gt-pj-1
516 (setq ret (decode-char ccs code-point))
517 (setq ret (encode-char ret '=gt 'defined-only)))
518 (decode-builtin-char '=gt ret))
520 (decode-builtin-char ccs code-point))))
521 (cond ((and (<= 0 (char-int ret))
522 (<= (char-int ret) #x1F))
523 (decode-char '=ucs (+ #x2400 (char-int ret))))
524 ((= (char-int ret) #x7F)
528 (defvar char-db-convert-obsolete-format t)
530 (defun char-db-insert-ccs-feature (name value line-breaking)
536 ((memq name '(=shinjigen
538 =shinjigen@rev =shinjigen/+p@rev
539 =daikanwa/ho =>>daikanwa/ho =>daikanwa/ho))
540 "(%-18s . %04d)\t; %c")
541 ((eq name '=shinjigen@1ed/24pr)
542 "(%-18s . %04d)\t; %c")
543 ((or (memq name '(=daikanwa =>>daikanwa =>daikanwa
544 =daikanwa@rev1 =daikanwa@rev2
545 =daikanwa/+p =>>daikanwa/+p
546 =daikanwa/+2p =>>daikanwa/+2p
547 =gt =>>>gt =>>gt =+>gt =>gt
549 =adobe-japan1-0 =>>>adobe-japan1-0
550 =adobe-japan1-1 =>>>adobe-japan1-1
551 =adobe-japan1-2 =>>>adobe-japan1-2
552 =adobe-japan1-3 =>>>adobe-japan1-3
553 =adobe-japan1-4 =>>>adobe-japan1-4
554 =adobe-japan1-5 =>>>adobe-japan1-5
555 =adobe-japan1-6 =>>>adobe-japan1-6
556 =>>adobe-japan1-0 =+>adobe-japan1-0
557 =>>adobe-japan1-1 =+>adobe-japan1-1
558 =>>adobe-japan1-2 =+>adobe-japan1-2
559 =>>adobe-japan1-3 =+>adobe-japan1-3
560 =>>adobe-japan1-4 =+>adobe-japan1-4
561 =>>adobe-japan1-5 =+>adobe-japan1-5
562 =>>adobe-japan1-6 =+>adobe-japan1-6
564 =zinbun-oracle =>zinbun-oracle))
565 ;; (string-match "^=adobe-" (symbol-name name))
567 "(%-18s . %05d)\t; %c")
568 ((memq name '(=hanyo-denshi/ks
569 =>>>hanyo-denshi/ks =>>hanyo-denshi/ks
571 "(%-18s . %06d)\t; %c")
572 ((>= (charset-dimension name) 2)
573 "(%-18s . #x%04X)\t; %c")
575 "(%-18s . #x%02X)\t; %c"))
577 (if (= (charset-iso-graphic-plane name) 1)
579 (cond ((= (charset-dimension name) 1)
581 ((= (charset-dimension name) 2)
583 ((= (charset-dimension name) 3)
587 (char-db-decode-isolated-char name value)))
588 (if (and (= (charset-chars name) 94)
589 (= (charset-dimension name) 2))
590 (insert (format " [%02d-%02d]"
591 (- (lsh value -8) 32)
592 (- (logand value 255) 32))))
595 (insert (format "(%-18s . %s)" name value))
597 (insert line-breaking))
599 (defun char-db-insert-relation-feature (char name value line-breaking
601 (insert (format "(%-18s%s " name line-breaking))
602 (let ((lbs (concat "\n" (make-string (current-column) ?\ )))
603 separator cell sources required-features
606 (setq cell (car value))
608 (setq cell (decode-char '=ucs cell)))
610 ((eq name '->subsumptive)
611 (when (or (not (some (lambda (atr)
612 (get-char-attribute cell atr))
613 char-db-ignored-attributes))
615 (encode-char cell ccs 'defined-only))
619 (let ((char-db-ignored-attributes
621 char-db-ignored-attributes)))
622 (insert-char-attributes cell readable nil nil 'for-sub-node))
623 (setq separator lbs))
628 char (intern (format "%s*sources" name))))
629 (setq required-features nil)
630 (dolist (source sources)
634 shinjigen shinjigen@1ed shinjigen@rev))
635 (setq required-features
636 (union required-features
648 =shinjigen/+p@rev))))
650 (setq required-features
651 (union required-features
656 ((find-charset (setq ret (intern (format "=%s" source))))
657 (setq required-features
658 (cons ret required-features)))
659 (t (setq required-features
660 (cons source required-features)))))
661 (cond ((string-match "@JP" (symbol-name name))
662 (setq required-features
663 (union required-features
671 ((string-match "@CN" (symbol-name name))
672 (setq required-features
673 (union required-features
680 (insert (format "%S" cell))
681 (char-db-insert-char-spec cell readable
684 (setq separator lbs))
688 (if (consp (car cell))
689 (char-db-insert-char-spec cell readable)
690 (char-db-insert-char-reference cell readable))
691 (setq separator lbs))
695 (insert (prin1-to-string cell))
696 (setq separator " ")))
697 (setq value (cdr value)))
699 (insert line-breaking)))
701 (defun insert-char-attributes (char &optional readable attributes column
704 (setq column (current-column)))
705 (let (name value ; has-long-ccs-name
709 (concat "\n" (make-string (1+ column) ?\ )))
710 lbs cell separator ret
712 dest-ccss ; sources required-features
717 (if (consp attributes)
719 (dolist (name attributes)
720 (unless (memq name char-db-ignored-attributes)
721 (if (find-charset name)
725 (dolist (name (char-attribute-list))
726 (unless (memq name char-db-ignored-attributes)
727 (if (find-charset name)
731 #'char-attribute-name<)))
733 (when (memq '<-subsumptive attributes)
734 (when (or readable (not for-sub-node))
735 (when (setq value (get-char-attribute char '<-subsumptive))
736 (char-db-insert-relation-feature char '<-subsumptive value
739 (setq attributes (delq '<-subsumptive attributes)))
740 (when (and (memq '<-denotational attributes)
741 (setq value (get-char-attribute char '<-denotational)))
742 (char-db-insert-relation-feature char '<-denotational value
745 (setq attributes (delq '<-denotational attributes)))
746 (when (and (memq 'name attributes)
747 (setq value (get-char-attribute char 'name)))
749 (if (> (+ (current-column) (length value)) 48)
752 value line-breaking))
753 (setq attributes (delq 'name attributes))
755 (when (and (memq 'name* attributes)
756 (setq value (get-char-attribute char 'name*)))
758 (if (> (+ (current-column) (length value)) 48)
761 value line-breaking))
762 (setq attributes (delq 'name* attributes))
764 (when (and (memq 'script attributes)
765 (setq value (get-char-attribute char 'script)))
766 (insert (format "(script\t\t%s)%s"
767 (mapconcat (function prin1-to-string)
770 (setq attributes (delq 'script attributes))
772 (dolist (name '(=>ucs =>ucs*))
773 (when (and (memq name attributes)
774 (setq value (get-char-attribute char name)))
775 (insert (format "(%-18s . #x%04X)\t; %c%s"
776 name value (decode-char '=ucs value)
778 (setq attributes (delq name attributes))))
779 (dolist (name '(=>ucs@gb =>ucs@big5))
780 (when (and (memq name attributes)
781 (setq value (get-char-attribute char name)))
782 (insert (format "(%-18s . #x%04X)\t; %c%s"
787 (symbol-name name) 2)))
790 (setq attributes (delq name attributes))
792 ;; (dolist (name '(=>daikanwa))
793 ;; (when (and (memq name attributes)
794 ;; (setq value (get-char-attribute char name)))
796 ;; (if (integerp value)
797 ;; (format "(%-18s . %05d)\t; %c%s"
798 ;; name value (decode-char '=daikanwa value)
800 ;; (format "(%-18s %s)\t; %c%s"
802 ;; (mapconcat (function prin1-to-string)
804 ;; (char-representative-of-daikanwa char)
806 ;; (setq attributes (delq name attributes))))
807 (when (and (memq 'general-category attributes)
808 (setq value (get-char-attribute char 'general-category)))
810 "(general-category\t%s) ; %s%s"
811 (mapconcat (lambda (cell)
814 (cond ((rassoc value unidata-normative-category-alist)
815 "Normative Category")
816 ((rassoc value unidata-informative-category-alist)
817 "Informative Category")
821 (setq attributes (delq 'general-category attributes))
823 (when (and (memq 'bidi-category attributes)
824 (setq value (get-char-attribute char 'bidi-category)))
825 (insert (format "(bidi-category\t. %S)%s"
828 (setq attributes (delq 'bidi-category attributes))
830 (unless (or (not (memq 'mirrored attributes))
831 (eq (setq value (get-char-attribute char 'mirrored 'empty))
833 (insert (format "(mirrored\t\t. %S)%s"
836 (setq attributes (delq 'mirrored attributes))
839 ((and (memq 'decimal-digit-value attributes)
840 (setq value (get-char-attribute char 'decimal-digit-value)))
841 (insert (format "(decimal-digit-value . %S)%s"
844 (setq attributes (delq 'decimal-digit-value attributes))
845 (when (and (memq 'digit-value attributes)
846 (setq value (get-char-attribute char 'digit-value)))
847 (insert (format "(digit-value\t . %S)%s"
850 (setq attributes (delq 'digit-value attributes))
852 (when (and (memq 'numeric-value attributes)
853 (setq value (get-char-attribute char 'numeric-value)))
854 (insert (format "(numeric-value\t . %S)%s"
857 (setq attributes (delq 'numeric-value attributes))
861 (when (and (memq 'digit-value attributes)
862 (setq value (get-char-attribute char 'digit-value)))
863 (insert (format "(digit-value\t. %S)%s"
866 (setq attributes (delq 'digit-value attributes))
868 (when (and (memq 'numeric-value attributes)
869 (setq value (get-char-attribute char 'numeric-value)))
870 (insert (format "(numeric-value\t. %S)%s"
873 (setq attributes (delq 'numeric-value attributes))
875 (when (and (memq 'iso-10646-comment attributes)
876 (setq value (get-char-attribute char 'iso-10646-comment)))
877 (insert (format "(iso-10646-comment\t. %S)%s"
880 (setq attributes (delq 'iso-10646-comment attributes))
882 (when (and (memq 'morohashi-daikanwa attributes)
883 (setq value (get-char-attribute char 'morohashi-daikanwa)))
884 (insert (format "(morohashi-daikanwa\t%s)%s"
885 (mapconcat (function prin1-to-string) value " ")
887 (setq attributes (delq 'morohashi-daikanwa attributes))
891 (when (and (memq 'ideographic-radical attributes)
892 (setq value (get-char-attribute char 'ideographic-radical)))
894 (insert (format "(ideographic-radical . %S)\t; %c%s"
896 (ideographic-radical radical)
898 (setq attributes (delq 'ideographic-radical attributes))
900 (when (and (memq 'shuowen-radical attributes)
901 (setq value (get-char-attribute char 'shuowen-radical)))
902 (insert (format "(shuowen-radical\t. %S)\t; %c%s"
904 (shuowen-radical value)
906 (setq attributes (delq 'shuowen-radical attributes))
911 char-db-feature-domains
913 (dolist (feature (char-attribute-list))
914 (setq feature (symbol-name feature))
916 "\\(radical\\|strokes\\)@\\([^@*]+\\)\\(\\*\\|$\\)"
918 (setq domain (intern (match-string 2 feature)))
919 (unless (memq domain dest)
920 (setq dest (cons domain dest)))))
921 (sort dest #'string<))))
922 (setq key (intern (format "%s@%s" 'ideographic-radical domain)))
923 (when (and (memq key attributes)
924 (setq value (get-char-attribute char key)))
926 (insert (format "(%s . %S)\t; %c%s"
929 (ideographic-radical radical)
931 (setq attributes (delq key attributes))
933 (setq key (intern (format "%s@%s" 'ideographic-strokes domain)))
934 (when (and (memq key attributes)
935 (setq value (get-char-attribute char key)))
937 (insert (format "(%s . %S)%s"
941 (setq attributes (delq key attributes))
943 (setq key (intern (format "%s@%s" 'total-strokes domain)))
944 (when (and (memq key attributes)
945 (setq value (get-char-attribute char key)))
946 (insert (format "(%s . %S)%s"
950 (setq attributes (delq key attributes))
952 (dolist (feature '(ideographic-radical
955 (setq key (intern (format "%s@%s*sources" feature domain)))
956 (when (and (memq key attributes)
957 (setq value (get-char-attribute char key)))
958 (insert (format "(%s%s" key line-breaking))
960 (insert (format " %s" cell)))
962 (insert line-breaking)
963 (setq attributes (delq key attributes))
966 (when (and (memq 'ideographic-strokes attributes)
967 (setq value (get-char-attribute char 'ideographic-strokes)))
969 (insert (format "(ideographic-strokes . %S)%s"
972 (setq attributes (delq 'ideographic-strokes attributes))
974 (when (and (memq 'kangxi-radical attributes)
975 (setq value (get-char-attribute char 'kangxi-radical)))
976 (unless (eq value radical)
977 (insert (format "(kangxi-radical\t . %S)\t; %c%s"
979 (ideographic-radical value)
982 (setq radical value)))
983 (setq attributes (delq 'kangxi-radical attributes))
985 (when (and (memq 'kangxi-strokes attributes)
986 (setq value (get-char-attribute char 'kangxi-strokes)))
987 (unless (eq value strokes)
988 (insert (format "(kangxi-strokes\t . %S)%s"
992 (setq strokes value)))
993 (setq attributes (delq 'kangxi-strokes attributes))
995 (when (and (memq 'japanese-radical attributes)
996 (setq value (get-char-attribute char 'japanese-radical)))
997 (unless (eq value radical)
998 (insert (format "(japanese-radical\t . %S)\t; %c%s"
1000 (ideographic-radical value)
1003 (setq radical value)))
1004 (setq attributes (delq 'japanese-radical attributes))
1006 (when (and (memq 'japanese-strokes attributes)
1007 (setq value (get-char-attribute char 'japanese-strokes)))
1008 (unless (eq value strokes)
1009 (insert (format "(japanese-strokes\t . %S)%s"
1013 (setq strokes value)))
1014 (setq attributes (delq 'japanese-strokes attributes))
1016 (when (and (memq 'cns-radical attributes)
1017 (setq value (get-char-attribute char 'cns-radical)))
1018 (insert (format "(cns-radical\t . %S)\t; %c%s"
1020 (ideographic-radical value)
1022 (setq attributes (delq 'cns-radical attributes))
1024 (when (and (memq 'cns-strokes attributes)
1025 (setq value (get-char-attribute char 'cns-strokes)))
1026 (unless (eq value strokes)
1027 (insert (format "(cns-strokes\t . %S)%s"
1031 (setq strokes value)))
1032 (setq attributes (delq 'cns-strokes attributes))
1034 ;; (when (and (memq 'shinjigen-1-radical attributes)
1035 ;; (setq value (get-char-attribute char 'shinjigen-1-radical)))
1036 ;; (unless (eq value radical)
1037 ;; (insert (format "(shinjigen-1-radical . %S)\t; %c%s"
1039 ;; (ideographic-radical value)
1042 ;; (setq radical value)))
1043 ;; (setq attributes (delq 'shinjigen-1-radical attributes))
1045 (when (and (memq 'ideographic- attributes)
1046 (setq value (get-char-attribute char 'ideographic-)))
1047 (insert "(ideographic- ")
1048 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1050 (while (consp value)
1051 (setq cell (car value))
1053 (setq cell (decode-char '=ucs cell)))
1054 (cond ((characterp cell)
1058 (insert (format "%S" cell))
1059 (char-db-insert-char-spec cell readable))
1060 (setq separator lbs))
1064 (if (consp (car cell))
1065 (char-db-insert-char-spec cell readable)
1066 (char-db-insert-char-reference cell readable))
1067 (setq separator lbs))
1071 (insert (prin1-to-string cell))
1072 (setq separator " ")))
1073 (setq value (cdr value)))
1075 (insert line-breaking)
1076 (setq attributes (delq 'ideographic- attributes)))
1077 (when (and (memq 'total-strokes attributes)
1078 (setq value (get-char-attribute char 'total-strokes)))
1079 (insert (format "(total-strokes . %S)%s"
1082 (setq attributes (delq 'total-strokes attributes))
1084 (when (and (memq '->ideograph attributes)
1085 (setq value (get-char-attribute char '->ideograph)))
1086 (insert (format "(->ideograph\t%s)%s"
1087 (mapconcat (lambda (code)
1088 (cond ((symbolp code)
1091 (format "#x%04X" code))
1094 line-breaking code))))
1097 (setq attributes (delq '->ideograph attributes))
1099 ;; (when (and (memq '->decomposition attributes)
1100 ;; (setq value (get-char-attribute char '->decomposition)))
1101 ;; (insert (format "(->decomposition\t%s)%s"
1102 ;; (mapconcat (lambda (code)
1103 ;; (cond ((symbolp code)
1104 ;; (symbol-name code))
1105 ;; ((characterp code)
1107 ;; (format "%S" code)
1112 ;; (format "#x%04X" code))
1114 ;; (format "%s%S" line-breaking code))))
1117 ;; (setq attributes (delq '->decomposition attributes))
1119 (if (equal (get-char-attribute char '->titlecase)
1120 (get-char-attribute char '->uppercase))
1121 (setq attributes (delq '->titlecase attributes)))
1122 (when (and (memq '->mojikyo attributes)
1123 (setq value (get-char-attribute char '->mojikyo)))
1124 (insert (format "(->mojikyo\t\t. %06d)\t; %c%s"
1125 value (decode-char 'mojikyo value)
1127 (setq attributes (delq '->mojikyo attributes))
1129 (when (and (memq 'hanyu-dazidian-vol attributes)
1130 (setq value (get-char-attribute char 'hanyu-dazidian-vol)))
1131 (insert (format "(hanyu-dazidian-vol . %d)%s"
1132 value line-breaking))
1133 (setq attributes (delq 'hanyu-dazidian-vol attributes))
1135 (when (and (memq 'hanyu-dazidian-page attributes)
1136 (setq value (get-char-attribute char 'hanyu-dazidian-page)))
1137 (insert (format "(hanyu-dazidian-page . %d)%s"
1138 value line-breaking))
1139 (setq attributes (delq 'hanyu-dazidian-page attributes))
1141 (when (and (memq 'hanyu-dazidian-char attributes)
1142 (setq value (get-char-attribute char 'hanyu-dazidian-char)))
1143 (insert (format "(hanyu-dazidian-char . %d)%s"
1144 value line-breaking))
1145 (setq attributes (delq 'hanyu-dazidian-char attributes))
1148 (dolist (ignored '(composition
1149 ->denotational <-subsumptive ->ucs-unified
1150 ->ideographic-component-forms))
1151 (setq attributes (delq ignored attributes))))
1153 (setq name (car attributes))
1154 (unless (eq (setq value (get-char-attribute char name 'value-is-empty))
1156 (cond ((setq ret (find-charset name))
1157 (setq name (charset-name ret))
1158 (when (not (memq name dest-ccss))
1159 (setq dest-ccss (cons name dest-ccss))
1160 (char-db-insert-ccs-feature name value line-breaking))
1162 ((string-match "^=>ucs@" (symbol-name name))
1163 (insert (format "(%-18s . #x%04X)\t; %c%s"
1164 name value (decode-char '=ucs value)
1167 ((eq name 'jisx0208-1978/4X)
1168 (insert (format "(%-18s . #x%04X)%s"
1174 (not (eq name '->subsumptive))
1175 (not (eq name '->uppercase))
1176 (not (eq name '->lowercase))
1177 (not (eq name '->titlecase))
1178 (not (eq name '->canonical))
1179 (not (eq name '->Bopomofo))
1180 (not (eq name '->mistakable))
1181 (not (eq name '->ideographic-variants))
1182 (null (get-char-attribute
1183 char (intern (format "%s*sources" name))))
1184 (not (string-match "\\*sources$" (symbol-name name)))
1185 (null (get-char-attribute
1186 char (intern (format "%s*note" name))))
1187 (not (string-match "\\*note$" (symbol-name name)))
1188 (or (eq name '<-identical)
1189 (eq name '<-uppercase)
1190 (eq name '<-lowercase)
1191 (eq name '<-titlecase)
1192 (eq name '<-canonical)
1193 (eq name '<-ideographic-variants)
1194 ;; (eq name '<-synonyms)
1195 (string-match "^<-synonyms" (symbol-name name))
1196 (eq name '<-mistakable)
1197 (when (string-match "^->" (symbol-name name))
1199 ((string-match "^->fullwidth" (symbol-name name))
1200 (not (and (consp value)
1201 (characterp (car value))
1203 (car value) '=ucs 'defined-only)))
1208 ((or (eq name 'ideographic-structure)
1209 (eq name 'ideographic-combination)
1210 (eq name 'ideographic-)
1211 (eq name '=decomposition)
1212 (char-feature-base-name= '=decomposition name)
1213 (char-feature-base-name= '=>decomposition name)
1214 ;; (string-match "^=>*decomposition\\(@[^*]+\\)?$"
1215 ;; (symbol-name name))
1216 (string-match "^\\(->\\|<-\\)[^*]*$" (symbol-name name))
1217 (string-match "^\\(->\\|<-\\)[^*]*\\*sources$"
1220 (char-db-insert-relation-feature char name value
1223 ((memq name '(ideograph=
1224 original-ideograph-of
1225 ancient-ideograph-of
1228 ;; simplified-ideograph-of
1229 ideographic-variants
1230 ;; ideographic-different-form-of
1232 (insert (format "(%-18s%s " name line-breaking))
1233 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1235 (while (consp value)
1236 (setq cell (car value))
1237 (if (and (consp cell)
1242 (char-db-insert-alist cell readable)
1243 (setq separator lbs))
1246 (insert (prin1-to-string cell))
1247 (setq separator " "))
1248 (setq value (cdr value)))
1250 (insert line-breaking))
1252 (insert (format "(%-18s " name))
1253 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1255 (while (consp value)
1256 (setq cell (car value))
1257 (if (and (consp cell)
1259 (setq ret (condition-case nil
1267 (setq key (car (car rest)))
1268 (if (find-charset key)
1269 (setq cal (cons key cal))
1270 (setq al (cons key al)))
1271 (setq rest (cdr rest)))
1274 (insert-char-attributes ret
1278 (setq separator lbs))
1279 (setq ret (prin1-to-string cell))
1281 (if (< (+ (current-column)
1288 (setq separator " "))
1289 (setq value (cdr value)))
1291 (insert line-breaking))
1293 (insert (format "(%-18s" name))
1294 (setq ret (prin1-to-string value))
1295 (unless (< (+ (current-column)
1299 (insert line-breaking))
1300 (insert " . " ret ")" line-breaking)
1301 ;; (insert (format "(%-18s . %S)%s"
1306 (setq attributes (cdr attributes)))
1309 (defun insert-char-data (char &optional readable
1312 (narrow-to-region (point)(point))
1313 (insert "(define-char
1315 (insert-char-attributes char readable attributes)
1317 (goto-char (point-min))
1318 (while (re-search-forward "[ \t]+$" nil t)
1321 (goto-char (point-min))
1322 (while (re-search-forward "[ \t][ \t][ \t]*" nil t)
1323 (let ((column (current-column))
1324 (indent-tabs-mode t))
1325 (delete-region (match-beginning 0) (point))
1326 (indent-to column)))
1327 (goto-char (point-max))
1328 ;; (tabify (point-min)(point-max))
1331 (defun insert-char-data-with-variant (char &optional printable
1333 script excluded-script)
1334 (insert-char-data char printable)
1335 (let ((variants (char-variants char))
1338 (setq variants (sort variants #'<))
1339 (setq rest variants)
1340 (setq variants (cons char variants))
1342 (setq variant (car rest))
1343 (unless (get-char-attribute variant '<-subsumptive)
1344 (if (and (or (null script)
1345 (null (setq vs (get-char-attribute variant 'script)))
1347 (or (null excluded-script)
1348 (null (setq vs (get-char-attribute variant 'script)))
1349 (not (memq excluded-script vs))))
1350 (unless (and no-ucs-unified (get-char-attribute variant '=ucs))
1351 (insert-char-data variant printable)
1352 (if (setq ret (char-variants variant))
1354 (or (memq (car ret) variants)
1355 ;; (get-char-attribute (car ret) '<-subsumptive)
1356 (setq rest (nconc rest (list (car ret)))))
1357 (setq ret (cdr ret)))))))
1358 (setq rest (cdr rest)))))
1360 (defun insert-char-range-data (min max &optional script excluded-script)
1363 (while (<= code max)
1364 (setq char (decode-char '=ucs code))
1365 (if (encode-char char '=ucs 'defined-only)
1366 (insert-char-data-with-variant char nil 'no-ucs-unified
1367 script excluded-script))
1368 (setq code (1+ code)))))
1370 (defun write-char-range-data-to-file (min max file
1371 &optional script excluded-script)
1372 (let ((coding-system-for-write char-db-file-coding-system))
1374 (insert (format ";; -*- coding: %s -*-\n"
1375 char-db-file-coding-system))
1376 (insert-char-range-data min max script excluded-script)
1377 (write-region (point-min)(point-max) file))))
1379 (defvar what-character-original-window-configuration)
1382 (defun what-char-definition (char)
1383 (interactive (list (char-after)))
1384 (let ((buf (get-buffer-create "*Character Description*"))
1385 (the-buf (current-buffer))
1386 (win-conf (current-window-configuration)))
1388 (make-local-variable 'what-character-original-window-configuration)
1389 (setq what-character-original-window-configuration win-conf)
1390 (setq buffer-read-only nil)
1394 (insert-char-data-with-variant char 'printable)
1395 (unless (char-attribute-alist char)
1396 (insert (format ";; = %c\n"
1397 (let* ((rest (split-char char))
1401 (setq code (logior (lsh code 8)
1403 (decode-char ccs code)))))
1404 ;; (char-db-update-comment)
1405 (set-buffer-modified-p nil)
1406 (view-mode the-buf (lambda (buf)
1407 (set-window-configuration
1408 what-character-original-window-configuration)
1410 (goto-char (point-min)))
1412 (set-window-configuration
1413 what-character-original-window-configuration)
1414 (signal (car err) (cdr err)))))))
1420 (provide 'char-db-util)
1422 ;;; char-db-util.el ends here