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 MORIOKA Tomohiko.
6 ;; Author: MORIOKA Tomohiko <tomo@kanji.zinbun.kyoto-u.ac.jp>
7 ;; Keywords: CHISE, Character Database, ISO/IEC 10646, UCS, Unicode, MULE.
9 ;; This file is part of XEmacs CHISE.
11 ;; XEmacs CHISE is free software; you can redistribute it and/or
12 ;; modify it under the terms of the GNU General Public License as
13 ;; published by the Free Software Foundation; either version 2, or (at
14 ;; your option) any later version.
16 ;; XEmacs CHISE is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 ;; General Public License for more details.
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with XEmacs CHISE; see the file COPYING. If not, write to
23 ;; the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
24 ;; Boston, MA 02111-1307, USA.
30 (defconst unidata-normative-category-alist
31 '(("Lu" letter uppercase)
32 ("Ll" letter lowercase)
33 ("Lt" letter titlecase)
34 ("Mn" mark non-spacing)
35 ("Mc" mark spacing-combining)
37 ("Nd" number decimal-digit)
40 ("Zs" separator space)
42 ("Zp" separator paragraph)
45 ("Cs" other surrogate)
46 ("Co" other private-use)
47 ("Cn" other not-assigned)))
49 (defconst unidata-informative-category-alist
50 '(("Lm" letter modifier)
52 ("Pc" punctuation connector)
53 ("Pd" punctuation dash)
54 ("Ps" punctuation open)
55 ("Pe" punctuation close)
56 ("Pi" punctuation initial-quote)
57 ("Pf" punctuation final-quote)
58 ("Po" punctuation other)
60 ("Sc" symbol currency)
61 ("Sk" symbol modifier)
65 (defconst ideographic-radicals
66 (let ((v (make-vector 215 nil))
69 (aset v i (decode-char '=ucs (+ #x2EFF i)))
74 (defun ideographic-radical (number)
75 "Return character corresponding with Kangxi-radical number."
76 (aref ideographic-radicals number))
78 (defconst shuowen-radicals
79 [?一 ?上 ?示 ?三 ?王 ?玉 ?玨 ?气 ?士 ?丨 ; 010
80 ?屮 ?艸 ?蓐 ?茻 ?小 ?八 ?釆 ?半 ?牛 ?犛 ; 020
81 ?告 ?口 ?凵 ?吅 ?哭 ?走 ?止 ?癶 ?步 ?此 ; 030
82 ?正 ?是 ?辵 ?彳 ?廴 ?㢟 ?行 ?齒 ?牙 ?足 ; 040
83 ?疋 ?品 ?龠 ?冊 ?㗊 ?舌 ?干 ?谷 ?只 ?㕯 ; 050
84 ?句 ?丩 ?古 ?十 ?卅 ?言 ?誩 ?音 ?䇂 ?丵 ; 060
85 ?菐 ?𠬞 ?廾 ?共 ?異 ?舁 ?𦥑 ?䢅 ?爨 ?革 ; 070
86 ?鬲 ?䰜 ?爪 ?𠃨 ?鬥 ?又 ?𠂇 ?㕜 ?支 ?𦘒 ; 080
87 ?聿 ?畫 ?隶 ?臤 ?臣 ?殳 ?殺 ?𠘧 ?寸 ?皮 ; 090
88 ?㼱 ?攴 ?敎 ?卜 ?用 ?爻 ?㸚 ?𥄎 ?目 ?䀠 ; 100
89 ?眉 ?盾 ?自 ?白 ?鼻 ?皕 ?習 ?羽 ?隹 ?奞 ; 110
90 ?萑 ?𦫳 ?苜 ?羊 ?羴 ?瞿 ?雔 ?雥 ?鳥 ?烏 ; 120
91 ?𠦒 ?冓 ?幺 ?𢆶 ?叀 ?玄 ?予 ?放 ?𠬪 ?𣦼 ; 130
92 ?歺 ?死 ?冎 ?骨 ?肉 ?筋 ?刀 ?刃 ?㓞 ?丰 ; 140
93 ?耒 ?𧢲 ?竹 ?箕 ?丌 ?左 ?工 ?㠭 ?巫 ?甘 ; 150
94 ?曰 ?乃 ?丂 ?可 ?兮 ?号 ?亏 ?旨 ?喜 ?壴 ; 160
95 ?鼓 ?豈 ?豆 ?豊 ?豐 ?䖒 ?虍 ?虎 ?虤 ?皿 ; 170
96 ?𠙴 ?去 ?血 ?丶 ?丹 ?青 ?井 ?皀 ?鬯 ?食 ; 180
97 ?亼 ?會 ?倉 ?入 ?缶 ?矢 ?高 ?冂 ?𩫏 ?京 ; 190
98 ?亯 ?𣆪 ?畗 ?㐭 ?嗇 ?來 ?麥 ?夊 ?舛 ?䑞 ; 200
99 ?韋 ?弟 ?夂 ?久 ?桀 ?木 ?東 ?林 ?才 ?叒 ; 210
100 ?之 ?帀 ?出 ?𣎵 ?生 ?乇 ?𠂹 ?𠌶 ?華 ?𥝌 ; 220
101 ?稽 ?巢 ?桼 ?束 ?㯻 ?囗 ?員 ?貝 ?邑 ?𨛜 ; 230
102 ?日 ?旦 ?倝 ?㫃 ?冥 ?晶 ?月 ?有 ?明 ?囧 ; 240
103 ?夕 ?多 ?毌 ?𢎘 ?𣐺 ?卣 ?齊 ?朿 ?片 ?鼎 ; 250
104 ?克 ?彔 ?禾 ?秝 ?黍 ?香 ?米 ?毇 ?臼 ?凶 ; 260
105 ?𣎳 ?林 ?麻 ?尗 ?耑 ?韭 ?瓜 ?瓠 ?宀 ?宮 ; 270
106 ?呂 ?穴 ?㝱 ?𤕫 ?冖 ?𠔼 ?冃 ?㒳 ?网 ?襾 ; 280
107 ?巾 ?巿 ?帛 ?白 ?㡀 ?黹 ?人 ?𠤎 ?匕 ?从 ; 290
110 (defun shuowen-radical (number)
111 (aref shuowen-radicals (1- number)))
113 (defvar char-db-file-coding-system 'utf-8-mcs-er)
115 (defvar char-db-feature-domains
116 '(ucs ucs/compat daikanwa cns gt jis jis/alt jis/a jis/b
117 jis-x0212 jis-x0213 cdp shinjigen misc unknown))
119 (defvar char-db-ignored-attributes '(ideographic-products))
121 (defun char-attribute-name< (ka kb)
123 ((eq '->denotational kb)
125 ((eq '->subsumptive kb)
126 (not (eq '->denotational ka)))
127 ((eq '->denotational ka)
129 ((eq '->subsumptive ka)
132 (string-match "^->" (symbol-name ka)))
133 (cond ((and (symbolp kb)
134 (string-match "^->" (symbol-name kb)))
135 (string< (symbol-name ka)
140 (string-match "^->" (symbol-name kb)))
143 (string-match "^<-" (symbol-name ka)))
145 (cond ((string-match "^<-" (symbol-name kb))
146 (string< (symbol-name ka)
149 ;; ((string-match "^->" (symbol-name kb))
154 (string-match "^<-" (symbol-name kb)))
156 ;; (not (string-match "^->" (symbol-name ka)))
159 (if (find-charset kb)
161 (if (setq a-ir (charset-property ka 'iso-ir))
162 (if (setq b-ir (charset-property kb 'iso-ir))
165 (< (charset-id ka)(charset-id kb))
175 (if (charset-property kb 'iso-ir)
177 (< (charset-id ka)(charset-id kb)))))
183 (string< (symbol-name ka)
189 (defvar char-db-coded-charset-priority-list
267 (defun char-db-make-char-spec (char)
269 (cond ((characterp char)
270 (cond ((and (setq ret (encode-char char '=ucs 'defined-only))
271 (not (and (<= #xE000 ret)(<= ret #xF8FF))))
272 (setq char-spec (list (cons '=ucs ret)))
273 (cond ((setq ret (get-char-attribute char 'name))
274 (setq char-spec (cons (cons 'name ret) char-spec))
276 ((setq ret (get-char-attribute char 'name*))
277 (setq char-spec (cons (cons 'name* ret) char-spec))
282 (let ((rest char-db-coded-charset-priority-list)
285 (setq ccs (charset-name
286 (find-charset (car rest))))
288 (encode-char char ccs
290 (throw 'tag (cons ccs ret)))
291 (setq rest (cdr rest))))))
292 (setq char-spec (list ret))
293 (dolist (ccs (delq (car ret) (charset-list)))
294 (if (and (or (charset-iso-final-char ccs)
301 (string-match "=ucs@" (symbol-name ccs)))
302 (setq ccs (charset-name ccs))
303 (null (assq ccs char-spec))
304 (setq ret (encode-char char ccs 'defined-only)))
305 (setq char-spec (cons (cons ccs ret) char-spec))))
307 (setq char-spec (split-char char)))
308 (cond ((setq ret (get-char-attribute char 'name))
309 (setq char-spec (cons (cons 'name ret) char-spec))
311 ((setq ret (get-char-attribute char 'name*))
312 (setq char-spec (cons (cons 'name* ret) char-spec))
315 ((setq ret (get-char-attribute
316 char 'ideographic-combination))
318 (cons (cons 'ideographic-combination ret)
325 (defun char-db-insert-char-spec (char &optional readable column
328 (setq column (current-column)))
329 (let (char-spec temp-char)
330 (setq char-spec (char-db-make-char-spec char))
331 (unless (or (characterp char) ; char
333 (setq char (find-char char-spec))
335 ;; define temporary character
336 ;; Current implementation is dirty.
337 (setq temp-char (define-char (cons '(ideograph-daikanwa . 0)
339 (remove-char-attribute temp-char 'ideograph-daikanwa)
340 (setq char temp-char))
341 (insert-char-attributes char
343 (union (mapcar #'car char-spec)
346 ;; undefine temporary character
347 ;; Current implementation is dirty.
348 (setq char-spec (char-attribute-alist temp-char))
350 (remove-char-attribute temp-char (car (car char-spec)))
351 (setq char-spec (cdr char-spec))))))
353 (defun char-db-insert-alist (alist &optional readable column)
355 (setq column (current-column)))
357 (concat "\n" (make-string (1+ column) ?\ )))
361 lbs cell rest separator)
364 (setq name (car (car alist))
365 value (cdr (car alist)))
366 (cond ((eq name 'char)
368 (if (setq ret (condition-case nil
376 (setq key (car (car value)))
377 ;; (if (find-charset key)
378 ;; (setq cal (cons key cal))
379 (setq al (cons key al))
381 (setq value (cdr value)))
382 (insert-char-attributes ret
386 (insert (prin1-to-string value)))
388 (insert line-breaking))
390 (insert (format "(%-18s " name))
391 (setq lbs (concat "\n" (make-string (current-column) ?\ )))
393 (setq cell (car value))
394 (if (and (consp cell)
396 (setq ret (condition-case nil
406 (setq key (car (car rest)))
407 ;; (if (find-charset key)
408 ;; (setq cal (cons key cal))
409 (setq al (cons key al))
411 (setq rest (cdr rest)))
414 (insert-char-attributes ret
418 (setq separator lbs))
421 (insert (prin1-to-string cell))
422 (setq separator " "))
423 (setq value (cdr value)))
425 (insert line-breaking))
427 (insert (format "(%-18s . %S)%s"
430 (setq alist (cdr alist))))
433 (defun char-db-insert-char-reference (plist &optional readable column)
435 (setq column (current-column)))
437 (concat "\n" (make-string (1+ column) ?\ )))
442 (setq name (pop plist))
443 (setq value (pop plist))
444 (cond ((eq name :char)
447 (cond ((numberp value)
448 (setq value (decode-char '=ucs value)))
450 ;; (setq value (or (find-char value)
453 (char-db-insert-char-spec value readable)
454 (insert line-breaking)
457 (insert (format "%s%s\t%d ; %c%s"
460 (ideographic-radical value)
464 (insert (format "%s%s\t%S" separator name value))
465 (setq separator line-breaking)))
469 (defun char-db-decode-isolated-char (ccs code-point)
472 (cond ((eq ccs 'arabic-iso8859-6)
473 (decode-char ccs code-point))
474 ((and (memq ccs '(=gt-pj-1
485 (setq ret (decode-char ccs code-point))
486 (setq ret (encode-char ret '=gt 'defined-only)))
487 (decode-builtin-char '=gt ret))
489 (decode-builtin-char ccs code-point))))
490 (cond ((and (<= 0 (char-int ret))
491 (<= (char-int ret) #x1F))
492 (decode-char '=ucs (+ #x2400 (char-int ret))))
493 ((= (char-int ret) #x7F)
497 (defvar char-db-convert-obsolete-format t)
499 (defun char-db-insert-ccs-feature (name value line-breaking)
502 (cond ((memq name '(=shinjigen
504 =shinjigen@rev =shinjigen/+p@rev))
505 "(%-18s . %04d)\t; %c")
506 ((eq name '=shinjigen@1ed/24pr)
507 "(%-18s . %04d)\t; %c")
508 ((or (memq name '(=daikanwa
509 =daikanwa@rev1 =daikanwa@rev2
510 =gt =>>gt =>gt =gt-k =cbeta
511 =zinbun-oracle =>zinbun-oracle))
512 (string-match "^=adobe-" (symbol-name name)))
513 "(%-18s . %05d)\t; %c")
515 "(%-18s . %06d)\t; %c")
516 ((>= (charset-dimension name) 2)
517 "(%-18s . #x%04X)\t; %c")
519 "(%-18s . #x%02X)\t; %c"))
521 (if (= (charset-iso-graphic-plane name) 1)
523 (cond ((= (charset-dimension name) 1)
525 ((= (charset-dimension name) 2)
527 ((= (charset-dimension name) 3)
531 (char-db-decode-isolated-char name value)))
532 (if (and (= (charset-chars name) 94)
533 (= (charset-dimension name) 2))
534 (insert (format " [%02d-%02d]"
535 (- (lsh value -8) 32)
536 (- (logand value 255) 32))))
537 (insert line-breaking))
539 (defun char-db-insert-relation-feature (char name value line-breaking
541 (insert (format "(%-18s%s " name line-breaking))
542 (let ((lbs (concat "\n" (make-string (current-column) ?\ )))
543 separator cell sources required-features
546 (setq cell (car value))
548 (setq cell (decode-char '=ucs cell)))
550 ((eq name '->subsumptive)
551 (when (or (not (some (lambda (atr)
552 (get-char-attribute cell atr))
553 char-db-ignored-attributes))
555 (encode-char cell ccs 'defined-only))
559 (let ((char-db-ignored-attributes
561 char-db-ignored-attributes)))
562 (insert-char-attributes cell readable))
563 (setq separator lbs))
568 char (intern (format "%s*sources" name))))
569 (setq required-features nil)
570 (dolist (source sources)
574 shinjigen shinjigen@1ed shinjigen@rev))
575 (setq required-features
576 (union required-features
586 (setq required-features
587 (union required-features
592 ((find-charset (setq ret (intern (format "=%s" source))))
593 (setq required-features
594 (cons ret required-features)))
595 (t (setq required-features
596 (cons source required-features)))))
597 (cond ((string-match "@JP" (symbol-name name))
598 (setq required-features
599 (union required-features
607 ((string-match "@CN" (symbol-name name))
608 (setq required-features
609 (union required-features
616 (insert (format "%S" cell))
617 (char-db-insert-char-spec cell readable
620 (setq separator lbs))
624 (if (consp (car cell))
625 (char-db-insert-char-spec cell readable)
626 (char-db-insert-char-reference cell readable))
627 (setq separator lbs))
631 (insert (prin1-to-string cell))
632 (setq separator " ")))
633 (setq value (cdr value)))
635 (insert line-breaking)))
637 (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)
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@cns =>ucs@jis =>ucs@ks =>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)))
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 (if (setq value (get-char-attribute char name))
1090 (cond ((setq ret (find-charset name))
1091 (setq name (charset-name ret))
1092 (if (and (not (memq name dest-ccss))
1094 (setq value (get-char-attribute char name))
1095 (setq dest-ccss (cons name dest-ccss))))
1096 (char-db-insert-ccs-feature name value line-breaking))
1098 ((string-match "^=>ucs@" (symbol-name name))
1099 (insert (format "(%-18s . #x%04X)\t; %c%s"
1100 name value (decode-char '=ucs value)
1103 ((eq name 'jisx0208-1978/4X)
1104 (insert (format "(%-18s . #x%04X)%s"
1110 (not (eq name '->subsumptive))
1111 (not (eq name '->uppercase))
1112 (not (eq name '->lowercase))
1113 (not (eq name '->titlecase))
1114 (not (eq name '->canonical))
1115 (not (eq name '->Bopomofo))
1116 (not (eq name '->mistakable))
1117 (not (eq name '->ideographic-variants))
1118 (null (get-char-attribute
1119 char (intern (format "%s*sources" name))))
1120 (not (string-match "\\*sources$" (symbol-name name)))
1121 (null (get-char-attribute
1122 char (intern (format "%s*note" name))))
1123 (not (string-match "\\*note$" (symbol-name name)))
1124 (or (eq name '<-identical)
1125 (eq name '<-uppercase)
1126 (eq name '<-lowercase)
1127 (eq name '<-titlecase)
1128 (eq name '<-canonical)
1129 (eq name '<-ideographic-variants)
1130 ;; (eq name '<-synonyms)
1131 (string-match "^<-synonyms" (symbol-name name))
1132 (eq name '<-mistakable)
1133 (when (string-match "^->" (symbol-name name))
1135 ((string-match "^->fullwidth" (symbol-name name))
1136 (not (and (consp value)
1137 (characterp (car value))
1139 (car value) '=ucs 'defined-only)))
1144 ((or (eq name 'ideographic-structure)
1145 (eq name 'ideographic-combination)
1146 (eq name 'ideographic-)
1147 (eq name '=decomposition)
1148 (string-match "^=>decomposition" (symbol-name name))
1149 (string-match "^\\(->\\|<-\\)[^*]*$" (symbol-name name))
1150 (string-match "^\\(->\\|<-\\)[^*]*\\*sources$"
1153 (char-db-insert-relation-feature char name value
1156 ((memq name '(ideograph=
1157 original-ideograph-of
1158 ancient-ideograph-of
1161 ;; simplified-ideograph-of
1162 ideographic-variants
1163 ;; ideographic-different-form-of
1165 (insert (format "(%-18s%s " name line-breaking))
1166 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1168 (while (consp value)
1169 (setq cell (car value))
1170 (if (and (consp cell)
1175 (char-db-insert-alist cell readable)
1176 (setq separator lbs))
1179 (insert (prin1-to-string cell))
1180 (setq separator " "))
1181 (setq value (cdr value)))
1183 (insert line-breaking))
1185 (insert (format "(%-18s " name))
1186 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1188 (while (consp value)
1189 (setq cell (car value))
1190 (if (and (consp cell)
1192 (setq ret (condition-case nil
1200 (setq key (car (car rest)))
1201 (if (find-charset key)
1202 (setq cal (cons key cal))
1203 (setq al (cons key al)))
1204 (setq rest (cdr rest)))
1207 (insert-char-attributes ret
1210 (setq separator lbs))
1211 (setq ret (prin1-to-string cell))
1213 (if (< (+ (current-column)
1220 (setq separator " "))
1221 (setq value (cdr value)))
1223 (insert line-breaking))
1225 (insert (format "(%-18s" name))
1226 (setq ret (prin1-to-string value))
1227 (unless (< (+ (current-column)
1231 (insert line-breaking))
1232 (insert " . " ret ")" line-breaking)
1233 ;; (insert (format "(%-18s . %S)%s"
1238 (setq attributes (cdr attributes)))
1241 (defun insert-char-data (char &optional readable
1244 (narrow-to-region (point)(point))
1245 (insert "(define-char
1247 (insert-char-attributes char readable attributes)
1249 (goto-char (point-min))
1250 (while (re-search-forward "[ \t]+$" nil t)
1253 (goto-char (point-min))
1254 (while (re-search-forward "[ \t][ \t][ \t]*" nil t)
1255 (let ((column (current-column))
1256 (indent-tabs-mode t))
1257 (delete-region (match-beginning 0) (point))
1258 (indent-to column)))
1259 (goto-char (point-max))
1260 ;; (tabify (point-min)(point-max))
1263 (defun insert-char-data-with-variant (char &optional printable
1265 script excluded-script)
1266 (insert-char-data char printable)
1267 (let ((variants (char-variants char))
1270 (setq variants (sort variants #'<))
1271 (setq rest variants)
1272 (setq variants (cons char variants))
1274 (setq variant (car rest))
1275 (unless (get-char-attribute variant '<-subsumptive)
1276 (if (and (or (null script)
1277 (null (setq vs (get-char-attribute variant 'script)))
1279 (or (null excluded-script)
1280 (null (setq vs (get-char-attribute variant 'script)))
1281 (not (memq excluded-script vs))))
1282 (unless (and no-ucs-unified (get-char-attribute variant '=ucs))
1283 (insert-char-data variant printable)
1284 (if (setq ret (char-variants variant))
1286 (or (memq (car ret) variants)
1287 ;; (get-char-attribute (car ret) '<-subsumptive)
1288 (setq rest (nconc rest (list (car ret)))))
1289 (setq ret (cdr ret)))))))
1290 (setq rest (cdr rest)))))
1292 (defun insert-char-range-data (min max &optional script excluded-script)
1295 (while (<= code max)
1296 (setq char (decode-char '=ucs code))
1297 (if (encode-char char '=ucs 'defined-only)
1298 (insert-char-data-with-variant char nil 'no-ucs-unified
1299 script excluded-script))
1300 (setq code (1+ code)))))
1302 (defun write-char-range-data-to-file (min max file
1303 &optional script excluded-script)
1304 (let ((coding-system-for-write char-db-file-coding-system))
1306 (insert (format ";; -*- coding: %s -*-\n"
1307 char-db-file-coding-system))
1308 (insert-char-range-data min max script excluded-script)
1309 (write-region (point-min)(point-max) file))))
1311 (defvar what-character-original-window-configuration)
1314 (defun what-char-definition (char)
1315 (interactive (list (char-after)))
1316 (let ((buf (get-buffer-create "*Character Description*"))
1317 (the-buf (current-buffer))
1318 (win-conf (current-window-configuration)))
1320 (make-local-variable 'what-character-original-window-configuration)
1321 (setq what-character-original-window-configuration win-conf)
1322 (setq buffer-read-only nil)
1326 (insert-char-data-with-variant char 'printable)
1327 (unless (char-attribute-alist char)
1328 (insert (format ";; = %c\n"
1329 (let* ((rest (split-char char))
1333 (setq code (logior (lsh code 8)
1335 (decode-char ccs code)))))
1336 ;; (char-db-update-comment)
1337 (set-buffer-modified-p nil)
1338 (view-mode the-buf (lambda (buf)
1339 (set-window-configuration
1340 what-character-original-window-configuration)
1342 (goto-char (point-min)))
1344 (set-window-configuration
1345 what-character-original-window-configuration)
1346 (signal (car err) (cdr err)))))))
1348 (provide 'char-db-util)
1350 ;;; char-db-util.el ends here