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 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.
30 (defconst unidata-normative-category-alist
31 '(("Lu" letter uppercase)
32 ("Ll" letter lowercase)
33 ("Lt" letter titlecase)
34 ("Mn" mark non-spacing)
35 ("Mc" mark spacing-combining)
37 ("Nd" number decimal-digit)
40 ("Zs" separator space)
42 ("Zp" separator paragraph)
45 ("Cs" other surrogate)
46 ("Co" other private-use)
47 ("Cn" other not-assigned)))
49 (defconst unidata-informative-category-alist
50 '(("Lm" letter modifier)
52 ("Pc" punctuation connector)
53 ("Pd" punctuation dash)
54 ("Ps" punctuation open)
55 ("Pe" punctuation close)
56 ("Pi" punctuation initial-quote)
57 ("Pf" punctuation final-quote)
58 ("Po" punctuation other)
60 ("Sc" symbol currency)
61 ("Sk" symbol modifier)
65 (defconst ideographic-radicals
66 (let ((v (make-vector 215 nil))
69 (aset v i (decode-char '=ucs (+ #x2EFF i)))
74 (defun ideographic-radical (number)
75 "Return character corresponding with Kangxi-radical number."
76 (aref ideographic-radicals number))
78 (defconst shuowen-radicals
79 [?一 ?上 ?示 ?三 ?王 ?玉 ?玨 ?气 ?士 ?丨 ; 010
80 ?屮 ?艸 ?蓐 ?茻 ?小 ?八 ?釆 ?半 ?牛 ?犛 ; 020
81 ?告 ?口 ?凵 ?吅 ?哭 ?走 ?止 ?癶 ?步 ?此 ; 030
82 ?正 ?是 ?辵 ?彳 ?廴 ?㢟 ?行 ?齒 ?牙 ?足 ; 040
83 ?疋 ?品 ?龠 ?冊 ?㗊 ?舌 ?干 ?谷 ?只 ?㕯 ; 050
84 ?句 ?丩 ?古 ?十 ?卅 ?言 ?誩 ?音 ?䇂 ?丵 ; 060
85 ?菐 ?𠬞 ?廾 ?共 ?異 ?舁 ?𦥑 ?䢅 ?爨 ?革 ; 070
86 ?鬲 ?䰜 ?爪 ?𠃨 ?鬥 ?又 ?𠂇 ?㕜 ?支 ?𦘒 ; 080
87 ?聿 ?畫 ?隶 ?臤 ?臣 ?殳 ?殺 ?𠘧 ?寸 ?皮 ; 090
88 ?㼱 ?攴 ?敎 ?卜 ?用 ?爻 ?㸚 ?𥄎 ?目 ?䀠 ; 100
89 ?眉 ?盾 ?自 ?白 ?鼻 ?皕 ?習 ?羽 ?隹 ?奞 ; 110
90 ?萑 ?𦫳 ?苜 ?羊 ?羴 ?瞿 ?雔 ?雥 ?鳥 ?烏 ; 120
91 ?𠦒 ?冓 ?幺 ?𢆶 ?叀 ?玄 ?予 ?放 ?𠬪 ?𣦼 ; 130
92 ?歺 ?死 ?冎 ?骨 ?肉 ?筋 ?刀 ?刃 ?㓞 ?丰 ; 140
93 ?耒 ?𧢲 ?竹 ?箕 ?丌 ?左 ?工 ?㠭 ?巫 ?甘 ; 150
94 ?曰 ?乃 ?丂 ?可 ?兮 ?号 ?亏 ?旨 ?喜 ?壴 ; 160
95 ?鼓 ?豈 ?豆 ?豊 ?豐 ?䖒 ?虍 ?虎 ?虤 ?皿 ; 170
96 ?𠙴 ?去 ?血 ?丶 ?丹 ?青 ?井 ?皀 ?鬯 ?食 ; 180
97 ?亼 ?會 ?倉 ?入 ?缶 ?矢 ?高 ?冂 ?𩫏 ?京 ; 190
98 ?亯 ?𣆪 ?畗 ?㐭 ?嗇 ?來 ?麥 ?夊 ?舛 ?䑞 ; 200
99 ?韋 ?弟 ?夂 ?久 ?桀 ?木 ?東 ?林 ?才 ?叒 ; 210
100 ?之 ?帀 ?出 ?𣎵 ?生 ?乇 ?𠂹 ?𠌶 ?華 ?𥝌 ; 220
101 ?稽 ?巢 ?桼 ?束 ?㯻 ?囗 ?員 ?貝 ?邑 ?𨛜 ; 230
102 ?日 ?旦 ?倝 ?㫃 ?冥 ?晶 ?月 ?有 ?明 ?囧 ; 240
103 ?夕 ?多 ?毌 ?𢎘 ?𣐺 ?卣 ?齊 ?朿 ?片 ?鼎 ; 250
104 ?克 ?彔 ?禾 ?秝 ?黍 ?香 ?米 ?毇 ?臼 ?凶 ; 260
105 ?𣎳 ?林 ?麻 ?尗 ?耑 ?韭 ?瓜 ?瓠 ?宀 ?宮 ; 270
106 ?呂 ?穴 ?㝱 ?𤕫 ?冖 ?𠔼 ?冃 ?㒳 ?网 ?襾 ; 280
107 ?巾 ?巿 ?帛 ?白 ?㡀 ?黹 ?人 ?𠤎 ?匕 ?从 ; 290
110 (defun shuowen-radical (number)
111 (aref shuowen-radicals (1- number)))
113 (defvar char-db-file-coding-system 'utf-8-mcs-er)
115 (defvar char-db-feature-domains
116 '(ucs ucs/compat daikanwa cns gt jis jis/alt jis/a jis/b
117 jis-x0212 jis-x0213 cdp shinjigen misc unknown))
119 (defvar char-db-ignored-attributes '(ideographic-products))
121 (defun char-attribute-name< (ka kb)
123 ((eq '->denotational kb)
125 ((eq '->subsumptive kb)
126 (not (eq '->denotational ka)))
127 ((eq '->denotational ka)
129 ((eq '->subsumptive ka)
132 (string-match "^->" (symbol-name ka)))
133 (cond ((and (symbolp kb)
134 (string-match "^->" (symbol-name kb)))
135 (string< (symbol-name ka)
140 (string-match "^->" (symbol-name kb)))
143 (string-match "^<-" (symbol-name ka)))
145 (cond ((string-match "^<-" (symbol-name kb))
146 (string< (symbol-name ka)
149 ;; ((string-match "^->" (symbol-name kb))
154 (string-match "^<-" (symbol-name kb)))
156 ;; (not (string-match "^->" (symbol-name ka)))
159 (if (find-charset kb)
161 (if (setq a-ir (charset-property ka 'iso-ir))
162 (if (setq b-ir (charset-property kb 'iso-ir))
165 (< (charset-id ka)(charset-id kb))
175 (if (charset-property kb 'iso-ir)
177 (< (charset-id ka)(charset-id kb)))))
183 (string< (symbol-name ka)
189 (defvar char-db-coded-charset-priority-list
268 (defun char-db-make-char-spec (char)
270 (cond ((characterp char)
271 (cond ((and (setq ret (encode-char char '=ucs 'defined-only))
272 (not (and (<= #xE000 ret)(<= ret #xF8FF))))
273 (setq char-spec (list (cons '=ucs ret)))
274 (cond ((setq ret (get-char-attribute char 'name))
275 (setq char-spec (cons (cons 'name ret) char-spec))
277 ((setq ret (get-char-attribute char 'name*))
278 (setq char-spec (cons (cons 'name* ret) char-spec))
283 (let ((rest char-db-coded-charset-priority-list)
286 (setq ccs (charset-name
287 (find-charset (car rest))))
289 (encode-char char ccs
291 (throw 'tag (cons ccs ret)))
292 (setq rest (cdr rest))))))
293 (setq char-spec (list ret))
294 (dolist (ccs (delq (car ret) (charset-list)))
295 (if (and (or (charset-iso-final-char ccs)
302 (string-match "=ucs@" (symbol-name ccs)))
303 (setq ccs (charset-name ccs))
304 (null (assq ccs char-spec))
305 (setq ret (encode-char char ccs 'defined-only)))
306 (setq char-spec (cons (cons ccs ret) char-spec))))
308 (setq char-spec (split-char char)))
309 (cond ((setq ret (get-char-attribute char 'name))
310 (setq char-spec (cons (cons 'name ret) char-spec))
312 ((setq ret (get-char-attribute char 'name*))
313 (setq char-spec (cons (cons 'name* ret) char-spec))
316 ((setq ret (get-char-attribute
317 char 'ideographic-combination))
319 (cons (cons 'ideographic-combination ret)
326 (defun char-db-insert-char-spec (char &optional readable column
329 (setq column (current-column)))
330 (let (char-spec temp-char)
331 (setq char-spec (char-db-make-char-spec char))
332 (unless (or (characterp char) ; char
334 (setq char (find-char char-spec))
336 ;; define temporary character
337 ;; Current implementation is dirty.
338 (setq temp-char (define-char (cons '(ideograph-daikanwa . 0)
340 (remove-char-attribute temp-char 'ideograph-daikanwa)
341 (setq char temp-char))
342 (insert-char-attributes char
344 (union (mapcar #'car char-spec)
347 ;; undefine temporary character
348 ;; Current implementation is dirty.
349 (setq char-spec (char-attribute-alist temp-char))
351 (remove-char-attribute temp-char (car (car char-spec)))
352 (setq char-spec (cdr char-spec))))))
354 (defun char-db-insert-alist (alist &optional readable column)
356 (setq column (current-column)))
358 (concat "\n" (make-string (1+ column) ?\ )))
362 lbs cell rest separator)
365 (setq name (car (car alist))
366 value (cdr (car alist)))
367 (cond ((eq name 'char)
369 (if (setq ret (condition-case nil
377 (setq key (car (car value)))
378 ;; (if (find-charset key)
379 ;; (setq cal (cons key cal))
380 (setq al (cons key al))
382 (setq value (cdr value)))
383 (insert-char-attributes ret
387 (insert (prin1-to-string value)))
389 (insert line-breaking))
391 (insert (format "(%-18s " name))
392 (setq lbs (concat "\n" (make-string (current-column) ?\ )))
394 (setq cell (car value))
395 (if (and (consp cell)
397 (setq ret (condition-case nil
407 (setq key (car (car rest)))
408 ;; (if (find-charset key)
409 ;; (setq cal (cons key cal))
410 (setq al (cons key al))
412 (setq rest (cdr rest)))
415 (insert-char-attributes ret
419 (setq separator lbs))
422 (insert (prin1-to-string cell))
423 (setq separator " "))
424 (setq value (cdr value)))
426 (insert line-breaking))
428 (insert (format "(%-18s . %S)%s"
431 (setq alist (cdr alist))))
434 (defun char-db-insert-char-reference (plist &optional readable column)
436 (setq column (current-column)))
438 (concat "\n" (make-string (1+ column) ?\ )))
443 (setq name (pop plist))
444 (setq value (pop plist))
445 (cond ((eq name :char)
448 (cond ((numberp value)
449 (setq value (decode-char '=ucs value)))
451 ;; (setq value (or (find-char value)
454 (char-db-insert-char-spec value readable)
455 (insert line-breaking)
458 (insert (format "%s%s\t%d ; %c%s"
461 (ideographic-radical value)
465 (insert (format "%s%s\t%S" separator name value))
466 (setq separator line-breaking)))
470 (defun char-db-decode-isolated-char (ccs code-point)
473 (cond ((eq ccs 'arabic-iso8859-6)
474 (decode-char ccs code-point))
475 ((and (memq ccs '(=gt-pj-1
486 (setq ret (decode-char ccs code-point))
487 (setq ret (encode-char ret '=gt 'defined-only)))
488 (decode-builtin-char '=gt ret))
490 (decode-builtin-char ccs code-point))))
491 (cond ((and (<= 0 (char-int ret))
492 (<= (char-int ret) #x1F))
493 (decode-char '=ucs (+ #x2400 (char-int ret))))
494 ((= (char-int ret) #x7F)
498 (defvar char-db-convert-obsolete-format t)
500 (defun char-db-insert-ccs-feature (name value line-breaking)
503 (cond ((memq name '(=shinjigen
505 =shinjigen@rev =shinjigen/+p@rev))
506 "(%-18s . %04d)\t; %c")
507 ((eq name '=shinjigen@1ed/24pr)
508 "(%-18s . %04d)\t; %c")
509 ((or (memq name '(=daikanwa
510 =daikanwa@rev1 =daikanwa@rev2
511 =gt =>>gt =>gt =gt-k =cbeta
512 =zinbun-oracle =>zinbun-oracle))
513 (string-match "^=adobe-" (symbol-name name)))
514 "(%-18s . %05d)\t; %c")
516 "(%-18s . %06d)\t; %c")
517 ((>= (charset-dimension name) 2)
518 "(%-18s . #x%04X)\t; %c")
520 "(%-18s . #x%02X)\t; %c"))
522 (if (= (charset-iso-graphic-plane name) 1)
524 (cond ((= (charset-dimension name) 1)
526 ((= (charset-dimension name) 2)
528 ((= (charset-dimension name) 3)
532 (char-db-decode-isolated-char name value)))
533 (if (and (= (charset-chars name) 94)
534 (= (charset-dimension name) 2))
535 (insert (format " [%02d-%02d]"
536 (- (lsh value -8) 32)
537 (- (logand value 255) 32))))
538 (insert line-breaking))
540 (defun char-db-insert-relation-feature (char name value line-breaking
542 (insert (format "(%-18s%s " name line-breaking))
543 (let ((lbs (concat "\n" (make-string (current-column) ?\ )))
544 separator cell sources required-features
547 (setq cell (car value))
549 (setq cell (decode-char '=ucs cell)))
551 ((eq name '->subsumptive)
552 (when (or (not (some (lambda (atr)
553 (get-char-attribute cell atr))
554 char-db-ignored-attributes))
556 (encode-char cell ccs 'defined-only))
560 (let ((char-db-ignored-attributes
562 char-db-ignored-attributes)))
563 (insert-char-attributes cell readable))
564 (setq separator lbs))
569 char (intern (format "%s*sources" name))))
570 (setq required-features nil)
571 (dolist (source sources)
575 shinjigen shinjigen@1ed shinjigen@rev))
576 (setq required-features
577 (union required-features
587 (setq required-features
588 (union required-features
593 ((find-charset (setq ret (intern (format "=%s" source))))
594 (setq required-features
595 (cons ret required-features)))
596 (t (setq required-features
597 (cons source required-features)))))
598 (cond ((string-match "@JP" (symbol-name name))
599 (setq required-features
600 (union required-features
608 ((string-match "@CN" (symbol-name name))
609 (setq required-features
610 (union required-features
617 (insert (format "%S" cell))
618 (char-db-insert-char-spec cell readable
621 (setq separator lbs))
625 (if (consp (car cell))
626 (char-db-insert-char-spec cell readable)
627 (char-db-insert-char-reference cell readable))
628 (setq separator lbs))
632 (insert (prin1-to-string cell))
633 (setq separator " ")))
634 (setq value (cdr value)))
636 (insert line-breaking)))
638 (defun insert-char-attributes (char &optional readable attributes column)
640 (setq column (current-column)))
641 (let (name value ; has-long-ccs-name
645 (concat "\n" (make-string (1+ column) ?\ )))
646 lbs cell separator ret
648 dest-ccss ; sources required-features
653 (if (consp attributes)
655 (dolist (name attributes)
656 (unless (memq name char-db-ignored-attributes)
657 (if (find-charset name)
661 (dolist (name (char-attribute-list))
662 (unless (memq name char-db-ignored-attributes)
663 (if (find-charset name)
667 #'char-attribute-name<)))
669 (when (memq '<-subsumptive attributes)
671 (when (setq value (get-char-attribute char '<-subsumptive))
672 (char-db-insert-relation-feature char '<-subsumptive value
675 (setq attributes (delq '<-subsumptive attributes)))
676 (when (and (memq '<-denotational attributes)
677 (setq value (get-char-attribute char '<-denotational)))
678 (char-db-insert-relation-feature char '<-denotational value
681 (setq attributes (delq '<-denotational attributes)))
682 (when (and (memq 'name attributes)
683 (setq value (get-char-attribute char 'name)))
685 (if (> (+ (current-column) (length value)) 48)
688 value line-breaking))
689 (setq attributes (delq 'name attributes))
691 (when (and (memq 'name* attributes)
692 (setq value (get-char-attribute char 'name*)))
694 (if (> (+ (current-column) (length value)) 48)
697 value line-breaking))
698 (setq attributes (delq 'name* attributes))
700 (when (and (memq 'script attributes)
701 (setq value (get-char-attribute char 'script)))
702 (insert (format "(script\t\t%s)%s"
703 (mapconcat (function prin1-to-string)
706 (setq attributes (delq 'script attributes))
708 (dolist (name '(=>ucs =>ucs*))
709 (when (and (memq name attributes)
710 (setq value (get-char-attribute char name)))
711 (insert (format "(%-18s . #x%04X)\t; %c%s"
712 name value (decode-char '=ucs value)
714 (setq attributes (delq name attributes))))
715 (dolist (name '(=>ucs@gb =>ucs@cns =>ucs@jis =>ucs@ks =>ucs@big5))
716 (when (and (memq name attributes)
717 (setq value (get-char-attribute char name)))
718 (insert (format "(%-18s . #x%04X)\t; %c%s"
723 (symbol-name name) 2)))
726 (setq attributes (delq name attributes))
728 (dolist (name '(=>daikanwa))
729 (when (and (memq name attributes)
730 (setq value (get-char-attribute char name)))
733 (format "(%-18s . %05d)\t; %c%s"
734 name value (decode-char '=daikanwa value)
736 (format "(%-18s %s)\t; %c%s"
738 (mapconcat (function prin1-to-string)
740 (char-representative-of-daikanwa char)
742 (setq attributes (delq name attributes))))
743 (when (and (memq 'general-category attributes)
744 (setq value (get-char-attribute char 'general-category)))
746 "(general-category\t%s) ; %s%s"
747 (mapconcat (lambda (cell)
750 (cond ((rassoc value unidata-normative-category-alist)
751 "Normative Category")
752 ((rassoc value unidata-informative-category-alist)
753 "Informative Category")
757 (setq attributes (delq 'general-category attributes))
759 (when (and (memq 'bidi-category attributes)
760 (setq value (get-char-attribute char 'bidi-category)))
761 (insert (format "(bidi-category\t. %S)%s"
764 (setq attributes (delq 'bidi-category attributes))
766 (unless (or (not (memq 'mirrored attributes))
767 (eq (setq value (get-char-attribute char 'mirrored 'empty))
769 (insert (format "(mirrored\t\t. %S)%s"
772 (setq attributes (delq 'mirrored attributes))
775 ((and (memq 'decimal-digit-value attributes)
776 (setq value (get-char-attribute char 'decimal-digit-value)))
777 (insert (format "(decimal-digit-value . %S)%s"
780 (setq attributes (delq 'decimal-digit-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))
797 (when (and (memq 'digit-value attributes)
798 (setq value (get-char-attribute char 'digit-value)))
799 (insert (format "(digit-value\t. %S)%s"
802 (setq attributes (delq 'digit-value attributes))
804 (when (and (memq 'numeric-value attributes)
805 (setq value (get-char-attribute char 'numeric-value)))
806 (insert (format "(numeric-value\t. %S)%s"
809 (setq attributes (delq 'numeric-value attributes))
811 (when (and (memq 'iso-10646-comment attributes)
812 (setq value (get-char-attribute char 'iso-10646-comment)))
813 (insert (format "(iso-10646-comment\t. %S)%s"
816 (setq attributes (delq 'iso-10646-comment attributes))
818 (when (and (memq 'morohashi-daikanwa attributes)
819 (setq value (get-char-attribute char 'morohashi-daikanwa)))
820 (insert (format "(morohashi-daikanwa\t%s)%s"
821 (mapconcat (function prin1-to-string) value " ")
823 (setq attributes (delq 'morohashi-daikanwa attributes))
827 (when (and (memq 'ideographic-radical attributes)
828 (setq value (get-char-attribute char 'ideographic-radical)))
830 (insert (format "(ideographic-radical . %S)\t; %c%s"
832 (ideographic-radical radical)
834 (setq attributes (delq 'ideographic-radical attributes))
836 (when (and (memq 'shuowen-radical attributes)
837 (setq value (get-char-attribute char 'shuowen-radical)))
838 (insert (format "(shuowen-radical\t. %S)\t; %c%s"
840 (shuowen-radical value)
842 (setq attributes (delq 'shuowen-radical attributes))
847 char-db-feature-domains
849 (dolist (feature (char-attribute-list))
850 (setq feature (symbol-name feature))
852 "\\(radical\\|strokes\\)@\\([^@*]+\\)\\(\\*\\|$\\)"
854 (setq domain (intern (match-string 2 feature)))
855 (unless (memq domain dest)
856 (setq dest (cons domain dest)))))
857 (sort dest #'string<))))
858 (setq key (intern (format "%s@%s" 'ideographic-radical domain)))
859 (when (and (memq key attributes)
860 (setq value (get-char-attribute char key)))
862 (insert (format "(%s . %S)\t; %c%s"
865 (ideographic-radical radical)
867 (setq attributes (delq key attributes))
869 (setq key (intern (format "%s@%s" 'ideographic-strokes domain)))
870 (when (and (memq key attributes)
871 (setq value (get-char-attribute char key)))
873 (insert (format "(%s . %S)%s"
877 (setq attributes (delq key attributes))
879 (setq key (intern (format "%s@%s" 'total-strokes domain)))
880 (when (and (memq key attributes)
881 (setq value (get-char-attribute char key)))
882 (insert (format "(%s . %S)%s"
886 (setq attributes (delq key attributes))
888 (dolist (feature '(ideographic-radical
891 (setq key (intern (format "%s@%s*sources" feature domain)))
892 (when (and (memq key attributes)
893 (setq value (get-char-attribute char key)))
894 (insert (format "(%s%s" key line-breaking))
896 (insert (format " %s" cell)))
898 (insert line-breaking)
899 (setq attributes (delq key attributes))
902 (when (and (memq 'ideographic-strokes attributes)
903 (setq value (get-char-attribute char 'ideographic-strokes)))
905 (insert (format "(ideographic-strokes . %S)%s"
908 (setq attributes (delq 'ideographic-strokes attributes))
910 (when (and (memq 'kangxi-radical attributes)
911 (setq value (get-char-attribute char 'kangxi-radical)))
912 (unless (eq value radical)
913 (insert (format "(kangxi-radical\t . %S)\t; %c%s"
915 (ideographic-radical value)
918 (setq radical value)))
919 (setq attributes (delq 'kangxi-radical attributes))
921 (when (and (memq 'kangxi-strokes attributes)
922 (setq value (get-char-attribute char 'kangxi-strokes)))
923 (unless (eq value strokes)
924 (insert (format "(kangxi-strokes\t . %S)%s"
928 (setq strokes value)))
929 (setq attributes (delq 'kangxi-strokes attributes))
931 (when (and (memq 'japanese-radical attributes)
932 (setq value (get-char-attribute char 'japanese-radical)))
933 (unless (eq value radical)
934 (insert (format "(japanese-radical\t . %S)\t; %c%s"
936 (ideographic-radical value)
939 (setq radical value)))
940 (setq attributes (delq 'japanese-radical attributes))
942 (when (and (memq 'japanese-strokes attributes)
943 (setq value (get-char-attribute char 'japanese-strokes)))
944 (unless (eq value strokes)
945 (insert (format "(japanese-strokes\t . %S)%s"
949 (setq strokes value)))
950 (setq attributes (delq 'japanese-strokes attributes))
952 (when (and (memq 'cns-radical attributes)
953 (setq value (get-char-attribute char 'cns-radical)))
954 (insert (format "(cns-radical\t . %S)\t; %c%s"
956 (ideographic-radical value)
958 (setq attributes (delq 'cns-radical attributes))
960 (when (and (memq 'cns-strokes attributes)
961 (setq value (get-char-attribute char 'cns-strokes)))
962 (unless (eq value strokes)
963 (insert (format "(cns-strokes\t . %S)%s"
967 (setq strokes value)))
968 (setq attributes (delq 'cns-strokes attributes))
970 (when (and (memq 'shinjigen-1-radical attributes)
971 (setq value (get-char-attribute char 'shinjigen-1-radical)))
972 (unless (eq value radical)
973 (insert (format "(shinjigen-1-radical . %S)\t; %c%s"
975 (ideographic-radical value)
978 (setq radical value)))
979 (setq attributes (delq 'shinjigen-1-radical attributes))
981 (when (and (memq 'ideographic- attributes)
982 (setq value (get-char-attribute char 'ideographic-)))
983 (insert "(ideographic- ")
984 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
987 (setq cell (car value))
989 (setq cell (decode-char '=ucs cell)))
990 (cond ((characterp cell)
994 (insert (format "%S" cell))
995 (char-db-insert-char-spec cell readable))
996 (setq separator lbs))
1000 (if (consp (car cell))
1001 (char-db-insert-char-spec cell readable)
1002 (char-db-insert-char-reference cell readable))
1003 (setq separator lbs))
1007 (insert (prin1-to-string cell))
1008 (setq separator " ")))
1009 (setq value (cdr value)))
1011 (insert line-breaking)
1012 (setq attributes (delq 'ideographic- attributes)))
1013 (when (and (memq 'total-strokes attributes)
1014 (setq value (get-char-attribute char 'total-strokes)))
1015 (insert (format "(total-strokes . %S)%s"
1018 (setq attributes (delq 'total-strokes attributes))
1020 (when (and (memq '->ideograph attributes)
1021 (setq value (get-char-attribute char '->ideograph)))
1022 (insert (format "(->ideograph\t%s)%s"
1023 (mapconcat (lambda (code)
1024 (cond ((symbolp code)
1027 (format "#x%04X" code))
1030 line-breaking code))))
1033 (setq attributes (delq '->ideograph attributes))
1035 ;; (when (and (memq '->decomposition attributes)
1036 ;; (setq value (get-char-attribute char '->decomposition)))
1037 ;; (insert (format "(->decomposition\t%s)%s"
1038 ;; (mapconcat (lambda (code)
1039 ;; (cond ((symbolp code)
1040 ;; (symbol-name code))
1041 ;; ((characterp code)
1043 ;; (format "%S" code)
1048 ;; (format "#x%04X" code))
1050 ;; (format "%s%S" line-breaking code))))
1053 ;; (setq attributes (delq '->decomposition attributes))
1055 (if (equal (get-char-attribute char '->titlecase)
1056 (get-char-attribute char '->uppercase))
1057 (setq attributes (delq '->titlecase attributes)))
1058 (when (and (memq '->mojikyo attributes)
1059 (setq value (get-char-attribute char '->mojikyo)))
1060 (insert (format "(->mojikyo\t\t. %06d)\t; %c%s"
1061 value (decode-char 'mojikyo value)
1063 (setq attributes (delq '->mojikyo attributes))
1065 (when (and (memq 'hanyu-dazidian-vol attributes)
1066 (setq value (get-char-attribute char 'hanyu-dazidian-vol)))
1067 (insert (format "(hanyu-dazidian-vol . %d)%s"
1068 value line-breaking))
1069 (setq attributes (delq 'hanyu-dazidian-vol attributes))
1071 (when (and (memq 'hanyu-dazidian-page attributes)
1072 (setq value (get-char-attribute char 'hanyu-dazidian-page)))
1073 (insert (format "(hanyu-dazidian-page . %d)%s"
1074 value line-breaking))
1075 (setq attributes (delq 'hanyu-dazidian-page attributes))
1077 (when (and (memq 'hanyu-dazidian-char attributes)
1078 (setq value (get-char-attribute char 'hanyu-dazidian-char)))
1079 (insert (format "(hanyu-dazidian-char . %d)%s"
1080 value line-breaking))
1081 (setq attributes (delq 'hanyu-dazidian-char attributes))
1084 (dolist (ignored '(composition
1085 ->denotational <-subsumptive ->ucs-unified
1086 ->ideographic-component-forms))
1087 (setq attributes (delq ignored attributes))))
1089 (setq name (car attributes))
1090 (if (setq value (get-char-attribute char name))
1091 (cond ((setq ret (find-charset name))
1092 (setq name (charset-name ret))
1093 (if (and (not (memq name dest-ccss))
1095 (setq value (get-char-attribute char name))
1096 (setq dest-ccss (cons name dest-ccss))))
1097 (char-db-insert-ccs-feature name value line-breaking))
1099 ((string-match "^=>ucs@" (symbol-name name))
1100 (insert (format "(%-18s . #x%04X)\t; %c%s"
1101 name value (decode-char '=ucs value)
1104 ((eq name 'jisx0208-1978/4X)
1105 (insert (format "(%-18s . #x%04X)%s"
1111 (not (eq name '->subsumptive))
1112 (not (eq name '->uppercase))
1113 (not (eq name '->lowercase))
1114 (not (eq name '->titlecase))
1115 (not (eq name '->canonical))
1116 (not (eq name '->Bopomofo))
1117 (not (eq name '->mistakable))
1118 (not (eq name '->ideographic-variants))
1119 (null (get-char-attribute
1120 char (intern (format "%s*sources" name))))
1121 (not (string-match "\\*sources$" (symbol-name name)))
1122 (null (get-char-attribute
1123 char (intern (format "%s*note" name))))
1124 (not (string-match "\\*note$" (symbol-name name)))
1125 (or (eq name '<-identical)
1126 (eq name '<-uppercase)
1127 (eq name '<-lowercase)
1128 (eq name '<-titlecase)
1129 (eq name '<-canonical)
1130 (eq name '<-ideographic-variants)
1131 ;; (eq name '<-synonyms)
1132 (string-match "^<-synonyms" (symbol-name name))
1133 (eq name '<-mistakable)
1134 (when (string-match "^->" (symbol-name name))
1136 ((string-match "^->fullwidth" (symbol-name name))
1137 (not (and (consp value)
1138 (characterp (car value))
1140 (car value) '=ucs 'defined-only)))
1145 ((or (eq name 'ideographic-structure)
1146 (eq name 'ideographic-combination)
1147 (eq name 'ideographic-)
1148 (eq name '=decomposition)
1149 (string-match "^=>decomposition" (symbol-name name))
1150 (string-match "^\\(->\\|<-\\)[^*]*$" (symbol-name name))
1151 (string-match "^\\(->\\|<-\\)[^*]*\\*sources$"
1154 (char-db-insert-relation-feature char name value
1157 ((memq name '(ideograph=
1158 original-ideograph-of
1159 ancient-ideograph-of
1162 ;; simplified-ideograph-of
1163 ideographic-variants
1164 ;; ideographic-different-form-of
1166 (insert (format "(%-18s%s " name line-breaking))
1167 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1169 (while (consp value)
1170 (setq cell (car value))
1171 (if (and (consp cell)
1176 (char-db-insert-alist cell readable)
1177 (setq separator lbs))
1180 (insert (prin1-to-string cell))
1181 (setq separator " "))
1182 (setq value (cdr value)))
1184 (insert line-breaking))
1186 (insert (format "(%-18s " name))
1187 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1189 (while (consp value)
1190 (setq cell (car value))
1191 (if (and (consp cell)
1193 (setq ret (condition-case nil
1201 (setq key (car (car rest)))
1202 (if (find-charset key)
1203 (setq cal (cons key cal))
1204 (setq al (cons key al)))
1205 (setq rest (cdr rest)))
1208 (insert-char-attributes ret
1211 (setq separator lbs))
1212 (setq ret (prin1-to-string cell))
1214 (if (< (+ (current-column)
1221 (setq separator " "))
1222 (setq value (cdr value)))
1224 (insert line-breaking))
1226 (insert (format "(%-18s" name))
1227 (setq ret (prin1-to-string value))
1228 (unless (< (+ (current-column)
1232 (insert line-breaking))
1233 (insert " . " ret ")" line-breaking)
1234 ;; (insert (format "(%-18s . %S)%s"
1239 (setq attributes (cdr attributes)))
1242 (defun insert-char-data (char &optional readable
1245 (narrow-to-region (point)(point))
1246 (insert "(define-char
1248 (insert-char-attributes char readable attributes)
1250 (goto-char (point-min))
1251 (while (re-search-forward "[ \t]+$" nil t)
1254 (goto-char (point-min))
1255 (while (re-search-forward "[ \t][ \t][ \t]*" nil t)
1256 (let ((column (current-column))
1257 (indent-tabs-mode t))
1258 (delete-region (match-beginning 0) (point))
1259 (indent-to column)))
1260 (goto-char (point-max))
1261 ;; (tabify (point-min)(point-max))
1264 (defun insert-char-data-with-variant (char &optional printable
1266 script excluded-script)
1267 (insert-char-data char printable)
1268 (let ((variants (char-variants char))
1271 (setq variants (sort variants #'<))
1272 (setq rest variants)
1273 (setq variants (cons char variants))
1275 (setq variant (car rest))
1276 (unless (get-char-attribute variant '<-subsumptive)
1277 (if (and (or (null script)
1278 (null (setq vs (get-char-attribute variant 'script)))
1280 (or (null excluded-script)
1281 (null (setq vs (get-char-attribute variant 'script)))
1282 (not (memq excluded-script vs))))
1283 (unless (and no-ucs-unified (get-char-attribute variant '=ucs))
1284 (insert-char-data variant printable)
1285 (if (setq ret (char-variants variant))
1287 (or (memq (car ret) variants)
1288 ;; (get-char-attribute (car ret) '<-subsumptive)
1289 (setq rest (nconc rest (list (car ret)))))
1290 (setq ret (cdr ret)))))))
1291 (setq rest (cdr rest)))))
1293 (defun insert-char-range-data (min max &optional script excluded-script)
1296 (while (<= code max)
1297 (setq char (decode-char '=ucs code))
1298 (if (encode-char char '=ucs 'defined-only)
1299 (insert-char-data-with-variant char nil 'no-ucs-unified
1300 script excluded-script))
1301 (setq code (1+ code)))))
1303 (defun write-char-range-data-to-file (min max file
1304 &optional script excluded-script)
1305 (let ((coding-system-for-write char-db-file-coding-system))
1307 (insert (format ";; -*- coding: %s -*-\n"
1308 char-db-file-coding-system))
1309 (insert-char-range-data min max script excluded-script)
1310 (write-region (point-min)(point-max) file))))
1312 (defvar what-character-original-window-configuration)
1315 (defun what-char-definition (char)
1316 (interactive (list (char-after)))
1317 (let ((buf (get-buffer-create "*Character Description*"))
1318 (the-buf (current-buffer))
1319 (win-conf (current-window-configuration)))
1321 (make-local-variable 'what-character-original-window-configuration)
1322 (setq what-character-original-window-configuration win-conf)
1323 (setq buffer-read-only nil)
1327 (insert-char-data-with-variant char 'printable)
1328 (unless (char-attribute-alist char)
1329 (insert (format ";; = %c\n"
1330 (let* ((rest (split-char char))
1334 (setq code (logior (lsh code 8)
1336 (decode-char ccs code)))))
1337 ;; (char-db-update-comment)
1338 (set-buffer-modified-p nil)
1339 (view-mode the-buf (lambda (buf)
1340 (set-window-configuration
1341 what-character-original-window-configuration)
1343 (goto-char (point-min)))
1345 (set-window-configuration
1346 what-character-original-window-configuration)
1347 (signal (car err) (cdr err)))))))
1349 (provide 'char-db-util)
1351 ;;; char-db-util.el ends here