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
234 ;;; @ char-db formatters
237 (defun char-db-make-char-spec (char)
239 (cond ((characterp char)
240 (cond ((and (setq ret (encode-char char '=ucs 'defined-only))
241 (not (and (<= #xE000 ret)(<= ret #xF8FF))))
242 (setq char-spec (list (cons '=ucs ret)))
243 (cond ((setq ret (get-char-attribute char 'name))
244 (setq char-spec (cons (cons 'name ret) char-spec))
246 ((setq ret (get-char-attribute char 'name*))
247 (setq char-spec (cons (cons 'name* ret) char-spec))
252 (let ((rest char-db-coded-charset-priority-list)
255 (setq ccs (charset-name
256 (find-charset (car rest))))
258 (encode-char char ccs
260 (throw 'tag (cons ccs ret)))
261 (setq rest (cdr rest))))))
262 (setq char-spec (list ret))
263 (dolist (ccs (delq (car ret) (charset-list)))
264 (if (and (or (charset-iso-final-char ccs)
271 (string-match "=ucs@" (symbol-name ccs)))
272 (setq ccs (charset-name ccs))
273 (null (assq ccs char-spec))
274 (setq ret (encode-char char ccs 'defined-only)))
275 (setq char-spec (cons (cons ccs ret) char-spec))))
277 (setq char-spec (split-char char)))
278 (cond ((setq ret (get-char-attribute char 'name))
279 (setq char-spec (cons (cons 'name ret) char-spec))
281 ((setq ret (get-char-attribute char 'name*))
282 (setq char-spec (cons (cons 'name* ret) char-spec))
285 ((setq ret (get-char-attribute
286 char 'ideographic-combination))
288 (cons (cons 'ideographic-combination ret)
295 (defun char-db-insert-char-spec (char &optional readable column
298 (setq column (current-column)))
299 (let (char-spec temp-char)
300 (setq char-spec (char-db-make-char-spec char))
301 (unless (or (characterp char) ; char
303 (setq char (find-char char-spec))
305 ;; define temporary character
306 ;; Current implementation is dirty.
307 (setq temp-char (define-char (cons '(ideograph-daikanwa . 0)
309 (remove-char-attribute temp-char 'ideograph-daikanwa)
310 (setq char temp-char))
311 (insert-char-attributes char
313 (union (mapcar #'car char-spec)
317 ;; undefine temporary character
318 ;; Current implementation is dirty.
319 (setq char-spec (char-attribute-alist temp-char))
321 (remove-char-attribute temp-char (car (car char-spec)))
322 (setq char-spec (cdr char-spec))))))
324 (defun char-db-insert-alist (alist &optional readable column)
326 (setq column (current-column)))
328 (concat "\n" (make-string (1+ column) ?\ )))
332 lbs cell rest separator)
335 (setq name (car (car alist))
336 value (cdr (car alist)))
337 (cond ((eq name 'char)
339 (if (setq ret (condition-case nil
347 (setq key (car (car value)))
348 ;; (if (find-charset key)
349 ;; (setq cal (cons key cal))
350 (setq al (cons key al))
352 (setq value (cdr value)))
353 (insert-char-attributes ret
357 (insert (prin1-to-string value)))
359 (insert line-breaking))
361 (insert (format "(%-18s " name))
362 (setq lbs (concat "\n" (make-string (current-column) ?\ )))
364 (setq cell (car value))
365 (if (and (consp cell)
367 (setq ret (condition-case nil
377 (setq key (car (car rest)))
378 ;; (if (find-charset key)
379 ;; (setq cal (cons key cal))
380 (setq al (cons key al))
382 (setq rest (cdr rest)))
385 (insert-char-attributes ret
389 (setq separator lbs))
392 (insert (prin1-to-string cell))
393 (setq separator " "))
394 (setq value (cdr value)))
396 (insert line-breaking))
398 (insert (format "(%-18s . %S)%s"
401 (setq alist (cdr alist))))
404 (defun char-db-insert-char-reference (plist &optional readable column)
406 (setq column (current-column)))
408 (concat "\n" (make-string (1+ column) ?\ )))
413 (setq name (pop plist))
414 (setq value (pop plist))
415 (cond ((eq name :char)
418 (cond ((numberp value)
419 (setq value (decode-char '=ucs value)))
421 ;; (setq value (or (find-char value)
424 (char-db-insert-char-spec value readable)
425 (insert line-breaking)
428 (insert (format "%s%s\t%d ; %c%s"
431 (ideographic-radical value)
435 (insert (format "%s%s\t%S" separator name value))
436 (setq separator line-breaking)))
440 (defun char-db-decode-isolated-char (ccs code-point)
443 (cond ((eq ccs 'arabic-iso8859-6)
444 (decode-char ccs code-point))
445 ((and (memq ccs '(=gt-pj-1
456 (setq ret (decode-char ccs code-point))
457 (setq ret (encode-char ret '=gt 'defined-only)))
458 (decode-builtin-char '=gt ret))
460 (decode-builtin-char ccs code-point))))
461 (cond ((and (<= 0 (char-int ret))
462 (<= (char-int ret) #x1F))
463 (decode-char '=ucs (+ #x2400 (char-int ret))))
464 ((= (char-int ret) #x7F)
468 (defvar char-db-convert-obsolete-format t)
470 (defun char-db-insert-ccs-feature (name value line-breaking)
476 ((memq name '(=shinjigen
478 =shinjigen@rev =shinjigen/+p@rev
480 "(%-18s . %04d)\t; %c")
481 ((eq name '=shinjigen@1ed/24pr)
482 "(%-18s . %04d)\t; %c")
483 ((or (memq name '(=daikanwa =>>daikanwa =>daikanwa
484 =daikanwa@rev1 =daikanwa@rev2
485 =daikanwa/+p =daikanwa/+2p
486 =gt =>>>gt =>>gt =>gt
490 =zinbun-oracle =>zinbun-oracle))
491 (string-match "^=adobe-" (symbol-name name)))
492 "(%-18s . %05d)\t; %c")
493 ((memq name '(=hanyo-denshi/ks =>>hanyo-denshi/ks mojikyo))
494 "(%-18s . %06d)\t; %c")
495 ((>= (charset-dimension name) 2)
496 "(%-18s . #x%04X)\t; %c")
498 "(%-18s . #x%02X)\t; %c"))
500 (if (= (charset-iso-graphic-plane name) 1)
502 (cond ((= (charset-dimension name) 1)
504 ((= (charset-dimension name) 2)
506 ((= (charset-dimension name) 3)
510 (char-db-decode-isolated-char name value)))
511 (if (and (= (charset-chars name) 94)
512 (= (charset-dimension name) 2))
513 (insert (format " [%02d-%02d]"
514 (- (lsh value -8) 32)
515 (- (logand value 255) 32))))
518 (insert (format "(%-18s . %s)" name value))
520 (insert line-breaking))
522 (defun char-db-insert-relation-feature (char name value line-breaking
524 (insert (format "(%-18s%s " name line-breaking))
525 (let ((lbs (concat "\n" (make-string (current-column) ?\ )))
526 separator cell sources required-features
529 (setq cell (car value))
531 (setq cell (decode-char '=ucs cell)))
533 ((eq name '->subsumptive)
534 (when (or (not (some (lambda (atr)
535 (get-char-attribute cell atr))
536 char-db-ignored-attributes))
538 (encode-char cell ccs 'defined-only))
542 (let ((char-db-ignored-attributes
544 char-db-ignored-attributes)))
545 (insert-char-attributes cell readable nil nil 'for-sub-node))
546 (setq separator lbs))
551 char (intern (format "%s*sources" name))))
552 (setq required-features nil)
553 (dolist (source sources)
557 shinjigen shinjigen@1ed shinjigen@rev))
558 (setq required-features
559 (union required-features
570 (setq required-features
571 (union required-features
576 ((find-charset (setq ret (intern (format "=%s" source))))
577 (setq required-features
578 (cons ret required-features)))
579 (t (setq required-features
580 (cons source required-features)))))
581 (cond ((string-match "@JP" (symbol-name name))
582 (setq required-features
583 (union required-features
591 ((string-match "@CN" (symbol-name name))
592 (setq required-features
593 (union required-features
600 (insert (format "%S" cell))
601 (char-db-insert-char-spec cell readable
604 (setq separator lbs))
608 (if (consp (car cell))
609 (char-db-insert-char-spec cell readable)
610 (char-db-insert-char-reference cell readable))
611 (setq separator lbs))
615 (insert (prin1-to-string cell))
616 (setq separator " ")))
617 (setq value (cdr value)))
619 (insert line-breaking)))
621 (defun insert-char-attributes (char &optional readable attributes column
624 (setq column (current-column)))
625 (let (name value ; has-long-ccs-name
629 (concat "\n" (make-string (1+ column) ?\ )))
630 lbs cell separator ret
632 dest-ccss ; sources required-features
637 (if (consp attributes)
639 (dolist (name attributes)
640 (unless (memq name char-db-ignored-attributes)
641 (if (find-charset name)
645 (dolist (name (char-attribute-list))
646 (unless (memq name char-db-ignored-attributes)
647 (if (find-charset name)
651 #'char-attribute-name<)))
653 (when (memq '<-subsumptive attributes)
654 (when (or readable (not for-sub-node))
655 (when (setq value (get-char-attribute char '<-subsumptive))
656 (char-db-insert-relation-feature char '<-subsumptive value
659 (setq attributes (delq '<-subsumptive attributes)))
660 (when (and (memq '<-denotational attributes)
661 (setq value (get-char-attribute char '<-denotational)))
662 (char-db-insert-relation-feature char '<-denotational value
665 (setq attributes (delq '<-denotational attributes)))
666 (when (and (memq 'name attributes)
667 (setq value (get-char-attribute char 'name)))
669 (if (> (+ (current-column) (length value)) 48)
672 value line-breaking))
673 (setq attributes (delq 'name attributes))
675 (when (and (memq 'name* attributes)
676 (setq value (get-char-attribute char 'name*)))
678 (if (> (+ (current-column) (length value)) 48)
681 value line-breaking))
682 (setq attributes (delq 'name* attributes))
684 (when (and (memq 'script attributes)
685 (setq value (get-char-attribute char 'script)))
686 (insert (format "(script\t\t%s)%s"
687 (mapconcat (function prin1-to-string)
690 (setq attributes (delq 'script attributes))
692 (dolist (name '(=>ucs =>ucs*))
693 (when (and (memq name attributes)
694 (setq value (get-char-attribute char name)))
695 (insert (format "(%-18s . #x%04X)\t; %c%s"
696 name value (decode-char '=ucs value)
698 (setq attributes (delq name attributes))))
699 (dolist (name '(=>ucs@gb =>ucs@big5))
700 (when (and (memq name attributes)
701 (setq value (get-char-attribute char name)))
702 (insert (format "(%-18s . #x%04X)\t; %c%s"
707 (symbol-name name) 2)))
710 (setq attributes (delq name attributes))
712 ;; (dolist (name '(=>daikanwa))
713 ;; (when (and (memq name attributes)
714 ;; (setq value (get-char-attribute char name)))
716 ;; (if (integerp value)
717 ;; (format "(%-18s . %05d)\t; %c%s"
718 ;; name value (decode-char '=daikanwa value)
720 ;; (format "(%-18s %s)\t; %c%s"
722 ;; (mapconcat (function prin1-to-string)
724 ;; (char-representative-of-daikanwa char)
726 ;; (setq attributes (delq name attributes))))
727 (when (and (memq 'general-category attributes)
728 (setq value (get-char-attribute char 'general-category)))
730 "(general-category\t%s) ; %s%s"
731 (mapconcat (lambda (cell)
734 (cond ((rassoc value unidata-normative-category-alist)
735 "Normative Category")
736 ((rassoc value unidata-informative-category-alist)
737 "Informative Category")
741 (setq attributes (delq 'general-category attributes))
743 (when (and (memq 'bidi-category attributes)
744 (setq value (get-char-attribute char 'bidi-category)))
745 (insert (format "(bidi-category\t. %S)%s"
748 (setq attributes (delq 'bidi-category attributes))
750 (unless (or (not (memq 'mirrored attributes))
751 (eq (setq value (get-char-attribute char 'mirrored 'empty))
753 (insert (format "(mirrored\t\t. %S)%s"
756 (setq attributes (delq 'mirrored attributes))
759 ((and (memq 'decimal-digit-value attributes)
760 (setq value (get-char-attribute char 'decimal-digit-value)))
761 (insert (format "(decimal-digit-value . %S)%s"
764 (setq attributes (delq 'decimal-digit-value attributes))
765 (when (and (memq 'digit-value attributes)
766 (setq value (get-char-attribute char 'digit-value)))
767 (insert (format "(digit-value\t . %S)%s"
770 (setq attributes (delq 'digit-value attributes))
772 (when (and (memq 'numeric-value attributes)
773 (setq value (get-char-attribute char 'numeric-value)))
774 (insert (format "(numeric-value\t . %S)%s"
777 (setq attributes (delq 'numeric-value attributes))
781 (when (and (memq 'digit-value attributes)
782 (setq value (get-char-attribute char 'digit-value)))
783 (insert (format "(digit-value\t. %S)%s"
786 (setq attributes (delq 'digit-value attributes))
788 (when (and (memq 'numeric-value attributes)
789 (setq value (get-char-attribute char 'numeric-value)))
790 (insert (format "(numeric-value\t. %S)%s"
793 (setq attributes (delq 'numeric-value attributes))
795 (when (and (memq 'iso-10646-comment attributes)
796 (setq value (get-char-attribute char 'iso-10646-comment)))
797 (insert (format "(iso-10646-comment\t. %S)%s"
800 (setq attributes (delq 'iso-10646-comment attributes))
802 (when (and (memq 'morohashi-daikanwa attributes)
803 (setq value (get-char-attribute char 'morohashi-daikanwa)))
804 (insert (format "(morohashi-daikanwa\t%s)%s"
805 (mapconcat (function prin1-to-string) value " ")
807 (setq attributes (delq 'morohashi-daikanwa attributes))
811 (when (and (memq 'ideographic-radical attributes)
812 (setq value (get-char-attribute char 'ideographic-radical)))
814 (insert (format "(ideographic-radical . %S)\t; %c%s"
816 (ideographic-radical radical)
818 (setq attributes (delq 'ideographic-radical attributes))
820 (when (and (memq 'shuowen-radical attributes)
821 (setq value (get-char-attribute char 'shuowen-radical)))
822 (insert (format "(shuowen-radical\t. %S)\t; %c%s"
824 (shuowen-radical value)
826 (setq attributes (delq 'shuowen-radical attributes))
831 char-db-feature-domains
833 (dolist (feature (char-attribute-list))
834 (setq feature (symbol-name feature))
836 "\\(radical\\|strokes\\)@\\([^@*]+\\)\\(\\*\\|$\\)"
838 (setq domain (intern (match-string 2 feature)))
839 (unless (memq domain dest)
840 (setq dest (cons domain dest)))))
841 (sort dest #'string<))))
842 (setq key (intern (format "%s@%s" 'ideographic-radical domain)))
843 (when (and (memq key attributes)
844 (setq value (get-char-attribute char key)))
846 (insert (format "(%s . %S)\t; %c%s"
849 (ideographic-radical radical)
851 (setq attributes (delq key attributes))
853 (setq key (intern (format "%s@%s" 'ideographic-strokes domain)))
854 (when (and (memq key attributes)
855 (setq value (get-char-attribute char key)))
857 (insert (format "(%s . %S)%s"
861 (setq attributes (delq key attributes))
863 (setq key (intern (format "%s@%s" 'total-strokes domain)))
864 (when (and (memq key attributes)
865 (setq value (get-char-attribute char key)))
866 (insert (format "(%s . %S)%s"
870 (setq attributes (delq key attributes))
872 (dolist (feature '(ideographic-radical
875 (setq key (intern (format "%s@%s*sources" feature domain)))
876 (when (and (memq key attributes)
877 (setq value (get-char-attribute char key)))
878 (insert (format "(%s%s" key line-breaking))
880 (insert (format " %s" cell)))
882 (insert line-breaking)
883 (setq attributes (delq key attributes))
886 (when (and (memq 'ideographic-strokes attributes)
887 (setq value (get-char-attribute char 'ideographic-strokes)))
889 (insert (format "(ideographic-strokes . %S)%s"
892 (setq attributes (delq 'ideographic-strokes attributes))
894 (when (and (memq 'kangxi-radical attributes)
895 (setq value (get-char-attribute char 'kangxi-radical)))
896 (unless (eq value radical)
897 (insert (format "(kangxi-radical\t . %S)\t; %c%s"
899 (ideographic-radical value)
902 (setq radical value)))
903 (setq attributes (delq 'kangxi-radical attributes))
905 (when (and (memq 'kangxi-strokes attributes)
906 (setq value (get-char-attribute char 'kangxi-strokes)))
907 (unless (eq value strokes)
908 (insert (format "(kangxi-strokes\t . %S)%s"
912 (setq strokes value)))
913 (setq attributes (delq 'kangxi-strokes attributes))
915 (when (and (memq 'japanese-radical attributes)
916 (setq value (get-char-attribute char 'japanese-radical)))
917 (unless (eq value radical)
918 (insert (format "(japanese-radical\t . %S)\t; %c%s"
920 (ideographic-radical value)
923 (setq radical value)))
924 (setq attributes (delq 'japanese-radical attributes))
926 (when (and (memq 'japanese-strokes attributes)
927 (setq value (get-char-attribute char 'japanese-strokes)))
928 (unless (eq value strokes)
929 (insert (format "(japanese-strokes\t . %S)%s"
933 (setq strokes value)))
934 (setq attributes (delq 'japanese-strokes attributes))
936 (when (and (memq 'cns-radical attributes)
937 (setq value (get-char-attribute char 'cns-radical)))
938 (insert (format "(cns-radical\t . %S)\t; %c%s"
940 (ideographic-radical value)
942 (setq attributes (delq 'cns-radical attributes))
944 (when (and (memq 'cns-strokes attributes)
945 (setq value (get-char-attribute char 'cns-strokes)))
946 (unless (eq value strokes)
947 (insert (format "(cns-strokes\t . %S)%s"
951 (setq strokes value)))
952 (setq attributes (delq 'cns-strokes attributes))
954 (when (and (memq 'shinjigen-1-radical attributes)
955 (setq value (get-char-attribute char 'shinjigen-1-radical)))
956 (unless (eq value radical)
957 (insert (format "(shinjigen-1-radical . %S)\t; %c%s"
959 (ideographic-radical value)
962 (setq radical value)))
963 (setq attributes (delq 'shinjigen-1-radical attributes))
965 (when (and (memq 'ideographic- attributes)
966 (setq value (get-char-attribute char 'ideographic-)))
967 (insert "(ideographic- ")
968 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
971 (setq cell (car value))
973 (setq cell (decode-char '=ucs cell)))
974 (cond ((characterp cell)
978 (insert (format "%S" cell))
979 (char-db-insert-char-spec cell readable))
980 (setq separator lbs))
984 (if (consp (car cell))
985 (char-db-insert-char-spec cell readable)
986 (char-db-insert-char-reference cell readable))
987 (setq separator lbs))
991 (insert (prin1-to-string cell))
992 (setq separator " ")))
993 (setq value (cdr value)))
995 (insert line-breaking)
996 (setq attributes (delq 'ideographic- attributes)))
997 (when (and (memq 'total-strokes attributes)
998 (setq value (get-char-attribute char 'total-strokes)))
999 (insert (format "(total-strokes . %S)%s"
1002 (setq attributes (delq 'total-strokes attributes))
1004 (when (and (memq '->ideograph attributes)
1005 (setq value (get-char-attribute char '->ideograph)))
1006 (insert (format "(->ideograph\t%s)%s"
1007 (mapconcat (lambda (code)
1008 (cond ((symbolp code)
1011 (format "#x%04X" code))
1014 line-breaking code))))
1017 (setq attributes (delq '->ideograph attributes))
1019 ;; (when (and (memq '->decomposition attributes)
1020 ;; (setq value (get-char-attribute char '->decomposition)))
1021 ;; (insert (format "(->decomposition\t%s)%s"
1022 ;; (mapconcat (lambda (code)
1023 ;; (cond ((symbolp code)
1024 ;; (symbol-name code))
1025 ;; ((characterp code)
1027 ;; (format "%S" code)
1032 ;; (format "#x%04X" code))
1034 ;; (format "%s%S" line-breaking code))))
1037 ;; (setq attributes (delq '->decomposition attributes))
1039 (if (equal (get-char-attribute char '->titlecase)
1040 (get-char-attribute char '->uppercase))
1041 (setq attributes (delq '->titlecase attributes)))
1042 (when (and (memq '->mojikyo attributes)
1043 (setq value (get-char-attribute char '->mojikyo)))
1044 (insert (format "(->mojikyo\t\t. %06d)\t; %c%s"
1045 value (decode-char 'mojikyo value)
1047 (setq attributes (delq '->mojikyo attributes))
1049 (when (and (memq 'hanyu-dazidian-vol attributes)
1050 (setq value (get-char-attribute char 'hanyu-dazidian-vol)))
1051 (insert (format "(hanyu-dazidian-vol . %d)%s"
1052 value line-breaking))
1053 (setq attributes (delq 'hanyu-dazidian-vol attributes))
1055 (when (and (memq 'hanyu-dazidian-page attributes)
1056 (setq value (get-char-attribute char 'hanyu-dazidian-page)))
1057 (insert (format "(hanyu-dazidian-page . %d)%s"
1058 value line-breaking))
1059 (setq attributes (delq 'hanyu-dazidian-page attributes))
1061 (when (and (memq 'hanyu-dazidian-char attributes)
1062 (setq value (get-char-attribute char 'hanyu-dazidian-char)))
1063 (insert (format "(hanyu-dazidian-char . %d)%s"
1064 value line-breaking))
1065 (setq attributes (delq 'hanyu-dazidian-char attributes))
1068 (dolist (ignored '(composition
1069 ->denotational <-subsumptive ->ucs-unified
1070 ->ideographic-component-forms))
1071 (setq attributes (delq ignored attributes))))
1073 (setq name (car attributes))
1074 (unless (eq (setq value (get-char-attribute char name 'value-is-empty))
1076 (cond ((setq ret (find-charset name))
1077 (setq name (charset-name ret))
1078 (when (not (memq name dest-ccss))
1079 (setq dest-ccss (cons name dest-ccss))
1080 (char-db-insert-ccs-feature name value line-breaking))
1082 ((string-match "^=>ucs@" (symbol-name name))
1083 (insert (format "(%-18s . #x%04X)\t; %c%s"
1084 name value (decode-char '=ucs value)
1087 ((eq name 'jisx0208-1978/4X)
1088 (insert (format "(%-18s . #x%04X)%s"
1094 (not (eq name '->subsumptive))
1095 (not (eq name '->uppercase))
1096 (not (eq name '->lowercase))
1097 (not (eq name '->titlecase))
1098 (not (eq name '->canonical))
1099 (not (eq name '->Bopomofo))
1100 (not (eq name '->mistakable))
1101 (not (eq name '->ideographic-variants))
1102 (null (get-char-attribute
1103 char (intern (format "%s*sources" name))))
1104 (not (string-match "\\*sources$" (symbol-name name)))
1105 (null (get-char-attribute
1106 char (intern (format "%s*note" name))))
1107 (not (string-match "\\*note$" (symbol-name name)))
1108 (or (eq name '<-identical)
1109 (eq name '<-uppercase)
1110 (eq name '<-lowercase)
1111 (eq name '<-titlecase)
1112 (eq name '<-canonical)
1113 (eq name '<-ideographic-variants)
1114 ;; (eq name '<-synonyms)
1115 (string-match "^<-synonyms" (symbol-name name))
1116 (eq name '<-mistakable)
1117 (when (string-match "^->" (symbol-name name))
1119 ((string-match "^->fullwidth" (symbol-name name))
1120 (not (and (consp value)
1121 (characterp (car value))
1123 (car value) '=ucs 'defined-only)))
1128 ((or (eq name 'ideographic-structure)
1129 (eq name 'ideographic-combination)
1130 (eq name 'ideographic-)
1131 (eq name '=decomposition)
1132 (char-feature-base-name= '=decomposition name)
1133 (char-feature-base-name= '=>decomposition name)
1134 ;; (string-match "^=>*decomposition\\(@[^*]+\\)?$"
1135 ;; (symbol-name name))
1136 (string-match "^\\(->\\|<-\\)[^*]*$" (symbol-name name))
1137 (string-match "^\\(->\\|<-\\)[^*]*\\*sources$"
1140 (char-db-insert-relation-feature char name value
1143 ((memq name '(ideograph=
1144 original-ideograph-of
1145 ancient-ideograph-of
1148 ;; simplified-ideograph-of
1149 ideographic-variants
1150 ;; ideographic-different-form-of
1152 (insert (format "(%-18s%s " name line-breaking))
1153 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1155 (while (consp value)
1156 (setq cell (car value))
1157 (if (and (consp cell)
1162 (char-db-insert-alist cell readable)
1163 (setq separator lbs))
1166 (insert (prin1-to-string cell))
1167 (setq separator " "))
1168 (setq value (cdr value)))
1170 (insert line-breaking))
1172 (insert (format "(%-18s " name))
1173 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1175 (while (consp value)
1176 (setq cell (car value))
1177 (if (and (consp cell)
1179 (setq ret (condition-case nil
1187 (setq key (car (car rest)))
1188 (if (find-charset key)
1189 (setq cal (cons key cal))
1190 (setq al (cons key al)))
1191 (setq rest (cdr rest)))
1194 (insert-char-attributes ret
1198 (setq separator lbs))
1199 (setq ret (prin1-to-string cell))
1201 (if (< (+ (current-column)
1208 (setq separator " "))
1209 (setq value (cdr value)))
1211 (insert line-breaking))
1213 (insert (format "(%-18s" name))
1214 (setq ret (prin1-to-string value))
1215 (unless (< (+ (current-column)
1219 (insert line-breaking))
1220 (insert " . " ret ")" line-breaking)
1221 ;; (insert (format "(%-18s . %S)%s"
1226 (setq attributes (cdr attributes)))
1229 (defun insert-char-data (char &optional readable
1232 (narrow-to-region (point)(point))
1233 (insert "(define-char
1235 (insert-char-attributes char readable attributes)
1237 (goto-char (point-min))
1238 (while (re-search-forward "[ \t]+$" nil t)
1241 (goto-char (point-min))
1242 (while (re-search-forward "[ \t][ \t][ \t]*" nil t)
1243 (let ((column (current-column))
1244 (indent-tabs-mode t))
1245 (delete-region (match-beginning 0) (point))
1246 (indent-to column)))
1247 (goto-char (point-max))
1248 ;; (tabify (point-min)(point-max))
1251 (defun insert-char-data-with-variant (char &optional printable
1253 script excluded-script)
1254 (insert-char-data char printable)
1255 (let ((variants (char-variants char))
1258 (setq variants (sort variants #'<))
1259 (setq rest variants)
1260 (setq variants (cons char variants))
1262 (setq variant (car rest))
1263 (unless (get-char-attribute variant '<-subsumptive)
1264 (if (and (or (null script)
1265 (null (setq vs (get-char-attribute variant 'script)))
1267 (or (null excluded-script)
1268 (null (setq vs (get-char-attribute variant 'script)))
1269 (not (memq excluded-script vs))))
1270 (unless (and no-ucs-unified (get-char-attribute variant '=ucs))
1271 (insert-char-data variant printable)
1272 (if (setq ret (char-variants variant))
1274 (or (memq (car ret) variants)
1275 ;; (get-char-attribute (car ret) '<-subsumptive)
1276 (setq rest (nconc rest (list (car ret)))))
1277 (setq ret (cdr ret)))))))
1278 (setq rest (cdr rest)))))
1280 (defun insert-char-range-data (min max &optional script excluded-script)
1283 (while (<= code max)
1284 (setq char (decode-char '=ucs code))
1285 (if (encode-char char '=ucs 'defined-only)
1286 (insert-char-data-with-variant char nil 'no-ucs-unified
1287 script excluded-script))
1288 (setq code (1+ code)))))
1290 (defun write-char-range-data-to-file (min max file
1291 &optional script excluded-script)
1292 (let ((coding-system-for-write char-db-file-coding-system))
1294 (insert (format ";; -*- coding: %s -*-\n"
1295 char-db-file-coding-system))
1296 (insert-char-range-data min max script excluded-script)
1297 (write-region (point-min)(point-max) file))))
1299 (defvar what-character-original-window-configuration)
1302 (defun what-char-definition (char)
1303 (interactive (list (char-after)))
1304 (let ((buf (get-buffer-create "*Character Description*"))
1305 (the-buf (current-buffer))
1306 (win-conf (current-window-configuration)))
1308 (make-local-variable 'what-character-original-window-configuration)
1309 (setq what-character-original-window-configuration win-conf)
1310 (setq buffer-read-only nil)
1314 (insert-char-data-with-variant char 'printable)
1315 (unless (char-attribute-alist char)
1316 (insert (format ";; = %c\n"
1317 (let* ((rest (split-char char))
1321 (setq code (logior (lsh code 8)
1323 (decode-char ccs code)))))
1324 ;; (char-db-update-comment)
1325 (set-buffer-modified-p nil)
1326 (view-mode the-buf (lambda (buf)
1327 (set-window-configuration
1328 what-character-original-window-configuration)
1330 (goto-char (point-min)))
1332 (set-window-configuration
1333 what-character-original-window-configuration)
1334 (signal (car err) (cdr err)))))))
1340 (provide 'char-db-util)
1342 ;;; char-db-util.el ends here