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 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
103 (defun shuowen-radical (number)
104 (aref shuowen-radicals (1- number)))
106 (defvar char-db-file-coding-system 'utf-8-mcs-er)
108 (defvar char-db-feature-domains
109 '(ucs ucs/compat daikanwa cns gt jis jis/alt jis/a jis/b
110 jis-x0212 jis-x0213 cdp shinjigen misc unknown))
112 (defvar char-db-ignored-attributes '(ideographic-products))
114 (defun char-attribute-name< (ka kb)
116 ((eq '->denotational kb)
118 ((eq '->subsumptive kb)
119 (not (eq '->denotational ka)))
120 ((eq '->denotational ka)
122 ((eq '->subsumptive ka)
125 (string-match "^->" (symbol-name ka)))
126 (cond ((and (symbolp kb)
127 (string-match "^->" (symbol-name kb)))
128 (string< (symbol-name ka)
133 (string-match "^->" (symbol-name kb)))
136 (string-match "^<-" (symbol-name ka)))
138 (cond ((string-match "^<-" (symbol-name kb))
139 (string< (symbol-name ka)
142 ;; ((string-match "^->" (symbol-name kb))
147 (string-match "^<-" (symbol-name kb)))
149 ;; (not (string-match "^->" (symbol-name ka)))
152 (if (find-charset kb)
153 (if (<= (charset-id ka) 1)
154 (if (<= (charset-id kb) 1)
156 ((= (charset-dimension ka)
157 (charset-dimension kb))
158 (> (charset-id ka)(charset-id kb)))
160 (> (charset-dimension ka)
161 (charset-dimension kb))
164 (if (<= (charset-id kb) 1)
166 (< (charset-id ka)(charset-id kb))))
172 (string< (symbol-name ka)
178 (defvar char-db-coded-charset-priority-list
239 (defun char-db-make-char-spec (char)
241 (cond ((characterp char)
242 (cond ((and (setq ret (encode-char char '=ucs 'defined-only))
243 (not (and (<= #xE000 ret)(<= ret #xF8FF))))
244 (setq char-spec (list (cons '=ucs ret)))
245 (cond ((setq ret (get-char-attribute char 'name))
246 (setq char-spec (cons (cons 'name ret) char-spec))
248 ((setq ret (get-char-attribute char 'name*))
249 (setq char-spec (cons (cons 'name* ret) char-spec))
254 (let ((rest char-db-coded-charset-priority-list)
257 (setq ccs (charset-name
258 (find-charset (car rest))))
260 (encode-char char ccs
262 (throw 'tag (cons ccs ret)))
263 (setq rest (cdr rest))))))
264 (setq char-spec (list ret))
265 (dolist (ccs (delq (car ret) (charset-list)))
266 (if (and (or (charset-iso-final-char ccs)
273 (setq ccs (charset-name ccs))
274 (null (assq ccs char-spec))
275 (setq ret (encode-char char ccs 'defined-only)))
276 (setq char-spec (cons (cons ccs ret) char-spec))))
278 (setq char-spec (split-char char)))
279 (cond ((setq ret (get-char-attribute char 'name))
280 (setq char-spec (cons (cons 'name ret) char-spec))
282 ((setq ret (get-char-attribute char 'name*))
283 (setq char-spec (cons (cons 'name* ret) char-spec))
290 (defun char-db-insert-char-spec (char &optional readable column
293 (setq column (current-column)))
294 (let (char-spec temp-char)
295 (setq char-spec (char-db-make-char-spec char))
296 (unless (or (characterp char) ; char
298 (setq char (find-char char-spec))
300 ;; define temporary character
301 ;; Current implementation is dirty.
302 (setq temp-char (define-char (cons '(ideograph-daikanwa . 0)
304 (remove-char-attribute temp-char 'ideograph-daikanwa)
305 (setq char temp-char))
306 (insert-char-attributes char
308 (union (mapcar #'car char-spec)
311 ;; undefine temporary character
312 ;; Current implementation is dirty.
313 (setq char-spec (char-attribute-alist temp-char))
315 (remove-char-attribute temp-char (car (car char-spec)))
316 (setq char-spec (cdr char-spec))))))
318 (defun char-db-insert-alist (alist &optional readable column)
320 (setq column (current-column)))
322 (concat "\n" (make-string (1+ column) ?\ )))
326 lbs cell rest separator)
329 (setq name (car (car alist))
330 value (cdr (car alist)))
331 (cond ((eq name 'char)
333 (if (setq ret (condition-case nil
341 (setq key (car (car value)))
342 ;; (if (find-charset key)
343 ;; (setq cal (cons key cal))
344 (setq al (cons key al))
346 (setq value (cdr value)))
347 (insert-char-attributes ret
351 (insert (prin1-to-string value)))
353 (insert line-breaking))
355 (insert (format "(%-18s " name))
356 (setq lbs (concat "\n" (make-string (current-column) ?\ )))
358 (setq cell (car value))
359 (if (and (consp cell)
361 (setq ret (condition-case nil
371 (setq key (car (car rest)))
372 ;; (if (find-charset key)
373 ;; (setq cal (cons key cal))
374 (setq al (cons key al))
376 (setq rest (cdr rest)))
379 (insert-char-attributes ret
383 (setq separator lbs))
386 (insert (prin1-to-string cell))
387 (setq separator " "))
388 (setq value (cdr value)))
390 (insert line-breaking))
392 (insert (format "(%-18s . %S)%s"
395 (setq alist (cdr alist))))
398 (defun char-db-insert-char-reference (plist &optional readable column)
400 (setq column (current-column)))
402 (concat "\n" (make-string (1+ column) ?\ )))
407 (setq name (pop plist))
408 (setq value (pop plist))
409 (cond ((eq name :char)
412 (cond ((numberp value)
413 (setq value (decode-char '=ucs value)))
415 ;; (setq value (or (find-char value)
418 (char-db-insert-char-spec value readable)
419 (insert line-breaking)
422 (insert (format "%s%s\t%d ; %c%s"
425 (ideographic-radical value)
429 (insert (format "%s%s\t%S" separator name value))
430 (setq separator line-breaking)))
434 (defun char-db-decode-isolated-char (ccs code-point)
437 (cond ((eq ccs 'arabic-iso8859-6)
438 (decode-char ccs code-point))
439 ((and (memq ccs '(=gt-pj-1
450 (setq ret (decode-char ccs code-point))
451 (setq ret (encode-char ret '=gt 'defined-only)))
452 (decode-builtin-char '=gt ret))
454 (decode-builtin-char ccs code-point))))
455 (cond ((and (<= 0 (char-int ret))
456 (<= (char-int ret) #x1F))
457 (decode-char '=ucs (+ #x2400 (char-int ret))))
458 ((= (char-int ret) #x7F)
462 (defvar char-db-convert-obsolete-format t)
464 (defun char-db-insert-ccs-feature (name value line-breaking)
467 (cond ((or (memq name '(=daikanwa
468 =daikanwa@rev1 =daikanwa@rev2
469 =gt =gt-k =cbeta =zinbun-oracle))
470 (string-match "^=adobe-" (symbol-name name)))
471 "(%-18s . %05d)\t; %c")
473 "(%-18s . %06d)\t; %c")
474 ((>= (charset-dimension name) 2)
475 "(%-18s . #x%04X)\t; %c")
477 "(%-18s . #x%02X)\t; %c"))
479 (if (= (charset-iso-graphic-plane name) 1)
481 (cond ((= (charset-dimension name) 1)
483 ((= (charset-dimension name) 2)
485 ((= (charset-dimension name) 3)
489 (char-db-decode-isolated-char name value)))
490 (if (and (= (charset-chars name) 94)
491 (= (charset-dimension name) 2))
492 (insert (format " [%02d-%02d]"
493 (- (lsh value -8) 32)
494 (- (logand value 255) 32))))
495 (insert line-breaking))
497 (defun char-db-insert-relation-feature (char name value line-breaking
499 (insert (format "(%-18s%s " name line-breaking))
500 (let ((lbs (concat "\n" (make-string (current-column) ?\ )))
501 separator cell sources required-features
504 (setq cell (car value))
506 (setq cell (decode-char '=ucs cell)))
508 ((eq name '->subsumptive)
509 (when (or (not (some (lambda (atr)
510 (get-char-attribute cell atr))
511 char-db-ignored-attributes))
513 (encode-char cell ccs 'defined-only))
517 (let ((char-db-ignored-attributes
519 char-db-ignored-attributes)))
520 (insert-char-attributes cell readable))
521 (setq separator lbs))
526 char (intern (format "%s*sources" name))))
527 (setq required-features nil)
528 (dolist (source sources)
530 ((memq source '(JP JP/Jouyou shinjigen-1))
531 (setq required-features
532 (union required-features
541 (setq required-features
542 (union required-features
547 ((find-charset (setq ret (intern (format "=%s" source))))
548 (setq required-features
549 (cons ret required-features)))
550 (t (setq required-features
551 (cons source required-features)))))
552 (cond ((string-match "@JP" (symbol-name name))
553 (setq required-features
554 (union required-features
562 ((string-match "@CN" (symbol-name name))
563 (setq required-features
564 (union required-features
571 (insert (format "%S" cell))
572 (char-db-insert-char-spec cell readable
575 (setq separator lbs))
579 (if (consp (car cell))
580 (char-db-insert-char-spec cell readable)
581 (char-db-insert-char-reference cell readable))
582 (setq separator lbs))
586 (insert (prin1-to-string cell))
587 (setq separator " ")))
588 (setq value (cdr value)))
590 (insert line-breaking)))
592 (defun insert-char-attributes (char &optional readable attributes column)
594 (setq column (current-column)))
595 (let (name value ; has-long-ccs-name
599 (concat "\n" (make-string (1+ column) ?\ )))
600 lbs cell separator ret
602 dest-ccss ; sources required-features
607 (if (consp attributes)
609 (dolist (name attributes)
610 (unless (memq name char-db-ignored-attributes)
611 (if (find-charset name)
615 (dolist (name (char-attribute-list))
616 (unless (memq name char-db-ignored-attributes)
617 (if (find-charset name)
621 #'char-attribute-name<)))
623 (when (memq '<-subsumptive attributes)
625 (when (setq value (get-char-attribute char '<-subsumptive))
626 (char-db-insert-relation-feature char '<-subsumptive value
629 (setq attributes (delq '<-subsumptive attributes)))
630 (when (and (memq '<-denotational attributes)
631 (setq value (get-char-attribute char '<-denotational)))
632 (char-db-insert-relation-feature char '<-denotational value
635 (setq attributes (delq '<-denotational attributes)))
636 (when (and (memq 'name attributes)
637 (setq value (get-char-attribute char 'name)))
639 (if (> (+ (current-column) (length value)) 48)
642 value line-breaking))
643 (setq attributes (delq 'name attributes))
645 (when (and (memq 'name* attributes)
646 (setq value (get-char-attribute char 'name*)))
648 (if (> (+ (current-column) (length value)) 48)
651 value line-breaking))
652 (setq attributes (delq 'name* attributes))
654 (when (and (memq 'script attributes)
655 (setq value (get-char-attribute char 'script)))
656 (insert (format "(script\t\t%s)%s"
657 (mapconcat (function prin1-to-string)
660 (setq attributes (delq 'script attributes))
662 (dolist (name '(=>ucs =>ucs*))
663 (when (and (memq name attributes)
664 (setq value (get-char-attribute char name)))
665 (insert (format "(%-18s . #x%04X)\t; %c%s"
666 name value (decode-char '=ucs value)
668 (setq attributes (delq name attributes))))
669 (dolist (name '(=>ucs@gb =>ucs@cns =>ucs@jis =>ucs@ks =>ucs@big5))
670 (when (and (memq name attributes)
671 (setq value (get-char-attribute char name)))
672 (insert (format "(%-18s . #x%04X)\t; %c%s"
677 (symbol-name name) 2)))
680 (setq attributes (delq name attributes))
682 (dolist (name '(=>daikanwa))
683 (when (and (memq name attributes)
684 (setq value (get-char-attribute char name)))
687 (format "(%-18s . %05d)\t; %c%s"
688 name value (decode-char '=daikanwa value)
690 (format "(%-18s %s)\t; %c%s"
692 (mapconcat (function prin1-to-string)
694 (char-representative-of-daikanwa char)
696 (setq attributes (delq name attributes))))
697 (when (and (memq 'general-category attributes)
698 (setq value (get-char-attribute char 'general-category)))
700 "(general-category\t%s) ; %s%s"
701 (mapconcat (lambda (cell)
704 (cond ((rassoc value unidata-normative-category-alist)
705 "Normative Category")
706 ((rassoc value unidata-informative-category-alist)
707 "Informative Category")
711 (setq attributes (delq 'general-category attributes))
713 (when (and (memq 'bidi-category attributes)
714 (setq value (get-char-attribute char 'bidi-category)))
715 (insert (format "(bidi-category\t. %S)%s"
718 (setq attributes (delq 'bidi-category attributes))
720 (unless (or (not (memq 'mirrored attributes))
721 (eq (setq value (get-char-attribute char 'mirrored 'empty))
723 (insert (format "(mirrored\t\t. %S)%s"
726 (setq attributes (delq 'mirrored attributes))
729 ((and (memq 'decimal-digit-value attributes)
730 (setq value (get-char-attribute char 'decimal-digit-value)))
731 (insert (format "(decimal-digit-value . %S)%s"
734 (setq attributes (delq 'decimal-digit-value attributes))
735 (when (and (memq 'digit-value attributes)
736 (setq value (get-char-attribute char 'digit-value)))
737 (insert (format "(digit-value\t . %S)%s"
740 (setq attributes (delq 'digit-value attributes))
742 (when (and (memq 'numeric-value attributes)
743 (setq value (get-char-attribute char 'numeric-value)))
744 (insert (format "(numeric-value\t . %S)%s"
747 (setq attributes (delq 'numeric-value attributes))
751 (when (and (memq 'digit-value attributes)
752 (setq value (get-char-attribute char 'digit-value)))
753 (insert (format "(digit-value\t. %S)%s"
756 (setq attributes (delq 'digit-value attributes))
758 (when (and (memq 'numeric-value attributes)
759 (setq value (get-char-attribute char 'numeric-value)))
760 (insert (format "(numeric-value\t. %S)%s"
763 (setq attributes (delq 'numeric-value attributes))
765 (when (and (memq 'iso-10646-comment attributes)
766 (setq value (get-char-attribute char 'iso-10646-comment)))
767 (insert (format "(iso-10646-comment\t. %S)%s"
770 (setq attributes (delq 'iso-10646-comment attributes))
772 (when (and (memq 'morohashi-daikanwa attributes)
773 (setq value (get-char-attribute char 'morohashi-daikanwa)))
774 (insert (format "(morohashi-daikanwa\t%s)%s"
775 (mapconcat (function prin1-to-string) value " ")
777 (setq attributes (delq 'morohashi-daikanwa attributes))
781 (when (and (memq 'ideographic-radical attributes)
782 (setq value (get-char-attribute char 'ideographic-radical)))
784 (insert (format "(ideographic-radical . %S)\t; %c%s"
786 (ideographic-radical radical)
788 (setq attributes (delq 'ideographic-radical attributes))
790 (when (and (memq 'shuowen-radical attributes)
791 (setq value (get-char-attribute char 'shuowen-radical)))
792 (insert (format "(shuowen-radical\t. %S)\t; %c%s"
794 (shuowen-radical value)
796 (setq attributes (delq 'shuowen-radical attributes))
801 char-db-feature-domains
803 (dolist (feature (char-attribute-list))
804 (setq feature (symbol-name feature))
806 "\\(radical\\|strokes\\)@\\([^@*]+\\)\\(\\*\\|$\\)"
808 (setq domain (intern (match-string 2 feature)))
809 (unless (memq domain dest)
810 (setq dest (cons domain dest)))))
811 (sort dest #'string<))))
812 (setq key (intern (format "%s@%s" 'ideographic-radical domain)))
813 (when (and (memq key attributes)
814 (setq value (get-char-attribute char key)))
816 (insert (format "(%s . %S)\t; %c%s"
819 (ideographic-radical radical)
821 (setq attributes (delq key attributes))
823 (setq key (intern (format "%s@%s" 'ideographic-strokes domain)))
824 (when (and (memq key attributes)
825 (setq value (get-char-attribute char key)))
827 (insert (format "(%s . %S)%s"
831 (setq attributes (delq key attributes))
833 (setq key (intern (format "%s@%s" 'total-strokes domain)))
834 (when (and (memq key attributes)
835 (setq value (get-char-attribute char key)))
836 (insert (format "(%s . %S)%s"
840 (setq attributes (delq key attributes))
842 (dolist (feature '(ideographic-radical
845 (setq key (intern (format "%s@%s*sources" feature domain)))
846 (when (and (memq key attributes)
847 (setq value (get-char-attribute char key)))
848 (insert (format "(%s%s" key line-breaking))
850 (insert (format " %s" cell)))
852 (insert line-breaking)
853 (setq attributes (delq key attributes))
856 (when (and (memq 'ideographic-strokes attributes)
857 (setq value (get-char-attribute char 'ideographic-strokes)))
859 (insert (format "(ideographic-strokes . %S)%s"
862 (setq attributes (delq 'ideographic-strokes attributes))
864 (when (and (memq 'kangxi-radical attributes)
865 (setq value (get-char-attribute char 'kangxi-radical)))
866 (unless (eq value radical)
867 (insert (format "(kangxi-radical\t . %S)\t; %c%s"
869 (ideographic-radical value)
872 (setq radical value)))
873 (setq attributes (delq 'kangxi-radical attributes))
875 (when (and (memq 'kangxi-strokes attributes)
876 (setq value (get-char-attribute char 'kangxi-strokes)))
877 (unless (eq value strokes)
878 (insert (format "(kangxi-strokes\t . %S)%s"
882 (setq strokes value)))
883 (setq attributes (delq 'kangxi-strokes attributes))
885 (when (and (memq 'japanese-radical attributes)
886 (setq value (get-char-attribute char 'japanese-radical)))
887 (unless (eq value radical)
888 (insert (format "(japanese-radical\t . %S)\t; %c%s"
890 (ideographic-radical value)
893 (setq radical value)))
894 (setq attributes (delq 'japanese-radical attributes))
896 (when (and (memq 'japanese-strokes attributes)
897 (setq value (get-char-attribute char 'japanese-strokes)))
898 (unless (eq value strokes)
899 (insert (format "(japanese-strokes\t . %S)%s"
903 (setq strokes value)))
904 (setq attributes (delq 'japanese-strokes attributes))
906 (when (and (memq 'cns-radical attributes)
907 (setq value (get-char-attribute char 'cns-radical)))
908 (insert (format "(cns-radical\t . %S)\t; %c%s"
910 (ideographic-radical value)
912 (setq attributes (delq 'cns-radical attributes))
914 (when (and (memq 'cns-strokes attributes)
915 (setq value (get-char-attribute char 'cns-strokes)))
916 (unless (eq value strokes)
917 (insert (format "(cns-strokes\t . %S)%s"
921 (setq strokes value)))
922 (setq attributes (delq 'cns-strokes attributes))
924 (when (and (memq 'shinjigen-1-radical attributes)
925 (setq value (get-char-attribute char 'shinjigen-1-radical)))
926 (unless (eq value radical)
927 (insert (format "(shinjigen-1-radical . %S)\t; %c%s"
929 (ideographic-radical value)
932 (setq radical value)))
933 (setq attributes (delq 'shinjigen-1-radical attributes))
935 (when (and (memq 'ideographic- attributes)
936 (setq value (get-char-attribute char 'ideographic-)))
937 (insert "(ideographic- ")
938 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
941 (setq cell (car value))
943 (setq cell (decode-char '=ucs cell)))
944 (cond ((characterp cell)
948 (insert (format "%S" cell))
949 (char-db-insert-char-spec cell readable))
950 (setq separator lbs))
954 (if (consp (car cell))
955 (char-db-insert-char-spec cell readable)
956 (char-db-insert-char-reference cell readable))
957 (setq separator lbs))
961 (insert (prin1-to-string cell))
962 (setq separator " ")))
963 (setq value (cdr value)))
965 (insert line-breaking)
966 (setq attributes (delq 'ideographic- attributes)))
967 (when (and (memq 'total-strokes attributes)
968 (setq value (get-char-attribute char 'total-strokes)))
969 (insert (format "(total-strokes . %S)%s"
972 (setq attributes (delq 'total-strokes attributes))
974 (when (and (memq '->ideograph attributes)
975 (setq value (get-char-attribute char '->ideograph)))
976 (insert (format "(->ideograph\t%s)%s"
977 (mapconcat (lambda (code)
978 (cond ((symbolp code)
981 (format "#x%04X" code))
984 line-breaking code))))
987 (setq attributes (delq '->ideograph attributes))
989 ;; (when (and (memq '->decomposition attributes)
990 ;; (setq value (get-char-attribute char '->decomposition)))
991 ;; (insert (format "(->decomposition\t%s)%s"
992 ;; (mapconcat (lambda (code)
993 ;; (cond ((symbolp code)
994 ;; (symbol-name code))
995 ;; ((characterp code)
997 ;; (format "%S" code)
1002 ;; (format "#x%04X" code))
1004 ;; (format "%s%S" line-breaking code))))
1007 ;; (setq attributes (delq '->decomposition attributes))
1009 (if (equal (get-char-attribute char '->titlecase)
1010 (get-char-attribute char '->uppercase))
1011 (setq attributes (delq '->titlecase attributes)))
1012 (when (and (memq '->mojikyo attributes)
1013 (setq value (get-char-attribute char '->mojikyo)))
1014 (insert (format "(->mojikyo\t\t. %06d)\t; %c%s"
1015 value (decode-char 'mojikyo value)
1017 (setq attributes (delq '->mojikyo attributes))
1019 (when (and (memq 'hanyu-dazidian-vol attributes)
1020 (setq value (get-char-attribute char 'hanyu-dazidian-vol)))
1021 (insert (format "(hanyu-dazidian-vol . %d)%s"
1022 value line-breaking))
1023 (setq attributes (delq 'hanyu-dazidian-vol attributes))
1025 (when (and (memq 'hanyu-dazidian-page attributes)
1026 (setq value (get-char-attribute char 'hanyu-dazidian-page)))
1027 (insert (format "(hanyu-dazidian-page . %d)%s"
1028 value line-breaking))
1029 (setq attributes (delq 'hanyu-dazidian-page attributes))
1031 (when (and (memq 'hanyu-dazidian-char attributes)
1032 (setq value (get-char-attribute char 'hanyu-dazidian-char)))
1033 (insert (format "(hanyu-dazidian-char . %d)%s"
1034 value line-breaking))
1035 (setq attributes (delq 'hanyu-dazidian-char attributes))
1038 (dolist (ignored '(composition
1039 ->denotational <-subsumptive ->ucs-unified
1040 ->ideographic-component-forms))
1041 (setq attributes (delq ignored attributes))))
1043 (setq name (car attributes))
1044 (if (setq value (get-char-attribute char name))
1045 (cond ((setq ret (find-charset name))
1046 (setq name (charset-name ret))
1047 (if (and (not (memq name dest-ccss))
1049 (setq value (get-char-attribute char name))
1050 (setq dest-ccss (cons name dest-ccss))))
1051 (char-db-insert-ccs-feature name value line-breaking))
1053 ((string-match "^=>ucs@" (symbol-name name))
1054 (insert (format "(%-18s . #x%04X)\t; %c%s"
1055 name value (decode-char '=ucs value)
1058 ((eq name 'jisx0208-1978/4X)
1059 (insert (format "(%-18s . #x%04X)%s"
1065 (not (eq name '->subsumptive))
1066 (not (eq name '->uppercase))
1067 (not (eq name '->lowercase))
1068 (not (eq name '->titlecase))
1069 (not (eq name '->canonical))
1070 (not (eq name '->Bopomofo))
1071 (not (eq name '->mistakable))
1072 (not (eq name '->ideographic-variants))
1073 (null (get-char-attribute
1074 char (intern (format "%s*sources" name))))
1075 (not (string-match "\\*sources$" (symbol-name name)))
1076 (null (get-char-attribute
1077 char (intern (format "%s*note" name))))
1078 (not (string-match "\\*note$" (symbol-name name)))
1079 (or (eq name '<-identical)
1080 (eq name '<-uppercase)
1081 (eq name '<-lowercase)
1082 (eq name '<-titlecase)
1083 (eq name '<-canonical)
1084 (eq name '<-ideographic-variants)
1085 ;; (eq name '<-synonyms)
1086 (string-match "^<-synonyms" (symbol-name name))
1087 (eq name '<-mistakable)
1088 (when (string-match "^->" (symbol-name name))
1090 ((string-match "^->fullwidth" (symbol-name name))
1091 (not (and (consp value)
1092 (characterp (car value))
1094 (car value) '=ucs 'defined-only)))
1099 ((or (eq name 'ideographic-structure)
1100 (eq name 'ideographic-combination)
1101 (eq name 'ideographic-)
1102 (eq name '=decomposition)
1103 (string-match "^=>decomposition" (symbol-name name))
1104 (string-match "^\\(->\\|<-\\)[^*]*$" (symbol-name name))
1105 (string-match "^\\(->\\|<-\\)[^*]*\\*sources$"
1108 (char-db-insert-relation-feature char name value
1111 ((memq name '(ideograph=
1112 original-ideograph-of
1113 ancient-ideograph-of
1116 ;; simplified-ideograph-of
1117 ideographic-variants
1118 ;; ideographic-different-form-of
1120 (insert (format "(%-18s%s " name line-breaking))
1121 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1123 (while (consp value)
1124 (setq cell (car value))
1125 (if (and (consp cell)
1130 (char-db-insert-alist cell readable)
1131 (setq separator lbs))
1134 (insert (prin1-to-string cell))
1135 (setq separator " "))
1136 (setq value (cdr value)))
1138 (insert line-breaking))
1140 (insert (format "(%-18s " name))
1141 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1143 (while (consp value)
1144 (setq cell (car value))
1145 (if (and (consp cell)
1147 (setq ret (condition-case nil
1155 (setq key (car (car rest)))
1156 (if (find-charset key)
1157 (setq cal (cons key cal))
1158 (setq al (cons key al)))
1159 (setq rest (cdr rest)))
1162 (insert-char-attributes ret
1165 (setq separator lbs))
1166 (setq ret (prin1-to-string cell))
1168 (if (< (+ (current-column)
1175 (setq separator " "))
1176 (setq value (cdr value)))
1178 (insert line-breaking))
1180 (insert (format "(%-18s" name))
1181 (setq ret (prin1-to-string value))
1182 (unless (< (+ (current-column)
1186 (insert line-breaking))
1187 (insert " . " ret ")" line-breaking)
1188 ;; (insert (format "(%-18s . %S)%s"
1193 (setq attributes (cdr attributes)))
1196 (defun insert-char-data (char &optional readable
1199 (narrow-to-region (point)(point))
1200 (insert "(define-char
1202 (insert-char-attributes char readable attributes)
1204 (goto-char (point-min))
1205 (while (re-search-forward "[ \t]+$" nil t)
1208 (goto-char (point-min))
1209 (while (re-search-forward "[ \t][ \t][ \t]*" nil t)
1210 (let ((column (current-column))
1211 (indent-tabs-mode t))
1212 (delete-region (match-beginning 0) (point))
1213 (indent-to column)))
1214 (goto-char (point-max))
1215 ;; (tabify (point-min)(point-max))
1218 (defun insert-char-data-with-variant (char &optional printable
1220 script excluded-script)
1221 (insert-char-data char printable)
1222 (let ((variants (char-variants char))
1225 (setq variants (sort variants #'<))
1226 (setq rest variants)
1227 (setq variants (cons char variants))
1229 (setq variant (car rest))
1230 (unless (get-char-attribute variant '<-subsumptive)
1231 (if (and (or (null script)
1232 (null (setq vs (get-char-attribute variant 'script)))
1234 (or (null excluded-script)
1235 (null (setq vs (get-char-attribute variant 'script)))
1236 (not (memq excluded-script vs))))
1237 (unless (and no-ucs-unified (get-char-attribute variant '=ucs))
1238 (insert-char-data variant printable)
1239 (if (setq ret (char-variants variant))
1241 (or (memq (car ret) variants)
1242 ;; (get-char-attribute (car ret) '<-subsumptive)
1243 (setq rest (nconc rest (list (car ret)))))
1244 (setq ret (cdr ret)))))))
1245 (setq rest (cdr rest)))))
1247 (defun insert-char-range-data (min max &optional script excluded-script)
1250 (while (<= code max)
1251 (setq char (decode-char '=ucs code))
1252 (if (encode-char char '=ucs 'defined-only)
1253 (insert-char-data-with-variant char nil 'no-ucs-unified
1254 script excluded-script))
1255 (setq code (1+ code)))))
1257 (defun write-char-range-data-to-file (min max file
1258 &optional script excluded-script)
1259 (let ((coding-system-for-write char-db-file-coding-system))
1261 (insert (format ";; -*- coding: %s -*-\n"
1262 char-db-file-coding-system))
1263 (insert-char-range-data min max script excluded-script)
1264 (write-region (point-min)(point-max) file))))
1266 (defvar what-character-original-window-configuration)
1269 (defun what-char-definition (char)
1270 (interactive (list (char-after)))
1271 (let ((buf (get-buffer-create "*Character Description*"))
1272 (the-buf (current-buffer))
1273 (win-conf (current-window-configuration)))
1275 (make-local-variable 'what-character-original-window-configuration)
1276 (setq what-character-original-window-configuration win-conf)
1277 (setq buffer-read-only nil)
1281 (insert-char-data-with-variant char 'printable)
1282 (unless (char-attribute-alist char)
1283 (insert (format ";; = %c\n"
1284 (let* ((rest (split-char char))
1288 (setq code (logior (lsh code 8)
1290 (decode-char ccs code)))))
1291 ;; (char-db-update-comment)
1292 (set-buffer-modified-p nil)
1293 (view-mode the-buf (lambda (buf)
1294 (set-window-configuration
1295 what-character-original-window-configuration)
1297 (goto-char (point-min)))
1299 (set-window-configuration
1300 what-character-original-window-configuration)
1301 (signal (car err) (cdr err)))))))
1303 (provide 'char-db-util)
1305 ;;; char-db-util.el ends here