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,2016 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
213 ;; =>>>adobe-japan1-0
214 ;; =>>>adobe-japan1-1
215 ;; =>>>adobe-japan1-2
216 ;; =>>>adobe-japan1-3
217 ;; =>>>adobe-japan1-4
218 ;; =>>>adobe-japan1-5
219 ;; =>>>adobe-japan1-6
223 ;; =>>>hanyo-denshi/ja
224 ;; =>>>hanyo-denshi/jb
225 ;; =>>>hanyo-denshi/jc
226 ;; =>>>hanyo-denshi/ft
227 ;; =>>>hanyo-denshi/ib
228 ;; =>>>hanyo-denshi/hg
229 ;; =>>>hanyo-denshi/jt
230 ;; =>>>hanyo-denshi/ks
346 =>big5-cdp-itaiji-001
358 ;;; @ char-db formatters
361 (defun char-db-make-char-spec (char)
363 (cond ((characterp char)
364 (cond ((and (setq ret (encode-char char '=ucs 'defined-only))
365 (not (and (<= #xE000 ret)(<= ret #xF8FF))))
366 (setq char-spec (list (cons '=ucs ret)))
367 (cond ((setq ret (get-char-attribute char 'name))
368 (setq char-spec (cons (cons 'name ret) char-spec))
370 ((setq ret (get-char-attribute char 'name*))
371 (setq char-spec (cons (cons 'name* ret) char-spec))
374 ((encode-char char '=mj 'defined-only)
376 (dolist (ccs (charset-list))
377 (if (and (or (eq ccs '=mj)
378 ;; (eq (charset-property ccs 'iso-ir) 177)
379 (string-match "=ucs@" (symbol-name ccs))
381 (setq ccs (charset-name ccs))
382 (null (assq ccs char-spec))
383 (setq ret (encode-char char ccs 'defined-only)))
384 (setq char-spec (cons (cons ccs ret) char-spec))))
386 ((encode-char char '==mj 'defined-only)
388 (dolist (ccs (charset-list))
389 (if (and (or (eq ccs '==mj)
390 ;; (eq (charset-property ccs 'iso-ir) 177)
391 (string-match "=ucs@" (symbol-name ccs))
393 (setq ccs (charset-name ccs))
394 (null (assq ccs char-spec))
395 (setq ret (encode-char char ccs 'defined-only)))
396 (setq char-spec (cons (cons ccs ret) char-spec))))
398 ((encode-char char '=adobe-japan1 'defined-only)
400 (dolist (ccs (charset-list))
401 (if (and (or (memq ccs
410 ;; (eq (charset-property ccs 'iso-ir) 177)
411 (string-match "=ucs@" (symbol-name ccs))
413 (setq ccs (charset-name ccs))
414 (null (assq ccs char-spec))
415 (setq ret (encode-char char ccs 'defined-only)))
416 (setq char-spec (cons (cons ccs ret) char-spec))))
418 ((encode-char char '==adobe-japan1 'defined-only)
420 (dolist (ccs (charset-list))
421 (if (and (or (memq 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))))
440 (let ((rest char-db-coded-charset-priority-list)
443 (setq ccs (charset-name
444 (find-charset (car rest))))
446 (encode-char char ccs
448 (throw 'tag (cons ccs ret)))
449 (setq rest (cdr rest))))))
450 (setq char-spec (list ret))
451 (dolist (ccs (delq (car ret) (charset-list)))
452 (if (and (or (charset-iso-final-char ccs)
459 (eq (charset-property ccs 'iso-ir) 177)
460 ;; (string-match "=ucs@" (symbol-name ccs))
462 (setq ccs (charset-name ccs))
463 (null (assq ccs char-spec))
464 (setq ret (encode-char char ccs 'defined-only)))
465 (setq char-spec (cons (cons ccs ret) char-spec))))
467 (setq char-spec (split-char char)))
468 (cond ((setq ret (get-char-attribute char 'name))
469 (setq char-spec (cons (cons 'name ret) char-spec))
471 ((setq ret (get-char-attribute char 'name*))
472 (setq char-spec (cons (cons 'name* ret) char-spec))
475 ((setq ret (get-char-attribute
476 char 'ideographic-combination))
478 (cons (cons 'ideographic-combination ret)
485 (defun char-db-insert-char-spec (char &optional readable column
488 (setq column (current-column)))
489 (let (char-spec temp-char)
490 (setq char-spec (char-db-make-char-spec char))
491 (unless (or (characterp char) ; char
493 (setq char (find-char char-spec))
495 ;; define temporary character
496 ;; Current implementation is dirty.
497 (setq temp-char (define-char (cons '(ideograph-daikanwa . 0)
499 (remove-char-attribute temp-char 'ideograph-daikanwa)
500 (setq char temp-char))
501 (insert-char-attributes char
503 (union (mapcar #'car char-spec)
507 ;; undefine temporary character
508 ;; Current implementation is dirty.
509 (setq char-spec (char-attribute-alist temp-char))
511 (remove-char-attribute temp-char (car (car char-spec)))
512 (setq char-spec (cdr char-spec))))))
514 (defun char-db-insert-alist (alist &optional readable column)
516 (setq column (current-column)))
518 (concat "\n" (make-string (1+ column) ?\ )))
522 lbs cell rest separator)
525 (setq name (car (car alist))
526 value (cdr (car alist)))
527 (cond ((eq name 'char)
529 (if (setq ret (condition-case nil
537 (setq key (car (car value)))
538 ;; (if (find-charset key)
539 ;; (setq cal (cons key cal))
540 (setq al (cons key al))
542 (setq value (cdr value)))
543 (insert-char-attributes ret
547 (insert (prin1-to-string value)))
549 (insert line-breaking))
551 (insert (format "(%-18s " name))
552 (setq lbs (concat "\n" (make-string (current-column) ?\ )))
554 (setq cell (car value))
555 (if (and (consp cell)
557 (setq ret (condition-case nil
567 (setq key (car (car rest)))
568 ;; (if (find-charset key)
569 ;; (setq cal (cons key cal))
570 (setq al (cons key al))
572 (setq rest (cdr rest)))
575 (insert-char-attributes ret
579 (setq separator lbs))
582 (insert (prin1-to-string cell))
583 (setq separator " "))
584 (setq value (cdr value)))
586 (insert line-breaking))
588 (insert (format "(%-18s . %S)%s"
591 (setq alist (cdr alist))))
594 (defun char-db-insert-char-reference (plist &optional readable column)
596 (setq column (current-column)))
598 (concat "\n" (make-string (1+ column) ?\ )))
603 (setq name (pop plist))
604 (setq value (pop plist))
605 (cond ((eq name :char)
608 (cond ((numberp value)
609 (setq value (decode-char '=ucs value)))
611 ;; (setq value (or (find-char value)
614 (char-db-insert-char-spec value readable)
615 (insert line-breaking)
618 (insert (format "%s%s\t%d ; %c%s"
621 (ideographic-radical value)
625 (insert (format "%s%s\t%S" separator name value))
626 (setq separator line-breaking)))
630 (defun char-db-decode-isolated-char (ccs code-point)
633 (cond ((eq ccs 'arabic-iso8859-6)
634 (decode-char ccs code-point))
636 ;; (decode-builtin-char '==gt code-point))
637 ((and (memq ccs '(=gt-pj-1
648 (setq ret (decode-char ccs code-point))
649 (setq ret (encode-char ret '=gt 'defined-only)))
650 (decode-builtin-char '=gt ret))
652 (decode-builtin-char ccs code-point))))
654 (or (decode-char ccs code-point)
655 (define-char (list (cons ccs code-point)))))
656 ((and (<= 0 (char-int ret))
657 (<= (char-int ret) #x1F))
658 (decode-char '=ucs (+ #x2400 (char-int ret))))
659 ((= (char-int ret) #x7F)
663 (defvar char-db-convert-obsolete-format t)
665 (defun char-db-insert-ccs-feature (name value line-breaking)
671 ((memq name '(=>iwds-1
674 =shinjigen@1ed ==shinjigen@1ed
675 =shinjigen@rev ==shinjigen@rev
676 =shinjigen/+p@rev ==shinjigen/+p@rev
677 ===daikanwa/ho ==daikanwa/ho
678 =daikanwa/ho =>>daikanwa/ho =>daikanwa/ho))
679 "(%-18s . %04d)\t; %c")
680 ((eq name '=shinjigen@1ed/24pr)
681 "(%-18s . %04d)\t; %c")
685 ==daikanwa =daikanwa =>>daikanwa =>daikanwa
686 =daikanwa@rev1 =daikanwa@rev2
687 =daikanwa/+p ==daikanwa/+p ===daikanwa/+p
689 =daikanwa/+2p =>>daikanwa/+2p
694 =adobe-japan1-0 ==adobe-japan1-0 ===adobe-japan1-0
695 =adobe-japan1-1 ==adobe-japan1-1 ===adobe-japan1-1
696 =adobe-japan1-2 ==adobe-japan1-2 ===adobe-japan1-2
697 =adobe-japan1-3 ==adobe-japan1-3 ===adobe-japan1-3
698 =adobe-japan1-4 ==adobe-japan1-4 ===adobe-japan1-4
699 =adobe-japan1-5 ==adobe-japan1-5 ===adobe-japan1-5
700 =adobe-japan1-6 ==adobe-japan1-6 ===adobe-japan1-6
701 =>>adobe-japan1-0 =+>adobe-japan1-0
702 =>>adobe-japan1-1 =+>adobe-japan1-1
703 =>>adobe-japan1-2 =+>adobe-japan1-2
704 =>>adobe-japan1-3 =+>adobe-japan1-3
705 =>>adobe-japan1-4 =+>adobe-japan1-4
706 =>>adobe-japan1-5 =+>adobe-japan1-5
707 =>>adobe-japan1-6 =+>adobe-japan1-6
708 =>cbeta =cbeta =>>cbeta ==cbeta ===cbeta
709 =zinbun-oracle =>zinbun-oracle
710 ===hng-jou ===hng-keg ===hng-dng ===hng-mam
711 ===hng-drt ===hng-kgk ===hng-myz ===hng-kda
712 ===hng-khi ===hng-khm ===hng-hok ===hng-kyd ===hng-sok
713 ===hng-yhk ===hng-kak ===hng-kar ===hng-kae
714 ===hng-sys ===hng-tsu ===hng-tzj
715 ===hng-hos ===hng-nak ===hng-jhk
716 ===hng-hod ===hng-gok ===hng-ink ===hng-nto
717 ===hng-nkm ===hng-k24 ===hng-nkk
718 ===hng-kcc ===hng-kcj ===hng-kbk ===hng-sik
719 ===hng-skk ===hng-kyu ===hng-ksk ===hng-wan
720 ===hng-okd ===hng-wad ===hng-kmi
721 ===hng-zkd ===hng-doh ===hng-jyu
722 ===hng-tzs ===hng-kss ===hng-kyo
724 ;; (string-match "^=adobe-" (symbol-name name))
726 "(%-18s . %05d)\t; %c")
727 ((memq name '(=hanyo-denshi/ks
728 ==hanyo-denshi/ks ===hanyo-denshi/ks
731 =mj ==mj ===mj =>>mj =>mj
733 "(%-18s . %06d)\t; %c")
734 ((memq name '(=hanyo-denshi/tk ==hanyo-denshi/tk))
735 "(%-18s . %08d)\t; %c")
736 ((>= (charset-dimension name) 2)
737 "(%-18s . #x%04X)\t; %c")
739 "(%-18s . #x%02X)\t; %c"))
741 (if (= (charset-iso-graphic-plane name) 1)
743 (cond ((= (charset-dimension name) 1)
745 ((= (charset-dimension name) 2)
747 ((= (charset-dimension name) 3)
751 (char-db-decode-isolated-char name value)))
752 (if (and (= (charset-chars name) 94)
753 (= (charset-dimension name) 2))
754 (insert (format " [%02d-%02d]"
755 (- (lsh value -8) 32)
756 (- (logand value 255) 32))))
759 (insert (format "(%-18s . %s)" name value))
761 (insert line-breaking))
763 (defun char-db-insert-relation-feature (char name value line-breaking
765 (insert (format "(%-18s%s " name line-breaking))
766 (let ((lbs (concat "\n" (make-string (current-column) ?\ )))
767 separator cell sources required-features
769 (if (characterp value)
770 (setq value (list value)))
772 (setq cell (car value))
774 (setq cell (decode-char '=ucs cell)))
776 ((eq name '->subsumptive)
777 (when (or (not (some (lambda (atr)
778 (get-char-attribute cell atr))
779 char-db-ignored-attributes))
781 (encode-char cell ccs 'defined-only))
785 (let ((char-db-ignored-attributes
787 char-db-ignored-attributes)))
788 (insert-char-attributes cell readable nil nil 'for-sub-node))
789 (setq separator lbs))
794 char (intern (format "%s*sources" name))))
795 (setq required-features nil)
796 (dolist (source sources)
800 shinjigen shinjigen@1ed shinjigen@rev))
801 (setq required-features
802 (union required-features
814 =shinjigen/+p@rev))))
816 (setq required-features
817 (union required-features
822 ((find-charset (setq ret (intern (format "=%s" source))))
823 (setq required-features
824 (cons ret required-features)))
825 (t (setq required-features
826 (cons source required-features)))))
827 (cond ((string-match "@JP" (symbol-name name))
828 (setq required-features
829 (union required-features
837 ((string-match "@CN" (symbol-name name))
838 (setq required-features
839 (union required-features
846 (insert (format "%S" cell))
847 (char-db-insert-char-spec cell readable
850 (setq separator lbs))
854 (if (consp (car cell))
855 (char-db-insert-char-spec cell readable)
856 (char-db-insert-char-reference cell readable))
857 (setq separator lbs))
861 (insert (prin1-to-string cell))
862 (setq separator " ")))
863 (setq value (cdr value)))
865 (insert line-breaking)))
867 (defun insert-char-attributes (char &optional readable attributes column
870 (setq column (current-column)))
871 (let (name value ; has-long-ccs-name
875 (concat "\n" (make-string (1+ column) ?\ )))
876 lbs cell separator ret
878 dest-ccss ; sources required-features
883 (if (consp attributes)
885 (dolist (name attributes)
886 (unless (memq name char-db-ignored-attributes)
887 (if (find-charset name)
891 (dolist (name (char-attribute-list))
892 (unless (memq name char-db-ignored-attributes)
893 (if (find-charset name)
897 #'char-attribute-name<)))
899 (when (memq '<-subsumptive attributes)
900 (when (or readable (not for-sub-node))
901 (when (setq value (get-char-attribute char '<-subsumptive))
902 (char-db-insert-relation-feature char '<-subsumptive value
905 (setq attributes (delq '<-subsumptive attributes)))
906 (when (and (memq '<-denotational attributes)
907 (setq value (get-char-attribute char '<-denotational)))
908 (char-db-insert-relation-feature char '<-denotational value
911 (setq attributes (delq '<-denotational attributes)))
912 (when (and (memq '<-denotational@component attributes)
913 (setq value (get-char-attribute char '<-denotational@component)))
914 (char-db-insert-relation-feature char '<-denotational@component value
917 (setq attributes (delq '<-denotational@component attributes)))
918 (when (and (memq 'name attributes)
919 (setq value (get-char-attribute char 'name)))
921 (if (> (+ (current-column) (length value)) 48)
924 value line-breaking))
925 (setq attributes (delq 'name attributes))
927 (when (and (memq 'name* attributes)
928 (setq value (get-char-attribute char 'name*)))
930 (if (> (+ (current-column) (length value)) 48)
933 value line-breaking))
934 (setq attributes (delq 'name* attributes))
936 (when (and (memq 'script attributes)
937 (setq value (get-char-attribute char 'script)))
938 (insert (format "(script\t\t%s)%s"
939 (mapconcat (function prin1-to-string)
942 (setq attributes (delq 'script attributes))
944 (dolist (name '(=>ucs =>ucs*))
945 (when (and (memq name attributes)
946 (setq value (get-char-attribute char name)))
947 (insert (format "(%-18s . #x%04X)\t; %c%s"
948 name value (decode-char '=ucs value)
950 (setq attributes (delq name attributes))))
951 (dolist (name '(=>ucs@gb =>ucs@big5))
952 (when (and (memq name attributes)
953 (setq value (get-char-attribute char name)))
954 (insert (format "(%-18s . #x%04X)\t; %c%s"
959 (symbol-name name) 2)))
962 (setq attributes (delq name attributes))
964 ;; (dolist (name '(=>daikanwa))
965 ;; (when (and (memq name attributes)
966 ;; (setq value (get-char-attribute char name)))
968 ;; (if (integerp value)
969 ;; (format "(%-18s . %05d)\t; %c%s"
970 ;; name value (decode-char '=daikanwa value)
972 ;; (format "(%-18s %s)\t; %c%s"
974 ;; (mapconcat (function prin1-to-string)
976 ;; (char-representative-of-daikanwa char)
978 ;; (setq attributes (delq name attributes))))
979 (when (and (memq 'general-category attributes)
980 (setq value (get-char-attribute char 'general-category)))
982 "(general-category\t%s) ; %s%s"
983 (mapconcat (lambda (cell)
986 (cond ((rassoc value unidata-normative-category-alist)
987 "Normative Category")
988 ((rassoc value unidata-informative-category-alist)
989 "Informative Category")
993 (setq attributes (delq 'general-category attributes))
995 (when (and (memq 'bidi-category attributes)
996 (setq value (get-char-attribute char 'bidi-category)))
997 (insert (format "(bidi-category\t. %S)%s"
1000 (setq attributes (delq 'bidi-category attributes))
1002 (unless (or (not (memq 'mirrored attributes))
1003 (eq (setq value (get-char-attribute char 'mirrored 'empty))
1005 (insert (format "(mirrored\t\t. %S)%s"
1008 (setq attributes (delq 'mirrored attributes))
1011 ((and (memq 'decimal-digit-value attributes)
1012 (setq value (get-char-attribute char 'decimal-digit-value)))
1013 (insert (format "(decimal-digit-value . %S)%s"
1016 (setq attributes (delq 'decimal-digit-value attributes))
1017 (when (and (memq 'digit-value attributes)
1018 (setq value (get-char-attribute char 'digit-value)))
1019 (insert (format "(digit-value\t . %S)%s"
1022 (setq attributes (delq 'digit-value attributes))
1024 (when (and (memq 'numeric-value attributes)
1025 (setq value (get-char-attribute char 'numeric-value)))
1026 (insert (format "(numeric-value\t . %S)%s"
1029 (setq attributes (delq 'numeric-value attributes))
1033 (when (and (memq 'digit-value attributes)
1034 (setq value (get-char-attribute char 'digit-value)))
1035 (insert (format "(digit-value\t. %S)%s"
1038 (setq attributes (delq 'digit-value attributes))
1040 (when (and (memq 'numeric-value attributes)
1041 (setq value (get-char-attribute char 'numeric-value)))
1042 (insert (format "(numeric-value\t. %S)%s"
1045 (setq attributes (delq 'numeric-value attributes))
1047 (when (and (memq 'iso-10646-comment attributes)
1048 (setq value (get-char-attribute char 'iso-10646-comment)))
1049 (insert (format "(iso-10646-comment\t. %S)%s"
1052 (setq attributes (delq 'iso-10646-comment attributes))
1054 (when (and (memq 'morohashi-daikanwa attributes)
1055 (setq value (get-char-attribute char 'morohashi-daikanwa)))
1056 (insert (format "(morohashi-daikanwa\t%s)%s"
1057 (mapconcat (function prin1-to-string) value " ")
1059 (setq attributes (delq 'morohashi-daikanwa attributes))
1063 (when (and (memq 'ideographic-radical attributes)
1064 (setq value (get-char-attribute char 'ideographic-radical)))
1065 (setq radical value)
1066 (insert (format "(ideographic-radical . %S)\t; %c%s"
1068 (ideographic-radical radical)
1070 (setq attributes (delq 'ideographic-radical attributes))
1072 (when (and (memq 'shuowen-radical attributes)
1073 (setq value (get-char-attribute char 'shuowen-radical)))
1074 (insert (format "(shuowen-radical\t. %S)\t; %c%s"
1076 (shuowen-radical value)
1078 (setq attributes (delq 'shuowen-radical attributes))
1083 char-db-feature-domains
1085 (dolist (feature (char-attribute-list))
1086 (setq feature (symbol-name feature))
1088 "\\(radical\\|strokes\\)@\\([^@*]+\\)\\(\\*\\|$\\)"
1090 (setq domain (intern (match-string 2 feature)))
1091 (unless (memq domain dest)
1092 (setq dest (cons domain dest)))))
1093 (sort dest #'string<))))
1094 (setq key (intern (format "%s@%s" 'ideographic-radical domain)))
1095 (when (and (memq key attributes)
1096 (setq value (get-char-attribute char key)))
1097 (setq radical value)
1098 (insert (format "(%s . %S)\t; %c%s"
1101 (ideographic-radical radical)
1103 (setq attributes (delq key attributes))
1105 (setq key (intern (format "%s@%s" 'ideographic-strokes domain)))
1106 (when (and (memq key attributes)
1107 (setq value (get-char-attribute char key)))
1108 (setq strokes value)
1109 (insert (format "(%s . %S)%s"
1113 (setq attributes (delq key attributes))
1115 (setq key (intern (format "%s@%s" 'total-strokes domain)))
1116 (when (and (memq key attributes)
1117 (setq value (get-char-attribute char key)))
1118 (insert (format "(%s . %S)%s"
1122 (setq attributes (delq key attributes))
1124 (dolist (feature '(ideographic-radical
1127 (setq key (intern (format "%s@%s*sources" feature domain)))
1128 (when (and (memq key attributes)
1129 (setq value (get-char-attribute char key)))
1130 (insert (format "(%s%s" key line-breaking))
1131 (dolist (cell value)
1132 (insert (format " %s" cell)))
1134 (insert line-breaking)
1135 (setq attributes (delq key attributes))
1138 (when (and (memq 'ideographic-strokes attributes)
1139 (setq value (get-char-attribute char 'ideographic-strokes)))
1140 (setq strokes value)
1141 (insert (format "(ideographic-strokes . %S)%s"
1144 (setq attributes (delq 'ideographic-strokes attributes))
1146 (when (and (memq 'kangxi-radical attributes)
1147 (setq value (get-char-attribute char 'kangxi-radical)))
1148 (unless (eq value radical)
1149 (insert (format "(kangxi-radical\t . %S)\t; %c%s"
1151 (ideographic-radical value)
1154 (setq radical value)))
1155 (setq attributes (delq 'kangxi-radical attributes))
1157 (when (and (memq 'kangxi-strokes attributes)
1158 (setq value (get-char-attribute char 'kangxi-strokes)))
1159 (unless (eq value strokes)
1160 (insert (format "(kangxi-strokes\t . %S)%s"
1164 (setq strokes value)))
1165 (setq attributes (delq 'kangxi-strokes attributes))
1167 ;; (when (and (memq 'japanese-radical attributes)
1168 ;; (setq value (get-char-attribute char 'japanese-radical)))
1169 ;; (unless (eq value radical)
1170 ;; (insert (format "(japanese-radical\t . %S)\t; %c%s"
1172 ;; (ideographic-radical value)
1175 ;; (setq radical value)))
1176 ;; (setq attributes (delq 'japanese-radical attributes))
1178 (when (and (memq 'japanese-strokes attributes)
1179 (setq value (get-char-attribute char 'japanese-strokes)))
1180 (unless (eq value strokes)
1181 (insert (format "(japanese-strokes\t . %S)%s"
1185 (setq strokes value)))
1186 (setq attributes (delq 'japanese-strokes attributes))
1188 (when (and (memq 'cns-radical attributes)
1189 (setq value (get-char-attribute char 'cns-radical)))
1190 (insert (format "(cns-radical\t . %S)\t; %c%s"
1192 (ideographic-radical value)
1194 (setq attributes (delq 'cns-radical attributes))
1196 (when (and (memq 'cns-strokes attributes)
1197 (setq value (get-char-attribute char 'cns-strokes)))
1198 (unless (eq value strokes)
1199 (insert (format "(cns-strokes\t . %S)%s"
1203 (setq strokes value)))
1204 (setq attributes (delq 'cns-strokes attributes))
1206 ;; (when (and (memq 'shinjigen-1-radical attributes)
1207 ;; (setq value (get-char-attribute char 'shinjigen-1-radical)))
1208 ;; (unless (eq value radical)
1209 ;; (insert (format "(shinjigen-1-radical . %S)\t; %c%s"
1211 ;; (ideographic-radical value)
1214 ;; (setq radical value)))
1215 ;; (setq attributes (delq 'shinjigen-1-radical attributes))
1217 ;; (when (and (memq 'ideographic- attributes)
1218 ;; (setq value (get-char-attribute char 'ideographic-)))
1219 ;; (insert "(ideographic- ")
1220 ;; (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1222 ;; (while (consp value)
1223 ;; (setq cell (car value))
1224 ;; (if (integerp cell)
1225 ;; (setq cell (decode-char '=ucs cell)))
1226 ;; (cond ((characterp cell)
1230 ;; (insert (format "%S" cell))
1231 ;; (char-db-insert-char-spec cell readable))
1232 ;; (setq separator lbs))
1236 ;; (if (consp (car cell))
1237 ;; (char-db-insert-char-spec cell readable)
1238 ;; (char-db-insert-char-reference cell readable))
1239 ;; (setq separator lbs))
1242 ;; (insert separator))
1243 ;; (insert (prin1-to-string cell))
1244 ;; (setq separator " ")))
1245 ;; (setq value (cdr value)))
1247 ;; (insert line-breaking)
1248 ;; (setq attributes (delq 'ideographic- attributes)))
1249 (when (and (memq 'total-strokes attributes)
1250 (setq value (get-char-attribute char 'total-strokes)))
1251 (insert (format "(total-strokes . %S)%s"
1254 (setq attributes (delq 'total-strokes attributes))
1256 ;; (when (and (memq '->ideograph attributes)
1257 ;; (setq value (get-char-attribute char '->ideograph)))
1258 ;; (insert (format "(->ideograph\t%s)%s"
1259 ;; (mapconcat (lambda (code)
1260 ;; (cond ((symbolp code)
1261 ;; (symbol-name code))
1263 ;; (format "#x%04X" code))
1266 ;; line-breaking code))))
1269 ;; (setq attributes (delq '->ideograph attributes))
1271 ;; (when (and (memq '->decomposition attributes)
1272 ;; (setq value (get-char-attribute char '->decomposition)))
1273 ;; (insert (format "(->decomposition\t%s)%s"
1274 ;; (mapconcat (lambda (code)
1275 ;; (cond ((symbolp code)
1276 ;; (symbol-name code))
1277 ;; ((characterp code)
1279 ;; (format "%S" code)
1284 ;; (format "#x%04X" code))
1286 ;; (format "%s%S" line-breaking code))))
1289 ;; (setq attributes (delq '->decomposition attributes))
1291 (if (equal (get-char-attribute char '->titlecase)
1292 (get-char-attribute char '->uppercase))
1293 (setq attributes (delq '->titlecase attributes)))
1294 (when (and (memq '->mojikyo attributes)
1295 (setq value (get-char-attribute char '->mojikyo)))
1296 (insert (format "(->mojikyo\t\t. %06d)\t; %c%s"
1297 value (decode-char 'mojikyo value)
1299 (setq attributes (delq '->mojikyo attributes))
1301 ;; (when (and (memq 'hanyu-dazidian-vol attributes)
1302 ;; (setq value (get-char-attribute char 'hanyu-dazidian-vol)))
1303 ;; (insert (format "(hanyu-dazidian-vol . %d)%s"
1304 ;; value line-breaking))
1305 ;; (setq attributes (delq 'hanyu-dazidian-vol attributes))
1307 ;; (when (and (memq 'hanyu-dazidian-page attributes)
1308 ;; (setq value (get-char-attribute char 'hanyu-dazidian-page)))
1309 ;; (insert (format "(hanyu-dazidian-page . %d)%s"
1310 ;; value line-breaking))
1311 ;; (setq attributes (delq 'hanyu-dazidian-page attributes))
1313 ;; (when (and (memq 'hanyu-dazidian-char attributes)
1314 ;; (setq value (get-char-attribute char 'hanyu-dazidian-char)))
1315 ;; (insert (format "(hanyu-dazidian-char . %d)%s"
1316 ;; value line-breaking))
1317 ;; (setq attributes (delq 'hanyu-dazidian-char attributes))
1320 (dolist (ignored '(composition
1321 ->denotational <-subsumptive ->ucs-unified
1322 ->ideographic-component-forms))
1323 (setq attributes (delq ignored attributes))))
1325 (setq name (car attributes))
1326 (unless (eq (setq value (get-char-attribute char name 'value-is-empty))
1328 (cond ((setq ret (find-charset name))
1329 (setq name (charset-name ret))
1330 (when (not (memq name dest-ccss))
1331 (setq dest-ccss (cons name dest-ccss))
1332 (char-db-insert-ccs-feature name value line-breaking))
1334 ((string-match "^=>ucs@" (symbol-name name))
1335 (insert (format "(%-18s . #x%04X)\t; %c%s"
1336 name value (decode-char '=ucs value)
1339 ((eq name 'jisx0208-1978/4X)
1340 (insert (format "(%-18s . #x%04X)%s"
1346 (not (eq name '->subsumptive))
1347 (not (eq name '->uppercase))
1348 (not (eq name '->lowercase))
1349 (not (eq name '->titlecase))
1350 (not (eq name '->canonical))
1351 (not (eq name '->Bopomofo))
1352 (not (eq name '->mistakable))
1353 (not (eq name '->ideographic-variants))
1354 (null (get-char-attribute
1355 char (intern (format "%s*sources" name))))
1356 (not (string-match "\\*sources$" (symbol-name name)))
1357 (null (get-char-attribute
1358 char (intern (format "%s*note" name))))
1359 (not (string-match "\\*note$" (symbol-name name)))
1360 (or (eq name '<-identical)
1361 (eq name '<-uppercase)
1362 (eq name '<-lowercase)
1363 (eq name '<-titlecase)
1364 (eq name '<-canonical)
1365 (eq name '<-ideographic-variants)
1366 ;; (eq name '<-synonyms)
1367 (string-match "^<-synonyms" (symbol-name name))
1368 (eq name '<-mistakable)
1369 (when (string-match "^->" (symbol-name name))
1371 ((string-match "^->fullwidth" (symbol-name name))
1372 (not (and (consp value)
1373 (characterp (car value))
1375 (car value) '=ucs 'defined-only)))
1380 ((or (eq name 'ideographic-structure)
1381 (eq name 'ideographic-combination)
1382 ;; (eq name 'ideographic-)
1383 (eq name '=decomposition)
1384 (char-feature-base-name= '=decomposition name)
1385 (char-feature-base-name= '=>decomposition name)
1386 ;; (string-match "^=>*decomposition\\(@[^*]+\\)?$"
1387 ;; (symbol-name name))
1388 (string-match "^\\(->\\|<-\\)[^*]*$" (symbol-name name))
1389 (string-match "^\\(->\\|<-\\)[^*]*\\*sources$"
1392 (char-db-insert-relation-feature char name value
1395 ;; ((memq name '(ideograph=
1396 ;; original-ideograph-of
1397 ;; ancient-ideograph-of
1398 ;; vulgar-ideograph-of
1399 ;; wrong-ideograph-of
1400 ;; ;; simplified-ideograph-of
1401 ;; ideographic-variants
1402 ;; ;; ideographic-different-form-of
1404 ;; (insert (format "(%-18s%s " name line-breaking))
1405 ;; (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1407 ;; (while (consp value)
1408 ;; (setq cell (car value))
1409 ;; (if (and (consp cell)
1410 ;; (consp (car cell)))
1414 ;; (char-db-insert-alist cell readable)
1415 ;; (setq separator lbs))
1417 ;; (insert separator))
1418 ;; (insert (prin1-to-string cell))
1419 ;; (setq separator " "))
1420 ;; (setq value (cdr value)))
1422 ;; (insert line-breaking))
1424 (insert (format "(%-18s " name))
1425 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1427 (while (consp value)
1428 (setq cell (car value))
1429 (if (and (consp cell)
1431 (setq ret (condition-case nil
1439 (setq key (car (car rest)))
1440 (if (find-charset key)
1441 (setq cal (cons key cal))
1442 (setq al (cons key al)))
1443 (setq rest (cdr rest)))
1446 (insert-char-attributes ret
1450 (setq separator lbs))
1451 (setq ret (prin1-to-string cell))
1453 (if (< (+ (current-column)
1460 (setq separator " "))
1461 (setq value (cdr value)))
1463 (insert line-breaking))
1465 (insert (format "(%-18s" name))
1466 (setq ret (prin1-to-string value))
1467 (unless (< (+ (current-column)
1471 (insert line-breaking))
1472 (insert " . " ret ")" line-breaking)
1473 ;; (insert (format "(%-18s . %S)%s"
1478 (setq attributes (cdr attributes)))
1481 (defun insert-char-data (char &optional readable
1484 (narrow-to-region (point)(point))
1485 (insert "(define-char
1487 (insert-char-attributes char readable attributes)
1489 (goto-char (point-min))
1490 (while (re-search-forward "[ \t]+$" nil t)
1493 (goto-char (point-min))
1494 (while (re-search-forward "[ \t][ \t][ \t]*" nil t)
1495 (let ((column (current-column))
1496 (indent-tabs-mode t))
1497 (delete-region (match-beginning 0) (point))
1498 (indent-to column)))
1499 (goto-char (point-max))
1500 ;; (tabify (point-min)(point-max))
1503 (defun insert-char-data-with-variant (char &optional printable
1505 script excluded-script)
1506 (insert-char-data char printable)
1507 (let ((variants (char-variants char))
1510 (setq variants (sort variants #'<))
1511 (setq rest variants)
1512 (setq variants (cons char variants))
1514 (setq variant (car rest))
1515 (unless (get-char-attribute variant '<-subsumptive)
1516 (if (and (or (null script)
1517 (null (setq vs (get-char-attribute variant 'script)))
1519 (or (null excluded-script)
1520 (null (setq vs (get-char-attribute variant 'script)))
1521 (not (memq excluded-script vs))))
1522 (unless (and no-ucs-unified (get-char-attribute variant '=ucs))
1523 (insert-char-data variant printable)
1524 (if (setq ret (char-variants variant))
1526 (or (memq (car ret) variants)
1527 ;; (get-char-attribute (car ret) '<-subsumptive)
1528 (setq rest (nconc rest (list (car ret)))))
1529 (setq ret (cdr ret)))))))
1530 (setq rest (cdr rest)))))
1532 (defun insert-char-range-data (min max &optional script excluded-script)
1535 (while (<= code max)
1536 (setq char (decode-char '=ucs code))
1537 (if (encode-char char '=ucs 'defined-only)
1538 (insert-char-data-with-variant char nil 'no-ucs-unified
1539 script excluded-script))
1540 (setq code (1+ code)))))
1542 (defun write-char-range-data-to-file (min max file
1543 &optional script excluded-script)
1544 (let ((coding-system-for-write char-db-file-coding-system))
1546 (insert (format ";; -*- coding: %s -*-\n"
1547 char-db-file-coding-system))
1548 (insert-char-range-data min max script excluded-script)
1549 (write-region (point-min)(point-max) file))))
1551 (defvar what-character-original-window-configuration)
1554 (defun what-char-definition (char)
1555 (interactive (list (char-after)))
1556 (let ((buf (get-buffer-create "*Character Description*"))
1557 (the-buf (current-buffer))
1558 (win-conf (current-window-configuration)))
1560 (make-local-variable 'what-character-original-window-configuration)
1561 (setq what-character-original-window-configuration win-conf)
1562 (setq buffer-read-only nil)
1566 (insert-char-data-with-variant char 'printable)
1567 (unless (char-attribute-alist char)
1568 (insert (format ";; = %c\n"
1569 (let* ((rest (split-char char))
1573 (setq code (logior (lsh code 8)
1575 (decode-char ccs code)))))
1576 ;; (char-db-update-comment)
1577 (set-buffer-modified-p nil)
1578 (view-mode the-buf (lambda (buf)
1579 (set-window-configuration
1580 what-character-original-window-configuration)
1582 (goto-char (point-min)))
1584 (set-window-configuration
1585 what-character-original-window-configuration)
1586 (signal (car err) (cdr err)))))))
1592 (provide 'char-db-util)
1594 ;;; char-db-util.el ends here