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
368 =>big5-cdp-itaiji-001
372 =>ucs-itaiji-001@iwds-1
381 ;;; @ char-db formatters
384 (defun char-db-make-char-spec (char)
386 (cond ((characterp char)
387 (cond ((and (setq ret (encode-char char '=ucs 'defined-only))
388 (not (and (<= #xE000 ret)(<= ret #xF8FF))))
389 (setq char-spec (list (cons '=ucs ret)))
390 (cond ((setq ret (get-char-attribute char 'name))
391 (setq char-spec (cons (cons 'name ret) char-spec))
393 ((setq ret (get-char-attribute char 'name*))
394 (setq char-spec (cons (cons 'name* ret) char-spec))
397 ((encode-char char '=mj 'defined-only)
399 (dolist (ccs (charset-list))
400 (if (and (or (eq ccs '=mj)
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))))
409 ((encode-char char '==mj 'defined-only)
411 (dolist (ccs (charset-list))
412 (if (and (or (eq ccs '==mj)
413 ;; (eq (charset-property ccs 'iso-ir) 177)
414 (string-match "=ucs@" (symbol-name ccs))
416 (setq ccs (charset-name ccs))
417 (null (assq ccs char-spec))
418 (setq ret (encode-char char ccs 'defined-only)))
419 (setq char-spec (cons (cons ccs ret) char-spec))))
421 ((encode-char char '=adobe-japan1 'defined-only)
423 (dolist (ccs (charset-list))
424 (if (and (or (memq ccs
433 ;; (eq (charset-property ccs 'iso-ir) 177)
434 (string-match "=ucs@" (symbol-name ccs))
436 (setq ccs (charset-name ccs))
437 (null (assq ccs char-spec))
438 (setq ret (encode-char char ccs 'defined-only)))
439 (setq char-spec (cons (cons ccs ret) char-spec))))
441 ((encode-char char '==adobe-japan1 'defined-only)
443 (dolist (ccs (charset-list))
444 (if (and (or (memq ccs
453 ;; (eq (charset-property ccs 'iso-ir) 177)
454 (string-match "=ucs@" (symbol-name ccs))
456 (setq ccs (charset-name ccs))
457 (null (assq ccs char-spec))
458 (setq ret (encode-char char ccs 'defined-only)))
459 (setq char-spec (cons (cons ccs ret) char-spec))))
463 (let ((rest char-db-coded-charset-priority-list)
466 (setq ccs (charset-name
467 (find-charset (car rest))))
469 (encode-char char ccs
471 (throw 'tag (cons ccs ret)))
472 (setq rest (cdr rest))))))
473 (setq char-spec (list ret))
474 (dolist (ccs (delq (car ret) (charset-list)))
475 (if (and (or (charset-iso-final-char ccs)
482 (and (eq (charset-property ccs 'iso-ir) 177)
483 (not (eq (charset-name ccs) '=ucs@big5)))
484 ;; (string-match "=ucs@" (symbol-name ccs))
486 (setq ccs (charset-name ccs))
487 (null (assq ccs char-spec))
488 (setq ret (encode-char char ccs 'defined-only)))
489 (setq char-spec (cons (cons ccs ret) char-spec))))
491 (setq char-spec (split-char char)))
492 (cond ((setq ret (get-char-attribute char 'name))
493 (setq char-spec (cons (cons 'name ret) char-spec))
495 ((setq ret (get-char-attribute char 'name*))
496 (setq char-spec (cons (cons 'name* ret) char-spec))
499 ((setq ret (get-char-attribute
500 char 'ideographic-combination))
502 (cons (cons 'ideographic-combination ret)
509 (defun char-db-insert-char-spec (char &optional readable column
512 (setq column (current-column)))
513 (let (char-spec temp-char)
514 (setq char-spec (char-db-make-char-spec char))
515 (unless (or (characterp char) ; char
517 (setq char (find-char char-spec))
519 ;; define temporary character
520 ;; Current implementation is dirty.
521 (setq temp-char (define-char (cons '(ideograph-daikanwa . 0)
523 (remove-char-attribute temp-char 'ideograph-daikanwa)
524 (setq char temp-char))
525 (insert-char-attributes char
527 (union (mapcar #'car char-spec)
531 ;; undefine temporary character
532 ;; Current implementation is dirty.
533 (setq char-spec (char-attribute-alist temp-char))
535 (remove-char-attribute temp-char (car (car char-spec)))
536 (setq char-spec (cdr char-spec))))))
538 (defun char-db-insert-alist (alist &optional readable column)
540 (setq column (current-column)))
542 (concat "\n" (make-string (1+ column) ?\ )))
546 lbs cell rest separator)
549 (setq name (car (car alist))
550 value (cdr (car alist)))
551 (cond ((eq name 'char)
553 (if (setq ret (condition-case nil
561 (setq key (car (car value)))
562 ;; (if (find-charset key)
563 ;; (setq cal (cons key cal))
564 (setq al (cons key al))
566 (setq value (cdr value)))
567 (insert-char-attributes ret
571 (insert (prin1-to-string value)))
573 (insert line-breaking))
575 (insert (format "(%-18s " name))
576 (setq lbs (concat "\n" (make-string (current-column) ?\ )))
578 (setq cell (car value))
579 (if (and (consp cell)
581 (setq ret (condition-case nil
591 (setq key (car (car rest)))
592 ;; (if (find-charset key)
593 ;; (setq cal (cons key cal))
594 (setq al (cons key al))
596 (setq rest (cdr rest)))
599 (insert-char-attributes ret
603 (setq separator lbs))
606 (insert (prin1-to-string cell))
607 (setq separator " "))
608 (setq value (cdr value)))
610 (insert line-breaking))
612 (insert (format "(%-18s . %S)%s"
615 (setq alist (cdr alist))))
618 (defun char-db-insert-char-reference (plist &optional readable column)
620 (setq column (current-column)))
622 (concat "\n" (make-string (1+ column) ?\ )))
627 (setq name (pop plist))
628 (setq value (pop plist))
629 (cond ((eq name :char)
632 (cond ((numberp value)
633 (setq value (decode-char '=ucs value)))
635 ;; (setq value (or (find-char value)
638 (char-db-insert-char-spec value readable)
639 (insert line-breaking)
642 (insert (format "%s%s\t%d ; %c%s"
645 (ideographic-radical value)
649 (insert (format "%s%s\t%S" separator name value))
650 (setq separator line-breaking)))
654 (defun char-db-decode-isolated-char (ccs code-point)
657 (cond ((eq ccs 'arabic-iso8859-6)
658 (decode-char ccs code-point))
660 ;; (decode-builtin-char '==gt code-point))
661 ((and (memq ccs '(=gt-pj-1
672 (setq ret (decode-char ccs code-point))
673 (setq ret (encode-char ret '=gt 'defined-only)))
674 (decode-builtin-char '=gt ret))
676 (decode-builtin-char ccs code-point))))
678 (or (decode-char ccs code-point)
679 (define-char (list (cons ccs code-point)))))
680 ((and (<= 0 (char-int ret))
681 (<= (char-int ret) #x1F))
682 (decode-char '=ucs (+ #x2400 (char-int ret))))
683 ((= (char-int ret) #x7F)
687 (defvar char-db-convert-obsolete-format t)
689 (defun char-db-insert-ccs-feature (name value line-breaking)
695 ((memq name '(=>iwds-1
698 =shinjigen@1ed ==shinjigen@1ed
699 =shinjigen@rev ==shinjigen@rev
700 =shinjigen/+p@rev ==shinjigen/+p@rev
701 ===daikanwa/ho ==daikanwa/ho
702 =daikanwa/ho =>>daikanwa/ho =>daikanwa/ho))
703 "(%-18s . %04d)\t; %c")
704 ((eq name '=shinjigen@1ed/24pr)
705 "(%-18s . %04d)\t; %c")
709 ==daikanwa =daikanwa =>>daikanwa =>daikanwa
710 =daikanwa@rev1 =daikanwa@rev2
711 =daikanwa/+p ==daikanwa/+p ===daikanwa/+p
713 =daikanwa/+2p =>>daikanwa/+2p
718 =adobe-japan1-0 ==adobe-japan1-0 ===adobe-japan1-0
719 =adobe-japan1-1 ==adobe-japan1-1 ===adobe-japan1-1
720 =adobe-japan1-2 ==adobe-japan1-2 ===adobe-japan1-2
721 =adobe-japan1-3 ==adobe-japan1-3 ===adobe-japan1-3
722 =adobe-japan1-4 ==adobe-japan1-4 ===adobe-japan1-4
723 =adobe-japan1-5 ==adobe-japan1-5 ===adobe-japan1-5
724 =adobe-japan1-6 ==adobe-japan1-6 ===adobe-japan1-6
725 =>>adobe-japan1-0 =+>adobe-japan1-0
726 =>>adobe-japan1-1 =+>adobe-japan1-1
727 =>>adobe-japan1-2 =+>adobe-japan1-2
728 =>>adobe-japan1-3 =+>adobe-japan1-3
729 =>>adobe-japan1-4 =+>adobe-japan1-4
730 =>>adobe-japan1-5 =+>adobe-japan1-5
731 =>>adobe-japan1-6 =+>adobe-japan1-6
732 =>cbeta =cbeta =>>cbeta ==cbeta ===cbeta
733 =zinbun-oracle =>zinbun-oracle
734 ===hng-jou ===hng-keg ===hng-dng ===hng-mam
735 ===hng-drt ===hng-kgk ===hng-myz ===hng-kda
736 ===hng-khi ===hng-khm ===hng-hok ===hng-kyd ===hng-sok
737 ===hng-yhk ===hng-kak ===hng-kar ===hng-kae
738 ===hng-sys ===hng-tsu ===hng-tzj
739 ===hng-hos ===hng-nak ===hng-jhk
740 ===hng-hod ===hng-gok ===hng-ink ===hng-nto
741 ===hng-nkm ===hng-k24 ===hng-nkk
742 ===hng-kcc ===hng-kcj ===hng-kbk ===hng-sik
743 ===hng-skk ===hng-kyu ===hng-ksk ===hng-wan
744 ===hng-okd ===hng-wad ===hng-kmi
745 ===hng-zkd ===hng-doh ===hng-jyu
746 ===hng-tzs ===hng-kss ===hng-kyo
748 ;; (string-match "^=adobe-" (symbol-name name))
750 "(%-18s . %05d)\t; %c")
751 ((memq name '(=hanyo-denshi/ks
752 ==hanyo-denshi/ks ===hanyo-denshi/ks
755 =mj ==mj ===mj =>>mj =>mj
757 "(%-18s . %06d)\t; %c")
758 ((memq name '(=hanyo-denshi/tk ==hanyo-denshi/tk))
759 "(%-18s . %08d)\t; %c")
760 ((>= (charset-dimension name) 2)
761 "(%-18s . #x%04X)\t; %c")
763 "(%-18s . #x%02X)\t; %c"))
765 (if (= (charset-iso-graphic-plane name) 1)
767 (cond ((= (charset-dimension name) 1)
769 ((= (charset-dimension name) 2)
771 ((= (charset-dimension name) 3)
775 (char-db-decode-isolated-char name value)))
776 (if (and (= (charset-chars name) 94)
777 (= (charset-dimension name) 2))
778 (insert (format " [%02d-%02d]"
779 (- (lsh value -8) 32)
780 (- (logand value 255) 32))))
783 (insert (format "(%-18s . %s)" name value))
785 (insert line-breaking))
787 (defun char-db-insert-relation-feature (char name value line-breaking
789 (insert (format "(%-18s%s " name line-breaking))
790 (let ((lbs (concat "\n" (make-string (current-column) ?\ )))
791 separator cell sources required-features
794 (setq cell (car value))
796 (setq cell (decode-char '=ucs cell)))
798 ((eq name '->subsumptive)
799 (when (or (not (some (lambda (atr)
800 (get-char-attribute cell atr))
801 char-db-ignored-attributes))
803 (encode-char cell ccs 'defined-only))
807 (let ((char-db-ignored-attributes
809 char-db-ignored-attributes)))
810 (insert-char-attributes cell readable nil nil 'for-sub-node))
811 (setq separator lbs))
816 char (intern (format "%s*sources" name))))
817 (setq required-features nil)
818 (dolist (source sources)
822 shinjigen shinjigen@1ed shinjigen@rev))
823 (setq required-features
824 (union required-features
836 =shinjigen/+p@rev))))
838 (setq required-features
839 (union required-features
844 ((find-charset (setq ret (intern (format "=%s" source))))
845 (setq required-features
846 (cons ret required-features)))
847 (t (setq required-features
848 (cons source required-features)))))
849 (cond ((string-match "@JP" (symbol-name name))
850 (setq required-features
851 (union required-features
859 ((string-match "@CN" (symbol-name name))
860 (setq required-features
861 (union required-features
868 (insert (format "%S" cell))
869 (char-db-insert-char-spec cell readable
872 (setq separator lbs))
876 (if (consp (car cell))
877 (char-db-insert-char-spec cell readable)
878 (char-db-insert-char-reference cell readable))
879 (setq separator lbs))
883 (insert (prin1-to-string cell))
884 (setq separator " ")))
885 (setq value (cdr value)))
887 (insert line-breaking)))
889 (defun insert-char-attributes (char &optional readable attributes column
892 (setq column (current-column)))
893 (let (name value ; has-long-ccs-name
897 (concat "\n" (make-string (1+ column) ?\ )))
898 lbs cell separator ret
900 dest-ccss ; sources required-features
905 (if (consp attributes)
907 (dolist (name attributes)
908 (unless (memq name char-db-ignored-attributes)
909 (if (find-charset name)
913 (dolist (name (char-attribute-list))
914 (unless (memq name char-db-ignored-attributes)
915 (if (find-charset name)
919 #'char-attribute-name<)))
921 (when (memq '<-subsumptive attributes)
922 (when (or readable (not for-sub-node))
923 (when (setq value (get-char-attribute char '<-subsumptive))
924 (char-db-insert-relation-feature char '<-subsumptive value
927 (setq attributes (delq '<-subsumptive attributes)))
928 (when (and (memq '<-denotational attributes)
929 (setq value (get-char-attribute char '<-denotational)))
930 (char-db-insert-relation-feature char '<-denotational value
933 (setq attributes (delq '<-denotational attributes)))
934 (when (and (memq '<-denotational@component attributes)
935 (setq value (get-char-attribute char '<-denotational@component)))
936 (char-db-insert-relation-feature char '<-denotational@component value
939 (setq attributes (delq '<-denotational@component attributes)))
940 (when (and (memq 'name attributes)
941 (setq value (get-char-attribute char 'name)))
943 (if (> (+ (current-column) (length value)) 48)
946 value line-breaking))
947 (setq attributes (delq 'name attributes))
949 (when (and (memq 'name* attributes)
950 (setq value (get-char-attribute char 'name*)))
952 (if (> (+ (current-column) (length value)) 48)
955 value line-breaking))
956 (setq attributes (delq 'name* attributes))
958 (when (and (memq 'script attributes)
959 (setq value (get-char-attribute char 'script)))
960 (insert (format "(script\t\t%s)%s"
961 (mapconcat (function prin1-to-string)
964 (setq attributes (delq 'script attributes))
966 (dolist (name '(=>ucs =>ucs*))
967 (when (and (memq name attributes)
968 (setq value (get-char-attribute char name)))
969 (insert (format "(%-18s . #x%04X)\t; %c%s"
970 name value (decode-char '=ucs value)
972 (setq attributes (delq name attributes))))
973 (dolist (name '(=>ucs@gb =>ucs@big5))
974 (when (and (memq name attributes)
975 (setq value (get-char-attribute char name)))
976 (insert (format "(%-18s . #x%04X)\t; %c%s"
981 (symbol-name name) 2)))
984 (setq attributes (delq name attributes))
986 ;; (dolist (name '(=>daikanwa))
987 ;; (when (and (memq name attributes)
988 ;; (setq value (get-char-attribute char name)))
990 ;; (if (integerp value)
991 ;; (format "(%-18s . %05d)\t; %c%s"
992 ;; name value (decode-char '=daikanwa value)
994 ;; (format "(%-18s %s)\t; %c%s"
996 ;; (mapconcat (function prin1-to-string)
998 ;; (char-representative-of-daikanwa char)
1000 ;; (setq attributes (delq name attributes))))
1001 (when (and (memq 'general-category attributes)
1002 (setq value (get-char-attribute char 'general-category)))
1004 "(general-category\t%s) ; %s%s"
1005 (mapconcat (lambda (cell)
1008 (cond ((rassoc value unidata-normative-category-alist)
1009 "Normative Category")
1010 ((rassoc value unidata-informative-category-alist)
1011 "Informative Category")
1013 "Unknown Category"))
1015 (setq attributes (delq 'general-category attributes))
1017 (when (and (memq 'bidi-category attributes)
1018 (setq value (get-char-attribute char 'bidi-category)))
1019 (insert (format "(bidi-category\t. %S)%s"
1022 (setq attributes (delq 'bidi-category attributes))
1024 (unless (or (not (memq 'mirrored attributes))
1025 (eq (setq value (get-char-attribute char 'mirrored 'empty))
1027 (insert (format "(mirrored\t\t. %S)%s"
1030 (setq attributes (delq 'mirrored attributes))
1033 ((and (memq 'decimal-digit-value attributes)
1034 (setq value (get-char-attribute char 'decimal-digit-value)))
1035 (insert (format "(decimal-digit-value . %S)%s"
1038 (setq attributes (delq 'decimal-digit-value attributes))
1039 (when (and (memq 'digit-value attributes)
1040 (setq value (get-char-attribute char 'digit-value)))
1041 (insert (format "(digit-value\t . %S)%s"
1044 (setq attributes (delq 'digit-value attributes))
1046 (when (and (memq 'numeric-value attributes)
1047 (setq value (get-char-attribute char 'numeric-value)))
1048 (insert (format "(numeric-value\t . %S)%s"
1051 (setq attributes (delq 'numeric-value attributes))
1055 (when (and (memq 'digit-value attributes)
1056 (setq value (get-char-attribute char 'digit-value)))
1057 (insert (format "(digit-value\t. %S)%s"
1060 (setq attributes (delq 'digit-value attributes))
1062 (when (and (memq 'numeric-value attributes)
1063 (setq value (get-char-attribute char 'numeric-value)))
1064 (insert (format "(numeric-value\t. %S)%s"
1067 (setq attributes (delq 'numeric-value attributes))
1069 (when (and (memq 'iso-10646-comment attributes)
1070 (setq value (get-char-attribute char 'iso-10646-comment)))
1071 (insert (format "(iso-10646-comment\t. %S)%s"
1074 (setq attributes (delq 'iso-10646-comment attributes))
1076 (when (and (memq 'morohashi-daikanwa attributes)
1077 (setq value (get-char-attribute char 'morohashi-daikanwa)))
1078 (insert (format "(morohashi-daikanwa\t%s)%s"
1079 (mapconcat (function prin1-to-string) value " ")
1081 (setq attributes (delq 'morohashi-daikanwa attributes))
1085 (when (and (memq 'ideographic-radical attributes)
1086 (setq value (get-char-attribute char 'ideographic-radical)))
1087 (setq radical value)
1088 (insert (format "(ideographic-radical . %S)\t; %c%s"
1090 (ideographic-radical radical)
1092 (setq attributes (delq 'ideographic-radical attributes))
1094 (when (and (memq 'shuowen-radical attributes)
1095 (setq value (get-char-attribute char 'shuowen-radical)))
1096 (insert (format "(shuowen-radical\t. %S)\t; %c%s"
1098 (shuowen-radical value)
1100 (setq attributes (delq 'shuowen-radical attributes))
1105 char-db-feature-domains
1107 (dolist (feature (char-attribute-list))
1108 (setq feature (symbol-name feature))
1110 "\\(radical\\|strokes\\)@\\([^@*]+\\)\\(\\*\\|$\\)"
1112 (setq domain (intern (match-string 2 feature)))
1113 (unless (memq domain dest)
1114 (setq dest (cons domain dest)))))
1115 (sort dest #'string<))))
1116 (setq key (intern (format "%s@%s" 'ideographic-radical domain)))
1117 (when (and (memq key attributes)
1118 (setq value (get-char-attribute char key)))
1119 (setq radical value)
1120 (insert (format "(%s . %S)\t; %c%s"
1123 (ideographic-radical radical)
1125 (setq attributes (delq key attributes))
1127 (setq key (intern (format "%s@%s" 'ideographic-strokes domain)))
1128 (when (and (memq key attributes)
1129 (setq value (get-char-attribute char key)))
1130 (setq strokes value)
1131 (insert (format "(%s . %S)%s"
1135 (setq attributes (delq key attributes))
1137 (setq key (intern (format "%s@%s" 'total-strokes domain)))
1138 (when (and (memq key attributes)
1139 (setq value (get-char-attribute char key)))
1140 (insert (format "(%s . %S)%s"
1144 (setq attributes (delq key attributes))
1146 (dolist (feature '(ideographic-radical
1149 (setq key (intern (format "%s@%s*sources" feature domain)))
1150 (when (and (memq key attributes)
1151 (setq value (get-char-attribute char key)))
1152 (insert (format "(%s%s" key line-breaking))
1153 (dolist (cell value)
1154 (insert (format " %s" cell)))
1156 (insert line-breaking)
1157 (setq attributes (delq key attributes))
1160 (when (and (memq 'ideographic-strokes attributes)
1161 (setq value (get-char-attribute char 'ideographic-strokes)))
1162 (setq strokes value)
1163 (insert (format "(ideographic-strokes . %S)%s"
1166 (setq attributes (delq 'ideographic-strokes attributes))
1168 (when (and (memq 'kangxi-radical attributes)
1169 (setq value (get-char-attribute char 'kangxi-radical)))
1170 (unless (eq value radical)
1171 (insert (format "(kangxi-radical\t . %S)\t; %c%s"
1173 (ideographic-radical value)
1176 (setq radical value)))
1177 (setq attributes (delq 'kangxi-radical attributes))
1179 (when (and (memq 'kangxi-strokes attributes)
1180 (setq value (get-char-attribute char 'kangxi-strokes)))
1181 (unless (eq value strokes)
1182 (insert (format "(kangxi-strokes\t . %S)%s"
1186 (setq strokes value)))
1187 (setq attributes (delq 'kangxi-strokes attributes))
1189 ;; (when (and (memq 'japanese-radical attributes)
1190 ;; (setq value (get-char-attribute char 'japanese-radical)))
1191 ;; (unless (eq value radical)
1192 ;; (insert (format "(japanese-radical\t . %S)\t; %c%s"
1194 ;; (ideographic-radical value)
1197 ;; (setq radical value)))
1198 ;; (setq attributes (delq 'japanese-radical attributes))
1200 (when (and (memq 'japanese-strokes attributes)
1201 (setq value (get-char-attribute char 'japanese-strokes)))
1202 (unless (eq value strokes)
1203 (insert (format "(japanese-strokes\t . %S)%s"
1207 (setq strokes value)))
1208 (setq attributes (delq 'japanese-strokes attributes))
1210 (when (and (memq 'cns-radical attributes)
1211 (setq value (get-char-attribute char 'cns-radical)))
1212 (insert (format "(cns-radical\t . %S)\t; %c%s"
1214 (ideographic-radical value)
1216 (setq attributes (delq 'cns-radical attributes))
1218 (when (and (memq 'cns-strokes attributes)
1219 (setq value (get-char-attribute char 'cns-strokes)))
1220 (unless (eq value strokes)
1221 (insert (format "(cns-strokes\t . %S)%s"
1225 (setq strokes value)))
1226 (setq attributes (delq 'cns-strokes attributes))
1228 ;; (when (and (memq 'shinjigen-1-radical attributes)
1229 ;; (setq value (get-char-attribute char 'shinjigen-1-radical)))
1230 ;; (unless (eq value radical)
1231 ;; (insert (format "(shinjigen-1-radical . %S)\t; %c%s"
1233 ;; (ideographic-radical value)
1236 ;; (setq radical value)))
1237 ;; (setq attributes (delq 'shinjigen-1-radical attributes))
1239 ;; (when (and (memq 'ideographic- attributes)
1240 ;; (setq value (get-char-attribute char 'ideographic-)))
1241 ;; (insert "(ideographic- ")
1242 ;; (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1244 ;; (while (consp value)
1245 ;; (setq cell (car value))
1246 ;; (if (integerp cell)
1247 ;; (setq cell (decode-char '=ucs cell)))
1248 ;; (cond ((characterp cell)
1252 ;; (insert (format "%S" cell))
1253 ;; (char-db-insert-char-spec cell readable))
1254 ;; (setq separator lbs))
1258 ;; (if (consp (car cell))
1259 ;; (char-db-insert-char-spec cell readable)
1260 ;; (char-db-insert-char-reference cell readable))
1261 ;; (setq separator lbs))
1264 ;; (insert separator))
1265 ;; (insert (prin1-to-string cell))
1266 ;; (setq separator " ")))
1267 ;; (setq value (cdr value)))
1269 ;; (insert line-breaking)
1270 ;; (setq attributes (delq 'ideographic- attributes)))
1271 (when (and (memq 'total-strokes attributes)
1272 (setq value (get-char-attribute char 'total-strokes)))
1273 (insert (format "(total-strokes . %S)%s"
1276 (setq attributes (delq 'total-strokes attributes))
1278 ;; (when (and (memq '->ideograph attributes)
1279 ;; (setq value (get-char-attribute char '->ideograph)))
1280 ;; (insert (format "(->ideograph\t%s)%s"
1281 ;; (mapconcat (lambda (code)
1282 ;; (cond ((symbolp code)
1283 ;; (symbol-name code))
1285 ;; (format "#x%04X" code))
1288 ;; line-breaking code))))
1291 ;; (setq attributes (delq '->ideograph attributes))
1293 ;; (when (and (memq '->decomposition attributes)
1294 ;; (setq value (get-char-attribute char '->decomposition)))
1295 ;; (insert (format "(->decomposition\t%s)%s"
1296 ;; (mapconcat (lambda (code)
1297 ;; (cond ((symbolp code)
1298 ;; (symbol-name code))
1299 ;; ((characterp code)
1301 ;; (format "%S" code)
1306 ;; (format "#x%04X" code))
1308 ;; (format "%s%S" line-breaking code))))
1311 ;; (setq attributes (delq '->decomposition attributes))
1313 (if (equal (get-char-attribute char '->titlecase)
1314 (get-char-attribute char '->uppercase))
1315 (setq attributes (delq '->titlecase attributes)))
1316 (when (and (memq '->mojikyo attributes)
1317 (setq value (get-char-attribute char '->mojikyo)))
1318 (insert (format "(->mojikyo\t\t. %06d)\t; %c%s"
1319 value (decode-char 'mojikyo value)
1321 (setq attributes (delq '->mojikyo attributes))
1323 ;; (when (and (memq 'hanyu-dazidian-vol attributes)
1324 ;; (setq value (get-char-attribute char 'hanyu-dazidian-vol)))
1325 ;; (insert (format "(hanyu-dazidian-vol . %d)%s"
1326 ;; value line-breaking))
1327 ;; (setq attributes (delq 'hanyu-dazidian-vol attributes))
1329 ;; (when (and (memq 'hanyu-dazidian-page attributes)
1330 ;; (setq value (get-char-attribute char 'hanyu-dazidian-page)))
1331 ;; (insert (format "(hanyu-dazidian-page . %d)%s"
1332 ;; value line-breaking))
1333 ;; (setq attributes (delq 'hanyu-dazidian-page attributes))
1335 ;; (when (and (memq 'hanyu-dazidian-char attributes)
1336 ;; (setq value (get-char-attribute char 'hanyu-dazidian-char)))
1337 ;; (insert (format "(hanyu-dazidian-char . %d)%s"
1338 ;; value line-breaking))
1339 ;; (setq attributes (delq 'hanyu-dazidian-char attributes))
1342 (dolist (ignored '(composition
1343 ->denotational <-subsumptive ->ucs-unified
1344 ->ideographic-component-forms))
1345 (setq attributes (delq ignored attributes))))
1347 (setq name (car attributes))
1348 (unless (eq (setq value (get-char-attribute char name 'value-is-empty))
1350 (cond ((setq ret (find-charset name))
1351 (setq name (charset-name ret))
1352 (when (not (memq name dest-ccss))
1353 (setq dest-ccss (cons name dest-ccss))
1354 (char-db-insert-ccs-feature name value line-breaking))
1356 ((string-match "^=>ucs@" (symbol-name name))
1357 (insert (format "(%-18s . #x%04X)\t; %c%s"
1358 name value (decode-char '=ucs value)
1361 ((eq name 'jisx0208-1978/4X)
1362 (insert (format "(%-18s . #x%04X)%s"
1368 (not (eq name '->subsumptive))
1369 (not (eq name '->uppercase))
1370 (not (eq name '->lowercase))
1371 (not (eq name '->titlecase))
1372 (not (eq name '->canonical))
1373 (not (eq name '->Bopomofo))
1374 (not (eq name '->mistakable))
1375 (not (eq name '->ideographic-variants))
1376 (null (get-char-attribute
1377 char (intern (format "%s*sources" name))))
1378 (not (string-match "\\*sources$" (symbol-name name)))
1379 (null (get-char-attribute
1380 char (intern (format "%s*note" name))))
1381 (not (string-match "\\*note$" (symbol-name name)))
1382 (or (eq name '<-identical)
1383 (eq name '<-uppercase)
1384 (eq name '<-lowercase)
1385 (eq name '<-titlecase)
1386 (eq name '<-canonical)
1387 (eq name '<-ideographic-variants)
1388 ;; (eq name '<-synonyms)
1389 (string-match "^<-synonyms" (symbol-name name))
1390 (eq name '<-mistakable)
1391 (when (string-match "^->" (symbol-name name))
1393 ((string-match "^->fullwidth" (symbol-name name))
1394 (not (and (consp value)
1395 (characterp (car value))
1397 (car value) '=ucs 'defined-only)))
1402 ((or (eq name 'ideographic-structure)
1403 (eq name 'ideographic-combination)
1404 ;; (eq name 'ideographic-)
1405 (eq name '=decomposition)
1406 (char-feature-base-name= '=decomposition name)
1407 (char-feature-base-name= '=>decomposition name)
1408 ;; (string-match "^=>*decomposition\\(@[^*]+\\)?$"
1409 ;; (symbol-name name))
1410 (string-match "^\\(->\\|<-\\)[^*]*$" (symbol-name name))
1411 (string-match "^\\(->\\|<-\\)[^*]*\\*sources$"
1414 (char-db-insert-relation-feature char name value
1417 ;; ((memq name '(ideograph=
1418 ;; original-ideograph-of
1419 ;; ancient-ideograph-of
1420 ;; vulgar-ideograph-of
1421 ;; wrong-ideograph-of
1422 ;; ;; simplified-ideograph-of
1423 ;; ideographic-variants
1424 ;; ;; ideographic-different-form-of
1426 ;; (insert (format "(%-18s%s " name line-breaking))
1427 ;; (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1429 ;; (while (consp value)
1430 ;; (setq cell (car value))
1431 ;; (if (and (consp cell)
1432 ;; (consp (car cell)))
1436 ;; (char-db-insert-alist cell readable)
1437 ;; (setq separator lbs))
1439 ;; (insert separator))
1440 ;; (insert (prin1-to-string cell))
1441 ;; (setq separator " "))
1442 ;; (setq value (cdr value)))
1444 ;; (insert line-breaking))
1446 (insert (format "(%-18s " name))
1447 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1449 (while (consp value)
1450 (setq cell (car value))
1451 (if (and (consp cell)
1453 (setq ret (condition-case nil
1461 (setq key (car (car rest)))
1462 (if (find-charset key)
1463 (setq cal (cons key cal))
1464 (setq al (cons key al)))
1465 (setq rest (cdr rest)))
1468 (insert-char-attributes ret
1472 (setq separator lbs))
1473 (setq ret (prin1-to-string cell))
1475 (if (< (+ (current-column)
1482 (setq separator " "))
1483 (setq value (cdr value)))
1485 (insert line-breaking))
1487 (insert (format "(%-18s" name))
1488 (setq ret (prin1-to-string value))
1489 (unless (< (+ (current-column)
1493 (insert line-breaking))
1494 (insert " . " ret ")" line-breaking)
1495 ;; (insert (format "(%-18s . %S)%s"
1500 (setq attributes (cdr attributes)))
1503 (defun insert-char-data (char &optional readable
1506 (narrow-to-region (point)(point))
1507 (insert "(define-char
1509 (insert-char-attributes char readable attributes)
1511 (goto-char (point-min))
1512 (while (re-search-forward "[ \t]+$" nil t)
1515 (goto-char (point-min))
1516 (while (re-search-forward "[ \t][ \t][ \t]*" nil t)
1517 (let ((column (current-column))
1518 (indent-tabs-mode t))
1519 (delete-region (match-beginning 0) (point))
1520 (indent-to column)))
1521 (goto-char (point-max))
1522 ;; (tabify (point-min)(point-max))
1525 (defun insert-char-data-with-variant (char &optional printable
1527 script excluded-script)
1528 (insert-char-data char printable)
1529 (let ((variants (char-variants char))
1532 (setq variants (sort variants #'<))
1533 (setq rest variants)
1534 (setq variants (cons char variants))
1536 (setq variant (car rest))
1537 (unless (get-char-attribute variant '<-subsumptive)
1538 (if (and (or (null script)
1539 (null (setq vs (get-char-attribute variant 'script)))
1541 (or (null excluded-script)
1542 (null (setq vs (get-char-attribute variant 'script)))
1543 (not (memq excluded-script vs))))
1544 (unless (and no-ucs-unified (get-char-attribute variant '=ucs))
1545 (insert-char-data variant printable)
1546 (if (setq ret (char-variants variant))
1548 (or (memq (car ret) variants)
1549 ;; (get-char-attribute (car ret) '<-subsumptive)
1550 (setq rest (nconc rest (list (car ret)))))
1551 (setq ret (cdr ret)))))))
1552 (setq rest (cdr rest)))))
1554 (defun insert-char-range-data (min max &optional script excluded-script)
1557 (while (<= code max)
1558 (setq char (decode-char '=ucs code))
1559 (if (encode-char char '=ucs 'defined-only)
1560 (insert-char-data-with-variant char nil 'no-ucs-unified
1561 script excluded-script))
1562 (setq code (1+ code)))))
1564 (defun write-char-range-data-to-file (min max file
1565 &optional script excluded-script)
1566 (let ((coding-system-for-write char-db-file-coding-system))
1568 (insert (format ";; -*- coding: %s -*-\n"
1569 char-db-file-coding-system))
1570 (insert-char-range-data min max script excluded-script)
1571 (write-region (point-min)(point-max) file))))
1573 (defvar what-character-original-window-configuration)
1576 (defun what-char-definition (char)
1577 (interactive (list (char-after)))
1578 (let ((buf (get-buffer-create "*Character Description*"))
1579 (the-buf (current-buffer))
1580 (win-conf (current-window-configuration)))
1582 (make-local-variable 'what-character-original-window-configuration)
1583 (setq what-character-original-window-configuration win-conf)
1584 (setq buffer-read-only nil)
1588 (insert-char-data-with-variant char 'printable)
1589 (unless (char-attribute-alist char)
1590 (insert (format ";; = %c\n"
1591 (let* ((rest (split-char char))
1595 (setq code (logior (lsh code 8)
1597 (decode-char ccs code)))))
1598 ;; (char-db-update-comment)
1599 (set-buffer-modified-p nil)
1600 (view-mode the-buf (lambda (buf)
1601 (set-window-configuration
1602 what-character-original-window-configuration)
1604 (goto-char (point-min)))
1606 (set-window-configuration
1607 what-character-original-window-configuration)
1608 (signal (car err) (cdr err)))))))
1614 (provide 'char-db-util)
1616 ;;; char-db-util.el ends here