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-1 shinjigen-2 shinjigen-2-p))
473 "(%-18s . %04d)\t; %c")
474 ((or (memq name '(=daikanwa
475 =daikanwa@rev1 =daikanwa@rev2
476 =gt =gt-k =cbeta =zinbun-oracle))
477 (string-match "^=adobe-" (symbol-name name)))
478 "(%-18s . %05d)\t; %c")
480 "(%-18s . %06d)\t; %c")
481 ((>= (charset-dimension name) 2)
482 "(%-18s . #x%04X)\t; %c")
484 "(%-18s . #x%02X)\t; %c"))
486 (if (= (charset-iso-graphic-plane name) 1)
488 (cond ((= (charset-dimension name) 1)
490 ((= (charset-dimension name) 2)
492 ((= (charset-dimension name) 3)
496 (char-db-decode-isolated-char name value)))
497 (if (and (= (charset-chars name) 94)
498 (= (charset-dimension name) 2))
499 (insert (format " [%02d-%02d]"
500 (- (lsh value -8) 32)
501 (- (logand value 255) 32))))
502 (insert line-breaking))
504 (defun char-db-insert-relation-feature (char name value line-breaking
506 (insert (format "(%-18s%s " name line-breaking))
507 (let ((lbs (concat "\n" (make-string (current-column) ?\ )))
508 separator cell sources required-features
511 (setq cell (car value))
513 (setq cell (decode-char '=ucs cell)))
515 ((eq name '->subsumptive)
516 (when (or (not (some (lambda (atr)
517 (get-char-attribute cell atr))
518 char-db-ignored-attributes))
520 (encode-char cell ccs 'defined-only))
524 (let ((char-db-ignored-attributes
526 char-db-ignored-attributes)))
527 (insert-char-attributes cell readable))
528 (setq separator lbs))
533 char (intern (format "%s*sources" name))))
534 (setq required-features nil)
535 (dolist (source sources)
537 ((memq source '(JP JP/Jouyou shinjigen-1))
538 (setq required-features
539 (union required-features
548 (setq required-features
549 (union required-features
554 ((find-charset (setq ret (intern (format "=%s" source))))
555 (setq required-features
556 (cons ret required-features)))
557 (t (setq required-features
558 (cons source required-features)))))
559 (cond ((string-match "@JP" (symbol-name name))
560 (setq required-features
561 (union required-features
569 ((string-match "@CN" (symbol-name name))
570 (setq required-features
571 (union required-features
578 (insert (format "%S" cell))
579 (char-db-insert-char-spec cell readable
582 (setq separator lbs))
586 (if (consp (car cell))
587 (char-db-insert-char-spec cell readable)
588 (char-db-insert-char-reference cell readable))
589 (setq separator lbs))
593 (insert (prin1-to-string cell))
594 (setq separator " ")))
595 (setq value (cdr value)))
597 (insert line-breaking)))
599 (defun insert-char-attributes (char &optional readable attributes column)
601 (setq column (current-column)))
602 (let (name value ; has-long-ccs-name
606 (concat "\n" (make-string (1+ column) ?\ )))
607 lbs cell separator ret
609 dest-ccss ; sources required-features
614 (if (consp attributes)
616 (dolist (name attributes)
617 (unless (memq name char-db-ignored-attributes)
618 (if (find-charset name)
622 (dolist (name (char-attribute-list))
623 (unless (memq name char-db-ignored-attributes)
624 (if (find-charset name)
628 #'char-attribute-name<)))
630 (when (memq '<-subsumptive attributes)
632 (when (setq value (get-char-attribute char '<-subsumptive))
633 (char-db-insert-relation-feature char '<-subsumptive value
636 (setq attributes (delq '<-subsumptive attributes)))
637 (when (and (memq '<-denotational attributes)
638 (setq value (get-char-attribute char '<-denotational)))
639 (char-db-insert-relation-feature char '<-denotational value
642 (setq attributes (delq '<-denotational attributes)))
643 (when (and (memq 'name attributes)
644 (setq value (get-char-attribute char 'name)))
646 (if (> (+ (current-column) (length value)) 48)
649 value line-breaking))
650 (setq attributes (delq 'name attributes))
652 (when (and (memq 'name* attributes)
653 (setq value (get-char-attribute char 'name*)))
655 (if (> (+ (current-column) (length value)) 48)
658 value line-breaking))
659 (setq attributes (delq 'name* attributes))
661 (when (and (memq 'script attributes)
662 (setq value (get-char-attribute char 'script)))
663 (insert (format "(script\t\t%s)%s"
664 (mapconcat (function prin1-to-string)
667 (setq attributes (delq 'script attributes))
669 (dolist (name '(=>ucs =>ucs*))
670 (when (and (memq name attributes)
671 (setq value (get-char-attribute char name)))
672 (insert (format "(%-18s . #x%04X)\t; %c%s"
673 name value (decode-char '=ucs value)
675 (setq attributes (delq name attributes))))
676 (dolist (name '(=>ucs@gb =>ucs@cns =>ucs@jis =>ucs@ks =>ucs@big5))
677 (when (and (memq name attributes)
678 (setq value (get-char-attribute char name)))
679 (insert (format "(%-18s . #x%04X)\t; %c%s"
684 (symbol-name name) 2)))
687 (setq attributes (delq name attributes))
689 (dolist (name '(=>daikanwa))
690 (when (and (memq name attributes)
691 (setq value (get-char-attribute char name)))
694 (format "(%-18s . %05d)\t; %c%s"
695 name value (decode-char '=daikanwa value)
697 (format "(%-18s %s)\t; %c%s"
699 (mapconcat (function prin1-to-string)
701 (char-representative-of-daikanwa char)
703 (setq attributes (delq name attributes))))
704 (when (and (memq 'general-category attributes)
705 (setq value (get-char-attribute char 'general-category)))
707 "(general-category\t%s) ; %s%s"
708 (mapconcat (lambda (cell)
711 (cond ((rassoc value unidata-normative-category-alist)
712 "Normative Category")
713 ((rassoc value unidata-informative-category-alist)
714 "Informative Category")
718 (setq attributes (delq 'general-category attributes))
720 (when (and (memq 'bidi-category attributes)
721 (setq value (get-char-attribute char 'bidi-category)))
722 (insert (format "(bidi-category\t. %S)%s"
725 (setq attributes (delq 'bidi-category attributes))
727 (unless (or (not (memq 'mirrored attributes))
728 (eq (setq value (get-char-attribute char 'mirrored 'empty))
730 (insert (format "(mirrored\t\t. %S)%s"
733 (setq attributes (delq 'mirrored attributes))
736 ((and (memq 'decimal-digit-value attributes)
737 (setq value (get-char-attribute char 'decimal-digit-value)))
738 (insert (format "(decimal-digit-value . %S)%s"
741 (setq attributes (delq 'decimal-digit-value attributes))
742 (when (and (memq 'digit-value attributes)
743 (setq value (get-char-attribute char 'digit-value)))
744 (insert (format "(digit-value\t . %S)%s"
747 (setq attributes (delq 'digit-value attributes))
749 (when (and (memq 'numeric-value attributes)
750 (setq value (get-char-attribute char 'numeric-value)))
751 (insert (format "(numeric-value\t . %S)%s"
754 (setq attributes (delq 'numeric-value attributes))
758 (when (and (memq 'digit-value attributes)
759 (setq value (get-char-attribute char 'digit-value)))
760 (insert (format "(digit-value\t. %S)%s"
763 (setq attributes (delq 'digit-value attributes))
765 (when (and (memq 'numeric-value attributes)
766 (setq value (get-char-attribute char 'numeric-value)))
767 (insert (format "(numeric-value\t. %S)%s"
770 (setq attributes (delq 'numeric-value attributes))
772 (when (and (memq 'iso-10646-comment attributes)
773 (setq value (get-char-attribute char 'iso-10646-comment)))
774 (insert (format "(iso-10646-comment\t. %S)%s"
777 (setq attributes (delq 'iso-10646-comment attributes))
779 (when (and (memq 'morohashi-daikanwa attributes)
780 (setq value (get-char-attribute char 'morohashi-daikanwa)))
781 (insert (format "(morohashi-daikanwa\t%s)%s"
782 (mapconcat (function prin1-to-string) value " ")
784 (setq attributes (delq 'morohashi-daikanwa attributes))
788 (when (and (memq 'ideographic-radical attributes)
789 (setq value (get-char-attribute char 'ideographic-radical)))
791 (insert (format "(ideographic-radical . %S)\t; %c%s"
793 (ideographic-radical radical)
795 (setq attributes (delq 'ideographic-radical attributes))
797 (when (and (memq 'shuowen-radical attributes)
798 (setq value (get-char-attribute char 'shuowen-radical)))
799 (insert (format "(shuowen-radical\t. %S)\t; %c%s"
801 (shuowen-radical value)
803 (setq attributes (delq 'shuowen-radical attributes))
808 char-db-feature-domains
810 (dolist (feature (char-attribute-list))
811 (setq feature (symbol-name feature))
813 "\\(radical\\|strokes\\)@\\([^@*]+\\)\\(\\*\\|$\\)"
815 (setq domain (intern (match-string 2 feature)))
816 (unless (memq domain dest)
817 (setq dest (cons domain dest)))))
818 (sort dest #'string<))))
819 (setq key (intern (format "%s@%s" 'ideographic-radical domain)))
820 (when (and (memq key attributes)
821 (setq value (get-char-attribute char key)))
823 (insert (format "(%s . %S)\t; %c%s"
826 (ideographic-radical radical)
828 (setq attributes (delq key attributes))
830 (setq key (intern (format "%s@%s" 'ideographic-strokes domain)))
831 (when (and (memq key attributes)
832 (setq value (get-char-attribute char key)))
834 (insert (format "(%s . %S)%s"
838 (setq attributes (delq key attributes))
840 (setq key (intern (format "%s@%s" 'total-strokes domain)))
841 (when (and (memq key attributes)
842 (setq value (get-char-attribute char key)))
843 (insert (format "(%s . %S)%s"
847 (setq attributes (delq key attributes))
849 (dolist (feature '(ideographic-radical
852 (setq key (intern (format "%s@%s*sources" feature domain)))
853 (when (and (memq key attributes)
854 (setq value (get-char-attribute char key)))
855 (insert (format "(%s%s" key line-breaking))
857 (insert (format " %s" cell)))
859 (insert line-breaking)
860 (setq attributes (delq key attributes))
863 (when (and (memq 'ideographic-strokes attributes)
864 (setq value (get-char-attribute char 'ideographic-strokes)))
866 (insert (format "(ideographic-strokes . %S)%s"
869 (setq attributes (delq 'ideographic-strokes attributes))
871 (when (and (memq 'kangxi-radical attributes)
872 (setq value (get-char-attribute char 'kangxi-radical)))
873 (unless (eq value radical)
874 (insert (format "(kangxi-radical\t . %S)\t; %c%s"
876 (ideographic-radical value)
879 (setq radical value)))
880 (setq attributes (delq 'kangxi-radical attributes))
882 (when (and (memq 'kangxi-strokes attributes)
883 (setq value (get-char-attribute char 'kangxi-strokes)))
884 (unless (eq value strokes)
885 (insert (format "(kangxi-strokes\t . %S)%s"
889 (setq strokes value)))
890 (setq attributes (delq 'kangxi-strokes attributes))
892 (when (and (memq 'japanese-radical attributes)
893 (setq value (get-char-attribute char 'japanese-radical)))
894 (unless (eq value radical)
895 (insert (format "(japanese-radical\t . %S)\t; %c%s"
897 (ideographic-radical value)
900 (setq radical value)))
901 (setq attributes (delq 'japanese-radical attributes))
903 (when (and (memq 'japanese-strokes attributes)
904 (setq value (get-char-attribute char 'japanese-strokes)))
905 (unless (eq value strokes)
906 (insert (format "(japanese-strokes\t . %S)%s"
910 (setq strokes value)))
911 (setq attributes (delq 'japanese-strokes attributes))
913 (when (and (memq 'cns-radical attributes)
914 (setq value (get-char-attribute char 'cns-radical)))
915 (insert (format "(cns-radical\t . %S)\t; %c%s"
917 (ideographic-radical value)
919 (setq attributes (delq 'cns-radical attributes))
921 (when (and (memq 'cns-strokes attributes)
922 (setq value (get-char-attribute char 'cns-strokes)))
923 (unless (eq value strokes)
924 (insert (format "(cns-strokes\t . %S)%s"
928 (setq strokes value)))
929 (setq attributes (delq 'cns-strokes attributes))
931 (when (and (memq 'shinjigen-1-radical attributes)
932 (setq value (get-char-attribute char 'shinjigen-1-radical)))
933 (unless (eq value radical)
934 (insert (format "(shinjigen-1-radical . %S)\t; %c%s"
936 (ideographic-radical value)
939 (setq radical value)))
940 (setq attributes (delq 'shinjigen-1-radical attributes))
942 (when (and (memq 'ideographic- attributes)
943 (setq value (get-char-attribute char 'ideographic-)))
944 (insert "(ideographic- ")
945 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
948 (setq cell (car value))
950 (setq cell (decode-char '=ucs cell)))
951 (cond ((characterp cell)
955 (insert (format "%S" cell))
956 (char-db-insert-char-spec cell readable))
957 (setq separator lbs))
961 (if (consp (car cell))
962 (char-db-insert-char-spec cell readable)
963 (char-db-insert-char-reference cell readable))
964 (setq separator lbs))
968 (insert (prin1-to-string cell))
969 (setq separator " ")))
970 (setq value (cdr value)))
972 (insert line-breaking)
973 (setq attributes (delq 'ideographic- attributes)))
974 (when (and (memq 'total-strokes attributes)
975 (setq value (get-char-attribute char 'total-strokes)))
976 (insert (format "(total-strokes . %S)%s"
979 (setq attributes (delq 'total-strokes attributes))
981 (when (and (memq '->ideograph attributes)
982 (setq value (get-char-attribute char '->ideograph)))
983 (insert (format "(->ideograph\t%s)%s"
984 (mapconcat (lambda (code)
985 (cond ((symbolp code)
988 (format "#x%04X" code))
991 line-breaking code))))
994 (setq attributes (delq '->ideograph attributes))
996 ;; (when (and (memq '->decomposition attributes)
997 ;; (setq value (get-char-attribute char '->decomposition)))
998 ;; (insert (format "(->decomposition\t%s)%s"
999 ;; (mapconcat (lambda (code)
1000 ;; (cond ((symbolp code)
1001 ;; (symbol-name code))
1002 ;; ((characterp code)
1004 ;; (format "%S" code)
1009 ;; (format "#x%04X" code))
1011 ;; (format "%s%S" line-breaking code))))
1014 ;; (setq attributes (delq '->decomposition attributes))
1016 (if (equal (get-char-attribute char '->titlecase)
1017 (get-char-attribute char '->uppercase))
1018 (setq attributes (delq '->titlecase attributes)))
1019 (when (and (memq '->mojikyo attributes)
1020 (setq value (get-char-attribute char '->mojikyo)))
1021 (insert (format "(->mojikyo\t\t. %06d)\t; %c%s"
1022 value (decode-char 'mojikyo value)
1024 (setq attributes (delq '->mojikyo attributes))
1026 (when (and (memq 'hanyu-dazidian-vol attributes)
1027 (setq value (get-char-attribute char 'hanyu-dazidian-vol)))
1028 (insert (format "(hanyu-dazidian-vol . %d)%s"
1029 value line-breaking))
1030 (setq attributes (delq 'hanyu-dazidian-vol attributes))
1032 (when (and (memq 'hanyu-dazidian-page attributes)
1033 (setq value (get-char-attribute char 'hanyu-dazidian-page)))
1034 (insert (format "(hanyu-dazidian-page . %d)%s"
1035 value line-breaking))
1036 (setq attributes (delq 'hanyu-dazidian-page attributes))
1038 (when (and (memq 'hanyu-dazidian-char attributes)
1039 (setq value (get-char-attribute char 'hanyu-dazidian-char)))
1040 (insert (format "(hanyu-dazidian-char . %d)%s"
1041 value line-breaking))
1042 (setq attributes (delq 'hanyu-dazidian-char attributes))
1045 (dolist (ignored '(composition
1046 ->denotational <-subsumptive ->ucs-unified
1047 ->ideographic-component-forms))
1048 (setq attributes (delq ignored attributes))))
1050 (setq name (car attributes))
1051 (if (setq value (get-char-attribute char name))
1052 (cond ((setq ret (find-charset name))
1053 (setq name (charset-name ret))
1054 (if (and (not (memq name dest-ccss))
1056 (setq value (get-char-attribute char name))
1057 (setq dest-ccss (cons name dest-ccss))))
1058 (char-db-insert-ccs-feature name value line-breaking))
1060 ((string-match "^=>ucs@" (symbol-name name))
1061 (insert (format "(%-18s . #x%04X)\t; %c%s"
1062 name value (decode-char '=ucs value)
1065 ((eq name 'jisx0208-1978/4X)
1066 (insert (format "(%-18s . #x%04X)%s"
1072 (not (eq name '->subsumptive))
1073 (not (eq name '->uppercase))
1074 (not (eq name '->lowercase))
1075 (not (eq name '->titlecase))
1076 (not (eq name '->canonical))
1077 (not (eq name '->Bopomofo))
1078 (not (eq name '->mistakable))
1079 (not (eq name '->ideographic-variants))
1080 (null (get-char-attribute
1081 char (intern (format "%s*sources" name))))
1082 (not (string-match "\\*sources$" (symbol-name name)))
1083 (null (get-char-attribute
1084 char (intern (format "%s*note" name))))
1085 (not (string-match "\\*note$" (symbol-name name)))
1086 (or (eq name '<-identical)
1087 (eq name '<-uppercase)
1088 (eq name '<-lowercase)
1089 (eq name '<-titlecase)
1090 (eq name '<-canonical)
1091 (eq name '<-ideographic-variants)
1092 ;; (eq name '<-synonyms)
1093 (string-match "^<-synonyms" (symbol-name name))
1094 (eq name '<-mistakable)
1095 (when (string-match "^->" (symbol-name name))
1097 ((string-match "^->fullwidth" (symbol-name name))
1098 (not (and (consp value)
1099 (characterp (car value))
1101 (car value) '=ucs 'defined-only)))
1106 ((or (eq name 'ideographic-structure)
1107 (eq name 'ideographic-combination)
1108 (eq name 'ideographic-)
1109 (eq name '=decomposition)
1110 (string-match "^=>decomposition" (symbol-name name))
1111 (string-match "^\\(->\\|<-\\)[^*]*$" (symbol-name name))
1112 (string-match "^\\(->\\|<-\\)[^*]*\\*sources$"
1115 (char-db-insert-relation-feature char name value
1118 ((memq name '(ideograph=
1119 original-ideograph-of
1120 ancient-ideograph-of
1123 ;; simplified-ideograph-of
1124 ideographic-variants
1125 ;; ideographic-different-form-of
1127 (insert (format "(%-18s%s " name line-breaking))
1128 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1130 (while (consp value)
1131 (setq cell (car value))
1132 (if (and (consp cell)
1137 (char-db-insert-alist cell readable)
1138 (setq separator lbs))
1141 (insert (prin1-to-string cell))
1142 (setq separator " "))
1143 (setq value (cdr value)))
1145 (insert line-breaking))
1147 (insert (format "(%-18s " name))
1148 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1150 (while (consp value)
1151 (setq cell (car value))
1152 (if (and (consp cell)
1154 (setq ret (condition-case nil
1162 (setq key (car (car rest)))
1163 (if (find-charset key)
1164 (setq cal (cons key cal))
1165 (setq al (cons key al)))
1166 (setq rest (cdr rest)))
1169 (insert-char-attributes ret
1172 (setq separator lbs))
1173 (setq ret (prin1-to-string cell))
1175 (if (< (+ (current-column)
1182 (setq separator " "))
1183 (setq value (cdr value)))
1185 (insert line-breaking))
1187 (insert (format "(%-18s" name))
1188 (setq ret (prin1-to-string value))
1189 (unless (< (+ (current-column)
1193 (insert line-breaking))
1194 (insert " . " ret ")" line-breaking)
1195 ;; (insert (format "(%-18s . %S)%s"
1200 (setq attributes (cdr attributes)))
1203 (defun insert-char-data (char &optional readable
1206 (narrow-to-region (point)(point))
1207 (insert "(define-char
1209 (insert-char-attributes char readable attributes)
1211 (goto-char (point-min))
1212 (while (re-search-forward "[ \t]+$" nil t)
1215 (goto-char (point-min))
1216 (while (re-search-forward "[ \t][ \t][ \t]*" nil t)
1217 (let ((column (current-column))
1218 (indent-tabs-mode t))
1219 (delete-region (match-beginning 0) (point))
1220 (indent-to column)))
1221 (goto-char (point-max))
1222 ;; (tabify (point-min)(point-max))
1225 (defun insert-char-data-with-variant (char &optional printable
1227 script excluded-script)
1228 (insert-char-data char printable)
1229 (let ((variants (char-variants char))
1232 (setq variants (sort variants #'<))
1233 (setq rest variants)
1234 (setq variants (cons char variants))
1236 (setq variant (car rest))
1237 (unless (get-char-attribute variant '<-subsumptive)
1238 (if (and (or (null script)
1239 (null (setq vs (get-char-attribute variant 'script)))
1241 (or (null excluded-script)
1242 (null (setq vs (get-char-attribute variant 'script)))
1243 (not (memq excluded-script vs))))
1244 (unless (and no-ucs-unified (get-char-attribute variant '=ucs))
1245 (insert-char-data variant printable)
1246 (if (setq ret (char-variants variant))
1248 (or (memq (car ret) variants)
1249 ;; (get-char-attribute (car ret) '<-subsumptive)
1250 (setq rest (nconc rest (list (car ret)))))
1251 (setq ret (cdr ret)))))))
1252 (setq rest (cdr rest)))))
1254 (defun insert-char-range-data (min max &optional script excluded-script)
1257 (while (<= code max)
1258 (setq char (decode-char '=ucs code))
1259 (if (encode-char char '=ucs 'defined-only)
1260 (insert-char-data-with-variant char nil 'no-ucs-unified
1261 script excluded-script))
1262 (setq code (1+ code)))))
1264 (defun write-char-range-data-to-file (min max file
1265 &optional script excluded-script)
1266 (let ((coding-system-for-write char-db-file-coding-system))
1268 (insert (format ";; -*- coding: %s -*-\n"
1269 char-db-file-coding-system))
1270 (insert-char-range-data min max script excluded-script)
1271 (write-region (point-min)(point-max) file))))
1273 (defvar what-character-original-window-configuration)
1276 (defun what-char-definition (char)
1277 (interactive (list (char-after)))
1278 (let ((buf (get-buffer-create "*Character Description*"))
1279 (the-buf (current-buffer))
1280 (win-conf (current-window-configuration)))
1282 (make-local-variable 'what-character-original-window-configuration)
1283 (setq what-character-original-window-configuration win-conf)
1284 (setq buffer-read-only nil)
1288 (insert-char-data-with-variant char 'printable)
1289 (unless (char-attribute-alist char)
1290 (insert (format ";; = %c\n"
1291 (let* ((rest (split-char char))
1295 (setq code (logior (lsh code 8)
1297 (decode-char ccs code)))))
1298 ;; (char-db-update-comment)
1299 (set-buffer-modified-p nil)
1300 (view-mode the-buf (lambda (buf)
1301 (set-window-configuration
1302 what-character-original-window-configuration)
1304 (goto-char (point-min)))
1306 (set-window-configuration
1307 what-character-original-window-configuration)
1308 (signal (car err) (cdr err)))))))
1310 (provide 'char-db-util)
1312 ;;; char-db-util.el ends here