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
104 ?呂 ?穴 ?㝱 ?𤕫 ?冖 ?𠔼 ?冃 ?㒳 ?网 ?襾 ; 280
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-feature-domains
113 '(ucs ucs/compat daikanwa cns gt jis jis/alt jis/a jis/b
114 jis-x0212 jis-x0213 cdp shinjigen misc unknown))
116 (defvar char-db-ignored-attributes '(ideographic-products))
118 (defun char-attribute-name< (ka kb)
120 ((eq '->denotational kb)
122 ((eq '->subsumptive kb)
123 (not (eq '->denotational ka)))
124 ((eq '->denotational ka)
126 ((eq '->subsumptive ka)
129 (string-match "^->" (symbol-name ka)))
130 (cond ((and (symbolp kb)
131 (string-match "^->" (symbol-name kb)))
132 (string< (symbol-name ka)
137 (string-match "^->" (symbol-name kb)))
140 (string-match "^<-" (symbol-name ka)))
142 (cond ((string-match "^<-" (symbol-name kb))
143 (string< (symbol-name ka)
146 ;; ((string-match "^->" (symbol-name kb))
151 (string-match "^<-" (symbol-name kb)))
153 ;; (not (string-match "^->" (symbol-name ka)))
156 (if (find-charset kb)
157 (if (<= (charset-id ka) 1)
158 (if (<= (charset-id kb) 1)
160 ((= (charset-dimension ka)
161 (charset-dimension kb))
162 (> (charset-id ka)(charset-id kb)))
164 (> (charset-dimension ka)
165 (charset-dimension kb))
168 (if (<= (charset-id kb) 1)
170 (< (charset-id ka)(charset-id kb))))
176 (string< (symbol-name ka)
182 (defvar char-db-coded-charset-priority-list
243 (defun char-db-make-char-spec (char)
245 (cond ((characterp char)
246 (cond ((and (setq ret (encode-char char '=ucs 'defined-only))
247 (not (and (<= #xE000 ret)(<= ret #xF8FF))))
248 (setq char-spec (list (cons '=ucs ret)))
249 (cond ((setq ret (get-char-attribute char 'name))
250 (setq char-spec (cons (cons 'name ret) char-spec))
252 ((setq ret (get-char-attribute char 'name*))
253 (setq char-spec (cons (cons 'name* ret) char-spec))
258 (let ((rest char-db-coded-charset-priority-list)
261 (setq ccs (charset-name
262 (find-charset (car rest))))
264 (encode-char char ccs
266 (throw 'tag (cons ccs ret)))
267 (setq rest (cdr rest))))))
268 (setq char-spec (list ret))
269 (dolist (ccs (delq (car ret) (charset-list)))
270 (if (and (or (charset-iso-final-char ccs)
277 (setq ccs (charset-name ccs))
278 (null (assq ccs char-spec))
279 (setq ret (encode-char char ccs 'defined-only)))
280 (setq char-spec (cons (cons ccs ret) char-spec))))
282 (setq char-spec (split-char char)))
283 (cond ((setq ret (get-char-attribute char 'name))
284 (setq char-spec (cons (cons 'name ret) char-spec))
286 ((setq ret (get-char-attribute char 'name*))
287 (setq char-spec (cons (cons 'name* ret) char-spec))
294 (defun char-db-insert-char-spec (char &optional readable column
297 (setq column (current-column)))
298 (let (char-spec temp-char)
299 (setq char-spec (char-db-make-char-spec char))
300 (unless (or (characterp char) ; char
302 (setq char (find-char char-spec))
304 ;; define temporary character
305 ;; Current implementation is dirty.
306 (setq temp-char (define-char (cons '(ideograph-daikanwa . 0)
308 (remove-char-attribute temp-char 'ideograph-daikanwa)
309 (setq char temp-char))
310 (insert-char-attributes char
312 (union (mapcar #'car char-spec)
315 ;; undefine temporary character
316 ;; Current implementation is dirty.
317 (setq char-spec (char-attribute-alist temp-char))
319 (remove-char-attribute temp-char (car (car char-spec)))
320 (setq char-spec (cdr char-spec))))))
322 (defun char-db-insert-alist (alist &optional readable column)
324 (setq column (current-column)))
326 (concat "\n" (make-string (1+ column) ?\ )))
330 lbs cell rest separator)
333 (setq name (car (car alist))
334 value (cdr (car alist)))
335 (cond ((eq name 'char)
337 (if (setq ret (condition-case nil
345 (setq key (car (car value)))
346 ;; (if (find-charset key)
347 ;; (setq cal (cons key cal))
348 (setq al (cons key al))
350 (setq value (cdr value)))
351 (insert-char-attributes ret
355 (insert (prin1-to-string value)))
357 (insert line-breaking))
359 (insert (format "(%-18s " name))
360 (setq lbs (concat "\n" (make-string (current-column) ?\ )))
362 (setq cell (car value))
363 (if (and (consp cell)
365 (setq ret (condition-case nil
375 (setq key (car (car rest)))
376 ;; (if (find-charset key)
377 ;; (setq cal (cons key cal))
378 (setq al (cons key al))
380 (setq rest (cdr rest)))
383 (insert-char-attributes ret
387 (setq separator lbs))
390 (insert (prin1-to-string cell))
391 (setq separator " "))
392 (setq value (cdr value)))
394 (insert line-breaking))
396 (insert (format "(%-18s . %S)%s"
399 (setq alist (cdr alist))))
402 (defun char-db-insert-char-reference (plist &optional readable column)
404 (setq column (current-column)))
406 (concat "\n" (make-string (1+ column) ?\ )))
411 (setq name (pop plist))
412 (setq value (pop plist))
413 (cond ((eq name :char)
416 (cond ((numberp value)
417 (setq value (decode-char '=ucs value)))
419 ;; (setq value (or (find-char value)
422 (char-db-insert-char-spec value readable)
423 (insert line-breaking)
426 (insert (format "%s%s\t%d ; %c%s"
429 (ideographic-radical value)
433 (insert (format "%s%s\t%S" separator name value))
434 (setq separator line-breaking)))
438 (defun char-db-decode-isolated-char (ccs code-point)
441 (cond ((eq ccs 'arabic-iso8859-6)
442 (decode-char ccs code-point))
443 ((and (memq ccs '(=gt-pj-1
454 (setq ret (decode-char ccs code-point))
455 (setq ret (encode-char ret '=gt 'defined-only)))
456 (decode-builtin-char '=gt ret))
458 (decode-builtin-char ccs code-point))))
459 (cond ((and (<= 0 (char-int ret))
460 (<= (char-int ret) #x1F))
461 (decode-char '=ucs (+ #x2400 (char-int ret))))
462 ((= (char-int ret) #x7F)
466 (defvar char-db-convert-obsolete-format t)
468 (defun char-db-insert-ccs-feature (name value line-breaking)
471 (cond ((or (memq name '(=daikanwa
472 =daikanwa@rev1 =daikanwa@rev2
473 =gt =gt-k =cbeta =zinbun-oracle))
474 (string-match "^=adobe-" (symbol-name name)))
475 "(%-18s . %05d)\t; %c")
477 "(%-18s . %06d)\t; %c")
478 ((>= (charset-dimension name) 2)
479 "(%-18s . #x%04X)\t; %c")
481 "(%-18s . #x%02X)\t; %c"))
483 (if (= (charset-iso-graphic-plane name) 1)
485 (cond ((= (charset-dimension name) 1)
487 ((= (charset-dimension name) 2)
489 ((= (charset-dimension name) 3)
493 (char-db-decode-isolated-char name value)))
494 (if (and (= (charset-chars name) 94)
495 (= (charset-dimension name) 2))
496 (insert (format " [%02d-%02d]"
497 (- (lsh value -8) 32)
498 (- (logand value 255) 32))))
499 (insert line-breaking))
501 (defun char-db-insert-relation-feature (char name value line-breaking
503 (insert (format "(%-18s%s " name line-breaking))
504 (let ((lbs (concat "\n" (make-string (current-column) ?\ )))
505 separator cell sources required-features
508 (setq cell (car value))
510 (setq cell (decode-char '=ucs cell)))
512 ((eq name '->subsumptive)
513 (when (or (not (some (lambda (atr)
514 (get-char-attribute cell atr))
515 char-db-ignored-attributes))
517 (encode-char cell ccs 'defined-only))
521 (let ((char-db-ignored-attributes
523 char-db-ignored-attributes)))
524 (insert-char-attributes cell readable))
525 (setq separator lbs))
530 char (intern (format "%s*sources" name))))
531 (setq required-features nil)
532 (dolist (source sources)
534 ((memq source '(JP JP/Jouyou shinjigen-1))
535 (setq required-features
536 (union required-features
545 (setq required-features
546 (union required-features
551 ((find-charset (setq ret (intern (format "=%s" source))))
552 (setq required-features
553 (cons ret required-features)))
554 (t (setq required-features
555 (cons source required-features)))))
556 (cond ((string-match "@JP" (symbol-name name))
557 (setq required-features
558 (union required-features
566 ((string-match "@CN" (symbol-name name))
567 (setq required-features
568 (union required-features
575 (insert (format "%S" cell))
576 (char-db-insert-char-spec cell readable
579 (setq separator lbs))
583 (if (consp (car cell))
584 (char-db-insert-char-spec cell readable)
585 (char-db-insert-char-reference cell readable))
586 (setq separator lbs))
590 (insert (prin1-to-string cell))
591 (setq separator " ")))
592 (setq value (cdr value)))
594 (insert line-breaking)))
596 (defun insert-char-attributes (char &optional readable attributes column)
598 (setq column (current-column)))
599 (let (name value ; has-long-ccs-name
603 (concat "\n" (make-string (1+ column) ?\ )))
604 lbs cell separator ret
606 dest-ccss ; sources required-features
611 (if (consp attributes)
613 (dolist (name attributes)
614 (unless (memq name char-db-ignored-attributes)
615 (if (find-charset name)
619 (dolist (name (char-attribute-list))
620 (unless (memq name char-db-ignored-attributes)
621 (if (find-charset name)
625 #'char-attribute-name<)))
627 (when (memq '<-subsumptive attributes)
629 (when (setq value (get-char-attribute char '<-subsumptive))
630 (char-db-insert-relation-feature char '<-subsumptive value
633 (setq attributes (delq '<-subsumptive attributes)))
634 (when (and (memq '<-denotational attributes)
635 (setq value (get-char-attribute char '<-denotational)))
636 (char-db-insert-relation-feature char '<-denotational value
639 (setq attributes (delq '<-denotational attributes)))
640 (when (and (memq 'name attributes)
641 (setq value (get-char-attribute char 'name)))
643 (if (> (+ (current-column) (length value)) 48)
646 value line-breaking))
647 (setq attributes (delq 'name attributes))
649 (when (and (memq 'name* attributes)
650 (setq value (get-char-attribute char 'name*)))
652 (if (> (+ (current-column) (length value)) 48)
655 value line-breaking))
656 (setq attributes (delq 'name* attributes))
658 (when (and (memq 'script attributes)
659 (setq value (get-char-attribute char 'script)))
660 (insert (format "(script\t\t%s)%s"
661 (mapconcat (function prin1-to-string)
664 (setq attributes (delq 'script attributes))
666 (dolist (name '(=>ucs =>ucs*))
667 (when (and (memq name attributes)
668 (setq value (get-char-attribute char name)))
669 (insert (format "(%-18s . #x%04X)\t; %c%s"
670 name value (decode-char '=ucs value)
672 (setq attributes (delq name attributes))))
673 (dolist (name '(=>ucs@gb =>ucs@cns =>ucs@jis =>ucs@ks =>ucs@big5))
674 (when (and (memq name attributes)
675 (setq value (get-char-attribute char name)))
676 (insert (format "(%-18s . #x%04X)\t; %c%s"
681 (symbol-name name) 2)))
684 (setq attributes (delq name attributes))
686 (dolist (name '(=>daikanwa))
687 (when (and (memq name attributes)
688 (setq value (get-char-attribute char name)))
691 (format "(%-18s . %05d)\t; %c%s"
692 name value (decode-char '=daikanwa value)
694 (format "(%-18s %s)\t; %c%s"
696 (mapconcat (function prin1-to-string)
698 (char-representative-of-daikanwa char)
700 (setq attributes (delq name attributes))))
701 (when (and (memq 'general-category attributes)
702 (setq value (get-char-attribute char 'general-category)))
704 "(general-category\t%s) ; %s%s"
705 (mapconcat (lambda (cell)
708 (cond ((rassoc value unidata-normative-category-alist)
709 "Normative Category")
710 ((rassoc value unidata-informative-category-alist)
711 "Informative Category")
715 (setq attributes (delq 'general-category attributes))
717 (when (and (memq 'bidi-category attributes)
718 (setq value (get-char-attribute char 'bidi-category)))
719 (insert (format "(bidi-category\t. %S)%s"
722 (setq attributes (delq 'bidi-category attributes))
724 (unless (or (not (memq 'mirrored attributes))
725 (eq (setq value (get-char-attribute char 'mirrored 'empty))
727 (insert (format "(mirrored\t\t. %S)%s"
730 (setq attributes (delq 'mirrored attributes))
733 ((and (memq 'decimal-digit-value attributes)
734 (setq value (get-char-attribute char 'decimal-digit-value)))
735 (insert (format "(decimal-digit-value . %S)%s"
738 (setq attributes (delq 'decimal-digit-value attributes))
739 (when (and (memq 'digit-value attributes)
740 (setq value (get-char-attribute char 'digit-value)))
741 (insert (format "(digit-value\t . %S)%s"
744 (setq attributes (delq 'digit-value attributes))
746 (when (and (memq 'numeric-value attributes)
747 (setq value (get-char-attribute char 'numeric-value)))
748 (insert (format "(numeric-value\t . %S)%s"
751 (setq attributes (delq 'numeric-value attributes))
755 (when (and (memq 'digit-value attributes)
756 (setq value (get-char-attribute char 'digit-value)))
757 (insert (format "(digit-value\t. %S)%s"
760 (setq attributes (delq 'digit-value attributes))
762 (when (and (memq 'numeric-value attributes)
763 (setq value (get-char-attribute char 'numeric-value)))
764 (insert (format "(numeric-value\t. %S)%s"
767 (setq attributes (delq 'numeric-value attributes))
769 (when (and (memq 'iso-10646-comment attributes)
770 (setq value (get-char-attribute char 'iso-10646-comment)))
771 (insert (format "(iso-10646-comment\t. %S)%s"
774 (setq attributes (delq 'iso-10646-comment attributes))
776 (when (and (memq 'morohashi-daikanwa attributes)
777 (setq value (get-char-attribute char 'morohashi-daikanwa)))
778 (insert (format "(morohashi-daikanwa\t%s)%s"
779 (mapconcat (function prin1-to-string) value " ")
781 (setq attributes (delq 'morohashi-daikanwa attributes))
785 (when (and (memq 'ideographic-radical attributes)
786 (setq value (get-char-attribute char 'ideographic-radical)))
788 (insert (format "(ideographic-radical . %S)\t; %c%s"
790 (ideographic-radical radical)
792 (setq attributes (delq 'ideographic-radical attributes))
794 (when (and (memq 'shuowen-radical attributes)
795 (setq value (get-char-attribute char 'shuowen-radical)))
796 (insert (format "(shuowen-radical\t. %S)\t; %c%s"
798 (shuowen-radical value)
800 (setq attributes (delq 'shuowen-radical attributes))
805 char-db-feature-domains
807 (dolist (feature (char-attribute-list))
808 (setq feature (symbol-name feature))
810 "\\(radical\\|strokes\\)@\\([^@*]+\\)\\(\\*\\|$\\)"
812 (setq domain (intern (match-string 2 feature)))
813 (unless (memq domain dest)
814 (setq dest (cons domain dest)))))
815 (sort dest #'string<))))
816 (setq key (intern (format "%s@%s" 'ideographic-radical domain)))
817 (when (and (memq key attributes)
818 (setq value (get-char-attribute char key)))
820 (insert (format "(%s . %S)\t; %c%s"
823 (ideographic-radical radical)
825 (setq attributes (delq key attributes))
827 (setq key (intern (format "%s@%s" 'ideographic-strokes domain)))
828 (when (and (memq key attributes)
829 (setq value (get-char-attribute char key)))
831 (insert (format "(%s . %S)%s"
835 (setq attributes (delq key attributes))
837 (setq key (intern (format "%s@%s" 'total-strokes domain)))
838 (when (and (memq key attributes)
839 (setq value (get-char-attribute char key)))
840 (insert (format "(%s . %S)%s"
844 (setq attributes (delq key attributes))
846 (dolist (feature '(ideographic-radical
849 (setq key (intern (format "%s@%s*sources" feature domain)))
850 (when (and (memq key attributes)
851 (setq value (get-char-attribute char key)))
852 (insert (format "(%s%s" key line-breaking))
854 (insert (format " %s" cell)))
856 (insert line-breaking)
857 (setq attributes (delq key attributes))
860 (when (and (memq 'ideographic-strokes attributes)
861 (setq value (get-char-attribute char 'ideographic-strokes)))
863 (insert (format "(ideographic-strokes . %S)%s"
866 (setq attributes (delq 'ideographic-strokes attributes))
868 (when (and (memq 'kangxi-radical attributes)
869 (setq value (get-char-attribute char 'kangxi-radical)))
870 (unless (eq value radical)
871 (insert (format "(kangxi-radical\t . %S)\t; %c%s"
873 (ideographic-radical value)
876 (setq radical value)))
877 (setq attributes (delq 'kangxi-radical attributes))
879 (when (and (memq 'kangxi-strokes attributes)
880 (setq value (get-char-attribute char 'kangxi-strokes)))
881 (unless (eq value strokes)
882 (insert (format "(kangxi-strokes\t . %S)%s"
886 (setq strokes value)))
887 (setq attributes (delq 'kangxi-strokes attributes))
889 (when (and (memq 'japanese-radical attributes)
890 (setq value (get-char-attribute char 'japanese-radical)))
891 (unless (eq value radical)
892 (insert (format "(japanese-radical\t . %S)\t; %c%s"
894 (ideographic-radical value)
897 (setq radical value)))
898 (setq attributes (delq 'japanese-radical attributes))
900 (when (and (memq 'japanese-strokes attributes)
901 (setq value (get-char-attribute char 'japanese-strokes)))
902 (unless (eq value strokes)
903 (insert (format "(japanese-strokes\t . %S)%s"
907 (setq strokes value)))
908 (setq attributes (delq 'japanese-strokes attributes))
910 (when (and (memq 'cns-radical attributes)
911 (setq value (get-char-attribute char 'cns-radical)))
912 (insert (format "(cns-radical\t . %S)\t; %c%s"
914 (ideographic-radical value)
916 (setq attributes (delq 'cns-radical attributes))
918 (when (and (memq 'cns-strokes attributes)
919 (setq value (get-char-attribute char 'cns-strokes)))
920 (unless (eq value strokes)
921 (insert (format "(cns-strokes\t . %S)%s"
925 (setq strokes value)))
926 (setq attributes (delq 'cns-strokes attributes))
928 (when (and (memq 'shinjigen-1-radical attributes)
929 (setq value (get-char-attribute char 'shinjigen-1-radical)))
930 (unless (eq value radical)
931 (insert (format "(shinjigen-1-radical . %S)\t; %c%s"
933 (ideographic-radical value)
936 (setq radical value)))
937 (setq attributes (delq 'shinjigen-1-radical attributes))
939 (when (and (memq 'ideographic- attributes)
940 (setq value (get-char-attribute char 'ideographic-)))
941 (insert "(ideographic- ")
942 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
945 (setq cell (car value))
947 (setq cell (decode-char '=ucs cell)))
948 (cond ((characterp cell)
952 (insert (format "%S" cell))
953 (char-db-insert-char-spec cell readable))
954 (setq separator lbs))
958 (if (consp (car cell))
959 (char-db-insert-char-spec cell readable)
960 (char-db-insert-char-reference cell readable))
961 (setq separator lbs))
965 (insert (prin1-to-string cell))
966 (setq separator " ")))
967 (setq value (cdr value)))
969 (insert line-breaking)
970 (setq attributes (delq 'ideographic- attributes)))
971 (when (and (memq 'total-strokes attributes)
972 (setq value (get-char-attribute char 'total-strokes)))
973 (insert (format "(total-strokes . %S)%s"
976 (setq attributes (delq 'total-strokes attributes))
978 (when (and (memq '->ideograph attributes)
979 (setq value (get-char-attribute char '->ideograph)))
980 (insert (format "(->ideograph\t%s)%s"
981 (mapconcat (lambda (code)
982 (cond ((symbolp code)
985 (format "#x%04X" code))
988 line-breaking code))))
991 (setq attributes (delq '->ideograph attributes))
993 ;; (when (and (memq '->decomposition attributes)
994 ;; (setq value (get-char-attribute char '->decomposition)))
995 ;; (insert (format "(->decomposition\t%s)%s"
996 ;; (mapconcat (lambda (code)
997 ;; (cond ((symbolp code)
998 ;; (symbol-name code))
999 ;; ((characterp code)
1001 ;; (format "%S" code)
1006 ;; (format "#x%04X" code))
1008 ;; (format "%s%S" line-breaking code))))
1011 ;; (setq attributes (delq '->decomposition attributes))
1013 (if (equal (get-char-attribute char '->titlecase)
1014 (get-char-attribute char '->uppercase))
1015 (setq attributes (delq '->titlecase attributes)))
1016 (when (and (memq '->mojikyo attributes)
1017 (setq value (get-char-attribute char '->mojikyo)))
1018 (insert (format "(->mojikyo\t\t. %06d)\t; %c%s"
1019 value (decode-char 'mojikyo value)
1021 (setq attributes (delq '->mojikyo attributes))
1023 (when (and (memq 'hanyu-dazidian-vol attributes)
1024 (setq value (get-char-attribute char 'hanyu-dazidian-vol)))
1025 (insert (format "(hanyu-dazidian-vol . %d)%s"
1026 value line-breaking))
1027 (setq attributes (delq 'hanyu-dazidian-vol attributes))
1029 (when (and (memq 'hanyu-dazidian-page attributes)
1030 (setq value (get-char-attribute char 'hanyu-dazidian-page)))
1031 (insert (format "(hanyu-dazidian-page . %d)%s"
1032 value line-breaking))
1033 (setq attributes (delq 'hanyu-dazidian-page attributes))
1035 (when (and (memq 'hanyu-dazidian-char attributes)
1036 (setq value (get-char-attribute char 'hanyu-dazidian-char)))
1037 (insert (format "(hanyu-dazidian-char . %d)%s"
1038 value line-breaking))
1039 (setq attributes (delq 'hanyu-dazidian-char attributes))
1042 (dolist (ignored '(composition
1043 ->denotational <-subsumptive ->ucs-unified
1044 ->ideographic-component-forms))
1045 (setq attributes (delq ignored attributes))))
1047 (setq name (car attributes))
1048 (if (setq value (get-char-attribute char name))
1049 (cond ((setq ret (find-charset name))
1050 (setq name (charset-name ret))
1051 (if (and (not (memq name dest-ccss))
1053 (setq value (get-char-attribute char name))
1054 (setq dest-ccss (cons name dest-ccss))))
1055 (char-db-insert-ccs-feature name value line-breaking))
1057 ((string-match "^=>ucs@" (symbol-name name))
1058 (insert (format "(%-18s . #x%04X)\t; %c%s"
1059 name value (decode-char '=ucs value)
1062 ((eq name 'jisx0208-1978/4X)
1063 (insert (format "(%-18s . #x%04X)%s"
1069 (not (eq name '->subsumptive))
1070 (not (eq name '->uppercase))
1071 (not (eq name '->lowercase))
1072 (not (eq name '->titlecase))
1073 (not (eq name '->canonical))
1074 (not (eq name '->Bopomofo))
1075 (not (eq name '->mistakable))
1076 (not (eq name '->ideographic-variants))
1077 (null (get-char-attribute
1078 char (intern (format "%s*sources" name))))
1079 (not (string-match "\\*sources$" (symbol-name name)))
1080 (null (get-char-attribute
1081 char (intern (format "%s*note" name))))
1082 (not (string-match "\\*note$" (symbol-name name)))
1083 (or (eq name '<-identical)
1084 (eq name '<-uppercase)
1085 (eq name '<-lowercase)
1086 (eq name '<-titlecase)
1087 (eq name '<-canonical)
1088 (eq name '<-ideographic-variants)
1089 ;; (eq name '<-synonyms)
1090 (string-match "^<-synonyms" (symbol-name name))
1091 (eq name '<-mistakable)
1092 (when (string-match "^->" (symbol-name name))
1094 ((string-match "^->fullwidth" (symbol-name name))
1095 (not (and (consp value)
1096 (characterp (car value))
1098 (car value) '=ucs 'defined-only)))
1103 ((or (eq name 'ideographic-structure)
1104 (eq name 'ideographic-combination)
1105 (eq name 'ideographic-)
1106 (eq name '=decomposition)
1107 (string-match "^=>decomposition" (symbol-name name))
1108 (string-match "^\\(->\\|<-\\)[^*]*$" (symbol-name name))
1109 (string-match "^\\(->\\|<-\\)[^*]*\\*sources$"
1112 (char-db-insert-relation-feature char name value
1115 ((memq name '(ideograph=
1116 original-ideograph-of
1117 ancient-ideograph-of
1120 ;; simplified-ideograph-of
1121 ideographic-variants
1122 ;; ideographic-different-form-of
1124 (insert (format "(%-18s%s " name line-breaking))
1125 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1127 (while (consp value)
1128 (setq cell (car value))
1129 (if (and (consp cell)
1134 (char-db-insert-alist cell readable)
1135 (setq separator lbs))
1138 (insert (prin1-to-string cell))
1139 (setq separator " "))
1140 (setq value (cdr value)))
1142 (insert line-breaking))
1144 (insert (format "(%-18s " name))
1145 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1147 (while (consp value)
1148 (setq cell (car value))
1149 (if (and (consp cell)
1151 (setq ret (condition-case nil
1159 (setq key (car (car rest)))
1160 (if (find-charset key)
1161 (setq cal (cons key cal))
1162 (setq al (cons key al)))
1163 (setq rest (cdr rest)))
1166 (insert-char-attributes ret
1169 (setq separator lbs))
1170 (setq ret (prin1-to-string cell))
1172 (if (< (+ (current-column)
1179 (setq separator " "))
1180 (setq value (cdr value)))
1182 (insert line-breaking))
1184 (insert (format "(%-18s" name))
1185 (setq ret (prin1-to-string value))
1186 (unless (< (+ (current-column)
1190 (insert line-breaking))
1191 (insert " . " ret ")" line-breaking)
1192 ;; (insert (format "(%-18s . %S)%s"
1197 (setq attributes (cdr attributes)))
1200 (defun insert-char-data (char &optional readable
1203 (narrow-to-region (point)(point))
1204 (insert "(define-char
1206 (insert-char-attributes char readable attributes)
1208 (goto-char (point-min))
1209 (while (re-search-forward "[ \t]+$" nil t)
1212 (goto-char (point-min))
1213 (while (re-search-forward "[ \t][ \t][ \t]*" nil t)
1214 (let ((column (current-column))
1215 (indent-tabs-mode t))
1216 (delete-region (match-beginning 0) (point))
1217 (indent-to column)))
1218 (goto-char (point-max))
1219 ;; (tabify (point-min)(point-max))
1222 (defun insert-char-data-with-variant (char &optional printable
1224 script excluded-script)
1225 (insert-char-data char printable)
1226 (let ((variants (char-variants char))
1229 (setq variants (sort variants #'<))
1230 (setq rest variants)
1231 (setq variants (cons char variants))
1233 (setq variant (car rest))
1234 (unless (get-char-attribute variant '<-subsumptive)
1235 (if (and (or (null script)
1236 (null (setq vs (get-char-attribute variant 'script)))
1238 (or (null excluded-script)
1239 (null (setq vs (get-char-attribute variant 'script)))
1240 (not (memq excluded-script vs))))
1241 (unless (and no-ucs-unified (get-char-attribute variant '=ucs))
1242 (insert-char-data variant printable)
1243 (if (setq ret (char-variants variant))
1245 (or (memq (car ret) variants)
1246 ;; (get-char-attribute (car ret) '<-subsumptive)
1247 (setq rest (nconc rest (list (car ret)))))
1248 (setq ret (cdr ret)))))))
1249 (setq rest (cdr rest)))))
1251 (defun insert-char-range-data (min max &optional script excluded-script)
1254 (while (<= code max)
1255 (setq char (decode-char '=ucs code))
1256 (if (encode-char char '=ucs 'defined-only)
1257 (insert-char-data-with-variant char nil 'no-ucs-unified
1258 script excluded-script))
1259 (setq code (1+ code)))))
1261 (defun write-char-range-data-to-file (min max file
1262 &optional script excluded-script)
1263 (let ((coding-system-for-write char-db-file-coding-system))
1265 (insert (format ";; -*- coding: %s -*-\n"
1266 char-db-file-coding-system))
1267 (insert-char-range-data min max script excluded-script)
1268 (write-region (point-min)(point-max) file))))
1270 (defvar what-character-original-window-configuration)
1273 (defun what-char-definition (char)
1274 (interactive (list (char-after)))
1275 (let ((buf (get-buffer-create "*Character Description*"))
1276 (the-buf (current-buffer))
1277 (win-conf (current-window-configuration)))
1279 (make-local-variable 'what-character-original-window-configuration)
1280 (setq what-character-original-window-configuration win-conf)
1281 (setq buffer-read-only nil)
1285 (insert-char-data-with-variant char 'printable)
1286 (unless (char-attribute-alist char)
1287 (insert (format ";; = %c\n"
1288 (let* ((rest (split-char char))
1292 (setq code (logior (lsh code 8)
1294 (decode-char ccs code)))))
1295 ;; (char-db-update-comment)
1296 (set-buffer-modified-p nil)
1297 (view-mode the-buf (lambda (buf)
1298 (set-window-configuration
1299 what-character-original-window-configuration)
1301 (goto-char (point-min)))
1303 (set-window-configuration
1304 what-character-original-window-configuration)
1305 (signal (car err) (cdr err)))))))
1307 (provide 'char-db-util)
1309 ;;; char-db-util.el ends here