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, 2014 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
200 ;; =>>>adobe-japan1-0
201 ;; =>>>adobe-japan1-1
202 ;; =>>>adobe-japan1-2
203 ;; =>>>adobe-japan1-3
204 ;; =>>>adobe-japan1-4
205 ;; =>>>adobe-japan1-5
206 ;; =>>>adobe-japan1-6
210 ;; =>>>hanyo-denshi/ja
211 ;; =>>>hanyo-denshi/jb
212 ;; =>>>hanyo-denshi/jc
213 ;; =>>>hanyo-denshi/ft
214 ;; =>>>hanyo-denshi/ib
215 ;; =>>>hanyo-denshi/hg
216 ;; =>>>hanyo-denshi/jt
217 ;; =>>>hanyo-denshi/ks
308 ;;; @ char-db formatters
311 (defun char-db-make-char-spec (char)
313 (cond ((characterp char)
314 (cond ((and (setq ret (encode-char char '=ucs 'defined-only))
315 (not (and (<= #xE000 ret)(<= ret #xF8FF))))
316 (setq char-spec (list (cons '=ucs ret)))
317 (cond ((setq ret (get-char-attribute char 'name))
318 (setq char-spec (cons (cons 'name ret) char-spec))
320 ((setq ret (get-char-attribute char 'name*))
321 (setq char-spec (cons (cons 'name* ret) char-spec))
324 ((encode-char char '=mj 'defined-only)
326 (dolist (ccs (charset-list))
327 (if (and (or (eq ccs '=mj)
328 ;; (eq (charset-property ccs 'iso-ir) 177)
329 (string-match "=ucs@" (symbol-name ccs))
331 (setq ccs (charset-name ccs))
332 (null (assq ccs char-spec))
333 (setq ret (encode-char char ccs 'defined-only)))
334 (setq char-spec (cons (cons ccs ret) char-spec))))
336 ((encode-char char '==mj 'defined-only)
338 (dolist (ccs (charset-list))
339 (if (and (or (eq ccs '==mj)
340 ;; (eq (charset-property ccs 'iso-ir) 177)
341 (string-match "=ucs@" (symbol-name ccs))
343 (setq ccs (charset-name ccs))
344 (null (assq ccs char-spec))
345 (setq ret (encode-char char ccs 'defined-only)))
346 (setq char-spec (cons (cons ccs ret) char-spec))))
348 ((encode-char char '=adobe-japan1 'defined-only)
350 (dolist (ccs (charset-list))
351 (if (and (or (memq ccs
360 ;; (eq (charset-property ccs 'iso-ir) 177)
361 (string-match "=ucs@" (symbol-name ccs))
363 (setq ccs (charset-name ccs))
364 (null (assq ccs char-spec))
365 (setq ret (encode-char char ccs 'defined-only)))
366 (setq char-spec (cons (cons ccs ret) char-spec))))
368 ((encode-char char '==adobe-japan1 'defined-only)
370 (dolist (ccs (charset-list))
371 (if (and (or (memq ccs
380 ;; (eq (charset-property ccs 'iso-ir) 177)
381 (string-match "=ucs@" (symbol-name ccs))
383 (setq ccs (charset-name ccs))
384 (null (assq ccs char-spec))
385 (setq ret (encode-char char ccs 'defined-only)))
386 (setq char-spec (cons (cons ccs ret) char-spec))))
390 (let ((rest char-db-coded-charset-priority-list)
393 (setq ccs (charset-name
394 (find-charset (car rest))))
396 (encode-char char ccs
398 (throw 'tag (cons ccs ret)))
399 (setq rest (cdr rest))))))
400 (setq char-spec (list ret))
401 (dolist (ccs (delq (car ret) (charset-list)))
402 (if (and (or (charset-iso-final-char ccs)
409 (eq (charset-property ccs 'iso-ir) 177)
410 ;; (string-match "=ucs@" (symbol-name ccs))
412 (setq ccs (charset-name ccs))
413 (null (assq ccs char-spec))
414 (setq ret (encode-char char ccs 'defined-only)))
415 (setq char-spec (cons (cons ccs ret) char-spec))))
417 (setq char-spec (split-char char)))
418 (cond ((setq ret (get-char-attribute char 'name))
419 (setq char-spec (cons (cons 'name ret) char-spec))
421 ((setq ret (get-char-attribute char 'name*))
422 (setq char-spec (cons (cons 'name* ret) char-spec))
425 ((setq ret (get-char-attribute
426 char 'ideographic-combination))
428 (cons (cons 'ideographic-combination ret)
435 (defun char-db-insert-char-spec (char &optional readable column
438 (setq column (current-column)))
439 (let (char-spec temp-char)
440 (setq char-spec (char-db-make-char-spec char))
441 (unless (or (characterp char) ; char
443 (setq char (find-char char-spec))
445 ;; define temporary character
446 ;; Current implementation is dirty.
447 (setq temp-char (define-char (cons '(ideograph-daikanwa . 0)
449 (remove-char-attribute temp-char 'ideograph-daikanwa)
450 (setq char temp-char))
451 (insert-char-attributes char
453 (union (mapcar #'car char-spec)
457 ;; undefine temporary character
458 ;; Current implementation is dirty.
459 (setq char-spec (char-attribute-alist temp-char))
461 (remove-char-attribute temp-char (car (car char-spec)))
462 (setq char-spec (cdr char-spec))))))
464 (defun char-db-insert-alist (alist &optional readable column)
466 (setq column (current-column)))
468 (concat "\n" (make-string (1+ column) ?\ )))
472 lbs cell rest separator)
475 (setq name (car (car alist))
476 value (cdr (car alist)))
477 (cond ((eq name 'char)
479 (if (setq ret (condition-case nil
487 (setq key (car (car value)))
488 ;; (if (find-charset key)
489 ;; (setq cal (cons key cal))
490 (setq al (cons key al))
492 (setq value (cdr value)))
493 (insert-char-attributes ret
497 (insert (prin1-to-string value)))
499 (insert line-breaking))
501 (insert (format "(%-18s " name))
502 (setq lbs (concat "\n" (make-string (current-column) ?\ )))
504 (setq cell (car value))
505 (if (and (consp cell)
507 (setq ret (condition-case nil
517 (setq key (car (car rest)))
518 ;; (if (find-charset key)
519 ;; (setq cal (cons key cal))
520 (setq al (cons key al))
522 (setq rest (cdr rest)))
525 (insert-char-attributes ret
529 (setq separator lbs))
532 (insert (prin1-to-string cell))
533 (setq separator " "))
534 (setq value (cdr value)))
536 (insert line-breaking))
538 (insert (format "(%-18s . %S)%s"
541 (setq alist (cdr alist))))
544 (defun char-db-insert-char-reference (plist &optional readable column)
546 (setq column (current-column)))
548 (concat "\n" (make-string (1+ column) ?\ )))
553 (setq name (pop plist))
554 (setq value (pop plist))
555 (cond ((eq name :char)
558 (cond ((numberp value)
559 (setq value (decode-char '=ucs value)))
561 ;; (setq value (or (find-char value)
564 (char-db-insert-char-spec value readable)
565 (insert line-breaking)
568 (insert (format "%s%s\t%d ; %c%s"
571 (ideographic-radical value)
575 (insert (format "%s%s\t%S" separator name value))
576 (setq separator line-breaking)))
580 (defun char-db-decode-isolated-char (ccs code-point)
583 (cond ((eq ccs 'arabic-iso8859-6)
584 (decode-char ccs code-point))
586 ;; (decode-builtin-char '==gt code-point))
587 ((and (memq ccs '(=gt-pj-1
598 (setq ret (decode-char ccs code-point))
599 (setq ret (encode-char ret '=gt 'defined-only)))
600 (decode-builtin-char '=gt ret))
602 (decode-builtin-char ccs code-point))))
603 (cond ((and (<= 0 (char-int ret))
604 (<= (char-int ret) #x1F))
605 (decode-char '=ucs (+ #x2400 (char-int ret))))
606 ((= (char-int ret) #x7F)
610 (defvar char-db-convert-obsolete-format t)
612 (defun char-db-insert-ccs-feature (name value line-breaking)
618 ((memq name '(==shinjigen
620 =shinjigen@1ed ==shinjigen@1ed
621 =shinjigen@rev ==shinjigen@rev
622 =shinjigen/+p@rev ==shinjigen/+p@rev
624 =daikanwa/ho =>>daikanwa/ho =>daikanwa/ho))
625 "(%-18s . %04d)\t; %c")
626 ((eq name '=shinjigen@1ed/24pr)
627 "(%-18s . %04d)\t; %c")
628 ((or (memq name '(==daikanwa
629 =daikanwa =>>daikanwa =>daikanwa
630 =daikanwa@rev1 =daikanwa@rev2
631 =daikanwa/+p ==daikanwa/+p =>>daikanwa/+p
632 =daikanwa/+2p =>>daikanwa/+2p
635 =gt-k ==gt-k =>>gt-k =>gt-k
636 =adobe-japan1-0 ==adobe-japan1-0 ; =>>>adobe-japan1-0
637 =adobe-japan1-1 ==adobe-japan1-1 ; =>>>adobe-japan1-1
638 =adobe-japan1-2 ==adobe-japan1-2 ; =>>>adobe-japan1-2
639 =adobe-japan1-3 ==adobe-japan1-3 ; =>>>adobe-japan1-3
640 =adobe-japan1-4 ==adobe-japan1-4 ; =>>>adobe-japan1-4
641 =adobe-japan1-5 ==adobe-japan1-5 ; =>>>adobe-japan1-5
642 =adobe-japan1-6 ==adobe-japan1-6 ; =>>>adobe-japan1-6
643 =>>adobe-japan1-0 =+>adobe-japan1-0
644 =>>adobe-japan1-1 =+>adobe-japan1-1
645 =>>adobe-japan1-2 =+>adobe-japan1-2
646 =>>adobe-japan1-3 =+>adobe-japan1-3
647 =>>adobe-japan1-4 =+>adobe-japan1-4
648 =>>adobe-japan1-5 =+>adobe-japan1-5
649 =>>adobe-japan1-6 =+>adobe-japan1-6
651 =zinbun-oracle =>zinbun-oracle))
652 ;; (string-match "^=adobe-" (symbol-name name))
654 "(%-18s . %05d)\t; %c")
655 ((memq name '(=hanyo-denshi/ks
656 ==hanyo-denshi/ks ; =>>>hanyo-denshi/ks
661 "(%-18s . %06d)\t; %c")
662 ((>= (charset-dimension name) 2)
663 "(%-18s . #x%04X)\t; %c")
665 "(%-18s . #x%02X)\t; %c"))
667 (if (= (charset-iso-graphic-plane name) 1)
669 (cond ((= (charset-dimension name) 1)
671 ((= (charset-dimension name) 2)
673 ((= (charset-dimension name) 3)
677 (char-db-decode-isolated-char name value)))
678 (if (and (= (charset-chars name) 94)
679 (= (charset-dimension name) 2))
680 (insert (format " [%02d-%02d]"
681 (- (lsh value -8) 32)
682 (- (logand value 255) 32))))
685 (insert (format "(%-18s . %s)" name value))
687 (insert line-breaking))
689 (defun char-db-insert-relation-feature (char name value line-breaking
691 (insert (format "(%-18s%s " name line-breaking))
692 (let ((lbs (concat "\n" (make-string (current-column) ?\ )))
693 separator cell sources required-features
696 (setq cell (car value))
698 (setq cell (decode-char '=ucs cell)))
700 ((eq name '->subsumptive)
701 (when (or (not (some (lambda (atr)
702 (get-char-attribute cell atr))
703 char-db-ignored-attributes))
705 (encode-char cell ccs 'defined-only))
709 (let ((char-db-ignored-attributes
711 char-db-ignored-attributes)))
712 (insert-char-attributes cell readable nil nil 'for-sub-node))
713 (setq separator lbs))
718 char (intern (format "%s*sources" name))))
719 (setq required-features nil)
720 (dolist (source sources)
724 shinjigen shinjigen@1ed shinjigen@rev))
725 (setq required-features
726 (union required-features
738 =shinjigen/+p@rev))))
740 (setq required-features
741 (union required-features
746 ((find-charset (setq ret (intern (format "=%s" source))))
747 (setq required-features
748 (cons ret required-features)))
749 (t (setq required-features
750 (cons source required-features)))))
751 (cond ((string-match "@JP" (symbol-name name))
752 (setq required-features
753 (union required-features
761 ((string-match "@CN" (symbol-name name))
762 (setq required-features
763 (union required-features
770 (insert (format "%S" cell))
771 (char-db-insert-char-spec cell readable
774 (setq separator lbs))
778 (if (consp (car cell))
779 (char-db-insert-char-spec cell readable)
780 (char-db-insert-char-reference cell readable))
781 (setq separator lbs))
785 (insert (prin1-to-string cell))
786 (setq separator " ")))
787 (setq value (cdr value)))
789 (insert line-breaking)))
791 (defun insert-char-attributes (char &optional readable attributes column
794 (setq column (current-column)))
795 (let (name value ; has-long-ccs-name
799 (concat "\n" (make-string (1+ column) ?\ )))
800 lbs cell separator ret
802 dest-ccss ; sources required-features
807 (if (consp attributes)
809 (dolist (name attributes)
810 (unless (memq name char-db-ignored-attributes)
811 (if (find-charset name)
815 (dolist (name (char-attribute-list))
816 (unless (memq name char-db-ignored-attributes)
817 (if (find-charset name)
821 #'char-attribute-name<)))
823 (when (memq '<-subsumptive attributes)
824 (when (or readable (not for-sub-node))
825 (when (setq value (get-char-attribute char '<-subsumptive))
826 (char-db-insert-relation-feature char '<-subsumptive value
829 (setq attributes (delq '<-subsumptive attributes)))
830 (when (and (memq '<-denotational attributes)
831 (setq value (get-char-attribute char '<-denotational)))
832 (char-db-insert-relation-feature char '<-denotational value
835 (setq attributes (delq '<-denotational attributes)))
836 (when (and (memq 'name attributes)
837 (setq value (get-char-attribute char 'name)))
839 (if (> (+ (current-column) (length value)) 48)
842 value line-breaking))
843 (setq attributes (delq 'name attributes))
845 (when (and (memq 'name* attributes)
846 (setq value (get-char-attribute char 'name*)))
848 (if (> (+ (current-column) (length value)) 48)
851 value line-breaking))
852 (setq attributes (delq 'name* attributes))
854 (when (and (memq 'script attributes)
855 (setq value (get-char-attribute char 'script)))
856 (insert (format "(script\t\t%s)%s"
857 (mapconcat (function prin1-to-string)
860 (setq attributes (delq 'script attributes))
862 (dolist (name '(=>ucs =>ucs*))
863 (when (and (memq name attributes)
864 (setq value (get-char-attribute char name)))
865 (insert (format "(%-18s . #x%04X)\t; %c%s"
866 name value (decode-char '=ucs value)
868 (setq attributes (delq name attributes))))
869 (dolist (name '(=>ucs@gb =>ucs@big5))
870 (when (and (memq name attributes)
871 (setq value (get-char-attribute char name)))
872 (insert (format "(%-18s . #x%04X)\t; %c%s"
877 (symbol-name name) 2)))
880 (setq attributes (delq name attributes))
882 ;; (dolist (name '(=>daikanwa))
883 ;; (when (and (memq name attributes)
884 ;; (setq value (get-char-attribute char name)))
886 ;; (if (integerp value)
887 ;; (format "(%-18s . %05d)\t; %c%s"
888 ;; name value (decode-char '=daikanwa value)
890 ;; (format "(%-18s %s)\t; %c%s"
892 ;; (mapconcat (function prin1-to-string)
894 ;; (char-representative-of-daikanwa char)
896 ;; (setq attributes (delq name attributes))))
897 (when (and (memq 'general-category attributes)
898 (setq value (get-char-attribute char 'general-category)))
900 "(general-category\t%s) ; %s%s"
901 (mapconcat (lambda (cell)
904 (cond ((rassoc value unidata-normative-category-alist)
905 "Normative Category")
906 ((rassoc value unidata-informative-category-alist)
907 "Informative Category")
911 (setq attributes (delq 'general-category attributes))
913 (when (and (memq 'bidi-category attributes)
914 (setq value (get-char-attribute char 'bidi-category)))
915 (insert (format "(bidi-category\t. %S)%s"
918 (setq attributes (delq 'bidi-category attributes))
920 (unless (or (not (memq 'mirrored attributes))
921 (eq (setq value (get-char-attribute char 'mirrored 'empty))
923 (insert (format "(mirrored\t\t. %S)%s"
926 (setq attributes (delq 'mirrored attributes))
929 ((and (memq 'decimal-digit-value attributes)
930 (setq value (get-char-attribute char 'decimal-digit-value)))
931 (insert (format "(decimal-digit-value . %S)%s"
934 (setq attributes (delq 'decimal-digit-value attributes))
935 (when (and (memq 'digit-value attributes)
936 (setq value (get-char-attribute char 'digit-value)))
937 (insert (format "(digit-value\t . %S)%s"
940 (setq attributes (delq 'digit-value attributes))
942 (when (and (memq 'numeric-value attributes)
943 (setq value (get-char-attribute char 'numeric-value)))
944 (insert (format "(numeric-value\t . %S)%s"
947 (setq attributes (delq 'numeric-value attributes))
951 (when (and (memq 'digit-value attributes)
952 (setq value (get-char-attribute char 'digit-value)))
953 (insert (format "(digit-value\t. %S)%s"
956 (setq attributes (delq 'digit-value attributes))
958 (when (and (memq 'numeric-value attributes)
959 (setq value (get-char-attribute char 'numeric-value)))
960 (insert (format "(numeric-value\t. %S)%s"
963 (setq attributes (delq 'numeric-value attributes))
965 (when (and (memq 'iso-10646-comment attributes)
966 (setq value (get-char-attribute char 'iso-10646-comment)))
967 (insert (format "(iso-10646-comment\t. %S)%s"
970 (setq attributes (delq 'iso-10646-comment attributes))
972 (when (and (memq 'morohashi-daikanwa attributes)
973 (setq value (get-char-attribute char 'morohashi-daikanwa)))
974 (insert (format "(morohashi-daikanwa\t%s)%s"
975 (mapconcat (function prin1-to-string) value " ")
977 (setq attributes (delq 'morohashi-daikanwa attributes))
981 (when (and (memq 'ideographic-radical attributes)
982 (setq value (get-char-attribute char 'ideographic-radical)))
984 (insert (format "(ideographic-radical . %S)\t; %c%s"
986 (ideographic-radical radical)
988 (setq attributes (delq 'ideographic-radical attributes))
990 (when (and (memq 'shuowen-radical attributes)
991 (setq value (get-char-attribute char 'shuowen-radical)))
992 (insert (format "(shuowen-radical\t. %S)\t; %c%s"
994 (shuowen-radical value)
996 (setq attributes (delq 'shuowen-radical attributes))
1001 char-db-feature-domains
1003 (dolist (feature (char-attribute-list))
1004 (setq feature (symbol-name feature))
1006 "\\(radical\\|strokes\\)@\\([^@*]+\\)\\(\\*\\|$\\)"
1008 (setq domain (intern (match-string 2 feature)))
1009 (unless (memq domain dest)
1010 (setq dest (cons domain dest)))))
1011 (sort dest #'string<))))
1012 (setq key (intern (format "%s@%s" 'ideographic-radical domain)))
1013 (when (and (memq key attributes)
1014 (setq value (get-char-attribute char key)))
1015 (setq radical value)
1016 (insert (format "(%s . %S)\t; %c%s"
1019 (ideographic-radical radical)
1021 (setq attributes (delq key attributes))
1023 (setq key (intern (format "%s@%s" 'ideographic-strokes domain)))
1024 (when (and (memq key attributes)
1025 (setq value (get-char-attribute char key)))
1026 (setq strokes value)
1027 (insert (format "(%s . %S)%s"
1031 (setq attributes (delq key attributes))
1033 (setq key (intern (format "%s@%s" 'total-strokes domain)))
1034 (when (and (memq key attributes)
1035 (setq value (get-char-attribute char key)))
1036 (insert (format "(%s . %S)%s"
1040 (setq attributes (delq key attributes))
1042 (dolist (feature '(ideographic-radical
1045 (setq key (intern (format "%s@%s*sources" feature domain)))
1046 (when (and (memq key attributes)
1047 (setq value (get-char-attribute char key)))
1048 (insert (format "(%s%s" key line-breaking))
1049 (dolist (cell value)
1050 (insert (format " %s" cell)))
1052 (insert line-breaking)
1053 (setq attributes (delq key attributes))
1056 (when (and (memq 'ideographic-strokes attributes)
1057 (setq value (get-char-attribute char 'ideographic-strokes)))
1058 (setq strokes value)
1059 (insert (format "(ideographic-strokes . %S)%s"
1062 (setq attributes (delq 'ideographic-strokes attributes))
1064 (when (and (memq 'kangxi-radical attributes)
1065 (setq value (get-char-attribute char 'kangxi-radical)))
1066 (unless (eq value radical)
1067 (insert (format "(kangxi-radical\t . %S)\t; %c%s"
1069 (ideographic-radical value)
1072 (setq radical value)))
1073 (setq attributes (delq 'kangxi-radical attributes))
1075 (when (and (memq 'kangxi-strokes attributes)
1076 (setq value (get-char-attribute char 'kangxi-strokes)))
1077 (unless (eq value strokes)
1078 (insert (format "(kangxi-strokes\t . %S)%s"
1082 (setq strokes value)))
1083 (setq attributes (delq 'kangxi-strokes attributes))
1085 (when (and (memq 'japanese-radical attributes)
1086 (setq value (get-char-attribute char 'japanese-radical)))
1087 (unless (eq value radical)
1088 (insert (format "(japanese-radical\t . %S)\t; %c%s"
1090 (ideographic-radical value)
1093 (setq radical value)))
1094 (setq attributes (delq 'japanese-radical attributes))
1096 (when (and (memq 'japanese-strokes attributes)
1097 (setq value (get-char-attribute char 'japanese-strokes)))
1098 (unless (eq value strokes)
1099 (insert (format "(japanese-strokes\t . %S)%s"
1103 (setq strokes value)))
1104 (setq attributes (delq 'japanese-strokes attributes))
1106 (when (and (memq 'cns-radical attributes)
1107 (setq value (get-char-attribute char 'cns-radical)))
1108 (insert (format "(cns-radical\t . %S)\t; %c%s"
1110 (ideographic-radical value)
1112 (setq attributes (delq 'cns-radical attributes))
1114 (when (and (memq 'cns-strokes attributes)
1115 (setq value (get-char-attribute char 'cns-strokes)))
1116 (unless (eq value strokes)
1117 (insert (format "(cns-strokes\t . %S)%s"
1121 (setq strokes value)))
1122 (setq attributes (delq 'cns-strokes attributes))
1124 ;; (when (and (memq 'shinjigen-1-radical attributes)
1125 ;; (setq value (get-char-attribute char 'shinjigen-1-radical)))
1126 ;; (unless (eq value radical)
1127 ;; (insert (format "(shinjigen-1-radical . %S)\t; %c%s"
1129 ;; (ideographic-radical value)
1132 ;; (setq radical value)))
1133 ;; (setq attributes (delq 'shinjigen-1-radical attributes))
1135 (when (and (memq 'ideographic- attributes)
1136 (setq value (get-char-attribute char 'ideographic-)))
1137 (insert "(ideographic- ")
1138 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1140 (while (consp value)
1141 (setq cell (car value))
1143 (setq cell (decode-char '=ucs cell)))
1144 (cond ((characterp cell)
1148 (insert (format "%S" cell))
1149 (char-db-insert-char-spec cell readable))
1150 (setq separator lbs))
1154 (if (consp (car cell))
1155 (char-db-insert-char-spec cell readable)
1156 (char-db-insert-char-reference cell readable))
1157 (setq separator lbs))
1161 (insert (prin1-to-string cell))
1162 (setq separator " ")))
1163 (setq value (cdr value)))
1165 (insert line-breaking)
1166 (setq attributes (delq 'ideographic- attributes)))
1167 (when (and (memq 'total-strokes attributes)
1168 (setq value (get-char-attribute char 'total-strokes)))
1169 (insert (format "(total-strokes . %S)%s"
1172 (setq attributes (delq 'total-strokes attributes))
1174 (when (and (memq '->ideograph attributes)
1175 (setq value (get-char-attribute char '->ideograph)))
1176 (insert (format "(->ideograph\t%s)%s"
1177 (mapconcat (lambda (code)
1178 (cond ((symbolp code)
1181 (format "#x%04X" code))
1184 line-breaking code))))
1187 (setq attributes (delq '->ideograph attributes))
1189 ;; (when (and (memq '->decomposition attributes)
1190 ;; (setq value (get-char-attribute char '->decomposition)))
1191 ;; (insert (format "(->decomposition\t%s)%s"
1192 ;; (mapconcat (lambda (code)
1193 ;; (cond ((symbolp code)
1194 ;; (symbol-name code))
1195 ;; ((characterp code)
1197 ;; (format "%S" code)
1202 ;; (format "#x%04X" code))
1204 ;; (format "%s%S" line-breaking code))))
1207 ;; (setq attributes (delq '->decomposition attributes))
1209 (if (equal (get-char-attribute char '->titlecase)
1210 (get-char-attribute char '->uppercase))
1211 (setq attributes (delq '->titlecase attributes)))
1212 (when (and (memq '->mojikyo attributes)
1213 (setq value (get-char-attribute char '->mojikyo)))
1214 (insert (format "(->mojikyo\t\t. %06d)\t; %c%s"
1215 value (decode-char 'mojikyo value)
1217 (setq attributes (delq '->mojikyo attributes))
1219 (when (and (memq 'hanyu-dazidian-vol attributes)
1220 (setq value (get-char-attribute char 'hanyu-dazidian-vol)))
1221 (insert (format "(hanyu-dazidian-vol . %d)%s"
1222 value line-breaking))
1223 (setq attributes (delq 'hanyu-dazidian-vol attributes))
1225 (when (and (memq 'hanyu-dazidian-page attributes)
1226 (setq value (get-char-attribute char 'hanyu-dazidian-page)))
1227 (insert (format "(hanyu-dazidian-page . %d)%s"
1228 value line-breaking))
1229 (setq attributes (delq 'hanyu-dazidian-page attributes))
1231 (when (and (memq 'hanyu-dazidian-char attributes)
1232 (setq value (get-char-attribute char 'hanyu-dazidian-char)))
1233 (insert (format "(hanyu-dazidian-char . %d)%s"
1234 value line-breaking))
1235 (setq attributes (delq 'hanyu-dazidian-char attributes))
1238 (dolist (ignored '(composition
1239 ->denotational <-subsumptive ->ucs-unified
1240 ->ideographic-component-forms))
1241 (setq attributes (delq ignored attributes))))
1243 (setq name (car attributes))
1244 (unless (eq (setq value (get-char-attribute char name 'value-is-empty))
1246 (cond ((setq ret (find-charset name))
1247 (setq name (charset-name ret))
1248 (when (not (memq name dest-ccss))
1249 (setq dest-ccss (cons name dest-ccss))
1250 (char-db-insert-ccs-feature name value line-breaking))
1252 ((string-match "^=>ucs@" (symbol-name name))
1253 (insert (format "(%-18s . #x%04X)\t; %c%s"
1254 name value (decode-char '=ucs value)
1257 ((eq name 'jisx0208-1978/4X)
1258 (insert (format "(%-18s . #x%04X)%s"
1264 (not (eq name '->subsumptive))
1265 (not (eq name '->uppercase))
1266 (not (eq name '->lowercase))
1267 (not (eq name '->titlecase))
1268 (not (eq name '->canonical))
1269 (not (eq name '->Bopomofo))
1270 (not (eq name '->mistakable))
1271 (not (eq name '->ideographic-variants))
1272 (null (get-char-attribute
1273 char (intern (format "%s*sources" name))))
1274 (not (string-match "\\*sources$" (symbol-name name)))
1275 (null (get-char-attribute
1276 char (intern (format "%s*note" name))))
1277 (not (string-match "\\*note$" (symbol-name name)))
1278 (or (eq name '<-identical)
1279 (eq name '<-uppercase)
1280 (eq name '<-lowercase)
1281 (eq name '<-titlecase)
1282 (eq name '<-canonical)
1283 (eq name '<-ideographic-variants)
1284 ;; (eq name '<-synonyms)
1285 (string-match "^<-synonyms" (symbol-name name))
1286 (eq name '<-mistakable)
1287 (when (string-match "^->" (symbol-name name))
1289 ((string-match "^->fullwidth" (symbol-name name))
1290 (not (and (consp value)
1291 (characterp (car value))
1293 (car value) '=ucs 'defined-only)))
1298 ((or (eq name 'ideographic-structure)
1299 (eq name 'ideographic-combination)
1300 (eq name 'ideographic-)
1301 (eq name '=decomposition)
1302 (char-feature-base-name= '=decomposition name)
1303 (char-feature-base-name= '=>decomposition name)
1304 ;; (string-match "^=>*decomposition\\(@[^*]+\\)?$"
1305 ;; (symbol-name name))
1306 (string-match "^\\(->\\|<-\\)[^*]*$" (symbol-name name))
1307 (string-match "^\\(->\\|<-\\)[^*]*\\*sources$"
1310 (char-db-insert-relation-feature char name value
1313 ((memq name '(ideograph=
1314 original-ideograph-of
1315 ancient-ideograph-of
1318 ;; simplified-ideograph-of
1319 ideographic-variants
1320 ;; ideographic-different-form-of
1322 (insert (format "(%-18s%s " name line-breaking))
1323 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1325 (while (consp value)
1326 (setq cell (car value))
1327 (if (and (consp cell)
1332 (char-db-insert-alist cell readable)
1333 (setq separator lbs))
1336 (insert (prin1-to-string cell))
1337 (setq separator " "))
1338 (setq value (cdr value)))
1340 (insert line-breaking))
1342 (insert (format "(%-18s " name))
1343 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1345 (while (consp value)
1346 (setq cell (car value))
1347 (if (and (consp cell)
1349 (setq ret (condition-case nil
1357 (setq key (car (car rest)))
1358 (if (find-charset key)
1359 (setq cal (cons key cal))
1360 (setq al (cons key al)))
1361 (setq rest (cdr rest)))
1364 (insert-char-attributes ret
1368 (setq separator lbs))
1369 (setq ret (prin1-to-string cell))
1371 (if (< (+ (current-column)
1378 (setq separator " "))
1379 (setq value (cdr value)))
1381 (insert line-breaking))
1383 (insert (format "(%-18s" name))
1384 (setq ret (prin1-to-string value))
1385 (unless (< (+ (current-column)
1389 (insert line-breaking))
1390 (insert " . " ret ")" line-breaking)
1391 ;; (insert (format "(%-18s . %S)%s"
1396 (setq attributes (cdr attributes)))
1399 (defun insert-char-data (char &optional readable
1402 (narrow-to-region (point)(point))
1403 (insert "(define-char
1405 (insert-char-attributes char readable attributes)
1407 (goto-char (point-min))
1408 (while (re-search-forward "[ \t]+$" nil t)
1411 (goto-char (point-min))
1412 (while (re-search-forward "[ \t][ \t][ \t]*" nil t)
1413 (let ((column (current-column))
1414 (indent-tabs-mode t))
1415 (delete-region (match-beginning 0) (point))
1416 (indent-to column)))
1417 (goto-char (point-max))
1418 ;; (tabify (point-min)(point-max))
1421 (defun insert-char-data-with-variant (char &optional printable
1423 script excluded-script)
1424 (insert-char-data char printable)
1425 (let ((variants (char-variants char))
1428 (setq variants (sort variants #'<))
1429 (setq rest variants)
1430 (setq variants (cons char variants))
1432 (setq variant (car rest))
1433 (unless (get-char-attribute variant '<-subsumptive)
1434 (if (and (or (null script)
1435 (null (setq vs (get-char-attribute variant 'script)))
1437 (or (null excluded-script)
1438 (null (setq vs (get-char-attribute variant 'script)))
1439 (not (memq excluded-script vs))))
1440 (unless (and no-ucs-unified (get-char-attribute variant '=ucs))
1441 (insert-char-data variant printable)
1442 (if (setq ret (char-variants variant))
1444 (or (memq (car ret) variants)
1445 ;; (get-char-attribute (car ret) '<-subsumptive)
1446 (setq rest (nconc rest (list (car ret)))))
1447 (setq ret (cdr ret)))))))
1448 (setq rest (cdr rest)))))
1450 (defun insert-char-range-data (min max &optional script excluded-script)
1453 (while (<= code max)
1454 (setq char (decode-char '=ucs code))
1455 (if (encode-char char '=ucs 'defined-only)
1456 (insert-char-data-with-variant char nil 'no-ucs-unified
1457 script excluded-script))
1458 (setq code (1+ code)))))
1460 (defun write-char-range-data-to-file (min max file
1461 &optional script excluded-script)
1462 (let ((coding-system-for-write char-db-file-coding-system))
1464 (insert (format ";; -*- coding: %s -*-\n"
1465 char-db-file-coding-system))
1466 (insert-char-range-data min max script excluded-script)
1467 (write-region (point-min)(point-max) file))))
1469 (defvar what-character-original-window-configuration)
1472 (defun what-char-definition (char)
1473 (interactive (list (char-after)))
1474 (let ((buf (get-buffer-create "*Character Description*"))
1475 (the-buf (current-buffer))
1476 (win-conf (current-window-configuration)))
1478 (make-local-variable 'what-character-original-window-configuration)
1479 (setq what-character-original-window-configuration win-conf)
1480 (setq buffer-read-only nil)
1484 (insert-char-data-with-variant char 'printable)
1485 (unless (char-attribute-alist char)
1486 (insert (format ";; = %c\n"
1487 (let* ((rest (split-char char))
1491 (setq code (logior (lsh code 8)
1493 (decode-char ccs code)))))
1494 ;; (char-db-update-comment)
1495 (set-buffer-modified-p nil)
1496 (view-mode the-buf (lambda (buf)
1497 (set-window-configuration
1498 what-character-original-window-configuration)
1500 (goto-char (point-min)))
1502 (set-window-configuration
1503 what-character-original-window-configuration)
1504 (signal (car err) (cdr err)))))))
1510 (provide 'char-db-util)
1512 ;;; char-db-util.el ends here