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 ;; (when (and (memq '<-denotational attributes)
451 ;; (setq value (get-char-attribute char '<-denotational))
452 ;; (null (cdr value))
453 ;; (setq value (encode-char (car value) 'ucs 'defined-only)))
454 ;; (insert (format "(%-18s . #x%04X)\t; %c%s"
455 ;; '=>ucs value (decode-char 'ucs value)
457 ;; (setq attributes (delq '<-denotational attributes)))
458 (dolist (name '(=>ucs =>ucs*))
459 (when (and (memq name attributes)
460 (setq value (get-char-attribute char name)))
461 (insert (format "(%-18s . #x%04X)\t; %c%s"
462 name value (decode-char '=ucs value)
464 (setq attributes (delq name attributes))))
465 (dolist (name '(=>ucs@gb =>ucs@cns =>ucs@jis =>ucs@ks =>ucs@big5))
466 (when (and (memq name attributes)
467 (setq value (get-char-attribute char name)))
468 (insert (format "(%-18s . #x%04X)\t; %c%s"
473 (symbol-name name) 2)))
476 (setq attributes (delq name attributes))
478 ;; (dolist (name '(=>ucs-gb =>ucs-cns =>ucs-jis =>ucs-ks =>ucs-big5))
479 ;; (when (and (memq name attributes)
480 ;; (setq value (get-char-attribute char name)))
481 ;; (insert (format "(%-18s . #x%04X)\t; %c%s"
484 ;; (substring (symbol-name name) 6)))
486 ;; (decode-char (intern
489 ;; (symbol-name name) 6)))
492 ;; (setq attributes (delq name attributes))))
493 ;; (when (and (memq '->ucs attributes)
494 ;; (setq value (get-char-attribute char '->ucs)))
495 ;; (insert (format (if char-db-convert-obsolete-format
496 ;; "(=>ucs\t\t. #x%04X)\t; %c%s"
497 ;; "(->ucs\t\t. #x%04X)\t; %c%s")
498 ;; value (decode-char '=ucs value)
500 ;; (setq attributes (delq '->ucs attributes))
502 (dolist (name '(=>daikanwa))
503 (when (and (memq name attributes)
504 (setq value (get-char-attribute char name)))
507 (format "(%-18s . %05d)\t; %c%s"
508 name value (decode-char '=daikanwa value)
510 (format "(%-18s %s)\t; %c%s"
512 (mapconcat (function prin1-to-string)
514 (char-representative-of-daikanwa char)
516 (setq attributes (delq name attributes))))
517 (when (and (memq 'general-category attributes)
518 (setq value (get-char-attribute char 'general-category)))
520 "(general-category\t%s) ; %s%s"
521 (mapconcat (lambda (cell)
524 (cond ((rassoc value unidata-normative-category-alist)
525 "Normative Category")
526 ((rassoc value unidata-informative-category-alist)
527 "Informative Category")
531 (setq attributes (delq 'general-category attributes))
533 (when (and (memq 'bidi-category attributes)
534 (setq value (get-char-attribute char 'bidi-category)))
535 (insert (format "(bidi-category\t. %S)%s"
538 (setq attributes (delq 'bidi-category attributes))
540 (unless (or (not (memq 'mirrored attributes))
541 (eq (setq value (get-char-attribute char 'mirrored 'empty))
543 (insert (format "(mirrored\t\t. %S)%s"
546 (setq attributes (delq 'mirrored attributes))
549 ((and (memq 'decimal-digit-value attributes)
550 (setq value (get-char-attribute char 'decimal-digit-value)))
551 (insert (format "(decimal-digit-value . %S)%s"
554 (setq attributes (delq 'decimal-digit-value attributes))
555 (when (and (memq 'digit-value attributes)
556 (setq value (get-char-attribute char 'digit-value)))
557 (insert (format "(digit-value\t . %S)%s"
560 (setq attributes (delq 'digit-value attributes))
562 (when (and (memq 'numeric-value attributes)
563 (setq value (get-char-attribute char 'numeric-value)))
564 (insert (format "(numeric-value\t . %S)%s"
567 (setq attributes (delq 'numeric-value attributes))
571 (when (and (memq 'digit-value attributes)
572 (setq value (get-char-attribute char 'digit-value)))
573 (insert (format "(digit-value\t. %S)%s"
576 (setq attributes (delq 'digit-value attributes))
578 (when (and (memq 'numeric-value attributes)
579 (setq value (get-char-attribute char 'numeric-value)))
580 (insert (format "(numeric-value\t. %S)%s"
583 (setq attributes (delq 'numeric-value attributes))
585 (when (and (memq 'iso-10646-comment attributes)
586 (setq value (get-char-attribute char 'iso-10646-comment)))
587 (insert (format "(iso-10646-comment\t. %S)%s"
590 (setq attributes (delq 'iso-10646-comment attributes))
592 (when (and (memq 'morohashi-daikanwa attributes)
593 (setq value (get-char-attribute char 'morohashi-daikanwa)))
594 (insert (format "(morohashi-daikanwa\t%s)%s"
595 (mapconcat (function prin1-to-string) value " ")
597 (setq attributes (delq 'morohashi-daikanwa attributes))
601 (when (and (memq 'ideographic-radical attributes)
602 (setq value (get-char-attribute char 'ideographic-radical)))
604 (insert (format "(ideographic-radical . %S)\t; %c%s"
606 (aref ideographic-radicals radical)
608 (setq attributes (delq 'ideographic-radical attributes))
611 (dolist (domain char-db-feature-domains)
612 (setq key (intern (format "%s@%s" 'ideographic-radical domain)))
613 (when (and (memq key attributes)
614 (setq value (get-char-attribute char key)))
616 (insert (format "(%s . %S)\t; %c%s"
619 (aref ideographic-radicals radical)
621 (setq attributes (delq key attributes))
623 (setq key (intern (format "%s@%s" 'ideographic-strokes domain)))
624 (when (and (memq key attributes)
625 (setq value (get-char-attribute char key)))
627 (insert (format "(%s . %S)%s"
631 (setq attributes (delq key attributes))
633 (setq key (intern (format "%s@%s" 'total-strokes domain)))
634 (when (and (memq key attributes)
635 (setq value (get-char-attribute char key)))
636 (insert (format "(%s . %S)%s"
640 (setq attributes (delq key attributes))
642 (dolist (feature '(ideographic-radical
645 (setq key (intern (format "%s@%s*sources" feature domain)))
646 (when (and (memq key attributes)
647 (setq value (get-char-attribute char key)))
648 (insert (format "(%s%s" key line-breaking))
650 (insert (format " %s" cell)))
652 (insert line-breaking)
653 (setq attributes (delq key attributes))
656 (when (and (memq 'ideographic-strokes attributes)
657 (setq value (get-char-attribute char 'ideographic-strokes)))
659 (insert (format "(ideographic-strokes . %S)%s"
662 (setq attributes (delq 'ideographic-strokes attributes))
664 (when (and (memq 'kangxi-radical attributes)
665 (setq value (get-char-attribute char 'kangxi-radical)))
666 (unless (eq value radical)
667 (insert (format "(kangxi-radical\t . %S)\t; %c%s"
669 (aref ideographic-radicals value)
672 (setq radical value)))
673 (setq attributes (delq 'kangxi-radical attributes))
675 (when (and (memq 'kangxi-strokes attributes)
676 (setq value (get-char-attribute char 'kangxi-strokes)))
677 (unless (eq value strokes)
678 (insert (format "(kangxi-strokes\t . %S)%s"
682 (setq strokes value)))
683 (setq attributes (delq 'kangxi-strokes attributes))
685 (when (and (memq 'japanese-radical attributes)
686 (setq value (get-char-attribute char 'japanese-radical)))
687 (unless (eq value radical)
688 (insert (format "(japanese-radical\t . %S)\t; %c%s"
690 (aref ideographic-radicals value)
693 (setq radical value)))
694 (setq attributes (delq 'japanese-radical attributes))
696 (when (and (memq 'japanese-strokes attributes)
697 (setq value (get-char-attribute char 'japanese-strokes)))
698 (unless (eq value strokes)
699 (insert (format "(japanese-strokes\t . %S)%s"
703 (setq strokes value)))
704 (setq attributes (delq 'japanese-strokes attributes))
706 (when (and (memq 'cns-radical attributes)
707 (setq value (get-char-attribute char 'cns-radical)))
708 (insert (format "(cns-radical\t . %S)\t; %c%s"
710 (aref ideographic-radicals value)
712 (setq attributes (delq 'cns-radical attributes))
714 (when (and (memq 'cns-strokes attributes)
715 (setq value (get-char-attribute char 'cns-strokes)))
716 (unless (eq value strokes)
717 (insert (format "(cns-strokes\t . %S)%s"
721 (setq strokes value)))
722 (setq attributes (delq 'cns-strokes attributes))
724 (when (and (memq 'shinjigen-1-radical attributes)
725 (setq value (get-char-attribute char 'shinjigen-1-radical)))
726 (unless (eq value radical)
727 (insert (format "(shinjigen-1-radical . %S)\t; %c%s"
729 (aref ideographic-radicals value)
732 (setq radical value)))
733 (setq attributes (delq 'shinjigen-1-radical attributes))
735 (when (and (memq 'ideographic- attributes)
736 (setq value (get-char-attribute char 'ideographic-)))
737 (insert "(ideographic- ")
738 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
741 (setq cell (car value))
743 (setq cell (decode-char '=ucs cell)))
744 (cond ((characterp cell)
748 (insert (format "%S" cell))
749 (char-db-insert-char-spec cell readable))
750 (setq separator lbs))
754 (if (consp (car cell))
755 (char-db-insert-char-spec cell readable)
756 (char-db-insert-char-reference cell readable))
757 (setq separator lbs))
761 (insert (prin1-to-string cell))
762 (setq separator " ")))
763 (setq value (cdr value)))
765 (insert line-breaking)
766 (setq attributes (delq 'ideographic- attributes)))
767 (when (and (memq 'total-strokes attributes)
768 (setq value (get-char-attribute char 'total-strokes)))
769 (insert (format "(total-strokes . %S)%s"
772 (setq attributes (delq 'total-strokes attributes))
774 (when (and (memq '->ideograph attributes)
775 (setq value (get-char-attribute char '->ideograph)))
776 (insert (format "(->ideograph\t%s)%s"
777 (mapconcat (lambda (code)
778 (cond ((symbolp code)
781 (format "#x%04X" code))
784 line-breaking code))))
787 (setq attributes (delq '->ideograph attributes))
789 (when (and (memq '->decomposition attributes)
790 (setq value (get-char-attribute char '->decomposition)))
791 (insert (format "(->decomposition\t%s)%s"
792 (mapconcat (lambda (code)
793 (cond ((symbolp code)
802 (format "#x%04X" code))
804 (format "%s%S" line-breaking code))))
807 (setq attributes (delq '->decomposition attributes))
809 (if (equal (get-char-attribute char '->titlecase)
810 (get-char-attribute char '->uppercase))
811 (setq attributes (delq '->titlecase attributes)))
812 (when (and (memq '->mojikyo attributes)
813 (setq value (get-char-attribute char '->mojikyo)))
814 (insert (format "(->mojikyo\t\t. %06d)\t; %c%s"
815 value (decode-char 'mojikyo value)
817 (setq attributes (delq '->mojikyo attributes))
819 (when (and (memq 'hanyu-dazidian-vol attributes)
820 (setq value (get-char-attribute char 'hanyu-dazidian-vol)))
821 (insert (format "(hanyu-dazidian-vol . %d)%s"
822 value line-breaking))
823 (setq attributes (delq 'hanyu-dazidian-vol attributes))
825 (when (and (memq 'hanyu-dazidian-page attributes)
826 (setq value (get-char-attribute char 'hanyu-dazidian-page)))
827 (insert (format "(hanyu-dazidian-page . %d)%s"
828 value line-breaking))
829 (setq attributes (delq 'hanyu-dazidian-page attributes))
831 (when (and (memq 'hanyu-dazidian-char attributes)
832 (setq value (get-char-attribute char 'hanyu-dazidian-char)))
833 (insert (format "(hanyu-dazidian-char . %d)%s"
834 value line-breaking))
835 (setq attributes (delq 'hanyu-dazidian-char attributes))
838 (dolist (ignored '(composition
839 ->denotational <-subsumptive ->ucs-unified
840 ->ideographic-component-forms))
841 (setq attributes (delq ignored attributes))))
842 ;; (setq rest ccs-attributes)
845 ;; (setq value (get-char-attribute char (car rest)))
847 ;; (if (>= (length (symbol-name (car rest))) 19)
849 ;; (setq has-long-ccs-name t)
853 ;; (setq rest (cdr rest)))
855 (setq name (car attributes))
856 (if (setq value (get-char-attribute char name))
857 (cond ((setq ret (find-charset name))
858 (setq name (charset-name ret))
859 (if (and (not (memq name dest-ccss))
861 (setq value (get-char-attribute char name))
862 (setq dest-ccss (cons name dest-ccss))))
865 (cond ((memq name '(=daikanwa
866 =daikanwa-rev1 =daikanwa-rev2
868 (if has-long-ccs-name
869 "(%-26s . %05d)\t; %c%s"
870 "(%-18s . %05d)\t; %c%s"))
872 (if has-long-ccs-name
873 "(%-26s . %06d)\t; %c%s"
874 "(%-18s . %06d)\t; %c%s"))
875 ((>= (charset-dimension name) 2)
876 (if has-long-ccs-name
877 "(%-26s . #x%04X)\t; %c%s"
878 "(%-18s . #x%04X)\t; %c%s"))
880 (if has-long-ccs-name
881 "(%-26s . #x%02X)\t; %c%s"
882 "(%-18s . #x%02X)\t; %c%s")))
884 (if (= (charset-iso-graphic-plane name) 1)
886 (cond ((= (charset-dimension name) 1)
888 ((= (charset-dimension name) 2)
890 ((= (charset-dimension name) 3)
894 (char-db-decode-isolated-char name value)
897 ((string-match "^=>ucs@" (symbol-name name))
898 (insert (format "(%-18s . #x%04X)\t; %c%s"
899 name value (decode-char '=ucs value)
902 ((eq name 'jisx0208-1978/4X)
903 (insert (format "(%-18s . #x%04X)%s"
908 (or (eq name '<-identical)
909 (string-match "^->simplified" (symbol-name name))))
911 ((or (eq name 'ideographic-structure)
912 (eq name 'ideographic-)
913 (string-match "^\\(->\\|<-\\)" (symbol-name name)))
914 (insert (format "(%-18s%s " name line-breaking))
915 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
918 (setq cell (car value))
920 (setq cell (decode-char '=ucs cell)))
921 (cond ((eq name '->subsumptive)
924 (get-char-attribute cell atr))
925 char-db-ignored-attributes))
927 (encode-char cell ccs
932 (let ((char-db-ignored-attributes
934 char-db-ignored-attributes)))
935 (insert-char-attributes cell readable))
936 (setq separator lbs))
942 (intern (format "%s*sources" name))))
943 (setq required-features nil)
944 (dolist (source sources)
945 (setq required-features
949 (format "=%s" source))))
953 (when (string-match "@JP" (symbol-name name))
954 (setq required-features
955 (union required-features
966 (insert (format "%S" cell))
967 (char-db-insert-char-spec cell readable
970 (setq separator lbs))
974 (if (consp (car cell))
975 (char-db-insert-char-spec cell readable)
976 (char-db-insert-char-reference cell readable))
977 (setq separator lbs))
981 (insert (prin1-to-string cell))
982 (setq separator " ")))
983 (setq value (cdr value)))
985 (insert line-breaking))
986 ((memq name '(ideograph=
987 original-ideograph-of
991 ;; simplified-ideograph-of
993 ;; ideographic-different-form-of
995 (insert (format "(%-18s%s " name line-breaking))
996 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
999 (setq cell (car value))
1000 (if (and (consp cell)
1005 (char-db-insert-alist cell readable)
1006 (setq separator lbs))
1009 (insert (prin1-to-string cell))
1010 (setq separator " "))
1011 (setq value (cdr value)))
1013 (insert line-breaking))
1015 (insert (format "(%-18s " name))
1016 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1018 (while (consp value)
1019 (setq cell (car value))
1020 (if (and (consp cell)
1022 (setq ret (condition-case nil
1030 (setq key (car (car rest)))
1031 (if (find-charset key)
1032 (setq cal (cons key cal))
1033 (setq al (cons key al)))
1034 (setq rest (cdr rest)))
1037 (insert-char-attributes ret
1040 (setq separator lbs))
1041 (setq ret (prin1-to-string cell))
1043 (if (< (+ (current-column)
1050 (setq separator " "))
1051 (setq value (cdr value)))
1053 (insert line-breaking))
1055 (insert (format "(%-18s . %S)%s"
1059 (setq attributes (cdr attributes)))
1060 ;; (while ccs-attributes
1061 ;; (setq name (charset-name (car ccs-attributes)))
1062 ;; (if (and (not (memq name dest-ccss))
1064 ;; (setq value (get-char-attribute char name))
1065 ;; (setq dest-ccss (cons name dest-ccss))))
1068 ;; (cond ((memq name '(=daikanwa
1069 ;; =daikanwa-rev1 =daikanwa-rev2
1070 ;; =gt =gt-k =cbeta))
1071 ;; (if has-long-ccs-name
1072 ;; "(%-26s . %05d)\t; %c%s"
1073 ;; "(%-18s . %05d)\t; %c%s"))
1074 ;; ((eq name 'mojikyo)
1075 ;; (if has-long-ccs-name
1076 ;; "(%-26s . %06d)\t; %c%s"
1077 ;; "(%-18s . %06d)\t; %c%s"))
1078 ;; ((>= (charset-dimension name) 2)
1079 ;; (if has-long-ccs-name
1080 ;; "(%-26s . #x%04X)\t; %c%s"
1081 ;; "(%-18s . #x%04X)\t; %c%s"))
1083 ;; (if has-long-ccs-name
1084 ;; "(%-26s . #x%02X)\t; %c%s"
1085 ;; "(%-18s . #x%02X)\t; %c%s")))
1087 ;; (if (= (charset-iso-graphic-plane name) 1)
1089 ;; (cond ((= (charset-dimension name) 1)
1091 ;; ((= (charset-dimension name) 2)
1093 ;; ((= (charset-dimension name) 3)
1097 ;; (char-db-decode-isolated-char name value)
1099 ;; (setq ccs-attributes (cdr ccs-attributes)))
1102 (defun insert-char-data (char &optional readable
1105 (narrow-to-region (point)(point))
1106 (insert "(define-char
1108 (insert-char-attributes char readable attributes)
1110 (goto-char (point-min))
1111 (while (re-search-forward "[ \t]+$" nil t)
1114 (goto-char (point-min))
1115 (while (re-search-forward "[ \t][ \t][ \t]*" nil t)
1116 (let ((column (current-column))
1117 (indent-tabs-mode t))
1118 (delete-region (match-beginning 0) (point))
1119 (indent-to column)))
1120 (goto-char (point-max))
1121 ;; (tabify (point-min)(point-max))
1124 (defun insert-char-data-with-variant (char &optional printable
1126 script excluded-script)
1127 (insert-char-data char printable)
1128 (let ((variants (or (char-variants char)
1129 (let ((ucs (get-char-attribute char '->ucs)))
1131 (delete char (char-variants (int-char ucs)))))))
1133 (setq variants (sort variants #'<))
1135 (setq variant (car variants))
1136 (if (and (or (null script)
1137 (null (setq vs (get-char-attribute variant 'script)))
1139 (or (null excluded-script)
1140 (null (setq vs (get-char-attribute variant 'script)))
1141 (not (memq excluded-script vs))))
1142 (or (and no-ucs-unified (get-char-attribute variant '=ucs))
1143 (insert-char-data variant printable)))
1144 (setq variants (cdr variants))
1147 (defun insert-char-range-data (min max &optional script excluded-script)
1150 (while (<= code max)
1151 (setq char (decode-char '=ucs code))
1152 (if (encode-char char '=ucs 'defined-only)
1153 (insert-char-data-with-variant char nil 'no-ucs-unified
1154 script excluded-script))
1155 (setq code (1+ code)))))
1157 (defun write-char-range-data-to-file (min max file
1158 &optional script excluded-script)
1159 (let ((coding-system-for-write 'utf-8-mcs))
1161 (insert ";; -*- coding: utf-8-mcs -*-\n")
1162 (insert-char-range-data min max script excluded-script)
1163 (write-region (point-min)(point-max) file))))
1165 (defvar what-character-original-window-configuration)
1168 (defun what-char-definition (char)
1169 (interactive (list (char-after)))
1170 (let ((buf (get-buffer-create "*Character Description*"))
1171 (the-buf (current-buffer))
1172 (win-conf (current-window-configuration)))
1174 (make-local-variable 'what-character-original-window-configuration)
1175 (setq what-character-original-window-configuration win-conf)
1176 (setq buffer-read-only nil)
1180 (insert-char-data-with-variant char 'printable)
1181 (unless (char-attribute-alist char)
1182 (insert (format ";; = %c\n"
1183 (let* ((rest (split-char char))
1187 (setq code (logior (lsh code 8)
1189 (decode-char ccs code)))))
1190 ;; (char-db-update-comment)
1191 (set-buffer-modified-p nil)
1192 (view-mode the-buf (lambda (buf)
1193 (set-window-configuration
1194 what-character-original-window-configuration)
1196 (goto-char (point-min)))
1198 (set-window-configuration
1199 what-character-original-window-configuration)
1200 (signal (car err) (cdr err)))))))
1202 (provide 'char-db-util)
1204 ;;; char-db-util.el ends here