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,2017,2018 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
214 ;; =>>>adobe-japan1-0
215 ;; =>>>adobe-japan1-1
216 ;; =>>>adobe-japan1-2
217 ;; =>>>adobe-japan1-3
218 ;; =>>>adobe-japan1-4
219 ;; =>>>adobe-japan1-5
220 ;; =>>>adobe-japan1-6
224 ;; =>>>hanyo-denshi/ja
225 ;; =>>>hanyo-denshi/jb
226 ;; =>>>hanyo-denshi/jc
227 ;; =>>>hanyo-denshi/ft
228 ;; =>>>hanyo-denshi/ib
229 ;; =>>>hanyo-denshi/hg
230 ;; =>>>hanyo-denshi/jt
231 ;; =>>>hanyo-denshi/ks
271 ;; =>ucs@hanyo-denshi
366 =>big5-cdp-itaiji-001
376 ;;; @ char-db formatters
379 (defun char-db-make-char-spec (char)
381 (cond ((characterp char)
382 (cond ((and (setq ret (encode-char char '=ucs 'defined-only))
383 (not (and (<= #xE000 ret)(<= ret #xF8FF))))
384 (setq char-spec (list (cons '=ucs ret)))
385 (cond ((setq ret (get-char-attribute char 'name))
386 (setq char-spec (cons (cons 'name ret) char-spec))
388 ((setq ret (get-char-attribute char 'name*))
389 (setq char-spec (cons (cons 'name* ret) char-spec))
392 ((encode-char char '=mj 'defined-only)
394 (dolist (ccs (charset-list))
395 (if (and (or (eq ccs '=mj)
396 ;; (eq (charset-property ccs 'iso-ir) 177)
397 (string-match "=ucs@" (symbol-name ccs))
399 (setq ccs (charset-name ccs))
400 (null (assq ccs char-spec))
401 (setq ret (encode-char char ccs 'defined-only)))
402 (setq char-spec (cons (cons ccs ret) char-spec))))
404 ((encode-char char '==mj 'defined-only)
406 (dolist (ccs (charset-list))
407 (if (and (or (eq ccs '==mj)
408 ;; (eq (charset-property ccs 'iso-ir) 177)
409 (string-match "=ucs@" (symbol-name ccs))
411 (setq ccs (charset-name ccs))
412 (null (assq ccs char-spec))
413 (setq ret (encode-char char ccs 'defined-only)))
414 (setq char-spec (cons (cons ccs ret) char-spec))))
416 ((encode-char char '=adobe-japan1 'defined-only)
418 (dolist (ccs (charset-list))
419 (if (and (or (memq 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 ((encode-char char '==adobe-japan1 'defined-only)
438 (dolist (ccs (charset-list))
439 (if (and (or (memq ccs
448 ;; (eq (charset-property ccs 'iso-ir) 177)
449 (string-match "=ucs@" (symbol-name ccs))
451 (setq ccs (charset-name ccs))
452 (null (assq ccs char-spec))
453 (setq ret (encode-char char ccs 'defined-only)))
454 (setq char-spec (cons (cons ccs ret) char-spec))))
458 (let ((rest char-db-coded-charset-priority-list)
461 (setq ccs (charset-name
462 (find-charset (car rest))))
464 (encode-char char ccs
466 (throw 'tag (cons ccs ret)))
467 (setq rest (cdr rest))))))
468 (setq char-spec (list ret))
469 (dolist (ccs (delq (car ret) (charset-list)))
470 (if (and (or (charset-iso-final-char ccs)
477 (and (eq (charset-property ccs 'iso-ir) 177)
478 (not (eq (charset-name ccs) '=ucs@big5)))
479 ;; (string-match "=ucs@" (symbol-name ccs))
481 (setq ccs (charset-name ccs))
482 (null (assq ccs char-spec))
483 (setq ret (encode-char char ccs 'defined-only)))
484 (setq char-spec (cons (cons ccs ret) char-spec))))
486 (setq char-spec (split-char char)))
487 (cond ((setq ret (get-char-attribute char 'name))
488 (setq char-spec (cons (cons 'name ret) char-spec))
490 ((setq ret (get-char-attribute char 'name*))
491 (setq char-spec (cons (cons 'name* ret) char-spec))
494 ((setq ret (get-char-attribute
495 char 'ideographic-combination))
497 (cons (cons 'ideographic-combination ret)
504 (defun char-db-insert-char-spec (char &optional readable column
507 (setq column (current-column)))
508 (let (char-spec temp-char)
509 (setq char-spec (char-db-make-char-spec char))
510 (unless (or (characterp char) ; char
512 (setq char (find-char char-spec))
514 ;; define temporary character
515 ;; Current implementation is dirty.
516 (setq temp-char (define-char (cons '(ideograph-daikanwa . 0)
518 (remove-char-attribute temp-char 'ideograph-daikanwa)
519 (setq char temp-char))
520 (insert-char-attributes char
522 (union (mapcar #'car char-spec)
526 ;; undefine temporary character
527 ;; Current implementation is dirty.
528 (setq char-spec (char-attribute-alist temp-char))
530 (remove-char-attribute temp-char (car (car char-spec)))
531 (setq char-spec (cdr char-spec))))))
533 (defun char-db-insert-alist (alist &optional readable column)
535 (setq column (current-column)))
537 (concat "\n" (make-string (1+ column) ?\ )))
541 lbs cell rest separator)
544 (setq name (car (car alist))
545 value (cdr (car alist)))
546 (cond ((eq name 'char)
548 (if (setq ret (condition-case nil
556 (setq key (car (car value)))
557 ;; (if (find-charset key)
558 ;; (setq cal (cons key cal))
559 (setq al (cons key al))
561 (setq value (cdr value)))
562 (insert-char-attributes ret
566 (insert (prin1-to-string value)))
568 (insert line-breaking))
570 (insert (format "(%-18s " name))
571 (setq lbs (concat "\n" (make-string (current-column) ?\ )))
573 (setq cell (car value))
574 (if (and (consp cell)
576 (setq ret (condition-case nil
586 (setq key (car (car rest)))
587 ;; (if (find-charset key)
588 ;; (setq cal (cons key cal))
589 (setq al (cons key al))
591 (setq rest (cdr rest)))
594 (insert-char-attributes ret
598 (setq separator lbs))
601 (insert (prin1-to-string cell))
602 (setq separator " "))
603 (setq value (cdr value)))
605 (insert line-breaking))
607 (insert (format "(%-18s . %S)%s"
610 (setq alist (cdr alist))))
613 (defun char-db-insert-char-reference (plist &optional readable column)
615 (setq column (current-column)))
617 (concat "\n" (make-string (1+ column) ?\ )))
622 (setq name (pop plist))
623 (setq value (pop plist))
624 (cond ((eq name :char)
627 (cond ((numberp value)
628 (setq value (decode-char '=ucs value)))
630 ;; (setq value (or (find-char value)
633 (char-db-insert-char-spec value readable)
634 (insert line-breaking)
637 (insert (format "%s%s\t%d ; %c%s"
640 (ideographic-radical value)
644 (insert (format "%s%s\t%S" separator name value))
645 (setq separator line-breaking)))
649 (defun char-db-decode-isolated-char (ccs code-point)
652 (cond ((eq ccs 'arabic-iso8859-6)
653 (decode-char ccs code-point))
655 ;; (decode-builtin-char '==gt code-point))
656 ((and (memq ccs '(=gt-pj-1
667 (setq ret (decode-char ccs code-point))
668 (setq ret (encode-char ret '=gt 'defined-only)))
669 (decode-builtin-char '=gt ret))
671 (decode-builtin-char ccs code-point))))
673 (or (decode-char ccs code-point)
674 (define-char (list (cons ccs code-point)))))
675 ((and (<= 0 (char-int ret))
676 (<= (char-int ret) #x1F))
677 (decode-char '=ucs (+ #x2400 (char-int ret))))
678 ((= (char-int ret) #x7F)
682 (defvar char-db-convert-obsolete-format t)
684 (defun char-db-insert-ccs-feature (name value line-breaking)
690 ((memq name '(=>iwds-1
693 =shinjigen@1ed ==shinjigen@1ed
694 =shinjigen@rev ==shinjigen@rev
695 =shinjigen/+p@rev ==shinjigen/+p@rev
696 ===daikanwa/ho ==daikanwa/ho
697 =daikanwa/ho =>>daikanwa/ho =>daikanwa/ho))
698 "(%-18s . %04d)\t; %c")
699 ((eq name '=shinjigen@1ed/24pr)
700 "(%-18s . %04d)\t; %c")
704 ==daikanwa =daikanwa =>>daikanwa =>daikanwa
705 =daikanwa@rev1 =daikanwa@rev2
706 =daikanwa/+p ==daikanwa/+p ===daikanwa/+p
708 =daikanwa/+2p =>>daikanwa/+2p
713 =adobe-japan1-0 ==adobe-japan1-0 ===adobe-japan1-0
714 =adobe-japan1-1 ==adobe-japan1-1 ===adobe-japan1-1
715 =adobe-japan1-2 ==adobe-japan1-2 ===adobe-japan1-2
716 =adobe-japan1-3 ==adobe-japan1-3 ===adobe-japan1-3
717 =adobe-japan1-4 ==adobe-japan1-4 ===adobe-japan1-4
718 =adobe-japan1-5 ==adobe-japan1-5 ===adobe-japan1-5
719 =adobe-japan1-6 ==adobe-japan1-6 ===adobe-japan1-6
720 =>>adobe-japan1-0 =+>adobe-japan1-0
721 =>>adobe-japan1-1 =+>adobe-japan1-1
722 =>>adobe-japan1-2 =+>adobe-japan1-2
723 =>>adobe-japan1-3 =+>adobe-japan1-3
724 =>>adobe-japan1-4 =+>adobe-japan1-4
725 =>>adobe-japan1-5 =+>adobe-japan1-5
726 =>>adobe-japan1-6 =+>adobe-japan1-6
727 =>cbeta =cbeta =>>cbeta ==cbeta ===cbeta
728 =zinbun-oracle =>zinbun-oracle
729 ===hng-jou ===hng-keg ===hng-dng ===hng-mam
730 ===hng-drt ===hng-kgk ===hng-myz ===hng-kda
731 ===hng-khi ===hng-khm ===hng-hok ===hng-kyd ===hng-sok
732 ===hng-yhk ===hng-kak ===hng-kar ===hng-kae
733 ===hng-sys ===hng-tsu ===hng-tzj
734 ===hng-hos ===hng-nak ===hng-jhk
735 ===hng-hod ===hng-gok ===hng-ink ===hng-nto
736 ===hng-nkm ===hng-k24 ===hng-nkk
737 ===hng-kcc ===hng-kcj ===hng-kbk ===hng-sik
738 ===hng-skk ===hng-kyu ===hng-ksk ===hng-wan
739 ===hng-okd ===hng-wad ===hng-kmi
740 ===hng-zkd ===hng-doh ===hng-jyu
741 ===hng-tzs ===hng-kss ===hng-kyo
743 ;; (string-match "^=adobe-" (symbol-name name))
745 "(%-18s . %05d)\t; %c")
746 ((memq name '(=hanyo-denshi/ks
747 ==hanyo-denshi/ks ===hanyo-denshi/ks
750 =mj ==mj ===mj =>>mj =>mj
752 "(%-18s . %06d)\t; %c")
753 ((memq name '(=hanyo-denshi/tk ==hanyo-denshi/tk))
754 "(%-18s . %08d)\t; %c")
755 ((>= (charset-dimension name) 2)
756 "(%-18s . #x%04X)\t; %c")
758 "(%-18s . #x%02X)\t; %c"))
760 (if (= (charset-iso-graphic-plane name) 1)
762 (cond ((= (charset-dimension name) 1)
764 ((= (charset-dimension name) 2)
766 ((= (charset-dimension name) 3)
770 (char-db-decode-isolated-char name value)))
771 (if (and (= (charset-chars name) 94)
772 (= (charset-dimension name) 2))
773 (insert (format " [%02d-%02d]"
774 (- (lsh value -8) 32)
775 (- (logand value 255) 32))))
778 (insert (format "(%-18s . %s)" name value))
780 (insert line-breaking))
782 (defun char-db-insert-relation-feature (char name value line-breaking
784 (insert (format "(%-18s%s " name line-breaking))
785 (let ((lbs (concat "\n" (make-string (current-column) ?\ )))
786 separator cell sources required-features
789 (setq cell (car value))
791 (setq cell (decode-char '=ucs cell)))
793 ((eq name '->subsumptive)
794 (when (or (not (some (lambda (atr)
795 (get-char-attribute cell atr))
796 char-db-ignored-attributes))
798 (encode-char cell ccs 'defined-only))
802 (let ((char-db-ignored-attributes
804 char-db-ignored-attributes)))
805 (insert-char-attributes cell readable nil nil 'for-sub-node))
806 (setq separator lbs))
811 char (intern (format "%s*sources" name))))
812 (setq required-features nil)
813 (dolist (source sources)
817 shinjigen shinjigen@1ed shinjigen@rev))
818 (setq required-features
819 (union required-features
831 =shinjigen/+p@rev))))
833 (setq required-features
834 (union required-features
839 ((find-charset (setq ret (intern (format "=%s" source))))
840 (setq required-features
841 (cons ret required-features)))
842 (t (setq required-features
843 (cons source required-features)))))
844 (cond ((string-match "@JP" (symbol-name name))
845 (setq required-features
846 (union required-features
854 ((string-match "@CN" (symbol-name name))
855 (setq required-features
856 (union required-features
863 (insert (format "%S" cell))
864 (char-db-insert-char-spec cell readable
867 (setq separator lbs))
871 (if (consp (car cell))
872 (char-db-insert-char-spec cell readable)
873 (char-db-insert-char-reference cell readable))
874 (setq separator lbs))
878 (insert (prin1-to-string cell))
879 (setq separator " ")))
880 (setq value (cdr value)))
882 (insert line-breaking)))
884 (defun insert-char-attributes (char &optional readable attributes column
887 (setq column (current-column)))
888 (let (name value ; has-long-ccs-name
892 (concat "\n" (make-string (1+ column) ?\ )))
893 lbs cell separator ret
895 dest-ccss ; sources required-features
900 (if (consp attributes)
902 (dolist (name attributes)
903 (unless (memq name char-db-ignored-attributes)
904 (if (find-charset name)
908 (dolist (name (char-attribute-list))
909 (unless (memq name char-db-ignored-attributes)
910 (if (find-charset name)
914 #'char-attribute-name<)))
916 (when (memq '<-subsumptive attributes)
917 (when (or readable (not for-sub-node))
918 (when (setq value (get-char-attribute char '<-subsumptive))
919 (char-db-insert-relation-feature char '<-subsumptive value
922 (setq attributes (delq '<-subsumptive attributes)))
923 (when (and (memq '<-denotational attributes)
924 (setq value (get-char-attribute char '<-denotational)))
925 (char-db-insert-relation-feature char '<-denotational value
928 (setq attributes (delq '<-denotational attributes)))
929 (when (and (memq '<-denotational@component attributes)
930 (setq value (get-char-attribute char '<-denotational@component)))
931 (char-db-insert-relation-feature char '<-denotational@component value
934 (setq attributes (delq '<-denotational@component attributes)))
935 (when (and (memq 'name attributes)
936 (setq value (get-char-attribute char 'name)))
938 (if (> (+ (current-column) (length value)) 48)
941 value line-breaking))
942 (setq attributes (delq 'name attributes))
944 (when (and (memq 'name* attributes)
945 (setq value (get-char-attribute char 'name*)))
947 (if (> (+ (current-column) (length value)) 48)
950 value line-breaking))
951 (setq attributes (delq 'name* attributes))
953 (when (and (memq 'script attributes)
954 (setq value (get-char-attribute char 'script)))
955 (insert (format "(script\t\t%s)%s"
956 (mapconcat (function prin1-to-string)
959 (setq attributes (delq 'script attributes))
961 (dolist (name '(=>ucs =>ucs*))
962 (when (and (memq name attributes)
963 (setq value (get-char-attribute char name)))
964 (insert (format "(%-18s . #x%04X)\t; %c%s"
965 name value (decode-char '=ucs value)
967 (setq attributes (delq name attributes))))
968 (dolist (name '(=>ucs@gb =>ucs@big5))
969 (when (and (memq name attributes)
970 (setq value (get-char-attribute char name)))
971 (insert (format "(%-18s . #x%04X)\t; %c%s"
976 (symbol-name name) 2)))
979 (setq attributes (delq name attributes))
981 ;; (dolist (name '(=>daikanwa))
982 ;; (when (and (memq name attributes)
983 ;; (setq value (get-char-attribute char name)))
985 ;; (if (integerp value)
986 ;; (format "(%-18s . %05d)\t; %c%s"
987 ;; name value (decode-char '=daikanwa value)
989 ;; (format "(%-18s %s)\t; %c%s"
991 ;; (mapconcat (function prin1-to-string)
993 ;; (char-representative-of-daikanwa char)
995 ;; (setq attributes (delq name attributes))))
996 (when (and (memq 'general-category attributes)
997 (setq value (get-char-attribute char 'general-category)))
999 "(general-category\t%s) ; %s%s"
1000 (mapconcat (lambda (cell)
1003 (cond ((rassoc value unidata-normative-category-alist)
1004 "Normative Category")
1005 ((rassoc value unidata-informative-category-alist)
1006 "Informative Category")
1008 "Unknown Category"))
1010 (setq attributes (delq 'general-category attributes))
1012 (when (and (memq 'bidi-category attributes)
1013 (setq value (get-char-attribute char 'bidi-category)))
1014 (insert (format "(bidi-category\t. %S)%s"
1017 (setq attributes (delq 'bidi-category attributes))
1019 (unless (or (not (memq 'mirrored attributes))
1020 (eq (setq value (get-char-attribute char 'mirrored 'empty))
1022 (insert (format "(mirrored\t\t. %S)%s"
1025 (setq attributes (delq 'mirrored attributes))
1028 ((and (memq 'decimal-digit-value attributes)
1029 (setq value (get-char-attribute char 'decimal-digit-value)))
1030 (insert (format "(decimal-digit-value . %S)%s"
1033 (setq attributes (delq 'decimal-digit-value attributes))
1034 (when (and (memq 'digit-value attributes)
1035 (setq value (get-char-attribute char 'digit-value)))
1036 (insert (format "(digit-value\t . %S)%s"
1039 (setq attributes (delq 'digit-value attributes))
1041 (when (and (memq 'numeric-value attributes)
1042 (setq value (get-char-attribute char 'numeric-value)))
1043 (insert (format "(numeric-value\t . %S)%s"
1046 (setq attributes (delq 'numeric-value attributes))
1050 (when (and (memq 'digit-value attributes)
1051 (setq value (get-char-attribute char 'digit-value)))
1052 (insert (format "(digit-value\t. %S)%s"
1055 (setq attributes (delq 'digit-value attributes))
1057 (when (and (memq 'numeric-value attributes)
1058 (setq value (get-char-attribute char 'numeric-value)))
1059 (insert (format "(numeric-value\t. %S)%s"
1062 (setq attributes (delq 'numeric-value attributes))
1064 (when (and (memq 'iso-10646-comment attributes)
1065 (setq value (get-char-attribute char 'iso-10646-comment)))
1066 (insert (format "(iso-10646-comment\t. %S)%s"
1069 (setq attributes (delq 'iso-10646-comment attributes))
1071 (when (and (memq 'morohashi-daikanwa attributes)
1072 (setq value (get-char-attribute char 'morohashi-daikanwa)))
1073 (insert (format "(morohashi-daikanwa\t%s)%s"
1074 (mapconcat (function prin1-to-string) value " ")
1076 (setq attributes (delq 'morohashi-daikanwa attributes))
1080 (when (and (memq 'ideographic-radical attributes)
1081 (setq value (get-char-attribute char 'ideographic-radical)))
1082 (setq radical value)
1083 (insert (format "(ideographic-radical . %S)\t; %c%s"
1085 (ideographic-radical radical)
1087 (setq attributes (delq 'ideographic-radical attributes))
1089 (when (and (memq 'shuowen-radical attributes)
1090 (setq value (get-char-attribute char 'shuowen-radical)))
1091 (insert (format "(shuowen-radical\t. %S)\t; %c%s"
1093 (shuowen-radical value)
1095 (setq attributes (delq 'shuowen-radical attributes))
1100 char-db-feature-domains
1102 (dolist (feature (char-attribute-list))
1103 (setq feature (symbol-name feature))
1105 "\\(radical\\|strokes\\)@\\([^@*]+\\)\\(\\*\\|$\\)"
1107 (setq domain (intern (match-string 2 feature)))
1108 (unless (memq domain dest)
1109 (setq dest (cons domain dest)))))
1110 (sort dest #'string<))))
1111 (setq key (intern (format "%s@%s" 'ideographic-radical domain)))
1112 (when (and (memq key attributes)
1113 (setq value (get-char-attribute char key)))
1114 (setq radical value)
1115 (insert (format "(%s . %S)\t; %c%s"
1118 (ideographic-radical radical)
1120 (setq attributes (delq key attributes))
1122 (setq key (intern (format "%s@%s" 'ideographic-strokes domain)))
1123 (when (and (memq key attributes)
1124 (setq value (get-char-attribute char key)))
1125 (setq strokes value)
1126 (insert (format "(%s . %S)%s"
1130 (setq attributes (delq key attributes))
1132 (setq key (intern (format "%s@%s" 'total-strokes domain)))
1133 (when (and (memq key attributes)
1134 (setq value (get-char-attribute char key)))
1135 (insert (format "(%s . %S)%s"
1139 (setq attributes (delq key attributes))
1141 (dolist (feature '(ideographic-radical
1144 (setq key (intern (format "%s@%s*sources" feature domain)))
1145 (when (and (memq key attributes)
1146 (setq value (get-char-attribute char key)))
1147 (insert (format "(%s%s" key line-breaking))
1148 (dolist (cell value)
1149 (insert (format " %s" cell)))
1151 (insert line-breaking)
1152 (setq attributes (delq key attributes))
1155 (when (and (memq 'ideographic-strokes attributes)
1156 (setq value (get-char-attribute char 'ideographic-strokes)))
1157 (setq strokes value)
1158 (insert (format "(ideographic-strokes . %S)%s"
1161 (setq attributes (delq 'ideographic-strokes attributes))
1163 (when (and (memq 'kangxi-radical attributes)
1164 (setq value (get-char-attribute char 'kangxi-radical)))
1165 (unless (eq value radical)
1166 (insert (format "(kangxi-radical\t . %S)\t; %c%s"
1168 (ideographic-radical value)
1171 (setq radical value)))
1172 (setq attributes (delq 'kangxi-radical attributes))
1174 (when (and (memq 'kangxi-strokes attributes)
1175 (setq value (get-char-attribute char 'kangxi-strokes)))
1176 (unless (eq value strokes)
1177 (insert (format "(kangxi-strokes\t . %S)%s"
1181 (setq strokes value)))
1182 (setq attributes (delq 'kangxi-strokes attributes))
1184 ;; (when (and (memq 'japanese-radical attributes)
1185 ;; (setq value (get-char-attribute char 'japanese-radical)))
1186 ;; (unless (eq value radical)
1187 ;; (insert (format "(japanese-radical\t . %S)\t; %c%s"
1189 ;; (ideographic-radical value)
1192 ;; (setq radical value)))
1193 ;; (setq attributes (delq 'japanese-radical attributes))
1195 (when (and (memq 'japanese-strokes attributes)
1196 (setq value (get-char-attribute char 'japanese-strokes)))
1197 (unless (eq value strokes)
1198 (insert (format "(japanese-strokes\t . %S)%s"
1202 (setq strokes value)))
1203 (setq attributes (delq 'japanese-strokes attributes))
1205 (when (and (memq 'cns-radical attributes)
1206 (setq value (get-char-attribute char 'cns-radical)))
1207 (insert (format "(cns-radical\t . %S)\t; %c%s"
1209 (ideographic-radical value)
1211 (setq attributes (delq 'cns-radical attributes))
1213 (when (and (memq 'cns-strokes attributes)
1214 (setq value (get-char-attribute char 'cns-strokes)))
1215 (unless (eq value strokes)
1216 (insert (format "(cns-strokes\t . %S)%s"
1220 (setq strokes value)))
1221 (setq attributes (delq 'cns-strokes attributes))
1223 ;; (when (and (memq 'shinjigen-1-radical attributes)
1224 ;; (setq value (get-char-attribute char 'shinjigen-1-radical)))
1225 ;; (unless (eq value radical)
1226 ;; (insert (format "(shinjigen-1-radical . %S)\t; %c%s"
1228 ;; (ideographic-radical value)
1231 ;; (setq radical value)))
1232 ;; (setq attributes (delq 'shinjigen-1-radical attributes))
1234 ;; (when (and (memq 'ideographic- attributes)
1235 ;; (setq value (get-char-attribute char 'ideographic-)))
1236 ;; (insert "(ideographic- ")
1237 ;; (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1239 ;; (while (consp value)
1240 ;; (setq cell (car value))
1241 ;; (if (integerp cell)
1242 ;; (setq cell (decode-char '=ucs cell)))
1243 ;; (cond ((characterp cell)
1247 ;; (insert (format "%S" cell))
1248 ;; (char-db-insert-char-spec cell readable))
1249 ;; (setq separator lbs))
1253 ;; (if (consp (car cell))
1254 ;; (char-db-insert-char-spec cell readable)
1255 ;; (char-db-insert-char-reference cell readable))
1256 ;; (setq separator lbs))
1259 ;; (insert separator))
1260 ;; (insert (prin1-to-string cell))
1261 ;; (setq separator " ")))
1262 ;; (setq value (cdr value)))
1264 ;; (insert line-breaking)
1265 ;; (setq attributes (delq 'ideographic- attributes)))
1266 (when (and (memq 'total-strokes attributes)
1267 (setq value (get-char-attribute char 'total-strokes)))
1268 (insert (format "(total-strokes . %S)%s"
1271 (setq attributes (delq 'total-strokes attributes))
1273 ;; (when (and (memq '->ideograph attributes)
1274 ;; (setq value (get-char-attribute char '->ideograph)))
1275 ;; (insert (format "(->ideograph\t%s)%s"
1276 ;; (mapconcat (lambda (code)
1277 ;; (cond ((symbolp code)
1278 ;; (symbol-name code))
1280 ;; (format "#x%04X" code))
1283 ;; line-breaking code))))
1286 ;; (setq attributes (delq '->ideograph attributes))
1288 ;; (when (and (memq '->decomposition attributes)
1289 ;; (setq value (get-char-attribute char '->decomposition)))
1290 ;; (insert (format "(->decomposition\t%s)%s"
1291 ;; (mapconcat (lambda (code)
1292 ;; (cond ((symbolp code)
1293 ;; (symbol-name code))
1294 ;; ((characterp code)
1296 ;; (format "%S" code)
1301 ;; (format "#x%04X" code))
1303 ;; (format "%s%S" line-breaking code))))
1306 ;; (setq attributes (delq '->decomposition attributes))
1308 (if (equal (get-char-attribute char '->titlecase)
1309 (get-char-attribute char '->uppercase))
1310 (setq attributes (delq '->titlecase attributes)))
1311 (when (and (memq '->mojikyo attributes)
1312 (setq value (get-char-attribute char '->mojikyo)))
1313 (insert (format "(->mojikyo\t\t. %06d)\t; %c%s"
1314 value (decode-char 'mojikyo value)
1316 (setq attributes (delq '->mojikyo attributes))
1318 ;; (when (and (memq 'hanyu-dazidian-vol attributes)
1319 ;; (setq value (get-char-attribute char 'hanyu-dazidian-vol)))
1320 ;; (insert (format "(hanyu-dazidian-vol . %d)%s"
1321 ;; value line-breaking))
1322 ;; (setq attributes (delq 'hanyu-dazidian-vol attributes))
1324 ;; (when (and (memq 'hanyu-dazidian-page attributes)
1325 ;; (setq value (get-char-attribute char 'hanyu-dazidian-page)))
1326 ;; (insert (format "(hanyu-dazidian-page . %d)%s"
1327 ;; value line-breaking))
1328 ;; (setq attributes (delq 'hanyu-dazidian-page attributes))
1330 ;; (when (and (memq 'hanyu-dazidian-char attributes)
1331 ;; (setq value (get-char-attribute char 'hanyu-dazidian-char)))
1332 ;; (insert (format "(hanyu-dazidian-char . %d)%s"
1333 ;; value line-breaking))
1334 ;; (setq attributes (delq 'hanyu-dazidian-char attributes))
1337 (dolist (ignored '(composition
1338 ->denotational <-subsumptive ->ucs-unified
1339 ->ideographic-component-forms))
1340 (setq attributes (delq ignored attributes))))
1342 (setq name (car attributes))
1343 (unless (eq (setq value (get-char-attribute char name 'value-is-empty))
1345 (cond ((setq ret (find-charset name))
1346 (setq name (charset-name ret))
1347 (when (not (memq name dest-ccss))
1348 (setq dest-ccss (cons name dest-ccss))
1349 (char-db-insert-ccs-feature name value line-breaking))
1351 ((string-match "^=>ucs@" (symbol-name name))
1352 (insert (format "(%-18s . #x%04X)\t; %c%s"
1353 name value (decode-char '=ucs value)
1356 ((eq name 'jisx0208-1978/4X)
1357 (insert (format "(%-18s . #x%04X)%s"
1363 (not (eq name '->subsumptive))
1364 (not (eq name '->uppercase))
1365 (not (eq name '->lowercase))
1366 (not (eq name '->titlecase))
1367 (not (eq name '->canonical))
1368 (not (eq name '->Bopomofo))
1369 (not (eq name '->mistakable))
1370 (not (eq name '->ideographic-variants))
1371 (null (get-char-attribute
1372 char (intern (format "%s*sources" name))))
1373 (not (string-match "\\*sources$" (symbol-name name)))
1374 (null (get-char-attribute
1375 char (intern (format "%s*note" name))))
1376 (not (string-match "\\*note$" (symbol-name name)))
1377 (or (eq name '<-identical)
1378 (eq name '<-uppercase)
1379 (eq name '<-lowercase)
1380 (eq name '<-titlecase)
1381 (eq name '<-canonical)
1382 (eq name '<-ideographic-variants)
1383 ;; (eq name '<-synonyms)
1384 (string-match "^<-synonyms" (symbol-name name))
1385 (eq name '<-mistakable)
1386 (when (string-match "^->" (symbol-name name))
1388 ((string-match "^->fullwidth" (symbol-name name))
1389 (not (and (consp value)
1390 (characterp (car value))
1392 (car value) '=ucs 'defined-only)))
1397 ((or (eq name 'ideographic-structure)
1398 (eq name 'ideographic-combination)
1399 ;; (eq name 'ideographic-)
1400 (eq name '=decomposition)
1401 (char-feature-base-name= '=decomposition name)
1402 (char-feature-base-name= '=>decomposition name)
1403 ;; (string-match "^=>*decomposition\\(@[^*]+\\)?$"
1404 ;; (symbol-name name))
1405 (string-match "^\\(->\\|<-\\)[^*]*$" (symbol-name name))
1406 (string-match "^\\(->\\|<-\\)[^*]*\\*sources$"
1409 (char-db-insert-relation-feature char name value
1412 ;; ((memq name '(ideograph=
1413 ;; original-ideograph-of
1414 ;; ancient-ideograph-of
1415 ;; vulgar-ideograph-of
1416 ;; wrong-ideograph-of
1417 ;; ;; simplified-ideograph-of
1418 ;; ideographic-variants
1419 ;; ;; ideographic-different-form-of
1421 ;; (insert (format "(%-18s%s " name line-breaking))
1422 ;; (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1424 ;; (while (consp value)
1425 ;; (setq cell (car value))
1426 ;; (if (and (consp cell)
1427 ;; (consp (car cell)))
1431 ;; (char-db-insert-alist cell readable)
1432 ;; (setq separator lbs))
1434 ;; (insert separator))
1435 ;; (insert (prin1-to-string cell))
1436 ;; (setq separator " "))
1437 ;; (setq value (cdr value)))
1439 ;; (insert line-breaking))
1441 (insert (format "(%-18s " name))
1442 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1444 (while (consp value)
1445 (setq cell (car value))
1446 (if (and (consp cell)
1448 (setq ret (condition-case nil
1456 (setq key (car (car rest)))
1457 (if (find-charset key)
1458 (setq cal (cons key cal))
1459 (setq al (cons key al)))
1460 (setq rest (cdr rest)))
1463 (insert-char-attributes ret
1467 (setq separator lbs))
1468 (setq ret (prin1-to-string cell))
1470 (if (< (+ (current-column)
1477 (setq separator " "))
1478 (setq value (cdr value)))
1480 (insert line-breaking))
1482 (insert (format "(%-18s" name))
1483 (setq ret (prin1-to-string value))
1484 (unless (< (+ (current-column)
1488 (insert line-breaking))
1489 (insert " . " ret ")" line-breaking)
1490 ;; (insert (format "(%-18s . %S)%s"
1495 (setq attributes (cdr attributes)))
1498 (defun insert-char-data (char &optional readable
1501 (narrow-to-region (point)(point))
1502 (insert "(define-char
1504 (insert-char-attributes char readable attributes)
1506 (goto-char (point-min))
1507 (while (re-search-forward "[ \t]+$" nil t)
1510 (goto-char (point-min))
1511 (while (re-search-forward "[ \t][ \t][ \t]*" nil t)
1512 (let ((column (current-column))
1513 (indent-tabs-mode t))
1514 (delete-region (match-beginning 0) (point))
1515 (indent-to column)))
1516 (goto-char (point-max))
1517 ;; (tabify (point-min)(point-max))
1520 (defun insert-char-data-with-variant (char &optional printable
1522 script excluded-script)
1523 (insert-char-data char printable)
1524 (let ((variants (char-variants char))
1527 (setq variants (sort variants #'<))
1528 (setq rest variants)
1529 (setq variants (cons char variants))
1531 (setq variant (car rest))
1532 (unless (get-char-attribute variant '<-subsumptive)
1533 (if (and (or (null script)
1534 (null (setq vs (get-char-attribute variant 'script)))
1536 (or (null excluded-script)
1537 (null (setq vs (get-char-attribute variant 'script)))
1538 (not (memq excluded-script vs))))
1539 (unless (and no-ucs-unified (get-char-attribute variant '=ucs))
1540 (insert-char-data variant printable)
1541 (if (setq ret (char-variants variant))
1543 (or (memq (car ret) variants)
1544 ;; (get-char-attribute (car ret) '<-subsumptive)
1545 (setq rest (nconc rest (list (car ret)))))
1546 (setq ret (cdr ret)))))))
1547 (setq rest (cdr rest)))))
1549 (defun insert-char-range-data (min max &optional script excluded-script)
1552 (while (<= code max)
1553 (setq char (decode-char '=ucs code))
1554 (if (encode-char char '=ucs 'defined-only)
1555 (insert-char-data-with-variant char nil 'no-ucs-unified
1556 script excluded-script))
1557 (setq code (1+ code)))))
1559 (defun write-char-range-data-to-file (min max file
1560 &optional script excluded-script)
1561 (let ((coding-system-for-write char-db-file-coding-system))
1563 (insert (format ";; -*- coding: %s -*-\n"
1564 char-db-file-coding-system))
1565 (insert-char-range-data min max script excluded-script)
1566 (write-region (point-min)(point-max) file))))
1568 (defvar what-character-original-window-configuration)
1571 (defun what-char-definition (char)
1572 (interactive (list (char-after)))
1573 (let ((buf (get-buffer-create "*Character Description*"))
1574 (the-buf (current-buffer))
1575 (win-conf (current-window-configuration)))
1577 (make-local-variable 'what-character-original-window-configuration)
1578 (setq what-character-original-window-configuration win-conf)
1579 (setq buffer-read-only nil)
1583 (insert-char-data-with-variant char 'printable)
1584 (unless (char-attribute-alist char)
1585 (insert (format ";; = %c\n"
1586 (let* ((rest (split-char char))
1590 (setq code (logior (lsh code 8)
1592 (decode-char ccs code)))))
1593 ;; (char-db-update-comment)
1594 (set-buffer-modified-p nil)
1595 (view-mode the-buf (lambda (buf)
1596 (set-window-configuration
1597 what-character-original-window-configuration)
1599 (goto-char (point-min)))
1601 (set-window-configuration
1602 what-character-original-window-configuration)
1603 (signal (car err) (cdr err)))))))
1609 (provide 'char-db-util)
1611 ;;; char-db-util.el ends here