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 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
100 (defun shuowen-radical (number)
101 (aref shuowen-radicals (1- number)))
103 (defvar char-db-file-coding-system 'utf-8-mcs-er)
105 (defvar char-db-ignored-attributes '(ideographic-products))
107 (defvar char-db-coded-charset-priority-list
274 ;;; @ char-db formatters
277 (defun char-db-make-char-spec (char)
279 (cond ((characterp char)
280 (cond ((and (setq ret (encode-char char '=ucs 'defined-only))
281 (not (and (<= #xE000 ret)(<= ret #xF8FF))))
282 (setq char-spec (list (cons '=ucs ret)))
283 (cond ((setq ret (get-char-attribute char 'name))
284 (setq char-spec (cons (cons 'name ret) char-spec))
286 ((setq ret (get-char-attribute char 'name*))
287 (setq char-spec (cons (cons 'name* ret) char-spec))
290 ((encode-char char '=adobe-japan1 'defined-only)
292 (dolist (ccs (charset-list))
293 (if (and (or (memq ccs
302 ;; (eq (charset-property ccs 'iso-ir) 177)
303 (string-match "=ucs@" (symbol-name ccs))
305 (setq ccs (charset-name ccs))
306 (null (assq ccs char-spec))
307 (setq ret (encode-char char ccs 'defined-only)))
308 (setq char-spec (cons (cons ccs ret) char-spec))))
312 (let ((rest char-db-coded-charset-priority-list)
315 (setq ccs (charset-name
316 (find-charset (car rest))))
318 (encode-char char ccs
320 (throw 'tag (cons ccs ret)))
321 (setq rest (cdr rest))))))
322 (setq char-spec (list ret))
323 (dolist (ccs (delq (car ret) (charset-list)))
324 (if (and (or (charset-iso-final-char ccs)
331 (eq (charset-property ccs 'iso-ir) 177)
332 ;; (string-match "=ucs@" (symbol-name ccs))
334 (setq ccs (charset-name ccs))
335 (null (assq ccs char-spec))
336 (setq ret (encode-char char ccs 'defined-only)))
337 (setq char-spec (cons (cons ccs ret) char-spec))))
339 (setq char-spec (split-char char)))
340 (cond ((setq ret (get-char-attribute char 'name))
341 (setq char-spec (cons (cons 'name ret) char-spec))
343 ((setq ret (get-char-attribute char 'name*))
344 (setq char-spec (cons (cons 'name* ret) char-spec))
347 ((setq ret (get-char-attribute
348 char 'ideographic-combination))
350 (cons (cons 'ideographic-combination ret)
357 (defun char-db-insert-char-spec (char &optional readable column
360 (setq column (current-column)))
361 (let (char-spec temp-char)
362 (setq char-spec (char-db-make-char-spec char))
363 (unless (or (characterp char) ; char
365 (setq char (find-char char-spec))
367 ;; define temporary character
368 ;; Current implementation is dirty.
369 (setq temp-char (define-char (cons '(ideograph-daikanwa . 0)
371 (remove-char-attribute temp-char 'ideograph-daikanwa)
372 (setq char temp-char))
373 (insert-char-attributes char
375 (union (mapcar #'car char-spec)
379 ;; undefine temporary character
380 ;; Current implementation is dirty.
381 (setq char-spec (char-attribute-alist temp-char))
383 (remove-char-attribute temp-char (car (car char-spec)))
384 (setq char-spec (cdr char-spec))))))
386 (defun char-db-insert-alist (alist &optional readable column)
388 (setq column (current-column)))
390 (concat "\n" (make-string (1+ column) ?\ )))
394 lbs cell rest separator)
397 (setq name (car (car alist))
398 value (cdr (car alist)))
399 (cond ((eq name 'char)
401 (if (setq ret (condition-case nil
409 (setq key (car (car value)))
410 ;; (if (find-charset key)
411 ;; (setq cal (cons key cal))
412 (setq al (cons key al))
414 (setq value (cdr value)))
415 (insert-char-attributes ret
419 (insert (prin1-to-string value)))
421 (insert line-breaking))
423 (insert (format "(%-18s " name))
424 (setq lbs (concat "\n" (make-string (current-column) ?\ )))
426 (setq cell (car value))
427 (if (and (consp cell)
429 (setq ret (condition-case nil
439 (setq key (car (car rest)))
440 ;; (if (find-charset key)
441 ;; (setq cal (cons key cal))
442 (setq al (cons key al))
444 (setq rest (cdr rest)))
447 (insert-char-attributes ret
451 (setq separator lbs))
454 (insert (prin1-to-string cell))
455 (setq separator " "))
456 (setq value (cdr value)))
458 (insert line-breaking))
460 (insert (format "(%-18s . %S)%s"
463 (setq alist (cdr alist))))
466 (defun char-db-insert-char-reference (plist &optional readable column)
468 (setq column (current-column)))
470 (concat "\n" (make-string (1+ column) ?\ )))
475 (setq name (pop plist))
476 (setq value (pop plist))
477 (cond ((eq name :char)
480 (cond ((numberp value)
481 (setq value (decode-char '=ucs value)))
483 ;; (setq value (or (find-char value)
486 (char-db-insert-char-spec value readable)
487 (insert line-breaking)
490 (insert (format "%s%s\t%d ; %c%s"
493 (ideographic-radical value)
497 (insert (format "%s%s\t%S" separator name value))
498 (setq separator line-breaking)))
502 (defun char-db-decode-isolated-char (ccs code-point)
505 (cond ((eq ccs 'arabic-iso8859-6)
506 (decode-char ccs code-point))
507 ((and (memq ccs '(=gt-pj-1
518 (setq ret (decode-char ccs code-point))
519 (setq ret (encode-char ret '=gt 'defined-only)))
520 (decode-builtin-char '=gt ret))
522 (decode-builtin-char ccs code-point))))
523 (cond ((and (<= 0 (char-int ret))
524 (<= (char-int ret) #x1F))
525 (decode-char '=ucs (+ #x2400 (char-int ret))))
526 ((= (char-int ret) #x7F)
530 (defvar char-db-convert-obsolete-format t)
532 (defun char-db-insert-ccs-feature (name value line-breaking)
538 ((memq name '(=shinjigen
540 =shinjigen@rev =shinjigen/+p@rev
541 =daikanwa/ho =>>daikanwa/ho =>daikanwa/ho))
542 "(%-18s . %04d)\t; %c")
543 ((eq name '=shinjigen@1ed/24pr)
544 "(%-18s . %04d)\t; %c")
545 ((or (memq name '(=daikanwa =>>daikanwa =>daikanwa
546 =daikanwa@rev1 =daikanwa@rev2
547 =daikanwa/+p =>>daikanwa/+p
548 =daikanwa/+2p =>>daikanwa/+2p
549 =gt =>>>gt =>>gt =+>gt =>gt
551 =adobe-japan1-0 =>>>adobe-japan1-0
552 =adobe-japan1-1 =>>>adobe-japan1-1
553 =adobe-japan1-2 =>>>adobe-japan1-2
554 =adobe-japan1-3 =>>>adobe-japan1-3
555 =adobe-japan1-4 =>>>adobe-japan1-4
556 =adobe-japan1-5 =>>>adobe-japan1-5
557 =adobe-japan1-6 =>>>adobe-japan1-6
558 =>>adobe-japan1-0 =+>adobe-japan1-0
559 =>>adobe-japan1-1 =+>adobe-japan1-1
560 =>>adobe-japan1-2 =+>adobe-japan1-2
561 =>>adobe-japan1-3 =+>adobe-japan1-3
562 =>>adobe-japan1-4 =+>adobe-japan1-4
563 =>>adobe-japan1-5 =+>adobe-japan1-5
564 =>>adobe-japan1-6 =+>adobe-japan1-6
566 =zinbun-oracle =>zinbun-oracle))
567 ;; (string-match "^=adobe-" (symbol-name name))
569 "(%-18s . %05d)\t; %c")
570 ((memq name '(=hanyo-denshi/ks
571 =>>>hanyo-denshi/ks =>>hanyo-denshi/ks
573 "(%-18s . %06d)\t; %c")
574 ((>= (charset-dimension name) 2)
575 "(%-18s . #x%04X)\t; %c")
577 "(%-18s . #x%02X)\t; %c"))
579 (if (= (charset-iso-graphic-plane name) 1)
581 (cond ((= (charset-dimension name) 1)
583 ((= (charset-dimension name) 2)
585 ((= (charset-dimension name) 3)
589 (char-db-decode-isolated-char name value)))
590 (if (and (= (charset-chars name) 94)
591 (= (charset-dimension name) 2))
592 (insert (format " [%02d-%02d]"
593 (- (lsh value -8) 32)
594 (- (logand value 255) 32))))
597 (insert (format "(%-18s . %s)" name value))
599 (insert line-breaking))
601 (defun char-db-insert-relation-feature (char name value line-breaking
603 (insert (format "(%-18s%s " name line-breaking))
604 (let ((lbs (concat "\n" (make-string (current-column) ?\ )))
605 separator cell sources required-features
608 (setq cell (car value))
610 (setq cell (decode-char '=ucs cell)))
612 ((eq name '->subsumptive)
613 (when (or (not (some (lambda (atr)
614 (get-char-attribute cell atr))
615 char-db-ignored-attributes))
617 (encode-char cell ccs 'defined-only))
621 (let ((char-db-ignored-attributes
623 char-db-ignored-attributes)))
624 (insert-char-attributes cell readable nil nil 'for-sub-node))
625 (setq separator lbs))
630 char (intern (format "%s*sources" name))))
631 (setq required-features nil)
632 (dolist (source sources)
636 shinjigen shinjigen@1ed shinjigen@rev))
637 (setq required-features
638 (union required-features
650 =shinjigen/+p@rev))))
652 (setq required-features
653 (union required-features
658 ((find-charset (setq ret (intern (format "=%s" source))))
659 (setq required-features
660 (cons ret required-features)))
661 (t (setq required-features
662 (cons source required-features)))))
663 (cond ((string-match "@JP" (symbol-name name))
664 (setq required-features
665 (union required-features
673 ((string-match "@CN" (symbol-name name))
674 (setq required-features
675 (union required-features
682 (insert (format "%S" cell))
683 (char-db-insert-char-spec cell readable
686 (setq separator lbs))
690 (if (consp (car cell))
691 (char-db-insert-char-spec cell readable)
692 (char-db-insert-char-reference cell readable))
693 (setq separator lbs))
697 (insert (prin1-to-string cell))
698 (setq separator " ")))
699 (setq value (cdr value)))
701 (insert line-breaking)))
703 (defun insert-char-attributes (char &optional readable attributes column
706 (setq column (current-column)))
707 (let (name value ; has-long-ccs-name
711 (concat "\n" (make-string (1+ column) ?\ )))
712 lbs cell separator ret
714 dest-ccss ; sources required-features
719 (if (consp attributes)
721 (dolist (name attributes)
722 (unless (memq name char-db-ignored-attributes)
723 (if (find-charset name)
727 (dolist (name (char-attribute-list))
728 (unless (memq name char-db-ignored-attributes)
729 (if (find-charset name)
733 #'char-attribute-name<)))
735 (when (memq '<-subsumptive attributes)
736 (when (or readable (not for-sub-node))
737 (when (setq value (get-char-attribute char '<-subsumptive))
738 (char-db-insert-relation-feature char '<-subsumptive value
741 (setq attributes (delq '<-subsumptive attributes)))
742 (when (and (memq '<-denotational attributes)
743 (setq value (get-char-attribute char '<-denotational)))
744 (char-db-insert-relation-feature char '<-denotational value
747 (setq attributes (delq '<-denotational attributes)))
748 (when (and (memq 'name attributes)
749 (setq value (get-char-attribute char 'name)))
751 (if (> (+ (current-column) (length value)) 48)
754 value line-breaking))
755 (setq attributes (delq 'name attributes))
757 (when (and (memq 'name* attributes)
758 (setq value (get-char-attribute char 'name*)))
760 (if (> (+ (current-column) (length value)) 48)
763 value line-breaking))
764 (setq attributes (delq 'name* attributes))
766 (when (and (memq 'script attributes)
767 (setq value (get-char-attribute char 'script)))
768 (insert (format "(script\t\t%s)%s"
769 (mapconcat (function prin1-to-string)
772 (setq attributes (delq 'script attributes))
774 (dolist (name '(=>ucs =>ucs*))
775 (when (and (memq name attributes)
776 (setq value (get-char-attribute char name)))
777 (insert (format "(%-18s . #x%04X)\t; %c%s"
778 name value (decode-char '=ucs value)
780 (setq attributes (delq name attributes))))
781 (dolist (name '(=>ucs@gb =>ucs@big5))
782 (when (and (memq name attributes)
783 (setq value (get-char-attribute char name)))
784 (insert (format "(%-18s . #x%04X)\t; %c%s"
789 (symbol-name name) 2)))
792 (setq attributes (delq name attributes))
794 ;; (dolist (name '(=>daikanwa))
795 ;; (when (and (memq name attributes)
796 ;; (setq value (get-char-attribute char name)))
798 ;; (if (integerp value)
799 ;; (format "(%-18s . %05d)\t; %c%s"
800 ;; name value (decode-char '=daikanwa value)
802 ;; (format "(%-18s %s)\t; %c%s"
804 ;; (mapconcat (function prin1-to-string)
806 ;; (char-representative-of-daikanwa char)
808 ;; (setq attributes (delq name attributes))))
809 (when (and (memq 'general-category attributes)
810 (setq value (get-char-attribute char 'general-category)))
812 "(general-category\t%s) ; %s%s"
813 (mapconcat (lambda (cell)
816 (cond ((rassoc value unidata-normative-category-alist)
817 "Normative Category")
818 ((rassoc value unidata-informative-category-alist)
819 "Informative Category")
823 (setq attributes (delq 'general-category attributes))
825 (when (and (memq 'bidi-category attributes)
826 (setq value (get-char-attribute char 'bidi-category)))
827 (insert (format "(bidi-category\t. %S)%s"
830 (setq attributes (delq 'bidi-category attributes))
832 (unless (or (not (memq 'mirrored attributes))
833 (eq (setq value (get-char-attribute char 'mirrored 'empty))
835 (insert (format "(mirrored\t\t. %S)%s"
838 (setq attributes (delq 'mirrored attributes))
841 ((and (memq 'decimal-digit-value attributes)
842 (setq value (get-char-attribute char 'decimal-digit-value)))
843 (insert (format "(decimal-digit-value . %S)%s"
846 (setq attributes (delq 'decimal-digit-value attributes))
847 (when (and (memq 'digit-value attributes)
848 (setq value (get-char-attribute char 'digit-value)))
849 (insert (format "(digit-value\t . %S)%s"
852 (setq attributes (delq 'digit-value attributes))
854 (when (and (memq 'numeric-value attributes)
855 (setq value (get-char-attribute char 'numeric-value)))
856 (insert (format "(numeric-value\t . %S)%s"
859 (setq attributes (delq 'numeric-value attributes))
863 (when (and (memq 'digit-value attributes)
864 (setq value (get-char-attribute char 'digit-value)))
865 (insert (format "(digit-value\t. %S)%s"
868 (setq attributes (delq 'digit-value attributes))
870 (when (and (memq 'numeric-value attributes)
871 (setq value (get-char-attribute char 'numeric-value)))
872 (insert (format "(numeric-value\t. %S)%s"
875 (setq attributes (delq 'numeric-value attributes))
877 (when (and (memq 'iso-10646-comment attributes)
878 (setq value (get-char-attribute char 'iso-10646-comment)))
879 (insert (format "(iso-10646-comment\t. %S)%s"
882 (setq attributes (delq 'iso-10646-comment attributes))
884 (when (and (memq 'morohashi-daikanwa attributes)
885 (setq value (get-char-attribute char 'morohashi-daikanwa)))
886 (insert (format "(morohashi-daikanwa\t%s)%s"
887 (mapconcat (function prin1-to-string) value " ")
889 (setq attributes (delq 'morohashi-daikanwa attributes))
893 (when (and (memq 'ideographic-radical attributes)
894 (setq value (get-char-attribute char 'ideographic-radical)))
896 (insert (format "(ideographic-radical . %S)\t; %c%s"
898 (ideographic-radical radical)
900 (setq attributes (delq 'ideographic-radical attributes))
902 (when (and (memq 'shuowen-radical attributes)
903 (setq value (get-char-attribute char 'shuowen-radical)))
904 (insert (format "(shuowen-radical\t. %S)\t; %c%s"
906 (shuowen-radical value)
908 (setq attributes (delq 'shuowen-radical attributes))
913 char-db-feature-domains
915 (dolist (feature (char-attribute-list))
916 (setq feature (symbol-name feature))
918 "\\(radical\\|strokes\\)@\\([^@*]+\\)\\(\\*\\|$\\)"
920 (setq domain (intern (match-string 2 feature)))
921 (unless (memq domain dest)
922 (setq dest (cons domain dest)))))
923 (sort dest #'string<))))
924 (setq key (intern (format "%s@%s" 'ideographic-radical domain)))
925 (when (and (memq key attributes)
926 (setq value (get-char-attribute char key)))
928 (insert (format "(%s . %S)\t; %c%s"
931 (ideographic-radical radical)
933 (setq attributes (delq key attributes))
935 (setq key (intern (format "%s@%s" 'ideographic-strokes domain)))
936 (when (and (memq key attributes)
937 (setq value (get-char-attribute char key)))
939 (insert (format "(%s . %S)%s"
943 (setq attributes (delq key attributes))
945 (setq key (intern (format "%s@%s" 'total-strokes domain)))
946 (when (and (memq key attributes)
947 (setq value (get-char-attribute char key)))
948 (insert (format "(%s . %S)%s"
952 (setq attributes (delq key attributes))
954 (dolist (feature '(ideographic-radical
957 (setq key (intern (format "%s@%s*sources" feature domain)))
958 (when (and (memq key attributes)
959 (setq value (get-char-attribute char key)))
960 (insert (format "(%s%s" key line-breaking))
962 (insert (format " %s" cell)))
964 (insert line-breaking)
965 (setq attributes (delq key attributes))
968 (when (and (memq 'ideographic-strokes attributes)
969 (setq value (get-char-attribute char 'ideographic-strokes)))
971 (insert (format "(ideographic-strokes . %S)%s"
974 (setq attributes (delq 'ideographic-strokes attributes))
976 (when (and (memq 'kangxi-radical attributes)
977 (setq value (get-char-attribute char 'kangxi-radical)))
978 (unless (eq value radical)
979 (insert (format "(kangxi-radical\t . %S)\t; %c%s"
981 (ideographic-radical value)
984 (setq radical value)))
985 (setq attributes (delq 'kangxi-radical attributes))
987 (when (and (memq 'kangxi-strokes attributes)
988 (setq value (get-char-attribute char 'kangxi-strokes)))
989 (unless (eq value strokes)
990 (insert (format "(kangxi-strokes\t . %S)%s"
994 (setq strokes value)))
995 (setq attributes (delq 'kangxi-strokes attributes))
997 (when (and (memq 'japanese-radical attributes)
998 (setq value (get-char-attribute char 'japanese-radical)))
999 (unless (eq value radical)
1000 (insert (format "(japanese-radical\t . %S)\t; %c%s"
1002 (ideographic-radical value)
1005 (setq radical value)))
1006 (setq attributes (delq 'japanese-radical attributes))
1008 (when (and (memq 'japanese-strokes attributes)
1009 (setq value (get-char-attribute char 'japanese-strokes)))
1010 (unless (eq value strokes)
1011 (insert (format "(japanese-strokes\t . %S)%s"
1015 (setq strokes value)))
1016 (setq attributes (delq 'japanese-strokes attributes))
1018 (when (and (memq 'cns-radical attributes)
1019 (setq value (get-char-attribute char 'cns-radical)))
1020 (insert (format "(cns-radical\t . %S)\t; %c%s"
1022 (ideographic-radical value)
1024 (setq attributes (delq 'cns-radical attributes))
1026 (when (and (memq 'cns-strokes attributes)
1027 (setq value (get-char-attribute char 'cns-strokes)))
1028 (unless (eq value strokes)
1029 (insert (format "(cns-strokes\t . %S)%s"
1033 (setq strokes value)))
1034 (setq attributes (delq 'cns-strokes attributes))
1036 ;; (when (and (memq 'shinjigen-1-radical attributes)
1037 ;; (setq value (get-char-attribute char 'shinjigen-1-radical)))
1038 ;; (unless (eq value radical)
1039 ;; (insert (format "(shinjigen-1-radical . %S)\t; %c%s"
1041 ;; (ideographic-radical value)
1044 ;; (setq radical value)))
1045 ;; (setq attributes (delq 'shinjigen-1-radical attributes))
1047 (when (and (memq 'ideographic- attributes)
1048 (setq value (get-char-attribute char 'ideographic-)))
1049 (insert "(ideographic- ")
1050 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1052 (while (consp value)
1053 (setq cell (car value))
1055 (setq cell (decode-char '=ucs cell)))
1056 (cond ((characterp cell)
1060 (insert (format "%S" cell))
1061 (char-db-insert-char-spec cell readable))
1062 (setq separator lbs))
1066 (if (consp (car cell))
1067 (char-db-insert-char-spec cell readable)
1068 (char-db-insert-char-reference cell readable))
1069 (setq separator lbs))
1073 (insert (prin1-to-string cell))
1074 (setq separator " ")))
1075 (setq value (cdr value)))
1077 (insert line-breaking)
1078 (setq attributes (delq 'ideographic- attributes)))
1079 (when (and (memq 'total-strokes attributes)
1080 (setq value (get-char-attribute char 'total-strokes)))
1081 (insert (format "(total-strokes . %S)%s"
1084 (setq attributes (delq 'total-strokes attributes))
1086 (when (and (memq '->ideograph attributes)
1087 (setq value (get-char-attribute char '->ideograph)))
1088 (insert (format "(->ideograph\t%s)%s"
1089 (mapconcat (lambda (code)
1090 (cond ((symbolp code)
1093 (format "#x%04X" code))
1096 line-breaking code))))
1099 (setq attributes (delq '->ideograph attributes))
1101 ;; (when (and (memq '->decomposition attributes)
1102 ;; (setq value (get-char-attribute char '->decomposition)))
1103 ;; (insert (format "(->decomposition\t%s)%s"
1104 ;; (mapconcat (lambda (code)
1105 ;; (cond ((symbolp code)
1106 ;; (symbol-name code))
1107 ;; ((characterp code)
1109 ;; (format "%S" code)
1114 ;; (format "#x%04X" code))
1116 ;; (format "%s%S" line-breaking code))))
1119 ;; (setq attributes (delq '->decomposition attributes))
1121 (if (equal (get-char-attribute char '->titlecase)
1122 (get-char-attribute char '->uppercase))
1123 (setq attributes (delq '->titlecase attributes)))
1124 (when (and (memq '->mojikyo attributes)
1125 (setq value (get-char-attribute char '->mojikyo)))
1126 (insert (format "(->mojikyo\t\t. %06d)\t; %c%s"
1127 value (decode-char 'mojikyo value)
1129 (setq attributes (delq '->mojikyo attributes))
1131 (when (and (memq 'hanyu-dazidian-vol attributes)
1132 (setq value (get-char-attribute char 'hanyu-dazidian-vol)))
1133 (insert (format "(hanyu-dazidian-vol . %d)%s"
1134 value line-breaking))
1135 (setq attributes (delq 'hanyu-dazidian-vol attributes))
1137 (when (and (memq 'hanyu-dazidian-page attributes)
1138 (setq value (get-char-attribute char 'hanyu-dazidian-page)))
1139 (insert (format "(hanyu-dazidian-page . %d)%s"
1140 value line-breaking))
1141 (setq attributes (delq 'hanyu-dazidian-page attributes))
1143 (when (and (memq 'hanyu-dazidian-char attributes)
1144 (setq value (get-char-attribute char 'hanyu-dazidian-char)))
1145 (insert (format "(hanyu-dazidian-char . %d)%s"
1146 value line-breaking))
1147 (setq attributes (delq 'hanyu-dazidian-char attributes))
1150 (dolist (ignored '(composition
1151 ->denotational <-subsumptive ->ucs-unified
1152 ->ideographic-component-forms))
1153 (setq attributes (delq ignored attributes))))
1155 (setq name (car attributes))
1156 (unless (eq (setq value (get-char-attribute char name 'value-is-empty))
1158 (cond ((setq ret (find-charset name))
1159 (setq name (charset-name ret))
1160 (when (not (memq name dest-ccss))
1161 (setq dest-ccss (cons name dest-ccss))
1162 (char-db-insert-ccs-feature name value line-breaking))
1164 ((string-match "^=>ucs@" (symbol-name name))
1165 (insert (format "(%-18s . #x%04X)\t; %c%s"
1166 name value (decode-char '=ucs value)
1169 ((eq name 'jisx0208-1978/4X)
1170 (insert (format "(%-18s . #x%04X)%s"
1176 (not (eq name '->subsumptive))
1177 (not (eq name '->uppercase))
1178 (not (eq name '->lowercase))
1179 (not (eq name '->titlecase))
1180 (not (eq name '->canonical))
1181 (not (eq name '->Bopomofo))
1182 (not (eq name '->mistakable))
1183 (not (eq name '->ideographic-variants))
1184 (null (get-char-attribute
1185 char (intern (format "%s*sources" name))))
1186 (not (string-match "\\*sources$" (symbol-name name)))
1187 (null (get-char-attribute
1188 char (intern (format "%s*note" name))))
1189 (not (string-match "\\*note$" (symbol-name name)))
1190 (or (eq name '<-identical)
1191 (eq name '<-uppercase)
1192 (eq name '<-lowercase)
1193 (eq name '<-titlecase)
1194 (eq name '<-canonical)
1195 (eq name '<-ideographic-variants)
1196 ;; (eq name '<-synonyms)
1197 (string-match "^<-synonyms" (symbol-name name))
1198 (eq name '<-mistakable)
1199 (when (string-match "^->" (symbol-name name))
1201 ((string-match "^->fullwidth" (symbol-name name))
1202 (not (and (consp value)
1203 (characterp (car value))
1205 (car value) '=ucs 'defined-only)))
1210 ((or (eq name 'ideographic-structure)
1211 (eq name 'ideographic-combination)
1212 (eq name 'ideographic-)
1213 (eq name '=decomposition)
1214 (char-feature-base-name= '=decomposition name)
1215 (char-feature-base-name= '=>decomposition name)
1216 ;; (string-match "^=>*decomposition\\(@[^*]+\\)?$"
1217 ;; (symbol-name name))
1218 (string-match "^\\(->\\|<-\\)[^*]*$" (symbol-name name))
1219 (string-match "^\\(->\\|<-\\)[^*]*\\*sources$"
1222 (char-db-insert-relation-feature char name value
1225 ((memq name '(ideograph=
1226 original-ideograph-of
1227 ancient-ideograph-of
1230 ;; simplified-ideograph-of
1231 ideographic-variants
1232 ;; ideographic-different-form-of
1234 (insert (format "(%-18s%s " name line-breaking))
1235 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1237 (while (consp value)
1238 (setq cell (car value))
1239 (if (and (consp cell)
1244 (char-db-insert-alist cell readable)
1245 (setq separator lbs))
1248 (insert (prin1-to-string cell))
1249 (setq separator " "))
1250 (setq value (cdr value)))
1252 (insert line-breaking))
1254 (insert (format "(%-18s " name))
1255 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1257 (while (consp value)
1258 (setq cell (car value))
1259 (if (and (consp cell)
1261 (setq ret (condition-case nil
1269 (setq key (car (car rest)))
1270 (if (find-charset key)
1271 (setq cal (cons key cal))
1272 (setq al (cons key al)))
1273 (setq rest (cdr rest)))
1276 (insert-char-attributes ret
1280 (setq separator lbs))
1281 (setq ret (prin1-to-string cell))
1283 (if (< (+ (current-column)
1290 (setq separator " "))
1291 (setq value (cdr value)))
1293 (insert line-breaking))
1295 (insert (format "(%-18s" name))
1296 (setq ret (prin1-to-string value))
1297 (unless (< (+ (current-column)
1301 (insert line-breaking))
1302 (insert " . " ret ")" line-breaking)
1303 ;; (insert (format "(%-18s . %S)%s"
1308 (setq attributes (cdr attributes)))
1311 (defun insert-char-data (char &optional readable
1314 (narrow-to-region (point)(point))
1315 (insert "(define-char
1317 (insert-char-attributes char readable attributes)
1319 (goto-char (point-min))
1320 (while (re-search-forward "[ \t]+$" nil t)
1323 (goto-char (point-min))
1324 (while (re-search-forward "[ \t][ \t][ \t]*" nil t)
1325 (let ((column (current-column))
1326 (indent-tabs-mode t))
1327 (delete-region (match-beginning 0) (point))
1328 (indent-to column)))
1329 (goto-char (point-max))
1330 ;; (tabify (point-min)(point-max))
1333 (defun insert-char-data-with-variant (char &optional printable
1335 script excluded-script)
1336 (insert-char-data char printable)
1337 (let ((variants (char-variants char))
1340 (setq variants (sort variants #'<))
1341 (setq rest variants)
1342 (setq variants (cons char variants))
1344 (setq variant (car rest))
1345 (unless (get-char-attribute variant '<-subsumptive)
1346 (if (and (or (null script)
1347 (null (setq vs (get-char-attribute variant 'script)))
1349 (or (null excluded-script)
1350 (null (setq vs (get-char-attribute variant 'script)))
1351 (not (memq excluded-script vs))))
1352 (unless (and no-ucs-unified (get-char-attribute variant '=ucs))
1353 (insert-char-data variant printable)
1354 (if (setq ret (char-variants variant))
1356 (or (memq (car ret) variants)
1357 ;; (get-char-attribute (car ret) '<-subsumptive)
1358 (setq rest (nconc rest (list (car ret)))))
1359 (setq ret (cdr ret)))))))
1360 (setq rest (cdr rest)))))
1362 (defun insert-char-range-data (min max &optional script excluded-script)
1365 (while (<= code max)
1366 (setq char (decode-char '=ucs code))
1367 (if (encode-char char '=ucs 'defined-only)
1368 (insert-char-data-with-variant char nil 'no-ucs-unified
1369 script excluded-script))
1370 (setq code (1+ code)))))
1372 (defun write-char-range-data-to-file (min max file
1373 &optional script excluded-script)
1374 (let ((coding-system-for-write char-db-file-coding-system))
1376 (insert (format ";; -*- coding: %s -*-\n"
1377 char-db-file-coding-system))
1378 (insert-char-range-data min max script excluded-script)
1379 (write-region (point-min)(point-max) file))))
1381 (defvar what-character-original-window-configuration)
1384 (defun what-char-definition (char)
1385 (interactive (list (char-after)))
1386 (let ((buf (get-buffer-create "*Character Description*"))
1387 (the-buf (current-buffer))
1388 (win-conf (current-window-configuration)))
1390 (make-local-variable 'what-character-original-window-configuration)
1391 (setq what-character-original-window-configuration win-conf)
1392 (setq buffer-read-only nil)
1396 (insert-char-data-with-variant char 'printable)
1397 (unless (char-attribute-alist char)
1398 (insert (format ";; = %c\n"
1399 (let* ((rest (split-char char))
1403 (setq code (logior (lsh code 8)
1405 (decode-char ccs code)))))
1406 ;; (char-db-update-comment)
1407 (set-buffer-modified-p nil)
1408 (view-mode the-buf (lambda (buf)
1409 (set-window-configuration
1410 what-character-original-window-configuration)
1412 (goto-char (point-min)))
1414 (set-window-configuration
1415 what-character-original-window-configuration)
1416 (signal (car err) (cdr err)))))))
1422 (provide 'char-db-util)
1424 ;;; char-db-util.el ends here