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
199 (defun char-db-make-char-spec (char)
201 (cond ((characterp char)
202 (cond ((and (setq ret (encode-char char '=ucs 'defined-only))
203 (not (and (<= #xE000 ret)(<= ret #xF8FF))))
204 (setq char-spec (list (cons '=ucs ret)))
205 (cond ((setq ret (get-char-attribute char 'name))
206 (setq char-spec (cons (cons 'name ret) char-spec))
208 ((setq ret (get-char-attribute char 'name*))
209 (setq char-spec (cons (cons 'name* ret) char-spec))
214 (let ((rest char-db-coded-charset-priority-list)
217 (setq ccs (charset-name
218 (find-charset (car rest))))
220 (encode-char char ccs
222 (throw 'tag (cons ccs ret)))
223 (setq rest (cdr rest))))))
224 (setq char-spec (list ret))
225 (dolist (ccs (delq (car ret) (charset-list)))
226 (if (and (or (charset-iso-final-char ccs)
232 (setq ret (encode-char char ccs 'defined-only)))
233 (setq char-spec (cons (cons ccs ret) char-spec))))
235 (setq char-spec (split-char char)))
236 (cond ((setq ret (get-char-attribute char 'name))
237 (setq char-spec (cons (cons 'name ret) char-spec))
239 ((setq ret (get-char-attribute char 'name*))
240 (setq char-spec (cons (cons 'name* ret) char-spec))
247 (defun char-db-insert-char-spec (char &optional readable column)
249 (setq column (current-column)))
250 (let (char-spec ret al cal key temp-char)
251 (setq char-spec (char-db-make-char-spec char))
252 (unless (or (characterp char) ; char
254 (setq char (find-char char-spec))
256 ;; define temporary character
257 ;; Current implementation is dirty.
258 (setq temp-char (define-char (cons '(ideograph-daikanwa . 0)
260 (remove-char-attribute temp-char 'ideograph-daikanwa)
261 (setq char temp-char))
265 (setq key (car (car char-spec)))
266 (unless (memq key char-db-ignored-attributes)
267 (if (find-charset key)
268 (if (encode-char char key 'defined-only)
269 (setq cal (cons key cal)))
270 (setq al (cons key al))))
271 (setq char-spec (cdr char-spec)))
273 (setq char-spec (char-db-make-char-spec char))
275 (setq key (car (car char-spec)))
276 (unless (memq key char-db-ignored-attributes)
277 (if (find-charset key)
278 (setq cal (cons key cal))
279 (setq al (cons key al))))
280 (setq char-spec (cdr char-spec)))
283 (memq 'ideographic-structure al))
284 (push 'ideographic-structure al))
285 (insert-char-attributes char
289 ;; undefine temporary character
290 ;; Current implementation is dirty.
291 (setq char-spec (char-attribute-alist temp-char))
293 (remove-char-attribute temp-char (car (car char-spec)))
294 (setq char-spec (cdr char-spec))))))
296 (defun char-db-insert-alist (alist &optional readable column)
298 (setq column (current-column)))
300 (concat "\n" (make-string (1+ column) ?\ )))
303 lbs cell rest separator)
306 (setq name (car (car alist))
307 value (cdr (car alist)))
308 (cond ((eq name 'char)
310 (if (setq ret (condition-case nil
317 (setq key (car (car value)))
318 (if (find-charset key)
319 (setq cal (cons key cal))
320 (setq al (cons key al)))
321 (setq value (cdr value)))
322 (insert-char-attributes ret
325 (insert (prin1-to-string value)))
327 (insert line-breaking))
329 (insert (format "(%-18s " name))
330 (setq lbs (concat "\n" (make-string (current-column) ?\ )))
332 (setq cell (car value))
333 (if (and (consp cell)
335 (setq ret (condition-case nil
344 (setq key (car (car rest)))
345 (if (find-charset key)
346 (setq cal (cons key cal))
347 (setq al (cons key al)))
348 (setq rest (cdr rest)))
351 (insert-char-attributes ret
354 (setq separator lbs))
357 (insert (prin1-to-string cell))
358 (setq separator " "))
359 (setq value (cdr value)))
361 (insert line-breaking))
363 (insert (format "(%-18s . %S)%s"
366 (setq alist (cdr alist))))
369 (defun char-db-insert-char-reference (plist &optional readable column)
371 (setq column (current-column)))
373 (concat "\n" (make-string (1+ column) ?\ )))
378 (setq name (pop plist))
379 (setq value (pop plist))
380 (cond ((eq name :char)
383 (cond ((numberp value)
384 (setq value (decode-char '=ucs value)))
386 ;; (setq value (or (find-char value)
389 (char-db-insert-char-spec value readable)
390 (insert line-breaking)
393 (insert (format "%s%s\t%d ; %c%s"
396 (aref ideographic-radicals value)
400 (insert (format "%s%s\t%S" separator name value))
401 (setq separator line-breaking)))
405 (defun char-db-decode-isolated-char (ccs code-point)
408 (cond ((eq ccs 'arabic-iso8859-6)
409 (decode-char ccs code-point))
410 ((and (memq ccs '(=gt-pj-1
421 (setq ret (decode-char ccs code-point))
422 (setq ret (encode-char ret '=gt 'defined-only)))
423 (decode-builtin-char '=gt ret))
425 (decode-builtin-char ccs code-point))))
426 (cond ((and (<= 0 (char-int ret))
427 (<= (char-int ret) #x1F))
428 (decode-char '=ucs (+ #x2400 (char-int ret))))
429 ((= (char-int ret) #x7F)
433 (defvar char-db-convert-obsolete-format t)
435 (defun insert-char-attributes (char &optional readable
436 attributes ccs-attributes
441 (if (consp attributes)
443 (dolist (name attributes)
444 (unless (memq name char-db-ignored-attributes)
447 (dolist (name (char-attribute-list))
448 (unless (memq name char-db-ignored-attributes)
449 (if (find-charset name)
453 #'char-attribute-name<))
455 (sort (if ccs-attributes
458 (dolist (name ccs-attributes)
459 (unless (memq name char-db-ignored-attributes)
464 (dolist (name (charset-list))
465 (unless (memq name char-db-ignored-attributes)
468 #'char-attribute-name<)))
470 (setq column (current-column)))
471 (let (name value has-long-ccs-name rest
474 (concat "\n" (make-string (1+ column) ?\ )))
475 lbs cell separator ret
479 (when (and (memq 'name attributes)
480 (setq value (get-char-attribute char 'name)))
482 (if (> (+ (current-column) (length value)) 48)
485 value line-breaking))
486 (setq attributes (delq 'name attributes))
488 (when (and (memq 'name* attributes)
489 (setq value (get-char-attribute char 'name*)))
491 (if (> (+ (current-column) (length value)) 48)
494 value line-breaking))
495 (setq attributes (delq 'name* attributes))
497 (when (and (memq 'script attributes)
498 (setq value (get-char-attribute char 'script)))
499 (insert (format "(script\t\t%s)%s"
500 (mapconcat (function prin1-to-string)
503 (setq attributes (delq 'script attributes))
505 (dolist (name '(=>ucs =>ucs*))
506 (when (and (memq name attributes)
507 (setq value (get-char-attribute char name)))
508 (insert (format "(%-18s . #x%04X)\t; %c%s"
509 name value (decode-char '=ucs value)
511 (setq attributes (delq name attributes))))
512 (dolist (name '(=>ucs@gb =>ucs@cns =>ucs@jis =>ucs@ks =>ucs@big5))
513 (when (and (memq name attributes)
514 (setq value (get-char-attribute char name)))
515 (insert (format "(%-18s . #x%04X)\t; %c%s"
520 (symbol-name name) 2)))
523 (setq attributes (delq name attributes))
525 (dolist (name '(=>ucs-gb =>ucs-cns =>ucs-jis =>ucs-ks =>ucs-big5))
526 (when (and (memq name attributes)
527 (setq value (get-char-attribute char name)))
528 (insert (format "(%-18s . #x%04X)\t; %c%s"
531 (substring (symbol-name name) 6)))
536 (symbol-name name) 6)))
539 (setq attributes (delq name 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))
634 (dolist (domain '(ucs daikanwa cns))
635 (setq key (intern (format "%s@%s" 'ideographic-radical domain)))
636 (when (and (memq key attributes)
637 (setq value (get-char-attribute char key)))
639 (insert (format "(%s . %S)\t; %c%s"
642 (aref ideographic-radicals radical)
644 (setq attributes (delq key attributes))
646 (setq key (intern (format "%s@%s" 'ideographic-strokes domain)))
647 (when (and (memq key attributes)
648 (setq value (get-char-attribute char key)))
650 (insert (format "(%s . %S)%s"
654 (setq attributes (delq key attributes))
656 (setq key (intern (format "%s@%s*sources"
657 'ideographic-radical domain)))
658 (when (and (memq key attributes)
659 (setq value (get-char-attribute char key)))
660 (insert (format "(%s%s" key line-breaking))
662 (insert (format " %s" cell)))
664 (insert line-breaking)
665 (setq attributes (delq key attributes))
668 (when (and (memq 'ideographic-radical attributes)
669 (setq value (get-char-attribute char 'ideographic-radical)))
671 (insert (format "(ideographic-radical . %S)\t; %c%s"
673 (aref ideographic-radicals radical)
675 (setq attributes (delq 'ideographic-radical attributes))
677 (when (and (memq 'ideographic-strokes attributes)
678 (setq value (get-char-attribute char 'ideographic-strokes)))
680 (insert (format "(ideographic-strokes . %S)%s"
683 (setq attributes (delq 'ideographic-strokes attributes))
685 (when (and (memq 'kangxi-radical attributes)
686 (setq value (get-char-attribute char 'kangxi-radical)))
687 (unless (eq value radical)
688 (insert (format "(kangxi-radical\t . %S)\t; %c%s"
690 (aref ideographic-radicals value)
693 (setq radical value)))
694 (setq attributes (delq 'kangxi-radical attributes))
696 (when (and (memq 'kangxi-strokes attributes)
697 (setq value (get-char-attribute char 'kangxi-strokes)))
698 (unless (eq value strokes)
699 (insert (format "(kangxi-strokes\t . %S)%s"
703 (setq strokes value)))
704 (setq attributes (delq 'kangxi-strokes attributes))
706 (when (and (memq 'japanese-radical attributes)
707 (setq value (get-char-attribute char 'japanese-radical)))
708 (unless (eq value radical)
709 (insert (format "(japanese-radical\t . %S)\t; %c%s"
711 (aref ideographic-radicals value)
714 (setq radical value)))
715 (setq attributes (delq 'japanese-radical attributes))
717 (when (and (memq 'japanese-strokes attributes)
718 (setq value (get-char-attribute char 'japanese-strokes)))
719 (unless (eq value strokes)
720 (insert (format "(japanese-strokes\t . %S)%s"
724 (setq strokes value)))
725 (setq attributes (delq 'japanese-strokes attributes))
727 (when (and (memq 'cns-radical attributes)
728 (setq value (get-char-attribute char 'cns-radical)))
729 (insert (format "(cns-radical\t . %S)\t; %c%s"
731 (aref ideographic-radicals value)
733 (setq attributes (delq 'cns-radical attributes))
735 (when (and (memq 'cns-strokes attributes)
736 (setq value (get-char-attribute char 'cns-strokes)))
737 (unless (eq value strokes)
738 (insert (format "(cns-strokes\t . %S)%s"
742 (setq strokes value)))
743 (setq attributes (delq 'cns-strokes attributes))
745 (when (and (memq 'shinjigen-1-radical attributes)
746 (setq value (get-char-attribute char 'shinjigen-1-radical)))
747 (unless (eq value radical)
748 (insert (format "(shinjigen-1-radical . %S)\t; %c%s"
750 (aref ideographic-radicals value)
753 (setq radical value)))
754 (setq attributes (delq 'shinjigen-1-radical attributes))
756 (when (and (memq 'ideographic- attributes)
757 (setq value (get-char-attribute char 'ideographic-)))
758 (insert "(ideographic- ")
759 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
762 (setq cell (car value))
764 (setq cell (decode-char '=ucs cell)))
765 (cond ((characterp cell)
769 (insert (format "%S" cell))
770 (char-db-insert-char-spec cell readable))
771 (setq separator lbs))
775 (if (consp (car cell))
776 (char-db-insert-char-spec cell readable)
777 (char-db-insert-char-reference cell readable))
778 (setq separator lbs))
782 (insert (prin1-to-string cell))
783 (setq separator " ")))
784 (setq value (cdr value)))
786 (insert line-breaking)
787 (setq attributes (delq 'ideographic- attributes)))
788 (when (and (memq 'total-strokes attributes)
789 (setq value (get-char-attribute char 'total-strokes)))
790 (insert (format "(total-strokes . %S)%s"
793 (setq attributes (delq 'total-strokes attributes))
795 (when (and (memq '->ideograph attributes)
796 (setq value (get-char-attribute char '->ideograph)))
797 (insert (format "(->ideograph\t%s)%s"
798 (mapconcat (lambda (code)
799 (cond ((symbolp code)
802 (format "#x%04X" code))
805 line-breaking code))))
808 (setq attributes (delq '->ideograph attributes))
810 (when (and (memq '->decomposition attributes)
811 (setq value (get-char-attribute char '->decomposition)))
812 (insert (format "(->decomposition\t%s)%s"
813 (mapconcat (lambda (code)
814 (cond ((symbolp code)
823 (format "#x%04X" code))
825 (format "%s%S" line-breaking code))))
828 (setq attributes (delq '->decomposition attributes))
830 (if (equal (get-char-attribute char '->titlecase)
831 (get-char-attribute char '->uppercase))
832 (setq attributes (delq '->titlecase attributes)))
833 (when (and (memq '->mojikyo attributes)
834 (setq value (get-char-attribute char '->mojikyo)))
835 (insert (format "(->mojikyo\t\t. %06d)\t; %c%s"
836 value (decode-char 'mojikyo value)
838 (setq attributes (delq '->mojikyo attributes))
840 (when (and (memq 'hanyu-dazidian-vol attributes)
841 (setq value (get-char-attribute char 'hanyu-dazidian-vol)))
842 (insert (format "(hanyu-dazidian-vol . %d)%s"
843 value line-breaking))
844 (setq attributes (delq 'hanyu-dazidian-vol attributes))
846 (when (and (memq 'hanyu-dazidian-page attributes)
847 (setq value (get-char-attribute char 'hanyu-dazidian-page)))
848 (insert (format "(hanyu-dazidian-page . %d)%s"
849 value line-breaking))
850 (setq attributes (delq 'hanyu-dazidian-page attributes))
852 (when (and (memq 'hanyu-dazidian-char attributes)
853 (setq value (get-char-attribute char 'hanyu-dazidian-char)))
854 (insert (format "(hanyu-dazidian-char . %d)%s"
855 value line-breaking))
856 (setq attributes (delq 'hanyu-dazidian-char attributes))
858 (setq rest ccs-attributes)
861 (setq value (get-char-attribute char (car rest)))
863 (if (>= (length (symbol-name (car rest))) 19)
865 (setq has-long-ccs-name t)
869 (setq rest (cdr rest)))
871 (setq name (car attributes))
872 (if (setq value (get-char-attribute char name))
873 (cond ((string-match "^=>ucs@" (symbol-name name))
874 (insert (format "(%-18s . #x%04X)\t; %c%s"
875 name value (decode-char '=ucs value)
878 ((eq name 'jisx0208-1978/4X)
879 (insert (format "(%-18s . #x%04X)%s"
882 ((or (eq name 'ideographic-structure)
883 (eq name 'ideographic-)
884 (string-match "^\\(->\\|<-\\)" (symbol-name name)))
885 (insert (format "(%-18s%s " name line-breaking))
886 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
889 (setq cell (car value))
891 (setq cell (decode-char '=ucs cell)))
892 (cond ((characterp cell)
896 (insert (format "%S" cell))
897 (char-db-insert-char-spec cell readable))
898 (setq separator lbs))
902 (if (consp (car cell))
903 (char-db-insert-char-spec cell readable)
904 (char-db-insert-char-reference cell readable))
905 (setq separator lbs))
909 (insert (prin1-to-string cell))
910 (setq separator " ")))
911 (setq value (cdr value)))
913 (insert line-breaking))
914 ((memq name '(ideograph=
915 original-ideograph-of
919 simplified-ideograph-of
921 ideographic-different-form-of))
922 (insert (format "(%-18s%s " name line-breaking))
923 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
926 (setq cell (car value))
927 (if (and (consp cell)
932 (char-db-insert-alist cell readable)
933 (setq separator lbs))
936 (insert (prin1-to-string cell))
937 (setq separator " "))
938 (setq value (cdr value)))
940 (insert line-breaking))
941 ;; ((string-match "^->" (symbol-name name))
943 ;; (format "(%-18s %s)%s"
945 ;; (mapconcat (lambda (code)
946 ;; (cond ((symbolp code)
947 ;; (symbol-name code))
949 ;; (format "#x%04X" code))
952 ;; line-breaking code))))
956 (insert (format "(%-18s " name))
957 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
960 (setq cell (car value))
961 (if (and (consp cell)
963 (setq ret (condition-case nil
971 (setq key (car (car rest)))
972 (if (find-charset key)
973 (setq cal (cons key cal))
974 (setq al (cons key al)))
975 (setq rest (cdr rest)))
978 (insert-char-attributes ret
981 (setq separator lbs))
984 (insert (prin1-to-string cell))
985 (setq separator " "))
986 (setq value (cdr value)))
988 (insert line-breaking))
990 (insert (format "(%-18s . %S)%s"
994 (setq attributes (cdr attributes)))
995 (while ccs-attributes
996 (setq name (charset-name (car ccs-attributes)))
997 (if (and (not (memq name dest-ccss))
999 (setq value (get-char-attribute char name))
1000 (setq dest-ccss (cons name dest-ccss))))
1003 (cond ((memq name '(=daikanwa
1004 =daikanwa-rev1 =daikanwa-rev2
1006 (if has-long-ccs-name
1007 "(%-26s . %05d)\t; %c%s"
1008 "(%-18s . %05d)\t; %c%s"))
1010 (if has-long-ccs-name
1011 "(%-26s . %06d)\t; %c%s"
1012 "(%-18s . %06d)\t; %c%s"))
1013 ((>= (charset-dimension name) 2)
1014 (if has-long-ccs-name
1015 "(%-26s . #x%04X)\t; %c%s"
1016 "(%-18s . #x%04X)\t; %c%s"))
1018 (if has-long-ccs-name
1019 "(%-26s . #x%02X)\t; %c%s"
1020 "(%-18s . #x%02X)\t; %c%s")))
1022 (if (= (charset-iso-graphic-plane name) 1)
1024 (cond ((= (charset-dimension name) 1)
1026 ((= (charset-dimension name) 2)
1028 ((= (charset-dimension name) 3)
1032 (char-db-decode-isolated-char name value)
1034 (setq ccs-attributes (cdr ccs-attributes)))
1037 (defun insert-char-data (char &optional readable
1038 attributes ccs-attributes)
1040 (narrow-to-region (point)(point))
1041 (insert "(define-char
1043 (insert-char-attributes char readable
1044 attributes ccs-attributes)
1046 (goto-char (point-min))
1047 (while (re-search-forward "[ \t]+$" nil t)
1050 (goto-char (point-min))
1051 (while (re-search-forward "[ \t][ \t][ \t]*" nil t)
1052 (let ((column (current-column))
1053 (indent-tabs-mode t))
1054 (delete-region (match-beginning 0) (point))
1055 (indent-to column)))
1056 (goto-char (point-max))
1057 ;; (tabify (point-min)(point-max))
1060 (defun insert-char-data-with-variant (char &optional printable
1062 script excluded-script)
1063 (insert-char-data char printable)
1064 (let ((variants (or (char-variants char)
1065 (let ((ucs (get-char-attribute char '->ucs)))
1067 (delete char (char-variants (int-char ucs)))))))
1069 (setq variants (sort variants #'<))
1071 (setq variant (car variants))
1072 (if (and (or (null script)
1073 (null (setq vs (get-char-attribute variant 'script)))
1075 (or (null excluded-script)
1076 (null (setq vs (get-char-attribute variant 'script)))
1077 (not (memq excluded-script vs))))
1078 (or (and no-ucs-variant (get-char-attribute variant '=ucs))
1079 (insert-char-data variant printable)))
1080 (setq variants (cdr variants))
1083 (defun insert-char-range-data (min max &optional script excluded-script)
1086 (while (<= code max)
1087 (setq char (decode-char '=ucs code))
1088 (if (encode-char char '=ucs 'defined-only)
1089 (insert-char-data-with-variant char nil 'no-ucs-variant
1090 script excluded-script))
1091 (setq code (1+ code)))))
1093 (defun write-char-range-data-to-file (min max file
1094 &optional script excluded-script)
1095 (let ((coding-system-for-write 'utf-8))
1097 (insert-char-range-data min max script excluded-script)
1098 (write-region (point-min)(point-max) file))))
1100 (defvar what-character-original-window-configuration)
1103 (defun what-char-definition (char)
1104 (interactive (list (char-after)))
1105 (let ((buf (get-buffer-create "*Character Description*"))
1106 (the-buf (current-buffer))
1107 (win-conf (current-window-configuration)))
1109 (make-local-variable 'what-character-original-window-configuration)
1110 (setq what-character-original-window-configuration win-conf)
1111 (setq buffer-read-only nil)
1115 (insert-char-data-with-variant char 'printable)
1116 (unless (char-attribute-alist char)
1117 (insert (format ";; = %c\n"
1118 (let* ((rest (split-char char))
1122 (setq code (logior (lsh code 8)
1124 (decode-char ccs code)))))
1125 ;; (char-db-update-comment)
1126 (set-buffer-modified-p nil)
1127 (view-mode the-buf (lambda (buf)
1128 (set-window-configuration
1129 what-character-original-window-configuration)
1131 (goto-char (point-min)))
1133 (set-window-configuration
1134 what-character-original-window-configuration)
1135 (signal (car err) (cdr err)))))))
1137 (provide 'char-db-util)
1139 ;;; char-db-util.el ends here