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
235 ;;; @ char-db formatters
238 (defun char-db-make-char-spec (char)
240 (cond ((characterp char)
241 (cond ((and (setq ret (encode-char char '=ucs 'defined-only))
242 (not (and (<= #xE000 ret)(<= ret #xF8FF))))
243 (setq char-spec (list (cons '=ucs ret)))
244 (cond ((setq ret (get-char-attribute char 'name))
245 (setq char-spec (cons (cons 'name ret) char-spec))
247 ((setq ret (get-char-attribute char 'name*))
248 (setq char-spec (cons (cons 'name* ret) char-spec))
253 (let ((rest char-db-coded-charset-priority-list)
256 (setq ccs (charset-name
257 (find-charset (car rest))))
259 (encode-char char ccs
261 (throw 'tag (cons ccs ret)))
262 (setq rest (cdr rest))))))
263 (setq char-spec (list ret))
264 (dolist (ccs (delq (car ret) (charset-list)))
265 (if (and (or (charset-iso-final-char ccs)
272 (string-match "=ucs@" (symbol-name ccs)))
273 (setq ccs (charset-name ccs))
274 (null (assq ccs char-spec))
275 (setq ret (encode-char char ccs 'defined-only)))
276 (setq char-spec (cons (cons ccs ret) char-spec))))
278 (setq char-spec (split-char char)))
279 (cond ((setq ret (get-char-attribute char 'name))
280 (setq char-spec (cons (cons 'name ret) char-spec))
282 ((setq ret (get-char-attribute char 'name*))
283 (setq char-spec (cons (cons 'name* ret) char-spec))
286 ((setq ret (get-char-attribute
287 char 'ideographic-combination))
289 (cons (cons 'ideographic-combination ret)
296 (defun char-db-insert-char-spec (char &optional readable column
299 (setq column (current-column)))
300 (let (char-spec temp-char)
301 (setq char-spec (char-db-make-char-spec char))
302 (unless (or (characterp char) ; char
304 (setq char (find-char char-spec))
306 ;; define temporary character
307 ;; Current implementation is dirty.
308 (setq temp-char (define-char (cons '(ideograph-daikanwa . 0)
310 (remove-char-attribute temp-char 'ideograph-daikanwa)
311 (setq char temp-char))
312 (insert-char-attributes char
314 (union (mapcar #'car char-spec)
318 ;; undefine temporary character
319 ;; Current implementation is dirty.
320 (setq char-spec (char-attribute-alist temp-char))
322 (remove-char-attribute temp-char (car (car char-spec)))
323 (setq char-spec (cdr char-spec))))))
325 (defun char-db-insert-alist (alist &optional readable column)
327 (setq column (current-column)))
329 (concat "\n" (make-string (1+ column) ?\ )))
333 lbs cell rest separator)
336 (setq name (car (car alist))
337 value (cdr (car alist)))
338 (cond ((eq name 'char)
340 (if (setq ret (condition-case nil
348 (setq key (car (car value)))
349 ;; (if (find-charset key)
350 ;; (setq cal (cons key cal))
351 (setq al (cons key al))
353 (setq value (cdr value)))
354 (insert-char-attributes ret
358 (insert (prin1-to-string value)))
360 (insert line-breaking))
362 (insert (format "(%-18s " name))
363 (setq lbs (concat "\n" (make-string (current-column) ?\ )))
365 (setq cell (car value))
366 (if (and (consp cell)
368 (setq ret (condition-case nil
378 (setq key (car (car rest)))
379 ;; (if (find-charset key)
380 ;; (setq cal (cons key cal))
381 (setq al (cons key al))
383 (setq rest (cdr rest)))
386 (insert-char-attributes ret
390 (setq separator lbs))
393 (insert (prin1-to-string cell))
394 (setq separator " "))
395 (setq value (cdr value)))
397 (insert line-breaking))
399 (insert (format "(%-18s . %S)%s"
402 (setq alist (cdr alist))))
405 (defun char-db-insert-char-reference (plist &optional readable column)
407 (setq column (current-column)))
409 (concat "\n" (make-string (1+ column) ?\ )))
414 (setq name (pop plist))
415 (setq value (pop plist))
416 (cond ((eq name :char)
419 (cond ((numberp value)
420 (setq value (decode-char '=ucs value)))
422 ;; (setq value (or (find-char value)
425 (char-db-insert-char-spec value readable)
426 (insert line-breaking)
429 (insert (format "%s%s\t%d ; %c%s"
432 (ideographic-radical value)
436 (insert (format "%s%s\t%S" separator name value))
437 (setq separator line-breaking)))
441 (defun char-db-decode-isolated-char (ccs code-point)
444 (cond ((eq ccs 'arabic-iso8859-6)
445 (decode-char ccs code-point))
446 ((and (memq ccs '(=gt-pj-1
457 (setq ret (decode-char ccs code-point))
458 (setq ret (encode-char ret '=gt 'defined-only)))
459 (decode-builtin-char '=gt ret))
461 (decode-builtin-char ccs code-point))))
462 (cond ((and (<= 0 (char-int ret))
463 (<= (char-int ret) #x1F))
464 (decode-char '=ucs (+ #x2400 (char-int ret))))
465 ((= (char-int ret) #x7F)
469 (defvar char-db-convert-obsolete-format t)
471 (defun char-db-insert-ccs-feature (name value line-breaking)
477 ((memq name '(=shinjigen
479 =shinjigen@rev =shinjigen/+p@rev
481 "(%-18s . %04d)\t; %c")
482 ((eq name '=shinjigen@1ed/24pr)
483 "(%-18s . %04d)\t; %c")
484 ((or (memq name '(=daikanwa =>>daikanwa =>daikanwa
485 =daikanwa@rev1 =daikanwa@rev2
486 =daikanwa/+p =daikanwa/+2p
487 =gt =>>>gt =>>gt =>gt
491 =zinbun-oracle =>zinbun-oracle))
492 (string-match "^=adobe-" (symbol-name name)))
493 "(%-18s . %05d)\t; %c")
494 ((memq name '(=hanyo-denshi/ks =>>hanyo-denshi/ks mojikyo))
495 "(%-18s . %06d)\t; %c")
496 ((>= (charset-dimension name) 2)
497 "(%-18s . #x%04X)\t; %c")
499 "(%-18s . #x%02X)\t; %c"))
501 (if (= (charset-iso-graphic-plane name) 1)
503 (cond ((= (charset-dimension name) 1)
505 ((= (charset-dimension name) 2)
507 ((= (charset-dimension name) 3)
511 (char-db-decode-isolated-char name value)))
512 (if (and (= (charset-chars name) 94)
513 (= (charset-dimension name) 2))
514 (insert (format " [%02d-%02d]"
515 (- (lsh value -8) 32)
516 (- (logand value 255) 32))))
519 (insert (format "(%-18s . %s)" name value))
521 (insert line-breaking))
523 (defun char-db-insert-relation-feature (char name value line-breaking
525 (insert (format "(%-18s%s " name line-breaking))
526 (let ((lbs (concat "\n" (make-string (current-column) ?\ )))
527 separator cell sources required-features
530 (setq cell (car value))
532 (setq cell (decode-char '=ucs cell)))
534 ((eq name '->subsumptive)
535 (when (or (not (some (lambda (atr)
536 (get-char-attribute cell atr))
537 char-db-ignored-attributes))
539 (encode-char cell ccs 'defined-only))
543 (let ((char-db-ignored-attributes
545 char-db-ignored-attributes)))
546 (insert-char-attributes cell readable nil nil 'for-sub-node))
547 (setq separator lbs))
552 char (intern (format "%s*sources" name))))
553 (setq required-features nil)
554 (dolist (source sources)
558 shinjigen shinjigen@1ed shinjigen@rev))
559 (setq required-features
560 (union required-features
571 (setq required-features
572 (union required-features
577 ((find-charset (setq ret (intern (format "=%s" source))))
578 (setq required-features
579 (cons ret required-features)))
580 (t (setq required-features
581 (cons source required-features)))))
582 (cond ((string-match "@JP" (symbol-name name))
583 (setq required-features
584 (union required-features
592 ((string-match "@CN" (symbol-name name))
593 (setq required-features
594 (union required-features
601 (insert (format "%S" cell))
602 (char-db-insert-char-spec cell readable
605 (setq separator lbs))
609 (if (consp (car cell))
610 (char-db-insert-char-spec cell readable)
611 (char-db-insert-char-reference cell readable))
612 (setq separator lbs))
616 (insert (prin1-to-string cell))
617 (setq separator " ")))
618 (setq value (cdr value)))
620 (insert line-breaking)))
622 (defun insert-char-attributes (char &optional readable attributes column
625 (setq column (current-column)))
626 (let (name value ; has-long-ccs-name
630 (concat "\n" (make-string (1+ column) ?\ )))
631 lbs cell separator ret
633 dest-ccss ; sources required-features
638 (if (consp attributes)
640 (dolist (name attributes)
641 (unless (memq name char-db-ignored-attributes)
642 (if (find-charset name)
646 (dolist (name (char-attribute-list))
647 (unless (memq name char-db-ignored-attributes)
648 (if (find-charset name)
652 #'char-attribute-name<)))
654 (when (memq '<-subsumptive attributes)
655 (when (or readable (not for-sub-node))
656 (when (setq value (get-char-attribute char '<-subsumptive))
657 (char-db-insert-relation-feature char '<-subsumptive value
660 (setq attributes (delq '<-subsumptive attributes)))
661 (when (and (memq '<-denotational attributes)
662 (setq value (get-char-attribute char '<-denotational)))
663 (char-db-insert-relation-feature char '<-denotational value
666 (setq attributes (delq '<-denotational attributes)))
667 (when (and (memq 'name attributes)
668 (setq value (get-char-attribute char 'name)))
670 (if (> (+ (current-column) (length value)) 48)
673 value line-breaking))
674 (setq attributes (delq 'name attributes))
676 (when (and (memq 'name* attributes)
677 (setq value (get-char-attribute char 'name*)))
679 (if (> (+ (current-column) (length value)) 48)
682 value line-breaking))
683 (setq attributes (delq 'name* attributes))
685 (when (and (memq 'script attributes)
686 (setq value (get-char-attribute char 'script)))
687 (insert (format "(script\t\t%s)%s"
688 (mapconcat (function prin1-to-string)
691 (setq attributes (delq 'script attributes))
693 (dolist (name '(=>ucs =>ucs*))
694 (when (and (memq name attributes)
695 (setq value (get-char-attribute char name)))
696 (insert (format "(%-18s . #x%04X)\t; %c%s"
697 name value (decode-char '=ucs value)
699 (setq attributes (delq name attributes))))
700 (dolist (name '(=>ucs@gb =>ucs@big5))
701 (when (and (memq name attributes)
702 (setq value (get-char-attribute char name)))
703 (insert (format "(%-18s . #x%04X)\t; %c%s"
708 (symbol-name name) 2)))
711 (setq attributes (delq name attributes))
713 ;; (dolist (name '(=>daikanwa))
714 ;; (when (and (memq name attributes)
715 ;; (setq value (get-char-attribute char name)))
717 ;; (if (integerp value)
718 ;; (format "(%-18s . %05d)\t; %c%s"
719 ;; name value (decode-char '=daikanwa value)
721 ;; (format "(%-18s %s)\t; %c%s"
723 ;; (mapconcat (function prin1-to-string)
725 ;; (char-representative-of-daikanwa char)
727 ;; (setq attributes (delq name attributes))))
728 (when (and (memq 'general-category attributes)
729 (setq value (get-char-attribute char 'general-category)))
731 "(general-category\t%s) ; %s%s"
732 (mapconcat (lambda (cell)
735 (cond ((rassoc value unidata-normative-category-alist)
736 "Normative Category")
737 ((rassoc value unidata-informative-category-alist)
738 "Informative Category")
742 (setq attributes (delq 'general-category attributes))
744 (when (and (memq 'bidi-category attributes)
745 (setq value (get-char-attribute char 'bidi-category)))
746 (insert (format "(bidi-category\t. %S)%s"
749 (setq attributes (delq 'bidi-category attributes))
751 (unless (or (not (memq 'mirrored attributes))
752 (eq (setq value (get-char-attribute char 'mirrored 'empty))
754 (insert (format "(mirrored\t\t. %S)%s"
757 (setq attributes (delq 'mirrored attributes))
760 ((and (memq 'decimal-digit-value attributes)
761 (setq value (get-char-attribute char 'decimal-digit-value)))
762 (insert (format "(decimal-digit-value . %S)%s"
765 (setq attributes (delq 'decimal-digit-value attributes))
766 (when (and (memq 'digit-value attributes)
767 (setq value (get-char-attribute char 'digit-value)))
768 (insert (format "(digit-value\t . %S)%s"
771 (setq attributes (delq 'digit-value attributes))
773 (when (and (memq 'numeric-value attributes)
774 (setq value (get-char-attribute char 'numeric-value)))
775 (insert (format "(numeric-value\t . %S)%s"
778 (setq attributes (delq 'numeric-value attributes))
782 (when (and (memq 'digit-value attributes)
783 (setq value (get-char-attribute char 'digit-value)))
784 (insert (format "(digit-value\t. %S)%s"
787 (setq attributes (delq 'digit-value attributes))
789 (when (and (memq 'numeric-value attributes)
790 (setq value (get-char-attribute char 'numeric-value)))
791 (insert (format "(numeric-value\t. %S)%s"
794 (setq attributes (delq 'numeric-value attributes))
796 (when (and (memq 'iso-10646-comment attributes)
797 (setq value (get-char-attribute char 'iso-10646-comment)))
798 (insert (format "(iso-10646-comment\t. %S)%s"
801 (setq attributes (delq 'iso-10646-comment attributes))
803 (when (and (memq 'morohashi-daikanwa attributes)
804 (setq value (get-char-attribute char 'morohashi-daikanwa)))
805 (insert (format "(morohashi-daikanwa\t%s)%s"
806 (mapconcat (function prin1-to-string) value " ")
808 (setq attributes (delq 'morohashi-daikanwa attributes))
812 (when (and (memq 'ideographic-radical attributes)
813 (setq value (get-char-attribute char 'ideographic-radical)))
815 (insert (format "(ideographic-radical . %S)\t; %c%s"
817 (ideographic-radical radical)
819 (setq attributes (delq 'ideographic-radical attributes))
821 (when (and (memq 'shuowen-radical attributes)
822 (setq value (get-char-attribute char 'shuowen-radical)))
823 (insert (format "(shuowen-radical\t. %S)\t; %c%s"
825 (shuowen-radical value)
827 (setq attributes (delq 'shuowen-radical attributes))
832 char-db-feature-domains
834 (dolist (feature (char-attribute-list))
835 (setq feature (symbol-name feature))
837 "\\(radical\\|strokes\\)@\\([^@*]+\\)\\(\\*\\|$\\)"
839 (setq domain (intern (match-string 2 feature)))
840 (unless (memq domain dest)
841 (setq dest (cons domain dest)))))
842 (sort dest #'string<))))
843 (setq key (intern (format "%s@%s" 'ideographic-radical domain)))
844 (when (and (memq key attributes)
845 (setq value (get-char-attribute char key)))
847 (insert (format "(%s . %S)\t; %c%s"
850 (ideographic-radical radical)
852 (setq attributes (delq key attributes))
854 (setq key (intern (format "%s@%s" 'ideographic-strokes domain)))
855 (when (and (memq key attributes)
856 (setq value (get-char-attribute char key)))
858 (insert (format "(%s . %S)%s"
862 (setq attributes (delq key attributes))
864 (setq key (intern (format "%s@%s" 'total-strokes domain)))
865 (when (and (memq key attributes)
866 (setq value (get-char-attribute char key)))
867 (insert (format "(%s . %S)%s"
871 (setq attributes (delq key attributes))
873 (dolist (feature '(ideographic-radical
876 (setq key (intern (format "%s@%s*sources" feature domain)))
877 (when (and (memq key attributes)
878 (setq value (get-char-attribute char key)))
879 (insert (format "(%s%s" key line-breaking))
881 (insert (format " %s" cell)))
883 (insert line-breaking)
884 (setq attributes (delq key attributes))
887 (when (and (memq 'ideographic-strokes attributes)
888 (setq value (get-char-attribute char 'ideographic-strokes)))
890 (insert (format "(ideographic-strokes . %S)%s"
893 (setq attributes (delq 'ideographic-strokes attributes))
895 (when (and (memq 'kangxi-radical attributes)
896 (setq value (get-char-attribute char 'kangxi-radical)))
897 (unless (eq value radical)
898 (insert (format "(kangxi-radical\t . %S)\t; %c%s"
900 (ideographic-radical value)
903 (setq radical value)))
904 (setq attributes (delq 'kangxi-radical attributes))
906 (when (and (memq 'kangxi-strokes attributes)
907 (setq value (get-char-attribute char 'kangxi-strokes)))
908 (unless (eq value strokes)
909 (insert (format "(kangxi-strokes\t . %S)%s"
913 (setq strokes value)))
914 (setq attributes (delq 'kangxi-strokes attributes))
916 (when (and (memq 'japanese-radical attributes)
917 (setq value (get-char-attribute char 'japanese-radical)))
918 (unless (eq value radical)
919 (insert (format "(japanese-radical\t . %S)\t; %c%s"
921 (ideographic-radical value)
924 (setq radical value)))
925 (setq attributes (delq 'japanese-radical attributes))
927 (when (and (memq 'japanese-strokes attributes)
928 (setq value (get-char-attribute char 'japanese-strokes)))
929 (unless (eq value strokes)
930 (insert (format "(japanese-strokes\t . %S)%s"
934 (setq strokes value)))
935 (setq attributes (delq 'japanese-strokes attributes))
937 (when (and (memq 'cns-radical attributes)
938 (setq value (get-char-attribute char 'cns-radical)))
939 (insert (format "(cns-radical\t . %S)\t; %c%s"
941 (ideographic-radical value)
943 (setq attributes (delq 'cns-radical attributes))
945 (when (and (memq 'cns-strokes attributes)
946 (setq value (get-char-attribute char 'cns-strokes)))
947 (unless (eq value strokes)
948 (insert (format "(cns-strokes\t . %S)%s"
952 (setq strokes value)))
953 (setq attributes (delq 'cns-strokes attributes))
955 (when (and (memq 'shinjigen-1-radical attributes)
956 (setq value (get-char-attribute char 'shinjigen-1-radical)))
957 (unless (eq value radical)
958 (insert (format "(shinjigen-1-radical . %S)\t; %c%s"
960 (ideographic-radical value)
963 (setq radical value)))
964 (setq attributes (delq 'shinjigen-1-radical attributes))
966 (when (and (memq 'ideographic- attributes)
967 (setq value (get-char-attribute char 'ideographic-)))
968 (insert "(ideographic- ")
969 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
972 (setq cell (car value))
974 (setq cell (decode-char '=ucs cell)))
975 (cond ((characterp cell)
979 (insert (format "%S" cell))
980 (char-db-insert-char-spec cell readable))
981 (setq separator lbs))
985 (if (consp (car cell))
986 (char-db-insert-char-spec cell readable)
987 (char-db-insert-char-reference cell readable))
988 (setq separator lbs))
992 (insert (prin1-to-string cell))
993 (setq separator " ")))
994 (setq value (cdr value)))
996 (insert line-breaking)
997 (setq attributes (delq 'ideographic- attributes)))
998 (when (and (memq 'total-strokes attributes)
999 (setq value (get-char-attribute char 'total-strokes)))
1000 (insert (format "(total-strokes . %S)%s"
1003 (setq attributes (delq 'total-strokes attributes))
1005 (when (and (memq '->ideograph attributes)
1006 (setq value (get-char-attribute char '->ideograph)))
1007 (insert (format "(->ideograph\t%s)%s"
1008 (mapconcat (lambda (code)
1009 (cond ((symbolp code)
1012 (format "#x%04X" code))
1015 line-breaking code))))
1018 (setq attributes (delq '->ideograph attributes))
1020 ;; (when (and (memq '->decomposition attributes)
1021 ;; (setq value (get-char-attribute char '->decomposition)))
1022 ;; (insert (format "(->decomposition\t%s)%s"
1023 ;; (mapconcat (lambda (code)
1024 ;; (cond ((symbolp code)
1025 ;; (symbol-name code))
1026 ;; ((characterp code)
1028 ;; (format "%S" code)
1033 ;; (format "#x%04X" code))
1035 ;; (format "%s%S" line-breaking code))))
1038 ;; (setq attributes (delq '->decomposition attributes))
1040 (if (equal (get-char-attribute char '->titlecase)
1041 (get-char-attribute char '->uppercase))
1042 (setq attributes (delq '->titlecase attributes)))
1043 (when (and (memq '->mojikyo attributes)
1044 (setq value (get-char-attribute char '->mojikyo)))
1045 (insert (format "(->mojikyo\t\t. %06d)\t; %c%s"
1046 value (decode-char 'mojikyo value)
1048 (setq attributes (delq '->mojikyo attributes))
1050 (when (and (memq 'hanyu-dazidian-vol attributes)
1051 (setq value (get-char-attribute char 'hanyu-dazidian-vol)))
1052 (insert (format "(hanyu-dazidian-vol . %d)%s"
1053 value line-breaking))
1054 (setq attributes (delq 'hanyu-dazidian-vol attributes))
1056 (when (and (memq 'hanyu-dazidian-page attributes)
1057 (setq value (get-char-attribute char 'hanyu-dazidian-page)))
1058 (insert (format "(hanyu-dazidian-page . %d)%s"
1059 value line-breaking))
1060 (setq attributes (delq 'hanyu-dazidian-page attributes))
1062 (when (and (memq 'hanyu-dazidian-char attributes)
1063 (setq value (get-char-attribute char 'hanyu-dazidian-char)))
1064 (insert (format "(hanyu-dazidian-char . %d)%s"
1065 value line-breaking))
1066 (setq attributes (delq 'hanyu-dazidian-char attributes))
1069 (dolist (ignored '(composition
1070 ->denotational <-subsumptive ->ucs-unified
1071 ->ideographic-component-forms))
1072 (setq attributes (delq ignored attributes))))
1074 (setq name (car attributes))
1075 (unless (eq (setq value (get-char-attribute char name 'value-is-empty))
1077 (cond ((setq ret (find-charset name))
1078 (setq name (charset-name ret))
1079 (when (not (memq name dest-ccss))
1080 (setq dest-ccss (cons name dest-ccss))
1081 (char-db-insert-ccs-feature name value line-breaking))
1083 ((string-match "^=>ucs@" (symbol-name name))
1084 (insert (format "(%-18s . #x%04X)\t; %c%s"
1085 name value (decode-char '=ucs value)
1088 ((eq name 'jisx0208-1978/4X)
1089 (insert (format "(%-18s . #x%04X)%s"
1095 (not (eq name '->subsumptive))
1096 (not (eq name '->uppercase))
1097 (not (eq name '->lowercase))
1098 (not (eq name '->titlecase))
1099 (not (eq name '->canonical))
1100 (not (eq name '->Bopomofo))
1101 (not (eq name '->mistakable))
1102 (not (eq name '->ideographic-variants))
1103 (null (get-char-attribute
1104 char (intern (format "%s*sources" name))))
1105 (not (string-match "\\*sources$" (symbol-name name)))
1106 (null (get-char-attribute
1107 char (intern (format "%s*note" name))))
1108 (not (string-match "\\*note$" (symbol-name name)))
1109 (or (eq name '<-identical)
1110 (eq name '<-uppercase)
1111 (eq name '<-lowercase)
1112 (eq name '<-titlecase)
1113 (eq name '<-canonical)
1114 (eq name '<-ideographic-variants)
1115 ;; (eq name '<-synonyms)
1116 (string-match "^<-synonyms" (symbol-name name))
1117 (eq name '<-mistakable)
1118 (when (string-match "^->" (symbol-name name))
1120 ((string-match "^->fullwidth" (symbol-name name))
1121 (not (and (consp value)
1122 (characterp (car value))
1124 (car value) '=ucs 'defined-only)))
1129 ((or (eq name 'ideographic-structure)
1130 (eq name 'ideographic-combination)
1131 (eq name 'ideographic-)
1132 (eq name '=decomposition)
1133 (char-feature-base-name= '=decomposition name)
1134 (char-feature-base-name= '=>decomposition name)
1135 ;; (string-match "^=>*decomposition\\(@[^*]+\\)?$"
1136 ;; (symbol-name name))
1137 (string-match "^\\(->\\|<-\\)[^*]*$" (symbol-name name))
1138 (string-match "^\\(->\\|<-\\)[^*]*\\*sources$"
1141 (char-db-insert-relation-feature char name value
1144 ((memq name '(ideograph=
1145 original-ideograph-of
1146 ancient-ideograph-of
1149 ;; simplified-ideograph-of
1150 ideographic-variants
1151 ;; ideographic-different-form-of
1153 (insert (format "(%-18s%s " name line-breaking))
1154 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1156 (while (consp value)
1157 (setq cell (car value))
1158 (if (and (consp cell)
1163 (char-db-insert-alist cell readable)
1164 (setq separator lbs))
1167 (insert (prin1-to-string cell))
1168 (setq separator " "))
1169 (setq value (cdr value)))
1171 (insert line-breaking))
1173 (insert (format "(%-18s " name))
1174 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1176 (while (consp value)
1177 (setq cell (car value))
1178 (if (and (consp cell)
1180 (setq ret (condition-case nil
1188 (setq key (car (car rest)))
1189 (if (find-charset key)
1190 (setq cal (cons key cal))
1191 (setq al (cons key al)))
1192 (setq rest (cdr rest)))
1195 (insert-char-attributes ret
1199 (setq separator lbs))
1200 (setq ret (prin1-to-string cell))
1202 (if (< (+ (current-column)
1209 (setq separator " "))
1210 (setq value (cdr value)))
1212 (insert line-breaking))
1214 (insert (format "(%-18s" name))
1215 (setq ret (prin1-to-string value))
1216 (unless (< (+ (current-column)
1220 (insert line-breaking))
1221 (insert " . " ret ")" line-breaking)
1222 ;; (insert (format "(%-18s . %S)%s"
1227 (setq attributes (cdr attributes)))
1230 (defun insert-char-data (char &optional readable
1233 (narrow-to-region (point)(point))
1234 (insert "(define-char
1236 (insert-char-attributes char readable attributes)
1238 (goto-char (point-min))
1239 (while (re-search-forward "[ \t]+$" nil t)
1242 (goto-char (point-min))
1243 (while (re-search-forward "[ \t][ \t][ \t]*" nil t)
1244 (let ((column (current-column))
1245 (indent-tabs-mode t))
1246 (delete-region (match-beginning 0) (point))
1247 (indent-to column)))
1248 (goto-char (point-max))
1249 ;; (tabify (point-min)(point-max))
1252 (defun insert-char-data-with-variant (char &optional printable
1254 script excluded-script)
1255 (insert-char-data char printable)
1256 (let ((variants (char-variants char))
1259 (setq variants (sort variants #'<))
1260 (setq rest variants)
1261 (setq variants (cons char variants))
1263 (setq variant (car rest))
1264 (unless (get-char-attribute variant '<-subsumptive)
1265 (if (and (or (null script)
1266 (null (setq vs (get-char-attribute variant 'script)))
1268 (or (null excluded-script)
1269 (null (setq vs (get-char-attribute variant 'script)))
1270 (not (memq excluded-script vs))))
1271 (unless (and no-ucs-unified (get-char-attribute variant '=ucs))
1272 (insert-char-data variant printable)
1273 (if (setq ret (char-variants variant))
1275 (or (memq (car ret) variants)
1276 ;; (get-char-attribute (car ret) '<-subsumptive)
1277 (setq rest (nconc rest (list (car ret)))))
1278 (setq ret (cdr ret)))))))
1279 (setq rest (cdr rest)))))
1281 (defun insert-char-range-data (min max &optional script excluded-script)
1284 (while (<= code max)
1285 (setq char (decode-char '=ucs code))
1286 (if (encode-char char '=ucs 'defined-only)
1287 (insert-char-data-with-variant char nil 'no-ucs-unified
1288 script excluded-script))
1289 (setq code (1+ code)))))
1291 (defun write-char-range-data-to-file (min max file
1292 &optional script excluded-script)
1293 (let ((coding-system-for-write char-db-file-coding-system))
1295 (insert (format ";; -*- coding: %s -*-\n"
1296 char-db-file-coding-system))
1297 (insert-char-range-data min max script excluded-script)
1298 (write-region (point-min)(point-max) file))))
1300 (defvar what-character-original-window-configuration)
1303 (defun what-char-definition (char)
1304 (interactive (list (char-after)))
1305 (let ((buf (get-buffer-create "*Character Description*"))
1306 (the-buf (current-buffer))
1307 (win-conf (current-window-configuration)))
1309 (make-local-variable 'what-character-original-window-configuration)
1310 (setq what-character-original-window-configuration win-conf)
1311 (setq buffer-read-only nil)
1315 (insert-char-data-with-variant char 'printable)
1316 (unless (char-attribute-alist char)
1317 (insert (format ";; = %c\n"
1318 (let* ((rest (split-char char))
1322 (setq code (logior (lsh code 8)
1324 (decode-char ccs code)))))
1325 ;; (char-db-update-comment)
1326 (set-buffer-modified-p nil)
1327 (view-mode the-buf (lambda (buf)
1328 (set-window-configuration
1329 what-character-original-window-configuration)
1331 (goto-char (point-min)))
1333 (set-window-configuration
1334 what-character-original-window-configuration)
1335 (signal (car err) (cdr err)))))))
1341 (provide 'char-db-util)
1343 ;;; char-db-util.el ends here