1 ;;; char-db-util.el --- Character Database utility -*- coding: utf-8-er; -*-
3 ;; Copyright (C) 1998,1999,2000,2001,2002,2003,2004,2005,2006,2007,
4 ;; 2008,2009,2010,2011,2012,2013,2014,2015,2016,2017 MORIOKA Tomohiko.
6 ;; Author: MORIOKA Tomohiko <tomo@kanji.zinbun.kyoto-u.ac.jp>
7 ;; Keywords: CHISE, Character Database, ISO/IEC 10646, UCS, Unicode, MULE.
9 ;; This file is part of XEmacs CHISE.
11 ;; XEmacs CHISE is free software; you can redistribute it and/or
12 ;; modify it under the terms of the GNU General Public License as
13 ;; published by the Free Software Foundation; either version 2, or (at
14 ;; your option) any later version.
16 ;; XEmacs CHISE is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 ;; General Public License for more details.
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with XEmacs CHISE; see the file COPYING. If not, write to
23 ;; the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
24 ;; Boston, MA 02111-1307, USA.
29 (require 'ideograph-subr)
31 (defconst unidata-normative-category-alist
32 '(("Lu" letter uppercase)
33 ("Ll" letter lowercase)
34 ("Lt" letter titlecase)
35 ("Mn" mark non-spacing)
36 ("Mc" mark spacing-combining)
38 ("Nd" number decimal-digit)
41 ("Zs" separator space)
43 ("Zp" separator paragraph)
46 ("Cs" other surrogate)
47 ("Co" other private-use)
48 ("Cn" other not-assigned)))
50 (defconst unidata-informative-category-alist
51 '(("Lm" letter modifier)
53 ("Pc" punctuation connector)
54 ("Pd" punctuation dash)
55 ("Ps" punctuation open)
56 ("Pe" punctuation close)
57 ("Pi" punctuation initial-quote)
58 ("Pf" punctuation final-quote)
59 ("Po" punctuation other)
61 ("Sc" symbol currency)
62 ("Sk" symbol modifier)
66 (defconst shuowen-radicals
67 [?一 ?上 ?示 ?三 ?王 ?玉 ?玨 ?气 ?士 ?丨 ; 010
68 ?屮 ?艸 ?蓐 ?茻 ?小 ?八 ?釆 ?半 ?牛 ?犛 ; 020
69 ?告 ?口 ?凵 ?吅 ?哭 ?走 ?止 ?癶 ?步 ?此 ; 030
70 ?正 ?是 ?辵 ?彳 ?廴 ?㢟 ?行 ?齒 ?牙 ?足 ; 040
71 ?疋 ?品 ?龠 ?冊 ?㗊 ?舌 ?干 ?谷 ?只 ?㕯 ; 050
72 ?句 ?丩 ?古 ?十 ?卅 ?言 ?誩 ?音 ?䇂 ?丵 ; 060
73 ?菐 ?𠬞 ?𠬜 ?共 ?異 ?舁 ?𦥑 ?䢅 ?爨 ?革 ; 070
74 ?鬲 ?䰜 ?爪 ?𠃨 ?鬥 ?又 ?𠂇 ?㕜 ?支 ?𦘒 ; 080
75 ?聿 ?畫 ?隶 ?臤 ?臣 ?殳 ?殺 ?𠘧 ?寸 ?皮 ; 090
76 ?㼱 ?攴 ?敎 ?卜 ?用 ?爻 ?㸚 ?𥄎 ?目 ?䀠 ; 100
77 ?眉 ?盾 ?自 ?白 ?鼻 ?皕 ?習 ?羽 ?隹 ?奞 ; 110
78 ?萑 ?𦫳 ?苜 ?羊 ?羴 ?瞿 ?雔 ?雥 ?鳥 ?烏 ; 120
79 ?𠦒 ?冓 ?幺 ?𢆶 ?叀 ?玄 ?予 ?放 ?𠬪 ?𣦼 ; 130
80 ?歺 ?死 ?冎 ?骨 ?肉 ?筋 ?刀 ?刃 ?㓞 ?丰 ; 140
81 ?耒 ?𧢲 ?竹 ?箕 ?丌 ?左 ?工 ?㠭 ?巫 ?甘 ; 150
82 ?曰 ?乃 ?丂 ?可 ?兮 ?号 ?亏 ?旨 ?喜 ?壴 ; 160
83 ; ?旨 ?曰 ?乃 ?丂 ?可 ?兮 ?号 ?亏 ?喜 ?壴 ; 160
84 ?鼓 ?豈 ?豆 ?豊 ?豐 ?䖒 ?虍 ?虎 ?虤 ?皿 ; 170
85 ?𠙴 ?去 ?血 ?丶 ?丹 ?青 ?井 ?皀 ?鬯 ?食 ; 180
86 ?亼 ?會 ?倉 ?入 ?缶 ?矢 ?高 ?冂 ?𩫏 ?京 ; 190
87 ?亯 ?𣆪 ?畗 ?㐭 ?嗇 ?來 ?麥 ?夊 ?舛 ?䑞 ; 200
88 ?韋 ?弟 ?夂 ?久 ?桀 ?木 ?東 ?林 ?才 ?叒 ; 210
89 ?之 ?帀 ?出 ?𣎵 ?生 ?乇 ?𠂹 ?𠌶 ?華 ?𥝌 ; 220
90 ?稽 ?巢 ?桼 ?束 ?㯻 ?囗 ?員 ?貝 ?邑 ?𨛜 ; 230
91 ?日 ?旦 ?倝 ?㫃 ?冥 ?晶 ?月 ?有 ?明 ?囧 ; 240
92 ?夕 ?多 ?毌 ?𢎘 ?𣐺 ?卣 ?齊 ?朿 ?片 ?鼎 ; 250
93 ?克 ?彔 ?禾 ?秝 ?黍 ?香 ?米 ?毇 ?臼 ?凶 ; 260
94 ?𣎳 ?林 ?麻 ?尗 ?耑 ?韭 ?瓜 ?瓠 ?宀 ?宮 ; 270
95 ?呂 ?穴 ?㝱 ?𤕫 ?冖 ?𠔼 ?冃 ?㒳 ?网 ?襾 ; 280
96 ?巾 ?巿 ?帛 ?白 ?㡀 ?黹 ?人 ?𠤎 ?匕 ?从 ; 290
97 ?比 ?北 ?丘 ?㐺 ?𡈼 ?重 ?臥 ?身 ?㐆 ?衣 ; 300
98 ?裘 ?老 ?毛 ?毳 ?尸 ?尺 ?尾 ?履 ?舟 ?方 ; 310
99 ?儿 ?兄 ?兂 ?皃 ?𠑹 ?先 ?秃 ?見 ?覞 ?欠 ; 320
100 ?㱃 ?㳄 ?旡 ?頁 ?𦣻 ?面 ?丏 ?首 ?𥄉 ?須 ; 330
101 ?彡 ?彣 ?文 ?髟 ?后 ?司 ?卮 ?卩 ?印 ?色 ; 340
102 ?𠨍 ?辟 ?勹 ?包 ?茍 ?鬼 ?甶 ?厶 ?嵬 ?山 ; 350
103 ?屾 ?屵 ?广 ?厂 ?丸 ?危 ?石 ?長 ?勿 ?冄 ; 360
104 ?而 ?豕 ?㣇 ?彑 ?豚 ?豸 ?𤉡 ?易 ?象 ?馬 ; 370
105 ?𢊁 ?鹿 ?麤 ?㲋 ?兔 ?萈 ?犬 ?㹜 ?鼠 ?能 ; 380
106 ?熊 ?火 ?炎 ?黑 ?囪 ?焱 ?炙 ?赤 ?大 ?亦 ; 390
109 (defun shuowen-radical (number)
110 (aref shuowen-radicals (1- number)))
112 (defvar char-db-file-coding-system 'utf-8-mcs-er)
114 (defvar char-db-ignored-attributes '(ideographic-products))
116 (defvar char-db-coded-charset-priority-list
214 ;; =>>>adobe-japan1-0
215 ;; =>>>adobe-japan1-1
216 ;; =>>>adobe-japan1-2
217 ;; =>>>adobe-japan1-3
218 ;; =>>>adobe-japan1-4
219 ;; =>>>adobe-japan1-5
220 ;; =>>>adobe-japan1-6
224 ;; =>>>hanyo-denshi/ja
225 ;; =>>>hanyo-denshi/jb
226 ;; =>>>hanyo-denshi/jc
227 ;; =>>>hanyo-denshi/ft
228 ;; =>>>hanyo-denshi/ib
229 ;; =>>>hanyo-denshi/hg
230 ;; =>>>hanyo-denshi/jt
231 ;; =>>>hanyo-denshi/ks
271 ;; =>ucs@hanyo-denshi
366 =>big5-cdp-itaiji-001
376 ;;; @ char-db formatters
379 (defun char-db-make-char-spec (char)
381 (cond ((characterp char)
382 (cond ((and (setq ret (encode-char char '=ucs 'defined-only))
383 (not (and (<= #xE000 ret)(<= ret #xF8FF))))
384 (setq char-spec (list (cons '=ucs ret)))
385 (cond ((setq ret (get-char-attribute char 'name))
386 (setq char-spec (cons (cons 'name ret) char-spec))
388 ((setq ret (get-char-attribute char 'name*))
389 (setq char-spec (cons (cons 'name* ret) char-spec))
392 ((encode-char char '=mj 'defined-only)
394 (dolist (ccs (charset-list))
395 (if (and (or (eq ccs '=mj)
396 ;; (eq (charset-property ccs 'iso-ir) 177)
397 (string-match "=ucs@" (symbol-name ccs))
399 (setq ccs (charset-name ccs))
400 (null (assq ccs char-spec))
401 (setq ret (encode-char char ccs 'defined-only)))
402 (setq char-spec (cons (cons ccs ret) char-spec))))
404 ((encode-char char '==mj 'defined-only)
406 (dolist (ccs (charset-list))
407 (if (and (or (eq ccs '==mj)
408 ;; (eq (charset-property ccs 'iso-ir) 177)
409 (string-match "=ucs@" (symbol-name ccs))
411 (setq ccs (charset-name ccs))
412 (null (assq ccs char-spec))
413 (setq ret (encode-char char ccs 'defined-only)))
414 (setq char-spec (cons (cons ccs ret) char-spec))))
416 ((encode-char char '=adobe-japan1 'defined-only)
418 (dolist (ccs (charset-list))
419 (if (and (or (memq ccs
428 ;; (eq (charset-property ccs 'iso-ir) 177)
429 (string-match "=ucs@" (symbol-name ccs))
431 (setq ccs (charset-name ccs))
432 (null (assq ccs char-spec))
433 (setq ret (encode-char char ccs 'defined-only)))
434 (setq char-spec (cons (cons ccs ret) char-spec))))
436 ((encode-char char '==adobe-japan1 'defined-only)
438 (dolist (ccs (charset-list))
439 (if (and (or (memq ccs
448 ;; (eq (charset-property ccs 'iso-ir) 177)
449 (string-match "=ucs@" (symbol-name ccs))
451 (setq ccs (charset-name ccs))
452 (null (assq ccs char-spec))
453 (setq ret (encode-char char ccs 'defined-only)))
454 (setq char-spec (cons (cons ccs ret) char-spec))))
458 (let ((rest char-db-coded-charset-priority-list)
461 (setq ccs (charset-name
462 (find-charset (car rest))))
464 (encode-char char ccs
466 (throw 'tag (cons ccs ret)))
467 (setq rest (cdr rest))))))
468 (setq char-spec (list ret))
469 (dolist (ccs (delq (car ret) (charset-list)))
470 (if (and (or (charset-iso-final-char ccs)
477 (eq (charset-property ccs 'iso-ir) 177)
478 ;; (string-match "=ucs@" (symbol-name ccs))
480 (setq ccs (charset-name ccs))
481 (null (assq ccs char-spec))
482 (setq ret (encode-char char ccs 'defined-only)))
483 (setq char-spec (cons (cons ccs ret) char-spec))))
485 (setq char-spec (split-char char)))
486 (cond ((setq ret (get-char-attribute char 'name))
487 (setq char-spec (cons (cons 'name ret) char-spec))
489 ((setq ret (get-char-attribute char 'name*))
490 (setq char-spec (cons (cons 'name* ret) char-spec))
493 ((setq ret (get-char-attribute
494 char 'ideographic-combination))
496 (cons (cons 'ideographic-combination ret)
503 (defun char-db-insert-char-spec (char &optional readable column
506 (setq column (current-column)))
507 (let (char-spec temp-char)
508 (setq char-spec (char-db-make-char-spec char))
509 (unless (or (characterp char) ; char
511 (setq char (find-char char-spec))
513 ;; define temporary character
514 ;; Current implementation is dirty.
515 (setq temp-char (define-char (cons '(ideograph-daikanwa . 0)
517 (remove-char-attribute temp-char 'ideograph-daikanwa)
518 (setq char temp-char))
519 (insert-char-attributes char
521 (union (mapcar #'car char-spec)
525 ;; undefine temporary character
526 ;; Current implementation is dirty.
527 (setq char-spec (char-attribute-alist temp-char))
529 (remove-char-attribute temp-char (car (car char-spec)))
530 (setq char-spec (cdr char-spec))))))
532 (defun char-db-insert-alist (alist &optional readable column)
534 (setq column (current-column)))
536 (concat "\n" (make-string (1+ column) ?\ )))
540 lbs cell rest separator)
543 (setq name (car (car alist))
544 value (cdr (car alist)))
545 (cond ((eq name 'char)
547 (if (setq ret (condition-case nil
555 (setq key (car (car value)))
556 ;; (if (find-charset key)
557 ;; (setq cal (cons key cal))
558 (setq al (cons key al))
560 (setq value (cdr value)))
561 (insert-char-attributes ret
565 (insert (prin1-to-string value)))
567 (insert line-breaking))
569 (insert (format "(%-18s " name))
570 (setq lbs (concat "\n" (make-string (current-column) ?\ )))
572 (setq cell (car value))
573 (if (and (consp cell)
575 (setq ret (condition-case nil
585 (setq key (car (car rest)))
586 ;; (if (find-charset key)
587 ;; (setq cal (cons key cal))
588 (setq al (cons key al))
590 (setq rest (cdr rest)))
593 (insert-char-attributes ret
597 (setq separator lbs))
600 (insert (prin1-to-string cell))
601 (setq separator " "))
602 (setq value (cdr value)))
604 (insert line-breaking))
606 (insert (format "(%-18s . %S)%s"
609 (setq alist (cdr alist))))
612 (defun char-db-insert-char-reference (plist &optional readable column)
614 (setq column (current-column)))
616 (concat "\n" (make-string (1+ column) ?\ )))
621 (setq name (pop plist))
622 (setq value (pop plist))
623 (cond ((eq name :char)
626 (cond ((numberp value)
627 (setq value (decode-char '=ucs value)))
629 ;; (setq value (or (find-char value)
632 (char-db-insert-char-spec value readable)
633 (insert line-breaking)
636 (insert (format "%s%s\t%d ; %c%s"
639 (ideographic-radical value)
643 (insert (format "%s%s\t%S" separator name value))
644 (setq separator line-breaking)))
648 (defun char-db-decode-isolated-char (ccs code-point)
651 (cond ((eq ccs 'arabic-iso8859-6)
652 (decode-char ccs code-point))
654 ;; (decode-builtin-char '==gt code-point))
655 ((and (memq ccs '(=gt-pj-1
666 (setq ret (decode-char ccs code-point))
667 (setq ret (encode-char ret '=gt 'defined-only)))
668 (decode-builtin-char '=gt ret))
670 (decode-builtin-char ccs code-point))))
672 (or (decode-char ccs code-point)
673 (define-char (list (cons ccs code-point)))))
674 ((and (<= 0 (char-int ret))
675 (<= (char-int ret) #x1F))
676 (decode-char '=ucs (+ #x2400 (char-int ret))))
677 ((= (char-int ret) #x7F)
681 (defvar char-db-convert-obsolete-format t)
683 (defun char-db-insert-ccs-feature (name value line-breaking)
689 ((memq name '(=>iwds-1
692 =shinjigen@1ed ==shinjigen@1ed
693 =shinjigen@rev ==shinjigen@rev
694 =shinjigen/+p@rev ==shinjigen/+p@rev
695 ===daikanwa/ho ==daikanwa/ho
696 =daikanwa/ho =>>daikanwa/ho =>daikanwa/ho))
697 "(%-18s . %04d)\t; %c")
698 ((eq name '=shinjigen@1ed/24pr)
699 "(%-18s . %04d)\t; %c")
703 ==daikanwa =daikanwa =>>daikanwa =>daikanwa
704 =daikanwa@rev1 =daikanwa@rev2
705 =daikanwa/+p ==daikanwa/+p ===daikanwa/+p
707 =daikanwa/+2p =>>daikanwa/+2p
712 =adobe-japan1-0 ==adobe-japan1-0 ===adobe-japan1-0
713 =adobe-japan1-1 ==adobe-japan1-1 ===adobe-japan1-1
714 =adobe-japan1-2 ==adobe-japan1-2 ===adobe-japan1-2
715 =adobe-japan1-3 ==adobe-japan1-3 ===adobe-japan1-3
716 =adobe-japan1-4 ==adobe-japan1-4 ===adobe-japan1-4
717 =adobe-japan1-5 ==adobe-japan1-5 ===adobe-japan1-5
718 =adobe-japan1-6 ==adobe-japan1-6 ===adobe-japan1-6
719 =>>adobe-japan1-0 =+>adobe-japan1-0
720 =>>adobe-japan1-1 =+>adobe-japan1-1
721 =>>adobe-japan1-2 =+>adobe-japan1-2
722 =>>adobe-japan1-3 =+>adobe-japan1-3
723 =>>adobe-japan1-4 =+>adobe-japan1-4
724 =>>adobe-japan1-5 =+>adobe-japan1-5
725 =>>adobe-japan1-6 =+>adobe-japan1-6
726 =>cbeta =cbeta =>>cbeta ==cbeta ===cbeta
727 =zinbun-oracle =>zinbun-oracle
728 ===hng-jou ===hng-keg ===hng-dng ===hng-mam
729 ===hng-drt ===hng-kgk ===hng-myz ===hng-kda
730 ===hng-khi ===hng-khm ===hng-hok ===hng-kyd ===hng-sok
731 ===hng-yhk ===hng-kak ===hng-kar ===hng-kae
732 ===hng-sys ===hng-tsu ===hng-tzj
733 ===hng-hos ===hng-nak ===hng-jhk
734 ===hng-hod ===hng-gok ===hng-ink ===hng-nto
735 ===hng-nkm ===hng-k24 ===hng-nkk
736 ===hng-kcc ===hng-kcj ===hng-kbk ===hng-sik
737 ===hng-skk ===hng-kyu ===hng-ksk ===hng-wan
738 ===hng-okd ===hng-wad ===hng-kmi
739 ===hng-zkd ===hng-doh ===hng-jyu
740 ===hng-tzs ===hng-kss ===hng-kyo
742 ;; (string-match "^=adobe-" (symbol-name name))
744 "(%-18s . %05d)\t; %c")
745 ((memq name '(=hanyo-denshi/ks
746 ==hanyo-denshi/ks ===hanyo-denshi/ks
749 =mj ==mj ===mj =>>mj =>mj
751 "(%-18s . %06d)\t; %c")
752 ((memq name '(=hanyo-denshi/tk ==hanyo-denshi/tk))
753 "(%-18s . %08d)\t; %c")
754 ((>= (charset-dimension name) 2)
755 "(%-18s . #x%04X)\t; %c")
757 "(%-18s . #x%02X)\t; %c"))
759 (if (= (charset-iso-graphic-plane name) 1)
761 (cond ((= (charset-dimension name) 1)
763 ((= (charset-dimension name) 2)
765 ((= (charset-dimension name) 3)
769 (char-db-decode-isolated-char name value)))
770 (if (and (= (charset-chars name) 94)
771 (= (charset-dimension name) 2))
772 (insert (format " [%02d-%02d]"
773 (- (lsh value -8) 32)
774 (- (logand value 255) 32))))
777 (insert (format "(%-18s . %s)" name value))
779 (insert line-breaking))
781 (defun char-db-insert-relation-feature (char name value line-breaking
783 (insert (format "(%-18s%s " name line-breaking))
784 (let ((lbs (concat "\n" (make-string (current-column) ?\ )))
785 separator cell sources required-features
788 (setq cell (car value))
790 (setq cell (decode-char '=ucs cell)))
792 ((eq name '->subsumptive)
793 (when (or (not (some (lambda (atr)
794 (get-char-attribute cell atr))
795 char-db-ignored-attributes))
797 (encode-char cell ccs 'defined-only))
801 (let ((char-db-ignored-attributes
803 char-db-ignored-attributes)))
804 (insert-char-attributes cell readable nil nil 'for-sub-node))
805 (setq separator lbs))
810 char (intern (format "%s*sources" name))))
811 (setq required-features nil)
812 (dolist (source sources)
816 shinjigen shinjigen@1ed shinjigen@rev))
817 (setq required-features
818 (union required-features
830 =shinjigen/+p@rev))))
832 (setq required-features
833 (union required-features
838 ((find-charset (setq ret (intern (format "=%s" source))))
839 (setq required-features
840 (cons ret required-features)))
841 (t (setq required-features
842 (cons source required-features)))))
843 (cond ((string-match "@JP" (symbol-name name))
844 (setq required-features
845 (union required-features
853 ((string-match "@CN" (symbol-name name))
854 (setq required-features
855 (union required-features
862 (insert (format "%S" cell))
863 (char-db-insert-char-spec cell readable
866 (setq separator lbs))
870 (if (consp (car cell))
871 (char-db-insert-char-spec cell readable)
872 (char-db-insert-char-reference cell readable))
873 (setq separator lbs))
877 (insert (prin1-to-string cell))
878 (setq separator " ")))
879 (setq value (cdr value)))
881 (insert line-breaking)))
883 (defun insert-char-attributes (char &optional readable attributes column
886 (setq column (current-column)))
887 (let (name value ; has-long-ccs-name
891 (concat "\n" (make-string (1+ column) ?\ )))
892 lbs cell separator ret
894 dest-ccss ; sources required-features
899 (if (consp attributes)
901 (dolist (name attributes)
902 (unless (memq name char-db-ignored-attributes)
903 (if (find-charset name)
907 (dolist (name (char-attribute-list))
908 (unless (memq name char-db-ignored-attributes)
909 (if (find-charset name)
913 #'char-attribute-name<)))
915 (when (memq '<-subsumptive attributes)
916 (when (or readable (not for-sub-node))
917 (when (setq value (get-char-attribute char '<-subsumptive))
918 (char-db-insert-relation-feature char '<-subsumptive value
921 (setq attributes (delq '<-subsumptive attributes)))
922 (when (and (memq '<-denotational attributes)
923 (setq value (get-char-attribute char '<-denotational)))
924 (char-db-insert-relation-feature char '<-denotational value
927 (setq attributes (delq '<-denotational attributes)))
928 (when (and (memq '<-denotational@component attributes)
929 (setq value (get-char-attribute char '<-denotational@component)))
930 (char-db-insert-relation-feature char '<-denotational@component value
933 (setq attributes (delq '<-denotational@component attributes)))
934 (when (and (memq 'name attributes)
935 (setq value (get-char-attribute char 'name)))
937 (if (> (+ (current-column) (length value)) 48)
940 value line-breaking))
941 (setq attributes (delq 'name attributes))
943 (when (and (memq 'name* attributes)
944 (setq value (get-char-attribute char 'name*)))
946 (if (> (+ (current-column) (length value)) 48)
949 value line-breaking))
950 (setq attributes (delq 'name* attributes))
952 (when (and (memq 'script attributes)
953 (setq value (get-char-attribute char 'script)))
954 (insert (format "(script\t\t%s)%s"
955 (mapconcat (function prin1-to-string)
958 (setq attributes (delq 'script attributes))
960 (dolist (name '(=>ucs =>ucs*))
961 (when (and (memq name attributes)
962 (setq value (get-char-attribute char name)))
963 (insert (format "(%-18s . #x%04X)\t; %c%s"
964 name value (decode-char '=ucs value)
966 (setq attributes (delq name attributes))))
967 (dolist (name '(=>ucs@gb =>ucs@big5))
968 (when (and (memq name attributes)
969 (setq value (get-char-attribute char name)))
970 (insert (format "(%-18s . #x%04X)\t; %c%s"
975 (symbol-name name) 2)))
978 (setq attributes (delq name attributes))
980 ;; (dolist (name '(=>daikanwa))
981 ;; (when (and (memq name attributes)
982 ;; (setq value (get-char-attribute char name)))
984 ;; (if (integerp value)
985 ;; (format "(%-18s . %05d)\t; %c%s"
986 ;; name value (decode-char '=daikanwa value)
988 ;; (format "(%-18s %s)\t; %c%s"
990 ;; (mapconcat (function prin1-to-string)
992 ;; (char-representative-of-daikanwa char)
994 ;; (setq attributes (delq name attributes))))
995 (when (and (memq 'general-category attributes)
996 (setq value (get-char-attribute char 'general-category)))
998 "(general-category\t%s) ; %s%s"
999 (mapconcat (lambda (cell)
1002 (cond ((rassoc value unidata-normative-category-alist)
1003 "Normative Category")
1004 ((rassoc value unidata-informative-category-alist)
1005 "Informative Category")
1007 "Unknown Category"))
1009 (setq attributes (delq 'general-category attributes))
1011 (when (and (memq 'bidi-category attributes)
1012 (setq value (get-char-attribute char 'bidi-category)))
1013 (insert (format "(bidi-category\t. %S)%s"
1016 (setq attributes (delq 'bidi-category attributes))
1018 (unless (or (not (memq 'mirrored attributes))
1019 (eq (setq value (get-char-attribute char 'mirrored 'empty))
1021 (insert (format "(mirrored\t\t. %S)%s"
1024 (setq attributes (delq 'mirrored attributes))
1027 ((and (memq 'decimal-digit-value attributes)
1028 (setq value (get-char-attribute char 'decimal-digit-value)))
1029 (insert (format "(decimal-digit-value . %S)%s"
1032 (setq attributes (delq 'decimal-digit-value attributes))
1033 (when (and (memq 'digit-value attributes)
1034 (setq value (get-char-attribute char 'digit-value)))
1035 (insert (format "(digit-value\t . %S)%s"
1038 (setq attributes (delq 'digit-value attributes))
1040 (when (and (memq 'numeric-value attributes)
1041 (setq value (get-char-attribute char 'numeric-value)))
1042 (insert (format "(numeric-value\t . %S)%s"
1045 (setq attributes (delq 'numeric-value attributes))
1049 (when (and (memq 'digit-value attributes)
1050 (setq value (get-char-attribute char 'digit-value)))
1051 (insert (format "(digit-value\t. %S)%s"
1054 (setq attributes (delq 'digit-value attributes))
1056 (when (and (memq 'numeric-value attributes)
1057 (setq value (get-char-attribute char 'numeric-value)))
1058 (insert (format "(numeric-value\t. %S)%s"
1061 (setq attributes (delq 'numeric-value attributes))
1063 (when (and (memq 'iso-10646-comment attributes)
1064 (setq value (get-char-attribute char 'iso-10646-comment)))
1065 (insert (format "(iso-10646-comment\t. %S)%s"
1068 (setq attributes (delq 'iso-10646-comment attributes))
1070 (when (and (memq 'morohashi-daikanwa attributes)
1071 (setq value (get-char-attribute char 'morohashi-daikanwa)))
1072 (insert (format "(morohashi-daikanwa\t%s)%s"
1073 (mapconcat (function prin1-to-string) value " ")
1075 (setq attributes (delq 'morohashi-daikanwa attributes))
1079 (when (and (memq 'ideographic-radical attributes)
1080 (setq value (get-char-attribute char 'ideographic-radical)))
1081 (setq radical value)
1082 (insert (format "(ideographic-radical . %S)\t; %c%s"
1084 (ideographic-radical radical)
1086 (setq attributes (delq 'ideographic-radical attributes))
1088 (when (and (memq 'shuowen-radical attributes)
1089 (setq value (get-char-attribute char 'shuowen-radical)))
1090 (insert (format "(shuowen-radical\t. %S)\t; %c%s"
1092 (shuowen-radical value)
1094 (setq attributes (delq 'shuowen-radical attributes))
1099 char-db-feature-domains
1101 (dolist (feature (char-attribute-list))
1102 (setq feature (symbol-name feature))
1104 "\\(radical\\|strokes\\)@\\([^@*]+\\)\\(\\*\\|$\\)"
1106 (setq domain (intern (match-string 2 feature)))
1107 (unless (memq domain dest)
1108 (setq dest (cons domain dest)))))
1109 (sort dest #'string<))))
1110 (setq key (intern (format "%s@%s" 'ideographic-radical domain)))
1111 (when (and (memq key attributes)
1112 (setq value (get-char-attribute char key)))
1113 (setq radical value)
1114 (insert (format "(%s . %S)\t; %c%s"
1117 (ideographic-radical radical)
1119 (setq attributes (delq key attributes))
1121 (setq key (intern (format "%s@%s" 'ideographic-strokes domain)))
1122 (when (and (memq key attributes)
1123 (setq value (get-char-attribute char key)))
1124 (setq strokes value)
1125 (insert (format "(%s . %S)%s"
1129 (setq attributes (delq key attributes))
1131 (setq key (intern (format "%s@%s" 'total-strokes domain)))
1132 (when (and (memq key attributes)
1133 (setq value (get-char-attribute char key)))
1134 (insert (format "(%s . %S)%s"
1138 (setq attributes (delq key attributes))
1140 (dolist (feature '(ideographic-radical
1143 (setq key (intern (format "%s@%s*sources" feature domain)))
1144 (when (and (memq key attributes)
1145 (setq value (get-char-attribute char key)))
1146 (insert (format "(%s%s" key line-breaking))
1147 (dolist (cell value)
1148 (insert (format " %s" cell)))
1150 (insert line-breaking)
1151 (setq attributes (delq key attributes))
1154 (when (and (memq 'ideographic-strokes attributes)
1155 (setq value (get-char-attribute char 'ideographic-strokes)))
1156 (setq strokes value)
1157 (insert (format "(ideographic-strokes . %S)%s"
1160 (setq attributes (delq 'ideographic-strokes attributes))
1162 (when (and (memq 'kangxi-radical attributes)
1163 (setq value (get-char-attribute char 'kangxi-radical)))
1164 (unless (eq value radical)
1165 (insert (format "(kangxi-radical\t . %S)\t; %c%s"
1167 (ideographic-radical value)
1170 (setq radical value)))
1171 (setq attributes (delq 'kangxi-radical attributes))
1173 (when (and (memq 'kangxi-strokes attributes)
1174 (setq value (get-char-attribute char 'kangxi-strokes)))
1175 (unless (eq value strokes)
1176 (insert (format "(kangxi-strokes\t . %S)%s"
1180 (setq strokes value)))
1181 (setq attributes (delq 'kangxi-strokes attributes))
1183 ;; (when (and (memq 'japanese-radical attributes)
1184 ;; (setq value (get-char-attribute char 'japanese-radical)))
1185 ;; (unless (eq value radical)
1186 ;; (insert (format "(japanese-radical\t . %S)\t; %c%s"
1188 ;; (ideographic-radical value)
1191 ;; (setq radical value)))
1192 ;; (setq attributes (delq 'japanese-radical attributes))
1194 (when (and (memq 'japanese-strokes attributes)
1195 (setq value (get-char-attribute char 'japanese-strokes)))
1196 (unless (eq value strokes)
1197 (insert (format "(japanese-strokes\t . %S)%s"
1201 (setq strokes value)))
1202 (setq attributes (delq 'japanese-strokes attributes))
1204 (when (and (memq 'cns-radical attributes)
1205 (setq value (get-char-attribute char 'cns-radical)))
1206 (insert (format "(cns-radical\t . %S)\t; %c%s"
1208 (ideographic-radical value)
1210 (setq attributes (delq 'cns-radical attributes))
1212 (when (and (memq 'cns-strokes attributes)
1213 (setq value (get-char-attribute char 'cns-strokes)))
1214 (unless (eq value strokes)
1215 (insert (format "(cns-strokes\t . %S)%s"
1219 (setq strokes value)))
1220 (setq attributes (delq 'cns-strokes attributes))
1222 ;; (when (and (memq 'shinjigen-1-radical attributes)
1223 ;; (setq value (get-char-attribute char 'shinjigen-1-radical)))
1224 ;; (unless (eq value radical)
1225 ;; (insert (format "(shinjigen-1-radical . %S)\t; %c%s"
1227 ;; (ideographic-radical value)
1230 ;; (setq radical value)))
1231 ;; (setq attributes (delq 'shinjigen-1-radical attributes))
1233 ;; (when (and (memq 'ideographic- attributes)
1234 ;; (setq value (get-char-attribute char 'ideographic-)))
1235 ;; (insert "(ideographic- ")
1236 ;; (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1238 ;; (while (consp value)
1239 ;; (setq cell (car value))
1240 ;; (if (integerp cell)
1241 ;; (setq cell (decode-char '=ucs cell)))
1242 ;; (cond ((characterp cell)
1246 ;; (insert (format "%S" cell))
1247 ;; (char-db-insert-char-spec cell readable))
1248 ;; (setq separator lbs))
1252 ;; (if (consp (car cell))
1253 ;; (char-db-insert-char-spec cell readable)
1254 ;; (char-db-insert-char-reference cell readable))
1255 ;; (setq separator lbs))
1258 ;; (insert separator))
1259 ;; (insert (prin1-to-string cell))
1260 ;; (setq separator " ")))
1261 ;; (setq value (cdr value)))
1263 ;; (insert line-breaking)
1264 ;; (setq attributes (delq 'ideographic- attributes)))
1265 (when (and (memq 'total-strokes attributes)
1266 (setq value (get-char-attribute char 'total-strokes)))
1267 (insert (format "(total-strokes . %S)%s"
1270 (setq attributes (delq 'total-strokes attributes))
1272 ;; (when (and (memq '->ideograph attributes)
1273 ;; (setq value (get-char-attribute char '->ideograph)))
1274 ;; (insert (format "(->ideograph\t%s)%s"
1275 ;; (mapconcat (lambda (code)
1276 ;; (cond ((symbolp code)
1277 ;; (symbol-name code))
1279 ;; (format "#x%04X" code))
1282 ;; line-breaking code))))
1285 ;; (setq attributes (delq '->ideograph attributes))
1287 ;; (when (and (memq '->decomposition attributes)
1288 ;; (setq value (get-char-attribute char '->decomposition)))
1289 ;; (insert (format "(->decomposition\t%s)%s"
1290 ;; (mapconcat (lambda (code)
1291 ;; (cond ((symbolp code)
1292 ;; (symbol-name code))
1293 ;; ((characterp code)
1295 ;; (format "%S" code)
1300 ;; (format "#x%04X" code))
1302 ;; (format "%s%S" line-breaking code))))
1305 ;; (setq attributes (delq '->decomposition attributes))
1307 (if (equal (get-char-attribute char '->titlecase)
1308 (get-char-attribute char '->uppercase))
1309 (setq attributes (delq '->titlecase attributes)))
1310 (when (and (memq '->mojikyo attributes)
1311 (setq value (get-char-attribute char '->mojikyo)))
1312 (insert (format "(->mojikyo\t\t. %06d)\t; %c%s"
1313 value (decode-char 'mojikyo value)
1315 (setq attributes (delq '->mojikyo attributes))
1317 ;; (when (and (memq 'hanyu-dazidian-vol attributes)
1318 ;; (setq value (get-char-attribute char 'hanyu-dazidian-vol)))
1319 ;; (insert (format "(hanyu-dazidian-vol . %d)%s"
1320 ;; value line-breaking))
1321 ;; (setq attributes (delq 'hanyu-dazidian-vol attributes))
1323 ;; (when (and (memq 'hanyu-dazidian-page attributes)
1324 ;; (setq value (get-char-attribute char 'hanyu-dazidian-page)))
1325 ;; (insert (format "(hanyu-dazidian-page . %d)%s"
1326 ;; value line-breaking))
1327 ;; (setq attributes (delq 'hanyu-dazidian-page attributes))
1329 ;; (when (and (memq 'hanyu-dazidian-char attributes)
1330 ;; (setq value (get-char-attribute char 'hanyu-dazidian-char)))
1331 ;; (insert (format "(hanyu-dazidian-char . %d)%s"
1332 ;; value line-breaking))
1333 ;; (setq attributes (delq 'hanyu-dazidian-char attributes))
1336 (dolist (ignored '(composition
1337 ->denotational <-subsumptive ->ucs-unified
1338 ->ideographic-component-forms))
1339 (setq attributes (delq ignored attributes))))
1341 (setq name (car attributes))
1342 (unless (eq (setq value (get-char-attribute char name 'value-is-empty))
1344 (cond ((setq ret (find-charset name))
1345 (setq name (charset-name ret))
1346 (when (not (memq name dest-ccss))
1347 (setq dest-ccss (cons name dest-ccss))
1348 (char-db-insert-ccs-feature name value line-breaking))
1350 ((string-match "^=>ucs@" (symbol-name name))
1351 (insert (format "(%-18s . #x%04X)\t; %c%s"
1352 name value (decode-char '=ucs value)
1355 ((eq name 'jisx0208-1978/4X)
1356 (insert (format "(%-18s . #x%04X)%s"
1362 (not (eq name '->subsumptive))
1363 (not (eq name '->uppercase))
1364 (not (eq name '->lowercase))
1365 (not (eq name '->titlecase))
1366 (not (eq name '->canonical))
1367 (not (eq name '->Bopomofo))
1368 (not (eq name '->mistakable))
1369 (not (eq name '->ideographic-variants))
1370 (null (get-char-attribute
1371 char (intern (format "%s*sources" name))))
1372 (not (string-match "\\*sources$" (symbol-name name)))
1373 (null (get-char-attribute
1374 char (intern (format "%s*note" name))))
1375 (not (string-match "\\*note$" (symbol-name name)))
1376 (or (eq name '<-identical)
1377 (eq name '<-uppercase)
1378 (eq name '<-lowercase)
1379 (eq name '<-titlecase)
1380 (eq name '<-canonical)
1381 (eq name '<-ideographic-variants)
1382 ;; (eq name '<-synonyms)
1383 (string-match "^<-synonyms" (symbol-name name))
1384 (eq name '<-mistakable)
1385 (when (string-match "^->" (symbol-name name))
1387 ((string-match "^->fullwidth" (symbol-name name))
1388 (not (and (consp value)
1389 (characterp (car value))
1391 (car value) '=ucs 'defined-only)))
1396 ((or (eq name 'ideographic-structure)
1397 (eq name 'ideographic-combination)
1398 ;; (eq name 'ideographic-)
1399 (eq name '=decomposition)
1400 (char-feature-base-name= '=decomposition name)
1401 (char-feature-base-name= '=>decomposition name)
1402 ;; (string-match "^=>*decomposition\\(@[^*]+\\)?$"
1403 ;; (symbol-name name))
1404 (string-match "^\\(->\\|<-\\)[^*]*$" (symbol-name name))
1405 (string-match "^\\(->\\|<-\\)[^*]*\\*sources$"
1408 (char-db-insert-relation-feature char name value
1411 ;; ((memq name '(ideograph=
1412 ;; original-ideograph-of
1413 ;; ancient-ideograph-of
1414 ;; vulgar-ideograph-of
1415 ;; wrong-ideograph-of
1416 ;; ;; simplified-ideograph-of
1417 ;; ideographic-variants
1418 ;; ;; ideographic-different-form-of
1420 ;; (insert (format "(%-18s%s " name line-breaking))
1421 ;; (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1423 ;; (while (consp value)
1424 ;; (setq cell (car value))
1425 ;; (if (and (consp cell)
1426 ;; (consp (car cell)))
1430 ;; (char-db-insert-alist cell readable)
1431 ;; (setq separator lbs))
1433 ;; (insert separator))
1434 ;; (insert (prin1-to-string cell))
1435 ;; (setq separator " "))
1436 ;; (setq value (cdr value)))
1438 ;; (insert line-breaking))
1440 (insert (format "(%-18s " name))
1441 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1443 (while (consp value)
1444 (setq cell (car value))
1445 (if (and (consp cell)
1447 (setq ret (condition-case nil
1455 (setq key (car (car rest)))
1456 (if (find-charset key)
1457 (setq cal (cons key cal))
1458 (setq al (cons key al)))
1459 (setq rest (cdr rest)))
1462 (insert-char-attributes ret
1466 (setq separator lbs))
1467 (setq ret (prin1-to-string cell))
1469 (if (< (+ (current-column)
1476 (setq separator " "))
1477 (setq value (cdr value)))
1479 (insert line-breaking))
1481 (insert (format "(%-18s" name))
1482 (setq ret (prin1-to-string value))
1483 (unless (< (+ (current-column)
1487 (insert line-breaking))
1488 (insert " . " ret ")" line-breaking)
1489 ;; (insert (format "(%-18s . %S)%s"
1494 (setq attributes (cdr attributes)))
1497 (defun insert-char-data (char &optional readable
1500 (narrow-to-region (point)(point))
1501 (insert "(define-char
1503 (insert-char-attributes char readable attributes)
1505 (goto-char (point-min))
1506 (while (re-search-forward "[ \t]+$" nil t)
1509 (goto-char (point-min))
1510 (while (re-search-forward "[ \t][ \t][ \t]*" nil t)
1511 (let ((column (current-column))
1512 (indent-tabs-mode t))
1513 (delete-region (match-beginning 0) (point))
1514 (indent-to column)))
1515 (goto-char (point-max))
1516 ;; (tabify (point-min)(point-max))
1519 (defun insert-char-data-with-variant (char &optional printable
1521 script excluded-script)
1522 (insert-char-data char printable)
1523 (let ((variants (char-variants char))
1526 (setq variants (sort variants #'<))
1527 (setq rest variants)
1528 (setq variants (cons char variants))
1530 (setq variant (car rest))
1531 (unless (get-char-attribute variant '<-subsumptive)
1532 (if (and (or (null script)
1533 (null (setq vs (get-char-attribute variant 'script)))
1535 (or (null excluded-script)
1536 (null (setq vs (get-char-attribute variant 'script)))
1537 (not (memq excluded-script vs))))
1538 (unless (and no-ucs-unified (get-char-attribute variant '=ucs))
1539 (insert-char-data variant printable)
1540 (if (setq ret (char-variants variant))
1542 (or (memq (car ret) variants)
1543 ;; (get-char-attribute (car ret) '<-subsumptive)
1544 (setq rest (nconc rest (list (car ret)))))
1545 (setq ret (cdr ret)))))))
1546 (setq rest (cdr rest)))))
1548 (defun insert-char-range-data (min max &optional script excluded-script)
1551 (while (<= code max)
1552 (setq char (decode-char '=ucs code))
1553 (if (encode-char char '=ucs 'defined-only)
1554 (insert-char-data-with-variant char nil 'no-ucs-unified
1555 script excluded-script))
1556 (setq code (1+ code)))))
1558 (defun write-char-range-data-to-file (min max file
1559 &optional script excluded-script)
1560 (let ((coding-system-for-write char-db-file-coding-system))
1562 (insert (format ";; -*- coding: %s -*-\n"
1563 char-db-file-coding-system))
1564 (insert-char-range-data min max script excluded-script)
1565 (write-region (point-min)(point-max) file))))
1567 (defvar what-character-original-window-configuration)
1570 (defun what-char-definition (char)
1571 (interactive (list (char-after)))
1572 (let ((buf (get-buffer-create "*Character Description*"))
1573 (the-buf (current-buffer))
1574 (win-conf (current-window-configuration)))
1576 (make-local-variable 'what-character-original-window-configuration)
1577 (setq what-character-original-window-configuration win-conf)
1578 (setq buffer-read-only nil)
1582 (insert-char-data-with-variant char 'printable)
1583 (unless (char-attribute-alist char)
1584 (insert (format ";; = %c\n"
1585 (let* ((rest (split-char char))
1589 (setq code (logior (lsh code 8)
1591 (decode-char ccs code)))))
1592 ;; (char-db-update-comment)
1593 (set-buffer-modified-p nil)
1594 (view-mode the-buf (lambda (buf)
1595 (set-window-configuration
1596 what-character-original-window-configuration)
1598 (goto-char (point-min)))
1600 (set-window-configuration
1601 what-character-original-window-configuration)
1602 (signal (car err) (cdr err)))))))
1608 (provide 'char-db-util)
1610 ;;; char-db-util.el ends here