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
340 ;;; @ char-db formatters
343 (defun char-db-make-char-spec (char)
345 (cond ((characterp char)
346 (cond ((and (setq ret (encode-char char '=ucs 'defined-only))
347 (not (and (<= #xE000 ret)(<= ret #xF8FF))))
348 (setq char-spec (list (cons '=ucs ret)))
349 (cond ((setq ret (get-char-attribute char 'name))
350 (setq char-spec (cons (cons 'name ret) char-spec))
352 ((setq ret (get-char-attribute char 'name*))
353 (setq char-spec (cons (cons 'name* ret) char-spec))
356 ((encode-char char '=mj 'defined-only)
358 (dolist (ccs (charset-list))
359 (if (and (or (eq ccs '=mj)
360 ;; (eq (charset-property ccs 'iso-ir) 177)
361 (string-match "=ucs@" (symbol-name ccs))
363 (setq ccs (charset-name ccs))
364 (null (assq ccs char-spec))
365 (setq ret (encode-char char ccs 'defined-only)))
366 (setq char-spec (cons (cons ccs ret) char-spec))))
368 ((encode-char char '==mj 'defined-only)
370 (dolist (ccs (charset-list))
371 (if (and (or (eq ccs '==mj)
372 ;; (eq (charset-property ccs 'iso-ir) 177)
373 (string-match "=ucs@" (symbol-name ccs))
375 (setq ccs (charset-name ccs))
376 (null (assq ccs char-spec))
377 (setq ret (encode-char char ccs 'defined-only)))
378 (setq char-spec (cons (cons ccs ret) char-spec))))
380 ((encode-char char '=adobe-japan1 'defined-only)
382 (dolist (ccs (charset-list))
383 (if (and (or (memq ccs
392 ;; (eq (charset-property ccs 'iso-ir) 177)
393 (string-match "=ucs@" (symbol-name ccs))
395 (setq ccs (charset-name ccs))
396 (null (assq ccs char-spec))
397 (setq ret (encode-char char ccs 'defined-only)))
398 (setq char-spec (cons (cons ccs ret) char-spec))))
400 ((encode-char char '==adobe-japan1 'defined-only)
402 (dolist (ccs (charset-list))
403 (if (and (or (memq ccs
412 ;; (eq (charset-property ccs 'iso-ir) 177)
413 (string-match "=ucs@" (symbol-name ccs))
415 (setq ccs (charset-name ccs))
416 (null (assq ccs char-spec))
417 (setq ret (encode-char char ccs 'defined-only)))
418 (setq char-spec (cons (cons ccs ret) char-spec))))
422 (let ((rest char-db-coded-charset-priority-list)
425 (setq ccs (charset-name
426 (find-charset (car rest))))
428 (encode-char char ccs
430 (throw 'tag (cons ccs ret)))
431 (setq rest (cdr rest))))))
432 (setq char-spec (list ret))
433 (dolist (ccs (delq (car ret) (charset-list)))
434 (if (and (or (charset-iso-final-char ccs)
441 (eq (charset-property ccs 'iso-ir) 177)
442 ;; (string-match "=ucs@" (symbol-name ccs))
444 (setq ccs (charset-name ccs))
445 (null (assq ccs char-spec))
446 (setq ret (encode-char char ccs 'defined-only)))
447 (setq char-spec (cons (cons ccs ret) char-spec))))
449 (setq char-spec (split-char char)))
450 (cond ((setq ret (get-char-attribute char 'name))
451 (setq char-spec (cons (cons 'name ret) char-spec))
453 ((setq ret (get-char-attribute char 'name*))
454 (setq char-spec (cons (cons 'name* ret) char-spec))
457 ((setq ret (get-char-attribute
458 char 'ideographic-combination))
460 (cons (cons 'ideographic-combination ret)
467 (defun char-db-insert-char-spec (char &optional readable column
470 (setq column (current-column)))
471 (let (char-spec temp-char)
472 (setq char-spec (char-db-make-char-spec char))
473 (unless (or (characterp char) ; char
475 (setq char (find-char char-spec))
477 ;; define temporary character
478 ;; Current implementation is dirty.
479 (setq temp-char (define-char (cons '(ideograph-daikanwa . 0)
481 (remove-char-attribute temp-char 'ideograph-daikanwa)
482 (setq char temp-char))
483 (insert-char-attributes char
485 (union (mapcar #'car char-spec)
489 ;; undefine temporary character
490 ;; Current implementation is dirty.
491 (setq char-spec (char-attribute-alist temp-char))
493 (remove-char-attribute temp-char (car (car char-spec)))
494 (setq char-spec (cdr char-spec))))))
496 (defun char-db-insert-alist (alist &optional readable column)
498 (setq column (current-column)))
500 (concat "\n" (make-string (1+ column) ?\ )))
504 lbs cell rest separator)
507 (setq name (car (car alist))
508 value (cdr (car alist)))
509 (cond ((eq name 'char)
511 (if (setq ret (condition-case nil
519 (setq key (car (car value)))
520 ;; (if (find-charset key)
521 ;; (setq cal (cons key cal))
522 (setq al (cons key al))
524 (setq value (cdr value)))
525 (insert-char-attributes ret
529 (insert (prin1-to-string value)))
531 (insert line-breaking))
533 (insert (format "(%-18s " name))
534 (setq lbs (concat "\n" (make-string (current-column) ?\ )))
536 (setq cell (car value))
537 (if (and (consp cell)
539 (setq ret (condition-case nil
549 (setq key (car (car rest)))
550 ;; (if (find-charset key)
551 ;; (setq cal (cons key cal))
552 (setq al (cons key al))
554 (setq rest (cdr rest)))
557 (insert-char-attributes ret
561 (setq separator lbs))
564 (insert (prin1-to-string cell))
565 (setq separator " "))
566 (setq value (cdr value)))
568 (insert line-breaking))
570 (insert (format "(%-18s . %S)%s"
573 (setq alist (cdr alist))))
576 (defun char-db-insert-char-reference (plist &optional readable column)
578 (setq column (current-column)))
580 (concat "\n" (make-string (1+ column) ?\ )))
585 (setq name (pop plist))
586 (setq value (pop plist))
587 (cond ((eq name :char)
590 (cond ((numberp value)
591 (setq value (decode-char '=ucs value)))
593 ;; (setq value (or (find-char value)
596 (char-db-insert-char-spec value readable)
597 (insert line-breaking)
600 (insert (format "%s%s\t%d ; %c%s"
603 (ideographic-radical value)
607 (insert (format "%s%s\t%S" separator name value))
608 (setq separator line-breaking)))
612 (defun char-db-decode-isolated-char (ccs code-point)
615 (cond ((eq ccs 'arabic-iso8859-6)
616 (decode-char ccs code-point))
618 ;; (decode-builtin-char '==gt code-point))
619 ((and (memq ccs '(=gt-pj-1
630 (setq ret (decode-char ccs code-point))
631 (setq ret (encode-char ret '=gt 'defined-only)))
632 (decode-builtin-char '=gt ret))
634 (decode-builtin-char ccs code-point))))
636 (or (decode-char ccs code-point)
637 (define-char (list (cons ccs code-point)))))
638 ((and (<= 0 (char-int ret))
639 (<= (char-int ret) #x1F))
640 (decode-char '=ucs (+ #x2400 (char-int ret))))
641 ((= (char-int ret) #x7F)
645 (defvar char-db-convert-obsolete-format t)
647 (defun char-db-insert-ccs-feature (name value line-breaking)
653 ((memq name '(=>iwds-1
656 =shinjigen@1ed ==shinjigen@1ed
657 =shinjigen@rev ==shinjigen@rev
658 =shinjigen/+p@rev ==shinjigen/+p@rev
659 ===daikanwa/ho ==daikanwa/ho
660 =daikanwa/ho =>>daikanwa/ho =>daikanwa/ho))
661 "(%-18s . %04d)\t; %c")
662 ((eq name '=shinjigen@1ed/24pr)
663 "(%-18s . %04d)\t; %c")
667 ==daikanwa =daikanwa =>>daikanwa =>daikanwa
668 =daikanwa@rev1 =daikanwa@rev2
669 =daikanwa/+p ==daikanwa/+p ===daikanwa/+p
671 =daikanwa/+2p =>>daikanwa/+2p
676 =adobe-japan1-0 ==adobe-japan1-0 ===adobe-japan1-0
677 =adobe-japan1-1 ==adobe-japan1-1 ===adobe-japan1-1
678 =adobe-japan1-2 ==adobe-japan1-2 ===adobe-japan1-2
679 =adobe-japan1-3 ==adobe-japan1-3 ===adobe-japan1-3
680 =adobe-japan1-4 ==adobe-japan1-4 ===adobe-japan1-4
681 =adobe-japan1-5 ==adobe-japan1-5 ===adobe-japan1-5
682 =adobe-japan1-6 ==adobe-japan1-6 ===adobe-japan1-6
683 =>>adobe-japan1-0 =+>adobe-japan1-0
684 =>>adobe-japan1-1 =+>adobe-japan1-1
685 =>>adobe-japan1-2 =+>adobe-japan1-2
686 =>>adobe-japan1-3 =+>adobe-japan1-3
687 =>>adobe-japan1-4 =+>adobe-japan1-4
688 =>>adobe-japan1-5 =+>adobe-japan1-5
689 =>>adobe-japan1-6 =+>adobe-japan1-6
690 =>cbeta =cbeta =>>cbeta ==cbeta ===cbeta
691 =zinbun-oracle =>zinbun-oracle
692 ===hng-jou ===hng-keg ===hng-dng ===hng-mam
693 ===hng-drt ===hng-kgk ===hng-myz ===hng-kda
694 ===hng-khi ===hng-khm ===hng-hok ===hng-kyd ===hng-sok
695 ===hng-yhk ===hng-kak ===hng-kar ===hng-kae
696 ===hng-sys ===hng-tsu ===hng-tzj
697 ===hng-hos ===hng-nak ===hng-jhk
698 ===hng-hod ===hng-gok ===hng-ink ===hng-nto
699 ===hng-nkm ===hng-k24 ===hng-nkk
700 ===hng-kcc ===hng-kcj ===hng-kbk ===hng-sik
701 ===hng-skk ===hng-kyu ===hng-ksk ===hng-wan
702 ===hng-okd ===hng-wad ===hng-kmi
703 ===hng-zkd ===hng-doh ===hng-jyu
704 ===hng-tzs ===hng-kss ===hng-kyo
706 ;; (string-match "^=adobe-" (symbol-name name))
708 "(%-18s . %05d)\t; %c")
709 ((memq name '(=hanyo-denshi/ks
710 ==hanyo-denshi/ks ===hanyo-denshi/ks
715 "(%-18s . %06d)\t; %c")
716 ((>= (charset-dimension name) 2)
717 "(%-18s . #x%04X)\t; %c")
719 "(%-18s . #x%02X)\t; %c"))
721 (if (= (charset-iso-graphic-plane name) 1)
723 (cond ((= (charset-dimension name) 1)
725 ((= (charset-dimension name) 2)
727 ((= (charset-dimension name) 3)
731 (char-db-decode-isolated-char name value)))
732 (if (and (= (charset-chars name) 94)
733 (= (charset-dimension name) 2))
734 (insert (format " [%02d-%02d]"
735 (- (lsh value -8) 32)
736 (- (logand value 255) 32))))
739 (insert (format "(%-18s . %s)" name value))
741 (insert line-breaking))
743 (defun char-db-insert-relation-feature (char name value line-breaking
745 (insert (format "(%-18s%s " name line-breaking))
746 (let ((lbs (concat "\n" (make-string (current-column) ?\ )))
747 separator cell sources required-features
750 (setq cell (car value))
752 (setq cell (decode-char '=ucs cell)))
754 ((eq name '->subsumptive)
755 (when (or (not (some (lambda (atr)
756 (get-char-attribute cell atr))
757 char-db-ignored-attributes))
759 (encode-char cell ccs 'defined-only))
763 (let ((char-db-ignored-attributes
765 char-db-ignored-attributes)))
766 (insert-char-attributes cell readable nil nil 'for-sub-node))
767 (setq separator lbs))
772 char (intern (format "%s*sources" name))))
773 (setq required-features nil)
774 (dolist (source sources)
778 shinjigen shinjigen@1ed shinjigen@rev))
779 (setq required-features
780 (union required-features
792 =shinjigen/+p@rev))))
794 (setq required-features
795 (union required-features
800 ((find-charset (setq ret (intern (format "=%s" source))))
801 (setq required-features
802 (cons ret required-features)))
803 (t (setq required-features
804 (cons source required-features)))))
805 (cond ((string-match "@JP" (symbol-name name))
806 (setq required-features
807 (union required-features
815 ((string-match "@CN" (symbol-name name))
816 (setq required-features
817 (union required-features
824 (insert (format "%S" cell))
825 (char-db-insert-char-spec cell readable
828 (setq separator lbs))
832 (if (consp (car cell))
833 (char-db-insert-char-spec cell readable)
834 (char-db-insert-char-reference cell readable))
835 (setq separator lbs))
839 (insert (prin1-to-string cell))
840 (setq separator " ")))
841 (setq value (cdr value)))
843 (insert line-breaking)))
845 (defun insert-char-attributes (char &optional readable attributes column
848 (setq column (current-column)))
849 (let (name value ; has-long-ccs-name
853 (concat "\n" (make-string (1+ column) ?\ )))
854 lbs cell separator ret
856 dest-ccss ; sources required-features
861 (if (consp attributes)
863 (dolist (name attributes)
864 (unless (memq name char-db-ignored-attributes)
865 (if (find-charset name)
869 (dolist (name (char-attribute-list))
870 (unless (memq name char-db-ignored-attributes)
871 (if (find-charset name)
875 #'char-attribute-name<)))
877 (when (memq '<-subsumptive attributes)
878 (when (or readable (not for-sub-node))
879 (when (setq value (get-char-attribute char '<-subsumptive))
880 (char-db-insert-relation-feature char '<-subsumptive value
883 (setq attributes (delq '<-subsumptive attributes)))
884 (when (and (memq '<-denotational attributes)
885 (setq value (get-char-attribute char '<-denotational)))
886 (char-db-insert-relation-feature char '<-denotational value
889 (setq attributes (delq '<-denotational attributes)))
890 (when (and (memq '<-denotational@component attributes)
891 (setq value (get-char-attribute char '<-denotational@component)))
892 (char-db-insert-relation-feature char '<-denotational@component value
895 (setq attributes (delq '<-denotational@component attributes)))
896 (when (and (memq 'name attributes)
897 (setq value (get-char-attribute char 'name)))
899 (if (> (+ (current-column) (length value)) 48)
902 value line-breaking))
903 (setq attributes (delq 'name attributes))
905 (when (and (memq 'name* attributes)
906 (setq value (get-char-attribute char 'name*)))
908 (if (> (+ (current-column) (length value)) 48)
911 value line-breaking))
912 (setq attributes (delq 'name* attributes))
914 (when (and (memq 'script attributes)
915 (setq value (get-char-attribute char 'script)))
916 (insert (format "(script\t\t%s)%s"
917 (mapconcat (function prin1-to-string)
920 (setq attributes (delq 'script attributes))
922 (dolist (name '(=>ucs =>ucs*))
923 (when (and (memq name attributes)
924 (setq value (get-char-attribute char name)))
925 (insert (format "(%-18s . #x%04X)\t; %c%s"
926 name value (decode-char '=ucs value)
928 (setq attributes (delq name attributes))))
929 (dolist (name '(=>ucs@gb =>ucs@big5))
930 (when (and (memq name attributes)
931 (setq value (get-char-attribute char name)))
932 (insert (format "(%-18s . #x%04X)\t; %c%s"
937 (symbol-name name) 2)))
940 (setq attributes (delq name attributes))
942 ;; (dolist (name '(=>daikanwa))
943 ;; (when (and (memq name attributes)
944 ;; (setq value (get-char-attribute char name)))
946 ;; (if (integerp value)
947 ;; (format "(%-18s . %05d)\t; %c%s"
948 ;; name value (decode-char '=daikanwa value)
950 ;; (format "(%-18s %s)\t; %c%s"
952 ;; (mapconcat (function prin1-to-string)
954 ;; (char-representative-of-daikanwa char)
956 ;; (setq attributes (delq name attributes))))
957 (when (and (memq 'general-category attributes)
958 (setq value (get-char-attribute char 'general-category)))
960 "(general-category\t%s) ; %s%s"
961 (mapconcat (lambda (cell)
964 (cond ((rassoc value unidata-normative-category-alist)
965 "Normative Category")
966 ((rassoc value unidata-informative-category-alist)
967 "Informative Category")
971 (setq attributes (delq 'general-category attributes))
973 (when (and (memq 'bidi-category attributes)
974 (setq value (get-char-attribute char 'bidi-category)))
975 (insert (format "(bidi-category\t. %S)%s"
978 (setq attributes (delq 'bidi-category attributes))
980 (unless (or (not (memq 'mirrored attributes))
981 (eq (setq value (get-char-attribute char 'mirrored 'empty))
983 (insert (format "(mirrored\t\t. %S)%s"
986 (setq attributes (delq 'mirrored attributes))
989 ((and (memq 'decimal-digit-value attributes)
990 (setq value (get-char-attribute char 'decimal-digit-value)))
991 (insert (format "(decimal-digit-value . %S)%s"
994 (setq attributes (delq 'decimal-digit-value attributes))
995 (when (and (memq 'digit-value attributes)
996 (setq value (get-char-attribute char 'digit-value)))
997 (insert (format "(digit-value\t . %S)%s"
1000 (setq attributes (delq 'digit-value attributes))
1002 (when (and (memq 'numeric-value attributes)
1003 (setq value (get-char-attribute char 'numeric-value)))
1004 (insert (format "(numeric-value\t . %S)%s"
1007 (setq attributes (delq 'numeric-value attributes))
1011 (when (and (memq 'digit-value attributes)
1012 (setq value (get-char-attribute char 'digit-value)))
1013 (insert (format "(digit-value\t. %S)%s"
1016 (setq attributes (delq 'digit-value attributes))
1018 (when (and (memq 'numeric-value attributes)
1019 (setq value (get-char-attribute char 'numeric-value)))
1020 (insert (format "(numeric-value\t. %S)%s"
1023 (setq attributes (delq 'numeric-value attributes))
1025 (when (and (memq 'iso-10646-comment attributes)
1026 (setq value (get-char-attribute char 'iso-10646-comment)))
1027 (insert (format "(iso-10646-comment\t. %S)%s"
1030 (setq attributes (delq 'iso-10646-comment attributes))
1032 (when (and (memq 'morohashi-daikanwa attributes)
1033 (setq value (get-char-attribute char 'morohashi-daikanwa)))
1034 (insert (format "(morohashi-daikanwa\t%s)%s"
1035 (mapconcat (function prin1-to-string) value " ")
1037 (setq attributes (delq 'morohashi-daikanwa attributes))
1041 (when (and (memq 'ideographic-radical attributes)
1042 (setq value (get-char-attribute char 'ideographic-radical)))
1043 (setq radical value)
1044 (insert (format "(ideographic-radical . %S)\t; %c%s"
1046 (ideographic-radical radical)
1048 (setq attributes (delq 'ideographic-radical attributes))
1050 (when (and (memq 'shuowen-radical attributes)
1051 (setq value (get-char-attribute char 'shuowen-radical)))
1052 (insert (format "(shuowen-radical\t. %S)\t; %c%s"
1054 (shuowen-radical value)
1056 (setq attributes (delq 'shuowen-radical attributes))
1061 char-db-feature-domains
1063 (dolist (feature (char-attribute-list))
1064 (setq feature (symbol-name feature))
1066 "\\(radical\\|strokes\\)@\\([^@*]+\\)\\(\\*\\|$\\)"
1068 (setq domain (intern (match-string 2 feature)))
1069 (unless (memq domain dest)
1070 (setq dest (cons domain dest)))))
1071 (sort dest #'string<))))
1072 (setq key (intern (format "%s@%s" 'ideographic-radical domain)))
1073 (when (and (memq key attributes)
1074 (setq value (get-char-attribute char key)))
1075 (setq radical value)
1076 (insert (format "(%s . %S)\t; %c%s"
1079 (ideographic-radical radical)
1081 (setq attributes (delq key attributes))
1083 (setq key (intern (format "%s@%s" 'ideographic-strokes domain)))
1084 (when (and (memq key attributes)
1085 (setq value (get-char-attribute char key)))
1086 (setq strokes value)
1087 (insert (format "(%s . %S)%s"
1091 (setq attributes (delq key attributes))
1093 (setq key (intern (format "%s@%s" 'total-strokes domain)))
1094 (when (and (memq key attributes)
1095 (setq value (get-char-attribute char key)))
1096 (insert (format "(%s . %S)%s"
1100 (setq attributes (delq key attributes))
1102 (dolist (feature '(ideographic-radical
1105 (setq key (intern (format "%s@%s*sources" feature domain)))
1106 (when (and (memq key attributes)
1107 (setq value (get-char-attribute char key)))
1108 (insert (format "(%s%s" key line-breaking))
1109 (dolist (cell value)
1110 (insert (format " %s" cell)))
1112 (insert line-breaking)
1113 (setq attributes (delq key attributes))
1116 (when (and (memq 'ideographic-strokes attributes)
1117 (setq value (get-char-attribute char 'ideographic-strokes)))
1118 (setq strokes value)
1119 (insert (format "(ideographic-strokes . %S)%s"
1122 (setq attributes (delq 'ideographic-strokes attributes))
1124 (when (and (memq 'kangxi-radical attributes)
1125 (setq value (get-char-attribute char 'kangxi-radical)))
1126 (unless (eq value radical)
1127 (insert (format "(kangxi-radical\t . %S)\t; %c%s"
1129 (ideographic-radical value)
1132 (setq radical value)))
1133 (setq attributes (delq 'kangxi-radical attributes))
1135 (when (and (memq 'kangxi-strokes attributes)
1136 (setq value (get-char-attribute char 'kangxi-strokes)))
1137 (unless (eq value strokes)
1138 (insert (format "(kangxi-strokes\t . %S)%s"
1142 (setq strokes value)))
1143 (setq attributes (delq 'kangxi-strokes attributes))
1145 (when (and (memq 'japanese-radical attributes)
1146 (setq value (get-char-attribute char 'japanese-radical)))
1147 (unless (eq value radical)
1148 (insert (format "(japanese-radical\t . %S)\t; %c%s"
1150 (ideographic-radical value)
1153 (setq radical value)))
1154 (setq attributes (delq 'japanese-radical attributes))
1156 (when (and (memq 'japanese-strokes attributes)
1157 (setq value (get-char-attribute char 'japanese-strokes)))
1158 (unless (eq value strokes)
1159 (insert (format "(japanese-strokes\t . %S)%s"
1163 (setq strokes value)))
1164 (setq attributes (delq 'japanese-strokes attributes))
1166 (when (and (memq 'cns-radical attributes)
1167 (setq value (get-char-attribute char 'cns-radical)))
1168 (insert (format "(cns-radical\t . %S)\t; %c%s"
1170 (ideographic-radical value)
1172 (setq attributes (delq 'cns-radical attributes))
1174 (when (and (memq 'cns-strokes attributes)
1175 (setq value (get-char-attribute char 'cns-strokes)))
1176 (unless (eq value strokes)
1177 (insert (format "(cns-strokes\t . %S)%s"
1181 (setq strokes value)))
1182 (setq attributes (delq 'cns-strokes attributes))
1184 ;; (when (and (memq 'shinjigen-1-radical attributes)
1185 ;; (setq value (get-char-attribute char 'shinjigen-1-radical)))
1186 ;; (unless (eq value radical)
1187 ;; (insert (format "(shinjigen-1-radical . %S)\t; %c%s"
1189 ;; (ideographic-radical value)
1192 ;; (setq radical value)))
1193 ;; (setq attributes (delq 'shinjigen-1-radical attributes))
1195 (when (and (memq 'ideographic- attributes)
1196 (setq value (get-char-attribute char 'ideographic-)))
1197 (insert "(ideographic- ")
1198 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1200 (while (consp value)
1201 (setq cell (car value))
1203 (setq cell (decode-char '=ucs cell)))
1204 (cond ((characterp cell)
1208 (insert (format "%S" cell))
1209 (char-db-insert-char-spec cell readable))
1210 (setq separator lbs))
1214 (if (consp (car cell))
1215 (char-db-insert-char-spec cell readable)
1216 (char-db-insert-char-reference cell readable))
1217 (setq separator lbs))
1221 (insert (prin1-to-string cell))
1222 (setq separator " ")))
1223 (setq value (cdr value)))
1225 (insert line-breaking)
1226 (setq attributes (delq 'ideographic- attributes)))
1227 (when (and (memq 'total-strokes attributes)
1228 (setq value (get-char-attribute char 'total-strokes)))
1229 (insert (format "(total-strokes . %S)%s"
1232 (setq attributes (delq 'total-strokes attributes))
1234 (when (and (memq '->ideograph attributes)
1235 (setq value (get-char-attribute char '->ideograph)))
1236 (insert (format "(->ideograph\t%s)%s"
1237 (mapconcat (lambda (code)
1238 (cond ((symbolp code)
1241 (format "#x%04X" code))
1244 line-breaking code))))
1247 (setq attributes (delq '->ideograph attributes))
1249 ;; (when (and (memq '->decomposition attributes)
1250 ;; (setq value (get-char-attribute char '->decomposition)))
1251 ;; (insert (format "(->decomposition\t%s)%s"
1252 ;; (mapconcat (lambda (code)
1253 ;; (cond ((symbolp code)
1254 ;; (symbol-name code))
1255 ;; ((characterp code)
1257 ;; (format "%S" code)
1262 ;; (format "#x%04X" code))
1264 ;; (format "%s%S" line-breaking code))))
1267 ;; (setq attributes (delq '->decomposition attributes))
1269 (if (equal (get-char-attribute char '->titlecase)
1270 (get-char-attribute char '->uppercase))
1271 (setq attributes (delq '->titlecase attributes)))
1272 (when (and (memq '->mojikyo attributes)
1273 (setq value (get-char-attribute char '->mojikyo)))
1274 (insert (format "(->mojikyo\t\t. %06d)\t; %c%s"
1275 value (decode-char 'mojikyo value)
1277 (setq attributes (delq '->mojikyo attributes))
1279 (when (and (memq 'hanyu-dazidian-vol attributes)
1280 (setq value (get-char-attribute char 'hanyu-dazidian-vol)))
1281 (insert (format "(hanyu-dazidian-vol . %d)%s"
1282 value line-breaking))
1283 (setq attributes (delq 'hanyu-dazidian-vol attributes))
1285 (when (and (memq 'hanyu-dazidian-page attributes)
1286 (setq value (get-char-attribute char 'hanyu-dazidian-page)))
1287 (insert (format "(hanyu-dazidian-page . %d)%s"
1288 value line-breaking))
1289 (setq attributes (delq 'hanyu-dazidian-page attributes))
1291 (when (and (memq 'hanyu-dazidian-char attributes)
1292 (setq value (get-char-attribute char 'hanyu-dazidian-char)))
1293 (insert (format "(hanyu-dazidian-char . %d)%s"
1294 value line-breaking))
1295 (setq attributes (delq 'hanyu-dazidian-char attributes))
1298 (dolist (ignored '(composition
1299 ->denotational <-subsumptive ->ucs-unified
1300 ->ideographic-component-forms))
1301 (setq attributes (delq ignored attributes))))
1303 (setq name (car attributes))
1304 (unless (eq (setq value (get-char-attribute char name 'value-is-empty))
1306 (cond ((setq ret (find-charset name))
1307 (setq name (charset-name ret))
1308 (when (not (memq name dest-ccss))
1309 (setq dest-ccss (cons name dest-ccss))
1310 (char-db-insert-ccs-feature name value line-breaking))
1312 ((string-match "^=>ucs@" (symbol-name name))
1313 (insert (format "(%-18s . #x%04X)\t; %c%s"
1314 name value (decode-char '=ucs value)
1317 ((eq name 'jisx0208-1978/4X)
1318 (insert (format "(%-18s . #x%04X)%s"
1324 (not (eq name '->subsumptive))
1325 (not (eq name '->uppercase))
1326 (not (eq name '->lowercase))
1327 (not (eq name '->titlecase))
1328 (not (eq name '->canonical))
1329 (not (eq name '->Bopomofo))
1330 (not (eq name '->mistakable))
1331 (not (eq name '->ideographic-variants))
1332 (null (get-char-attribute
1333 char (intern (format "%s*sources" name))))
1334 (not (string-match "\\*sources$" (symbol-name name)))
1335 (null (get-char-attribute
1336 char (intern (format "%s*note" name))))
1337 (not (string-match "\\*note$" (symbol-name name)))
1338 (or (eq name '<-identical)
1339 (eq name '<-uppercase)
1340 (eq name '<-lowercase)
1341 (eq name '<-titlecase)
1342 (eq name '<-canonical)
1343 (eq name '<-ideographic-variants)
1344 ;; (eq name '<-synonyms)
1345 (string-match "^<-synonyms" (symbol-name name))
1346 (eq name '<-mistakable)
1347 (when (string-match "^->" (symbol-name name))
1349 ((string-match "^->fullwidth" (symbol-name name))
1350 (not (and (consp value)
1351 (characterp (car value))
1353 (car value) '=ucs 'defined-only)))
1358 ((or (eq name 'ideographic-structure)
1359 (eq name 'ideographic-combination)
1360 (eq name 'ideographic-)
1361 (eq name '=decomposition)
1362 (char-feature-base-name= '=decomposition name)
1363 (char-feature-base-name= '=>decomposition name)
1364 ;; (string-match "^=>*decomposition\\(@[^*]+\\)?$"
1365 ;; (symbol-name name))
1366 (string-match "^\\(->\\|<-\\)[^*]*$" (symbol-name name))
1367 (string-match "^\\(->\\|<-\\)[^*]*\\*sources$"
1370 (char-db-insert-relation-feature char name value
1373 ((memq name '(ideograph=
1374 original-ideograph-of
1375 ancient-ideograph-of
1378 ;; simplified-ideograph-of
1379 ideographic-variants
1380 ;; ideographic-different-form-of
1382 (insert (format "(%-18s%s " name line-breaking))
1383 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1385 (while (consp value)
1386 (setq cell (car value))
1387 (if (and (consp cell)
1392 (char-db-insert-alist cell readable)
1393 (setq separator lbs))
1396 (insert (prin1-to-string cell))
1397 (setq separator " "))
1398 (setq value (cdr value)))
1400 (insert line-breaking))
1402 (insert (format "(%-18s " name))
1403 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1405 (while (consp value)
1406 (setq cell (car value))
1407 (if (and (consp cell)
1409 (setq ret (condition-case nil
1417 (setq key (car (car rest)))
1418 (if (find-charset key)
1419 (setq cal (cons key cal))
1420 (setq al (cons key al)))
1421 (setq rest (cdr rest)))
1424 (insert-char-attributes ret
1428 (setq separator lbs))
1429 (setq ret (prin1-to-string cell))
1431 (if (< (+ (current-column)
1438 (setq separator " "))
1439 (setq value (cdr value)))
1441 (insert line-breaking))
1443 (insert (format "(%-18s" name))
1444 (setq ret (prin1-to-string value))
1445 (unless (< (+ (current-column)
1449 (insert line-breaking))
1450 (insert " . " ret ")" line-breaking)
1451 ;; (insert (format "(%-18s . %S)%s"
1456 (setq attributes (cdr attributes)))
1459 (defun insert-char-data (char &optional readable
1462 (narrow-to-region (point)(point))
1463 (insert "(define-char
1465 (insert-char-attributes char readable attributes)
1467 (goto-char (point-min))
1468 (while (re-search-forward "[ \t]+$" nil t)
1471 (goto-char (point-min))
1472 (while (re-search-forward "[ \t][ \t][ \t]*" nil t)
1473 (let ((column (current-column))
1474 (indent-tabs-mode t))
1475 (delete-region (match-beginning 0) (point))
1476 (indent-to column)))
1477 (goto-char (point-max))
1478 ;; (tabify (point-min)(point-max))
1481 (defun insert-char-data-with-variant (char &optional printable
1483 script excluded-script)
1484 (insert-char-data char printable)
1485 (let ((variants (char-variants char))
1488 (setq variants (sort variants #'<))
1489 (setq rest variants)
1490 (setq variants (cons char variants))
1492 (setq variant (car rest))
1493 (unless (get-char-attribute variant '<-subsumptive)
1494 (if (and (or (null script)
1495 (null (setq vs (get-char-attribute variant 'script)))
1497 (or (null excluded-script)
1498 (null (setq vs (get-char-attribute variant 'script)))
1499 (not (memq excluded-script vs))))
1500 (unless (and no-ucs-unified (get-char-attribute variant '=ucs))
1501 (insert-char-data variant printable)
1502 (if (setq ret (char-variants variant))
1504 (or (memq (car ret) variants)
1505 ;; (get-char-attribute (car ret) '<-subsumptive)
1506 (setq rest (nconc rest (list (car ret)))))
1507 (setq ret (cdr ret)))))))
1508 (setq rest (cdr rest)))))
1510 (defun insert-char-range-data (min max &optional script excluded-script)
1513 (while (<= code max)
1514 (setq char (decode-char '=ucs code))
1515 (if (encode-char char '=ucs 'defined-only)
1516 (insert-char-data-with-variant char nil 'no-ucs-unified
1517 script excluded-script))
1518 (setq code (1+ code)))))
1520 (defun write-char-range-data-to-file (min max file
1521 &optional script excluded-script)
1522 (let ((coding-system-for-write char-db-file-coding-system))
1524 (insert (format ";; -*- coding: %s -*-\n"
1525 char-db-file-coding-system))
1526 (insert-char-range-data min max script excluded-script)
1527 (write-region (point-min)(point-max) file))))
1529 (defvar what-character-original-window-configuration)
1532 (defun what-char-definition (char)
1533 (interactive (list (char-after)))
1534 (let ((buf (get-buffer-create "*Character Description*"))
1535 (the-buf (current-buffer))
1536 (win-conf (current-window-configuration)))
1538 (make-local-variable 'what-character-original-window-configuration)
1539 (setq what-character-original-window-configuration win-conf)
1540 (setq buffer-read-only nil)
1544 (insert-char-data-with-variant char 'printable)
1545 (unless (char-attribute-alist char)
1546 (insert (format ";; = %c\n"
1547 (let* ((rest (split-char char))
1551 (setq code (logior (lsh code 8)
1553 (decode-char ccs code)))))
1554 ;; (char-db-update-comment)
1555 (set-buffer-modified-p nil)
1556 (view-mode the-buf (lambda (buf)
1557 (set-window-configuration
1558 what-character-original-window-configuration)
1560 (goto-char (point-min)))
1562 (set-window-configuration
1563 what-character-original-window-configuration)
1564 (signal (car err) (cdr err)))))))
1570 (provide 'char-db-util)
1572 ;;; char-db-util.el ends here