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
256 ;;; @ char-db formatters
259 (defun char-db-make-char-spec (char)
261 (cond ((characterp char)
262 (cond ((and (setq ret (encode-char char '=ucs 'defined-only))
263 (not (and (<= #xE000 ret)(<= ret #xF8FF))))
264 (setq char-spec (list (cons '=ucs ret)))
265 (cond ((setq ret (get-char-attribute char 'name))
266 (setq char-spec (cons (cons 'name ret) char-spec))
268 ((setq ret (get-char-attribute char 'name*))
269 (setq char-spec (cons (cons 'name* ret) char-spec))
272 ((encode-char char '=adobe-japan1 'defined-only)
274 (dolist (ccs (charset-list))
275 (if (and (or (memq ccs
284 ;; (eq (charset-property ccs 'iso-ir) 177)
285 (string-match "=ucs@" (symbol-name ccs))
287 (setq ccs (charset-name ccs))
288 (null (assq ccs char-spec))
289 (setq ret (encode-char char ccs 'defined-only)))
290 (setq char-spec (cons (cons ccs ret) char-spec))))
294 (let ((rest char-db-coded-charset-priority-list)
297 (setq ccs (charset-name
298 (find-charset (car rest))))
300 (encode-char char ccs
302 (throw 'tag (cons ccs ret)))
303 (setq rest (cdr rest))))))
304 (setq char-spec (list ret))
305 (dolist (ccs (delq (car ret) (charset-list)))
306 (if (and (or (charset-iso-final-char ccs)
313 (eq (charset-property ccs 'iso-ir) 177)
314 ;; (string-match "=ucs@" (symbol-name ccs))
316 (setq ccs (charset-name ccs))
317 (null (assq ccs char-spec))
318 (setq ret (encode-char char ccs 'defined-only)))
319 (setq char-spec (cons (cons ccs ret) char-spec))))
321 (setq char-spec (split-char char)))
322 (cond ((setq ret (get-char-attribute char 'name))
323 (setq char-spec (cons (cons 'name ret) char-spec))
325 ((setq ret (get-char-attribute char 'name*))
326 (setq char-spec (cons (cons 'name* ret) char-spec))
329 ((setq ret (get-char-attribute
330 char 'ideographic-combination))
332 (cons (cons 'ideographic-combination ret)
339 (defun char-db-insert-char-spec (char &optional readable column
342 (setq column (current-column)))
343 (let (char-spec temp-char)
344 (setq char-spec (char-db-make-char-spec char))
345 (unless (or (characterp char) ; char
347 (setq char (find-char char-spec))
349 ;; define temporary character
350 ;; Current implementation is dirty.
351 (setq temp-char (define-char (cons '(ideograph-daikanwa . 0)
353 (remove-char-attribute temp-char 'ideograph-daikanwa)
354 (setq char temp-char))
355 (insert-char-attributes char
357 (union (mapcar #'car char-spec)
361 ;; undefine temporary character
362 ;; Current implementation is dirty.
363 (setq char-spec (char-attribute-alist temp-char))
365 (remove-char-attribute temp-char (car (car char-spec)))
366 (setq char-spec (cdr char-spec))))))
368 (defun char-db-insert-alist (alist &optional readable column)
370 (setq column (current-column)))
372 (concat "\n" (make-string (1+ column) ?\ )))
376 lbs cell rest separator)
379 (setq name (car (car alist))
380 value (cdr (car alist)))
381 (cond ((eq name 'char)
383 (if (setq ret (condition-case nil
391 (setq key (car (car value)))
392 ;; (if (find-charset key)
393 ;; (setq cal (cons key cal))
394 (setq al (cons key al))
396 (setq value (cdr value)))
397 (insert-char-attributes ret
401 (insert (prin1-to-string value)))
403 (insert line-breaking))
405 (insert (format "(%-18s " name))
406 (setq lbs (concat "\n" (make-string (current-column) ?\ )))
408 (setq cell (car value))
409 (if (and (consp cell)
411 (setq ret (condition-case nil
421 (setq key (car (car rest)))
422 ;; (if (find-charset key)
423 ;; (setq cal (cons key cal))
424 (setq al (cons key al))
426 (setq rest (cdr rest)))
429 (insert-char-attributes ret
433 (setq separator lbs))
436 (insert (prin1-to-string cell))
437 (setq separator " "))
438 (setq value (cdr value)))
440 (insert line-breaking))
442 (insert (format "(%-18s . %S)%s"
445 (setq alist (cdr alist))))
448 (defun char-db-insert-char-reference (plist &optional readable column)
450 (setq column (current-column)))
452 (concat "\n" (make-string (1+ column) ?\ )))
457 (setq name (pop plist))
458 (setq value (pop plist))
459 (cond ((eq name :char)
462 (cond ((numberp value)
463 (setq value (decode-char '=ucs value)))
465 ;; (setq value (or (find-char value)
468 (char-db-insert-char-spec value readable)
469 (insert line-breaking)
472 (insert (format "%s%s\t%d ; %c%s"
475 (ideographic-radical value)
479 (insert (format "%s%s\t%S" separator name value))
480 (setq separator line-breaking)))
484 (defun char-db-decode-isolated-char (ccs code-point)
487 (cond ((eq ccs 'arabic-iso8859-6)
488 (decode-char ccs code-point))
489 ((and (memq ccs '(=gt-pj-1
500 (setq ret (decode-char ccs code-point))
501 (setq ret (encode-char ret '=gt 'defined-only)))
502 (decode-builtin-char '=gt ret))
504 (decode-builtin-char ccs code-point))))
505 (cond ((and (<= 0 (char-int ret))
506 (<= (char-int ret) #x1F))
507 (decode-char '=ucs (+ #x2400 (char-int ret))))
508 ((= (char-int ret) #x7F)
512 (defvar char-db-convert-obsolete-format t)
514 (defun char-db-insert-ccs-feature (name value line-breaking)
520 ((memq name '(=shinjigen
522 =shinjigen@rev =shinjigen/+p@rev
523 =daikanwa/ho =>>daikanwa/ho =>daikanwa/ho))
524 "(%-18s . %04d)\t; %c")
525 ((eq name '=shinjigen@1ed/24pr)
526 "(%-18s . %04d)\t; %c")
527 ((or (memq name '(=daikanwa =>>daikanwa =>daikanwa
528 =daikanwa@rev1 =daikanwa@rev2
529 =daikanwa/+p =>>daikanwa/+p
530 =daikanwa/+2p =>>daikanwa/+2p
531 =gt =>>>gt =>>gt =+>gt =>gt
533 =adobe-japan1-0 =>>>adobe-japan1-0 =>>adobe-japan1-0
534 =adobe-japan1-1 =>>>adobe-japan1-1 =>>adobe-japan1-1
535 =adobe-japan1-2 =>>>adobe-japan1-2 =>>adobe-japan1-2
536 =adobe-japan1-3 =>>>adobe-japan1-3 =>>adobe-japan1-3
537 =adobe-japan1-4 =>>>adobe-japan1-4 =>>adobe-japan1-4
538 =adobe-japan1-5 =>>>adobe-japan1-5 =>>adobe-japan1-5
539 =adobe-japan1-6 =>>>adobe-japan1-6 =>>adobe-japan1-6
542 =zinbun-oracle =>zinbun-oracle))
543 ;; (string-match "^=adobe-" (symbol-name name))
545 "(%-18s . %05d)\t; %c")
546 ((memq name '(=hanyo-denshi/ks =>>>hanyo-denshi/ks =>>hanyo-denshi/ks mojikyo))
547 "(%-18s . %06d)\t; %c")
548 ((>= (charset-dimension name) 2)
549 "(%-18s . #x%04X)\t; %c")
551 "(%-18s . #x%02X)\t; %c"))
553 (if (= (charset-iso-graphic-plane name) 1)
555 (cond ((= (charset-dimension name) 1)
557 ((= (charset-dimension name) 2)
559 ((= (charset-dimension name) 3)
563 (char-db-decode-isolated-char name value)))
564 (if (and (= (charset-chars name) 94)
565 (= (charset-dimension name) 2))
566 (insert (format " [%02d-%02d]"
567 (- (lsh value -8) 32)
568 (- (logand value 255) 32))))
571 (insert (format "(%-18s . %s)" name value))
573 (insert line-breaking))
575 (defun char-db-insert-relation-feature (char name value line-breaking
577 (insert (format "(%-18s%s " name line-breaking))
578 (let ((lbs (concat "\n" (make-string (current-column) ?\ )))
579 separator cell sources required-features
582 (setq cell (car value))
584 (setq cell (decode-char '=ucs cell)))
586 ((eq name '->subsumptive)
587 (when (or (not (some (lambda (atr)
588 (get-char-attribute cell atr))
589 char-db-ignored-attributes))
591 (encode-char cell ccs 'defined-only))
595 (let ((char-db-ignored-attributes
597 char-db-ignored-attributes)))
598 (insert-char-attributes cell readable nil nil 'for-sub-node))
599 (setq separator lbs))
604 char (intern (format "%s*sources" name))))
605 (setq required-features nil)
606 (dolist (source sources)
610 shinjigen shinjigen@1ed shinjigen@rev))
611 (setq required-features
612 (union required-features
623 (setq required-features
624 (union required-features
629 ((find-charset (setq ret (intern (format "=%s" source))))
630 (setq required-features
631 (cons ret required-features)))
632 (t (setq required-features
633 (cons source required-features)))))
634 (cond ((string-match "@JP" (symbol-name name))
635 (setq required-features
636 (union required-features
644 ((string-match "@CN" (symbol-name name))
645 (setq required-features
646 (union required-features
653 (insert (format "%S" cell))
654 (char-db-insert-char-spec cell readable
657 (setq separator lbs))
661 (if (consp (car cell))
662 (char-db-insert-char-spec cell readable)
663 (char-db-insert-char-reference cell readable))
664 (setq separator lbs))
668 (insert (prin1-to-string cell))
669 (setq separator " ")))
670 (setq value (cdr value)))
672 (insert line-breaking)))
674 (defun insert-char-attributes (char &optional readable attributes column
677 (setq column (current-column)))
678 (let (name value ; has-long-ccs-name
682 (concat "\n" (make-string (1+ column) ?\ )))
683 lbs cell separator ret
685 dest-ccss ; sources required-features
690 (if (consp attributes)
692 (dolist (name attributes)
693 (unless (memq name char-db-ignored-attributes)
694 (if (find-charset name)
698 (dolist (name (char-attribute-list))
699 (unless (memq name char-db-ignored-attributes)
700 (if (find-charset name)
704 #'char-attribute-name<)))
706 (when (memq '<-subsumptive attributes)
707 (when (or readable (not for-sub-node))
708 (when (setq value (get-char-attribute char '<-subsumptive))
709 (char-db-insert-relation-feature char '<-subsumptive value
712 (setq attributes (delq '<-subsumptive attributes)))
713 (when (and (memq '<-denotational attributes)
714 (setq value (get-char-attribute char '<-denotational)))
715 (char-db-insert-relation-feature char '<-denotational value
718 (setq attributes (delq '<-denotational attributes)))
719 (when (and (memq 'name attributes)
720 (setq value (get-char-attribute char 'name)))
722 (if (> (+ (current-column) (length value)) 48)
725 value line-breaking))
726 (setq attributes (delq 'name attributes))
728 (when (and (memq 'name* attributes)
729 (setq value (get-char-attribute char 'name*)))
731 (if (> (+ (current-column) (length value)) 48)
734 value line-breaking))
735 (setq attributes (delq 'name* attributes))
737 (when (and (memq 'script attributes)
738 (setq value (get-char-attribute char 'script)))
739 (insert (format "(script\t\t%s)%s"
740 (mapconcat (function prin1-to-string)
743 (setq attributes (delq 'script attributes))
745 (dolist (name '(=>ucs =>ucs*))
746 (when (and (memq name attributes)
747 (setq value (get-char-attribute char name)))
748 (insert (format "(%-18s . #x%04X)\t; %c%s"
749 name value (decode-char '=ucs value)
751 (setq attributes (delq name attributes))))
752 (dolist (name '(=>ucs@gb =>ucs@big5))
753 (when (and (memq name attributes)
754 (setq value (get-char-attribute char name)))
755 (insert (format "(%-18s . #x%04X)\t; %c%s"
760 (symbol-name name) 2)))
763 (setq attributes (delq name attributes))
765 ;; (dolist (name '(=>daikanwa))
766 ;; (when (and (memq name attributes)
767 ;; (setq value (get-char-attribute char name)))
769 ;; (if (integerp value)
770 ;; (format "(%-18s . %05d)\t; %c%s"
771 ;; name value (decode-char '=daikanwa value)
773 ;; (format "(%-18s %s)\t; %c%s"
775 ;; (mapconcat (function prin1-to-string)
777 ;; (char-representative-of-daikanwa char)
779 ;; (setq attributes (delq name attributes))))
780 (when (and (memq 'general-category attributes)
781 (setq value (get-char-attribute char 'general-category)))
783 "(general-category\t%s) ; %s%s"
784 (mapconcat (lambda (cell)
787 (cond ((rassoc value unidata-normative-category-alist)
788 "Normative Category")
789 ((rassoc value unidata-informative-category-alist)
790 "Informative Category")
794 (setq attributes (delq 'general-category attributes))
796 (when (and (memq 'bidi-category attributes)
797 (setq value (get-char-attribute char 'bidi-category)))
798 (insert (format "(bidi-category\t. %S)%s"
801 (setq attributes (delq 'bidi-category attributes))
803 (unless (or (not (memq 'mirrored attributes))
804 (eq (setq value (get-char-attribute char 'mirrored 'empty))
806 (insert (format "(mirrored\t\t. %S)%s"
809 (setq attributes (delq 'mirrored attributes))
812 ((and (memq 'decimal-digit-value attributes)
813 (setq value (get-char-attribute char 'decimal-digit-value)))
814 (insert (format "(decimal-digit-value . %S)%s"
817 (setq attributes (delq 'decimal-digit-value attributes))
818 (when (and (memq 'digit-value attributes)
819 (setq value (get-char-attribute char 'digit-value)))
820 (insert (format "(digit-value\t . %S)%s"
823 (setq attributes (delq 'digit-value attributes))
825 (when (and (memq 'numeric-value attributes)
826 (setq value (get-char-attribute char 'numeric-value)))
827 (insert (format "(numeric-value\t . %S)%s"
830 (setq attributes (delq 'numeric-value attributes))
834 (when (and (memq 'digit-value attributes)
835 (setq value (get-char-attribute char 'digit-value)))
836 (insert (format "(digit-value\t. %S)%s"
839 (setq attributes (delq 'digit-value attributes))
841 (when (and (memq 'numeric-value attributes)
842 (setq value (get-char-attribute char 'numeric-value)))
843 (insert (format "(numeric-value\t. %S)%s"
846 (setq attributes (delq 'numeric-value attributes))
848 (when (and (memq 'iso-10646-comment attributes)
849 (setq value (get-char-attribute char 'iso-10646-comment)))
850 (insert (format "(iso-10646-comment\t. %S)%s"
853 (setq attributes (delq 'iso-10646-comment attributes))
855 (when (and (memq 'morohashi-daikanwa attributes)
856 (setq value (get-char-attribute char 'morohashi-daikanwa)))
857 (insert (format "(morohashi-daikanwa\t%s)%s"
858 (mapconcat (function prin1-to-string) value " ")
860 (setq attributes (delq 'morohashi-daikanwa attributes))
864 (when (and (memq 'ideographic-radical attributes)
865 (setq value (get-char-attribute char 'ideographic-radical)))
867 (insert (format "(ideographic-radical . %S)\t; %c%s"
869 (ideographic-radical radical)
871 (setq attributes (delq 'ideographic-radical attributes))
873 (when (and (memq 'shuowen-radical attributes)
874 (setq value (get-char-attribute char 'shuowen-radical)))
875 (insert (format "(shuowen-radical\t. %S)\t; %c%s"
877 (shuowen-radical value)
879 (setq attributes (delq 'shuowen-radical attributes))
884 char-db-feature-domains
886 (dolist (feature (char-attribute-list))
887 (setq feature (symbol-name feature))
889 "\\(radical\\|strokes\\)@\\([^@*]+\\)\\(\\*\\|$\\)"
891 (setq domain (intern (match-string 2 feature)))
892 (unless (memq domain dest)
893 (setq dest (cons domain dest)))))
894 (sort dest #'string<))))
895 (setq key (intern (format "%s@%s" 'ideographic-radical domain)))
896 (when (and (memq key attributes)
897 (setq value (get-char-attribute char key)))
899 (insert (format "(%s . %S)\t; %c%s"
902 (ideographic-radical radical)
904 (setq attributes (delq key attributes))
906 (setq key (intern (format "%s@%s" 'ideographic-strokes domain)))
907 (when (and (memq key attributes)
908 (setq value (get-char-attribute char key)))
910 (insert (format "(%s . %S)%s"
914 (setq attributes (delq key attributes))
916 (setq key (intern (format "%s@%s" 'total-strokes domain)))
917 (when (and (memq key attributes)
918 (setq value (get-char-attribute char key)))
919 (insert (format "(%s . %S)%s"
923 (setq attributes (delq key attributes))
925 (dolist (feature '(ideographic-radical
928 (setq key (intern (format "%s@%s*sources" feature domain)))
929 (when (and (memq key attributes)
930 (setq value (get-char-attribute char key)))
931 (insert (format "(%s%s" key line-breaking))
933 (insert (format " %s" cell)))
935 (insert line-breaking)
936 (setq attributes (delq key attributes))
939 (when (and (memq 'ideographic-strokes attributes)
940 (setq value (get-char-attribute char 'ideographic-strokes)))
942 (insert (format "(ideographic-strokes . %S)%s"
945 (setq attributes (delq 'ideographic-strokes attributes))
947 (when (and (memq 'kangxi-radical attributes)
948 (setq value (get-char-attribute char 'kangxi-radical)))
949 (unless (eq value radical)
950 (insert (format "(kangxi-radical\t . %S)\t; %c%s"
952 (ideographic-radical value)
955 (setq radical value)))
956 (setq attributes (delq 'kangxi-radical attributes))
958 (when (and (memq 'kangxi-strokes attributes)
959 (setq value (get-char-attribute char 'kangxi-strokes)))
960 (unless (eq value strokes)
961 (insert (format "(kangxi-strokes\t . %S)%s"
965 (setq strokes value)))
966 (setq attributes (delq 'kangxi-strokes attributes))
968 (when (and (memq 'japanese-radical attributes)
969 (setq value (get-char-attribute char 'japanese-radical)))
970 (unless (eq value radical)
971 (insert (format "(japanese-radical\t . %S)\t; %c%s"
973 (ideographic-radical value)
976 (setq radical value)))
977 (setq attributes (delq 'japanese-radical attributes))
979 (when (and (memq 'japanese-strokes attributes)
980 (setq value (get-char-attribute char 'japanese-strokes)))
981 (unless (eq value strokes)
982 (insert (format "(japanese-strokes\t . %S)%s"
986 (setq strokes value)))
987 (setq attributes (delq 'japanese-strokes attributes))
989 (when (and (memq 'cns-radical attributes)
990 (setq value (get-char-attribute char 'cns-radical)))
991 (insert (format "(cns-radical\t . %S)\t; %c%s"
993 (ideographic-radical value)
995 (setq attributes (delq 'cns-radical attributes))
997 (when (and (memq 'cns-strokes attributes)
998 (setq value (get-char-attribute char 'cns-strokes)))
999 (unless (eq value strokes)
1000 (insert (format "(cns-strokes\t . %S)%s"
1004 (setq strokes value)))
1005 (setq attributes (delq 'cns-strokes attributes))
1007 (when (and (memq 'shinjigen-1-radical attributes)
1008 (setq value (get-char-attribute char 'shinjigen-1-radical)))
1009 (unless (eq value radical)
1010 (insert (format "(shinjigen-1-radical . %S)\t; %c%s"
1012 (ideographic-radical value)
1015 (setq radical value)))
1016 (setq attributes (delq 'shinjigen-1-radical attributes))
1018 (when (and (memq 'ideographic- attributes)
1019 (setq value (get-char-attribute char 'ideographic-)))
1020 (insert "(ideographic- ")
1021 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1023 (while (consp value)
1024 (setq cell (car value))
1026 (setq cell (decode-char '=ucs cell)))
1027 (cond ((characterp cell)
1031 (insert (format "%S" cell))
1032 (char-db-insert-char-spec cell readable))
1033 (setq separator lbs))
1037 (if (consp (car cell))
1038 (char-db-insert-char-spec cell readable)
1039 (char-db-insert-char-reference cell readable))
1040 (setq separator lbs))
1044 (insert (prin1-to-string cell))
1045 (setq separator " ")))
1046 (setq value (cdr value)))
1048 (insert line-breaking)
1049 (setq attributes (delq 'ideographic- attributes)))
1050 (when (and (memq 'total-strokes attributes)
1051 (setq value (get-char-attribute char 'total-strokes)))
1052 (insert (format "(total-strokes . %S)%s"
1055 (setq attributes (delq 'total-strokes attributes))
1057 (when (and (memq '->ideograph attributes)
1058 (setq value (get-char-attribute char '->ideograph)))
1059 (insert (format "(->ideograph\t%s)%s"
1060 (mapconcat (lambda (code)
1061 (cond ((symbolp code)
1064 (format "#x%04X" code))
1067 line-breaking code))))
1070 (setq attributes (delq '->ideograph attributes))
1072 ;; (when (and (memq '->decomposition attributes)
1073 ;; (setq value (get-char-attribute char '->decomposition)))
1074 ;; (insert (format "(->decomposition\t%s)%s"
1075 ;; (mapconcat (lambda (code)
1076 ;; (cond ((symbolp code)
1077 ;; (symbol-name code))
1078 ;; ((characterp code)
1080 ;; (format "%S" code)
1085 ;; (format "#x%04X" code))
1087 ;; (format "%s%S" line-breaking code))))
1090 ;; (setq attributes (delq '->decomposition attributes))
1092 (if (equal (get-char-attribute char '->titlecase)
1093 (get-char-attribute char '->uppercase))
1094 (setq attributes (delq '->titlecase attributes)))
1095 (when (and (memq '->mojikyo attributes)
1096 (setq value (get-char-attribute char '->mojikyo)))
1097 (insert (format "(->mojikyo\t\t. %06d)\t; %c%s"
1098 value (decode-char 'mojikyo value)
1100 (setq attributes (delq '->mojikyo attributes))
1102 (when (and (memq 'hanyu-dazidian-vol attributes)
1103 (setq value (get-char-attribute char 'hanyu-dazidian-vol)))
1104 (insert (format "(hanyu-dazidian-vol . %d)%s"
1105 value line-breaking))
1106 (setq attributes (delq 'hanyu-dazidian-vol attributes))
1108 (when (and (memq 'hanyu-dazidian-page attributes)
1109 (setq value (get-char-attribute char 'hanyu-dazidian-page)))
1110 (insert (format "(hanyu-dazidian-page . %d)%s"
1111 value line-breaking))
1112 (setq attributes (delq 'hanyu-dazidian-page attributes))
1114 (when (and (memq 'hanyu-dazidian-char attributes)
1115 (setq value (get-char-attribute char 'hanyu-dazidian-char)))
1116 (insert (format "(hanyu-dazidian-char . %d)%s"
1117 value line-breaking))
1118 (setq attributes (delq 'hanyu-dazidian-char attributes))
1121 (dolist (ignored '(composition
1122 ->denotational <-subsumptive ->ucs-unified
1123 ->ideographic-component-forms))
1124 (setq attributes (delq ignored attributes))))
1126 (setq name (car attributes))
1127 (unless (eq (setq value (get-char-attribute char name 'value-is-empty))
1129 (cond ((setq ret (find-charset name))
1130 (setq name (charset-name ret))
1131 (when (not (memq name dest-ccss))
1132 (setq dest-ccss (cons name dest-ccss))
1133 (char-db-insert-ccs-feature name value line-breaking))
1135 ((string-match "^=>ucs@" (symbol-name name))
1136 (insert (format "(%-18s . #x%04X)\t; %c%s"
1137 name value (decode-char '=ucs value)
1140 ((eq name 'jisx0208-1978/4X)
1141 (insert (format "(%-18s . #x%04X)%s"
1147 (not (eq name '->subsumptive))
1148 (not (eq name '->uppercase))
1149 (not (eq name '->lowercase))
1150 (not (eq name '->titlecase))
1151 (not (eq name '->canonical))
1152 (not (eq name '->Bopomofo))
1153 (not (eq name '->mistakable))
1154 (not (eq name '->ideographic-variants))
1155 (null (get-char-attribute
1156 char (intern (format "%s*sources" name))))
1157 (not (string-match "\\*sources$" (symbol-name name)))
1158 (null (get-char-attribute
1159 char (intern (format "%s*note" name))))
1160 (not (string-match "\\*note$" (symbol-name name)))
1161 (or (eq name '<-identical)
1162 (eq name '<-uppercase)
1163 (eq name '<-lowercase)
1164 (eq name '<-titlecase)
1165 (eq name '<-canonical)
1166 (eq name '<-ideographic-variants)
1167 ;; (eq name '<-synonyms)
1168 (string-match "^<-synonyms" (symbol-name name))
1169 (eq name '<-mistakable)
1170 (when (string-match "^->" (symbol-name name))
1172 ((string-match "^->fullwidth" (symbol-name name))
1173 (not (and (consp value)
1174 (characterp (car value))
1176 (car value) '=ucs 'defined-only)))
1181 ((or (eq name 'ideographic-structure)
1182 (eq name 'ideographic-combination)
1183 (eq name 'ideographic-)
1184 (eq name '=decomposition)
1185 (char-feature-base-name= '=decomposition name)
1186 (char-feature-base-name= '=>decomposition name)
1187 ;; (string-match "^=>*decomposition\\(@[^*]+\\)?$"
1188 ;; (symbol-name name))
1189 (string-match "^\\(->\\|<-\\)[^*]*$" (symbol-name name))
1190 (string-match "^\\(->\\|<-\\)[^*]*\\*sources$"
1193 (char-db-insert-relation-feature char name value
1196 ((memq name '(ideograph=
1197 original-ideograph-of
1198 ancient-ideograph-of
1201 ;; simplified-ideograph-of
1202 ideographic-variants
1203 ;; ideographic-different-form-of
1205 (insert (format "(%-18s%s " name line-breaking))
1206 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1208 (while (consp value)
1209 (setq cell (car value))
1210 (if (and (consp cell)
1215 (char-db-insert-alist cell readable)
1216 (setq separator lbs))
1219 (insert (prin1-to-string cell))
1220 (setq separator " "))
1221 (setq value (cdr value)))
1223 (insert line-breaking))
1225 (insert (format "(%-18s " name))
1226 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1228 (while (consp value)
1229 (setq cell (car value))
1230 (if (and (consp cell)
1232 (setq ret (condition-case nil
1240 (setq key (car (car rest)))
1241 (if (find-charset key)
1242 (setq cal (cons key cal))
1243 (setq al (cons key al)))
1244 (setq rest (cdr rest)))
1247 (insert-char-attributes ret
1251 (setq separator lbs))
1252 (setq ret (prin1-to-string cell))
1254 (if (< (+ (current-column)
1261 (setq separator " "))
1262 (setq value (cdr value)))
1264 (insert line-breaking))
1266 (insert (format "(%-18s" name))
1267 (setq ret (prin1-to-string value))
1268 (unless (< (+ (current-column)
1272 (insert line-breaking))
1273 (insert " . " ret ")" line-breaking)
1274 ;; (insert (format "(%-18s . %S)%s"
1279 (setq attributes (cdr attributes)))
1282 (defun insert-char-data (char &optional readable
1285 (narrow-to-region (point)(point))
1286 (insert "(define-char
1288 (insert-char-attributes char readable attributes)
1290 (goto-char (point-min))
1291 (while (re-search-forward "[ \t]+$" nil t)
1294 (goto-char (point-min))
1295 (while (re-search-forward "[ \t][ \t][ \t]*" nil t)
1296 (let ((column (current-column))
1297 (indent-tabs-mode t))
1298 (delete-region (match-beginning 0) (point))
1299 (indent-to column)))
1300 (goto-char (point-max))
1301 ;; (tabify (point-min)(point-max))
1304 (defun insert-char-data-with-variant (char &optional printable
1306 script excluded-script)
1307 (insert-char-data char printable)
1308 (let ((variants (char-variants char))
1311 (setq variants (sort variants #'<))
1312 (setq rest variants)
1313 (setq variants (cons char variants))
1315 (setq variant (car rest))
1316 (unless (get-char-attribute variant '<-subsumptive)
1317 (if (and (or (null script)
1318 (null (setq vs (get-char-attribute variant 'script)))
1320 (or (null excluded-script)
1321 (null (setq vs (get-char-attribute variant 'script)))
1322 (not (memq excluded-script vs))))
1323 (unless (and no-ucs-unified (get-char-attribute variant '=ucs))
1324 (insert-char-data variant printable)
1325 (if (setq ret (char-variants variant))
1327 (or (memq (car ret) variants)
1328 ;; (get-char-attribute (car ret) '<-subsumptive)
1329 (setq rest (nconc rest (list (car ret)))))
1330 (setq ret (cdr ret)))))))
1331 (setq rest (cdr rest)))))
1333 (defun insert-char-range-data (min max &optional script excluded-script)
1336 (while (<= code max)
1337 (setq char (decode-char '=ucs code))
1338 (if (encode-char char '=ucs 'defined-only)
1339 (insert-char-data-with-variant char nil 'no-ucs-unified
1340 script excluded-script))
1341 (setq code (1+ code)))))
1343 (defun write-char-range-data-to-file (min max file
1344 &optional script excluded-script)
1345 (let ((coding-system-for-write char-db-file-coding-system))
1347 (insert (format ";; -*- coding: %s -*-\n"
1348 char-db-file-coding-system))
1349 (insert-char-range-data min max script excluded-script)
1350 (write-region (point-min)(point-max) file))))
1352 (defvar what-character-original-window-configuration)
1355 (defun what-char-definition (char)
1356 (interactive (list (char-after)))
1357 (let ((buf (get-buffer-create "*Character Description*"))
1358 (the-buf (current-buffer))
1359 (win-conf (current-window-configuration)))
1361 (make-local-variable 'what-character-original-window-configuration)
1362 (setq what-character-original-window-configuration win-conf)
1363 (setq buffer-read-only nil)
1367 (insert-char-data-with-variant char 'printable)
1368 (unless (char-attribute-alist char)
1369 (insert (format ";; = %c\n"
1370 (let* ((rest (split-char char))
1374 (setq code (logior (lsh code 8)
1376 (decode-char ccs code)))))
1377 ;; (char-db-update-comment)
1378 (set-buffer-modified-p nil)
1379 (view-mode the-buf (lambda (buf)
1380 (set-window-configuration
1381 what-character-original-window-configuration)
1383 (goto-char (point-min)))
1385 (set-window-configuration
1386 what-character-original-window-configuration)
1387 (signal (car err) (cdr err)))))))
1393 (provide 'char-db-util)
1395 ;;; char-db-util.el ends here