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)
171 (< (charset-id ka)(charset-id kb))))
177 (string< (symbol-name ka)
183 (defvar char-db-coded-charset-priority-list
244 (defun char-db-make-char-spec (char)
246 (cond ((characterp char)
247 (cond ((and (setq ret (encode-char char '=ucs 'defined-only))
248 (not (and (<= #xE000 ret)(<= ret #xF8FF))))
249 (setq char-spec (list (cons '=ucs ret)))
250 (cond ((setq ret (get-char-attribute char 'name))
251 (setq char-spec (cons (cons 'name ret) char-spec))
253 ((setq ret (get-char-attribute char 'name*))
254 (setq char-spec (cons (cons 'name* ret) char-spec))
259 (let ((rest char-db-coded-charset-priority-list)
262 (setq ccs (charset-name
263 (find-charset (car rest))))
265 (encode-char char ccs
267 (throw 'tag (cons ccs ret)))
268 (setq rest (cdr rest))))))
269 (setq char-spec (list ret))
270 (dolist (ccs (delq (car ret) (charset-list)))
271 (if (and (or (charset-iso-final-char ccs)
278 (setq ccs (charset-name ccs))
279 (null (assq ccs char-spec))
280 (setq ret (encode-char char ccs 'defined-only)))
281 (setq char-spec (cons (cons ccs ret) char-spec))))
283 (setq char-spec (split-char char)))
284 (cond ((setq ret (get-char-attribute char 'name))
285 (setq char-spec (cons (cons 'name ret) char-spec))
287 ((setq ret (get-char-attribute char 'name*))
288 (setq char-spec (cons (cons 'name* ret) char-spec))
295 (defun char-db-insert-char-spec (char &optional readable column
298 (setq column (current-column)))
299 (let (char-spec temp-char)
300 (setq char-spec (char-db-make-char-spec char))
301 (unless (or (characterp char) ; char
303 (setq char (find-char char-spec))
305 ;; define temporary character
306 ;; Current implementation is dirty.
307 (setq temp-char (define-char (cons '(ideograph-daikanwa . 0)
309 (remove-char-attribute temp-char 'ideograph-daikanwa)
310 (setq char temp-char))
311 (insert-char-attributes char
313 (union (mapcar #'car char-spec)
316 ;; undefine temporary character
317 ;; Current implementation is dirty.
318 (setq char-spec (char-attribute-alist temp-char))
320 (remove-char-attribute temp-char (car (car char-spec)))
321 (setq char-spec (cdr char-spec))))))
323 (defun char-db-insert-alist (alist &optional readable column)
325 (setq column (current-column)))
327 (concat "\n" (make-string (1+ column) ?\ )))
331 lbs cell rest separator)
334 (setq name (car (car alist))
335 value (cdr (car alist)))
336 (cond ((eq name 'char)
338 (if (setq ret (condition-case nil
346 (setq key (car (car value)))
347 ;; (if (find-charset key)
348 ;; (setq cal (cons key cal))
349 (setq al (cons key al))
351 (setq value (cdr value)))
352 (insert-char-attributes ret
356 (insert (prin1-to-string value)))
358 (insert line-breaking))
360 (insert (format "(%-18s " name))
361 (setq lbs (concat "\n" (make-string (current-column) ?\ )))
363 (setq cell (car value))
364 (if (and (consp cell)
366 (setq ret (condition-case nil
376 (setq key (car (car rest)))
377 ;; (if (find-charset key)
378 ;; (setq cal (cons key cal))
379 (setq al (cons key al))
381 (setq rest (cdr rest)))
384 (insert-char-attributes ret
388 (setq separator lbs))
391 (insert (prin1-to-string cell))
392 (setq separator " "))
393 (setq value (cdr value)))
395 (insert line-breaking))
397 (insert (format "(%-18s . %S)%s"
400 (setq alist (cdr alist))))
403 (defun char-db-insert-char-reference (plist &optional readable column)
405 (setq column (current-column)))
407 (concat "\n" (make-string (1+ column) ?\ )))
412 (setq name (pop plist))
413 (setq value (pop plist))
414 (cond ((eq name :char)
417 (cond ((numberp value)
418 (setq value (decode-char '=ucs value)))
420 ;; (setq value (or (find-char value)
423 (char-db-insert-char-spec value readable)
424 (insert line-breaking)
427 (insert (format "%s%s\t%d ; %c%s"
430 (ideographic-radical value)
434 (insert (format "%s%s\t%S" separator name value))
435 (setq separator line-breaking)))
439 (defun char-db-decode-isolated-char (ccs code-point)
442 (cond ((eq ccs 'arabic-iso8859-6)
443 (decode-char ccs code-point))
444 ((and (memq ccs '(=gt-pj-1
455 (setq ret (decode-char ccs code-point))
456 (setq ret (encode-char ret '=gt 'defined-only)))
457 (decode-builtin-char '=gt ret))
459 (decode-builtin-char ccs code-point))))
460 (cond ((and (<= 0 (char-int ret))
461 (<= (char-int ret) #x1F))
462 (decode-char '=ucs (+ #x2400 (char-int ret))))
463 ((= (char-int ret) #x7F)
467 (defvar char-db-convert-obsolete-format t)
469 (defun char-db-insert-ccs-feature (name value line-breaking)
472 (cond ((or (memq name '(=daikanwa
473 =daikanwa@rev1 =daikanwa@rev2
474 =gt =gt-k =cbeta =zinbun-oracle))
475 (string-match "^=adobe-" (symbol-name name)))
476 "(%-18s . %05d)\t; %c")
478 "(%-18s . %06d)\t; %c")
479 ((>= (charset-dimension name) 2)
480 "(%-18s . #x%04X)\t; %c")
482 "(%-18s . #x%02X)\t; %c"))
484 (if (= (charset-iso-graphic-plane name) 1)
486 (cond ((= (charset-dimension name) 1)
488 ((= (charset-dimension name) 2)
490 ((= (charset-dimension name) 3)
494 (char-db-decode-isolated-char name value)))
495 (if (and (= (charset-chars name) 94)
496 (= (charset-dimension name) 2))
497 (insert (format " [%02d-%02d]"
498 (- (lsh value -8) 32)
499 (- (logand value 255) 32))))
500 (insert line-breaking))
502 (defun char-db-insert-relation-feature (char name value line-breaking
504 (insert (format "(%-18s%s " name line-breaking))
505 (let ((lbs (concat "\n" (make-string (current-column) ?\ )))
506 separator cell sources required-features
509 (setq cell (car value))
511 (setq cell (decode-char '=ucs cell)))
513 ((eq name '->subsumptive)
514 (when (or (not (some (lambda (atr)
515 (get-char-attribute cell atr))
516 char-db-ignored-attributes))
518 (encode-char cell ccs 'defined-only))
522 (let ((char-db-ignored-attributes
524 char-db-ignored-attributes)))
525 (insert-char-attributes cell readable))
526 (setq separator lbs))
531 char (intern (format "%s*sources" name))))
532 (setq required-features nil)
533 (dolist (source sources)
535 ((memq source '(JP JP/Jouyou shinjigen-1))
536 (setq required-features
537 (union required-features
546 (setq required-features
547 (union required-features
552 ((find-charset (setq ret (intern (format "=%s" source))))
553 (setq required-features
554 (cons ret required-features)))
555 (t (setq required-features
556 (cons source required-features)))))
557 (cond ((string-match "@JP" (symbol-name name))
558 (setq required-features
559 (union required-features
567 ((string-match "@CN" (symbol-name name))
568 (setq required-features
569 (union required-features
576 (insert (format "%S" cell))
577 (char-db-insert-char-spec cell readable
580 (setq separator lbs))
584 (if (consp (car cell))
585 (char-db-insert-char-spec cell readable)
586 (char-db-insert-char-reference cell readable))
587 (setq separator lbs))
591 (insert (prin1-to-string cell))
592 (setq separator " ")))
593 (setq value (cdr value)))
595 (insert line-breaking)))
597 (defun insert-char-attributes (char &optional readable attributes column)
599 (setq column (current-column)))
600 (let (name value ; has-long-ccs-name
604 (concat "\n" (make-string (1+ column) ?\ )))
605 lbs cell separator ret
607 dest-ccss ; sources required-features
612 (if (consp attributes)
614 (dolist (name attributes)
615 (unless (memq name char-db-ignored-attributes)
616 (if (find-charset name)
620 (dolist (name (char-attribute-list))
621 (unless (memq name char-db-ignored-attributes)
622 (if (find-charset name)
626 #'char-attribute-name<)))
628 (when (memq '<-subsumptive attributes)
630 (when (setq value (get-char-attribute char '<-subsumptive))
631 (char-db-insert-relation-feature char '<-subsumptive value
634 (setq attributes (delq '<-subsumptive attributes)))
635 (when (and (memq '<-denotational attributes)
636 (setq value (get-char-attribute char '<-denotational)))
637 (char-db-insert-relation-feature char '<-denotational value
640 (setq attributes (delq '<-denotational attributes)))
641 (when (and (memq 'name attributes)
642 (setq value (get-char-attribute char 'name)))
644 (if (> (+ (current-column) (length value)) 48)
647 value line-breaking))
648 (setq attributes (delq 'name attributes))
650 (when (and (memq 'name* attributes)
651 (setq value (get-char-attribute char 'name*)))
653 (if (> (+ (current-column) (length value)) 48)
656 value line-breaking))
657 (setq attributes (delq 'name* attributes))
659 (when (and (memq 'script attributes)
660 (setq value (get-char-attribute char 'script)))
661 (insert (format "(script\t\t%s)%s"
662 (mapconcat (function prin1-to-string)
665 (setq attributes (delq 'script attributes))
667 (dolist (name '(=>ucs =>ucs*))
668 (when (and (memq name attributes)
669 (setq value (get-char-attribute char name)))
670 (insert (format "(%-18s . #x%04X)\t; %c%s"
671 name value (decode-char '=ucs value)
673 (setq attributes (delq name attributes))))
674 (dolist (name '(=>ucs@gb =>ucs@cns =>ucs@jis =>ucs@ks =>ucs@big5))
675 (when (and (memq name attributes)
676 (setq value (get-char-attribute char name)))
677 (insert (format "(%-18s . #x%04X)\t; %c%s"
682 (symbol-name name) 2)))
685 (setq attributes (delq name attributes))
687 (dolist (name '(=>daikanwa))
688 (when (and (memq name attributes)
689 (setq value (get-char-attribute char name)))
692 (format "(%-18s . %05d)\t; %c%s"
693 name value (decode-char '=daikanwa value)
695 (format "(%-18s %s)\t; %c%s"
697 (mapconcat (function prin1-to-string)
699 (char-representative-of-daikanwa char)
701 (setq attributes (delq name attributes))))
702 (when (and (memq 'general-category attributes)
703 (setq value (get-char-attribute char 'general-category)))
705 "(general-category\t%s) ; %s%s"
706 (mapconcat (lambda (cell)
709 (cond ((rassoc value unidata-normative-category-alist)
710 "Normative Category")
711 ((rassoc value unidata-informative-category-alist)
712 "Informative Category")
716 (setq attributes (delq 'general-category attributes))
718 (when (and (memq 'bidi-category attributes)
719 (setq value (get-char-attribute char 'bidi-category)))
720 (insert (format "(bidi-category\t. %S)%s"
723 (setq attributes (delq 'bidi-category attributes))
725 (unless (or (not (memq 'mirrored attributes))
726 (eq (setq value (get-char-attribute char 'mirrored 'empty))
728 (insert (format "(mirrored\t\t. %S)%s"
731 (setq attributes (delq 'mirrored attributes))
734 ((and (memq 'decimal-digit-value attributes)
735 (setq value (get-char-attribute char 'decimal-digit-value)))
736 (insert (format "(decimal-digit-value . %S)%s"
739 (setq attributes (delq 'decimal-digit-value attributes))
740 (when (and (memq 'digit-value attributes)
741 (setq value (get-char-attribute char 'digit-value)))
742 (insert (format "(digit-value\t . %S)%s"
745 (setq attributes (delq 'digit-value attributes))
747 (when (and (memq 'numeric-value attributes)
748 (setq value (get-char-attribute char 'numeric-value)))
749 (insert (format "(numeric-value\t . %S)%s"
752 (setq attributes (delq 'numeric-value attributes))
756 (when (and (memq 'digit-value attributes)
757 (setq value (get-char-attribute char 'digit-value)))
758 (insert (format "(digit-value\t. %S)%s"
761 (setq attributes (delq 'digit-value attributes))
763 (when (and (memq 'numeric-value attributes)
764 (setq value (get-char-attribute char 'numeric-value)))
765 (insert (format "(numeric-value\t. %S)%s"
768 (setq attributes (delq 'numeric-value attributes))
770 (when (and (memq 'iso-10646-comment attributes)
771 (setq value (get-char-attribute char 'iso-10646-comment)))
772 (insert (format "(iso-10646-comment\t. %S)%s"
775 (setq attributes (delq 'iso-10646-comment attributes))
777 (when (and (memq 'morohashi-daikanwa attributes)
778 (setq value (get-char-attribute char 'morohashi-daikanwa)))
779 (insert (format "(morohashi-daikanwa\t%s)%s"
780 (mapconcat (function prin1-to-string) value " ")
782 (setq attributes (delq 'morohashi-daikanwa attributes))
786 (when (and (memq 'ideographic-radical attributes)
787 (setq value (get-char-attribute char 'ideographic-radical)))
789 (insert (format "(ideographic-radical . %S)\t; %c%s"
791 (ideographic-radical radical)
793 (setq attributes (delq 'ideographic-radical attributes))
795 (when (and (memq 'shuowen-radical attributes)
796 (setq value (get-char-attribute char 'shuowen-radical)))
797 (insert (format "(shuowen-radical\t. %S)\t; %c%s"
799 (shuowen-radical value)
801 (setq attributes (delq 'shuowen-radical attributes))
806 char-db-feature-domains
808 (dolist (feature (char-attribute-list))
809 (setq feature (symbol-name feature))
811 "\\(radical\\|strokes\\)@\\([^@*]+\\)\\(\\*\\|$\\)"
813 (setq domain (intern (match-string 2 feature)))
814 (unless (memq domain dest)
815 (setq dest (cons domain dest)))))
816 (sort dest #'string<))))
817 (setq key (intern (format "%s@%s" 'ideographic-radical domain)))
818 (when (and (memq key attributes)
819 (setq value (get-char-attribute char key)))
821 (insert (format "(%s . %S)\t; %c%s"
824 (ideographic-radical radical)
826 (setq attributes (delq key attributes))
828 (setq key (intern (format "%s@%s" 'ideographic-strokes domain)))
829 (when (and (memq key attributes)
830 (setq value (get-char-attribute char key)))
832 (insert (format "(%s . %S)%s"
836 (setq attributes (delq key attributes))
838 (setq key (intern (format "%s@%s" 'total-strokes domain)))
839 (when (and (memq key attributes)
840 (setq value (get-char-attribute char key)))
841 (insert (format "(%s . %S)%s"
845 (setq attributes (delq key attributes))
847 (dolist (feature '(ideographic-radical
850 (setq key (intern (format "%s@%s*sources" feature domain)))
851 (when (and (memq key attributes)
852 (setq value (get-char-attribute char key)))
853 (insert (format "(%s%s" key line-breaking))
855 (insert (format " %s" cell)))
857 (insert line-breaking)
858 (setq attributes (delq key attributes))
861 (when (and (memq 'ideographic-strokes attributes)
862 (setq value (get-char-attribute char 'ideographic-strokes)))
864 (insert (format "(ideographic-strokes . %S)%s"
867 (setq attributes (delq 'ideographic-strokes attributes))
869 (when (and (memq 'kangxi-radical attributes)
870 (setq value (get-char-attribute char 'kangxi-radical)))
871 (unless (eq value radical)
872 (insert (format "(kangxi-radical\t . %S)\t; %c%s"
874 (ideographic-radical value)
877 (setq radical value)))
878 (setq attributes (delq 'kangxi-radical attributes))
880 (when (and (memq 'kangxi-strokes attributes)
881 (setq value (get-char-attribute char 'kangxi-strokes)))
882 (unless (eq value strokes)
883 (insert (format "(kangxi-strokes\t . %S)%s"
887 (setq strokes value)))
888 (setq attributes (delq 'kangxi-strokes attributes))
890 (when (and (memq 'japanese-radical attributes)
891 (setq value (get-char-attribute char 'japanese-radical)))
892 (unless (eq value radical)
893 (insert (format "(japanese-radical\t . %S)\t; %c%s"
895 (ideographic-radical value)
898 (setq radical value)))
899 (setq attributes (delq 'japanese-radical attributes))
901 (when (and (memq 'japanese-strokes attributes)
902 (setq value (get-char-attribute char 'japanese-strokes)))
903 (unless (eq value strokes)
904 (insert (format "(japanese-strokes\t . %S)%s"
908 (setq strokes value)))
909 (setq attributes (delq 'japanese-strokes attributes))
911 (when (and (memq 'cns-radical attributes)
912 (setq value (get-char-attribute char 'cns-radical)))
913 (insert (format "(cns-radical\t . %S)\t; %c%s"
915 (ideographic-radical value)
917 (setq attributes (delq 'cns-radical attributes))
919 (when (and (memq 'cns-strokes attributes)
920 (setq value (get-char-attribute char 'cns-strokes)))
921 (unless (eq value strokes)
922 (insert (format "(cns-strokes\t . %S)%s"
926 (setq strokes value)))
927 (setq attributes (delq 'cns-strokes attributes))
929 (when (and (memq 'shinjigen-1-radical attributes)
930 (setq value (get-char-attribute char 'shinjigen-1-radical)))
931 (unless (eq value radical)
932 (insert (format "(shinjigen-1-radical . %S)\t; %c%s"
934 (ideographic-radical value)
937 (setq radical value)))
938 (setq attributes (delq 'shinjigen-1-radical attributes))
940 (when (and (memq 'ideographic- attributes)
941 (setq value (get-char-attribute char 'ideographic-)))
942 (insert "(ideographic- ")
943 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
946 (setq cell (car value))
948 (setq cell (decode-char '=ucs cell)))
949 (cond ((characterp cell)
953 (insert (format "%S" cell))
954 (char-db-insert-char-spec cell readable))
955 (setq separator lbs))
959 (if (consp (car cell))
960 (char-db-insert-char-spec cell readable)
961 (char-db-insert-char-reference cell readable))
962 (setq separator lbs))
966 (insert (prin1-to-string cell))
967 (setq separator " ")))
968 (setq value (cdr value)))
970 (insert line-breaking)
971 (setq attributes (delq 'ideographic- attributes)))
972 (when (and (memq 'total-strokes attributes)
973 (setq value (get-char-attribute char 'total-strokes)))
974 (insert (format "(total-strokes . %S)%s"
977 (setq attributes (delq 'total-strokes attributes))
979 (when (and (memq '->ideograph attributes)
980 (setq value (get-char-attribute char '->ideograph)))
981 (insert (format "(->ideograph\t%s)%s"
982 (mapconcat (lambda (code)
983 (cond ((symbolp code)
986 (format "#x%04X" code))
989 line-breaking code))))
992 (setq attributes (delq '->ideograph attributes))
994 ;; (when (and (memq '->decomposition attributes)
995 ;; (setq value (get-char-attribute char '->decomposition)))
996 ;; (insert (format "(->decomposition\t%s)%s"
997 ;; (mapconcat (lambda (code)
998 ;; (cond ((symbolp code)
999 ;; (symbol-name code))
1000 ;; ((characterp code)
1002 ;; (format "%S" code)
1007 ;; (format "#x%04X" code))
1009 ;; (format "%s%S" line-breaking code))))
1012 ;; (setq attributes (delq '->decomposition attributes))
1014 (if (equal (get-char-attribute char '->titlecase)
1015 (get-char-attribute char '->uppercase))
1016 (setq attributes (delq '->titlecase attributes)))
1017 (when (and (memq '->mojikyo attributes)
1018 (setq value (get-char-attribute char '->mojikyo)))
1019 (insert (format "(->mojikyo\t\t. %06d)\t; %c%s"
1020 value (decode-char 'mojikyo value)
1022 (setq attributes (delq '->mojikyo attributes))
1024 (when (and (memq 'hanyu-dazidian-vol attributes)
1025 (setq value (get-char-attribute char 'hanyu-dazidian-vol)))
1026 (insert (format "(hanyu-dazidian-vol . %d)%s"
1027 value line-breaking))
1028 (setq attributes (delq 'hanyu-dazidian-vol attributes))
1030 (when (and (memq 'hanyu-dazidian-page attributes)
1031 (setq value (get-char-attribute char 'hanyu-dazidian-page)))
1032 (insert (format "(hanyu-dazidian-page . %d)%s"
1033 value line-breaking))
1034 (setq attributes (delq 'hanyu-dazidian-page attributes))
1036 (when (and (memq 'hanyu-dazidian-char attributes)
1037 (setq value (get-char-attribute char 'hanyu-dazidian-char)))
1038 (insert (format "(hanyu-dazidian-char . %d)%s"
1039 value line-breaking))
1040 (setq attributes (delq 'hanyu-dazidian-char attributes))
1043 (dolist (ignored '(composition
1044 ->denotational <-subsumptive ->ucs-unified
1045 ->ideographic-component-forms))
1046 (setq attributes (delq ignored attributes))))
1048 (setq name (car attributes))
1049 (if (setq value (get-char-attribute char name))
1050 (cond ((setq ret (find-charset name))
1051 (setq name (charset-name ret))
1052 (if (and (not (memq name dest-ccss))
1054 (setq value (get-char-attribute char name))
1055 (setq dest-ccss (cons name dest-ccss))))
1056 (char-db-insert-ccs-feature name value line-breaking))
1058 ((string-match "^=>ucs@" (symbol-name name))
1059 (insert (format "(%-18s . #x%04X)\t; %c%s"
1060 name value (decode-char '=ucs value)
1063 ((eq name 'jisx0208-1978/4X)
1064 (insert (format "(%-18s . #x%04X)%s"
1070 (not (eq name '->subsumptive))
1071 (not (eq name '->uppercase))
1072 (not (eq name '->lowercase))
1073 (not (eq name '->titlecase))
1074 (not (eq name '->canonical))
1075 (not (eq name '->Bopomofo))
1076 (not (eq name '->mistakable))
1077 (not (eq name '->ideographic-variants))
1078 (null (get-char-attribute
1079 char (intern (format "%s*sources" name))))
1080 (not (string-match "\\*sources$" (symbol-name name)))
1081 (null (get-char-attribute
1082 char (intern (format "%s*note" name))))
1083 (not (string-match "\\*note$" (symbol-name name)))
1084 (or (eq name '<-identical)
1085 (eq name '<-uppercase)
1086 (eq name '<-lowercase)
1087 (eq name '<-titlecase)
1088 (eq name '<-canonical)
1089 (eq name '<-ideographic-variants)
1090 ;; (eq name '<-synonyms)
1091 (string-match "^<-synonyms" (symbol-name name))
1092 (eq name '<-mistakable)
1093 (when (string-match "^->" (symbol-name name))
1095 ((string-match "^->fullwidth" (symbol-name name))
1096 (not (and (consp value)
1097 (characterp (car value))
1099 (car value) '=ucs 'defined-only)))
1104 ((or (eq name 'ideographic-structure)
1105 (eq name 'ideographic-combination)
1106 (eq name 'ideographic-)
1107 (eq name '=decomposition)
1108 (string-match "^=>decomposition" (symbol-name name))
1109 (string-match "^\\(->\\|<-\\)[^*]*$" (symbol-name name))
1110 (string-match "^\\(->\\|<-\\)[^*]*\\*sources$"
1113 (char-db-insert-relation-feature char name value
1116 ((memq name '(ideograph=
1117 original-ideograph-of
1118 ancient-ideograph-of
1121 ;; simplified-ideograph-of
1122 ideographic-variants
1123 ;; ideographic-different-form-of
1125 (insert (format "(%-18s%s " name line-breaking))
1126 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1128 (while (consp value)
1129 (setq cell (car value))
1130 (if (and (consp cell)
1135 (char-db-insert-alist cell readable)
1136 (setq separator lbs))
1139 (insert (prin1-to-string cell))
1140 (setq separator " "))
1141 (setq value (cdr value)))
1143 (insert line-breaking))
1145 (insert (format "(%-18s " name))
1146 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1148 (while (consp value)
1149 (setq cell (car value))
1150 (if (and (consp cell)
1152 (setq ret (condition-case nil
1160 (setq key (car (car rest)))
1161 (if (find-charset key)
1162 (setq cal (cons key cal))
1163 (setq al (cons key al)))
1164 (setq rest (cdr rest)))
1167 (insert-char-attributes ret
1170 (setq separator lbs))
1171 (setq ret (prin1-to-string cell))
1173 (if (< (+ (current-column)
1180 (setq separator " "))
1181 (setq value (cdr value)))
1183 (insert line-breaking))
1185 (insert (format "(%-18s" name))
1186 (setq ret (prin1-to-string value))
1187 (unless (< (+ (current-column)
1191 (insert line-breaking))
1192 (insert " . " ret ")" line-breaking)
1193 ;; (insert (format "(%-18s . %S)%s"
1198 (setq attributes (cdr attributes)))
1201 (defun insert-char-data (char &optional readable
1204 (narrow-to-region (point)(point))
1205 (insert "(define-char
1207 (insert-char-attributes char readable attributes)
1209 (goto-char (point-min))
1210 (while (re-search-forward "[ \t]+$" nil t)
1213 (goto-char (point-min))
1214 (while (re-search-forward "[ \t][ \t][ \t]*" nil t)
1215 (let ((column (current-column))
1216 (indent-tabs-mode t))
1217 (delete-region (match-beginning 0) (point))
1218 (indent-to column)))
1219 (goto-char (point-max))
1220 ;; (tabify (point-min)(point-max))
1223 (defun insert-char-data-with-variant (char &optional printable
1225 script excluded-script)
1226 (insert-char-data char printable)
1227 (let ((variants (char-variants char))
1230 (setq variants (sort variants #'<))
1231 (setq rest variants)
1232 (setq variants (cons char variants))
1234 (setq variant (car rest))
1235 (unless (get-char-attribute variant '<-subsumptive)
1236 (if (and (or (null script)
1237 (null (setq vs (get-char-attribute variant 'script)))
1239 (or (null excluded-script)
1240 (null (setq vs (get-char-attribute variant 'script)))
1241 (not (memq excluded-script vs))))
1242 (unless (and no-ucs-unified (get-char-attribute variant '=ucs))
1243 (insert-char-data variant printable)
1244 (if (setq ret (char-variants variant))
1246 (or (memq (car ret) variants)
1247 ;; (get-char-attribute (car ret) '<-subsumptive)
1248 (setq rest (nconc rest (list (car ret)))))
1249 (setq ret (cdr ret)))))))
1250 (setq rest (cdr rest)))))
1252 (defun insert-char-range-data (min max &optional script excluded-script)
1255 (while (<= code max)
1256 (setq char (decode-char '=ucs code))
1257 (if (encode-char char '=ucs 'defined-only)
1258 (insert-char-data-with-variant char nil 'no-ucs-unified
1259 script excluded-script))
1260 (setq code (1+ code)))))
1262 (defun write-char-range-data-to-file (min max file
1263 &optional script excluded-script)
1264 (let ((coding-system-for-write char-db-file-coding-system))
1266 (insert (format ";; -*- coding: %s -*-\n"
1267 char-db-file-coding-system))
1268 (insert-char-range-data min max script excluded-script)
1269 (write-region (point-min)(point-max) file))))
1271 (defvar what-character-original-window-configuration)
1274 (defun what-char-definition (char)
1275 (interactive (list (char-after)))
1276 (let ((buf (get-buffer-create "*Character Description*"))
1277 (the-buf (current-buffer))
1278 (win-conf (current-window-configuration)))
1280 (make-local-variable 'what-character-original-window-configuration)
1281 (setq what-character-original-window-configuration win-conf)
1282 (setq buffer-read-only nil)
1286 (insert-char-data-with-variant char 'printable)
1287 (unless (char-attribute-alist char)
1288 (insert (format ";; = %c\n"
1289 (let* ((rest (split-char char))
1293 (setq code (logior (lsh code 8)
1295 (decode-char ccs code)))))
1296 ;; (char-db-update-comment)
1297 (set-buffer-modified-p nil)
1298 (view-mode the-buf (lambda (buf)
1299 (set-window-configuration
1300 what-character-original-window-configuration)
1302 (goto-char (point-min)))
1304 (set-window-configuration
1305 what-character-original-window-configuration)
1306 (signal (car err) (cdr err)))))))
1308 (provide 'char-db-util)
1310 ;;; char-db-util.el ends here