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-003
388 =>ucs@iwds-1/normalized
389 =>ucs-itaiji-001@iwds-1
390 =>ucs-itaiji-002@iwds-1
399 ;;; @ char-db formatters
402 (defun char-db-make-char-spec (char)
404 (cond ((characterp char)
405 (cond ((and (setq ret (encode-char char '=ucs 'defined-only))
406 (not (and (<= #xE000 ret)(<= ret #xF8FF))))
407 (setq char-spec (list (cons '=ucs ret)))
408 (cond ((setq ret (get-char-attribute char 'name))
409 (setq char-spec (cons (cons 'name ret) char-spec))
411 ((setq ret (get-char-attribute char 'name*))
412 (setq char-spec (cons (cons 'name* ret) char-spec))
415 ((encode-char char '=mj 'defined-only)
417 (dolist (ccs (charset-list))
418 (if (and (or (eq ccs '=mj)
419 ;; (eq (charset-property ccs 'iso-ir) 177)
420 (string-match "=ucs@" (symbol-name ccs))
422 (setq ccs (charset-name ccs))
423 (null (assq ccs char-spec))
424 (setq ret (encode-char char ccs 'defined-only)))
425 (setq char-spec (cons (cons ccs ret) char-spec))))
427 ((encode-char char '==mj 'defined-only)
429 (dolist (ccs (charset-list))
430 (if (and (or (eq ccs '==mj)
431 ;; (eq (charset-property ccs 'iso-ir) 177)
432 (string-match "=ucs@" (symbol-name ccs))
434 (setq ccs (charset-name ccs))
435 (null (assq ccs char-spec))
436 (setq ret (encode-char char ccs 'defined-only)))
437 (setq char-spec (cons (cons ccs ret) char-spec))))
439 ((encode-char char '=adobe-japan1 'defined-only)
441 (dolist (ccs (charset-list))
442 (if (and (or (memq ccs
451 ;; (eq (charset-property ccs 'iso-ir) 177)
452 (string-match "=ucs@" (symbol-name ccs))
454 (setq ccs (charset-name ccs))
455 (null (assq ccs char-spec))
456 (setq ret (encode-char char ccs 'defined-only)))
457 (setq char-spec (cons (cons ccs ret) char-spec))))
459 ((encode-char char '==adobe-japan1 'defined-only)
461 (dolist (ccs (charset-list))
462 (if (and (or (memq ccs
471 ;; (eq (charset-property ccs 'iso-ir) 177)
472 (string-match "=ucs@" (symbol-name ccs))
474 (setq ccs (charset-name ccs))
475 (null (assq ccs char-spec))
476 (setq ret (encode-char char ccs 'defined-only)))
477 (setq char-spec (cons (cons ccs ret) char-spec))))
481 (let ((rest char-db-coded-charset-priority-list)
484 (setq ccs (charset-name
485 (find-charset (car rest))))
487 (encode-char char ccs
489 (throw 'tag (cons ccs ret)))
490 (setq rest (cdr rest))))))
491 (setq char-spec (list ret))
492 (dolist (ccs (delq (car ret) (charset-list)))
493 (if (and (or (charset-iso-final-char ccs)
500 (and (eq (charset-property ccs 'iso-ir) 177)
501 (not (eq (charset-name ccs) '=ucs@big5)))
502 ;; (string-match "=ucs@" (symbol-name ccs))
504 (setq ccs (charset-name ccs))
505 (null (assq ccs char-spec))
506 (setq ret (encode-char char ccs 'defined-only)))
507 (setq char-spec (cons (cons ccs ret) char-spec))))
509 (setq char-spec (split-char char)))
510 (cond ((setq ret (get-char-attribute char 'name))
511 (setq char-spec (cons (cons 'name ret) char-spec))
513 ((setq ret (get-char-attribute char 'name*))
514 (setq char-spec (cons (cons 'name* ret) char-spec))
517 ((setq ret (get-char-attribute
518 char 'ideographic-combination))
520 (cons (cons 'ideographic-combination ret)
527 (defun char-db-insert-char-spec (char &optional readable column
530 (setq column (current-column)))
531 (let (char-spec temp-char)
532 (setq char-spec (char-db-make-char-spec char))
533 (unless (or (characterp char) ; char
535 (setq char (find-char char-spec))
537 ;; define temporary character
538 ;; Current implementation is dirty.
539 (setq temp-char (define-char (cons '(ideograph-daikanwa . 0)
541 (remove-char-attribute temp-char 'ideograph-daikanwa)
542 (setq char temp-char))
543 (insert-char-attributes char
545 (union (mapcar #'car char-spec)
549 ;; undefine temporary character
550 ;; Current implementation is dirty.
551 (setq char-spec (char-attribute-alist temp-char))
553 (remove-char-attribute temp-char (car (car char-spec)))
554 (setq char-spec (cdr char-spec))))))
556 (defun char-db-insert-alist (alist &optional readable column)
558 (setq column (current-column)))
560 (concat "\n" (make-string (1+ column) ?\ )))
564 lbs cell rest separator)
567 (setq name (car (car alist))
568 value (cdr (car alist)))
569 (cond ((eq name 'char)
571 (if (setq ret (condition-case nil
579 (setq key (car (car value)))
580 ;; (if (find-charset key)
581 ;; (setq cal (cons key cal))
582 (setq al (cons key al))
584 (setq value (cdr value)))
585 (insert-char-attributes ret
589 (insert (prin1-to-string value)))
591 (insert line-breaking))
593 (insert (format "(%-18s " name))
594 (setq lbs (concat "\n" (make-string (current-column) ?\ )))
596 (setq cell (car value))
597 (if (and (consp cell)
599 (setq ret (condition-case nil
609 (setq key (car (car rest)))
610 ;; (if (find-charset key)
611 ;; (setq cal (cons key cal))
612 (setq al (cons key al))
614 (setq rest (cdr rest)))
617 (insert-char-attributes ret
621 (setq separator lbs))
624 (insert (prin1-to-string cell))
625 (setq separator " "))
626 (setq value (cdr value)))
628 (insert line-breaking))
630 (insert (format "(%-18s . %S)%s"
633 (setq alist (cdr alist))))
636 (defun char-db-insert-char-reference (plist &optional readable column)
638 (setq column (current-column)))
640 (concat "\n" (make-string (1+ column) ?\ )))
645 (setq name (pop plist))
646 (setq value (pop plist))
647 (cond ((eq name :char)
650 (cond ((numberp value)
651 (setq value (decode-char '=ucs value)))
653 ;; (setq value (or (find-char value)
656 (char-db-insert-char-spec value readable)
657 (insert line-breaking)
660 (insert (format "%s%s\t%d ; %c%s"
663 (ideographic-radical value)
667 (insert (format "%s%s\t%S" separator name value))
668 (setq separator line-breaking)))
672 (defun char-db-decode-isolated-char (ccs code-point)
675 (cond ((eq ccs 'arabic-iso8859-6)
676 (decode-char ccs code-point))
678 ;; (decode-builtin-char '==gt code-point))
679 ((and (memq ccs '(=gt-pj-1
690 (setq ret (decode-char ccs code-point))
691 (setq ret (encode-char ret '=gt 'defined-only)))
692 (decode-builtin-char '=gt ret))
694 (decode-builtin-char ccs code-point))))
696 (or (decode-char ccs code-point)
697 (define-char (list (cons ccs code-point)))))
698 ((and (<= 0 (char-int ret))
699 (<= (char-int ret) #x1F))
700 (decode-char '=ucs (+ #x2400 (char-int ret))))
701 ((= (char-int ret) #x7F)
705 (defvar char-db-convert-obsolete-format t)
707 (defun char-db-insert-ccs-feature (name value line-breaking)
713 ((memq name '(=>iwds-1
716 =shinjigen@1ed ==shinjigen@1ed
717 =shinjigen@rev ==shinjigen@rev
718 =shinjigen/+p@rev ==shinjigen/+p@rev
719 ===daikanwa/ho ==daikanwa/ho
720 =daikanwa/ho =>>daikanwa/ho =>daikanwa/ho))
721 "(%-18s . %04d)\t; %c")
722 ((eq name '=shinjigen@1ed/24pr)
723 "(%-18s . %04d)\t; %c")
727 ==daikanwa =daikanwa =>>daikanwa =>daikanwa
728 =daikanwa@rev1 =daikanwa@rev2
729 =daikanwa/+p ==daikanwa/+p ===daikanwa/+p
731 =daikanwa/+2p =>>daikanwa/+2p
736 =adobe-japan1-0 ==adobe-japan1-0 ===adobe-japan1-0
737 =adobe-japan1-1 ==adobe-japan1-1 ===adobe-japan1-1
738 =adobe-japan1-2 ==adobe-japan1-2 ===adobe-japan1-2
739 =adobe-japan1-3 ==adobe-japan1-3 ===adobe-japan1-3
740 =adobe-japan1-4 ==adobe-japan1-4 ===adobe-japan1-4
741 =adobe-japan1-5 ==adobe-japan1-5 ===adobe-japan1-5
742 =adobe-japan1-6 ==adobe-japan1-6 ===adobe-japan1-6
743 =>>adobe-japan1-0 =+>adobe-japan1-0
744 =>>adobe-japan1-1 =+>adobe-japan1-1
745 =>>adobe-japan1-2 =+>adobe-japan1-2
746 =>>adobe-japan1-3 =+>adobe-japan1-3
747 =>>adobe-japan1-4 =+>adobe-japan1-4
748 =>>adobe-japan1-5 =+>adobe-japan1-5
749 =>>adobe-japan1-6 =+>adobe-japan1-6
750 =>cbeta =cbeta =>>cbeta ==cbeta ===cbeta
751 =zinbun-oracle =>zinbun-oracle
752 =daijiten ==daijiten ===daijiten ==>daijiten
753 ===hng-jou ===hng-keg ===hng-dng ===hng-mam
754 ===hng-drt ===hng-kgk ===hng-myz ===hng-kda
755 ===hng-khi ===hng-khm ===hng-fhs ===hng-hok
756 ===hng-kyd ===hng-sok
757 ===hng-yhk ===hng-kak ===hng-kar ===hng-kae
758 ===hng-sys ===hng-tsu ===hng-tzj
759 ===hng-hos ===hng-kkh ===hng-nak ===hng-jhk
760 ===hng-hod ===hng-gok ===hng-ink ===hng-nto
761 ===hng-nkm ===hng-k24 ===hng-ini ===hng-nkk
762 ===hng-kcc ===hng-kcj ===hng-kbk ===hng-sik
763 ===hng-skk ===hng-kyu ===hng-ksk ===hng-wan
764 ===hng-okd ===hng-wad ===hng-kmi
765 ===hng-zkd ===hng-doh ===hng-jyu ===hng-tzs
766 ===hng-sai ===hng-kad ===hng-kss
767 ===hng-kyo ===hng-ykk ===hng-saa
768 ===hng-sab ===hng-wks ===hng-wke ===hng-smk
769 ===hng-sgs ===hng-sts
770 =shuowen-jiguge ===shuowen-jiguge4 ===shuowen-jiguge5))
771 ;; (string-match "^=adobe-" (symbol-name name))
773 "(%-18s . %05d)\t; %c")
774 ((memq name '(=hanyo-denshi/ks
775 ==hanyo-denshi/ks ===hanyo-denshi/ks
778 =mj ==mj ===mj =>>mj =>mj
780 "(%-18s . %06d)\t; %c")
781 ((memq name '(=hanyo-denshi/tk ==hanyo-denshi/tk))
782 "(%-18s . %08d)\t; %c")
783 ((>= (charset-dimension name) 2)
784 "(%-18s . #x%04X)\t; %c")
786 "(%-18s . #x%02X)\t; %c"))
788 (if (= (charset-iso-graphic-plane name) 1)
790 (cond ((= (charset-dimension name) 1)
792 ((= (charset-dimension name) 2)
794 ((= (charset-dimension name) 3)
798 (char-db-decode-isolated-char name value)))
799 (if (and (= (charset-chars name) 94)
800 (= (charset-dimension name) 2))
801 (insert (format " [%02d-%02d]"
802 (- (lsh value -8) 32)
803 (- (logand value 255) 32))))
806 (insert (format "(%-18s . %s)" name value))
808 (insert line-breaking))
810 (defun char-db-insert-relation-feature (char name value line-breaking
812 (insert (format "(%-18s%s " name line-breaking))
813 (let ((lbs (concat "\n" (make-string (current-column) ?\ )))
814 separator cell sources required-features
817 (setq cell (car value))
819 (setq cell (decode-char '=ucs cell)))
821 ((eq name '->subsumptive)
822 (when (or (not (some (lambda (atr)
823 (get-char-attribute cell atr))
824 char-db-ignored-attributes))
826 (encode-char cell ccs 'defined-only))
830 (let ((char-db-ignored-attributes
832 char-db-ignored-attributes)))
833 (insert-char-attributes cell readable nil nil 'for-sub-node))
834 (setq separator lbs))
839 char (intern (format "%s*sources" name))))
840 (setq required-features nil)
841 (dolist (source sources)
845 shinjigen shinjigen@1ed shinjigen@rev))
846 (setq required-features
847 (union required-features
859 =shinjigen/+p@rev))))
861 (setq required-features
862 (union required-features
867 ((find-charset (setq ret (intern (format "=%s" source))))
868 (setq required-features
869 (cons ret required-features)))
870 (t (setq required-features
871 (cons source required-features)))))
872 (cond ((string-match "@JP" (symbol-name name))
873 (setq required-features
874 (union required-features
882 ((string-match "@CN" (symbol-name name))
883 (setq required-features
884 (union required-features
891 (insert (format "%S" cell))
892 (char-db-insert-char-spec cell readable
895 (setq separator lbs))
899 (if (consp (car cell))
900 (char-db-insert-char-spec cell readable)
901 (char-db-insert-char-reference cell readable))
902 (setq separator lbs))
906 (insert (prin1-to-string cell))
907 (setq separator " ")))
908 (setq value (cdr value)))
910 (insert line-breaking)))
912 (defun insert-char-attributes (char &optional readable attributes column
915 (setq column (current-column)))
916 (let (name value ; has-long-ccs-name
920 (concat "\n" (make-string (1+ column) ?\ )))
921 lbs cell separator ret
923 dest-ccss ; sources required-features
928 (if (consp attributes)
930 (dolist (name attributes)
931 (unless (memq name char-db-ignored-attributes)
932 (if (find-charset name)
936 (dolist (name (char-attribute-list))
937 (unless (memq name char-db-ignored-attributes)
938 (if (find-charset name)
942 #'char-attribute-name<)))
944 (when (memq '<-subsumptive attributes)
945 (when (or readable (not for-sub-node))
946 (when (setq value (get-char-attribute char '<-subsumptive))
947 (char-db-insert-relation-feature char '<-subsumptive value
950 (setq attributes (delq '<-subsumptive attributes)))
951 (when (and (memq '<-denotational attributes)
952 (setq value (get-char-attribute char '<-denotational)))
953 (char-db-insert-relation-feature char '<-denotational value
956 (setq attributes (delq '<-denotational attributes)))
957 (when (and (memq '<-denotational@component attributes)
958 (setq value (get-char-attribute char '<-denotational@component)))
959 (char-db-insert-relation-feature char '<-denotational@component value
962 (setq attributes (delq '<-denotational@component attributes)))
963 (when (and (memq '<-denotational@usage attributes)
964 (setq value (get-char-attribute char '<-denotational@usage)))
965 (char-db-insert-relation-feature char '<-denotational@usage value
968 (setq attributes (delq '<-denotational@usage attributes)))
969 (when (and (memq 'name attributes)
970 (setq value (get-char-attribute char 'name)))
972 (if (> (+ (current-column) (length value)) 48)
975 value line-breaking))
976 (setq attributes (delq 'name attributes))
978 (when (and (memq 'name* attributes)
979 (setq value (get-char-attribute char 'name*)))
981 (if (> (+ (current-column) (length value)) 48)
984 value line-breaking))
985 (setq attributes (delq 'name* attributes))
987 (when (and (memq 'script attributes)
988 (setq value (get-char-attribute char 'script)))
989 (insert (format "(script\t\t%s)%s"
990 (mapconcat (function prin1-to-string)
993 (setq attributes (delq 'script attributes))
995 (dolist (name '(=>ucs =>ucs*))
996 (when (and (memq name attributes)
997 (setq value (get-char-attribute char name)))
998 (insert (format "(%-18s . #x%04X)\t; %c%s"
999 name value (decode-char '=ucs value)
1001 (setq attributes (delq name attributes))))
1002 (dolist (name '(=>ucs@gb =>ucs@big5))
1003 (when (and (memq name attributes)
1004 (setq value (get-char-attribute char name)))
1005 (insert (format "(%-18s . #x%04X)\t; %c%s"
1007 (decode-char (intern
1010 (symbol-name name) 2)))
1013 (setq attributes (delq name attributes))
1015 ;; (dolist (name '(=>daikanwa))
1016 ;; (when (and (memq name attributes)
1017 ;; (setq value (get-char-attribute char name)))
1019 ;; (if (integerp value)
1020 ;; (format "(%-18s . %05d)\t; %c%s"
1021 ;; name value (decode-char '=daikanwa value)
1023 ;; (format "(%-18s %s)\t; %c%s"
1025 ;; (mapconcat (function prin1-to-string)
1027 ;; (char-representative-of-daikanwa char)
1029 ;; (setq attributes (delq name attributes))))
1030 (when (and (memq 'general-category attributes)
1031 (setq value (get-char-attribute char 'general-category)))
1033 "(general-category\t%s) ; %s%s"
1034 (mapconcat (lambda (cell)
1037 (cond ((rassoc value unidata-normative-category-alist)
1038 "Normative Category")
1039 ((rassoc value unidata-informative-category-alist)
1040 "Informative Category")
1042 "Unknown Category"))
1044 (setq attributes (delq 'general-category attributes))
1046 (when (and (memq 'bidi-category attributes)
1047 (setq value (get-char-attribute char 'bidi-category)))
1048 (insert (format "(bidi-category\t. %S)%s"
1051 (setq attributes (delq 'bidi-category attributes))
1053 (unless (or (not (memq 'mirrored attributes))
1054 (eq (setq value (get-char-attribute char 'mirrored 'empty))
1056 (insert (format "(mirrored\t\t. %S)%s"
1059 (setq attributes (delq 'mirrored attributes))
1062 ((and (memq 'decimal-digit-value attributes)
1063 (setq value (get-char-attribute char 'decimal-digit-value)))
1064 (insert (format "(decimal-digit-value . %S)%s"
1067 (setq attributes (delq 'decimal-digit-value attributes))
1068 (when (and (memq 'digit-value attributes)
1069 (setq value (get-char-attribute char 'digit-value)))
1070 (insert (format "(digit-value\t . %S)%s"
1073 (setq attributes (delq 'digit-value attributes))
1075 (when (and (memq 'numeric-value attributes)
1076 (setq value (get-char-attribute char 'numeric-value)))
1077 (insert (format "(numeric-value\t . %S)%s"
1080 (setq attributes (delq 'numeric-value attributes))
1084 (when (and (memq 'digit-value attributes)
1085 (setq value (get-char-attribute char 'digit-value)))
1086 (insert (format "(digit-value\t. %S)%s"
1089 (setq attributes (delq 'digit-value attributes))
1091 (when (and (memq 'numeric-value attributes)
1092 (setq value (get-char-attribute char 'numeric-value)))
1093 (insert (format "(numeric-value\t. %S)%s"
1096 (setq attributes (delq 'numeric-value attributes))
1098 (when (and (memq 'iso-10646-comment attributes)
1099 (setq value (get-char-attribute char 'iso-10646-comment)))
1100 (insert (format "(iso-10646-comment\t. %S)%s"
1103 (setq attributes (delq 'iso-10646-comment attributes))
1105 (when (and (memq 'morohashi-daikanwa attributes)
1106 (setq value (get-char-attribute char 'morohashi-daikanwa)))
1107 (insert (format "(morohashi-daikanwa\t%s)%s"
1108 (mapconcat (function prin1-to-string) value " ")
1110 (setq attributes (delq 'morohashi-daikanwa attributes))
1114 (when (and (memq 'ideographic-radical attributes)
1115 (setq value (get-char-attribute char 'ideographic-radical)))
1116 (setq radical value)
1117 (insert (format "(ideographic-radical . %S)\t; %c%s"
1119 (ideographic-radical radical)
1121 (setq attributes (delq 'ideographic-radical attributes))
1123 (when (and (memq 'shuowen-radical attributes)
1124 (setq value (get-char-attribute char 'shuowen-radical)))
1125 (insert (format "(shuowen-radical\t. %S)\t; %c%s"
1127 (shuowen-radical value)
1129 (setq attributes (delq 'shuowen-radical attributes))
1134 char-db-feature-domains
1136 (dolist (feature (char-attribute-list))
1137 (setq feature (symbol-name feature))
1139 "\\(radical\\|strokes\\)@\\([^@*]+\\)\\(\\*\\|$\\)"
1141 (setq domain (intern (match-string 2 feature)))
1142 (unless (memq domain dest)
1143 (setq dest (cons domain dest)))))
1144 (sort dest #'string<))))
1145 (setq key (intern (format "%s@%s" 'ideographic-radical domain)))
1146 (when (and (memq key attributes)
1147 (setq value (get-char-attribute char key)))
1148 (setq radical value)
1149 (insert (format "(%s . %S)\t; %c%s"
1152 (ideographic-radical radical)
1154 (setq attributes (delq key attributes))
1156 (setq key (intern (format "%s@%s" 'ideographic-strokes domain)))
1157 (when (and (memq key attributes)
1158 (setq value (get-char-attribute char key)))
1159 (setq strokes value)
1160 (insert (format "(%s . %S)%s"
1164 (setq attributes (delq key attributes))
1166 (setq key (intern (format "%s@%s" 'total-strokes domain)))
1167 (when (and (memq key attributes)
1168 (setq value (get-char-attribute char key)))
1169 (insert (format "(%s . %S)%s"
1173 (setq attributes (delq key attributes))
1175 (dolist (feature '(ideographic-radical
1178 (setq key (intern (format "%s@%s*sources" feature domain)))
1179 (when (and (memq key attributes)
1180 (setq value (get-char-attribute char key)))
1181 (insert (format "(%s%s" key line-breaking))
1182 (dolist (cell value)
1183 (insert (format " %s" cell)))
1185 (insert line-breaking)
1186 (setq attributes (delq key attributes))
1189 (when (and (memq 'ideographic-strokes attributes)
1190 (setq value (get-char-attribute char 'ideographic-strokes)))
1191 (setq strokes value)
1192 (insert (format "(ideographic-strokes . %S)%s"
1195 (setq attributes (delq 'ideographic-strokes attributes))
1197 (when (and (memq 'kangxi-radical attributes)
1198 (setq value (get-char-attribute char 'kangxi-radical)))
1199 (unless (eq value radical)
1200 (insert (format "(kangxi-radical\t . %S)\t; %c%s"
1202 (ideographic-radical value)
1205 (setq radical value)))
1206 (setq attributes (delq 'kangxi-radical attributes))
1208 (when (and (memq 'kangxi-strokes attributes)
1209 (setq value (get-char-attribute char 'kangxi-strokes)))
1210 (unless (eq value strokes)
1211 (insert (format "(kangxi-strokes\t . %S)%s"
1215 (setq strokes value)))
1216 (setq attributes (delq 'kangxi-strokes attributes))
1218 ;; (when (and (memq 'japanese-radical attributes)
1219 ;; (setq value (get-char-attribute char 'japanese-radical)))
1220 ;; (unless (eq value radical)
1221 ;; (insert (format "(japanese-radical\t . %S)\t; %c%s"
1223 ;; (ideographic-radical value)
1226 ;; (setq radical value)))
1227 ;; (setq attributes (delq 'japanese-radical attributes))
1229 (when (and (memq 'japanese-strokes attributes)
1230 (setq value (get-char-attribute char 'japanese-strokes)))
1231 (unless (eq value strokes)
1232 (insert (format "(japanese-strokes\t . %S)%s"
1236 (setq strokes value)))
1237 (setq attributes (delq 'japanese-strokes attributes))
1239 (when (and (memq 'cns-radical attributes)
1240 (setq value (get-char-attribute char 'cns-radical)))
1241 (insert (format "(cns-radical\t . %S)\t; %c%s"
1243 (ideographic-radical value)
1245 (setq attributes (delq 'cns-radical attributes))
1247 (when (and (memq 'cns-strokes attributes)
1248 (setq value (get-char-attribute char 'cns-strokes)))
1249 (unless (eq value strokes)
1250 (insert (format "(cns-strokes\t . %S)%s"
1254 (setq strokes value)))
1255 (setq attributes (delq 'cns-strokes attributes))
1257 ;; (when (and (memq 'ideographic- attributes)
1258 ;; (setq value (get-char-attribute char 'ideographic-)))
1259 ;; (insert "(ideographic- ")
1260 ;; (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1262 ;; (while (consp value)
1263 ;; (setq cell (car value))
1264 ;; (if (integerp cell)
1265 ;; (setq cell (decode-char '=ucs cell)))
1266 ;; (cond ((characterp cell)
1270 ;; (insert (format "%S" cell))
1271 ;; (char-db-insert-char-spec cell readable))
1272 ;; (setq separator lbs))
1276 ;; (if (consp (car cell))
1277 ;; (char-db-insert-char-spec cell readable)
1278 ;; (char-db-insert-char-reference cell readable))
1279 ;; (setq separator lbs))
1282 ;; (insert separator))
1283 ;; (insert (prin1-to-string cell))
1284 ;; (setq separator " ")))
1285 ;; (setq value (cdr value)))
1287 ;; (insert line-breaking)
1288 ;; (setq attributes (delq 'ideographic- attributes)))
1289 (when (and (memq 'total-strokes attributes)
1290 (setq value (get-char-attribute char 'total-strokes)))
1291 (insert (format "(total-strokes . %S)%s"
1294 (setq attributes (delq 'total-strokes attributes))
1296 ;; (when (and (memq '->ideograph attributes)
1297 ;; (setq value (get-char-attribute char '->ideograph)))
1298 ;; (insert (format "(->ideograph\t%s)%s"
1299 ;; (mapconcat (lambda (code)
1300 ;; (cond ((symbolp code)
1301 ;; (symbol-name code))
1303 ;; (format "#x%04X" code))
1306 ;; line-breaking code))))
1309 ;; (setq attributes (delq '->ideograph attributes))
1311 ;; (when (and (memq '->decomposition attributes)
1312 ;; (setq value (get-char-attribute char '->decomposition)))
1313 ;; (insert (format "(->decomposition\t%s)%s"
1314 ;; (mapconcat (lambda (code)
1315 ;; (cond ((symbolp code)
1316 ;; (symbol-name code))
1317 ;; ((characterp code)
1319 ;; (format "%S" code)
1324 ;; (format "#x%04X" code))
1326 ;; (format "%s%S" line-breaking code))))
1329 ;; (setq attributes (delq '->decomposition attributes))
1331 (if (equal (get-char-attribute char '->titlecase)
1332 (get-char-attribute char '->uppercase))
1333 (setq attributes (delq '->titlecase attributes)))
1334 (when (and (memq '->mojikyo attributes)
1335 (setq value (get-char-attribute char '->mojikyo)))
1336 (insert (format "(->mojikyo\t\t. %06d)\t; %c%s"
1337 value (decode-char 'mojikyo value)
1339 (setq attributes (delq '->mojikyo attributes))
1342 (dolist (ignored '(composition
1343 ->denotational <-subsumptive ->ucs-unified
1344 ;; ->ideographic-component-forms
1346 (setq attributes (delq ignored attributes))))
1348 (setq name (car attributes))
1349 (unless (eq (setq value (get-char-attribute char name 'value-is-empty))
1351 (cond ((setq ret (find-charset name))
1352 (setq name (charset-name ret))
1353 (when (not (memq name dest-ccss))
1354 (setq dest-ccss (cons name dest-ccss))
1355 (char-db-insert-ccs-feature name value line-breaking))
1357 ((string-match "^=>ucs@" (symbol-name name))
1358 (insert (format "(%-18s . #x%04X)\t; %c%s"
1359 name value (decode-char '=ucs value)
1362 ((eq name 'jisx0208-1978/4X)
1363 (insert (format "(%-18s . #x%04X)%s"
1369 (not (eq name '->subsumptive))
1370 (not (eq name '->uppercase))
1371 (not (eq name '->lowercase))
1372 (not (eq name '->titlecase))
1373 (not (eq name '->canonical))
1374 (not (eq name '->Bopomofo))
1375 (not (eq name '->mistakable))
1376 (not (eq name '->ideographic-variants))
1377 (null (get-char-attribute
1378 char (intern (format "%s*sources" name))))
1379 (not (string-match "\\*sources$" (symbol-name name)))
1380 (null (get-char-attribute
1381 char (intern (format "%s*note" name))))
1382 (not (string-match "\\*note$" (symbol-name name)))
1383 (or (eq name '<-identical)
1384 (eq name '<-uppercase)
1385 (eq name '<-lowercase)
1386 (eq name '<-titlecase)
1387 (eq name '<-canonical)
1388 (eq name '<-ideographic-variants)
1389 ;; (eq name '<-synonyms)
1390 (string-match "^<-synonyms" (symbol-name name))
1391 (eq name '<-mistakable)
1392 (when (string-match "^->" (symbol-name name))
1394 ((string-match "^->fullwidth" (symbol-name name))
1395 (not (and (consp value)
1396 (characterp (car value))
1398 (car value) '=ucs 'defined-only)))
1403 ((or (eq name 'ideographic-structure)
1404 (eq name 'ideographic-structure@apparent)
1405 (eq name 'ideographic-combination)
1406 ;; (eq name 'ideographic-)
1407 (eq name '=decomposition)
1408 (char-feature-base-name= '=decomposition name)
1409 (char-feature-base-name= '=>decomposition name)
1410 ;; (string-match "^=>*decomposition\\(@[^*]+\\)?$"
1411 ;; (symbol-name name))
1412 (string-match "^\\(->\\|<-\\)[^*]*$" (symbol-name name))
1413 (string-match "^\\(->\\|<-\\)[^*]*\\*sources$"
1416 (char-db-insert-relation-feature char name value
1419 ;; ((memq name '(ideograph=
1420 ;; original-ideograph-of
1421 ;; ancient-ideograph-of
1422 ;; vulgar-ideograph-of
1423 ;; wrong-ideograph-of
1424 ;; ;; simplified-ideograph-of
1425 ;; ideographic-variants
1426 ;; ;; ideographic-different-form-of
1428 ;; (insert (format "(%-18s%s " name line-breaking))
1429 ;; (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1431 ;; (while (consp value)
1432 ;; (setq cell (car value))
1433 ;; (if (and (consp cell)
1434 ;; (consp (car cell)))
1438 ;; (char-db-insert-alist cell readable)
1439 ;; (setq separator lbs))
1441 ;; (insert separator))
1442 ;; (insert (prin1-to-string cell))
1443 ;; (setq separator " "))
1444 ;; (setq value (cdr value)))
1446 ;; (insert line-breaking))
1448 (insert (format "(%-18s " name))
1449 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1451 (while (consp value)
1452 (setq cell (car value))
1453 (if (and (consp cell)
1455 (setq ret (condition-case nil
1463 (setq key (car (car rest)))
1464 (if (find-charset key)
1465 (setq cal (cons key cal))
1466 (setq al (cons key al)))
1467 (setq rest (cdr rest)))
1470 (insert-char-attributes ret
1474 (setq separator lbs))
1475 (setq ret (prin1-to-string cell))
1477 (if (< (+ (current-column)
1484 (setq separator " "))
1485 (setq value (cdr value)))
1487 (insert line-breaking))
1489 (insert (format "(%-18s" name))
1490 (setq ret (prin1-to-string value))
1491 (unless (< (+ (current-column)
1495 (insert line-breaking))
1496 (insert " . " ret ")" line-breaking)
1497 ;; (insert (format "(%-18s . %S)%s"
1502 (setq attributes (cdr attributes)))
1505 (defun insert-char-data (char &optional readable
1508 (narrow-to-region (point)(point))
1509 (insert "(define-char
1511 (insert-char-attributes char readable attributes)
1513 (goto-char (point-min))
1514 (while (re-search-forward "[ \t]+$" nil t)
1517 (goto-char (point-min))
1518 (while (re-search-forward "[ \t][ \t][ \t]*" nil t)
1519 (let ((column (current-column))
1520 (indent-tabs-mode t))
1521 (delete-region (match-beginning 0) (point))
1522 (indent-to column)))
1523 (goto-char (point-max))
1524 ;; (tabify (point-min)(point-max))
1527 (defun insert-char-data-with-variant (char &optional printable
1529 script excluded-script)
1530 (insert-char-data char printable)
1531 (let ((variants (char-variants char))
1534 (setq variants (sort variants #'<))
1535 (setq rest variants)
1536 (setq variants (cons char variants))
1538 (setq variant (car rest))
1539 (unless (get-char-attribute variant '<-subsumptive)
1540 (if (and (or (null script)
1541 (null (setq vs (get-char-attribute variant 'script)))
1543 (or (null excluded-script)
1544 (null (setq vs (get-char-attribute variant 'script)))
1545 (not (memq excluded-script vs))))
1546 (unless (and no-ucs-unified (get-char-attribute variant '=ucs))
1547 (insert-char-data variant printable)
1548 (if (setq ret (char-variants variant))
1550 (or (memq (car ret) variants)
1551 ;; (get-char-attribute (car ret) '<-subsumptive)
1552 (setq rest (nconc rest (list (car ret)))))
1553 (setq ret (cdr ret)))))))
1554 (setq rest (cdr rest)))))
1556 (defun insert-char-range-data (min max &optional script excluded-script)
1559 (while (<= code max)
1560 (setq char (decode-char '=ucs code))
1561 (if (encode-char char '=ucs 'defined-only)
1562 (insert-char-data-with-variant char nil 'no-ucs-unified
1563 script excluded-script))
1564 (setq code (1+ code)))))
1566 (defun write-char-range-data-to-file (min max file
1567 &optional script excluded-script)
1568 (let ((coding-system-for-write char-db-file-coding-system))
1570 (insert (format ";; -*- coding: %s -*-\n"
1571 char-db-file-coding-system))
1572 (insert-char-range-data min max script excluded-script)
1573 (write-region (point-min)(point-max) file))))
1575 (defvar what-character-original-window-configuration)
1578 (defun what-char-definition (char)
1579 (interactive (list (char-after)))
1580 (let ((buf (get-buffer-create "*Character Description*"))
1581 (the-buf (current-buffer))
1582 (win-conf (current-window-configuration)))
1584 (make-local-variable 'what-character-original-window-configuration)
1585 (setq what-character-original-window-configuration win-conf)
1586 (setq buffer-read-only nil)
1590 (insert-char-data-with-variant char 'printable)
1591 (unless (char-attribute-alist char)
1592 (insert (format ";; = %c\n"
1593 (let* ((rest (split-char char))
1597 (setq code (logior (lsh code 8)
1599 (decode-char ccs code)))))
1600 ;; (char-db-update-comment)
1601 (set-buffer-modified-p nil)
1602 (view-mode the-buf (lambda (buf)
1603 (set-window-configuration
1604 what-character-original-window-configuration)
1606 (goto-char (point-min)))
1608 (set-window-configuration
1609 what-character-original-window-configuration)
1610 (signal (car err) (cdr err)))))))
1616 (provide 'char-db-util)
1618 ;;; char-db-util.el ends here