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 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
212 ;; =>>>adobe-japan1-0
213 ;; =>>>adobe-japan1-1
214 ;; =>>>adobe-japan1-2
215 ;; =>>>adobe-japan1-3
216 ;; =>>>adobe-japan1-4
217 ;; =>>>adobe-japan1-5
218 ;; =>>>adobe-japan1-6
222 ;; =>>>hanyo-denshi/ja
223 ;; =>>>hanyo-denshi/jb
224 ;; =>>>hanyo-denshi/jc
225 ;; =>>>hanyo-denshi/ft
226 ;; =>>>hanyo-denshi/ib
227 ;; =>>>hanyo-denshi/hg
228 ;; =>>>hanyo-denshi/jt
229 ;; =>>>hanyo-denshi/ks
348 ;;; @ char-db formatters
351 (defun char-db-make-char-spec (char)
353 (cond ((characterp char)
354 (cond ((and (setq ret (encode-char char '=ucs 'defined-only))
355 (not (and (<= #xE000 ret)(<= ret #xF8FF))))
356 (setq char-spec (list (cons '=ucs ret)))
357 (cond ((setq ret (get-char-attribute char 'name))
358 (setq char-spec (cons (cons 'name ret) char-spec))
360 ((setq ret (get-char-attribute char 'name*))
361 (setq char-spec (cons (cons 'name* ret) char-spec))
364 ((encode-char char '=mj 'defined-only)
366 (dolist (ccs (charset-list))
367 (if (and (or (eq ccs '=mj)
368 ;; (eq (charset-property ccs 'iso-ir) 177)
369 (string-match "=ucs@" (symbol-name ccs))
371 (setq ccs (charset-name ccs))
372 (null (assq ccs char-spec))
373 (setq ret (encode-char char ccs 'defined-only)))
374 (setq char-spec (cons (cons ccs ret) char-spec))))
376 ((encode-char char '==mj 'defined-only)
378 (dolist (ccs (charset-list))
379 (if (and (or (eq ccs '==mj)
380 ;; (eq (charset-property ccs 'iso-ir) 177)
381 (string-match "=ucs@" (symbol-name ccs))
383 (setq ccs (charset-name ccs))
384 (null (assq ccs char-spec))
385 (setq ret (encode-char char ccs 'defined-only)))
386 (setq char-spec (cons (cons ccs ret) char-spec))))
388 ((encode-char char '=adobe-japan1 'defined-only)
390 (dolist (ccs (charset-list))
391 (if (and (or (memq ccs
400 ;; (eq (charset-property ccs 'iso-ir) 177)
401 (string-match "=ucs@" (symbol-name ccs))
403 (setq ccs (charset-name ccs))
404 (null (assq ccs char-spec))
405 (setq ret (encode-char char ccs 'defined-only)))
406 (setq char-spec (cons (cons ccs ret) char-spec))))
408 ((encode-char char '==adobe-japan1 'defined-only)
410 (dolist (ccs (charset-list))
411 (if (and (or (memq ccs
420 ;; (eq (charset-property ccs 'iso-ir) 177)
421 (string-match "=ucs@" (symbol-name ccs))
423 (setq ccs (charset-name ccs))
424 (null (assq ccs char-spec))
425 (setq ret (encode-char char ccs 'defined-only)))
426 (setq char-spec (cons (cons ccs ret) char-spec))))
430 (let ((rest char-db-coded-charset-priority-list)
433 (setq ccs (charset-name
434 (find-charset (car rest))))
436 (encode-char char ccs
438 (throw 'tag (cons ccs ret)))
439 (setq rest (cdr rest))))))
440 (setq char-spec (list ret))
441 (dolist (ccs (delq (car ret) (charset-list)))
442 (if (and (or (charset-iso-final-char ccs)
449 (eq (charset-property ccs 'iso-ir) 177)
450 ;; (string-match "=ucs@" (symbol-name ccs))
452 (setq ccs (charset-name ccs))
453 (null (assq ccs char-spec))
454 (setq ret (encode-char char ccs 'defined-only)))
455 (setq char-spec (cons (cons ccs ret) char-spec))))
457 (setq char-spec (split-char char)))
458 (cond ((setq ret (get-char-attribute char 'name))
459 (setq char-spec (cons (cons 'name ret) char-spec))
461 ((setq ret (get-char-attribute char 'name*))
462 (setq char-spec (cons (cons 'name* ret) char-spec))
465 ((setq ret (get-char-attribute
466 char 'ideographic-combination))
468 (cons (cons 'ideographic-combination ret)
475 (defun char-db-insert-char-spec (char &optional readable column
478 (setq column (current-column)))
479 (let (char-spec temp-char)
480 (setq char-spec (char-db-make-char-spec char))
481 (unless (or (characterp char) ; char
483 (setq char (find-char char-spec))
485 ;; define temporary character
486 ;; Current implementation is dirty.
487 (setq temp-char (define-char (cons '(ideograph-daikanwa . 0)
489 (remove-char-attribute temp-char 'ideograph-daikanwa)
490 (setq char temp-char))
491 (insert-char-attributes char
493 (union (mapcar #'car char-spec)
497 ;; undefine temporary character
498 ;; Current implementation is dirty.
499 (setq char-spec (char-attribute-alist temp-char))
501 (remove-char-attribute temp-char (car (car char-spec)))
502 (setq char-spec (cdr char-spec))))))
504 (defun char-db-insert-alist (alist &optional readable column)
506 (setq column (current-column)))
508 (concat "\n" (make-string (1+ column) ?\ )))
512 lbs cell rest separator)
515 (setq name (car (car alist))
516 value (cdr (car alist)))
517 (cond ((eq name 'char)
519 (if (setq ret (condition-case nil
527 (setq key (car (car value)))
528 ;; (if (find-charset key)
529 ;; (setq cal (cons key cal))
530 (setq al (cons key al))
532 (setq value (cdr value)))
533 (insert-char-attributes ret
537 (insert (prin1-to-string value)))
539 (insert line-breaking))
541 (insert (format "(%-18s " name))
542 (setq lbs (concat "\n" (make-string (current-column) ?\ )))
544 (setq cell (car value))
545 (if (and (consp cell)
547 (setq ret (condition-case nil
557 (setq key (car (car rest)))
558 ;; (if (find-charset key)
559 ;; (setq cal (cons key cal))
560 (setq al (cons key al))
562 (setq rest (cdr rest)))
565 (insert-char-attributes ret
569 (setq separator lbs))
572 (insert (prin1-to-string cell))
573 (setq separator " "))
574 (setq value (cdr value)))
576 (insert line-breaking))
578 (insert (format "(%-18s . %S)%s"
581 (setq alist (cdr alist))))
584 (defun char-db-insert-char-reference (plist &optional readable column)
586 (setq column (current-column)))
588 (concat "\n" (make-string (1+ column) ?\ )))
593 (setq name (pop plist))
594 (setq value (pop plist))
595 (cond ((eq name :char)
598 (cond ((numberp value)
599 (setq value (decode-char '=ucs value)))
601 ;; (setq value (or (find-char value)
604 (char-db-insert-char-spec value readable)
605 (insert line-breaking)
608 (insert (format "%s%s\t%d ; %c%s"
611 (ideographic-radical value)
615 (insert (format "%s%s\t%S" separator name value))
616 (setq separator line-breaking)))
620 (defun char-db-decode-isolated-char (ccs code-point)
623 (cond ((eq ccs 'arabic-iso8859-6)
624 (decode-char ccs code-point))
626 ;; (decode-builtin-char '==gt code-point))
627 ((and (memq ccs '(=gt-pj-1
638 (setq ret (decode-char ccs code-point))
639 (setq ret (encode-char ret '=gt 'defined-only)))
640 (decode-builtin-char '=gt ret))
642 (decode-builtin-char ccs code-point))))
644 (or (decode-char ccs code-point)
645 (define-char (list (cons ccs code-point)))))
646 ((and (<= 0 (char-int ret))
647 (<= (char-int ret) #x1F))
648 (decode-char '=ucs (+ #x2400 (char-int ret))))
649 ((= (char-int ret) #x7F)
653 (defvar char-db-convert-obsolete-format t)
655 (defun char-db-insert-ccs-feature (name value line-breaking)
661 ((memq name '(=>iwds-1
664 =shinjigen@1ed ==shinjigen@1ed
665 =shinjigen@rev ==shinjigen@rev
666 =shinjigen/+p@rev ==shinjigen/+p@rev
667 ===daikanwa/ho ==daikanwa/ho
668 =daikanwa/ho =>>daikanwa/ho =>daikanwa/ho))
669 "(%-18s . %04d)\t; %c")
670 ((eq name '=shinjigen@1ed/24pr)
671 "(%-18s . %04d)\t; %c")
675 ==daikanwa =daikanwa =>>daikanwa =>daikanwa
676 =daikanwa@rev1 =daikanwa@rev2
677 =daikanwa/+p ==daikanwa/+p ===daikanwa/+p
679 =daikanwa/+2p =>>daikanwa/+2p
684 =adobe-japan1-0 ==adobe-japan1-0 ===adobe-japan1-0
685 =adobe-japan1-1 ==adobe-japan1-1 ===adobe-japan1-1
686 =adobe-japan1-2 ==adobe-japan1-2 ===adobe-japan1-2
687 =adobe-japan1-3 ==adobe-japan1-3 ===adobe-japan1-3
688 =adobe-japan1-4 ==adobe-japan1-4 ===adobe-japan1-4
689 =adobe-japan1-5 ==adobe-japan1-5 ===adobe-japan1-5
690 =adobe-japan1-6 ==adobe-japan1-6 ===adobe-japan1-6
691 =>>adobe-japan1-0 =+>adobe-japan1-0
692 =>>adobe-japan1-1 =+>adobe-japan1-1
693 =>>adobe-japan1-2 =+>adobe-japan1-2
694 =>>adobe-japan1-3 =+>adobe-japan1-3
695 =>>adobe-japan1-4 =+>adobe-japan1-4
696 =>>adobe-japan1-5 =+>adobe-japan1-5
697 =>>adobe-japan1-6 =+>adobe-japan1-6
698 =>cbeta =cbeta =>>cbeta ==cbeta ===cbeta
699 =zinbun-oracle =>zinbun-oracle
700 ===hng-jou ===hng-keg ===hng-dng ===hng-mam
701 ===hng-drt ===hng-kgk ===hng-myz ===hng-kda
702 ===hng-khi ===hng-khm ===hng-hok ===hng-kyd ===hng-sok
703 ===hng-yhk ===hng-kak ===hng-kar ===hng-kae
704 ===hng-sys ===hng-tsu ===hng-tzj
705 ===hng-hos ===hng-nak ===hng-jhk
706 ===hng-hod ===hng-gok ===hng-ink ===hng-nto
707 ===hng-nkm ===hng-k24 ===hng-nkk
708 ===hng-kcc ===hng-kcj ===hng-kbk ===hng-sik
709 ===hng-skk ===hng-kyu ===hng-ksk ===hng-wan
710 ===hng-okd ===hng-wad ===hng-kmi
711 ===hng-zkd ===hng-doh ===hng-jyu
712 ===hng-tzs ===hng-kss ===hng-kyo
714 ;; (string-match "^=adobe-" (symbol-name name))
716 "(%-18s . %05d)\t; %c")
717 ((memq name '(=hanyo-denshi/ks
718 ==hanyo-denshi/ks ===hanyo-denshi/ks
721 =mj ==mj ===mj =>>mj =>mj
723 "(%-18s . %06d)\t; %c")
724 ((memq name '(=hanyo-denshi/tk ==hanyo-denshi/tk))
725 "(%-18s . %08d)\t; %c")
726 ((>= (charset-dimension name) 2)
727 "(%-18s . #x%04X)\t; %c")
729 "(%-18s . #x%02X)\t; %c"))
731 (if (= (charset-iso-graphic-plane name) 1)
733 (cond ((= (charset-dimension name) 1)
735 ((= (charset-dimension name) 2)
737 ((= (charset-dimension name) 3)
741 (char-db-decode-isolated-char name value)))
742 (if (and (= (charset-chars name) 94)
743 (= (charset-dimension name) 2))
744 (insert (format " [%02d-%02d]"
745 (- (lsh value -8) 32)
746 (- (logand value 255) 32))))
749 (insert (format "(%-18s . %s)" name value))
751 (insert line-breaking))
753 (defun char-db-insert-relation-feature (char name value line-breaking
755 (insert (format "(%-18s%s " name line-breaking))
756 (let ((lbs (concat "\n" (make-string (current-column) ?\ )))
757 separator cell sources required-features
760 (setq cell (car value))
762 (setq cell (decode-char '=ucs cell)))
764 ((eq name '->subsumptive)
765 (when (or (not (some (lambda (atr)
766 (get-char-attribute cell atr))
767 char-db-ignored-attributes))
769 (encode-char cell ccs 'defined-only))
773 (let ((char-db-ignored-attributes
775 char-db-ignored-attributes)))
776 (insert-char-attributes cell readable nil nil 'for-sub-node))
777 (setq separator lbs))
782 char (intern (format "%s*sources" name))))
783 (setq required-features nil)
784 (dolist (source sources)
788 shinjigen shinjigen@1ed shinjigen@rev))
789 (setq required-features
790 (union required-features
802 =shinjigen/+p@rev))))
804 (setq required-features
805 (union required-features
810 ((find-charset (setq ret (intern (format "=%s" source))))
811 (setq required-features
812 (cons ret required-features)))
813 (t (setq required-features
814 (cons source required-features)))))
815 (cond ((string-match "@JP" (symbol-name name))
816 (setq required-features
817 (union required-features
825 ((string-match "@CN" (symbol-name name))
826 (setq required-features
827 (union required-features
834 (insert (format "%S" cell))
835 (char-db-insert-char-spec cell readable
838 (setq separator lbs))
842 (if (consp (car cell))
843 (char-db-insert-char-spec cell readable)
844 (char-db-insert-char-reference cell readable))
845 (setq separator lbs))
849 (insert (prin1-to-string cell))
850 (setq separator " ")))
851 (setq value (cdr value)))
853 (insert line-breaking)))
855 (defun insert-char-attributes (char &optional readable attributes column
858 (setq column (current-column)))
859 (let (name value ; has-long-ccs-name
863 (concat "\n" (make-string (1+ column) ?\ )))
864 lbs cell separator ret
866 dest-ccss ; sources required-features
871 (if (consp attributes)
873 (dolist (name attributes)
874 (unless (memq name char-db-ignored-attributes)
875 (if (find-charset name)
879 (dolist (name (char-attribute-list))
880 (unless (memq name char-db-ignored-attributes)
881 (if (find-charset name)
885 #'char-attribute-name<)))
887 (when (memq '<-subsumptive attributes)
888 (when (or readable (not for-sub-node))
889 (when (setq value (get-char-attribute char '<-subsumptive))
890 (char-db-insert-relation-feature char '<-subsumptive value
893 (setq attributes (delq '<-subsumptive attributes)))
894 (when (and (memq '<-denotational attributes)
895 (setq value (get-char-attribute char '<-denotational)))
896 (char-db-insert-relation-feature char '<-denotational value
899 (setq attributes (delq '<-denotational attributes)))
900 (when (and (memq '<-denotational@component attributes)
901 (setq value (get-char-attribute char '<-denotational@component)))
902 (char-db-insert-relation-feature char '<-denotational@component value
905 (setq attributes (delq '<-denotational@component 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 'name* attributes)
916 (setq value (get-char-attribute char 'name*)))
918 (if (> (+ (current-column) (length value)) 48)
921 value line-breaking))
922 (setq attributes (delq 'name* attributes))
924 (when (and (memq 'script attributes)
925 (setq value (get-char-attribute char 'script)))
926 (insert (format "(script\t\t%s)%s"
927 (mapconcat (function prin1-to-string)
930 (setq attributes (delq 'script attributes))
932 (dolist (name '(=>ucs =>ucs*))
933 (when (and (memq name attributes)
934 (setq value (get-char-attribute char name)))
935 (insert (format "(%-18s . #x%04X)\t; %c%s"
936 name value (decode-char '=ucs value)
938 (setq attributes (delq name attributes))))
939 (dolist (name '(=>ucs@gb =>ucs@big5))
940 (when (and (memq name attributes)
941 (setq value (get-char-attribute char name)))
942 (insert (format "(%-18s . #x%04X)\t; %c%s"
947 (symbol-name name) 2)))
950 (setq attributes (delq name attributes))
952 ;; (dolist (name '(=>daikanwa))
953 ;; (when (and (memq name attributes)
954 ;; (setq value (get-char-attribute char name)))
956 ;; (if (integerp value)
957 ;; (format "(%-18s . %05d)\t; %c%s"
958 ;; name value (decode-char '=daikanwa value)
960 ;; (format "(%-18s %s)\t; %c%s"
962 ;; (mapconcat (function prin1-to-string)
964 ;; (char-representative-of-daikanwa char)
966 ;; (setq attributes (delq name attributes))))
967 (when (and (memq 'general-category attributes)
968 (setq value (get-char-attribute char 'general-category)))
970 "(general-category\t%s) ; %s%s"
971 (mapconcat (lambda (cell)
974 (cond ((rassoc value unidata-normative-category-alist)
975 "Normative Category")
976 ((rassoc value unidata-informative-category-alist)
977 "Informative Category")
981 (setq attributes (delq 'general-category attributes))
983 (when (and (memq 'bidi-category attributes)
984 (setq value (get-char-attribute char 'bidi-category)))
985 (insert (format "(bidi-category\t. %S)%s"
988 (setq attributes (delq 'bidi-category attributes))
990 (unless (or (not (memq 'mirrored attributes))
991 (eq (setq value (get-char-attribute char 'mirrored 'empty))
993 (insert (format "(mirrored\t\t. %S)%s"
996 (setq attributes (delq 'mirrored attributes))
999 ((and (memq 'decimal-digit-value attributes)
1000 (setq value (get-char-attribute char 'decimal-digit-value)))
1001 (insert (format "(decimal-digit-value . %S)%s"
1004 (setq attributes (delq 'decimal-digit-value attributes))
1005 (when (and (memq 'digit-value attributes)
1006 (setq value (get-char-attribute char 'digit-value)))
1007 (insert (format "(digit-value\t . %S)%s"
1010 (setq attributes (delq 'digit-value attributes))
1012 (when (and (memq 'numeric-value attributes)
1013 (setq value (get-char-attribute char 'numeric-value)))
1014 (insert (format "(numeric-value\t . %S)%s"
1017 (setq attributes (delq 'numeric-value attributes))
1021 (when (and (memq 'digit-value attributes)
1022 (setq value (get-char-attribute char 'digit-value)))
1023 (insert (format "(digit-value\t. %S)%s"
1026 (setq attributes (delq 'digit-value attributes))
1028 (when (and (memq 'numeric-value attributes)
1029 (setq value (get-char-attribute char 'numeric-value)))
1030 (insert (format "(numeric-value\t. %S)%s"
1033 (setq attributes (delq 'numeric-value attributes))
1035 (when (and (memq 'iso-10646-comment attributes)
1036 (setq value (get-char-attribute char 'iso-10646-comment)))
1037 (insert (format "(iso-10646-comment\t. %S)%s"
1040 (setq attributes (delq 'iso-10646-comment attributes))
1042 (when (and (memq 'morohashi-daikanwa attributes)
1043 (setq value (get-char-attribute char 'morohashi-daikanwa)))
1044 (insert (format "(morohashi-daikanwa\t%s)%s"
1045 (mapconcat (function prin1-to-string) value " ")
1047 (setq attributes (delq 'morohashi-daikanwa attributes))
1051 (when (and (memq 'ideographic-radical attributes)
1052 (setq value (get-char-attribute char 'ideographic-radical)))
1053 (setq radical value)
1054 (insert (format "(ideographic-radical . %S)\t; %c%s"
1056 (ideographic-radical radical)
1058 (setq attributes (delq 'ideographic-radical attributes))
1060 (when (and (memq 'shuowen-radical attributes)
1061 (setq value (get-char-attribute char 'shuowen-radical)))
1062 (insert (format "(shuowen-radical\t. %S)\t; %c%s"
1064 (shuowen-radical value)
1066 (setq attributes (delq 'shuowen-radical attributes))
1071 char-db-feature-domains
1073 (dolist (feature (char-attribute-list))
1074 (setq feature (symbol-name feature))
1076 "\\(radical\\|strokes\\)@\\([^@*]+\\)\\(\\*\\|$\\)"
1078 (setq domain (intern (match-string 2 feature)))
1079 (unless (memq domain dest)
1080 (setq dest (cons domain dest)))))
1081 (sort dest #'string<))))
1082 (setq key (intern (format "%s@%s" 'ideographic-radical domain)))
1083 (when (and (memq key attributes)
1084 (setq value (get-char-attribute char key)))
1085 (setq radical value)
1086 (insert (format "(%s . %S)\t; %c%s"
1089 (ideographic-radical radical)
1091 (setq attributes (delq key attributes))
1093 (setq key (intern (format "%s@%s" 'ideographic-strokes domain)))
1094 (when (and (memq key attributes)
1095 (setq value (get-char-attribute char key)))
1096 (setq strokes value)
1097 (insert (format "(%s . %S)%s"
1101 (setq attributes (delq key attributes))
1103 (setq key (intern (format "%s@%s" 'total-strokes domain)))
1104 (when (and (memq key attributes)
1105 (setq value (get-char-attribute char key)))
1106 (insert (format "(%s . %S)%s"
1110 (setq attributes (delq key attributes))
1112 (dolist (feature '(ideographic-radical
1115 (setq key (intern (format "%s@%s*sources" feature domain)))
1116 (when (and (memq key attributes)
1117 (setq value (get-char-attribute char key)))
1118 (insert (format "(%s%s" key line-breaking))
1119 (dolist (cell value)
1120 (insert (format " %s" cell)))
1122 (insert line-breaking)
1123 (setq attributes (delq key attributes))
1126 (when (and (memq 'ideographic-strokes attributes)
1127 (setq value (get-char-attribute char 'ideographic-strokes)))
1128 (setq strokes value)
1129 (insert (format "(ideographic-strokes . %S)%s"
1132 (setq attributes (delq 'ideographic-strokes attributes))
1134 (when (and (memq 'kangxi-radical attributes)
1135 (setq value (get-char-attribute char 'kangxi-radical)))
1136 (unless (eq value radical)
1137 (insert (format "(kangxi-radical\t . %S)\t; %c%s"
1139 (ideographic-radical value)
1142 (setq radical value)))
1143 (setq attributes (delq 'kangxi-radical attributes))
1145 (when (and (memq 'kangxi-strokes attributes)
1146 (setq value (get-char-attribute char 'kangxi-strokes)))
1147 (unless (eq value strokes)
1148 (insert (format "(kangxi-strokes\t . %S)%s"
1152 (setq strokes value)))
1153 (setq attributes (delq 'kangxi-strokes attributes))
1155 (when (and (memq 'japanese-radical attributes)
1156 (setq value (get-char-attribute char 'japanese-radical)))
1157 (unless (eq value radical)
1158 (insert (format "(japanese-radical\t . %S)\t; %c%s"
1160 (ideographic-radical value)
1163 (setq radical value)))
1164 (setq attributes (delq 'japanese-radical attributes))
1166 (when (and (memq 'japanese-strokes attributes)
1167 (setq value (get-char-attribute char 'japanese-strokes)))
1168 (unless (eq value strokes)
1169 (insert (format "(japanese-strokes\t . %S)%s"
1173 (setq strokes value)))
1174 (setq attributes (delq 'japanese-strokes attributes))
1176 (when (and (memq 'cns-radical attributes)
1177 (setq value (get-char-attribute char 'cns-radical)))
1178 (insert (format "(cns-radical\t . %S)\t; %c%s"
1180 (ideographic-radical value)
1182 (setq attributes (delq 'cns-radical attributes))
1184 (when (and (memq 'cns-strokes attributes)
1185 (setq value (get-char-attribute char 'cns-strokes)))
1186 (unless (eq value strokes)
1187 (insert (format "(cns-strokes\t . %S)%s"
1191 (setq strokes value)))
1192 (setq attributes (delq 'cns-strokes attributes))
1194 ;; (when (and (memq 'shinjigen-1-radical attributes)
1195 ;; (setq value (get-char-attribute char 'shinjigen-1-radical)))
1196 ;; (unless (eq value radical)
1197 ;; (insert (format "(shinjigen-1-radical . %S)\t; %c%s"
1199 ;; (ideographic-radical value)
1202 ;; (setq radical value)))
1203 ;; (setq attributes (delq 'shinjigen-1-radical attributes))
1205 (when (and (memq 'ideographic- attributes)
1206 (setq value (get-char-attribute char 'ideographic-)))
1207 (insert "(ideographic- ")
1208 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1210 (while (consp value)
1211 (setq cell (car value))
1213 (setq cell (decode-char '=ucs cell)))
1214 (cond ((characterp cell)
1218 (insert (format "%S" cell))
1219 (char-db-insert-char-spec cell readable))
1220 (setq separator lbs))
1224 (if (consp (car cell))
1225 (char-db-insert-char-spec cell readable)
1226 (char-db-insert-char-reference cell readable))
1227 (setq separator lbs))
1231 (insert (prin1-to-string cell))
1232 (setq separator " ")))
1233 (setq value (cdr value)))
1235 (insert line-breaking)
1236 (setq attributes (delq 'ideographic- attributes)))
1237 (when (and (memq 'total-strokes attributes)
1238 (setq value (get-char-attribute char 'total-strokes)))
1239 (insert (format "(total-strokes . %S)%s"
1242 (setq attributes (delq 'total-strokes attributes))
1244 (when (and (memq '->ideograph attributes)
1245 (setq value (get-char-attribute char '->ideograph)))
1246 (insert (format "(->ideograph\t%s)%s"
1247 (mapconcat (lambda (code)
1248 (cond ((symbolp code)
1251 (format "#x%04X" code))
1254 line-breaking code))))
1257 (setq attributes (delq '->ideograph attributes))
1259 ;; (when (and (memq '->decomposition attributes)
1260 ;; (setq value (get-char-attribute char '->decomposition)))
1261 ;; (insert (format "(->decomposition\t%s)%s"
1262 ;; (mapconcat (lambda (code)
1263 ;; (cond ((symbolp code)
1264 ;; (symbol-name code))
1265 ;; ((characterp code)
1267 ;; (format "%S" code)
1272 ;; (format "#x%04X" code))
1274 ;; (format "%s%S" line-breaking code))))
1277 ;; (setq attributes (delq '->decomposition attributes))
1279 (if (equal (get-char-attribute char '->titlecase)
1280 (get-char-attribute char '->uppercase))
1281 (setq attributes (delq '->titlecase attributes)))
1282 (when (and (memq '->mojikyo attributes)
1283 (setq value (get-char-attribute char '->mojikyo)))
1284 (insert (format "(->mojikyo\t\t. %06d)\t; %c%s"
1285 value (decode-char 'mojikyo value)
1287 (setq attributes (delq '->mojikyo attributes))
1289 (when (and (memq 'hanyu-dazidian-vol attributes)
1290 (setq value (get-char-attribute char 'hanyu-dazidian-vol)))
1291 (insert (format "(hanyu-dazidian-vol . %d)%s"
1292 value line-breaking))
1293 (setq attributes (delq 'hanyu-dazidian-vol attributes))
1295 (when (and (memq 'hanyu-dazidian-page attributes)
1296 (setq value (get-char-attribute char 'hanyu-dazidian-page)))
1297 (insert (format "(hanyu-dazidian-page . %d)%s"
1298 value line-breaking))
1299 (setq attributes (delq 'hanyu-dazidian-page attributes))
1301 (when (and (memq 'hanyu-dazidian-char attributes)
1302 (setq value (get-char-attribute char 'hanyu-dazidian-char)))
1303 (insert (format "(hanyu-dazidian-char . %d)%s"
1304 value line-breaking))
1305 (setq attributes (delq 'hanyu-dazidian-char attributes))
1308 (dolist (ignored '(composition
1309 ->denotational <-subsumptive ->ucs-unified
1310 ->ideographic-component-forms))
1311 (setq attributes (delq ignored attributes))))
1313 (setq name (car attributes))
1314 (unless (eq (setq value (get-char-attribute char name 'value-is-empty))
1316 (cond ((setq ret (find-charset name))
1317 (setq name (charset-name ret))
1318 (when (not (memq name dest-ccss))
1319 (setq dest-ccss (cons name dest-ccss))
1320 (char-db-insert-ccs-feature name value line-breaking))
1322 ((string-match "^=>ucs@" (symbol-name name))
1323 (insert (format "(%-18s . #x%04X)\t; %c%s"
1324 name value (decode-char '=ucs value)
1327 ((eq name 'jisx0208-1978/4X)
1328 (insert (format "(%-18s . #x%04X)%s"
1334 (not (eq name '->subsumptive))
1335 (not (eq name '->uppercase))
1336 (not (eq name '->lowercase))
1337 (not (eq name '->titlecase))
1338 (not (eq name '->canonical))
1339 (not (eq name '->Bopomofo))
1340 (not (eq name '->mistakable))
1341 (not (eq name '->ideographic-variants))
1342 (null (get-char-attribute
1343 char (intern (format "%s*sources" name))))
1344 (not (string-match "\\*sources$" (symbol-name name)))
1345 (null (get-char-attribute
1346 char (intern (format "%s*note" name))))
1347 (not (string-match "\\*note$" (symbol-name name)))
1348 (or (eq name '<-identical)
1349 (eq name '<-uppercase)
1350 (eq name '<-lowercase)
1351 (eq name '<-titlecase)
1352 (eq name '<-canonical)
1353 (eq name '<-ideographic-variants)
1354 ;; (eq name '<-synonyms)
1355 (string-match "^<-synonyms" (symbol-name name))
1356 (eq name '<-mistakable)
1357 (when (string-match "^->" (symbol-name name))
1359 ((string-match "^->fullwidth" (symbol-name name))
1360 (not (and (consp value)
1361 (characterp (car value))
1363 (car value) '=ucs 'defined-only)))
1368 ((or (eq name 'ideographic-structure)
1369 (eq name 'ideographic-combination)
1370 (eq name 'ideographic-)
1371 (eq name '=decomposition)
1372 (char-feature-base-name= '=decomposition name)
1373 (char-feature-base-name= '=>decomposition name)
1374 ;; (string-match "^=>*decomposition\\(@[^*]+\\)?$"
1375 ;; (symbol-name name))
1376 (string-match "^\\(->\\|<-\\)[^*]*$" (symbol-name name))
1377 (string-match "^\\(->\\|<-\\)[^*]*\\*sources$"
1380 (char-db-insert-relation-feature char name value
1383 ((memq name '(ideograph=
1384 original-ideograph-of
1385 ancient-ideograph-of
1388 ;; simplified-ideograph-of
1389 ideographic-variants
1390 ;; ideographic-different-form-of
1392 (insert (format "(%-18s%s " name line-breaking))
1393 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1395 (while (consp value)
1396 (setq cell (car value))
1397 (if (and (consp cell)
1402 (char-db-insert-alist cell readable)
1403 (setq separator lbs))
1406 (insert (prin1-to-string cell))
1407 (setq separator " "))
1408 (setq value (cdr value)))
1410 (insert line-breaking))
1412 (insert (format "(%-18s " name))
1413 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1415 (while (consp value)
1416 (setq cell (car value))
1417 (if (and (consp cell)
1419 (setq ret (condition-case nil
1427 (setq key (car (car rest)))
1428 (if (find-charset key)
1429 (setq cal (cons key cal))
1430 (setq al (cons key al)))
1431 (setq rest (cdr rest)))
1434 (insert-char-attributes ret
1438 (setq separator lbs))
1439 (setq ret (prin1-to-string cell))
1441 (if (< (+ (current-column)
1448 (setq separator " "))
1449 (setq value (cdr value)))
1451 (insert line-breaking))
1453 (insert (format "(%-18s" name))
1454 (setq ret (prin1-to-string value))
1455 (unless (< (+ (current-column)
1459 (insert line-breaking))
1460 (insert " . " ret ")" line-breaking)
1461 ;; (insert (format "(%-18s . %S)%s"
1466 (setq attributes (cdr attributes)))
1469 (defun insert-char-data (char &optional readable
1472 (narrow-to-region (point)(point))
1473 (insert "(define-char
1475 (insert-char-attributes char readable attributes)
1477 (goto-char (point-min))
1478 (while (re-search-forward "[ \t]+$" nil t)
1481 (goto-char (point-min))
1482 (while (re-search-forward "[ \t][ \t][ \t]*" nil t)
1483 (let ((column (current-column))
1484 (indent-tabs-mode t))
1485 (delete-region (match-beginning 0) (point))
1486 (indent-to column)))
1487 (goto-char (point-max))
1488 ;; (tabify (point-min)(point-max))
1491 (defun insert-char-data-with-variant (char &optional printable
1493 script excluded-script)
1494 (insert-char-data char printable)
1495 (let ((variants (char-variants char))
1498 (setq variants (sort variants #'<))
1499 (setq rest variants)
1500 (setq variants (cons char variants))
1502 (setq variant (car rest))
1503 (unless (get-char-attribute variant '<-subsumptive)
1504 (if (and (or (null script)
1505 (null (setq vs (get-char-attribute variant 'script)))
1507 (or (null excluded-script)
1508 (null (setq vs (get-char-attribute variant 'script)))
1509 (not (memq excluded-script vs))))
1510 (unless (and no-ucs-unified (get-char-attribute variant '=ucs))
1511 (insert-char-data variant printable)
1512 (if (setq ret (char-variants variant))
1514 (or (memq (car ret) variants)
1515 ;; (get-char-attribute (car ret) '<-subsumptive)
1516 (setq rest (nconc rest (list (car ret)))))
1517 (setq ret (cdr ret)))))))
1518 (setq rest (cdr rest)))))
1520 (defun insert-char-range-data (min max &optional script excluded-script)
1523 (while (<= code max)
1524 (setq char (decode-char '=ucs code))
1525 (if (encode-char char '=ucs 'defined-only)
1526 (insert-char-data-with-variant char nil 'no-ucs-unified
1527 script excluded-script))
1528 (setq code (1+ code)))))
1530 (defun write-char-range-data-to-file (min max file
1531 &optional script excluded-script)
1532 (let ((coding-system-for-write char-db-file-coding-system))
1534 (insert (format ";; -*- coding: %s -*-\n"
1535 char-db-file-coding-system))
1536 (insert-char-range-data min max script excluded-script)
1537 (write-region (point-min)(point-max) file))))
1539 (defvar what-character-original-window-configuration)
1542 (defun what-char-definition (char)
1543 (interactive (list (char-after)))
1544 (let ((buf (get-buffer-create "*Character Description*"))
1545 (the-buf (current-buffer))
1546 (win-conf (current-window-configuration)))
1548 (make-local-variable 'what-character-original-window-configuration)
1549 (setq what-character-original-window-configuration win-conf)
1550 (setq buffer-read-only nil)
1554 (insert-char-data-with-variant char 'printable)
1555 (unless (char-attribute-alist char)
1556 (insert (format ";; = %c\n"
1557 (let* ((rest (split-char char))
1561 (setq code (logior (lsh code 8)
1563 (decode-char ccs code)))))
1564 ;; (char-db-update-comment)
1565 (set-buffer-modified-p nil)
1566 (view-mode the-buf (lambda (buf)
1567 (set-window-configuration
1568 what-character-original-window-configuration)
1570 (goto-char (point-min)))
1572 (set-window-configuration
1573 what-character-original-window-configuration)
1574 (signal (car err) (cdr err)))))))
1580 (provide 'char-db-util)
1582 ;;; char-db-util.el ends here