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
231 ;;; @ char-db formatters
234 (defun char-db-make-char-spec (char)
236 (cond ((characterp char)
237 (cond ((and (setq ret (encode-char char '=ucs 'defined-only))
238 (not (and (<= #xE000 ret)(<= ret #xF8FF))))
239 (setq char-spec (list (cons '=ucs ret)))
240 (cond ((setq ret (get-char-attribute char 'name))
241 (setq char-spec (cons (cons 'name ret) char-spec))
243 ((setq ret (get-char-attribute char 'name*))
244 (setq char-spec (cons (cons 'name* ret) char-spec))
249 (let ((rest char-db-coded-charset-priority-list)
252 (setq ccs (charset-name
253 (find-charset (car rest))))
255 (encode-char char ccs
257 (throw 'tag (cons ccs ret)))
258 (setq rest (cdr rest))))))
259 (setq char-spec (list ret))
260 (dolist (ccs (delq (car ret) (charset-list)))
261 (if (and (or (charset-iso-final-char ccs)
268 (string-match "=ucs@" (symbol-name ccs)))
269 (setq ccs (charset-name ccs))
270 (null (assq ccs char-spec))
271 (setq ret (encode-char char ccs 'defined-only)))
272 (setq char-spec (cons (cons ccs ret) char-spec))))
274 (setq char-spec (split-char char)))
275 (cond ((setq ret (get-char-attribute char 'name))
276 (setq char-spec (cons (cons 'name ret) char-spec))
278 ((setq ret (get-char-attribute char 'name*))
279 (setq char-spec (cons (cons 'name* ret) char-spec))
282 ((setq ret (get-char-attribute
283 char 'ideographic-combination))
285 (cons (cons 'ideographic-combination ret)
292 (defun char-db-insert-char-spec (char &optional readable column
295 (setq column (current-column)))
296 (let (char-spec temp-char)
297 (setq char-spec (char-db-make-char-spec char))
298 (unless (or (characterp char) ; char
300 (setq char (find-char char-spec))
302 ;; define temporary character
303 ;; Current implementation is dirty.
304 (setq temp-char (define-char (cons '(ideograph-daikanwa . 0)
306 (remove-char-attribute temp-char 'ideograph-daikanwa)
307 (setq char temp-char))
308 (insert-char-attributes char
310 (union (mapcar #'car char-spec)
314 ;; undefine temporary character
315 ;; Current implementation is dirty.
316 (setq char-spec (char-attribute-alist temp-char))
318 (remove-char-attribute temp-char (car (car char-spec)))
319 (setq char-spec (cdr char-spec))))))
321 (defun char-db-insert-alist (alist &optional readable column)
323 (setq column (current-column)))
325 (concat "\n" (make-string (1+ column) ?\ )))
329 lbs cell rest separator)
332 (setq name (car (car alist))
333 value (cdr (car alist)))
334 (cond ((eq name 'char)
336 (if (setq ret (condition-case nil
344 (setq key (car (car value)))
345 ;; (if (find-charset key)
346 ;; (setq cal (cons key cal))
347 (setq al (cons key al))
349 (setq value (cdr value)))
350 (insert-char-attributes ret
354 (insert (prin1-to-string value)))
356 (insert line-breaking))
358 (insert (format "(%-18s " name))
359 (setq lbs (concat "\n" (make-string (current-column) ?\ )))
361 (setq cell (car value))
362 (if (and (consp cell)
364 (setq ret (condition-case nil
374 (setq key (car (car rest)))
375 ;; (if (find-charset key)
376 ;; (setq cal (cons key cal))
377 (setq al (cons key al))
379 (setq rest (cdr rest)))
382 (insert-char-attributes ret
386 (setq separator lbs))
389 (insert (prin1-to-string cell))
390 (setq separator " "))
391 (setq value (cdr value)))
393 (insert line-breaking))
395 (insert (format "(%-18s . %S)%s"
398 (setq alist (cdr alist))))
401 (defun char-db-insert-char-reference (plist &optional readable column)
403 (setq column (current-column)))
405 (concat "\n" (make-string (1+ column) ?\ )))
410 (setq name (pop plist))
411 (setq value (pop plist))
412 (cond ((eq name :char)
415 (cond ((numberp value)
416 (setq value (decode-char '=ucs value)))
418 ;; (setq value (or (find-char value)
421 (char-db-insert-char-spec value readable)
422 (insert line-breaking)
425 (insert (format "%s%s\t%d ; %c%s"
428 (ideographic-radical value)
432 (insert (format "%s%s\t%S" separator name value))
433 (setq separator line-breaking)))
437 (defun char-db-decode-isolated-char (ccs code-point)
440 (cond ((eq ccs 'arabic-iso8859-6)
441 (decode-char ccs code-point))
442 ((and (memq ccs '(=gt-pj-1
453 (setq ret (decode-char ccs code-point))
454 (setq ret (encode-char ret '=gt 'defined-only)))
455 (decode-builtin-char '=gt ret))
457 (decode-builtin-char ccs code-point))))
458 (cond ((and (<= 0 (char-int ret))
459 (<= (char-int ret) #x1F))
460 (decode-char '=ucs (+ #x2400 (char-int ret))))
461 ((= (char-int ret) #x7F)
465 (defvar char-db-convert-obsolete-format t)
467 (defun char-db-insert-ccs-feature (name value line-breaking)
473 ((memq name '(=shinjigen
475 =shinjigen@rev =shinjigen/+p@rev
477 "(%-18s . %04d)\t; %c")
478 ((eq name '=shinjigen@1ed/24pr)
479 "(%-18s . %04d)\t; %c")
480 ((or (memq name '(=daikanwa =>>daikanwa =>daikanwa
481 =daikanwa@rev1 =daikanwa@rev2
482 =daikanwa/+p =daikanwa/+2p
483 =gt =>>>gt =>>gt =>gt
487 =zinbun-oracle =>zinbun-oracle))
488 (string-match "^=adobe-" (symbol-name name)))
489 "(%-18s . %05d)\t; %c")
490 ((memq name '(=hanyo-denshi/ks =>>hanyo-denshi/ks mojikyo))
491 "(%-18s . %06d)\t; %c")
492 ((>= (charset-dimension name) 2)
493 "(%-18s . #x%04X)\t; %c")
495 "(%-18s . #x%02X)\t; %c"))
497 (if (= (charset-iso-graphic-plane name) 1)
499 (cond ((= (charset-dimension name) 1)
501 ((= (charset-dimension name) 2)
503 ((= (charset-dimension name) 3)
507 (char-db-decode-isolated-char name value)))
508 (if (and (= (charset-chars name) 94)
509 (= (charset-dimension name) 2))
510 (insert (format " [%02d-%02d]"
511 (- (lsh value -8) 32)
512 (- (logand value 255) 32))))
515 (insert (format "(%-18s . %s)" name value))
517 (insert line-breaking))
519 (defun char-db-insert-relation-feature (char name value line-breaking
521 (insert (format "(%-18s%s " name line-breaking))
522 (let ((lbs (concat "\n" (make-string (current-column) ?\ )))
523 separator cell sources required-features
526 (setq cell (car value))
528 (setq cell (decode-char '=ucs cell)))
530 ((eq name '->subsumptive)
531 (when (or (not (some (lambda (atr)
532 (get-char-attribute cell atr))
533 char-db-ignored-attributes))
535 (encode-char cell ccs 'defined-only))
539 (let ((char-db-ignored-attributes
541 char-db-ignored-attributes)))
542 (insert-char-attributes cell readable nil nil 'for-sub-node))
543 (setq separator lbs))
548 char (intern (format "%s*sources" name))))
549 (setq required-features nil)
550 (dolist (source sources)
554 shinjigen shinjigen@1ed shinjigen@rev))
555 (setq required-features
556 (union required-features
567 (setq required-features
568 (union required-features
573 ((find-charset (setq ret (intern (format "=%s" source))))
574 (setq required-features
575 (cons ret required-features)))
576 (t (setq required-features
577 (cons source required-features)))))
578 (cond ((string-match "@JP" (symbol-name name))
579 (setq required-features
580 (union required-features
588 ((string-match "@CN" (symbol-name name))
589 (setq required-features
590 (union required-features
597 (insert (format "%S" cell))
598 (char-db-insert-char-spec cell readable
601 (setq separator lbs))
605 (if (consp (car cell))
606 (char-db-insert-char-spec cell readable)
607 (char-db-insert-char-reference cell readable))
608 (setq separator lbs))
612 (insert (prin1-to-string cell))
613 (setq separator " ")))
614 (setq value (cdr value)))
616 (insert line-breaking)))
618 (defun insert-char-attributes (char &optional readable attributes column
621 (setq column (current-column)))
622 (let (name value ; has-long-ccs-name
626 (concat "\n" (make-string (1+ column) ?\ )))
627 lbs cell separator ret
629 dest-ccss ; sources required-features
634 (if (consp attributes)
636 (dolist (name attributes)
637 (unless (memq name char-db-ignored-attributes)
638 (if (find-charset name)
642 (dolist (name (char-attribute-list))
643 (unless (memq name char-db-ignored-attributes)
644 (if (find-charset name)
648 #'char-attribute-name<)))
650 (when (memq '<-subsumptive attributes)
651 (when (or readable (not for-sub-node))
652 (when (setq value (get-char-attribute char '<-subsumptive))
653 (char-db-insert-relation-feature char '<-subsumptive value
656 (setq attributes (delq '<-subsumptive attributes)))
657 (when (and (memq '<-denotational attributes)
658 (setq value (get-char-attribute char '<-denotational)))
659 (char-db-insert-relation-feature char '<-denotational value
662 (setq attributes (delq '<-denotational attributes)))
663 (when (and (memq 'name attributes)
664 (setq value (get-char-attribute char 'name)))
666 (if (> (+ (current-column) (length value)) 48)
669 value line-breaking))
670 (setq attributes (delq 'name attributes))
672 (when (and (memq 'name* attributes)
673 (setq value (get-char-attribute char 'name*)))
675 (if (> (+ (current-column) (length value)) 48)
678 value line-breaking))
679 (setq attributes (delq 'name* attributes))
681 (when (and (memq 'script attributes)
682 (setq value (get-char-attribute char 'script)))
683 (insert (format "(script\t\t%s)%s"
684 (mapconcat (function prin1-to-string)
687 (setq attributes (delq 'script attributes))
689 (dolist (name '(=>ucs =>ucs*))
690 (when (and (memq name attributes)
691 (setq value (get-char-attribute char name)))
692 (insert (format "(%-18s . #x%04X)\t; %c%s"
693 name value (decode-char '=ucs value)
695 (setq attributes (delq name attributes))))
696 (dolist (name '(=>ucs@gb =>ucs@big5))
697 (when (and (memq name attributes)
698 (setq value (get-char-attribute char name)))
699 (insert (format "(%-18s . #x%04X)\t; %c%s"
704 (symbol-name name) 2)))
707 (setq attributes (delq name attributes))
709 ;; (dolist (name '(=>daikanwa))
710 ;; (when (and (memq name attributes)
711 ;; (setq value (get-char-attribute char name)))
713 ;; (if (integerp value)
714 ;; (format "(%-18s . %05d)\t; %c%s"
715 ;; name value (decode-char '=daikanwa value)
717 ;; (format "(%-18s %s)\t; %c%s"
719 ;; (mapconcat (function prin1-to-string)
721 ;; (char-representative-of-daikanwa char)
723 ;; (setq attributes (delq name attributes))))
724 (when (and (memq 'general-category attributes)
725 (setq value (get-char-attribute char 'general-category)))
727 "(general-category\t%s) ; %s%s"
728 (mapconcat (lambda (cell)
731 (cond ((rassoc value unidata-normative-category-alist)
732 "Normative Category")
733 ((rassoc value unidata-informative-category-alist)
734 "Informative Category")
738 (setq attributes (delq 'general-category attributes))
740 (when (and (memq 'bidi-category attributes)
741 (setq value (get-char-attribute char 'bidi-category)))
742 (insert (format "(bidi-category\t. %S)%s"
745 (setq attributes (delq 'bidi-category attributes))
747 (unless (or (not (memq 'mirrored attributes))
748 (eq (setq value (get-char-attribute char 'mirrored 'empty))
750 (insert (format "(mirrored\t\t. %S)%s"
753 (setq attributes (delq 'mirrored attributes))
756 ((and (memq 'decimal-digit-value attributes)
757 (setq value (get-char-attribute char 'decimal-digit-value)))
758 (insert (format "(decimal-digit-value . %S)%s"
761 (setq attributes (delq 'decimal-digit-value attributes))
762 (when (and (memq 'digit-value attributes)
763 (setq value (get-char-attribute char 'digit-value)))
764 (insert (format "(digit-value\t . %S)%s"
767 (setq attributes (delq 'digit-value attributes))
769 (when (and (memq 'numeric-value attributes)
770 (setq value (get-char-attribute char 'numeric-value)))
771 (insert (format "(numeric-value\t . %S)%s"
774 (setq attributes (delq 'numeric-value attributes))
778 (when (and (memq 'digit-value attributes)
779 (setq value (get-char-attribute char 'digit-value)))
780 (insert (format "(digit-value\t. %S)%s"
783 (setq attributes (delq 'digit-value attributes))
785 (when (and (memq 'numeric-value attributes)
786 (setq value (get-char-attribute char 'numeric-value)))
787 (insert (format "(numeric-value\t. %S)%s"
790 (setq attributes (delq 'numeric-value attributes))
792 (when (and (memq 'iso-10646-comment attributes)
793 (setq value (get-char-attribute char 'iso-10646-comment)))
794 (insert (format "(iso-10646-comment\t. %S)%s"
797 (setq attributes (delq 'iso-10646-comment attributes))
799 (when (and (memq 'morohashi-daikanwa attributes)
800 (setq value (get-char-attribute char 'morohashi-daikanwa)))
801 (insert (format "(morohashi-daikanwa\t%s)%s"
802 (mapconcat (function prin1-to-string) value " ")
804 (setq attributes (delq 'morohashi-daikanwa attributes))
808 (when (and (memq 'ideographic-radical attributes)
809 (setq value (get-char-attribute char 'ideographic-radical)))
811 (insert (format "(ideographic-radical . %S)\t; %c%s"
813 (ideographic-radical radical)
815 (setq attributes (delq 'ideographic-radical attributes))
817 (when (and (memq 'shuowen-radical attributes)
818 (setq value (get-char-attribute char 'shuowen-radical)))
819 (insert (format "(shuowen-radical\t. %S)\t; %c%s"
821 (shuowen-radical value)
823 (setq attributes (delq 'shuowen-radical attributes))
828 char-db-feature-domains
830 (dolist (feature (char-attribute-list))
831 (setq feature (symbol-name feature))
833 "\\(radical\\|strokes\\)@\\([^@*]+\\)\\(\\*\\|$\\)"
835 (setq domain (intern (match-string 2 feature)))
836 (unless (memq domain dest)
837 (setq dest (cons domain dest)))))
838 (sort dest #'string<))))
839 (setq key (intern (format "%s@%s" 'ideographic-radical domain)))
840 (when (and (memq key attributes)
841 (setq value (get-char-attribute char key)))
843 (insert (format "(%s . %S)\t; %c%s"
846 (ideographic-radical radical)
848 (setq attributes (delq key attributes))
850 (setq key (intern (format "%s@%s" 'ideographic-strokes domain)))
851 (when (and (memq key attributes)
852 (setq value (get-char-attribute char key)))
854 (insert (format "(%s . %S)%s"
858 (setq attributes (delq key attributes))
860 (setq key (intern (format "%s@%s" 'total-strokes domain)))
861 (when (and (memq key attributes)
862 (setq value (get-char-attribute char key)))
863 (insert (format "(%s . %S)%s"
867 (setq attributes (delq key attributes))
869 (dolist (feature '(ideographic-radical
872 (setq key (intern (format "%s@%s*sources" feature domain)))
873 (when (and (memq key attributes)
874 (setq value (get-char-attribute char key)))
875 (insert (format "(%s%s" key line-breaking))
877 (insert (format " %s" cell)))
879 (insert line-breaking)
880 (setq attributes (delq key attributes))
883 (when (and (memq 'ideographic-strokes attributes)
884 (setq value (get-char-attribute char 'ideographic-strokes)))
886 (insert (format "(ideographic-strokes . %S)%s"
889 (setq attributes (delq 'ideographic-strokes attributes))
891 (when (and (memq 'kangxi-radical attributes)
892 (setq value (get-char-attribute char 'kangxi-radical)))
893 (unless (eq value radical)
894 (insert (format "(kangxi-radical\t . %S)\t; %c%s"
896 (ideographic-radical value)
899 (setq radical value)))
900 (setq attributes (delq 'kangxi-radical attributes))
902 (when (and (memq 'kangxi-strokes attributes)
903 (setq value (get-char-attribute char 'kangxi-strokes)))
904 (unless (eq value strokes)
905 (insert (format "(kangxi-strokes\t . %S)%s"
909 (setq strokes value)))
910 (setq attributes (delq 'kangxi-strokes attributes))
912 (when (and (memq 'japanese-radical attributes)
913 (setq value (get-char-attribute char 'japanese-radical)))
914 (unless (eq value radical)
915 (insert (format "(japanese-radical\t . %S)\t; %c%s"
917 (ideographic-radical value)
920 (setq radical value)))
921 (setq attributes (delq 'japanese-radical attributes))
923 (when (and (memq 'japanese-strokes attributes)
924 (setq value (get-char-attribute char 'japanese-strokes)))
925 (unless (eq value strokes)
926 (insert (format "(japanese-strokes\t . %S)%s"
930 (setq strokes value)))
931 (setq attributes (delq 'japanese-strokes attributes))
933 (when (and (memq 'cns-radical attributes)
934 (setq value (get-char-attribute char 'cns-radical)))
935 (insert (format "(cns-radical\t . %S)\t; %c%s"
937 (ideographic-radical value)
939 (setq attributes (delq 'cns-radical attributes))
941 (when (and (memq 'cns-strokes attributes)
942 (setq value (get-char-attribute char 'cns-strokes)))
943 (unless (eq value strokes)
944 (insert (format "(cns-strokes\t . %S)%s"
948 (setq strokes value)))
949 (setq attributes (delq 'cns-strokes attributes))
951 (when (and (memq 'shinjigen-1-radical attributes)
952 (setq value (get-char-attribute char 'shinjigen-1-radical)))
953 (unless (eq value radical)
954 (insert (format "(shinjigen-1-radical . %S)\t; %c%s"
956 (ideographic-radical value)
959 (setq radical value)))
960 (setq attributes (delq 'shinjigen-1-radical attributes))
962 (when (and (memq 'ideographic- attributes)
963 (setq value (get-char-attribute char 'ideographic-)))
964 (insert "(ideographic- ")
965 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
968 (setq cell (car value))
970 (setq cell (decode-char '=ucs cell)))
971 (cond ((characterp cell)
975 (insert (format "%S" cell))
976 (char-db-insert-char-spec cell readable))
977 (setq separator lbs))
981 (if (consp (car cell))
982 (char-db-insert-char-spec cell readable)
983 (char-db-insert-char-reference cell readable))
984 (setq separator lbs))
988 (insert (prin1-to-string cell))
989 (setq separator " ")))
990 (setq value (cdr value)))
992 (insert line-breaking)
993 (setq attributes (delq 'ideographic- attributes)))
994 (when (and (memq 'total-strokes attributes)
995 (setq value (get-char-attribute char 'total-strokes)))
996 (insert (format "(total-strokes . %S)%s"
999 (setq attributes (delq 'total-strokes attributes))
1001 (when (and (memq '->ideograph attributes)
1002 (setq value (get-char-attribute char '->ideograph)))
1003 (insert (format "(->ideograph\t%s)%s"
1004 (mapconcat (lambda (code)
1005 (cond ((symbolp code)
1008 (format "#x%04X" code))
1011 line-breaking code))))
1014 (setq attributes (delq '->ideograph attributes))
1016 ;; (when (and (memq '->decomposition attributes)
1017 ;; (setq value (get-char-attribute char '->decomposition)))
1018 ;; (insert (format "(->decomposition\t%s)%s"
1019 ;; (mapconcat (lambda (code)
1020 ;; (cond ((symbolp code)
1021 ;; (symbol-name code))
1022 ;; ((characterp code)
1024 ;; (format "%S" code)
1029 ;; (format "#x%04X" code))
1031 ;; (format "%s%S" line-breaking code))))
1034 ;; (setq attributes (delq '->decomposition attributes))
1036 (if (equal (get-char-attribute char '->titlecase)
1037 (get-char-attribute char '->uppercase))
1038 (setq attributes (delq '->titlecase attributes)))
1039 (when (and (memq '->mojikyo attributes)
1040 (setq value (get-char-attribute char '->mojikyo)))
1041 (insert (format "(->mojikyo\t\t. %06d)\t; %c%s"
1042 value (decode-char 'mojikyo value)
1044 (setq attributes (delq '->mojikyo attributes))
1046 (when (and (memq 'hanyu-dazidian-vol attributes)
1047 (setq value (get-char-attribute char 'hanyu-dazidian-vol)))
1048 (insert (format "(hanyu-dazidian-vol . %d)%s"
1049 value line-breaking))
1050 (setq attributes (delq 'hanyu-dazidian-vol attributes))
1052 (when (and (memq 'hanyu-dazidian-page attributes)
1053 (setq value (get-char-attribute char 'hanyu-dazidian-page)))
1054 (insert (format "(hanyu-dazidian-page . %d)%s"
1055 value line-breaking))
1056 (setq attributes (delq 'hanyu-dazidian-page attributes))
1058 (when (and (memq 'hanyu-dazidian-char attributes)
1059 (setq value (get-char-attribute char 'hanyu-dazidian-char)))
1060 (insert (format "(hanyu-dazidian-char . %d)%s"
1061 value line-breaking))
1062 (setq attributes (delq 'hanyu-dazidian-char attributes))
1065 (dolist (ignored '(composition
1066 ->denotational <-subsumptive ->ucs-unified
1067 ->ideographic-component-forms))
1068 (setq attributes (delq ignored attributes))))
1070 (setq name (car attributes))
1071 (unless (eq (setq value (get-char-attribute char name 'value-is-empty))
1073 (cond ((setq ret (find-charset name))
1074 (setq name (charset-name ret))
1075 (when (not (memq name dest-ccss))
1076 (setq dest-ccss (cons name dest-ccss))
1077 (char-db-insert-ccs-feature name value line-breaking))
1079 ((string-match "^=>ucs@" (symbol-name name))
1080 (insert (format "(%-18s . #x%04X)\t; %c%s"
1081 name value (decode-char '=ucs value)
1084 ((eq name 'jisx0208-1978/4X)
1085 (insert (format "(%-18s . #x%04X)%s"
1091 (not (eq name '->subsumptive))
1092 (not (eq name '->uppercase))
1093 (not (eq name '->lowercase))
1094 (not (eq name '->titlecase))
1095 (not (eq name '->canonical))
1096 (not (eq name '->Bopomofo))
1097 (not (eq name '->mistakable))
1098 (not (eq name '->ideographic-variants))
1099 (null (get-char-attribute
1100 char (intern (format "%s*sources" name))))
1101 (not (string-match "\\*sources$" (symbol-name name)))
1102 (null (get-char-attribute
1103 char (intern (format "%s*note" name))))
1104 (not (string-match "\\*note$" (symbol-name name)))
1105 (or (eq name '<-identical)
1106 (eq name '<-uppercase)
1107 (eq name '<-lowercase)
1108 (eq name '<-titlecase)
1109 (eq name '<-canonical)
1110 (eq name '<-ideographic-variants)
1111 ;; (eq name '<-synonyms)
1112 (string-match "^<-synonyms" (symbol-name name))
1113 (eq name '<-mistakable)
1114 (when (string-match "^->" (symbol-name name))
1116 ((string-match "^->fullwidth" (symbol-name name))
1117 (not (and (consp value)
1118 (characterp (car value))
1120 (car value) '=ucs 'defined-only)))
1125 ((or (eq name 'ideographic-structure)
1126 (eq name 'ideographic-combination)
1127 (eq name 'ideographic-)
1128 (eq name '=decomposition)
1129 (char-feature-base-name= '=decomposition name)
1130 (char-feature-base-name= '=>decomposition name)
1131 ;; (string-match "^=>*decomposition\\(@[^*]+\\)?$"
1132 ;; (symbol-name name))
1133 (string-match "^\\(->\\|<-\\)[^*]*$" (symbol-name name))
1134 (string-match "^\\(->\\|<-\\)[^*]*\\*sources$"
1137 (char-db-insert-relation-feature char name value
1140 ((memq name '(ideograph=
1141 original-ideograph-of
1142 ancient-ideograph-of
1145 ;; simplified-ideograph-of
1146 ideographic-variants
1147 ;; ideographic-different-form-of
1149 (insert (format "(%-18s%s " name line-breaking))
1150 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1152 (while (consp value)
1153 (setq cell (car value))
1154 (if (and (consp cell)
1159 (char-db-insert-alist cell readable)
1160 (setq separator lbs))
1163 (insert (prin1-to-string cell))
1164 (setq separator " "))
1165 (setq value (cdr value)))
1167 (insert line-breaking))
1169 (insert (format "(%-18s " name))
1170 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1172 (while (consp value)
1173 (setq cell (car value))
1174 (if (and (consp cell)
1176 (setq ret (condition-case nil
1184 (setq key (car (car rest)))
1185 (if (find-charset key)
1186 (setq cal (cons key cal))
1187 (setq al (cons key al)))
1188 (setq rest (cdr rest)))
1191 (insert-char-attributes ret
1195 (setq separator lbs))
1196 (setq ret (prin1-to-string cell))
1198 (if (< (+ (current-column)
1205 (setq separator " "))
1206 (setq value (cdr value)))
1208 (insert line-breaking))
1210 (insert (format "(%-18s" name))
1211 (setq ret (prin1-to-string value))
1212 (unless (< (+ (current-column)
1216 (insert line-breaking))
1217 (insert " . " ret ")" line-breaking)
1218 ;; (insert (format "(%-18s . %S)%s"
1223 (setq attributes (cdr attributes)))
1226 (defun insert-char-data (char &optional readable
1229 (narrow-to-region (point)(point))
1230 (insert "(define-char
1232 (insert-char-attributes char readable attributes)
1234 (goto-char (point-min))
1235 (while (re-search-forward "[ \t]+$" nil t)
1238 (goto-char (point-min))
1239 (while (re-search-forward "[ \t][ \t][ \t]*" nil t)
1240 (let ((column (current-column))
1241 (indent-tabs-mode t))
1242 (delete-region (match-beginning 0) (point))
1243 (indent-to column)))
1244 (goto-char (point-max))
1245 ;; (tabify (point-min)(point-max))
1248 (defun insert-char-data-with-variant (char &optional printable
1250 script excluded-script)
1251 (insert-char-data char printable)
1252 (let ((variants (char-variants char))
1255 (setq variants (sort variants #'<))
1256 (setq rest variants)
1257 (setq variants (cons char variants))
1259 (setq variant (car rest))
1260 (unless (get-char-attribute variant '<-subsumptive)
1261 (if (and (or (null script)
1262 (null (setq vs (get-char-attribute variant 'script)))
1264 (or (null excluded-script)
1265 (null (setq vs (get-char-attribute variant 'script)))
1266 (not (memq excluded-script vs))))
1267 (unless (and no-ucs-unified (get-char-attribute variant '=ucs))
1268 (insert-char-data variant printable)
1269 (if (setq ret (char-variants variant))
1271 (or (memq (car ret) variants)
1272 ;; (get-char-attribute (car ret) '<-subsumptive)
1273 (setq rest (nconc rest (list (car ret)))))
1274 (setq ret (cdr ret)))))))
1275 (setq rest (cdr rest)))))
1277 (defun insert-char-range-data (min max &optional script excluded-script)
1280 (while (<= code max)
1281 (setq char (decode-char '=ucs code))
1282 (if (encode-char char '=ucs 'defined-only)
1283 (insert-char-data-with-variant char nil 'no-ucs-unified
1284 script excluded-script))
1285 (setq code (1+ code)))))
1287 (defun write-char-range-data-to-file (min max file
1288 &optional script excluded-script)
1289 (let ((coding-system-for-write char-db-file-coding-system))
1291 (insert (format ";; -*- coding: %s -*-\n"
1292 char-db-file-coding-system))
1293 (insert-char-range-data min max script excluded-script)
1294 (write-region (point-min)(point-max) file))))
1296 (defvar what-character-original-window-configuration)
1299 (defun what-char-definition (char)
1300 (interactive (list (char-after)))
1301 (let ((buf (get-buffer-create "*Character Description*"))
1302 (the-buf (current-buffer))
1303 (win-conf (current-window-configuration)))
1305 (make-local-variable 'what-character-original-window-configuration)
1306 (setq what-character-original-window-configuration win-conf)
1307 (setq buffer-read-only nil)
1311 (insert-char-data-with-variant char 'printable)
1312 (unless (char-attribute-alist char)
1313 (insert (format ";; = %c\n"
1314 (let* ((rest (split-char char))
1318 (setq code (logior (lsh code 8)
1320 (decode-char ccs code)))))
1321 ;; (char-db-update-comment)
1322 (set-buffer-modified-p nil)
1323 (view-mode the-buf (lambda (buf)
1324 (set-window-configuration
1325 what-character-original-window-configuration)
1327 (goto-char (point-min)))
1329 (set-window-configuration
1330 what-character-original-window-configuration)
1331 (signal (car err) (cdr err)))))))
1337 (provide 'char-db-util)
1339 ;;; char-db-util.el ends here