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
218 ;;; @ char-db formatters
221 (defun char-db-make-char-spec (char)
223 (cond ((characterp char)
224 (cond ((and (setq ret (encode-char char '=ucs 'defined-only))
225 (not (and (<= #xE000 ret)(<= ret #xF8FF))))
226 (setq char-spec (list (cons '=ucs ret)))
227 (cond ((setq ret (get-char-attribute char 'name))
228 (setq char-spec (cons (cons 'name ret) char-spec))
230 ((setq ret (get-char-attribute char 'name*))
231 (setq char-spec (cons (cons 'name* ret) char-spec))
236 (let ((rest char-db-coded-charset-priority-list)
239 (setq ccs (charset-name
240 (find-charset (car rest))))
242 (encode-char char ccs
244 (throw 'tag (cons ccs ret)))
245 (setq rest (cdr rest))))))
246 (setq char-spec (list ret))
247 (dolist (ccs (delq (car ret) (charset-list)))
248 (if (and (or (charset-iso-final-char ccs)
255 (string-match "=ucs@" (symbol-name ccs)))
256 (setq ccs (charset-name ccs))
257 (null (assq ccs char-spec))
258 (setq ret (encode-char char ccs 'defined-only)))
259 (setq char-spec (cons (cons ccs ret) char-spec))))
261 (setq char-spec (split-char char)))
262 (cond ((setq ret (get-char-attribute char 'name))
263 (setq char-spec (cons (cons 'name ret) char-spec))
265 ((setq ret (get-char-attribute char 'name*))
266 (setq char-spec (cons (cons 'name* ret) char-spec))
269 ((setq ret (get-char-attribute
270 char 'ideographic-combination))
272 (cons (cons 'ideographic-combination ret)
279 (defun char-db-insert-char-spec (char &optional readable column
282 (setq column (current-column)))
283 (let (char-spec temp-char)
284 (setq char-spec (char-db-make-char-spec char))
285 (unless (or (characterp char) ; char
287 (setq char (find-char char-spec))
289 ;; define temporary character
290 ;; Current implementation is dirty.
291 (setq temp-char (define-char (cons '(ideograph-daikanwa . 0)
293 (remove-char-attribute temp-char 'ideograph-daikanwa)
294 (setq char temp-char))
295 (insert-char-attributes char
297 (union (mapcar #'car char-spec)
300 ;; undefine temporary character
301 ;; Current implementation is dirty.
302 (setq char-spec (char-attribute-alist temp-char))
304 (remove-char-attribute temp-char (car (car char-spec)))
305 (setq char-spec (cdr char-spec))))))
307 (defun char-db-insert-alist (alist &optional readable column)
309 (setq column (current-column)))
311 (concat "\n" (make-string (1+ column) ?\ )))
315 lbs cell rest separator)
318 (setq name (car (car alist))
319 value (cdr (car alist)))
320 (cond ((eq name 'char)
322 (if (setq ret (condition-case nil
330 (setq key (car (car value)))
331 ;; (if (find-charset key)
332 ;; (setq cal (cons key cal))
333 (setq al (cons key al))
335 (setq value (cdr value)))
336 (insert-char-attributes ret
340 (insert (prin1-to-string value)))
342 (insert line-breaking))
344 (insert (format "(%-18s " name))
345 (setq lbs (concat "\n" (make-string (current-column) ?\ )))
347 (setq cell (car value))
348 (if (and (consp cell)
350 (setq ret (condition-case nil
360 (setq key (car (car rest)))
361 ;; (if (find-charset key)
362 ;; (setq cal (cons key cal))
363 (setq al (cons key al))
365 (setq rest (cdr rest)))
368 (insert-char-attributes ret
372 (setq separator lbs))
375 (insert (prin1-to-string cell))
376 (setq separator " "))
377 (setq value (cdr value)))
379 (insert line-breaking))
381 (insert (format "(%-18s . %S)%s"
384 (setq alist (cdr alist))))
387 (defun char-db-insert-char-reference (plist &optional readable column)
389 (setq column (current-column)))
391 (concat "\n" (make-string (1+ column) ?\ )))
396 (setq name (pop plist))
397 (setq value (pop plist))
398 (cond ((eq name :char)
401 (cond ((numberp value)
402 (setq value (decode-char '=ucs value)))
404 ;; (setq value (or (find-char value)
407 (char-db-insert-char-spec value readable)
408 (insert line-breaking)
411 (insert (format "%s%s\t%d ; %c%s"
414 (ideographic-radical value)
418 (insert (format "%s%s\t%S" separator name value))
419 (setq separator line-breaking)))
423 (defun char-db-decode-isolated-char (ccs code-point)
426 (cond ((eq ccs 'arabic-iso8859-6)
427 (decode-char ccs code-point))
428 ((and (memq ccs '(=gt-pj-1
439 (setq ret (decode-char ccs code-point))
440 (setq ret (encode-char ret '=gt 'defined-only)))
441 (decode-builtin-char '=gt ret))
443 (decode-builtin-char ccs code-point))))
444 (cond ((and (<= 0 (char-int ret))
445 (<= (char-int ret) #x1F))
446 (decode-char '=ucs (+ #x2400 (char-int ret))))
447 ((= (char-int ret) #x7F)
451 (defvar char-db-convert-obsolete-format t)
453 (defun char-db-insert-ccs-feature (name value line-breaking)
456 (cond ((memq name '(=shinjigen
458 =shinjigen@rev =shinjigen/+p@rev
460 "(%-18s . %04d)\t; %c")
461 ((eq name '=shinjigen@1ed/24pr)
462 "(%-18s . %04d)\t; %c")
463 ((or (memq name '(=daikanwa
464 =daikanwa@rev1 =daikanwa@rev2
465 =daikanwa/+p =daikanwa/+2p
466 =>>daikanwa =>daikanwa
467 =gt =>>gt =>gt =gt-k =>>gt-k =>gt-k =cbeta
468 =zinbun-oracle =>zinbun-oracle))
469 (string-match "^=adobe-" (symbol-name name)))
470 "(%-18s . %05d)\t; %c")
471 ((memq name '(=hanyo-denshi/ks mojikyo))
472 "(%-18s . %06d)\t; %c")
473 ((>= (charset-dimension name) 2)
474 "(%-18s . #x%04X)\t; %c")
476 "(%-18s . #x%02X)\t; %c"))
478 (if (= (charset-iso-graphic-plane name) 1)
480 (cond ((= (charset-dimension name) 1)
482 ((= (charset-dimension name) 2)
484 ((= (charset-dimension name) 3)
488 (char-db-decode-isolated-char name value)))
489 (if (and (= (charset-chars name) 94)
490 (= (charset-dimension name) 2))
491 (insert (format " [%02d-%02d]"
492 (- (lsh value -8) 32)
493 (- (logand value 255) 32))))
494 (insert line-breaking))
496 (defun char-db-insert-relation-feature (char name value line-breaking
498 (insert (format "(%-18s%s " name line-breaking))
499 (let ((lbs (concat "\n" (make-string (current-column) ?\ )))
500 separator cell sources required-features
503 (setq cell (car value))
505 (setq cell (decode-char '=ucs cell)))
507 ((eq name '->subsumptive)
508 (when (or (not (some (lambda (atr)
509 (get-char-attribute cell atr))
510 char-db-ignored-attributes))
512 (encode-char cell ccs 'defined-only))
516 (let ((char-db-ignored-attributes
518 char-db-ignored-attributes)))
519 (insert-char-attributes cell readable))
520 (setq separator lbs))
525 char (intern (format "%s*sources" name))))
526 (setq required-features nil)
527 (dolist (source sources)
531 shinjigen shinjigen@1ed shinjigen@rev))
532 (setq required-features
533 (union required-features
544 (setq required-features
545 (union required-features
550 ((find-charset (setq ret (intern (format "=%s" source))))
551 (setq required-features
552 (cons ret required-features)))
553 (t (setq required-features
554 (cons source required-features)))))
555 (cond ((string-match "@JP" (symbol-name name))
556 (setq required-features
557 (union required-features
565 ((string-match "@CN" (symbol-name name))
566 (setq required-features
567 (union required-features
574 (insert (format "%S" cell))
575 (char-db-insert-char-spec cell readable
578 (setq separator lbs))
582 (if (consp (car cell))
583 (char-db-insert-char-spec cell readable)
584 (char-db-insert-char-reference cell readable))
585 (setq separator lbs))
589 (insert (prin1-to-string cell))
590 (setq separator " ")))
591 (setq value (cdr value)))
593 (insert line-breaking)))
595 (defun insert-char-attributes (char &optional readable attributes column)
597 (setq column (current-column)))
598 (let (name value ; has-long-ccs-name
602 (concat "\n" (make-string (1+ column) ?\ )))
603 lbs cell separator ret
605 dest-ccss ; sources required-features
610 (if (consp attributes)
612 (dolist (name attributes)
613 (unless (memq name char-db-ignored-attributes)
614 (if (find-charset name)
618 (dolist (name (char-attribute-list))
619 (unless (memq name char-db-ignored-attributes)
620 (if (find-charset name)
624 #'char-attribute-name<)))
626 (when (memq '<-subsumptive attributes)
628 (when (setq value (get-char-attribute char '<-subsumptive))
629 (char-db-insert-relation-feature char '<-subsumptive value
632 (setq attributes (delq '<-subsumptive attributes)))
633 (when (and (memq '<-denotational attributes)
634 (setq value (get-char-attribute char '<-denotational)))
635 (char-db-insert-relation-feature char '<-denotational value
638 (setq attributes (delq '<-denotational attributes)))
639 (when (and (memq 'name attributes)
640 (setq value (get-char-attribute char 'name)))
642 (if (> (+ (current-column) (length value)) 48)
645 value line-breaking))
646 (setq attributes (delq 'name attributes))
648 (when (and (memq 'name* attributes)
649 (setq value (get-char-attribute char 'name*)))
651 (if (> (+ (current-column) (length value)) 48)
654 value line-breaking))
655 (setq attributes (delq 'name* attributes))
657 (when (and (memq 'script attributes)
658 (setq value (get-char-attribute char 'script)))
659 (insert (format "(script\t\t%s)%s"
660 (mapconcat (function prin1-to-string)
663 (setq attributes (delq 'script attributes))
665 (dolist (name '(=>ucs =>ucs*))
666 (when (and (memq name attributes)
667 (setq value (get-char-attribute char name)))
668 (insert (format "(%-18s . #x%04X)\t; %c%s"
669 name value (decode-char '=ucs value)
671 (setq attributes (delq name attributes))))
672 (dolist (name '(=>ucs@gb =>ucs@big5))
673 (when (and (memq name attributes)
674 (setq value (get-char-attribute char name)))
675 (insert (format "(%-18s . #x%04X)\t; %c%s"
680 (symbol-name name) 2)))
683 (setq attributes (delq name attributes))
685 ;; (dolist (name '(=>daikanwa))
686 ;; (when (and (memq name attributes)
687 ;; (setq value (get-char-attribute char name)))
689 ;; (if (integerp value)
690 ;; (format "(%-18s . %05d)\t; %c%s"
691 ;; name value (decode-char '=daikanwa value)
693 ;; (format "(%-18s %s)\t; %c%s"
695 ;; (mapconcat (function prin1-to-string)
697 ;; (char-representative-of-daikanwa char)
699 ;; (setq attributes (delq name attributes))))
700 (when (and (memq 'general-category attributes)
701 (setq value (get-char-attribute char 'general-category)))
703 "(general-category\t%s) ; %s%s"
704 (mapconcat (lambda (cell)
707 (cond ((rassoc value unidata-normative-category-alist)
708 "Normative Category")
709 ((rassoc value unidata-informative-category-alist)
710 "Informative Category")
714 (setq attributes (delq 'general-category attributes))
716 (when (and (memq 'bidi-category attributes)
717 (setq value (get-char-attribute char 'bidi-category)))
718 (insert (format "(bidi-category\t. %S)%s"
721 (setq attributes (delq 'bidi-category attributes))
723 (unless (or (not (memq 'mirrored attributes))
724 (eq (setq value (get-char-attribute char 'mirrored 'empty))
726 (insert (format "(mirrored\t\t. %S)%s"
729 (setq attributes (delq 'mirrored attributes))
732 ((and (memq 'decimal-digit-value attributes)
733 (setq value (get-char-attribute char 'decimal-digit-value)))
734 (insert (format "(decimal-digit-value . %S)%s"
737 (setq attributes (delq 'decimal-digit-value attributes))
738 (when (and (memq 'digit-value attributes)
739 (setq value (get-char-attribute char 'digit-value)))
740 (insert (format "(digit-value\t . %S)%s"
743 (setq attributes (delq 'digit-value attributes))
745 (when (and (memq 'numeric-value attributes)
746 (setq value (get-char-attribute char 'numeric-value)))
747 (insert (format "(numeric-value\t . %S)%s"
750 (setq attributes (delq 'numeric-value attributes))
754 (when (and (memq 'digit-value attributes)
755 (setq value (get-char-attribute char 'digit-value)))
756 (insert (format "(digit-value\t. %S)%s"
759 (setq attributes (delq 'digit-value attributes))
761 (when (and (memq 'numeric-value attributes)
762 (setq value (get-char-attribute char 'numeric-value)))
763 (insert (format "(numeric-value\t. %S)%s"
766 (setq attributes (delq 'numeric-value attributes))
768 (when (and (memq 'iso-10646-comment attributes)
769 (setq value (get-char-attribute char 'iso-10646-comment)))
770 (insert (format "(iso-10646-comment\t. %S)%s"
773 (setq attributes (delq 'iso-10646-comment attributes))
775 (when (and (memq 'morohashi-daikanwa attributes)
776 (setq value (get-char-attribute char 'morohashi-daikanwa)))
777 (insert (format "(morohashi-daikanwa\t%s)%s"
778 (mapconcat (function prin1-to-string) value " ")
780 (setq attributes (delq 'morohashi-daikanwa attributes))
784 (when (and (memq 'ideographic-radical attributes)
785 (setq value (get-char-attribute char 'ideographic-radical)))
787 (insert (format "(ideographic-radical . %S)\t; %c%s"
789 (ideographic-radical radical)
791 (setq attributes (delq 'ideographic-radical attributes))
793 (when (and (memq 'shuowen-radical attributes)
794 (setq value (get-char-attribute char 'shuowen-radical)))
795 (insert (format "(shuowen-radical\t. %S)\t; %c%s"
797 (shuowen-radical value)
799 (setq attributes (delq 'shuowen-radical attributes))
804 char-db-feature-domains
806 (dolist (feature (char-attribute-list))
807 (setq feature (symbol-name feature))
809 "\\(radical\\|strokes\\)@\\([^@*]+\\)\\(\\*\\|$\\)"
811 (setq domain (intern (match-string 2 feature)))
812 (unless (memq domain dest)
813 (setq dest (cons domain dest)))))
814 (sort dest #'string<))))
815 (setq key (intern (format "%s@%s" 'ideographic-radical domain)))
816 (when (and (memq key attributes)
817 (setq value (get-char-attribute char key)))
819 (insert (format "(%s . %S)\t; %c%s"
822 (ideographic-radical radical)
824 (setq attributes (delq key attributes))
826 (setq key (intern (format "%s@%s" 'ideographic-strokes domain)))
827 (when (and (memq key attributes)
828 (setq value (get-char-attribute char key)))
830 (insert (format "(%s . %S)%s"
834 (setq attributes (delq key attributes))
836 (setq key (intern (format "%s@%s" 'total-strokes domain)))
837 (when (and (memq key attributes)
838 (setq value (get-char-attribute char key)))
839 (insert (format "(%s . %S)%s"
843 (setq attributes (delq key attributes))
845 (dolist (feature '(ideographic-radical
848 (setq key (intern (format "%s@%s*sources" feature domain)))
849 (when (and (memq key attributes)
850 (setq value (get-char-attribute char key)))
851 (insert (format "(%s%s" key line-breaking))
853 (insert (format " %s" cell)))
855 (insert line-breaking)
856 (setq attributes (delq key attributes))
859 (when (and (memq 'ideographic-strokes attributes)
860 (setq value (get-char-attribute char 'ideographic-strokes)))
862 (insert (format "(ideographic-strokes . %S)%s"
865 (setq attributes (delq 'ideographic-strokes attributes))
867 (when (and (memq 'kangxi-radical attributes)
868 (setq value (get-char-attribute char 'kangxi-radical)))
869 (unless (eq value radical)
870 (insert (format "(kangxi-radical\t . %S)\t; %c%s"
872 (ideographic-radical value)
875 (setq radical value)))
876 (setq attributes (delq 'kangxi-radical attributes))
878 (when (and (memq 'kangxi-strokes attributes)
879 (setq value (get-char-attribute char 'kangxi-strokes)))
880 (unless (eq value strokes)
881 (insert (format "(kangxi-strokes\t . %S)%s"
885 (setq strokes value)))
886 (setq attributes (delq 'kangxi-strokes attributes))
888 (when (and (memq 'japanese-radical attributes)
889 (setq value (get-char-attribute char 'japanese-radical)))
890 (unless (eq value radical)
891 (insert (format "(japanese-radical\t . %S)\t; %c%s"
893 (ideographic-radical value)
896 (setq radical value)))
897 (setq attributes (delq 'japanese-radical attributes))
899 (when (and (memq 'japanese-strokes attributes)
900 (setq value (get-char-attribute char 'japanese-strokes)))
901 (unless (eq value strokes)
902 (insert (format "(japanese-strokes\t . %S)%s"
906 (setq strokes value)))
907 (setq attributes (delq 'japanese-strokes attributes))
909 (when (and (memq 'cns-radical attributes)
910 (setq value (get-char-attribute char 'cns-radical)))
911 (insert (format "(cns-radical\t . %S)\t; %c%s"
913 (ideographic-radical value)
915 (setq attributes (delq 'cns-radical attributes))
917 (when (and (memq 'cns-strokes attributes)
918 (setq value (get-char-attribute char 'cns-strokes)))
919 (unless (eq value strokes)
920 (insert (format "(cns-strokes\t . %S)%s"
924 (setq strokes value)))
925 (setq attributes (delq 'cns-strokes attributes))
927 (when (and (memq 'shinjigen-1-radical attributes)
928 (setq value (get-char-attribute char 'shinjigen-1-radical)))
929 (unless (eq value radical)
930 (insert (format "(shinjigen-1-radical . %S)\t; %c%s"
932 (ideographic-radical value)
935 (setq radical value)))
936 (setq attributes (delq 'shinjigen-1-radical attributes))
938 (when (and (memq 'ideographic- attributes)
939 (setq value (get-char-attribute char 'ideographic-)))
940 (insert "(ideographic- ")
941 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
944 (setq cell (car value))
946 (setq cell (decode-char '=ucs cell)))
947 (cond ((characterp cell)
951 (insert (format "%S" cell))
952 (char-db-insert-char-spec cell readable))
953 (setq separator lbs))
957 (if (consp (car cell))
958 (char-db-insert-char-spec cell readable)
959 (char-db-insert-char-reference cell readable))
960 (setq separator lbs))
964 (insert (prin1-to-string cell))
965 (setq separator " ")))
966 (setq value (cdr value)))
968 (insert line-breaking)
969 (setq attributes (delq 'ideographic- attributes)))
970 (when (and (memq 'total-strokes attributes)
971 (setq value (get-char-attribute char 'total-strokes)))
972 (insert (format "(total-strokes . %S)%s"
975 (setq attributes (delq 'total-strokes attributes))
977 (when (and (memq '->ideograph attributes)
978 (setq value (get-char-attribute char '->ideograph)))
979 (insert (format "(->ideograph\t%s)%s"
980 (mapconcat (lambda (code)
981 (cond ((symbolp code)
984 (format "#x%04X" code))
987 line-breaking code))))
990 (setq attributes (delq '->ideograph attributes))
992 ;; (when (and (memq '->decomposition attributes)
993 ;; (setq value (get-char-attribute char '->decomposition)))
994 ;; (insert (format "(->decomposition\t%s)%s"
995 ;; (mapconcat (lambda (code)
996 ;; (cond ((symbolp code)
997 ;; (symbol-name code))
998 ;; ((characterp code)
1000 ;; (format "%S" code)
1005 ;; (format "#x%04X" code))
1007 ;; (format "%s%S" line-breaking code))))
1010 ;; (setq attributes (delq '->decomposition attributes))
1012 (if (equal (get-char-attribute char '->titlecase)
1013 (get-char-attribute char '->uppercase))
1014 (setq attributes (delq '->titlecase attributes)))
1015 (when (and (memq '->mojikyo attributes)
1016 (setq value (get-char-attribute char '->mojikyo)))
1017 (insert (format "(->mojikyo\t\t. %06d)\t; %c%s"
1018 value (decode-char 'mojikyo value)
1020 (setq attributes (delq '->mojikyo attributes))
1022 (when (and (memq 'hanyu-dazidian-vol attributes)
1023 (setq value (get-char-attribute char 'hanyu-dazidian-vol)))
1024 (insert (format "(hanyu-dazidian-vol . %d)%s"
1025 value line-breaking))
1026 (setq attributes (delq 'hanyu-dazidian-vol attributes))
1028 (when (and (memq 'hanyu-dazidian-page attributes)
1029 (setq value (get-char-attribute char 'hanyu-dazidian-page)))
1030 (insert (format "(hanyu-dazidian-page . %d)%s"
1031 value line-breaking))
1032 (setq attributes (delq 'hanyu-dazidian-page attributes))
1034 (when (and (memq 'hanyu-dazidian-char attributes)
1035 (setq value (get-char-attribute char 'hanyu-dazidian-char)))
1036 (insert (format "(hanyu-dazidian-char . %d)%s"
1037 value line-breaking))
1038 (setq attributes (delq 'hanyu-dazidian-char attributes))
1041 (dolist (ignored '(composition
1042 ->denotational <-subsumptive ->ucs-unified
1043 ->ideographic-component-forms))
1044 (setq attributes (delq ignored attributes))))
1046 (setq name (car attributes))
1047 (if (setq value (get-char-attribute char name))
1048 (cond ((setq ret (find-charset name))
1049 (setq name (charset-name ret))
1050 (if (and (not (memq name dest-ccss))
1052 (setq value (get-char-attribute char name))
1053 (setq dest-ccss (cons name dest-ccss))))
1054 (char-db-insert-ccs-feature name value line-breaking))
1056 ((string-match "^=>ucs@" (symbol-name name))
1057 (insert (format "(%-18s . #x%04X)\t; %c%s"
1058 name value (decode-char '=ucs value)
1061 ((eq name 'jisx0208-1978/4X)
1062 (insert (format "(%-18s . #x%04X)%s"
1068 (not (eq name '->subsumptive))
1069 (not (eq name '->uppercase))
1070 (not (eq name '->lowercase))
1071 (not (eq name '->titlecase))
1072 (not (eq name '->canonical))
1073 (not (eq name '->Bopomofo))
1074 (not (eq name '->mistakable))
1075 (not (eq name '->ideographic-variants))
1076 (null (get-char-attribute
1077 char (intern (format "%s*sources" name))))
1078 (not (string-match "\\*sources$" (symbol-name name)))
1079 (null (get-char-attribute
1080 char (intern (format "%s*note" name))))
1081 (not (string-match "\\*note$" (symbol-name name)))
1082 (or (eq name '<-identical)
1083 (eq name '<-uppercase)
1084 (eq name '<-lowercase)
1085 (eq name '<-titlecase)
1086 (eq name '<-canonical)
1087 (eq name '<-ideographic-variants)
1088 ;; (eq name '<-synonyms)
1089 (string-match "^<-synonyms" (symbol-name name))
1090 (eq name '<-mistakable)
1091 (when (string-match "^->" (symbol-name name))
1093 ((string-match "^->fullwidth" (symbol-name name))
1094 (not (and (consp value)
1095 (characterp (car value))
1097 (car value) '=ucs 'defined-only)))
1102 ((or (eq name 'ideographic-structure)
1103 (eq name 'ideographic-combination)
1104 (eq name 'ideographic-)
1105 (eq name '=decomposition)
1106 (string-match "^=>*decomposition\\(@[^*]+\\)?$"
1108 (string-match "^\\(->\\|<-\\)[^*]*$" (symbol-name name))
1109 (string-match "^\\(->\\|<-\\)[^*]*\\*sources$"
1112 (char-db-insert-relation-feature char name value
1115 ((memq name '(ideograph=
1116 original-ideograph-of
1117 ancient-ideograph-of
1120 ;; simplified-ideograph-of
1121 ideographic-variants
1122 ;; ideographic-different-form-of
1124 (insert (format "(%-18s%s " name line-breaking))
1125 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1127 (while (consp value)
1128 (setq cell (car value))
1129 (if (and (consp cell)
1134 (char-db-insert-alist cell readable)
1135 (setq separator lbs))
1138 (insert (prin1-to-string cell))
1139 (setq separator " "))
1140 (setq value (cdr value)))
1142 (insert line-breaking))
1144 (insert (format "(%-18s " name))
1145 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1147 (while (consp value)
1148 (setq cell (car value))
1149 (if (and (consp cell)
1151 (setq ret (condition-case nil
1159 (setq key (car (car rest)))
1160 (if (find-charset key)
1161 (setq cal (cons key cal))
1162 (setq al (cons key al)))
1163 (setq rest (cdr rest)))
1166 (insert-char-attributes ret
1169 (setq separator lbs))
1170 (setq ret (prin1-to-string cell))
1172 (if (< (+ (current-column)
1179 (setq separator " "))
1180 (setq value (cdr value)))
1182 (insert line-breaking))
1184 (insert (format "(%-18s" name))
1185 (setq ret (prin1-to-string value))
1186 (unless (< (+ (current-column)
1190 (insert line-breaking))
1191 (insert " . " ret ")" line-breaking)
1192 ;; (insert (format "(%-18s . %S)%s"
1197 (setq attributes (cdr attributes)))
1200 (defun insert-char-data (char &optional readable
1203 (narrow-to-region (point)(point))
1204 (insert "(define-char
1206 (insert-char-attributes char readable attributes)
1208 (goto-char (point-min))
1209 (while (re-search-forward "[ \t]+$" nil t)
1212 (goto-char (point-min))
1213 (while (re-search-forward "[ \t][ \t][ \t]*" nil t)
1214 (let ((column (current-column))
1215 (indent-tabs-mode t))
1216 (delete-region (match-beginning 0) (point))
1217 (indent-to column)))
1218 (goto-char (point-max))
1219 ;; (tabify (point-min)(point-max))
1222 (defun insert-char-data-with-variant (char &optional printable
1224 script excluded-script)
1225 (insert-char-data char printable)
1226 (let ((variants (char-variants char))
1229 (setq variants (sort variants #'<))
1230 (setq rest variants)
1231 (setq variants (cons char variants))
1233 (setq variant (car rest))
1234 (unless (get-char-attribute variant '<-subsumptive)
1235 (if (and (or (null script)
1236 (null (setq vs (get-char-attribute variant 'script)))
1238 (or (null excluded-script)
1239 (null (setq vs (get-char-attribute variant 'script)))
1240 (not (memq excluded-script vs))))
1241 (unless (and no-ucs-unified (get-char-attribute variant '=ucs))
1242 (insert-char-data variant printable)
1243 (if (setq ret (char-variants variant))
1245 (or (memq (car ret) variants)
1246 ;; (get-char-attribute (car ret) '<-subsumptive)
1247 (setq rest (nconc rest (list (car ret)))))
1248 (setq ret (cdr ret)))))))
1249 (setq rest (cdr rest)))))
1251 (defun insert-char-range-data (min max &optional script excluded-script)
1254 (while (<= code max)
1255 (setq char (decode-char '=ucs code))
1256 (if (encode-char char '=ucs 'defined-only)
1257 (insert-char-data-with-variant char nil 'no-ucs-unified
1258 script excluded-script))
1259 (setq code (1+ code)))))
1261 (defun write-char-range-data-to-file (min max file
1262 &optional script excluded-script)
1263 (let ((coding-system-for-write char-db-file-coding-system))
1265 (insert (format ";; -*- coding: %s -*-\n"
1266 char-db-file-coding-system))
1267 (insert-char-range-data min max script excluded-script)
1268 (write-region (point-min)(point-max) file))))
1270 (defvar what-character-original-window-configuration)
1273 (defun what-char-definition (char)
1274 (interactive (list (char-after)))
1275 (let ((buf (get-buffer-create "*Character Description*"))
1276 (the-buf (current-buffer))
1277 (win-conf (current-window-configuration)))
1279 (make-local-variable 'what-character-original-window-configuration)
1280 (setq what-character-original-window-configuration win-conf)
1281 (setq buffer-read-only nil)
1285 (insert-char-data-with-variant char 'printable)
1286 (unless (char-attribute-alist char)
1287 (insert (format ";; = %c\n"
1288 (let* ((rest (split-char char))
1292 (setq code (logior (lsh code 8)
1294 (decode-char ccs code)))))
1295 ;; (char-db-update-comment)
1296 (set-buffer-modified-p nil)
1297 (view-mode the-buf (lambda (buf)
1298 (set-window-configuration
1299 what-character-original-window-configuration)
1301 (goto-char (point-min)))
1303 (set-window-configuration
1304 what-character-original-window-configuration)
1305 (signal (car err) (cdr err)))))))
1311 (provide 'char-db-util)
1313 ;;; char-db-util.el ends here