1 ;;; char-db-util.el --- Character Database utility -*- coding: utf-8-er; -*-
3 ;; Copyright (C) 1998,1999,2000,2001,2002,2003,2004,2005,2006,2007,
4 ;; 2008,2009,2010,2011,2012,2013,2014,2015 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
106 ?熊 ?火 ?炎 ?黑 ?囪 ?焱 ?炙 ?赤 ?大 ?亦 ; 390
109 (defun shuowen-radical (number)
110 (aref shuowen-radicals (1- number)))
112 (defvar char-db-file-coding-system 'utf-8-mcs-er)
114 (defvar char-db-ignored-attributes '(ideographic-products))
116 (defvar char-db-coded-charset-priority-list
209 ;; =>>>adobe-japan1-0
210 ;; =>>>adobe-japan1-1
211 ;; =>>>adobe-japan1-2
212 ;; =>>>adobe-japan1-3
213 ;; =>>>adobe-japan1-4
214 ;; =>>>adobe-japan1-5
215 ;; =>>>adobe-japan1-6
219 ;; =>>>hanyo-denshi/ja
220 ;; =>>>hanyo-denshi/jb
221 ;; =>>>hanyo-denshi/jc
222 ;; =>>>hanyo-denshi/ft
223 ;; =>>>hanyo-denshi/ib
224 ;; =>>>hanyo-denshi/hg
225 ;; =>>>hanyo-denshi/jt
226 ;; =>>>hanyo-denshi/ks
329 ;;; @ char-db formatters
332 (defun char-db-make-char-spec (char)
334 (cond ((characterp char)
335 (cond ((and (setq ret (encode-char char '=ucs 'defined-only))
336 (not (and (<= #xE000 ret)(<= ret #xF8FF))))
337 (setq char-spec (list (cons '=ucs ret)))
338 (cond ((setq ret (get-char-attribute char 'name))
339 (setq char-spec (cons (cons 'name ret) char-spec))
341 ((setq ret (get-char-attribute char 'name*))
342 (setq char-spec (cons (cons 'name* ret) char-spec))
345 ((encode-char char '=mj 'defined-only)
347 (dolist (ccs (charset-list))
348 (if (and (or (eq ccs '=mj)
349 ;; (eq (charset-property ccs 'iso-ir) 177)
350 (string-match "=ucs@" (symbol-name ccs))
352 (setq ccs (charset-name ccs))
353 (null (assq ccs char-spec))
354 (setq ret (encode-char char ccs 'defined-only)))
355 (setq char-spec (cons (cons ccs ret) char-spec))))
357 ((encode-char char '==mj 'defined-only)
359 (dolist (ccs (charset-list))
360 (if (and (or (eq ccs '==mj)
361 ;; (eq (charset-property ccs 'iso-ir) 177)
362 (string-match "=ucs@" (symbol-name ccs))
364 (setq ccs (charset-name ccs))
365 (null (assq ccs char-spec))
366 (setq ret (encode-char char ccs 'defined-only)))
367 (setq char-spec (cons (cons ccs ret) char-spec))))
369 ((encode-char char '=adobe-japan1 'defined-only)
371 (dolist (ccs (charset-list))
372 (if (and (or (memq ccs
381 ;; (eq (charset-property ccs 'iso-ir) 177)
382 (string-match "=ucs@" (symbol-name ccs))
384 (setq ccs (charset-name ccs))
385 (null (assq ccs char-spec))
386 (setq ret (encode-char char ccs 'defined-only)))
387 (setq char-spec (cons (cons ccs ret) char-spec))))
389 ((encode-char char '==adobe-japan1 'defined-only)
391 (dolist (ccs (charset-list))
392 (if (and (or (memq ccs
401 ;; (eq (charset-property ccs 'iso-ir) 177)
402 (string-match "=ucs@" (symbol-name ccs))
404 (setq ccs (charset-name ccs))
405 (null (assq ccs char-spec))
406 (setq ret (encode-char char ccs 'defined-only)))
407 (setq char-spec (cons (cons ccs ret) char-spec))))
411 (let ((rest char-db-coded-charset-priority-list)
414 (setq ccs (charset-name
415 (find-charset (car rest))))
417 (encode-char char ccs
419 (throw 'tag (cons ccs ret)))
420 (setq rest (cdr rest))))))
421 (setq char-spec (list ret))
422 (dolist (ccs (delq (car ret) (charset-list)))
423 (if (and (or (charset-iso-final-char ccs)
430 (eq (charset-property ccs 'iso-ir) 177)
431 ;; (string-match "=ucs@" (symbol-name ccs))
433 (setq ccs (charset-name ccs))
434 (null (assq ccs char-spec))
435 (setq ret (encode-char char ccs 'defined-only)))
436 (setq char-spec (cons (cons ccs ret) char-spec))))
438 (setq char-spec (split-char char)))
439 (cond ((setq ret (get-char-attribute char 'name))
440 (setq char-spec (cons (cons 'name ret) char-spec))
442 ((setq ret (get-char-attribute char 'name*))
443 (setq char-spec (cons (cons 'name* ret) char-spec))
446 ((setq ret (get-char-attribute
447 char 'ideographic-combination))
449 (cons (cons 'ideographic-combination ret)
456 (defun char-db-insert-char-spec (char &optional readable column
459 (setq column (current-column)))
460 (let (char-spec temp-char)
461 (setq char-spec (char-db-make-char-spec char))
462 (unless (or (characterp char) ; char
464 (setq char (find-char char-spec))
466 ;; define temporary character
467 ;; Current implementation is dirty.
468 (setq temp-char (define-char (cons '(ideograph-daikanwa . 0)
470 (remove-char-attribute temp-char 'ideograph-daikanwa)
471 (setq char temp-char))
472 (insert-char-attributes char
474 (union (mapcar #'car char-spec)
478 ;; undefine temporary character
479 ;; Current implementation is dirty.
480 (setq char-spec (char-attribute-alist temp-char))
482 (remove-char-attribute temp-char (car (car char-spec)))
483 (setq char-spec (cdr char-spec))))))
485 (defun char-db-insert-alist (alist &optional readable column)
487 (setq column (current-column)))
489 (concat "\n" (make-string (1+ column) ?\ )))
493 lbs cell rest separator)
496 (setq name (car (car alist))
497 value (cdr (car alist)))
498 (cond ((eq name 'char)
500 (if (setq ret (condition-case nil
508 (setq key (car (car value)))
509 ;; (if (find-charset key)
510 ;; (setq cal (cons key cal))
511 (setq al (cons key al))
513 (setq value (cdr value)))
514 (insert-char-attributes ret
518 (insert (prin1-to-string value)))
520 (insert line-breaking))
522 (insert (format "(%-18s " name))
523 (setq lbs (concat "\n" (make-string (current-column) ?\ )))
525 (setq cell (car value))
526 (if (and (consp cell)
528 (setq ret (condition-case nil
538 (setq key (car (car rest)))
539 ;; (if (find-charset key)
540 ;; (setq cal (cons key cal))
541 (setq al (cons key al))
543 (setq rest (cdr rest)))
546 (insert-char-attributes ret
550 (setq separator lbs))
553 (insert (prin1-to-string cell))
554 (setq separator " "))
555 (setq value (cdr value)))
557 (insert line-breaking))
559 (insert (format "(%-18s . %S)%s"
562 (setq alist (cdr alist))))
565 (defun char-db-insert-char-reference (plist &optional readable column)
567 (setq column (current-column)))
569 (concat "\n" (make-string (1+ column) ?\ )))
574 (setq name (pop plist))
575 (setq value (pop plist))
576 (cond ((eq name :char)
579 (cond ((numberp value)
580 (setq value (decode-char '=ucs value)))
582 ;; (setq value (or (find-char value)
585 (char-db-insert-char-spec value readable)
586 (insert line-breaking)
589 (insert (format "%s%s\t%d ; %c%s"
592 (ideographic-radical value)
596 (insert (format "%s%s\t%S" separator name value))
597 (setq separator line-breaking)))
601 (defun char-db-decode-isolated-char (ccs code-point)
604 (cond ((eq ccs 'arabic-iso8859-6)
605 (decode-char ccs code-point))
607 ;; (decode-builtin-char '==gt code-point))
608 ((and (memq ccs '(=gt-pj-1
619 (setq ret (decode-char ccs code-point))
620 (setq ret (encode-char ret '=gt 'defined-only)))
621 (decode-builtin-char '=gt ret))
623 (decode-builtin-char ccs code-point))))
625 (or (decode-char ccs code-point)
626 (define-char (list (cons ccs code-point)))))
627 ((and (<= 0 (char-int ret))
628 (<= (char-int ret) #x1F))
629 (decode-char '=ucs (+ #x2400 (char-int ret))))
630 ((= (char-int ret) #x7F)
634 (defvar char-db-convert-obsolete-format t)
636 (defun char-db-insert-ccs-feature (name value line-breaking)
642 ((memq name '(=>iwds-1
645 =shinjigen@1ed ==shinjigen@1ed
646 =shinjigen@rev ==shinjigen@rev
647 =shinjigen/+p@rev ==shinjigen/+p@rev
648 ===daikanwa/ho ==daikanwa/ho
649 =daikanwa/ho =>>daikanwa/ho =>daikanwa/ho))
650 "(%-18s . %04d)\t; %c")
651 ((eq name '=shinjigen@1ed/24pr)
652 "(%-18s . %04d)\t; %c")
653 ((or (memq name '(===daikanwa
654 ==daikanwa =daikanwa =>>daikanwa =>daikanwa
655 =daikanwa@rev1 =daikanwa@rev2
656 =daikanwa/+p ==daikanwa/+p ===daikanwa/+p
658 =daikanwa/+2p =>>daikanwa/+2p
663 =adobe-japan1-0 ==adobe-japan1-0 ===adobe-japan1-0
664 =adobe-japan1-1 ==adobe-japan1-1 ===adobe-japan1-1
665 =adobe-japan1-2 ==adobe-japan1-2 ===adobe-japan1-2
666 =adobe-japan1-3 ==adobe-japan1-3 ===adobe-japan1-3
667 =adobe-japan1-4 ==adobe-japan1-4 ===adobe-japan1-4
668 =adobe-japan1-5 ==adobe-japan1-5 ===adobe-japan1-5
669 =adobe-japan1-6 ==adobe-japan1-6 ===adobe-japan1-6
670 =>>adobe-japan1-0 =+>adobe-japan1-0
671 =>>adobe-japan1-1 =+>adobe-japan1-1
672 =>>adobe-japan1-2 =+>adobe-japan1-2
673 =>>adobe-japan1-3 =+>adobe-japan1-3
674 =>>adobe-japan1-4 =+>adobe-japan1-4
675 =>>adobe-japan1-5 =+>adobe-japan1-5
676 =>>adobe-japan1-6 =+>adobe-japan1-6
677 =>cbeta =cbeta =>>cbeta ==cbeta ===cbeta
678 =zinbun-oracle =>zinbun-oracle))
679 ;; (string-match "^=adobe-" (symbol-name name))
681 "(%-18s . %05d)\t; %c")
682 ((memq name '(=hanyo-denshi/ks
683 ==hanyo-denshi/ks ===hanyo-denshi/ks
688 "(%-18s . %06d)\t; %c")
689 ((>= (charset-dimension name) 2)
690 "(%-18s . #x%04X)\t; %c")
692 "(%-18s . #x%02X)\t; %c"))
694 (if (= (charset-iso-graphic-plane name) 1)
696 (cond ((= (charset-dimension name) 1)
698 ((= (charset-dimension name) 2)
700 ((= (charset-dimension name) 3)
704 (char-db-decode-isolated-char name value)))
705 (if (and (= (charset-chars name) 94)
706 (= (charset-dimension name) 2))
707 (insert (format " [%02d-%02d]"
708 (- (lsh value -8) 32)
709 (- (logand value 255) 32))))
712 (insert (format "(%-18s . %s)" name value))
714 (insert line-breaking))
716 (defun char-db-insert-relation-feature (char name value line-breaking
718 (insert (format "(%-18s%s " name line-breaking))
719 (let ((lbs (concat "\n" (make-string (current-column) ?\ )))
720 separator cell sources required-features
723 (setq cell (car value))
725 (setq cell (decode-char '=ucs cell)))
727 ((eq name '->subsumptive)
728 (when (or (not (some (lambda (atr)
729 (get-char-attribute cell atr))
730 char-db-ignored-attributes))
732 (encode-char cell ccs 'defined-only))
736 (let ((char-db-ignored-attributes
738 char-db-ignored-attributes)))
739 (insert-char-attributes cell readable nil nil 'for-sub-node))
740 (setq separator lbs))
745 char (intern (format "%s*sources" name))))
746 (setq required-features nil)
747 (dolist (source sources)
751 shinjigen shinjigen@1ed shinjigen@rev))
752 (setq required-features
753 (union required-features
765 =shinjigen/+p@rev))))
767 (setq required-features
768 (union required-features
773 ((find-charset (setq ret (intern (format "=%s" source))))
774 (setq required-features
775 (cons ret required-features)))
776 (t (setq required-features
777 (cons source required-features)))))
778 (cond ((string-match "@JP" (symbol-name name))
779 (setq required-features
780 (union required-features
788 ((string-match "@CN" (symbol-name name))
789 (setq required-features
790 (union required-features
797 (insert (format "%S" cell))
798 (char-db-insert-char-spec cell readable
801 (setq separator lbs))
805 (if (consp (car cell))
806 (char-db-insert-char-spec cell readable)
807 (char-db-insert-char-reference cell readable))
808 (setq separator lbs))
812 (insert (prin1-to-string cell))
813 (setq separator " ")))
814 (setq value (cdr value)))
816 (insert line-breaking)))
818 (defun insert-char-attributes (char &optional readable attributes column
821 (setq column (current-column)))
822 (let (name value ; has-long-ccs-name
826 (concat "\n" (make-string (1+ column) ?\ )))
827 lbs cell separator ret
829 dest-ccss ; sources required-features
834 (if (consp attributes)
836 (dolist (name attributes)
837 (unless (memq name char-db-ignored-attributes)
838 (if (find-charset name)
842 (dolist (name (char-attribute-list))
843 (unless (memq name char-db-ignored-attributes)
844 (if (find-charset name)
848 #'char-attribute-name<)))
850 (when (memq '<-subsumptive attributes)
851 (when (or readable (not for-sub-node))
852 (when (setq value (get-char-attribute char '<-subsumptive))
853 (char-db-insert-relation-feature char '<-subsumptive value
856 (setq attributes (delq '<-subsumptive attributes)))
857 (when (and (memq '<-denotational attributes)
858 (setq value (get-char-attribute char '<-denotational)))
859 (char-db-insert-relation-feature char '<-denotational value
862 (setq attributes (delq '<-denotational attributes)))
863 (when (and (memq '<-denotational@component attributes)
864 (setq value (get-char-attribute char '<-denotational@component)))
865 (char-db-insert-relation-feature char '<-denotational@component value
868 (setq attributes (delq '<-denotational@component attributes)))
869 (when (and (memq 'name attributes)
870 (setq value (get-char-attribute char 'name)))
872 (if (> (+ (current-column) (length value)) 48)
875 value line-breaking))
876 (setq attributes (delq 'name attributes))
878 (when (and (memq 'name* attributes)
879 (setq value (get-char-attribute char 'name*)))
881 (if (> (+ (current-column) (length value)) 48)
884 value line-breaking))
885 (setq attributes (delq 'name* attributes))
887 (when (and (memq 'script attributes)
888 (setq value (get-char-attribute char 'script)))
889 (insert (format "(script\t\t%s)%s"
890 (mapconcat (function prin1-to-string)
893 (setq attributes (delq 'script attributes))
895 (dolist (name '(=>ucs =>ucs*))
896 (when (and (memq name attributes)
897 (setq value (get-char-attribute char name)))
898 (insert (format "(%-18s . #x%04X)\t; %c%s"
899 name value (decode-char '=ucs value)
901 (setq attributes (delq name attributes))))
902 (dolist (name '(=>ucs@gb =>ucs@big5))
903 (when (and (memq name attributes)
904 (setq value (get-char-attribute char name)))
905 (insert (format "(%-18s . #x%04X)\t; %c%s"
910 (symbol-name name) 2)))
913 (setq attributes (delq name attributes))
915 ;; (dolist (name '(=>daikanwa))
916 ;; (when (and (memq name attributes)
917 ;; (setq value (get-char-attribute char name)))
919 ;; (if (integerp value)
920 ;; (format "(%-18s . %05d)\t; %c%s"
921 ;; name value (decode-char '=daikanwa value)
923 ;; (format "(%-18s %s)\t; %c%s"
925 ;; (mapconcat (function prin1-to-string)
927 ;; (char-representative-of-daikanwa char)
929 ;; (setq attributes (delq name attributes))))
930 (when (and (memq 'general-category attributes)
931 (setq value (get-char-attribute char 'general-category)))
933 "(general-category\t%s) ; %s%s"
934 (mapconcat (lambda (cell)
937 (cond ((rassoc value unidata-normative-category-alist)
938 "Normative Category")
939 ((rassoc value unidata-informative-category-alist)
940 "Informative Category")
944 (setq attributes (delq 'general-category attributes))
946 (when (and (memq 'bidi-category attributes)
947 (setq value (get-char-attribute char 'bidi-category)))
948 (insert (format "(bidi-category\t. %S)%s"
951 (setq attributes (delq 'bidi-category attributes))
953 (unless (or (not (memq 'mirrored attributes))
954 (eq (setq value (get-char-attribute char 'mirrored 'empty))
956 (insert (format "(mirrored\t\t. %S)%s"
959 (setq attributes (delq 'mirrored attributes))
962 ((and (memq 'decimal-digit-value attributes)
963 (setq value (get-char-attribute char 'decimal-digit-value)))
964 (insert (format "(decimal-digit-value . %S)%s"
967 (setq attributes (delq 'decimal-digit-value attributes))
968 (when (and (memq 'digit-value attributes)
969 (setq value (get-char-attribute char 'digit-value)))
970 (insert (format "(digit-value\t . %S)%s"
973 (setq attributes (delq 'digit-value attributes))
975 (when (and (memq 'numeric-value attributes)
976 (setq value (get-char-attribute char 'numeric-value)))
977 (insert (format "(numeric-value\t . %S)%s"
980 (setq attributes (delq 'numeric-value attributes))
984 (when (and (memq 'digit-value attributes)
985 (setq value (get-char-attribute char 'digit-value)))
986 (insert (format "(digit-value\t. %S)%s"
989 (setq attributes (delq 'digit-value attributes))
991 (when (and (memq 'numeric-value attributes)
992 (setq value (get-char-attribute char 'numeric-value)))
993 (insert (format "(numeric-value\t. %S)%s"
996 (setq attributes (delq 'numeric-value attributes))
998 (when (and (memq 'iso-10646-comment attributes)
999 (setq value (get-char-attribute char 'iso-10646-comment)))
1000 (insert (format "(iso-10646-comment\t. %S)%s"
1003 (setq attributes (delq 'iso-10646-comment attributes))
1005 (when (and (memq 'morohashi-daikanwa attributes)
1006 (setq value (get-char-attribute char 'morohashi-daikanwa)))
1007 (insert (format "(morohashi-daikanwa\t%s)%s"
1008 (mapconcat (function prin1-to-string) value " ")
1010 (setq attributes (delq 'morohashi-daikanwa attributes))
1014 (when (and (memq 'ideographic-radical attributes)
1015 (setq value (get-char-attribute char 'ideographic-radical)))
1016 (setq radical value)
1017 (insert (format "(ideographic-radical . %S)\t; %c%s"
1019 (ideographic-radical radical)
1021 (setq attributes (delq 'ideographic-radical attributes))
1023 (when (and (memq 'shuowen-radical attributes)
1024 (setq value (get-char-attribute char 'shuowen-radical)))
1025 (insert (format "(shuowen-radical\t. %S)\t; %c%s"
1027 (shuowen-radical value)
1029 (setq attributes (delq 'shuowen-radical attributes))
1034 char-db-feature-domains
1036 (dolist (feature (char-attribute-list))
1037 (setq feature (symbol-name feature))
1039 "\\(radical\\|strokes\\)@\\([^@*]+\\)\\(\\*\\|$\\)"
1041 (setq domain (intern (match-string 2 feature)))
1042 (unless (memq domain dest)
1043 (setq dest (cons domain dest)))))
1044 (sort dest #'string<))))
1045 (setq key (intern (format "%s@%s" 'ideographic-radical domain)))
1046 (when (and (memq key attributes)
1047 (setq value (get-char-attribute char key)))
1048 (setq radical value)
1049 (insert (format "(%s . %S)\t; %c%s"
1052 (ideographic-radical radical)
1054 (setq attributes (delq key attributes))
1056 (setq key (intern (format "%s@%s" 'ideographic-strokes domain)))
1057 (when (and (memq key attributes)
1058 (setq value (get-char-attribute char key)))
1059 (setq strokes value)
1060 (insert (format "(%s . %S)%s"
1064 (setq attributes (delq key attributes))
1066 (setq key (intern (format "%s@%s" 'total-strokes domain)))
1067 (when (and (memq key attributes)
1068 (setq value (get-char-attribute char key)))
1069 (insert (format "(%s . %S)%s"
1073 (setq attributes (delq key attributes))
1075 (dolist (feature '(ideographic-radical
1078 (setq key (intern (format "%s@%s*sources" feature domain)))
1079 (when (and (memq key attributes)
1080 (setq value (get-char-attribute char key)))
1081 (insert (format "(%s%s" key line-breaking))
1082 (dolist (cell value)
1083 (insert (format " %s" cell)))
1085 (insert line-breaking)
1086 (setq attributes (delq key attributes))
1089 (when (and (memq 'ideographic-strokes attributes)
1090 (setq value (get-char-attribute char 'ideographic-strokes)))
1091 (setq strokes value)
1092 (insert (format "(ideographic-strokes . %S)%s"
1095 (setq attributes (delq 'ideographic-strokes attributes))
1097 (when (and (memq 'kangxi-radical attributes)
1098 (setq value (get-char-attribute char 'kangxi-radical)))
1099 (unless (eq value radical)
1100 (insert (format "(kangxi-radical\t . %S)\t; %c%s"
1102 (ideographic-radical value)
1105 (setq radical value)))
1106 (setq attributes (delq 'kangxi-radical attributes))
1108 (when (and (memq 'kangxi-strokes attributes)
1109 (setq value (get-char-attribute char 'kangxi-strokes)))
1110 (unless (eq value strokes)
1111 (insert (format "(kangxi-strokes\t . %S)%s"
1115 (setq strokes value)))
1116 (setq attributes (delq 'kangxi-strokes attributes))
1118 (when (and (memq 'japanese-radical attributes)
1119 (setq value (get-char-attribute char 'japanese-radical)))
1120 (unless (eq value radical)
1121 (insert (format "(japanese-radical\t . %S)\t; %c%s"
1123 (ideographic-radical value)
1126 (setq radical value)))
1127 (setq attributes (delq 'japanese-radical attributes))
1129 (when (and (memq 'japanese-strokes attributes)
1130 (setq value (get-char-attribute char 'japanese-strokes)))
1131 (unless (eq value strokes)
1132 (insert (format "(japanese-strokes\t . %S)%s"
1136 (setq strokes value)))
1137 (setq attributes (delq 'japanese-strokes attributes))
1139 (when (and (memq 'cns-radical attributes)
1140 (setq value (get-char-attribute char 'cns-radical)))
1141 (insert (format "(cns-radical\t . %S)\t; %c%s"
1143 (ideographic-radical value)
1145 (setq attributes (delq 'cns-radical attributes))
1147 (when (and (memq 'cns-strokes attributes)
1148 (setq value (get-char-attribute char 'cns-strokes)))
1149 (unless (eq value strokes)
1150 (insert (format "(cns-strokes\t . %S)%s"
1154 (setq strokes value)))
1155 (setq attributes (delq 'cns-strokes attributes))
1157 ;; (when (and (memq 'shinjigen-1-radical attributes)
1158 ;; (setq value (get-char-attribute char 'shinjigen-1-radical)))
1159 ;; (unless (eq value radical)
1160 ;; (insert (format "(shinjigen-1-radical . %S)\t; %c%s"
1162 ;; (ideographic-radical value)
1165 ;; (setq radical value)))
1166 ;; (setq attributes (delq 'shinjigen-1-radical attributes))
1168 (when (and (memq 'ideographic- attributes)
1169 (setq value (get-char-attribute char 'ideographic-)))
1170 (insert "(ideographic- ")
1171 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1173 (while (consp value)
1174 (setq cell (car value))
1176 (setq cell (decode-char '=ucs cell)))
1177 (cond ((characterp cell)
1181 (insert (format "%S" cell))
1182 (char-db-insert-char-spec cell readable))
1183 (setq separator lbs))
1187 (if (consp (car cell))
1188 (char-db-insert-char-spec cell readable)
1189 (char-db-insert-char-reference cell readable))
1190 (setq separator lbs))
1194 (insert (prin1-to-string cell))
1195 (setq separator " ")))
1196 (setq value (cdr value)))
1198 (insert line-breaking)
1199 (setq attributes (delq 'ideographic- attributes)))
1200 (when (and (memq 'total-strokes attributes)
1201 (setq value (get-char-attribute char 'total-strokes)))
1202 (insert (format "(total-strokes . %S)%s"
1205 (setq attributes (delq 'total-strokes attributes))
1207 (when (and (memq '->ideograph attributes)
1208 (setq value (get-char-attribute char '->ideograph)))
1209 (insert (format "(->ideograph\t%s)%s"
1210 (mapconcat (lambda (code)
1211 (cond ((symbolp code)
1214 (format "#x%04X" code))
1217 line-breaking code))))
1220 (setq attributes (delq '->ideograph attributes))
1222 ;; (when (and (memq '->decomposition attributes)
1223 ;; (setq value (get-char-attribute char '->decomposition)))
1224 ;; (insert (format "(->decomposition\t%s)%s"
1225 ;; (mapconcat (lambda (code)
1226 ;; (cond ((symbolp code)
1227 ;; (symbol-name code))
1228 ;; ((characterp code)
1230 ;; (format "%S" code)
1235 ;; (format "#x%04X" code))
1237 ;; (format "%s%S" line-breaking code))))
1240 ;; (setq attributes (delq '->decomposition attributes))
1242 (if (equal (get-char-attribute char '->titlecase)
1243 (get-char-attribute char '->uppercase))
1244 (setq attributes (delq '->titlecase attributes)))
1245 (when (and (memq '->mojikyo attributes)
1246 (setq value (get-char-attribute char '->mojikyo)))
1247 (insert (format "(->mojikyo\t\t. %06d)\t; %c%s"
1248 value (decode-char 'mojikyo value)
1250 (setq attributes (delq '->mojikyo attributes))
1252 (when (and (memq 'hanyu-dazidian-vol attributes)
1253 (setq value (get-char-attribute char 'hanyu-dazidian-vol)))
1254 (insert (format "(hanyu-dazidian-vol . %d)%s"
1255 value line-breaking))
1256 (setq attributes (delq 'hanyu-dazidian-vol attributes))
1258 (when (and (memq 'hanyu-dazidian-page attributes)
1259 (setq value (get-char-attribute char 'hanyu-dazidian-page)))
1260 (insert (format "(hanyu-dazidian-page . %d)%s"
1261 value line-breaking))
1262 (setq attributes (delq 'hanyu-dazidian-page attributes))
1264 (when (and (memq 'hanyu-dazidian-char attributes)
1265 (setq value (get-char-attribute char 'hanyu-dazidian-char)))
1266 (insert (format "(hanyu-dazidian-char . %d)%s"
1267 value line-breaking))
1268 (setq attributes (delq 'hanyu-dazidian-char attributes))
1271 (dolist (ignored '(composition
1272 ->denotational <-subsumptive ->ucs-unified
1273 ->ideographic-component-forms))
1274 (setq attributes (delq ignored attributes))))
1276 (setq name (car attributes))
1277 (unless (eq (setq value (get-char-attribute char name 'value-is-empty))
1279 (cond ((setq ret (find-charset name))
1280 (setq name (charset-name ret))
1281 (when (not (memq name dest-ccss))
1282 (setq dest-ccss (cons name dest-ccss))
1283 (char-db-insert-ccs-feature name value line-breaking))
1285 ((string-match "^=>ucs@" (symbol-name name))
1286 (insert (format "(%-18s . #x%04X)\t; %c%s"
1287 name value (decode-char '=ucs value)
1290 ((eq name 'jisx0208-1978/4X)
1291 (insert (format "(%-18s . #x%04X)%s"
1297 (not (eq name '->subsumptive))
1298 (not (eq name '->uppercase))
1299 (not (eq name '->lowercase))
1300 (not (eq name '->titlecase))
1301 (not (eq name '->canonical))
1302 (not (eq name '->Bopomofo))
1303 (not (eq name '->mistakable))
1304 (not (eq name '->ideographic-variants))
1305 (null (get-char-attribute
1306 char (intern (format "%s*sources" name))))
1307 (not (string-match "\\*sources$" (symbol-name name)))
1308 (null (get-char-attribute
1309 char (intern (format "%s*note" name))))
1310 (not (string-match "\\*note$" (symbol-name name)))
1311 (or (eq name '<-identical)
1312 (eq name '<-uppercase)
1313 (eq name '<-lowercase)
1314 (eq name '<-titlecase)
1315 (eq name '<-canonical)
1316 (eq name '<-ideographic-variants)
1317 ;; (eq name '<-synonyms)
1318 (string-match "^<-synonyms" (symbol-name name))
1319 (eq name '<-mistakable)
1320 (when (string-match "^->" (symbol-name name))
1322 ((string-match "^->fullwidth" (symbol-name name))
1323 (not (and (consp value)
1324 (characterp (car value))
1326 (car value) '=ucs 'defined-only)))
1331 ((or (eq name 'ideographic-structure)
1332 (eq name 'ideographic-combination)
1333 (eq name 'ideographic-)
1334 (eq name '=decomposition)
1335 (char-feature-base-name= '=decomposition name)
1336 (char-feature-base-name= '=>decomposition name)
1337 ;; (string-match "^=>*decomposition\\(@[^*]+\\)?$"
1338 ;; (symbol-name name))
1339 (string-match "^\\(->\\|<-\\)[^*]*$" (symbol-name name))
1340 (string-match "^\\(->\\|<-\\)[^*]*\\*sources$"
1343 (char-db-insert-relation-feature char name value
1346 ((memq name '(ideograph=
1347 original-ideograph-of
1348 ancient-ideograph-of
1351 ;; simplified-ideograph-of
1352 ideographic-variants
1353 ;; ideographic-different-form-of
1355 (insert (format "(%-18s%s " name line-breaking))
1356 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1358 (while (consp value)
1359 (setq cell (car value))
1360 (if (and (consp cell)
1365 (char-db-insert-alist cell readable)
1366 (setq separator lbs))
1369 (insert (prin1-to-string cell))
1370 (setq separator " "))
1371 (setq value (cdr value)))
1373 (insert line-breaking))
1375 (insert (format "(%-18s " name))
1376 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1378 (while (consp value)
1379 (setq cell (car value))
1380 (if (and (consp cell)
1382 (setq ret (condition-case nil
1390 (setq key (car (car rest)))
1391 (if (find-charset key)
1392 (setq cal (cons key cal))
1393 (setq al (cons key al)))
1394 (setq rest (cdr rest)))
1397 (insert-char-attributes ret
1401 (setq separator lbs))
1402 (setq ret (prin1-to-string cell))
1404 (if (< (+ (current-column)
1411 (setq separator " "))
1412 (setq value (cdr value)))
1414 (insert line-breaking))
1416 (insert (format "(%-18s" name))
1417 (setq ret (prin1-to-string value))
1418 (unless (< (+ (current-column)
1422 (insert line-breaking))
1423 (insert " . " ret ")" line-breaking)
1424 ;; (insert (format "(%-18s . %S)%s"
1429 (setq attributes (cdr attributes)))
1432 (defun insert-char-data (char &optional readable
1435 (narrow-to-region (point)(point))
1436 (insert "(define-char
1438 (insert-char-attributes char readable attributes)
1440 (goto-char (point-min))
1441 (while (re-search-forward "[ \t]+$" nil t)
1444 (goto-char (point-min))
1445 (while (re-search-forward "[ \t][ \t][ \t]*" nil t)
1446 (let ((column (current-column))
1447 (indent-tabs-mode t))
1448 (delete-region (match-beginning 0) (point))
1449 (indent-to column)))
1450 (goto-char (point-max))
1451 ;; (tabify (point-min)(point-max))
1454 (defun insert-char-data-with-variant (char &optional printable
1456 script excluded-script)
1457 (insert-char-data char printable)
1458 (let ((variants (char-variants char))
1461 (setq variants (sort variants #'<))
1462 (setq rest variants)
1463 (setq variants (cons char variants))
1465 (setq variant (car rest))
1466 (unless (get-char-attribute variant '<-subsumptive)
1467 (if (and (or (null script)
1468 (null (setq vs (get-char-attribute variant 'script)))
1470 (or (null excluded-script)
1471 (null (setq vs (get-char-attribute variant 'script)))
1472 (not (memq excluded-script vs))))
1473 (unless (and no-ucs-unified (get-char-attribute variant '=ucs))
1474 (insert-char-data variant printable)
1475 (if (setq ret (char-variants variant))
1477 (or (memq (car ret) variants)
1478 ;; (get-char-attribute (car ret) '<-subsumptive)
1479 (setq rest (nconc rest (list (car ret)))))
1480 (setq ret (cdr ret)))))))
1481 (setq rest (cdr rest)))))
1483 (defun insert-char-range-data (min max &optional script excluded-script)
1486 (while (<= code max)
1487 (setq char (decode-char '=ucs code))
1488 (if (encode-char char '=ucs 'defined-only)
1489 (insert-char-data-with-variant char nil 'no-ucs-unified
1490 script excluded-script))
1491 (setq code (1+ code)))))
1493 (defun write-char-range-data-to-file (min max file
1494 &optional script excluded-script)
1495 (let ((coding-system-for-write char-db-file-coding-system))
1497 (insert (format ";; -*- coding: %s -*-\n"
1498 char-db-file-coding-system))
1499 (insert-char-range-data min max script excluded-script)
1500 (write-region (point-min)(point-max) file))))
1502 (defvar what-character-original-window-configuration)
1505 (defun what-char-definition (char)
1506 (interactive (list (char-after)))
1507 (let ((buf (get-buffer-create "*Character Description*"))
1508 (the-buf (current-buffer))
1509 (win-conf (current-window-configuration)))
1511 (make-local-variable 'what-character-original-window-configuration)
1512 (setq what-character-original-window-configuration win-conf)
1513 (setq buffer-read-only nil)
1517 (insert-char-data-with-variant char 'printable)
1518 (unless (char-attribute-alist char)
1519 (insert (format ";; = %c\n"
1520 (let* ((rest (split-char char))
1524 (setq code (logior (lsh code 8)
1526 (decode-char ccs code)))))
1527 ;; (char-db-update-comment)
1528 (set-buffer-modified-p nil)
1529 (view-mode the-buf (lambda (buf)
1530 (set-window-configuration
1531 what-character-original-window-configuration)
1533 (goto-char (point-min)))
1535 (set-window-configuration
1536 what-character-original-window-configuration)
1537 (signal (car err) (cdr err)))))))
1543 (provide 'char-db-util)
1545 ;;; char-db-util.el ends here