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
242 ;;; @ char-db formatters
245 (defun char-db-make-char-spec (char)
247 (cond ((characterp char)
248 (cond ((and (setq ret (encode-char char '=ucs 'defined-only))
249 (not (and (<= #xE000 ret)(<= ret #xF8FF))))
250 (setq char-spec (list (cons '=ucs ret)))
251 (cond ((setq ret (get-char-attribute char 'name))
252 (setq char-spec (cons (cons 'name ret) char-spec))
254 ((setq ret (get-char-attribute char 'name*))
255 (setq char-spec (cons (cons 'name* ret) char-spec))
260 (let ((rest char-db-coded-charset-priority-list)
263 (setq ccs (charset-name
264 (find-charset (car rest))))
266 (encode-char char ccs
268 (throw 'tag (cons ccs ret)))
269 (setq rest (cdr rest))))))
270 (setq char-spec (list ret))
271 (dolist (ccs (delq (car ret) (charset-list)))
272 (if (and (or (charset-iso-final-char ccs)
279 (string-match "=ucs@" (symbol-name ccs)))
280 (setq ccs (charset-name ccs))
281 (null (assq ccs char-spec))
282 (setq ret (encode-char char ccs 'defined-only)))
283 (setq char-spec (cons (cons ccs ret) char-spec))))
285 (setq char-spec (split-char char)))
286 (cond ((setq ret (get-char-attribute char 'name))
287 (setq char-spec (cons (cons 'name ret) char-spec))
289 ((setq ret (get-char-attribute char 'name*))
290 (setq char-spec (cons (cons 'name* ret) char-spec))
293 ((setq ret (get-char-attribute
294 char 'ideographic-combination))
296 (cons (cons 'ideographic-combination ret)
303 (defun char-db-insert-char-spec (char &optional readable column
306 (setq column (current-column)))
307 (let (char-spec temp-char)
308 (setq char-spec (char-db-make-char-spec char))
309 (unless (or (characterp char) ; char
311 (setq char (find-char char-spec))
313 ;; define temporary character
314 ;; Current implementation is dirty.
315 (setq temp-char (define-char (cons '(ideograph-daikanwa . 0)
317 (remove-char-attribute temp-char 'ideograph-daikanwa)
318 (setq char temp-char))
319 (insert-char-attributes char
321 (union (mapcar #'car char-spec)
325 ;; undefine temporary character
326 ;; Current implementation is dirty.
327 (setq char-spec (char-attribute-alist temp-char))
329 (remove-char-attribute temp-char (car (car char-spec)))
330 (setq char-spec (cdr char-spec))))))
332 (defun char-db-insert-alist (alist &optional readable column)
334 (setq column (current-column)))
336 (concat "\n" (make-string (1+ column) ?\ )))
340 lbs cell rest separator)
343 (setq name (car (car alist))
344 value (cdr (car alist)))
345 (cond ((eq name 'char)
347 (if (setq ret (condition-case nil
355 (setq key (car (car value)))
356 ;; (if (find-charset key)
357 ;; (setq cal (cons key cal))
358 (setq al (cons key al))
360 (setq value (cdr value)))
361 (insert-char-attributes ret
365 (insert (prin1-to-string value)))
367 (insert line-breaking))
369 (insert (format "(%-18s " name))
370 (setq lbs (concat "\n" (make-string (current-column) ?\ )))
372 (setq cell (car value))
373 (if (and (consp cell)
375 (setq ret (condition-case nil
385 (setq key (car (car rest)))
386 ;; (if (find-charset key)
387 ;; (setq cal (cons key cal))
388 (setq al (cons key al))
390 (setq rest (cdr rest)))
393 (insert-char-attributes ret
397 (setq separator lbs))
400 (insert (prin1-to-string cell))
401 (setq separator " "))
402 (setq value (cdr value)))
404 (insert line-breaking))
406 (insert (format "(%-18s . %S)%s"
409 (setq alist (cdr alist))))
412 (defun char-db-insert-char-reference (plist &optional readable column)
414 (setq column (current-column)))
416 (concat "\n" (make-string (1+ column) ?\ )))
421 (setq name (pop plist))
422 (setq value (pop plist))
423 (cond ((eq name :char)
426 (cond ((numberp value)
427 (setq value (decode-char '=ucs value)))
429 ;; (setq value (or (find-char value)
432 (char-db-insert-char-spec value readable)
433 (insert line-breaking)
436 (insert (format "%s%s\t%d ; %c%s"
439 (ideographic-radical value)
443 (insert (format "%s%s\t%S" separator name value))
444 (setq separator line-breaking)))
448 (defun char-db-decode-isolated-char (ccs code-point)
451 (cond ((eq ccs 'arabic-iso8859-6)
452 (decode-char ccs code-point))
453 ((and (memq ccs '(=gt-pj-1
464 (setq ret (decode-char ccs code-point))
465 (setq ret (encode-char ret '=gt 'defined-only)))
466 (decode-builtin-char '=gt ret))
468 (decode-builtin-char ccs code-point))))
469 (cond ((and (<= 0 (char-int ret))
470 (<= (char-int ret) #x1F))
471 (decode-char '=ucs (+ #x2400 (char-int ret))))
472 ((= (char-int ret) #x7F)
476 (defvar char-db-convert-obsolete-format t)
478 (defun char-db-insert-ccs-feature (name value line-breaking)
484 ((memq name '(=shinjigen
486 =shinjigen@rev =shinjigen/+p@rev
488 "(%-18s . %04d)\t; %c")
489 ((eq name '=shinjigen@1ed/24pr)
490 "(%-18s . %04d)\t; %c")
491 ((or (memq name '(=daikanwa =>>daikanwa =>daikanwa
492 =daikanwa@rev1 =daikanwa@rev2
493 =daikanwa/+p =daikanwa/+2p
494 =gt =>>>gt =>>gt =+>gt =>gt
496 =adobe-japan1-0 =>>>adobe-japan1-0 =>>adobe-japan1-0
497 =adobe-japan1-1 =>>>adobe-japan1-1 =>>adobe-japan1-1
498 =adobe-japan1-2 =>>>adobe-japan1-2 =>>adobe-japan1-2
499 =adobe-japan1-3 =>>>adobe-japan1-3 =>>adobe-japan1-3
500 =adobe-japan1-4 =>>>adobe-japan1-4 =>>adobe-japan1-4
501 =adobe-japan1-5 =>>>adobe-japan1-5 =>>adobe-japan1-5
502 =adobe-japan1-6 =>>>adobe-japan1-6 =>>adobe-japan1-6
505 =zinbun-oracle =>zinbun-oracle))
506 ;; (string-match "^=adobe-" (symbol-name name))
508 "(%-18s . %05d)\t; %c")
509 ((memq name '(=hanyo-denshi/ks =>>hanyo-denshi/ks mojikyo))
510 "(%-18s . %06d)\t; %c")
511 ((>= (charset-dimension name) 2)
512 "(%-18s . #x%04X)\t; %c")
514 "(%-18s . #x%02X)\t; %c"))
516 (if (= (charset-iso-graphic-plane name) 1)
518 (cond ((= (charset-dimension name) 1)
520 ((= (charset-dimension name) 2)
522 ((= (charset-dimension name) 3)
526 (char-db-decode-isolated-char name value)))
527 (if (and (= (charset-chars name) 94)
528 (= (charset-dimension name) 2))
529 (insert (format " [%02d-%02d]"
530 (- (lsh value -8) 32)
531 (- (logand value 255) 32))))
534 (insert (format "(%-18s . %s)" name value))
536 (insert line-breaking))
538 (defun char-db-insert-relation-feature (char name value line-breaking
540 (insert (format "(%-18s%s " name line-breaking))
541 (let ((lbs (concat "\n" (make-string (current-column) ?\ )))
542 separator cell sources required-features
545 (setq cell (car value))
547 (setq cell (decode-char '=ucs cell)))
549 ((eq name '->subsumptive)
550 (when (or (not (some (lambda (atr)
551 (get-char-attribute cell atr))
552 char-db-ignored-attributes))
554 (encode-char cell ccs 'defined-only))
558 (let ((char-db-ignored-attributes
560 char-db-ignored-attributes)))
561 (insert-char-attributes cell readable nil nil 'for-sub-node))
562 (setq separator lbs))
567 char (intern (format "%s*sources" name))))
568 (setq required-features nil)
569 (dolist (source sources)
573 shinjigen shinjigen@1ed shinjigen@rev))
574 (setq required-features
575 (union required-features
586 (setq required-features
587 (union required-features
592 ((find-charset (setq ret (intern (format "=%s" source))))
593 (setq required-features
594 (cons ret required-features)))
595 (t (setq required-features
596 (cons source required-features)))))
597 (cond ((string-match "@JP" (symbol-name name))
598 (setq required-features
599 (union required-features
607 ((string-match "@CN" (symbol-name name))
608 (setq required-features
609 (union required-features
616 (insert (format "%S" cell))
617 (char-db-insert-char-spec cell readable
620 (setq separator lbs))
624 (if (consp (car cell))
625 (char-db-insert-char-spec cell readable)
626 (char-db-insert-char-reference cell readable))
627 (setq separator lbs))
631 (insert (prin1-to-string cell))
632 (setq separator " ")))
633 (setq value (cdr value)))
635 (insert line-breaking)))
637 (defun insert-char-attributes (char &optional readable attributes column
640 (setq column (current-column)))
641 (let (name value ; has-long-ccs-name
645 (concat "\n" (make-string (1+ column) ?\ )))
646 lbs cell separator ret
648 dest-ccss ; sources required-features
653 (if (consp attributes)
655 (dolist (name attributes)
656 (unless (memq name char-db-ignored-attributes)
657 (if (find-charset name)
661 (dolist (name (char-attribute-list))
662 (unless (memq name char-db-ignored-attributes)
663 (if (find-charset name)
667 #'char-attribute-name<)))
669 (when (memq '<-subsumptive attributes)
670 (when (or readable (not for-sub-node))
671 (when (setq value (get-char-attribute char '<-subsumptive))
672 (char-db-insert-relation-feature char '<-subsumptive value
675 (setq attributes (delq '<-subsumptive attributes)))
676 (when (and (memq '<-denotational attributes)
677 (setq value (get-char-attribute char '<-denotational)))
678 (char-db-insert-relation-feature char '<-denotational value
681 (setq attributes (delq '<-denotational attributes)))
682 (when (and (memq 'name attributes)
683 (setq value (get-char-attribute char 'name)))
685 (if (> (+ (current-column) (length value)) 48)
688 value line-breaking))
689 (setq attributes (delq 'name attributes))
691 (when (and (memq 'name* attributes)
692 (setq value (get-char-attribute char 'name*)))
694 (if (> (+ (current-column) (length value)) 48)
697 value line-breaking))
698 (setq attributes (delq 'name* attributes))
700 (when (and (memq 'script attributes)
701 (setq value (get-char-attribute char 'script)))
702 (insert (format "(script\t\t%s)%s"
703 (mapconcat (function prin1-to-string)
706 (setq attributes (delq 'script attributes))
708 (dolist (name '(=>ucs =>ucs*))
709 (when (and (memq name attributes)
710 (setq value (get-char-attribute char name)))
711 (insert (format "(%-18s . #x%04X)\t; %c%s"
712 name value (decode-char '=ucs value)
714 (setq attributes (delq name attributes))))
715 (dolist (name '(=>ucs@gb =>ucs@big5))
716 (when (and (memq name attributes)
717 (setq value (get-char-attribute char name)))
718 (insert (format "(%-18s . #x%04X)\t; %c%s"
723 (symbol-name name) 2)))
726 (setq attributes (delq name attributes))
728 ;; (dolist (name '(=>daikanwa))
729 ;; (when (and (memq name attributes)
730 ;; (setq value (get-char-attribute char name)))
732 ;; (if (integerp value)
733 ;; (format "(%-18s . %05d)\t; %c%s"
734 ;; name value (decode-char '=daikanwa value)
736 ;; (format "(%-18s %s)\t; %c%s"
738 ;; (mapconcat (function prin1-to-string)
740 ;; (char-representative-of-daikanwa char)
742 ;; (setq attributes (delq name attributes))))
743 (when (and (memq 'general-category attributes)
744 (setq value (get-char-attribute char 'general-category)))
746 "(general-category\t%s) ; %s%s"
747 (mapconcat (lambda (cell)
750 (cond ((rassoc value unidata-normative-category-alist)
751 "Normative Category")
752 ((rassoc value unidata-informative-category-alist)
753 "Informative Category")
757 (setq attributes (delq 'general-category attributes))
759 (when (and (memq 'bidi-category attributes)
760 (setq value (get-char-attribute char 'bidi-category)))
761 (insert (format "(bidi-category\t. %S)%s"
764 (setq attributes (delq 'bidi-category attributes))
766 (unless (or (not (memq 'mirrored attributes))
767 (eq (setq value (get-char-attribute char 'mirrored 'empty))
769 (insert (format "(mirrored\t\t. %S)%s"
772 (setq attributes (delq 'mirrored attributes))
775 ((and (memq 'decimal-digit-value attributes)
776 (setq value (get-char-attribute char 'decimal-digit-value)))
777 (insert (format "(decimal-digit-value . %S)%s"
780 (setq attributes (delq 'decimal-digit-value attributes))
781 (when (and (memq 'digit-value attributes)
782 (setq value (get-char-attribute char 'digit-value)))
783 (insert (format "(digit-value\t . %S)%s"
786 (setq attributes (delq 'digit-value attributes))
788 (when (and (memq 'numeric-value attributes)
789 (setq value (get-char-attribute char 'numeric-value)))
790 (insert (format "(numeric-value\t . %S)%s"
793 (setq attributes (delq 'numeric-value attributes))
797 (when (and (memq 'digit-value attributes)
798 (setq value (get-char-attribute char 'digit-value)))
799 (insert (format "(digit-value\t. %S)%s"
802 (setq attributes (delq 'digit-value attributes))
804 (when (and (memq 'numeric-value attributes)
805 (setq value (get-char-attribute char 'numeric-value)))
806 (insert (format "(numeric-value\t. %S)%s"
809 (setq attributes (delq 'numeric-value attributes))
811 (when (and (memq 'iso-10646-comment attributes)
812 (setq value (get-char-attribute char 'iso-10646-comment)))
813 (insert (format "(iso-10646-comment\t. %S)%s"
816 (setq attributes (delq 'iso-10646-comment attributes))
818 (when (and (memq 'morohashi-daikanwa attributes)
819 (setq value (get-char-attribute char 'morohashi-daikanwa)))
820 (insert (format "(morohashi-daikanwa\t%s)%s"
821 (mapconcat (function prin1-to-string) value " ")
823 (setq attributes (delq 'morohashi-daikanwa attributes))
827 (when (and (memq 'ideographic-radical attributes)
828 (setq value (get-char-attribute char 'ideographic-radical)))
830 (insert (format "(ideographic-radical . %S)\t; %c%s"
832 (ideographic-radical radical)
834 (setq attributes (delq 'ideographic-radical attributes))
836 (when (and (memq 'shuowen-radical attributes)
837 (setq value (get-char-attribute char 'shuowen-radical)))
838 (insert (format "(shuowen-radical\t. %S)\t; %c%s"
840 (shuowen-radical value)
842 (setq attributes (delq 'shuowen-radical attributes))
847 char-db-feature-domains
849 (dolist (feature (char-attribute-list))
850 (setq feature (symbol-name feature))
852 "\\(radical\\|strokes\\)@\\([^@*]+\\)\\(\\*\\|$\\)"
854 (setq domain (intern (match-string 2 feature)))
855 (unless (memq domain dest)
856 (setq dest (cons domain dest)))))
857 (sort dest #'string<))))
858 (setq key (intern (format "%s@%s" 'ideographic-radical domain)))
859 (when (and (memq key attributes)
860 (setq value (get-char-attribute char key)))
862 (insert (format "(%s . %S)\t; %c%s"
865 (ideographic-radical radical)
867 (setq attributes (delq key attributes))
869 (setq key (intern (format "%s@%s" 'ideographic-strokes domain)))
870 (when (and (memq key attributes)
871 (setq value (get-char-attribute char key)))
873 (insert (format "(%s . %S)%s"
877 (setq attributes (delq key attributes))
879 (setq key (intern (format "%s@%s" 'total-strokes domain)))
880 (when (and (memq key attributes)
881 (setq value (get-char-attribute char key)))
882 (insert (format "(%s . %S)%s"
886 (setq attributes (delq key attributes))
888 (dolist (feature '(ideographic-radical
891 (setq key (intern (format "%s@%s*sources" feature domain)))
892 (when (and (memq key attributes)
893 (setq value (get-char-attribute char key)))
894 (insert (format "(%s%s" key line-breaking))
896 (insert (format " %s" cell)))
898 (insert line-breaking)
899 (setq attributes (delq key attributes))
902 (when (and (memq 'ideographic-strokes attributes)
903 (setq value (get-char-attribute char 'ideographic-strokes)))
905 (insert (format "(ideographic-strokes . %S)%s"
908 (setq attributes (delq 'ideographic-strokes attributes))
910 (when (and (memq 'kangxi-radical attributes)
911 (setq value (get-char-attribute char 'kangxi-radical)))
912 (unless (eq value radical)
913 (insert (format "(kangxi-radical\t . %S)\t; %c%s"
915 (ideographic-radical value)
918 (setq radical value)))
919 (setq attributes (delq 'kangxi-radical attributes))
921 (when (and (memq 'kangxi-strokes attributes)
922 (setq value (get-char-attribute char 'kangxi-strokes)))
923 (unless (eq value strokes)
924 (insert (format "(kangxi-strokes\t . %S)%s"
928 (setq strokes value)))
929 (setq attributes (delq 'kangxi-strokes attributes))
931 (when (and (memq 'japanese-radical attributes)
932 (setq value (get-char-attribute char 'japanese-radical)))
933 (unless (eq value radical)
934 (insert (format "(japanese-radical\t . %S)\t; %c%s"
936 (ideographic-radical value)
939 (setq radical value)))
940 (setq attributes (delq 'japanese-radical attributes))
942 (when (and (memq 'japanese-strokes attributes)
943 (setq value (get-char-attribute char 'japanese-strokes)))
944 (unless (eq value strokes)
945 (insert (format "(japanese-strokes\t . %S)%s"
949 (setq strokes value)))
950 (setq attributes (delq 'japanese-strokes attributes))
952 (when (and (memq 'cns-radical attributes)
953 (setq value (get-char-attribute char 'cns-radical)))
954 (insert (format "(cns-radical\t . %S)\t; %c%s"
956 (ideographic-radical value)
958 (setq attributes (delq 'cns-radical attributes))
960 (when (and (memq 'cns-strokes attributes)
961 (setq value (get-char-attribute char 'cns-strokes)))
962 (unless (eq value strokes)
963 (insert (format "(cns-strokes\t . %S)%s"
967 (setq strokes value)))
968 (setq attributes (delq 'cns-strokes attributes))
970 (when (and (memq 'shinjigen-1-radical attributes)
971 (setq value (get-char-attribute char 'shinjigen-1-radical)))
972 (unless (eq value radical)
973 (insert (format "(shinjigen-1-radical . %S)\t; %c%s"
975 (ideographic-radical value)
978 (setq radical value)))
979 (setq attributes (delq 'shinjigen-1-radical attributes))
981 (when (and (memq 'ideographic- attributes)
982 (setq value (get-char-attribute char 'ideographic-)))
983 (insert "(ideographic- ")
984 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
987 (setq cell (car value))
989 (setq cell (decode-char '=ucs cell)))
990 (cond ((characterp cell)
994 (insert (format "%S" cell))
995 (char-db-insert-char-spec cell readable))
996 (setq separator lbs))
1000 (if (consp (car cell))
1001 (char-db-insert-char-spec cell readable)
1002 (char-db-insert-char-reference cell readable))
1003 (setq separator lbs))
1007 (insert (prin1-to-string cell))
1008 (setq separator " ")))
1009 (setq value (cdr value)))
1011 (insert line-breaking)
1012 (setq attributes (delq 'ideographic- attributes)))
1013 (when (and (memq 'total-strokes attributes)
1014 (setq value (get-char-attribute char 'total-strokes)))
1015 (insert (format "(total-strokes . %S)%s"
1018 (setq attributes (delq 'total-strokes attributes))
1020 (when (and (memq '->ideograph attributes)
1021 (setq value (get-char-attribute char '->ideograph)))
1022 (insert (format "(->ideograph\t%s)%s"
1023 (mapconcat (lambda (code)
1024 (cond ((symbolp code)
1027 (format "#x%04X" code))
1030 line-breaking code))))
1033 (setq attributes (delq '->ideograph attributes))
1035 ;; (when (and (memq '->decomposition attributes)
1036 ;; (setq value (get-char-attribute char '->decomposition)))
1037 ;; (insert (format "(->decomposition\t%s)%s"
1038 ;; (mapconcat (lambda (code)
1039 ;; (cond ((symbolp code)
1040 ;; (symbol-name code))
1041 ;; ((characterp code)
1043 ;; (format "%S" code)
1048 ;; (format "#x%04X" code))
1050 ;; (format "%s%S" line-breaking code))))
1053 ;; (setq attributes (delq '->decomposition attributes))
1055 (if (equal (get-char-attribute char '->titlecase)
1056 (get-char-attribute char '->uppercase))
1057 (setq attributes (delq '->titlecase attributes)))
1058 (when (and (memq '->mojikyo attributes)
1059 (setq value (get-char-attribute char '->mojikyo)))
1060 (insert (format "(->mojikyo\t\t. %06d)\t; %c%s"
1061 value (decode-char 'mojikyo value)
1063 (setq attributes (delq '->mojikyo attributes))
1065 (when (and (memq 'hanyu-dazidian-vol attributes)
1066 (setq value (get-char-attribute char 'hanyu-dazidian-vol)))
1067 (insert (format "(hanyu-dazidian-vol . %d)%s"
1068 value line-breaking))
1069 (setq attributes (delq 'hanyu-dazidian-vol attributes))
1071 (when (and (memq 'hanyu-dazidian-page attributes)
1072 (setq value (get-char-attribute char 'hanyu-dazidian-page)))
1073 (insert (format "(hanyu-dazidian-page . %d)%s"
1074 value line-breaking))
1075 (setq attributes (delq 'hanyu-dazidian-page attributes))
1077 (when (and (memq 'hanyu-dazidian-char attributes)
1078 (setq value (get-char-attribute char 'hanyu-dazidian-char)))
1079 (insert (format "(hanyu-dazidian-char . %d)%s"
1080 value line-breaking))
1081 (setq attributes (delq 'hanyu-dazidian-char attributes))
1084 (dolist (ignored '(composition
1085 ->denotational <-subsumptive ->ucs-unified
1086 ->ideographic-component-forms))
1087 (setq attributes (delq ignored attributes))))
1089 (setq name (car attributes))
1090 (unless (eq (setq value (get-char-attribute char name 'value-is-empty))
1092 (cond ((setq ret (find-charset name))
1093 (setq name (charset-name ret))
1094 (when (not (memq name dest-ccss))
1095 (setq dest-ccss (cons name dest-ccss))
1096 (char-db-insert-ccs-feature name value line-breaking))
1098 ((string-match "^=>ucs@" (symbol-name name))
1099 (insert (format "(%-18s . #x%04X)\t; %c%s"
1100 name value (decode-char '=ucs value)
1103 ((eq name 'jisx0208-1978/4X)
1104 (insert (format "(%-18s . #x%04X)%s"
1110 (not (eq name '->subsumptive))
1111 (not (eq name '->uppercase))
1112 (not (eq name '->lowercase))
1113 (not (eq name '->titlecase))
1114 (not (eq name '->canonical))
1115 (not (eq name '->Bopomofo))
1116 (not (eq name '->mistakable))
1117 (not (eq name '->ideographic-variants))
1118 (null (get-char-attribute
1119 char (intern (format "%s*sources" name))))
1120 (not (string-match "\\*sources$" (symbol-name name)))
1121 (null (get-char-attribute
1122 char (intern (format "%s*note" name))))
1123 (not (string-match "\\*note$" (symbol-name name)))
1124 (or (eq name '<-identical)
1125 (eq name '<-uppercase)
1126 (eq name '<-lowercase)
1127 (eq name '<-titlecase)
1128 (eq name '<-canonical)
1129 (eq name '<-ideographic-variants)
1130 ;; (eq name '<-synonyms)
1131 (string-match "^<-synonyms" (symbol-name name))
1132 (eq name '<-mistakable)
1133 (when (string-match "^->" (symbol-name name))
1135 ((string-match "^->fullwidth" (symbol-name name))
1136 (not (and (consp value)
1137 (characterp (car value))
1139 (car value) '=ucs 'defined-only)))
1144 ((or (eq name 'ideographic-structure)
1145 (eq name 'ideographic-combination)
1146 (eq name 'ideographic-)
1147 (eq name '=decomposition)
1148 (char-feature-base-name= '=decomposition name)
1149 (char-feature-base-name= '=>decomposition name)
1150 ;; (string-match "^=>*decomposition\\(@[^*]+\\)?$"
1151 ;; (symbol-name name))
1152 (string-match "^\\(->\\|<-\\)[^*]*$" (symbol-name name))
1153 (string-match "^\\(->\\|<-\\)[^*]*\\*sources$"
1156 (char-db-insert-relation-feature char name value
1159 ((memq name '(ideograph=
1160 original-ideograph-of
1161 ancient-ideograph-of
1164 ;; simplified-ideograph-of
1165 ideographic-variants
1166 ;; ideographic-different-form-of
1168 (insert (format "(%-18s%s " name line-breaking))
1169 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1171 (while (consp value)
1172 (setq cell (car value))
1173 (if (and (consp cell)
1178 (char-db-insert-alist cell readable)
1179 (setq separator lbs))
1182 (insert (prin1-to-string cell))
1183 (setq separator " "))
1184 (setq value (cdr value)))
1186 (insert line-breaking))
1188 (insert (format "(%-18s " name))
1189 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1191 (while (consp value)
1192 (setq cell (car value))
1193 (if (and (consp cell)
1195 (setq ret (condition-case nil
1203 (setq key (car (car rest)))
1204 (if (find-charset key)
1205 (setq cal (cons key cal))
1206 (setq al (cons key al)))
1207 (setq rest (cdr rest)))
1210 (insert-char-attributes ret
1214 (setq separator lbs))
1215 (setq ret (prin1-to-string cell))
1217 (if (< (+ (current-column)
1224 (setq separator " "))
1225 (setq value (cdr value)))
1227 (insert line-breaking))
1229 (insert (format "(%-18s" name))
1230 (setq ret (prin1-to-string value))
1231 (unless (< (+ (current-column)
1235 (insert line-breaking))
1236 (insert " . " ret ")" line-breaking)
1237 ;; (insert (format "(%-18s . %S)%s"
1242 (setq attributes (cdr attributes)))
1245 (defun insert-char-data (char &optional readable
1248 (narrow-to-region (point)(point))
1249 (insert "(define-char
1251 (insert-char-attributes char readable attributes)
1253 (goto-char (point-min))
1254 (while (re-search-forward "[ \t]+$" nil t)
1257 (goto-char (point-min))
1258 (while (re-search-forward "[ \t][ \t][ \t]*" nil t)
1259 (let ((column (current-column))
1260 (indent-tabs-mode t))
1261 (delete-region (match-beginning 0) (point))
1262 (indent-to column)))
1263 (goto-char (point-max))
1264 ;; (tabify (point-min)(point-max))
1267 (defun insert-char-data-with-variant (char &optional printable
1269 script excluded-script)
1270 (insert-char-data char printable)
1271 (let ((variants (char-variants char))
1274 (setq variants (sort variants #'<))
1275 (setq rest variants)
1276 (setq variants (cons char variants))
1278 (setq variant (car rest))
1279 (unless (get-char-attribute variant '<-subsumptive)
1280 (if (and (or (null script)
1281 (null (setq vs (get-char-attribute variant 'script)))
1283 (or (null excluded-script)
1284 (null (setq vs (get-char-attribute variant 'script)))
1285 (not (memq excluded-script vs))))
1286 (unless (and no-ucs-unified (get-char-attribute variant '=ucs))
1287 (insert-char-data variant printable)
1288 (if (setq ret (char-variants variant))
1290 (or (memq (car ret) variants)
1291 ;; (get-char-attribute (car ret) '<-subsumptive)
1292 (setq rest (nconc rest (list (car ret)))))
1293 (setq ret (cdr ret)))))))
1294 (setq rest (cdr rest)))))
1296 (defun insert-char-range-data (min max &optional script excluded-script)
1299 (while (<= code max)
1300 (setq char (decode-char '=ucs code))
1301 (if (encode-char char '=ucs 'defined-only)
1302 (insert-char-data-with-variant char nil 'no-ucs-unified
1303 script excluded-script))
1304 (setq code (1+ code)))))
1306 (defun write-char-range-data-to-file (min max file
1307 &optional script excluded-script)
1308 (let ((coding-system-for-write char-db-file-coding-system))
1310 (insert (format ";; -*- coding: %s -*-\n"
1311 char-db-file-coding-system))
1312 (insert-char-range-data min max script excluded-script)
1313 (write-region (point-min)(point-max) file))))
1315 (defvar what-character-original-window-configuration)
1318 (defun what-char-definition (char)
1319 (interactive (list (char-after)))
1320 (let ((buf (get-buffer-create "*Character Description*"))
1321 (the-buf (current-buffer))
1322 (win-conf (current-window-configuration)))
1324 (make-local-variable 'what-character-original-window-configuration)
1325 (setq what-character-original-window-configuration win-conf)
1326 (setq buffer-read-only nil)
1330 (insert-char-data-with-variant char 'printable)
1331 (unless (char-attribute-alist char)
1332 (insert (format ";; = %c\n"
1333 (let* ((rest (split-char char))
1337 (setq code (logior (lsh code 8)
1339 (decode-char ccs code)))))
1340 ;; (char-db-update-comment)
1341 (set-buffer-modified-p nil)
1342 (view-mode the-buf (lambda (buf)
1343 (set-window-configuration
1344 what-character-original-window-configuration)
1346 (goto-char (point-min)))
1348 (set-window-configuration
1349 what-character-original-window-configuration)
1350 (signal (car err) (cdr err)))))))
1356 (provide 'char-db-util)
1358 ;;; char-db-util.el ends here