1 ;;; char-db-util.el --- Character Database utility -*- coding: utf-8-er; -*-
3 ;; Copyright (C) 1998,1999,2000,2001,2002,2003,2004,2005 MORIOKA Tomohiko.
5 ;; Author: MORIOKA Tomohiko <tomo@kanji.zinbun.kyoto-u.ac.jp>
6 ;; Keywords: CHISE, Character Database, ISO/IEC 10646, UCS, Unicode, MULE.
8 ;; This file is part of XEmacs CHISE.
10 ;; XEmacs CHISE is free software; you can redistribute it and/or
11 ;; modify it under the terms of the GNU General Public License as
12 ;; published by the Free Software Foundation; either version 2, or (at
13 ;; your option) any later version.
15 ;; XEmacs CHISE is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 ;; General Public License for more details.
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with XEmacs CHISE; see the file COPYING. If not, write to
22 ;; the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23 ;; Boston, MA 02111-1307, USA.
29 (defconst unidata-normative-category-alist
30 '(("Lu" letter uppercase)
31 ("Ll" letter lowercase)
32 ("Lt" letter titlecase)
33 ("Mn" mark non-spacing)
34 ("Mc" mark spacing-combining)
36 ("Nd" number decimal-digit)
39 ("Zs" separator space)
41 ("Zp" separator paragraph)
44 ("Cs" other surrogate)
45 ("Co" other private-use)
46 ("Cn" other not-assigned)))
48 (defconst unidata-informative-category-alist
49 '(("Lm" letter modifier)
51 ("Pc" punctuation connector)
52 ("Pd" punctuation dash)
53 ("Ps" punctuation open)
54 ("Pe" punctuation close)
55 ("Pi" punctuation initial-quote)
56 ("Pf" punctuation final-quote)
57 ("Po" punctuation other)
59 ("Sc" symbol currency)
60 ("Sk" symbol modifier)
64 (defconst ideographic-radicals
65 (let ((v (make-vector 215 nil))
68 (aset v i (decode-char '=ucs (+ #x2EFF i)))
72 (defun ideographic-radical (number)
73 (aref ideographic-radicals number))
75 (defconst shuowen-radicals
76 [?一 ?上 ?示 ?三 ?王 ?玉 ?玨 ?气 ?士 ?丨 ?屮 ?艸 ?茻])
78 (defun shuowen-radical (number)
79 (aref shuowen-radicals (1- number)))
81 (defvar char-db-file-coding-system 'utf-8-mcs-er)
83 (defvar char-db-feature-domains
84 '(ucs daikanwa cns gt jis jis/alt jis/a jis/b
85 jis-x0212 jis-x0213 cdp shinjigen misc unknown))
87 (defvar char-db-ignored-attributes '(ideographic-products))
89 (defun char-attribute-name< (ka kb)
91 ((eq '->denotational kb)
93 ((eq '->subsumptive kb)
94 (not (eq '->denotational ka)))
95 ((eq '->denotational ka)
97 ((eq '->subsumptive ka)
100 (string-match "^->" (symbol-name ka)))
101 (cond ((and (symbolp kb)
102 (string-match "^->" (symbol-name kb)))
103 (string< (symbol-name ka)
108 (string-match "^->" (symbol-name kb)))
111 (string-match "^<-" (symbol-name ka)))
113 (cond ((string-match "^<-" (symbol-name kb))
114 (string< (symbol-name ka)
117 ;; ((string-match "^->" (symbol-name kb))
122 (string-match "^<-" (symbol-name kb)))
124 ;; (not (string-match "^->" (symbol-name ka)))
127 (if (find-charset kb)
128 (if (<= (charset-id ka) 1)
129 (if (<= (charset-id kb) 1)
131 ((= (charset-dimension ka)
132 (charset-dimension kb))
133 (> (charset-id ka)(charset-id kb)))
135 (> (charset-dimension ka)
136 (charset-dimension kb))
139 (if (<= (charset-id kb) 1)
141 (< (charset-id ka)(charset-id kb))))
147 (string< (symbol-name ka)
153 (defvar char-db-coded-charset-priority-list
214 (defun char-db-make-char-spec (char)
216 (cond ((characterp char)
217 (cond ((and (setq ret (encode-char char '=ucs 'defined-only))
218 (not (and (<= #xE000 ret)(<= ret #xF8FF))))
219 (setq char-spec (list (cons '=ucs ret)))
220 (cond ((setq ret (get-char-attribute char 'name))
221 (setq char-spec (cons (cons 'name ret) char-spec))
223 ((setq ret (get-char-attribute char 'name*))
224 (setq char-spec (cons (cons 'name* ret) char-spec))
229 (let ((rest char-db-coded-charset-priority-list)
232 (setq ccs (charset-name
233 (find-charset (car rest))))
235 (encode-char char ccs
237 (throw 'tag (cons ccs ret)))
238 (setq rest (cdr rest))))))
239 (setq char-spec (list ret))
240 (dolist (ccs (delq (car ret) (charset-list)))
241 (if (and (or (charset-iso-final-char ccs)
247 (setq ccs (charset-name ccs))
248 (null (assq ccs char-spec))
249 (setq ret (encode-char char ccs 'defined-only)))
250 (setq char-spec (cons (cons ccs ret) char-spec))))
252 (setq char-spec (split-char char)))
253 (cond ((setq ret (get-char-attribute char 'name))
254 (setq char-spec (cons (cons 'name ret) char-spec))
256 ((setq ret (get-char-attribute char 'name*))
257 (setq char-spec (cons (cons 'name* ret) char-spec))
264 (defun char-db-insert-char-spec (char &optional readable column
267 (setq column (current-column)))
268 (let (char-spec temp-char)
269 (setq char-spec (char-db-make-char-spec char))
270 (unless (or (characterp char) ; char
272 (setq char (find-char char-spec))
274 ;; define temporary character
275 ;; Current implementation is dirty.
276 (setq temp-char (define-char (cons '(ideograph-daikanwa . 0)
278 (remove-char-attribute temp-char 'ideograph-daikanwa)
279 (setq char temp-char))
280 (insert-char-attributes char
282 (union (mapcar #'car char-spec)
285 ;; undefine temporary character
286 ;; Current implementation is dirty.
287 (setq char-spec (char-attribute-alist temp-char))
289 (remove-char-attribute temp-char (car (car char-spec)))
290 (setq char-spec (cdr char-spec))))))
292 (defun char-db-insert-alist (alist &optional readable column)
294 (setq column (current-column)))
296 (concat "\n" (make-string (1+ column) ?\ )))
300 lbs cell rest separator)
303 (setq name (car (car alist))
304 value (cdr (car alist)))
305 (cond ((eq name 'char)
307 (if (setq ret (condition-case nil
315 (setq key (car (car value)))
316 ;; (if (find-charset key)
317 ;; (setq cal (cons key cal))
318 (setq al (cons key al))
320 (setq value (cdr value)))
321 (insert-char-attributes ret
325 (insert (prin1-to-string value)))
327 (insert line-breaking))
329 (insert (format "(%-18s " name))
330 (setq lbs (concat "\n" (make-string (current-column) ?\ )))
332 (setq cell (car value))
333 (if (and (consp cell)
335 (setq ret (condition-case nil
345 (setq key (car (car rest)))
346 ;; (if (find-charset key)
347 ;; (setq cal (cons key cal))
348 (setq al (cons key al))
350 (setq rest (cdr rest)))
353 (insert-char-attributes ret
357 (setq separator lbs))
360 (insert (prin1-to-string cell))
361 (setq separator " "))
362 (setq value (cdr value)))
364 (insert line-breaking))
366 (insert (format "(%-18s . %S)%s"
369 (setq alist (cdr alist))))
372 (defun char-db-insert-char-reference (plist &optional readable column)
374 (setq column (current-column)))
376 (concat "\n" (make-string (1+ column) ?\ )))
381 (setq name (pop plist))
382 (setq value (pop plist))
383 (cond ((eq name :char)
386 (cond ((numberp value)
387 (setq value (decode-char '=ucs value)))
389 ;; (setq value (or (find-char value)
392 (char-db-insert-char-spec value readable)
393 (insert line-breaking)
396 (insert (format "%s%s\t%d ; %c%s"
399 (ideographic-radical value)
403 (insert (format "%s%s\t%S" separator name value))
404 (setq separator line-breaking)))
408 (defun char-db-decode-isolated-char (ccs code-point)
411 (cond ((eq ccs 'arabic-iso8859-6)
412 (decode-char ccs code-point))
413 ((and (memq ccs '(=gt-pj-1
424 (setq ret (decode-char ccs code-point))
425 (setq ret (encode-char ret '=gt 'defined-only)))
426 (decode-builtin-char '=gt ret))
428 (decode-builtin-char ccs code-point))))
429 (cond ((and (<= 0 (char-int ret))
430 (<= (char-int ret) #x1F))
431 (decode-char '=ucs (+ #x2400 (char-int ret))))
432 ((= (char-int ret) #x7F)
436 (defvar char-db-convert-obsolete-format t)
438 (defun char-db-insert-ccs-feature (name value line-breaking)
441 (cond ((memq name '(=daikanwa
442 =daikanwa@rev1 =daikanwa@rev2
443 =gt =gt-k =cbeta =zinbun-oracle))
444 "(%-18s . %05d)\t; %c")
446 "(%-18s . %06d)\t; %c")
447 ((>= (charset-dimension name) 2)
448 "(%-18s . #x%04X)\t; %c")
450 "(%-18s . #x%02X)\t; %c"))
452 (if (= (charset-iso-graphic-plane name) 1)
454 (cond ((= (charset-dimension name) 1)
456 ((= (charset-dimension name) 2)
458 ((= (charset-dimension name) 3)
462 (char-db-decode-isolated-char name value)))
463 (if (and (= (charset-chars name) 94)
464 (= (charset-dimension name) 2))
465 (insert (format " [%02d-%02d]"
466 (- (lsh value -8) 32)
467 (- (logand value 255) 32))))
468 (insert line-breaking))
470 (defun char-db-insert-relation-feature (char name value line-breaking
472 (insert (format "(%-18s%s " name line-breaking))
473 (let ((lbs (concat "\n" (make-string (current-column) ?\ )))
474 separator cell sources required-features
477 (setq cell (car value))
479 (setq cell (decode-char '=ucs cell)))
481 ((eq name '->subsumptive)
482 (when (or (not (some (lambda (atr)
483 (get-char-attribute cell atr))
484 char-db-ignored-attributes))
486 (encode-char cell ccs 'defined-only))
490 (let ((char-db-ignored-attributes
492 char-db-ignored-attributes)))
493 (insert-char-attributes cell readable))
494 (setq separator lbs))
499 char (intern (format "%s*sources" name))))
500 (setq required-features nil)
501 (dolist (source sources)
503 ((memq source '(JP JP/Jouyou shinjigen-1))
504 (setq required-features
505 (union required-features
514 (setq required-features
515 (union required-features
520 ((find-charset (setq ret (intern (format "=%s" source))))
521 (setq required-features
522 (cons ret required-features)))
523 (t (setq required-features
524 (cons source required-features)))))
525 (cond ((string-match "@JP" (symbol-name name))
526 (setq required-features
527 (union required-features
535 ((string-match "@CN" (symbol-name name))
536 (setq required-features
537 (union required-features
544 (insert (format "%S" cell))
545 (char-db-insert-char-spec cell readable
548 (setq separator lbs))
552 (if (consp (car cell))
553 (char-db-insert-char-spec cell readable)
554 (char-db-insert-char-reference cell readable))
555 (setq separator lbs))
559 (insert (prin1-to-string cell))
560 (setq separator " ")))
561 (setq value (cdr value)))
563 (insert line-breaking)))
565 (defun insert-char-attributes (char &optional readable attributes column)
567 (setq column (current-column)))
568 (let (name value ; has-long-ccs-name
572 (concat "\n" (make-string (1+ column) ?\ )))
573 lbs cell separator ret
575 dest-ccss ; sources required-features
580 (if (consp attributes)
582 (dolist (name attributes)
583 (unless (memq name char-db-ignored-attributes)
584 (if (find-charset name)
588 (dolist (name (char-attribute-list))
589 (unless (memq name char-db-ignored-attributes)
590 (if (find-charset name)
594 #'char-attribute-name<)))
596 (when (memq '<-subsumptive attributes)
598 (when (setq value (get-char-attribute char '<-subsumptive))
599 (char-db-insert-relation-feature char '<-subsumptive value
602 (setq attributes (delq '<-subsumptive attributes)))
603 (when (and (memq '<-denotational attributes)
604 (setq value (get-char-attribute char '<-denotational)))
605 (char-db-insert-relation-feature char '<-denotational value
608 (setq attributes (delq '<-denotational attributes)))
609 (when (and (memq 'name attributes)
610 (setq value (get-char-attribute char 'name)))
612 (if (> (+ (current-column) (length value)) 48)
615 value line-breaking))
616 (setq attributes (delq 'name attributes))
618 (when (and (memq 'name* attributes)
619 (setq value (get-char-attribute char 'name*)))
621 (if (> (+ (current-column) (length value)) 48)
624 value line-breaking))
625 (setq attributes (delq 'name* attributes))
627 (when (and (memq 'script attributes)
628 (setq value (get-char-attribute char 'script)))
629 (insert (format "(script\t\t%s)%s"
630 (mapconcat (function prin1-to-string)
633 (setq attributes (delq 'script attributes))
635 (dolist (name '(=>ucs =>ucs*))
636 (when (and (memq name attributes)
637 (setq value (get-char-attribute char name)))
638 (insert (format "(%-18s . #x%04X)\t; %c%s"
639 name value (decode-char '=ucs value)
641 (setq attributes (delq name attributes))))
642 (dolist (name '(=>ucs@gb =>ucs@cns =>ucs@jis =>ucs@ks =>ucs@big5))
643 (when (and (memq name attributes)
644 (setq value (get-char-attribute char name)))
645 (insert (format "(%-18s . #x%04X)\t; %c%s"
650 (symbol-name name) 2)))
653 (setq attributes (delq name attributes))
655 (dolist (name '(=>daikanwa))
656 (when (and (memq name attributes)
657 (setq value (get-char-attribute char name)))
660 (format "(%-18s . %05d)\t; %c%s"
661 name value (decode-char '=daikanwa value)
663 (format "(%-18s %s)\t; %c%s"
665 (mapconcat (function prin1-to-string)
667 (char-representative-of-daikanwa char)
669 (setq attributes (delq name attributes))))
670 (when (and (memq 'general-category attributes)
671 (setq value (get-char-attribute char 'general-category)))
673 "(general-category\t%s) ; %s%s"
674 (mapconcat (lambda (cell)
677 (cond ((rassoc value unidata-normative-category-alist)
678 "Normative Category")
679 ((rassoc value unidata-informative-category-alist)
680 "Informative Category")
684 (setq attributes (delq 'general-category attributes))
686 (when (and (memq 'bidi-category attributes)
687 (setq value (get-char-attribute char 'bidi-category)))
688 (insert (format "(bidi-category\t. %S)%s"
691 (setq attributes (delq 'bidi-category attributes))
693 (unless (or (not (memq 'mirrored attributes))
694 (eq (setq value (get-char-attribute char 'mirrored 'empty))
696 (insert (format "(mirrored\t\t. %S)%s"
699 (setq attributes (delq 'mirrored attributes))
702 ((and (memq 'decimal-digit-value attributes)
703 (setq value (get-char-attribute char 'decimal-digit-value)))
704 (insert (format "(decimal-digit-value . %S)%s"
707 (setq attributes (delq 'decimal-digit-value attributes))
708 (when (and (memq 'digit-value attributes)
709 (setq value (get-char-attribute char 'digit-value)))
710 (insert (format "(digit-value\t . %S)%s"
713 (setq attributes (delq 'digit-value attributes))
715 (when (and (memq 'numeric-value attributes)
716 (setq value (get-char-attribute char 'numeric-value)))
717 (insert (format "(numeric-value\t . %S)%s"
720 (setq attributes (delq 'numeric-value attributes))
724 (when (and (memq 'digit-value attributes)
725 (setq value (get-char-attribute char 'digit-value)))
726 (insert (format "(digit-value\t. %S)%s"
729 (setq attributes (delq 'digit-value attributes))
731 (when (and (memq 'numeric-value attributes)
732 (setq value (get-char-attribute char 'numeric-value)))
733 (insert (format "(numeric-value\t. %S)%s"
736 (setq attributes (delq 'numeric-value attributes))
738 (when (and (memq 'iso-10646-comment attributes)
739 (setq value (get-char-attribute char 'iso-10646-comment)))
740 (insert (format "(iso-10646-comment\t. %S)%s"
743 (setq attributes (delq 'iso-10646-comment attributes))
745 (when (and (memq 'morohashi-daikanwa attributes)
746 (setq value (get-char-attribute char 'morohashi-daikanwa)))
747 (insert (format "(morohashi-daikanwa\t%s)%s"
748 (mapconcat (function prin1-to-string) value " ")
750 (setq attributes (delq 'morohashi-daikanwa attributes))
754 (when (and (memq 'ideographic-radical attributes)
755 (setq value (get-char-attribute char 'ideographic-radical)))
757 (insert (format "(ideographic-radical . %S)\t; %c%s"
759 (ideographic-radical radical)
761 (setq attributes (delq 'ideographic-radical attributes))
763 (when (and (memq 'shuowen-radical attributes)
764 (setq value (get-char-attribute char 'shuowen-radical)))
765 (insert (format "(shuowen-radical\t. %S)\t; %c%s"
767 (shuowen-radical value)
769 (setq attributes (delq 'shuowen-radical attributes))
774 char-db-feature-domains
776 (dolist (feature (char-attribute-list))
777 (setq feature (symbol-name feature))
779 "\\(radical\\|strokes\\)@\\([^@*]+\\)\\(\\*\\|$\\)"
781 (setq domain (intern (match-string 2 feature)))
782 (unless (memq domain dest)
783 (setq dest (cons domain dest)))))
784 (sort dest #'string<))))
785 (setq key (intern (format "%s@%s" 'ideographic-radical domain)))
786 (when (and (memq key attributes)
787 (setq value (get-char-attribute char key)))
789 (insert (format "(%s . %S)\t; %c%s"
792 (ideographic-radical radical)
794 (setq attributes (delq key attributes))
796 (setq key (intern (format "%s@%s" 'ideographic-strokes domain)))
797 (when (and (memq key attributes)
798 (setq value (get-char-attribute char key)))
800 (insert (format "(%s . %S)%s"
804 (setq attributes (delq key attributes))
806 (setq key (intern (format "%s@%s" 'total-strokes domain)))
807 (when (and (memq key attributes)
808 (setq value (get-char-attribute char key)))
809 (insert (format "(%s . %S)%s"
813 (setq attributes (delq key attributes))
815 (dolist (feature '(ideographic-radical
818 (setq key (intern (format "%s@%s*sources" feature domain)))
819 (when (and (memq key attributes)
820 (setq value (get-char-attribute char key)))
821 (insert (format "(%s%s" key line-breaking))
823 (insert (format " %s" cell)))
825 (insert line-breaking)
826 (setq attributes (delq key attributes))
829 (when (and (memq 'ideographic-strokes attributes)
830 (setq value (get-char-attribute char 'ideographic-strokes)))
832 (insert (format "(ideographic-strokes . %S)%s"
835 (setq attributes (delq 'ideographic-strokes attributes))
837 (when (and (memq 'kangxi-radical attributes)
838 (setq value (get-char-attribute char 'kangxi-radical)))
839 (unless (eq value radical)
840 (insert (format "(kangxi-radical\t . %S)\t; %c%s"
842 (ideographic-radical value)
845 (setq radical value)))
846 (setq attributes (delq 'kangxi-radical attributes))
848 (when (and (memq 'kangxi-strokes attributes)
849 (setq value (get-char-attribute char 'kangxi-strokes)))
850 (unless (eq value strokes)
851 (insert (format "(kangxi-strokes\t . %S)%s"
855 (setq strokes value)))
856 (setq attributes (delq 'kangxi-strokes attributes))
858 (when (and (memq 'japanese-radical attributes)
859 (setq value (get-char-attribute char 'japanese-radical)))
860 (unless (eq value radical)
861 (insert (format "(japanese-radical\t . %S)\t; %c%s"
863 (ideographic-radical value)
866 (setq radical value)))
867 (setq attributes (delq 'japanese-radical attributes))
869 (when (and (memq 'japanese-strokes attributes)
870 (setq value (get-char-attribute char 'japanese-strokes)))
871 (unless (eq value strokes)
872 (insert (format "(japanese-strokes\t . %S)%s"
876 (setq strokes value)))
877 (setq attributes (delq 'japanese-strokes attributes))
879 (when (and (memq 'cns-radical attributes)
880 (setq value (get-char-attribute char 'cns-radical)))
881 (insert (format "(cns-radical\t . %S)\t; %c%s"
883 (ideographic-radical value)
885 (setq attributes (delq 'cns-radical attributes))
887 (when (and (memq 'cns-strokes attributes)
888 (setq value (get-char-attribute char 'cns-strokes)))
889 (unless (eq value strokes)
890 (insert (format "(cns-strokes\t . %S)%s"
894 (setq strokes value)))
895 (setq attributes (delq 'cns-strokes attributes))
897 (when (and (memq 'shinjigen-1-radical attributes)
898 (setq value (get-char-attribute char 'shinjigen-1-radical)))
899 (unless (eq value radical)
900 (insert (format "(shinjigen-1-radical . %S)\t; %c%s"
902 (ideographic-radical value)
905 (setq radical value)))
906 (setq attributes (delq 'shinjigen-1-radical attributes))
908 (when (and (memq 'ideographic- attributes)
909 (setq value (get-char-attribute char 'ideographic-)))
910 (insert "(ideographic- ")
911 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
914 (setq cell (car value))
916 (setq cell (decode-char '=ucs cell)))
917 (cond ((characterp cell)
921 (insert (format "%S" cell))
922 (char-db-insert-char-spec cell readable))
923 (setq separator lbs))
927 (if (consp (car cell))
928 (char-db-insert-char-spec cell readable)
929 (char-db-insert-char-reference cell readable))
930 (setq separator lbs))
934 (insert (prin1-to-string cell))
935 (setq separator " ")))
936 (setq value (cdr value)))
938 (insert line-breaking)
939 (setq attributes (delq 'ideographic- attributes)))
940 (when (and (memq 'total-strokes attributes)
941 (setq value (get-char-attribute char 'total-strokes)))
942 (insert (format "(total-strokes . %S)%s"
945 (setq attributes (delq 'total-strokes attributes))
947 (when (and (memq '->ideograph attributes)
948 (setq value (get-char-attribute char '->ideograph)))
949 (insert (format "(->ideograph\t%s)%s"
950 (mapconcat (lambda (code)
951 (cond ((symbolp code)
954 (format "#x%04X" code))
957 line-breaking code))))
960 (setq attributes (delq '->ideograph attributes))
962 ;; (when (and (memq '->decomposition attributes)
963 ;; (setq value (get-char-attribute char '->decomposition)))
964 ;; (insert (format "(->decomposition\t%s)%s"
965 ;; (mapconcat (lambda (code)
966 ;; (cond ((symbolp code)
967 ;; (symbol-name code))
968 ;; ((characterp code)
970 ;; (format "%S" code)
975 ;; (format "#x%04X" code))
977 ;; (format "%s%S" line-breaking code))))
980 ;; (setq attributes (delq '->decomposition attributes))
982 (if (equal (get-char-attribute char '->titlecase)
983 (get-char-attribute char '->uppercase))
984 (setq attributes (delq '->titlecase attributes)))
985 (when (and (memq '->mojikyo attributes)
986 (setq value (get-char-attribute char '->mojikyo)))
987 (insert (format "(->mojikyo\t\t. %06d)\t; %c%s"
988 value (decode-char 'mojikyo value)
990 (setq attributes (delq '->mojikyo attributes))
992 (when (and (memq 'hanyu-dazidian-vol attributes)
993 (setq value (get-char-attribute char 'hanyu-dazidian-vol)))
994 (insert (format "(hanyu-dazidian-vol . %d)%s"
995 value line-breaking))
996 (setq attributes (delq 'hanyu-dazidian-vol attributes))
998 (when (and (memq 'hanyu-dazidian-page attributes)
999 (setq value (get-char-attribute char 'hanyu-dazidian-page)))
1000 (insert (format "(hanyu-dazidian-page . %d)%s"
1001 value line-breaking))
1002 (setq attributes (delq 'hanyu-dazidian-page attributes))
1004 (when (and (memq 'hanyu-dazidian-char attributes)
1005 (setq value (get-char-attribute char 'hanyu-dazidian-char)))
1006 (insert (format "(hanyu-dazidian-char . %d)%s"
1007 value line-breaking))
1008 (setq attributes (delq 'hanyu-dazidian-char attributes))
1011 (dolist (ignored '(composition
1012 ->denotational <-subsumptive ->ucs-unified
1013 ->ideographic-component-forms))
1014 (setq attributes (delq ignored attributes))))
1016 (setq name (car attributes))
1017 (if (setq value (get-char-attribute char name))
1018 (cond ((setq ret (find-charset name))
1019 (setq name (charset-name ret))
1020 (if (and (not (memq name dest-ccss))
1022 (setq value (get-char-attribute char name))
1023 (setq dest-ccss (cons name dest-ccss))))
1024 (char-db-insert-ccs-feature name value line-breaking))
1026 ((string-match "^=>ucs@" (symbol-name name))
1027 (insert (format "(%-18s . #x%04X)\t; %c%s"
1028 name value (decode-char '=ucs value)
1031 ((eq name 'jisx0208-1978/4X)
1032 (insert (format "(%-18s . #x%04X)%s"
1038 (not (eq name '->subsumptive))
1039 (not (eq name '->uppercase))
1040 (not (eq name '->lowercase))
1041 (not (eq name '->titlecase))
1042 (not (eq name '->canonical))
1043 (not (eq name '->Bopomofo))
1044 (not (eq name '->mistakable))
1045 (not (eq name '->ideographic-variants))
1046 (null (get-char-attribute
1047 char (intern (format "%s*sources" name))))
1048 (not (string-match "\\*sources$" (symbol-name name)))
1049 (null (get-char-attribute
1050 char (intern (format "%s*note" name))))
1051 (not (string-match "\\*note$" (symbol-name name)))
1052 (or (eq name '<-identical)
1053 (eq name '<-uppercase)
1054 (eq name '<-lowercase)
1055 (eq name '<-titlecase)
1056 (eq name '<-canonical)
1057 (eq name '<-ideographic-variants)
1058 ;; (eq name '<-synonyms)
1059 (string-match "^<-synonyms" (symbol-name name))
1060 (eq name '<-mistakable)
1061 (when (string-match "^->" (symbol-name name))
1063 ((string-match "^->fullwidth" (symbol-name name))
1064 (not (and (consp value)
1065 (characterp (car value))
1067 (car value) '=ucs 'defined-only)))
1072 ((or (eq name 'ideographic-structure)
1073 (eq name 'ideographic-combination)
1074 (eq name 'ideographic-)
1075 (eq name '=decomposition)
1076 (string-match "^=>decomposition" (symbol-name name))
1077 (string-match "^\\(->\\|<-\\)[^*]*$" (symbol-name name))
1078 (string-match "^\\(->\\|<-\\)[^*]*\\*sources$"
1081 (char-db-insert-relation-feature char name value
1084 ((memq name '(ideograph=
1085 original-ideograph-of
1086 ancient-ideograph-of
1089 ;; simplified-ideograph-of
1090 ideographic-variants
1091 ;; ideographic-different-form-of
1093 (insert (format "(%-18s%s " name line-breaking))
1094 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1096 (while (consp value)
1097 (setq cell (car value))
1098 (if (and (consp cell)
1103 (char-db-insert-alist cell readable)
1104 (setq separator lbs))
1107 (insert (prin1-to-string cell))
1108 (setq separator " "))
1109 (setq value (cdr value)))
1111 (insert line-breaking))
1113 (insert (format "(%-18s " name))
1114 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1116 (while (consp value)
1117 (setq cell (car value))
1118 (if (and (consp cell)
1120 (setq ret (condition-case nil
1128 (setq key (car (car rest)))
1129 (if (find-charset key)
1130 (setq cal (cons key cal))
1131 (setq al (cons key al)))
1132 (setq rest (cdr rest)))
1135 (insert-char-attributes ret
1138 (setq separator lbs))
1139 (setq ret (prin1-to-string cell))
1141 (if (< (+ (current-column)
1148 (setq separator " "))
1149 (setq value (cdr value)))
1151 (insert line-breaking))
1153 (insert (format "(%-18s" name))
1154 (setq ret (prin1-to-string value))
1155 (unless (< (+ (current-column)
1159 (insert line-breaking))
1160 (insert " . " ret ")" line-breaking)
1161 ;; (insert (format "(%-18s . %S)%s"
1166 (setq attributes (cdr attributes)))
1169 (defun insert-char-data (char &optional readable
1172 (narrow-to-region (point)(point))
1173 (insert "(define-char
1175 (insert-char-attributes char readable attributes)
1177 (goto-char (point-min))
1178 (while (re-search-forward "[ \t]+$" nil t)
1181 (goto-char (point-min))
1182 (while (re-search-forward "[ \t][ \t][ \t]*" nil t)
1183 (let ((column (current-column))
1184 (indent-tabs-mode t))
1185 (delete-region (match-beginning 0) (point))
1186 (indent-to column)))
1187 (goto-char (point-max))
1188 ;; (tabify (point-min)(point-max))
1191 (defun insert-char-data-with-variant (char &optional printable
1193 script excluded-script)
1194 (insert-char-data char printable)
1195 (let ((variants (char-variants char))
1198 (setq variants (sort variants #'<))
1199 (setq rest variants)
1200 (setq variants (cons char variants))
1202 (setq variant (car rest))
1203 (unless (get-char-attribute variant '<-subsumptive)
1204 (if (and (or (null script)
1205 (null (setq vs (get-char-attribute variant 'script)))
1207 (or (null excluded-script)
1208 (null (setq vs (get-char-attribute variant 'script)))
1209 (not (memq excluded-script vs))))
1210 (unless (and no-ucs-unified (get-char-attribute variant '=ucs))
1211 (insert-char-data variant printable)
1212 (if (setq ret (char-variants variant))
1214 (or (memq (car ret) variants)
1215 ;; (get-char-attribute (car ret) '<-subsumptive)
1216 (setq rest (nconc rest (list (car ret)))))
1217 (setq ret (cdr ret)))))))
1218 (setq rest (cdr rest)))))
1220 (defun insert-char-range-data (min max &optional script excluded-script)
1223 (while (<= code max)
1224 (setq char (decode-char '=ucs code))
1225 (if (encode-char char '=ucs 'defined-only)
1226 (insert-char-data-with-variant char nil 'no-ucs-unified
1227 script excluded-script))
1228 (setq code (1+ code)))))
1230 (defun write-char-range-data-to-file (min max file
1231 &optional script excluded-script)
1232 (let ((coding-system-for-write char-db-file-coding-system))
1234 (insert (format ";; -*- coding: %s -*-\n"
1235 char-db-file-coding-system))
1236 (insert-char-range-data min max script excluded-script)
1237 (write-region (point-min)(point-max) file))))
1239 (defvar what-character-original-window-configuration)
1242 (defun what-char-definition (char)
1243 (interactive (list (char-after)))
1244 (let ((buf (get-buffer-create "*Character Description*"))
1245 (the-buf (current-buffer))
1246 (win-conf (current-window-configuration)))
1248 (make-local-variable 'what-character-original-window-configuration)
1249 (setq what-character-original-window-configuration win-conf)
1250 (setq buffer-read-only nil)
1254 (insert-char-data-with-variant char 'printable)
1255 (unless (char-attribute-alist char)
1256 (insert (format ";; = %c\n"
1257 (let* ((rest (split-char char))
1261 (setq code (logior (lsh code 8)
1263 (decode-char ccs code)))))
1264 ;; (char-db-update-comment)
1265 (set-buffer-modified-p nil)
1266 (view-mode the-buf (lambda (buf)
1267 (set-window-configuration
1268 what-character-original-window-configuration)
1270 (goto-char (point-min)))
1272 (set-window-configuration
1273 what-character-original-window-configuration)
1274 (signal (car err) (cdr err)))))))
1276 (provide 'char-db-util)
1278 ;;; char-db-util.el ends here