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 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
360 =>big5-cdp-itaiji-001
367 ;;; @ char-db formatters
370 (defun char-db-make-char-spec (char)
372 (cond ((characterp char)
373 (cond ((and (setq ret (encode-char char '=ucs 'defined-only))
374 (not (and (<= #xE000 ret)(<= ret #xF8FF))))
375 (setq char-spec (list (cons '=ucs ret)))
376 (cond ((setq ret (get-char-attribute char 'name))
377 (setq char-spec (cons (cons 'name ret) char-spec))
379 ((setq ret (get-char-attribute char 'name*))
380 (setq char-spec (cons (cons 'name* ret) char-spec))
383 ((encode-char char '=mj 'defined-only)
385 (dolist (ccs (charset-list))
386 (if (and (or (eq ccs '=mj)
387 ;; (eq (charset-property ccs 'iso-ir) 177)
388 (string-match "=ucs@" (symbol-name ccs))
390 (setq ccs (charset-name ccs))
391 (null (assq ccs char-spec))
392 (setq ret (encode-char char ccs 'defined-only)))
393 (setq char-spec (cons (cons ccs ret) char-spec))))
395 ((encode-char char '==mj 'defined-only)
397 (dolist (ccs (charset-list))
398 (if (and (or (eq ccs '==mj)
399 ;; (eq (charset-property ccs 'iso-ir) 177)
400 (string-match "=ucs@" (symbol-name ccs))
402 (setq ccs (charset-name ccs))
403 (null (assq ccs char-spec))
404 (setq ret (encode-char char ccs 'defined-only)))
405 (setq char-spec (cons (cons ccs ret) char-spec))))
407 ((encode-char char '=adobe-japan1 'defined-only)
409 (dolist (ccs (charset-list))
410 (if (and (or (memq ccs
419 ;; (eq (charset-property ccs 'iso-ir) 177)
420 (string-match "=ucs@" (symbol-name ccs))
422 (setq ccs (charset-name ccs))
423 (null (assq ccs char-spec))
424 (setq ret (encode-char char ccs 'defined-only)))
425 (setq char-spec (cons (cons ccs ret) char-spec))))
427 ((encode-char char '==adobe-japan1 'defined-only)
429 (dolist (ccs (charset-list))
430 (if (and (or (memq ccs
439 ;; (eq (charset-property ccs 'iso-ir) 177)
440 (string-match "=ucs@" (symbol-name ccs))
442 (setq ccs (charset-name ccs))
443 (null (assq ccs char-spec))
444 (setq ret (encode-char char ccs 'defined-only)))
445 (setq char-spec (cons (cons ccs ret) char-spec))))
449 (let ((rest char-db-coded-charset-priority-list)
452 (setq ccs (charset-name
453 (find-charset (car rest))))
455 (encode-char char ccs
457 (throw 'tag (cons ccs ret)))
458 (setq rest (cdr rest))))))
459 (setq char-spec (list ret))
460 (dolist (ccs (delq (car ret) (charset-list)))
461 (if (and (or (charset-iso-final-char ccs)
468 (eq (charset-property ccs 'iso-ir) 177)
469 ;; (string-match "=ucs@" (symbol-name ccs))
471 (setq ccs (charset-name ccs))
472 (null (assq ccs char-spec))
473 (setq ret (encode-char char ccs 'defined-only)))
474 (setq char-spec (cons (cons ccs ret) char-spec))))
476 (setq char-spec (split-char char)))
477 (cond ((setq ret (get-char-attribute char 'name))
478 (setq char-spec (cons (cons 'name ret) char-spec))
480 ((setq ret (get-char-attribute char 'name*))
481 (setq char-spec (cons (cons 'name* ret) char-spec))
484 ((setq ret (get-char-attribute
485 char 'ideographic-combination))
487 (cons (cons 'ideographic-combination ret)
494 (defun char-db-insert-char-spec (char &optional readable column
497 (setq column (current-column)))
498 (let (char-spec temp-char)
499 (setq char-spec (char-db-make-char-spec char))
500 (unless (or (characterp char) ; char
502 (setq char (find-char char-spec))
504 ;; define temporary character
505 ;; Current implementation is dirty.
506 (setq temp-char (define-char (cons '(ideograph-daikanwa . 0)
508 (remove-char-attribute temp-char 'ideograph-daikanwa)
509 (setq char temp-char))
510 (insert-char-attributes char
512 (union (mapcar #'car char-spec)
516 ;; undefine temporary character
517 ;; Current implementation is dirty.
518 (setq char-spec (char-attribute-alist temp-char))
520 (remove-char-attribute temp-char (car (car char-spec)))
521 (setq char-spec (cdr char-spec))))))
523 (defun char-db-insert-alist (alist &optional readable column)
525 (setq column (current-column)))
527 (concat "\n" (make-string (1+ column) ?\ )))
531 lbs cell rest separator)
534 (setq name (car (car alist))
535 value (cdr (car alist)))
536 (cond ((eq name 'char)
538 (if (setq ret (condition-case nil
546 (setq key (car (car value)))
547 ;; (if (find-charset key)
548 ;; (setq cal (cons key cal))
549 (setq al (cons key al))
551 (setq value (cdr value)))
552 (insert-char-attributes ret
556 (insert (prin1-to-string value)))
558 (insert line-breaking))
560 (insert (format "(%-18s " name))
561 (setq lbs (concat "\n" (make-string (current-column) ?\ )))
563 (setq cell (car value))
564 (if (and (consp cell)
566 (setq ret (condition-case nil
576 (setq key (car (car rest)))
577 ;; (if (find-charset key)
578 ;; (setq cal (cons key cal))
579 (setq al (cons key al))
581 (setq rest (cdr rest)))
584 (insert-char-attributes ret
588 (setq separator lbs))
591 (insert (prin1-to-string cell))
592 (setq separator " "))
593 (setq value (cdr value)))
595 (insert line-breaking))
597 (insert (format "(%-18s . %S)%s"
600 (setq alist (cdr alist))))
603 (defun char-db-insert-char-reference (plist &optional readable column)
605 (setq column (current-column)))
607 (concat "\n" (make-string (1+ column) ?\ )))
612 (setq name (pop plist))
613 (setq value (pop plist))
614 (cond ((eq name :char)
617 (cond ((numberp value)
618 (setq value (decode-char '=ucs value)))
620 ;; (setq value (or (find-char value)
623 (char-db-insert-char-spec value readable)
624 (insert line-breaking)
627 (insert (format "%s%s\t%d ; %c%s"
630 (ideographic-radical value)
634 (insert (format "%s%s\t%S" separator name value))
635 (setq separator line-breaking)))
639 (defun char-db-decode-isolated-char (ccs code-point)
642 (cond ((eq ccs 'arabic-iso8859-6)
643 (decode-char ccs code-point))
645 ;; (decode-builtin-char '==gt code-point))
646 ((and (memq ccs '(=gt-pj-1
657 (setq ret (decode-char ccs code-point))
658 (setq ret (encode-char ret '=gt 'defined-only)))
659 (decode-builtin-char '=gt ret))
661 (decode-builtin-char ccs code-point))))
663 (or (decode-char ccs code-point)
664 (define-char (list (cons ccs code-point)))))
665 ((and (<= 0 (char-int ret))
666 (<= (char-int ret) #x1F))
667 (decode-char '=ucs (+ #x2400 (char-int ret))))
668 ((= (char-int ret) #x7F)
672 (defvar char-db-convert-obsolete-format t)
674 (defun char-db-insert-ccs-feature (name value line-breaking)
680 ((memq name '(=>iwds-1
683 =shinjigen@1ed ==shinjigen@1ed
684 =shinjigen@rev ==shinjigen@rev
685 =shinjigen/+p@rev ==shinjigen/+p@rev
686 ===daikanwa/ho ==daikanwa/ho
687 =daikanwa/ho =>>daikanwa/ho =>daikanwa/ho))
688 "(%-18s . %04d)\t; %c")
689 ((eq name '=shinjigen@1ed/24pr)
690 "(%-18s . %04d)\t; %c")
694 ==daikanwa =daikanwa =>>daikanwa =>daikanwa
695 =daikanwa@rev1 =daikanwa@rev2
696 =daikanwa/+p ==daikanwa/+p ===daikanwa/+p
698 =daikanwa/+2p =>>daikanwa/+2p
703 =adobe-japan1-0 ==adobe-japan1-0 ===adobe-japan1-0
704 =adobe-japan1-1 ==adobe-japan1-1 ===adobe-japan1-1
705 =adobe-japan1-2 ==adobe-japan1-2 ===adobe-japan1-2
706 =adobe-japan1-3 ==adobe-japan1-3 ===adobe-japan1-3
707 =adobe-japan1-4 ==adobe-japan1-4 ===adobe-japan1-4
708 =adobe-japan1-5 ==adobe-japan1-5 ===adobe-japan1-5
709 =adobe-japan1-6 ==adobe-japan1-6 ===adobe-japan1-6
710 =>>adobe-japan1-0 =+>adobe-japan1-0
711 =>>adobe-japan1-1 =+>adobe-japan1-1
712 =>>adobe-japan1-2 =+>adobe-japan1-2
713 =>>adobe-japan1-3 =+>adobe-japan1-3
714 =>>adobe-japan1-4 =+>adobe-japan1-4
715 =>>adobe-japan1-5 =+>adobe-japan1-5
716 =>>adobe-japan1-6 =+>adobe-japan1-6
717 =>cbeta =cbeta =>>cbeta ==cbeta ===cbeta
718 =zinbun-oracle =>zinbun-oracle
719 ===hng-jou ===hng-keg ===hng-dng ===hng-mam
720 ===hng-drt ===hng-kgk ===hng-myz ===hng-kda
721 ===hng-khi ===hng-khm ===hng-hok ===hng-kyd ===hng-sok
722 ===hng-yhk ===hng-kak ===hng-kar ===hng-kae
723 ===hng-sys ===hng-tsu ===hng-tzj
724 ===hng-hos ===hng-nak ===hng-jhk
725 ===hng-hod ===hng-gok ===hng-ink ===hng-nto
726 ===hng-nkm ===hng-k24 ===hng-nkk
727 ===hng-kcc ===hng-kcj ===hng-kbk ===hng-sik
728 ===hng-skk ===hng-kyu ===hng-ksk ===hng-wan
729 ===hng-okd ===hng-wad ===hng-kmi
730 ===hng-zkd ===hng-doh ===hng-jyu
731 ===hng-tzs ===hng-kss ===hng-kyo
733 ;; (string-match "^=adobe-" (symbol-name name))
735 "(%-18s . %05d)\t; %c")
736 ((memq name '(=hanyo-denshi/ks
737 ==hanyo-denshi/ks ===hanyo-denshi/ks
740 =mj ==mj ===mj =>>mj =>mj
742 "(%-18s . %06d)\t; %c")
743 ((memq name '(=hanyo-denshi/tk ==hanyo-denshi/tk))
744 "(%-18s . %08d)\t; %c")
745 ((>= (charset-dimension name) 2)
746 "(%-18s . #x%04X)\t; %c")
748 "(%-18s . #x%02X)\t; %c"))
750 (if (= (charset-iso-graphic-plane name) 1)
752 (cond ((= (charset-dimension name) 1)
754 ((= (charset-dimension name) 2)
756 ((= (charset-dimension name) 3)
760 (char-db-decode-isolated-char name value)))
761 (if (and (= (charset-chars name) 94)
762 (= (charset-dimension name) 2))
763 (insert (format " [%02d-%02d]"
764 (- (lsh value -8) 32)
765 (- (logand value 255) 32))))
768 (insert (format "(%-18s . %s)" name value))
770 (insert line-breaking))
772 (defun char-db-insert-relation-feature (char name value line-breaking
774 (insert (format "(%-18s%s " name line-breaking))
775 (let ((lbs (concat "\n" (make-string (current-column) ?\ )))
776 separator cell sources required-features
778 (if (characterp value)
779 (setq value (list value)))
781 (setq cell (car value))
783 (setq cell (decode-char '=ucs cell)))
785 ((eq name '->subsumptive)
786 (when (or (not (some (lambda (atr)
787 (get-char-attribute cell atr))
788 char-db-ignored-attributes))
790 (encode-char cell ccs 'defined-only))
794 (let ((char-db-ignored-attributes
796 char-db-ignored-attributes)))
797 (insert-char-attributes cell readable nil nil 'for-sub-node))
798 (setq separator lbs))
803 char (intern (format "%s*sources" name))))
804 (setq required-features nil)
805 (dolist (source sources)
809 shinjigen shinjigen@1ed shinjigen@rev))
810 (setq required-features
811 (union required-features
823 =shinjigen/+p@rev))))
825 (setq required-features
826 (union required-features
831 ((find-charset (setq ret (intern (format "=%s" source))))
832 (setq required-features
833 (cons ret required-features)))
834 (t (setq required-features
835 (cons source required-features)))))
836 (cond ((string-match "@JP" (symbol-name name))
837 (setq required-features
838 (union required-features
846 ((string-match "@CN" (symbol-name name))
847 (setq required-features
848 (union required-features
855 (insert (format "%S" cell))
856 (char-db-insert-char-spec cell readable
859 (setq separator lbs))
863 (if (consp (car cell))
864 (char-db-insert-char-spec cell readable)
865 (char-db-insert-char-reference cell readable))
866 (setq separator lbs))
870 (insert (prin1-to-string cell))
871 (setq separator " ")))
872 (setq value (cdr value)))
874 (insert line-breaking)))
876 (defun insert-char-attributes (char &optional readable attributes column
879 (setq column (current-column)))
880 (let (name value ; has-long-ccs-name
884 (concat "\n" (make-string (1+ column) ?\ )))
885 lbs cell separator ret
887 dest-ccss ; sources required-features
892 (if (consp attributes)
894 (dolist (name attributes)
895 (unless (memq name char-db-ignored-attributes)
896 (if (find-charset name)
900 (dolist (name (char-attribute-list))
901 (unless (memq name char-db-ignored-attributes)
902 (if (find-charset name)
906 #'char-attribute-name<)))
908 (when (memq '<-subsumptive attributes)
909 (when (or readable (not for-sub-node))
910 (when (setq value (get-char-attribute char '<-subsumptive))
911 (char-db-insert-relation-feature char '<-subsumptive value
914 (setq attributes (delq '<-subsumptive attributes)))
915 (when (and (memq '<-denotational attributes)
916 (setq value (get-char-attribute char '<-denotational)))
917 (char-db-insert-relation-feature char '<-denotational value
920 (setq attributes (delq '<-denotational attributes)))
921 (when (and (memq '<-denotational@component attributes)
922 (setq value (get-char-attribute char '<-denotational@component)))
923 (char-db-insert-relation-feature char '<-denotational@component value
926 (setq attributes (delq '<-denotational@component 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 'name* attributes)
937 (setq value (get-char-attribute char 'name*)))
939 (if (> (+ (current-column) (length value)) 48)
942 value line-breaking))
943 (setq attributes (delq 'name* attributes))
945 (when (and (memq 'script attributes)
946 (setq value (get-char-attribute char 'script)))
947 (insert (format "(script\t\t%s)%s"
948 (mapconcat (function prin1-to-string)
951 (setq attributes (delq 'script attributes))
953 (dolist (name '(=>ucs =>ucs*))
954 (when (and (memq name attributes)
955 (setq value (get-char-attribute char name)))
956 (insert (format "(%-18s . #x%04X)\t; %c%s"
957 name value (decode-char '=ucs value)
959 (setq attributes (delq name attributes))))
960 (dolist (name '(=>ucs@gb =>ucs@big5))
961 (when (and (memq name attributes)
962 (setq value (get-char-attribute char name)))
963 (insert (format "(%-18s . #x%04X)\t; %c%s"
968 (symbol-name name) 2)))
971 (setq attributes (delq name attributes))
973 ;; (dolist (name '(=>daikanwa))
974 ;; (when (and (memq name attributes)
975 ;; (setq value (get-char-attribute char name)))
977 ;; (if (integerp value)
978 ;; (format "(%-18s . %05d)\t; %c%s"
979 ;; name value (decode-char '=daikanwa value)
981 ;; (format "(%-18s %s)\t; %c%s"
983 ;; (mapconcat (function prin1-to-string)
985 ;; (char-representative-of-daikanwa char)
987 ;; (setq attributes (delq name attributes))))
988 (when (and (memq 'general-category attributes)
989 (setq value (get-char-attribute char 'general-category)))
991 "(general-category\t%s) ; %s%s"
992 (mapconcat (lambda (cell)
995 (cond ((rassoc value unidata-normative-category-alist)
996 "Normative Category")
997 ((rassoc value unidata-informative-category-alist)
998 "Informative Category")
1000 "Unknown Category"))
1002 (setq attributes (delq 'general-category attributes))
1004 (when (and (memq 'bidi-category attributes)
1005 (setq value (get-char-attribute char 'bidi-category)))
1006 (insert (format "(bidi-category\t. %S)%s"
1009 (setq attributes (delq 'bidi-category attributes))
1011 (unless (or (not (memq 'mirrored attributes))
1012 (eq (setq value (get-char-attribute char 'mirrored 'empty))
1014 (insert (format "(mirrored\t\t. %S)%s"
1017 (setq attributes (delq 'mirrored attributes))
1020 ((and (memq 'decimal-digit-value attributes)
1021 (setq value (get-char-attribute char 'decimal-digit-value)))
1022 (insert (format "(decimal-digit-value . %S)%s"
1025 (setq attributes (delq 'decimal-digit-value attributes))
1026 (when (and (memq 'digit-value attributes)
1027 (setq value (get-char-attribute char 'digit-value)))
1028 (insert (format "(digit-value\t . %S)%s"
1031 (setq attributes (delq 'digit-value attributes))
1033 (when (and (memq 'numeric-value attributes)
1034 (setq value (get-char-attribute char 'numeric-value)))
1035 (insert (format "(numeric-value\t . %S)%s"
1038 (setq attributes (delq 'numeric-value attributes))
1042 (when (and (memq 'digit-value attributes)
1043 (setq value (get-char-attribute char 'digit-value)))
1044 (insert (format "(digit-value\t. %S)%s"
1047 (setq attributes (delq 'digit-value attributes))
1049 (when (and (memq 'numeric-value attributes)
1050 (setq value (get-char-attribute char 'numeric-value)))
1051 (insert (format "(numeric-value\t. %S)%s"
1054 (setq attributes (delq 'numeric-value attributes))
1056 (when (and (memq 'iso-10646-comment attributes)
1057 (setq value (get-char-attribute char 'iso-10646-comment)))
1058 (insert (format "(iso-10646-comment\t. %S)%s"
1061 (setq attributes (delq 'iso-10646-comment attributes))
1063 (when (and (memq 'morohashi-daikanwa attributes)
1064 (setq value (get-char-attribute char 'morohashi-daikanwa)))
1065 (insert (format "(morohashi-daikanwa\t%s)%s"
1066 (mapconcat (function prin1-to-string) value " ")
1068 (setq attributes (delq 'morohashi-daikanwa attributes))
1072 (when (and (memq 'ideographic-radical attributes)
1073 (setq value (get-char-attribute char 'ideographic-radical)))
1074 (setq radical value)
1075 (insert (format "(ideographic-radical . %S)\t; %c%s"
1077 (ideographic-radical radical)
1079 (setq attributes (delq 'ideographic-radical attributes))
1081 (when (and (memq 'shuowen-radical attributes)
1082 (setq value (get-char-attribute char 'shuowen-radical)))
1083 (insert (format "(shuowen-radical\t. %S)\t; %c%s"
1085 (shuowen-radical value)
1087 (setq attributes (delq 'shuowen-radical attributes))
1092 char-db-feature-domains
1094 (dolist (feature (char-attribute-list))
1095 (setq feature (symbol-name feature))
1097 "\\(radical\\|strokes\\)@\\([^@*]+\\)\\(\\*\\|$\\)"
1099 (setq domain (intern (match-string 2 feature)))
1100 (unless (memq domain dest)
1101 (setq dest (cons domain dest)))))
1102 (sort dest #'string<))))
1103 (setq key (intern (format "%s@%s" 'ideographic-radical domain)))
1104 (when (and (memq key attributes)
1105 (setq value (get-char-attribute char key)))
1106 (setq radical value)
1107 (insert (format "(%s . %S)\t; %c%s"
1110 (ideographic-radical radical)
1112 (setq attributes (delq key attributes))
1114 (setq key (intern (format "%s@%s" 'ideographic-strokes domain)))
1115 (when (and (memq key attributes)
1116 (setq value (get-char-attribute char key)))
1117 (setq strokes value)
1118 (insert (format "(%s . %S)%s"
1122 (setq attributes (delq key attributes))
1124 (setq key (intern (format "%s@%s" 'total-strokes domain)))
1125 (when (and (memq key attributes)
1126 (setq value (get-char-attribute char key)))
1127 (insert (format "(%s . %S)%s"
1131 (setq attributes (delq key attributes))
1133 (dolist (feature '(ideographic-radical
1136 (setq key (intern (format "%s@%s*sources" feature domain)))
1137 (when (and (memq key attributes)
1138 (setq value (get-char-attribute char key)))
1139 (insert (format "(%s%s" key line-breaking))
1140 (dolist (cell value)
1141 (insert (format " %s" cell)))
1143 (insert line-breaking)
1144 (setq attributes (delq key attributes))
1147 (when (and (memq 'ideographic-strokes attributes)
1148 (setq value (get-char-attribute char 'ideographic-strokes)))
1149 (setq strokes value)
1150 (insert (format "(ideographic-strokes . %S)%s"
1153 (setq attributes (delq 'ideographic-strokes attributes))
1155 (when (and (memq 'kangxi-radical attributes)
1156 (setq value (get-char-attribute char 'kangxi-radical)))
1157 (unless (eq value radical)
1158 (insert (format "(kangxi-radical\t . %S)\t; %c%s"
1160 (ideographic-radical value)
1163 (setq radical value)))
1164 (setq attributes (delq 'kangxi-radical attributes))
1166 (when (and (memq 'kangxi-strokes attributes)
1167 (setq value (get-char-attribute char 'kangxi-strokes)))
1168 (unless (eq value strokes)
1169 (insert (format "(kangxi-strokes\t . %S)%s"
1173 (setq strokes value)))
1174 (setq attributes (delq 'kangxi-strokes attributes))
1176 ;; (when (and (memq 'japanese-radical attributes)
1177 ;; (setq value (get-char-attribute char 'japanese-radical)))
1178 ;; (unless (eq value radical)
1179 ;; (insert (format "(japanese-radical\t . %S)\t; %c%s"
1181 ;; (ideographic-radical value)
1184 ;; (setq radical value)))
1185 ;; (setq attributes (delq 'japanese-radical attributes))
1187 (when (and (memq 'japanese-strokes attributes)
1188 (setq value (get-char-attribute char 'japanese-strokes)))
1189 (unless (eq value strokes)
1190 (insert (format "(japanese-strokes\t . %S)%s"
1194 (setq strokes value)))
1195 (setq attributes (delq 'japanese-strokes attributes))
1197 (when (and (memq 'cns-radical attributes)
1198 (setq value (get-char-attribute char 'cns-radical)))
1199 (insert (format "(cns-radical\t . %S)\t; %c%s"
1201 (ideographic-radical value)
1203 (setq attributes (delq 'cns-radical attributes))
1205 (when (and (memq 'cns-strokes attributes)
1206 (setq value (get-char-attribute char 'cns-strokes)))
1207 (unless (eq value strokes)
1208 (insert (format "(cns-strokes\t . %S)%s"
1212 (setq strokes value)))
1213 (setq attributes (delq 'cns-strokes attributes))
1215 ;; (when (and (memq 'shinjigen-1-radical attributes)
1216 ;; (setq value (get-char-attribute char 'shinjigen-1-radical)))
1217 ;; (unless (eq value radical)
1218 ;; (insert (format "(shinjigen-1-radical . %S)\t; %c%s"
1220 ;; (ideographic-radical value)
1223 ;; (setq radical value)))
1224 ;; (setq attributes (delq 'shinjigen-1-radical attributes))
1226 ;; (when (and (memq 'ideographic- attributes)
1227 ;; (setq value (get-char-attribute char 'ideographic-)))
1228 ;; (insert "(ideographic- ")
1229 ;; (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1231 ;; (while (consp value)
1232 ;; (setq cell (car value))
1233 ;; (if (integerp cell)
1234 ;; (setq cell (decode-char '=ucs cell)))
1235 ;; (cond ((characterp cell)
1239 ;; (insert (format "%S" cell))
1240 ;; (char-db-insert-char-spec cell readable))
1241 ;; (setq separator lbs))
1245 ;; (if (consp (car cell))
1246 ;; (char-db-insert-char-spec cell readable)
1247 ;; (char-db-insert-char-reference cell readable))
1248 ;; (setq separator lbs))
1251 ;; (insert separator))
1252 ;; (insert (prin1-to-string cell))
1253 ;; (setq separator " ")))
1254 ;; (setq value (cdr value)))
1256 ;; (insert line-breaking)
1257 ;; (setq attributes (delq 'ideographic- attributes)))
1258 (when (and (memq 'total-strokes attributes)
1259 (setq value (get-char-attribute char 'total-strokes)))
1260 (insert (format "(total-strokes . %S)%s"
1263 (setq attributes (delq 'total-strokes attributes))
1265 ;; (when (and (memq '->ideograph attributes)
1266 ;; (setq value (get-char-attribute char '->ideograph)))
1267 ;; (insert (format "(->ideograph\t%s)%s"
1268 ;; (mapconcat (lambda (code)
1269 ;; (cond ((symbolp code)
1270 ;; (symbol-name code))
1272 ;; (format "#x%04X" code))
1275 ;; line-breaking code))))
1278 ;; (setq attributes (delq '->ideograph attributes))
1280 ;; (when (and (memq '->decomposition attributes)
1281 ;; (setq value (get-char-attribute char '->decomposition)))
1282 ;; (insert (format "(->decomposition\t%s)%s"
1283 ;; (mapconcat (lambda (code)
1284 ;; (cond ((symbolp code)
1285 ;; (symbol-name code))
1286 ;; ((characterp code)
1288 ;; (format "%S" code)
1293 ;; (format "#x%04X" code))
1295 ;; (format "%s%S" line-breaking code))))
1298 ;; (setq attributes (delq '->decomposition attributes))
1300 (if (equal (get-char-attribute char '->titlecase)
1301 (get-char-attribute char '->uppercase))
1302 (setq attributes (delq '->titlecase attributes)))
1303 (when (and (memq '->mojikyo attributes)
1304 (setq value (get-char-attribute char '->mojikyo)))
1305 (insert (format "(->mojikyo\t\t. %06d)\t; %c%s"
1306 value (decode-char 'mojikyo value)
1308 (setq attributes (delq '->mojikyo attributes))
1310 ;; (when (and (memq 'hanyu-dazidian-vol attributes)
1311 ;; (setq value (get-char-attribute char 'hanyu-dazidian-vol)))
1312 ;; (insert (format "(hanyu-dazidian-vol . %d)%s"
1313 ;; value line-breaking))
1314 ;; (setq attributes (delq 'hanyu-dazidian-vol attributes))
1316 ;; (when (and (memq 'hanyu-dazidian-page attributes)
1317 ;; (setq value (get-char-attribute char 'hanyu-dazidian-page)))
1318 ;; (insert (format "(hanyu-dazidian-page . %d)%s"
1319 ;; value line-breaking))
1320 ;; (setq attributes (delq 'hanyu-dazidian-page attributes))
1322 ;; (when (and (memq 'hanyu-dazidian-char attributes)
1323 ;; (setq value (get-char-attribute char 'hanyu-dazidian-char)))
1324 ;; (insert (format "(hanyu-dazidian-char . %d)%s"
1325 ;; value line-breaking))
1326 ;; (setq attributes (delq 'hanyu-dazidian-char attributes))
1329 (dolist (ignored '(composition
1330 ->denotational <-subsumptive ->ucs-unified
1331 ->ideographic-component-forms))
1332 (setq attributes (delq ignored attributes))))
1334 (setq name (car attributes))
1335 (unless (eq (setq value (get-char-attribute char name 'value-is-empty))
1337 (cond ((setq ret (find-charset name))
1338 (setq name (charset-name ret))
1339 (when (not (memq name dest-ccss))
1340 (setq dest-ccss (cons name dest-ccss))
1341 (char-db-insert-ccs-feature name value line-breaking))
1343 ((string-match "^=>ucs@" (symbol-name name))
1344 (insert (format "(%-18s . #x%04X)\t; %c%s"
1345 name value (decode-char '=ucs value)
1348 ((eq name 'jisx0208-1978/4X)
1349 (insert (format "(%-18s . #x%04X)%s"
1355 (not (eq name '->subsumptive))
1356 (not (eq name '->uppercase))
1357 (not (eq name '->lowercase))
1358 (not (eq name '->titlecase))
1359 (not (eq name '->canonical))
1360 (not (eq name '->Bopomofo))
1361 (not (eq name '->mistakable))
1362 (not (eq name '->ideographic-variants))
1363 (null (get-char-attribute
1364 char (intern (format "%s*sources" name))))
1365 (not (string-match "\\*sources$" (symbol-name name)))
1366 (null (get-char-attribute
1367 char (intern (format "%s*note" name))))
1368 (not (string-match "\\*note$" (symbol-name name)))
1369 (or (eq name '<-identical)
1370 (eq name '<-uppercase)
1371 (eq name '<-lowercase)
1372 (eq name '<-titlecase)
1373 (eq name '<-canonical)
1374 (eq name '<-ideographic-variants)
1375 ;; (eq name '<-synonyms)
1376 (string-match "^<-synonyms" (symbol-name name))
1377 (eq name '<-mistakable)
1378 (when (string-match "^->" (symbol-name name))
1380 ((string-match "^->fullwidth" (symbol-name name))
1381 (not (and (consp value)
1382 (characterp (car value))
1384 (car value) '=ucs 'defined-only)))
1389 ((or (eq name 'ideographic-structure)
1390 (eq name 'ideographic-combination)
1391 ;; (eq name 'ideographic-)
1392 (eq name '=decomposition)
1393 (char-feature-base-name= '=decomposition name)
1394 (char-feature-base-name= '=>decomposition name)
1395 ;; (string-match "^=>*decomposition\\(@[^*]+\\)?$"
1396 ;; (symbol-name name))
1397 (string-match "^\\(->\\|<-\\)[^*]*$" (symbol-name name))
1398 (string-match "^\\(->\\|<-\\)[^*]*\\*sources$"
1401 (char-db-insert-relation-feature char name value
1404 ;; ((memq name '(ideograph=
1405 ;; original-ideograph-of
1406 ;; ancient-ideograph-of
1407 ;; vulgar-ideograph-of
1408 ;; wrong-ideograph-of
1409 ;; ;; simplified-ideograph-of
1410 ;; ideographic-variants
1411 ;; ;; ideographic-different-form-of
1413 ;; (insert (format "(%-18s%s " name line-breaking))
1414 ;; (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1416 ;; (while (consp value)
1417 ;; (setq cell (car value))
1418 ;; (if (and (consp cell)
1419 ;; (consp (car cell)))
1423 ;; (char-db-insert-alist cell readable)
1424 ;; (setq separator lbs))
1426 ;; (insert separator))
1427 ;; (insert (prin1-to-string cell))
1428 ;; (setq separator " "))
1429 ;; (setq value (cdr value)))
1431 ;; (insert line-breaking))
1433 (insert (format "(%-18s " name))
1434 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1436 (while (consp value)
1437 (setq cell (car value))
1438 (if (and (consp cell)
1440 (setq ret (condition-case nil
1448 (setq key (car (car rest)))
1449 (if (find-charset key)
1450 (setq cal (cons key cal))
1451 (setq al (cons key al)))
1452 (setq rest (cdr rest)))
1455 (insert-char-attributes ret
1459 (setq separator lbs))
1460 (setq ret (prin1-to-string cell))
1462 (if (< (+ (current-column)
1469 (setq separator " "))
1470 (setq value (cdr value)))
1472 (insert line-breaking))
1474 (insert (format "(%-18s" name))
1475 (setq ret (prin1-to-string value))
1476 (unless (< (+ (current-column)
1480 (insert line-breaking))
1481 (insert " . " ret ")" line-breaking)
1482 ;; (insert (format "(%-18s . %S)%s"
1487 (setq attributes (cdr attributes)))
1490 (defun insert-char-data (char &optional readable
1493 (narrow-to-region (point)(point))
1494 (insert "(define-char
1496 (insert-char-attributes char readable attributes)
1498 (goto-char (point-min))
1499 (while (re-search-forward "[ \t]+$" nil t)
1502 (goto-char (point-min))
1503 (while (re-search-forward "[ \t][ \t][ \t]*" nil t)
1504 (let ((column (current-column))
1505 (indent-tabs-mode t))
1506 (delete-region (match-beginning 0) (point))
1507 (indent-to column)))
1508 (goto-char (point-max))
1509 ;; (tabify (point-min)(point-max))
1512 (defun insert-char-data-with-variant (char &optional printable
1514 script excluded-script)
1515 (insert-char-data char printable)
1516 (let ((variants (char-variants char))
1519 (setq variants (sort variants #'<))
1520 (setq rest variants)
1521 (setq variants (cons char variants))
1523 (setq variant (car rest))
1524 (unless (get-char-attribute variant '<-subsumptive)
1525 (if (and (or (null script)
1526 (null (setq vs (get-char-attribute variant 'script)))
1528 (or (null excluded-script)
1529 (null (setq vs (get-char-attribute variant 'script)))
1530 (not (memq excluded-script vs))))
1531 (unless (and no-ucs-unified (get-char-attribute variant '=ucs))
1532 (insert-char-data variant printable)
1533 (if (setq ret (char-variants variant))
1535 (or (memq (car ret) variants)
1536 ;; (get-char-attribute (car ret) '<-subsumptive)
1537 (setq rest (nconc rest (list (car ret)))))
1538 (setq ret (cdr ret)))))))
1539 (setq rest (cdr rest)))))
1541 (defun insert-char-range-data (min max &optional script excluded-script)
1544 (while (<= code max)
1545 (setq char (decode-char '=ucs code))
1546 (if (encode-char char '=ucs 'defined-only)
1547 (insert-char-data-with-variant char nil 'no-ucs-unified
1548 script excluded-script))
1549 (setq code (1+ code)))))
1551 (defun write-char-range-data-to-file (min max file
1552 &optional script excluded-script)
1553 (let ((coding-system-for-write char-db-file-coding-system))
1555 (insert (format ";; -*- coding: %s -*-\n"
1556 char-db-file-coding-system))
1557 (insert-char-range-data min max script excluded-script)
1558 (write-region (point-min)(point-max) file))))
1560 (defvar what-character-original-window-configuration)
1563 (defun what-char-definition (char)
1564 (interactive (list (char-after)))
1565 (let ((buf (get-buffer-create "*Character Description*"))
1566 (the-buf (current-buffer))
1567 (win-conf (current-window-configuration)))
1569 (make-local-variable 'what-character-original-window-configuration)
1570 (setq what-character-original-window-configuration win-conf)
1571 (setq buffer-read-only nil)
1575 (insert-char-data-with-variant char 'printable)
1576 (unless (char-attribute-alist char)
1577 (insert (format ";; = %c\n"
1578 (let* ((rest (split-char char))
1582 (setq code (logior (lsh code 8)
1584 (decode-char ccs code)))))
1585 ;; (char-db-update-comment)
1586 (set-buffer-modified-p nil)
1587 (view-mode the-buf (lambda (buf)
1588 (set-window-configuration
1589 what-character-original-window-configuration)
1591 (goto-char (point-min)))
1593 (set-window-configuration
1594 what-character-original-window-configuration)
1595 (signal (car err) (cdr err)))))))
1601 (provide 'char-db-util)
1603 ;;; char-db-util.el ends here