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
226 ;;; @ char-db formatters
229 (defun char-db-make-char-spec (char)
231 (cond ((characterp char)
232 (cond ((and (setq ret (encode-char char '=ucs 'defined-only))
233 (not (and (<= #xE000 ret)(<= ret #xF8FF))))
234 (setq char-spec (list (cons '=ucs ret)))
235 (cond ((setq ret (get-char-attribute char 'name))
236 (setq char-spec (cons (cons 'name ret) char-spec))
238 ((setq ret (get-char-attribute char 'name*))
239 (setq char-spec (cons (cons 'name* ret) char-spec))
244 (let ((rest char-db-coded-charset-priority-list)
247 (setq ccs (charset-name
248 (find-charset (car rest))))
250 (encode-char char ccs
252 (throw 'tag (cons ccs ret)))
253 (setq rest (cdr rest))))))
254 (setq char-spec (list ret))
255 (dolist (ccs (delq (car ret) (charset-list)))
256 (if (and (or (charset-iso-final-char ccs)
263 (string-match "=ucs@" (symbol-name ccs)))
264 (setq ccs (charset-name ccs))
265 (null (assq ccs char-spec))
266 (setq ret (encode-char char ccs 'defined-only)))
267 (setq char-spec (cons (cons ccs ret) char-spec))))
269 (setq char-spec (split-char char)))
270 (cond ((setq ret (get-char-attribute char 'name))
271 (setq char-spec (cons (cons 'name ret) char-spec))
273 ((setq ret (get-char-attribute char 'name*))
274 (setq char-spec (cons (cons 'name* ret) char-spec))
277 ((setq ret (get-char-attribute
278 char 'ideographic-combination))
280 (cons (cons 'ideographic-combination ret)
287 (defun char-db-insert-char-spec (char &optional readable column
290 (setq column (current-column)))
291 (let (char-spec temp-char)
292 (setq char-spec (char-db-make-char-spec char))
293 (unless (or (characterp char) ; char
295 (setq char (find-char char-spec))
297 ;; define temporary character
298 ;; Current implementation is dirty.
299 (setq temp-char (define-char (cons '(ideograph-daikanwa . 0)
301 (remove-char-attribute temp-char 'ideograph-daikanwa)
302 (setq char temp-char))
303 (insert-char-attributes char
305 (union (mapcar #'car char-spec)
309 ;; undefine temporary character
310 ;; Current implementation is dirty.
311 (setq char-spec (char-attribute-alist temp-char))
313 (remove-char-attribute temp-char (car (car char-spec)))
314 (setq char-spec (cdr char-spec))))))
316 (defun char-db-insert-alist (alist &optional readable column)
318 (setq column (current-column)))
320 (concat "\n" (make-string (1+ column) ?\ )))
324 lbs cell rest separator)
327 (setq name (car (car alist))
328 value (cdr (car alist)))
329 (cond ((eq name 'char)
331 (if (setq ret (condition-case nil
339 (setq key (car (car value)))
340 ;; (if (find-charset key)
341 ;; (setq cal (cons key cal))
342 (setq al (cons key al))
344 (setq value (cdr value)))
345 (insert-char-attributes ret
349 (insert (prin1-to-string value)))
351 (insert line-breaking))
353 (insert (format "(%-18s " name))
354 (setq lbs (concat "\n" (make-string (current-column) ?\ )))
356 (setq cell (car value))
357 (if (and (consp cell)
359 (setq ret (condition-case nil
369 (setq key (car (car rest)))
370 ;; (if (find-charset key)
371 ;; (setq cal (cons key cal))
372 (setq al (cons key al))
374 (setq rest (cdr rest)))
377 (insert-char-attributes ret
381 (setq separator lbs))
384 (insert (prin1-to-string cell))
385 (setq separator " "))
386 (setq value (cdr value)))
388 (insert line-breaking))
390 (insert (format "(%-18s . %S)%s"
393 (setq alist (cdr alist))))
396 (defun char-db-insert-char-reference (plist &optional readable column)
398 (setq column (current-column)))
400 (concat "\n" (make-string (1+ column) ?\ )))
405 (setq name (pop plist))
406 (setq value (pop plist))
407 (cond ((eq name :char)
410 (cond ((numberp value)
411 (setq value (decode-char '=ucs value)))
413 ;; (setq value (or (find-char value)
416 (char-db-insert-char-spec value readable)
417 (insert line-breaking)
420 (insert (format "%s%s\t%d ; %c%s"
423 (ideographic-radical value)
427 (insert (format "%s%s\t%S" separator name value))
428 (setq separator line-breaking)))
432 (defun char-db-decode-isolated-char (ccs code-point)
435 (cond ((eq ccs 'arabic-iso8859-6)
436 (decode-char ccs code-point))
437 ((and (memq ccs '(=gt-pj-1
448 (setq ret (decode-char ccs code-point))
449 (setq ret (encode-char ret '=gt 'defined-only)))
450 (decode-builtin-char '=gt ret))
452 (decode-builtin-char ccs code-point))))
453 (cond ((and (<= 0 (char-int ret))
454 (<= (char-int ret) #x1F))
455 (decode-char '=ucs (+ #x2400 (char-int ret))))
456 ((= (char-int ret) #x7F)
460 (defvar char-db-convert-obsolete-format t)
462 (defun char-db-insert-ccs-feature (name value line-breaking)
465 (cond ((memq name '(=shinjigen
467 =shinjigen@rev =shinjigen/+p@rev
469 "(%-18s . %04d)\t; %c")
470 ((eq name '=shinjigen@1ed/24pr)
471 "(%-18s . %04d)\t; %c")
472 ((or (memq name '(=daikanwa =>>daikanwa =>daikanwa
473 =daikanwa@rev1 =daikanwa@rev2
474 =daikanwa/+p =daikanwa/+2p
475 =gt =>>>gt =>>gt =>gt
478 =cbeta =zinbun-oracle =>zinbun-oracle))
479 (string-match "^=adobe-" (symbol-name name)))
480 "(%-18s . %05d)\t; %c")
481 ((memq name '(=hanyo-denshi/ks =>>hanyo-denshi/ks mojikyo))
482 "(%-18s . %06d)\t; %c")
483 ((>= (charset-dimension name) 2)
484 "(%-18s . #x%04X)\t; %c")
486 "(%-18s . #x%02X)\t; %c"))
488 (if (= (charset-iso-graphic-plane name) 1)
490 (cond ((= (charset-dimension name) 1)
492 ((= (charset-dimension name) 2)
494 ((= (charset-dimension name) 3)
498 (char-db-decode-isolated-char name value)))
499 (if (and (= (charset-chars name) 94)
500 (= (charset-dimension name) 2))
501 (insert (format " [%02d-%02d]"
502 (- (lsh value -8) 32)
503 (- (logand value 255) 32))))
504 (insert line-breaking))
506 (defun char-db-insert-relation-feature (char name value line-breaking
508 (insert (format "(%-18s%s " name line-breaking))
509 (let ((lbs (concat "\n" (make-string (current-column) ?\ )))
510 separator cell sources required-features
513 (setq cell (car value))
515 (setq cell (decode-char '=ucs cell)))
517 ((eq name '->subsumptive)
518 (when (or (not (some (lambda (atr)
519 (get-char-attribute cell atr))
520 char-db-ignored-attributes))
522 (encode-char cell ccs 'defined-only))
526 (let ((char-db-ignored-attributes
528 char-db-ignored-attributes)))
529 (insert-char-attributes cell readable nil nil 'for-sub-node))
530 (setq separator lbs))
535 char (intern (format "%s*sources" name))))
536 (setq required-features nil)
537 (dolist (source sources)
541 shinjigen shinjigen@1ed shinjigen@rev))
542 (setq required-features
543 (union required-features
554 (setq required-features
555 (union required-features
560 ((find-charset (setq ret (intern (format "=%s" source))))
561 (setq required-features
562 (cons ret required-features)))
563 (t (setq required-features
564 (cons source required-features)))))
565 (cond ((string-match "@JP" (symbol-name name))
566 (setq required-features
567 (union required-features
575 ((string-match "@CN" (symbol-name name))
576 (setq required-features
577 (union required-features
584 (insert (format "%S" cell))
585 (char-db-insert-char-spec cell readable
588 (setq separator lbs))
592 (if (consp (car cell))
593 (char-db-insert-char-spec cell readable)
594 (char-db-insert-char-reference cell readable))
595 (setq separator lbs))
599 (insert (prin1-to-string cell))
600 (setq separator " ")))
601 (setq value (cdr value)))
603 (insert line-breaking)))
605 (defun insert-char-attributes (char &optional readable attributes column
608 (setq column (current-column)))
609 (let (name value ; has-long-ccs-name
613 (concat "\n" (make-string (1+ column) ?\ )))
614 lbs cell separator ret
616 dest-ccss ; sources required-features
621 (if (consp attributes)
623 (dolist (name attributes)
624 (unless (memq name char-db-ignored-attributes)
625 (if (find-charset name)
629 (dolist (name (char-attribute-list))
630 (unless (memq name char-db-ignored-attributes)
631 (if (find-charset name)
635 #'char-attribute-name<)))
637 (when (memq '<-subsumptive attributes)
638 (when (or readable (not for-sub-node))
639 (when (setq value (get-char-attribute char '<-subsumptive))
640 (char-db-insert-relation-feature char '<-subsumptive value
643 (setq attributes (delq '<-subsumptive attributes)))
644 (when (and (memq '<-denotational attributes)
645 (setq value (get-char-attribute char '<-denotational)))
646 (char-db-insert-relation-feature char '<-denotational value
649 (setq attributes (delq '<-denotational attributes)))
650 (when (and (memq 'name attributes)
651 (setq value (get-char-attribute char 'name)))
653 (if (> (+ (current-column) (length value)) 48)
656 value line-breaking))
657 (setq attributes (delq 'name attributes))
659 (when (and (memq 'name* attributes)
660 (setq value (get-char-attribute char 'name*)))
662 (if (> (+ (current-column) (length value)) 48)
665 value line-breaking))
666 (setq attributes (delq 'name* attributes))
668 (when (and (memq 'script attributes)
669 (setq value (get-char-attribute char 'script)))
670 (insert (format "(script\t\t%s)%s"
671 (mapconcat (function prin1-to-string)
674 (setq attributes (delq 'script attributes))
676 (dolist (name '(=>ucs =>ucs*))
677 (when (and (memq name attributes)
678 (setq value (get-char-attribute char name)))
679 (insert (format "(%-18s . #x%04X)\t; %c%s"
680 name value (decode-char '=ucs value)
682 (setq attributes (delq name attributes))))
683 (dolist (name '(=>ucs@gb =>ucs@big5))
684 (when (and (memq name attributes)
685 (setq value (get-char-attribute char name)))
686 (insert (format "(%-18s . #x%04X)\t; %c%s"
691 (symbol-name name) 2)))
694 (setq attributes (delq name attributes))
696 ;; (dolist (name '(=>daikanwa))
697 ;; (when (and (memq name attributes)
698 ;; (setq value (get-char-attribute char name)))
700 ;; (if (integerp value)
701 ;; (format "(%-18s . %05d)\t; %c%s"
702 ;; name value (decode-char '=daikanwa value)
704 ;; (format "(%-18s %s)\t; %c%s"
706 ;; (mapconcat (function prin1-to-string)
708 ;; (char-representative-of-daikanwa char)
710 ;; (setq attributes (delq name attributes))))
711 (when (and (memq 'general-category attributes)
712 (setq value (get-char-attribute char 'general-category)))
714 "(general-category\t%s) ; %s%s"
715 (mapconcat (lambda (cell)
718 (cond ((rassoc value unidata-normative-category-alist)
719 "Normative Category")
720 ((rassoc value unidata-informative-category-alist)
721 "Informative Category")
725 (setq attributes (delq 'general-category attributes))
727 (when (and (memq 'bidi-category attributes)
728 (setq value (get-char-attribute char 'bidi-category)))
729 (insert (format "(bidi-category\t. %S)%s"
732 (setq attributes (delq 'bidi-category attributes))
734 (unless (or (not (memq 'mirrored attributes))
735 (eq (setq value (get-char-attribute char 'mirrored 'empty))
737 (insert (format "(mirrored\t\t. %S)%s"
740 (setq attributes (delq 'mirrored attributes))
743 ((and (memq 'decimal-digit-value attributes)
744 (setq value (get-char-attribute char 'decimal-digit-value)))
745 (insert (format "(decimal-digit-value . %S)%s"
748 (setq attributes (delq 'decimal-digit-value attributes))
749 (when (and (memq 'digit-value attributes)
750 (setq value (get-char-attribute char 'digit-value)))
751 (insert (format "(digit-value\t . %S)%s"
754 (setq attributes (delq 'digit-value attributes))
756 (when (and (memq 'numeric-value attributes)
757 (setq value (get-char-attribute char 'numeric-value)))
758 (insert (format "(numeric-value\t . %S)%s"
761 (setq attributes (delq 'numeric-value attributes))
765 (when (and (memq 'digit-value attributes)
766 (setq value (get-char-attribute char 'digit-value)))
767 (insert (format "(digit-value\t. %S)%s"
770 (setq attributes (delq 'digit-value attributes))
772 (when (and (memq 'numeric-value attributes)
773 (setq value (get-char-attribute char 'numeric-value)))
774 (insert (format "(numeric-value\t. %S)%s"
777 (setq attributes (delq 'numeric-value attributes))
779 (when (and (memq 'iso-10646-comment attributes)
780 (setq value (get-char-attribute char 'iso-10646-comment)))
781 (insert (format "(iso-10646-comment\t. %S)%s"
784 (setq attributes (delq 'iso-10646-comment attributes))
786 (when (and (memq 'morohashi-daikanwa attributes)
787 (setq value (get-char-attribute char 'morohashi-daikanwa)))
788 (insert (format "(morohashi-daikanwa\t%s)%s"
789 (mapconcat (function prin1-to-string) value " ")
791 (setq attributes (delq 'morohashi-daikanwa attributes))
795 (when (and (memq 'ideographic-radical attributes)
796 (setq value (get-char-attribute char 'ideographic-radical)))
798 (insert (format "(ideographic-radical . %S)\t; %c%s"
800 (ideographic-radical radical)
802 (setq attributes (delq 'ideographic-radical attributes))
804 (when (and (memq 'shuowen-radical attributes)
805 (setq value (get-char-attribute char 'shuowen-radical)))
806 (insert (format "(shuowen-radical\t. %S)\t; %c%s"
808 (shuowen-radical value)
810 (setq attributes (delq 'shuowen-radical attributes))
815 char-db-feature-domains
817 (dolist (feature (char-attribute-list))
818 (setq feature (symbol-name feature))
820 "\\(radical\\|strokes\\)@\\([^@*]+\\)\\(\\*\\|$\\)"
822 (setq domain (intern (match-string 2 feature)))
823 (unless (memq domain dest)
824 (setq dest (cons domain dest)))))
825 (sort dest #'string<))))
826 (setq key (intern (format "%s@%s" 'ideographic-radical domain)))
827 (when (and (memq key attributes)
828 (setq value (get-char-attribute char key)))
830 (insert (format "(%s . %S)\t; %c%s"
833 (ideographic-radical radical)
835 (setq attributes (delq key attributes))
837 (setq key (intern (format "%s@%s" 'ideographic-strokes domain)))
838 (when (and (memq key attributes)
839 (setq value (get-char-attribute char key)))
841 (insert (format "(%s . %S)%s"
845 (setq attributes (delq key attributes))
847 (setq key (intern (format "%s@%s" 'total-strokes domain)))
848 (when (and (memq key attributes)
849 (setq value (get-char-attribute char key)))
850 (insert (format "(%s . %S)%s"
854 (setq attributes (delq key attributes))
856 (dolist (feature '(ideographic-radical
859 (setq key (intern (format "%s@%s*sources" feature domain)))
860 (when (and (memq key attributes)
861 (setq value (get-char-attribute char key)))
862 (insert (format "(%s%s" key line-breaking))
864 (insert (format " %s" cell)))
866 (insert line-breaking)
867 (setq attributes (delq key attributes))
870 (when (and (memq 'ideographic-strokes attributes)
871 (setq value (get-char-attribute char 'ideographic-strokes)))
873 (insert (format "(ideographic-strokes . %S)%s"
876 (setq attributes (delq 'ideographic-strokes attributes))
878 (when (and (memq 'kangxi-radical attributes)
879 (setq value (get-char-attribute char 'kangxi-radical)))
880 (unless (eq value radical)
881 (insert (format "(kangxi-radical\t . %S)\t; %c%s"
883 (ideographic-radical value)
886 (setq radical value)))
887 (setq attributes (delq 'kangxi-radical attributes))
889 (when (and (memq 'kangxi-strokes attributes)
890 (setq value (get-char-attribute char 'kangxi-strokes)))
891 (unless (eq value strokes)
892 (insert (format "(kangxi-strokes\t . %S)%s"
896 (setq strokes value)))
897 (setq attributes (delq 'kangxi-strokes attributes))
899 (when (and (memq 'japanese-radical attributes)
900 (setq value (get-char-attribute char 'japanese-radical)))
901 (unless (eq value radical)
902 (insert (format "(japanese-radical\t . %S)\t; %c%s"
904 (ideographic-radical value)
907 (setq radical value)))
908 (setq attributes (delq 'japanese-radical attributes))
910 (when (and (memq 'japanese-strokes attributes)
911 (setq value (get-char-attribute char 'japanese-strokes)))
912 (unless (eq value strokes)
913 (insert (format "(japanese-strokes\t . %S)%s"
917 (setq strokes value)))
918 (setq attributes (delq 'japanese-strokes attributes))
920 (when (and (memq 'cns-radical attributes)
921 (setq value (get-char-attribute char 'cns-radical)))
922 (insert (format "(cns-radical\t . %S)\t; %c%s"
924 (ideographic-radical value)
926 (setq attributes (delq 'cns-radical attributes))
928 (when (and (memq 'cns-strokes attributes)
929 (setq value (get-char-attribute char 'cns-strokes)))
930 (unless (eq value strokes)
931 (insert (format "(cns-strokes\t . %S)%s"
935 (setq strokes value)))
936 (setq attributes (delq 'cns-strokes attributes))
938 (when (and (memq 'shinjigen-1-radical attributes)
939 (setq value (get-char-attribute char 'shinjigen-1-radical)))
940 (unless (eq value radical)
941 (insert (format "(shinjigen-1-radical . %S)\t; %c%s"
943 (ideographic-radical value)
946 (setq radical value)))
947 (setq attributes (delq 'shinjigen-1-radical attributes))
949 (when (and (memq 'ideographic- attributes)
950 (setq value (get-char-attribute char 'ideographic-)))
951 (insert "(ideographic- ")
952 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
955 (setq cell (car value))
957 (setq cell (decode-char '=ucs cell)))
958 (cond ((characterp cell)
962 (insert (format "%S" cell))
963 (char-db-insert-char-spec cell readable))
964 (setq separator lbs))
968 (if (consp (car cell))
969 (char-db-insert-char-spec cell readable)
970 (char-db-insert-char-reference cell readable))
971 (setq separator lbs))
975 (insert (prin1-to-string cell))
976 (setq separator " ")))
977 (setq value (cdr value)))
979 (insert line-breaking)
980 (setq attributes (delq 'ideographic- attributes)))
981 (when (and (memq 'total-strokes attributes)
982 (setq value (get-char-attribute char 'total-strokes)))
983 (insert (format "(total-strokes . %S)%s"
986 (setq attributes (delq 'total-strokes attributes))
988 (when (and (memq '->ideograph attributes)
989 (setq value (get-char-attribute char '->ideograph)))
990 (insert (format "(->ideograph\t%s)%s"
991 (mapconcat (lambda (code)
992 (cond ((symbolp code)
995 (format "#x%04X" code))
998 line-breaking code))))
1001 (setq attributes (delq '->ideograph attributes))
1003 ;; (when (and (memq '->decomposition attributes)
1004 ;; (setq value (get-char-attribute char '->decomposition)))
1005 ;; (insert (format "(->decomposition\t%s)%s"
1006 ;; (mapconcat (lambda (code)
1007 ;; (cond ((symbolp code)
1008 ;; (symbol-name code))
1009 ;; ((characterp code)
1011 ;; (format "%S" code)
1016 ;; (format "#x%04X" code))
1018 ;; (format "%s%S" line-breaking code))))
1021 ;; (setq attributes (delq '->decomposition attributes))
1023 (if (equal (get-char-attribute char '->titlecase)
1024 (get-char-attribute char '->uppercase))
1025 (setq attributes (delq '->titlecase attributes)))
1026 (when (and (memq '->mojikyo attributes)
1027 (setq value (get-char-attribute char '->mojikyo)))
1028 (insert (format "(->mojikyo\t\t. %06d)\t; %c%s"
1029 value (decode-char 'mojikyo value)
1031 (setq attributes (delq '->mojikyo attributes))
1033 (when (and (memq 'hanyu-dazidian-vol attributes)
1034 (setq value (get-char-attribute char 'hanyu-dazidian-vol)))
1035 (insert (format "(hanyu-dazidian-vol . %d)%s"
1036 value line-breaking))
1037 (setq attributes (delq 'hanyu-dazidian-vol attributes))
1039 (when (and (memq 'hanyu-dazidian-page attributes)
1040 (setq value (get-char-attribute char 'hanyu-dazidian-page)))
1041 (insert (format "(hanyu-dazidian-page . %d)%s"
1042 value line-breaking))
1043 (setq attributes (delq 'hanyu-dazidian-page attributes))
1045 (when (and (memq 'hanyu-dazidian-char attributes)
1046 (setq value (get-char-attribute char 'hanyu-dazidian-char)))
1047 (insert (format "(hanyu-dazidian-char . %d)%s"
1048 value line-breaking))
1049 (setq attributes (delq 'hanyu-dazidian-char attributes))
1052 (dolist (ignored '(composition
1053 ->denotational <-subsumptive ->ucs-unified
1054 ->ideographic-component-forms))
1055 (setq attributes (delq ignored attributes))))
1057 (setq name (car attributes))
1058 (if (setq value (get-char-attribute char name))
1059 (cond ((setq ret (find-charset name))
1060 (setq name (charset-name ret))
1061 (if (and (not (memq name dest-ccss))
1063 (setq value (get-char-attribute char name))
1064 (setq dest-ccss (cons name dest-ccss))))
1065 (char-db-insert-ccs-feature name value line-breaking))
1067 ((string-match "^=>ucs@" (symbol-name name))
1068 (insert (format "(%-18s . #x%04X)\t; %c%s"
1069 name value (decode-char '=ucs value)
1072 ((eq name 'jisx0208-1978/4X)
1073 (insert (format "(%-18s . #x%04X)%s"
1079 (not (eq name '->subsumptive))
1080 (not (eq name '->uppercase))
1081 (not (eq name '->lowercase))
1082 (not (eq name '->titlecase))
1083 (not (eq name '->canonical))
1084 (not (eq name '->Bopomofo))
1085 (not (eq name '->mistakable))
1086 (not (eq name '->ideographic-variants))
1087 (null (get-char-attribute
1088 char (intern (format "%s*sources" name))))
1089 (not (string-match "\\*sources$" (symbol-name name)))
1090 (null (get-char-attribute
1091 char (intern (format "%s*note" name))))
1092 (not (string-match "\\*note$" (symbol-name name)))
1093 (or (eq name '<-identical)
1094 (eq name '<-uppercase)
1095 (eq name '<-lowercase)
1096 (eq name '<-titlecase)
1097 (eq name '<-canonical)
1098 (eq name '<-ideographic-variants)
1099 ;; (eq name '<-synonyms)
1100 (string-match "^<-synonyms" (symbol-name name))
1101 (eq name '<-mistakable)
1102 (when (string-match "^->" (symbol-name name))
1104 ((string-match "^->fullwidth" (symbol-name name))
1105 (not (and (consp value)
1106 (characterp (car value))
1108 (car value) '=ucs 'defined-only)))
1113 ((or (eq name 'ideographic-structure)
1114 (eq name 'ideographic-combination)
1115 (eq name 'ideographic-)
1116 (eq name '=decomposition)
1117 (char-feature-base-name= '=decomposition name)
1118 (char-feature-base-name= '=>decomposition name)
1119 ;; (string-match "^=>*decomposition\\(@[^*]+\\)?$"
1120 ;; (symbol-name name))
1121 (string-match "^\\(->\\|<-\\)[^*]*$" (symbol-name name))
1122 (string-match "^\\(->\\|<-\\)[^*]*\\*sources$"
1125 (char-db-insert-relation-feature char name value
1128 ((memq name '(ideograph=
1129 original-ideograph-of
1130 ancient-ideograph-of
1133 ;; simplified-ideograph-of
1134 ideographic-variants
1135 ;; ideographic-different-form-of
1137 (insert (format "(%-18s%s " name line-breaking))
1138 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1140 (while (consp value)
1141 (setq cell (car value))
1142 (if (and (consp cell)
1147 (char-db-insert-alist cell readable)
1148 (setq separator lbs))
1151 (insert (prin1-to-string cell))
1152 (setq separator " "))
1153 (setq value (cdr value)))
1155 (insert line-breaking))
1157 (insert (format "(%-18s " name))
1158 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1160 (while (consp value)
1161 (setq cell (car value))
1162 (if (and (consp cell)
1164 (setq ret (condition-case nil
1172 (setq key (car (car rest)))
1173 (if (find-charset key)
1174 (setq cal (cons key cal))
1175 (setq al (cons key al)))
1176 (setq rest (cdr rest)))
1179 (insert-char-attributes ret
1183 (setq separator lbs))
1184 (setq ret (prin1-to-string cell))
1186 (if (< (+ (current-column)
1193 (setq separator " "))
1194 (setq value (cdr value)))
1196 (insert line-breaking))
1198 (insert (format "(%-18s" name))
1199 (setq ret (prin1-to-string value))
1200 (unless (< (+ (current-column)
1204 (insert line-breaking))
1205 (insert " . " ret ")" line-breaking)
1206 ;; (insert (format "(%-18s . %S)%s"
1211 (setq attributes (cdr attributes)))
1214 (defun insert-char-data (char &optional readable
1217 (narrow-to-region (point)(point))
1218 (insert "(define-char
1220 (insert-char-attributes char readable attributes)
1222 (goto-char (point-min))
1223 (while (re-search-forward "[ \t]+$" nil t)
1226 (goto-char (point-min))
1227 (while (re-search-forward "[ \t][ \t][ \t]*" nil t)
1228 (let ((column (current-column))
1229 (indent-tabs-mode t))
1230 (delete-region (match-beginning 0) (point))
1231 (indent-to column)))
1232 (goto-char (point-max))
1233 ;; (tabify (point-min)(point-max))
1236 (defun insert-char-data-with-variant (char &optional printable
1238 script excluded-script)
1239 (insert-char-data char printable)
1240 (let ((variants (char-variants char))
1243 (setq variants (sort variants #'<))
1244 (setq rest variants)
1245 (setq variants (cons char variants))
1247 (setq variant (car rest))
1248 (unless (get-char-attribute variant '<-subsumptive)
1249 (if (and (or (null script)
1250 (null (setq vs (get-char-attribute variant 'script)))
1252 (or (null excluded-script)
1253 (null (setq vs (get-char-attribute variant 'script)))
1254 (not (memq excluded-script vs))))
1255 (unless (and no-ucs-unified (get-char-attribute variant '=ucs))
1256 (insert-char-data variant printable)
1257 (if (setq ret (char-variants variant))
1259 (or (memq (car ret) variants)
1260 ;; (get-char-attribute (car ret) '<-subsumptive)
1261 (setq rest (nconc rest (list (car ret)))))
1262 (setq ret (cdr ret)))))))
1263 (setq rest (cdr rest)))))
1265 (defun insert-char-range-data (min max &optional script excluded-script)
1268 (while (<= code max)
1269 (setq char (decode-char '=ucs code))
1270 (if (encode-char char '=ucs 'defined-only)
1271 (insert-char-data-with-variant char nil 'no-ucs-unified
1272 script excluded-script))
1273 (setq code (1+ code)))))
1275 (defun write-char-range-data-to-file (min max file
1276 &optional script excluded-script)
1277 (let ((coding-system-for-write char-db-file-coding-system))
1279 (insert (format ";; -*- coding: %s -*-\n"
1280 char-db-file-coding-system))
1281 (insert-char-range-data min max script excluded-script)
1282 (write-region (point-min)(point-max) file))))
1284 (defvar what-character-original-window-configuration)
1287 (defun what-char-definition (char)
1288 (interactive (list (char-after)))
1289 (let ((buf (get-buffer-create "*Character Description*"))
1290 (the-buf (current-buffer))
1291 (win-conf (current-window-configuration)))
1293 (make-local-variable 'what-character-original-window-configuration)
1294 (setq what-character-original-window-configuration win-conf)
1295 (setq buffer-read-only nil)
1299 (insert-char-data-with-variant char 'printable)
1300 (unless (char-attribute-alist char)
1301 (insert (format ";; = %c\n"
1302 (let* ((rest (split-char char))
1306 (setq code (logior (lsh code 8)
1308 (decode-char ccs code)))))
1309 ;; (char-db-update-comment)
1310 (set-buffer-modified-p nil)
1311 (view-mode the-buf (lambda (buf)
1312 (set-window-configuration
1313 what-character-original-window-configuration)
1315 (goto-char (point-min)))
1317 (set-window-configuration
1318 what-character-original-window-configuration)
1319 (signal (car err) (cdr err)))))))
1325 (provide 'char-db-util)
1327 ;;; char-db-util.el ends here