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
232 ;;; @ char-db formatters
235 (defun char-db-make-char-spec (char)
237 (cond ((characterp char)
238 (cond ((and (setq ret (encode-char char '=ucs 'defined-only))
239 (not (and (<= #xE000 ret)(<= ret #xF8FF))))
240 (setq char-spec (list (cons '=ucs ret)))
241 (cond ((setq ret (get-char-attribute char 'name))
242 (setq char-spec (cons (cons 'name ret) char-spec))
244 ((setq ret (get-char-attribute char 'name*))
245 (setq char-spec (cons (cons 'name* ret) char-spec))
250 (let ((rest char-db-coded-charset-priority-list)
253 (setq ccs (charset-name
254 (find-charset (car rest))))
256 (encode-char char ccs
258 (throw 'tag (cons ccs ret)))
259 (setq rest (cdr rest))))))
260 (setq char-spec (list ret))
261 (dolist (ccs (delq (car ret) (charset-list)))
262 (if (and (or (charset-iso-final-char ccs)
269 (string-match "=ucs@" (symbol-name ccs)))
270 (setq ccs (charset-name ccs))
271 (null (assq ccs char-spec))
272 (setq ret (encode-char char ccs 'defined-only)))
273 (setq char-spec (cons (cons ccs ret) char-spec))))
275 (setq char-spec (split-char char)))
276 (cond ((setq ret (get-char-attribute char 'name))
277 (setq char-spec (cons (cons 'name ret) char-spec))
279 ((setq ret (get-char-attribute char 'name*))
280 (setq char-spec (cons (cons 'name* ret) char-spec))
283 ((setq ret (get-char-attribute
284 char 'ideographic-combination))
286 (cons (cons 'ideographic-combination ret)
293 (defun char-db-insert-char-spec (char &optional readable column
296 (setq column (current-column)))
297 (let (char-spec temp-char)
298 (setq char-spec (char-db-make-char-spec char))
299 (unless (or (characterp char) ; char
301 (setq char (find-char char-spec))
303 ;; define temporary character
304 ;; Current implementation is dirty.
305 (setq temp-char (define-char (cons '(ideograph-daikanwa . 0)
307 (remove-char-attribute temp-char 'ideograph-daikanwa)
308 (setq char temp-char))
309 (insert-char-attributes char
311 (union (mapcar #'car char-spec)
315 ;; undefine temporary character
316 ;; Current implementation is dirty.
317 (setq char-spec (char-attribute-alist temp-char))
319 (remove-char-attribute temp-char (car (car char-spec)))
320 (setq char-spec (cdr char-spec))))))
322 (defun char-db-insert-alist (alist &optional readable column)
324 (setq column (current-column)))
326 (concat "\n" (make-string (1+ column) ?\ )))
330 lbs cell rest separator)
333 (setq name (car (car alist))
334 value (cdr (car alist)))
335 (cond ((eq name 'char)
337 (if (setq ret (condition-case nil
345 (setq key (car (car value)))
346 ;; (if (find-charset key)
347 ;; (setq cal (cons key cal))
348 (setq al (cons key al))
350 (setq value (cdr value)))
351 (insert-char-attributes ret
355 (insert (prin1-to-string value)))
357 (insert line-breaking))
359 (insert (format "(%-18s " name))
360 (setq lbs (concat "\n" (make-string (current-column) ?\ )))
362 (setq cell (car value))
363 (if (and (consp cell)
365 (setq ret (condition-case nil
375 (setq key (car (car rest)))
376 ;; (if (find-charset key)
377 ;; (setq cal (cons key cal))
378 (setq al (cons key al))
380 (setq rest (cdr rest)))
383 (insert-char-attributes ret
387 (setq separator lbs))
390 (insert (prin1-to-string cell))
391 (setq separator " "))
392 (setq value (cdr value)))
394 (insert line-breaking))
396 (insert (format "(%-18s . %S)%s"
399 (setq alist (cdr alist))))
402 (defun char-db-insert-char-reference (plist &optional readable column)
404 (setq column (current-column)))
406 (concat "\n" (make-string (1+ column) ?\ )))
411 (setq name (pop plist))
412 (setq value (pop plist))
413 (cond ((eq name :char)
416 (cond ((numberp value)
417 (setq value (decode-char '=ucs value)))
419 ;; (setq value (or (find-char value)
422 (char-db-insert-char-spec value readable)
423 (insert line-breaking)
426 (insert (format "%s%s\t%d ; %c%s"
429 (ideographic-radical value)
433 (insert (format "%s%s\t%S" separator name value))
434 (setq separator line-breaking)))
438 (defun char-db-decode-isolated-char (ccs code-point)
441 (cond ((eq ccs 'arabic-iso8859-6)
442 (decode-char ccs code-point))
443 ((and (memq ccs '(=gt-pj-1
454 (setq ret (decode-char ccs code-point))
455 (setq ret (encode-char ret '=gt 'defined-only)))
456 (decode-builtin-char '=gt ret))
458 (decode-builtin-char ccs code-point))))
459 (cond ((and (<= 0 (char-int ret))
460 (<= (char-int ret) #x1F))
461 (decode-char '=ucs (+ #x2400 (char-int ret))))
462 ((= (char-int ret) #x7F)
466 (defvar char-db-convert-obsolete-format t)
468 (defun char-db-insert-ccs-feature (name value line-breaking)
474 ((memq name '(=shinjigen
476 =shinjigen@rev =shinjigen/+p@rev
478 "(%-18s . %04d)\t; %c")
479 ((eq name '=shinjigen@1ed/24pr)
480 "(%-18s . %04d)\t; %c")
481 ((or (memq name '(=daikanwa =>>daikanwa =>daikanwa
482 =daikanwa@rev1 =daikanwa@rev2
483 =daikanwa/+p =daikanwa/+2p
484 =gt =>>>gt =>>gt =>gt
488 =zinbun-oracle =>zinbun-oracle))
489 (string-match "^=adobe-" (symbol-name name)))
490 "(%-18s . %05d)\t; %c")
491 ((memq name '(=hanyo-denshi/ks =>>hanyo-denshi/ks mojikyo))
492 "(%-18s . %06d)\t; %c")
493 ((>= (charset-dimension name) 2)
494 "(%-18s . #x%04X)\t; %c")
496 "(%-18s . #x%02X)\t; %c"))
498 (if (= (charset-iso-graphic-plane name) 1)
500 (cond ((= (charset-dimension name) 1)
502 ((= (charset-dimension name) 2)
504 ((= (charset-dimension name) 3)
508 (char-db-decode-isolated-char name value)))
509 (if (and (= (charset-chars name) 94)
510 (= (charset-dimension name) 2))
511 (insert (format " [%02d-%02d]"
512 (- (lsh value -8) 32)
513 (- (logand value 255) 32))))
516 (insert (format "(%-18s . %s)" name value))
518 (insert line-breaking))
520 (defun char-db-insert-relation-feature (char name value line-breaking
522 (insert (format "(%-18s%s " name line-breaking))
523 (let ((lbs (concat "\n" (make-string (current-column) ?\ )))
524 separator cell sources required-features
527 (setq cell (car value))
529 (setq cell (decode-char '=ucs cell)))
531 ((eq name '->subsumptive)
532 (when (or (not (some (lambda (atr)
533 (get-char-attribute cell atr))
534 char-db-ignored-attributes))
536 (encode-char cell ccs 'defined-only))
540 (let ((char-db-ignored-attributes
542 char-db-ignored-attributes)))
543 (insert-char-attributes cell readable nil nil 'for-sub-node))
544 (setq separator lbs))
549 char (intern (format "%s*sources" name))))
550 (setq required-features nil)
551 (dolist (source sources)
555 shinjigen shinjigen@1ed shinjigen@rev))
556 (setq required-features
557 (union required-features
568 (setq required-features
569 (union required-features
574 ((find-charset (setq ret (intern (format "=%s" source))))
575 (setq required-features
576 (cons ret required-features)))
577 (t (setq required-features
578 (cons source required-features)))))
579 (cond ((string-match "@JP" (symbol-name name))
580 (setq required-features
581 (union required-features
589 ((string-match "@CN" (symbol-name name))
590 (setq required-features
591 (union required-features
598 (insert (format "%S" cell))
599 (char-db-insert-char-spec cell readable
602 (setq separator lbs))
606 (if (consp (car cell))
607 (char-db-insert-char-spec cell readable)
608 (char-db-insert-char-reference cell readable))
609 (setq separator lbs))
613 (insert (prin1-to-string cell))
614 (setq separator " ")))
615 (setq value (cdr value)))
617 (insert line-breaking)))
619 (defun insert-char-attributes (char &optional readable attributes column
622 (setq column (current-column)))
623 (let (name value ; has-long-ccs-name
627 (concat "\n" (make-string (1+ column) ?\ )))
628 lbs cell separator ret
630 dest-ccss ; sources required-features
635 (if (consp attributes)
637 (dolist (name attributes)
638 (unless (memq name char-db-ignored-attributes)
639 (if (find-charset name)
643 (dolist (name (char-attribute-list))
644 (unless (memq name char-db-ignored-attributes)
645 (if (find-charset name)
649 #'char-attribute-name<)))
651 (when (memq '<-subsumptive attributes)
652 (when (or readable (not for-sub-node))
653 (when (setq value (get-char-attribute char '<-subsumptive))
654 (char-db-insert-relation-feature char '<-subsumptive value
657 (setq attributes (delq '<-subsumptive attributes)))
658 (when (and (memq '<-denotational attributes)
659 (setq value (get-char-attribute char '<-denotational)))
660 (char-db-insert-relation-feature char '<-denotational value
663 (setq attributes (delq '<-denotational attributes)))
664 (when (and (memq 'name attributes)
665 (setq value (get-char-attribute char 'name)))
667 (if (> (+ (current-column) (length value)) 48)
670 value line-breaking))
671 (setq attributes (delq 'name attributes))
673 (when (and (memq 'name* attributes)
674 (setq value (get-char-attribute char 'name*)))
676 (if (> (+ (current-column) (length value)) 48)
679 value line-breaking))
680 (setq attributes (delq 'name* attributes))
682 (when (and (memq 'script attributes)
683 (setq value (get-char-attribute char 'script)))
684 (insert (format "(script\t\t%s)%s"
685 (mapconcat (function prin1-to-string)
688 (setq attributes (delq 'script attributes))
690 (dolist (name '(=>ucs =>ucs*))
691 (when (and (memq name attributes)
692 (setq value (get-char-attribute char name)))
693 (insert (format "(%-18s . #x%04X)\t; %c%s"
694 name value (decode-char '=ucs value)
696 (setq attributes (delq name attributes))))
697 (dolist (name '(=>ucs@gb =>ucs@big5))
698 (when (and (memq name attributes)
699 (setq value (get-char-attribute char name)))
700 (insert (format "(%-18s . #x%04X)\t; %c%s"
705 (symbol-name name) 2)))
708 (setq attributes (delq name attributes))
710 ;; (dolist (name '(=>daikanwa))
711 ;; (when (and (memq name attributes)
712 ;; (setq value (get-char-attribute char name)))
714 ;; (if (integerp value)
715 ;; (format "(%-18s . %05d)\t; %c%s"
716 ;; name value (decode-char '=daikanwa value)
718 ;; (format "(%-18s %s)\t; %c%s"
720 ;; (mapconcat (function prin1-to-string)
722 ;; (char-representative-of-daikanwa char)
724 ;; (setq attributes (delq name attributes))))
725 (when (and (memq 'general-category attributes)
726 (setq value (get-char-attribute char 'general-category)))
728 "(general-category\t%s) ; %s%s"
729 (mapconcat (lambda (cell)
732 (cond ((rassoc value unidata-normative-category-alist)
733 "Normative Category")
734 ((rassoc value unidata-informative-category-alist)
735 "Informative Category")
739 (setq attributes (delq 'general-category attributes))
741 (when (and (memq 'bidi-category attributes)
742 (setq value (get-char-attribute char 'bidi-category)))
743 (insert (format "(bidi-category\t. %S)%s"
746 (setq attributes (delq 'bidi-category attributes))
748 (unless (or (not (memq 'mirrored attributes))
749 (eq (setq value (get-char-attribute char 'mirrored 'empty))
751 (insert (format "(mirrored\t\t. %S)%s"
754 (setq attributes (delq 'mirrored attributes))
757 ((and (memq 'decimal-digit-value attributes)
758 (setq value (get-char-attribute char 'decimal-digit-value)))
759 (insert (format "(decimal-digit-value . %S)%s"
762 (setq attributes (delq 'decimal-digit-value attributes))
763 (when (and (memq 'digit-value attributes)
764 (setq value (get-char-attribute char 'digit-value)))
765 (insert (format "(digit-value\t . %S)%s"
768 (setq attributes (delq 'digit-value attributes))
770 (when (and (memq 'numeric-value attributes)
771 (setq value (get-char-attribute char 'numeric-value)))
772 (insert (format "(numeric-value\t . %S)%s"
775 (setq attributes (delq 'numeric-value attributes))
779 (when (and (memq 'digit-value attributes)
780 (setq value (get-char-attribute char 'digit-value)))
781 (insert (format "(digit-value\t. %S)%s"
784 (setq attributes (delq 'digit-value attributes))
786 (when (and (memq 'numeric-value attributes)
787 (setq value (get-char-attribute char 'numeric-value)))
788 (insert (format "(numeric-value\t. %S)%s"
791 (setq attributes (delq 'numeric-value attributes))
793 (when (and (memq 'iso-10646-comment attributes)
794 (setq value (get-char-attribute char 'iso-10646-comment)))
795 (insert (format "(iso-10646-comment\t. %S)%s"
798 (setq attributes (delq 'iso-10646-comment attributes))
800 (when (and (memq 'morohashi-daikanwa attributes)
801 (setq value (get-char-attribute char 'morohashi-daikanwa)))
802 (insert (format "(morohashi-daikanwa\t%s)%s"
803 (mapconcat (function prin1-to-string) value " ")
805 (setq attributes (delq 'morohashi-daikanwa attributes))
809 (when (and (memq 'ideographic-radical attributes)
810 (setq value (get-char-attribute char 'ideographic-radical)))
812 (insert (format "(ideographic-radical . %S)\t; %c%s"
814 (ideographic-radical radical)
816 (setq attributes (delq 'ideographic-radical attributes))
818 (when (and (memq 'shuowen-radical attributes)
819 (setq value (get-char-attribute char 'shuowen-radical)))
820 (insert (format "(shuowen-radical\t. %S)\t; %c%s"
822 (shuowen-radical value)
824 (setq attributes (delq 'shuowen-radical attributes))
829 char-db-feature-domains
831 (dolist (feature (char-attribute-list))
832 (setq feature (symbol-name feature))
834 "\\(radical\\|strokes\\)@\\([^@*]+\\)\\(\\*\\|$\\)"
836 (setq domain (intern (match-string 2 feature)))
837 (unless (memq domain dest)
838 (setq dest (cons domain dest)))))
839 (sort dest #'string<))))
840 (setq key (intern (format "%s@%s" 'ideographic-radical domain)))
841 (when (and (memq key attributes)
842 (setq value (get-char-attribute char key)))
844 (insert (format "(%s . %S)\t; %c%s"
847 (ideographic-radical radical)
849 (setq attributes (delq key attributes))
851 (setq key (intern (format "%s@%s" 'ideographic-strokes domain)))
852 (when (and (memq key attributes)
853 (setq value (get-char-attribute char key)))
855 (insert (format "(%s . %S)%s"
859 (setq attributes (delq key attributes))
861 (setq key (intern (format "%s@%s" 'total-strokes domain)))
862 (when (and (memq key attributes)
863 (setq value (get-char-attribute char key)))
864 (insert (format "(%s . %S)%s"
868 (setq attributes (delq key attributes))
870 (dolist (feature '(ideographic-radical
873 (setq key (intern (format "%s@%s*sources" feature domain)))
874 (when (and (memq key attributes)
875 (setq value (get-char-attribute char key)))
876 (insert (format "(%s%s" key line-breaking))
878 (insert (format " %s" cell)))
880 (insert line-breaking)
881 (setq attributes (delq key attributes))
884 (when (and (memq 'ideographic-strokes attributes)
885 (setq value (get-char-attribute char 'ideographic-strokes)))
887 (insert (format "(ideographic-strokes . %S)%s"
890 (setq attributes (delq 'ideographic-strokes attributes))
892 (when (and (memq 'kangxi-radical attributes)
893 (setq value (get-char-attribute char 'kangxi-radical)))
894 (unless (eq value radical)
895 (insert (format "(kangxi-radical\t . %S)\t; %c%s"
897 (ideographic-radical value)
900 (setq radical value)))
901 (setq attributes (delq 'kangxi-radical attributes))
903 (when (and (memq 'kangxi-strokes attributes)
904 (setq value (get-char-attribute char 'kangxi-strokes)))
905 (unless (eq value strokes)
906 (insert (format "(kangxi-strokes\t . %S)%s"
910 (setq strokes value)))
911 (setq attributes (delq 'kangxi-strokes attributes))
913 (when (and (memq 'japanese-radical attributes)
914 (setq value (get-char-attribute char 'japanese-radical)))
915 (unless (eq value radical)
916 (insert (format "(japanese-radical\t . %S)\t; %c%s"
918 (ideographic-radical value)
921 (setq radical value)))
922 (setq attributes (delq 'japanese-radical attributes))
924 (when (and (memq 'japanese-strokes attributes)
925 (setq value (get-char-attribute char 'japanese-strokes)))
926 (unless (eq value strokes)
927 (insert (format "(japanese-strokes\t . %S)%s"
931 (setq strokes value)))
932 (setq attributes (delq 'japanese-strokes attributes))
934 (when (and (memq 'cns-radical attributes)
935 (setq value (get-char-attribute char 'cns-radical)))
936 (insert (format "(cns-radical\t . %S)\t; %c%s"
938 (ideographic-radical value)
940 (setq attributes (delq 'cns-radical attributes))
942 (when (and (memq 'cns-strokes attributes)
943 (setq value (get-char-attribute char 'cns-strokes)))
944 (unless (eq value strokes)
945 (insert (format "(cns-strokes\t . %S)%s"
949 (setq strokes value)))
950 (setq attributes (delq 'cns-strokes attributes))
952 (when (and (memq 'shinjigen-1-radical attributes)
953 (setq value (get-char-attribute char 'shinjigen-1-radical)))
954 (unless (eq value radical)
955 (insert (format "(shinjigen-1-radical . %S)\t; %c%s"
957 (ideographic-radical value)
960 (setq radical value)))
961 (setq attributes (delq 'shinjigen-1-radical attributes))
963 (when (and (memq 'ideographic- attributes)
964 (setq value (get-char-attribute char 'ideographic-)))
965 (insert "(ideographic- ")
966 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
969 (setq cell (car value))
971 (setq cell (decode-char '=ucs cell)))
972 (cond ((characterp cell)
976 (insert (format "%S" cell))
977 (char-db-insert-char-spec cell readable))
978 (setq separator lbs))
982 (if (consp (car cell))
983 (char-db-insert-char-spec cell readable)
984 (char-db-insert-char-reference cell readable))
985 (setq separator lbs))
989 (insert (prin1-to-string cell))
990 (setq separator " ")))
991 (setq value (cdr value)))
993 (insert line-breaking)
994 (setq attributes (delq 'ideographic- attributes)))
995 (when (and (memq 'total-strokes attributes)
996 (setq value (get-char-attribute char 'total-strokes)))
997 (insert (format "(total-strokes . %S)%s"
1000 (setq attributes (delq 'total-strokes attributes))
1002 (when (and (memq '->ideograph attributes)
1003 (setq value (get-char-attribute char '->ideograph)))
1004 (insert (format "(->ideograph\t%s)%s"
1005 (mapconcat (lambda (code)
1006 (cond ((symbolp code)
1009 (format "#x%04X" code))
1012 line-breaking code))))
1015 (setq attributes (delq '->ideograph attributes))
1017 ;; (when (and (memq '->decomposition attributes)
1018 ;; (setq value (get-char-attribute char '->decomposition)))
1019 ;; (insert (format "(->decomposition\t%s)%s"
1020 ;; (mapconcat (lambda (code)
1021 ;; (cond ((symbolp code)
1022 ;; (symbol-name code))
1023 ;; ((characterp code)
1025 ;; (format "%S" code)
1030 ;; (format "#x%04X" code))
1032 ;; (format "%s%S" line-breaking code))))
1035 ;; (setq attributes (delq '->decomposition attributes))
1037 (if (equal (get-char-attribute char '->titlecase)
1038 (get-char-attribute char '->uppercase))
1039 (setq attributes (delq '->titlecase attributes)))
1040 (when (and (memq '->mojikyo attributes)
1041 (setq value (get-char-attribute char '->mojikyo)))
1042 (insert (format "(->mojikyo\t\t. %06d)\t; %c%s"
1043 value (decode-char 'mojikyo value)
1045 (setq attributes (delq '->mojikyo attributes))
1047 (when (and (memq 'hanyu-dazidian-vol attributes)
1048 (setq value (get-char-attribute char 'hanyu-dazidian-vol)))
1049 (insert (format "(hanyu-dazidian-vol . %d)%s"
1050 value line-breaking))
1051 (setq attributes (delq 'hanyu-dazidian-vol attributes))
1053 (when (and (memq 'hanyu-dazidian-page attributes)
1054 (setq value (get-char-attribute char 'hanyu-dazidian-page)))
1055 (insert (format "(hanyu-dazidian-page . %d)%s"
1056 value line-breaking))
1057 (setq attributes (delq 'hanyu-dazidian-page attributes))
1059 (when (and (memq 'hanyu-dazidian-char attributes)
1060 (setq value (get-char-attribute char 'hanyu-dazidian-char)))
1061 (insert (format "(hanyu-dazidian-char . %d)%s"
1062 value line-breaking))
1063 (setq attributes (delq 'hanyu-dazidian-char attributes))
1066 (dolist (ignored '(composition
1067 ->denotational <-subsumptive ->ucs-unified
1068 ->ideographic-component-forms))
1069 (setq attributes (delq ignored attributes))))
1071 (setq name (car attributes))
1072 (unless (eq (setq value (get-char-attribute char name 'value-is-empty))
1074 (cond ((setq ret (find-charset name))
1075 (setq name (charset-name ret))
1076 (when (not (memq name dest-ccss))
1077 (setq dest-ccss (cons name dest-ccss))
1078 (char-db-insert-ccs-feature name value line-breaking))
1080 ((string-match "^=>ucs@" (symbol-name name))
1081 (insert (format "(%-18s . #x%04X)\t; %c%s"
1082 name value (decode-char '=ucs value)
1085 ((eq name 'jisx0208-1978/4X)
1086 (insert (format "(%-18s . #x%04X)%s"
1092 (not (eq name '->subsumptive))
1093 (not (eq name '->uppercase))
1094 (not (eq name '->lowercase))
1095 (not (eq name '->titlecase))
1096 (not (eq name '->canonical))
1097 (not (eq name '->Bopomofo))
1098 (not (eq name '->mistakable))
1099 (not (eq name '->ideographic-variants))
1100 (null (get-char-attribute
1101 char (intern (format "%s*sources" name))))
1102 (not (string-match "\\*sources$" (symbol-name name)))
1103 (null (get-char-attribute
1104 char (intern (format "%s*note" name))))
1105 (not (string-match "\\*note$" (symbol-name name)))
1106 (or (eq name '<-identical)
1107 (eq name '<-uppercase)
1108 (eq name '<-lowercase)
1109 (eq name '<-titlecase)
1110 (eq name '<-canonical)
1111 (eq name '<-ideographic-variants)
1112 ;; (eq name '<-synonyms)
1113 (string-match "^<-synonyms" (symbol-name name))
1114 (eq name '<-mistakable)
1115 (when (string-match "^->" (symbol-name name))
1117 ((string-match "^->fullwidth" (symbol-name name))
1118 (not (and (consp value)
1119 (characterp (car value))
1121 (car value) '=ucs 'defined-only)))
1126 ((or (eq name 'ideographic-structure)
1127 (eq name 'ideographic-combination)
1128 (eq name 'ideographic-)
1129 (eq name '=decomposition)
1130 (char-feature-base-name= '=decomposition name)
1131 (char-feature-base-name= '=>decomposition name)
1132 ;; (string-match "^=>*decomposition\\(@[^*]+\\)?$"
1133 ;; (symbol-name name))
1134 (string-match "^\\(->\\|<-\\)[^*]*$" (symbol-name name))
1135 (string-match "^\\(->\\|<-\\)[^*]*\\*sources$"
1138 (char-db-insert-relation-feature char name value
1141 ((memq name '(ideograph=
1142 original-ideograph-of
1143 ancient-ideograph-of
1146 ;; simplified-ideograph-of
1147 ideographic-variants
1148 ;; ideographic-different-form-of
1150 (insert (format "(%-18s%s " name line-breaking))
1151 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1153 (while (consp value)
1154 (setq cell (car value))
1155 (if (and (consp cell)
1160 (char-db-insert-alist cell readable)
1161 (setq separator lbs))
1164 (insert (prin1-to-string cell))
1165 (setq separator " "))
1166 (setq value (cdr value)))
1168 (insert line-breaking))
1170 (insert (format "(%-18s " name))
1171 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1173 (while (consp value)
1174 (setq cell (car value))
1175 (if (and (consp cell)
1177 (setq ret (condition-case nil
1185 (setq key (car (car rest)))
1186 (if (find-charset key)
1187 (setq cal (cons key cal))
1188 (setq al (cons key al)))
1189 (setq rest (cdr rest)))
1192 (insert-char-attributes ret
1196 (setq separator lbs))
1197 (setq ret (prin1-to-string cell))
1199 (if (< (+ (current-column)
1206 (setq separator " "))
1207 (setq value (cdr value)))
1209 (insert line-breaking))
1211 (insert (format "(%-18s" name))
1212 (setq ret (prin1-to-string value))
1213 (unless (< (+ (current-column)
1217 (insert line-breaking))
1218 (insert " . " ret ")" line-breaking)
1219 ;; (insert (format "(%-18s . %S)%s"
1224 (setq attributes (cdr attributes)))
1227 (defun insert-char-data (char &optional readable
1230 (narrow-to-region (point)(point))
1231 (insert "(define-char
1233 (insert-char-attributes char readable attributes)
1235 (goto-char (point-min))
1236 (while (re-search-forward "[ \t]+$" nil t)
1239 (goto-char (point-min))
1240 (while (re-search-forward "[ \t][ \t][ \t]*" nil t)
1241 (let ((column (current-column))
1242 (indent-tabs-mode t))
1243 (delete-region (match-beginning 0) (point))
1244 (indent-to column)))
1245 (goto-char (point-max))
1246 ;; (tabify (point-min)(point-max))
1249 (defun insert-char-data-with-variant (char &optional printable
1251 script excluded-script)
1252 (insert-char-data char printable)
1253 (let ((variants (char-variants char))
1256 (setq variants (sort variants #'<))
1257 (setq rest variants)
1258 (setq variants (cons char variants))
1260 (setq variant (car rest))
1261 (unless (get-char-attribute variant '<-subsumptive)
1262 (if (and (or (null script)
1263 (null (setq vs (get-char-attribute variant 'script)))
1265 (or (null excluded-script)
1266 (null (setq vs (get-char-attribute variant 'script)))
1267 (not (memq excluded-script vs))))
1268 (unless (and no-ucs-unified (get-char-attribute variant '=ucs))
1269 (insert-char-data variant printable)
1270 (if (setq ret (char-variants variant))
1272 (or (memq (car ret) variants)
1273 ;; (get-char-attribute (car ret) '<-subsumptive)
1274 (setq rest (nconc rest (list (car ret)))))
1275 (setq ret (cdr ret)))))))
1276 (setq rest (cdr rest)))))
1278 (defun insert-char-range-data (min max &optional script excluded-script)
1281 (while (<= code max)
1282 (setq char (decode-char '=ucs code))
1283 (if (encode-char char '=ucs 'defined-only)
1284 (insert-char-data-with-variant char nil 'no-ucs-unified
1285 script excluded-script))
1286 (setq code (1+ code)))))
1288 (defun write-char-range-data-to-file (min max file
1289 &optional script excluded-script)
1290 (let ((coding-system-for-write char-db-file-coding-system))
1292 (insert (format ";; -*- coding: %s -*-\n"
1293 char-db-file-coding-system))
1294 (insert-char-range-data min max script excluded-script)
1295 (write-region (point-min)(point-max) file))))
1297 (defvar what-character-original-window-configuration)
1300 (defun what-char-definition (char)
1301 (interactive (list (char-after)))
1302 (let ((buf (get-buffer-create "*Character Description*"))
1303 (the-buf (current-buffer))
1304 (win-conf (current-window-configuration)))
1306 (make-local-variable 'what-character-original-window-configuration)
1307 (setq what-character-original-window-configuration win-conf)
1308 (setq buffer-read-only nil)
1312 (insert-char-data-with-variant char 'printable)
1313 (unless (char-attribute-alist char)
1314 (insert (format ";; = %c\n"
1315 (let* ((rest (split-char char))
1319 (setq code (logior (lsh code 8)
1321 (decode-char ccs code)))))
1322 ;; (char-db-update-comment)
1323 (set-buffer-modified-p nil)
1324 (view-mode the-buf (lambda (buf)
1325 (set-window-configuration
1326 what-character-original-window-configuration)
1328 (goto-char (point-min)))
1330 (set-window-configuration
1331 what-character-original-window-configuration)
1332 (signal (car err) (cdr err)))))))
1338 (provide 'char-db-util)
1340 ;;; char-db-util.el ends here