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 [?一 ?上 ?示 ?三 ?王 ?玉 ?玨 ?气 ?士 ?丨 ?屮 ?艸 ?茻])
78 (defun shuowen-radical (number)
79 (aref shuowen-radicals (1- number)))
81 (defvar char-db-file-coding-system 'utf-8-mcs-er)
83 (defvar char-db-feature-domains
84 '(ucs daikanwa cns gt jis jis/alt jis/a jis/b
85 jis-x0212 jis-x0213 cdp shinjigen misc unknown))
87 (defvar char-db-ignored-attributes '(ideographic-products))
89 (defun char-attribute-name< (ka kb)
91 ((eq '->denotational kb)
93 ((eq '->subsumptive kb)
94 (not (eq '->denotational ka)))
95 ((eq '->denotational ka)
97 ((eq '->subsumptive ka)
100 (string-match "^->" (symbol-name ka)))
101 (cond ((and (symbolp kb)
102 (string-match "^->" (symbol-name kb)))
103 (string< (symbol-name ka)
108 (string-match "^->" (symbol-name kb)))
111 (string-match "^<-" (symbol-name ka)))
113 (cond ((string-match "^<-" (symbol-name kb))
114 (string< (symbol-name ka)
117 ;; ((string-match "^->" (symbol-name kb))
122 (string-match "^<-" (symbol-name kb)))
124 ;; (not (string-match "^->" (symbol-name ka)))
127 (if (find-charset kb)
128 (if (<= (charset-id ka) 1)
129 (if (<= (charset-id kb) 1)
131 ((= (charset-dimension ka)
132 (charset-dimension kb))
133 (> (charset-id ka)(charset-id kb)))
135 (> (charset-dimension ka)
136 (charset-dimension kb))
139 (if (<= (charset-id kb) 1)
141 (< (charset-id ka)(charset-id kb))))
147 (string< (symbol-name ka)
153 (defvar char-db-coded-charset-priority-list
214 (defun char-db-make-char-spec (char)
216 (cond ((characterp char)
217 (cond ((and (setq ret (encode-char char '=ucs 'defined-only))
218 (not (and (<= #xE000 ret)(<= ret #xF8FF))))
219 (setq char-spec (list (cons '=ucs ret)))
220 (cond ((setq ret (get-char-attribute char 'name))
221 (setq char-spec (cons (cons 'name ret) char-spec))
223 ((setq ret (get-char-attribute char 'name*))
224 (setq char-spec (cons (cons 'name* ret) char-spec))
229 (let ((rest char-db-coded-charset-priority-list)
232 (setq ccs (charset-name
233 (find-charset (car rest))))
235 (encode-char char ccs
237 (throw 'tag (cons ccs ret)))
238 (setq rest (cdr rest))))))
239 (setq char-spec (list ret))
240 (dolist (ccs (delq (car ret) (charset-list)))
241 (if (and (or (charset-iso-final-char ccs)
248 (setq ccs (charset-name ccs))
249 (null (assq ccs char-spec))
250 (setq ret (encode-char char ccs 'defined-only)))
251 (setq char-spec (cons (cons ccs ret) char-spec))))
253 (setq char-spec (split-char char)))
254 (cond ((setq ret (get-char-attribute char 'name))
255 (setq char-spec (cons (cons 'name ret) char-spec))
257 ((setq ret (get-char-attribute char 'name*))
258 (setq char-spec (cons (cons 'name* ret) char-spec))
265 (defun char-db-insert-char-spec (char &optional readable column
268 (setq column (current-column)))
269 (let (char-spec temp-char)
270 (setq char-spec (char-db-make-char-spec char))
271 (unless (or (characterp char) ; char
273 (setq char (find-char char-spec))
275 ;; define temporary character
276 ;; Current implementation is dirty.
277 (setq temp-char (define-char (cons '(ideograph-daikanwa . 0)
279 (remove-char-attribute temp-char 'ideograph-daikanwa)
280 (setq char temp-char))
281 (insert-char-attributes char
283 (union (mapcar #'car char-spec)
286 ;; undefine temporary character
287 ;; Current implementation is dirty.
288 (setq char-spec (char-attribute-alist temp-char))
290 (remove-char-attribute temp-char (car (car char-spec)))
291 (setq char-spec (cdr char-spec))))))
293 (defun char-db-insert-alist (alist &optional readable column)
295 (setq column (current-column)))
297 (concat "\n" (make-string (1+ column) ?\ )))
301 lbs cell rest separator)
304 (setq name (car (car alist))
305 value (cdr (car alist)))
306 (cond ((eq name 'char)
308 (if (setq ret (condition-case nil
316 (setq key (car (car value)))
317 ;; (if (find-charset key)
318 ;; (setq cal (cons key cal))
319 (setq al (cons key al))
321 (setq value (cdr value)))
322 (insert-char-attributes ret
326 (insert (prin1-to-string value)))
328 (insert line-breaking))
330 (insert (format "(%-18s " name))
331 (setq lbs (concat "\n" (make-string (current-column) ?\ )))
333 (setq cell (car value))
334 (if (and (consp cell)
336 (setq ret (condition-case nil
346 (setq key (car (car rest)))
347 ;; (if (find-charset key)
348 ;; (setq cal (cons key cal))
349 (setq al (cons key al))
351 (setq rest (cdr rest)))
354 (insert-char-attributes ret
358 (setq separator lbs))
361 (insert (prin1-to-string cell))
362 (setq separator " "))
363 (setq value (cdr value)))
365 (insert line-breaking))
367 (insert (format "(%-18s . %S)%s"
370 (setq alist (cdr alist))))
373 (defun char-db-insert-char-reference (plist &optional readable column)
375 (setq column (current-column)))
377 (concat "\n" (make-string (1+ column) ?\ )))
382 (setq name (pop plist))
383 (setq value (pop plist))
384 (cond ((eq name :char)
387 (cond ((numberp value)
388 (setq value (decode-char '=ucs value)))
390 ;; (setq value (or (find-char value)
393 (char-db-insert-char-spec value readable)
394 (insert line-breaking)
397 (insert (format "%s%s\t%d ; %c%s"
400 (ideographic-radical value)
404 (insert (format "%s%s\t%S" separator name value))
405 (setq separator line-breaking)))
409 (defun char-db-decode-isolated-char (ccs code-point)
412 (cond ((eq ccs 'arabic-iso8859-6)
413 (decode-char ccs code-point))
414 ((and (memq ccs '(=gt-pj-1
425 (setq ret (decode-char ccs code-point))
426 (setq ret (encode-char ret '=gt 'defined-only)))
427 (decode-builtin-char '=gt ret))
429 (decode-builtin-char ccs code-point))))
430 (cond ((and (<= 0 (char-int ret))
431 (<= (char-int ret) #x1F))
432 (decode-char '=ucs (+ #x2400 (char-int ret))))
433 ((= (char-int ret) #x7F)
437 (defvar char-db-convert-obsolete-format t)
439 (defun char-db-insert-ccs-feature (name value line-breaking)
442 (cond ((or (memq name '(=daikanwa
443 =daikanwa@rev1 =daikanwa@rev2
444 =gt =gt-k =cbeta =zinbun-oracle))
445 (string-match "^=adobe-" (symbol-name name)))
446 "(%-18s . %05d)\t; %c")
448 "(%-18s . %06d)\t; %c")
449 ((>= (charset-dimension name) 2)
450 "(%-18s . #x%04X)\t; %c")
452 "(%-18s . #x%02X)\t; %c"))
454 (if (= (charset-iso-graphic-plane name) 1)
456 (cond ((= (charset-dimension name) 1)
458 ((= (charset-dimension name) 2)
460 ((= (charset-dimension name) 3)
464 (char-db-decode-isolated-char name value)))
465 (if (and (= (charset-chars name) 94)
466 (= (charset-dimension name) 2))
467 (insert (format " [%02d-%02d]"
468 (- (lsh value -8) 32)
469 (- (logand value 255) 32))))
470 (insert line-breaking))
472 (defun char-db-insert-relation-feature (char name value line-breaking
474 (insert (format "(%-18s%s " name line-breaking))
475 (let ((lbs (concat "\n" (make-string (current-column) ?\ )))
476 separator cell sources required-features
479 (setq cell (car value))
481 (setq cell (decode-char '=ucs cell)))
483 ((eq name '->subsumptive)
484 (when (or (not (some (lambda (atr)
485 (get-char-attribute cell atr))
486 char-db-ignored-attributes))
488 (encode-char cell ccs 'defined-only))
492 (let ((char-db-ignored-attributes
494 char-db-ignored-attributes)))
495 (insert-char-attributes cell readable))
496 (setq separator lbs))
501 char (intern (format "%s*sources" name))))
502 (setq required-features nil)
503 (dolist (source sources)
505 ((memq source '(JP JP/Jouyou shinjigen-1))
506 (setq required-features
507 (union required-features
516 (setq required-features
517 (union required-features
522 ((find-charset (setq ret (intern (format "=%s" source))))
523 (setq required-features
524 (cons ret required-features)))
525 (t (setq required-features
526 (cons source required-features)))))
527 (cond ((string-match "@JP" (symbol-name name))
528 (setq required-features
529 (union required-features
537 ((string-match "@CN" (symbol-name name))
538 (setq required-features
539 (union required-features
546 (insert (format "%S" cell))
547 (char-db-insert-char-spec cell readable
550 (setq separator lbs))
554 (if (consp (car cell))
555 (char-db-insert-char-spec cell readable)
556 (char-db-insert-char-reference cell readable))
557 (setq separator lbs))
561 (insert (prin1-to-string cell))
562 (setq separator " ")))
563 (setq value (cdr value)))
565 (insert line-breaking)))
567 (defun insert-char-attributes (char &optional readable attributes column)
569 (setq column (current-column)))
570 (let (name value ; has-long-ccs-name
574 (concat "\n" (make-string (1+ column) ?\ )))
575 lbs cell separator ret
577 dest-ccss ; sources required-features
582 (if (consp attributes)
584 (dolist (name attributes)
585 (unless (memq name char-db-ignored-attributes)
586 (if (find-charset name)
590 (dolist (name (char-attribute-list))
591 (unless (memq name char-db-ignored-attributes)
592 (if (find-charset name)
596 #'char-attribute-name<)))
598 (when (memq '<-subsumptive attributes)
600 (when (setq value (get-char-attribute char '<-subsumptive))
601 (char-db-insert-relation-feature char '<-subsumptive value
604 (setq attributes (delq '<-subsumptive attributes)))
605 (when (and (memq '<-denotational attributes)
606 (setq value (get-char-attribute char '<-denotational)))
607 (char-db-insert-relation-feature char '<-denotational value
610 (setq attributes (delq '<-denotational attributes)))
611 (when (and (memq 'name attributes)
612 (setq value (get-char-attribute char 'name)))
614 (if (> (+ (current-column) (length value)) 48)
617 value line-breaking))
618 (setq attributes (delq 'name attributes))
620 (when (and (memq 'name* attributes)
621 (setq value (get-char-attribute char 'name*)))
623 (if (> (+ (current-column) (length value)) 48)
626 value line-breaking))
627 (setq attributes (delq 'name* attributes))
629 (when (and (memq 'script attributes)
630 (setq value (get-char-attribute char 'script)))
631 (insert (format "(script\t\t%s)%s"
632 (mapconcat (function prin1-to-string)
635 (setq attributes (delq 'script attributes))
637 (dolist (name '(=>ucs =>ucs*))
638 (when (and (memq name attributes)
639 (setq value (get-char-attribute char name)))
640 (insert (format "(%-18s . #x%04X)\t; %c%s"
641 name value (decode-char '=ucs value)
643 (setq attributes (delq name attributes))))
644 (dolist (name '(=>ucs@gb =>ucs@cns =>ucs@jis =>ucs@ks =>ucs@big5))
645 (when (and (memq name attributes)
646 (setq value (get-char-attribute char name)))
647 (insert (format "(%-18s . #x%04X)\t; %c%s"
652 (symbol-name name) 2)))
655 (setq attributes (delq name attributes))
657 (dolist (name '(=>daikanwa))
658 (when (and (memq name attributes)
659 (setq value (get-char-attribute char name)))
662 (format "(%-18s . %05d)\t; %c%s"
663 name value (decode-char '=daikanwa value)
665 (format "(%-18s %s)\t; %c%s"
667 (mapconcat (function prin1-to-string)
669 (char-representative-of-daikanwa char)
671 (setq attributes (delq name attributes))))
672 (when (and (memq 'general-category attributes)
673 (setq value (get-char-attribute char 'general-category)))
675 "(general-category\t%s) ; %s%s"
676 (mapconcat (lambda (cell)
679 (cond ((rassoc value unidata-normative-category-alist)
680 "Normative Category")
681 ((rassoc value unidata-informative-category-alist)
682 "Informative Category")
686 (setq attributes (delq 'general-category attributes))
688 (when (and (memq 'bidi-category attributes)
689 (setq value (get-char-attribute char 'bidi-category)))
690 (insert (format "(bidi-category\t. %S)%s"
693 (setq attributes (delq 'bidi-category attributes))
695 (unless (or (not (memq 'mirrored attributes))
696 (eq (setq value (get-char-attribute char 'mirrored 'empty))
698 (insert (format "(mirrored\t\t. %S)%s"
701 (setq attributes (delq 'mirrored attributes))
704 ((and (memq 'decimal-digit-value attributes)
705 (setq value (get-char-attribute char 'decimal-digit-value)))
706 (insert (format "(decimal-digit-value . %S)%s"
709 (setq attributes (delq 'decimal-digit-value attributes))
710 (when (and (memq 'digit-value attributes)
711 (setq value (get-char-attribute char 'digit-value)))
712 (insert (format "(digit-value\t . %S)%s"
715 (setq attributes (delq 'digit-value attributes))
717 (when (and (memq 'numeric-value attributes)
718 (setq value (get-char-attribute char 'numeric-value)))
719 (insert (format "(numeric-value\t . %S)%s"
722 (setq attributes (delq 'numeric-value attributes))
726 (when (and (memq 'digit-value attributes)
727 (setq value (get-char-attribute char 'digit-value)))
728 (insert (format "(digit-value\t. %S)%s"
731 (setq attributes (delq 'digit-value attributes))
733 (when (and (memq 'numeric-value attributes)
734 (setq value (get-char-attribute char 'numeric-value)))
735 (insert (format "(numeric-value\t. %S)%s"
738 (setq attributes (delq 'numeric-value attributes))
740 (when (and (memq 'iso-10646-comment attributes)
741 (setq value (get-char-attribute char 'iso-10646-comment)))
742 (insert (format "(iso-10646-comment\t. %S)%s"
745 (setq attributes (delq 'iso-10646-comment attributes))
747 (when (and (memq 'morohashi-daikanwa attributes)
748 (setq value (get-char-attribute char 'morohashi-daikanwa)))
749 (insert (format "(morohashi-daikanwa\t%s)%s"
750 (mapconcat (function prin1-to-string) value " ")
752 (setq attributes (delq 'morohashi-daikanwa attributes))
756 (when (and (memq 'ideographic-radical attributes)
757 (setq value (get-char-attribute char 'ideographic-radical)))
759 (insert (format "(ideographic-radical . %S)\t; %c%s"
761 (ideographic-radical radical)
763 (setq attributes (delq 'ideographic-radical attributes))
765 (when (and (memq 'shuowen-radical attributes)
766 (setq value (get-char-attribute char 'shuowen-radical)))
767 (insert (format "(shuowen-radical\t. %S)\t; %c%s"
769 (shuowen-radical value)
771 (setq attributes (delq 'shuowen-radical attributes))
776 char-db-feature-domains
778 (dolist (feature (char-attribute-list))
779 (setq feature (symbol-name feature))
781 "\\(radical\\|strokes\\)@\\([^@*]+\\)\\(\\*\\|$\\)"
783 (setq domain (intern (match-string 2 feature)))
784 (unless (memq domain dest)
785 (setq dest (cons domain dest)))))
786 (sort dest #'string<))))
787 (setq key (intern (format "%s@%s" 'ideographic-radical domain)))
788 (when (and (memq key attributes)
789 (setq value (get-char-attribute char key)))
791 (insert (format "(%s . %S)\t; %c%s"
794 (ideographic-radical radical)
796 (setq attributes (delq key attributes))
798 (setq key (intern (format "%s@%s" 'ideographic-strokes domain)))
799 (when (and (memq key attributes)
800 (setq value (get-char-attribute char key)))
802 (insert (format "(%s . %S)%s"
806 (setq attributes (delq key attributes))
808 (setq key (intern (format "%s@%s" 'total-strokes domain)))
809 (when (and (memq key attributes)
810 (setq value (get-char-attribute char key)))
811 (insert (format "(%s . %S)%s"
815 (setq attributes (delq key attributes))
817 (dolist (feature '(ideographic-radical
820 (setq key (intern (format "%s@%s*sources" feature domain)))
821 (when (and (memq key attributes)
822 (setq value (get-char-attribute char key)))
823 (insert (format "(%s%s" key line-breaking))
825 (insert (format " %s" cell)))
827 (insert line-breaking)
828 (setq attributes (delq key attributes))
831 (when (and (memq 'ideographic-strokes attributes)
832 (setq value (get-char-attribute char 'ideographic-strokes)))
834 (insert (format "(ideographic-strokes . %S)%s"
837 (setq attributes (delq 'ideographic-strokes attributes))
839 (when (and (memq 'kangxi-radical attributes)
840 (setq value (get-char-attribute char 'kangxi-radical)))
841 (unless (eq value radical)
842 (insert (format "(kangxi-radical\t . %S)\t; %c%s"
844 (ideographic-radical value)
847 (setq radical value)))
848 (setq attributes (delq 'kangxi-radical attributes))
850 (when (and (memq 'kangxi-strokes attributes)
851 (setq value (get-char-attribute char 'kangxi-strokes)))
852 (unless (eq value strokes)
853 (insert (format "(kangxi-strokes\t . %S)%s"
857 (setq strokes value)))
858 (setq attributes (delq 'kangxi-strokes attributes))
860 (when (and (memq 'japanese-radical attributes)
861 (setq value (get-char-attribute char 'japanese-radical)))
862 (unless (eq value radical)
863 (insert (format "(japanese-radical\t . %S)\t; %c%s"
865 (ideographic-radical value)
868 (setq radical value)))
869 (setq attributes (delq 'japanese-radical attributes))
871 (when (and (memq 'japanese-strokes attributes)
872 (setq value (get-char-attribute char 'japanese-strokes)))
873 (unless (eq value strokes)
874 (insert (format "(japanese-strokes\t . %S)%s"
878 (setq strokes value)))
879 (setq attributes (delq 'japanese-strokes attributes))
881 (when (and (memq 'cns-radical attributes)
882 (setq value (get-char-attribute char 'cns-radical)))
883 (insert (format "(cns-radical\t . %S)\t; %c%s"
885 (ideographic-radical value)
887 (setq attributes (delq 'cns-radical attributes))
889 (when (and (memq 'cns-strokes attributes)
890 (setq value (get-char-attribute char 'cns-strokes)))
891 (unless (eq value strokes)
892 (insert (format "(cns-strokes\t . %S)%s"
896 (setq strokes value)))
897 (setq attributes (delq 'cns-strokes attributes))
899 (when (and (memq 'shinjigen-1-radical attributes)
900 (setq value (get-char-attribute char 'shinjigen-1-radical)))
901 (unless (eq value radical)
902 (insert (format "(shinjigen-1-radical . %S)\t; %c%s"
904 (ideographic-radical value)
907 (setq radical value)))
908 (setq attributes (delq 'shinjigen-1-radical attributes))
910 (when (and (memq 'ideographic- attributes)
911 (setq value (get-char-attribute char 'ideographic-)))
912 (insert "(ideographic- ")
913 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
916 (setq cell (car value))
918 (setq cell (decode-char '=ucs cell)))
919 (cond ((characterp cell)
923 (insert (format "%S" cell))
924 (char-db-insert-char-spec cell readable))
925 (setq separator lbs))
929 (if (consp (car cell))
930 (char-db-insert-char-spec cell readable)
931 (char-db-insert-char-reference cell readable))
932 (setq separator lbs))
936 (insert (prin1-to-string cell))
937 (setq separator " ")))
938 (setq value (cdr value)))
940 (insert line-breaking)
941 (setq attributes (delq 'ideographic- attributes)))
942 (when (and (memq 'total-strokes attributes)
943 (setq value (get-char-attribute char 'total-strokes)))
944 (insert (format "(total-strokes . %S)%s"
947 (setq attributes (delq 'total-strokes attributes))
949 (when (and (memq '->ideograph attributes)
950 (setq value (get-char-attribute char '->ideograph)))
951 (insert (format "(->ideograph\t%s)%s"
952 (mapconcat (lambda (code)
953 (cond ((symbolp code)
956 (format "#x%04X" code))
959 line-breaking code))))
962 (setq attributes (delq '->ideograph attributes))
964 ;; (when (and (memq '->decomposition attributes)
965 ;; (setq value (get-char-attribute char '->decomposition)))
966 ;; (insert (format "(->decomposition\t%s)%s"
967 ;; (mapconcat (lambda (code)
968 ;; (cond ((symbolp code)
969 ;; (symbol-name code))
970 ;; ((characterp code)
972 ;; (format "%S" code)
977 ;; (format "#x%04X" code))
979 ;; (format "%s%S" line-breaking code))))
982 ;; (setq attributes (delq '->decomposition attributes))
984 (if (equal (get-char-attribute char '->titlecase)
985 (get-char-attribute char '->uppercase))
986 (setq attributes (delq '->titlecase attributes)))
987 (when (and (memq '->mojikyo attributes)
988 (setq value (get-char-attribute char '->mojikyo)))
989 (insert (format "(->mojikyo\t\t. %06d)\t; %c%s"
990 value (decode-char 'mojikyo value)
992 (setq attributes (delq '->mojikyo attributes))
994 (when (and (memq 'hanyu-dazidian-vol attributes)
995 (setq value (get-char-attribute char 'hanyu-dazidian-vol)))
996 (insert (format "(hanyu-dazidian-vol . %d)%s"
997 value line-breaking))
998 (setq attributes (delq 'hanyu-dazidian-vol attributes))
1000 (when (and (memq 'hanyu-dazidian-page attributes)
1001 (setq value (get-char-attribute char 'hanyu-dazidian-page)))
1002 (insert (format "(hanyu-dazidian-page . %d)%s"
1003 value line-breaking))
1004 (setq attributes (delq 'hanyu-dazidian-page attributes))
1006 (when (and (memq 'hanyu-dazidian-char attributes)
1007 (setq value (get-char-attribute char 'hanyu-dazidian-char)))
1008 (insert (format "(hanyu-dazidian-char . %d)%s"
1009 value line-breaking))
1010 (setq attributes (delq 'hanyu-dazidian-char attributes))
1013 (dolist (ignored '(composition
1014 ->denotational <-subsumptive ->ucs-unified
1015 ->ideographic-component-forms))
1016 (setq attributes (delq ignored attributes))))
1018 (setq name (car attributes))
1019 (if (setq value (get-char-attribute char name))
1020 (cond ((setq ret (find-charset name))
1021 (setq name (charset-name ret))
1022 (if (and (not (memq name dest-ccss))
1024 (setq value (get-char-attribute char name))
1025 (setq dest-ccss (cons name dest-ccss))))
1026 (char-db-insert-ccs-feature name value line-breaking))
1028 ((string-match "^=>ucs@" (symbol-name name))
1029 (insert (format "(%-18s . #x%04X)\t; %c%s"
1030 name value (decode-char '=ucs value)
1033 ((eq name 'jisx0208-1978/4X)
1034 (insert (format "(%-18s . #x%04X)%s"
1040 (not (eq name '->subsumptive))
1041 (not (eq name '->uppercase))
1042 (not (eq name '->lowercase))
1043 (not (eq name '->titlecase))
1044 (not (eq name '->canonical))
1045 (not (eq name '->Bopomofo))
1046 (not (eq name '->mistakable))
1047 (not (eq name '->ideographic-variants))
1048 (null (get-char-attribute
1049 char (intern (format "%s*sources" name))))
1050 (not (string-match "\\*sources$" (symbol-name name)))
1051 (null (get-char-attribute
1052 char (intern (format "%s*note" name))))
1053 (not (string-match "\\*note$" (symbol-name name)))
1054 (or (eq name '<-identical)
1055 (eq name '<-uppercase)
1056 (eq name '<-lowercase)
1057 (eq name '<-titlecase)
1058 (eq name '<-canonical)
1059 (eq name '<-ideographic-variants)
1060 ;; (eq name '<-synonyms)
1061 (string-match "^<-synonyms" (symbol-name name))
1062 (eq name '<-mistakable)
1063 (when (string-match "^->" (symbol-name name))
1065 ((string-match "^->fullwidth" (symbol-name name))
1066 (not (and (consp value)
1067 (characterp (car value))
1069 (car value) '=ucs 'defined-only)))
1074 ((or (eq name 'ideographic-structure)
1075 (eq name 'ideographic-combination)
1076 (eq name 'ideographic-)
1077 (eq name '=decomposition)
1078 (string-match "^=>decomposition" (symbol-name name))
1079 (string-match "^\\(->\\|<-\\)[^*]*$" (symbol-name name))
1080 (string-match "^\\(->\\|<-\\)[^*]*\\*sources$"
1083 (char-db-insert-relation-feature char name value
1086 ((memq name '(ideograph=
1087 original-ideograph-of
1088 ancient-ideograph-of
1091 ;; simplified-ideograph-of
1092 ideographic-variants
1093 ;; ideographic-different-form-of
1095 (insert (format "(%-18s%s " name line-breaking))
1096 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1098 (while (consp value)
1099 (setq cell (car value))
1100 (if (and (consp cell)
1105 (char-db-insert-alist cell readable)
1106 (setq separator lbs))
1109 (insert (prin1-to-string cell))
1110 (setq separator " "))
1111 (setq value (cdr value)))
1113 (insert line-breaking))
1115 (insert (format "(%-18s " name))
1116 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1118 (while (consp value)
1119 (setq cell (car value))
1120 (if (and (consp cell)
1122 (setq ret (condition-case nil
1130 (setq key (car (car rest)))
1131 (if (find-charset key)
1132 (setq cal (cons key cal))
1133 (setq al (cons key al)))
1134 (setq rest (cdr rest)))
1137 (insert-char-attributes ret
1140 (setq separator lbs))
1141 (setq ret (prin1-to-string cell))
1143 (if (< (+ (current-column)
1150 (setq separator " "))
1151 (setq value (cdr value)))
1153 (insert line-breaking))
1155 (insert (format "(%-18s" name))
1156 (setq ret (prin1-to-string value))
1157 (unless (< (+ (current-column)
1161 (insert line-breaking))
1162 (insert " . " ret ")" line-breaking)
1163 ;; (insert (format "(%-18s . %S)%s"
1168 (setq attributes (cdr attributes)))
1171 (defun insert-char-data (char &optional readable
1174 (narrow-to-region (point)(point))
1175 (insert "(define-char
1177 (insert-char-attributes char readable attributes)
1179 (goto-char (point-min))
1180 (while (re-search-forward "[ \t]+$" nil t)
1183 (goto-char (point-min))
1184 (while (re-search-forward "[ \t][ \t][ \t]*" nil t)
1185 (let ((column (current-column))
1186 (indent-tabs-mode t))
1187 (delete-region (match-beginning 0) (point))
1188 (indent-to column)))
1189 (goto-char (point-max))
1190 ;; (tabify (point-min)(point-max))
1193 (defun insert-char-data-with-variant (char &optional printable
1195 script excluded-script)
1196 (insert-char-data char printable)
1197 (let ((variants (char-variants char))
1200 (setq variants (sort variants #'<))
1201 (setq rest variants)
1202 (setq variants (cons char variants))
1204 (setq variant (car rest))
1205 (unless (get-char-attribute variant '<-subsumptive)
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 (unless (and no-ucs-unified (get-char-attribute variant '=ucs))
1213 (insert-char-data variant printable)
1214 (if (setq ret (char-variants variant))
1216 (or (memq (car ret) variants)
1217 ;; (get-char-attribute (car ret) '<-subsumptive)
1218 (setq rest (nconc rest (list (car ret)))))
1219 (setq ret (cdr ret)))))))
1220 (setq rest (cdr rest)))))
1222 (defun insert-char-range-data (min max &optional script excluded-script)
1225 (while (<= code max)
1226 (setq char (decode-char '=ucs code))
1227 (if (encode-char char '=ucs 'defined-only)
1228 (insert-char-data-with-variant char nil 'no-ucs-unified
1229 script excluded-script))
1230 (setq code (1+ code)))))
1232 (defun write-char-range-data-to-file (min max file
1233 &optional script excluded-script)
1234 (let ((coding-system-for-write char-db-file-coding-system))
1236 (insert (format ";; -*- coding: %s -*-\n"
1237 char-db-file-coding-system))
1238 (insert-char-range-data min max script excluded-script)
1239 (write-region (point-min)(point-max) file))))
1241 (defvar what-character-original-window-configuration)
1244 (defun what-char-definition (char)
1245 (interactive (list (char-after)))
1246 (let ((buf (get-buffer-create "*Character Description*"))
1247 (the-buf (current-buffer))
1248 (win-conf (current-window-configuration)))
1250 (make-local-variable 'what-character-original-window-configuration)
1251 (setq what-character-original-window-configuration win-conf)
1252 (setq buffer-read-only nil)
1256 (insert-char-data-with-variant char 'printable)
1257 (unless (char-attribute-alist char)
1258 (insert (format ";; = %c\n"
1259 (let* ((rest (split-char char))
1263 (setq code (logior (lsh code 8)
1265 (decode-char ccs code)))))
1266 ;; (char-db-update-comment)
1267 (set-buffer-modified-p nil)
1268 (view-mode the-buf (lambda (buf)
1269 (set-window-configuration
1270 what-character-original-window-configuration)
1272 (goto-char (point-min)))
1274 (set-window-configuration
1275 what-character-original-window-configuration)
1276 (signal (car err) (cdr err)))))))
1278 (provide 'char-db-util)
1280 ;;; char-db-util.el ends here