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
167 japanese-jisx0208-1990
200 (defun char-db-make-char-spec (char)
202 (cond ((characterp char)
203 (cond ((and (setq ret (get-char-attribute char 'ucs))
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 (or (and (charset-iso-final-char ccs)
224 (setq ret (get-char-attribute char ccs)))
225 (eq ccs 'ideograph-daikanwa))
226 (setq char-spec (cons (cons ccs ret) char-spec))))
228 (setq char-spec (split-char char)))
229 (cond ((setq ret (get-char-attribute char 'name))
230 (setq char-spec (cons (cons 'name ret) char-spec))
232 ((setq ret (get-char-attribute char 'name*))
233 (setq char-spec (cons (cons 'name* ret) char-spec))
240 (defun char-db-insert-char-spec (char &optional readable column)
242 (setq column (current-column)))
243 (let (char-spec ret al cal key temp-char)
244 (setq char-spec (char-db-make-char-spec char))
245 (unless (or (characterp char) ; char
247 (setq char (find-char char-spec))
249 ;; define temporary character
250 ;; Current implementation is dirty.
251 (setq temp-char (define-char (cons '(ideograph-daikanwa . 0)
253 (remove-char-attribute temp-char 'ideograph-daikanwa)
254 (setq char temp-char))
258 (setq key (car (car char-spec)))
259 (unless (memq key char-db-ignored-attributes)
260 (if (find-charset key)
261 (if (get-char-attribute char key)
262 (setq cal (cons key cal)))
263 (setq al (cons key al))))
264 (setq char-spec (cdr char-spec)))
266 (setq char-spec (char-db-make-char-spec char))
268 (setq key (car (car char-spec)))
269 (unless (memq key char-db-ignored-attributes)
270 (if (find-charset key)
271 (setq cal (cons key cal))
272 (setq al (cons key al))))
273 (setq char-spec (cdr char-spec)))
276 (memq 'ideographic-structure al))
277 (push 'ideographic-structure al))
278 (insert-char-attributes char
282 ;; undefine temporary character
283 ;; Current implementation is dirty.
284 (setq char-spec (char-attribute-alist temp-char))
286 (remove-char-attribute temp-char (car (car char-spec)))
287 (setq char-spec (cdr char-spec))))))
289 (defun char-db-insert-alist (alist &optional readable column)
291 (setq column (current-column)))
293 (concat "\n" (make-string (1+ column) ?\ )))
296 lbs cell rest separator)
299 (setq name (car (car alist))
300 value (cdr (car alist)))
301 (cond ((eq name 'char)
303 (if (setq ret (condition-case nil
310 (setq key (car (car value)))
311 (if (find-charset key)
312 (setq cal (cons key cal))
313 (setq al (cons key al)))
314 (setq value (cdr value)))
315 (insert-char-attributes ret
318 (insert (prin1-to-string value)))
320 (insert line-breaking))
322 (insert (format "(%-18s " name))
323 (setq lbs (concat "\n" (make-string (current-column) ?\ )))
325 (setq cell (car value))
326 (if (and (consp cell)
328 (setq ret (condition-case nil
337 (setq key (car (car rest)))
338 (if (find-charset key)
339 (setq cal (cons key cal))
340 (setq al (cons key al)))
341 (setq rest (cdr rest)))
344 (insert-char-attributes ret
347 (setq separator lbs))
350 (insert (prin1-to-string cell))
351 (setq separator " "))
352 (setq value (cdr value)))
354 (insert line-breaking))
356 (insert (format "(%-18s . %S)%s"
359 (setq alist (cdr alist))))
362 (defun char-db-insert-char-reference (plist &optional readable column)
364 (setq column (current-column)))
366 (concat "\n" (make-string (1+ column) ?\ )))
371 (setq name (pop plist))
372 (setq value (pop plist))
373 (cond ((eq name :char)
376 (cond ((numberp value)
377 (setq value (decode-char 'ucs value)))
379 ;; (setq value (or (find-char value)
382 (char-db-insert-char-spec value readable)
383 (insert line-breaking)
386 (insert (format "%s%s\t%d ; %c%s"
389 (aref ideographic-radicals value)
393 (insert (format "%s%s\t%S" separator name value))
394 (setq separator line-breaking)))
398 (defun char-db-decode-isolated-char (ccs code-point)
401 (cond ((eq ccs 'arabic-iso8859-6)
402 (decode-char ccs code-point))
403 ((and (memq ccs '(ideograph-gt-pj-1
414 (setq ret (decode-char ccs code-point))
415 (setq ret (get-char-attribute ret '=gt)))
416 (decode-builtin-char '=gt ret))
418 (decode-builtin-char ccs code-point))))
419 (cond ((and (<= 0 (char-int ret))
420 (<= (char-int ret) #x1F))
421 (decode-char 'ucs (+ #x2400 (char-int ret))))
422 ((= (char-int ret) #x7F)
426 (defvar char-db-convert-obsolete-format t)
428 (defun insert-char-attributes (char &optional readable
429 attributes ccs-attributes
434 (if (consp attributes)
436 (dolist (name attributes)
437 (unless (memq name char-db-ignored-attributes)
440 (dolist (name (char-attribute-list))
441 (unless (memq name char-db-ignored-attributes)
442 (if (find-charset name)
446 #'char-attribute-name<))
448 (sort (if ccs-attributes
451 (dolist (name ccs-attributes)
452 (unless (memq name char-db-ignored-attributes)
457 (dolist (name (charset-list))
458 (unless (memq name char-db-ignored-attributes)
461 #'char-attribute-name<)))
463 (setq column (current-column)))
464 (let (name value has-long-ccs-name rest
467 (concat "\n" (make-string (1+ column) ?\ )))
468 lbs cell separator ret
471 (when (and (memq 'name attributes)
472 (setq value (get-char-attribute char 'name)))
474 (if (> (+ (current-column) (length value)) 48)
477 value line-breaking))
478 (setq attributes (delq 'name attributes))
480 (when (and (memq 'name* attributes)
481 (setq value (get-char-attribute char 'name*)))
483 (if (> (+ (current-column) (length value)) 48)
486 value line-breaking))
487 (setq attributes (delq 'name* attributes))
489 (when (and (memq 'script attributes)
490 (setq value (get-char-attribute char 'script)))
491 (insert (format "(script\t\t%s)%s"
492 (mapconcat (function prin1-to-string)
495 (setq attributes (delq 'script attributes))
497 (when (and (memq '=>ucs attributes)
498 (setq value (get-char-attribute char '=>ucs)))
499 (insert (format "(=>ucs\t\t. #x%04X)\t; %c%s"
500 value (decode-char 'ucs value)
502 (setq attributes (delq '=>ucs attributes))
504 (when (and (memq '=>ucs* attributes)
505 (setq value (get-char-attribute char '=>ucs*)))
506 (insert (format "(=>ucs*\t\t. #x%04X)\t; %c%s"
507 value (decode-char 'ucs value)
509 (setq attributes (delq '=>ucs* attributes))
511 (when (and (memq '=>ucs-gb attributes)
512 (setq value (get-char-attribute char '=>ucs-gb)))
513 (insert (format "(=>ucs-gb\t\t. #x%04X)\t; %c%s"
514 value (decode-char 'ucs value)
516 (setq attributes (delq '=>ucs-gb attributes))
518 (when (and (memq '=>ucs-cns attributes)
519 (setq value (get-char-attribute char '=>ucs-cns)))
520 (insert (format "(=>ucs-cns\t\t. #x%04X)\t; %c%s"
521 value (decode-char 'ucs-cns value)
523 (setq attributes (delq '=>ucs-cns attributes))
525 (when (and (memq '=>ucs-jis attributes)
526 (setq value (get-char-attribute char '=>ucs-jis)))
527 (insert (format "(=>ucs-jis\t\t. #x%04X)\t; %c%s"
528 value (decode-char 'ucs-jis value)
530 (setq attributes (delq '=>ucs-jis attributes))
532 (when (and (memq '=>ucs-ks attributes)
533 (setq value (get-char-attribute char '=>ucs-ks)))
534 (insert (format "(=>ucs-ks\t\t. #x%04X)\t; %c%s"
535 value (decode-char 'ucs-ks value)
537 (setq attributes (delq '=>ucs-ks attributes))
539 (when (and (memq '->ucs attributes)
540 (setq value (get-char-attribute char '->ucs)))
541 (insert (format (if char-db-convert-obsolete-format
542 "(=>ucs\t\t. #x%04X)\t; %c%s"
543 "(->ucs\t\t. #x%04X)\t; %c%s")
544 value (decode-char 'ucs value)
546 (setq attributes (delq '->ucs attributes))
548 (when (and (memq 'general-category attributes)
549 (setq value (get-char-attribute char 'general-category)))
551 "(general-category\t%s) ; %s%s"
552 (mapconcat (lambda (cell)
555 (cond ((rassoc value unidata-normative-category-alist)
556 "Normative Category")
557 ((rassoc value unidata-informative-category-alist)
558 "Informative Category")
562 (setq attributes (delq 'general-category attributes))
564 (when (and (memq 'bidi-category attributes)
565 (setq value (get-char-attribute char 'bidi-category)))
566 (insert (format "(bidi-category\t. %S)%s"
569 (setq attributes (delq 'bidi-category attributes))
571 (unless (or (not (memq 'mirrored attributes))
572 (eq (setq value (get-char-attribute char 'mirrored 'empty))
574 (insert (format "(mirrored\t\t. %S)%s"
577 (setq attributes (delq 'mirrored attributes))
580 ((and (memq 'decimal-digit-value attributes)
581 (setq value (get-char-attribute char 'decimal-digit-value)))
582 (insert (format "(decimal-digit-value . %S)%s"
585 (setq attributes (delq 'decimal-digit-value attributes))
586 (when (and (memq 'digit-value attributes)
587 (setq value (get-char-attribute char 'digit-value)))
588 (insert (format "(digit-value\t . %S)%s"
591 (setq attributes (delq 'digit-value attributes))
593 (when (and (memq 'numeric-value attributes)
594 (setq value (get-char-attribute char 'numeric-value)))
595 (insert (format "(numeric-value\t . %S)%s"
598 (setq attributes (delq 'numeric-value attributes))
602 (when (and (memq 'digit-value attributes)
603 (setq value (get-char-attribute char 'digit-value)))
604 (insert (format "(digit-value\t. %S)%s"
607 (setq attributes (delq 'digit-value attributes))
609 (when (and (memq 'numeric-value attributes)
610 (setq value (get-char-attribute char 'numeric-value)))
611 (insert (format "(numeric-value\t. %S)%s"
614 (setq attributes (delq 'numeric-value attributes))
616 (when (and (memq 'iso-10646-comment attributes)
617 (setq value (get-char-attribute char 'iso-10646-comment)))
618 (insert (format "(iso-10646-comment\t. %S)%s"
621 (setq attributes (delq 'iso-10646-comment attributes))
623 (when (and (memq 'morohashi-daikanwa attributes)
624 (setq value (get-char-attribute char 'morohashi-daikanwa)))
625 (insert (format "(morohashi-daikanwa\t%s)%s"
626 (mapconcat (function prin1-to-string) value " ")
628 (setq attributes (delq 'morohashi-daikanwa attributes))
632 (when (and (memq 'ideographic-radical attributes)
633 (setq value (get-char-attribute char 'ideographic-radical)))
635 (insert (format "(ideographic-radical . %S)\t; %c%s"
637 (aref ideographic-radicals radical)
639 (setq attributes (delq 'ideographic-radical attributes))
641 (when (and (memq 'ideographic-strokes attributes)
642 (setq value (get-char-attribute char 'ideographic-strokes)))
644 (insert (format "(ideographic-strokes . %S)%s"
647 (setq attributes (delq 'ideographic-strokes attributes))
649 (when (and (memq 'kangxi-radical attributes)
650 (setq value (get-char-attribute char 'kangxi-radical)))
651 (unless (eq value radical)
652 (insert (format "(kangxi-radical\t . %S)\t; %c%s"
654 (aref ideographic-radicals value)
657 (setq radical value)))
658 (setq attributes (delq 'kangxi-radical attributes))
660 (when (and (memq 'kangxi-strokes attributes)
661 (setq value (get-char-attribute char 'kangxi-strokes)))
662 (unless (eq value strokes)
663 (insert (format "(kangxi-strokes\t . %S)%s"
667 (setq strokes value)))
668 (setq attributes (delq 'kangxi-strokes attributes))
670 (when (and (memq 'japanese-radical attributes)
671 (setq value (get-char-attribute char 'japanese-radical)))
672 (unless (eq value radical)
673 (insert (format "(japanese-radical\t . %S)\t; %c%s"
675 (aref ideographic-radicals value)
678 (setq radical value)))
679 (setq attributes (delq 'japanese-radical attributes))
681 (when (and (memq 'japanese-strokes attributes)
682 (setq value (get-char-attribute char 'japanese-strokes)))
683 (unless (eq value strokes)
684 (insert (format "(japanese-strokes\t . %S)%s"
688 (setq strokes value)))
689 (setq attributes (delq 'japanese-strokes attributes))
691 (when (and (memq 'cns-radical attributes)
692 (setq value (get-char-attribute char 'cns-radical)))
693 (insert (format "(cns-radical\t . %S)\t; %c%s"
695 (aref ideographic-radicals value)
697 (setq attributes (delq 'cns-radical attributes))
699 (when (and (memq 'cns-strokes attributes)
700 (setq value (get-char-attribute char 'cns-strokes)))
701 (unless (eq value strokes)
702 (insert (format "(cns-strokes\t . %S)%s"
706 (setq strokes value)))
707 (setq attributes (delq 'cns-strokes attributes))
709 (when (and (memq 'shinjigen-1-radical attributes)
710 (setq value (get-char-attribute char 'shinjigen-1-radical)))
711 (unless (eq value radical)
712 (insert (format "(shinjigen-1-radical . %S)\t; %c%s"
714 (aref ideographic-radicals value)
717 (setq radical value)))
718 (setq attributes (delq 'shinjigen-1-radical attributes))
720 (when (and (memq 'ideographic- attributes)
721 (setq value (get-char-attribute char 'ideographic-)))
722 (insert "(ideographic- ")
723 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
726 (setq cell (car value))
728 (setq cell (decode-char 'ucs cell)))
729 (cond ((characterp cell)
733 (insert (format "%S" cell))
734 (char-db-insert-char-spec cell readable))
735 (setq separator lbs))
739 (if (consp (car cell))
740 (char-db-insert-char-spec cell readable)
741 (char-db-insert-char-reference cell readable))
742 (setq separator lbs))
746 (insert (prin1-to-string cell))
747 (setq separator " ")))
748 (setq value (cdr value)))
750 (insert line-breaking)
751 (setq attributes (delq 'ideographic- attributes)))
752 (when (and (memq 'total-strokes attributes)
753 (setq value (get-char-attribute char 'total-strokes)))
754 (insert (format "(total-strokes . %S)%s"
757 (setq attributes (delq 'total-strokes attributes))
759 (when (and (memq '->ideograph attributes)
760 (setq value (get-char-attribute char '->ideograph)))
761 (insert (format "(->ideograph\t%s)%s"
762 (mapconcat (lambda (code)
763 (cond ((symbolp code)
766 (format "#x%04X" code))
769 line-breaking code))))
772 (setq attributes (delq '->ideograph attributes))
774 (when (and (memq '->decomposition attributes)
775 (setq value (get-char-attribute char '->decomposition)))
776 (insert (format "(->decomposition\t%s)%s"
777 (mapconcat (lambda (code)
778 (cond ((symbolp code)
787 (format "#x%04X" code))
789 (format "%s%S" line-breaking code))))
792 (setq attributes (delq '->decomposition attributes))
794 (if (equal (get-char-attribute char '->titlecase)
795 (get-char-attribute char '->uppercase))
796 (setq attributes (delq '->titlecase attributes)))
797 (when (and (memq '->mojikyo attributes)
798 (setq value (get-char-attribute char '->mojikyo)))
799 (insert (format "(->mojikyo\t\t. %06d)\t; %c%s"
800 value (decode-char 'mojikyo value)
802 (setq attributes (delq '->mojikyo attributes))
804 (when (and (memq 'hanyu-dazidian-vol attributes)
805 (setq value (get-char-attribute char 'hanyu-dazidian-vol)))
806 (insert (format "(hanyu-dazidian-vol . %d)%s"
807 value line-breaking))
808 (setq attributes (delq 'hanyu-dazidian-vol attributes))
810 (when (and (memq 'hanyu-dazidian-page attributes)
811 (setq value (get-char-attribute char 'hanyu-dazidian-page)))
812 (insert (format "(hanyu-dazidian-page . %d)%s"
813 value line-breaking))
814 (setq attributes (delq 'hanyu-dazidian-page attributes))
816 (when (and (memq 'hanyu-dazidian-char attributes)
817 (setq value (get-char-attribute char 'hanyu-dazidian-char)))
818 (insert (format "(hanyu-dazidian-char . %d)%s"
819 value line-breaking))
820 (setq attributes (delq 'hanyu-dazidian-char attributes))
822 (setq rest ccs-attributes)
825 (setq value (get-char-attribute char (car rest)))
827 (if (>= (length (symbol-name (car rest))) 19)
829 (setq has-long-ccs-name t)
833 (setq rest (cdr rest)))
835 (setq name (car attributes))
836 (if (setq value (get-char-attribute char name))
837 (cond ((eq name 'jisx0208-1978/4X)
838 (insert (format "(%-18s . #x%04X)%s"
841 ((or (eq name 'ideographic-structure)
842 (eq name 'ideographic-)
843 (string-match "^\\(->\\|<-\\)" (symbol-name name)))
844 (insert (format "(%-18s%s " name line-breaking))
845 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
848 (setq cell (car value))
850 (setq cell (decode-char 'ucs cell)))
851 (cond ((characterp cell)
855 (insert (format "%S" cell))
856 (char-db-insert-char-spec cell readable))
857 (setq separator lbs))
861 (if (consp (car cell))
862 (char-db-insert-char-spec cell readable)
863 (char-db-insert-char-reference cell readable))
864 (setq separator lbs))
868 (insert (prin1-to-string cell))
869 (setq separator " ")))
870 (setq value (cdr value)))
872 (insert line-breaking))
873 ((memq name '(ideograph=
874 original-ideograph-of
878 simplified-ideograph-of
880 ideographic-different-form-of))
881 (insert (format "(%-18s%s " name line-breaking))
882 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
885 (setq cell (car value))
886 (if (and (consp cell)
891 (char-db-insert-alist cell readable)
892 (setq separator lbs))
895 (insert (prin1-to-string cell))
896 (setq separator " "))
897 (setq value (cdr value)))
899 (insert line-breaking))
900 ;; ((string-match "^->" (symbol-name name))
902 ;; (format "(%-18s %s)%s"
904 ;; (mapconcat (lambda (code)
905 ;; (cond ((symbolp code)
906 ;; (symbol-name code))
908 ;; (format "#x%04X" code))
911 ;; line-breaking code))))
915 (insert (format "(%-18s " name))
916 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
919 (setq cell (car value))
920 (if (and (consp cell)
922 (setq ret (condition-case nil
930 (setq key (car (car rest)))
931 (if (find-charset key)
932 (setq cal (cons key cal))
933 (setq al (cons key al)))
934 (setq rest (cdr rest)))
937 (insert-char-attributes ret
940 (setq separator lbs))
943 (insert (prin1-to-string cell))
944 (setq separator " "))
945 (setq value (cdr value)))
947 (insert line-breaking))
949 (insert (format "(%-18s . %S)%s"
953 (setq attributes (cdr attributes)))
954 (while ccs-attributes
955 (setq name (car ccs-attributes))
956 (if (and (eq name (charset-name name))
957 (setq value (get-char-attribute char name)))
960 (cond ((memq name '(ideograph-daikanwa-2
963 (if has-long-ccs-name
964 "(%-26s . %05d)\t; %c%s"
965 "(%-18s . %05d)\t; %c%s"))
967 (if has-long-ccs-name
968 "(%-26s . %06d)\t; %c%s"
969 "(%-18s . %06d)\t; %c%s"))
970 ((>= (charset-dimension name) 2)
971 (if has-long-ccs-name
972 "(%-26s . #x%04X)\t; %c%s"
973 "(%-18s . #x%04X)\t; %c%s"))
975 (if has-long-ccs-name
976 "(%-26s . #x%02X)\t; %c%s"
977 "(%-18s . #x%02X)\t; %c%s")))
979 (if (= (charset-iso-graphic-plane name) 1)
981 (cond ((= (charset-dimension name) 1)
983 ((= (charset-dimension name) 2)
985 ((= (charset-dimension name) 3)
989 (char-db-decode-isolated-char name value)
991 (setq ccs-attributes (cdr ccs-attributes)))
994 (defun insert-char-data (char &optional readable
995 attributes ccs-attributes)
997 (narrow-to-region (point)(point))
998 (insert "(define-char
1000 (insert-char-attributes char readable
1001 attributes ccs-attributes)
1003 (goto-char (point-min))
1004 (while (re-search-forward "[ \t]+$" nil t)
1006 (goto-char (point-max))
1007 (tabify (point-min)(point-max))
1010 (defun insert-char-data-with-variant (char &optional printable
1012 script excluded-script)
1013 (insert-char-data char printable)
1014 (let ((variants (or (char-variants char)
1015 (let ((ucs (get-char-attribute char '->ucs)))
1017 (delete char (char-variants (int-char ucs)))))))
1019 (setq variants (sort variants #'<))
1021 (setq variant (car variants))
1022 (if (and (or (null script)
1023 (null (setq vs (get-char-attribute variant 'script)))
1025 (or (null excluded-script)
1026 (null (setq vs (get-char-attribute variant 'script)))
1027 (not (memq excluded-script vs))))
1028 (or (and no-ucs-variant (get-char-attribute variant 'ucs))
1029 (insert-char-data variant printable)))
1030 (setq variants (cdr variants))
1033 (defun insert-char-range-data (min max &optional script excluded-script)
1036 (while (<= code max)
1037 (setq char (decode-char 'ucs code))
1038 (if (get-char-attribute char 'ucs)
1039 (insert-char-data-with-variant char nil 'no-ucs-variant
1040 script excluded-script))
1041 (setq code (1+ code))
1044 (defun write-char-range-data-to-file (min max file
1045 &optional script excluded-script)
1046 (let ((coding-system-for-write 'utf-8))
1048 (insert-char-range-data min max script excluded-script)
1049 (write-region (point-min)(point-max) file))))
1051 (defvar what-character-original-window-configuration)
1054 (defun what-char-definition (char)
1055 (interactive (list (char-after)))
1056 (let ((buf (get-buffer-create "*Character Description*"))
1057 (the-buf (current-buffer))
1058 (win-conf (current-window-configuration)))
1060 (make-local-variable 'what-character-original-window-configuration)
1061 (setq what-character-original-window-configuration win-conf)
1062 (setq buffer-read-only nil)
1066 (insert-char-data-with-variant char 'printable)
1067 (unless (char-attribute-alist char)
1068 (insert (format ";; = %c\n"
1069 (let* ((rest (split-char char))
1073 (setq code (logior (lsh code 8)
1075 (decode-char ccs code)))))
1076 ;; (char-db-update-comment)
1077 (set-buffer-modified-p nil)
1078 (view-mode the-buf (lambda (buf)
1079 (set-window-configuration
1080 what-character-original-window-configuration)
1082 (goto-char (point-min)))
1084 (set-window-configuration
1085 what-character-original-window-configuration)
1086 (signal (car err) (cdr err)))))))
1088 (provide 'char-db-util)
1090 ;;; char-db-util.el ends here