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 (and (charset-iso-final-char ka)
83 (>= (charset-iso-final-char ka) ?@)
84 (charset-iso-final-char kb)
85 (>= (charset-iso-final-char kb) ?@))
87 ((= (charset-dimension ka)
88 (charset-dimension kb))
89 (< (charset-iso-final-char ka)
90 (charset-iso-final-char kb)))
92 (> (charset-dimension ka)
93 (charset-dimension kb))
95 (if (< (charset-id ka) 0)
96 (if (< (charset-id kb) 0)
98 ((= (charset-dimension ka)
99 (charset-dimension kb))
100 (> (charset-id ka)(charset-id kb)))
102 (> (charset-dimension ka)
103 (charset-dimension kb))
106 (< (charset-id ka)(charset-id kb)))))
115 (string< (symbol-name ka)
121 (defvar char-db-coded-charset-priority-list
136 japanese-jisx0208-1978
177 (defun char-db-make-char-spec (char)
179 (cond ((characterp char)
180 (cond ((and (setq ret (encode-char char '=ucs 'defined-only))
181 (not (and (<= #xE000 ret)(<= ret #xF8FF))))
182 (setq char-spec (list (cons '=ucs ret)))
183 (cond ((setq ret (get-char-attribute char 'name))
184 (setq char-spec (cons (cons 'name ret) char-spec))
186 ((setq ret (get-char-attribute char 'name*))
187 (setq char-spec (cons (cons 'name* ret) char-spec))
192 (let ((rest char-db-coded-charset-priority-list)
195 (setq ccs (charset-name
196 (find-charset (car rest))))
198 (encode-char char ccs
200 (throw 'tag (cons ccs ret)))
201 (setq rest (cdr rest))))))
202 (setq char-spec (list ret))
203 (dolist (ccs (delq (car ret) (charset-list)))
204 (if (and (or (charset-iso-final-char ccs)
210 (setq ret (encode-char char ccs 'defined-only)))
211 (setq char-spec (cons (cons ccs ret) char-spec))))
213 (setq char-spec (split-char char)))
214 (cond ((setq ret (get-char-attribute char 'name))
215 (setq char-spec (cons (cons 'name ret) char-spec))
217 ((setq ret (get-char-attribute char 'name*))
218 (setq char-spec (cons (cons 'name* ret) char-spec))
225 (defun char-db-insert-char-spec (char &optional readable column)
227 (setq column (current-column)))
228 (let (char-spec al cal key temp-char)
229 (setq char-spec (char-db-make-char-spec char))
230 (unless (or (characterp char) ; char
232 (setq char (find-char char-spec))
234 ;; define temporary character
235 ;; Current implementation is dirty.
236 (setq temp-char (define-char (cons '(ideograph-daikanwa . 0)
238 (remove-char-attribute temp-char 'ideograph-daikanwa)
239 (setq char temp-char))
243 (setq key (car (car char-spec)))
244 (unless (memq key char-db-ignored-attributes)
245 (if (find-charset key)
246 (if (encode-char char key 'defined-only)
247 (setq cal (cons key cal)))
248 (setq al (cons key al))))
249 (setq char-spec (cdr char-spec)))
251 (setq char-spec (char-db-make-char-spec char))
253 (setq key (car (car char-spec)))
254 (unless (memq key char-db-ignored-attributes)
255 (if (find-charset key)
256 (setq cal (cons key cal))
257 (setq al (cons key al))))
258 (setq char-spec (cdr char-spec)))
261 (memq 'ideographic-structure al))
262 (push 'ideographic-structure al))
263 (insert-char-attributes char
267 ;; undefine temporary character
268 ;; Current implementation is dirty.
269 (setq char-spec (char-attribute-alist temp-char))
271 (remove-char-attribute temp-char (car (car char-spec)))
272 (setq char-spec (cdr char-spec))))))
274 (defun char-db-insert-alist (alist &optional readable column)
276 (setq column (current-column)))
278 (concat "\n" (make-string (1+ column) ?\ )))
281 lbs cell rest separator)
284 (setq name (car (car alist))
285 value (cdr (car alist)))
286 (cond ((eq name 'char)
288 (if (setq ret (condition-case nil
295 (setq key (car (car value)))
296 (if (find-charset key)
297 (setq cal (cons key cal))
298 (setq al (cons key al)))
299 (setq value (cdr value)))
300 (insert-char-attributes ret
303 (insert (prin1-to-string value)))
305 (insert line-breaking))
307 (insert (format "(%-18s " name))
308 (setq lbs (concat "\n" (make-string (current-column) ?\ )))
310 (setq cell (car value))
311 (if (and (consp cell)
313 (setq ret (condition-case nil
322 (setq key (car (car rest)))
323 (if (find-charset key)
324 (setq cal (cons key cal))
325 (setq al (cons key al)))
326 (setq rest (cdr rest)))
329 (insert-char-attributes ret
332 (setq separator lbs))
335 (insert (prin1-to-string cell))
336 (setq separator " "))
337 (setq value (cdr value)))
339 (insert line-breaking))
341 (insert (format "(%-18s . %S)%s"
344 (setq alist (cdr alist))))
347 (defun char-db-insert-char-reference (plist &optional readable column)
349 (setq column (current-column)))
351 (concat "\n" (make-string (1+ column) ?\ )))
356 (setq name (pop plist))
357 (setq value (pop plist))
358 (cond ((eq name :char)
361 (cond ((numberp value)
362 (setq value (decode-char '=ucs value)))
364 ;; (setq value (or (find-char value)
367 (char-db-insert-char-spec value readable)
368 (insert line-breaking)
371 (insert (format "%s%s\t%d ; %c%s"
374 (aref ideographic-radicals value)
378 (insert (format "%s%s\t%S" separator name value))
379 (setq separator line-breaking)))
383 (defun char-db-decode-isolated-char (ccs code-point)
386 (cond ((eq ccs 'arabic-iso8859-6)
387 (decode-char ccs code-point))
388 ((and (memq ccs '(=gt-pj-1
399 (setq ret (decode-char ccs code-point))
400 (setq ret (encode-char ret '=gt 'defined-only)))
401 (decode-builtin-char '=gt ret))
403 (decode-builtin-char ccs code-point))))
404 (cond ((and (<= 0 (char-int ret))
405 (<= (char-int ret) #x1F))
406 (decode-char '=ucs (+ #x2400 (char-int ret))))
407 ((= (char-int ret) #x7F)
411 (defvar char-db-convert-obsolete-format t)
413 (defun insert-char-attributes (char &optional readable
414 attributes ccs-attributes
419 (if (consp attributes)
421 (dolist (name attributes)
422 (unless (memq name char-db-ignored-attributes)
425 (dolist (name (char-attribute-list))
426 (unless (memq name char-db-ignored-attributes)
427 (if (find-charset name)
431 #'char-attribute-name<))
433 (sort (if ccs-attributes
436 (dolist (name ccs-attributes)
437 (unless (memq name char-db-ignored-attributes)
442 (dolist (name (charset-list))
443 (unless (memq name char-db-ignored-attributes)
446 #'char-attribute-name<)))
448 (setq column (current-column)))
449 (let (name value has-long-ccs-name rest
452 (concat "\n" (make-string (1+ column) ?\ )))
453 lbs cell separator ret
457 (when (and (memq 'name attributes)
458 (setq value (get-char-attribute char 'name)))
460 (if (> (+ (current-column) (length value)) 48)
463 value line-breaking))
464 (setq attributes (delq 'name attributes))
466 (when (and (memq 'name* attributes)
467 (setq value (get-char-attribute char 'name*)))
469 (if (> (+ (current-column) (length value)) 48)
472 value line-breaking))
473 (setq attributes (delq 'name* attributes))
475 (when (and (memq 'script attributes)
476 (setq value (get-char-attribute char 'script)))
477 (insert (format "(script\t\t%s)%s"
478 (mapconcat (function prin1-to-string)
481 (setq attributes (delq 'script attributes))
483 (dolist (name '(=>ucs =>ucs*))
484 (when (and (memq name attributes)
485 (setq value (get-char-attribute char name)))
486 (insert (format "(%-18s . #x%04X)\t; %c%s"
487 name value (decode-char '=ucs value)
489 (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"
498 (symbol-name name) 2)))
501 (setq attributes (delq name attributes))
503 (dolist (name '(=>ucs-gb =>ucs-cns =>ucs-jis =>ucs-ks =>ucs-big5))
504 (when (and (memq name attributes)
505 (setq value (get-char-attribute char name)))
506 (insert (format "(%-18s . #x%04X)\t; %c%s"
509 (substring (symbol-name name) 6)))
514 (symbol-name name) 6)))
517 (setq attributes (delq name attributes))))
518 (when (and (memq '->ucs attributes)
519 (setq value (get-char-attribute char '->ucs)))
520 (insert (format (if char-db-convert-obsolete-format
521 "(=>ucs\t\t. #x%04X)\t; %c%s"
522 "(->ucs\t\t. #x%04X)\t; %c%s")
523 value (decode-char '=ucs value)
525 (setq attributes (delq '->ucs attributes))
527 (when (and (memq 'general-category attributes)
528 (setq value (get-char-attribute char 'general-category)))
530 "(general-category\t%s) ; %s%s"
531 (mapconcat (lambda (cell)
534 (cond ((rassoc value unidata-normative-category-alist)
535 "Normative Category")
536 ((rassoc value unidata-informative-category-alist)
537 "Informative Category")
541 (setq attributes (delq 'general-category attributes))
543 (when (and (memq 'bidi-category attributes)
544 (setq value (get-char-attribute char 'bidi-category)))
545 (insert (format "(bidi-category\t. %S)%s"
548 (setq attributes (delq 'bidi-category attributes))
550 (unless (or (not (memq 'mirrored attributes))
551 (eq (setq value (get-char-attribute char 'mirrored 'empty))
553 (insert (format "(mirrored\t\t. %S)%s"
556 (setq attributes (delq 'mirrored attributes))
559 ((and (memq 'decimal-digit-value attributes)
560 (setq value (get-char-attribute char 'decimal-digit-value)))
561 (insert (format "(decimal-digit-value . %S)%s"
564 (setq attributes (delq 'decimal-digit-value attributes))
565 (when (and (memq 'digit-value attributes)
566 (setq value (get-char-attribute char 'digit-value)))
567 (insert (format "(digit-value\t . %S)%s"
570 (setq attributes (delq 'digit-value attributes))
572 (when (and (memq 'numeric-value attributes)
573 (setq value (get-char-attribute char 'numeric-value)))
574 (insert (format "(numeric-value\t . %S)%s"
577 (setq attributes (delq 'numeric-value attributes))
581 (when (and (memq 'digit-value attributes)
582 (setq value (get-char-attribute char 'digit-value)))
583 (insert (format "(digit-value\t. %S)%s"
586 (setq attributes (delq 'digit-value attributes))
588 (when (and (memq 'numeric-value attributes)
589 (setq value (get-char-attribute char 'numeric-value)))
590 (insert (format "(numeric-value\t. %S)%s"
593 (setq attributes (delq 'numeric-value attributes))
595 (when (and (memq 'iso-10646-comment attributes)
596 (setq value (get-char-attribute char 'iso-10646-comment)))
597 (insert (format "(iso-10646-comment\t. %S)%s"
600 (setq attributes (delq 'iso-10646-comment attributes))
602 (when (and (memq 'morohashi-daikanwa attributes)
603 (setq value (get-char-attribute char 'morohashi-daikanwa)))
604 (insert (format "(morohashi-daikanwa\t%s)%s"
605 (mapconcat (function prin1-to-string) value " ")
607 (setq attributes (delq 'morohashi-daikanwa attributes))
611 (when (and (memq 'ideographic-radical attributes)
612 (setq value (get-char-attribute char 'ideographic-radical)))
614 (insert (format "(ideographic-radical . %S)\t; %c%s"
616 (aref ideographic-radicals radical)
618 (setq attributes (delq 'ideographic-radical attributes))
621 (dolist (domain char-db-feature-domains)
622 (setq key (intern (format "%s@%s" 'ideographic-radical domain)))
623 (when (and (memq key attributes)
624 (setq value (get-char-attribute char key)))
626 (insert (format "(%s . %S)\t; %c%s"
629 (aref ideographic-radicals radical)
631 (setq attributes (delq key attributes))
633 (setq key (intern (format "%s@%s" 'ideographic-strokes domain)))
634 (when (and (memq key attributes)
635 (setq value (get-char-attribute char key)))
637 (insert (format "(%s . %S)%s"
641 (setq attributes (delq key attributes))
643 (setq key (intern (format "%s@%s" 'total-strokes domain)))
644 (when (and (memq key attributes)
645 (setq value (get-char-attribute char key)))
646 (insert (format "(%s . %S)%s"
650 (setq attributes (delq key attributes))
652 (dolist (feature '(ideographic-radical
655 (setq key (intern (format "%s@%s*sources" feature domain)))
656 (when (and (memq key attributes)
657 (setq value (get-char-attribute char key)))
658 (insert (format "(%s%s" key line-breaking))
660 (insert (format " %s" cell)))
662 (insert line-breaking)
663 (setq attributes (delq key attributes))
666 (when (and (memq 'ideographic-strokes attributes)
667 (setq value (get-char-attribute char 'ideographic-strokes)))
669 (insert (format "(ideographic-strokes . %S)%s"
672 (setq attributes (delq 'ideographic-strokes attributes))
674 (when (and (memq 'kangxi-radical attributes)
675 (setq value (get-char-attribute char 'kangxi-radical)))
676 (unless (eq value radical)
677 (insert (format "(kangxi-radical\t . %S)\t; %c%s"
679 (aref ideographic-radicals value)
682 (setq radical value)))
683 (setq attributes (delq 'kangxi-radical attributes))
685 (when (and (memq 'kangxi-strokes attributes)
686 (setq value (get-char-attribute char 'kangxi-strokes)))
687 (unless (eq value strokes)
688 (insert (format "(kangxi-strokes\t . %S)%s"
692 (setq strokes value)))
693 (setq attributes (delq 'kangxi-strokes attributes))
695 (when (and (memq 'japanese-radical attributes)
696 (setq value (get-char-attribute char 'japanese-radical)))
697 (unless (eq value radical)
698 (insert (format "(japanese-radical\t . %S)\t; %c%s"
700 (aref ideographic-radicals value)
703 (setq radical value)))
704 (setq attributes (delq 'japanese-radical attributes))
706 (when (and (memq 'japanese-strokes attributes)
707 (setq value (get-char-attribute char 'japanese-strokes)))
708 (unless (eq value strokes)
709 (insert (format "(japanese-strokes\t . %S)%s"
713 (setq strokes value)))
714 (setq attributes (delq 'japanese-strokes attributes))
716 (when (and (memq 'cns-radical attributes)
717 (setq value (get-char-attribute char 'cns-radical)))
718 (insert (format "(cns-radical\t . %S)\t; %c%s"
720 (aref ideographic-radicals value)
722 (setq attributes (delq 'cns-radical attributes))
724 (when (and (memq 'cns-strokes attributes)
725 (setq value (get-char-attribute char 'cns-strokes)))
726 (unless (eq value strokes)
727 (insert (format "(cns-strokes\t . %S)%s"
731 (setq strokes value)))
732 (setq attributes (delq 'cns-strokes attributes))
734 (when (and (memq 'shinjigen-1-radical attributes)
735 (setq value (get-char-attribute char 'shinjigen-1-radical)))
736 (unless (eq value radical)
737 (insert (format "(shinjigen-1-radical . %S)\t; %c%s"
739 (aref ideographic-radicals value)
742 (setq radical value)))
743 (setq attributes (delq 'shinjigen-1-radical attributes))
745 (when (and (memq 'ideographic- attributes)
746 (setq value (get-char-attribute char 'ideographic-)))
747 (insert "(ideographic- ")
748 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
751 (setq cell (car value))
753 (setq cell (decode-char '=ucs cell)))
754 (cond ((characterp cell)
758 (insert (format "%S" cell))
759 (char-db-insert-char-spec cell readable))
760 (setq separator lbs))
764 (if (consp (car cell))
765 (char-db-insert-char-spec cell readable)
766 (char-db-insert-char-reference cell readable))
767 (setq separator lbs))
771 (insert (prin1-to-string cell))
772 (setq separator " ")))
773 (setq value (cdr value)))
775 (insert line-breaking)
776 (setq attributes (delq 'ideographic- attributes)))
777 (when (and (memq 'total-strokes attributes)
778 (setq value (get-char-attribute char 'total-strokes)))
779 (insert (format "(total-strokes . %S)%s"
782 (setq attributes (delq 'total-strokes attributes))
784 (when (and (memq '->ideograph attributes)
785 (setq value (get-char-attribute char '->ideograph)))
786 (insert (format "(->ideograph\t%s)%s"
787 (mapconcat (lambda (code)
788 (cond ((symbolp code)
791 (format "#x%04X" code))
794 line-breaking code))))
797 (setq attributes (delq '->ideograph attributes))
799 (when (and (memq '->decomposition attributes)
800 (setq value (get-char-attribute char '->decomposition)))
801 (insert (format "(->decomposition\t%s)%s"
802 (mapconcat (lambda (code)
803 (cond ((symbolp code)
812 (format "#x%04X" code))
814 (format "%s%S" line-breaking code))))
817 (setq attributes (delq '->decomposition attributes))
819 (if (equal (get-char-attribute char '->titlecase)
820 (get-char-attribute char '->uppercase))
821 (setq attributes (delq '->titlecase attributes)))
822 (when (and (memq '->mojikyo attributes)
823 (setq value (get-char-attribute char '->mojikyo)))
824 (insert (format "(->mojikyo\t\t. %06d)\t; %c%s"
825 value (decode-char 'mojikyo value)
827 (setq attributes (delq '->mojikyo attributes))
829 (when (and (memq 'hanyu-dazidian-vol attributes)
830 (setq value (get-char-attribute char 'hanyu-dazidian-vol)))
831 (insert (format "(hanyu-dazidian-vol . %d)%s"
832 value line-breaking))
833 (setq attributes (delq 'hanyu-dazidian-vol attributes))
835 (when (and (memq 'hanyu-dazidian-page attributes)
836 (setq value (get-char-attribute char 'hanyu-dazidian-page)))
837 (insert (format "(hanyu-dazidian-page . %d)%s"
838 value line-breaking))
839 (setq attributes (delq 'hanyu-dazidian-page attributes))
841 (when (and (memq 'hanyu-dazidian-char attributes)
842 (setq value (get-char-attribute char 'hanyu-dazidian-char)))
843 (insert (format "(hanyu-dazidian-char . %d)%s"
844 value line-breaking))
845 (setq attributes (delq 'hanyu-dazidian-char attributes))
848 (when (memq '->ucs-unified attributes)
849 (setq attributes (delq '->ucs-unified attributes))
851 (when (memq 'composition attributes)
852 (setq attributes (delq 'composition attributes))
854 (setq rest ccs-attributes)
857 (setq value (get-char-attribute char (car rest)))
859 (if (>= (length (symbol-name (car rest))) 19)
861 (setq has-long-ccs-name t)
865 (setq rest (cdr rest)))
867 (setq name (car attributes))
868 (if (setq value (get-char-attribute char name))
869 (cond ((string-match "^=>ucs@" (symbol-name name))
870 (insert (format "(%-18s . #x%04X)\t; %c%s"
871 name value (decode-char '=ucs value)
874 ((eq name 'jisx0208-1978/4X)
875 (insert (format "(%-18s . #x%04X)%s"
878 ((or (eq name 'ideographic-structure)
879 (eq name 'ideographic-)
880 (string-match "^\\(->\\|<-\\)" (symbol-name name)))
881 (insert (format "(%-18s%s " name line-breaking))
882 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
885 (setq cell (car value))
887 (setq cell (decode-char '=ucs cell)))
888 (cond ((characterp cell)
892 (insert (format "%S" cell))
893 (char-db-insert-char-spec cell readable))
894 (setq separator lbs))
898 (if (consp (car cell))
899 (char-db-insert-char-spec cell readable)
900 (char-db-insert-char-reference cell readable))
901 (setq separator lbs))
905 (insert (prin1-to-string cell))
906 (setq separator " ")))
907 (setq value (cdr value)))
909 (insert line-breaking))
910 ((memq name '(ideograph=
911 original-ideograph-of
915 simplified-ideograph-of
917 ideographic-different-form-of))
918 (insert (format "(%-18s%s " name line-breaking))
919 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
922 (setq cell (car value))
923 (if (and (consp cell)
928 (char-db-insert-alist cell readable)
929 (setq separator lbs))
932 (insert (prin1-to-string cell))
933 (setq separator " "))
934 (setq value (cdr value)))
936 (insert line-breaking))
937 ;; ((string-match "^->" (symbol-name name))
939 ;; (format "(%-18s %s)%s"
941 ;; (mapconcat (lambda (code)
942 ;; (cond ((symbolp code)
943 ;; (symbol-name code))
945 ;; (format "#x%04X" code))
948 ;; line-breaking code))))
952 (insert (format "(%-18s " name))
953 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
956 (setq cell (car value))
957 (if (and (consp cell)
959 (setq ret (condition-case nil
967 (setq key (car (car rest)))
968 (if (find-charset key)
969 (setq cal (cons key cal))
970 (setq al (cons key al)))
971 (setq rest (cdr rest)))
974 (insert-char-attributes ret
977 (setq separator lbs))
980 (insert (prin1-to-string cell))
981 (setq separator " "))
982 (setq value (cdr value)))
984 (insert line-breaking))
986 (insert (format "(%-18s . %S)%s"
990 (setq attributes (cdr attributes)))
991 (while ccs-attributes
992 (setq name (charset-name (car ccs-attributes)))
993 (if (and (not (memq name dest-ccss))
995 (setq value (get-char-attribute char name))
996 (setq dest-ccss (cons name dest-ccss))))
999 (cond ((memq name '(=daikanwa
1000 =daikanwa-rev1 =daikanwa-rev2
1002 (if has-long-ccs-name
1003 "(%-26s . %05d)\t; %c%s"
1004 "(%-18s . %05d)\t; %c%s"))
1006 (if has-long-ccs-name
1007 "(%-26s . %06d)\t; %c%s"
1008 "(%-18s . %06d)\t; %c%s"))
1009 ((>= (charset-dimension name) 2)
1010 (if has-long-ccs-name
1011 "(%-26s . #x%04X)\t; %c%s"
1012 "(%-18s . #x%04X)\t; %c%s"))
1014 (if has-long-ccs-name
1015 "(%-26s . #x%02X)\t; %c%s"
1016 "(%-18s . #x%02X)\t; %c%s")))
1018 (if (= (charset-iso-graphic-plane name) 1)
1020 (cond ((= (charset-dimension name) 1)
1022 ((= (charset-dimension name) 2)
1024 ((= (charset-dimension name) 3)
1028 (char-db-decode-isolated-char name value)
1030 (setq ccs-attributes (cdr ccs-attributes)))
1033 (defun insert-char-data (char &optional readable
1034 attributes ccs-attributes)
1036 (narrow-to-region (point)(point))
1037 (insert "(define-char
1039 (insert-char-attributes char readable
1040 attributes ccs-attributes)
1042 (goto-char (point-min))
1043 (while (re-search-forward "[ \t]+$" nil t)
1046 (goto-char (point-min))
1047 (while (re-search-forward "[ \t][ \t][ \t]*" nil t)
1048 (let ((column (current-column))
1049 (indent-tabs-mode t))
1050 (delete-region (match-beginning 0) (point))
1051 (indent-to column)))
1052 (goto-char (point-max))
1053 ;; (tabify (point-min)(point-max))
1056 (defun insert-char-data-with-variant (char &optional printable
1058 script excluded-script)
1059 (insert-char-data char printable)
1060 (let ((variants (or (char-variants char)
1061 (let ((ucs (get-char-attribute char '->ucs)))
1063 (delete char (char-variants (int-char ucs)))))))
1065 (setq variants (sort variants #'<))
1067 (setq variant (car variants))
1068 (if (and (or (null script)
1069 (null (setq vs (get-char-attribute variant 'script)))
1071 (or (null excluded-script)
1072 (null (setq vs (get-char-attribute variant 'script)))
1073 (not (memq excluded-script vs))))
1074 (or (and no-ucs-unified (get-char-attribute variant '=ucs))
1075 (insert-char-data variant printable)))
1076 (setq variants (cdr variants))
1079 (defun insert-char-range-data (min max &optional script excluded-script)
1082 (while (<= code max)
1083 (setq char (decode-char '=ucs code))
1084 (if (encode-char char '=ucs 'defined-only)
1085 (insert-char-data-with-variant char nil 'no-ucs-unified
1086 script excluded-script))
1087 (setq code (1+ code)))))
1089 (defun write-char-range-data-to-file (min max file
1090 &optional script excluded-script)
1091 (let ((coding-system-for-write 'utf-8-mcs))
1093 (insert ";; -*- coding: utf-8-mcs -*-\n")
1094 (insert-char-range-data min max script excluded-script)
1095 (write-region (point-min)(point-max) file))))
1097 (defvar what-character-original-window-configuration)
1100 (defun what-char-definition (char)
1101 (interactive (list (char-after)))
1102 (let ((buf (get-buffer-create "*Character Description*"))
1103 (the-buf (current-buffer))
1104 (win-conf (current-window-configuration)))
1106 (make-local-variable 'what-character-original-window-configuration)
1107 (setq what-character-original-window-configuration win-conf)
1108 (setq buffer-read-only nil)
1112 (insert-char-data-with-variant char 'printable)
1113 (unless (char-attribute-alist char)
1114 (insert (format ";; = %c\n"
1115 (let* ((rest (split-char char))
1119 (setq code (logior (lsh code 8)
1121 (decode-char ccs code)))))
1122 ;; (char-db-update-comment)
1123 (set-buffer-modified-p nil)
1124 (view-mode the-buf (lambda (buf)
1125 (set-window-configuration
1126 what-character-original-window-configuration)
1128 (goto-char (point-min)))
1130 (set-window-configuration
1131 what-character-original-window-configuration)
1132 (signal (car err) (cdr err)))))))
1134 (provide 'char-db-util)
1136 ;;; char-db-util.el ends here