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
104 (defun shuowen-radical (number)
105 (aref shuowen-radicals (1- number)))
107 (defvar char-db-file-coding-system 'utf-8-mcs-er)
109 (defvar char-db-ignored-attributes '(ideographic-products))
111 (defvar char-db-coded-charset-priority-list
204 ;; =>>>adobe-japan1-0
205 ;; =>>>adobe-japan1-1
206 ;; =>>>adobe-japan1-2
207 ;; =>>>adobe-japan1-3
208 ;; =>>>adobe-japan1-4
209 ;; =>>>adobe-japan1-5
210 ;; =>>>adobe-japan1-6
214 ;; =>>>hanyo-denshi/ja
215 ;; =>>>hanyo-denshi/jb
216 ;; =>>>hanyo-denshi/jc
217 ;; =>>>hanyo-denshi/ft
218 ;; =>>>hanyo-denshi/ib
219 ;; =>>>hanyo-denshi/hg
220 ;; =>>>hanyo-denshi/jt
221 ;; =>>>hanyo-denshi/ks
321 ;;; @ char-db formatters
324 (defun char-db-make-char-spec (char)
326 (cond ((characterp char)
327 (cond ((and (setq ret (encode-char char '=ucs 'defined-only))
328 (not (and (<= #xE000 ret)(<= ret #xF8FF))))
329 (setq char-spec (list (cons '=ucs ret)))
330 (cond ((setq ret (get-char-attribute char 'name))
331 (setq char-spec (cons (cons 'name ret) char-spec))
333 ((setq ret (get-char-attribute char 'name*))
334 (setq char-spec (cons (cons 'name* ret) char-spec))
337 ((encode-char char '=mj 'defined-only)
339 (dolist (ccs (charset-list))
340 (if (and (or (eq ccs '=mj)
341 ;; (eq (charset-property ccs 'iso-ir) 177)
342 (string-match "=ucs@" (symbol-name ccs))
344 (setq ccs (charset-name ccs))
345 (null (assq ccs char-spec))
346 (setq ret (encode-char char ccs 'defined-only)))
347 (setq char-spec (cons (cons ccs ret) char-spec))))
349 ((encode-char char '==mj 'defined-only)
351 (dolist (ccs (charset-list))
352 (if (and (or (eq ccs '==mj)
353 ;; (eq (charset-property ccs 'iso-ir) 177)
354 (string-match "=ucs@" (symbol-name ccs))
356 (setq ccs (charset-name ccs))
357 (null (assq ccs char-spec))
358 (setq ret (encode-char char ccs 'defined-only)))
359 (setq char-spec (cons (cons ccs ret) char-spec))))
361 ((encode-char char '=adobe-japan1 'defined-only)
363 (dolist (ccs (charset-list))
364 (if (and (or (memq ccs
373 ;; (eq (charset-property ccs 'iso-ir) 177)
374 (string-match "=ucs@" (symbol-name ccs))
376 (setq ccs (charset-name ccs))
377 (null (assq ccs char-spec))
378 (setq ret (encode-char char ccs 'defined-only)))
379 (setq char-spec (cons (cons ccs ret) char-spec))))
381 ((encode-char char '==adobe-japan1 'defined-only)
383 (dolist (ccs (charset-list))
384 (if (and (or (memq ccs
393 ;; (eq (charset-property ccs 'iso-ir) 177)
394 (string-match "=ucs@" (symbol-name ccs))
396 (setq ccs (charset-name ccs))
397 (null (assq ccs char-spec))
398 (setq ret (encode-char char ccs 'defined-only)))
399 (setq char-spec (cons (cons ccs ret) char-spec))))
403 (let ((rest char-db-coded-charset-priority-list)
406 (setq ccs (charset-name
407 (find-charset (car rest))))
409 (encode-char char ccs
411 (throw 'tag (cons ccs ret)))
412 (setq rest (cdr rest))))))
413 (setq char-spec (list ret))
414 (dolist (ccs (delq (car ret) (charset-list)))
415 (if (and (or (charset-iso-final-char ccs)
422 (eq (charset-property ccs 'iso-ir) 177)
423 ;; (string-match "=ucs@" (symbol-name ccs))
425 (setq ccs (charset-name ccs))
426 (null (assq ccs char-spec))
427 (setq ret (encode-char char ccs 'defined-only)))
428 (setq char-spec (cons (cons ccs ret) char-spec))))
430 (setq char-spec (split-char char)))
431 (cond ((setq ret (get-char-attribute char 'name))
432 (setq char-spec (cons (cons 'name ret) char-spec))
434 ((setq ret (get-char-attribute char 'name*))
435 (setq char-spec (cons (cons 'name* ret) char-spec))
438 ((setq ret (get-char-attribute
439 char 'ideographic-combination))
441 (cons (cons 'ideographic-combination ret)
448 (defun char-db-insert-char-spec (char &optional readable column
451 (setq column (current-column)))
452 (let (char-spec temp-char)
453 (setq char-spec (char-db-make-char-spec char))
454 (unless (or (characterp char) ; char
456 (setq char (find-char char-spec))
458 ;; define temporary character
459 ;; Current implementation is dirty.
460 (setq temp-char (define-char (cons '(ideograph-daikanwa . 0)
462 (remove-char-attribute temp-char 'ideograph-daikanwa)
463 (setq char temp-char))
464 (insert-char-attributes char
466 (union (mapcar #'car char-spec)
470 ;; undefine temporary character
471 ;; Current implementation is dirty.
472 (setq char-spec (char-attribute-alist temp-char))
474 (remove-char-attribute temp-char (car (car char-spec)))
475 (setq char-spec (cdr char-spec))))))
477 (defun char-db-insert-alist (alist &optional readable column)
479 (setq column (current-column)))
481 (concat "\n" (make-string (1+ column) ?\ )))
485 lbs cell rest separator)
488 (setq name (car (car alist))
489 value (cdr (car alist)))
490 (cond ((eq name 'char)
492 (if (setq ret (condition-case nil
500 (setq key (car (car value)))
501 ;; (if (find-charset key)
502 ;; (setq cal (cons key cal))
503 (setq al (cons key al))
505 (setq value (cdr value)))
506 (insert-char-attributes ret
510 (insert (prin1-to-string value)))
512 (insert line-breaking))
514 (insert (format "(%-18s " name))
515 (setq lbs (concat "\n" (make-string (current-column) ?\ )))
517 (setq cell (car value))
518 (if (and (consp cell)
520 (setq ret (condition-case nil
530 (setq key (car (car rest)))
531 ;; (if (find-charset key)
532 ;; (setq cal (cons key cal))
533 (setq al (cons key al))
535 (setq rest (cdr rest)))
538 (insert-char-attributes ret
542 (setq separator lbs))
545 (insert (prin1-to-string cell))
546 (setq separator " "))
547 (setq value (cdr value)))
549 (insert line-breaking))
551 (insert (format "(%-18s . %S)%s"
554 (setq alist (cdr alist))))
557 (defun char-db-insert-char-reference (plist &optional readable column)
559 (setq column (current-column)))
561 (concat "\n" (make-string (1+ column) ?\ )))
566 (setq name (pop plist))
567 (setq value (pop plist))
568 (cond ((eq name :char)
571 (cond ((numberp value)
572 (setq value (decode-char '=ucs value)))
574 ;; (setq value (or (find-char value)
577 (char-db-insert-char-spec value readable)
578 (insert line-breaking)
581 (insert (format "%s%s\t%d ; %c%s"
584 (ideographic-radical value)
588 (insert (format "%s%s\t%S" separator name value))
589 (setq separator line-breaking)))
593 (defun char-db-decode-isolated-char (ccs code-point)
596 (cond ((eq ccs 'arabic-iso8859-6)
597 (decode-char ccs code-point))
599 ;; (decode-builtin-char '==gt code-point))
600 ((and (memq ccs '(=gt-pj-1
611 (setq ret (decode-char ccs code-point))
612 (setq ret (encode-char ret '=gt 'defined-only)))
613 (decode-builtin-char '=gt ret))
615 (decode-builtin-char ccs code-point))))
616 (cond ((and (<= 0 (char-int ret))
617 (<= (char-int ret) #x1F))
618 (decode-char '=ucs (+ #x2400 (char-int ret))))
619 ((= (char-int ret) #x7F)
623 (defvar char-db-convert-obsolete-format t)
625 (defun char-db-insert-ccs-feature (name value line-breaking)
631 ((memq name '(==shinjigen
633 =shinjigen@1ed ==shinjigen@1ed
634 =shinjigen@rev ==shinjigen@rev
635 =shinjigen/+p@rev ==shinjigen/+p@rev
636 ===daikanwa/ho ==daikanwa/ho
637 =daikanwa/ho =>>daikanwa/ho =>daikanwa/ho))
638 "(%-18s . %04d)\t; %c")
639 ((eq name '=shinjigen@1ed/24pr)
640 "(%-18s . %04d)\t; %c")
641 ((or (memq name '(===daikanwa
642 ==daikanwa =daikanwa =>>daikanwa =>daikanwa
643 =daikanwa@rev1 =daikanwa@rev2
644 =daikanwa/+p ==daikanwa/+p =>>daikanwa/+p
645 =daikanwa/+2p =>>daikanwa/+2p
650 =adobe-japan1-0 ==adobe-japan1-0 ===adobe-japan1-0
651 =adobe-japan1-1 ==adobe-japan1-1 ===adobe-japan1-1
652 =adobe-japan1-2 ==adobe-japan1-2 ===adobe-japan1-2
653 =adobe-japan1-3 ==adobe-japan1-3 ===adobe-japan1-3
654 =adobe-japan1-4 ==adobe-japan1-4 ===adobe-japan1-4
655 =adobe-japan1-5 ==adobe-japan1-5 ===adobe-japan1-5
656 =adobe-japan1-6 ==adobe-japan1-6 ===adobe-japan1-6
657 =>>adobe-japan1-0 =+>adobe-japan1-0
658 =>>adobe-japan1-1 =+>adobe-japan1-1
659 =>>adobe-japan1-2 =+>adobe-japan1-2
660 =>>adobe-japan1-3 =+>adobe-japan1-3
661 =>>adobe-japan1-4 =+>adobe-japan1-4
662 =>>adobe-japan1-5 =+>adobe-japan1-5
663 =>>adobe-japan1-6 =+>adobe-japan1-6
664 =cbeta ==cbeta ===cbeta =>>cbeta
665 =zinbun-oracle =>zinbun-oracle))
666 ;; (string-match "^=adobe-" (symbol-name name))
668 "(%-18s . %05d)\t; %c")
669 ((memq name '(=hanyo-denshi/ks
670 ==hanyo-denshi/ks ===hanyo-denshi/ks
675 "(%-18s . %06d)\t; %c")
676 ((>= (charset-dimension name) 2)
677 "(%-18s . #x%04X)\t; %c")
679 "(%-18s . #x%02X)\t; %c"))
681 (if (= (charset-iso-graphic-plane name) 1)
683 (cond ((= (charset-dimension name) 1)
685 ((= (charset-dimension name) 2)
687 ((= (charset-dimension name) 3)
691 (char-db-decode-isolated-char name value)))
692 (if (and (= (charset-chars name) 94)
693 (= (charset-dimension name) 2))
694 (insert (format " [%02d-%02d]"
695 (- (lsh value -8) 32)
696 (- (logand value 255) 32))))
699 (insert (format "(%-18s . %s)" name value))
701 (insert line-breaking))
703 (defun char-db-insert-relation-feature (char name value line-breaking
705 (insert (format "(%-18s%s " name line-breaking))
706 (let ((lbs (concat "\n" (make-string (current-column) ?\ )))
707 separator cell sources required-features
710 (setq cell (car value))
712 (setq cell (decode-char '=ucs cell)))
714 ((eq name '->subsumptive)
715 (when (or (not (some (lambda (atr)
716 (get-char-attribute cell atr))
717 char-db-ignored-attributes))
719 (encode-char cell ccs 'defined-only))
723 (let ((char-db-ignored-attributes
725 char-db-ignored-attributes)))
726 (insert-char-attributes cell readable nil nil 'for-sub-node))
727 (setq separator lbs))
732 char (intern (format "%s*sources" name))))
733 (setq required-features nil)
734 (dolist (source sources)
738 shinjigen shinjigen@1ed shinjigen@rev))
739 (setq required-features
740 (union required-features
752 =shinjigen/+p@rev))))
754 (setq required-features
755 (union required-features
760 ((find-charset (setq ret (intern (format "=%s" source))))
761 (setq required-features
762 (cons ret required-features)))
763 (t (setq required-features
764 (cons source required-features)))))
765 (cond ((string-match "@JP" (symbol-name name))
766 (setq required-features
767 (union required-features
775 ((string-match "@CN" (symbol-name name))
776 (setq required-features
777 (union required-features
784 (insert (format "%S" cell))
785 (char-db-insert-char-spec cell readable
788 (setq separator lbs))
792 (if (consp (car cell))
793 (char-db-insert-char-spec cell readable)
794 (char-db-insert-char-reference cell readable))
795 (setq separator lbs))
799 (insert (prin1-to-string cell))
800 (setq separator " ")))
801 (setq value (cdr value)))
803 (insert line-breaking)))
805 (defun insert-char-attributes (char &optional readable attributes column
808 (setq column (current-column)))
809 (let (name value ; has-long-ccs-name
813 (concat "\n" (make-string (1+ column) ?\ )))
814 lbs cell separator ret
816 dest-ccss ; sources required-features
821 (if (consp attributes)
823 (dolist (name attributes)
824 (unless (memq name char-db-ignored-attributes)
825 (if (find-charset name)
829 (dolist (name (char-attribute-list))
830 (unless (memq name char-db-ignored-attributes)
831 (if (find-charset name)
835 #'char-attribute-name<)))
837 (when (memq '<-subsumptive attributes)
838 (when (or readable (not for-sub-node))
839 (when (setq value (get-char-attribute char '<-subsumptive))
840 (char-db-insert-relation-feature char '<-subsumptive value
843 (setq attributes (delq '<-subsumptive attributes)))
844 (when (and (memq '<-denotational attributes)
845 (setq value (get-char-attribute char '<-denotational)))
846 (char-db-insert-relation-feature char '<-denotational value
849 (setq attributes (delq '<-denotational attributes)))
850 (when (and (memq 'name attributes)
851 (setq value (get-char-attribute char 'name)))
853 (if (> (+ (current-column) (length value)) 48)
856 value line-breaking))
857 (setq attributes (delq 'name attributes))
859 (when (and (memq 'name* attributes)
860 (setq value (get-char-attribute char 'name*)))
862 (if (> (+ (current-column) (length value)) 48)
865 value line-breaking))
866 (setq attributes (delq 'name* attributes))
868 (when (and (memq 'script attributes)
869 (setq value (get-char-attribute char 'script)))
870 (insert (format "(script\t\t%s)%s"
871 (mapconcat (function prin1-to-string)
874 (setq attributes (delq 'script attributes))
876 (dolist (name '(=>ucs =>ucs*))
877 (when (and (memq name attributes)
878 (setq value (get-char-attribute char name)))
879 (insert (format "(%-18s . #x%04X)\t; %c%s"
880 name value (decode-char '=ucs value)
882 (setq attributes (delq name attributes))))
883 (dolist (name '(=>ucs@gb =>ucs@big5))
884 (when (and (memq name attributes)
885 (setq value (get-char-attribute char name)))
886 (insert (format "(%-18s . #x%04X)\t; %c%s"
891 (symbol-name name) 2)))
894 (setq attributes (delq name attributes))
896 ;; (dolist (name '(=>daikanwa))
897 ;; (when (and (memq name attributes)
898 ;; (setq value (get-char-attribute char name)))
900 ;; (if (integerp value)
901 ;; (format "(%-18s . %05d)\t; %c%s"
902 ;; name value (decode-char '=daikanwa value)
904 ;; (format "(%-18s %s)\t; %c%s"
906 ;; (mapconcat (function prin1-to-string)
908 ;; (char-representative-of-daikanwa char)
910 ;; (setq attributes (delq name attributes))))
911 (when (and (memq 'general-category attributes)
912 (setq value (get-char-attribute char 'general-category)))
914 "(general-category\t%s) ; %s%s"
915 (mapconcat (lambda (cell)
918 (cond ((rassoc value unidata-normative-category-alist)
919 "Normative Category")
920 ((rassoc value unidata-informative-category-alist)
921 "Informative Category")
925 (setq attributes (delq 'general-category attributes))
927 (when (and (memq 'bidi-category attributes)
928 (setq value (get-char-attribute char 'bidi-category)))
929 (insert (format "(bidi-category\t. %S)%s"
932 (setq attributes (delq 'bidi-category attributes))
934 (unless (or (not (memq 'mirrored attributes))
935 (eq (setq value (get-char-attribute char 'mirrored 'empty))
937 (insert (format "(mirrored\t\t. %S)%s"
940 (setq attributes (delq 'mirrored attributes))
943 ((and (memq 'decimal-digit-value attributes)
944 (setq value (get-char-attribute char 'decimal-digit-value)))
945 (insert (format "(decimal-digit-value . %S)%s"
948 (setq attributes (delq 'decimal-digit-value attributes))
949 (when (and (memq 'digit-value attributes)
950 (setq value (get-char-attribute char 'digit-value)))
951 (insert (format "(digit-value\t . %S)%s"
954 (setq attributes (delq 'digit-value attributes))
956 (when (and (memq 'numeric-value attributes)
957 (setq value (get-char-attribute char 'numeric-value)))
958 (insert (format "(numeric-value\t . %S)%s"
961 (setq attributes (delq 'numeric-value attributes))
965 (when (and (memq 'digit-value attributes)
966 (setq value (get-char-attribute char 'digit-value)))
967 (insert (format "(digit-value\t. %S)%s"
970 (setq attributes (delq 'digit-value attributes))
972 (when (and (memq 'numeric-value attributes)
973 (setq value (get-char-attribute char 'numeric-value)))
974 (insert (format "(numeric-value\t. %S)%s"
977 (setq attributes (delq 'numeric-value attributes))
979 (when (and (memq 'iso-10646-comment attributes)
980 (setq value (get-char-attribute char 'iso-10646-comment)))
981 (insert (format "(iso-10646-comment\t. %S)%s"
984 (setq attributes (delq 'iso-10646-comment attributes))
986 (when (and (memq 'morohashi-daikanwa attributes)
987 (setq value (get-char-attribute char 'morohashi-daikanwa)))
988 (insert (format "(morohashi-daikanwa\t%s)%s"
989 (mapconcat (function prin1-to-string) value " ")
991 (setq attributes (delq 'morohashi-daikanwa attributes))
995 (when (and (memq 'ideographic-radical attributes)
996 (setq value (get-char-attribute char 'ideographic-radical)))
998 (insert (format "(ideographic-radical . %S)\t; %c%s"
1000 (ideographic-radical radical)
1002 (setq attributes (delq 'ideographic-radical attributes))
1004 (when (and (memq 'shuowen-radical attributes)
1005 (setq value (get-char-attribute char 'shuowen-radical)))
1006 (insert (format "(shuowen-radical\t. %S)\t; %c%s"
1008 (shuowen-radical value)
1010 (setq attributes (delq 'shuowen-radical attributes))
1015 char-db-feature-domains
1017 (dolist (feature (char-attribute-list))
1018 (setq feature (symbol-name feature))
1020 "\\(radical\\|strokes\\)@\\([^@*]+\\)\\(\\*\\|$\\)"
1022 (setq domain (intern (match-string 2 feature)))
1023 (unless (memq domain dest)
1024 (setq dest (cons domain dest)))))
1025 (sort dest #'string<))))
1026 (setq key (intern (format "%s@%s" 'ideographic-radical domain)))
1027 (when (and (memq key attributes)
1028 (setq value (get-char-attribute char key)))
1029 (setq radical value)
1030 (insert (format "(%s . %S)\t; %c%s"
1033 (ideographic-radical radical)
1035 (setq attributes (delq key attributes))
1037 (setq key (intern (format "%s@%s" 'ideographic-strokes domain)))
1038 (when (and (memq key attributes)
1039 (setq value (get-char-attribute char key)))
1040 (setq strokes value)
1041 (insert (format "(%s . %S)%s"
1045 (setq attributes (delq key attributes))
1047 (setq key (intern (format "%s@%s" 'total-strokes domain)))
1048 (when (and (memq key attributes)
1049 (setq value (get-char-attribute char key)))
1050 (insert (format "(%s . %S)%s"
1054 (setq attributes (delq key attributes))
1056 (dolist (feature '(ideographic-radical
1059 (setq key (intern (format "%s@%s*sources" feature domain)))
1060 (when (and (memq key attributes)
1061 (setq value (get-char-attribute char key)))
1062 (insert (format "(%s%s" key line-breaking))
1063 (dolist (cell value)
1064 (insert (format " %s" cell)))
1066 (insert line-breaking)
1067 (setq attributes (delq key attributes))
1070 (when (and (memq 'ideographic-strokes attributes)
1071 (setq value (get-char-attribute char 'ideographic-strokes)))
1072 (setq strokes value)
1073 (insert (format "(ideographic-strokes . %S)%s"
1076 (setq attributes (delq 'ideographic-strokes attributes))
1078 (when (and (memq 'kangxi-radical attributes)
1079 (setq value (get-char-attribute char 'kangxi-radical)))
1080 (unless (eq value radical)
1081 (insert (format "(kangxi-radical\t . %S)\t; %c%s"
1083 (ideographic-radical value)
1086 (setq radical value)))
1087 (setq attributes (delq 'kangxi-radical attributes))
1089 (when (and (memq 'kangxi-strokes attributes)
1090 (setq value (get-char-attribute char 'kangxi-strokes)))
1091 (unless (eq value strokes)
1092 (insert (format "(kangxi-strokes\t . %S)%s"
1096 (setq strokes value)))
1097 (setq attributes (delq 'kangxi-strokes attributes))
1099 (when (and (memq 'japanese-radical attributes)
1100 (setq value (get-char-attribute char 'japanese-radical)))
1101 (unless (eq value radical)
1102 (insert (format "(japanese-radical\t . %S)\t; %c%s"
1104 (ideographic-radical value)
1107 (setq radical value)))
1108 (setq attributes (delq 'japanese-radical attributes))
1110 (when (and (memq 'japanese-strokes attributes)
1111 (setq value (get-char-attribute char 'japanese-strokes)))
1112 (unless (eq value strokes)
1113 (insert (format "(japanese-strokes\t . %S)%s"
1117 (setq strokes value)))
1118 (setq attributes (delq 'japanese-strokes attributes))
1120 (when (and (memq 'cns-radical attributes)
1121 (setq value (get-char-attribute char 'cns-radical)))
1122 (insert (format "(cns-radical\t . %S)\t; %c%s"
1124 (ideographic-radical value)
1126 (setq attributes (delq 'cns-radical attributes))
1128 (when (and (memq 'cns-strokes attributes)
1129 (setq value (get-char-attribute char 'cns-strokes)))
1130 (unless (eq value strokes)
1131 (insert (format "(cns-strokes\t . %S)%s"
1135 (setq strokes value)))
1136 (setq attributes (delq 'cns-strokes attributes))
1138 ;; (when (and (memq 'shinjigen-1-radical attributes)
1139 ;; (setq value (get-char-attribute char 'shinjigen-1-radical)))
1140 ;; (unless (eq value radical)
1141 ;; (insert (format "(shinjigen-1-radical . %S)\t; %c%s"
1143 ;; (ideographic-radical value)
1146 ;; (setq radical value)))
1147 ;; (setq attributes (delq 'shinjigen-1-radical attributes))
1149 (when (and (memq 'ideographic- attributes)
1150 (setq value (get-char-attribute char 'ideographic-)))
1151 (insert "(ideographic- ")
1152 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1154 (while (consp value)
1155 (setq cell (car value))
1157 (setq cell (decode-char '=ucs cell)))
1158 (cond ((characterp cell)
1162 (insert (format "%S" cell))
1163 (char-db-insert-char-spec cell readable))
1164 (setq separator lbs))
1168 (if (consp (car cell))
1169 (char-db-insert-char-spec cell readable)
1170 (char-db-insert-char-reference cell readable))
1171 (setq separator lbs))
1175 (insert (prin1-to-string cell))
1176 (setq separator " ")))
1177 (setq value (cdr value)))
1179 (insert line-breaking)
1180 (setq attributes (delq 'ideographic- attributes)))
1181 (when (and (memq 'total-strokes attributes)
1182 (setq value (get-char-attribute char 'total-strokes)))
1183 (insert (format "(total-strokes . %S)%s"
1186 (setq attributes (delq 'total-strokes attributes))
1188 (when (and (memq '->ideograph attributes)
1189 (setq value (get-char-attribute char '->ideograph)))
1190 (insert (format "(->ideograph\t%s)%s"
1191 (mapconcat (lambda (code)
1192 (cond ((symbolp code)
1195 (format "#x%04X" code))
1198 line-breaking code))))
1201 (setq attributes (delq '->ideograph attributes))
1203 ;; (when (and (memq '->decomposition attributes)
1204 ;; (setq value (get-char-attribute char '->decomposition)))
1205 ;; (insert (format "(->decomposition\t%s)%s"
1206 ;; (mapconcat (lambda (code)
1207 ;; (cond ((symbolp code)
1208 ;; (symbol-name code))
1209 ;; ((characterp code)
1211 ;; (format "%S" code)
1216 ;; (format "#x%04X" code))
1218 ;; (format "%s%S" line-breaking code))))
1221 ;; (setq attributes (delq '->decomposition attributes))
1223 (if (equal (get-char-attribute char '->titlecase)
1224 (get-char-attribute char '->uppercase))
1225 (setq attributes (delq '->titlecase attributes)))
1226 (when (and (memq '->mojikyo attributes)
1227 (setq value (get-char-attribute char '->mojikyo)))
1228 (insert (format "(->mojikyo\t\t. %06d)\t; %c%s"
1229 value (decode-char 'mojikyo value)
1231 (setq attributes (delq '->mojikyo attributes))
1233 (when (and (memq 'hanyu-dazidian-vol attributes)
1234 (setq value (get-char-attribute char 'hanyu-dazidian-vol)))
1235 (insert (format "(hanyu-dazidian-vol . %d)%s"
1236 value line-breaking))
1237 (setq attributes (delq 'hanyu-dazidian-vol attributes))
1239 (when (and (memq 'hanyu-dazidian-page attributes)
1240 (setq value (get-char-attribute char 'hanyu-dazidian-page)))
1241 (insert (format "(hanyu-dazidian-page . %d)%s"
1242 value line-breaking))
1243 (setq attributes (delq 'hanyu-dazidian-page attributes))
1245 (when (and (memq 'hanyu-dazidian-char attributes)
1246 (setq value (get-char-attribute char 'hanyu-dazidian-char)))
1247 (insert (format "(hanyu-dazidian-char . %d)%s"
1248 value line-breaking))
1249 (setq attributes (delq 'hanyu-dazidian-char attributes))
1252 (dolist (ignored '(composition
1253 ->denotational <-subsumptive ->ucs-unified
1254 ->ideographic-component-forms))
1255 (setq attributes (delq ignored attributes))))
1257 (setq name (car attributes))
1258 (unless (eq (setq value (get-char-attribute char name 'value-is-empty))
1260 (cond ((setq ret (find-charset name))
1261 (setq name (charset-name ret))
1262 (when (not (memq name dest-ccss))
1263 (setq dest-ccss (cons name dest-ccss))
1264 (char-db-insert-ccs-feature name value line-breaking))
1266 ((string-match "^=>ucs@" (symbol-name name))
1267 (insert (format "(%-18s . #x%04X)\t; %c%s"
1268 name value (decode-char '=ucs value)
1271 ((eq name 'jisx0208-1978/4X)
1272 (insert (format "(%-18s . #x%04X)%s"
1278 (not (eq name '->subsumptive))
1279 (not (eq name '->uppercase))
1280 (not (eq name '->lowercase))
1281 (not (eq name '->titlecase))
1282 (not (eq name '->canonical))
1283 (not (eq name '->Bopomofo))
1284 (not (eq name '->mistakable))
1285 (not (eq name '->ideographic-variants))
1286 (null (get-char-attribute
1287 char (intern (format "%s*sources" name))))
1288 (not (string-match "\\*sources$" (symbol-name name)))
1289 (null (get-char-attribute
1290 char (intern (format "%s*note" name))))
1291 (not (string-match "\\*note$" (symbol-name name)))
1292 (or (eq name '<-identical)
1293 (eq name '<-uppercase)
1294 (eq name '<-lowercase)
1295 (eq name '<-titlecase)
1296 (eq name '<-canonical)
1297 (eq name '<-ideographic-variants)
1298 ;; (eq name '<-synonyms)
1299 (string-match "^<-synonyms" (symbol-name name))
1300 (eq name '<-mistakable)
1301 (when (string-match "^->" (symbol-name name))
1303 ((string-match "^->fullwidth" (symbol-name name))
1304 (not (and (consp value)
1305 (characterp (car value))
1307 (car value) '=ucs 'defined-only)))
1312 ((or (eq name 'ideographic-structure)
1313 (eq name 'ideographic-combination)
1314 (eq name 'ideographic-)
1315 (eq name '=decomposition)
1316 (char-feature-base-name= '=decomposition name)
1317 (char-feature-base-name= '=>decomposition name)
1318 ;; (string-match "^=>*decomposition\\(@[^*]+\\)?$"
1319 ;; (symbol-name name))
1320 (string-match "^\\(->\\|<-\\)[^*]*$" (symbol-name name))
1321 (string-match "^\\(->\\|<-\\)[^*]*\\*sources$"
1324 (char-db-insert-relation-feature char name value
1327 ((memq name '(ideograph=
1328 original-ideograph-of
1329 ancient-ideograph-of
1332 ;; simplified-ideograph-of
1333 ideographic-variants
1334 ;; ideographic-different-form-of
1336 (insert (format "(%-18s%s " name line-breaking))
1337 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1339 (while (consp value)
1340 (setq cell (car value))
1341 (if (and (consp cell)
1346 (char-db-insert-alist cell readable)
1347 (setq separator lbs))
1350 (insert (prin1-to-string cell))
1351 (setq separator " "))
1352 (setq value (cdr value)))
1354 (insert line-breaking))
1356 (insert (format "(%-18s " name))
1357 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1359 (while (consp value)
1360 (setq cell (car value))
1361 (if (and (consp cell)
1363 (setq ret (condition-case nil
1371 (setq key (car (car rest)))
1372 (if (find-charset key)
1373 (setq cal (cons key cal))
1374 (setq al (cons key al)))
1375 (setq rest (cdr rest)))
1378 (insert-char-attributes ret
1382 (setq separator lbs))
1383 (setq ret (prin1-to-string cell))
1385 (if (< (+ (current-column)
1392 (setq separator " "))
1393 (setq value (cdr value)))
1395 (insert line-breaking))
1397 (insert (format "(%-18s" name))
1398 (setq ret (prin1-to-string value))
1399 (unless (< (+ (current-column)
1403 (insert line-breaking))
1404 (insert " . " ret ")" line-breaking)
1405 ;; (insert (format "(%-18s . %S)%s"
1410 (setq attributes (cdr attributes)))
1413 (defun insert-char-data (char &optional readable
1416 (narrow-to-region (point)(point))
1417 (insert "(define-char
1419 (insert-char-attributes char readable attributes)
1421 (goto-char (point-min))
1422 (while (re-search-forward "[ \t]+$" nil t)
1425 (goto-char (point-min))
1426 (while (re-search-forward "[ \t][ \t][ \t]*" nil t)
1427 (let ((column (current-column))
1428 (indent-tabs-mode t))
1429 (delete-region (match-beginning 0) (point))
1430 (indent-to column)))
1431 (goto-char (point-max))
1432 ;; (tabify (point-min)(point-max))
1435 (defun insert-char-data-with-variant (char &optional printable
1437 script excluded-script)
1438 (insert-char-data char printable)
1439 (let ((variants (char-variants char))
1442 (setq variants (sort variants #'<))
1443 (setq rest variants)
1444 (setq variants (cons char variants))
1446 (setq variant (car rest))
1447 (unless (get-char-attribute variant '<-subsumptive)
1448 (if (and (or (null script)
1449 (null (setq vs (get-char-attribute variant 'script)))
1451 (or (null excluded-script)
1452 (null (setq vs (get-char-attribute variant 'script)))
1453 (not (memq excluded-script vs))))
1454 (unless (and no-ucs-unified (get-char-attribute variant '=ucs))
1455 (insert-char-data variant printable)
1456 (if (setq ret (char-variants variant))
1458 (or (memq (car ret) variants)
1459 ;; (get-char-attribute (car ret) '<-subsumptive)
1460 (setq rest (nconc rest (list (car ret)))))
1461 (setq ret (cdr ret)))))))
1462 (setq rest (cdr rest)))))
1464 (defun insert-char-range-data (min max &optional script excluded-script)
1467 (while (<= code max)
1468 (setq char (decode-char '=ucs code))
1469 (if (encode-char char '=ucs 'defined-only)
1470 (insert-char-data-with-variant char nil 'no-ucs-unified
1471 script excluded-script))
1472 (setq code (1+ code)))))
1474 (defun write-char-range-data-to-file (min max file
1475 &optional script excluded-script)
1476 (let ((coding-system-for-write char-db-file-coding-system))
1478 (insert (format ";; -*- coding: %s -*-\n"
1479 char-db-file-coding-system))
1480 (insert-char-range-data min max script excluded-script)
1481 (write-region (point-min)(point-max) file))))
1483 (defvar what-character-original-window-configuration)
1486 (defun what-char-definition (char)
1487 (interactive (list (char-after)))
1488 (let ((buf (get-buffer-create "*Character Description*"))
1489 (the-buf (current-buffer))
1490 (win-conf (current-window-configuration)))
1492 (make-local-variable 'what-character-original-window-configuration)
1493 (setq what-character-original-window-configuration win-conf)
1494 (setq buffer-read-only nil)
1498 (insert-char-data-with-variant char 'printable)
1499 (unless (char-attribute-alist char)
1500 (insert (format ";; = %c\n"
1501 (let* ((rest (split-char char))
1505 (setq code (logior (lsh code 8)
1507 (decode-char ccs code)))))
1508 ;; (char-db-update-comment)
1509 (set-buffer-modified-p nil)
1510 (view-mode the-buf (lambda (buf)
1511 (set-window-configuration
1512 what-character-original-window-configuration)
1514 (goto-char (point-min)))
1516 (set-window-configuration
1517 what-character-original-window-configuration)
1518 (signal (car err) (cdr err)))))))
1524 (provide 'char-db-util)
1526 ;;; char-db-util.el ends here