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
229 ;;; @ char-db formatters
232 (defun char-db-make-char-spec (char)
234 (cond ((characterp char)
235 (cond ((and (setq ret (encode-char char '=ucs 'defined-only))
236 (not (and (<= #xE000 ret)(<= ret #xF8FF))))
237 (setq char-spec (list (cons '=ucs ret)))
238 (cond ((setq ret (get-char-attribute char 'name))
239 (setq char-spec (cons (cons 'name ret) char-spec))
241 ((setq ret (get-char-attribute char 'name*))
242 (setq char-spec (cons (cons 'name* ret) char-spec))
247 (let ((rest char-db-coded-charset-priority-list)
250 (setq ccs (charset-name
251 (find-charset (car rest))))
253 (encode-char char ccs
255 (throw 'tag (cons ccs ret)))
256 (setq rest (cdr rest))))))
257 (setq char-spec (list ret))
258 (dolist (ccs (delq (car ret) (charset-list)))
259 (if (and (or (charset-iso-final-char ccs)
266 (string-match "=ucs@" (symbol-name ccs)))
267 (setq ccs (charset-name ccs))
268 (null (assq ccs char-spec))
269 (setq ret (encode-char char ccs 'defined-only)))
270 (setq char-spec (cons (cons ccs ret) char-spec))))
272 (setq char-spec (split-char char)))
273 (cond ((setq ret (get-char-attribute char 'name))
274 (setq char-spec (cons (cons 'name ret) char-spec))
276 ((setq ret (get-char-attribute char 'name*))
277 (setq char-spec (cons (cons 'name* ret) char-spec))
280 ((setq ret (get-char-attribute
281 char 'ideographic-combination))
283 (cons (cons 'ideographic-combination ret)
290 (defun char-db-insert-char-spec (char &optional readable column
293 (setq column (current-column)))
294 (let (char-spec temp-char)
295 (setq char-spec (char-db-make-char-spec char))
296 (unless (or (characterp char) ; char
298 (setq char (find-char char-spec))
300 ;; define temporary character
301 ;; Current implementation is dirty.
302 (setq temp-char (define-char (cons '(ideograph-daikanwa . 0)
304 (remove-char-attribute temp-char 'ideograph-daikanwa)
305 (setq char temp-char))
306 (insert-char-attributes char
308 (union (mapcar #'car char-spec)
312 ;; undefine temporary character
313 ;; Current implementation is dirty.
314 (setq char-spec (char-attribute-alist temp-char))
316 (remove-char-attribute temp-char (car (car char-spec)))
317 (setq char-spec (cdr char-spec))))))
319 (defun char-db-insert-alist (alist &optional readable column)
321 (setq column (current-column)))
323 (concat "\n" (make-string (1+ column) ?\ )))
327 lbs cell rest separator)
330 (setq name (car (car alist))
331 value (cdr (car alist)))
332 (cond ((eq name 'char)
334 (if (setq ret (condition-case nil
342 (setq key (car (car value)))
343 ;; (if (find-charset key)
344 ;; (setq cal (cons key cal))
345 (setq al (cons key al))
347 (setq value (cdr value)))
348 (insert-char-attributes ret
352 (insert (prin1-to-string value)))
354 (insert line-breaking))
356 (insert (format "(%-18s " name))
357 (setq lbs (concat "\n" (make-string (current-column) ?\ )))
359 (setq cell (car value))
360 (if (and (consp cell)
362 (setq ret (condition-case nil
372 (setq key (car (car rest)))
373 ;; (if (find-charset key)
374 ;; (setq cal (cons key cal))
375 (setq al (cons key al))
377 (setq rest (cdr rest)))
380 (insert-char-attributes ret
384 (setq separator lbs))
387 (insert (prin1-to-string cell))
388 (setq separator " "))
389 (setq value (cdr value)))
391 (insert line-breaking))
393 (insert (format "(%-18s . %S)%s"
396 (setq alist (cdr alist))))
399 (defun char-db-insert-char-reference (plist &optional readable column)
401 (setq column (current-column)))
403 (concat "\n" (make-string (1+ column) ?\ )))
408 (setq name (pop plist))
409 (setq value (pop plist))
410 (cond ((eq name :char)
413 (cond ((numberp value)
414 (setq value (decode-char '=ucs value)))
416 ;; (setq value (or (find-char value)
419 (char-db-insert-char-spec value readable)
420 (insert line-breaking)
423 (insert (format "%s%s\t%d ; %c%s"
426 (ideographic-radical value)
430 (insert (format "%s%s\t%S" separator name value))
431 (setq separator line-breaking)))
435 (defun char-db-decode-isolated-char (ccs code-point)
438 (cond ((eq ccs 'arabic-iso8859-6)
439 (decode-char ccs code-point))
440 ((and (memq ccs '(=gt-pj-1
451 (setq ret (decode-char ccs code-point))
452 (setq ret (encode-char ret '=gt 'defined-only)))
453 (decode-builtin-char '=gt ret))
455 (decode-builtin-char ccs code-point))))
456 (cond ((and (<= 0 (char-int ret))
457 (<= (char-int ret) #x1F))
458 (decode-char '=ucs (+ #x2400 (char-int ret))))
459 ((= (char-int ret) #x7F)
463 (defvar char-db-convert-obsolete-format t)
465 (defun char-db-insert-ccs-feature (name value line-breaking)
471 ((memq name '(=shinjigen
473 =shinjigen@rev =shinjigen/+p@rev
475 "(%-18s . %04d)\t; %c")
476 ((eq name '=shinjigen@1ed/24pr)
477 "(%-18s . %04d)\t; %c")
478 ((or (memq name '(=daikanwa =>>daikanwa =>daikanwa
479 =daikanwa@rev1 =daikanwa@rev2
480 =daikanwa/+p =daikanwa/+2p
481 =gt =>>>gt =>>gt =>gt
485 =zinbun-oracle =>zinbun-oracle))
486 (string-match "^=adobe-" (symbol-name name)))
487 "(%-18s . %05d)\t; %c")
488 ((memq name '(=hanyo-denshi/ks =>>hanyo-denshi/ks mojikyo))
489 "(%-18s . %06d)\t; %c")
490 ((>= (charset-dimension name) 2)
491 "(%-18s . #x%04X)\t; %c")
493 "(%-18s . #x%02X)\t; %c"))
495 (if (= (charset-iso-graphic-plane name) 1)
497 (cond ((= (charset-dimension name) 1)
499 ((= (charset-dimension name) 2)
501 ((= (charset-dimension name) 3)
505 (char-db-decode-isolated-char name value)))
506 (if (and (= (charset-chars name) 94)
507 (= (charset-dimension name) 2))
508 (insert (format " [%02d-%02d]"
509 (- (lsh value -8) 32)
510 (- (logand value 255) 32))))
513 (insert (format "(%-18s . %s)" name value))
515 (insert line-breaking))
517 (defun char-db-insert-relation-feature (char name value line-breaking
519 (insert (format "(%-18s%s " name line-breaking))
520 (let ((lbs (concat "\n" (make-string (current-column) ?\ )))
521 separator cell sources required-features
524 (setq cell (car value))
526 (setq cell (decode-char '=ucs cell)))
528 ((eq name '->subsumptive)
529 (when (or (not (some (lambda (atr)
530 (get-char-attribute cell atr))
531 char-db-ignored-attributes))
533 (encode-char cell ccs 'defined-only))
537 (let ((char-db-ignored-attributes
539 char-db-ignored-attributes)))
540 (insert-char-attributes cell readable nil nil 'for-sub-node))
541 (setq separator lbs))
546 char (intern (format "%s*sources" name))))
547 (setq required-features nil)
548 (dolist (source sources)
552 shinjigen shinjigen@1ed shinjigen@rev))
553 (setq required-features
554 (union required-features
565 (setq required-features
566 (union required-features
571 ((find-charset (setq ret (intern (format "=%s" source))))
572 (setq required-features
573 (cons ret required-features)))
574 (t (setq required-features
575 (cons source required-features)))))
576 (cond ((string-match "@JP" (symbol-name name))
577 (setq required-features
578 (union required-features
586 ((string-match "@CN" (symbol-name name))
587 (setq required-features
588 (union required-features
595 (insert (format "%S" cell))
596 (char-db-insert-char-spec cell readable
599 (setq separator lbs))
603 (if (consp (car cell))
604 (char-db-insert-char-spec cell readable)
605 (char-db-insert-char-reference cell readable))
606 (setq separator lbs))
610 (insert (prin1-to-string cell))
611 (setq separator " ")))
612 (setq value (cdr value)))
614 (insert line-breaking)))
616 (defun insert-char-attributes (char &optional readable attributes column
619 (setq column (current-column)))
620 (let (name value ; has-long-ccs-name
624 (concat "\n" (make-string (1+ column) ?\ )))
625 lbs cell separator ret
627 dest-ccss ; sources required-features
632 (if (consp attributes)
634 (dolist (name attributes)
635 (unless (memq name char-db-ignored-attributes)
636 (if (find-charset name)
640 (dolist (name (char-attribute-list))
641 (unless (memq name char-db-ignored-attributes)
642 (if (find-charset name)
646 #'char-attribute-name<)))
648 (when (memq '<-subsumptive attributes)
649 (when (or readable (not for-sub-node))
650 (when (setq value (get-char-attribute char '<-subsumptive))
651 (char-db-insert-relation-feature char '<-subsumptive value
654 (setq attributes (delq '<-subsumptive attributes)))
655 (when (and (memq '<-denotational attributes)
656 (setq value (get-char-attribute char '<-denotational)))
657 (char-db-insert-relation-feature char '<-denotational value
660 (setq attributes (delq '<-denotational attributes)))
661 (when (and (memq 'name attributes)
662 (setq value (get-char-attribute char 'name)))
664 (if (> (+ (current-column) (length value)) 48)
667 value line-breaking))
668 (setq attributes (delq 'name attributes))
670 (when (and (memq 'name* attributes)
671 (setq value (get-char-attribute char 'name*)))
673 (if (> (+ (current-column) (length value)) 48)
676 value line-breaking))
677 (setq attributes (delq 'name* attributes))
679 (when (and (memq 'script attributes)
680 (setq value (get-char-attribute char 'script)))
681 (insert (format "(script\t\t%s)%s"
682 (mapconcat (function prin1-to-string)
685 (setq attributes (delq 'script attributes))
687 (dolist (name '(=>ucs =>ucs*))
688 (when (and (memq name attributes)
689 (setq value (get-char-attribute char name)))
690 (insert (format "(%-18s . #x%04X)\t; %c%s"
691 name value (decode-char '=ucs value)
693 (setq attributes (delq name attributes))))
694 (dolist (name '(=>ucs@gb =>ucs@big5))
695 (when (and (memq name attributes)
696 (setq value (get-char-attribute char name)))
697 (insert (format "(%-18s . #x%04X)\t; %c%s"
702 (symbol-name name) 2)))
705 (setq attributes (delq name attributes))
707 ;; (dolist (name '(=>daikanwa))
708 ;; (when (and (memq name attributes)
709 ;; (setq value (get-char-attribute char name)))
711 ;; (if (integerp value)
712 ;; (format "(%-18s . %05d)\t; %c%s"
713 ;; name value (decode-char '=daikanwa value)
715 ;; (format "(%-18s %s)\t; %c%s"
717 ;; (mapconcat (function prin1-to-string)
719 ;; (char-representative-of-daikanwa char)
721 ;; (setq attributes (delq name attributes))))
722 (when (and (memq 'general-category attributes)
723 (setq value (get-char-attribute char 'general-category)))
725 "(general-category\t%s) ; %s%s"
726 (mapconcat (lambda (cell)
729 (cond ((rassoc value unidata-normative-category-alist)
730 "Normative Category")
731 ((rassoc value unidata-informative-category-alist)
732 "Informative Category")
736 (setq attributes (delq 'general-category attributes))
738 (when (and (memq 'bidi-category attributes)
739 (setq value (get-char-attribute char 'bidi-category)))
740 (insert (format "(bidi-category\t. %S)%s"
743 (setq attributes (delq 'bidi-category attributes))
745 (unless (or (not (memq 'mirrored attributes))
746 (eq (setq value (get-char-attribute char 'mirrored 'empty))
748 (insert (format "(mirrored\t\t. %S)%s"
751 (setq attributes (delq 'mirrored attributes))
754 ((and (memq 'decimal-digit-value attributes)
755 (setq value (get-char-attribute char 'decimal-digit-value)))
756 (insert (format "(decimal-digit-value . %S)%s"
759 (setq attributes (delq 'decimal-digit-value attributes))
760 (when (and (memq 'digit-value attributes)
761 (setq value (get-char-attribute char 'digit-value)))
762 (insert (format "(digit-value\t . %S)%s"
765 (setq attributes (delq 'digit-value attributes))
767 (when (and (memq 'numeric-value attributes)
768 (setq value (get-char-attribute char 'numeric-value)))
769 (insert (format "(numeric-value\t . %S)%s"
772 (setq attributes (delq 'numeric-value attributes))
776 (when (and (memq 'digit-value attributes)
777 (setq value (get-char-attribute char 'digit-value)))
778 (insert (format "(digit-value\t. %S)%s"
781 (setq attributes (delq 'digit-value attributes))
783 (when (and (memq 'numeric-value attributes)
784 (setq value (get-char-attribute char 'numeric-value)))
785 (insert (format "(numeric-value\t. %S)%s"
788 (setq attributes (delq 'numeric-value attributes))
790 (when (and (memq 'iso-10646-comment attributes)
791 (setq value (get-char-attribute char 'iso-10646-comment)))
792 (insert (format "(iso-10646-comment\t. %S)%s"
795 (setq attributes (delq 'iso-10646-comment attributes))
797 (when (and (memq 'morohashi-daikanwa attributes)
798 (setq value (get-char-attribute char 'morohashi-daikanwa)))
799 (insert (format "(morohashi-daikanwa\t%s)%s"
800 (mapconcat (function prin1-to-string) value " ")
802 (setq attributes (delq 'morohashi-daikanwa attributes))
806 (when (and (memq 'ideographic-radical attributes)
807 (setq value (get-char-attribute char 'ideographic-radical)))
809 (insert (format "(ideographic-radical . %S)\t; %c%s"
811 (ideographic-radical radical)
813 (setq attributes (delq 'ideographic-radical attributes))
815 (when (and (memq 'shuowen-radical attributes)
816 (setq value (get-char-attribute char 'shuowen-radical)))
817 (insert (format "(shuowen-radical\t. %S)\t; %c%s"
819 (shuowen-radical value)
821 (setq attributes (delq 'shuowen-radical attributes))
826 char-db-feature-domains
828 (dolist (feature (char-attribute-list))
829 (setq feature (symbol-name feature))
831 "\\(radical\\|strokes\\)@\\([^@*]+\\)\\(\\*\\|$\\)"
833 (setq domain (intern (match-string 2 feature)))
834 (unless (memq domain dest)
835 (setq dest (cons domain dest)))))
836 (sort dest #'string<))))
837 (setq key (intern (format "%s@%s" 'ideographic-radical domain)))
838 (when (and (memq key attributes)
839 (setq value (get-char-attribute char key)))
841 (insert (format "(%s . %S)\t; %c%s"
844 (ideographic-radical radical)
846 (setq attributes (delq key attributes))
848 (setq key (intern (format "%s@%s" 'ideographic-strokes domain)))
849 (when (and (memq key attributes)
850 (setq value (get-char-attribute char key)))
852 (insert (format "(%s . %S)%s"
856 (setq attributes (delq key attributes))
858 (setq key (intern (format "%s@%s" 'total-strokes domain)))
859 (when (and (memq key attributes)
860 (setq value (get-char-attribute char key)))
861 (insert (format "(%s . %S)%s"
865 (setq attributes (delq key attributes))
867 (dolist (feature '(ideographic-radical
870 (setq key (intern (format "%s@%s*sources" feature domain)))
871 (when (and (memq key attributes)
872 (setq value (get-char-attribute char key)))
873 (insert (format "(%s%s" key line-breaking))
875 (insert (format " %s" cell)))
877 (insert line-breaking)
878 (setq attributes (delq key attributes))
881 (when (and (memq 'ideographic-strokes attributes)
882 (setq value (get-char-attribute char 'ideographic-strokes)))
884 (insert (format "(ideographic-strokes . %S)%s"
887 (setq attributes (delq 'ideographic-strokes attributes))
889 (when (and (memq 'kangxi-radical attributes)
890 (setq value (get-char-attribute char 'kangxi-radical)))
891 (unless (eq value radical)
892 (insert (format "(kangxi-radical\t . %S)\t; %c%s"
894 (ideographic-radical value)
897 (setq radical value)))
898 (setq attributes (delq 'kangxi-radical attributes))
900 (when (and (memq 'kangxi-strokes attributes)
901 (setq value (get-char-attribute char 'kangxi-strokes)))
902 (unless (eq value strokes)
903 (insert (format "(kangxi-strokes\t . %S)%s"
907 (setq strokes value)))
908 (setq attributes (delq 'kangxi-strokes attributes))
910 (when (and (memq 'japanese-radical attributes)
911 (setq value (get-char-attribute char 'japanese-radical)))
912 (unless (eq value radical)
913 (insert (format "(japanese-radical\t . %S)\t; %c%s"
915 (ideographic-radical value)
918 (setq radical value)))
919 (setq attributes (delq 'japanese-radical attributes))
921 (when (and (memq 'japanese-strokes attributes)
922 (setq value (get-char-attribute char 'japanese-strokes)))
923 (unless (eq value strokes)
924 (insert (format "(japanese-strokes\t . %S)%s"
928 (setq strokes value)))
929 (setq attributes (delq 'japanese-strokes attributes))
931 (when (and (memq 'cns-radical attributes)
932 (setq value (get-char-attribute char 'cns-radical)))
933 (insert (format "(cns-radical\t . %S)\t; %c%s"
935 (ideographic-radical value)
937 (setq attributes (delq 'cns-radical attributes))
939 (when (and (memq 'cns-strokes attributes)
940 (setq value (get-char-attribute char 'cns-strokes)))
941 (unless (eq value strokes)
942 (insert (format "(cns-strokes\t . %S)%s"
946 (setq strokes value)))
947 (setq attributes (delq 'cns-strokes attributes))
949 (when (and (memq 'shinjigen-1-radical attributes)
950 (setq value (get-char-attribute char 'shinjigen-1-radical)))
951 (unless (eq value radical)
952 (insert (format "(shinjigen-1-radical . %S)\t; %c%s"
954 (ideographic-radical value)
957 (setq radical value)))
958 (setq attributes (delq 'shinjigen-1-radical attributes))
960 (when (and (memq 'ideographic- attributes)
961 (setq value (get-char-attribute char 'ideographic-)))
962 (insert "(ideographic- ")
963 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
966 (setq cell (car value))
968 (setq cell (decode-char '=ucs cell)))
969 (cond ((characterp cell)
973 (insert (format "%S" cell))
974 (char-db-insert-char-spec cell readable))
975 (setq separator lbs))
979 (if (consp (car cell))
980 (char-db-insert-char-spec cell readable)
981 (char-db-insert-char-reference cell readable))
982 (setq separator lbs))
986 (insert (prin1-to-string cell))
987 (setq separator " ")))
988 (setq value (cdr value)))
990 (insert line-breaking)
991 (setq attributes (delq 'ideographic- attributes)))
992 (when (and (memq 'total-strokes attributes)
993 (setq value (get-char-attribute char 'total-strokes)))
994 (insert (format "(total-strokes . %S)%s"
997 (setq attributes (delq 'total-strokes attributes))
999 (when (and (memq '->ideograph attributes)
1000 (setq value (get-char-attribute char '->ideograph)))
1001 (insert (format "(->ideograph\t%s)%s"
1002 (mapconcat (lambda (code)
1003 (cond ((symbolp code)
1006 (format "#x%04X" code))
1009 line-breaking code))))
1012 (setq attributes (delq '->ideograph attributes))
1014 ;; (when (and (memq '->decomposition attributes)
1015 ;; (setq value (get-char-attribute char '->decomposition)))
1016 ;; (insert (format "(->decomposition\t%s)%s"
1017 ;; (mapconcat (lambda (code)
1018 ;; (cond ((symbolp code)
1019 ;; (symbol-name code))
1020 ;; ((characterp code)
1022 ;; (format "%S" code)
1027 ;; (format "#x%04X" code))
1029 ;; (format "%s%S" line-breaking code))))
1032 ;; (setq attributes (delq '->decomposition attributes))
1034 (if (equal (get-char-attribute char '->titlecase)
1035 (get-char-attribute char '->uppercase))
1036 (setq attributes (delq '->titlecase attributes)))
1037 (when (and (memq '->mojikyo attributes)
1038 (setq value (get-char-attribute char '->mojikyo)))
1039 (insert (format "(->mojikyo\t\t. %06d)\t; %c%s"
1040 value (decode-char 'mojikyo value)
1042 (setq attributes (delq '->mojikyo attributes))
1044 (when (and (memq 'hanyu-dazidian-vol attributes)
1045 (setq value (get-char-attribute char 'hanyu-dazidian-vol)))
1046 (insert (format "(hanyu-dazidian-vol . %d)%s"
1047 value line-breaking))
1048 (setq attributes (delq 'hanyu-dazidian-vol attributes))
1050 (when (and (memq 'hanyu-dazidian-page attributes)
1051 (setq value (get-char-attribute char 'hanyu-dazidian-page)))
1052 (insert (format "(hanyu-dazidian-page . %d)%s"
1053 value line-breaking))
1054 (setq attributes (delq 'hanyu-dazidian-page attributes))
1056 (when (and (memq 'hanyu-dazidian-char attributes)
1057 (setq value (get-char-attribute char 'hanyu-dazidian-char)))
1058 (insert (format "(hanyu-dazidian-char . %d)%s"
1059 value line-breaking))
1060 (setq attributes (delq 'hanyu-dazidian-char attributes))
1063 (dolist (ignored '(composition
1064 ->denotational <-subsumptive ->ucs-unified
1065 ->ideographic-component-forms))
1066 (setq attributes (delq ignored attributes))))
1068 (setq name (car attributes))
1069 (unless (eq (setq value (get-char-attribute char name 'value-is-empty))
1071 (cond ((setq ret (find-charset name))
1072 (setq name (charset-name ret))
1073 (when (not (memq name dest-ccss))
1074 (setq dest-ccss (cons name dest-ccss))
1075 (char-db-insert-ccs-feature name value line-breaking))
1077 ((string-match "^=>ucs@" (symbol-name name))
1078 (insert (format "(%-18s . #x%04X)\t; %c%s"
1079 name value (decode-char '=ucs value)
1082 ((eq name 'jisx0208-1978/4X)
1083 (insert (format "(%-18s . #x%04X)%s"
1089 (not (eq name '->subsumptive))
1090 (not (eq name '->uppercase))
1091 (not (eq name '->lowercase))
1092 (not (eq name '->titlecase))
1093 (not (eq name '->canonical))
1094 (not (eq name '->Bopomofo))
1095 (not (eq name '->mistakable))
1096 (not (eq name '->ideographic-variants))
1097 (null (get-char-attribute
1098 char (intern (format "%s*sources" name))))
1099 (not (string-match "\\*sources$" (symbol-name name)))
1100 (null (get-char-attribute
1101 char (intern (format "%s*note" name))))
1102 (not (string-match "\\*note$" (symbol-name name)))
1103 (or (eq name '<-identical)
1104 (eq name '<-uppercase)
1105 (eq name '<-lowercase)
1106 (eq name '<-titlecase)
1107 (eq name '<-canonical)
1108 (eq name '<-ideographic-variants)
1109 ;; (eq name '<-synonyms)
1110 (string-match "^<-synonyms" (symbol-name name))
1111 (eq name '<-mistakable)
1112 (when (string-match "^->" (symbol-name name))
1114 ((string-match "^->fullwidth" (symbol-name name))
1115 (not (and (consp value)
1116 (characterp (car value))
1118 (car value) '=ucs 'defined-only)))
1123 ((or (eq name 'ideographic-structure)
1124 (eq name 'ideographic-combination)
1125 (eq name 'ideographic-)
1126 (eq name '=decomposition)
1127 (char-feature-base-name= '=decomposition name)
1128 (char-feature-base-name= '=>decomposition name)
1129 ;; (string-match "^=>*decomposition\\(@[^*]+\\)?$"
1130 ;; (symbol-name name))
1131 (string-match "^\\(->\\|<-\\)[^*]*$" (symbol-name name))
1132 (string-match "^\\(->\\|<-\\)[^*]*\\*sources$"
1135 (char-db-insert-relation-feature char name value
1138 ((memq name '(ideograph=
1139 original-ideograph-of
1140 ancient-ideograph-of
1143 ;; simplified-ideograph-of
1144 ideographic-variants
1145 ;; ideographic-different-form-of
1147 (insert (format "(%-18s%s " name line-breaking))
1148 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1150 (while (consp value)
1151 (setq cell (car value))
1152 (if (and (consp cell)
1157 (char-db-insert-alist cell readable)
1158 (setq separator lbs))
1161 (insert (prin1-to-string cell))
1162 (setq separator " "))
1163 (setq value (cdr value)))
1165 (insert line-breaking))
1167 (insert (format "(%-18s " name))
1168 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1170 (while (consp value)
1171 (setq cell (car value))
1172 (if (and (consp cell)
1174 (setq ret (condition-case nil
1182 (setq key (car (car rest)))
1183 (if (find-charset key)
1184 (setq cal (cons key cal))
1185 (setq al (cons key al)))
1186 (setq rest (cdr rest)))
1189 (insert-char-attributes ret
1193 (setq separator lbs))
1194 (setq ret (prin1-to-string cell))
1196 (if (< (+ (current-column)
1203 (setq separator " "))
1204 (setq value (cdr value)))
1206 (insert line-breaking))
1208 (insert (format "(%-18s" name))
1209 (setq ret (prin1-to-string value))
1210 (unless (< (+ (current-column)
1214 (insert line-breaking))
1215 (insert " . " ret ")" line-breaking)
1216 ;; (insert (format "(%-18s . %S)%s"
1221 (setq attributes (cdr attributes)))
1224 (defun insert-char-data (char &optional readable
1227 (narrow-to-region (point)(point))
1228 (insert "(define-char
1230 (insert-char-attributes char readable attributes)
1232 (goto-char (point-min))
1233 (while (re-search-forward "[ \t]+$" nil t)
1236 (goto-char (point-min))
1237 (while (re-search-forward "[ \t][ \t][ \t]*" nil t)
1238 (let ((column (current-column))
1239 (indent-tabs-mode t))
1240 (delete-region (match-beginning 0) (point))
1241 (indent-to column)))
1242 (goto-char (point-max))
1243 ;; (tabify (point-min)(point-max))
1246 (defun insert-char-data-with-variant (char &optional printable
1248 script excluded-script)
1249 (insert-char-data char printable)
1250 (let ((variants (char-variants char))
1253 (setq variants (sort variants #'<))
1254 (setq rest variants)
1255 (setq variants (cons char variants))
1257 (setq variant (car rest))
1258 (unless (get-char-attribute variant '<-subsumptive)
1259 (if (and (or (null script)
1260 (null (setq vs (get-char-attribute variant 'script)))
1262 (or (null excluded-script)
1263 (null (setq vs (get-char-attribute variant 'script)))
1264 (not (memq excluded-script vs))))
1265 (unless (and no-ucs-unified (get-char-attribute variant '=ucs))
1266 (insert-char-data variant printable)
1267 (if (setq ret (char-variants variant))
1269 (or (memq (car ret) variants)
1270 ;; (get-char-attribute (car ret) '<-subsumptive)
1271 (setq rest (nconc rest (list (car ret)))))
1272 (setq ret (cdr ret)))))))
1273 (setq rest (cdr rest)))))
1275 (defun insert-char-range-data (min max &optional script excluded-script)
1278 (while (<= code max)
1279 (setq char (decode-char '=ucs code))
1280 (if (encode-char char '=ucs 'defined-only)
1281 (insert-char-data-with-variant char nil 'no-ucs-unified
1282 script excluded-script))
1283 (setq code (1+ code)))))
1285 (defun write-char-range-data-to-file (min max file
1286 &optional script excluded-script)
1287 (let ((coding-system-for-write char-db-file-coding-system))
1289 (insert (format ";; -*- coding: %s -*-\n"
1290 char-db-file-coding-system))
1291 (insert-char-range-data min max script excluded-script)
1292 (write-region (point-min)(point-max) file))))
1294 (defvar what-character-original-window-configuration)
1297 (defun what-char-definition (char)
1298 (interactive (list (char-after)))
1299 (let ((buf (get-buffer-create "*Character Description*"))
1300 (the-buf (current-buffer))
1301 (win-conf (current-window-configuration)))
1303 (make-local-variable 'what-character-original-window-configuration)
1304 (setq what-character-original-window-configuration win-conf)
1305 (setq buffer-read-only nil)
1309 (insert-char-data-with-variant char 'printable)
1310 (unless (char-attribute-alist char)
1311 (insert (format ";; = %c\n"
1312 (let* ((rest (split-char char))
1316 (setq code (logior (lsh code 8)
1318 (decode-char ccs code)))))
1319 ;; (char-db-update-comment)
1320 (set-buffer-modified-p nil)
1321 (view-mode the-buf (lambda (buf)
1322 (set-window-configuration
1323 what-character-original-window-configuration)
1325 (goto-char (point-min)))
1327 (set-window-configuration
1328 what-character-original-window-configuration)
1329 (signal (car err) (cdr err)))))))
1335 (provide 'char-db-util)
1337 ;;; char-db-util.el ends here