1 ;;; char-db-util.el --- Character Database utility -*- coding: utf-8-er; -*-
3 ;; Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006,
4 ;; 2007 MORIOKA Tomohiko.
6 ;; Author: MORIOKA Tomohiko <tomo@kanji.zinbun.kyoto-u.ac.jp>
7 ;; Keywords: CHISE, Character Database, ISO/IEC 10646, UCS, Unicode, MULE.
9 ;; This file is part of XEmacs CHISE.
11 ;; XEmacs CHISE is free software; you can redistribute it and/or
12 ;; modify it under the terms of the GNU General Public License as
13 ;; published by the Free Software Foundation; either version 2, or (at
14 ;; your option) any later version.
16 ;; XEmacs CHISE is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 ;; General Public License for more details.
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with XEmacs CHISE; see the file COPYING. If not, write to
23 ;; the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
24 ;; Boston, MA 02111-1307, USA.
30 (defconst unidata-normative-category-alist
31 '(("Lu" letter uppercase)
32 ("Ll" letter lowercase)
33 ("Lt" letter titlecase)
34 ("Mn" mark non-spacing)
35 ("Mc" mark spacing-combining)
37 ("Nd" number decimal-digit)
40 ("Zs" separator space)
42 ("Zp" separator paragraph)
45 ("Cs" other surrogate)
46 ("Co" other private-use)
47 ("Cn" other not-assigned)))
49 (defconst unidata-informative-category-alist
50 '(("Lm" letter modifier)
52 ("Pc" punctuation connector)
53 ("Pd" punctuation dash)
54 ("Ps" punctuation open)
55 ("Pe" punctuation close)
56 ("Pi" punctuation initial-quote)
57 ("Pf" punctuation final-quote)
58 ("Po" punctuation other)
60 ("Sc" symbol currency)
61 ("Sk" symbol modifier)
65 (defconst ideographic-radicals
66 (let ((v (make-vector 215 nil))
69 (aset v i (decode-char '=ucs (+ #x2EFF i)))
73 (defun ideographic-radical (number)
74 (aref ideographic-radicals number))
76 (defconst shuowen-radicals
77 [?一 ?上 ?示 ?三 ?王 ?玉 ?玨 ?气 ?士 ?丨
78 ?屮 ?艸 ?蓐 ?茻 ?小 ?八 ?釆 ?半 ?牛 ?犛
79 ?告 ?口 ?凵 ?吅 ?哭 ?走 ?止 ?癶 ?步 ?此
80 ?正 ?是 ?辵 ?彳 ?廴 ?𢓊 ?行 ?齒 ?牙 ?足
81 ?疋 ?品 ?龠 ?冊 ?㗊 ?舌 ?干 ?谷 ?只 ?㕯
82 ?句 ?丩 ?古 ?十 ?卅 ?言 ?誩 ?音 ?䇂 ?丵
83 ?菐 ?𠬞 ?廾 ?共 ?異 ?舁 ?𦥑 ?䢅 ?爨 ?革
84 ?鬲 ?䰜 ?爪 ?𠃨 ?鬥 ?又 ?𠂇 ?㕜 ?支 ?𦘒
85 ?聿 ?畫 ?隶 ?堅 ?臣 ?殳 ?殺 ?𠘧 ?寸 ?皮
86 ?㼱 ?攴 ?敎 ?卜 ?用 ?爻 ?㸚])
88 (defun shuowen-radical (number)
89 (aref shuowen-radicals (1- number)))
91 (defvar char-db-file-coding-system 'utf-8-mcs-er)
93 (defvar char-db-feature-domains
94 '(ucs ucs/compat daikanwa cns gt jis jis/alt jis/a jis/b
95 jis-x0212 jis-x0213 cdp shinjigen misc unknown))
97 (defvar char-db-ignored-attributes '(ideographic-products))
99 (defun char-attribute-name< (ka kb)
101 ((eq '->denotational kb)
103 ((eq '->subsumptive kb)
104 (not (eq '->denotational ka)))
105 ((eq '->denotational ka)
107 ((eq '->subsumptive ka)
110 (string-match "^->" (symbol-name ka)))
111 (cond ((and (symbolp kb)
112 (string-match "^->" (symbol-name kb)))
113 (string< (symbol-name ka)
118 (string-match "^->" (symbol-name kb)))
121 (string-match "^<-" (symbol-name ka)))
123 (cond ((string-match "^<-" (symbol-name kb))
124 (string< (symbol-name ka)
127 ;; ((string-match "^->" (symbol-name kb))
132 (string-match "^<-" (symbol-name kb)))
134 ;; (not (string-match "^->" (symbol-name ka)))
137 (if (find-charset kb)
138 (if (<= (charset-id ka) 1)
139 (if (<= (charset-id kb) 1)
141 ((= (charset-dimension ka)
142 (charset-dimension kb))
143 (> (charset-id ka)(charset-id kb)))
145 (> (charset-dimension ka)
146 (charset-dimension kb))
149 (if (<= (charset-id kb) 1)
151 (< (charset-id ka)(charset-id kb))))
157 (string< (symbol-name ka)
163 (defvar char-db-coded-charset-priority-list
224 (defun char-db-make-char-spec (char)
226 (cond ((characterp char)
227 (cond ((and (setq ret (encode-char char '=ucs 'defined-only))
228 (not (and (<= #xE000 ret)(<= ret #xF8FF))))
229 (setq char-spec (list (cons '=ucs ret)))
230 (cond ((setq ret (get-char-attribute char 'name))
231 (setq char-spec (cons (cons 'name ret) char-spec))
233 ((setq ret (get-char-attribute char 'name*))
234 (setq char-spec (cons (cons 'name* ret) char-spec))
239 (let ((rest char-db-coded-charset-priority-list)
242 (setq ccs (charset-name
243 (find-charset (car rest))))
245 (encode-char char ccs
247 (throw 'tag (cons ccs ret)))
248 (setq rest (cdr rest))))))
249 (setq char-spec (list ret))
250 (dolist (ccs (delq (car ret) (charset-list)))
251 (if (and (or (charset-iso-final-char ccs)
258 (setq ccs (charset-name ccs))
259 (null (assq ccs char-spec))
260 (setq ret (encode-char char ccs 'defined-only)))
261 (setq char-spec (cons (cons ccs ret) char-spec))))
263 (setq char-spec (split-char char)))
264 (cond ((setq ret (get-char-attribute char 'name))
265 (setq char-spec (cons (cons 'name ret) char-spec))
267 ((setq ret (get-char-attribute char 'name*))
268 (setq char-spec (cons (cons 'name* ret) char-spec))
275 (defun char-db-insert-char-spec (char &optional readable column
278 (setq column (current-column)))
279 (let (char-spec temp-char)
280 (setq char-spec (char-db-make-char-spec char))
281 (unless (or (characterp char) ; char
283 (setq char (find-char char-spec))
285 ;; define temporary character
286 ;; Current implementation is dirty.
287 (setq temp-char (define-char (cons '(ideograph-daikanwa . 0)
289 (remove-char-attribute temp-char 'ideograph-daikanwa)
290 (setq char temp-char))
291 (insert-char-attributes char
293 (union (mapcar #'car char-spec)
296 ;; undefine temporary character
297 ;; Current implementation is dirty.
298 (setq char-spec (char-attribute-alist temp-char))
300 (remove-char-attribute temp-char (car (car char-spec)))
301 (setq char-spec (cdr char-spec))))))
303 (defun char-db-insert-alist (alist &optional readable column)
305 (setq column (current-column)))
307 (concat "\n" (make-string (1+ column) ?\ )))
311 lbs cell rest separator)
314 (setq name (car (car alist))
315 value (cdr (car alist)))
316 (cond ((eq name 'char)
318 (if (setq ret (condition-case nil
326 (setq key (car (car value)))
327 ;; (if (find-charset key)
328 ;; (setq cal (cons key cal))
329 (setq al (cons key al))
331 (setq value (cdr value)))
332 (insert-char-attributes ret
336 (insert (prin1-to-string value)))
338 (insert line-breaking))
340 (insert (format "(%-18s " name))
341 (setq lbs (concat "\n" (make-string (current-column) ?\ )))
343 (setq cell (car value))
344 (if (and (consp cell)
346 (setq ret (condition-case nil
356 (setq key (car (car rest)))
357 ;; (if (find-charset key)
358 ;; (setq cal (cons key cal))
359 (setq al (cons key al))
361 (setq rest (cdr rest)))
364 (insert-char-attributes ret
368 (setq separator lbs))
371 (insert (prin1-to-string cell))
372 (setq separator " "))
373 (setq value (cdr value)))
375 (insert line-breaking))
377 (insert (format "(%-18s . %S)%s"
380 (setq alist (cdr alist))))
383 (defun char-db-insert-char-reference (plist &optional readable column)
385 (setq column (current-column)))
387 (concat "\n" (make-string (1+ column) ?\ )))
392 (setq name (pop plist))
393 (setq value (pop plist))
394 (cond ((eq name :char)
397 (cond ((numberp value)
398 (setq value (decode-char '=ucs value)))
400 ;; (setq value (or (find-char value)
403 (char-db-insert-char-spec value readable)
404 (insert line-breaking)
407 (insert (format "%s%s\t%d ; %c%s"
410 (ideographic-radical value)
414 (insert (format "%s%s\t%S" separator name value))
415 (setq separator line-breaking)))
419 (defun char-db-decode-isolated-char (ccs code-point)
422 (cond ((eq ccs 'arabic-iso8859-6)
423 (decode-char ccs code-point))
424 ((and (memq ccs '(=gt-pj-1
435 (setq ret (decode-char ccs code-point))
436 (setq ret (encode-char ret '=gt 'defined-only)))
437 (decode-builtin-char '=gt ret))
439 (decode-builtin-char ccs code-point))))
440 (cond ((and (<= 0 (char-int ret))
441 (<= (char-int ret) #x1F))
442 (decode-char '=ucs (+ #x2400 (char-int ret))))
443 ((= (char-int ret) #x7F)
447 (defvar char-db-convert-obsolete-format t)
449 (defun char-db-insert-ccs-feature (name value line-breaking)
452 (cond ((or (memq name '(=daikanwa
453 =daikanwa@rev1 =daikanwa@rev2
454 =gt =gt-k =cbeta =zinbun-oracle))
455 (string-match "^=adobe-" (symbol-name name)))
456 "(%-18s . %05d)\t; %c")
458 "(%-18s . %06d)\t; %c")
459 ((>= (charset-dimension name) 2)
460 "(%-18s . #x%04X)\t; %c")
462 "(%-18s . #x%02X)\t; %c"))
464 (if (= (charset-iso-graphic-plane name) 1)
466 (cond ((= (charset-dimension name) 1)
468 ((= (charset-dimension name) 2)
470 ((= (charset-dimension name) 3)
474 (char-db-decode-isolated-char name value)))
475 (if (and (= (charset-chars name) 94)
476 (= (charset-dimension name) 2))
477 (insert (format " [%02d-%02d]"
478 (- (lsh value -8) 32)
479 (- (logand value 255) 32))))
480 (insert line-breaking))
482 (defun char-db-insert-relation-feature (char name value line-breaking
484 (insert (format "(%-18s%s " name line-breaking))
485 (let ((lbs (concat "\n" (make-string (current-column) ?\ )))
486 separator cell sources required-features
489 (setq cell (car value))
491 (setq cell (decode-char '=ucs cell)))
493 ((eq name '->subsumptive)
494 (when (or (not (some (lambda (atr)
495 (get-char-attribute cell atr))
496 char-db-ignored-attributes))
498 (encode-char cell ccs 'defined-only))
502 (let ((char-db-ignored-attributes
504 char-db-ignored-attributes)))
505 (insert-char-attributes cell readable))
506 (setq separator lbs))
511 char (intern (format "%s*sources" name))))
512 (setq required-features nil)
513 (dolist (source sources)
515 ((memq source '(JP JP/Jouyou shinjigen-1))
516 (setq required-features
517 (union required-features
526 (setq required-features
527 (union required-features
532 ((find-charset (setq ret (intern (format "=%s" source))))
533 (setq required-features
534 (cons ret required-features)))
535 (t (setq required-features
536 (cons source required-features)))))
537 (cond ((string-match "@JP" (symbol-name name))
538 (setq required-features
539 (union required-features
547 ((string-match "@CN" (symbol-name name))
548 (setq required-features
549 (union required-features
556 (insert (format "%S" cell))
557 (char-db-insert-char-spec cell readable
560 (setq separator lbs))
564 (if (consp (car cell))
565 (char-db-insert-char-spec cell readable)
566 (char-db-insert-char-reference cell readable))
567 (setq separator lbs))
571 (insert (prin1-to-string cell))
572 (setq separator " ")))
573 (setq value (cdr value)))
575 (insert line-breaking)))
577 (defun insert-char-attributes (char &optional readable attributes column)
579 (setq column (current-column)))
580 (let (name value ; has-long-ccs-name
584 (concat "\n" (make-string (1+ column) ?\ )))
585 lbs cell separator ret
587 dest-ccss ; sources required-features
592 (if (consp attributes)
594 (dolist (name attributes)
595 (unless (memq name char-db-ignored-attributes)
596 (if (find-charset name)
600 (dolist (name (char-attribute-list))
601 (unless (memq name char-db-ignored-attributes)
602 (if (find-charset name)
606 #'char-attribute-name<)))
608 (when (memq '<-subsumptive attributes)
610 (when (setq value (get-char-attribute char '<-subsumptive))
611 (char-db-insert-relation-feature char '<-subsumptive value
614 (setq attributes (delq '<-subsumptive attributes)))
615 (when (and (memq '<-denotational attributes)
616 (setq value (get-char-attribute char '<-denotational)))
617 (char-db-insert-relation-feature char '<-denotational value
620 (setq attributes (delq '<-denotational 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 'name* attributes)
631 (setq value (get-char-attribute char 'name*)))
633 (if (> (+ (current-column) (length value)) 48)
636 value line-breaking))
637 (setq attributes (delq 'name* attributes))
639 (when (and (memq 'script attributes)
640 (setq value (get-char-attribute char 'script)))
641 (insert (format "(script\t\t%s)%s"
642 (mapconcat (function prin1-to-string)
645 (setq attributes (delq 'script attributes))
647 (dolist (name '(=>ucs =>ucs*))
648 (when (and (memq name attributes)
649 (setq value (get-char-attribute char name)))
650 (insert (format "(%-18s . #x%04X)\t; %c%s"
651 name value (decode-char '=ucs value)
653 (setq attributes (delq name attributes))))
654 (dolist (name '(=>ucs@gb =>ucs@cns =>ucs@jis =>ucs@ks =>ucs@big5))
655 (when (and (memq name attributes)
656 (setq value (get-char-attribute char name)))
657 (insert (format "(%-18s . #x%04X)\t; %c%s"
662 (symbol-name name) 2)))
665 (setq attributes (delq name attributes))
667 (dolist (name '(=>daikanwa))
668 (when (and (memq name attributes)
669 (setq value (get-char-attribute char name)))
672 (format "(%-18s . %05d)\t; %c%s"
673 name value (decode-char '=daikanwa value)
675 (format "(%-18s %s)\t; %c%s"
677 (mapconcat (function prin1-to-string)
679 (char-representative-of-daikanwa char)
681 (setq attributes (delq name attributes))))
682 (when (and (memq 'general-category attributes)
683 (setq value (get-char-attribute char 'general-category)))
685 "(general-category\t%s) ; %s%s"
686 (mapconcat (lambda (cell)
689 (cond ((rassoc value unidata-normative-category-alist)
690 "Normative Category")
691 ((rassoc value unidata-informative-category-alist)
692 "Informative Category")
696 (setq attributes (delq 'general-category attributes))
698 (when (and (memq 'bidi-category attributes)
699 (setq value (get-char-attribute char 'bidi-category)))
700 (insert (format "(bidi-category\t. %S)%s"
703 (setq attributes (delq 'bidi-category attributes))
705 (unless (or (not (memq 'mirrored attributes))
706 (eq (setq value (get-char-attribute char 'mirrored 'empty))
708 (insert (format "(mirrored\t\t. %S)%s"
711 (setq attributes (delq 'mirrored attributes))
714 ((and (memq 'decimal-digit-value attributes)
715 (setq value (get-char-attribute char 'decimal-digit-value)))
716 (insert (format "(decimal-digit-value . %S)%s"
719 (setq attributes (delq 'decimal-digit-value attributes))
720 (when (and (memq 'digit-value attributes)
721 (setq value (get-char-attribute char 'digit-value)))
722 (insert (format "(digit-value\t . %S)%s"
725 (setq attributes (delq 'digit-value attributes))
727 (when (and (memq 'numeric-value attributes)
728 (setq value (get-char-attribute char 'numeric-value)))
729 (insert (format "(numeric-value\t . %S)%s"
732 (setq attributes (delq 'numeric-value attributes))
736 (when (and (memq 'digit-value attributes)
737 (setq value (get-char-attribute char 'digit-value)))
738 (insert (format "(digit-value\t. %S)%s"
741 (setq attributes (delq 'digit-value attributes))
743 (when (and (memq 'numeric-value attributes)
744 (setq value (get-char-attribute char 'numeric-value)))
745 (insert (format "(numeric-value\t. %S)%s"
748 (setq attributes (delq 'numeric-value attributes))
750 (when (and (memq 'iso-10646-comment attributes)
751 (setq value (get-char-attribute char 'iso-10646-comment)))
752 (insert (format "(iso-10646-comment\t. %S)%s"
755 (setq attributes (delq 'iso-10646-comment attributes))
757 (when (and (memq 'morohashi-daikanwa attributes)
758 (setq value (get-char-attribute char 'morohashi-daikanwa)))
759 (insert (format "(morohashi-daikanwa\t%s)%s"
760 (mapconcat (function prin1-to-string) value " ")
762 (setq attributes (delq 'morohashi-daikanwa attributes))
766 (when (and (memq 'ideographic-radical attributes)
767 (setq value (get-char-attribute char 'ideographic-radical)))
769 (insert (format "(ideographic-radical . %S)\t; %c%s"
771 (ideographic-radical radical)
773 (setq attributes (delq 'ideographic-radical attributes))
775 (when (and (memq 'shuowen-radical attributes)
776 (setq value (get-char-attribute char 'shuowen-radical)))
777 (insert (format "(shuowen-radical\t. %S)\t; %c%s"
779 (shuowen-radical value)
781 (setq attributes (delq 'shuowen-radical attributes))
786 char-db-feature-domains
788 (dolist (feature (char-attribute-list))
789 (setq feature (symbol-name feature))
791 "\\(radical\\|strokes\\)@\\([^@*]+\\)\\(\\*\\|$\\)"
793 (setq domain (intern (match-string 2 feature)))
794 (unless (memq domain dest)
795 (setq dest (cons domain dest)))))
796 (sort dest #'string<))))
797 (setq key (intern (format "%s@%s" 'ideographic-radical domain)))
798 (when (and (memq key attributes)
799 (setq value (get-char-attribute char key)))
801 (insert (format "(%s . %S)\t; %c%s"
804 (ideographic-radical radical)
806 (setq attributes (delq key attributes))
808 (setq key (intern (format "%s@%s" 'ideographic-strokes domain)))
809 (when (and (memq key attributes)
810 (setq value (get-char-attribute char key)))
812 (insert (format "(%s . %S)%s"
816 (setq attributes (delq key attributes))
818 (setq key (intern (format "%s@%s" 'total-strokes domain)))
819 (when (and (memq key attributes)
820 (setq value (get-char-attribute char key)))
821 (insert (format "(%s . %S)%s"
825 (setq attributes (delq key attributes))
827 (dolist (feature '(ideographic-radical
830 (setq key (intern (format "%s@%s*sources" feature domain)))
831 (when (and (memq key attributes)
832 (setq value (get-char-attribute char key)))
833 (insert (format "(%s%s" key line-breaking))
835 (insert (format " %s" cell)))
837 (insert line-breaking)
838 (setq attributes (delq key attributes))
841 (when (and (memq 'ideographic-strokes attributes)
842 (setq value (get-char-attribute char 'ideographic-strokes)))
844 (insert (format "(ideographic-strokes . %S)%s"
847 (setq attributes (delq 'ideographic-strokes attributes))
849 (when (and (memq 'kangxi-radical attributes)
850 (setq value (get-char-attribute char 'kangxi-radical)))
851 (unless (eq value radical)
852 (insert (format "(kangxi-radical\t . %S)\t; %c%s"
854 (ideographic-radical value)
857 (setq radical value)))
858 (setq attributes (delq 'kangxi-radical attributes))
860 (when (and (memq 'kangxi-strokes attributes)
861 (setq value (get-char-attribute char 'kangxi-strokes)))
862 (unless (eq value strokes)
863 (insert (format "(kangxi-strokes\t . %S)%s"
867 (setq strokes value)))
868 (setq attributes (delq 'kangxi-strokes attributes))
870 (when (and (memq 'japanese-radical attributes)
871 (setq value (get-char-attribute char 'japanese-radical)))
872 (unless (eq value radical)
873 (insert (format "(japanese-radical\t . %S)\t; %c%s"
875 (ideographic-radical value)
878 (setq radical value)))
879 (setq attributes (delq 'japanese-radical attributes))
881 (when (and (memq 'japanese-strokes attributes)
882 (setq value (get-char-attribute char 'japanese-strokes)))
883 (unless (eq value strokes)
884 (insert (format "(japanese-strokes\t . %S)%s"
888 (setq strokes value)))
889 (setq attributes (delq 'japanese-strokes attributes))
891 (when (and (memq 'cns-radical attributes)
892 (setq value (get-char-attribute char 'cns-radical)))
893 (insert (format "(cns-radical\t . %S)\t; %c%s"
895 (ideographic-radical value)
897 (setq attributes (delq 'cns-radical attributes))
899 (when (and (memq 'cns-strokes attributes)
900 (setq value (get-char-attribute char 'cns-strokes)))
901 (unless (eq value strokes)
902 (insert (format "(cns-strokes\t . %S)%s"
906 (setq strokes value)))
907 (setq attributes (delq 'cns-strokes attributes))
909 (when (and (memq 'shinjigen-1-radical attributes)
910 (setq value (get-char-attribute char 'shinjigen-1-radical)))
911 (unless (eq value radical)
912 (insert (format "(shinjigen-1-radical . %S)\t; %c%s"
914 (ideographic-radical value)
917 (setq radical value)))
918 (setq attributes (delq 'shinjigen-1-radical attributes))
920 (when (and (memq 'ideographic- attributes)
921 (setq value (get-char-attribute char 'ideographic-)))
922 (insert "(ideographic- ")
923 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
926 (setq cell (car value))
928 (setq cell (decode-char '=ucs cell)))
929 (cond ((characterp cell)
933 (insert (format "%S" cell))
934 (char-db-insert-char-spec cell readable))
935 (setq separator lbs))
939 (if (consp (car cell))
940 (char-db-insert-char-spec cell readable)
941 (char-db-insert-char-reference cell readable))
942 (setq separator lbs))
946 (insert (prin1-to-string cell))
947 (setq separator " ")))
948 (setq value (cdr value)))
950 (insert line-breaking)
951 (setq attributes (delq 'ideographic- attributes)))
952 (when (and (memq 'total-strokes attributes)
953 (setq value (get-char-attribute char 'total-strokes)))
954 (insert (format "(total-strokes . %S)%s"
957 (setq attributes (delq 'total-strokes attributes))
959 (when (and (memq '->ideograph attributes)
960 (setq value (get-char-attribute char '->ideograph)))
961 (insert (format "(->ideograph\t%s)%s"
962 (mapconcat (lambda (code)
963 (cond ((symbolp code)
966 (format "#x%04X" code))
969 line-breaking code))))
972 (setq attributes (delq '->ideograph attributes))
974 ;; (when (and (memq '->decomposition attributes)
975 ;; (setq value (get-char-attribute char '->decomposition)))
976 ;; (insert (format "(->decomposition\t%s)%s"
977 ;; (mapconcat (lambda (code)
978 ;; (cond ((symbolp code)
979 ;; (symbol-name code))
980 ;; ((characterp code)
982 ;; (format "%S" code)
987 ;; (format "#x%04X" code))
989 ;; (format "%s%S" line-breaking code))))
992 ;; (setq attributes (delq '->decomposition attributes))
994 (if (equal (get-char-attribute char '->titlecase)
995 (get-char-attribute char '->uppercase))
996 (setq attributes (delq '->titlecase attributes)))
997 (when (and (memq '->mojikyo attributes)
998 (setq value (get-char-attribute char '->mojikyo)))
999 (insert (format "(->mojikyo\t\t. %06d)\t; %c%s"
1000 value (decode-char 'mojikyo value)
1002 (setq attributes (delq '->mojikyo attributes))
1004 (when (and (memq 'hanyu-dazidian-vol attributes)
1005 (setq value (get-char-attribute char 'hanyu-dazidian-vol)))
1006 (insert (format "(hanyu-dazidian-vol . %d)%s"
1007 value line-breaking))
1008 (setq attributes (delq 'hanyu-dazidian-vol attributes))
1010 (when (and (memq 'hanyu-dazidian-page attributes)
1011 (setq value (get-char-attribute char 'hanyu-dazidian-page)))
1012 (insert (format "(hanyu-dazidian-page . %d)%s"
1013 value line-breaking))
1014 (setq attributes (delq 'hanyu-dazidian-page attributes))
1016 (when (and (memq 'hanyu-dazidian-char attributes)
1017 (setq value (get-char-attribute char 'hanyu-dazidian-char)))
1018 (insert (format "(hanyu-dazidian-char . %d)%s"
1019 value line-breaking))
1020 (setq attributes (delq 'hanyu-dazidian-char attributes))
1023 (dolist (ignored '(composition
1024 ->denotational <-subsumptive ->ucs-unified
1025 ->ideographic-component-forms))
1026 (setq attributes (delq ignored attributes))))
1028 (setq name (car attributes))
1029 (if (setq value (get-char-attribute char name))
1030 (cond ((setq ret (find-charset name))
1031 (setq name (charset-name ret))
1032 (if (and (not (memq name dest-ccss))
1034 (setq value (get-char-attribute char name))
1035 (setq dest-ccss (cons name dest-ccss))))
1036 (char-db-insert-ccs-feature name value line-breaking))
1038 ((string-match "^=>ucs@" (symbol-name name))
1039 (insert (format "(%-18s . #x%04X)\t; %c%s"
1040 name value (decode-char '=ucs value)
1043 ((eq name 'jisx0208-1978/4X)
1044 (insert (format "(%-18s . #x%04X)%s"
1050 (not (eq name '->subsumptive))
1051 (not (eq name '->uppercase))
1052 (not (eq name '->lowercase))
1053 (not (eq name '->titlecase))
1054 (not (eq name '->canonical))
1055 (not (eq name '->Bopomofo))
1056 (not (eq name '->mistakable))
1057 (not (eq name '->ideographic-variants))
1058 (null (get-char-attribute
1059 char (intern (format "%s*sources" name))))
1060 (not (string-match "\\*sources$" (symbol-name name)))
1061 (null (get-char-attribute
1062 char (intern (format "%s*note" name))))
1063 (not (string-match "\\*note$" (symbol-name name)))
1064 (or (eq name '<-identical)
1065 (eq name '<-uppercase)
1066 (eq name '<-lowercase)
1067 (eq name '<-titlecase)
1068 (eq name '<-canonical)
1069 (eq name '<-ideographic-variants)
1070 ;; (eq name '<-synonyms)
1071 (string-match "^<-synonyms" (symbol-name name))
1072 (eq name '<-mistakable)
1073 (when (string-match "^->" (symbol-name name))
1075 ((string-match "^->fullwidth" (symbol-name name))
1076 (not (and (consp value)
1077 (characterp (car value))
1079 (car value) '=ucs 'defined-only)))
1084 ((or (eq name 'ideographic-structure)
1085 (eq name 'ideographic-combination)
1086 (eq name 'ideographic-)
1087 (eq name '=decomposition)
1088 (string-match "^=>decomposition" (symbol-name name))
1089 (string-match "^\\(->\\|<-\\)[^*]*$" (symbol-name name))
1090 (string-match "^\\(->\\|<-\\)[^*]*\\*sources$"
1093 (char-db-insert-relation-feature char name value
1096 ((memq name '(ideograph=
1097 original-ideograph-of
1098 ancient-ideograph-of
1101 ;; simplified-ideograph-of
1102 ideographic-variants
1103 ;; ideographic-different-form-of
1105 (insert (format "(%-18s%s " name line-breaking))
1106 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1108 (while (consp value)
1109 (setq cell (car value))
1110 (if (and (consp cell)
1115 (char-db-insert-alist cell readable)
1116 (setq separator lbs))
1119 (insert (prin1-to-string cell))
1120 (setq separator " "))
1121 (setq value (cdr value)))
1123 (insert line-breaking))
1125 (insert (format "(%-18s " name))
1126 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1128 (while (consp value)
1129 (setq cell (car value))
1130 (if (and (consp cell)
1132 (setq ret (condition-case nil
1140 (setq key (car (car rest)))
1141 (if (find-charset key)
1142 (setq cal (cons key cal))
1143 (setq al (cons key al)))
1144 (setq rest (cdr rest)))
1147 (insert-char-attributes ret
1150 (setq separator lbs))
1151 (setq ret (prin1-to-string cell))
1153 (if (< (+ (current-column)
1160 (setq separator " "))
1161 (setq value (cdr value)))
1163 (insert line-breaking))
1165 (insert (format "(%-18s" name))
1166 (setq ret (prin1-to-string value))
1167 (unless (< (+ (current-column)
1171 (insert line-breaking))
1172 (insert " . " ret ")" line-breaking)
1173 ;; (insert (format "(%-18s . %S)%s"
1178 (setq attributes (cdr attributes)))
1181 (defun insert-char-data (char &optional readable
1184 (narrow-to-region (point)(point))
1185 (insert "(define-char
1187 (insert-char-attributes char readable attributes)
1189 (goto-char (point-min))
1190 (while (re-search-forward "[ \t]+$" nil t)
1193 (goto-char (point-min))
1194 (while (re-search-forward "[ \t][ \t][ \t]*" nil t)
1195 (let ((column (current-column))
1196 (indent-tabs-mode t))
1197 (delete-region (match-beginning 0) (point))
1198 (indent-to column)))
1199 (goto-char (point-max))
1200 ;; (tabify (point-min)(point-max))
1203 (defun insert-char-data-with-variant (char &optional printable
1205 script excluded-script)
1206 (insert-char-data char printable)
1207 (let ((variants (char-variants char))
1210 (setq variants (sort variants #'<))
1211 (setq rest variants)
1212 (setq variants (cons char variants))
1214 (setq variant (car rest))
1215 (unless (get-char-attribute variant '<-subsumptive)
1216 (if (and (or (null script)
1217 (null (setq vs (get-char-attribute variant 'script)))
1219 (or (null excluded-script)
1220 (null (setq vs (get-char-attribute variant 'script)))
1221 (not (memq excluded-script vs))))
1222 (unless (and no-ucs-unified (get-char-attribute variant '=ucs))
1223 (insert-char-data variant printable)
1224 (if (setq ret (char-variants variant))
1226 (or (memq (car ret) variants)
1227 ;; (get-char-attribute (car ret) '<-subsumptive)
1228 (setq rest (nconc rest (list (car ret)))))
1229 (setq ret (cdr ret)))))))
1230 (setq rest (cdr rest)))))
1232 (defun insert-char-range-data (min max &optional script excluded-script)
1235 (while (<= code max)
1236 (setq char (decode-char '=ucs code))
1237 (if (encode-char char '=ucs 'defined-only)
1238 (insert-char-data-with-variant char nil 'no-ucs-unified
1239 script excluded-script))
1240 (setq code (1+ code)))))
1242 (defun write-char-range-data-to-file (min max file
1243 &optional script excluded-script)
1244 (let ((coding-system-for-write char-db-file-coding-system))
1246 (insert (format ";; -*- coding: %s -*-\n"
1247 char-db-file-coding-system))
1248 (insert-char-range-data min max script excluded-script)
1249 (write-region (point-min)(point-max) file))))
1251 (defvar what-character-original-window-configuration)
1254 (defun what-char-definition (char)
1255 (interactive (list (char-after)))
1256 (let ((buf (get-buffer-create "*Character Description*"))
1257 (the-buf (current-buffer))
1258 (win-conf (current-window-configuration)))
1260 (make-local-variable 'what-character-original-window-configuration)
1261 (setq what-character-original-window-configuration win-conf)
1262 (setq buffer-read-only nil)
1266 (insert-char-data-with-variant char 'printable)
1267 (unless (char-attribute-alist char)
1268 (insert (format ";; = %c\n"
1269 (let* ((rest (split-char char))
1273 (setq code (logior (lsh code 8)
1275 (decode-char ccs code)))))
1276 ;; (char-db-update-comment)
1277 (set-buffer-modified-p nil)
1278 (view-mode the-buf (lambda (buf)
1279 (set-window-configuration
1280 what-character-original-window-configuration)
1282 (goto-char (point-min)))
1284 (set-window-configuration
1285 what-character-original-window-configuration)
1286 (signal (car err) (cdr err)))))))
1288 (provide 'char-db-util)
1290 ;;; char-db-util.el ends here