1 ;;; char-db-util.el --- Character Database utility -*- coding: utf-8-er; -*-
3 ;; Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006,
4 ;; 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014 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
108 (defun shuowen-radical (number)
109 (aref shuowen-radicals (1- number)))
111 (defvar char-db-file-coding-system 'utf-8-mcs-er)
113 (defvar char-db-ignored-attributes '(ideographic-products))
115 (defvar char-db-coded-charset-priority-list
208 ;; =>>>adobe-japan1-0
209 ;; =>>>adobe-japan1-1
210 ;; =>>>adobe-japan1-2
211 ;; =>>>adobe-japan1-3
212 ;; =>>>adobe-japan1-4
213 ;; =>>>adobe-japan1-5
214 ;; =>>>adobe-japan1-6
218 ;; =>>>hanyo-denshi/ja
219 ;; =>>>hanyo-denshi/jb
220 ;; =>>>hanyo-denshi/jc
221 ;; =>>>hanyo-denshi/ft
222 ;; =>>>hanyo-denshi/ib
223 ;; =>>>hanyo-denshi/hg
224 ;; =>>>hanyo-denshi/jt
225 ;; =>>>hanyo-denshi/ks
326 ;;; @ char-db formatters
329 (defun char-db-make-char-spec (char)
331 (cond ((characterp char)
332 (cond ((and (setq ret (encode-char char '=ucs 'defined-only))
333 (not (and (<= #xE000 ret)(<= ret #xF8FF))))
334 (setq char-spec (list (cons '=ucs ret)))
335 (cond ((setq ret (get-char-attribute char 'name))
336 (setq char-spec (cons (cons 'name ret) char-spec))
338 ((setq ret (get-char-attribute char 'name*))
339 (setq char-spec (cons (cons 'name* ret) char-spec))
342 ((encode-char char '=mj 'defined-only)
344 (dolist (ccs (charset-list))
345 (if (and (or (eq ccs '=mj)
346 ;; (eq (charset-property ccs 'iso-ir) 177)
347 (string-match "=ucs@" (symbol-name ccs))
349 (setq ccs (charset-name ccs))
350 (null (assq ccs char-spec))
351 (setq ret (encode-char char ccs 'defined-only)))
352 (setq char-spec (cons (cons ccs ret) char-spec))))
354 ((encode-char char '==mj 'defined-only)
356 (dolist (ccs (charset-list))
357 (if (and (or (eq ccs '==mj)
358 ;; (eq (charset-property ccs 'iso-ir) 177)
359 (string-match "=ucs@" (symbol-name ccs))
361 (setq ccs (charset-name ccs))
362 (null (assq ccs char-spec))
363 (setq ret (encode-char char ccs 'defined-only)))
364 (setq char-spec (cons (cons ccs ret) char-spec))))
366 ((encode-char char '=adobe-japan1 'defined-only)
368 (dolist (ccs (charset-list))
369 (if (and (or (memq ccs
378 ;; (eq (charset-property ccs 'iso-ir) 177)
379 (string-match "=ucs@" (symbol-name ccs))
381 (setq ccs (charset-name ccs))
382 (null (assq ccs char-spec))
383 (setq ret (encode-char char ccs 'defined-only)))
384 (setq char-spec (cons (cons ccs ret) char-spec))))
386 ((encode-char char '==adobe-japan1 'defined-only)
388 (dolist (ccs (charset-list))
389 (if (and (or (memq ccs
398 ;; (eq (charset-property ccs 'iso-ir) 177)
399 (string-match "=ucs@" (symbol-name ccs))
401 (setq ccs (charset-name ccs))
402 (null (assq ccs char-spec))
403 (setq ret (encode-char char ccs 'defined-only)))
404 (setq char-spec (cons (cons ccs ret) char-spec))))
408 (let ((rest char-db-coded-charset-priority-list)
411 (setq ccs (charset-name
412 (find-charset (car rest))))
414 (encode-char char ccs
416 (throw 'tag (cons ccs ret)))
417 (setq rest (cdr rest))))))
418 (setq char-spec (list ret))
419 (dolist (ccs (delq (car ret) (charset-list)))
420 (if (and (or (charset-iso-final-char ccs)
427 (eq (charset-property ccs 'iso-ir) 177)
428 ;; (string-match "=ucs@" (symbol-name ccs))
430 (setq ccs (charset-name ccs))
431 (null (assq ccs char-spec))
432 (setq ret (encode-char char ccs 'defined-only)))
433 (setq char-spec (cons (cons ccs ret) char-spec))))
435 (setq char-spec (split-char char)))
436 (cond ((setq ret (get-char-attribute char 'name))
437 (setq char-spec (cons (cons 'name ret) char-spec))
439 ((setq ret (get-char-attribute char 'name*))
440 (setq char-spec (cons (cons 'name* ret) char-spec))
443 ((setq ret (get-char-attribute
444 char 'ideographic-combination))
446 (cons (cons 'ideographic-combination ret)
453 (defun char-db-insert-char-spec (char &optional readable column
456 (setq column (current-column)))
457 (let (char-spec temp-char)
458 (setq char-spec (char-db-make-char-spec char))
459 (unless (or (characterp char) ; char
461 (setq char (find-char char-spec))
463 ;; define temporary character
464 ;; Current implementation is dirty.
465 (setq temp-char (define-char (cons '(ideograph-daikanwa . 0)
467 (remove-char-attribute temp-char 'ideograph-daikanwa)
468 (setq char temp-char))
469 (insert-char-attributes char
471 (union (mapcar #'car char-spec)
475 ;; undefine temporary character
476 ;; Current implementation is dirty.
477 (setq char-spec (char-attribute-alist temp-char))
479 (remove-char-attribute temp-char (car (car char-spec)))
480 (setq char-spec (cdr char-spec))))))
482 (defun char-db-insert-alist (alist &optional readable column)
484 (setq column (current-column)))
486 (concat "\n" (make-string (1+ column) ?\ )))
490 lbs cell rest separator)
493 (setq name (car (car alist))
494 value (cdr (car alist)))
495 (cond ((eq name 'char)
497 (if (setq ret (condition-case nil
505 (setq key (car (car value)))
506 ;; (if (find-charset key)
507 ;; (setq cal (cons key cal))
508 (setq al (cons key al))
510 (setq value (cdr value)))
511 (insert-char-attributes ret
515 (insert (prin1-to-string value)))
517 (insert line-breaking))
519 (insert (format "(%-18s " name))
520 (setq lbs (concat "\n" (make-string (current-column) ?\ )))
522 (setq cell (car value))
523 (if (and (consp cell)
525 (setq ret (condition-case nil
535 (setq key (car (car rest)))
536 ;; (if (find-charset key)
537 ;; (setq cal (cons key cal))
538 (setq al (cons key al))
540 (setq rest (cdr rest)))
543 (insert-char-attributes ret
547 (setq separator lbs))
550 (insert (prin1-to-string cell))
551 (setq separator " "))
552 (setq value (cdr value)))
554 (insert line-breaking))
556 (insert (format "(%-18s . %S)%s"
559 (setq alist (cdr alist))))
562 (defun char-db-insert-char-reference (plist &optional readable column)
564 (setq column (current-column)))
566 (concat "\n" (make-string (1+ column) ?\ )))
571 (setq name (pop plist))
572 (setq value (pop plist))
573 (cond ((eq name :char)
576 (cond ((numberp value)
577 (setq value (decode-char '=ucs value)))
579 ;; (setq value (or (find-char value)
582 (char-db-insert-char-spec value readable)
583 (insert line-breaking)
586 (insert (format "%s%s\t%d ; %c%s"
589 (ideographic-radical value)
593 (insert (format "%s%s\t%S" separator name value))
594 (setq separator line-breaking)))
598 (defun char-db-decode-isolated-char (ccs code-point)
601 (cond ((eq ccs 'arabic-iso8859-6)
602 (decode-char ccs code-point))
604 ;; (decode-builtin-char '==gt code-point))
605 ((and (memq ccs '(=gt-pj-1
616 (setq ret (decode-char ccs code-point))
617 (setq ret (encode-char ret '=gt 'defined-only)))
618 (decode-builtin-char '=gt ret))
620 (decode-builtin-char ccs code-point))))
621 (cond ((and (<= 0 (char-int ret))
622 (<= (char-int ret) #x1F))
623 (decode-char '=ucs (+ #x2400 (char-int ret))))
624 ((= (char-int ret) #x7F)
628 (defvar char-db-convert-obsolete-format t)
630 (defun char-db-insert-ccs-feature (name value line-breaking)
636 ((memq name '(==shinjigen
638 =shinjigen@1ed ==shinjigen@1ed
639 =shinjigen@rev ==shinjigen@rev
640 =shinjigen/+p@rev ==shinjigen/+p@rev
641 ===daikanwa/ho ==daikanwa/ho
642 =daikanwa/ho =>>daikanwa/ho =>daikanwa/ho))
643 "(%-18s . %04d)\t; %c")
644 ((eq name '=shinjigen@1ed/24pr)
645 "(%-18s . %04d)\t; %c")
646 ((or (memq name '(===daikanwa
647 ==daikanwa =daikanwa =>>daikanwa =>daikanwa
648 =daikanwa@rev1 =daikanwa@rev2
649 =daikanwa/+p ==daikanwa/+p ===daikanwa/+p
651 =daikanwa/+2p =>>daikanwa/+2p
656 =adobe-japan1-0 ==adobe-japan1-0 ===adobe-japan1-0
657 =adobe-japan1-1 ==adobe-japan1-1 ===adobe-japan1-1
658 =adobe-japan1-2 ==adobe-japan1-2 ===adobe-japan1-2
659 =adobe-japan1-3 ==adobe-japan1-3 ===adobe-japan1-3
660 =adobe-japan1-4 ==adobe-japan1-4 ===adobe-japan1-4
661 =adobe-japan1-5 ==adobe-japan1-5 ===adobe-japan1-5
662 =adobe-japan1-6 ==adobe-japan1-6 ===adobe-japan1-6
663 =>>adobe-japan1-0 =+>adobe-japan1-0
664 =>>adobe-japan1-1 =+>adobe-japan1-1
665 =>>adobe-japan1-2 =+>adobe-japan1-2
666 =>>adobe-japan1-3 =+>adobe-japan1-3
667 =>>adobe-japan1-4 =+>adobe-japan1-4
668 =>>adobe-japan1-5 =+>adobe-japan1-5
669 =>>adobe-japan1-6 =+>adobe-japan1-6
670 =cbeta ==cbeta ===cbeta =>>cbeta
671 =zinbun-oracle =>zinbun-oracle))
672 ;; (string-match "^=adobe-" (symbol-name name))
674 "(%-18s . %05d)\t; %c")
675 ((memq name '(=hanyo-denshi/ks
676 ==hanyo-denshi/ks ===hanyo-denshi/ks
681 "(%-18s . %06d)\t; %c")
682 ((>= (charset-dimension name) 2)
683 "(%-18s . #x%04X)\t; %c")
685 "(%-18s . #x%02X)\t; %c"))
687 (if (= (charset-iso-graphic-plane name) 1)
689 (cond ((= (charset-dimension name) 1)
691 ((= (charset-dimension name) 2)
693 ((= (charset-dimension name) 3)
697 (char-db-decode-isolated-char name value)))
698 (if (and (= (charset-chars name) 94)
699 (= (charset-dimension name) 2))
700 (insert (format " [%02d-%02d]"
701 (- (lsh value -8) 32)
702 (- (logand value 255) 32))))
705 (insert (format "(%-18s . %s)" name value))
707 (insert line-breaking))
709 (defun char-db-insert-relation-feature (char name value line-breaking
711 (insert (format "(%-18s%s " name line-breaking))
712 (let ((lbs (concat "\n" (make-string (current-column) ?\ )))
713 separator cell sources required-features
716 (setq cell (car value))
718 (setq cell (decode-char '=ucs cell)))
720 ((eq name '->subsumptive)
721 (when (or (not (some (lambda (atr)
722 (get-char-attribute cell atr))
723 char-db-ignored-attributes))
725 (encode-char cell ccs 'defined-only))
729 (let ((char-db-ignored-attributes
731 char-db-ignored-attributes)))
732 (insert-char-attributes cell readable nil nil 'for-sub-node))
733 (setq separator lbs))
738 char (intern (format "%s*sources" name))))
739 (setq required-features nil)
740 (dolist (source sources)
744 shinjigen shinjigen@1ed shinjigen@rev))
745 (setq required-features
746 (union required-features
758 =shinjigen/+p@rev))))
760 (setq required-features
761 (union required-features
766 ((find-charset (setq ret (intern (format "=%s" source))))
767 (setq required-features
768 (cons ret required-features)))
769 (t (setq required-features
770 (cons source required-features)))))
771 (cond ((string-match "@JP" (symbol-name name))
772 (setq required-features
773 (union required-features
781 ((string-match "@CN" (symbol-name name))
782 (setq required-features
783 (union required-features
790 (insert (format "%S" cell))
791 (char-db-insert-char-spec cell readable
794 (setq separator lbs))
798 (if (consp (car cell))
799 (char-db-insert-char-spec cell readable)
800 (char-db-insert-char-reference cell readable))
801 (setq separator lbs))
805 (insert (prin1-to-string cell))
806 (setq separator " ")))
807 (setq value (cdr value)))
809 (insert line-breaking)))
811 (defun insert-char-attributes (char &optional readable attributes column
814 (setq column (current-column)))
815 (let (name value ; has-long-ccs-name
819 (concat "\n" (make-string (1+ column) ?\ )))
820 lbs cell separator ret
822 dest-ccss ; sources required-features
827 (if (consp attributes)
829 (dolist (name attributes)
830 (unless (memq name char-db-ignored-attributes)
831 (if (find-charset name)
835 (dolist (name (char-attribute-list))
836 (unless (memq name char-db-ignored-attributes)
837 (if (find-charset name)
841 #'char-attribute-name<)))
843 (when (memq '<-subsumptive attributes)
844 (when (or readable (not for-sub-node))
845 (when (setq value (get-char-attribute char '<-subsumptive))
846 (char-db-insert-relation-feature char '<-subsumptive value
849 (setq attributes (delq '<-subsumptive attributes)))
850 (when (and (memq '<-denotational attributes)
851 (setq value (get-char-attribute char '<-denotational)))
852 (char-db-insert-relation-feature char '<-denotational value
855 (setq attributes (delq '<-denotational attributes)))
856 (when (and (memq 'name attributes)
857 (setq value (get-char-attribute char 'name)))
859 (if (> (+ (current-column) (length value)) 48)
862 value line-breaking))
863 (setq attributes (delq 'name attributes))
865 (when (and (memq 'name* attributes)
866 (setq value (get-char-attribute char 'name*)))
868 (if (> (+ (current-column) (length value)) 48)
871 value line-breaking))
872 (setq attributes (delq 'name* attributes))
874 (when (and (memq 'script attributes)
875 (setq value (get-char-attribute char 'script)))
876 (insert (format "(script\t\t%s)%s"
877 (mapconcat (function prin1-to-string)
880 (setq attributes (delq 'script attributes))
882 (dolist (name '(=>ucs =>ucs*))
883 (when (and (memq name attributes)
884 (setq value (get-char-attribute char name)))
885 (insert (format "(%-18s . #x%04X)\t; %c%s"
886 name value (decode-char '=ucs value)
888 (setq attributes (delq name attributes))))
889 (dolist (name '(=>ucs@gb =>ucs@big5))
890 (when (and (memq name attributes)
891 (setq value (get-char-attribute char name)))
892 (insert (format "(%-18s . #x%04X)\t; %c%s"
897 (symbol-name name) 2)))
900 (setq attributes (delq name attributes))
902 ;; (dolist (name '(=>daikanwa))
903 ;; (when (and (memq name attributes)
904 ;; (setq value (get-char-attribute char name)))
906 ;; (if (integerp value)
907 ;; (format "(%-18s . %05d)\t; %c%s"
908 ;; name value (decode-char '=daikanwa value)
910 ;; (format "(%-18s %s)\t; %c%s"
912 ;; (mapconcat (function prin1-to-string)
914 ;; (char-representative-of-daikanwa char)
916 ;; (setq attributes (delq name attributes))))
917 (when (and (memq 'general-category attributes)
918 (setq value (get-char-attribute char 'general-category)))
920 "(general-category\t%s) ; %s%s"
921 (mapconcat (lambda (cell)
924 (cond ((rassoc value unidata-normative-category-alist)
925 "Normative Category")
926 ((rassoc value unidata-informative-category-alist)
927 "Informative Category")
931 (setq attributes (delq 'general-category attributes))
933 (when (and (memq 'bidi-category attributes)
934 (setq value (get-char-attribute char 'bidi-category)))
935 (insert (format "(bidi-category\t. %S)%s"
938 (setq attributes (delq 'bidi-category attributes))
940 (unless (or (not (memq 'mirrored attributes))
941 (eq (setq value (get-char-attribute char 'mirrored 'empty))
943 (insert (format "(mirrored\t\t. %S)%s"
946 (setq attributes (delq 'mirrored attributes))
949 ((and (memq 'decimal-digit-value attributes)
950 (setq value (get-char-attribute char 'decimal-digit-value)))
951 (insert (format "(decimal-digit-value . %S)%s"
954 (setq attributes (delq 'decimal-digit-value attributes))
955 (when (and (memq 'digit-value attributes)
956 (setq value (get-char-attribute char 'digit-value)))
957 (insert (format "(digit-value\t . %S)%s"
960 (setq attributes (delq 'digit-value attributes))
962 (when (and (memq 'numeric-value attributes)
963 (setq value (get-char-attribute char 'numeric-value)))
964 (insert (format "(numeric-value\t . %S)%s"
967 (setq attributes (delq 'numeric-value attributes))
971 (when (and (memq 'digit-value attributes)
972 (setq value (get-char-attribute char 'digit-value)))
973 (insert (format "(digit-value\t. %S)%s"
976 (setq attributes (delq 'digit-value attributes))
978 (when (and (memq 'numeric-value attributes)
979 (setq value (get-char-attribute char 'numeric-value)))
980 (insert (format "(numeric-value\t. %S)%s"
983 (setq attributes (delq 'numeric-value attributes))
985 (when (and (memq 'iso-10646-comment attributes)
986 (setq value (get-char-attribute char 'iso-10646-comment)))
987 (insert (format "(iso-10646-comment\t. %S)%s"
990 (setq attributes (delq 'iso-10646-comment attributes))
992 (when (and (memq 'morohashi-daikanwa attributes)
993 (setq value (get-char-attribute char 'morohashi-daikanwa)))
994 (insert (format "(morohashi-daikanwa\t%s)%s"
995 (mapconcat (function prin1-to-string) value " ")
997 (setq attributes (delq 'morohashi-daikanwa attributes))
1001 (when (and (memq 'ideographic-radical attributes)
1002 (setq value (get-char-attribute char 'ideographic-radical)))
1003 (setq radical value)
1004 (insert (format "(ideographic-radical . %S)\t; %c%s"
1006 (ideographic-radical radical)
1008 (setq attributes (delq 'ideographic-radical attributes))
1010 (when (and (memq 'shuowen-radical attributes)
1011 (setq value (get-char-attribute char 'shuowen-radical)))
1012 (insert (format "(shuowen-radical\t. %S)\t; %c%s"
1014 (shuowen-radical value)
1016 (setq attributes (delq 'shuowen-radical attributes))
1021 char-db-feature-domains
1023 (dolist (feature (char-attribute-list))
1024 (setq feature (symbol-name feature))
1026 "\\(radical\\|strokes\\)@\\([^@*]+\\)\\(\\*\\|$\\)"
1028 (setq domain (intern (match-string 2 feature)))
1029 (unless (memq domain dest)
1030 (setq dest (cons domain dest)))))
1031 (sort dest #'string<))))
1032 (setq key (intern (format "%s@%s" 'ideographic-radical domain)))
1033 (when (and (memq key attributes)
1034 (setq value (get-char-attribute char key)))
1035 (setq radical value)
1036 (insert (format "(%s . %S)\t; %c%s"
1039 (ideographic-radical radical)
1041 (setq attributes (delq key attributes))
1043 (setq key (intern (format "%s@%s" 'ideographic-strokes domain)))
1044 (when (and (memq key attributes)
1045 (setq value (get-char-attribute char key)))
1046 (setq strokes value)
1047 (insert (format "(%s . %S)%s"
1051 (setq attributes (delq key attributes))
1053 (setq key (intern (format "%s@%s" 'total-strokes domain)))
1054 (when (and (memq key attributes)
1055 (setq value (get-char-attribute char key)))
1056 (insert (format "(%s . %S)%s"
1060 (setq attributes (delq key attributes))
1062 (dolist (feature '(ideographic-radical
1065 (setq key (intern (format "%s@%s*sources" feature domain)))
1066 (when (and (memq key attributes)
1067 (setq value (get-char-attribute char key)))
1068 (insert (format "(%s%s" key line-breaking))
1069 (dolist (cell value)
1070 (insert (format " %s" cell)))
1072 (insert line-breaking)
1073 (setq attributes (delq key attributes))
1076 (when (and (memq 'ideographic-strokes attributes)
1077 (setq value (get-char-attribute char 'ideographic-strokes)))
1078 (setq strokes value)
1079 (insert (format "(ideographic-strokes . %S)%s"
1082 (setq attributes (delq 'ideographic-strokes attributes))
1084 (when (and (memq 'kangxi-radical attributes)
1085 (setq value (get-char-attribute char 'kangxi-radical)))
1086 (unless (eq value radical)
1087 (insert (format "(kangxi-radical\t . %S)\t; %c%s"
1089 (ideographic-radical value)
1092 (setq radical value)))
1093 (setq attributes (delq 'kangxi-radical attributes))
1095 (when (and (memq 'kangxi-strokes attributes)
1096 (setq value (get-char-attribute char 'kangxi-strokes)))
1097 (unless (eq value strokes)
1098 (insert (format "(kangxi-strokes\t . %S)%s"
1102 (setq strokes value)))
1103 (setq attributes (delq 'kangxi-strokes attributes))
1105 (when (and (memq 'japanese-radical attributes)
1106 (setq value (get-char-attribute char 'japanese-radical)))
1107 (unless (eq value radical)
1108 (insert (format "(japanese-radical\t . %S)\t; %c%s"
1110 (ideographic-radical value)
1113 (setq radical value)))
1114 (setq attributes (delq 'japanese-radical attributes))
1116 (when (and (memq 'japanese-strokes attributes)
1117 (setq value (get-char-attribute char 'japanese-strokes)))
1118 (unless (eq value strokes)
1119 (insert (format "(japanese-strokes\t . %S)%s"
1123 (setq strokes value)))
1124 (setq attributes (delq 'japanese-strokes attributes))
1126 (when (and (memq 'cns-radical attributes)
1127 (setq value (get-char-attribute char 'cns-radical)))
1128 (insert (format "(cns-radical\t . %S)\t; %c%s"
1130 (ideographic-radical value)
1132 (setq attributes (delq 'cns-radical attributes))
1134 (when (and (memq 'cns-strokes attributes)
1135 (setq value (get-char-attribute char 'cns-strokes)))
1136 (unless (eq value strokes)
1137 (insert (format "(cns-strokes\t . %S)%s"
1141 (setq strokes value)))
1142 (setq attributes (delq 'cns-strokes attributes))
1144 ;; (when (and (memq 'shinjigen-1-radical attributes)
1145 ;; (setq value (get-char-attribute char 'shinjigen-1-radical)))
1146 ;; (unless (eq value radical)
1147 ;; (insert (format "(shinjigen-1-radical . %S)\t; %c%s"
1149 ;; (ideographic-radical value)
1152 ;; (setq radical value)))
1153 ;; (setq attributes (delq 'shinjigen-1-radical attributes))
1155 (when (and (memq 'ideographic- attributes)
1156 (setq value (get-char-attribute char 'ideographic-)))
1157 (insert "(ideographic- ")
1158 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1160 (while (consp value)
1161 (setq cell (car value))
1163 (setq cell (decode-char '=ucs cell)))
1164 (cond ((characterp cell)
1168 (insert (format "%S" cell))
1169 (char-db-insert-char-spec cell readable))
1170 (setq separator lbs))
1174 (if (consp (car cell))
1175 (char-db-insert-char-spec cell readable)
1176 (char-db-insert-char-reference cell readable))
1177 (setq separator lbs))
1181 (insert (prin1-to-string cell))
1182 (setq separator " ")))
1183 (setq value (cdr value)))
1185 (insert line-breaking)
1186 (setq attributes (delq 'ideographic- attributes)))
1187 (when (and (memq 'total-strokes attributes)
1188 (setq value (get-char-attribute char 'total-strokes)))
1189 (insert (format "(total-strokes . %S)%s"
1192 (setq attributes (delq 'total-strokes attributes))
1194 (when (and (memq '->ideograph attributes)
1195 (setq value (get-char-attribute char '->ideograph)))
1196 (insert (format "(->ideograph\t%s)%s"
1197 (mapconcat (lambda (code)
1198 (cond ((symbolp code)
1201 (format "#x%04X" code))
1204 line-breaking code))))
1207 (setq attributes (delq '->ideograph attributes))
1209 ;; (when (and (memq '->decomposition attributes)
1210 ;; (setq value (get-char-attribute char '->decomposition)))
1211 ;; (insert (format "(->decomposition\t%s)%s"
1212 ;; (mapconcat (lambda (code)
1213 ;; (cond ((symbolp code)
1214 ;; (symbol-name code))
1215 ;; ((characterp code)
1217 ;; (format "%S" code)
1222 ;; (format "#x%04X" code))
1224 ;; (format "%s%S" line-breaking code))))
1227 ;; (setq attributes (delq '->decomposition attributes))
1229 (if (equal (get-char-attribute char '->titlecase)
1230 (get-char-attribute char '->uppercase))
1231 (setq attributes (delq '->titlecase attributes)))
1232 (when (and (memq '->mojikyo attributes)
1233 (setq value (get-char-attribute char '->mojikyo)))
1234 (insert (format "(->mojikyo\t\t. %06d)\t; %c%s"
1235 value (decode-char 'mojikyo value)
1237 (setq attributes (delq '->mojikyo attributes))
1239 (when (and (memq 'hanyu-dazidian-vol attributes)
1240 (setq value (get-char-attribute char 'hanyu-dazidian-vol)))
1241 (insert (format "(hanyu-dazidian-vol . %d)%s"
1242 value line-breaking))
1243 (setq attributes (delq 'hanyu-dazidian-vol attributes))
1245 (when (and (memq 'hanyu-dazidian-page attributes)
1246 (setq value (get-char-attribute char 'hanyu-dazidian-page)))
1247 (insert (format "(hanyu-dazidian-page . %d)%s"
1248 value line-breaking))
1249 (setq attributes (delq 'hanyu-dazidian-page attributes))
1251 (when (and (memq 'hanyu-dazidian-char attributes)
1252 (setq value (get-char-attribute char 'hanyu-dazidian-char)))
1253 (insert (format "(hanyu-dazidian-char . %d)%s"
1254 value line-breaking))
1255 (setq attributes (delq 'hanyu-dazidian-char attributes))
1258 (dolist (ignored '(composition
1259 ->denotational <-subsumptive ->ucs-unified
1260 ->ideographic-component-forms))
1261 (setq attributes (delq ignored attributes))))
1263 (setq name (car attributes))
1264 (unless (eq (setq value (get-char-attribute char name 'value-is-empty))
1266 (cond ((setq ret (find-charset name))
1267 (setq name (charset-name ret))
1268 (when (not (memq name dest-ccss))
1269 (setq dest-ccss (cons name dest-ccss))
1270 (char-db-insert-ccs-feature name value line-breaking))
1272 ((string-match "^=>ucs@" (symbol-name name))
1273 (insert (format "(%-18s . #x%04X)\t; %c%s"
1274 name value (decode-char '=ucs value)
1277 ((eq name 'jisx0208-1978/4X)
1278 (insert (format "(%-18s . #x%04X)%s"
1284 (not (eq name '->subsumptive))
1285 (not (eq name '->uppercase))
1286 (not (eq name '->lowercase))
1287 (not (eq name '->titlecase))
1288 (not (eq name '->canonical))
1289 (not (eq name '->Bopomofo))
1290 (not (eq name '->mistakable))
1291 (not (eq name '->ideographic-variants))
1292 (null (get-char-attribute
1293 char (intern (format "%s*sources" name))))
1294 (not (string-match "\\*sources$" (symbol-name name)))
1295 (null (get-char-attribute
1296 char (intern (format "%s*note" name))))
1297 (not (string-match "\\*note$" (symbol-name name)))
1298 (or (eq name '<-identical)
1299 (eq name '<-uppercase)
1300 (eq name '<-lowercase)
1301 (eq name '<-titlecase)
1302 (eq name '<-canonical)
1303 (eq name '<-ideographic-variants)
1304 ;; (eq name '<-synonyms)
1305 (string-match "^<-synonyms" (symbol-name name))
1306 (eq name '<-mistakable)
1307 (when (string-match "^->" (symbol-name name))
1309 ((string-match "^->fullwidth" (symbol-name name))
1310 (not (and (consp value)
1311 (characterp (car value))
1313 (car value) '=ucs 'defined-only)))
1318 ((or (eq name 'ideographic-structure)
1319 (eq name 'ideographic-combination)
1320 (eq name 'ideographic-)
1321 (eq name '=decomposition)
1322 (char-feature-base-name= '=decomposition name)
1323 (char-feature-base-name= '=>decomposition name)
1324 ;; (string-match "^=>*decomposition\\(@[^*]+\\)?$"
1325 ;; (symbol-name name))
1326 (string-match "^\\(->\\|<-\\)[^*]*$" (symbol-name name))
1327 (string-match "^\\(->\\|<-\\)[^*]*\\*sources$"
1330 (char-db-insert-relation-feature char name value
1333 ((memq name '(ideograph=
1334 original-ideograph-of
1335 ancient-ideograph-of
1338 ;; simplified-ideograph-of
1339 ideographic-variants
1340 ;; ideographic-different-form-of
1342 (insert (format "(%-18s%s " name line-breaking))
1343 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1345 (while (consp value)
1346 (setq cell (car value))
1347 (if (and (consp cell)
1352 (char-db-insert-alist cell readable)
1353 (setq separator lbs))
1356 (insert (prin1-to-string cell))
1357 (setq separator " "))
1358 (setq value (cdr value)))
1360 (insert line-breaking))
1362 (insert (format "(%-18s " name))
1363 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1365 (while (consp value)
1366 (setq cell (car value))
1367 (if (and (consp cell)
1369 (setq ret (condition-case nil
1377 (setq key (car (car rest)))
1378 (if (find-charset key)
1379 (setq cal (cons key cal))
1380 (setq al (cons key al)))
1381 (setq rest (cdr rest)))
1384 (insert-char-attributes ret
1388 (setq separator lbs))
1389 (setq ret (prin1-to-string cell))
1391 (if (< (+ (current-column)
1398 (setq separator " "))
1399 (setq value (cdr value)))
1401 (insert line-breaking))
1403 (insert (format "(%-18s" name))
1404 (setq ret (prin1-to-string value))
1405 (unless (< (+ (current-column)
1409 (insert line-breaking))
1410 (insert " . " ret ")" line-breaking)
1411 ;; (insert (format "(%-18s . %S)%s"
1416 (setq attributes (cdr attributes)))
1419 (defun insert-char-data (char &optional readable
1422 (narrow-to-region (point)(point))
1423 (insert "(define-char
1425 (insert-char-attributes char readable attributes)
1427 (goto-char (point-min))
1428 (while (re-search-forward "[ \t]+$" nil t)
1431 (goto-char (point-min))
1432 (while (re-search-forward "[ \t][ \t][ \t]*" nil t)
1433 (let ((column (current-column))
1434 (indent-tabs-mode t))
1435 (delete-region (match-beginning 0) (point))
1436 (indent-to column)))
1437 (goto-char (point-max))
1438 ;; (tabify (point-min)(point-max))
1441 (defun insert-char-data-with-variant (char &optional printable
1443 script excluded-script)
1444 (insert-char-data char printable)
1445 (let ((variants (char-variants char))
1448 (setq variants (sort variants #'<))
1449 (setq rest variants)
1450 (setq variants (cons char variants))
1452 (setq variant (car rest))
1453 (unless (get-char-attribute variant '<-subsumptive)
1454 (if (and (or (null script)
1455 (null (setq vs (get-char-attribute variant 'script)))
1457 (or (null excluded-script)
1458 (null (setq vs (get-char-attribute variant 'script)))
1459 (not (memq excluded-script vs))))
1460 (unless (and no-ucs-unified (get-char-attribute variant '=ucs))
1461 (insert-char-data variant printable)
1462 (if (setq ret (char-variants variant))
1464 (or (memq (car ret) variants)
1465 ;; (get-char-attribute (car ret) '<-subsumptive)
1466 (setq rest (nconc rest (list (car ret)))))
1467 (setq ret (cdr ret)))))))
1468 (setq rest (cdr rest)))))
1470 (defun insert-char-range-data (min max &optional script excluded-script)
1473 (while (<= code max)
1474 (setq char (decode-char '=ucs code))
1475 (if (encode-char char '=ucs 'defined-only)
1476 (insert-char-data-with-variant char nil 'no-ucs-unified
1477 script excluded-script))
1478 (setq code (1+ code)))))
1480 (defun write-char-range-data-to-file (min max file
1481 &optional script excluded-script)
1482 (let ((coding-system-for-write char-db-file-coding-system))
1484 (insert (format ";; -*- coding: %s -*-\n"
1485 char-db-file-coding-system))
1486 (insert-char-range-data min max script excluded-script)
1487 (write-region (point-min)(point-max) file))))
1489 (defvar what-character-original-window-configuration)
1492 (defun what-char-definition (char)
1493 (interactive (list (char-after)))
1494 (let ((buf (get-buffer-create "*Character Description*"))
1495 (the-buf (current-buffer))
1496 (win-conf (current-window-configuration)))
1498 (make-local-variable 'what-character-original-window-configuration)
1499 (setq what-character-original-window-configuration win-conf)
1500 (setq buffer-read-only nil)
1504 (insert-char-data-with-variant char 'printable)
1505 (unless (char-attribute-alist char)
1506 (insert (format ";; = %c\n"
1507 (let* ((rest (split-char char))
1511 (setq code (logior (lsh code 8)
1513 (decode-char ccs code)))))
1514 ;; (char-db-update-comment)
1515 (set-buffer-modified-p nil)
1516 (view-mode the-buf (lambda (buf)
1517 (set-window-configuration
1518 what-character-original-window-configuration)
1520 (goto-char (point-min)))
1522 (set-window-configuration
1523 what-character-original-window-configuration)
1524 (signal (car err) (cdr err)))))))
1530 (provide 'char-db-util)
1532 ;;; char-db-util.el ends here