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-ignored-attributes nil)
75 (defun char-ref= (cr1 cr2)
76 (cond ((char-ref-p cr1)
78 (char-spec= (plist-get cr1 :char)
79 (plist-get cr2 :char))
80 (char-spec= (plist-get cr1 :char) cr2)))
88 (defun char-spec= (cs1 cs2)
92 (eq cs1 (find-char cs2)))
94 (eq (find-char cs1) cs2)
95 (eq (find-char cs1) (find-char cs2)))))
97 (defun char-attribute-name< (ka kb)
103 ((= (charset-dimension ka)
104 (charset-dimension kb))
105 (cond ((= (charset-chars ka)(charset-chars kb))
106 (if (charset-iso-final-char ka)
108 ((>= (charset-iso-final-char ka) ?@)
109 (if (and (charset-iso-final-char kb)
110 (>= (charset-iso-final-char kb) ?@))
111 (< (charset-iso-final-char ka)
112 (charset-iso-final-char kb))
115 (if (charset-iso-final-char kb)
116 (if (>= (charset-iso-final-char kb) ?@)
118 (< (charset-iso-final-char ka)
119 (charset-iso-final-char kb)))
121 (if (charset-iso-final-char kb)
123 (< (charset-id ka)(charset-id kb)))))
124 ((<= (charset-chars ka)(charset-chars kb)))))
126 (< (charset-dimension ka)
127 (charset-dimension kb))
137 (string< (symbol-name ka)
143 (defvar char-db-coded-charset-priority-list
158 japanese-jisx0208-1978
200 (defun char-db-make-char-spec (char)
202 (cond ((characterp char)
203 (cond ((and (setq ret (encode-char char '=ucs 'defined-only))
204 (not (and (<= #xE000 ret)(<= ret #xF8FF))))
205 (setq char-spec (list (cons '=ucs ret)))
206 (cond ((setq ret (get-char-attribute char 'name))
207 (setq char-spec (cons (cons 'name ret) char-spec))
209 ((setq ret (get-char-attribute char 'name*))
210 (setq char-spec (cons (cons 'name* ret) char-spec))
215 (let ((rest char-db-coded-charset-priority-list))
218 (get-char-attribute char (car rest)))
219 (throw 'tag (cons (car rest) ret)))
220 (setq rest (cdr rest))))))
221 (setq char-spec (list ret))
222 (dolist (ccs (delq (car ret) (charset-list)))
223 (if (and (or (charset-iso-final-char ccs)
229 (setq ret (get-char-attribute char ccs)))
230 (setq char-spec (cons (cons ccs ret) char-spec))))
232 (setq char-spec (split-char char)))
233 (cond ((setq ret (get-char-attribute char 'name))
234 (setq char-spec (cons (cons 'name ret) char-spec))
236 ((setq ret (get-char-attribute char 'name*))
237 (setq char-spec (cons (cons 'name* ret) char-spec))
244 (defun char-db-insert-char-spec (char &optional readable column)
246 (setq column (current-column)))
247 (let (char-spec ret al cal key temp-char)
248 (setq char-spec (char-db-make-char-spec char))
249 (unless (or (characterp char) ; char
251 (setq char (find-char char-spec))
253 ;; define temporary character
254 ;; Current implementation is dirty.
255 (setq temp-char (define-char (cons '(ideograph-daikanwa . 0)
257 (remove-char-attribute temp-char 'ideograph-daikanwa)
258 (setq char temp-char))
262 (setq key (car (car char-spec)))
263 (unless (memq key char-db-ignored-attributes)
264 (if (find-charset key)
265 (if (get-char-attribute char key)
266 (setq cal (cons key cal)))
267 (setq al (cons key al))))
268 (setq char-spec (cdr char-spec)))
270 (setq char-spec (char-db-make-char-spec char))
272 (setq key (car (car char-spec)))
273 (unless (memq key char-db-ignored-attributes)
274 (if (find-charset key)
275 (setq cal (cons key cal))
276 (setq al (cons key al))))
277 (setq char-spec (cdr char-spec)))
280 (memq 'ideographic-structure al))
281 (push 'ideographic-structure al))
282 (insert-char-attributes char
286 ;; undefine temporary character
287 ;; Current implementation is dirty.
288 (setq char-spec (char-attribute-alist temp-char))
290 (remove-char-attribute temp-char (car (car char-spec)))
291 (setq char-spec (cdr char-spec))))))
293 (defun char-db-insert-alist (alist &optional readable column)
295 (setq column (current-column)))
297 (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
314 (setq key (car (car value)))
315 (if (find-charset key)
316 (setq cal (cons key cal))
317 (setq al (cons key al)))
318 (setq value (cdr value)))
319 (insert-char-attributes ret
322 (insert (prin1-to-string value)))
324 (insert line-breaking))
326 (insert (format "(%-18s " name))
327 (setq lbs (concat "\n" (make-string (current-column) ?\ )))
329 (setq cell (car value))
330 (if (and (consp cell)
332 (setq ret (condition-case nil
341 (setq key (car (car rest)))
342 (if (find-charset key)
343 (setq cal (cons key cal))
344 (setq al (cons key al)))
345 (setq rest (cdr rest)))
348 (insert-char-attributes ret
351 (setq separator lbs))
354 (insert (prin1-to-string cell))
355 (setq separator " "))
356 (setq value (cdr value)))
358 (insert line-breaking))
360 (insert (format "(%-18s . %S)%s"
363 (setq alist (cdr alist))))
366 (defun char-db-insert-char-reference (plist &optional readable column)
368 (setq column (current-column)))
370 (concat "\n" (make-string (1+ column) ?\ )))
375 (setq name (pop plist))
376 (setq value (pop plist))
377 (cond ((eq name :char)
380 (cond ((numberp value)
381 (setq value (decode-char '=ucs value)))
383 ;; (setq value (or (find-char value)
386 (char-db-insert-char-spec value readable)
387 (insert line-breaking)
390 (insert (format "%s%s\t%d ; %c%s"
393 (aref ideographic-radicals value)
397 (insert (format "%s%s\t%S" separator name value))
398 (setq separator line-breaking)))
402 (defun char-db-decode-isolated-char (ccs code-point)
405 (cond ((eq ccs 'arabic-iso8859-6)
406 (decode-char ccs code-point))
407 ((and (memq ccs '(=gt-pj-1
418 (setq ret (decode-char ccs code-point))
419 (setq ret (get-char-attribute ret '=gt)))
420 (decode-builtin-char '=gt ret))
422 (decode-builtin-char ccs code-point))))
423 (cond ((and (<= 0 (char-int ret))
424 (<= (char-int ret) #x1F))
425 (decode-char '=ucs (+ #x2400 (char-int ret))))
426 ((= (char-int ret) #x7F)
430 (defvar char-db-convert-obsolete-format t)
432 (defun insert-char-attributes (char &optional readable
433 attributes ccs-attributes
438 (if (consp attributes)
440 (dolist (name attributes)
441 (unless (memq name char-db-ignored-attributes)
444 (dolist (name (char-attribute-list))
445 (unless (memq name char-db-ignored-attributes)
446 (if (find-charset name)
450 #'char-attribute-name<))
452 (sort (if ccs-attributes
455 (dolist (name ccs-attributes)
456 (unless (memq name char-db-ignored-attributes)
461 (dolist (name (charset-list))
462 (unless (memq name char-db-ignored-attributes)
465 #'char-attribute-name<)))
467 (setq column (current-column)))
468 (let (name value has-long-ccs-name rest
471 (concat "\n" (make-string (1+ column) ?\ )))
472 lbs cell separator ret
475 (when (and (memq 'name attributes)
476 (setq value (get-char-attribute char 'name)))
478 (if (> (+ (current-column) (length value)) 48)
481 value line-breaking))
482 (setq attributes (delq 'name attributes))
484 (when (and (memq 'name* attributes)
485 (setq value (get-char-attribute char 'name*)))
487 (if (> (+ (current-column) (length value)) 48)
490 value line-breaking))
491 (setq attributes (delq 'name* attributes))
493 (when (and (memq 'script attributes)
494 (setq value (get-char-attribute char 'script)))
495 (insert (format "(script\t\t%s)%s"
496 (mapconcat (function prin1-to-string)
499 (setq attributes (delq 'script attributes))
501 (dolist (name '(=>ucs =>ucs*))
502 (when (and (memq name attributes)
503 (setq value (get-char-attribute char name)))
504 (insert (format "(%-18s . #x%04X)\t; %c%s"
505 name value (decode-char '=ucs value)
507 (setq attributes (delq name attributes))))
508 ;; (when (and (memq '=>ucs* attributes)
509 ;; (setq value (get-char-attribute char '=>ucs*)))
510 ;; (insert (format "(=>ucs*\t\t. #x%04X)\t; %c%s"
511 ;; value (decode-char '=ucs value)
513 ;; (setq attributes (delq '=>ucs* attributes))
515 (dolist (name '(=>ucs@gb =>ucs@cns))
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 (when (and (memq '=>ucs-gb attributes)
529 (setq value (get-char-attribute char '=>ucs-gb)))
530 (insert (format "(=>ucs@gb\t\t. #x%04X)\t; %c%s"
531 value (decode-char '=ucs@gb value)
533 (setq attributes (delq '=>ucs-gb attributes))
535 (when (and (memq '=>ucs-cns attributes)
536 (setq value (get-char-attribute char '=>ucs-cns)))
537 (insert (format "(=>ucs@cns\t\t. #x%04X)\t; %c%s"
538 value (decode-char '=ucs@cns value)
540 (setq attributes (delq '=>ucs-cns attributes))
542 (when (and (memq '=>ucs-big5 attributes)
543 (setq value (get-char-attribute char '=>ucs-big5)))
544 (insert (format "(=>ucs-big5\t\t. #x%04X)\t; %c%s"
545 value (decode-char 'ucs-big5 value)
547 (setq attributes (delq '=>ucs-big5 attributes))
549 (when (and (memq '=>ucs-jis attributes)
550 (setq value (get-char-attribute char '=>ucs-jis)))
551 (insert (format "(=>ucs-jis\t\t. #x%04X)\t; %c%s"
552 value (decode-char 'ucs-jis value)
554 (setq attributes (delq '=>ucs-jis attributes))
556 (when (and (memq '=>ucs-ks attributes)
557 (setq value (get-char-attribute char '=>ucs-ks)))
558 (insert (format "(=>ucs-ks\t\t. #x%04X)\t; %c%s"
559 value (decode-char 'ucs-ks value)
561 (setq attributes (delq '=>ucs-ks attributes))
563 (when (and (memq '->ucs attributes)
564 (setq value (get-char-attribute char '->ucs)))
565 (insert (format (if char-db-convert-obsolete-format
566 "(=>ucs\t\t. #x%04X)\t; %c%s"
567 "(->ucs\t\t. #x%04X)\t; %c%s")
568 value (decode-char '=ucs value)
570 (setq attributes (delq '->ucs attributes))
572 (when (and (memq 'general-category attributes)
573 (setq value (get-char-attribute char 'general-category)))
575 "(general-category\t%s) ; %s%s"
576 (mapconcat (lambda (cell)
579 (cond ((rassoc value unidata-normative-category-alist)
580 "Normative Category")
581 ((rassoc value unidata-informative-category-alist)
582 "Informative Category")
586 (setq attributes (delq 'general-category attributes))
588 (when (and (memq 'bidi-category attributes)
589 (setq value (get-char-attribute char 'bidi-category)))
590 (insert (format "(bidi-category\t. %S)%s"
593 (setq attributes (delq 'bidi-category attributes))
595 (unless (or (not (memq 'mirrored attributes))
596 (eq (setq value (get-char-attribute char 'mirrored 'empty))
598 (insert (format "(mirrored\t\t. %S)%s"
601 (setq attributes (delq 'mirrored attributes))
604 ((and (memq 'decimal-digit-value attributes)
605 (setq value (get-char-attribute char 'decimal-digit-value)))
606 (insert (format "(decimal-digit-value . %S)%s"
609 (setq attributes (delq 'decimal-digit-value attributes))
610 (when (and (memq 'digit-value attributes)
611 (setq value (get-char-attribute char 'digit-value)))
612 (insert (format "(digit-value\t . %S)%s"
615 (setq attributes (delq 'digit-value attributes))
617 (when (and (memq 'numeric-value attributes)
618 (setq value (get-char-attribute char 'numeric-value)))
619 (insert (format "(numeric-value\t . %S)%s"
622 (setq attributes (delq 'numeric-value attributes))
626 (when (and (memq 'digit-value attributes)
627 (setq value (get-char-attribute char 'digit-value)))
628 (insert (format "(digit-value\t. %S)%s"
631 (setq attributes (delq 'digit-value attributes))
633 (when (and (memq 'numeric-value attributes)
634 (setq value (get-char-attribute char 'numeric-value)))
635 (insert (format "(numeric-value\t. %S)%s"
638 (setq attributes (delq 'numeric-value attributes))
640 (when (and (memq 'iso-10646-comment attributes)
641 (setq value (get-char-attribute char 'iso-10646-comment)))
642 (insert (format "(iso-10646-comment\t. %S)%s"
645 (setq attributes (delq 'iso-10646-comment attributes))
647 (when (and (memq 'morohashi-daikanwa attributes)
648 (setq value (get-char-attribute char 'morohashi-daikanwa)))
649 (insert (format "(morohashi-daikanwa\t%s)%s"
650 (mapconcat (function prin1-to-string) value " ")
652 (setq attributes (delq 'morohashi-daikanwa attributes))
656 (when (and (memq 'ideographic-radical attributes)
657 (setq value (get-char-attribute char 'ideographic-radical)))
659 (insert (format "(ideographic-radical . %S)\t; %c%s"
661 (aref ideographic-radicals radical)
663 (setq attributes (delq 'ideographic-radical attributes))
665 (when (and (memq 'ideographic-strokes attributes)
666 (setq value (get-char-attribute char 'ideographic-strokes)))
668 (insert (format "(ideographic-strokes . %S)%s"
671 (setq attributes (delq 'ideographic-strokes attributes))
673 (when (and (memq 'kangxi-radical attributes)
674 (setq value (get-char-attribute char 'kangxi-radical)))
675 (unless (eq value radical)
676 (insert (format "(kangxi-radical\t . %S)\t; %c%s"
678 (aref ideographic-radicals value)
681 (setq radical value)))
682 (setq attributes (delq 'kangxi-radical attributes))
684 (when (and (memq 'kangxi-strokes attributes)
685 (setq value (get-char-attribute char 'kangxi-strokes)))
686 (unless (eq value strokes)
687 (insert (format "(kangxi-strokes\t . %S)%s"
691 (setq strokes value)))
692 (setq attributes (delq 'kangxi-strokes attributes))
694 (when (and (memq 'japanese-radical attributes)
695 (setq value (get-char-attribute char 'japanese-radical)))
696 (unless (eq value radical)
697 (insert (format "(japanese-radical\t . %S)\t; %c%s"
699 (aref ideographic-radicals value)
702 (setq radical value)))
703 (setq attributes (delq 'japanese-radical attributes))
705 (when (and (memq 'japanese-strokes attributes)
706 (setq value (get-char-attribute char 'japanese-strokes)))
707 (unless (eq value strokes)
708 (insert (format "(japanese-strokes\t . %S)%s"
712 (setq strokes value)))
713 (setq attributes (delq 'japanese-strokes attributes))
715 (when (and (memq 'cns-radical attributes)
716 (setq value (get-char-attribute char 'cns-radical)))
717 (insert (format "(cns-radical\t . %S)\t; %c%s"
719 (aref ideographic-radicals value)
721 (setq attributes (delq 'cns-radical attributes))
723 (when (and (memq 'cns-strokes attributes)
724 (setq value (get-char-attribute char 'cns-strokes)))
725 (unless (eq value strokes)
726 (insert (format "(cns-strokes\t . %S)%s"
730 (setq strokes value)))
731 (setq attributes (delq 'cns-strokes attributes))
733 (when (and (memq 'shinjigen-1-radical attributes)
734 (setq value (get-char-attribute char 'shinjigen-1-radical)))
735 (unless (eq value radical)
736 (insert (format "(shinjigen-1-radical . %S)\t; %c%s"
738 (aref ideographic-radicals value)
741 (setq radical value)))
742 (setq attributes (delq 'shinjigen-1-radical attributes))
744 (when (and (memq 'ideographic- attributes)
745 (setq value (get-char-attribute char 'ideographic-)))
746 (insert "(ideographic- ")
747 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
750 (setq cell (car value))
752 (setq cell (decode-char '=ucs cell)))
753 (cond ((characterp cell)
757 (insert (format "%S" cell))
758 (char-db-insert-char-spec cell readable))
759 (setq separator lbs))
763 (if (consp (car cell))
764 (char-db-insert-char-spec cell readable)
765 (char-db-insert-char-reference cell readable))
766 (setq separator lbs))
770 (insert (prin1-to-string cell))
771 (setq separator " ")))
772 (setq value (cdr value)))
774 (insert line-breaking)
775 (setq attributes (delq 'ideographic- attributes)))
776 (when (and (memq 'total-strokes attributes)
777 (setq value (get-char-attribute char 'total-strokes)))
778 (insert (format "(total-strokes . %S)%s"
781 (setq attributes (delq 'total-strokes attributes))
783 (when (and (memq '->ideograph attributes)
784 (setq value (get-char-attribute char '->ideograph)))
785 (insert (format "(->ideograph\t%s)%s"
786 (mapconcat (lambda (code)
787 (cond ((symbolp code)
790 (format "#x%04X" code))
793 line-breaking code))))
796 (setq attributes (delq '->ideograph attributes))
798 (when (and (memq '->decomposition attributes)
799 (setq value (get-char-attribute char '->decomposition)))
800 (insert (format "(->decomposition\t%s)%s"
801 (mapconcat (lambda (code)
802 (cond ((symbolp code)
811 (format "#x%04X" code))
813 (format "%s%S" line-breaking code))))
816 (setq attributes (delq '->decomposition attributes))
818 (if (equal (get-char-attribute char '->titlecase)
819 (get-char-attribute char '->uppercase))
820 (setq attributes (delq '->titlecase attributes)))
821 (when (and (memq '->mojikyo attributes)
822 (setq value (get-char-attribute char '->mojikyo)))
823 (insert (format "(->mojikyo\t\t. %06d)\t; %c%s"
824 value (decode-char 'mojikyo value)
826 (setq attributes (delq '->mojikyo attributes))
828 (when (and (memq 'hanyu-dazidian-vol attributes)
829 (setq value (get-char-attribute char 'hanyu-dazidian-vol)))
830 (insert (format "(hanyu-dazidian-vol . %d)%s"
831 value line-breaking))
832 (setq attributes (delq 'hanyu-dazidian-vol attributes))
834 (when (and (memq 'hanyu-dazidian-page attributes)
835 (setq value (get-char-attribute char 'hanyu-dazidian-page)))
836 (insert (format "(hanyu-dazidian-page . %d)%s"
837 value line-breaking))
838 (setq attributes (delq 'hanyu-dazidian-page attributes))
840 (when (and (memq 'hanyu-dazidian-char attributes)
841 (setq value (get-char-attribute char 'hanyu-dazidian-char)))
842 (insert (format "(hanyu-dazidian-char . %d)%s"
843 value line-breaking))
844 (setq attributes (delq 'hanyu-dazidian-char attributes))
846 (setq rest ccs-attributes)
849 (setq value (get-char-attribute char (car rest)))
851 (if (>= (length (symbol-name (car rest))) 19)
853 (setq has-long-ccs-name t)
857 (setq rest (cdr rest)))
859 (setq name (car attributes))
860 (if (setq value (get-char-attribute char name))
861 (cond ((string-match "^=>ucs@" (symbol-name name))
862 (insert (format "(%-18s . #x%04X)\t; %c%s"
863 name value (decode-char '=ucs value)
866 ((eq name 'jisx0208-1978/4X)
867 (insert (format "(%-18s . #x%04X)%s"
870 ((or (eq name 'ideographic-structure)
871 (eq name 'ideographic-)
872 (string-match "^\\(->\\|<-\\)" (symbol-name name)))
873 (insert (format "(%-18s%s " name line-breaking))
874 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
877 (setq cell (car value))
879 (setq cell (decode-char '=ucs cell)))
880 (cond ((characterp cell)
884 (insert (format "%S" cell))
885 (char-db-insert-char-spec cell readable))
886 (setq separator lbs))
890 (if (consp (car cell))
891 (char-db-insert-char-spec cell readable)
892 (char-db-insert-char-reference cell readable))
893 (setq separator lbs))
897 (insert (prin1-to-string cell))
898 (setq separator " ")))
899 (setq value (cdr value)))
901 (insert line-breaking))
902 ((memq name '(ideograph=
903 original-ideograph-of
907 simplified-ideograph-of
909 ideographic-different-form-of))
910 (insert (format "(%-18s%s " name line-breaking))
911 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
914 (setq cell (car value))
915 (if (and (consp cell)
920 (char-db-insert-alist cell readable)
921 (setq separator lbs))
924 (insert (prin1-to-string cell))
925 (setq separator " "))
926 (setq value (cdr value)))
928 (insert line-breaking))
929 ;; ((string-match "^->" (symbol-name name))
931 ;; (format "(%-18s %s)%s"
933 ;; (mapconcat (lambda (code)
934 ;; (cond ((symbolp code)
935 ;; (symbol-name code))
937 ;; (format "#x%04X" code))
940 ;; line-breaking code))))
944 (insert (format "(%-18s " name))
945 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
948 (setq cell (car value))
949 (if (and (consp cell)
951 (setq ret (condition-case nil
959 (setq key (car (car rest)))
960 (if (find-charset key)
961 (setq cal (cons key cal))
962 (setq al (cons key al)))
963 (setq rest (cdr rest)))
966 (insert-char-attributes ret
969 (setq separator lbs))
972 (insert (prin1-to-string cell))
973 (setq separator " "))
974 (setq value (cdr value)))
976 (insert line-breaking))
978 (insert (format "(%-18s . %S)%s"
982 (setq attributes (cdr attributes)))
983 (while ccs-attributes
984 (setq name (car ccs-attributes))
985 (if (and (eq name (charset-name name))
986 (setq value (get-char-attribute char name)))
989 (cond ((memq name '(ideograph-daikanwa
993 (if has-long-ccs-name
994 "(%-26s . %05d)\t; %c%s"
995 "(%-18s . %05d)\t; %c%s"))
997 (if has-long-ccs-name
998 "(%-26s . %06d)\t; %c%s"
999 "(%-18s . %06d)\t; %c%s"))
1000 ((>= (charset-dimension name) 2)
1001 (if has-long-ccs-name
1002 "(%-26s . #x%04X)\t; %c%s"
1003 "(%-18s . #x%04X)\t; %c%s"))
1005 (if has-long-ccs-name
1006 "(%-26s . #x%02X)\t; %c%s"
1007 "(%-18s . #x%02X)\t; %c%s")))
1009 (if (= (charset-iso-graphic-plane name) 1)
1011 (cond ((= (charset-dimension name) 1)
1013 ((= (charset-dimension name) 2)
1015 ((= (charset-dimension name) 3)
1019 (char-db-decode-isolated-char name value)
1021 (setq ccs-attributes (cdr ccs-attributes)))
1024 (defun insert-char-data (char &optional readable
1025 attributes ccs-attributes)
1027 (narrow-to-region (point)(point))
1028 (insert "(define-char
1030 (insert-char-attributes char readable
1031 attributes ccs-attributes)
1033 (goto-char (point-min))
1034 (while (re-search-forward "[ \t]+$" nil t)
1037 (goto-char (point-min))
1038 (while (re-search-forward "[ \t][ \t][ \t]*" nil t)
1039 (let ((column (current-column))
1040 (indent-tabs-mode t))
1041 (delete-region (match-beginning 0) (point))
1042 (indent-to column)))
1043 (goto-char (point-max))
1044 ;; (tabify (point-min)(point-max))
1047 (defun insert-char-data-with-variant (char &optional printable
1049 script excluded-script)
1050 (insert-char-data char printable)
1051 (let ((variants (or (char-variants char)
1052 (let ((ucs (get-char-attribute char '->ucs)))
1054 (delete char (char-variants (int-char ucs)))))))
1056 (setq variants (sort variants #'<))
1058 (setq variant (car variants))
1059 (if (and (or (null script)
1060 (null (setq vs (get-char-attribute variant 'script)))
1062 (or (null excluded-script)
1063 (null (setq vs (get-char-attribute variant 'script)))
1064 (not (memq excluded-script vs))))
1065 (or (and no-ucs-variant (get-char-attribute variant '=ucs))
1066 (insert-char-data variant printable)))
1067 (setq variants (cdr variants))
1070 (defun insert-char-range-data (min max &optional script excluded-script)
1073 (while (<= code max)
1074 (setq char (decode-char '=ucs code))
1075 (if (encode-char char '=ucs 'defined-only)
1076 (insert-char-data-with-variant char nil 'no-ucs-variant
1077 script excluded-script))
1078 (setq code (1+ code)))))
1080 (defun write-char-range-data-to-file (min max file
1081 &optional script excluded-script)
1082 (let ((coding-system-for-write 'utf-8))
1084 (insert-char-range-data min max script excluded-script)
1085 (write-region (point-min)(point-max) file))))
1087 (defvar what-character-original-window-configuration)
1090 (defun what-char-definition (char)
1091 (interactive (list (char-after)))
1092 (let ((buf (get-buffer-create "*Character Description*"))
1093 (the-buf (current-buffer))
1094 (win-conf (current-window-configuration)))
1096 (make-local-variable 'what-character-original-window-configuration)
1097 (setq what-character-original-window-configuration win-conf)
1098 (setq buffer-read-only nil)
1102 (insert-char-data-with-variant char 'printable)
1103 (unless (char-attribute-alist char)
1104 (insert (format ";; = %c\n"
1105 (let* ((rest (split-char char))
1109 (setq code (logior (lsh code 8)
1111 (decode-char ccs code)))))
1112 ;; (char-db-update-comment)
1113 (set-buffer-modified-p nil)
1114 (view-mode the-buf (lambda (buf)
1115 (set-window-configuration
1116 what-character-original-window-configuration)
1118 (goto-char (point-min)))
1120 (set-window-configuration
1121 what-character-original-window-configuration)
1122 (signal (car err) (cdr err)))))))
1124 (provide 'char-db-util)
1126 ;;; char-db-util.el ends here