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
225 ;;; @ char-db formatters
228 (defun char-db-make-char-spec (char)
230 (cond ((characterp char)
231 (cond ((and (setq ret (encode-char char '=ucs 'defined-only))
232 (not (and (<= #xE000 ret)(<= ret #xF8FF))))
233 (setq char-spec (list (cons '=ucs ret)))
234 (cond ((setq ret (get-char-attribute char 'name))
235 (setq char-spec (cons (cons 'name ret) char-spec))
237 ((setq ret (get-char-attribute char 'name*))
238 (setq char-spec (cons (cons 'name* ret) char-spec))
243 (let ((rest char-db-coded-charset-priority-list)
246 (setq ccs (charset-name
247 (find-charset (car rest))))
249 (encode-char char ccs
251 (throw 'tag (cons ccs ret)))
252 (setq rest (cdr rest))))))
253 (setq char-spec (list ret))
254 (dolist (ccs (delq (car ret) (charset-list)))
255 (if (and (or (charset-iso-final-char ccs)
262 (string-match "=ucs@" (symbol-name ccs)))
263 (setq ccs (charset-name ccs))
264 (null (assq ccs char-spec))
265 (setq ret (encode-char char ccs 'defined-only)))
266 (setq char-spec (cons (cons ccs ret) char-spec))))
268 (setq char-spec (split-char char)))
269 (cond ((setq ret (get-char-attribute char 'name))
270 (setq char-spec (cons (cons 'name ret) char-spec))
272 ((setq ret (get-char-attribute char 'name*))
273 (setq char-spec (cons (cons 'name* ret) char-spec))
276 ((setq ret (get-char-attribute
277 char 'ideographic-combination))
279 (cons (cons 'ideographic-combination ret)
286 (defun char-db-insert-char-spec (char &optional readable column
289 (setq column (current-column)))
290 (let (char-spec temp-char)
291 (setq char-spec (char-db-make-char-spec char))
292 (unless (or (characterp char) ; char
294 (setq char (find-char char-spec))
296 ;; define temporary character
297 ;; Current implementation is dirty.
298 (setq temp-char (define-char (cons '(ideograph-daikanwa . 0)
300 (remove-char-attribute temp-char 'ideograph-daikanwa)
301 (setq char temp-char))
302 (insert-char-attributes char
304 (union (mapcar #'car char-spec)
307 ;; undefine temporary character
308 ;; Current implementation is dirty.
309 (setq char-spec (char-attribute-alist temp-char))
311 (remove-char-attribute temp-char (car (car char-spec)))
312 (setq char-spec (cdr char-spec))))))
314 (defun char-db-insert-alist (alist &optional readable column)
316 (setq column (current-column)))
318 (concat "\n" (make-string (1+ column) ?\ )))
322 lbs cell rest separator)
325 (setq name (car (car alist))
326 value (cdr (car alist)))
327 (cond ((eq name 'char)
329 (if (setq ret (condition-case nil
337 (setq key (car (car value)))
338 ;; (if (find-charset key)
339 ;; (setq cal (cons key cal))
340 (setq al (cons key al))
342 (setq value (cdr value)))
343 (insert-char-attributes ret
347 (insert (prin1-to-string value)))
349 (insert line-breaking))
351 (insert (format "(%-18s " name))
352 (setq lbs (concat "\n" (make-string (current-column) ?\ )))
354 (setq cell (car value))
355 (if (and (consp cell)
357 (setq ret (condition-case nil
367 (setq key (car (car rest)))
368 ;; (if (find-charset key)
369 ;; (setq cal (cons key cal))
370 (setq al (cons key al))
372 (setq rest (cdr rest)))
375 (insert-char-attributes ret
379 (setq separator lbs))
382 (insert (prin1-to-string cell))
383 (setq separator " "))
384 (setq value (cdr value)))
386 (insert line-breaking))
388 (insert (format "(%-18s . %S)%s"
391 (setq alist (cdr alist))))
394 (defun char-db-insert-char-reference (plist &optional readable column)
396 (setq column (current-column)))
398 (concat "\n" (make-string (1+ column) ?\ )))
403 (setq name (pop plist))
404 (setq value (pop plist))
405 (cond ((eq name :char)
408 (cond ((numberp value)
409 (setq value (decode-char '=ucs value)))
411 ;; (setq value (or (find-char value)
414 (char-db-insert-char-spec value readable)
415 (insert line-breaking)
418 (insert (format "%s%s\t%d ; %c%s"
421 (ideographic-radical value)
425 (insert (format "%s%s\t%S" separator name value))
426 (setq separator line-breaking)))
430 (defun char-db-decode-isolated-char (ccs code-point)
433 (cond ((eq ccs 'arabic-iso8859-6)
434 (decode-char ccs code-point))
435 ((and (memq ccs '(=gt-pj-1
446 (setq ret (decode-char ccs code-point))
447 (setq ret (encode-char ret '=gt 'defined-only)))
448 (decode-builtin-char '=gt ret))
450 (decode-builtin-char ccs code-point))))
451 (cond ((and (<= 0 (char-int ret))
452 (<= (char-int ret) #x1F))
453 (decode-char '=ucs (+ #x2400 (char-int ret))))
454 ((= (char-int ret) #x7F)
458 (defvar char-db-convert-obsolete-format t)
460 (defun char-db-insert-ccs-feature (name value line-breaking)
463 (cond ((memq name '(=shinjigen
465 =shinjigen@rev =shinjigen/+p@rev
467 "(%-18s . %04d)\t; %c")
468 ((eq name '=shinjigen@1ed/24pr)
469 "(%-18s . %04d)\t; %c")
470 ((or (memq name '(=daikanwa =>>daikanwa =>daikanwa
471 =daikanwa@rev1 =daikanwa@rev2
472 =daikanwa/+p =daikanwa/+2p
473 =gt =>>>gt =>>gt =>gt
475 =cbeta =zinbun-oracle =>zinbun-oracle))
476 (string-match "^=adobe-" (symbol-name name)))
477 "(%-18s . %05d)\t; %c")
478 ((memq name '(=hanyo-denshi/ks =>>hanyo-denshi/ks mojikyo))
479 "(%-18s . %06d)\t; %c")
480 ((>= (charset-dimension name) 2)
481 "(%-18s . #x%04X)\t; %c")
483 "(%-18s . #x%02X)\t; %c"))
485 (if (= (charset-iso-graphic-plane name) 1)
487 (cond ((= (charset-dimension name) 1)
489 ((= (charset-dimension name) 2)
491 ((= (charset-dimension name) 3)
495 (char-db-decode-isolated-char name value)))
496 (if (and (= (charset-chars name) 94)
497 (= (charset-dimension name) 2))
498 (insert (format " [%02d-%02d]"
499 (- (lsh value -8) 32)
500 (- (logand value 255) 32))))
501 (insert line-breaking))
503 (defun char-db-insert-relation-feature (char name value line-breaking
505 (insert (format "(%-18s%s " name line-breaking))
506 (let ((lbs (concat "\n" (make-string (current-column) ?\ )))
507 separator cell sources required-features
510 (setq cell (car value))
512 (setq cell (decode-char '=ucs cell)))
514 ((eq name '->subsumptive)
515 (when (or (not (some (lambda (atr)
516 (get-char-attribute cell atr))
517 char-db-ignored-attributes))
519 (encode-char cell ccs 'defined-only))
523 (let ((char-db-ignored-attributes
525 char-db-ignored-attributes)))
526 (insert-char-attributes cell readable))
527 (setq separator lbs))
532 char (intern (format "%s*sources" name))))
533 (setq required-features nil)
534 (dolist (source sources)
538 shinjigen shinjigen@1ed shinjigen@rev))
539 (setq required-features
540 (union required-features
551 (setq required-features
552 (union required-features
557 ((find-charset (setq ret (intern (format "=%s" source))))
558 (setq required-features
559 (cons ret required-features)))
560 (t (setq required-features
561 (cons source required-features)))))
562 (cond ((string-match "@JP" (symbol-name name))
563 (setq required-features
564 (union required-features
572 ((string-match "@CN" (symbol-name name))
573 (setq required-features
574 (union required-features
581 (insert (format "%S" cell))
582 (char-db-insert-char-spec cell readable
585 (setq separator lbs))
589 (if (consp (car cell))
590 (char-db-insert-char-spec cell readable)
591 (char-db-insert-char-reference cell readable))
592 (setq separator lbs))
596 (insert (prin1-to-string cell))
597 (setq separator " ")))
598 (setq value (cdr value)))
600 (insert line-breaking)))
602 (defun insert-char-attributes (char &optional readable attributes column)
604 (setq column (current-column)))
605 (let (name value ; has-long-ccs-name
609 (concat "\n" (make-string (1+ column) ?\ )))
610 lbs cell separator ret
612 dest-ccss ; sources required-features
617 (if (consp attributes)
619 (dolist (name attributes)
620 (unless (memq name char-db-ignored-attributes)
621 (if (find-charset name)
625 (dolist (name (char-attribute-list))
626 (unless (memq name char-db-ignored-attributes)
627 (if (find-charset name)
631 #'char-attribute-name<)))
633 (when (memq '<-subsumptive attributes)
635 (when (setq value (get-char-attribute char '<-subsumptive))
636 (char-db-insert-relation-feature char '<-subsumptive value
639 (setq attributes (delq '<-subsumptive attributes)))
640 (when (and (memq '<-denotational attributes)
641 (setq value (get-char-attribute char '<-denotational)))
642 (char-db-insert-relation-feature char '<-denotational value
645 (setq attributes (delq '<-denotational attributes)))
646 (when (and (memq 'name attributes)
647 (setq value (get-char-attribute char 'name)))
649 (if (> (+ (current-column) (length value)) 48)
652 value line-breaking))
653 (setq attributes (delq 'name attributes))
655 (when (and (memq 'name* attributes)
656 (setq value (get-char-attribute char 'name*)))
658 (if (> (+ (current-column) (length value)) 48)
661 value line-breaking))
662 (setq attributes (delq 'name* attributes))
664 (when (and (memq 'script attributes)
665 (setq value (get-char-attribute char 'script)))
666 (insert (format "(script\t\t%s)%s"
667 (mapconcat (function prin1-to-string)
670 (setq attributes (delq 'script attributes))
672 (dolist (name '(=>ucs =>ucs*))
673 (when (and (memq name attributes)
674 (setq value (get-char-attribute char name)))
675 (insert (format "(%-18s . #x%04X)\t; %c%s"
676 name value (decode-char '=ucs value)
678 (setq attributes (delq name attributes))))
679 (dolist (name '(=>ucs@gb =>ucs@big5))
680 (when (and (memq name attributes)
681 (setq value (get-char-attribute char name)))
682 (insert (format "(%-18s . #x%04X)\t; %c%s"
687 (symbol-name name) 2)))
690 (setq attributes (delq name attributes))
692 ;; (dolist (name '(=>daikanwa))
693 ;; (when (and (memq name attributes)
694 ;; (setq value (get-char-attribute char name)))
696 ;; (if (integerp value)
697 ;; (format "(%-18s . %05d)\t; %c%s"
698 ;; name value (decode-char '=daikanwa value)
700 ;; (format "(%-18s %s)\t; %c%s"
702 ;; (mapconcat (function prin1-to-string)
704 ;; (char-representative-of-daikanwa char)
706 ;; (setq attributes (delq name attributes))))
707 (when (and (memq 'general-category attributes)
708 (setq value (get-char-attribute char 'general-category)))
710 "(general-category\t%s) ; %s%s"
711 (mapconcat (lambda (cell)
714 (cond ((rassoc value unidata-normative-category-alist)
715 "Normative Category")
716 ((rassoc value unidata-informative-category-alist)
717 "Informative Category")
721 (setq attributes (delq 'general-category attributes))
723 (when (and (memq 'bidi-category attributes)
724 (setq value (get-char-attribute char 'bidi-category)))
725 (insert (format "(bidi-category\t. %S)%s"
728 (setq attributes (delq 'bidi-category attributes))
730 (unless (or (not (memq 'mirrored attributes))
731 (eq (setq value (get-char-attribute char 'mirrored 'empty))
733 (insert (format "(mirrored\t\t. %S)%s"
736 (setq attributes (delq 'mirrored attributes))
739 ((and (memq 'decimal-digit-value attributes)
740 (setq value (get-char-attribute char 'decimal-digit-value)))
741 (insert (format "(decimal-digit-value . %S)%s"
744 (setq attributes (delq 'decimal-digit-value attributes))
745 (when (and (memq 'digit-value attributes)
746 (setq value (get-char-attribute char 'digit-value)))
747 (insert (format "(digit-value\t . %S)%s"
750 (setq attributes (delq 'digit-value attributes))
752 (when (and (memq 'numeric-value attributes)
753 (setq value (get-char-attribute char 'numeric-value)))
754 (insert (format "(numeric-value\t . %S)%s"
757 (setq attributes (delq 'numeric-value attributes))
761 (when (and (memq 'digit-value attributes)
762 (setq value (get-char-attribute char 'digit-value)))
763 (insert (format "(digit-value\t. %S)%s"
766 (setq attributes (delq 'digit-value attributes))
768 (when (and (memq 'numeric-value attributes)
769 (setq value (get-char-attribute char 'numeric-value)))
770 (insert (format "(numeric-value\t. %S)%s"
773 (setq attributes (delq 'numeric-value attributes))
775 (when (and (memq 'iso-10646-comment attributes)
776 (setq value (get-char-attribute char 'iso-10646-comment)))
777 (insert (format "(iso-10646-comment\t. %S)%s"
780 (setq attributes (delq 'iso-10646-comment attributes))
782 (when (and (memq 'morohashi-daikanwa attributes)
783 (setq value (get-char-attribute char 'morohashi-daikanwa)))
784 (insert (format "(morohashi-daikanwa\t%s)%s"
785 (mapconcat (function prin1-to-string) value " ")
787 (setq attributes (delq 'morohashi-daikanwa attributes))
791 (when (and (memq 'ideographic-radical attributes)
792 (setq value (get-char-attribute char 'ideographic-radical)))
794 (insert (format "(ideographic-radical . %S)\t; %c%s"
796 (ideographic-radical radical)
798 (setq attributes (delq 'ideographic-radical attributes))
800 (when (and (memq 'shuowen-radical attributes)
801 (setq value (get-char-attribute char 'shuowen-radical)))
802 (insert (format "(shuowen-radical\t. %S)\t; %c%s"
804 (shuowen-radical value)
806 (setq attributes (delq 'shuowen-radical attributes))
811 char-db-feature-domains
813 (dolist (feature (char-attribute-list))
814 (setq feature (symbol-name feature))
816 "\\(radical\\|strokes\\)@\\([^@*]+\\)\\(\\*\\|$\\)"
818 (setq domain (intern (match-string 2 feature)))
819 (unless (memq domain dest)
820 (setq dest (cons domain dest)))))
821 (sort dest #'string<))))
822 (setq key (intern (format "%s@%s" 'ideographic-radical domain)))
823 (when (and (memq key attributes)
824 (setq value (get-char-attribute char key)))
826 (insert (format "(%s . %S)\t; %c%s"
829 (ideographic-radical radical)
831 (setq attributes (delq key attributes))
833 (setq key (intern (format "%s@%s" 'ideographic-strokes domain)))
834 (when (and (memq key attributes)
835 (setq value (get-char-attribute char key)))
837 (insert (format "(%s . %S)%s"
841 (setq attributes (delq key attributes))
843 (setq key (intern (format "%s@%s" 'total-strokes domain)))
844 (when (and (memq key attributes)
845 (setq value (get-char-attribute char key)))
846 (insert (format "(%s . %S)%s"
850 (setq attributes (delq key attributes))
852 (dolist (feature '(ideographic-radical
855 (setq key (intern (format "%s@%s*sources" feature domain)))
856 (when (and (memq key attributes)
857 (setq value (get-char-attribute char key)))
858 (insert (format "(%s%s" key line-breaking))
860 (insert (format " %s" cell)))
862 (insert line-breaking)
863 (setq attributes (delq key attributes))
866 (when (and (memq 'ideographic-strokes attributes)
867 (setq value (get-char-attribute char 'ideographic-strokes)))
869 (insert (format "(ideographic-strokes . %S)%s"
872 (setq attributes (delq 'ideographic-strokes attributes))
874 (when (and (memq 'kangxi-radical attributes)
875 (setq value (get-char-attribute char 'kangxi-radical)))
876 (unless (eq value radical)
877 (insert (format "(kangxi-radical\t . %S)\t; %c%s"
879 (ideographic-radical value)
882 (setq radical value)))
883 (setq attributes (delq 'kangxi-radical attributes))
885 (when (and (memq 'kangxi-strokes attributes)
886 (setq value (get-char-attribute char 'kangxi-strokes)))
887 (unless (eq value strokes)
888 (insert (format "(kangxi-strokes\t . %S)%s"
892 (setq strokes value)))
893 (setq attributes (delq 'kangxi-strokes attributes))
895 (when (and (memq 'japanese-radical attributes)
896 (setq value (get-char-attribute char 'japanese-radical)))
897 (unless (eq value radical)
898 (insert (format "(japanese-radical\t . %S)\t; %c%s"
900 (ideographic-radical value)
903 (setq radical value)))
904 (setq attributes (delq 'japanese-radical attributes))
906 (when (and (memq 'japanese-strokes attributes)
907 (setq value (get-char-attribute char 'japanese-strokes)))
908 (unless (eq value strokes)
909 (insert (format "(japanese-strokes\t . %S)%s"
913 (setq strokes value)))
914 (setq attributes (delq 'japanese-strokes attributes))
916 (when (and (memq 'cns-radical attributes)
917 (setq value (get-char-attribute char 'cns-radical)))
918 (insert (format "(cns-radical\t . %S)\t; %c%s"
920 (ideographic-radical value)
922 (setq attributes (delq 'cns-radical attributes))
924 (when (and (memq 'cns-strokes attributes)
925 (setq value (get-char-attribute char 'cns-strokes)))
926 (unless (eq value strokes)
927 (insert (format "(cns-strokes\t . %S)%s"
931 (setq strokes value)))
932 (setq attributes (delq 'cns-strokes attributes))
934 (when (and (memq 'shinjigen-1-radical attributes)
935 (setq value (get-char-attribute char 'shinjigen-1-radical)))
936 (unless (eq value radical)
937 (insert (format "(shinjigen-1-radical . %S)\t; %c%s"
939 (ideographic-radical value)
942 (setq radical value)))
943 (setq attributes (delq 'shinjigen-1-radical attributes))
945 (when (and (memq 'ideographic- attributes)
946 (setq value (get-char-attribute char 'ideographic-)))
947 (insert "(ideographic- ")
948 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
951 (setq cell (car value))
953 (setq cell (decode-char '=ucs cell)))
954 (cond ((characterp cell)
958 (insert (format "%S" cell))
959 (char-db-insert-char-spec cell readable))
960 (setq separator lbs))
964 (if (consp (car cell))
965 (char-db-insert-char-spec cell readable)
966 (char-db-insert-char-reference cell readable))
967 (setq separator lbs))
971 (insert (prin1-to-string cell))
972 (setq separator " ")))
973 (setq value (cdr value)))
975 (insert line-breaking)
976 (setq attributes (delq 'ideographic- attributes)))
977 (when (and (memq 'total-strokes attributes)
978 (setq value (get-char-attribute char 'total-strokes)))
979 (insert (format "(total-strokes . %S)%s"
982 (setq attributes (delq 'total-strokes attributes))
984 (when (and (memq '->ideograph attributes)
985 (setq value (get-char-attribute char '->ideograph)))
986 (insert (format "(->ideograph\t%s)%s"
987 (mapconcat (lambda (code)
988 (cond ((symbolp code)
991 (format "#x%04X" code))
994 line-breaking code))))
997 (setq attributes (delq '->ideograph attributes))
999 ;; (when (and (memq '->decomposition attributes)
1000 ;; (setq value (get-char-attribute char '->decomposition)))
1001 ;; (insert (format "(->decomposition\t%s)%s"
1002 ;; (mapconcat (lambda (code)
1003 ;; (cond ((symbolp code)
1004 ;; (symbol-name code))
1005 ;; ((characterp code)
1007 ;; (format "%S" code)
1012 ;; (format "#x%04X" code))
1014 ;; (format "%s%S" line-breaking code))))
1017 ;; (setq attributes (delq '->decomposition attributes))
1019 (if (equal (get-char-attribute char '->titlecase)
1020 (get-char-attribute char '->uppercase))
1021 (setq attributes (delq '->titlecase attributes)))
1022 (when (and (memq '->mojikyo attributes)
1023 (setq value (get-char-attribute char '->mojikyo)))
1024 (insert (format "(->mojikyo\t\t. %06d)\t; %c%s"
1025 value (decode-char 'mojikyo value)
1027 (setq attributes (delq '->mojikyo attributes))
1029 (when (and (memq 'hanyu-dazidian-vol attributes)
1030 (setq value (get-char-attribute char 'hanyu-dazidian-vol)))
1031 (insert (format "(hanyu-dazidian-vol . %d)%s"
1032 value line-breaking))
1033 (setq attributes (delq 'hanyu-dazidian-vol attributes))
1035 (when (and (memq 'hanyu-dazidian-page attributes)
1036 (setq value (get-char-attribute char 'hanyu-dazidian-page)))
1037 (insert (format "(hanyu-dazidian-page . %d)%s"
1038 value line-breaking))
1039 (setq attributes (delq 'hanyu-dazidian-page attributes))
1041 (when (and (memq 'hanyu-dazidian-char attributes)
1042 (setq value (get-char-attribute char 'hanyu-dazidian-char)))
1043 (insert (format "(hanyu-dazidian-char . %d)%s"
1044 value line-breaking))
1045 (setq attributes (delq 'hanyu-dazidian-char attributes))
1048 (dolist (ignored '(composition
1049 ->denotational <-subsumptive ->ucs-unified
1050 ->ideographic-component-forms))
1051 (setq attributes (delq ignored attributes))))
1053 (setq name (car attributes))
1054 (if (setq value (get-char-attribute char name))
1055 (cond ((setq ret (find-charset name))
1056 (setq name (charset-name ret))
1057 (if (and (not (memq name dest-ccss))
1059 (setq value (get-char-attribute char name))
1060 (setq dest-ccss (cons name dest-ccss))))
1061 (char-db-insert-ccs-feature name value line-breaking))
1063 ((string-match "^=>ucs@" (symbol-name name))
1064 (insert (format "(%-18s . #x%04X)\t; %c%s"
1065 name value (decode-char '=ucs value)
1068 ((eq name 'jisx0208-1978/4X)
1069 (insert (format "(%-18s . #x%04X)%s"
1075 (not (eq name '->subsumptive))
1076 (not (eq name '->uppercase))
1077 (not (eq name '->lowercase))
1078 (not (eq name '->titlecase))
1079 (not (eq name '->canonical))
1080 (not (eq name '->Bopomofo))
1081 (not (eq name '->mistakable))
1082 (not (eq name '->ideographic-variants))
1083 (null (get-char-attribute
1084 char (intern (format "%s*sources" name))))
1085 (not (string-match "\\*sources$" (symbol-name name)))
1086 (null (get-char-attribute
1087 char (intern (format "%s*note" name))))
1088 (not (string-match "\\*note$" (symbol-name name)))
1089 (or (eq name '<-identical)
1090 (eq name '<-uppercase)
1091 (eq name '<-lowercase)
1092 (eq name '<-titlecase)
1093 (eq name '<-canonical)
1094 (eq name '<-ideographic-variants)
1095 ;; (eq name '<-synonyms)
1096 (string-match "^<-synonyms" (symbol-name name))
1097 (eq name '<-mistakable)
1098 (when (string-match "^->" (symbol-name name))
1100 ((string-match "^->fullwidth" (symbol-name name))
1101 (not (and (consp value)
1102 (characterp (car value))
1104 (car value) '=ucs 'defined-only)))
1109 ((or (eq name 'ideographic-structure)
1110 (eq name 'ideographic-combination)
1111 (eq name 'ideographic-)
1112 (eq name '=decomposition)
1113 (char-feature-base-name= '=decomposition name)
1114 (char-feature-base-name= '=>decomposition name)
1115 ;; (string-match "^=>*decomposition\\(@[^*]+\\)?$"
1116 ;; (symbol-name name))
1117 (string-match "^\\(->\\|<-\\)[^*]*$" (symbol-name name))
1118 (string-match "^\\(->\\|<-\\)[^*]*\\*sources$"
1121 (char-db-insert-relation-feature char name value
1124 ((memq name '(ideograph=
1125 original-ideograph-of
1126 ancient-ideograph-of
1129 ;; simplified-ideograph-of
1130 ideographic-variants
1131 ;; ideographic-different-form-of
1133 (insert (format "(%-18s%s " name line-breaking))
1134 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1136 (while (consp value)
1137 (setq cell (car value))
1138 (if (and (consp cell)
1143 (char-db-insert-alist cell readable)
1144 (setq separator lbs))
1147 (insert (prin1-to-string cell))
1148 (setq separator " "))
1149 (setq value (cdr value)))
1151 (insert line-breaking))
1153 (insert (format "(%-18s " name))
1154 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1156 (while (consp value)
1157 (setq cell (car value))
1158 (if (and (consp cell)
1160 (setq ret (condition-case nil
1168 (setq key (car (car rest)))
1169 (if (find-charset key)
1170 (setq cal (cons key cal))
1171 (setq al (cons key al)))
1172 (setq rest (cdr rest)))
1175 (insert-char-attributes ret
1178 (setq separator lbs))
1179 (setq ret (prin1-to-string cell))
1181 (if (< (+ (current-column)
1188 (setq separator " "))
1189 (setq value (cdr value)))
1191 (insert line-breaking))
1193 (insert (format "(%-18s" name))
1194 (setq ret (prin1-to-string value))
1195 (unless (< (+ (current-column)
1199 (insert line-breaking))
1200 (insert " . " ret ")" line-breaking)
1201 ;; (insert (format "(%-18s . %S)%s"
1206 (setq attributes (cdr attributes)))
1209 (defun insert-char-data (char &optional readable
1212 (narrow-to-region (point)(point))
1213 (insert "(define-char
1215 (insert-char-attributes char readable attributes)
1217 (goto-char (point-min))
1218 (while (re-search-forward "[ \t]+$" nil t)
1221 (goto-char (point-min))
1222 (while (re-search-forward "[ \t][ \t][ \t]*" nil t)
1223 (let ((column (current-column))
1224 (indent-tabs-mode t))
1225 (delete-region (match-beginning 0) (point))
1226 (indent-to column)))
1227 (goto-char (point-max))
1228 ;; (tabify (point-min)(point-max))
1231 (defun insert-char-data-with-variant (char &optional printable
1233 script excluded-script)
1234 (insert-char-data char printable)
1235 (let ((variants (char-variants char))
1238 (setq variants (sort variants #'<))
1239 (setq rest variants)
1240 (setq variants (cons char variants))
1242 (setq variant (car rest))
1243 (unless (get-char-attribute variant '<-subsumptive)
1244 (if (and (or (null script)
1245 (null (setq vs (get-char-attribute variant 'script)))
1247 (or (null excluded-script)
1248 (null (setq vs (get-char-attribute variant 'script)))
1249 (not (memq excluded-script vs))))
1250 (unless (and no-ucs-unified (get-char-attribute variant '=ucs))
1251 (insert-char-data variant printable)
1252 (if (setq ret (char-variants variant))
1254 (or (memq (car ret) variants)
1255 ;; (get-char-attribute (car ret) '<-subsumptive)
1256 (setq rest (nconc rest (list (car ret)))))
1257 (setq ret (cdr ret)))))))
1258 (setq rest (cdr rest)))))
1260 (defun insert-char-range-data (min max &optional script excluded-script)
1263 (while (<= code max)
1264 (setq char (decode-char '=ucs code))
1265 (if (encode-char char '=ucs 'defined-only)
1266 (insert-char-data-with-variant char nil 'no-ucs-unified
1267 script excluded-script))
1268 (setq code (1+ code)))))
1270 (defun write-char-range-data-to-file (min max file
1271 &optional script excluded-script)
1272 (let ((coding-system-for-write char-db-file-coding-system))
1274 (insert (format ";; -*- coding: %s -*-\n"
1275 char-db-file-coding-system))
1276 (insert-char-range-data min max script excluded-script)
1277 (write-region (point-min)(point-max) file))))
1279 (defvar what-character-original-window-configuration)
1282 (defun what-char-definition (char)
1283 (interactive (list (char-after)))
1284 (let ((buf (get-buffer-create "*Character Description*"))
1285 (the-buf (current-buffer))
1286 (win-conf (current-window-configuration)))
1288 (make-local-variable 'what-character-original-window-configuration)
1289 (setq what-character-original-window-configuration win-conf)
1290 (setq buffer-read-only nil)
1294 (insert-char-data-with-variant char 'printable)
1295 (unless (char-attribute-alist char)
1296 (insert (format ";; = %c\n"
1297 (let* ((rest (split-char char))
1301 (setq code (logior (lsh code 8)
1303 (decode-char ccs code)))))
1304 ;; (char-db-update-comment)
1305 (set-buffer-modified-p nil)
1306 (view-mode the-buf (lambda (buf)
1307 (set-window-configuration
1308 what-character-original-window-configuration)
1310 (goto-char (point-min)))
1312 (set-window-configuration
1313 what-character-original-window-configuration)
1314 (signal (car err) (cdr err)))))))
1320 (provide 'char-db-util)
1322 ;;; char-db-util.el ends here