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 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)))
73 (defun ideographic-radical (number)
74 (aref ideographic-radicals number))
76 (defconst shuowen-radicals
77 [?一 ?上 ?示 ?三 ?王 ?玉 ?玨 ?气 ?士 ?丨 ; 010
78 ?屮 ?艸 ?蓐 ?茻 ?小 ?八 ?釆 ?半 ?牛 ?犛 ; 020
79 ?告 ?口 ?凵 ?吅 ?哭 ?走 ?止 ?癶 ?步 ?此 ; 030
80 ?正 ?是 ?辵 ?彳 ?廴 ?㢟 ?行 ?齒 ?牙 ?足 ; 040
81 ?疋 ?品 ?龠 ?冊 ?㗊 ?舌 ?干 ?谷 ?只 ?㕯 ; 050
82 ?句 ?丩 ?古 ?十 ?卅 ?言 ?誩 ?音 ?䇂 ?丵 ; 060
83 ?菐 ?𠬞 ?廾 ?共 ?異 ?舁 ?𦥑 ?䢅 ?爨 ?革 ; 070
84 ?鬲 ?䰜 ?爪 ?𠃨 ?鬥 ?又 ?𠂇 ?㕜 ?支 ?𦘒 ; 080
85 ?聿 ?畫 ?隶 ?臤 ?臣 ?殳 ?殺 ?𠘧 ?寸 ?皮 ; 090
86 ?㼱 ?攴 ?敎 ?卜 ?用 ?爻 ?㸚 ?𥄎 ?目 ?䀠 ; 100
87 ?眉 ?盾 ?自 ?白 ?鼻 ?皕 ?習 ?羽 ?隹 ?奞 ; 110
88 ?萑 ?𦫳 ?苜 ?羊 ?羴 ?瞿 ?雔 ?雥 ?鳥 ?烏 ; 120
89 ?𠦒 ?冓 ?幺 ?𢆶 ?叀 ?玄 ?予 ?放 ?𠬪 ?𣦼 ; 130
90 ?歺 ?死 ?冎 ?骨 ?肉 ?筋 ?刀 ?刃 ?㓞 ?丰 ; 140
91 ?耒 ?𧢲 ?竹 ?箕 ?丌 ?左 ?工 ?㠭 ?巫 ?甘 ; 150
92 ?曰 ?乃 ?丂 ?可 ?兮 ?号 ?亏 ?旨 ?喜 ?壴 ; 160
93 ?鼓 ?豈 ?豆 ?豊 ?豐 ?䖒 ?虍 ?虎 ?虤 ?皿 ; 170
94 ?𠙴 ?去 ?血 ?丶 ?丹 ?青 ?井 ?皀 ?鬯 ?食 ; 180
95 ?亼 ?會 ?倉 ?入 ?缶 ?矢 ?高 ?冂 ?𩫏 ?京 ; 190
96 ?亯 ?𣆪 ?畗 ?㐭 ?嗇 ?來 ?麥 ?夊 ?舛 ?䑞 ; 200
97 ?韋 ?弟 ?夂 ?久 ?桀 ?木 ?東 ?林 ?才 ?叒 ; 210
98 ?之 ?帀 ?出 ?𣎵 ?生 ?乇 ?𠂹 ?𠌶 ?華 ?𥝌 ; 220
99 ?稽 ?巢 ?桼 ?束 ?㯻 ?囗 ?員 ?貝 ?邑 ?𨛜 ; 230
100 ?日 ?旦 ?倝 ?㫃 ?冥 ?晶 ?月 ?有 ?明 ?囧 ; 240
101 ?夕 ?多 ?毌 ?𢎘 ?𣐺 ?卣 ?齊 ?朿 ?片 ?鼎 ; 250
102 ?克 ?彔 ?禾 ?秝 ?黍 ?香 ?米 ?毇 ?臼 ?凶 ; 260
103 ?𣎳 ?林 ?麻 ?尗 ?耑 ?韭 ?瓜 ?瓠 ?宀 ?宫 ; 270
106 (defun shuowen-radical (number)
107 (aref shuowen-radicals (1- number)))
109 (defvar char-db-file-coding-system 'utf-8-mcs-er)
111 (defvar char-db-feature-domains
112 '(ucs ucs/compat daikanwa cns gt jis jis/alt jis/a jis/b
113 jis-x0212 jis-x0213 cdp shinjigen misc unknown))
115 (defvar char-db-ignored-attributes '(ideographic-products))
117 (defun char-attribute-name< (ka kb)
119 ((eq '->denotational kb)
121 ((eq '->subsumptive kb)
122 (not (eq '->denotational ka)))
123 ((eq '->denotational ka)
125 ((eq '->subsumptive ka)
128 (string-match "^->" (symbol-name ka)))
129 (cond ((and (symbolp kb)
130 (string-match "^->" (symbol-name kb)))
131 (string< (symbol-name ka)
136 (string-match "^->" (symbol-name kb)))
139 (string-match "^<-" (symbol-name ka)))
141 (cond ((string-match "^<-" (symbol-name kb))
142 (string< (symbol-name ka)
145 ;; ((string-match "^->" (symbol-name kb))
150 (string-match "^<-" (symbol-name kb)))
152 ;; (not (string-match "^->" (symbol-name ka)))
155 (if (find-charset kb)
156 (if (<= (charset-id ka) 1)
157 (if (<= (charset-id kb) 1)
159 ((= (charset-dimension ka)
160 (charset-dimension kb))
161 (> (charset-id ka)(charset-id kb)))
163 (> (charset-dimension ka)
164 (charset-dimension kb))
167 (if (<= (charset-id kb) 1)
169 (< (charset-id ka)(charset-id kb))))
175 (string< (symbol-name ka)
181 (defvar char-db-coded-charset-priority-list
242 (defun char-db-make-char-spec (char)
244 (cond ((characterp char)
245 (cond ((and (setq ret (encode-char char '=ucs 'defined-only))
246 (not (and (<= #xE000 ret)(<= ret #xF8FF))))
247 (setq char-spec (list (cons '=ucs ret)))
248 (cond ((setq ret (get-char-attribute char 'name))
249 (setq char-spec (cons (cons 'name ret) char-spec))
251 ((setq ret (get-char-attribute char 'name*))
252 (setq char-spec (cons (cons 'name* ret) char-spec))
257 (let ((rest char-db-coded-charset-priority-list)
260 (setq ccs (charset-name
261 (find-charset (car rest))))
263 (encode-char char ccs
265 (throw 'tag (cons ccs ret)))
266 (setq rest (cdr rest))))))
267 (setq char-spec (list ret))
268 (dolist (ccs (delq (car ret) (charset-list)))
269 (if (and (or (charset-iso-final-char ccs)
276 (setq ccs (charset-name ccs))
277 (null (assq ccs char-spec))
278 (setq ret (encode-char char ccs 'defined-only)))
279 (setq char-spec (cons (cons ccs ret) char-spec))))
281 (setq char-spec (split-char char)))
282 (cond ((setq ret (get-char-attribute char 'name))
283 (setq char-spec (cons (cons 'name ret) char-spec))
285 ((setq ret (get-char-attribute char 'name*))
286 (setq char-spec (cons (cons 'name* ret) char-spec))
293 (defun char-db-insert-char-spec (char &optional readable column
296 (setq column (current-column)))
297 (let (char-spec temp-char)
298 (setq char-spec (char-db-make-char-spec char))
299 (unless (or (characterp char) ; char
301 (setq char (find-char char-spec))
303 ;; define temporary character
304 ;; Current implementation is dirty.
305 (setq temp-char (define-char (cons '(ideograph-daikanwa . 0)
307 (remove-char-attribute temp-char 'ideograph-daikanwa)
308 (setq char temp-char))
309 (insert-char-attributes char
311 (union (mapcar #'car char-spec)
314 ;; undefine temporary character
315 ;; Current implementation is dirty.
316 (setq char-spec (char-attribute-alist temp-char))
318 (remove-char-attribute temp-char (car (car char-spec)))
319 (setq char-spec (cdr char-spec))))))
321 (defun char-db-insert-alist (alist &optional readable column)
323 (setq column (current-column)))
325 (concat "\n" (make-string (1+ column) ?\ )))
329 lbs cell rest separator)
332 (setq name (car (car alist))
333 value (cdr (car alist)))
334 (cond ((eq name 'char)
336 (if (setq ret (condition-case nil
344 (setq key (car (car value)))
345 ;; (if (find-charset key)
346 ;; (setq cal (cons key cal))
347 (setq al (cons key al))
349 (setq value (cdr value)))
350 (insert-char-attributes ret
354 (insert (prin1-to-string value)))
356 (insert line-breaking))
358 (insert (format "(%-18s " name))
359 (setq lbs (concat "\n" (make-string (current-column) ?\ )))
361 (setq cell (car value))
362 (if (and (consp cell)
364 (setq ret (condition-case nil
374 (setq key (car (car rest)))
375 ;; (if (find-charset key)
376 ;; (setq cal (cons key cal))
377 (setq al (cons key al))
379 (setq rest (cdr rest)))
382 (insert-char-attributes ret
386 (setq separator lbs))
389 (insert (prin1-to-string cell))
390 (setq separator " "))
391 (setq value (cdr value)))
393 (insert line-breaking))
395 (insert (format "(%-18s . %S)%s"
398 (setq alist (cdr alist))))
401 (defun char-db-insert-char-reference (plist &optional readable column)
403 (setq column (current-column)))
405 (concat "\n" (make-string (1+ column) ?\ )))
410 (setq name (pop plist))
411 (setq value (pop plist))
412 (cond ((eq name :char)
415 (cond ((numberp value)
416 (setq value (decode-char '=ucs value)))
418 ;; (setq value (or (find-char value)
421 (char-db-insert-char-spec value readable)
422 (insert line-breaking)
425 (insert (format "%s%s\t%d ; %c%s"
428 (ideographic-radical value)
432 (insert (format "%s%s\t%S" separator name value))
433 (setq separator line-breaking)))
437 (defun char-db-decode-isolated-char (ccs code-point)
440 (cond ((eq ccs 'arabic-iso8859-6)
441 (decode-char ccs code-point))
442 ((and (memq ccs '(=gt-pj-1
453 (setq ret (decode-char ccs code-point))
454 (setq ret (encode-char ret '=gt 'defined-only)))
455 (decode-builtin-char '=gt ret))
457 (decode-builtin-char ccs code-point))))
458 (cond ((and (<= 0 (char-int ret))
459 (<= (char-int ret) #x1F))
460 (decode-char '=ucs (+ #x2400 (char-int ret))))
461 ((= (char-int ret) #x7F)
465 (defvar char-db-convert-obsolete-format t)
467 (defun char-db-insert-ccs-feature (name value line-breaking)
470 (cond ((or (memq name '(=daikanwa
471 =daikanwa@rev1 =daikanwa@rev2
472 =gt =gt-k =cbeta =zinbun-oracle))
473 (string-match "^=adobe-" (symbol-name name)))
474 "(%-18s . %05d)\t; %c")
476 "(%-18s . %06d)\t; %c")
477 ((>= (charset-dimension name) 2)
478 "(%-18s . #x%04X)\t; %c")
480 "(%-18s . #x%02X)\t; %c"))
482 (if (= (charset-iso-graphic-plane name) 1)
484 (cond ((= (charset-dimension name) 1)
486 ((= (charset-dimension name) 2)
488 ((= (charset-dimension name) 3)
492 (char-db-decode-isolated-char name value)))
493 (if (and (= (charset-chars name) 94)
494 (= (charset-dimension name) 2))
495 (insert (format " [%02d-%02d]"
496 (- (lsh value -8) 32)
497 (- (logand value 255) 32))))
498 (insert line-breaking))
500 (defun char-db-insert-relation-feature (char name value line-breaking
502 (insert (format "(%-18s%s " name line-breaking))
503 (let ((lbs (concat "\n" (make-string (current-column) ?\ )))
504 separator cell sources required-features
507 (setq cell (car value))
509 (setq cell (decode-char '=ucs cell)))
511 ((eq name '->subsumptive)
512 (when (or (not (some (lambda (atr)
513 (get-char-attribute cell atr))
514 char-db-ignored-attributes))
516 (encode-char cell ccs 'defined-only))
520 (let ((char-db-ignored-attributes
522 char-db-ignored-attributes)))
523 (insert-char-attributes cell readable))
524 (setq separator lbs))
529 char (intern (format "%s*sources" name))))
530 (setq required-features nil)
531 (dolist (source sources)
533 ((memq source '(JP JP/Jouyou shinjigen-1))
534 (setq required-features
535 (union required-features
544 (setq required-features
545 (union required-features
550 ((find-charset (setq ret (intern (format "=%s" source))))
551 (setq required-features
552 (cons ret required-features)))
553 (t (setq required-features
554 (cons source required-features)))))
555 (cond ((string-match "@JP" (symbol-name name))
556 (setq required-features
557 (union required-features
565 ((string-match "@CN" (symbol-name name))
566 (setq required-features
567 (union required-features
574 (insert (format "%S" cell))
575 (char-db-insert-char-spec cell readable
578 (setq separator lbs))
582 (if (consp (car cell))
583 (char-db-insert-char-spec cell readable)
584 (char-db-insert-char-reference cell readable))
585 (setq separator lbs))
589 (insert (prin1-to-string cell))
590 (setq separator " ")))
591 (setq value (cdr value)))
593 (insert line-breaking)))
595 (defun insert-char-attributes (char &optional readable attributes column)
597 (setq column (current-column)))
598 (let (name value ; has-long-ccs-name
602 (concat "\n" (make-string (1+ column) ?\ )))
603 lbs cell separator ret
605 dest-ccss ; sources required-features
610 (if (consp attributes)
612 (dolist (name attributes)
613 (unless (memq name char-db-ignored-attributes)
614 (if (find-charset name)
618 (dolist (name (char-attribute-list))
619 (unless (memq name char-db-ignored-attributes)
620 (if (find-charset name)
624 #'char-attribute-name<)))
626 (when (memq '<-subsumptive attributes)
628 (when (setq value (get-char-attribute char '<-subsumptive))
629 (char-db-insert-relation-feature char '<-subsumptive value
632 (setq attributes (delq '<-subsumptive attributes)))
633 (when (and (memq '<-denotational attributes)
634 (setq value (get-char-attribute char '<-denotational)))
635 (char-db-insert-relation-feature char '<-denotational value
638 (setq attributes (delq '<-denotational attributes)))
639 (when (and (memq 'name attributes)
640 (setq value (get-char-attribute char 'name)))
642 (if (> (+ (current-column) (length value)) 48)
645 value line-breaking))
646 (setq attributes (delq 'name attributes))
648 (when (and (memq 'name* attributes)
649 (setq value (get-char-attribute char 'name*)))
651 (if (> (+ (current-column) (length value)) 48)
654 value line-breaking))
655 (setq attributes (delq 'name* attributes))
657 (when (and (memq 'script attributes)
658 (setq value (get-char-attribute char 'script)))
659 (insert (format "(script\t\t%s)%s"
660 (mapconcat (function prin1-to-string)
663 (setq attributes (delq 'script attributes))
665 (dolist (name '(=>ucs =>ucs*))
666 (when (and (memq name attributes)
667 (setq value (get-char-attribute char name)))
668 (insert (format "(%-18s . #x%04X)\t; %c%s"
669 name value (decode-char '=ucs value)
671 (setq attributes (delq name attributes))))
672 (dolist (name '(=>ucs@gb =>ucs@cns =>ucs@jis =>ucs@ks =>ucs@big5))
673 (when (and (memq name attributes)
674 (setq value (get-char-attribute char name)))
675 (insert (format "(%-18s . #x%04X)\t; %c%s"
680 (symbol-name name) 2)))
683 (setq attributes (delq name attributes))
685 (dolist (name '(=>daikanwa))
686 (when (and (memq name attributes)
687 (setq value (get-char-attribute char name)))
690 (format "(%-18s . %05d)\t; %c%s"
691 name value (decode-char '=daikanwa value)
693 (format "(%-18s %s)\t; %c%s"
695 (mapconcat (function prin1-to-string)
697 (char-representative-of-daikanwa char)
699 (setq attributes (delq name attributes))))
700 (when (and (memq 'general-category attributes)
701 (setq value (get-char-attribute char 'general-category)))
703 "(general-category\t%s) ; %s%s"
704 (mapconcat (lambda (cell)
707 (cond ((rassoc value unidata-normative-category-alist)
708 "Normative Category")
709 ((rassoc value unidata-informative-category-alist)
710 "Informative Category")
714 (setq attributes (delq 'general-category attributes))
716 (when (and (memq 'bidi-category attributes)
717 (setq value (get-char-attribute char 'bidi-category)))
718 (insert (format "(bidi-category\t. %S)%s"
721 (setq attributes (delq 'bidi-category attributes))
723 (unless (or (not (memq 'mirrored attributes))
724 (eq (setq value (get-char-attribute char 'mirrored 'empty))
726 (insert (format "(mirrored\t\t. %S)%s"
729 (setq attributes (delq 'mirrored attributes))
732 ((and (memq 'decimal-digit-value attributes)
733 (setq value (get-char-attribute char 'decimal-digit-value)))
734 (insert (format "(decimal-digit-value . %S)%s"
737 (setq attributes (delq 'decimal-digit-value attributes))
738 (when (and (memq 'digit-value attributes)
739 (setq value (get-char-attribute char 'digit-value)))
740 (insert (format "(digit-value\t . %S)%s"
743 (setq attributes (delq 'digit-value attributes))
745 (when (and (memq 'numeric-value attributes)
746 (setq value (get-char-attribute char 'numeric-value)))
747 (insert (format "(numeric-value\t . %S)%s"
750 (setq attributes (delq 'numeric-value attributes))
754 (when (and (memq 'digit-value attributes)
755 (setq value (get-char-attribute char 'digit-value)))
756 (insert (format "(digit-value\t. %S)%s"
759 (setq attributes (delq 'digit-value attributes))
761 (when (and (memq 'numeric-value attributes)
762 (setq value (get-char-attribute char 'numeric-value)))
763 (insert (format "(numeric-value\t. %S)%s"
766 (setq attributes (delq 'numeric-value attributes))
768 (when (and (memq 'iso-10646-comment attributes)
769 (setq value (get-char-attribute char 'iso-10646-comment)))
770 (insert (format "(iso-10646-comment\t. %S)%s"
773 (setq attributes (delq 'iso-10646-comment attributes))
775 (when (and (memq 'morohashi-daikanwa attributes)
776 (setq value (get-char-attribute char 'morohashi-daikanwa)))
777 (insert (format "(morohashi-daikanwa\t%s)%s"
778 (mapconcat (function prin1-to-string) value " ")
780 (setq attributes (delq 'morohashi-daikanwa attributes))
784 (when (and (memq 'ideographic-radical attributes)
785 (setq value (get-char-attribute char 'ideographic-radical)))
787 (insert (format "(ideographic-radical . %S)\t; %c%s"
789 (ideographic-radical radical)
791 (setq attributes (delq 'ideographic-radical attributes))
793 (when (and (memq 'shuowen-radical attributes)
794 (setq value (get-char-attribute char 'shuowen-radical)))
795 (insert (format "(shuowen-radical\t. %S)\t; %c%s"
797 (shuowen-radical value)
799 (setq attributes (delq 'shuowen-radical attributes))
804 char-db-feature-domains
806 (dolist (feature (char-attribute-list))
807 (setq feature (symbol-name feature))
809 "\\(radical\\|strokes\\)@\\([^@*]+\\)\\(\\*\\|$\\)"
811 (setq domain (intern (match-string 2 feature)))
812 (unless (memq domain dest)
813 (setq dest (cons domain dest)))))
814 (sort dest #'string<))))
815 (setq key (intern (format "%s@%s" 'ideographic-radical domain)))
816 (when (and (memq key attributes)
817 (setq value (get-char-attribute char key)))
819 (insert (format "(%s . %S)\t; %c%s"
822 (ideographic-radical radical)
824 (setq attributes (delq key attributes))
826 (setq key (intern (format "%s@%s" 'ideographic-strokes domain)))
827 (when (and (memq key attributes)
828 (setq value (get-char-attribute char key)))
830 (insert (format "(%s . %S)%s"
834 (setq attributes (delq key attributes))
836 (setq key (intern (format "%s@%s" 'total-strokes domain)))
837 (when (and (memq key attributes)
838 (setq value (get-char-attribute char key)))
839 (insert (format "(%s . %S)%s"
843 (setq attributes (delq key attributes))
845 (dolist (feature '(ideographic-radical
848 (setq key (intern (format "%s@%s*sources" feature domain)))
849 (when (and (memq key attributes)
850 (setq value (get-char-attribute char key)))
851 (insert (format "(%s%s" key line-breaking))
853 (insert (format " %s" cell)))
855 (insert line-breaking)
856 (setq attributes (delq key attributes))
859 (when (and (memq 'ideographic-strokes attributes)
860 (setq value (get-char-attribute char 'ideographic-strokes)))
862 (insert (format "(ideographic-strokes . %S)%s"
865 (setq attributes (delq 'ideographic-strokes attributes))
867 (when (and (memq 'kangxi-radical attributes)
868 (setq value (get-char-attribute char 'kangxi-radical)))
869 (unless (eq value radical)
870 (insert (format "(kangxi-radical\t . %S)\t; %c%s"
872 (ideographic-radical value)
875 (setq radical value)))
876 (setq attributes (delq 'kangxi-radical attributes))
878 (when (and (memq 'kangxi-strokes attributes)
879 (setq value (get-char-attribute char 'kangxi-strokes)))
880 (unless (eq value strokes)
881 (insert (format "(kangxi-strokes\t . %S)%s"
885 (setq strokes value)))
886 (setq attributes (delq 'kangxi-strokes attributes))
888 (when (and (memq 'japanese-radical attributes)
889 (setq value (get-char-attribute char 'japanese-radical)))
890 (unless (eq value radical)
891 (insert (format "(japanese-radical\t . %S)\t; %c%s"
893 (ideographic-radical value)
896 (setq radical value)))
897 (setq attributes (delq 'japanese-radical attributes))
899 (when (and (memq 'japanese-strokes attributes)
900 (setq value (get-char-attribute char 'japanese-strokes)))
901 (unless (eq value strokes)
902 (insert (format "(japanese-strokes\t . %S)%s"
906 (setq strokes value)))
907 (setq attributes (delq 'japanese-strokes attributes))
909 (when (and (memq 'cns-radical attributes)
910 (setq value (get-char-attribute char 'cns-radical)))
911 (insert (format "(cns-radical\t . %S)\t; %c%s"
913 (ideographic-radical value)
915 (setq attributes (delq 'cns-radical attributes))
917 (when (and (memq 'cns-strokes attributes)
918 (setq value (get-char-attribute char 'cns-strokes)))
919 (unless (eq value strokes)
920 (insert (format "(cns-strokes\t . %S)%s"
924 (setq strokes value)))
925 (setq attributes (delq 'cns-strokes attributes))
927 (when (and (memq 'shinjigen-1-radical attributes)
928 (setq value (get-char-attribute char 'shinjigen-1-radical)))
929 (unless (eq value radical)
930 (insert (format "(shinjigen-1-radical . %S)\t; %c%s"
932 (ideographic-radical value)
935 (setq radical value)))
936 (setq attributes (delq 'shinjigen-1-radical attributes))
938 (when (and (memq 'ideographic- attributes)
939 (setq value (get-char-attribute char 'ideographic-)))
940 (insert "(ideographic- ")
941 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
944 (setq cell (car value))
946 (setq cell (decode-char '=ucs cell)))
947 (cond ((characterp cell)
951 (insert (format "%S" cell))
952 (char-db-insert-char-spec cell readable))
953 (setq separator lbs))
957 (if (consp (car cell))
958 (char-db-insert-char-spec cell readable)
959 (char-db-insert-char-reference cell readable))
960 (setq separator lbs))
964 (insert (prin1-to-string cell))
965 (setq separator " ")))
966 (setq value (cdr value)))
968 (insert line-breaking)
969 (setq attributes (delq 'ideographic- attributes)))
970 (when (and (memq 'total-strokes attributes)
971 (setq value (get-char-attribute char 'total-strokes)))
972 (insert (format "(total-strokes . %S)%s"
975 (setq attributes (delq 'total-strokes attributes))
977 (when (and (memq '->ideograph attributes)
978 (setq value (get-char-attribute char '->ideograph)))
979 (insert (format "(->ideograph\t%s)%s"
980 (mapconcat (lambda (code)
981 (cond ((symbolp code)
984 (format "#x%04X" code))
987 line-breaking code))))
990 (setq attributes (delq '->ideograph attributes))
992 ;; (when (and (memq '->decomposition attributes)
993 ;; (setq value (get-char-attribute char '->decomposition)))
994 ;; (insert (format "(->decomposition\t%s)%s"
995 ;; (mapconcat (lambda (code)
996 ;; (cond ((symbolp code)
997 ;; (symbol-name code))
998 ;; ((characterp code)
1000 ;; (format "%S" code)
1005 ;; (format "#x%04X" code))
1007 ;; (format "%s%S" line-breaking code))))
1010 ;; (setq attributes (delq '->decomposition attributes))
1012 (if (equal (get-char-attribute char '->titlecase)
1013 (get-char-attribute char '->uppercase))
1014 (setq attributes (delq '->titlecase attributes)))
1015 (when (and (memq '->mojikyo attributes)
1016 (setq value (get-char-attribute char '->mojikyo)))
1017 (insert (format "(->mojikyo\t\t. %06d)\t; %c%s"
1018 value (decode-char 'mojikyo value)
1020 (setq attributes (delq '->mojikyo attributes))
1022 (when (and (memq 'hanyu-dazidian-vol attributes)
1023 (setq value (get-char-attribute char 'hanyu-dazidian-vol)))
1024 (insert (format "(hanyu-dazidian-vol . %d)%s"
1025 value line-breaking))
1026 (setq attributes (delq 'hanyu-dazidian-vol attributes))
1028 (when (and (memq 'hanyu-dazidian-page attributes)
1029 (setq value (get-char-attribute char 'hanyu-dazidian-page)))
1030 (insert (format "(hanyu-dazidian-page . %d)%s"
1031 value line-breaking))
1032 (setq attributes (delq 'hanyu-dazidian-page attributes))
1034 (when (and (memq 'hanyu-dazidian-char attributes)
1035 (setq value (get-char-attribute char 'hanyu-dazidian-char)))
1036 (insert (format "(hanyu-dazidian-char . %d)%s"
1037 value line-breaking))
1038 (setq attributes (delq 'hanyu-dazidian-char attributes))
1041 (dolist (ignored '(composition
1042 ->denotational <-subsumptive ->ucs-unified
1043 ->ideographic-component-forms))
1044 (setq attributes (delq ignored attributes))))
1046 (setq name (car attributes))
1047 (if (setq value (get-char-attribute char name))
1048 (cond ((setq ret (find-charset name))
1049 (setq name (charset-name ret))
1050 (if (and (not (memq name dest-ccss))
1052 (setq value (get-char-attribute char name))
1053 (setq dest-ccss (cons name dest-ccss))))
1054 (char-db-insert-ccs-feature name value line-breaking))
1056 ((string-match "^=>ucs@" (symbol-name name))
1057 (insert (format "(%-18s . #x%04X)\t; %c%s"
1058 name value (decode-char '=ucs value)
1061 ((eq name 'jisx0208-1978/4X)
1062 (insert (format "(%-18s . #x%04X)%s"
1068 (not (eq name '->subsumptive))
1069 (not (eq name '->uppercase))
1070 (not (eq name '->lowercase))
1071 (not (eq name '->titlecase))
1072 (not (eq name '->canonical))
1073 (not (eq name '->Bopomofo))
1074 (not (eq name '->mistakable))
1075 (not (eq name '->ideographic-variants))
1076 (null (get-char-attribute
1077 char (intern (format "%s*sources" name))))
1078 (not (string-match "\\*sources$" (symbol-name name)))
1079 (null (get-char-attribute
1080 char (intern (format "%s*note" name))))
1081 (not (string-match "\\*note$" (symbol-name name)))
1082 (or (eq name '<-identical)
1083 (eq name '<-uppercase)
1084 (eq name '<-lowercase)
1085 (eq name '<-titlecase)
1086 (eq name '<-canonical)
1087 (eq name '<-ideographic-variants)
1088 ;; (eq name '<-synonyms)
1089 (string-match "^<-synonyms" (symbol-name name))
1090 (eq name '<-mistakable)
1091 (when (string-match "^->" (symbol-name name))
1093 ((string-match "^->fullwidth" (symbol-name name))
1094 (not (and (consp value)
1095 (characterp (car value))
1097 (car value) '=ucs 'defined-only)))
1102 ((or (eq name 'ideographic-structure)
1103 (eq name 'ideographic-combination)
1104 (eq name 'ideographic-)
1105 (eq name '=decomposition)
1106 (string-match "^=>decomposition" (symbol-name name))
1107 (string-match "^\\(->\\|<-\\)[^*]*$" (symbol-name name))
1108 (string-match "^\\(->\\|<-\\)[^*]*\\*sources$"
1111 (char-db-insert-relation-feature char name value
1114 ((memq name '(ideograph=
1115 original-ideograph-of
1116 ancient-ideograph-of
1119 ;; simplified-ideograph-of
1120 ideographic-variants
1121 ;; ideographic-different-form-of
1123 (insert (format "(%-18s%s " name line-breaking))
1124 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1126 (while (consp value)
1127 (setq cell (car value))
1128 (if (and (consp cell)
1133 (char-db-insert-alist cell readable)
1134 (setq separator lbs))
1137 (insert (prin1-to-string cell))
1138 (setq separator " "))
1139 (setq value (cdr value)))
1141 (insert line-breaking))
1143 (insert (format "(%-18s " name))
1144 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1146 (while (consp value)
1147 (setq cell (car value))
1148 (if (and (consp cell)
1150 (setq ret (condition-case nil
1158 (setq key (car (car rest)))
1159 (if (find-charset key)
1160 (setq cal (cons key cal))
1161 (setq al (cons key al)))
1162 (setq rest (cdr rest)))
1165 (insert-char-attributes ret
1168 (setq separator lbs))
1169 (setq ret (prin1-to-string cell))
1171 (if (< (+ (current-column)
1178 (setq separator " "))
1179 (setq value (cdr value)))
1181 (insert line-breaking))
1183 (insert (format "(%-18s" name))
1184 (setq ret (prin1-to-string value))
1185 (unless (< (+ (current-column)
1189 (insert line-breaking))
1190 (insert " . " ret ")" line-breaking)
1191 ;; (insert (format "(%-18s . %S)%s"
1196 (setq attributes (cdr attributes)))
1199 (defun insert-char-data (char &optional readable
1202 (narrow-to-region (point)(point))
1203 (insert "(define-char
1205 (insert-char-attributes char readable attributes)
1207 (goto-char (point-min))
1208 (while (re-search-forward "[ \t]+$" nil t)
1211 (goto-char (point-min))
1212 (while (re-search-forward "[ \t][ \t][ \t]*" nil t)
1213 (let ((column (current-column))
1214 (indent-tabs-mode t))
1215 (delete-region (match-beginning 0) (point))
1216 (indent-to column)))
1217 (goto-char (point-max))
1218 ;; (tabify (point-min)(point-max))
1221 (defun insert-char-data-with-variant (char &optional printable
1223 script excluded-script)
1224 (insert-char-data char printable)
1225 (let ((variants (char-variants char))
1228 (setq variants (sort variants #'<))
1229 (setq rest variants)
1230 (setq variants (cons char variants))
1232 (setq variant (car rest))
1233 (unless (get-char-attribute variant '<-subsumptive)
1234 (if (and (or (null script)
1235 (null (setq vs (get-char-attribute variant 'script)))
1237 (or (null excluded-script)
1238 (null (setq vs (get-char-attribute variant 'script)))
1239 (not (memq excluded-script vs))))
1240 (unless (and no-ucs-unified (get-char-attribute variant '=ucs))
1241 (insert-char-data variant printable)
1242 (if (setq ret (char-variants variant))
1244 (or (memq (car ret) variants)
1245 ;; (get-char-attribute (car ret) '<-subsumptive)
1246 (setq rest (nconc rest (list (car ret)))))
1247 (setq ret (cdr ret)))))))
1248 (setq rest (cdr rest)))))
1250 (defun insert-char-range-data (min max &optional script excluded-script)
1253 (while (<= code max)
1254 (setq char (decode-char '=ucs code))
1255 (if (encode-char char '=ucs 'defined-only)
1256 (insert-char-data-with-variant char nil 'no-ucs-unified
1257 script excluded-script))
1258 (setq code (1+ code)))))
1260 (defun write-char-range-data-to-file (min max file
1261 &optional script excluded-script)
1262 (let ((coding-system-for-write char-db-file-coding-system))
1264 (insert (format ";; -*- coding: %s -*-\n"
1265 char-db-file-coding-system))
1266 (insert-char-range-data min max script excluded-script)
1267 (write-region (point-min)(point-max) file))))
1269 (defvar what-character-original-window-configuration)
1272 (defun what-char-definition (char)
1273 (interactive (list (char-after)))
1274 (let ((buf (get-buffer-create "*Character Description*"))
1275 (the-buf (current-buffer))
1276 (win-conf (current-window-configuration)))
1278 (make-local-variable 'what-character-original-window-configuration)
1279 (setq what-character-original-window-configuration win-conf)
1280 (setq buffer-read-only nil)
1284 (insert-char-data-with-variant char 'printable)
1285 (unless (char-attribute-alist char)
1286 (insert (format ";; = %c\n"
1287 (let* ((rest (split-char char))
1291 (setq code (logior (lsh code 8)
1293 (decode-char ccs code)))))
1294 ;; (char-db-update-comment)
1295 (set-buffer-modified-p nil)
1296 (view-mode the-buf (lambda (buf)
1297 (set-window-configuration
1298 what-character-original-window-configuration)
1300 (goto-char (point-min)))
1302 (set-window-configuration
1303 what-character-original-window-configuration)
1304 (signal (car err) (cdr err)))))))
1306 (provide 'char-db-util)
1308 ;;; char-db-util.el ends here