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)
217 (setq column (current-column)))
218 (let (char-spec al cal key temp-char)
219 (setq char-spec (char-db-make-char-spec char))
220 (unless (or (characterp char) ; char
222 (setq char (find-char char-spec))
224 ;; define temporary character
225 ;; Current implementation is dirty.
226 (setq temp-char (define-char (cons '(ideograph-daikanwa . 0)
228 (remove-char-attribute temp-char 'ideograph-daikanwa)
229 (setq char temp-char))
233 (setq key (car (car char-spec)))
234 (unless (memq key char-db-ignored-attributes)
235 (if (find-charset key)
236 (if (encode-char char key 'defined-only)
237 (setq cal (cons key cal)))
238 (setq al (cons key al))))
239 (setq char-spec (cdr char-spec)))
241 (setq char-spec (char-db-make-char-spec char))
243 (setq key (car (car char-spec)))
244 (unless (memq key char-db-ignored-attributes)
245 (if (find-charset key)
246 (setq cal (cons key cal))
247 (setq al (cons key al))))
248 (setq char-spec (cdr char-spec)))
251 (memq 'ideographic-structure al))
252 (push 'ideographic-structure al))
253 (insert-char-attributes char
257 ;; undefine temporary character
258 ;; Current implementation is dirty.
259 (setq char-spec (char-attribute-alist temp-char))
261 (remove-char-attribute temp-char (car (car char-spec)))
262 (setq char-spec (cdr char-spec))))))
264 (defun char-db-insert-alist (alist &optional readable column)
266 (setq column (current-column)))
268 (concat "\n" (make-string (1+ column) ?\ )))
271 lbs cell rest separator)
274 (setq name (car (car alist))
275 value (cdr (car alist)))
276 (cond ((eq name 'char)
278 (if (setq ret (condition-case nil
285 (setq key (car (car value)))
286 (if (find-charset key)
287 (setq cal (cons key cal))
288 (setq al (cons key al)))
289 (setq value (cdr value)))
290 (insert-char-attributes ret
293 (insert (prin1-to-string value)))
295 (insert line-breaking))
297 (insert (format "(%-18s " name))
298 (setq lbs (concat "\n" (make-string (current-column) ?\ )))
300 (setq cell (car value))
301 (if (and (consp cell)
303 (setq ret (condition-case nil
312 (setq key (car (car rest)))
313 (if (find-charset key)
314 (setq cal (cons key cal))
315 (setq al (cons key al)))
316 (setq rest (cdr rest)))
319 (insert-char-attributes ret
322 (setq separator lbs))
325 (insert (prin1-to-string cell))
326 (setq separator " "))
327 (setq value (cdr value)))
329 (insert line-breaking))
331 (insert (format "(%-18s . %S)%s"
334 (setq alist (cdr alist))))
337 (defun char-db-insert-char-reference (plist &optional readable column)
339 (setq column (current-column)))
341 (concat "\n" (make-string (1+ column) ?\ )))
346 (setq name (pop plist))
347 (setq value (pop plist))
348 (cond ((eq name :char)
351 (cond ((numberp value)
352 (setq value (decode-char '=ucs value)))
354 ;; (setq value (or (find-char value)
357 (char-db-insert-char-spec value readable)
358 (insert line-breaking)
361 (insert (format "%s%s\t%d ; %c%s"
364 (aref ideographic-radicals value)
368 (insert (format "%s%s\t%S" separator name value))
369 (setq separator line-breaking)))
373 (defun char-db-decode-isolated-char (ccs code-point)
376 (cond ((eq ccs 'arabic-iso8859-6)
377 (decode-char ccs code-point))
378 ((and (memq ccs '(=gt-pj-1
389 (setq ret (decode-char ccs code-point))
390 (setq ret (encode-char ret '=gt 'defined-only)))
391 (decode-builtin-char '=gt ret))
393 (decode-builtin-char ccs code-point))))
394 (cond ((and (<= 0 (char-int ret))
395 (<= (char-int ret) #x1F))
396 (decode-char '=ucs (+ #x2400 (char-int ret))))
397 ((= (char-int ret) #x7F)
401 (defvar char-db-convert-obsolete-format t)
403 (defun insert-char-attributes (char &optional readable
404 attributes ccs-attributes
409 (if (consp attributes)
411 (dolist (name attributes)
412 (unless (memq name char-db-ignored-attributes)
415 (dolist (name (char-attribute-list))
416 (unless (memq name char-db-ignored-attributes)
417 (if (find-charset name)
421 #'char-attribute-name<))
423 (sort (if ccs-attributes
426 (dolist (name ccs-attributes)
427 (unless (memq name char-db-ignored-attributes)
432 (dolist (name (charset-list))
433 (unless (memq name char-db-ignored-attributes)
436 #'char-attribute-name<)))
438 (setq column (current-column)))
439 (let (name value has-long-ccs-name rest
442 (concat "\n" (make-string (1+ column) ?\ )))
443 lbs cell separator ret
447 (when (and (memq 'name attributes)
448 (setq value (get-char-attribute char 'name)))
450 (if (> (+ (current-column) (length value)) 48)
453 value line-breaking))
454 (setq attributes (delq 'name attributes))
456 (when (and (memq 'name* attributes)
457 (setq value (get-char-attribute char 'name*)))
459 (if (> (+ (current-column) (length value)) 48)
462 value line-breaking))
463 (setq attributes (delq 'name* attributes))
465 (when (and (memq 'script attributes)
466 (setq value (get-char-attribute char 'script)))
467 (insert (format "(script\t\t%s)%s"
468 (mapconcat (function prin1-to-string)
471 (setq attributes (delq 'script attributes))
473 (dolist (name '(=>ucs =>ucs*))
474 (when (and (memq name attributes)
475 (setq value (get-char-attribute char name)))
476 (insert (format "(%-18s . #x%04X)\t; %c%s"
477 name value (decode-char '=ucs value)
479 (setq attributes (delq name attributes))))
480 (dolist (name '(=>ucs@gb =>ucs@cns =>ucs@jis =>ucs@ks =>ucs@big5))
481 (when (and (memq name attributes)
482 (setq value (get-char-attribute char name)))
483 (insert (format "(%-18s . #x%04X)\t; %c%s"
488 (symbol-name name) 2)))
491 (setq attributes (delq name attributes))
493 (dolist (name '(=>ucs-gb =>ucs-cns =>ucs-jis =>ucs-ks =>ucs-big5))
494 (when (and (memq name attributes)
495 (setq value (get-char-attribute char name)))
496 (insert (format "(%-18s . #x%04X)\t; %c%s"
499 (substring (symbol-name name) 6)))
504 (symbol-name name) 6)))
507 (setq attributes (delq name attributes))))
508 (when (and (memq '->ucs attributes)
509 (setq value (get-char-attribute char '->ucs)))
510 (insert (format (if char-db-convert-obsolete-format
511 "(=>ucs\t\t. #x%04X)\t; %c%s"
512 "(->ucs\t\t. #x%04X)\t; %c%s")
513 value (decode-char '=ucs value)
515 (setq attributes (delq '->ucs attributes))
517 (when (and (memq 'general-category attributes)
518 (setq value (get-char-attribute char 'general-category)))
520 "(general-category\t%s) ; %s%s"
521 (mapconcat (lambda (cell)
524 (cond ((rassoc value unidata-normative-category-alist)
525 "Normative Category")
526 ((rassoc value unidata-informative-category-alist)
527 "Informative Category")
531 (setq attributes (delq 'general-category attributes))
533 (when (and (memq 'bidi-category attributes)
534 (setq value (get-char-attribute char 'bidi-category)))
535 (insert (format "(bidi-category\t. %S)%s"
538 (setq attributes (delq 'bidi-category attributes))
540 (unless (or (not (memq 'mirrored attributes))
541 (eq (setq value (get-char-attribute char 'mirrored 'empty))
543 (insert (format "(mirrored\t\t. %S)%s"
546 (setq attributes (delq 'mirrored attributes))
549 ((and (memq 'decimal-digit-value attributes)
550 (setq value (get-char-attribute char 'decimal-digit-value)))
551 (insert (format "(decimal-digit-value . %S)%s"
554 (setq attributes (delq 'decimal-digit-value attributes))
555 (when (and (memq 'digit-value attributes)
556 (setq value (get-char-attribute char 'digit-value)))
557 (insert (format "(digit-value\t . %S)%s"
560 (setq attributes (delq 'digit-value attributes))
562 (when (and (memq 'numeric-value attributes)
563 (setq value (get-char-attribute char 'numeric-value)))
564 (insert (format "(numeric-value\t . %S)%s"
567 (setq attributes (delq 'numeric-value attributes))
571 (when (and (memq 'digit-value attributes)
572 (setq value (get-char-attribute char 'digit-value)))
573 (insert (format "(digit-value\t. %S)%s"
576 (setq attributes (delq 'digit-value attributes))
578 (when (and (memq 'numeric-value attributes)
579 (setq value (get-char-attribute char 'numeric-value)))
580 (insert (format "(numeric-value\t. %S)%s"
583 (setq attributes (delq 'numeric-value attributes))
585 (when (and (memq 'iso-10646-comment attributes)
586 (setq value (get-char-attribute char 'iso-10646-comment)))
587 (insert (format "(iso-10646-comment\t. %S)%s"
590 (setq attributes (delq 'iso-10646-comment attributes))
592 (when (and (memq 'morohashi-daikanwa attributes)
593 (setq value (get-char-attribute char 'morohashi-daikanwa)))
594 (insert (format "(morohashi-daikanwa\t%s)%s"
595 (mapconcat (function prin1-to-string) value " ")
597 (setq attributes (delq 'morohashi-daikanwa attributes))
601 (when (and (memq 'ideographic-radical attributes)
602 (setq value (get-char-attribute char 'ideographic-radical)))
604 (insert (format "(ideographic-radical . %S)\t; %c%s"
606 (aref ideographic-radicals radical)
608 (setq attributes (delq 'ideographic-radical attributes))
611 (dolist (domain char-db-feature-domains)
612 (setq key (intern (format "%s@%s" 'ideographic-radical domain)))
613 (when (and (memq key attributes)
614 (setq value (get-char-attribute char key)))
616 (insert (format "(%s . %S)\t; %c%s"
619 (aref ideographic-radicals radical)
621 (setq attributes (delq key attributes))
623 (setq key (intern (format "%s@%s" 'ideographic-strokes domain)))
624 (when (and (memq key attributes)
625 (setq value (get-char-attribute char key)))
627 (insert (format "(%s . %S)%s"
631 (setq attributes (delq key attributes))
633 (setq key (intern (format "%s@%s" 'total-strokes domain)))
634 (when (and (memq key attributes)
635 (setq value (get-char-attribute char key)))
636 (insert (format "(%s . %S)%s"
640 (setq attributes (delq key attributes))
642 (dolist (feature '(ideographic-radical
645 (setq key (intern (format "%s@%s*sources" feature domain)))
646 (when (and (memq key attributes)
647 (setq value (get-char-attribute char key)))
648 (insert (format "(%s%s" key line-breaking))
650 (insert (format " %s" cell)))
652 (insert line-breaking)
653 (setq attributes (delq key attributes))
656 (when (and (memq 'ideographic-strokes attributes)
657 (setq value (get-char-attribute char 'ideographic-strokes)))
659 (insert (format "(ideographic-strokes . %S)%s"
662 (setq attributes (delq 'ideographic-strokes attributes))
664 (when (and (memq 'kangxi-radical attributes)
665 (setq value (get-char-attribute char 'kangxi-radical)))
666 (unless (eq value radical)
667 (insert (format "(kangxi-radical\t . %S)\t; %c%s"
669 (aref ideographic-radicals value)
672 (setq radical value)))
673 (setq attributes (delq 'kangxi-radical attributes))
675 (when (and (memq 'kangxi-strokes attributes)
676 (setq value (get-char-attribute char 'kangxi-strokes)))
677 (unless (eq value strokes)
678 (insert (format "(kangxi-strokes\t . %S)%s"
682 (setq strokes value)))
683 (setq attributes (delq 'kangxi-strokes attributes))
685 (when (and (memq 'japanese-radical attributes)
686 (setq value (get-char-attribute char 'japanese-radical)))
687 (unless (eq value radical)
688 (insert (format "(japanese-radical\t . %S)\t; %c%s"
690 (aref ideographic-radicals value)
693 (setq radical value)))
694 (setq attributes (delq 'japanese-radical attributes))
696 (when (and (memq 'japanese-strokes attributes)
697 (setq value (get-char-attribute char 'japanese-strokes)))
698 (unless (eq value strokes)
699 (insert (format "(japanese-strokes\t . %S)%s"
703 (setq strokes value)))
704 (setq attributes (delq 'japanese-strokes attributes))
706 (when (and (memq 'cns-radical attributes)
707 (setq value (get-char-attribute char 'cns-radical)))
708 (insert (format "(cns-radical\t . %S)\t; %c%s"
710 (aref ideographic-radicals value)
712 (setq attributes (delq 'cns-radical attributes))
714 (when (and (memq 'cns-strokes attributes)
715 (setq value (get-char-attribute char 'cns-strokes)))
716 (unless (eq value strokes)
717 (insert (format "(cns-strokes\t . %S)%s"
721 (setq strokes value)))
722 (setq attributes (delq 'cns-strokes attributes))
724 (when (and (memq 'shinjigen-1-radical attributes)
725 (setq value (get-char-attribute char 'shinjigen-1-radical)))
726 (unless (eq value radical)
727 (insert (format "(shinjigen-1-radical . %S)\t; %c%s"
729 (aref ideographic-radicals value)
732 (setq radical value)))
733 (setq attributes (delq 'shinjigen-1-radical attributes))
735 (when (and (memq 'ideographic- attributes)
736 (setq value (get-char-attribute char 'ideographic-)))
737 (insert "(ideographic- ")
738 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
741 (setq cell (car value))
743 (setq cell (decode-char '=ucs cell)))
744 (cond ((characterp cell)
748 (insert (format "%S" cell))
749 (char-db-insert-char-spec cell readable))
750 (setq separator lbs))
754 (if (consp (car cell))
755 (char-db-insert-char-spec cell readable)
756 (char-db-insert-char-reference cell readable))
757 (setq separator lbs))
761 (insert (prin1-to-string cell))
762 (setq separator " ")))
763 (setq value (cdr value)))
765 (insert line-breaking)
766 (setq attributes (delq 'ideographic- attributes)))
767 (when (and (memq 'total-strokes attributes)
768 (setq value (get-char-attribute char 'total-strokes)))
769 (insert (format "(total-strokes . %S)%s"
772 (setq attributes (delq 'total-strokes attributes))
774 (when (and (memq '->ideograph attributes)
775 (setq value (get-char-attribute char '->ideograph)))
776 (insert (format "(->ideograph\t%s)%s"
777 (mapconcat (lambda (code)
778 (cond ((symbolp code)
781 (format "#x%04X" code))
784 line-breaking code))))
787 (setq attributes (delq '->ideograph attributes))
789 (when (and (memq '->decomposition attributes)
790 (setq value (get-char-attribute char '->decomposition)))
791 (insert (format "(->decomposition\t%s)%s"
792 (mapconcat (lambda (code)
793 (cond ((symbolp code)
802 (format "#x%04X" code))
804 (format "%s%S" line-breaking code))))
807 (setq attributes (delq '->decomposition attributes))
809 (if (equal (get-char-attribute char '->titlecase)
810 (get-char-attribute char '->uppercase))
811 (setq attributes (delq '->titlecase attributes)))
812 (when (and (memq '->mojikyo attributes)
813 (setq value (get-char-attribute char '->mojikyo)))
814 (insert (format "(->mojikyo\t\t. %06d)\t; %c%s"
815 value (decode-char 'mojikyo value)
817 (setq attributes (delq '->mojikyo attributes))
819 (when (and (memq 'hanyu-dazidian-vol attributes)
820 (setq value (get-char-attribute char 'hanyu-dazidian-vol)))
821 (insert (format "(hanyu-dazidian-vol . %d)%s"
822 value line-breaking))
823 (setq attributes (delq 'hanyu-dazidian-vol attributes))
825 (when (and (memq 'hanyu-dazidian-page attributes)
826 (setq value (get-char-attribute char 'hanyu-dazidian-page)))
827 (insert (format "(hanyu-dazidian-page . %d)%s"
828 value line-breaking))
829 (setq attributes (delq 'hanyu-dazidian-page attributes))
831 (when (and (memq 'hanyu-dazidian-char attributes)
832 (setq value (get-char-attribute char 'hanyu-dazidian-char)))
833 (insert (format "(hanyu-dazidian-char . %d)%s"
834 value line-breaking))
835 (setq attributes (delq 'hanyu-dazidian-char attributes))
838 (when (memq '->ucs-unified attributes)
839 (setq attributes (delq '->ucs-unified attributes))
841 (when (memq 'composition attributes)
842 (setq attributes (delq 'composition attributes))
844 (setq rest ccs-attributes)
847 (setq value (get-char-attribute char (car rest)))
849 (if (>= (length (symbol-name (car rest))) 19)
851 (setq has-long-ccs-name t)
855 (setq rest (cdr rest)))
857 (setq name (car attributes))
858 (if (setq value (get-char-attribute char name))
859 (cond ((string-match "^=>ucs@" (symbol-name name))
860 (insert (format "(%-18s . #x%04X)\t; %c%s"
861 name value (decode-char '=ucs value)
864 ((eq name 'jisx0208-1978/4X)
865 (insert (format "(%-18s . #x%04X)%s"
868 ((or (eq name 'ideographic-structure)
869 (eq name 'ideographic-)
870 (string-match "^\\(->\\|<-\\)" (symbol-name name)))
871 (insert (format "(%-18s%s " name line-breaking))
872 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
875 (setq cell (car value))
877 (setq cell (decode-char '=ucs cell)))
878 (cond ((characterp cell)
882 (insert (format "%S" cell))
883 (char-db-insert-char-spec cell readable))
884 (setq separator lbs))
888 (if (consp (car cell))
889 (char-db-insert-char-spec cell readable)
890 (char-db-insert-char-reference cell readable))
891 (setq separator lbs))
895 (insert (prin1-to-string cell))
896 (setq separator " ")))
897 (setq value (cdr value)))
899 (insert line-breaking))
900 ((memq name '(ideograph=
901 original-ideograph-of
905 ;; simplified-ideograph-of
907 ;; ideographic-different-form-of
909 (insert (format "(%-18s%s " name line-breaking))
910 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
913 (setq cell (car value))
914 (if (and (consp cell)
919 (char-db-insert-alist cell readable)
920 (setq separator lbs))
923 (insert (prin1-to-string cell))
924 (setq separator " "))
925 (setq value (cdr value)))
927 (insert line-breaking))
929 (insert (format "(%-18s " name))
930 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
933 (setq cell (car value))
934 (if (and (consp cell)
936 (setq ret (condition-case nil
944 (setq key (car (car rest)))
945 (if (find-charset key)
946 (setq cal (cons key cal))
947 (setq al (cons key al)))
948 (setq rest (cdr rest)))
951 (insert-char-attributes ret
954 (setq separator lbs))
957 (insert (prin1-to-string cell))
958 (setq separator " "))
959 (setq value (cdr value)))
961 (insert line-breaking))
963 (insert (format "(%-18s . %S)%s"
967 (setq attributes (cdr attributes)))
968 (while ccs-attributes
969 (setq name (charset-name (car ccs-attributes)))
970 (if (and (not (memq name dest-ccss))
972 (setq value (get-char-attribute char name))
973 (setq dest-ccss (cons name dest-ccss))))
976 (cond ((memq name '(=daikanwa
977 =daikanwa-rev1 =daikanwa-rev2
979 (if has-long-ccs-name
980 "(%-26s . %05d)\t; %c%s"
981 "(%-18s . %05d)\t; %c%s"))
983 (if has-long-ccs-name
984 "(%-26s . %06d)\t; %c%s"
985 "(%-18s . %06d)\t; %c%s"))
986 ((>= (charset-dimension name) 2)
987 (if has-long-ccs-name
988 "(%-26s . #x%04X)\t; %c%s"
989 "(%-18s . #x%04X)\t; %c%s"))
991 (if has-long-ccs-name
992 "(%-26s . #x%02X)\t; %c%s"
993 "(%-18s . #x%02X)\t; %c%s")))
995 (if (= (charset-iso-graphic-plane name) 1)
997 (cond ((= (charset-dimension name) 1)
999 ((= (charset-dimension name) 2)
1001 ((= (charset-dimension name) 3)
1005 (char-db-decode-isolated-char name value)
1007 (setq ccs-attributes (cdr ccs-attributes)))
1010 (defun insert-char-data (char &optional readable
1011 attributes ccs-attributes)
1013 (narrow-to-region (point)(point))
1014 (insert "(define-char
1016 (insert-char-attributes char readable
1017 attributes ccs-attributes)
1019 (goto-char (point-min))
1020 (while (re-search-forward "[ \t]+$" nil t)
1023 (goto-char (point-min))
1024 (while (re-search-forward "[ \t][ \t][ \t]*" nil t)
1025 (let ((column (current-column))
1026 (indent-tabs-mode t))
1027 (delete-region (match-beginning 0) (point))
1028 (indent-to column)))
1029 (goto-char (point-max))
1030 ;; (tabify (point-min)(point-max))
1033 (defun insert-char-data-with-variant (char &optional printable
1035 script excluded-script)
1036 (insert-char-data char printable)
1037 (let ((variants (or (char-variants char)
1038 (let ((ucs (get-char-attribute char '->ucs)))
1040 (delete char (char-variants (int-char ucs)))))))
1042 (setq variants (sort variants #'<))
1044 (setq variant (car variants))
1045 (if (and (or (null script)
1046 (null (setq vs (get-char-attribute variant 'script)))
1048 (or (null excluded-script)
1049 (null (setq vs (get-char-attribute variant 'script)))
1050 (not (memq excluded-script vs))))
1051 (or (and no-ucs-unified (get-char-attribute variant '=ucs))
1052 (insert-char-data variant printable)))
1053 (setq variants (cdr variants))
1056 (defun insert-char-range-data (min max &optional script excluded-script)
1059 (while (<= code max)
1060 (setq char (decode-char '=ucs code))
1061 (if (encode-char char '=ucs 'defined-only)
1062 (insert-char-data-with-variant char nil 'no-ucs-unified
1063 script excluded-script))
1064 (setq code (1+ code)))))
1066 (defun write-char-range-data-to-file (min max file
1067 &optional script excluded-script)
1068 (let ((coding-system-for-write 'utf-8-mcs))
1070 (insert ";; -*- coding: utf-8-mcs -*-\n")
1071 (insert-char-range-data min max script excluded-script)
1072 (write-region (point-min)(point-max) file))))
1074 (defvar what-character-original-window-configuration)
1077 (defun what-char-definition (char)
1078 (interactive (list (char-after)))
1079 (let ((buf (get-buffer-create "*Character Description*"))
1080 (the-buf (current-buffer))
1081 (win-conf (current-window-configuration)))
1083 (make-local-variable 'what-character-original-window-configuration)
1084 (setq what-character-original-window-configuration win-conf)
1085 (setq buffer-read-only nil)
1089 (insert-char-data-with-variant char 'printable)
1090 (unless (char-attribute-alist char)
1091 (insert (format ";; = %c\n"
1092 (let* ((rest (split-char char))
1096 (setq code (logior (lsh code 8)
1098 (decode-char ccs code)))))
1099 ;; (char-db-update-comment)
1100 (set-buffer-modified-p nil)
1101 (view-mode the-buf (lambda (buf)
1102 (set-window-configuration
1103 what-character-original-window-configuration)
1105 (goto-char (point-min)))
1107 (set-window-configuration
1108 what-character-original-window-configuration)
1109 (signal (car err) (cdr err)))))))
1111 (provide 'char-db-util)
1113 ;;; char-db-util.el ends here