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, 2012 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
244 ;;; @ char-db formatters
247 (defun char-db-make-char-spec (char)
249 (cond ((characterp char)
250 (cond ((and (setq ret (encode-char char '=ucs 'defined-only))
251 (not (and (<= #xE000 ret)(<= ret #xF8FF))))
252 (setq char-spec (list (cons '=ucs ret)))
253 (cond ((setq ret (get-char-attribute char 'name))
254 (setq char-spec (cons (cons 'name ret) char-spec))
256 ((setq ret (get-char-attribute char 'name*))
257 (setq char-spec (cons (cons 'name* ret) char-spec))
262 (let ((rest char-db-coded-charset-priority-list)
265 (setq ccs (charset-name
266 (find-charset (car rest))))
268 (encode-char char ccs
270 (throw 'tag (cons ccs ret)))
271 (setq rest (cdr rest))))))
272 (setq char-spec (list ret))
273 (dolist (ccs (delq (car ret) (charset-list)))
274 (if (and (or (charset-iso-final-char ccs)
281 (string-match "=ucs@" (symbol-name ccs)))
282 (setq ccs (charset-name ccs))
283 (null (assq ccs char-spec))
284 (setq ret (encode-char char ccs 'defined-only)))
285 (setq char-spec (cons (cons ccs ret) char-spec))))
287 (setq char-spec (split-char char)))
288 (cond ((setq ret (get-char-attribute char 'name))
289 (setq char-spec (cons (cons 'name ret) char-spec))
291 ((setq ret (get-char-attribute char 'name*))
292 (setq char-spec (cons (cons 'name* ret) char-spec))
295 ((setq ret (get-char-attribute
296 char 'ideographic-combination))
298 (cons (cons 'ideographic-combination ret)
305 (defun char-db-insert-char-spec (char &optional readable column
308 (setq column (current-column)))
309 (let (char-spec temp-char)
310 (setq char-spec (char-db-make-char-spec char))
311 (unless (or (characterp char) ; char
313 (setq char (find-char char-spec))
315 ;; define temporary character
316 ;; Current implementation is dirty.
317 (setq temp-char (define-char (cons '(ideograph-daikanwa . 0)
319 (remove-char-attribute temp-char 'ideograph-daikanwa)
320 (setq char temp-char))
321 (insert-char-attributes char
323 (union (mapcar #'car char-spec)
327 ;; undefine temporary character
328 ;; Current implementation is dirty.
329 (setq char-spec (char-attribute-alist temp-char))
331 (remove-char-attribute temp-char (car (car char-spec)))
332 (setq char-spec (cdr char-spec))))))
334 (defun char-db-insert-alist (alist &optional readable column)
336 (setq column (current-column)))
338 (concat "\n" (make-string (1+ column) ?\ )))
342 lbs cell rest separator)
345 (setq name (car (car alist))
346 value (cdr (car alist)))
347 (cond ((eq name 'char)
349 (if (setq ret (condition-case nil
357 (setq key (car (car value)))
358 ;; (if (find-charset key)
359 ;; (setq cal (cons key cal))
360 (setq al (cons key al))
362 (setq value (cdr value)))
363 (insert-char-attributes ret
367 (insert (prin1-to-string value)))
369 (insert line-breaking))
371 (insert (format "(%-18s " name))
372 (setq lbs (concat "\n" (make-string (current-column) ?\ )))
374 (setq cell (car value))
375 (if (and (consp cell)
377 (setq ret (condition-case nil
387 (setq key (car (car rest)))
388 ;; (if (find-charset key)
389 ;; (setq cal (cons key cal))
390 (setq al (cons key al))
392 (setq rest (cdr rest)))
395 (insert-char-attributes ret
399 (setq separator lbs))
402 (insert (prin1-to-string cell))
403 (setq separator " "))
404 (setq value (cdr value)))
406 (insert line-breaking))
408 (insert (format "(%-18s . %S)%s"
411 (setq alist (cdr alist))))
414 (defun char-db-insert-char-reference (plist &optional readable column)
416 (setq column (current-column)))
418 (concat "\n" (make-string (1+ column) ?\ )))
423 (setq name (pop plist))
424 (setq value (pop plist))
425 (cond ((eq name :char)
428 (cond ((numberp value)
429 (setq value (decode-char '=ucs value)))
431 ;; (setq value (or (find-char value)
434 (char-db-insert-char-spec value readable)
435 (insert line-breaking)
438 (insert (format "%s%s\t%d ; %c%s"
441 (ideographic-radical value)
445 (insert (format "%s%s\t%S" separator name value))
446 (setq separator line-breaking)))
450 (defun char-db-decode-isolated-char (ccs code-point)
453 (cond ((eq ccs 'arabic-iso8859-6)
454 (decode-char ccs code-point))
455 ((and (memq ccs '(=gt-pj-1
466 (setq ret (decode-char ccs code-point))
467 (setq ret (encode-char ret '=gt 'defined-only)))
468 (decode-builtin-char '=gt ret))
470 (decode-builtin-char ccs code-point))))
471 (cond ((and (<= 0 (char-int ret))
472 (<= (char-int ret) #x1F))
473 (decode-char '=ucs (+ #x2400 (char-int ret))))
474 ((= (char-int ret) #x7F)
478 (defvar char-db-convert-obsolete-format t)
480 (defun char-db-insert-ccs-feature (name value line-breaking)
486 ((memq name '(=shinjigen
488 =shinjigen@rev =shinjigen/+p@rev
489 =daikanwa/ho =>>daikanwa/ho =>daikanwa/ho))
490 "(%-18s . %04d)\t; %c")
491 ((eq name '=shinjigen@1ed/24pr)
492 "(%-18s . %04d)\t; %c")
493 ((or (memq name '(=daikanwa =>>daikanwa =>daikanwa
494 =daikanwa@rev1 =daikanwa@rev2
495 =daikanwa/+p =>>daikanwa/+p
497 =gt =>>>gt =>>gt =+>gt =>gt
499 =adobe-japan1-0 =>>>adobe-japan1-0 =>>adobe-japan1-0
500 =adobe-japan1-1 =>>>adobe-japan1-1 =>>adobe-japan1-1
501 =adobe-japan1-2 =>>>adobe-japan1-2 =>>adobe-japan1-2
502 =adobe-japan1-3 =>>>adobe-japan1-3 =>>adobe-japan1-3
503 =adobe-japan1-4 =>>>adobe-japan1-4 =>>adobe-japan1-4
504 =adobe-japan1-5 =>>>adobe-japan1-5 =>>adobe-japan1-5
505 =adobe-japan1-6 =>>>adobe-japan1-6 =>>adobe-japan1-6
508 =zinbun-oracle =>zinbun-oracle))
509 ;; (string-match "^=adobe-" (symbol-name name))
511 "(%-18s . %05d)\t; %c")
512 ((memq name '(=hanyo-denshi/ks =>>hanyo-denshi/ks mojikyo))
513 "(%-18s . %06d)\t; %c")
514 ((>= (charset-dimension name) 2)
515 "(%-18s . #x%04X)\t; %c")
517 "(%-18s . #x%02X)\t; %c"))
519 (if (= (charset-iso-graphic-plane name) 1)
521 (cond ((= (charset-dimension name) 1)
523 ((= (charset-dimension name) 2)
525 ((= (charset-dimension name) 3)
529 (char-db-decode-isolated-char name value)))
530 (if (and (= (charset-chars name) 94)
531 (= (charset-dimension name) 2))
532 (insert (format " [%02d-%02d]"
533 (- (lsh value -8) 32)
534 (- (logand value 255) 32))))
537 (insert (format "(%-18s . %s)" name value))
539 (insert line-breaking))
541 (defun char-db-insert-relation-feature (char name value line-breaking
543 (insert (format "(%-18s%s " name line-breaking))
544 (let ((lbs (concat "\n" (make-string (current-column) ?\ )))
545 separator cell sources required-features
548 (setq cell (car value))
550 (setq cell (decode-char '=ucs cell)))
552 ((eq name '->subsumptive)
553 (when (or (not (some (lambda (atr)
554 (get-char-attribute cell atr))
555 char-db-ignored-attributes))
557 (encode-char cell ccs 'defined-only))
561 (let ((char-db-ignored-attributes
563 char-db-ignored-attributes)))
564 (insert-char-attributes cell readable nil nil 'for-sub-node))
565 (setq separator lbs))
570 char (intern (format "%s*sources" name))))
571 (setq required-features nil)
572 (dolist (source sources)
576 shinjigen shinjigen@1ed shinjigen@rev))
577 (setq required-features
578 (union required-features
589 (setq required-features
590 (union required-features
595 ((find-charset (setq ret (intern (format "=%s" source))))
596 (setq required-features
597 (cons ret required-features)))
598 (t (setq required-features
599 (cons source required-features)))))
600 (cond ((string-match "@JP" (symbol-name name))
601 (setq required-features
602 (union required-features
610 ((string-match "@CN" (symbol-name name))
611 (setq required-features
612 (union required-features
619 (insert (format "%S" cell))
620 (char-db-insert-char-spec cell readable
623 (setq separator lbs))
627 (if (consp (car cell))
628 (char-db-insert-char-spec cell readable)
629 (char-db-insert-char-reference cell readable))
630 (setq separator lbs))
634 (insert (prin1-to-string cell))
635 (setq separator " ")))
636 (setq value (cdr value)))
638 (insert line-breaking)))
640 (defun insert-char-attributes (char &optional readable attributes column
643 (setq column (current-column)))
644 (let (name value ; has-long-ccs-name
648 (concat "\n" (make-string (1+ column) ?\ )))
649 lbs cell separator ret
651 dest-ccss ; sources required-features
656 (if (consp attributes)
658 (dolist (name attributes)
659 (unless (memq name char-db-ignored-attributes)
660 (if (find-charset name)
664 (dolist (name (char-attribute-list))
665 (unless (memq name char-db-ignored-attributes)
666 (if (find-charset name)
670 #'char-attribute-name<)))
672 (when (memq '<-subsumptive attributes)
673 (when (or readable (not for-sub-node))
674 (when (setq value (get-char-attribute char '<-subsumptive))
675 (char-db-insert-relation-feature char '<-subsumptive value
678 (setq attributes (delq '<-subsumptive attributes)))
679 (when (and (memq '<-denotational attributes)
680 (setq value (get-char-attribute char '<-denotational)))
681 (char-db-insert-relation-feature char '<-denotational value
684 (setq attributes (delq '<-denotational attributes)))
685 (when (and (memq 'name attributes)
686 (setq value (get-char-attribute char 'name)))
688 (if (> (+ (current-column) (length value)) 48)
691 value line-breaking))
692 (setq attributes (delq 'name attributes))
694 (when (and (memq 'name* attributes)
695 (setq value (get-char-attribute char 'name*)))
697 (if (> (+ (current-column) (length value)) 48)
700 value line-breaking))
701 (setq attributes (delq 'name* attributes))
703 (when (and (memq 'script attributes)
704 (setq value (get-char-attribute char 'script)))
705 (insert (format "(script\t\t%s)%s"
706 (mapconcat (function prin1-to-string)
709 (setq attributes (delq 'script attributes))
711 (dolist (name '(=>ucs =>ucs*))
712 (when (and (memq name attributes)
713 (setq value (get-char-attribute char name)))
714 (insert (format "(%-18s . #x%04X)\t; %c%s"
715 name value (decode-char '=ucs value)
717 (setq attributes (delq name attributes))))
718 (dolist (name '(=>ucs@gb =>ucs@big5))
719 (when (and (memq name attributes)
720 (setq value (get-char-attribute char name)))
721 (insert (format "(%-18s . #x%04X)\t; %c%s"
726 (symbol-name name) 2)))
729 (setq attributes (delq name attributes))
731 ;; (dolist (name '(=>daikanwa))
732 ;; (when (and (memq name attributes)
733 ;; (setq value (get-char-attribute char name)))
735 ;; (if (integerp value)
736 ;; (format "(%-18s . %05d)\t; %c%s"
737 ;; name value (decode-char '=daikanwa value)
739 ;; (format "(%-18s %s)\t; %c%s"
741 ;; (mapconcat (function prin1-to-string)
743 ;; (char-representative-of-daikanwa char)
745 ;; (setq attributes (delq name attributes))))
746 (when (and (memq 'general-category attributes)
747 (setq value (get-char-attribute char 'general-category)))
749 "(general-category\t%s) ; %s%s"
750 (mapconcat (lambda (cell)
753 (cond ((rassoc value unidata-normative-category-alist)
754 "Normative Category")
755 ((rassoc value unidata-informative-category-alist)
756 "Informative Category")
760 (setq attributes (delq 'general-category attributes))
762 (when (and (memq 'bidi-category attributes)
763 (setq value (get-char-attribute char 'bidi-category)))
764 (insert (format "(bidi-category\t. %S)%s"
767 (setq attributes (delq 'bidi-category attributes))
769 (unless (or (not (memq 'mirrored attributes))
770 (eq (setq value (get-char-attribute char 'mirrored 'empty))
772 (insert (format "(mirrored\t\t. %S)%s"
775 (setq attributes (delq 'mirrored attributes))
778 ((and (memq 'decimal-digit-value attributes)
779 (setq value (get-char-attribute char 'decimal-digit-value)))
780 (insert (format "(decimal-digit-value . %S)%s"
783 (setq attributes (delq 'decimal-digit-value attributes))
784 (when (and (memq 'digit-value attributes)
785 (setq value (get-char-attribute char 'digit-value)))
786 (insert (format "(digit-value\t . %S)%s"
789 (setq attributes (delq 'digit-value attributes))
791 (when (and (memq 'numeric-value attributes)
792 (setq value (get-char-attribute char 'numeric-value)))
793 (insert (format "(numeric-value\t . %S)%s"
796 (setq attributes (delq 'numeric-value attributes))
800 (when (and (memq 'digit-value attributes)
801 (setq value (get-char-attribute char 'digit-value)))
802 (insert (format "(digit-value\t. %S)%s"
805 (setq attributes (delq 'digit-value attributes))
807 (when (and (memq 'numeric-value attributes)
808 (setq value (get-char-attribute char 'numeric-value)))
809 (insert (format "(numeric-value\t. %S)%s"
812 (setq attributes (delq 'numeric-value attributes))
814 (when (and (memq 'iso-10646-comment attributes)
815 (setq value (get-char-attribute char 'iso-10646-comment)))
816 (insert (format "(iso-10646-comment\t. %S)%s"
819 (setq attributes (delq 'iso-10646-comment attributes))
821 (when (and (memq 'morohashi-daikanwa attributes)
822 (setq value (get-char-attribute char 'morohashi-daikanwa)))
823 (insert (format "(morohashi-daikanwa\t%s)%s"
824 (mapconcat (function prin1-to-string) value " ")
826 (setq attributes (delq 'morohashi-daikanwa attributes))
830 (when (and (memq 'ideographic-radical attributes)
831 (setq value (get-char-attribute char 'ideographic-radical)))
833 (insert (format "(ideographic-radical . %S)\t; %c%s"
835 (ideographic-radical radical)
837 (setq attributes (delq 'ideographic-radical attributes))
839 (when (and (memq 'shuowen-radical attributes)
840 (setq value (get-char-attribute char 'shuowen-radical)))
841 (insert (format "(shuowen-radical\t. %S)\t; %c%s"
843 (shuowen-radical value)
845 (setq attributes (delq 'shuowen-radical attributes))
850 char-db-feature-domains
852 (dolist (feature (char-attribute-list))
853 (setq feature (symbol-name feature))
855 "\\(radical\\|strokes\\)@\\([^@*]+\\)\\(\\*\\|$\\)"
857 (setq domain (intern (match-string 2 feature)))
858 (unless (memq domain dest)
859 (setq dest (cons domain dest)))))
860 (sort dest #'string<))))
861 (setq key (intern (format "%s@%s" 'ideographic-radical domain)))
862 (when (and (memq key attributes)
863 (setq value (get-char-attribute char key)))
865 (insert (format "(%s . %S)\t; %c%s"
868 (ideographic-radical radical)
870 (setq attributes (delq key attributes))
872 (setq key (intern (format "%s@%s" 'ideographic-strokes domain)))
873 (when (and (memq key attributes)
874 (setq value (get-char-attribute char key)))
876 (insert (format "(%s . %S)%s"
880 (setq attributes (delq key attributes))
882 (setq key (intern (format "%s@%s" 'total-strokes domain)))
883 (when (and (memq key attributes)
884 (setq value (get-char-attribute char key)))
885 (insert (format "(%s . %S)%s"
889 (setq attributes (delq key attributes))
891 (dolist (feature '(ideographic-radical
894 (setq key (intern (format "%s@%s*sources" feature domain)))
895 (when (and (memq key attributes)
896 (setq value (get-char-attribute char key)))
897 (insert (format "(%s%s" key line-breaking))
899 (insert (format " %s" cell)))
901 (insert line-breaking)
902 (setq attributes (delq key attributes))
905 (when (and (memq 'ideographic-strokes attributes)
906 (setq value (get-char-attribute char 'ideographic-strokes)))
908 (insert (format "(ideographic-strokes . %S)%s"
911 (setq attributes (delq 'ideographic-strokes attributes))
913 (when (and (memq 'kangxi-radical attributes)
914 (setq value (get-char-attribute char 'kangxi-radical)))
915 (unless (eq value radical)
916 (insert (format "(kangxi-radical\t . %S)\t; %c%s"
918 (ideographic-radical value)
921 (setq radical value)))
922 (setq attributes (delq 'kangxi-radical attributes))
924 (when (and (memq 'kangxi-strokes attributes)
925 (setq value (get-char-attribute char 'kangxi-strokes)))
926 (unless (eq value strokes)
927 (insert (format "(kangxi-strokes\t . %S)%s"
931 (setq strokes value)))
932 (setq attributes (delq 'kangxi-strokes attributes))
934 (when (and (memq 'japanese-radical attributes)
935 (setq value (get-char-attribute char 'japanese-radical)))
936 (unless (eq value radical)
937 (insert (format "(japanese-radical\t . %S)\t; %c%s"
939 (ideographic-radical value)
942 (setq radical value)))
943 (setq attributes (delq 'japanese-radical attributes))
945 (when (and (memq 'japanese-strokes attributes)
946 (setq value (get-char-attribute char 'japanese-strokes)))
947 (unless (eq value strokes)
948 (insert (format "(japanese-strokes\t . %S)%s"
952 (setq strokes value)))
953 (setq attributes (delq 'japanese-strokes attributes))
955 (when (and (memq 'cns-radical attributes)
956 (setq value (get-char-attribute char 'cns-radical)))
957 (insert (format "(cns-radical\t . %S)\t; %c%s"
959 (ideographic-radical value)
961 (setq attributes (delq 'cns-radical attributes))
963 (when (and (memq 'cns-strokes attributes)
964 (setq value (get-char-attribute char 'cns-strokes)))
965 (unless (eq value strokes)
966 (insert (format "(cns-strokes\t . %S)%s"
970 (setq strokes value)))
971 (setq attributes (delq 'cns-strokes attributes))
973 (when (and (memq 'shinjigen-1-radical attributes)
974 (setq value (get-char-attribute char 'shinjigen-1-radical)))
975 (unless (eq value radical)
976 (insert (format "(shinjigen-1-radical . %S)\t; %c%s"
978 (ideographic-radical value)
981 (setq radical value)))
982 (setq attributes (delq 'shinjigen-1-radical attributes))
984 (when (and (memq 'ideographic- attributes)
985 (setq value (get-char-attribute char 'ideographic-)))
986 (insert "(ideographic- ")
987 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
990 (setq cell (car value))
992 (setq cell (decode-char '=ucs cell)))
993 (cond ((characterp cell)
997 (insert (format "%S" cell))
998 (char-db-insert-char-spec cell readable))
999 (setq separator lbs))
1003 (if (consp (car cell))
1004 (char-db-insert-char-spec cell readable)
1005 (char-db-insert-char-reference cell readable))
1006 (setq separator lbs))
1010 (insert (prin1-to-string cell))
1011 (setq separator " ")))
1012 (setq value (cdr value)))
1014 (insert line-breaking)
1015 (setq attributes (delq 'ideographic- attributes)))
1016 (when (and (memq 'total-strokes attributes)
1017 (setq value (get-char-attribute char 'total-strokes)))
1018 (insert (format "(total-strokes . %S)%s"
1021 (setq attributes (delq 'total-strokes attributes))
1023 (when (and (memq '->ideograph attributes)
1024 (setq value (get-char-attribute char '->ideograph)))
1025 (insert (format "(->ideograph\t%s)%s"
1026 (mapconcat (lambda (code)
1027 (cond ((symbolp code)
1030 (format "#x%04X" code))
1033 line-breaking code))))
1036 (setq attributes (delq '->ideograph attributes))
1038 ;; (when (and (memq '->decomposition attributes)
1039 ;; (setq value (get-char-attribute char '->decomposition)))
1040 ;; (insert (format "(->decomposition\t%s)%s"
1041 ;; (mapconcat (lambda (code)
1042 ;; (cond ((symbolp code)
1043 ;; (symbol-name code))
1044 ;; ((characterp code)
1046 ;; (format "%S" code)
1051 ;; (format "#x%04X" code))
1053 ;; (format "%s%S" line-breaking code))))
1056 ;; (setq attributes (delq '->decomposition attributes))
1058 (if (equal (get-char-attribute char '->titlecase)
1059 (get-char-attribute char '->uppercase))
1060 (setq attributes (delq '->titlecase attributes)))
1061 (when (and (memq '->mojikyo attributes)
1062 (setq value (get-char-attribute char '->mojikyo)))
1063 (insert (format "(->mojikyo\t\t. %06d)\t; %c%s"
1064 value (decode-char 'mojikyo value)
1066 (setq attributes (delq '->mojikyo attributes))
1068 (when (and (memq 'hanyu-dazidian-vol attributes)
1069 (setq value (get-char-attribute char 'hanyu-dazidian-vol)))
1070 (insert (format "(hanyu-dazidian-vol . %d)%s"
1071 value line-breaking))
1072 (setq attributes (delq 'hanyu-dazidian-vol attributes))
1074 (when (and (memq 'hanyu-dazidian-page attributes)
1075 (setq value (get-char-attribute char 'hanyu-dazidian-page)))
1076 (insert (format "(hanyu-dazidian-page . %d)%s"
1077 value line-breaking))
1078 (setq attributes (delq 'hanyu-dazidian-page attributes))
1080 (when (and (memq 'hanyu-dazidian-char attributes)
1081 (setq value (get-char-attribute char 'hanyu-dazidian-char)))
1082 (insert (format "(hanyu-dazidian-char . %d)%s"
1083 value line-breaking))
1084 (setq attributes (delq 'hanyu-dazidian-char attributes))
1087 (dolist (ignored '(composition
1088 ->denotational <-subsumptive ->ucs-unified
1089 ->ideographic-component-forms))
1090 (setq attributes (delq ignored attributes))))
1092 (setq name (car attributes))
1093 (unless (eq (setq value (get-char-attribute char name 'value-is-empty))
1095 (cond ((setq ret (find-charset name))
1096 (setq name (charset-name ret))
1097 (when (not (memq name dest-ccss))
1098 (setq dest-ccss (cons name dest-ccss))
1099 (char-db-insert-ccs-feature name value line-breaking))
1101 ((string-match "^=>ucs@" (symbol-name name))
1102 (insert (format "(%-18s . #x%04X)\t; %c%s"
1103 name value (decode-char '=ucs value)
1106 ((eq name 'jisx0208-1978/4X)
1107 (insert (format "(%-18s . #x%04X)%s"
1113 (not (eq name '->subsumptive))
1114 (not (eq name '->uppercase))
1115 (not (eq name '->lowercase))
1116 (not (eq name '->titlecase))
1117 (not (eq name '->canonical))
1118 (not (eq name '->Bopomofo))
1119 (not (eq name '->mistakable))
1120 (not (eq name '->ideographic-variants))
1121 (null (get-char-attribute
1122 char (intern (format "%s*sources" name))))
1123 (not (string-match "\\*sources$" (symbol-name name)))
1124 (null (get-char-attribute
1125 char (intern (format "%s*note" name))))
1126 (not (string-match "\\*note$" (symbol-name name)))
1127 (or (eq name '<-identical)
1128 (eq name '<-uppercase)
1129 (eq name '<-lowercase)
1130 (eq name '<-titlecase)
1131 (eq name '<-canonical)
1132 (eq name '<-ideographic-variants)
1133 ;; (eq name '<-synonyms)
1134 (string-match "^<-synonyms" (symbol-name name))
1135 (eq name '<-mistakable)
1136 (when (string-match "^->" (symbol-name name))
1138 ((string-match "^->fullwidth" (symbol-name name))
1139 (not (and (consp value)
1140 (characterp (car value))
1142 (car value) '=ucs 'defined-only)))
1147 ((or (eq name 'ideographic-structure)
1148 (eq name 'ideographic-combination)
1149 (eq name 'ideographic-)
1150 (eq name '=decomposition)
1151 (char-feature-base-name= '=decomposition name)
1152 (char-feature-base-name= '=>decomposition name)
1153 ;; (string-match "^=>*decomposition\\(@[^*]+\\)?$"
1154 ;; (symbol-name name))
1155 (string-match "^\\(->\\|<-\\)[^*]*$" (symbol-name name))
1156 (string-match "^\\(->\\|<-\\)[^*]*\\*sources$"
1159 (char-db-insert-relation-feature char name value
1162 ((memq name '(ideograph=
1163 original-ideograph-of
1164 ancient-ideograph-of
1167 ;; simplified-ideograph-of
1168 ideographic-variants
1169 ;; ideographic-different-form-of
1171 (insert (format "(%-18s%s " name line-breaking))
1172 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1174 (while (consp value)
1175 (setq cell (car value))
1176 (if (and (consp cell)
1181 (char-db-insert-alist cell readable)
1182 (setq separator lbs))
1185 (insert (prin1-to-string cell))
1186 (setq separator " "))
1187 (setq value (cdr value)))
1189 (insert line-breaking))
1191 (insert (format "(%-18s " name))
1192 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1194 (while (consp value)
1195 (setq cell (car value))
1196 (if (and (consp cell)
1198 (setq ret (condition-case nil
1206 (setq key (car (car rest)))
1207 (if (find-charset key)
1208 (setq cal (cons key cal))
1209 (setq al (cons key al)))
1210 (setq rest (cdr rest)))
1213 (insert-char-attributes ret
1217 (setq separator lbs))
1218 (setq ret (prin1-to-string cell))
1220 (if (< (+ (current-column)
1227 (setq separator " "))
1228 (setq value (cdr value)))
1230 (insert line-breaking))
1232 (insert (format "(%-18s" name))
1233 (setq ret (prin1-to-string value))
1234 (unless (< (+ (current-column)
1238 (insert line-breaking))
1239 (insert " . " ret ")" line-breaking)
1240 ;; (insert (format "(%-18s . %S)%s"
1245 (setq attributes (cdr attributes)))
1248 (defun insert-char-data (char &optional readable
1251 (narrow-to-region (point)(point))
1252 (insert "(define-char
1254 (insert-char-attributes char readable attributes)
1256 (goto-char (point-min))
1257 (while (re-search-forward "[ \t]+$" nil t)
1260 (goto-char (point-min))
1261 (while (re-search-forward "[ \t][ \t][ \t]*" nil t)
1262 (let ((column (current-column))
1263 (indent-tabs-mode t))
1264 (delete-region (match-beginning 0) (point))
1265 (indent-to column)))
1266 (goto-char (point-max))
1267 ;; (tabify (point-min)(point-max))
1270 (defun insert-char-data-with-variant (char &optional printable
1272 script excluded-script)
1273 (insert-char-data char printable)
1274 (let ((variants (char-variants char))
1277 (setq variants (sort variants #'<))
1278 (setq rest variants)
1279 (setq variants (cons char variants))
1281 (setq variant (car rest))
1282 (unless (get-char-attribute variant '<-subsumptive)
1283 (if (and (or (null script)
1284 (null (setq vs (get-char-attribute variant 'script)))
1286 (or (null excluded-script)
1287 (null (setq vs (get-char-attribute variant 'script)))
1288 (not (memq excluded-script vs))))
1289 (unless (and no-ucs-unified (get-char-attribute variant '=ucs))
1290 (insert-char-data variant printable)
1291 (if (setq ret (char-variants variant))
1293 (or (memq (car ret) variants)
1294 ;; (get-char-attribute (car ret) '<-subsumptive)
1295 (setq rest (nconc rest (list (car ret)))))
1296 (setq ret (cdr ret)))))))
1297 (setq rest (cdr rest)))))
1299 (defun insert-char-range-data (min max &optional script excluded-script)
1302 (while (<= code max)
1303 (setq char (decode-char '=ucs code))
1304 (if (encode-char char '=ucs 'defined-only)
1305 (insert-char-data-with-variant char nil 'no-ucs-unified
1306 script excluded-script))
1307 (setq code (1+ code)))))
1309 (defun write-char-range-data-to-file (min max file
1310 &optional script excluded-script)
1311 (let ((coding-system-for-write char-db-file-coding-system))
1313 (insert (format ";; -*- coding: %s -*-\n"
1314 char-db-file-coding-system))
1315 (insert-char-range-data min max script excluded-script)
1316 (write-region (point-min)(point-max) file))))
1318 (defvar what-character-original-window-configuration)
1321 (defun what-char-definition (char)
1322 (interactive (list (char-after)))
1323 (let ((buf (get-buffer-create "*Character Description*"))
1324 (the-buf (current-buffer))
1325 (win-conf (current-window-configuration)))
1327 (make-local-variable 'what-character-original-window-configuration)
1328 (setq what-character-original-window-configuration win-conf)
1329 (setq buffer-read-only nil)
1333 (insert-char-data-with-variant char 'printable)
1334 (unless (char-attribute-alist char)
1335 (insert (format ";; = %c\n"
1336 (let* ((rest (split-char char))
1340 (setq code (logior (lsh code 8)
1342 (decode-char ccs code)))))
1343 ;; (char-db-update-comment)
1344 (set-buffer-modified-p nil)
1345 (view-mode the-buf (lambda (buf)
1346 (set-window-configuration
1347 what-character-original-window-configuration)
1349 (goto-char (point-min)))
1351 (set-window-configuration
1352 what-character-original-window-configuration)
1353 (signal (car err) (cdr err)))))))
1359 (provide 'char-db-util)
1361 ;;; char-db-util.el ends here