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
254 (defun char-db-make-char-spec (char)
256 (cond ((characterp char)
257 (cond ((and (setq ret (encode-char char '=ucs 'defined-only))
258 (not (and (<= #xE000 ret)(<= ret #xF8FF))))
259 (setq char-spec (list (cons '=ucs ret)))
260 (cond ((setq ret (get-char-attribute char 'name))
261 (setq char-spec (cons (cons 'name ret) char-spec))
263 ((setq ret (get-char-attribute char 'name*))
264 (setq char-spec (cons (cons 'name* ret) char-spec))
269 (let ((rest char-db-coded-charset-priority-list)
272 (setq ccs (charset-name
273 (find-charset (car rest))))
275 (encode-char char ccs
277 (throw 'tag (cons ccs ret)))
278 (setq rest (cdr rest))))))
279 (setq char-spec (list ret))
280 (dolist (ccs (delq (car ret) (charset-list)))
281 (if (and (or (charset-iso-final-char ccs)
288 (string-match "=ucs@" (symbol-name ccs)))
289 (setq ccs (charset-name ccs))
290 (null (assq ccs char-spec))
291 (setq ret (encode-char char ccs 'defined-only)))
292 (setq char-spec (cons (cons ccs ret) char-spec))))
294 (setq char-spec (split-char char)))
295 (cond ((setq ret (get-char-attribute char 'name))
296 (setq char-spec (cons (cons 'name ret) char-spec))
298 ((setq ret (get-char-attribute char 'name*))
299 (setq char-spec (cons (cons 'name* ret) char-spec))
302 ((setq ret (get-char-attribute
303 char 'ideographic-combination))
305 (cons (cons 'ideographic-combination ret)
312 (defun char-db-insert-char-spec (char &optional readable column
315 (setq column (current-column)))
316 (let (char-spec temp-char)
317 (setq char-spec (char-db-make-char-spec char))
318 (unless (or (characterp char) ; char
320 (setq char (find-char char-spec))
322 ;; define temporary character
323 ;; Current implementation is dirty.
324 (setq temp-char (define-char (cons '(ideograph-daikanwa . 0)
326 (remove-char-attribute temp-char 'ideograph-daikanwa)
327 (setq char temp-char))
328 (insert-char-attributes char
330 (union (mapcar #'car char-spec)
333 ;; undefine temporary character
334 ;; Current implementation is dirty.
335 (setq char-spec (char-attribute-alist temp-char))
337 (remove-char-attribute temp-char (car (car char-spec)))
338 (setq char-spec (cdr char-spec))))))
340 (defun char-db-insert-alist (alist &optional readable column)
342 (setq column (current-column)))
344 (concat "\n" (make-string (1+ column) ?\ )))
348 lbs cell rest separator)
351 (setq name (car (car alist))
352 value (cdr (car alist)))
353 (cond ((eq name 'char)
355 (if (setq ret (condition-case nil
363 (setq key (car (car value)))
364 ;; (if (find-charset key)
365 ;; (setq cal (cons key cal))
366 (setq al (cons key al))
368 (setq value (cdr value)))
369 (insert-char-attributes ret
373 (insert (prin1-to-string value)))
375 (insert line-breaking))
377 (insert (format "(%-18s " name))
378 (setq lbs (concat "\n" (make-string (current-column) ?\ )))
380 (setq cell (car value))
381 (if (and (consp cell)
383 (setq ret (condition-case nil
393 (setq key (car (car rest)))
394 ;; (if (find-charset key)
395 ;; (setq cal (cons key cal))
396 (setq al (cons key al))
398 (setq rest (cdr rest)))
401 (insert-char-attributes ret
405 (setq separator lbs))
408 (insert (prin1-to-string cell))
409 (setq separator " "))
410 (setq value (cdr value)))
412 (insert line-breaking))
414 (insert (format "(%-18s . %S)%s"
417 (setq alist (cdr alist))))
420 (defun char-db-insert-char-reference (plist &optional readable column)
422 (setq column (current-column)))
424 (concat "\n" (make-string (1+ column) ?\ )))
429 (setq name (pop plist))
430 (setq value (pop plist))
431 (cond ((eq name :char)
434 (cond ((numberp value)
435 (setq value (decode-char '=ucs value)))
437 ;; (setq value (or (find-char value)
440 (char-db-insert-char-spec value readable)
441 (insert line-breaking)
444 (insert (format "%s%s\t%d ; %c%s"
447 (ideographic-radical value)
451 (insert (format "%s%s\t%S" separator name value))
452 (setq separator line-breaking)))
456 (defun char-db-decode-isolated-char (ccs code-point)
459 (cond ((eq ccs 'arabic-iso8859-6)
460 (decode-char ccs code-point))
461 ((and (memq ccs '(=gt-pj-1
472 (setq ret (decode-char ccs code-point))
473 (setq ret (encode-char ret '=gt 'defined-only)))
474 (decode-builtin-char '=gt ret))
476 (decode-builtin-char ccs code-point))))
477 (cond ((and (<= 0 (char-int ret))
478 (<= (char-int ret) #x1F))
479 (decode-char '=ucs (+ #x2400 (char-int ret))))
480 ((= (char-int ret) #x7F)
484 (defvar char-db-convert-obsolete-format t)
486 (defun char-db-insert-ccs-feature (name value line-breaking)
489 (cond ((memq name '(=shinjigen
491 =shinjigen@rev =shinjigen/+p@rev))
492 "(%-18s . %04d)\t; %c")
493 ((eq name '=shinjigen@1ed/24pr)
494 "(%-18s . %04d)\t; %c")
495 ((or (memq name '(=daikanwa
496 =daikanwa@rev1 =daikanwa@rev2
497 =gt <=>gt =gt-k =cbeta =zinbun-oracle))
498 (string-match "^=adobe-" (symbol-name name)))
499 "(%-18s . %05d)\t; %c")
501 "(%-18s . %06d)\t; %c")
502 ((>= (charset-dimension name) 2)
503 "(%-18s . #x%04X)\t; %c")
505 "(%-18s . #x%02X)\t; %c"))
507 (if (= (charset-iso-graphic-plane name) 1)
509 (cond ((= (charset-dimension name) 1)
511 ((= (charset-dimension name) 2)
513 ((= (charset-dimension name) 3)
517 (char-db-decode-isolated-char name value)))
518 (if (and (= (charset-chars name) 94)
519 (= (charset-dimension name) 2))
520 (insert (format " [%02d-%02d]"
521 (- (lsh value -8) 32)
522 (- (logand value 255) 32))))
523 (insert line-breaking))
525 (defun char-db-insert-relation-feature (char name value line-breaking
527 (insert (format "(%-18s%s " name line-breaking))
528 (let ((lbs (concat "\n" (make-string (current-column) ?\ )))
529 separator cell sources required-features
532 (setq cell (car value))
534 (setq cell (decode-char '=ucs cell)))
536 ((eq name '->subsumptive)
537 (when (or (not (some (lambda (atr)
538 (get-char-attribute cell atr))
539 char-db-ignored-attributes))
541 (encode-char cell ccs 'defined-only))
545 (let ((char-db-ignored-attributes
547 char-db-ignored-attributes)))
548 (insert-char-attributes cell readable))
549 (setq separator lbs))
554 char (intern (format "%s*sources" name))))
555 (setq required-features nil)
556 (dolist (source sources)
560 shinjigen shinjigen@1ed shinjigen@rev))
561 (setq required-features
562 (union required-features
572 (setq required-features
573 (union required-features
578 ((find-charset (setq ret (intern (format "=%s" source))))
579 (setq required-features
580 (cons ret required-features)))
581 (t (setq required-features
582 (cons source required-features)))))
583 (cond ((string-match "@JP" (symbol-name name))
584 (setq required-features
585 (union required-features
593 ((string-match "@CN" (symbol-name name))
594 (setq required-features
595 (union required-features
602 (insert (format "%S" cell))
603 (char-db-insert-char-spec cell readable
606 (setq separator lbs))
610 (if (consp (car cell))
611 (char-db-insert-char-spec cell readable)
612 (char-db-insert-char-reference cell readable))
613 (setq separator lbs))
617 (insert (prin1-to-string cell))
618 (setq separator " ")))
619 (setq value (cdr value)))
621 (insert line-breaking)))
623 (defun insert-char-attributes (char &optional readable attributes column)
625 (setq column (current-column)))
626 (let (name value ; has-long-ccs-name
630 (concat "\n" (make-string (1+ column) ?\ )))
631 lbs cell separator ret
633 dest-ccss ; sources required-features
638 (if (consp attributes)
640 (dolist (name attributes)
641 (unless (memq name char-db-ignored-attributes)
642 (if (find-charset name)
646 (dolist (name (char-attribute-list))
647 (unless (memq name char-db-ignored-attributes)
648 (if (find-charset name)
652 #'char-attribute-name<)))
654 (when (memq '<-subsumptive attributes)
656 (when (setq value (get-char-attribute char '<-subsumptive))
657 (char-db-insert-relation-feature char '<-subsumptive value
660 (setq attributes (delq '<-subsumptive attributes)))
661 (when (and (memq '<-denotational attributes)
662 (setq value (get-char-attribute char '<-denotational)))
663 (char-db-insert-relation-feature char '<-denotational value
666 (setq attributes (delq '<-denotational attributes)))
667 (when (and (memq 'name attributes)
668 (setq value (get-char-attribute char 'name)))
670 (if (> (+ (current-column) (length value)) 48)
673 value line-breaking))
674 (setq attributes (delq 'name attributes))
676 (when (and (memq 'name* attributes)
677 (setq value (get-char-attribute char 'name*)))
679 (if (> (+ (current-column) (length value)) 48)
682 value line-breaking))
683 (setq attributes (delq 'name* attributes))
685 (when (and (memq 'script attributes)
686 (setq value (get-char-attribute char 'script)))
687 (insert (format "(script\t\t%s)%s"
688 (mapconcat (function prin1-to-string)
691 (setq attributes (delq 'script attributes))
693 (dolist (name '(=>ucs =>ucs*))
694 (when (and (memq name attributes)
695 (setq value (get-char-attribute char name)))
696 (insert (format "(%-18s . #x%04X)\t; %c%s"
697 name value (decode-char '=ucs value)
699 (setq attributes (delq name attributes))))
700 (dolist (name '(=>ucs@gb =>ucs@cns =>ucs@jis =>ucs@ks =>ucs@big5))
701 (when (and (memq name attributes)
702 (setq value (get-char-attribute char name)))
703 (insert (format "(%-18s . #x%04X)\t; %c%s"
708 (symbol-name name) 2)))
711 (setq attributes (delq name attributes))
713 (dolist (name '(=>daikanwa))
714 (when (and (memq name attributes)
715 (setq value (get-char-attribute char name)))
718 (format "(%-18s . %05d)\t; %c%s"
719 name value (decode-char '=daikanwa value)
721 (format "(%-18s %s)\t; %c%s"
723 (mapconcat (function prin1-to-string)
725 (char-representative-of-daikanwa char)
727 (setq attributes (delq name attributes))))
728 (when (and (memq 'general-category attributes)
729 (setq value (get-char-attribute char 'general-category)))
731 "(general-category\t%s) ; %s%s"
732 (mapconcat (lambda (cell)
735 (cond ((rassoc value unidata-normative-category-alist)
736 "Normative Category")
737 ((rassoc value unidata-informative-category-alist)
738 "Informative Category")
742 (setq attributes (delq 'general-category attributes))
744 (when (and (memq 'bidi-category attributes)
745 (setq value (get-char-attribute char 'bidi-category)))
746 (insert (format "(bidi-category\t. %S)%s"
749 (setq attributes (delq 'bidi-category attributes))
751 (unless (or (not (memq 'mirrored attributes))
752 (eq (setq value (get-char-attribute char 'mirrored 'empty))
754 (insert (format "(mirrored\t\t. %S)%s"
757 (setq attributes (delq 'mirrored attributes))
760 ((and (memq 'decimal-digit-value attributes)
761 (setq value (get-char-attribute char 'decimal-digit-value)))
762 (insert (format "(decimal-digit-value . %S)%s"
765 (setq attributes (delq 'decimal-digit-value attributes))
766 (when (and (memq 'digit-value attributes)
767 (setq value (get-char-attribute char 'digit-value)))
768 (insert (format "(digit-value\t . %S)%s"
771 (setq attributes (delq 'digit-value attributes))
773 (when (and (memq 'numeric-value attributes)
774 (setq value (get-char-attribute char 'numeric-value)))
775 (insert (format "(numeric-value\t . %S)%s"
778 (setq attributes (delq 'numeric-value attributes))
782 (when (and (memq 'digit-value attributes)
783 (setq value (get-char-attribute char 'digit-value)))
784 (insert (format "(digit-value\t. %S)%s"
787 (setq attributes (delq 'digit-value attributes))
789 (when (and (memq 'numeric-value attributes)
790 (setq value (get-char-attribute char 'numeric-value)))
791 (insert (format "(numeric-value\t. %S)%s"
794 (setq attributes (delq 'numeric-value attributes))
796 (when (and (memq 'iso-10646-comment attributes)
797 (setq value (get-char-attribute char 'iso-10646-comment)))
798 (insert (format "(iso-10646-comment\t. %S)%s"
801 (setq attributes (delq 'iso-10646-comment attributes))
803 (when (and (memq 'morohashi-daikanwa attributes)
804 (setq value (get-char-attribute char 'morohashi-daikanwa)))
805 (insert (format "(morohashi-daikanwa\t%s)%s"
806 (mapconcat (function prin1-to-string) value " ")
808 (setq attributes (delq 'morohashi-daikanwa attributes))
812 (when (and (memq 'ideographic-radical attributes)
813 (setq value (get-char-attribute char 'ideographic-radical)))
815 (insert (format "(ideographic-radical . %S)\t; %c%s"
817 (ideographic-radical radical)
819 (setq attributes (delq 'ideographic-radical attributes))
821 (when (and (memq 'shuowen-radical attributes)
822 (setq value (get-char-attribute char 'shuowen-radical)))
823 (insert (format "(shuowen-radical\t. %S)\t; %c%s"
825 (shuowen-radical value)
827 (setq attributes (delq 'shuowen-radical attributes))
832 char-db-feature-domains
834 (dolist (feature (char-attribute-list))
835 (setq feature (symbol-name feature))
837 "\\(radical\\|strokes\\)@\\([^@*]+\\)\\(\\*\\|$\\)"
839 (setq domain (intern (match-string 2 feature)))
840 (unless (memq domain dest)
841 (setq dest (cons domain dest)))))
842 (sort dest #'string<))))
843 (setq key (intern (format "%s@%s" 'ideographic-radical domain)))
844 (when (and (memq key attributes)
845 (setq value (get-char-attribute char key)))
847 (insert (format "(%s . %S)\t; %c%s"
850 (ideographic-radical radical)
852 (setq attributes (delq key attributes))
854 (setq key (intern (format "%s@%s" 'ideographic-strokes domain)))
855 (when (and (memq key attributes)
856 (setq value (get-char-attribute char key)))
858 (insert (format "(%s . %S)%s"
862 (setq attributes (delq key attributes))
864 (setq key (intern (format "%s@%s" 'total-strokes domain)))
865 (when (and (memq key attributes)
866 (setq value (get-char-attribute char key)))
867 (insert (format "(%s . %S)%s"
871 (setq attributes (delq key attributes))
873 (dolist (feature '(ideographic-radical
876 (setq key (intern (format "%s@%s*sources" feature domain)))
877 (when (and (memq key attributes)
878 (setq value (get-char-attribute char key)))
879 (insert (format "(%s%s" key line-breaking))
881 (insert (format " %s" cell)))
883 (insert line-breaking)
884 (setq attributes (delq key attributes))
887 (when (and (memq 'ideographic-strokes attributes)
888 (setq value (get-char-attribute char 'ideographic-strokes)))
890 (insert (format "(ideographic-strokes . %S)%s"
893 (setq attributes (delq 'ideographic-strokes attributes))
895 (when (and (memq 'kangxi-radical attributes)
896 (setq value (get-char-attribute char 'kangxi-radical)))
897 (unless (eq value radical)
898 (insert (format "(kangxi-radical\t . %S)\t; %c%s"
900 (ideographic-radical value)
903 (setq radical value)))
904 (setq attributes (delq 'kangxi-radical attributes))
906 (when (and (memq 'kangxi-strokes attributes)
907 (setq value (get-char-attribute char 'kangxi-strokes)))
908 (unless (eq value strokes)
909 (insert (format "(kangxi-strokes\t . %S)%s"
913 (setq strokes value)))
914 (setq attributes (delq 'kangxi-strokes attributes))
916 (when (and (memq 'japanese-radical attributes)
917 (setq value (get-char-attribute char 'japanese-radical)))
918 (unless (eq value radical)
919 (insert (format "(japanese-radical\t . %S)\t; %c%s"
921 (ideographic-radical value)
924 (setq radical value)))
925 (setq attributes (delq 'japanese-radical attributes))
927 (when (and (memq 'japanese-strokes attributes)
928 (setq value (get-char-attribute char 'japanese-strokes)))
929 (unless (eq value strokes)
930 (insert (format "(japanese-strokes\t . %S)%s"
934 (setq strokes value)))
935 (setq attributes (delq 'japanese-strokes attributes))
937 (when (and (memq 'cns-radical attributes)
938 (setq value (get-char-attribute char 'cns-radical)))
939 (insert (format "(cns-radical\t . %S)\t; %c%s"
941 (ideographic-radical value)
943 (setq attributes (delq 'cns-radical attributes))
945 (when (and (memq 'cns-strokes attributes)
946 (setq value (get-char-attribute char 'cns-strokes)))
947 (unless (eq value strokes)
948 (insert (format "(cns-strokes\t . %S)%s"
952 (setq strokes value)))
953 (setq attributes (delq 'cns-strokes attributes))
955 (when (and (memq 'shinjigen-1-radical attributes)
956 (setq value (get-char-attribute char 'shinjigen-1-radical)))
957 (unless (eq value radical)
958 (insert (format "(shinjigen-1-radical . %S)\t; %c%s"
960 (ideographic-radical value)
963 (setq radical value)))
964 (setq attributes (delq 'shinjigen-1-radical attributes))
966 (when (and (memq 'ideographic- attributes)
967 (setq value (get-char-attribute char 'ideographic-)))
968 (insert "(ideographic- ")
969 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
972 (setq cell (car value))
974 (setq cell (decode-char '=ucs cell)))
975 (cond ((characterp cell)
979 (insert (format "%S" cell))
980 (char-db-insert-char-spec cell readable))
981 (setq separator lbs))
985 (if (consp (car cell))
986 (char-db-insert-char-spec cell readable)
987 (char-db-insert-char-reference cell readable))
988 (setq separator lbs))
992 (insert (prin1-to-string cell))
993 (setq separator " ")))
994 (setq value (cdr value)))
996 (insert line-breaking)
997 (setq attributes (delq 'ideographic- attributes)))
998 (when (and (memq 'total-strokes attributes)
999 (setq value (get-char-attribute char 'total-strokes)))
1000 (insert (format "(total-strokes . %S)%s"
1003 (setq attributes (delq 'total-strokes attributes))
1005 (when (and (memq '->ideograph attributes)
1006 (setq value (get-char-attribute char '->ideograph)))
1007 (insert (format "(->ideograph\t%s)%s"
1008 (mapconcat (lambda (code)
1009 (cond ((symbolp code)
1012 (format "#x%04X" code))
1015 line-breaking code))))
1018 (setq attributes (delq '->ideograph attributes))
1020 ;; (when (and (memq '->decomposition attributes)
1021 ;; (setq value (get-char-attribute char '->decomposition)))
1022 ;; (insert (format "(->decomposition\t%s)%s"
1023 ;; (mapconcat (lambda (code)
1024 ;; (cond ((symbolp code)
1025 ;; (symbol-name code))
1026 ;; ((characterp code)
1028 ;; (format "%S" code)
1033 ;; (format "#x%04X" code))
1035 ;; (format "%s%S" line-breaking code))))
1038 ;; (setq attributes (delq '->decomposition attributes))
1040 (if (equal (get-char-attribute char '->titlecase)
1041 (get-char-attribute char '->uppercase))
1042 (setq attributes (delq '->titlecase attributes)))
1043 (when (and (memq '->mojikyo attributes)
1044 (setq value (get-char-attribute char '->mojikyo)))
1045 (insert (format "(->mojikyo\t\t. %06d)\t; %c%s"
1046 value (decode-char 'mojikyo value)
1048 (setq attributes (delq '->mojikyo attributes))
1050 (when (and (memq 'hanyu-dazidian-vol attributes)
1051 (setq value (get-char-attribute char 'hanyu-dazidian-vol)))
1052 (insert (format "(hanyu-dazidian-vol . %d)%s"
1053 value line-breaking))
1054 (setq attributes (delq 'hanyu-dazidian-vol attributes))
1056 (when (and (memq 'hanyu-dazidian-page attributes)
1057 (setq value (get-char-attribute char 'hanyu-dazidian-page)))
1058 (insert (format "(hanyu-dazidian-page . %d)%s"
1059 value line-breaking))
1060 (setq attributes (delq 'hanyu-dazidian-page attributes))
1062 (when (and (memq 'hanyu-dazidian-char attributes)
1063 (setq value (get-char-attribute char 'hanyu-dazidian-char)))
1064 (insert (format "(hanyu-dazidian-char . %d)%s"
1065 value line-breaking))
1066 (setq attributes (delq 'hanyu-dazidian-char attributes))
1069 (dolist (ignored '(composition
1070 ->denotational <-subsumptive ->ucs-unified
1071 ->ideographic-component-forms))
1072 (setq attributes (delq ignored attributes))))
1074 (setq name (car attributes))
1075 (if (setq value (get-char-attribute char name))
1076 (cond ((setq ret (find-charset name))
1077 (setq name (charset-name ret))
1078 (if (and (not (memq name dest-ccss))
1080 (setq value (get-char-attribute char name))
1081 (setq dest-ccss (cons name dest-ccss))))
1082 (char-db-insert-ccs-feature name value line-breaking))
1084 ((string-match "^=>ucs@" (symbol-name name))
1085 (insert (format "(%-18s . #x%04X)\t; %c%s"
1086 name value (decode-char '=ucs value)
1089 ((eq name 'jisx0208-1978/4X)
1090 (insert (format "(%-18s . #x%04X)%s"
1096 (not (eq name '->subsumptive))
1097 (not (eq name '->uppercase))
1098 (not (eq name '->lowercase))
1099 (not (eq name '->titlecase))
1100 (not (eq name '->canonical))
1101 (not (eq name '->Bopomofo))
1102 (not (eq name '->mistakable))
1103 (not (eq name '->ideographic-variants))
1104 (null (get-char-attribute
1105 char (intern (format "%s*sources" name))))
1106 (not (string-match "\\*sources$" (symbol-name name)))
1107 (null (get-char-attribute
1108 char (intern (format "%s*note" name))))
1109 (not (string-match "\\*note$" (symbol-name name)))
1110 (or (eq name '<-identical)
1111 (eq name '<-uppercase)
1112 (eq name '<-lowercase)
1113 (eq name '<-titlecase)
1114 (eq name '<-canonical)
1115 (eq name '<-ideographic-variants)
1116 ;; (eq name '<-synonyms)
1117 (string-match "^<-synonyms" (symbol-name name))
1118 (eq name '<-mistakable)
1119 (when (string-match "^->" (symbol-name name))
1121 ((string-match "^->fullwidth" (symbol-name name))
1122 (not (and (consp value)
1123 (characterp (car value))
1125 (car value) '=ucs 'defined-only)))
1130 ((or (eq name 'ideographic-structure)
1131 (eq name 'ideographic-combination)
1132 (eq name 'ideographic-)
1133 (eq name '=decomposition)
1134 (string-match "^=>decomposition" (symbol-name name))
1135 (string-match "^\\(->\\|<-\\)[^*]*$" (symbol-name name))
1136 (string-match "^\\(->\\|<-\\)[^*]*\\*sources$"
1139 (char-db-insert-relation-feature char name value
1142 ((memq name '(ideograph=
1143 original-ideograph-of
1144 ancient-ideograph-of
1147 ;; simplified-ideograph-of
1148 ideographic-variants
1149 ;; ideographic-different-form-of
1151 (insert (format "(%-18s%s " name line-breaking))
1152 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1154 (while (consp value)
1155 (setq cell (car value))
1156 (if (and (consp cell)
1161 (char-db-insert-alist cell readable)
1162 (setq separator lbs))
1165 (insert (prin1-to-string cell))
1166 (setq separator " "))
1167 (setq value (cdr value)))
1169 (insert line-breaking))
1171 (insert (format "(%-18s " name))
1172 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1174 (while (consp value)
1175 (setq cell (car value))
1176 (if (and (consp cell)
1178 (setq ret (condition-case nil
1186 (setq key (car (car rest)))
1187 (if (find-charset key)
1188 (setq cal (cons key cal))
1189 (setq al (cons key al)))
1190 (setq rest (cdr rest)))
1193 (insert-char-attributes ret
1196 (setq separator lbs))
1197 (setq ret (prin1-to-string cell))
1199 (if (< (+ (current-column)
1206 (setq separator " "))
1207 (setq value (cdr value)))
1209 (insert line-breaking))
1211 (insert (format "(%-18s" name))
1212 (setq ret (prin1-to-string value))
1213 (unless (< (+ (current-column)
1217 (insert line-breaking))
1218 (insert " . " ret ")" line-breaking)
1219 ;; (insert (format "(%-18s . %S)%s"
1224 (setq attributes (cdr attributes)))
1227 (defun insert-char-data (char &optional readable
1230 (narrow-to-region (point)(point))
1231 (insert "(define-char
1233 (insert-char-attributes char readable attributes)
1235 (goto-char (point-min))
1236 (while (re-search-forward "[ \t]+$" nil t)
1239 (goto-char (point-min))
1240 (while (re-search-forward "[ \t][ \t][ \t]*" nil t)
1241 (let ((column (current-column))
1242 (indent-tabs-mode t))
1243 (delete-region (match-beginning 0) (point))
1244 (indent-to column)))
1245 (goto-char (point-max))
1246 ;; (tabify (point-min)(point-max))
1249 (defun insert-char-data-with-variant (char &optional printable
1251 script excluded-script)
1252 (insert-char-data char printable)
1253 (let ((variants (char-variants char))
1256 (setq variants (sort variants #'<))
1257 (setq rest variants)
1258 (setq variants (cons char variants))
1260 (setq variant (car rest))
1261 (unless (get-char-attribute variant '<-subsumptive)
1262 (if (and (or (null script)
1263 (null (setq vs (get-char-attribute variant 'script)))
1265 (or (null excluded-script)
1266 (null (setq vs (get-char-attribute variant 'script)))
1267 (not (memq excluded-script vs))))
1268 (unless (and no-ucs-unified (get-char-attribute variant '=ucs))
1269 (insert-char-data variant printable)
1270 (if (setq ret (char-variants variant))
1272 (or (memq (car ret) variants)
1273 ;; (get-char-attribute (car ret) '<-subsumptive)
1274 (setq rest (nconc rest (list (car ret)))))
1275 (setq ret (cdr ret)))))))
1276 (setq rest (cdr rest)))))
1278 (defun insert-char-range-data (min max &optional script excluded-script)
1281 (while (<= code max)
1282 (setq char (decode-char '=ucs code))
1283 (if (encode-char char '=ucs 'defined-only)
1284 (insert-char-data-with-variant char nil 'no-ucs-unified
1285 script excluded-script))
1286 (setq code (1+ code)))))
1288 (defun write-char-range-data-to-file (min max file
1289 &optional script excluded-script)
1290 (let ((coding-system-for-write char-db-file-coding-system))
1292 (insert (format ";; -*- coding: %s -*-\n"
1293 char-db-file-coding-system))
1294 (insert-char-range-data min max script excluded-script)
1295 (write-region (point-min)(point-max) file))))
1297 (defvar what-character-original-window-configuration)
1300 (defun what-char-definition (char)
1301 (interactive (list (char-after)))
1302 (let ((buf (get-buffer-create "*Character Description*"))
1303 (the-buf (current-buffer))
1304 (win-conf (current-window-configuration)))
1306 (make-local-variable 'what-character-original-window-configuration)
1307 (setq what-character-original-window-configuration win-conf)
1308 (setq buffer-read-only nil)
1312 (insert-char-data-with-variant char 'printable)
1313 (unless (char-attribute-alist char)
1314 (insert (format ";; = %c\n"
1315 (let* ((rest (split-char char))
1319 (setq code (logior (lsh code 8)
1321 (decode-char ccs code)))))
1322 ;; (char-db-update-comment)
1323 (set-buffer-modified-p nil)
1324 (view-mode the-buf (lambda (buf)
1325 (set-window-configuration
1326 what-character-original-window-configuration)
1328 (goto-char (point-min)))
1330 (set-window-configuration
1331 what-character-original-window-configuration)
1332 (signal (car err) (cdr err)))))))
1334 (provide 'char-db-util)
1336 ;;; char-db-util.el ends here