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
102 (defun shuowen-radical (number)
103 (aref shuowen-radicals (1- number)))
105 (defvar char-db-file-coding-system 'utf-8-mcs-er)
107 (defvar char-db-ignored-attributes '(ideographic-products))
109 (defvar char-db-coded-charset-priority-list
202 ;; =>>>adobe-japan1-0
203 ;; =>>>adobe-japan1-1
204 ;; =>>>adobe-japan1-2
205 ;; =>>>adobe-japan1-3
206 ;; =>>>adobe-japan1-4
207 ;; =>>>adobe-japan1-5
208 ;; =>>>adobe-japan1-6
212 ;; =>>>hanyo-denshi/ja
213 ;; =>>>hanyo-denshi/jb
214 ;; =>>>hanyo-denshi/jc
215 ;; =>>>hanyo-denshi/ft
216 ;; =>>>hanyo-denshi/ib
217 ;; =>>>hanyo-denshi/hg
218 ;; =>>>hanyo-denshi/jt
219 ;; =>>>hanyo-denshi/ks
310 ;;; @ char-db formatters
313 (defun char-db-make-char-spec (char)
315 (cond ((characterp char)
316 (cond ((and (setq ret (encode-char char '=ucs 'defined-only))
317 (not (and (<= #xE000 ret)(<= ret #xF8FF))))
318 (setq char-spec (list (cons '=ucs ret)))
319 (cond ((setq ret (get-char-attribute char 'name))
320 (setq char-spec (cons (cons 'name ret) char-spec))
322 ((setq ret (get-char-attribute char 'name*))
323 (setq char-spec (cons (cons 'name* ret) char-spec))
326 ((encode-char char '=mj 'defined-only)
328 (dolist (ccs (charset-list))
329 (if (and (or (eq ccs '=mj)
330 ;; (eq (charset-property ccs 'iso-ir) 177)
331 (string-match "=ucs@" (symbol-name ccs))
333 (setq ccs (charset-name ccs))
334 (null (assq ccs char-spec))
335 (setq ret (encode-char char ccs 'defined-only)))
336 (setq char-spec (cons (cons ccs ret) char-spec))))
338 ((encode-char char '==mj 'defined-only)
340 (dolist (ccs (charset-list))
341 (if (and (or (eq ccs '==mj)
342 ;; (eq (charset-property ccs 'iso-ir) 177)
343 (string-match "=ucs@" (symbol-name ccs))
345 (setq ccs (charset-name ccs))
346 (null (assq ccs char-spec))
347 (setq ret (encode-char char ccs 'defined-only)))
348 (setq char-spec (cons (cons ccs ret) char-spec))))
350 ((encode-char char '=adobe-japan1 'defined-only)
352 (dolist (ccs (charset-list))
353 (if (and (or (memq ccs
362 ;; (eq (charset-property ccs 'iso-ir) 177)
363 (string-match "=ucs@" (symbol-name ccs))
365 (setq ccs (charset-name ccs))
366 (null (assq ccs char-spec))
367 (setq ret (encode-char char ccs 'defined-only)))
368 (setq char-spec (cons (cons ccs ret) char-spec))))
370 ((encode-char char '==adobe-japan1 'defined-only)
372 (dolist (ccs (charset-list))
373 (if (and (or (memq ccs
382 ;; (eq (charset-property ccs 'iso-ir) 177)
383 (string-match "=ucs@" (symbol-name ccs))
385 (setq ccs (charset-name ccs))
386 (null (assq ccs char-spec))
387 (setq ret (encode-char char ccs 'defined-only)))
388 (setq char-spec (cons (cons ccs ret) char-spec))))
392 (let ((rest char-db-coded-charset-priority-list)
395 (setq ccs (charset-name
396 (find-charset (car rest))))
398 (encode-char char ccs
400 (throw 'tag (cons ccs ret)))
401 (setq rest (cdr rest))))))
402 (setq char-spec (list ret))
403 (dolist (ccs (delq (car ret) (charset-list)))
404 (if (and (or (charset-iso-final-char ccs)
411 (eq (charset-property ccs 'iso-ir) 177)
412 ;; (string-match "=ucs@" (symbol-name ccs))
414 (setq ccs (charset-name ccs))
415 (null (assq ccs char-spec))
416 (setq ret (encode-char char ccs 'defined-only)))
417 (setq char-spec (cons (cons ccs ret) char-spec))))
419 (setq char-spec (split-char char)))
420 (cond ((setq ret (get-char-attribute char 'name))
421 (setq char-spec (cons (cons 'name ret) char-spec))
423 ((setq ret (get-char-attribute char 'name*))
424 (setq char-spec (cons (cons 'name* ret) char-spec))
427 ((setq ret (get-char-attribute
428 char 'ideographic-combination))
430 (cons (cons 'ideographic-combination ret)
437 (defun char-db-insert-char-spec (char &optional readable column
440 (setq column (current-column)))
441 (let (char-spec temp-char)
442 (setq char-spec (char-db-make-char-spec char))
443 (unless (or (characterp char) ; char
445 (setq char (find-char char-spec))
447 ;; define temporary character
448 ;; Current implementation is dirty.
449 (setq temp-char (define-char (cons '(ideograph-daikanwa . 0)
451 (remove-char-attribute temp-char 'ideograph-daikanwa)
452 (setq char temp-char))
453 (insert-char-attributes char
455 (union (mapcar #'car char-spec)
459 ;; undefine temporary character
460 ;; Current implementation is dirty.
461 (setq char-spec (char-attribute-alist temp-char))
463 (remove-char-attribute temp-char (car (car char-spec)))
464 (setq char-spec (cdr char-spec))))))
466 (defun char-db-insert-alist (alist &optional readable column)
468 (setq column (current-column)))
470 (concat "\n" (make-string (1+ column) ?\ )))
474 lbs cell rest separator)
477 (setq name (car (car alist))
478 value (cdr (car alist)))
479 (cond ((eq name 'char)
481 (if (setq ret (condition-case nil
489 (setq key (car (car value)))
490 ;; (if (find-charset key)
491 ;; (setq cal (cons key cal))
492 (setq al (cons key al))
494 (setq value (cdr value)))
495 (insert-char-attributes ret
499 (insert (prin1-to-string value)))
501 (insert line-breaking))
503 (insert (format "(%-18s " name))
504 (setq lbs (concat "\n" (make-string (current-column) ?\ )))
506 (setq cell (car value))
507 (if (and (consp cell)
509 (setq ret (condition-case nil
519 (setq key (car (car rest)))
520 ;; (if (find-charset key)
521 ;; (setq cal (cons key cal))
522 (setq al (cons key al))
524 (setq rest (cdr rest)))
527 (insert-char-attributes ret
531 (setq separator lbs))
534 (insert (prin1-to-string cell))
535 (setq separator " "))
536 (setq value (cdr value)))
538 (insert line-breaking))
540 (insert (format "(%-18s . %S)%s"
543 (setq alist (cdr alist))))
546 (defun char-db-insert-char-reference (plist &optional readable column)
548 (setq column (current-column)))
550 (concat "\n" (make-string (1+ column) ?\ )))
555 (setq name (pop plist))
556 (setq value (pop plist))
557 (cond ((eq name :char)
560 (cond ((numberp value)
561 (setq value (decode-char '=ucs value)))
563 ;; (setq value (or (find-char value)
566 (char-db-insert-char-spec value readable)
567 (insert line-breaking)
570 (insert (format "%s%s\t%d ; %c%s"
573 (ideographic-radical value)
577 (insert (format "%s%s\t%S" separator name value))
578 (setq separator line-breaking)))
582 (defun char-db-decode-isolated-char (ccs code-point)
585 (cond ((eq ccs 'arabic-iso8859-6)
586 (decode-char ccs code-point))
588 ;; (decode-builtin-char '==gt code-point))
589 ((and (memq ccs '(=gt-pj-1
600 (setq ret (decode-char ccs code-point))
601 (setq ret (encode-char ret '=gt 'defined-only)))
602 (decode-builtin-char '=gt ret))
604 (decode-builtin-char ccs code-point))))
605 (cond ((and (<= 0 (char-int ret))
606 (<= (char-int ret) #x1F))
607 (decode-char '=ucs (+ #x2400 (char-int ret))))
608 ((= (char-int ret) #x7F)
612 (defvar char-db-convert-obsolete-format t)
614 (defun char-db-insert-ccs-feature (name value line-breaking)
620 ((memq name '(==shinjigen
622 =shinjigen@1ed ==shinjigen@1ed
623 =shinjigen@rev ==shinjigen@rev
624 =shinjigen/+p@rev ==shinjigen/+p@rev
626 =daikanwa/ho =>>daikanwa/ho =>daikanwa/ho))
627 "(%-18s . %04d)\t; %c")
628 ((eq name '=shinjigen@1ed/24pr)
629 "(%-18s . %04d)\t; %c")
630 ((or (memq name '(==daikanwa
631 =daikanwa =>>daikanwa =>daikanwa
632 =daikanwa@rev1 =daikanwa@rev2
633 =daikanwa/+p ==daikanwa/+p =>>daikanwa/+p
634 =daikanwa/+2p =>>daikanwa/+2p
637 =gt-k ==gt-k =>>gt-k =>gt-k
638 =adobe-japan1-0 ==adobe-japan1-0 ; =>>>adobe-japan1-0
639 =adobe-japan1-1 ==adobe-japan1-1 ; =>>>adobe-japan1-1
640 =adobe-japan1-2 ==adobe-japan1-2 ; =>>>adobe-japan1-2
641 =adobe-japan1-3 ==adobe-japan1-3 ; =>>>adobe-japan1-3
642 =adobe-japan1-4 ==adobe-japan1-4 ; =>>>adobe-japan1-4
643 =adobe-japan1-5 ==adobe-japan1-5 ; =>>>adobe-japan1-5
644 =adobe-japan1-6 ==adobe-japan1-6 ; =>>>adobe-japan1-6
645 =>>adobe-japan1-0 =+>adobe-japan1-0
646 =>>adobe-japan1-1 =+>adobe-japan1-1
647 =>>adobe-japan1-2 =+>adobe-japan1-2
648 =>>adobe-japan1-3 =+>adobe-japan1-3
649 =>>adobe-japan1-4 =+>adobe-japan1-4
650 =>>adobe-japan1-5 =+>adobe-japan1-5
651 =>>adobe-japan1-6 =+>adobe-japan1-6
653 =zinbun-oracle =>zinbun-oracle))
654 ;; (string-match "^=adobe-" (symbol-name name))
656 "(%-18s . %05d)\t; %c")
657 ((memq name '(=hanyo-denshi/ks
658 ==hanyo-denshi/ks ; =>>>hanyo-denshi/ks
663 "(%-18s . %06d)\t; %c")
664 ((>= (charset-dimension name) 2)
665 "(%-18s . #x%04X)\t; %c")
667 "(%-18s . #x%02X)\t; %c"))
669 (if (= (charset-iso-graphic-plane name) 1)
671 (cond ((= (charset-dimension name) 1)
673 ((= (charset-dimension name) 2)
675 ((= (charset-dimension name) 3)
679 (char-db-decode-isolated-char name value)))
680 (if (and (= (charset-chars name) 94)
681 (= (charset-dimension name) 2))
682 (insert (format " [%02d-%02d]"
683 (- (lsh value -8) 32)
684 (- (logand value 255) 32))))
687 (insert (format "(%-18s . %s)" name value))
689 (insert line-breaking))
691 (defun char-db-insert-relation-feature (char name value line-breaking
693 (insert (format "(%-18s%s " name line-breaking))
694 (let ((lbs (concat "\n" (make-string (current-column) ?\ )))
695 separator cell sources required-features
698 (setq cell (car value))
700 (setq cell (decode-char '=ucs cell)))
702 ((eq name '->subsumptive)
703 (when (or (not (some (lambda (atr)
704 (get-char-attribute cell atr))
705 char-db-ignored-attributes))
707 (encode-char cell ccs 'defined-only))
711 (let ((char-db-ignored-attributes
713 char-db-ignored-attributes)))
714 (insert-char-attributes cell readable nil nil 'for-sub-node))
715 (setq separator lbs))
720 char (intern (format "%s*sources" name))))
721 (setq required-features nil)
722 (dolist (source sources)
726 shinjigen shinjigen@1ed shinjigen@rev))
727 (setq required-features
728 (union required-features
740 =shinjigen/+p@rev))))
742 (setq required-features
743 (union required-features
748 ((find-charset (setq ret (intern (format "=%s" source))))
749 (setq required-features
750 (cons ret required-features)))
751 (t (setq required-features
752 (cons source required-features)))))
753 (cond ((string-match "@JP" (symbol-name name))
754 (setq required-features
755 (union required-features
763 ((string-match "@CN" (symbol-name name))
764 (setq required-features
765 (union required-features
772 (insert (format "%S" cell))
773 (char-db-insert-char-spec cell readable
776 (setq separator lbs))
780 (if (consp (car cell))
781 (char-db-insert-char-spec cell readable)
782 (char-db-insert-char-reference cell readable))
783 (setq separator lbs))
787 (insert (prin1-to-string cell))
788 (setq separator " ")))
789 (setq value (cdr value)))
791 (insert line-breaking)))
793 (defun insert-char-attributes (char &optional readable attributes column
796 (setq column (current-column)))
797 (let (name value ; has-long-ccs-name
801 (concat "\n" (make-string (1+ column) ?\ )))
802 lbs cell separator ret
804 dest-ccss ; sources required-features
809 (if (consp attributes)
811 (dolist (name attributes)
812 (unless (memq name char-db-ignored-attributes)
813 (if (find-charset name)
817 (dolist (name (char-attribute-list))
818 (unless (memq name char-db-ignored-attributes)
819 (if (find-charset name)
823 #'char-attribute-name<)))
825 (when (memq '<-subsumptive attributes)
826 (when (or readable (not for-sub-node))
827 (when (setq value (get-char-attribute char '<-subsumptive))
828 (char-db-insert-relation-feature char '<-subsumptive value
831 (setq attributes (delq '<-subsumptive attributes)))
832 (when (and (memq '<-denotational attributes)
833 (setq value (get-char-attribute char '<-denotational)))
834 (char-db-insert-relation-feature char '<-denotational value
837 (setq attributes (delq '<-denotational attributes)))
838 (when (and (memq 'name attributes)
839 (setq value (get-char-attribute char 'name)))
841 (if (> (+ (current-column) (length value)) 48)
844 value line-breaking))
845 (setq attributes (delq 'name attributes))
847 (when (and (memq 'name* attributes)
848 (setq value (get-char-attribute char 'name*)))
850 (if (> (+ (current-column) (length value)) 48)
853 value line-breaking))
854 (setq attributes (delq 'name* attributes))
856 (when (and (memq 'script attributes)
857 (setq value (get-char-attribute char 'script)))
858 (insert (format "(script\t\t%s)%s"
859 (mapconcat (function prin1-to-string)
862 (setq attributes (delq 'script attributes))
864 (dolist (name '(=>ucs =>ucs*))
865 (when (and (memq name attributes)
866 (setq value (get-char-attribute char name)))
867 (insert (format "(%-18s . #x%04X)\t; %c%s"
868 name value (decode-char '=ucs value)
870 (setq attributes (delq name attributes))))
871 (dolist (name '(=>ucs@gb =>ucs@big5))
872 (when (and (memq name attributes)
873 (setq value (get-char-attribute char name)))
874 (insert (format "(%-18s . #x%04X)\t; %c%s"
879 (symbol-name name) 2)))
882 (setq attributes (delq name attributes))
884 ;; (dolist (name '(=>daikanwa))
885 ;; (when (and (memq name attributes)
886 ;; (setq value (get-char-attribute char name)))
888 ;; (if (integerp value)
889 ;; (format "(%-18s . %05d)\t; %c%s"
890 ;; name value (decode-char '=daikanwa value)
892 ;; (format "(%-18s %s)\t; %c%s"
894 ;; (mapconcat (function prin1-to-string)
896 ;; (char-representative-of-daikanwa char)
898 ;; (setq attributes (delq name attributes))))
899 (when (and (memq 'general-category attributes)
900 (setq value (get-char-attribute char 'general-category)))
902 "(general-category\t%s) ; %s%s"
903 (mapconcat (lambda (cell)
906 (cond ((rassoc value unidata-normative-category-alist)
907 "Normative Category")
908 ((rassoc value unidata-informative-category-alist)
909 "Informative Category")
913 (setq attributes (delq 'general-category attributes))
915 (when (and (memq 'bidi-category attributes)
916 (setq value (get-char-attribute char 'bidi-category)))
917 (insert (format "(bidi-category\t. %S)%s"
920 (setq attributes (delq 'bidi-category attributes))
922 (unless (or (not (memq 'mirrored attributes))
923 (eq (setq value (get-char-attribute char 'mirrored 'empty))
925 (insert (format "(mirrored\t\t. %S)%s"
928 (setq attributes (delq 'mirrored attributes))
931 ((and (memq 'decimal-digit-value attributes)
932 (setq value (get-char-attribute char 'decimal-digit-value)))
933 (insert (format "(decimal-digit-value . %S)%s"
936 (setq attributes (delq 'decimal-digit-value attributes))
937 (when (and (memq 'digit-value attributes)
938 (setq value (get-char-attribute char 'digit-value)))
939 (insert (format "(digit-value\t . %S)%s"
942 (setq attributes (delq 'digit-value attributes))
944 (when (and (memq 'numeric-value attributes)
945 (setq value (get-char-attribute char 'numeric-value)))
946 (insert (format "(numeric-value\t . %S)%s"
949 (setq attributes (delq 'numeric-value attributes))
953 (when (and (memq 'digit-value attributes)
954 (setq value (get-char-attribute char 'digit-value)))
955 (insert (format "(digit-value\t. %S)%s"
958 (setq attributes (delq 'digit-value attributes))
960 (when (and (memq 'numeric-value attributes)
961 (setq value (get-char-attribute char 'numeric-value)))
962 (insert (format "(numeric-value\t. %S)%s"
965 (setq attributes (delq 'numeric-value attributes))
967 (when (and (memq 'iso-10646-comment attributes)
968 (setq value (get-char-attribute char 'iso-10646-comment)))
969 (insert (format "(iso-10646-comment\t. %S)%s"
972 (setq attributes (delq 'iso-10646-comment attributes))
974 (when (and (memq 'morohashi-daikanwa attributes)
975 (setq value (get-char-attribute char 'morohashi-daikanwa)))
976 (insert (format "(morohashi-daikanwa\t%s)%s"
977 (mapconcat (function prin1-to-string) value " ")
979 (setq attributes (delq 'morohashi-daikanwa attributes))
983 (when (and (memq 'ideographic-radical attributes)
984 (setq value (get-char-attribute char 'ideographic-radical)))
986 (insert (format "(ideographic-radical . %S)\t; %c%s"
988 (ideographic-radical radical)
990 (setq attributes (delq 'ideographic-radical attributes))
992 (when (and (memq 'shuowen-radical attributes)
993 (setq value (get-char-attribute char 'shuowen-radical)))
994 (insert (format "(shuowen-radical\t. %S)\t; %c%s"
996 (shuowen-radical value)
998 (setq attributes (delq 'shuowen-radical attributes))
1003 char-db-feature-domains
1005 (dolist (feature (char-attribute-list))
1006 (setq feature (symbol-name feature))
1008 "\\(radical\\|strokes\\)@\\([^@*]+\\)\\(\\*\\|$\\)"
1010 (setq domain (intern (match-string 2 feature)))
1011 (unless (memq domain dest)
1012 (setq dest (cons domain dest)))))
1013 (sort dest #'string<))))
1014 (setq key (intern (format "%s@%s" 'ideographic-radical domain)))
1015 (when (and (memq key attributes)
1016 (setq value (get-char-attribute char key)))
1017 (setq radical value)
1018 (insert (format "(%s . %S)\t; %c%s"
1021 (ideographic-radical radical)
1023 (setq attributes (delq key attributes))
1025 (setq key (intern (format "%s@%s" 'ideographic-strokes domain)))
1026 (when (and (memq key attributes)
1027 (setq value (get-char-attribute char key)))
1028 (setq strokes value)
1029 (insert (format "(%s . %S)%s"
1033 (setq attributes (delq key attributes))
1035 (setq key (intern (format "%s@%s" 'total-strokes domain)))
1036 (when (and (memq key attributes)
1037 (setq value (get-char-attribute char key)))
1038 (insert (format "(%s . %S)%s"
1042 (setq attributes (delq key attributes))
1044 (dolist (feature '(ideographic-radical
1047 (setq key (intern (format "%s@%s*sources" feature domain)))
1048 (when (and (memq key attributes)
1049 (setq value (get-char-attribute char key)))
1050 (insert (format "(%s%s" key line-breaking))
1051 (dolist (cell value)
1052 (insert (format " %s" cell)))
1054 (insert line-breaking)
1055 (setq attributes (delq key attributes))
1058 (when (and (memq 'ideographic-strokes attributes)
1059 (setq value (get-char-attribute char 'ideographic-strokes)))
1060 (setq strokes value)
1061 (insert (format "(ideographic-strokes . %S)%s"
1064 (setq attributes (delq 'ideographic-strokes attributes))
1066 (when (and (memq 'kangxi-radical attributes)
1067 (setq value (get-char-attribute char 'kangxi-radical)))
1068 (unless (eq value radical)
1069 (insert (format "(kangxi-radical\t . %S)\t; %c%s"
1071 (ideographic-radical value)
1074 (setq radical value)))
1075 (setq attributes (delq 'kangxi-radical attributes))
1077 (when (and (memq 'kangxi-strokes attributes)
1078 (setq value (get-char-attribute char 'kangxi-strokes)))
1079 (unless (eq value strokes)
1080 (insert (format "(kangxi-strokes\t . %S)%s"
1084 (setq strokes value)))
1085 (setq attributes (delq 'kangxi-strokes attributes))
1087 (when (and (memq 'japanese-radical attributes)
1088 (setq value (get-char-attribute char 'japanese-radical)))
1089 (unless (eq value radical)
1090 (insert (format "(japanese-radical\t . %S)\t; %c%s"
1092 (ideographic-radical value)
1095 (setq radical value)))
1096 (setq attributes (delq 'japanese-radical attributes))
1098 (when (and (memq 'japanese-strokes attributes)
1099 (setq value (get-char-attribute char 'japanese-strokes)))
1100 (unless (eq value strokes)
1101 (insert (format "(japanese-strokes\t . %S)%s"
1105 (setq strokes value)))
1106 (setq attributes (delq 'japanese-strokes attributes))
1108 (when (and (memq 'cns-radical attributes)
1109 (setq value (get-char-attribute char 'cns-radical)))
1110 (insert (format "(cns-radical\t . %S)\t; %c%s"
1112 (ideographic-radical value)
1114 (setq attributes (delq 'cns-radical attributes))
1116 (when (and (memq 'cns-strokes attributes)
1117 (setq value (get-char-attribute char 'cns-strokes)))
1118 (unless (eq value strokes)
1119 (insert (format "(cns-strokes\t . %S)%s"
1123 (setq strokes value)))
1124 (setq attributes (delq 'cns-strokes attributes))
1126 ;; (when (and (memq 'shinjigen-1-radical attributes)
1127 ;; (setq value (get-char-attribute char 'shinjigen-1-radical)))
1128 ;; (unless (eq value radical)
1129 ;; (insert (format "(shinjigen-1-radical . %S)\t; %c%s"
1131 ;; (ideographic-radical value)
1134 ;; (setq radical value)))
1135 ;; (setq attributes (delq 'shinjigen-1-radical attributes))
1137 (when (and (memq 'ideographic- attributes)
1138 (setq value (get-char-attribute char 'ideographic-)))
1139 (insert "(ideographic- ")
1140 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1142 (while (consp value)
1143 (setq cell (car value))
1145 (setq cell (decode-char '=ucs cell)))
1146 (cond ((characterp cell)
1150 (insert (format "%S" cell))
1151 (char-db-insert-char-spec cell readable))
1152 (setq separator lbs))
1156 (if (consp (car cell))
1157 (char-db-insert-char-spec cell readable)
1158 (char-db-insert-char-reference cell readable))
1159 (setq separator lbs))
1163 (insert (prin1-to-string cell))
1164 (setq separator " ")))
1165 (setq value (cdr value)))
1167 (insert line-breaking)
1168 (setq attributes (delq 'ideographic- attributes)))
1169 (when (and (memq 'total-strokes attributes)
1170 (setq value (get-char-attribute char 'total-strokes)))
1171 (insert (format "(total-strokes . %S)%s"
1174 (setq attributes (delq 'total-strokes attributes))
1176 (when (and (memq '->ideograph attributes)
1177 (setq value (get-char-attribute char '->ideograph)))
1178 (insert (format "(->ideograph\t%s)%s"
1179 (mapconcat (lambda (code)
1180 (cond ((symbolp code)
1183 (format "#x%04X" code))
1186 line-breaking code))))
1189 (setq attributes (delq '->ideograph attributes))
1191 ;; (when (and (memq '->decomposition attributes)
1192 ;; (setq value (get-char-attribute char '->decomposition)))
1193 ;; (insert (format "(->decomposition\t%s)%s"
1194 ;; (mapconcat (lambda (code)
1195 ;; (cond ((symbolp code)
1196 ;; (symbol-name code))
1197 ;; ((characterp code)
1199 ;; (format "%S" code)
1204 ;; (format "#x%04X" code))
1206 ;; (format "%s%S" line-breaking code))))
1209 ;; (setq attributes (delq '->decomposition attributes))
1211 (if (equal (get-char-attribute char '->titlecase)
1212 (get-char-attribute char '->uppercase))
1213 (setq attributes (delq '->titlecase attributes)))
1214 (when (and (memq '->mojikyo attributes)
1215 (setq value (get-char-attribute char '->mojikyo)))
1216 (insert (format "(->mojikyo\t\t. %06d)\t; %c%s"
1217 value (decode-char 'mojikyo value)
1219 (setq attributes (delq '->mojikyo attributes))
1221 (when (and (memq 'hanyu-dazidian-vol attributes)
1222 (setq value (get-char-attribute char 'hanyu-dazidian-vol)))
1223 (insert (format "(hanyu-dazidian-vol . %d)%s"
1224 value line-breaking))
1225 (setq attributes (delq 'hanyu-dazidian-vol attributes))
1227 (when (and (memq 'hanyu-dazidian-page attributes)
1228 (setq value (get-char-attribute char 'hanyu-dazidian-page)))
1229 (insert (format "(hanyu-dazidian-page . %d)%s"
1230 value line-breaking))
1231 (setq attributes (delq 'hanyu-dazidian-page attributes))
1233 (when (and (memq 'hanyu-dazidian-char attributes)
1234 (setq value (get-char-attribute char 'hanyu-dazidian-char)))
1235 (insert (format "(hanyu-dazidian-char . %d)%s"
1236 value line-breaking))
1237 (setq attributes (delq 'hanyu-dazidian-char attributes))
1240 (dolist (ignored '(composition
1241 ->denotational <-subsumptive ->ucs-unified
1242 ->ideographic-component-forms))
1243 (setq attributes (delq ignored attributes))))
1245 (setq name (car attributes))
1246 (unless (eq (setq value (get-char-attribute char name 'value-is-empty))
1248 (cond ((setq ret (find-charset name))
1249 (setq name (charset-name ret))
1250 (when (not (memq name dest-ccss))
1251 (setq dest-ccss (cons name dest-ccss))
1252 (char-db-insert-ccs-feature name value line-breaking))
1254 ((string-match "^=>ucs@" (symbol-name name))
1255 (insert (format "(%-18s . #x%04X)\t; %c%s"
1256 name value (decode-char '=ucs value)
1259 ((eq name 'jisx0208-1978/4X)
1260 (insert (format "(%-18s . #x%04X)%s"
1266 (not (eq name '->subsumptive))
1267 (not (eq name '->uppercase))
1268 (not (eq name '->lowercase))
1269 (not (eq name '->titlecase))
1270 (not (eq name '->canonical))
1271 (not (eq name '->Bopomofo))
1272 (not (eq name '->mistakable))
1273 (not (eq name '->ideographic-variants))
1274 (null (get-char-attribute
1275 char (intern (format "%s*sources" name))))
1276 (not (string-match "\\*sources$" (symbol-name name)))
1277 (null (get-char-attribute
1278 char (intern (format "%s*note" name))))
1279 (not (string-match "\\*note$" (symbol-name name)))
1280 (or (eq name '<-identical)
1281 (eq name '<-uppercase)
1282 (eq name '<-lowercase)
1283 (eq name '<-titlecase)
1284 (eq name '<-canonical)
1285 (eq name '<-ideographic-variants)
1286 ;; (eq name '<-synonyms)
1287 (string-match "^<-synonyms" (symbol-name name))
1288 (eq name '<-mistakable)
1289 (when (string-match "^->" (symbol-name name))
1291 ((string-match "^->fullwidth" (symbol-name name))
1292 (not (and (consp value)
1293 (characterp (car value))
1295 (car value) '=ucs 'defined-only)))
1300 ((or (eq name 'ideographic-structure)
1301 (eq name 'ideographic-combination)
1302 (eq name 'ideographic-)
1303 (eq name '=decomposition)
1304 (char-feature-base-name= '=decomposition name)
1305 (char-feature-base-name= '=>decomposition name)
1306 ;; (string-match "^=>*decomposition\\(@[^*]+\\)?$"
1307 ;; (symbol-name name))
1308 (string-match "^\\(->\\|<-\\)[^*]*$" (symbol-name name))
1309 (string-match "^\\(->\\|<-\\)[^*]*\\*sources$"
1312 (char-db-insert-relation-feature char name value
1315 ((memq name '(ideograph=
1316 original-ideograph-of
1317 ancient-ideograph-of
1320 ;; simplified-ideograph-of
1321 ideographic-variants
1322 ;; ideographic-different-form-of
1324 (insert (format "(%-18s%s " name line-breaking))
1325 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1327 (while (consp value)
1328 (setq cell (car value))
1329 (if (and (consp cell)
1334 (char-db-insert-alist cell readable)
1335 (setq separator lbs))
1338 (insert (prin1-to-string cell))
1339 (setq separator " "))
1340 (setq value (cdr value)))
1342 (insert line-breaking))
1344 (insert (format "(%-18s " name))
1345 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1347 (while (consp value)
1348 (setq cell (car value))
1349 (if (and (consp cell)
1351 (setq ret (condition-case nil
1359 (setq key (car (car rest)))
1360 (if (find-charset key)
1361 (setq cal (cons key cal))
1362 (setq al (cons key al)))
1363 (setq rest (cdr rest)))
1366 (insert-char-attributes ret
1370 (setq separator lbs))
1371 (setq ret (prin1-to-string cell))
1373 (if (< (+ (current-column)
1380 (setq separator " "))
1381 (setq value (cdr value)))
1383 (insert line-breaking))
1385 (insert (format "(%-18s" name))
1386 (setq ret (prin1-to-string value))
1387 (unless (< (+ (current-column)
1391 (insert line-breaking))
1392 (insert " . " ret ")" line-breaking)
1393 ;; (insert (format "(%-18s . %S)%s"
1398 (setq attributes (cdr attributes)))
1401 (defun insert-char-data (char &optional readable
1404 (narrow-to-region (point)(point))
1405 (insert "(define-char
1407 (insert-char-attributes char readable attributes)
1409 (goto-char (point-min))
1410 (while (re-search-forward "[ \t]+$" nil t)
1413 (goto-char (point-min))
1414 (while (re-search-forward "[ \t][ \t][ \t]*" nil t)
1415 (let ((column (current-column))
1416 (indent-tabs-mode t))
1417 (delete-region (match-beginning 0) (point))
1418 (indent-to column)))
1419 (goto-char (point-max))
1420 ;; (tabify (point-min)(point-max))
1423 (defun insert-char-data-with-variant (char &optional printable
1425 script excluded-script)
1426 (insert-char-data char printable)
1427 (let ((variants (char-variants char))
1430 (setq variants (sort variants #'<))
1431 (setq rest variants)
1432 (setq variants (cons char variants))
1434 (setq variant (car rest))
1435 (unless (get-char-attribute variant '<-subsumptive)
1436 (if (and (or (null script)
1437 (null (setq vs (get-char-attribute variant 'script)))
1439 (or (null excluded-script)
1440 (null (setq vs (get-char-attribute variant 'script)))
1441 (not (memq excluded-script vs))))
1442 (unless (and no-ucs-unified (get-char-attribute variant '=ucs))
1443 (insert-char-data variant printable)
1444 (if (setq ret (char-variants variant))
1446 (or (memq (car ret) variants)
1447 ;; (get-char-attribute (car ret) '<-subsumptive)
1448 (setq rest (nconc rest (list (car ret)))))
1449 (setq ret (cdr ret)))))))
1450 (setq rest (cdr rest)))))
1452 (defun insert-char-range-data (min max &optional script excluded-script)
1455 (while (<= code max)
1456 (setq char (decode-char '=ucs code))
1457 (if (encode-char char '=ucs 'defined-only)
1458 (insert-char-data-with-variant char nil 'no-ucs-unified
1459 script excluded-script))
1460 (setq code (1+ code)))))
1462 (defun write-char-range-data-to-file (min max file
1463 &optional script excluded-script)
1464 (let ((coding-system-for-write char-db-file-coding-system))
1466 (insert (format ";; -*- coding: %s -*-\n"
1467 char-db-file-coding-system))
1468 (insert-char-range-data min max script excluded-script)
1469 (write-region (point-min)(point-max) file))))
1471 (defvar what-character-original-window-configuration)
1474 (defun what-char-definition (char)
1475 (interactive (list (char-after)))
1476 (let ((buf (get-buffer-create "*Character Description*"))
1477 (the-buf (current-buffer))
1478 (win-conf (current-window-configuration)))
1480 (make-local-variable 'what-character-original-window-configuration)
1481 (setq what-character-original-window-configuration win-conf)
1482 (setq buffer-read-only nil)
1486 (insert-char-data-with-variant char 'printable)
1487 (unless (char-attribute-alist char)
1488 (insert (format ";; = %c\n"
1489 (let* ((rest (split-char char))
1493 (setq code (logior (lsh code 8)
1495 (decode-char ccs code)))))
1496 ;; (char-db-update-comment)
1497 (set-buffer-modified-p nil)
1498 (view-mode the-buf (lambda (buf)
1499 (set-window-configuration
1500 what-character-original-window-configuration)
1502 (goto-char (point-min)))
1504 (set-window-configuration
1505 what-character-original-window-configuration)
1506 (signal (car err) (cdr err)))))))
1512 (provide 'char-db-util)
1514 ;;; char-db-util.el ends here