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
276 ;; =>ucs@hanyo-denshi
379 =>big5-cdp-itaiji-001
380 =>big5-cdp-itaiji-003
385 =>ucs@iwds-1/normalized
386 =>ucs-itaiji-001@iwds-1
387 =>ucs-itaiji-002@iwds-1
397 ;;; @ char-db formatters
400 (defun char-db-make-char-spec (char)
402 (cond ((characterp char)
403 (cond ((and (setq ret (encode-char char '=ucs 'defined-only))
404 (not (and (<= #xE000 ret)(<= ret #xF8FF))))
405 (setq char-spec (list (cons '=ucs ret)))
406 (cond ((setq ret (get-char-attribute char 'name))
407 (setq char-spec (cons (cons 'name ret) char-spec))
409 ((setq ret (get-char-attribute char 'name*))
410 (setq char-spec (cons (cons 'name* ret) char-spec))
413 ((encode-char char '=mj 'defined-only)
415 (dolist (ccs (charset-list))
416 (if (and (or (eq ccs '=mj)
417 ;; (eq (charset-property ccs 'iso-ir) 177)
418 (string-match "=ucs@" (symbol-name ccs))
420 (setq ccs (charset-name ccs))
421 (null (assq ccs char-spec))
422 (setq ret (encode-char char ccs 'defined-only)))
423 (setq char-spec (cons (cons ccs ret) char-spec))))
425 ((encode-char char '==mj 'defined-only)
427 (dolist (ccs (charset-list))
428 (if (and (or (eq ccs '==mj)
429 ;; (eq (charset-property ccs 'iso-ir) 177)
430 (string-match "=ucs@" (symbol-name ccs))
432 (setq ccs (charset-name ccs))
433 (null (assq ccs char-spec))
434 (setq ret (encode-char char ccs 'defined-only)))
435 (setq char-spec (cons (cons ccs ret) char-spec))))
437 ((encode-char char '=adobe-japan1 'defined-only)
439 (dolist (ccs (charset-list))
440 (if (and (or (memq ccs
449 ;; (eq (charset-property ccs 'iso-ir) 177)
450 (string-match "=ucs@" (symbol-name ccs))
452 (setq ccs (charset-name ccs))
453 (null (assq ccs char-spec))
454 (setq ret (encode-char char ccs 'defined-only)))
455 (setq char-spec (cons (cons ccs ret) char-spec))))
457 ((encode-char char '==adobe-japan1 'defined-only)
459 (dolist (ccs (charset-list))
460 (if (and (or (memq ccs
469 ;; (eq (charset-property ccs 'iso-ir) 177)
470 (string-match "=ucs@" (symbol-name ccs))
472 (setq ccs (charset-name ccs))
473 (null (assq ccs char-spec))
474 (setq ret (encode-char char ccs 'defined-only)))
475 (setq char-spec (cons (cons ccs ret) char-spec))))
479 (let ((rest char-db-coded-charset-priority-list)
482 (setq ccs (charset-name
483 (find-charset (car rest))))
485 (encode-char char ccs
487 (throw 'tag (cons ccs ret)))
488 (setq rest (cdr rest))))))
489 (setq char-spec (list ret))
490 (dolist (ccs (delq (car ret) (charset-list)))
491 (if (and (or (charset-iso-final-char ccs)
498 (and (eq (charset-property ccs 'iso-ir) 177)
499 (not (eq (charset-name ccs) '=ucs@big5)))
500 ;; (string-match "=ucs@" (symbol-name ccs))
502 (setq ccs (charset-name ccs))
503 (null (assq ccs char-spec))
504 (setq ret (encode-char char ccs 'defined-only)))
505 (setq char-spec (cons (cons ccs ret) char-spec))))
507 (setq char-spec (split-char char)))
508 (cond ((setq ret (get-char-attribute char 'name))
509 (setq char-spec (cons (cons 'name ret) char-spec))
511 ((setq ret (get-char-attribute char 'name*))
512 (setq char-spec (cons (cons 'name* ret) char-spec))
515 ((setq ret (get-char-attribute
516 char 'ideographic-combination))
518 (cons (cons 'ideographic-combination ret)
525 (defun char-db-insert-char-spec (char &optional readable column
528 (setq column (current-column)))
529 (let (char-spec temp-char)
530 (setq char-spec (char-db-make-char-spec char))
531 (unless (or (characterp char) ; char
533 (setq char (find-char char-spec))
535 ;; define temporary character
536 ;; Current implementation is dirty.
537 (setq temp-char (define-char (cons '(ideograph-daikanwa . 0)
539 (remove-char-attribute temp-char 'ideograph-daikanwa)
540 (setq char temp-char))
541 (insert-char-attributes char
543 (union (mapcar #'car char-spec)
547 ;; undefine temporary character
548 ;; Current implementation is dirty.
549 (setq char-spec (char-attribute-alist temp-char))
551 (remove-char-attribute temp-char (car (car char-spec)))
552 (setq char-spec (cdr char-spec))))))
554 (defun char-db-insert-alist (alist &optional readable column)
556 (setq column (current-column)))
558 (concat "\n" (make-string (1+ column) ?\ )))
562 lbs cell rest separator)
565 (setq name (car (car alist))
566 value (cdr (car alist)))
567 (cond ((eq name 'char)
569 (if (setq ret (condition-case nil
577 (setq key (car (car value)))
578 ;; (if (find-charset key)
579 ;; (setq cal (cons key cal))
580 (setq al (cons key al))
582 (setq value (cdr value)))
583 (insert-char-attributes ret
587 (insert (prin1-to-string value)))
589 (insert line-breaking))
591 (insert (format "(%-18s " name))
592 (setq lbs (concat "\n" (make-string (current-column) ?\ )))
594 (setq cell (car value))
595 (if (and (consp cell)
597 (setq ret (condition-case nil
607 (setq key (car (car rest)))
608 ;; (if (find-charset key)
609 ;; (setq cal (cons key cal))
610 (setq al (cons key al))
612 (setq rest (cdr rest)))
615 (insert-char-attributes ret
619 (setq separator lbs))
622 (insert (prin1-to-string cell))
623 (setq separator " "))
624 (setq value (cdr value)))
626 (insert line-breaking))
628 (insert (format "(%-18s . %S)%s"
631 (setq alist (cdr alist))))
634 (defun char-db-insert-char-reference (plist &optional readable column)
636 (setq column (current-column)))
638 (concat "\n" (make-string (1+ column) ?\ )))
643 (setq name (pop plist))
644 (setq value (pop plist))
645 (cond ((eq name :char)
648 (cond ((numberp value)
649 (setq value (decode-char '=ucs value)))
651 ;; (setq value (or (find-char value)
654 (char-db-insert-char-spec value readable)
655 (insert line-breaking)
658 (insert (format "%s%s\t%d ; %c%s"
661 (ideographic-radical value)
665 (insert (format "%s%s\t%S" separator name value))
666 (setq separator line-breaking)))
670 (defun char-db-decode-isolated-char (ccs code-point)
673 (cond ((eq ccs 'arabic-iso8859-6)
674 (decode-char ccs code-point))
676 ;; (decode-builtin-char '==gt code-point))
677 ((and (memq ccs '(=gt-pj-1
688 (setq ret (decode-char ccs code-point))
689 (setq ret (encode-char ret '=gt 'defined-only)))
690 (decode-builtin-char '=gt ret))
692 (decode-builtin-char ccs code-point))))
694 (or (decode-char ccs code-point)
695 (define-char (list (cons ccs code-point)))))
696 ((and (<= 0 (char-int ret))
697 (<= (char-int ret) #x1F))
698 (decode-char '=ucs (+ #x2400 (char-int ret))))
699 ((= (char-int ret) #x7F)
703 (defvar char-db-convert-obsolete-format t)
705 (defun char-db-insert-ccs-feature (name value line-breaking)
711 ((memq name '(=>iwds-1
714 =shinjigen@1ed ==shinjigen@1ed
715 =shinjigen@rev ==shinjigen@rev
716 =shinjigen/+p@rev ==shinjigen/+p@rev
717 ===daikanwa/ho ==daikanwa/ho
718 =daikanwa/ho =>>daikanwa/ho =>daikanwa/ho))
719 "(%-18s . %04d)\t; %c")
720 ((eq name '=shinjigen@1ed/24pr)
721 "(%-18s . %04d)\t; %c")
725 ==daikanwa =daikanwa =>>daikanwa =>daikanwa
726 =daikanwa@rev1 =daikanwa@rev2
727 =daikanwa/+p ==daikanwa/+p ===daikanwa/+p
729 =daikanwa/+2p =>>daikanwa/+2p
734 =adobe-japan1-0 ==adobe-japan1-0 ===adobe-japan1-0
735 =adobe-japan1-1 ==adobe-japan1-1 ===adobe-japan1-1
736 =adobe-japan1-2 ==adobe-japan1-2 ===adobe-japan1-2
737 =adobe-japan1-3 ==adobe-japan1-3 ===adobe-japan1-3
738 =adobe-japan1-4 ==adobe-japan1-4 ===adobe-japan1-4
739 =adobe-japan1-5 ==adobe-japan1-5 ===adobe-japan1-5
740 =adobe-japan1-6 ==adobe-japan1-6 ===adobe-japan1-6
741 =>>adobe-japan1-0 =+>adobe-japan1-0
742 =>>adobe-japan1-1 =+>adobe-japan1-1
743 =>>adobe-japan1-2 =+>adobe-japan1-2
744 =>>adobe-japan1-3 =+>adobe-japan1-3
745 =>>adobe-japan1-4 =+>adobe-japan1-4
746 =>>adobe-japan1-5 =+>adobe-japan1-5
747 =>>adobe-japan1-6 =+>adobe-japan1-6
748 =>cbeta =cbeta =>>cbeta ==cbeta ===cbeta
749 =zinbun-oracle =>zinbun-oracle
750 =daijiten ==daijiten ===daijiten ==>daijiten
751 ===hng-jou ===hng-keg ===hng-dng ===hng-mam
752 ===hng-drt ===hng-kgk ===hng-myz ===hng-kda
753 ===hng-khi ===hng-khm ===hng-fhs ===hng-hok
754 ===hng-kyd ===hng-sok
755 ===hng-yhk ===hng-kak ===hng-kar ===hng-kae
756 ===hng-sys ===hng-tsu ===hng-tzj
757 ===hng-hos ===hng-kkh ===hng-nak ===hng-jhk
758 ===hng-hod ===hng-gok ===hng-ink ===hng-nto
759 ===hng-nkm ===hng-k24 ===hng-ini ===hng-nkk
760 ===hng-kcc ===hng-kcj ===hng-kbk ===hng-sik
761 ===hng-skk ===hng-kyu ===hng-ksk ===hng-wan
762 ===hng-okd ===hng-wad ===hng-kmi
763 ===hng-zkd ===hng-doh ===hng-jyu ===hng-tzs
764 ===hng-sai ===hng-kad ===hng-kss
765 ===hng-kyo ===hng-ykk ===hng-saa
766 ===hng-sab ===hng-wks ===hng-wke ===hng-smk
767 ===hng-sgs ===hng-sts
768 =shuowen-jiguge ===shuowen-jiguge4 ===shuowen-jiguge5))
769 ;; (string-match "^=adobe-" (symbol-name name))
771 "(%-18s . %05d)\t; %c")
772 ((memq name '(=hanyo-denshi/ks
773 ==hanyo-denshi/ks ===hanyo-denshi/ks
776 =mj ==mj ===mj =>>mj =>mj
778 "(%-18s . %06d)\t; %c")
779 ((memq name '(=hanyo-denshi/tk ==hanyo-denshi/tk))
780 "(%-18s . %08d)\t; %c")
781 ((>= (charset-dimension name) 2)
782 "(%-18s . #x%04X)\t; %c")
784 "(%-18s . #x%02X)\t; %c"))
786 (if (= (charset-iso-graphic-plane name) 1)
788 (cond ((= (charset-dimension name) 1)
790 ((= (charset-dimension name) 2)
792 ((= (charset-dimension name) 3)
796 (char-db-decode-isolated-char name value)))
797 (if (and (= (charset-chars name) 94)
798 (= (charset-dimension name) 2))
799 (insert (format " [%02d-%02d]"
800 (- (lsh value -8) 32)
801 (- (logand value 255) 32))))
804 (insert (format "(%-18s . %s)" name value))
806 (insert line-breaking))
808 (defun char-db-insert-relation-feature (char name value line-breaking
810 (insert (format "(%-18s%s " name line-breaking))
811 (let ((lbs (concat "\n" (make-string (current-column) ?\ )))
812 separator cell sources required-features
815 (setq cell (car value))
817 (setq cell (decode-char '=ucs cell)))
819 ((eq name '->subsumptive)
820 (when (or (not (some (lambda (atr)
821 (get-char-attribute cell atr))
822 char-db-ignored-attributes))
824 (encode-char cell ccs 'defined-only))
828 (let ((char-db-ignored-attributes
830 char-db-ignored-attributes)))
831 (insert-char-attributes cell readable nil nil 'for-sub-node))
832 (setq separator lbs))
837 char (intern (format "%s*sources" name))))
838 (setq required-features nil)
839 (dolist (source sources)
843 shinjigen shinjigen@1ed shinjigen@rev))
844 (setq required-features
845 (union required-features
857 =shinjigen/+p@rev))))
859 (setq required-features
860 (union required-features
865 ((find-charset (setq ret (intern (format "=%s" source))))
866 (setq required-features
867 (cons ret required-features)))
868 (t (setq required-features
869 (cons source required-features)))))
870 (cond ((string-match "@JP" (symbol-name name))
871 (setq required-features
872 (union required-features
880 ((string-match "@CN" (symbol-name name))
881 (setq required-features
882 (union required-features
889 (insert (format "%S" cell))
890 (char-db-insert-char-spec cell readable
893 (setq separator lbs))
897 (if (consp (car cell))
898 (char-db-insert-char-spec cell readable)
899 (char-db-insert-char-reference cell readable))
900 (setq separator lbs))
904 (insert (prin1-to-string cell))
905 (setq separator " ")))
906 (setq value (cdr value)))
908 (insert line-breaking)))
910 (defun insert-char-attributes (char &optional readable attributes column
913 (setq column (current-column)))
914 (let (name value ; has-long-ccs-name
918 (concat "\n" (make-string (1+ column) ?\ )))
919 lbs cell separator ret
921 dest-ccss ; sources required-features
926 (if (consp attributes)
928 (dolist (name attributes)
929 (unless (memq name char-db-ignored-attributes)
930 (if (find-charset name)
934 (dolist (name (char-attribute-list))
935 (unless (memq name char-db-ignored-attributes)
936 (if (find-charset name)
940 #'char-attribute-name<)))
942 (when (memq '<-subsumptive attributes)
943 (when (or readable (not for-sub-node))
944 (when (setq value (get-char-attribute char '<-subsumptive))
945 (char-db-insert-relation-feature char '<-subsumptive value
948 (setq attributes (delq '<-subsumptive attributes)))
949 (when (and (memq '<-denotational attributes)
950 (setq value (get-char-attribute char '<-denotational)))
951 (char-db-insert-relation-feature char '<-denotational value
954 (setq attributes (delq '<-denotational attributes)))
955 (when (and (memq '<-denotational@component attributes)
956 (setq value (get-char-attribute char '<-denotational@component)))
957 (char-db-insert-relation-feature char '<-denotational@component value
960 (setq attributes (delq '<-denotational@component attributes)))
961 (when (and (memq '<-denotational@usage attributes)
962 (setq value (get-char-attribute char '<-denotational@usage)))
963 (char-db-insert-relation-feature char '<-denotational@usage value
966 (setq attributes (delq '<-denotational@usage attributes)))
967 (when (and (memq 'name attributes)
968 (setq value (get-char-attribute char 'name)))
970 (if (> (+ (current-column) (length value)) 48)
973 value line-breaking))
974 (setq attributes (delq 'name attributes))
976 (when (and (memq 'name* attributes)
977 (setq value (get-char-attribute char 'name*)))
979 (if (> (+ (current-column) (length value)) 48)
982 value line-breaking))
983 (setq attributes (delq 'name* attributes))
985 (when (and (memq 'script attributes)
986 (setq value (get-char-attribute char 'script)))
987 (insert (format "(script\t\t%s)%s"
988 (mapconcat (function prin1-to-string)
991 (setq attributes (delq 'script attributes))
993 (dolist (name '(=>ucs =>ucs*))
994 (when (and (memq name attributes)
995 (setq value (get-char-attribute char name)))
996 (insert (format "(%-18s . #x%04X)\t; %c%s"
997 name value (decode-char '=ucs value)
999 (setq attributes (delq name attributes))))
1000 (dolist (name '(=>ucs@gb =>ucs@big5))
1001 (when (and (memq name attributes)
1002 (setq value (get-char-attribute char name)))
1003 (insert (format "(%-18s . #x%04X)\t; %c%s"
1005 (decode-char (intern
1008 (symbol-name name) 2)))
1011 (setq attributes (delq name attributes))
1013 ;; (dolist (name '(=>daikanwa))
1014 ;; (when (and (memq name attributes)
1015 ;; (setq value (get-char-attribute char name)))
1017 ;; (if (integerp value)
1018 ;; (format "(%-18s . %05d)\t; %c%s"
1019 ;; name value (decode-char '=daikanwa value)
1021 ;; (format "(%-18s %s)\t; %c%s"
1023 ;; (mapconcat (function prin1-to-string)
1025 ;; (char-representative-of-daikanwa char)
1027 ;; (setq attributes (delq name attributes))))
1028 (when (and (memq 'general-category attributes)
1029 (setq value (get-char-attribute char 'general-category)))
1031 "(general-category\t%s) ; %s%s"
1032 (mapconcat (lambda (cell)
1035 (cond ((rassoc value unidata-normative-category-alist)
1036 "Normative Category")
1037 ((rassoc value unidata-informative-category-alist)
1038 "Informative Category")
1040 "Unknown Category"))
1042 (setq attributes (delq 'general-category attributes))
1044 (when (and (memq 'bidi-category attributes)
1045 (setq value (get-char-attribute char 'bidi-category)))
1046 (insert (format "(bidi-category\t. %S)%s"
1049 (setq attributes (delq 'bidi-category attributes))
1051 (unless (or (not (memq 'mirrored attributes))
1052 (eq (setq value (get-char-attribute char 'mirrored 'empty))
1054 (insert (format "(mirrored\t\t. %S)%s"
1057 (setq attributes (delq 'mirrored attributes))
1060 ((and (memq 'decimal-digit-value attributes)
1061 (setq value (get-char-attribute char 'decimal-digit-value)))
1062 (insert (format "(decimal-digit-value . %S)%s"
1065 (setq attributes (delq 'decimal-digit-value attributes))
1066 (when (and (memq 'digit-value attributes)
1067 (setq value (get-char-attribute char 'digit-value)))
1068 (insert (format "(digit-value\t . %S)%s"
1071 (setq attributes (delq 'digit-value attributes))
1073 (when (and (memq 'numeric-value attributes)
1074 (setq value (get-char-attribute char 'numeric-value)))
1075 (insert (format "(numeric-value\t . %S)%s"
1078 (setq attributes (delq 'numeric-value attributes))
1082 (when (and (memq 'digit-value attributes)
1083 (setq value (get-char-attribute char 'digit-value)))
1084 (insert (format "(digit-value\t. %S)%s"
1087 (setq attributes (delq 'digit-value attributes))
1089 (when (and (memq 'numeric-value attributes)
1090 (setq value (get-char-attribute char 'numeric-value)))
1091 (insert (format "(numeric-value\t. %S)%s"
1094 (setq attributes (delq 'numeric-value attributes))
1096 (when (and (memq 'iso-10646-comment attributes)
1097 (setq value (get-char-attribute char 'iso-10646-comment)))
1098 (insert (format "(iso-10646-comment\t. %S)%s"
1101 (setq attributes (delq 'iso-10646-comment attributes))
1103 (when (and (memq 'morohashi-daikanwa attributes)
1104 (setq value (get-char-attribute char 'morohashi-daikanwa)))
1105 (insert (format "(morohashi-daikanwa\t%s)%s"
1106 (mapconcat (function prin1-to-string) value " ")
1108 (setq attributes (delq 'morohashi-daikanwa attributes))
1112 (when (and (memq 'ideographic-radical attributes)
1113 (setq value (get-char-attribute char 'ideographic-radical)))
1114 (setq radical value)
1115 (insert (format "(ideographic-radical . %S)\t; %c%s"
1117 (ideographic-radical radical)
1119 (setq attributes (delq 'ideographic-radical attributes))
1121 (when (and (memq 'shuowen-radical attributes)
1122 (setq value (get-char-attribute char 'shuowen-radical)))
1123 (insert (format "(shuowen-radical\t. %S)\t; %c%s"
1125 (shuowen-radical value)
1127 (setq attributes (delq 'shuowen-radical attributes))
1132 char-db-feature-domains
1134 (dolist (feature (char-attribute-list))
1135 (setq feature (symbol-name feature))
1137 "\\(radical\\|strokes\\)@\\([^@*]+\\)\\(\\*\\|$\\)"
1139 (setq domain (intern (match-string 2 feature)))
1140 (unless (memq domain dest)
1141 (setq dest (cons domain dest)))))
1142 (sort dest #'string<))))
1143 (setq key (intern (format "%s@%s" 'ideographic-radical domain)))
1144 (when (and (memq key attributes)
1145 (setq value (get-char-attribute char key)))
1146 (setq radical value)
1147 (insert (format "(%s . %S)\t; %c%s"
1150 (ideographic-radical radical)
1152 (setq attributes (delq key attributes))
1154 (setq key (intern (format "%s@%s" 'ideographic-strokes domain)))
1155 (when (and (memq key attributes)
1156 (setq value (get-char-attribute char key)))
1157 (setq strokes value)
1158 (insert (format "(%s . %S)%s"
1162 (setq attributes (delq key attributes))
1164 (setq key (intern (format "%s@%s" 'total-strokes domain)))
1165 (when (and (memq key attributes)
1166 (setq value (get-char-attribute char key)))
1167 (insert (format "(%s . %S)%s"
1171 (setq attributes (delq key attributes))
1173 (dolist (feature '(ideographic-radical
1176 (setq key (intern (format "%s@%s*sources" feature domain)))
1177 (when (and (memq key attributes)
1178 (setq value (get-char-attribute char key)))
1179 (insert (format "(%s%s" key line-breaking))
1180 (dolist (cell value)
1181 (insert (format " %s" cell)))
1183 (insert line-breaking)
1184 (setq attributes (delq key attributes))
1187 (when (and (memq 'ideographic-strokes attributes)
1188 (setq value (get-char-attribute char 'ideographic-strokes)))
1189 (setq strokes value)
1190 (insert (format "(ideographic-strokes . %S)%s"
1193 (setq attributes (delq 'ideographic-strokes attributes))
1195 (when (and (memq 'kangxi-radical attributes)
1196 (setq value (get-char-attribute char 'kangxi-radical)))
1197 (unless (eq value radical)
1198 (insert (format "(kangxi-radical\t . %S)\t; %c%s"
1200 (ideographic-radical value)
1203 (setq radical value)))
1204 (setq attributes (delq 'kangxi-radical attributes))
1206 (when (and (memq 'kangxi-strokes attributes)
1207 (setq value (get-char-attribute char 'kangxi-strokes)))
1208 (unless (eq value strokes)
1209 (insert (format "(kangxi-strokes\t . %S)%s"
1213 (setq strokes value)))
1214 (setq attributes (delq 'kangxi-strokes attributes))
1216 ;; (when (and (memq 'japanese-radical attributes)
1217 ;; (setq value (get-char-attribute char 'japanese-radical)))
1218 ;; (unless (eq value radical)
1219 ;; (insert (format "(japanese-radical\t . %S)\t; %c%s"
1221 ;; (ideographic-radical value)
1224 ;; (setq radical value)))
1225 ;; (setq attributes (delq 'japanese-radical attributes))
1227 (when (and (memq 'japanese-strokes attributes)
1228 (setq value (get-char-attribute char 'japanese-strokes)))
1229 (unless (eq value strokes)
1230 (insert (format "(japanese-strokes\t . %S)%s"
1234 (setq strokes value)))
1235 (setq attributes (delq 'japanese-strokes attributes))
1237 (when (and (memq 'cns-radical attributes)
1238 (setq value (get-char-attribute char 'cns-radical)))
1239 (insert (format "(cns-radical\t . %S)\t; %c%s"
1241 (ideographic-radical value)
1243 (setq attributes (delq 'cns-radical attributes))
1245 (when (and (memq 'cns-strokes attributes)
1246 (setq value (get-char-attribute char 'cns-strokes)))
1247 (unless (eq value strokes)
1248 (insert (format "(cns-strokes\t . %S)%s"
1252 (setq strokes value)))
1253 (setq attributes (delq 'cns-strokes attributes))
1255 ;; (when (and (memq 'ideographic- attributes)
1256 ;; (setq value (get-char-attribute char 'ideographic-)))
1257 ;; (insert "(ideographic- ")
1258 ;; (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1260 ;; (while (consp value)
1261 ;; (setq cell (car value))
1262 ;; (if (integerp cell)
1263 ;; (setq cell (decode-char '=ucs cell)))
1264 ;; (cond ((characterp cell)
1268 ;; (insert (format "%S" cell))
1269 ;; (char-db-insert-char-spec cell readable))
1270 ;; (setq separator lbs))
1274 ;; (if (consp (car cell))
1275 ;; (char-db-insert-char-spec cell readable)
1276 ;; (char-db-insert-char-reference cell readable))
1277 ;; (setq separator lbs))
1280 ;; (insert separator))
1281 ;; (insert (prin1-to-string cell))
1282 ;; (setq separator " ")))
1283 ;; (setq value (cdr value)))
1285 ;; (insert line-breaking)
1286 ;; (setq attributes (delq 'ideographic- attributes)))
1287 (when (and (memq 'total-strokes attributes)
1288 (setq value (get-char-attribute char 'total-strokes)))
1289 (insert (format "(total-strokes . %S)%s"
1292 (setq attributes (delq 'total-strokes attributes))
1294 ;; (when (and (memq '->ideograph attributes)
1295 ;; (setq value (get-char-attribute char '->ideograph)))
1296 ;; (insert (format "(->ideograph\t%s)%s"
1297 ;; (mapconcat (lambda (code)
1298 ;; (cond ((symbolp code)
1299 ;; (symbol-name code))
1301 ;; (format "#x%04X" code))
1304 ;; line-breaking code))))
1307 ;; (setq attributes (delq '->ideograph attributes))
1309 ;; (when (and (memq '->decomposition attributes)
1310 ;; (setq value (get-char-attribute char '->decomposition)))
1311 ;; (insert (format "(->decomposition\t%s)%s"
1312 ;; (mapconcat (lambda (code)
1313 ;; (cond ((symbolp code)
1314 ;; (symbol-name code))
1315 ;; ((characterp code)
1317 ;; (format "%S" code)
1322 ;; (format "#x%04X" code))
1324 ;; (format "%s%S" line-breaking code))))
1327 ;; (setq attributes (delq '->decomposition attributes))
1329 (if (equal (get-char-attribute char '->titlecase)
1330 (get-char-attribute char '->uppercase))
1331 (setq attributes (delq '->titlecase attributes)))
1332 (when (and (memq '->mojikyo attributes)
1333 (setq value (get-char-attribute char '->mojikyo)))
1334 (insert (format "(->mojikyo\t\t. %06d)\t; %c%s"
1335 value (decode-char 'mojikyo value)
1337 (setq attributes (delq '->mojikyo attributes))
1340 (dolist (ignored '(composition
1341 ->denotational <-subsumptive ->ucs-unified
1342 ;; ->ideographic-component-forms
1344 (setq attributes (delq ignored attributes))))
1346 (setq name (car attributes))
1347 (unless (eq (setq value (get-char-attribute char name 'value-is-empty))
1349 (cond ((setq ret (find-charset name))
1350 (setq name (charset-name ret))
1351 (when (not (memq name dest-ccss))
1352 (setq dest-ccss (cons name dest-ccss))
1353 (char-db-insert-ccs-feature name value line-breaking))
1355 ((string-match "^=>ucs@" (symbol-name name))
1356 (insert (format "(%-18s . #x%04X)\t; %c%s"
1357 name value (decode-char '=ucs value)
1360 ((eq name 'jisx0208-1978/4X)
1361 (insert (format "(%-18s . #x%04X)%s"
1367 (not (eq name '->subsumptive))
1368 (not (eq name '->uppercase))
1369 (not (eq name '->lowercase))
1370 (not (eq name '->titlecase))
1371 (not (eq name '->canonical))
1372 (not (eq name '->Bopomofo))
1373 (not (eq name '->mistakable))
1374 (not (eq name '->ideographic-variants))
1375 (null (get-char-attribute
1376 char (intern (format "%s*sources" name))))
1377 (not (string-match "\\*sources$" (symbol-name name)))
1378 (null (get-char-attribute
1379 char (intern (format "%s*note" name))))
1380 (not (string-match "\\*note$" (symbol-name name)))
1381 (or (eq name '<-identical)
1382 (eq name '<-uppercase)
1383 (eq name '<-lowercase)
1384 (eq name '<-titlecase)
1385 (eq name '<-canonical)
1386 (eq name '<-ideographic-variants)
1387 ;; (eq name '<-synonyms)
1388 (string-match "^<-synonyms" (symbol-name name))
1389 (eq name '<-mistakable)
1390 (when (string-match "^->" (symbol-name name))
1392 ((string-match "^->fullwidth" (symbol-name name))
1393 (not (and (consp value)
1394 (characterp (car value))
1396 (car value) '=ucs 'defined-only)))
1401 ((or (eq name 'ideographic-structure)
1402 (eq name 'ideographic-combination)
1403 ;; (eq name 'ideographic-)
1404 (eq name '=decomposition)
1405 (char-feature-base-name= '=decomposition name)
1406 (char-feature-base-name= '=>decomposition name)
1407 ;; (string-match "^=>*decomposition\\(@[^*]+\\)?$"
1408 ;; (symbol-name name))
1409 (string-match "^\\(->\\|<-\\)[^*]*$" (symbol-name name))
1410 (string-match "^\\(->\\|<-\\)[^*]*\\*sources$"
1413 (char-db-insert-relation-feature char name value
1416 ;; ((memq name '(ideograph=
1417 ;; original-ideograph-of
1418 ;; ancient-ideograph-of
1419 ;; vulgar-ideograph-of
1420 ;; wrong-ideograph-of
1421 ;; ;; simplified-ideograph-of
1422 ;; ideographic-variants
1423 ;; ;; ideographic-different-form-of
1425 ;; (insert (format "(%-18s%s " name line-breaking))
1426 ;; (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1428 ;; (while (consp value)
1429 ;; (setq cell (car value))
1430 ;; (if (and (consp cell)
1431 ;; (consp (car cell)))
1435 ;; (char-db-insert-alist cell readable)
1436 ;; (setq separator lbs))
1438 ;; (insert separator))
1439 ;; (insert (prin1-to-string cell))
1440 ;; (setq separator " "))
1441 ;; (setq value (cdr value)))
1443 ;; (insert line-breaking))
1445 (insert (format "(%-18s " name))
1446 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1448 (while (consp value)
1449 (setq cell (car value))
1450 (if (and (consp cell)
1452 (setq ret (condition-case nil
1460 (setq key (car (car rest)))
1461 (if (find-charset key)
1462 (setq cal (cons key cal))
1463 (setq al (cons key al)))
1464 (setq rest (cdr rest)))
1467 (insert-char-attributes ret
1471 (setq separator lbs))
1472 (setq ret (prin1-to-string cell))
1474 (if (< (+ (current-column)
1481 (setq separator " "))
1482 (setq value (cdr value)))
1484 (insert line-breaking))
1486 (insert (format "(%-18s" name))
1487 (setq ret (prin1-to-string value))
1488 (unless (< (+ (current-column)
1492 (insert line-breaking))
1493 (insert " . " ret ")" line-breaking)
1494 ;; (insert (format "(%-18s . %S)%s"
1499 (setq attributes (cdr attributes)))
1502 (defun insert-char-data (char &optional readable
1505 (narrow-to-region (point)(point))
1506 (insert "(define-char
1508 (insert-char-attributes char readable attributes)
1510 (goto-char (point-min))
1511 (while (re-search-forward "[ \t]+$" nil t)
1514 (goto-char (point-min))
1515 (while (re-search-forward "[ \t][ \t][ \t]*" nil t)
1516 (let ((column (current-column))
1517 (indent-tabs-mode t))
1518 (delete-region (match-beginning 0) (point))
1519 (indent-to column)))
1520 (goto-char (point-max))
1521 ;; (tabify (point-min)(point-max))
1524 (defun insert-char-data-with-variant (char &optional printable
1526 script excluded-script)
1527 (insert-char-data char printable)
1528 (let ((variants (char-variants char))
1531 (setq variants (sort variants #'<))
1532 (setq rest variants)
1533 (setq variants (cons char variants))
1535 (setq variant (car rest))
1536 (unless (get-char-attribute variant '<-subsumptive)
1537 (if (and (or (null script)
1538 (null (setq vs (get-char-attribute variant 'script)))
1540 (or (null excluded-script)
1541 (null (setq vs (get-char-attribute variant 'script)))
1542 (not (memq excluded-script vs))))
1543 (unless (and no-ucs-unified (get-char-attribute variant '=ucs))
1544 (insert-char-data variant printable)
1545 (if (setq ret (char-variants variant))
1547 (or (memq (car ret) variants)
1548 ;; (get-char-attribute (car ret) '<-subsumptive)
1549 (setq rest (nconc rest (list (car ret)))))
1550 (setq ret (cdr ret)))))))
1551 (setq rest (cdr rest)))))
1553 (defun insert-char-range-data (min max &optional script excluded-script)
1556 (while (<= code max)
1557 (setq char (decode-char '=ucs code))
1558 (if (encode-char char '=ucs 'defined-only)
1559 (insert-char-data-with-variant char nil 'no-ucs-unified
1560 script excluded-script))
1561 (setq code (1+ code)))))
1563 (defun write-char-range-data-to-file (min max file
1564 &optional script excluded-script)
1565 (let ((coding-system-for-write char-db-file-coding-system))
1567 (insert (format ";; -*- coding: %s -*-\n"
1568 char-db-file-coding-system))
1569 (insert-char-range-data min max script excluded-script)
1570 (write-region (point-min)(point-max) file))))
1572 (defvar what-character-original-window-configuration)
1575 (defun what-char-definition (char)
1576 (interactive (list (char-after)))
1577 (let ((buf (get-buffer-create "*Character Description*"))
1578 (the-buf (current-buffer))
1579 (win-conf (current-window-configuration)))
1581 (make-local-variable 'what-character-original-window-configuration)
1582 (setq what-character-original-window-configuration win-conf)
1583 (setq buffer-read-only nil)
1587 (insert-char-data-with-variant char 'printable)
1588 (unless (char-attribute-alist char)
1589 (insert (format ";; = %c\n"
1590 (let* ((rest (split-char char))
1594 (setq code (logior (lsh code 8)
1596 (decode-char ccs code)))))
1597 ;; (char-db-update-comment)
1598 (set-buffer-modified-p nil)
1599 (view-mode the-buf (lambda (buf)
1600 (set-window-configuration
1601 what-character-original-window-configuration)
1603 (goto-char (point-min)))
1605 (set-window-configuration
1606 what-character-original-window-configuration)
1607 (signal (car err) (cdr err)))))))
1613 (provide 'char-db-util)
1615 ;;; char-db-util.el ends here