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
241 ;;; @ char-db formatters
244 (defun char-db-make-char-spec (char)
246 (cond ((characterp char)
247 (cond ((and (setq ret (encode-char char '=ucs 'defined-only))
248 (not (and (<= #xE000 ret)(<= ret #xF8FF))))
249 (setq char-spec (list (cons '=ucs ret)))
250 (cond ((setq ret (get-char-attribute char 'name))
251 (setq char-spec (cons (cons 'name ret) char-spec))
253 ((setq ret (get-char-attribute char 'name*))
254 (setq char-spec (cons (cons 'name* ret) char-spec))
259 (let ((rest char-db-coded-charset-priority-list)
262 (setq ccs (charset-name
263 (find-charset (car rest))))
265 (encode-char char ccs
267 (throw 'tag (cons ccs ret)))
268 (setq rest (cdr rest))))))
269 (setq char-spec (list ret))
270 (dolist (ccs (delq (car ret) (charset-list)))
271 (if (and (or (charset-iso-final-char ccs)
278 (string-match "=ucs@" (symbol-name ccs)))
279 (setq ccs (charset-name ccs))
280 (null (assq ccs char-spec))
281 (setq ret (encode-char char ccs 'defined-only)))
282 (setq char-spec (cons (cons ccs ret) char-spec))))
284 (setq char-spec (split-char char)))
285 (cond ((setq ret (get-char-attribute char 'name))
286 (setq char-spec (cons (cons 'name ret) char-spec))
288 ((setq ret (get-char-attribute char 'name*))
289 (setq char-spec (cons (cons 'name* ret) char-spec))
292 ((setq ret (get-char-attribute
293 char 'ideographic-combination))
295 (cons (cons 'ideographic-combination ret)
302 (defun char-db-insert-char-spec (char &optional readable column
305 (setq column (current-column)))
306 (let (char-spec temp-char)
307 (setq char-spec (char-db-make-char-spec char))
308 (unless (or (characterp char) ; char
310 (setq char (find-char char-spec))
312 ;; define temporary character
313 ;; Current implementation is dirty.
314 (setq temp-char (define-char (cons '(ideograph-daikanwa . 0)
316 (remove-char-attribute temp-char 'ideograph-daikanwa)
317 (setq char temp-char))
318 (insert-char-attributes char
320 (union (mapcar #'car char-spec)
324 ;; undefine temporary character
325 ;; Current implementation is dirty.
326 (setq char-spec (char-attribute-alist temp-char))
328 (remove-char-attribute temp-char (car (car char-spec)))
329 (setq char-spec (cdr char-spec))))))
331 (defun char-db-insert-alist (alist &optional readable column)
333 (setq column (current-column)))
335 (concat "\n" (make-string (1+ column) ?\ )))
339 lbs cell rest separator)
342 (setq name (car (car alist))
343 value (cdr (car alist)))
344 (cond ((eq name 'char)
346 (if (setq ret (condition-case nil
354 (setq key (car (car value)))
355 ;; (if (find-charset key)
356 ;; (setq cal (cons key cal))
357 (setq al (cons key al))
359 (setq value (cdr value)))
360 (insert-char-attributes ret
364 (insert (prin1-to-string value)))
366 (insert line-breaking))
368 (insert (format "(%-18s " name))
369 (setq lbs (concat "\n" (make-string (current-column) ?\ )))
371 (setq cell (car value))
372 (if (and (consp cell)
374 (setq ret (condition-case nil
384 (setq key (car (car rest)))
385 ;; (if (find-charset key)
386 ;; (setq cal (cons key cal))
387 (setq al (cons key al))
389 (setq rest (cdr rest)))
392 (insert-char-attributes ret
396 (setq separator lbs))
399 (insert (prin1-to-string cell))
400 (setq separator " "))
401 (setq value (cdr value)))
403 (insert line-breaking))
405 (insert (format "(%-18s . %S)%s"
408 (setq alist (cdr alist))))
411 (defun char-db-insert-char-reference (plist &optional readable column)
413 (setq column (current-column)))
415 (concat "\n" (make-string (1+ column) ?\ )))
420 (setq name (pop plist))
421 (setq value (pop plist))
422 (cond ((eq name :char)
425 (cond ((numberp value)
426 (setq value (decode-char '=ucs value)))
428 ;; (setq value (or (find-char value)
431 (char-db-insert-char-spec value readable)
432 (insert line-breaking)
435 (insert (format "%s%s\t%d ; %c%s"
438 (ideographic-radical value)
442 (insert (format "%s%s\t%S" separator name value))
443 (setq separator line-breaking)))
447 (defun char-db-decode-isolated-char (ccs code-point)
450 (cond ((eq ccs 'arabic-iso8859-6)
451 (decode-char ccs code-point))
452 ((and (memq ccs '(=gt-pj-1
463 (setq ret (decode-char ccs code-point))
464 (setq ret (encode-char ret '=gt 'defined-only)))
465 (decode-builtin-char '=gt ret))
467 (decode-builtin-char ccs code-point))))
468 (cond ((and (<= 0 (char-int ret))
469 (<= (char-int ret) #x1F))
470 (decode-char '=ucs (+ #x2400 (char-int ret))))
471 ((= (char-int ret) #x7F)
475 (defvar char-db-convert-obsolete-format t)
477 (defun char-db-insert-ccs-feature (name value line-breaking)
483 ((memq name '(=shinjigen
485 =shinjigen@rev =shinjigen/+p@rev
487 "(%-18s . %04d)\t; %c")
488 ((eq name '=shinjigen@1ed/24pr)
489 "(%-18s . %04d)\t; %c")
490 ((or (memq name '(=daikanwa =>>daikanwa =>daikanwa
491 =daikanwa@rev1 =daikanwa@rev2
492 =daikanwa/+p =daikanwa/+2p
493 =gt =>>>gt =>>gt =+>gt =>gt
495 =adobe-japan1-0 =>>>adobe-japan1-0 =>>adobe-japan1-0
496 =adobe-japan1-1 =>>>adobe-japan1-1 =>>adobe-japan1-1
497 =adobe-japan1-2 =>>>adobe-japan1-2 =>>adobe-japan1-2
498 =adobe-japan1-3 =>>>adobe-japan1-3 =>>adobe-japan1-3
499 =adobe-japan1-4 =>>>adobe-japan1-4 =>>adobe-japan1-4
500 =adobe-japan1-5 =>>>adobe-japan1-5 =>>adobe-japan1-5
501 =adobe-japan1-6 =>>>adobe-japan1-6 =>>adobe-japan1-6
504 =zinbun-oracle =>zinbun-oracle))
505 ;; (string-match "^=adobe-" (symbol-name name))
507 "(%-18s . %05d)\t; %c")
508 ((memq name '(=hanyo-denshi/ks =>>hanyo-denshi/ks mojikyo))
509 "(%-18s . %06d)\t; %c")
510 ((>= (charset-dimension name) 2)
511 "(%-18s . #x%04X)\t; %c")
513 "(%-18s . #x%02X)\t; %c"))
515 (if (= (charset-iso-graphic-plane name) 1)
517 (cond ((= (charset-dimension name) 1)
519 ((= (charset-dimension name) 2)
521 ((= (charset-dimension name) 3)
525 (char-db-decode-isolated-char name value)))
526 (if (and (= (charset-chars name) 94)
527 (= (charset-dimension name) 2))
528 (insert (format " [%02d-%02d]"
529 (- (lsh value -8) 32)
530 (- (logand value 255) 32))))
533 (insert (format "(%-18s . %s)" name value))
535 (insert line-breaking))
537 (defun char-db-insert-relation-feature (char name value line-breaking
539 (insert (format "(%-18s%s " name line-breaking))
540 (let ((lbs (concat "\n" (make-string (current-column) ?\ )))
541 separator cell sources required-features
544 (setq cell (car value))
546 (setq cell (decode-char '=ucs cell)))
548 ((eq name '->subsumptive)
549 (when (or (not (some (lambda (atr)
550 (get-char-attribute cell atr))
551 char-db-ignored-attributes))
553 (encode-char cell ccs 'defined-only))
557 (let ((char-db-ignored-attributes
559 char-db-ignored-attributes)))
560 (insert-char-attributes cell readable nil nil 'for-sub-node))
561 (setq separator lbs))
566 char (intern (format "%s*sources" name))))
567 (setq required-features nil)
568 (dolist (source sources)
572 shinjigen shinjigen@1ed shinjigen@rev))
573 (setq required-features
574 (union required-features
585 (setq required-features
586 (union required-features
591 ((find-charset (setq ret (intern (format "=%s" source))))
592 (setq required-features
593 (cons ret required-features)))
594 (t (setq required-features
595 (cons source required-features)))))
596 (cond ((string-match "@JP" (symbol-name name))
597 (setq required-features
598 (union required-features
606 ((string-match "@CN" (symbol-name name))
607 (setq required-features
608 (union required-features
615 (insert (format "%S" cell))
616 (char-db-insert-char-spec cell readable
619 (setq separator lbs))
623 (if (consp (car cell))
624 (char-db-insert-char-spec cell readable)
625 (char-db-insert-char-reference cell readable))
626 (setq separator lbs))
630 (insert (prin1-to-string cell))
631 (setq separator " ")))
632 (setq value (cdr value)))
634 (insert line-breaking)))
636 (defun insert-char-attributes (char &optional readable attributes column
639 (setq column (current-column)))
640 (let (name value ; has-long-ccs-name
644 (concat "\n" (make-string (1+ column) ?\ )))
645 lbs cell separator ret
647 dest-ccss ; sources required-features
652 (if (consp attributes)
654 (dolist (name attributes)
655 (unless (memq name char-db-ignored-attributes)
656 (if (find-charset name)
660 (dolist (name (char-attribute-list))
661 (unless (memq name char-db-ignored-attributes)
662 (if (find-charset name)
666 #'char-attribute-name<)))
668 (when (memq '<-subsumptive attributes)
669 (when (or readable (not for-sub-node))
670 (when (setq value (get-char-attribute char '<-subsumptive))
671 (char-db-insert-relation-feature char '<-subsumptive value
674 (setq attributes (delq '<-subsumptive attributes)))
675 (when (and (memq '<-denotational attributes)
676 (setq value (get-char-attribute char '<-denotational)))
677 (char-db-insert-relation-feature char '<-denotational value
680 (setq attributes (delq '<-denotational 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 'name* attributes)
691 (setq value (get-char-attribute char 'name*)))
693 (if (> (+ (current-column) (length value)) 48)
696 value line-breaking))
697 (setq attributes (delq 'name* attributes))
699 (when (and (memq 'script attributes)
700 (setq value (get-char-attribute char 'script)))
701 (insert (format "(script\t\t%s)%s"
702 (mapconcat (function prin1-to-string)
705 (setq attributes (delq 'script attributes))
707 (dolist (name '(=>ucs =>ucs*))
708 (when (and (memq name attributes)
709 (setq value (get-char-attribute char name)))
710 (insert (format "(%-18s . #x%04X)\t; %c%s"
711 name value (decode-char '=ucs value)
713 (setq attributes (delq name attributes))))
714 (dolist (name '(=>ucs@gb =>ucs@big5))
715 (when (and (memq name attributes)
716 (setq value (get-char-attribute char name)))
717 (insert (format "(%-18s . #x%04X)\t; %c%s"
722 (symbol-name name) 2)))
725 (setq attributes (delq name attributes))
727 ;; (dolist (name '(=>daikanwa))
728 ;; (when (and (memq name attributes)
729 ;; (setq value (get-char-attribute char name)))
731 ;; (if (integerp value)
732 ;; (format "(%-18s . %05d)\t; %c%s"
733 ;; name value (decode-char '=daikanwa value)
735 ;; (format "(%-18s %s)\t; %c%s"
737 ;; (mapconcat (function prin1-to-string)
739 ;; (char-representative-of-daikanwa char)
741 ;; (setq attributes (delq name attributes))))
742 (when (and (memq 'general-category attributes)
743 (setq value (get-char-attribute char 'general-category)))
745 "(general-category\t%s) ; %s%s"
746 (mapconcat (lambda (cell)
749 (cond ((rassoc value unidata-normative-category-alist)
750 "Normative Category")
751 ((rassoc value unidata-informative-category-alist)
752 "Informative Category")
756 (setq attributes (delq 'general-category attributes))
758 (when (and (memq 'bidi-category attributes)
759 (setq value (get-char-attribute char 'bidi-category)))
760 (insert (format "(bidi-category\t. %S)%s"
763 (setq attributes (delq 'bidi-category attributes))
765 (unless (or (not (memq 'mirrored attributes))
766 (eq (setq value (get-char-attribute char 'mirrored 'empty))
768 (insert (format "(mirrored\t\t. %S)%s"
771 (setq attributes (delq 'mirrored attributes))
774 ((and (memq 'decimal-digit-value attributes)
775 (setq value (get-char-attribute char 'decimal-digit-value)))
776 (insert (format "(decimal-digit-value . %S)%s"
779 (setq attributes (delq 'decimal-digit-value attributes))
780 (when (and (memq 'digit-value attributes)
781 (setq value (get-char-attribute char 'digit-value)))
782 (insert (format "(digit-value\t . %S)%s"
785 (setq attributes (delq 'digit-value attributes))
787 (when (and (memq 'numeric-value attributes)
788 (setq value (get-char-attribute char 'numeric-value)))
789 (insert (format "(numeric-value\t . %S)%s"
792 (setq attributes (delq 'numeric-value attributes))
796 (when (and (memq 'digit-value attributes)
797 (setq value (get-char-attribute char 'digit-value)))
798 (insert (format "(digit-value\t. %S)%s"
801 (setq attributes (delq 'digit-value attributes))
803 (when (and (memq 'numeric-value attributes)
804 (setq value (get-char-attribute char 'numeric-value)))
805 (insert (format "(numeric-value\t. %S)%s"
808 (setq attributes (delq 'numeric-value attributes))
810 (when (and (memq 'iso-10646-comment attributes)
811 (setq value (get-char-attribute char 'iso-10646-comment)))
812 (insert (format "(iso-10646-comment\t. %S)%s"
815 (setq attributes (delq 'iso-10646-comment attributes))
817 (when (and (memq 'morohashi-daikanwa attributes)
818 (setq value (get-char-attribute char 'morohashi-daikanwa)))
819 (insert (format "(morohashi-daikanwa\t%s)%s"
820 (mapconcat (function prin1-to-string) value " ")
822 (setq attributes (delq 'morohashi-daikanwa attributes))
826 (when (and (memq 'ideographic-radical attributes)
827 (setq value (get-char-attribute char 'ideographic-radical)))
829 (insert (format "(ideographic-radical . %S)\t; %c%s"
831 (ideographic-radical radical)
833 (setq attributes (delq 'ideographic-radical attributes))
835 (when (and (memq 'shuowen-radical attributes)
836 (setq value (get-char-attribute char 'shuowen-radical)))
837 (insert (format "(shuowen-radical\t. %S)\t; %c%s"
839 (shuowen-radical value)
841 (setq attributes (delq 'shuowen-radical attributes))
846 char-db-feature-domains
848 (dolist (feature (char-attribute-list))
849 (setq feature (symbol-name feature))
851 "\\(radical\\|strokes\\)@\\([^@*]+\\)\\(\\*\\|$\\)"
853 (setq domain (intern (match-string 2 feature)))
854 (unless (memq domain dest)
855 (setq dest (cons domain dest)))))
856 (sort dest #'string<))))
857 (setq key (intern (format "%s@%s" 'ideographic-radical domain)))
858 (when (and (memq key attributes)
859 (setq value (get-char-attribute char key)))
861 (insert (format "(%s . %S)\t; %c%s"
864 (ideographic-radical radical)
866 (setq attributes (delq key attributes))
868 (setq key (intern (format "%s@%s" 'ideographic-strokes domain)))
869 (when (and (memq key attributes)
870 (setq value (get-char-attribute char key)))
872 (insert (format "(%s . %S)%s"
876 (setq attributes (delq key attributes))
878 (setq key (intern (format "%s@%s" 'total-strokes domain)))
879 (when (and (memq key attributes)
880 (setq value (get-char-attribute char key)))
881 (insert (format "(%s . %S)%s"
885 (setq attributes (delq key attributes))
887 (dolist (feature '(ideographic-radical
890 (setq key (intern (format "%s@%s*sources" feature domain)))
891 (when (and (memq key attributes)
892 (setq value (get-char-attribute char key)))
893 (insert (format "(%s%s" key line-breaking))
895 (insert (format " %s" cell)))
897 (insert line-breaking)
898 (setq attributes (delq key attributes))
901 (when (and (memq 'ideographic-strokes attributes)
902 (setq value (get-char-attribute char 'ideographic-strokes)))
904 (insert (format "(ideographic-strokes . %S)%s"
907 (setq attributes (delq 'ideographic-strokes attributes))
909 (when (and (memq 'kangxi-radical attributes)
910 (setq value (get-char-attribute char 'kangxi-radical)))
911 (unless (eq value radical)
912 (insert (format "(kangxi-radical\t . %S)\t; %c%s"
914 (ideographic-radical value)
917 (setq radical value)))
918 (setq attributes (delq 'kangxi-radical attributes))
920 (when (and (memq 'kangxi-strokes attributes)
921 (setq value (get-char-attribute char 'kangxi-strokes)))
922 (unless (eq value strokes)
923 (insert (format "(kangxi-strokes\t . %S)%s"
927 (setq strokes value)))
928 (setq attributes (delq 'kangxi-strokes attributes))
930 (when (and (memq 'japanese-radical attributes)
931 (setq value (get-char-attribute char 'japanese-radical)))
932 (unless (eq value radical)
933 (insert (format "(japanese-radical\t . %S)\t; %c%s"
935 (ideographic-radical value)
938 (setq radical value)))
939 (setq attributes (delq 'japanese-radical attributes))
941 (when (and (memq 'japanese-strokes attributes)
942 (setq value (get-char-attribute char 'japanese-strokes)))
943 (unless (eq value strokes)
944 (insert (format "(japanese-strokes\t . %S)%s"
948 (setq strokes value)))
949 (setq attributes (delq 'japanese-strokes attributes))
951 (when (and (memq 'cns-radical attributes)
952 (setq value (get-char-attribute char 'cns-radical)))
953 (insert (format "(cns-radical\t . %S)\t; %c%s"
955 (ideographic-radical value)
957 (setq attributes (delq 'cns-radical attributes))
959 (when (and (memq 'cns-strokes attributes)
960 (setq value (get-char-attribute char 'cns-strokes)))
961 (unless (eq value strokes)
962 (insert (format "(cns-strokes\t . %S)%s"
966 (setq strokes value)))
967 (setq attributes (delq 'cns-strokes attributes))
969 (when (and (memq 'shinjigen-1-radical attributes)
970 (setq value (get-char-attribute char 'shinjigen-1-radical)))
971 (unless (eq value radical)
972 (insert (format "(shinjigen-1-radical . %S)\t; %c%s"
974 (ideographic-radical value)
977 (setq radical value)))
978 (setq attributes (delq 'shinjigen-1-radical attributes))
980 (when (and (memq 'ideographic- attributes)
981 (setq value (get-char-attribute char 'ideographic-)))
982 (insert "(ideographic- ")
983 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
986 (setq cell (car value))
988 (setq cell (decode-char '=ucs cell)))
989 (cond ((characterp cell)
993 (insert (format "%S" cell))
994 (char-db-insert-char-spec cell readable))
995 (setq separator lbs))
999 (if (consp (car cell))
1000 (char-db-insert-char-spec cell readable)
1001 (char-db-insert-char-reference cell readable))
1002 (setq separator lbs))
1006 (insert (prin1-to-string cell))
1007 (setq separator " ")))
1008 (setq value (cdr value)))
1010 (insert line-breaking)
1011 (setq attributes (delq 'ideographic- attributes)))
1012 (when (and (memq 'total-strokes attributes)
1013 (setq value (get-char-attribute char 'total-strokes)))
1014 (insert (format "(total-strokes . %S)%s"
1017 (setq attributes (delq 'total-strokes attributes))
1019 (when (and (memq '->ideograph attributes)
1020 (setq value (get-char-attribute char '->ideograph)))
1021 (insert (format "(->ideograph\t%s)%s"
1022 (mapconcat (lambda (code)
1023 (cond ((symbolp code)
1026 (format "#x%04X" code))
1029 line-breaking code))))
1032 (setq attributes (delq '->ideograph attributes))
1034 ;; (when (and (memq '->decomposition attributes)
1035 ;; (setq value (get-char-attribute char '->decomposition)))
1036 ;; (insert (format "(->decomposition\t%s)%s"
1037 ;; (mapconcat (lambda (code)
1038 ;; (cond ((symbolp code)
1039 ;; (symbol-name code))
1040 ;; ((characterp code)
1042 ;; (format "%S" code)
1047 ;; (format "#x%04X" code))
1049 ;; (format "%s%S" line-breaking code))))
1052 ;; (setq attributes (delq '->decomposition attributes))
1054 (if (equal (get-char-attribute char '->titlecase)
1055 (get-char-attribute char '->uppercase))
1056 (setq attributes (delq '->titlecase attributes)))
1057 (when (and (memq '->mojikyo attributes)
1058 (setq value (get-char-attribute char '->mojikyo)))
1059 (insert (format "(->mojikyo\t\t. %06d)\t; %c%s"
1060 value (decode-char 'mojikyo value)
1062 (setq attributes (delq '->mojikyo attributes))
1064 (when (and (memq 'hanyu-dazidian-vol attributes)
1065 (setq value (get-char-attribute char 'hanyu-dazidian-vol)))
1066 (insert (format "(hanyu-dazidian-vol . %d)%s"
1067 value line-breaking))
1068 (setq attributes (delq 'hanyu-dazidian-vol attributes))
1070 (when (and (memq 'hanyu-dazidian-page attributes)
1071 (setq value (get-char-attribute char 'hanyu-dazidian-page)))
1072 (insert (format "(hanyu-dazidian-page . %d)%s"
1073 value line-breaking))
1074 (setq attributes (delq 'hanyu-dazidian-page attributes))
1076 (when (and (memq 'hanyu-dazidian-char attributes)
1077 (setq value (get-char-attribute char 'hanyu-dazidian-char)))
1078 (insert (format "(hanyu-dazidian-char . %d)%s"
1079 value line-breaking))
1080 (setq attributes (delq 'hanyu-dazidian-char attributes))
1083 (dolist (ignored '(composition
1084 ->denotational <-subsumptive ->ucs-unified
1085 ->ideographic-component-forms))
1086 (setq attributes (delq ignored attributes))))
1088 (setq name (car attributes))
1089 (unless (eq (setq value (get-char-attribute char name 'value-is-empty))
1091 (cond ((setq ret (find-charset name))
1092 (setq name (charset-name ret))
1093 (when (not (memq name dest-ccss))
1094 (setq dest-ccss (cons name dest-ccss))
1095 (char-db-insert-ccs-feature name value line-breaking))
1097 ((string-match "^=>ucs@" (symbol-name name))
1098 (insert (format "(%-18s . #x%04X)\t; %c%s"
1099 name value (decode-char '=ucs value)
1102 ((eq name 'jisx0208-1978/4X)
1103 (insert (format "(%-18s . #x%04X)%s"
1109 (not (eq name '->subsumptive))
1110 (not (eq name '->uppercase))
1111 (not (eq name '->lowercase))
1112 (not (eq name '->titlecase))
1113 (not (eq name '->canonical))
1114 (not (eq name '->Bopomofo))
1115 (not (eq name '->mistakable))
1116 (not (eq name '->ideographic-variants))
1117 (null (get-char-attribute
1118 char (intern (format "%s*sources" name))))
1119 (not (string-match "\\*sources$" (symbol-name name)))
1120 (null (get-char-attribute
1121 char (intern (format "%s*note" name))))
1122 (not (string-match "\\*note$" (symbol-name name)))
1123 (or (eq name '<-identical)
1124 (eq name '<-uppercase)
1125 (eq name '<-lowercase)
1126 (eq name '<-titlecase)
1127 (eq name '<-canonical)
1128 (eq name '<-ideographic-variants)
1129 ;; (eq name '<-synonyms)
1130 (string-match "^<-synonyms" (symbol-name name))
1131 (eq name '<-mistakable)
1132 (when (string-match "^->" (symbol-name name))
1134 ((string-match "^->fullwidth" (symbol-name name))
1135 (not (and (consp value)
1136 (characterp (car value))
1138 (car value) '=ucs 'defined-only)))
1143 ((or (eq name 'ideographic-structure)
1144 (eq name 'ideographic-combination)
1145 (eq name 'ideographic-)
1146 (eq name '=decomposition)
1147 (char-feature-base-name= '=decomposition name)
1148 (char-feature-base-name= '=>decomposition name)
1149 ;; (string-match "^=>*decomposition\\(@[^*]+\\)?$"
1150 ;; (symbol-name name))
1151 (string-match "^\\(->\\|<-\\)[^*]*$" (symbol-name name))
1152 (string-match "^\\(->\\|<-\\)[^*]*\\*sources$"
1155 (char-db-insert-relation-feature char name value
1158 ((memq name '(ideograph=
1159 original-ideograph-of
1160 ancient-ideograph-of
1163 ;; simplified-ideograph-of
1164 ideographic-variants
1165 ;; ideographic-different-form-of
1167 (insert (format "(%-18s%s " name line-breaking))
1168 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1170 (while (consp value)
1171 (setq cell (car value))
1172 (if (and (consp cell)
1177 (char-db-insert-alist cell readable)
1178 (setq separator lbs))
1181 (insert (prin1-to-string cell))
1182 (setq separator " "))
1183 (setq value (cdr value)))
1185 (insert line-breaking))
1187 (insert (format "(%-18s " name))
1188 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1190 (while (consp value)
1191 (setq cell (car value))
1192 (if (and (consp cell)
1194 (setq ret (condition-case nil
1202 (setq key (car (car rest)))
1203 (if (find-charset key)
1204 (setq cal (cons key cal))
1205 (setq al (cons key al)))
1206 (setq rest (cdr rest)))
1209 (insert-char-attributes ret
1213 (setq separator lbs))
1214 (setq ret (prin1-to-string cell))
1216 (if (< (+ (current-column)
1223 (setq separator " "))
1224 (setq value (cdr value)))
1226 (insert line-breaking))
1228 (insert (format "(%-18s" name))
1229 (setq ret (prin1-to-string value))
1230 (unless (< (+ (current-column)
1234 (insert line-breaking))
1235 (insert " . " ret ")" line-breaking)
1236 ;; (insert (format "(%-18s . %S)%s"
1241 (setq attributes (cdr attributes)))
1244 (defun insert-char-data (char &optional readable
1247 (narrow-to-region (point)(point))
1248 (insert "(define-char
1250 (insert-char-attributes char readable attributes)
1252 (goto-char (point-min))
1253 (while (re-search-forward "[ \t]+$" nil t)
1256 (goto-char (point-min))
1257 (while (re-search-forward "[ \t][ \t][ \t]*" nil t)
1258 (let ((column (current-column))
1259 (indent-tabs-mode t))
1260 (delete-region (match-beginning 0) (point))
1261 (indent-to column)))
1262 (goto-char (point-max))
1263 ;; (tabify (point-min)(point-max))
1266 (defun insert-char-data-with-variant (char &optional printable
1268 script excluded-script)
1269 (insert-char-data char printable)
1270 (let ((variants (char-variants char))
1273 (setq variants (sort variants #'<))
1274 (setq rest variants)
1275 (setq variants (cons char variants))
1277 (setq variant (car rest))
1278 (unless (get-char-attribute variant '<-subsumptive)
1279 (if (and (or (null script)
1280 (null (setq vs (get-char-attribute variant 'script)))
1282 (or (null excluded-script)
1283 (null (setq vs (get-char-attribute variant 'script)))
1284 (not (memq excluded-script vs))))
1285 (unless (and no-ucs-unified (get-char-attribute variant '=ucs))
1286 (insert-char-data variant printable)
1287 (if (setq ret (char-variants variant))
1289 (or (memq (car ret) variants)
1290 ;; (get-char-attribute (car ret) '<-subsumptive)
1291 (setq rest (nconc rest (list (car ret)))))
1292 (setq ret (cdr ret)))))))
1293 (setq rest (cdr rest)))))
1295 (defun insert-char-range-data (min max &optional script excluded-script)
1298 (while (<= code max)
1299 (setq char (decode-char '=ucs code))
1300 (if (encode-char char '=ucs 'defined-only)
1301 (insert-char-data-with-variant char nil 'no-ucs-unified
1302 script excluded-script))
1303 (setq code (1+ code)))))
1305 (defun write-char-range-data-to-file (min max file
1306 &optional script excluded-script)
1307 (let ((coding-system-for-write char-db-file-coding-system))
1309 (insert (format ";; -*- coding: %s -*-\n"
1310 char-db-file-coding-system))
1311 (insert-char-range-data min max script excluded-script)
1312 (write-region (point-min)(point-max) file))))
1314 (defvar what-character-original-window-configuration)
1317 (defun what-char-definition (char)
1318 (interactive (list (char-after)))
1319 (let ((buf (get-buffer-create "*Character Description*"))
1320 (the-buf (current-buffer))
1321 (win-conf (current-window-configuration)))
1323 (make-local-variable 'what-character-original-window-configuration)
1324 (setq what-character-original-window-configuration win-conf)
1325 (setq buffer-read-only nil)
1329 (insert-char-data-with-variant char 'printable)
1330 (unless (char-attribute-alist char)
1331 (insert (format ";; = %c\n"
1332 (let* ((rest (split-char char))
1336 (setq code (logior (lsh code 8)
1338 (decode-char ccs code)))))
1339 ;; (char-db-update-comment)
1340 (set-buffer-modified-p nil)
1341 (view-mode the-buf (lambda (buf)
1342 (set-window-configuration
1343 what-character-original-window-configuration)
1345 (goto-char (point-min)))
1347 (set-window-configuration
1348 what-character-original-window-configuration)
1349 (signal (car err) (cdr err)))))))
1355 (provide 'char-db-util)
1357 ;;; char-db-util.el ends here