+(defvar char-db-coded-charset-priority-list
+ '(ascii
+ control-1
+ latin-iso8859-1
+ latin-iso8859-2
+ latin-iso8859-3
+ latin-iso8859-4
+ latin-iso8859-9
+ latin-jisx0201
+ cyrillic-iso8859-5
+ greek-iso8859-7
+ thai-tis620
+ =jis-x0208
+ japanese-jisx0208
+ japanese-jisx0212
+ japanese-jisx0208-1978
+ chinese-gb2312
+ =cns11643-1
+ chinese-cns11643-2
+ chinese-cns11643-3
+ chinese-cns11643-4
+ chinese-cns11643-5
+ chinese-cns11643-6
+ chinese-cns11643-7
+ =jis-x0208-1990
+ =jis-x0213-1-2000
+ =jis-x0213-2-2000
+ korean-ksc5601
+ chinese-isoir165
+ katakana-jisx0201
+ hebrew-iso8859-8
+ chinese-gb12345
+ latin-viscii
+ ethiopic-ucs
+ =gt
+ ideograph-daikanwa-2
+ ideograph-daikanwa
+ =cbeta
+ ideograph-hanziku-1
+ ideograph-hanziku-2
+ ideograph-hanziku-3
+ ideograph-hanziku-4
+ ideograph-hanziku-5
+ ideograph-hanziku-6
+ ideograph-hanziku-7
+ ideograph-hanziku-8
+ ideograph-hanziku-9
+ ideograph-hanziku-10
+ ideograph-hanziku-11
+ ideograph-hanziku-12
+ =big5
+ =big5-eten
+ =big5-cdp
+ =gt-k
+ =jef-china3))
+
+(defun char-db-make-char-spec (char)
+ (let (ret char-spec)
+ (cond ((characterp char)
+ (cond ((and (setq ret (encode-char char '=ucs 'defined-only))
+ (not (and (<= #xE000 ret)(<= ret #xF8FF))))
+ (setq char-spec (list (cons '=ucs ret)))
+ (cond ((setq ret (get-char-attribute char 'name))
+ (setq char-spec (cons (cons 'name ret) char-spec))
+ )
+ ((setq ret (get-char-attribute char 'name*))
+ (setq char-spec (cons (cons 'name* ret) char-spec))
+ ))
+ )
+ ((setq ret
+ (catch 'tag
+ (let ((rest char-db-coded-charset-priority-list)
+ ccs)
+ (while rest
+ (setq ccs (charset-name
+ (find-charset (car rest))))
+ (if (setq ret
+ (encode-char char ccs
+ 'defined-only))
+ (throw 'tag (cons ccs ret)))
+ (setq rest (cdr rest))))))
+ (setq char-spec (list ret))
+ (dolist (ccs (delq (car ret) (charset-list)))
+ (if (and (or (charset-iso-final-char ccs)
+ (memq ccs
+ '(ideograph-daikanwa
+ =daikanwa-rev2
+ ;; =gt-k
+ )))
+ (setq ret (encode-char char ccs 'defined-only)))
+ (setq char-spec (cons (cons ccs ret) char-spec))))
+ (if (null char-spec)
+ (setq char-spec (split-char char)))
+ (cond ((setq ret (get-char-attribute char 'name))
+ (setq char-spec (cons (cons 'name ret) char-spec))
+ )
+ ((setq ret (get-char-attribute char 'name*))
+ (setq char-spec (cons (cons 'name* ret) char-spec))
+ ))
+ ))
+ char-spec)
+ ((consp char)
+ char))))
+
+(defun char-db-insert-char-spec (char &optional readable column)
+ (unless column
+ (setq column (current-column)))
+ (let (char-spec ret al cal key temp-char)
+ (setq char-spec (char-db-make-char-spec char))
+ (unless (or (characterp char) ; char
+ (condition-case nil
+ (setq char (find-char char-spec))
+ (error nil)))
+ ;; define temporary character
+ ;; Current implementation is dirty.
+ (setq temp-char (define-char (cons '(ideograph-daikanwa . 0)
+ char-spec)))
+ (remove-char-attribute temp-char 'ideograph-daikanwa)
+ (setq char temp-char))
+ (setq al nil
+ cal nil)
+ (while char-spec
+ (setq key (car (car char-spec)))
+ (unless (memq key char-db-ignored-attributes)
+ (if (find-charset key)
+ (if (encode-char char key 'defined-only)
+ (setq cal (cons key cal)))
+ (setq al (cons key al))))
+ (setq char-spec (cdr char-spec)))
+ (unless cal
+ (setq char-spec (char-db-make-char-spec char))
+ (while char-spec
+ (setq key (car (car char-spec)))
+ (unless (memq key char-db-ignored-attributes)
+ (if (find-charset key)
+ (setq cal (cons key cal))
+ (setq al (cons key al))))
+ (setq char-spec (cdr char-spec)))
+ )
+ (unless (or cal
+ (memq 'ideographic-structure al))
+ (push 'ideographic-structure al))
+ (insert-char-attributes char
+ readable
+ (or al 'none) cal)
+ (when temp-char
+ ;; undefine temporary character
+ ;; Current implementation is dirty.
+ (setq char-spec (char-attribute-alist temp-char))
+ (while char-spec
+ (remove-char-attribute temp-char (car (car char-spec)))
+ (setq char-spec (cdr char-spec))))))
+