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, 2011 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
225 ;;; @ char-db formatters
228 (defun char-db-make-char-spec (char)
230 (cond ((characterp char)
231 (cond ((and (setq ret (encode-char char '=ucs 'defined-only))
232 (not (and (<= #xE000 ret)(<= ret #xF8FF))))
233 (setq char-spec (list (cons '=ucs ret)))
234 (cond ((setq ret (get-char-attribute char 'name))
235 (setq char-spec (cons (cons 'name ret) char-spec))
237 ((setq ret (get-char-attribute char 'name*))
238 (setq char-spec (cons (cons 'name* ret) char-spec))
243 (let ((rest char-db-coded-charset-priority-list)
246 (setq ccs (charset-name
247 (find-charset (car rest))))
249 (encode-char char ccs
251 (throw 'tag (cons ccs ret)))
252 (setq rest (cdr rest))))))
253 (setq char-spec (list ret))
254 (dolist (ccs (delq (car ret) (charset-list)))
255 (if (and (or (charset-iso-final-char ccs)
262 (string-match "=ucs@" (symbol-name ccs)))
263 (setq ccs (charset-name ccs))
264 (null (assq ccs char-spec))
265 (setq ret (encode-char char ccs 'defined-only)))
266 (setq char-spec (cons (cons ccs ret) char-spec))))
268 (setq char-spec (split-char char)))
269 (cond ((setq ret (get-char-attribute char 'name))
270 (setq char-spec (cons (cons 'name ret) char-spec))
272 ((setq ret (get-char-attribute char 'name*))
273 (setq char-spec (cons (cons 'name* ret) char-spec))
276 ((setq ret (get-char-attribute
277 char 'ideographic-combination))
279 (cons (cons 'ideographic-combination ret)
286 (defun char-db-insert-char-spec (char &optional readable column
289 (setq column (current-column)))
290 (let (char-spec temp-char)
291 (setq char-spec (char-db-make-char-spec char))
292 (unless (or (characterp char) ; char
294 (setq char (find-char char-spec))
296 ;; define temporary character
297 ;; Current implementation is dirty.
298 (setq temp-char (define-char (cons '(ideograph-daikanwa . 0)
300 (remove-char-attribute temp-char 'ideograph-daikanwa)
301 (setq char temp-char))
302 (insert-char-attributes char
304 (union (mapcar #'car char-spec)
307 ;; undefine temporary character
308 ;; Current implementation is dirty.
309 (setq char-spec (char-attribute-alist temp-char))
311 (remove-char-attribute temp-char (car (car char-spec)))
312 (setq char-spec (cdr char-spec))))))
314 (defun char-db-insert-alist (alist &optional readable column)
316 (setq column (current-column)))
318 (concat "\n" (make-string (1+ column) ?\ )))
322 lbs cell rest separator)
325 (setq name (car (car alist))
326 value (cdr (car alist)))
327 (cond ((eq name 'char)
329 (if (setq ret (condition-case nil
337 (setq key (car (car value)))
338 ;; (if (find-charset key)
339 ;; (setq cal (cons key cal))
340 (setq al (cons key al))
342 (setq value (cdr value)))
343 (insert-char-attributes ret
347 (insert (prin1-to-string value)))
349 (insert line-breaking))
351 (insert (format "(%-18s " name))
352 (setq lbs (concat "\n" (make-string (current-column) ?\ )))
354 (setq cell (car value))
355 (if (and (consp cell)
357 (setq ret (condition-case nil
367 (setq key (car (car rest)))
368 ;; (if (find-charset key)
369 ;; (setq cal (cons key cal))
370 (setq al (cons key al))
372 (setq rest (cdr rest)))
375 (insert-char-attributes ret
379 (setq separator lbs))
382 (insert (prin1-to-string cell))
383 (setq separator " "))
384 (setq value (cdr value)))
386 (insert line-breaking))
388 (insert (format "(%-18s . %S)%s"
391 (setq alist (cdr alist))))
394 (defun char-db-insert-char-reference (plist &optional readable column)
396 (setq column (current-column)))
398 (concat "\n" (make-string (1+ column) ?\ )))
403 (setq name (pop plist))
404 (setq value (pop plist))
405 (cond ((eq name :char)
408 (cond ((numberp value)
409 (setq value (decode-char '=ucs value)))
411 ;; (setq value (or (find-char value)
414 (char-db-insert-char-spec value readable)
415 (insert line-breaking)
418 (insert (format "%s%s\t%d ; %c%s"
421 (ideographic-radical value)
425 (insert (format "%s%s\t%S" separator name value))
426 (setq separator line-breaking)))
430 (defun char-db-decode-isolated-char (ccs code-point)
433 (cond ((eq ccs 'arabic-iso8859-6)
434 (decode-char ccs code-point))
435 ((and (memq ccs '(=gt-pj-1
446 (setq ret (decode-char ccs code-point))
447 (setq ret (encode-char ret '=gt 'defined-only)))
448 (decode-builtin-char '=gt ret))
450 (decode-builtin-char ccs code-point))))
451 (cond ((and (<= 0 (char-int ret))
452 (<= (char-int ret) #x1F))
453 (decode-char '=ucs (+ #x2400 (char-int ret))))
454 ((= (char-int ret) #x7F)
458 (defvar char-db-convert-obsolete-format t)
460 (defun char-db-insert-ccs-feature (name value line-breaking)
463 (cond ((memq name '(=shinjigen
465 =shinjigen@rev =shinjigen/+p@rev
467 "(%-18s . %04d)\t; %c")
468 ((eq name '=shinjigen@1ed/24pr)
469 "(%-18s . %04d)\t; %c")
470 ((or (memq name '(=daikanwa =>>daikanwa =>daikanwa
471 =daikanwa@rev1 =daikanwa@rev2
472 =daikanwa/+p =daikanwa/+2p
473 =gt =>>>gt =>>gt =>gt
476 =cbeta =zinbun-oracle =>zinbun-oracle))
477 (string-match "^=adobe-" (symbol-name name)))
478 "(%-18s . %05d)\t; %c")
479 ((memq name '(=hanyo-denshi/ks =>>hanyo-denshi/ks mojikyo))
480 "(%-18s . %06d)\t; %c")
481 ((>= (charset-dimension name) 2)
482 "(%-18s . #x%04X)\t; %c")
484 "(%-18s . #x%02X)\t; %c"))
486 (if (= (charset-iso-graphic-plane name) 1)
488 (cond ((= (charset-dimension name) 1)
490 ((= (charset-dimension name) 2)
492 ((= (charset-dimension name) 3)
496 (char-db-decode-isolated-char name value)))
497 (if (and (= (charset-chars name) 94)
498 (= (charset-dimension name) 2))
499 (insert (format " [%02d-%02d]"
500 (- (lsh value -8) 32)
501 (- (logand value 255) 32))))
502 (insert line-breaking))
504 (defun char-db-insert-relation-feature (char name value line-breaking
506 (insert (format "(%-18s%s " name line-breaking))
507 (let ((lbs (concat "\n" (make-string (current-column) ?\ )))
508 separator cell sources required-features
511 (setq cell (car value))
513 (setq cell (decode-char '=ucs cell)))
515 ((eq name '->subsumptive)
516 (when (or (not (some (lambda (atr)
517 (get-char-attribute cell atr))
518 char-db-ignored-attributes))
520 (encode-char cell ccs 'defined-only))
524 (let ((char-db-ignored-attributes
526 char-db-ignored-attributes)))
527 (insert-char-attributes cell readable))
528 (setq separator lbs))
533 char (intern (format "%s*sources" name))))
534 (setq required-features nil)
535 (dolist (source sources)
539 shinjigen shinjigen@1ed shinjigen@rev))
540 (setq required-features
541 (union required-features
552 (setq required-features
553 (union required-features
558 ((find-charset (setq ret (intern (format "=%s" source))))
559 (setq required-features
560 (cons ret required-features)))
561 (t (setq required-features
562 (cons source required-features)))))
563 (cond ((string-match "@JP" (symbol-name name))
564 (setq required-features
565 (union required-features
573 ((string-match "@CN" (symbol-name name))
574 (setq required-features
575 (union required-features
582 (insert (format "%S" cell))
583 (char-db-insert-char-spec cell readable
586 (setq separator lbs))
590 (if (consp (car cell))
591 (char-db-insert-char-spec cell readable)
592 (char-db-insert-char-reference cell readable))
593 (setq separator lbs))
597 (insert (prin1-to-string cell))
598 (setq separator " ")))
599 (setq value (cdr value)))
601 (insert line-breaking)))
603 (defun insert-char-attributes (char &optional readable attributes column)
605 (setq column (current-column)))
606 (let (name value ; has-long-ccs-name
610 (concat "\n" (make-string (1+ column) ?\ )))
611 lbs cell separator ret
613 dest-ccss ; sources required-features
618 (if (consp attributes)
620 (dolist (name attributes)
621 (unless (memq name char-db-ignored-attributes)
622 (if (find-charset name)
626 (dolist (name (char-attribute-list))
627 (unless (memq name char-db-ignored-attributes)
628 (if (find-charset name)
632 #'char-attribute-name<)))
634 (when (memq '<-subsumptive attributes)
636 (when (setq value (get-char-attribute char '<-subsumptive))
637 (char-db-insert-relation-feature char '<-subsumptive value
640 (setq attributes (delq '<-subsumptive attributes)))
641 (when (and (memq '<-denotational attributes)
642 (setq value (get-char-attribute char '<-denotational)))
643 (char-db-insert-relation-feature char '<-denotational value
646 (setq attributes (delq '<-denotational attributes)))
647 (when (and (memq 'name attributes)
648 (setq value (get-char-attribute char 'name)))
650 (if (> (+ (current-column) (length value)) 48)
653 value line-breaking))
654 (setq attributes (delq 'name attributes))
656 (when (and (memq 'name* attributes)
657 (setq value (get-char-attribute char 'name*)))
659 (if (> (+ (current-column) (length value)) 48)
662 value line-breaking))
663 (setq attributes (delq 'name* attributes))
665 (when (and (memq 'script attributes)
666 (setq value (get-char-attribute char 'script)))
667 (insert (format "(script\t\t%s)%s"
668 (mapconcat (function prin1-to-string)
671 (setq attributes (delq 'script attributes))
673 (dolist (name '(=>ucs =>ucs*))
674 (when (and (memq name attributes)
675 (setq value (get-char-attribute char name)))
676 (insert (format "(%-18s . #x%04X)\t; %c%s"
677 name value (decode-char '=ucs value)
679 (setq attributes (delq name attributes))))
680 (dolist (name '(=>ucs@gb =>ucs@big5))
681 (when (and (memq name attributes)
682 (setq value (get-char-attribute char name)))
683 (insert (format "(%-18s . #x%04X)\t; %c%s"
688 (symbol-name name) 2)))
691 (setq attributes (delq name attributes))
693 ;; (dolist (name '(=>daikanwa))
694 ;; (when (and (memq name attributes)
695 ;; (setq value (get-char-attribute char name)))
697 ;; (if (integerp value)
698 ;; (format "(%-18s . %05d)\t; %c%s"
699 ;; name value (decode-char '=daikanwa value)
701 ;; (format "(%-18s %s)\t; %c%s"
703 ;; (mapconcat (function prin1-to-string)
705 ;; (char-representative-of-daikanwa char)
707 ;; (setq attributes (delq name attributes))))
708 (when (and (memq 'general-category attributes)
709 (setq value (get-char-attribute char 'general-category)))
711 "(general-category\t%s) ; %s%s"
712 (mapconcat (lambda (cell)
715 (cond ((rassoc value unidata-normative-category-alist)
716 "Normative Category")
717 ((rassoc value unidata-informative-category-alist)
718 "Informative Category")
722 (setq attributes (delq 'general-category attributes))
724 (when (and (memq 'bidi-category attributes)
725 (setq value (get-char-attribute char 'bidi-category)))
726 (insert (format "(bidi-category\t. %S)%s"
729 (setq attributes (delq 'bidi-category attributes))
731 (unless (or (not (memq 'mirrored attributes))
732 (eq (setq value (get-char-attribute char 'mirrored 'empty))
734 (insert (format "(mirrored\t\t. %S)%s"
737 (setq attributes (delq 'mirrored attributes))
740 ((and (memq 'decimal-digit-value attributes)
741 (setq value (get-char-attribute char 'decimal-digit-value)))
742 (insert (format "(decimal-digit-value . %S)%s"
745 (setq attributes (delq 'decimal-digit-value attributes))
746 (when (and (memq 'digit-value attributes)
747 (setq value (get-char-attribute char 'digit-value)))
748 (insert (format "(digit-value\t . %S)%s"
751 (setq attributes (delq 'digit-value attributes))
753 (when (and (memq 'numeric-value attributes)
754 (setq value (get-char-attribute char 'numeric-value)))
755 (insert (format "(numeric-value\t . %S)%s"
758 (setq attributes (delq 'numeric-value attributes))
762 (when (and (memq 'digit-value attributes)
763 (setq value (get-char-attribute char 'digit-value)))
764 (insert (format "(digit-value\t. %S)%s"
767 (setq attributes (delq 'digit-value attributes))
769 (when (and (memq 'numeric-value attributes)
770 (setq value (get-char-attribute char 'numeric-value)))
771 (insert (format "(numeric-value\t. %S)%s"
774 (setq attributes (delq 'numeric-value attributes))
776 (when (and (memq 'iso-10646-comment attributes)
777 (setq value (get-char-attribute char 'iso-10646-comment)))
778 (insert (format "(iso-10646-comment\t. %S)%s"
781 (setq attributes (delq 'iso-10646-comment attributes))
783 (when (and (memq 'morohashi-daikanwa attributes)
784 (setq value (get-char-attribute char 'morohashi-daikanwa)))
785 (insert (format "(morohashi-daikanwa\t%s)%s"
786 (mapconcat (function prin1-to-string) value " ")
788 (setq attributes (delq 'morohashi-daikanwa attributes))
792 (when (and (memq 'ideographic-radical attributes)
793 (setq value (get-char-attribute char 'ideographic-radical)))
795 (insert (format "(ideographic-radical . %S)\t; %c%s"
797 (ideographic-radical radical)
799 (setq attributes (delq 'ideographic-radical attributes))
801 (when (and (memq 'shuowen-radical attributes)
802 (setq value (get-char-attribute char 'shuowen-radical)))
803 (insert (format "(shuowen-radical\t. %S)\t; %c%s"
805 (shuowen-radical value)
807 (setq attributes (delq 'shuowen-radical attributes))
812 char-db-feature-domains
814 (dolist (feature (char-attribute-list))
815 (setq feature (symbol-name feature))
817 "\\(radical\\|strokes\\)@\\([^@*]+\\)\\(\\*\\|$\\)"
819 (setq domain (intern (match-string 2 feature)))
820 (unless (memq domain dest)
821 (setq dest (cons domain dest)))))
822 (sort dest #'string<))))
823 (setq key (intern (format "%s@%s" 'ideographic-radical domain)))
824 (when (and (memq key attributes)
825 (setq value (get-char-attribute char key)))
827 (insert (format "(%s . %S)\t; %c%s"
830 (ideographic-radical radical)
832 (setq attributes (delq key attributes))
834 (setq key (intern (format "%s@%s" 'ideographic-strokes domain)))
835 (when (and (memq key attributes)
836 (setq value (get-char-attribute char key)))
838 (insert (format "(%s . %S)%s"
842 (setq attributes (delq key attributes))
844 (setq key (intern (format "%s@%s" 'total-strokes domain)))
845 (when (and (memq key attributes)
846 (setq value (get-char-attribute char key)))
847 (insert (format "(%s . %S)%s"
851 (setq attributes (delq key attributes))
853 (dolist (feature '(ideographic-radical
856 (setq key (intern (format "%s@%s*sources" feature domain)))
857 (when (and (memq key attributes)
858 (setq value (get-char-attribute char key)))
859 (insert (format "(%s%s" key line-breaking))
861 (insert (format " %s" cell)))
863 (insert line-breaking)
864 (setq attributes (delq key attributes))
867 (when (and (memq 'ideographic-strokes attributes)
868 (setq value (get-char-attribute char 'ideographic-strokes)))
870 (insert (format "(ideographic-strokes . %S)%s"
873 (setq attributes (delq 'ideographic-strokes attributes))
875 (when (and (memq 'kangxi-radical attributes)
876 (setq value (get-char-attribute char 'kangxi-radical)))
877 (unless (eq value radical)
878 (insert (format "(kangxi-radical\t . %S)\t; %c%s"
880 (ideographic-radical value)
883 (setq radical value)))
884 (setq attributes (delq 'kangxi-radical attributes))
886 (when (and (memq 'kangxi-strokes attributes)
887 (setq value (get-char-attribute char 'kangxi-strokes)))
888 (unless (eq value strokes)
889 (insert (format "(kangxi-strokes\t . %S)%s"
893 (setq strokes value)))
894 (setq attributes (delq 'kangxi-strokes attributes))
896 (when (and (memq 'japanese-radical attributes)
897 (setq value (get-char-attribute char 'japanese-radical)))
898 (unless (eq value radical)
899 (insert (format "(japanese-radical\t . %S)\t; %c%s"
901 (ideographic-radical value)
904 (setq radical value)))
905 (setq attributes (delq 'japanese-radical attributes))
907 (when (and (memq 'japanese-strokes attributes)
908 (setq value (get-char-attribute char 'japanese-strokes)))
909 (unless (eq value strokes)
910 (insert (format "(japanese-strokes\t . %S)%s"
914 (setq strokes value)))
915 (setq attributes (delq 'japanese-strokes attributes))
917 (when (and (memq 'cns-radical attributes)
918 (setq value (get-char-attribute char 'cns-radical)))
919 (insert (format "(cns-radical\t . %S)\t; %c%s"
921 (ideographic-radical value)
923 (setq attributes (delq 'cns-radical attributes))
925 (when (and (memq 'cns-strokes attributes)
926 (setq value (get-char-attribute char 'cns-strokes)))
927 (unless (eq value strokes)
928 (insert (format "(cns-strokes\t . %S)%s"
932 (setq strokes value)))
933 (setq attributes (delq 'cns-strokes attributes))
935 (when (and (memq 'shinjigen-1-radical attributes)
936 (setq value (get-char-attribute char 'shinjigen-1-radical)))
937 (unless (eq value radical)
938 (insert (format "(shinjigen-1-radical . %S)\t; %c%s"
940 (ideographic-radical value)
943 (setq radical value)))
944 (setq attributes (delq 'shinjigen-1-radical attributes))
946 (when (and (memq 'ideographic- attributes)
947 (setq value (get-char-attribute char 'ideographic-)))
948 (insert "(ideographic- ")
949 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
952 (setq cell (car value))
954 (setq cell (decode-char '=ucs cell)))
955 (cond ((characterp cell)
959 (insert (format "%S" cell))
960 (char-db-insert-char-spec cell readable))
961 (setq separator lbs))
965 (if (consp (car cell))
966 (char-db-insert-char-spec cell readable)
967 (char-db-insert-char-reference cell readable))
968 (setq separator lbs))
972 (insert (prin1-to-string cell))
973 (setq separator " ")))
974 (setq value (cdr value)))
976 (insert line-breaking)
977 (setq attributes (delq 'ideographic- attributes)))
978 (when (and (memq 'total-strokes attributes)
979 (setq value (get-char-attribute char 'total-strokes)))
980 (insert (format "(total-strokes . %S)%s"
983 (setq attributes (delq 'total-strokes attributes))
985 (when (and (memq '->ideograph attributes)
986 (setq value (get-char-attribute char '->ideograph)))
987 (insert (format "(->ideograph\t%s)%s"
988 (mapconcat (lambda (code)
989 (cond ((symbolp code)
992 (format "#x%04X" code))
995 line-breaking code))))
998 (setq attributes (delq '->ideograph attributes))
1000 ;; (when (and (memq '->decomposition attributes)
1001 ;; (setq value (get-char-attribute char '->decomposition)))
1002 ;; (insert (format "(->decomposition\t%s)%s"
1003 ;; (mapconcat (lambda (code)
1004 ;; (cond ((symbolp code)
1005 ;; (symbol-name code))
1006 ;; ((characterp code)
1008 ;; (format "%S" code)
1013 ;; (format "#x%04X" code))
1015 ;; (format "%s%S" line-breaking code))))
1018 ;; (setq attributes (delq '->decomposition attributes))
1020 (if (equal (get-char-attribute char '->titlecase)
1021 (get-char-attribute char '->uppercase))
1022 (setq attributes (delq '->titlecase attributes)))
1023 (when (and (memq '->mojikyo attributes)
1024 (setq value (get-char-attribute char '->mojikyo)))
1025 (insert (format "(->mojikyo\t\t. %06d)\t; %c%s"
1026 value (decode-char 'mojikyo value)
1028 (setq attributes (delq '->mojikyo attributes))
1030 (when (and (memq 'hanyu-dazidian-vol attributes)
1031 (setq value (get-char-attribute char 'hanyu-dazidian-vol)))
1032 (insert (format "(hanyu-dazidian-vol . %d)%s"
1033 value line-breaking))
1034 (setq attributes (delq 'hanyu-dazidian-vol attributes))
1036 (when (and (memq 'hanyu-dazidian-page attributes)
1037 (setq value (get-char-attribute char 'hanyu-dazidian-page)))
1038 (insert (format "(hanyu-dazidian-page . %d)%s"
1039 value line-breaking))
1040 (setq attributes (delq 'hanyu-dazidian-page attributes))
1042 (when (and (memq 'hanyu-dazidian-char attributes)
1043 (setq value (get-char-attribute char 'hanyu-dazidian-char)))
1044 (insert (format "(hanyu-dazidian-char . %d)%s"
1045 value line-breaking))
1046 (setq attributes (delq 'hanyu-dazidian-char attributes))
1049 (dolist (ignored '(composition
1050 ->denotational <-subsumptive ->ucs-unified
1051 ->ideographic-component-forms))
1052 (setq attributes (delq ignored attributes))))
1054 (setq name (car attributes))
1055 (if (setq value (get-char-attribute char name))
1056 (cond ((setq ret (find-charset name))
1057 (setq name (charset-name ret))
1058 (if (and (not (memq name dest-ccss))
1060 (setq value (get-char-attribute char name))
1061 (setq dest-ccss (cons name dest-ccss))))
1062 (char-db-insert-ccs-feature name value line-breaking))
1064 ((string-match "^=>ucs@" (symbol-name name))
1065 (insert (format "(%-18s . #x%04X)\t; %c%s"
1066 name value (decode-char '=ucs value)
1069 ((eq name 'jisx0208-1978/4X)
1070 (insert (format "(%-18s . #x%04X)%s"
1076 (not (eq name '->subsumptive))
1077 (not (eq name '->uppercase))
1078 (not (eq name '->lowercase))
1079 (not (eq name '->titlecase))
1080 (not (eq name '->canonical))
1081 (not (eq name '->Bopomofo))
1082 (not (eq name '->mistakable))
1083 (not (eq name '->ideographic-variants))
1084 (null (get-char-attribute
1085 char (intern (format "%s*sources" name))))
1086 (not (string-match "\\*sources$" (symbol-name name)))
1087 (null (get-char-attribute
1088 char (intern (format "%s*note" name))))
1089 (not (string-match "\\*note$" (symbol-name name)))
1090 (or (eq name '<-identical)
1091 (eq name '<-uppercase)
1092 (eq name '<-lowercase)
1093 (eq name '<-titlecase)
1094 (eq name '<-canonical)
1095 (eq name '<-ideographic-variants)
1096 ;; (eq name '<-synonyms)
1097 (string-match "^<-synonyms" (symbol-name name))
1098 (eq name '<-mistakable)
1099 (when (string-match "^->" (symbol-name name))
1101 ((string-match "^->fullwidth" (symbol-name name))
1102 (not (and (consp value)
1103 (characterp (car value))
1105 (car value) '=ucs 'defined-only)))
1110 ((or (eq name 'ideographic-structure)
1111 (eq name 'ideographic-combination)
1112 (eq name 'ideographic-)
1113 (eq name '=decomposition)
1114 (char-feature-base-name= '=decomposition name)
1115 (char-feature-base-name= '=>decomposition name)
1116 ;; (string-match "^=>*decomposition\\(@[^*]+\\)?$"
1117 ;; (symbol-name name))
1118 (string-match "^\\(->\\|<-\\)[^*]*$" (symbol-name name))
1119 (string-match "^\\(->\\|<-\\)[^*]*\\*sources$"
1122 (char-db-insert-relation-feature char name value
1125 ((memq name '(ideograph=
1126 original-ideograph-of
1127 ancient-ideograph-of
1130 ;; simplified-ideograph-of
1131 ideographic-variants
1132 ;; ideographic-different-form-of
1134 (insert (format "(%-18s%s " name line-breaking))
1135 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1137 (while (consp value)
1138 (setq cell (car value))
1139 (if (and (consp cell)
1144 (char-db-insert-alist cell readable)
1145 (setq separator lbs))
1148 (insert (prin1-to-string cell))
1149 (setq separator " "))
1150 (setq value (cdr value)))
1152 (insert line-breaking))
1154 (insert (format "(%-18s " name))
1155 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1157 (while (consp value)
1158 (setq cell (car value))
1159 (if (and (consp cell)
1161 (setq ret (condition-case nil
1169 (setq key (car (car rest)))
1170 (if (find-charset key)
1171 (setq cal (cons key cal))
1172 (setq al (cons key al)))
1173 (setq rest (cdr rest)))
1176 (insert-char-attributes ret
1179 (setq separator lbs))
1180 (setq ret (prin1-to-string cell))
1182 (if (< (+ (current-column)
1189 (setq separator " "))
1190 (setq value (cdr value)))
1192 (insert line-breaking))
1194 (insert (format "(%-18s" name))
1195 (setq ret (prin1-to-string value))
1196 (unless (< (+ (current-column)
1200 (insert line-breaking))
1201 (insert " . " ret ")" line-breaking)
1202 ;; (insert (format "(%-18s . %S)%s"
1207 (setq attributes (cdr attributes)))
1210 (defun insert-char-data (char &optional readable
1213 (narrow-to-region (point)(point))
1214 (insert "(define-char
1216 (insert-char-attributes char readable attributes)
1218 (goto-char (point-min))
1219 (while (re-search-forward "[ \t]+$" nil t)
1222 (goto-char (point-min))
1223 (while (re-search-forward "[ \t][ \t][ \t]*" nil t)
1224 (let ((column (current-column))
1225 (indent-tabs-mode t))
1226 (delete-region (match-beginning 0) (point))
1227 (indent-to column)))
1228 (goto-char (point-max))
1229 ;; (tabify (point-min)(point-max))
1232 (defun insert-char-data-with-variant (char &optional printable
1234 script excluded-script)
1235 (insert-char-data char printable)
1236 (let ((variants (char-variants char))
1239 (setq variants (sort variants #'<))
1240 (setq rest variants)
1241 (setq variants (cons char variants))
1243 (setq variant (car rest))
1244 (unless (get-char-attribute variant '<-subsumptive)
1245 (if (and (or (null script)
1246 (null (setq vs (get-char-attribute variant 'script)))
1248 (or (null excluded-script)
1249 (null (setq vs (get-char-attribute variant 'script)))
1250 (not (memq excluded-script vs))))
1251 (unless (and no-ucs-unified (get-char-attribute variant '=ucs))
1252 (insert-char-data variant printable)
1253 (if (setq ret (char-variants variant))
1255 (or (memq (car ret) variants)
1256 ;; (get-char-attribute (car ret) '<-subsumptive)
1257 (setq rest (nconc rest (list (car ret)))))
1258 (setq ret (cdr ret)))))))
1259 (setq rest (cdr rest)))))
1261 (defun insert-char-range-data (min max &optional script excluded-script)
1264 (while (<= code max)
1265 (setq char (decode-char '=ucs code))
1266 (if (encode-char char '=ucs 'defined-only)
1267 (insert-char-data-with-variant char nil 'no-ucs-unified
1268 script excluded-script))
1269 (setq code (1+ code)))))
1271 (defun write-char-range-data-to-file (min max file
1272 &optional script excluded-script)
1273 (let ((coding-system-for-write char-db-file-coding-system))
1275 (insert (format ";; -*- coding: %s -*-\n"
1276 char-db-file-coding-system))
1277 (insert-char-range-data min max script excluded-script)
1278 (write-region (point-min)(point-max) file))))
1280 (defvar what-character-original-window-configuration)
1283 (defun what-char-definition (char)
1284 (interactive (list (char-after)))
1285 (let ((buf (get-buffer-create "*Character Description*"))
1286 (the-buf (current-buffer))
1287 (win-conf (current-window-configuration)))
1289 (make-local-variable 'what-character-original-window-configuration)
1290 (setq what-character-original-window-configuration win-conf)
1291 (setq buffer-read-only nil)
1295 (insert-char-data-with-variant char 'printable)
1296 (unless (char-attribute-alist char)
1297 (insert (format ";; = %c\n"
1298 (let* ((rest (split-char char))
1302 (setq code (logior (lsh code 8)
1304 (decode-char ccs code)))))
1305 ;; (char-db-update-comment)
1306 (set-buffer-modified-p nil)
1307 (view-mode the-buf (lambda (buf)
1308 (set-window-configuration
1309 what-character-original-window-configuration)
1311 (goto-char (point-min)))
1313 (set-window-configuration
1314 what-character-original-window-configuration)
1315 (signal (car err) (cdr err)))))))
1321 (provide 'char-db-util)
1323 ;;; char-db-util.el ends here