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 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)))
73 (defun ideographic-radical (number)
74 (aref ideographic-radicals number))
76 (defconst shuowen-radicals
77 [?一 ?上 ?示 ?三 ?王 ?玉 ?玨 ?气 ?士 ?丨 ; 010
78 ?屮 ?艸 ?蓐 ?茻 ?小 ?八 ?釆 ?半 ?牛 ?犛 ; 020
79 ?告 ?口 ?凵 ?吅 ?哭 ?走 ?止 ?癶 ?步 ?此 ; 030
80 ?正 ?是 ?辵 ?彳 ?廴 ?㢟 ?行 ?齒 ?牙 ?足 ; 040
81 ?疋 ?品 ?龠 ?冊 ?㗊 ?舌 ?干 ?谷 ?只 ?㕯 ; 050
82 ?句 ?丩 ?古 ?十 ?卅 ?言 ?誩 ?音 ?䇂 ?丵 ; 060
83 ?菐 ?𠬞 ?廾 ?共 ?異 ?舁 ?𦥑 ?䢅 ?爨 ?革 ; 070
84 ?鬲 ?䰜 ?爪 ?𠃨 ?鬥 ?又 ?𠂇 ?㕜 ?支 ?𦘒 ; 080
85 ?聿 ?畫 ?隶 ?臤 ?臣 ?殳 ?殺 ?𠘧 ?寸 ?皮 ; 090
86 ?㼱 ?攴 ?敎 ?卜 ?用 ?爻 ?㸚 ?𥄎 ?目 ?䀠 ; 100
87 ?眉 ?盾 ?自 ?白 ?鼻 ?皕 ?習 ?羽 ?隹 ?奞 ; 110
88 ?萑 ?𦫳 ?苜 ?羊 ?羴 ?瞿 ?雔 ?雥 ?鳥 ?烏 ; 120
89 ?𠦒 ?冓 ?幺 ?𢆶 ?叀 ?玄 ?予 ?放 ?𠬪 ?𣦼 ; 130
90 ?歺 ?死 ?冎 ?骨 ?肉 ?筋 ?刀 ?刃 ?㓞 ?丰 ; 140
91 ?耒 ?𧢲 ?竹 ?箕 ?丌 ?左 ?工 ?㠭 ?巫 ?甘 ; 150
92 ?曰 ?乃 ?丂 ?可 ?兮 ?号 ?亏 ?旨 ?喜 ?壴 ; 160
93 ?鼓 ?豈 ?豆 ?豊 ?豐 ?䖒 ?虍 ?虎 ?虤 ?皿 ; 170
94 ?𠙴 ?去 ?血 ?丶 ?丹 ?青 ?井 ?皀 ?鬯 ?食 ; 180
95 ?亼 ?會 ?倉 ?入 ?缶 ?矢 ?高 ?冂 ?𩫏 ?京 ; 190
96 ?亯 ?𣆪 ?畗 ?㐭 ?嗇 ?來 ?麥 ?夊 ?舛 ?䑞 ; 200
97 ?韋 ?弟 ?夂 ?久 ?桀 ?木 ?東 ?林 ?才 ?叒 ; 210
98 ?之 ?帀 ?出 ?𣎵 ?生 ?乇 ?𠂹 ?𠌶 ?華 ?𥝌 ; 220
99 ?稽 ?巢 ?桼 ?束 ?㯻 ?囗 ?員 ?貝 ?邑 ?𨛜 ; 230
100 ?日 ?旦 ?倝 ?㫃 ?冥 ?晶 ?月 ?有 ?明 ?囧 ; 240
101 ?夕 ?多 ?毌 ?𢎘 ?𣐺 ?卣 ?齊 ?朿 ?片 ?鼎 ; 250
102 ?克 ?彔 ?禾 ?秝 ?黍 ?香 ?米 ?毇 ?臼 ?凶 ; 260
103 ?𣎳 ?林 ?麻 ?尗 ?耑 ?韭 ?瓜 ?瓠 ?宀 ?宮 ; 270
104 ?呂 ?穴 ?㝱 ?𤕫 ?冖 ?𠔼 ?冃 ?㒳 ?网 ?襾 ; 280
105 ?巾 ?巿 ?帛 ?白 ?㡀 ?黹 ?人 ?𠤎 ?匕 ?从 ; 290
108 (defun shuowen-radical (number)
109 (aref shuowen-radicals (1- number)))
111 (defvar char-db-file-coding-system 'utf-8-mcs-er)
113 (defvar char-db-feature-domains
114 '(ucs ucs/compat daikanwa cns gt jis jis/alt jis/a jis/b
115 jis-x0212 jis-x0213 cdp shinjigen misc unknown))
117 (defvar char-db-ignored-attributes '(ideographic-products))
119 (defun char-attribute-name< (ka kb)
121 ((eq '->denotational kb)
123 ((eq '->subsumptive kb)
124 (not (eq '->denotational ka)))
125 ((eq '->denotational ka)
127 ((eq '->subsumptive ka)
130 (string-match "^->" (symbol-name ka)))
131 (cond ((and (symbolp kb)
132 (string-match "^->" (symbol-name kb)))
133 (string< (symbol-name ka)
138 (string-match "^->" (symbol-name kb)))
141 (string-match "^<-" (symbol-name ka)))
143 (cond ((string-match "^<-" (symbol-name kb))
144 (string< (symbol-name ka)
147 ;; ((string-match "^->" (symbol-name kb))
152 (string-match "^<-" (symbol-name kb)))
154 ;; (not (string-match "^->" (symbol-name ka)))
157 (if (find-charset kb)
159 (if (setq a-ir (charset-property ka 'iso-ir))
160 (if (setq b-ir (charset-property kb 'iso-ir))
163 (< (charset-id ka)(charset-id kb))
173 (if (charset-property kb 'iso-ir)
175 (< (charset-id ka)(charset-id kb)))))
181 (string< (symbol-name ka)
187 (defvar char-db-coded-charset-priority-list
260 (defun char-db-make-char-spec (char)
262 (cond ((characterp char)
263 (cond ((and (setq ret (encode-char char '=ucs 'defined-only))
264 (not (and (<= #xE000 ret)(<= ret #xF8FF))))
265 (setq char-spec (list (cons '=ucs ret)))
266 (cond ((setq ret (get-char-attribute char 'name))
267 (setq char-spec (cons (cons 'name ret) char-spec))
269 ((setq ret (get-char-attribute char 'name*))
270 (setq char-spec (cons (cons 'name* ret) char-spec))
275 (let ((rest char-db-coded-charset-priority-list)
278 (setq ccs (charset-name
279 (find-charset (car rest))))
281 (encode-char char ccs
283 (throw 'tag (cons ccs ret)))
284 (setq rest (cdr rest))))))
285 (setq char-spec (list ret))
286 (dolist (ccs (delq (car ret) (charset-list)))
287 (if (and (or (charset-iso-final-char ccs)
294 (string-match "=ucs@" (symbol-name ccs)))
295 (setq ccs (charset-name ccs))
296 (null (assq ccs char-spec))
297 (setq ret (encode-char char ccs 'defined-only)))
298 (setq char-spec (cons (cons ccs ret) char-spec))))
300 (setq char-spec (split-char char)))
301 (cond ((setq ret (get-char-attribute char 'name))
302 (setq char-spec (cons (cons 'name ret) char-spec))
304 ((setq ret (get-char-attribute char 'name*))
305 (setq char-spec (cons (cons 'name* ret) char-spec))
308 ((setq ret (get-char-attribute
309 char 'ideographic-combination))
311 (cons (cons 'ideographic-combination ret)
318 (defun char-db-insert-char-spec (char &optional readable column
321 (setq column (current-column)))
322 (let (char-spec temp-char)
323 (setq char-spec (char-db-make-char-spec char))
324 (unless (or (characterp char) ; char
326 (setq char (find-char char-spec))
328 ;; define temporary character
329 ;; Current implementation is dirty.
330 (setq temp-char (define-char (cons '(ideograph-daikanwa . 0)
332 (remove-char-attribute temp-char 'ideograph-daikanwa)
333 (setq char temp-char))
334 (insert-char-attributes char
336 (union (mapcar #'car char-spec)
339 ;; undefine temporary character
340 ;; Current implementation is dirty.
341 (setq char-spec (char-attribute-alist temp-char))
343 (remove-char-attribute temp-char (car (car char-spec)))
344 (setq char-spec (cdr char-spec))))))
346 (defun char-db-insert-alist (alist &optional readable column)
348 (setq column (current-column)))
350 (concat "\n" (make-string (1+ column) ?\ )))
354 lbs cell rest separator)
357 (setq name (car (car alist))
358 value (cdr (car alist)))
359 (cond ((eq name 'char)
361 (if (setq ret (condition-case nil
369 (setq key (car (car value)))
370 ;; (if (find-charset key)
371 ;; (setq cal (cons key cal))
372 (setq al (cons key al))
374 (setq value (cdr value)))
375 (insert-char-attributes ret
379 (insert (prin1-to-string value)))
381 (insert line-breaking))
383 (insert (format "(%-18s " name))
384 (setq lbs (concat "\n" (make-string (current-column) ?\ )))
386 (setq cell (car value))
387 (if (and (consp cell)
389 (setq ret (condition-case nil
399 (setq key (car (car rest)))
400 ;; (if (find-charset key)
401 ;; (setq cal (cons key cal))
402 (setq al (cons key al))
404 (setq rest (cdr rest)))
407 (insert-char-attributes ret
411 (setq separator lbs))
414 (insert (prin1-to-string cell))
415 (setq separator " "))
416 (setq value (cdr value)))
418 (insert line-breaking))
420 (insert (format "(%-18s . %S)%s"
423 (setq alist (cdr alist))))
426 (defun char-db-insert-char-reference (plist &optional readable column)
428 (setq column (current-column)))
430 (concat "\n" (make-string (1+ column) ?\ )))
435 (setq name (pop plist))
436 (setq value (pop plist))
437 (cond ((eq name :char)
440 (cond ((numberp value)
441 (setq value (decode-char '=ucs value)))
443 ;; (setq value (or (find-char value)
446 (char-db-insert-char-spec value readable)
447 (insert line-breaking)
450 (insert (format "%s%s\t%d ; %c%s"
453 (ideographic-radical value)
457 (insert (format "%s%s\t%S" separator name value))
458 (setq separator line-breaking)))
462 (defun char-db-decode-isolated-char (ccs code-point)
465 (cond ((eq ccs 'arabic-iso8859-6)
466 (decode-char ccs code-point))
467 ((and (memq ccs '(=gt-pj-1
478 (setq ret (decode-char ccs code-point))
479 (setq ret (encode-char ret '=gt 'defined-only)))
480 (decode-builtin-char '=gt ret))
482 (decode-builtin-char ccs code-point))))
483 (cond ((and (<= 0 (char-int ret))
484 (<= (char-int ret) #x1F))
485 (decode-char '=ucs (+ #x2400 (char-int ret))))
486 ((= (char-int ret) #x7F)
490 (defvar char-db-convert-obsolete-format t)
492 (defun char-db-insert-ccs-feature (name value line-breaking)
495 (cond ((memq name '(=shinjigen
497 =shinjigen@rev =shinjigen/+p@rev))
498 "(%-18s . %04d)\t; %c")
499 ((eq name '=shinjigen@1ed/24pr)
500 "(%-18s . %04d)\t; %c")
501 ((or (memq name '(=daikanwa
502 =daikanwa@rev1 =daikanwa@rev2
503 =gt =>>gt =>gt =gt-k =cbeta =zinbun-oracle))
504 (string-match "^=adobe-" (symbol-name name)))
505 "(%-18s . %05d)\t; %c")
507 "(%-18s . %06d)\t; %c")
508 ((>= (charset-dimension name) 2)
509 "(%-18s . #x%04X)\t; %c")
511 "(%-18s . #x%02X)\t; %c"))
513 (if (= (charset-iso-graphic-plane name) 1)
515 (cond ((= (charset-dimension name) 1)
517 ((= (charset-dimension name) 2)
519 ((= (charset-dimension name) 3)
523 (char-db-decode-isolated-char name value)))
524 (if (and (= (charset-chars name) 94)
525 (= (charset-dimension name) 2))
526 (insert (format " [%02d-%02d]"
527 (- (lsh value -8) 32)
528 (- (logand value 255) 32))))
529 (insert line-breaking))
531 (defun char-db-insert-relation-feature (char name value line-breaking
533 (insert (format "(%-18s%s " name line-breaking))
534 (let ((lbs (concat "\n" (make-string (current-column) ?\ )))
535 separator cell sources required-features
538 (setq cell (car value))
540 (setq cell (decode-char '=ucs cell)))
542 ((eq name '->subsumptive)
543 (when (or (not (some (lambda (atr)
544 (get-char-attribute cell atr))
545 char-db-ignored-attributes))
547 (encode-char cell ccs 'defined-only))
551 (let ((char-db-ignored-attributes
553 char-db-ignored-attributes)))
554 (insert-char-attributes cell readable))
555 (setq separator lbs))
560 char (intern (format "%s*sources" name))))
561 (setq required-features nil)
562 (dolist (source sources)
566 shinjigen shinjigen@1ed shinjigen@rev))
567 (setq required-features
568 (union required-features
578 (setq required-features
579 (union required-features
584 ((find-charset (setq ret (intern (format "=%s" source))))
585 (setq required-features
586 (cons ret required-features)))
587 (t (setq required-features
588 (cons source required-features)))))
589 (cond ((string-match "@JP" (symbol-name name))
590 (setq required-features
591 (union required-features
599 ((string-match "@CN" (symbol-name name))
600 (setq required-features
601 (union required-features
608 (insert (format "%S" cell))
609 (char-db-insert-char-spec cell readable
612 (setq separator lbs))
616 (if (consp (car cell))
617 (char-db-insert-char-spec cell readable)
618 (char-db-insert-char-reference cell readable))
619 (setq separator lbs))
623 (insert (prin1-to-string cell))
624 (setq separator " ")))
625 (setq value (cdr value)))
627 (insert line-breaking)))
629 (defun insert-char-attributes (char &optional readable attributes column)
631 (setq column (current-column)))
632 (let (name value ; has-long-ccs-name
636 (concat "\n" (make-string (1+ column) ?\ )))
637 lbs cell separator ret
639 dest-ccss ; sources required-features
644 (if (consp attributes)
646 (dolist (name attributes)
647 (unless (memq name char-db-ignored-attributes)
648 (if (find-charset name)
652 (dolist (name (char-attribute-list))
653 (unless (memq name char-db-ignored-attributes)
654 (if (find-charset name)
658 #'char-attribute-name<)))
660 (when (memq '<-subsumptive attributes)
662 (when (setq value (get-char-attribute char '<-subsumptive))
663 (char-db-insert-relation-feature char '<-subsumptive value
666 (setq attributes (delq '<-subsumptive attributes)))
667 (when (and (memq '<-denotational attributes)
668 (setq value (get-char-attribute char '<-denotational)))
669 (char-db-insert-relation-feature char '<-denotational value
672 (setq attributes (delq '<-denotational attributes)))
673 (when (and (memq 'name attributes)
674 (setq value (get-char-attribute char 'name)))
676 (if (> (+ (current-column) (length value)) 48)
679 value line-breaking))
680 (setq attributes (delq 'name 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 'script attributes)
692 (setq value (get-char-attribute char 'script)))
693 (insert (format "(script\t\t%s)%s"
694 (mapconcat (function prin1-to-string)
697 (setq attributes (delq 'script attributes))
699 (dolist (name '(=>ucs =>ucs*))
700 (when (and (memq name attributes)
701 (setq value (get-char-attribute char name)))
702 (insert (format "(%-18s . #x%04X)\t; %c%s"
703 name value (decode-char '=ucs value)
705 (setq attributes (delq name attributes))))
706 (dolist (name '(=>ucs@gb =>ucs@cns =>ucs@jis =>ucs@ks =>ucs@big5))
707 (when (and (memq name attributes)
708 (setq value (get-char-attribute char name)))
709 (insert (format "(%-18s . #x%04X)\t; %c%s"
714 (symbol-name name) 2)))
717 (setq attributes (delq name attributes))
719 (dolist (name '(=>daikanwa))
720 (when (and (memq name attributes)
721 (setq value (get-char-attribute char name)))
724 (format "(%-18s . %05d)\t; %c%s"
725 name value (decode-char '=daikanwa value)
727 (format "(%-18s %s)\t; %c%s"
729 (mapconcat (function prin1-to-string)
731 (char-representative-of-daikanwa char)
733 (setq attributes (delq name attributes))))
734 (when (and (memq 'general-category attributes)
735 (setq value (get-char-attribute char 'general-category)))
737 "(general-category\t%s) ; %s%s"
738 (mapconcat (lambda (cell)
741 (cond ((rassoc value unidata-normative-category-alist)
742 "Normative Category")
743 ((rassoc value unidata-informative-category-alist)
744 "Informative Category")
748 (setq attributes (delq 'general-category attributes))
750 (when (and (memq 'bidi-category attributes)
751 (setq value (get-char-attribute char 'bidi-category)))
752 (insert (format "(bidi-category\t. %S)%s"
755 (setq attributes (delq 'bidi-category attributes))
757 (unless (or (not (memq 'mirrored attributes))
758 (eq (setq value (get-char-attribute char 'mirrored 'empty))
760 (insert (format "(mirrored\t\t. %S)%s"
763 (setq attributes (delq 'mirrored attributes))
766 ((and (memq 'decimal-digit-value attributes)
767 (setq value (get-char-attribute char 'decimal-digit-value)))
768 (insert (format "(decimal-digit-value . %S)%s"
771 (setq attributes (delq 'decimal-digit-value attributes))
772 (when (and (memq 'digit-value attributes)
773 (setq value (get-char-attribute char 'digit-value)))
774 (insert (format "(digit-value\t . %S)%s"
777 (setq attributes (delq 'digit-value attributes))
779 (when (and (memq 'numeric-value attributes)
780 (setq value (get-char-attribute char 'numeric-value)))
781 (insert (format "(numeric-value\t . %S)%s"
784 (setq attributes (delq 'numeric-value attributes))
788 (when (and (memq 'digit-value attributes)
789 (setq value (get-char-attribute char 'digit-value)))
790 (insert (format "(digit-value\t. %S)%s"
793 (setq attributes (delq 'digit-value attributes))
795 (when (and (memq 'numeric-value attributes)
796 (setq value (get-char-attribute char 'numeric-value)))
797 (insert (format "(numeric-value\t. %S)%s"
800 (setq attributes (delq 'numeric-value attributes))
802 (when (and (memq 'iso-10646-comment attributes)
803 (setq value (get-char-attribute char 'iso-10646-comment)))
804 (insert (format "(iso-10646-comment\t. %S)%s"
807 (setq attributes (delq 'iso-10646-comment attributes))
809 (when (and (memq 'morohashi-daikanwa attributes)
810 (setq value (get-char-attribute char 'morohashi-daikanwa)))
811 (insert (format "(morohashi-daikanwa\t%s)%s"
812 (mapconcat (function prin1-to-string) value " ")
814 (setq attributes (delq 'morohashi-daikanwa attributes))
818 (when (and (memq 'ideographic-radical attributes)
819 (setq value (get-char-attribute char 'ideographic-radical)))
821 (insert (format "(ideographic-radical . %S)\t; %c%s"
823 (ideographic-radical radical)
825 (setq attributes (delq 'ideographic-radical attributes))
827 (when (and (memq 'shuowen-radical attributes)
828 (setq value (get-char-attribute char 'shuowen-radical)))
829 (insert (format "(shuowen-radical\t. %S)\t; %c%s"
831 (shuowen-radical value)
833 (setq attributes (delq 'shuowen-radical attributes))
838 char-db-feature-domains
840 (dolist (feature (char-attribute-list))
841 (setq feature (symbol-name feature))
843 "\\(radical\\|strokes\\)@\\([^@*]+\\)\\(\\*\\|$\\)"
845 (setq domain (intern (match-string 2 feature)))
846 (unless (memq domain dest)
847 (setq dest (cons domain dest)))))
848 (sort dest #'string<))))
849 (setq key (intern (format "%s@%s" 'ideographic-radical domain)))
850 (when (and (memq key attributes)
851 (setq value (get-char-attribute char key)))
853 (insert (format "(%s . %S)\t; %c%s"
856 (ideographic-radical radical)
858 (setq attributes (delq key attributes))
860 (setq key (intern (format "%s@%s" 'ideographic-strokes domain)))
861 (when (and (memq key attributes)
862 (setq value (get-char-attribute char key)))
864 (insert (format "(%s . %S)%s"
868 (setq attributes (delq key attributes))
870 (setq key (intern (format "%s@%s" 'total-strokes domain)))
871 (when (and (memq key attributes)
872 (setq value (get-char-attribute char key)))
873 (insert (format "(%s . %S)%s"
877 (setq attributes (delq key attributes))
879 (dolist (feature '(ideographic-radical
882 (setq key (intern (format "%s@%s*sources" feature domain)))
883 (when (and (memq key attributes)
884 (setq value (get-char-attribute char key)))
885 (insert (format "(%s%s" key line-breaking))
887 (insert (format " %s" cell)))
889 (insert line-breaking)
890 (setq attributes (delq key attributes))
893 (when (and (memq 'ideographic-strokes attributes)
894 (setq value (get-char-attribute char 'ideographic-strokes)))
896 (insert (format "(ideographic-strokes . %S)%s"
899 (setq attributes (delq 'ideographic-strokes attributes))
901 (when (and (memq 'kangxi-radical attributes)
902 (setq value (get-char-attribute char 'kangxi-radical)))
903 (unless (eq value radical)
904 (insert (format "(kangxi-radical\t . %S)\t; %c%s"
906 (ideographic-radical value)
909 (setq radical value)))
910 (setq attributes (delq 'kangxi-radical attributes))
912 (when (and (memq 'kangxi-strokes attributes)
913 (setq value (get-char-attribute char 'kangxi-strokes)))
914 (unless (eq value strokes)
915 (insert (format "(kangxi-strokes\t . %S)%s"
919 (setq strokes value)))
920 (setq attributes (delq 'kangxi-strokes attributes))
922 (when (and (memq 'japanese-radical attributes)
923 (setq value (get-char-attribute char 'japanese-radical)))
924 (unless (eq value radical)
925 (insert (format "(japanese-radical\t . %S)\t; %c%s"
927 (ideographic-radical value)
930 (setq radical value)))
931 (setq attributes (delq 'japanese-radical attributes))
933 (when (and (memq 'japanese-strokes attributes)
934 (setq value (get-char-attribute char 'japanese-strokes)))
935 (unless (eq value strokes)
936 (insert (format "(japanese-strokes\t . %S)%s"
940 (setq strokes value)))
941 (setq attributes (delq 'japanese-strokes attributes))
943 (when (and (memq 'cns-radical attributes)
944 (setq value (get-char-attribute char 'cns-radical)))
945 (insert (format "(cns-radical\t . %S)\t; %c%s"
947 (ideographic-radical value)
949 (setq attributes (delq 'cns-radical attributes))
951 (when (and (memq 'cns-strokes attributes)
952 (setq value (get-char-attribute char 'cns-strokes)))
953 (unless (eq value strokes)
954 (insert (format "(cns-strokes\t . %S)%s"
958 (setq strokes value)))
959 (setq attributes (delq 'cns-strokes attributes))
961 (when (and (memq 'shinjigen-1-radical attributes)
962 (setq value (get-char-attribute char 'shinjigen-1-radical)))
963 (unless (eq value radical)
964 (insert (format "(shinjigen-1-radical . %S)\t; %c%s"
966 (ideographic-radical value)
969 (setq radical value)))
970 (setq attributes (delq 'shinjigen-1-radical attributes))
972 (when (and (memq 'ideographic- attributes)
973 (setq value (get-char-attribute char 'ideographic-)))
974 (insert "(ideographic- ")
975 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
978 (setq cell (car value))
980 (setq cell (decode-char '=ucs cell)))
981 (cond ((characterp cell)
985 (insert (format "%S" cell))
986 (char-db-insert-char-spec cell readable))
987 (setq separator lbs))
991 (if (consp (car cell))
992 (char-db-insert-char-spec cell readable)
993 (char-db-insert-char-reference cell readable))
994 (setq separator lbs))
998 (insert (prin1-to-string cell))
999 (setq separator " ")))
1000 (setq value (cdr value)))
1002 (insert line-breaking)
1003 (setq attributes (delq 'ideographic- attributes)))
1004 (when (and (memq 'total-strokes attributes)
1005 (setq value (get-char-attribute char 'total-strokes)))
1006 (insert (format "(total-strokes . %S)%s"
1009 (setq attributes (delq 'total-strokes attributes))
1011 (when (and (memq '->ideograph attributes)
1012 (setq value (get-char-attribute char '->ideograph)))
1013 (insert (format "(->ideograph\t%s)%s"
1014 (mapconcat (lambda (code)
1015 (cond ((symbolp code)
1018 (format "#x%04X" code))
1021 line-breaking code))))
1024 (setq attributes (delq '->ideograph attributes))
1026 ;; (when (and (memq '->decomposition attributes)
1027 ;; (setq value (get-char-attribute char '->decomposition)))
1028 ;; (insert (format "(->decomposition\t%s)%s"
1029 ;; (mapconcat (lambda (code)
1030 ;; (cond ((symbolp code)
1031 ;; (symbol-name code))
1032 ;; ((characterp code)
1034 ;; (format "%S" code)
1039 ;; (format "#x%04X" code))
1041 ;; (format "%s%S" line-breaking code))))
1044 ;; (setq attributes (delq '->decomposition attributes))
1046 (if (equal (get-char-attribute char '->titlecase)
1047 (get-char-attribute char '->uppercase))
1048 (setq attributes (delq '->titlecase attributes)))
1049 (when (and (memq '->mojikyo attributes)
1050 (setq value (get-char-attribute char '->mojikyo)))
1051 (insert (format "(->mojikyo\t\t. %06d)\t; %c%s"
1052 value (decode-char 'mojikyo value)
1054 (setq attributes (delq '->mojikyo attributes))
1056 (when (and (memq 'hanyu-dazidian-vol attributes)
1057 (setq value (get-char-attribute char 'hanyu-dazidian-vol)))
1058 (insert (format "(hanyu-dazidian-vol . %d)%s"
1059 value line-breaking))
1060 (setq attributes (delq 'hanyu-dazidian-vol attributes))
1062 (when (and (memq 'hanyu-dazidian-page attributes)
1063 (setq value (get-char-attribute char 'hanyu-dazidian-page)))
1064 (insert (format "(hanyu-dazidian-page . %d)%s"
1065 value line-breaking))
1066 (setq attributes (delq 'hanyu-dazidian-page attributes))
1068 (when (and (memq 'hanyu-dazidian-char attributes)
1069 (setq value (get-char-attribute char 'hanyu-dazidian-char)))
1070 (insert (format "(hanyu-dazidian-char . %d)%s"
1071 value line-breaking))
1072 (setq attributes (delq 'hanyu-dazidian-char attributes))
1075 (dolist (ignored '(composition
1076 ->denotational <-subsumptive ->ucs-unified
1077 ->ideographic-component-forms))
1078 (setq attributes (delq ignored attributes))))
1080 (setq name (car attributes))
1081 (if (setq value (get-char-attribute char name))
1082 (cond ((setq ret (find-charset name))
1083 (setq name (charset-name ret))
1084 (if (and (not (memq name dest-ccss))
1086 (setq value (get-char-attribute char name))
1087 (setq dest-ccss (cons name dest-ccss))))
1088 (char-db-insert-ccs-feature name value line-breaking))
1090 ((string-match "^=>ucs@" (symbol-name name))
1091 (insert (format "(%-18s . #x%04X)\t; %c%s"
1092 name value (decode-char '=ucs value)
1095 ((eq name 'jisx0208-1978/4X)
1096 (insert (format "(%-18s . #x%04X)%s"
1102 (not (eq name '->subsumptive))
1103 (not (eq name '->uppercase))
1104 (not (eq name '->lowercase))
1105 (not (eq name '->titlecase))
1106 (not (eq name '->canonical))
1107 (not (eq name '->Bopomofo))
1108 (not (eq name '->mistakable))
1109 (not (eq name '->ideographic-variants))
1110 (null (get-char-attribute
1111 char (intern (format "%s*sources" name))))
1112 (not (string-match "\\*sources$" (symbol-name name)))
1113 (null (get-char-attribute
1114 char (intern (format "%s*note" name))))
1115 (not (string-match "\\*note$" (symbol-name name)))
1116 (or (eq name '<-identical)
1117 (eq name '<-uppercase)
1118 (eq name '<-lowercase)
1119 (eq name '<-titlecase)
1120 (eq name '<-canonical)
1121 (eq name '<-ideographic-variants)
1122 ;; (eq name '<-synonyms)
1123 (string-match "^<-synonyms" (symbol-name name))
1124 (eq name '<-mistakable)
1125 (when (string-match "^->" (symbol-name name))
1127 ((string-match "^->fullwidth" (symbol-name name))
1128 (not (and (consp value)
1129 (characterp (car value))
1131 (car value) '=ucs 'defined-only)))
1136 ((or (eq name 'ideographic-structure)
1137 (eq name 'ideographic-combination)
1138 (eq name 'ideographic-)
1139 (eq name '=decomposition)
1140 (string-match "^=>decomposition" (symbol-name name))
1141 (string-match "^\\(->\\|<-\\)[^*]*$" (symbol-name name))
1142 (string-match "^\\(->\\|<-\\)[^*]*\\*sources$"
1145 (char-db-insert-relation-feature char name value
1148 ((memq name '(ideograph=
1149 original-ideograph-of
1150 ancient-ideograph-of
1153 ;; simplified-ideograph-of
1154 ideographic-variants
1155 ;; ideographic-different-form-of
1157 (insert (format "(%-18s%s " name line-breaking))
1158 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1160 (while (consp value)
1161 (setq cell (car value))
1162 (if (and (consp cell)
1167 (char-db-insert-alist cell readable)
1168 (setq separator lbs))
1171 (insert (prin1-to-string cell))
1172 (setq separator " "))
1173 (setq value (cdr value)))
1175 (insert line-breaking))
1177 (insert (format "(%-18s " name))
1178 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1180 (while (consp value)
1181 (setq cell (car value))
1182 (if (and (consp cell)
1184 (setq ret (condition-case nil
1192 (setq key (car (car rest)))
1193 (if (find-charset key)
1194 (setq cal (cons key cal))
1195 (setq al (cons key al)))
1196 (setq rest (cdr rest)))
1199 (insert-char-attributes ret
1202 (setq separator lbs))
1203 (setq ret (prin1-to-string cell))
1205 (if (< (+ (current-column)
1212 (setq separator " "))
1213 (setq value (cdr value)))
1215 (insert line-breaking))
1217 (insert (format "(%-18s" name))
1218 (setq ret (prin1-to-string value))
1219 (unless (< (+ (current-column)
1223 (insert line-breaking))
1224 (insert " . " ret ")" line-breaking)
1225 ;; (insert (format "(%-18s . %S)%s"
1230 (setq attributes (cdr attributes)))
1233 (defun insert-char-data (char &optional readable
1236 (narrow-to-region (point)(point))
1237 (insert "(define-char
1239 (insert-char-attributes char readable attributes)
1241 (goto-char (point-min))
1242 (while (re-search-forward "[ \t]+$" nil t)
1245 (goto-char (point-min))
1246 (while (re-search-forward "[ \t][ \t][ \t]*" nil t)
1247 (let ((column (current-column))
1248 (indent-tabs-mode t))
1249 (delete-region (match-beginning 0) (point))
1250 (indent-to column)))
1251 (goto-char (point-max))
1252 ;; (tabify (point-min)(point-max))
1255 (defun insert-char-data-with-variant (char &optional printable
1257 script excluded-script)
1258 (insert-char-data char printable)
1259 (let ((variants (char-variants char))
1262 (setq variants (sort variants #'<))
1263 (setq rest variants)
1264 (setq variants (cons char variants))
1266 (setq variant (car rest))
1267 (unless (get-char-attribute variant '<-subsumptive)
1268 (if (and (or (null script)
1269 (null (setq vs (get-char-attribute variant 'script)))
1271 (or (null excluded-script)
1272 (null (setq vs (get-char-attribute variant 'script)))
1273 (not (memq excluded-script vs))))
1274 (unless (and no-ucs-unified (get-char-attribute variant '=ucs))
1275 (insert-char-data variant printable)
1276 (if (setq ret (char-variants variant))
1278 (or (memq (car ret) variants)
1279 ;; (get-char-attribute (car ret) '<-subsumptive)
1280 (setq rest (nconc rest (list (car ret)))))
1281 (setq ret (cdr ret)))))))
1282 (setq rest (cdr rest)))))
1284 (defun insert-char-range-data (min max &optional script excluded-script)
1287 (while (<= code max)
1288 (setq char (decode-char '=ucs code))
1289 (if (encode-char char '=ucs 'defined-only)
1290 (insert-char-data-with-variant char nil 'no-ucs-unified
1291 script excluded-script))
1292 (setq code (1+ code)))))
1294 (defun write-char-range-data-to-file (min max file
1295 &optional script excluded-script)
1296 (let ((coding-system-for-write char-db-file-coding-system))
1298 (insert (format ";; -*- coding: %s -*-\n"
1299 char-db-file-coding-system))
1300 (insert-char-range-data min max script excluded-script)
1301 (write-region (point-min)(point-max) file))))
1303 (defvar what-character-original-window-configuration)
1306 (defun what-char-definition (char)
1307 (interactive (list (char-after)))
1308 (let ((buf (get-buffer-create "*Character Description*"))
1309 (the-buf (current-buffer))
1310 (win-conf (current-window-configuration)))
1312 (make-local-variable 'what-character-original-window-configuration)
1313 (setq what-character-original-window-configuration win-conf)
1314 (setq buffer-read-only nil)
1318 (insert-char-data-with-variant char 'printable)
1319 (unless (char-attribute-alist char)
1320 (insert (format ";; = %c\n"
1321 (let* ((rest (split-char char))
1325 (setq code (logior (lsh code 8)
1327 (decode-char ccs code)))))
1328 ;; (char-db-update-comment)
1329 (set-buffer-modified-p nil)
1330 (view-mode the-buf (lambda (buf)
1331 (set-window-configuration
1332 what-character-original-window-configuration)
1334 (goto-char (point-min)))
1336 (set-window-configuration
1337 what-character-original-window-configuration)
1338 (signal (car err) (cdr err)))))))
1340 (provide 'char-db-util)
1342 ;;; char-db-util.el ends here