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, 2012 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
243 ;;; @ char-db formatters
246 (defun char-db-make-char-spec (char)
248 (cond ((characterp char)
249 (cond ((and (setq ret (encode-char char '=ucs 'defined-only))
250 (not (and (<= #xE000 ret)(<= ret #xF8FF))))
251 (setq char-spec (list (cons '=ucs ret)))
252 (cond ((setq ret (get-char-attribute char 'name))
253 (setq char-spec (cons (cons 'name ret) char-spec))
255 ((setq ret (get-char-attribute char 'name*))
256 (setq char-spec (cons (cons 'name* ret) char-spec))
261 (let ((rest char-db-coded-charset-priority-list)
264 (setq ccs (charset-name
265 (find-charset (car rest))))
267 (encode-char char ccs
269 (throw 'tag (cons ccs ret)))
270 (setq rest (cdr rest))))))
271 (setq char-spec (list ret))
272 (dolist (ccs (delq (car ret) (charset-list)))
273 (if (and (or (charset-iso-final-char ccs)
280 (string-match "=ucs@" (symbol-name ccs)))
281 (setq ccs (charset-name ccs))
282 (null (assq ccs char-spec))
283 (setq ret (encode-char char ccs 'defined-only)))
284 (setq char-spec (cons (cons ccs ret) char-spec))))
286 (setq char-spec (split-char char)))
287 (cond ((setq ret (get-char-attribute char 'name))
288 (setq char-spec (cons (cons 'name ret) char-spec))
290 ((setq ret (get-char-attribute char 'name*))
291 (setq char-spec (cons (cons 'name* ret) char-spec))
294 ((setq ret (get-char-attribute
295 char 'ideographic-combination))
297 (cons (cons 'ideographic-combination ret)
304 (defun char-db-insert-char-spec (char &optional readable column
307 (setq column (current-column)))
308 (let (char-spec temp-char)
309 (setq char-spec (char-db-make-char-spec char))
310 (unless (or (characterp char) ; char
312 (setq char (find-char char-spec))
314 ;; define temporary character
315 ;; Current implementation is dirty.
316 (setq temp-char (define-char (cons '(ideograph-daikanwa . 0)
318 (remove-char-attribute temp-char 'ideograph-daikanwa)
319 (setq char temp-char))
320 (insert-char-attributes char
322 (union (mapcar #'car char-spec)
326 ;; undefine temporary character
327 ;; Current implementation is dirty.
328 (setq char-spec (char-attribute-alist temp-char))
330 (remove-char-attribute temp-char (car (car char-spec)))
331 (setq char-spec (cdr char-spec))))))
333 (defun char-db-insert-alist (alist &optional readable column)
335 (setq column (current-column)))
337 (concat "\n" (make-string (1+ column) ?\ )))
341 lbs cell rest separator)
344 (setq name (car (car alist))
345 value (cdr (car alist)))
346 (cond ((eq name 'char)
348 (if (setq ret (condition-case nil
356 (setq key (car (car value)))
357 ;; (if (find-charset key)
358 ;; (setq cal (cons key cal))
359 (setq al (cons key al))
361 (setq value (cdr value)))
362 (insert-char-attributes ret
366 (insert (prin1-to-string value)))
368 (insert line-breaking))
370 (insert (format "(%-18s " name))
371 (setq lbs (concat "\n" (make-string (current-column) ?\ )))
373 (setq cell (car value))
374 (if (and (consp cell)
376 (setq ret (condition-case nil
386 (setq key (car (car rest)))
387 ;; (if (find-charset key)
388 ;; (setq cal (cons key cal))
389 (setq al (cons key al))
391 (setq rest (cdr rest)))
394 (insert-char-attributes ret
398 (setq separator lbs))
401 (insert (prin1-to-string cell))
402 (setq separator " "))
403 (setq value (cdr value)))
405 (insert line-breaking))
407 (insert (format "(%-18s . %S)%s"
410 (setq alist (cdr alist))))
413 (defun char-db-insert-char-reference (plist &optional readable column)
415 (setq column (current-column)))
417 (concat "\n" (make-string (1+ column) ?\ )))
422 (setq name (pop plist))
423 (setq value (pop plist))
424 (cond ((eq name :char)
427 (cond ((numberp value)
428 (setq value (decode-char '=ucs value)))
430 ;; (setq value (or (find-char value)
433 (char-db-insert-char-spec value readable)
434 (insert line-breaking)
437 (insert (format "%s%s\t%d ; %c%s"
440 (ideographic-radical value)
444 (insert (format "%s%s\t%S" separator name value))
445 (setq separator line-breaking)))
449 (defun char-db-decode-isolated-char (ccs code-point)
452 (cond ((eq ccs 'arabic-iso8859-6)
453 (decode-char ccs code-point))
454 ((and (memq ccs '(=gt-pj-1
465 (setq ret (decode-char ccs code-point))
466 (setq ret (encode-char ret '=gt 'defined-only)))
467 (decode-builtin-char '=gt ret))
469 (decode-builtin-char ccs code-point))))
470 (cond ((and (<= 0 (char-int ret))
471 (<= (char-int ret) #x1F))
472 (decode-char '=ucs (+ #x2400 (char-int ret))))
473 ((= (char-int ret) #x7F)
477 (defvar char-db-convert-obsolete-format t)
479 (defun char-db-insert-ccs-feature (name value line-breaking)
485 ((memq name '(=shinjigen
487 =shinjigen@rev =shinjigen/+p@rev
488 =daikanwa/ho =>>daikanwa/ho))
489 "(%-18s . %04d)\t; %c")
490 ((eq name '=shinjigen@1ed/24pr)
491 "(%-18s . %04d)\t; %c")
492 ((or (memq name '(=daikanwa =>>daikanwa =>daikanwa
493 =daikanwa@rev1 =daikanwa@rev2
494 =daikanwa/+p =>>daikanwa/+p
496 =gt =>>>gt =>>gt =+>gt =>gt
498 =adobe-japan1-0 =>>>adobe-japan1-0 =>>adobe-japan1-0
499 =adobe-japan1-1 =>>>adobe-japan1-1 =>>adobe-japan1-1
500 =adobe-japan1-2 =>>>adobe-japan1-2 =>>adobe-japan1-2
501 =adobe-japan1-3 =>>>adobe-japan1-3 =>>adobe-japan1-3
502 =adobe-japan1-4 =>>>adobe-japan1-4 =>>adobe-japan1-4
503 =adobe-japan1-5 =>>>adobe-japan1-5 =>>adobe-japan1-5
504 =adobe-japan1-6 =>>>adobe-japan1-6 =>>adobe-japan1-6
507 =zinbun-oracle =>zinbun-oracle))
508 ;; (string-match "^=adobe-" (symbol-name name))
510 "(%-18s . %05d)\t; %c")
511 ((memq name '(=hanyo-denshi/ks =>>hanyo-denshi/ks mojikyo))
512 "(%-18s . %06d)\t; %c")
513 ((>= (charset-dimension name) 2)
514 "(%-18s . #x%04X)\t; %c")
516 "(%-18s . #x%02X)\t; %c"))
518 (if (= (charset-iso-graphic-plane name) 1)
520 (cond ((= (charset-dimension name) 1)
522 ((= (charset-dimension name) 2)
524 ((= (charset-dimension name) 3)
528 (char-db-decode-isolated-char name value)))
529 (if (and (= (charset-chars name) 94)
530 (= (charset-dimension name) 2))
531 (insert (format " [%02d-%02d]"
532 (- (lsh value -8) 32)
533 (- (logand value 255) 32))))
536 (insert (format "(%-18s . %s)" name value))
538 (insert line-breaking))
540 (defun char-db-insert-relation-feature (char name value line-breaking
542 (insert (format "(%-18s%s " name line-breaking))
543 (let ((lbs (concat "\n" (make-string (current-column) ?\ )))
544 separator cell sources required-features
547 (setq cell (car value))
549 (setq cell (decode-char '=ucs cell)))
551 ((eq name '->subsumptive)
552 (when (or (not (some (lambda (atr)
553 (get-char-attribute cell atr))
554 char-db-ignored-attributes))
556 (encode-char cell ccs 'defined-only))
560 (let ((char-db-ignored-attributes
562 char-db-ignored-attributes)))
563 (insert-char-attributes cell readable nil nil 'for-sub-node))
564 (setq separator lbs))
569 char (intern (format "%s*sources" name))))
570 (setq required-features nil)
571 (dolist (source sources)
575 shinjigen shinjigen@1ed shinjigen@rev))
576 (setq required-features
577 (union required-features
588 (setq required-features
589 (union required-features
594 ((find-charset (setq ret (intern (format "=%s" source))))
595 (setq required-features
596 (cons ret required-features)))
597 (t (setq required-features
598 (cons source required-features)))))
599 (cond ((string-match "@JP" (symbol-name name))
600 (setq required-features
601 (union required-features
609 ((string-match "@CN" (symbol-name name))
610 (setq required-features
611 (union required-features
618 (insert (format "%S" cell))
619 (char-db-insert-char-spec cell readable
622 (setq separator lbs))
626 (if (consp (car cell))
627 (char-db-insert-char-spec cell readable)
628 (char-db-insert-char-reference cell readable))
629 (setq separator lbs))
633 (insert (prin1-to-string cell))
634 (setq separator " ")))
635 (setq value (cdr value)))
637 (insert line-breaking)))
639 (defun insert-char-attributes (char &optional readable attributes column
642 (setq column (current-column)))
643 (let (name value ; has-long-ccs-name
647 (concat "\n" (make-string (1+ column) ?\ )))
648 lbs cell separator ret
650 dest-ccss ; sources required-features
655 (if (consp attributes)
657 (dolist (name attributes)
658 (unless (memq name char-db-ignored-attributes)
659 (if (find-charset name)
663 (dolist (name (char-attribute-list))
664 (unless (memq name char-db-ignored-attributes)
665 (if (find-charset name)
669 #'char-attribute-name<)))
671 (when (memq '<-subsumptive attributes)
672 (when (or readable (not for-sub-node))
673 (when (setq value (get-char-attribute char '<-subsumptive))
674 (char-db-insert-relation-feature char '<-subsumptive value
677 (setq attributes (delq '<-subsumptive attributes)))
678 (when (and (memq '<-denotational attributes)
679 (setq value (get-char-attribute char '<-denotational)))
680 (char-db-insert-relation-feature char '<-denotational value
683 (setq attributes (delq '<-denotational attributes)))
684 (when (and (memq 'name attributes)
685 (setq value (get-char-attribute char 'name)))
687 (if (> (+ (current-column) (length value)) 48)
690 value line-breaking))
691 (setq attributes (delq 'name attributes))
693 (when (and (memq 'name* attributes)
694 (setq value (get-char-attribute char 'name*)))
696 (if (> (+ (current-column) (length value)) 48)
699 value line-breaking))
700 (setq attributes (delq 'name* attributes))
702 (when (and (memq 'script attributes)
703 (setq value (get-char-attribute char 'script)))
704 (insert (format "(script\t\t%s)%s"
705 (mapconcat (function prin1-to-string)
708 (setq attributes (delq 'script attributes))
710 (dolist (name '(=>ucs =>ucs*))
711 (when (and (memq name attributes)
712 (setq value (get-char-attribute char name)))
713 (insert (format "(%-18s . #x%04X)\t; %c%s"
714 name value (decode-char '=ucs value)
716 (setq attributes (delq name attributes))))
717 (dolist (name '(=>ucs@gb =>ucs@big5))
718 (when (and (memq name attributes)
719 (setq value (get-char-attribute char name)))
720 (insert (format "(%-18s . #x%04X)\t; %c%s"
725 (symbol-name name) 2)))
728 (setq attributes (delq name attributes))
730 ;; (dolist (name '(=>daikanwa))
731 ;; (when (and (memq name attributes)
732 ;; (setq value (get-char-attribute char name)))
734 ;; (if (integerp value)
735 ;; (format "(%-18s . %05d)\t; %c%s"
736 ;; name value (decode-char '=daikanwa value)
738 ;; (format "(%-18s %s)\t; %c%s"
740 ;; (mapconcat (function prin1-to-string)
742 ;; (char-representative-of-daikanwa char)
744 ;; (setq attributes (delq name attributes))))
745 (when (and (memq 'general-category attributes)
746 (setq value (get-char-attribute char 'general-category)))
748 "(general-category\t%s) ; %s%s"
749 (mapconcat (lambda (cell)
752 (cond ((rassoc value unidata-normative-category-alist)
753 "Normative Category")
754 ((rassoc value unidata-informative-category-alist)
755 "Informative Category")
759 (setq attributes (delq 'general-category attributes))
761 (when (and (memq 'bidi-category attributes)
762 (setq value (get-char-attribute char 'bidi-category)))
763 (insert (format "(bidi-category\t. %S)%s"
766 (setq attributes (delq 'bidi-category attributes))
768 (unless (or (not (memq 'mirrored attributes))
769 (eq (setq value (get-char-attribute char 'mirrored 'empty))
771 (insert (format "(mirrored\t\t. %S)%s"
774 (setq attributes (delq 'mirrored attributes))
777 ((and (memq 'decimal-digit-value attributes)
778 (setq value (get-char-attribute char 'decimal-digit-value)))
779 (insert (format "(decimal-digit-value . %S)%s"
782 (setq attributes (delq 'decimal-digit-value attributes))
783 (when (and (memq 'digit-value attributes)
784 (setq value (get-char-attribute char 'digit-value)))
785 (insert (format "(digit-value\t . %S)%s"
788 (setq attributes (delq 'digit-value attributes))
790 (when (and (memq 'numeric-value attributes)
791 (setq value (get-char-attribute char 'numeric-value)))
792 (insert (format "(numeric-value\t . %S)%s"
795 (setq attributes (delq 'numeric-value attributes))
799 (when (and (memq 'digit-value attributes)
800 (setq value (get-char-attribute char 'digit-value)))
801 (insert (format "(digit-value\t. %S)%s"
804 (setq attributes (delq 'digit-value attributes))
806 (when (and (memq 'numeric-value attributes)
807 (setq value (get-char-attribute char 'numeric-value)))
808 (insert (format "(numeric-value\t. %S)%s"
811 (setq attributes (delq 'numeric-value attributes))
813 (when (and (memq 'iso-10646-comment attributes)
814 (setq value (get-char-attribute char 'iso-10646-comment)))
815 (insert (format "(iso-10646-comment\t. %S)%s"
818 (setq attributes (delq 'iso-10646-comment attributes))
820 (when (and (memq 'morohashi-daikanwa attributes)
821 (setq value (get-char-attribute char 'morohashi-daikanwa)))
822 (insert (format "(morohashi-daikanwa\t%s)%s"
823 (mapconcat (function prin1-to-string) value " ")
825 (setq attributes (delq 'morohashi-daikanwa attributes))
829 (when (and (memq 'ideographic-radical attributes)
830 (setq value (get-char-attribute char 'ideographic-radical)))
832 (insert (format "(ideographic-radical . %S)\t; %c%s"
834 (ideographic-radical radical)
836 (setq attributes (delq 'ideographic-radical attributes))
838 (when (and (memq 'shuowen-radical attributes)
839 (setq value (get-char-attribute char 'shuowen-radical)))
840 (insert (format "(shuowen-radical\t. %S)\t; %c%s"
842 (shuowen-radical value)
844 (setq attributes (delq 'shuowen-radical attributes))
849 char-db-feature-domains
851 (dolist (feature (char-attribute-list))
852 (setq feature (symbol-name feature))
854 "\\(radical\\|strokes\\)@\\([^@*]+\\)\\(\\*\\|$\\)"
856 (setq domain (intern (match-string 2 feature)))
857 (unless (memq domain dest)
858 (setq dest (cons domain dest)))))
859 (sort dest #'string<))))
860 (setq key (intern (format "%s@%s" 'ideographic-radical domain)))
861 (when (and (memq key attributes)
862 (setq value (get-char-attribute char key)))
864 (insert (format "(%s . %S)\t; %c%s"
867 (ideographic-radical radical)
869 (setq attributes (delq key attributes))
871 (setq key (intern (format "%s@%s" 'ideographic-strokes domain)))
872 (when (and (memq key attributes)
873 (setq value (get-char-attribute char key)))
875 (insert (format "(%s . %S)%s"
879 (setq attributes (delq key attributes))
881 (setq key (intern (format "%s@%s" 'total-strokes domain)))
882 (when (and (memq key attributes)
883 (setq value (get-char-attribute char key)))
884 (insert (format "(%s . %S)%s"
888 (setq attributes (delq key attributes))
890 (dolist (feature '(ideographic-radical
893 (setq key (intern (format "%s@%s*sources" feature domain)))
894 (when (and (memq key attributes)
895 (setq value (get-char-attribute char key)))
896 (insert (format "(%s%s" key line-breaking))
898 (insert (format " %s" cell)))
900 (insert line-breaking)
901 (setq attributes (delq key attributes))
904 (when (and (memq 'ideographic-strokes attributes)
905 (setq value (get-char-attribute char 'ideographic-strokes)))
907 (insert (format "(ideographic-strokes . %S)%s"
910 (setq attributes (delq 'ideographic-strokes attributes))
912 (when (and (memq 'kangxi-radical attributes)
913 (setq value (get-char-attribute char 'kangxi-radical)))
914 (unless (eq value radical)
915 (insert (format "(kangxi-radical\t . %S)\t; %c%s"
917 (ideographic-radical value)
920 (setq radical value)))
921 (setq attributes (delq 'kangxi-radical attributes))
923 (when (and (memq 'kangxi-strokes attributes)
924 (setq value (get-char-attribute char 'kangxi-strokes)))
925 (unless (eq value strokes)
926 (insert (format "(kangxi-strokes\t . %S)%s"
930 (setq strokes value)))
931 (setq attributes (delq 'kangxi-strokes attributes))
933 (when (and (memq 'japanese-radical attributes)
934 (setq value (get-char-attribute char 'japanese-radical)))
935 (unless (eq value radical)
936 (insert (format "(japanese-radical\t . %S)\t; %c%s"
938 (ideographic-radical value)
941 (setq radical value)))
942 (setq attributes (delq 'japanese-radical attributes))
944 (when (and (memq 'japanese-strokes attributes)
945 (setq value (get-char-attribute char 'japanese-strokes)))
946 (unless (eq value strokes)
947 (insert (format "(japanese-strokes\t . %S)%s"
951 (setq strokes value)))
952 (setq attributes (delq 'japanese-strokes attributes))
954 (when (and (memq 'cns-radical attributes)
955 (setq value (get-char-attribute char 'cns-radical)))
956 (insert (format "(cns-radical\t . %S)\t; %c%s"
958 (ideographic-radical value)
960 (setq attributes (delq 'cns-radical attributes))
962 (when (and (memq 'cns-strokes attributes)
963 (setq value (get-char-attribute char 'cns-strokes)))
964 (unless (eq value strokes)
965 (insert (format "(cns-strokes\t . %S)%s"
969 (setq strokes value)))
970 (setq attributes (delq 'cns-strokes attributes))
972 (when (and (memq 'shinjigen-1-radical attributes)
973 (setq value (get-char-attribute char 'shinjigen-1-radical)))
974 (unless (eq value radical)
975 (insert (format "(shinjigen-1-radical . %S)\t; %c%s"
977 (ideographic-radical value)
980 (setq radical value)))
981 (setq attributes (delq 'shinjigen-1-radical attributes))
983 (when (and (memq 'ideographic- attributes)
984 (setq value (get-char-attribute char 'ideographic-)))
985 (insert "(ideographic- ")
986 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
989 (setq cell (car value))
991 (setq cell (decode-char '=ucs cell)))
992 (cond ((characterp cell)
996 (insert (format "%S" cell))
997 (char-db-insert-char-spec cell readable))
998 (setq separator lbs))
1002 (if (consp (car cell))
1003 (char-db-insert-char-spec cell readable)
1004 (char-db-insert-char-reference cell readable))
1005 (setq separator lbs))
1009 (insert (prin1-to-string cell))
1010 (setq separator " ")))
1011 (setq value (cdr value)))
1013 (insert line-breaking)
1014 (setq attributes (delq 'ideographic- attributes)))
1015 (when (and (memq 'total-strokes attributes)
1016 (setq value (get-char-attribute char 'total-strokes)))
1017 (insert (format "(total-strokes . %S)%s"
1020 (setq attributes (delq 'total-strokes attributes))
1022 (when (and (memq '->ideograph attributes)
1023 (setq value (get-char-attribute char '->ideograph)))
1024 (insert (format "(->ideograph\t%s)%s"
1025 (mapconcat (lambda (code)
1026 (cond ((symbolp code)
1029 (format "#x%04X" code))
1032 line-breaking code))))
1035 (setq attributes (delq '->ideograph attributes))
1037 ;; (when (and (memq '->decomposition attributes)
1038 ;; (setq value (get-char-attribute char '->decomposition)))
1039 ;; (insert (format "(->decomposition\t%s)%s"
1040 ;; (mapconcat (lambda (code)
1041 ;; (cond ((symbolp code)
1042 ;; (symbol-name code))
1043 ;; ((characterp code)
1045 ;; (format "%S" code)
1050 ;; (format "#x%04X" code))
1052 ;; (format "%s%S" line-breaking code))))
1055 ;; (setq attributes (delq '->decomposition attributes))
1057 (if (equal (get-char-attribute char '->titlecase)
1058 (get-char-attribute char '->uppercase))
1059 (setq attributes (delq '->titlecase attributes)))
1060 (when (and (memq '->mojikyo attributes)
1061 (setq value (get-char-attribute char '->mojikyo)))
1062 (insert (format "(->mojikyo\t\t. %06d)\t; %c%s"
1063 value (decode-char 'mojikyo value)
1065 (setq attributes (delq '->mojikyo attributes))
1067 (when (and (memq 'hanyu-dazidian-vol attributes)
1068 (setq value (get-char-attribute char 'hanyu-dazidian-vol)))
1069 (insert (format "(hanyu-dazidian-vol . %d)%s"
1070 value line-breaking))
1071 (setq attributes (delq 'hanyu-dazidian-vol attributes))
1073 (when (and (memq 'hanyu-dazidian-page attributes)
1074 (setq value (get-char-attribute char 'hanyu-dazidian-page)))
1075 (insert (format "(hanyu-dazidian-page . %d)%s"
1076 value line-breaking))
1077 (setq attributes (delq 'hanyu-dazidian-page attributes))
1079 (when (and (memq 'hanyu-dazidian-char attributes)
1080 (setq value (get-char-attribute char 'hanyu-dazidian-char)))
1081 (insert (format "(hanyu-dazidian-char . %d)%s"
1082 value line-breaking))
1083 (setq attributes (delq 'hanyu-dazidian-char attributes))
1086 (dolist (ignored '(composition
1087 ->denotational <-subsumptive ->ucs-unified
1088 ->ideographic-component-forms))
1089 (setq attributes (delq ignored attributes))))
1091 (setq name (car attributes))
1092 (unless (eq (setq value (get-char-attribute char name 'value-is-empty))
1094 (cond ((setq ret (find-charset name))
1095 (setq name (charset-name ret))
1096 (when (not (memq name dest-ccss))
1097 (setq dest-ccss (cons name dest-ccss))
1098 (char-db-insert-ccs-feature name value line-breaking))
1100 ((string-match "^=>ucs@" (symbol-name name))
1101 (insert (format "(%-18s . #x%04X)\t; %c%s"
1102 name value (decode-char '=ucs value)
1105 ((eq name 'jisx0208-1978/4X)
1106 (insert (format "(%-18s . #x%04X)%s"
1112 (not (eq name '->subsumptive))
1113 (not (eq name '->uppercase))
1114 (not (eq name '->lowercase))
1115 (not (eq name '->titlecase))
1116 (not (eq name '->canonical))
1117 (not (eq name '->Bopomofo))
1118 (not (eq name '->mistakable))
1119 (not (eq name '->ideographic-variants))
1120 (null (get-char-attribute
1121 char (intern (format "%s*sources" name))))
1122 (not (string-match "\\*sources$" (symbol-name name)))
1123 (null (get-char-attribute
1124 char (intern (format "%s*note" name))))
1125 (not (string-match "\\*note$" (symbol-name name)))
1126 (or (eq name '<-identical)
1127 (eq name '<-uppercase)
1128 (eq name '<-lowercase)
1129 (eq name '<-titlecase)
1130 (eq name '<-canonical)
1131 (eq name '<-ideographic-variants)
1132 ;; (eq name '<-synonyms)
1133 (string-match "^<-synonyms" (symbol-name name))
1134 (eq name '<-mistakable)
1135 (when (string-match "^->" (symbol-name name))
1137 ((string-match "^->fullwidth" (symbol-name name))
1138 (not (and (consp value)
1139 (characterp (car value))
1141 (car value) '=ucs 'defined-only)))
1146 ((or (eq name 'ideographic-structure)
1147 (eq name 'ideographic-combination)
1148 (eq name 'ideographic-)
1149 (eq name '=decomposition)
1150 (char-feature-base-name= '=decomposition name)
1151 (char-feature-base-name= '=>decomposition name)
1152 ;; (string-match "^=>*decomposition\\(@[^*]+\\)?$"
1153 ;; (symbol-name name))
1154 (string-match "^\\(->\\|<-\\)[^*]*$" (symbol-name name))
1155 (string-match "^\\(->\\|<-\\)[^*]*\\*sources$"
1158 (char-db-insert-relation-feature char name value
1161 ((memq name '(ideograph=
1162 original-ideograph-of
1163 ancient-ideograph-of
1166 ;; simplified-ideograph-of
1167 ideographic-variants
1168 ;; ideographic-different-form-of
1170 (insert (format "(%-18s%s " name line-breaking))
1171 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1173 (while (consp value)
1174 (setq cell (car value))
1175 (if (and (consp cell)
1180 (char-db-insert-alist cell readable)
1181 (setq separator lbs))
1184 (insert (prin1-to-string cell))
1185 (setq separator " "))
1186 (setq value (cdr value)))
1188 (insert line-breaking))
1190 (insert (format "(%-18s " name))
1191 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1193 (while (consp value)
1194 (setq cell (car value))
1195 (if (and (consp cell)
1197 (setq ret (condition-case nil
1205 (setq key (car (car rest)))
1206 (if (find-charset key)
1207 (setq cal (cons key cal))
1208 (setq al (cons key al)))
1209 (setq rest (cdr rest)))
1212 (insert-char-attributes ret
1216 (setq separator lbs))
1217 (setq ret (prin1-to-string cell))
1219 (if (< (+ (current-column)
1226 (setq separator " "))
1227 (setq value (cdr value)))
1229 (insert line-breaking))
1231 (insert (format "(%-18s" name))
1232 (setq ret (prin1-to-string value))
1233 (unless (< (+ (current-column)
1237 (insert line-breaking))
1238 (insert " . " ret ")" line-breaking)
1239 ;; (insert (format "(%-18s . %S)%s"
1244 (setq attributes (cdr attributes)))
1247 (defun insert-char-data (char &optional readable
1250 (narrow-to-region (point)(point))
1251 (insert "(define-char
1253 (insert-char-attributes char readable attributes)
1255 (goto-char (point-min))
1256 (while (re-search-forward "[ \t]+$" nil t)
1259 (goto-char (point-min))
1260 (while (re-search-forward "[ \t][ \t][ \t]*" nil t)
1261 (let ((column (current-column))
1262 (indent-tabs-mode t))
1263 (delete-region (match-beginning 0) (point))
1264 (indent-to column)))
1265 (goto-char (point-max))
1266 ;; (tabify (point-min)(point-max))
1269 (defun insert-char-data-with-variant (char &optional printable
1271 script excluded-script)
1272 (insert-char-data char printable)
1273 (let ((variants (char-variants char))
1276 (setq variants (sort variants #'<))
1277 (setq rest variants)
1278 (setq variants (cons char variants))
1280 (setq variant (car rest))
1281 (unless (get-char-attribute variant '<-subsumptive)
1282 (if (and (or (null script)
1283 (null (setq vs (get-char-attribute variant 'script)))
1285 (or (null excluded-script)
1286 (null (setq vs (get-char-attribute variant 'script)))
1287 (not (memq excluded-script vs))))
1288 (unless (and no-ucs-unified (get-char-attribute variant '=ucs))
1289 (insert-char-data variant printable)
1290 (if (setq ret (char-variants variant))
1292 (or (memq (car ret) variants)
1293 ;; (get-char-attribute (car ret) '<-subsumptive)
1294 (setq rest (nconc rest (list (car ret)))))
1295 (setq ret (cdr ret)))))))
1296 (setq rest (cdr rest)))))
1298 (defun insert-char-range-data (min max &optional script excluded-script)
1301 (while (<= code max)
1302 (setq char (decode-char '=ucs code))
1303 (if (encode-char char '=ucs 'defined-only)
1304 (insert-char-data-with-variant char nil 'no-ucs-unified
1305 script excluded-script))
1306 (setq code (1+ code)))))
1308 (defun write-char-range-data-to-file (min max file
1309 &optional script excluded-script)
1310 (let ((coding-system-for-write char-db-file-coding-system))
1312 (insert (format ";; -*- coding: %s -*-\n"
1313 char-db-file-coding-system))
1314 (insert-char-range-data min max script excluded-script)
1315 (write-region (point-min)(point-max) file))))
1317 (defvar what-character-original-window-configuration)
1320 (defun what-char-definition (char)
1321 (interactive (list (char-after)))
1322 (let ((buf (get-buffer-create "*Character Description*"))
1323 (the-buf (current-buffer))
1324 (win-conf (current-window-configuration)))
1326 (make-local-variable 'what-character-original-window-configuration)
1327 (setq what-character-original-window-configuration win-conf)
1328 (setq buffer-read-only nil)
1332 (insert-char-data-with-variant char 'printable)
1333 (unless (char-attribute-alist char)
1334 (insert (format ";; = %c\n"
1335 (let* ((rest (split-char char))
1339 (setq code (logior (lsh code 8)
1341 (decode-char ccs code)))))
1342 ;; (char-db-update-comment)
1343 (set-buffer-modified-p nil)
1344 (view-mode the-buf (lambda (buf)
1345 (set-window-configuration
1346 what-character-original-window-configuration)
1348 (goto-char (point-min)))
1350 (set-window-configuration
1351 what-character-original-window-configuration)
1352 (signal (car err) (cdr err)))))))
1358 (provide 'char-db-util)
1360 ;;; char-db-util.el ends here