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
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
209 ;; =>>>adobe-japan1-0
210 ;; =>>>adobe-japan1-1
211 ;; =>>>adobe-japan1-2
212 ;; =>>>adobe-japan1-3
213 ;; =>>>adobe-japan1-4
214 ;; =>>>adobe-japan1-5
215 ;; =>>>adobe-japan1-6
219 ;; =>>>hanyo-denshi/ja
220 ;; =>>>hanyo-denshi/jb
221 ;; =>>>hanyo-denshi/jc
222 ;; =>>>hanyo-denshi/ft
223 ;; =>>>hanyo-denshi/ib
224 ;; =>>>hanyo-denshi/hg
225 ;; =>>>hanyo-denshi/jt
226 ;; =>>>hanyo-denshi/ks
328 ;;; @ char-db formatters
331 (defun char-db-make-char-spec (char)
333 (cond ((characterp char)
334 (cond ((and (setq ret (encode-char char '=ucs 'defined-only))
335 (not (and (<= #xE000 ret)(<= ret #xF8FF))))
336 (setq char-spec (list (cons '=ucs ret)))
337 (cond ((setq ret (get-char-attribute char 'name))
338 (setq char-spec (cons (cons 'name ret) char-spec))
340 ((setq ret (get-char-attribute char 'name*))
341 (setq char-spec (cons (cons 'name* ret) char-spec))
344 ((encode-char char '=mj 'defined-only)
346 (dolist (ccs (charset-list))
347 (if (and (or (eq ccs '=mj)
348 ;; (eq (charset-property ccs 'iso-ir) 177)
349 (string-match "=ucs@" (symbol-name ccs))
351 (setq ccs (charset-name ccs))
352 (null (assq ccs char-spec))
353 (setq ret (encode-char char ccs 'defined-only)))
354 (setq char-spec (cons (cons ccs ret) char-spec))))
356 ((encode-char char '==mj 'defined-only)
358 (dolist (ccs (charset-list))
359 (if (and (or (eq ccs '==mj)
360 ;; (eq (charset-property ccs 'iso-ir) 177)
361 (string-match "=ucs@" (symbol-name ccs))
363 (setq ccs (charset-name ccs))
364 (null (assq ccs char-spec))
365 (setq ret (encode-char char ccs 'defined-only)))
366 (setq char-spec (cons (cons ccs ret) char-spec))))
368 ((encode-char char '=adobe-japan1 'defined-only)
370 (dolist (ccs (charset-list))
371 (if (and (or (memq ccs
380 ;; (eq (charset-property ccs 'iso-ir) 177)
381 (string-match "=ucs@" (symbol-name ccs))
383 (setq ccs (charset-name ccs))
384 (null (assq ccs char-spec))
385 (setq ret (encode-char char ccs 'defined-only)))
386 (setq char-spec (cons (cons ccs ret) char-spec))))
388 ((encode-char char '==adobe-japan1 'defined-only)
390 (dolist (ccs (charset-list))
391 (if (and (or (memq ccs
400 ;; (eq (charset-property ccs 'iso-ir) 177)
401 (string-match "=ucs@" (symbol-name ccs))
403 (setq ccs (charset-name ccs))
404 (null (assq ccs char-spec))
405 (setq ret (encode-char char ccs 'defined-only)))
406 (setq char-spec (cons (cons ccs ret) char-spec))))
410 (let ((rest char-db-coded-charset-priority-list)
413 (setq ccs (charset-name
414 (find-charset (car rest))))
416 (encode-char char ccs
418 (throw 'tag (cons ccs ret)))
419 (setq rest (cdr rest))))))
420 (setq char-spec (list ret))
421 (dolist (ccs (delq (car ret) (charset-list)))
422 (if (and (or (charset-iso-final-char ccs)
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 (setq char-spec (split-char char)))
438 (cond ((setq ret (get-char-attribute char 'name))
439 (setq char-spec (cons (cons 'name ret) char-spec))
441 ((setq ret (get-char-attribute char 'name*))
442 (setq char-spec (cons (cons 'name* ret) char-spec))
445 ((setq ret (get-char-attribute
446 char 'ideographic-combination))
448 (cons (cons 'ideographic-combination ret)
455 (defun char-db-insert-char-spec (char &optional readable column
458 (setq column (current-column)))
459 (let (char-spec temp-char)
460 (setq char-spec (char-db-make-char-spec char))
461 (unless (or (characterp char) ; char
463 (setq char (find-char char-spec))
465 ;; define temporary character
466 ;; Current implementation is dirty.
467 (setq temp-char (define-char (cons '(ideograph-daikanwa . 0)
469 (remove-char-attribute temp-char 'ideograph-daikanwa)
470 (setq char temp-char))
471 (insert-char-attributes char
473 (union (mapcar #'car char-spec)
477 ;; undefine temporary character
478 ;; Current implementation is dirty.
479 (setq char-spec (char-attribute-alist temp-char))
481 (remove-char-attribute temp-char (car (car char-spec)))
482 (setq char-spec (cdr char-spec))))))
484 (defun char-db-insert-alist (alist &optional readable column)
486 (setq column (current-column)))
488 (concat "\n" (make-string (1+ column) ?\ )))
492 lbs cell rest separator)
495 (setq name (car (car alist))
496 value (cdr (car alist)))
497 (cond ((eq name 'char)
499 (if (setq ret (condition-case nil
507 (setq key (car (car value)))
508 ;; (if (find-charset key)
509 ;; (setq cal (cons key cal))
510 (setq al (cons key al))
512 (setq value (cdr value)))
513 (insert-char-attributes ret
517 (insert (prin1-to-string value)))
519 (insert line-breaking))
521 (insert (format "(%-18s " name))
522 (setq lbs (concat "\n" (make-string (current-column) ?\ )))
524 (setq cell (car value))
525 (if (and (consp cell)
527 (setq ret (condition-case nil
537 (setq key (car (car rest)))
538 ;; (if (find-charset key)
539 ;; (setq cal (cons key cal))
540 (setq al (cons key al))
542 (setq rest (cdr rest)))
545 (insert-char-attributes ret
549 (setq separator lbs))
552 (insert (prin1-to-string cell))
553 (setq separator " "))
554 (setq value (cdr value)))
556 (insert line-breaking))
558 (insert (format "(%-18s . %S)%s"
561 (setq alist (cdr alist))))
564 (defun char-db-insert-char-reference (plist &optional readable column)
566 (setq column (current-column)))
568 (concat "\n" (make-string (1+ column) ?\ )))
573 (setq name (pop plist))
574 (setq value (pop plist))
575 (cond ((eq name :char)
578 (cond ((numberp value)
579 (setq value (decode-char '=ucs value)))
581 ;; (setq value (or (find-char value)
584 (char-db-insert-char-spec value readable)
585 (insert line-breaking)
588 (insert (format "%s%s\t%d ; %c%s"
591 (ideographic-radical value)
595 (insert (format "%s%s\t%S" separator name value))
596 (setq separator line-breaking)))
600 (defun char-db-decode-isolated-char (ccs code-point)
603 (cond ((eq ccs 'arabic-iso8859-6)
604 (decode-char ccs code-point))
606 ;; (decode-builtin-char '==gt code-point))
607 ((and (memq ccs '(=gt-pj-1
618 (setq ret (decode-char ccs code-point))
619 (setq ret (encode-char ret '=gt 'defined-only)))
620 (decode-builtin-char '=gt ret))
622 (decode-builtin-char ccs code-point))))
623 (cond ((and (<= 0 (char-int ret))
624 (<= (char-int ret) #x1F))
625 (decode-char '=ucs (+ #x2400 (char-int ret))))
626 ((= (char-int ret) #x7F)
630 (defvar char-db-convert-obsolete-format t)
632 (defun char-db-insert-ccs-feature (name value line-breaking)
638 ((memq name '(==shinjigen
640 =shinjigen@1ed ==shinjigen@1ed
641 =shinjigen@rev ==shinjigen@rev
642 =shinjigen/+p@rev ==shinjigen/+p@rev
643 ===daikanwa/ho ==daikanwa/ho
644 =daikanwa/ho =>>daikanwa/ho =>daikanwa/ho))
645 "(%-18s . %04d)\t; %c")
646 ((eq name '=shinjigen@1ed/24pr)
647 "(%-18s . %04d)\t; %c")
648 ((or (memq name '(===daikanwa
649 ==daikanwa =daikanwa =>>daikanwa =>daikanwa
650 =daikanwa@rev1 =daikanwa@rev2
651 =daikanwa/+p ==daikanwa/+p ===daikanwa/+p
653 =daikanwa/+2p =>>daikanwa/+2p
658 =adobe-japan1-0 ==adobe-japan1-0 ===adobe-japan1-0
659 =adobe-japan1-1 ==adobe-japan1-1 ===adobe-japan1-1
660 =adobe-japan1-2 ==adobe-japan1-2 ===adobe-japan1-2
661 =adobe-japan1-3 ==adobe-japan1-3 ===adobe-japan1-3
662 =adobe-japan1-4 ==adobe-japan1-4 ===adobe-japan1-4
663 =adobe-japan1-5 ==adobe-japan1-5 ===adobe-japan1-5
664 =adobe-japan1-6 ==adobe-japan1-6 ===adobe-japan1-6
665 =>>adobe-japan1-0 =+>adobe-japan1-0
666 =>>adobe-japan1-1 =+>adobe-japan1-1
667 =>>adobe-japan1-2 =+>adobe-japan1-2
668 =>>adobe-japan1-3 =+>adobe-japan1-3
669 =>>adobe-japan1-4 =+>adobe-japan1-4
670 =>>adobe-japan1-5 =+>adobe-japan1-5
671 =>>adobe-japan1-6 =+>adobe-japan1-6
672 =>cbeta =cbeta =>>cbeta ==cbeta ===cbeta
673 =zinbun-oracle =>zinbun-oracle))
674 ;; (string-match "^=adobe-" (symbol-name name))
676 "(%-18s . %05d)\t; %c")
677 ((memq name '(=hanyo-denshi/ks
678 ==hanyo-denshi/ks ===hanyo-denshi/ks
683 "(%-18s . %06d)\t; %c")
684 ((>= (charset-dimension name) 2)
685 "(%-18s . #x%04X)\t; %c")
687 "(%-18s . #x%02X)\t; %c"))
689 (if (= (charset-iso-graphic-plane name) 1)
691 (cond ((= (charset-dimension name) 1)
693 ((= (charset-dimension name) 2)
695 ((= (charset-dimension name) 3)
699 (char-db-decode-isolated-char name value)))
700 (if (and (= (charset-chars name) 94)
701 (= (charset-dimension name) 2))
702 (insert (format " [%02d-%02d]"
703 (- (lsh value -8) 32)
704 (- (logand value 255) 32))))
707 (insert (format "(%-18s . %s)" name value))
709 (insert line-breaking))
711 (defun char-db-insert-relation-feature (char name value line-breaking
713 (insert (format "(%-18s%s " name line-breaking))
714 (let ((lbs (concat "\n" (make-string (current-column) ?\ )))
715 separator cell sources required-features
718 (setq cell (car value))
720 (setq cell (decode-char '=ucs cell)))
722 ((eq name '->subsumptive)
723 (when (or (not (some (lambda (atr)
724 (get-char-attribute cell atr))
725 char-db-ignored-attributes))
727 (encode-char cell ccs 'defined-only))
731 (let ((char-db-ignored-attributes
733 char-db-ignored-attributes)))
734 (insert-char-attributes cell readable nil nil 'for-sub-node))
735 (setq separator lbs))
740 char (intern (format "%s*sources" name))))
741 (setq required-features nil)
742 (dolist (source sources)
746 shinjigen shinjigen@1ed shinjigen@rev))
747 (setq required-features
748 (union required-features
760 =shinjigen/+p@rev))))
762 (setq required-features
763 (union required-features
768 ((find-charset (setq ret (intern (format "=%s" source))))
769 (setq required-features
770 (cons ret required-features)))
771 (t (setq required-features
772 (cons source required-features)))))
773 (cond ((string-match "@JP" (symbol-name name))
774 (setq required-features
775 (union required-features
783 ((string-match "@CN" (symbol-name name))
784 (setq required-features
785 (union required-features
792 (insert (format "%S" cell))
793 (char-db-insert-char-spec cell readable
796 (setq separator lbs))
800 (if (consp (car cell))
801 (char-db-insert-char-spec cell readable)
802 (char-db-insert-char-reference cell readable))
803 (setq separator lbs))
807 (insert (prin1-to-string cell))
808 (setq separator " ")))
809 (setq value (cdr value)))
811 (insert line-breaking)))
813 (defun insert-char-attributes (char &optional readable attributes column
816 (setq column (current-column)))
817 (let (name value ; has-long-ccs-name
821 (concat "\n" (make-string (1+ column) ?\ )))
822 lbs cell separator ret
824 dest-ccss ; sources required-features
829 (if (consp attributes)
831 (dolist (name attributes)
832 (unless (memq name char-db-ignored-attributes)
833 (if (find-charset name)
837 (dolist (name (char-attribute-list))
838 (unless (memq name char-db-ignored-attributes)
839 (if (find-charset name)
843 #'char-attribute-name<)))
845 (when (memq '<-subsumptive attributes)
846 (when (or readable (not for-sub-node))
847 (when (setq value (get-char-attribute char '<-subsumptive))
848 (char-db-insert-relation-feature char '<-subsumptive value
851 (setq attributes (delq '<-subsumptive attributes)))
852 (when (and (memq '<-denotational attributes)
853 (setq value (get-char-attribute char '<-denotational)))
854 (char-db-insert-relation-feature char '<-denotational value
857 (setq attributes (delq '<-denotational attributes)))
858 (when (and (memq 'name attributes)
859 (setq value (get-char-attribute char 'name)))
861 (if (> (+ (current-column) (length value)) 48)
864 value line-breaking))
865 (setq attributes (delq 'name attributes))
867 (when (and (memq 'name* attributes)
868 (setq value (get-char-attribute char 'name*)))
870 (if (> (+ (current-column) (length value)) 48)
873 value line-breaking))
874 (setq attributes (delq 'name* attributes))
876 (when (and (memq 'script attributes)
877 (setq value (get-char-attribute char 'script)))
878 (insert (format "(script\t\t%s)%s"
879 (mapconcat (function prin1-to-string)
882 (setq attributes (delq 'script attributes))
884 (dolist (name '(=>ucs =>ucs*))
885 (when (and (memq name attributes)
886 (setq value (get-char-attribute char name)))
887 (insert (format "(%-18s . #x%04X)\t; %c%s"
888 name value (decode-char '=ucs value)
890 (setq attributes (delq name attributes))))
891 (dolist (name '(=>ucs@gb =>ucs@big5))
892 (when (and (memq name attributes)
893 (setq value (get-char-attribute char name)))
894 (insert (format "(%-18s . #x%04X)\t; %c%s"
899 (symbol-name name) 2)))
902 (setq attributes (delq name attributes))
904 ;; (dolist (name '(=>daikanwa))
905 ;; (when (and (memq name attributes)
906 ;; (setq value (get-char-attribute char name)))
908 ;; (if (integerp value)
909 ;; (format "(%-18s . %05d)\t; %c%s"
910 ;; name value (decode-char '=daikanwa value)
912 ;; (format "(%-18s %s)\t; %c%s"
914 ;; (mapconcat (function prin1-to-string)
916 ;; (char-representative-of-daikanwa char)
918 ;; (setq attributes (delq name attributes))))
919 (when (and (memq 'general-category attributes)
920 (setq value (get-char-attribute char 'general-category)))
922 "(general-category\t%s) ; %s%s"
923 (mapconcat (lambda (cell)
926 (cond ((rassoc value unidata-normative-category-alist)
927 "Normative Category")
928 ((rassoc value unidata-informative-category-alist)
929 "Informative Category")
933 (setq attributes (delq 'general-category attributes))
935 (when (and (memq 'bidi-category attributes)
936 (setq value (get-char-attribute char 'bidi-category)))
937 (insert (format "(bidi-category\t. %S)%s"
940 (setq attributes (delq 'bidi-category attributes))
942 (unless (or (not (memq 'mirrored attributes))
943 (eq (setq value (get-char-attribute char 'mirrored 'empty))
945 (insert (format "(mirrored\t\t. %S)%s"
948 (setq attributes (delq 'mirrored attributes))
951 ((and (memq 'decimal-digit-value attributes)
952 (setq value (get-char-attribute char 'decimal-digit-value)))
953 (insert (format "(decimal-digit-value . %S)%s"
956 (setq attributes (delq 'decimal-digit-value attributes))
957 (when (and (memq 'digit-value attributes)
958 (setq value (get-char-attribute char 'digit-value)))
959 (insert (format "(digit-value\t . %S)%s"
962 (setq attributes (delq 'digit-value attributes))
964 (when (and (memq 'numeric-value attributes)
965 (setq value (get-char-attribute char 'numeric-value)))
966 (insert (format "(numeric-value\t . %S)%s"
969 (setq attributes (delq 'numeric-value attributes))
973 (when (and (memq 'digit-value attributes)
974 (setq value (get-char-attribute char 'digit-value)))
975 (insert (format "(digit-value\t. %S)%s"
978 (setq attributes (delq 'digit-value attributes))
980 (when (and (memq 'numeric-value attributes)
981 (setq value (get-char-attribute char 'numeric-value)))
982 (insert (format "(numeric-value\t. %S)%s"
985 (setq attributes (delq 'numeric-value attributes))
987 (when (and (memq 'iso-10646-comment attributes)
988 (setq value (get-char-attribute char 'iso-10646-comment)))
989 (insert (format "(iso-10646-comment\t. %S)%s"
992 (setq attributes (delq 'iso-10646-comment attributes))
994 (when (and (memq 'morohashi-daikanwa attributes)
995 (setq value (get-char-attribute char 'morohashi-daikanwa)))
996 (insert (format "(morohashi-daikanwa\t%s)%s"
997 (mapconcat (function prin1-to-string) value " ")
999 (setq attributes (delq 'morohashi-daikanwa attributes))
1003 (when (and (memq 'ideographic-radical attributes)
1004 (setq value (get-char-attribute char 'ideographic-radical)))
1005 (setq radical value)
1006 (insert (format "(ideographic-radical . %S)\t; %c%s"
1008 (ideographic-radical radical)
1010 (setq attributes (delq 'ideographic-radical attributes))
1012 (when (and (memq 'shuowen-radical attributes)
1013 (setq value (get-char-attribute char 'shuowen-radical)))
1014 (insert (format "(shuowen-radical\t. %S)\t; %c%s"
1016 (shuowen-radical value)
1018 (setq attributes (delq 'shuowen-radical attributes))
1023 char-db-feature-domains
1025 (dolist (feature (char-attribute-list))
1026 (setq feature (symbol-name feature))
1028 "\\(radical\\|strokes\\)@\\([^@*]+\\)\\(\\*\\|$\\)"
1030 (setq domain (intern (match-string 2 feature)))
1031 (unless (memq domain dest)
1032 (setq dest (cons domain dest)))))
1033 (sort dest #'string<))))
1034 (setq key (intern (format "%s@%s" 'ideographic-radical domain)))
1035 (when (and (memq key attributes)
1036 (setq value (get-char-attribute char key)))
1037 (setq radical value)
1038 (insert (format "(%s . %S)\t; %c%s"
1041 (ideographic-radical radical)
1043 (setq attributes (delq key attributes))
1045 (setq key (intern (format "%s@%s" 'ideographic-strokes domain)))
1046 (when (and (memq key attributes)
1047 (setq value (get-char-attribute char key)))
1048 (setq strokes value)
1049 (insert (format "(%s . %S)%s"
1053 (setq attributes (delq key attributes))
1055 (setq key (intern (format "%s@%s" 'total-strokes domain)))
1056 (when (and (memq key attributes)
1057 (setq value (get-char-attribute char key)))
1058 (insert (format "(%s . %S)%s"
1062 (setq attributes (delq key attributes))
1064 (dolist (feature '(ideographic-radical
1067 (setq key (intern (format "%s@%s*sources" feature domain)))
1068 (when (and (memq key attributes)
1069 (setq value (get-char-attribute char key)))
1070 (insert (format "(%s%s" key line-breaking))
1071 (dolist (cell value)
1072 (insert (format " %s" cell)))
1074 (insert line-breaking)
1075 (setq attributes (delq key attributes))
1078 (when (and (memq 'ideographic-strokes attributes)
1079 (setq value (get-char-attribute char 'ideographic-strokes)))
1080 (setq strokes value)
1081 (insert (format "(ideographic-strokes . %S)%s"
1084 (setq attributes (delq 'ideographic-strokes attributes))
1086 (when (and (memq 'kangxi-radical attributes)
1087 (setq value (get-char-attribute char 'kangxi-radical)))
1088 (unless (eq value radical)
1089 (insert (format "(kangxi-radical\t . %S)\t; %c%s"
1091 (ideographic-radical value)
1094 (setq radical value)))
1095 (setq attributes (delq 'kangxi-radical attributes))
1097 (when (and (memq 'kangxi-strokes attributes)
1098 (setq value (get-char-attribute char 'kangxi-strokes)))
1099 (unless (eq value strokes)
1100 (insert (format "(kangxi-strokes\t . %S)%s"
1104 (setq strokes value)))
1105 (setq attributes (delq 'kangxi-strokes attributes))
1107 (when (and (memq 'japanese-radical attributes)
1108 (setq value (get-char-attribute char 'japanese-radical)))
1109 (unless (eq value radical)
1110 (insert (format "(japanese-radical\t . %S)\t; %c%s"
1112 (ideographic-radical value)
1115 (setq radical value)))
1116 (setq attributes (delq 'japanese-radical attributes))
1118 (when (and (memq 'japanese-strokes attributes)
1119 (setq value (get-char-attribute char 'japanese-strokes)))
1120 (unless (eq value strokes)
1121 (insert (format "(japanese-strokes\t . %S)%s"
1125 (setq strokes value)))
1126 (setq attributes (delq 'japanese-strokes attributes))
1128 (when (and (memq 'cns-radical attributes)
1129 (setq value (get-char-attribute char 'cns-radical)))
1130 (insert (format "(cns-radical\t . %S)\t; %c%s"
1132 (ideographic-radical value)
1134 (setq attributes (delq 'cns-radical attributes))
1136 (when (and (memq 'cns-strokes attributes)
1137 (setq value (get-char-attribute char 'cns-strokes)))
1138 (unless (eq value strokes)
1139 (insert (format "(cns-strokes\t . %S)%s"
1143 (setq strokes value)))
1144 (setq attributes (delq 'cns-strokes attributes))
1146 ;; (when (and (memq 'shinjigen-1-radical attributes)
1147 ;; (setq value (get-char-attribute char 'shinjigen-1-radical)))
1148 ;; (unless (eq value radical)
1149 ;; (insert (format "(shinjigen-1-radical . %S)\t; %c%s"
1151 ;; (ideographic-radical value)
1154 ;; (setq radical value)))
1155 ;; (setq attributes (delq 'shinjigen-1-radical attributes))
1157 (when (and (memq 'ideographic- attributes)
1158 (setq value (get-char-attribute char 'ideographic-)))
1159 (insert "(ideographic- ")
1160 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1162 (while (consp value)
1163 (setq cell (car value))
1165 (setq cell (decode-char '=ucs cell)))
1166 (cond ((characterp cell)
1170 (insert (format "%S" cell))
1171 (char-db-insert-char-spec cell readable))
1172 (setq separator lbs))
1176 (if (consp (car cell))
1177 (char-db-insert-char-spec cell readable)
1178 (char-db-insert-char-reference cell readable))
1179 (setq separator lbs))
1183 (insert (prin1-to-string cell))
1184 (setq separator " ")))
1185 (setq value (cdr value)))
1187 (insert line-breaking)
1188 (setq attributes (delq 'ideographic- attributes)))
1189 (when (and (memq 'total-strokes attributes)
1190 (setq value (get-char-attribute char 'total-strokes)))
1191 (insert (format "(total-strokes . %S)%s"
1194 (setq attributes (delq 'total-strokes attributes))
1196 (when (and (memq '->ideograph attributes)
1197 (setq value (get-char-attribute char '->ideograph)))
1198 (insert (format "(->ideograph\t%s)%s"
1199 (mapconcat (lambda (code)
1200 (cond ((symbolp code)
1203 (format "#x%04X" code))
1206 line-breaking code))))
1209 (setq attributes (delq '->ideograph attributes))
1211 ;; (when (and (memq '->decomposition attributes)
1212 ;; (setq value (get-char-attribute char '->decomposition)))
1213 ;; (insert (format "(->decomposition\t%s)%s"
1214 ;; (mapconcat (lambda (code)
1215 ;; (cond ((symbolp code)
1216 ;; (symbol-name code))
1217 ;; ((characterp code)
1219 ;; (format "%S" code)
1224 ;; (format "#x%04X" code))
1226 ;; (format "%s%S" line-breaking code))))
1229 ;; (setq attributes (delq '->decomposition attributes))
1231 (if (equal (get-char-attribute char '->titlecase)
1232 (get-char-attribute char '->uppercase))
1233 (setq attributes (delq '->titlecase attributes)))
1234 (when (and (memq '->mojikyo attributes)
1235 (setq value (get-char-attribute char '->mojikyo)))
1236 (insert (format "(->mojikyo\t\t. %06d)\t; %c%s"
1237 value (decode-char 'mojikyo value)
1239 (setq attributes (delq '->mojikyo attributes))
1241 (when (and (memq 'hanyu-dazidian-vol attributes)
1242 (setq value (get-char-attribute char 'hanyu-dazidian-vol)))
1243 (insert (format "(hanyu-dazidian-vol . %d)%s"
1244 value line-breaking))
1245 (setq attributes (delq 'hanyu-dazidian-vol attributes))
1247 (when (and (memq 'hanyu-dazidian-page attributes)
1248 (setq value (get-char-attribute char 'hanyu-dazidian-page)))
1249 (insert (format "(hanyu-dazidian-page . %d)%s"
1250 value line-breaking))
1251 (setq attributes (delq 'hanyu-dazidian-page attributes))
1253 (when (and (memq 'hanyu-dazidian-char attributes)
1254 (setq value (get-char-attribute char 'hanyu-dazidian-char)))
1255 (insert (format "(hanyu-dazidian-char . %d)%s"
1256 value line-breaking))
1257 (setq attributes (delq 'hanyu-dazidian-char attributes))
1260 (dolist (ignored '(composition
1261 ->denotational <-subsumptive ->ucs-unified
1262 ->ideographic-component-forms))
1263 (setq attributes (delq ignored attributes))))
1265 (setq name (car attributes))
1266 (unless (eq (setq value (get-char-attribute char name 'value-is-empty))
1268 (cond ((setq ret (find-charset name))
1269 (setq name (charset-name ret))
1270 (when (not (memq name dest-ccss))
1271 (setq dest-ccss (cons name dest-ccss))
1272 (char-db-insert-ccs-feature name value line-breaking))
1274 ((string-match "^=>ucs@" (symbol-name name))
1275 (insert (format "(%-18s . #x%04X)\t; %c%s"
1276 name value (decode-char '=ucs value)
1279 ((eq name 'jisx0208-1978/4X)
1280 (insert (format "(%-18s . #x%04X)%s"
1286 (not (eq name '->subsumptive))
1287 (not (eq name '->uppercase))
1288 (not (eq name '->lowercase))
1289 (not (eq name '->titlecase))
1290 (not (eq name '->canonical))
1291 (not (eq name '->Bopomofo))
1292 (not (eq name '->mistakable))
1293 (not (eq name '->ideographic-variants))
1294 (null (get-char-attribute
1295 char (intern (format "%s*sources" name))))
1296 (not (string-match "\\*sources$" (symbol-name name)))
1297 (null (get-char-attribute
1298 char (intern (format "%s*note" name))))
1299 (not (string-match "\\*note$" (symbol-name name)))
1300 (or (eq name '<-identical)
1301 (eq name '<-uppercase)
1302 (eq name '<-lowercase)
1303 (eq name '<-titlecase)
1304 (eq name '<-canonical)
1305 (eq name '<-ideographic-variants)
1306 ;; (eq name '<-synonyms)
1307 (string-match "^<-synonyms" (symbol-name name))
1308 (eq name '<-mistakable)
1309 (when (string-match "^->" (symbol-name name))
1311 ((string-match "^->fullwidth" (symbol-name name))
1312 (not (and (consp value)
1313 (characterp (car value))
1315 (car value) '=ucs 'defined-only)))
1320 ((or (eq name 'ideographic-structure)
1321 (eq name 'ideographic-combination)
1322 (eq name 'ideographic-)
1323 (eq name '=decomposition)
1324 (char-feature-base-name= '=decomposition name)
1325 (char-feature-base-name= '=>decomposition name)
1326 ;; (string-match "^=>*decomposition\\(@[^*]+\\)?$"
1327 ;; (symbol-name name))
1328 (string-match "^\\(->\\|<-\\)[^*]*$" (symbol-name name))
1329 (string-match "^\\(->\\|<-\\)[^*]*\\*sources$"
1332 (char-db-insert-relation-feature char name value
1335 ((memq name '(ideograph=
1336 original-ideograph-of
1337 ancient-ideograph-of
1340 ;; simplified-ideograph-of
1341 ideographic-variants
1342 ;; ideographic-different-form-of
1344 (insert (format "(%-18s%s " name line-breaking))
1345 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1347 (while (consp value)
1348 (setq cell (car value))
1349 (if (and (consp cell)
1354 (char-db-insert-alist cell readable)
1355 (setq separator lbs))
1358 (insert (prin1-to-string cell))
1359 (setq separator " "))
1360 (setq value (cdr value)))
1362 (insert line-breaking))
1364 (insert (format "(%-18s " name))
1365 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1367 (while (consp value)
1368 (setq cell (car value))
1369 (if (and (consp cell)
1371 (setq ret (condition-case nil
1379 (setq key (car (car rest)))
1380 (if (find-charset key)
1381 (setq cal (cons key cal))
1382 (setq al (cons key al)))
1383 (setq rest (cdr rest)))
1386 (insert-char-attributes ret
1390 (setq separator lbs))
1391 (setq ret (prin1-to-string cell))
1393 (if (< (+ (current-column)
1400 (setq separator " "))
1401 (setq value (cdr value)))
1403 (insert line-breaking))
1405 (insert (format "(%-18s" name))
1406 (setq ret (prin1-to-string value))
1407 (unless (< (+ (current-column)
1411 (insert line-breaking))
1412 (insert " . " ret ")" line-breaking)
1413 ;; (insert (format "(%-18s . %S)%s"
1418 (setq attributes (cdr attributes)))
1421 (defun insert-char-data (char &optional readable
1424 (narrow-to-region (point)(point))
1425 (insert "(define-char
1427 (insert-char-attributes char readable attributes)
1429 (goto-char (point-min))
1430 (while (re-search-forward "[ \t]+$" nil t)
1433 (goto-char (point-min))
1434 (while (re-search-forward "[ \t][ \t][ \t]*" nil t)
1435 (let ((column (current-column))
1436 (indent-tabs-mode t))
1437 (delete-region (match-beginning 0) (point))
1438 (indent-to column)))
1439 (goto-char (point-max))
1440 ;; (tabify (point-min)(point-max))
1443 (defun insert-char-data-with-variant (char &optional printable
1445 script excluded-script)
1446 (insert-char-data char printable)
1447 (let ((variants (char-variants char))
1450 (setq variants (sort variants #'<))
1451 (setq rest variants)
1452 (setq variants (cons char variants))
1454 (setq variant (car rest))
1455 (unless (get-char-attribute variant '<-subsumptive)
1456 (if (and (or (null script)
1457 (null (setq vs (get-char-attribute variant 'script)))
1459 (or (null excluded-script)
1460 (null (setq vs (get-char-attribute variant 'script)))
1461 (not (memq excluded-script vs))))
1462 (unless (and no-ucs-unified (get-char-attribute variant '=ucs))
1463 (insert-char-data variant printable)
1464 (if (setq ret (char-variants variant))
1466 (or (memq (car ret) variants)
1467 ;; (get-char-attribute (car ret) '<-subsumptive)
1468 (setq rest (nconc rest (list (car ret)))))
1469 (setq ret (cdr ret)))))))
1470 (setq rest (cdr rest)))))
1472 (defun insert-char-range-data (min max &optional script excluded-script)
1475 (while (<= code max)
1476 (setq char (decode-char '=ucs code))
1477 (if (encode-char char '=ucs 'defined-only)
1478 (insert-char-data-with-variant char nil 'no-ucs-unified
1479 script excluded-script))
1480 (setq code (1+ code)))))
1482 (defun write-char-range-data-to-file (min max file
1483 &optional script excluded-script)
1484 (let ((coding-system-for-write char-db-file-coding-system))
1486 (insert (format ";; -*- coding: %s -*-\n"
1487 char-db-file-coding-system))
1488 (insert-char-range-data min max script excluded-script)
1489 (write-region (point-min)(point-max) file))))
1491 (defvar what-character-original-window-configuration)
1494 (defun what-char-definition (char)
1495 (interactive (list (char-after)))
1496 (let ((buf (get-buffer-create "*Character Description*"))
1497 (the-buf (current-buffer))
1498 (win-conf (current-window-configuration)))
1500 (make-local-variable 'what-character-original-window-configuration)
1501 (setq what-character-original-window-configuration win-conf)
1502 (setq buffer-read-only nil)
1506 (insert-char-data-with-variant char 'printable)
1507 (unless (char-attribute-alist char)
1508 (insert (format ";; = %c\n"
1509 (let* ((rest (split-char char))
1513 (setq code (logior (lsh code 8)
1515 (decode-char ccs code)))))
1516 ;; (char-db-update-comment)
1517 (set-buffer-modified-p nil)
1518 (view-mode the-buf (lambda (buf)
1519 (set-window-configuration
1520 what-character-original-window-configuration)
1522 (goto-char (point-min)))
1524 (set-window-configuration
1525 what-character-original-window-configuration)
1526 (signal (car err) (cdr err)))))))
1532 (provide 'char-db-util)
1534 ;;; char-db-util.el ends here