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 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.
30 (defconst unidata-normative-category-alist
31 '(("Lu" letter uppercase)
32 ("Ll" letter lowercase)
33 ("Lt" letter titlecase)
34 ("Mn" mark non-spacing)
35 ("Mc" mark spacing-combining)
37 ("Nd" number decimal-digit)
40 ("Zs" separator space)
42 ("Zp" separator paragraph)
45 ("Cs" other surrogate)
46 ("Co" other private-use)
47 ("Cn" other not-assigned)))
49 (defconst unidata-informative-category-alist
50 '(("Lm" letter modifier)
52 ("Pc" punctuation connector)
53 ("Pd" punctuation dash)
54 ("Ps" punctuation open)
55 ("Pe" punctuation close)
56 ("Pi" punctuation initial-quote)
57 ("Pf" punctuation final-quote)
58 ("Po" punctuation other)
60 ("Sc" symbol currency)
61 ("Sk" symbol modifier)
65 (defconst ideographic-radicals
66 (let ((v (make-vector 215 nil))
69 (aset v i (decode-char '=ucs (+ #x2EFF i)))
73 (defun ideographic-radical (number)
74 (aref ideographic-radicals number))
76 (defconst shuowen-radicals
77 [?一 ?上 ?示 ?三 ?王 ?玉 ?玨 ?气 ?士 ?丨 ; 010
78 ?屮 ?艸 ?蓐 ?茻 ?小 ?八 ?釆 ?半 ?牛 ?犛 ; 020
79 ?告 ?口 ?凵 ?吅 ?哭 ?走 ?止 ?癶 ?步 ?此 ; 030
80 ?正 ?是 ?辵 ?彳 ?廴 ?㢟 ?行 ?齒 ?牙 ?足 ; 040
81 ?疋 ?品 ?龠 ?冊 ?㗊 ?舌 ?干 ?谷 ?只 ?㕯 ; 050
82 ?句 ?丩 ?古 ?十 ?卅 ?言 ?誩 ?音 ?䇂 ?丵 ; 060
83 ?菐 ?𠬞 ?廾 ?共 ?異 ?舁 ?𦥑 ?䢅 ?爨 ?革 ; 070
84 ?鬲 ?䰜 ?爪 ?𠃨 ?鬥 ?又 ?𠂇 ?㕜 ?支 ?𦘒 ; 080
85 ?聿 ?畫 ?隶 ?臤 ?臣 ?殳 ?殺 ?𠘧 ?寸 ?皮 ; 090
86 ?㼱 ?攴 ?敎 ?卜 ?用 ?爻 ?㸚 ?𥄎 ?目 ?䀠 ; 100
87 ?眉 ?盾 ?自 ?白 ?鼻 ?皕 ?習 ?羽 ?隹 ?奞 ; 110
88 ?萑 ?𦫳 ?苜 ?羊 ?羴 ?瞿 ?雔 ?雥 ?鳥 ?烏 ; 120
89 ?𠦒 ?冓 ?幺 ?𢆶 ?叀 ?玄 ?予 ?放 ?𠬪 ?𣦼 ; 130
90 ?歺 ?死 ?冎 ?骨 ?肉 ?筋 ?刀 ?刃 ?㓞 ?丰 ; 140
91 ?耒 ?𧢲 ?竹 ?箕 ?丌 ?左 ?工 ?㠭 ?巫 ?甘 ; 150
92 ?曰 ?乃 ?丂 ?可 ?兮 ?号 ?亏 ?旨 ?喜 ?壴 ; 160
93 ?鼓 ?豈 ?豆 ?豊 ?豐 ?䖒 ?虍 ?虎 ?虤 ?皿 ; 170
94 ?𠙴 ?去 ?血 ?丶 ?丹 ?青 ?井 ?皀 ?鬯 ?食 ; 180
95 ?亼 ?會 ?倉 ?入 ?缶 ?矢 ?高 ?冂 ?𩫏 ?京 ; 190
96 ?亯 ?𣆪 ?畗 ?㐭 ?嗇 ?來 ?麥 ?夊 ?舛 ?䑞 ; 200
97 ?韋 ?弟 ?夂 ?久 ?桀 ?木 ?東 ?林 ?才 ?叒 ; 210
98 ?之 ?帀 ?出 ?𣎵 ?生 ?乇 ?𠂹 ?𠌶 ?華 ?𥝌 ; 220
99 ?稽 ?巢 ?桼 ?束 ?㯻 ?囗 ?員 ?貝 ?邑 ?𨛜 ; 230
100 ?日 ?旦 ?倝 ?㫃 ?冥 ?晶 ?月 ?有 ?明 ?囧 ; 240
101 ?夕 ?多 ?毌 ?𢎘 ?𣐺 ?卣 ?齊 ?朿 ?片 ?鼎 ; 250
102 ?克 ?彔 ?禾 ?秝 ?黍 ?香 ?米 ?毇 ?臼 ?凶 ; 260
103 ?𣎳 ?林 ?麻 ?尗 ?耑 ?韭 ?瓜 ?瓠 ?宀 ?宮 ; 270
104 ?呂 ?穴 ?㝱 ?𤕫 ?冖 ?𠔼 ?冃 ?㒳 ?网 ?襾 ; 280
105 ?巾 ?巿 ?帛 ?白 ?㡀 ?黹 ?人 ?𠤎 ?匕 ?从 ; 290
108 (defun shuowen-radical (number)
109 (aref shuowen-radicals (1- number)))
111 (defvar char-db-file-coding-system 'utf-8-mcs-er)
113 (defvar char-db-feature-domains
114 '(ucs ucs/compat daikanwa cns gt jis jis/alt jis/a jis/b
115 jis-x0212 jis-x0213 cdp shinjigen misc unknown))
117 (defvar char-db-ignored-attributes '(ideographic-products))
119 (defun char-attribute-name< (ka kb)
121 ((eq '->denotational kb)
123 ((eq '->subsumptive kb)
124 (not (eq '->denotational ka)))
125 ((eq '->denotational ka)
127 ((eq '->subsumptive ka)
130 (string-match "^->" (symbol-name ka)))
131 (cond ((and (symbolp kb)
132 (string-match "^->" (symbol-name kb)))
133 (string< (symbol-name ka)
138 (string-match "^->" (symbol-name kb)))
141 (string-match "^<-" (symbol-name ka)))
143 (cond ((string-match "^<-" (symbol-name kb))
144 (string< (symbol-name ka)
147 ;; ((string-match "^->" (symbol-name kb))
152 (string-match "^<-" (symbol-name kb)))
154 ;; (not (string-match "^->" (symbol-name ka)))
157 (if (find-charset kb)
159 (if (setq a-ir (charset-property ka 'iso-ir))
160 (if (setq b-ir (charset-property kb 'iso-ir))
163 (< (charset-id ka)(charset-id kb))
173 (if (charset-property kb 'iso-ir)
175 (< (charset-id ka)(charset-id kb)))))
181 (string< (symbol-name ka)
187 (defvar char-db-coded-charset-priority-list
257 (defun char-db-make-char-spec (char)
259 (cond ((characterp char)
260 (cond ((and (setq ret (encode-char char '=ucs 'defined-only))
261 (not (and (<= #xE000 ret)(<= ret #xF8FF))))
262 (setq char-spec (list (cons '=ucs ret)))
263 (cond ((setq ret (get-char-attribute char 'name))
264 (setq char-spec (cons (cons 'name ret) char-spec))
266 ((setq ret (get-char-attribute char 'name*))
267 (setq char-spec (cons (cons 'name* ret) char-spec))
272 (let ((rest char-db-coded-charset-priority-list)
275 (setq ccs (charset-name
276 (find-charset (car rest))))
278 (encode-char char ccs
280 (throw 'tag (cons ccs ret)))
281 (setq rest (cdr rest))))))
282 (setq char-spec (list ret))
283 (dolist (ccs (delq (car ret) (charset-list)))
284 (if (and (or (charset-iso-final-char ccs)
291 (string-match "=ucs@" (symbol-name ccs)))
292 (setq ccs (charset-name ccs))
293 (null (assq ccs char-spec))
294 (setq ret (encode-char char ccs 'defined-only)))
295 (setq char-spec (cons (cons ccs ret) char-spec))))
297 (setq char-spec (split-char char)))
298 (cond ((setq ret (get-char-attribute char 'name))
299 (setq char-spec (cons (cons 'name ret) char-spec))
301 ((setq ret (get-char-attribute char 'name*))
302 (setq char-spec (cons (cons 'name* ret) char-spec))
305 ((setq ret (get-char-attribute
306 char 'ideographic-combination))
308 (cons (cons 'ideographic-combination ret)
315 (defun char-db-insert-char-spec (char &optional readable column
318 (setq column (current-column)))
319 (let (char-spec temp-char)
320 (setq char-spec (char-db-make-char-spec char))
321 (unless (or (characterp char) ; char
323 (setq char (find-char char-spec))
325 ;; define temporary character
326 ;; Current implementation is dirty.
327 (setq temp-char (define-char (cons '(ideograph-daikanwa . 0)
329 (remove-char-attribute temp-char 'ideograph-daikanwa)
330 (setq char temp-char))
331 (insert-char-attributes char
333 (union (mapcar #'car char-spec)
336 ;; undefine temporary character
337 ;; Current implementation is dirty.
338 (setq char-spec (char-attribute-alist temp-char))
340 (remove-char-attribute temp-char (car (car char-spec)))
341 (setq char-spec (cdr char-spec))))))
343 (defun char-db-insert-alist (alist &optional readable column)
345 (setq column (current-column)))
347 (concat "\n" (make-string (1+ column) ?\ )))
351 lbs cell rest separator)
354 (setq name (car (car alist))
355 value (cdr (car alist)))
356 (cond ((eq name 'char)
358 (if (setq ret (condition-case nil
366 (setq key (car (car value)))
367 ;; (if (find-charset key)
368 ;; (setq cal (cons key cal))
369 (setq al (cons key al))
371 (setq value (cdr value)))
372 (insert-char-attributes ret
376 (insert (prin1-to-string value)))
378 (insert line-breaking))
380 (insert (format "(%-18s " name))
381 (setq lbs (concat "\n" (make-string (current-column) ?\ )))
383 (setq cell (car value))
384 (if (and (consp cell)
386 (setq ret (condition-case nil
396 (setq key (car (car rest)))
397 ;; (if (find-charset key)
398 ;; (setq cal (cons key cal))
399 (setq al (cons key al))
401 (setq rest (cdr rest)))
404 (insert-char-attributes ret
408 (setq separator lbs))
411 (insert (prin1-to-string cell))
412 (setq separator " "))
413 (setq value (cdr value)))
415 (insert line-breaking))
417 (insert (format "(%-18s . %S)%s"
420 (setq alist (cdr alist))))
423 (defun char-db-insert-char-reference (plist &optional readable column)
425 (setq column (current-column)))
427 (concat "\n" (make-string (1+ column) ?\ )))
432 (setq name (pop plist))
433 (setq value (pop plist))
434 (cond ((eq name :char)
437 (cond ((numberp value)
438 (setq value (decode-char '=ucs value)))
440 ;; (setq value (or (find-char value)
443 (char-db-insert-char-spec value readable)
444 (insert line-breaking)
447 (insert (format "%s%s\t%d ; %c%s"
450 (ideographic-radical value)
454 (insert (format "%s%s\t%S" separator name value))
455 (setq separator line-breaking)))
459 (defun char-db-decode-isolated-char (ccs code-point)
462 (cond ((eq ccs 'arabic-iso8859-6)
463 (decode-char ccs code-point))
464 ((and (memq ccs '(=gt-pj-1
475 (setq ret (decode-char ccs code-point))
476 (setq ret (encode-char ret '=gt 'defined-only)))
477 (decode-builtin-char '=gt ret))
479 (decode-builtin-char ccs code-point))))
480 (cond ((and (<= 0 (char-int ret))
481 (<= (char-int ret) #x1F))
482 (decode-char '=ucs (+ #x2400 (char-int ret))))
483 ((= (char-int ret) #x7F)
487 (defvar char-db-convert-obsolete-format t)
489 (defun char-db-insert-ccs-feature (name value line-breaking)
492 (cond ((memq name '(=shinjigen
494 =shinjigen@rev =shinjigen/+p@rev))
495 "(%-18s . %04d)\t; %c")
496 ((eq name '=shinjigen@1ed/24pr)
497 "(%-18s . %04d)\t; %c")
498 ((or (memq name '(=daikanwa
499 =daikanwa@rev1 =daikanwa@rev2
500 =gt =>>gt =>gt =gt-k =cbeta =zinbun-oracle))
501 (string-match "^=adobe-" (symbol-name name)))
502 "(%-18s . %05d)\t; %c")
504 "(%-18s . %06d)\t; %c")
505 ((>= (charset-dimension name) 2)
506 "(%-18s . #x%04X)\t; %c")
508 "(%-18s . #x%02X)\t; %c"))
510 (if (= (charset-iso-graphic-plane name) 1)
512 (cond ((= (charset-dimension name) 1)
514 ((= (charset-dimension name) 2)
516 ((= (charset-dimension name) 3)
520 (char-db-decode-isolated-char name value)))
521 (if (and (= (charset-chars name) 94)
522 (= (charset-dimension name) 2))
523 (insert (format " [%02d-%02d]"
524 (- (lsh value -8) 32)
525 (- (logand value 255) 32))))
526 (insert line-breaking))
528 (defun char-db-insert-relation-feature (char name value line-breaking
530 (insert (format "(%-18s%s " name line-breaking))
531 (let ((lbs (concat "\n" (make-string (current-column) ?\ )))
532 separator cell sources required-features
535 (setq cell (car value))
537 (setq cell (decode-char '=ucs cell)))
539 ((eq name '->subsumptive)
540 (when (or (not (some (lambda (atr)
541 (get-char-attribute cell atr))
542 char-db-ignored-attributes))
544 (encode-char cell ccs 'defined-only))
548 (let ((char-db-ignored-attributes
550 char-db-ignored-attributes)))
551 (insert-char-attributes cell readable))
552 (setq separator lbs))
557 char (intern (format "%s*sources" name))))
558 (setq required-features nil)
559 (dolist (source sources)
563 shinjigen shinjigen@1ed shinjigen@rev))
564 (setq required-features
565 (union required-features
575 (setq required-features
576 (union required-features
581 ((find-charset (setq ret (intern (format "=%s" source))))
582 (setq required-features
583 (cons ret required-features)))
584 (t (setq required-features
585 (cons source required-features)))))
586 (cond ((string-match "@JP" (symbol-name name))
587 (setq required-features
588 (union required-features
596 ((string-match "@CN" (symbol-name name))
597 (setq required-features
598 (union required-features
605 (insert (format "%S" cell))
606 (char-db-insert-char-spec cell readable
609 (setq separator lbs))
613 (if (consp (car cell))
614 (char-db-insert-char-spec cell readable)
615 (char-db-insert-char-reference cell readable))
616 (setq separator lbs))
620 (insert (prin1-to-string cell))
621 (setq separator " ")))
622 (setq value (cdr value)))
624 (insert line-breaking)))
626 (defun insert-char-attributes (char &optional readable attributes column)
628 (setq column (current-column)))
629 (let (name value ; has-long-ccs-name
633 (concat "\n" (make-string (1+ column) ?\ )))
634 lbs cell separator ret
636 dest-ccss ; sources required-features
641 (if (consp attributes)
643 (dolist (name attributes)
644 (unless (memq name char-db-ignored-attributes)
645 (if (find-charset name)
649 (dolist (name (char-attribute-list))
650 (unless (memq name char-db-ignored-attributes)
651 (if (find-charset name)
655 #'char-attribute-name<)))
657 (when (memq '<-subsumptive attributes)
659 (when (setq value (get-char-attribute char '<-subsumptive))
660 (char-db-insert-relation-feature char '<-subsumptive value
663 (setq attributes (delq '<-subsumptive attributes)))
664 (when (and (memq '<-denotational attributes)
665 (setq value (get-char-attribute char '<-denotational)))
666 (char-db-insert-relation-feature char '<-denotational value
669 (setq attributes (delq '<-denotational 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 'name* attributes)
680 (setq value (get-char-attribute char 'name*)))
682 (if (> (+ (current-column) (length value)) 48)
685 value line-breaking))
686 (setq attributes (delq 'name* attributes))
688 (when (and (memq 'script attributes)
689 (setq value (get-char-attribute char 'script)))
690 (insert (format "(script\t\t%s)%s"
691 (mapconcat (function prin1-to-string)
694 (setq attributes (delq 'script attributes))
696 (dolist (name '(=>ucs =>ucs*))
697 (when (and (memq name attributes)
698 (setq value (get-char-attribute char name)))
699 (insert (format "(%-18s . #x%04X)\t; %c%s"
700 name value (decode-char '=ucs value)
702 (setq attributes (delq name attributes))))
703 (dolist (name '(=>ucs@gb =>ucs@cns =>ucs@jis =>ucs@ks =>ucs@big5))
704 (when (and (memq name attributes)
705 (setq value (get-char-attribute char name)))
706 (insert (format "(%-18s . #x%04X)\t; %c%s"
711 (symbol-name name) 2)))
714 (setq attributes (delq name attributes))
716 (dolist (name '(=>daikanwa))
717 (when (and (memq name attributes)
718 (setq value (get-char-attribute char name)))
721 (format "(%-18s . %05d)\t; %c%s"
722 name value (decode-char '=daikanwa value)
724 (format "(%-18s %s)\t; %c%s"
726 (mapconcat (function prin1-to-string)
728 (char-representative-of-daikanwa char)
730 (setq attributes (delq name attributes))))
731 (when (and (memq 'general-category attributes)
732 (setq value (get-char-attribute char 'general-category)))
734 "(general-category\t%s) ; %s%s"
735 (mapconcat (lambda (cell)
738 (cond ((rassoc value unidata-normative-category-alist)
739 "Normative Category")
740 ((rassoc value unidata-informative-category-alist)
741 "Informative Category")
745 (setq attributes (delq 'general-category attributes))
747 (when (and (memq 'bidi-category attributes)
748 (setq value (get-char-attribute char 'bidi-category)))
749 (insert (format "(bidi-category\t. %S)%s"
752 (setq attributes (delq 'bidi-category attributes))
754 (unless (or (not (memq 'mirrored attributes))
755 (eq (setq value (get-char-attribute char 'mirrored 'empty))
757 (insert (format "(mirrored\t\t. %S)%s"
760 (setq attributes (delq 'mirrored attributes))
763 ((and (memq 'decimal-digit-value attributes)
764 (setq value (get-char-attribute char 'decimal-digit-value)))
765 (insert (format "(decimal-digit-value . %S)%s"
768 (setq attributes (delq 'decimal-digit-value attributes))
769 (when (and (memq 'digit-value attributes)
770 (setq value (get-char-attribute char 'digit-value)))
771 (insert (format "(digit-value\t . %S)%s"
774 (setq attributes (delq 'digit-value attributes))
776 (when (and (memq 'numeric-value attributes)
777 (setq value (get-char-attribute char 'numeric-value)))
778 (insert (format "(numeric-value\t . %S)%s"
781 (setq attributes (delq 'numeric-value attributes))
785 (when (and (memq 'digit-value attributes)
786 (setq value (get-char-attribute char 'digit-value)))
787 (insert (format "(digit-value\t. %S)%s"
790 (setq attributes (delq 'digit-value attributes))
792 (when (and (memq 'numeric-value attributes)
793 (setq value (get-char-attribute char 'numeric-value)))
794 (insert (format "(numeric-value\t. %S)%s"
797 (setq attributes (delq 'numeric-value attributes))
799 (when (and (memq 'iso-10646-comment attributes)
800 (setq value (get-char-attribute char 'iso-10646-comment)))
801 (insert (format "(iso-10646-comment\t. %S)%s"
804 (setq attributes (delq 'iso-10646-comment attributes))
806 (when (and (memq 'morohashi-daikanwa attributes)
807 (setq value (get-char-attribute char 'morohashi-daikanwa)))
808 (insert (format "(morohashi-daikanwa\t%s)%s"
809 (mapconcat (function prin1-to-string) value " ")
811 (setq attributes (delq 'morohashi-daikanwa attributes))
815 (when (and (memq 'ideographic-radical attributes)
816 (setq value (get-char-attribute char 'ideographic-radical)))
818 (insert (format "(ideographic-radical . %S)\t; %c%s"
820 (ideographic-radical radical)
822 (setq attributes (delq 'ideographic-radical attributes))
824 (when (and (memq 'shuowen-radical attributes)
825 (setq value (get-char-attribute char 'shuowen-radical)))
826 (insert (format "(shuowen-radical\t. %S)\t; %c%s"
828 (shuowen-radical value)
830 (setq attributes (delq 'shuowen-radical attributes))
835 char-db-feature-domains
837 (dolist (feature (char-attribute-list))
838 (setq feature (symbol-name feature))
840 "\\(radical\\|strokes\\)@\\([^@*]+\\)\\(\\*\\|$\\)"
842 (setq domain (intern (match-string 2 feature)))
843 (unless (memq domain dest)
844 (setq dest (cons domain dest)))))
845 (sort dest #'string<))))
846 (setq key (intern (format "%s@%s" 'ideographic-radical domain)))
847 (when (and (memq key attributes)
848 (setq value (get-char-attribute char key)))
850 (insert (format "(%s . %S)\t; %c%s"
853 (ideographic-radical radical)
855 (setq attributes (delq key attributes))
857 (setq key (intern (format "%s@%s" 'ideographic-strokes domain)))
858 (when (and (memq key attributes)
859 (setq value (get-char-attribute char key)))
861 (insert (format "(%s . %S)%s"
865 (setq attributes (delq key attributes))
867 (setq key (intern (format "%s@%s" 'total-strokes domain)))
868 (when (and (memq key attributes)
869 (setq value (get-char-attribute char key)))
870 (insert (format "(%s . %S)%s"
874 (setq attributes (delq key attributes))
876 (dolist (feature '(ideographic-radical
879 (setq key (intern (format "%s@%s*sources" feature domain)))
880 (when (and (memq key attributes)
881 (setq value (get-char-attribute char key)))
882 (insert (format "(%s%s" key line-breaking))
884 (insert (format " %s" cell)))
886 (insert line-breaking)
887 (setq attributes (delq key attributes))
890 (when (and (memq 'ideographic-strokes attributes)
891 (setq value (get-char-attribute char 'ideographic-strokes)))
893 (insert (format "(ideographic-strokes . %S)%s"
896 (setq attributes (delq 'ideographic-strokes attributes))
898 (when (and (memq 'kangxi-radical attributes)
899 (setq value (get-char-attribute char 'kangxi-radical)))
900 (unless (eq value radical)
901 (insert (format "(kangxi-radical\t . %S)\t; %c%s"
903 (ideographic-radical value)
906 (setq radical value)))
907 (setq attributes (delq 'kangxi-radical attributes))
909 (when (and (memq 'kangxi-strokes attributes)
910 (setq value (get-char-attribute char 'kangxi-strokes)))
911 (unless (eq value strokes)
912 (insert (format "(kangxi-strokes\t . %S)%s"
916 (setq strokes value)))
917 (setq attributes (delq 'kangxi-strokes attributes))
919 (when (and (memq 'japanese-radical attributes)
920 (setq value (get-char-attribute char 'japanese-radical)))
921 (unless (eq value radical)
922 (insert (format "(japanese-radical\t . %S)\t; %c%s"
924 (ideographic-radical value)
927 (setq radical value)))
928 (setq attributes (delq 'japanese-radical attributes))
930 (when (and (memq 'japanese-strokes attributes)
931 (setq value (get-char-attribute char 'japanese-strokes)))
932 (unless (eq value strokes)
933 (insert (format "(japanese-strokes\t . %S)%s"
937 (setq strokes value)))
938 (setq attributes (delq 'japanese-strokes attributes))
940 (when (and (memq 'cns-radical attributes)
941 (setq value (get-char-attribute char 'cns-radical)))
942 (insert (format "(cns-radical\t . %S)\t; %c%s"
944 (ideographic-radical value)
946 (setq attributes (delq 'cns-radical attributes))
948 (when (and (memq 'cns-strokes attributes)
949 (setq value (get-char-attribute char 'cns-strokes)))
950 (unless (eq value strokes)
951 (insert (format "(cns-strokes\t . %S)%s"
955 (setq strokes value)))
956 (setq attributes (delq 'cns-strokes attributes))
958 (when (and (memq 'shinjigen-1-radical attributes)
959 (setq value (get-char-attribute char 'shinjigen-1-radical)))
960 (unless (eq value radical)
961 (insert (format "(shinjigen-1-radical . %S)\t; %c%s"
963 (ideographic-radical value)
966 (setq radical value)))
967 (setq attributes (delq 'shinjigen-1-radical attributes))
969 (when (and (memq 'ideographic- attributes)
970 (setq value (get-char-attribute char 'ideographic-)))
971 (insert "(ideographic- ")
972 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
975 (setq cell (car value))
977 (setq cell (decode-char '=ucs cell)))
978 (cond ((characterp cell)
982 (insert (format "%S" cell))
983 (char-db-insert-char-spec cell readable))
984 (setq separator lbs))
988 (if (consp (car cell))
989 (char-db-insert-char-spec cell readable)
990 (char-db-insert-char-reference cell readable))
991 (setq separator lbs))
995 (insert (prin1-to-string cell))
996 (setq separator " ")))
997 (setq value (cdr value)))
999 (insert line-breaking)
1000 (setq attributes (delq 'ideographic- attributes)))
1001 (when (and (memq 'total-strokes attributes)
1002 (setq value (get-char-attribute char 'total-strokes)))
1003 (insert (format "(total-strokes . %S)%s"
1006 (setq attributes (delq 'total-strokes attributes))
1008 (when (and (memq '->ideograph attributes)
1009 (setq value (get-char-attribute char '->ideograph)))
1010 (insert (format "(->ideograph\t%s)%s"
1011 (mapconcat (lambda (code)
1012 (cond ((symbolp code)
1015 (format "#x%04X" code))
1018 line-breaking code))))
1021 (setq attributes (delq '->ideograph attributes))
1023 ;; (when (and (memq '->decomposition attributes)
1024 ;; (setq value (get-char-attribute char '->decomposition)))
1025 ;; (insert (format "(->decomposition\t%s)%s"
1026 ;; (mapconcat (lambda (code)
1027 ;; (cond ((symbolp code)
1028 ;; (symbol-name code))
1029 ;; ((characterp code)
1031 ;; (format "%S" code)
1036 ;; (format "#x%04X" code))
1038 ;; (format "%s%S" line-breaking code))))
1041 ;; (setq attributes (delq '->decomposition attributes))
1043 (if (equal (get-char-attribute char '->titlecase)
1044 (get-char-attribute char '->uppercase))
1045 (setq attributes (delq '->titlecase attributes)))
1046 (when (and (memq '->mojikyo attributes)
1047 (setq value (get-char-attribute char '->mojikyo)))
1048 (insert (format "(->mojikyo\t\t. %06d)\t; %c%s"
1049 value (decode-char 'mojikyo value)
1051 (setq attributes (delq '->mojikyo attributes))
1053 (when (and (memq 'hanyu-dazidian-vol attributes)
1054 (setq value (get-char-attribute char 'hanyu-dazidian-vol)))
1055 (insert (format "(hanyu-dazidian-vol . %d)%s"
1056 value line-breaking))
1057 (setq attributes (delq 'hanyu-dazidian-vol attributes))
1059 (when (and (memq 'hanyu-dazidian-page attributes)
1060 (setq value (get-char-attribute char 'hanyu-dazidian-page)))
1061 (insert (format "(hanyu-dazidian-page . %d)%s"
1062 value line-breaking))
1063 (setq attributes (delq 'hanyu-dazidian-page attributes))
1065 (when (and (memq 'hanyu-dazidian-char attributes)
1066 (setq value (get-char-attribute char 'hanyu-dazidian-char)))
1067 (insert (format "(hanyu-dazidian-char . %d)%s"
1068 value line-breaking))
1069 (setq attributes (delq 'hanyu-dazidian-char attributes))
1072 (dolist (ignored '(composition
1073 ->denotational <-subsumptive ->ucs-unified
1074 ->ideographic-component-forms))
1075 (setq attributes (delq ignored attributes))))
1077 (setq name (car attributes))
1078 (if (setq value (get-char-attribute char name))
1079 (cond ((setq ret (find-charset name))
1080 (setq name (charset-name ret))
1081 (if (and (not (memq name dest-ccss))
1083 (setq value (get-char-attribute char name))
1084 (setq dest-ccss (cons name dest-ccss))))
1085 (char-db-insert-ccs-feature name value line-breaking))
1087 ((string-match "^=>ucs@" (symbol-name name))
1088 (insert (format "(%-18s . #x%04X)\t; %c%s"
1089 name value (decode-char '=ucs value)
1092 ((eq name 'jisx0208-1978/4X)
1093 (insert (format "(%-18s . #x%04X)%s"
1099 (not (eq name '->subsumptive))
1100 (not (eq name '->uppercase))
1101 (not (eq name '->lowercase))
1102 (not (eq name '->titlecase))
1103 (not (eq name '->canonical))
1104 (not (eq name '->Bopomofo))
1105 (not (eq name '->mistakable))
1106 (not (eq name '->ideographic-variants))
1107 (null (get-char-attribute
1108 char (intern (format "%s*sources" name))))
1109 (not (string-match "\\*sources$" (symbol-name name)))
1110 (null (get-char-attribute
1111 char (intern (format "%s*note" name))))
1112 (not (string-match "\\*note$" (symbol-name name)))
1113 (or (eq name '<-identical)
1114 (eq name '<-uppercase)
1115 (eq name '<-lowercase)
1116 (eq name '<-titlecase)
1117 (eq name '<-canonical)
1118 (eq name '<-ideographic-variants)
1119 ;; (eq name '<-synonyms)
1120 (string-match "^<-synonyms" (symbol-name name))
1121 (eq name '<-mistakable)
1122 (when (string-match "^->" (symbol-name name))
1124 ((string-match "^->fullwidth" (symbol-name name))
1125 (not (and (consp value)
1126 (characterp (car value))
1128 (car value) '=ucs 'defined-only)))
1133 ((or (eq name 'ideographic-structure)
1134 (eq name 'ideographic-combination)
1135 (eq name 'ideographic-)
1136 (eq name '=decomposition)
1137 (string-match "^=>decomposition" (symbol-name name))
1138 (string-match "^\\(->\\|<-\\)[^*]*$" (symbol-name name))
1139 (string-match "^\\(->\\|<-\\)[^*]*\\*sources$"
1142 (char-db-insert-relation-feature char name value
1145 ((memq name '(ideograph=
1146 original-ideograph-of
1147 ancient-ideograph-of
1150 ;; simplified-ideograph-of
1151 ideographic-variants
1152 ;; ideographic-different-form-of
1154 (insert (format "(%-18s%s " name line-breaking))
1155 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1157 (while (consp value)
1158 (setq cell (car value))
1159 (if (and (consp cell)
1164 (char-db-insert-alist cell readable)
1165 (setq separator lbs))
1168 (insert (prin1-to-string cell))
1169 (setq separator " "))
1170 (setq value (cdr value)))
1172 (insert line-breaking))
1174 (insert (format "(%-18s " name))
1175 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1177 (while (consp value)
1178 (setq cell (car value))
1179 (if (and (consp cell)
1181 (setq ret (condition-case nil
1189 (setq key (car (car rest)))
1190 (if (find-charset key)
1191 (setq cal (cons key cal))
1192 (setq al (cons key al)))
1193 (setq rest (cdr rest)))
1196 (insert-char-attributes ret
1199 (setq separator lbs))
1200 (setq ret (prin1-to-string cell))
1202 (if (< (+ (current-column)
1209 (setq separator " "))
1210 (setq value (cdr value)))
1212 (insert line-breaking))
1214 (insert (format "(%-18s" name))
1215 (setq ret (prin1-to-string value))
1216 (unless (< (+ (current-column)
1220 (insert line-breaking))
1221 (insert " . " ret ")" line-breaking)
1222 ;; (insert (format "(%-18s . %S)%s"
1227 (setq attributes (cdr attributes)))
1230 (defun insert-char-data (char &optional readable
1233 (narrow-to-region (point)(point))
1234 (insert "(define-char
1236 (insert-char-attributes char readable attributes)
1238 (goto-char (point-min))
1239 (while (re-search-forward "[ \t]+$" nil t)
1242 (goto-char (point-min))
1243 (while (re-search-forward "[ \t][ \t][ \t]*" nil t)
1244 (let ((column (current-column))
1245 (indent-tabs-mode t))
1246 (delete-region (match-beginning 0) (point))
1247 (indent-to column)))
1248 (goto-char (point-max))
1249 ;; (tabify (point-min)(point-max))
1252 (defun insert-char-data-with-variant (char &optional printable
1254 script excluded-script)
1255 (insert-char-data char printable)
1256 (let ((variants (char-variants char))
1259 (setq variants (sort variants #'<))
1260 (setq rest variants)
1261 (setq variants (cons char variants))
1263 (setq variant (car rest))
1264 (unless (get-char-attribute variant '<-subsumptive)
1265 (if (and (or (null script)
1266 (null (setq vs (get-char-attribute variant 'script)))
1268 (or (null excluded-script)
1269 (null (setq vs (get-char-attribute variant 'script)))
1270 (not (memq excluded-script vs))))
1271 (unless (and no-ucs-unified (get-char-attribute variant '=ucs))
1272 (insert-char-data variant printable)
1273 (if (setq ret (char-variants variant))
1275 (or (memq (car ret) variants)
1276 ;; (get-char-attribute (car ret) '<-subsumptive)
1277 (setq rest (nconc rest (list (car ret)))))
1278 (setq ret (cdr ret)))))))
1279 (setq rest (cdr rest)))))
1281 (defun insert-char-range-data (min max &optional script excluded-script)
1284 (while (<= code max)
1285 (setq char (decode-char '=ucs code))
1286 (if (encode-char char '=ucs 'defined-only)
1287 (insert-char-data-with-variant char nil 'no-ucs-unified
1288 script excluded-script))
1289 (setq code (1+ code)))))
1291 (defun write-char-range-data-to-file (min max file
1292 &optional script excluded-script)
1293 (let ((coding-system-for-write char-db-file-coding-system))
1295 (insert (format ";; -*- coding: %s -*-\n"
1296 char-db-file-coding-system))
1297 (insert-char-range-data min max script excluded-script)
1298 (write-region (point-min)(point-max) file))))
1300 (defvar what-character-original-window-configuration)
1303 (defun what-char-definition (char)
1304 (interactive (list (char-after)))
1305 (let ((buf (get-buffer-create "*Character Description*"))
1306 (the-buf (current-buffer))
1307 (win-conf (current-window-configuration)))
1309 (make-local-variable 'what-character-original-window-configuration)
1310 (setq what-character-original-window-configuration win-conf)
1311 (setq buffer-read-only nil)
1315 (insert-char-data-with-variant char 'printable)
1316 (unless (char-attribute-alist char)
1317 (insert (format ";; = %c\n"
1318 (let* ((rest (split-char char))
1322 (setq code (logior (lsh code 8)
1324 (decode-char ccs code)))))
1325 ;; (char-db-update-comment)
1326 (set-buffer-modified-p nil)
1327 (view-mode the-buf (lambda (buf)
1328 (set-window-configuration
1329 what-character-original-window-configuration)
1331 (goto-char (point-min)))
1333 (set-window-configuration
1334 what-character-original-window-configuration)
1335 (signal (car err) (cdr err)))))))
1337 (provide 'char-db-util)
1339 ;;; char-db-util.el ends here