1 ;;; char-db-util.el --- Character Database utility
3 ;; Copyright (C) 1998,1999,2000,2001,2002,2003 MORIOKA Tomohiko.
5 ;; Author: MORIOKA Tomohiko <tomo@kanji.zinbun.kyoto-u.ac.jp>
6 ;; Keywords: UTF-2000, ISO/IEC 10646, Unicode, UCS-4, MULE.
8 ;; This file is part of XEmacs UTF-2000.
10 ;; XEmacs UTF-2000 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 UTF-2000 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 UTF-2000; 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 (defvar char-db-feature-domains
73 '(ucs daikanwa cns gt))
75 (defvar char-db-ignored-attributes nil)
78 (defun char-ref= (cr1 cr2)
79 (cond ((char-ref-p cr1)
81 (char-spec= (plist-get cr1 :char)
82 (plist-get cr2 :char))
83 (char-spec= (plist-get cr1 :char) cr2)))
91 (defun char-spec= (cs1 cs2)
95 (eq cs1 (find-char cs2)))
97 (eq (find-char cs1) cs2)
98 (eq (find-char cs1) (find-char cs2)))))
100 (defun char-attribute-name< (ka kb)
106 ((= (charset-dimension ka)
107 (charset-dimension kb))
108 (cond ((= (charset-chars ka)(charset-chars kb))
109 (if (charset-iso-final-char ka)
111 ((>= (charset-iso-final-char ka) ?@)
112 (if (and (charset-iso-final-char kb)
113 (>= (charset-iso-final-char kb) ?@))
114 (< (charset-iso-final-char ka)
115 (charset-iso-final-char kb))
118 (if (charset-iso-final-char kb)
119 (if (>= (charset-iso-final-char kb) ?@)
121 (< (charset-iso-final-char ka)
122 (charset-iso-final-char kb)))
124 (if (charset-iso-final-char kb)
126 (< (charset-id ka)(charset-id kb)))))
127 ((<= (charset-chars ka)(charset-chars kb)))))
129 (< (charset-dimension ka)
130 (charset-dimension kb))
140 (string< (symbol-name ka)
146 (defvar char-db-coded-charset-priority-list
161 japanese-jisx0208-1978
202 (defun char-db-make-char-spec (char)
204 (cond ((characterp char)
205 (cond ((and (setq ret (encode-char char '=ucs 'defined-only))
206 (not (and (<= #xE000 ret)(<= ret #xF8FF))))
207 (setq char-spec (list (cons '=ucs ret)))
208 (cond ((setq ret (get-char-attribute char 'name))
209 (setq char-spec (cons (cons 'name ret) char-spec))
211 ((setq ret (get-char-attribute char 'name*))
212 (setq char-spec (cons (cons 'name* ret) char-spec))
217 (let ((rest char-db-coded-charset-priority-list)
220 (setq ccs (charset-name
221 (find-charset (car rest))))
223 (encode-char char ccs
225 (throw 'tag (cons ccs ret)))
226 (setq rest (cdr rest))))))
227 (setq char-spec (list ret))
228 (dolist (ccs (delq (car ret) (charset-list)))
229 (if (and (or (charset-iso-final-char ccs)
235 (setq ret (encode-char char ccs 'defined-only)))
236 (setq char-spec (cons (cons ccs ret) char-spec))))
238 (setq char-spec (split-char char)))
239 (cond ((setq ret (get-char-attribute char 'name))
240 (setq char-spec (cons (cons 'name ret) char-spec))
242 ((setq ret (get-char-attribute char 'name*))
243 (setq char-spec (cons (cons 'name* ret) char-spec))
250 (defun char-db-insert-char-spec (char &optional readable column)
252 (setq column (current-column)))
253 (let (char-spec ret al cal key temp-char)
254 (setq char-spec (char-db-make-char-spec char))
255 (unless (or (characterp char) ; char
257 (setq char (find-char char-spec))
259 ;; define temporary character
260 ;; Current implementation is dirty.
261 (setq temp-char (define-char (cons '(ideograph-daikanwa . 0)
263 (remove-char-attribute temp-char 'ideograph-daikanwa)
264 (setq char temp-char))
268 (setq key (car (car char-spec)))
269 (unless (memq key char-db-ignored-attributes)
270 (if (find-charset key)
271 (if (encode-char char key 'defined-only)
272 (setq cal (cons key cal)))
273 (setq al (cons key al))))
274 (setq char-spec (cdr char-spec)))
276 (setq char-spec (char-db-make-char-spec char))
278 (setq key (car (car char-spec)))
279 (unless (memq key char-db-ignored-attributes)
280 (if (find-charset key)
281 (setq cal (cons key cal))
282 (setq al (cons key al))))
283 (setq char-spec (cdr char-spec)))
286 (memq 'ideographic-structure al))
287 (push 'ideographic-structure al))
288 (insert-char-attributes char
292 ;; undefine temporary character
293 ;; Current implementation is dirty.
294 (setq char-spec (char-attribute-alist temp-char))
296 (remove-char-attribute temp-char (car (car char-spec)))
297 (setq char-spec (cdr char-spec))))))
299 (defun char-db-insert-alist (alist &optional readable column)
301 (setq column (current-column)))
303 (concat "\n" (make-string (1+ column) ?\ )))
306 lbs cell rest separator)
309 (setq name (car (car alist))
310 value (cdr (car alist)))
311 (cond ((eq name 'char)
313 (if (setq ret (condition-case nil
320 (setq key (car (car value)))
321 (if (find-charset key)
322 (setq cal (cons key cal))
323 (setq al (cons key al)))
324 (setq value (cdr value)))
325 (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
347 (setq key (car (car rest)))
348 (if (find-charset key)
349 (setq cal (cons key cal))
350 (setq al (cons key al)))
351 (setq rest (cdr rest)))
354 (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 (aref ideographic-radicals 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 insert-char-attributes (char &optional readable
439 attributes ccs-attributes
444 (if (consp attributes)
446 (dolist (name attributes)
447 (unless (memq name char-db-ignored-attributes)
450 (dolist (name (char-attribute-list))
451 (unless (memq name char-db-ignored-attributes)
452 (if (find-charset name)
456 #'char-attribute-name<))
458 (sort (if ccs-attributes
461 (dolist (name ccs-attributes)
462 (unless (memq name char-db-ignored-attributes)
467 (dolist (name (charset-list))
468 (unless (memq name char-db-ignored-attributes)
471 #'char-attribute-name<)))
473 (setq column (current-column)))
474 (let (name value has-long-ccs-name rest
477 (concat "\n" (make-string (1+ column) ?\ )))
478 lbs cell separator ret
482 (when (and (memq 'name attributes)
483 (setq value (get-char-attribute char 'name)))
485 (if (> (+ (current-column) (length value)) 48)
488 value line-breaking))
489 (setq attributes (delq 'name attributes))
491 (when (and (memq 'name* attributes)
492 (setq value (get-char-attribute char 'name*)))
494 (if (> (+ (current-column) (length value)) 48)
497 value line-breaking))
498 (setq attributes (delq 'name* attributes))
500 (when (and (memq 'script attributes)
501 (setq value (get-char-attribute char 'script)))
502 (insert (format "(script\t\t%s)%s"
503 (mapconcat (function prin1-to-string)
506 (setq attributes (delq 'script attributes))
508 (dolist (name '(=>ucs =>ucs*))
509 (when (and (memq name attributes)
510 (setq value (get-char-attribute char name)))
511 (insert (format "(%-18s . #x%04X)\t; %c%s"
512 name value (decode-char '=ucs value)
514 (setq attributes (delq name attributes))))
515 (dolist (name '(=>ucs@gb =>ucs@cns =>ucs@jis =>ucs@ks =>ucs@big5))
516 (when (and (memq name attributes)
517 (setq value (get-char-attribute char name)))
518 (insert (format "(%-18s . #x%04X)\t; %c%s"
523 (symbol-name name) 2)))
526 (setq attributes (delq name attributes))
528 (dolist (name '(=>ucs-gb =>ucs-cns =>ucs-jis =>ucs-ks =>ucs-big5))
529 (when (and (memq name attributes)
530 (setq value (get-char-attribute char name)))
531 (insert (format "(%-18s . #x%04X)\t; %c%s"
534 (substring (symbol-name name) 6)))
539 (symbol-name name) 6)))
542 (setq attributes (delq name attributes))))
543 (when (and (memq '->ucs attributes)
544 (setq value (get-char-attribute char '->ucs)))
545 (insert (format (if char-db-convert-obsolete-format
546 "(=>ucs\t\t. #x%04X)\t; %c%s"
547 "(->ucs\t\t. #x%04X)\t; %c%s")
548 value (decode-char '=ucs value)
550 (setq attributes (delq '->ucs attributes))
552 (when (and (memq 'general-category attributes)
553 (setq value (get-char-attribute char 'general-category)))
555 "(general-category\t%s) ; %s%s"
556 (mapconcat (lambda (cell)
559 (cond ((rassoc value unidata-normative-category-alist)
560 "Normative Category")
561 ((rassoc value unidata-informative-category-alist)
562 "Informative Category")
566 (setq attributes (delq 'general-category attributes))
568 (when (and (memq 'bidi-category attributes)
569 (setq value (get-char-attribute char 'bidi-category)))
570 (insert (format "(bidi-category\t. %S)%s"
573 (setq attributes (delq 'bidi-category attributes))
575 (unless (or (not (memq 'mirrored attributes))
576 (eq (setq value (get-char-attribute char 'mirrored 'empty))
578 (insert (format "(mirrored\t\t. %S)%s"
581 (setq attributes (delq 'mirrored attributes))
584 ((and (memq 'decimal-digit-value attributes)
585 (setq value (get-char-attribute char 'decimal-digit-value)))
586 (insert (format "(decimal-digit-value . %S)%s"
589 (setq attributes (delq 'decimal-digit-value attributes))
590 (when (and (memq 'digit-value attributes)
591 (setq value (get-char-attribute char 'digit-value)))
592 (insert (format "(digit-value\t . %S)%s"
595 (setq attributes (delq 'digit-value attributes))
597 (when (and (memq 'numeric-value attributes)
598 (setq value (get-char-attribute char 'numeric-value)))
599 (insert (format "(numeric-value\t . %S)%s"
602 (setq attributes (delq 'numeric-value attributes))
606 (when (and (memq 'digit-value attributes)
607 (setq value (get-char-attribute char 'digit-value)))
608 (insert (format "(digit-value\t. %S)%s"
611 (setq attributes (delq 'digit-value attributes))
613 (when (and (memq 'numeric-value attributes)
614 (setq value (get-char-attribute char 'numeric-value)))
615 (insert (format "(numeric-value\t. %S)%s"
618 (setq attributes (delq 'numeric-value attributes))
620 (when (and (memq 'iso-10646-comment attributes)
621 (setq value (get-char-attribute char 'iso-10646-comment)))
622 (insert (format "(iso-10646-comment\t. %S)%s"
625 (setq attributes (delq 'iso-10646-comment attributes))
627 (when (and (memq 'morohashi-daikanwa attributes)
628 (setq value (get-char-attribute char 'morohashi-daikanwa)))
629 (insert (format "(morohashi-daikanwa\t%s)%s"
630 (mapconcat (function prin1-to-string) value " ")
632 (setq attributes (delq 'morohashi-daikanwa attributes))
636 (when (and (memq 'ideographic-radical attributes)
637 (setq value (get-char-attribute char 'ideographic-radical)))
639 (insert (format "(ideographic-radical . %S)\t; %c%s"
641 (aref ideographic-radicals radical)
643 (setq attributes (delq 'ideographic-radical attributes))
646 (dolist (domain char-db-feature-domains)
647 (setq key (intern (format "%s@%s" 'ideographic-radical domain)))
648 (when (and (memq key attributes)
649 (setq value (get-char-attribute char key)))
651 (insert (format "(%s . %S)\t; %c%s"
654 (aref ideographic-radicals radical)
656 (setq attributes (delq key attributes))
658 (setq key (intern (format "%s@%s" 'ideographic-strokes domain)))
659 (when (and (memq key attributes)
660 (setq value (get-char-attribute char key)))
662 (insert (format "(%s . %S)%s"
666 (setq attributes (delq key attributes))
668 (setq key (intern (format "%s@%s" 'total-strokes domain)))
669 (when (and (memq key attributes)
670 (setq value (get-char-attribute char key)))
671 (insert (format "(%s . %S)%s"
675 (setq attributes (delq key attributes))
677 (dolist (feature '(ideographic-radical
680 (setq key (intern (format "%s@%s*sources" feature domain)))
681 (when (and (memq key attributes)
682 (setq value (get-char-attribute char key)))
683 (insert (format "(%s%s" key line-breaking))
685 (insert (format " %s" cell)))
687 (insert line-breaking)
688 (setq attributes (delq key attributes))
691 (when (and (memq 'ideographic-strokes attributes)
692 (setq value (get-char-attribute char 'ideographic-strokes)))
694 (insert (format "(ideographic-strokes . %S)%s"
697 (setq attributes (delq 'ideographic-strokes attributes))
699 (when (and (memq 'kangxi-radical attributes)
700 (setq value (get-char-attribute char 'kangxi-radical)))
701 (unless (eq value radical)
702 (insert (format "(kangxi-radical\t . %S)\t; %c%s"
704 (aref ideographic-radicals value)
707 (setq radical value)))
708 (setq attributes (delq 'kangxi-radical attributes))
710 (when (and (memq 'kangxi-strokes attributes)
711 (setq value (get-char-attribute char 'kangxi-strokes)))
712 (unless (eq value strokes)
713 (insert (format "(kangxi-strokes\t . %S)%s"
717 (setq strokes value)))
718 (setq attributes (delq 'kangxi-strokes attributes))
720 (when (and (memq 'japanese-radical attributes)
721 (setq value (get-char-attribute char 'japanese-radical)))
722 (unless (eq value radical)
723 (insert (format "(japanese-radical\t . %S)\t; %c%s"
725 (aref ideographic-radicals value)
728 (setq radical value)))
729 (setq attributes (delq 'japanese-radical attributes))
731 (when (and (memq 'japanese-strokes attributes)
732 (setq value (get-char-attribute char 'japanese-strokes)))
733 (unless (eq value strokes)
734 (insert (format "(japanese-strokes\t . %S)%s"
738 (setq strokes value)))
739 (setq attributes (delq 'japanese-strokes attributes))
741 (when (and (memq 'cns-radical attributes)
742 (setq value (get-char-attribute char 'cns-radical)))
743 (insert (format "(cns-radical\t . %S)\t; %c%s"
745 (aref ideographic-radicals value)
747 (setq attributes (delq 'cns-radical attributes))
749 (when (and (memq 'cns-strokes attributes)
750 (setq value (get-char-attribute char 'cns-strokes)))
751 (unless (eq value strokes)
752 (insert (format "(cns-strokes\t . %S)%s"
756 (setq strokes value)))
757 (setq attributes (delq 'cns-strokes attributes))
759 (when (and (memq 'shinjigen-1-radical attributes)
760 (setq value (get-char-attribute char 'shinjigen-1-radical)))
761 (unless (eq value radical)
762 (insert (format "(shinjigen-1-radical . %S)\t; %c%s"
764 (aref ideographic-radicals value)
767 (setq radical value)))
768 (setq attributes (delq 'shinjigen-1-radical attributes))
770 (when (and (memq 'ideographic- attributes)
771 (setq value (get-char-attribute char 'ideographic-)))
772 (insert "(ideographic- ")
773 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
776 (setq cell (car value))
778 (setq cell (decode-char '=ucs cell)))
779 (cond ((characterp cell)
783 (insert (format "%S" cell))
784 (char-db-insert-char-spec cell readable))
785 (setq separator lbs))
789 (if (consp (car cell))
790 (char-db-insert-char-spec cell readable)
791 (char-db-insert-char-reference cell readable))
792 (setq separator lbs))
796 (insert (prin1-to-string cell))
797 (setq separator " ")))
798 (setq value (cdr value)))
800 (insert line-breaking)
801 (setq attributes (delq 'ideographic- attributes)))
802 (when (and (memq 'total-strokes attributes)
803 (setq value (get-char-attribute char 'total-strokes)))
804 (insert (format "(total-strokes . %S)%s"
807 (setq attributes (delq 'total-strokes attributes))
809 (when (and (memq '->ideograph attributes)
810 (setq value (get-char-attribute char '->ideograph)))
811 (insert (format "(->ideograph\t%s)%s"
812 (mapconcat (lambda (code)
813 (cond ((symbolp code)
816 (format "#x%04X" code))
819 line-breaking code))))
822 (setq attributes (delq '->ideograph attributes))
824 (when (and (memq '->decomposition attributes)
825 (setq value (get-char-attribute char '->decomposition)))
826 (insert (format "(->decomposition\t%s)%s"
827 (mapconcat (lambda (code)
828 (cond ((symbolp code)
837 (format "#x%04X" code))
839 (format "%s%S" line-breaking code))))
842 (setq attributes (delq '->decomposition attributes))
844 (if (equal (get-char-attribute char '->titlecase)
845 (get-char-attribute char '->uppercase))
846 (setq attributes (delq '->titlecase attributes)))
847 (when (and (memq '->mojikyo attributes)
848 (setq value (get-char-attribute char '->mojikyo)))
849 (insert (format "(->mojikyo\t\t. %06d)\t; %c%s"
850 value (decode-char 'mojikyo value)
852 (setq attributes (delq '->mojikyo attributes))
854 (when (and (memq 'hanyu-dazidian-vol attributes)
855 (setq value (get-char-attribute char 'hanyu-dazidian-vol)))
856 (insert (format "(hanyu-dazidian-vol . %d)%s"
857 value line-breaking))
858 (setq attributes (delq 'hanyu-dazidian-vol attributes))
860 (when (and (memq 'hanyu-dazidian-page attributes)
861 (setq value (get-char-attribute char 'hanyu-dazidian-page)))
862 (insert (format "(hanyu-dazidian-page . %d)%s"
863 value line-breaking))
864 (setq attributes (delq 'hanyu-dazidian-page attributes))
866 (when (and (memq 'hanyu-dazidian-char attributes)
867 (setq value (get-char-attribute char 'hanyu-dazidian-char)))
868 (insert (format "(hanyu-dazidian-char . %d)%s"
869 value line-breaking))
870 (setq attributes (delq 'hanyu-dazidian-char attributes))
872 (setq rest ccs-attributes)
875 (setq value (get-char-attribute char (car rest)))
877 (if (>= (length (symbol-name (car rest))) 19)
879 (setq has-long-ccs-name t)
883 (setq rest (cdr rest)))
885 (setq name (car attributes))
886 (if (setq value (get-char-attribute char name))
887 (cond ((string-match "^=>ucs@" (symbol-name name))
888 (insert (format "(%-18s . #x%04X)\t; %c%s"
889 name value (decode-char '=ucs value)
892 ((eq name 'jisx0208-1978/4X)
893 (insert (format "(%-18s . #x%04X)%s"
896 ((or (eq name 'ideographic-structure)
897 (eq name 'ideographic-)
898 (string-match "^\\(->\\|<-\\)" (symbol-name name)))
899 (insert (format "(%-18s%s " name line-breaking))
900 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
903 (setq cell (car value))
905 (setq cell (decode-char '=ucs cell)))
906 (cond ((characterp cell)
910 (insert (format "%S" cell))
911 (char-db-insert-char-spec cell readable))
912 (setq separator lbs))
916 (if (consp (car cell))
917 (char-db-insert-char-spec cell readable)
918 (char-db-insert-char-reference cell readable))
919 (setq separator lbs))
923 (insert (prin1-to-string cell))
924 (setq separator " ")))
925 (setq value (cdr value)))
927 (insert line-breaking))
928 ((memq name '(ideograph=
929 original-ideograph-of
933 simplified-ideograph-of
935 ideographic-different-form-of))
936 (insert (format "(%-18s%s " name line-breaking))
937 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
940 (setq cell (car value))
941 (if (and (consp cell)
946 (char-db-insert-alist cell readable)
947 (setq separator lbs))
950 (insert (prin1-to-string cell))
951 (setq separator " "))
952 (setq value (cdr value)))
954 (insert line-breaking))
955 ;; ((string-match "^->" (symbol-name name))
957 ;; (format "(%-18s %s)%s"
959 ;; (mapconcat (lambda (code)
960 ;; (cond ((symbolp code)
961 ;; (symbol-name code))
963 ;; (format "#x%04X" code))
966 ;; line-breaking code))))
970 (insert (format "(%-18s " name))
971 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
974 (setq cell (car value))
975 (if (and (consp cell)
977 (setq ret (condition-case nil
985 (setq key (car (car rest)))
986 (if (find-charset key)
987 (setq cal (cons key cal))
988 (setq al (cons key al)))
989 (setq rest (cdr rest)))
992 (insert-char-attributes ret
995 (setq separator lbs))
998 (insert (prin1-to-string cell))
999 (setq separator " "))
1000 (setq value (cdr value)))
1002 (insert line-breaking))
1004 (insert (format "(%-18s . %S)%s"
1008 (setq attributes (cdr attributes)))
1009 (while ccs-attributes
1010 (setq name (charset-name (car ccs-attributes)))
1011 (if (and (not (memq name dest-ccss))
1013 (setq value (get-char-attribute char name))
1014 (setq dest-ccss (cons name dest-ccss))))
1017 (cond ((memq name '(=daikanwa
1018 =daikanwa-rev1 =daikanwa-rev2
1020 (if has-long-ccs-name
1021 "(%-26s . %05d)\t; %c%s"
1022 "(%-18s . %05d)\t; %c%s"))
1024 (if has-long-ccs-name
1025 "(%-26s . %06d)\t; %c%s"
1026 "(%-18s . %06d)\t; %c%s"))
1027 ((>= (charset-dimension name) 2)
1028 (if has-long-ccs-name
1029 "(%-26s . #x%04X)\t; %c%s"
1030 "(%-18s . #x%04X)\t; %c%s"))
1032 (if has-long-ccs-name
1033 "(%-26s . #x%02X)\t; %c%s"
1034 "(%-18s . #x%02X)\t; %c%s")))
1036 (if (= (charset-iso-graphic-plane name) 1)
1038 (cond ((= (charset-dimension name) 1)
1040 ((= (charset-dimension name) 2)
1042 ((= (charset-dimension name) 3)
1046 (char-db-decode-isolated-char name value)
1048 (setq ccs-attributes (cdr ccs-attributes)))
1051 (defun insert-char-data (char &optional readable
1052 attributes ccs-attributes)
1054 (narrow-to-region (point)(point))
1055 (insert "(define-char
1057 (insert-char-attributes char readable
1058 attributes ccs-attributes)
1060 (goto-char (point-min))
1061 (while (re-search-forward "[ \t]+$" nil t)
1064 (goto-char (point-min))
1065 (while (re-search-forward "[ \t][ \t][ \t]*" nil t)
1066 (let ((column (current-column))
1067 (indent-tabs-mode t))
1068 (delete-region (match-beginning 0) (point))
1069 (indent-to column)))
1070 (goto-char (point-max))
1071 ;; (tabify (point-min)(point-max))
1074 (defun insert-char-data-with-variant (char &optional printable
1076 script excluded-script)
1077 (insert-char-data char printable)
1078 (let ((variants (or (char-variants char)
1079 (let ((ucs (get-char-attribute char '->ucs)))
1081 (delete char (char-variants (int-char ucs)))))))
1083 (setq variants (sort variants #'<))
1085 (setq variant (car variants))
1086 (if (and (or (null script)
1087 (null (setq vs (get-char-attribute variant 'script)))
1089 (or (null excluded-script)
1090 (null (setq vs (get-char-attribute variant 'script)))
1091 (not (memq excluded-script vs))))
1092 (or (and no-ucs-unified (get-char-attribute variant '=ucs))
1093 (insert-char-data variant printable)))
1094 (setq variants (cdr variants))
1097 (defun insert-char-range-data (min max &optional script excluded-script)
1100 (while (<= code max)
1101 (setq char (decode-char '=ucs code))
1102 (if (encode-char char '=ucs 'defined-only)
1103 (insert-char-data-with-variant char nil 'no-ucs-unified
1104 script excluded-script))
1105 (setq code (1+ code)))))
1107 (defun write-char-range-data-to-file (min max file
1108 &optional script excluded-script)
1109 (let ((coding-system-for-write 'utf-8))
1111 (insert-char-range-data min max script excluded-script)
1112 (write-region (point-min)(point-max) file))))
1114 (defvar what-character-original-window-configuration)
1117 (defun what-char-definition (char)
1118 (interactive (list (char-after)))
1119 (let ((buf (get-buffer-create "*Character Description*"))
1120 (the-buf (current-buffer))
1121 (win-conf (current-window-configuration)))
1123 (make-local-variable 'what-character-original-window-configuration)
1124 (setq what-character-original-window-configuration win-conf)
1125 (setq buffer-read-only nil)
1129 (insert-char-data-with-variant char 'printable)
1130 (unless (char-attribute-alist char)
1131 (insert (format ";; = %c\n"
1132 (let* ((rest (split-char char))
1136 (setq code (logior (lsh code 8)
1138 (decode-char ccs code)))))
1139 ;; (char-db-update-comment)
1140 (set-buffer-modified-p nil)
1141 (view-mode the-buf (lambda (buf)
1142 (set-window-configuration
1143 what-character-original-window-configuration)
1145 (goto-char (point-min)))
1147 (set-window-configuration
1148 what-character-original-window-configuration)
1149 (signal (car err) (cdr err)))))))
1151 (provide 'char-db-util)
1153 ;;; char-db-util.el ends here