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
173 japanese-jisx0208-1990
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 (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 '(=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-big5 attributes)
526 (setq value (get-char-attribute char '=>ucs-big5)))
527 (insert (format "(=>ucs-big5\t\t. #x%04X)\t; %c%s"
528 value (decode-char 'ucs-big5 value)
530 (setq attributes (delq '=>ucs-big5 attributes))
532 (when (and (memq '=>ucs-jis attributes)
533 (setq value (get-char-attribute char '=>ucs-jis)))
534 (insert (format "(=>ucs-jis\t\t. #x%04X)\t; %c%s"
535 value (decode-char 'ucs-jis value)
537 (setq attributes (delq '=>ucs-jis attributes))
539 (when (and (memq '=>ucs-ks attributes)
540 (setq value (get-char-attribute char '=>ucs-ks)))
541 (insert (format "(=>ucs-ks\t\t. #x%04X)\t; %c%s"
542 value (decode-char 'ucs-ks value)
544 (setq attributes (delq '=>ucs-ks attributes))
546 (when (and (memq '->ucs attributes)
547 (setq value (get-char-attribute char '->ucs)))
548 (insert (format (if char-db-convert-obsolete-format
549 "(=>ucs\t\t. #x%04X)\t; %c%s"
550 "(->ucs\t\t. #x%04X)\t; %c%s")
551 value (decode-char '=ucs value)
553 (setq attributes (delq '->ucs attributes))
555 (when (and (memq 'general-category attributes)
556 (setq value (get-char-attribute char 'general-category)))
558 "(general-category\t%s) ; %s%s"
559 (mapconcat (lambda (cell)
562 (cond ((rassoc value unidata-normative-category-alist)
563 "Normative Category")
564 ((rassoc value unidata-informative-category-alist)
565 "Informative Category")
569 (setq attributes (delq 'general-category attributes))
571 (when (and (memq 'bidi-category attributes)
572 (setq value (get-char-attribute char 'bidi-category)))
573 (insert (format "(bidi-category\t. %S)%s"
576 (setq attributes (delq 'bidi-category attributes))
578 (unless (or (not (memq 'mirrored attributes))
579 (eq (setq value (get-char-attribute char 'mirrored 'empty))
581 (insert (format "(mirrored\t\t. %S)%s"
584 (setq attributes (delq 'mirrored attributes))
587 ((and (memq 'decimal-digit-value attributes)
588 (setq value (get-char-attribute char 'decimal-digit-value)))
589 (insert (format "(decimal-digit-value . %S)%s"
592 (setq attributes (delq 'decimal-digit-value attributes))
593 (when (and (memq 'digit-value attributes)
594 (setq value (get-char-attribute char 'digit-value)))
595 (insert (format "(digit-value\t . %S)%s"
598 (setq attributes (delq 'digit-value attributes))
600 (when (and (memq 'numeric-value attributes)
601 (setq value (get-char-attribute char 'numeric-value)))
602 (insert (format "(numeric-value\t . %S)%s"
605 (setq attributes (delq 'numeric-value attributes))
609 (when (and (memq 'digit-value attributes)
610 (setq value (get-char-attribute char 'digit-value)))
611 (insert (format "(digit-value\t. %S)%s"
614 (setq attributes (delq 'digit-value attributes))
616 (when (and (memq 'numeric-value attributes)
617 (setq value (get-char-attribute char 'numeric-value)))
618 (insert (format "(numeric-value\t. %S)%s"
621 (setq attributes (delq 'numeric-value attributes))
623 (when (and (memq 'iso-10646-comment attributes)
624 (setq value (get-char-attribute char 'iso-10646-comment)))
625 (insert (format "(iso-10646-comment\t. %S)%s"
628 (setq attributes (delq 'iso-10646-comment attributes))
630 (when (and (memq 'morohashi-daikanwa attributes)
631 (setq value (get-char-attribute char 'morohashi-daikanwa)))
632 (insert (format "(morohashi-daikanwa\t%s)%s"
633 (mapconcat (function prin1-to-string) value " ")
635 (setq attributes (delq 'morohashi-daikanwa attributes))
639 (when (and (memq 'ideographic-radical attributes)
640 (setq value (get-char-attribute char 'ideographic-radical)))
642 (insert (format "(ideographic-radical . %S)\t; %c%s"
644 (aref ideographic-radicals radical)
646 (setq attributes (delq 'ideographic-radical attributes))
648 (when (and (memq 'ideographic-strokes attributes)
649 (setq value (get-char-attribute char 'ideographic-strokes)))
651 (insert (format "(ideographic-strokes . %S)%s"
654 (setq attributes (delq 'ideographic-strokes attributes))
656 (when (and (memq 'kangxi-radical attributes)
657 (setq value (get-char-attribute char 'kangxi-radical)))
658 (unless (eq value radical)
659 (insert (format "(kangxi-radical\t . %S)\t; %c%s"
661 (aref ideographic-radicals value)
664 (setq radical value)))
665 (setq attributes (delq 'kangxi-radical attributes))
667 (when (and (memq 'kangxi-strokes attributes)
668 (setq value (get-char-attribute char 'kangxi-strokes)))
669 (unless (eq value strokes)
670 (insert (format "(kangxi-strokes\t . %S)%s"
674 (setq strokes value)))
675 (setq attributes (delq 'kangxi-strokes attributes))
677 (when (and (memq 'japanese-radical attributes)
678 (setq value (get-char-attribute char 'japanese-radical)))
679 (unless (eq value radical)
680 (insert (format "(japanese-radical\t . %S)\t; %c%s"
682 (aref ideographic-radicals value)
685 (setq radical value)))
686 (setq attributes (delq 'japanese-radical attributes))
688 (when (and (memq 'japanese-strokes attributes)
689 (setq value (get-char-attribute char 'japanese-strokes)))
690 (unless (eq value strokes)
691 (insert (format "(japanese-strokes\t . %S)%s"
695 (setq strokes value)))
696 (setq attributes (delq 'japanese-strokes attributes))
698 (when (and (memq 'cns-radical attributes)
699 (setq value (get-char-attribute char 'cns-radical)))
700 (insert (format "(cns-radical\t . %S)\t; %c%s"
702 (aref ideographic-radicals value)
704 (setq attributes (delq 'cns-radical attributes))
706 (when (and (memq 'cns-strokes attributes)
707 (setq value (get-char-attribute char 'cns-strokes)))
708 (unless (eq value strokes)
709 (insert (format "(cns-strokes\t . %S)%s"
713 (setq strokes value)))
714 (setq attributes (delq 'cns-strokes attributes))
716 (when (and (memq 'shinjigen-1-radical attributes)
717 (setq value (get-char-attribute char 'shinjigen-1-radical)))
718 (unless (eq value radical)
719 (insert (format "(shinjigen-1-radical . %S)\t; %c%s"
721 (aref ideographic-radicals value)
724 (setq radical value)))
725 (setq attributes (delq 'shinjigen-1-radical attributes))
727 (when (and (memq 'ideographic- attributes)
728 (setq value (get-char-attribute char 'ideographic-)))
729 (insert "(ideographic- ")
730 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
733 (setq cell (car value))
735 (setq cell (decode-char '=ucs cell)))
736 (cond ((characterp cell)
740 (insert (format "%S" cell))
741 (char-db-insert-char-spec cell readable))
742 (setq separator lbs))
746 (if (consp (car cell))
747 (char-db-insert-char-spec cell readable)
748 (char-db-insert-char-reference cell readable))
749 (setq separator lbs))
753 (insert (prin1-to-string cell))
754 (setq separator " ")))
755 (setq value (cdr value)))
757 (insert line-breaking)
758 (setq attributes (delq 'ideographic- attributes)))
759 (when (and (memq 'total-strokes attributes)
760 (setq value (get-char-attribute char 'total-strokes)))
761 (insert (format "(total-strokes . %S)%s"
764 (setq attributes (delq 'total-strokes attributes))
766 (when (and (memq '->ideograph attributes)
767 (setq value (get-char-attribute char '->ideograph)))
768 (insert (format "(->ideograph\t%s)%s"
769 (mapconcat (lambda (code)
770 (cond ((symbolp code)
773 (format "#x%04X" code))
776 line-breaking code))))
779 (setq attributes (delq '->ideograph attributes))
781 (when (and (memq '->decomposition attributes)
782 (setq value (get-char-attribute char '->decomposition)))
783 (insert (format "(->decomposition\t%s)%s"
784 (mapconcat (lambda (code)
785 (cond ((symbolp code)
794 (format "#x%04X" code))
796 (format "%s%S" line-breaking code))))
799 (setq attributes (delq '->decomposition attributes))
801 (if (equal (get-char-attribute char '->titlecase)
802 (get-char-attribute char '->uppercase))
803 (setq attributes (delq '->titlecase attributes)))
804 (when (and (memq '->mojikyo attributes)
805 (setq value (get-char-attribute char '->mojikyo)))
806 (insert (format "(->mojikyo\t\t. %06d)\t; %c%s"
807 value (decode-char 'mojikyo value)
809 (setq attributes (delq '->mojikyo attributes))
811 (when (and (memq 'hanyu-dazidian-vol attributes)
812 (setq value (get-char-attribute char 'hanyu-dazidian-vol)))
813 (insert (format "(hanyu-dazidian-vol . %d)%s"
814 value line-breaking))
815 (setq attributes (delq 'hanyu-dazidian-vol attributes))
817 (when (and (memq 'hanyu-dazidian-page attributes)
818 (setq value (get-char-attribute char 'hanyu-dazidian-page)))
819 (insert (format "(hanyu-dazidian-page . %d)%s"
820 value line-breaking))
821 (setq attributes (delq 'hanyu-dazidian-page attributes))
823 (when (and (memq 'hanyu-dazidian-char attributes)
824 (setq value (get-char-attribute char 'hanyu-dazidian-char)))
825 (insert (format "(hanyu-dazidian-char . %d)%s"
826 value line-breaking))
827 (setq attributes (delq 'hanyu-dazidian-char attributes))
829 (setq rest ccs-attributes)
832 (setq value (get-char-attribute char (car rest)))
834 (if (>= (length (symbol-name (car rest))) 19)
836 (setq has-long-ccs-name t)
840 (setq rest (cdr rest)))
842 (setq name (car attributes))
843 (if (setq value (get-char-attribute char name))
844 (cond ((eq name 'jisx0208-1978/4X)
845 (insert (format "(%-18s . #x%04X)%s"
848 ((or (eq name 'ideographic-structure)
849 (eq name 'ideographic-)
850 (string-match "^\\(->\\|<-\\)" (symbol-name name)))
851 (insert (format "(%-18s%s " name line-breaking))
852 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
855 (setq cell (car value))
857 (setq cell (decode-char '=ucs cell)))
858 (cond ((characterp cell)
862 (insert (format "%S" cell))
863 (char-db-insert-char-spec cell readable))
864 (setq separator lbs))
868 (if (consp (car cell))
869 (char-db-insert-char-spec cell readable)
870 (char-db-insert-char-reference cell readable))
871 (setq separator lbs))
875 (insert (prin1-to-string cell))
876 (setq separator " ")))
877 (setq value (cdr value)))
879 (insert line-breaking))
880 ((memq name '(ideograph=
881 original-ideograph-of
885 simplified-ideograph-of
887 ideographic-different-form-of))
888 (insert (format "(%-18s%s " name line-breaking))
889 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
892 (setq cell (car value))
893 (if (and (consp cell)
898 (char-db-insert-alist cell readable)
899 (setq separator lbs))
902 (insert (prin1-to-string cell))
903 (setq separator " "))
904 (setq value (cdr value)))
906 (insert line-breaking))
907 ;; ((string-match "^->" (symbol-name name))
909 ;; (format "(%-18s %s)%s"
911 ;; (mapconcat (lambda (code)
912 ;; (cond ((symbolp code)
913 ;; (symbol-name code))
915 ;; (format "#x%04X" code))
918 ;; line-breaking code))))
922 (insert (format "(%-18s " name))
923 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
926 (setq cell (car value))
927 (if (and (consp cell)
929 (setq ret (condition-case nil
937 (setq key (car (car rest)))
938 (if (find-charset key)
939 (setq cal (cons key cal))
940 (setq al (cons key al)))
941 (setq rest (cdr rest)))
944 (insert-char-attributes ret
947 (setq separator lbs))
950 (insert (prin1-to-string cell))
951 (setq separator " "))
952 (setq value (cdr value)))
954 (insert line-breaking))
956 (insert (format "(%-18s . %S)%s"
960 (setq attributes (cdr attributes)))
961 (while ccs-attributes
962 (setq name (car ccs-attributes))
963 (if (and (eq name (charset-name name))
964 (setq value (get-char-attribute char name)))
967 (cond ((memq name '(ideograph-daikanwa-2
970 (if has-long-ccs-name
971 "(%-26s . %05d)\t; %c%s"
972 "(%-18s . %05d)\t; %c%s"))
974 (if has-long-ccs-name
975 "(%-26s . %06d)\t; %c%s"
976 "(%-18s . %06d)\t; %c%s"))
977 ((>= (charset-dimension name) 2)
978 (if has-long-ccs-name
979 "(%-26s . #x%04X)\t; %c%s"
980 "(%-18s . #x%04X)\t; %c%s"))
982 (if has-long-ccs-name
983 "(%-26s . #x%02X)\t; %c%s"
984 "(%-18s . #x%02X)\t; %c%s")))
986 (if (= (charset-iso-graphic-plane name) 1)
988 (cond ((= (charset-dimension name) 1)
990 ((= (charset-dimension name) 2)
992 ((= (charset-dimension name) 3)
996 (char-db-decode-isolated-char name value)
998 (setq ccs-attributes (cdr ccs-attributes)))
1001 (defun insert-char-data (char &optional readable
1002 attributes ccs-attributes)
1004 (narrow-to-region (point)(point))
1005 (insert "(define-char
1007 (insert-char-attributes char readable
1008 attributes ccs-attributes)
1010 (goto-char (point-min))
1011 (while (re-search-forward "[ \t]+$" nil t)
1014 (goto-char (point-min))
1015 (while (re-search-forward "[ \t][ \t][ \t]*" nil t)
1016 (let ((column (current-column))
1017 (indent-tabs-mode t))
1018 (delete-region (match-beginning 0) (point))
1019 (indent-to column)))
1020 (goto-char (point-max))
1021 ;; (tabify (point-min)(point-max))
1024 (defun insert-char-data-with-variant (char &optional printable
1026 script excluded-script)
1027 (insert-char-data char printable)
1028 (let ((variants (or (char-variants char)
1029 (let ((ucs (get-char-attribute char '->ucs)))
1031 (delete char (char-variants (int-char ucs)))))))
1033 (setq variants (sort variants #'<))
1035 (setq variant (car variants))
1036 (if (and (or (null script)
1037 (null (setq vs (get-char-attribute variant 'script)))
1039 (or (null excluded-script)
1040 (null (setq vs (get-char-attribute variant 'script)))
1041 (not (memq excluded-script vs))))
1042 (or (and no-ucs-variant (get-char-attribute variant '=ucs))
1043 (insert-char-data variant printable)))
1044 (setq variants (cdr variants))
1047 (defun insert-char-range-data (min max &optional script excluded-script)
1050 (while (<= code max)
1051 (setq char (decode-char '=ucs code))
1052 (if (encode-char char '=ucs 'defined-only)
1053 (insert-char-data-with-variant char nil 'no-ucs-variant
1054 script excluded-script))
1055 (setq code (1+ code)))))
1057 (defun write-char-range-data-to-file (min max file
1058 &optional script excluded-script)
1059 (let ((coding-system-for-write 'utf-8))
1061 (insert-char-range-data min max script excluded-script)
1062 (write-region (point-min)(point-max) file))))
1064 (defvar what-character-original-window-configuration)
1067 (defun what-char-definition (char)
1068 (interactive (list (char-after)))
1069 (let ((buf (get-buffer-create "*Character Description*"))
1070 (the-buf (current-buffer))
1071 (win-conf (current-window-configuration)))
1073 (make-local-variable 'what-character-original-window-configuration)
1074 (setq what-character-original-window-configuration win-conf)
1075 (setq buffer-read-only nil)
1079 (insert-char-data-with-variant char 'printable)
1080 (unless (char-attribute-alist char)
1081 (insert (format ";; = %c\n"
1082 (let* ((rest (split-char char))
1086 (setq code (logior (lsh code 8)
1088 (decode-char ccs code)))))
1089 ;; (char-db-update-comment)
1090 (set-buffer-modified-p nil)
1091 (view-mode the-buf (lambda (buf)
1092 (set-window-configuration
1093 what-character-original-window-configuration)
1095 (goto-char (point-min)))
1097 (set-window-configuration
1098 what-character-original-window-configuration)
1099 (signal (car err) (cdr err)))))))
1101 (provide 'char-db-util)
1103 ;;; char-db-util.el ends here