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, 2018, 2019,
5 ;; 2020 MORIOKA Tomohiko.
7 ;; Author: MORIOKA Tomohiko <tomo@kanji.zinbun.kyoto-u.ac.jp>
8 ;; Keywords: CHISE, Character Database, ISO/IEC 10646, UCS, Unicode, MULE.
10 ;; This file is part of XEmacs CHISE.
12 ;; XEmacs CHISE is free software; you can redistribute it and/or
13 ;; modify it under the terms of the GNU General Public License as
14 ;; published by the Free Software Foundation; either version 2, or (at
15 ;; your option) any later version.
17 ;; XEmacs CHISE is distributed in the hope that it will be useful,
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 ;; General Public License for more details.
22 ;; You should have received a copy of the GNU General Public License
23 ;; along with XEmacs CHISE; see the file COPYING. If not, write to
24 ;; the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
25 ;; Boston, MA 02111-1307, USA.
30 (require 'ideograph-subr)
32 (defconst unidata-normative-category-alist
33 '(("Lu" letter uppercase)
34 ("Ll" letter lowercase)
35 ("Lt" letter titlecase)
36 ("Mn" mark non-spacing)
37 ("Mc" mark spacing-combining)
39 ("Nd" number decimal-digit)
42 ("Zs" separator space)
44 ("Zp" separator paragraph)
47 ("Cs" other surrogate)
48 ("Co" other private-use)
49 ("Cn" other not-assigned)))
51 (defconst unidata-informative-category-alist
52 '(("Lm" letter modifier)
54 ("Pc" punctuation connector)
55 ("Pd" punctuation dash)
56 ("Ps" punctuation open)
57 ("Pe" punctuation close)
58 ("Pi" punctuation initial-quote)
59 ("Pf" punctuation final-quote)
60 ("Po" punctuation other)
62 ("Sc" symbol currency)
63 ("Sk" symbol modifier)
67 (defconst shuowen-radicals
68 [?一 ?上 ?示 ?三 ?王 ?玉 ?玨 ?气 ?士 ?丨 ; 010
69 ?屮 ?艸 ?蓐 ?茻 ?小 ?八 ?釆 ?半 ?牛 ?犛 ; 020
70 ?告 ?口 ?凵 ?吅 ?哭 ?走 ?止 ?癶 ?步 ?此 ; 030
71 ?正 ?是 ?辵 ?彳 ?廴 ?㢟 ?行 ?齒 ?牙 ?足 ; 040
72 ?疋 ?品 ?龠 ?冊 ?㗊 ?舌 ?干 ?𧮫 ?只 ?㕯 ; 050
73 ?句 ?丩 ?古 ?十 ?卅 ?言 ?誩 ?音 ?䇂 ?丵 ; 060
74 ?菐 ?廾 ?𠬜 ?共 ?異 ?舁 ?𦥑 ?䢅 ?爨 ?革 ; 070
75 ?鬲 ?䰜 ?爪 ?𠃨 ?鬥 ?又 ?𠂇 ?史 ?支 ?𦘒 ; 080
76 ?聿 ?畫 ?隶 ?臤 ?臣 ?殳 ?殺 ?𠘧 ?寸 ?皮 ; 090
77 ?㼱 ?攴 ?敎 ?卜 ?用 ?爻 ?㸚 ?𥄎 ?目 ?䀠 ; 100
78 ?眉 ?盾 ?自 ?白 ?鼻 ?皕 ?習 ?羽 ?隹 ?奞 ; 110
79 ?雈 ?𦫳 ?𥄕 ?羊 ?羴 ?瞿 ?雔 ?雥 ?鳥 ?烏 ; 120
80 ?𠦒 ?冓 ?幺 ?𢆶 ?叀 ?玄 ?予 ?放 ?𠬪 ?𣦼 ; 130
81 ?歺 ?死 ?冎 ?骨 ?肉 ?筋 ?刀 ?刃 ?㓞 ?丯 ; 140
82 ?耒 ?角 ?竹 ?箕 ?丌 ?左 ?工 ?㠭 ?巫 ?甘 ; 150
83 ?曰 ?乃 ?丂 ?可 ?兮 ?号 ?亏 ?旨 ?喜 ?壴 ; 160
84 ; ?旨 ?曰 ?乃 ?丂 ?可 ?兮 ?号 ?亏 ?喜 ?壴 ; 160
85 ?鼓 ?豈 ?豆 ?豊 ?豐 ?䖒 ?虍 ?虎 ?虤 ?皿 ; 170
86 ?𠙴 ?去 ?血 ?丶 ?丹 ?青 ?井 ?皀 ?鬯 ?食 ; 180
87 ?亼 ?會 ?倉 ?入 ?缶 ?矢 ?高 ?冂 ?𩫏 ?京 ; 190
88 ?亯 ?𣆪 ?畗 ?㐭 ?嗇 ?來 ?麥 ?夊 ?舛 ?䑞 ; 200
89 ?韋 ?弟 ?夂 ?久 ?桀 ?木 ?東 ?林 ?才 ?叒 ; 210
90 ?之 ?帀 ?出 ?𣎵 ?生 ?乇 ?𠂹 ?𠌶 ?華 ?𥝌 ; 220
91 ?稽 ?巢 ?桼 ?束 ?㯻 ?囗 ?員 ?貝 ?邑 ?𨛜 ; 230
92 ?日 ?旦 ?倝 ?㫃 ?冥 ?晶 ?月 ?有 ?明 ?囧 ; 240
93 ?夕 ?多 ?毌 ?𢎘 ?𣐺 ?𠧪 ?齊 ?朿 ?片 ?鼎 ; 250
94 ?克 ?彔 ?禾 ?秝 ?黍 ?香 ?米 ?毇 ?臼 ?凶 ; 260
95 ?𣎳 ?𣏟 ?麻 ?尗 ?耑 ?韭 ?瓜 ?瓠 ?宀 ?宮 ; 270
96 ?呂 ?穴 ?㝱 ?疒 ?冖 ?𠔼 ?冃 ?㒳 ?网 ?襾 ; 280
97 ?巾 ?巿 ?帛 ?白 ?㡀 ?黹 ?人 ?𠤎 ?匕 ?从 ; 290
98 ?比 ?北 ?丘 ?㐺 ?𡈼 ?重 ?臥 ?身 ?㐆 ?衣 ; 300
99 ?裘 ?老 ?毛 ?毳 ?尸 ?尺 ?尾 ?履 ?舟 ?方 ; 310
100 ?儿 ?兄 ?兂 ?皃 ?𠑹 ?先 ?秃 ?見 ?覞 ?欠 ; 320
101 ?㱃 ?㳄 ?旡 ?頁 ?𦣻 ?面 ?丏 ?首 ?𥄉 ?須 ; 330
102 ?彡 ?彣 ?文 ?髟 ?后 ?司 ?卮 ?卩 ?印 ?色 ; 340
103 ?𠨍 ?辟 ?勹 ?包 ?茍 ?鬼 ?甶 ?厶 ?嵬 ?山 ; 350
104 ?屾 ?屵 ?广 ?厂 ?丸 ?危 ?石 ?長 ?勿 ?冄 ; 360
105 ?而 ?豕 ?㣇 ?彑 ?豚 ?豸 ?𤉡 ?易 ?象 ?馬 ; 370
106 ?𢊁 ?鹿 ?麤 ?㲋 ?兔 ?萈 ?犬 ?㹜 ?鼠 ?能 ; 380
107 ?熊 ?火 ?炎 ?黑 ?囪 ?焱 ?炙 ?赤 ?大 ?亦 ; 390
108 ?夨 ?夭 ?交 ?尣 ?壺 ?壹 ?㚔 ?奢 ?亢 ?夲 ; 400
111 (defun shuowen-radical (number)
112 (aref shuowen-radicals (1- number)))
114 (defvar char-db-file-coding-system 'utf-8-mcs-er)
116 (defvar char-db-ignored-attributes '(ideographic-products))
118 (defvar char-db-coded-charset-priority-list
218 ;; =>>>adobe-japan1-0
219 ;; =>>>adobe-japan1-1
220 ;; =>>>adobe-japan1-2
221 ;; =>>>adobe-japan1-3
222 ;; =>>>adobe-japan1-4
223 ;; =>>>adobe-japan1-5
224 ;; =>>>adobe-japan1-6
228 ;; =>>>hanyo-denshi/ja
229 ;; =>>>hanyo-denshi/jb
230 ;; =>>>hanyo-denshi/jc
231 ;; =>>>hanyo-denshi/ft
232 ;; =>>>hanyo-denshi/ib
233 ;; =>>>hanyo-denshi/hg
234 ;; =>>>hanyo-denshi/jt
235 ;; =>>>hanyo-denshi/ks
275 ;; =>ucs@hanyo-denshi
382 =>big5-cdp-itaiji-001
383 =>big5-cdp-itaiji-002
384 =>big5-cdp-itaiji-003
389 =>ucs@iwds-1/normalized
390 =>ucs-itaiji-001@iwds-1
391 =>ucs-itaiji-002@iwds-1
400 ;;; @ char-db formatters
403 (defun char-db-make-char-spec (char)
405 (cond ((characterp char)
406 (cond ((and (setq ret (encode-char char '=ucs 'defined-only))
407 (not (and (<= #xE000 ret)(<= ret #xF8FF))))
408 (setq char-spec (list (cons '=ucs ret)))
409 (cond ((setq ret (get-char-attribute char 'name))
410 (setq char-spec (cons (cons 'name ret) char-spec))
412 ((setq ret (get-char-attribute char 'name*))
413 (setq char-spec (cons (cons 'name* ret) char-spec))
416 ((encode-char char '=mj 'defined-only)
418 (dolist (ccs (charset-list))
419 (if (and (or (eq ccs '=mj)
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))))
428 ((encode-char char '==mj 'defined-only)
430 (dolist (ccs (charset-list))
431 (if (and (or (eq ccs '==mj)
432 ;; (eq (charset-property ccs 'iso-ir) 177)
433 (string-match "=ucs@" (symbol-name ccs))
435 (setq ccs (charset-name ccs))
436 (null (assq ccs char-spec))
437 (setq ret (encode-char char ccs 'defined-only)))
438 (setq char-spec (cons (cons ccs ret) char-spec))))
440 ((encode-char char '=adobe-japan1 'defined-only)
442 (dolist (ccs (charset-list))
443 (if (and (or (memq ccs
452 ;; (eq (charset-property ccs 'iso-ir) 177)
453 (string-match "=ucs@" (symbol-name ccs))
455 (setq ccs (charset-name ccs))
456 (null (assq ccs char-spec))
457 (setq ret (encode-char char ccs 'defined-only)))
458 (setq char-spec (cons (cons ccs ret) char-spec))))
460 ((encode-char char '==adobe-japan1 'defined-only)
462 (dolist (ccs (charset-list))
463 (if (and (or (memq ccs
472 ;; (eq (charset-property ccs 'iso-ir) 177)
473 (string-match "=ucs@" (symbol-name ccs))
475 (setq ccs (charset-name ccs))
476 (null (assq ccs char-spec))
477 (setq ret (encode-char char ccs 'defined-only)))
478 (setq char-spec (cons (cons ccs ret) char-spec))))
482 (let ((rest char-db-coded-charset-priority-list)
485 (setq ccs (charset-name
486 (find-charset (car rest))))
488 (encode-char char ccs
490 (throw 'tag (cons ccs ret)))
491 (setq rest (cdr rest))))))
492 (setq char-spec (list ret))
493 (dolist (ccs (delq (car ret) (charset-list)))
494 (if (and (or (charset-iso-final-char ccs)
501 (and (eq (charset-property ccs 'iso-ir) 177)
502 (not (eq (charset-name ccs) '=ucs@big5)))
503 ;; (string-match "=ucs@" (symbol-name ccs))
505 (setq ccs (charset-name ccs))
506 (null (assq ccs char-spec))
507 (setq ret (encode-char char ccs 'defined-only)))
508 (setq char-spec (cons (cons ccs ret) char-spec))))
510 (setq char-spec (split-char char)))
511 (cond ((setq ret (get-char-attribute char 'name))
512 (setq char-spec (cons (cons 'name ret) char-spec))
514 ((setq ret (get-char-attribute char 'name*))
515 (setq char-spec (cons (cons 'name* ret) char-spec))
518 ((setq ret (get-char-attribute
519 char 'ideographic-combination))
521 (cons (cons 'ideographic-combination ret)
528 (defun char-db-insert-char-spec (char &optional readable column
531 (setq column (current-column)))
532 (let (char-spec temp-char)
533 (setq char-spec (char-db-make-char-spec char))
534 (unless (or (characterp char) ; char
536 (setq char (find-char char-spec))
538 ;; define temporary character
539 ;; Current implementation is dirty.
540 (setq temp-char (define-char (cons '(ideograph-daikanwa . 0)
542 (remove-char-attribute temp-char 'ideograph-daikanwa)
543 (setq char temp-char))
544 (insert-char-attributes char
546 (union (mapcar #'car char-spec)
550 ;; undefine temporary character
551 ;; Current implementation is dirty.
552 (setq char-spec (char-attribute-alist temp-char))
554 (remove-char-attribute temp-char (car (car char-spec)))
555 (setq char-spec (cdr char-spec))))))
557 (defun char-db-insert-alist (alist &optional readable column)
559 (setq column (current-column)))
561 (concat "\n" (make-string (1+ column) ?\ )))
565 lbs cell rest separator)
568 (setq name (car (car alist))
569 value (cdr (car alist)))
570 (cond ((eq name 'char)
572 (if (setq ret (condition-case nil
580 (setq key (car (car value)))
581 ;; (if (find-charset key)
582 ;; (setq cal (cons key cal))
583 (setq al (cons key al))
585 (setq value (cdr value)))
586 (insert-char-attributes ret
590 (insert (prin1-to-string value)))
592 (insert line-breaking))
594 (insert (format "(%-18s " name))
595 (setq lbs (concat "\n" (make-string (current-column) ?\ )))
597 (setq cell (car value))
598 (if (and (consp cell)
600 (setq ret (condition-case nil
610 (setq key (car (car rest)))
611 ;; (if (find-charset key)
612 ;; (setq cal (cons key cal))
613 (setq al (cons key al))
615 (setq rest (cdr rest)))
618 (insert-char-attributes ret
622 (setq separator lbs))
625 (insert (prin1-to-string cell))
626 (setq separator " "))
627 (setq value (cdr value)))
629 (insert line-breaking))
631 (insert (format "(%-18s . %S)%s"
634 (setq alist (cdr alist))))
637 (defun char-db-insert-char-reference (plist &optional readable column)
639 (setq column (current-column)))
641 (concat "\n" (make-string (1+ column) ?\ )))
646 (setq name (pop plist))
647 (setq value (pop plist))
648 (cond ((eq name :char)
651 (cond ((numberp value)
652 (setq value (decode-char '=ucs value)))
654 ;; (setq value (or (find-char value)
657 (char-db-insert-char-spec value readable)
658 (insert line-breaking)
661 (insert (format "%s%s\t%d ; %c%s"
664 (ideographic-radical value)
668 (insert (format "%s%s\t%S" separator name value))
669 (setq separator line-breaking)))
673 (defun char-db-decode-isolated-char (ccs code-point)
676 (cond ((eq ccs 'arabic-iso8859-6)
677 (decode-char ccs code-point))
679 ;; (decode-builtin-char '==gt code-point))
680 ((and (memq ccs '(=gt-pj-1
691 (setq ret (decode-char ccs code-point))
692 (setq ret (encode-char ret '=gt 'defined-only)))
693 (decode-builtin-char '=gt ret))
695 (decode-builtin-char ccs code-point))))
697 (or (decode-char ccs code-point)
698 (define-char (list (cons ccs code-point)))))
699 ((and (<= 0 (char-int ret))
700 (<= (char-int ret) #x1F))
701 (decode-char '=ucs (+ #x2400 (char-int ret))))
702 ((= (char-int ret) #x7F)
706 (defvar char-db-convert-obsolete-format t)
708 (defun char-db-insert-ccs-feature (name value line-breaking)
714 ((memq name '(=>iwds-1
717 =shinjigen@1ed ==shinjigen@1ed
718 =shinjigen@rev ==shinjigen@rev
719 =shinjigen/+p@rev ==shinjigen/+p@rev
720 ===daikanwa/ho ==daikanwa/ho
721 =daikanwa/ho =>>daikanwa/ho =>daikanwa/ho))
722 "(%-18s . %04d)\t; %c")
723 ((eq name '=shinjigen@1ed/24pr)
724 "(%-18s . %04d)\t; %c")
728 ==daikanwa =daikanwa =>>daikanwa =>daikanwa
729 =daikanwa@rev1 =daikanwa@rev2
730 =daikanwa/+p ==daikanwa/+p ===daikanwa/+p
732 =daikanwa/+2p =>>daikanwa/+2p
737 =adobe-japan1-0 ==adobe-japan1-0 ===adobe-japan1-0
738 =adobe-japan1-1 ==adobe-japan1-1 ===adobe-japan1-1
739 =adobe-japan1-2 ==adobe-japan1-2 ===adobe-japan1-2
740 =adobe-japan1-3 ==adobe-japan1-3 ===adobe-japan1-3
741 =adobe-japan1-4 ==adobe-japan1-4 ===adobe-japan1-4
742 =adobe-japan1-5 ==adobe-japan1-5 ===adobe-japan1-5
743 =adobe-japan1-6 ==adobe-japan1-6 ===adobe-japan1-6
744 =>>adobe-japan1-0 =+>adobe-japan1-0
745 =>>adobe-japan1-1 =+>adobe-japan1-1
746 =>>adobe-japan1-2 =+>adobe-japan1-2
747 =>>adobe-japan1-3 =+>adobe-japan1-3
748 =>>adobe-japan1-4 =+>adobe-japan1-4
749 =>>adobe-japan1-5 =+>adobe-japan1-5
750 =>>adobe-japan1-6 =+>adobe-japan1-6
751 =>cbeta =cbeta =>>cbeta ==cbeta ===cbeta
752 =zinbun-oracle =>zinbun-oracle
753 =daijiten ==daijiten ===daijiten ==>daijiten
754 ===hng-jou ===hng-keg ===hng-dng ===hng-mam
755 ===hng-drt ===hng-kgk ===hng-myz ===hng-kda
756 ===hng-khi ===hng-khm ===hng-fhs ===hng-hok
757 ===hng-kyd ===hng-sok
758 ===hng-yhk ===hng-kak ===hng-kar ===hng-kae
759 ===hng-sys ===hng-tsu ===hng-tzj
760 ===hng-hos ===hng-kkh ===hng-nak ===hng-jhk
761 ===hng-hod ===hng-gok ===hng-ink ===hng-nto
762 ===hng-nkm ===hng-k24 ===hng-ini ===hng-nkk
763 ===hng-kcc ===hng-kcj ===hng-kbk ===hng-sik
764 ===hng-skk ===hng-kyu ===hng-ksk ===hng-wan
765 ===hng-okd ===hng-wad ===hng-kmi
766 ===hng-zkd ===hng-doh ===hng-jyu ===hng-tzs
767 ===hng-sai ===hng-kad ===hng-kss
768 ===hng-kyo ===hng-ykk ===hng-saa
769 ===hng-sab ===hng-wks ===hng-wke ===hng-smk
770 ===hng-sgs ===hng-sts
771 =shuowen-jiguge ===shuowen-jiguge4 ===shuowen-jiguge5))
772 ;; (string-match "^=adobe-" (symbol-name name))
774 "(%-18s . %05d)\t; %c")
775 ((memq name '(=hanyo-denshi/ks
776 ==hanyo-denshi/ks ===hanyo-denshi/ks
779 =mj ==mj ===mj =>>mj =>mj
781 "(%-18s . %06d)\t; %c")
782 ((memq name '(=hanyo-denshi/tk ==hanyo-denshi/tk))
783 "(%-18s . %08d)\t; %c")
784 ((>= (charset-dimension name) 2)
785 "(%-18s . #x%04X)\t; %c")
787 "(%-18s . #x%02X)\t; %c"))
789 (if (= (charset-iso-graphic-plane name) 1)
791 (cond ((= (charset-dimension name) 1)
793 ((= (charset-dimension name) 2)
795 ((= (charset-dimension name) 3)
799 (char-db-decode-isolated-char name value)))
800 (if (and (= (charset-chars name) 94)
801 (= (charset-dimension name) 2))
802 (insert (format " [%02d-%02d]"
803 (- (lsh value -8) 32)
804 (- (logand value 255) 32))))
807 (insert (format "(%-18s . %s)" name value))
809 (insert line-breaking))
811 (defun char-db-insert-relation-feature (char name value line-breaking
813 (insert (format "(%-18s%s " name line-breaking))
814 (let ((lbs (concat "\n" (make-string (current-column) ?\ )))
815 separator cell sources required-features
818 (setq cell (car value))
820 (setq cell (decode-char '=ucs cell)))
822 ((eq name '->subsumptive)
823 (when (or (not (some (lambda (atr)
824 (get-char-attribute cell atr))
825 char-db-ignored-attributes))
827 (encode-char cell ccs 'defined-only))
831 (let ((char-db-ignored-attributes
833 char-db-ignored-attributes)))
834 (insert-char-attributes cell readable nil nil 'for-sub-node))
835 (setq separator lbs))
840 char (intern (format "%s*sources" name))))
841 (setq required-features nil)
842 (dolist (source sources)
846 shinjigen shinjigen@1ed shinjigen@rev))
847 (setq required-features
848 (union required-features
860 =shinjigen/+p@rev))))
862 (setq required-features
863 (union required-features
868 ((find-charset (setq ret (intern (format "=%s" source))))
869 (setq required-features
870 (cons ret required-features)))
871 (t (setq required-features
872 (cons source required-features)))))
873 (cond ((string-match "@JP" (symbol-name name))
874 (setq required-features
875 (union required-features
883 ((string-match "@CN" (symbol-name name))
884 (setq required-features
885 (union required-features
892 (insert (format "%S" cell))
893 (char-db-insert-char-spec cell readable
896 (setq separator lbs))
900 (if (consp (car cell))
901 (char-db-insert-char-spec cell readable)
902 (char-db-insert-char-reference cell readable))
903 (setq separator lbs))
907 (insert (prin1-to-string cell))
908 (setq separator " ")))
909 (setq value (cdr value)))
911 (insert line-breaking)))
913 (defun insert-char-attributes (char &optional readable attributes column
916 (setq column (current-column)))
917 (let (name value ; has-long-ccs-name
921 (concat "\n" (make-string (1+ column) ?\ )))
922 lbs cell separator ret
924 dest-ccss ; sources required-features
929 (if (consp attributes)
931 (dolist (name attributes)
932 (unless (memq name char-db-ignored-attributes)
933 (if (find-charset name)
937 (dolist (name (char-attribute-list))
938 (unless (memq name char-db-ignored-attributes)
939 (if (find-charset name)
943 #'char-attribute-name<)))
945 (when (memq '<-subsumptive attributes)
946 (when (or readable (not for-sub-node))
947 (when (setq value (get-char-attribute char '<-subsumptive))
948 (char-db-insert-relation-feature char '<-subsumptive value
951 (setq attributes (delq '<-subsumptive attributes)))
952 (when (and (memq '<-denotational attributes)
953 (setq value (get-char-attribute char '<-denotational)))
954 (char-db-insert-relation-feature char '<-denotational value
957 (setq attributes (delq '<-denotational attributes)))
958 (when (and (memq '<-denotational@component attributes)
959 (setq value (get-char-attribute char '<-denotational@component)))
960 (char-db-insert-relation-feature char '<-denotational@component value
963 (setq attributes (delq '<-denotational@component attributes)))
964 (when (and (memq '<-denotational@usage attributes)
965 (setq value (get-char-attribute char '<-denotational@usage)))
966 (char-db-insert-relation-feature char '<-denotational@usage value
969 (setq attributes (delq '<-denotational@usage attributes)))
970 (when (and (memq 'name attributes)
971 (setq value (get-char-attribute char 'name)))
973 (if (> (+ (current-column) (length value)) 48)
976 value line-breaking))
977 (setq attributes (delq 'name attributes))
979 (when (and (memq 'name* attributes)
980 (setq value (get-char-attribute char 'name*)))
982 (if (> (+ (current-column) (length value)) 48)
985 value line-breaking))
986 (setq attributes (delq 'name* attributes))
988 (when (and (memq 'script attributes)
989 (setq value (get-char-attribute char 'script)))
990 (insert (format "(script\t\t%s)%s"
991 (mapconcat (function prin1-to-string)
994 (setq attributes (delq 'script attributes))
996 (dolist (name '(=>ucs =>ucs*))
997 (when (and (memq name attributes)
998 (setq value (get-char-attribute char name)))
999 (insert (format "(%-18s . #x%04X)\t; %c%s"
1000 name value (decode-char '=ucs value)
1002 (setq attributes (delq name attributes))))
1003 (dolist (name '(=>ucs@gb =>ucs@big5))
1004 (when (and (memq name attributes)
1005 (setq value (get-char-attribute char name)))
1006 (insert (format "(%-18s . #x%04X)\t; %c%s"
1008 (decode-char (intern
1011 (symbol-name name) 2)))
1014 (setq attributes (delq name attributes))
1016 ;; (dolist (name '(=>daikanwa))
1017 ;; (when (and (memq name attributes)
1018 ;; (setq value (get-char-attribute char name)))
1020 ;; (if (integerp value)
1021 ;; (format "(%-18s . %05d)\t; %c%s"
1022 ;; name value (decode-char '=daikanwa value)
1024 ;; (format "(%-18s %s)\t; %c%s"
1026 ;; (mapconcat (function prin1-to-string)
1028 ;; (char-representative-of-daikanwa char)
1030 ;; (setq attributes (delq name attributes))))
1031 (when (and (memq 'general-category attributes)
1032 (setq value (get-char-attribute char 'general-category)))
1034 "(general-category\t%s) ; %s%s"
1035 (mapconcat (lambda (cell)
1038 (cond ((rassoc value unidata-normative-category-alist)
1039 "Normative Category")
1040 ((rassoc value unidata-informative-category-alist)
1041 "Informative Category")
1043 "Unknown Category"))
1045 (setq attributes (delq 'general-category attributes))
1047 (when (and (memq 'bidi-category attributes)
1048 (setq value (get-char-attribute char 'bidi-category)))
1049 (insert (format "(bidi-category\t. %S)%s"
1052 (setq attributes (delq 'bidi-category attributes))
1054 (unless (or (not (memq 'mirrored attributes))
1055 (eq (setq value (get-char-attribute char 'mirrored 'empty))
1057 (insert (format "(mirrored\t\t. %S)%s"
1060 (setq attributes (delq 'mirrored attributes))
1063 ((and (memq 'decimal-digit-value attributes)
1064 (setq value (get-char-attribute char 'decimal-digit-value)))
1065 (insert (format "(decimal-digit-value . %S)%s"
1068 (setq attributes (delq 'decimal-digit-value attributes))
1069 (when (and (memq 'digit-value attributes)
1070 (setq value (get-char-attribute char 'digit-value)))
1071 (insert (format "(digit-value\t . %S)%s"
1074 (setq attributes (delq 'digit-value attributes))
1076 (when (and (memq 'numeric-value attributes)
1077 (setq value (get-char-attribute char 'numeric-value)))
1078 (insert (format "(numeric-value\t . %S)%s"
1081 (setq attributes (delq 'numeric-value attributes))
1085 (when (and (memq 'digit-value attributes)
1086 (setq value (get-char-attribute char 'digit-value)))
1087 (insert (format "(digit-value\t. %S)%s"
1090 (setq attributes (delq 'digit-value attributes))
1092 (when (and (memq 'numeric-value attributes)
1093 (setq value (get-char-attribute char 'numeric-value)))
1094 (insert (format "(numeric-value\t. %S)%s"
1097 (setq attributes (delq 'numeric-value attributes))
1099 (when (and (memq 'iso-10646-comment attributes)
1100 (setq value (get-char-attribute char 'iso-10646-comment)))
1101 (insert (format "(iso-10646-comment\t. %S)%s"
1104 (setq attributes (delq 'iso-10646-comment attributes))
1106 (when (and (memq 'morohashi-daikanwa attributes)
1107 (setq value (get-char-attribute char 'morohashi-daikanwa)))
1108 (insert (format "(morohashi-daikanwa\t%s)%s"
1109 (mapconcat (function prin1-to-string) value " ")
1111 (setq attributes (delq 'morohashi-daikanwa attributes))
1115 (when (and (memq 'ideographic-radical attributes)
1116 (setq value (get-char-attribute char 'ideographic-radical)))
1117 (setq radical value)
1118 (insert (format "(ideographic-radical . %S)\t; %c%s"
1120 (ideographic-radical radical)
1122 (setq attributes (delq 'ideographic-radical attributes))
1124 (when (and (memq 'shuowen-radical attributes)
1125 (setq value (get-char-attribute char 'shuowen-radical)))
1126 (insert (format "(shuowen-radical\t. %S)\t; %c%s"
1128 (shuowen-radical value)
1130 (setq attributes (delq 'shuowen-radical attributes))
1135 char-db-feature-domains
1137 (dolist (feature (char-attribute-list))
1138 (setq feature (symbol-name feature))
1140 "\\(radical\\|strokes\\)@\\([^@*]+\\)\\(\\*\\|$\\)"
1142 (setq domain (intern (match-string 2 feature)))
1143 (unless (memq domain dest)
1144 (setq dest (cons domain dest)))))
1145 (sort dest #'string<))))
1146 (setq key (intern (format "%s@%s" 'ideographic-radical domain)))
1147 (when (and (memq key attributes)
1148 (setq value (get-char-attribute char key)))
1149 (setq radical value)
1150 (insert (format "(%s . %S)\t; %c%s"
1153 (ideographic-radical radical)
1155 (setq attributes (delq key attributes))
1157 (setq key (intern (format "%s@%s" 'ideographic-strokes domain)))
1158 (when (and (memq key attributes)
1159 (setq value (get-char-attribute char key)))
1160 (setq strokes value)
1161 (insert (format "(%s . %S)%s"
1165 (setq attributes (delq key attributes))
1167 (setq key (intern (format "%s@%s" 'total-strokes domain)))
1168 (when (and (memq key attributes)
1169 (setq value (get-char-attribute char key)))
1170 (insert (format "(%s . %S)%s"
1174 (setq attributes (delq key attributes))
1176 (dolist (feature '(ideographic-radical
1179 (setq key (intern (format "%s@%s*sources" feature domain)))
1180 (when (and (memq key attributes)
1181 (setq value (get-char-attribute char key)))
1182 (insert (format "(%s%s" key line-breaking))
1183 (dolist (cell value)
1184 (insert (format " %s" cell)))
1186 (insert line-breaking)
1187 (setq attributes (delq key attributes))
1190 (when (and (memq 'ideographic-strokes attributes)
1191 (setq value (get-char-attribute char 'ideographic-strokes)))
1192 (setq strokes value)
1193 (insert (format "(ideographic-strokes . %S)%s"
1196 (setq attributes (delq 'ideographic-strokes attributes))
1198 (when (and (memq 'kangxi-radical attributes)
1199 (setq value (get-char-attribute char 'kangxi-radical)))
1200 (unless (eq value radical)
1201 (insert (format "(kangxi-radical\t . %S)\t; %c%s"
1203 (ideographic-radical value)
1206 (setq radical value)))
1207 (setq attributes (delq 'kangxi-radical attributes))
1209 (when (and (memq 'kangxi-strokes attributes)
1210 (setq value (get-char-attribute char 'kangxi-strokes)))
1211 (unless (eq value strokes)
1212 (insert (format "(kangxi-strokes\t . %S)%s"
1216 (setq strokes value)))
1217 (setq attributes (delq 'kangxi-strokes attributes))
1219 ;; (when (and (memq 'japanese-radical attributes)
1220 ;; (setq value (get-char-attribute char 'japanese-radical)))
1221 ;; (unless (eq value radical)
1222 ;; (insert (format "(japanese-radical\t . %S)\t; %c%s"
1224 ;; (ideographic-radical value)
1227 ;; (setq radical value)))
1228 ;; (setq attributes (delq 'japanese-radical attributes))
1230 (when (and (memq 'japanese-strokes attributes)
1231 (setq value (get-char-attribute char 'japanese-strokes)))
1232 (unless (eq value strokes)
1233 (insert (format "(japanese-strokes\t . %S)%s"
1237 (setq strokes value)))
1238 (setq attributes (delq 'japanese-strokes attributes))
1240 (when (and (memq 'cns-radical attributes)
1241 (setq value (get-char-attribute char 'cns-radical)))
1242 (insert (format "(cns-radical\t . %S)\t; %c%s"
1244 (ideographic-radical value)
1246 (setq attributes (delq 'cns-radical attributes))
1248 (when (and (memq 'cns-strokes attributes)
1249 (setq value (get-char-attribute char 'cns-strokes)))
1250 (unless (eq value strokes)
1251 (insert (format "(cns-strokes\t . %S)%s"
1255 (setq strokes value)))
1256 (setq attributes (delq 'cns-strokes attributes))
1258 ;; (when (and (memq 'ideographic- attributes)
1259 ;; (setq value (get-char-attribute char 'ideographic-)))
1260 ;; (insert "(ideographic- ")
1261 ;; (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1263 ;; (while (consp value)
1264 ;; (setq cell (car value))
1265 ;; (if (integerp cell)
1266 ;; (setq cell (decode-char '=ucs cell)))
1267 ;; (cond ((characterp cell)
1271 ;; (insert (format "%S" cell))
1272 ;; (char-db-insert-char-spec cell readable))
1273 ;; (setq separator lbs))
1277 ;; (if (consp (car cell))
1278 ;; (char-db-insert-char-spec cell readable)
1279 ;; (char-db-insert-char-reference cell readable))
1280 ;; (setq separator lbs))
1283 ;; (insert separator))
1284 ;; (insert (prin1-to-string cell))
1285 ;; (setq separator " ")))
1286 ;; (setq value (cdr value)))
1288 ;; (insert line-breaking)
1289 ;; (setq attributes (delq 'ideographic- attributes)))
1290 (when (and (memq 'total-strokes attributes)
1291 (setq value (get-char-attribute char 'total-strokes)))
1292 (insert (format "(total-strokes . %S)%s"
1295 (setq attributes (delq 'total-strokes attributes))
1297 ;; (when (and (memq '->ideograph attributes)
1298 ;; (setq value (get-char-attribute char '->ideograph)))
1299 ;; (insert (format "(->ideograph\t%s)%s"
1300 ;; (mapconcat (lambda (code)
1301 ;; (cond ((symbolp code)
1302 ;; (symbol-name code))
1304 ;; (format "#x%04X" code))
1307 ;; line-breaking code))))
1310 ;; (setq attributes (delq '->ideograph attributes))
1312 ;; (when (and (memq '->decomposition attributes)
1313 ;; (setq value (get-char-attribute char '->decomposition)))
1314 ;; (insert (format "(->decomposition\t%s)%s"
1315 ;; (mapconcat (lambda (code)
1316 ;; (cond ((symbolp code)
1317 ;; (symbol-name code))
1318 ;; ((characterp code)
1320 ;; (format "%S" code)
1325 ;; (format "#x%04X" code))
1327 ;; (format "%s%S" line-breaking code))))
1330 ;; (setq attributes (delq '->decomposition attributes))
1332 (if (equal (get-char-attribute char '->titlecase)
1333 (get-char-attribute char '->uppercase))
1334 (setq attributes (delq '->titlecase attributes)))
1335 (when (and (memq '->mojikyo attributes)
1336 (setq value (get-char-attribute char '->mojikyo)))
1337 (insert (format "(->mojikyo\t\t. %06d)\t; %c%s"
1338 value (decode-char 'mojikyo value)
1340 (setq attributes (delq '->mojikyo attributes))
1343 (dolist (ignored '(composition
1344 ->denotational <-subsumptive ->ucs-unified
1345 ;; ->ideographic-component-forms
1347 (setq attributes (delq ignored attributes))))
1349 (setq name (car attributes))
1350 (unless (eq (setq value (get-char-attribute char name 'value-is-empty))
1352 (cond ((setq ret (find-charset name))
1353 (setq name (charset-name ret))
1354 (when (not (memq name dest-ccss))
1355 (setq dest-ccss (cons name dest-ccss))
1356 (char-db-insert-ccs-feature name value line-breaking))
1358 ((string-match "^=>ucs@" (symbol-name name))
1359 (insert (format "(%-18s . #x%04X)\t; %c%s"
1360 name value (decode-char '=ucs value)
1363 ((eq name 'jisx0208-1978/4X)
1364 (insert (format "(%-18s . #x%04X)%s"
1370 (not (eq name '->subsumptive))
1371 (not (eq name '->uppercase))
1372 (not (eq name '->lowercase))
1373 (not (eq name '->titlecase))
1374 (not (eq name '->canonical))
1375 (not (eq name '->Bopomofo))
1376 (not (eq name '->mistakable))
1377 (not (eq name '->ideographic-variants))
1378 (null (get-char-attribute
1379 char (intern (format "%s*sources" name))))
1380 (not (string-match "\\*sources$" (symbol-name name)))
1381 (null (get-char-attribute
1382 char (intern (format "%s*note" name))))
1383 (not (string-match "\\*note$" (symbol-name name)))
1384 (or (eq name '<-identical)
1385 (eq name '<-uppercase)
1386 (eq name '<-lowercase)
1387 (eq name '<-titlecase)
1388 (eq name '<-canonical)
1389 (eq name '<-ideographic-variants)
1390 ;; (eq name '<-synonyms)
1391 (string-match "^<-synonyms" (symbol-name name))
1392 (eq name '<-mistakable)
1393 (when (string-match "^->" (symbol-name name))
1395 ((string-match "^->fullwidth" (symbol-name name))
1396 (not (and (consp value)
1397 (characterp (car value))
1399 (car value) '=ucs 'defined-only)))
1404 ((or (eq name 'ideographic-structure)
1405 (eq name 'ideographic-structure@apparent)
1406 (eq name 'ideographic-combination)
1407 ;; (eq name 'ideographic-)
1408 (eq name '=decomposition)
1409 (char-feature-base-name= '=decomposition name)
1410 (char-feature-base-name= '=>decomposition name)
1411 ;; (string-match "^=>*decomposition\\(@[^*]+\\)?$"
1412 ;; (symbol-name name))
1413 (string-match "^\\(->\\|<-\\)[^*]*$" (symbol-name name))
1414 (string-match "^\\(->\\|<-\\)[^*]*\\*sources$"
1417 (char-db-insert-relation-feature char name value
1420 ;; ((memq name '(ideograph=
1421 ;; original-ideograph-of
1422 ;; ancient-ideograph-of
1423 ;; vulgar-ideograph-of
1424 ;; wrong-ideograph-of
1425 ;; ;; simplified-ideograph-of
1426 ;; ideographic-variants
1427 ;; ;; ideographic-different-form-of
1429 ;; (insert (format "(%-18s%s " name line-breaking))
1430 ;; (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1432 ;; (while (consp value)
1433 ;; (setq cell (car value))
1434 ;; (if (and (consp cell)
1435 ;; (consp (car cell)))
1439 ;; (char-db-insert-alist cell readable)
1440 ;; (setq separator lbs))
1442 ;; (insert separator))
1443 ;; (insert (prin1-to-string cell))
1444 ;; (setq separator " "))
1445 ;; (setq value (cdr value)))
1447 ;; (insert line-breaking))
1449 (insert (format "(%-18s " name))
1450 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1452 (while (consp value)
1453 (setq cell (car value))
1454 (if (and (consp cell)
1456 (setq ret (condition-case nil
1464 (setq key (car (car rest)))
1465 (if (find-charset key)
1466 (setq cal (cons key cal))
1467 (setq al (cons key al)))
1468 (setq rest (cdr rest)))
1471 (insert-char-attributes ret
1475 (setq separator lbs))
1476 (setq ret (prin1-to-string cell))
1478 (if (< (+ (current-column)
1485 (setq separator " "))
1486 (setq value (cdr value)))
1488 (insert line-breaking))
1490 (insert (format "(%-18s" name))
1491 (setq ret (prin1-to-string value))
1492 (unless (< (+ (current-column)
1496 (insert line-breaking))
1497 (insert " . " ret ")" line-breaking)
1498 ;; (insert (format "(%-18s . %S)%s"
1503 (setq attributes (cdr attributes)))
1506 (defun insert-char-data (char &optional readable
1509 (narrow-to-region (point)(point))
1510 (insert "(define-char
1512 (insert-char-attributes char readable attributes)
1514 (goto-char (point-min))
1515 (while (re-search-forward "[ \t]+$" nil t)
1518 (goto-char (point-min))
1519 (while (re-search-forward "[ \t][ \t][ \t]*" nil t)
1520 (let ((column (current-column))
1521 (indent-tabs-mode t))
1522 (delete-region (match-beginning 0) (point))
1523 (indent-to column)))
1524 (goto-char (point-max))
1525 ;; (tabify (point-min)(point-max))
1528 (defun insert-char-data-with-variant (char &optional printable
1530 script excluded-script)
1531 (insert-char-data char printable)
1532 (let ((variants (char-variants char))
1535 (setq variants (sort variants #'<))
1536 (setq rest variants)
1537 (setq variants (cons char variants))
1539 (setq variant (car rest))
1540 (unless (get-char-attribute variant '<-subsumptive)
1541 (if (and (or (null script)
1542 (null (setq vs (get-char-attribute variant 'script)))
1544 (or (null excluded-script)
1545 (null (setq vs (get-char-attribute variant 'script)))
1546 (not (memq excluded-script vs))))
1547 (unless (and no-ucs-unified (get-char-attribute variant '=ucs))
1548 (insert-char-data variant printable)
1549 (if (setq ret (char-variants variant))
1551 (or (memq (car ret) variants)
1552 ;; (get-char-attribute (car ret) '<-subsumptive)
1553 (setq rest (nconc rest (list (car ret)))))
1554 (setq ret (cdr ret)))))))
1555 (setq rest (cdr rest)))))
1557 (defun insert-char-range-data (min max &optional script excluded-script)
1560 (while (<= code max)
1561 (setq char (decode-char '=ucs code))
1562 (if (encode-char char '=ucs 'defined-only)
1563 (insert-char-data-with-variant char nil 'no-ucs-unified
1564 script excluded-script))
1565 (setq code (1+ code)))))
1567 (defun write-char-range-data-to-file (min max file
1568 &optional script excluded-script)
1569 (let ((coding-system-for-write char-db-file-coding-system))
1571 (insert (format ";; -*- coding: %s -*-\n"
1572 char-db-file-coding-system))
1573 (insert-char-range-data min max script excluded-script)
1574 (write-region (point-min)(point-max) file))))
1576 (defvar what-character-original-window-configuration)
1579 (defun what-char-definition (char)
1580 (interactive (list (char-after)))
1581 (let ((buf (get-buffer-create "*Character Description*"))
1582 (the-buf (current-buffer))
1583 (win-conf (current-window-configuration)))
1585 (make-local-variable 'what-character-original-window-configuration)
1586 (setq what-character-original-window-configuration win-conf)
1587 (setq buffer-read-only nil)
1591 (insert-char-data-with-variant char 'printable)
1592 (unless (char-attribute-alist char)
1593 (insert (format ";; = %c\n"
1594 (let* ((rest (split-char char))
1598 (setq code (logior (lsh code 8)
1600 (decode-char ccs code)))))
1601 ;; (char-db-update-comment)
1602 (set-buffer-modified-p nil)
1603 (view-mode the-buf (lambda (buf)
1604 (set-window-configuration
1605 what-character-original-window-configuration)
1607 (goto-char (point-min)))
1609 (set-window-configuration
1610 what-character-original-window-configuration)
1611 (signal (car err) (cdr err)))))))
1617 (provide 'char-db-util)
1619 ;;; char-db-util.el ends here