1 ;;; char-db-util.el --- Character Database utility -*- coding: utf-8-er; -*-
3 ;; Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006,
4 ;; 2007, 2008, 2009, 2010, 2011, 2012, 2013 MORIOKA Tomohiko.
6 ;; Author: MORIOKA Tomohiko <tomo@kanji.zinbun.kyoto-u.ac.jp>
7 ;; Keywords: CHISE, Character Database, ISO/IEC 10646, UCS, Unicode, MULE.
9 ;; This file is part of XEmacs CHISE.
11 ;; XEmacs CHISE is free software; you can redistribute it and/or
12 ;; modify it under the terms of the GNU General Public License as
13 ;; published by the Free Software Foundation; either version 2, or (at
14 ;; your option) any later version.
16 ;; XEmacs CHISE is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 ;; General Public License for more details.
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with XEmacs CHISE; see the file COPYING. If not, write to
23 ;; the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
24 ;; Boston, MA 02111-1307, USA.
29 (require 'ideograph-subr)
31 (defconst unidata-normative-category-alist
32 '(("Lu" letter uppercase)
33 ("Ll" letter lowercase)
34 ("Lt" letter titlecase)
35 ("Mn" mark non-spacing)
36 ("Mc" mark spacing-combining)
38 ("Nd" number decimal-digit)
41 ("Zs" separator space)
43 ("Zp" separator paragraph)
46 ("Cs" other surrogate)
47 ("Co" other private-use)
48 ("Cn" other not-assigned)))
50 (defconst unidata-informative-category-alist
51 '(("Lm" letter modifier)
53 ("Pc" punctuation connector)
54 ("Pd" punctuation dash)
55 ("Ps" punctuation open)
56 ("Pe" punctuation close)
57 ("Pi" punctuation initial-quote)
58 ("Pf" punctuation final-quote)
59 ("Po" punctuation other)
61 ("Sc" symbol currency)
62 ("Sk" symbol modifier)
66 (defconst shuowen-radicals
67 [?一 ?上 ?示 ?三 ?王 ?玉 ?玨 ?气 ?士 ?丨 ; 010
68 ?屮 ?艸 ?蓐 ?茻 ?小 ?八 ?釆 ?半 ?牛 ?犛 ; 020
69 ?告 ?口 ?凵 ?吅 ?哭 ?走 ?止 ?癶 ?步 ?此 ; 030
70 ?正 ?是 ?辵 ?彳 ?廴 ?㢟 ?行 ?齒 ?牙 ?足 ; 040
71 ?疋 ?品 ?龠 ?冊 ?㗊 ?舌 ?干 ?谷 ?只 ?㕯 ; 050
72 ?句 ?丩 ?古 ?十 ?卅 ?言 ?誩 ?音 ?䇂 ?丵 ; 060
73 ?菐 ?𠬞 ?𠬜 ?共 ?異 ?舁 ?𦥑 ?䢅 ?爨 ?革 ; 070
74 ?鬲 ?䰜 ?爪 ?𠃨 ?鬥 ?又 ?𠂇 ?㕜 ?支 ?𦘒 ; 080
75 ?聿 ?畫 ?隶 ?臤 ?臣 ?殳 ?殺 ?𠘧 ?寸 ?皮 ; 090
76 ?㼱 ?攴 ?敎 ?卜 ?用 ?爻 ?㸚 ?𥄎 ?目 ?䀠 ; 100
77 ?眉 ?盾 ?自 ?白 ?鼻 ?皕 ?習 ?羽 ?隹 ?奞 ; 110
78 ?萑 ?𦫳 ?苜 ?羊 ?羴 ?瞿 ?雔 ?雥 ?鳥 ?烏 ; 120
79 ?𠦒 ?冓 ?幺 ?𢆶 ?叀 ?玄 ?予 ?放 ?𠬪 ?𣦼 ; 130
80 ?歺 ?死 ?冎 ?骨 ?肉 ?筋 ?刀 ?刃 ?㓞 ?丰 ; 140
81 ?耒 ?𧢲 ?竹 ?箕 ?丌 ?左 ?工 ?㠭 ?巫 ?甘 ; 150
82 ?曰 ?乃 ?丂 ?可 ?兮 ?号 ?亏 ?旨 ?喜 ?壴 ; 160
83 ; ?旨 ?曰 ?乃 ?丂 ?可 ?兮 ?号 ?亏 ?喜 ?壴 ; 160
84 ?鼓 ?豈 ?豆 ?豊 ?豐 ?䖒 ?虍 ?虎 ?虤 ?皿 ; 170
85 ?𠙴 ?去 ?血 ?丶 ?丹 ?青 ?井 ?皀 ?鬯 ?食 ; 180
86 ?亼 ?會 ?倉 ?入 ?缶 ?矢 ?高 ?冂 ?𩫏 ?京 ; 190
87 ?亯 ?𣆪 ?畗 ?㐭 ?嗇 ?來 ?麥 ?夊 ?舛 ?䑞 ; 200
88 ?韋 ?弟 ?夂 ?久 ?桀 ?木 ?東 ?林 ?才 ?叒 ; 210
89 ?之 ?帀 ?出 ?𣎵 ?生 ?乇 ?𠂹 ?𠌶 ?華 ?𥝌 ; 220
90 ?稽 ?巢 ?桼 ?束 ?㯻 ?囗 ?員 ?貝 ?邑 ?𨛜 ; 230
91 ?日 ?旦 ?倝 ?㫃 ?冥 ?晶 ?月 ?有 ?明 ?囧 ; 240
92 ?夕 ?多 ?毌 ?𢎘 ?𣐺 ?卣 ?齊 ?朿 ?片 ?鼎 ; 250
93 ?克 ?彔 ?禾 ?秝 ?黍 ?香 ?米 ?毇 ?臼 ?凶 ; 260
94 ?𣎳 ?林 ?麻 ?尗 ?耑 ?韭 ?瓜 ?瓠 ?宀 ?宮 ; 270
95 ?呂 ?穴 ?㝱 ?𤕫 ?冖 ?𠔼 ?冃 ?㒳 ?网 ?襾 ; 280
96 ?巾 ?巿 ?帛 ?白 ?㡀 ?黹 ?人 ?𠤎 ?匕 ?从 ; 290
97 ?比 ?北 ?丘 ?㐺 ?𡈼 ?重 ?臥 ?身 ?㐆 ?衣 ; 300
100 (defun shuowen-radical (number)
101 (aref shuowen-radicals (1- number)))
103 (defvar char-db-file-coding-system 'utf-8-mcs-er)
105 (defvar char-db-ignored-attributes '(ideographic-products))
107 (defvar char-db-coded-charset-priority-list
197 ;; =>>>adobe-japan1-0
198 ;; =>>>adobe-japan1-1
199 ;; =>>>adobe-japan1-2
200 ;; =>>>adobe-japan1-3
201 ;; =>>>adobe-japan1-4
202 ;; =>>>adobe-japan1-5
203 ;; =>>>adobe-japan1-6
207 ;; =>>>hanyo-denshi/ja
208 ;; =>>>hanyo-denshi/jb
209 ;; =>>>hanyo-denshi/jc
210 ;; =>>>hanyo-denshi/ft
211 ;; =>>>hanyo-denshi/ib
212 ;; =>>>hanyo-denshi/hg
213 ;; =>>>hanyo-denshi/jt
214 ;; =>>>hanyo-denshi/ks
301 ;;; @ char-db formatters
304 (defun char-db-make-char-spec (char)
306 (cond ((characterp char)
307 (cond ((and (setq ret (encode-char char '=ucs 'defined-only))
308 (not (and (<= #xE000 ret)(<= ret #xF8FF))))
309 (setq char-spec (list (cons '=ucs ret)))
310 (cond ((setq ret (get-char-attribute char 'name))
311 (setq char-spec (cons (cons 'name ret) char-spec))
313 ((setq ret (get-char-attribute char 'name*))
314 (setq char-spec (cons (cons 'name* ret) char-spec))
317 ((encode-char char '=adobe-japan1 'defined-only)
319 (dolist (ccs (charset-list))
320 (if (and (or (memq ccs
329 ;; (eq (charset-property ccs 'iso-ir) 177)
330 (string-match "=ucs@" (symbol-name ccs))
332 (setq ccs (charset-name ccs))
333 (null (assq ccs char-spec))
334 (setq ret (encode-char char ccs 'defined-only)))
335 (setq char-spec (cons (cons ccs ret) char-spec))))
337 ((encode-char char '==adobe-japan1 'defined-only)
339 (dolist (ccs (charset-list))
340 (if (and (or (memq ccs
349 ;; (eq (charset-property ccs 'iso-ir) 177)
350 (string-match "=ucs@" (symbol-name ccs))
352 (setq ccs (charset-name ccs))
353 (null (assq ccs char-spec))
354 (setq ret (encode-char char ccs 'defined-only)))
355 (setq char-spec (cons (cons ccs ret) char-spec))))
359 (let ((rest char-db-coded-charset-priority-list)
362 (setq ccs (charset-name
363 (find-charset (car rest))))
365 (encode-char char ccs
367 (throw 'tag (cons ccs ret)))
368 (setq rest (cdr rest))))))
369 (setq char-spec (list ret))
370 (dolist (ccs (delq (car ret) (charset-list)))
371 (if (and (or (charset-iso-final-char ccs)
378 (eq (charset-property ccs 'iso-ir) 177)
379 ;; (string-match "=ucs@" (symbol-name ccs))
381 (setq ccs (charset-name ccs))
382 (null (assq ccs char-spec))
383 (setq ret (encode-char char ccs 'defined-only)))
384 (setq char-spec (cons (cons ccs ret) char-spec))))
386 (setq char-spec (split-char char)))
387 (cond ((setq ret (get-char-attribute char 'name))
388 (setq char-spec (cons (cons 'name ret) char-spec))
390 ((setq ret (get-char-attribute char 'name*))
391 (setq char-spec (cons (cons 'name* ret) char-spec))
394 ((setq ret (get-char-attribute
395 char 'ideographic-combination))
397 (cons (cons 'ideographic-combination ret)
404 (defun char-db-insert-char-spec (char &optional readable column
407 (setq column (current-column)))
408 (let (char-spec temp-char)
409 (setq char-spec (char-db-make-char-spec char))
410 (unless (or (characterp char) ; char
412 (setq char (find-char char-spec))
414 ;; define temporary character
415 ;; Current implementation is dirty.
416 (setq temp-char (define-char (cons '(ideograph-daikanwa . 0)
418 (remove-char-attribute temp-char 'ideograph-daikanwa)
419 (setq char temp-char))
420 (insert-char-attributes char
422 (union (mapcar #'car char-spec)
426 ;; undefine temporary character
427 ;; Current implementation is dirty.
428 (setq char-spec (char-attribute-alist temp-char))
430 (remove-char-attribute temp-char (car (car char-spec)))
431 (setq char-spec (cdr char-spec))))))
433 (defun char-db-insert-alist (alist &optional readable column)
435 (setq column (current-column)))
437 (concat "\n" (make-string (1+ column) ?\ )))
441 lbs cell rest separator)
444 (setq name (car (car alist))
445 value (cdr (car alist)))
446 (cond ((eq name 'char)
448 (if (setq ret (condition-case nil
456 (setq key (car (car value)))
457 ;; (if (find-charset key)
458 ;; (setq cal (cons key cal))
459 (setq al (cons key al))
461 (setq value (cdr value)))
462 (insert-char-attributes ret
466 (insert (prin1-to-string value)))
468 (insert line-breaking))
470 (insert (format "(%-18s " name))
471 (setq lbs (concat "\n" (make-string (current-column) ?\ )))
473 (setq cell (car value))
474 (if (and (consp cell)
476 (setq ret (condition-case nil
486 (setq key (car (car rest)))
487 ;; (if (find-charset key)
488 ;; (setq cal (cons key cal))
489 (setq al (cons key al))
491 (setq rest (cdr rest)))
494 (insert-char-attributes ret
498 (setq separator lbs))
501 (insert (prin1-to-string cell))
502 (setq separator " "))
503 (setq value (cdr value)))
505 (insert line-breaking))
507 (insert (format "(%-18s . %S)%s"
510 (setq alist (cdr alist))))
513 (defun char-db-insert-char-reference (plist &optional readable column)
515 (setq column (current-column)))
517 (concat "\n" (make-string (1+ column) ?\ )))
522 (setq name (pop plist))
523 (setq value (pop plist))
524 (cond ((eq name :char)
527 (cond ((numberp value)
528 (setq value (decode-char '=ucs value)))
530 ;; (setq value (or (find-char value)
533 (char-db-insert-char-spec value readable)
534 (insert line-breaking)
537 (insert (format "%s%s\t%d ; %c%s"
540 (ideographic-radical value)
544 (insert (format "%s%s\t%S" separator name value))
545 (setq separator line-breaking)))
549 (defun char-db-decode-isolated-char (ccs code-point)
552 (cond ((eq ccs 'arabic-iso8859-6)
553 (decode-char ccs code-point))
555 ;; (decode-builtin-char '==gt code-point))
556 ((and (memq ccs '(=gt-pj-1
567 (setq ret (decode-char ccs code-point))
568 (setq ret (encode-char ret '=gt 'defined-only)))
569 (decode-builtin-char '=gt ret))
571 (decode-builtin-char ccs code-point))))
572 (cond ((and (<= 0 (char-int ret))
573 (<= (char-int ret) #x1F))
574 (decode-char '=ucs (+ #x2400 (char-int ret))))
575 ((= (char-int ret) #x7F)
579 (defvar char-db-convert-obsolete-format t)
581 (defun char-db-insert-ccs-feature (name value line-breaking)
587 ((memq name '(==shinjigen
590 =shinjigen@rev =shinjigen/+p@rev
591 =daikanwa/ho =>>daikanwa/ho =>daikanwa/ho))
592 "(%-18s . %04d)\t; %c")
593 ((eq name '=shinjigen@1ed/24pr)
594 "(%-18s . %04d)\t; %c")
595 ((or (memq name '(==daikanwa
596 =daikanwa =>>daikanwa =>daikanwa
597 =daikanwa@rev1 =daikanwa@rev2
598 =daikanwa/+p =>>daikanwa/+p
599 =daikanwa/+2p =>>daikanwa/+2p
602 =gt-k ==gt-k =>>gt-k =>gt-k
603 =adobe-japan1-0 ==adobe-japan1-0 ; =>>>adobe-japan1-0
604 =adobe-japan1-1 ==adobe-japan1-1 ; =>>>adobe-japan1-1
605 =adobe-japan1-2 ==adobe-japan1-2 ; =>>>adobe-japan1-2
606 =adobe-japan1-3 ==adobe-japan1-3 ; =>>>adobe-japan1-3
607 =adobe-japan1-4 ==adobe-japan1-4 ; =>>>adobe-japan1-4
608 =adobe-japan1-5 ==adobe-japan1-5 ; =>>>adobe-japan1-5
609 =adobe-japan1-6 ==adobe-japan1-6 ; =>>>adobe-japan1-6
610 =>>adobe-japan1-0 =+>adobe-japan1-0
611 =>>adobe-japan1-1 =+>adobe-japan1-1
612 =>>adobe-japan1-2 =+>adobe-japan1-2
613 =>>adobe-japan1-3 =+>adobe-japan1-3
614 =>>adobe-japan1-4 =+>adobe-japan1-4
615 =>>adobe-japan1-5 =+>adobe-japan1-5
616 =>>adobe-japan1-6 =+>adobe-japan1-6
618 =zinbun-oracle =>zinbun-oracle))
619 ;; (string-match "^=adobe-" (symbol-name name))
621 "(%-18s . %05d)\t; %c")
622 ((memq name '(=hanyo-denshi/ks
623 ==hanyo-denshi/ks ; =>>>hanyo-denshi/ks
626 "(%-18s . %06d)\t; %c")
627 ((>= (charset-dimension name) 2)
628 "(%-18s . #x%04X)\t; %c")
630 "(%-18s . #x%02X)\t; %c"))
632 (if (= (charset-iso-graphic-plane name) 1)
634 (cond ((= (charset-dimension name) 1)
636 ((= (charset-dimension name) 2)
638 ((= (charset-dimension name) 3)
642 (char-db-decode-isolated-char name value)))
643 (if (and (= (charset-chars name) 94)
644 (= (charset-dimension name) 2))
645 (insert (format " [%02d-%02d]"
646 (- (lsh value -8) 32)
647 (- (logand value 255) 32))))
650 (insert (format "(%-18s . %s)" name value))
652 (insert line-breaking))
654 (defun char-db-insert-relation-feature (char name value line-breaking
656 (insert (format "(%-18s%s " name line-breaking))
657 (let ((lbs (concat "\n" (make-string (current-column) ?\ )))
658 separator cell sources required-features
661 (setq cell (car value))
663 (setq cell (decode-char '=ucs cell)))
665 ((eq name '->subsumptive)
666 (when (or (not (some (lambda (atr)
667 (get-char-attribute cell atr))
668 char-db-ignored-attributes))
670 (encode-char cell ccs 'defined-only))
674 (let ((char-db-ignored-attributes
676 char-db-ignored-attributes)))
677 (insert-char-attributes cell readable nil nil 'for-sub-node))
678 (setq separator lbs))
683 char (intern (format "%s*sources" name))))
684 (setq required-features nil)
685 (dolist (source sources)
689 shinjigen shinjigen@1ed shinjigen@rev))
690 (setq required-features
691 (union required-features
703 =shinjigen/+p@rev))))
705 (setq required-features
706 (union required-features
711 ((find-charset (setq ret (intern (format "=%s" source))))
712 (setq required-features
713 (cons ret required-features)))
714 (t (setq required-features
715 (cons source required-features)))))
716 (cond ((string-match "@JP" (symbol-name name))
717 (setq required-features
718 (union required-features
726 ((string-match "@CN" (symbol-name name))
727 (setq required-features
728 (union required-features
735 (insert (format "%S" cell))
736 (char-db-insert-char-spec cell readable
739 (setq separator lbs))
743 (if (consp (car cell))
744 (char-db-insert-char-spec cell readable)
745 (char-db-insert-char-reference cell readable))
746 (setq separator lbs))
750 (insert (prin1-to-string cell))
751 (setq separator " ")))
752 (setq value (cdr value)))
754 (insert line-breaking)))
756 (defun insert-char-attributes (char &optional readable attributes column
759 (setq column (current-column)))
760 (let (name value ; has-long-ccs-name
764 (concat "\n" (make-string (1+ column) ?\ )))
765 lbs cell separator ret
767 dest-ccss ; sources required-features
772 (if (consp attributes)
774 (dolist (name attributes)
775 (unless (memq name char-db-ignored-attributes)
776 (if (find-charset name)
780 (dolist (name (char-attribute-list))
781 (unless (memq name char-db-ignored-attributes)
782 (if (find-charset name)
786 #'char-attribute-name<)))
788 (when (memq '<-subsumptive attributes)
789 (when (or readable (not for-sub-node))
790 (when (setq value (get-char-attribute char '<-subsumptive))
791 (char-db-insert-relation-feature char '<-subsumptive value
794 (setq attributes (delq '<-subsumptive attributes)))
795 (when (and (memq '<-denotational attributes)
796 (setq value (get-char-attribute char '<-denotational)))
797 (char-db-insert-relation-feature char '<-denotational value
800 (setq attributes (delq '<-denotational attributes)))
801 (when (and (memq 'name attributes)
802 (setq value (get-char-attribute char 'name)))
804 (if (> (+ (current-column) (length value)) 48)
807 value line-breaking))
808 (setq attributes (delq 'name attributes))
810 (when (and (memq 'name* attributes)
811 (setq value (get-char-attribute char 'name*)))
813 (if (> (+ (current-column) (length value)) 48)
816 value line-breaking))
817 (setq attributes (delq 'name* attributes))
819 (when (and (memq 'script attributes)
820 (setq value (get-char-attribute char 'script)))
821 (insert (format "(script\t\t%s)%s"
822 (mapconcat (function prin1-to-string)
825 (setq attributes (delq 'script attributes))
827 (dolist (name '(=>ucs =>ucs*))
828 (when (and (memq name attributes)
829 (setq value (get-char-attribute char name)))
830 (insert (format "(%-18s . #x%04X)\t; %c%s"
831 name value (decode-char '=ucs value)
833 (setq attributes (delq name attributes))))
834 (dolist (name '(=>ucs@gb =>ucs@big5))
835 (when (and (memq name attributes)
836 (setq value (get-char-attribute char name)))
837 (insert (format "(%-18s . #x%04X)\t; %c%s"
842 (symbol-name name) 2)))
845 (setq attributes (delq name attributes))
847 ;; (dolist (name '(=>daikanwa))
848 ;; (when (and (memq name attributes)
849 ;; (setq value (get-char-attribute char name)))
851 ;; (if (integerp value)
852 ;; (format "(%-18s . %05d)\t; %c%s"
853 ;; name value (decode-char '=daikanwa value)
855 ;; (format "(%-18s %s)\t; %c%s"
857 ;; (mapconcat (function prin1-to-string)
859 ;; (char-representative-of-daikanwa char)
861 ;; (setq attributes (delq name attributes))))
862 (when (and (memq 'general-category attributes)
863 (setq value (get-char-attribute char 'general-category)))
865 "(general-category\t%s) ; %s%s"
866 (mapconcat (lambda (cell)
869 (cond ((rassoc value unidata-normative-category-alist)
870 "Normative Category")
871 ((rassoc value unidata-informative-category-alist)
872 "Informative Category")
876 (setq attributes (delq 'general-category attributes))
878 (when (and (memq 'bidi-category attributes)
879 (setq value (get-char-attribute char 'bidi-category)))
880 (insert (format "(bidi-category\t. %S)%s"
883 (setq attributes (delq 'bidi-category attributes))
885 (unless (or (not (memq 'mirrored attributes))
886 (eq (setq value (get-char-attribute char 'mirrored 'empty))
888 (insert (format "(mirrored\t\t. %S)%s"
891 (setq attributes (delq 'mirrored attributes))
894 ((and (memq 'decimal-digit-value attributes)
895 (setq value (get-char-attribute char 'decimal-digit-value)))
896 (insert (format "(decimal-digit-value . %S)%s"
899 (setq attributes (delq 'decimal-digit-value attributes))
900 (when (and (memq 'digit-value attributes)
901 (setq value (get-char-attribute char 'digit-value)))
902 (insert (format "(digit-value\t . %S)%s"
905 (setq attributes (delq 'digit-value attributes))
907 (when (and (memq 'numeric-value attributes)
908 (setq value (get-char-attribute char 'numeric-value)))
909 (insert (format "(numeric-value\t . %S)%s"
912 (setq attributes (delq 'numeric-value attributes))
916 (when (and (memq 'digit-value attributes)
917 (setq value (get-char-attribute char 'digit-value)))
918 (insert (format "(digit-value\t. %S)%s"
921 (setq attributes (delq 'digit-value attributes))
923 (when (and (memq 'numeric-value attributes)
924 (setq value (get-char-attribute char 'numeric-value)))
925 (insert (format "(numeric-value\t. %S)%s"
928 (setq attributes (delq 'numeric-value attributes))
930 (when (and (memq 'iso-10646-comment attributes)
931 (setq value (get-char-attribute char 'iso-10646-comment)))
932 (insert (format "(iso-10646-comment\t. %S)%s"
935 (setq attributes (delq 'iso-10646-comment attributes))
937 (when (and (memq 'morohashi-daikanwa attributes)
938 (setq value (get-char-attribute char 'morohashi-daikanwa)))
939 (insert (format "(morohashi-daikanwa\t%s)%s"
940 (mapconcat (function prin1-to-string) value " ")
942 (setq attributes (delq 'morohashi-daikanwa attributes))
946 (when (and (memq 'ideographic-radical attributes)
947 (setq value (get-char-attribute char 'ideographic-radical)))
949 (insert (format "(ideographic-radical . %S)\t; %c%s"
951 (ideographic-radical radical)
953 (setq attributes (delq 'ideographic-radical attributes))
955 (when (and (memq 'shuowen-radical attributes)
956 (setq value (get-char-attribute char 'shuowen-radical)))
957 (insert (format "(shuowen-radical\t. %S)\t; %c%s"
959 (shuowen-radical value)
961 (setq attributes (delq 'shuowen-radical attributes))
966 char-db-feature-domains
968 (dolist (feature (char-attribute-list))
969 (setq feature (symbol-name feature))
971 "\\(radical\\|strokes\\)@\\([^@*]+\\)\\(\\*\\|$\\)"
973 (setq domain (intern (match-string 2 feature)))
974 (unless (memq domain dest)
975 (setq dest (cons domain dest)))))
976 (sort dest #'string<))))
977 (setq key (intern (format "%s@%s" 'ideographic-radical domain)))
978 (when (and (memq key attributes)
979 (setq value (get-char-attribute char key)))
981 (insert (format "(%s . %S)\t; %c%s"
984 (ideographic-radical radical)
986 (setq attributes (delq key attributes))
988 (setq key (intern (format "%s@%s" 'ideographic-strokes domain)))
989 (when (and (memq key attributes)
990 (setq value (get-char-attribute char key)))
992 (insert (format "(%s . %S)%s"
996 (setq attributes (delq key attributes))
998 (setq key (intern (format "%s@%s" 'total-strokes domain)))
999 (when (and (memq key attributes)
1000 (setq value (get-char-attribute char key)))
1001 (insert (format "(%s . %S)%s"
1005 (setq attributes (delq key attributes))
1007 (dolist (feature '(ideographic-radical
1010 (setq key (intern (format "%s@%s*sources" feature domain)))
1011 (when (and (memq key attributes)
1012 (setq value (get-char-attribute char key)))
1013 (insert (format "(%s%s" key line-breaking))
1014 (dolist (cell value)
1015 (insert (format " %s" cell)))
1017 (insert line-breaking)
1018 (setq attributes (delq key attributes))
1021 (when (and (memq 'ideographic-strokes attributes)
1022 (setq value (get-char-attribute char 'ideographic-strokes)))
1023 (setq strokes value)
1024 (insert (format "(ideographic-strokes . %S)%s"
1027 (setq attributes (delq 'ideographic-strokes attributes))
1029 (when (and (memq 'kangxi-radical attributes)
1030 (setq value (get-char-attribute char 'kangxi-radical)))
1031 (unless (eq value radical)
1032 (insert (format "(kangxi-radical\t . %S)\t; %c%s"
1034 (ideographic-radical value)
1037 (setq radical value)))
1038 (setq attributes (delq 'kangxi-radical attributes))
1040 (when (and (memq 'kangxi-strokes attributes)
1041 (setq value (get-char-attribute char 'kangxi-strokes)))
1042 (unless (eq value strokes)
1043 (insert (format "(kangxi-strokes\t . %S)%s"
1047 (setq strokes value)))
1048 (setq attributes (delq 'kangxi-strokes attributes))
1050 (when (and (memq 'japanese-radical attributes)
1051 (setq value (get-char-attribute char 'japanese-radical)))
1052 (unless (eq value radical)
1053 (insert (format "(japanese-radical\t . %S)\t; %c%s"
1055 (ideographic-radical value)
1058 (setq radical value)))
1059 (setq attributes (delq 'japanese-radical attributes))
1061 (when (and (memq 'japanese-strokes attributes)
1062 (setq value (get-char-attribute char 'japanese-strokes)))
1063 (unless (eq value strokes)
1064 (insert (format "(japanese-strokes\t . %S)%s"
1068 (setq strokes value)))
1069 (setq attributes (delq 'japanese-strokes attributes))
1071 (when (and (memq 'cns-radical attributes)
1072 (setq value (get-char-attribute char 'cns-radical)))
1073 (insert (format "(cns-radical\t . %S)\t; %c%s"
1075 (ideographic-radical value)
1077 (setq attributes (delq 'cns-radical attributes))
1079 (when (and (memq 'cns-strokes attributes)
1080 (setq value (get-char-attribute char 'cns-strokes)))
1081 (unless (eq value strokes)
1082 (insert (format "(cns-strokes\t . %S)%s"
1086 (setq strokes value)))
1087 (setq attributes (delq 'cns-strokes attributes))
1089 ;; (when (and (memq 'shinjigen-1-radical attributes)
1090 ;; (setq value (get-char-attribute char 'shinjigen-1-radical)))
1091 ;; (unless (eq value radical)
1092 ;; (insert (format "(shinjigen-1-radical . %S)\t; %c%s"
1094 ;; (ideographic-radical value)
1097 ;; (setq radical value)))
1098 ;; (setq attributes (delq 'shinjigen-1-radical attributes))
1100 (when (and (memq 'ideographic- attributes)
1101 (setq value (get-char-attribute char 'ideographic-)))
1102 (insert "(ideographic- ")
1103 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1105 (while (consp value)
1106 (setq cell (car value))
1108 (setq cell (decode-char '=ucs cell)))
1109 (cond ((characterp cell)
1113 (insert (format "%S" cell))
1114 (char-db-insert-char-spec cell readable))
1115 (setq separator lbs))
1119 (if (consp (car cell))
1120 (char-db-insert-char-spec cell readable)
1121 (char-db-insert-char-reference cell readable))
1122 (setq separator lbs))
1126 (insert (prin1-to-string cell))
1127 (setq separator " ")))
1128 (setq value (cdr value)))
1130 (insert line-breaking)
1131 (setq attributes (delq 'ideographic- attributes)))
1132 (when (and (memq 'total-strokes attributes)
1133 (setq value (get-char-attribute char 'total-strokes)))
1134 (insert (format "(total-strokes . %S)%s"
1137 (setq attributes (delq 'total-strokes attributes))
1139 (when (and (memq '->ideograph attributes)
1140 (setq value (get-char-attribute char '->ideograph)))
1141 (insert (format "(->ideograph\t%s)%s"
1142 (mapconcat (lambda (code)
1143 (cond ((symbolp code)
1146 (format "#x%04X" code))
1149 line-breaking code))))
1152 (setq attributes (delq '->ideograph attributes))
1154 ;; (when (and (memq '->decomposition attributes)
1155 ;; (setq value (get-char-attribute char '->decomposition)))
1156 ;; (insert (format "(->decomposition\t%s)%s"
1157 ;; (mapconcat (lambda (code)
1158 ;; (cond ((symbolp code)
1159 ;; (symbol-name code))
1160 ;; ((characterp code)
1162 ;; (format "%S" code)
1167 ;; (format "#x%04X" code))
1169 ;; (format "%s%S" line-breaking code))))
1172 ;; (setq attributes (delq '->decomposition attributes))
1174 (if (equal (get-char-attribute char '->titlecase)
1175 (get-char-attribute char '->uppercase))
1176 (setq attributes (delq '->titlecase attributes)))
1177 (when (and (memq '->mojikyo attributes)
1178 (setq value (get-char-attribute char '->mojikyo)))
1179 (insert (format "(->mojikyo\t\t. %06d)\t; %c%s"
1180 value (decode-char 'mojikyo value)
1182 (setq attributes (delq '->mojikyo attributes))
1184 (when (and (memq 'hanyu-dazidian-vol attributes)
1185 (setq value (get-char-attribute char 'hanyu-dazidian-vol)))
1186 (insert (format "(hanyu-dazidian-vol . %d)%s"
1187 value line-breaking))
1188 (setq attributes (delq 'hanyu-dazidian-vol attributes))
1190 (when (and (memq 'hanyu-dazidian-page attributes)
1191 (setq value (get-char-attribute char 'hanyu-dazidian-page)))
1192 (insert (format "(hanyu-dazidian-page . %d)%s"
1193 value line-breaking))
1194 (setq attributes (delq 'hanyu-dazidian-page attributes))
1196 (when (and (memq 'hanyu-dazidian-char attributes)
1197 (setq value (get-char-attribute char 'hanyu-dazidian-char)))
1198 (insert (format "(hanyu-dazidian-char . %d)%s"
1199 value line-breaking))
1200 (setq attributes (delq 'hanyu-dazidian-char attributes))
1203 (dolist (ignored '(composition
1204 ->denotational <-subsumptive ->ucs-unified
1205 ->ideographic-component-forms))
1206 (setq attributes (delq ignored attributes))))
1208 (setq name (car attributes))
1209 (unless (eq (setq value (get-char-attribute char name 'value-is-empty))
1211 (cond ((setq ret (find-charset name))
1212 (setq name (charset-name ret))
1213 (when (not (memq name dest-ccss))
1214 (setq dest-ccss (cons name dest-ccss))
1215 (char-db-insert-ccs-feature name value line-breaking))
1217 ((string-match "^=>ucs@" (symbol-name name))
1218 (insert (format "(%-18s . #x%04X)\t; %c%s"
1219 name value (decode-char '=ucs value)
1222 ((eq name 'jisx0208-1978/4X)
1223 (insert (format "(%-18s . #x%04X)%s"
1229 (not (eq name '->subsumptive))
1230 (not (eq name '->uppercase))
1231 (not (eq name '->lowercase))
1232 (not (eq name '->titlecase))
1233 (not (eq name '->canonical))
1234 (not (eq name '->Bopomofo))
1235 (not (eq name '->mistakable))
1236 (not (eq name '->ideographic-variants))
1237 (null (get-char-attribute
1238 char (intern (format "%s*sources" name))))
1239 (not (string-match "\\*sources$" (symbol-name name)))
1240 (null (get-char-attribute
1241 char (intern (format "%s*note" name))))
1242 (not (string-match "\\*note$" (symbol-name name)))
1243 (or (eq name '<-identical)
1244 (eq name '<-uppercase)
1245 (eq name '<-lowercase)
1246 (eq name '<-titlecase)
1247 (eq name '<-canonical)
1248 (eq name '<-ideographic-variants)
1249 ;; (eq name '<-synonyms)
1250 (string-match "^<-synonyms" (symbol-name name))
1251 (eq name '<-mistakable)
1252 (when (string-match "^->" (symbol-name name))
1254 ((string-match "^->fullwidth" (symbol-name name))
1255 (not (and (consp value)
1256 (characterp (car value))
1258 (car value) '=ucs 'defined-only)))
1263 ((or (eq name 'ideographic-structure)
1264 (eq name 'ideographic-combination)
1265 (eq name 'ideographic-)
1266 (eq name '=decomposition)
1267 (char-feature-base-name= '=decomposition name)
1268 (char-feature-base-name= '=>decomposition name)
1269 ;; (string-match "^=>*decomposition\\(@[^*]+\\)?$"
1270 ;; (symbol-name name))
1271 (string-match "^\\(->\\|<-\\)[^*]*$" (symbol-name name))
1272 (string-match "^\\(->\\|<-\\)[^*]*\\*sources$"
1275 (char-db-insert-relation-feature char name value
1278 ((memq name '(ideograph=
1279 original-ideograph-of
1280 ancient-ideograph-of
1283 ;; simplified-ideograph-of
1284 ideographic-variants
1285 ;; ideographic-different-form-of
1287 (insert (format "(%-18s%s " name line-breaking))
1288 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1290 (while (consp value)
1291 (setq cell (car value))
1292 (if (and (consp cell)
1297 (char-db-insert-alist cell readable)
1298 (setq separator lbs))
1301 (insert (prin1-to-string cell))
1302 (setq separator " "))
1303 (setq value (cdr value)))
1305 (insert line-breaking))
1307 (insert (format "(%-18s " name))
1308 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1310 (while (consp value)
1311 (setq cell (car value))
1312 (if (and (consp cell)
1314 (setq ret (condition-case nil
1322 (setq key (car (car rest)))
1323 (if (find-charset key)
1324 (setq cal (cons key cal))
1325 (setq al (cons key al)))
1326 (setq rest (cdr rest)))
1329 (insert-char-attributes ret
1333 (setq separator lbs))
1334 (setq ret (prin1-to-string cell))
1336 (if (< (+ (current-column)
1343 (setq separator " "))
1344 (setq value (cdr value)))
1346 (insert line-breaking))
1348 (insert (format "(%-18s" name))
1349 (setq ret (prin1-to-string value))
1350 (unless (< (+ (current-column)
1354 (insert line-breaking))
1355 (insert " . " ret ")" line-breaking)
1356 ;; (insert (format "(%-18s . %S)%s"
1361 (setq attributes (cdr attributes)))
1364 (defun insert-char-data (char &optional readable
1367 (narrow-to-region (point)(point))
1368 (insert "(define-char
1370 (insert-char-attributes char readable attributes)
1372 (goto-char (point-min))
1373 (while (re-search-forward "[ \t]+$" nil t)
1376 (goto-char (point-min))
1377 (while (re-search-forward "[ \t][ \t][ \t]*" nil t)
1378 (let ((column (current-column))
1379 (indent-tabs-mode t))
1380 (delete-region (match-beginning 0) (point))
1381 (indent-to column)))
1382 (goto-char (point-max))
1383 ;; (tabify (point-min)(point-max))
1386 (defun insert-char-data-with-variant (char &optional printable
1388 script excluded-script)
1389 (insert-char-data char printable)
1390 (let ((variants (char-variants char))
1393 (setq variants (sort variants #'<))
1394 (setq rest variants)
1395 (setq variants (cons char variants))
1397 (setq variant (car rest))
1398 (unless (get-char-attribute variant '<-subsumptive)
1399 (if (and (or (null script)
1400 (null (setq vs (get-char-attribute variant 'script)))
1402 (or (null excluded-script)
1403 (null (setq vs (get-char-attribute variant 'script)))
1404 (not (memq excluded-script vs))))
1405 (unless (and no-ucs-unified (get-char-attribute variant '=ucs))
1406 (insert-char-data variant printable)
1407 (if (setq ret (char-variants variant))
1409 (or (memq (car ret) variants)
1410 ;; (get-char-attribute (car ret) '<-subsumptive)
1411 (setq rest (nconc rest (list (car ret)))))
1412 (setq ret (cdr ret)))))))
1413 (setq rest (cdr rest)))))
1415 (defun insert-char-range-data (min max &optional script excluded-script)
1418 (while (<= code max)
1419 (setq char (decode-char '=ucs code))
1420 (if (encode-char char '=ucs 'defined-only)
1421 (insert-char-data-with-variant char nil 'no-ucs-unified
1422 script excluded-script))
1423 (setq code (1+ code)))))
1425 (defun write-char-range-data-to-file (min max file
1426 &optional script excluded-script)
1427 (let ((coding-system-for-write char-db-file-coding-system))
1429 (insert (format ";; -*- coding: %s -*-\n"
1430 char-db-file-coding-system))
1431 (insert-char-range-data min max script excluded-script)
1432 (write-region (point-min)(point-max) file))))
1434 (defvar what-character-original-window-configuration)
1437 (defun what-char-definition (char)
1438 (interactive (list (char-after)))
1439 (let ((buf (get-buffer-create "*Character Description*"))
1440 (the-buf (current-buffer))
1441 (win-conf (current-window-configuration)))
1443 (make-local-variable 'what-character-original-window-configuration)
1444 (setq what-character-original-window-configuration win-conf)
1445 (setq buffer-read-only nil)
1449 (insert-char-data-with-variant char 'printable)
1450 (unless (char-attribute-alist char)
1451 (insert (format ";; = %c\n"
1452 (let* ((rest (split-char char))
1456 (setq code (logior (lsh code 8)
1458 (decode-char ccs code)))))
1459 ;; (char-db-update-comment)
1460 (set-buffer-modified-p nil)
1461 (view-mode the-buf (lambda (buf)
1462 (set-window-configuration
1463 what-character-original-window-configuration)
1465 (goto-char (point-min)))
1467 (set-window-configuration
1468 what-character-original-window-configuration)
1469 (signal (car err) (cdr err)))))))
1475 (provide 'char-db-util)
1477 ;;; char-db-util.el ends here