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-file-coding-system 'utf-8-mcs-er)
74 (defvar char-db-feature-domains
75 '(ucs daikanwa cns gt jis jis/alt jis/a jis/b
76 jis-x0213 cdp shinjigen misc unknown))
78 (defvar char-db-ignored-attributes nil)
80 (defun char-attribute-name< (ka kb)
82 ((eq '->denotational kb)
84 ((eq '->subsumptive kb)
85 (not (eq '->denotational ka)))
86 ((eq '->denotational ka)
88 ((eq '->subsumptive ka)
92 (if (<= (charset-id ka) 1)
93 (if (<= (charset-id kb) 1)
95 ((= (charset-dimension ka)
96 (charset-dimension kb))
97 (> (charset-id ka)(charset-id kb)))
99 (> (charset-dimension ka)
100 (charset-dimension kb))
103 (if (<= (charset-id kb) 1)
105 (< (charset-id ka)(charset-id kb))))
111 (string< (symbol-name ka)
117 (defvar char-db-coded-charset-priority-list
132 japanese-jisx0208-1978
173 (defun char-db-make-char-spec (char)
175 (cond ((characterp char)
176 (cond ((and (setq ret (encode-char char '=ucs 'defined-only))
177 (not (and (<= #xE000 ret)(<= ret #xF8FF))))
178 (setq char-spec (list (cons '=ucs ret)))
179 (cond ((setq ret (get-char-attribute char 'name))
180 (setq char-spec (cons (cons 'name ret) char-spec))
182 ((setq ret (get-char-attribute char 'name*))
183 (setq char-spec (cons (cons 'name* ret) char-spec))
188 (let ((rest char-db-coded-charset-priority-list)
191 (setq ccs (charset-name
192 (find-charset (car rest))))
194 (encode-char char ccs
196 (throw 'tag (cons ccs ret)))
197 (setq rest (cdr rest))))))
198 (setq char-spec (list ret))
199 (dolist (ccs (delq (car ret) (charset-list)))
200 (if (and (or (charset-iso-final-char ccs)
206 (setq ret (encode-char char ccs 'defined-only)))
207 (setq char-spec (cons (cons ccs ret) char-spec))))
209 (setq char-spec (split-char char)))
210 (cond ((setq ret (get-char-attribute char 'name))
211 (setq char-spec (cons (cons 'name ret) char-spec))
213 ((setq ret (get-char-attribute char 'name*))
214 (setq char-spec (cons (cons 'name* ret) char-spec))
221 (defun char-db-insert-char-spec (char &optional readable column
224 (setq column (current-column)))
225 (let (char-spec temp-char)
226 (setq char-spec (char-db-make-char-spec char))
227 (unless (or (characterp char) ; char
229 (setq char (find-char char-spec))
231 ;; define temporary character
232 ;; Current implementation is dirty.
233 (setq temp-char (define-char (cons '(ideograph-daikanwa . 0)
235 (remove-char-attribute temp-char 'ideograph-daikanwa)
236 (setq char temp-char))
237 (insert-char-attributes char
239 (union (mapcar #'car char-spec)
242 ;; undefine temporary character
243 ;; Current implementation is dirty.
244 (setq char-spec (char-attribute-alist temp-char))
246 (remove-char-attribute temp-char (car (car char-spec)))
247 (setq char-spec (cdr char-spec))))))
249 (defun char-db-insert-alist (alist &optional readable column)
251 (setq column (current-column)))
253 (concat "\n" (make-string (1+ column) ?\ )))
257 lbs cell rest separator)
260 (setq name (car (car alist))
261 value (cdr (car alist)))
262 (cond ((eq name 'char)
264 (if (setq ret (condition-case nil
272 (setq key (car (car value)))
273 ;; (if (find-charset key)
274 ;; (setq cal (cons key cal))
275 (setq al (cons key al))
277 (setq value (cdr value)))
278 (insert-char-attributes ret
282 (insert (prin1-to-string value)))
284 (insert line-breaking))
286 (insert (format "(%-18s " name))
287 (setq lbs (concat "\n" (make-string (current-column) ?\ )))
289 (setq cell (car value))
290 (if (and (consp cell)
292 (setq ret (condition-case nil
302 (setq key (car (car rest)))
303 ;; (if (find-charset key)
304 ;; (setq cal (cons key cal))
305 (setq al (cons key al))
307 (setq rest (cdr rest)))
310 (insert-char-attributes ret
314 (setq separator lbs))
317 (insert (prin1-to-string cell))
318 (setq separator " "))
319 (setq value (cdr value)))
321 (insert line-breaking))
323 (insert (format "(%-18s . %S)%s"
326 (setq alist (cdr alist))))
329 (defun char-db-insert-char-reference (plist &optional readable column)
331 (setq column (current-column)))
333 (concat "\n" (make-string (1+ column) ?\ )))
338 (setq name (pop plist))
339 (setq value (pop plist))
340 (cond ((eq name :char)
343 (cond ((numberp value)
344 (setq value (decode-char '=ucs value)))
346 ;; (setq value (or (find-char value)
349 (char-db-insert-char-spec value readable)
350 (insert line-breaking)
353 (insert (format "%s%s\t%d ; %c%s"
356 (aref ideographic-radicals value)
360 (insert (format "%s%s\t%S" separator name value))
361 (setq separator line-breaking)))
365 (defun char-db-decode-isolated-char (ccs code-point)
368 (cond ((eq ccs 'arabic-iso8859-6)
369 (decode-char ccs code-point))
370 ((and (memq ccs '(=gt-pj-1
381 (setq ret (decode-char ccs code-point))
382 (setq ret (encode-char ret '=gt 'defined-only)))
383 (decode-builtin-char '=gt ret))
385 (decode-builtin-char ccs code-point))))
386 (cond ((and (<= 0 (char-int ret))
387 (<= (char-int ret) #x1F))
388 (decode-char '=ucs (+ #x2400 (char-int ret))))
389 ((= (char-int ret) #x7F)
393 (defvar char-db-convert-obsolete-format t)
395 (defun char-db-insert-ccs-feature (name value line-breaking)
398 (cond ((memq name '(=daikanwa
399 =daikanwa-rev1 =daikanwa-rev2
401 "(%-18s . %05d)\t; %c")
403 "(%-18s . %06d)\t; %c")
404 ((>= (charset-dimension name) 2)
405 "(%-18s . #x%04X)\t; %c")
407 "(%-18s . #x%02X)\t; %c"))
409 (if (= (charset-iso-graphic-plane name) 1)
411 (cond ((= (charset-dimension name) 1)
413 ((= (charset-dimension name) 2)
415 ((= (charset-dimension name) 3)
419 (char-db-decode-isolated-char name value)))
420 (if (and (= (charset-chars name) 94)
421 (= (charset-dimension name) 2))
422 (insert (format " [%02d-%02d]"
423 (- (lsh value -8) 32)
424 (- (logand value 255) 32))))
425 (insert line-breaking))
427 (defun insert-char-attributes (char &optional readable attributes column)
429 (setq column (current-column)))
430 (let (name value ; has-long-ccs-name
434 (concat "\n" (make-string (1+ column) ?\ )))
435 lbs cell separator ret
438 sources required-features
443 (if (consp attributes)
445 (dolist (name attributes)
446 (unless (memq name char-db-ignored-attributes)
447 (if (find-charset name)
451 (dolist (name (char-attribute-list))
452 (unless (memq name char-db-ignored-attributes)
453 (if (find-charset name)
457 #'char-attribute-name<)))
459 (when (and (memq 'name attributes)
460 (setq value (get-char-attribute char 'name)))
462 (if (> (+ (current-column) (length value)) 48)
465 value line-breaking))
466 (setq attributes (delq 'name attributes))
468 (when (and (memq 'name* attributes)
469 (setq value (get-char-attribute char 'name*)))
471 (if (> (+ (current-column) (length value)) 48)
474 value line-breaking))
475 (setq attributes (delq 'name* attributes))
477 (when (and (memq 'script attributes)
478 (setq value (get-char-attribute char 'script)))
479 (insert (format "(script\t\t%s)%s"
480 (mapconcat (function prin1-to-string)
483 (setq attributes (delq 'script attributes))
485 ;; (when (and (memq '<-denotational attributes)
486 ;; (setq value (get-char-attribute char '<-denotational))
487 ;; (null (cdr value))
488 ;; (setq value (encode-char (car value) 'ucs 'defined-only)))
489 ;; (insert (format "(%-18s . #x%04X)\t; %c%s"
490 ;; '=>ucs value (decode-char 'ucs value)
492 ;; (setq attributes (delq '<-denotational attributes)))
493 (dolist (name '(=>ucs =>ucs*))
494 (when (and (memq name attributes)
495 (setq value (get-char-attribute char name)))
496 (insert (format "(%-18s . #x%04X)\t; %c%s"
497 name value (decode-char '=ucs value)
499 (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"
508 (symbol-name name) 2)))
511 (setq attributes (delq name attributes))
513 ;; (dolist (name '(=>ucs-gb =>ucs-cns =>ucs-jis =>ucs-ks =>ucs-big5))
514 ;; (when (and (memq name attributes)
515 ;; (setq value (get-char-attribute char name)))
516 ;; (insert (format "(%-18s . #x%04X)\t; %c%s"
519 ;; (substring (symbol-name name) 6)))
521 ;; (decode-char (intern
524 ;; (symbol-name name) 6)))
527 ;; (setq attributes (delq name attributes))))
528 ;; (when (and (memq '->ucs attributes)
529 ;; (setq value (get-char-attribute char '->ucs)))
530 ;; (insert (format (if char-db-convert-obsolete-format
531 ;; "(=>ucs\t\t. #x%04X)\t; %c%s"
532 ;; "(->ucs\t\t. #x%04X)\t; %c%s")
533 ;; value (decode-char '=ucs value)
535 ;; (setq attributes (delq '->ucs attributes))
537 (dolist (name '(=>daikanwa))
538 (when (and (memq name attributes)
539 (setq value (get-char-attribute char name)))
542 (format "(%-18s . %05d)\t; %c%s"
543 name value (decode-char '=daikanwa value)
545 (format "(%-18s %s)\t; %c%s"
547 (mapconcat (function prin1-to-string)
549 (char-representative-of-daikanwa char)
551 (setq attributes (delq name attributes))))
552 (when (and (memq 'general-category attributes)
553 (setq value (get-char-attribute char 'general-category)))
555 "(general-category\t%s) ; %s%s"
556 (mapconcat (lambda (cell)
559 (cond ((rassoc value unidata-normative-category-alist)
560 "Normative Category")
561 ((rassoc value unidata-informative-category-alist)
562 "Informative Category")
566 (setq attributes (delq 'general-category attributes))
568 (when (and (memq 'bidi-category attributes)
569 (setq value (get-char-attribute char 'bidi-category)))
570 (insert (format "(bidi-category\t. %S)%s"
573 (setq attributes (delq 'bidi-category attributes))
575 (unless (or (not (memq 'mirrored attributes))
576 (eq (setq value (get-char-attribute char 'mirrored 'empty))
578 (insert (format "(mirrored\t\t. %S)%s"
581 (setq attributes (delq 'mirrored attributes))
584 ((and (memq 'decimal-digit-value attributes)
585 (setq value (get-char-attribute char 'decimal-digit-value)))
586 (insert (format "(decimal-digit-value . %S)%s"
589 (setq attributes (delq 'decimal-digit-value attributes))
590 (when (and (memq 'digit-value attributes)
591 (setq value (get-char-attribute char 'digit-value)))
592 (insert (format "(digit-value\t . %S)%s"
595 (setq attributes (delq 'digit-value attributes))
597 (when (and (memq 'numeric-value attributes)
598 (setq value (get-char-attribute char 'numeric-value)))
599 (insert (format "(numeric-value\t . %S)%s"
602 (setq attributes (delq 'numeric-value attributes))
606 (when (and (memq 'digit-value attributes)
607 (setq value (get-char-attribute char 'digit-value)))
608 (insert (format "(digit-value\t. %S)%s"
611 (setq attributes (delq 'digit-value attributes))
613 (when (and (memq 'numeric-value attributes)
614 (setq value (get-char-attribute char 'numeric-value)))
615 (insert (format "(numeric-value\t. %S)%s"
618 (setq attributes (delq 'numeric-value attributes))
620 (when (and (memq 'iso-10646-comment attributes)
621 (setq value (get-char-attribute char 'iso-10646-comment)))
622 (insert (format "(iso-10646-comment\t. %S)%s"
625 (setq attributes (delq 'iso-10646-comment attributes))
627 (when (and (memq 'morohashi-daikanwa attributes)
628 (setq value (get-char-attribute char 'morohashi-daikanwa)))
629 (insert (format "(morohashi-daikanwa\t%s)%s"
630 (mapconcat (function prin1-to-string) value " ")
632 (setq attributes (delq 'morohashi-daikanwa attributes))
636 (when (and (memq 'ideographic-radical attributes)
637 (setq value (get-char-attribute char 'ideographic-radical)))
639 (insert (format "(ideographic-radical . %S)\t; %c%s"
641 (aref ideographic-radicals radical)
643 (setq attributes (delq 'ideographic-radical attributes))
646 (dolist (domain char-db-feature-domains)
647 (setq key (intern (format "%s@%s" 'ideographic-radical domain)))
648 (when (and (memq key attributes)
649 (setq value (get-char-attribute char key)))
651 (insert (format "(%s . %S)\t; %c%s"
654 (aref ideographic-radicals radical)
656 (setq attributes (delq key attributes))
658 (setq key (intern (format "%s@%s" 'ideographic-strokes domain)))
659 (when (and (memq key attributes)
660 (setq value (get-char-attribute char key)))
662 (insert (format "(%s . %S)%s"
666 (setq attributes (delq key attributes))
668 (setq key (intern (format "%s@%s" 'total-strokes domain)))
669 (when (and (memq key attributes)
670 (setq value (get-char-attribute char key)))
671 (insert (format "(%s . %S)%s"
675 (setq attributes (delq key attributes))
677 (dolist (feature '(ideographic-radical
680 (setq key (intern (format "%s@%s*sources" feature domain)))
681 (when (and (memq key attributes)
682 (setq value (get-char-attribute char key)))
683 (insert (format "(%s%s" key line-breaking))
685 (insert (format " %s" cell)))
687 (insert line-breaking)
688 (setq attributes (delq key attributes))
691 (when (and (memq 'ideographic-strokes attributes)
692 (setq value (get-char-attribute char 'ideographic-strokes)))
694 (insert (format "(ideographic-strokes . %S)%s"
697 (setq attributes (delq 'ideographic-strokes attributes))
699 (when (and (memq 'kangxi-radical attributes)
700 (setq value (get-char-attribute char 'kangxi-radical)))
701 (unless (eq value radical)
702 (insert (format "(kangxi-radical\t . %S)\t; %c%s"
704 (aref ideographic-radicals value)
707 (setq radical value)))
708 (setq attributes (delq 'kangxi-radical attributes))
710 (when (and (memq 'kangxi-strokes attributes)
711 (setq value (get-char-attribute char 'kangxi-strokes)))
712 (unless (eq value strokes)
713 (insert (format "(kangxi-strokes\t . %S)%s"
717 (setq strokes value)))
718 (setq attributes (delq 'kangxi-strokes attributes))
720 (when (and (memq 'japanese-radical attributes)
721 (setq value (get-char-attribute char 'japanese-radical)))
722 (unless (eq value radical)
723 (insert (format "(japanese-radical\t . %S)\t; %c%s"
725 (aref ideographic-radicals value)
728 (setq radical value)))
729 (setq attributes (delq 'japanese-radical attributes))
731 (when (and (memq 'japanese-strokes attributes)
732 (setq value (get-char-attribute char 'japanese-strokes)))
733 (unless (eq value strokes)
734 (insert (format "(japanese-strokes\t . %S)%s"
738 (setq strokes value)))
739 (setq attributes (delq 'japanese-strokes attributes))
741 (when (and (memq 'cns-radical attributes)
742 (setq value (get-char-attribute char 'cns-radical)))
743 (insert (format "(cns-radical\t . %S)\t; %c%s"
745 (aref ideographic-radicals value)
747 (setq attributes (delq 'cns-radical attributes))
749 (when (and (memq 'cns-strokes attributes)
750 (setq value (get-char-attribute char 'cns-strokes)))
751 (unless (eq value strokes)
752 (insert (format "(cns-strokes\t . %S)%s"
756 (setq strokes value)))
757 (setq attributes (delq 'cns-strokes attributes))
759 (when (and (memq 'shinjigen-1-radical attributes)
760 (setq value (get-char-attribute char 'shinjigen-1-radical)))
761 (unless (eq value radical)
762 (insert (format "(shinjigen-1-radical . %S)\t; %c%s"
764 (aref ideographic-radicals value)
767 (setq radical value)))
768 (setq attributes (delq 'shinjigen-1-radical attributes))
770 (when (and (memq 'ideographic- attributes)
771 (setq value (get-char-attribute char 'ideographic-)))
772 (insert "(ideographic- ")
773 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
776 (setq cell (car value))
778 (setq cell (decode-char '=ucs cell)))
779 (cond ((characterp cell)
783 (insert (format "%S" cell))
784 (char-db-insert-char-spec cell readable))
785 (setq separator lbs))
789 (if (consp (car cell))
790 (char-db-insert-char-spec cell readable)
791 (char-db-insert-char-reference cell readable))
792 (setq separator lbs))
796 (insert (prin1-to-string cell))
797 (setq separator " ")))
798 (setq value (cdr value)))
800 (insert line-breaking)
801 (setq attributes (delq 'ideographic- attributes)))
802 (when (and (memq 'total-strokes attributes)
803 (setq value (get-char-attribute char 'total-strokes)))
804 (insert (format "(total-strokes . %S)%s"
807 (setq attributes (delq 'total-strokes attributes))
809 (when (and (memq '->ideograph attributes)
810 (setq value (get-char-attribute char '->ideograph)))
811 (insert (format "(->ideograph\t%s)%s"
812 (mapconcat (lambda (code)
813 (cond ((symbolp code)
816 (format "#x%04X" code))
819 line-breaking code))))
822 (setq attributes (delq '->ideograph attributes))
824 (when (and (memq '->decomposition attributes)
825 (setq value (get-char-attribute char '->decomposition)))
826 (insert (format "(->decomposition\t%s)%s"
827 (mapconcat (lambda (code)
828 (cond ((symbolp code)
837 (format "#x%04X" code))
839 (format "%s%S" line-breaking code))))
842 (setq attributes (delq '->decomposition attributes))
844 (if (equal (get-char-attribute char '->titlecase)
845 (get-char-attribute char '->uppercase))
846 (setq attributes (delq '->titlecase attributes)))
847 (when (and (memq '->mojikyo attributes)
848 (setq value (get-char-attribute char '->mojikyo)))
849 (insert (format "(->mojikyo\t\t. %06d)\t; %c%s"
850 value (decode-char 'mojikyo value)
852 (setq attributes (delq '->mojikyo attributes))
854 (when (and (memq 'hanyu-dazidian-vol attributes)
855 (setq value (get-char-attribute char 'hanyu-dazidian-vol)))
856 (insert (format "(hanyu-dazidian-vol . %d)%s"
857 value line-breaking))
858 (setq attributes (delq 'hanyu-dazidian-vol attributes))
860 (when (and (memq 'hanyu-dazidian-page attributes)
861 (setq value (get-char-attribute char 'hanyu-dazidian-page)))
862 (insert (format "(hanyu-dazidian-page . %d)%s"
863 value line-breaking))
864 (setq attributes (delq 'hanyu-dazidian-page attributes))
866 (when (and (memq 'hanyu-dazidian-char attributes)
867 (setq value (get-char-attribute char 'hanyu-dazidian-char)))
868 (insert (format "(hanyu-dazidian-char . %d)%s"
869 value line-breaking))
870 (setq attributes (delq 'hanyu-dazidian-char attributes))
873 (dolist (ignored '(composition
874 ->denotational <-subsumptive ->ucs-unified
875 ->ideographic-component-forms
877 (setq attributes (delq ignored attributes))))
878 ;; (setq rest ccs-attributes)
881 ;; (setq value (get-char-attribute char (car rest)))
883 ;; (if (>= (length (symbol-name (car rest))) 19)
885 ;; (setq has-long-ccs-name t)
889 ;; (setq rest (cdr rest)))
891 (setq name (car attributes))
892 (if (setq value (get-char-attribute char name))
893 (cond ((setq ret (find-charset name))
894 (setq name (charset-name ret))
895 (if (and (not (memq name dest-ccss))
897 (setq value (get-char-attribute char name))
898 (setq dest-ccss (cons name dest-ccss))))
899 (char-db-insert-ccs-feature name value line-breaking)
902 ;; (cond ((memq name '(=daikanwa
903 ;; =daikanwa-rev1 =daikanwa-rev2
904 ;; =gt =gt-k =cbeta))
905 ;; (if has-long-ccs-name
906 ;; "(%-26s . %05d)\t; %c%s"
907 ;; "(%-18s . %05d)\t; %c%s"))
908 ;; ((eq name 'mojikyo)
909 ;; (if has-long-ccs-name
910 ;; "(%-26s . %06d)\t; %c%s"
911 ;; "(%-18s . %06d)\t; %c%s"))
912 ;; ((>= (charset-dimension name) 2)
913 ;; (if has-long-ccs-name
914 ;; "(%-26s . #x%04X)\t; %c%s"
915 ;; "(%-18s . #x%04X)\t; %c%s"))
917 ;; (if has-long-ccs-name
918 ;; "(%-26s . #x%02X)\t; %c%s"
919 ;; "(%-18s . #x%02X)\t; %c%s")))
921 ;; (if (= (charset-iso-graphic-plane name) 1)
923 ;; (cond ((= (charset-dimension name) 1)
925 ;; ((= (charset-dimension name) 2)
927 ;; ((= (charset-dimension name) 3)
931 ;; (char-db-decode-isolated-char name value)
935 ((string-match "^=>ucs@" (symbol-name name))
936 (insert (format "(%-18s . #x%04X)\t; %c%s"
937 name value (decode-char '=ucs value)
940 ((eq name 'jisx0208-1978/4X)
941 (insert (format "(%-18s . #x%04X)%s"
946 (null (get-char-attribute
948 (intern (format "%s*sources" name))))
949 (not (string-match "\\*sources$" (symbol-name name)))
950 (or (eq name '<-identical)
951 (string-match "^->simplified" (symbol-name name))
952 (string-match "^<-same" (symbol-name name))
953 (string-match "^->vulgar" (symbol-name name))
954 (string-match "^->wrong" (symbol-name name))
955 (string-match "^->original" (symbol-name name))
958 ((or (eq name 'ideographic-structure)
959 (eq name 'ideographic-)
960 (string-match "^\\(->\\|<-\\)" (symbol-name name)))
961 (insert (format "(%-18s%s " name line-breaking))
962 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
965 (setq cell (car value))
967 (setq cell (decode-char '=ucs cell)))
968 (cond ((eq name '->subsumptive)
971 (get-char-attribute cell atr))
972 char-db-ignored-attributes))
974 (encode-char cell ccs
979 (let ((char-db-ignored-attributes
981 char-db-ignored-attributes)))
982 (insert-char-attributes cell readable))
983 (setq separator lbs))
989 (intern (format "%s*sources" name))))
990 (setq required-features nil)
991 (dolist (source sources)
993 ((memq source '(JP JP/Jouyou
995 (setq required-features
996 (union required-features
1005 (setq required-features
1006 (union required-features
1012 (setq ret (intern (format "=%s" source))))
1013 (setq required-features
1014 (cons ret required-features)))
1015 (t (setq required-features
1016 (cons source required-features)))))
1017 (cond ((string-match "@JP" (symbol-name name))
1018 (setq required-features
1019 (union required-features
1027 ((string-match "@CN" (symbol-name name))
1028 (setq required-features
1029 (union required-features
1036 (insert (format "%S" cell))
1037 (char-db-insert-char-spec cell readable
1040 (setq separator lbs))
1044 (if (consp (car cell))
1045 (char-db-insert-char-spec cell readable)
1046 (char-db-insert-char-reference cell readable))
1047 (setq separator lbs))
1051 (insert (prin1-to-string cell))
1052 (setq separator " ")))
1053 (setq value (cdr value)))
1055 (insert line-breaking))
1056 ((memq name '(ideograph=
1057 original-ideograph-of
1058 ancient-ideograph-of
1061 ;; simplified-ideograph-of
1062 ideographic-variants
1063 ;; ideographic-different-form-of
1065 (insert (format "(%-18s%s " name line-breaking))
1066 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1068 (while (consp value)
1069 (setq cell (car value))
1070 (if (and (consp cell)
1075 (char-db-insert-alist cell readable)
1076 (setq separator lbs))
1079 (insert (prin1-to-string cell))
1080 (setq separator " "))
1081 (setq value (cdr value)))
1083 (insert line-breaking))
1085 (insert (format "(%-18s " name))
1086 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1088 (while (consp value)
1089 (setq cell (car value))
1090 (if (and (consp cell)
1092 (setq ret (condition-case nil
1100 (setq key (car (car rest)))
1101 (if (find-charset key)
1102 (setq cal (cons key cal))
1103 (setq al (cons key al)))
1104 (setq rest (cdr rest)))
1107 (insert-char-attributes ret
1110 (setq separator lbs))
1111 (setq ret (prin1-to-string cell))
1113 (if (< (+ (current-column)
1120 (setq separator " "))
1121 (setq value (cdr value)))
1123 (insert line-breaking))
1125 (insert (format "(%-18s . %S)%s"
1129 (setq attributes (cdr attributes)))
1130 ;; (while ccs-attributes
1131 ;; (setq name (charset-name (car ccs-attributes)))
1132 ;; (if (and (not (memq name dest-ccss))
1134 ;; (setq value (get-char-attribute char name))
1135 ;; (setq dest-ccss (cons name dest-ccss))))
1138 ;; (cond ((memq name '(=daikanwa
1139 ;; =daikanwa-rev1 =daikanwa-rev2
1140 ;; =gt =gt-k =cbeta))
1141 ;; (if has-long-ccs-name
1142 ;; "(%-26s . %05d)\t; %c%s"
1143 ;; "(%-18s . %05d)\t; %c%s"))
1144 ;; ((eq name 'mojikyo)
1145 ;; (if has-long-ccs-name
1146 ;; "(%-26s . %06d)\t; %c%s"
1147 ;; "(%-18s . %06d)\t; %c%s"))
1148 ;; ((>= (charset-dimension name) 2)
1149 ;; (if has-long-ccs-name
1150 ;; "(%-26s . #x%04X)\t; %c%s"
1151 ;; "(%-18s . #x%04X)\t; %c%s"))
1153 ;; (if has-long-ccs-name
1154 ;; "(%-26s . #x%02X)\t; %c%s"
1155 ;; "(%-18s . #x%02X)\t; %c%s")))
1157 ;; (if (= (charset-iso-graphic-plane name) 1)
1159 ;; (cond ((= (charset-dimension name) 1)
1161 ;; ((= (charset-dimension name) 2)
1163 ;; ((= (charset-dimension name) 3)
1167 ;; (char-db-decode-isolated-char name value)
1169 ;; (setq ccs-attributes (cdr ccs-attributes)))
1172 (defun insert-char-data (char &optional readable
1175 (narrow-to-region (point)(point))
1176 (insert "(define-char
1178 (insert-char-attributes char readable attributes)
1180 (goto-char (point-min))
1181 (while (re-search-forward "[ \t]+$" nil t)
1184 (goto-char (point-min))
1185 (while (re-search-forward "[ \t][ \t][ \t]*" nil t)
1186 (let ((column (current-column))
1187 (indent-tabs-mode t))
1188 (delete-region (match-beginning 0) (point))
1189 (indent-to column)))
1190 (goto-char (point-max))
1191 ;; (tabify (point-min)(point-max))
1194 (defun insert-char-data-with-variant (char &optional printable
1196 script excluded-script)
1197 (insert-char-data char printable)
1198 (let ((variants (or (char-variants char)
1199 (let ((ucs (get-char-attribute char '->ucs)))
1201 (delete char (char-variants (int-char ucs)))))))
1203 (setq variants (sort variants #'<))
1205 (setq variant (car variants))
1206 (if (and (or (null script)
1207 (null (setq vs (get-char-attribute variant 'script)))
1209 (or (null excluded-script)
1210 (null (setq vs (get-char-attribute variant 'script)))
1211 (not (memq excluded-script vs))))
1212 (or (and no-ucs-unified (get-char-attribute variant '=ucs))
1213 (insert-char-data variant printable)))
1214 (setq variants (cdr variants))
1217 (defun insert-char-range-data (min max &optional script excluded-script)
1220 (while (<= code max)
1221 (setq char (decode-char '=ucs code))
1222 (if (encode-char char '=ucs 'defined-only)
1223 (insert-char-data-with-variant char nil 'no-ucs-unified
1224 script excluded-script))
1225 (setq code (1+ code)))))
1227 (defun write-char-range-data-to-file (min max file
1228 &optional script excluded-script)
1229 (let ((coding-system-for-write char-db-file-coding-system))
1231 (insert (format ";; -*- coding: %s -*-\n"
1232 char-db-file-coding-system))
1233 (insert-char-range-data min max script excluded-script)
1234 (write-region (point-min)(point-max) file))))
1236 (defvar what-character-original-window-configuration)
1239 (defun what-char-definition (char)
1240 (interactive (list (char-after)))
1241 (let ((buf (get-buffer-create "*Character Description*"))
1242 (the-buf (current-buffer))
1243 (win-conf (current-window-configuration)))
1245 (make-local-variable 'what-character-original-window-configuration)
1246 (setq what-character-original-window-configuration win-conf)
1247 (setq buffer-read-only nil)
1251 (insert-char-data-with-variant char 'printable)
1252 (unless (char-attribute-alist char)
1253 (insert (format ";; = %c\n"
1254 (let* ((rest (split-char char))
1258 (setq code (logior (lsh code 8)
1260 (decode-char ccs code)))))
1261 ;; (char-db-update-comment)
1262 (set-buffer-modified-p nil)
1263 (view-mode the-buf (lambda (buf)
1264 (set-window-configuration
1265 what-character-original-window-configuration)
1267 (goto-char (point-min)))
1269 (set-window-configuration
1270 what-character-original-window-configuration)
1271 (signal (car err) (cdr err)))))))
1273 (provide 'char-db-util)
1275 ;;; char-db-util.el ends here