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 (memq '<-subsumptive attributes)
570 (when (setq value (get-char-attribute char '<-subsumptive))
571 (char-db-insert-relation-feature char '<-subsumptive value
574 (setq attributes (delq '<-subsumptive attributes)))
575 (when (and (memq '<-denotational attributes)
576 (setq value (get-char-attribute char '<-denotational)))
577 (char-db-insert-relation-feature char '<-denotational value
580 (setq attributes (delq '<-denotational attributes)))
581 (when (and (memq 'name attributes)
582 (setq value (get-char-attribute char 'name)))
584 (if (> (+ (current-column) (length value)) 48)
587 value line-breaking))
588 (setq attributes (delq 'name attributes))
590 (when (and (memq 'name* attributes)
591 (setq value (get-char-attribute char 'name*)))
593 (if (> (+ (current-column) (length value)) 48)
596 value line-breaking))
597 (setq attributes (delq 'name* attributes))
599 (when (and (memq 'script attributes)
600 (setq value (get-char-attribute char 'script)))
601 (insert (format "(script\t\t%s)%s"
602 (mapconcat (function prin1-to-string)
605 (setq attributes (delq 'script attributes))
607 (dolist (name '(=>ucs =>ucs*))
608 (when (and (memq name attributes)
609 (setq value (get-char-attribute char name)))
610 (insert (format "(%-18s . #x%04X)\t; %c%s"
611 name value (decode-char '=ucs value)
613 (setq attributes (delq name attributes))))
614 (dolist (name '(=>ucs@gb =>ucs@cns =>ucs@jis =>ucs@ks =>ucs@big5))
615 (when (and (memq name attributes)
616 (setq value (get-char-attribute char name)))
617 (insert (format "(%-18s . #x%04X)\t; %c%s"
622 (symbol-name name) 2)))
625 (setq attributes (delq name attributes))
627 (dolist (name '(=>daikanwa))
628 (when (and (memq name attributes)
629 (setq value (get-char-attribute char name)))
632 (format "(%-18s . %05d)\t; %c%s"
633 name value (decode-char '=daikanwa value)
635 (format "(%-18s %s)\t; %c%s"
637 (mapconcat (function prin1-to-string)
639 (char-representative-of-daikanwa char)
641 (setq attributes (delq name attributes))))
642 (when (and (memq 'general-category attributes)
643 (setq value (get-char-attribute char 'general-category)))
645 "(general-category\t%s) ; %s%s"
646 (mapconcat (lambda (cell)
649 (cond ((rassoc value unidata-normative-category-alist)
650 "Normative Category")
651 ((rassoc value unidata-informative-category-alist)
652 "Informative Category")
656 (setq attributes (delq 'general-category attributes))
658 (when (and (memq 'bidi-category attributes)
659 (setq value (get-char-attribute char 'bidi-category)))
660 (insert (format "(bidi-category\t. %S)%s"
663 (setq attributes (delq 'bidi-category attributes))
665 (unless (or (not (memq 'mirrored attributes))
666 (eq (setq value (get-char-attribute char 'mirrored 'empty))
668 (insert (format "(mirrored\t\t. %S)%s"
671 (setq attributes (delq 'mirrored attributes))
674 ((and (memq 'decimal-digit-value attributes)
675 (setq value (get-char-attribute char 'decimal-digit-value)))
676 (insert (format "(decimal-digit-value . %S)%s"
679 (setq attributes (delq 'decimal-digit-value attributes))
680 (when (and (memq 'digit-value attributes)
681 (setq value (get-char-attribute char 'digit-value)))
682 (insert (format "(digit-value\t . %S)%s"
685 (setq attributes (delq 'digit-value attributes))
687 (when (and (memq 'numeric-value attributes)
688 (setq value (get-char-attribute char 'numeric-value)))
689 (insert (format "(numeric-value\t . %S)%s"
692 (setq attributes (delq 'numeric-value attributes))
696 (when (and (memq 'digit-value attributes)
697 (setq value (get-char-attribute char 'digit-value)))
698 (insert (format "(digit-value\t. %S)%s"
701 (setq attributes (delq 'digit-value attributes))
703 (when (and (memq 'numeric-value attributes)
704 (setq value (get-char-attribute char 'numeric-value)))
705 (insert (format "(numeric-value\t. %S)%s"
708 (setq attributes (delq 'numeric-value attributes))
710 (when (and (memq 'iso-10646-comment attributes)
711 (setq value (get-char-attribute char 'iso-10646-comment)))
712 (insert (format "(iso-10646-comment\t. %S)%s"
715 (setq attributes (delq 'iso-10646-comment attributes))
717 (when (and (memq 'morohashi-daikanwa attributes)
718 (setq value (get-char-attribute char 'morohashi-daikanwa)))
719 (insert (format "(morohashi-daikanwa\t%s)%s"
720 (mapconcat (function prin1-to-string) value " ")
722 (setq attributes (delq 'morohashi-daikanwa attributes))
726 (when (and (memq 'ideographic-radical attributes)
727 (setq value (get-char-attribute char 'ideographic-radical)))
729 (insert (format "(ideographic-radical . %S)\t; %c%s"
731 (ideographic-radical radical)
733 (setq attributes (delq 'ideographic-radical attributes))
735 (when (and (memq 'shuowen-radical attributes)
736 (setq value (get-char-attribute char 'shuowen-radical)))
737 (insert (format "(shuowen-radical\t. %S)\t; %c%s"
739 (shuowen-radical value)
741 (setq attributes (delq 'shuowen-radical attributes))
746 char-db-feature-domains
748 (dolist (feature (char-attribute-list))
749 (setq feature (symbol-name feature))
751 "\\(radical\\|strokes\\)@\\([^@*]+\\)\\(\\*\\|$\\)"
753 (setq domain (intern (match-string 2 feature)))
754 (unless (memq domain dest)
755 (setq dest (cons domain dest)))))
756 (sort dest #'string<))))
757 (setq key (intern (format "%s@%s" 'ideographic-radical domain)))
758 (when (and (memq key attributes)
759 (setq value (get-char-attribute char key)))
761 (insert (format "(%s . %S)\t; %c%s"
764 (ideographic-radical radical)
766 (setq attributes (delq key attributes))
768 (setq key (intern (format "%s@%s" 'ideographic-strokes domain)))
769 (when (and (memq key attributes)
770 (setq value (get-char-attribute char key)))
772 (insert (format "(%s . %S)%s"
776 (setq attributes (delq key attributes))
778 (setq key (intern (format "%s@%s" 'total-strokes domain)))
779 (when (and (memq key attributes)
780 (setq value (get-char-attribute char key)))
781 (insert (format "(%s . %S)%s"
785 (setq attributes (delq key attributes))
787 (dolist (feature '(ideographic-radical
790 (setq key (intern (format "%s@%s*sources" feature domain)))
791 (when (and (memq key attributes)
792 (setq value (get-char-attribute char key)))
793 (insert (format "(%s%s" key line-breaking))
795 (insert (format " %s" cell)))
797 (insert line-breaking)
798 (setq attributes (delq key attributes))
801 (when (and (memq 'ideographic-strokes attributes)
802 (setq value (get-char-attribute char 'ideographic-strokes)))
804 (insert (format "(ideographic-strokes . %S)%s"
807 (setq attributes (delq 'ideographic-strokes attributes))
809 (when (and (memq 'kangxi-radical attributes)
810 (setq value (get-char-attribute char 'kangxi-radical)))
811 (unless (eq value radical)
812 (insert (format "(kangxi-radical\t . %S)\t; %c%s"
814 (ideographic-radical value)
817 (setq radical value)))
818 (setq attributes (delq 'kangxi-radical attributes))
820 (when (and (memq 'kangxi-strokes attributes)
821 (setq value (get-char-attribute char 'kangxi-strokes)))
822 (unless (eq value strokes)
823 (insert (format "(kangxi-strokes\t . %S)%s"
827 (setq strokes value)))
828 (setq attributes (delq 'kangxi-strokes attributes))
830 (when (and (memq 'japanese-radical attributes)
831 (setq value (get-char-attribute char 'japanese-radical)))
832 (unless (eq value radical)
833 (insert (format "(japanese-radical\t . %S)\t; %c%s"
835 (ideographic-radical value)
838 (setq radical value)))
839 (setq attributes (delq 'japanese-radical attributes))
841 (when (and (memq 'japanese-strokes attributes)
842 (setq value (get-char-attribute char 'japanese-strokes)))
843 (unless (eq value strokes)
844 (insert (format "(japanese-strokes\t . %S)%s"
848 (setq strokes value)))
849 (setq attributes (delq 'japanese-strokes attributes))
851 (when (and (memq 'cns-radical attributes)
852 (setq value (get-char-attribute char 'cns-radical)))
853 (insert (format "(cns-radical\t . %S)\t; %c%s"
855 (ideographic-radical value)
857 (setq attributes (delq 'cns-radical attributes))
859 (when (and (memq 'cns-strokes attributes)
860 (setq value (get-char-attribute char 'cns-strokes)))
861 (unless (eq value strokes)
862 (insert (format "(cns-strokes\t . %S)%s"
866 (setq strokes value)))
867 (setq attributes (delq 'cns-strokes attributes))
869 (when (and (memq 'shinjigen-1-radical attributes)
870 (setq value (get-char-attribute char 'shinjigen-1-radical)))
871 (unless (eq value radical)
872 (insert (format "(shinjigen-1-radical . %S)\t; %c%s"
874 (ideographic-radical value)
877 (setq radical value)))
878 (setq attributes (delq 'shinjigen-1-radical attributes))
880 (when (and (memq 'ideographic- attributes)
881 (setq value (get-char-attribute char 'ideographic-)))
882 (insert "(ideographic- ")
883 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
886 (setq cell (car value))
888 (setq cell (decode-char '=ucs cell)))
889 (cond ((characterp cell)
893 (insert (format "%S" cell))
894 (char-db-insert-char-spec cell readable))
895 (setq separator lbs))
899 (if (consp (car cell))
900 (char-db-insert-char-spec cell readable)
901 (char-db-insert-char-reference cell readable))
902 (setq separator lbs))
906 (insert (prin1-to-string cell))
907 (setq separator " ")))
908 (setq value (cdr value)))
910 (insert line-breaking)
911 (setq attributes (delq 'ideographic- attributes)))
912 (when (and (memq 'total-strokes attributes)
913 (setq value (get-char-attribute char 'total-strokes)))
914 (insert (format "(total-strokes . %S)%s"
917 (setq attributes (delq 'total-strokes attributes))
919 (when (and (memq '->ideograph attributes)
920 (setq value (get-char-attribute char '->ideograph)))
921 (insert (format "(->ideograph\t%s)%s"
922 (mapconcat (lambda (code)
923 (cond ((symbolp code)
926 (format "#x%04X" code))
929 line-breaking code))))
932 (setq attributes (delq '->ideograph attributes))
934 ;; (when (and (memq '->decomposition attributes)
935 ;; (setq value (get-char-attribute char '->decomposition)))
936 ;; (insert (format "(->decomposition\t%s)%s"
937 ;; (mapconcat (lambda (code)
938 ;; (cond ((symbolp code)
939 ;; (symbol-name code))
940 ;; ((characterp code)
942 ;; (format "%S" code)
947 ;; (format "#x%04X" code))
949 ;; (format "%s%S" line-breaking code))))
952 ;; (setq attributes (delq '->decomposition attributes))
954 (if (equal (get-char-attribute char '->titlecase)
955 (get-char-attribute char '->uppercase))
956 (setq attributes (delq '->titlecase attributes)))
957 (when (and (memq '->mojikyo attributes)
958 (setq value (get-char-attribute char '->mojikyo)))
959 (insert (format "(->mojikyo\t\t. %06d)\t; %c%s"
960 value (decode-char 'mojikyo value)
962 (setq attributes (delq '->mojikyo attributes))
964 (when (and (memq 'hanyu-dazidian-vol attributes)
965 (setq value (get-char-attribute char 'hanyu-dazidian-vol)))
966 (insert (format "(hanyu-dazidian-vol . %d)%s"
967 value line-breaking))
968 (setq attributes (delq 'hanyu-dazidian-vol attributes))
970 (when (and (memq 'hanyu-dazidian-page attributes)
971 (setq value (get-char-attribute char 'hanyu-dazidian-page)))
972 (insert (format "(hanyu-dazidian-page . %d)%s"
973 value line-breaking))
974 (setq attributes (delq 'hanyu-dazidian-page attributes))
976 (when (and (memq 'hanyu-dazidian-char attributes)
977 (setq value (get-char-attribute char 'hanyu-dazidian-char)))
978 (insert (format "(hanyu-dazidian-char . %d)%s"
979 value line-breaking))
980 (setq attributes (delq 'hanyu-dazidian-char attributes))
983 (dolist (ignored '(composition
984 ->denotational <-subsumptive ->ucs-unified
985 ->ideographic-component-forms))
986 (setq attributes (delq ignored attributes))))
988 (setq name (car attributes))
989 (if (setq value (get-char-attribute char name))
990 (cond ((setq ret (find-charset name))
991 (setq name (charset-name ret))
992 (if (and (not (memq name dest-ccss))
994 (setq value (get-char-attribute char name))
995 (setq dest-ccss (cons name dest-ccss))))
996 (char-db-insert-ccs-feature name value line-breaking))
998 ((string-match "^=>ucs@" (symbol-name name))
999 (insert (format "(%-18s . #x%04X)\t; %c%s"
1000 name value (decode-char '=ucs value)
1003 ((eq name 'jisx0208-1978/4X)
1004 (insert (format "(%-18s . #x%04X)%s"
1008 ((and (not readable)
1009 (null (get-char-attribute
1011 (intern (format "%s*sources" name))))
1012 (not (string-match "\\*sources$" (symbol-name name)))
1013 (or (eq name '<-identical)
1014 (eq name '->superscript)
1015 (eq name '->subscript)
1016 (string-match "^->compat" (symbol-name name))
1017 (string-match "^->halfwidth" (symbol-name name))
1019 (string-match "^->fullwidth" (symbol-name name))
1022 (characterp (car value))
1024 (car value) '=ucs 'defined-only))))
1025 (string-match "^->simplified" (symbol-name name))
1026 (string-match "^->vulgar" (symbol-name name))
1027 (string-match "^->wrong" (symbol-name name))
1028 (string-match "^->same" (symbol-name name))
1029 (string-match "^->formed" (symbol-name name))
1030 (string-match "^->original" (symbol-name name))
1031 (string-match "^->ancient" (symbol-name name))
1032 (string-match "^->Oracle-Bones" (symbol-name name))
1035 ((or (eq name 'ideographic-structure)
1036 (eq name 'ideographic-combination)
1037 (eq name 'ideographic-)
1038 (eq name '=decomposition)
1039 (string-match "^=>decomposition" (symbol-name name))
1040 (string-match "^\\(->\\|<-\\)" (symbol-name name)))
1041 (char-db-insert-relation-feature char name value
1044 ((memq name '(ideograph=
1045 original-ideograph-of
1046 ancient-ideograph-of
1049 ;; simplified-ideograph-of
1050 ideographic-variants
1051 ;; ideographic-different-form-of
1053 (insert (format "(%-18s%s " name line-breaking))
1054 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1056 (while (consp value)
1057 (setq cell (car value))
1058 (if (and (consp cell)
1063 (char-db-insert-alist cell readable)
1064 (setq separator lbs))
1067 (insert (prin1-to-string cell))
1068 (setq separator " "))
1069 (setq value (cdr value)))
1071 (insert line-breaking))
1073 (insert (format "(%-18s " name))
1074 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1076 (while (consp value)
1077 (setq cell (car value))
1078 (if (and (consp cell)
1080 (setq ret (condition-case nil
1088 (setq key (car (car rest)))
1089 (if (find-charset key)
1090 (setq cal (cons key cal))
1091 (setq al (cons key al)))
1092 (setq rest (cdr rest)))
1095 (insert-char-attributes ret
1098 (setq separator lbs))
1099 (setq ret (prin1-to-string cell))
1101 (if (< (+ (current-column)
1108 (setq separator " "))
1109 (setq value (cdr value)))
1111 (insert line-breaking))
1113 (insert (format "(%-18s . %S)%s"
1117 (setq attributes (cdr attributes)))
1120 (defun insert-char-data (char &optional readable
1123 (narrow-to-region (point)(point))
1124 (insert "(define-char
1126 (insert-char-attributes char readable attributes)
1128 (goto-char (point-min))
1129 (while (re-search-forward "[ \t]+$" nil t)
1132 (goto-char (point-min))
1133 (while (re-search-forward "[ \t][ \t][ \t]*" nil t)
1134 (let ((column (current-column))
1135 (indent-tabs-mode t))
1136 (delete-region (match-beginning 0) (point))
1137 (indent-to column)))
1138 (goto-char (point-max))
1139 ;; (tabify (point-min)(point-max))
1142 (defun insert-char-data-with-variant (char &optional printable
1144 script excluded-script)
1145 (insert-char-data char printable)
1146 (let ((variants (char-variants char))
1149 (setq variants (sort variants #'<))
1150 (setq rest variants)
1151 (setq variants (cons char variants))
1153 (setq variant (car rest))
1154 (unless (get-char-attribute variant '<-subsumptive)
1155 (if (and (or (null script)
1156 (null (setq vs (get-char-attribute variant 'script)))
1158 (or (null excluded-script)
1159 (null (setq vs (get-char-attribute variant 'script)))
1160 (not (memq excluded-script vs))))
1161 (unless (and no-ucs-unified (get-char-attribute variant '=ucs))
1162 (insert-char-data variant printable)
1163 (if (setq ret (char-variants variant))
1165 (or (memq (car ret) variants)
1166 ;; (get-char-attribute (car ret) '<-subsumptive)
1167 (setq rest (nconc rest (list (car ret)))))
1168 (setq ret (cdr ret)))))))
1169 (setq rest (cdr rest)))))
1171 (defun insert-char-range-data (min max &optional script excluded-script)
1174 (while (<= code max)
1175 (setq char (decode-char '=ucs code))
1176 (if (encode-char char '=ucs 'defined-only)
1177 (insert-char-data-with-variant char nil 'no-ucs-unified
1178 script excluded-script))
1179 (setq code (1+ code)))))
1181 (defun write-char-range-data-to-file (min max file
1182 &optional script excluded-script)
1183 (let ((coding-system-for-write char-db-file-coding-system))
1185 (insert (format ";; -*- coding: %s -*-\n"
1186 char-db-file-coding-system))
1187 (insert-char-range-data min max script excluded-script)
1188 (write-region (point-min)(point-max) file))))
1190 (defvar what-character-original-window-configuration)
1193 (defun what-char-definition (char)
1194 (interactive (list (char-after)))
1195 (let ((buf (get-buffer-create "*Character Description*"))
1196 (the-buf (current-buffer))
1197 (win-conf (current-window-configuration)))
1199 (make-local-variable 'what-character-original-window-configuration)
1200 (setq what-character-original-window-configuration win-conf)
1201 (setq buffer-read-only nil)
1205 (insert-char-data-with-variant char 'printable)
1206 (unless (char-attribute-alist char)
1207 (insert (format ";; = %c\n"
1208 (let* ((rest (split-char char))
1212 (setq code (logior (lsh code 8)
1214 (decode-char ccs code)))))
1215 ;; (char-db-update-comment)
1216 (set-buffer-modified-p nil)
1217 (view-mode the-buf (lambda (buf)
1218 (set-window-configuration
1219 what-character-original-window-configuration)
1221 (goto-char (point-min)))
1223 (set-window-configuration
1224 what-character-original-window-configuration)
1225 (signal (car err) (cdr err)))))))
1227 (provide 'char-db-util)
1229 ;;; char-db-util.el ends here