1 ;;; char-db-util.el --- Character Database utility
3 ;; Copyright (C) 1998,1999,2000,2001,2002,2003,2004 MORIOKA Tomohiko.
5 ;; Author: MORIOKA Tomohiko <tomo@kanji.zinbun.kyoto-u.ac.jp>
6 ;; Keywords: CHISE, Character Database, ISO/IEC 10646, Unicode, UCS-4, MULE.
8 ;; This file is part of XEmacs CHISE.
10 ;; XEmacs CHISE 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 CHISE 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 CHISE; 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-feature-domains
73 '(ucs daikanwa cns gt jis jis/alt jis/a jis/b
74 jis-x0213 misc unknown))
76 (defvar char-db-ignored-attributes nil)
78 (defun char-attribute-name< (ka kb)
83 (if (<= (charset-id ka) 0)
84 (if (<= (charset-id kb) 0)
86 ((= (charset-dimension ka)
87 (charset-dimension kb))
88 (> (charset-id ka)(charset-id kb)))
90 (> (charset-dimension ka)
91 (charset-dimension kb))
94 (if (<= (charset-id kb) 0)
96 (< (charset-id ka)(charset-id kb)))))
105 (string< (symbol-name ka)
111 (defvar char-db-coded-charset-priority-list
126 japanese-jisx0208-1978
167 (defun char-db-make-char-spec (char)
169 (cond ((characterp char)
170 (cond ((and (setq ret (encode-char char '=ucs 'defined-only))
171 (not (and (<= #xE000 ret)(<= ret #xF8FF))))
172 (setq char-spec (list (cons '=ucs ret)))
173 (cond ((setq ret (get-char-attribute char 'name))
174 (setq char-spec (cons (cons 'name ret) char-spec))
176 ((setq ret (get-char-attribute char 'name*))
177 (setq char-spec (cons (cons 'name* ret) char-spec))
182 (let ((rest char-db-coded-charset-priority-list)
185 (setq ccs (charset-name
186 (find-charset (car rest))))
188 (encode-char char ccs
190 (throw 'tag (cons ccs ret)))
191 (setq rest (cdr rest))))))
192 (setq char-spec (list ret))
193 (dolist (ccs (delq (car ret) (charset-list)))
194 (if (and (or (charset-iso-final-char ccs)
200 (setq ret (encode-char char ccs 'defined-only)))
201 (setq char-spec (cons (cons ccs ret) char-spec))))
203 (setq char-spec (split-char char)))
204 (cond ((setq ret (get-char-attribute char 'name))
205 (setq char-spec (cons (cons 'name ret) char-spec))
207 ((setq ret (get-char-attribute char 'name*))
208 (setq char-spec (cons (cons 'name* ret) char-spec))
215 (defun char-db-insert-char-spec (char &optional readable column
218 (setq column (current-column)))
219 (let (char-spec al cal key temp-char)
220 (setq char-spec (char-db-make-char-spec char))
221 (unless (or (characterp char) ; char
223 (setq char (find-char char-spec))
225 ;; define temporary character
226 ;; Current implementation is dirty.
227 (setq temp-char (define-char (cons '(ideograph-daikanwa . 0)
229 (remove-char-attribute temp-char 'ideograph-daikanwa)
230 (setq char temp-char))
234 (setq key (car (car char-spec)))
235 (unless (memq key char-db-ignored-attributes)
236 (if (find-charset key)
237 (if (encode-char char key 'defined-only)
238 (setq cal (cons key cal)))
239 (setq al (cons key al))))
240 (setq char-spec (cdr char-spec)))
242 (setq char-spec (char-db-make-char-spec char))
244 (setq key (car (car char-spec)))
245 (unless (memq key char-db-ignored-attributes)
246 (if (find-charset key)
247 (setq cal (cons key cal))
248 (setq al (cons key al))))
249 (setq char-spec (cdr char-spec)))
252 (memq 'ideographic-structure al))
253 (push 'ideographic-structure al))
254 (dolist (feature required-features)
255 (if (find-charset feature)
256 (if (encode-char char feature 'defined-only)
257 (setq cal (adjoin feature cal)))
258 (setq al (adjoin feature 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 (encode-char ret '=gt 'defined-only)))
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 sources required-features)
454 (when (and (memq 'name attributes)
455 (setq value (get-char-attribute char 'name)))
457 (if (> (+ (current-column) (length value)) 48)
460 value line-breaking))
461 (setq attributes (delq 'name attributes))
463 (when (and (memq 'name* attributes)
464 (setq value (get-char-attribute char 'name*)))
466 (if (> (+ (current-column) (length value)) 48)
469 value line-breaking))
470 (setq attributes (delq 'name* attributes))
472 (when (and (memq 'script attributes)
473 (setq value (get-char-attribute char 'script)))
474 (insert (format "(script\t\t%s)%s"
475 (mapconcat (function prin1-to-string)
478 (setq attributes (delq 'script attributes))
480 (dolist (name '(=>ucs =>ucs*))
481 (when (and (memq name attributes)
482 (setq value (get-char-attribute char name)))
483 (insert (format "(%-18s . #x%04X)\t; %c%s"
484 name value (decode-char '=ucs value)
486 (setq attributes (delq name attributes))))
487 (dolist (name '(=>ucs@gb =>ucs@cns =>ucs@jis =>ucs@ks =>ucs@big5))
488 (when (and (memq name attributes)
489 (setq value (get-char-attribute char name)))
490 (insert (format "(%-18s . #x%04X)\t; %c%s"
495 (symbol-name name) 2)))
498 (setq attributes (delq name attributes))
500 (dolist (name '(=>ucs-gb =>ucs-cns =>ucs-jis =>ucs-ks =>ucs-big5))
501 (when (and (memq name attributes)
502 (setq value (get-char-attribute char name)))
503 (insert (format "(%-18s . #x%04X)\t; %c%s"
506 (substring (symbol-name name) 6)))
511 (symbol-name name) 6)))
514 (setq attributes (delq name attributes))))
515 (when (and (memq '->ucs attributes)
516 (setq value (get-char-attribute char '->ucs)))
517 (insert (format (if char-db-convert-obsolete-format
518 "(=>ucs\t\t. #x%04X)\t; %c%s"
519 "(->ucs\t\t. #x%04X)\t; %c%s")
520 value (decode-char '=ucs value)
522 (setq attributes (delq '->ucs attributes))
524 (when (and (memq 'general-category attributes)
525 (setq value (get-char-attribute char 'general-category)))
527 "(general-category\t%s) ; %s%s"
528 (mapconcat (lambda (cell)
531 (cond ((rassoc value unidata-normative-category-alist)
532 "Normative Category")
533 ((rassoc value unidata-informative-category-alist)
534 "Informative Category")
538 (setq attributes (delq 'general-category attributes))
540 (when (and (memq 'bidi-category attributes)
541 (setq value (get-char-attribute char 'bidi-category)))
542 (insert (format "(bidi-category\t. %S)%s"
545 (setq attributes (delq 'bidi-category attributes))
547 (unless (or (not (memq 'mirrored attributes))
548 (eq (setq value (get-char-attribute char 'mirrored 'empty))
550 (insert (format "(mirrored\t\t. %S)%s"
553 (setq attributes (delq 'mirrored attributes))
556 ((and (memq 'decimal-digit-value attributes)
557 (setq value (get-char-attribute char 'decimal-digit-value)))
558 (insert (format "(decimal-digit-value . %S)%s"
561 (setq attributes (delq 'decimal-digit-value attributes))
562 (when (and (memq 'digit-value attributes)
563 (setq value (get-char-attribute char 'digit-value)))
564 (insert (format "(digit-value\t . %S)%s"
567 (setq attributes (delq 'digit-value attributes))
569 (when (and (memq 'numeric-value attributes)
570 (setq value (get-char-attribute char 'numeric-value)))
571 (insert (format "(numeric-value\t . %S)%s"
574 (setq attributes (delq 'numeric-value attributes))
578 (when (and (memq 'digit-value attributes)
579 (setq value (get-char-attribute char 'digit-value)))
580 (insert (format "(digit-value\t. %S)%s"
583 (setq attributes (delq 'digit-value attributes))
585 (when (and (memq 'numeric-value attributes)
586 (setq value (get-char-attribute char 'numeric-value)))
587 (insert (format "(numeric-value\t. %S)%s"
590 (setq attributes (delq 'numeric-value attributes))
592 (when (and (memq 'iso-10646-comment attributes)
593 (setq value (get-char-attribute char 'iso-10646-comment)))
594 (insert (format "(iso-10646-comment\t. %S)%s"
597 (setq attributes (delq 'iso-10646-comment attributes))
599 (when (and (memq 'morohashi-daikanwa attributes)
600 (setq value (get-char-attribute char 'morohashi-daikanwa)))
601 (insert (format "(morohashi-daikanwa\t%s)%s"
602 (mapconcat (function prin1-to-string) value " ")
604 (setq attributes (delq 'morohashi-daikanwa attributes))
608 (when (and (memq 'ideographic-radical attributes)
609 (setq value (get-char-attribute char 'ideographic-radical)))
611 (insert (format "(ideographic-radical . %S)\t; %c%s"
613 (aref ideographic-radicals radical)
615 (setq attributes (delq 'ideographic-radical attributes))
618 (dolist (domain char-db-feature-domains)
619 (setq key (intern (format "%s@%s" 'ideographic-radical domain)))
620 (when (and (memq key attributes)
621 (setq value (get-char-attribute char key)))
623 (insert (format "(%s . %S)\t; %c%s"
626 (aref ideographic-radicals radical)
628 (setq attributes (delq key attributes))
630 (setq key (intern (format "%s@%s" 'ideographic-strokes domain)))
631 (when (and (memq key attributes)
632 (setq value (get-char-attribute char key)))
634 (insert (format "(%s . %S)%s"
638 (setq attributes (delq key attributes))
640 (setq key (intern (format "%s@%s" 'total-strokes domain)))
641 (when (and (memq key attributes)
642 (setq value (get-char-attribute char key)))
643 (insert (format "(%s . %S)%s"
647 (setq attributes (delq key attributes))
649 (dolist (feature '(ideographic-radical
652 (setq key (intern (format "%s@%s*sources" feature domain)))
653 (when (and (memq key attributes)
654 (setq value (get-char-attribute char key)))
655 (insert (format "(%s%s" key line-breaking))
657 (insert (format " %s" cell)))
659 (insert line-breaking)
660 (setq attributes (delq key attributes))
663 (when (and (memq 'ideographic-strokes attributes)
664 (setq value (get-char-attribute char 'ideographic-strokes)))
666 (insert (format "(ideographic-strokes . %S)%s"
669 (setq attributes (delq 'ideographic-strokes attributes))
671 (when (and (memq 'kangxi-radical attributes)
672 (setq value (get-char-attribute char 'kangxi-radical)))
673 (unless (eq value radical)
674 (insert (format "(kangxi-radical\t . %S)\t; %c%s"
676 (aref ideographic-radicals value)
679 (setq radical value)))
680 (setq attributes (delq 'kangxi-radical attributes))
682 (when (and (memq 'kangxi-strokes attributes)
683 (setq value (get-char-attribute char 'kangxi-strokes)))
684 (unless (eq value strokes)
685 (insert (format "(kangxi-strokes\t . %S)%s"
689 (setq strokes value)))
690 (setq attributes (delq 'kangxi-strokes attributes))
692 (when (and (memq 'japanese-radical attributes)
693 (setq value (get-char-attribute char 'japanese-radical)))
694 (unless (eq value radical)
695 (insert (format "(japanese-radical\t . %S)\t; %c%s"
697 (aref ideographic-radicals value)
700 (setq radical value)))
701 (setq attributes (delq 'japanese-radical attributes))
703 (when (and (memq 'japanese-strokes attributes)
704 (setq value (get-char-attribute char 'japanese-strokes)))
705 (unless (eq value strokes)
706 (insert (format "(japanese-strokes\t . %S)%s"
710 (setq strokes value)))
711 (setq attributes (delq 'japanese-strokes attributes))
713 (when (and (memq 'cns-radical attributes)
714 (setq value (get-char-attribute char 'cns-radical)))
715 (insert (format "(cns-radical\t . %S)\t; %c%s"
717 (aref ideographic-radicals value)
719 (setq attributes (delq 'cns-radical attributes))
721 (when (and (memq 'cns-strokes attributes)
722 (setq value (get-char-attribute char 'cns-strokes)))
723 (unless (eq value strokes)
724 (insert (format "(cns-strokes\t . %S)%s"
728 (setq strokes value)))
729 (setq attributes (delq 'cns-strokes attributes))
731 (when (and (memq 'shinjigen-1-radical attributes)
732 (setq value (get-char-attribute char 'shinjigen-1-radical)))
733 (unless (eq value radical)
734 (insert (format "(shinjigen-1-radical . %S)\t; %c%s"
736 (aref ideographic-radicals value)
739 (setq radical value)))
740 (setq attributes (delq 'shinjigen-1-radical attributes))
742 (when (and (memq 'ideographic- attributes)
743 (setq value (get-char-attribute char 'ideographic-)))
744 (insert "(ideographic- ")
745 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
748 (setq cell (car value))
750 (setq cell (decode-char '=ucs cell)))
751 (cond ((characterp cell)
755 (insert (format "%S" cell))
756 (char-db-insert-char-spec cell readable))
757 (setq separator lbs))
761 (if (consp (car cell))
762 (char-db-insert-char-spec cell readable)
763 (char-db-insert-char-reference cell readable))
764 (setq separator lbs))
768 (insert (prin1-to-string cell))
769 (setq separator " ")))
770 (setq value (cdr value)))
772 (insert line-breaking)
773 (setq attributes (delq 'ideographic- attributes)))
774 (when (and (memq 'total-strokes attributes)
775 (setq value (get-char-attribute char 'total-strokes)))
776 (insert (format "(total-strokes . %S)%s"
779 (setq attributes (delq 'total-strokes attributes))
781 (when (and (memq '->ideograph attributes)
782 (setq value (get-char-attribute char '->ideograph)))
783 (insert (format "(->ideograph\t%s)%s"
784 (mapconcat (lambda (code)
785 (cond ((symbolp code)
788 (format "#x%04X" code))
791 line-breaking code))))
794 (setq attributes (delq '->ideograph attributes))
796 (when (and (memq '->decomposition attributes)
797 (setq value (get-char-attribute char '->decomposition)))
798 (insert (format "(->decomposition\t%s)%s"
799 (mapconcat (lambda (code)
800 (cond ((symbolp code)
809 (format "#x%04X" code))
811 (format "%s%S" line-breaking code))))
814 (setq attributes (delq '->decomposition attributes))
816 (if (equal (get-char-attribute char '->titlecase)
817 (get-char-attribute char '->uppercase))
818 (setq attributes (delq '->titlecase attributes)))
819 (when (and (memq '->mojikyo attributes)
820 (setq value (get-char-attribute char '->mojikyo)))
821 (insert (format "(->mojikyo\t\t. %06d)\t; %c%s"
822 value (decode-char 'mojikyo value)
824 (setq attributes (delq '->mojikyo attributes))
826 (when (and (memq 'hanyu-dazidian-vol attributes)
827 (setq value (get-char-attribute char 'hanyu-dazidian-vol)))
828 (insert (format "(hanyu-dazidian-vol . %d)%s"
829 value line-breaking))
830 (setq attributes (delq 'hanyu-dazidian-vol attributes))
832 (when (and (memq 'hanyu-dazidian-page attributes)
833 (setq value (get-char-attribute char 'hanyu-dazidian-page)))
834 (insert (format "(hanyu-dazidian-page . %d)%s"
835 value line-breaking))
836 (setq attributes (delq 'hanyu-dazidian-page attributes))
838 (when (and (memq 'hanyu-dazidian-char attributes)
839 (setq value (get-char-attribute char 'hanyu-dazidian-char)))
840 (insert (format "(hanyu-dazidian-char . %d)%s"
841 value line-breaking))
842 (setq attributes (delq 'hanyu-dazidian-char attributes))
845 (when (memq '->ucs-unified attributes)
846 (setq attributes (delq '->ucs-unified attributes))
848 (when (memq 'composition attributes)
849 (setq attributes (delq 'composition attributes))
851 (setq rest ccs-attributes)
854 (setq value (get-char-attribute char (car rest)))
856 (if (>= (length (symbol-name (car rest))) 19)
858 (setq has-long-ccs-name t)
862 (setq rest (cdr rest)))
864 (setq name (car attributes))
865 (if (setq value (get-char-attribute char name))
866 (cond ((string-match "^=>ucs@" (symbol-name name))
867 (insert (format "(%-18s . #x%04X)\t; %c%s"
868 name value (decode-char '=ucs value)
871 ((eq name 'jisx0208-1978/4X)
872 (insert (format "(%-18s . #x%04X)%s"
875 ((or (eq name 'ideographic-structure)
876 (eq name 'ideographic-)
877 (string-match "^\\(->\\|<-\\)" (symbol-name name)))
878 (insert (format "(%-18s%s " name line-breaking))
879 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
882 (setq cell (car value))
884 (setq cell (decode-char '=ucs cell)))
885 (cond ((characterp cell)
889 (intern (format "%s*sources" name))))
890 (setq required-features nil)
891 (dolist (source sources)
892 (setq required-features
896 (format "=%s" source))))
900 (when (string-match "@JP" (symbol-name name))
901 (setq required-features
902 (union required-features
913 (insert (format "%S" cell))
914 (char-db-insert-char-spec cell readable
917 (setq separator lbs))
921 (if (consp (car cell))
922 (char-db-insert-char-spec cell readable)
923 (char-db-insert-char-reference cell readable))
924 (setq separator lbs))
928 (insert (prin1-to-string cell))
929 (setq separator " ")))
930 (setq value (cdr value)))
932 (insert line-breaking))
933 ((memq name '(ideograph=
934 original-ideograph-of
938 ;; simplified-ideograph-of
940 ;; ideographic-different-form-of
942 (insert (format "(%-18s%s " name line-breaking))
943 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
946 (setq cell (car value))
947 (if (and (consp cell)
952 (char-db-insert-alist cell readable)
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 " name))
963 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
966 (setq cell (car value))
967 (if (and (consp cell)
969 (setq ret (condition-case nil
977 (setq key (car (car rest)))
978 (if (find-charset key)
979 (setq cal (cons key cal))
980 (setq al (cons key al)))
981 (setq rest (cdr rest)))
984 (insert-char-attributes ret
987 (setq separator lbs))
990 (insert (prin1-to-string cell))
991 (setq separator " "))
992 (setq value (cdr value)))
994 (insert line-breaking))
996 (insert (format "(%-18s . %S)%s"
1000 (setq attributes (cdr attributes)))
1001 (while ccs-attributes
1002 (setq name (charset-name (car ccs-attributes)))
1003 (if (and (not (memq name dest-ccss))
1005 (setq value (get-char-attribute char name))
1006 (setq dest-ccss (cons name dest-ccss))))
1009 (cond ((memq name '(=daikanwa
1010 =daikanwa-rev1 =daikanwa-rev2
1012 (if has-long-ccs-name
1013 "(%-26s . %05d)\t; %c%s"
1014 "(%-18s . %05d)\t; %c%s"))
1016 (if has-long-ccs-name
1017 "(%-26s . %06d)\t; %c%s"
1018 "(%-18s . %06d)\t; %c%s"))
1019 ((>= (charset-dimension name) 2)
1020 (if has-long-ccs-name
1021 "(%-26s . #x%04X)\t; %c%s"
1022 "(%-18s . #x%04X)\t; %c%s"))
1024 (if has-long-ccs-name
1025 "(%-26s . #x%02X)\t; %c%s"
1026 "(%-18s . #x%02X)\t; %c%s")))
1028 (if (= (charset-iso-graphic-plane name) 1)
1030 (cond ((= (charset-dimension name) 1)
1032 ((= (charset-dimension name) 2)
1034 ((= (charset-dimension name) 3)
1038 (char-db-decode-isolated-char name value)
1040 (setq ccs-attributes (cdr ccs-attributes)))
1043 (defun insert-char-data (char &optional readable
1044 attributes ccs-attributes)
1046 (narrow-to-region (point)(point))
1047 (insert "(define-char
1049 (insert-char-attributes char readable
1050 attributes ccs-attributes)
1052 (goto-char (point-min))
1053 (while (re-search-forward "[ \t]+$" nil t)
1056 (goto-char (point-min))
1057 (while (re-search-forward "[ \t][ \t][ \t]*" nil t)
1058 (let ((column (current-column))
1059 (indent-tabs-mode t))
1060 (delete-region (match-beginning 0) (point))
1061 (indent-to column)))
1062 (goto-char (point-max))
1063 ;; (tabify (point-min)(point-max))
1066 (defun insert-char-data-with-variant (char &optional printable
1068 script excluded-script)
1069 (insert-char-data char printable)
1070 (let ((variants (or (char-variants char)
1071 (let ((ucs (get-char-attribute char '->ucs)))
1073 (delete char (char-variants (int-char ucs)))))))
1075 (setq variants (sort variants #'<))
1077 (setq variant (car variants))
1078 (if (and (or (null script)
1079 (null (setq vs (get-char-attribute variant 'script)))
1081 (or (null excluded-script)
1082 (null (setq vs (get-char-attribute variant 'script)))
1083 (not (memq excluded-script vs))))
1084 (or (and no-ucs-unified (get-char-attribute variant '=ucs))
1085 (insert-char-data variant printable)))
1086 (setq variants (cdr variants))
1089 (defun insert-char-range-data (min max &optional script excluded-script)
1092 (while (<= code max)
1093 (setq char (decode-char '=ucs code))
1094 (if (encode-char char '=ucs 'defined-only)
1095 (insert-char-data-with-variant char nil 'no-ucs-unified
1096 script excluded-script))
1097 (setq code (1+ code)))))
1099 (defun write-char-range-data-to-file (min max file
1100 &optional script excluded-script)
1101 (let ((coding-system-for-write 'utf-8-mcs))
1103 (insert ";; -*- coding: utf-8-mcs -*-\n")
1104 (insert-char-range-data min max script excluded-script)
1105 (write-region (point-min)(point-max) file))))
1107 (defvar what-character-original-window-configuration)
1110 (defun what-char-definition (char)
1111 (interactive (list (char-after)))
1112 (let ((buf (get-buffer-create "*Character Description*"))
1113 (the-buf (current-buffer))
1114 (win-conf (current-window-configuration)))
1116 (make-local-variable 'what-character-original-window-configuration)
1117 (setq what-character-original-window-configuration win-conf)
1118 (setq buffer-read-only nil)
1122 (insert-char-data-with-variant char 'printable)
1123 (unless (char-attribute-alist char)
1124 (insert (format ";; = %c\n"
1125 (let* ((rest (split-char char))
1129 (setq code (logior (lsh code 8)
1131 (decode-char ccs code)))))
1132 ;; (char-db-update-comment)
1133 (set-buffer-modified-p nil)
1134 (view-mode the-buf (lambda (buf)
1135 (set-window-configuration
1136 what-character-original-window-configuration)
1138 (goto-char (point-min)))
1140 (set-window-configuration
1141 what-character-original-window-configuration)
1142 (signal (car err) (cdr err)))))))
1144 (provide 'char-db-util)
1146 ;;; char-db-util.el ends here