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
101 ?彡 ?彣 ?文 ?髟 ?后 ?司 ?卮 ?卩 ?印 ?色 ; 340
102 ?𠨍 ?辟 ?勹 ?包 ?茍 ?鬼 ?甶 ?厶 ?嵬 ?山 ; 350
103 ?屾 ?屵 ?广 ?厂 ?丸 ?危 ?石 ?長 ?勿 ?冄 ; 360
104 ?而 ?豕 ?㣇 ?彑 ?豚 ?豸 ?𤉡 ?易 ?象 ?馬 ; 370
105 ?𢊁 ?鹿 ?麤 ?㲋 ?兔 ?萈 ?犬 ?㹜 ?鼠 ?能 ; 380
108 (defun shuowen-radical (number)
109 (aref shuowen-radicals (1- number)))
111 (defvar char-db-file-coding-system 'utf-8-mcs-er)
113 (defvar char-db-ignored-attributes '(ideographic-products))
115 (defvar char-db-coded-charset-priority-list
208 ;; =>>>adobe-japan1-0
209 ;; =>>>adobe-japan1-1
210 ;; =>>>adobe-japan1-2
211 ;; =>>>adobe-japan1-3
212 ;; =>>>adobe-japan1-4
213 ;; =>>>adobe-japan1-5
214 ;; =>>>adobe-japan1-6
218 ;; =>>>hanyo-denshi/ja
219 ;; =>>>hanyo-denshi/jb
220 ;; =>>>hanyo-denshi/jc
221 ;; =>>>hanyo-denshi/ft
222 ;; =>>>hanyo-denshi/ib
223 ;; =>>>hanyo-denshi/hg
224 ;; =>>>hanyo-denshi/jt
225 ;; =>>>hanyo-denshi/ks
327 ;;; @ char-db formatters
330 (defun char-db-make-char-spec (char)
332 (cond ((characterp char)
333 (cond ((and (setq ret (encode-char char '=ucs 'defined-only))
334 (not (and (<= #xE000 ret)(<= ret #xF8FF))))
335 (setq char-spec (list (cons '=ucs ret)))
336 (cond ((setq ret (get-char-attribute char 'name))
337 (setq char-spec (cons (cons 'name ret) char-spec))
339 ((setq ret (get-char-attribute char 'name*))
340 (setq char-spec (cons (cons 'name* ret) char-spec))
343 ((encode-char char '=mj 'defined-only)
345 (dolist (ccs (charset-list))
346 (if (and (or (eq ccs '=mj)
347 ;; (eq (charset-property ccs 'iso-ir) 177)
348 (string-match "=ucs@" (symbol-name ccs))
350 (setq ccs (charset-name ccs))
351 (null (assq ccs char-spec))
352 (setq ret (encode-char char ccs 'defined-only)))
353 (setq char-spec (cons (cons ccs ret) char-spec))))
355 ((encode-char char '==mj 'defined-only)
357 (dolist (ccs (charset-list))
358 (if (and (or (eq ccs '==mj)
359 ;; (eq (charset-property ccs 'iso-ir) 177)
360 (string-match "=ucs@" (symbol-name ccs))
362 (setq ccs (charset-name ccs))
363 (null (assq ccs char-spec))
364 (setq ret (encode-char char ccs 'defined-only)))
365 (setq char-spec (cons (cons ccs ret) char-spec))))
367 ((encode-char char '=adobe-japan1 'defined-only)
369 (dolist (ccs (charset-list))
370 (if (and (or (memq ccs
379 ;; (eq (charset-property ccs 'iso-ir) 177)
380 (string-match "=ucs@" (symbol-name ccs))
382 (setq ccs (charset-name ccs))
383 (null (assq ccs char-spec))
384 (setq ret (encode-char char ccs 'defined-only)))
385 (setq char-spec (cons (cons ccs ret) char-spec))))
387 ((encode-char char '==adobe-japan1 'defined-only)
389 (dolist (ccs (charset-list))
390 (if (and (or (memq ccs
399 ;; (eq (charset-property ccs 'iso-ir) 177)
400 (string-match "=ucs@" (symbol-name ccs))
402 (setq ccs (charset-name ccs))
403 (null (assq ccs char-spec))
404 (setq ret (encode-char char ccs 'defined-only)))
405 (setq char-spec (cons (cons ccs ret) char-spec))))
409 (let ((rest char-db-coded-charset-priority-list)
412 (setq ccs (charset-name
413 (find-charset (car rest))))
415 (encode-char char ccs
417 (throw 'tag (cons ccs ret)))
418 (setq rest (cdr rest))))))
419 (setq char-spec (list ret))
420 (dolist (ccs (delq (car ret) (charset-list)))
421 (if (and (or (charset-iso-final-char ccs)
428 (eq (charset-property ccs 'iso-ir) 177)
429 ;; (string-match "=ucs@" (symbol-name ccs))
431 (setq ccs (charset-name ccs))
432 (null (assq ccs char-spec))
433 (setq ret (encode-char char ccs 'defined-only)))
434 (setq char-spec (cons (cons ccs ret) char-spec))))
436 (setq char-spec (split-char char)))
437 (cond ((setq ret (get-char-attribute char 'name))
438 (setq char-spec (cons (cons 'name ret) char-spec))
440 ((setq ret (get-char-attribute char 'name*))
441 (setq char-spec (cons (cons 'name* ret) char-spec))
444 ((setq ret (get-char-attribute
445 char 'ideographic-combination))
447 (cons (cons 'ideographic-combination ret)
454 (defun char-db-insert-char-spec (char &optional readable column
457 (setq column (current-column)))
458 (let (char-spec temp-char)
459 (setq char-spec (char-db-make-char-spec char))
460 (unless (or (characterp char) ; char
462 (setq char (find-char char-spec))
464 ;; define temporary character
465 ;; Current implementation is dirty.
466 (setq temp-char (define-char (cons '(ideograph-daikanwa . 0)
468 (remove-char-attribute temp-char 'ideograph-daikanwa)
469 (setq char temp-char))
470 (insert-char-attributes char
472 (union (mapcar #'car char-spec)
476 ;; undefine temporary character
477 ;; Current implementation is dirty.
478 (setq char-spec (char-attribute-alist temp-char))
480 (remove-char-attribute temp-char (car (car char-spec)))
481 (setq char-spec (cdr char-spec))))))
483 (defun char-db-insert-alist (alist &optional readable column)
485 (setq column (current-column)))
487 (concat "\n" (make-string (1+ column) ?\ )))
491 lbs cell rest separator)
494 (setq name (car (car alist))
495 value (cdr (car alist)))
496 (cond ((eq name 'char)
498 (if (setq ret (condition-case nil
506 (setq key (car (car value)))
507 ;; (if (find-charset key)
508 ;; (setq cal (cons key cal))
509 (setq al (cons key al))
511 (setq value (cdr value)))
512 (insert-char-attributes ret
516 (insert (prin1-to-string value)))
518 (insert line-breaking))
520 (insert (format "(%-18s " name))
521 (setq lbs (concat "\n" (make-string (current-column) ?\ )))
523 (setq cell (car value))
524 (if (and (consp cell)
526 (setq ret (condition-case nil
536 (setq key (car (car rest)))
537 ;; (if (find-charset key)
538 ;; (setq cal (cons key cal))
539 (setq al (cons key al))
541 (setq rest (cdr rest)))
544 (insert-char-attributes ret
548 (setq separator lbs))
551 (insert (prin1-to-string cell))
552 (setq separator " "))
553 (setq value (cdr value)))
555 (insert line-breaking))
557 (insert (format "(%-18s . %S)%s"
560 (setq alist (cdr alist))))
563 (defun char-db-insert-char-reference (plist &optional readable column)
565 (setq column (current-column)))
567 (concat "\n" (make-string (1+ column) ?\ )))
572 (setq name (pop plist))
573 (setq value (pop plist))
574 (cond ((eq name :char)
577 (cond ((numberp value)
578 (setq value (decode-char '=ucs value)))
580 ;; (setq value (or (find-char value)
583 (char-db-insert-char-spec value readable)
584 (insert line-breaking)
587 (insert (format "%s%s\t%d ; %c%s"
590 (ideographic-radical value)
594 (insert (format "%s%s\t%S" separator name value))
595 (setq separator line-breaking)))
599 (defun char-db-decode-isolated-char (ccs code-point)
602 (cond ((eq ccs 'arabic-iso8859-6)
603 (decode-char ccs code-point))
605 ;; (decode-builtin-char '==gt code-point))
606 ((and (memq ccs '(=gt-pj-1
617 (setq ret (decode-char ccs code-point))
618 (setq ret (encode-char ret '=gt 'defined-only)))
619 (decode-builtin-char '=gt ret))
621 (decode-builtin-char ccs code-point))))
622 (cond ((and (<= 0 (char-int ret))
623 (<= (char-int ret) #x1F))
624 (decode-char '=ucs (+ #x2400 (char-int ret))))
625 ((= (char-int ret) #x7F)
629 (defvar char-db-convert-obsolete-format t)
631 (defun char-db-insert-ccs-feature (name value line-breaking)
637 ((memq name '(==shinjigen
639 =shinjigen@1ed ==shinjigen@1ed
640 =shinjigen@rev ==shinjigen@rev
641 =shinjigen/+p@rev ==shinjigen/+p@rev
642 ===daikanwa/ho ==daikanwa/ho
643 =daikanwa/ho =>>daikanwa/ho =>daikanwa/ho))
644 "(%-18s . %04d)\t; %c")
645 ((eq name '=shinjigen@1ed/24pr)
646 "(%-18s . %04d)\t; %c")
647 ((or (memq name '(===daikanwa
648 ==daikanwa =daikanwa =>>daikanwa =>daikanwa
649 =daikanwa@rev1 =daikanwa@rev2
650 =daikanwa/+p ==daikanwa/+p ===daikanwa/+p
652 =daikanwa/+2p =>>daikanwa/+2p
657 =adobe-japan1-0 ==adobe-japan1-0 ===adobe-japan1-0
658 =adobe-japan1-1 ==adobe-japan1-1 ===adobe-japan1-1
659 =adobe-japan1-2 ==adobe-japan1-2 ===adobe-japan1-2
660 =adobe-japan1-3 ==adobe-japan1-3 ===adobe-japan1-3
661 =adobe-japan1-4 ==adobe-japan1-4 ===adobe-japan1-4
662 =adobe-japan1-5 ==adobe-japan1-5 ===adobe-japan1-5
663 =adobe-japan1-6 ==adobe-japan1-6 ===adobe-japan1-6
664 =>>adobe-japan1-0 =+>adobe-japan1-0
665 =>>adobe-japan1-1 =+>adobe-japan1-1
666 =>>adobe-japan1-2 =+>adobe-japan1-2
667 =>>adobe-japan1-3 =+>adobe-japan1-3
668 =>>adobe-japan1-4 =+>adobe-japan1-4
669 =>>adobe-japan1-5 =+>adobe-japan1-5
670 =>>adobe-japan1-6 =+>adobe-japan1-6
671 =>cbeta =cbeta =>>cbeta ==cbeta ===cbeta
672 =zinbun-oracle =>zinbun-oracle))
673 ;; (string-match "^=adobe-" (symbol-name name))
675 "(%-18s . %05d)\t; %c")
676 ((memq name '(=hanyo-denshi/ks
677 ==hanyo-denshi/ks ===hanyo-denshi/ks
682 "(%-18s . %06d)\t; %c")
683 ((>= (charset-dimension name) 2)
684 "(%-18s . #x%04X)\t; %c")
686 "(%-18s . #x%02X)\t; %c"))
688 (if (= (charset-iso-graphic-plane name) 1)
690 (cond ((= (charset-dimension name) 1)
692 ((= (charset-dimension name) 2)
694 ((= (charset-dimension name) 3)
698 (char-db-decode-isolated-char name value)))
699 (if (and (= (charset-chars name) 94)
700 (= (charset-dimension name) 2))
701 (insert (format " [%02d-%02d]"
702 (- (lsh value -8) 32)
703 (- (logand value 255) 32))))
706 (insert (format "(%-18s . %s)" name value))
708 (insert line-breaking))
710 (defun char-db-insert-relation-feature (char name value line-breaking
712 (insert (format "(%-18s%s " name line-breaking))
713 (let ((lbs (concat "\n" (make-string (current-column) ?\ )))
714 separator cell sources required-features
717 (setq cell (car value))
719 (setq cell (decode-char '=ucs cell)))
721 ((eq name '->subsumptive)
722 (when (or (not (some (lambda (atr)
723 (get-char-attribute cell atr))
724 char-db-ignored-attributes))
726 (encode-char cell ccs 'defined-only))
730 (let ((char-db-ignored-attributes
732 char-db-ignored-attributes)))
733 (insert-char-attributes cell readable nil nil 'for-sub-node))
734 (setq separator lbs))
739 char (intern (format "%s*sources" name))))
740 (setq required-features nil)
741 (dolist (source sources)
745 shinjigen shinjigen@1ed shinjigen@rev))
746 (setq required-features
747 (union required-features
759 =shinjigen/+p@rev))))
761 (setq required-features
762 (union required-features
767 ((find-charset (setq ret (intern (format "=%s" source))))
768 (setq required-features
769 (cons ret required-features)))
770 (t (setq required-features
771 (cons source required-features)))))
772 (cond ((string-match "@JP" (symbol-name name))
773 (setq required-features
774 (union required-features
782 ((string-match "@CN" (symbol-name name))
783 (setq required-features
784 (union required-features
791 (insert (format "%S" cell))
792 (char-db-insert-char-spec cell readable
795 (setq separator lbs))
799 (if (consp (car cell))
800 (char-db-insert-char-spec cell readable)
801 (char-db-insert-char-reference cell readable))
802 (setq separator lbs))
806 (insert (prin1-to-string cell))
807 (setq separator " ")))
808 (setq value (cdr value)))
810 (insert line-breaking)))
812 (defun insert-char-attributes (char &optional readable attributes column
815 (setq column (current-column)))
816 (let (name value ; has-long-ccs-name
820 (concat "\n" (make-string (1+ column) ?\ )))
821 lbs cell separator ret
823 dest-ccss ; sources required-features
828 (if (consp attributes)
830 (dolist (name attributes)
831 (unless (memq name char-db-ignored-attributes)
832 (if (find-charset name)
836 (dolist (name (char-attribute-list))
837 (unless (memq name char-db-ignored-attributes)
838 (if (find-charset name)
842 #'char-attribute-name<)))
844 (when (memq '<-subsumptive attributes)
845 (when (or readable (not for-sub-node))
846 (when (setq value (get-char-attribute char '<-subsumptive))
847 (char-db-insert-relation-feature char '<-subsumptive value
850 (setq attributes (delq '<-subsumptive attributes)))
851 (when (and (memq '<-denotational attributes)
852 (setq value (get-char-attribute char '<-denotational)))
853 (char-db-insert-relation-feature char '<-denotational value
856 (setq attributes (delq '<-denotational attributes)))
857 (when (and (memq 'name attributes)
858 (setq value (get-char-attribute char 'name)))
860 (if (> (+ (current-column) (length value)) 48)
863 value line-breaking))
864 (setq attributes (delq 'name attributes))
866 (when (and (memq 'name* attributes)
867 (setq value (get-char-attribute char 'name*)))
869 (if (> (+ (current-column) (length value)) 48)
872 value line-breaking))
873 (setq attributes (delq 'name* attributes))
875 (when (and (memq 'script attributes)
876 (setq value (get-char-attribute char 'script)))
877 (insert (format "(script\t\t%s)%s"
878 (mapconcat (function prin1-to-string)
881 (setq attributes (delq 'script attributes))
883 (dolist (name '(=>ucs =>ucs*))
884 (when (and (memq name attributes)
885 (setq value (get-char-attribute char name)))
886 (insert (format "(%-18s . #x%04X)\t; %c%s"
887 name value (decode-char '=ucs value)
889 (setq attributes (delq name attributes))))
890 (dolist (name '(=>ucs@gb =>ucs@big5))
891 (when (and (memq name attributes)
892 (setq value (get-char-attribute char name)))
893 (insert (format "(%-18s . #x%04X)\t; %c%s"
898 (symbol-name name) 2)))
901 (setq attributes (delq name attributes))
903 ;; (dolist (name '(=>daikanwa))
904 ;; (when (and (memq name attributes)
905 ;; (setq value (get-char-attribute char name)))
907 ;; (if (integerp value)
908 ;; (format "(%-18s . %05d)\t; %c%s"
909 ;; name value (decode-char '=daikanwa value)
911 ;; (format "(%-18s %s)\t; %c%s"
913 ;; (mapconcat (function prin1-to-string)
915 ;; (char-representative-of-daikanwa char)
917 ;; (setq attributes (delq name attributes))))
918 (when (and (memq 'general-category attributes)
919 (setq value (get-char-attribute char 'general-category)))
921 "(general-category\t%s) ; %s%s"
922 (mapconcat (lambda (cell)
925 (cond ((rassoc value unidata-normative-category-alist)
926 "Normative Category")
927 ((rassoc value unidata-informative-category-alist)
928 "Informative Category")
932 (setq attributes (delq 'general-category attributes))
934 (when (and (memq 'bidi-category attributes)
935 (setq value (get-char-attribute char 'bidi-category)))
936 (insert (format "(bidi-category\t. %S)%s"
939 (setq attributes (delq 'bidi-category attributes))
941 (unless (or (not (memq 'mirrored attributes))
942 (eq (setq value (get-char-attribute char 'mirrored 'empty))
944 (insert (format "(mirrored\t\t. %S)%s"
947 (setq attributes (delq 'mirrored attributes))
950 ((and (memq 'decimal-digit-value attributes)
951 (setq value (get-char-attribute char 'decimal-digit-value)))
952 (insert (format "(decimal-digit-value . %S)%s"
955 (setq attributes (delq 'decimal-digit-value attributes))
956 (when (and (memq 'digit-value attributes)
957 (setq value (get-char-attribute char 'digit-value)))
958 (insert (format "(digit-value\t . %S)%s"
961 (setq attributes (delq 'digit-value attributes))
963 (when (and (memq 'numeric-value attributes)
964 (setq value (get-char-attribute char 'numeric-value)))
965 (insert (format "(numeric-value\t . %S)%s"
968 (setq attributes (delq 'numeric-value attributes))
972 (when (and (memq 'digit-value attributes)
973 (setq value (get-char-attribute char 'digit-value)))
974 (insert (format "(digit-value\t. %S)%s"
977 (setq attributes (delq 'digit-value attributes))
979 (when (and (memq 'numeric-value attributes)
980 (setq value (get-char-attribute char 'numeric-value)))
981 (insert (format "(numeric-value\t. %S)%s"
984 (setq attributes (delq 'numeric-value attributes))
986 (when (and (memq 'iso-10646-comment attributes)
987 (setq value (get-char-attribute char 'iso-10646-comment)))
988 (insert (format "(iso-10646-comment\t. %S)%s"
991 (setq attributes (delq 'iso-10646-comment attributes))
993 (when (and (memq 'morohashi-daikanwa attributes)
994 (setq value (get-char-attribute char 'morohashi-daikanwa)))
995 (insert (format "(morohashi-daikanwa\t%s)%s"
996 (mapconcat (function prin1-to-string) value " ")
998 (setq attributes (delq 'morohashi-daikanwa attributes))
1002 (when (and (memq 'ideographic-radical attributes)
1003 (setq value (get-char-attribute char 'ideographic-radical)))
1004 (setq radical value)
1005 (insert (format "(ideographic-radical . %S)\t; %c%s"
1007 (ideographic-radical radical)
1009 (setq attributes (delq 'ideographic-radical attributes))
1011 (when (and (memq 'shuowen-radical attributes)
1012 (setq value (get-char-attribute char 'shuowen-radical)))
1013 (insert (format "(shuowen-radical\t. %S)\t; %c%s"
1015 (shuowen-radical value)
1017 (setq attributes (delq 'shuowen-radical attributes))
1022 char-db-feature-domains
1024 (dolist (feature (char-attribute-list))
1025 (setq feature (symbol-name feature))
1027 "\\(radical\\|strokes\\)@\\([^@*]+\\)\\(\\*\\|$\\)"
1029 (setq domain (intern (match-string 2 feature)))
1030 (unless (memq domain dest)
1031 (setq dest (cons domain dest)))))
1032 (sort dest #'string<))))
1033 (setq key (intern (format "%s@%s" 'ideographic-radical domain)))
1034 (when (and (memq key attributes)
1035 (setq value (get-char-attribute char key)))
1036 (setq radical value)
1037 (insert (format "(%s . %S)\t; %c%s"
1040 (ideographic-radical radical)
1042 (setq attributes (delq key attributes))
1044 (setq key (intern (format "%s@%s" 'ideographic-strokes domain)))
1045 (when (and (memq key attributes)
1046 (setq value (get-char-attribute char key)))
1047 (setq strokes value)
1048 (insert (format "(%s . %S)%s"
1052 (setq attributes (delq key attributes))
1054 (setq key (intern (format "%s@%s" 'total-strokes domain)))
1055 (when (and (memq key attributes)
1056 (setq value (get-char-attribute char key)))
1057 (insert (format "(%s . %S)%s"
1061 (setq attributes (delq key attributes))
1063 (dolist (feature '(ideographic-radical
1066 (setq key (intern (format "%s@%s*sources" feature domain)))
1067 (when (and (memq key attributes)
1068 (setq value (get-char-attribute char key)))
1069 (insert (format "(%s%s" key line-breaking))
1070 (dolist (cell value)
1071 (insert (format " %s" cell)))
1073 (insert line-breaking)
1074 (setq attributes (delq key attributes))
1077 (when (and (memq 'ideographic-strokes attributes)
1078 (setq value (get-char-attribute char 'ideographic-strokes)))
1079 (setq strokes value)
1080 (insert (format "(ideographic-strokes . %S)%s"
1083 (setq attributes (delq 'ideographic-strokes attributes))
1085 (when (and (memq 'kangxi-radical attributes)
1086 (setq value (get-char-attribute char 'kangxi-radical)))
1087 (unless (eq value radical)
1088 (insert (format "(kangxi-radical\t . %S)\t; %c%s"
1090 (ideographic-radical value)
1093 (setq radical value)))
1094 (setq attributes (delq 'kangxi-radical attributes))
1096 (when (and (memq 'kangxi-strokes attributes)
1097 (setq value (get-char-attribute char 'kangxi-strokes)))
1098 (unless (eq value strokes)
1099 (insert (format "(kangxi-strokes\t . %S)%s"
1103 (setq strokes value)))
1104 (setq attributes (delq 'kangxi-strokes attributes))
1106 (when (and (memq 'japanese-radical attributes)
1107 (setq value (get-char-attribute char 'japanese-radical)))
1108 (unless (eq value radical)
1109 (insert (format "(japanese-radical\t . %S)\t; %c%s"
1111 (ideographic-radical value)
1114 (setq radical value)))
1115 (setq attributes (delq 'japanese-radical attributes))
1117 (when (and (memq 'japanese-strokes attributes)
1118 (setq value (get-char-attribute char 'japanese-strokes)))
1119 (unless (eq value strokes)
1120 (insert (format "(japanese-strokes\t . %S)%s"
1124 (setq strokes value)))
1125 (setq attributes (delq 'japanese-strokes attributes))
1127 (when (and (memq 'cns-radical attributes)
1128 (setq value (get-char-attribute char 'cns-radical)))
1129 (insert (format "(cns-radical\t . %S)\t; %c%s"
1131 (ideographic-radical value)
1133 (setq attributes (delq 'cns-radical attributes))
1135 (when (and (memq 'cns-strokes attributes)
1136 (setq value (get-char-attribute char 'cns-strokes)))
1137 (unless (eq value strokes)
1138 (insert (format "(cns-strokes\t . %S)%s"
1142 (setq strokes value)))
1143 (setq attributes (delq 'cns-strokes attributes))
1145 ;; (when (and (memq 'shinjigen-1-radical attributes)
1146 ;; (setq value (get-char-attribute char 'shinjigen-1-radical)))
1147 ;; (unless (eq value radical)
1148 ;; (insert (format "(shinjigen-1-radical . %S)\t; %c%s"
1150 ;; (ideographic-radical value)
1153 ;; (setq radical value)))
1154 ;; (setq attributes (delq 'shinjigen-1-radical attributes))
1156 (when (and (memq 'ideographic- attributes)
1157 (setq value (get-char-attribute char 'ideographic-)))
1158 (insert "(ideographic- ")
1159 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1161 (while (consp value)
1162 (setq cell (car value))
1164 (setq cell (decode-char '=ucs cell)))
1165 (cond ((characterp cell)
1169 (insert (format "%S" cell))
1170 (char-db-insert-char-spec cell readable))
1171 (setq separator lbs))
1175 (if (consp (car cell))
1176 (char-db-insert-char-spec cell readable)
1177 (char-db-insert-char-reference cell readable))
1178 (setq separator lbs))
1182 (insert (prin1-to-string cell))
1183 (setq separator " ")))
1184 (setq value (cdr value)))
1186 (insert line-breaking)
1187 (setq attributes (delq 'ideographic- attributes)))
1188 (when (and (memq 'total-strokes attributes)
1189 (setq value (get-char-attribute char 'total-strokes)))
1190 (insert (format "(total-strokes . %S)%s"
1193 (setq attributes (delq 'total-strokes attributes))
1195 (when (and (memq '->ideograph attributes)
1196 (setq value (get-char-attribute char '->ideograph)))
1197 (insert (format "(->ideograph\t%s)%s"
1198 (mapconcat (lambda (code)
1199 (cond ((symbolp code)
1202 (format "#x%04X" code))
1205 line-breaking code))))
1208 (setq attributes (delq '->ideograph attributes))
1210 ;; (when (and (memq '->decomposition attributes)
1211 ;; (setq value (get-char-attribute char '->decomposition)))
1212 ;; (insert (format "(->decomposition\t%s)%s"
1213 ;; (mapconcat (lambda (code)
1214 ;; (cond ((symbolp code)
1215 ;; (symbol-name code))
1216 ;; ((characterp code)
1218 ;; (format "%S" code)
1223 ;; (format "#x%04X" code))
1225 ;; (format "%s%S" line-breaking code))))
1228 ;; (setq attributes (delq '->decomposition attributes))
1230 (if (equal (get-char-attribute char '->titlecase)
1231 (get-char-attribute char '->uppercase))
1232 (setq attributes (delq '->titlecase attributes)))
1233 (when (and (memq '->mojikyo attributes)
1234 (setq value (get-char-attribute char '->mojikyo)))
1235 (insert (format "(->mojikyo\t\t. %06d)\t; %c%s"
1236 value (decode-char 'mojikyo value)
1238 (setq attributes (delq '->mojikyo attributes))
1240 (when (and (memq 'hanyu-dazidian-vol attributes)
1241 (setq value (get-char-attribute char 'hanyu-dazidian-vol)))
1242 (insert (format "(hanyu-dazidian-vol . %d)%s"
1243 value line-breaking))
1244 (setq attributes (delq 'hanyu-dazidian-vol attributes))
1246 (when (and (memq 'hanyu-dazidian-page attributes)
1247 (setq value (get-char-attribute char 'hanyu-dazidian-page)))
1248 (insert (format "(hanyu-dazidian-page . %d)%s"
1249 value line-breaking))
1250 (setq attributes (delq 'hanyu-dazidian-page attributes))
1252 (when (and (memq 'hanyu-dazidian-char attributes)
1253 (setq value (get-char-attribute char 'hanyu-dazidian-char)))
1254 (insert (format "(hanyu-dazidian-char . %d)%s"
1255 value line-breaking))
1256 (setq attributes (delq 'hanyu-dazidian-char attributes))
1259 (dolist (ignored '(composition
1260 ->denotational <-subsumptive ->ucs-unified
1261 ->ideographic-component-forms))
1262 (setq attributes (delq ignored attributes))))
1264 (setq name (car attributes))
1265 (unless (eq (setq value (get-char-attribute char name 'value-is-empty))
1267 (cond ((setq ret (find-charset name))
1268 (setq name (charset-name ret))
1269 (when (not (memq name dest-ccss))
1270 (setq dest-ccss (cons name dest-ccss))
1271 (char-db-insert-ccs-feature name value line-breaking))
1273 ((string-match "^=>ucs@" (symbol-name name))
1274 (insert (format "(%-18s . #x%04X)\t; %c%s"
1275 name value (decode-char '=ucs value)
1278 ((eq name 'jisx0208-1978/4X)
1279 (insert (format "(%-18s . #x%04X)%s"
1285 (not (eq name '->subsumptive))
1286 (not (eq name '->uppercase))
1287 (not (eq name '->lowercase))
1288 (not (eq name '->titlecase))
1289 (not (eq name '->canonical))
1290 (not (eq name '->Bopomofo))
1291 (not (eq name '->mistakable))
1292 (not (eq name '->ideographic-variants))
1293 (null (get-char-attribute
1294 char (intern (format "%s*sources" name))))
1295 (not (string-match "\\*sources$" (symbol-name name)))
1296 (null (get-char-attribute
1297 char (intern (format "%s*note" name))))
1298 (not (string-match "\\*note$" (symbol-name name)))
1299 (or (eq name '<-identical)
1300 (eq name '<-uppercase)
1301 (eq name '<-lowercase)
1302 (eq name '<-titlecase)
1303 (eq name '<-canonical)
1304 (eq name '<-ideographic-variants)
1305 ;; (eq name '<-synonyms)
1306 (string-match "^<-synonyms" (symbol-name name))
1307 (eq name '<-mistakable)
1308 (when (string-match "^->" (symbol-name name))
1310 ((string-match "^->fullwidth" (symbol-name name))
1311 (not (and (consp value)
1312 (characterp (car value))
1314 (car value) '=ucs 'defined-only)))
1319 ((or (eq name 'ideographic-structure)
1320 (eq name 'ideographic-combination)
1321 (eq name 'ideographic-)
1322 (eq name '=decomposition)
1323 (char-feature-base-name= '=decomposition name)
1324 (char-feature-base-name= '=>decomposition name)
1325 ;; (string-match "^=>*decomposition\\(@[^*]+\\)?$"
1326 ;; (symbol-name name))
1327 (string-match "^\\(->\\|<-\\)[^*]*$" (symbol-name name))
1328 (string-match "^\\(->\\|<-\\)[^*]*\\*sources$"
1331 (char-db-insert-relation-feature char name value
1334 ((memq name '(ideograph=
1335 original-ideograph-of
1336 ancient-ideograph-of
1339 ;; simplified-ideograph-of
1340 ideographic-variants
1341 ;; ideographic-different-form-of
1343 (insert (format "(%-18s%s " name line-breaking))
1344 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1346 (while (consp value)
1347 (setq cell (car value))
1348 (if (and (consp cell)
1353 (char-db-insert-alist cell readable)
1354 (setq separator lbs))
1357 (insert (prin1-to-string cell))
1358 (setq separator " "))
1359 (setq value (cdr value)))
1361 (insert line-breaking))
1363 (insert (format "(%-18s " name))
1364 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1366 (while (consp value)
1367 (setq cell (car value))
1368 (if (and (consp cell)
1370 (setq ret (condition-case nil
1378 (setq key (car (car rest)))
1379 (if (find-charset key)
1380 (setq cal (cons key cal))
1381 (setq al (cons key al)))
1382 (setq rest (cdr rest)))
1385 (insert-char-attributes ret
1389 (setq separator lbs))
1390 (setq ret (prin1-to-string cell))
1392 (if (< (+ (current-column)
1399 (setq separator " "))
1400 (setq value (cdr value)))
1402 (insert line-breaking))
1404 (insert (format "(%-18s" name))
1405 (setq ret (prin1-to-string value))
1406 (unless (< (+ (current-column)
1410 (insert line-breaking))
1411 (insert " . " ret ")" line-breaking)
1412 ;; (insert (format "(%-18s . %S)%s"
1417 (setq attributes (cdr attributes)))
1420 (defun insert-char-data (char &optional readable
1423 (narrow-to-region (point)(point))
1424 (insert "(define-char
1426 (insert-char-attributes char readable attributes)
1428 (goto-char (point-min))
1429 (while (re-search-forward "[ \t]+$" nil t)
1432 (goto-char (point-min))
1433 (while (re-search-forward "[ \t][ \t][ \t]*" nil t)
1434 (let ((column (current-column))
1435 (indent-tabs-mode t))
1436 (delete-region (match-beginning 0) (point))
1437 (indent-to column)))
1438 (goto-char (point-max))
1439 ;; (tabify (point-min)(point-max))
1442 (defun insert-char-data-with-variant (char &optional printable
1444 script excluded-script)
1445 (insert-char-data char printable)
1446 (let ((variants (char-variants char))
1449 (setq variants (sort variants #'<))
1450 (setq rest variants)
1451 (setq variants (cons char variants))
1453 (setq variant (car rest))
1454 (unless (get-char-attribute variant '<-subsumptive)
1455 (if (and (or (null script)
1456 (null (setq vs (get-char-attribute variant 'script)))
1458 (or (null excluded-script)
1459 (null (setq vs (get-char-attribute variant 'script)))
1460 (not (memq excluded-script vs))))
1461 (unless (and no-ucs-unified (get-char-attribute variant '=ucs))
1462 (insert-char-data variant printable)
1463 (if (setq ret (char-variants variant))
1465 (or (memq (car ret) variants)
1466 ;; (get-char-attribute (car ret) '<-subsumptive)
1467 (setq rest (nconc rest (list (car ret)))))
1468 (setq ret (cdr ret)))))))
1469 (setq rest (cdr rest)))))
1471 (defun insert-char-range-data (min max &optional script excluded-script)
1474 (while (<= code max)
1475 (setq char (decode-char '=ucs code))
1476 (if (encode-char char '=ucs 'defined-only)
1477 (insert-char-data-with-variant char nil 'no-ucs-unified
1478 script excluded-script))
1479 (setq code (1+ code)))))
1481 (defun write-char-range-data-to-file (min max file
1482 &optional script excluded-script)
1483 (let ((coding-system-for-write char-db-file-coding-system))
1485 (insert (format ";; -*- coding: %s -*-\n"
1486 char-db-file-coding-system))
1487 (insert-char-range-data min max script excluded-script)
1488 (write-region (point-min)(point-max) file))))
1490 (defvar what-character-original-window-configuration)
1493 (defun what-char-definition (char)
1494 (interactive (list (char-after)))
1495 (let ((buf (get-buffer-create "*Character Description*"))
1496 (the-buf (current-buffer))
1497 (win-conf (current-window-configuration)))
1499 (make-local-variable 'what-character-original-window-configuration)
1500 (setq what-character-original-window-configuration win-conf)
1501 (setq buffer-read-only nil)
1505 (insert-char-data-with-variant char 'printable)
1506 (unless (char-attribute-alist char)
1507 (insert (format ";; = %c\n"
1508 (let* ((rest (split-char char))
1512 (setq code (logior (lsh code 8)
1514 (decode-char ccs code)))))
1515 ;; (char-db-update-comment)
1516 (set-buffer-modified-p nil)
1517 (view-mode the-buf (lambda (buf)
1518 (set-window-configuration
1519 what-character-original-window-configuration)
1521 (goto-char (point-min)))
1523 (set-window-configuration
1524 what-character-original-window-configuration)
1525 (signal (car err) (cdr err)))))))
1531 (provide 'char-db-util)
1533 ;;; char-db-util.el ends here