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 [?一 ?上 ?示 ?三 ?王 ?玉 ?玨 ?气 ?士 ?丨
78 ?屮 ?艸 ?蓐 ?茻 ?小 ?八 ?釆 ?半 ?牛 ?犛
79 ?告 ?口 ?凵 ?吅 ?哭 ?走 ?止 ?癶 ?步 ?此
80 ?正 ?是 ?辵 ?彳 ?廴 ?𢓊 ?行 ?齒 ?牙 ?足
81 ?疋 ?品 ?龠 ?冊 ?㗊 ?舌 ?干 ?谷 ?只 ?㕯
82 ?句 ?丩 ?古 ?十 ?卅 ?言 ?誩 ?音 ?䇂 ?丵
83 ?菐 ?𠬞 ?廾 ?共 ?異 ?舁 ?𦥑 ?䢅 ?爨 ?革
84 ?鬲 ?䰜 ?爪 ?𠃨 ?鬥 ?又 ?𠂇 ?㕜 ?支 ?𦘒
85 ?聿 ?畫 ?隶 ?堅 ?臣 ?殳 ?殺 ?𠘧 ?寸 ?皮
86 ?㼱 ?攴 ?敎 ?卜 ?用 ?爻 ?㸚 ?𥄎 ?目 ?䀠
87 ?眉 ?盾 ?自 ?白 ?鼻 ?皕 ?習 ?羽 ?隹 ?奞
88 ?萑 ?𦫳 ?苜 ?羊 ?羴 ?瞿 ?雔 ?雥 ?鳥 ?𠦒
89 ?冓 ?幺 ?𢆶 ?叀 ?玄 ?予 ?放 ?𠬪 ?𣦼 ?歺
90 ?死 ?冎 ?骨 ?肉 ?筋 ?刀 ?刃 ?㓞 ?丰 ?耒
93 (defun shuowen-radical (number)
94 (aref shuowen-radicals (1- number)))
96 (defvar char-db-file-coding-system 'utf-8-mcs-er)
98 (defvar char-db-feature-domains
99 '(ucs ucs/compat daikanwa cns gt jis jis/alt jis/a jis/b
100 jis-x0212 jis-x0213 cdp shinjigen misc unknown))
102 (defvar char-db-ignored-attributes '(ideographic-products))
104 (defun char-attribute-name< (ka kb)
106 ((eq '->denotational kb)
108 ((eq '->subsumptive kb)
109 (not (eq '->denotational ka)))
110 ((eq '->denotational ka)
112 ((eq '->subsumptive ka)
115 (string-match "^->" (symbol-name ka)))
116 (cond ((and (symbolp kb)
117 (string-match "^->" (symbol-name kb)))
118 (string< (symbol-name ka)
123 (string-match "^->" (symbol-name kb)))
126 (string-match "^<-" (symbol-name ka)))
128 (cond ((string-match "^<-" (symbol-name kb))
129 (string< (symbol-name ka)
132 ;; ((string-match "^->" (symbol-name kb))
137 (string-match "^<-" (symbol-name kb)))
139 ;; (not (string-match "^->" (symbol-name ka)))
142 (if (find-charset kb)
143 (if (<= (charset-id ka) 1)
144 (if (<= (charset-id kb) 1)
146 ((= (charset-dimension ka)
147 (charset-dimension kb))
148 (> (charset-id ka)(charset-id kb)))
150 (> (charset-dimension ka)
151 (charset-dimension kb))
154 (if (<= (charset-id kb) 1)
156 (< (charset-id ka)(charset-id kb))))
162 (string< (symbol-name ka)
168 (defvar char-db-coded-charset-priority-list
229 (defun char-db-make-char-spec (char)
231 (cond ((characterp char)
232 (cond ((and (setq ret (encode-char char '=ucs 'defined-only))
233 (not (and (<= #xE000 ret)(<= ret #xF8FF))))
234 (setq char-spec (list (cons '=ucs ret)))
235 (cond ((setq ret (get-char-attribute char 'name))
236 (setq char-spec (cons (cons 'name ret) char-spec))
238 ((setq ret (get-char-attribute char 'name*))
239 (setq char-spec (cons (cons 'name* ret) char-spec))
244 (let ((rest char-db-coded-charset-priority-list)
247 (setq ccs (charset-name
248 (find-charset (car rest))))
250 (encode-char char ccs
252 (throw 'tag (cons ccs ret)))
253 (setq rest (cdr rest))))))
254 (setq char-spec (list ret))
255 (dolist (ccs (delq (car ret) (charset-list)))
256 (if (and (or (charset-iso-final-char ccs)
263 (setq ccs (charset-name ccs))
264 (null (assq ccs char-spec))
265 (setq ret (encode-char char ccs 'defined-only)))
266 (setq char-spec (cons (cons ccs ret) char-spec))))
268 (setq char-spec (split-char char)))
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))
280 (defun char-db-insert-char-spec (char &optional readable column
283 (setq column (current-column)))
284 (let (char-spec temp-char)
285 (setq char-spec (char-db-make-char-spec char))
286 (unless (or (characterp char) ; char
288 (setq char (find-char char-spec))
290 ;; define temporary character
291 ;; Current implementation is dirty.
292 (setq temp-char (define-char (cons '(ideograph-daikanwa . 0)
294 (remove-char-attribute temp-char 'ideograph-daikanwa)
295 (setq char temp-char))
296 (insert-char-attributes char
298 (union (mapcar #'car char-spec)
301 ;; undefine temporary character
302 ;; Current implementation is dirty.
303 (setq char-spec (char-attribute-alist temp-char))
305 (remove-char-attribute temp-char (car (car char-spec)))
306 (setq char-spec (cdr char-spec))))))
308 (defun char-db-insert-alist (alist &optional readable column)
310 (setq column (current-column)))
312 (concat "\n" (make-string (1+ column) ?\ )))
316 lbs cell rest separator)
319 (setq name (car (car alist))
320 value (cdr (car alist)))
321 (cond ((eq name 'char)
323 (if (setq ret (condition-case nil
331 (setq key (car (car value)))
332 ;; (if (find-charset key)
333 ;; (setq cal (cons key cal))
334 (setq al (cons key al))
336 (setq value (cdr value)))
337 (insert-char-attributes ret
341 (insert (prin1-to-string value)))
343 (insert line-breaking))
345 (insert (format "(%-18s " name))
346 (setq lbs (concat "\n" (make-string (current-column) ?\ )))
348 (setq cell (car value))
349 (if (and (consp cell)
351 (setq ret (condition-case nil
361 (setq key (car (car rest)))
362 ;; (if (find-charset key)
363 ;; (setq cal (cons key cal))
364 (setq al (cons key al))
366 (setq rest (cdr rest)))
369 (insert-char-attributes ret
373 (setq separator lbs))
376 (insert (prin1-to-string cell))
377 (setq separator " "))
378 (setq value (cdr value)))
380 (insert line-breaking))
382 (insert (format "(%-18s . %S)%s"
385 (setq alist (cdr alist))))
388 (defun char-db-insert-char-reference (plist &optional readable column)
390 (setq column (current-column)))
392 (concat "\n" (make-string (1+ column) ?\ )))
397 (setq name (pop plist))
398 (setq value (pop plist))
399 (cond ((eq name :char)
402 (cond ((numberp value)
403 (setq value (decode-char '=ucs value)))
405 ;; (setq value (or (find-char value)
408 (char-db-insert-char-spec value readable)
409 (insert line-breaking)
412 (insert (format "%s%s\t%d ; %c%s"
415 (ideographic-radical value)
419 (insert (format "%s%s\t%S" separator name value))
420 (setq separator line-breaking)))
424 (defun char-db-decode-isolated-char (ccs code-point)
427 (cond ((eq ccs 'arabic-iso8859-6)
428 (decode-char ccs code-point))
429 ((and (memq ccs '(=gt-pj-1
440 (setq ret (decode-char ccs code-point))
441 (setq ret (encode-char ret '=gt 'defined-only)))
442 (decode-builtin-char '=gt ret))
444 (decode-builtin-char ccs code-point))))
445 (cond ((and (<= 0 (char-int ret))
446 (<= (char-int ret) #x1F))
447 (decode-char '=ucs (+ #x2400 (char-int ret))))
448 ((= (char-int ret) #x7F)
452 (defvar char-db-convert-obsolete-format t)
454 (defun char-db-insert-ccs-feature (name value line-breaking)
457 (cond ((or (memq name '(=daikanwa
458 =daikanwa@rev1 =daikanwa@rev2
459 =gt =gt-k =cbeta =zinbun-oracle))
460 (string-match "^=adobe-" (symbol-name name)))
461 "(%-18s . %05d)\t; %c")
463 "(%-18s . %06d)\t; %c")
464 ((>= (charset-dimension name) 2)
465 "(%-18s . #x%04X)\t; %c")
467 "(%-18s . #x%02X)\t; %c"))
469 (if (= (charset-iso-graphic-plane name) 1)
471 (cond ((= (charset-dimension name) 1)
473 ((= (charset-dimension name) 2)
475 ((= (charset-dimension name) 3)
479 (char-db-decode-isolated-char name value)))
480 (if (and (= (charset-chars name) 94)
481 (= (charset-dimension name) 2))
482 (insert (format " [%02d-%02d]"
483 (- (lsh value -8) 32)
484 (- (logand value 255) 32))))
485 (insert line-breaking))
487 (defun char-db-insert-relation-feature (char name value line-breaking
489 (insert (format "(%-18s%s " name line-breaking))
490 (let ((lbs (concat "\n" (make-string (current-column) ?\ )))
491 separator cell sources required-features
494 (setq cell (car value))
496 (setq cell (decode-char '=ucs cell)))
498 ((eq name '->subsumptive)
499 (when (or (not (some (lambda (atr)
500 (get-char-attribute cell atr))
501 char-db-ignored-attributes))
503 (encode-char cell ccs 'defined-only))
507 (let ((char-db-ignored-attributes
509 char-db-ignored-attributes)))
510 (insert-char-attributes cell readable))
511 (setq separator lbs))
516 char (intern (format "%s*sources" name))))
517 (setq required-features nil)
518 (dolist (source sources)
520 ((memq source '(JP JP/Jouyou shinjigen-1))
521 (setq required-features
522 (union required-features
531 (setq required-features
532 (union required-features
537 ((find-charset (setq ret (intern (format "=%s" source))))
538 (setq required-features
539 (cons ret required-features)))
540 (t (setq required-features
541 (cons source required-features)))))
542 (cond ((string-match "@JP" (symbol-name name))
543 (setq required-features
544 (union required-features
552 ((string-match "@CN" (symbol-name name))
553 (setq required-features
554 (union required-features
561 (insert (format "%S" cell))
562 (char-db-insert-char-spec cell readable
565 (setq separator lbs))
569 (if (consp (car cell))
570 (char-db-insert-char-spec cell readable)
571 (char-db-insert-char-reference cell readable))
572 (setq separator lbs))
576 (insert (prin1-to-string cell))
577 (setq separator " ")))
578 (setq value (cdr value)))
580 (insert line-breaking)))
582 (defun insert-char-attributes (char &optional readable attributes column)
584 (setq column (current-column)))
585 (let (name value ; has-long-ccs-name
589 (concat "\n" (make-string (1+ column) ?\ )))
590 lbs cell separator ret
592 dest-ccss ; sources required-features
597 (if (consp attributes)
599 (dolist (name attributes)
600 (unless (memq name char-db-ignored-attributes)
601 (if (find-charset name)
605 (dolist (name (char-attribute-list))
606 (unless (memq name char-db-ignored-attributes)
607 (if (find-charset name)
611 #'char-attribute-name<)))
613 (when (memq '<-subsumptive attributes)
615 (when (setq value (get-char-attribute char '<-subsumptive))
616 (char-db-insert-relation-feature char '<-subsumptive value
619 (setq attributes (delq '<-subsumptive attributes)))
620 (when (and (memq '<-denotational attributes)
621 (setq value (get-char-attribute char '<-denotational)))
622 (char-db-insert-relation-feature char '<-denotational value
625 (setq attributes (delq '<-denotational attributes)))
626 (when (and (memq 'name attributes)
627 (setq value (get-char-attribute char 'name)))
629 (if (> (+ (current-column) (length value)) 48)
632 value line-breaking))
633 (setq attributes (delq 'name attributes))
635 (when (and (memq 'name* attributes)
636 (setq value (get-char-attribute char 'name*)))
638 (if (> (+ (current-column) (length value)) 48)
641 value line-breaking))
642 (setq attributes (delq 'name* attributes))
644 (when (and (memq 'script attributes)
645 (setq value (get-char-attribute char 'script)))
646 (insert (format "(script\t\t%s)%s"
647 (mapconcat (function prin1-to-string)
650 (setq attributes (delq 'script attributes))
652 (dolist (name '(=>ucs =>ucs*))
653 (when (and (memq name attributes)
654 (setq value (get-char-attribute char name)))
655 (insert (format "(%-18s . #x%04X)\t; %c%s"
656 name value (decode-char '=ucs value)
658 (setq attributes (delq name attributes))))
659 (dolist (name '(=>ucs@gb =>ucs@cns =>ucs@jis =>ucs@ks =>ucs@big5))
660 (when (and (memq name attributes)
661 (setq value (get-char-attribute char name)))
662 (insert (format "(%-18s . #x%04X)\t; %c%s"
667 (symbol-name name) 2)))
670 (setq attributes (delq name attributes))
672 (dolist (name '(=>daikanwa))
673 (when (and (memq name attributes)
674 (setq value (get-char-attribute char name)))
677 (format "(%-18s . %05d)\t; %c%s"
678 name value (decode-char '=daikanwa value)
680 (format "(%-18s %s)\t; %c%s"
682 (mapconcat (function prin1-to-string)
684 (char-representative-of-daikanwa char)
686 (setq attributes (delq name attributes))))
687 (when (and (memq 'general-category attributes)
688 (setq value (get-char-attribute char 'general-category)))
690 "(general-category\t%s) ; %s%s"
691 (mapconcat (lambda (cell)
694 (cond ((rassoc value unidata-normative-category-alist)
695 "Normative Category")
696 ((rassoc value unidata-informative-category-alist)
697 "Informative Category")
701 (setq attributes (delq 'general-category attributes))
703 (when (and (memq 'bidi-category attributes)
704 (setq value (get-char-attribute char 'bidi-category)))
705 (insert (format "(bidi-category\t. %S)%s"
708 (setq attributes (delq 'bidi-category attributes))
710 (unless (or (not (memq 'mirrored attributes))
711 (eq (setq value (get-char-attribute char 'mirrored 'empty))
713 (insert (format "(mirrored\t\t. %S)%s"
716 (setq attributes (delq 'mirrored attributes))
719 ((and (memq 'decimal-digit-value attributes)
720 (setq value (get-char-attribute char 'decimal-digit-value)))
721 (insert (format "(decimal-digit-value . %S)%s"
724 (setq attributes (delq 'decimal-digit-value attributes))
725 (when (and (memq 'digit-value attributes)
726 (setq value (get-char-attribute char 'digit-value)))
727 (insert (format "(digit-value\t . %S)%s"
730 (setq attributes (delq 'digit-value attributes))
732 (when (and (memq 'numeric-value attributes)
733 (setq value (get-char-attribute char 'numeric-value)))
734 (insert (format "(numeric-value\t . %S)%s"
737 (setq attributes (delq 'numeric-value attributes))
741 (when (and (memq 'digit-value attributes)
742 (setq value (get-char-attribute char 'digit-value)))
743 (insert (format "(digit-value\t. %S)%s"
746 (setq attributes (delq 'digit-value attributes))
748 (when (and (memq 'numeric-value attributes)
749 (setq value (get-char-attribute char 'numeric-value)))
750 (insert (format "(numeric-value\t. %S)%s"
753 (setq attributes (delq 'numeric-value attributes))
755 (when (and (memq 'iso-10646-comment attributes)
756 (setq value (get-char-attribute char 'iso-10646-comment)))
757 (insert (format "(iso-10646-comment\t. %S)%s"
760 (setq attributes (delq 'iso-10646-comment attributes))
762 (when (and (memq 'morohashi-daikanwa attributes)
763 (setq value (get-char-attribute char 'morohashi-daikanwa)))
764 (insert (format "(morohashi-daikanwa\t%s)%s"
765 (mapconcat (function prin1-to-string) value " ")
767 (setq attributes (delq 'morohashi-daikanwa attributes))
771 (when (and (memq 'ideographic-radical attributes)
772 (setq value (get-char-attribute char 'ideographic-radical)))
774 (insert (format "(ideographic-radical . %S)\t; %c%s"
776 (ideographic-radical radical)
778 (setq attributes (delq 'ideographic-radical attributes))
780 (when (and (memq 'shuowen-radical attributes)
781 (setq value (get-char-attribute char 'shuowen-radical)))
782 (insert (format "(shuowen-radical\t. %S)\t; %c%s"
784 (shuowen-radical value)
786 (setq attributes (delq 'shuowen-radical attributes))
791 char-db-feature-domains
793 (dolist (feature (char-attribute-list))
794 (setq feature (symbol-name feature))
796 "\\(radical\\|strokes\\)@\\([^@*]+\\)\\(\\*\\|$\\)"
798 (setq domain (intern (match-string 2 feature)))
799 (unless (memq domain dest)
800 (setq dest (cons domain dest)))))
801 (sort dest #'string<))))
802 (setq key (intern (format "%s@%s" 'ideographic-radical domain)))
803 (when (and (memq key attributes)
804 (setq value (get-char-attribute char key)))
806 (insert (format "(%s . %S)\t; %c%s"
809 (ideographic-radical radical)
811 (setq attributes (delq key attributes))
813 (setq key (intern (format "%s@%s" 'ideographic-strokes domain)))
814 (when (and (memq key attributes)
815 (setq value (get-char-attribute char key)))
817 (insert (format "(%s . %S)%s"
821 (setq attributes (delq key attributes))
823 (setq key (intern (format "%s@%s" 'total-strokes domain)))
824 (when (and (memq key attributes)
825 (setq value (get-char-attribute char key)))
826 (insert (format "(%s . %S)%s"
830 (setq attributes (delq key attributes))
832 (dolist (feature '(ideographic-radical
835 (setq key (intern (format "%s@%s*sources" feature domain)))
836 (when (and (memq key attributes)
837 (setq value (get-char-attribute char key)))
838 (insert (format "(%s%s" key line-breaking))
840 (insert (format " %s" cell)))
842 (insert line-breaking)
843 (setq attributes (delq key attributes))
846 (when (and (memq 'ideographic-strokes attributes)
847 (setq value (get-char-attribute char 'ideographic-strokes)))
849 (insert (format "(ideographic-strokes . %S)%s"
852 (setq attributes (delq 'ideographic-strokes attributes))
854 (when (and (memq 'kangxi-radical attributes)
855 (setq value (get-char-attribute char 'kangxi-radical)))
856 (unless (eq value radical)
857 (insert (format "(kangxi-radical\t . %S)\t; %c%s"
859 (ideographic-radical value)
862 (setq radical value)))
863 (setq attributes (delq 'kangxi-radical attributes))
865 (when (and (memq 'kangxi-strokes attributes)
866 (setq value (get-char-attribute char 'kangxi-strokes)))
867 (unless (eq value strokes)
868 (insert (format "(kangxi-strokes\t . %S)%s"
872 (setq strokes value)))
873 (setq attributes (delq 'kangxi-strokes attributes))
875 (when (and (memq 'japanese-radical attributes)
876 (setq value (get-char-attribute char 'japanese-radical)))
877 (unless (eq value radical)
878 (insert (format "(japanese-radical\t . %S)\t; %c%s"
880 (ideographic-radical value)
883 (setq radical value)))
884 (setq attributes (delq 'japanese-radical attributes))
886 (when (and (memq 'japanese-strokes attributes)
887 (setq value (get-char-attribute char 'japanese-strokes)))
888 (unless (eq value strokes)
889 (insert (format "(japanese-strokes\t . %S)%s"
893 (setq strokes value)))
894 (setq attributes (delq 'japanese-strokes attributes))
896 (when (and (memq 'cns-radical attributes)
897 (setq value (get-char-attribute char 'cns-radical)))
898 (insert (format "(cns-radical\t . %S)\t; %c%s"
900 (ideographic-radical value)
902 (setq attributes (delq 'cns-radical attributes))
904 (when (and (memq 'cns-strokes attributes)
905 (setq value (get-char-attribute char 'cns-strokes)))
906 (unless (eq value strokes)
907 (insert (format "(cns-strokes\t . %S)%s"
911 (setq strokes value)))
912 (setq attributes (delq 'cns-strokes attributes))
914 (when (and (memq 'shinjigen-1-radical attributes)
915 (setq value (get-char-attribute char 'shinjigen-1-radical)))
916 (unless (eq value radical)
917 (insert (format "(shinjigen-1-radical . %S)\t; %c%s"
919 (ideographic-radical value)
922 (setq radical value)))
923 (setq attributes (delq 'shinjigen-1-radical attributes))
925 (when (and (memq 'ideographic- attributes)
926 (setq value (get-char-attribute char 'ideographic-)))
927 (insert "(ideographic- ")
928 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
931 (setq cell (car value))
933 (setq cell (decode-char '=ucs cell)))
934 (cond ((characterp cell)
938 (insert (format "%S" cell))
939 (char-db-insert-char-spec cell readable))
940 (setq separator lbs))
944 (if (consp (car cell))
945 (char-db-insert-char-spec cell readable)
946 (char-db-insert-char-reference cell readable))
947 (setq separator lbs))
951 (insert (prin1-to-string cell))
952 (setq separator " ")))
953 (setq value (cdr value)))
955 (insert line-breaking)
956 (setq attributes (delq 'ideographic- attributes)))
957 (when (and (memq 'total-strokes attributes)
958 (setq value (get-char-attribute char 'total-strokes)))
959 (insert (format "(total-strokes . %S)%s"
962 (setq attributes (delq 'total-strokes attributes))
964 (when (and (memq '->ideograph attributes)
965 (setq value (get-char-attribute char '->ideograph)))
966 (insert (format "(->ideograph\t%s)%s"
967 (mapconcat (lambda (code)
968 (cond ((symbolp code)
971 (format "#x%04X" code))
974 line-breaking code))))
977 (setq attributes (delq '->ideograph attributes))
979 ;; (when (and (memq '->decomposition attributes)
980 ;; (setq value (get-char-attribute char '->decomposition)))
981 ;; (insert (format "(->decomposition\t%s)%s"
982 ;; (mapconcat (lambda (code)
983 ;; (cond ((symbolp code)
984 ;; (symbol-name code))
985 ;; ((characterp code)
987 ;; (format "%S" code)
992 ;; (format "#x%04X" code))
994 ;; (format "%s%S" line-breaking code))))
997 ;; (setq attributes (delq '->decomposition attributes))
999 (if (equal (get-char-attribute char '->titlecase)
1000 (get-char-attribute char '->uppercase))
1001 (setq attributes (delq '->titlecase attributes)))
1002 (when (and (memq '->mojikyo attributes)
1003 (setq value (get-char-attribute char '->mojikyo)))
1004 (insert (format "(->mojikyo\t\t. %06d)\t; %c%s"
1005 value (decode-char 'mojikyo value)
1007 (setq attributes (delq '->mojikyo attributes))
1009 (when (and (memq 'hanyu-dazidian-vol attributes)
1010 (setq value (get-char-attribute char 'hanyu-dazidian-vol)))
1011 (insert (format "(hanyu-dazidian-vol . %d)%s"
1012 value line-breaking))
1013 (setq attributes (delq 'hanyu-dazidian-vol attributes))
1015 (when (and (memq 'hanyu-dazidian-page attributes)
1016 (setq value (get-char-attribute char 'hanyu-dazidian-page)))
1017 (insert (format "(hanyu-dazidian-page . %d)%s"
1018 value line-breaking))
1019 (setq attributes (delq 'hanyu-dazidian-page attributes))
1021 (when (and (memq 'hanyu-dazidian-char attributes)
1022 (setq value (get-char-attribute char 'hanyu-dazidian-char)))
1023 (insert (format "(hanyu-dazidian-char . %d)%s"
1024 value line-breaking))
1025 (setq attributes (delq 'hanyu-dazidian-char attributes))
1028 (dolist (ignored '(composition
1029 ->denotational <-subsumptive ->ucs-unified
1030 ->ideographic-component-forms))
1031 (setq attributes (delq ignored attributes))))
1033 (setq name (car attributes))
1034 (if (setq value (get-char-attribute char name))
1035 (cond ((setq ret (find-charset name))
1036 (setq name (charset-name ret))
1037 (if (and (not (memq name dest-ccss))
1039 (setq value (get-char-attribute char name))
1040 (setq dest-ccss (cons name dest-ccss))))
1041 (char-db-insert-ccs-feature name value line-breaking))
1043 ((string-match "^=>ucs@" (symbol-name name))
1044 (insert (format "(%-18s . #x%04X)\t; %c%s"
1045 name value (decode-char '=ucs value)
1048 ((eq name 'jisx0208-1978/4X)
1049 (insert (format "(%-18s . #x%04X)%s"
1055 (not (eq name '->subsumptive))
1056 (not (eq name '->uppercase))
1057 (not (eq name '->lowercase))
1058 (not (eq name '->titlecase))
1059 (not (eq name '->canonical))
1060 (not (eq name '->Bopomofo))
1061 (not (eq name '->mistakable))
1062 (not (eq name '->ideographic-variants))
1063 (null (get-char-attribute
1064 char (intern (format "%s*sources" name))))
1065 (not (string-match "\\*sources$" (symbol-name name)))
1066 (null (get-char-attribute
1067 char (intern (format "%s*note" name))))
1068 (not (string-match "\\*note$" (symbol-name name)))
1069 (or (eq name '<-identical)
1070 (eq name '<-uppercase)
1071 (eq name '<-lowercase)
1072 (eq name '<-titlecase)
1073 (eq name '<-canonical)
1074 (eq name '<-ideographic-variants)
1075 ;; (eq name '<-synonyms)
1076 (string-match "^<-synonyms" (symbol-name name))
1077 (eq name '<-mistakable)
1078 (when (string-match "^->" (symbol-name name))
1080 ((string-match "^->fullwidth" (symbol-name name))
1081 (not (and (consp value)
1082 (characterp (car value))
1084 (car value) '=ucs 'defined-only)))
1089 ((or (eq name 'ideographic-structure)
1090 (eq name 'ideographic-combination)
1091 (eq name 'ideographic-)
1092 (eq name '=decomposition)
1093 (string-match "^=>decomposition" (symbol-name name))
1094 (string-match "^\\(->\\|<-\\)[^*]*$" (symbol-name name))
1095 (string-match "^\\(->\\|<-\\)[^*]*\\*sources$"
1098 (char-db-insert-relation-feature char name value
1101 ((memq name '(ideograph=
1102 original-ideograph-of
1103 ancient-ideograph-of
1106 ;; simplified-ideograph-of
1107 ideographic-variants
1108 ;; ideographic-different-form-of
1110 (insert (format "(%-18s%s " name line-breaking))
1111 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1113 (while (consp value)
1114 (setq cell (car value))
1115 (if (and (consp cell)
1120 (char-db-insert-alist cell readable)
1121 (setq separator lbs))
1124 (insert (prin1-to-string cell))
1125 (setq separator " "))
1126 (setq value (cdr value)))
1128 (insert line-breaking))
1130 (insert (format "(%-18s " name))
1131 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1133 (while (consp value)
1134 (setq cell (car value))
1135 (if (and (consp cell)
1137 (setq ret (condition-case nil
1145 (setq key (car (car rest)))
1146 (if (find-charset key)
1147 (setq cal (cons key cal))
1148 (setq al (cons key al)))
1149 (setq rest (cdr rest)))
1152 (insert-char-attributes ret
1155 (setq separator lbs))
1156 (setq ret (prin1-to-string cell))
1158 (if (< (+ (current-column)
1165 (setq separator " "))
1166 (setq value (cdr value)))
1168 (insert line-breaking))
1170 (insert (format "(%-18s" name))
1171 (setq ret (prin1-to-string value))
1172 (unless (< (+ (current-column)
1176 (insert line-breaking))
1177 (insert " . " ret ")" line-breaking)
1178 ;; (insert (format "(%-18s . %S)%s"
1183 (setq attributes (cdr attributes)))
1186 (defun insert-char-data (char &optional readable
1189 (narrow-to-region (point)(point))
1190 (insert "(define-char
1192 (insert-char-attributes char readable attributes)
1194 (goto-char (point-min))
1195 (while (re-search-forward "[ \t]+$" nil t)
1198 (goto-char (point-min))
1199 (while (re-search-forward "[ \t][ \t][ \t]*" nil t)
1200 (let ((column (current-column))
1201 (indent-tabs-mode t))
1202 (delete-region (match-beginning 0) (point))
1203 (indent-to column)))
1204 (goto-char (point-max))
1205 ;; (tabify (point-min)(point-max))
1208 (defun insert-char-data-with-variant (char &optional printable
1210 script excluded-script)
1211 (insert-char-data char printable)
1212 (let ((variants (char-variants char))
1215 (setq variants (sort variants #'<))
1216 (setq rest variants)
1217 (setq variants (cons char variants))
1219 (setq variant (car rest))
1220 (unless (get-char-attribute variant '<-subsumptive)
1221 (if (and (or (null script)
1222 (null (setq vs (get-char-attribute variant 'script)))
1224 (or (null excluded-script)
1225 (null (setq vs (get-char-attribute variant 'script)))
1226 (not (memq excluded-script vs))))
1227 (unless (and no-ucs-unified (get-char-attribute variant '=ucs))
1228 (insert-char-data variant printable)
1229 (if (setq ret (char-variants variant))
1231 (or (memq (car ret) variants)
1232 ;; (get-char-attribute (car ret) '<-subsumptive)
1233 (setq rest (nconc rest (list (car ret)))))
1234 (setq ret (cdr ret)))))))
1235 (setq rest (cdr rest)))))
1237 (defun insert-char-range-data (min max &optional script excluded-script)
1240 (while (<= code max)
1241 (setq char (decode-char '=ucs code))
1242 (if (encode-char char '=ucs 'defined-only)
1243 (insert-char-data-with-variant char nil 'no-ucs-unified
1244 script excluded-script))
1245 (setq code (1+ code)))))
1247 (defun write-char-range-data-to-file (min max file
1248 &optional script excluded-script)
1249 (let ((coding-system-for-write char-db-file-coding-system))
1251 (insert (format ";; -*- coding: %s -*-\n"
1252 char-db-file-coding-system))
1253 (insert-char-range-data min max script excluded-script)
1254 (write-region (point-min)(point-max) file))))
1256 (defvar what-character-original-window-configuration)
1259 (defun what-char-definition (char)
1260 (interactive (list (char-after)))
1261 (let ((buf (get-buffer-create "*Character Description*"))
1262 (the-buf (current-buffer))
1263 (win-conf (current-window-configuration)))
1265 (make-local-variable 'what-character-original-window-configuration)
1266 (setq what-character-original-window-configuration win-conf)
1267 (setq buffer-read-only nil)
1271 (insert-char-data-with-variant char 'printable)
1272 (unless (char-attribute-alist char)
1273 (insert (format ";; = %c\n"
1274 (let* ((rest (split-char char))
1278 (setq code (logior (lsh code 8)
1280 (decode-char ccs code)))))
1281 ;; (char-db-update-comment)
1282 (set-buffer-modified-p nil)
1283 (view-mode the-buf (lambda (buf)
1284 (set-window-configuration
1285 what-character-original-window-configuration)
1287 (goto-char (point-min)))
1289 (set-window-configuration
1290 what-character-original-window-configuration)
1291 (signal (car err) (cdr err)))))))
1293 (provide 'char-db-util)
1295 ;;; char-db-util.el ends here