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, 2012, 2013, 2014 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 ; ?旨 ?曰 ?乃 ?丂 ?可 ?兮 ?号 ?亏 ?喜 ?壴 ; 160
84 ?鼓 ?豈 ?豆 ?豊 ?豐 ?䖒 ?虍 ?虎 ?虤 ?皿 ; 170
85 ?𠙴 ?去 ?血 ?丶 ?丹 ?青 ?井 ?皀 ?鬯 ?食 ; 180
86 ?亼 ?會 ?倉 ?入 ?缶 ?矢 ?高 ?冂 ?𩫏 ?京 ; 190
87 ?亯 ?𣆪 ?畗 ?㐭 ?嗇 ?來 ?麥 ?夊 ?舛 ?䑞 ; 200
88 ?韋 ?弟 ?夂 ?久 ?桀 ?木 ?東 ?林 ?才 ?叒 ; 210
89 ?之 ?帀 ?出 ?𣎵 ?生 ?乇 ?𠂹 ?𠌶 ?華 ?𥝌 ; 220
90 ?稽 ?巢 ?桼 ?束 ?㯻 ?囗 ?員 ?貝 ?邑 ?𨛜 ; 230
91 ?日 ?旦 ?倝 ?㫃 ?冥 ?晶 ?月 ?有 ?明 ?囧 ; 240
92 ?夕 ?多 ?毌 ?𢎘 ?𣐺 ?卣 ?齊 ?朿 ?片 ?鼎 ; 250
93 ?克 ?彔 ?禾 ?秝 ?黍 ?香 ?米 ?毇 ?臼 ?凶 ; 260
94 ?𣎳 ?林 ?麻 ?尗 ?耑 ?韭 ?瓜 ?瓠 ?宀 ?宮 ; 270
95 ?呂 ?穴 ?㝱 ?𤕫 ?冖 ?𠔼 ?冃 ?㒳 ?网 ?襾 ; 280
96 ?巾 ?巿 ?帛 ?白 ?㡀 ?黹 ?人 ?𠤎 ?匕 ?从 ; 290
97 ?比 ?北 ?丘 ?㐺 ?𡈼 ?重 ?臥 ?身 ?㐆 ?衣 ; 300
98 ?裘 ?老 ?毛 ?毳 ?尸 ?尺 ?尾 ?履 ?舟 ?方 ; 310
99 ?儿 ?兄 ?兂 ?皃 ?𠑹 ?先 ?秃 ?見 ?覞 ?欠 ; 320
100 ?㱃 ?㳄 ?旡 ?頁 ?𦣻 ?面 ?丏 ?首 ?𥄉 ?須 ; 330
101 ?彡 ?彣 ?文 ?髟 ?后 ?司 ?卮 ?卩 ?印 ?色 ; 340
102 ?𠨍 ?辟 ?勹 ?包 ?茍 ?鬼 ?甶 ?厶 ?嵬 ?山 ; 350
103 ?屾 ?屵 ?广 ?厂 ?丸 ?危 ?石 ?長 ?勿 ?冄 ; 360
104 ?而 ?豕 ?㣇 ?彑 ?豚 ?豸 ?𤉡 ?易 ?象 ?馬 ; 370
107 (defun shuowen-radical (number)
108 (aref shuowen-radicals (1- number)))
110 (defvar char-db-file-coding-system 'utf-8-mcs-er)
112 (defvar char-db-ignored-attributes '(ideographic-products))
114 (defvar char-db-coded-charset-priority-list
207 ;; =>>>adobe-japan1-0
208 ;; =>>>adobe-japan1-1
209 ;; =>>>adobe-japan1-2
210 ;; =>>>adobe-japan1-3
211 ;; =>>>adobe-japan1-4
212 ;; =>>>adobe-japan1-5
213 ;; =>>>adobe-japan1-6
217 ;; =>>>hanyo-denshi/ja
218 ;; =>>>hanyo-denshi/jb
219 ;; =>>>hanyo-denshi/jc
220 ;; =>>>hanyo-denshi/ft
221 ;; =>>>hanyo-denshi/ib
222 ;; =>>>hanyo-denshi/hg
223 ;; =>>>hanyo-denshi/jt
224 ;; =>>>hanyo-denshi/ks
325 ;;; @ char-db formatters
328 (defun char-db-make-char-spec (char)
330 (cond ((characterp char)
331 (cond ((and (setq ret (encode-char char '=ucs 'defined-only))
332 (not (and (<= #xE000 ret)(<= ret #xF8FF))))
333 (setq char-spec (list (cons '=ucs ret)))
334 (cond ((setq ret (get-char-attribute char 'name))
335 (setq char-spec (cons (cons 'name ret) char-spec))
337 ((setq ret (get-char-attribute char 'name*))
338 (setq char-spec (cons (cons 'name* ret) char-spec))
341 ((encode-char char '=mj 'defined-only)
343 (dolist (ccs (charset-list))
344 (if (and (or (eq ccs '=mj)
345 ;; (eq (charset-property ccs 'iso-ir) 177)
346 (string-match "=ucs@" (symbol-name ccs))
348 (setq ccs (charset-name ccs))
349 (null (assq ccs char-spec))
350 (setq ret (encode-char char ccs 'defined-only)))
351 (setq char-spec (cons (cons ccs ret) char-spec))))
353 ((encode-char char '==mj 'defined-only)
355 (dolist (ccs (charset-list))
356 (if (and (or (eq ccs '==mj)
357 ;; (eq (charset-property ccs 'iso-ir) 177)
358 (string-match "=ucs@" (symbol-name ccs))
360 (setq ccs (charset-name ccs))
361 (null (assq ccs char-spec))
362 (setq ret (encode-char char ccs 'defined-only)))
363 (setq char-spec (cons (cons ccs ret) char-spec))))
365 ((encode-char char '=adobe-japan1 'defined-only)
367 (dolist (ccs (charset-list))
368 (if (and (or (memq ccs
377 ;; (eq (charset-property ccs 'iso-ir) 177)
378 (string-match "=ucs@" (symbol-name ccs))
380 (setq ccs (charset-name ccs))
381 (null (assq ccs char-spec))
382 (setq ret (encode-char char ccs 'defined-only)))
383 (setq char-spec (cons (cons ccs ret) char-spec))))
385 ((encode-char char '==adobe-japan1 'defined-only)
387 (dolist (ccs (charset-list))
388 (if (and (or (memq ccs
397 ;; (eq (charset-property ccs 'iso-ir) 177)
398 (string-match "=ucs@" (symbol-name ccs))
400 (setq ccs (charset-name ccs))
401 (null (assq ccs char-spec))
402 (setq ret (encode-char char ccs 'defined-only)))
403 (setq char-spec (cons (cons ccs ret) char-spec))))
407 (let ((rest char-db-coded-charset-priority-list)
410 (setq ccs (charset-name
411 (find-charset (car rest))))
413 (encode-char char ccs
415 (throw 'tag (cons ccs ret)))
416 (setq rest (cdr rest))))))
417 (setq char-spec (list ret))
418 (dolist (ccs (delq (car ret) (charset-list)))
419 (if (and (or (charset-iso-final-char ccs)
426 (eq (charset-property ccs 'iso-ir) 177)
427 ;; (string-match "=ucs@" (symbol-name ccs))
429 (setq ccs (charset-name ccs))
430 (null (assq ccs char-spec))
431 (setq ret (encode-char char ccs 'defined-only)))
432 (setq char-spec (cons (cons ccs ret) char-spec))))
434 (setq char-spec (split-char char)))
435 (cond ((setq ret (get-char-attribute char 'name))
436 (setq char-spec (cons (cons 'name ret) char-spec))
438 ((setq ret (get-char-attribute char 'name*))
439 (setq char-spec (cons (cons 'name* ret) char-spec))
442 ((setq ret (get-char-attribute
443 char 'ideographic-combination))
445 (cons (cons 'ideographic-combination ret)
452 (defun char-db-insert-char-spec (char &optional readable column
455 (setq column (current-column)))
456 (let (char-spec temp-char)
457 (setq char-spec (char-db-make-char-spec char))
458 (unless (or (characterp char) ; char
460 (setq char (find-char char-spec))
462 ;; define temporary character
463 ;; Current implementation is dirty.
464 (setq temp-char (define-char (cons '(ideograph-daikanwa . 0)
466 (remove-char-attribute temp-char 'ideograph-daikanwa)
467 (setq char temp-char))
468 (insert-char-attributes char
470 (union (mapcar #'car char-spec)
474 ;; undefine temporary character
475 ;; Current implementation is dirty.
476 (setq char-spec (char-attribute-alist temp-char))
478 (remove-char-attribute temp-char (car (car char-spec)))
479 (setq char-spec (cdr char-spec))))))
481 (defun char-db-insert-alist (alist &optional readable column)
483 (setq column (current-column)))
485 (concat "\n" (make-string (1+ column) ?\ )))
489 lbs cell rest separator)
492 (setq name (car (car alist))
493 value (cdr (car alist)))
494 (cond ((eq name 'char)
496 (if (setq ret (condition-case nil
504 (setq key (car (car value)))
505 ;; (if (find-charset key)
506 ;; (setq cal (cons key cal))
507 (setq al (cons key al))
509 (setq value (cdr value)))
510 (insert-char-attributes ret
514 (insert (prin1-to-string value)))
516 (insert line-breaking))
518 (insert (format "(%-18s " name))
519 (setq lbs (concat "\n" (make-string (current-column) ?\ )))
521 (setq cell (car value))
522 (if (and (consp cell)
524 (setq ret (condition-case nil
534 (setq key (car (car rest)))
535 ;; (if (find-charset key)
536 ;; (setq cal (cons key cal))
537 (setq al (cons key al))
539 (setq rest (cdr rest)))
542 (insert-char-attributes ret
546 (setq separator lbs))
549 (insert (prin1-to-string cell))
550 (setq separator " "))
551 (setq value (cdr value)))
553 (insert line-breaking))
555 (insert (format "(%-18s . %S)%s"
558 (setq alist (cdr alist))))
561 (defun char-db-insert-char-reference (plist &optional readable column)
563 (setq column (current-column)))
565 (concat "\n" (make-string (1+ column) ?\ )))
570 (setq name (pop plist))
571 (setq value (pop plist))
572 (cond ((eq name :char)
575 (cond ((numberp value)
576 (setq value (decode-char '=ucs value)))
578 ;; (setq value (or (find-char value)
581 (char-db-insert-char-spec value readable)
582 (insert line-breaking)
585 (insert (format "%s%s\t%d ; %c%s"
588 (ideographic-radical value)
592 (insert (format "%s%s\t%S" separator name value))
593 (setq separator line-breaking)))
597 (defun char-db-decode-isolated-char (ccs code-point)
600 (cond ((eq ccs 'arabic-iso8859-6)
601 (decode-char ccs code-point))
603 ;; (decode-builtin-char '==gt code-point))
604 ((and (memq ccs '(=gt-pj-1
615 (setq ret (decode-char ccs code-point))
616 (setq ret (encode-char ret '=gt 'defined-only)))
617 (decode-builtin-char '=gt ret))
619 (decode-builtin-char ccs code-point))))
620 (cond ((and (<= 0 (char-int ret))
621 (<= (char-int ret) #x1F))
622 (decode-char '=ucs (+ #x2400 (char-int ret))))
623 ((= (char-int ret) #x7F)
627 (defvar char-db-convert-obsolete-format t)
629 (defun char-db-insert-ccs-feature (name value line-breaking)
635 ((memq name '(==shinjigen
637 =shinjigen@1ed ==shinjigen@1ed
638 =shinjigen@rev ==shinjigen@rev
639 =shinjigen/+p@rev ==shinjigen/+p@rev
640 ===daikanwa/ho ==daikanwa/ho
641 =daikanwa/ho =>>daikanwa/ho =>daikanwa/ho))
642 "(%-18s . %04d)\t; %c")
643 ((eq name '=shinjigen@1ed/24pr)
644 "(%-18s . %04d)\t; %c")
645 ((or (memq name '(===daikanwa
646 ==daikanwa =daikanwa =>>daikanwa =>daikanwa
647 =daikanwa@rev1 =daikanwa@rev2
648 =daikanwa/+p ==daikanwa/+p ===daikanwa/+p
650 =daikanwa/+2p =>>daikanwa/+2p
655 =adobe-japan1-0 ==adobe-japan1-0 ===adobe-japan1-0
656 =adobe-japan1-1 ==adobe-japan1-1 ===adobe-japan1-1
657 =adobe-japan1-2 ==adobe-japan1-2 ===adobe-japan1-2
658 =adobe-japan1-3 ==adobe-japan1-3 ===adobe-japan1-3
659 =adobe-japan1-4 ==adobe-japan1-4 ===adobe-japan1-4
660 =adobe-japan1-5 ==adobe-japan1-5 ===adobe-japan1-5
661 =adobe-japan1-6 ==adobe-japan1-6 ===adobe-japan1-6
662 =>>adobe-japan1-0 =+>adobe-japan1-0
663 =>>adobe-japan1-1 =+>adobe-japan1-1
664 =>>adobe-japan1-2 =+>adobe-japan1-2
665 =>>adobe-japan1-3 =+>adobe-japan1-3
666 =>>adobe-japan1-4 =+>adobe-japan1-4
667 =>>adobe-japan1-5 =+>adobe-japan1-5
668 =>>adobe-japan1-6 =+>adobe-japan1-6
669 =cbeta ==cbeta ===cbeta =>>cbeta
670 =zinbun-oracle =>zinbun-oracle))
671 ;; (string-match "^=adobe-" (symbol-name name))
673 "(%-18s . %05d)\t; %c")
674 ((memq name '(=hanyo-denshi/ks
675 ==hanyo-denshi/ks ===hanyo-denshi/ks
680 "(%-18s . %06d)\t; %c")
681 ((>= (charset-dimension name) 2)
682 "(%-18s . #x%04X)\t; %c")
684 "(%-18s . #x%02X)\t; %c"))
686 (if (= (charset-iso-graphic-plane name) 1)
688 (cond ((= (charset-dimension name) 1)
690 ((= (charset-dimension name) 2)
692 ((= (charset-dimension name) 3)
696 (char-db-decode-isolated-char name value)))
697 (if (and (= (charset-chars name) 94)
698 (= (charset-dimension name) 2))
699 (insert (format " [%02d-%02d]"
700 (- (lsh value -8) 32)
701 (- (logand value 255) 32))))
704 (insert (format "(%-18s . %s)" name value))
706 (insert line-breaking))
708 (defun char-db-insert-relation-feature (char name value line-breaking
710 (insert (format "(%-18s%s " name line-breaking))
711 (let ((lbs (concat "\n" (make-string (current-column) ?\ )))
712 separator cell sources required-features
715 (setq cell (car value))
717 (setq cell (decode-char '=ucs cell)))
719 ((eq name '->subsumptive)
720 (when (or (not (some (lambda (atr)
721 (get-char-attribute cell atr))
722 char-db-ignored-attributes))
724 (encode-char cell ccs 'defined-only))
728 (let ((char-db-ignored-attributes
730 char-db-ignored-attributes)))
731 (insert-char-attributes cell readable nil nil 'for-sub-node))
732 (setq separator lbs))
737 char (intern (format "%s*sources" name))))
738 (setq required-features nil)
739 (dolist (source sources)
743 shinjigen shinjigen@1ed shinjigen@rev))
744 (setq required-features
745 (union required-features
757 =shinjigen/+p@rev))))
759 (setq required-features
760 (union required-features
765 ((find-charset (setq ret (intern (format "=%s" source))))
766 (setq required-features
767 (cons ret required-features)))
768 (t (setq required-features
769 (cons source required-features)))))
770 (cond ((string-match "@JP" (symbol-name name))
771 (setq required-features
772 (union required-features
780 ((string-match "@CN" (symbol-name name))
781 (setq required-features
782 (union required-features
789 (insert (format "%S" cell))
790 (char-db-insert-char-spec cell readable
793 (setq separator lbs))
797 (if (consp (car cell))
798 (char-db-insert-char-spec cell readable)
799 (char-db-insert-char-reference cell readable))
800 (setq separator lbs))
804 (insert (prin1-to-string cell))
805 (setq separator " ")))
806 (setq value (cdr value)))
808 (insert line-breaking)))
810 (defun insert-char-attributes (char &optional readable attributes column
813 (setq column (current-column)))
814 (let (name value ; has-long-ccs-name
818 (concat "\n" (make-string (1+ column) ?\ )))
819 lbs cell separator ret
821 dest-ccss ; sources required-features
826 (if (consp attributes)
828 (dolist (name attributes)
829 (unless (memq name char-db-ignored-attributes)
830 (if (find-charset name)
834 (dolist (name (char-attribute-list))
835 (unless (memq name char-db-ignored-attributes)
836 (if (find-charset name)
840 #'char-attribute-name<)))
842 (when (memq '<-subsumptive attributes)
843 (when (or readable (not for-sub-node))
844 (when (setq value (get-char-attribute char '<-subsumptive))
845 (char-db-insert-relation-feature char '<-subsumptive value
848 (setq attributes (delq '<-subsumptive attributes)))
849 (when (and (memq '<-denotational attributes)
850 (setq value (get-char-attribute char '<-denotational)))
851 (char-db-insert-relation-feature char '<-denotational value
854 (setq attributes (delq '<-denotational attributes)))
855 (when (and (memq 'name attributes)
856 (setq value (get-char-attribute char 'name)))
858 (if (> (+ (current-column) (length value)) 48)
861 value line-breaking))
862 (setq attributes (delq 'name attributes))
864 (when (and (memq 'name* attributes)
865 (setq value (get-char-attribute char 'name*)))
867 (if (> (+ (current-column) (length value)) 48)
870 value line-breaking))
871 (setq attributes (delq 'name* attributes))
873 (when (and (memq 'script attributes)
874 (setq value (get-char-attribute char 'script)))
875 (insert (format "(script\t\t%s)%s"
876 (mapconcat (function prin1-to-string)
879 (setq attributes (delq 'script attributes))
881 (dolist (name '(=>ucs =>ucs*))
882 (when (and (memq name attributes)
883 (setq value (get-char-attribute char name)))
884 (insert (format "(%-18s . #x%04X)\t; %c%s"
885 name value (decode-char '=ucs value)
887 (setq attributes (delq name attributes))))
888 (dolist (name '(=>ucs@gb =>ucs@big5))
889 (when (and (memq name attributes)
890 (setq value (get-char-attribute char name)))
891 (insert (format "(%-18s . #x%04X)\t; %c%s"
896 (symbol-name name) 2)))
899 (setq attributes (delq name attributes))
901 ;; (dolist (name '(=>daikanwa))
902 ;; (when (and (memq name attributes)
903 ;; (setq value (get-char-attribute char name)))
905 ;; (if (integerp value)
906 ;; (format "(%-18s . %05d)\t; %c%s"
907 ;; name value (decode-char '=daikanwa value)
909 ;; (format "(%-18s %s)\t; %c%s"
911 ;; (mapconcat (function prin1-to-string)
913 ;; (char-representative-of-daikanwa char)
915 ;; (setq attributes (delq name attributes))))
916 (when (and (memq 'general-category attributes)
917 (setq value (get-char-attribute char 'general-category)))
919 "(general-category\t%s) ; %s%s"
920 (mapconcat (lambda (cell)
923 (cond ((rassoc value unidata-normative-category-alist)
924 "Normative Category")
925 ((rassoc value unidata-informative-category-alist)
926 "Informative Category")
930 (setq attributes (delq 'general-category attributes))
932 (when (and (memq 'bidi-category attributes)
933 (setq value (get-char-attribute char 'bidi-category)))
934 (insert (format "(bidi-category\t. %S)%s"
937 (setq attributes (delq 'bidi-category attributes))
939 (unless (or (not (memq 'mirrored attributes))
940 (eq (setq value (get-char-attribute char 'mirrored 'empty))
942 (insert (format "(mirrored\t\t. %S)%s"
945 (setq attributes (delq 'mirrored attributes))
948 ((and (memq 'decimal-digit-value attributes)
949 (setq value (get-char-attribute char 'decimal-digit-value)))
950 (insert (format "(decimal-digit-value . %S)%s"
953 (setq attributes (delq 'decimal-digit-value attributes))
954 (when (and (memq 'digit-value attributes)
955 (setq value (get-char-attribute char 'digit-value)))
956 (insert (format "(digit-value\t . %S)%s"
959 (setq attributes (delq 'digit-value attributes))
961 (when (and (memq 'numeric-value attributes)
962 (setq value (get-char-attribute char 'numeric-value)))
963 (insert (format "(numeric-value\t . %S)%s"
966 (setq attributes (delq 'numeric-value attributes))
970 (when (and (memq 'digit-value attributes)
971 (setq value (get-char-attribute char 'digit-value)))
972 (insert (format "(digit-value\t. %S)%s"
975 (setq attributes (delq 'digit-value attributes))
977 (when (and (memq 'numeric-value attributes)
978 (setq value (get-char-attribute char 'numeric-value)))
979 (insert (format "(numeric-value\t. %S)%s"
982 (setq attributes (delq 'numeric-value attributes))
984 (when (and (memq 'iso-10646-comment attributes)
985 (setq value (get-char-attribute char 'iso-10646-comment)))
986 (insert (format "(iso-10646-comment\t. %S)%s"
989 (setq attributes (delq 'iso-10646-comment attributes))
991 (when (and (memq 'morohashi-daikanwa attributes)
992 (setq value (get-char-attribute char 'morohashi-daikanwa)))
993 (insert (format "(morohashi-daikanwa\t%s)%s"
994 (mapconcat (function prin1-to-string) value " ")
996 (setq attributes (delq 'morohashi-daikanwa attributes))
1000 (when (and (memq 'ideographic-radical attributes)
1001 (setq value (get-char-attribute char 'ideographic-radical)))
1002 (setq radical value)
1003 (insert (format "(ideographic-radical . %S)\t; %c%s"
1005 (ideographic-radical radical)
1007 (setq attributes (delq 'ideographic-radical attributes))
1009 (when (and (memq 'shuowen-radical attributes)
1010 (setq value (get-char-attribute char 'shuowen-radical)))
1011 (insert (format "(shuowen-radical\t. %S)\t; %c%s"
1013 (shuowen-radical value)
1015 (setq attributes (delq 'shuowen-radical attributes))
1020 char-db-feature-domains
1022 (dolist (feature (char-attribute-list))
1023 (setq feature (symbol-name feature))
1025 "\\(radical\\|strokes\\)@\\([^@*]+\\)\\(\\*\\|$\\)"
1027 (setq domain (intern (match-string 2 feature)))
1028 (unless (memq domain dest)
1029 (setq dest (cons domain dest)))))
1030 (sort dest #'string<))))
1031 (setq key (intern (format "%s@%s" 'ideographic-radical domain)))
1032 (when (and (memq key attributes)
1033 (setq value (get-char-attribute char key)))
1034 (setq radical value)
1035 (insert (format "(%s . %S)\t; %c%s"
1038 (ideographic-radical radical)
1040 (setq attributes (delq key attributes))
1042 (setq key (intern (format "%s@%s" 'ideographic-strokes domain)))
1043 (when (and (memq key attributes)
1044 (setq value (get-char-attribute char key)))
1045 (setq strokes value)
1046 (insert (format "(%s . %S)%s"
1050 (setq attributes (delq key attributes))
1052 (setq key (intern (format "%s@%s" 'total-strokes domain)))
1053 (when (and (memq key attributes)
1054 (setq value (get-char-attribute char key)))
1055 (insert (format "(%s . %S)%s"
1059 (setq attributes (delq key attributes))
1061 (dolist (feature '(ideographic-radical
1064 (setq key (intern (format "%s@%s*sources" feature domain)))
1065 (when (and (memq key attributes)
1066 (setq value (get-char-attribute char key)))
1067 (insert (format "(%s%s" key line-breaking))
1068 (dolist (cell value)
1069 (insert (format " %s" cell)))
1071 (insert line-breaking)
1072 (setq attributes (delq key attributes))
1075 (when (and (memq 'ideographic-strokes attributes)
1076 (setq value (get-char-attribute char 'ideographic-strokes)))
1077 (setq strokes value)
1078 (insert (format "(ideographic-strokes . %S)%s"
1081 (setq attributes (delq 'ideographic-strokes attributes))
1083 (when (and (memq 'kangxi-radical attributes)
1084 (setq value (get-char-attribute char 'kangxi-radical)))
1085 (unless (eq value radical)
1086 (insert (format "(kangxi-radical\t . %S)\t; %c%s"
1088 (ideographic-radical value)
1091 (setq radical value)))
1092 (setq attributes (delq 'kangxi-radical attributes))
1094 (when (and (memq 'kangxi-strokes attributes)
1095 (setq value (get-char-attribute char 'kangxi-strokes)))
1096 (unless (eq value strokes)
1097 (insert (format "(kangxi-strokes\t . %S)%s"
1101 (setq strokes value)))
1102 (setq attributes (delq 'kangxi-strokes attributes))
1104 (when (and (memq 'japanese-radical attributes)
1105 (setq value (get-char-attribute char 'japanese-radical)))
1106 (unless (eq value radical)
1107 (insert (format "(japanese-radical\t . %S)\t; %c%s"
1109 (ideographic-radical value)
1112 (setq radical value)))
1113 (setq attributes (delq 'japanese-radical attributes))
1115 (when (and (memq 'japanese-strokes attributes)
1116 (setq value (get-char-attribute char 'japanese-strokes)))
1117 (unless (eq value strokes)
1118 (insert (format "(japanese-strokes\t . %S)%s"
1122 (setq strokes value)))
1123 (setq attributes (delq 'japanese-strokes attributes))
1125 (when (and (memq 'cns-radical attributes)
1126 (setq value (get-char-attribute char 'cns-radical)))
1127 (insert (format "(cns-radical\t . %S)\t; %c%s"
1129 (ideographic-radical value)
1131 (setq attributes (delq 'cns-radical attributes))
1133 (when (and (memq 'cns-strokes attributes)
1134 (setq value (get-char-attribute char 'cns-strokes)))
1135 (unless (eq value strokes)
1136 (insert (format "(cns-strokes\t . %S)%s"
1140 (setq strokes value)))
1141 (setq attributes (delq 'cns-strokes attributes))
1143 ;; (when (and (memq 'shinjigen-1-radical attributes)
1144 ;; (setq value (get-char-attribute char 'shinjigen-1-radical)))
1145 ;; (unless (eq value radical)
1146 ;; (insert (format "(shinjigen-1-radical . %S)\t; %c%s"
1148 ;; (ideographic-radical value)
1151 ;; (setq radical value)))
1152 ;; (setq attributes (delq 'shinjigen-1-radical attributes))
1154 (when (and (memq 'ideographic- attributes)
1155 (setq value (get-char-attribute char 'ideographic-)))
1156 (insert "(ideographic- ")
1157 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1159 (while (consp value)
1160 (setq cell (car value))
1162 (setq cell (decode-char '=ucs cell)))
1163 (cond ((characterp cell)
1167 (insert (format "%S" cell))
1168 (char-db-insert-char-spec cell readable))
1169 (setq separator lbs))
1173 (if (consp (car cell))
1174 (char-db-insert-char-spec cell readable)
1175 (char-db-insert-char-reference cell readable))
1176 (setq separator lbs))
1180 (insert (prin1-to-string cell))
1181 (setq separator " ")))
1182 (setq value (cdr value)))
1184 (insert line-breaking)
1185 (setq attributes (delq 'ideographic- attributes)))
1186 (when (and (memq 'total-strokes attributes)
1187 (setq value (get-char-attribute char 'total-strokes)))
1188 (insert (format "(total-strokes . %S)%s"
1191 (setq attributes (delq 'total-strokes attributes))
1193 (when (and (memq '->ideograph attributes)
1194 (setq value (get-char-attribute char '->ideograph)))
1195 (insert (format "(->ideograph\t%s)%s"
1196 (mapconcat (lambda (code)
1197 (cond ((symbolp code)
1200 (format "#x%04X" code))
1203 line-breaking code))))
1206 (setq attributes (delq '->ideograph attributes))
1208 ;; (when (and (memq '->decomposition attributes)
1209 ;; (setq value (get-char-attribute char '->decomposition)))
1210 ;; (insert (format "(->decomposition\t%s)%s"
1211 ;; (mapconcat (lambda (code)
1212 ;; (cond ((symbolp code)
1213 ;; (symbol-name code))
1214 ;; ((characterp code)
1216 ;; (format "%S" code)
1221 ;; (format "#x%04X" code))
1223 ;; (format "%s%S" line-breaking code))))
1226 ;; (setq attributes (delq '->decomposition attributes))
1228 (if (equal (get-char-attribute char '->titlecase)
1229 (get-char-attribute char '->uppercase))
1230 (setq attributes (delq '->titlecase attributes)))
1231 (when (and (memq '->mojikyo attributes)
1232 (setq value (get-char-attribute char '->mojikyo)))
1233 (insert (format "(->mojikyo\t\t. %06d)\t; %c%s"
1234 value (decode-char 'mojikyo value)
1236 (setq attributes (delq '->mojikyo attributes))
1238 (when (and (memq 'hanyu-dazidian-vol attributes)
1239 (setq value (get-char-attribute char 'hanyu-dazidian-vol)))
1240 (insert (format "(hanyu-dazidian-vol . %d)%s"
1241 value line-breaking))
1242 (setq attributes (delq 'hanyu-dazidian-vol attributes))
1244 (when (and (memq 'hanyu-dazidian-page attributes)
1245 (setq value (get-char-attribute char 'hanyu-dazidian-page)))
1246 (insert (format "(hanyu-dazidian-page . %d)%s"
1247 value line-breaking))
1248 (setq attributes (delq 'hanyu-dazidian-page attributes))
1250 (when (and (memq 'hanyu-dazidian-char attributes)
1251 (setq value (get-char-attribute char 'hanyu-dazidian-char)))
1252 (insert (format "(hanyu-dazidian-char . %d)%s"
1253 value line-breaking))
1254 (setq attributes (delq 'hanyu-dazidian-char attributes))
1257 (dolist (ignored '(composition
1258 ->denotational <-subsumptive ->ucs-unified
1259 ->ideographic-component-forms))
1260 (setq attributes (delq ignored attributes))))
1262 (setq name (car attributes))
1263 (unless (eq (setq value (get-char-attribute char name 'value-is-empty))
1265 (cond ((setq ret (find-charset name))
1266 (setq name (charset-name ret))
1267 (when (not (memq name dest-ccss))
1268 (setq dest-ccss (cons name dest-ccss))
1269 (char-db-insert-ccs-feature name value line-breaking))
1271 ((string-match "^=>ucs@" (symbol-name name))
1272 (insert (format "(%-18s . #x%04X)\t; %c%s"
1273 name value (decode-char '=ucs value)
1276 ((eq name 'jisx0208-1978/4X)
1277 (insert (format "(%-18s . #x%04X)%s"
1283 (not (eq name '->subsumptive))
1284 (not (eq name '->uppercase))
1285 (not (eq name '->lowercase))
1286 (not (eq name '->titlecase))
1287 (not (eq name '->canonical))
1288 (not (eq name '->Bopomofo))
1289 (not (eq name '->mistakable))
1290 (not (eq name '->ideographic-variants))
1291 (null (get-char-attribute
1292 char (intern (format "%s*sources" name))))
1293 (not (string-match "\\*sources$" (symbol-name name)))
1294 (null (get-char-attribute
1295 char (intern (format "%s*note" name))))
1296 (not (string-match "\\*note$" (symbol-name name)))
1297 (or (eq name '<-identical)
1298 (eq name '<-uppercase)
1299 (eq name '<-lowercase)
1300 (eq name '<-titlecase)
1301 (eq name '<-canonical)
1302 (eq name '<-ideographic-variants)
1303 ;; (eq name '<-synonyms)
1304 (string-match "^<-synonyms" (symbol-name name))
1305 (eq name '<-mistakable)
1306 (when (string-match "^->" (symbol-name name))
1308 ((string-match "^->fullwidth" (symbol-name name))
1309 (not (and (consp value)
1310 (characterp (car value))
1312 (car value) '=ucs 'defined-only)))
1317 ((or (eq name 'ideographic-structure)
1318 (eq name 'ideographic-combination)
1319 (eq name 'ideographic-)
1320 (eq name '=decomposition)
1321 (char-feature-base-name= '=decomposition name)
1322 (char-feature-base-name= '=>decomposition name)
1323 ;; (string-match "^=>*decomposition\\(@[^*]+\\)?$"
1324 ;; (symbol-name name))
1325 (string-match "^\\(->\\|<-\\)[^*]*$" (symbol-name name))
1326 (string-match "^\\(->\\|<-\\)[^*]*\\*sources$"
1329 (char-db-insert-relation-feature char name value
1332 ((memq name '(ideograph=
1333 original-ideograph-of
1334 ancient-ideograph-of
1337 ;; simplified-ideograph-of
1338 ideographic-variants
1339 ;; ideographic-different-form-of
1341 (insert (format "(%-18s%s " name line-breaking))
1342 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1344 (while (consp value)
1345 (setq cell (car value))
1346 (if (and (consp cell)
1351 (char-db-insert-alist cell readable)
1352 (setq separator lbs))
1355 (insert (prin1-to-string cell))
1356 (setq separator " "))
1357 (setq value (cdr value)))
1359 (insert line-breaking))
1361 (insert (format "(%-18s " name))
1362 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1364 (while (consp value)
1365 (setq cell (car value))
1366 (if (and (consp cell)
1368 (setq ret (condition-case nil
1376 (setq key (car (car rest)))
1377 (if (find-charset key)
1378 (setq cal (cons key cal))
1379 (setq al (cons key al)))
1380 (setq rest (cdr rest)))
1383 (insert-char-attributes ret
1387 (setq separator lbs))
1388 (setq ret (prin1-to-string cell))
1390 (if (< (+ (current-column)
1397 (setq separator " "))
1398 (setq value (cdr value)))
1400 (insert line-breaking))
1402 (insert (format "(%-18s" name))
1403 (setq ret (prin1-to-string value))
1404 (unless (< (+ (current-column)
1408 (insert line-breaking))
1409 (insert " . " ret ")" line-breaking)
1410 ;; (insert (format "(%-18s . %S)%s"
1415 (setq attributes (cdr attributes)))
1418 (defun insert-char-data (char &optional readable
1421 (narrow-to-region (point)(point))
1422 (insert "(define-char
1424 (insert-char-attributes char readable attributes)
1426 (goto-char (point-min))
1427 (while (re-search-forward "[ \t]+$" nil t)
1430 (goto-char (point-min))
1431 (while (re-search-forward "[ \t][ \t][ \t]*" nil t)
1432 (let ((column (current-column))
1433 (indent-tabs-mode t))
1434 (delete-region (match-beginning 0) (point))
1435 (indent-to column)))
1436 (goto-char (point-max))
1437 ;; (tabify (point-min)(point-max))
1440 (defun insert-char-data-with-variant (char &optional printable
1442 script excluded-script)
1443 (insert-char-data char printable)
1444 (let ((variants (char-variants char))
1447 (setq variants (sort variants #'<))
1448 (setq rest variants)
1449 (setq variants (cons char variants))
1451 (setq variant (car rest))
1452 (unless (get-char-attribute variant '<-subsumptive)
1453 (if (and (or (null script)
1454 (null (setq vs (get-char-attribute variant 'script)))
1456 (or (null excluded-script)
1457 (null (setq vs (get-char-attribute variant 'script)))
1458 (not (memq excluded-script vs))))
1459 (unless (and no-ucs-unified (get-char-attribute variant '=ucs))
1460 (insert-char-data variant printable)
1461 (if (setq ret (char-variants variant))
1463 (or (memq (car ret) variants)
1464 ;; (get-char-attribute (car ret) '<-subsumptive)
1465 (setq rest (nconc rest (list (car ret)))))
1466 (setq ret (cdr ret)))))))
1467 (setq rest (cdr rest)))))
1469 (defun insert-char-range-data (min max &optional script excluded-script)
1472 (while (<= code max)
1473 (setq char (decode-char '=ucs code))
1474 (if (encode-char char '=ucs 'defined-only)
1475 (insert-char-data-with-variant char nil 'no-ucs-unified
1476 script excluded-script))
1477 (setq code (1+ code)))))
1479 (defun write-char-range-data-to-file (min max file
1480 &optional script excluded-script)
1481 (let ((coding-system-for-write char-db-file-coding-system))
1483 (insert (format ";; -*- coding: %s -*-\n"
1484 char-db-file-coding-system))
1485 (insert-char-range-data min max script excluded-script)
1486 (write-region (point-min)(point-max) file))))
1488 (defvar what-character-original-window-configuration)
1491 (defun what-char-definition (char)
1492 (interactive (list (char-after)))
1493 (let ((buf (get-buffer-create "*Character Description*"))
1494 (the-buf (current-buffer))
1495 (win-conf (current-window-configuration)))
1497 (make-local-variable 'what-character-original-window-configuration)
1498 (setq what-character-original-window-configuration win-conf)
1499 (setq buffer-read-only nil)
1503 (insert-char-data-with-variant char 'printable)
1504 (unless (char-attribute-alist char)
1505 (insert (format ";; = %c\n"
1506 (let* ((rest (split-char char))
1510 (setq code (logior (lsh code 8)
1512 (decode-char ccs code)))))
1513 ;; (char-db-update-comment)
1514 (set-buffer-modified-p nil)
1515 (view-mode the-buf (lambda (buf)
1516 (set-window-configuration
1517 what-character-original-window-configuration)
1519 (goto-char (point-min)))
1521 (set-window-configuration
1522 what-character-original-window-configuration)
1523 (signal (car err) (cdr err)))))))
1529 (provide 'char-db-util)
1531 ;;; char-db-util.el ends here