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 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
270 ;;; @ char-db formatters
273 (defun char-db-make-char-spec (char)
275 (cond ((characterp char)
276 (cond ((and (setq ret (encode-char char '=ucs 'defined-only))
277 (not (and (<= #xE000 ret)(<= ret #xF8FF))))
278 (setq char-spec (list (cons '=ucs ret)))
279 (cond ((setq ret (get-char-attribute char 'name))
280 (setq char-spec (cons (cons 'name ret) char-spec))
282 ((setq ret (get-char-attribute char 'name*))
283 (setq char-spec (cons (cons 'name* ret) char-spec))
286 ((encode-char char '=adobe-japan1 'defined-only)
288 (dolist (ccs (charset-list))
289 (if (and (or (memq ccs
298 ;; (eq (charset-property ccs 'iso-ir) 177)
299 (string-match "=ucs@" (symbol-name ccs))
301 (setq ccs (charset-name ccs))
302 (null (assq ccs char-spec))
303 (setq ret (encode-char char ccs 'defined-only)))
304 (setq char-spec (cons (cons ccs ret) char-spec))))
308 (let ((rest char-db-coded-charset-priority-list)
311 (setq ccs (charset-name
312 (find-charset (car rest))))
314 (encode-char char ccs
316 (throw 'tag (cons ccs ret)))
317 (setq rest (cdr rest))))))
318 (setq char-spec (list ret))
319 (dolist (ccs (delq (car ret) (charset-list)))
320 (if (and (or (charset-iso-final-char 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 (setq char-spec (split-char char)))
336 (cond ((setq ret (get-char-attribute char 'name))
337 (setq char-spec (cons (cons 'name ret) char-spec))
339 ((setq ret (get-char-attribute char 'name*))
340 (setq char-spec (cons (cons 'name* ret) char-spec))
343 ((setq ret (get-char-attribute
344 char 'ideographic-combination))
346 (cons (cons 'ideographic-combination ret)
353 (defun char-db-insert-char-spec (char &optional readable column
356 (setq column (current-column)))
357 (let (char-spec temp-char)
358 (setq char-spec (char-db-make-char-spec char))
359 (unless (or (characterp char) ; char
361 (setq char (find-char char-spec))
363 ;; define temporary character
364 ;; Current implementation is dirty.
365 (setq temp-char (define-char (cons '(ideograph-daikanwa . 0)
367 (remove-char-attribute temp-char 'ideograph-daikanwa)
368 (setq char temp-char))
369 (insert-char-attributes char
371 (union (mapcar #'car char-spec)
375 ;; undefine temporary character
376 ;; Current implementation is dirty.
377 (setq char-spec (char-attribute-alist temp-char))
379 (remove-char-attribute temp-char (car (car char-spec)))
380 (setq char-spec (cdr char-spec))))))
382 (defun char-db-insert-alist (alist &optional readable column)
384 (setq column (current-column)))
386 (concat "\n" (make-string (1+ column) ?\ )))
390 lbs cell rest separator)
393 (setq name (car (car alist))
394 value (cdr (car alist)))
395 (cond ((eq name 'char)
397 (if (setq ret (condition-case nil
405 (setq key (car (car value)))
406 ;; (if (find-charset key)
407 ;; (setq cal (cons key cal))
408 (setq al (cons key al))
410 (setq value (cdr value)))
411 (insert-char-attributes ret
415 (insert (prin1-to-string value)))
417 (insert line-breaking))
419 (insert (format "(%-18s " name))
420 (setq lbs (concat "\n" (make-string (current-column) ?\ )))
422 (setq cell (car value))
423 (if (and (consp cell)
425 (setq ret (condition-case nil
435 (setq key (car (car rest)))
436 ;; (if (find-charset key)
437 ;; (setq cal (cons key cal))
438 (setq al (cons key al))
440 (setq rest (cdr rest)))
443 (insert-char-attributes ret
447 (setq separator lbs))
450 (insert (prin1-to-string cell))
451 (setq separator " "))
452 (setq value (cdr value)))
454 (insert line-breaking))
456 (insert (format "(%-18s . %S)%s"
459 (setq alist (cdr alist))))
462 (defun char-db-insert-char-reference (plist &optional readable column)
464 (setq column (current-column)))
466 (concat "\n" (make-string (1+ column) ?\ )))
471 (setq name (pop plist))
472 (setq value (pop plist))
473 (cond ((eq name :char)
476 (cond ((numberp value)
477 (setq value (decode-char '=ucs value)))
479 ;; (setq value (or (find-char value)
482 (char-db-insert-char-spec value readable)
483 (insert line-breaking)
486 (insert (format "%s%s\t%d ; %c%s"
489 (ideographic-radical value)
493 (insert (format "%s%s\t%S" separator name value))
494 (setq separator line-breaking)))
498 (defun char-db-decode-isolated-char (ccs code-point)
501 (cond ((eq ccs 'arabic-iso8859-6)
502 (decode-char ccs code-point))
503 ((and (memq ccs '(=gt-pj-1
514 (setq ret (decode-char ccs code-point))
515 (setq ret (encode-char ret '=gt 'defined-only)))
516 (decode-builtin-char '=gt ret))
518 (decode-builtin-char ccs code-point))))
519 (cond ((and (<= 0 (char-int ret))
520 (<= (char-int ret) #x1F))
521 (decode-char '=ucs (+ #x2400 (char-int ret))))
522 ((= (char-int ret) #x7F)
526 (defvar char-db-convert-obsolete-format t)
528 (defun char-db-insert-ccs-feature (name value line-breaking)
534 ((memq name '(=shinjigen
536 =shinjigen@rev =shinjigen/+p@rev
537 =daikanwa/ho =>>daikanwa/ho =>daikanwa/ho))
538 "(%-18s . %04d)\t; %c")
539 ((eq name '=shinjigen@1ed/24pr)
540 "(%-18s . %04d)\t; %c")
541 ((or (memq name '(=daikanwa =>>daikanwa =>daikanwa
542 =daikanwa@rev1 =daikanwa@rev2
543 =daikanwa/+p =>>daikanwa/+p
544 =daikanwa/+2p =>>daikanwa/+2p
545 =gt =>>>gt =>>gt =+>gt =>gt
547 =adobe-japan1-0 =>>>adobe-japan1-0
548 =adobe-japan1-1 =>>>adobe-japan1-1
549 =adobe-japan1-2 =>>>adobe-japan1-2
550 =adobe-japan1-3 =>>>adobe-japan1-3
551 =adobe-japan1-4 =>>>adobe-japan1-4
552 =adobe-japan1-5 =>>>adobe-japan1-5
553 =adobe-japan1-6 =>>>adobe-japan1-6
554 =>>adobe-japan1-0 =+>adobe-japan1-0
555 =>>adobe-japan1-1 =+>adobe-japan1-1
556 =>>adobe-japan1-2 =+>adobe-japan1-2
557 =>>adobe-japan1-3 =+>adobe-japan1-3
558 =>>adobe-japan1-4 =+>adobe-japan1-4
559 =>>adobe-japan1-5 =+>adobe-japan1-5
560 =>>adobe-japan1-6 =+>adobe-japan1-6
562 =zinbun-oracle =>zinbun-oracle))
563 ;; (string-match "^=adobe-" (symbol-name name))
565 "(%-18s . %05d)\t; %c")
566 ((memq name '(=hanyo-denshi/ks =>>>hanyo-denshi/ks =>>hanyo-denshi/ks mojikyo))
567 "(%-18s . %06d)\t; %c")
568 ((>= (charset-dimension name) 2)
569 "(%-18s . #x%04X)\t; %c")
571 "(%-18s . #x%02X)\t; %c"))
573 (if (= (charset-iso-graphic-plane name) 1)
575 (cond ((= (charset-dimension name) 1)
577 ((= (charset-dimension name) 2)
579 ((= (charset-dimension name) 3)
583 (char-db-decode-isolated-char name value)))
584 (if (and (= (charset-chars name) 94)
585 (= (charset-dimension name) 2))
586 (insert (format " [%02d-%02d]"
587 (- (lsh value -8) 32)
588 (- (logand value 255) 32))))
591 (insert (format "(%-18s . %s)" name value))
593 (insert line-breaking))
595 (defun char-db-insert-relation-feature (char name value line-breaking
597 (insert (format "(%-18s%s " name line-breaking))
598 (let ((lbs (concat "\n" (make-string (current-column) ?\ )))
599 separator cell sources required-features
602 (setq cell (car value))
604 (setq cell (decode-char '=ucs cell)))
606 ((eq name '->subsumptive)
607 (when (or (not (some (lambda (atr)
608 (get-char-attribute cell atr))
609 char-db-ignored-attributes))
611 (encode-char cell ccs 'defined-only))
615 (let ((char-db-ignored-attributes
617 char-db-ignored-attributes)))
618 (insert-char-attributes cell readable nil nil 'for-sub-node))
619 (setq separator lbs))
624 char (intern (format "%s*sources" name))))
625 (setq required-features nil)
626 (dolist (source sources)
630 shinjigen shinjigen@1ed shinjigen@rev))
631 (setq required-features
632 (union required-features
644 =shinjigen/+p@rev))))
646 (setq required-features
647 (union required-features
652 ((find-charset (setq ret (intern (format "=%s" source))))
653 (setq required-features
654 (cons ret required-features)))
655 (t (setq required-features
656 (cons source required-features)))))
657 (cond ((string-match "@JP" (symbol-name name))
658 (setq required-features
659 (union required-features
667 ((string-match "@CN" (symbol-name name))
668 (setq required-features
669 (union required-features
676 (insert (format "%S" cell))
677 (char-db-insert-char-spec cell readable
680 (setq separator lbs))
684 (if (consp (car cell))
685 (char-db-insert-char-spec cell readable)
686 (char-db-insert-char-reference cell readable))
687 (setq separator lbs))
691 (insert (prin1-to-string cell))
692 (setq separator " ")))
693 (setq value (cdr value)))
695 (insert line-breaking)))
697 (defun insert-char-attributes (char &optional readable attributes column
700 (setq column (current-column)))
701 (let (name value ; has-long-ccs-name
705 (concat "\n" (make-string (1+ column) ?\ )))
706 lbs cell separator ret
708 dest-ccss ; sources required-features
713 (if (consp attributes)
715 (dolist (name attributes)
716 (unless (memq name char-db-ignored-attributes)
717 (if (find-charset name)
721 (dolist (name (char-attribute-list))
722 (unless (memq name char-db-ignored-attributes)
723 (if (find-charset name)
727 #'char-attribute-name<)))
729 (when (memq '<-subsumptive attributes)
730 (when (or readable (not for-sub-node))
731 (when (setq value (get-char-attribute char '<-subsumptive))
732 (char-db-insert-relation-feature char '<-subsumptive value
735 (setq attributes (delq '<-subsumptive attributes)))
736 (when (and (memq '<-denotational attributes)
737 (setq value (get-char-attribute char '<-denotational)))
738 (char-db-insert-relation-feature char '<-denotational value
741 (setq attributes (delq '<-denotational attributes)))
742 (when (and (memq 'name attributes)
743 (setq value (get-char-attribute char 'name)))
745 (if (> (+ (current-column) (length value)) 48)
748 value line-breaking))
749 (setq attributes (delq 'name attributes))
751 (when (and (memq 'name* attributes)
752 (setq value (get-char-attribute char 'name*)))
754 (if (> (+ (current-column) (length value)) 48)
757 value line-breaking))
758 (setq attributes (delq 'name* attributes))
760 (when (and (memq 'script attributes)
761 (setq value (get-char-attribute char 'script)))
762 (insert (format "(script\t\t%s)%s"
763 (mapconcat (function prin1-to-string)
766 (setq attributes (delq 'script attributes))
768 (dolist (name '(=>ucs =>ucs*))
769 (when (and (memq name attributes)
770 (setq value (get-char-attribute char name)))
771 (insert (format "(%-18s . #x%04X)\t; %c%s"
772 name value (decode-char '=ucs value)
774 (setq attributes (delq name attributes))))
775 (dolist (name '(=>ucs@gb =>ucs@big5))
776 (when (and (memq name attributes)
777 (setq value (get-char-attribute char name)))
778 (insert (format "(%-18s . #x%04X)\t; %c%s"
783 (symbol-name name) 2)))
786 (setq attributes (delq name attributes))
788 ;; (dolist (name '(=>daikanwa))
789 ;; (when (and (memq name attributes)
790 ;; (setq value (get-char-attribute char name)))
792 ;; (if (integerp value)
793 ;; (format "(%-18s . %05d)\t; %c%s"
794 ;; name value (decode-char '=daikanwa value)
796 ;; (format "(%-18s %s)\t; %c%s"
798 ;; (mapconcat (function prin1-to-string)
800 ;; (char-representative-of-daikanwa char)
802 ;; (setq attributes (delq name attributes))))
803 (when (and (memq 'general-category attributes)
804 (setq value (get-char-attribute char 'general-category)))
806 "(general-category\t%s) ; %s%s"
807 (mapconcat (lambda (cell)
810 (cond ((rassoc value unidata-normative-category-alist)
811 "Normative Category")
812 ((rassoc value unidata-informative-category-alist)
813 "Informative Category")
817 (setq attributes (delq 'general-category attributes))
819 (when (and (memq 'bidi-category attributes)
820 (setq value (get-char-attribute char 'bidi-category)))
821 (insert (format "(bidi-category\t. %S)%s"
824 (setq attributes (delq 'bidi-category attributes))
826 (unless (or (not (memq 'mirrored attributes))
827 (eq (setq value (get-char-attribute char 'mirrored 'empty))
829 (insert (format "(mirrored\t\t. %S)%s"
832 (setq attributes (delq 'mirrored attributes))
835 ((and (memq 'decimal-digit-value attributes)
836 (setq value (get-char-attribute char 'decimal-digit-value)))
837 (insert (format "(decimal-digit-value . %S)%s"
840 (setq attributes (delq 'decimal-digit-value attributes))
841 (when (and (memq 'digit-value attributes)
842 (setq value (get-char-attribute char 'digit-value)))
843 (insert (format "(digit-value\t . %S)%s"
846 (setq attributes (delq 'digit-value attributes))
848 (when (and (memq 'numeric-value attributes)
849 (setq value (get-char-attribute char 'numeric-value)))
850 (insert (format "(numeric-value\t . %S)%s"
853 (setq attributes (delq 'numeric-value attributes))
857 (when (and (memq 'digit-value attributes)
858 (setq value (get-char-attribute char 'digit-value)))
859 (insert (format "(digit-value\t. %S)%s"
862 (setq attributes (delq 'digit-value attributes))
864 (when (and (memq 'numeric-value attributes)
865 (setq value (get-char-attribute char 'numeric-value)))
866 (insert (format "(numeric-value\t. %S)%s"
869 (setq attributes (delq 'numeric-value attributes))
871 (when (and (memq 'iso-10646-comment attributes)
872 (setq value (get-char-attribute char 'iso-10646-comment)))
873 (insert (format "(iso-10646-comment\t. %S)%s"
876 (setq attributes (delq 'iso-10646-comment attributes))
878 (when (and (memq 'morohashi-daikanwa attributes)
879 (setq value (get-char-attribute char 'morohashi-daikanwa)))
880 (insert (format "(morohashi-daikanwa\t%s)%s"
881 (mapconcat (function prin1-to-string) value " ")
883 (setq attributes (delq 'morohashi-daikanwa attributes))
887 (when (and (memq 'ideographic-radical attributes)
888 (setq value (get-char-attribute char 'ideographic-radical)))
890 (insert (format "(ideographic-radical . %S)\t; %c%s"
892 (ideographic-radical radical)
894 (setq attributes (delq 'ideographic-radical attributes))
896 (when (and (memq 'shuowen-radical attributes)
897 (setq value (get-char-attribute char 'shuowen-radical)))
898 (insert (format "(shuowen-radical\t. %S)\t; %c%s"
900 (shuowen-radical value)
902 (setq attributes (delq 'shuowen-radical attributes))
907 char-db-feature-domains
909 (dolist (feature (char-attribute-list))
910 (setq feature (symbol-name feature))
912 "\\(radical\\|strokes\\)@\\([^@*]+\\)\\(\\*\\|$\\)"
914 (setq domain (intern (match-string 2 feature)))
915 (unless (memq domain dest)
916 (setq dest (cons domain dest)))))
917 (sort dest #'string<))))
918 (setq key (intern (format "%s@%s" 'ideographic-radical domain)))
919 (when (and (memq key attributes)
920 (setq value (get-char-attribute char key)))
922 (insert (format "(%s . %S)\t; %c%s"
925 (ideographic-radical radical)
927 (setq attributes (delq key attributes))
929 (setq key (intern (format "%s@%s" 'ideographic-strokes domain)))
930 (when (and (memq key attributes)
931 (setq value (get-char-attribute char key)))
933 (insert (format "(%s . %S)%s"
937 (setq attributes (delq key attributes))
939 (setq key (intern (format "%s@%s" 'total-strokes domain)))
940 (when (and (memq key attributes)
941 (setq value (get-char-attribute char key)))
942 (insert (format "(%s . %S)%s"
946 (setq attributes (delq key attributes))
948 (dolist (feature '(ideographic-radical
951 (setq key (intern (format "%s@%s*sources" feature domain)))
952 (when (and (memq key attributes)
953 (setq value (get-char-attribute char key)))
954 (insert (format "(%s%s" key line-breaking))
956 (insert (format " %s" cell)))
958 (insert line-breaking)
959 (setq attributes (delq key attributes))
962 (when (and (memq 'ideographic-strokes attributes)
963 (setq value (get-char-attribute char 'ideographic-strokes)))
965 (insert (format "(ideographic-strokes . %S)%s"
968 (setq attributes (delq 'ideographic-strokes attributes))
970 (when (and (memq 'kangxi-radical attributes)
971 (setq value (get-char-attribute char 'kangxi-radical)))
972 (unless (eq value radical)
973 (insert (format "(kangxi-radical\t . %S)\t; %c%s"
975 (ideographic-radical value)
978 (setq radical value)))
979 (setq attributes (delq 'kangxi-radical attributes))
981 (when (and (memq 'kangxi-strokes attributes)
982 (setq value (get-char-attribute char 'kangxi-strokes)))
983 (unless (eq value strokes)
984 (insert (format "(kangxi-strokes\t . %S)%s"
988 (setq strokes value)))
989 (setq attributes (delq 'kangxi-strokes attributes))
991 (when (and (memq 'japanese-radical attributes)
992 (setq value (get-char-attribute char 'japanese-radical)))
993 (unless (eq value radical)
994 (insert (format "(japanese-radical\t . %S)\t; %c%s"
996 (ideographic-radical value)
999 (setq radical value)))
1000 (setq attributes (delq 'japanese-radical attributes))
1002 (when (and (memq 'japanese-strokes attributes)
1003 (setq value (get-char-attribute char 'japanese-strokes)))
1004 (unless (eq value strokes)
1005 (insert (format "(japanese-strokes\t . %S)%s"
1009 (setq strokes value)))
1010 (setq attributes (delq 'japanese-strokes attributes))
1012 (when (and (memq 'cns-radical attributes)
1013 (setq value (get-char-attribute char 'cns-radical)))
1014 (insert (format "(cns-radical\t . %S)\t; %c%s"
1016 (ideographic-radical value)
1018 (setq attributes (delq 'cns-radical attributes))
1020 (when (and (memq 'cns-strokes attributes)
1021 (setq value (get-char-attribute char 'cns-strokes)))
1022 (unless (eq value strokes)
1023 (insert (format "(cns-strokes\t . %S)%s"
1027 (setq strokes value)))
1028 (setq attributes (delq 'cns-strokes attributes))
1030 ;; (when (and (memq 'shinjigen-1-radical attributes)
1031 ;; (setq value (get-char-attribute char 'shinjigen-1-radical)))
1032 ;; (unless (eq value radical)
1033 ;; (insert (format "(shinjigen-1-radical . %S)\t; %c%s"
1035 ;; (ideographic-radical value)
1038 ;; (setq radical value)))
1039 ;; (setq attributes (delq 'shinjigen-1-radical attributes))
1041 (when (and (memq 'ideographic- attributes)
1042 (setq value (get-char-attribute char 'ideographic-)))
1043 (insert "(ideographic- ")
1044 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1046 (while (consp value)
1047 (setq cell (car value))
1049 (setq cell (decode-char '=ucs cell)))
1050 (cond ((characterp cell)
1054 (insert (format "%S" cell))
1055 (char-db-insert-char-spec cell readable))
1056 (setq separator lbs))
1060 (if (consp (car cell))
1061 (char-db-insert-char-spec cell readable)
1062 (char-db-insert-char-reference cell readable))
1063 (setq separator lbs))
1067 (insert (prin1-to-string cell))
1068 (setq separator " ")))
1069 (setq value (cdr value)))
1071 (insert line-breaking)
1072 (setq attributes (delq 'ideographic- attributes)))
1073 (when (and (memq 'total-strokes attributes)
1074 (setq value (get-char-attribute char 'total-strokes)))
1075 (insert (format "(total-strokes . %S)%s"
1078 (setq attributes (delq 'total-strokes attributes))
1080 (when (and (memq '->ideograph attributes)
1081 (setq value (get-char-attribute char '->ideograph)))
1082 (insert (format "(->ideograph\t%s)%s"
1083 (mapconcat (lambda (code)
1084 (cond ((symbolp code)
1087 (format "#x%04X" code))
1090 line-breaking code))))
1093 (setq attributes (delq '->ideograph attributes))
1095 ;; (when (and (memq '->decomposition attributes)
1096 ;; (setq value (get-char-attribute char '->decomposition)))
1097 ;; (insert (format "(->decomposition\t%s)%s"
1098 ;; (mapconcat (lambda (code)
1099 ;; (cond ((symbolp code)
1100 ;; (symbol-name code))
1101 ;; ((characterp code)
1103 ;; (format "%S" code)
1108 ;; (format "#x%04X" code))
1110 ;; (format "%s%S" line-breaking code))))
1113 ;; (setq attributes (delq '->decomposition attributes))
1115 (if (equal (get-char-attribute char '->titlecase)
1116 (get-char-attribute char '->uppercase))
1117 (setq attributes (delq '->titlecase attributes)))
1118 (when (and (memq '->mojikyo attributes)
1119 (setq value (get-char-attribute char '->mojikyo)))
1120 (insert (format "(->mojikyo\t\t. %06d)\t; %c%s"
1121 value (decode-char 'mojikyo value)
1123 (setq attributes (delq '->mojikyo attributes))
1125 (when (and (memq 'hanyu-dazidian-vol attributes)
1126 (setq value (get-char-attribute char 'hanyu-dazidian-vol)))
1127 (insert (format "(hanyu-dazidian-vol . %d)%s"
1128 value line-breaking))
1129 (setq attributes (delq 'hanyu-dazidian-vol attributes))
1131 (when (and (memq 'hanyu-dazidian-page attributes)
1132 (setq value (get-char-attribute char 'hanyu-dazidian-page)))
1133 (insert (format "(hanyu-dazidian-page . %d)%s"
1134 value line-breaking))
1135 (setq attributes (delq 'hanyu-dazidian-page attributes))
1137 (when (and (memq 'hanyu-dazidian-char attributes)
1138 (setq value (get-char-attribute char 'hanyu-dazidian-char)))
1139 (insert (format "(hanyu-dazidian-char . %d)%s"
1140 value line-breaking))
1141 (setq attributes (delq 'hanyu-dazidian-char attributes))
1144 (dolist (ignored '(composition
1145 ->denotational <-subsumptive ->ucs-unified
1146 ->ideographic-component-forms))
1147 (setq attributes (delq ignored attributes))))
1149 (setq name (car attributes))
1150 (unless (eq (setq value (get-char-attribute char name 'value-is-empty))
1152 (cond ((setq ret (find-charset name))
1153 (setq name (charset-name ret))
1154 (when (not (memq name dest-ccss))
1155 (setq dest-ccss (cons name dest-ccss))
1156 (char-db-insert-ccs-feature name value line-breaking))
1158 ((string-match "^=>ucs@" (symbol-name name))
1159 (insert (format "(%-18s . #x%04X)\t; %c%s"
1160 name value (decode-char '=ucs value)
1163 ((eq name 'jisx0208-1978/4X)
1164 (insert (format "(%-18s . #x%04X)%s"
1170 (not (eq name '->subsumptive))
1171 (not (eq name '->uppercase))
1172 (not (eq name '->lowercase))
1173 (not (eq name '->titlecase))
1174 (not (eq name '->canonical))
1175 (not (eq name '->Bopomofo))
1176 (not (eq name '->mistakable))
1177 (not (eq name '->ideographic-variants))
1178 (null (get-char-attribute
1179 char (intern (format "%s*sources" name))))
1180 (not (string-match "\\*sources$" (symbol-name name)))
1181 (null (get-char-attribute
1182 char (intern (format "%s*note" name))))
1183 (not (string-match "\\*note$" (symbol-name name)))
1184 (or (eq name '<-identical)
1185 (eq name '<-uppercase)
1186 (eq name '<-lowercase)
1187 (eq name '<-titlecase)
1188 (eq name '<-canonical)
1189 (eq name '<-ideographic-variants)
1190 ;; (eq name '<-synonyms)
1191 (string-match "^<-synonyms" (symbol-name name))
1192 (eq name '<-mistakable)
1193 (when (string-match "^->" (symbol-name name))
1195 ((string-match "^->fullwidth" (symbol-name name))
1196 (not (and (consp value)
1197 (characterp (car value))
1199 (car value) '=ucs 'defined-only)))
1204 ((or (eq name 'ideographic-structure)
1205 (eq name 'ideographic-combination)
1206 (eq name 'ideographic-)
1207 (eq name '=decomposition)
1208 (char-feature-base-name= '=decomposition name)
1209 (char-feature-base-name= '=>decomposition name)
1210 ;; (string-match "^=>*decomposition\\(@[^*]+\\)?$"
1211 ;; (symbol-name name))
1212 (string-match "^\\(->\\|<-\\)[^*]*$" (symbol-name name))
1213 (string-match "^\\(->\\|<-\\)[^*]*\\*sources$"
1216 (char-db-insert-relation-feature char name value
1219 ((memq name '(ideograph=
1220 original-ideograph-of
1221 ancient-ideograph-of
1224 ;; simplified-ideograph-of
1225 ideographic-variants
1226 ;; ideographic-different-form-of
1228 (insert (format "(%-18s%s " name line-breaking))
1229 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1231 (while (consp value)
1232 (setq cell (car value))
1233 (if (and (consp cell)
1238 (char-db-insert-alist cell readable)
1239 (setq separator lbs))
1242 (insert (prin1-to-string cell))
1243 (setq separator " "))
1244 (setq value (cdr value)))
1246 (insert line-breaking))
1248 (insert (format "(%-18s " name))
1249 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1251 (while (consp value)
1252 (setq cell (car value))
1253 (if (and (consp cell)
1255 (setq ret (condition-case nil
1263 (setq key (car (car rest)))
1264 (if (find-charset key)
1265 (setq cal (cons key cal))
1266 (setq al (cons key al)))
1267 (setq rest (cdr rest)))
1270 (insert-char-attributes ret
1274 (setq separator lbs))
1275 (setq ret (prin1-to-string cell))
1277 (if (< (+ (current-column)
1284 (setq separator " "))
1285 (setq value (cdr value)))
1287 (insert line-breaking))
1289 (insert (format "(%-18s" name))
1290 (setq ret (prin1-to-string value))
1291 (unless (< (+ (current-column)
1295 (insert line-breaking))
1296 (insert " . " ret ")" line-breaking)
1297 ;; (insert (format "(%-18s . %S)%s"
1302 (setq attributes (cdr attributes)))
1305 (defun insert-char-data (char &optional readable
1308 (narrow-to-region (point)(point))
1309 (insert "(define-char
1311 (insert-char-attributes char readable attributes)
1313 (goto-char (point-min))
1314 (while (re-search-forward "[ \t]+$" nil t)
1317 (goto-char (point-min))
1318 (while (re-search-forward "[ \t][ \t][ \t]*" nil t)
1319 (let ((column (current-column))
1320 (indent-tabs-mode t))
1321 (delete-region (match-beginning 0) (point))
1322 (indent-to column)))
1323 (goto-char (point-max))
1324 ;; (tabify (point-min)(point-max))
1327 (defun insert-char-data-with-variant (char &optional printable
1329 script excluded-script)
1330 (insert-char-data char printable)
1331 (let ((variants (char-variants char))
1334 (setq variants (sort variants #'<))
1335 (setq rest variants)
1336 (setq variants (cons char variants))
1338 (setq variant (car rest))
1339 (unless (get-char-attribute variant '<-subsumptive)
1340 (if (and (or (null script)
1341 (null (setq vs (get-char-attribute variant 'script)))
1343 (or (null excluded-script)
1344 (null (setq vs (get-char-attribute variant 'script)))
1345 (not (memq excluded-script vs))))
1346 (unless (and no-ucs-unified (get-char-attribute variant '=ucs))
1347 (insert-char-data variant printable)
1348 (if (setq ret (char-variants variant))
1350 (or (memq (car ret) variants)
1351 ;; (get-char-attribute (car ret) '<-subsumptive)
1352 (setq rest (nconc rest (list (car ret)))))
1353 (setq ret (cdr ret)))))))
1354 (setq rest (cdr rest)))))
1356 (defun insert-char-range-data (min max &optional script excluded-script)
1359 (while (<= code max)
1360 (setq char (decode-char '=ucs code))
1361 (if (encode-char char '=ucs 'defined-only)
1362 (insert-char-data-with-variant char nil 'no-ucs-unified
1363 script excluded-script))
1364 (setq code (1+ code)))))
1366 (defun write-char-range-data-to-file (min max file
1367 &optional script excluded-script)
1368 (let ((coding-system-for-write char-db-file-coding-system))
1370 (insert (format ";; -*- coding: %s -*-\n"
1371 char-db-file-coding-system))
1372 (insert-char-range-data min max script excluded-script)
1373 (write-region (point-min)(point-max) file))))
1375 (defvar what-character-original-window-configuration)
1378 (defun what-char-definition (char)
1379 (interactive (list (char-after)))
1380 (let ((buf (get-buffer-create "*Character Description*"))
1381 (the-buf (current-buffer))
1382 (win-conf (current-window-configuration)))
1384 (make-local-variable 'what-character-original-window-configuration)
1385 (setq what-character-original-window-configuration win-conf)
1386 (setq buffer-read-only nil)
1390 (insert-char-data-with-variant char 'printable)
1391 (unless (char-attribute-alist char)
1392 (insert (format ";; = %c\n"
1393 (let* ((rest (split-char char))
1397 (setq code (logior (lsh code 8)
1399 (decode-char ccs code)))))
1400 ;; (char-db-update-comment)
1401 (set-buffer-modified-p nil)
1402 (view-mode the-buf (lambda (buf)
1403 (set-window-configuration
1404 what-character-original-window-configuration)
1406 (goto-char (point-min)))
1408 (set-window-configuration
1409 what-character-original-window-configuration)
1410 (signal (car err) (cdr err)))))))
1416 (provide 'char-db-util)
1418 ;;; char-db-util.el ends here