1 ;;; char-db-util.el --- Character Database utility
3 ;; Copyright (C) 1998,1999,2000,2001,2002,2003,2004 MORIOKA Tomohiko.
5 ;; Author: MORIOKA Tomohiko <tomo@kanji.zinbun.kyoto-u.ac.jp>
6 ;; Keywords: CHISE, Character Database, ISO/IEC 10646, Unicode, UCS-4, MULE.
8 ;; This file is part of XEmacs CHISE.
10 ;; XEmacs CHISE is free software; you can redistribute it and/or
11 ;; modify it under the terms of the GNU General Public License as
12 ;; published by the Free Software Foundation; either version 2, or (at
13 ;; your option) any later version.
15 ;; XEmacs CHISE is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 ;; General Public License for more details.
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with XEmacs CHISE; see the file COPYING. If not, write to
22 ;; the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23 ;; Boston, MA 02111-1307, USA.
29 (defconst unidata-normative-category-alist
30 '(("Lu" letter uppercase)
31 ("Ll" letter lowercase)
32 ("Lt" letter titlecase)
33 ("Mn" mark non-spacing)
34 ("Mc" mark spacing-combining)
36 ("Nd" number decimal-digit)
39 ("Zs" separator space)
41 ("Zp" separator paragraph)
44 ("Cs" other surrogate)
45 ("Co" other private-use)
46 ("Cn" other not-assigned)))
48 (defconst unidata-informative-category-alist
49 '(("Lm" letter modifier)
51 ("Pc" punctuation connector)
52 ("Pd" punctuation dash)
53 ("Ps" punctuation open)
54 ("Pe" punctuation close)
55 ("Pi" punctuation initial-quote)
56 ("Pf" punctuation final-quote)
57 ("Po" punctuation other)
59 ("Sc" symbol currency)
60 ("Sk" symbol modifier)
64 (defconst ideographic-radicals
65 (let ((v (make-vector 215 nil))
68 (aset v i (decode-char '=ucs (+ #x2EFF i)))
72 (defvar char-db-feature-domains
73 '(ucs daikanwa cns gt jis jis/alt jis/a jis/b
74 jis-x0213 misc unknown))
76 (defvar char-db-ignored-attributes nil)
78 (defun char-attribute-name< (ka kb)
83 (if (<= (charset-id ka) 0)
84 (if (<= (charset-id kb) 0)
86 ((= (charset-dimension ka)
87 (charset-dimension kb))
88 (> (charset-id ka)(charset-id kb)))
90 (> (charset-dimension ka)
91 (charset-dimension kb))
94 (if (<= (charset-id kb) 0)
96 (< (charset-id ka)(charset-id kb)))))
105 (string< (symbol-name ka)
111 (defvar char-db-coded-charset-priority-list
126 japanese-jisx0208-1978
167 (defun char-db-make-char-spec (char)
169 (cond ((characterp char)
170 (cond ((and (setq ret (encode-char char '=ucs 'defined-only))
171 (not (and (<= #xE000 ret)(<= ret #xF8FF))))
172 (setq char-spec (list (cons '=ucs ret)))
173 (cond ((setq ret (get-char-attribute char 'name))
174 (setq char-spec (cons (cons 'name ret) char-spec))
176 ((setq ret (get-char-attribute char 'name*))
177 (setq char-spec (cons (cons 'name* ret) char-spec))
182 (let ((rest char-db-coded-charset-priority-list)
185 (setq ccs (charset-name
186 (find-charset (car rest))))
188 (encode-char char ccs
190 (throw 'tag (cons ccs ret)))
191 (setq rest (cdr rest))))))
192 (setq char-spec (list ret))
193 (dolist (ccs (delq (car ret) (charset-list)))
194 (if (and (or (charset-iso-final-char ccs)
200 (setq ret (encode-char char ccs 'defined-only)))
201 (setq char-spec (cons (cons ccs ret) char-spec))))
203 (setq char-spec (split-char char)))
204 (cond ((setq ret (get-char-attribute char 'name))
205 (setq char-spec (cons (cons 'name ret) char-spec))
207 ((setq ret (get-char-attribute char 'name*))
208 (setq char-spec (cons (cons 'name* ret) char-spec))
215 (defun char-db-insert-char-spec (char &optional readable column
218 (setq column (current-column)))
219 (let (char-spec al cal key temp-char)
220 (setq char-spec (char-db-make-char-spec char))
221 (unless (or (characterp char) ; char
223 (setq char (find-char char-spec))
225 ;; define temporary character
226 ;; Current implementation is dirty.
227 (setq temp-char (define-char (cons '(ideograph-daikanwa . 0)
229 (remove-char-attribute temp-char 'ideograph-daikanwa)
230 (setq char temp-char))
234 (setq key (car (car char-spec)))
235 (unless (memq key char-db-ignored-attributes)
236 (if (find-charset key)
237 (if (encode-char char key 'defined-only)
238 (setq cal (cons key cal)))
239 (setq al (cons key al))))
240 (setq char-spec (cdr char-spec)))
242 (setq char-spec (char-db-make-char-spec char))
244 (setq key (car (car char-spec)))
245 (unless (memq key char-db-ignored-attributes)
246 (if (find-charset key)
247 (setq cal (cons key cal))
248 (setq al (cons key al))))
249 (setq char-spec (cdr char-spec)))
252 (memq 'ideographic-structure al))
253 (push 'ideographic-structure al))
254 (dolist (feature required-features)
255 (if (find-charset feature)
256 (if (encode-char char feature 'defined-only)
257 (setq cal (adjoin feature cal)))
258 (setq al (adjoin feature al))))
259 (insert-char-attributes char
263 ;; undefine temporary character
264 ;; Current implementation is dirty.
265 (setq char-spec (char-attribute-alist temp-char))
267 (remove-char-attribute temp-char (car (car char-spec)))
268 (setq char-spec (cdr char-spec))))))
270 (defun char-db-insert-alist (alist &optional readable column)
272 (setq column (current-column)))
274 (concat "\n" (make-string (1+ column) ?\ )))
277 lbs cell rest separator)
280 (setq name (car (car alist))
281 value (cdr (car alist)))
282 (cond ((eq name 'char)
284 (if (setq ret (condition-case nil
291 (setq key (car (car value)))
292 (if (find-charset key)
293 (setq cal (cons key cal))
294 (setq al (cons key al)))
295 (setq value (cdr value)))
296 (insert-char-attributes ret
299 (insert (prin1-to-string value)))
301 (insert line-breaking))
303 (insert (format "(%-18s " name))
304 (setq lbs (concat "\n" (make-string (current-column) ?\ )))
306 (setq cell (car value))
307 (if (and (consp cell)
309 (setq ret (condition-case nil
318 (setq key (car (car rest)))
319 (if (find-charset key)
320 (setq cal (cons key cal))
321 (setq al (cons key al)))
322 (setq rest (cdr rest)))
325 (insert-char-attributes ret
328 (setq separator lbs))
331 (insert (prin1-to-string cell))
332 (setq separator " "))
333 (setq value (cdr value)))
335 (insert line-breaking))
337 (insert (format "(%-18s . %S)%s"
340 (setq alist (cdr alist))))
343 (defun char-db-insert-char-reference (plist &optional readable column)
345 (setq column (current-column)))
347 (concat "\n" (make-string (1+ column) ?\ )))
352 (setq name (pop plist))
353 (setq value (pop plist))
354 (cond ((eq name :char)
357 (cond ((numberp value)
358 (setq value (decode-char '=ucs value)))
360 ;; (setq value (or (find-char value)
363 (char-db-insert-char-spec value readable)
364 (insert line-breaking)
367 (insert (format "%s%s\t%d ; %c%s"
370 (aref ideographic-radicals value)
374 (insert (format "%s%s\t%S" separator name value))
375 (setq separator line-breaking)))
379 (defun char-db-decode-isolated-char (ccs code-point)
382 (cond ((eq ccs 'arabic-iso8859-6)
383 (decode-char ccs code-point))
384 ((and (memq ccs '(=gt-pj-1
395 (setq ret (decode-char ccs code-point))
396 (setq ret (encode-char ret '=gt 'defined-only)))
397 (decode-builtin-char '=gt ret))
399 (decode-builtin-char ccs code-point))))
400 (cond ((and (<= 0 (char-int ret))
401 (<= (char-int ret) #x1F))
402 (decode-char '=ucs (+ #x2400 (char-int ret))))
403 ((= (char-int ret) #x7F)
407 (defvar char-db-convert-obsolete-format t)
409 (defun insert-char-attributes (char &optional readable
410 attributes ccs-attributes
415 (if (consp attributes)
417 (dolist (name attributes)
418 (unless (memq name char-db-ignored-attributes)
421 (dolist (name (char-attribute-list))
422 (unless (memq name char-db-ignored-attributes)
423 (if (find-charset name)
427 #'char-attribute-name<))
429 (sort (if ccs-attributes
432 (dolist (name ccs-attributes)
433 (unless (memq name char-db-ignored-attributes)
438 (dolist (name (charset-list))
439 (unless (memq name char-db-ignored-attributes)
442 #'char-attribute-name<)))
444 (setq column (current-column)))
445 (let (name value has-long-ccs-name rest
448 (concat "\n" (make-string (1+ column) ?\ )))
449 lbs cell separator ret
452 sources required-features)
454 (when (and (memq 'name attributes)
455 (setq value (get-char-attribute char 'name)))
457 (if (> (+ (current-column) (length value)) 48)
460 value line-breaking))
461 (setq attributes (delq 'name attributes))
463 (when (and (memq 'name* attributes)
464 (setq value (get-char-attribute char 'name*)))
466 (if (> (+ (current-column) (length value)) 48)
469 value line-breaking))
470 (setq attributes (delq 'name* attributes))
472 (when (and (memq 'script attributes)
473 (setq value (get-char-attribute char 'script)))
474 (insert (format "(script\t\t%s)%s"
475 (mapconcat (function prin1-to-string)
478 (setq attributes (delq 'script attributes))
480 (dolist (name '(=>ucs =>ucs*))
481 (when (and (memq name attributes)
482 (setq value (get-char-attribute char name)))
483 (insert (format "(%-18s . #x%04X)\t; %c%s"
484 name value (decode-char '=ucs value)
486 (setq attributes (delq name attributes))))
487 (dolist (name '(=>ucs@gb =>ucs@cns =>ucs@jis =>ucs@ks =>ucs@big5))
488 (when (and (memq name attributes)
489 (setq value (get-char-attribute char name)))
490 (insert (format "(%-18s . #x%04X)\t; %c%s"
495 (symbol-name name) 2)))
498 (setq attributes (delq name attributes))
500 ;; (dolist (name '(=>ucs-gb =>ucs-cns =>ucs-jis =>ucs-ks =>ucs-big5))
501 ;; (when (and (memq name attributes)
502 ;; (setq value (get-char-attribute char name)))
503 ;; (insert (format "(%-18s . #x%04X)\t; %c%s"
506 ;; (substring (symbol-name name) 6)))
508 ;; (decode-char (intern
511 ;; (symbol-name name) 6)))
514 ;; (setq attributes (delq name attributes))))
515 ;; (when (and (memq '->ucs attributes)
516 ;; (setq value (get-char-attribute char '->ucs)))
517 ;; (insert (format (if char-db-convert-obsolete-format
518 ;; "(=>ucs\t\t. #x%04X)\t; %c%s"
519 ;; "(->ucs\t\t. #x%04X)\t; %c%s")
520 ;; value (decode-char '=ucs value)
522 ;; (setq attributes (delq '->ucs attributes))
524 (dolist (name '(=>daikanwa))
525 (when (and (memq name attributes)
526 (setq value (get-char-attribute char name)))
529 (format "(%-18s . %05d)\t; %c%s"
530 name value (decode-char '=daikanwa value)
532 (format "(%-18s %s)\t; %c%s"
534 (mapconcat #'prin1-to-string
536 (char-representative-of-daikanwa char)
538 (setq attributes (delq name attributes))))
539 (when (and (memq 'general-category attributes)
540 (setq value (get-char-attribute char 'general-category)))
542 "(general-category\t%s) ; %s%s"
543 (mapconcat (lambda (cell)
546 (cond ((rassoc value unidata-normative-category-alist)
547 "Normative Category")
548 ((rassoc value unidata-informative-category-alist)
549 "Informative Category")
553 (setq attributes (delq 'general-category attributes))
555 (when (and (memq 'bidi-category attributes)
556 (setq value (get-char-attribute char 'bidi-category)))
557 (insert (format "(bidi-category\t. %S)%s"
560 (setq attributes (delq 'bidi-category attributes))
562 (unless (or (not (memq 'mirrored attributes))
563 (eq (setq value (get-char-attribute char 'mirrored 'empty))
565 (insert (format "(mirrored\t\t. %S)%s"
568 (setq attributes (delq 'mirrored attributes))
571 ((and (memq 'decimal-digit-value attributes)
572 (setq value (get-char-attribute char 'decimal-digit-value)))
573 (insert (format "(decimal-digit-value . %S)%s"
576 (setq attributes (delq 'decimal-digit-value attributes))
577 (when (and (memq 'digit-value attributes)
578 (setq value (get-char-attribute char 'digit-value)))
579 (insert (format "(digit-value\t . %S)%s"
582 (setq attributes (delq 'digit-value attributes))
584 (when (and (memq 'numeric-value attributes)
585 (setq value (get-char-attribute char 'numeric-value)))
586 (insert (format "(numeric-value\t . %S)%s"
589 (setq attributes (delq 'numeric-value attributes))
593 (when (and (memq 'digit-value attributes)
594 (setq value (get-char-attribute char 'digit-value)))
595 (insert (format "(digit-value\t. %S)%s"
598 (setq attributes (delq 'digit-value attributes))
600 (when (and (memq 'numeric-value attributes)
601 (setq value (get-char-attribute char 'numeric-value)))
602 (insert (format "(numeric-value\t. %S)%s"
605 (setq attributes (delq 'numeric-value attributes))
607 (when (and (memq 'iso-10646-comment attributes)
608 (setq value (get-char-attribute char 'iso-10646-comment)))
609 (insert (format "(iso-10646-comment\t. %S)%s"
612 (setq attributes (delq 'iso-10646-comment attributes))
614 (when (and (memq 'morohashi-daikanwa attributes)
615 (setq value (get-char-attribute char 'morohashi-daikanwa)))
616 (insert (format "(morohashi-daikanwa\t%s)%s"
617 (mapconcat (function prin1-to-string) value " ")
619 (setq attributes (delq 'morohashi-daikanwa attributes))
623 (when (and (memq 'ideographic-radical attributes)
624 (setq value (get-char-attribute char 'ideographic-radical)))
626 (insert (format "(ideographic-radical . %S)\t; %c%s"
628 (aref ideographic-radicals radical)
630 (setq attributes (delq 'ideographic-radical attributes))
633 (dolist (domain char-db-feature-domains)
634 (setq key (intern (format "%s@%s" 'ideographic-radical domain)))
635 (when (and (memq key attributes)
636 (setq value (get-char-attribute char key)))
638 (insert (format "(%s . %S)\t; %c%s"
641 (aref ideographic-radicals radical)
643 (setq attributes (delq key attributes))
645 (setq key (intern (format "%s@%s" 'ideographic-strokes domain)))
646 (when (and (memq key attributes)
647 (setq value (get-char-attribute char key)))
649 (insert (format "(%s . %S)%s"
653 (setq attributes (delq key attributes))
655 (setq key (intern (format "%s@%s" 'total-strokes domain)))
656 (when (and (memq key attributes)
657 (setq value (get-char-attribute char key)))
658 (insert (format "(%s . %S)%s"
662 (setq attributes (delq key attributes))
664 (dolist (feature '(ideographic-radical
667 (setq key (intern (format "%s@%s*sources" feature domain)))
668 (when (and (memq key attributes)
669 (setq value (get-char-attribute char key)))
670 (insert (format "(%s%s" key line-breaking))
672 (insert (format " %s" cell)))
674 (insert line-breaking)
675 (setq attributes (delq key attributes))
678 (when (and (memq 'ideographic-strokes attributes)
679 (setq value (get-char-attribute char 'ideographic-strokes)))
681 (insert (format "(ideographic-strokes . %S)%s"
684 (setq attributes (delq 'ideographic-strokes attributes))
686 (when (and (memq 'kangxi-radical attributes)
687 (setq value (get-char-attribute char 'kangxi-radical)))
688 (unless (eq value radical)
689 (insert (format "(kangxi-radical\t . %S)\t; %c%s"
691 (aref ideographic-radicals value)
694 (setq radical value)))
695 (setq attributes (delq 'kangxi-radical attributes))
697 (when (and (memq 'kangxi-strokes attributes)
698 (setq value (get-char-attribute char 'kangxi-strokes)))
699 (unless (eq value strokes)
700 (insert (format "(kangxi-strokes\t . %S)%s"
704 (setq strokes value)))
705 (setq attributes (delq 'kangxi-strokes attributes))
707 (when (and (memq 'japanese-radical attributes)
708 (setq value (get-char-attribute char 'japanese-radical)))
709 (unless (eq value radical)
710 (insert (format "(japanese-radical\t . %S)\t; %c%s"
712 (aref ideographic-radicals value)
715 (setq radical value)))
716 (setq attributes (delq 'japanese-radical attributes))
718 (when (and (memq 'japanese-strokes attributes)
719 (setq value (get-char-attribute char 'japanese-strokes)))
720 (unless (eq value strokes)
721 (insert (format "(japanese-strokes\t . %S)%s"
725 (setq strokes value)))
726 (setq attributes (delq 'japanese-strokes attributes))
728 (when (and (memq 'cns-radical attributes)
729 (setq value (get-char-attribute char 'cns-radical)))
730 (insert (format "(cns-radical\t . %S)\t; %c%s"
732 (aref ideographic-radicals value)
734 (setq attributes (delq 'cns-radical attributes))
736 (when (and (memq 'cns-strokes attributes)
737 (setq value (get-char-attribute char 'cns-strokes)))
738 (unless (eq value strokes)
739 (insert (format "(cns-strokes\t . %S)%s"
743 (setq strokes value)))
744 (setq attributes (delq 'cns-strokes attributes))
746 (when (and (memq 'shinjigen-1-radical attributes)
747 (setq value (get-char-attribute char 'shinjigen-1-radical)))
748 (unless (eq value radical)
749 (insert (format "(shinjigen-1-radical . %S)\t; %c%s"
751 (aref ideographic-radicals value)
754 (setq radical value)))
755 (setq attributes (delq 'shinjigen-1-radical attributes))
757 (when (and (memq 'ideographic- attributes)
758 (setq value (get-char-attribute char 'ideographic-)))
759 (insert "(ideographic- ")
760 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
763 (setq cell (car value))
765 (setq cell (decode-char '=ucs cell)))
766 (cond ((characterp cell)
770 (insert (format "%S" cell))
771 (char-db-insert-char-spec cell readable))
772 (setq separator lbs))
776 (if (consp (car cell))
777 (char-db-insert-char-spec cell readable)
778 (char-db-insert-char-reference cell readable))
779 (setq separator lbs))
783 (insert (prin1-to-string cell))
784 (setq separator " ")))
785 (setq value (cdr value)))
787 (insert line-breaking)
788 (setq attributes (delq 'ideographic- attributes)))
789 (when (and (memq 'total-strokes attributes)
790 (setq value (get-char-attribute char 'total-strokes)))
791 (insert (format "(total-strokes . %S)%s"
794 (setq attributes (delq 'total-strokes attributes))
796 (when (and (memq '->ideograph attributes)
797 (setq value (get-char-attribute char '->ideograph)))
798 (insert (format "(->ideograph\t%s)%s"
799 (mapconcat (lambda (code)
800 (cond ((symbolp code)
803 (format "#x%04X" code))
806 line-breaking code))))
809 (setq attributes (delq '->ideograph attributes))
811 (when (and (memq '->decomposition attributes)
812 (setq value (get-char-attribute char '->decomposition)))
813 (insert (format "(->decomposition\t%s)%s"
814 (mapconcat (lambda (code)
815 (cond ((symbolp code)
824 (format "#x%04X" code))
826 (format "%s%S" line-breaking code))))
829 (setq attributes (delq '->decomposition attributes))
831 (if (equal (get-char-attribute char '->titlecase)
832 (get-char-attribute char '->uppercase))
833 (setq attributes (delq '->titlecase attributes)))
834 (when (and (memq '->mojikyo attributes)
835 (setq value (get-char-attribute char '->mojikyo)))
836 (insert (format "(->mojikyo\t\t. %06d)\t; %c%s"
837 value (decode-char 'mojikyo value)
839 (setq attributes (delq '->mojikyo attributes))
841 (when (and (memq 'hanyu-dazidian-vol attributes)
842 (setq value (get-char-attribute char 'hanyu-dazidian-vol)))
843 (insert (format "(hanyu-dazidian-vol . %d)%s"
844 value line-breaking))
845 (setq attributes (delq 'hanyu-dazidian-vol attributes))
847 (when (and (memq 'hanyu-dazidian-page attributes)
848 (setq value (get-char-attribute char 'hanyu-dazidian-page)))
849 (insert (format "(hanyu-dazidian-page . %d)%s"
850 value line-breaking))
851 (setq attributes (delq 'hanyu-dazidian-page attributes))
853 (when (and (memq 'hanyu-dazidian-char attributes)
854 (setq value (get-char-attribute char 'hanyu-dazidian-char)))
855 (insert (format "(hanyu-dazidian-char . %d)%s"
856 value line-breaking))
857 (setq attributes (delq 'hanyu-dazidian-char attributes))
860 (when (memq '->ucs-unified attributes)
861 (setq attributes (delq '->ucs-unified attributes))
863 (when (memq 'composition attributes)
864 (setq attributes (delq 'composition attributes))
866 (setq rest ccs-attributes)
869 (setq value (get-char-attribute char (car rest)))
871 (if (>= (length (symbol-name (car rest))) 19)
873 (setq has-long-ccs-name t)
877 (setq rest (cdr rest)))
879 (setq name (car attributes))
880 (if (setq value (get-char-attribute char name))
881 (cond ((string-match "^=>ucs@" (symbol-name name))
882 (insert (format "(%-18s . #x%04X)\t; %c%s"
883 name value (decode-char '=ucs value)
886 ((eq name 'jisx0208-1978/4X)
887 (insert (format "(%-18s . #x%04X)%s"
890 ((or (eq name 'ideographic-structure)
891 (eq name 'ideographic-)
892 (string-match "^\\(->\\|<-\\)" (symbol-name name)))
893 (insert (format "(%-18s%s " name line-breaking))
894 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
897 (setq cell (car value))
899 (setq cell (decode-char '=ucs cell)))
900 (cond ((eq name '->unified)
903 (let ((char-db-ignored-attributes
905 char-db-ignored-attributes)))
906 (insert-char-attributes cell readable))
907 (setq separator lbs))
912 (intern (format "%s*sources" name))))
913 (setq required-features nil)
914 (dolist (source sources)
915 (setq required-features
919 (format "=%s" source))))
923 (when (string-match "@JP" (symbol-name name))
924 (setq required-features
925 (union required-features
936 (insert (format "%S" cell))
937 (char-db-insert-char-spec cell readable
940 (setq separator lbs))
944 (if (consp (car cell))
945 (char-db-insert-char-spec cell readable)
946 (char-db-insert-char-reference cell readable))
947 (setq separator lbs))
951 (insert (prin1-to-string cell))
952 (setq separator " ")))
953 (setq value (cdr value)))
955 (insert line-breaking))
956 ((memq name '(ideograph=
957 original-ideograph-of
961 ;; simplified-ideograph-of
963 ;; ideographic-different-form-of
965 (insert (format "(%-18s%s " name line-breaking))
966 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
969 (setq cell (car value))
970 (if (and (consp cell)
975 (char-db-insert-alist cell readable)
976 (setq separator lbs))
979 (insert (prin1-to-string cell))
980 (setq separator " "))
981 (setq value (cdr value)))
983 (insert line-breaking))
985 (insert (format "(%-18s " name))
986 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
989 (setq cell (car value))
990 (if (and (consp cell)
992 (setq ret (condition-case nil
1000 (setq key (car (car rest)))
1001 (if (find-charset key)
1002 (setq cal (cons key cal))
1003 (setq al (cons key al)))
1004 (setq rest (cdr rest)))
1007 (insert-char-attributes ret
1010 (setq separator lbs))
1013 (insert (prin1-to-string cell))
1014 (setq separator " "))
1015 (setq value (cdr value)))
1017 (insert line-breaking))
1019 (insert (format "(%-18s . %S)%s"
1023 (setq attributes (cdr attributes)))
1024 (while ccs-attributes
1025 (setq name (charset-name (car ccs-attributes)))
1026 (if (and (not (memq name dest-ccss))
1028 (setq value (get-char-attribute char name))
1029 (setq dest-ccss (cons name dest-ccss))))
1032 (cond ((memq name '(=daikanwa
1033 =daikanwa-rev1 =daikanwa-rev2
1035 (if has-long-ccs-name
1036 "(%-26s . %05d)\t; %c%s"
1037 "(%-18s . %05d)\t; %c%s"))
1039 (if has-long-ccs-name
1040 "(%-26s . %06d)\t; %c%s"
1041 "(%-18s . %06d)\t; %c%s"))
1042 ((>= (charset-dimension name) 2)
1043 (if has-long-ccs-name
1044 "(%-26s . #x%04X)\t; %c%s"
1045 "(%-18s . #x%04X)\t; %c%s"))
1047 (if has-long-ccs-name
1048 "(%-26s . #x%02X)\t; %c%s"
1049 "(%-18s . #x%02X)\t; %c%s")))
1051 (if (= (charset-iso-graphic-plane name) 1)
1053 (cond ((= (charset-dimension name) 1)
1055 ((= (charset-dimension name) 2)
1057 ((= (charset-dimension name) 3)
1061 (char-db-decode-isolated-char name value)
1063 (setq ccs-attributes (cdr ccs-attributes)))
1066 (defun insert-char-data (char &optional readable
1067 attributes ccs-attributes)
1069 (narrow-to-region (point)(point))
1070 (insert "(define-char
1072 (insert-char-attributes char readable
1073 attributes ccs-attributes)
1075 (goto-char (point-min))
1076 (while (re-search-forward "[ \t]+$" nil t)
1079 (goto-char (point-min))
1080 (while (re-search-forward "[ \t][ \t][ \t]*" nil t)
1081 (let ((column (current-column))
1082 (indent-tabs-mode t))
1083 (delete-region (match-beginning 0) (point))
1084 (indent-to column)))
1085 (goto-char (point-max))
1086 ;; (tabify (point-min)(point-max))
1089 (defun insert-char-data-with-variant (char &optional printable
1091 script excluded-script)
1092 (insert-char-data char printable)
1093 (let ((variants (or (char-variants char)
1094 (let ((ucs (get-char-attribute char '->ucs)))
1096 (delete char (char-variants (int-char ucs)))))))
1098 (setq variants (sort variants #'<))
1100 (setq variant (car variants))
1101 (if (and (or (null script)
1102 (null (setq vs (get-char-attribute variant 'script)))
1104 (or (null excluded-script)
1105 (null (setq vs (get-char-attribute variant 'script)))
1106 (not (memq excluded-script vs))))
1107 (or (and no-ucs-unified (get-char-attribute variant '=ucs))
1108 (insert-char-data variant printable)))
1109 (setq variants (cdr variants))
1112 (defun insert-char-range-data (min max &optional script excluded-script)
1115 (while (<= code max)
1116 (setq char (decode-char '=ucs code))
1117 (if (encode-char char '=ucs 'defined-only)
1118 (insert-char-data-with-variant char nil 'no-ucs-unified
1119 script excluded-script))
1120 (setq code (1+ code)))))
1122 (defun write-char-range-data-to-file (min max file
1123 &optional script excluded-script)
1124 (let ((coding-system-for-write 'utf-8-mcs))
1126 (insert ";; -*- coding: utf-8-mcs -*-\n")
1127 (insert-char-range-data min max script excluded-script)
1128 (write-region (point-min)(point-max) file))))
1130 (defvar what-character-original-window-configuration)
1133 (defun what-char-definition (char)
1134 (interactive (list (char-after)))
1135 (let ((buf (get-buffer-create "*Character Description*"))
1136 (the-buf (current-buffer))
1137 (win-conf (current-window-configuration)))
1139 (make-local-variable 'what-character-original-window-configuration)
1140 (setq what-character-original-window-configuration win-conf)
1141 (setq buffer-read-only nil)
1145 (insert-char-data-with-variant char 'printable)
1146 (unless (char-attribute-alist char)
1147 (insert (format ";; = %c\n"
1148 (let* ((rest (split-char char))
1152 (setq code (logior (lsh code 8)
1154 (decode-char ccs code)))))
1155 ;; (char-db-update-comment)
1156 (set-buffer-modified-p nil)
1157 (view-mode the-buf (lambda (buf)
1158 (set-window-configuration
1159 what-character-original-window-configuration)
1161 (goto-char (point-min)))
1163 (set-window-configuration
1164 what-character-original-window-configuration)
1165 (signal (car err) (cdr err)))))))
1167 (provide 'char-db-util)
1169 ;;; char-db-util.el ends here