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 ?屮 ?艸 ?茻 ?小 ?八 ?釆 ?牛 ?告 ?口])
80 (defun shuowen-radical (number)
81 (aref shuowen-radicals (1- number)))
83 (defvar char-db-file-coding-system 'utf-8-mcs-er)
85 (defvar char-db-feature-domains
86 '(ucs ucs/compat daikanwa cns gt jis jis/alt jis/a jis/b
87 jis-x0212 jis-x0213 cdp shinjigen misc unknown))
89 (defvar char-db-ignored-attributes '(ideographic-products))
91 (defun char-attribute-name< (ka kb)
93 ((eq '->denotational kb)
95 ((eq '->subsumptive kb)
96 (not (eq '->denotational ka)))
97 ((eq '->denotational ka)
99 ((eq '->subsumptive ka)
102 (string-match "^->" (symbol-name ka)))
103 (cond ((and (symbolp kb)
104 (string-match "^->" (symbol-name kb)))
105 (string< (symbol-name ka)
110 (string-match "^->" (symbol-name kb)))
113 (string-match "^<-" (symbol-name ka)))
115 (cond ((string-match "^<-" (symbol-name kb))
116 (string< (symbol-name ka)
119 ;; ((string-match "^->" (symbol-name kb))
124 (string-match "^<-" (symbol-name kb)))
126 ;; (not (string-match "^->" (symbol-name ka)))
129 (if (find-charset kb)
130 (if (<= (charset-id ka) 1)
131 (if (<= (charset-id kb) 1)
133 ((= (charset-dimension ka)
134 (charset-dimension kb))
135 (> (charset-id ka)(charset-id kb)))
137 (> (charset-dimension ka)
138 (charset-dimension kb))
141 (if (<= (charset-id kb) 1)
143 (< (charset-id ka)(charset-id kb))))
149 (string< (symbol-name ka)
155 (defvar char-db-coded-charset-priority-list
216 (defun char-db-make-char-spec (char)
218 (cond ((characterp char)
219 (cond ((and (setq ret (encode-char char '=ucs 'defined-only))
220 (not (and (<= #xE000 ret)(<= ret #xF8FF))))
221 (setq char-spec (list (cons '=ucs ret)))
222 (cond ((setq ret (get-char-attribute char 'name))
223 (setq char-spec (cons (cons 'name ret) char-spec))
225 ((setq ret (get-char-attribute char 'name*))
226 (setq char-spec (cons (cons 'name* ret) char-spec))
231 (let ((rest char-db-coded-charset-priority-list)
234 (setq ccs (charset-name
235 (find-charset (car rest))))
237 (encode-char char ccs
239 (throw 'tag (cons ccs ret)))
240 (setq rest (cdr rest))))))
241 (setq char-spec (list ret))
242 (dolist (ccs (delq (car ret) (charset-list)))
243 (if (and (or (charset-iso-final-char ccs)
250 (setq ccs (charset-name ccs))
251 (null (assq ccs char-spec))
252 (setq ret (encode-char char ccs 'defined-only)))
253 (setq char-spec (cons (cons ccs ret) char-spec))))
255 (setq char-spec (split-char char)))
256 (cond ((setq ret (get-char-attribute char 'name))
257 (setq char-spec (cons (cons 'name ret) char-spec))
259 ((setq ret (get-char-attribute char 'name*))
260 (setq char-spec (cons (cons 'name* ret) char-spec))
267 (defun char-db-insert-char-spec (char &optional readable column
270 (setq column (current-column)))
271 (let (char-spec temp-char)
272 (setq char-spec (char-db-make-char-spec char))
273 (unless (or (characterp char) ; char
275 (setq char (find-char char-spec))
277 ;; define temporary character
278 ;; Current implementation is dirty.
279 (setq temp-char (define-char (cons '(ideograph-daikanwa . 0)
281 (remove-char-attribute temp-char 'ideograph-daikanwa)
282 (setq char temp-char))
283 (insert-char-attributes char
285 (union (mapcar #'car char-spec)
288 ;; undefine temporary character
289 ;; Current implementation is dirty.
290 (setq char-spec (char-attribute-alist temp-char))
292 (remove-char-attribute temp-char (car (car char-spec)))
293 (setq char-spec (cdr char-spec))))))
295 (defun char-db-insert-alist (alist &optional readable column)
297 (setq column (current-column)))
299 (concat "\n" (make-string (1+ column) ?\ )))
303 lbs cell rest separator)
306 (setq name (car (car alist))
307 value (cdr (car alist)))
308 (cond ((eq name 'char)
310 (if (setq ret (condition-case nil
318 (setq key (car (car value)))
319 ;; (if (find-charset key)
320 ;; (setq cal (cons key cal))
321 (setq al (cons key al))
323 (setq value (cdr value)))
324 (insert-char-attributes ret
328 (insert (prin1-to-string value)))
330 (insert line-breaking))
332 (insert (format "(%-18s " name))
333 (setq lbs (concat "\n" (make-string (current-column) ?\ )))
335 (setq cell (car value))
336 (if (and (consp cell)
338 (setq ret (condition-case nil
348 (setq key (car (car rest)))
349 ;; (if (find-charset key)
350 ;; (setq cal (cons key cal))
351 (setq al (cons key al))
353 (setq rest (cdr rest)))
356 (insert-char-attributes ret
360 (setq separator lbs))
363 (insert (prin1-to-string cell))
364 (setq separator " "))
365 (setq value (cdr value)))
367 (insert line-breaking))
369 (insert (format "(%-18s . %S)%s"
372 (setq alist (cdr alist))))
375 (defun char-db-insert-char-reference (plist &optional readable column)
377 (setq column (current-column)))
379 (concat "\n" (make-string (1+ column) ?\ )))
384 (setq name (pop plist))
385 (setq value (pop plist))
386 (cond ((eq name :char)
389 (cond ((numberp value)
390 (setq value (decode-char '=ucs value)))
392 ;; (setq value (or (find-char value)
395 (char-db-insert-char-spec value readable)
396 (insert line-breaking)
399 (insert (format "%s%s\t%d ; %c%s"
402 (ideographic-radical value)
406 (insert (format "%s%s\t%S" separator name value))
407 (setq separator line-breaking)))
411 (defun char-db-decode-isolated-char (ccs code-point)
414 (cond ((eq ccs 'arabic-iso8859-6)
415 (decode-char ccs code-point))
416 ((and (memq ccs '(=gt-pj-1
427 (setq ret (decode-char ccs code-point))
428 (setq ret (encode-char ret '=gt 'defined-only)))
429 (decode-builtin-char '=gt ret))
431 (decode-builtin-char ccs code-point))))
432 (cond ((and (<= 0 (char-int ret))
433 (<= (char-int ret) #x1F))
434 (decode-char '=ucs (+ #x2400 (char-int ret))))
435 ((= (char-int ret) #x7F)
439 (defvar char-db-convert-obsolete-format t)
441 (defun char-db-insert-ccs-feature (name value line-breaking)
444 (cond ((or (memq name '(=daikanwa
445 =daikanwa@rev1 =daikanwa@rev2
446 =gt =gt-k =cbeta =zinbun-oracle))
447 (string-match "^=adobe-" (symbol-name name)))
448 "(%-18s . %05d)\t; %c")
450 "(%-18s . %06d)\t; %c")
451 ((>= (charset-dimension name) 2)
452 "(%-18s . #x%04X)\t; %c")
454 "(%-18s . #x%02X)\t; %c"))
456 (if (= (charset-iso-graphic-plane name) 1)
458 (cond ((= (charset-dimension name) 1)
460 ((= (charset-dimension name) 2)
462 ((= (charset-dimension name) 3)
466 (char-db-decode-isolated-char name value)))
467 (if (and (= (charset-chars name) 94)
468 (= (charset-dimension name) 2))
469 (insert (format " [%02d-%02d]"
470 (- (lsh value -8) 32)
471 (- (logand value 255) 32))))
472 (insert line-breaking))
474 (defun char-db-insert-relation-feature (char name value line-breaking
476 (insert (format "(%-18s%s " name line-breaking))
477 (let ((lbs (concat "\n" (make-string (current-column) ?\ )))
478 separator cell sources required-features
481 (setq cell (car value))
483 (setq cell (decode-char '=ucs cell)))
485 ((eq name '->subsumptive)
486 (when (or (not (some (lambda (atr)
487 (get-char-attribute cell atr))
488 char-db-ignored-attributes))
490 (encode-char cell ccs 'defined-only))
494 (let ((char-db-ignored-attributes
496 char-db-ignored-attributes)))
497 (insert-char-attributes cell readable))
498 (setq separator lbs))
503 char (intern (format "%s*sources" name))))
504 (setq required-features nil)
505 (dolist (source sources)
507 ((memq source '(JP JP/Jouyou shinjigen-1))
508 (setq required-features
509 (union required-features
518 (setq required-features
519 (union required-features
524 ((find-charset (setq ret (intern (format "=%s" source))))
525 (setq required-features
526 (cons ret required-features)))
527 (t (setq required-features
528 (cons source required-features)))))
529 (cond ((string-match "@JP" (symbol-name name))
530 (setq required-features
531 (union required-features
539 ((string-match "@CN" (symbol-name name))
540 (setq required-features
541 (union required-features
548 (insert (format "%S" cell))
549 (char-db-insert-char-spec cell readable
552 (setq separator lbs))
556 (if (consp (car cell))
557 (char-db-insert-char-spec cell readable)
558 (char-db-insert-char-reference cell readable))
559 (setq separator lbs))
563 (insert (prin1-to-string cell))
564 (setq separator " ")))
565 (setq value (cdr value)))
567 (insert line-breaking)))
569 (defun insert-char-attributes (char &optional readable attributes column)
571 (setq column (current-column)))
572 (let (name value ; has-long-ccs-name
576 (concat "\n" (make-string (1+ column) ?\ )))
577 lbs cell separator ret
579 dest-ccss ; sources required-features
584 (if (consp attributes)
586 (dolist (name attributes)
587 (unless (memq name char-db-ignored-attributes)
588 (if (find-charset name)
592 (dolist (name (char-attribute-list))
593 (unless (memq name char-db-ignored-attributes)
594 (if (find-charset name)
598 #'char-attribute-name<)))
600 (when (memq '<-subsumptive attributes)
602 (when (setq value (get-char-attribute char '<-subsumptive))
603 (char-db-insert-relation-feature char '<-subsumptive value
606 (setq attributes (delq '<-subsumptive attributes)))
607 (when (and (memq '<-denotational attributes)
608 (setq value (get-char-attribute char '<-denotational)))
609 (char-db-insert-relation-feature char '<-denotational value
612 (setq attributes (delq '<-denotational attributes)))
613 (when (and (memq 'name attributes)
614 (setq value (get-char-attribute char 'name)))
616 (if (> (+ (current-column) (length value)) 48)
619 value line-breaking))
620 (setq attributes (delq 'name attributes))
622 (when (and (memq 'name* attributes)
623 (setq value (get-char-attribute char 'name*)))
625 (if (> (+ (current-column) (length value)) 48)
628 value line-breaking))
629 (setq attributes (delq 'name* attributes))
631 (when (and (memq 'script attributes)
632 (setq value (get-char-attribute char 'script)))
633 (insert (format "(script\t\t%s)%s"
634 (mapconcat (function prin1-to-string)
637 (setq attributes (delq 'script attributes))
639 (dolist (name '(=>ucs =>ucs*))
640 (when (and (memq name attributes)
641 (setq value (get-char-attribute char name)))
642 (insert (format "(%-18s . #x%04X)\t; %c%s"
643 name value (decode-char '=ucs value)
645 (setq attributes (delq name attributes))))
646 (dolist (name '(=>ucs@gb =>ucs@cns =>ucs@jis =>ucs@ks =>ucs@big5))
647 (when (and (memq name attributes)
648 (setq value (get-char-attribute char name)))
649 (insert (format "(%-18s . #x%04X)\t; %c%s"
654 (symbol-name name) 2)))
657 (setq attributes (delq name attributes))
659 (dolist (name '(=>daikanwa))
660 (when (and (memq name attributes)
661 (setq value (get-char-attribute char name)))
664 (format "(%-18s . %05d)\t; %c%s"
665 name value (decode-char '=daikanwa value)
667 (format "(%-18s %s)\t; %c%s"
669 (mapconcat (function prin1-to-string)
671 (char-representative-of-daikanwa char)
673 (setq attributes (delq name attributes))))
674 (when (and (memq 'general-category attributes)
675 (setq value (get-char-attribute char 'general-category)))
677 "(general-category\t%s) ; %s%s"
678 (mapconcat (lambda (cell)
681 (cond ((rassoc value unidata-normative-category-alist)
682 "Normative Category")
683 ((rassoc value unidata-informative-category-alist)
684 "Informative Category")
688 (setq attributes (delq 'general-category attributes))
690 (when (and (memq 'bidi-category attributes)
691 (setq value (get-char-attribute char 'bidi-category)))
692 (insert (format "(bidi-category\t. %S)%s"
695 (setq attributes (delq 'bidi-category attributes))
697 (unless (or (not (memq 'mirrored attributes))
698 (eq (setq value (get-char-attribute char 'mirrored 'empty))
700 (insert (format "(mirrored\t\t. %S)%s"
703 (setq attributes (delq 'mirrored attributes))
706 ((and (memq 'decimal-digit-value attributes)
707 (setq value (get-char-attribute char 'decimal-digit-value)))
708 (insert (format "(decimal-digit-value . %S)%s"
711 (setq attributes (delq 'decimal-digit-value attributes))
712 (when (and (memq 'digit-value attributes)
713 (setq value (get-char-attribute char 'digit-value)))
714 (insert (format "(digit-value\t . %S)%s"
717 (setq attributes (delq 'digit-value attributes))
719 (when (and (memq 'numeric-value attributes)
720 (setq value (get-char-attribute char 'numeric-value)))
721 (insert (format "(numeric-value\t . %S)%s"
724 (setq attributes (delq 'numeric-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))
742 (when (and (memq 'iso-10646-comment attributes)
743 (setq value (get-char-attribute char 'iso-10646-comment)))
744 (insert (format "(iso-10646-comment\t. %S)%s"
747 (setq attributes (delq 'iso-10646-comment attributes))
749 (when (and (memq 'morohashi-daikanwa attributes)
750 (setq value (get-char-attribute char 'morohashi-daikanwa)))
751 (insert (format "(morohashi-daikanwa\t%s)%s"
752 (mapconcat (function prin1-to-string) value " ")
754 (setq attributes (delq 'morohashi-daikanwa attributes))
758 (when (and (memq 'ideographic-radical attributes)
759 (setq value (get-char-attribute char 'ideographic-radical)))
761 (insert (format "(ideographic-radical . %S)\t; %c%s"
763 (ideographic-radical radical)
765 (setq attributes (delq 'ideographic-radical attributes))
767 (when (and (memq 'shuowen-radical attributes)
768 (setq value (get-char-attribute char 'shuowen-radical)))
769 (insert (format "(shuowen-radical\t. %S)\t; %c%s"
771 (shuowen-radical value)
773 (setq attributes (delq 'shuowen-radical attributes))
778 char-db-feature-domains
780 (dolist (feature (char-attribute-list))
781 (setq feature (symbol-name feature))
783 "\\(radical\\|strokes\\)@\\([^@*]+\\)\\(\\*\\|$\\)"
785 (setq domain (intern (match-string 2 feature)))
786 (unless (memq domain dest)
787 (setq dest (cons domain dest)))))
788 (sort dest #'string<))))
789 (setq key (intern (format "%s@%s" 'ideographic-radical domain)))
790 (when (and (memq key attributes)
791 (setq value (get-char-attribute char key)))
793 (insert (format "(%s . %S)\t; %c%s"
796 (ideographic-radical radical)
798 (setq attributes (delq key attributes))
800 (setq key (intern (format "%s@%s" 'ideographic-strokes domain)))
801 (when (and (memq key attributes)
802 (setq value (get-char-attribute char key)))
804 (insert (format "(%s . %S)%s"
808 (setq attributes (delq key attributes))
810 (setq key (intern (format "%s@%s" 'total-strokes domain)))
811 (when (and (memq key attributes)
812 (setq value (get-char-attribute char key)))
813 (insert (format "(%s . %S)%s"
817 (setq attributes (delq key attributes))
819 (dolist (feature '(ideographic-radical
822 (setq key (intern (format "%s@%s*sources" feature domain)))
823 (when (and (memq key attributes)
824 (setq value (get-char-attribute char key)))
825 (insert (format "(%s%s" key line-breaking))
827 (insert (format " %s" cell)))
829 (insert line-breaking)
830 (setq attributes (delq key attributes))
833 (when (and (memq 'ideographic-strokes attributes)
834 (setq value (get-char-attribute char 'ideographic-strokes)))
836 (insert (format "(ideographic-strokes . %S)%s"
839 (setq attributes (delq 'ideographic-strokes attributes))
841 (when (and (memq 'kangxi-radical attributes)
842 (setq value (get-char-attribute char 'kangxi-radical)))
843 (unless (eq value radical)
844 (insert (format "(kangxi-radical\t . %S)\t; %c%s"
846 (ideographic-radical value)
849 (setq radical value)))
850 (setq attributes (delq 'kangxi-radical attributes))
852 (when (and (memq 'kangxi-strokes attributes)
853 (setq value (get-char-attribute char 'kangxi-strokes)))
854 (unless (eq value strokes)
855 (insert (format "(kangxi-strokes\t . %S)%s"
859 (setq strokes value)))
860 (setq attributes (delq 'kangxi-strokes attributes))
862 (when (and (memq 'japanese-radical attributes)
863 (setq value (get-char-attribute char 'japanese-radical)))
864 (unless (eq value radical)
865 (insert (format "(japanese-radical\t . %S)\t; %c%s"
867 (ideographic-radical value)
870 (setq radical value)))
871 (setq attributes (delq 'japanese-radical attributes))
873 (when (and (memq 'japanese-strokes attributes)
874 (setq value (get-char-attribute char 'japanese-strokes)))
875 (unless (eq value strokes)
876 (insert (format "(japanese-strokes\t . %S)%s"
880 (setq strokes value)))
881 (setq attributes (delq 'japanese-strokes attributes))
883 (when (and (memq 'cns-radical attributes)
884 (setq value (get-char-attribute char 'cns-radical)))
885 (insert (format "(cns-radical\t . %S)\t; %c%s"
887 (ideographic-radical value)
889 (setq attributes (delq 'cns-radical attributes))
891 (when (and (memq 'cns-strokes attributes)
892 (setq value (get-char-attribute char 'cns-strokes)))
893 (unless (eq value strokes)
894 (insert (format "(cns-strokes\t . %S)%s"
898 (setq strokes value)))
899 (setq attributes (delq 'cns-strokes attributes))
901 (when (and (memq 'shinjigen-1-radical attributes)
902 (setq value (get-char-attribute char 'shinjigen-1-radical)))
903 (unless (eq value radical)
904 (insert (format "(shinjigen-1-radical . %S)\t; %c%s"
906 (ideographic-radical value)
909 (setq radical value)))
910 (setq attributes (delq 'shinjigen-1-radical attributes))
912 (when (and (memq 'ideographic- attributes)
913 (setq value (get-char-attribute char 'ideographic-)))
914 (insert "(ideographic- ")
915 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
918 (setq cell (car value))
920 (setq cell (decode-char '=ucs cell)))
921 (cond ((characterp cell)
925 (insert (format "%S" cell))
926 (char-db-insert-char-spec cell readable))
927 (setq separator lbs))
931 (if (consp (car cell))
932 (char-db-insert-char-spec cell readable)
933 (char-db-insert-char-reference cell readable))
934 (setq separator lbs))
938 (insert (prin1-to-string cell))
939 (setq separator " ")))
940 (setq value (cdr value)))
942 (insert line-breaking)
943 (setq attributes (delq 'ideographic- attributes)))
944 (when (and (memq 'total-strokes attributes)
945 (setq value (get-char-attribute char 'total-strokes)))
946 (insert (format "(total-strokes . %S)%s"
949 (setq attributes (delq 'total-strokes attributes))
951 (when (and (memq '->ideograph attributes)
952 (setq value (get-char-attribute char '->ideograph)))
953 (insert (format "(->ideograph\t%s)%s"
954 (mapconcat (lambda (code)
955 (cond ((symbolp code)
958 (format "#x%04X" code))
961 line-breaking code))))
964 (setq attributes (delq '->ideograph attributes))
966 ;; (when (and (memq '->decomposition attributes)
967 ;; (setq value (get-char-attribute char '->decomposition)))
968 ;; (insert (format "(->decomposition\t%s)%s"
969 ;; (mapconcat (lambda (code)
970 ;; (cond ((symbolp code)
971 ;; (symbol-name code))
972 ;; ((characterp code)
974 ;; (format "%S" code)
979 ;; (format "#x%04X" code))
981 ;; (format "%s%S" line-breaking code))))
984 ;; (setq attributes (delq '->decomposition attributes))
986 (if (equal (get-char-attribute char '->titlecase)
987 (get-char-attribute char '->uppercase))
988 (setq attributes (delq '->titlecase attributes)))
989 (when (and (memq '->mojikyo attributes)
990 (setq value (get-char-attribute char '->mojikyo)))
991 (insert (format "(->mojikyo\t\t. %06d)\t; %c%s"
992 value (decode-char 'mojikyo value)
994 (setq attributes (delq '->mojikyo attributes))
996 (when (and (memq 'hanyu-dazidian-vol attributes)
997 (setq value (get-char-attribute char 'hanyu-dazidian-vol)))
998 (insert (format "(hanyu-dazidian-vol . %d)%s"
999 value line-breaking))
1000 (setq attributes (delq 'hanyu-dazidian-vol attributes))
1002 (when (and (memq 'hanyu-dazidian-page attributes)
1003 (setq value (get-char-attribute char 'hanyu-dazidian-page)))
1004 (insert (format "(hanyu-dazidian-page . %d)%s"
1005 value line-breaking))
1006 (setq attributes (delq 'hanyu-dazidian-page attributes))
1008 (when (and (memq 'hanyu-dazidian-char attributes)
1009 (setq value (get-char-attribute char 'hanyu-dazidian-char)))
1010 (insert (format "(hanyu-dazidian-char . %d)%s"
1011 value line-breaking))
1012 (setq attributes (delq 'hanyu-dazidian-char attributes))
1015 (dolist (ignored '(composition
1016 ->denotational <-subsumptive ->ucs-unified
1017 ->ideographic-component-forms))
1018 (setq attributes (delq ignored attributes))))
1020 (setq name (car attributes))
1021 (if (setq value (get-char-attribute char name))
1022 (cond ((setq ret (find-charset name))
1023 (setq name (charset-name ret))
1024 (if (and (not (memq name dest-ccss))
1026 (setq value (get-char-attribute char name))
1027 (setq dest-ccss (cons name dest-ccss))))
1028 (char-db-insert-ccs-feature name value line-breaking))
1030 ((string-match "^=>ucs@" (symbol-name name))
1031 (insert (format "(%-18s . #x%04X)\t; %c%s"
1032 name value (decode-char '=ucs value)
1035 ((eq name 'jisx0208-1978/4X)
1036 (insert (format "(%-18s . #x%04X)%s"
1042 (not (eq name '->subsumptive))
1043 (not (eq name '->uppercase))
1044 (not (eq name '->lowercase))
1045 (not (eq name '->titlecase))
1046 (not (eq name '->canonical))
1047 (not (eq name '->Bopomofo))
1048 (not (eq name '->mistakable))
1049 (not (eq name '->ideographic-variants))
1050 (null (get-char-attribute
1051 char (intern (format "%s*sources" name))))
1052 (not (string-match "\\*sources$" (symbol-name name)))
1053 (null (get-char-attribute
1054 char (intern (format "%s*note" name))))
1055 (not (string-match "\\*note$" (symbol-name name)))
1056 (or (eq name '<-identical)
1057 (eq name '<-uppercase)
1058 (eq name '<-lowercase)
1059 (eq name '<-titlecase)
1060 (eq name '<-canonical)
1061 (eq name '<-ideographic-variants)
1062 ;; (eq name '<-synonyms)
1063 (string-match "^<-synonyms" (symbol-name name))
1064 (eq name '<-mistakable)
1065 (when (string-match "^->" (symbol-name name))
1067 ((string-match "^->fullwidth" (symbol-name name))
1068 (not (and (consp value)
1069 (characterp (car value))
1071 (car value) '=ucs 'defined-only)))
1076 ((or (eq name 'ideographic-structure)
1077 (eq name 'ideographic-combination)
1078 (eq name 'ideographic-)
1079 (eq name '=decomposition)
1080 (string-match "^=>decomposition" (symbol-name name))
1081 (string-match "^\\(->\\|<-\\)[^*]*$" (symbol-name name))
1082 (string-match "^\\(->\\|<-\\)[^*]*\\*sources$"
1085 (char-db-insert-relation-feature char name value
1088 ((memq name '(ideograph=
1089 original-ideograph-of
1090 ancient-ideograph-of
1093 ;; simplified-ideograph-of
1094 ideographic-variants
1095 ;; ideographic-different-form-of
1097 (insert (format "(%-18s%s " name line-breaking))
1098 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1100 (while (consp value)
1101 (setq cell (car value))
1102 (if (and (consp cell)
1107 (char-db-insert-alist cell readable)
1108 (setq separator lbs))
1111 (insert (prin1-to-string cell))
1112 (setq separator " "))
1113 (setq value (cdr value)))
1115 (insert line-breaking))
1117 (insert (format "(%-18s " name))
1118 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1120 (while (consp value)
1121 (setq cell (car value))
1122 (if (and (consp cell)
1124 (setq ret (condition-case nil
1132 (setq key (car (car rest)))
1133 (if (find-charset key)
1134 (setq cal (cons key cal))
1135 (setq al (cons key al)))
1136 (setq rest (cdr rest)))
1139 (insert-char-attributes ret
1142 (setq separator lbs))
1143 (setq ret (prin1-to-string cell))
1145 (if (< (+ (current-column)
1152 (setq separator " "))
1153 (setq value (cdr value)))
1155 (insert line-breaking))
1157 (insert (format "(%-18s" name))
1158 (setq ret (prin1-to-string value))
1159 (unless (< (+ (current-column)
1163 (insert line-breaking))
1164 (insert " . " ret ")" line-breaking)
1165 ;; (insert (format "(%-18s . %S)%s"
1170 (setq attributes (cdr attributes)))
1173 (defun insert-char-data (char &optional readable
1176 (narrow-to-region (point)(point))
1177 (insert "(define-char
1179 (insert-char-attributes char readable attributes)
1181 (goto-char (point-min))
1182 (while (re-search-forward "[ \t]+$" nil t)
1185 (goto-char (point-min))
1186 (while (re-search-forward "[ \t][ \t][ \t]*" nil t)
1187 (let ((column (current-column))
1188 (indent-tabs-mode t))
1189 (delete-region (match-beginning 0) (point))
1190 (indent-to column)))
1191 (goto-char (point-max))
1192 ;; (tabify (point-min)(point-max))
1195 (defun insert-char-data-with-variant (char &optional printable
1197 script excluded-script)
1198 (insert-char-data char printable)
1199 (let ((variants (char-variants char))
1202 (setq variants (sort variants #'<))
1203 (setq rest variants)
1204 (setq variants (cons char variants))
1206 (setq variant (car rest))
1207 (unless (get-char-attribute variant '<-subsumptive)
1208 (if (and (or (null script)
1209 (null (setq vs (get-char-attribute variant 'script)))
1211 (or (null excluded-script)
1212 (null (setq vs (get-char-attribute variant 'script)))
1213 (not (memq excluded-script vs))))
1214 (unless (and no-ucs-unified (get-char-attribute variant '=ucs))
1215 (insert-char-data variant printable)
1216 (if (setq ret (char-variants variant))
1218 (or (memq (car ret) variants)
1219 ;; (get-char-attribute (car ret) '<-subsumptive)
1220 (setq rest (nconc rest (list (car ret)))))
1221 (setq ret (cdr ret)))))))
1222 (setq rest (cdr rest)))))
1224 (defun insert-char-range-data (min max &optional script excluded-script)
1227 (while (<= code max)
1228 (setq char (decode-char '=ucs code))
1229 (if (encode-char char '=ucs 'defined-only)
1230 (insert-char-data-with-variant char nil 'no-ucs-unified
1231 script excluded-script))
1232 (setq code (1+ code)))))
1234 (defun write-char-range-data-to-file (min max file
1235 &optional script excluded-script)
1236 (let ((coding-system-for-write char-db-file-coding-system))
1238 (insert (format ";; -*- coding: %s -*-\n"
1239 char-db-file-coding-system))
1240 (insert-char-range-data min max script excluded-script)
1241 (write-region (point-min)(point-max) file))))
1243 (defvar what-character-original-window-configuration)
1246 (defun what-char-definition (char)
1247 (interactive (list (char-after)))
1248 (let ((buf (get-buffer-create "*Character Description*"))
1249 (the-buf (current-buffer))
1250 (win-conf (current-window-configuration)))
1252 (make-local-variable 'what-character-original-window-configuration)
1253 (setq what-character-original-window-configuration win-conf)
1254 (setq buffer-read-only nil)
1258 (insert-char-data-with-variant char 'printable)
1259 (unless (char-attribute-alist char)
1260 (insert (format ";; = %c\n"
1261 (let* ((rest (split-char char))
1265 (setq code (logior (lsh code 8)
1267 (decode-char ccs code)))))
1268 ;; (char-db-update-comment)
1269 (set-buffer-modified-p nil)
1270 (view-mode the-buf (lambda (buf)
1271 (set-window-configuration
1272 what-character-original-window-configuration)
1274 (goto-char (point-min)))
1276 (set-window-configuration
1277 what-character-original-window-configuration)
1278 (signal (car err) (cdr err)))))))
1280 (provide 'char-db-util)
1282 ;;; char-db-util.el ends here