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
266 (defun char-db-make-char-spec (char)
268 (cond ((characterp char)
269 (cond ((and (setq ret (encode-char char '=ucs 'defined-only))
270 (not (and (<= #xE000 ret)(<= ret #xF8FF))))
271 (setq char-spec (list (cons '=ucs ret)))
272 (cond ((setq ret (get-char-attribute char 'name))
273 (setq char-spec (cons (cons 'name ret) char-spec))
275 ((setq ret (get-char-attribute char 'name*))
276 (setq char-spec (cons (cons 'name* ret) char-spec))
281 (let ((rest char-db-coded-charset-priority-list)
284 (setq ccs (charset-name
285 (find-charset (car rest))))
287 (encode-char char ccs
289 (throw 'tag (cons ccs ret)))
290 (setq rest (cdr rest))))))
291 (setq char-spec (list ret))
292 (dolist (ccs (delq (car ret) (charset-list)))
293 (if (and (or (charset-iso-final-char ccs)
300 (string-match "=ucs@" (symbol-name ccs)))
301 (setq ccs (charset-name ccs))
302 (null (assq ccs char-spec))
303 (setq ret (encode-char char ccs 'defined-only)))
304 (setq char-spec (cons (cons ccs ret) char-spec))))
306 (setq char-spec (split-char char)))
307 (cond ((setq ret (get-char-attribute char 'name))
308 (setq char-spec (cons (cons 'name ret) char-spec))
310 ((setq ret (get-char-attribute char 'name*))
311 (setq char-spec (cons (cons 'name* ret) char-spec))
314 ((setq ret (get-char-attribute
315 char 'ideographic-combination))
317 (cons (cons 'ideographic-combination ret)
324 (defun char-db-insert-char-spec (char &optional readable column
327 (setq column (current-column)))
328 (let (char-spec temp-char)
329 (setq char-spec (char-db-make-char-spec char))
330 (unless (or (characterp char) ; char
332 (setq char (find-char char-spec))
334 ;; define temporary character
335 ;; Current implementation is dirty.
336 (setq temp-char (define-char (cons '(ideograph-daikanwa . 0)
338 (remove-char-attribute temp-char 'ideograph-daikanwa)
339 (setq char temp-char))
340 (insert-char-attributes char
342 (union (mapcar #'car char-spec)
345 ;; undefine temporary character
346 ;; Current implementation is dirty.
347 (setq char-spec (char-attribute-alist temp-char))
349 (remove-char-attribute temp-char (car (car char-spec)))
350 (setq char-spec (cdr char-spec))))))
352 (defun char-db-insert-alist (alist &optional readable column)
354 (setq column (current-column)))
356 (concat "\n" (make-string (1+ column) ?\ )))
360 lbs cell rest separator)
363 (setq name (car (car alist))
364 value (cdr (car alist)))
365 (cond ((eq name 'char)
367 (if (setq ret (condition-case nil
375 (setq key (car (car value)))
376 ;; (if (find-charset key)
377 ;; (setq cal (cons key cal))
378 (setq al (cons key al))
380 (setq value (cdr value)))
381 (insert-char-attributes ret
385 (insert (prin1-to-string value)))
387 (insert line-breaking))
389 (insert (format "(%-18s " name))
390 (setq lbs (concat "\n" (make-string (current-column) ?\ )))
392 (setq cell (car value))
393 (if (and (consp cell)
395 (setq ret (condition-case nil
405 (setq key (car (car rest)))
406 ;; (if (find-charset key)
407 ;; (setq cal (cons key cal))
408 (setq al (cons key al))
410 (setq rest (cdr rest)))
413 (insert-char-attributes ret
417 (setq separator lbs))
420 (insert (prin1-to-string cell))
421 (setq separator " "))
422 (setq value (cdr value)))
424 (insert line-breaking))
426 (insert (format "(%-18s . %S)%s"
429 (setq alist (cdr alist))))
432 (defun char-db-insert-char-reference (plist &optional readable column)
434 (setq column (current-column)))
436 (concat "\n" (make-string (1+ column) ?\ )))
441 (setq name (pop plist))
442 (setq value (pop plist))
443 (cond ((eq name :char)
446 (cond ((numberp value)
447 (setq value (decode-char '=ucs value)))
449 ;; (setq value (or (find-char value)
452 (char-db-insert-char-spec value readable)
453 (insert line-breaking)
456 (insert (format "%s%s\t%d ; %c%s"
459 (ideographic-radical value)
463 (insert (format "%s%s\t%S" separator name value))
464 (setq separator line-breaking)))
468 (defun char-db-decode-isolated-char (ccs code-point)
471 (cond ((eq ccs 'arabic-iso8859-6)
472 (decode-char ccs code-point))
473 ((and (memq ccs '(=gt-pj-1
484 (setq ret (decode-char ccs code-point))
485 (setq ret (encode-char ret '=gt 'defined-only)))
486 (decode-builtin-char '=gt ret))
488 (decode-builtin-char ccs code-point))))
489 (cond ((and (<= 0 (char-int ret))
490 (<= (char-int ret) #x1F))
491 (decode-char '=ucs (+ #x2400 (char-int ret))))
492 ((= (char-int ret) #x7F)
496 (defvar char-db-convert-obsolete-format t)
498 (defun char-db-insert-ccs-feature (name value line-breaking)
501 (cond ((memq name '(=shinjigen
503 =shinjigen@rev =shinjigen/+p@rev))
504 "(%-18s . %04d)\t; %c")
505 ((eq name '=shinjigen@1ed/24pr)
506 "(%-18s . %04d)\t; %c")
507 ((or (memq name '(=daikanwa
508 =daikanwa@rev1 =daikanwa@rev2
509 =gt =>>gt =>gt =gt-k =cbeta
510 =zinbun-oracle =>zinbun-oracle))
511 (string-match "^=adobe-" (symbol-name name)))
512 "(%-18s . %05d)\t; %c")
514 "(%-18s . %06d)\t; %c")
515 ((>= (charset-dimension name) 2)
516 "(%-18s . #x%04X)\t; %c")
518 "(%-18s . #x%02X)\t; %c"))
520 (if (= (charset-iso-graphic-plane name) 1)
522 (cond ((= (charset-dimension name) 1)
524 ((= (charset-dimension name) 2)
526 ((= (charset-dimension name) 3)
530 (char-db-decode-isolated-char name value)))
531 (if (and (= (charset-chars name) 94)
532 (= (charset-dimension name) 2))
533 (insert (format " [%02d-%02d]"
534 (- (lsh value -8) 32)
535 (- (logand value 255) 32))))
536 (insert line-breaking))
538 (defun char-db-insert-relation-feature (char name value line-breaking
540 (insert (format "(%-18s%s " name line-breaking))
541 (let ((lbs (concat "\n" (make-string (current-column) ?\ )))
542 separator cell sources required-features
545 (setq cell (car value))
547 (setq cell (decode-char '=ucs cell)))
549 ((eq name '->subsumptive)
550 (when (or (not (some (lambda (atr)
551 (get-char-attribute cell atr))
552 char-db-ignored-attributes))
554 (encode-char cell ccs 'defined-only))
558 (let ((char-db-ignored-attributes
560 char-db-ignored-attributes)))
561 (insert-char-attributes cell readable))
562 (setq separator lbs))
567 char (intern (format "%s*sources" name))))
568 (setq required-features nil)
569 (dolist (source sources)
573 shinjigen shinjigen@1ed shinjigen@rev))
574 (setq required-features
575 (union required-features
585 (setq required-features
586 (union required-features
591 ((find-charset (setq ret (intern (format "=%s" source))))
592 (setq required-features
593 (cons ret required-features)))
594 (t (setq required-features
595 (cons source required-features)))))
596 (cond ((string-match "@JP" (symbol-name name))
597 (setq required-features
598 (union required-features
606 ((string-match "@CN" (symbol-name name))
607 (setq required-features
608 (union required-features
615 (insert (format "%S" cell))
616 (char-db-insert-char-spec cell readable
619 (setq separator lbs))
623 (if (consp (car cell))
624 (char-db-insert-char-spec cell readable)
625 (char-db-insert-char-reference cell readable))
626 (setq separator lbs))
630 (insert (prin1-to-string cell))
631 (setq separator " ")))
632 (setq value (cdr value)))
634 (insert line-breaking)))
636 (defun insert-char-attributes (char &optional readable attributes column)
638 (setq column (current-column)))
639 (let (name value ; has-long-ccs-name
643 (concat "\n" (make-string (1+ column) ?\ )))
644 lbs cell separator ret
646 dest-ccss ; sources required-features
651 (if (consp attributes)
653 (dolist (name attributes)
654 (unless (memq name char-db-ignored-attributes)
655 (if (find-charset name)
659 (dolist (name (char-attribute-list))
660 (unless (memq name char-db-ignored-attributes)
661 (if (find-charset name)
665 #'char-attribute-name<)))
667 (when (memq '<-subsumptive attributes)
669 (when (setq value (get-char-attribute char '<-subsumptive))
670 (char-db-insert-relation-feature char '<-subsumptive value
673 (setq attributes (delq '<-subsumptive attributes)))
674 (when (and (memq '<-denotational attributes)
675 (setq value (get-char-attribute char '<-denotational)))
676 (char-db-insert-relation-feature char '<-denotational value
679 (setq attributes (delq '<-denotational attributes)))
680 (when (and (memq 'name attributes)
681 (setq value (get-char-attribute char 'name)))
683 (if (> (+ (current-column) (length value)) 48)
686 value line-breaking))
687 (setq attributes (delq 'name attributes))
689 (when (and (memq 'name* attributes)
690 (setq value (get-char-attribute char 'name*)))
692 (if (> (+ (current-column) (length value)) 48)
695 value line-breaking))
696 (setq attributes (delq 'name* attributes))
698 (when (and (memq 'script attributes)
699 (setq value (get-char-attribute char 'script)))
700 (insert (format "(script\t\t%s)%s"
701 (mapconcat (function prin1-to-string)
704 (setq attributes (delq 'script attributes))
706 (dolist (name '(=>ucs =>ucs*))
707 (when (and (memq name attributes)
708 (setq value (get-char-attribute char name)))
709 (insert (format "(%-18s . #x%04X)\t; %c%s"
710 name value (decode-char '=ucs value)
712 (setq attributes (delq name attributes))))
713 (dolist (name '(=>ucs@gb =>ucs@cns =>ucs@jis =>ucs@ks =>ucs@big5))
714 (when (and (memq name attributes)
715 (setq value (get-char-attribute char name)))
716 (insert (format "(%-18s . #x%04X)\t; %c%s"
721 (symbol-name name) 2)))
724 (setq attributes (delq name attributes))
726 (dolist (name '(=>daikanwa))
727 (when (and (memq name attributes)
728 (setq value (get-char-attribute char name)))
731 (format "(%-18s . %05d)\t; %c%s"
732 name value (decode-char '=daikanwa value)
734 (format "(%-18s %s)\t; %c%s"
736 (mapconcat (function prin1-to-string)
738 (char-representative-of-daikanwa char)
740 (setq attributes (delq name attributes))))
741 (when (and (memq 'general-category attributes)
742 (setq value (get-char-attribute char 'general-category)))
744 "(general-category\t%s) ; %s%s"
745 (mapconcat (lambda (cell)
748 (cond ((rassoc value unidata-normative-category-alist)
749 "Normative Category")
750 ((rassoc value unidata-informative-category-alist)
751 "Informative Category")
755 (setq attributes (delq 'general-category attributes))
757 (when (and (memq 'bidi-category attributes)
758 (setq value (get-char-attribute char 'bidi-category)))
759 (insert (format "(bidi-category\t. %S)%s"
762 (setq attributes (delq 'bidi-category attributes))
764 (unless (or (not (memq 'mirrored attributes))
765 (eq (setq value (get-char-attribute char 'mirrored 'empty))
767 (insert (format "(mirrored\t\t. %S)%s"
770 (setq attributes (delq 'mirrored attributes))
773 ((and (memq 'decimal-digit-value attributes)
774 (setq value (get-char-attribute char 'decimal-digit-value)))
775 (insert (format "(decimal-digit-value . %S)%s"
778 (setq attributes (delq 'decimal-digit-value attributes))
779 (when (and (memq 'digit-value attributes)
780 (setq value (get-char-attribute char 'digit-value)))
781 (insert (format "(digit-value\t . %S)%s"
784 (setq attributes (delq 'digit-value attributes))
786 (when (and (memq 'numeric-value attributes)
787 (setq value (get-char-attribute char 'numeric-value)))
788 (insert (format "(numeric-value\t . %S)%s"
791 (setq attributes (delq 'numeric-value attributes))
795 (when (and (memq 'digit-value attributes)
796 (setq value (get-char-attribute char 'digit-value)))
797 (insert (format "(digit-value\t. %S)%s"
800 (setq attributes (delq 'digit-value attributes))
802 (when (and (memq 'numeric-value attributes)
803 (setq value (get-char-attribute char 'numeric-value)))
804 (insert (format "(numeric-value\t. %S)%s"
807 (setq attributes (delq 'numeric-value attributes))
809 (when (and (memq 'iso-10646-comment attributes)
810 (setq value (get-char-attribute char 'iso-10646-comment)))
811 (insert (format "(iso-10646-comment\t. %S)%s"
814 (setq attributes (delq 'iso-10646-comment attributes))
816 (when (and (memq 'morohashi-daikanwa attributes)
817 (setq value (get-char-attribute char 'morohashi-daikanwa)))
818 (insert (format "(morohashi-daikanwa\t%s)%s"
819 (mapconcat (function prin1-to-string) value " ")
821 (setq attributes (delq 'morohashi-daikanwa attributes))
825 (when (and (memq 'ideographic-radical attributes)
826 (setq value (get-char-attribute char 'ideographic-radical)))
828 (insert (format "(ideographic-radical . %S)\t; %c%s"
830 (ideographic-radical radical)
832 (setq attributes (delq 'ideographic-radical attributes))
834 (when (and (memq 'shuowen-radical attributes)
835 (setq value (get-char-attribute char 'shuowen-radical)))
836 (insert (format "(shuowen-radical\t. %S)\t; %c%s"
838 (shuowen-radical value)
840 (setq attributes (delq 'shuowen-radical attributes))
845 char-db-feature-domains
847 (dolist (feature (char-attribute-list))
848 (setq feature (symbol-name feature))
850 "\\(radical\\|strokes\\)@\\([^@*]+\\)\\(\\*\\|$\\)"
852 (setq domain (intern (match-string 2 feature)))
853 (unless (memq domain dest)
854 (setq dest (cons domain dest)))))
855 (sort dest #'string<))))
856 (setq key (intern (format "%s@%s" 'ideographic-radical domain)))
857 (when (and (memq key attributes)
858 (setq value (get-char-attribute char key)))
860 (insert (format "(%s . %S)\t; %c%s"
863 (ideographic-radical radical)
865 (setq attributes (delq key attributes))
867 (setq key (intern (format "%s@%s" 'ideographic-strokes domain)))
868 (when (and (memq key attributes)
869 (setq value (get-char-attribute char key)))
871 (insert (format "(%s . %S)%s"
875 (setq attributes (delq key attributes))
877 (setq key (intern (format "%s@%s" 'total-strokes domain)))
878 (when (and (memq key attributes)
879 (setq value (get-char-attribute char key)))
880 (insert (format "(%s . %S)%s"
884 (setq attributes (delq key attributes))
886 (dolist (feature '(ideographic-radical
889 (setq key (intern (format "%s@%s*sources" feature domain)))
890 (when (and (memq key attributes)
891 (setq value (get-char-attribute char key)))
892 (insert (format "(%s%s" key line-breaking))
894 (insert (format " %s" cell)))
896 (insert line-breaking)
897 (setq attributes (delq key attributes))
900 (when (and (memq 'ideographic-strokes attributes)
901 (setq value (get-char-attribute char 'ideographic-strokes)))
903 (insert (format "(ideographic-strokes . %S)%s"
906 (setq attributes (delq 'ideographic-strokes attributes))
908 (when (and (memq 'kangxi-radical attributes)
909 (setq value (get-char-attribute char 'kangxi-radical)))
910 (unless (eq value radical)
911 (insert (format "(kangxi-radical\t . %S)\t; %c%s"
913 (ideographic-radical value)
916 (setq radical value)))
917 (setq attributes (delq 'kangxi-radical attributes))
919 (when (and (memq 'kangxi-strokes attributes)
920 (setq value (get-char-attribute char 'kangxi-strokes)))
921 (unless (eq value strokes)
922 (insert (format "(kangxi-strokes\t . %S)%s"
926 (setq strokes value)))
927 (setq attributes (delq 'kangxi-strokes attributes))
929 (when (and (memq 'japanese-radical attributes)
930 (setq value (get-char-attribute char 'japanese-radical)))
931 (unless (eq value radical)
932 (insert (format "(japanese-radical\t . %S)\t; %c%s"
934 (ideographic-radical value)
937 (setq radical value)))
938 (setq attributes (delq 'japanese-radical attributes))
940 (when (and (memq 'japanese-strokes attributes)
941 (setq value (get-char-attribute char 'japanese-strokes)))
942 (unless (eq value strokes)
943 (insert (format "(japanese-strokes\t . %S)%s"
947 (setq strokes value)))
948 (setq attributes (delq 'japanese-strokes attributes))
950 (when (and (memq 'cns-radical attributes)
951 (setq value (get-char-attribute char 'cns-radical)))
952 (insert (format "(cns-radical\t . %S)\t; %c%s"
954 (ideographic-radical value)
956 (setq attributes (delq 'cns-radical attributes))
958 (when (and (memq 'cns-strokes attributes)
959 (setq value (get-char-attribute char 'cns-strokes)))
960 (unless (eq value strokes)
961 (insert (format "(cns-strokes\t . %S)%s"
965 (setq strokes value)))
966 (setq attributes (delq 'cns-strokes attributes))
968 (when (and (memq 'shinjigen-1-radical attributes)
969 (setq value (get-char-attribute char 'shinjigen-1-radical)))
970 (unless (eq value radical)
971 (insert (format "(shinjigen-1-radical . %S)\t; %c%s"
973 (ideographic-radical value)
976 (setq radical value)))
977 (setq attributes (delq 'shinjigen-1-radical attributes))
979 (when (and (memq 'ideographic- attributes)
980 (setq value (get-char-attribute char 'ideographic-)))
981 (insert "(ideographic- ")
982 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
985 (setq cell (car value))
987 (setq cell (decode-char '=ucs cell)))
988 (cond ((characterp cell)
992 (insert (format "%S" cell))
993 (char-db-insert-char-spec cell readable))
994 (setq separator lbs))
998 (if (consp (car cell))
999 (char-db-insert-char-spec cell readable)
1000 (char-db-insert-char-reference cell readable))
1001 (setq separator lbs))
1005 (insert (prin1-to-string cell))
1006 (setq separator " ")))
1007 (setq value (cdr value)))
1009 (insert line-breaking)
1010 (setq attributes (delq 'ideographic- attributes)))
1011 (when (and (memq 'total-strokes attributes)
1012 (setq value (get-char-attribute char 'total-strokes)))
1013 (insert (format "(total-strokes . %S)%s"
1016 (setq attributes (delq 'total-strokes attributes))
1018 (when (and (memq '->ideograph attributes)
1019 (setq value (get-char-attribute char '->ideograph)))
1020 (insert (format "(->ideograph\t%s)%s"
1021 (mapconcat (lambda (code)
1022 (cond ((symbolp code)
1025 (format "#x%04X" code))
1028 line-breaking code))))
1031 (setq attributes (delq '->ideograph attributes))
1033 ;; (when (and (memq '->decomposition attributes)
1034 ;; (setq value (get-char-attribute char '->decomposition)))
1035 ;; (insert (format "(->decomposition\t%s)%s"
1036 ;; (mapconcat (lambda (code)
1037 ;; (cond ((symbolp code)
1038 ;; (symbol-name code))
1039 ;; ((characterp code)
1041 ;; (format "%S" code)
1046 ;; (format "#x%04X" code))
1048 ;; (format "%s%S" line-breaking code))))
1051 ;; (setq attributes (delq '->decomposition attributes))
1053 (if (equal (get-char-attribute char '->titlecase)
1054 (get-char-attribute char '->uppercase))
1055 (setq attributes (delq '->titlecase attributes)))
1056 (when (and (memq '->mojikyo attributes)
1057 (setq value (get-char-attribute char '->mojikyo)))
1058 (insert (format "(->mojikyo\t\t. %06d)\t; %c%s"
1059 value (decode-char 'mojikyo value)
1061 (setq attributes (delq '->mojikyo attributes))
1063 (when (and (memq 'hanyu-dazidian-vol attributes)
1064 (setq value (get-char-attribute char 'hanyu-dazidian-vol)))
1065 (insert (format "(hanyu-dazidian-vol . %d)%s"
1066 value line-breaking))
1067 (setq attributes (delq 'hanyu-dazidian-vol attributes))
1069 (when (and (memq 'hanyu-dazidian-page attributes)
1070 (setq value (get-char-attribute char 'hanyu-dazidian-page)))
1071 (insert (format "(hanyu-dazidian-page . %d)%s"
1072 value line-breaking))
1073 (setq attributes (delq 'hanyu-dazidian-page attributes))
1075 (when (and (memq 'hanyu-dazidian-char attributes)
1076 (setq value (get-char-attribute char 'hanyu-dazidian-char)))
1077 (insert (format "(hanyu-dazidian-char . %d)%s"
1078 value line-breaking))
1079 (setq attributes (delq 'hanyu-dazidian-char attributes))
1082 (dolist (ignored '(composition
1083 ->denotational <-subsumptive ->ucs-unified
1084 ->ideographic-component-forms))
1085 (setq attributes (delq ignored attributes))))
1087 (setq name (car attributes))
1088 (if (setq value (get-char-attribute char name))
1089 (cond ((setq ret (find-charset name))
1090 (setq name (charset-name ret))
1091 (if (and (not (memq name dest-ccss))
1093 (setq value (get-char-attribute char name))
1094 (setq dest-ccss (cons name dest-ccss))))
1095 (char-db-insert-ccs-feature name value line-breaking))
1097 ((string-match "^=>ucs@" (symbol-name name))
1098 (insert (format "(%-18s . #x%04X)\t; %c%s"
1099 name value (decode-char '=ucs value)
1102 ((eq name 'jisx0208-1978/4X)
1103 (insert (format "(%-18s . #x%04X)%s"
1109 (not (eq name '->subsumptive))
1110 (not (eq name '->uppercase))
1111 (not (eq name '->lowercase))
1112 (not (eq name '->titlecase))
1113 (not (eq name '->canonical))
1114 (not (eq name '->Bopomofo))
1115 (not (eq name '->mistakable))
1116 (not (eq name '->ideographic-variants))
1117 (null (get-char-attribute
1118 char (intern (format "%s*sources" name))))
1119 (not (string-match "\\*sources$" (symbol-name name)))
1120 (null (get-char-attribute
1121 char (intern (format "%s*note" name))))
1122 (not (string-match "\\*note$" (symbol-name name)))
1123 (or (eq name '<-identical)
1124 (eq name '<-uppercase)
1125 (eq name '<-lowercase)
1126 (eq name '<-titlecase)
1127 (eq name '<-canonical)
1128 (eq name '<-ideographic-variants)
1129 ;; (eq name '<-synonyms)
1130 (string-match "^<-synonyms" (symbol-name name))
1131 (eq name '<-mistakable)
1132 (when (string-match "^->" (symbol-name name))
1134 ((string-match "^->fullwidth" (symbol-name name))
1135 (not (and (consp value)
1136 (characterp (car value))
1138 (car value) '=ucs 'defined-only)))
1143 ((or (eq name 'ideographic-structure)
1144 (eq name 'ideographic-combination)
1145 (eq name 'ideographic-)
1146 (eq name '=decomposition)
1147 (string-match "^=>decomposition" (symbol-name name))
1148 (string-match "^\\(->\\|<-\\)[^*]*$" (symbol-name name))
1149 (string-match "^\\(->\\|<-\\)[^*]*\\*sources$"
1152 (char-db-insert-relation-feature char name value
1155 ((memq name '(ideograph=
1156 original-ideograph-of
1157 ancient-ideograph-of
1160 ;; simplified-ideograph-of
1161 ideographic-variants
1162 ;; ideographic-different-form-of
1164 (insert (format "(%-18s%s " name line-breaking))
1165 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1167 (while (consp value)
1168 (setq cell (car value))
1169 (if (and (consp cell)
1174 (char-db-insert-alist cell readable)
1175 (setq separator lbs))
1178 (insert (prin1-to-string cell))
1179 (setq separator " "))
1180 (setq value (cdr value)))
1182 (insert line-breaking))
1184 (insert (format "(%-18s " name))
1185 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1187 (while (consp value)
1188 (setq cell (car value))
1189 (if (and (consp cell)
1191 (setq ret (condition-case nil
1199 (setq key (car (car rest)))
1200 (if (find-charset key)
1201 (setq cal (cons key cal))
1202 (setq al (cons key al)))
1203 (setq rest (cdr rest)))
1206 (insert-char-attributes ret
1209 (setq separator lbs))
1210 (setq ret (prin1-to-string cell))
1212 (if (< (+ (current-column)
1219 (setq separator " "))
1220 (setq value (cdr value)))
1222 (insert line-breaking))
1224 (insert (format "(%-18s" name))
1225 (setq ret (prin1-to-string value))
1226 (unless (< (+ (current-column)
1230 (insert line-breaking))
1231 (insert " . " ret ")" line-breaking)
1232 ;; (insert (format "(%-18s . %S)%s"
1237 (setq attributes (cdr attributes)))
1240 (defun insert-char-data (char &optional readable
1243 (narrow-to-region (point)(point))
1244 (insert "(define-char
1246 (insert-char-attributes char readable attributes)
1248 (goto-char (point-min))
1249 (while (re-search-forward "[ \t]+$" nil t)
1252 (goto-char (point-min))
1253 (while (re-search-forward "[ \t][ \t][ \t]*" nil t)
1254 (let ((column (current-column))
1255 (indent-tabs-mode t))
1256 (delete-region (match-beginning 0) (point))
1257 (indent-to column)))
1258 (goto-char (point-max))
1259 ;; (tabify (point-min)(point-max))
1262 (defun insert-char-data-with-variant (char &optional printable
1264 script excluded-script)
1265 (insert-char-data char printable)
1266 (let ((variants (char-variants char))
1269 (setq variants (sort variants #'<))
1270 (setq rest variants)
1271 (setq variants (cons char variants))
1273 (setq variant (car rest))
1274 (unless (get-char-attribute variant '<-subsumptive)
1275 (if (and (or (null script)
1276 (null (setq vs (get-char-attribute variant 'script)))
1278 (or (null excluded-script)
1279 (null (setq vs (get-char-attribute variant 'script)))
1280 (not (memq excluded-script vs))))
1281 (unless (and no-ucs-unified (get-char-attribute variant '=ucs))
1282 (insert-char-data variant printable)
1283 (if (setq ret (char-variants variant))
1285 (or (memq (car ret) variants)
1286 ;; (get-char-attribute (car ret) '<-subsumptive)
1287 (setq rest (nconc rest (list (car ret)))))
1288 (setq ret (cdr ret)))))))
1289 (setq rest (cdr rest)))))
1291 (defun insert-char-range-data (min max &optional script excluded-script)
1294 (while (<= code max)
1295 (setq char (decode-char '=ucs code))
1296 (if (encode-char char '=ucs 'defined-only)
1297 (insert-char-data-with-variant char nil 'no-ucs-unified
1298 script excluded-script))
1299 (setq code (1+ code)))))
1301 (defun write-char-range-data-to-file (min max file
1302 &optional script excluded-script)
1303 (let ((coding-system-for-write char-db-file-coding-system))
1305 (insert (format ";; -*- coding: %s -*-\n"
1306 char-db-file-coding-system))
1307 (insert-char-range-data min max script excluded-script)
1308 (write-region (point-min)(point-max) file))))
1310 (defvar what-character-original-window-configuration)
1313 (defun what-char-definition (char)
1314 (interactive (list (char-after)))
1315 (let ((buf (get-buffer-create "*Character Description*"))
1316 (the-buf (current-buffer))
1317 (win-conf (current-window-configuration)))
1319 (make-local-variable 'what-character-original-window-configuration)
1320 (setq what-character-original-window-configuration win-conf)
1321 (setq buffer-read-only nil)
1325 (insert-char-data-with-variant char 'printable)
1326 (unless (char-attribute-alist char)
1327 (insert (format ";; = %c\n"
1328 (let* ((rest (split-char char))
1332 (setq code (logior (lsh code 8)
1334 (decode-char ccs code)))))
1335 ;; (char-db-update-comment)
1336 (set-buffer-modified-p nil)
1337 (view-mode the-buf (lambda (buf)
1338 (set-window-configuration
1339 what-character-original-window-configuration)
1341 (goto-char (point-min)))
1343 (set-window-configuration
1344 what-character-original-window-configuration)
1345 (signal (car err) (cdr err)))))))
1347 (provide 'char-db-util)
1349 ;;; char-db-util.el ends here