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 ((memq name '(=daikanwa
443 =daikanwa@rev1 =daikanwa@rev2
444 =gt =gt-k =cbeta =zinbun-oracle))
445 "(%-18s . %05d)\t; %c")
447 "(%-18s . %06d)\t; %c")
448 ((>= (charset-dimension name) 2)
449 "(%-18s . #x%04X)\t; %c")
451 "(%-18s . #x%02X)\t; %c"))
453 (if (= (charset-iso-graphic-plane name) 1)
455 (cond ((= (charset-dimension name) 1)
457 ((= (charset-dimension name) 2)
459 ((= (charset-dimension name) 3)
463 (char-db-decode-isolated-char name value)))
464 (if (and (= (charset-chars name) 94)
465 (= (charset-dimension name) 2))
466 (insert (format " [%02d-%02d]"
467 (- (lsh value -8) 32)
468 (- (logand value 255) 32))))
469 (insert line-breaking))
471 (defun char-db-insert-relation-feature (char name value line-breaking
473 (insert (format "(%-18s%s " name line-breaking))
474 (let ((lbs (concat "\n" (make-string (current-column) ?\ )))
475 separator cell sources required-features
478 (setq cell (car value))
480 (setq cell (decode-char '=ucs cell)))
482 ((eq name '->subsumptive)
483 (when (or (not (some (lambda (atr)
484 (get-char-attribute cell atr))
485 char-db-ignored-attributes))
487 (encode-char cell ccs 'defined-only))
491 (let ((char-db-ignored-attributes
493 char-db-ignored-attributes)))
494 (insert-char-attributes cell readable))
495 (setq separator lbs))
500 char (intern (format "%s*sources" name))))
501 (setq required-features nil)
502 (dolist (source sources)
504 ((memq source '(JP JP/Jouyou shinjigen-1))
505 (setq required-features
506 (union required-features
515 (setq required-features
516 (union required-features
521 ((find-charset (setq ret (intern (format "=%s" source))))
522 (setq required-features
523 (cons ret required-features)))
524 (t (setq required-features
525 (cons source required-features)))))
526 (cond ((string-match "@JP" (symbol-name name))
527 (setq required-features
528 (union required-features
536 ((string-match "@CN" (symbol-name name))
537 (setq required-features
538 (union required-features
545 (insert (format "%S" cell))
546 (char-db-insert-char-spec cell readable
549 (setq separator lbs))
553 (if (consp (car cell))
554 (char-db-insert-char-spec cell readable)
555 (char-db-insert-char-reference cell readable))
556 (setq separator lbs))
560 (insert (prin1-to-string cell))
561 (setq separator " ")))
562 (setq value (cdr value)))
564 (insert line-breaking)))
566 (defun insert-char-attributes (char &optional readable attributes column)
568 (setq column (current-column)))
569 (let (name value ; has-long-ccs-name
573 (concat "\n" (make-string (1+ column) ?\ )))
574 lbs cell separator ret
576 dest-ccss ; sources required-features
581 (if (consp attributes)
583 (dolist (name attributes)
584 (unless (memq name char-db-ignored-attributes)
585 (if (find-charset name)
589 (dolist (name (char-attribute-list))
590 (unless (memq name char-db-ignored-attributes)
591 (if (find-charset name)
595 #'char-attribute-name<)))
597 (when (memq '<-subsumptive attributes)
599 (when (setq value (get-char-attribute char '<-subsumptive))
600 (char-db-insert-relation-feature char '<-subsumptive value
603 (setq attributes (delq '<-subsumptive attributes)))
604 (when (and (memq '<-denotational attributes)
605 (setq value (get-char-attribute char '<-denotational)))
606 (char-db-insert-relation-feature char '<-denotational value
609 (setq attributes (delq '<-denotational attributes)))
610 (when (and (memq 'name attributes)
611 (setq value (get-char-attribute char 'name)))
613 (if (> (+ (current-column) (length value)) 48)
616 value line-breaking))
617 (setq attributes (delq 'name attributes))
619 (when (and (memq 'name* attributes)
620 (setq value (get-char-attribute char 'name*)))
622 (if (> (+ (current-column) (length value)) 48)
625 value line-breaking))
626 (setq attributes (delq 'name* attributes))
628 (when (and (memq 'script attributes)
629 (setq value (get-char-attribute char 'script)))
630 (insert (format "(script\t\t%s)%s"
631 (mapconcat (function prin1-to-string)
634 (setq attributes (delq 'script attributes))
636 (dolist (name '(=>ucs =>ucs*))
637 (when (and (memq name attributes)
638 (setq value (get-char-attribute char name)))
639 (insert (format "(%-18s . #x%04X)\t; %c%s"
640 name value (decode-char '=ucs value)
642 (setq attributes (delq name attributes))))
643 (dolist (name '(=>ucs@gb =>ucs@cns =>ucs@jis =>ucs@ks =>ucs@big5))
644 (when (and (memq name attributes)
645 (setq value (get-char-attribute char name)))
646 (insert (format "(%-18s . #x%04X)\t; %c%s"
651 (symbol-name name) 2)))
654 (setq attributes (delq name attributes))
656 (dolist (name '(=>daikanwa))
657 (when (and (memq name attributes)
658 (setq value (get-char-attribute char name)))
661 (format "(%-18s . %05d)\t; %c%s"
662 name value (decode-char '=daikanwa value)
664 (format "(%-18s %s)\t; %c%s"
666 (mapconcat (function prin1-to-string)
668 (char-representative-of-daikanwa char)
670 (setq attributes (delq name attributes))))
671 (when (and (memq 'general-category attributes)
672 (setq value (get-char-attribute char 'general-category)))
674 "(general-category\t%s) ; %s%s"
675 (mapconcat (lambda (cell)
678 (cond ((rassoc value unidata-normative-category-alist)
679 "Normative Category")
680 ((rassoc value unidata-informative-category-alist)
681 "Informative Category")
685 (setq attributes (delq 'general-category attributes))
687 (when (and (memq 'bidi-category attributes)
688 (setq value (get-char-attribute char 'bidi-category)))
689 (insert (format "(bidi-category\t. %S)%s"
692 (setq attributes (delq 'bidi-category attributes))
694 (unless (or (not (memq 'mirrored attributes))
695 (eq (setq value (get-char-attribute char 'mirrored 'empty))
697 (insert (format "(mirrored\t\t. %S)%s"
700 (setq attributes (delq 'mirrored attributes))
703 ((and (memq 'decimal-digit-value attributes)
704 (setq value (get-char-attribute char 'decimal-digit-value)))
705 (insert (format "(decimal-digit-value . %S)%s"
708 (setq attributes (delq 'decimal-digit-value attributes))
709 (when (and (memq 'digit-value attributes)
710 (setq value (get-char-attribute char 'digit-value)))
711 (insert (format "(digit-value\t . %S)%s"
714 (setq attributes (delq 'digit-value attributes))
716 (when (and (memq 'numeric-value attributes)
717 (setq value (get-char-attribute char 'numeric-value)))
718 (insert (format "(numeric-value\t . %S)%s"
721 (setq attributes (delq 'numeric-value attributes))
725 (when (and (memq 'digit-value attributes)
726 (setq value (get-char-attribute char 'digit-value)))
727 (insert (format "(digit-value\t. %S)%s"
730 (setq attributes (delq 'digit-value attributes))
732 (when (and (memq 'numeric-value attributes)
733 (setq value (get-char-attribute char 'numeric-value)))
734 (insert (format "(numeric-value\t. %S)%s"
737 (setq attributes (delq 'numeric-value attributes))
739 (when (and (memq 'iso-10646-comment attributes)
740 (setq value (get-char-attribute char 'iso-10646-comment)))
741 (insert (format "(iso-10646-comment\t. %S)%s"
744 (setq attributes (delq 'iso-10646-comment attributes))
746 (when (and (memq 'morohashi-daikanwa attributes)
747 (setq value (get-char-attribute char 'morohashi-daikanwa)))
748 (insert (format "(morohashi-daikanwa\t%s)%s"
749 (mapconcat (function prin1-to-string) value " ")
751 (setq attributes (delq 'morohashi-daikanwa attributes))
755 (when (and (memq 'ideographic-radical attributes)
756 (setq value (get-char-attribute char 'ideographic-radical)))
758 (insert (format "(ideographic-radical . %S)\t; %c%s"
760 (ideographic-radical radical)
762 (setq attributes (delq 'ideographic-radical attributes))
764 (when (and (memq 'shuowen-radical attributes)
765 (setq value (get-char-attribute char 'shuowen-radical)))
766 (insert (format "(shuowen-radical\t. %S)\t; %c%s"
768 (shuowen-radical value)
770 (setq attributes (delq 'shuowen-radical attributes))
775 char-db-feature-domains
777 (dolist (feature (char-attribute-list))
778 (setq feature (symbol-name feature))
780 "\\(radical\\|strokes\\)@\\([^@*]+\\)\\(\\*\\|$\\)"
782 (setq domain (intern (match-string 2 feature)))
783 (unless (memq domain dest)
784 (setq dest (cons domain dest)))))
785 (sort dest #'string<))))
786 (setq key (intern (format "%s@%s" 'ideographic-radical domain)))
787 (when (and (memq key attributes)
788 (setq value (get-char-attribute char key)))
790 (insert (format "(%s . %S)\t; %c%s"
793 (ideographic-radical radical)
795 (setq attributes (delq key attributes))
797 (setq key (intern (format "%s@%s" 'ideographic-strokes domain)))
798 (when (and (memq key attributes)
799 (setq value (get-char-attribute char key)))
801 (insert (format "(%s . %S)%s"
805 (setq attributes (delq key attributes))
807 (setq key (intern (format "%s@%s" 'total-strokes domain)))
808 (when (and (memq key attributes)
809 (setq value (get-char-attribute char key)))
810 (insert (format "(%s . %S)%s"
814 (setq attributes (delq key attributes))
816 (dolist (feature '(ideographic-radical
819 (setq key (intern (format "%s@%s*sources" feature domain)))
820 (when (and (memq key attributes)
821 (setq value (get-char-attribute char key)))
822 (insert (format "(%s%s" key line-breaking))
824 (insert (format " %s" cell)))
826 (insert line-breaking)
827 (setq attributes (delq key attributes))
830 (when (and (memq 'ideographic-strokes attributes)
831 (setq value (get-char-attribute char 'ideographic-strokes)))
833 (insert (format "(ideographic-strokes . %S)%s"
836 (setq attributes (delq 'ideographic-strokes attributes))
838 (when (and (memq 'kangxi-radical attributes)
839 (setq value (get-char-attribute char 'kangxi-radical)))
840 (unless (eq value radical)
841 (insert (format "(kangxi-radical\t . %S)\t; %c%s"
843 (ideographic-radical value)
846 (setq radical value)))
847 (setq attributes (delq 'kangxi-radical attributes))
849 (when (and (memq 'kangxi-strokes attributes)
850 (setq value (get-char-attribute char 'kangxi-strokes)))
851 (unless (eq value strokes)
852 (insert (format "(kangxi-strokes\t . %S)%s"
856 (setq strokes value)))
857 (setq attributes (delq 'kangxi-strokes attributes))
859 (when (and (memq 'japanese-radical attributes)
860 (setq value (get-char-attribute char 'japanese-radical)))
861 (unless (eq value radical)
862 (insert (format "(japanese-radical\t . %S)\t; %c%s"
864 (ideographic-radical value)
867 (setq radical value)))
868 (setq attributes (delq 'japanese-radical attributes))
870 (when (and (memq 'japanese-strokes attributes)
871 (setq value (get-char-attribute char 'japanese-strokes)))
872 (unless (eq value strokes)
873 (insert (format "(japanese-strokes\t . %S)%s"
877 (setq strokes value)))
878 (setq attributes (delq 'japanese-strokes attributes))
880 (when (and (memq 'cns-radical attributes)
881 (setq value (get-char-attribute char 'cns-radical)))
882 (insert (format "(cns-radical\t . %S)\t; %c%s"
884 (ideographic-radical value)
886 (setq attributes (delq 'cns-radical attributes))
888 (when (and (memq 'cns-strokes attributes)
889 (setq value (get-char-attribute char 'cns-strokes)))
890 (unless (eq value strokes)
891 (insert (format "(cns-strokes\t . %S)%s"
895 (setq strokes value)))
896 (setq attributes (delq 'cns-strokes attributes))
898 (when (and (memq 'shinjigen-1-radical attributes)
899 (setq value (get-char-attribute char 'shinjigen-1-radical)))
900 (unless (eq value radical)
901 (insert (format "(shinjigen-1-radical . %S)\t; %c%s"
903 (ideographic-radical value)
906 (setq radical value)))
907 (setq attributes (delq 'shinjigen-1-radical attributes))
909 (when (and (memq 'ideographic- attributes)
910 (setq value (get-char-attribute char 'ideographic-)))
911 (insert "(ideographic- ")
912 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
915 (setq cell (car value))
917 (setq cell (decode-char '=ucs cell)))
918 (cond ((characterp cell)
922 (insert (format "%S" cell))
923 (char-db-insert-char-spec cell readable))
924 (setq separator lbs))
928 (if (consp (car cell))
929 (char-db-insert-char-spec cell readable)
930 (char-db-insert-char-reference cell readable))
931 (setq separator lbs))
935 (insert (prin1-to-string cell))
936 (setq separator " ")))
937 (setq value (cdr value)))
939 (insert line-breaking)
940 (setq attributes (delq 'ideographic- attributes)))
941 (when (and (memq 'total-strokes attributes)
942 (setq value (get-char-attribute char 'total-strokes)))
943 (insert (format "(total-strokes . %S)%s"
946 (setq attributes (delq 'total-strokes attributes))
948 (when (and (memq '->ideograph attributes)
949 (setq value (get-char-attribute char '->ideograph)))
950 (insert (format "(->ideograph\t%s)%s"
951 (mapconcat (lambda (code)
952 (cond ((symbolp code)
955 (format "#x%04X" code))
958 line-breaking code))))
961 (setq attributes (delq '->ideograph attributes))
963 ;; (when (and (memq '->decomposition attributes)
964 ;; (setq value (get-char-attribute char '->decomposition)))
965 ;; (insert (format "(->decomposition\t%s)%s"
966 ;; (mapconcat (lambda (code)
967 ;; (cond ((symbolp code)
968 ;; (symbol-name code))
969 ;; ((characterp code)
971 ;; (format "%S" code)
976 ;; (format "#x%04X" code))
978 ;; (format "%s%S" line-breaking code))))
981 ;; (setq attributes (delq '->decomposition attributes))
983 (if (equal (get-char-attribute char '->titlecase)
984 (get-char-attribute char '->uppercase))
985 (setq attributes (delq '->titlecase attributes)))
986 (when (and (memq '->mojikyo attributes)
987 (setq value (get-char-attribute char '->mojikyo)))
988 (insert (format "(->mojikyo\t\t. %06d)\t; %c%s"
989 value (decode-char 'mojikyo value)
991 (setq attributes (delq '->mojikyo attributes))
993 (when (and (memq 'hanyu-dazidian-vol attributes)
994 (setq value (get-char-attribute char 'hanyu-dazidian-vol)))
995 (insert (format "(hanyu-dazidian-vol . %d)%s"
996 value line-breaking))
997 (setq attributes (delq 'hanyu-dazidian-vol attributes))
999 (when (and (memq 'hanyu-dazidian-page attributes)
1000 (setq value (get-char-attribute char 'hanyu-dazidian-page)))
1001 (insert (format "(hanyu-dazidian-page . %d)%s"
1002 value line-breaking))
1003 (setq attributes (delq 'hanyu-dazidian-page attributes))
1005 (when (and (memq 'hanyu-dazidian-char attributes)
1006 (setq value (get-char-attribute char 'hanyu-dazidian-char)))
1007 (insert (format "(hanyu-dazidian-char . %d)%s"
1008 value line-breaking))
1009 (setq attributes (delq 'hanyu-dazidian-char attributes))
1012 (dolist (ignored '(composition
1013 ->denotational <-subsumptive ->ucs-unified
1014 ->ideographic-component-forms))
1015 (setq attributes (delq ignored attributes))))
1017 (setq name (car attributes))
1018 (if (setq value (get-char-attribute char name))
1019 (cond ((setq ret (find-charset name))
1020 (setq name (charset-name ret))
1021 (if (and (not (memq name dest-ccss))
1023 (setq value (get-char-attribute char name))
1024 (setq dest-ccss (cons name dest-ccss))))
1025 (char-db-insert-ccs-feature name value line-breaking))
1027 ((string-match "^=>ucs@" (symbol-name name))
1028 (insert (format "(%-18s . #x%04X)\t; %c%s"
1029 name value (decode-char '=ucs value)
1032 ((eq name 'jisx0208-1978/4X)
1033 (insert (format "(%-18s . #x%04X)%s"
1039 (not (eq name '->subsumptive))
1040 (not (eq name '->uppercase))
1041 (not (eq name '->lowercase))
1042 (not (eq name '->titlecase))
1043 (not (eq name '->canonical))
1044 (not (eq name '->Bopomofo))
1045 (not (eq name '->mistakable))
1046 (not (eq name '->ideographic-variants))
1047 (null (get-char-attribute
1048 char (intern (format "%s*sources" name))))
1049 (not (string-match "\\*sources$" (symbol-name name)))
1050 (null (get-char-attribute
1051 char (intern (format "%s*note" name))))
1052 (not (string-match "\\*note$" (symbol-name name)))
1053 (or (eq name '<-identical)
1054 (eq name '<-uppercase)
1055 (eq name '<-lowercase)
1056 (eq name '<-titlecase)
1057 (eq name '<-canonical)
1058 (eq name '<-ideographic-variants)
1059 ;; (eq name '<-synonyms)
1060 (string-match "^<-synonyms" (symbol-name name))
1061 (eq name '<-mistakable)
1062 (when (string-match "^->" (symbol-name name))
1064 ((string-match "^->fullwidth" (symbol-name name))
1065 (not (and (consp value)
1066 (characterp (car value))
1068 (car value) '=ucs 'defined-only)))
1073 ((or (eq name 'ideographic-structure)
1074 (eq name 'ideographic-combination)
1075 (eq name 'ideographic-)
1076 (eq name '=decomposition)
1077 (string-match "^=>decomposition" (symbol-name name))
1078 (string-match "^\\(->\\|<-\\)[^*]*$" (symbol-name name))
1079 (string-match "^\\(->\\|<-\\)[^*]*\\*sources$"
1082 (char-db-insert-relation-feature char name value
1085 ((memq name '(ideograph=
1086 original-ideograph-of
1087 ancient-ideograph-of
1090 ;; simplified-ideograph-of
1091 ideographic-variants
1092 ;; ideographic-different-form-of
1094 (insert (format "(%-18s%s " name line-breaking))
1095 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1097 (while (consp value)
1098 (setq cell (car value))
1099 (if (and (consp cell)
1104 (char-db-insert-alist cell readable)
1105 (setq separator lbs))
1108 (insert (prin1-to-string cell))
1109 (setq separator " "))
1110 (setq value (cdr value)))
1112 (insert line-breaking))
1114 (insert (format "(%-18s " name))
1115 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1117 (while (consp value)
1118 (setq cell (car value))
1119 (if (and (consp cell)
1121 (setq ret (condition-case nil
1129 (setq key (car (car rest)))
1130 (if (find-charset key)
1131 (setq cal (cons key cal))
1132 (setq al (cons key al)))
1133 (setq rest (cdr rest)))
1136 (insert-char-attributes ret
1139 (setq separator lbs))
1140 (setq ret (prin1-to-string cell))
1142 (if (< (+ (current-column)
1149 (setq separator " "))
1150 (setq value (cdr value)))
1152 (insert line-breaking))
1154 (insert (format "(%-18s" name))
1155 (setq ret (prin1-to-string value))
1156 (unless (< (+ (current-column)
1160 (insert line-breaking))
1161 (insert " . " ret ")" line-breaking)
1162 ;; (insert (format "(%-18s . %S)%s"
1167 (setq attributes (cdr attributes)))
1170 (defun insert-char-data (char &optional readable
1173 (narrow-to-region (point)(point))
1174 (insert "(define-char
1176 (insert-char-attributes char readable attributes)
1178 (goto-char (point-min))
1179 (while (re-search-forward "[ \t]+$" nil t)
1182 (goto-char (point-min))
1183 (while (re-search-forward "[ \t][ \t][ \t]*" nil t)
1184 (let ((column (current-column))
1185 (indent-tabs-mode t))
1186 (delete-region (match-beginning 0) (point))
1187 (indent-to column)))
1188 (goto-char (point-max))
1189 ;; (tabify (point-min)(point-max))
1192 (defun insert-char-data-with-variant (char &optional printable
1194 script excluded-script)
1195 (insert-char-data char printable)
1196 (let ((variants (char-variants char))
1199 (setq variants (sort variants #'<))
1200 (setq rest variants)
1201 (setq variants (cons char variants))
1203 (setq variant (car rest))
1204 (unless (get-char-attribute variant '<-subsumptive)
1205 (if (and (or (null script)
1206 (null (setq vs (get-char-attribute variant 'script)))
1208 (or (null excluded-script)
1209 (null (setq vs (get-char-attribute variant 'script)))
1210 (not (memq excluded-script vs))))
1211 (unless (and no-ucs-unified (get-char-attribute variant '=ucs))
1212 (insert-char-data variant printable)
1213 (if (setq ret (char-variants variant))
1215 (or (memq (car ret) variants)
1216 ;; (get-char-attribute (car ret) '<-subsumptive)
1217 (setq rest (nconc rest (list (car ret)))))
1218 (setq ret (cdr ret)))))))
1219 (setq rest (cdr rest)))))
1221 (defun insert-char-range-data (min max &optional script excluded-script)
1224 (while (<= code max)
1225 (setq char (decode-char '=ucs code))
1226 (if (encode-char char '=ucs 'defined-only)
1227 (insert-char-data-with-variant char nil 'no-ucs-unified
1228 script excluded-script))
1229 (setq code (1+ code)))))
1231 (defun write-char-range-data-to-file (min max file
1232 &optional script excluded-script)
1233 (let ((coding-system-for-write char-db-file-coding-system))
1235 (insert (format ";; -*- coding: %s -*-\n"
1236 char-db-file-coding-system))
1237 (insert-char-range-data min max script excluded-script)
1238 (write-region (point-min)(point-max) file))))
1240 (defvar what-character-original-window-configuration)
1243 (defun what-char-definition (char)
1244 (interactive (list (char-after)))
1245 (let ((buf (get-buffer-create "*Character Description*"))
1246 (the-buf (current-buffer))
1247 (win-conf (current-window-configuration)))
1249 (make-local-variable 'what-character-original-window-configuration)
1250 (setq what-character-original-window-configuration win-conf)
1251 (setq buffer-read-only nil)
1255 (insert-char-data-with-variant char 'printable)
1256 (unless (char-attribute-alist char)
1257 (insert (format ";; = %c\n"
1258 (let* ((rest (split-char char))
1262 (setq code (logior (lsh code 8)
1264 (decode-char ccs code)))))
1265 ;; (char-db-update-comment)
1266 (set-buffer-modified-p nil)
1267 (view-mode the-buf (lambda (buf)
1268 (set-window-configuration
1269 what-character-original-window-configuration)
1271 (goto-char (point-min)))
1273 (set-window-configuration
1274 what-character-original-window-configuration)
1275 (signal (car err) (cdr err)))))))
1277 (provide 'char-db-util)
1279 ;;; char-db-util.el ends here