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
322 ;;; @ char-db formatters
325 (defun char-db-make-char-spec (char)
327 (cond ((characterp char)
328 (cond ((and (setq ret (encode-char char '=ucs 'defined-only))
329 (not (and (<= #xE000 ret)(<= ret #xF8FF))))
330 (setq char-spec (list (cons '=ucs ret)))
331 (cond ((setq ret (get-char-attribute char 'name))
332 (setq char-spec (cons (cons 'name ret) char-spec))
334 ((setq ret (get-char-attribute char 'name*))
335 (setq char-spec (cons (cons 'name* ret) char-spec))
338 ((encode-char char '=mj 'defined-only)
340 (dolist (ccs (charset-list))
341 (if (and (or (eq ccs '=mj)
342 ;; (eq (charset-property ccs 'iso-ir) 177)
343 (string-match "=ucs@" (symbol-name ccs))
345 (setq ccs (charset-name ccs))
346 (null (assq ccs char-spec))
347 (setq ret (encode-char char ccs 'defined-only)))
348 (setq char-spec (cons (cons ccs ret) char-spec))))
350 ((encode-char char '==mj 'defined-only)
352 (dolist (ccs (charset-list))
353 (if (and (or (eq ccs '==mj)
354 ;; (eq (charset-property ccs 'iso-ir) 177)
355 (string-match "=ucs@" (symbol-name ccs))
357 (setq ccs (charset-name ccs))
358 (null (assq ccs char-spec))
359 (setq ret (encode-char char ccs 'defined-only)))
360 (setq char-spec (cons (cons ccs ret) char-spec))))
362 ((encode-char char '=adobe-japan1 'defined-only)
364 (dolist (ccs (charset-list))
365 (if (and (or (memq ccs
374 ;; (eq (charset-property ccs 'iso-ir) 177)
375 (string-match "=ucs@" (symbol-name ccs))
377 (setq ccs (charset-name ccs))
378 (null (assq ccs char-spec))
379 (setq ret (encode-char char ccs 'defined-only)))
380 (setq char-spec (cons (cons ccs ret) char-spec))))
382 ((encode-char char '==adobe-japan1 'defined-only)
384 (dolist (ccs (charset-list))
385 (if (and (or (memq ccs
394 ;; (eq (charset-property ccs 'iso-ir) 177)
395 (string-match "=ucs@" (symbol-name ccs))
397 (setq ccs (charset-name ccs))
398 (null (assq ccs char-spec))
399 (setq ret (encode-char char ccs 'defined-only)))
400 (setq char-spec (cons (cons ccs ret) char-spec))))
404 (let ((rest char-db-coded-charset-priority-list)
407 (setq ccs (charset-name
408 (find-charset (car rest))))
410 (encode-char char ccs
412 (throw 'tag (cons ccs ret)))
413 (setq rest (cdr rest))))))
414 (setq char-spec (list ret))
415 (dolist (ccs (delq (car ret) (charset-list)))
416 (if (and (or (charset-iso-final-char ccs)
423 (eq (charset-property ccs 'iso-ir) 177)
424 ;; (string-match "=ucs@" (symbol-name ccs))
426 (setq ccs (charset-name ccs))
427 (null (assq ccs char-spec))
428 (setq ret (encode-char char ccs 'defined-only)))
429 (setq char-spec (cons (cons ccs ret) char-spec))))
431 (setq char-spec (split-char char)))
432 (cond ((setq ret (get-char-attribute char 'name))
433 (setq char-spec (cons (cons 'name ret) char-spec))
435 ((setq ret (get-char-attribute char 'name*))
436 (setq char-spec (cons (cons 'name* ret) char-spec))
439 ((setq ret (get-char-attribute
440 char 'ideographic-combination))
442 (cons (cons 'ideographic-combination ret)
449 (defun char-db-insert-char-spec (char &optional readable column
452 (setq column (current-column)))
453 (let (char-spec temp-char)
454 (setq char-spec (char-db-make-char-spec char))
455 (unless (or (characterp char) ; char
457 (setq char (find-char char-spec))
459 ;; define temporary character
460 ;; Current implementation is dirty.
461 (setq temp-char (define-char (cons '(ideograph-daikanwa . 0)
463 (remove-char-attribute temp-char 'ideograph-daikanwa)
464 (setq char temp-char))
465 (insert-char-attributes char
467 (union (mapcar #'car char-spec)
471 ;; undefine temporary character
472 ;; Current implementation is dirty.
473 (setq char-spec (char-attribute-alist temp-char))
475 (remove-char-attribute temp-char (car (car char-spec)))
476 (setq char-spec (cdr char-spec))))))
478 (defun char-db-insert-alist (alist &optional readable column)
480 (setq column (current-column)))
482 (concat "\n" (make-string (1+ column) ?\ )))
486 lbs cell rest separator)
489 (setq name (car (car alist))
490 value (cdr (car alist)))
491 (cond ((eq name 'char)
493 (if (setq ret (condition-case nil
501 (setq key (car (car value)))
502 ;; (if (find-charset key)
503 ;; (setq cal (cons key cal))
504 (setq al (cons key al))
506 (setq value (cdr value)))
507 (insert-char-attributes ret
511 (insert (prin1-to-string value)))
513 (insert line-breaking))
515 (insert (format "(%-18s " name))
516 (setq lbs (concat "\n" (make-string (current-column) ?\ )))
518 (setq cell (car value))
519 (if (and (consp cell)
521 (setq ret (condition-case nil
531 (setq key (car (car rest)))
532 ;; (if (find-charset key)
533 ;; (setq cal (cons key cal))
534 (setq al (cons key al))
536 (setq rest (cdr rest)))
539 (insert-char-attributes ret
543 (setq separator lbs))
546 (insert (prin1-to-string cell))
547 (setq separator " "))
548 (setq value (cdr value)))
550 (insert line-breaking))
552 (insert (format "(%-18s . %S)%s"
555 (setq alist (cdr alist))))
558 (defun char-db-insert-char-reference (plist &optional readable column)
560 (setq column (current-column)))
562 (concat "\n" (make-string (1+ column) ?\ )))
567 (setq name (pop plist))
568 (setq value (pop plist))
569 (cond ((eq name :char)
572 (cond ((numberp value)
573 (setq value (decode-char '=ucs value)))
575 ;; (setq value (or (find-char value)
578 (char-db-insert-char-spec value readable)
579 (insert line-breaking)
582 (insert (format "%s%s\t%d ; %c%s"
585 (ideographic-radical value)
589 (insert (format "%s%s\t%S" separator name value))
590 (setq separator line-breaking)))
594 (defun char-db-decode-isolated-char (ccs code-point)
597 (cond ((eq ccs 'arabic-iso8859-6)
598 (decode-char ccs code-point))
600 ;; (decode-builtin-char '==gt code-point))
601 ((and (memq ccs '(=gt-pj-1
612 (setq ret (decode-char ccs code-point))
613 (setq ret (encode-char ret '=gt 'defined-only)))
614 (decode-builtin-char '=gt ret))
616 (decode-builtin-char ccs code-point))))
617 (cond ((and (<= 0 (char-int ret))
618 (<= (char-int ret) #x1F))
619 (decode-char '=ucs (+ #x2400 (char-int ret))))
620 ((= (char-int ret) #x7F)
624 (defvar char-db-convert-obsolete-format t)
626 (defun char-db-insert-ccs-feature (name value line-breaking)
632 ((memq name '(==shinjigen
634 =shinjigen@1ed ==shinjigen@1ed
635 =shinjigen@rev ==shinjigen@rev
636 =shinjigen/+p@rev ==shinjigen/+p@rev
637 ===daikanwa/ho ==daikanwa/ho
638 =daikanwa/ho =>>daikanwa/ho =>daikanwa/ho))
639 "(%-18s . %04d)\t; %c")
640 ((eq name '=shinjigen@1ed/24pr)
641 "(%-18s . %04d)\t; %c")
642 ((or (memq name '(===daikanwa
643 ==daikanwa =daikanwa =>>daikanwa =>daikanwa
644 =daikanwa@rev1 =daikanwa@rev2
645 =daikanwa/+p ==daikanwa/+p ===daikanwa/+p
647 =daikanwa/+2p =>>daikanwa/+2p
652 =adobe-japan1-0 ==adobe-japan1-0 ===adobe-japan1-0
653 =adobe-japan1-1 ==adobe-japan1-1 ===adobe-japan1-1
654 =adobe-japan1-2 ==adobe-japan1-2 ===adobe-japan1-2
655 =adobe-japan1-3 ==adobe-japan1-3 ===adobe-japan1-3
656 =adobe-japan1-4 ==adobe-japan1-4 ===adobe-japan1-4
657 =adobe-japan1-5 ==adobe-japan1-5 ===adobe-japan1-5
658 =adobe-japan1-6 ==adobe-japan1-6 ===adobe-japan1-6
659 =>>adobe-japan1-0 =+>adobe-japan1-0
660 =>>adobe-japan1-1 =+>adobe-japan1-1
661 =>>adobe-japan1-2 =+>adobe-japan1-2
662 =>>adobe-japan1-3 =+>adobe-japan1-3
663 =>>adobe-japan1-4 =+>adobe-japan1-4
664 =>>adobe-japan1-5 =+>adobe-japan1-5
665 =>>adobe-japan1-6 =+>adobe-japan1-6
666 =cbeta ==cbeta ===cbeta =>>cbeta
667 =zinbun-oracle =>zinbun-oracle))
668 ;; (string-match "^=adobe-" (symbol-name name))
670 "(%-18s . %05d)\t; %c")
671 ((memq name '(=hanyo-denshi/ks
672 ==hanyo-denshi/ks ===hanyo-denshi/ks
677 "(%-18s . %06d)\t; %c")
678 ((>= (charset-dimension name) 2)
679 "(%-18s . #x%04X)\t; %c")
681 "(%-18s . #x%02X)\t; %c"))
683 (if (= (charset-iso-graphic-plane name) 1)
685 (cond ((= (charset-dimension name) 1)
687 ((= (charset-dimension name) 2)
689 ((= (charset-dimension name) 3)
693 (char-db-decode-isolated-char name value)))
694 (if (and (= (charset-chars name) 94)
695 (= (charset-dimension name) 2))
696 (insert (format " [%02d-%02d]"
697 (- (lsh value -8) 32)
698 (- (logand value 255) 32))))
701 (insert (format "(%-18s . %s)" name value))
703 (insert line-breaking))
705 (defun char-db-insert-relation-feature (char name value line-breaking
707 (insert (format "(%-18s%s " name line-breaking))
708 (let ((lbs (concat "\n" (make-string (current-column) ?\ )))
709 separator cell sources required-features
712 (setq cell (car value))
714 (setq cell (decode-char '=ucs cell)))
716 ((eq name '->subsumptive)
717 (when (or (not (some (lambda (atr)
718 (get-char-attribute cell atr))
719 char-db-ignored-attributes))
721 (encode-char cell ccs 'defined-only))
725 (let ((char-db-ignored-attributes
727 char-db-ignored-attributes)))
728 (insert-char-attributes cell readable nil nil 'for-sub-node))
729 (setq separator lbs))
734 char (intern (format "%s*sources" name))))
735 (setq required-features nil)
736 (dolist (source sources)
740 shinjigen shinjigen@1ed shinjigen@rev))
741 (setq required-features
742 (union required-features
754 =shinjigen/+p@rev))))
756 (setq required-features
757 (union required-features
762 ((find-charset (setq ret (intern (format "=%s" source))))
763 (setq required-features
764 (cons ret required-features)))
765 (t (setq required-features
766 (cons source required-features)))))
767 (cond ((string-match "@JP" (symbol-name name))
768 (setq required-features
769 (union required-features
777 ((string-match "@CN" (symbol-name name))
778 (setq required-features
779 (union required-features
786 (insert (format "%S" cell))
787 (char-db-insert-char-spec cell readable
790 (setq separator lbs))
794 (if (consp (car cell))
795 (char-db-insert-char-spec cell readable)
796 (char-db-insert-char-reference cell readable))
797 (setq separator lbs))
801 (insert (prin1-to-string cell))
802 (setq separator " ")))
803 (setq value (cdr value)))
805 (insert line-breaking)))
807 (defun insert-char-attributes (char &optional readable attributes column
810 (setq column (current-column)))
811 (let (name value ; has-long-ccs-name
815 (concat "\n" (make-string (1+ column) ?\ )))
816 lbs cell separator ret
818 dest-ccss ; sources required-features
823 (if (consp attributes)
825 (dolist (name attributes)
826 (unless (memq name char-db-ignored-attributes)
827 (if (find-charset name)
831 (dolist (name (char-attribute-list))
832 (unless (memq name char-db-ignored-attributes)
833 (if (find-charset name)
837 #'char-attribute-name<)))
839 (when (memq '<-subsumptive attributes)
840 (when (or readable (not for-sub-node))
841 (when (setq value (get-char-attribute char '<-subsumptive))
842 (char-db-insert-relation-feature char '<-subsumptive value
845 (setq attributes (delq '<-subsumptive attributes)))
846 (when (and (memq '<-denotational attributes)
847 (setq value (get-char-attribute char '<-denotational)))
848 (char-db-insert-relation-feature char '<-denotational value
851 (setq attributes (delq '<-denotational attributes)))
852 (when (and (memq 'name attributes)
853 (setq value (get-char-attribute char 'name)))
855 (if (> (+ (current-column) (length value)) 48)
858 value line-breaking))
859 (setq attributes (delq 'name attributes))
861 (when (and (memq 'name* attributes)
862 (setq value (get-char-attribute char 'name*)))
864 (if (> (+ (current-column) (length value)) 48)
867 value line-breaking))
868 (setq attributes (delq 'name* attributes))
870 (when (and (memq 'script attributes)
871 (setq value (get-char-attribute char 'script)))
872 (insert (format "(script\t\t%s)%s"
873 (mapconcat (function prin1-to-string)
876 (setq attributes (delq 'script attributes))
878 (dolist (name '(=>ucs =>ucs*))
879 (when (and (memq name attributes)
880 (setq value (get-char-attribute char name)))
881 (insert (format "(%-18s . #x%04X)\t; %c%s"
882 name value (decode-char '=ucs value)
884 (setq attributes (delq name attributes))))
885 (dolist (name '(=>ucs@gb =>ucs@big5))
886 (when (and (memq name attributes)
887 (setq value (get-char-attribute char name)))
888 (insert (format "(%-18s . #x%04X)\t; %c%s"
893 (symbol-name name) 2)))
896 (setq attributes (delq name attributes))
898 ;; (dolist (name '(=>daikanwa))
899 ;; (when (and (memq name attributes)
900 ;; (setq value (get-char-attribute char name)))
902 ;; (if (integerp value)
903 ;; (format "(%-18s . %05d)\t; %c%s"
904 ;; name value (decode-char '=daikanwa value)
906 ;; (format "(%-18s %s)\t; %c%s"
908 ;; (mapconcat (function prin1-to-string)
910 ;; (char-representative-of-daikanwa char)
912 ;; (setq attributes (delq name attributes))))
913 (when (and (memq 'general-category attributes)
914 (setq value (get-char-attribute char 'general-category)))
916 "(general-category\t%s) ; %s%s"
917 (mapconcat (lambda (cell)
920 (cond ((rassoc value unidata-normative-category-alist)
921 "Normative Category")
922 ((rassoc value unidata-informative-category-alist)
923 "Informative Category")
927 (setq attributes (delq 'general-category attributes))
929 (when (and (memq 'bidi-category attributes)
930 (setq value (get-char-attribute char 'bidi-category)))
931 (insert (format "(bidi-category\t. %S)%s"
934 (setq attributes (delq 'bidi-category attributes))
936 (unless (or (not (memq 'mirrored attributes))
937 (eq (setq value (get-char-attribute char 'mirrored 'empty))
939 (insert (format "(mirrored\t\t. %S)%s"
942 (setq attributes (delq 'mirrored attributes))
945 ((and (memq 'decimal-digit-value attributes)
946 (setq value (get-char-attribute char 'decimal-digit-value)))
947 (insert (format "(decimal-digit-value . %S)%s"
950 (setq attributes (delq 'decimal-digit-value attributes))
951 (when (and (memq 'digit-value attributes)
952 (setq value (get-char-attribute char 'digit-value)))
953 (insert (format "(digit-value\t . %S)%s"
956 (setq attributes (delq 'digit-value attributes))
958 (when (and (memq 'numeric-value attributes)
959 (setq value (get-char-attribute char 'numeric-value)))
960 (insert (format "(numeric-value\t . %S)%s"
963 (setq attributes (delq 'numeric-value attributes))
967 (when (and (memq 'digit-value attributes)
968 (setq value (get-char-attribute char 'digit-value)))
969 (insert (format "(digit-value\t. %S)%s"
972 (setq attributes (delq 'digit-value attributes))
974 (when (and (memq 'numeric-value attributes)
975 (setq value (get-char-attribute char 'numeric-value)))
976 (insert (format "(numeric-value\t. %S)%s"
979 (setq attributes (delq 'numeric-value attributes))
981 (when (and (memq 'iso-10646-comment attributes)
982 (setq value (get-char-attribute char 'iso-10646-comment)))
983 (insert (format "(iso-10646-comment\t. %S)%s"
986 (setq attributes (delq 'iso-10646-comment attributes))
988 (when (and (memq 'morohashi-daikanwa attributes)
989 (setq value (get-char-attribute char 'morohashi-daikanwa)))
990 (insert (format "(morohashi-daikanwa\t%s)%s"
991 (mapconcat (function prin1-to-string) value " ")
993 (setq attributes (delq 'morohashi-daikanwa attributes))
997 (when (and (memq 'ideographic-radical attributes)
998 (setq value (get-char-attribute char 'ideographic-radical)))
1000 (insert (format "(ideographic-radical . %S)\t; %c%s"
1002 (ideographic-radical radical)
1004 (setq attributes (delq 'ideographic-radical attributes))
1006 (when (and (memq 'shuowen-radical attributes)
1007 (setq value (get-char-attribute char 'shuowen-radical)))
1008 (insert (format "(shuowen-radical\t. %S)\t; %c%s"
1010 (shuowen-radical value)
1012 (setq attributes (delq 'shuowen-radical attributes))
1017 char-db-feature-domains
1019 (dolist (feature (char-attribute-list))
1020 (setq feature (symbol-name feature))
1022 "\\(radical\\|strokes\\)@\\([^@*]+\\)\\(\\*\\|$\\)"
1024 (setq domain (intern (match-string 2 feature)))
1025 (unless (memq domain dest)
1026 (setq dest (cons domain dest)))))
1027 (sort dest #'string<))))
1028 (setq key (intern (format "%s@%s" 'ideographic-radical domain)))
1029 (when (and (memq key attributes)
1030 (setq value (get-char-attribute char key)))
1031 (setq radical value)
1032 (insert (format "(%s . %S)\t; %c%s"
1035 (ideographic-radical radical)
1037 (setq attributes (delq key attributes))
1039 (setq key (intern (format "%s@%s" 'ideographic-strokes domain)))
1040 (when (and (memq key attributes)
1041 (setq value (get-char-attribute char key)))
1042 (setq strokes value)
1043 (insert (format "(%s . %S)%s"
1047 (setq attributes (delq key attributes))
1049 (setq key (intern (format "%s@%s" 'total-strokes domain)))
1050 (when (and (memq key attributes)
1051 (setq value (get-char-attribute char key)))
1052 (insert (format "(%s . %S)%s"
1056 (setq attributes (delq key attributes))
1058 (dolist (feature '(ideographic-radical
1061 (setq key (intern (format "%s@%s*sources" feature domain)))
1062 (when (and (memq key attributes)
1063 (setq value (get-char-attribute char key)))
1064 (insert (format "(%s%s" key line-breaking))
1065 (dolist (cell value)
1066 (insert (format " %s" cell)))
1068 (insert line-breaking)
1069 (setq attributes (delq key attributes))
1072 (when (and (memq 'ideographic-strokes attributes)
1073 (setq value (get-char-attribute char 'ideographic-strokes)))
1074 (setq strokes value)
1075 (insert (format "(ideographic-strokes . %S)%s"
1078 (setq attributes (delq 'ideographic-strokes attributes))
1080 (when (and (memq 'kangxi-radical attributes)
1081 (setq value (get-char-attribute char 'kangxi-radical)))
1082 (unless (eq value radical)
1083 (insert (format "(kangxi-radical\t . %S)\t; %c%s"
1085 (ideographic-radical value)
1088 (setq radical value)))
1089 (setq attributes (delq 'kangxi-radical attributes))
1091 (when (and (memq 'kangxi-strokes attributes)
1092 (setq value (get-char-attribute char 'kangxi-strokes)))
1093 (unless (eq value strokes)
1094 (insert (format "(kangxi-strokes\t . %S)%s"
1098 (setq strokes value)))
1099 (setq attributes (delq 'kangxi-strokes attributes))
1101 (when (and (memq 'japanese-radical attributes)
1102 (setq value (get-char-attribute char 'japanese-radical)))
1103 (unless (eq value radical)
1104 (insert (format "(japanese-radical\t . %S)\t; %c%s"
1106 (ideographic-radical value)
1109 (setq radical value)))
1110 (setq attributes (delq 'japanese-radical attributes))
1112 (when (and (memq 'japanese-strokes attributes)
1113 (setq value (get-char-attribute char 'japanese-strokes)))
1114 (unless (eq value strokes)
1115 (insert (format "(japanese-strokes\t . %S)%s"
1119 (setq strokes value)))
1120 (setq attributes (delq 'japanese-strokes attributes))
1122 (when (and (memq 'cns-radical attributes)
1123 (setq value (get-char-attribute char 'cns-radical)))
1124 (insert (format "(cns-radical\t . %S)\t; %c%s"
1126 (ideographic-radical value)
1128 (setq attributes (delq 'cns-radical attributes))
1130 (when (and (memq 'cns-strokes attributes)
1131 (setq value (get-char-attribute char 'cns-strokes)))
1132 (unless (eq value strokes)
1133 (insert (format "(cns-strokes\t . %S)%s"
1137 (setq strokes value)))
1138 (setq attributes (delq 'cns-strokes attributes))
1140 ;; (when (and (memq 'shinjigen-1-radical attributes)
1141 ;; (setq value (get-char-attribute char 'shinjigen-1-radical)))
1142 ;; (unless (eq value radical)
1143 ;; (insert (format "(shinjigen-1-radical . %S)\t; %c%s"
1145 ;; (ideographic-radical value)
1148 ;; (setq radical value)))
1149 ;; (setq attributes (delq 'shinjigen-1-radical attributes))
1151 (when (and (memq 'ideographic- attributes)
1152 (setq value (get-char-attribute char 'ideographic-)))
1153 (insert "(ideographic- ")
1154 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1156 (while (consp value)
1157 (setq cell (car value))
1159 (setq cell (decode-char '=ucs cell)))
1160 (cond ((characterp cell)
1164 (insert (format "%S" cell))
1165 (char-db-insert-char-spec cell readable))
1166 (setq separator lbs))
1170 (if (consp (car cell))
1171 (char-db-insert-char-spec cell readable)
1172 (char-db-insert-char-reference cell readable))
1173 (setq separator lbs))
1177 (insert (prin1-to-string cell))
1178 (setq separator " ")))
1179 (setq value (cdr value)))
1181 (insert line-breaking)
1182 (setq attributes (delq 'ideographic- attributes)))
1183 (when (and (memq 'total-strokes attributes)
1184 (setq value (get-char-attribute char 'total-strokes)))
1185 (insert (format "(total-strokes . %S)%s"
1188 (setq attributes (delq 'total-strokes attributes))
1190 (when (and (memq '->ideograph attributes)
1191 (setq value (get-char-attribute char '->ideograph)))
1192 (insert (format "(->ideograph\t%s)%s"
1193 (mapconcat (lambda (code)
1194 (cond ((symbolp code)
1197 (format "#x%04X" code))
1200 line-breaking code))))
1203 (setq attributes (delq '->ideograph attributes))
1205 ;; (when (and (memq '->decomposition attributes)
1206 ;; (setq value (get-char-attribute char '->decomposition)))
1207 ;; (insert (format "(->decomposition\t%s)%s"
1208 ;; (mapconcat (lambda (code)
1209 ;; (cond ((symbolp code)
1210 ;; (symbol-name code))
1211 ;; ((characterp code)
1213 ;; (format "%S" code)
1218 ;; (format "#x%04X" code))
1220 ;; (format "%s%S" line-breaking code))))
1223 ;; (setq attributes (delq '->decomposition attributes))
1225 (if (equal (get-char-attribute char '->titlecase)
1226 (get-char-attribute char '->uppercase))
1227 (setq attributes (delq '->titlecase attributes)))
1228 (when (and (memq '->mojikyo attributes)
1229 (setq value (get-char-attribute char '->mojikyo)))
1230 (insert (format "(->mojikyo\t\t. %06d)\t; %c%s"
1231 value (decode-char 'mojikyo value)
1233 (setq attributes (delq '->mojikyo attributes))
1235 (when (and (memq 'hanyu-dazidian-vol attributes)
1236 (setq value (get-char-attribute char 'hanyu-dazidian-vol)))
1237 (insert (format "(hanyu-dazidian-vol . %d)%s"
1238 value line-breaking))
1239 (setq attributes (delq 'hanyu-dazidian-vol attributes))
1241 (when (and (memq 'hanyu-dazidian-page attributes)
1242 (setq value (get-char-attribute char 'hanyu-dazidian-page)))
1243 (insert (format "(hanyu-dazidian-page . %d)%s"
1244 value line-breaking))
1245 (setq attributes (delq 'hanyu-dazidian-page attributes))
1247 (when (and (memq 'hanyu-dazidian-char attributes)
1248 (setq value (get-char-attribute char 'hanyu-dazidian-char)))
1249 (insert (format "(hanyu-dazidian-char . %d)%s"
1250 value line-breaking))
1251 (setq attributes (delq 'hanyu-dazidian-char attributes))
1254 (dolist (ignored '(composition
1255 ->denotational <-subsumptive ->ucs-unified
1256 ->ideographic-component-forms))
1257 (setq attributes (delq ignored attributes))))
1259 (setq name (car attributes))
1260 (unless (eq (setq value (get-char-attribute char name 'value-is-empty))
1262 (cond ((setq ret (find-charset name))
1263 (setq name (charset-name ret))
1264 (when (not (memq name dest-ccss))
1265 (setq dest-ccss (cons name dest-ccss))
1266 (char-db-insert-ccs-feature name value line-breaking))
1268 ((string-match "^=>ucs@" (symbol-name name))
1269 (insert (format "(%-18s . #x%04X)\t; %c%s"
1270 name value (decode-char '=ucs value)
1273 ((eq name 'jisx0208-1978/4X)
1274 (insert (format "(%-18s . #x%04X)%s"
1280 (not (eq name '->subsumptive))
1281 (not (eq name '->uppercase))
1282 (not (eq name '->lowercase))
1283 (not (eq name '->titlecase))
1284 (not (eq name '->canonical))
1285 (not (eq name '->Bopomofo))
1286 (not (eq name '->mistakable))
1287 (not (eq name '->ideographic-variants))
1288 (null (get-char-attribute
1289 char (intern (format "%s*sources" name))))
1290 (not (string-match "\\*sources$" (symbol-name name)))
1291 (null (get-char-attribute
1292 char (intern (format "%s*note" name))))
1293 (not (string-match "\\*note$" (symbol-name name)))
1294 (or (eq name '<-identical)
1295 (eq name '<-uppercase)
1296 (eq name '<-lowercase)
1297 (eq name '<-titlecase)
1298 (eq name '<-canonical)
1299 (eq name '<-ideographic-variants)
1300 ;; (eq name '<-synonyms)
1301 (string-match "^<-synonyms" (symbol-name name))
1302 (eq name '<-mistakable)
1303 (when (string-match "^->" (symbol-name name))
1305 ((string-match "^->fullwidth" (symbol-name name))
1306 (not (and (consp value)
1307 (characterp (car value))
1309 (car value) '=ucs 'defined-only)))
1314 ((or (eq name 'ideographic-structure)
1315 (eq name 'ideographic-combination)
1316 (eq name 'ideographic-)
1317 (eq name '=decomposition)
1318 (char-feature-base-name= '=decomposition name)
1319 (char-feature-base-name= '=>decomposition name)
1320 ;; (string-match "^=>*decomposition\\(@[^*]+\\)?$"
1321 ;; (symbol-name name))
1322 (string-match "^\\(->\\|<-\\)[^*]*$" (symbol-name name))
1323 (string-match "^\\(->\\|<-\\)[^*]*\\*sources$"
1326 (char-db-insert-relation-feature char name value
1329 ((memq name '(ideograph=
1330 original-ideograph-of
1331 ancient-ideograph-of
1334 ;; simplified-ideograph-of
1335 ideographic-variants
1336 ;; ideographic-different-form-of
1338 (insert (format "(%-18s%s " name line-breaking))
1339 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1341 (while (consp value)
1342 (setq cell (car value))
1343 (if (and (consp cell)
1348 (char-db-insert-alist cell readable)
1349 (setq separator lbs))
1352 (insert (prin1-to-string cell))
1353 (setq separator " "))
1354 (setq value (cdr value)))
1356 (insert line-breaking))
1358 (insert (format "(%-18s " name))
1359 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1361 (while (consp value)
1362 (setq cell (car value))
1363 (if (and (consp cell)
1365 (setq ret (condition-case nil
1373 (setq key (car (car rest)))
1374 (if (find-charset key)
1375 (setq cal (cons key cal))
1376 (setq al (cons key al)))
1377 (setq rest (cdr rest)))
1380 (insert-char-attributes ret
1384 (setq separator lbs))
1385 (setq ret (prin1-to-string cell))
1387 (if (< (+ (current-column)
1394 (setq separator " "))
1395 (setq value (cdr value)))
1397 (insert line-breaking))
1399 (insert (format "(%-18s" name))
1400 (setq ret (prin1-to-string value))
1401 (unless (< (+ (current-column)
1405 (insert line-breaking))
1406 (insert " . " ret ")" line-breaking)
1407 ;; (insert (format "(%-18s . %S)%s"
1412 (setq attributes (cdr attributes)))
1415 (defun insert-char-data (char &optional readable
1418 (narrow-to-region (point)(point))
1419 (insert "(define-char
1421 (insert-char-attributes char readable attributes)
1423 (goto-char (point-min))
1424 (while (re-search-forward "[ \t]+$" nil t)
1427 (goto-char (point-min))
1428 (while (re-search-forward "[ \t][ \t][ \t]*" nil t)
1429 (let ((column (current-column))
1430 (indent-tabs-mode t))
1431 (delete-region (match-beginning 0) (point))
1432 (indent-to column)))
1433 (goto-char (point-max))
1434 ;; (tabify (point-min)(point-max))
1437 (defun insert-char-data-with-variant (char &optional printable
1439 script excluded-script)
1440 (insert-char-data char printable)
1441 (let ((variants (char-variants char))
1444 (setq variants (sort variants #'<))
1445 (setq rest variants)
1446 (setq variants (cons char variants))
1448 (setq variant (car rest))
1449 (unless (get-char-attribute variant '<-subsumptive)
1450 (if (and (or (null script)
1451 (null (setq vs (get-char-attribute variant 'script)))
1453 (or (null excluded-script)
1454 (null (setq vs (get-char-attribute variant 'script)))
1455 (not (memq excluded-script vs))))
1456 (unless (and no-ucs-unified (get-char-attribute variant '=ucs))
1457 (insert-char-data variant printable)
1458 (if (setq ret (char-variants variant))
1460 (or (memq (car ret) variants)
1461 ;; (get-char-attribute (car ret) '<-subsumptive)
1462 (setq rest (nconc rest (list (car ret)))))
1463 (setq ret (cdr ret)))))))
1464 (setq rest (cdr rest)))))
1466 (defun insert-char-range-data (min max &optional script excluded-script)
1469 (while (<= code max)
1470 (setq char (decode-char '=ucs code))
1471 (if (encode-char char '=ucs 'defined-only)
1472 (insert-char-data-with-variant char nil 'no-ucs-unified
1473 script excluded-script))
1474 (setq code (1+ code)))))
1476 (defun write-char-range-data-to-file (min max file
1477 &optional script excluded-script)
1478 (let ((coding-system-for-write char-db-file-coding-system))
1480 (insert (format ";; -*- coding: %s -*-\n"
1481 char-db-file-coding-system))
1482 (insert-char-range-data min max script excluded-script)
1483 (write-region (point-min)(point-max) file))))
1485 (defvar what-character-original-window-configuration)
1488 (defun what-char-definition (char)
1489 (interactive (list (char-after)))
1490 (let ((buf (get-buffer-create "*Character Description*"))
1491 (the-buf (current-buffer))
1492 (win-conf (current-window-configuration)))
1494 (make-local-variable 'what-character-original-window-configuration)
1495 (setq what-character-original-window-configuration win-conf)
1496 (setq buffer-read-only nil)
1500 (insert-char-data-with-variant char 'printable)
1501 (unless (char-attribute-alist char)
1502 (insert (format ";; = %c\n"
1503 (let* ((rest (split-char char))
1507 (setq code (logior (lsh code 8)
1509 (decode-char ccs code)))))
1510 ;; (char-db-update-comment)
1511 (set-buffer-modified-p nil)
1512 (view-mode the-buf (lambda (buf)
1513 (set-window-configuration
1514 what-character-original-window-configuration)
1516 (goto-char (point-min)))
1518 (set-window-configuration
1519 what-character-original-window-configuration)
1520 (signal (car err) (cdr err)))))))
1526 (provide 'char-db-util)
1528 ;;; char-db-util.el ends here