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 MORIOKA Tomohiko.
6 ;; Author: MORIOKA Tomohiko <tomo@kanji.zinbun.kyoto-u.ac.jp>
7 ;; Keywords: CHISE, Character Database, ISO/IEC 10646, UCS, Unicode, MULE.
9 ;; This file is part of XEmacs CHISE.
11 ;; XEmacs CHISE is free software; you can redistribute it and/or
12 ;; modify it under the terms of the GNU General Public License as
13 ;; published by the Free Software Foundation; either version 2, or (at
14 ;; your option) any later version.
16 ;; XEmacs CHISE is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 ;; General Public License for more details.
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with XEmacs CHISE; see the file COPYING. If not, write to
23 ;; the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
24 ;; Boston, MA 02111-1307, USA.
29 (require 'ideograph-subr)
31 (defconst unidata-normative-category-alist
32 '(("Lu" letter uppercase)
33 ("Ll" letter lowercase)
34 ("Lt" letter titlecase)
35 ("Mn" mark non-spacing)
36 ("Mc" mark spacing-combining)
38 ("Nd" number decimal-digit)
41 ("Zs" separator space)
43 ("Zp" separator paragraph)
46 ("Cs" other surrogate)
47 ("Co" other private-use)
48 ("Cn" other not-assigned)))
50 (defconst unidata-informative-category-alist
51 '(("Lm" letter modifier)
53 ("Pc" punctuation connector)
54 ("Pd" punctuation dash)
55 ("Ps" punctuation open)
56 ("Pe" punctuation close)
57 ("Pi" punctuation initial-quote)
58 ("Pf" punctuation final-quote)
59 ("Po" punctuation other)
61 ("Sc" symbol currency)
62 ("Sk" symbol modifier)
66 (defconst shuowen-radicals
67 [?一 ?上 ?示 ?三 ?王 ?玉 ?玨 ?气 ?士 ?丨 ; 010
68 ?屮 ?艸 ?蓐 ?茻 ?小 ?八 ?釆 ?半 ?牛 ?犛 ; 020
69 ?告 ?口 ?凵 ?吅 ?哭 ?走 ?止 ?癶 ?步 ?此 ; 030
70 ?正 ?是 ?辵 ?彳 ?廴 ?㢟 ?行 ?齒 ?牙 ?足 ; 040
71 ?疋 ?品 ?龠 ?冊 ?㗊 ?舌 ?干 ?谷 ?只 ?㕯 ; 050
72 ?句 ?丩 ?古 ?十 ?卅 ?言 ?誩 ?音 ?䇂 ?丵 ; 060
73 ?菐 ?𠬞 ?𠬜 ?共 ?異 ?舁 ?𦥑 ?䢅 ?爨 ?革 ; 070
74 ?鬲 ?䰜 ?爪 ?𠃨 ?鬥 ?又 ?𠂇 ?㕜 ?支 ?𦘒 ; 080
75 ?聿 ?畫 ?隶 ?臤 ?臣 ?殳 ?殺 ?𠘧 ?寸 ?皮 ; 090
76 ?㼱 ?攴 ?敎 ?卜 ?用 ?爻 ?㸚 ?𥄎 ?目 ?䀠 ; 100
77 ?眉 ?盾 ?自 ?白 ?鼻 ?皕 ?習 ?羽 ?隹 ?奞 ; 110
78 ?萑 ?𦫳 ?苜 ?羊 ?羴 ?瞿 ?雔 ?雥 ?鳥 ?烏 ; 120
79 ?𠦒 ?冓 ?幺 ?𢆶 ?叀 ?玄 ?予 ?放 ?𠬪 ?𣦼 ; 130
80 ?歺 ?死 ?冎 ?骨 ?肉 ?筋 ?刀 ?刃 ?㓞 ?丰 ; 140
81 ?耒 ?𧢲 ?竹 ?箕 ?丌 ?左 ?工 ?㠭 ?巫 ?甘 ; 150
82 ?曰 ?乃 ?丂 ?可 ?兮 ?号 ?亏 ?旨 ?喜 ?壴 ; 160
83 ; ?旨 ?曰 ?乃 ?丂 ?可 ?兮 ?号 ?亏 ?喜 ?壴 ; 160
84 ?鼓 ?豈 ?豆 ?豊 ?豐 ?䖒 ?虍 ?虎 ?虤 ?皿 ; 170
85 ?𠙴 ?去 ?血 ?丶 ?丹 ?青 ?井 ?皀 ?鬯 ?食 ; 180
86 ?亼 ?會 ?倉 ?入 ?缶 ?矢 ?高 ?冂 ?𩫏 ?京 ; 190
87 ?亯 ?𣆪 ?畗 ?㐭 ?嗇 ?來 ?麥 ?夊 ?舛 ?䑞 ; 200
88 ?韋 ?弟 ?夂 ?久 ?桀 ?木 ?東 ?林 ?才 ?叒 ; 210
89 ?之 ?帀 ?出 ?𣎵 ?生 ?乇 ?𠂹 ?𠌶 ?華 ?𥝌 ; 220
90 ?稽 ?巢 ?桼 ?束 ?㯻 ?囗 ?員 ?貝 ?邑 ?𨛜 ; 230
91 ?日 ?旦 ?倝 ?㫃 ?冥 ?晶 ?月 ?有 ?明 ?囧 ; 240
92 ?夕 ?多 ?毌 ?𢎘 ?𣐺 ?卣 ?齊 ?朿 ?片 ?鼎 ; 250
93 ?克 ?彔 ?禾 ?秝 ?黍 ?香 ?米 ?毇 ?臼 ?凶 ; 260
94 ?𣎳 ?林 ?麻 ?尗 ?耑 ?韭 ?瓜 ?瓠 ?宀 ?宮 ; 270
95 ?呂 ?穴 ?㝱 ?𤕫 ?冖 ?𠔼 ?冃 ?㒳 ?网 ?襾 ; 280
96 ?巾 ?巿 ?帛 ?白 ?㡀 ?黹 ?人 ?𠤎 ?匕 ?从 ; 290
97 ?比 ?北 ?丘 ?㐺 ?𡈼 ?重 ?臥 ?身 ?㐆 ?衣 ; 300
98 ?裘 ?老 ?毛 ?毳 ?尸 ?尺 ?尾 ?履 ?舟 ?方 ; 310
99 ?儿 ?兄 ?兂 ?皃 ?𠑹 ?先 ?秃 ?見 ?覞 ?欠 ; 320
100 ?㱃 ?㳄 ?旡 ?頁 ?𦣻 ?面 ?丏 ?首 ?𥄉 ?須 ; 330
101 ?彡 ?彣 ?文 ?髟 ?后 ?司 ?卮 ?卩 ?印 ?色 ; 340
102 ?𠨍 ?辟 ?勹 ?包 ?茍 ?鬼 ?甶 ?厶 ?嵬 ?山 ; 350
103 ?屾 ?屵 ?广 ?厂 ?丸 ?危 ?石 ?長 ?勿 ?冄 ; 360
104 ?而 ?豕 ?㣇 ?彑 ?豚 ?豸 ?𤉡 ?易 ?象 ?馬 ; 370
105 ?𢊁 ?鹿 ?麤 ?㲋 ?兔 ?萈 ?犬 ?㹜 ?鼠 ?能 ; 380
106 ?熊 ?火 ?炎 ?黑 ?囪 ?焱 ?炙 ?赤 ?大 ?亦 ; 390
109 (defun shuowen-radical (number)
110 (aref shuowen-radicals (1- number)))
112 (defvar char-db-file-coding-system 'utf-8-mcs-er)
114 (defvar char-db-ignored-attributes '(ideographic-products))
116 (defvar char-db-coded-charset-priority-list
212 ;; =>>>adobe-japan1-0
213 ;; =>>>adobe-japan1-1
214 ;; =>>>adobe-japan1-2
215 ;; =>>>adobe-japan1-3
216 ;; =>>>adobe-japan1-4
217 ;; =>>>adobe-japan1-5
218 ;; =>>>adobe-japan1-6
222 ;; =>>>hanyo-denshi/ja
223 ;; =>>>hanyo-denshi/jb
224 ;; =>>>hanyo-denshi/jc
225 ;; =>>>hanyo-denshi/ft
226 ;; =>>>hanyo-denshi/ib
227 ;; =>>>hanyo-denshi/hg
228 ;; =>>>hanyo-denshi/jt
229 ;; =>>>hanyo-denshi/ks
352 ;;; @ char-db formatters
355 (defun char-db-make-char-spec (char)
357 (cond ((characterp char)
358 (cond ((and (setq ret (encode-char char '=ucs 'defined-only))
359 (not (and (<= #xE000 ret)(<= ret #xF8FF))))
360 (setq char-spec (list (cons '=ucs ret)))
361 (cond ((setq ret (get-char-attribute char 'name))
362 (setq char-spec (cons (cons 'name ret) char-spec))
364 ((setq ret (get-char-attribute char 'name*))
365 (setq char-spec (cons (cons 'name* ret) char-spec))
368 ((encode-char char '=mj 'defined-only)
370 (dolist (ccs (charset-list))
371 (if (and (or (eq ccs '=mj)
372 ;; (eq (charset-property ccs 'iso-ir) 177)
373 (string-match "=ucs@" (symbol-name ccs))
375 (setq ccs (charset-name ccs))
376 (null (assq ccs char-spec))
377 (setq ret (encode-char char ccs 'defined-only)))
378 (setq char-spec (cons (cons ccs ret) char-spec))))
380 ((encode-char char '==mj 'defined-only)
382 (dolist (ccs (charset-list))
383 (if (and (or (eq ccs '==mj)
384 ;; (eq (charset-property ccs 'iso-ir) 177)
385 (string-match "=ucs@" (symbol-name ccs))
387 (setq ccs (charset-name ccs))
388 (null (assq ccs char-spec))
389 (setq ret (encode-char char ccs 'defined-only)))
390 (setq char-spec (cons (cons ccs ret) char-spec))))
392 ((encode-char char '=adobe-japan1 'defined-only)
394 (dolist (ccs (charset-list))
395 (if (and (or (memq ccs
404 ;; (eq (charset-property ccs 'iso-ir) 177)
405 (string-match "=ucs@" (symbol-name ccs))
407 (setq ccs (charset-name ccs))
408 (null (assq ccs char-spec))
409 (setq ret (encode-char char ccs 'defined-only)))
410 (setq char-spec (cons (cons ccs ret) char-spec))))
412 ((encode-char char '==adobe-japan1 'defined-only)
414 (dolist (ccs (charset-list))
415 (if (and (or (memq ccs
424 ;; (eq (charset-property ccs 'iso-ir) 177)
425 (string-match "=ucs@" (symbol-name ccs))
427 (setq ccs (charset-name ccs))
428 (null (assq ccs char-spec))
429 (setq ret (encode-char char ccs 'defined-only)))
430 (setq char-spec (cons (cons ccs ret) char-spec))))
434 (let ((rest char-db-coded-charset-priority-list)
437 (setq ccs (charset-name
438 (find-charset (car rest))))
440 (encode-char char ccs
442 (throw 'tag (cons ccs ret)))
443 (setq rest (cdr rest))))))
444 (setq char-spec (list ret))
445 (dolist (ccs (delq (car ret) (charset-list)))
446 (if (and (or (charset-iso-final-char ccs)
453 (eq (charset-property ccs 'iso-ir) 177)
454 ;; (string-match "=ucs@" (symbol-name ccs))
456 (setq ccs (charset-name ccs))
457 (null (assq ccs char-spec))
458 (setq ret (encode-char char ccs 'defined-only)))
459 (setq char-spec (cons (cons ccs ret) char-spec))))
461 (setq char-spec (split-char char)))
462 (cond ((setq ret (get-char-attribute char 'name))
463 (setq char-spec (cons (cons 'name ret) char-spec))
465 ((setq ret (get-char-attribute char 'name*))
466 (setq char-spec (cons (cons 'name* ret) char-spec))
469 ((setq ret (get-char-attribute
470 char 'ideographic-combination))
472 (cons (cons 'ideographic-combination ret)
479 (defun char-db-insert-char-spec (char &optional readable column
482 (setq column (current-column)))
483 (let (char-spec temp-char)
484 (setq char-spec (char-db-make-char-spec char))
485 (unless (or (characterp char) ; char
487 (setq char (find-char char-spec))
489 ;; define temporary character
490 ;; Current implementation is dirty.
491 (setq temp-char (define-char (cons '(ideograph-daikanwa . 0)
493 (remove-char-attribute temp-char 'ideograph-daikanwa)
494 (setq char temp-char))
495 (insert-char-attributes char
497 (union (mapcar #'car char-spec)
501 ;; undefine temporary character
502 ;; Current implementation is dirty.
503 (setq char-spec (char-attribute-alist temp-char))
505 (remove-char-attribute temp-char (car (car char-spec)))
506 (setq char-spec (cdr char-spec))))))
508 (defun char-db-insert-alist (alist &optional readable column)
510 (setq column (current-column)))
512 (concat "\n" (make-string (1+ column) ?\ )))
516 lbs cell rest separator)
519 (setq name (car (car alist))
520 value (cdr (car alist)))
521 (cond ((eq name 'char)
523 (if (setq ret (condition-case nil
531 (setq key (car (car value)))
532 ;; (if (find-charset key)
533 ;; (setq cal (cons key cal))
534 (setq al (cons key al))
536 (setq value (cdr value)))
537 (insert-char-attributes ret
541 (insert (prin1-to-string value)))
543 (insert line-breaking))
545 (insert (format "(%-18s " name))
546 (setq lbs (concat "\n" (make-string (current-column) ?\ )))
548 (setq cell (car value))
549 (if (and (consp cell)
551 (setq ret (condition-case nil
561 (setq key (car (car rest)))
562 ;; (if (find-charset key)
563 ;; (setq cal (cons key cal))
564 (setq al (cons key al))
566 (setq rest (cdr rest)))
569 (insert-char-attributes ret
573 (setq separator lbs))
576 (insert (prin1-to-string cell))
577 (setq separator " "))
578 (setq value (cdr value)))
580 (insert line-breaking))
582 (insert (format "(%-18s . %S)%s"
585 (setq alist (cdr alist))))
588 (defun char-db-insert-char-reference (plist &optional readable column)
590 (setq column (current-column)))
592 (concat "\n" (make-string (1+ column) ?\ )))
597 (setq name (pop plist))
598 (setq value (pop plist))
599 (cond ((eq name :char)
602 (cond ((numberp value)
603 (setq value (decode-char '=ucs value)))
605 ;; (setq value (or (find-char value)
608 (char-db-insert-char-spec value readable)
609 (insert line-breaking)
612 (insert (format "%s%s\t%d ; %c%s"
615 (ideographic-radical value)
619 (insert (format "%s%s\t%S" separator name value))
620 (setq separator line-breaking)))
624 (defun char-db-decode-isolated-char (ccs code-point)
627 (cond ((eq ccs 'arabic-iso8859-6)
628 (decode-char ccs code-point))
630 ;; (decode-builtin-char '==gt code-point))
631 ((and (memq ccs '(=gt-pj-1
642 (setq ret (decode-char ccs code-point))
643 (setq ret (encode-char ret '=gt 'defined-only)))
644 (decode-builtin-char '=gt ret))
646 (decode-builtin-char ccs code-point))))
648 (or (decode-char ccs code-point)
649 (define-char (list (cons ccs code-point)))))
650 ((and (<= 0 (char-int ret))
651 (<= (char-int ret) #x1F))
652 (decode-char '=ucs (+ #x2400 (char-int ret))))
653 ((= (char-int ret) #x7F)
657 (defvar char-db-convert-obsolete-format t)
659 (defun char-db-insert-ccs-feature (name value line-breaking)
665 ((memq name '(=>iwds-1
668 =shinjigen@1ed ==shinjigen@1ed
669 =shinjigen@rev ==shinjigen@rev
670 =shinjigen/+p@rev ==shinjigen/+p@rev
671 ===daikanwa/ho ==daikanwa/ho
672 =daikanwa/ho =>>daikanwa/ho =>daikanwa/ho))
673 "(%-18s . %04d)\t; %c")
674 ((eq name '=shinjigen@1ed/24pr)
675 "(%-18s . %04d)\t; %c")
679 ==daikanwa =daikanwa =>>daikanwa =>daikanwa
680 =daikanwa@rev1 =daikanwa@rev2
681 =daikanwa/+p ==daikanwa/+p ===daikanwa/+p
683 =daikanwa/+2p =>>daikanwa/+2p
688 =adobe-japan1-0 ==adobe-japan1-0 ===adobe-japan1-0
689 =adobe-japan1-1 ==adobe-japan1-1 ===adobe-japan1-1
690 =adobe-japan1-2 ==adobe-japan1-2 ===adobe-japan1-2
691 =adobe-japan1-3 ==adobe-japan1-3 ===adobe-japan1-3
692 =adobe-japan1-4 ==adobe-japan1-4 ===adobe-japan1-4
693 =adobe-japan1-5 ==adobe-japan1-5 ===adobe-japan1-5
694 =adobe-japan1-6 ==adobe-japan1-6 ===adobe-japan1-6
695 =>>adobe-japan1-0 =+>adobe-japan1-0
696 =>>adobe-japan1-1 =+>adobe-japan1-1
697 =>>adobe-japan1-2 =+>adobe-japan1-2
698 =>>adobe-japan1-3 =+>adobe-japan1-3
699 =>>adobe-japan1-4 =+>adobe-japan1-4
700 =>>adobe-japan1-5 =+>adobe-japan1-5
701 =>>adobe-japan1-6 =+>adobe-japan1-6
702 =>cbeta =cbeta =>>cbeta ==cbeta ===cbeta
703 =zinbun-oracle =>zinbun-oracle
704 ===hng-jou ===hng-keg ===hng-dng ===hng-mam
705 ===hng-drt ===hng-kgk ===hng-myz ===hng-kda
706 ===hng-khi ===hng-khm ===hng-hok ===hng-kyd ===hng-sok
707 ===hng-yhk ===hng-kak ===hng-kar ===hng-kae
708 ===hng-sys ===hng-tsu ===hng-tzj
709 ===hng-hos ===hng-nak ===hng-jhk
710 ===hng-hod ===hng-gok ===hng-ink ===hng-nto
711 ===hng-nkm ===hng-k24 ===hng-nkk
712 ===hng-kcc ===hng-kcj ===hng-kbk ===hng-sik
713 ===hng-skk ===hng-kyu ===hng-ksk ===hng-wan
714 ===hng-okd ===hng-wad ===hng-kmi
715 ===hng-zkd ===hng-doh ===hng-jyu
716 ===hng-tzs ===hng-kss ===hng-kyo
718 ;; (string-match "^=adobe-" (symbol-name name))
720 "(%-18s . %05d)\t; %c")
721 ((memq name '(=hanyo-denshi/ks
722 ==hanyo-denshi/ks ===hanyo-denshi/ks
725 =mj ==mj ===mj =>>mj =>mj
727 "(%-18s . %06d)\t; %c")
728 ((memq name '(=hanyo-denshi/tk ==hanyo-denshi/tk))
729 "(%-18s . %08d)\t; %c")
730 ((>= (charset-dimension name) 2)
731 "(%-18s . #x%04X)\t; %c")
733 "(%-18s . #x%02X)\t; %c"))
735 (if (= (charset-iso-graphic-plane name) 1)
737 (cond ((= (charset-dimension name) 1)
739 ((= (charset-dimension name) 2)
741 ((= (charset-dimension name) 3)
745 (char-db-decode-isolated-char name value)))
746 (if (and (= (charset-chars name) 94)
747 (= (charset-dimension name) 2))
748 (insert (format " [%02d-%02d]"
749 (- (lsh value -8) 32)
750 (- (logand value 255) 32))))
753 (insert (format "(%-18s . %s)" name value))
755 (insert line-breaking))
757 (defun char-db-insert-relation-feature (char name value line-breaking
759 (insert (format "(%-18s%s " name line-breaking))
760 (let ((lbs (concat "\n" (make-string (current-column) ?\ )))
761 separator cell sources required-features
764 (setq cell (car value))
766 (setq cell (decode-char '=ucs cell)))
768 ((eq name '->subsumptive)
769 (when (or (not (some (lambda (atr)
770 (get-char-attribute cell atr))
771 char-db-ignored-attributes))
773 (encode-char cell ccs 'defined-only))
777 (let ((char-db-ignored-attributes
779 char-db-ignored-attributes)))
780 (insert-char-attributes cell readable nil nil 'for-sub-node))
781 (setq separator lbs))
786 char (intern (format "%s*sources" name))))
787 (setq required-features nil)
788 (dolist (source sources)
792 shinjigen shinjigen@1ed shinjigen@rev))
793 (setq required-features
794 (union required-features
806 =shinjigen/+p@rev))))
808 (setq required-features
809 (union required-features
814 ((find-charset (setq ret (intern (format "=%s" source))))
815 (setq required-features
816 (cons ret required-features)))
817 (t (setq required-features
818 (cons source required-features)))))
819 (cond ((string-match "@JP" (symbol-name name))
820 (setq required-features
821 (union required-features
829 ((string-match "@CN" (symbol-name name))
830 (setq required-features
831 (union required-features
838 (insert (format "%S" cell))
839 (char-db-insert-char-spec cell readable
842 (setq separator lbs))
846 (if (consp (car cell))
847 (char-db-insert-char-spec cell readable)
848 (char-db-insert-char-reference cell readable))
849 (setq separator lbs))
853 (insert (prin1-to-string cell))
854 (setq separator " ")))
855 (setq value (cdr value)))
857 (insert line-breaking)))
859 (defun insert-char-attributes (char &optional readable attributes column
862 (setq column (current-column)))
863 (let (name value ; has-long-ccs-name
867 (concat "\n" (make-string (1+ column) ?\ )))
868 lbs cell separator ret
870 dest-ccss ; sources required-features
875 (if (consp attributes)
877 (dolist (name attributes)
878 (unless (memq name char-db-ignored-attributes)
879 (if (find-charset name)
883 (dolist (name (char-attribute-list))
884 (unless (memq name char-db-ignored-attributes)
885 (if (find-charset name)
889 #'char-attribute-name<)))
891 (when (memq '<-subsumptive attributes)
892 (when (or readable (not for-sub-node))
893 (when (setq value (get-char-attribute char '<-subsumptive))
894 (char-db-insert-relation-feature char '<-subsumptive value
897 (setq attributes (delq '<-subsumptive attributes)))
898 (when (and (memq '<-denotational attributes)
899 (setq value (get-char-attribute char '<-denotational)))
900 (char-db-insert-relation-feature char '<-denotational value
903 (setq attributes (delq '<-denotational attributes)))
904 (when (and (memq '<-denotational@component attributes)
905 (setq value (get-char-attribute char '<-denotational@component)))
906 (char-db-insert-relation-feature char '<-denotational@component value
909 (setq attributes (delq '<-denotational@component attributes)))
910 (when (and (memq 'name attributes)
911 (setq value (get-char-attribute char 'name)))
913 (if (> (+ (current-column) (length value)) 48)
916 value line-breaking))
917 (setq attributes (delq 'name attributes))
919 (when (and (memq 'name* attributes)
920 (setq value (get-char-attribute char 'name*)))
922 (if (> (+ (current-column) (length value)) 48)
925 value line-breaking))
926 (setq attributes (delq 'name* attributes))
928 (when (and (memq 'script attributes)
929 (setq value (get-char-attribute char 'script)))
930 (insert (format "(script\t\t%s)%s"
931 (mapconcat (function prin1-to-string)
934 (setq attributes (delq 'script attributes))
936 (dolist (name '(=>ucs =>ucs*))
937 (when (and (memq name attributes)
938 (setq value (get-char-attribute char name)))
939 (insert (format "(%-18s . #x%04X)\t; %c%s"
940 name value (decode-char '=ucs value)
942 (setq attributes (delq name attributes))))
943 (dolist (name '(=>ucs@gb =>ucs@big5))
944 (when (and (memq name attributes)
945 (setq value (get-char-attribute char name)))
946 (insert (format "(%-18s . #x%04X)\t; %c%s"
951 (symbol-name name) 2)))
954 (setq attributes (delq name attributes))
956 ;; (dolist (name '(=>daikanwa))
957 ;; (when (and (memq name attributes)
958 ;; (setq value (get-char-attribute char name)))
960 ;; (if (integerp value)
961 ;; (format "(%-18s . %05d)\t; %c%s"
962 ;; name value (decode-char '=daikanwa value)
964 ;; (format "(%-18s %s)\t; %c%s"
966 ;; (mapconcat (function prin1-to-string)
968 ;; (char-representative-of-daikanwa char)
970 ;; (setq attributes (delq name attributes))))
971 (when (and (memq 'general-category attributes)
972 (setq value (get-char-attribute char 'general-category)))
974 "(general-category\t%s) ; %s%s"
975 (mapconcat (lambda (cell)
978 (cond ((rassoc value unidata-normative-category-alist)
979 "Normative Category")
980 ((rassoc value unidata-informative-category-alist)
981 "Informative Category")
985 (setq attributes (delq 'general-category attributes))
987 (when (and (memq 'bidi-category attributes)
988 (setq value (get-char-attribute char 'bidi-category)))
989 (insert (format "(bidi-category\t. %S)%s"
992 (setq attributes (delq 'bidi-category attributes))
994 (unless (or (not (memq 'mirrored attributes))
995 (eq (setq value (get-char-attribute char 'mirrored 'empty))
997 (insert (format "(mirrored\t\t. %S)%s"
1000 (setq attributes (delq 'mirrored attributes))
1003 ((and (memq 'decimal-digit-value attributes)
1004 (setq value (get-char-attribute char 'decimal-digit-value)))
1005 (insert (format "(decimal-digit-value . %S)%s"
1008 (setq attributes (delq 'decimal-digit-value attributes))
1009 (when (and (memq 'digit-value attributes)
1010 (setq value (get-char-attribute char 'digit-value)))
1011 (insert (format "(digit-value\t . %S)%s"
1014 (setq attributes (delq 'digit-value attributes))
1016 (when (and (memq 'numeric-value attributes)
1017 (setq value (get-char-attribute char 'numeric-value)))
1018 (insert (format "(numeric-value\t . %S)%s"
1021 (setq attributes (delq 'numeric-value attributes))
1025 (when (and (memq 'digit-value attributes)
1026 (setq value (get-char-attribute char 'digit-value)))
1027 (insert (format "(digit-value\t. %S)%s"
1030 (setq attributes (delq 'digit-value attributes))
1032 (when (and (memq 'numeric-value attributes)
1033 (setq value (get-char-attribute char 'numeric-value)))
1034 (insert (format "(numeric-value\t. %S)%s"
1037 (setq attributes (delq 'numeric-value attributes))
1039 (when (and (memq 'iso-10646-comment attributes)
1040 (setq value (get-char-attribute char 'iso-10646-comment)))
1041 (insert (format "(iso-10646-comment\t. %S)%s"
1044 (setq attributes (delq 'iso-10646-comment attributes))
1046 (when (and (memq 'morohashi-daikanwa attributes)
1047 (setq value (get-char-attribute char 'morohashi-daikanwa)))
1048 (insert (format "(morohashi-daikanwa\t%s)%s"
1049 (mapconcat (function prin1-to-string) value " ")
1051 (setq attributes (delq 'morohashi-daikanwa attributes))
1055 (when (and (memq 'ideographic-radical attributes)
1056 (setq value (get-char-attribute char 'ideographic-radical)))
1057 (setq radical value)
1058 (insert (format "(ideographic-radical . %S)\t; %c%s"
1060 (ideographic-radical radical)
1062 (setq attributes (delq 'ideographic-radical attributes))
1064 (when (and (memq 'shuowen-radical attributes)
1065 (setq value (get-char-attribute char 'shuowen-radical)))
1066 (insert (format "(shuowen-radical\t. %S)\t; %c%s"
1068 (shuowen-radical value)
1070 (setq attributes (delq 'shuowen-radical attributes))
1075 char-db-feature-domains
1077 (dolist (feature (char-attribute-list))
1078 (setq feature (symbol-name feature))
1080 "\\(radical\\|strokes\\)@\\([^@*]+\\)\\(\\*\\|$\\)"
1082 (setq domain (intern (match-string 2 feature)))
1083 (unless (memq domain dest)
1084 (setq dest (cons domain dest)))))
1085 (sort dest #'string<))))
1086 (setq key (intern (format "%s@%s" 'ideographic-radical domain)))
1087 (when (and (memq key attributes)
1088 (setq value (get-char-attribute char key)))
1089 (setq radical value)
1090 (insert (format "(%s . %S)\t; %c%s"
1093 (ideographic-radical radical)
1095 (setq attributes (delq key attributes))
1097 (setq key (intern (format "%s@%s" 'ideographic-strokes domain)))
1098 (when (and (memq key attributes)
1099 (setq value (get-char-attribute char key)))
1100 (setq strokes value)
1101 (insert (format "(%s . %S)%s"
1105 (setq attributes (delq key attributes))
1107 (setq key (intern (format "%s@%s" 'total-strokes domain)))
1108 (when (and (memq key attributes)
1109 (setq value (get-char-attribute char key)))
1110 (insert (format "(%s . %S)%s"
1114 (setq attributes (delq key attributes))
1116 (dolist (feature '(ideographic-radical
1119 (setq key (intern (format "%s@%s*sources" feature domain)))
1120 (when (and (memq key attributes)
1121 (setq value (get-char-attribute char key)))
1122 (insert (format "(%s%s" key line-breaking))
1123 (dolist (cell value)
1124 (insert (format " %s" cell)))
1126 (insert line-breaking)
1127 (setq attributes (delq key attributes))
1130 (when (and (memq 'ideographic-strokes attributes)
1131 (setq value (get-char-attribute char 'ideographic-strokes)))
1132 (setq strokes value)
1133 (insert (format "(ideographic-strokes . %S)%s"
1136 (setq attributes (delq 'ideographic-strokes attributes))
1138 (when (and (memq 'kangxi-radical attributes)
1139 (setq value (get-char-attribute char 'kangxi-radical)))
1140 (unless (eq value radical)
1141 (insert (format "(kangxi-radical\t . %S)\t; %c%s"
1143 (ideographic-radical value)
1146 (setq radical value)))
1147 (setq attributes (delq 'kangxi-radical attributes))
1149 (when (and (memq 'kangxi-strokes attributes)
1150 (setq value (get-char-attribute char 'kangxi-strokes)))
1151 (unless (eq value strokes)
1152 (insert (format "(kangxi-strokes\t . %S)%s"
1156 (setq strokes value)))
1157 (setq attributes (delq 'kangxi-strokes attributes))
1159 ;; (when (and (memq 'japanese-radical attributes)
1160 ;; (setq value (get-char-attribute char 'japanese-radical)))
1161 ;; (unless (eq value radical)
1162 ;; (insert (format "(japanese-radical\t . %S)\t; %c%s"
1164 ;; (ideographic-radical value)
1167 ;; (setq radical value)))
1168 ;; (setq attributes (delq 'japanese-radical attributes))
1170 (when (and (memq 'japanese-strokes attributes)
1171 (setq value (get-char-attribute char 'japanese-strokes)))
1172 (unless (eq value strokes)
1173 (insert (format "(japanese-strokes\t . %S)%s"
1177 (setq strokes value)))
1178 (setq attributes (delq 'japanese-strokes attributes))
1180 (when (and (memq 'cns-radical attributes)
1181 (setq value (get-char-attribute char 'cns-radical)))
1182 (insert (format "(cns-radical\t . %S)\t; %c%s"
1184 (ideographic-radical value)
1186 (setq attributes (delq 'cns-radical attributes))
1188 (when (and (memq 'cns-strokes attributes)
1189 (setq value (get-char-attribute char 'cns-strokes)))
1190 (unless (eq value strokes)
1191 (insert (format "(cns-strokes\t . %S)%s"
1195 (setq strokes value)))
1196 (setq attributes (delq 'cns-strokes attributes))
1198 ;; (when (and (memq 'shinjigen-1-radical attributes)
1199 ;; (setq value (get-char-attribute char 'shinjigen-1-radical)))
1200 ;; (unless (eq value radical)
1201 ;; (insert (format "(shinjigen-1-radical . %S)\t; %c%s"
1203 ;; (ideographic-radical value)
1206 ;; (setq radical value)))
1207 ;; (setq attributes (delq 'shinjigen-1-radical attributes))
1209 ;; (when (and (memq 'ideographic- attributes)
1210 ;; (setq value (get-char-attribute char 'ideographic-)))
1211 ;; (insert "(ideographic- ")
1212 ;; (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1214 ;; (while (consp value)
1215 ;; (setq cell (car value))
1216 ;; (if (integerp cell)
1217 ;; (setq cell (decode-char '=ucs cell)))
1218 ;; (cond ((characterp cell)
1222 ;; (insert (format "%S" cell))
1223 ;; (char-db-insert-char-spec cell readable))
1224 ;; (setq separator lbs))
1228 ;; (if (consp (car cell))
1229 ;; (char-db-insert-char-spec cell readable)
1230 ;; (char-db-insert-char-reference cell readable))
1231 ;; (setq separator lbs))
1234 ;; (insert separator))
1235 ;; (insert (prin1-to-string cell))
1236 ;; (setq separator " ")))
1237 ;; (setq value (cdr value)))
1239 ;; (insert line-breaking)
1240 ;; (setq attributes (delq 'ideographic- attributes)))
1241 (when (and (memq 'total-strokes attributes)
1242 (setq value (get-char-attribute char 'total-strokes)))
1243 (insert (format "(total-strokes . %S)%s"
1246 (setq attributes (delq 'total-strokes attributes))
1248 ;; (when (and (memq '->ideograph attributes)
1249 ;; (setq value (get-char-attribute char '->ideograph)))
1250 ;; (insert (format "(->ideograph\t%s)%s"
1251 ;; (mapconcat (lambda (code)
1252 ;; (cond ((symbolp code)
1253 ;; (symbol-name code))
1255 ;; (format "#x%04X" code))
1258 ;; line-breaking code))))
1261 ;; (setq attributes (delq '->ideograph attributes))
1263 ;; (when (and (memq '->decomposition attributes)
1264 ;; (setq value (get-char-attribute char '->decomposition)))
1265 ;; (insert (format "(->decomposition\t%s)%s"
1266 ;; (mapconcat (lambda (code)
1267 ;; (cond ((symbolp code)
1268 ;; (symbol-name code))
1269 ;; ((characterp code)
1271 ;; (format "%S" code)
1276 ;; (format "#x%04X" code))
1278 ;; (format "%s%S" line-breaking code))))
1281 ;; (setq attributes (delq '->decomposition attributes))
1283 (if (equal (get-char-attribute char '->titlecase)
1284 (get-char-attribute char '->uppercase))
1285 (setq attributes (delq '->titlecase attributes)))
1286 (when (and (memq '->mojikyo attributes)
1287 (setq value (get-char-attribute char '->mojikyo)))
1288 (insert (format "(->mojikyo\t\t. %06d)\t; %c%s"
1289 value (decode-char 'mojikyo value)
1291 (setq attributes (delq '->mojikyo attributes))
1293 ;; (when (and (memq 'hanyu-dazidian-vol attributes)
1294 ;; (setq value (get-char-attribute char 'hanyu-dazidian-vol)))
1295 ;; (insert (format "(hanyu-dazidian-vol . %d)%s"
1296 ;; value line-breaking))
1297 ;; (setq attributes (delq 'hanyu-dazidian-vol attributes))
1299 ;; (when (and (memq 'hanyu-dazidian-page attributes)
1300 ;; (setq value (get-char-attribute char 'hanyu-dazidian-page)))
1301 ;; (insert (format "(hanyu-dazidian-page . %d)%s"
1302 ;; value line-breaking))
1303 ;; (setq attributes (delq 'hanyu-dazidian-page attributes))
1305 ;; (when (and (memq 'hanyu-dazidian-char attributes)
1306 ;; (setq value (get-char-attribute char 'hanyu-dazidian-char)))
1307 ;; (insert (format "(hanyu-dazidian-char . %d)%s"
1308 ;; value line-breaking))
1309 ;; (setq attributes (delq 'hanyu-dazidian-char attributes))
1312 (dolist (ignored '(composition
1313 ->denotational <-subsumptive ->ucs-unified
1314 ->ideographic-component-forms))
1315 (setq attributes (delq ignored attributes))))
1317 (setq name (car attributes))
1318 (unless (eq (setq value (get-char-attribute char name 'value-is-empty))
1320 (cond ((setq ret (find-charset name))
1321 (setq name (charset-name ret))
1322 (when (not (memq name dest-ccss))
1323 (setq dest-ccss (cons name dest-ccss))
1324 (char-db-insert-ccs-feature name value line-breaking))
1326 ((string-match "^=>ucs@" (symbol-name name))
1327 (insert (format "(%-18s . #x%04X)\t; %c%s"
1328 name value (decode-char '=ucs value)
1331 ((eq name 'jisx0208-1978/4X)
1332 (insert (format "(%-18s . #x%04X)%s"
1338 (not (eq name '->subsumptive))
1339 (not (eq name '->uppercase))
1340 (not (eq name '->lowercase))
1341 (not (eq name '->titlecase))
1342 (not (eq name '->canonical))
1343 (not (eq name '->Bopomofo))
1344 (not (eq name '->mistakable))
1345 (not (eq name '->ideographic-variants))
1346 (null (get-char-attribute
1347 char (intern (format "%s*sources" name))))
1348 (not (string-match "\\*sources$" (symbol-name name)))
1349 (null (get-char-attribute
1350 char (intern (format "%s*note" name))))
1351 (not (string-match "\\*note$" (symbol-name name)))
1352 (or (eq name '<-identical)
1353 (eq name '<-uppercase)
1354 (eq name '<-lowercase)
1355 (eq name '<-titlecase)
1356 (eq name '<-canonical)
1357 (eq name '<-ideographic-variants)
1358 ;; (eq name '<-synonyms)
1359 (string-match "^<-synonyms" (symbol-name name))
1360 (eq name '<-mistakable)
1361 (when (string-match "^->" (symbol-name name))
1363 ((string-match "^->fullwidth" (symbol-name name))
1364 (not (and (consp value)
1365 (characterp (car value))
1367 (car value) '=ucs 'defined-only)))
1372 ((or (eq name 'ideographic-structure)
1373 (eq name 'ideographic-combination)
1374 ;; (eq name 'ideographic-)
1375 (eq name '=decomposition)
1376 (char-feature-base-name= '=decomposition name)
1377 (char-feature-base-name= '=>decomposition name)
1378 ;; (string-match "^=>*decomposition\\(@[^*]+\\)?$"
1379 ;; (symbol-name name))
1380 (string-match "^\\(->\\|<-\\)[^*]*$" (symbol-name name))
1381 (string-match "^\\(->\\|<-\\)[^*]*\\*sources$"
1384 (char-db-insert-relation-feature char name value
1387 ;; ((memq name '(ideograph=
1388 ;; original-ideograph-of
1389 ;; ancient-ideograph-of
1390 ;; vulgar-ideograph-of
1391 ;; wrong-ideograph-of
1392 ;; ;; simplified-ideograph-of
1393 ;; ideographic-variants
1394 ;; ;; ideographic-different-form-of
1396 ;; (insert (format "(%-18s%s " name line-breaking))
1397 ;; (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1399 ;; (while (consp value)
1400 ;; (setq cell (car value))
1401 ;; (if (and (consp cell)
1402 ;; (consp (car cell)))
1406 ;; (char-db-insert-alist cell readable)
1407 ;; (setq separator lbs))
1409 ;; (insert separator))
1410 ;; (insert (prin1-to-string cell))
1411 ;; (setq separator " "))
1412 ;; (setq value (cdr value)))
1414 ;; (insert line-breaking))
1416 (insert (format "(%-18s " name))
1417 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1419 (while (consp value)
1420 (setq cell (car value))
1421 (if (and (consp cell)
1423 (setq ret (condition-case nil
1431 (setq key (car (car rest)))
1432 (if (find-charset key)
1433 (setq cal (cons key cal))
1434 (setq al (cons key al)))
1435 (setq rest (cdr rest)))
1438 (insert-char-attributes ret
1442 (setq separator lbs))
1443 (setq ret (prin1-to-string cell))
1445 (if (< (+ (current-column)
1452 (setq separator " "))
1453 (setq value (cdr value)))
1455 (insert line-breaking))
1457 (insert (format "(%-18s" name))
1458 (setq ret (prin1-to-string value))
1459 (unless (< (+ (current-column)
1463 (insert line-breaking))
1464 (insert " . " ret ")" line-breaking)
1465 ;; (insert (format "(%-18s . %S)%s"
1470 (setq attributes (cdr attributes)))
1473 (defun insert-char-data (char &optional readable
1476 (narrow-to-region (point)(point))
1477 (insert "(define-char
1479 (insert-char-attributes char readable attributes)
1481 (goto-char (point-min))
1482 (while (re-search-forward "[ \t]+$" nil t)
1485 (goto-char (point-min))
1486 (while (re-search-forward "[ \t][ \t][ \t]*" nil t)
1487 (let ((column (current-column))
1488 (indent-tabs-mode t))
1489 (delete-region (match-beginning 0) (point))
1490 (indent-to column)))
1491 (goto-char (point-max))
1492 ;; (tabify (point-min)(point-max))
1495 (defun insert-char-data-with-variant (char &optional printable
1497 script excluded-script)
1498 (insert-char-data char printable)
1499 (let ((variants (char-variants char))
1502 (setq variants (sort variants #'<))
1503 (setq rest variants)
1504 (setq variants (cons char variants))
1506 (setq variant (car rest))
1507 (unless (get-char-attribute variant '<-subsumptive)
1508 (if (and (or (null script)
1509 (null (setq vs (get-char-attribute variant 'script)))
1511 (or (null excluded-script)
1512 (null (setq vs (get-char-attribute variant 'script)))
1513 (not (memq excluded-script vs))))
1514 (unless (and no-ucs-unified (get-char-attribute variant '=ucs))
1515 (insert-char-data variant printable)
1516 (if (setq ret (char-variants variant))
1518 (or (memq (car ret) variants)
1519 ;; (get-char-attribute (car ret) '<-subsumptive)
1520 (setq rest (nconc rest (list (car ret)))))
1521 (setq ret (cdr ret)))))))
1522 (setq rest (cdr rest)))))
1524 (defun insert-char-range-data (min max &optional script excluded-script)
1527 (while (<= code max)
1528 (setq char (decode-char '=ucs code))
1529 (if (encode-char char '=ucs 'defined-only)
1530 (insert-char-data-with-variant char nil 'no-ucs-unified
1531 script excluded-script))
1532 (setq code (1+ code)))))
1534 (defun write-char-range-data-to-file (min max file
1535 &optional script excluded-script)
1536 (let ((coding-system-for-write char-db-file-coding-system))
1538 (insert (format ";; -*- coding: %s -*-\n"
1539 char-db-file-coding-system))
1540 (insert-char-range-data min max script excluded-script)
1541 (write-region (point-min)(point-max) file))))
1543 (defvar what-character-original-window-configuration)
1546 (defun what-char-definition (char)
1547 (interactive (list (char-after)))
1548 (let ((buf (get-buffer-create "*Character Description*"))
1549 (the-buf (current-buffer))
1550 (win-conf (current-window-configuration)))
1552 (make-local-variable 'what-character-original-window-configuration)
1553 (setq what-character-original-window-configuration win-conf)
1554 (setq buffer-read-only nil)
1558 (insert-char-data-with-variant char 'printable)
1559 (unless (char-attribute-alist char)
1560 (insert (format ";; = %c\n"
1561 (let* ((rest (split-char char))
1565 (setq code (logior (lsh code 8)
1567 (decode-char ccs code)))))
1568 ;; (char-db-update-comment)
1569 (set-buffer-modified-p nil)
1570 (view-mode the-buf (lambda (buf)
1571 (set-window-configuration
1572 what-character-original-window-configuration)
1574 (goto-char (point-min)))
1576 (set-window-configuration
1577 what-character-original-window-configuration)
1578 (signal (car err) (cdr err)))))))
1584 (provide 'char-db-util)
1586 ;;; char-db-util.el ends here