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
217 ;;; @ char-db formatters
220 (defun char-db-make-char-spec (char)
222 (cond ((characterp char)
223 (cond ((and (setq ret (encode-char char '=ucs 'defined-only))
224 (not (and (<= #xE000 ret)(<= ret #xF8FF))))
225 (setq char-spec (list (cons '=ucs ret)))
226 (cond ((setq ret (get-char-attribute char 'name))
227 (setq char-spec (cons (cons 'name ret) char-spec))
229 ((setq ret (get-char-attribute char 'name*))
230 (setq char-spec (cons (cons 'name* ret) char-spec))
235 (let ((rest char-db-coded-charset-priority-list)
238 (setq ccs (charset-name
239 (find-charset (car rest))))
241 (encode-char char ccs
243 (throw 'tag (cons ccs ret)))
244 (setq rest (cdr rest))))))
245 (setq char-spec (list ret))
246 (dolist (ccs (delq (car ret) (charset-list)))
247 (if (and (or (charset-iso-final-char ccs)
254 (string-match "=ucs@" (symbol-name ccs)))
255 (setq ccs (charset-name ccs))
256 (null (assq ccs char-spec))
257 (setq ret (encode-char char ccs 'defined-only)))
258 (setq char-spec (cons (cons ccs ret) char-spec))))
260 (setq char-spec (split-char char)))
261 (cond ((setq ret (get-char-attribute char 'name))
262 (setq char-spec (cons (cons 'name ret) char-spec))
264 ((setq ret (get-char-attribute char 'name*))
265 (setq char-spec (cons (cons 'name* ret) char-spec))
268 ((setq ret (get-char-attribute
269 char 'ideographic-combination))
271 (cons (cons 'ideographic-combination ret)
278 (defun char-db-insert-char-spec (char &optional readable column
281 (setq column (current-column)))
282 (let (char-spec temp-char)
283 (setq char-spec (char-db-make-char-spec char))
284 (unless (or (characterp char) ; char
286 (setq char (find-char char-spec))
288 ;; define temporary character
289 ;; Current implementation is dirty.
290 (setq temp-char (define-char (cons '(ideograph-daikanwa . 0)
292 (remove-char-attribute temp-char 'ideograph-daikanwa)
293 (setq char temp-char))
294 (insert-char-attributes char
296 (union (mapcar #'car char-spec)
299 ;; undefine temporary character
300 ;; Current implementation is dirty.
301 (setq char-spec (char-attribute-alist temp-char))
303 (remove-char-attribute temp-char (car (car char-spec)))
304 (setq char-spec (cdr char-spec))))))
306 (defun char-db-insert-alist (alist &optional readable column)
308 (setq column (current-column)))
310 (concat "\n" (make-string (1+ column) ?\ )))
314 lbs cell rest separator)
317 (setq name (car (car alist))
318 value (cdr (car alist)))
319 (cond ((eq name 'char)
321 (if (setq ret (condition-case nil
329 (setq key (car (car value)))
330 ;; (if (find-charset key)
331 ;; (setq cal (cons key cal))
332 (setq al (cons key al))
334 (setq value (cdr value)))
335 (insert-char-attributes ret
339 (insert (prin1-to-string value)))
341 (insert line-breaking))
343 (insert (format "(%-18s " name))
344 (setq lbs (concat "\n" (make-string (current-column) ?\ )))
346 (setq cell (car value))
347 (if (and (consp cell)
349 (setq ret (condition-case nil
359 (setq key (car (car rest)))
360 ;; (if (find-charset key)
361 ;; (setq cal (cons key cal))
362 (setq al (cons key al))
364 (setq rest (cdr rest)))
367 (insert-char-attributes ret
371 (setq separator lbs))
374 (insert (prin1-to-string cell))
375 (setq separator " "))
376 (setq value (cdr value)))
378 (insert line-breaking))
380 (insert (format "(%-18s . %S)%s"
383 (setq alist (cdr alist))))
386 (defun char-db-insert-char-reference (plist &optional readable column)
388 (setq column (current-column)))
390 (concat "\n" (make-string (1+ column) ?\ )))
395 (setq name (pop plist))
396 (setq value (pop plist))
397 (cond ((eq name :char)
400 (cond ((numberp value)
401 (setq value (decode-char '=ucs value)))
403 ;; (setq value (or (find-char value)
406 (char-db-insert-char-spec value readable)
407 (insert line-breaking)
410 (insert (format "%s%s\t%d ; %c%s"
413 (ideographic-radical value)
417 (insert (format "%s%s\t%S" separator name value))
418 (setq separator line-breaking)))
422 (defun char-db-decode-isolated-char (ccs code-point)
425 (cond ((eq ccs 'arabic-iso8859-6)
426 (decode-char ccs code-point))
427 ((and (memq ccs '(=gt-pj-1
438 (setq ret (decode-char ccs code-point))
439 (setq ret (encode-char ret '=gt 'defined-only)))
440 (decode-builtin-char '=gt ret))
442 (decode-builtin-char ccs code-point))))
443 (cond ((and (<= 0 (char-int ret))
444 (<= (char-int ret) #x1F))
445 (decode-char '=ucs (+ #x2400 (char-int ret))))
446 ((= (char-int ret) #x7F)
450 (defvar char-db-convert-obsolete-format t)
452 (defun char-db-insert-ccs-feature (name value line-breaking)
455 (cond ((memq name '(=shinjigen
457 =shinjigen@rev =shinjigen/+p@rev
459 "(%-18s . %04d)\t; %c")
460 ((eq name '=shinjigen@1ed/24pr)
461 "(%-18s . %04d)\t; %c")
462 ((or (memq name '(=daikanwa
463 =daikanwa@rev1 =daikanwa@rev2
464 =daikanwa/+p =daikanwa/+2p
465 =>>daikanwa =>daikanwa
466 =gt =>>gt =>gt =gt-k =>>gt-k =cbeta
467 =zinbun-oracle =>zinbun-oracle))
468 (string-match "^=adobe-" (symbol-name name)))
469 "(%-18s . %05d)\t; %c")
470 ((memq name '(=hanyo-denshi/ks mojikyo))
471 "(%-18s . %06d)\t; %c")
472 ((>= (charset-dimension name) 2)
473 "(%-18s . #x%04X)\t; %c")
475 "(%-18s . #x%02X)\t; %c"))
477 (if (= (charset-iso-graphic-plane name) 1)
479 (cond ((= (charset-dimension name) 1)
481 ((= (charset-dimension name) 2)
483 ((= (charset-dimension name) 3)
487 (char-db-decode-isolated-char name value)))
488 (if (and (= (charset-chars name) 94)
489 (= (charset-dimension name) 2))
490 (insert (format " [%02d-%02d]"
491 (- (lsh value -8) 32)
492 (- (logand value 255) 32))))
493 (insert line-breaking))
495 (defun char-db-insert-relation-feature (char name value line-breaking
497 (insert (format "(%-18s%s " name line-breaking))
498 (let ((lbs (concat "\n" (make-string (current-column) ?\ )))
499 separator cell sources required-features
502 (setq cell (car value))
504 (setq cell (decode-char '=ucs cell)))
506 ((eq name '->subsumptive)
507 (when (or (not (some (lambda (atr)
508 (get-char-attribute cell atr))
509 char-db-ignored-attributes))
511 (encode-char cell ccs 'defined-only))
515 (let ((char-db-ignored-attributes
517 char-db-ignored-attributes)))
518 (insert-char-attributes cell readable))
519 (setq separator lbs))
524 char (intern (format "%s*sources" name))))
525 (setq required-features nil)
526 (dolist (source sources)
530 shinjigen shinjigen@1ed shinjigen@rev))
531 (setq required-features
532 (union required-features
543 (setq required-features
544 (union required-features
549 ((find-charset (setq ret (intern (format "=%s" source))))
550 (setq required-features
551 (cons ret required-features)))
552 (t (setq required-features
553 (cons source required-features)))))
554 (cond ((string-match "@JP" (symbol-name name))
555 (setq required-features
556 (union required-features
564 ((string-match "@CN" (symbol-name name))
565 (setq required-features
566 (union required-features
573 (insert (format "%S" cell))
574 (char-db-insert-char-spec cell readable
577 (setq separator lbs))
581 (if (consp (car cell))
582 (char-db-insert-char-spec cell readable)
583 (char-db-insert-char-reference cell readable))
584 (setq separator lbs))
588 (insert (prin1-to-string cell))
589 (setq separator " ")))
590 (setq value (cdr value)))
592 (insert line-breaking)))
594 (defun insert-char-attributes (char &optional readable attributes column)
596 (setq column (current-column)))
597 (let (name value ; has-long-ccs-name
601 (concat "\n" (make-string (1+ column) ?\ )))
602 lbs cell separator ret
604 dest-ccss ; sources required-features
609 (if (consp attributes)
611 (dolist (name attributes)
612 (unless (memq name char-db-ignored-attributes)
613 (if (find-charset name)
617 (dolist (name (char-attribute-list))
618 (unless (memq name char-db-ignored-attributes)
619 (if (find-charset name)
623 #'char-attribute-name<)))
625 (when (memq '<-subsumptive attributes)
627 (when (setq value (get-char-attribute char '<-subsumptive))
628 (char-db-insert-relation-feature char '<-subsumptive value
631 (setq attributes (delq '<-subsumptive attributes)))
632 (when (and (memq '<-denotational attributes)
633 (setq value (get-char-attribute char '<-denotational)))
634 (char-db-insert-relation-feature char '<-denotational value
637 (setq attributes (delq '<-denotational attributes)))
638 (when (and (memq 'name attributes)
639 (setq value (get-char-attribute char 'name)))
641 (if (> (+ (current-column) (length value)) 48)
644 value line-breaking))
645 (setq attributes (delq 'name attributes))
647 (when (and (memq 'name* attributes)
648 (setq value (get-char-attribute char 'name*)))
650 (if (> (+ (current-column) (length value)) 48)
653 value line-breaking))
654 (setq attributes (delq 'name* attributes))
656 (when (and (memq 'script attributes)
657 (setq value (get-char-attribute char 'script)))
658 (insert (format "(script\t\t%s)%s"
659 (mapconcat (function prin1-to-string)
662 (setq attributes (delq 'script attributes))
664 (dolist (name '(=>ucs =>ucs*))
665 (when (and (memq name attributes)
666 (setq value (get-char-attribute char name)))
667 (insert (format "(%-18s . #x%04X)\t; %c%s"
668 name value (decode-char '=ucs value)
670 (setq attributes (delq name attributes))))
671 (dolist (name '(=>ucs@gb =>ucs@big5))
672 (when (and (memq name attributes)
673 (setq value (get-char-attribute char name)))
674 (insert (format "(%-18s . #x%04X)\t; %c%s"
679 (symbol-name name) 2)))
682 (setq attributes (delq name attributes))
684 ;; (dolist (name '(=>daikanwa))
685 ;; (when (and (memq name attributes)
686 ;; (setq value (get-char-attribute char name)))
688 ;; (if (integerp value)
689 ;; (format "(%-18s . %05d)\t; %c%s"
690 ;; name value (decode-char '=daikanwa value)
692 ;; (format "(%-18s %s)\t; %c%s"
694 ;; (mapconcat (function prin1-to-string)
696 ;; (char-representative-of-daikanwa char)
698 ;; (setq attributes (delq name attributes))))
699 (when (and (memq 'general-category attributes)
700 (setq value (get-char-attribute char 'general-category)))
702 "(general-category\t%s) ; %s%s"
703 (mapconcat (lambda (cell)
706 (cond ((rassoc value unidata-normative-category-alist)
707 "Normative Category")
708 ((rassoc value unidata-informative-category-alist)
709 "Informative Category")
713 (setq attributes (delq 'general-category attributes))
715 (when (and (memq 'bidi-category attributes)
716 (setq value (get-char-attribute char 'bidi-category)))
717 (insert (format "(bidi-category\t. %S)%s"
720 (setq attributes (delq 'bidi-category attributes))
722 (unless (or (not (memq 'mirrored attributes))
723 (eq (setq value (get-char-attribute char 'mirrored 'empty))
725 (insert (format "(mirrored\t\t. %S)%s"
728 (setq attributes (delq 'mirrored attributes))
731 ((and (memq 'decimal-digit-value attributes)
732 (setq value (get-char-attribute char 'decimal-digit-value)))
733 (insert (format "(decimal-digit-value . %S)%s"
736 (setq attributes (delq 'decimal-digit-value attributes))
737 (when (and (memq 'digit-value attributes)
738 (setq value (get-char-attribute char 'digit-value)))
739 (insert (format "(digit-value\t . %S)%s"
742 (setq attributes (delq 'digit-value attributes))
744 (when (and (memq 'numeric-value attributes)
745 (setq value (get-char-attribute char 'numeric-value)))
746 (insert (format "(numeric-value\t . %S)%s"
749 (setq attributes (delq 'numeric-value attributes))
753 (when (and (memq 'digit-value attributes)
754 (setq value (get-char-attribute char 'digit-value)))
755 (insert (format "(digit-value\t. %S)%s"
758 (setq attributes (delq 'digit-value attributes))
760 (when (and (memq 'numeric-value attributes)
761 (setq value (get-char-attribute char 'numeric-value)))
762 (insert (format "(numeric-value\t. %S)%s"
765 (setq attributes (delq 'numeric-value attributes))
767 (when (and (memq 'iso-10646-comment attributes)
768 (setq value (get-char-attribute char 'iso-10646-comment)))
769 (insert (format "(iso-10646-comment\t. %S)%s"
772 (setq attributes (delq 'iso-10646-comment attributes))
774 (when (and (memq 'morohashi-daikanwa attributes)
775 (setq value (get-char-attribute char 'morohashi-daikanwa)))
776 (insert (format "(morohashi-daikanwa\t%s)%s"
777 (mapconcat (function prin1-to-string) value " ")
779 (setq attributes (delq 'morohashi-daikanwa attributes))
783 (when (and (memq 'ideographic-radical attributes)
784 (setq value (get-char-attribute char 'ideographic-radical)))
786 (insert (format "(ideographic-radical . %S)\t; %c%s"
788 (ideographic-radical radical)
790 (setq attributes (delq 'ideographic-radical attributes))
792 (when (and (memq 'shuowen-radical attributes)
793 (setq value (get-char-attribute char 'shuowen-radical)))
794 (insert (format "(shuowen-radical\t. %S)\t; %c%s"
796 (shuowen-radical value)
798 (setq attributes (delq 'shuowen-radical attributes))
803 char-db-feature-domains
805 (dolist (feature (char-attribute-list))
806 (setq feature (symbol-name feature))
808 "\\(radical\\|strokes\\)@\\([^@*]+\\)\\(\\*\\|$\\)"
810 (setq domain (intern (match-string 2 feature)))
811 (unless (memq domain dest)
812 (setq dest (cons domain dest)))))
813 (sort dest #'string<))))
814 (setq key (intern (format "%s@%s" 'ideographic-radical domain)))
815 (when (and (memq key attributes)
816 (setq value (get-char-attribute char key)))
818 (insert (format "(%s . %S)\t; %c%s"
821 (ideographic-radical radical)
823 (setq attributes (delq key attributes))
825 (setq key (intern (format "%s@%s" 'ideographic-strokes domain)))
826 (when (and (memq key attributes)
827 (setq value (get-char-attribute char key)))
829 (insert (format "(%s . %S)%s"
833 (setq attributes (delq key attributes))
835 (setq key (intern (format "%s@%s" 'total-strokes domain)))
836 (when (and (memq key attributes)
837 (setq value (get-char-attribute char key)))
838 (insert (format "(%s . %S)%s"
842 (setq attributes (delq key attributes))
844 (dolist (feature '(ideographic-radical
847 (setq key (intern (format "%s@%s*sources" feature domain)))
848 (when (and (memq key attributes)
849 (setq value (get-char-attribute char key)))
850 (insert (format "(%s%s" key line-breaking))
852 (insert (format " %s" cell)))
854 (insert line-breaking)
855 (setq attributes (delq key attributes))
858 (when (and (memq 'ideographic-strokes attributes)
859 (setq value (get-char-attribute char 'ideographic-strokes)))
861 (insert (format "(ideographic-strokes . %S)%s"
864 (setq attributes (delq 'ideographic-strokes attributes))
866 (when (and (memq 'kangxi-radical attributes)
867 (setq value (get-char-attribute char 'kangxi-radical)))
868 (unless (eq value radical)
869 (insert (format "(kangxi-radical\t . %S)\t; %c%s"
871 (ideographic-radical value)
874 (setq radical value)))
875 (setq attributes (delq 'kangxi-radical attributes))
877 (when (and (memq 'kangxi-strokes attributes)
878 (setq value (get-char-attribute char 'kangxi-strokes)))
879 (unless (eq value strokes)
880 (insert (format "(kangxi-strokes\t . %S)%s"
884 (setq strokes value)))
885 (setq attributes (delq 'kangxi-strokes attributes))
887 (when (and (memq 'japanese-radical attributes)
888 (setq value (get-char-attribute char 'japanese-radical)))
889 (unless (eq value radical)
890 (insert (format "(japanese-radical\t . %S)\t; %c%s"
892 (ideographic-radical value)
895 (setq radical value)))
896 (setq attributes (delq 'japanese-radical attributes))
898 (when (and (memq 'japanese-strokes attributes)
899 (setq value (get-char-attribute char 'japanese-strokes)))
900 (unless (eq value strokes)
901 (insert (format "(japanese-strokes\t . %S)%s"
905 (setq strokes value)))
906 (setq attributes (delq 'japanese-strokes attributes))
908 (when (and (memq 'cns-radical attributes)
909 (setq value (get-char-attribute char 'cns-radical)))
910 (insert (format "(cns-radical\t . %S)\t; %c%s"
912 (ideographic-radical value)
914 (setq attributes (delq 'cns-radical attributes))
916 (when (and (memq 'cns-strokes attributes)
917 (setq value (get-char-attribute char 'cns-strokes)))
918 (unless (eq value strokes)
919 (insert (format "(cns-strokes\t . %S)%s"
923 (setq strokes value)))
924 (setq attributes (delq 'cns-strokes attributes))
926 (when (and (memq 'shinjigen-1-radical attributes)
927 (setq value (get-char-attribute char 'shinjigen-1-radical)))
928 (unless (eq value radical)
929 (insert (format "(shinjigen-1-radical . %S)\t; %c%s"
931 (ideographic-radical value)
934 (setq radical value)))
935 (setq attributes (delq 'shinjigen-1-radical attributes))
937 (when (and (memq 'ideographic- attributes)
938 (setq value (get-char-attribute char 'ideographic-)))
939 (insert "(ideographic- ")
940 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
943 (setq cell (car value))
945 (setq cell (decode-char '=ucs cell)))
946 (cond ((characterp cell)
950 (insert (format "%S" cell))
951 (char-db-insert-char-spec cell readable))
952 (setq separator lbs))
956 (if (consp (car cell))
957 (char-db-insert-char-spec cell readable)
958 (char-db-insert-char-reference cell readable))
959 (setq separator lbs))
963 (insert (prin1-to-string cell))
964 (setq separator " ")))
965 (setq value (cdr value)))
967 (insert line-breaking)
968 (setq attributes (delq 'ideographic- attributes)))
969 (when (and (memq 'total-strokes attributes)
970 (setq value (get-char-attribute char 'total-strokes)))
971 (insert (format "(total-strokes . %S)%s"
974 (setq attributes (delq 'total-strokes attributes))
976 (when (and (memq '->ideograph attributes)
977 (setq value (get-char-attribute char '->ideograph)))
978 (insert (format "(->ideograph\t%s)%s"
979 (mapconcat (lambda (code)
980 (cond ((symbolp code)
983 (format "#x%04X" code))
986 line-breaking code))))
989 (setq attributes (delq '->ideograph attributes))
991 ;; (when (and (memq '->decomposition attributes)
992 ;; (setq value (get-char-attribute char '->decomposition)))
993 ;; (insert (format "(->decomposition\t%s)%s"
994 ;; (mapconcat (lambda (code)
995 ;; (cond ((symbolp code)
996 ;; (symbol-name code))
997 ;; ((characterp code)
999 ;; (format "%S" code)
1004 ;; (format "#x%04X" code))
1006 ;; (format "%s%S" line-breaking code))))
1009 ;; (setq attributes (delq '->decomposition attributes))
1011 (if (equal (get-char-attribute char '->titlecase)
1012 (get-char-attribute char '->uppercase))
1013 (setq attributes (delq '->titlecase attributes)))
1014 (when (and (memq '->mojikyo attributes)
1015 (setq value (get-char-attribute char '->mojikyo)))
1016 (insert (format "(->mojikyo\t\t. %06d)\t; %c%s"
1017 value (decode-char 'mojikyo value)
1019 (setq attributes (delq '->mojikyo attributes))
1021 (when (and (memq 'hanyu-dazidian-vol attributes)
1022 (setq value (get-char-attribute char 'hanyu-dazidian-vol)))
1023 (insert (format "(hanyu-dazidian-vol . %d)%s"
1024 value line-breaking))
1025 (setq attributes (delq 'hanyu-dazidian-vol attributes))
1027 (when (and (memq 'hanyu-dazidian-page attributes)
1028 (setq value (get-char-attribute char 'hanyu-dazidian-page)))
1029 (insert (format "(hanyu-dazidian-page . %d)%s"
1030 value line-breaking))
1031 (setq attributes (delq 'hanyu-dazidian-page attributes))
1033 (when (and (memq 'hanyu-dazidian-char attributes)
1034 (setq value (get-char-attribute char 'hanyu-dazidian-char)))
1035 (insert (format "(hanyu-dazidian-char . %d)%s"
1036 value line-breaking))
1037 (setq attributes (delq 'hanyu-dazidian-char attributes))
1040 (dolist (ignored '(composition
1041 ->denotational <-subsumptive ->ucs-unified
1042 ->ideographic-component-forms))
1043 (setq attributes (delq ignored attributes))))
1045 (setq name (car attributes))
1046 (if (setq value (get-char-attribute char name))
1047 (cond ((setq ret (find-charset name))
1048 (setq name (charset-name ret))
1049 (if (and (not (memq name dest-ccss))
1051 (setq value (get-char-attribute char name))
1052 (setq dest-ccss (cons name dest-ccss))))
1053 (char-db-insert-ccs-feature name value line-breaking))
1055 ((string-match "^=>ucs@" (symbol-name name))
1056 (insert (format "(%-18s . #x%04X)\t; %c%s"
1057 name value (decode-char '=ucs value)
1060 ((eq name 'jisx0208-1978/4X)
1061 (insert (format "(%-18s . #x%04X)%s"
1067 (not (eq name '->subsumptive))
1068 (not (eq name '->uppercase))
1069 (not (eq name '->lowercase))
1070 (not (eq name '->titlecase))
1071 (not (eq name '->canonical))
1072 (not (eq name '->Bopomofo))
1073 (not (eq name '->mistakable))
1074 (not (eq name '->ideographic-variants))
1075 (null (get-char-attribute
1076 char (intern (format "%s*sources" name))))
1077 (not (string-match "\\*sources$" (symbol-name name)))
1078 (null (get-char-attribute
1079 char (intern (format "%s*note" name))))
1080 (not (string-match "\\*note$" (symbol-name name)))
1081 (or (eq name '<-identical)
1082 (eq name '<-uppercase)
1083 (eq name '<-lowercase)
1084 (eq name '<-titlecase)
1085 (eq name '<-canonical)
1086 (eq name '<-ideographic-variants)
1087 ;; (eq name '<-synonyms)
1088 (string-match "^<-synonyms" (symbol-name name))
1089 (eq name '<-mistakable)
1090 (when (string-match "^->" (symbol-name name))
1092 ((string-match "^->fullwidth" (symbol-name name))
1093 (not (and (consp value)
1094 (characterp (car value))
1096 (car value) '=ucs 'defined-only)))
1101 ((or (eq name 'ideographic-structure)
1102 (eq name 'ideographic-combination)
1103 (eq name 'ideographic-)
1104 (eq name '=decomposition)
1105 (string-match "^=>*decomposition\\(@[^*]+\\)?$"
1107 (string-match "^\\(->\\|<-\\)[^*]*$" (symbol-name name))
1108 (string-match "^\\(->\\|<-\\)[^*]*\\*sources$"
1111 (char-db-insert-relation-feature char name value
1114 ((memq name '(ideograph=
1115 original-ideograph-of
1116 ancient-ideograph-of
1119 ;; simplified-ideograph-of
1120 ideographic-variants
1121 ;; ideographic-different-form-of
1123 (insert (format "(%-18s%s " name line-breaking))
1124 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1126 (while (consp value)
1127 (setq cell (car value))
1128 (if (and (consp cell)
1133 (char-db-insert-alist cell readable)
1134 (setq separator lbs))
1137 (insert (prin1-to-string cell))
1138 (setq separator " "))
1139 (setq value (cdr value)))
1141 (insert line-breaking))
1143 (insert (format "(%-18s " name))
1144 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1146 (while (consp value)
1147 (setq cell (car value))
1148 (if (and (consp cell)
1150 (setq ret (condition-case nil
1158 (setq key (car (car rest)))
1159 (if (find-charset key)
1160 (setq cal (cons key cal))
1161 (setq al (cons key al)))
1162 (setq rest (cdr rest)))
1165 (insert-char-attributes ret
1168 (setq separator lbs))
1169 (setq ret (prin1-to-string cell))
1171 (if (< (+ (current-column)
1178 (setq separator " "))
1179 (setq value (cdr value)))
1181 (insert line-breaking))
1183 (insert (format "(%-18s" name))
1184 (setq ret (prin1-to-string value))
1185 (unless (< (+ (current-column)
1189 (insert line-breaking))
1190 (insert " . " ret ")" line-breaking)
1191 ;; (insert (format "(%-18s . %S)%s"
1196 (setq attributes (cdr attributes)))
1199 (defun insert-char-data (char &optional readable
1202 (narrow-to-region (point)(point))
1203 (insert "(define-char
1205 (insert-char-attributes char readable attributes)
1207 (goto-char (point-min))
1208 (while (re-search-forward "[ \t]+$" nil t)
1211 (goto-char (point-min))
1212 (while (re-search-forward "[ \t][ \t][ \t]*" nil t)
1213 (let ((column (current-column))
1214 (indent-tabs-mode t))
1215 (delete-region (match-beginning 0) (point))
1216 (indent-to column)))
1217 (goto-char (point-max))
1218 ;; (tabify (point-min)(point-max))
1221 (defun insert-char-data-with-variant (char &optional printable
1223 script excluded-script)
1224 (insert-char-data char printable)
1225 (let ((variants (char-variants char))
1228 (setq variants (sort variants #'<))
1229 (setq rest variants)
1230 (setq variants (cons char variants))
1232 (setq variant (car rest))
1233 (unless (get-char-attribute variant '<-subsumptive)
1234 (if (and (or (null script)
1235 (null (setq vs (get-char-attribute variant 'script)))
1237 (or (null excluded-script)
1238 (null (setq vs (get-char-attribute variant 'script)))
1239 (not (memq excluded-script vs))))
1240 (unless (and no-ucs-unified (get-char-attribute variant '=ucs))
1241 (insert-char-data variant printable)
1242 (if (setq ret (char-variants variant))
1244 (or (memq (car ret) variants)
1245 ;; (get-char-attribute (car ret) '<-subsumptive)
1246 (setq rest (nconc rest (list (car ret)))))
1247 (setq ret (cdr ret)))))))
1248 (setq rest (cdr rest)))))
1250 (defun insert-char-range-data (min max &optional script excluded-script)
1253 (while (<= code max)
1254 (setq char (decode-char '=ucs code))
1255 (if (encode-char char '=ucs 'defined-only)
1256 (insert-char-data-with-variant char nil 'no-ucs-unified
1257 script excluded-script))
1258 (setq code (1+ code)))))
1260 (defun write-char-range-data-to-file (min max file
1261 &optional script excluded-script)
1262 (let ((coding-system-for-write char-db-file-coding-system))
1264 (insert (format ";; -*- coding: %s -*-\n"
1265 char-db-file-coding-system))
1266 (insert-char-range-data min max script excluded-script)
1267 (write-region (point-min)(point-max) file))))
1269 (defvar what-character-original-window-configuration)
1272 (defun what-char-definition (char)
1273 (interactive (list (char-after)))
1274 (let ((buf (get-buffer-create "*Character Description*"))
1275 (the-buf (current-buffer))
1276 (win-conf (current-window-configuration)))
1278 (make-local-variable 'what-character-original-window-configuration)
1279 (setq what-character-original-window-configuration win-conf)
1280 (setq buffer-read-only nil)
1284 (insert-char-data-with-variant char 'printable)
1285 (unless (char-attribute-alist char)
1286 (insert (format ";; = %c\n"
1287 (let* ((rest (split-char char))
1291 (setq code (logior (lsh code 8)
1293 (decode-char ccs code)))))
1294 ;; (char-db-update-comment)
1295 (set-buffer-modified-p nil)
1296 (view-mode the-buf (lambda (buf)
1297 (set-window-configuration
1298 what-character-original-window-configuration)
1300 (goto-char (point-min)))
1302 (set-window-configuration
1303 what-character-original-window-configuration)
1304 (signal (car err) (cdr err)))))))
1310 (provide 'char-db-util)
1312 ;;; char-db-util.el ends here