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)))
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
263 (defun char-db-make-char-spec (char)
265 (cond ((characterp char)
266 (cond ((and (setq ret (encode-char char '=ucs 'defined-only))
267 (not (and (<= #xE000 ret)(<= ret #xF8FF))))
268 (setq char-spec (list (cons '=ucs ret)))
269 (cond ((setq ret (get-char-attribute char 'name))
270 (setq char-spec (cons (cons 'name ret) char-spec))
272 ((setq ret (get-char-attribute char 'name*))
273 (setq char-spec (cons (cons 'name* ret) char-spec))
278 (let ((rest char-db-coded-charset-priority-list)
281 (setq ccs (charset-name
282 (find-charset (car rest))))
284 (encode-char char ccs
286 (throw 'tag (cons ccs ret)))
287 (setq rest (cdr rest))))))
288 (setq char-spec (list ret))
289 (dolist (ccs (delq (car ret) (charset-list)))
290 (if (and (or (charset-iso-final-char ccs)
297 (string-match "=ucs@" (symbol-name ccs)))
298 (setq ccs (charset-name ccs))
299 (null (assq ccs char-spec))
300 (setq ret (encode-char char ccs 'defined-only)))
301 (setq char-spec (cons (cons ccs ret) char-spec))))
303 (setq char-spec (split-char char)))
304 (cond ((setq ret (get-char-attribute char 'name))
305 (setq char-spec (cons (cons 'name ret) char-spec))
307 ((setq ret (get-char-attribute char 'name*))
308 (setq char-spec (cons (cons 'name* ret) char-spec))
311 ((setq ret (get-char-attribute
312 char 'ideographic-combination))
314 (cons (cons 'ideographic-combination ret)
321 (defun char-db-insert-char-spec (char &optional readable column
324 (setq column (current-column)))
325 (let (char-spec temp-char)
326 (setq char-spec (char-db-make-char-spec char))
327 (unless (or (characterp char) ; char
329 (setq char (find-char char-spec))
331 ;; define temporary character
332 ;; Current implementation is dirty.
333 (setq temp-char (define-char (cons '(ideograph-daikanwa . 0)
335 (remove-char-attribute temp-char 'ideograph-daikanwa)
336 (setq char temp-char))
337 (insert-char-attributes char
339 (union (mapcar #'car char-spec)
342 ;; undefine temporary character
343 ;; Current implementation is dirty.
344 (setq char-spec (char-attribute-alist temp-char))
346 (remove-char-attribute temp-char (car (car char-spec)))
347 (setq char-spec (cdr char-spec))))))
349 (defun char-db-insert-alist (alist &optional readable column)
351 (setq column (current-column)))
353 (concat "\n" (make-string (1+ column) ?\ )))
357 lbs cell rest separator)
360 (setq name (car (car alist))
361 value (cdr (car alist)))
362 (cond ((eq name 'char)
364 (if (setq ret (condition-case nil
372 (setq key (car (car value)))
373 ;; (if (find-charset key)
374 ;; (setq cal (cons key cal))
375 (setq al (cons key al))
377 (setq value (cdr value)))
378 (insert-char-attributes ret
382 (insert (prin1-to-string value)))
384 (insert line-breaking))
386 (insert (format "(%-18s " name))
387 (setq lbs (concat "\n" (make-string (current-column) ?\ )))
389 (setq cell (car value))
390 (if (and (consp cell)
392 (setq ret (condition-case nil
402 (setq key (car (car rest)))
403 ;; (if (find-charset key)
404 ;; (setq cal (cons key cal))
405 (setq al (cons key al))
407 (setq rest (cdr rest)))
410 (insert-char-attributes ret
414 (setq separator lbs))
417 (insert (prin1-to-string cell))
418 (setq separator " "))
419 (setq value (cdr value)))
421 (insert line-breaking))
423 (insert (format "(%-18s . %S)%s"
426 (setq alist (cdr alist))))
429 (defun char-db-insert-char-reference (plist &optional readable column)
431 (setq column (current-column)))
433 (concat "\n" (make-string (1+ column) ?\ )))
438 (setq name (pop plist))
439 (setq value (pop plist))
440 (cond ((eq name :char)
443 (cond ((numberp value)
444 (setq value (decode-char '=ucs value)))
446 ;; (setq value (or (find-char value)
449 (char-db-insert-char-spec value readable)
450 (insert line-breaking)
453 (insert (format "%s%s\t%d ; %c%s"
456 (ideographic-radical value)
460 (insert (format "%s%s\t%S" separator name value))
461 (setq separator line-breaking)))
465 (defun char-db-decode-isolated-char (ccs code-point)
468 (cond ((eq ccs 'arabic-iso8859-6)
469 (decode-char ccs code-point))
470 ((and (memq ccs '(=gt-pj-1
481 (setq ret (decode-char ccs code-point))
482 (setq ret (encode-char ret '=gt 'defined-only)))
483 (decode-builtin-char '=gt ret))
485 (decode-builtin-char ccs code-point))))
486 (cond ((and (<= 0 (char-int ret))
487 (<= (char-int ret) #x1F))
488 (decode-char '=ucs (+ #x2400 (char-int ret))))
489 ((= (char-int ret) #x7F)
493 (defvar char-db-convert-obsolete-format t)
495 (defun char-db-insert-ccs-feature (name value line-breaking)
498 (cond ((memq name '(=shinjigen
500 =shinjigen@rev =shinjigen/+p@rev))
501 "(%-18s . %04d)\t; %c")
502 ((eq name '=shinjigen@1ed/24pr)
503 "(%-18s . %04d)\t; %c")
504 ((or (memq name '(=daikanwa
505 =daikanwa@rev1 =daikanwa@rev2
506 =gt =>>gt =>gt =gt-k =cbeta =zinbun-oracle))
507 (string-match "^=adobe-" (symbol-name name)))
508 "(%-18s . %05d)\t; %c")
510 "(%-18s . %06d)\t; %c")
511 ((>= (charset-dimension name) 2)
512 "(%-18s . #x%04X)\t; %c")
514 "(%-18s . #x%02X)\t; %c"))
516 (if (= (charset-iso-graphic-plane name) 1)
518 (cond ((= (charset-dimension name) 1)
520 ((= (charset-dimension name) 2)
522 ((= (charset-dimension name) 3)
526 (char-db-decode-isolated-char name value)))
527 (if (and (= (charset-chars name) 94)
528 (= (charset-dimension name) 2))
529 (insert (format " [%02d-%02d]"
530 (- (lsh value -8) 32)
531 (- (logand value 255) 32))))
532 (insert line-breaking))
534 (defun char-db-insert-relation-feature (char name value line-breaking
536 (insert (format "(%-18s%s " name line-breaking))
537 (let ((lbs (concat "\n" (make-string (current-column) ?\ )))
538 separator cell sources required-features
541 (setq cell (car value))
543 (setq cell (decode-char '=ucs cell)))
545 ((eq name '->subsumptive)
546 (when (or (not (some (lambda (atr)
547 (get-char-attribute cell atr))
548 char-db-ignored-attributes))
550 (encode-char cell ccs 'defined-only))
554 (let ((char-db-ignored-attributes
556 char-db-ignored-attributes)))
557 (insert-char-attributes cell readable))
558 (setq separator lbs))
563 char (intern (format "%s*sources" name))))
564 (setq required-features nil)
565 (dolist (source sources)
569 shinjigen shinjigen@1ed shinjigen@rev))
570 (setq required-features
571 (union required-features
581 (setq required-features
582 (union required-features
587 ((find-charset (setq ret (intern (format "=%s" source))))
588 (setq required-features
589 (cons ret required-features)))
590 (t (setq required-features
591 (cons source required-features)))))
592 (cond ((string-match "@JP" (symbol-name name))
593 (setq required-features
594 (union required-features
602 ((string-match "@CN" (symbol-name name))
603 (setq required-features
604 (union required-features
611 (insert (format "%S" cell))
612 (char-db-insert-char-spec cell readable
615 (setq separator lbs))
619 (if (consp (car cell))
620 (char-db-insert-char-spec cell readable)
621 (char-db-insert-char-reference cell readable))
622 (setq separator lbs))
626 (insert (prin1-to-string cell))
627 (setq separator " ")))
628 (setq value (cdr value)))
630 (insert line-breaking)))
632 (defun insert-char-attributes (char &optional readable attributes column)
634 (setq column (current-column)))
635 (let (name value ; has-long-ccs-name
639 (concat "\n" (make-string (1+ column) ?\ )))
640 lbs cell separator ret
642 dest-ccss ; sources required-features
647 (if (consp attributes)
649 (dolist (name attributes)
650 (unless (memq name char-db-ignored-attributes)
651 (if (find-charset name)
655 (dolist (name (char-attribute-list))
656 (unless (memq name char-db-ignored-attributes)
657 (if (find-charset name)
661 #'char-attribute-name<)))
663 (when (memq '<-subsumptive attributes)
665 (when (setq value (get-char-attribute char '<-subsumptive))
666 (char-db-insert-relation-feature char '<-subsumptive value
669 (setq attributes (delq '<-subsumptive attributes)))
670 (when (and (memq '<-denotational attributes)
671 (setq value (get-char-attribute char '<-denotational)))
672 (char-db-insert-relation-feature char '<-denotational value
675 (setq attributes (delq '<-denotational attributes)))
676 (when (and (memq 'name attributes)
677 (setq value (get-char-attribute char 'name)))
679 (if (> (+ (current-column) (length value)) 48)
682 value line-breaking))
683 (setq attributes (delq 'name attributes))
685 (when (and (memq 'name* attributes)
686 (setq value (get-char-attribute char 'name*)))
688 (if (> (+ (current-column) (length value)) 48)
691 value line-breaking))
692 (setq attributes (delq 'name* attributes))
694 (when (and (memq 'script attributes)
695 (setq value (get-char-attribute char 'script)))
696 (insert (format "(script\t\t%s)%s"
697 (mapconcat (function prin1-to-string)
700 (setq attributes (delq 'script attributes))
702 (dolist (name '(=>ucs =>ucs*))
703 (when (and (memq name attributes)
704 (setq value (get-char-attribute char name)))
705 (insert (format "(%-18s . #x%04X)\t; %c%s"
706 name value (decode-char '=ucs value)
708 (setq attributes (delq name attributes))))
709 (dolist (name '(=>ucs@gb =>ucs@cns =>ucs@jis =>ucs@ks =>ucs@big5))
710 (when (and (memq name attributes)
711 (setq value (get-char-attribute char name)))
712 (insert (format "(%-18s . #x%04X)\t; %c%s"
717 (symbol-name name) 2)))
720 (setq attributes (delq name attributes))
722 (dolist (name '(=>daikanwa))
723 (when (and (memq name attributes)
724 (setq value (get-char-attribute char name)))
727 (format "(%-18s . %05d)\t; %c%s"
728 name value (decode-char '=daikanwa value)
730 (format "(%-18s %s)\t; %c%s"
732 (mapconcat (function prin1-to-string)
734 (char-representative-of-daikanwa char)
736 (setq attributes (delq name attributes))))
737 (when (and (memq 'general-category attributes)
738 (setq value (get-char-attribute char 'general-category)))
740 "(general-category\t%s) ; %s%s"
741 (mapconcat (lambda (cell)
744 (cond ((rassoc value unidata-normative-category-alist)
745 "Normative Category")
746 ((rassoc value unidata-informative-category-alist)
747 "Informative Category")
751 (setq attributes (delq 'general-category attributes))
753 (when (and (memq 'bidi-category attributes)
754 (setq value (get-char-attribute char 'bidi-category)))
755 (insert (format "(bidi-category\t. %S)%s"
758 (setq attributes (delq 'bidi-category attributes))
760 (unless (or (not (memq 'mirrored attributes))
761 (eq (setq value (get-char-attribute char 'mirrored 'empty))
763 (insert (format "(mirrored\t\t. %S)%s"
766 (setq attributes (delq 'mirrored attributes))
769 ((and (memq 'decimal-digit-value attributes)
770 (setq value (get-char-attribute char 'decimal-digit-value)))
771 (insert (format "(decimal-digit-value . %S)%s"
774 (setq attributes (delq 'decimal-digit-value attributes))
775 (when (and (memq 'digit-value attributes)
776 (setq value (get-char-attribute char 'digit-value)))
777 (insert (format "(digit-value\t . %S)%s"
780 (setq attributes (delq 'digit-value attributes))
782 (when (and (memq 'numeric-value attributes)
783 (setq value (get-char-attribute char 'numeric-value)))
784 (insert (format "(numeric-value\t . %S)%s"
787 (setq attributes (delq 'numeric-value attributes))
791 (when (and (memq 'digit-value attributes)
792 (setq value (get-char-attribute char 'digit-value)))
793 (insert (format "(digit-value\t. %S)%s"
796 (setq attributes (delq 'digit-value attributes))
798 (when (and (memq 'numeric-value attributes)
799 (setq value (get-char-attribute char 'numeric-value)))
800 (insert (format "(numeric-value\t. %S)%s"
803 (setq attributes (delq 'numeric-value attributes))
805 (when (and (memq 'iso-10646-comment attributes)
806 (setq value (get-char-attribute char 'iso-10646-comment)))
807 (insert (format "(iso-10646-comment\t. %S)%s"
810 (setq attributes (delq 'iso-10646-comment attributes))
812 (when (and (memq 'morohashi-daikanwa attributes)
813 (setq value (get-char-attribute char 'morohashi-daikanwa)))
814 (insert (format "(morohashi-daikanwa\t%s)%s"
815 (mapconcat (function prin1-to-string) value " ")
817 (setq attributes (delq 'morohashi-daikanwa attributes))
821 (when (and (memq 'ideographic-radical attributes)
822 (setq value (get-char-attribute char 'ideographic-radical)))
824 (insert (format "(ideographic-radical . %S)\t; %c%s"
826 (ideographic-radical radical)
828 (setq attributes (delq 'ideographic-radical attributes))
830 (when (and (memq 'shuowen-radical attributes)
831 (setq value (get-char-attribute char 'shuowen-radical)))
832 (insert (format "(shuowen-radical\t. %S)\t; %c%s"
834 (shuowen-radical value)
836 (setq attributes (delq 'shuowen-radical attributes))
841 char-db-feature-domains
843 (dolist (feature (char-attribute-list))
844 (setq feature (symbol-name feature))
846 "\\(radical\\|strokes\\)@\\([^@*]+\\)\\(\\*\\|$\\)"
848 (setq domain (intern (match-string 2 feature)))
849 (unless (memq domain dest)
850 (setq dest (cons domain dest)))))
851 (sort dest #'string<))))
852 (setq key (intern (format "%s@%s" 'ideographic-radical domain)))
853 (when (and (memq key attributes)
854 (setq value (get-char-attribute char key)))
856 (insert (format "(%s . %S)\t; %c%s"
859 (ideographic-radical radical)
861 (setq attributes (delq key attributes))
863 (setq key (intern (format "%s@%s" 'ideographic-strokes domain)))
864 (when (and (memq key attributes)
865 (setq value (get-char-attribute char key)))
867 (insert (format "(%s . %S)%s"
871 (setq attributes (delq key attributes))
873 (setq key (intern (format "%s@%s" 'total-strokes domain)))
874 (when (and (memq key attributes)
875 (setq value (get-char-attribute char key)))
876 (insert (format "(%s . %S)%s"
880 (setq attributes (delq key attributes))
882 (dolist (feature '(ideographic-radical
885 (setq key (intern (format "%s@%s*sources" feature domain)))
886 (when (and (memq key attributes)
887 (setq value (get-char-attribute char key)))
888 (insert (format "(%s%s" key line-breaking))
890 (insert (format " %s" cell)))
892 (insert line-breaking)
893 (setq attributes (delq key attributes))
896 (when (and (memq 'ideographic-strokes attributes)
897 (setq value (get-char-attribute char 'ideographic-strokes)))
899 (insert (format "(ideographic-strokes . %S)%s"
902 (setq attributes (delq 'ideographic-strokes attributes))
904 (when (and (memq 'kangxi-radical attributes)
905 (setq value (get-char-attribute char 'kangxi-radical)))
906 (unless (eq value radical)
907 (insert (format "(kangxi-radical\t . %S)\t; %c%s"
909 (ideographic-radical value)
912 (setq radical value)))
913 (setq attributes (delq 'kangxi-radical attributes))
915 (when (and (memq 'kangxi-strokes attributes)
916 (setq value (get-char-attribute char 'kangxi-strokes)))
917 (unless (eq value strokes)
918 (insert (format "(kangxi-strokes\t . %S)%s"
922 (setq strokes value)))
923 (setq attributes (delq 'kangxi-strokes attributes))
925 (when (and (memq 'japanese-radical attributes)
926 (setq value (get-char-attribute char 'japanese-radical)))
927 (unless (eq value radical)
928 (insert (format "(japanese-radical\t . %S)\t; %c%s"
930 (ideographic-radical value)
933 (setq radical value)))
934 (setq attributes (delq 'japanese-radical attributes))
936 (when (and (memq 'japanese-strokes attributes)
937 (setq value (get-char-attribute char 'japanese-strokes)))
938 (unless (eq value strokes)
939 (insert (format "(japanese-strokes\t . %S)%s"
943 (setq strokes value)))
944 (setq attributes (delq 'japanese-strokes attributes))
946 (when (and (memq 'cns-radical attributes)
947 (setq value (get-char-attribute char 'cns-radical)))
948 (insert (format "(cns-radical\t . %S)\t; %c%s"
950 (ideographic-radical value)
952 (setq attributes (delq 'cns-radical attributes))
954 (when (and (memq 'cns-strokes attributes)
955 (setq value (get-char-attribute char 'cns-strokes)))
956 (unless (eq value strokes)
957 (insert (format "(cns-strokes\t . %S)%s"
961 (setq strokes value)))
962 (setq attributes (delq 'cns-strokes attributes))
964 (when (and (memq 'shinjigen-1-radical attributes)
965 (setq value (get-char-attribute char 'shinjigen-1-radical)))
966 (unless (eq value radical)
967 (insert (format "(shinjigen-1-radical . %S)\t; %c%s"
969 (ideographic-radical value)
972 (setq radical value)))
973 (setq attributes (delq 'shinjigen-1-radical attributes))
975 (when (and (memq 'ideographic- attributes)
976 (setq value (get-char-attribute char 'ideographic-)))
977 (insert "(ideographic- ")
978 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
981 (setq cell (car value))
983 (setq cell (decode-char '=ucs cell)))
984 (cond ((characterp cell)
988 (insert (format "%S" cell))
989 (char-db-insert-char-spec cell readable))
990 (setq separator lbs))
994 (if (consp (car cell))
995 (char-db-insert-char-spec cell readable)
996 (char-db-insert-char-reference cell readable))
997 (setq separator lbs))
1001 (insert (prin1-to-string cell))
1002 (setq separator " ")))
1003 (setq value (cdr value)))
1005 (insert line-breaking)
1006 (setq attributes (delq 'ideographic- attributes)))
1007 (when (and (memq 'total-strokes attributes)
1008 (setq value (get-char-attribute char 'total-strokes)))
1009 (insert (format "(total-strokes . %S)%s"
1012 (setq attributes (delq 'total-strokes attributes))
1014 (when (and (memq '->ideograph attributes)
1015 (setq value (get-char-attribute char '->ideograph)))
1016 (insert (format "(->ideograph\t%s)%s"
1017 (mapconcat (lambda (code)
1018 (cond ((symbolp code)
1021 (format "#x%04X" code))
1024 line-breaking code))))
1027 (setq attributes (delq '->ideograph attributes))
1029 ;; (when (and (memq '->decomposition attributes)
1030 ;; (setq value (get-char-attribute char '->decomposition)))
1031 ;; (insert (format "(->decomposition\t%s)%s"
1032 ;; (mapconcat (lambda (code)
1033 ;; (cond ((symbolp code)
1034 ;; (symbol-name code))
1035 ;; ((characterp code)
1037 ;; (format "%S" code)
1042 ;; (format "#x%04X" code))
1044 ;; (format "%s%S" line-breaking code))))
1047 ;; (setq attributes (delq '->decomposition attributes))
1049 (if (equal (get-char-attribute char '->titlecase)
1050 (get-char-attribute char '->uppercase))
1051 (setq attributes (delq '->titlecase attributes)))
1052 (when (and (memq '->mojikyo attributes)
1053 (setq value (get-char-attribute char '->mojikyo)))
1054 (insert (format "(->mojikyo\t\t. %06d)\t; %c%s"
1055 value (decode-char 'mojikyo value)
1057 (setq attributes (delq '->mojikyo attributes))
1059 (when (and (memq 'hanyu-dazidian-vol attributes)
1060 (setq value (get-char-attribute char 'hanyu-dazidian-vol)))
1061 (insert (format "(hanyu-dazidian-vol . %d)%s"
1062 value line-breaking))
1063 (setq attributes (delq 'hanyu-dazidian-vol attributes))
1065 (when (and (memq 'hanyu-dazidian-page attributes)
1066 (setq value (get-char-attribute char 'hanyu-dazidian-page)))
1067 (insert (format "(hanyu-dazidian-page . %d)%s"
1068 value line-breaking))
1069 (setq attributes (delq 'hanyu-dazidian-page attributes))
1071 (when (and (memq 'hanyu-dazidian-char attributes)
1072 (setq value (get-char-attribute char 'hanyu-dazidian-char)))
1073 (insert (format "(hanyu-dazidian-char . %d)%s"
1074 value line-breaking))
1075 (setq attributes (delq 'hanyu-dazidian-char attributes))
1078 (dolist (ignored '(composition
1079 ->denotational <-subsumptive ->ucs-unified
1080 ->ideographic-component-forms))
1081 (setq attributes (delq ignored attributes))))
1083 (setq name (car attributes))
1084 (if (setq value (get-char-attribute char name))
1085 (cond ((setq ret (find-charset name))
1086 (setq name (charset-name ret))
1087 (if (and (not (memq name dest-ccss))
1089 (setq value (get-char-attribute char name))
1090 (setq dest-ccss (cons name dest-ccss))))
1091 (char-db-insert-ccs-feature name value line-breaking))
1093 ((string-match "^=>ucs@" (symbol-name name))
1094 (insert (format "(%-18s . #x%04X)\t; %c%s"
1095 name value (decode-char '=ucs value)
1098 ((eq name 'jisx0208-1978/4X)
1099 (insert (format "(%-18s . #x%04X)%s"
1105 (not (eq name '->subsumptive))
1106 (not (eq name '->uppercase))
1107 (not (eq name '->lowercase))
1108 (not (eq name '->titlecase))
1109 (not (eq name '->canonical))
1110 (not (eq name '->Bopomofo))
1111 (not (eq name '->mistakable))
1112 (not (eq name '->ideographic-variants))
1113 (null (get-char-attribute
1114 char (intern (format "%s*sources" name))))
1115 (not (string-match "\\*sources$" (symbol-name name)))
1116 (null (get-char-attribute
1117 char (intern (format "%s*note" name))))
1118 (not (string-match "\\*note$" (symbol-name name)))
1119 (or (eq name '<-identical)
1120 (eq name '<-uppercase)
1121 (eq name '<-lowercase)
1122 (eq name '<-titlecase)
1123 (eq name '<-canonical)
1124 (eq name '<-ideographic-variants)
1125 ;; (eq name '<-synonyms)
1126 (string-match "^<-synonyms" (symbol-name name))
1127 (eq name '<-mistakable)
1128 (when (string-match "^->" (symbol-name name))
1130 ((string-match "^->fullwidth" (symbol-name name))
1131 (not (and (consp value)
1132 (characterp (car value))
1134 (car value) '=ucs 'defined-only)))
1139 ((or (eq name 'ideographic-structure)
1140 (eq name 'ideographic-combination)
1141 (eq name 'ideographic-)
1142 (eq name '=decomposition)
1143 (string-match "^=>decomposition" (symbol-name name))
1144 (string-match "^\\(->\\|<-\\)[^*]*$" (symbol-name name))
1145 (string-match "^\\(->\\|<-\\)[^*]*\\*sources$"
1148 (char-db-insert-relation-feature char name value
1151 ((memq name '(ideograph=
1152 original-ideograph-of
1153 ancient-ideograph-of
1156 ;; simplified-ideograph-of
1157 ideographic-variants
1158 ;; ideographic-different-form-of
1160 (insert (format "(%-18s%s " name line-breaking))
1161 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1163 (while (consp value)
1164 (setq cell (car value))
1165 (if (and (consp cell)
1170 (char-db-insert-alist cell readable)
1171 (setq separator lbs))
1174 (insert (prin1-to-string cell))
1175 (setq separator " "))
1176 (setq value (cdr value)))
1178 (insert line-breaking))
1180 (insert (format "(%-18s " name))
1181 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1183 (while (consp value)
1184 (setq cell (car value))
1185 (if (and (consp cell)
1187 (setq ret (condition-case nil
1195 (setq key (car (car rest)))
1196 (if (find-charset key)
1197 (setq cal (cons key cal))
1198 (setq al (cons key al)))
1199 (setq rest (cdr rest)))
1202 (insert-char-attributes ret
1205 (setq separator lbs))
1206 (setq ret (prin1-to-string cell))
1208 (if (< (+ (current-column)
1215 (setq separator " "))
1216 (setq value (cdr value)))
1218 (insert line-breaking))
1220 (insert (format "(%-18s" name))
1221 (setq ret (prin1-to-string value))
1222 (unless (< (+ (current-column)
1226 (insert line-breaking))
1227 (insert " . " ret ")" line-breaking)
1228 ;; (insert (format "(%-18s . %S)%s"
1233 (setq attributes (cdr attributes)))
1236 (defun insert-char-data (char &optional readable
1239 (narrow-to-region (point)(point))
1240 (insert "(define-char
1242 (insert-char-attributes char readable attributes)
1244 (goto-char (point-min))
1245 (while (re-search-forward "[ \t]+$" nil t)
1248 (goto-char (point-min))
1249 (while (re-search-forward "[ \t][ \t][ \t]*" nil t)
1250 (let ((column (current-column))
1251 (indent-tabs-mode t))
1252 (delete-region (match-beginning 0) (point))
1253 (indent-to column)))
1254 (goto-char (point-max))
1255 ;; (tabify (point-min)(point-max))
1258 (defun insert-char-data-with-variant (char &optional printable
1260 script excluded-script)
1261 (insert-char-data char printable)
1262 (let ((variants (char-variants char))
1265 (setq variants (sort variants #'<))
1266 (setq rest variants)
1267 (setq variants (cons char variants))
1269 (setq variant (car rest))
1270 (unless (get-char-attribute variant '<-subsumptive)
1271 (if (and (or (null script)
1272 (null (setq vs (get-char-attribute variant 'script)))
1274 (or (null excluded-script)
1275 (null (setq vs (get-char-attribute variant 'script)))
1276 (not (memq excluded-script vs))))
1277 (unless (and no-ucs-unified (get-char-attribute variant '=ucs))
1278 (insert-char-data variant printable)
1279 (if (setq ret (char-variants variant))
1281 (or (memq (car ret) variants)
1282 ;; (get-char-attribute (car ret) '<-subsumptive)
1283 (setq rest (nconc rest (list (car ret)))))
1284 (setq ret (cdr ret)))))))
1285 (setq rest (cdr rest)))))
1287 (defun insert-char-range-data (min max &optional script excluded-script)
1290 (while (<= code max)
1291 (setq char (decode-char '=ucs code))
1292 (if (encode-char char '=ucs 'defined-only)
1293 (insert-char-data-with-variant char nil 'no-ucs-unified
1294 script excluded-script))
1295 (setq code (1+ code)))))
1297 (defun write-char-range-data-to-file (min max file
1298 &optional script excluded-script)
1299 (let ((coding-system-for-write char-db-file-coding-system))
1301 (insert (format ";; -*- coding: %s -*-\n"
1302 char-db-file-coding-system))
1303 (insert-char-range-data min max script excluded-script)
1304 (write-region (point-min)(point-max) file))))
1306 (defvar what-character-original-window-configuration)
1309 (defun what-char-definition (char)
1310 (interactive (list (char-after)))
1311 (let ((buf (get-buffer-create "*Character Description*"))
1312 (the-buf (current-buffer))
1313 (win-conf (current-window-configuration)))
1315 (make-local-variable 'what-character-original-window-configuration)
1316 (setq what-character-original-window-configuration win-conf)
1317 (setq buffer-read-only nil)
1321 (insert-char-data-with-variant char 'printable)
1322 (unless (char-attribute-alist char)
1323 (insert (format ";; = %c\n"
1324 (let* ((rest (split-char char))
1328 (setq code (logior (lsh code 8)
1330 (decode-char ccs code)))))
1331 ;; (char-db-update-comment)
1332 (set-buffer-modified-p nil)
1333 (view-mode the-buf (lambda (buf)
1334 (set-window-configuration
1335 what-character-original-window-configuration)
1337 (goto-char (point-min)))
1339 (set-window-configuration
1340 what-character-original-window-configuration)
1341 (signal (car err) (cdr err)))))))
1343 (provide 'char-db-util)
1345 ;;; char-db-util.el ends here