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 (when (and (memq '=>ucs attributes)
502 (setq value (get-char-attribute char '=>ucs)))
503 (insert (format "(=>ucs\t\t. #x%04X)\t; %c%s"
504 value (decode-char '=ucs value)
506 (setq attributes (delq '=>ucs 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 (when (and (memq '=>ucs-gb attributes)
516 (setq value (get-char-attribute char '=>ucs-gb)))
517 (insert (format "(=>ucs-gb\t\t. #x%04X)\t; %c%s"
518 value (decode-char '=ucs value)
520 (setq attributes (delq '=>ucs-gb attributes))
522 (when (and (memq '=>ucs-cns attributes)
523 (setq value (get-char-attribute char '=>ucs-cns)))
524 (insert (format "(=>ucs-cns\t\t. #x%04X)\t; %c%s"
525 value (decode-char 'ucs-cns value)
527 (setq attributes (delq '=>ucs-cns attributes))
529 (when (and (memq '=>ucs-big5 attributes)
530 (setq value (get-char-attribute char '=>ucs-big5)))
531 (insert (format "(=>ucs-big5\t\t. #x%04X)\t; %c%s"
532 value (decode-char 'ucs-big5 value)
534 (setq attributes (delq '=>ucs-big5 attributes))
536 (when (and (memq '=>ucs-jis attributes)
537 (setq value (get-char-attribute char '=>ucs-jis)))
538 (insert (format "(=>ucs-jis\t\t. #x%04X)\t; %c%s"
539 value (decode-char 'ucs-jis value)
541 (setq attributes (delq '=>ucs-jis attributes))
543 (when (and (memq '=>ucs-ks attributes)
544 (setq value (get-char-attribute char '=>ucs-ks)))
545 (insert (format "(=>ucs-ks\t\t. #x%04X)\t; %c%s"
546 value (decode-char 'ucs-ks value)
548 (setq attributes (delq '=>ucs-ks attributes))
550 (when (and (memq '->ucs attributes)
551 (setq value (get-char-attribute char '->ucs)))
552 (insert (format (if char-db-convert-obsolete-format
553 "(=>ucs\t\t. #x%04X)\t; %c%s"
554 "(->ucs\t\t. #x%04X)\t; %c%s")
555 value (decode-char '=ucs value)
557 (setq attributes (delq '->ucs attributes))
559 (when (and (memq 'general-category attributes)
560 (setq value (get-char-attribute char 'general-category)))
562 "(general-category\t%s) ; %s%s"
563 (mapconcat (lambda (cell)
566 (cond ((rassoc value unidata-normative-category-alist)
567 "Normative Category")
568 ((rassoc value unidata-informative-category-alist)
569 "Informative Category")
573 (setq attributes (delq 'general-category attributes))
575 (when (and (memq 'bidi-category attributes)
576 (setq value (get-char-attribute char 'bidi-category)))
577 (insert (format "(bidi-category\t. %S)%s"
580 (setq attributes (delq 'bidi-category attributes))
582 (unless (or (not (memq 'mirrored attributes))
583 (eq (setq value (get-char-attribute char 'mirrored 'empty))
585 (insert (format "(mirrored\t\t. %S)%s"
588 (setq attributes (delq 'mirrored attributes))
591 ((and (memq 'decimal-digit-value attributes)
592 (setq value (get-char-attribute char 'decimal-digit-value)))
593 (insert (format "(decimal-digit-value . %S)%s"
596 (setq attributes (delq 'decimal-digit-value attributes))
597 (when (and (memq 'digit-value attributes)
598 (setq value (get-char-attribute char 'digit-value)))
599 (insert (format "(digit-value\t . %S)%s"
602 (setq attributes (delq 'digit-value attributes))
604 (when (and (memq 'numeric-value attributes)
605 (setq value (get-char-attribute char 'numeric-value)))
606 (insert (format "(numeric-value\t . %S)%s"
609 (setq attributes (delq 'numeric-value attributes))
613 (when (and (memq 'digit-value attributes)
614 (setq value (get-char-attribute char 'digit-value)))
615 (insert (format "(digit-value\t. %S)%s"
618 (setq attributes (delq 'digit-value attributes))
620 (when (and (memq 'numeric-value attributes)
621 (setq value (get-char-attribute char 'numeric-value)))
622 (insert (format "(numeric-value\t. %S)%s"
625 (setq attributes (delq 'numeric-value attributes))
627 (when (and (memq 'iso-10646-comment attributes)
628 (setq value (get-char-attribute char 'iso-10646-comment)))
629 (insert (format "(iso-10646-comment\t. %S)%s"
632 (setq attributes (delq 'iso-10646-comment attributes))
634 (when (and (memq 'morohashi-daikanwa attributes)
635 (setq value (get-char-attribute char 'morohashi-daikanwa)))
636 (insert (format "(morohashi-daikanwa\t%s)%s"
637 (mapconcat (function prin1-to-string) value " ")
639 (setq attributes (delq 'morohashi-daikanwa attributes))
643 (when (and (memq 'ideographic-radical attributes)
644 (setq value (get-char-attribute char 'ideographic-radical)))
646 (insert (format "(ideographic-radical . %S)\t; %c%s"
648 (aref ideographic-radicals radical)
650 (setq attributes (delq 'ideographic-radical attributes))
652 (when (and (memq 'ideographic-strokes attributes)
653 (setq value (get-char-attribute char 'ideographic-strokes)))
655 (insert (format "(ideographic-strokes . %S)%s"
658 (setq attributes (delq 'ideographic-strokes attributes))
660 (when (and (memq 'kangxi-radical attributes)
661 (setq value (get-char-attribute char 'kangxi-radical)))
662 (unless (eq value radical)
663 (insert (format "(kangxi-radical\t . %S)\t; %c%s"
665 (aref ideographic-radicals value)
668 (setq radical value)))
669 (setq attributes (delq 'kangxi-radical attributes))
671 (when (and (memq 'kangxi-strokes attributes)
672 (setq value (get-char-attribute char 'kangxi-strokes)))
673 (unless (eq value strokes)
674 (insert (format "(kangxi-strokes\t . %S)%s"
678 (setq strokes value)))
679 (setq attributes (delq 'kangxi-strokes attributes))
681 (when (and (memq 'japanese-radical attributes)
682 (setq value (get-char-attribute char 'japanese-radical)))
683 (unless (eq value radical)
684 (insert (format "(japanese-radical\t . %S)\t; %c%s"
686 (aref ideographic-radicals value)
689 (setq radical value)))
690 (setq attributes (delq 'japanese-radical attributes))
692 (when (and (memq 'japanese-strokes attributes)
693 (setq value (get-char-attribute char 'japanese-strokes)))
694 (unless (eq value strokes)
695 (insert (format "(japanese-strokes\t . %S)%s"
699 (setq strokes value)))
700 (setq attributes (delq 'japanese-strokes attributes))
702 (when (and (memq 'cns-radical attributes)
703 (setq value (get-char-attribute char 'cns-radical)))
704 (insert (format "(cns-radical\t . %S)\t; %c%s"
706 (aref ideographic-radicals value)
708 (setq attributes (delq 'cns-radical attributes))
710 (when (and (memq 'cns-strokes attributes)
711 (setq value (get-char-attribute char 'cns-strokes)))
712 (unless (eq value strokes)
713 (insert (format "(cns-strokes\t . %S)%s"
717 (setq strokes value)))
718 (setq attributes (delq 'cns-strokes attributes))
720 (when (and (memq 'shinjigen-1-radical attributes)
721 (setq value (get-char-attribute char 'shinjigen-1-radical)))
722 (unless (eq value radical)
723 (insert (format "(shinjigen-1-radical . %S)\t; %c%s"
725 (aref ideographic-radicals value)
728 (setq radical value)))
729 (setq attributes (delq 'shinjigen-1-radical attributes))
731 (when (and (memq 'ideographic- attributes)
732 (setq value (get-char-attribute char 'ideographic-)))
733 (insert "(ideographic- ")
734 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
737 (setq cell (car value))
739 (setq cell (decode-char '=ucs cell)))
740 (cond ((characterp cell)
744 (insert (format "%S" cell))
745 (char-db-insert-char-spec cell readable))
746 (setq separator lbs))
750 (if (consp (car cell))
751 (char-db-insert-char-spec cell readable)
752 (char-db-insert-char-reference cell readable))
753 (setq separator lbs))
757 (insert (prin1-to-string cell))
758 (setq separator " ")))
759 (setq value (cdr value)))
761 (insert line-breaking)
762 (setq attributes (delq 'ideographic- attributes)))
763 (when (and (memq 'total-strokes attributes)
764 (setq value (get-char-attribute char 'total-strokes)))
765 (insert (format "(total-strokes . %S)%s"
768 (setq attributes (delq 'total-strokes attributes))
770 (when (and (memq '->ideograph attributes)
771 (setq value (get-char-attribute char '->ideograph)))
772 (insert (format "(->ideograph\t%s)%s"
773 (mapconcat (lambda (code)
774 (cond ((symbolp code)
777 (format "#x%04X" code))
780 line-breaking code))))
783 (setq attributes (delq '->ideograph attributes))
785 (when (and (memq '->decomposition attributes)
786 (setq value (get-char-attribute char '->decomposition)))
787 (insert (format "(->decomposition\t%s)%s"
788 (mapconcat (lambda (code)
789 (cond ((symbolp code)
798 (format "#x%04X" code))
800 (format "%s%S" line-breaking code))))
803 (setq attributes (delq '->decomposition attributes))
805 (if (equal (get-char-attribute char '->titlecase)
806 (get-char-attribute char '->uppercase))
807 (setq attributes (delq '->titlecase attributes)))
808 (when (and (memq '->mojikyo attributes)
809 (setq value (get-char-attribute char '->mojikyo)))
810 (insert (format "(->mojikyo\t\t. %06d)\t; %c%s"
811 value (decode-char 'mojikyo value)
813 (setq attributes (delq '->mojikyo attributes))
815 (when (and (memq 'hanyu-dazidian-vol attributes)
816 (setq value (get-char-attribute char 'hanyu-dazidian-vol)))
817 (insert (format "(hanyu-dazidian-vol . %d)%s"
818 value line-breaking))
819 (setq attributes (delq 'hanyu-dazidian-vol attributes))
821 (when (and (memq 'hanyu-dazidian-page attributes)
822 (setq value (get-char-attribute char 'hanyu-dazidian-page)))
823 (insert (format "(hanyu-dazidian-page . %d)%s"
824 value line-breaking))
825 (setq attributes (delq 'hanyu-dazidian-page attributes))
827 (when (and (memq 'hanyu-dazidian-char attributes)
828 (setq value (get-char-attribute char 'hanyu-dazidian-char)))
829 (insert (format "(hanyu-dazidian-char . %d)%s"
830 value line-breaking))
831 (setq attributes (delq 'hanyu-dazidian-char attributes))
833 (setq rest ccs-attributes)
836 (setq value (get-char-attribute char (car rest)))
838 (if (>= (length (symbol-name (car rest))) 19)
840 (setq has-long-ccs-name t)
844 (setq rest (cdr rest)))
846 (setq name (car attributes))
847 (if (setq value (get-char-attribute char name))
848 (cond ((eq name 'jisx0208-1978/4X)
849 (insert (format "(%-18s . #x%04X)%s"
852 ((or (eq name 'ideographic-structure)
853 (eq name 'ideographic-)
854 (string-match "^\\(->\\|<-\\)" (symbol-name name)))
855 (insert (format "(%-18s%s " name line-breaking))
856 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
859 (setq cell (car value))
861 (setq cell (decode-char '=ucs cell)))
862 (cond ((characterp cell)
866 (insert (format "%S" cell))
867 (char-db-insert-char-spec cell readable))
868 (setq separator lbs))
872 (if (consp (car cell))
873 (char-db-insert-char-spec cell readable)
874 (char-db-insert-char-reference cell readable))
875 (setq separator lbs))
879 (insert (prin1-to-string cell))
880 (setq separator " ")))
881 (setq value (cdr value)))
883 (insert line-breaking))
884 ((memq name '(ideograph=
885 original-ideograph-of
889 simplified-ideograph-of
891 ideographic-different-form-of))
892 (insert (format "(%-18s%s " name line-breaking))
893 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
896 (setq cell (car value))
897 (if (and (consp cell)
902 (char-db-insert-alist cell readable)
903 (setq separator lbs))
906 (insert (prin1-to-string cell))
907 (setq separator " "))
908 (setq value (cdr value)))
910 (insert line-breaking))
911 ;; ((string-match "^->" (symbol-name name))
913 ;; (format "(%-18s %s)%s"
915 ;; (mapconcat (lambda (code)
916 ;; (cond ((symbolp code)
917 ;; (symbol-name code))
919 ;; (format "#x%04X" code))
922 ;; line-breaking code))))
926 (insert (format "(%-18s " name))
927 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
930 (setq cell (car value))
931 (if (and (consp cell)
933 (setq ret (condition-case nil
941 (setq key (car (car rest)))
942 (if (find-charset key)
943 (setq cal (cons key cal))
944 (setq al (cons key al)))
945 (setq rest (cdr rest)))
948 (insert-char-attributes ret
951 (setq separator lbs))
954 (insert (prin1-to-string cell))
955 (setq separator " "))
956 (setq value (cdr value)))
958 (insert line-breaking))
960 (insert (format "(%-18s . %S)%s"
964 (setq attributes (cdr attributes)))
965 (while ccs-attributes
966 (setq name (car ccs-attributes))
967 (if (and (eq name (charset-name name))
968 (setq value (get-char-attribute char name)))
971 (cond ((memq name '(ideograph-daikanwa
975 (if has-long-ccs-name
976 "(%-26s . %05d)\t; %c%s"
977 "(%-18s . %05d)\t; %c%s"))
979 (if has-long-ccs-name
980 "(%-26s . %06d)\t; %c%s"
981 "(%-18s . %06d)\t; %c%s"))
982 ((>= (charset-dimension name) 2)
983 (if has-long-ccs-name
984 "(%-26s . #x%04X)\t; %c%s"
985 "(%-18s . #x%04X)\t; %c%s"))
987 (if has-long-ccs-name
988 "(%-26s . #x%02X)\t; %c%s"
989 "(%-18s . #x%02X)\t; %c%s")))
991 (if (= (charset-iso-graphic-plane name) 1)
993 (cond ((= (charset-dimension name) 1)
995 ((= (charset-dimension name) 2)
997 ((= (charset-dimension name) 3)
1001 (char-db-decode-isolated-char name value)
1003 (setq ccs-attributes (cdr ccs-attributes)))
1006 (defun insert-char-data (char &optional readable
1007 attributes ccs-attributes)
1009 (narrow-to-region (point)(point))
1010 (insert "(define-char
1012 (insert-char-attributes char readable
1013 attributes ccs-attributes)
1015 (goto-char (point-min))
1016 (while (re-search-forward "[ \t]+$" nil t)
1019 (goto-char (point-min))
1020 (while (re-search-forward "[ \t][ \t][ \t]*" nil t)
1021 (let ((column (current-column))
1022 (indent-tabs-mode t))
1023 (delete-region (match-beginning 0) (point))
1024 (indent-to column)))
1025 (goto-char (point-max))
1026 ;; (tabify (point-min)(point-max))
1029 (defun insert-char-data-with-variant (char &optional printable
1031 script excluded-script)
1032 (insert-char-data char printable)
1033 (let ((variants (or (char-variants char)
1034 (let ((ucs (get-char-attribute char '->ucs)))
1036 (delete char (char-variants (int-char ucs)))))))
1038 (setq variants (sort variants #'<))
1040 (setq variant (car variants))
1041 (if (and (or (null script)
1042 (null (setq vs (get-char-attribute variant 'script)))
1044 (or (null excluded-script)
1045 (null (setq vs (get-char-attribute variant 'script)))
1046 (not (memq excluded-script vs))))
1047 (or (and no-ucs-variant (get-char-attribute variant '=ucs))
1048 (insert-char-data variant printable)))
1049 (setq variants (cdr variants))
1052 (defun insert-char-range-data (min max &optional script excluded-script)
1055 (while (<= code max)
1056 (setq char (decode-char '=ucs code))
1057 (if (encode-char char '=ucs 'defined-only)
1058 (insert-char-data-with-variant char nil 'no-ucs-variant
1059 script excluded-script))
1060 (setq code (1+ code)))))
1062 (defun write-char-range-data-to-file (min max file
1063 &optional script excluded-script)
1064 (let ((coding-system-for-write 'utf-8))
1066 (insert-char-range-data min max script excluded-script)
1067 (write-region (point-min)(point-max) file))))
1069 (defvar what-character-original-window-configuration)
1072 (defun what-char-definition (char)
1073 (interactive (list (char-after)))
1074 (let ((buf (get-buffer-create "*Character Description*"))
1075 (the-buf (current-buffer))
1076 (win-conf (current-window-configuration)))
1078 (make-local-variable 'what-character-original-window-configuration)
1079 (setq what-character-original-window-configuration win-conf)
1080 (setq buffer-read-only nil)
1084 (insert-char-data-with-variant char 'printable)
1085 (unless (char-attribute-alist char)
1086 (insert (format ";; = %c\n"
1087 (let* ((rest (split-char char))
1091 (setq code (logior (lsh code 8)
1093 (decode-char ccs code)))))
1094 ;; (char-db-update-comment)
1095 (set-buffer-modified-p nil)
1096 (view-mode the-buf (lambda (buf)
1097 (set-window-configuration
1098 what-character-original-window-configuration)
1100 (goto-char (point-min)))
1102 (set-window-configuration
1103 what-character-original-window-configuration)
1104 (signal (car err) (cdr err)))))))
1106 (provide 'char-db-util)
1108 ;;; char-db-util.el ends here