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, 2008, 2009, 2010, 2011 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.
29 (require 'ideograph-subr)
31 (defconst unidata-normative-category-alist
32 '(("Lu" letter uppercase)
33 ("Ll" letter lowercase)
34 ("Lt" letter titlecase)
35 ("Mn" mark non-spacing)
36 ("Mc" mark spacing-combining)
38 ("Nd" number decimal-digit)
41 ("Zs" separator space)
43 ("Zp" separator paragraph)
46 ("Cs" other surrogate)
47 ("Co" other private-use)
48 ("Cn" other not-assigned)))
50 (defconst unidata-informative-category-alist
51 '(("Lm" letter modifier)
53 ("Pc" punctuation connector)
54 ("Pd" punctuation dash)
55 ("Ps" punctuation open)
56 ("Pe" punctuation close)
57 ("Pi" punctuation initial-quote)
58 ("Pf" punctuation final-quote)
59 ("Po" punctuation other)
61 ("Sc" symbol currency)
62 ("Sk" symbol modifier)
66 (defconst shuowen-radicals
67 [?一 ?上 ?示 ?三 ?王 ?玉 ?玨 ?气 ?士 ?丨 ; 010
68 ?屮 ?艸 ?蓐 ?茻 ?小 ?八 ?釆 ?半 ?牛 ?犛 ; 020
69 ?告 ?口 ?凵 ?吅 ?哭 ?走 ?止 ?癶 ?步 ?此 ; 030
70 ?正 ?是 ?辵 ?彳 ?廴 ?㢟 ?行 ?齒 ?牙 ?足 ; 040
71 ?疋 ?品 ?龠 ?冊 ?㗊 ?舌 ?干 ?谷 ?只 ?㕯 ; 050
72 ?句 ?丩 ?古 ?十 ?卅 ?言 ?誩 ?音 ?䇂 ?丵 ; 060
73 ?菐 ?𠬞 ?𠬜 ?共 ?異 ?舁 ?𦥑 ?䢅 ?爨 ?革 ; 070
74 ?鬲 ?䰜 ?爪 ?𠃨 ?鬥 ?又 ?𠂇 ?㕜 ?支 ?𦘒 ; 080
75 ?聿 ?畫 ?隶 ?臤 ?臣 ?殳 ?殺 ?𠘧 ?寸 ?皮 ; 090
76 ?㼱 ?攴 ?敎 ?卜 ?用 ?爻 ?㸚 ?𥄎 ?目 ?䀠 ; 100
77 ?眉 ?盾 ?自 ?白 ?鼻 ?皕 ?習 ?羽 ?隹 ?奞 ; 110
78 ?萑 ?𦫳 ?苜 ?羊 ?羴 ?瞿 ?雔 ?雥 ?鳥 ?烏 ; 120
79 ?𠦒 ?冓 ?幺 ?𢆶 ?叀 ?玄 ?予 ?放 ?𠬪 ?𣦼 ; 130
80 ?歺 ?死 ?冎 ?骨 ?肉 ?筋 ?刀 ?刃 ?㓞 ?丰 ; 140
81 ?耒 ?𧢲 ?竹 ?箕 ?丌 ?左 ?工 ?㠭 ?巫 ?甘 ; 150
82 ?旨 ?曰 ?乃 ?丂 ?可 ?兮 ?号 ?亏 ?喜 ?壴 ; 160
83 ?鼓 ?豈 ?豆 ?豊 ?豐 ?䖒 ?虍 ?虎 ?虤 ?皿 ; 170
84 ?𠙴 ?去 ?血 ?丶 ?丹 ?青 ?井 ?皀 ?鬯 ?食 ; 180
85 ?亼 ?會 ?倉 ?入 ?缶 ?矢 ?高 ?冂 ?𩫏 ?京 ; 190
86 ?亯 ?𣆪 ?畗 ?㐭 ?嗇 ?來 ?麥 ?夊 ?舛 ?䑞 ; 200
87 ?韋 ?弟 ?夂 ?久 ?桀 ?木 ?東 ?林 ?才 ?叒 ; 210
88 ?之 ?帀 ?出 ?𣎵 ?生 ?乇 ?𠂹 ?𠌶 ?華 ?𥝌 ; 220
89 ?稽 ?巢 ?桼 ?束 ?㯻 ?囗 ?員 ?貝 ?邑 ?𨛜 ; 230
90 ?日 ?旦 ?倝 ?㫃 ?冥 ?晶 ?月 ?有 ?明 ?囧 ; 240
91 ?夕 ?多 ?毌 ?𢎘 ?𣐺 ?卣 ?齊 ?朿 ?片 ?鼎 ; 250
92 ?克 ?彔 ?禾 ?秝 ?黍 ?香 ?米 ?毇 ?臼 ?凶 ; 260
93 ?𣎳 ?林 ?麻 ?尗 ?耑 ?韭 ?瓜 ?瓠 ?宀 ?宮 ; 270
94 ?呂 ?穴 ?㝱 ?𤕫 ?冖 ?𠔼 ?冃 ?㒳 ?网 ?襾 ; 280
95 ?巾 ?巿 ?帛 ?白 ?㡀 ?黹 ?人 ?𠤎 ?匕 ?从 ; 290
98 (defun shuowen-radical (number)
99 (aref shuowen-radicals (1- number)))
101 (defvar char-db-file-coding-system 'utf-8-mcs-er)
103 (defvar char-db-ignored-attributes '(ideographic-products))
105 (defvar char-db-coded-charset-priority-list
237 ;;; @ char-db formatters
240 (defun char-db-make-char-spec (char)
242 (cond ((characterp char)
243 (cond ((and (setq ret (encode-char char '=ucs 'defined-only))
244 (not (and (<= #xE000 ret)(<= ret #xF8FF))))
245 (setq char-spec (list (cons '=ucs ret)))
246 (cond ((setq ret (get-char-attribute char 'name))
247 (setq char-spec (cons (cons 'name ret) char-spec))
249 ((setq ret (get-char-attribute char 'name*))
250 (setq char-spec (cons (cons 'name* ret) char-spec))
255 (let ((rest char-db-coded-charset-priority-list)
258 (setq ccs (charset-name
259 (find-charset (car rest))))
261 (encode-char char ccs
263 (throw 'tag (cons ccs ret)))
264 (setq rest (cdr rest))))))
265 (setq char-spec (list ret))
266 (dolist (ccs (delq (car ret) (charset-list)))
267 (if (and (or (charset-iso-final-char ccs)
274 (string-match "=ucs@" (symbol-name ccs)))
275 (setq ccs (charset-name ccs))
276 (null (assq ccs char-spec))
277 (setq ret (encode-char char ccs 'defined-only)))
278 (setq char-spec (cons (cons ccs ret) char-spec))))
280 (setq char-spec (split-char char)))
281 (cond ((setq ret (get-char-attribute char 'name))
282 (setq char-spec (cons (cons 'name ret) char-spec))
284 ((setq ret (get-char-attribute char 'name*))
285 (setq char-spec (cons (cons 'name* ret) char-spec))
288 ((setq ret (get-char-attribute
289 char 'ideographic-combination))
291 (cons (cons 'ideographic-combination ret)
298 (defun char-db-insert-char-spec (char &optional readable column
301 (setq column (current-column)))
302 (let (char-spec temp-char)
303 (setq char-spec (char-db-make-char-spec char))
304 (unless (or (characterp char) ; char
306 (setq char (find-char char-spec))
308 ;; define temporary character
309 ;; Current implementation is dirty.
310 (setq temp-char (define-char (cons '(ideograph-daikanwa . 0)
312 (remove-char-attribute temp-char 'ideograph-daikanwa)
313 (setq char temp-char))
314 (insert-char-attributes char
316 (union (mapcar #'car char-spec)
320 ;; undefine temporary character
321 ;; Current implementation is dirty.
322 (setq char-spec (char-attribute-alist temp-char))
324 (remove-char-attribute temp-char (car (car char-spec)))
325 (setq char-spec (cdr char-spec))))))
327 (defun char-db-insert-alist (alist &optional readable column)
329 (setq column (current-column)))
331 (concat "\n" (make-string (1+ column) ?\ )))
335 lbs cell rest separator)
338 (setq name (car (car alist))
339 value (cdr (car alist)))
340 (cond ((eq name 'char)
342 (if (setq ret (condition-case nil
350 (setq key (car (car value)))
351 ;; (if (find-charset key)
352 ;; (setq cal (cons key cal))
353 (setq al (cons key al))
355 (setq value (cdr value)))
356 (insert-char-attributes ret
360 (insert (prin1-to-string value)))
362 (insert line-breaking))
364 (insert (format "(%-18s " name))
365 (setq lbs (concat "\n" (make-string (current-column) ?\ )))
367 (setq cell (car value))
368 (if (and (consp cell)
370 (setq ret (condition-case nil
380 (setq key (car (car rest)))
381 ;; (if (find-charset key)
382 ;; (setq cal (cons key cal))
383 (setq al (cons key al))
385 (setq rest (cdr rest)))
388 (insert-char-attributes ret
392 (setq separator lbs))
395 (insert (prin1-to-string cell))
396 (setq separator " "))
397 (setq value (cdr value)))
399 (insert line-breaking))
401 (insert (format "(%-18s . %S)%s"
404 (setq alist (cdr alist))))
407 (defun char-db-insert-char-reference (plist &optional readable column)
409 (setq column (current-column)))
411 (concat "\n" (make-string (1+ column) ?\ )))
416 (setq name (pop plist))
417 (setq value (pop plist))
418 (cond ((eq name :char)
421 (cond ((numberp value)
422 (setq value (decode-char '=ucs value)))
424 ;; (setq value (or (find-char value)
427 (char-db-insert-char-spec value readable)
428 (insert line-breaking)
431 (insert (format "%s%s\t%d ; %c%s"
434 (ideographic-radical value)
438 (insert (format "%s%s\t%S" separator name value))
439 (setq separator line-breaking)))
443 (defun char-db-decode-isolated-char (ccs code-point)
446 (cond ((eq ccs 'arabic-iso8859-6)
447 (decode-char ccs code-point))
448 ((and (memq ccs '(=gt-pj-1
459 (setq ret (decode-char ccs code-point))
460 (setq ret (encode-char ret '=gt 'defined-only)))
461 (decode-builtin-char '=gt ret))
463 (decode-builtin-char ccs code-point))))
464 (cond ((and (<= 0 (char-int ret))
465 (<= (char-int ret) #x1F))
466 (decode-char '=ucs (+ #x2400 (char-int ret))))
467 ((= (char-int ret) #x7F)
471 (defvar char-db-convert-obsolete-format t)
473 (defun char-db-insert-ccs-feature (name value line-breaking)
479 ((memq name '(=shinjigen
481 =shinjigen@rev =shinjigen/+p@rev
483 "(%-18s . %04d)\t; %c")
484 ((eq name '=shinjigen@1ed/24pr)
485 "(%-18s . %04d)\t; %c")
486 ((or (memq name '(=daikanwa =>>daikanwa =>daikanwa
487 =daikanwa@rev1 =daikanwa@rev2
488 =daikanwa/+p =daikanwa/+2p
489 =gt =>>>gt =>>gt =+>gt =>gt
491 =adobe-japan1-0 =adobe-japan1-1 =adobe-japan1-2
492 =adobe-japan1-3 =adobe-japan1-4 =adobe-japan1-5
493 =adobe-japan1-6 =>>>adobe-japan1 =>>adobe-japan1
496 =zinbun-oracle =>zinbun-oracle))
497 ;; (string-match "^=adobe-" (symbol-name name))
499 "(%-18s . %05d)\t; %c")
500 ((memq name '(=hanyo-denshi/ks =>>hanyo-denshi/ks mojikyo))
501 "(%-18s . %06d)\t; %c")
502 ((>= (charset-dimension name) 2)
503 "(%-18s . #x%04X)\t; %c")
505 "(%-18s . #x%02X)\t; %c"))
507 (if (= (charset-iso-graphic-plane name) 1)
509 (cond ((= (charset-dimension name) 1)
511 ((= (charset-dimension name) 2)
513 ((= (charset-dimension name) 3)
517 (char-db-decode-isolated-char name value)))
518 (if (and (= (charset-chars name) 94)
519 (= (charset-dimension name) 2))
520 (insert (format " [%02d-%02d]"
521 (- (lsh value -8) 32)
522 (- (logand value 255) 32))))
525 (insert (format "(%-18s . %s)" name value))
527 (insert line-breaking))
529 (defun char-db-insert-relation-feature (char name value line-breaking
531 (insert (format "(%-18s%s " name line-breaking))
532 (let ((lbs (concat "\n" (make-string (current-column) ?\ )))
533 separator cell sources required-features
536 (setq cell (car value))
538 (setq cell (decode-char '=ucs cell)))
540 ((eq name '->subsumptive)
541 (when (or (not (some (lambda (atr)
542 (get-char-attribute cell atr))
543 char-db-ignored-attributes))
545 (encode-char cell ccs 'defined-only))
549 (let ((char-db-ignored-attributes
551 char-db-ignored-attributes)))
552 (insert-char-attributes cell readable nil nil 'for-sub-node))
553 (setq separator lbs))
558 char (intern (format "%s*sources" name))))
559 (setq required-features nil)
560 (dolist (source sources)
564 shinjigen shinjigen@1ed shinjigen@rev))
565 (setq required-features
566 (union required-features
577 (setq required-features
578 (union required-features
583 ((find-charset (setq ret (intern (format "=%s" source))))
584 (setq required-features
585 (cons ret required-features)))
586 (t (setq required-features
587 (cons source required-features)))))
588 (cond ((string-match "@JP" (symbol-name name))
589 (setq required-features
590 (union required-features
598 ((string-match "@CN" (symbol-name name))
599 (setq required-features
600 (union required-features
607 (insert (format "%S" cell))
608 (char-db-insert-char-spec cell readable
611 (setq separator lbs))
615 (if (consp (car cell))
616 (char-db-insert-char-spec cell readable)
617 (char-db-insert-char-reference cell readable))
618 (setq separator lbs))
622 (insert (prin1-to-string cell))
623 (setq separator " ")))
624 (setq value (cdr value)))
626 (insert line-breaking)))
628 (defun insert-char-attributes (char &optional readable attributes column
631 (setq column (current-column)))
632 (let (name value ; has-long-ccs-name
636 (concat "\n" (make-string (1+ column) ?\ )))
637 lbs cell separator ret
639 dest-ccss ; sources required-features
644 (if (consp attributes)
646 (dolist (name attributes)
647 (unless (memq name char-db-ignored-attributes)
648 (if (find-charset name)
652 (dolist (name (char-attribute-list))
653 (unless (memq name char-db-ignored-attributes)
654 (if (find-charset name)
658 #'char-attribute-name<)))
660 (when (memq '<-subsumptive attributes)
661 (when (or readable (not for-sub-node))
662 (when (setq value (get-char-attribute char '<-subsumptive))
663 (char-db-insert-relation-feature char '<-subsumptive value
666 (setq attributes (delq '<-subsumptive attributes)))
667 (when (and (memq '<-denotational attributes)
668 (setq value (get-char-attribute char '<-denotational)))
669 (char-db-insert-relation-feature char '<-denotational value
672 (setq attributes (delq '<-denotational attributes)))
673 (when (and (memq 'name attributes)
674 (setq value (get-char-attribute char 'name)))
676 (if (> (+ (current-column) (length value)) 48)
679 value line-breaking))
680 (setq attributes (delq 'name attributes))
682 (when (and (memq 'name* attributes)
683 (setq value (get-char-attribute char 'name*)))
685 (if (> (+ (current-column) (length value)) 48)
688 value line-breaking))
689 (setq attributes (delq 'name* attributes))
691 (when (and (memq 'script attributes)
692 (setq value (get-char-attribute char 'script)))
693 (insert (format "(script\t\t%s)%s"
694 (mapconcat (function prin1-to-string)
697 (setq attributes (delq 'script attributes))
699 (dolist (name '(=>ucs =>ucs*))
700 (when (and (memq name attributes)
701 (setq value (get-char-attribute char name)))
702 (insert (format "(%-18s . #x%04X)\t; %c%s"
703 name value (decode-char '=ucs value)
705 (setq attributes (delq name attributes))))
706 (dolist (name '(=>ucs@gb =>ucs@big5))
707 (when (and (memq name attributes)
708 (setq value (get-char-attribute char name)))
709 (insert (format "(%-18s . #x%04X)\t; %c%s"
714 (symbol-name name) 2)))
717 (setq attributes (delq name attributes))
719 ;; (dolist (name '(=>daikanwa))
720 ;; (when (and (memq name attributes)
721 ;; (setq value (get-char-attribute char name)))
723 ;; (if (integerp value)
724 ;; (format "(%-18s . %05d)\t; %c%s"
725 ;; name value (decode-char '=daikanwa value)
727 ;; (format "(%-18s %s)\t; %c%s"
729 ;; (mapconcat (function prin1-to-string)
731 ;; (char-representative-of-daikanwa char)
733 ;; (setq attributes (delq name attributes))))
734 (when (and (memq 'general-category attributes)
735 (setq value (get-char-attribute char 'general-category)))
737 "(general-category\t%s) ; %s%s"
738 (mapconcat (lambda (cell)
741 (cond ((rassoc value unidata-normative-category-alist)
742 "Normative Category")
743 ((rassoc value unidata-informative-category-alist)
744 "Informative Category")
748 (setq attributes (delq 'general-category attributes))
750 (when (and (memq 'bidi-category attributes)
751 (setq value (get-char-attribute char 'bidi-category)))
752 (insert (format "(bidi-category\t. %S)%s"
755 (setq attributes (delq 'bidi-category attributes))
757 (unless (or (not (memq 'mirrored attributes))
758 (eq (setq value (get-char-attribute char 'mirrored 'empty))
760 (insert (format "(mirrored\t\t. %S)%s"
763 (setq attributes (delq 'mirrored attributes))
766 ((and (memq 'decimal-digit-value attributes)
767 (setq value (get-char-attribute char 'decimal-digit-value)))
768 (insert (format "(decimal-digit-value . %S)%s"
771 (setq attributes (delq 'decimal-digit-value attributes))
772 (when (and (memq 'digit-value attributes)
773 (setq value (get-char-attribute char 'digit-value)))
774 (insert (format "(digit-value\t . %S)%s"
777 (setq attributes (delq 'digit-value attributes))
779 (when (and (memq 'numeric-value attributes)
780 (setq value (get-char-attribute char 'numeric-value)))
781 (insert (format "(numeric-value\t . %S)%s"
784 (setq attributes (delq 'numeric-value attributes))
788 (when (and (memq 'digit-value attributes)
789 (setq value (get-char-attribute char 'digit-value)))
790 (insert (format "(digit-value\t. %S)%s"
793 (setq attributes (delq 'digit-value attributes))
795 (when (and (memq 'numeric-value attributes)
796 (setq value (get-char-attribute char 'numeric-value)))
797 (insert (format "(numeric-value\t. %S)%s"
800 (setq attributes (delq 'numeric-value attributes))
802 (when (and (memq 'iso-10646-comment attributes)
803 (setq value (get-char-attribute char 'iso-10646-comment)))
804 (insert (format "(iso-10646-comment\t. %S)%s"
807 (setq attributes (delq 'iso-10646-comment attributes))
809 (when (and (memq 'morohashi-daikanwa attributes)
810 (setq value (get-char-attribute char 'morohashi-daikanwa)))
811 (insert (format "(morohashi-daikanwa\t%s)%s"
812 (mapconcat (function prin1-to-string) value " ")
814 (setq attributes (delq 'morohashi-daikanwa attributes))
818 (when (and (memq 'ideographic-radical attributes)
819 (setq value (get-char-attribute char 'ideographic-radical)))
821 (insert (format "(ideographic-radical . %S)\t; %c%s"
823 (ideographic-radical radical)
825 (setq attributes (delq 'ideographic-radical attributes))
827 (when (and (memq 'shuowen-radical attributes)
828 (setq value (get-char-attribute char 'shuowen-radical)))
829 (insert (format "(shuowen-radical\t. %S)\t; %c%s"
831 (shuowen-radical value)
833 (setq attributes (delq 'shuowen-radical attributes))
838 char-db-feature-domains
840 (dolist (feature (char-attribute-list))
841 (setq feature (symbol-name feature))
843 "\\(radical\\|strokes\\)@\\([^@*]+\\)\\(\\*\\|$\\)"
845 (setq domain (intern (match-string 2 feature)))
846 (unless (memq domain dest)
847 (setq dest (cons domain dest)))))
848 (sort dest #'string<))))
849 (setq key (intern (format "%s@%s" 'ideographic-radical domain)))
850 (when (and (memq key attributes)
851 (setq value (get-char-attribute char key)))
853 (insert (format "(%s . %S)\t; %c%s"
856 (ideographic-radical radical)
858 (setq attributes (delq key attributes))
860 (setq key (intern (format "%s@%s" 'ideographic-strokes domain)))
861 (when (and (memq key attributes)
862 (setq value (get-char-attribute char key)))
864 (insert (format "(%s . %S)%s"
868 (setq attributes (delq key attributes))
870 (setq key (intern (format "%s@%s" 'total-strokes domain)))
871 (when (and (memq key attributes)
872 (setq value (get-char-attribute char key)))
873 (insert (format "(%s . %S)%s"
877 (setq attributes (delq key attributes))
879 (dolist (feature '(ideographic-radical
882 (setq key (intern (format "%s@%s*sources" feature domain)))
883 (when (and (memq key attributes)
884 (setq value (get-char-attribute char key)))
885 (insert (format "(%s%s" key line-breaking))
887 (insert (format " %s" cell)))
889 (insert line-breaking)
890 (setq attributes (delq key attributes))
893 (when (and (memq 'ideographic-strokes attributes)
894 (setq value (get-char-attribute char 'ideographic-strokes)))
896 (insert (format "(ideographic-strokes . %S)%s"
899 (setq attributes (delq 'ideographic-strokes attributes))
901 (when (and (memq 'kangxi-radical attributes)
902 (setq value (get-char-attribute char 'kangxi-radical)))
903 (unless (eq value radical)
904 (insert (format "(kangxi-radical\t . %S)\t; %c%s"
906 (ideographic-radical value)
909 (setq radical value)))
910 (setq attributes (delq 'kangxi-radical attributes))
912 (when (and (memq 'kangxi-strokes attributes)
913 (setq value (get-char-attribute char 'kangxi-strokes)))
914 (unless (eq value strokes)
915 (insert (format "(kangxi-strokes\t . %S)%s"
919 (setq strokes value)))
920 (setq attributes (delq 'kangxi-strokes attributes))
922 (when (and (memq 'japanese-radical attributes)
923 (setq value (get-char-attribute char 'japanese-radical)))
924 (unless (eq value radical)
925 (insert (format "(japanese-radical\t . %S)\t; %c%s"
927 (ideographic-radical value)
930 (setq radical value)))
931 (setq attributes (delq 'japanese-radical attributes))
933 (when (and (memq 'japanese-strokes attributes)
934 (setq value (get-char-attribute char 'japanese-strokes)))
935 (unless (eq value strokes)
936 (insert (format "(japanese-strokes\t . %S)%s"
940 (setq strokes value)))
941 (setq attributes (delq 'japanese-strokes attributes))
943 (when (and (memq 'cns-radical attributes)
944 (setq value (get-char-attribute char 'cns-radical)))
945 (insert (format "(cns-radical\t . %S)\t; %c%s"
947 (ideographic-radical value)
949 (setq attributes (delq 'cns-radical attributes))
951 (when (and (memq 'cns-strokes attributes)
952 (setq value (get-char-attribute char 'cns-strokes)))
953 (unless (eq value strokes)
954 (insert (format "(cns-strokes\t . %S)%s"
958 (setq strokes value)))
959 (setq attributes (delq 'cns-strokes attributes))
961 (when (and (memq 'shinjigen-1-radical attributes)
962 (setq value (get-char-attribute char 'shinjigen-1-radical)))
963 (unless (eq value radical)
964 (insert (format "(shinjigen-1-radical . %S)\t; %c%s"
966 (ideographic-radical value)
969 (setq radical value)))
970 (setq attributes (delq 'shinjigen-1-radical attributes))
972 (when (and (memq 'ideographic- attributes)
973 (setq value (get-char-attribute char 'ideographic-)))
974 (insert "(ideographic- ")
975 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
978 (setq cell (car value))
980 (setq cell (decode-char '=ucs cell)))
981 (cond ((characterp cell)
985 (insert (format "%S" cell))
986 (char-db-insert-char-spec cell readable))
987 (setq separator lbs))
991 (if (consp (car cell))
992 (char-db-insert-char-spec cell readable)
993 (char-db-insert-char-reference cell readable))
994 (setq separator lbs))
998 (insert (prin1-to-string cell))
999 (setq separator " ")))
1000 (setq value (cdr value)))
1002 (insert line-breaking)
1003 (setq attributes (delq 'ideographic- attributes)))
1004 (when (and (memq 'total-strokes attributes)
1005 (setq value (get-char-attribute char 'total-strokes)))
1006 (insert (format "(total-strokes . %S)%s"
1009 (setq attributes (delq 'total-strokes attributes))
1011 (when (and (memq '->ideograph attributes)
1012 (setq value (get-char-attribute char '->ideograph)))
1013 (insert (format "(->ideograph\t%s)%s"
1014 (mapconcat (lambda (code)
1015 (cond ((symbolp code)
1018 (format "#x%04X" code))
1021 line-breaking code))))
1024 (setq attributes (delq '->ideograph attributes))
1026 ;; (when (and (memq '->decomposition attributes)
1027 ;; (setq value (get-char-attribute char '->decomposition)))
1028 ;; (insert (format "(->decomposition\t%s)%s"
1029 ;; (mapconcat (lambda (code)
1030 ;; (cond ((symbolp code)
1031 ;; (symbol-name code))
1032 ;; ((characterp code)
1034 ;; (format "%S" code)
1039 ;; (format "#x%04X" code))
1041 ;; (format "%s%S" line-breaking code))))
1044 ;; (setq attributes (delq '->decomposition attributes))
1046 (if (equal (get-char-attribute char '->titlecase)
1047 (get-char-attribute char '->uppercase))
1048 (setq attributes (delq '->titlecase attributes)))
1049 (when (and (memq '->mojikyo attributes)
1050 (setq value (get-char-attribute char '->mojikyo)))
1051 (insert (format "(->mojikyo\t\t. %06d)\t; %c%s"
1052 value (decode-char 'mojikyo value)
1054 (setq attributes (delq '->mojikyo attributes))
1056 (when (and (memq 'hanyu-dazidian-vol attributes)
1057 (setq value (get-char-attribute char 'hanyu-dazidian-vol)))
1058 (insert (format "(hanyu-dazidian-vol . %d)%s"
1059 value line-breaking))
1060 (setq attributes (delq 'hanyu-dazidian-vol attributes))
1062 (when (and (memq 'hanyu-dazidian-page attributes)
1063 (setq value (get-char-attribute char 'hanyu-dazidian-page)))
1064 (insert (format "(hanyu-dazidian-page . %d)%s"
1065 value line-breaking))
1066 (setq attributes (delq 'hanyu-dazidian-page attributes))
1068 (when (and (memq 'hanyu-dazidian-char attributes)
1069 (setq value (get-char-attribute char 'hanyu-dazidian-char)))
1070 (insert (format "(hanyu-dazidian-char . %d)%s"
1071 value line-breaking))
1072 (setq attributes (delq 'hanyu-dazidian-char attributes))
1075 (dolist (ignored '(composition
1076 ->denotational <-subsumptive ->ucs-unified
1077 ->ideographic-component-forms))
1078 (setq attributes (delq ignored attributes))))
1080 (setq name (car attributes))
1081 (unless (eq (setq value (get-char-attribute char name 'value-is-empty))
1083 (cond ((setq ret (find-charset name))
1084 (setq name (charset-name ret))
1085 (when (not (memq name dest-ccss))
1086 (setq dest-ccss (cons name dest-ccss))
1087 (char-db-insert-ccs-feature name value line-breaking))
1089 ((string-match "^=>ucs@" (symbol-name name))
1090 (insert (format "(%-18s . #x%04X)\t; %c%s"
1091 name value (decode-char '=ucs value)
1094 ((eq name 'jisx0208-1978/4X)
1095 (insert (format "(%-18s . #x%04X)%s"
1101 (not (eq name '->subsumptive))
1102 (not (eq name '->uppercase))
1103 (not (eq name '->lowercase))
1104 (not (eq name '->titlecase))
1105 (not (eq name '->canonical))
1106 (not (eq name '->Bopomofo))
1107 (not (eq name '->mistakable))
1108 (not (eq name '->ideographic-variants))
1109 (null (get-char-attribute
1110 char (intern (format "%s*sources" name))))
1111 (not (string-match "\\*sources$" (symbol-name name)))
1112 (null (get-char-attribute
1113 char (intern (format "%s*note" name))))
1114 (not (string-match "\\*note$" (symbol-name name)))
1115 (or (eq name '<-identical)
1116 (eq name '<-uppercase)
1117 (eq name '<-lowercase)
1118 (eq name '<-titlecase)
1119 (eq name '<-canonical)
1120 (eq name '<-ideographic-variants)
1121 ;; (eq name '<-synonyms)
1122 (string-match "^<-synonyms" (symbol-name name))
1123 (eq name '<-mistakable)
1124 (when (string-match "^->" (symbol-name name))
1126 ((string-match "^->fullwidth" (symbol-name name))
1127 (not (and (consp value)
1128 (characterp (car value))
1130 (car value) '=ucs 'defined-only)))
1135 ((or (eq name 'ideographic-structure)
1136 (eq name 'ideographic-combination)
1137 (eq name 'ideographic-)
1138 (eq name '=decomposition)
1139 (char-feature-base-name= '=decomposition name)
1140 (char-feature-base-name= '=>decomposition name)
1141 ;; (string-match "^=>*decomposition\\(@[^*]+\\)?$"
1142 ;; (symbol-name name))
1143 (string-match "^\\(->\\|<-\\)[^*]*$" (symbol-name name))
1144 (string-match "^\\(->\\|<-\\)[^*]*\\*sources$"
1147 (char-db-insert-relation-feature char name value
1150 ((memq name '(ideograph=
1151 original-ideograph-of
1152 ancient-ideograph-of
1155 ;; simplified-ideograph-of
1156 ideographic-variants
1157 ;; ideographic-different-form-of
1159 (insert (format "(%-18s%s " name line-breaking))
1160 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1162 (while (consp value)
1163 (setq cell (car value))
1164 (if (and (consp cell)
1169 (char-db-insert-alist cell readable)
1170 (setq separator lbs))
1173 (insert (prin1-to-string cell))
1174 (setq separator " "))
1175 (setq value (cdr value)))
1177 (insert line-breaking))
1179 (insert (format "(%-18s " name))
1180 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1182 (while (consp value)
1183 (setq cell (car value))
1184 (if (and (consp cell)
1186 (setq ret (condition-case nil
1194 (setq key (car (car rest)))
1195 (if (find-charset key)
1196 (setq cal (cons key cal))
1197 (setq al (cons key al)))
1198 (setq rest (cdr rest)))
1201 (insert-char-attributes ret
1205 (setq separator lbs))
1206 (setq ret (prin1-to-string cell))
1208 (if (< (+ (current-column)
1215 (setq separator " "))
1216 (setq value (cdr value)))
1218 (insert line-breaking))
1220 (insert (format "(%-18s" name))
1221 (setq ret (prin1-to-string value))
1222 (unless (< (+ (current-column)
1226 (insert line-breaking))
1227 (insert " . " ret ")" line-breaking)
1228 ;; (insert (format "(%-18s . %S)%s"
1233 (setq attributes (cdr attributes)))
1236 (defun insert-char-data (char &optional readable
1239 (narrow-to-region (point)(point))
1240 (insert "(define-char
1242 (insert-char-attributes char readable attributes)
1244 (goto-char (point-min))
1245 (while (re-search-forward "[ \t]+$" nil t)
1248 (goto-char (point-min))
1249 (while (re-search-forward "[ \t][ \t][ \t]*" nil t)
1250 (let ((column (current-column))
1251 (indent-tabs-mode t))
1252 (delete-region (match-beginning 0) (point))
1253 (indent-to column)))
1254 (goto-char (point-max))
1255 ;; (tabify (point-min)(point-max))
1258 (defun insert-char-data-with-variant (char &optional printable
1260 script excluded-script)
1261 (insert-char-data char printable)
1262 (let ((variants (char-variants char))
1265 (setq variants (sort variants #'<))
1266 (setq rest variants)
1267 (setq variants (cons char variants))
1269 (setq variant (car rest))
1270 (unless (get-char-attribute variant '<-subsumptive)
1271 (if (and (or (null script)
1272 (null (setq vs (get-char-attribute variant 'script)))
1274 (or (null excluded-script)
1275 (null (setq vs (get-char-attribute variant 'script)))
1276 (not (memq excluded-script vs))))
1277 (unless (and no-ucs-unified (get-char-attribute variant '=ucs))
1278 (insert-char-data variant printable)
1279 (if (setq ret (char-variants variant))
1281 (or (memq (car ret) variants)
1282 ;; (get-char-attribute (car ret) '<-subsumptive)
1283 (setq rest (nconc rest (list (car ret)))))
1284 (setq ret (cdr ret)))))))
1285 (setq rest (cdr rest)))))
1287 (defun insert-char-range-data (min max &optional script excluded-script)
1290 (while (<= code max)
1291 (setq char (decode-char '=ucs code))
1292 (if (encode-char char '=ucs 'defined-only)
1293 (insert-char-data-with-variant char nil 'no-ucs-unified
1294 script excluded-script))
1295 (setq code (1+ code)))))
1297 (defun write-char-range-data-to-file (min max file
1298 &optional script excluded-script)
1299 (let ((coding-system-for-write char-db-file-coding-system))
1301 (insert (format ";; -*- coding: %s -*-\n"
1302 char-db-file-coding-system))
1303 (insert-char-range-data min max script excluded-script)
1304 (write-region (point-min)(point-max) file))))
1306 (defvar what-character-original-window-configuration)
1309 (defun what-char-definition (char)
1310 (interactive (list (char-after)))
1311 (let ((buf (get-buffer-create "*Character Description*"))
1312 (the-buf (current-buffer))
1313 (win-conf (current-window-configuration)))
1315 (make-local-variable 'what-character-original-window-configuration)
1316 (setq what-character-original-window-configuration win-conf)
1317 (setq buffer-read-only nil)
1321 (insert-char-data-with-variant char 'printable)
1322 (unless (char-attribute-alist char)
1323 (insert (format ";; = %c\n"
1324 (let* ((rest (split-char char))
1328 (setq code (logior (lsh code 8)
1330 (decode-char ccs code)))))
1331 ;; (char-db-update-comment)
1332 (set-buffer-modified-p nil)
1333 (view-mode the-buf (lambda (buf)
1334 (set-window-configuration
1335 what-character-original-window-configuration)
1337 (goto-char (point-min)))
1339 (set-window-configuration
1340 what-character-original-window-configuration)
1341 (signal (car err) (cdr err)))))))
1347 (provide 'char-db-util)
1349 ;;; char-db-util.el ends here