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: 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 misc unknown))
75 (defvar char-db-ignored-attributes nil)
77 (defun char-attribute-name< (ka kb)
82 (if (<= (charset-id ka) 0)
83 (if (<= (charset-id kb) 0)
85 ((= (charset-dimension ka)
86 (charset-dimension kb))
87 (> (charset-id ka)(charset-id kb)))
89 (> (charset-dimension ka)
90 (charset-dimension kb))
93 (if (<= (charset-id kb) 0)
95 (< (charset-id ka)(charset-id kb)))))
104 (string< (symbol-name ka)
110 (defvar char-db-coded-charset-priority-list
125 japanese-jisx0208-1978
166 (defun char-db-make-char-spec (char)
168 (cond ((characterp char)
169 (cond ((and (setq ret (encode-char char '=ucs 'defined-only))
170 (not (and (<= #xE000 ret)(<= ret #xF8FF))))
171 (setq char-spec (list (cons '=ucs ret)))
172 (cond ((setq ret (get-char-attribute char 'name))
173 (setq char-spec (cons (cons 'name ret) char-spec))
175 ((setq ret (get-char-attribute char 'name*))
176 (setq char-spec (cons (cons 'name* ret) char-spec))
181 (let ((rest char-db-coded-charset-priority-list)
184 (setq ccs (charset-name
185 (find-charset (car rest))))
187 (encode-char char ccs
189 (throw 'tag (cons ccs ret)))
190 (setq rest (cdr rest))))))
191 (setq char-spec (list ret))
192 (dolist (ccs (delq (car ret) (charset-list)))
193 (if (and (or (charset-iso-final-char ccs)
199 (setq ret (encode-char char ccs 'defined-only)))
200 (setq char-spec (cons (cons ccs ret) char-spec))))
202 (setq char-spec (split-char char)))
203 (cond ((setq ret (get-char-attribute char 'name))
204 (setq char-spec (cons (cons 'name ret) char-spec))
206 ((setq ret (get-char-attribute char 'name*))
207 (setq char-spec (cons (cons 'name* ret) char-spec))
214 (defun char-db-insert-char-spec (char &optional readable column)
216 (setq column (current-column)))
217 (let (char-spec al cal key temp-char)
218 (setq char-spec (char-db-make-char-spec char))
219 (unless (or (characterp char) ; char
221 (setq char (find-char char-spec))
223 ;; define temporary character
224 ;; Current implementation is dirty.
225 (setq temp-char (define-char (cons '(ideograph-daikanwa . 0)
227 (remove-char-attribute temp-char 'ideograph-daikanwa)
228 (setq char temp-char))
232 (setq key (car (car char-spec)))
233 (unless (memq key char-db-ignored-attributes)
234 (if (find-charset key)
235 (if (encode-char char key 'defined-only)
236 (setq cal (cons key cal)))
237 (setq al (cons key al))))
238 (setq char-spec (cdr char-spec)))
240 (setq char-spec (char-db-make-char-spec char))
242 (setq key (car (car char-spec)))
243 (unless (memq key char-db-ignored-attributes)
244 (if (find-charset key)
245 (setq cal (cons key cal))
246 (setq al (cons key al))))
247 (setq char-spec (cdr char-spec)))
250 (memq 'ideographic-structure al))
251 (push 'ideographic-structure al))
252 (insert-char-attributes char
256 ;; undefine temporary character
257 ;; Current implementation is dirty.
258 (setq char-spec (char-attribute-alist temp-char))
260 (remove-char-attribute temp-char (car (car char-spec)))
261 (setq char-spec (cdr char-spec))))))
263 (defun char-db-insert-alist (alist &optional readable column)
265 (setq column (current-column)))
267 (concat "\n" (make-string (1+ column) ?\ )))
270 lbs cell rest separator)
273 (setq name (car (car alist))
274 value (cdr (car alist)))
275 (cond ((eq name 'char)
277 (if (setq ret (condition-case nil
284 (setq key (car (car value)))
285 (if (find-charset key)
286 (setq cal (cons key cal))
287 (setq al (cons key al)))
288 (setq value (cdr value)))
289 (insert-char-attributes ret
292 (insert (prin1-to-string value)))
294 (insert line-breaking))
296 (insert (format "(%-18s " name))
297 (setq lbs (concat "\n" (make-string (current-column) ?\ )))
299 (setq cell (car value))
300 (if (and (consp cell)
302 (setq ret (condition-case nil
311 (setq key (car (car rest)))
312 (if (find-charset key)
313 (setq cal (cons key cal))
314 (setq al (cons key al)))
315 (setq rest (cdr rest)))
318 (insert-char-attributes ret
321 (setq separator lbs))
324 (insert (prin1-to-string cell))
325 (setq separator " "))
326 (setq value (cdr value)))
328 (insert line-breaking))
330 (insert (format "(%-18s . %S)%s"
333 (setq alist (cdr alist))))
336 (defun char-db-insert-char-reference (plist &optional readable column)
338 (setq column (current-column)))
340 (concat "\n" (make-string (1+ column) ?\ )))
345 (setq name (pop plist))
346 (setq value (pop plist))
347 (cond ((eq name :char)
350 (cond ((numberp value)
351 (setq value (decode-char '=ucs value)))
353 ;; (setq value (or (find-char value)
356 (char-db-insert-char-spec value readable)
357 (insert line-breaking)
360 (insert (format "%s%s\t%d ; %c%s"
363 (aref ideographic-radicals value)
367 (insert (format "%s%s\t%S" separator name value))
368 (setq separator line-breaking)))
372 (defun char-db-decode-isolated-char (ccs code-point)
375 (cond ((eq ccs 'arabic-iso8859-6)
376 (decode-char ccs code-point))
377 ((and (memq ccs '(=gt-pj-1
388 (setq ret (decode-char ccs code-point))
389 (setq ret (encode-char ret '=gt 'defined-only)))
390 (decode-builtin-char '=gt ret))
392 (decode-builtin-char ccs code-point))))
393 (cond ((and (<= 0 (char-int ret))
394 (<= (char-int ret) #x1F))
395 (decode-char '=ucs (+ #x2400 (char-int ret))))
396 ((= (char-int ret) #x7F)
400 (defvar char-db-convert-obsolete-format t)
402 (defun insert-char-attributes (char &optional readable
403 attributes ccs-attributes
408 (if (consp attributes)
410 (dolist (name attributes)
411 (unless (memq name char-db-ignored-attributes)
414 (dolist (name (char-attribute-list))
415 (unless (memq name char-db-ignored-attributes)
416 (if (find-charset name)
420 #'char-attribute-name<))
422 (sort (if ccs-attributes
425 (dolist (name ccs-attributes)
426 (unless (memq name char-db-ignored-attributes)
431 (dolist (name (charset-list))
432 (unless (memq name char-db-ignored-attributes)
435 #'char-attribute-name<)))
437 (setq column (current-column)))
438 (let (name value has-long-ccs-name rest
441 (concat "\n" (make-string (1+ column) ?\ )))
442 lbs cell separator ret
446 (when (and (memq 'name attributes)
447 (setq value (get-char-attribute char 'name)))
449 (if (> (+ (current-column) (length value)) 48)
452 value line-breaking))
453 (setq attributes (delq 'name attributes))
455 (when (and (memq 'name* attributes)
456 (setq value (get-char-attribute char 'name*)))
458 (if (> (+ (current-column) (length value)) 48)
461 value line-breaking))
462 (setq attributes (delq 'name* attributes))
464 (when (and (memq 'script attributes)
465 (setq value (get-char-attribute char 'script)))
466 (insert (format "(script\t\t%s)%s"
467 (mapconcat (function prin1-to-string)
470 (setq attributes (delq 'script attributes))
472 (dolist (name '(=>ucs =>ucs*))
473 (when (and (memq name attributes)
474 (setq value (get-char-attribute char name)))
475 (insert (format "(%-18s . #x%04X)\t; %c%s"
476 name value (decode-char '=ucs value)
478 (setq attributes (delq name attributes))))
479 (dolist (name '(=>ucs@gb =>ucs@cns =>ucs@jis =>ucs@ks =>ucs@big5))
480 (when (and (memq name attributes)
481 (setq value (get-char-attribute char name)))
482 (insert (format "(%-18s . #x%04X)\t; %c%s"
487 (symbol-name name) 2)))
490 (setq attributes (delq name attributes))
492 (dolist (name '(=>ucs-gb =>ucs-cns =>ucs-jis =>ucs-ks =>ucs-big5))
493 (when (and (memq name attributes)
494 (setq value (get-char-attribute char name)))
495 (insert (format "(%-18s . #x%04X)\t; %c%s"
498 (substring (symbol-name name) 6)))
503 (symbol-name name) 6)))
506 (setq attributes (delq name attributes))))
507 (when (and (memq '->ucs attributes)
508 (setq value (get-char-attribute char '->ucs)))
509 (insert (format (if char-db-convert-obsolete-format
510 "(=>ucs\t\t. #x%04X)\t; %c%s"
511 "(->ucs\t\t. #x%04X)\t; %c%s")
512 value (decode-char '=ucs value)
514 (setq attributes (delq '->ucs attributes))
516 (when (and (memq 'general-category attributes)
517 (setq value (get-char-attribute char 'general-category)))
519 "(general-category\t%s) ; %s%s"
520 (mapconcat (lambda (cell)
523 (cond ((rassoc value unidata-normative-category-alist)
524 "Normative Category")
525 ((rassoc value unidata-informative-category-alist)
526 "Informative Category")
530 (setq attributes (delq 'general-category attributes))
532 (when (and (memq 'bidi-category attributes)
533 (setq value (get-char-attribute char 'bidi-category)))
534 (insert (format "(bidi-category\t. %S)%s"
537 (setq attributes (delq 'bidi-category attributes))
539 (unless (or (not (memq 'mirrored attributes))
540 (eq (setq value (get-char-attribute char 'mirrored 'empty))
542 (insert (format "(mirrored\t\t. %S)%s"
545 (setq attributes (delq 'mirrored attributes))
548 ((and (memq 'decimal-digit-value attributes)
549 (setq value (get-char-attribute char 'decimal-digit-value)))
550 (insert (format "(decimal-digit-value . %S)%s"
553 (setq attributes (delq 'decimal-digit-value attributes))
554 (when (and (memq 'digit-value attributes)
555 (setq value (get-char-attribute char 'digit-value)))
556 (insert (format "(digit-value\t . %S)%s"
559 (setq attributes (delq 'digit-value attributes))
561 (when (and (memq 'numeric-value attributes)
562 (setq value (get-char-attribute char 'numeric-value)))
563 (insert (format "(numeric-value\t . %S)%s"
566 (setq attributes (delq 'numeric-value attributes))
570 (when (and (memq 'digit-value attributes)
571 (setq value (get-char-attribute char 'digit-value)))
572 (insert (format "(digit-value\t. %S)%s"
575 (setq attributes (delq 'digit-value attributes))
577 (when (and (memq 'numeric-value attributes)
578 (setq value (get-char-attribute char 'numeric-value)))
579 (insert (format "(numeric-value\t. %S)%s"
582 (setq attributes (delq 'numeric-value attributes))
584 (when (and (memq 'iso-10646-comment attributes)
585 (setq value (get-char-attribute char 'iso-10646-comment)))
586 (insert (format "(iso-10646-comment\t. %S)%s"
589 (setq attributes (delq 'iso-10646-comment attributes))
591 (when (and (memq 'morohashi-daikanwa attributes)
592 (setq value (get-char-attribute char 'morohashi-daikanwa)))
593 (insert (format "(morohashi-daikanwa\t%s)%s"
594 (mapconcat (function prin1-to-string) value " ")
596 (setq attributes (delq 'morohashi-daikanwa attributes))
600 (when (and (memq 'ideographic-radical attributes)
601 (setq value (get-char-attribute char 'ideographic-radical)))
603 (insert (format "(ideographic-radical . %S)\t; %c%s"
605 (aref ideographic-radicals radical)
607 (setq attributes (delq 'ideographic-radical attributes))
610 (dolist (domain char-db-feature-domains)
611 (setq key (intern (format "%s@%s" 'ideographic-radical domain)))
612 (when (and (memq key attributes)
613 (setq value (get-char-attribute char key)))
615 (insert (format "(%s . %S)\t; %c%s"
618 (aref ideographic-radicals radical)
620 (setq attributes (delq key attributes))
622 (setq key (intern (format "%s@%s" 'ideographic-strokes domain)))
623 (when (and (memq key attributes)
624 (setq value (get-char-attribute char key)))
626 (insert (format "(%s . %S)%s"
630 (setq attributes (delq key attributes))
632 (setq key (intern (format "%s@%s" 'total-strokes domain)))
633 (when (and (memq key attributes)
634 (setq value (get-char-attribute char key)))
635 (insert (format "(%s . %S)%s"
639 (setq attributes (delq key attributes))
641 (dolist (feature '(ideographic-radical
644 (setq key (intern (format "%s@%s*sources" feature domain)))
645 (when (and (memq key attributes)
646 (setq value (get-char-attribute char key)))
647 (insert (format "(%s%s" key line-breaking))
649 (insert (format " %s" cell)))
651 (insert line-breaking)
652 (setq attributes (delq key attributes))
655 (when (and (memq 'ideographic-strokes attributes)
656 (setq value (get-char-attribute char 'ideographic-strokes)))
658 (insert (format "(ideographic-strokes . %S)%s"
661 (setq attributes (delq 'ideographic-strokes attributes))
663 (when (and (memq 'kangxi-radical attributes)
664 (setq value (get-char-attribute char 'kangxi-radical)))
665 (unless (eq value radical)
666 (insert (format "(kangxi-radical\t . %S)\t; %c%s"
668 (aref ideographic-radicals value)
671 (setq radical value)))
672 (setq attributes (delq 'kangxi-radical attributes))
674 (when (and (memq 'kangxi-strokes attributes)
675 (setq value (get-char-attribute char 'kangxi-strokes)))
676 (unless (eq value strokes)
677 (insert (format "(kangxi-strokes\t . %S)%s"
681 (setq strokes value)))
682 (setq attributes (delq 'kangxi-strokes attributes))
684 (when (and (memq 'japanese-radical attributes)
685 (setq value (get-char-attribute char 'japanese-radical)))
686 (unless (eq value radical)
687 (insert (format "(japanese-radical\t . %S)\t; %c%s"
689 (aref ideographic-radicals value)
692 (setq radical value)))
693 (setq attributes (delq 'japanese-radical attributes))
695 (when (and (memq 'japanese-strokes attributes)
696 (setq value (get-char-attribute char 'japanese-strokes)))
697 (unless (eq value strokes)
698 (insert (format "(japanese-strokes\t . %S)%s"
702 (setq strokes value)))
703 (setq attributes (delq 'japanese-strokes attributes))
705 (when (and (memq 'cns-radical attributes)
706 (setq value (get-char-attribute char 'cns-radical)))
707 (insert (format "(cns-radical\t . %S)\t; %c%s"
709 (aref ideographic-radicals value)
711 (setq attributes (delq 'cns-radical attributes))
713 (when (and (memq 'cns-strokes attributes)
714 (setq value (get-char-attribute char 'cns-strokes)))
715 (unless (eq value strokes)
716 (insert (format "(cns-strokes\t . %S)%s"
720 (setq strokes value)))
721 (setq attributes (delq 'cns-strokes attributes))
723 (when (and (memq 'shinjigen-1-radical attributes)
724 (setq value (get-char-attribute char 'shinjigen-1-radical)))
725 (unless (eq value radical)
726 (insert (format "(shinjigen-1-radical . %S)\t; %c%s"
728 (aref ideographic-radicals value)
731 (setq radical value)))
732 (setq attributes (delq 'shinjigen-1-radical attributes))
734 (when (and (memq 'ideographic- attributes)
735 (setq value (get-char-attribute char 'ideographic-)))
736 (insert "(ideographic- ")
737 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
740 (setq cell (car value))
742 (setq cell (decode-char '=ucs cell)))
743 (cond ((characterp cell)
747 (insert (format "%S" cell))
748 (char-db-insert-char-spec cell readable))
749 (setq separator lbs))
753 (if (consp (car cell))
754 (char-db-insert-char-spec cell readable)
755 (char-db-insert-char-reference cell readable))
756 (setq separator lbs))
760 (insert (prin1-to-string cell))
761 (setq separator " ")))
762 (setq value (cdr value)))
764 (insert line-breaking)
765 (setq attributes (delq 'ideographic- attributes)))
766 (when (and (memq 'total-strokes attributes)
767 (setq value (get-char-attribute char 'total-strokes)))
768 (insert (format "(total-strokes . %S)%s"
771 (setq attributes (delq 'total-strokes attributes))
773 (when (and (memq '->ideograph attributes)
774 (setq value (get-char-attribute char '->ideograph)))
775 (insert (format "(->ideograph\t%s)%s"
776 (mapconcat (lambda (code)
777 (cond ((symbolp code)
780 (format "#x%04X" code))
783 line-breaking code))))
786 (setq attributes (delq '->ideograph attributes))
788 (when (and (memq '->decomposition attributes)
789 (setq value (get-char-attribute char '->decomposition)))
790 (insert (format "(->decomposition\t%s)%s"
791 (mapconcat (lambda (code)
792 (cond ((symbolp code)
801 (format "#x%04X" code))
803 (format "%s%S" line-breaking code))))
806 (setq attributes (delq '->decomposition attributes))
808 (if (equal (get-char-attribute char '->titlecase)
809 (get-char-attribute char '->uppercase))
810 (setq attributes (delq '->titlecase attributes)))
811 (when (and (memq '->mojikyo attributes)
812 (setq value (get-char-attribute char '->mojikyo)))
813 (insert (format "(->mojikyo\t\t. %06d)\t; %c%s"
814 value (decode-char 'mojikyo value)
816 (setq attributes (delq '->mojikyo attributes))
818 (when (and (memq 'hanyu-dazidian-vol attributes)
819 (setq value (get-char-attribute char 'hanyu-dazidian-vol)))
820 (insert (format "(hanyu-dazidian-vol . %d)%s"
821 value line-breaking))
822 (setq attributes (delq 'hanyu-dazidian-vol attributes))
824 (when (and (memq 'hanyu-dazidian-page attributes)
825 (setq value (get-char-attribute char 'hanyu-dazidian-page)))
826 (insert (format "(hanyu-dazidian-page . %d)%s"
827 value line-breaking))
828 (setq attributes (delq 'hanyu-dazidian-page attributes))
830 (when (and (memq 'hanyu-dazidian-char attributes)
831 (setq value (get-char-attribute char 'hanyu-dazidian-char)))
832 (insert (format "(hanyu-dazidian-char . %d)%s"
833 value line-breaking))
834 (setq attributes (delq 'hanyu-dazidian-char attributes))
837 (when (memq '->ucs-unified attributes)
838 (setq attributes (delq '->ucs-unified attributes))
840 (when (memq 'composition attributes)
841 (setq attributes (delq 'composition attributes))
843 (setq rest ccs-attributes)
846 (setq value (get-char-attribute char (car rest)))
848 (if (>= (length (symbol-name (car rest))) 19)
850 (setq has-long-ccs-name t)
854 (setq rest (cdr rest)))
856 (setq name (car attributes))
857 (if (setq value (get-char-attribute char name))
858 (cond ((string-match "^=>ucs@" (symbol-name name))
859 (insert (format "(%-18s . #x%04X)\t; %c%s"
860 name value (decode-char '=ucs value)
863 ((eq name 'jisx0208-1978/4X)
864 (insert (format "(%-18s . #x%04X)%s"
867 ((or (eq name 'ideographic-structure)
868 (eq name 'ideographic-)
869 (string-match "^\\(->\\|<-\\)" (symbol-name name)))
870 (insert (format "(%-18s%s " name line-breaking))
871 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
874 (setq cell (car value))
876 (setq cell (decode-char '=ucs cell)))
877 (cond ((characterp cell)
881 (insert (format "%S" cell))
882 (char-db-insert-char-spec cell readable))
883 (setq separator lbs))
887 (if (consp (car cell))
888 (char-db-insert-char-spec cell readable)
889 (char-db-insert-char-reference cell readable))
890 (setq separator lbs))
894 (insert (prin1-to-string cell))
895 (setq separator " ")))
896 (setq value (cdr value)))
898 (insert line-breaking))
899 ((memq name '(ideograph=
900 original-ideograph-of
904 simplified-ideograph-of
906 ideographic-different-form-of))
907 (insert (format "(%-18s%s " name line-breaking))
908 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
911 (setq cell (car value))
912 (if (and (consp cell)
917 (char-db-insert-alist cell readable)
918 (setq separator lbs))
921 (insert (prin1-to-string cell))
922 (setq separator " "))
923 (setq value (cdr value)))
925 (insert line-breaking))
926 ;; ((string-match "^->" (symbol-name name))
928 ;; (format "(%-18s %s)%s"
930 ;; (mapconcat (lambda (code)
931 ;; (cond ((symbolp code)
932 ;; (symbol-name code))
934 ;; (format "#x%04X" code))
937 ;; line-breaking code))))
941 (insert (format "(%-18s " name))
942 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
945 (setq cell (car value))
946 (if (and (consp cell)
948 (setq ret (condition-case nil
956 (setq key (car (car rest)))
957 (if (find-charset key)
958 (setq cal (cons key cal))
959 (setq al (cons key al)))
960 (setq rest (cdr rest)))
963 (insert-char-attributes ret
966 (setq separator lbs))
969 (insert (prin1-to-string cell))
970 (setq separator " "))
971 (setq value (cdr value)))
973 (insert line-breaking))
975 (insert (format "(%-18s . %S)%s"
979 (setq attributes (cdr attributes)))
980 (while ccs-attributes
981 (setq name (charset-name (car ccs-attributes)))
982 (if (and (not (memq name dest-ccss))
984 (setq value (get-char-attribute char name))
985 (setq dest-ccss (cons name dest-ccss))))
988 (cond ((memq name '(=daikanwa
989 =daikanwa-rev1 =daikanwa-rev2
991 (if has-long-ccs-name
992 "(%-26s . %05d)\t; %c%s"
993 "(%-18s . %05d)\t; %c%s"))
995 (if has-long-ccs-name
996 "(%-26s . %06d)\t; %c%s"
997 "(%-18s . %06d)\t; %c%s"))
998 ((>= (charset-dimension name) 2)
999 (if has-long-ccs-name
1000 "(%-26s . #x%04X)\t; %c%s"
1001 "(%-18s . #x%04X)\t; %c%s"))
1003 (if has-long-ccs-name
1004 "(%-26s . #x%02X)\t; %c%s"
1005 "(%-18s . #x%02X)\t; %c%s")))
1007 (if (= (charset-iso-graphic-plane name) 1)
1009 (cond ((= (charset-dimension name) 1)
1011 ((= (charset-dimension name) 2)
1013 ((= (charset-dimension name) 3)
1017 (char-db-decode-isolated-char name value)
1019 (setq ccs-attributes (cdr ccs-attributes)))
1022 (defun insert-char-data (char &optional readable
1023 attributes ccs-attributes)
1025 (narrow-to-region (point)(point))
1026 (insert "(define-char
1028 (insert-char-attributes char readable
1029 attributes ccs-attributes)
1031 (goto-char (point-min))
1032 (while (re-search-forward "[ \t]+$" nil t)
1035 (goto-char (point-min))
1036 (while (re-search-forward "[ \t][ \t][ \t]*" nil t)
1037 (let ((column (current-column))
1038 (indent-tabs-mode t))
1039 (delete-region (match-beginning 0) (point))
1040 (indent-to column)))
1041 (goto-char (point-max))
1042 ;; (tabify (point-min)(point-max))
1045 (defun insert-char-data-with-variant (char &optional printable
1047 script excluded-script)
1048 (insert-char-data char printable)
1049 (let ((variants (or (char-variants char)
1050 (let ((ucs (get-char-attribute char '->ucs)))
1052 (delete char (char-variants (int-char ucs)))))))
1054 (setq variants (sort variants #'<))
1056 (setq variant (car variants))
1057 (if (and (or (null script)
1058 (null (setq vs (get-char-attribute variant 'script)))
1060 (or (null excluded-script)
1061 (null (setq vs (get-char-attribute variant 'script)))
1062 (not (memq excluded-script vs))))
1063 (or (and no-ucs-unified (get-char-attribute variant '=ucs))
1064 (insert-char-data variant printable)))
1065 (setq variants (cdr variants))
1068 (defun insert-char-range-data (min max &optional script excluded-script)
1071 (while (<= code max)
1072 (setq char (decode-char '=ucs code))
1073 (if (encode-char char '=ucs 'defined-only)
1074 (insert-char-data-with-variant char nil 'no-ucs-unified
1075 script excluded-script))
1076 (setq code (1+ code)))))
1078 (defun write-char-range-data-to-file (min max file
1079 &optional script excluded-script)
1080 (let ((coding-system-for-write 'utf-8-mcs))
1082 (insert ";; -*- coding: utf-8-mcs -*-\n")
1083 (insert-char-range-data min max script excluded-script)
1084 (write-region (point-min)(point-max) file))))
1086 (defvar what-character-original-window-configuration)
1089 (defun what-char-definition (char)
1090 (interactive (list (char-after)))
1091 (let ((buf (get-buffer-create "*Character Description*"))
1092 (the-buf (current-buffer))
1093 (win-conf (current-window-configuration)))
1095 (make-local-variable 'what-character-original-window-configuration)
1096 (setq what-character-original-window-configuration win-conf)
1097 (setq buffer-read-only nil)
1101 (insert-char-data-with-variant char 'printable)
1102 (unless (char-attribute-alist char)
1103 (insert (format ";; = %c\n"
1104 (let* ((rest (split-char char))
1108 (setq code (logior (lsh code 8)
1110 (decode-char ccs code)))))
1111 ;; (char-db-update-comment)
1112 (set-buffer-modified-p nil)
1113 (view-mode the-buf (lambda (buf)
1114 (set-window-configuration
1115 what-character-original-window-configuration)
1117 (goto-char (point-min)))
1119 (set-window-configuration
1120 what-character-original-window-configuration)
1121 (signal (car err) (cdr err)))))))
1123 (provide 'char-db-util)
1125 ;;; char-db-util.el ends here