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
381 =>big5-cdp-itaiji-001
382 =>big5-cdp-itaiji-003
387 =>ucs@iwds-1/normalized
388 =>ucs-itaiji-001@iwds-1
389 =>ucs-itaiji-002@iwds-1
398 ;;; @ char-db formatters
401 (defun char-db-make-char-spec (char)
403 (cond ((characterp char)
404 (cond ((and (setq ret (encode-char char '=ucs 'defined-only))
405 (not (and (<= #xE000 ret)(<= ret #xF8FF))))
406 (setq char-spec (list (cons '=ucs ret)))
407 (cond ((setq ret (get-char-attribute char 'name))
408 (setq char-spec (cons (cons 'name ret) char-spec))
410 ((setq ret (get-char-attribute char 'name*))
411 (setq char-spec (cons (cons 'name* ret) char-spec))
414 ((encode-char char '=mj 'defined-only)
416 (dolist (ccs (charset-list))
417 (if (and (or (eq ccs '=mj)
418 ;; (eq (charset-property ccs 'iso-ir) 177)
419 (string-match "=ucs@" (symbol-name ccs))
421 (setq ccs (charset-name ccs))
422 (null (assq ccs char-spec))
423 (setq ret (encode-char char ccs 'defined-only)))
424 (setq char-spec (cons (cons ccs ret) char-spec))))
426 ((encode-char char '==mj 'defined-only)
428 (dolist (ccs (charset-list))
429 (if (and (or (eq ccs '==mj)
430 ;; (eq (charset-property ccs 'iso-ir) 177)
431 (string-match "=ucs@" (symbol-name ccs))
433 (setq ccs (charset-name ccs))
434 (null (assq ccs char-spec))
435 (setq ret (encode-char char ccs 'defined-only)))
436 (setq char-spec (cons (cons ccs ret) char-spec))))
438 ((encode-char char '=adobe-japan1 'defined-only)
440 (dolist (ccs (charset-list))
441 (if (and (or (memq ccs
450 ;; (eq (charset-property ccs 'iso-ir) 177)
451 (string-match "=ucs@" (symbol-name ccs))
453 (setq ccs (charset-name ccs))
454 (null (assq ccs char-spec))
455 (setq ret (encode-char char ccs 'defined-only)))
456 (setq char-spec (cons (cons ccs ret) char-spec))))
458 ((encode-char char '==adobe-japan1 'defined-only)
460 (dolist (ccs (charset-list))
461 (if (and (or (memq ccs
470 ;; (eq (charset-property ccs 'iso-ir) 177)
471 (string-match "=ucs@" (symbol-name ccs))
473 (setq ccs (charset-name ccs))
474 (null (assq ccs char-spec))
475 (setq ret (encode-char char ccs 'defined-only)))
476 (setq char-spec (cons (cons ccs ret) char-spec))))
480 (let ((rest char-db-coded-charset-priority-list)
483 (setq ccs (charset-name
484 (find-charset (car rest))))
486 (encode-char char ccs
488 (throw 'tag (cons ccs ret)))
489 (setq rest (cdr rest))))))
490 (setq char-spec (list ret))
491 (dolist (ccs (delq (car ret) (charset-list)))
492 (if (and (or (charset-iso-final-char ccs)
499 (and (eq (charset-property ccs 'iso-ir) 177)
500 (not (eq (charset-name ccs) '=ucs@big5)))
501 ;; (string-match "=ucs@" (symbol-name ccs))
503 (setq ccs (charset-name ccs))
504 (null (assq ccs char-spec))
505 (setq ret (encode-char char ccs 'defined-only)))
506 (setq char-spec (cons (cons ccs ret) char-spec))))
508 (setq char-spec (split-char char)))
509 (cond ((setq ret (get-char-attribute char 'name))
510 (setq char-spec (cons (cons 'name ret) char-spec))
512 ((setq ret (get-char-attribute char 'name*))
513 (setq char-spec (cons (cons 'name* ret) char-spec))
516 ((setq ret (get-char-attribute
517 char 'ideographic-combination))
519 (cons (cons 'ideographic-combination ret)
526 (defun char-db-insert-char-spec (char &optional readable column
529 (setq column (current-column)))
530 (let (char-spec temp-char)
531 (setq char-spec (char-db-make-char-spec char))
532 (unless (or (characterp char) ; char
534 (setq char (find-char char-spec))
536 ;; define temporary character
537 ;; Current implementation is dirty.
538 (setq temp-char (define-char (cons '(ideograph-daikanwa . 0)
540 (remove-char-attribute temp-char 'ideograph-daikanwa)
541 (setq char temp-char))
542 (insert-char-attributes char
544 (union (mapcar #'car char-spec)
548 ;; undefine temporary character
549 ;; Current implementation is dirty.
550 (setq char-spec (char-attribute-alist temp-char))
552 (remove-char-attribute temp-char (car (car char-spec)))
553 (setq char-spec (cdr char-spec))))))
555 (defun char-db-insert-alist (alist &optional readable column)
557 (setq column (current-column)))
559 (concat "\n" (make-string (1+ column) ?\ )))
563 lbs cell rest separator)
566 (setq name (car (car alist))
567 value (cdr (car alist)))
568 (cond ((eq name 'char)
570 (if (setq ret (condition-case nil
578 (setq key (car (car value)))
579 ;; (if (find-charset key)
580 ;; (setq cal (cons key cal))
581 (setq al (cons key al))
583 (setq value (cdr value)))
584 (insert-char-attributes ret
588 (insert (prin1-to-string value)))
590 (insert line-breaking))
592 (insert (format "(%-18s " name))
593 (setq lbs (concat "\n" (make-string (current-column) ?\ )))
595 (setq cell (car value))
596 (if (and (consp cell)
598 (setq ret (condition-case nil
608 (setq key (car (car rest)))
609 ;; (if (find-charset key)
610 ;; (setq cal (cons key cal))
611 (setq al (cons key al))
613 (setq rest (cdr rest)))
616 (insert-char-attributes ret
620 (setq separator lbs))
623 (insert (prin1-to-string cell))
624 (setq separator " "))
625 (setq value (cdr value)))
627 (insert line-breaking))
629 (insert (format "(%-18s . %S)%s"
632 (setq alist (cdr alist))))
635 (defun char-db-insert-char-reference (plist &optional readable column)
637 (setq column (current-column)))
639 (concat "\n" (make-string (1+ column) ?\ )))
644 (setq name (pop plist))
645 (setq value (pop plist))
646 (cond ((eq name :char)
649 (cond ((numberp value)
650 (setq value (decode-char '=ucs value)))
652 ;; (setq value (or (find-char value)
655 (char-db-insert-char-spec value readable)
656 (insert line-breaking)
659 (insert (format "%s%s\t%d ; %c%s"
662 (ideographic-radical value)
666 (insert (format "%s%s\t%S" separator name value))
667 (setq separator line-breaking)))
671 (defun char-db-decode-isolated-char (ccs code-point)
674 (cond ((eq ccs 'arabic-iso8859-6)
675 (decode-char ccs code-point))
677 ;; (decode-builtin-char '==gt code-point))
678 ((and (memq ccs '(=gt-pj-1
689 (setq ret (decode-char ccs code-point))
690 (setq ret (encode-char ret '=gt 'defined-only)))
691 (decode-builtin-char '=gt ret))
693 (decode-builtin-char ccs code-point))))
695 (or (decode-char ccs code-point)
696 (define-char (list (cons ccs code-point)))))
697 ((and (<= 0 (char-int ret))
698 (<= (char-int ret) #x1F))
699 (decode-char '=ucs (+ #x2400 (char-int ret))))
700 ((= (char-int ret) #x7F)
704 (defvar char-db-convert-obsolete-format t)
706 (defun char-db-insert-ccs-feature (name value line-breaking)
712 ((memq name '(=>iwds-1
715 =shinjigen@1ed ==shinjigen@1ed
716 =shinjigen@rev ==shinjigen@rev
717 =shinjigen/+p@rev ==shinjigen/+p@rev
718 ===daikanwa/ho ==daikanwa/ho
719 =daikanwa/ho =>>daikanwa/ho =>daikanwa/ho))
720 "(%-18s . %04d)\t; %c")
721 ((eq name '=shinjigen@1ed/24pr)
722 "(%-18s . %04d)\t; %c")
726 ==daikanwa =daikanwa =>>daikanwa =>daikanwa
727 =daikanwa@rev1 =daikanwa@rev2
728 =daikanwa/+p ==daikanwa/+p ===daikanwa/+p
730 =daikanwa/+2p =>>daikanwa/+2p
735 =adobe-japan1-0 ==adobe-japan1-0 ===adobe-japan1-0
736 =adobe-japan1-1 ==adobe-japan1-1 ===adobe-japan1-1
737 =adobe-japan1-2 ==adobe-japan1-2 ===adobe-japan1-2
738 =adobe-japan1-3 ==adobe-japan1-3 ===adobe-japan1-3
739 =adobe-japan1-4 ==adobe-japan1-4 ===adobe-japan1-4
740 =adobe-japan1-5 ==adobe-japan1-5 ===adobe-japan1-5
741 =adobe-japan1-6 ==adobe-japan1-6 ===adobe-japan1-6
742 =>>adobe-japan1-0 =+>adobe-japan1-0
743 =>>adobe-japan1-1 =+>adobe-japan1-1
744 =>>adobe-japan1-2 =+>adobe-japan1-2
745 =>>adobe-japan1-3 =+>adobe-japan1-3
746 =>>adobe-japan1-4 =+>adobe-japan1-4
747 =>>adobe-japan1-5 =+>adobe-japan1-5
748 =>>adobe-japan1-6 =+>adobe-japan1-6
749 =>cbeta =cbeta =>>cbeta ==cbeta ===cbeta
750 =zinbun-oracle =>zinbun-oracle
751 =daijiten ==daijiten ===daijiten ==>daijiten
752 ===hng-jou ===hng-keg ===hng-dng ===hng-mam
753 ===hng-drt ===hng-kgk ===hng-myz ===hng-kda
754 ===hng-khi ===hng-khm ===hng-fhs ===hng-hok
755 ===hng-kyd ===hng-sok
756 ===hng-yhk ===hng-kak ===hng-kar ===hng-kae
757 ===hng-sys ===hng-tsu ===hng-tzj
758 ===hng-hos ===hng-kkh ===hng-nak ===hng-jhk
759 ===hng-hod ===hng-gok ===hng-ink ===hng-nto
760 ===hng-nkm ===hng-k24 ===hng-ini ===hng-nkk
761 ===hng-kcc ===hng-kcj ===hng-kbk ===hng-sik
762 ===hng-skk ===hng-kyu ===hng-ksk ===hng-wan
763 ===hng-okd ===hng-wad ===hng-kmi
764 ===hng-zkd ===hng-doh ===hng-jyu ===hng-tzs
765 ===hng-sai ===hng-kad ===hng-kss
766 ===hng-kyo ===hng-ykk ===hng-saa
767 ===hng-sab ===hng-wks ===hng-wke ===hng-smk
768 ===hng-sgs ===hng-sts
769 =shuowen-jiguge ===shuowen-jiguge4 ===shuowen-jiguge5))
770 ;; (string-match "^=adobe-" (symbol-name name))
772 "(%-18s . %05d)\t; %c")
773 ((memq name '(=hanyo-denshi/ks
774 ==hanyo-denshi/ks ===hanyo-denshi/ks
777 =mj ==mj ===mj =>>mj =>mj
779 "(%-18s . %06d)\t; %c")
780 ((memq name '(=hanyo-denshi/tk ==hanyo-denshi/tk))
781 "(%-18s . %08d)\t; %c")
782 ((>= (charset-dimension name) 2)
783 "(%-18s . #x%04X)\t; %c")
785 "(%-18s . #x%02X)\t; %c"))
787 (if (= (charset-iso-graphic-plane name) 1)
789 (cond ((= (charset-dimension name) 1)
791 ((= (charset-dimension name) 2)
793 ((= (charset-dimension name) 3)
797 (char-db-decode-isolated-char name value)))
798 (if (and (= (charset-chars name) 94)
799 (= (charset-dimension name) 2))
800 (insert (format " [%02d-%02d]"
801 (- (lsh value -8) 32)
802 (- (logand value 255) 32))))
805 (insert (format "(%-18s . %s)" name value))
807 (insert line-breaking))
809 (defun char-db-insert-relation-feature (char name value line-breaking
811 (insert (format "(%-18s%s " name line-breaking))
812 (let ((lbs (concat "\n" (make-string (current-column) ?\ )))
813 separator cell sources required-features
816 (setq cell (car value))
818 (setq cell (decode-char '=ucs cell)))
820 ((eq name '->subsumptive)
821 (when (or (not (some (lambda (atr)
822 (get-char-attribute cell atr))
823 char-db-ignored-attributes))
825 (encode-char cell ccs 'defined-only))
829 (let ((char-db-ignored-attributes
831 char-db-ignored-attributes)))
832 (insert-char-attributes cell readable nil nil 'for-sub-node))
833 (setq separator lbs))
838 char (intern (format "%s*sources" name))))
839 (setq required-features nil)
840 (dolist (source sources)
844 shinjigen shinjigen@1ed shinjigen@rev))
845 (setq required-features
846 (union required-features
858 =shinjigen/+p@rev))))
860 (setq required-features
861 (union required-features
866 ((find-charset (setq ret (intern (format "=%s" source))))
867 (setq required-features
868 (cons ret required-features)))
869 (t (setq required-features
870 (cons source required-features)))))
871 (cond ((string-match "@JP" (symbol-name name))
872 (setq required-features
873 (union required-features
881 ((string-match "@CN" (symbol-name name))
882 (setq required-features
883 (union required-features
890 (insert (format "%S" cell))
891 (char-db-insert-char-spec cell readable
894 (setq separator lbs))
898 (if (consp (car cell))
899 (char-db-insert-char-spec cell readable)
900 (char-db-insert-char-reference cell readable))
901 (setq separator lbs))
905 (insert (prin1-to-string cell))
906 (setq separator " ")))
907 (setq value (cdr value)))
909 (insert line-breaking)))
911 (defun insert-char-attributes (char &optional readable attributes column
914 (setq column (current-column)))
915 (let (name value ; has-long-ccs-name
919 (concat "\n" (make-string (1+ column) ?\ )))
920 lbs cell separator ret
922 dest-ccss ; sources required-features
927 (if (consp attributes)
929 (dolist (name attributes)
930 (unless (memq name char-db-ignored-attributes)
931 (if (find-charset name)
935 (dolist (name (char-attribute-list))
936 (unless (memq name char-db-ignored-attributes)
937 (if (find-charset name)
941 #'char-attribute-name<)))
943 (when (memq '<-subsumptive attributes)
944 (when (or readable (not for-sub-node))
945 (when (setq value (get-char-attribute char '<-subsumptive))
946 (char-db-insert-relation-feature char '<-subsumptive value
949 (setq attributes (delq '<-subsumptive attributes)))
950 (when (and (memq '<-denotational attributes)
951 (setq value (get-char-attribute char '<-denotational)))
952 (char-db-insert-relation-feature char '<-denotational value
955 (setq attributes (delq '<-denotational attributes)))
956 (when (and (memq '<-denotational@component attributes)
957 (setq value (get-char-attribute char '<-denotational@component)))
958 (char-db-insert-relation-feature char '<-denotational@component value
961 (setq attributes (delq '<-denotational@component attributes)))
962 (when (and (memq '<-denotational@usage attributes)
963 (setq value (get-char-attribute char '<-denotational@usage)))
964 (char-db-insert-relation-feature char '<-denotational@usage value
967 (setq attributes (delq '<-denotational@usage attributes)))
968 (when (and (memq 'name attributes)
969 (setq value (get-char-attribute char 'name)))
971 (if (> (+ (current-column) (length value)) 48)
974 value line-breaking))
975 (setq attributes (delq 'name attributes))
977 (when (and (memq 'name* attributes)
978 (setq value (get-char-attribute char 'name*)))
980 (if (> (+ (current-column) (length value)) 48)
983 value line-breaking))
984 (setq attributes (delq 'name* attributes))
986 (when (and (memq 'script attributes)
987 (setq value (get-char-attribute char 'script)))
988 (insert (format "(script\t\t%s)%s"
989 (mapconcat (function prin1-to-string)
992 (setq attributes (delq 'script attributes))
994 (dolist (name '(=>ucs =>ucs*))
995 (when (and (memq name attributes)
996 (setq value (get-char-attribute char name)))
997 (insert (format "(%-18s . #x%04X)\t; %c%s"
998 name value (decode-char '=ucs value)
1000 (setq attributes (delq name attributes))))
1001 (dolist (name '(=>ucs@gb =>ucs@big5))
1002 (when (and (memq name attributes)
1003 (setq value (get-char-attribute char name)))
1004 (insert (format "(%-18s . #x%04X)\t; %c%s"
1006 (decode-char (intern
1009 (symbol-name name) 2)))
1012 (setq attributes (delq name attributes))
1014 ;; (dolist (name '(=>daikanwa))
1015 ;; (when (and (memq name attributes)
1016 ;; (setq value (get-char-attribute char name)))
1018 ;; (if (integerp value)
1019 ;; (format "(%-18s . %05d)\t; %c%s"
1020 ;; name value (decode-char '=daikanwa value)
1022 ;; (format "(%-18s %s)\t; %c%s"
1024 ;; (mapconcat (function prin1-to-string)
1026 ;; (char-representative-of-daikanwa char)
1028 ;; (setq attributes (delq name attributes))))
1029 (when (and (memq 'general-category attributes)
1030 (setq value (get-char-attribute char 'general-category)))
1032 "(general-category\t%s) ; %s%s"
1033 (mapconcat (lambda (cell)
1036 (cond ((rassoc value unidata-normative-category-alist)
1037 "Normative Category")
1038 ((rassoc value unidata-informative-category-alist)
1039 "Informative Category")
1041 "Unknown Category"))
1043 (setq attributes (delq 'general-category attributes))
1045 (when (and (memq 'bidi-category attributes)
1046 (setq value (get-char-attribute char 'bidi-category)))
1047 (insert (format "(bidi-category\t. %S)%s"
1050 (setq attributes (delq 'bidi-category attributes))
1052 (unless (or (not (memq 'mirrored attributes))
1053 (eq (setq value (get-char-attribute char 'mirrored 'empty))
1055 (insert (format "(mirrored\t\t. %S)%s"
1058 (setq attributes (delq 'mirrored attributes))
1061 ((and (memq 'decimal-digit-value attributes)
1062 (setq value (get-char-attribute char 'decimal-digit-value)))
1063 (insert (format "(decimal-digit-value . %S)%s"
1066 (setq attributes (delq 'decimal-digit-value attributes))
1067 (when (and (memq 'digit-value attributes)
1068 (setq value (get-char-attribute char 'digit-value)))
1069 (insert (format "(digit-value\t . %S)%s"
1072 (setq attributes (delq 'digit-value attributes))
1074 (when (and (memq 'numeric-value attributes)
1075 (setq value (get-char-attribute char 'numeric-value)))
1076 (insert (format "(numeric-value\t . %S)%s"
1079 (setq attributes (delq 'numeric-value attributes))
1083 (when (and (memq 'digit-value attributes)
1084 (setq value (get-char-attribute char 'digit-value)))
1085 (insert (format "(digit-value\t. %S)%s"
1088 (setq attributes (delq 'digit-value attributes))
1090 (when (and (memq 'numeric-value attributes)
1091 (setq value (get-char-attribute char 'numeric-value)))
1092 (insert (format "(numeric-value\t. %S)%s"
1095 (setq attributes (delq 'numeric-value attributes))
1097 (when (and (memq 'iso-10646-comment attributes)
1098 (setq value (get-char-attribute char 'iso-10646-comment)))
1099 (insert (format "(iso-10646-comment\t. %S)%s"
1102 (setq attributes (delq 'iso-10646-comment attributes))
1104 (when (and (memq 'morohashi-daikanwa attributes)
1105 (setq value (get-char-attribute char 'morohashi-daikanwa)))
1106 (insert (format "(morohashi-daikanwa\t%s)%s"
1107 (mapconcat (function prin1-to-string) value " ")
1109 (setq attributes (delq 'morohashi-daikanwa attributes))
1113 (when (and (memq 'ideographic-radical attributes)
1114 (setq value (get-char-attribute char 'ideographic-radical)))
1115 (setq radical value)
1116 (insert (format "(ideographic-radical . %S)\t; %c%s"
1118 (ideographic-radical radical)
1120 (setq attributes (delq 'ideographic-radical attributes))
1122 (when (and (memq 'shuowen-radical attributes)
1123 (setq value (get-char-attribute char 'shuowen-radical)))
1124 (insert (format "(shuowen-radical\t. %S)\t; %c%s"
1126 (shuowen-radical value)
1128 (setq attributes (delq 'shuowen-radical attributes))
1133 char-db-feature-domains
1135 (dolist (feature (char-attribute-list))
1136 (setq feature (symbol-name feature))
1138 "\\(radical\\|strokes\\)@\\([^@*]+\\)\\(\\*\\|$\\)"
1140 (setq domain (intern (match-string 2 feature)))
1141 (unless (memq domain dest)
1142 (setq dest (cons domain dest)))))
1143 (sort dest #'string<))))
1144 (setq key (intern (format "%s@%s" 'ideographic-radical domain)))
1145 (when (and (memq key attributes)
1146 (setq value (get-char-attribute char key)))
1147 (setq radical value)
1148 (insert (format "(%s . %S)\t; %c%s"
1151 (ideographic-radical radical)
1153 (setq attributes (delq key attributes))
1155 (setq key (intern (format "%s@%s" 'ideographic-strokes domain)))
1156 (when (and (memq key attributes)
1157 (setq value (get-char-attribute char key)))
1158 (setq strokes value)
1159 (insert (format "(%s . %S)%s"
1163 (setq attributes (delq key attributes))
1165 (setq key (intern (format "%s@%s" 'total-strokes domain)))
1166 (when (and (memq key attributes)
1167 (setq value (get-char-attribute char key)))
1168 (insert (format "(%s . %S)%s"
1172 (setq attributes (delq key attributes))
1174 (dolist (feature '(ideographic-radical
1177 (setq key (intern (format "%s@%s*sources" feature domain)))
1178 (when (and (memq key attributes)
1179 (setq value (get-char-attribute char key)))
1180 (insert (format "(%s%s" key line-breaking))
1181 (dolist (cell value)
1182 (insert (format " %s" cell)))
1184 (insert line-breaking)
1185 (setq attributes (delq key attributes))
1188 (when (and (memq 'ideographic-strokes attributes)
1189 (setq value (get-char-attribute char 'ideographic-strokes)))
1190 (setq strokes value)
1191 (insert (format "(ideographic-strokes . %S)%s"
1194 (setq attributes (delq 'ideographic-strokes attributes))
1196 (when (and (memq 'kangxi-radical attributes)
1197 (setq value (get-char-attribute char 'kangxi-radical)))
1198 (unless (eq value radical)
1199 (insert (format "(kangxi-radical\t . %S)\t; %c%s"
1201 (ideographic-radical value)
1204 (setq radical value)))
1205 (setq attributes (delq 'kangxi-radical attributes))
1207 (when (and (memq 'kangxi-strokes attributes)
1208 (setq value (get-char-attribute char 'kangxi-strokes)))
1209 (unless (eq value strokes)
1210 (insert (format "(kangxi-strokes\t . %S)%s"
1214 (setq strokes value)))
1215 (setq attributes (delq 'kangxi-strokes attributes))
1217 ;; (when (and (memq 'japanese-radical attributes)
1218 ;; (setq value (get-char-attribute char 'japanese-radical)))
1219 ;; (unless (eq value radical)
1220 ;; (insert (format "(japanese-radical\t . %S)\t; %c%s"
1222 ;; (ideographic-radical value)
1225 ;; (setq radical value)))
1226 ;; (setq attributes (delq 'japanese-radical attributes))
1228 (when (and (memq 'japanese-strokes attributes)
1229 (setq value (get-char-attribute char 'japanese-strokes)))
1230 (unless (eq value strokes)
1231 (insert (format "(japanese-strokes\t . %S)%s"
1235 (setq strokes value)))
1236 (setq attributes (delq 'japanese-strokes attributes))
1238 (when (and (memq 'cns-radical attributes)
1239 (setq value (get-char-attribute char 'cns-radical)))
1240 (insert (format "(cns-radical\t . %S)\t; %c%s"
1242 (ideographic-radical value)
1244 (setq attributes (delq 'cns-radical attributes))
1246 (when (and (memq 'cns-strokes attributes)
1247 (setq value (get-char-attribute char 'cns-strokes)))
1248 (unless (eq value strokes)
1249 (insert (format "(cns-strokes\t . %S)%s"
1253 (setq strokes value)))
1254 (setq attributes (delq 'cns-strokes attributes))
1256 ;; (when (and (memq 'ideographic- attributes)
1257 ;; (setq value (get-char-attribute char 'ideographic-)))
1258 ;; (insert "(ideographic- ")
1259 ;; (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1261 ;; (while (consp value)
1262 ;; (setq cell (car value))
1263 ;; (if (integerp cell)
1264 ;; (setq cell (decode-char '=ucs cell)))
1265 ;; (cond ((characterp cell)
1269 ;; (insert (format "%S" cell))
1270 ;; (char-db-insert-char-spec cell readable))
1271 ;; (setq separator lbs))
1275 ;; (if (consp (car cell))
1276 ;; (char-db-insert-char-spec cell readable)
1277 ;; (char-db-insert-char-reference cell readable))
1278 ;; (setq separator lbs))
1281 ;; (insert separator))
1282 ;; (insert (prin1-to-string cell))
1283 ;; (setq separator " ")))
1284 ;; (setq value (cdr value)))
1286 ;; (insert line-breaking)
1287 ;; (setq attributes (delq 'ideographic- attributes)))
1288 (when (and (memq 'total-strokes attributes)
1289 (setq value (get-char-attribute char 'total-strokes)))
1290 (insert (format "(total-strokes . %S)%s"
1293 (setq attributes (delq 'total-strokes attributes))
1295 ;; (when (and (memq '->ideograph attributes)
1296 ;; (setq value (get-char-attribute char '->ideograph)))
1297 ;; (insert (format "(->ideograph\t%s)%s"
1298 ;; (mapconcat (lambda (code)
1299 ;; (cond ((symbolp code)
1300 ;; (symbol-name code))
1302 ;; (format "#x%04X" code))
1305 ;; line-breaking code))))
1308 ;; (setq attributes (delq '->ideograph attributes))
1310 ;; (when (and (memq '->decomposition attributes)
1311 ;; (setq value (get-char-attribute char '->decomposition)))
1312 ;; (insert (format "(->decomposition\t%s)%s"
1313 ;; (mapconcat (lambda (code)
1314 ;; (cond ((symbolp code)
1315 ;; (symbol-name code))
1316 ;; ((characterp code)
1318 ;; (format "%S" code)
1323 ;; (format "#x%04X" code))
1325 ;; (format "%s%S" line-breaking code))))
1328 ;; (setq attributes (delq '->decomposition attributes))
1330 (if (equal (get-char-attribute char '->titlecase)
1331 (get-char-attribute char '->uppercase))
1332 (setq attributes (delq '->titlecase attributes)))
1333 (when (and (memq '->mojikyo attributes)
1334 (setq value (get-char-attribute char '->mojikyo)))
1335 (insert (format "(->mojikyo\t\t. %06d)\t; %c%s"
1336 value (decode-char 'mojikyo value)
1338 (setq attributes (delq '->mojikyo attributes))
1341 (dolist (ignored '(composition
1342 ->denotational <-subsumptive ->ucs-unified
1343 ;; ->ideographic-component-forms
1345 (setq attributes (delq ignored attributes))))
1347 (setq name (car attributes))
1348 (unless (eq (setq value (get-char-attribute char name 'value-is-empty))
1350 (cond ((setq ret (find-charset name))
1351 (setq name (charset-name ret))
1352 (when (not (memq name dest-ccss))
1353 (setq dest-ccss (cons name dest-ccss))
1354 (char-db-insert-ccs-feature name value line-breaking))
1356 ((string-match "^=>ucs@" (symbol-name name))
1357 (insert (format "(%-18s . #x%04X)\t; %c%s"
1358 name value (decode-char '=ucs value)
1361 ((eq name 'jisx0208-1978/4X)
1362 (insert (format "(%-18s . #x%04X)%s"
1368 (not (eq name '->subsumptive))
1369 (not (eq name '->uppercase))
1370 (not (eq name '->lowercase))
1371 (not (eq name '->titlecase))
1372 (not (eq name '->canonical))
1373 (not (eq name '->Bopomofo))
1374 (not (eq name '->mistakable))
1375 (not (eq name '->ideographic-variants))
1376 (null (get-char-attribute
1377 char (intern (format "%s*sources" name))))
1378 (not (string-match "\\*sources$" (symbol-name name)))
1379 (null (get-char-attribute
1380 char (intern (format "%s*note" name))))
1381 (not (string-match "\\*note$" (symbol-name name)))
1382 (or (eq name '<-identical)
1383 (eq name '<-uppercase)
1384 (eq name '<-lowercase)
1385 (eq name '<-titlecase)
1386 (eq name '<-canonical)
1387 (eq name '<-ideographic-variants)
1388 ;; (eq name '<-synonyms)
1389 (string-match "^<-synonyms" (symbol-name name))
1390 (eq name '<-mistakable)
1391 (when (string-match "^->" (symbol-name name))
1393 ((string-match "^->fullwidth" (symbol-name name))
1394 (not (and (consp value)
1395 (characterp (car value))
1397 (car value) '=ucs 'defined-only)))
1402 ((or (eq name 'ideographic-structure)
1403 (eq name 'ideographic-combination)
1404 ;; (eq name 'ideographic-)
1405 (eq name '=decomposition)
1406 (char-feature-base-name= '=decomposition name)
1407 (char-feature-base-name= '=>decomposition name)
1408 ;; (string-match "^=>*decomposition\\(@[^*]+\\)?$"
1409 ;; (symbol-name name))
1410 (string-match "^\\(->\\|<-\\)[^*]*$" (symbol-name name))
1411 (string-match "^\\(->\\|<-\\)[^*]*\\*sources$"
1414 (char-db-insert-relation-feature char name value
1417 ;; ((memq name '(ideograph=
1418 ;; original-ideograph-of
1419 ;; ancient-ideograph-of
1420 ;; vulgar-ideograph-of
1421 ;; wrong-ideograph-of
1422 ;; ;; simplified-ideograph-of
1423 ;; ideographic-variants
1424 ;; ;; ideographic-different-form-of
1426 ;; (insert (format "(%-18s%s " name line-breaking))
1427 ;; (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1429 ;; (while (consp value)
1430 ;; (setq cell (car value))
1431 ;; (if (and (consp cell)
1432 ;; (consp (car cell)))
1436 ;; (char-db-insert-alist cell readable)
1437 ;; (setq separator lbs))
1439 ;; (insert separator))
1440 ;; (insert (prin1-to-string cell))
1441 ;; (setq separator " "))
1442 ;; (setq value (cdr value)))
1444 ;; (insert line-breaking))
1446 (insert (format "(%-18s " name))
1447 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1449 (while (consp value)
1450 (setq cell (car value))
1451 (if (and (consp cell)
1453 (setq ret (condition-case nil
1461 (setq key (car (car rest)))
1462 (if (find-charset key)
1463 (setq cal (cons key cal))
1464 (setq al (cons key al)))
1465 (setq rest (cdr rest)))
1468 (insert-char-attributes ret
1472 (setq separator lbs))
1473 (setq ret (prin1-to-string cell))
1475 (if (< (+ (current-column)
1482 (setq separator " "))
1483 (setq value (cdr value)))
1485 (insert line-breaking))
1487 (insert (format "(%-18s" name))
1488 (setq ret (prin1-to-string value))
1489 (unless (< (+ (current-column)
1493 (insert line-breaking))
1494 (insert " . " ret ")" line-breaking)
1495 ;; (insert (format "(%-18s . %S)%s"
1500 (setq attributes (cdr attributes)))
1503 (defun insert-char-data (char &optional readable
1506 (narrow-to-region (point)(point))
1507 (insert "(define-char
1509 (insert-char-attributes char readable attributes)
1511 (goto-char (point-min))
1512 (while (re-search-forward "[ \t]+$" nil t)
1515 (goto-char (point-min))
1516 (while (re-search-forward "[ \t][ \t][ \t]*" nil t)
1517 (let ((column (current-column))
1518 (indent-tabs-mode t))
1519 (delete-region (match-beginning 0) (point))
1520 (indent-to column)))
1521 (goto-char (point-max))
1522 ;; (tabify (point-min)(point-max))
1525 (defun insert-char-data-with-variant (char &optional printable
1527 script excluded-script)
1528 (insert-char-data char printable)
1529 (let ((variants (char-variants char))
1532 (setq variants (sort variants #'<))
1533 (setq rest variants)
1534 (setq variants (cons char variants))
1536 (setq variant (car rest))
1537 (unless (get-char-attribute variant '<-subsumptive)
1538 (if (and (or (null script)
1539 (null (setq vs (get-char-attribute variant 'script)))
1541 (or (null excluded-script)
1542 (null (setq vs (get-char-attribute variant 'script)))
1543 (not (memq excluded-script vs))))
1544 (unless (and no-ucs-unified (get-char-attribute variant '=ucs))
1545 (insert-char-data variant printable)
1546 (if (setq ret (char-variants variant))
1548 (or (memq (car ret) variants)
1549 ;; (get-char-attribute (car ret) '<-subsumptive)
1550 (setq rest (nconc rest (list (car ret)))))
1551 (setq ret (cdr ret)))))))
1552 (setq rest (cdr rest)))))
1554 (defun insert-char-range-data (min max &optional script excluded-script)
1557 (while (<= code max)
1558 (setq char (decode-char '=ucs code))
1559 (if (encode-char char '=ucs 'defined-only)
1560 (insert-char-data-with-variant char nil 'no-ucs-unified
1561 script excluded-script))
1562 (setq code (1+ code)))))
1564 (defun write-char-range-data-to-file (min max file
1565 &optional script excluded-script)
1566 (let ((coding-system-for-write char-db-file-coding-system))
1568 (insert (format ";; -*- coding: %s -*-\n"
1569 char-db-file-coding-system))
1570 (insert-char-range-data min max script excluded-script)
1571 (write-region (point-min)(point-max) file))))
1573 (defvar what-character-original-window-configuration)
1576 (defun what-char-definition (char)
1577 (interactive (list (char-after)))
1578 (let ((buf (get-buffer-create "*Character Description*"))
1579 (the-buf (current-buffer))
1580 (win-conf (current-window-configuration)))
1582 (make-local-variable 'what-character-original-window-configuration)
1583 (setq what-character-original-window-configuration win-conf)
1584 (setq buffer-read-only nil)
1588 (insert-char-data-with-variant char 'printable)
1589 (unless (char-attribute-alist char)
1590 (insert (format ";; = %c\n"
1591 (let* ((rest (split-char char))
1595 (setq code (logior (lsh code 8)
1597 (decode-char ccs code)))))
1598 ;; (char-db-update-comment)
1599 (set-buffer-modified-p nil)
1600 (view-mode the-buf (lambda (buf)
1601 (set-window-configuration
1602 what-character-original-window-configuration)
1604 (goto-char (point-min)))
1606 (set-window-configuration
1607 what-character-original-window-configuration)
1608 (signal (car err) (cdr err)))))))
1614 (provide 'char-db-util)
1616 ;;; char-db-util.el ends here