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 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 ?鼓 ?豈 ?豆 ?豊 ?豐 ?䖒 ?虍 ?虎 ?虤 ?皿 ; 170
84 ?𠙴 ?去 ?血 ?丶 ?丹 ?青 ?井 ?皀 ?鬯 ?食 ; 180
85 ?亼 ?會 ?倉 ?入 ?缶 ?矢 ?高 ?冂 ?𩫏 ?京 ; 190
86 ?亯 ?𣆪 ?畗 ?㐭 ?嗇 ?來 ?麥 ?夊 ?舛 ?䑞 ; 200
87 ?韋 ?弟 ?夂 ?久 ?桀 ?木 ?東 ?林 ?才 ?叒 ; 210
88 ?之 ?帀 ?出 ?𣎵 ?生 ?乇 ?𠂹 ?𠌶 ?華 ?𥝌 ; 220
89 ?稽 ?巢 ?桼 ?束 ?㯻 ?囗 ?員 ?貝 ?邑 ?𨛜 ; 230
90 ?日 ?旦 ?倝 ?㫃 ?冥 ?晶 ?月 ?有 ?明 ?囧 ; 240
91 ?夕 ?多 ?毌 ?𢎘 ?𣐺 ?卣 ?齊 ?朿 ?片 ?鼎 ; 250
92 ?克 ?彔 ?禾 ?秝 ?黍 ?香 ?米 ?毇 ?臼 ?凶 ; 260
93 ?𣎳 ?林 ?麻 ?尗 ?耑 ?韭 ?瓜 ?瓠 ?宀 ?宮 ; 270
94 ?呂 ?穴 ?㝱 ?𤕫 ?冖 ?𠔼 ?冃 ?㒳 ?网 ?襾 ; 280
95 ?巾 ?巿 ?帛 ?白 ?㡀 ?黹 ?人 ?𠤎 ?匕 ?从 ; 290
98 (defun shuowen-radical (number)
99 (aref shuowen-radicals (1- number)))
101 (defvar char-db-file-coding-system 'utf-8-mcs-er)
103 (defvar char-db-ignored-attributes '(ideographic-products))
105 (defvar char-db-coded-charset-priority-list
264 ;;; @ char-db formatters
267 (defun char-db-make-char-spec (char)
269 (cond ((characterp char)
270 (cond ((and (setq ret (encode-char char '=ucs 'defined-only))
271 (not (and (<= #xE000 ret)(<= ret #xF8FF))))
272 (setq char-spec (list (cons '=ucs ret)))
273 (cond ((setq ret (get-char-attribute char 'name))
274 (setq char-spec (cons (cons 'name ret) char-spec))
276 ((setq ret (get-char-attribute char 'name*))
277 (setq char-spec (cons (cons 'name* ret) char-spec))
280 ((encode-char char '=adobe-japan1 'defined-only)
282 (dolist (ccs (charset-list))
283 (if (and (or (memq ccs
292 ;; (eq (charset-property ccs 'iso-ir) 177)
293 (string-match "=ucs@" (symbol-name ccs))
295 (setq ccs (charset-name ccs))
296 (null (assq ccs char-spec))
297 (setq ret (encode-char char ccs 'defined-only)))
298 (setq char-spec (cons (cons ccs ret) char-spec))))
302 (let ((rest char-db-coded-charset-priority-list)
305 (setq ccs (charset-name
306 (find-charset (car rest))))
308 (encode-char char ccs
310 (throw 'tag (cons ccs ret)))
311 (setq rest (cdr rest))))))
312 (setq char-spec (list ret))
313 (dolist (ccs (delq (car ret) (charset-list)))
314 (if (and (or (charset-iso-final-char ccs)
321 (eq (charset-property ccs 'iso-ir) 177)
322 ;; (string-match "=ucs@" (symbol-name ccs))
324 (setq ccs (charset-name ccs))
325 (null (assq ccs char-spec))
326 (setq ret (encode-char char ccs 'defined-only)))
327 (setq char-spec (cons (cons ccs ret) char-spec))))
329 (setq char-spec (split-char char)))
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 ((setq ret (get-char-attribute
338 char 'ideographic-combination))
340 (cons (cons 'ideographic-combination ret)
347 (defun char-db-insert-char-spec (char &optional readable column
350 (setq column (current-column)))
351 (let (char-spec temp-char)
352 (setq char-spec (char-db-make-char-spec char))
353 (unless (or (characterp char) ; char
355 (setq char (find-char char-spec))
357 ;; define temporary character
358 ;; Current implementation is dirty.
359 (setq temp-char (define-char (cons '(ideograph-daikanwa . 0)
361 (remove-char-attribute temp-char 'ideograph-daikanwa)
362 (setq char temp-char))
363 (insert-char-attributes char
365 (union (mapcar #'car char-spec)
369 ;; undefine temporary character
370 ;; Current implementation is dirty.
371 (setq char-spec (char-attribute-alist temp-char))
373 (remove-char-attribute temp-char (car (car char-spec)))
374 (setq char-spec (cdr char-spec))))))
376 (defun char-db-insert-alist (alist &optional readable column)
378 (setq column (current-column)))
380 (concat "\n" (make-string (1+ column) ?\ )))
384 lbs cell rest separator)
387 (setq name (car (car alist))
388 value (cdr (car alist)))
389 (cond ((eq name 'char)
391 (if (setq ret (condition-case nil
399 (setq key (car (car value)))
400 ;; (if (find-charset key)
401 ;; (setq cal (cons key cal))
402 (setq al (cons key al))
404 (setq value (cdr value)))
405 (insert-char-attributes ret
409 (insert (prin1-to-string value)))
411 (insert line-breaking))
413 (insert (format "(%-18s " name))
414 (setq lbs (concat "\n" (make-string (current-column) ?\ )))
416 (setq cell (car value))
417 (if (and (consp cell)
419 (setq ret (condition-case nil
429 (setq key (car (car rest)))
430 ;; (if (find-charset key)
431 ;; (setq cal (cons key cal))
432 (setq al (cons key al))
434 (setq rest (cdr rest)))
437 (insert-char-attributes ret
441 (setq separator lbs))
444 (insert (prin1-to-string cell))
445 (setq separator " "))
446 (setq value (cdr value)))
448 (insert line-breaking))
450 (insert (format "(%-18s . %S)%s"
453 (setq alist (cdr alist))))
456 (defun char-db-insert-char-reference (plist &optional readable column)
458 (setq column (current-column)))
460 (concat "\n" (make-string (1+ column) ?\ )))
465 (setq name (pop plist))
466 (setq value (pop plist))
467 (cond ((eq name :char)
470 (cond ((numberp value)
471 (setq value (decode-char '=ucs value)))
473 ;; (setq value (or (find-char value)
476 (char-db-insert-char-spec value readable)
477 (insert line-breaking)
480 (insert (format "%s%s\t%d ; %c%s"
483 (ideographic-radical value)
487 (insert (format "%s%s\t%S" separator name value))
488 (setq separator line-breaking)))
492 (defun char-db-decode-isolated-char (ccs code-point)
495 (cond ((eq ccs 'arabic-iso8859-6)
496 (decode-char ccs code-point))
497 ((and (memq ccs '(=gt-pj-1
508 (setq ret (decode-char ccs code-point))
509 (setq ret (encode-char ret '=gt 'defined-only)))
510 (decode-builtin-char '=gt ret))
512 (decode-builtin-char ccs code-point))))
513 (cond ((and (<= 0 (char-int ret))
514 (<= (char-int ret) #x1F))
515 (decode-char '=ucs (+ #x2400 (char-int ret))))
516 ((= (char-int ret) #x7F)
520 (defvar char-db-convert-obsolete-format t)
522 (defun char-db-insert-ccs-feature (name value line-breaking)
528 ((memq name '(=shinjigen
530 =shinjigen@rev =shinjigen/+p@rev
531 =daikanwa/ho =>>daikanwa/ho =>daikanwa/ho))
532 "(%-18s . %04d)\t; %c")
533 ((eq name '=shinjigen@1ed/24pr)
534 "(%-18s . %04d)\t; %c")
535 ((or (memq name '(=daikanwa =>>daikanwa =>daikanwa
536 =daikanwa@rev1 =daikanwa@rev2
537 =daikanwa/+p =>>daikanwa/+p
538 =daikanwa/+2p =>>daikanwa/+2p
539 =gt =>>>gt =>>gt =+>gt =>gt
541 =adobe-japan1-0 =>>>adobe-japan1-0
542 =adobe-japan1-1 =>>>adobe-japan1-1
543 =adobe-japan1-2 =>>>adobe-japan1-2
544 =adobe-japan1-3 =>>>adobe-japan1-3
545 =adobe-japan1-4 =>>>adobe-japan1-4
546 =adobe-japan1-5 =>>>adobe-japan1-5
547 =adobe-japan1-6 =>>>adobe-japan1-6
548 =>>adobe-japan1-0 =+>adobe-japan1-0
549 =>>adobe-japan1-1 =+>adobe-japan1-1
550 =>>adobe-japan1-2 =+>adobe-japan1-2
551 =>>adobe-japan1-3 =+>adobe-japan1-3
552 =>>adobe-japan1-4 =+>adobe-japan1-4
553 =>>adobe-japan1-5 =+>adobe-japan1-5
554 =>>adobe-japan1-6 =+>adobe-japan1-6
556 =zinbun-oracle =>zinbun-oracle))
557 ;; (string-match "^=adobe-" (symbol-name name))
559 "(%-18s . %05d)\t; %c")
560 ((memq name '(=hanyo-denshi/ks =>>>hanyo-denshi/ks =>>hanyo-denshi/ks mojikyo))
561 "(%-18s . %06d)\t; %c")
562 ((>= (charset-dimension name) 2)
563 "(%-18s . #x%04X)\t; %c")
565 "(%-18s . #x%02X)\t; %c"))
567 (if (= (charset-iso-graphic-plane name) 1)
569 (cond ((= (charset-dimension name) 1)
571 ((= (charset-dimension name) 2)
573 ((= (charset-dimension name) 3)
577 (char-db-decode-isolated-char name value)))
578 (if (and (= (charset-chars name) 94)
579 (= (charset-dimension name) 2))
580 (insert (format " [%02d-%02d]"
581 (- (lsh value -8) 32)
582 (- (logand value 255) 32))))
585 (insert (format "(%-18s . %s)" name value))
587 (insert line-breaking))
589 (defun char-db-insert-relation-feature (char name value line-breaking
591 (insert (format "(%-18s%s " name line-breaking))
592 (let ((lbs (concat "\n" (make-string (current-column) ?\ )))
593 separator cell sources required-features
596 (setq cell (car value))
598 (setq cell (decode-char '=ucs cell)))
600 ((eq name '->subsumptive)
601 (when (or (not (some (lambda (atr)
602 (get-char-attribute cell atr))
603 char-db-ignored-attributes))
605 (encode-char cell ccs 'defined-only))
609 (let ((char-db-ignored-attributes
611 char-db-ignored-attributes)))
612 (insert-char-attributes cell readable nil nil 'for-sub-node))
613 (setq separator lbs))
618 char (intern (format "%s*sources" name))))
619 (setq required-features nil)
620 (dolist (source sources)
624 shinjigen shinjigen@1ed shinjigen@rev))
625 (setq required-features
626 (union required-features
637 (setq required-features
638 (union required-features
643 ((find-charset (setq ret (intern (format "=%s" source))))
644 (setq required-features
645 (cons ret required-features)))
646 (t (setq required-features
647 (cons source required-features)))))
648 (cond ((string-match "@JP" (symbol-name name))
649 (setq required-features
650 (union required-features
658 ((string-match "@CN" (symbol-name name))
659 (setq required-features
660 (union required-features
667 (insert (format "%S" cell))
668 (char-db-insert-char-spec cell readable
671 (setq separator lbs))
675 (if (consp (car cell))
676 (char-db-insert-char-spec cell readable)
677 (char-db-insert-char-reference cell readable))
678 (setq separator lbs))
682 (insert (prin1-to-string cell))
683 (setq separator " ")))
684 (setq value (cdr value)))
686 (insert line-breaking)))
688 (defun insert-char-attributes (char &optional readable attributes column
691 (setq column (current-column)))
692 (let (name value ; has-long-ccs-name
696 (concat "\n" (make-string (1+ column) ?\ )))
697 lbs cell separator ret
699 dest-ccss ; sources required-features
704 (if (consp attributes)
706 (dolist (name attributes)
707 (unless (memq name char-db-ignored-attributes)
708 (if (find-charset name)
712 (dolist (name (char-attribute-list))
713 (unless (memq name char-db-ignored-attributes)
714 (if (find-charset name)
718 #'char-attribute-name<)))
720 (when (memq '<-subsumptive attributes)
721 (when (or readable (not for-sub-node))
722 (when (setq value (get-char-attribute char '<-subsumptive))
723 (char-db-insert-relation-feature char '<-subsumptive value
726 (setq attributes (delq '<-subsumptive attributes)))
727 (when (and (memq '<-denotational attributes)
728 (setq value (get-char-attribute char '<-denotational)))
729 (char-db-insert-relation-feature char '<-denotational value
732 (setq attributes (delq '<-denotational attributes)))
733 (when (and (memq 'name attributes)
734 (setq value (get-char-attribute char 'name)))
736 (if (> (+ (current-column) (length value)) 48)
739 value line-breaking))
740 (setq attributes (delq 'name attributes))
742 (when (and (memq 'name* attributes)
743 (setq value (get-char-attribute char 'name*)))
745 (if (> (+ (current-column) (length value)) 48)
748 value line-breaking))
749 (setq attributes (delq 'name* attributes))
751 (when (and (memq 'script attributes)
752 (setq value (get-char-attribute char 'script)))
753 (insert (format "(script\t\t%s)%s"
754 (mapconcat (function prin1-to-string)
757 (setq attributes (delq 'script attributes))
759 (dolist (name '(=>ucs =>ucs*))
760 (when (and (memq name attributes)
761 (setq value (get-char-attribute char name)))
762 (insert (format "(%-18s . #x%04X)\t; %c%s"
763 name value (decode-char '=ucs value)
765 (setq attributes (delq name attributes))))
766 (dolist (name '(=>ucs@gb =>ucs@big5))
767 (when (and (memq name attributes)
768 (setq value (get-char-attribute char name)))
769 (insert (format "(%-18s . #x%04X)\t; %c%s"
774 (symbol-name name) 2)))
777 (setq attributes (delq name attributes))
779 ;; (dolist (name '(=>daikanwa))
780 ;; (when (and (memq name attributes)
781 ;; (setq value (get-char-attribute char name)))
783 ;; (if (integerp value)
784 ;; (format "(%-18s . %05d)\t; %c%s"
785 ;; name value (decode-char '=daikanwa value)
787 ;; (format "(%-18s %s)\t; %c%s"
789 ;; (mapconcat (function prin1-to-string)
791 ;; (char-representative-of-daikanwa char)
793 ;; (setq attributes (delq name attributes))))
794 (when (and (memq 'general-category attributes)
795 (setq value (get-char-attribute char 'general-category)))
797 "(general-category\t%s) ; %s%s"
798 (mapconcat (lambda (cell)
801 (cond ((rassoc value unidata-normative-category-alist)
802 "Normative Category")
803 ((rassoc value unidata-informative-category-alist)
804 "Informative Category")
808 (setq attributes (delq 'general-category attributes))
810 (when (and (memq 'bidi-category attributes)
811 (setq value (get-char-attribute char 'bidi-category)))
812 (insert (format "(bidi-category\t. %S)%s"
815 (setq attributes (delq 'bidi-category attributes))
817 (unless (or (not (memq 'mirrored attributes))
818 (eq (setq value (get-char-attribute char 'mirrored 'empty))
820 (insert (format "(mirrored\t\t. %S)%s"
823 (setq attributes (delq 'mirrored attributes))
826 ((and (memq 'decimal-digit-value attributes)
827 (setq value (get-char-attribute char 'decimal-digit-value)))
828 (insert (format "(decimal-digit-value . %S)%s"
831 (setq attributes (delq 'decimal-digit-value attributes))
832 (when (and (memq 'digit-value attributes)
833 (setq value (get-char-attribute char 'digit-value)))
834 (insert (format "(digit-value\t . %S)%s"
837 (setq attributes (delq 'digit-value attributes))
839 (when (and (memq 'numeric-value attributes)
840 (setq value (get-char-attribute char 'numeric-value)))
841 (insert (format "(numeric-value\t . %S)%s"
844 (setq attributes (delq 'numeric-value attributes))
848 (when (and (memq 'digit-value attributes)
849 (setq value (get-char-attribute char 'digit-value)))
850 (insert (format "(digit-value\t. %S)%s"
853 (setq attributes (delq 'digit-value attributes))
855 (when (and (memq 'numeric-value attributes)
856 (setq value (get-char-attribute char 'numeric-value)))
857 (insert (format "(numeric-value\t. %S)%s"
860 (setq attributes (delq 'numeric-value attributes))
862 (when (and (memq 'iso-10646-comment attributes)
863 (setq value (get-char-attribute char 'iso-10646-comment)))
864 (insert (format "(iso-10646-comment\t. %S)%s"
867 (setq attributes (delq 'iso-10646-comment attributes))
869 (when (and (memq 'morohashi-daikanwa attributes)
870 (setq value (get-char-attribute char 'morohashi-daikanwa)))
871 (insert (format "(morohashi-daikanwa\t%s)%s"
872 (mapconcat (function prin1-to-string) value " ")
874 (setq attributes (delq 'morohashi-daikanwa attributes))
878 (when (and (memq 'ideographic-radical attributes)
879 (setq value (get-char-attribute char 'ideographic-radical)))
881 (insert (format "(ideographic-radical . %S)\t; %c%s"
883 (ideographic-radical radical)
885 (setq attributes (delq 'ideographic-radical attributes))
887 (when (and (memq 'shuowen-radical attributes)
888 (setq value (get-char-attribute char 'shuowen-radical)))
889 (insert (format "(shuowen-radical\t. %S)\t; %c%s"
891 (shuowen-radical value)
893 (setq attributes (delq 'shuowen-radical attributes))
898 char-db-feature-domains
900 (dolist (feature (char-attribute-list))
901 (setq feature (symbol-name feature))
903 "\\(radical\\|strokes\\)@\\([^@*]+\\)\\(\\*\\|$\\)"
905 (setq domain (intern (match-string 2 feature)))
906 (unless (memq domain dest)
907 (setq dest (cons domain dest)))))
908 (sort dest #'string<))))
909 (setq key (intern (format "%s@%s" 'ideographic-radical domain)))
910 (when (and (memq key attributes)
911 (setq value (get-char-attribute char key)))
913 (insert (format "(%s . %S)\t; %c%s"
916 (ideographic-radical radical)
918 (setq attributes (delq key attributes))
920 (setq key (intern (format "%s@%s" 'ideographic-strokes domain)))
921 (when (and (memq key attributes)
922 (setq value (get-char-attribute char key)))
924 (insert (format "(%s . %S)%s"
928 (setq attributes (delq key attributes))
930 (setq key (intern (format "%s@%s" 'total-strokes domain)))
931 (when (and (memq key attributes)
932 (setq value (get-char-attribute char key)))
933 (insert (format "(%s . %S)%s"
937 (setq attributes (delq key attributes))
939 (dolist (feature '(ideographic-radical
942 (setq key (intern (format "%s@%s*sources" feature domain)))
943 (when (and (memq key attributes)
944 (setq value (get-char-attribute char key)))
945 (insert (format "(%s%s" key line-breaking))
947 (insert (format " %s" cell)))
949 (insert line-breaking)
950 (setq attributes (delq key attributes))
953 (when (and (memq 'ideographic-strokes attributes)
954 (setq value (get-char-attribute char 'ideographic-strokes)))
956 (insert (format "(ideographic-strokes . %S)%s"
959 (setq attributes (delq 'ideographic-strokes attributes))
961 (when (and (memq 'kangxi-radical attributes)
962 (setq value (get-char-attribute char 'kangxi-radical)))
963 (unless (eq value radical)
964 (insert (format "(kangxi-radical\t . %S)\t; %c%s"
966 (ideographic-radical value)
969 (setq radical value)))
970 (setq attributes (delq 'kangxi-radical attributes))
972 (when (and (memq 'kangxi-strokes attributes)
973 (setq value (get-char-attribute char 'kangxi-strokes)))
974 (unless (eq value strokes)
975 (insert (format "(kangxi-strokes\t . %S)%s"
979 (setq strokes value)))
980 (setq attributes (delq 'kangxi-strokes attributes))
982 (when (and (memq 'japanese-radical attributes)
983 (setq value (get-char-attribute char 'japanese-radical)))
984 (unless (eq value radical)
985 (insert (format "(japanese-radical\t . %S)\t; %c%s"
987 (ideographic-radical value)
990 (setq radical value)))
991 (setq attributes (delq 'japanese-radical attributes))
993 (when (and (memq 'japanese-strokes attributes)
994 (setq value (get-char-attribute char 'japanese-strokes)))
995 (unless (eq value strokes)
996 (insert (format "(japanese-strokes\t . %S)%s"
1000 (setq strokes value)))
1001 (setq attributes (delq 'japanese-strokes attributes))
1003 (when (and (memq 'cns-radical attributes)
1004 (setq value (get-char-attribute char 'cns-radical)))
1005 (insert (format "(cns-radical\t . %S)\t; %c%s"
1007 (ideographic-radical value)
1009 (setq attributes (delq 'cns-radical attributes))
1011 (when (and (memq 'cns-strokes attributes)
1012 (setq value (get-char-attribute char 'cns-strokes)))
1013 (unless (eq value strokes)
1014 (insert (format "(cns-strokes\t . %S)%s"
1018 (setq strokes value)))
1019 (setq attributes (delq 'cns-strokes attributes))
1021 (when (and (memq 'shinjigen-1-radical attributes)
1022 (setq value (get-char-attribute char 'shinjigen-1-radical)))
1023 (unless (eq value radical)
1024 (insert (format "(shinjigen-1-radical . %S)\t; %c%s"
1026 (ideographic-radical value)
1029 (setq radical value)))
1030 (setq attributes (delq 'shinjigen-1-radical attributes))
1032 (when (and (memq 'ideographic- attributes)
1033 (setq value (get-char-attribute char 'ideographic-)))
1034 (insert "(ideographic- ")
1035 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1037 (while (consp value)
1038 (setq cell (car value))
1040 (setq cell (decode-char '=ucs cell)))
1041 (cond ((characterp cell)
1045 (insert (format "%S" cell))
1046 (char-db-insert-char-spec cell readable))
1047 (setq separator lbs))
1051 (if (consp (car cell))
1052 (char-db-insert-char-spec cell readable)
1053 (char-db-insert-char-reference cell readable))
1054 (setq separator lbs))
1058 (insert (prin1-to-string cell))
1059 (setq separator " ")))
1060 (setq value (cdr value)))
1062 (insert line-breaking)
1063 (setq attributes (delq 'ideographic- attributes)))
1064 (when (and (memq 'total-strokes attributes)
1065 (setq value (get-char-attribute char 'total-strokes)))
1066 (insert (format "(total-strokes . %S)%s"
1069 (setq attributes (delq 'total-strokes attributes))
1071 (when (and (memq '->ideograph attributes)
1072 (setq value (get-char-attribute char '->ideograph)))
1073 (insert (format "(->ideograph\t%s)%s"
1074 (mapconcat (lambda (code)
1075 (cond ((symbolp code)
1078 (format "#x%04X" code))
1081 line-breaking code))))
1084 (setq attributes (delq '->ideograph attributes))
1086 ;; (when (and (memq '->decomposition attributes)
1087 ;; (setq value (get-char-attribute char '->decomposition)))
1088 ;; (insert (format "(->decomposition\t%s)%s"
1089 ;; (mapconcat (lambda (code)
1090 ;; (cond ((symbolp code)
1091 ;; (symbol-name code))
1092 ;; ((characterp code)
1094 ;; (format "%S" code)
1099 ;; (format "#x%04X" code))
1101 ;; (format "%s%S" line-breaking code))))
1104 ;; (setq attributes (delq '->decomposition attributes))
1106 (if (equal (get-char-attribute char '->titlecase)
1107 (get-char-attribute char '->uppercase))
1108 (setq attributes (delq '->titlecase attributes)))
1109 (when (and (memq '->mojikyo attributes)
1110 (setq value (get-char-attribute char '->mojikyo)))
1111 (insert (format "(->mojikyo\t\t. %06d)\t; %c%s"
1112 value (decode-char 'mojikyo value)
1114 (setq attributes (delq '->mojikyo attributes))
1116 (when (and (memq 'hanyu-dazidian-vol attributes)
1117 (setq value (get-char-attribute char 'hanyu-dazidian-vol)))
1118 (insert (format "(hanyu-dazidian-vol . %d)%s"
1119 value line-breaking))
1120 (setq attributes (delq 'hanyu-dazidian-vol attributes))
1122 (when (and (memq 'hanyu-dazidian-page attributes)
1123 (setq value (get-char-attribute char 'hanyu-dazidian-page)))
1124 (insert (format "(hanyu-dazidian-page . %d)%s"
1125 value line-breaking))
1126 (setq attributes (delq 'hanyu-dazidian-page attributes))
1128 (when (and (memq 'hanyu-dazidian-char attributes)
1129 (setq value (get-char-attribute char 'hanyu-dazidian-char)))
1130 (insert (format "(hanyu-dazidian-char . %d)%s"
1131 value line-breaking))
1132 (setq attributes (delq 'hanyu-dazidian-char attributes))
1135 (dolist (ignored '(composition
1136 ->denotational <-subsumptive ->ucs-unified
1137 ->ideographic-component-forms))
1138 (setq attributes (delq ignored attributes))))
1140 (setq name (car attributes))
1141 (unless (eq (setq value (get-char-attribute char name 'value-is-empty))
1143 (cond ((setq ret (find-charset name))
1144 (setq name (charset-name ret))
1145 (when (not (memq name dest-ccss))
1146 (setq dest-ccss (cons name dest-ccss))
1147 (char-db-insert-ccs-feature name value line-breaking))
1149 ((string-match "^=>ucs@" (symbol-name name))
1150 (insert (format "(%-18s . #x%04X)\t; %c%s"
1151 name value (decode-char '=ucs value)
1154 ((eq name 'jisx0208-1978/4X)
1155 (insert (format "(%-18s . #x%04X)%s"
1161 (not (eq name '->subsumptive))
1162 (not (eq name '->uppercase))
1163 (not (eq name '->lowercase))
1164 (not (eq name '->titlecase))
1165 (not (eq name '->canonical))
1166 (not (eq name '->Bopomofo))
1167 (not (eq name '->mistakable))
1168 (not (eq name '->ideographic-variants))
1169 (null (get-char-attribute
1170 char (intern (format "%s*sources" name))))
1171 (not (string-match "\\*sources$" (symbol-name name)))
1172 (null (get-char-attribute
1173 char (intern (format "%s*note" name))))
1174 (not (string-match "\\*note$" (symbol-name name)))
1175 (or (eq name '<-identical)
1176 (eq name '<-uppercase)
1177 (eq name '<-lowercase)
1178 (eq name '<-titlecase)
1179 (eq name '<-canonical)
1180 (eq name '<-ideographic-variants)
1181 ;; (eq name '<-synonyms)
1182 (string-match "^<-synonyms" (symbol-name name))
1183 (eq name '<-mistakable)
1184 (when (string-match "^->" (symbol-name name))
1186 ((string-match "^->fullwidth" (symbol-name name))
1187 (not (and (consp value)
1188 (characterp (car value))
1190 (car value) '=ucs 'defined-only)))
1195 ((or (eq name 'ideographic-structure)
1196 (eq name 'ideographic-combination)
1197 (eq name 'ideographic-)
1198 (eq name '=decomposition)
1199 (char-feature-base-name= '=decomposition name)
1200 (char-feature-base-name= '=>decomposition name)
1201 ;; (string-match "^=>*decomposition\\(@[^*]+\\)?$"
1202 ;; (symbol-name name))
1203 (string-match "^\\(->\\|<-\\)[^*]*$" (symbol-name name))
1204 (string-match "^\\(->\\|<-\\)[^*]*\\*sources$"
1207 (char-db-insert-relation-feature char name value
1210 ((memq name '(ideograph=
1211 original-ideograph-of
1212 ancient-ideograph-of
1215 ;; simplified-ideograph-of
1216 ideographic-variants
1217 ;; ideographic-different-form-of
1219 (insert (format "(%-18s%s " name line-breaking))
1220 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1222 (while (consp value)
1223 (setq cell (car value))
1224 (if (and (consp cell)
1229 (char-db-insert-alist cell readable)
1230 (setq separator lbs))
1233 (insert (prin1-to-string cell))
1234 (setq separator " "))
1235 (setq value (cdr value)))
1237 (insert line-breaking))
1239 (insert (format "(%-18s " name))
1240 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1242 (while (consp value)
1243 (setq cell (car value))
1244 (if (and (consp cell)
1246 (setq ret (condition-case nil
1254 (setq key (car (car rest)))
1255 (if (find-charset key)
1256 (setq cal (cons key cal))
1257 (setq al (cons key al)))
1258 (setq rest (cdr rest)))
1261 (insert-char-attributes ret
1265 (setq separator lbs))
1266 (setq ret (prin1-to-string cell))
1268 (if (< (+ (current-column)
1275 (setq separator " "))
1276 (setq value (cdr value)))
1278 (insert line-breaking))
1280 (insert (format "(%-18s" name))
1281 (setq ret (prin1-to-string value))
1282 (unless (< (+ (current-column)
1286 (insert line-breaking))
1287 (insert " . " ret ")" line-breaking)
1288 ;; (insert (format "(%-18s . %S)%s"
1293 (setq attributes (cdr attributes)))
1296 (defun insert-char-data (char &optional readable
1299 (narrow-to-region (point)(point))
1300 (insert "(define-char
1302 (insert-char-attributes char readable attributes)
1304 (goto-char (point-min))
1305 (while (re-search-forward "[ \t]+$" nil t)
1308 (goto-char (point-min))
1309 (while (re-search-forward "[ \t][ \t][ \t]*" nil t)
1310 (let ((column (current-column))
1311 (indent-tabs-mode t))
1312 (delete-region (match-beginning 0) (point))
1313 (indent-to column)))
1314 (goto-char (point-max))
1315 ;; (tabify (point-min)(point-max))
1318 (defun insert-char-data-with-variant (char &optional printable
1320 script excluded-script)
1321 (insert-char-data char printable)
1322 (let ((variants (char-variants char))
1325 (setq variants (sort variants #'<))
1326 (setq rest variants)
1327 (setq variants (cons char variants))
1329 (setq variant (car rest))
1330 (unless (get-char-attribute variant '<-subsumptive)
1331 (if (and (or (null script)
1332 (null (setq vs (get-char-attribute variant 'script)))
1334 (or (null excluded-script)
1335 (null (setq vs (get-char-attribute variant 'script)))
1336 (not (memq excluded-script vs))))
1337 (unless (and no-ucs-unified (get-char-attribute variant '=ucs))
1338 (insert-char-data variant printable)
1339 (if (setq ret (char-variants variant))
1341 (or (memq (car ret) variants)
1342 ;; (get-char-attribute (car ret) '<-subsumptive)
1343 (setq rest (nconc rest (list (car ret)))))
1344 (setq ret (cdr ret)))))))
1345 (setq rest (cdr rest)))))
1347 (defun insert-char-range-data (min max &optional script excluded-script)
1350 (while (<= code max)
1351 (setq char (decode-char '=ucs code))
1352 (if (encode-char char '=ucs 'defined-only)
1353 (insert-char-data-with-variant char nil 'no-ucs-unified
1354 script excluded-script))
1355 (setq code (1+ code)))))
1357 (defun write-char-range-data-to-file (min max file
1358 &optional script excluded-script)
1359 (let ((coding-system-for-write char-db-file-coding-system))
1361 (insert (format ";; -*- coding: %s -*-\n"
1362 char-db-file-coding-system))
1363 (insert-char-range-data min max script excluded-script)
1364 (write-region (point-min)(point-max) file))))
1366 (defvar what-character-original-window-configuration)
1369 (defun what-char-definition (char)
1370 (interactive (list (char-after)))
1371 (let ((buf (get-buffer-create "*Character Description*"))
1372 (the-buf (current-buffer))
1373 (win-conf (current-window-configuration)))
1375 (make-local-variable 'what-character-original-window-configuration)
1376 (setq what-character-original-window-configuration win-conf)
1377 (setq buffer-read-only nil)
1381 (insert-char-data-with-variant char 'printable)
1382 (unless (char-attribute-alist char)
1383 (insert (format ";; = %c\n"
1384 (let* ((rest (split-char char))
1388 (setq code (logior (lsh code 8)
1390 (decode-char ccs code)))))
1391 ;; (char-db-update-comment)
1392 (set-buffer-modified-p nil)
1393 (view-mode the-buf (lambda (buf)
1394 (set-window-configuration
1395 what-character-original-window-configuration)
1397 (goto-char (point-min)))
1399 (set-window-configuration
1400 what-character-original-window-configuration)
1401 (signal (car err) (cdr err)))))))
1407 (provide 'char-db-util)
1409 ;;; char-db-util.el ends here