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
265 (defun char-db-make-char-spec (char)
267 (cond ((characterp char)
268 (cond ((and (setq ret (encode-char char '=ucs 'defined-only))
269 (not (and (<= #xE000 ret)(<= ret #xF8FF))))
270 (setq char-spec (list (cons '=ucs ret)))
271 (cond ((setq ret (get-char-attribute char 'name))
272 (setq char-spec (cons (cons 'name ret) char-spec))
274 ((setq ret (get-char-attribute char 'name*))
275 (setq char-spec (cons (cons 'name* ret) char-spec))
280 (let ((rest char-db-coded-charset-priority-list)
283 (setq ccs (charset-name
284 (find-charset (car rest))))
286 (encode-char char ccs
288 (throw 'tag (cons ccs ret)))
289 (setq rest (cdr rest))))))
290 (setq char-spec (list ret))
291 (dolist (ccs (delq (car ret) (charset-list)))
292 (if (and (or (charset-iso-final-char ccs)
299 (string-match "=ucs@" (symbol-name ccs)))
300 (setq ccs (charset-name ccs))
301 (null (assq ccs char-spec))
302 (setq ret (encode-char char ccs 'defined-only)))
303 (setq char-spec (cons (cons ccs ret) char-spec))))
305 (setq char-spec (split-char char)))
306 (cond ((setq ret (get-char-attribute char 'name))
307 (setq char-spec (cons (cons 'name ret) char-spec))
309 ((setq ret (get-char-attribute char 'name*))
310 (setq char-spec (cons (cons 'name* ret) char-spec))
313 ((setq ret (get-char-attribute
314 char 'ideographic-combination))
316 (cons (cons 'ideographic-combination ret)
323 (defun char-db-insert-char-spec (char &optional readable column
326 (setq column (current-column)))
327 (let (char-spec temp-char)
328 (setq char-spec (char-db-make-char-spec char))
329 (unless (or (characterp char) ; char
331 (setq char (find-char char-spec))
333 ;; define temporary character
334 ;; Current implementation is dirty.
335 (setq temp-char (define-char (cons '(ideograph-daikanwa . 0)
337 (remove-char-attribute temp-char 'ideograph-daikanwa)
338 (setq char temp-char))
339 (insert-char-attributes char
341 (union (mapcar #'car char-spec)
344 ;; undefine temporary character
345 ;; Current implementation is dirty.
346 (setq char-spec (char-attribute-alist temp-char))
348 (remove-char-attribute temp-char (car (car char-spec)))
349 (setq char-spec (cdr char-spec))))))
351 (defun char-db-insert-alist (alist &optional readable column)
353 (setq column (current-column)))
355 (concat "\n" (make-string (1+ column) ?\ )))
359 lbs cell rest separator)
362 (setq name (car (car alist))
363 value (cdr (car alist)))
364 (cond ((eq name 'char)
366 (if (setq ret (condition-case nil
374 (setq key (car (car value)))
375 ;; (if (find-charset key)
376 ;; (setq cal (cons key cal))
377 (setq al (cons key al))
379 (setq value (cdr value)))
380 (insert-char-attributes ret
384 (insert (prin1-to-string value)))
386 (insert line-breaking))
388 (insert (format "(%-18s " name))
389 (setq lbs (concat "\n" (make-string (current-column) ?\ )))
391 (setq cell (car value))
392 (if (and (consp cell)
394 (setq ret (condition-case nil
404 (setq key (car (car rest)))
405 ;; (if (find-charset key)
406 ;; (setq cal (cons key cal))
407 (setq al (cons key al))
409 (setq rest (cdr rest)))
412 (insert-char-attributes ret
416 (setq separator lbs))
419 (insert (prin1-to-string cell))
420 (setq separator " "))
421 (setq value (cdr value)))
423 (insert line-breaking))
425 (insert (format "(%-18s . %S)%s"
428 (setq alist (cdr alist))))
431 (defun char-db-insert-char-reference (plist &optional readable column)
433 (setq column (current-column)))
435 (concat "\n" (make-string (1+ column) ?\ )))
440 (setq name (pop plist))
441 (setq value (pop plist))
442 (cond ((eq name :char)
445 (cond ((numberp value)
446 (setq value (decode-char '=ucs value)))
448 ;; (setq value (or (find-char value)
451 (char-db-insert-char-spec value readable)
452 (insert line-breaking)
455 (insert (format "%s%s\t%d ; %c%s"
458 (ideographic-radical value)
462 (insert (format "%s%s\t%S" separator name value))
463 (setq separator line-breaking)))
467 (defun char-db-decode-isolated-char (ccs code-point)
470 (cond ((eq ccs 'arabic-iso8859-6)
471 (decode-char ccs code-point))
472 ((and (memq ccs '(=gt-pj-1
483 (setq ret (decode-char ccs code-point))
484 (setq ret (encode-char ret '=gt 'defined-only)))
485 (decode-builtin-char '=gt ret))
487 (decode-builtin-char ccs code-point))))
488 (cond ((and (<= 0 (char-int ret))
489 (<= (char-int ret) #x1F))
490 (decode-char '=ucs (+ #x2400 (char-int ret))))
491 ((= (char-int ret) #x7F)
495 (defvar char-db-convert-obsolete-format t)
497 (defun char-db-insert-ccs-feature (name value line-breaking)
500 (cond ((memq name '(=shinjigen
502 =shinjigen@rev =shinjigen/+p@rev))
503 "(%-18s . %04d)\t; %c")
504 ((eq name '=shinjigen@1ed/24pr)
505 "(%-18s . %04d)\t; %c")
506 ((or (memq name '(=daikanwa
507 =daikanwa@rev1 =daikanwa@rev2
508 =gt =>>gt =>gt =gt-k =cbeta =zinbun-oracle))
509 (string-match "^=adobe-" (symbol-name name)))
510 "(%-18s . %05d)\t; %c")
512 "(%-18s . %06d)\t; %c")
513 ((>= (charset-dimension name) 2)
514 "(%-18s . #x%04X)\t; %c")
516 "(%-18s . #x%02X)\t; %c"))
518 (if (= (charset-iso-graphic-plane name) 1)
520 (cond ((= (charset-dimension name) 1)
522 ((= (charset-dimension name) 2)
524 ((= (charset-dimension name) 3)
528 (char-db-decode-isolated-char name value)))
529 (if (and (= (charset-chars name) 94)
530 (= (charset-dimension name) 2))
531 (insert (format " [%02d-%02d]"
532 (- (lsh value -8) 32)
533 (- (logand value 255) 32))))
534 (insert line-breaking))
536 (defun char-db-insert-relation-feature (char name value line-breaking
538 (insert (format "(%-18s%s " name line-breaking))
539 (let ((lbs (concat "\n" (make-string (current-column) ?\ )))
540 separator cell sources required-features
543 (setq cell (car value))
545 (setq cell (decode-char '=ucs cell)))
547 ((eq name '->subsumptive)
548 (when (or (not (some (lambda (atr)
549 (get-char-attribute cell atr))
550 char-db-ignored-attributes))
552 (encode-char cell ccs 'defined-only))
556 (let ((char-db-ignored-attributes
558 char-db-ignored-attributes)))
559 (insert-char-attributes cell readable))
560 (setq separator lbs))
565 char (intern (format "%s*sources" name))))
566 (setq required-features nil)
567 (dolist (source sources)
571 shinjigen shinjigen@1ed shinjigen@rev))
572 (setq required-features
573 (union required-features
583 (setq required-features
584 (union required-features
589 ((find-charset (setq ret (intern (format "=%s" source))))
590 (setq required-features
591 (cons ret required-features)))
592 (t (setq required-features
593 (cons source required-features)))))
594 (cond ((string-match "@JP" (symbol-name name))
595 (setq required-features
596 (union required-features
604 ((string-match "@CN" (symbol-name name))
605 (setq required-features
606 (union required-features
613 (insert (format "%S" cell))
614 (char-db-insert-char-spec cell readable
617 (setq separator lbs))
621 (if (consp (car cell))
622 (char-db-insert-char-spec cell readable)
623 (char-db-insert-char-reference cell readable))
624 (setq separator lbs))
628 (insert (prin1-to-string cell))
629 (setq separator " ")))
630 (setq value (cdr value)))
632 (insert line-breaking)))
634 (defun insert-char-attributes (char &optional readable attributes column)
636 (setq column (current-column)))
637 (let (name value ; has-long-ccs-name
641 (concat "\n" (make-string (1+ column) ?\ )))
642 lbs cell separator ret
644 dest-ccss ; sources required-features
649 (if (consp attributes)
651 (dolist (name attributes)
652 (unless (memq name char-db-ignored-attributes)
653 (if (find-charset name)
657 (dolist (name (char-attribute-list))
658 (unless (memq name char-db-ignored-attributes)
659 (if (find-charset name)
663 #'char-attribute-name<)))
665 (when (memq '<-subsumptive attributes)
667 (when (setq value (get-char-attribute char '<-subsumptive))
668 (char-db-insert-relation-feature char '<-subsumptive value
671 (setq attributes (delq '<-subsumptive attributes)))
672 (when (and (memq '<-denotational attributes)
673 (setq value (get-char-attribute char '<-denotational)))
674 (char-db-insert-relation-feature char '<-denotational value
677 (setq attributes (delq '<-denotational attributes)))
678 (when (and (memq 'name attributes)
679 (setq value (get-char-attribute char 'name)))
681 (if (> (+ (current-column) (length value)) 48)
684 value line-breaking))
685 (setq attributes (delq 'name attributes))
687 (when (and (memq 'name* attributes)
688 (setq value (get-char-attribute char 'name*)))
690 (if (> (+ (current-column) (length value)) 48)
693 value line-breaking))
694 (setq attributes (delq 'name* attributes))
696 (when (and (memq 'script attributes)
697 (setq value (get-char-attribute char 'script)))
698 (insert (format "(script\t\t%s)%s"
699 (mapconcat (function prin1-to-string)
702 (setq attributes (delq 'script attributes))
704 (dolist (name '(=>ucs =>ucs*))
705 (when (and (memq name attributes)
706 (setq value (get-char-attribute char name)))
707 (insert (format "(%-18s . #x%04X)\t; %c%s"
708 name value (decode-char '=ucs value)
710 (setq attributes (delq name attributes))))
711 (dolist (name '(=>ucs@gb =>ucs@cns =>ucs@jis =>ucs@ks =>ucs@big5))
712 (when (and (memq name attributes)
713 (setq value (get-char-attribute char name)))
714 (insert (format "(%-18s . #x%04X)\t; %c%s"
719 (symbol-name name) 2)))
722 (setq attributes (delq name attributes))
724 (dolist (name '(=>daikanwa))
725 (when (and (memq name attributes)
726 (setq value (get-char-attribute char name)))
729 (format "(%-18s . %05d)\t; %c%s"
730 name value (decode-char '=daikanwa value)
732 (format "(%-18s %s)\t; %c%s"
734 (mapconcat (function prin1-to-string)
736 (char-representative-of-daikanwa char)
738 (setq attributes (delq name attributes))))
739 (when (and (memq 'general-category attributes)
740 (setq value (get-char-attribute char 'general-category)))
742 "(general-category\t%s) ; %s%s"
743 (mapconcat (lambda (cell)
746 (cond ((rassoc value unidata-normative-category-alist)
747 "Normative Category")
748 ((rassoc value unidata-informative-category-alist)
749 "Informative Category")
753 (setq attributes (delq 'general-category attributes))
755 (when (and (memq 'bidi-category attributes)
756 (setq value (get-char-attribute char 'bidi-category)))
757 (insert (format "(bidi-category\t. %S)%s"
760 (setq attributes (delq 'bidi-category attributes))
762 (unless (or (not (memq 'mirrored attributes))
763 (eq (setq value (get-char-attribute char 'mirrored 'empty))
765 (insert (format "(mirrored\t\t. %S)%s"
768 (setq attributes (delq 'mirrored attributes))
771 ((and (memq 'decimal-digit-value attributes)
772 (setq value (get-char-attribute char 'decimal-digit-value)))
773 (insert (format "(decimal-digit-value . %S)%s"
776 (setq attributes (delq 'decimal-digit-value attributes))
777 (when (and (memq 'digit-value attributes)
778 (setq value (get-char-attribute char 'digit-value)))
779 (insert (format "(digit-value\t . %S)%s"
782 (setq attributes (delq 'digit-value attributes))
784 (when (and (memq 'numeric-value attributes)
785 (setq value (get-char-attribute char 'numeric-value)))
786 (insert (format "(numeric-value\t . %S)%s"
789 (setq attributes (delq 'numeric-value attributes))
793 (when (and (memq 'digit-value attributes)
794 (setq value (get-char-attribute char 'digit-value)))
795 (insert (format "(digit-value\t. %S)%s"
798 (setq attributes (delq 'digit-value attributes))
800 (when (and (memq 'numeric-value attributes)
801 (setq value (get-char-attribute char 'numeric-value)))
802 (insert (format "(numeric-value\t. %S)%s"
805 (setq attributes (delq 'numeric-value attributes))
807 (when (and (memq 'iso-10646-comment attributes)
808 (setq value (get-char-attribute char 'iso-10646-comment)))
809 (insert (format "(iso-10646-comment\t. %S)%s"
812 (setq attributes (delq 'iso-10646-comment attributes))
814 (when (and (memq 'morohashi-daikanwa attributes)
815 (setq value (get-char-attribute char 'morohashi-daikanwa)))
816 (insert (format "(morohashi-daikanwa\t%s)%s"
817 (mapconcat (function prin1-to-string) value " ")
819 (setq attributes (delq 'morohashi-daikanwa attributes))
823 (when (and (memq 'ideographic-radical attributes)
824 (setq value (get-char-attribute char 'ideographic-radical)))
826 (insert (format "(ideographic-radical . %S)\t; %c%s"
828 (ideographic-radical radical)
830 (setq attributes (delq 'ideographic-radical attributes))
832 (when (and (memq 'shuowen-radical attributes)
833 (setq value (get-char-attribute char 'shuowen-radical)))
834 (insert (format "(shuowen-radical\t. %S)\t; %c%s"
836 (shuowen-radical value)
838 (setq attributes (delq 'shuowen-radical attributes))
843 char-db-feature-domains
845 (dolist (feature (char-attribute-list))
846 (setq feature (symbol-name feature))
848 "\\(radical\\|strokes\\)@\\([^@*]+\\)\\(\\*\\|$\\)"
850 (setq domain (intern (match-string 2 feature)))
851 (unless (memq domain dest)
852 (setq dest (cons domain dest)))))
853 (sort dest #'string<))))
854 (setq key (intern (format "%s@%s" 'ideographic-radical domain)))
855 (when (and (memq key attributes)
856 (setq value (get-char-attribute char key)))
858 (insert (format "(%s . %S)\t; %c%s"
861 (ideographic-radical radical)
863 (setq attributes (delq key attributes))
865 (setq key (intern (format "%s@%s" 'ideographic-strokes domain)))
866 (when (and (memq key attributes)
867 (setq value (get-char-attribute char key)))
869 (insert (format "(%s . %S)%s"
873 (setq attributes (delq key attributes))
875 (setq key (intern (format "%s@%s" 'total-strokes domain)))
876 (when (and (memq key attributes)
877 (setq value (get-char-attribute char key)))
878 (insert (format "(%s . %S)%s"
882 (setq attributes (delq key attributes))
884 (dolist (feature '(ideographic-radical
887 (setq key (intern (format "%s@%s*sources" feature domain)))
888 (when (and (memq key attributes)
889 (setq value (get-char-attribute char key)))
890 (insert (format "(%s%s" key line-breaking))
892 (insert (format " %s" cell)))
894 (insert line-breaking)
895 (setq attributes (delq key attributes))
898 (when (and (memq 'ideographic-strokes attributes)
899 (setq value (get-char-attribute char 'ideographic-strokes)))
901 (insert (format "(ideographic-strokes . %S)%s"
904 (setq attributes (delq 'ideographic-strokes attributes))
906 (when (and (memq 'kangxi-radical attributes)
907 (setq value (get-char-attribute char 'kangxi-radical)))
908 (unless (eq value radical)
909 (insert (format "(kangxi-radical\t . %S)\t; %c%s"
911 (ideographic-radical value)
914 (setq radical value)))
915 (setq attributes (delq 'kangxi-radical attributes))
917 (when (and (memq 'kangxi-strokes attributes)
918 (setq value (get-char-attribute char 'kangxi-strokes)))
919 (unless (eq value strokes)
920 (insert (format "(kangxi-strokes\t . %S)%s"
924 (setq strokes value)))
925 (setq attributes (delq 'kangxi-strokes attributes))
927 (when (and (memq 'japanese-radical attributes)
928 (setq value (get-char-attribute char 'japanese-radical)))
929 (unless (eq value radical)
930 (insert (format "(japanese-radical\t . %S)\t; %c%s"
932 (ideographic-radical value)
935 (setq radical value)))
936 (setq attributes (delq 'japanese-radical attributes))
938 (when (and (memq 'japanese-strokes attributes)
939 (setq value (get-char-attribute char 'japanese-strokes)))
940 (unless (eq value strokes)
941 (insert (format "(japanese-strokes\t . %S)%s"
945 (setq strokes value)))
946 (setq attributes (delq 'japanese-strokes attributes))
948 (when (and (memq 'cns-radical attributes)
949 (setq value (get-char-attribute char 'cns-radical)))
950 (insert (format "(cns-radical\t . %S)\t; %c%s"
952 (ideographic-radical value)
954 (setq attributes (delq 'cns-radical attributes))
956 (when (and (memq 'cns-strokes attributes)
957 (setq value (get-char-attribute char 'cns-strokes)))
958 (unless (eq value strokes)
959 (insert (format "(cns-strokes\t . %S)%s"
963 (setq strokes value)))
964 (setq attributes (delq 'cns-strokes attributes))
966 (when (and (memq 'shinjigen-1-radical attributes)
967 (setq value (get-char-attribute char 'shinjigen-1-radical)))
968 (unless (eq value radical)
969 (insert (format "(shinjigen-1-radical . %S)\t; %c%s"
971 (ideographic-radical value)
974 (setq radical value)))
975 (setq attributes (delq 'shinjigen-1-radical attributes))
977 (when (and (memq 'ideographic- attributes)
978 (setq value (get-char-attribute char 'ideographic-)))
979 (insert "(ideographic- ")
980 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
983 (setq cell (car value))
985 (setq cell (decode-char '=ucs cell)))
986 (cond ((characterp cell)
990 (insert (format "%S" cell))
991 (char-db-insert-char-spec cell readable))
992 (setq separator lbs))
996 (if (consp (car cell))
997 (char-db-insert-char-spec cell readable)
998 (char-db-insert-char-reference cell readable))
999 (setq separator lbs))
1003 (insert (prin1-to-string cell))
1004 (setq separator " ")))
1005 (setq value (cdr value)))
1007 (insert line-breaking)
1008 (setq attributes (delq 'ideographic- attributes)))
1009 (when (and (memq 'total-strokes attributes)
1010 (setq value (get-char-attribute char 'total-strokes)))
1011 (insert (format "(total-strokes . %S)%s"
1014 (setq attributes (delq 'total-strokes attributes))
1016 (when (and (memq '->ideograph attributes)
1017 (setq value (get-char-attribute char '->ideograph)))
1018 (insert (format "(->ideograph\t%s)%s"
1019 (mapconcat (lambda (code)
1020 (cond ((symbolp code)
1023 (format "#x%04X" code))
1026 line-breaking code))))
1029 (setq attributes (delq '->ideograph attributes))
1031 ;; (when (and (memq '->decomposition attributes)
1032 ;; (setq value (get-char-attribute char '->decomposition)))
1033 ;; (insert (format "(->decomposition\t%s)%s"
1034 ;; (mapconcat (lambda (code)
1035 ;; (cond ((symbolp code)
1036 ;; (symbol-name code))
1037 ;; ((characterp code)
1039 ;; (format "%S" code)
1044 ;; (format "#x%04X" code))
1046 ;; (format "%s%S" line-breaking code))))
1049 ;; (setq attributes (delq '->decomposition attributes))
1051 (if (equal (get-char-attribute char '->titlecase)
1052 (get-char-attribute char '->uppercase))
1053 (setq attributes (delq '->titlecase attributes)))
1054 (when (and (memq '->mojikyo attributes)
1055 (setq value (get-char-attribute char '->mojikyo)))
1056 (insert (format "(->mojikyo\t\t. %06d)\t; %c%s"
1057 value (decode-char 'mojikyo value)
1059 (setq attributes (delq '->mojikyo attributes))
1061 (when (and (memq 'hanyu-dazidian-vol attributes)
1062 (setq value (get-char-attribute char 'hanyu-dazidian-vol)))
1063 (insert (format "(hanyu-dazidian-vol . %d)%s"
1064 value line-breaking))
1065 (setq attributes (delq 'hanyu-dazidian-vol attributes))
1067 (when (and (memq 'hanyu-dazidian-page attributes)
1068 (setq value (get-char-attribute char 'hanyu-dazidian-page)))
1069 (insert (format "(hanyu-dazidian-page . %d)%s"
1070 value line-breaking))
1071 (setq attributes (delq 'hanyu-dazidian-page attributes))
1073 (when (and (memq 'hanyu-dazidian-char attributes)
1074 (setq value (get-char-attribute char 'hanyu-dazidian-char)))
1075 (insert (format "(hanyu-dazidian-char . %d)%s"
1076 value line-breaking))
1077 (setq attributes (delq 'hanyu-dazidian-char attributes))
1080 (dolist (ignored '(composition
1081 ->denotational <-subsumptive ->ucs-unified
1082 ->ideographic-component-forms))
1083 (setq attributes (delq ignored attributes))))
1085 (setq name (car attributes))
1086 (if (setq value (get-char-attribute char name))
1087 (cond ((setq ret (find-charset name))
1088 (setq name (charset-name ret))
1089 (if (and (not (memq name dest-ccss))
1091 (setq value (get-char-attribute char name))
1092 (setq dest-ccss (cons name dest-ccss))))
1093 (char-db-insert-ccs-feature name value line-breaking))
1095 ((string-match "^=>ucs@" (symbol-name name))
1096 (insert (format "(%-18s . #x%04X)\t; %c%s"
1097 name value (decode-char '=ucs value)
1100 ((eq name 'jisx0208-1978/4X)
1101 (insert (format "(%-18s . #x%04X)%s"
1107 (not (eq name '->subsumptive))
1108 (not (eq name '->uppercase))
1109 (not (eq name '->lowercase))
1110 (not (eq name '->titlecase))
1111 (not (eq name '->canonical))
1112 (not (eq name '->Bopomofo))
1113 (not (eq name '->mistakable))
1114 (not (eq name '->ideographic-variants))
1115 (null (get-char-attribute
1116 char (intern (format "%s*sources" name))))
1117 (not (string-match "\\*sources$" (symbol-name name)))
1118 (null (get-char-attribute
1119 char (intern (format "%s*note" name))))
1120 (not (string-match "\\*note$" (symbol-name name)))
1121 (or (eq name '<-identical)
1122 (eq name '<-uppercase)
1123 (eq name '<-lowercase)
1124 (eq name '<-titlecase)
1125 (eq name '<-canonical)
1126 (eq name '<-ideographic-variants)
1127 ;; (eq name '<-synonyms)
1128 (string-match "^<-synonyms" (symbol-name name))
1129 (eq name '<-mistakable)
1130 (when (string-match "^->" (symbol-name name))
1132 ((string-match "^->fullwidth" (symbol-name name))
1133 (not (and (consp value)
1134 (characterp (car value))
1136 (car value) '=ucs 'defined-only)))
1141 ((or (eq name 'ideographic-structure)
1142 (eq name 'ideographic-combination)
1143 (eq name 'ideographic-)
1144 (eq name '=decomposition)
1145 (string-match "^=>decomposition" (symbol-name name))
1146 (string-match "^\\(->\\|<-\\)[^*]*$" (symbol-name name))
1147 (string-match "^\\(->\\|<-\\)[^*]*\\*sources$"
1150 (char-db-insert-relation-feature char name value
1153 ((memq name '(ideograph=
1154 original-ideograph-of
1155 ancient-ideograph-of
1158 ;; simplified-ideograph-of
1159 ideographic-variants
1160 ;; ideographic-different-form-of
1162 (insert (format "(%-18s%s " name line-breaking))
1163 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1165 (while (consp value)
1166 (setq cell (car value))
1167 (if (and (consp cell)
1172 (char-db-insert-alist cell readable)
1173 (setq separator lbs))
1176 (insert (prin1-to-string cell))
1177 (setq separator " "))
1178 (setq value (cdr value)))
1180 (insert line-breaking))
1182 (insert (format "(%-18s " name))
1183 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1185 (while (consp value)
1186 (setq cell (car value))
1187 (if (and (consp cell)
1189 (setq ret (condition-case nil
1197 (setq key (car (car rest)))
1198 (if (find-charset key)
1199 (setq cal (cons key cal))
1200 (setq al (cons key al)))
1201 (setq rest (cdr rest)))
1204 (insert-char-attributes ret
1207 (setq separator lbs))
1208 (setq ret (prin1-to-string cell))
1210 (if (< (+ (current-column)
1217 (setq separator " "))
1218 (setq value (cdr value)))
1220 (insert line-breaking))
1222 (insert (format "(%-18s" name))
1223 (setq ret (prin1-to-string value))
1224 (unless (< (+ (current-column)
1228 (insert line-breaking))
1229 (insert " . " ret ")" line-breaking)
1230 ;; (insert (format "(%-18s . %S)%s"
1235 (setq attributes (cdr attributes)))
1238 (defun insert-char-data (char &optional readable
1241 (narrow-to-region (point)(point))
1242 (insert "(define-char
1244 (insert-char-attributes char readable attributes)
1246 (goto-char (point-min))
1247 (while (re-search-forward "[ \t]+$" nil t)
1250 (goto-char (point-min))
1251 (while (re-search-forward "[ \t][ \t][ \t]*" nil t)
1252 (let ((column (current-column))
1253 (indent-tabs-mode t))
1254 (delete-region (match-beginning 0) (point))
1255 (indent-to column)))
1256 (goto-char (point-max))
1257 ;; (tabify (point-min)(point-max))
1260 (defun insert-char-data-with-variant (char &optional printable
1262 script excluded-script)
1263 (insert-char-data char printable)
1264 (let ((variants (char-variants char))
1267 (setq variants (sort variants #'<))
1268 (setq rest variants)
1269 (setq variants (cons char variants))
1271 (setq variant (car rest))
1272 (unless (get-char-attribute variant '<-subsumptive)
1273 (if (and (or (null script)
1274 (null (setq vs (get-char-attribute variant 'script)))
1276 (or (null excluded-script)
1277 (null (setq vs (get-char-attribute variant 'script)))
1278 (not (memq excluded-script vs))))
1279 (unless (and no-ucs-unified (get-char-attribute variant '=ucs))
1280 (insert-char-data variant printable)
1281 (if (setq ret (char-variants variant))
1283 (or (memq (car ret) variants)
1284 ;; (get-char-attribute (car ret) '<-subsumptive)
1285 (setq rest (nconc rest (list (car ret)))))
1286 (setq ret (cdr ret)))))))
1287 (setq rest (cdr rest)))))
1289 (defun insert-char-range-data (min max &optional script excluded-script)
1292 (while (<= code max)
1293 (setq char (decode-char '=ucs code))
1294 (if (encode-char char '=ucs 'defined-only)
1295 (insert-char-data-with-variant char nil 'no-ucs-unified
1296 script excluded-script))
1297 (setq code (1+ code)))))
1299 (defun write-char-range-data-to-file (min max file
1300 &optional script excluded-script)
1301 (let ((coding-system-for-write char-db-file-coding-system))
1303 (insert (format ";; -*- coding: %s -*-\n"
1304 char-db-file-coding-system))
1305 (insert-char-range-data min max script excluded-script)
1306 (write-region (point-min)(point-max) file))))
1308 (defvar what-character-original-window-configuration)
1311 (defun what-char-definition (char)
1312 (interactive (list (char-after)))
1313 (let ((buf (get-buffer-create "*Character Description*"))
1314 (the-buf (current-buffer))
1315 (win-conf (current-window-configuration)))
1317 (make-local-variable 'what-character-original-window-configuration)
1318 (setq what-character-original-window-configuration win-conf)
1319 (setq buffer-read-only nil)
1323 (insert-char-data-with-variant char 'printable)
1324 (unless (char-attribute-alist char)
1325 (insert (format ";; = %c\n"
1326 (let* ((rest (split-char char))
1330 (setq code (logior (lsh code 8)
1332 (decode-char ccs code)))))
1333 ;; (char-db-update-comment)
1334 (set-buffer-modified-p nil)
1335 (view-mode the-buf (lambda (buf)
1336 (set-window-configuration
1337 what-character-original-window-configuration)
1339 (goto-char (point-min)))
1341 (set-window-configuration
1342 what-character-original-window-configuration)
1343 (signal (car err) (cdr err)))))))
1345 (provide 'char-db-util)
1347 ;;; char-db-util.el ends here