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
495 =zinbun-oracle =>zinbun-oracle))
496 ;; (string-match "^=adobe-" (symbol-name name))
498 "(%-18s . %05d)\t; %c")
499 ((memq name '(=hanyo-denshi/ks =>>hanyo-denshi/ks mojikyo))
500 "(%-18s . %06d)\t; %c")
501 ((>= (charset-dimension name) 2)
502 "(%-18s . #x%04X)\t; %c")
504 "(%-18s . #x%02X)\t; %c"))
506 (if (= (charset-iso-graphic-plane name) 1)
508 (cond ((= (charset-dimension name) 1)
510 ((= (charset-dimension name) 2)
512 ((= (charset-dimension name) 3)
516 (char-db-decode-isolated-char name value)))
517 (if (and (= (charset-chars name) 94)
518 (= (charset-dimension name) 2))
519 (insert (format " [%02d-%02d]"
520 (- (lsh value -8) 32)
521 (- (logand value 255) 32))))
524 (insert (format "(%-18s . %s)" name value))
526 (insert line-breaking))
528 (defun char-db-insert-relation-feature (char name value line-breaking
530 (insert (format "(%-18s%s " name line-breaking))
531 (let ((lbs (concat "\n" (make-string (current-column) ?\ )))
532 separator cell sources required-features
535 (setq cell (car value))
537 (setq cell (decode-char '=ucs cell)))
539 ((eq name '->subsumptive)
540 (when (or (not (some (lambda (atr)
541 (get-char-attribute cell atr))
542 char-db-ignored-attributes))
544 (encode-char cell ccs 'defined-only))
548 (let ((char-db-ignored-attributes
550 char-db-ignored-attributes)))
551 (insert-char-attributes cell readable nil nil 'for-sub-node))
552 (setq separator lbs))
557 char (intern (format "%s*sources" name))))
558 (setq required-features nil)
559 (dolist (source sources)
563 shinjigen shinjigen@1ed shinjigen@rev))
564 (setq required-features
565 (union required-features
576 (setq required-features
577 (union required-features
582 ((find-charset (setq ret (intern (format "=%s" source))))
583 (setq required-features
584 (cons ret required-features)))
585 (t (setq required-features
586 (cons source required-features)))))
587 (cond ((string-match "@JP" (symbol-name name))
588 (setq required-features
589 (union required-features
597 ((string-match "@CN" (symbol-name name))
598 (setq required-features
599 (union required-features
606 (insert (format "%S" cell))
607 (char-db-insert-char-spec cell readable
610 (setq separator lbs))
614 (if (consp (car cell))
615 (char-db-insert-char-spec cell readable)
616 (char-db-insert-char-reference cell readable))
617 (setq separator lbs))
621 (insert (prin1-to-string cell))
622 (setq separator " ")))
623 (setq value (cdr value)))
625 (insert line-breaking)))
627 (defun insert-char-attributes (char &optional readable attributes column
630 (setq column (current-column)))
631 (let (name value ; has-long-ccs-name
635 (concat "\n" (make-string (1+ column) ?\ )))
636 lbs cell separator ret
638 dest-ccss ; sources required-features
643 (if (consp attributes)
645 (dolist (name attributes)
646 (unless (memq name char-db-ignored-attributes)
647 (if (find-charset name)
651 (dolist (name (char-attribute-list))
652 (unless (memq name char-db-ignored-attributes)
653 (if (find-charset name)
657 #'char-attribute-name<)))
659 (when (memq '<-subsumptive attributes)
660 (when (or readable (not for-sub-node))
661 (when (setq value (get-char-attribute char '<-subsumptive))
662 (char-db-insert-relation-feature char '<-subsumptive value
665 (setq attributes (delq '<-subsumptive attributes)))
666 (when (and (memq '<-denotational attributes)
667 (setq value (get-char-attribute char '<-denotational)))
668 (char-db-insert-relation-feature char '<-denotational value
671 (setq attributes (delq '<-denotational attributes)))
672 (when (and (memq 'name attributes)
673 (setq value (get-char-attribute char 'name)))
675 (if (> (+ (current-column) (length value)) 48)
678 value line-breaking))
679 (setq attributes (delq 'name attributes))
681 (when (and (memq 'name* attributes)
682 (setq value (get-char-attribute char 'name*)))
684 (if (> (+ (current-column) (length value)) 48)
687 value line-breaking))
688 (setq attributes (delq 'name* attributes))
690 (when (and (memq 'script attributes)
691 (setq value (get-char-attribute char 'script)))
692 (insert (format "(script\t\t%s)%s"
693 (mapconcat (function prin1-to-string)
696 (setq attributes (delq 'script attributes))
698 (dolist (name '(=>ucs =>ucs*))
699 (when (and (memq name attributes)
700 (setq value (get-char-attribute char name)))
701 (insert (format "(%-18s . #x%04X)\t; %c%s"
702 name value (decode-char '=ucs value)
704 (setq attributes (delq name attributes))))
705 (dolist (name '(=>ucs@gb =>ucs@big5))
706 (when (and (memq name attributes)
707 (setq value (get-char-attribute char name)))
708 (insert (format "(%-18s . #x%04X)\t; %c%s"
713 (symbol-name name) 2)))
716 (setq attributes (delq name attributes))
718 ;; (dolist (name '(=>daikanwa))
719 ;; (when (and (memq name attributes)
720 ;; (setq value (get-char-attribute char name)))
722 ;; (if (integerp value)
723 ;; (format "(%-18s . %05d)\t; %c%s"
724 ;; name value (decode-char '=daikanwa value)
726 ;; (format "(%-18s %s)\t; %c%s"
728 ;; (mapconcat (function prin1-to-string)
730 ;; (char-representative-of-daikanwa char)
732 ;; (setq attributes (delq name attributes))))
733 (when (and (memq 'general-category attributes)
734 (setq value (get-char-attribute char 'general-category)))
736 "(general-category\t%s) ; %s%s"
737 (mapconcat (lambda (cell)
740 (cond ((rassoc value unidata-normative-category-alist)
741 "Normative Category")
742 ((rassoc value unidata-informative-category-alist)
743 "Informative Category")
747 (setq attributes (delq 'general-category attributes))
749 (when (and (memq 'bidi-category attributes)
750 (setq value (get-char-attribute char 'bidi-category)))
751 (insert (format "(bidi-category\t. %S)%s"
754 (setq attributes (delq 'bidi-category attributes))
756 (unless (or (not (memq 'mirrored attributes))
757 (eq (setq value (get-char-attribute char 'mirrored 'empty))
759 (insert (format "(mirrored\t\t. %S)%s"
762 (setq attributes (delq 'mirrored attributes))
765 ((and (memq 'decimal-digit-value attributes)
766 (setq value (get-char-attribute char 'decimal-digit-value)))
767 (insert (format "(decimal-digit-value . %S)%s"
770 (setq attributes (delq 'decimal-digit-value attributes))
771 (when (and (memq 'digit-value attributes)
772 (setq value (get-char-attribute char 'digit-value)))
773 (insert (format "(digit-value\t . %S)%s"
776 (setq attributes (delq 'digit-value attributes))
778 (when (and (memq 'numeric-value attributes)
779 (setq value (get-char-attribute char 'numeric-value)))
780 (insert (format "(numeric-value\t . %S)%s"
783 (setq attributes (delq 'numeric-value attributes))
787 (when (and (memq 'digit-value attributes)
788 (setq value (get-char-attribute char 'digit-value)))
789 (insert (format "(digit-value\t. %S)%s"
792 (setq attributes (delq 'digit-value attributes))
794 (when (and (memq 'numeric-value attributes)
795 (setq value (get-char-attribute char 'numeric-value)))
796 (insert (format "(numeric-value\t. %S)%s"
799 (setq attributes (delq 'numeric-value attributes))
801 (when (and (memq 'iso-10646-comment attributes)
802 (setq value (get-char-attribute char 'iso-10646-comment)))
803 (insert (format "(iso-10646-comment\t. %S)%s"
806 (setq attributes (delq 'iso-10646-comment attributes))
808 (when (and (memq 'morohashi-daikanwa attributes)
809 (setq value (get-char-attribute char 'morohashi-daikanwa)))
810 (insert (format "(morohashi-daikanwa\t%s)%s"
811 (mapconcat (function prin1-to-string) value " ")
813 (setq attributes (delq 'morohashi-daikanwa attributes))
817 (when (and (memq 'ideographic-radical attributes)
818 (setq value (get-char-attribute char 'ideographic-radical)))
820 (insert (format "(ideographic-radical . %S)\t; %c%s"
822 (ideographic-radical radical)
824 (setq attributes (delq 'ideographic-radical attributes))
826 (when (and (memq 'shuowen-radical attributes)
827 (setq value (get-char-attribute char 'shuowen-radical)))
828 (insert (format "(shuowen-radical\t. %S)\t; %c%s"
830 (shuowen-radical value)
832 (setq attributes (delq 'shuowen-radical attributes))
837 char-db-feature-domains
839 (dolist (feature (char-attribute-list))
840 (setq feature (symbol-name feature))
842 "\\(radical\\|strokes\\)@\\([^@*]+\\)\\(\\*\\|$\\)"
844 (setq domain (intern (match-string 2 feature)))
845 (unless (memq domain dest)
846 (setq dest (cons domain dest)))))
847 (sort dest #'string<))))
848 (setq key (intern (format "%s@%s" 'ideographic-radical domain)))
849 (when (and (memq key attributes)
850 (setq value (get-char-attribute char key)))
852 (insert (format "(%s . %S)\t; %c%s"
855 (ideographic-radical radical)
857 (setq attributes (delq key attributes))
859 (setq key (intern (format "%s@%s" 'ideographic-strokes domain)))
860 (when (and (memq key attributes)
861 (setq value (get-char-attribute char key)))
863 (insert (format "(%s . %S)%s"
867 (setq attributes (delq key attributes))
869 (setq key (intern (format "%s@%s" 'total-strokes domain)))
870 (when (and (memq key attributes)
871 (setq value (get-char-attribute char key)))
872 (insert (format "(%s . %S)%s"
876 (setq attributes (delq key attributes))
878 (dolist (feature '(ideographic-radical
881 (setq key (intern (format "%s@%s*sources" feature domain)))
882 (when (and (memq key attributes)
883 (setq value (get-char-attribute char key)))
884 (insert (format "(%s%s" key line-breaking))
886 (insert (format " %s" cell)))
888 (insert line-breaking)
889 (setq attributes (delq key attributes))
892 (when (and (memq 'ideographic-strokes attributes)
893 (setq value (get-char-attribute char 'ideographic-strokes)))
895 (insert (format "(ideographic-strokes . %S)%s"
898 (setq attributes (delq 'ideographic-strokes attributes))
900 (when (and (memq 'kangxi-radical attributes)
901 (setq value (get-char-attribute char 'kangxi-radical)))
902 (unless (eq value radical)
903 (insert (format "(kangxi-radical\t . %S)\t; %c%s"
905 (ideographic-radical value)
908 (setq radical value)))
909 (setq attributes (delq 'kangxi-radical attributes))
911 (when (and (memq 'kangxi-strokes attributes)
912 (setq value (get-char-attribute char 'kangxi-strokes)))
913 (unless (eq value strokes)
914 (insert (format "(kangxi-strokes\t . %S)%s"
918 (setq strokes value)))
919 (setq attributes (delq 'kangxi-strokes attributes))
921 (when (and (memq 'japanese-radical attributes)
922 (setq value (get-char-attribute char 'japanese-radical)))
923 (unless (eq value radical)
924 (insert (format "(japanese-radical\t . %S)\t; %c%s"
926 (ideographic-radical value)
929 (setq radical value)))
930 (setq attributes (delq 'japanese-radical attributes))
932 (when (and (memq 'japanese-strokes attributes)
933 (setq value (get-char-attribute char 'japanese-strokes)))
934 (unless (eq value strokes)
935 (insert (format "(japanese-strokes\t . %S)%s"
939 (setq strokes value)))
940 (setq attributes (delq 'japanese-strokes attributes))
942 (when (and (memq 'cns-radical attributes)
943 (setq value (get-char-attribute char 'cns-radical)))
944 (insert (format "(cns-radical\t . %S)\t; %c%s"
946 (ideographic-radical value)
948 (setq attributes (delq 'cns-radical attributes))
950 (when (and (memq 'cns-strokes attributes)
951 (setq value (get-char-attribute char 'cns-strokes)))
952 (unless (eq value strokes)
953 (insert (format "(cns-strokes\t . %S)%s"
957 (setq strokes value)))
958 (setq attributes (delq 'cns-strokes attributes))
960 (when (and (memq 'shinjigen-1-radical attributes)
961 (setq value (get-char-attribute char 'shinjigen-1-radical)))
962 (unless (eq value radical)
963 (insert (format "(shinjigen-1-radical . %S)\t; %c%s"
965 (ideographic-radical value)
968 (setq radical value)))
969 (setq attributes (delq 'shinjigen-1-radical attributes))
971 (when (and (memq 'ideographic- attributes)
972 (setq value (get-char-attribute char 'ideographic-)))
973 (insert "(ideographic- ")
974 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
977 (setq cell (car value))
979 (setq cell (decode-char '=ucs cell)))
980 (cond ((characterp cell)
984 (insert (format "%S" cell))
985 (char-db-insert-char-spec cell readable))
986 (setq separator lbs))
990 (if (consp (car cell))
991 (char-db-insert-char-spec cell readable)
992 (char-db-insert-char-reference cell readable))
993 (setq separator lbs))
997 (insert (prin1-to-string cell))
998 (setq separator " ")))
999 (setq value (cdr value)))
1001 (insert line-breaking)
1002 (setq attributes (delq 'ideographic- attributes)))
1003 (when (and (memq 'total-strokes attributes)
1004 (setq value (get-char-attribute char 'total-strokes)))
1005 (insert (format "(total-strokes . %S)%s"
1008 (setq attributes (delq 'total-strokes attributes))
1010 (when (and (memq '->ideograph attributes)
1011 (setq value (get-char-attribute char '->ideograph)))
1012 (insert (format "(->ideograph\t%s)%s"
1013 (mapconcat (lambda (code)
1014 (cond ((symbolp code)
1017 (format "#x%04X" code))
1020 line-breaking code))))
1023 (setq attributes (delq '->ideograph attributes))
1025 ;; (when (and (memq '->decomposition attributes)
1026 ;; (setq value (get-char-attribute char '->decomposition)))
1027 ;; (insert (format "(->decomposition\t%s)%s"
1028 ;; (mapconcat (lambda (code)
1029 ;; (cond ((symbolp code)
1030 ;; (symbol-name code))
1031 ;; ((characterp code)
1033 ;; (format "%S" code)
1038 ;; (format "#x%04X" code))
1040 ;; (format "%s%S" line-breaking code))))
1043 ;; (setq attributes (delq '->decomposition attributes))
1045 (if (equal (get-char-attribute char '->titlecase)
1046 (get-char-attribute char '->uppercase))
1047 (setq attributes (delq '->titlecase attributes)))
1048 (when (and (memq '->mojikyo attributes)
1049 (setq value (get-char-attribute char '->mojikyo)))
1050 (insert (format "(->mojikyo\t\t. %06d)\t; %c%s"
1051 value (decode-char 'mojikyo value)
1053 (setq attributes (delq '->mojikyo attributes))
1055 (when (and (memq 'hanyu-dazidian-vol attributes)
1056 (setq value (get-char-attribute char 'hanyu-dazidian-vol)))
1057 (insert (format "(hanyu-dazidian-vol . %d)%s"
1058 value line-breaking))
1059 (setq attributes (delq 'hanyu-dazidian-vol attributes))
1061 (when (and (memq 'hanyu-dazidian-page attributes)
1062 (setq value (get-char-attribute char 'hanyu-dazidian-page)))
1063 (insert (format "(hanyu-dazidian-page . %d)%s"
1064 value line-breaking))
1065 (setq attributes (delq 'hanyu-dazidian-page attributes))
1067 (when (and (memq 'hanyu-dazidian-char attributes)
1068 (setq value (get-char-attribute char 'hanyu-dazidian-char)))
1069 (insert (format "(hanyu-dazidian-char . %d)%s"
1070 value line-breaking))
1071 (setq attributes (delq 'hanyu-dazidian-char attributes))
1074 (dolist (ignored '(composition
1075 ->denotational <-subsumptive ->ucs-unified
1076 ->ideographic-component-forms))
1077 (setq attributes (delq ignored attributes))))
1079 (setq name (car attributes))
1080 (unless (eq (setq value (get-char-attribute char name 'value-is-empty))
1082 (cond ((setq ret (find-charset name))
1083 (setq name (charset-name ret))
1084 (when (not (memq name dest-ccss))
1085 (setq dest-ccss (cons name dest-ccss))
1086 (char-db-insert-ccs-feature name value line-breaking))
1088 ((string-match "^=>ucs@" (symbol-name name))
1089 (insert (format "(%-18s . #x%04X)\t; %c%s"
1090 name value (decode-char '=ucs value)
1093 ((eq name 'jisx0208-1978/4X)
1094 (insert (format "(%-18s . #x%04X)%s"
1100 (not (eq name '->subsumptive))
1101 (not (eq name '->uppercase))
1102 (not (eq name '->lowercase))
1103 (not (eq name '->titlecase))
1104 (not (eq name '->canonical))
1105 (not (eq name '->Bopomofo))
1106 (not (eq name '->mistakable))
1107 (not (eq name '->ideographic-variants))
1108 (null (get-char-attribute
1109 char (intern (format "%s*sources" name))))
1110 (not (string-match "\\*sources$" (symbol-name name)))
1111 (null (get-char-attribute
1112 char (intern (format "%s*note" name))))
1113 (not (string-match "\\*note$" (symbol-name name)))
1114 (or (eq name '<-identical)
1115 (eq name '<-uppercase)
1116 (eq name '<-lowercase)
1117 (eq name '<-titlecase)
1118 (eq name '<-canonical)
1119 (eq name '<-ideographic-variants)
1120 ;; (eq name '<-synonyms)
1121 (string-match "^<-synonyms" (symbol-name name))
1122 (eq name '<-mistakable)
1123 (when (string-match "^->" (symbol-name name))
1125 ((string-match "^->fullwidth" (symbol-name name))
1126 (not (and (consp value)
1127 (characterp (car value))
1129 (car value) '=ucs 'defined-only)))
1134 ((or (eq name 'ideographic-structure)
1135 (eq name 'ideographic-combination)
1136 (eq name 'ideographic-)
1137 (eq name '=decomposition)
1138 (char-feature-base-name= '=decomposition name)
1139 (char-feature-base-name= '=>decomposition name)
1140 ;; (string-match "^=>*decomposition\\(@[^*]+\\)?$"
1141 ;; (symbol-name name))
1142 (string-match "^\\(->\\|<-\\)[^*]*$" (symbol-name name))
1143 (string-match "^\\(->\\|<-\\)[^*]*\\*sources$"
1146 (char-db-insert-relation-feature char name value
1149 ((memq name '(ideograph=
1150 original-ideograph-of
1151 ancient-ideograph-of
1154 ;; simplified-ideograph-of
1155 ideographic-variants
1156 ;; ideographic-different-form-of
1158 (insert (format "(%-18s%s " name line-breaking))
1159 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1161 (while (consp value)
1162 (setq cell (car value))
1163 (if (and (consp cell)
1168 (char-db-insert-alist cell readable)
1169 (setq separator lbs))
1172 (insert (prin1-to-string cell))
1173 (setq separator " "))
1174 (setq value (cdr value)))
1176 (insert line-breaking))
1178 (insert (format "(%-18s " name))
1179 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1181 (while (consp value)
1182 (setq cell (car value))
1183 (if (and (consp cell)
1185 (setq ret (condition-case nil
1193 (setq key (car (car rest)))
1194 (if (find-charset key)
1195 (setq cal (cons key cal))
1196 (setq al (cons key al)))
1197 (setq rest (cdr rest)))
1200 (insert-char-attributes ret
1204 (setq separator lbs))
1205 (setq ret (prin1-to-string cell))
1207 (if (< (+ (current-column)
1214 (setq separator " "))
1215 (setq value (cdr value)))
1217 (insert line-breaking))
1219 (insert (format "(%-18s" name))
1220 (setq ret (prin1-to-string value))
1221 (unless (< (+ (current-column)
1225 (insert line-breaking))
1226 (insert " . " ret ")" line-breaking)
1227 ;; (insert (format "(%-18s . %S)%s"
1232 (setq attributes (cdr attributes)))
1235 (defun insert-char-data (char &optional readable
1238 (narrow-to-region (point)(point))
1239 (insert "(define-char
1241 (insert-char-attributes char readable attributes)
1243 (goto-char (point-min))
1244 (while (re-search-forward "[ \t]+$" nil t)
1247 (goto-char (point-min))
1248 (while (re-search-forward "[ \t][ \t][ \t]*" nil t)
1249 (let ((column (current-column))
1250 (indent-tabs-mode t))
1251 (delete-region (match-beginning 0) (point))
1252 (indent-to column)))
1253 (goto-char (point-max))
1254 ;; (tabify (point-min)(point-max))
1257 (defun insert-char-data-with-variant (char &optional printable
1259 script excluded-script)
1260 (insert-char-data char printable)
1261 (let ((variants (char-variants char))
1264 (setq variants (sort variants #'<))
1265 (setq rest variants)
1266 (setq variants (cons char variants))
1268 (setq variant (car rest))
1269 (unless (get-char-attribute variant '<-subsumptive)
1270 (if (and (or (null script)
1271 (null (setq vs (get-char-attribute variant 'script)))
1273 (or (null excluded-script)
1274 (null (setq vs (get-char-attribute variant 'script)))
1275 (not (memq excluded-script vs))))
1276 (unless (and no-ucs-unified (get-char-attribute variant '=ucs))
1277 (insert-char-data variant printable)
1278 (if (setq ret (char-variants variant))
1280 (or (memq (car ret) variants)
1281 ;; (get-char-attribute (car ret) '<-subsumptive)
1282 (setq rest (nconc rest (list (car ret)))))
1283 (setq ret (cdr ret)))))))
1284 (setq rest (cdr rest)))))
1286 (defun insert-char-range-data (min max &optional script excluded-script)
1289 (while (<= code max)
1290 (setq char (decode-char '=ucs code))
1291 (if (encode-char char '=ucs 'defined-only)
1292 (insert-char-data-with-variant char nil 'no-ucs-unified
1293 script excluded-script))
1294 (setq code (1+ code)))))
1296 (defun write-char-range-data-to-file (min max file
1297 &optional script excluded-script)
1298 (let ((coding-system-for-write char-db-file-coding-system))
1300 (insert (format ";; -*- coding: %s -*-\n"
1301 char-db-file-coding-system))
1302 (insert-char-range-data min max script excluded-script)
1303 (write-region (point-min)(point-max) file))))
1305 (defvar what-character-original-window-configuration)
1308 (defun what-char-definition (char)
1309 (interactive (list (char-after)))
1310 (let ((buf (get-buffer-create "*Character Description*"))
1311 (the-buf (current-buffer))
1312 (win-conf (current-window-configuration)))
1314 (make-local-variable 'what-character-original-window-configuration)
1315 (setq what-character-original-window-configuration win-conf)
1316 (setq buffer-read-only nil)
1320 (insert-char-data-with-variant char 'printable)
1321 (unless (char-attribute-alist char)
1322 (insert (format ";; = %c\n"
1323 (let* ((rest (split-char char))
1327 (setq code (logior (lsh code 8)
1329 (decode-char ccs code)))))
1330 ;; (char-db-update-comment)
1331 (set-buffer-modified-p nil)
1332 (view-mode the-buf (lambda (buf)
1333 (set-window-configuration
1334 what-character-original-window-configuration)
1336 (goto-char (point-min)))
1338 (set-window-configuration
1339 what-character-original-window-configuration)
1340 (signal (car err) (cdr err)))))))
1346 (provide 'char-db-util)
1348 ;;; char-db-util.el ends here