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
176 (defun char-db-make-char-spec (char)
178 (cond ((characterp char)
179 (cond ((and (setq ret (encode-char char '=ucs 'defined-only))
180 (not (and (<= #xE000 ret)(<= ret #xF8FF))))
181 (setq char-spec (list (cons '=ucs ret)))
182 (cond ((setq ret (get-char-attribute char 'name))
183 (setq char-spec (cons (cons 'name ret) char-spec))
185 ((setq ret (get-char-attribute char 'name*))
186 (setq char-spec (cons (cons 'name* ret) char-spec))
191 (let ((rest char-db-coded-charset-priority-list)
194 (setq ccs (charset-name
195 (find-charset (car rest))))
197 (encode-char char ccs
199 (throw 'tag (cons ccs ret)))
200 (setq rest (cdr rest))))))
201 (setq char-spec (list ret))
202 (dolist (ccs (delq (car ret) (charset-list)))
203 (if (and (or (charset-iso-final-char ccs)
209 (setq ret (encode-char char ccs 'defined-only)))
210 (setq char-spec (cons (cons ccs ret) char-spec))))
212 (setq char-spec (split-char char)))
213 (cond ((setq ret (get-char-attribute char 'name))
214 (setq char-spec (cons (cons 'name ret) char-spec))
216 ((setq ret (get-char-attribute char 'name*))
217 (setq char-spec (cons (cons 'name* ret) char-spec))
224 (defun char-db-insert-char-spec (char &optional readable column)
226 (setq column (current-column)))
227 (let (char-spec ret al cal key temp-char)
228 (setq char-spec (char-db-make-char-spec char))
229 (unless (or (characterp char) ; char
231 (setq char (find-char char-spec))
233 ;; define temporary character
234 ;; Current implementation is dirty.
235 (setq temp-char (define-char (cons '(ideograph-daikanwa . 0)
237 (remove-char-attribute temp-char 'ideograph-daikanwa)
238 (setq char temp-char))
242 (setq key (car (car char-spec)))
243 (unless (memq key char-db-ignored-attributes)
244 (if (find-charset key)
245 (if (encode-char char key 'defined-only)
246 (setq cal (cons key cal)))
247 (setq al (cons key al))))
248 (setq char-spec (cdr char-spec)))
250 (setq char-spec (char-db-make-char-spec char))
252 (setq key (car (car char-spec)))
253 (unless (memq key char-db-ignored-attributes)
254 (if (find-charset key)
255 (setq cal (cons key cal))
256 (setq al (cons key al))))
257 (setq char-spec (cdr char-spec)))
260 (memq 'ideographic-structure al))
261 (push 'ideographic-structure al))
262 (insert-char-attributes char
266 ;; undefine temporary character
267 ;; Current implementation is dirty.
268 (setq char-spec (char-attribute-alist temp-char))
270 (remove-char-attribute temp-char (car (car char-spec)))
271 (setq char-spec (cdr char-spec))))))
273 (defun char-db-insert-alist (alist &optional readable column)
275 (setq column (current-column)))
277 (concat "\n" (make-string (1+ column) ?\ )))
280 lbs cell rest separator)
283 (setq name (car (car alist))
284 value (cdr (car alist)))
285 (cond ((eq name 'char)
287 (if (setq ret (condition-case nil
294 (setq key (car (car value)))
295 (if (find-charset key)
296 (setq cal (cons key cal))
297 (setq al (cons key al)))
298 (setq value (cdr value)))
299 (insert-char-attributes ret
302 (insert (prin1-to-string value)))
304 (insert line-breaking))
306 (insert (format "(%-18s " name))
307 (setq lbs (concat "\n" (make-string (current-column) ?\ )))
309 (setq cell (car value))
310 (if (and (consp cell)
312 (setq ret (condition-case nil
321 (setq key (car (car rest)))
322 (if (find-charset key)
323 (setq cal (cons key cal))
324 (setq al (cons key al)))
325 (setq rest (cdr rest)))
328 (insert-char-attributes ret
331 (setq separator lbs))
334 (insert (prin1-to-string cell))
335 (setq separator " "))
336 (setq value (cdr value)))
338 (insert line-breaking))
340 (insert (format "(%-18s . %S)%s"
343 (setq alist (cdr alist))))
346 (defun char-db-insert-char-reference (plist &optional readable column)
348 (setq column (current-column)))
350 (concat "\n" (make-string (1+ column) ?\ )))
355 (setq name (pop plist))
356 (setq value (pop plist))
357 (cond ((eq name :char)
360 (cond ((numberp value)
361 (setq value (decode-char '=ucs value)))
363 ;; (setq value (or (find-char value)
366 (char-db-insert-char-spec value readable)
367 (insert line-breaking)
370 (insert (format "%s%s\t%d ; %c%s"
373 (aref ideographic-radicals value)
377 (insert (format "%s%s\t%S" separator name value))
378 (setq separator line-breaking)))
382 (defun char-db-decode-isolated-char (ccs code-point)
385 (cond ((eq ccs 'arabic-iso8859-6)
386 (decode-char ccs code-point))
387 ((and (memq ccs '(=gt-pj-1
398 (setq ret (decode-char ccs code-point))
399 (setq ret (encode-char ret '=gt 'defined-only)))
400 (decode-builtin-char '=gt ret))
402 (decode-builtin-char ccs code-point))))
403 (cond ((and (<= 0 (char-int ret))
404 (<= (char-int ret) #x1F))
405 (decode-char '=ucs (+ #x2400 (char-int ret))))
406 ((= (char-int ret) #x7F)
410 (defvar char-db-convert-obsolete-format t)
412 (defun insert-char-attributes (char &optional readable
413 attributes ccs-attributes
418 (if (consp attributes)
420 (dolist (name attributes)
421 (unless (memq name char-db-ignored-attributes)
424 (dolist (name (char-attribute-list))
425 (unless (memq name char-db-ignored-attributes)
426 (if (find-charset name)
430 #'char-attribute-name<))
432 (sort (if ccs-attributes
435 (dolist (name ccs-attributes)
436 (unless (memq name char-db-ignored-attributes)
441 (dolist (name (charset-list))
442 (unless (memq name char-db-ignored-attributes)
445 #'char-attribute-name<)))
447 (setq column (current-column)))
448 (let (name value has-long-ccs-name rest
451 (concat "\n" (make-string (1+ column) ?\ )))
452 lbs cell separator ret
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 'name* attributes)
466 (setq value (get-char-attribute char 'name*)))
468 (if (> (+ (current-column) (length value)) 48)
471 value line-breaking))
472 (setq attributes (delq 'name* attributes))
474 (when (and (memq 'script attributes)
475 (setq value (get-char-attribute char 'script)))
476 (insert (format "(script\t\t%s)%s"
477 (mapconcat (function prin1-to-string)
480 (setq attributes (delq 'script attributes))
482 (dolist (name '(=>ucs =>ucs*))
483 (when (and (memq name attributes)
484 (setq value (get-char-attribute char name)))
485 (insert (format "(%-18s . #x%04X)\t; %c%s"
486 name value (decode-char '=ucs value)
488 (setq attributes (delq name attributes))))
489 (dolist (name '(=>ucs@gb =>ucs@cns =>ucs@jis =>ucs@ks =>ucs@big5))
490 (when (and (memq name attributes)
491 (setq value (get-char-attribute char name)))
492 (insert (format "(%-18s . #x%04X)\t; %c%s"
497 (symbol-name name) 2)))
500 (setq attributes (delq name attributes))
502 (dolist (name '(=>ucs-gb =>ucs-cns =>ucs-jis =>ucs-ks =>ucs-big5))
503 (when (and (memq name attributes)
504 (setq value (get-char-attribute char name)))
505 (insert (format "(%-18s . #x%04X)\t; %c%s"
508 (substring (symbol-name name) 6)))
513 (symbol-name name) 6)))
516 (setq attributes (delq name attributes))))
517 (when (and (memq '->ucs attributes)
518 (setq value (get-char-attribute char '->ucs)))
519 (insert (format (if char-db-convert-obsolete-format
520 "(=>ucs\t\t. #x%04X)\t; %c%s"
521 "(->ucs\t\t. #x%04X)\t; %c%s")
522 value (decode-char '=ucs value)
524 (setq attributes (delq '->ucs attributes))
526 (when (and (memq 'general-category attributes)
527 (setq value (get-char-attribute char 'general-category)))
529 "(general-category\t%s) ; %s%s"
530 (mapconcat (lambda (cell)
533 (cond ((rassoc value unidata-normative-category-alist)
534 "Normative Category")
535 ((rassoc value unidata-informative-category-alist)
536 "Informative Category")
540 (setq attributes (delq 'general-category attributes))
542 (when (and (memq 'bidi-category attributes)
543 (setq value (get-char-attribute char 'bidi-category)))
544 (insert (format "(bidi-category\t. %S)%s"
547 (setq attributes (delq 'bidi-category attributes))
549 (unless (or (not (memq 'mirrored attributes))
550 (eq (setq value (get-char-attribute char 'mirrored 'empty))
552 (insert (format "(mirrored\t\t. %S)%s"
555 (setq attributes (delq 'mirrored attributes))
558 ((and (memq 'decimal-digit-value attributes)
559 (setq value (get-char-attribute char 'decimal-digit-value)))
560 (insert (format "(decimal-digit-value . %S)%s"
563 (setq attributes (delq 'decimal-digit-value attributes))
564 (when (and (memq 'digit-value attributes)
565 (setq value (get-char-attribute char 'digit-value)))
566 (insert (format "(digit-value\t . %S)%s"
569 (setq attributes (delq 'digit-value attributes))
571 (when (and (memq 'numeric-value attributes)
572 (setq value (get-char-attribute char 'numeric-value)))
573 (insert (format "(numeric-value\t . %S)%s"
576 (setq attributes (delq 'numeric-value attributes))
580 (when (and (memq 'digit-value attributes)
581 (setq value (get-char-attribute char 'digit-value)))
582 (insert (format "(digit-value\t. %S)%s"
585 (setq attributes (delq 'digit-value attributes))
587 (when (and (memq 'numeric-value attributes)
588 (setq value (get-char-attribute char 'numeric-value)))
589 (insert (format "(numeric-value\t. %S)%s"
592 (setq attributes (delq 'numeric-value attributes))
594 (when (and (memq 'iso-10646-comment attributes)
595 (setq value (get-char-attribute char 'iso-10646-comment)))
596 (insert (format "(iso-10646-comment\t. %S)%s"
599 (setq attributes (delq 'iso-10646-comment attributes))
601 (when (and (memq 'morohashi-daikanwa attributes)
602 (setq value (get-char-attribute char 'morohashi-daikanwa)))
603 (insert (format "(morohashi-daikanwa\t%s)%s"
604 (mapconcat (function prin1-to-string) value " ")
606 (setq attributes (delq 'morohashi-daikanwa attributes))
611 (dolist (domain '(ucs daikanwa cns))
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*sources"
634 'ideographic-radical domain)))
635 (when (and (memq key attributes)
636 (setq value (get-char-attribute char key)))
637 (insert (format "(%s%s" key line-breaking))
639 (insert (format " %s" cell)))
641 (insert line-breaking)
642 (setq attributes (delq key attributes))
645 (when (and (memq 'ideographic-radical attributes)
646 (setq value (get-char-attribute char 'ideographic-radical)))
648 (insert (format "(ideographic-radical . %S)\t; %c%s"
650 (aref ideographic-radicals radical)
652 (setq attributes (delq 'ideographic-radical attributes))
654 (when (and (memq 'ideographic-strokes attributes)
655 (setq value (get-char-attribute char 'ideographic-strokes)))
657 (insert (format "(ideographic-strokes . %S)%s"
660 (setq attributes (delq 'ideographic-strokes attributes))
662 (when (and (memq 'kangxi-radical attributes)
663 (setq value (get-char-attribute char 'kangxi-radical)))
664 (unless (eq value radical)
665 (insert (format "(kangxi-radical\t . %S)\t; %c%s"
667 (aref ideographic-radicals value)
670 (setq radical value)))
671 (setq attributes (delq 'kangxi-radical attributes))
673 (when (and (memq 'kangxi-strokes attributes)
674 (setq value (get-char-attribute char 'kangxi-strokes)))
675 (unless (eq value strokes)
676 (insert (format "(kangxi-strokes\t . %S)%s"
680 (setq strokes value)))
681 (setq attributes (delq 'kangxi-strokes attributes))
683 (when (and (memq 'japanese-radical attributes)
684 (setq value (get-char-attribute char 'japanese-radical)))
685 (unless (eq value radical)
686 (insert (format "(japanese-radical\t . %S)\t; %c%s"
688 (aref ideographic-radicals value)
691 (setq radical value)))
692 (setq attributes (delq 'japanese-radical attributes))
694 (when (and (memq 'japanese-strokes attributes)
695 (setq value (get-char-attribute char 'japanese-strokes)))
696 (unless (eq value strokes)
697 (insert (format "(japanese-strokes\t . %S)%s"
701 (setq strokes value)))
702 (setq attributes (delq 'japanese-strokes attributes))
704 (when (and (memq 'cns-radical attributes)
705 (setq value (get-char-attribute char 'cns-radical)))
706 (insert (format "(cns-radical\t . %S)\t; %c%s"
708 (aref ideographic-radicals value)
710 (setq attributes (delq 'cns-radical attributes))
712 (when (and (memq 'cns-strokes attributes)
713 (setq value (get-char-attribute char 'cns-strokes)))
714 (unless (eq value strokes)
715 (insert (format "(cns-strokes\t . %S)%s"
719 (setq strokes value)))
720 (setq attributes (delq 'cns-strokes attributes))
722 (when (and (memq 'shinjigen-1-radical attributes)
723 (setq value (get-char-attribute char 'shinjigen-1-radical)))
724 (unless (eq value radical)
725 (insert (format "(shinjigen-1-radical . %S)\t; %c%s"
727 (aref ideographic-radicals value)
730 (setq radical value)))
731 (setq attributes (delq 'shinjigen-1-radical attributes))
733 (when (and (memq 'ideographic- attributes)
734 (setq value (get-char-attribute char 'ideographic-)))
735 (insert "(ideographic- ")
736 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
739 (setq cell (car value))
741 (setq cell (decode-char '=ucs cell)))
742 (cond ((characterp cell)
746 (insert (format "%S" cell))
747 (char-db-insert-char-spec cell readable))
748 (setq separator lbs))
752 (if (consp (car cell))
753 (char-db-insert-char-spec cell readable)
754 (char-db-insert-char-reference cell readable))
755 (setq separator lbs))
759 (insert (prin1-to-string cell))
760 (setq separator " ")))
761 (setq value (cdr value)))
763 (insert line-breaking)
764 (setq attributes (delq 'ideographic- attributes)))
765 (when (and (memq 'total-strokes attributes)
766 (setq value (get-char-attribute char 'total-strokes)))
767 (insert (format "(total-strokes . %S)%s"
770 (setq attributes (delq 'total-strokes attributes))
772 (when (and (memq '->ideograph attributes)
773 (setq value (get-char-attribute char '->ideograph)))
774 (insert (format "(->ideograph\t%s)%s"
775 (mapconcat (lambda (code)
776 (cond ((symbolp code)
779 (format "#x%04X" code))
782 line-breaking code))))
785 (setq attributes (delq '->ideograph attributes))
787 (when (and (memq '->decomposition attributes)
788 (setq value (get-char-attribute char '->decomposition)))
789 (insert (format "(->decomposition\t%s)%s"
790 (mapconcat (lambda (code)
791 (cond ((symbolp code)
800 (format "#x%04X" code))
802 (format "%s%S" line-breaking code))))
805 (setq attributes (delq '->decomposition attributes))
807 (if (equal (get-char-attribute char '->titlecase)
808 (get-char-attribute char '->uppercase))
809 (setq attributes (delq '->titlecase attributes)))
810 (when (and (memq '->mojikyo attributes)
811 (setq value (get-char-attribute char '->mojikyo)))
812 (insert (format "(->mojikyo\t\t. %06d)\t; %c%s"
813 value (decode-char 'mojikyo value)
815 (setq attributes (delq '->mojikyo attributes))
817 (when (and (memq 'hanyu-dazidian-vol attributes)
818 (setq value (get-char-attribute char 'hanyu-dazidian-vol)))
819 (insert (format "(hanyu-dazidian-vol . %d)%s"
820 value line-breaking))
821 (setq attributes (delq 'hanyu-dazidian-vol attributes))
823 (when (and (memq 'hanyu-dazidian-page attributes)
824 (setq value (get-char-attribute char 'hanyu-dazidian-page)))
825 (insert (format "(hanyu-dazidian-page . %d)%s"
826 value line-breaking))
827 (setq attributes (delq 'hanyu-dazidian-page attributes))
829 (when (and (memq 'hanyu-dazidian-char attributes)
830 (setq value (get-char-attribute char 'hanyu-dazidian-char)))
831 (insert (format "(hanyu-dazidian-char . %d)%s"
832 value line-breaking))
833 (setq attributes (delq 'hanyu-dazidian-char attributes))
836 (when (memq '->ucs-variants attributes)
837 (setq attributes (delq '->ucs-variants attributes))
839 (when (memq 'composition attributes)
840 (setq attributes (delq 'composition attributes))
842 (setq rest ccs-attributes)
845 (setq value (get-char-attribute char (car rest)))
847 (if (>= (length (symbol-name (car rest))) 19)
849 (setq has-long-ccs-name t)
853 (setq rest (cdr rest)))
855 (setq name (car attributes))
856 (if (setq value (get-char-attribute char name))
857 (cond ((string-match "^=>ucs@" (symbol-name name))
858 (insert (format "(%-18s . #x%04X)\t; %c%s"
859 name value (decode-char '=ucs value)
862 ((eq name 'jisx0208-1978/4X)
863 (insert (format "(%-18s . #x%04X)%s"
866 ((or (eq name 'ideographic-structure)
867 (eq name 'ideographic-)
868 (string-match "^\\(->\\|<-\\)" (symbol-name name)))
869 (insert (format "(%-18s%s " name line-breaking))
870 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
873 (setq cell (car value))
875 (setq cell (decode-char '=ucs cell)))
876 (cond ((characterp cell)
880 (insert (format "%S" cell))
881 (char-db-insert-char-spec cell readable))
882 (setq separator lbs))
886 (if (consp (car cell))
887 (char-db-insert-char-spec cell readable)
888 (char-db-insert-char-reference cell readable))
889 (setq separator lbs))
893 (insert (prin1-to-string cell))
894 (setq separator " ")))
895 (setq value (cdr value)))
897 (insert line-breaking))
898 ((memq name '(ideograph=
899 original-ideograph-of
903 simplified-ideograph-of
905 ideographic-different-form-of))
906 (insert (format "(%-18s%s " name line-breaking))
907 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
910 (setq cell (car value))
911 (if (and (consp cell)
916 (char-db-insert-alist cell readable)
917 (setq separator lbs))
920 (insert (prin1-to-string cell))
921 (setq separator " "))
922 (setq value (cdr value)))
924 (insert line-breaking))
925 ;; ((string-match "^->" (symbol-name name))
927 ;; (format "(%-18s %s)%s"
929 ;; (mapconcat (lambda (code)
930 ;; (cond ((symbolp code)
931 ;; (symbol-name code))
933 ;; (format "#x%04X" code))
936 ;; line-breaking code))))
940 (insert (format "(%-18s " name))
941 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
944 (setq cell (car value))
945 (if (and (consp cell)
947 (setq ret (condition-case nil
955 (setq key (car (car rest)))
956 (if (find-charset key)
957 (setq cal (cons key cal))
958 (setq al (cons key al)))
959 (setq rest (cdr rest)))
962 (insert-char-attributes ret
965 (setq separator lbs))
968 (insert (prin1-to-string cell))
969 (setq separator " "))
970 (setq value (cdr value)))
972 (insert line-breaking))
974 (insert (format "(%-18s . %S)%s"
978 (setq attributes (cdr attributes)))
979 (while ccs-attributes
980 (setq name (charset-name (car ccs-attributes)))
981 (if (and (not (memq name dest-ccss))
983 (setq value (get-char-attribute char name))
984 (setq dest-ccss (cons name dest-ccss))))
987 (cond ((memq name '(=daikanwa
988 =daikanwa-rev1 =daikanwa-rev2
990 (if has-long-ccs-name
991 "(%-26s . %05d)\t; %c%s"
992 "(%-18s . %05d)\t; %c%s"))
994 (if has-long-ccs-name
995 "(%-26s . %06d)\t; %c%s"
996 "(%-18s . %06d)\t; %c%s"))
997 ((>= (charset-dimension name) 2)
998 (if has-long-ccs-name
999 "(%-26s . #x%04X)\t; %c%s"
1000 "(%-18s . #x%04X)\t; %c%s"))
1002 (if has-long-ccs-name
1003 "(%-26s . #x%02X)\t; %c%s"
1004 "(%-18s . #x%02X)\t; %c%s")))
1006 (if (= (charset-iso-graphic-plane name) 1)
1008 (cond ((= (charset-dimension name) 1)
1010 ((= (charset-dimension name) 2)
1012 ((= (charset-dimension name) 3)
1016 (char-db-decode-isolated-char name value)
1018 (setq ccs-attributes (cdr ccs-attributes)))
1021 (defun insert-char-data (char &optional readable
1022 attributes ccs-attributes)
1024 (narrow-to-region (point)(point))
1025 (insert "(define-char
1027 (insert-char-attributes char readable
1028 attributes ccs-attributes)
1030 (goto-char (point-min))
1031 (while (re-search-forward "[ \t]+$" nil t)
1034 (goto-char (point-min))
1035 (while (re-search-forward "[ \t][ \t][ \t]*" nil t)
1036 (let ((column (current-column))
1037 (indent-tabs-mode t))
1038 (delete-region (match-beginning 0) (point))
1039 (indent-to column)))
1040 (goto-char (point-max))
1041 ;; (tabify (point-min)(point-max))
1044 (defun insert-char-data-with-variant (char &optional printable
1046 script excluded-script)
1047 (insert-char-data char printable)
1048 (let ((variants (or (char-variants char)
1049 (let ((ucs (get-char-attribute char '->ucs)))
1051 (delete char (char-variants (int-char ucs)))))))
1053 (setq variants (sort variants #'<))
1055 (setq variant (car variants))
1056 (if (and (or (null script)
1057 (null (setq vs (get-char-attribute variant 'script)))
1059 (or (null excluded-script)
1060 (null (setq vs (get-char-attribute variant 'script)))
1061 (not (memq excluded-script vs))))
1062 (or (and no-ucs-variant (get-char-attribute variant '=ucs))
1063 (insert-char-data variant printable)))
1064 (setq variants (cdr variants))
1067 (defun insert-char-range-data (min max &optional script excluded-script)
1070 (while (<= code max)
1071 (setq char (decode-char '=ucs code))
1072 (if (encode-char char '=ucs 'defined-only)
1073 (insert-char-data-with-variant char nil 'no-ucs-variant
1074 script excluded-script))
1075 (setq code (1+ code)))))
1077 (defun write-char-range-data-to-file (min max file
1078 &optional script excluded-script)
1079 (let ((coding-system-for-write 'utf-8))
1081 (insert-char-range-data min max script excluded-script)
1082 (write-region (point-min)(point-max) file))))
1084 (defvar what-character-original-window-configuration)
1087 (defun what-char-definition (char)
1088 (interactive (list (char-after)))
1089 (let ((buf (get-buffer-create "*Character Description*"))
1090 (the-buf (current-buffer))
1091 (win-conf (current-window-configuration)))
1093 (make-local-variable 'what-character-original-window-configuration)
1094 (setq what-character-original-window-configuration win-conf)
1095 (setq buffer-read-only nil)
1099 (insert-char-data-with-variant char 'printable)
1100 (unless (char-attribute-alist char)
1101 (insert (format ";; = %c\n"
1102 (let* ((rest (split-char char))
1106 (setq code (logior (lsh code 8)
1108 (decode-char ccs code)))))
1109 ;; (char-db-update-comment)
1110 (set-buffer-modified-p nil)
1111 (view-mode the-buf (lambda (buf)
1112 (set-window-configuration
1113 what-character-original-window-configuration)
1115 (goto-char (point-min)))
1117 (set-window-configuration
1118 what-character-original-window-configuration)
1119 (signal (car err) (cdr err)))))))
1121 (provide 'char-db-util)
1123 ;;; char-db-util.el ends here