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, 2009, 2010 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.
29 (require 'ideograph-subr)
31 (defconst unidata-normative-category-alist
32 '(("Lu" letter uppercase)
33 ("Ll" letter lowercase)
34 ("Lt" letter titlecase)
35 ("Mn" mark non-spacing)
36 ("Mc" mark spacing-combining)
38 ("Nd" number decimal-digit)
41 ("Zs" separator space)
43 ("Zp" separator paragraph)
46 ("Cs" other surrogate)
47 ("Co" other private-use)
48 ("Cn" other not-assigned)))
50 (defconst unidata-informative-category-alist
51 '(("Lm" letter modifier)
53 ("Pc" punctuation connector)
54 ("Pd" punctuation dash)
55 ("Ps" punctuation open)
56 ("Pe" punctuation close)
57 ("Pi" punctuation initial-quote)
58 ("Pf" punctuation final-quote)
59 ("Po" punctuation other)
61 ("Sc" symbol currency)
62 ("Sk" symbol modifier)
66 (defconst shuowen-radicals
67 [?一 ?上 ?示 ?三 ?王 ?玉 ?玨 ?气 ?士 ?丨 ; 010
68 ?屮 ?艸 ?蓐 ?茻 ?小 ?八 ?釆 ?半 ?牛 ?犛 ; 020
69 ?告 ?口 ?凵 ?吅 ?哭 ?走 ?止 ?癶 ?步 ?此 ; 030
70 ?正 ?是 ?辵 ?彳 ?廴 ?㢟 ?行 ?齒 ?牙 ?足 ; 040
71 ?疋 ?品 ?龠 ?冊 ?㗊 ?舌 ?干 ?谷 ?只 ?㕯 ; 050
72 ?句 ?丩 ?古 ?十 ?卅 ?言 ?誩 ?音 ?䇂 ?丵 ; 060
73 ?菐 ?𠬞 ?廾 ?共 ?異 ?舁 ?𦥑 ?䢅 ?爨 ?革 ; 070
74 ?鬲 ?䰜 ?爪 ?𠃨 ?鬥 ?又 ?𠂇 ?㕜 ?支 ?𦘒 ; 080
75 ?聿 ?畫 ?隶 ?臤 ?臣 ?殳 ?殺 ?𠘧 ?寸 ?皮 ; 090
76 ?㼱 ?攴 ?敎 ?卜 ?用 ?爻 ?㸚 ?𥄎 ?目 ?䀠 ; 100
77 ?眉 ?盾 ?自 ?白 ?鼻 ?皕 ?習 ?羽 ?隹 ?奞 ; 110
78 ?萑 ?𦫳 ?苜 ?羊 ?羴 ?瞿 ?雔 ?雥 ?鳥 ?烏 ; 120
79 ?𠦒 ?冓 ?幺 ?𢆶 ?叀 ?玄 ?予 ?放 ?𠬪 ?𣦼 ; 130
80 ?歺 ?死 ?冎 ?骨 ?肉 ?筋 ?刀 ?刃 ?㓞 ?丰 ; 140
81 ?耒 ?𧢲 ?竹 ?箕 ?丌 ?左 ?工 ?㠭 ?巫 ?甘 ; 150
82 ?曰 ?乃 ?丂 ?可 ?兮 ?号 ?亏 ?旨 ?喜 ?壴 ; 160
83 ?鼓 ?豈 ?豆 ?豊 ?豐 ?䖒 ?虍 ?虎 ?虤 ?皿 ; 170
84 ?𠙴 ?去 ?血 ?丶 ?丹 ?青 ?井 ?皀 ?鬯 ?食 ; 180
85 ?亼 ?會 ?倉 ?入 ?缶 ?矢 ?高 ?冂 ?𩫏 ?京 ; 190
86 ?亯 ?𣆪 ?畗 ?㐭 ?嗇 ?來 ?麥 ?夊 ?舛 ?䑞 ; 200
87 ?韋 ?弟 ?夂 ?久 ?桀 ?木 ?東 ?林 ?才 ?叒 ; 210
88 ?之 ?帀 ?出 ?𣎵 ?生 ?乇 ?𠂹 ?𠌶 ?華 ?𥝌 ; 220
89 ?稽 ?巢 ?桼 ?束 ?㯻 ?囗 ?員 ?貝 ?邑 ?𨛜 ; 230
90 ?日 ?旦 ?倝 ?㫃 ?冥 ?晶 ?月 ?有 ?明 ?囧 ; 240
91 ?夕 ?多 ?毌 ?𢎘 ?𣐺 ?卣 ?齊 ?朿 ?片 ?鼎 ; 250
92 ?克 ?彔 ?禾 ?秝 ?黍 ?香 ?米 ?毇 ?臼 ?凶 ; 260
93 ?𣎳 ?林 ?麻 ?尗 ?耑 ?韭 ?瓜 ?瓠 ?宀 ?宮 ; 270
94 ?呂 ?穴 ?㝱 ?𤕫 ?冖 ?𠔼 ?冃 ?㒳 ?网 ?襾 ; 280
95 ?巾 ?巿 ?帛 ?白 ?㡀 ?黹 ?人 ?𠤎 ?匕 ?从 ; 290
98 (defun shuowen-radical (number)
99 (aref shuowen-radicals (1- number)))
101 (defvar char-db-file-coding-system 'utf-8-mcs-er)
103 (defvar char-db-ignored-attributes '(ideographic-products))
105 (defvar char-db-coded-charset-priority-list
187 ;;; @ char-db formatters
190 (defun char-db-make-char-spec (char)
192 (cond ((characterp char)
193 (cond ((and (setq ret (encode-char char '=ucs 'defined-only))
194 (not (and (<= #xE000 ret)(<= ret #xF8FF))))
195 (setq char-spec (list (cons '=ucs ret)))
196 (cond ((setq ret (get-char-attribute char 'name))
197 (setq char-spec (cons (cons 'name ret) char-spec))
199 ((setq ret (get-char-attribute char 'name*))
200 (setq char-spec (cons (cons 'name* ret) char-spec))
205 (let ((rest char-db-coded-charset-priority-list)
208 (setq ccs (charset-name
209 (find-charset (car rest))))
211 (encode-char char ccs
213 (throw 'tag (cons ccs ret)))
214 (setq rest (cdr rest))))))
215 (setq char-spec (list ret))
216 (dolist (ccs (delq (car ret) (charset-list)))
217 (if (and (or (charset-iso-final-char ccs)
224 (string-match "=ucs@" (symbol-name ccs)))
225 (setq ccs (charset-name ccs))
226 (null (assq ccs char-spec))
227 (setq ret (encode-char char ccs 'defined-only)))
228 (setq char-spec (cons (cons ccs ret) char-spec))))
230 (setq char-spec (split-char char)))
231 (cond ((setq ret (get-char-attribute char 'name))
232 (setq char-spec (cons (cons 'name ret) char-spec))
234 ((setq ret (get-char-attribute char 'name*))
235 (setq char-spec (cons (cons 'name* ret) char-spec))
238 ((setq ret (get-char-attribute
239 char 'ideographic-combination))
241 (cons (cons 'ideographic-combination ret)
248 (defun char-db-insert-char-spec (char &optional readable column
251 (setq column (current-column)))
252 (let (char-spec temp-char)
253 (setq char-spec (char-db-make-char-spec char))
254 (unless (or (characterp char) ; char
256 (setq char (find-char char-spec))
258 ;; define temporary character
259 ;; Current implementation is dirty.
260 (setq temp-char (define-char (cons '(ideograph-daikanwa . 0)
262 (remove-char-attribute temp-char 'ideograph-daikanwa)
263 (setq char temp-char))
264 (insert-char-attributes char
266 (union (mapcar #'car char-spec)
269 ;; undefine temporary character
270 ;; Current implementation is dirty.
271 (setq char-spec (char-attribute-alist temp-char))
273 (remove-char-attribute temp-char (car (car char-spec)))
274 (setq char-spec (cdr char-spec))))))
276 (defun char-db-insert-alist (alist &optional readable column)
278 (setq column (current-column)))
280 (concat "\n" (make-string (1+ column) ?\ )))
284 lbs cell rest separator)
287 (setq name (car (car alist))
288 value (cdr (car alist)))
289 (cond ((eq name 'char)
291 (if (setq ret (condition-case nil
299 (setq key (car (car value)))
300 ;; (if (find-charset key)
301 ;; (setq cal (cons key cal))
302 (setq al (cons key al))
304 (setq value (cdr value)))
305 (insert-char-attributes ret
309 (insert (prin1-to-string value)))
311 (insert line-breaking))
313 (insert (format "(%-18s " name))
314 (setq lbs (concat "\n" (make-string (current-column) ?\ )))
316 (setq cell (car value))
317 (if (and (consp cell)
319 (setq ret (condition-case nil
329 (setq key (car (car rest)))
330 ;; (if (find-charset key)
331 ;; (setq cal (cons key cal))
332 (setq al (cons key al))
334 (setq rest (cdr rest)))
337 (insert-char-attributes ret
341 (setq separator lbs))
344 (insert (prin1-to-string cell))
345 (setq separator " "))
346 (setq value (cdr value)))
348 (insert line-breaking))
350 (insert (format "(%-18s . %S)%s"
353 (setq alist (cdr alist))))
356 (defun char-db-insert-char-reference (plist &optional readable column)
358 (setq column (current-column)))
360 (concat "\n" (make-string (1+ column) ?\ )))
365 (setq name (pop plist))
366 (setq value (pop plist))
367 (cond ((eq name :char)
370 (cond ((numberp value)
371 (setq value (decode-char '=ucs value)))
373 ;; (setq value (or (find-char value)
376 (char-db-insert-char-spec value readable)
377 (insert line-breaking)
380 (insert (format "%s%s\t%d ; %c%s"
383 (ideographic-radical value)
387 (insert (format "%s%s\t%S" separator name value))
388 (setq separator line-breaking)))
392 (defun char-db-decode-isolated-char (ccs code-point)
395 (cond ((eq ccs 'arabic-iso8859-6)
396 (decode-char ccs code-point))
397 ((and (memq ccs '(=gt-pj-1
408 (setq ret (decode-char ccs code-point))
409 (setq ret (encode-char ret '=gt 'defined-only)))
410 (decode-builtin-char '=gt ret))
412 (decode-builtin-char ccs code-point))))
413 (cond ((and (<= 0 (char-int ret))
414 (<= (char-int ret) #x1F))
415 (decode-char '=ucs (+ #x2400 (char-int ret))))
416 ((= (char-int ret) #x7F)
420 (defvar char-db-convert-obsolete-format t)
422 (defun char-db-insert-ccs-feature (name value line-breaking)
425 (cond ((memq name '(=shinjigen
427 =shinjigen@rev =shinjigen/+p@rev))
428 "(%-18s . %04d)\t; %c")
429 ((eq name '=shinjigen@1ed/24pr)
430 "(%-18s . %04d)\t; %c")
431 ((or (memq name '(=daikanwa
432 =daikanwa@rev1 =daikanwa@rev2
433 =gt =>>gt =>gt =gt-k =>>gt-k =cbeta
434 =zinbun-oracle =>zinbun-oracle))
435 (string-match "^=adobe-" (symbol-name name)))
436 "(%-18s . %05d)\t; %c")
438 "(%-18s . %06d)\t; %c")
439 ((>= (charset-dimension name) 2)
440 "(%-18s . #x%04X)\t; %c")
442 "(%-18s . #x%02X)\t; %c"))
444 (if (= (charset-iso-graphic-plane name) 1)
446 (cond ((= (charset-dimension name) 1)
448 ((= (charset-dimension name) 2)
450 ((= (charset-dimension name) 3)
454 (char-db-decode-isolated-char name value)))
455 (if (and (= (charset-chars name) 94)
456 (= (charset-dimension name) 2))
457 (insert (format " [%02d-%02d]"
458 (- (lsh value -8) 32)
459 (- (logand value 255) 32))))
460 (insert line-breaking))
462 (defun char-db-insert-relation-feature (char name value line-breaking
464 (insert (format "(%-18s%s " name line-breaking))
465 (let ((lbs (concat "\n" (make-string (current-column) ?\ )))
466 separator cell sources required-features
469 (setq cell (car value))
471 (setq cell (decode-char '=ucs cell)))
473 ((eq name '->subsumptive)
474 (when (or (not (some (lambda (atr)
475 (get-char-attribute cell atr))
476 char-db-ignored-attributes))
478 (encode-char cell ccs 'defined-only))
482 (let ((char-db-ignored-attributes
484 char-db-ignored-attributes)))
485 (insert-char-attributes cell readable))
486 (setq separator lbs))
491 char (intern (format "%s*sources" name))))
492 (setq required-features nil)
493 (dolist (source sources)
497 shinjigen shinjigen@1ed shinjigen@rev))
498 (setq required-features
499 (union required-features
509 (setq required-features
510 (union required-features
515 ((find-charset (setq ret (intern (format "=%s" source))))
516 (setq required-features
517 (cons ret required-features)))
518 (t (setq required-features
519 (cons source required-features)))))
520 (cond ((string-match "@JP" (symbol-name name))
521 (setq required-features
522 (union required-features
530 ((string-match "@CN" (symbol-name name))
531 (setq required-features
532 (union required-features
539 (insert (format "%S" cell))
540 (char-db-insert-char-spec cell readable
543 (setq separator lbs))
547 (if (consp (car cell))
548 (char-db-insert-char-spec cell readable)
549 (char-db-insert-char-reference cell readable))
550 (setq separator lbs))
554 (insert (prin1-to-string cell))
555 (setq separator " ")))
556 (setq value (cdr value)))
558 (insert line-breaking)))
560 (defun insert-char-attributes (char &optional readable attributes column)
562 (setq column (current-column)))
563 (let (name value ; has-long-ccs-name
567 (concat "\n" (make-string (1+ column) ?\ )))
568 lbs cell separator ret
570 dest-ccss ; sources required-features
575 (if (consp attributes)
577 (dolist (name attributes)
578 (unless (memq name char-db-ignored-attributes)
579 (if (find-charset name)
583 (dolist (name (char-attribute-list))
584 (unless (memq name char-db-ignored-attributes)
585 (if (find-charset name)
589 #'char-attribute-name<)))
591 (when (memq '<-subsumptive attributes)
593 (when (setq value (get-char-attribute char '<-subsumptive))
594 (char-db-insert-relation-feature char '<-subsumptive value
597 (setq attributes (delq '<-subsumptive attributes)))
598 (when (and (memq '<-denotational attributes)
599 (setq value (get-char-attribute char '<-denotational)))
600 (char-db-insert-relation-feature char '<-denotational value
603 (setq attributes (delq '<-denotational attributes)))
604 (when (and (memq 'name attributes)
605 (setq value (get-char-attribute char 'name)))
607 (if (> (+ (current-column) (length value)) 48)
610 value line-breaking))
611 (setq attributes (delq 'name attributes))
613 (when (and (memq 'name* attributes)
614 (setq value (get-char-attribute char 'name*)))
616 (if (> (+ (current-column) (length value)) 48)
619 value line-breaking))
620 (setq attributes (delq 'name* attributes))
622 (when (and (memq 'script attributes)
623 (setq value (get-char-attribute char 'script)))
624 (insert (format "(script\t\t%s)%s"
625 (mapconcat (function prin1-to-string)
628 (setq attributes (delq 'script attributes))
630 (dolist (name '(=>ucs =>ucs*))
631 (when (and (memq name attributes)
632 (setq value (get-char-attribute char name)))
633 (insert (format "(%-18s . #x%04X)\t; %c%s"
634 name value (decode-char '=ucs value)
636 (setq attributes (delq name attributes))))
637 (dolist (name '(=>ucs@gb =>ucs@cns =>ucs@jis =>ucs@ks =>ucs@big5))
638 (when (and (memq name attributes)
639 (setq value (get-char-attribute char name)))
640 (insert (format "(%-18s . #x%04X)\t; %c%s"
645 (symbol-name name) 2)))
648 (setq attributes (delq name attributes))
650 (dolist (name '(=>daikanwa))
651 (when (and (memq name attributes)
652 (setq value (get-char-attribute char name)))
655 (format "(%-18s . %05d)\t; %c%s"
656 name value (decode-char '=daikanwa value)
658 (format "(%-18s %s)\t; %c%s"
660 (mapconcat (function prin1-to-string)
662 (char-representative-of-daikanwa char)
664 (setq attributes (delq name attributes))))
665 (when (and (memq 'general-category attributes)
666 (setq value (get-char-attribute char 'general-category)))
668 "(general-category\t%s) ; %s%s"
669 (mapconcat (lambda (cell)
672 (cond ((rassoc value unidata-normative-category-alist)
673 "Normative Category")
674 ((rassoc value unidata-informative-category-alist)
675 "Informative Category")
679 (setq attributes (delq 'general-category attributes))
681 (when (and (memq 'bidi-category attributes)
682 (setq value (get-char-attribute char 'bidi-category)))
683 (insert (format "(bidi-category\t. %S)%s"
686 (setq attributes (delq 'bidi-category attributes))
688 (unless (or (not (memq 'mirrored attributes))
689 (eq (setq value (get-char-attribute char 'mirrored 'empty))
691 (insert (format "(mirrored\t\t. %S)%s"
694 (setq attributes (delq 'mirrored attributes))
697 ((and (memq 'decimal-digit-value attributes)
698 (setq value (get-char-attribute char 'decimal-digit-value)))
699 (insert (format "(decimal-digit-value . %S)%s"
702 (setq attributes (delq 'decimal-digit-value attributes))
703 (when (and (memq 'digit-value attributes)
704 (setq value (get-char-attribute char 'digit-value)))
705 (insert (format "(digit-value\t . %S)%s"
708 (setq attributes (delq 'digit-value attributes))
710 (when (and (memq 'numeric-value attributes)
711 (setq value (get-char-attribute char 'numeric-value)))
712 (insert (format "(numeric-value\t . %S)%s"
715 (setq attributes (delq 'numeric-value attributes))
719 (when (and (memq 'digit-value attributes)
720 (setq value (get-char-attribute char 'digit-value)))
721 (insert (format "(digit-value\t. %S)%s"
724 (setq attributes (delq 'digit-value attributes))
726 (when (and (memq 'numeric-value attributes)
727 (setq value (get-char-attribute char 'numeric-value)))
728 (insert (format "(numeric-value\t. %S)%s"
731 (setq attributes (delq 'numeric-value attributes))
733 (when (and (memq 'iso-10646-comment attributes)
734 (setq value (get-char-attribute char 'iso-10646-comment)))
735 (insert (format "(iso-10646-comment\t. %S)%s"
738 (setq attributes (delq 'iso-10646-comment attributes))
740 (when (and (memq 'morohashi-daikanwa attributes)
741 (setq value (get-char-attribute char 'morohashi-daikanwa)))
742 (insert (format "(morohashi-daikanwa\t%s)%s"
743 (mapconcat (function prin1-to-string) value " ")
745 (setq attributes (delq 'morohashi-daikanwa attributes))
749 (when (and (memq 'ideographic-radical attributes)
750 (setq value (get-char-attribute char 'ideographic-radical)))
752 (insert (format "(ideographic-radical . %S)\t; %c%s"
754 (ideographic-radical radical)
756 (setq attributes (delq 'ideographic-radical attributes))
758 (when (and (memq 'shuowen-radical attributes)
759 (setq value (get-char-attribute char 'shuowen-radical)))
760 (insert (format "(shuowen-radical\t. %S)\t; %c%s"
762 (shuowen-radical value)
764 (setq attributes (delq 'shuowen-radical attributes))
769 char-db-feature-domains
771 (dolist (feature (char-attribute-list))
772 (setq feature (symbol-name feature))
774 "\\(radical\\|strokes\\)@\\([^@*]+\\)\\(\\*\\|$\\)"
776 (setq domain (intern (match-string 2 feature)))
777 (unless (memq domain dest)
778 (setq dest (cons domain dest)))))
779 (sort dest #'string<))))
780 (setq key (intern (format "%s@%s" 'ideographic-radical domain)))
781 (when (and (memq key attributes)
782 (setq value (get-char-attribute char key)))
784 (insert (format "(%s . %S)\t; %c%s"
787 (ideographic-radical radical)
789 (setq attributes (delq key attributes))
791 (setq key (intern (format "%s@%s" 'ideographic-strokes domain)))
792 (when (and (memq key attributes)
793 (setq value (get-char-attribute char key)))
795 (insert (format "(%s . %S)%s"
799 (setq attributes (delq key attributes))
801 (setq key (intern (format "%s@%s" 'total-strokes domain)))
802 (when (and (memq key attributes)
803 (setq value (get-char-attribute char key)))
804 (insert (format "(%s . %S)%s"
808 (setq attributes (delq key attributes))
810 (dolist (feature '(ideographic-radical
813 (setq key (intern (format "%s@%s*sources" feature domain)))
814 (when (and (memq key attributes)
815 (setq value (get-char-attribute char key)))
816 (insert (format "(%s%s" key line-breaking))
818 (insert (format " %s" cell)))
820 (insert line-breaking)
821 (setq attributes (delq key attributes))
824 (when (and (memq 'ideographic-strokes attributes)
825 (setq value (get-char-attribute char 'ideographic-strokes)))
827 (insert (format "(ideographic-strokes . %S)%s"
830 (setq attributes (delq 'ideographic-strokes attributes))
832 (when (and (memq 'kangxi-radical attributes)
833 (setq value (get-char-attribute char 'kangxi-radical)))
834 (unless (eq value radical)
835 (insert (format "(kangxi-radical\t . %S)\t; %c%s"
837 (ideographic-radical value)
840 (setq radical value)))
841 (setq attributes (delq 'kangxi-radical attributes))
843 (when (and (memq 'kangxi-strokes attributes)
844 (setq value (get-char-attribute char 'kangxi-strokes)))
845 (unless (eq value strokes)
846 (insert (format "(kangxi-strokes\t . %S)%s"
850 (setq strokes value)))
851 (setq attributes (delq 'kangxi-strokes attributes))
853 (when (and (memq 'japanese-radical attributes)
854 (setq value (get-char-attribute char 'japanese-radical)))
855 (unless (eq value radical)
856 (insert (format "(japanese-radical\t . %S)\t; %c%s"
858 (ideographic-radical value)
861 (setq radical value)))
862 (setq attributes (delq 'japanese-radical attributes))
864 (when (and (memq 'japanese-strokes attributes)
865 (setq value (get-char-attribute char 'japanese-strokes)))
866 (unless (eq value strokes)
867 (insert (format "(japanese-strokes\t . %S)%s"
871 (setq strokes value)))
872 (setq attributes (delq 'japanese-strokes attributes))
874 (when (and (memq 'cns-radical attributes)
875 (setq value (get-char-attribute char 'cns-radical)))
876 (insert (format "(cns-radical\t . %S)\t; %c%s"
878 (ideographic-radical value)
880 (setq attributes (delq 'cns-radical attributes))
882 (when (and (memq 'cns-strokes attributes)
883 (setq value (get-char-attribute char 'cns-strokes)))
884 (unless (eq value strokes)
885 (insert (format "(cns-strokes\t . %S)%s"
889 (setq strokes value)))
890 (setq attributes (delq 'cns-strokes attributes))
892 (when (and (memq 'shinjigen-1-radical attributes)
893 (setq value (get-char-attribute char 'shinjigen-1-radical)))
894 (unless (eq value radical)
895 (insert (format "(shinjigen-1-radical . %S)\t; %c%s"
897 (ideographic-radical value)
900 (setq radical value)))
901 (setq attributes (delq 'shinjigen-1-radical attributes))
903 (when (and (memq 'ideographic- attributes)
904 (setq value (get-char-attribute char 'ideographic-)))
905 (insert "(ideographic- ")
906 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
909 (setq cell (car value))
911 (setq cell (decode-char '=ucs cell)))
912 (cond ((characterp cell)
916 (insert (format "%S" cell))
917 (char-db-insert-char-spec cell readable))
918 (setq separator lbs))
922 (if (consp (car cell))
923 (char-db-insert-char-spec cell readable)
924 (char-db-insert-char-reference cell readable))
925 (setq separator lbs))
929 (insert (prin1-to-string cell))
930 (setq separator " ")))
931 (setq value (cdr value)))
933 (insert line-breaking)
934 (setq attributes (delq 'ideographic- attributes)))
935 (when (and (memq 'total-strokes attributes)
936 (setq value (get-char-attribute char 'total-strokes)))
937 (insert (format "(total-strokes . %S)%s"
940 (setq attributes (delq 'total-strokes attributes))
942 (when (and (memq '->ideograph attributes)
943 (setq value (get-char-attribute char '->ideograph)))
944 (insert (format "(->ideograph\t%s)%s"
945 (mapconcat (lambda (code)
946 (cond ((symbolp code)
949 (format "#x%04X" code))
952 line-breaking code))))
955 (setq attributes (delq '->ideograph attributes))
957 ;; (when (and (memq '->decomposition attributes)
958 ;; (setq value (get-char-attribute char '->decomposition)))
959 ;; (insert (format "(->decomposition\t%s)%s"
960 ;; (mapconcat (lambda (code)
961 ;; (cond ((symbolp code)
962 ;; (symbol-name code))
963 ;; ((characterp code)
965 ;; (format "%S" code)
970 ;; (format "#x%04X" code))
972 ;; (format "%s%S" line-breaking code))))
975 ;; (setq attributes (delq '->decomposition attributes))
977 (if (equal (get-char-attribute char '->titlecase)
978 (get-char-attribute char '->uppercase))
979 (setq attributes (delq '->titlecase attributes)))
980 (when (and (memq '->mojikyo attributes)
981 (setq value (get-char-attribute char '->mojikyo)))
982 (insert (format "(->mojikyo\t\t. %06d)\t; %c%s"
983 value (decode-char 'mojikyo value)
985 (setq attributes (delq '->mojikyo attributes))
987 (when (and (memq 'hanyu-dazidian-vol attributes)
988 (setq value (get-char-attribute char 'hanyu-dazidian-vol)))
989 (insert (format "(hanyu-dazidian-vol . %d)%s"
990 value line-breaking))
991 (setq attributes (delq 'hanyu-dazidian-vol attributes))
993 (when (and (memq 'hanyu-dazidian-page attributes)
994 (setq value (get-char-attribute char 'hanyu-dazidian-page)))
995 (insert (format "(hanyu-dazidian-page . %d)%s"
996 value line-breaking))
997 (setq attributes (delq 'hanyu-dazidian-page attributes))
999 (when (and (memq 'hanyu-dazidian-char attributes)
1000 (setq value (get-char-attribute char 'hanyu-dazidian-char)))
1001 (insert (format "(hanyu-dazidian-char . %d)%s"
1002 value line-breaking))
1003 (setq attributes (delq 'hanyu-dazidian-char attributes))
1006 (dolist (ignored '(composition
1007 ->denotational <-subsumptive ->ucs-unified
1008 ->ideographic-component-forms))
1009 (setq attributes (delq ignored attributes))))
1011 (setq name (car attributes))
1012 (if (setq value (get-char-attribute char name))
1013 (cond ((setq ret (find-charset name))
1014 (setq name (charset-name ret))
1015 (if (and (not (memq name dest-ccss))
1017 (setq value (get-char-attribute char name))
1018 (setq dest-ccss (cons name dest-ccss))))
1019 (char-db-insert-ccs-feature name value line-breaking))
1021 ((string-match "^=>ucs@" (symbol-name name))
1022 (insert (format "(%-18s . #x%04X)\t; %c%s"
1023 name value (decode-char '=ucs value)
1026 ((eq name 'jisx0208-1978/4X)
1027 (insert (format "(%-18s . #x%04X)%s"
1033 (not (eq name '->subsumptive))
1034 (not (eq name '->uppercase))
1035 (not (eq name '->lowercase))
1036 (not (eq name '->titlecase))
1037 (not (eq name '->canonical))
1038 (not (eq name '->Bopomofo))
1039 (not (eq name '->mistakable))
1040 (not (eq name '->ideographic-variants))
1041 (null (get-char-attribute
1042 char (intern (format "%s*sources" name))))
1043 (not (string-match "\\*sources$" (symbol-name name)))
1044 (null (get-char-attribute
1045 char (intern (format "%s*note" name))))
1046 (not (string-match "\\*note$" (symbol-name name)))
1047 (or (eq name '<-identical)
1048 (eq name '<-uppercase)
1049 (eq name '<-lowercase)
1050 (eq name '<-titlecase)
1051 (eq name '<-canonical)
1052 (eq name '<-ideographic-variants)
1053 ;; (eq name '<-synonyms)
1054 (string-match "^<-synonyms" (symbol-name name))
1055 (eq name '<-mistakable)
1056 (when (string-match "^->" (symbol-name name))
1058 ((string-match "^->fullwidth" (symbol-name name))
1059 (not (and (consp value)
1060 (characterp (car value))
1062 (car value) '=ucs 'defined-only)))
1067 ((or (eq name 'ideographic-structure)
1068 (eq name 'ideographic-combination)
1069 (eq name 'ideographic-)
1070 (eq name '=decomposition)
1071 (string-match "^=>decomposition" (symbol-name name))
1072 (string-match "^\\(->\\|<-\\)[^*]*$" (symbol-name name))
1073 (string-match "^\\(->\\|<-\\)[^*]*\\*sources$"
1076 (char-db-insert-relation-feature char name value
1079 ((memq name '(ideograph=
1080 original-ideograph-of
1081 ancient-ideograph-of
1084 ;; simplified-ideograph-of
1085 ideographic-variants
1086 ;; ideographic-different-form-of
1088 (insert (format "(%-18s%s " name line-breaking))
1089 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1091 (while (consp value)
1092 (setq cell (car value))
1093 (if (and (consp cell)
1098 (char-db-insert-alist cell readable)
1099 (setq separator lbs))
1102 (insert (prin1-to-string cell))
1103 (setq separator " "))
1104 (setq value (cdr value)))
1106 (insert line-breaking))
1108 (insert (format "(%-18s " name))
1109 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1111 (while (consp value)
1112 (setq cell (car value))
1113 (if (and (consp cell)
1115 (setq ret (condition-case nil
1123 (setq key (car (car rest)))
1124 (if (find-charset key)
1125 (setq cal (cons key cal))
1126 (setq al (cons key al)))
1127 (setq rest (cdr rest)))
1130 (insert-char-attributes ret
1133 (setq separator lbs))
1134 (setq ret (prin1-to-string cell))
1136 (if (< (+ (current-column)
1143 (setq separator " "))
1144 (setq value (cdr value)))
1146 (insert line-breaking))
1148 (insert (format "(%-18s" name))
1149 (setq ret (prin1-to-string value))
1150 (unless (< (+ (current-column)
1154 (insert line-breaking))
1155 (insert " . " ret ")" line-breaking)
1156 ;; (insert (format "(%-18s . %S)%s"
1161 (setq attributes (cdr attributes)))
1164 (defun insert-char-data (char &optional readable
1167 (narrow-to-region (point)(point))
1168 (insert "(define-char
1170 (insert-char-attributes char readable attributes)
1172 (goto-char (point-min))
1173 (while (re-search-forward "[ \t]+$" nil t)
1176 (goto-char (point-min))
1177 (while (re-search-forward "[ \t][ \t][ \t]*" nil t)
1178 (let ((column (current-column))
1179 (indent-tabs-mode t))
1180 (delete-region (match-beginning 0) (point))
1181 (indent-to column)))
1182 (goto-char (point-max))
1183 ;; (tabify (point-min)(point-max))
1186 (defun insert-char-data-with-variant (char &optional printable
1188 script excluded-script)
1189 (insert-char-data char printable)
1190 (let ((variants (char-variants char))
1193 (setq variants (sort variants #'<))
1194 (setq rest variants)
1195 (setq variants (cons char variants))
1197 (setq variant (car rest))
1198 (unless (get-char-attribute variant '<-subsumptive)
1199 (if (and (or (null script)
1200 (null (setq vs (get-char-attribute variant 'script)))
1202 (or (null excluded-script)
1203 (null (setq vs (get-char-attribute variant 'script)))
1204 (not (memq excluded-script vs))))
1205 (unless (and no-ucs-unified (get-char-attribute variant '=ucs))
1206 (insert-char-data variant printable)
1207 (if (setq ret (char-variants variant))
1209 (or (memq (car ret) variants)
1210 ;; (get-char-attribute (car ret) '<-subsumptive)
1211 (setq rest (nconc rest (list (car ret)))))
1212 (setq ret (cdr ret)))))))
1213 (setq rest (cdr rest)))))
1215 (defun insert-char-range-data (min max &optional script excluded-script)
1218 (while (<= code max)
1219 (setq char (decode-char '=ucs code))
1220 (if (encode-char char '=ucs 'defined-only)
1221 (insert-char-data-with-variant char nil 'no-ucs-unified
1222 script excluded-script))
1223 (setq code (1+ code)))))
1225 (defun write-char-range-data-to-file (min max file
1226 &optional script excluded-script)
1227 (let ((coding-system-for-write char-db-file-coding-system))
1229 (insert (format ";; -*- coding: %s -*-\n"
1230 char-db-file-coding-system))
1231 (insert-char-range-data min max script excluded-script)
1232 (write-region (point-min)(point-max) file))))
1234 (defvar what-character-original-window-configuration)
1237 (defun what-char-definition (char)
1238 (interactive (list (char-after)))
1239 (let ((buf (get-buffer-create "*Character Description*"))
1240 (the-buf (current-buffer))
1241 (win-conf (current-window-configuration)))
1243 (make-local-variable 'what-character-original-window-configuration)
1244 (setq what-character-original-window-configuration win-conf)
1245 (setq buffer-read-only nil)
1249 (insert-char-data-with-variant char 'printable)
1250 (unless (char-attribute-alist char)
1251 (insert (format ";; = %c\n"
1252 (let* ((rest (split-char char))
1256 (setq code (logior (lsh code 8)
1258 (decode-char ccs code)))))
1259 ;; (char-db-update-comment)
1260 (set-buffer-modified-p nil)
1261 (view-mode the-buf (lambda (buf)
1262 (set-window-configuration
1263 what-character-original-window-configuration)
1265 (goto-char (point-min)))
1267 (set-window-configuration
1268 what-character-original-window-configuration)
1269 (signal (car err) (cdr err)))))))
1275 (provide 'char-db-util)
1277 ;;; char-db-util.el ends here