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)
74 (defun char-attribute-name< (ka kb)
80 ((= (charset-dimension ka)
81 (charset-dimension kb))
82 (cond ((= (charset-chars ka)(charset-chars kb))
83 (if (charset-iso-final-char ka)
85 ((>= (charset-iso-final-char ka) ?@)
86 (if (and (charset-iso-final-char kb)
87 (>= (charset-iso-final-char kb) ?@))
88 (< (charset-iso-final-char ka)
89 (charset-iso-final-char kb))
92 (if (charset-iso-final-char kb)
93 (if (>= (charset-iso-final-char kb) ?@)
95 (< (charset-iso-final-char ka)
96 (charset-iso-final-char kb)))
98 (if (charset-iso-final-char kb)
100 (< (charset-id ka)(charset-id kb)))))
101 ((<= (charset-chars ka)(charset-chars kb)))))
103 (< (charset-dimension ka)
104 (charset-dimension kb))
114 (string< (symbol-name ka)
120 (defvar char-db-coded-charset-priority-list
135 japanese-jisx0208-1978
177 (defun char-db-make-char-spec (char)
179 (cond ((characterp char)
180 (cond ((and (setq ret (encode-char char '=ucs 'defined-only))
181 (not (and (<= #xE000 ret)(<= ret #xF8FF))))
182 (setq char-spec (list (cons '=ucs ret)))
183 (cond ((setq ret (get-char-attribute char 'name))
184 (setq char-spec (cons (cons 'name ret) char-spec))
186 ((setq ret (get-char-attribute char 'name*))
187 (setq char-spec (cons (cons 'name* ret) char-spec))
192 (let ((rest char-db-coded-charset-priority-list))
195 (get-char-attribute char (car rest)))
196 (throw 'tag (cons (car rest) ret)))
197 (setq rest (cdr rest))))))
198 (setq char-spec (list ret))
199 (dolist (ccs (delq (car ret) (charset-list)))
200 (if (and (or (charset-iso-final-char ccs)
206 (setq ret (get-char-attribute char ccs)))
207 (setq char-spec (cons (cons ccs ret) char-spec))))
209 (setq char-spec (split-char char)))
210 (cond ((setq ret (get-char-attribute char 'name))
211 (setq char-spec (cons (cons 'name ret) char-spec))
213 ((setq ret (get-char-attribute char 'name*))
214 (setq char-spec (cons (cons 'name* ret) char-spec))
221 (defun char-db-insert-char-spec (char &optional readable column)
223 (setq column (current-column)))
224 (let (char-spec ret al cal key temp-char)
225 (setq char-spec (char-db-make-char-spec char))
226 (unless (or (characterp char) ; char
228 (setq char (find-char char-spec))
230 ;; define temporary character
231 ;; Current implementation is dirty.
232 (setq temp-char (define-char (cons '(ideograph-daikanwa . 0)
234 (remove-char-attribute temp-char 'ideograph-daikanwa)
235 (setq char temp-char))
239 (setq key (car (car char-spec)))
240 (unless (memq key char-db-ignored-attributes)
241 (if (find-charset key)
242 (if (get-char-attribute char key)
243 (setq cal (cons key cal)))
244 (setq al (cons key al))))
245 (setq char-spec (cdr char-spec)))
247 (setq char-spec (char-db-make-char-spec char))
249 (setq key (car (car char-spec)))
250 (unless (memq key char-db-ignored-attributes)
251 (if (find-charset key)
252 (setq cal (cons key cal))
253 (setq al (cons key al))))
254 (setq char-spec (cdr char-spec)))
257 (memq 'ideographic-structure al))
258 (push 'ideographic-structure al))
259 (insert-char-attributes char
263 ;; undefine temporary character
264 ;; Current implementation is dirty.
265 (setq char-spec (char-attribute-alist temp-char))
267 (remove-char-attribute temp-char (car (car char-spec)))
268 (setq char-spec (cdr char-spec))))))
270 (defun char-db-insert-alist (alist &optional readable column)
272 (setq column (current-column)))
274 (concat "\n" (make-string (1+ column) ?\ )))
277 lbs cell rest separator)
280 (setq name (car (car alist))
281 value (cdr (car alist)))
282 (cond ((eq name 'char)
284 (if (setq ret (condition-case nil
291 (setq key (car (car value)))
292 (if (find-charset key)
293 (setq cal (cons key cal))
294 (setq al (cons key al)))
295 (setq value (cdr value)))
296 (insert-char-attributes ret
299 (insert (prin1-to-string value)))
301 (insert line-breaking))
303 (insert (format "(%-18s " name))
304 (setq lbs (concat "\n" (make-string (current-column) ?\ )))
306 (setq cell (car value))
307 (if (and (consp cell)
309 (setq ret (condition-case nil
318 (setq key (car (car rest)))
319 (if (find-charset key)
320 (setq cal (cons key cal))
321 (setq al (cons key al)))
322 (setq rest (cdr rest)))
325 (insert-char-attributes ret
328 (setq separator lbs))
331 (insert (prin1-to-string cell))
332 (setq separator " "))
333 (setq value (cdr value)))
335 (insert line-breaking))
337 (insert (format "(%-18s . %S)%s"
340 (setq alist (cdr alist))))
343 (defun char-db-insert-char-reference (plist &optional readable column)
345 (setq column (current-column)))
347 (concat "\n" (make-string (1+ column) ?\ )))
352 (setq name (pop plist))
353 (setq value (pop plist))
354 (cond ((eq name :char)
357 (cond ((numberp value)
358 (setq value (decode-char '=ucs value)))
360 ;; (setq value (or (find-char value)
363 (char-db-insert-char-spec value readable)
364 (insert line-breaking)
367 (insert (format "%s%s\t%d ; %c%s"
370 (aref ideographic-radicals value)
374 (insert (format "%s%s\t%S" separator name value))
375 (setq separator line-breaking)))
379 (defun char-db-decode-isolated-char (ccs code-point)
382 (cond ((eq ccs 'arabic-iso8859-6)
383 (decode-char ccs code-point))
384 ((and (memq ccs '(=gt-pj-1
395 (setq ret (decode-char ccs code-point))
396 (setq ret (get-char-attribute ret '=gt)))
397 (decode-builtin-char '=gt ret))
399 (decode-builtin-char ccs code-point))))
400 (cond ((and (<= 0 (char-int ret))
401 (<= (char-int ret) #x1F))
402 (decode-char '=ucs (+ #x2400 (char-int ret))))
403 ((= (char-int ret) #x7F)
407 (defvar char-db-convert-obsolete-format t)
409 (defun insert-char-attributes (char &optional readable
410 attributes ccs-attributes
415 (if (consp attributes)
417 (dolist (name attributes)
418 (unless (memq name char-db-ignored-attributes)
421 (dolist (name (char-attribute-list))
422 (unless (memq name char-db-ignored-attributes)
423 (if (find-charset name)
427 #'char-attribute-name<))
429 (sort (if ccs-attributes
432 (dolist (name ccs-attributes)
433 (unless (memq name char-db-ignored-attributes)
438 (dolist (name (charset-list))
439 (unless (memq name char-db-ignored-attributes)
442 #'char-attribute-name<)))
444 (setq column (current-column)))
445 (let (name value has-long-ccs-name rest
448 (concat "\n" (make-string (1+ column) ?\ )))
449 lbs cell separator ret
452 (when (and (memq 'name attributes)
453 (setq value (get-char-attribute char 'name)))
455 (if (> (+ (current-column) (length value)) 48)
458 value line-breaking))
459 (setq attributes (delq 'name attributes))
461 (when (and (memq 'name* attributes)
462 (setq value (get-char-attribute char 'name*)))
464 (if (> (+ (current-column) (length value)) 48)
467 value line-breaking))
468 (setq attributes (delq 'name* attributes))
470 (when (and (memq 'script attributes)
471 (setq value (get-char-attribute char 'script)))
472 (insert (format "(script\t\t%s)%s"
473 (mapconcat (function prin1-to-string)
476 (setq attributes (delq 'script attributes))
478 (dolist (name '(=>ucs =>ucs*))
479 (when (and (memq name attributes)
480 (setq value (get-char-attribute char name)))
481 (insert (format "(%-18s . #x%04X)\t; %c%s"
482 name value (decode-char '=ucs value)
484 (setq attributes (delq name attributes))))
485 ;; (when (and (memq '=>ucs* attributes)
486 ;; (setq value (get-char-attribute char '=>ucs*)))
487 ;; (insert (format "(=>ucs*\t\t. #x%04X)\t; %c%s"
488 ;; value (decode-char '=ucs value)
490 ;; (setq attributes (delq '=>ucs* attributes))
492 (dolist (name '(=>ucs@gb =>ucs@cns =>ucs@jis))
493 (when (and (memq name attributes)
494 (setq value (get-char-attribute char name)))
495 (insert (format "(%-18s . #x%04X)\t; %c%s"
500 (symbol-name name) 2)))
503 (setq attributes (delq name attributes))
505 (when (and (memq '=>ucs-gb attributes)
506 (setq value (get-char-attribute char '=>ucs-gb)))
507 (insert (format "(=>ucs@gb\t\t. #x%04X)\t; %c%s"
508 value (decode-char '=ucs@gb value)
510 (setq attributes (delq '=>ucs-gb attributes))
512 (when (and (memq '=>ucs-cns attributes)
513 (setq value (get-char-attribute char '=>ucs-cns)))
514 (insert (format "(=>ucs@cns\t\t. #x%04X)\t; %c%s"
515 value (decode-char '=ucs@cns value)
517 (setq attributes (delq '=>ucs-cns attributes))
519 (when (and (memq '=>ucs-big5 attributes)
520 (setq value (get-char-attribute char '=>ucs-big5)))
521 (insert (format "(=>ucs-big5\t\t. #x%04X)\t; %c%s"
522 value (decode-char 'ucs-big5 value)
524 (setq attributes (delq '=>ucs-big5 attributes))
526 (when (and (memq '=>ucs-jis attributes)
527 (setq value (get-char-attribute char '=>ucs-jis)))
528 (insert (format "(=>ucs@jis\t\t. #x%04X)\t; %c%s"
529 value (decode-char '=ucs@jis value)
531 (setq attributes (delq '=>ucs-jis attributes))
533 (when (and (memq '=>ucs-ks attributes)
534 (setq value (get-char-attribute char '=>ucs-ks)))
535 (insert (format "(=>ucs-ks\t\t. #x%04X)\t; %c%s"
536 value (decode-char 'ucs-ks value)
538 (setq attributes (delq '=>ucs-ks attributes))
540 (when (and (memq '->ucs attributes)
541 (setq value (get-char-attribute char '->ucs)))
542 (insert (format (if char-db-convert-obsolete-format
543 "(=>ucs\t\t. #x%04X)\t; %c%s"
544 "(->ucs\t\t. #x%04X)\t; %c%s")
545 value (decode-char '=ucs value)
547 (setq attributes (delq '->ucs attributes))
549 (when (and (memq 'general-category attributes)
550 (setq value (get-char-attribute char 'general-category)))
552 "(general-category\t%s) ; %s%s"
553 (mapconcat (lambda (cell)
556 (cond ((rassoc value unidata-normative-category-alist)
557 "Normative Category")
558 ((rassoc value unidata-informative-category-alist)
559 "Informative Category")
563 (setq attributes (delq 'general-category attributes))
565 (when (and (memq 'bidi-category attributes)
566 (setq value (get-char-attribute char 'bidi-category)))
567 (insert (format "(bidi-category\t. %S)%s"
570 (setq attributes (delq 'bidi-category attributes))
572 (unless (or (not (memq 'mirrored attributes))
573 (eq (setq value (get-char-attribute char 'mirrored 'empty))
575 (insert (format "(mirrored\t\t. %S)%s"
578 (setq attributes (delq 'mirrored attributes))
581 ((and (memq 'decimal-digit-value attributes)
582 (setq value (get-char-attribute char 'decimal-digit-value)))
583 (insert (format "(decimal-digit-value . %S)%s"
586 (setq attributes (delq 'decimal-digit-value attributes))
587 (when (and (memq 'digit-value attributes)
588 (setq value (get-char-attribute char 'digit-value)))
589 (insert (format "(digit-value\t . %S)%s"
592 (setq attributes (delq 'digit-value attributes))
594 (when (and (memq 'numeric-value attributes)
595 (setq value (get-char-attribute char 'numeric-value)))
596 (insert (format "(numeric-value\t . %S)%s"
599 (setq attributes (delq 'numeric-value attributes))
603 (when (and (memq 'digit-value attributes)
604 (setq value (get-char-attribute char 'digit-value)))
605 (insert (format "(digit-value\t. %S)%s"
608 (setq attributes (delq 'digit-value attributes))
610 (when (and (memq 'numeric-value attributes)
611 (setq value (get-char-attribute char 'numeric-value)))
612 (insert (format "(numeric-value\t. %S)%s"
615 (setq attributes (delq 'numeric-value attributes))
617 (when (and (memq 'iso-10646-comment attributes)
618 (setq value (get-char-attribute char 'iso-10646-comment)))
619 (insert (format "(iso-10646-comment\t. %S)%s"
622 (setq attributes (delq 'iso-10646-comment attributes))
624 (when (and (memq 'morohashi-daikanwa attributes)
625 (setq value (get-char-attribute char 'morohashi-daikanwa)))
626 (insert (format "(morohashi-daikanwa\t%s)%s"
627 (mapconcat (function prin1-to-string) value " ")
629 (setq attributes (delq 'morohashi-daikanwa attributes))
633 (when (and (memq 'ideographic-radical attributes)
634 (setq value (get-char-attribute char 'ideographic-radical)))
636 (insert (format "(ideographic-radical . %S)\t; %c%s"
638 (aref ideographic-radicals radical)
640 (setq attributes (delq 'ideographic-radical attributes))
642 (when (and (memq 'ideographic-strokes attributes)
643 (setq value (get-char-attribute char 'ideographic-strokes)))
645 (insert (format "(ideographic-strokes . %S)%s"
648 (setq attributes (delq 'ideographic-strokes attributes))
650 (when (and (memq 'kangxi-radical attributes)
651 (setq value (get-char-attribute char 'kangxi-radical)))
652 (unless (eq value radical)
653 (insert (format "(kangxi-radical\t . %S)\t; %c%s"
655 (aref ideographic-radicals value)
658 (setq radical value)))
659 (setq attributes (delq 'kangxi-radical attributes))
661 (when (and (memq 'kangxi-strokes attributes)
662 (setq value (get-char-attribute char 'kangxi-strokes)))
663 (unless (eq value strokes)
664 (insert (format "(kangxi-strokes\t . %S)%s"
668 (setq strokes value)))
669 (setq attributes (delq 'kangxi-strokes attributes))
671 (when (and (memq 'japanese-radical attributes)
672 (setq value (get-char-attribute char 'japanese-radical)))
673 (unless (eq value radical)
674 (insert (format "(japanese-radical\t . %S)\t; %c%s"
676 (aref ideographic-radicals value)
679 (setq radical value)))
680 (setq attributes (delq 'japanese-radical attributes))
682 (when (and (memq 'japanese-strokes attributes)
683 (setq value (get-char-attribute char 'japanese-strokes)))
684 (unless (eq value strokes)
685 (insert (format "(japanese-strokes\t . %S)%s"
689 (setq strokes value)))
690 (setq attributes (delq 'japanese-strokes attributes))
692 (when (and (memq 'cns-radical attributes)
693 (setq value (get-char-attribute char 'cns-radical)))
694 (insert (format "(cns-radical\t . %S)\t; %c%s"
696 (aref ideographic-radicals value)
698 (setq attributes (delq 'cns-radical attributes))
700 (when (and (memq 'cns-strokes attributes)
701 (setq value (get-char-attribute char 'cns-strokes)))
702 (unless (eq value strokes)
703 (insert (format "(cns-strokes\t . %S)%s"
707 (setq strokes value)))
708 (setq attributes (delq 'cns-strokes attributes))
710 (when (and (memq 'shinjigen-1-radical attributes)
711 (setq value (get-char-attribute char 'shinjigen-1-radical)))
712 (unless (eq value radical)
713 (insert (format "(shinjigen-1-radical . %S)\t; %c%s"
715 (aref ideographic-radicals value)
718 (setq radical value)))
719 (setq attributes (delq 'shinjigen-1-radical attributes))
721 (when (and (memq 'ideographic- attributes)
722 (setq value (get-char-attribute char 'ideographic-)))
723 (insert "(ideographic- ")
724 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
727 (setq cell (car value))
729 (setq cell (decode-char '=ucs cell)))
730 (cond ((characterp cell)
734 (insert (format "%S" cell))
735 (char-db-insert-char-spec cell readable))
736 (setq separator lbs))
740 (if (consp (car cell))
741 (char-db-insert-char-spec cell readable)
742 (char-db-insert-char-reference cell readable))
743 (setq separator lbs))
747 (insert (prin1-to-string cell))
748 (setq separator " ")))
749 (setq value (cdr value)))
751 (insert line-breaking)
752 (setq attributes (delq 'ideographic- attributes)))
753 (when (and (memq 'total-strokes attributes)
754 (setq value (get-char-attribute char 'total-strokes)))
755 (insert (format "(total-strokes . %S)%s"
758 (setq attributes (delq 'total-strokes attributes))
760 (when (and (memq '->ideograph attributes)
761 (setq value (get-char-attribute char '->ideograph)))
762 (insert (format "(->ideograph\t%s)%s"
763 (mapconcat (lambda (code)
764 (cond ((symbolp code)
767 (format "#x%04X" code))
770 line-breaking code))))
773 (setq attributes (delq '->ideograph attributes))
775 (when (and (memq '->decomposition attributes)
776 (setq value (get-char-attribute char '->decomposition)))
777 (insert (format "(->decomposition\t%s)%s"
778 (mapconcat (lambda (code)
779 (cond ((symbolp code)
788 (format "#x%04X" code))
790 (format "%s%S" line-breaking code))))
793 (setq attributes (delq '->decomposition attributes))
795 (if (equal (get-char-attribute char '->titlecase)
796 (get-char-attribute char '->uppercase))
797 (setq attributes (delq '->titlecase attributes)))
798 (when (and (memq '->mojikyo attributes)
799 (setq value (get-char-attribute char '->mojikyo)))
800 (insert (format "(->mojikyo\t\t. %06d)\t; %c%s"
801 value (decode-char 'mojikyo value)
803 (setq attributes (delq '->mojikyo attributes))
805 (when (and (memq 'hanyu-dazidian-vol attributes)
806 (setq value (get-char-attribute char 'hanyu-dazidian-vol)))
807 (insert (format "(hanyu-dazidian-vol . %d)%s"
808 value line-breaking))
809 (setq attributes (delq 'hanyu-dazidian-vol attributes))
811 (when (and (memq 'hanyu-dazidian-page attributes)
812 (setq value (get-char-attribute char 'hanyu-dazidian-page)))
813 (insert (format "(hanyu-dazidian-page . %d)%s"
814 value line-breaking))
815 (setq attributes (delq 'hanyu-dazidian-page attributes))
817 (when (and (memq 'hanyu-dazidian-char attributes)
818 (setq value (get-char-attribute char 'hanyu-dazidian-char)))
819 (insert (format "(hanyu-dazidian-char . %d)%s"
820 value line-breaking))
821 (setq attributes (delq 'hanyu-dazidian-char attributes))
824 (when (memq '->ucs-variants attributes)
825 (setq attributes (delq '->ucs-variants attributes))
827 (when (memq 'composition attributes)
828 (setq attributes (delq 'composition attributes))
830 (setq rest ccs-attributes)
833 (setq value (get-char-attribute char (car rest)))
835 (if (>= (length (symbol-name (car rest))) 19)
837 (setq has-long-ccs-name t)
841 (setq rest (cdr rest)))
843 (setq name (car attributes))
844 (if (setq value (get-char-attribute char name))
845 (cond ((string-match "^=>ucs@" (symbol-name name))
846 (insert (format "(%-18s . #x%04X)\t; %c%s"
847 name value (decode-char '=ucs value)
850 ((eq name 'jisx0208-1978/4X)
851 (insert (format "(%-18s . #x%04X)%s"
854 ((or (eq name 'ideographic-structure)
855 (eq name 'ideographic-)
856 (string-match "^\\(->\\|<-\\)" (symbol-name name)))
857 (insert (format "(%-18s%s " name line-breaking))
858 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
861 (setq cell (car value))
863 (setq cell (decode-char '=ucs cell)))
864 (cond ((characterp cell)
868 (insert (format "%S" cell))
869 (char-db-insert-char-spec cell readable))
870 (setq separator lbs))
874 (if (consp (car cell))
875 (char-db-insert-char-spec cell readable)
876 (char-db-insert-char-reference cell readable))
877 (setq separator lbs))
881 (insert (prin1-to-string cell))
882 (setq separator " ")))
883 (setq value (cdr value)))
885 (insert line-breaking))
886 ((memq name '(ideograph=
887 original-ideograph-of
891 simplified-ideograph-of
893 ideographic-different-form-of))
894 (insert (format "(%-18s%s " name line-breaking))
895 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
898 (setq cell (car value))
899 (if (and (consp cell)
904 (char-db-insert-alist cell readable)
905 (setq separator lbs))
908 (insert (prin1-to-string cell))
909 (setq separator " "))
910 (setq value (cdr value)))
912 (insert line-breaking))
913 ;; ((string-match "^->" (symbol-name name))
915 ;; (format "(%-18s %s)%s"
917 ;; (mapconcat (lambda (code)
918 ;; (cond ((symbolp code)
919 ;; (symbol-name code))
921 ;; (format "#x%04X" code))
924 ;; line-breaking code))))
928 (insert (format "(%-18s " name))
929 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
932 (setq cell (car value))
933 (if (and (consp cell)
935 (setq ret (condition-case nil
943 (setq key (car (car rest)))
944 (if (find-charset key)
945 (setq cal (cons key cal))
946 (setq al (cons key al)))
947 (setq rest (cdr rest)))
950 (insert-char-attributes ret
953 (setq separator lbs))
956 (insert (prin1-to-string cell))
957 (setq separator " "))
958 (setq value (cdr value)))
960 (insert line-breaking))
962 (insert (format "(%-18s . %S)%s"
966 (setq attributes (cdr attributes)))
967 (while ccs-attributes
968 (setq name (car ccs-attributes))
969 (if (and (eq name (charset-name name))
970 (setq value (get-char-attribute char name)))
973 (cond ((memq name '(ideograph-daikanwa
977 (if has-long-ccs-name
978 "(%-26s . %05d)\t; %c%s"
979 "(%-18s . %05d)\t; %c%s"))
981 (if has-long-ccs-name
982 "(%-26s . %06d)\t; %c%s"
983 "(%-18s . %06d)\t; %c%s"))
984 ((>= (charset-dimension name) 2)
985 (if has-long-ccs-name
986 "(%-26s . #x%04X)\t; %c%s"
987 "(%-18s . #x%04X)\t; %c%s"))
989 (if has-long-ccs-name
990 "(%-26s . #x%02X)\t; %c%s"
991 "(%-18s . #x%02X)\t; %c%s")))
993 (if (= (charset-iso-graphic-plane name) 1)
995 (cond ((= (charset-dimension name) 1)
997 ((= (charset-dimension name) 2)
999 ((= (charset-dimension name) 3)
1003 (char-db-decode-isolated-char name value)
1005 (setq ccs-attributes (cdr ccs-attributes)))
1008 (defun insert-char-data (char &optional readable
1009 attributes ccs-attributes)
1011 (narrow-to-region (point)(point))
1012 (insert "(define-char
1014 (insert-char-attributes char readable
1015 attributes ccs-attributes)
1017 (goto-char (point-min))
1018 (while (re-search-forward "[ \t]+$" nil t)
1021 (goto-char (point-min))
1022 (while (re-search-forward "[ \t][ \t][ \t]*" nil t)
1023 (let ((column (current-column))
1024 (indent-tabs-mode t))
1025 (delete-region (match-beginning 0) (point))
1026 (indent-to column)))
1027 (goto-char (point-max))
1028 ;; (tabify (point-min)(point-max))
1031 (defun insert-char-data-with-variant (char &optional printable
1033 script excluded-script)
1034 (insert-char-data char printable)
1035 (let ((variants (or (char-variants char)
1036 (let ((ucs (get-char-attribute char '->ucs)))
1038 (delete char (char-variants (int-char ucs)))))))
1040 (setq variants (sort variants #'<))
1042 (setq variant (car variants))
1043 (if (and (or (null script)
1044 (null (setq vs (get-char-attribute variant 'script)))
1046 (or (null excluded-script)
1047 (null (setq vs (get-char-attribute variant 'script)))
1048 (not (memq excluded-script vs))))
1049 (or (and no-ucs-variant (get-char-attribute variant '=ucs))
1050 (insert-char-data variant printable)))
1051 (setq variants (cdr variants))
1054 (defun insert-char-range-data (min max &optional script excluded-script)
1057 (while (<= code max)
1058 (setq char (decode-char '=ucs code))
1059 (if (encode-char char '=ucs 'defined-only)
1060 (insert-char-data-with-variant char nil 'no-ucs-variant
1061 script excluded-script))
1062 (setq code (1+ code)))))
1064 (defun write-char-range-data-to-file (min max file
1065 &optional script excluded-script)
1066 (let ((coding-system-for-write 'utf-8))
1068 (insert-char-range-data min max script excluded-script)
1069 (write-region (point-min)(point-max) file))))
1071 (defvar what-character-original-window-configuration)
1074 (defun what-char-definition (char)
1075 (interactive (list (char-after)))
1076 (let ((buf (get-buffer-create "*Character Description*"))
1077 (the-buf (current-buffer))
1078 (win-conf (current-window-configuration)))
1080 (make-local-variable 'what-character-original-window-configuration)
1081 (setq what-character-original-window-configuration win-conf)
1082 (setq buffer-read-only nil)
1086 (insert-char-data-with-variant char 'printable)
1087 (unless (char-attribute-alist char)
1088 (insert (format ";; = %c\n"
1089 (let* ((rest (split-char char))
1093 (setq code (logior (lsh code 8)
1095 (decode-char ccs code)))))
1096 ;; (char-db-update-comment)
1097 (set-buffer-modified-p nil)
1098 (view-mode the-buf (lambda (buf)
1099 (set-window-configuration
1100 what-character-original-window-configuration)
1102 (goto-char (point-min)))
1104 (set-window-configuration
1105 what-character-original-window-configuration)
1106 (signal (car err) (cdr err)))))))
1108 (provide 'char-db-util)
1110 ;;; char-db-util.el ends here