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)
80 ((eq '->denotational kb)
82 ((eq '->subsumptive kb)
83 (not (eq '->denotational ka)))
84 ((eq '->denotational ka)
86 ((eq '->subsumptive ka)
90 (if (<= (charset-id ka) 0)
91 (if (<= (charset-id kb) 0)
93 ((= (charset-dimension ka)
94 (charset-dimension kb))
95 (> (charset-id ka)(charset-id kb)))
97 (> (charset-dimension ka)
98 (charset-dimension kb))
101 (if (<= (charset-id kb) 0)
103 (< (charset-id ka)(charset-id kb))))
109 (string< (symbol-name ka)
115 (defvar char-db-coded-charset-priority-list
130 japanese-jisx0208-1978
171 (defun char-db-make-char-spec (char)
173 (cond ((characterp char)
174 (cond ((and (setq ret (encode-char char '=ucs 'defined-only))
175 (not (and (<= #xE000 ret)(<= ret #xF8FF))))
176 (setq char-spec (list (cons '=ucs ret)))
177 (cond ((setq ret (get-char-attribute char 'name))
178 (setq char-spec (cons (cons 'name ret) char-spec))
180 ((setq ret (get-char-attribute char 'name*))
181 (setq char-spec (cons (cons 'name* ret) char-spec))
186 (let ((rest char-db-coded-charset-priority-list)
189 (setq ccs (charset-name
190 (find-charset (car rest))))
192 (encode-char char ccs
194 (throw 'tag (cons ccs ret)))
195 (setq rest (cdr rest))))))
196 (setq char-spec (list ret))
197 (dolist (ccs (delq (car ret) (charset-list)))
198 (if (and (or (charset-iso-final-char ccs)
204 (setq ret (encode-char char ccs 'defined-only)))
205 (setq char-spec (cons (cons ccs ret) char-spec))))
207 (setq char-spec (split-char char)))
208 (cond ((setq ret (get-char-attribute char 'name))
209 (setq char-spec (cons (cons 'name ret) char-spec))
211 ((setq ret (get-char-attribute char 'name*))
212 (setq char-spec (cons (cons 'name* ret) char-spec))
219 (defun char-db-insert-char-spec (char &optional readable column
222 (setq column (current-column)))
223 (let (char-spec temp-char)
224 (setq char-spec (char-db-make-char-spec char))
225 (unless (or (characterp char) ; char
227 (setq char (find-char char-spec))
229 ;; define temporary character
230 ;; Current implementation is dirty.
231 (setq temp-char (define-char (cons '(ideograph-daikanwa . 0)
233 (remove-char-attribute temp-char 'ideograph-daikanwa)
234 (setq char temp-char))
235 (insert-char-attributes char
237 (union (mapcar #'car char-spec)
240 ;; undefine temporary character
241 ;; Current implementation is dirty.
242 (setq char-spec (char-attribute-alist temp-char))
244 (remove-char-attribute temp-char (car (car char-spec)))
245 (setq char-spec (cdr char-spec))))))
247 (defun char-db-insert-alist (alist &optional readable column)
249 (setq column (current-column)))
251 (concat "\n" (make-string (1+ column) ?\ )))
255 lbs cell rest separator)
258 (setq name (car (car alist))
259 value (cdr (car alist)))
260 (cond ((eq name 'char)
262 (if (setq ret (condition-case nil
270 (setq key (car (car value)))
271 ;; (if (find-charset key)
272 ;; (setq cal (cons key cal))
273 (setq al (cons key al))
275 (setq value (cdr value)))
276 (insert-char-attributes ret
280 (insert (prin1-to-string value)))
282 (insert line-breaking))
284 (insert (format "(%-18s " name))
285 (setq lbs (concat "\n" (make-string (current-column) ?\ )))
287 (setq cell (car value))
288 (if (and (consp cell)
290 (setq ret (condition-case nil
300 (setq key (car (car rest)))
301 ;; (if (find-charset key)
302 ;; (setq cal (cons key cal))
303 (setq al (cons key al))
305 (setq rest (cdr rest)))
308 (insert-char-attributes ret
312 (setq separator lbs))
315 (insert (prin1-to-string cell))
316 (setq separator " "))
317 (setq value (cdr value)))
319 (insert line-breaking))
321 (insert (format "(%-18s . %S)%s"
324 (setq alist (cdr alist))))
327 (defun char-db-insert-char-reference (plist &optional readable column)
329 (setq column (current-column)))
331 (concat "\n" (make-string (1+ column) ?\ )))
336 (setq name (pop plist))
337 (setq value (pop plist))
338 (cond ((eq name :char)
341 (cond ((numberp value)
342 (setq value (decode-char '=ucs value)))
344 ;; (setq value (or (find-char value)
347 (char-db-insert-char-spec value readable)
348 (insert line-breaking)
351 (insert (format "%s%s\t%d ; %c%s"
354 (aref ideographic-radicals value)
358 (insert (format "%s%s\t%S" separator name value))
359 (setq separator line-breaking)))
363 (defun char-db-decode-isolated-char (ccs code-point)
366 (cond ((eq ccs 'arabic-iso8859-6)
367 (decode-char ccs code-point))
368 ((and (memq ccs '(=gt-pj-1
379 (setq ret (decode-char ccs code-point))
380 (setq ret (encode-char ret '=gt 'defined-only)))
381 (decode-builtin-char '=gt ret))
383 (decode-builtin-char ccs code-point))))
384 (cond ((and (<= 0 (char-int ret))
385 (<= (char-int ret) #x1F))
386 (decode-char '=ucs (+ #x2400 (char-int ret))))
387 ((= (char-int ret) #x7F)
391 (defvar char-db-convert-obsolete-format t)
393 (defun insert-char-attributes (char &optional readable attributes column)
395 (setq column (current-column)))
396 (let (name value has-long-ccs-name rest
399 (concat "\n" (make-string (1+ column) ?\ )))
400 lbs cell separator ret
403 sources required-features
408 (if (consp attributes)
410 (dolist (name attributes)
411 (unless (memq name char-db-ignored-attributes)
412 (if (find-charset name)
416 (dolist (name (char-attribute-list))
417 (unless (memq name char-db-ignored-attributes)
418 (if (find-charset name)
422 #'char-attribute-name<)))
424 (when (and (memq 'name attributes)
425 (setq value (get-char-attribute char 'name)))
427 (if (> (+ (current-column) (length value)) 48)
430 value line-breaking))
431 (setq attributes (delq 'name attributes))
433 (when (and (memq 'name* attributes)
434 (setq value (get-char-attribute char 'name*)))
436 (if (> (+ (current-column) (length value)) 48)
439 value line-breaking))
440 (setq attributes (delq 'name* attributes))
442 (when (and (memq 'script attributes)
443 (setq value (get-char-attribute char 'script)))
444 (insert (format "(script\t\t%s)%s"
445 (mapconcat (function prin1-to-string)
448 (setq attributes (delq 'script attributes))
450 (dolist (name '(=>ucs =>ucs*))
451 (when (and (memq name attributes)
452 (setq value (get-char-attribute char name)))
453 (insert (format "(%-18s . #x%04X)\t; %c%s"
454 name value (decode-char '=ucs value)
456 (setq attributes (delq name attributes))))
457 (dolist (name '(=>ucs@gb =>ucs@cns =>ucs@jis =>ucs@ks =>ucs@big5))
458 (when (and (memq name attributes)
459 (setq value (get-char-attribute char name)))
460 (insert (format "(%-18s . #x%04X)\t; %c%s"
465 (symbol-name name) 2)))
468 (setq attributes (delq name attributes))
470 ;; (dolist (name '(=>ucs-gb =>ucs-cns =>ucs-jis =>ucs-ks =>ucs-big5))
471 ;; (when (and (memq name attributes)
472 ;; (setq value (get-char-attribute char name)))
473 ;; (insert (format "(%-18s . #x%04X)\t; %c%s"
476 ;; (substring (symbol-name name) 6)))
478 ;; (decode-char (intern
481 ;; (symbol-name name) 6)))
484 ;; (setq attributes (delq name attributes))))
485 ;; (when (and (memq '->ucs attributes)
486 ;; (setq value (get-char-attribute char '->ucs)))
487 ;; (insert (format (if char-db-convert-obsolete-format
488 ;; "(=>ucs\t\t. #x%04X)\t; %c%s"
489 ;; "(->ucs\t\t. #x%04X)\t; %c%s")
490 ;; value (decode-char '=ucs value)
492 ;; (setq attributes (delq '->ucs attributes))
494 (dolist (name '(=>daikanwa))
495 (when (and (memq name attributes)
496 (setq value (get-char-attribute char name)))
499 (format "(%-18s . %05d)\t; %c%s"
500 name value (decode-char '=daikanwa value)
502 (format "(%-18s %s)\t; %c%s"
504 (mapconcat (function prin1-to-string)
506 (char-representative-of-daikanwa char)
508 (setq attributes (delq name attributes))))
509 (when (and (memq 'general-category attributes)
510 (setq value (get-char-attribute char 'general-category)))
512 "(general-category\t%s) ; %s%s"
513 (mapconcat (lambda (cell)
516 (cond ((rassoc value unidata-normative-category-alist)
517 "Normative Category")
518 ((rassoc value unidata-informative-category-alist)
519 "Informative Category")
523 (setq attributes (delq 'general-category attributes))
525 (when (and (memq 'bidi-category attributes)
526 (setq value (get-char-attribute char 'bidi-category)))
527 (insert (format "(bidi-category\t. %S)%s"
530 (setq attributes (delq 'bidi-category attributes))
532 (unless (or (not (memq 'mirrored attributes))
533 (eq (setq value (get-char-attribute char 'mirrored 'empty))
535 (insert (format "(mirrored\t\t. %S)%s"
538 (setq attributes (delq 'mirrored attributes))
541 ((and (memq 'decimal-digit-value attributes)
542 (setq value (get-char-attribute char 'decimal-digit-value)))
543 (insert (format "(decimal-digit-value . %S)%s"
546 (setq attributes (delq 'decimal-digit-value attributes))
547 (when (and (memq 'digit-value attributes)
548 (setq value (get-char-attribute char 'digit-value)))
549 (insert (format "(digit-value\t . %S)%s"
552 (setq attributes (delq 'digit-value attributes))
554 (when (and (memq 'numeric-value attributes)
555 (setq value (get-char-attribute char 'numeric-value)))
556 (insert (format "(numeric-value\t . %S)%s"
559 (setq attributes (delq 'numeric-value attributes))
563 (when (and (memq 'digit-value attributes)
564 (setq value (get-char-attribute char 'digit-value)))
565 (insert (format "(digit-value\t. %S)%s"
568 (setq attributes (delq 'digit-value attributes))
570 (when (and (memq 'numeric-value attributes)
571 (setq value (get-char-attribute char 'numeric-value)))
572 (insert (format "(numeric-value\t. %S)%s"
575 (setq attributes (delq 'numeric-value attributes))
577 (when (and (memq 'iso-10646-comment attributes)
578 (setq value (get-char-attribute char 'iso-10646-comment)))
579 (insert (format "(iso-10646-comment\t. %S)%s"
582 (setq attributes (delq 'iso-10646-comment attributes))
584 (when (and (memq 'morohashi-daikanwa attributes)
585 (setq value (get-char-attribute char 'morohashi-daikanwa)))
586 (insert (format "(morohashi-daikanwa\t%s)%s"
587 (mapconcat (function prin1-to-string) value " ")
589 (setq attributes (delq 'morohashi-daikanwa attributes))
593 (when (and (memq 'ideographic-radical attributes)
594 (setq value (get-char-attribute char 'ideographic-radical)))
596 (insert (format "(ideographic-radical . %S)\t; %c%s"
598 (aref ideographic-radicals radical)
600 (setq attributes (delq 'ideographic-radical attributes))
603 (dolist (domain char-db-feature-domains)
604 (setq key (intern (format "%s@%s" 'ideographic-radical domain)))
605 (when (and (memq key attributes)
606 (setq value (get-char-attribute char key)))
608 (insert (format "(%s . %S)\t; %c%s"
611 (aref ideographic-radicals radical)
613 (setq attributes (delq key attributes))
615 (setq key (intern (format "%s@%s" 'ideographic-strokes domain)))
616 (when (and (memq key attributes)
617 (setq value (get-char-attribute char key)))
619 (insert (format "(%s . %S)%s"
623 (setq attributes (delq key attributes))
625 (setq key (intern (format "%s@%s" 'total-strokes domain)))
626 (when (and (memq key attributes)
627 (setq value (get-char-attribute char key)))
628 (insert (format "(%s . %S)%s"
632 (setq attributes (delq key attributes))
634 (dolist (feature '(ideographic-radical
637 (setq key (intern (format "%s@%s*sources" feature domain)))
638 (when (and (memq key attributes)
639 (setq value (get-char-attribute char key)))
640 (insert (format "(%s%s" key line-breaking))
642 (insert (format " %s" cell)))
644 (insert line-breaking)
645 (setq attributes (delq key attributes))
648 (when (and (memq 'ideographic-strokes attributes)
649 (setq value (get-char-attribute char 'ideographic-strokes)))
651 (insert (format "(ideographic-strokes . %S)%s"
654 (setq attributes (delq 'ideographic-strokes attributes))
656 (when (and (memq 'kangxi-radical attributes)
657 (setq value (get-char-attribute char 'kangxi-radical)))
658 (unless (eq value radical)
659 (insert (format "(kangxi-radical\t . %S)\t; %c%s"
661 (aref ideographic-radicals value)
664 (setq radical value)))
665 (setq attributes (delq 'kangxi-radical attributes))
667 (when (and (memq 'kangxi-strokes attributes)
668 (setq value (get-char-attribute char 'kangxi-strokes)))
669 (unless (eq value strokes)
670 (insert (format "(kangxi-strokes\t . %S)%s"
674 (setq strokes value)))
675 (setq attributes (delq 'kangxi-strokes attributes))
677 (when (and (memq 'japanese-radical attributes)
678 (setq value (get-char-attribute char 'japanese-radical)))
679 (unless (eq value radical)
680 (insert (format "(japanese-radical\t . %S)\t; %c%s"
682 (aref ideographic-radicals value)
685 (setq radical value)))
686 (setq attributes (delq 'japanese-radical attributes))
688 (when (and (memq 'japanese-strokes attributes)
689 (setq value (get-char-attribute char 'japanese-strokes)))
690 (unless (eq value strokes)
691 (insert (format "(japanese-strokes\t . %S)%s"
695 (setq strokes value)))
696 (setq attributes (delq 'japanese-strokes attributes))
698 (when (and (memq 'cns-radical attributes)
699 (setq value (get-char-attribute char 'cns-radical)))
700 (insert (format "(cns-radical\t . %S)\t; %c%s"
702 (aref ideographic-radicals value)
704 (setq attributes (delq 'cns-radical attributes))
706 (when (and (memq 'cns-strokes attributes)
707 (setq value (get-char-attribute char 'cns-strokes)))
708 (unless (eq value strokes)
709 (insert (format "(cns-strokes\t . %S)%s"
713 (setq strokes value)))
714 (setq attributes (delq 'cns-strokes attributes))
716 (when (and (memq 'shinjigen-1-radical attributes)
717 (setq value (get-char-attribute char 'shinjigen-1-radical)))
718 (unless (eq value radical)
719 (insert (format "(shinjigen-1-radical . %S)\t; %c%s"
721 (aref ideographic-radicals value)
724 (setq radical value)))
725 (setq attributes (delq 'shinjigen-1-radical attributes))
727 (when (and (memq 'ideographic- attributes)
728 (setq value (get-char-attribute char 'ideographic-)))
729 (insert "(ideographic- ")
730 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
733 (setq cell (car value))
735 (setq cell (decode-char '=ucs cell)))
736 (cond ((characterp cell)
740 (insert (format "%S" cell))
741 (char-db-insert-char-spec cell readable))
742 (setq separator lbs))
746 (if (consp (car cell))
747 (char-db-insert-char-spec cell readable)
748 (char-db-insert-char-reference cell readable))
749 (setq separator lbs))
753 (insert (prin1-to-string cell))
754 (setq separator " ")))
755 (setq value (cdr value)))
757 (insert line-breaking)
758 (setq attributes (delq 'ideographic- attributes)))
759 (when (and (memq 'total-strokes attributes)
760 (setq value (get-char-attribute char 'total-strokes)))
761 (insert (format "(total-strokes . %S)%s"
764 (setq attributes (delq 'total-strokes attributes))
766 (when (and (memq '->ideograph attributes)
767 (setq value (get-char-attribute char '->ideograph)))
768 (insert (format "(->ideograph\t%s)%s"
769 (mapconcat (lambda (code)
770 (cond ((symbolp code)
773 (format "#x%04X" code))
776 line-breaking code))))
779 (setq attributes (delq '->ideograph attributes))
781 (when (and (memq '->decomposition attributes)
782 (setq value (get-char-attribute char '->decomposition)))
783 (insert (format "(->decomposition\t%s)%s"
784 (mapconcat (lambda (code)
785 (cond ((symbolp code)
794 (format "#x%04X" code))
796 (format "%s%S" line-breaking code))))
799 (setq attributes (delq '->decomposition attributes))
801 (if (equal (get-char-attribute char '->titlecase)
802 (get-char-attribute char '->uppercase))
803 (setq attributes (delq '->titlecase attributes)))
804 (when (and (memq '->mojikyo attributes)
805 (setq value (get-char-attribute char '->mojikyo)))
806 (insert (format "(->mojikyo\t\t. %06d)\t; %c%s"
807 value (decode-char 'mojikyo value)
809 (setq attributes (delq '->mojikyo attributes))
811 (when (and (memq 'hanyu-dazidian-vol attributes)
812 (setq value (get-char-attribute char 'hanyu-dazidian-vol)))
813 (insert (format "(hanyu-dazidian-vol . %d)%s"
814 value line-breaking))
815 (setq attributes (delq 'hanyu-dazidian-vol attributes))
817 (when (and (memq 'hanyu-dazidian-page attributes)
818 (setq value (get-char-attribute char 'hanyu-dazidian-page)))
819 (insert (format "(hanyu-dazidian-page . %d)%s"
820 value line-breaking))
821 (setq attributes (delq 'hanyu-dazidian-page attributes))
823 (when (and (memq 'hanyu-dazidian-char attributes)
824 (setq value (get-char-attribute char 'hanyu-dazidian-char)))
825 (insert (format "(hanyu-dazidian-char . %d)%s"
826 value line-breaking))
827 (setq attributes (delq 'hanyu-dazidian-char attributes))
830 (dolist (ignored '(composition
831 ->denotational <-subsumptive ->ucs-unified))
832 (setq attributes (delq ignored attributes))))
833 ;; (setq rest ccs-attributes)
836 ;; (setq value (get-char-attribute char (car rest)))
838 ;; (if (>= (length (symbol-name (car rest))) 19)
840 ;; (setq has-long-ccs-name t)
844 ;; (setq rest (cdr rest)))
846 (setq name (car attributes))
847 (if (setq value (get-char-attribute char name))
848 (cond ((setq ret (find-charset name))
849 (setq name (charset-name ret))
850 (if (and (not (memq name dest-ccss))
852 (setq value (get-char-attribute char name))
853 (setq dest-ccss (cons name dest-ccss))))
856 (cond ((memq name '(=daikanwa
857 =daikanwa-rev1 =daikanwa-rev2
859 (if has-long-ccs-name
860 "(%-26s . %05d)\t; %c%s"
861 "(%-18s . %05d)\t; %c%s"))
863 (if has-long-ccs-name
864 "(%-26s . %06d)\t; %c%s"
865 "(%-18s . %06d)\t; %c%s"))
866 ((>= (charset-dimension name) 2)
867 (if has-long-ccs-name
868 "(%-26s . #x%04X)\t; %c%s"
869 "(%-18s . #x%04X)\t; %c%s"))
871 (if has-long-ccs-name
872 "(%-26s . #x%02X)\t; %c%s"
873 "(%-18s . #x%02X)\t; %c%s")))
875 (if (= (charset-iso-graphic-plane name) 1)
877 (cond ((= (charset-dimension name) 1)
879 ((= (charset-dimension name) 2)
881 ((= (charset-dimension name) 3)
885 (char-db-decode-isolated-char name value)
888 ((string-match "^=>ucs@" (symbol-name name))
889 (insert (format "(%-18s . #x%04X)\t; %c%s"
890 name value (decode-char '=ucs value)
893 ((eq name 'jisx0208-1978/4X)
894 (insert (format "(%-18s . #x%04X)%s"
899 (or (eq name '<-identical)
900 (string-match "^->simplified" (symbol-name name))))
902 ((or (eq name 'ideographic-structure)
903 (eq name 'ideographic-)
904 (string-match "^\\(->\\|<-\\)" (symbol-name name)))
905 (insert (format "(%-18s%s " name line-breaking))
906 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
909 (setq cell (car value))
911 (setq cell (decode-char '=ucs cell)))
912 (cond ((eq name '->subsumptive)
915 (get-char-attribute cell atr))
916 char-db-ignored-attributes))
918 (encode-char cell ccs
923 (let ((char-db-ignored-attributes
925 char-db-ignored-attributes)))
926 (insert-char-attributes cell readable))
927 (setq separator lbs))
933 (intern (format "%s*sources" name))))
934 (setq required-features nil)
935 (dolist (source sources)
936 (setq required-features
940 (format "=%s" source))))
944 (when (string-match "@JP" (symbol-name name))
945 (setq required-features
946 (union required-features
957 (insert (format "%S" cell))
958 (char-db-insert-char-spec cell readable
961 (setq separator lbs))
965 (if (consp (car cell))
966 (char-db-insert-char-spec cell readable)
967 (char-db-insert-char-reference cell readable))
968 (setq separator lbs))
972 (insert (prin1-to-string cell))
973 (setq separator " ")))
974 (setq value (cdr value)))
976 (insert line-breaking))
977 ((memq name '(ideograph=
978 original-ideograph-of
982 ;; simplified-ideograph-of
984 ;; ideographic-different-form-of
986 (insert (format "(%-18s%s " name line-breaking))
987 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
990 (setq cell (car value))
991 (if (and (consp cell)
996 (char-db-insert-alist cell readable)
997 (setq separator lbs))
1000 (insert (prin1-to-string cell))
1001 (setq separator " "))
1002 (setq value (cdr value)))
1004 (insert line-breaking))
1006 (insert (format "(%-18s " name))
1007 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1009 (while (consp value)
1010 (setq cell (car value))
1011 (if (and (consp cell)
1013 (setq ret (condition-case nil
1021 (setq key (car (car rest)))
1022 (if (find-charset key)
1023 (setq cal (cons key cal))
1024 (setq al (cons key al)))
1025 (setq rest (cdr rest)))
1028 (insert-char-attributes ret
1031 (setq separator lbs))
1032 (setq ret (prin1-to-string cell))
1034 (if (< (+ (current-column)
1041 (setq separator " "))
1042 (setq value (cdr value)))
1044 (insert line-breaking))
1046 (insert (format "(%-18s . %S)%s"
1050 (setq attributes (cdr attributes)))
1051 ;; (while ccs-attributes
1052 ;; (setq name (charset-name (car ccs-attributes)))
1053 ;; (if (and (not (memq name dest-ccss))
1055 ;; (setq value (get-char-attribute char name))
1056 ;; (setq dest-ccss (cons name dest-ccss))))
1059 ;; (cond ((memq name '(=daikanwa
1060 ;; =daikanwa-rev1 =daikanwa-rev2
1061 ;; =gt =gt-k =cbeta))
1062 ;; (if has-long-ccs-name
1063 ;; "(%-26s . %05d)\t; %c%s"
1064 ;; "(%-18s . %05d)\t; %c%s"))
1065 ;; ((eq name 'mojikyo)
1066 ;; (if has-long-ccs-name
1067 ;; "(%-26s . %06d)\t; %c%s"
1068 ;; "(%-18s . %06d)\t; %c%s"))
1069 ;; ((>= (charset-dimension name) 2)
1070 ;; (if has-long-ccs-name
1071 ;; "(%-26s . #x%04X)\t; %c%s"
1072 ;; "(%-18s . #x%04X)\t; %c%s"))
1074 ;; (if has-long-ccs-name
1075 ;; "(%-26s . #x%02X)\t; %c%s"
1076 ;; "(%-18s . #x%02X)\t; %c%s")))
1078 ;; (if (= (charset-iso-graphic-plane name) 1)
1080 ;; (cond ((= (charset-dimension name) 1)
1082 ;; ((= (charset-dimension name) 2)
1084 ;; ((= (charset-dimension name) 3)
1088 ;; (char-db-decode-isolated-char name value)
1090 ;; (setq ccs-attributes (cdr ccs-attributes)))
1093 (defun insert-char-data (char &optional readable
1096 (narrow-to-region (point)(point))
1097 (insert "(define-char
1099 (insert-char-attributes char readable attributes)
1101 (goto-char (point-min))
1102 (while (re-search-forward "[ \t]+$" nil t)
1105 (goto-char (point-min))
1106 (while (re-search-forward "[ \t][ \t][ \t]*" nil t)
1107 (let ((column (current-column))
1108 (indent-tabs-mode t))
1109 (delete-region (match-beginning 0) (point))
1110 (indent-to column)))
1111 (goto-char (point-max))
1112 ;; (tabify (point-min)(point-max))
1115 (defun insert-char-data-with-variant (char &optional printable
1117 script excluded-script)
1118 (insert-char-data char printable)
1119 (let ((variants (or (char-variants char)
1120 (let ((ucs (get-char-attribute char '->ucs)))
1122 (delete char (char-variants (int-char ucs)))))))
1124 (setq variants (sort variants #'<))
1126 (setq variant (car variants))
1127 (if (and (or (null script)
1128 (null (setq vs (get-char-attribute variant 'script)))
1130 (or (null excluded-script)
1131 (null (setq vs (get-char-attribute variant 'script)))
1132 (not (memq excluded-script vs))))
1133 (or (and no-ucs-unified (get-char-attribute variant '=ucs))
1134 (insert-char-data variant printable)))
1135 (setq variants (cdr variants))
1138 (defun insert-char-range-data (min max &optional script excluded-script)
1141 (while (<= code max)
1142 (setq char (decode-char '=ucs code))
1143 (if (encode-char char '=ucs 'defined-only)
1144 (insert-char-data-with-variant char nil 'no-ucs-unified
1145 script excluded-script))
1146 (setq code (1+ code)))))
1148 (defun write-char-range-data-to-file (min max file
1149 &optional script excluded-script)
1150 (let ((coding-system-for-write 'utf-8-mcs))
1152 (insert ";; -*- coding: utf-8-mcs -*-\n")
1153 (insert-char-range-data min max script excluded-script)
1154 (write-region (point-min)(point-max) file))))
1156 (defvar what-character-original-window-configuration)
1159 (defun what-char-definition (char)
1160 (interactive (list (char-after)))
1161 (let ((buf (get-buffer-create "*Character Description*"))
1162 (the-buf (current-buffer))
1163 (win-conf (current-window-configuration)))
1165 (make-local-variable 'what-character-original-window-configuration)
1166 (setq what-character-original-window-configuration win-conf)
1167 (setq buffer-read-only nil)
1171 (insert-char-data-with-variant char 'printable)
1172 (unless (char-attribute-alist char)
1173 (insert (format ";; = %c\n"
1174 (let* ((rest (split-char char))
1178 (setq code (logior (lsh code 8)
1180 (decode-char ccs code)))))
1181 ;; (char-db-update-comment)
1182 (set-buffer-modified-p nil)
1183 (view-mode the-buf (lambda (buf)
1184 (set-window-configuration
1185 what-character-original-window-configuration)
1187 (goto-char (point-min)))
1189 (set-window-configuration
1190 what-character-original-window-configuration)
1191 (signal (car err) (cdr err)))))))
1193 (provide 'char-db-util)
1195 ;;; char-db-util.el ends here