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 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
96 (defun shuowen-radical (number)
97 (aref shuowen-radicals (1- number)))
99 (defvar char-db-file-coding-system 'utf-8-mcs-er)
101 (defvar char-db-feature-domains
102 '(ucs ucs/compat daikanwa cns gt jis jis/alt jis/a jis/b
103 jis-x0212 jis-x0213 cdp shinjigen misc unknown))
105 (defvar char-db-ignored-attributes '(ideographic-products))
107 (defun char-attribute-name< (ka kb)
109 ((eq '->denotational kb)
111 ((eq '->subsumptive kb)
112 (not (eq '->denotational ka)))
113 ((eq '->denotational ka)
115 ((eq '->subsumptive ka)
118 (string-match "^->" (symbol-name ka)))
119 (cond ((and (symbolp kb)
120 (string-match "^->" (symbol-name kb)))
121 (string< (symbol-name ka)
126 (string-match "^->" (symbol-name kb)))
129 (string-match "^<-" (symbol-name ka)))
131 (cond ((string-match "^<-" (symbol-name kb))
132 (string< (symbol-name ka)
135 ;; ((string-match "^->" (symbol-name kb))
140 (string-match "^<-" (symbol-name kb)))
142 ;; (not (string-match "^->" (symbol-name ka)))
145 (if (find-charset kb)
146 (if (<= (charset-id ka) 1)
147 (if (<= (charset-id kb) 1)
149 ((= (charset-dimension ka)
150 (charset-dimension kb))
151 (> (charset-id ka)(charset-id kb)))
153 (> (charset-dimension ka)
154 (charset-dimension kb))
157 (if (<= (charset-id kb) 1)
159 (< (charset-id ka)(charset-id kb))))
165 (string< (symbol-name ka)
171 (defvar char-db-coded-charset-priority-list
232 (defun char-db-make-char-spec (char)
234 (cond ((characterp char)
235 (cond ((and (setq ret (encode-char char '=ucs 'defined-only))
236 (not (and (<= #xE000 ret)(<= ret #xF8FF))))
237 (setq char-spec (list (cons '=ucs ret)))
238 (cond ((setq ret (get-char-attribute char 'name))
239 (setq char-spec (cons (cons 'name ret) char-spec))
241 ((setq ret (get-char-attribute char 'name*))
242 (setq char-spec (cons (cons 'name* ret) char-spec))
247 (let ((rest char-db-coded-charset-priority-list)
250 (setq ccs (charset-name
251 (find-charset (car rest))))
253 (encode-char char ccs
255 (throw 'tag (cons ccs ret)))
256 (setq rest (cdr rest))))))
257 (setq char-spec (list ret))
258 (dolist (ccs (delq (car ret) (charset-list)))
259 (if (and (or (charset-iso-final-char ccs)
266 (setq ccs (charset-name ccs))
267 (null (assq ccs char-spec))
268 (setq ret (encode-char char ccs 'defined-only)))
269 (setq char-spec (cons (cons ccs ret) char-spec))))
271 (setq char-spec (split-char char)))
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))
283 (defun char-db-insert-char-spec (char &optional readable column
286 (setq column (current-column)))
287 (let (char-spec temp-char)
288 (setq char-spec (char-db-make-char-spec char))
289 (unless (or (characterp char) ; char
291 (setq char (find-char char-spec))
293 ;; define temporary character
294 ;; Current implementation is dirty.
295 (setq temp-char (define-char (cons '(ideograph-daikanwa . 0)
297 (remove-char-attribute temp-char 'ideograph-daikanwa)
298 (setq char temp-char))
299 (insert-char-attributes char
301 (union (mapcar #'car char-spec)
304 ;; undefine temporary character
305 ;; Current implementation is dirty.
306 (setq char-spec (char-attribute-alist temp-char))
308 (remove-char-attribute temp-char (car (car char-spec)))
309 (setq char-spec (cdr char-spec))))))
311 (defun char-db-insert-alist (alist &optional readable column)
313 (setq column (current-column)))
315 (concat "\n" (make-string (1+ column) ?\ )))
319 lbs cell rest separator)
322 (setq name (car (car alist))
323 value (cdr (car alist)))
324 (cond ((eq name 'char)
326 (if (setq ret (condition-case nil
334 (setq key (car (car value)))
335 ;; (if (find-charset key)
336 ;; (setq cal (cons key cal))
337 (setq al (cons key al))
339 (setq value (cdr value)))
340 (insert-char-attributes ret
344 (insert (prin1-to-string value)))
346 (insert line-breaking))
348 (insert (format "(%-18s " name))
349 (setq lbs (concat "\n" (make-string (current-column) ?\ )))
351 (setq cell (car value))
352 (if (and (consp cell)
354 (setq ret (condition-case nil
364 (setq key (car (car rest)))
365 ;; (if (find-charset key)
366 ;; (setq cal (cons key cal))
367 (setq al (cons key al))
369 (setq rest (cdr rest)))
372 (insert-char-attributes ret
376 (setq separator lbs))
379 (insert (prin1-to-string cell))
380 (setq separator " "))
381 (setq value (cdr value)))
383 (insert line-breaking))
385 (insert (format "(%-18s . %S)%s"
388 (setq alist (cdr alist))))
391 (defun char-db-insert-char-reference (plist &optional readable column)
393 (setq column (current-column)))
395 (concat "\n" (make-string (1+ column) ?\ )))
400 (setq name (pop plist))
401 (setq value (pop plist))
402 (cond ((eq name :char)
405 (cond ((numberp value)
406 (setq value (decode-char '=ucs value)))
408 ;; (setq value (or (find-char value)
411 (char-db-insert-char-spec value readable)
412 (insert line-breaking)
415 (insert (format "%s%s\t%d ; %c%s"
418 (ideographic-radical value)
422 (insert (format "%s%s\t%S" separator name value))
423 (setq separator line-breaking)))
427 (defun char-db-decode-isolated-char (ccs code-point)
430 (cond ((eq ccs 'arabic-iso8859-6)
431 (decode-char ccs code-point))
432 ((and (memq ccs '(=gt-pj-1
443 (setq ret (decode-char ccs code-point))
444 (setq ret (encode-char ret '=gt 'defined-only)))
445 (decode-builtin-char '=gt ret))
447 (decode-builtin-char ccs code-point))))
448 (cond ((and (<= 0 (char-int ret))
449 (<= (char-int ret) #x1F))
450 (decode-char '=ucs (+ #x2400 (char-int ret))))
451 ((= (char-int ret) #x7F)
455 (defvar char-db-convert-obsolete-format t)
457 (defun char-db-insert-ccs-feature (name value line-breaking)
460 (cond ((or (memq name '(=daikanwa
461 =daikanwa@rev1 =daikanwa@rev2
462 =gt =gt-k =cbeta =zinbun-oracle))
463 (string-match "^=adobe-" (symbol-name name)))
464 "(%-18s . %05d)\t; %c")
466 "(%-18s . %06d)\t; %c")
467 ((>= (charset-dimension name) 2)
468 "(%-18s . #x%04X)\t; %c")
470 "(%-18s . #x%02X)\t; %c"))
472 (if (= (charset-iso-graphic-plane name) 1)
474 (cond ((= (charset-dimension name) 1)
476 ((= (charset-dimension name) 2)
478 ((= (charset-dimension name) 3)
482 (char-db-decode-isolated-char name value)))
483 (if (and (= (charset-chars name) 94)
484 (= (charset-dimension name) 2))
485 (insert (format " [%02d-%02d]"
486 (- (lsh value -8) 32)
487 (- (logand value 255) 32))))
488 (insert line-breaking))
490 (defun char-db-insert-relation-feature (char name value line-breaking
492 (insert (format "(%-18s%s " name line-breaking))
493 (let ((lbs (concat "\n" (make-string (current-column) ?\ )))
494 separator cell sources required-features
497 (setq cell (car value))
499 (setq cell (decode-char '=ucs cell)))
501 ((eq name '->subsumptive)
502 (when (or (not (some (lambda (atr)
503 (get-char-attribute cell atr))
504 char-db-ignored-attributes))
506 (encode-char cell ccs 'defined-only))
510 (let ((char-db-ignored-attributes
512 char-db-ignored-attributes)))
513 (insert-char-attributes cell readable))
514 (setq separator lbs))
519 char (intern (format "%s*sources" name))))
520 (setq required-features nil)
521 (dolist (source sources)
523 ((memq source '(JP JP/Jouyou shinjigen-1))
524 (setq required-features
525 (union required-features
534 (setq required-features
535 (union required-features
540 ((find-charset (setq ret (intern (format "=%s" source))))
541 (setq required-features
542 (cons ret required-features)))
543 (t (setq required-features
544 (cons source required-features)))))
545 (cond ((string-match "@JP" (symbol-name name))
546 (setq required-features
547 (union required-features
555 ((string-match "@CN" (symbol-name name))
556 (setq required-features
557 (union required-features
564 (insert (format "%S" cell))
565 (char-db-insert-char-spec cell readable
568 (setq separator lbs))
572 (if (consp (car cell))
573 (char-db-insert-char-spec cell readable)
574 (char-db-insert-char-reference cell readable))
575 (setq separator lbs))
579 (insert (prin1-to-string cell))
580 (setq separator " ")))
581 (setq value (cdr value)))
583 (insert line-breaking)))
585 (defun insert-char-attributes (char &optional readable attributes column)
587 (setq column (current-column)))
588 (let (name value ; has-long-ccs-name
592 (concat "\n" (make-string (1+ column) ?\ )))
593 lbs cell separator ret
595 dest-ccss ; sources required-features
600 (if (consp attributes)
602 (dolist (name attributes)
603 (unless (memq name char-db-ignored-attributes)
604 (if (find-charset name)
608 (dolist (name (char-attribute-list))
609 (unless (memq name char-db-ignored-attributes)
610 (if (find-charset name)
614 #'char-attribute-name<)))
616 (when (memq '<-subsumptive attributes)
618 (when (setq value (get-char-attribute char '<-subsumptive))
619 (char-db-insert-relation-feature char '<-subsumptive value
622 (setq attributes (delq '<-subsumptive attributes)))
623 (when (and (memq '<-denotational attributes)
624 (setq value (get-char-attribute char '<-denotational)))
625 (char-db-insert-relation-feature char '<-denotational value
628 (setq attributes (delq '<-denotational attributes)))
629 (when (and (memq 'name attributes)
630 (setq value (get-char-attribute char 'name)))
632 (if (> (+ (current-column) (length value)) 48)
635 value line-breaking))
636 (setq attributes (delq 'name attributes))
638 (when (and (memq 'name* attributes)
639 (setq value (get-char-attribute char 'name*)))
641 (if (> (+ (current-column) (length value)) 48)
644 value line-breaking))
645 (setq attributes (delq 'name* attributes))
647 (when (and (memq 'script attributes)
648 (setq value (get-char-attribute char 'script)))
649 (insert (format "(script\t\t%s)%s"
650 (mapconcat (function prin1-to-string)
653 (setq attributes (delq 'script attributes))
655 (dolist (name '(=>ucs =>ucs*))
656 (when (and (memq name attributes)
657 (setq value (get-char-attribute char name)))
658 (insert (format "(%-18s . #x%04X)\t; %c%s"
659 name value (decode-char '=ucs value)
661 (setq attributes (delq name attributes))))
662 (dolist (name '(=>ucs@gb =>ucs@cns =>ucs@jis =>ucs@ks =>ucs@big5))
663 (when (and (memq name attributes)
664 (setq value (get-char-attribute char name)))
665 (insert (format "(%-18s . #x%04X)\t; %c%s"
670 (symbol-name name) 2)))
673 (setq attributes (delq name attributes))
675 (dolist (name '(=>daikanwa))
676 (when (and (memq name attributes)
677 (setq value (get-char-attribute char name)))
680 (format "(%-18s . %05d)\t; %c%s"
681 name value (decode-char '=daikanwa value)
683 (format "(%-18s %s)\t; %c%s"
685 (mapconcat (function prin1-to-string)
687 (char-representative-of-daikanwa char)
689 (setq attributes (delq name attributes))))
690 (when (and (memq 'general-category attributes)
691 (setq value (get-char-attribute char 'general-category)))
693 "(general-category\t%s) ; %s%s"
694 (mapconcat (lambda (cell)
697 (cond ((rassoc value unidata-normative-category-alist)
698 "Normative Category")
699 ((rassoc value unidata-informative-category-alist)
700 "Informative Category")
704 (setq attributes (delq 'general-category attributes))
706 (when (and (memq 'bidi-category attributes)
707 (setq value (get-char-attribute char 'bidi-category)))
708 (insert (format "(bidi-category\t. %S)%s"
711 (setq attributes (delq 'bidi-category attributes))
713 (unless (or (not (memq 'mirrored attributes))
714 (eq (setq value (get-char-attribute char 'mirrored 'empty))
716 (insert (format "(mirrored\t\t. %S)%s"
719 (setq attributes (delq 'mirrored attributes))
722 ((and (memq 'decimal-digit-value attributes)
723 (setq value (get-char-attribute char 'decimal-digit-value)))
724 (insert (format "(decimal-digit-value . %S)%s"
727 (setq attributes (delq 'decimal-digit-value attributes))
728 (when (and (memq 'digit-value attributes)
729 (setq value (get-char-attribute char 'digit-value)))
730 (insert (format "(digit-value\t . %S)%s"
733 (setq attributes (delq 'digit-value attributes))
735 (when (and (memq 'numeric-value attributes)
736 (setq value (get-char-attribute char 'numeric-value)))
737 (insert (format "(numeric-value\t . %S)%s"
740 (setq attributes (delq 'numeric-value attributes))
744 (when (and (memq 'digit-value attributes)
745 (setq value (get-char-attribute char 'digit-value)))
746 (insert (format "(digit-value\t. %S)%s"
749 (setq attributes (delq 'digit-value attributes))
751 (when (and (memq 'numeric-value attributes)
752 (setq value (get-char-attribute char 'numeric-value)))
753 (insert (format "(numeric-value\t. %S)%s"
756 (setq attributes (delq 'numeric-value attributes))
758 (when (and (memq 'iso-10646-comment attributes)
759 (setq value (get-char-attribute char 'iso-10646-comment)))
760 (insert (format "(iso-10646-comment\t. %S)%s"
763 (setq attributes (delq 'iso-10646-comment attributes))
765 (when (and (memq 'morohashi-daikanwa attributes)
766 (setq value (get-char-attribute char 'morohashi-daikanwa)))
767 (insert (format "(morohashi-daikanwa\t%s)%s"
768 (mapconcat (function prin1-to-string) value " ")
770 (setq attributes (delq 'morohashi-daikanwa attributes))
774 (when (and (memq 'ideographic-radical attributes)
775 (setq value (get-char-attribute char 'ideographic-radical)))
777 (insert (format "(ideographic-radical . %S)\t; %c%s"
779 (ideographic-radical radical)
781 (setq attributes (delq 'ideographic-radical attributes))
783 (when (and (memq 'shuowen-radical attributes)
784 (setq value (get-char-attribute char 'shuowen-radical)))
785 (insert (format "(shuowen-radical\t. %S)\t; %c%s"
787 (shuowen-radical value)
789 (setq attributes (delq 'shuowen-radical attributes))
794 char-db-feature-domains
796 (dolist (feature (char-attribute-list))
797 (setq feature (symbol-name feature))
799 "\\(radical\\|strokes\\)@\\([^@*]+\\)\\(\\*\\|$\\)"
801 (setq domain (intern (match-string 2 feature)))
802 (unless (memq domain dest)
803 (setq dest (cons domain dest)))))
804 (sort dest #'string<))))
805 (setq key (intern (format "%s@%s" 'ideographic-radical domain)))
806 (when (and (memq key attributes)
807 (setq value (get-char-attribute char key)))
809 (insert (format "(%s . %S)\t; %c%s"
812 (ideographic-radical radical)
814 (setq attributes (delq key attributes))
816 (setq key (intern (format "%s@%s" 'ideographic-strokes domain)))
817 (when (and (memq key attributes)
818 (setq value (get-char-attribute char key)))
820 (insert (format "(%s . %S)%s"
824 (setq attributes (delq key attributes))
826 (setq key (intern (format "%s@%s" 'total-strokes domain)))
827 (when (and (memq key attributes)
828 (setq value (get-char-attribute char key)))
829 (insert (format "(%s . %S)%s"
833 (setq attributes (delq key attributes))
835 (dolist (feature '(ideographic-radical
838 (setq key (intern (format "%s@%s*sources" feature domain)))
839 (when (and (memq key attributes)
840 (setq value (get-char-attribute char key)))
841 (insert (format "(%s%s" key line-breaking))
843 (insert (format " %s" cell)))
845 (insert line-breaking)
846 (setq attributes (delq key attributes))
849 (when (and (memq 'ideographic-strokes attributes)
850 (setq value (get-char-attribute char 'ideographic-strokes)))
852 (insert (format "(ideographic-strokes . %S)%s"
855 (setq attributes (delq 'ideographic-strokes attributes))
857 (when (and (memq 'kangxi-radical attributes)
858 (setq value (get-char-attribute char 'kangxi-radical)))
859 (unless (eq value radical)
860 (insert (format "(kangxi-radical\t . %S)\t; %c%s"
862 (ideographic-radical value)
865 (setq radical value)))
866 (setq attributes (delq 'kangxi-radical attributes))
868 (when (and (memq 'kangxi-strokes attributes)
869 (setq value (get-char-attribute char 'kangxi-strokes)))
870 (unless (eq value strokes)
871 (insert (format "(kangxi-strokes\t . %S)%s"
875 (setq strokes value)))
876 (setq attributes (delq 'kangxi-strokes attributes))
878 (when (and (memq 'japanese-radical attributes)
879 (setq value (get-char-attribute char 'japanese-radical)))
880 (unless (eq value radical)
881 (insert (format "(japanese-radical\t . %S)\t; %c%s"
883 (ideographic-radical value)
886 (setq radical value)))
887 (setq attributes (delq 'japanese-radical attributes))
889 (when (and (memq 'japanese-strokes attributes)
890 (setq value (get-char-attribute char 'japanese-strokes)))
891 (unless (eq value strokes)
892 (insert (format "(japanese-strokes\t . %S)%s"
896 (setq strokes value)))
897 (setq attributes (delq 'japanese-strokes attributes))
899 (when (and (memq 'cns-radical attributes)
900 (setq value (get-char-attribute char 'cns-radical)))
901 (insert (format "(cns-radical\t . %S)\t; %c%s"
903 (ideographic-radical value)
905 (setq attributes (delq 'cns-radical attributes))
907 (when (and (memq 'cns-strokes attributes)
908 (setq value (get-char-attribute char 'cns-strokes)))
909 (unless (eq value strokes)
910 (insert (format "(cns-strokes\t . %S)%s"
914 (setq strokes value)))
915 (setq attributes (delq 'cns-strokes attributes))
917 (when (and (memq 'shinjigen-1-radical attributes)
918 (setq value (get-char-attribute char 'shinjigen-1-radical)))
919 (unless (eq value radical)
920 (insert (format "(shinjigen-1-radical . %S)\t; %c%s"
922 (ideographic-radical value)
925 (setq radical value)))
926 (setq attributes (delq 'shinjigen-1-radical attributes))
928 (when (and (memq 'ideographic- attributes)
929 (setq value (get-char-attribute char 'ideographic-)))
930 (insert "(ideographic- ")
931 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
934 (setq cell (car value))
936 (setq cell (decode-char '=ucs cell)))
937 (cond ((characterp cell)
941 (insert (format "%S" cell))
942 (char-db-insert-char-spec cell readable))
943 (setq separator lbs))
947 (if (consp (car cell))
948 (char-db-insert-char-spec cell readable)
949 (char-db-insert-char-reference cell readable))
950 (setq separator lbs))
954 (insert (prin1-to-string cell))
955 (setq separator " ")))
956 (setq value (cdr value)))
958 (insert line-breaking)
959 (setq attributes (delq 'ideographic- attributes)))
960 (when (and (memq 'total-strokes attributes)
961 (setq value (get-char-attribute char 'total-strokes)))
962 (insert (format "(total-strokes . %S)%s"
965 (setq attributes (delq 'total-strokes attributes))
967 (when (and (memq '->ideograph attributes)
968 (setq value (get-char-attribute char '->ideograph)))
969 (insert (format "(->ideograph\t%s)%s"
970 (mapconcat (lambda (code)
971 (cond ((symbolp code)
974 (format "#x%04X" code))
977 line-breaking code))))
980 (setq attributes (delq '->ideograph attributes))
982 ;; (when (and (memq '->decomposition attributes)
983 ;; (setq value (get-char-attribute char '->decomposition)))
984 ;; (insert (format "(->decomposition\t%s)%s"
985 ;; (mapconcat (lambda (code)
986 ;; (cond ((symbolp code)
987 ;; (symbol-name code))
988 ;; ((characterp code)
990 ;; (format "%S" code)
995 ;; (format "#x%04X" code))
997 ;; (format "%s%S" line-breaking code))))
1000 ;; (setq attributes (delq '->decomposition attributes))
1002 (if (equal (get-char-attribute char '->titlecase)
1003 (get-char-attribute char '->uppercase))
1004 (setq attributes (delq '->titlecase attributes)))
1005 (when (and (memq '->mojikyo attributes)
1006 (setq value (get-char-attribute char '->mojikyo)))
1007 (insert (format "(->mojikyo\t\t. %06d)\t; %c%s"
1008 value (decode-char 'mojikyo value)
1010 (setq attributes (delq '->mojikyo attributes))
1012 (when (and (memq 'hanyu-dazidian-vol attributes)
1013 (setq value (get-char-attribute char 'hanyu-dazidian-vol)))
1014 (insert (format "(hanyu-dazidian-vol . %d)%s"
1015 value line-breaking))
1016 (setq attributes (delq 'hanyu-dazidian-vol attributes))
1018 (when (and (memq 'hanyu-dazidian-page attributes)
1019 (setq value (get-char-attribute char 'hanyu-dazidian-page)))
1020 (insert (format "(hanyu-dazidian-page . %d)%s"
1021 value line-breaking))
1022 (setq attributes (delq 'hanyu-dazidian-page attributes))
1024 (when (and (memq 'hanyu-dazidian-char attributes)
1025 (setq value (get-char-attribute char 'hanyu-dazidian-char)))
1026 (insert (format "(hanyu-dazidian-char . %d)%s"
1027 value line-breaking))
1028 (setq attributes (delq 'hanyu-dazidian-char attributes))
1031 (dolist (ignored '(composition
1032 ->denotational <-subsumptive ->ucs-unified
1033 ->ideographic-component-forms))
1034 (setq attributes (delq ignored attributes))))
1036 (setq name (car attributes))
1037 (if (setq value (get-char-attribute char name))
1038 (cond ((setq ret (find-charset name))
1039 (setq name (charset-name ret))
1040 (if (and (not (memq name dest-ccss))
1042 (setq value (get-char-attribute char name))
1043 (setq dest-ccss (cons name dest-ccss))))
1044 (char-db-insert-ccs-feature name value line-breaking))
1046 ((string-match "^=>ucs@" (symbol-name name))
1047 (insert (format "(%-18s . #x%04X)\t; %c%s"
1048 name value (decode-char '=ucs value)
1051 ((eq name 'jisx0208-1978/4X)
1052 (insert (format "(%-18s . #x%04X)%s"
1058 (not (eq name '->subsumptive))
1059 (not (eq name '->uppercase))
1060 (not (eq name '->lowercase))
1061 (not (eq name '->titlecase))
1062 (not (eq name '->canonical))
1063 (not (eq name '->Bopomofo))
1064 (not (eq name '->mistakable))
1065 (not (eq name '->ideographic-variants))
1066 (null (get-char-attribute
1067 char (intern (format "%s*sources" name))))
1068 (not (string-match "\\*sources$" (symbol-name name)))
1069 (null (get-char-attribute
1070 char (intern (format "%s*note" name))))
1071 (not (string-match "\\*note$" (symbol-name name)))
1072 (or (eq name '<-identical)
1073 (eq name '<-uppercase)
1074 (eq name '<-lowercase)
1075 (eq name '<-titlecase)
1076 (eq name '<-canonical)
1077 (eq name '<-ideographic-variants)
1078 ;; (eq name '<-synonyms)
1079 (string-match "^<-synonyms" (symbol-name name))
1080 (eq name '<-mistakable)
1081 (when (string-match "^->" (symbol-name name))
1083 ((string-match "^->fullwidth" (symbol-name name))
1084 (not (and (consp value)
1085 (characterp (car value))
1087 (car value) '=ucs 'defined-only)))
1092 ((or (eq name 'ideographic-structure)
1093 (eq name 'ideographic-combination)
1094 (eq name 'ideographic-)
1095 (eq name '=decomposition)
1096 (string-match "^=>decomposition" (symbol-name name))
1097 (string-match "^\\(->\\|<-\\)[^*]*$" (symbol-name name))
1098 (string-match "^\\(->\\|<-\\)[^*]*\\*sources$"
1101 (char-db-insert-relation-feature char name value
1104 ((memq name '(ideograph=
1105 original-ideograph-of
1106 ancient-ideograph-of
1109 ;; simplified-ideograph-of
1110 ideographic-variants
1111 ;; ideographic-different-form-of
1113 (insert (format "(%-18s%s " name line-breaking))
1114 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1116 (while (consp value)
1117 (setq cell (car value))
1118 (if (and (consp cell)
1123 (char-db-insert-alist cell readable)
1124 (setq separator lbs))
1127 (insert (prin1-to-string cell))
1128 (setq separator " "))
1129 (setq value (cdr value)))
1131 (insert line-breaking))
1133 (insert (format "(%-18s " name))
1134 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1136 (while (consp value)
1137 (setq cell (car value))
1138 (if (and (consp cell)
1140 (setq ret (condition-case nil
1148 (setq key (car (car rest)))
1149 (if (find-charset key)
1150 (setq cal (cons key cal))
1151 (setq al (cons key al)))
1152 (setq rest (cdr rest)))
1155 (insert-char-attributes ret
1158 (setq separator lbs))
1159 (setq ret (prin1-to-string cell))
1161 (if (< (+ (current-column)
1168 (setq separator " "))
1169 (setq value (cdr value)))
1171 (insert line-breaking))
1173 (insert (format "(%-18s" name))
1174 (setq ret (prin1-to-string value))
1175 (unless (< (+ (current-column)
1179 (insert line-breaking))
1180 (insert " . " ret ")" line-breaking)
1181 ;; (insert (format "(%-18s . %S)%s"
1186 (setq attributes (cdr attributes)))
1189 (defun insert-char-data (char &optional readable
1192 (narrow-to-region (point)(point))
1193 (insert "(define-char
1195 (insert-char-attributes char readable attributes)
1197 (goto-char (point-min))
1198 (while (re-search-forward "[ \t]+$" nil t)
1201 (goto-char (point-min))
1202 (while (re-search-forward "[ \t][ \t][ \t]*" nil t)
1203 (let ((column (current-column))
1204 (indent-tabs-mode t))
1205 (delete-region (match-beginning 0) (point))
1206 (indent-to column)))
1207 (goto-char (point-max))
1208 ;; (tabify (point-min)(point-max))
1211 (defun insert-char-data-with-variant (char &optional printable
1213 script excluded-script)
1214 (insert-char-data char printable)
1215 (let ((variants (char-variants char))
1218 (setq variants (sort variants #'<))
1219 (setq rest variants)
1220 (setq variants (cons char variants))
1222 (setq variant (car rest))
1223 (unless (get-char-attribute variant '<-subsumptive)
1224 (if (and (or (null script)
1225 (null (setq vs (get-char-attribute variant 'script)))
1227 (or (null excluded-script)
1228 (null (setq vs (get-char-attribute variant 'script)))
1229 (not (memq excluded-script vs))))
1230 (unless (and no-ucs-unified (get-char-attribute variant '=ucs))
1231 (insert-char-data variant printable)
1232 (if (setq ret (char-variants variant))
1234 (or (memq (car ret) variants)
1235 ;; (get-char-attribute (car ret) '<-subsumptive)
1236 (setq rest (nconc rest (list (car ret)))))
1237 (setq ret (cdr ret)))))))
1238 (setq rest (cdr rest)))))
1240 (defun insert-char-range-data (min max &optional script excluded-script)
1243 (while (<= code max)
1244 (setq char (decode-char '=ucs code))
1245 (if (encode-char char '=ucs 'defined-only)
1246 (insert-char-data-with-variant char nil 'no-ucs-unified
1247 script excluded-script))
1248 (setq code (1+ code)))))
1250 (defun write-char-range-data-to-file (min max file
1251 &optional script excluded-script)
1252 (let ((coding-system-for-write char-db-file-coding-system))
1254 (insert (format ";; -*- coding: %s -*-\n"
1255 char-db-file-coding-system))
1256 (insert-char-range-data min max script excluded-script)
1257 (write-region (point-min)(point-max) file))))
1259 (defvar what-character-original-window-configuration)
1262 (defun what-char-definition (char)
1263 (interactive (list (char-after)))
1264 (let ((buf (get-buffer-create "*Character Description*"))
1265 (the-buf (current-buffer))
1266 (win-conf (current-window-configuration)))
1268 (make-local-variable 'what-character-original-window-configuration)
1269 (setq what-character-original-window-configuration win-conf)
1270 (setq buffer-read-only nil)
1274 (insert-char-data-with-variant char 'printable)
1275 (unless (char-attribute-alist char)
1276 (insert (format ";; = %c\n"
1277 (let* ((rest (split-char char))
1281 (setq code (logior (lsh code 8)
1283 (decode-char ccs code)))))
1284 ;; (char-db-update-comment)
1285 (set-buffer-modified-p nil)
1286 (view-mode the-buf (lambda (buf)
1287 (set-window-configuration
1288 what-character-original-window-configuration)
1290 (goto-char (point-min)))
1292 (set-window-configuration
1293 what-character-original-window-configuration)
1294 (signal (car err) (cdr err)))))))
1296 (provide 'char-db-util)
1298 ;;; char-db-util.el ends here