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
353 ;;; @ char-db formatters
356 (defun char-db-make-char-spec (char)
358 (cond ((characterp char)
359 (cond ((and (setq ret (encode-char char '=ucs 'defined-only))
360 (not (and (<= #xE000 ret)(<= ret #xF8FF))))
361 (setq char-spec (list (cons '=ucs ret)))
362 (cond ((setq ret (get-char-attribute char 'name))
363 (setq char-spec (cons (cons 'name ret) char-spec))
365 ((setq ret (get-char-attribute char 'name*))
366 (setq char-spec (cons (cons 'name* 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 '==mj 'defined-only)
383 (dolist (ccs (charset-list))
384 (if (and (or (eq ccs '==mj)
385 ;; (eq (charset-property ccs 'iso-ir) 177)
386 (string-match "=ucs@" (symbol-name ccs))
388 (setq ccs (charset-name ccs))
389 (null (assq ccs char-spec))
390 (setq ret (encode-char char ccs 'defined-only)))
391 (setq char-spec (cons (cons ccs ret) char-spec))))
393 ((encode-char char '=adobe-japan1 'defined-only)
395 (dolist (ccs (charset-list))
396 (if (and (or (memq ccs
405 ;; (eq (charset-property ccs 'iso-ir) 177)
406 (string-match "=ucs@" (symbol-name ccs))
408 (setq ccs (charset-name ccs))
409 (null (assq ccs char-spec))
410 (setq ret (encode-char char ccs 'defined-only)))
411 (setq char-spec (cons (cons ccs ret) char-spec))))
413 ((encode-char char '==adobe-japan1 'defined-only)
415 (dolist (ccs (charset-list))
416 (if (and (or (memq ccs
425 ;; (eq (charset-property ccs 'iso-ir) 177)
426 (string-match "=ucs@" (symbol-name ccs))
428 (setq ccs (charset-name ccs))
429 (null (assq ccs char-spec))
430 (setq ret (encode-char char ccs 'defined-only)))
431 (setq char-spec (cons (cons ccs ret) char-spec))))
435 (let ((rest char-db-coded-charset-priority-list)
438 (setq ccs (charset-name
439 (find-charset (car rest))))
441 (encode-char char ccs
443 (throw 'tag (cons ccs ret)))
444 (setq rest (cdr rest))))))
445 (setq char-spec (list ret))
446 (dolist (ccs (delq (car ret) (charset-list)))
447 (if (and (or (charset-iso-final-char ccs)
454 (eq (charset-property ccs 'iso-ir) 177)
455 ;; (string-match "=ucs@" (symbol-name ccs))
457 (setq ccs (charset-name ccs))
458 (null (assq ccs char-spec))
459 (setq ret (encode-char char ccs 'defined-only)))
460 (setq char-spec (cons (cons ccs ret) char-spec))))
462 (setq char-spec (split-char char)))
463 (cond ((setq ret (get-char-attribute char 'name))
464 (setq char-spec (cons (cons 'name ret) char-spec))
466 ((setq ret (get-char-attribute char 'name*))
467 (setq char-spec (cons (cons 'name* ret) char-spec))
470 ((setq ret (get-char-attribute
471 char 'ideographic-combination))
473 (cons (cons 'ideographic-combination ret)
480 (defun char-db-insert-char-spec (char &optional readable column
483 (setq column (current-column)))
484 (let (char-spec temp-char)
485 (setq char-spec (char-db-make-char-spec char))
486 (unless (or (characterp char) ; char
488 (setq char (find-char char-spec))
490 ;; define temporary character
491 ;; Current implementation is dirty.
492 (setq temp-char (define-char (cons '(ideograph-daikanwa . 0)
494 (remove-char-attribute temp-char 'ideograph-daikanwa)
495 (setq char temp-char))
496 (insert-char-attributes char
498 (union (mapcar #'car char-spec)
502 ;; undefine temporary character
503 ;; Current implementation is dirty.
504 (setq char-spec (char-attribute-alist temp-char))
506 (remove-char-attribute temp-char (car (car char-spec)))
507 (setq char-spec (cdr char-spec))))))
509 (defun char-db-insert-alist (alist &optional readable column)
511 (setq column (current-column)))
513 (concat "\n" (make-string (1+ column) ?\ )))
517 lbs cell rest separator)
520 (setq name (car (car alist))
521 value (cdr (car alist)))
522 (cond ((eq name 'char)
524 (if (setq ret (condition-case nil
532 (setq key (car (car value)))
533 ;; (if (find-charset key)
534 ;; (setq cal (cons key cal))
535 (setq al (cons key al))
537 (setq value (cdr value)))
538 (insert-char-attributes ret
542 (insert (prin1-to-string value)))
544 (insert line-breaking))
546 (insert (format "(%-18s " name))
547 (setq lbs (concat "\n" (make-string (current-column) ?\ )))
549 (setq cell (car value))
550 (if (and (consp cell)
552 (setq ret (condition-case nil
562 (setq key (car (car rest)))
563 ;; (if (find-charset key)
564 ;; (setq cal (cons key cal))
565 (setq al (cons key al))
567 (setq rest (cdr rest)))
570 (insert-char-attributes ret
574 (setq separator lbs))
577 (insert (prin1-to-string cell))
578 (setq separator " "))
579 (setq value (cdr value)))
581 (insert line-breaking))
583 (insert (format "(%-18s . %S)%s"
586 (setq alist (cdr alist))))
589 (defun char-db-insert-char-reference (plist &optional readable column)
591 (setq column (current-column)))
593 (concat "\n" (make-string (1+ column) ?\ )))
598 (setq name (pop plist))
599 (setq value (pop plist))
600 (cond ((eq name :char)
603 (cond ((numberp value)
604 (setq value (decode-char '=ucs value)))
606 ;; (setq value (or (find-char value)
609 (char-db-insert-char-spec value readable)
610 (insert line-breaking)
613 (insert (format "%s%s\t%d ; %c%s"
616 (ideographic-radical value)
620 (insert (format "%s%s\t%S" separator name value))
621 (setq separator line-breaking)))
625 (defun char-db-decode-isolated-char (ccs code-point)
628 (cond ((eq ccs 'arabic-iso8859-6)
629 (decode-char ccs code-point))
631 ;; (decode-builtin-char '==gt code-point))
632 ((and (memq ccs '(=gt-pj-1
643 (setq ret (decode-char ccs code-point))
644 (setq ret (encode-char ret '=gt 'defined-only)))
645 (decode-builtin-char '=gt ret))
647 (decode-builtin-char ccs code-point))))
649 (or (decode-char ccs code-point)
650 (define-char (list (cons ccs code-point)))))
651 ((and (<= 0 (char-int ret))
652 (<= (char-int ret) #x1F))
653 (decode-char '=ucs (+ #x2400 (char-int ret))))
654 ((= (char-int ret) #x7F)
658 (defvar char-db-convert-obsolete-format t)
660 (defun char-db-insert-ccs-feature (name value line-breaking)
666 ((memq name '(=>iwds-1
669 =shinjigen@1ed ==shinjigen@1ed
670 =shinjigen@rev ==shinjigen@rev
671 =shinjigen/+p@rev ==shinjigen/+p@rev
672 ===daikanwa/ho ==daikanwa/ho
673 =daikanwa/ho =>>daikanwa/ho =>daikanwa/ho))
674 "(%-18s . %04d)\t; %c")
675 ((eq name '=shinjigen@1ed/24pr)
676 "(%-18s . %04d)\t; %c")
680 ==daikanwa =daikanwa =>>daikanwa =>daikanwa
681 =daikanwa@rev1 =daikanwa@rev2
682 =daikanwa/+p ==daikanwa/+p ===daikanwa/+p
684 =daikanwa/+2p =>>daikanwa/+2p
689 =adobe-japan1-0 ==adobe-japan1-0 ===adobe-japan1-0
690 =adobe-japan1-1 ==adobe-japan1-1 ===adobe-japan1-1
691 =adobe-japan1-2 ==adobe-japan1-2 ===adobe-japan1-2
692 =adobe-japan1-3 ==adobe-japan1-3 ===adobe-japan1-3
693 =adobe-japan1-4 ==adobe-japan1-4 ===adobe-japan1-4
694 =adobe-japan1-5 ==adobe-japan1-5 ===adobe-japan1-5
695 =adobe-japan1-6 ==adobe-japan1-6 ===adobe-japan1-6
696 =>>adobe-japan1-0 =+>adobe-japan1-0
697 =>>adobe-japan1-1 =+>adobe-japan1-1
698 =>>adobe-japan1-2 =+>adobe-japan1-2
699 =>>adobe-japan1-3 =+>adobe-japan1-3
700 =>>adobe-japan1-4 =+>adobe-japan1-4
701 =>>adobe-japan1-5 =+>adobe-japan1-5
702 =>>adobe-japan1-6 =+>adobe-japan1-6
703 =>cbeta =cbeta =>>cbeta ==cbeta ===cbeta
704 =zinbun-oracle =>zinbun-oracle
705 ===hng-jou ===hng-keg ===hng-dng ===hng-mam
706 ===hng-drt ===hng-kgk ===hng-myz ===hng-kda
707 ===hng-khi ===hng-khm ===hng-hok ===hng-kyd ===hng-sok
708 ===hng-yhk ===hng-kak ===hng-kar ===hng-kae
709 ===hng-sys ===hng-tsu ===hng-tzj
710 ===hng-hos ===hng-nak ===hng-jhk
711 ===hng-hod ===hng-gok ===hng-ink ===hng-nto
712 ===hng-nkm ===hng-k24 ===hng-nkk
713 ===hng-kcc ===hng-kcj ===hng-kbk ===hng-sik
714 ===hng-skk ===hng-kyu ===hng-ksk ===hng-wan
715 ===hng-okd ===hng-wad ===hng-kmi
716 ===hng-zkd ===hng-doh ===hng-jyu
717 ===hng-tzs ===hng-kss ===hng-kyo
719 ;; (string-match "^=adobe-" (symbol-name name))
721 "(%-18s . %05d)\t; %c")
722 ((memq name '(=hanyo-denshi/ks
723 ==hanyo-denshi/ks ===hanyo-denshi/ks
726 =mj ==mj ===mj =>>mj =>mj
728 "(%-18s . %06d)\t; %c")
729 ((memq name '(=hanyo-denshi/tk ==hanyo-denshi/tk))
730 "(%-18s . %08d)\t; %c")
731 ((>= (charset-dimension name) 2)
732 "(%-18s . #x%04X)\t; %c")
734 "(%-18s . #x%02X)\t; %c"))
736 (if (= (charset-iso-graphic-plane name) 1)
738 (cond ((= (charset-dimension name) 1)
740 ((= (charset-dimension name) 2)
742 ((= (charset-dimension name) 3)
746 (char-db-decode-isolated-char name value)))
747 (if (and (= (charset-chars name) 94)
748 (= (charset-dimension name) 2))
749 (insert (format " [%02d-%02d]"
750 (- (lsh value -8) 32)
751 (- (logand value 255) 32))))
754 (insert (format "(%-18s . %s)" name value))
756 (insert line-breaking))
758 (defun char-db-insert-relation-feature (char name value line-breaking
760 (insert (format "(%-18s%s " name line-breaking))
761 (let ((lbs (concat "\n" (make-string (current-column) ?\ )))
762 separator cell sources required-features
765 (setq cell (car value))
767 (setq cell (decode-char '=ucs cell)))
769 ((eq name '->subsumptive)
770 (when (or (not (some (lambda (atr)
771 (get-char-attribute cell atr))
772 char-db-ignored-attributes))
774 (encode-char cell ccs 'defined-only))
778 (let ((char-db-ignored-attributes
780 char-db-ignored-attributes)))
781 (insert-char-attributes cell readable nil nil 'for-sub-node))
782 (setq separator lbs))
787 char (intern (format "%s*sources" name))))
788 (setq required-features nil)
789 (dolist (source sources)
793 shinjigen shinjigen@1ed shinjigen@rev))
794 (setq required-features
795 (union required-features
807 =shinjigen/+p@rev))))
809 (setq required-features
810 (union required-features
815 ((find-charset (setq ret (intern (format "=%s" source))))
816 (setq required-features
817 (cons ret required-features)))
818 (t (setq required-features
819 (cons source required-features)))))
820 (cond ((string-match "@JP" (symbol-name name))
821 (setq required-features
822 (union required-features
830 ((string-match "@CN" (symbol-name name))
831 (setq required-features
832 (union required-features
839 (insert (format "%S" cell))
840 (char-db-insert-char-spec cell readable
843 (setq separator lbs))
847 (if (consp (car cell))
848 (char-db-insert-char-spec cell readable)
849 (char-db-insert-char-reference cell readable))
850 (setq separator lbs))
854 (insert (prin1-to-string cell))
855 (setq separator " ")))
856 (setq value (cdr value)))
858 (insert line-breaking)))
860 (defun insert-char-attributes (char &optional readable attributes column
863 (setq column (current-column)))
864 (let (name value ; has-long-ccs-name
868 (concat "\n" (make-string (1+ column) ?\ )))
869 lbs cell separator ret
871 dest-ccss ; sources required-features
876 (if (consp attributes)
878 (dolist (name attributes)
879 (unless (memq name char-db-ignored-attributes)
880 (if (find-charset name)
884 (dolist (name (char-attribute-list))
885 (unless (memq name char-db-ignored-attributes)
886 (if (find-charset name)
890 #'char-attribute-name<)))
892 (when (memq '<-subsumptive attributes)
893 (when (or readable (not for-sub-node))
894 (when (setq value (get-char-attribute char '<-subsumptive))
895 (char-db-insert-relation-feature char '<-subsumptive value
898 (setq attributes (delq '<-subsumptive attributes)))
899 (when (and (memq '<-denotational attributes)
900 (setq value (get-char-attribute char '<-denotational)))
901 (char-db-insert-relation-feature char '<-denotational value
904 (setq attributes (delq '<-denotational attributes)))
905 (when (and (memq '<-denotational@component attributes)
906 (setq value (get-char-attribute char '<-denotational@component)))
907 (char-db-insert-relation-feature char '<-denotational@component value
910 (setq attributes (delq '<-denotational@component attributes)))
911 (when (and (memq 'name attributes)
912 (setq value (get-char-attribute char 'name)))
914 (if (> (+ (current-column) (length value)) 48)
917 value line-breaking))
918 (setq attributes (delq 'name attributes))
920 (when (and (memq 'name* attributes)
921 (setq value (get-char-attribute char 'name*)))
923 (if (> (+ (current-column) (length value)) 48)
926 value line-breaking))
927 (setq attributes (delq 'name* attributes))
929 (when (and (memq 'script attributes)
930 (setq value (get-char-attribute char 'script)))
931 (insert (format "(script\t\t%s)%s"
932 (mapconcat (function prin1-to-string)
935 (setq attributes (delq 'script attributes))
937 (dolist (name '(=>ucs =>ucs*))
938 (when (and (memq name attributes)
939 (setq value (get-char-attribute char name)))
940 (insert (format "(%-18s . #x%04X)\t; %c%s"
941 name value (decode-char '=ucs value)
943 (setq attributes (delq name attributes))))
944 (dolist (name '(=>ucs@gb =>ucs@big5))
945 (when (and (memq name attributes)
946 (setq value (get-char-attribute char name)))
947 (insert (format "(%-18s . #x%04X)\t; %c%s"
952 (symbol-name name) 2)))
955 (setq attributes (delq name attributes))
957 ;; (dolist (name '(=>daikanwa))
958 ;; (when (and (memq name attributes)
959 ;; (setq value (get-char-attribute char name)))
961 ;; (if (integerp value)
962 ;; (format "(%-18s . %05d)\t; %c%s"
963 ;; name value (decode-char '=daikanwa value)
965 ;; (format "(%-18s %s)\t; %c%s"
967 ;; (mapconcat (function prin1-to-string)
969 ;; (char-representative-of-daikanwa char)
971 ;; (setq attributes (delq name attributes))))
972 (when (and (memq 'general-category attributes)
973 (setq value (get-char-attribute char 'general-category)))
975 "(general-category\t%s) ; %s%s"
976 (mapconcat (lambda (cell)
979 (cond ((rassoc value unidata-normative-category-alist)
980 "Normative Category")
981 ((rassoc value unidata-informative-category-alist)
982 "Informative Category")
986 (setq attributes (delq 'general-category attributes))
988 (when (and (memq 'bidi-category attributes)
989 (setq value (get-char-attribute char 'bidi-category)))
990 (insert (format "(bidi-category\t. %S)%s"
993 (setq attributes (delq 'bidi-category attributes))
995 (unless (or (not (memq 'mirrored attributes))
996 (eq (setq value (get-char-attribute char 'mirrored 'empty))
998 (insert (format "(mirrored\t\t. %S)%s"
1001 (setq attributes (delq 'mirrored attributes))
1004 ((and (memq 'decimal-digit-value attributes)
1005 (setq value (get-char-attribute char 'decimal-digit-value)))
1006 (insert (format "(decimal-digit-value . %S)%s"
1009 (setq attributes (delq 'decimal-digit-value attributes))
1010 (when (and (memq 'digit-value attributes)
1011 (setq value (get-char-attribute char 'digit-value)))
1012 (insert (format "(digit-value\t . %S)%s"
1015 (setq attributes (delq 'digit-value attributes))
1017 (when (and (memq 'numeric-value attributes)
1018 (setq value (get-char-attribute char 'numeric-value)))
1019 (insert (format "(numeric-value\t . %S)%s"
1022 (setq attributes (delq 'numeric-value attributes))
1026 (when (and (memq 'digit-value attributes)
1027 (setq value (get-char-attribute char 'digit-value)))
1028 (insert (format "(digit-value\t. %S)%s"
1031 (setq attributes (delq 'digit-value attributes))
1033 (when (and (memq 'numeric-value attributes)
1034 (setq value (get-char-attribute char 'numeric-value)))
1035 (insert (format "(numeric-value\t. %S)%s"
1038 (setq attributes (delq 'numeric-value attributes))
1040 (when (and (memq 'iso-10646-comment attributes)
1041 (setq value (get-char-attribute char 'iso-10646-comment)))
1042 (insert (format "(iso-10646-comment\t. %S)%s"
1045 (setq attributes (delq 'iso-10646-comment attributes))
1047 (when (and (memq 'morohashi-daikanwa attributes)
1048 (setq value (get-char-attribute char 'morohashi-daikanwa)))
1049 (insert (format "(morohashi-daikanwa\t%s)%s"
1050 (mapconcat (function prin1-to-string) value " ")
1052 (setq attributes (delq 'morohashi-daikanwa attributes))
1056 (when (and (memq 'ideographic-radical attributes)
1057 (setq value (get-char-attribute char 'ideographic-radical)))
1058 (setq radical value)
1059 (insert (format "(ideographic-radical . %S)\t; %c%s"
1061 (ideographic-radical radical)
1063 (setq attributes (delq 'ideographic-radical attributes))
1065 (when (and (memq 'shuowen-radical attributes)
1066 (setq value (get-char-attribute char 'shuowen-radical)))
1067 (insert (format "(shuowen-radical\t. %S)\t; %c%s"
1069 (shuowen-radical value)
1071 (setq attributes (delq 'shuowen-radical attributes))
1076 char-db-feature-domains
1078 (dolist (feature (char-attribute-list))
1079 (setq feature (symbol-name feature))
1081 "\\(radical\\|strokes\\)@\\([^@*]+\\)\\(\\*\\|$\\)"
1083 (setq domain (intern (match-string 2 feature)))
1084 (unless (memq domain dest)
1085 (setq dest (cons domain dest)))))
1086 (sort dest #'string<))))
1087 (setq key (intern (format "%s@%s" 'ideographic-radical domain)))
1088 (when (and (memq key attributes)
1089 (setq value (get-char-attribute char key)))
1090 (setq radical value)
1091 (insert (format "(%s . %S)\t; %c%s"
1094 (ideographic-radical radical)
1096 (setq attributes (delq key attributes))
1098 (setq key (intern (format "%s@%s" 'ideographic-strokes domain)))
1099 (when (and (memq key attributes)
1100 (setq value (get-char-attribute char key)))
1101 (setq strokes value)
1102 (insert (format "(%s . %S)%s"
1106 (setq attributes (delq key attributes))
1108 (setq key (intern (format "%s@%s" 'total-strokes domain)))
1109 (when (and (memq key attributes)
1110 (setq value (get-char-attribute char key)))
1111 (insert (format "(%s . %S)%s"
1115 (setq attributes (delq key attributes))
1117 (dolist (feature '(ideographic-radical
1120 (setq key (intern (format "%s@%s*sources" feature domain)))
1121 (when (and (memq key attributes)
1122 (setq value (get-char-attribute char key)))
1123 (insert (format "(%s%s" key line-breaking))
1124 (dolist (cell value)
1125 (insert (format " %s" cell)))
1127 (insert line-breaking)
1128 (setq attributes (delq key attributes))
1131 (when (and (memq 'ideographic-strokes attributes)
1132 (setq value (get-char-attribute char 'ideographic-strokes)))
1133 (setq strokes value)
1134 (insert (format "(ideographic-strokes . %S)%s"
1137 (setq attributes (delq 'ideographic-strokes attributes))
1139 (when (and (memq 'kangxi-radical attributes)
1140 (setq value (get-char-attribute char 'kangxi-radical)))
1141 (unless (eq value radical)
1142 (insert (format "(kangxi-radical\t . %S)\t; %c%s"
1144 (ideographic-radical value)
1147 (setq radical value)))
1148 (setq attributes (delq 'kangxi-radical attributes))
1150 (when (and (memq 'kangxi-strokes attributes)
1151 (setq value (get-char-attribute char 'kangxi-strokes)))
1152 (unless (eq value strokes)
1153 (insert (format "(kangxi-strokes\t . %S)%s"
1157 (setq strokes value)))
1158 (setq attributes (delq 'kangxi-strokes attributes))
1160 ;; (when (and (memq 'japanese-radical attributes)
1161 ;; (setq value (get-char-attribute char 'japanese-radical)))
1162 ;; (unless (eq value radical)
1163 ;; (insert (format "(japanese-radical\t . %S)\t; %c%s"
1165 ;; (ideographic-radical value)
1168 ;; (setq radical value)))
1169 ;; (setq attributes (delq 'japanese-radical attributes))
1171 (when (and (memq 'japanese-strokes attributes)
1172 (setq value (get-char-attribute char 'japanese-strokes)))
1173 (unless (eq value strokes)
1174 (insert (format "(japanese-strokes\t . %S)%s"
1178 (setq strokes value)))
1179 (setq attributes (delq 'japanese-strokes attributes))
1181 (when (and (memq 'cns-radical attributes)
1182 (setq value (get-char-attribute char 'cns-radical)))
1183 (insert (format "(cns-radical\t . %S)\t; %c%s"
1185 (ideographic-radical value)
1187 (setq attributes (delq 'cns-radical attributes))
1189 (when (and (memq 'cns-strokes attributes)
1190 (setq value (get-char-attribute char 'cns-strokes)))
1191 (unless (eq value strokes)
1192 (insert (format "(cns-strokes\t . %S)%s"
1196 (setq strokes value)))
1197 (setq attributes (delq 'cns-strokes attributes))
1199 ;; (when (and (memq 'shinjigen-1-radical attributes)
1200 ;; (setq value (get-char-attribute char 'shinjigen-1-radical)))
1201 ;; (unless (eq value radical)
1202 ;; (insert (format "(shinjigen-1-radical . %S)\t; %c%s"
1204 ;; (ideographic-radical value)
1207 ;; (setq radical value)))
1208 ;; (setq attributes (delq 'shinjigen-1-radical attributes))
1210 ;; (when (and (memq 'ideographic- attributes)
1211 ;; (setq value (get-char-attribute char 'ideographic-)))
1212 ;; (insert "(ideographic- ")
1213 ;; (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1215 ;; (while (consp value)
1216 ;; (setq cell (car value))
1217 ;; (if (integerp cell)
1218 ;; (setq cell (decode-char '=ucs cell)))
1219 ;; (cond ((characterp cell)
1223 ;; (insert (format "%S" cell))
1224 ;; (char-db-insert-char-spec cell readable))
1225 ;; (setq separator lbs))
1229 ;; (if (consp (car cell))
1230 ;; (char-db-insert-char-spec cell readable)
1231 ;; (char-db-insert-char-reference cell readable))
1232 ;; (setq separator lbs))
1235 ;; (insert separator))
1236 ;; (insert (prin1-to-string cell))
1237 ;; (setq separator " ")))
1238 ;; (setq value (cdr value)))
1240 ;; (insert line-breaking)
1241 ;; (setq attributes (delq 'ideographic- attributes)))
1242 (when (and (memq 'total-strokes attributes)
1243 (setq value (get-char-attribute char 'total-strokes)))
1244 (insert (format "(total-strokes . %S)%s"
1247 (setq attributes (delq 'total-strokes attributes))
1249 ;; (when (and (memq '->ideograph attributes)
1250 ;; (setq value (get-char-attribute char '->ideograph)))
1251 ;; (insert (format "(->ideograph\t%s)%s"
1252 ;; (mapconcat (lambda (code)
1253 ;; (cond ((symbolp code)
1254 ;; (symbol-name code))
1256 ;; (format "#x%04X" code))
1259 ;; line-breaking code))))
1262 ;; (setq attributes (delq '->ideograph attributes))
1264 ;; (when (and (memq '->decomposition attributes)
1265 ;; (setq value (get-char-attribute char '->decomposition)))
1266 ;; (insert (format "(->decomposition\t%s)%s"
1267 ;; (mapconcat (lambda (code)
1268 ;; (cond ((symbolp code)
1269 ;; (symbol-name code))
1270 ;; ((characterp code)
1272 ;; (format "%S" code)
1277 ;; (format "#x%04X" code))
1279 ;; (format "%s%S" line-breaking code))))
1282 ;; (setq attributes (delq '->decomposition attributes))
1284 (if (equal (get-char-attribute char '->titlecase)
1285 (get-char-attribute char '->uppercase))
1286 (setq attributes (delq '->titlecase attributes)))
1287 (when (and (memq '->mojikyo attributes)
1288 (setq value (get-char-attribute char '->mojikyo)))
1289 (insert (format "(->mojikyo\t\t. %06d)\t; %c%s"
1290 value (decode-char 'mojikyo value)
1292 (setq attributes (delq '->mojikyo attributes))
1294 ;; (when (and (memq 'hanyu-dazidian-vol attributes)
1295 ;; (setq value (get-char-attribute char 'hanyu-dazidian-vol)))
1296 ;; (insert (format "(hanyu-dazidian-vol . %d)%s"
1297 ;; value line-breaking))
1298 ;; (setq attributes (delq 'hanyu-dazidian-vol attributes))
1300 ;; (when (and (memq 'hanyu-dazidian-page attributes)
1301 ;; (setq value (get-char-attribute char 'hanyu-dazidian-page)))
1302 ;; (insert (format "(hanyu-dazidian-page . %d)%s"
1303 ;; value line-breaking))
1304 ;; (setq attributes (delq 'hanyu-dazidian-page attributes))
1306 ;; (when (and (memq 'hanyu-dazidian-char attributes)
1307 ;; (setq value (get-char-attribute char 'hanyu-dazidian-char)))
1308 ;; (insert (format "(hanyu-dazidian-char . %d)%s"
1309 ;; value line-breaking))
1310 ;; (setq attributes (delq 'hanyu-dazidian-char attributes))
1313 (dolist (ignored '(composition
1314 ->denotational <-subsumptive ->ucs-unified
1315 ->ideographic-component-forms))
1316 (setq attributes (delq ignored attributes))))
1318 (setq name (car attributes))
1319 (unless (eq (setq value (get-char-attribute char name 'value-is-empty))
1321 (cond ((setq ret (find-charset name))
1322 (setq name (charset-name ret))
1323 (when (not (memq name dest-ccss))
1324 (setq dest-ccss (cons name dest-ccss))
1325 (char-db-insert-ccs-feature name value line-breaking))
1327 ((string-match "^=>ucs@" (symbol-name name))
1328 (insert (format "(%-18s . #x%04X)\t; %c%s"
1329 name value (decode-char '=ucs value)
1332 ((eq name 'jisx0208-1978/4X)
1333 (insert (format "(%-18s . #x%04X)%s"
1339 (not (eq name '->subsumptive))
1340 (not (eq name '->uppercase))
1341 (not (eq name '->lowercase))
1342 (not (eq name '->titlecase))
1343 (not (eq name '->canonical))
1344 (not (eq name '->Bopomofo))
1345 (not (eq name '->mistakable))
1346 (not (eq name '->ideographic-variants))
1347 (null (get-char-attribute
1348 char (intern (format "%s*sources" name))))
1349 (not (string-match "\\*sources$" (symbol-name name)))
1350 (null (get-char-attribute
1351 char (intern (format "%s*note" name))))
1352 (not (string-match "\\*note$" (symbol-name name)))
1353 (or (eq name '<-identical)
1354 (eq name '<-uppercase)
1355 (eq name '<-lowercase)
1356 (eq name '<-titlecase)
1357 (eq name '<-canonical)
1358 (eq name '<-ideographic-variants)
1359 ;; (eq name '<-synonyms)
1360 (string-match "^<-synonyms" (symbol-name name))
1361 (eq name '<-mistakable)
1362 (when (string-match "^->" (symbol-name name))
1364 ((string-match "^->fullwidth" (symbol-name name))
1365 (not (and (consp value)
1366 (characterp (car value))
1368 (car value) '=ucs 'defined-only)))
1373 ((or (eq name 'ideographic-structure)
1374 (eq name 'ideographic-combination)
1375 ;; (eq name 'ideographic-)
1376 (eq name '=decomposition)
1377 (char-feature-base-name= '=decomposition name)
1378 (char-feature-base-name= '=>decomposition name)
1379 ;; (string-match "^=>*decomposition\\(@[^*]+\\)?$"
1380 ;; (symbol-name name))
1381 (string-match "^\\(->\\|<-\\)[^*]*$" (symbol-name name))
1382 (string-match "^\\(->\\|<-\\)[^*]*\\*sources$"
1385 (char-db-insert-relation-feature char name value
1388 ;; ((memq name '(ideograph=
1389 ;; original-ideograph-of
1390 ;; ancient-ideograph-of
1391 ;; vulgar-ideograph-of
1392 ;; wrong-ideograph-of
1393 ;; ;; simplified-ideograph-of
1394 ;; ideographic-variants
1395 ;; ;; ideographic-different-form-of
1397 ;; (insert (format "(%-18s%s " name line-breaking))
1398 ;; (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1400 ;; (while (consp value)
1401 ;; (setq cell (car value))
1402 ;; (if (and (consp cell)
1403 ;; (consp (car cell)))
1407 ;; (char-db-insert-alist cell readable)
1408 ;; (setq separator lbs))
1410 ;; (insert separator))
1411 ;; (insert (prin1-to-string cell))
1412 ;; (setq separator " "))
1413 ;; (setq value (cdr value)))
1415 ;; (insert line-breaking))
1417 (insert (format "(%-18s " name))
1418 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1420 (while (consp value)
1421 (setq cell (car value))
1422 (if (and (consp cell)
1424 (setq ret (condition-case nil
1432 (setq key (car (car rest)))
1433 (if (find-charset key)
1434 (setq cal (cons key cal))
1435 (setq al (cons key al)))
1436 (setq rest (cdr rest)))
1439 (insert-char-attributes ret
1443 (setq separator lbs))
1444 (setq ret (prin1-to-string cell))
1446 (if (< (+ (current-column)
1453 (setq separator " "))
1454 (setq value (cdr value)))
1456 (insert line-breaking))
1458 (insert (format "(%-18s" name))
1459 (setq ret (prin1-to-string value))
1460 (unless (< (+ (current-column)
1464 (insert line-breaking))
1465 (insert " . " ret ")" line-breaking)
1466 ;; (insert (format "(%-18s . %S)%s"
1471 (setq attributes (cdr attributes)))
1474 (defun insert-char-data (char &optional readable
1477 (narrow-to-region (point)(point))
1478 (insert "(define-char
1480 (insert-char-attributes char readable attributes)
1482 (goto-char (point-min))
1483 (while (re-search-forward "[ \t]+$" nil t)
1486 (goto-char (point-min))
1487 (while (re-search-forward "[ \t][ \t][ \t]*" nil t)
1488 (let ((column (current-column))
1489 (indent-tabs-mode t))
1490 (delete-region (match-beginning 0) (point))
1491 (indent-to column)))
1492 (goto-char (point-max))
1493 ;; (tabify (point-min)(point-max))
1496 (defun insert-char-data-with-variant (char &optional printable
1498 script excluded-script)
1499 (insert-char-data char printable)
1500 (let ((variants (char-variants char))
1503 (setq variants (sort variants #'<))
1504 (setq rest variants)
1505 (setq variants (cons char variants))
1507 (setq variant (car rest))
1508 (unless (get-char-attribute variant '<-subsumptive)
1509 (if (and (or (null script)
1510 (null (setq vs (get-char-attribute variant 'script)))
1512 (or (null excluded-script)
1513 (null (setq vs (get-char-attribute variant 'script)))
1514 (not (memq excluded-script vs))))
1515 (unless (and no-ucs-unified (get-char-attribute variant '=ucs))
1516 (insert-char-data variant printable)
1517 (if (setq ret (char-variants variant))
1519 (or (memq (car ret) variants)
1520 ;; (get-char-attribute (car ret) '<-subsumptive)
1521 (setq rest (nconc rest (list (car ret)))))
1522 (setq ret (cdr ret)))))))
1523 (setq rest (cdr rest)))))
1525 (defun insert-char-range-data (min max &optional script excluded-script)
1528 (while (<= code max)
1529 (setq char (decode-char '=ucs code))
1530 (if (encode-char char '=ucs 'defined-only)
1531 (insert-char-data-with-variant char nil 'no-ucs-unified
1532 script excluded-script))
1533 (setq code (1+ code)))))
1535 (defun write-char-range-data-to-file (min max file
1536 &optional script excluded-script)
1537 (let ((coding-system-for-write char-db-file-coding-system))
1539 (insert (format ";; -*- coding: %s -*-\n"
1540 char-db-file-coding-system))
1541 (insert-char-range-data min max script excluded-script)
1542 (write-region (point-min)(point-max) file))))
1544 (defvar what-character-original-window-configuration)
1547 (defun what-char-definition (char)
1548 (interactive (list (char-after)))
1549 (let ((buf (get-buffer-create "*Character Description*"))
1550 (the-buf (current-buffer))
1551 (win-conf (current-window-configuration)))
1553 (make-local-variable 'what-character-original-window-configuration)
1554 (setq what-character-original-window-configuration win-conf)
1555 (setq buffer-read-only nil)
1559 (insert-char-data-with-variant char 'printable)
1560 (unless (char-attribute-alist char)
1561 (insert (format ";; = %c\n"
1562 (let* ((rest (split-char char))
1566 (setq code (logior (lsh code 8)
1568 (decode-char ccs code)))))
1569 ;; (char-db-update-comment)
1570 (set-buffer-modified-p nil)
1571 (view-mode the-buf (lambda (buf)
1572 (set-window-configuration
1573 what-character-original-window-configuration)
1575 (goto-char (point-min)))
1577 (set-window-configuration
1578 what-character-original-window-configuration)
1579 (signal (car err) (cdr err)))))))
1585 (provide 'char-db-util)
1587 ;;; char-db-util.el ends here