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 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)
158 (if (<= (charset-id ka) 1)
159 (if (<= (charset-id kb) 1)
161 ((= (charset-dimension ka)
162 (charset-dimension kb))
163 (> (charset-id ka)(charset-id kb)))
165 (> (charset-dimension ka)
166 (charset-dimension kb))
169 (if (<= (charset-id kb) 1)
171 (< (charset-id ka)(charset-id kb))))
177 (string< (symbol-name ka)
183 (defvar char-db-coded-charset-priority-list
244 (defun char-db-make-char-spec (char)
246 (cond ((characterp char)
247 (cond ((and (setq ret (encode-char char '=ucs 'defined-only))
248 (not (and (<= #xE000 ret)(<= ret #xF8FF))))
249 (setq char-spec (list (cons '=ucs ret)))
250 (cond ((setq ret (get-char-attribute char 'name))
251 (setq char-spec (cons (cons 'name ret) char-spec))
253 ((setq ret (get-char-attribute char 'name*))
254 (setq char-spec (cons (cons 'name* ret) char-spec))
259 (let ((rest char-db-coded-charset-priority-list)
262 (setq ccs (charset-name
263 (find-charset (car rest))))
265 (encode-char char ccs
267 (throw 'tag (cons ccs ret)))
268 (setq rest (cdr rest))))))
269 (setq char-spec (list ret))
270 (dolist (ccs (delq (car ret) (charset-list)))
271 (if (and (or (charset-iso-final-char ccs)
278 (setq ccs (charset-name ccs))
279 (null (assq ccs char-spec))
280 (setq ret (encode-char char ccs 'defined-only)))
281 (setq char-spec (cons (cons ccs ret) char-spec))))
283 (setq char-spec (split-char char)))
284 (cond ((setq ret (get-char-attribute char 'name))
285 (setq char-spec (cons (cons 'name ret) char-spec))
287 ((setq ret (get-char-attribute char 'name*))
288 (setq char-spec (cons (cons 'name* ret) char-spec))
295 (defun char-db-insert-char-spec (char &optional readable column
298 (setq column (current-column)))
299 (let (char-spec temp-char)
300 (setq char-spec (char-db-make-char-spec char))
301 (unless (or (characterp char) ; char
303 (setq char (find-char char-spec))
305 ;; define temporary character
306 ;; Current implementation is dirty.
307 (setq temp-char (define-char (cons '(ideograph-daikanwa . 0)
309 (remove-char-attribute temp-char 'ideograph-daikanwa)
310 (setq char temp-char))
311 (insert-char-attributes char
313 (union (mapcar #'car char-spec)
316 ;; undefine temporary character
317 ;; Current implementation is dirty.
318 (setq char-spec (char-attribute-alist temp-char))
320 (remove-char-attribute temp-char (car (car char-spec)))
321 (setq char-spec (cdr char-spec))))))
323 (defun char-db-insert-alist (alist &optional readable column)
325 (setq column (current-column)))
327 (concat "\n" (make-string (1+ column) ?\ )))
331 lbs cell rest separator)
334 (setq name (car (car alist))
335 value (cdr (car alist)))
336 (cond ((eq name 'char)
338 (if (setq ret (condition-case nil
346 (setq key (car (car value)))
347 ;; (if (find-charset key)
348 ;; (setq cal (cons key cal))
349 (setq al (cons key al))
351 (setq value (cdr value)))
352 (insert-char-attributes ret
356 (insert (prin1-to-string value)))
358 (insert line-breaking))
360 (insert (format "(%-18s " name))
361 (setq lbs (concat "\n" (make-string (current-column) ?\ )))
363 (setq cell (car value))
364 (if (and (consp cell)
366 (setq ret (condition-case nil
376 (setq key (car (car rest)))
377 ;; (if (find-charset key)
378 ;; (setq cal (cons key cal))
379 (setq al (cons key al))
381 (setq rest (cdr rest)))
384 (insert-char-attributes ret
388 (setq separator lbs))
391 (insert (prin1-to-string cell))
392 (setq separator " "))
393 (setq value (cdr value)))
395 (insert line-breaking))
397 (insert (format "(%-18s . %S)%s"
400 (setq alist (cdr alist))))
403 (defun char-db-insert-char-reference (plist &optional readable column)
405 (setq column (current-column)))
407 (concat "\n" (make-string (1+ column) ?\ )))
412 (setq name (pop plist))
413 (setq value (pop plist))
414 (cond ((eq name :char)
417 (cond ((numberp value)
418 (setq value (decode-char '=ucs value)))
420 ;; (setq value (or (find-char value)
423 (char-db-insert-char-spec value readable)
424 (insert line-breaking)
427 (insert (format "%s%s\t%d ; %c%s"
430 (ideographic-radical value)
434 (insert (format "%s%s\t%S" separator name value))
435 (setq separator line-breaking)))
439 (defun char-db-decode-isolated-char (ccs code-point)
442 (cond ((eq ccs 'arabic-iso8859-6)
443 (decode-char ccs code-point))
444 ((and (memq ccs '(=gt-pj-1
455 (setq ret (decode-char ccs code-point))
456 (setq ret (encode-char ret '=gt 'defined-only)))
457 (decode-builtin-char '=gt ret))
459 (decode-builtin-char ccs code-point))))
460 (cond ((and (<= 0 (char-int ret))
461 (<= (char-int ret) #x1F))
462 (decode-char '=ucs (+ #x2400 (char-int ret))))
463 ((= (char-int ret) #x7F)
467 (defvar char-db-convert-obsolete-format t)
469 (defun char-db-insert-ccs-feature (name value line-breaking)
472 (cond ((memq name '(=shinjigen
474 =shinjigen@rev =shinjigen/+p@rev))
475 "(%-18s . %04d)\t; %c")
476 ((eq name '=shinjigen@1ed/24pr)
477 "(%-18s . %04d)\t; %c")
478 ((or (memq name '(=daikanwa
479 =daikanwa@rev1 =daikanwa@rev2
480 =gt =gt-k =cbeta =zinbun-oracle))
481 (string-match "^=adobe-" (symbol-name name)))
482 "(%-18s . %05d)\t; %c")
484 "(%-18s . %06d)\t; %c")
485 ((>= (charset-dimension name) 2)
486 "(%-18s . #x%04X)\t; %c")
488 "(%-18s . #x%02X)\t; %c"))
490 (if (= (charset-iso-graphic-plane name) 1)
492 (cond ((= (charset-dimension name) 1)
494 ((= (charset-dimension name) 2)
496 ((= (charset-dimension name) 3)
500 (char-db-decode-isolated-char name value)))
501 (if (and (= (charset-chars name) 94)
502 (= (charset-dimension name) 2))
503 (insert (format " [%02d-%02d]"
504 (- (lsh value -8) 32)
505 (- (logand value 255) 32))))
506 (insert line-breaking))
508 (defun char-db-insert-relation-feature (char name value line-breaking
510 (insert (format "(%-18s%s " name line-breaking))
511 (let ((lbs (concat "\n" (make-string (current-column) ?\ )))
512 separator cell sources required-features
515 (setq cell (car value))
517 (setq cell (decode-char '=ucs cell)))
519 ((eq name '->subsumptive)
520 (when (or (not (some (lambda (atr)
521 (get-char-attribute cell atr))
522 char-db-ignored-attributes))
524 (encode-char cell ccs 'defined-only))
528 (let ((char-db-ignored-attributes
530 char-db-ignored-attributes)))
531 (insert-char-attributes cell readable))
532 (setq separator lbs))
537 char (intern (format "%s*sources" name))))
538 (setq required-features nil)
539 (dolist (source sources)
543 shinjigen shinjigen@1ed shinjigen@rev))
544 (setq required-features
545 (union required-features
555 (setq required-features
556 (union required-features
561 ((find-charset (setq ret (intern (format "=%s" source))))
562 (setq required-features
563 (cons ret required-features)))
564 (t (setq required-features
565 (cons source required-features)))))
566 (cond ((string-match "@JP" (symbol-name name))
567 (setq required-features
568 (union required-features
576 ((string-match "@CN" (symbol-name name))
577 (setq required-features
578 (union required-features
585 (insert (format "%S" cell))
586 (char-db-insert-char-spec cell readable
589 (setq separator lbs))
593 (if (consp (car cell))
594 (char-db-insert-char-spec cell readable)
595 (char-db-insert-char-reference cell readable))
596 (setq separator lbs))
600 (insert (prin1-to-string cell))
601 (setq separator " ")))
602 (setq value (cdr value)))
604 (insert line-breaking)))
606 (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)
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@cns =>ucs@jis =>ucs@ks =>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)))
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 (string-match "^=>decomposition" (symbol-name name))
1118 (string-match "^\\(->\\|<-\\)[^*]*$" (symbol-name name))
1119 (string-match "^\\(->\\|<-\\)[^*]*\\*sources$"
1122 (char-db-insert-relation-feature char name value
1125 ((memq name '(ideograph=
1126 original-ideograph-of
1127 ancient-ideograph-of
1130 ;; simplified-ideograph-of
1131 ideographic-variants
1132 ;; ideographic-different-form-of
1134 (insert (format "(%-18s%s " name line-breaking))
1135 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1137 (while (consp value)
1138 (setq cell (car value))
1139 (if (and (consp cell)
1144 (char-db-insert-alist cell readable)
1145 (setq separator lbs))
1148 (insert (prin1-to-string cell))
1149 (setq separator " "))
1150 (setq value (cdr value)))
1152 (insert line-breaking))
1154 (insert (format "(%-18s " name))
1155 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1157 (while (consp value)
1158 (setq cell (car value))
1159 (if (and (consp cell)
1161 (setq ret (condition-case nil
1169 (setq key (car (car rest)))
1170 (if (find-charset key)
1171 (setq cal (cons key cal))
1172 (setq al (cons key al)))
1173 (setq rest (cdr rest)))
1176 (insert-char-attributes ret
1179 (setq separator lbs))
1180 (setq ret (prin1-to-string cell))
1182 (if (< (+ (current-column)
1189 (setq separator " "))
1190 (setq value (cdr value)))
1192 (insert line-breaking))
1194 (insert (format "(%-18s" name))
1195 (setq ret (prin1-to-string value))
1196 (unless (< (+ (current-column)
1200 (insert line-breaking))
1201 (insert " . " ret ")" line-breaking)
1202 ;; (insert (format "(%-18s . %S)%s"
1207 (setq attributes (cdr attributes)))
1210 (defun insert-char-data (char &optional readable
1213 (narrow-to-region (point)(point))
1214 (insert "(define-char
1216 (insert-char-attributes char readable attributes)
1218 (goto-char (point-min))
1219 (while (re-search-forward "[ \t]+$" nil t)
1222 (goto-char (point-min))
1223 (while (re-search-forward "[ \t][ \t][ \t]*" nil t)
1224 (let ((column (current-column))
1225 (indent-tabs-mode t))
1226 (delete-region (match-beginning 0) (point))
1227 (indent-to column)))
1228 (goto-char (point-max))
1229 ;; (tabify (point-min)(point-max))
1232 (defun insert-char-data-with-variant (char &optional printable
1234 script excluded-script)
1235 (insert-char-data char printable)
1236 (let ((variants (char-variants char))
1239 (setq variants (sort variants #'<))
1240 (setq rest variants)
1241 (setq variants (cons char variants))
1243 (setq variant (car rest))
1244 (unless (get-char-attribute variant '<-subsumptive)
1245 (if (and (or (null script)
1246 (null (setq vs (get-char-attribute variant 'script)))
1248 (or (null excluded-script)
1249 (null (setq vs (get-char-attribute variant 'script)))
1250 (not (memq excluded-script vs))))
1251 (unless (and no-ucs-unified (get-char-attribute variant '=ucs))
1252 (insert-char-data variant printable)
1253 (if (setq ret (char-variants variant))
1255 (or (memq (car ret) variants)
1256 ;; (get-char-attribute (car ret) '<-subsumptive)
1257 (setq rest (nconc rest (list (car ret)))))
1258 (setq ret (cdr ret)))))))
1259 (setq rest (cdr rest)))))
1261 (defun insert-char-range-data (min max &optional script excluded-script)
1264 (while (<= code max)
1265 (setq char (decode-char '=ucs code))
1266 (if (encode-char char '=ucs 'defined-only)
1267 (insert-char-data-with-variant char nil 'no-ucs-unified
1268 script excluded-script))
1269 (setq code (1+ code)))))
1271 (defun write-char-range-data-to-file (min max file
1272 &optional script excluded-script)
1273 (let ((coding-system-for-write char-db-file-coding-system))
1275 (insert (format ";; -*- coding: %s -*-\n"
1276 char-db-file-coding-system))
1277 (insert-char-range-data min max script excluded-script)
1278 (write-region (point-min)(point-max) file))))
1280 (defvar what-character-original-window-configuration)
1283 (defun what-char-definition (char)
1284 (interactive (list (char-after)))
1285 (let ((buf (get-buffer-create "*Character Description*"))
1286 (the-buf (current-buffer))
1287 (win-conf (current-window-configuration)))
1289 (make-local-variable 'what-character-original-window-configuration)
1290 (setq what-character-original-window-configuration win-conf)
1291 (setq buffer-read-only nil)
1295 (insert-char-data-with-variant char 'printable)
1296 (unless (char-attribute-alist char)
1297 (insert (format ";; = %c\n"
1298 (let* ((rest (split-char char))
1302 (setq code (logior (lsh code 8)
1304 (decode-char ccs code)))))
1305 ;; (char-db-update-comment)
1306 (set-buffer-modified-p nil)
1307 (view-mode the-buf (lambda (buf)
1308 (set-window-configuration
1309 what-character-original-window-configuration)
1311 (goto-char (point-min)))
1313 (set-window-configuration
1314 what-character-original-window-configuration)
1315 (signal (car err) (cdr err)))))))
1317 (provide 'char-db-util)
1319 ;;; char-db-util.el ends here