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 (if (find-charset kb)
101 (if (<= (charset-id ka) 1)
102 (if (<= (charset-id kb) 1)
104 ((= (charset-dimension ka)
105 (charset-dimension kb))
106 (> (charset-id ka)(charset-id kb)))
108 (> (charset-dimension ka)
109 (charset-dimension kb))
112 (if (<= (charset-id kb) 1)
114 (< (charset-id ka)(charset-id kb))))
120 (string< (symbol-name ka)
126 (defvar char-db-coded-charset-priority-list
186 (defun char-db-make-char-spec (char)
188 (cond ((characterp char)
189 (cond ((and (setq ret (encode-char char '=ucs 'defined-only))
190 (not (and (<= #xE000 ret)(<= ret #xF8FF))))
191 (setq char-spec (list (cons '=ucs ret)))
192 (cond ((setq ret (get-char-attribute char 'name))
193 (setq char-spec (cons (cons 'name ret) char-spec))
195 ((setq ret (get-char-attribute char 'name*))
196 (setq char-spec (cons (cons 'name* ret) char-spec))
201 (let ((rest char-db-coded-charset-priority-list)
204 (setq ccs (charset-name
205 (find-charset (car rest))))
207 (encode-char char ccs
209 (throw 'tag (cons ccs ret)))
210 (setq rest (cdr rest))))))
211 (setq char-spec (list ret))
212 (dolist (ccs (delq (car ret) (charset-list)))
213 (if (and (or (charset-iso-final-char ccs)
219 (setq ccs (charset-name ccs))
220 (null (assq ccs char-spec))
221 (setq ret (encode-char char ccs 'defined-only)))
222 (setq char-spec (cons (cons ccs ret) char-spec))))
224 (setq char-spec (split-char char)))
225 (cond ((setq ret (get-char-attribute char 'name))
226 (setq char-spec (cons (cons 'name ret) char-spec))
228 ((setq ret (get-char-attribute char 'name*))
229 (setq char-spec (cons (cons 'name* ret) char-spec))
236 (defun char-db-insert-char-spec (char &optional readable column
239 (setq column (current-column)))
240 (let (char-spec temp-char)
241 (setq char-spec (char-db-make-char-spec char))
242 (unless (or (characterp char) ; char
244 (setq char (find-char char-spec))
246 ;; define temporary character
247 ;; Current implementation is dirty.
248 (setq temp-char (define-char (cons '(ideograph-daikanwa . 0)
250 (remove-char-attribute temp-char 'ideograph-daikanwa)
251 (setq char temp-char))
252 (insert-char-attributes char
254 (union (mapcar #'car char-spec)
257 ;; undefine temporary character
258 ;; Current implementation is dirty.
259 (setq char-spec (char-attribute-alist temp-char))
261 (remove-char-attribute temp-char (car (car char-spec)))
262 (setq char-spec (cdr char-spec))))))
264 (defun char-db-insert-alist (alist &optional readable column)
266 (setq column (current-column)))
268 (concat "\n" (make-string (1+ column) ?\ )))
272 lbs cell rest separator)
275 (setq name (car (car alist))
276 value (cdr (car alist)))
277 (cond ((eq name 'char)
279 (if (setq ret (condition-case nil
287 (setq key (car (car value)))
288 ;; (if (find-charset key)
289 ;; (setq cal (cons key cal))
290 (setq al (cons key al))
292 (setq value (cdr value)))
293 (insert-char-attributes ret
297 (insert (prin1-to-string value)))
299 (insert line-breaking))
301 (insert (format "(%-18s " name))
302 (setq lbs (concat "\n" (make-string (current-column) ?\ )))
304 (setq cell (car value))
305 (if (and (consp cell)
307 (setq ret (condition-case nil
317 (setq key (car (car rest)))
318 ;; (if (find-charset key)
319 ;; (setq cal (cons key cal))
320 (setq al (cons key al))
322 (setq rest (cdr rest)))
325 (insert-char-attributes ret
329 (setq separator lbs))
332 (insert (prin1-to-string cell))
333 (setq separator " "))
334 (setq value (cdr value)))
336 (insert line-breaking))
338 (insert (format "(%-18s . %S)%s"
341 (setq alist (cdr alist))))
344 (defun char-db-insert-char-reference (plist &optional readable column)
346 (setq column (current-column)))
348 (concat "\n" (make-string (1+ column) ?\ )))
353 (setq name (pop plist))
354 (setq value (pop plist))
355 (cond ((eq name :char)
358 (cond ((numberp value)
359 (setq value (decode-char '=ucs value)))
361 ;; (setq value (or (find-char value)
364 (char-db-insert-char-spec value readable)
365 (insert line-breaking)
368 (insert (format "%s%s\t%d ; %c%s"
371 (ideographic-radical value)
375 (insert (format "%s%s\t%S" separator name value))
376 (setq separator line-breaking)))
380 (defun char-db-decode-isolated-char (ccs code-point)
383 (cond ((eq ccs 'arabic-iso8859-6)
384 (decode-char ccs code-point))
385 ((and (memq ccs '(=gt-pj-1
396 (setq ret (decode-char ccs code-point))
397 (setq ret (encode-char ret '=gt 'defined-only)))
398 (decode-builtin-char '=gt ret))
400 (decode-builtin-char ccs code-point))))
401 (cond ((and (<= 0 (char-int ret))
402 (<= (char-int ret) #x1F))
403 (decode-char '=ucs (+ #x2400 (char-int ret))))
404 ((= (char-int ret) #x7F)
408 (defvar char-db-convert-obsolete-format t)
410 (defun char-db-insert-ccs-feature (name value line-breaking)
413 (cond ((memq name '(=daikanwa
414 =daikanwa@rev1 =daikanwa@rev2
415 =gt =gt-k =cbeta =zinbun-oracle))
416 "(%-18s . %05d)\t; %c")
418 "(%-18s . %06d)\t; %c")
419 ((>= (charset-dimension name) 2)
420 "(%-18s . #x%04X)\t; %c")
422 "(%-18s . #x%02X)\t; %c"))
424 (if (= (charset-iso-graphic-plane name) 1)
426 (cond ((= (charset-dimension name) 1)
428 ((= (charset-dimension name) 2)
430 ((= (charset-dimension name) 3)
434 (char-db-decode-isolated-char name value)))
435 (if (and (= (charset-chars name) 94)
436 (= (charset-dimension name) 2))
437 (insert (format " [%02d-%02d]"
438 (- (lsh value -8) 32)
439 (- (logand value 255) 32))))
440 (insert line-breaking))
442 (defun char-db-insert-relation-feature (char name value line-breaking
444 (insert (format "(%-18s%s " name line-breaking))
445 (let ((lbs (concat "\n" (make-string (current-column) ?\ )))
446 separator cell sources required-features
449 (setq cell (car value))
451 (setq cell (decode-char '=ucs cell)))
453 ((eq name '->subsumptive)
454 (when (or (not (some (lambda (atr)
455 (get-char-attribute cell atr))
456 char-db-ignored-attributes))
458 (encode-char cell ccs 'defined-only))
462 (let ((char-db-ignored-attributes
464 char-db-ignored-attributes)))
465 (insert-char-attributes cell readable))
466 (setq separator lbs))
471 char (intern (format "%s*sources" name))))
472 (setq required-features nil)
473 (dolist (source sources)
475 ((memq source '(JP JP/Jouyou shinjigen-1))
476 (setq required-features
477 (union required-features
486 (setq required-features
487 (union required-features
492 ((find-charset (setq ret (intern (format "=%s" source))))
493 (setq required-features
494 (cons ret required-features)))
495 (t (setq required-features
496 (cons source required-features)))))
497 (cond ((string-match "@JP" (symbol-name name))
498 (setq required-features
499 (union required-features
507 ((string-match "@CN" (symbol-name name))
508 (setq required-features
509 (union required-features
516 (insert (format "%S" cell))
517 (char-db-insert-char-spec cell readable
520 (setq separator lbs))
524 (if (consp (car cell))
525 (char-db-insert-char-spec cell readable)
526 (char-db-insert-char-reference cell readable))
527 (setq separator lbs))
531 (insert (prin1-to-string cell))
532 (setq separator " ")))
533 (setq value (cdr value)))
535 (insert line-breaking)))
537 (defun insert-char-attributes (char &optional readable attributes column)
539 (setq column (current-column)))
540 (let (name value ; has-long-ccs-name
544 (concat "\n" (make-string (1+ column) ?\ )))
545 lbs cell separator ret
547 dest-ccss ; sources required-features
552 (if (consp attributes)
554 (dolist (name attributes)
555 (unless (memq name char-db-ignored-attributes)
556 (if (find-charset name)
560 (dolist (name (char-attribute-list))
561 (unless (memq name char-db-ignored-attributes)
562 (if (find-charset name)
566 #'char-attribute-name<)))
568 (when (and (memq 'name attributes)
569 (setq value (get-char-attribute char 'name)))
571 (if (> (+ (current-column) (length value)) 48)
574 value line-breaking))
575 (setq attributes (delq 'name attributes))
577 (when (and (memq 'name* attributes)
578 (setq value (get-char-attribute char 'name*)))
580 (if (> (+ (current-column) (length value)) 48)
583 value line-breaking))
584 (setq attributes (delq 'name* attributes))
586 (when (and (memq 'script attributes)
587 (setq value (get-char-attribute char 'script)))
588 (insert (format "(script\t\t%s)%s"
589 (mapconcat (function prin1-to-string)
592 (setq attributes (delq 'script attributes))
594 ;; (when (and (memq '<-denotational attributes)
595 ;; (setq value (get-char-attribute char '<-denotational))
596 ;; (null (cdr value))
597 ;; (setq value (encode-char (car value) 'ucs 'defined-only)))
598 ;; (insert (format "(%-18s . #x%04X)\t; %c%s"
599 ;; '=>ucs value (decode-char 'ucs value)
601 ;; (setq attributes (delq '<-denotational attributes)))
602 (dolist (name '(=>ucs =>ucs*))
603 (when (and (memq name attributes)
604 (setq value (get-char-attribute char name)))
605 (insert (format "(%-18s . #x%04X)\t; %c%s"
606 name value (decode-char '=ucs value)
608 (setq attributes (delq name attributes))))
609 (dolist (name '(=>ucs@gb =>ucs@cns =>ucs@jis =>ucs@ks =>ucs@big5))
610 (when (and (memq name attributes)
611 (setq value (get-char-attribute char name)))
612 (insert (format "(%-18s . #x%04X)\t; %c%s"
617 (symbol-name name) 2)))
620 (setq attributes (delq name attributes))
622 (dolist (name '(=>daikanwa))
623 (when (and (memq name attributes)
624 (setq value (get-char-attribute char name)))
627 (format "(%-18s . %05d)\t; %c%s"
628 name value (decode-char '=daikanwa value)
630 (format "(%-18s %s)\t; %c%s"
632 (mapconcat (function prin1-to-string)
634 (char-representative-of-daikanwa char)
636 (setq attributes (delq name attributes))))
637 (when (and (memq 'general-category attributes)
638 (setq value (get-char-attribute char 'general-category)))
640 "(general-category\t%s) ; %s%s"
641 (mapconcat (lambda (cell)
644 (cond ((rassoc value unidata-normative-category-alist)
645 "Normative Category")
646 ((rassoc value unidata-informative-category-alist)
647 "Informative Category")
651 (setq attributes (delq 'general-category attributes))
653 (when (and (memq 'bidi-category attributes)
654 (setq value (get-char-attribute char 'bidi-category)))
655 (insert (format "(bidi-category\t. %S)%s"
658 (setq attributes (delq 'bidi-category attributes))
660 (unless (or (not (memq 'mirrored attributes))
661 (eq (setq value (get-char-attribute char 'mirrored 'empty))
663 (insert (format "(mirrored\t\t. %S)%s"
666 (setq attributes (delq 'mirrored attributes))
669 ((and (memq 'decimal-digit-value attributes)
670 (setq value (get-char-attribute char 'decimal-digit-value)))
671 (insert (format "(decimal-digit-value . %S)%s"
674 (setq attributes (delq 'decimal-digit-value attributes))
675 (when (and (memq 'digit-value attributes)
676 (setq value (get-char-attribute char 'digit-value)))
677 (insert (format "(digit-value\t . %S)%s"
680 (setq attributes (delq 'digit-value attributes))
682 (when (and (memq 'numeric-value attributes)
683 (setq value (get-char-attribute char 'numeric-value)))
684 (insert (format "(numeric-value\t . %S)%s"
687 (setq attributes (delq 'numeric-value attributes))
691 (when (and (memq 'digit-value attributes)
692 (setq value (get-char-attribute char 'digit-value)))
693 (insert (format "(digit-value\t. %S)%s"
696 (setq attributes (delq 'digit-value attributes))
698 (when (and (memq 'numeric-value attributes)
699 (setq value (get-char-attribute char 'numeric-value)))
700 (insert (format "(numeric-value\t. %S)%s"
703 (setq attributes (delq 'numeric-value attributes))
705 (when (and (memq 'iso-10646-comment attributes)
706 (setq value (get-char-attribute char 'iso-10646-comment)))
707 (insert (format "(iso-10646-comment\t. %S)%s"
710 (setq attributes (delq 'iso-10646-comment attributes))
712 (when (and (memq 'morohashi-daikanwa attributes)
713 (setq value (get-char-attribute char 'morohashi-daikanwa)))
714 (insert (format "(morohashi-daikanwa\t%s)%s"
715 (mapconcat (function prin1-to-string) value " ")
717 (setq attributes (delq 'morohashi-daikanwa attributes))
721 (when (and (memq 'ideographic-radical attributes)
722 (setq value (get-char-attribute char 'ideographic-radical)))
724 (insert (format "(ideographic-radical . %S)\t; %c%s"
726 (ideographic-radical radical)
728 (setq attributes (delq 'ideographic-radical attributes))
730 (when (and (memq 'shuowen-radical attributes)
731 (setq value (get-char-attribute char 'shuowen-radical)))
732 (insert (format "(shuowen-radical\t. %S)\t; %c%s"
734 (shuowen-radical value)
736 (setq attributes (delq 'shuowen-radical attributes))
741 char-db-feature-domains
743 (dolist (feature (char-attribute-list))
744 (setq feature (symbol-name feature))
746 "\\(radical\\|strokes\\)@\\([^@*]+\\)\\(\\*\\|$\\)"
748 (setq domain (intern (match-string 2 feature)))
749 (unless (memq domain dest)
750 (setq dest (cons domain dest)))))
751 (sort dest #'string<))))
752 (setq key (intern (format "%s@%s" 'ideographic-radical domain)))
753 (when (and (memq key attributes)
754 (setq value (get-char-attribute char key)))
756 (insert (format "(%s . %S)\t; %c%s"
759 (ideographic-radical radical)
761 (setq attributes (delq key attributes))
763 (setq key (intern (format "%s@%s" 'ideographic-strokes domain)))
764 (when (and (memq key attributes)
765 (setq value (get-char-attribute char key)))
767 (insert (format "(%s . %S)%s"
771 (setq attributes (delq key attributes))
773 (setq key (intern (format "%s@%s" 'total-strokes domain)))
774 (when (and (memq key attributes)
775 (setq value (get-char-attribute char key)))
776 (insert (format "(%s . %S)%s"
780 (setq attributes (delq key attributes))
782 (dolist (feature '(ideographic-radical
785 (setq key (intern (format "%s@%s*sources" feature domain)))
786 (when (and (memq key attributes)
787 (setq value (get-char-attribute char key)))
788 (insert (format "(%s%s" key line-breaking))
790 (insert (format " %s" cell)))
792 (insert line-breaking)
793 (setq attributes (delq key attributes))
796 (when (and (memq 'ideographic-strokes attributes)
797 (setq value (get-char-attribute char 'ideographic-strokes)))
799 (insert (format "(ideographic-strokes . %S)%s"
802 (setq attributes (delq 'ideographic-strokes attributes))
804 (when (and (memq 'kangxi-radical attributes)
805 (setq value (get-char-attribute char 'kangxi-radical)))
806 (unless (eq value radical)
807 (insert (format "(kangxi-radical\t . %S)\t; %c%s"
809 (ideographic-radical value)
812 (setq radical value)))
813 (setq attributes (delq 'kangxi-radical attributes))
815 (when (and (memq 'kangxi-strokes attributes)
816 (setq value (get-char-attribute char 'kangxi-strokes)))
817 (unless (eq value strokes)
818 (insert (format "(kangxi-strokes\t . %S)%s"
822 (setq strokes value)))
823 (setq attributes (delq 'kangxi-strokes attributes))
825 (when (and (memq 'japanese-radical attributes)
826 (setq value (get-char-attribute char 'japanese-radical)))
827 (unless (eq value radical)
828 (insert (format "(japanese-radical\t . %S)\t; %c%s"
830 (ideographic-radical value)
833 (setq radical value)))
834 (setq attributes (delq 'japanese-radical attributes))
836 (when (and (memq 'japanese-strokes attributes)
837 (setq value (get-char-attribute char 'japanese-strokes)))
838 (unless (eq value strokes)
839 (insert (format "(japanese-strokes\t . %S)%s"
843 (setq strokes value)))
844 (setq attributes (delq 'japanese-strokes attributes))
846 (when (and (memq 'cns-radical attributes)
847 (setq value (get-char-attribute char 'cns-radical)))
848 (insert (format "(cns-radical\t . %S)\t; %c%s"
850 (ideographic-radical value)
852 (setq attributes (delq 'cns-radical attributes))
854 (when (and (memq 'cns-strokes attributes)
855 (setq value (get-char-attribute char 'cns-strokes)))
856 (unless (eq value strokes)
857 (insert (format "(cns-strokes\t . %S)%s"
861 (setq strokes value)))
862 (setq attributes (delq 'cns-strokes attributes))
864 (when (and (memq 'shinjigen-1-radical attributes)
865 (setq value (get-char-attribute char 'shinjigen-1-radical)))
866 (unless (eq value radical)
867 (insert (format "(shinjigen-1-radical . %S)\t; %c%s"
869 (ideographic-radical value)
872 (setq radical value)))
873 (setq attributes (delq 'shinjigen-1-radical attributes))
875 (when (and (memq 'ideographic- attributes)
876 (setq value (get-char-attribute char 'ideographic-)))
877 (insert "(ideographic- ")
878 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
881 (setq cell (car value))
883 (setq cell (decode-char '=ucs cell)))
884 (cond ((characterp cell)
888 (insert (format "%S" cell))
889 (char-db-insert-char-spec cell readable))
890 (setq separator lbs))
894 (if (consp (car cell))
895 (char-db-insert-char-spec cell readable)
896 (char-db-insert-char-reference cell readable))
897 (setq separator lbs))
901 (insert (prin1-to-string cell))
902 (setq separator " ")))
903 (setq value (cdr value)))
905 (insert line-breaking)
906 (setq attributes (delq 'ideographic- attributes)))
907 (when (and (memq 'total-strokes attributes)
908 (setq value (get-char-attribute char 'total-strokes)))
909 (insert (format "(total-strokes . %S)%s"
912 (setq attributes (delq 'total-strokes attributes))
914 (when (and (memq '->ideograph attributes)
915 (setq value (get-char-attribute char '->ideograph)))
916 (insert (format "(->ideograph\t%s)%s"
917 (mapconcat (lambda (code)
918 (cond ((symbolp code)
921 (format "#x%04X" code))
924 line-breaking code))))
927 (setq attributes (delq '->ideograph attributes))
929 (when (and (memq '->decomposition attributes)
930 (setq value (get-char-attribute char '->decomposition)))
931 (insert (format "(->decomposition\t%s)%s"
932 (mapconcat (lambda (code)
933 (cond ((symbolp code)
942 (format "#x%04X" code))
944 (format "%s%S" line-breaking code))))
947 (setq attributes (delq '->decomposition attributes))
949 (if (equal (get-char-attribute char '->titlecase)
950 (get-char-attribute char '->uppercase))
951 (setq attributes (delq '->titlecase attributes)))
952 (when (and (memq '->mojikyo attributes)
953 (setq value (get-char-attribute char '->mojikyo)))
954 (insert (format "(->mojikyo\t\t. %06d)\t; %c%s"
955 value (decode-char 'mojikyo value)
957 (setq attributes (delq '->mojikyo attributes))
959 (when (and (memq 'hanyu-dazidian-vol attributes)
960 (setq value (get-char-attribute char 'hanyu-dazidian-vol)))
961 (insert (format "(hanyu-dazidian-vol . %d)%s"
962 value line-breaking))
963 (setq attributes (delq 'hanyu-dazidian-vol attributes))
965 (when (and (memq 'hanyu-dazidian-page attributes)
966 (setq value (get-char-attribute char 'hanyu-dazidian-page)))
967 (insert (format "(hanyu-dazidian-page . %d)%s"
968 value line-breaking))
969 (setq attributes (delq 'hanyu-dazidian-page attributes))
971 (when (and (memq 'hanyu-dazidian-char attributes)
972 (setq value (get-char-attribute char 'hanyu-dazidian-char)))
973 (insert (format "(hanyu-dazidian-char . %d)%s"
974 value line-breaking))
975 (setq attributes (delq 'hanyu-dazidian-char attributes))
978 (dolist (ignored '(composition
979 ->denotational <-subsumptive ->ucs-unified
980 ->ideographic-component-forms))
981 (setq attributes (delq ignored attributes))))
983 (setq name (car attributes))
984 (if (setq value (get-char-attribute char name))
985 (cond ((setq ret (find-charset name))
986 (setq name (charset-name ret))
987 (if (and (not (memq name dest-ccss))
989 (setq value (get-char-attribute char name))
990 (setq dest-ccss (cons name dest-ccss))))
991 (char-db-insert-ccs-feature name value line-breaking))
993 ((string-match "^=>ucs@" (symbol-name name))
994 (insert (format "(%-18s . #x%04X)\t; %c%s"
995 name value (decode-char '=ucs value)
998 ((eq name 'jisx0208-1978/4X)
999 (insert (format "(%-18s . #x%04X)%s"
1003 ((and (not readable)
1004 (null (get-char-attribute
1006 (intern (format "%s*sources" name))))
1007 (not (string-match "\\*sources$" (symbol-name name)))
1008 (or (eq name '<-identical)
1009 (string-match "^->halfwidth" (symbol-name name))
1011 (string-match "^->fullwidth" (symbol-name name))
1014 (characterp (car value))
1016 (car value) '=ucs 'defined-only))))
1017 (string-match "^->simplified" (symbol-name name))
1018 (string-match "^->vulgar" (symbol-name name))
1019 (string-match "^->wrong" (symbol-name name))
1020 (string-match "^->same" (symbol-name name))
1021 (string-match "^->formed" (symbol-name name))
1022 (string-match "^->original" (symbol-name name))
1023 (string-match "^->ancient" (symbol-name name))
1024 (string-match "^->Oracle-Bones" (symbol-name name))
1027 ((or (eq name 'ideographic-structure)
1028 (eq name 'ideographic-combination)
1029 (eq name 'ideographic-)
1030 (string-match "^\\(->\\|<-\\)" (symbol-name name)))
1031 (char-db-insert-relation-feature char name value
1034 ((memq name '(ideograph=
1035 original-ideograph-of
1036 ancient-ideograph-of
1039 ;; simplified-ideograph-of
1040 ideographic-variants
1041 ;; ideographic-different-form-of
1043 (insert (format "(%-18s%s " name line-breaking))
1044 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1046 (while (consp value)
1047 (setq cell (car value))
1048 (if (and (consp cell)
1053 (char-db-insert-alist cell readable)
1054 (setq separator lbs))
1057 (insert (prin1-to-string cell))
1058 (setq separator " "))
1059 (setq value (cdr value)))
1061 (insert line-breaking))
1063 (insert (format "(%-18s " name))
1064 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1066 (while (consp value)
1067 (setq cell (car value))
1068 (if (and (consp cell)
1070 (setq ret (condition-case nil
1078 (setq key (car (car rest)))
1079 (if (find-charset key)
1080 (setq cal (cons key cal))
1081 (setq al (cons key al)))
1082 (setq rest (cdr rest)))
1085 (insert-char-attributes ret
1088 (setq separator lbs))
1089 (setq ret (prin1-to-string cell))
1091 (if (< (+ (current-column)
1098 (setq separator " "))
1099 (setq value (cdr value)))
1101 (insert line-breaking))
1103 (insert (format "(%-18s . %S)%s"
1107 (setq attributes (cdr attributes)))
1110 (defun insert-char-data (char &optional readable
1113 (narrow-to-region (point)(point))
1114 (insert "(define-char
1116 (insert-char-attributes char readable attributes)
1118 (goto-char (point-min))
1119 (while (re-search-forward "[ \t]+$" nil t)
1122 (goto-char (point-min))
1123 (while (re-search-forward "[ \t][ \t][ \t]*" nil t)
1124 (let ((column (current-column))
1125 (indent-tabs-mode t))
1126 (delete-region (match-beginning 0) (point))
1127 (indent-to column)))
1128 (goto-char (point-max))
1129 ;; (tabify (point-min)(point-max))
1132 (defun insert-char-data-with-variant (char &optional printable
1134 script excluded-script)
1135 (insert-char-data char printable)
1136 (let ((variants (char-variants char))
1139 (setq variants (sort variants #'<))
1140 (setq rest variants)
1141 (setq variants (cons char variants))
1143 (setq variant (car rest))
1144 (unless (get-char-attribute variant '<-subsumptive)
1145 (if (and (or (null script)
1146 (null (setq vs (get-char-attribute variant 'script)))
1148 (or (null excluded-script)
1149 (null (setq vs (get-char-attribute variant 'script)))
1150 (not (memq excluded-script vs))))
1151 (unless (and no-ucs-unified (get-char-attribute variant '=ucs))
1152 (insert-char-data variant printable)
1153 (if (setq ret (char-variants variant))
1155 (or (memq (car ret) variants)
1156 ;; (get-char-attribute (car ret) '<-subsumptive)
1157 (setq rest (nconc rest (list (car ret)))))
1158 (setq ret (cdr ret)))))))
1159 (setq rest (cdr rest)))))
1161 (defun insert-char-range-data (min max &optional script excluded-script)
1164 (while (<= code max)
1165 (setq char (decode-char '=ucs code))
1166 (if (encode-char char '=ucs 'defined-only)
1167 (insert-char-data-with-variant char nil 'no-ucs-unified
1168 script excluded-script))
1169 (setq code (1+ code)))))
1171 (defun write-char-range-data-to-file (min max file
1172 &optional script excluded-script)
1173 (let ((coding-system-for-write char-db-file-coding-system))
1175 (insert (format ";; -*- coding: %s -*-\n"
1176 char-db-file-coding-system))
1177 (insert-char-range-data min max script excluded-script)
1178 (write-region (point-min)(point-max) file))))
1180 (defvar what-character-original-window-configuration)
1183 (defun what-char-definition (char)
1184 (interactive (list (char-after)))
1185 (let ((buf (get-buffer-create "*Character Description*"))
1186 (the-buf (current-buffer))
1187 (win-conf (current-window-configuration)))
1189 (make-local-variable 'what-character-original-window-configuration)
1190 (setq what-character-original-window-configuration win-conf)
1191 (setq buffer-read-only nil)
1195 (insert-char-data-with-variant char 'printable)
1196 (unless (char-attribute-alist char)
1197 (insert (format ";; = %c\n"
1198 (let* ((rest (split-char char))
1202 (setq code (logior (lsh code 8)
1204 (decode-char ccs code)))))
1205 ;; (char-db-update-comment)
1206 (set-buffer-modified-p nil)
1207 (view-mode the-buf (lambda (buf)
1208 (set-window-configuration
1209 what-character-original-window-configuration)
1211 (goto-char (point-min)))
1213 (set-window-configuration
1214 what-character-original-window-configuration)
1215 (signal (car err) (cdr err)))))))
1217 (provide 'char-db-util)
1219 ;;; char-db-util.el ends here