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
98 ?裘 ?老 ?毛 ?毳 ?尸 ?尺 ?尾 ?履 ?舟 ?方 ; 310
99 ?儿 ?兄 ?兂 ?皃 ?𠑹 ?先 ?秃 ?見 ?覞 ?欠 ; 320
100 ?㱃 ?㳄 ?旡 ?頁 ?𦣻 ?面 ?丏 ?首 ?𥄉 ?須 ; 330
103 (defun shuowen-radical (number)
104 (aref shuowen-radicals (1- number)))
106 (defvar char-db-file-coding-system 'utf-8-mcs-er)
108 (defvar char-db-ignored-attributes '(ideographic-products))
110 (defvar char-db-coded-charset-priority-list
203 ;; =>>>adobe-japan1-0
204 ;; =>>>adobe-japan1-1
205 ;; =>>>adobe-japan1-2
206 ;; =>>>adobe-japan1-3
207 ;; =>>>adobe-japan1-4
208 ;; =>>>adobe-japan1-5
209 ;; =>>>adobe-japan1-6
213 ;; =>>>hanyo-denshi/ja
214 ;; =>>>hanyo-denshi/jb
215 ;; =>>>hanyo-denshi/jc
216 ;; =>>>hanyo-denshi/ft
217 ;; =>>>hanyo-denshi/ib
218 ;; =>>>hanyo-denshi/hg
219 ;; =>>>hanyo-denshi/jt
220 ;; =>>>hanyo-denshi/ks
311 ;;; @ char-db formatters
314 (defun char-db-make-char-spec (char)
316 (cond ((characterp char)
317 (cond ((and (setq ret (encode-char char '=ucs 'defined-only))
318 (not (and (<= #xE000 ret)(<= ret #xF8FF))))
319 (setq char-spec (list (cons '=ucs ret)))
320 (cond ((setq ret (get-char-attribute char 'name))
321 (setq char-spec (cons (cons 'name ret) char-spec))
323 ((setq ret (get-char-attribute char 'name*))
324 (setq char-spec (cons (cons 'name* ret) char-spec))
327 ((encode-char char '=mj 'defined-only)
329 (dolist (ccs (charset-list))
330 (if (and (or (eq ccs '=mj)
331 ;; (eq (charset-property ccs 'iso-ir) 177)
332 (string-match "=ucs@" (symbol-name ccs))
334 (setq ccs (charset-name ccs))
335 (null (assq ccs char-spec))
336 (setq ret (encode-char char ccs 'defined-only)))
337 (setq char-spec (cons (cons ccs ret) char-spec))))
339 ((encode-char char '==mj 'defined-only)
341 (dolist (ccs (charset-list))
342 (if (and (or (eq ccs '==mj)
343 ;; (eq (charset-property ccs 'iso-ir) 177)
344 (string-match "=ucs@" (symbol-name ccs))
346 (setq ccs (charset-name ccs))
347 (null (assq ccs char-spec))
348 (setq ret (encode-char char ccs 'defined-only)))
349 (setq char-spec (cons (cons ccs ret) char-spec))))
351 ((encode-char char '=adobe-japan1 'defined-only)
353 (dolist (ccs (charset-list))
354 (if (and (or (memq ccs
363 ;; (eq (charset-property ccs 'iso-ir) 177)
364 (string-match "=ucs@" (symbol-name ccs))
366 (setq ccs (charset-name ccs))
367 (null (assq ccs char-spec))
368 (setq ret (encode-char char ccs 'defined-only)))
369 (setq char-spec (cons (cons ccs ret) char-spec))))
371 ((encode-char char '==adobe-japan1 'defined-only)
373 (dolist (ccs (charset-list))
374 (if (and (or (memq ccs
383 ;; (eq (charset-property ccs 'iso-ir) 177)
384 (string-match "=ucs@" (symbol-name ccs))
386 (setq ccs (charset-name ccs))
387 (null (assq ccs char-spec))
388 (setq ret (encode-char char ccs 'defined-only)))
389 (setq char-spec (cons (cons ccs ret) char-spec))))
393 (let ((rest char-db-coded-charset-priority-list)
396 (setq ccs (charset-name
397 (find-charset (car rest))))
399 (encode-char char ccs
401 (throw 'tag (cons ccs ret)))
402 (setq rest (cdr rest))))))
403 (setq char-spec (list ret))
404 (dolist (ccs (delq (car ret) (charset-list)))
405 (if (and (or (charset-iso-final-char ccs)
412 (eq (charset-property ccs 'iso-ir) 177)
413 ;; (string-match "=ucs@" (symbol-name ccs))
415 (setq ccs (charset-name ccs))
416 (null (assq ccs char-spec))
417 (setq ret (encode-char char ccs 'defined-only)))
418 (setq char-spec (cons (cons ccs ret) char-spec))))
420 (setq char-spec (split-char char)))
421 (cond ((setq ret (get-char-attribute char 'name))
422 (setq char-spec (cons (cons 'name ret) char-spec))
424 ((setq ret (get-char-attribute char 'name*))
425 (setq char-spec (cons (cons 'name* ret) char-spec))
428 ((setq ret (get-char-attribute
429 char 'ideographic-combination))
431 (cons (cons 'ideographic-combination ret)
438 (defun char-db-insert-char-spec (char &optional readable column
441 (setq column (current-column)))
442 (let (char-spec temp-char)
443 (setq char-spec (char-db-make-char-spec char))
444 (unless (or (characterp char) ; char
446 (setq char (find-char char-spec))
448 ;; define temporary character
449 ;; Current implementation is dirty.
450 (setq temp-char (define-char (cons '(ideograph-daikanwa . 0)
452 (remove-char-attribute temp-char 'ideograph-daikanwa)
453 (setq char temp-char))
454 (insert-char-attributes char
456 (union (mapcar #'car char-spec)
460 ;; undefine temporary character
461 ;; Current implementation is dirty.
462 (setq char-spec (char-attribute-alist temp-char))
464 (remove-char-attribute temp-char (car (car char-spec)))
465 (setq char-spec (cdr char-spec))))))
467 (defun char-db-insert-alist (alist &optional readable column)
469 (setq column (current-column)))
471 (concat "\n" (make-string (1+ column) ?\ )))
475 lbs cell rest separator)
478 (setq name (car (car alist))
479 value (cdr (car alist)))
480 (cond ((eq name 'char)
482 (if (setq ret (condition-case nil
490 (setq key (car (car value)))
491 ;; (if (find-charset key)
492 ;; (setq cal (cons key cal))
493 (setq al (cons key al))
495 (setq value (cdr value)))
496 (insert-char-attributes ret
500 (insert (prin1-to-string value)))
502 (insert line-breaking))
504 (insert (format "(%-18s " name))
505 (setq lbs (concat "\n" (make-string (current-column) ?\ )))
507 (setq cell (car value))
508 (if (and (consp cell)
510 (setq ret (condition-case nil
520 (setq key (car (car rest)))
521 ;; (if (find-charset key)
522 ;; (setq cal (cons key cal))
523 (setq al (cons key al))
525 (setq rest (cdr rest)))
528 (insert-char-attributes ret
532 (setq separator lbs))
535 (insert (prin1-to-string cell))
536 (setq separator " "))
537 (setq value (cdr value)))
539 (insert line-breaking))
541 (insert (format "(%-18s . %S)%s"
544 (setq alist (cdr alist))))
547 (defun char-db-insert-char-reference (plist &optional readable column)
549 (setq column (current-column)))
551 (concat "\n" (make-string (1+ column) ?\ )))
556 (setq name (pop plist))
557 (setq value (pop plist))
558 (cond ((eq name :char)
561 (cond ((numberp value)
562 (setq value (decode-char '=ucs value)))
564 ;; (setq value (or (find-char value)
567 (char-db-insert-char-spec value readable)
568 (insert line-breaking)
571 (insert (format "%s%s\t%d ; %c%s"
574 (ideographic-radical value)
578 (insert (format "%s%s\t%S" separator name value))
579 (setq separator line-breaking)))
583 (defun char-db-decode-isolated-char (ccs code-point)
586 (cond ((eq ccs 'arabic-iso8859-6)
587 (decode-char ccs code-point))
589 ;; (decode-builtin-char '==gt code-point))
590 ((and (memq ccs '(=gt-pj-1
601 (setq ret (decode-char ccs code-point))
602 (setq ret (encode-char ret '=gt 'defined-only)))
603 (decode-builtin-char '=gt ret))
605 (decode-builtin-char ccs code-point))))
606 (cond ((and (<= 0 (char-int ret))
607 (<= (char-int ret) #x1F))
608 (decode-char '=ucs (+ #x2400 (char-int ret))))
609 ((= (char-int ret) #x7F)
613 (defvar char-db-convert-obsolete-format t)
615 (defun char-db-insert-ccs-feature (name value line-breaking)
621 ((memq name '(==shinjigen
623 =shinjigen@1ed ==shinjigen@1ed
624 =shinjigen@rev ==shinjigen@rev
625 =shinjigen/+p@rev ==shinjigen/+p@rev
627 =daikanwa/ho =>>daikanwa/ho =>daikanwa/ho))
628 "(%-18s . %04d)\t; %c")
629 ((eq name '=shinjigen@1ed/24pr)
630 "(%-18s . %04d)\t; %c")
631 ((or (memq name '(==daikanwa
632 =daikanwa =>>daikanwa =>daikanwa
633 =daikanwa@rev1 =daikanwa@rev2
634 =daikanwa/+p ==daikanwa/+p =>>daikanwa/+p
635 =daikanwa/+2p =>>daikanwa/+2p
638 =gt-k ==gt-k =>>gt-k =>gt-k
639 =adobe-japan1-0 ==adobe-japan1-0 ; =>>>adobe-japan1-0
640 =adobe-japan1-1 ==adobe-japan1-1 ; =>>>adobe-japan1-1
641 =adobe-japan1-2 ==adobe-japan1-2 ; =>>>adobe-japan1-2
642 =adobe-japan1-3 ==adobe-japan1-3 ; =>>>adobe-japan1-3
643 =adobe-japan1-4 ==adobe-japan1-4 ; =>>>adobe-japan1-4
644 =adobe-japan1-5 ==adobe-japan1-5 ; =>>>adobe-japan1-5
645 =adobe-japan1-6 ==adobe-japan1-6 ; =>>>adobe-japan1-6
646 =>>adobe-japan1-0 =+>adobe-japan1-0
647 =>>adobe-japan1-1 =+>adobe-japan1-1
648 =>>adobe-japan1-2 =+>adobe-japan1-2
649 =>>adobe-japan1-3 =+>adobe-japan1-3
650 =>>adobe-japan1-4 =+>adobe-japan1-4
651 =>>adobe-japan1-5 =+>adobe-japan1-5
652 =>>adobe-japan1-6 =+>adobe-japan1-6
654 =zinbun-oracle =>zinbun-oracle))
655 ;; (string-match "^=adobe-" (symbol-name name))
657 "(%-18s . %05d)\t; %c")
658 ((memq name '(=hanyo-denshi/ks
659 ==hanyo-denshi/ks ; =>>>hanyo-denshi/ks
664 "(%-18s . %06d)\t; %c")
665 ((>= (charset-dimension name) 2)
666 "(%-18s . #x%04X)\t; %c")
668 "(%-18s . #x%02X)\t; %c"))
670 (if (= (charset-iso-graphic-plane name) 1)
672 (cond ((= (charset-dimension name) 1)
674 ((= (charset-dimension name) 2)
676 ((= (charset-dimension name) 3)
680 (char-db-decode-isolated-char name value)))
681 (if (and (= (charset-chars name) 94)
682 (= (charset-dimension name) 2))
683 (insert (format " [%02d-%02d]"
684 (- (lsh value -8) 32)
685 (- (logand value 255) 32))))
688 (insert (format "(%-18s . %s)" name value))
690 (insert line-breaking))
692 (defun char-db-insert-relation-feature (char name value line-breaking
694 (insert (format "(%-18s%s " name line-breaking))
695 (let ((lbs (concat "\n" (make-string (current-column) ?\ )))
696 separator cell sources required-features
699 (setq cell (car value))
701 (setq cell (decode-char '=ucs cell)))
703 ((eq name '->subsumptive)
704 (when (or (not (some (lambda (atr)
705 (get-char-attribute cell atr))
706 char-db-ignored-attributes))
708 (encode-char cell ccs 'defined-only))
712 (let ((char-db-ignored-attributes
714 char-db-ignored-attributes)))
715 (insert-char-attributes cell readable nil nil 'for-sub-node))
716 (setq separator lbs))
721 char (intern (format "%s*sources" name))))
722 (setq required-features nil)
723 (dolist (source sources)
727 shinjigen shinjigen@1ed shinjigen@rev))
728 (setq required-features
729 (union required-features
741 =shinjigen/+p@rev))))
743 (setq required-features
744 (union required-features
749 ((find-charset (setq ret (intern (format "=%s" source))))
750 (setq required-features
751 (cons ret required-features)))
752 (t (setq required-features
753 (cons source required-features)))))
754 (cond ((string-match "@JP" (symbol-name name))
755 (setq required-features
756 (union required-features
764 ((string-match "@CN" (symbol-name name))
765 (setq required-features
766 (union required-features
773 (insert (format "%S" cell))
774 (char-db-insert-char-spec cell readable
777 (setq separator lbs))
781 (if (consp (car cell))
782 (char-db-insert-char-spec cell readable)
783 (char-db-insert-char-reference cell readable))
784 (setq separator lbs))
788 (insert (prin1-to-string cell))
789 (setq separator " ")))
790 (setq value (cdr value)))
792 (insert line-breaking)))
794 (defun insert-char-attributes (char &optional readable attributes column
797 (setq column (current-column)))
798 (let (name value ; has-long-ccs-name
802 (concat "\n" (make-string (1+ column) ?\ )))
803 lbs cell separator ret
805 dest-ccss ; sources required-features
810 (if (consp attributes)
812 (dolist (name attributes)
813 (unless (memq name char-db-ignored-attributes)
814 (if (find-charset name)
818 (dolist (name (char-attribute-list))
819 (unless (memq name char-db-ignored-attributes)
820 (if (find-charset name)
824 #'char-attribute-name<)))
826 (when (memq '<-subsumptive attributes)
827 (when (or readable (not for-sub-node))
828 (when (setq value (get-char-attribute char '<-subsumptive))
829 (char-db-insert-relation-feature char '<-subsumptive value
832 (setq attributes (delq '<-subsumptive attributes)))
833 (when (and (memq '<-denotational attributes)
834 (setq value (get-char-attribute char '<-denotational)))
835 (char-db-insert-relation-feature char '<-denotational value
838 (setq attributes (delq '<-denotational attributes)))
839 (when (and (memq 'name attributes)
840 (setq value (get-char-attribute char 'name)))
842 (if (> (+ (current-column) (length value)) 48)
845 value line-breaking))
846 (setq attributes (delq 'name attributes))
848 (when (and (memq 'name* attributes)
849 (setq value (get-char-attribute char 'name*)))
851 (if (> (+ (current-column) (length value)) 48)
854 value line-breaking))
855 (setq attributes (delq 'name* attributes))
857 (when (and (memq 'script attributes)
858 (setq value (get-char-attribute char 'script)))
859 (insert (format "(script\t\t%s)%s"
860 (mapconcat (function prin1-to-string)
863 (setq attributes (delq 'script attributes))
865 (dolist (name '(=>ucs =>ucs*))
866 (when (and (memq name attributes)
867 (setq value (get-char-attribute char name)))
868 (insert (format "(%-18s . #x%04X)\t; %c%s"
869 name value (decode-char '=ucs value)
871 (setq attributes (delq name attributes))))
872 (dolist (name '(=>ucs@gb =>ucs@big5))
873 (when (and (memq name attributes)
874 (setq value (get-char-attribute char name)))
875 (insert (format "(%-18s . #x%04X)\t; %c%s"
880 (symbol-name name) 2)))
883 (setq attributes (delq name attributes))
885 ;; (dolist (name '(=>daikanwa))
886 ;; (when (and (memq name attributes)
887 ;; (setq value (get-char-attribute char name)))
889 ;; (if (integerp value)
890 ;; (format "(%-18s . %05d)\t; %c%s"
891 ;; name value (decode-char '=daikanwa value)
893 ;; (format "(%-18s %s)\t; %c%s"
895 ;; (mapconcat (function prin1-to-string)
897 ;; (char-representative-of-daikanwa char)
899 ;; (setq attributes (delq name attributes))))
900 (when (and (memq 'general-category attributes)
901 (setq value (get-char-attribute char 'general-category)))
903 "(general-category\t%s) ; %s%s"
904 (mapconcat (lambda (cell)
907 (cond ((rassoc value unidata-normative-category-alist)
908 "Normative Category")
909 ((rassoc value unidata-informative-category-alist)
910 "Informative Category")
914 (setq attributes (delq 'general-category attributes))
916 (when (and (memq 'bidi-category attributes)
917 (setq value (get-char-attribute char 'bidi-category)))
918 (insert (format "(bidi-category\t. %S)%s"
921 (setq attributes (delq 'bidi-category attributes))
923 (unless (or (not (memq 'mirrored attributes))
924 (eq (setq value (get-char-attribute char 'mirrored 'empty))
926 (insert (format "(mirrored\t\t. %S)%s"
929 (setq attributes (delq 'mirrored attributes))
932 ((and (memq 'decimal-digit-value attributes)
933 (setq value (get-char-attribute char 'decimal-digit-value)))
934 (insert (format "(decimal-digit-value . %S)%s"
937 (setq attributes (delq 'decimal-digit-value attributes))
938 (when (and (memq 'digit-value attributes)
939 (setq value (get-char-attribute char 'digit-value)))
940 (insert (format "(digit-value\t . %S)%s"
943 (setq attributes (delq 'digit-value attributes))
945 (when (and (memq 'numeric-value attributes)
946 (setq value (get-char-attribute char 'numeric-value)))
947 (insert (format "(numeric-value\t . %S)%s"
950 (setq attributes (delq 'numeric-value attributes))
954 (when (and (memq 'digit-value attributes)
955 (setq value (get-char-attribute char 'digit-value)))
956 (insert (format "(digit-value\t. %S)%s"
959 (setq attributes (delq 'digit-value attributes))
961 (when (and (memq 'numeric-value attributes)
962 (setq value (get-char-attribute char 'numeric-value)))
963 (insert (format "(numeric-value\t. %S)%s"
966 (setq attributes (delq 'numeric-value attributes))
968 (when (and (memq 'iso-10646-comment attributes)
969 (setq value (get-char-attribute char 'iso-10646-comment)))
970 (insert (format "(iso-10646-comment\t. %S)%s"
973 (setq attributes (delq 'iso-10646-comment attributes))
975 (when (and (memq 'morohashi-daikanwa attributes)
976 (setq value (get-char-attribute char 'morohashi-daikanwa)))
977 (insert (format "(morohashi-daikanwa\t%s)%s"
978 (mapconcat (function prin1-to-string) value " ")
980 (setq attributes (delq 'morohashi-daikanwa attributes))
984 (when (and (memq 'ideographic-radical attributes)
985 (setq value (get-char-attribute char 'ideographic-radical)))
987 (insert (format "(ideographic-radical . %S)\t; %c%s"
989 (ideographic-radical radical)
991 (setq attributes (delq 'ideographic-radical attributes))
993 (when (and (memq 'shuowen-radical attributes)
994 (setq value (get-char-attribute char 'shuowen-radical)))
995 (insert (format "(shuowen-radical\t. %S)\t; %c%s"
997 (shuowen-radical value)
999 (setq attributes (delq 'shuowen-radical attributes))
1004 char-db-feature-domains
1006 (dolist (feature (char-attribute-list))
1007 (setq feature (symbol-name feature))
1009 "\\(radical\\|strokes\\)@\\([^@*]+\\)\\(\\*\\|$\\)"
1011 (setq domain (intern (match-string 2 feature)))
1012 (unless (memq domain dest)
1013 (setq dest (cons domain dest)))))
1014 (sort dest #'string<))))
1015 (setq key (intern (format "%s@%s" 'ideographic-radical domain)))
1016 (when (and (memq key attributes)
1017 (setq value (get-char-attribute char key)))
1018 (setq radical value)
1019 (insert (format "(%s . %S)\t; %c%s"
1022 (ideographic-radical radical)
1024 (setq attributes (delq key attributes))
1026 (setq key (intern (format "%s@%s" 'ideographic-strokes domain)))
1027 (when (and (memq key attributes)
1028 (setq value (get-char-attribute char key)))
1029 (setq strokes value)
1030 (insert (format "(%s . %S)%s"
1034 (setq attributes (delq key attributes))
1036 (setq key (intern (format "%s@%s" 'total-strokes domain)))
1037 (when (and (memq key attributes)
1038 (setq value (get-char-attribute char key)))
1039 (insert (format "(%s . %S)%s"
1043 (setq attributes (delq key attributes))
1045 (dolist (feature '(ideographic-radical
1048 (setq key (intern (format "%s@%s*sources" feature domain)))
1049 (when (and (memq key attributes)
1050 (setq value (get-char-attribute char key)))
1051 (insert (format "(%s%s" key line-breaking))
1052 (dolist (cell value)
1053 (insert (format " %s" cell)))
1055 (insert line-breaking)
1056 (setq attributes (delq key attributes))
1059 (when (and (memq 'ideographic-strokes attributes)
1060 (setq value (get-char-attribute char 'ideographic-strokes)))
1061 (setq strokes value)
1062 (insert (format "(ideographic-strokes . %S)%s"
1065 (setq attributes (delq 'ideographic-strokes attributes))
1067 (when (and (memq 'kangxi-radical attributes)
1068 (setq value (get-char-attribute char 'kangxi-radical)))
1069 (unless (eq value radical)
1070 (insert (format "(kangxi-radical\t . %S)\t; %c%s"
1072 (ideographic-radical value)
1075 (setq radical value)))
1076 (setq attributes (delq 'kangxi-radical attributes))
1078 (when (and (memq 'kangxi-strokes attributes)
1079 (setq value (get-char-attribute char 'kangxi-strokes)))
1080 (unless (eq value strokes)
1081 (insert (format "(kangxi-strokes\t . %S)%s"
1085 (setq strokes value)))
1086 (setq attributes (delq 'kangxi-strokes attributes))
1088 (when (and (memq 'japanese-radical attributes)
1089 (setq value (get-char-attribute char 'japanese-radical)))
1090 (unless (eq value radical)
1091 (insert (format "(japanese-radical\t . %S)\t; %c%s"
1093 (ideographic-radical value)
1096 (setq radical value)))
1097 (setq attributes (delq 'japanese-radical attributes))
1099 (when (and (memq 'japanese-strokes attributes)
1100 (setq value (get-char-attribute char 'japanese-strokes)))
1101 (unless (eq value strokes)
1102 (insert (format "(japanese-strokes\t . %S)%s"
1106 (setq strokes value)))
1107 (setq attributes (delq 'japanese-strokes attributes))
1109 (when (and (memq 'cns-radical attributes)
1110 (setq value (get-char-attribute char 'cns-radical)))
1111 (insert (format "(cns-radical\t . %S)\t; %c%s"
1113 (ideographic-radical value)
1115 (setq attributes (delq 'cns-radical attributes))
1117 (when (and (memq 'cns-strokes attributes)
1118 (setq value (get-char-attribute char 'cns-strokes)))
1119 (unless (eq value strokes)
1120 (insert (format "(cns-strokes\t . %S)%s"
1124 (setq strokes value)))
1125 (setq attributes (delq 'cns-strokes attributes))
1127 ;; (when (and (memq 'shinjigen-1-radical attributes)
1128 ;; (setq value (get-char-attribute char 'shinjigen-1-radical)))
1129 ;; (unless (eq value radical)
1130 ;; (insert (format "(shinjigen-1-radical . %S)\t; %c%s"
1132 ;; (ideographic-radical value)
1135 ;; (setq radical value)))
1136 ;; (setq attributes (delq 'shinjigen-1-radical attributes))
1138 (when (and (memq 'ideographic- attributes)
1139 (setq value (get-char-attribute char 'ideographic-)))
1140 (insert "(ideographic- ")
1141 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1143 (while (consp value)
1144 (setq cell (car value))
1146 (setq cell (decode-char '=ucs cell)))
1147 (cond ((characterp cell)
1151 (insert (format "%S" cell))
1152 (char-db-insert-char-spec cell readable))
1153 (setq separator lbs))
1157 (if (consp (car cell))
1158 (char-db-insert-char-spec cell readable)
1159 (char-db-insert-char-reference cell readable))
1160 (setq separator lbs))
1164 (insert (prin1-to-string cell))
1165 (setq separator " ")))
1166 (setq value (cdr value)))
1168 (insert line-breaking)
1169 (setq attributes (delq 'ideographic- attributes)))
1170 (when (and (memq 'total-strokes attributes)
1171 (setq value (get-char-attribute char 'total-strokes)))
1172 (insert (format "(total-strokes . %S)%s"
1175 (setq attributes (delq 'total-strokes attributes))
1177 (when (and (memq '->ideograph attributes)
1178 (setq value (get-char-attribute char '->ideograph)))
1179 (insert (format "(->ideograph\t%s)%s"
1180 (mapconcat (lambda (code)
1181 (cond ((symbolp code)
1184 (format "#x%04X" code))
1187 line-breaking code))))
1190 (setq attributes (delq '->ideograph attributes))
1192 ;; (when (and (memq '->decomposition attributes)
1193 ;; (setq value (get-char-attribute char '->decomposition)))
1194 ;; (insert (format "(->decomposition\t%s)%s"
1195 ;; (mapconcat (lambda (code)
1196 ;; (cond ((symbolp code)
1197 ;; (symbol-name code))
1198 ;; ((characterp code)
1200 ;; (format "%S" code)
1205 ;; (format "#x%04X" code))
1207 ;; (format "%s%S" line-breaking code))))
1210 ;; (setq attributes (delq '->decomposition attributes))
1212 (if (equal (get-char-attribute char '->titlecase)
1213 (get-char-attribute char '->uppercase))
1214 (setq attributes (delq '->titlecase attributes)))
1215 (when (and (memq '->mojikyo attributes)
1216 (setq value (get-char-attribute char '->mojikyo)))
1217 (insert (format "(->mojikyo\t\t. %06d)\t; %c%s"
1218 value (decode-char 'mojikyo value)
1220 (setq attributes (delq '->mojikyo attributes))
1222 (when (and (memq 'hanyu-dazidian-vol attributes)
1223 (setq value (get-char-attribute char 'hanyu-dazidian-vol)))
1224 (insert (format "(hanyu-dazidian-vol . %d)%s"
1225 value line-breaking))
1226 (setq attributes (delq 'hanyu-dazidian-vol attributes))
1228 (when (and (memq 'hanyu-dazidian-page attributes)
1229 (setq value (get-char-attribute char 'hanyu-dazidian-page)))
1230 (insert (format "(hanyu-dazidian-page . %d)%s"
1231 value line-breaking))
1232 (setq attributes (delq 'hanyu-dazidian-page attributes))
1234 (when (and (memq 'hanyu-dazidian-char attributes)
1235 (setq value (get-char-attribute char 'hanyu-dazidian-char)))
1236 (insert (format "(hanyu-dazidian-char . %d)%s"
1237 value line-breaking))
1238 (setq attributes (delq 'hanyu-dazidian-char attributes))
1241 (dolist (ignored '(composition
1242 ->denotational <-subsumptive ->ucs-unified
1243 ->ideographic-component-forms))
1244 (setq attributes (delq ignored attributes))))
1246 (setq name (car attributes))
1247 (unless (eq (setq value (get-char-attribute char name 'value-is-empty))
1249 (cond ((setq ret (find-charset name))
1250 (setq name (charset-name ret))
1251 (when (not (memq name dest-ccss))
1252 (setq dest-ccss (cons name dest-ccss))
1253 (char-db-insert-ccs-feature name value line-breaking))
1255 ((string-match "^=>ucs@" (symbol-name name))
1256 (insert (format "(%-18s . #x%04X)\t; %c%s"
1257 name value (decode-char '=ucs value)
1260 ((eq name 'jisx0208-1978/4X)
1261 (insert (format "(%-18s . #x%04X)%s"
1267 (not (eq name '->subsumptive))
1268 (not (eq name '->uppercase))
1269 (not (eq name '->lowercase))
1270 (not (eq name '->titlecase))
1271 (not (eq name '->canonical))
1272 (not (eq name '->Bopomofo))
1273 (not (eq name '->mistakable))
1274 (not (eq name '->ideographic-variants))
1275 (null (get-char-attribute
1276 char (intern (format "%s*sources" name))))
1277 (not (string-match "\\*sources$" (symbol-name name)))
1278 (null (get-char-attribute
1279 char (intern (format "%s*note" name))))
1280 (not (string-match "\\*note$" (symbol-name name)))
1281 (or (eq name '<-identical)
1282 (eq name '<-uppercase)
1283 (eq name '<-lowercase)
1284 (eq name '<-titlecase)
1285 (eq name '<-canonical)
1286 (eq name '<-ideographic-variants)
1287 ;; (eq name '<-synonyms)
1288 (string-match "^<-synonyms" (symbol-name name))
1289 (eq name '<-mistakable)
1290 (when (string-match "^->" (symbol-name name))
1292 ((string-match "^->fullwidth" (symbol-name name))
1293 (not (and (consp value)
1294 (characterp (car value))
1296 (car value) '=ucs 'defined-only)))
1301 ((or (eq name 'ideographic-structure)
1302 (eq name 'ideographic-combination)
1303 (eq name 'ideographic-)
1304 (eq name '=decomposition)
1305 (char-feature-base-name= '=decomposition name)
1306 (char-feature-base-name= '=>decomposition name)
1307 ;; (string-match "^=>*decomposition\\(@[^*]+\\)?$"
1308 ;; (symbol-name name))
1309 (string-match "^\\(->\\|<-\\)[^*]*$" (symbol-name name))
1310 (string-match "^\\(->\\|<-\\)[^*]*\\*sources$"
1313 (char-db-insert-relation-feature char name value
1316 ((memq name '(ideograph=
1317 original-ideograph-of
1318 ancient-ideograph-of
1321 ;; simplified-ideograph-of
1322 ideographic-variants
1323 ;; ideographic-different-form-of
1325 (insert (format "(%-18s%s " name line-breaking))
1326 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1328 (while (consp value)
1329 (setq cell (car value))
1330 (if (and (consp cell)
1335 (char-db-insert-alist cell readable)
1336 (setq separator lbs))
1339 (insert (prin1-to-string cell))
1340 (setq separator " "))
1341 (setq value (cdr value)))
1343 (insert line-breaking))
1345 (insert (format "(%-18s " name))
1346 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1348 (while (consp value)
1349 (setq cell (car value))
1350 (if (and (consp cell)
1352 (setq ret (condition-case nil
1360 (setq key (car (car rest)))
1361 (if (find-charset key)
1362 (setq cal (cons key cal))
1363 (setq al (cons key al)))
1364 (setq rest (cdr rest)))
1367 (insert-char-attributes ret
1371 (setq separator lbs))
1372 (setq ret (prin1-to-string cell))
1374 (if (< (+ (current-column)
1381 (setq separator " "))
1382 (setq value (cdr value)))
1384 (insert line-breaking))
1386 (insert (format "(%-18s" name))
1387 (setq ret (prin1-to-string value))
1388 (unless (< (+ (current-column)
1392 (insert line-breaking))
1393 (insert " . " ret ")" line-breaking)
1394 ;; (insert (format "(%-18s . %S)%s"
1399 (setq attributes (cdr attributes)))
1402 (defun insert-char-data (char &optional readable
1405 (narrow-to-region (point)(point))
1406 (insert "(define-char
1408 (insert-char-attributes char readable attributes)
1410 (goto-char (point-min))
1411 (while (re-search-forward "[ \t]+$" nil t)
1414 (goto-char (point-min))
1415 (while (re-search-forward "[ \t][ \t][ \t]*" nil t)
1416 (let ((column (current-column))
1417 (indent-tabs-mode t))
1418 (delete-region (match-beginning 0) (point))
1419 (indent-to column)))
1420 (goto-char (point-max))
1421 ;; (tabify (point-min)(point-max))
1424 (defun insert-char-data-with-variant (char &optional printable
1426 script excluded-script)
1427 (insert-char-data char printable)
1428 (let ((variants (char-variants char))
1431 (setq variants (sort variants #'<))
1432 (setq rest variants)
1433 (setq variants (cons char variants))
1435 (setq variant (car rest))
1436 (unless (get-char-attribute variant '<-subsumptive)
1437 (if (and (or (null script)
1438 (null (setq vs (get-char-attribute variant 'script)))
1440 (or (null excluded-script)
1441 (null (setq vs (get-char-attribute variant 'script)))
1442 (not (memq excluded-script vs))))
1443 (unless (and no-ucs-unified (get-char-attribute variant '=ucs))
1444 (insert-char-data variant printable)
1445 (if (setq ret (char-variants variant))
1447 (or (memq (car ret) variants)
1448 ;; (get-char-attribute (car ret) '<-subsumptive)
1449 (setq rest (nconc rest (list (car ret)))))
1450 (setq ret (cdr ret)))))))
1451 (setq rest (cdr rest)))))
1453 (defun insert-char-range-data (min max &optional script excluded-script)
1456 (while (<= code max)
1457 (setq char (decode-char '=ucs code))
1458 (if (encode-char char '=ucs 'defined-only)
1459 (insert-char-data-with-variant char nil 'no-ucs-unified
1460 script excluded-script))
1461 (setq code (1+ code)))))
1463 (defun write-char-range-data-to-file (min max file
1464 &optional script excluded-script)
1465 (let ((coding-system-for-write char-db-file-coding-system))
1467 (insert (format ";; -*- coding: %s -*-\n"
1468 char-db-file-coding-system))
1469 (insert-char-range-data min max script excluded-script)
1470 (write-region (point-min)(point-max) file))))
1472 (defvar what-character-original-window-configuration)
1475 (defun what-char-definition (char)
1476 (interactive (list (char-after)))
1477 (let ((buf (get-buffer-create "*Character Description*"))
1478 (the-buf (current-buffer))
1479 (win-conf (current-window-configuration)))
1481 (make-local-variable 'what-character-original-window-configuration)
1482 (setq what-character-original-window-configuration win-conf)
1483 (setq buffer-read-only nil)
1487 (insert-char-data-with-variant char 'printable)
1488 (unless (char-attribute-alist char)
1489 (insert (format ";; = %c\n"
1490 (let* ((rest (split-char char))
1494 (setq code (logior (lsh code 8)
1496 (decode-char ccs code)))))
1497 ;; (char-db-update-comment)
1498 (set-buffer-modified-p nil)
1499 (view-mode the-buf (lambda (buf)
1500 (set-window-configuration
1501 what-character-original-window-configuration)
1503 (goto-char (point-min)))
1505 (set-window-configuration
1506 what-character-original-window-configuration)
1507 (signal (car err) (cdr err)))))))
1513 (provide 'char-db-util)
1515 ;;; char-db-util.el ends here