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 (< (charset-id ka)(charset-id kb))))
102 (string< (symbol-name ka)
108 (defvar char-db-coded-charset-priority-list
123 japanese-jisx0208-1978
164 (defun char-db-make-char-spec (char)
166 (cond ((characterp char)
167 (cond ((and (setq ret (encode-char char '=ucs 'defined-only))
168 (not (and (<= #xE000 ret)(<= ret #xF8FF))))
169 (setq char-spec (list (cons '=ucs ret)))
170 (cond ((setq ret (get-char-attribute char 'name))
171 (setq char-spec (cons (cons 'name ret) char-spec))
173 ((setq ret (get-char-attribute char 'name*))
174 (setq char-spec (cons (cons 'name* ret) char-spec))
179 (let ((rest char-db-coded-charset-priority-list)
182 (setq ccs (charset-name
183 (find-charset (car rest))))
185 (encode-char char ccs
187 (throw 'tag (cons ccs ret)))
188 (setq rest (cdr rest))))))
189 (setq char-spec (list ret))
190 (dolist (ccs (delq (car ret) (charset-list)))
191 (if (and (or (charset-iso-final-char ccs)
197 (setq ret (encode-char char ccs 'defined-only)))
198 (setq char-spec (cons (cons ccs ret) char-spec))))
200 (setq char-spec (split-char char)))
201 (cond ((setq ret (get-char-attribute char 'name))
202 (setq char-spec (cons (cons 'name ret) char-spec))
204 ((setq ret (get-char-attribute char 'name*))
205 (setq char-spec (cons (cons 'name* ret) char-spec))
212 (defun char-db-insert-char-spec (char &optional readable column)
214 (setq column (current-column)))
215 (let (char-spec ret al cal key temp-char)
216 (setq char-spec (char-db-make-char-spec char))
217 (unless (or (characterp char) ; char
219 (setq char (find-char char-spec))
221 ;; define temporary character
222 ;; Current implementation is dirty.
223 (setq temp-char (define-char (cons '(ideograph-daikanwa . 0)
225 (remove-char-attribute temp-char 'ideograph-daikanwa)
226 (setq char temp-char))
230 (setq key (car (car char-spec)))
231 (unless (memq key char-db-ignored-attributes)
232 (if (find-charset key)
233 (if (encode-char char key 'defined-only)
234 (setq cal (cons key cal)))
235 (setq al (cons key al))))
236 (setq char-spec (cdr char-spec)))
238 (setq char-spec (char-db-make-char-spec char))
240 (setq key (car (car char-spec)))
241 (unless (memq key char-db-ignored-attributes)
242 (if (find-charset key)
243 (setq cal (cons key cal))
244 (setq al (cons key al))))
245 (setq char-spec (cdr char-spec)))
248 (memq 'ideographic-structure al))
249 (push 'ideographic-structure al))
250 (insert-char-attributes char
254 ;; undefine temporary character
255 ;; Current implementation is dirty.
256 (setq char-spec (char-attribute-alist temp-char))
258 (remove-char-attribute temp-char (car (car char-spec)))
259 (setq char-spec (cdr char-spec))))))
261 (defun char-db-insert-alist (alist &optional readable column)
263 (setq column (current-column)))
265 (concat "\n" (make-string (1+ column) ?\ )))
268 lbs cell rest separator)
271 (setq name (car (car alist))
272 value (cdr (car alist)))
273 (cond ((eq name 'char)
275 (if (setq ret (condition-case nil
282 (setq key (car (car value)))
283 (if (find-charset key)
284 (setq cal (cons key cal))
285 (setq al (cons key al)))
286 (setq value (cdr value)))
287 (insert-char-attributes ret
290 (insert (prin1-to-string value)))
292 (insert line-breaking))
294 (insert (format "(%-18s " name))
295 (setq lbs (concat "\n" (make-string (current-column) ?\ )))
297 (setq cell (car value))
298 (if (and (consp cell)
300 (setq ret (condition-case nil
309 (setq key (car (car rest)))
310 (if (find-charset key)
311 (setq cal (cons key cal))
312 (setq al (cons key al)))
313 (setq rest (cdr rest)))
316 (insert-char-attributes ret
319 (setq separator lbs))
322 (insert (prin1-to-string cell))
323 (setq separator " "))
324 (setq value (cdr value)))
326 (insert line-breaking))
328 (insert (format "(%-18s . %S)%s"
331 (setq alist (cdr alist))))
334 (defun char-db-insert-char-reference (plist &optional readable column)
336 (setq column (current-column)))
338 (concat "\n" (make-string (1+ column) ?\ )))
343 (setq name (pop plist))
344 (setq value (pop plist))
345 (cond ((eq name :char)
348 (cond ((numberp value)
349 (setq value (decode-char '=ucs value)))
351 ;; (setq value (or (find-char value)
354 (char-db-insert-char-spec value readable)
355 (insert line-breaking)
358 (insert (format "%s%s\t%d ; %c%s"
361 (aref ideographic-radicals value)
365 (insert (format "%s%s\t%S" separator name value))
366 (setq separator line-breaking)))
370 (defun char-db-decode-isolated-char (ccs code-point)
373 (cond ((eq ccs 'arabic-iso8859-6)
374 (decode-char ccs code-point))
375 ((and (memq ccs '(=gt-pj-1
386 (setq ret (decode-char ccs code-point))
387 (setq ret (encode-char ret '=gt 'defined-only)))
388 (decode-builtin-char '=gt ret))
390 (decode-builtin-char ccs code-point))))
391 (cond ((and (<= 0 (char-int ret))
392 (<= (char-int ret) #x1F))
393 (decode-char '=ucs (+ #x2400 (char-int ret))))
394 ((= (char-int ret) #x7F)
398 (defvar char-db-convert-obsolete-format t)
400 (defun insert-char-attributes (char &optional readable
401 attributes ccs-attributes
406 (if (consp attributes)
408 (dolist (name attributes)
409 (unless (memq name char-db-ignored-attributes)
412 (dolist (name (char-attribute-list))
413 (unless (memq name char-db-ignored-attributes)
414 (if (find-charset name)
418 #'char-attribute-name<))
420 (sort (if ccs-attributes
423 (dolist (name ccs-attributes)
424 (unless (memq name char-db-ignored-attributes)
429 (dolist (name (charset-list))
430 (unless (memq name char-db-ignored-attributes)
433 #'char-attribute-name<)))
435 (setq column (current-column)))
436 (let (name value has-long-ccs-name rest
439 (concat "\n" (make-string (1+ column) ?\ )))
440 lbs cell separator ret
444 (when (and (memq 'name attributes)
445 (setq value (get-char-attribute char 'name)))
447 (if (> (+ (current-column) (length value)) 48)
450 value line-breaking))
451 (setq attributes (delq 'name attributes))
453 (when (and (memq 'name* attributes)
454 (setq value (get-char-attribute char 'name*)))
456 (if (> (+ (current-column) (length value)) 48)
459 value line-breaking))
460 (setq attributes (delq 'name* attributes))
462 (when (and (memq 'script attributes)
463 (setq value (get-char-attribute char 'script)))
464 (insert (format "(script\t\t%s)%s"
465 (mapconcat (function prin1-to-string)
468 (setq attributes (delq 'script attributes))
470 (dolist (name '(=>ucs =>ucs*))
471 (when (and (memq name attributes)
472 (setq value (get-char-attribute char name)))
473 (insert (format "(%-18s . #x%04X)\t; %c%s"
474 name value (decode-char '=ucs value)
476 (setq attributes (delq name attributes))))
477 (dolist (name '(=>ucs@gb =>ucs@cns =>ucs@jis =>ucs@ks =>ucs@big5))
478 (when (and (memq name attributes)
479 (setq value (get-char-attribute char name)))
480 (insert (format "(%-18s . #x%04X)\t; %c%s"
485 (symbol-name name) 2)))
488 (setq attributes (delq name attributes))
490 (dolist (name '(=>ucs-gb =>ucs-cns =>ucs-jis =>ucs-ks =>ucs-big5))
491 (when (and (memq name attributes)
492 (setq value (get-char-attribute char name)))
493 (insert (format "(%-18s . #x%04X)\t; %c%s"
496 (substring (symbol-name name) 6)))
501 (symbol-name name) 6)))
504 (setq attributes (delq name attributes))))
505 (when (and (memq '->ucs attributes)
506 (setq value (get-char-attribute char '->ucs)))
507 (insert (format (if char-db-convert-obsolete-format
508 "(=>ucs\t\t. #x%04X)\t; %c%s"
509 "(->ucs\t\t. #x%04X)\t; %c%s")
510 value (decode-char '=ucs value)
512 (setq attributes (delq '->ucs attributes))
514 (when (and (memq 'general-category attributes)
515 (setq value (get-char-attribute char 'general-category)))
517 "(general-category\t%s) ; %s%s"
518 (mapconcat (lambda (cell)
521 (cond ((rassoc value unidata-normative-category-alist)
522 "Normative Category")
523 ((rassoc value unidata-informative-category-alist)
524 "Informative Category")
528 (setq attributes (delq 'general-category attributes))
530 (when (and (memq 'bidi-category attributes)
531 (setq value (get-char-attribute char 'bidi-category)))
532 (insert (format "(bidi-category\t. %S)%s"
535 (setq attributes (delq 'bidi-category attributes))
537 (unless (or (not (memq 'mirrored attributes))
538 (eq (setq value (get-char-attribute char 'mirrored 'empty))
540 (insert (format "(mirrored\t\t. %S)%s"
543 (setq attributes (delq 'mirrored attributes))
546 ((and (memq 'decimal-digit-value attributes)
547 (setq value (get-char-attribute char 'decimal-digit-value)))
548 (insert (format "(decimal-digit-value . %S)%s"
551 (setq attributes (delq 'decimal-digit-value attributes))
552 (when (and (memq 'digit-value attributes)
553 (setq value (get-char-attribute char 'digit-value)))
554 (insert (format "(digit-value\t . %S)%s"
557 (setq attributes (delq 'digit-value attributes))
559 (when (and (memq 'numeric-value attributes)
560 (setq value (get-char-attribute char 'numeric-value)))
561 (insert (format "(numeric-value\t . %S)%s"
564 (setq attributes (delq 'numeric-value attributes))
568 (when (and (memq 'digit-value attributes)
569 (setq value (get-char-attribute char 'digit-value)))
570 (insert (format "(digit-value\t. %S)%s"
573 (setq attributes (delq 'digit-value attributes))
575 (when (and (memq 'numeric-value attributes)
576 (setq value (get-char-attribute char 'numeric-value)))
577 (insert (format "(numeric-value\t. %S)%s"
580 (setq attributes (delq 'numeric-value attributes))
582 (when (and (memq 'iso-10646-comment attributes)
583 (setq value (get-char-attribute char 'iso-10646-comment)))
584 (insert (format "(iso-10646-comment\t. %S)%s"
587 (setq attributes (delq 'iso-10646-comment attributes))
589 (when (and (memq 'morohashi-daikanwa attributes)
590 (setq value (get-char-attribute char 'morohashi-daikanwa)))
591 (insert (format "(morohashi-daikanwa\t%s)%s"
592 (mapconcat (function prin1-to-string) value " ")
594 (setq attributes (delq 'morohashi-daikanwa attributes))
598 (when (and (memq 'ideographic-radical attributes)
599 (setq value (get-char-attribute char 'ideographic-radical)))
601 (insert (format "(ideographic-radical . %S)\t; %c%s"
603 (aref ideographic-radicals radical)
605 (setq attributes (delq 'ideographic-radical attributes))
608 (dolist (domain char-db-feature-domains)
609 (setq key (intern (format "%s@%s" 'ideographic-radical domain)))
610 (when (and (memq key attributes)
611 (setq value (get-char-attribute char key)))
613 (insert (format "(%s . %S)\t; %c%s"
616 (aref ideographic-radicals radical)
618 (setq attributes (delq key attributes))
620 (setq key (intern (format "%s@%s" 'ideographic-strokes domain)))
621 (when (and (memq key attributes)
622 (setq value (get-char-attribute char key)))
624 (insert (format "(%s . %S)%s"
628 (setq attributes (delq key attributes))
630 (setq key (intern (format "%s@%s" 'total-strokes domain)))
631 (when (and (memq key attributes)
632 (setq value (get-char-attribute char key)))
633 (insert (format "(%s . %S)%s"
637 (setq attributes (delq key attributes))
639 (dolist (feature '(ideographic-radical
642 (setq key (intern (format "%s@%s*sources" feature domain)))
643 (when (and (memq key attributes)
644 (setq value (get-char-attribute char key)))
645 (insert (format "(%s%s" key line-breaking))
647 (insert (format " %s" cell)))
649 (insert line-breaking)
650 (setq attributes (delq key attributes))
653 (when (and (memq 'ideographic-strokes attributes)
654 (setq value (get-char-attribute char 'ideographic-strokes)))
656 (insert (format "(ideographic-strokes . %S)%s"
659 (setq attributes (delq 'ideographic-strokes attributes))
661 (when (and (memq 'kangxi-radical attributes)
662 (setq value (get-char-attribute char 'kangxi-radical)))
663 (unless (eq value radical)
664 (insert (format "(kangxi-radical\t . %S)\t; %c%s"
666 (aref ideographic-radicals value)
669 (setq radical value)))
670 (setq attributes (delq 'kangxi-radical attributes))
672 (when (and (memq 'kangxi-strokes attributes)
673 (setq value (get-char-attribute char 'kangxi-strokes)))
674 (unless (eq value strokes)
675 (insert (format "(kangxi-strokes\t . %S)%s"
679 (setq strokes value)))
680 (setq attributes (delq 'kangxi-strokes attributes))
682 (when (and (memq 'japanese-radical attributes)
683 (setq value (get-char-attribute char 'japanese-radical)))
684 (unless (eq value radical)
685 (insert (format "(japanese-radical\t . %S)\t; %c%s"
687 (aref ideographic-radicals value)
690 (setq radical value)))
691 (setq attributes (delq 'japanese-radical attributes))
693 (when (and (memq 'japanese-strokes attributes)
694 (setq value (get-char-attribute char 'japanese-strokes)))
695 (unless (eq value strokes)
696 (insert (format "(japanese-strokes\t . %S)%s"
700 (setq strokes value)))
701 (setq attributes (delq 'japanese-strokes attributes))
703 (when (and (memq 'cns-radical attributes)
704 (setq value (get-char-attribute char 'cns-radical)))
705 (insert (format "(cns-radical\t . %S)\t; %c%s"
707 (aref ideographic-radicals value)
709 (setq attributes (delq 'cns-radical attributes))
711 (when (and (memq 'cns-strokes attributes)
712 (setq value (get-char-attribute char 'cns-strokes)))
713 (unless (eq value strokes)
714 (insert (format "(cns-strokes\t . %S)%s"
718 (setq strokes value)))
719 (setq attributes (delq 'cns-strokes attributes))
721 (when (and (memq 'shinjigen-1-radical attributes)
722 (setq value (get-char-attribute char 'shinjigen-1-radical)))
723 (unless (eq value radical)
724 (insert (format "(shinjigen-1-radical . %S)\t; %c%s"
726 (aref ideographic-radicals value)
729 (setq radical value)))
730 (setq attributes (delq 'shinjigen-1-radical attributes))
732 (when (and (memq 'ideographic- attributes)
733 (setq value (get-char-attribute char 'ideographic-)))
734 (insert "(ideographic- ")
735 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
738 (setq cell (car value))
740 (setq cell (decode-char '=ucs cell)))
741 (cond ((characterp cell)
745 (insert (format "%S" cell))
746 (char-db-insert-char-spec cell readable))
747 (setq separator lbs))
751 (if (consp (car cell))
752 (char-db-insert-char-spec cell readable)
753 (char-db-insert-char-reference cell readable))
754 (setq separator lbs))
758 (insert (prin1-to-string cell))
759 (setq separator " ")))
760 (setq value (cdr value)))
762 (insert line-breaking)
763 (setq attributes (delq 'ideographic- attributes)))
764 (when (and (memq 'total-strokes attributes)
765 (setq value (get-char-attribute char 'total-strokes)))
766 (insert (format "(total-strokes . %S)%s"
769 (setq attributes (delq 'total-strokes attributes))
771 (when (and (memq '->ideograph attributes)
772 (setq value (get-char-attribute char '->ideograph)))
773 (insert (format "(->ideograph\t%s)%s"
774 (mapconcat (lambda (code)
775 (cond ((symbolp code)
778 (format "#x%04X" code))
781 line-breaking code))))
784 (setq attributes (delq '->ideograph attributes))
786 (when (and (memq '->decomposition attributes)
787 (setq value (get-char-attribute char '->decomposition)))
788 (insert (format "(->decomposition\t%s)%s"
789 (mapconcat (lambda (code)
790 (cond ((symbolp code)
799 (format "#x%04X" code))
801 (format "%s%S" line-breaking code))))
804 (setq attributes (delq '->decomposition attributes))
806 (if (equal (get-char-attribute char '->titlecase)
807 (get-char-attribute char '->uppercase))
808 (setq attributes (delq '->titlecase attributes)))
809 (when (and (memq '->mojikyo attributes)
810 (setq value (get-char-attribute char '->mojikyo)))
811 (insert (format "(->mojikyo\t\t. %06d)\t; %c%s"
812 value (decode-char 'mojikyo value)
814 (setq attributes (delq '->mojikyo attributes))
816 (when (and (memq 'hanyu-dazidian-vol attributes)
817 (setq value (get-char-attribute char 'hanyu-dazidian-vol)))
818 (insert (format "(hanyu-dazidian-vol . %d)%s"
819 value line-breaking))
820 (setq attributes (delq 'hanyu-dazidian-vol attributes))
822 (when (and (memq 'hanyu-dazidian-page attributes)
823 (setq value (get-char-attribute char 'hanyu-dazidian-page)))
824 (insert (format "(hanyu-dazidian-page . %d)%s"
825 value line-breaking))
826 (setq attributes (delq 'hanyu-dazidian-page attributes))
828 (when (and (memq 'hanyu-dazidian-char attributes)
829 (setq value (get-char-attribute char 'hanyu-dazidian-char)))
830 (insert (format "(hanyu-dazidian-char . %d)%s"
831 value line-breaking))
832 (setq attributes (delq 'hanyu-dazidian-char attributes))
835 (when (memq '->ucs-unified attributes)
836 (setq attributes (delq '->ucs-unified attributes))
838 (when (memq 'composition attributes)
839 (setq attributes (delq 'composition attributes))
841 (setq rest ccs-attributes)
844 (setq value (get-char-attribute char (car rest)))
846 (if (>= (length (symbol-name (car rest))) 19)
848 (setq has-long-ccs-name t)
852 (setq rest (cdr rest)))
854 (setq name (car attributes))
855 (if (setq value (get-char-attribute char name))
856 (cond ((string-match "^=>ucs@" (symbol-name name))
857 (insert (format "(%-18s . #x%04X)\t; %c%s"
858 name value (decode-char '=ucs value)
861 ((eq name 'jisx0208-1978/4X)
862 (insert (format "(%-18s . #x%04X)%s"
865 ((or (eq name 'ideographic-structure)
866 (eq name 'ideographic-)
867 (string-match "^\\(->\\|<-\\)" (symbol-name name)))
868 (insert (format "(%-18s%s " name line-breaking))
869 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
872 (setq cell (car value))
874 (setq cell (decode-char '=ucs cell)))
875 (cond ((characterp cell)
879 (insert (format "%S" cell))
880 (char-db-insert-char-spec cell readable))
881 (setq separator lbs))
885 (if (consp (car cell))
886 (char-db-insert-char-spec cell readable)
887 (char-db-insert-char-reference cell readable))
888 (setq separator lbs))
892 (insert (prin1-to-string cell))
893 (setq separator " ")))
894 (setq value (cdr value)))
896 (insert line-breaking))
897 ((memq name '(ideograph=
898 original-ideograph-of
902 simplified-ideograph-of
904 ideographic-different-form-of))
905 (insert (format "(%-18s%s " name line-breaking))
906 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
909 (setq cell (car value))
910 (if (and (consp cell)
915 (char-db-insert-alist cell readable)
916 (setq separator lbs))
919 (insert (prin1-to-string cell))
920 (setq separator " "))
921 (setq value (cdr value)))
923 (insert line-breaking))
924 ;; ((string-match "^->" (symbol-name name))
926 ;; (format "(%-18s %s)%s"
928 ;; (mapconcat (lambda (code)
929 ;; (cond ((symbolp code)
930 ;; (symbol-name code))
932 ;; (format "#x%04X" code))
935 ;; line-breaking code))))
939 (insert (format "(%-18s " name))
940 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
943 (setq cell (car value))
944 (if (and (consp cell)
946 (setq ret (condition-case nil
954 (setq key (car (car rest)))
955 (if (find-charset key)
956 (setq cal (cons key cal))
957 (setq al (cons key al)))
958 (setq rest (cdr rest)))
961 (insert-char-attributes ret
964 (setq separator lbs))
967 (insert (prin1-to-string cell))
968 (setq separator " "))
969 (setq value (cdr value)))
971 (insert line-breaking))
973 (insert (format "(%-18s . %S)%s"
977 (setq attributes (cdr attributes)))
978 (while ccs-attributes
979 (setq name (charset-name (car ccs-attributes)))
980 (if (and (not (memq name dest-ccss))
982 (setq value (get-char-attribute char name))
983 (setq dest-ccss (cons name dest-ccss))))
986 (cond ((memq name '(=daikanwa
987 =daikanwa-rev1 =daikanwa-rev2
989 (if has-long-ccs-name
990 "(%-26s . %05d)\t; %c%s"
991 "(%-18s . %05d)\t; %c%s"))
993 (if has-long-ccs-name
994 "(%-26s . %06d)\t; %c%s"
995 "(%-18s . %06d)\t; %c%s"))
996 ((>= (charset-dimension name) 2)
997 (if has-long-ccs-name
998 "(%-26s . #x%04X)\t; %c%s"
999 "(%-18s . #x%04X)\t; %c%s"))
1001 (if has-long-ccs-name
1002 "(%-26s . #x%02X)\t; %c%s"
1003 "(%-18s . #x%02X)\t; %c%s")))
1005 (if (= (charset-iso-graphic-plane name) 1)
1007 (cond ((= (charset-dimension name) 1)
1009 ((= (charset-dimension name) 2)
1011 ((= (charset-dimension name) 3)
1015 (char-db-decode-isolated-char name value)
1017 (setq ccs-attributes (cdr ccs-attributes)))
1020 (defun insert-char-data (char &optional readable
1021 attributes ccs-attributes)
1023 (narrow-to-region (point)(point))
1024 (insert "(define-char
1026 (insert-char-attributes char readable
1027 attributes ccs-attributes)
1029 (goto-char (point-min))
1030 (while (re-search-forward "[ \t]+$" nil t)
1033 (goto-char (point-min))
1034 (while (re-search-forward "[ \t][ \t][ \t]*" nil t)
1035 (let ((column (current-column))
1036 (indent-tabs-mode t))
1037 (delete-region (match-beginning 0) (point))
1038 (indent-to column)))
1039 (goto-char (point-max))
1040 ;; (tabify (point-min)(point-max))
1043 (defun insert-char-data-with-variant (char &optional printable
1045 script excluded-script)
1046 (insert-char-data char printable)
1047 (let ((variants (or (char-variants char)
1048 (let ((ucs (get-char-attribute char '->ucs)))
1050 (delete char (char-variants (int-char ucs)))))))
1052 (setq variants (sort variants #'<))
1054 (setq variant (car variants))
1055 (if (and (or (null script)
1056 (null (setq vs (get-char-attribute variant 'script)))
1058 (or (null excluded-script)
1059 (null (setq vs (get-char-attribute variant 'script)))
1060 (not (memq excluded-script vs))))
1061 (or (and no-ucs-unified (get-char-attribute variant '=ucs))
1062 (insert-char-data variant printable)))
1063 (setq variants (cdr variants))
1066 (defun insert-char-range-data (min max &optional script excluded-script)
1069 (while (<= code max)
1070 (setq char (decode-char '=ucs code))
1071 (if (encode-char char '=ucs 'defined-only)
1072 (insert-char-data-with-variant char nil 'no-ucs-unified
1073 script excluded-script))
1074 (setq code (1+ code)))))
1076 (defun write-char-range-data-to-file (min max file
1077 &optional script excluded-script)
1078 (let ((coding-system-for-write 'utf-8-mcs))
1080 (insert ";; -*- coding: utf-8-mcs -*-\n")
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