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
105 ?巾 ?巿 ?帛 ?白 ?㡀 ?黹 ?人 ?𠤎 ?匕 ?从 ; 290
108 (defun shuowen-radical (number)
109 (aref shuowen-radicals (1- number)))
111 (defvar char-db-file-coding-system 'utf-8-mcs-er)
113 (defvar char-db-feature-domains
114 '(ucs ucs/compat daikanwa cns gt jis jis/alt jis/a jis/b
115 jis-x0212 jis-x0213 cdp shinjigen misc unknown))
117 (defvar char-db-ignored-attributes '(ideographic-products))
119 (defun char-attribute-name< (ka kb)
121 ((eq '->denotational kb)
123 ((eq '->subsumptive kb)
124 (not (eq '->denotational ka)))
125 ((eq '->denotational ka)
127 ((eq '->subsumptive ka)
130 (string-match "^->" (symbol-name ka)))
131 (cond ((and (symbolp kb)
132 (string-match "^->" (symbol-name kb)))
133 (string< (symbol-name ka)
138 (string-match "^->" (symbol-name kb)))
141 (string-match "^<-" (symbol-name ka)))
143 (cond ((string-match "^<-" (symbol-name kb))
144 (string< (symbol-name ka)
147 ;; ((string-match "^->" (symbol-name kb))
152 (string-match "^<-" (symbol-name kb)))
154 ;; (not (string-match "^->" (symbol-name ka)))
157 (if (find-charset kb)
158 (if (<= (charset-id ka) 1)
159 (if (<= (charset-id kb) 1)
161 ((= (charset-dimension ka)
162 (charset-dimension kb))
163 (> (charset-id ka)(charset-id kb)))
165 (> (charset-dimension ka)
166 (charset-dimension kb))
169 (if (<= (charset-id kb) 1)
172 ((and (charset-final ka)
173 (>= (charset-final ka) ?@))
174 (if (and (charset-final kb)
175 (>= (charset-final kb) ?@))
176 (< (charset-final ka)(charset-final kb))
178 ((and (charset-final kb)
179 (>= (charset-final kb) ?@))
182 (< (charset-id ka)(charset-id kb))))))
188 (string< (symbol-name ka)
194 (defvar char-db-coded-charset-priority-list
255 (defun char-db-make-char-spec (char)
257 (cond ((characterp char)
258 (cond ((and (setq ret (encode-char char '=ucs 'defined-only))
259 (not (and (<= #xE000 ret)(<= ret #xF8FF))))
260 (setq char-spec (list (cons '=ucs ret)))
261 (cond ((setq ret (get-char-attribute char 'name))
262 (setq char-spec (cons (cons 'name ret) char-spec))
264 ((setq ret (get-char-attribute char 'name*))
265 (setq char-spec (cons (cons 'name* ret) char-spec))
270 (let ((rest char-db-coded-charset-priority-list)
273 (setq ccs (charset-name
274 (find-charset (car rest))))
276 (encode-char char ccs
278 (throw 'tag (cons ccs ret)))
279 (setq rest (cdr rest))))))
280 (setq char-spec (list ret))
281 (dolist (ccs (delq (car ret) (charset-list)))
282 (if (and (or (charset-iso-final-char ccs)
289 (setq ccs (charset-name ccs))
290 (null (assq ccs char-spec))
291 (setq ret (encode-char char ccs 'defined-only)))
292 (setq char-spec (cons (cons ccs ret) char-spec))))
294 (setq char-spec (split-char char)))
295 (cond ((setq ret (get-char-attribute char 'name))
296 (setq char-spec (cons (cons 'name ret) char-spec))
298 ((setq ret (get-char-attribute char 'name*))
299 (setq char-spec (cons (cons 'name* ret) char-spec))
306 (defun char-db-insert-char-spec (char &optional readable column
309 (setq column (current-column)))
310 (let (char-spec temp-char)
311 (setq char-spec (char-db-make-char-spec char))
312 (unless (or (characterp char) ; char
314 (setq char (find-char char-spec))
316 ;; define temporary character
317 ;; Current implementation is dirty.
318 (setq temp-char (define-char (cons '(ideograph-daikanwa . 0)
320 (remove-char-attribute temp-char 'ideograph-daikanwa)
321 (setq char temp-char))
322 (insert-char-attributes char
324 (union (mapcar #'car char-spec)
327 ;; undefine temporary character
328 ;; Current implementation is dirty.
329 (setq char-spec (char-attribute-alist temp-char))
331 (remove-char-attribute temp-char (car (car char-spec)))
332 (setq char-spec (cdr char-spec))))))
334 (defun char-db-insert-alist (alist &optional readable column)
336 (setq column (current-column)))
338 (concat "\n" (make-string (1+ column) ?\ )))
342 lbs cell rest separator)
345 (setq name (car (car alist))
346 value (cdr (car alist)))
347 (cond ((eq name 'char)
349 (if (setq ret (condition-case nil
357 (setq key (car (car value)))
358 ;; (if (find-charset key)
359 ;; (setq cal (cons key cal))
360 (setq al (cons key al))
362 (setq value (cdr value)))
363 (insert-char-attributes ret
367 (insert (prin1-to-string value)))
369 (insert line-breaking))
371 (insert (format "(%-18s " name))
372 (setq lbs (concat "\n" (make-string (current-column) ?\ )))
374 (setq cell (car value))
375 (if (and (consp cell)
377 (setq ret (condition-case nil
387 (setq key (car (car rest)))
388 ;; (if (find-charset key)
389 ;; (setq cal (cons key cal))
390 (setq al (cons key al))
392 (setq rest (cdr rest)))
395 (insert-char-attributes ret
399 (setq separator lbs))
402 (insert (prin1-to-string cell))
403 (setq separator " "))
404 (setq value (cdr value)))
406 (insert line-breaking))
408 (insert (format "(%-18s . %S)%s"
411 (setq alist (cdr alist))))
414 (defun char-db-insert-char-reference (plist &optional readable column)
416 (setq column (current-column)))
418 (concat "\n" (make-string (1+ column) ?\ )))
423 (setq name (pop plist))
424 (setq value (pop plist))
425 (cond ((eq name :char)
428 (cond ((numberp value)
429 (setq value (decode-char '=ucs value)))
431 ;; (setq value (or (find-char value)
434 (char-db-insert-char-spec value readable)
435 (insert line-breaking)
438 (insert (format "%s%s\t%d ; %c%s"
441 (ideographic-radical value)
445 (insert (format "%s%s\t%S" separator name value))
446 (setq separator line-breaking)))
450 (defun char-db-decode-isolated-char (ccs code-point)
453 (cond ((eq ccs 'arabic-iso8859-6)
454 (decode-char ccs code-point))
455 ((and (memq ccs '(=gt-pj-1
466 (setq ret (decode-char ccs code-point))
467 (setq ret (encode-char ret '=gt 'defined-only)))
468 (decode-builtin-char '=gt ret))
470 (decode-builtin-char ccs code-point))))
471 (cond ((and (<= 0 (char-int ret))
472 (<= (char-int ret) #x1F))
473 (decode-char '=ucs (+ #x2400 (char-int ret))))
474 ((= (char-int ret) #x7F)
478 (defvar char-db-convert-obsolete-format t)
480 (defun char-db-insert-ccs-feature (name value line-breaking)
483 (cond ((memq name '(=shinjigen
485 =shinjigen@rev =shinjigen/+p@rev))
486 "(%-18s . %04d)\t; %c")
487 ((eq name '=shinjigen@1ed/24pr)
488 "(%-18s . %04d)\t; %c")
489 ((or (memq name '(=daikanwa
490 =daikanwa@rev1 =daikanwa@rev2
491 =gt =gt-k =cbeta =zinbun-oracle))
492 (string-match "^=adobe-" (symbol-name name)))
493 "(%-18s . %05d)\t; %c")
495 "(%-18s . %06d)\t; %c")
496 ((>= (charset-dimension name) 2)
497 "(%-18s . #x%04X)\t; %c")
499 "(%-18s . #x%02X)\t; %c"))
501 (if (= (charset-iso-graphic-plane name) 1)
503 (cond ((= (charset-dimension name) 1)
505 ((= (charset-dimension name) 2)
507 ((= (charset-dimension name) 3)
511 (char-db-decode-isolated-char name value)))
512 (if (and (= (charset-chars name) 94)
513 (= (charset-dimension name) 2))
514 (insert (format " [%02d-%02d]"
515 (- (lsh value -8) 32)
516 (- (logand value 255) 32))))
517 (insert line-breaking))
519 (defun char-db-insert-relation-feature (char name value line-breaking
521 (insert (format "(%-18s%s " name line-breaking))
522 (let ((lbs (concat "\n" (make-string (current-column) ?\ )))
523 separator cell sources required-features
526 (setq cell (car value))
528 (setq cell (decode-char '=ucs cell)))
530 ((eq name '->subsumptive)
531 (when (or (not (some (lambda (atr)
532 (get-char-attribute cell atr))
533 char-db-ignored-attributes))
535 (encode-char cell ccs 'defined-only))
539 (let ((char-db-ignored-attributes
541 char-db-ignored-attributes)))
542 (insert-char-attributes cell readable))
543 (setq separator lbs))
548 char (intern (format "%s*sources" name))))
549 (setq required-features nil)
550 (dolist (source sources)
554 shinjigen shinjigen@1ed shinjigen@rev))
555 (setq required-features
556 (union required-features
566 (setq required-features
567 (union required-features
572 ((find-charset (setq ret (intern (format "=%s" source))))
573 (setq required-features
574 (cons ret required-features)))
575 (t (setq required-features
576 (cons source required-features)))))
577 (cond ((string-match "@JP" (symbol-name name))
578 (setq required-features
579 (union required-features
587 ((string-match "@CN" (symbol-name name))
588 (setq required-features
589 (union required-features
596 (insert (format "%S" cell))
597 (char-db-insert-char-spec cell readable
600 (setq separator lbs))
604 (if (consp (car cell))
605 (char-db-insert-char-spec cell readable)
606 (char-db-insert-char-reference cell readable))
607 (setq separator lbs))
611 (insert (prin1-to-string cell))
612 (setq separator " ")))
613 (setq value (cdr value)))
615 (insert line-breaking)))
617 (defun insert-char-attributes (char &optional readable attributes column)
619 (setq column (current-column)))
620 (let (name value ; has-long-ccs-name
624 (concat "\n" (make-string (1+ column) ?\ )))
625 lbs cell separator ret
627 dest-ccss ; sources required-features
632 (if (consp attributes)
634 (dolist (name attributes)
635 (unless (memq name char-db-ignored-attributes)
636 (if (find-charset name)
640 (dolist (name (char-attribute-list))
641 (unless (memq name char-db-ignored-attributes)
642 (if (find-charset name)
646 #'char-attribute-name<)))
648 (when (memq '<-subsumptive attributes)
650 (when (setq value (get-char-attribute char '<-subsumptive))
651 (char-db-insert-relation-feature char '<-subsumptive value
654 (setq attributes (delq '<-subsumptive attributes)))
655 (when (and (memq '<-denotational attributes)
656 (setq value (get-char-attribute char '<-denotational)))
657 (char-db-insert-relation-feature char '<-denotational value
660 (setq attributes (delq '<-denotational attributes)))
661 (when (and (memq 'name attributes)
662 (setq value (get-char-attribute char 'name)))
664 (if (> (+ (current-column) (length value)) 48)
667 value line-breaking))
668 (setq attributes (delq 'name attributes))
670 (when (and (memq 'name* attributes)
671 (setq value (get-char-attribute char 'name*)))
673 (if (> (+ (current-column) (length value)) 48)
676 value line-breaking))
677 (setq attributes (delq 'name* attributes))
679 (when (and (memq 'script attributes)
680 (setq value (get-char-attribute char 'script)))
681 (insert (format "(script\t\t%s)%s"
682 (mapconcat (function prin1-to-string)
685 (setq attributes (delq 'script attributes))
687 (dolist (name '(=>ucs =>ucs*))
688 (when (and (memq name attributes)
689 (setq value (get-char-attribute char name)))
690 (insert (format "(%-18s . #x%04X)\t; %c%s"
691 name value (decode-char '=ucs value)
693 (setq attributes (delq name attributes))))
694 (dolist (name '(=>ucs@gb =>ucs@cns =>ucs@jis =>ucs@ks =>ucs@big5))
695 (when (and (memq name attributes)
696 (setq value (get-char-attribute char name)))
697 (insert (format "(%-18s . #x%04X)\t; %c%s"
702 (symbol-name name) 2)))
705 (setq attributes (delq name attributes))
707 (dolist (name '(=>daikanwa))
708 (when (and (memq name attributes)
709 (setq value (get-char-attribute char name)))
712 (format "(%-18s . %05d)\t; %c%s"
713 name value (decode-char '=daikanwa value)
715 (format "(%-18s %s)\t; %c%s"
717 (mapconcat (function prin1-to-string)
719 (char-representative-of-daikanwa char)
721 (setq attributes (delq name attributes))))
722 (when (and (memq 'general-category attributes)
723 (setq value (get-char-attribute char 'general-category)))
725 "(general-category\t%s) ; %s%s"
726 (mapconcat (lambda (cell)
729 (cond ((rassoc value unidata-normative-category-alist)
730 "Normative Category")
731 ((rassoc value unidata-informative-category-alist)
732 "Informative Category")
736 (setq attributes (delq 'general-category attributes))
738 (when (and (memq 'bidi-category attributes)
739 (setq value (get-char-attribute char 'bidi-category)))
740 (insert (format "(bidi-category\t. %S)%s"
743 (setq attributes (delq 'bidi-category attributes))
745 (unless (or (not (memq 'mirrored attributes))
746 (eq (setq value (get-char-attribute char 'mirrored 'empty))
748 (insert (format "(mirrored\t\t. %S)%s"
751 (setq attributes (delq 'mirrored attributes))
754 ((and (memq 'decimal-digit-value attributes)
755 (setq value (get-char-attribute char 'decimal-digit-value)))
756 (insert (format "(decimal-digit-value . %S)%s"
759 (setq attributes (delq 'decimal-digit-value attributes))
760 (when (and (memq 'digit-value attributes)
761 (setq value (get-char-attribute char 'digit-value)))
762 (insert (format "(digit-value\t . %S)%s"
765 (setq attributes (delq 'digit-value attributes))
767 (when (and (memq 'numeric-value attributes)
768 (setq value (get-char-attribute char 'numeric-value)))
769 (insert (format "(numeric-value\t . %S)%s"
772 (setq attributes (delq 'numeric-value attributes))
776 (when (and (memq 'digit-value attributes)
777 (setq value (get-char-attribute char 'digit-value)))
778 (insert (format "(digit-value\t. %S)%s"
781 (setq attributes (delq 'digit-value attributes))
783 (when (and (memq 'numeric-value attributes)
784 (setq value (get-char-attribute char 'numeric-value)))
785 (insert (format "(numeric-value\t. %S)%s"
788 (setq attributes (delq 'numeric-value attributes))
790 (when (and (memq 'iso-10646-comment attributes)
791 (setq value (get-char-attribute char 'iso-10646-comment)))
792 (insert (format "(iso-10646-comment\t. %S)%s"
795 (setq attributes (delq 'iso-10646-comment attributes))
797 (when (and (memq 'morohashi-daikanwa attributes)
798 (setq value (get-char-attribute char 'morohashi-daikanwa)))
799 (insert (format "(morohashi-daikanwa\t%s)%s"
800 (mapconcat (function prin1-to-string) value " ")
802 (setq attributes (delq 'morohashi-daikanwa attributes))
806 (when (and (memq 'ideographic-radical attributes)
807 (setq value (get-char-attribute char 'ideographic-radical)))
809 (insert (format "(ideographic-radical . %S)\t; %c%s"
811 (ideographic-radical radical)
813 (setq attributes (delq 'ideographic-radical attributes))
815 (when (and (memq 'shuowen-radical attributes)
816 (setq value (get-char-attribute char 'shuowen-radical)))
817 (insert (format "(shuowen-radical\t. %S)\t; %c%s"
819 (shuowen-radical value)
821 (setq attributes (delq 'shuowen-radical attributes))
826 char-db-feature-domains
828 (dolist (feature (char-attribute-list))
829 (setq feature (symbol-name feature))
831 "\\(radical\\|strokes\\)@\\([^@*]+\\)\\(\\*\\|$\\)"
833 (setq domain (intern (match-string 2 feature)))
834 (unless (memq domain dest)
835 (setq dest (cons domain dest)))))
836 (sort dest #'string<))))
837 (setq key (intern (format "%s@%s" 'ideographic-radical domain)))
838 (when (and (memq key attributes)
839 (setq value (get-char-attribute char key)))
841 (insert (format "(%s . %S)\t; %c%s"
844 (ideographic-radical radical)
846 (setq attributes (delq key attributes))
848 (setq key (intern (format "%s@%s" 'ideographic-strokes domain)))
849 (when (and (memq key attributes)
850 (setq value (get-char-attribute char key)))
852 (insert (format "(%s . %S)%s"
856 (setq attributes (delq key attributes))
858 (setq key (intern (format "%s@%s" 'total-strokes domain)))
859 (when (and (memq key attributes)
860 (setq value (get-char-attribute char key)))
861 (insert (format "(%s . %S)%s"
865 (setq attributes (delq key attributes))
867 (dolist (feature '(ideographic-radical
870 (setq key (intern (format "%s@%s*sources" feature domain)))
871 (when (and (memq key attributes)
872 (setq value (get-char-attribute char key)))
873 (insert (format "(%s%s" key line-breaking))
875 (insert (format " %s" cell)))
877 (insert line-breaking)
878 (setq attributes (delq key attributes))
881 (when (and (memq 'ideographic-strokes attributes)
882 (setq value (get-char-attribute char 'ideographic-strokes)))
884 (insert (format "(ideographic-strokes . %S)%s"
887 (setq attributes (delq 'ideographic-strokes attributes))
889 (when (and (memq 'kangxi-radical attributes)
890 (setq value (get-char-attribute char 'kangxi-radical)))
891 (unless (eq value radical)
892 (insert (format "(kangxi-radical\t . %S)\t; %c%s"
894 (ideographic-radical value)
897 (setq radical value)))
898 (setq attributes (delq 'kangxi-radical attributes))
900 (when (and (memq 'kangxi-strokes attributes)
901 (setq value (get-char-attribute char 'kangxi-strokes)))
902 (unless (eq value strokes)
903 (insert (format "(kangxi-strokes\t . %S)%s"
907 (setq strokes value)))
908 (setq attributes (delq 'kangxi-strokes attributes))
910 (when (and (memq 'japanese-radical attributes)
911 (setq value (get-char-attribute char 'japanese-radical)))
912 (unless (eq value radical)
913 (insert (format "(japanese-radical\t . %S)\t; %c%s"
915 (ideographic-radical value)
918 (setq radical value)))
919 (setq attributes (delq 'japanese-radical attributes))
921 (when (and (memq 'japanese-strokes attributes)
922 (setq value (get-char-attribute char 'japanese-strokes)))
923 (unless (eq value strokes)
924 (insert (format "(japanese-strokes\t . %S)%s"
928 (setq strokes value)))
929 (setq attributes (delq 'japanese-strokes attributes))
931 (when (and (memq 'cns-radical attributes)
932 (setq value (get-char-attribute char 'cns-radical)))
933 (insert (format "(cns-radical\t . %S)\t; %c%s"
935 (ideographic-radical value)
937 (setq attributes (delq 'cns-radical attributes))
939 (when (and (memq 'cns-strokes attributes)
940 (setq value (get-char-attribute char 'cns-strokes)))
941 (unless (eq value strokes)
942 (insert (format "(cns-strokes\t . %S)%s"
946 (setq strokes value)))
947 (setq attributes (delq 'cns-strokes attributes))
949 (when (and (memq 'shinjigen-1-radical attributes)
950 (setq value (get-char-attribute char 'shinjigen-1-radical)))
951 (unless (eq value radical)
952 (insert (format "(shinjigen-1-radical . %S)\t; %c%s"
954 (ideographic-radical value)
957 (setq radical value)))
958 (setq attributes (delq 'shinjigen-1-radical attributes))
960 (when (and (memq 'ideographic- attributes)
961 (setq value (get-char-attribute char 'ideographic-)))
962 (insert "(ideographic- ")
963 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
966 (setq cell (car value))
968 (setq cell (decode-char '=ucs cell)))
969 (cond ((characterp cell)
973 (insert (format "%S" cell))
974 (char-db-insert-char-spec cell readable))
975 (setq separator lbs))
979 (if (consp (car cell))
980 (char-db-insert-char-spec cell readable)
981 (char-db-insert-char-reference cell readable))
982 (setq separator lbs))
986 (insert (prin1-to-string cell))
987 (setq separator " ")))
988 (setq value (cdr value)))
990 (insert line-breaking)
991 (setq attributes (delq 'ideographic- attributes)))
992 (when (and (memq 'total-strokes attributes)
993 (setq value (get-char-attribute char 'total-strokes)))
994 (insert (format "(total-strokes . %S)%s"
997 (setq attributes (delq 'total-strokes attributes))
999 (when (and (memq '->ideograph attributes)
1000 (setq value (get-char-attribute char '->ideograph)))
1001 (insert (format "(->ideograph\t%s)%s"
1002 (mapconcat (lambda (code)
1003 (cond ((symbolp code)
1006 (format "#x%04X" code))
1009 line-breaking code))))
1012 (setq attributes (delq '->ideograph attributes))
1014 ;; (when (and (memq '->decomposition attributes)
1015 ;; (setq value (get-char-attribute char '->decomposition)))
1016 ;; (insert (format "(->decomposition\t%s)%s"
1017 ;; (mapconcat (lambda (code)
1018 ;; (cond ((symbolp code)
1019 ;; (symbol-name code))
1020 ;; ((characterp code)
1022 ;; (format "%S" code)
1027 ;; (format "#x%04X" code))
1029 ;; (format "%s%S" line-breaking code))))
1032 ;; (setq attributes (delq '->decomposition attributes))
1034 (if (equal (get-char-attribute char '->titlecase)
1035 (get-char-attribute char '->uppercase))
1036 (setq attributes (delq '->titlecase attributes)))
1037 (when (and (memq '->mojikyo attributes)
1038 (setq value (get-char-attribute char '->mojikyo)))
1039 (insert (format "(->mojikyo\t\t. %06d)\t; %c%s"
1040 value (decode-char 'mojikyo value)
1042 (setq attributes (delq '->mojikyo attributes))
1044 (when (and (memq 'hanyu-dazidian-vol attributes)
1045 (setq value (get-char-attribute char 'hanyu-dazidian-vol)))
1046 (insert (format "(hanyu-dazidian-vol . %d)%s"
1047 value line-breaking))
1048 (setq attributes (delq 'hanyu-dazidian-vol attributes))
1050 (when (and (memq 'hanyu-dazidian-page attributes)
1051 (setq value (get-char-attribute char 'hanyu-dazidian-page)))
1052 (insert (format "(hanyu-dazidian-page . %d)%s"
1053 value line-breaking))
1054 (setq attributes (delq 'hanyu-dazidian-page attributes))
1056 (when (and (memq 'hanyu-dazidian-char attributes)
1057 (setq value (get-char-attribute char 'hanyu-dazidian-char)))
1058 (insert (format "(hanyu-dazidian-char . %d)%s"
1059 value line-breaking))
1060 (setq attributes (delq 'hanyu-dazidian-char attributes))
1063 (dolist (ignored '(composition
1064 ->denotational <-subsumptive ->ucs-unified
1065 ->ideographic-component-forms))
1066 (setq attributes (delq ignored attributes))))
1068 (setq name (car attributes))
1069 (if (setq value (get-char-attribute char name))
1070 (cond ((setq ret (find-charset name))
1071 (setq name (charset-name ret))
1072 (if (and (not (memq name dest-ccss))
1074 (setq value (get-char-attribute char name))
1075 (setq dest-ccss (cons name dest-ccss))))
1076 (char-db-insert-ccs-feature name value line-breaking))
1078 ((string-match "^=>ucs@" (symbol-name name))
1079 (insert (format "(%-18s . #x%04X)\t; %c%s"
1080 name value (decode-char '=ucs value)
1083 ((eq name 'jisx0208-1978/4X)
1084 (insert (format "(%-18s . #x%04X)%s"
1090 (not (eq name '->subsumptive))
1091 (not (eq name '->uppercase))
1092 (not (eq name '->lowercase))
1093 (not (eq name '->titlecase))
1094 (not (eq name '->canonical))
1095 (not (eq name '->Bopomofo))
1096 (not (eq name '->mistakable))
1097 (not (eq name '->ideographic-variants))
1098 (null (get-char-attribute
1099 char (intern (format "%s*sources" name))))
1100 (not (string-match "\\*sources$" (symbol-name name)))
1101 (null (get-char-attribute
1102 char (intern (format "%s*note" name))))
1103 (not (string-match "\\*note$" (symbol-name name)))
1104 (or (eq name '<-identical)
1105 (eq name '<-uppercase)
1106 (eq name '<-lowercase)
1107 (eq name '<-titlecase)
1108 (eq name '<-canonical)
1109 (eq name '<-ideographic-variants)
1110 ;; (eq name '<-synonyms)
1111 (string-match "^<-synonyms" (symbol-name name))
1112 (eq name '<-mistakable)
1113 (when (string-match "^->" (symbol-name name))
1115 ((string-match "^->fullwidth" (symbol-name name))
1116 (not (and (consp value)
1117 (characterp (car value))
1119 (car value) '=ucs 'defined-only)))
1124 ((or (eq name 'ideographic-structure)
1125 (eq name 'ideographic-combination)
1126 (eq name 'ideographic-)
1127 (eq name '=decomposition)
1128 (string-match "^=>decomposition" (symbol-name name))
1129 (string-match "^\\(->\\|<-\\)[^*]*$" (symbol-name name))
1130 (string-match "^\\(->\\|<-\\)[^*]*\\*sources$"
1133 (char-db-insert-relation-feature char name value
1136 ((memq name '(ideograph=
1137 original-ideograph-of
1138 ancient-ideograph-of
1141 ;; simplified-ideograph-of
1142 ideographic-variants
1143 ;; ideographic-different-form-of
1145 (insert (format "(%-18s%s " name line-breaking))
1146 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1148 (while (consp value)
1149 (setq cell (car value))
1150 (if (and (consp cell)
1155 (char-db-insert-alist cell readable)
1156 (setq separator lbs))
1159 (insert (prin1-to-string cell))
1160 (setq separator " "))
1161 (setq value (cdr value)))
1163 (insert line-breaking))
1165 (insert (format "(%-18s " name))
1166 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1168 (while (consp value)
1169 (setq cell (car value))
1170 (if (and (consp cell)
1172 (setq ret (condition-case nil
1180 (setq key (car (car rest)))
1181 (if (find-charset key)
1182 (setq cal (cons key cal))
1183 (setq al (cons key al)))
1184 (setq rest (cdr rest)))
1187 (insert-char-attributes ret
1190 (setq separator lbs))
1191 (setq ret (prin1-to-string cell))
1193 (if (< (+ (current-column)
1200 (setq separator " "))
1201 (setq value (cdr value)))
1203 (insert line-breaking))
1205 (insert (format "(%-18s" name))
1206 (setq ret (prin1-to-string value))
1207 (unless (< (+ (current-column)
1211 (insert line-breaking))
1212 (insert " . " ret ")" line-breaking)
1213 ;; (insert (format "(%-18s . %S)%s"
1218 (setq attributes (cdr attributes)))
1221 (defun insert-char-data (char &optional readable
1224 (narrow-to-region (point)(point))
1225 (insert "(define-char
1227 (insert-char-attributes char readable attributes)
1229 (goto-char (point-min))
1230 (while (re-search-forward "[ \t]+$" nil t)
1233 (goto-char (point-min))
1234 (while (re-search-forward "[ \t][ \t][ \t]*" nil t)
1235 (let ((column (current-column))
1236 (indent-tabs-mode t))
1237 (delete-region (match-beginning 0) (point))
1238 (indent-to column)))
1239 (goto-char (point-max))
1240 ;; (tabify (point-min)(point-max))
1243 (defun insert-char-data-with-variant (char &optional printable
1245 script excluded-script)
1246 (insert-char-data char printable)
1247 (let ((variants (char-variants char))
1250 (setq variants (sort variants #'<))
1251 (setq rest variants)
1252 (setq variants (cons char variants))
1254 (setq variant (car rest))
1255 (unless (get-char-attribute variant '<-subsumptive)
1256 (if (and (or (null script)
1257 (null (setq vs (get-char-attribute variant 'script)))
1259 (or (null excluded-script)
1260 (null (setq vs (get-char-attribute variant 'script)))
1261 (not (memq excluded-script vs))))
1262 (unless (and no-ucs-unified (get-char-attribute variant '=ucs))
1263 (insert-char-data variant printable)
1264 (if (setq ret (char-variants variant))
1266 (or (memq (car ret) variants)
1267 ;; (get-char-attribute (car ret) '<-subsumptive)
1268 (setq rest (nconc rest (list (car ret)))))
1269 (setq ret (cdr ret)))))))
1270 (setq rest (cdr rest)))))
1272 (defun insert-char-range-data (min max &optional script excluded-script)
1275 (while (<= code max)
1276 (setq char (decode-char '=ucs code))
1277 (if (encode-char char '=ucs 'defined-only)
1278 (insert-char-data-with-variant char nil 'no-ucs-unified
1279 script excluded-script))
1280 (setq code (1+ code)))))
1282 (defun write-char-range-data-to-file (min max file
1283 &optional script excluded-script)
1284 (let ((coding-system-for-write char-db-file-coding-system))
1286 (insert (format ";; -*- coding: %s -*-\n"
1287 char-db-file-coding-system))
1288 (insert-char-range-data min max script excluded-script)
1289 (write-region (point-min)(point-max) file))))
1291 (defvar what-character-original-window-configuration)
1294 (defun what-char-definition (char)
1295 (interactive (list (char-after)))
1296 (let ((buf (get-buffer-create "*Character Description*"))
1297 (the-buf (current-buffer))
1298 (win-conf (current-window-configuration)))
1300 (make-local-variable 'what-character-original-window-configuration)
1301 (setq what-character-original-window-configuration win-conf)
1302 (setq buffer-read-only nil)
1306 (insert-char-data-with-variant char 'printable)
1307 (unless (char-attribute-alist char)
1308 (insert (format ";; = %c\n"
1309 (let* ((rest (split-char char))
1313 (setq code (logior (lsh code 8)
1315 (decode-char ccs code)))))
1316 ;; (char-db-update-comment)
1317 (set-buffer-modified-p nil)
1318 (view-mode the-buf (lambda (buf)
1319 (set-window-configuration
1320 what-character-original-window-configuration)
1322 (goto-char (point-min)))
1324 (set-window-configuration
1325 what-character-original-window-configuration)
1326 (signal (car err) (cdr err)))))))
1328 (provide 'char-db-util)
1330 ;;; char-db-util.el ends here