1 ;;; char-db-util.el --- Character Database utility -*- coding: utf-8-er; -*-
3 ;; Copyright (C) 1998,1999,2000,2001,2002,2003,2004,2005 MORIOKA Tomohiko.
5 ;; Author: MORIOKA Tomohiko <tomo@kanji.zinbun.kyoto-u.ac.jp>
6 ;; Keywords: CHISE, Character Database, ISO/IEC 10646, UCS, Unicode, 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 (defun ideographic-radical (number)
73 (aref ideographic-radicals number))
75 (defconst shuowen-radicals
76 [?一 ?上 ?示 ?三 ?王 ?玉 ?玨 ?气 ?士 ?丨
77 ?屮 ?艸 ?茻 ?小 ?八 ?釆 ?牛 ?告 ?口])
79 (defun shuowen-radical (number)
80 (aref shuowen-radicals (1- number)))
82 (defvar char-db-file-coding-system 'utf-8-mcs-er)
84 (defvar char-db-feature-domains
85 '(ucs daikanwa cns gt jis jis/alt jis/a jis/b
86 jis-x0212 jis-x0213 cdp shinjigen misc unknown))
88 (defvar char-db-ignored-attributes '(ideographic-products))
90 (defun char-attribute-name< (ka kb)
92 ((eq '->denotational kb)
94 ((eq '->subsumptive kb)
95 (not (eq '->denotational ka)))
96 ((eq '->denotational ka)
98 ((eq '->subsumptive ka)
101 (string-match "^->" (symbol-name ka)))
102 (cond ((and (symbolp kb)
103 (string-match "^->" (symbol-name kb)))
104 (string< (symbol-name ka)
109 (string-match "^->" (symbol-name kb)))
112 (string-match "^<-" (symbol-name ka)))
114 (cond ((string-match "^<-" (symbol-name kb))
115 (string< (symbol-name ka)
118 ;; ((string-match "^->" (symbol-name kb))
123 (string-match "^<-" (symbol-name kb)))
125 ;; (not (string-match "^->" (symbol-name ka)))
128 (if (find-charset kb)
129 (if (<= (charset-id ka) 1)
130 (if (<= (charset-id kb) 1)
132 ((= (charset-dimension ka)
133 (charset-dimension kb))
134 (> (charset-id ka)(charset-id kb)))
136 (> (charset-dimension ka)
137 (charset-dimension kb))
140 (if (<= (charset-id kb) 1)
142 (< (charset-id ka)(charset-id kb))))
148 (string< (symbol-name ka)
154 (defvar char-db-coded-charset-priority-list
215 (defun char-db-make-char-spec (char)
217 (cond ((characterp char)
218 (cond ((and (setq ret (encode-char char '=ucs 'defined-only))
219 (not (and (<= #xE000 ret)(<= ret #xF8FF))))
220 (setq char-spec (list (cons '=ucs ret)))
221 (cond ((setq ret (get-char-attribute char 'name))
222 (setq char-spec (cons (cons 'name ret) char-spec))
224 ((setq ret (get-char-attribute char 'name*))
225 (setq char-spec (cons (cons 'name* ret) char-spec))
230 (let ((rest char-db-coded-charset-priority-list)
233 (setq ccs (charset-name
234 (find-charset (car rest))))
236 (encode-char char ccs
238 (throw 'tag (cons ccs ret)))
239 (setq rest (cdr rest))))))
240 (setq char-spec (list ret))
241 (dolist (ccs (delq (car ret) (charset-list)))
242 (if (and (or (charset-iso-final-char ccs)
249 (setq ccs (charset-name ccs))
250 (null (assq ccs char-spec))
251 (setq ret (encode-char char ccs 'defined-only)))
252 (setq char-spec (cons (cons ccs ret) char-spec))))
254 (setq char-spec (split-char char)))
255 (cond ((setq ret (get-char-attribute char 'name))
256 (setq char-spec (cons (cons 'name ret) char-spec))
258 ((setq ret (get-char-attribute char 'name*))
259 (setq char-spec (cons (cons 'name* ret) char-spec))
266 (defun char-db-insert-char-spec (char &optional readable column
269 (setq column (current-column)))
270 (let (char-spec temp-char)
271 (setq char-spec (char-db-make-char-spec char))
272 (unless (or (characterp char) ; char
274 (setq char (find-char char-spec))
276 ;; define temporary character
277 ;; Current implementation is dirty.
278 (setq temp-char (define-char (cons '(ideograph-daikanwa . 0)
280 (remove-char-attribute temp-char 'ideograph-daikanwa)
281 (setq char temp-char))
282 (insert-char-attributes char
284 (union (mapcar #'car char-spec)
287 ;; undefine temporary character
288 ;; Current implementation is dirty.
289 (setq char-spec (char-attribute-alist temp-char))
291 (remove-char-attribute temp-char (car (car char-spec)))
292 (setq char-spec (cdr char-spec))))))
294 (defun char-db-insert-alist (alist &optional readable column)
296 (setq column (current-column)))
298 (concat "\n" (make-string (1+ column) ?\ )))
302 lbs cell rest separator)
305 (setq name (car (car alist))
306 value (cdr (car alist)))
307 (cond ((eq name 'char)
309 (if (setq ret (condition-case nil
317 (setq key (car (car value)))
318 ;; (if (find-charset key)
319 ;; (setq cal (cons key cal))
320 (setq al (cons key al))
322 (setq value (cdr value)))
323 (insert-char-attributes ret
327 (insert (prin1-to-string value)))
329 (insert line-breaking))
331 (insert (format "(%-18s " name))
332 (setq lbs (concat "\n" (make-string (current-column) ?\ )))
334 (setq cell (car value))
335 (if (and (consp cell)
337 (setq ret (condition-case nil
347 (setq key (car (car rest)))
348 ;; (if (find-charset key)
349 ;; (setq cal (cons key cal))
350 (setq al (cons key al))
352 (setq rest (cdr rest)))
355 (insert-char-attributes ret
359 (setq separator lbs))
362 (insert (prin1-to-string cell))
363 (setq separator " "))
364 (setq value (cdr value)))
366 (insert line-breaking))
368 (insert (format "(%-18s . %S)%s"
371 (setq alist (cdr alist))))
374 (defun char-db-insert-char-reference (plist &optional readable column)
376 (setq column (current-column)))
378 (concat "\n" (make-string (1+ column) ?\ )))
383 (setq name (pop plist))
384 (setq value (pop plist))
385 (cond ((eq name :char)
388 (cond ((numberp value)
389 (setq value (decode-char '=ucs value)))
391 ;; (setq value (or (find-char value)
394 (char-db-insert-char-spec value readable)
395 (insert line-breaking)
398 (insert (format "%s%s\t%d ; %c%s"
401 (ideographic-radical value)
405 (insert (format "%s%s\t%S" separator name value))
406 (setq separator line-breaking)))
410 (defun char-db-decode-isolated-char (ccs code-point)
413 (cond ((eq ccs 'arabic-iso8859-6)
414 (decode-char ccs code-point))
415 ((and (memq ccs '(=gt-pj-1
426 (setq ret (decode-char ccs code-point))
427 (setq ret (encode-char ret '=gt 'defined-only)))
428 (decode-builtin-char '=gt ret))
430 (decode-builtin-char ccs code-point))))
431 (cond ((and (<= 0 (char-int ret))
432 (<= (char-int ret) #x1F))
433 (decode-char '=ucs (+ #x2400 (char-int ret))))
434 ((= (char-int ret) #x7F)
438 (defvar char-db-convert-obsolete-format t)
440 (defun char-db-insert-ccs-feature (name value line-breaking)
443 (cond ((or (memq name '(=daikanwa
444 =daikanwa@rev1 =daikanwa@rev2
445 =gt =gt-k =cbeta =zinbun-oracle))
446 (string-match "^=adobe-" (symbol-name name)))
447 "(%-18s . %05d)\t; %c")
449 "(%-18s . %06d)\t; %c")
450 ((>= (charset-dimension name) 2)
451 "(%-18s . #x%04X)\t; %c")
453 "(%-18s . #x%02X)\t; %c"))
455 (if (= (charset-iso-graphic-plane name) 1)
457 (cond ((= (charset-dimension name) 1)
459 ((= (charset-dimension name) 2)
461 ((= (charset-dimension name) 3)
465 (char-db-decode-isolated-char name value)))
466 (if (and (= (charset-chars name) 94)
467 (= (charset-dimension name) 2))
468 (insert (format " [%02d-%02d]"
469 (- (lsh value -8) 32)
470 (- (logand value 255) 32))))
471 (insert line-breaking))
473 (defun char-db-insert-relation-feature (char name value line-breaking
475 (insert (format "(%-18s%s " name line-breaking))
476 (let ((lbs (concat "\n" (make-string (current-column) ?\ )))
477 separator cell sources required-features
480 (setq cell (car value))
482 (setq cell (decode-char '=ucs cell)))
484 ((eq name '->subsumptive)
485 (when (or (not (some (lambda (atr)
486 (get-char-attribute cell atr))
487 char-db-ignored-attributes))
489 (encode-char cell ccs 'defined-only))
493 (let ((char-db-ignored-attributes
495 char-db-ignored-attributes)))
496 (insert-char-attributes cell readable))
497 (setq separator lbs))
502 char (intern (format "%s*sources" name))))
503 (setq required-features nil)
504 (dolist (source sources)
506 ((memq source '(JP JP/Jouyou shinjigen-1))
507 (setq required-features
508 (union required-features
517 (setq required-features
518 (union required-features
523 ((find-charset (setq ret (intern (format "=%s" source))))
524 (setq required-features
525 (cons ret required-features)))
526 (t (setq required-features
527 (cons source required-features)))))
528 (cond ((string-match "@JP" (symbol-name name))
529 (setq required-features
530 (union required-features
538 ((string-match "@CN" (symbol-name name))
539 (setq required-features
540 (union required-features
547 (insert (format "%S" cell))
548 (char-db-insert-char-spec cell readable
551 (setq separator lbs))
555 (if (consp (car cell))
556 (char-db-insert-char-spec cell readable)
557 (char-db-insert-char-reference cell readable))
558 (setq separator lbs))
562 (insert (prin1-to-string cell))
563 (setq separator " ")))
564 (setq value (cdr value)))
566 (insert line-breaking)))
568 (defun insert-char-attributes (char &optional readable attributes column)
570 (setq column (current-column)))
571 (let (name value ; has-long-ccs-name
575 (concat "\n" (make-string (1+ column) ?\ )))
576 lbs cell separator ret
578 dest-ccss ; sources required-features
583 (if (consp attributes)
585 (dolist (name attributes)
586 (unless (memq name char-db-ignored-attributes)
587 (if (find-charset name)
591 (dolist (name (char-attribute-list))
592 (unless (memq name char-db-ignored-attributes)
593 (if (find-charset name)
597 #'char-attribute-name<)))
599 (when (memq '<-subsumptive attributes)
601 (when (setq value (get-char-attribute char '<-subsumptive))
602 (char-db-insert-relation-feature char '<-subsumptive value
605 (setq attributes (delq '<-subsumptive attributes)))
606 (when (and (memq '<-denotational attributes)
607 (setq value (get-char-attribute char '<-denotational)))
608 (char-db-insert-relation-feature char '<-denotational value
611 (setq attributes (delq '<-denotational attributes)))
612 (when (and (memq 'name attributes)
613 (setq value (get-char-attribute char 'name)))
615 (if (> (+ (current-column) (length value)) 48)
618 value line-breaking))
619 (setq attributes (delq 'name attributes))
621 (when (and (memq 'name* attributes)
622 (setq value (get-char-attribute char 'name*)))
624 (if (> (+ (current-column) (length value)) 48)
627 value line-breaking))
628 (setq attributes (delq 'name* attributes))
630 (when (and (memq 'script attributes)
631 (setq value (get-char-attribute char 'script)))
632 (insert (format "(script\t\t%s)%s"
633 (mapconcat (function prin1-to-string)
636 (setq attributes (delq 'script attributes))
638 (dolist (name '(=>ucs =>ucs*))
639 (when (and (memq name attributes)
640 (setq value (get-char-attribute char name)))
641 (insert (format "(%-18s . #x%04X)\t; %c%s"
642 name value (decode-char '=ucs value)
644 (setq attributes (delq name attributes))))
645 (dolist (name '(=>ucs@gb =>ucs@cns =>ucs@jis =>ucs@ks =>ucs@big5))
646 (when (and (memq name attributes)
647 (setq value (get-char-attribute char name)))
648 (insert (format "(%-18s . #x%04X)\t; %c%s"
653 (symbol-name name) 2)))
656 (setq attributes (delq name attributes))
658 (dolist (name '(=>daikanwa))
659 (when (and (memq name attributes)
660 (setq value (get-char-attribute char name)))
663 (format "(%-18s . %05d)\t; %c%s"
664 name value (decode-char '=daikanwa value)
666 (format "(%-18s %s)\t; %c%s"
668 (mapconcat (function prin1-to-string)
670 (char-representative-of-daikanwa char)
672 (setq attributes (delq name attributes))))
673 (when (and (memq 'general-category attributes)
674 (setq value (get-char-attribute char 'general-category)))
676 "(general-category\t%s) ; %s%s"
677 (mapconcat (lambda (cell)
680 (cond ((rassoc value unidata-normative-category-alist)
681 "Normative Category")
682 ((rassoc value unidata-informative-category-alist)
683 "Informative Category")
687 (setq attributes (delq 'general-category attributes))
689 (when (and (memq 'bidi-category attributes)
690 (setq value (get-char-attribute char 'bidi-category)))
691 (insert (format "(bidi-category\t. %S)%s"
694 (setq attributes (delq 'bidi-category attributes))
696 (unless (or (not (memq 'mirrored attributes))
697 (eq (setq value (get-char-attribute char 'mirrored 'empty))
699 (insert (format "(mirrored\t\t. %S)%s"
702 (setq attributes (delq 'mirrored attributes))
705 ((and (memq 'decimal-digit-value attributes)
706 (setq value (get-char-attribute char 'decimal-digit-value)))
707 (insert (format "(decimal-digit-value . %S)%s"
710 (setq attributes (delq 'decimal-digit-value attributes))
711 (when (and (memq 'digit-value attributes)
712 (setq value (get-char-attribute char 'digit-value)))
713 (insert (format "(digit-value\t . %S)%s"
716 (setq attributes (delq 'digit-value attributes))
718 (when (and (memq 'numeric-value attributes)
719 (setq value (get-char-attribute char 'numeric-value)))
720 (insert (format "(numeric-value\t . %S)%s"
723 (setq attributes (delq 'numeric-value attributes))
727 (when (and (memq 'digit-value attributes)
728 (setq value (get-char-attribute char 'digit-value)))
729 (insert (format "(digit-value\t. %S)%s"
732 (setq attributes (delq 'digit-value attributes))
734 (when (and (memq 'numeric-value attributes)
735 (setq value (get-char-attribute char 'numeric-value)))
736 (insert (format "(numeric-value\t. %S)%s"
739 (setq attributes (delq 'numeric-value attributes))
741 (when (and (memq 'iso-10646-comment attributes)
742 (setq value (get-char-attribute char 'iso-10646-comment)))
743 (insert (format "(iso-10646-comment\t. %S)%s"
746 (setq attributes (delq 'iso-10646-comment attributes))
748 (when (and (memq 'morohashi-daikanwa attributes)
749 (setq value (get-char-attribute char 'morohashi-daikanwa)))
750 (insert (format "(morohashi-daikanwa\t%s)%s"
751 (mapconcat (function prin1-to-string) value " ")
753 (setq attributes (delq 'morohashi-daikanwa attributes))
757 (when (and (memq 'ideographic-radical attributes)
758 (setq value (get-char-attribute char 'ideographic-radical)))
760 (insert (format "(ideographic-radical . %S)\t; %c%s"
762 (ideographic-radical radical)
764 (setq attributes (delq 'ideographic-radical attributes))
766 (when (and (memq 'shuowen-radical attributes)
767 (setq value (get-char-attribute char 'shuowen-radical)))
768 (insert (format "(shuowen-radical\t. %S)\t; %c%s"
770 (shuowen-radical value)
772 (setq attributes (delq 'shuowen-radical attributes))
777 char-db-feature-domains
779 (dolist (feature (char-attribute-list))
780 (setq feature (symbol-name feature))
782 "\\(radical\\|strokes\\)@\\([^@*]+\\)\\(\\*\\|$\\)"
784 (setq domain (intern (match-string 2 feature)))
785 (unless (memq domain dest)
786 (setq dest (cons domain dest)))))
787 (sort dest #'string<))))
788 (setq key (intern (format "%s@%s" 'ideographic-radical domain)))
789 (when (and (memq key attributes)
790 (setq value (get-char-attribute char key)))
792 (insert (format "(%s . %S)\t; %c%s"
795 (ideographic-radical radical)
797 (setq attributes (delq key attributes))
799 (setq key (intern (format "%s@%s" 'ideographic-strokes domain)))
800 (when (and (memq key attributes)
801 (setq value (get-char-attribute char key)))
803 (insert (format "(%s . %S)%s"
807 (setq attributes (delq key attributes))
809 (setq key (intern (format "%s@%s" 'total-strokes domain)))
810 (when (and (memq key attributes)
811 (setq value (get-char-attribute char key)))
812 (insert (format "(%s . %S)%s"
816 (setq attributes (delq key attributes))
818 (dolist (feature '(ideographic-radical
821 (setq key (intern (format "%s@%s*sources" feature domain)))
822 (when (and (memq key attributes)
823 (setq value (get-char-attribute char key)))
824 (insert (format "(%s%s" key line-breaking))
826 (insert (format " %s" cell)))
828 (insert line-breaking)
829 (setq attributes (delq key attributes))
832 (when (and (memq 'ideographic-strokes attributes)
833 (setq value (get-char-attribute char 'ideographic-strokes)))
835 (insert (format "(ideographic-strokes . %S)%s"
838 (setq attributes (delq 'ideographic-strokes attributes))
840 (when (and (memq 'kangxi-radical attributes)
841 (setq value (get-char-attribute char 'kangxi-radical)))
842 (unless (eq value radical)
843 (insert (format "(kangxi-radical\t . %S)\t; %c%s"
845 (ideographic-radical value)
848 (setq radical value)))
849 (setq attributes (delq 'kangxi-radical attributes))
851 (when (and (memq 'kangxi-strokes attributes)
852 (setq value (get-char-attribute char 'kangxi-strokes)))
853 (unless (eq value strokes)
854 (insert (format "(kangxi-strokes\t . %S)%s"
858 (setq strokes value)))
859 (setq attributes (delq 'kangxi-strokes attributes))
861 (when (and (memq 'japanese-radical attributes)
862 (setq value (get-char-attribute char 'japanese-radical)))
863 (unless (eq value radical)
864 (insert (format "(japanese-radical\t . %S)\t; %c%s"
866 (ideographic-radical value)
869 (setq radical value)))
870 (setq attributes (delq 'japanese-radical attributes))
872 (when (and (memq 'japanese-strokes attributes)
873 (setq value (get-char-attribute char 'japanese-strokes)))
874 (unless (eq value strokes)
875 (insert (format "(japanese-strokes\t . %S)%s"
879 (setq strokes value)))
880 (setq attributes (delq 'japanese-strokes attributes))
882 (when (and (memq 'cns-radical attributes)
883 (setq value (get-char-attribute char 'cns-radical)))
884 (insert (format "(cns-radical\t . %S)\t; %c%s"
886 (ideographic-radical value)
888 (setq attributes (delq 'cns-radical attributes))
890 (when (and (memq 'cns-strokes attributes)
891 (setq value (get-char-attribute char 'cns-strokes)))
892 (unless (eq value strokes)
893 (insert (format "(cns-strokes\t . %S)%s"
897 (setq strokes value)))
898 (setq attributes (delq 'cns-strokes attributes))
900 (when (and (memq 'shinjigen-1-radical attributes)
901 (setq value (get-char-attribute char 'shinjigen-1-radical)))
902 (unless (eq value radical)
903 (insert (format "(shinjigen-1-radical . %S)\t; %c%s"
905 (ideographic-radical value)
908 (setq radical value)))
909 (setq attributes (delq 'shinjigen-1-radical attributes))
911 (when (and (memq 'ideographic- attributes)
912 (setq value (get-char-attribute char 'ideographic-)))
913 (insert "(ideographic- ")
914 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
917 (setq cell (car value))
919 (setq cell (decode-char '=ucs cell)))
920 (cond ((characterp cell)
924 (insert (format "%S" cell))
925 (char-db-insert-char-spec cell readable))
926 (setq separator lbs))
930 (if (consp (car cell))
931 (char-db-insert-char-spec cell readable)
932 (char-db-insert-char-reference cell readable))
933 (setq separator lbs))
937 (insert (prin1-to-string cell))
938 (setq separator " ")))
939 (setq value (cdr value)))
941 (insert line-breaking)
942 (setq attributes (delq 'ideographic- attributes)))
943 (when (and (memq 'total-strokes attributes)
944 (setq value (get-char-attribute char 'total-strokes)))
945 (insert (format "(total-strokes . %S)%s"
948 (setq attributes (delq 'total-strokes attributes))
950 (when (and (memq '->ideograph attributes)
951 (setq value (get-char-attribute char '->ideograph)))
952 (insert (format "(->ideograph\t%s)%s"
953 (mapconcat (lambda (code)
954 (cond ((symbolp code)
957 (format "#x%04X" code))
960 line-breaking code))))
963 (setq attributes (delq '->ideograph attributes))
965 ;; (when (and (memq '->decomposition attributes)
966 ;; (setq value (get-char-attribute char '->decomposition)))
967 ;; (insert (format "(->decomposition\t%s)%s"
968 ;; (mapconcat (lambda (code)
969 ;; (cond ((symbolp code)
970 ;; (symbol-name code))
971 ;; ((characterp code)
973 ;; (format "%S" code)
978 ;; (format "#x%04X" code))
980 ;; (format "%s%S" line-breaking code))))
983 ;; (setq attributes (delq '->decomposition attributes))
985 (if (equal (get-char-attribute char '->titlecase)
986 (get-char-attribute char '->uppercase))
987 (setq attributes (delq '->titlecase attributes)))
988 (when (and (memq '->mojikyo attributes)
989 (setq value (get-char-attribute char '->mojikyo)))
990 (insert (format "(->mojikyo\t\t. %06d)\t; %c%s"
991 value (decode-char 'mojikyo value)
993 (setq attributes (delq '->mojikyo attributes))
995 (when (and (memq 'hanyu-dazidian-vol attributes)
996 (setq value (get-char-attribute char 'hanyu-dazidian-vol)))
997 (insert (format "(hanyu-dazidian-vol . %d)%s"
998 value line-breaking))
999 (setq attributes (delq 'hanyu-dazidian-vol attributes))
1001 (when (and (memq 'hanyu-dazidian-page attributes)
1002 (setq value (get-char-attribute char 'hanyu-dazidian-page)))
1003 (insert (format "(hanyu-dazidian-page . %d)%s"
1004 value line-breaking))
1005 (setq attributes (delq 'hanyu-dazidian-page attributes))
1007 (when (and (memq 'hanyu-dazidian-char attributes)
1008 (setq value (get-char-attribute char 'hanyu-dazidian-char)))
1009 (insert (format "(hanyu-dazidian-char . %d)%s"
1010 value line-breaking))
1011 (setq attributes (delq 'hanyu-dazidian-char attributes))
1014 (dolist (ignored '(composition
1015 ->denotational <-subsumptive ->ucs-unified
1016 ->ideographic-component-forms))
1017 (setq attributes (delq ignored attributes))))
1019 (setq name (car attributes))
1020 (if (setq value (get-char-attribute char name))
1021 (cond ((setq ret (find-charset name))
1022 (setq name (charset-name ret))
1023 (if (and (not (memq name dest-ccss))
1025 (setq value (get-char-attribute char name))
1026 (setq dest-ccss (cons name dest-ccss))))
1027 (char-db-insert-ccs-feature name value line-breaking))
1029 ((string-match "^=>ucs@" (symbol-name name))
1030 (insert (format "(%-18s . #x%04X)\t; %c%s"
1031 name value (decode-char '=ucs value)
1034 ((eq name 'jisx0208-1978/4X)
1035 (insert (format "(%-18s . #x%04X)%s"
1041 (not (eq name '->subsumptive))
1042 (not (eq name '->uppercase))
1043 (not (eq name '->lowercase))
1044 (not (eq name '->titlecase))
1045 (not (eq name '->canonical))
1046 (not (eq name '->Bopomofo))
1047 (not (eq name '->mistakable))
1048 (not (eq name '->ideographic-variants))
1049 (null (get-char-attribute
1050 char (intern (format "%s*sources" name))))
1051 (not (string-match "\\*sources$" (symbol-name name)))
1052 (null (get-char-attribute
1053 char (intern (format "%s*note" name))))
1054 (not (string-match "\\*note$" (symbol-name name)))
1055 (or (eq name '<-identical)
1056 (eq name '<-uppercase)
1057 (eq name '<-lowercase)
1058 (eq name '<-titlecase)
1059 (eq name '<-canonical)
1060 (eq name '<-ideographic-variants)
1061 ;; (eq name '<-synonyms)
1062 (string-match "^<-synonyms" (symbol-name name))
1063 (eq name '<-mistakable)
1064 (when (string-match "^->" (symbol-name name))
1066 ((string-match "^->fullwidth" (symbol-name name))
1067 (not (and (consp value)
1068 (characterp (car value))
1070 (car value) '=ucs 'defined-only)))
1075 ((or (eq name 'ideographic-structure)
1076 (eq name 'ideographic-combination)
1077 (eq name 'ideographic-)
1078 (eq name '=decomposition)
1079 (string-match "^=>decomposition" (symbol-name name))
1080 (string-match "^\\(->\\|<-\\)[^*]*$" (symbol-name name))
1081 (string-match "^\\(->\\|<-\\)[^*]*\\*sources$"
1084 (char-db-insert-relation-feature char name value
1087 ((memq name '(ideograph=
1088 original-ideograph-of
1089 ancient-ideograph-of
1092 ;; simplified-ideograph-of
1093 ideographic-variants
1094 ;; ideographic-different-form-of
1096 (insert (format "(%-18s%s " name line-breaking))
1097 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1099 (while (consp value)
1100 (setq cell (car value))
1101 (if (and (consp cell)
1106 (char-db-insert-alist cell readable)
1107 (setq separator lbs))
1110 (insert (prin1-to-string cell))
1111 (setq separator " "))
1112 (setq value (cdr value)))
1114 (insert line-breaking))
1116 (insert (format "(%-18s " name))
1117 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1119 (while (consp value)
1120 (setq cell (car value))
1121 (if (and (consp cell)
1123 (setq ret (condition-case nil
1131 (setq key (car (car rest)))
1132 (if (find-charset key)
1133 (setq cal (cons key cal))
1134 (setq al (cons key al)))
1135 (setq rest (cdr rest)))
1138 (insert-char-attributes ret
1141 (setq separator lbs))
1142 (setq ret (prin1-to-string cell))
1144 (if (< (+ (current-column)
1151 (setq separator " "))
1152 (setq value (cdr value)))
1154 (insert line-breaking))
1156 (insert (format "(%-18s" name))
1157 (setq ret (prin1-to-string value))
1158 (unless (< (+ (current-column)
1162 (insert line-breaking))
1163 (insert " . " ret ")" line-breaking)
1164 ;; (insert (format "(%-18s . %S)%s"
1169 (setq attributes (cdr 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 (char-variants char))
1201 (setq variants (sort variants #'<))
1202 (setq rest variants)
1203 (setq variants (cons char variants))
1205 (setq variant (car rest))
1206 (unless (get-char-attribute variant '<-subsumptive)
1207 (if (and (or (null script)
1208 (null (setq vs (get-char-attribute variant 'script)))
1210 (or (null excluded-script)
1211 (null (setq vs (get-char-attribute variant 'script)))
1212 (not (memq excluded-script vs))))
1213 (unless (and no-ucs-unified (get-char-attribute variant '=ucs))
1214 (insert-char-data variant printable)
1215 (if (setq ret (char-variants variant))
1217 (or (memq (car ret) variants)
1218 ;; (get-char-attribute (car ret) '<-subsumptive)
1219 (setq rest (nconc rest (list (car ret)))))
1220 (setq ret (cdr ret)))))))
1221 (setq rest (cdr rest)))))
1223 (defun insert-char-range-data (min max &optional script excluded-script)
1226 (while (<= code max)
1227 (setq char (decode-char '=ucs code))
1228 (if (encode-char char '=ucs 'defined-only)
1229 (insert-char-data-with-variant char nil 'no-ucs-unified
1230 script excluded-script))
1231 (setq code (1+ code)))))
1233 (defun write-char-range-data-to-file (min max file
1234 &optional script excluded-script)
1235 (let ((coding-system-for-write char-db-file-coding-system))
1237 (insert (format ";; -*- coding: %s -*-\n"
1238 char-db-file-coding-system))
1239 (insert-char-range-data min max script excluded-script)
1240 (write-region (point-min)(point-max) file))))
1242 (defvar what-character-original-window-configuration)
1245 (defun what-char-definition (char)
1246 (interactive (list (char-after)))
1247 (let ((buf (get-buffer-create "*Character Description*"))
1248 (the-buf (current-buffer))
1249 (win-conf (current-window-configuration)))
1251 (make-local-variable 'what-character-original-window-configuration)
1252 (setq what-character-original-window-configuration win-conf)
1253 (setq buffer-read-only nil)
1257 (insert-char-data-with-variant char 'printable)
1258 (unless (char-attribute-alist char)
1259 (insert (format ";; = %c\n"
1260 (let* ((rest (split-char char))
1264 (setq code (logior (lsh code 8)
1266 (decode-char ccs code)))))
1267 ;; (char-db-update-comment)
1268 (set-buffer-modified-p nil)
1269 (view-mode the-buf (lambda (buf)
1270 (set-window-configuration
1271 what-character-original-window-configuration)
1273 (goto-char (point-min)))
1275 (set-window-configuration
1276 what-character-original-window-configuration)
1277 (signal (car err) (cdr err)))))))
1279 (provide 'char-db-util)
1281 ;;; char-db-util.el ends here