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 ?告 ?口 ?凵 ?吅 ?哭 ?走 ?止 ?癶 ?步 ?此
82 (defun shuowen-radical (number)
83 (aref shuowen-radicals (1- number)))
85 (defvar char-db-file-coding-system 'utf-8-mcs-er)
87 (defvar char-db-feature-domains
88 '(ucs ucs/compat daikanwa cns gt jis jis/alt jis/a jis/b
89 jis-x0212 jis-x0213 cdp shinjigen misc unknown))
91 (defvar char-db-ignored-attributes '(ideographic-products))
93 (defun char-attribute-name< (ka kb)
95 ((eq '->denotational kb)
97 ((eq '->subsumptive kb)
98 (not (eq '->denotational ka)))
99 ((eq '->denotational ka)
101 ((eq '->subsumptive ka)
104 (string-match "^->" (symbol-name ka)))
105 (cond ((and (symbolp kb)
106 (string-match "^->" (symbol-name kb)))
107 (string< (symbol-name ka)
112 (string-match "^->" (symbol-name kb)))
115 (string-match "^<-" (symbol-name ka)))
117 (cond ((string-match "^<-" (symbol-name kb))
118 (string< (symbol-name ka)
121 ;; ((string-match "^->" (symbol-name kb))
126 (string-match "^<-" (symbol-name kb)))
128 ;; (not (string-match "^->" (symbol-name ka)))
131 (if (find-charset kb)
132 (if (<= (charset-id ka) 1)
133 (if (<= (charset-id kb) 1)
135 ((= (charset-dimension ka)
136 (charset-dimension kb))
137 (> (charset-id ka)(charset-id kb)))
139 (> (charset-dimension ka)
140 (charset-dimension kb))
143 (if (<= (charset-id kb) 1)
145 (< (charset-id ka)(charset-id kb))))
151 (string< (symbol-name ka)
157 (defvar char-db-coded-charset-priority-list
218 (defun char-db-make-char-spec (char)
220 (cond ((characterp char)
221 (cond ((and (setq ret (encode-char char '=ucs 'defined-only))
222 (not (and (<= #xE000 ret)(<= ret #xF8FF))))
223 (setq char-spec (list (cons '=ucs ret)))
224 (cond ((setq ret (get-char-attribute char 'name))
225 (setq char-spec (cons (cons 'name ret) char-spec))
227 ((setq ret (get-char-attribute char 'name*))
228 (setq char-spec (cons (cons 'name* ret) char-spec))
233 (let ((rest char-db-coded-charset-priority-list)
236 (setq ccs (charset-name
237 (find-charset (car rest))))
239 (encode-char char ccs
241 (throw 'tag (cons ccs ret)))
242 (setq rest (cdr rest))))))
243 (setq char-spec (list ret))
244 (dolist (ccs (delq (car ret) (charset-list)))
245 (if (and (or (charset-iso-final-char ccs)
252 (setq ccs (charset-name ccs))
253 (null (assq ccs char-spec))
254 (setq ret (encode-char char ccs 'defined-only)))
255 (setq char-spec (cons (cons ccs ret) char-spec))))
257 (setq char-spec (split-char char)))
258 (cond ((setq ret (get-char-attribute char 'name))
259 (setq char-spec (cons (cons 'name ret) char-spec))
261 ((setq ret (get-char-attribute char 'name*))
262 (setq char-spec (cons (cons 'name* ret) char-spec))
269 (defun char-db-insert-char-spec (char &optional readable column
272 (setq column (current-column)))
273 (let (char-spec temp-char)
274 (setq char-spec (char-db-make-char-spec char))
275 (unless (or (characterp char) ; char
277 (setq char (find-char char-spec))
279 ;; define temporary character
280 ;; Current implementation is dirty.
281 (setq temp-char (define-char (cons '(ideograph-daikanwa . 0)
283 (remove-char-attribute temp-char 'ideograph-daikanwa)
284 (setq char temp-char))
285 (insert-char-attributes char
287 (union (mapcar #'car char-spec)
290 ;; undefine temporary character
291 ;; Current implementation is dirty.
292 (setq char-spec (char-attribute-alist temp-char))
294 (remove-char-attribute temp-char (car (car char-spec)))
295 (setq char-spec (cdr char-spec))))))
297 (defun char-db-insert-alist (alist &optional readable column)
299 (setq column (current-column)))
301 (concat "\n" (make-string (1+ column) ?\ )))
305 lbs cell rest separator)
308 (setq name (car (car alist))
309 value (cdr (car alist)))
310 (cond ((eq name 'char)
312 (if (setq ret (condition-case nil
320 (setq key (car (car value)))
321 ;; (if (find-charset key)
322 ;; (setq cal (cons key cal))
323 (setq al (cons key al))
325 (setq value (cdr value)))
326 (insert-char-attributes ret
330 (insert (prin1-to-string value)))
332 (insert line-breaking))
334 (insert (format "(%-18s " name))
335 (setq lbs (concat "\n" (make-string (current-column) ?\ )))
337 (setq cell (car value))
338 (if (and (consp cell)
340 (setq ret (condition-case nil
350 (setq key (car (car rest)))
351 ;; (if (find-charset key)
352 ;; (setq cal (cons key cal))
353 (setq al (cons key al))
355 (setq rest (cdr rest)))
358 (insert-char-attributes ret
362 (setq separator lbs))
365 (insert (prin1-to-string cell))
366 (setq separator " "))
367 (setq value (cdr value)))
369 (insert line-breaking))
371 (insert (format "(%-18s . %S)%s"
374 (setq alist (cdr alist))))
377 (defun char-db-insert-char-reference (plist &optional readable column)
379 (setq column (current-column)))
381 (concat "\n" (make-string (1+ column) ?\ )))
386 (setq name (pop plist))
387 (setq value (pop plist))
388 (cond ((eq name :char)
391 (cond ((numberp value)
392 (setq value (decode-char '=ucs value)))
394 ;; (setq value (or (find-char value)
397 (char-db-insert-char-spec value readable)
398 (insert line-breaking)
401 (insert (format "%s%s\t%d ; %c%s"
404 (ideographic-radical value)
408 (insert (format "%s%s\t%S" separator name value))
409 (setq separator line-breaking)))
413 (defun char-db-decode-isolated-char (ccs code-point)
416 (cond ((eq ccs 'arabic-iso8859-6)
417 (decode-char ccs code-point))
418 ((and (memq ccs '(=gt-pj-1
429 (setq ret (decode-char ccs code-point))
430 (setq ret (encode-char ret '=gt 'defined-only)))
431 (decode-builtin-char '=gt ret))
433 (decode-builtin-char ccs code-point))))
434 (cond ((and (<= 0 (char-int ret))
435 (<= (char-int ret) #x1F))
436 (decode-char '=ucs (+ #x2400 (char-int ret))))
437 ((= (char-int ret) #x7F)
441 (defvar char-db-convert-obsolete-format t)
443 (defun char-db-insert-ccs-feature (name value line-breaking)
446 (cond ((or (memq name '(=daikanwa
447 =daikanwa@rev1 =daikanwa@rev2
448 =gt =gt-k =cbeta =zinbun-oracle))
449 (string-match "^=adobe-" (symbol-name name)))
450 "(%-18s . %05d)\t; %c")
452 "(%-18s . %06d)\t; %c")
453 ((>= (charset-dimension name) 2)
454 "(%-18s . #x%04X)\t; %c")
456 "(%-18s . #x%02X)\t; %c"))
458 (if (= (charset-iso-graphic-plane name) 1)
460 (cond ((= (charset-dimension name) 1)
462 ((= (charset-dimension name) 2)
464 ((= (charset-dimension name) 3)
468 (char-db-decode-isolated-char name value)))
469 (if (and (= (charset-chars name) 94)
470 (= (charset-dimension name) 2))
471 (insert (format " [%02d-%02d]"
472 (- (lsh value -8) 32)
473 (- (logand value 255) 32))))
474 (insert line-breaking))
476 (defun char-db-insert-relation-feature (char name value line-breaking
478 (insert (format "(%-18s%s " name line-breaking))
479 (let ((lbs (concat "\n" (make-string (current-column) ?\ )))
480 separator cell sources required-features
483 (setq cell (car value))
485 (setq cell (decode-char '=ucs cell)))
487 ((eq name '->subsumptive)
488 (when (or (not (some (lambda (atr)
489 (get-char-attribute cell atr))
490 char-db-ignored-attributes))
492 (encode-char cell ccs 'defined-only))
496 (let ((char-db-ignored-attributes
498 char-db-ignored-attributes)))
499 (insert-char-attributes cell readable))
500 (setq separator lbs))
505 char (intern (format "%s*sources" name))))
506 (setq required-features nil)
507 (dolist (source sources)
509 ((memq source '(JP JP/Jouyou shinjigen-1))
510 (setq required-features
511 (union required-features
520 (setq required-features
521 (union required-features
526 ((find-charset (setq ret (intern (format "=%s" source))))
527 (setq required-features
528 (cons ret required-features)))
529 (t (setq required-features
530 (cons source required-features)))))
531 (cond ((string-match "@JP" (symbol-name name))
532 (setq required-features
533 (union required-features
541 ((string-match "@CN" (symbol-name name))
542 (setq required-features
543 (union required-features
550 (insert (format "%S" cell))
551 (char-db-insert-char-spec cell readable
554 (setq separator lbs))
558 (if (consp (car cell))
559 (char-db-insert-char-spec cell readable)
560 (char-db-insert-char-reference cell readable))
561 (setq separator lbs))
565 (insert (prin1-to-string cell))
566 (setq separator " ")))
567 (setq value (cdr value)))
569 (insert line-breaking)))
571 (defun insert-char-attributes (char &optional readable attributes column)
573 (setq column (current-column)))
574 (let (name value ; has-long-ccs-name
578 (concat "\n" (make-string (1+ column) ?\ )))
579 lbs cell separator ret
581 dest-ccss ; sources required-features
586 (if (consp attributes)
588 (dolist (name attributes)
589 (unless (memq name char-db-ignored-attributes)
590 (if (find-charset name)
594 (dolist (name (char-attribute-list))
595 (unless (memq name char-db-ignored-attributes)
596 (if (find-charset name)
600 #'char-attribute-name<)))
602 (when (memq '<-subsumptive attributes)
604 (when (setq value (get-char-attribute char '<-subsumptive))
605 (char-db-insert-relation-feature char '<-subsumptive value
608 (setq attributes (delq '<-subsumptive attributes)))
609 (when (and (memq '<-denotational attributes)
610 (setq value (get-char-attribute char '<-denotational)))
611 (char-db-insert-relation-feature char '<-denotational value
614 (setq attributes (delq '<-denotational attributes)))
615 (when (and (memq 'name attributes)
616 (setq value (get-char-attribute char 'name)))
618 (if (> (+ (current-column) (length value)) 48)
621 value line-breaking))
622 (setq attributes (delq 'name attributes))
624 (when (and (memq 'name* attributes)
625 (setq value (get-char-attribute char 'name*)))
627 (if (> (+ (current-column) (length value)) 48)
630 value line-breaking))
631 (setq attributes (delq 'name* attributes))
633 (when (and (memq 'script attributes)
634 (setq value (get-char-attribute char 'script)))
635 (insert (format "(script\t\t%s)%s"
636 (mapconcat (function prin1-to-string)
639 (setq attributes (delq 'script attributes))
641 (dolist (name '(=>ucs =>ucs*))
642 (when (and (memq name attributes)
643 (setq value (get-char-attribute char name)))
644 (insert (format "(%-18s . #x%04X)\t; %c%s"
645 name value (decode-char '=ucs value)
647 (setq attributes (delq name attributes))))
648 (dolist (name '(=>ucs@gb =>ucs@cns =>ucs@jis =>ucs@ks =>ucs@big5))
649 (when (and (memq name attributes)
650 (setq value (get-char-attribute char name)))
651 (insert (format "(%-18s . #x%04X)\t; %c%s"
656 (symbol-name name) 2)))
659 (setq attributes (delq name attributes))
661 (dolist (name '(=>daikanwa))
662 (when (and (memq name attributes)
663 (setq value (get-char-attribute char name)))
666 (format "(%-18s . %05d)\t; %c%s"
667 name value (decode-char '=daikanwa value)
669 (format "(%-18s %s)\t; %c%s"
671 (mapconcat (function prin1-to-string)
673 (char-representative-of-daikanwa char)
675 (setq attributes (delq name attributes))))
676 (when (and (memq 'general-category attributes)
677 (setq value (get-char-attribute char 'general-category)))
679 "(general-category\t%s) ; %s%s"
680 (mapconcat (lambda (cell)
683 (cond ((rassoc value unidata-normative-category-alist)
684 "Normative Category")
685 ((rassoc value unidata-informative-category-alist)
686 "Informative Category")
690 (setq attributes (delq 'general-category attributes))
692 (when (and (memq 'bidi-category attributes)
693 (setq value (get-char-attribute char 'bidi-category)))
694 (insert (format "(bidi-category\t. %S)%s"
697 (setq attributes (delq 'bidi-category attributes))
699 (unless (or (not (memq 'mirrored attributes))
700 (eq (setq value (get-char-attribute char 'mirrored 'empty))
702 (insert (format "(mirrored\t\t. %S)%s"
705 (setq attributes (delq 'mirrored attributes))
708 ((and (memq 'decimal-digit-value attributes)
709 (setq value (get-char-attribute char 'decimal-digit-value)))
710 (insert (format "(decimal-digit-value . %S)%s"
713 (setq attributes (delq 'decimal-digit-value attributes))
714 (when (and (memq 'digit-value attributes)
715 (setq value (get-char-attribute char 'digit-value)))
716 (insert (format "(digit-value\t . %S)%s"
719 (setq attributes (delq 'digit-value attributes))
721 (when (and (memq 'numeric-value attributes)
722 (setq value (get-char-attribute char 'numeric-value)))
723 (insert (format "(numeric-value\t . %S)%s"
726 (setq attributes (delq 'numeric-value attributes))
730 (when (and (memq 'digit-value attributes)
731 (setq value (get-char-attribute char 'digit-value)))
732 (insert (format "(digit-value\t. %S)%s"
735 (setq attributes (delq 'digit-value attributes))
737 (when (and (memq 'numeric-value attributes)
738 (setq value (get-char-attribute char 'numeric-value)))
739 (insert (format "(numeric-value\t. %S)%s"
742 (setq attributes (delq 'numeric-value attributes))
744 (when (and (memq 'iso-10646-comment attributes)
745 (setq value (get-char-attribute char 'iso-10646-comment)))
746 (insert (format "(iso-10646-comment\t. %S)%s"
749 (setq attributes (delq 'iso-10646-comment attributes))
751 (when (and (memq 'morohashi-daikanwa attributes)
752 (setq value (get-char-attribute char 'morohashi-daikanwa)))
753 (insert (format "(morohashi-daikanwa\t%s)%s"
754 (mapconcat (function prin1-to-string) value " ")
756 (setq attributes (delq 'morohashi-daikanwa attributes))
760 (when (and (memq 'ideographic-radical attributes)
761 (setq value (get-char-attribute char 'ideographic-radical)))
763 (insert (format "(ideographic-radical . %S)\t; %c%s"
765 (ideographic-radical radical)
767 (setq attributes (delq 'ideographic-radical attributes))
769 (when (and (memq 'shuowen-radical attributes)
770 (setq value (get-char-attribute char 'shuowen-radical)))
771 (insert (format "(shuowen-radical\t. %S)\t; %c%s"
773 (shuowen-radical value)
775 (setq attributes (delq 'shuowen-radical attributes))
780 char-db-feature-domains
782 (dolist (feature (char-attribute-list))
783 (setq feature (symbol-name feature))
785 "\\(radical\\|strokes\\)@\\([^@*]+\\)\\(\\*\\|$\\)"
787 (setq domain (intern (match-string 2 feature)))
788 (unless (memq domain dest)
789 (setq dest (cons domain dest)))))
790 (sort dest #'string<))))
791 (setq key (intern (format "%s@%s" 'ideographic-radical domain)))
792 (when (and (memq key attributes)
793 (setq value (get-char-attribute char key)))
795 (insert (format "(%s . %S)\t; %c%s"
798 (ideographic-radical radical)
800 (setq attributes (delq key attributes))
802 (setq key (intern (format "%s@%s" 'ideographic-strokes domain)))
803 (when (and (memq key attributes)
804 (setq value (get-char-attribute char key)))
806 (insert (format "(%s . %S)%s"
810 (setq attributes (delq key attributes))
812 (setq key (intern (format "%s@%s" 'total-strokes domain)))
813 (when (and (memq key attributes)
814 (setq value (get-char-attribute char key)))
815 (insert (format "(%s . %S)%s"
819 (setq attributes (delq key attributes))
821 (dolist (feature '(ideographic-radical
824 (setq key (intern (format "%s@%s*sources" feature domain)))
825 (when (and (memq key attributes)
826 (setq value (get-char-attribute char key)))
827 (insert (format "(%s%s" key line-breaking))
829 (insert (format " %s" cell)))
831 (insert line-breaking)
832 (setq attributes (delq key attributes))
835 (when (and (memq 'ideographic-strokes attributes)
836 (setq value (get-char-attribute char 'ideographic-strokes)))
838 (insert (format "(ideographic-strokes . %S)%s"
841 (setq attributes (delq 'ideographic-strokes attributes))
843 (when (and (memq 'kangxi-radical attributes)
844 (setq value (get-char-attribute char 'kangxi-radical)))
845 (unless (eq value radical)
846 (insert (format "(kangxi-radical\t . %S)\t; %c%s"
848 (ideographic-radical value)
851 (setq radical value)))
852 (setq attributes (delq 'kangxi-radical attributes))
854 (when (and (memq 'kangxi-strokes attributes)
855 (setq value (get-char-attribute char 'kangxi-strokes)))
856 (unless (eq value strokes)
857 (insert (format "(kangxi-strokes\t . %S)%s"
861 (setq strokes value)))
862 (setq attributes (delq 'kangxi-strokes attributes))
864 (when (and (memq 'japanese-radical attributes)
865 (setq value (get-char-attribute char 'japanese-radical)))
866 (unless (eq value radical)
867 (insert (format "(japanese-radical\t . %S)\t; %c%s"
869 (ideographic-radical value)
872 (setq radical value)))
873 (setq attributes (delq 'japanese-radical attributes))
875 (when (and (memq 'japanese-strokes attributes)
876 (setq value (get-char-attribute char 'japanese-strokes)))
877 (unless (eq value strokes)
878 (insert (format "(japanese-strokes\t . %S)%s"
882 (setq strokes value)))
883 (setq attributes (delq 'japanese-strokes attributes))
885 (when (and (memq 'cns-radical attributes)
886 (setq value (get-char-attribute char 'cns-radical)))
887 (insert (format "(cns-radical\t . %S)\t; %c%s"
889 (ideographic-radical value)
891 (setq attributes (delq 'cns-radical attributes))
893 (when (and (memq 'cns-strokes attributes)
894 (setq value (get-char-attribute char 'cns-strokes)))
895 (unless (eq value strokes)
896 (insert (format "(cns-strokes\t . %S)%s"
900 (setq strokes value)))
901 (setq attributes (delq 'cns-strokes attributes))
903 (when (and (memq 'shinjigen-1-radical attributes)
904 (setq value (get-char-attribute char 'shinjigen-1-radical)))
905 (unless (eq value radical)
906 (insert (format "(shinjigen-1-radical . %S)\t; %c%s"
908 (ideographic-radical value)
911 (setq radical value)))
912 (setq attributes (delq 'shinjigen-1-radical attributes))
914 (when (and (memq 'ideographic- attributes)
915 (setq value (get-char-attribute char 'ideographic-)))
916 (insert "(ideographic- ")
917 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
920 (setq cell (car value))
922 (setq cell (decode-char '=ucs cell)))
923 (cond ((characterp cell)
927 (insert (format "%S" cell))
928 (char-db-insert-char-spec cell readable))
929 (setq separator lbs))
933 (if (consp (car cell))
934 (char-db-insert-char-spec cell readable)
935 (char-db-insert-char-reference cell readable))
936 (setq separator lbs))
940 (insert (prin1-to-string cell))
941 (setq separator " ")))
942 (setq value (cdr value)))
944 (insert line-breaking)
945 (setq attributes (delq 'ideographic- attributes)))
946 (when (and (memq 'total-strokes attributes)
947 (setq value (get-char-attribute char 'total-strokes)))
948 (insert (format "(total-strokes . %S)%s"
951 (setq attributes (delq 'total-strokes attributes))
953 (when (and (memq '->ideograph attributes)
954 (setq value (get-char-attribute char '->ideograph)))
955 (insert (format "(->ideograph\t%s)%s"
956 (mapconcat (lambda (code)
957 (cond ((symbolp code)
960 (format "#x%04X" code))
963 line-breaking code))))
966 (setq attributes (delq '->ideograph attributes))
968 ;; (when (and (memq '->decomposition attributes)
969 ;; (setq value (get-char-attribute char '->decomposition)))
970 ;; (insert (format "(->decomposition\t%s)%s"
971 ;; (mapconcat (lambda (code)
972 ;; (cond ((symbolp code)
973 ;; (symbol-name code))
974 ;; ((characterp code)
976 ;; (format "%S" code)
981 ;; (format "#x%04X" code))
983 ;; (format "%s%S" line-breaking code))))
986 ;; (setq attributes (delq '->decomposition attributes))
988 (if (equal (get-char-attribute char '->titlecase)
989 (get-char-attribute char '->uppercase))
990 (setq attributes (delq '->titlecase attributes)))
991 (when (and (memq '->mojikyo attributes)
992 (setq value (get-char-attribute char '->mojikyo)))
993 (insert (format "(->mojikyo\t\t. %06d)\t; %c%s"
994 value (decode-char 'mojikyo value)
996 (setq attributes (delq '->mojikyo attributes))
998 (when (and (memq 'hanyu-dazidian-vol attributes)
999 (setq value (get-char-attribute char 'hanyu-dazidian-vol)))
1000 (insert (format "(hanyu-dazidian-vol . %d)%s"
1001 value line-breaking))
1002 (setq attributes (delq 'hanyu-dazidian-vol attributes))
1004 (when (and (memq 'hanyu-dazidian-page attributes)
1005 (setq value (get-char-attribute char 'hanyu-dazidian-page)))
1006 (insert (format "(hanyu-dazidian-page . %d)%s"
1007 value line-breaking))
1008 (setq attributes (delq 'hanyu-dazidian-page attributes))
1010 (when (and (memq 'hanyu-dazidian-char attributes)
1011 (setq value (get-char-attribute char 'hanyu-dazidian-char)))
1012 (insert (format "(hanyu-dazidian-char . %d)%s"
1013 value line-breaking))
1014 (setq attributes (delq 'hanyu-dazidian-char attributes))
1017 (dolist (ignored '(composition
1018 ->denotational <-subsumptive ->ucs-unified
1019 ->ideographic-component-forms))
1020 (setq attributes (delq ignored attributes))))
1022 (setq name (car attributes))
1023 (if (setq value (get-char-attribute char name))
1024 (cond ((setq ret (find-charset name))
1025 (setq name (charset-name ret))
1026 (if (and (not (memq name dest-ccss))
1028 (setq value (get-char-attribute char name))
1029 (setq dest-ccss (cons name dest-ccss))))
1030 (char-db-insert-ccs-feature name value line-breaking))
1032 ((string-match "^=>ucs@" (symbol-name name))
1033 (insert (format "(%-18s . #x%04X)\t; %c%s"
1034 name value (decode-char '=ucs value)
1037 ((eq name 'jisx0208-1978/4X)
1038 (insert (format "(%-18s . #x%04X)%s"
1044 (not (eq name '->subsumptive))
1045 (not (eq name '->uppercase))
1046 (not (eq name '->lowercase))
1047 (not (eq name '->titlecase))
1048 (not (eq name '->canonical))
1049 (not (eq name '->Bopomofo))
1050 (not (eq name '->mistakable))
1051 (not (eq name '->ideographic-variants))
1052 (null (get-char-attribute
1053 char (intern (format "%s*sources" name))))
1054 (not (string-match "\\*sources$" (symbol-name name)))
1055 (null (get-char-attribute
1056 char (intern (format "%s*note" name))))
1057 (not (string-match "\\*note$" (symbol-name name)))
1058 (or (eq name '<-identical)
1059 (eq name '<-uppercase)
1060 (eq name '<-lowercase)
1061 (eq name '<-titlecase)
1062 (eq name '<-canonical)
1063 (eq name '<-ideographic-variants)
1064 ;; (eq name '<-synonyms)
1065 (string-match "^<-synonyms" (symbol-name name))
1066 (eq name '<-mistakable)
1067 (when (string-match "^->" (symbol-name name))
1069 ((string-match "^->fullwidth" (symbol-name name))
1070 (not (and (consp value)
1071 (characterp (car value))
1073 (car value) '=ucs 'defined-only)))
1078 ((or (eq name 'ideographic-structure)
1079 (eq name 'ideographic-combination)
1080 (eq name 'ideographic-)
1081 (eq name '=decomposition)
1082 (string-match "^=>decomposition" (symbol-name name))
1083 (string-match "^\\(->\\|<-\\)[^*]*$" (symbol-name name))
1084 (string-match "^\\(->\\|<-\\)[^*]*\\*sources$"
1087 (char-db-insert-relation-feature char name value
1090 ((memq name '(ideograph=
1091 original-ideograph-of
1092 ancient-ideograph-of
1095 ;; simplified-ideograph-of
1096 ideographic-variants
1097 ;; ideographic-different-form-of
1099 (insert (format "(%-18s%s " name line-breaking))
1100 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1102 (while (consp value)
1103 (setq cell (car value))
1104 (if (and (consp cell)
1109 (char-db-insert-alist cell readable)
1110 (setq separator lbs))
1113 (insert (prin1-to-string cell))
1114 (setq separator " "))
1115 (setq value (cdr value)))
1117 (insert line-breaking))
1119 (insert (format "(%-18s " name))
1120 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1122 (while (consp value)
1123 (setq cell (car value))
1124 (if (and (consp cell)
1126 (setq ret (condition-case nil
1134 (setq key (car (car rest)))
1135 (if (find-charset key)
1136 (setq cal (cons key cal))
1137 (setq al (cons key al)))
1138 (setq rest (cdr rest)))
1141 (insert-char-attributes ret
1144 (setq separator lbs))
1145 (setq ret (prin1-to-string cell))
1147 (if (< (+ (current-column)
1154 (setq separator " "))
1155 (setq value (cdr value)))
1157 (insert line-breaking))
1159 (insert (format "(%-18s" name))
1160 (setq ret (prin1-to-string value))
1161 (unless (< (+ (current-column)
1165 (insert line-breaking))
1166 (insert " . " ret ")" line-breaking)
1167 ;; (insert (format "(%-18s . %S)%s"
1172 (setq attributes (cdr attributes)))
1175 (defun insert-char-data (char &optional readable
1178 (narrow-to-region (point)(point))
1179 (insert "(define-char
1181 (insert-char-attributes char readable attributes)
1183 (goto-char (point-min))
1184 (while (re-search-forward "[ \t]+$" nil t)
1187 (goto-char (point-min))
1188 (while (re-search-forward "[ \t][ \t][ \t]*" nil t)
1189 (let ((column (current-column))
1190 (indent-tabs-mode t))
1191 (delete-region (match-beginning 0) (point))
1192 (indent-to column)))
1193 (goto-char (point-max))
1194 ;; (tabify (point-min)(point-max))
1197 (defun insert-char-data-with-variant (char &optional printable
1199 script excluded-script)
1200 (insert-char-data char printable)
1201 (let ((variants (char-variants char))
1204 (setq variants (sort variants #'<))
1205 (setq rest variants)
1206 (setq variants (cons char variants))
1208 (setq variant (car rest))
1209 (unless (get-char-attribute variant '<-subsumptive)
1210 (if (and (or (null script)
1211 (null (setq vs (get-char-attribute variant 'script)))
1213 (or (null excluded-script)
1214 (null (setq vs (get-char-attribute variant 'script)))
1215 (not (memq excluded-script vs))))
1216 (unless (and no-ucs-unified (get-char-attribute variant '=ucs))
1217 (insert-char-data variant printable)
1218 (if (setq ret (char-variants variant))
1220 (or (memq (car ret) variants)
1221 ;; (get-char-attribute (car ret) '<-subsumptive)
1222 (setq rest (nconc rest (list (car ret)))))
1223 (setq ret (cdr ret)))))))
1224 (setq rest (cdr rest)))))
1226 (defun insert-char-range-data (min max &optional script excluded-script)
1229 (while (<= code max)
1230 (setq char (decode-char '=ucs code))
1231 (if (encode-char char '=ucs 'defined-only)
1232 (insert-char-data-with-variant char nil 'no-ucs-unified
1233 script excluded-script))
1234 (setq code (1+ code)))))
1236 (defun write-char-range-data-to-file (min max file
1237 &optional script excluded-script)
1238 (let ((coding-system-for-write char-db-file-coding-system))
1240 (insert (format ";; -*- coding: %s -*-\n"
1241 char-db-file-coding-system))
1242 (insert-char-range-data min max script excluded-script)
1243 (write-region (point-min)(point-max) file))))
1245 (defvar what-character-original-window-configuration)
1248 (defun what-char-definition (char)
1249 (interactive (list (char-after)))
1250 (let ((buf (get-buffer-create "*Character Description*"))
1251 (the-buf (current-buffer))
1252 (win-conf (current-window-configuration)))
1254 (make-local-variable 'what-character-original-window-configuration)
1255 (setq what-character-original-window-configuration win-conf)
1256 (setq buffer-read-only nil)
1260 (insert-char-data-with-variant char 'printable)
1261 (unless (char-attribute-alist char)
1262 (insert (format ";; = %c\n"
1263 (let* ((rest (split-char char))
1267 (setq code (logior (lsh code 8)
1269 (decode-char ccs code)))))
1270 ;; (char-db-update-comment)
1271 (set-buffer-modified-p nil)
1272 (view-mode the-buf (lambda (buf)
1273 (set-window-configuration
1274 what-character-original-window-configuration)
1276 (goto-char (point-min)))
1278 (set-window-configuration
1279 what-character-original-window-configuration)
1280 (signal (car err) (cdr err)))))))
1282 (provide 'char-db-util)
1284 ;;; char-db-util.el ends here