1 ;;; char-db-util.el --- Character Database utility -*- coding: utf-8-er; -*-
3 ;; Copyright (C) 1998,1999,2000,2001,2002,2003,2004,2005,2006,2007,
4 ;; 2008,2009,2010,2011,2012,2013,2014,2015 MORIOKA Tomohiko.
6 ;; Author: MORIOKA Tomohiko <tomo@kanji.zinbun.kyoto-u.ac.jp>
7 ;; Keywords: CHISE, Character Database, ISO/IEC 10646, UCS, Unicode, MULE.
9 ;; This file is part of XEmacs CHISE.
11 ;; XEmacs CHISE is free software; you can redistribute it and/or
12 ;; modify it under the terms of the GNU General Public License as
13 ;; published by the Free Software Foundation; either version 2, or (at
14 ;; your option) any later version.
16 ;; XEmacs CHISE is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 ;; General Public License for more details.
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with XEmacs CHISE; see the file COPYING. If not, write to
23 ;; the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
24 ;; Boston, MA 02111-1307, USA.
29 (require 'ideograph-subr)
31 (defconst unidata-normative-category-alist
32 '(("Lu" letter uppercase)
33 ("Ll" letter lowercase)
34 ("Lt" letter titlecase)
35 ("Mn" mark non-spacing)
36 ("Mc" mark spacing-combining)
38 ("Nd" number decimal-digit)
41 ("Zs" separator space)
43 ("Zp" separator paragraph)
46 ("Cs" other surrogate)
47 ("Co" other private-use)
48 ("Cn" other not-assigned)))
50 (defconst unidata-informative-category-alist
51 '(("Lm" letter modifier)
53 ("Pc" punctuation connector)
54 ("Pd" punctuation dash)
55 ("Ps" punctuation open)
56 ("Pe" punctuation close)
57 ("Pi" punctuation initial-quote)
58 ("Pf" punctuation final-quote)
59 ("Po" punctuation other)
61 ("Sc" symbol currency)
62 ("Sk" symbol modifier)
66 (defconst shuowen-radicals
67 [?一 ?上 ?示 ?三 ?王 ?玉 ?玨 ?气 ?士 ?丨 ; 010
68 ?屮 ?艸 ?蓐 ?茻 ?小 ?八 ?釆 ?半 ?牛 ?犛 ; 020
69 ?告 ?口 ?凵 ?吅 ?哭 ?走 ?止 ?癶 ?步 ?此 ; 030
70 ?正 ?是 ?辵 ?彳 ?廴 ?㢟 ?行 ?齒 ?牙 ?足 ; 040
71 ?疋 ?品 ?龠 ?冊 ?㗊 ?舌 ?干 ?谷 ?只 ?㕯 ; 050
72 ?句 ?丩 ?古 ?十 ?卅 ?言 ?誩 ?音 ?䇂 ?丵 ; 060
73 ?菐 ?𠬞 ?𠬜 ?共 ?異 ?舁 ?𦥑 ?䢅 ?爨 ?革 ; 070
74 ?鬲 ?䰜 ?爪 ?𠃨 ?鬥 ?又 ?𠂇 ?㕜 ?支 ?𦘒 ; 080
75 ?聿 ?畫 ?隶 ?臤 ?臣 ?殳 ?殺 ?𠘧 ?寸 ?皮 ; 090
76 ?㼱 ?攴 ?敎 ?卜 ?用 ?爻 ?㸚 ?𥄎 ?目 ?䀠 ; 100
77 ?眉 ?盾 ?自 ?白 ?鼻 ?皕 ?習 ?羽 ?隹 ?奞 ; 110
78 ?萑 ?𦫳 ?苜 ?羊 ?羴 ?瞿 ?雔 ?雥 ?鳥 ?烏 ; 120
79 ?𠦒 ?冓 ?幺 ?𢆶 ?叀 ?玄 ?予 ?放 ?𠬪 ?𣦼 ; 130
80 ?歺 ?死 ?冎 ?骨 ?肉 ?筋 ?刀 ?刃 ?㓞 ?丰 ; 140
81 ?耒 ?𧢲 ?竹 ?箕 ?丌 ?左 ?工 ?㠭 ?巫 ?甘 ; 150
82 ?曰 ?乃 ?丂 ?可 ?兮 ?号 ?亏 ?旨 ?喜 ?壴 ; 160
83 ; ?旨 ?曰 ?乃 ?丂 ?可 ?兮 ?号 ?亏 ?喜 ?壴 ; 160
84 ?鼓 ?豈 ?豆 ?豊 ?豐 ?䖒 ?虍 ?虎 ?虤 ?皿 ; 170
85 ?𠙴 ?去 ?血 ?丶 ?丹 ?青 ?井 ?皀 ?鬯 ?食 ; 180
86 ?亼 ?會 ?倉 ?入 ?缶 ?矢 ?高 ?冂 ?𩫏 ?京 ; 190
87 ?亯 ?𣆪 ?畗 ?㐭 ?嗇 ?來 ?麥 ?夊 ?舛 ?䑞 ; 200
88 ?韋 ?弟 ?夂 ?久 ?桀 ?木 ?東 ?林 ?才 ?叒 ; 210
89 ?之 ?帀 ?出 ?𣎵 ?生 ?乇 ?𠂹 ?𠌶 ?華 ?𥝌 ; 220
90 ?稽 ?巢 ?桼 ?束 ?㯻 ?囗 ?員 ?貝 ?邑 ?𨛜 ; 230
91 ?日 ?旦 ?倝 ?㫃 ?冥 ?晶 ?月 ?有 ?明 ?囧 ; 240
92 ?夕 ?多 ?毌 ?𢎘 ?𣐺 ?卣 ?齊 ?朿 ?片 ?鼎 ; 250
93 ?克 ?彔 ?禾 ?秝 ?黍 ?香 ?米 ?毇 ?臼 ?凶 ; 260
94 ?𣎳 ?林 ?麻 ?尗 ?耑 ?韭 ?瓜 ?瓠 ?宀 ?宮 ; 270
95 ?呂 ?穴 ?㝱 ?𤕫 ?冖 ?𠔼 ?冃 ?㒳 ?网 ?襾 ; 280
96 ?巾 ?巿 ?帛 ?白 ?㡀 ?黹 ?人 ?𠤎 ?匕 ?从 ; 290
97 ?比 ?北 ?丘 ?㐺 ?𡈼 ?重 ?臥 ?身 ?㐆 ?衣 ; 300
98 ?裘 ?老 ?毛 ?毳 ?尸 ?尺 ?尾 ?履 ?舟 ?方 ; 310
99 ?儿 ?兄 ?兂 ?皃 ?𠑹 ?先 ?秃 ?見 ?覞 ?欠 ; 320
100 ?㱃 ?㳄 ?旡 ?頁 ?𦣻 ?面 ?丏 ?首 ?𥄉 ?須 ; 330
101 ?彡 ?彣 ?文 ?髟 ?后 ?司 ?卮 ?卩 ?印 ?色 ; 340
102 ?𠨍 ?辟 ?勹 ?包 ?茍 ?鬼 ?甶 ?厶 ?嵬 ?山 ; 350
103 ?屾 ?屵 ?广 ?厂 ?丸 ?危 ?石 ?長 ?勿 ?冄 ; 360
104 ?而 ?豕 ?㣇 ?彑 ?豚 ?豸 ?𤉡 ?易 ?象 ?馬 ; 370
105 ?𢊁 ?鹿 ?麤 ?㲋 ?兔 ?萈 ?犬 ?㹜 ?鼠 ?能 ; 380
106 ?熊 ?火 ?炎 ?黑 ?囪 ?焱 ?炙 ?赤 ?大 ?亦 ; 390
109 (defun shuowen-radical (number)
110 (aref shuowen-radicals (1- number)))
112 (defvar char-db-file-coding-system 'utf-8-mcs-er)
114 (defvar char-db-ignored-attributes '(ideographic-products))
116 (defvar char-db-coded-charset-priority-list
210 ;; =>>>adobe-japan1-0
211 ;; =>>>adobe-japan1-1
212 ;; =>>>adobe-japan1-2
213 ;; =>>>adobe-japan1-3
214 ;; =>>>adobe-japan1-4
215 ;; =>>>adobe-japan1-5
216 ;; =>>>adobe-japan1-6
220 ;; =>>>hanyo-denshi/ja
221 ;; =>>>hanyo-denshi/jb
222 ;; =>>>hanyo-denshi/jc
223 ;; =>>>hanyo-denshi/ft
224 ;; =>>>hanyo-denshi/ib
225 ;; =>>>hanyo-denshi/hg
226 ;; =>>>hanyo-denshi/jt
227 ;; =>>>hanyo-denshi/ks
341 ;;; @ char-db formatters
344 (defun char-db-make-char-spec (char)
346 (cond ((characterp char)
347 (cond ((and (setq ret (encode-char char '=ucs 'defined-only))
348 (not (and (<= #xE000 ret)(<= ret #xF8FF))))
349 (setq char-spec (list (cons '=ucs ret)))
350 (cond ((setq ret (get-char-attribute char 'name))
351 (setq char-spec (cons (cons 'name ret) char-spec))
353 ((setq ret (get-char-attribute char 'name*))
354 (setq char-spec (cons (cons 'name* ret) char-spec))
357 ((encode-char char '=mj 'defined-only)
359 (dolist (ccs (charset-list))
360 (if (and (or (eq ccs '=mj)
361 ;; (eq (charset-property ccs 'iso-ir) 177)
362 (string-match "=ucs@" (symbol-name ccs))
364 (setq ccs (charset-name ccs))
365 (null (assq ccs char-spec))
366 (setq ret (encode-char char ccs 'defined-only)))
367 (setq char-spec (cons (cons ccs ret) char-spec))))
369 ((encode-char char '==mj 'defined-only)
371 (dolist (ccs (charset-list))
372 (if (and (or (eq ccs '==mj)
373 ;; (eq (charset-property ccs 'iso-ir) 177)
374 (string-match "=ucs@" (symbol-name ccs))
376 (setq ccs (charset-name ccs))
377 (null (assq ccs char-spec))
378 (setq ret (encode-char char ccs 'defined-only)))
379 (setq char-spec (cons (cons ccs ret) char-spec))))
381 ((encode-char char '=adobe-japan1 'defined-only)
383 (dolist (ccs (charset-list))
384 (if (and (or (memq ccs
393 ;; (eq (charset-property ccs 'iso-ir) 177)
394 (string-match "=ucs@" (symbol-name ccs))
396 (setq ccs (charset-name ccs))
397 (null (assq ccs char-spec))
398 (setq ret (encode-char char ccs 'defined-only)))
399 (setq char-spec (cons (cons ccs ret) char-spec))))
401 ((encode-char char '==adobe-japan1 'defined-only)
403 (dolist (ccs (charset-list))
404 (if (and (or (memq ccs
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))))
423 (let ((rest char-db-coded-charset-priority-list)
426 (setq ccs (charset-name
427 (find-charset (car rest))))
429 (encode-char char ccs
431 (throw 'tag (cons ccs ret)))
432 (setq rest (cdr rest))))))
433 (setq char-spec (list ret))
434 (dolist (ccs (delq (car ret) (charset-list)))
435 (if (and (or (charset-iso-final-char ccs)
442 (eq (charset-property ccs 'iso-ir) 177)
443 ;; (string-match "=ucs@" (symbol-name ccs))
445 (setq ccs (charset-name ccs))
446 (null (assq ccs char-spec))
447 (setq ret (encode-char char ccs 'defined-only)))
448 (setq char-spec (cons (cons ccs ret) char-spec))))
450 (setq char-spec (split-char char)))
451 (cond ((setq ret (get-char-attribute char 'name))
452 (setq char-spec (cons (cons 'name ret) char-spec))
454 ((setq ret (get-char-attribute char 'name*))
455 (setq char-spec (cons (cons 'name* ret) char-spec))
458 ((setq ret (get-char-attribute
459 char 'ideographic-combination))
461 (cons (cons 'ideographic-combination ret)
468 (defun char-db-insert-char-spec (char &optional readable column
471 (setq column (current-column)))
472 (let (char-spec temp-char)
473 (setq char-spec (char-db-make-char-spec char))
474 (unless (or (characterp char) ; char
476 (setq char (find-char char-spec))
478 ;; define temporary character
479 ;; Current implementation is dirty.
480 (setq temp-char (define-char (cons '(ideograph-daikanwa . 0)
482 (remove-char-attribute temp-char 'ideograph-daikanwa)
483 (setq char temp-char))
484 (insert-char-attributes char
486 (union (mapcar #'car char-spec)
490 ;; undefine temporary character
491 ;; Current implementation is dirty.
492 (setq char-spec (char-attribute-alist temp-char))
494 (remove-char-attribute temp-char (car (car char-spec)))
495 (setq char-spec (cdr char-spec))))))
497 (defun char-db-insert-alist (alist &optional readable column)
499 (setq column (current-column)))
501 (concat "\n" (make-string (1+ column) ?\ )))
505 lbs cell rest separator)
508 (setq name (car (car alist))
509 value (cdr (car alist)))
510 (cond ((eq name 'char)
512 (if (setq ret (condition-case nil
520 (setq key (car (car value)))
521 ;; (if (find-charset key)
522 ;; (setq cal (cons key cal))
523 (setq al (cons key al))
525 (setq value (cdr value)))
526 (insert-char-attributes ret
530 (insert (prin1-to-string value)))
532 (insert line-breaking))
534 (insert (format "(%-18s " name))
535 (setq lbs (concat "\n" (make-string (current-column) ?\ )))
537 (setq cell (car value))
538 (if (and (consp cell)
540 (setq ret (condition-case nil
550 (setq key (car (car rest)))
551 ;; (if (find-charset key)
552 ;; (setq cal (cons key cal))
553 (setq al (cons key al))
555 (setq rest (cdr rest)))
558 (insert-char-attributes ret
562 (setq separator lbs))
565 (insert (prin1-to-string cell))
566 (setq separator " "))
567 (setq value (cdr value)))
569 (insert line-breaking))
571 (insert (format "(%-18s . %S)%s"
574 (setq alist (cdr alist))))
577 (defun char-db-insert-char-reference (plist &optional readable column)
579 (setq column (current-column)))
581 (concat "\n" (make-string (1+ column) ?\ )))
586 (setq name (pop plist))
587 (setq value (pop plist))
588 (cond ((eq name :char)
591 (cond ((numberp value)
592 (setq value (decode-char '=ucs value)))
594 ;; (setq value (or (find-char value)
597 (char-db-insert-char-spec value readable)
598 (insert line-breaking)
601 (insert (format "%s%s\t%d ; %c%s"
604 (ideographic-radical value)
608 (insert (format "%s%s\t%S" separator name value))
609 (setq separator line-breaking)))
613 (defun char-db-decode-isolated-char (ccs code-point)
616 (cond ((eq ccs 'arabic-iso8859-6)
617 (decode-char ccs code-point))
619 ;; (decode-builtin-char '==gt code-point))
620 ((and (memq ccs '(=gt-pj-1
631 (setq ret (decode-char ccs code-point))
632 (setq ret (encode-char ret '=gt 'defined-only)))
633 (decode-builtin-char '=gt ret))
635 (decode-builtin-char ccs code-point))))
637 (or (decode-char ccs code-point)
638 (define-char (list (cons ccs code-point)))))
639 ((and (<= 0 (char-int ret))
640 (<= (char-int ret) #x1F))
641 (decode-char '=ucs (+ #x2400 (char-int ret))))
642 ((= (char-int ret) #x7F)
646 (defvar char-db-convert-obsolete-format t)
648 (defun char-db-insert-ccs-feature (name value line-breaking)
654 ((memq name '(=>iwds-1
657 =shinjigen@1ed ==shinjigen@1ed
658 =shinjigen@rev ==shinjigen@rev
659 =shinjigen/+p@rev ==shinjigen/+p@rev
660 ===daikanwa/ho ==daikanwa/ho
661 =daikanwa/ho =>>daikanwa/ho =>daikanwa/ho))
662 "(%-18s . %04d)\t; %c")
663 ((eq name '=shinjigen@1ed/24pr)
664 "(%-18s . %04d)\t; %c")
668 ==daikanwa =daikanwa =>>daikanwa =>daikanwa
669 =daikanwa@rev1 =daikanwa@rev2
670 =daikanwa/+p ==daikanwa/+p ===daikanwa/+p
672 =daikanwa/+2p =>>daikanwa/+2p
677 =adobe-japan1-0 ==adobe-japan1-0 ===adobe-japan1-0
678 =adobe-japan1-1 ==adobe-japan1-1 ===adobe-japan1-1
679 =adobe-japan1-2 ==adobe-japan1-2 ===adobe-japan1-2
680 =adobe-japan1-3 ==adobe-japan1-3 ===adobe-japan1-3
681 =adobe-japan1-4 ==adobe-japan1-4 ===adobe-japan1-4
682 =adobe-japan1-5 ==adobe-japan1-5 ===adobe-japan1-5
683 =adobe-japan1-6 ==adobe-japan1-6 ===adobe-japan1-6
684 =>>adobe-japan1-0 =+>adobe-japan1-0
685 =>>adobe-japan1-1 =+>adobe-japan1-1
686 =>>adobe-japan1-2 =+>adobe-japan1-2
687 =>>adobe-japan1-3 =+>adobe-japan1-3
688 =>>adobe-japan1-4 =+>adobe-japan1-4
689 =>>adobe-japan1-5 =+>adobe-japan1-5
690 =>>adobe-japan1-6 =+>adobe-japan1-6
691 =>cbeta =cbeta =>>cbeta ==cbeta ===cbeta
692 =zinbun-oracle =>zinbun-oracle
693 ===hng-jou ===hng-keg ===hng-dng ===hng-mam
694 ===hng-drt ===hng-kgk ===hng-myz ===hng-kda
695 ===hng-khi ===hng-khm ===hng-hok ===hng-kyd ===hng-sok
696 ===hng-yhk ===hng-kak ===hng-kar ===hng-kae
697 ===hng-sys ===hng-tsu ===hng-tzj
698 ===hng-hos ===hng-nak ===hng-jhk
699 ===hng-hod ===hng-gok ===hng-ink ===hng-nto
700 ===hng-nkm ===hng-k24 ===hng-nkk
701 ===hng-kcc ===hng-kcj ===hng-kbk ===hng-sik
702 ===hng-skk ===hng-kyu ===hng-ksk ===hng-wan
703 ===hng-okd ===hng-wad ===hng-kmi
704 ===hng-zkd ===hng-doh ===hng-jyu
705 ===hng-tzs ===hng-kss ===hng-kyo
707 ;; (string-match "^=adobe-" (symbol-name name))
709 "(%-18s . %05d)\t; %c")
710 ((memq name '(=hanyo-denshi/ks
711 ==hanyo-denshi/ks ===hanyo-denshi/ks
716 "(%-18s . %06d)\t; %c")
717 ((>= (charset-dimension name) 2)
718 "(%-18s . #x%04X)\t; %c")
720 "(%-18s . #x%02X)\t; %c"))
722 (if (= (charset-iso-graphic-plane name) 1)
724 (cond ((= (charset-dimension name) 1)
726 ((= (charset-dimension name) 2)
728 ((= (charset-dimension name) 3)
732 (char-db-decode-isolated-char name value)))
733 (if (and (= (charset-chars name) 94)
734 (= (charset-dimension name) 2))
735 (insert (format " [%02d-%02d]"
736 (- (lsh value -8) 32)
737 (- (logand value 255) 32))))
740 (insert (format "(%-18s . %s)" name value))
742 (insert line-breaking))
744 (defun char-db-insert-relation-feature (char name value line-breaking
746 (insert (format "(%-18s%s " name line-breaking))
747 (let ((lbs (concat "\n" (make-string (current-column) ?\ )))
748 separator cell sources required-features
751 (setq cell (car value))
753 (setq cell (decode-char '=ucs cell)))
755 ((eq name '->subsumptive)
756 (when (or (not (some (lambda (atr)
757 (get-char-attribute cell atr))
758 char-db-ignored-attributes))
760 (encode-char cell ccs 'defined-only))
764 (let ((char-db-ignored-attributes
766 char-db-ignored-attributes)))
767 (insert-char-attributes cell readable nil nil 'for-sub-node))
768 (setq separator lbs))
773 char (intern (format "%s*sources" name))))
774 (setq required-features nil)
775 (dolist (source sources)
779 shinjigen shinjigen@1ed shinjigen@rev))
780 (setq required-features
781 (union required-features
793 =shinjigen/+p@rev))))
795 (setq required-features
796 (union required-features
801 ((find-charset (setq ret (intern (format "=%s" source))))
802 (setq required-features
803 (cons ret required-features)))
804 (t (setq required-features
805 (cons source required-features)))))
806 (cond ((string-match "@JP" (symbol-name name))
807 (setq required-features
808 (union required-features
816 ((string-match "@CN" (symbol-name name))
817 (setq required-features
818 (union required-features
825 (insert (format "%S" cell))
826 (char-db-insert-char-spec cell readable
829 (setq separator lbs))
833 (if (consp (car cell))
834 (char-db-insert-char-spec cell readable)
835 (char-db-insert-char-reference cell readable))
836 (setq separator lbs))
840 (insert (prin1-to-string cell))
841 (setq separator " ")))
842 (setq value (cdr value)))
844 (insert line-breaking)))
846 (defun insert-char-attributes (char &optional readable attributes column
849 (setq column (current-column)))
850 (let (name value ; has-long-ccs-name
854 (concat "\n" (make-string (1+ column) ?\ )))
855 lbs cell separator ret
857 dest-ccss ; sources required-features
862 (if (consp attributes)
864 (dolist (name attributes)
865 (unless (memq name char-db-ignored-attributes)
866 (if (find-charset name)
870 (dolist (name (char-attribute-list))
871 (unless (memq name char-db-ignored-attributes)
872 (if (find-charset name)
876 #'char-attribute-name<)))
878 (when (memq '<-subsumptive attributes)
879 (when (or readable (not for-sub-node))
880 (when (setq value (get-char-attribute char '<-subsumptive))
881 (char-db-insert-relation-feature char '<-subsumptive value
884 (setq attributes (delq '<-subsumptive attributes)))
885 (when (and (memq '<-denotational attributes)
886 (setq value (get-char-attribute char '<-denotational)))
887 (char-db-insert-relation-feature char '<-denotational value
890 (setq attributes (delq '<-denotational attributes)))
891 (when (and (memq '<-denotational@component attributes)
892 (setq value (get-char-attribute char '<-denotational@component)))
893 (char-db-insert-relation-feature char '<-denotational@component value
896 (setq attributes (delq '<-denotational@component attributes)))
897 (when (and (memq 'name attributes)
898 (setq value (get-char-attribute char 'name)))
900 (if (> (+ (current-column) (length value)) 48)
903 value line-breaking))
904 (setq attributes (delq 'name attributes))
906 (when (and (memq 'name* attributes)
907 (setq value (get-char-attribute char 'name*)))
909 (if (> (+ (current-column) (length value)) 48)
912 value line-breaking))
913 (setq attributes (delq 'name* attributes))
915 (when (and (memq 'script attributes)
916 (setq value (get-char-attribute char 'script)))
917 (insert (format "(script\t\t%s)%s"
918 (mapconcat (function prin1-to-string)
921 (setq attributes (delq 'script attributes))
923 (dolist (name '(=>ucs =>ucs*))
924 (when (and (memq name attributes)
925 (setq value (get-char-attribute char name)))
926 (insert (format "(%-18s . #x%04X)\t; %c%s"
927 name value (decode-char '=ucs value)
929 (setq attributes (delq name attributes))))
930 (dolist (name '(=>ucs@gb =>ucs@big5))
931 (when (and (memq name attributes)
932 (setq value (get-char-attribute char name)))
933 (insert (format "(%-18s . #x%04X)\t; %c%s"
938 (symbol-name name) 2)))
941 (setq attributes (delq name attributes))
943 ;; (dolist (name '(=>daikanwa))
944 ;; (when (and (memq name attributes)
945 ;; (setq value (get-char-attribute char name)))
947 ;; (if (integerp value)
948 ;; (format "(%-18s . %05d)\t; %c%s"
949 ;; name value (decode-char '=daikanwa value)
951 ;; (format "(%-18s %s)\t; %c%s"
953 ;; (mapconcat (function prin1-to-string)
955 ;; (char-representative-of-daikanwa char)
957 ;; (setq attributes (delq name attributes))))
958 (when (and (memq 'general-category attributes)
959 (setq value (get-char-attribute char 'general-category)))
961 "(general-category\t%s) ; %s%s"
962 (mapconcat (lambda (cell)
965 (cond ((rassoc value unidata-normative-category-alist)
966 "Normative Category")
967 ((rassoc value unidata-informative-category-alist)
968 "Informative Category")
972 (setq attributes (delq 'general-category attributes))
974 (when (and (memq 'bidi-category attributes)
975 (setq value (get-char-attribute char 'bidi-category)))
976 (insert (format "(bidi-category\t. %S)%s"
979 (setq attributes (delq 'bidi-category attributes))
981 (unless (or (not (memq 'mirrored attributes))
982 (eq (setq value (get-char-attribute char 'mirrored 'empty))
984 (insert (format "(mirrored\t\t. %S)%s"
987 (setq attributes (delq 'mirrored attributes))
990 ((and (memq 'decimal-digit-value attributes)
991 (setq value (get-char-attribute char 'decimal-digit-value)))
992 (insert (format "(decimal-digit-value . %S)%s"
995 (setq attributes (delq 'decimal-digit-value attributes))
996 (when (and (memq 'digit-value attributes)
997 (setq value (get-char-attribute char 'digit-value)))
998 (insert (format "(digit-value\t . %S)%s"
1001 (setq attributes (delq 'digit-value attributes))
1003 (when (and (memq 'numeric-value attributes)
1004 (setq value (get-char-attribute char 'numeric-value)))
1005 (insert (format "(numeric-value\t . %S)%s"
1008 (setq attributes (delq 'numeric-value attributes))
1012 (when (and (memq 'digit-value attributes)
1013 (setq value (get-char-attribute char 'digit-value)))
1014 (insert (format "(digit-value\t. %S)%s"
1017 (setq attributes (delq 'digit-value attributes))
1019 (when (and (memq 'numeric-value attributes)
1020 (setq value (get-char-attribute char 'numeric-value)))
1021 (insert (format "(numeric-value\t. %S)%s"
1024 (setq attributes (delq 'numeric-value attributes))
1026 (when (and (memq 'iso-10646-comment attributes)
1027 (setq value (get-char-attribute char 'iso-10646-comment)))
1028 (insert (format "(iso-10646-comment\t. %S)%s"
1031 (setq attributes (delq 'iso-10646-comment attributes))
1033 (when (and (memq 'morohashi-daikanwa attributes)
1034 (setq value (get-char-attribute char 'morohashi-daikanwa)))
1035 (insert (format "(morohashi-daikanwa\t%s)%s"
1036 (mapconcat (function prin1-to-string) value " ")
1038 (setq attributes (delq 'morohashi-daikanwa attributes))
1042 (when (and (memq 'ideographic-radical attributes)
1043 (setq value (get-char-attribute char 'ideographic-radical)))
1044 (setq radical value)
1045 (insert (format "(ideographic-radical . %S)\t; %c%s"
1047 (ideographic-radical radical)
1049 (setq attributes (delq 'ideographic-radical attributes))
1051 (when (and (memq 'shuowen-radical attributes)
1052 (setq value (get-char-attribute char 'shuowen-radical)))
1053 (insert (format "(shuowen-radical\t. %S)\t; %c%s"
1055 (shuowen-radical value)
1057 (setq attributes (delq 'shuowen-radical attributes))
1062 char-db-feature-domains
1064 (dolist (feature (char-attribute-list))
1065 (setq feature (symbol-name feature))
1067 "\\(radical\\|strokes\\)@\\([^@*]+\\)\\(\\*\\|$\\)"
1069 (setq domain (intern (match-string 2 feature)))
1070 (unless (memq domain dest)
1071 (setq dest (cons domain dest)))))
1072 (sort dest #'string<))))
1073 (setq key (intern (format "%s@%s" 'ideographic-radical domain)))
1074 (when (and (memq key attributes)
1075 (setq value (get-char-attribute char key)))
1076 (setq radical value)
1077 (insert (format "(%s . %S)\t; %c%s"
1080 (ideographic-radical radical)
1082 (setq attributes (delq key attributes))
1084 (setq key (intern (format "%s@%s" 'ideographic-strokes domain)))
1085 (when (and (memq key attributes)
1086 (setq value (get-char-attribute char key)))
1087 (setq strokes value)
1088 (insert (format "(%s . %S)%s"
1092 (setq attributes (delq key attributes))
1094 (setq key (intern (format "%s@%s" 'total-strokes domain)))
1095 (when (and (memq key attributes)
1096 (setq value (get-char-attribute char key)))
1097 (insert (format "(%s . %S)%s"
1101 (setq attributes (delq key attributes))
1103 (dolist (feature '(ideographic-radical
1106 (setq key (intern (format "%s@%s*sources" feature domain)))
1107 (when (and (memq key attributes)
1108 (setq value (get-char-attribute char key)))
1109 (insert (format "(%s%s" key line-breaking))
1110 (dolist (cell value)
1111 (insert (format " %s" cell)))
1113 (insert line-breaking)
1114 (setq attributes (delq key attributes))
1117 (when (and (memq 'ideographic-strokes attributes)
1118 (setq value (get-char-attribute char 'ideographic-strokes)))
1119 (setq strokes value)
1120 (insert (format "(ideographic-strokes . %S)%s"
1123 (setq attributes (delq 'ideographic-strokes attributes))
1125 (when (and (memq 'kangxi-radical attributes)
1126 (setq value (get-char-attribute char 'kangxi-radical)))
1127 (unless (eq value radical)
1128 (insert (format "(kangxi-radical\t . %S)\t; %c%s"
1130 (ideographic-radical value)
1133 (setq radical value)))
1134 (setq attributes (delq 'kangxi-radical attributes))
1136 (when (and (memq 'kangxi-strokes attributes)
1137 (setq value (get-char-attribute char 'kangxi-strokes)))
1138 (unless (eq value strokes)
1139 (insert (format "(kangxi-strokes\t . %S)%s"
1143 (setq strokes value)))
1144 (setq attributes (delq 'kangxi-strokes attributes))
1146 (when (and (memq 'japanese-radical attributes)
1147 (setq value (get-char-attribute char 'japanese-radical)))
1148 (unless (eq value radical)
1149 (insert (format "(japanese-radical\t . %S)\t; %c%s"
1151 (ideographic-radical value)
1154 (setq radical value)))
1155 (setq attributes (delq 'japanese-radical attributes))
1157 (when (and (memq 'japanese-strokes attributes)
1158 (setq value (get-char-attribute char 'japanese-strokes)))
1159 (unless (eq value strokes)
1160 (insert (format "(japanese-strokes\t . %S)%s"
1164 (setq strokes value)))
1165 (setq attributes (delq 'japanese-strokes attributes))
1167 (when (and (memq 'cns-radical attributes)
1168 (setq value (get-char-attribute char 'cns-radical)))
1169 (insert (format "(cns-radical\t . %S)\t; %c%s"
1171 (ideographic-radical value)
1173 (setq attributes (delq 'cns-radical attributes))
1175 (when (and (memq 'cns-strokes attributes)
1176 (setq value (get-char-attribute char 'cns-strokes)))
1177 (unless (eq value strokes)
1178 (insert (format "(cns-strokes\t . %S)%s"
1182 (setq strokes value)))
1183 (setq attributes (delq 'cns-strokes attributes))
1185 ;; (when (and (memq 'shinjigen-1-radical attributes)
1186 ;; (setq value (get-char-attribute char 'shinjigen-1-radical)))
1187 ;; (unless (eq value radical)
1188 ;; (insert (format "(shinjigen-1-radical . %S)\t; %c%s"
1190 ;; (ideographic-radical value)
1193 ;; (setq radical value)))
1194 ;; (setq attributes (delq 'shinjigen-1-radical attributes))
1196 (when (and (memq 'ideographic- attributes)
1197 (setq value (get-char-attribute char 'ideographic-)))
1198 (insert "(ideographic- ")
1199 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1201 (while (consp value)
1202 (setq cell (car value))
1204 (setq cell (decode-char '=ucs cell)))
1205 (cond ((characterp cell)
1209 (insert (format "%S" cell))
1210 (char-db-insert-char-spec cell readable))
1211 (setq separator lbs))
1215 (if (consp (car cell))
1216 (char-db-insert-char-spec cell readable)
1217 (char-db-insert-char-reference cell readable))
1218 (setq separator lbs))
1222 (insert (prin1-to-string cell))
1223 (setq separator " ")))
1224 (setq value (cdr value)))
1226 (insert line-breaking)
1227 (setq attributes (delq 'ideographic- attributes)))
1228 (when (and (memq 'total-strokes attributes)
1229 (setq value (get-char-attribute char 'total-strokes)))
1230 (insert (format "(total-strokes . %S)%s"
1233 (setq attributes (delq 'total-strokes attributes))
1235 (when (and (memq '->ideograph attributes)
1236 (setq value (get-char-attribute char '->ideograph)))
1237 (insert (format "(->ideograph\t%s)%s"
1238 (mapconcat (lambda (code)
1239 (cond ((symbolp code)
1242 (format "#x%04X" code))
1245 line-breaking code))))
1248 (setq attributes (delq '->ideograph attributes))
1250 ;; (when (and (memq '->decomposition attributes)
1251 ;; (setq value (get-char-attribute char '->decomposition)))
1252 ;; (insert (format "(->decomposition\t%s)%s"
1253 ;; (mapconcat (lambda (code)
1254 ;; (cond ((symbolp code)
1255 ;; (symbol-name code))
1256 ;; ((characterp code)
1258 ;; (format "%S" code)
1263 ;; (format "#x%04X" code))
1265 ;; (format "%s%S" line-breaking code))))
1268 ;; (setq attributes (delq '->decomposition attributes))
1270 (if (equal (get-char-attribute char '->titlecase)
1271 (get-char-attribute char '->uppercase))
1272 (setq attributes (delq '->titlecase attributes)))
1273 (when (and (memq '->mojikyo attributes)
1274 (setq value (get-char-attribute char '->mojikyo)))
1275 (insert (format "(->mojikyo\t\t. %06d)\t; %c%s"
1276 value (decode-char 'mojikyo value)
1278 (setq attributes (delq '->mojikyo attributes))
1280 (when (and (memq 'hanyu-dazidian-vol attributes)
1281 (setq value (get-char-attribute char 'hanyu-dazidian-vol)))
1282 (insert (format "(hanyu-dazidian-vol . %d)%s"
1283 value line-breaking))
1284 (setq attributes (delq 'hanyu-dazidian-vol attributes))
1286 (when (and (memq 'hanyu-dazidian-page attributes)
1287 (setq value (get-char-attribute char 'hanyu-dazidian-page)))
1288 (insert (format "(hanyu-dazidian-page . %d)%s"
1289 value line-breaking))
1290 (setq attributes (delq 'hanyu-dazidian-page attributes))
1292 (when (and (memq 'hanyu-dazidian-char attributes)
1293 (setq value (get-char-attribute char 'hanyu-dazidian-char)))
1294 (insert (format "(hanyu-dazidian-char . %d)%s"
1295 value line-breaking))
1296 (setq attributes (delq 'hanyu-dazidian-char attributes))
1299 (dolist (ignored '(composition
1300 ->denotational <-subsumptive ->ucs-unified
1301 ->ideographic-component-forms))
1302 (setq attributes (delq ignored attributes))))
1304 (setq name (car attributes))
1305 (unless (eq (setq value (get-char-attribute char name 'value-is-empty))
1307 (cond ((setq ret (find-charset name))
1308 (setq name (charset-name ret))
1309 (when (not (memq name dest-ccss))
1310 (setq dest-ccss (cons name dest-ccss))
1311 (char-db-insert-ccs-feature name value line-breaking))
1313 ((string-match "^=>ucs@" (symbol-name name))
1314 (insert (format "(%-18s . #x%04X)\t; %c%s"
1315 name value (decode-char '=ucs value)
1318 ((eq name 'jisx0208-1978/4X)
1319 (insert (format "(%-18s . #x%04X)%s"
1325 (not (eq name '->subsumptive))
1326 (not (eq name '->uppercase))
1327 (not (eq name '->lowercase))
1328 (not (eq name '->titlecase))
1329 (not (eq name '->canonical))
1330 (not (eq name '->Bopomofo))
1331 (not (eq name '->mistakable))
1332 (not (eq name '->ideographic-variants))
1333 (null (get-char-attribute
1334 char (intern (format "%s*sources" name))))
1335 (not (string-match "\\*sources$" (symbol-name name)))
1336 (null (get-char-attribute
1337 char (intern (format "%s*note" name))))
1338 (not (string-match "\\*note$" (symbol-name name)))
1339 (or (eq name '<-identical)
1340 (eq name '<-uppercase)
1341 (eq name '<-lowercase)
1342 (eq name '<-titlecase)
1343 (eq name '<-canonical)
1344 (eq name '<-ideographic-variants)
1345 ;; (eq name '<-synonyms)
1346 (string-match "^<-synonyms" (symbol-name name))
1347 (eq name '<-mistakable)
1348 (when (string-match "^->" (symbol-name name))
1350 ((string-match "^->fullwidth" (symbol-name name))
1351 (not (and (consp value)
1352 (characterp (car value))
1354 (car value) '=ucs 'defined-only)))
1359 ((or (eq name 'ideographic-structure)
1360 (eq name 'ideographic-combination)
1361 (eq name 'ideographic-)
1362 (eq name '=decomposition)
1363 (char-feature-base-name= '=decomposition name)
1364 (char-feature-base-name= '=>decomposition name)
1365 ;; (string-match "^=>*decomposition\\(@[^*]+\\)?$"
1366 ;; (symbol-name name))
1367 (string-match "^\\(->\\|<-\\)[^*]*$" (symbol-name name))
1368 (string-match "^\\(->\\|<-\\)[^*]*\\*sources$"
1371 (char-db-insert-relation-feature char name value
1374 ((memq name '(ideograph=
1375 original-ideograph-of
1376 ancient-ideograph-of
1379 ;; simplified-ideograph-of
1380 ideographic-variants
1381 ;; ideographic-different-form-of
1383 (insert (format "(%-18s%s " name line-breaking))
1384 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1386 (while (consp value)
1387 (setq cell (car value))
1388 (if (and (consp cell)
1393 (char-db-insert-alist cell readable)
1394 (setq separator lbs))
1397 (insert (prin1-to-string cell))
1398 (setq separator " "))
1399 (setq value (cdr value)))
1401 (insert line-breaking))
1403 (insert (format "(%-18s " name))
1404 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1406 (while (consp value)
1407 (setq cell (car value))
1408 (if (and (consp cell)
1410 (setq ret (condition-case nil
1418 (setq key (car (car rest)))
1419 (if (find-charset key)
1420 (setq cal (cons key cal))
1421 (setq al (cons key al)))
1422 (setq rest (cdr rest)))
1425 (insert-char-attributes ret
1429 (setq separator lbs))
1430 (setq ret (prin1-to-string cell))
1432 (if (< (+ (current-column)
1439 (setq separator " "))
1440 (setq value (cdr value)))
1442 (insert line-breaking))
1444 (insert (format "(%-18s" name))
1445 (setq ret (prin1-to-string value))
1446 (unless (< (+ (current-column)
1450 (insert line-breaking))
1451 (insert " . " ret ")" line-breaking)
1452 ;; (insert (format "(%-18s . %S)%s"
1457 (setq attributes (cdr attributes)))
1460 (defun insert-char-data (char &optional readable
1463 (narrow-to-region (point)(point))
1464 (insert "(define-char
1466 (insert-char-attributes char readable attributes)
1468 (goto-char (point-min))
1469 (while (re-search-forward "[ \t]+$" nil t)
1472 (goto-char (point-min))
1473 (while (re-search-forward "[ \t][ \t][ \t]*" nil t)
1474 (let ((column (current-column))
1475 (indent-tabs-mode t))
1476 (delete-region (match-beginning 0) (point))
1477 (indent-to column)))
1478 (goto-char (point-max))
1479 ;; (tabify (point-min)(point-max))
1482 (defun insert-char-data-with-variant (char &optional printable
1484 script excluded-script)
1485 (insert-char-data char printable)
1486 (let ((variants (char-variants char))
1489 (setq variants (sort variants #'<))
1490 (setq rest variants)
1491 (setq variants (cons char variants))
1493 (setq variant (car rest))
1494 (unless (get-char-attribute variant '<-subsumptive)
1495 (if (and (or (null script)
1496 (null (setq vs (get-char-attribute variant 'script)))
1498 (or (null excluded-script)
1499 (null (setq vs (get-char-attribute variant 'script)))
1500 (not (memq excluded-script vs))))
1501 (unless (and no-ucs-unified (get-char-attribute variant '=ucs))
1502 (insert-char-data variant printable)
1503 (if (setq ret (char-variants variant))
1505 (or (memq (car ret) variants)
1506 ;; (get-char-attribute (car ret) '<-subsumptive)
1507 (setq rest (nconc rest (list (car ret)))))
1508 (setq ret (cdr ret)))))))
1509 (setq rest (cdr rest)))))
1511 (defun insert-char-range-data (min max &optional script excluded-script)
1514 (while (<= code max)
1515 (setq char (decode-char '=ucs code))
1516 (if (encode-char char '=ucs 'defined-only)
1517 (insert-char-data-with-variant char nil 'no-ucs-unified
1518 script excluded-script))
1519 (setq code (1+ code)))))
1521 (defun write-char-range-data-to-file (min max file
1522 &optional script excluded-script)
1523 (let ((coding-system-for-write char-db-file-coding-system))
1525 (insert (format ";; -*- coding: %s -*-\n"
1526 char-db-file-coding-system))
1527 (insert-char-range-data min max script excluded-script)
1528 (write-region (point-min)(point-max) file))))
1530 (defvar what-character-original-window-configuration)
1533 (defun what-char-definition (char)
1534 (interactive (list (char-after)))
1535 (let ((buf (get-buffer-create "*Character Description*"))
1536 (the-buf (current-buffer))
1537 (win-conf (current-window-configuration)))
1539 (make-local-variable 'what-character-original-window-configuration)
1540 (setq what-character-original-window-configuration win-conf)
1541 (setq buffer-read-only nil)
1545 (insert-char-data-with-variant char 'printable)
1546 (unless (char-attribute-alist char)
1547 (insert (format ";; = %c\n"
1548 (let* ((rest (split-char char))
1552 (setq code (logior (lsh code 8)
1554 (decode-char ccs code)))))
1555 ;; (char-db-update-comment)
1556 (set-buffer-modified-p nil)
1557 (view-mode the-buf (lambda (buf)
1558 (set-window-configuration
1559 what-character-original-window-configuration)
1561 (goto-char (point-min)))
1563 (set-window-configuration
1564 what-character-original-window-configuration)
1565 (signal (car err) (cdr err)))))))
1571 (provide 'char-db-util)
1573 ;;; char-db-util.el ends here