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 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
236 ;;; @ char-db formatters
239 (defun char-db-make-char-spec (char)
241 (cond ((characterp char)
242 (cond ((and (setq ret (encode-char char '=ucs 'defined-only))
243 (not (and (<= #xE000 ret)(<= ret #xF8FF))))
244 (setq char-spec (list (cons '=ucs ret)))
245 (cond ((setq ret (get-char-attribute char 'name))
246 (setq char-spec (cons (cons 'name ret) char-spec))
248 ((setq ret (get-char-attribute char 'name*))
249 (setq char-spec (cons (cons 'name* ret) char-spec))
254 (let ((rest char-db-coded-charset-priority-list)
257 (setq ccs (charset-name
258 (find-charset (car rest))))
260 (encode-char char ccs
262 (throw 'tag (cons ccs ret)))
263 (setq rest (cdr rest))))))
264 (setq char-spec (list ret))
265 (dolist (ccs (delq (car ret) (charset-list)))
266 (if (and (or (charset-iso-final-char ccs)
273 (string-match "=ucs@" (symbol-name ccs)))
274 (setq ccs (charset-name ccs))
275 (null (assq ccs char-spec))
276 (setq ret (encode-char char ccs 'defined-only)))
277 (setq char-spec (cons (cons ccs ret) char-spec))))
279 (setq char-spec (split-char char)))
280 (cond ((setq ret (get-char-attribute char 'name))
281 (setq char-spec (cons (cons 'name ret) char-spec))
283 ((setq ret (get-char-attribute char 'name*))
284 (setq char-spec (cons (cons 'name* ret) char-spec))
287 ((setq ret (get-char-attribute
288 char 'ideographic-combination))
290 (cons (cons 'ideographic-combination ret)
297 (defun char-db-insert-char-spec (char &optional readable column
300 (setq column (current-column)))
301 (let (char-spec temp-char)
302 (setq char-spec (char-db-make-char-spec char))
303 (unless (or (characterp char) ; char
305 (setq char (find-char char-spec))
307 ;; define temporary character
308 ;; Current implementation is dirty.
309 (setq temp-char (define-char (cons '(ideograph-daikanwa . 0)
311 (remove-char-attribute temp-char 'ideograph-daikanwa)
312 (setq char temp-char))
313 (insert-char-attributes char
315 (union (mapcar #'car char-spec)
319 ;; undefine temporary character
320 ;; Current implementation is dirty.
321 (setq char-spec (char-attribute-alist temp-char))
323 (remove-char-attribute temp-char (car (car char-spec)))
324 (setq char-spec (cdr char-spec))))))
326 (defun char-db-insert-alist (alist &optional readable column)
328 (setq column (current-column)))
330 (concat "\n" (make-string (1+ column) ?\ )))
334 lbs cell rest separator)
337 (setq name (car (car alist))
338 value (cdr (car alist)))
339 (cond ((eq name 'char)
341 (if (setq ret (condition-case nil
349 (setq key (car (car value)))
350 ;; (if (find-charset key)
351 ;; (setq cal (cons key cal))
352 (setq al (cons key al))
354 (setq value (cdr value)))
355 (insert-char-attributes ret
359 (insert (prin1-to-string value)))
361 (insert line-breaking))
363 (insert (format "(%-18s " name))
364 (setq lbs (concat "\n" (make-string (current-column) ?\ )))
366 (setq cell (car value))
367 (if (and (consp cell)
369 (setq ret (condition-case nil
379 (setq key (car (car rest)))
380 ;; (if (find-charset key)
381 ;; (setq cal (cons key cal))
382 (setq al (cons key al))
384 (setq rest (cdr rest)))
387 (insert-char-attributes ret
391 (setq separator lbs))
394 (insert (prin1-to-string cell))
395 (setq separator " "))
396 (setq value (cdr value)))
398 (insert line-breaking))
400 (insert (format "(%-18s . %S)%s"
403 (setq alist (cdr alist))))
406 (defun char-db-insert-char-reference (plist &optional readable column)
408 (setq column (current-column)))
410 (concat "\n" (make-string (1+ column) ?\ )))
415 (setq name (pop plist))
416 (setq value (pop plist))
417 (cond ((eq name :char)
420 (cond ((numberp value)
421 (setq value (decode-char '=ucs value)))
423 ;; (setq value (or (find-char value)
426 (char-db-insert-char-spec value readable)
427 (insert line-breaking)
430 (insert (format "%s%s\t%d ; %c%s"
433 (ideographic-radical value)
437 (insert (format "%s%s\t%S" separator name value))
438 (setq separator line-breaking)))
442 (defun char-db-decode-isolated-char (ccs code-point)
445 (cond ((eq ccs 'arabic-iso8859-6)
446 (decode-char ccs code-point))
447 ((and (memq ccs '(=gt-pj-1
458 (setq ret (decode-char ccs code-point))
459 (setq ret (encode-char ret '=gt 'defined-only)))
460 (decode-builtin-char '=gt ret))
462 (decode-builtin-char ccs code-point))))
463 (cond ((and (<= 0 (char-int ret))
464 (<= (char-int ret) #x1F))
465 (decode-char '=ucs (+ #x2400 (char-int ret))))
466 ((= (char-int ret) #x7F)
470 (defvar char-db-convert-obsolete-format t)
472 (defun char-db-insert-ccs-feature (name value line-breaking)
478 ((memq name '(=shinjigen
480 =shinjigen@rev =shinjigen/+p@rev
482 "(%-18s . %04d)\t; %c")
483 ((eq name '=shinjigen@1ed/24pr)
484 "(%-18s . %04d)\t; %c")
485 ((or (memq name '(=daikanwa =>>daikanwa =>daikanwa
486 =daikanwa@rev1 =daikanwa@rev2
487 =daikanwa/+p =daikanwa/+2p
488 =gt =>>>gt =>>gt =+>gt =>gt
492 =zinbun-oracle =>zinbun-oracle))
493 (string-match "^=adobe-" (symbol-name name)))
494 "(%-18s . %05d)\t; %c")
495 ((memq name '(=hanyo-denshi/ks =>>hanyo-denshi/ks mojikyo))
496 "(%-18s . %06d)\t; %c")
497 ((>= (charset-dimension name) 2)
498 "(%-18s . #x%04X)\t; %c")
500 "(%-18s . #x%02X)\t; %c"))
502 (if (= (charset-iso-graphic-plane name) 1)
504 (cond ((= (charset-dimension name) 1)
506 ((= (charset-dimension name) 2)
508 ((= (charset-dimension name) 3)
512 (char-db-decode-isolated-char name value)))
513 (if (and (= (charset-chars name) 94)
514 (= (charset-dimension name) 2))
515 (insert (format " [%02d-%02d]"
516 (- (lsh value -8) 32)
517 (- (logand value 255) 32))))
520 (insert (format "(%-18s . %s)" name value))
522 (insert line-breaking))
524 (defun char-db-insert-relation-feature (char name value line-breaking
526 (insert (format "(%-18s%s " name line-breaking))
527 (let ((lbs (concat "\n" (make-string (current-column) ?\ )))
528 separator cell sources required-features
531 (setq cell (car value))
533 (setq cell (decode-char '=ucs cell)))
535 ((eq name '->subsumptive)
536 (when (or (not (some (lambda (atr)
537 (get-char-attribute cell atr))
538 char-db-ignored-attributes))
540 (encode-char cell ccs 'defined-only))
544 (let ((char-db-ignored-attributes
546 char-db-ignored-attributes)))
547 (insert-char-attributes cell readable nil nil 'for-sub-node))
548 (setq separator lbs))
553 char (intern (format "%s*sources" name))))
554 (setq required-features nil)
555 (dolist (source sources)
559 shinjigen shinjigen@1ed shinjigen@rev))
560 (setq required-features
561 (union required-features
572 (setq required-features
573 (union required-features
578 ((find-charset (setq ret (intern (format "=%s" source))))
579 (setq required-features
580 (cons ret required-features)))
581 (t (setq required-features
582 (cons source required-features)))))
583 (cond ((string-match "@JP" (symbol-name name))
584 (setq required-features
585 (union required-features
593 ((string-match "@CN" (symbol-name name))
594 (setq required-features
595 (union required-features
602 (insert (format "%S" cell))
603 (char-db-insert-char-spec cell readable
606 (setq separator lbs))
610 (if (consp (car cell))
611 (char-db-insert-char-spec cell readable)
612 (char-db-insert-char-reference cell readable))
613 (setq separator lbs))
617 (insert (prin1-to-string cell))
618 (setq separator " ")))
619 (setq value (cdr value)))
621 (insert line-breaking)))
623 (defun insert-char-attributes (char &optional readable attributes column
626 (setq column (current-column)))
627 (let (name value ; has-long-ccs-name
631 (concat "\n" (make-string (1+ column) ?\ )))
632 lbs cell separator ret
634 dest-ccss ; sources required-features
639 (if (consp attributes)
641 (dolist (name attributes)
642 (unless (memq name char-db-ignored-attributes)
643 (if (find-charset name)
647 (dolist (name (char-attribute-list))
648 (unless (memq name char-db-ignored-attributes)
649 (if (find-charset name)
653 #'char-attribute-name<)))
655 (when (memq '<-subsumptive attributes)
656 (when (or readable (not for-sub-node))
657 (when (setq value (get-char-attribute char '<-subsumptive))
658 (char-db-insert-relation-feature char '<-subsumptive value
661 (setq attributes (delq '<-subsumptive attributes)))
662 (when (and (memq '<-denotational attributes)
663 (setq value (get-char-attribute char '<-denotational)))
664 (char-db-insert-relation-feature char '<-denotational value
667 (setq attributes (delq '<-denotational attributes)))
668 (when (and (memq 'name attributes)
669 (setq value (get-char-attribute char 'name)))
671 (if (> (+ (current-column) (length value)) 48)
674 value line-breaking))
675 (setq attributes (delq 'name attributes))
677 (when (and (memq 'name* attributes)
678 (setq value (get-char-attribute char 'name*)))
680 (if (> (+ (current-column) (length value)) 48)
683 value line-breaking))
684 (setq attributes (delq 'name* attributes))
686 (when (and (memq 'script attributes)
687 (setq value (get-char-attribute char 'script)))
688 (insert (format "(script\t\t%s)%s"
689 (mapconcat (function prin1-to-string)
692 (setq attributes (delq 'script attributes))
694 (dolist (name '(=>ucs =>ucs*))
695 (when (and (memq name attributes)
696 (setq value (get-char-attribute char name)))
697 (insert (format "(%-18s . #x%04X)\t; %c%s"
698 name value (decode-char '=ucs value)
700 (setq attributes (delq name attributes))))
701 (dolist (name '(=>ucs@gb =>ucs@big5))
702 (when (and (memq name attributes)
703 (setq value (get-char-attribute char name)))
704 (insert (format "(%-18s . #x%04X)\t; %c%s"
709 (symbol-name name) 2)))
712 (setq attributes (delq name attributes))
714 ;; (dolist (name '(=>daikanwa))
715 ;; (when (and (memq name attributes)
716 ;; (setq value (get-char-attribute char name)))
718 ;; (if (integerp value)
719 ;; (format "(%-18s . %05d)\t; %c%s"
720 ;; name value (decode-char '=daikanwa value)
722 ;; (format "(%-18s %s)\t; %c%s"
724 ;; (mapconcat (function prin1-to-string)
726 ;; (char-representative-of-daikanwa char)
728 ;; (setq attributes (delq name attributes))))
729 (when (and (memq 'general-category attributes)
730 (setq value (get-char-attribute char 'general-category)))
732 "(general-category\t%s) ; %s%s"
733 (mapconcat (lambda (cell)
736 (cond ((rassoc value unidata-normative-category-alist)
737 "Normative Category")
738 ((rassoc value unidata-informative-category-alist)
739 "Informative Category")
743 (setq attributes (delq 'general-category attributes))
745 (when (and (memq 'bidi-category attributes)
746 (setq value (get-char-attribute char 'bidi-category)))
747 (insert (format "(bidi-category\t. %S)%s"
750 (setq attributes (delq 'bidi-category attributes))
752 (unless (or (not (memq 'mirrored attributes))
753 (eq (setq value (get-char-attribute char 'mirrored 'empty))
755 (insert (format "(mirrored\t\t. %S)%s"
758 (setq attributes (delq 'mirrored attributes))
761 ((and (memq 'decimal-digit-value attributes)
762 (setq value (get-char-attribute char 'decimal-digit-value)))
763 (insert (format "(decimal-digit-value . %S)%s"
766 (setq attributes (delq 'decimal-digit-value attributes))
767 (when (and (memq 'digit-value attributes)
768 (setq value (get-char-attribute char 'digit-value)))
769 (insert (format "(digit-value\t . %S)%s"
772 (setq attributes (delq 'digit-value attributes))
774 (when (and (memq 'numeric-value attributes)
775 (setq value (get-char-attribute char 'numeric-value)))
776 (insert (format "(numeric-value\t . %S)%s"
779 (setq attributes (delq 'numeric-value attributes))
783 (when (and (memq 'digit-value attributes)
784 (setq value (get-char-attribute char 'digit-value)))
785 (insert (format "(digit-value\t. %S)%s"
788 (setq attributes (delq 'digit-value attributes))
790 (when (and (memq 'numeric-value attributes)
791 (setq value (get-char-attribute char 'numeric-value)))
792 (insert (format "(numeric-value\t. %S)%s"
795 (setq attributes (delq 'numeric-value attributes))
797 (when (and (memq 'iso-10646-comment attributes)
798 (setq value (get-char-attribute char 'iso-10646-comment)))
799 (insert (format "(iso-10646-comment\t. %S)%s"
802 (setq attributes (delq 'iso-10646-comment attributes))
804 (when (and (memq 'morohashi-daikanwa attributes)
805 (setq value (get-char-attribute char 'morohashi-daikanwa)))
806 (insert (format "(morohashi-daikanwa\t%s)%s"
807 (mapconcat (function prin1-to-string) value " ")
809 (setq attributes (delq 'morohashi-daikanwa attributes))
813 (when (and (memq 'ideographic-radical attributes)
814 (setq value (get-char-attribute char 'ideographic-radical)))
816 (insert (format "(ideographic-radical . %S)\t; %c%s"
818 (ideographic-radical radical)
820 (setq attributes (delq 'ideographic-radical attributes))
822 (when (and (memq 'shuowen-radical attributes)
823 (setq value (get-char-attribute char 'shuowen-radical)))
824 (insert (format "(shuowen-radical\t. %S)\t; %c%s"
826 (shuowen-radical value)
828 (setq attributes (delq 'shuowen-radical attributes))
833 char-db-feature-domains
835 (dolist (feature (char-attribute-list))
836 (setq feature (symbol-name feature))
838 "\\(radical\\|strokes\\)@\\([^@*]+\\)\\(\\*\\|$\\)"
840 (setq domain (intern (match-string 2 feature)))
841 (unless (memq domain dest)
842 (setq dest (cons domain dest)))))
843 (sort dest #'string<))))
844 (setq key (intern (format "%s@%s" 'ideographic-radical domain)))
845 (when (and (memq key attributes)
846 (setq value (get-char-attribute char key)))
848 (insert (format "(%s . %S)\t; %c%s"
851 (ideographic-radical radical)
853 (setq attributes (delq key attributes))
855 (setq key (intern (format "%s@%s" 'ideographic-strokes domain)))
856 (when (and (memq key attributes)
857 (setq value (get-char-attribute char key)))
859 (insert (format "(%s . %S)%s"
863 (setq attributes (delq key attributes))
865 (setq key (intern (format "%s@%s" 'total-strokes domain)))
866 (when (and (memq key attributes)
867 (setq value (get-char-attribute char key)))
868 (insert (format "(%s . %S)%s"
872 (setq attributes (delq key attributes))
874 (dolist (feature '(ideographic-radical
877 (setq key (intern (format "%s@%s*sources" feature domain)))
878 (when (and (memq key attributes)
879 (setq value (get-char-attribute char key)))
880 (insert (format "(%s%s" key line-breaking))
882 (insert (format " %s" cell)))
884 (insert line-breaking)
885 (setq attributes (delq key attributes))
888 (when (and (memq 'ideographic-strokes attributes)
889 (setq value (get-char-attribute char 'ideographic-strokes)))
891 (insert (format "(ideographic-strokes . %S)%s"
894 (setq attributes (delq 'ideographic-strokes attributes))
896 (when (and (memq 'kangxi-radical attributes)
897 (setq value (get-char-attribute char 'kangxi-radical)))
898 (unless (eq value radical)
899 (insert (format "(kangxi-radical\t . %S)\t; %c%s"
901 (ideographic-radical value)
904 (setq radical value)))
905 (setq attributes (delq 'kangxi-radical attributes))
907 (when (and (memq 'kangxi-strokes attributes)
908 (setq value (get-char-attribute char 'kangxi-strokes)))
909 (unless (eq value strokes)
910 (insert (format "(kangxi-strokes\t . %S)%s"
914 (setq strokes value)))
915 (setq attributes (delq 'kangxi-strokes attributes))
917 (when (and (memq 'japanese-radical attributes)
918 (setq value (get-char-attribute char 'japanese-radical)))
919 (unless (eq value radical)
920 (insert (format "(japanese-radical\t . %S)\t; %c%s"
922 (ideographic-radical value)
925 (setq radical value)))
926 (setq attributes (delq 'japanese-radical attributes))
928 (when (and (memq 'japanese-strokes attributes)
929 (setq value (get-char-attribute char 'japanese-strokes)))
930 (unless (eq value strokes)
931 (insert (format "(japanese-strokes\t . %S)%s"
935 (setq strokes value)))
936 (setq attributes (delq 'japanese-strokes attributes))
938 (when (and (memq 'cns-radical attributes)
939 (setq value (get-char-attribute char 'cns-radical)))
940 (insert (format "(cns-radical\t . %S)\t; %c%s"
942 (ideographic-radical value)
944 (setq attributes (delq 'cns-radical attributes))
946 (when (and (memq 'cns-strokes attributes)
947 (setq value (get-char-attribute char 'cns-strokes)))
948 (unless (eq value strokes)
949 (insert (format "(cns-strokes\t . %S)%s"
953 (setq strokes value)))
954 (setq attributes (delq 'cns-strokes attributes))
956 (when (and (memq 'shinjigen-1-radical attributes)
957 (setq value (get-char-attribute char 'shinjigen-1-radical)))
958 (unless (eq value radical)
959 (insert (format "(shinjigen-1-radical . %S)\t; %c%s"
961 (ideographic-radical value)
964 (setq radical value)))
965 (setq attributes (delq 'shinjigen-1-radical attributes))
967 (when (and (memq 'ideographic- attributes)
968 (setq value (get-char-attribute char 'ideographic-)))
969 (insert "(ideographic- ")
970 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
973 (setq cell (car value))
975 (setq cell (decode-char '=ucs cell)))
976 (cond ((characterp cell)
980 (insert (format "%S" cell))
981 (char-db-insert-char-spec cell readable))
982 (setq separator lbs))
986 (if (consp (car cell))
987 (char-db-insert-char-spec cell readable)
988 (char-db-insert-char-reference cell readable))
989 (setq separator lbs))
993 (insert (prin1-to-string cell))
994 (setq separator " ")))
995 (setq value (cdr value)))
997 (insert line-breaking)
998 (setq attributes (delq 'ideographic- attributes)))
999 (when (and (memq 'total-strokes attributes)
1000 (setq value (get-char-attribute char 'total-strokes)))
1001 (insert (format "(total-strokes . %S)%s"
1004 (setq attributes (delq 'total-strokes attributes))
1006 (when (and (memq '->ideograph attributes)
1007 (setq value (get-char-attribute char '->ideograph)))
1008 (insert (format "(->ideograph\t%s)%s"
1009 (mapconcat (lambda (code)
1010 (cond ((symbolp code)
1013 (format "#x%04X" code))
1016 line-breaking code))))
1019 (setq attributes (delq '->ideograph attributes))
1021 ;; (when (and (memq '->decomposition attributes)
1022 ;; (setq value (get-char-attribute char '->decomposition)))
1023 ;; (insert (format "(->decomposition\t%s)%s"
1024 ;; (mapconcat (lambda (code)
1025 ;; (cond ((symbolp code)
1026 ;; (symbol-name code))
1027 ;; ((characterp code)
1029 ;; (format "%S" code)
1034 ;; (format "#x%04X" code))
1036 ;; (format "%s%S" line-breaking code))))
1039 ;; (setq attributes (delq '->decomposition attributes))
1041 (if (equal (get-char-attribute char '->titlecase)
1042 (get-char-attribute char '->uppercase))
1043 (setq attributes (delq '->titlecase attributes)))
1044 (when (and (memq '->mojikyo attributes)
1045 (setq value (get-char-attribute char '->mojikyo)))
1046 (insert (format "(->mojikyo\t\t. %06d)\t; %c%s"
1047 value (decode-char 'mojikyo value)
1049 (setq attributes (delq '->mojikyo attributes))
1051 (when (and (memq 'hanyu-dazidian-vol attributes)
1052 (setq value (get-char-attribute char 'hanyu-dazidian-vol)))
1053 (insert (format "(hanyu-dazidian-vol . %d)%s"
1054 value line-breaking))
1055 (setq attributes (delq 'hanyu-dazidian-vol attributes))
1057 (when (and (memq 'hanyu-dazidian-page attributes)
1058 (setq value (get-char-attribute char 'hanyu-dazidian-page)))
1059 (insert (format "(hanyu-dazidian-page . %d)%s"
1060 value line-breaking))
1061 (setq attributes (delq 'hanyu-dazidian-page attributes))
1063 (when (and (memq 'hanyu-dazidian-char attributes)
1064 (setq value (get-char-attribute char 'hanyu-dazidian-char)))
1065 (insert (format "(hanyu-dazidian-char . %d)%s"
1066 value line-breaking))
1067 (setq attributes (delq 'hanyu-dazidian-char attributes))
1070 (dolist (ignored '(composition
1071 ->denotational <-subsumptive ->ucs-unified
1072 ->ideographic-component-forms))
1073 (setq attributes (delq ignored attributes))))
1075 (setq name (car attributes))
1076 (unless (eq (setq value (get-char-attribute char name 'value-is-empty))
1078 (cond ((setq ret (find-charset name))
1079 (setq name (charset-name ret))
1080 (when (not (memq name dest-ccss))
1081 (setq dest-ccss (cons name dest-ccss))
1082 (char-db-insert-ccs-feature name value line-breaking))
1084 ((string-match "^=>ucs@" (symbol-name name))
1085 (insert (format "(%-18s . #x%04X)\t; %c%s"
1086 name value (decode-char '=ucs value)
1089 ((eq name 'jisx0208-1978/4X)
1090 (insert (format "(%-18s . #x%04X)%s"
1096 (not (eq name '->subsumptive))
1097 (not (eq name '->uppercase))
1098 (not (eq name '->lowercase))
1099 (not (eq name '->titlecase))
1100 (not (eq name '->canonical))
1101 (not (eq name '->Bopomofo))
1102 (not (eq name '->mistakable))
1103 (not (eq name '->ideographic-variants))
1104 (null (get-char-attribute
1105 char (intern (format "%s*sources" name))))
1106 (not (string-match "\\*sources$" (symbol-name name)))
1107 (null (get-char-attribute
1108 char (intern (format "%s*note" name))))
1109 (not (string-match "\\*note$" (symbol-name name)))
1110 (or (eq name '<-identical)
1111 (eq name '<-uppercase)
1112 (eq name '<-lowercase)
1113 (eq name '<-titlecase)
1114 (eq name '<-canonical)
1115 (eq name '<-ideographic-variants)
1116 ;; (eq name '<-synonyms)
1117 (string-match "^<-synonyms" (symbol-name name))
1118 (eq name '<-mistakable)
1119 (when (string-match "^->" (symbol-name name))
1121 ((string-match "^->fullwidth" (symbol-name name))
1122 (not (and (consp value)
1123 (characterp (car value))
1125 (car value) '=ucs 'defined-only)))
1130 ((or (eq name 'ideographic-structure)
1131 (eq name 'ideographic-combination)
1132 (eq name 'ideographic-)
1133 (eq name '=decomposition)
1134 (char-feature-base-name= '=decomposition name)
1135 (char-feature-base-name= '=>decomposition name)
1136 ;; (string-match "^=>*decomposition\\(@[^*]+\\)?$"
1137 ;; (symbol-name name))
1138 (string-match "^\\(->\\|<-\\)[^*]*$" (symbol-name name))
1139 (string-match "^\\(->\\|<-\\)[^*]*\\*sources$"
1142 (char-db-insert-relation-feature char name value
1145 ((memq name '(ideograph=
1146 original-ideograph-of
1147 ancient-ideograph-of
1150 ;; simplified-ideograph-of
1151 ideographic-variants
1152 ;; ideographic-different-form-of
1154 (insert (format "(%-18s%s " name line-breaking))
1155 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1157 (while (consp value)
1158 (setq cell (car value))
1159 (if (and (consp cell)
1164 (char-db-insert-alist cell readable)
1165 (setq separator lbs))
1168 (insert (prin1-to-string cell))
1169 (setq separator " "))
1170 (setq value (cdr value)))
1172 (insert line-breaking))
1174 (insert (format "(%-18s " name))
1175 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1177 (while (consp value)
1178 (setq cell (car value))
1179 (if (and (consp cell)
1181 (setq ret (condition-case nil
1189 (setq key (car (car rest)))
1190 (if (find-charset key)
1191 (setq cal (cons key cal))
1192 (setq al (cons key al)))
1193 (setq rest (cdr rest)))
1196 (insert-char-attributes ret
1200 (setq separator lbs))
1201 (setq ret (prin1-to-string cell))
1203 (if (< (+ (current-column)
1210 (setq separator " "))
1211 (setq value (cdr value)))
1213 (insert line-breaking))
1215 (insert (format "(%-18s" name))
1216 (setq ret (prin1-to-string value))
1217 (unless (< (+ (current-column)
1221 (insert line-breaking))
1222 (insert " . " ret ")" line-breaking)
1223 ;; (insert (format "(%-18s . %S)%s"
1228 (setq attributes (cdr attributes)))
1231 (defun insert-char-data (char &optional readable
1234 (narrow-to-region (point)(point))
1235 (insert "(define-char
1237 (insert-char-attributes char readable attributes)
1239 (goto-char (point-min))
1240 (while (re-search-forward "[ \t]+$" nil t)
1243 (goto-char (point-min))
1244 (while (re-search-forward "[ \t][ \t][ \t]*" nil t)
1245 (let ((column (current-column))
1246 (indent-tabs-mode t))
1247 (delete-region (match-beginning 0) (point))
1248 (indent-to column)))
1249 (goto-char (point-max))
1250 ;; (tabify (point-min)(point-max))
1253 (defun insert-char-data-with-variant (char &optional printable
1255 script excluded-script)
1256 (insert-char-data char printable)
1257 (let ((variants (char-variants char))
1260 (setq variants (sort variants #'<))
1261 (setq rest variants)
1262 (setq variants (cons char variants))
1264 (setq variant (car rest))
1265 (unless (get-char-attribute variant '<-subsumptive)
1266 (if (and (or (null script)
1267 (null (setq vs (get-char-attribute variant 'script)))
1269 (or (null excluded-script)
1270 (null (setq vs (get-char-attribute variant 'script)))
1271 (not (memq excluded-script vs))))
1272 (unless (and no-ucs-unified (get-char-attribute variant '=ucs))
1273 (insert-char-data variant printable)
1274 (if (setq ret (char-variants variant))
1276 (or (memq (car ret) variants)
1277 ;; (get-char-attribute (car ret) '<-subsumptive)
1278 (setq rest (nconc rest (list (car ret)))))
1279 (setq ret (cdr ret)))))))
1280 (setq rest (cdr rest)))))
1282 (defun insert-char-range-data (min max &optional script excluded-script)
1285 (while (<= code max)
1286 (setq char (decode-char '=ucs code))
1287 (if (encode-char char '=ucs 'defined-only)
1288 (insert-char-data-with-variant char nil 'no-ucs-unified
1289 script excluded-script))
1290 (setq code (1+ code)))))
1292 (defun write-char-range-data-to-file (min max file
1293 &optional script excluded-script)
1294 (let ((coding-system-for-write char-db-file-coding-system))
1296 (insert (format ";; -*- coding: %s -*-\n"
1297 char-db-file-coding-system))
1298 (insert-char-range-data min max script excluded-script)
1299 (write-region (point-min)(point-max) file))))
1301 (defvar what-character-original-window-configuration)
1304 (defun what-char-definition (char)
1305 (interactive (list (char-after)))
1306 (let ((buf (get-buffer-create "*Character Description*"))
1307 (the-buf (current-buffer))
1308 (win-conf (current-window-configuration)))
1310 (make-local-variable 'what-character-original-window-configuration)
1311 (setq what-character-original-window-configuration win-conf)
1312 (setq buffer-read-only nil)
1316 (insert-char-data-with-variant char 'printable)
1317 (unless (char-attribute-alist char)
1318 (insert (format ";; = %c\n"
1319 (let* ((rest (split-char char))
1323 (setq code (logior (lsh code 8)
1325 (decode-char ccs code)))))
1326 ;; (char-db-update-comment)
1327 (set-buffer-modified-p nil)
1328 (view-mode the-buf (lambda (buf)
1329 (set-window-configuration
1330 what-character-original-window-configuration)
1332 (goto-char (point-min)))
1334 (set-window-configuration
1335 what-character-original-window-configuration)
1336 (signal (car err) (cdr err)))))))
1342 (provide 'char-db-util)
1344 ;;; char-db-util.el ends here