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 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
104 (defun shuowen-radical (number)
105 (aref shuowen-radicals (1- number)))
107 (defvar char-db-file-coding-system 'utf-8-mcs-er)
109 (defvar char-db-feature-domains
110 '(ucs ucs/compat daikanwa cns gt jis jis/alt jis/a jis/b
111 jis-x0212 jis-x0213 cdp shinjigen misc unknown))
113 (defvar char-db-ignored-attributes '(ideographic-products))
115 (defun char-attribute-name< (ka kb)
117 ((eq '->denotational kb)
119 ((eq '->subsumptive kb)
120 (not (eq '->denotational ka)))
121 ((eq '->denotational ka)
123 ((eq '->subsumptive ka)
126 (string-match "^->" (symbol-name ka)))
127 (cond ((and (symbolp kb)
128 (string-match "^->" (symbol-name kb)))
129 (string< (symbol-name ka)
134 (string-match "^->" (symbol-name kb)))
137 (string-match "^<-" (symbol-name ka)))
139 (cond ((string-match "^<-" (symbol-name kb))
140 (string< (symbol-name ka)
143 ;; ((string-match "^->" (symbol-name kb))
148 (string-match "^<-" (symbol-name kb)))
150 ;; (not (string-match "^->" (symbol-name ka)))
153 (if (find-charset kb)
154 (if (<= (charset-id ka) 1)
155 (if (<= (charset-id kb) 1)
157 ((= (charset-dimension ka)
158 (charset-dimension kb))
159 (> (charset-id ka)(charset-id kb)))
161 (> (charset-dimension ka)
162 (charset-dimension kb))
165 (if (<= (charset-id kb) 1)
167 (< (charset-id ka)(charset-id kb))))
173 (string< (symbol-name ka)
179 (defvar char-db-coded-charset-priority-list
240 (defun char-db-make-char-spec (char)
242 (cond ((characterp char)
243 (cond ((and (setq ret (encode-char char '=ucs 'defined-only))
244 (not (and (<= #xE000 ret)(<= ret #xF8FF))))
245 (setq char-spec (list (cons '=ucs ret)))
246 (cond ((setq ret (get-char-attribute char 'name))
247 (setq char-spec (cons (cons 'name ret) char-spec))
249 ((setq ret (get-char-attribute char 'name*))
250 (setq char-spec (cons (cons 'name* ret) char-spec))
255 (let ((rest char-db-coded-charset-priority-list)
258 (setq ccs (charset-name
259 (find-charset (car rest))))
261 (encode-char char ccs
263 (throw 'tag (cons ccs ret)))
264 (setq rest (cdr rest))))))
265 (setq char-spec (list ret))
266 (dolist (ccs (delq (car ret) (charset-list)))
267 (if (and (or (charset-iso-final-char ccs)
274 (setq ccs (charset-name ccs))
275 (null (assq ccs char-spec))
276 (setq ret (encode-char char ccs 'defined-only)))
277 (setq char-spec (cons (cons ccs ret) char-spec))))
279 (setq char-spec (split-char char)))
280 (cond ((setq ret (get-char-attribute char 'name))
281 (setq char-spec (cons (cons 'name ret) char-spec))
283 ((setq ret (get-char-attribute char 'name*))
284 (setq char-spec (cons (cons 'name* ret) char-spec))
291 (defun char-db-insert-char-spec (char &optional readable column
294 (setq column (current-column)))
295 (let (char-spec temp-char)
296 (setq char-spec (char-db-make-char-spec char))
297 (unless (or (characterp char) ; char
299 (setq char (find-char char-spec))
301 ;; define temporary character
302 ;; Current implementation is dirty.
303 (setq temp-char (define-char (cons '(ideograph-daikanwa . 0)
305 (remove-char-attribute temp-char 'ideograph-daikanwa)
306 (setq char temp-char))
307 (insert-char-attributes char
309 (union (mapcar #'car char-spec)
312 ;; undefine temporary character
313 ;; Current implementation is dirty.
314 (setq char-spec (char-attribute-alist temp-char))
316 (remove-char-attribute temp-char (car (car char-spec)))
317 (setq char-spec (cdr char-spec))))))
319 (defun char-db-insert-alist (alist &optional readable column)
321 (setq column (current-column)))
323 (concat "\n" (make-string (1+ column) ?\ )))
327 lbs cell rest separator)
330 (setq name (car (car alist))
331 value (cdr (car alist)))
332 (cond ((eq name 'char)
334 (if (setq ret (condition-case nil
342 (setq key (car (car value)))
343 ;; (if (find-charset key)
344 ;; (setq cal (cons key cal))
345 (setq al (cons key al))
347 (setq value (cdr value)))
348 (insert-char-attributes ret
352 (insert (prin1-to-string value)))
354 (insert line-breaking))
356 (insert (format "(%-18s " name))
357 (setq lbs (concat "\n" (make-string (current-column) ?\ )))
359 (setq cell (car value))
360 (if (and (consp cell)
362 (setq ret (condition-case nil
372 (setq key (car (car rest)))
373 ;; (if (find-charset key)
374 ;; (setq cal (cons key cal))
375 (setq al (cons key al))
377 (setq rest (cdr rest)))
380 (insert-char-attributes ret
384 (setq separator lbs))
387 (insert (prin1-to-string cell))
388 (setq separator " "))
389 (setq value (cdr value)))
391 (insert line-breaking))
393 (insert (format "(%-18s . %S)%s"
396 (setq alist (cdr alist))))
399 (defun char-db-insert-char-reference (plist &optional readable column)
401 (setq column (current-column)))
403 (concat "\n" (make-string (1+ column) ?\ )))
408 (setq name (pop plist))
409 (setq value (pop plist))
410 (cond ((eq name :char)
413 (cond ((numberp value)
414 (setq value (decode-char '=ucs value)))
416 ;; (setq value (or (find-char value)
419 (char-db-insert-char-spec value readable)
420 (insert line-breaking)
423 (insert (format "%s%s\t%d ; %c%s"
426 (ideographic-radical value)
430 (insert (format "%s%s\t%S" separator name value))
431 (setq separator line-breaking)))
435 (defun char-db-decode-isolated-char (ccs code-point)
438 (cond ((eq ccs 'arabic-iso8859-6)
439 (decode-char ccs code-point))
440 ((and (memq ccs '(=gt-pj-1
451 (setq ret (decode-char ccs code-point))
452 (setq ret (encode-char ret '=gt 'defined-only)))
453 (decode-builtin-char '=gt ret))
455 (decode-builtin-char ccs code-point))))
456 (cond ((and (<= 0 (char-int ret))
457 (<= (char-int ret) #x1F))
458 (decode-char '=ucs (+ #x2400 (char-int ret))))
459 ((= (char-int ret) #x7F)
463 (defvar char-db-convert-obsolete-format t)
465 (defun char-db-insert-ccs-feature (name value line-breaking)
468 (cond ((or (memq name '(=daikanwa
469 =daikanwa@rev1 =daikanwa@rev2
470 =gt =gt-k =cbeta =zinbun-oracle))
471 (string-match "^=adobe-" (symbol-name name)))
472 "(%-18s . %05d)\t; %c")
474 "(%-18s . %06d)\t; %c")
475 ((>= (charset-dimension name) 2)
476 "(%-18s . #x%04X)\t; %c")
478 "(%-18s . #x%02X)\t; %c"))
480 (if (= (charset-iso-graphic-plane name) 1)
482 (cond ((= (charset-dimension name) 1)
484 ((= (charset-dimension name) 2)
486 ((= (charset-dimension name) 3)
490 (char-db-decode-isolated-char name value)))
491 (if (and (= (charset-chars name) 94)
492 (= (charset-dimension name) 2))
493 (insert (format " [%02d-%02d]"
494 (- (lsh value -8) 32)
495 (- (logand value 255) 32))))
496 (insert line-breaking))
498 (defun char-db-insert-relation-feature (char name value line-breaking
500 (insert (format "(%-18s%s " name line-breaking))
501 (let ((lbs (concat "\n" (make-string (current-column) ?\ )))
502 separator cell sources required-features
505 (setq cell (car value))
507 (setq cell (decode-char '=ucs cell)))
509 ((eq name '->subsumptive)
510 (when (or (not (some (lambda (atr)
511 (get-char-attribute cell atr))
512 char-db-ignored-attributes))
514 (encode-char cell ccs 'defined-only))
518 (let ((char-db-ignored-attributes
520 char-db-ignored-attributes)))
521 (insert-char-attributes cell readable))
522 (setq separator lbs))
527 char (intern (format "%s*sources" name))))
528 (setq required-features nil)
529 (dolist (source sources)
531 ((memq source '(JP JP/Jouyou shinjigen-1))
532 (setq required-features
533 (union required-features
542 (setq required-features
543 (union required-features
548 ((find-charset (setq ret (intern (format "=%s" source))))
549 (setq required-features
550 (cons ret required-features)))
551 (t (setq required-features
552 (cons source required-features)))))
553 (cond ((string-match "@JP" (symbol-name name))
554 (setq required-features
555 (union required-features
563 ((string-match "@CN" (symbol-name name))
564 (setq required-features
565 (union required-features
572 (insert (format "%S" cell))
573 (char-db-insert-char-spec cell readable
576 (setq separator lbs))
580 (if (consp (car cell))
581 (char-db-insert-char-spec cell readable)
582 (char-db-insert-char-reference cell readable))
583 (setq separator lbs))
587 (insert (prin1-to-string cell))
588 (setq separator " ")))
589 (setq value (cdr value)))
591 (insert line-breaking)))
593 (defun insert-char-attributes (char &optional readable attributes column)
595 (setq column (current-column)))
596 (let (name value ; has-long-ccs-name
600 (concat "\n" (make-string (1+ column) ?\ )))
601 lbs cell separator ret
603 dest-ccss ; sources required-features
608 (if (consp attributes)
610 (dolist (name attributes)
611 (unless (memq name char-db-ignored-attributes)
612 (if (find-charset name)
616 (dolist (name (char-attribute-list))
617 (unless (memq name char-db-ignored-attributes)
618 (if (find-charset name)
622 #'char-attribute-name<)))
624 (when (memq '<-subsumptive attributes)
626 (when (setq value (get-char-attribute char '<-subsumptive))
627 (char-db-insert-relation-feature char '<-subsumptive value
630 (setq attributes (delq '<-subsumptive attributes)))
631 (when (and (memq '<-denotational attributes)
632 (setq value (get-char-attribute char '<-denotational)))
633 (char-db-insert-relation-feature char '<-denotational value
636 (setq attributes (delq '<-denotational attributes)))
637 (when (and (memq 'name attributes)
638 (setq value (get-char-attribute char 'name)))
640 (if (> (+ (current-column) (length value)) 48)
643 value line-breaking))
644 (setq attributes (delq 'name attributes))
646 (when (and (memq 'name* attributes)
647 (setq value (get-char-attribute char 'name*)))
649 (if (> (+ (current-column) (length value)) 48)
652 value line-breaking))
653 (setq attributes (delq 'name* attributes))
655 (when (and (memq 'script attributes)
656 (setq value (get-char-attribute char 'script)))
657 (insert (format "(script\t\t%s)%s"
658 (mapconcat (function prin1-to-string)
661 (setq attributes (delq 'script attributes))
663 (dolist (name '(=>ucs =>ucs*))
664 (when (and (memq name attributes)
665 (setq value (get-char-attribute char name)))
666 (insert (format "(%-18s . #x%04X)\t; %c%s"
667 name value (decode-char '=ucs value)
669 (setq attributes (delq name attributes))))
670 (dolist (name '(=>ucs@gb =>ucs@cns =>ucs@jis =>ucs@ks =>ucs@big5))
671 (when (and (memq name attributes)
672 (setq value (get-char-attribute char name)))
673 (insert (format "(%-18s . #x%04X)\t; %c%s"
678 (symbol-name name) 2)))
681 (setq attributes (delq name attributes))
683 (dolist (name '(=>daikanwa))
684 (when (and (memq name attributes)
685 (setq value (get-char-attribute char name)))
688 (format "(%-18s . %05d)\t; %c%s"
689 name value (decode-char '=daikanwa value)
691 (format "(%-18s %s)\t; %c%s"
693 (mapconcat (function prin1-to-string)
695 (char-representative-of-daikanwa char)
697 (setq attributes (delq name attributes))))
698 (when (and (memq 'general-category attributes)
699 (setq value (get-char-attribute char 'general-category)))
701 "(general-category\t%s) ; %s%s"
702 (mapconcat (lambda (cell)
705 (cond ((rassoc value unidata-normative-category-alist)
706 "Normative Category")
707 ((rassoc value unidata-informative-category-alist)
708 "Informative Category")
712 (setq attributes (delq 'general-category attributes))
714 (when (and (memq 'bidi-category attributes)
715 (setq value (get-char-attribute char 'bidi-category)))
716 (insert (format "(bidi-category\t. %S)%s"
719 (setq attributes (delq 'bidi-category attributes))
721 (unless (or (not (memq 'mirrored attributes))
722 (eq (setq value (get-char-attribute char 'mirrored 'empty))
724 (insert (format "(mirrored\t\t. %S)%s"
727 (setq attributes (delq 'mirrored attributes))
730 ((and (memq 'decimal-digit-value attributes)
731 (setq value (get-char-attribute char 'decimal-digit-value)))
732 (insert (format "(decimal-digit-value . %S)%s"
735 (setq attributes (delq 'decimal-digit-value attributes))
736 (when (and (memq 'digit-value attributes)
737 (setq value (get-char-attribute char 'digit-value)))
738 (insert (format "(digit-value\t . %S)%s"
741 (setq attributes (delq 'digit-value attributes))
743 (when (and (memq 'numeric-value attributes)
744 (setq value (get-char-attribute char 'numeric-value)))
745 (insert (format "(numeric-value\t . %S)%s"
748 (setq attributes (delq 'numeric-value attributes))
752 (when (and (memq 'digit-value attributes)
753 (setq value (get-char-attribute char 'digit-value)))
754 (insert (format "(digit-value\t. %S)%s"
757 (setq attributes (delq 'digit-value attributes))
759 (when (and (memq 'numeric-value attributes)
760 (setq value (get-char-attribute char 'numeric-value)))
761 (insert (format "(numeric-value\t. %S)%s"
764 (setq attributes (delq 'numeric-value attributes))
766 (when (and (memq 'iso-10646-comment attributes)
767 (setq value (get-char-attribute char 'iso-10646-comment)))
768 (insert (format "(iso-10646-comment\t. %S)%s"
771 (setq attributes (delq 'iso-10646-comment attributes))
773 (when (and (memq 'morohashi-daikanwa attributes)
774 (setq value (get-char-attribute char 'morohashi-daikanwa)))
775 (insert (format "(morohashi-daikanwa\t%s)%s"
776 (mapconcat (function prin1-to-string) value " ")
778 (setq attributes (delq 'morohashi-daikanwa attributes))
782 (when (and (memq 'ideographic-radical attributes)
783 (setq value (get-char-attribute char 'ideographic-radical)))
785 (insert (format "(ideographic-radical . %S)\t; %c%s"
787 (ideographic-radical radical)
789 (setq attributes (delq 'ideographic-radical attributes))
791 (when (and (memq 'shuowen-radical attributes)
792 (setq value (get-char-attribute char 'shuowen-radical)))
793 (insert (format "(shuowen-radical\t. %S)\t; %c%s"
795 (shuowen-radical value)
797 (setq attributes (delq 'shuowen-radical attributes))
802 char-db-feature-domains
804 (dolist (feature (char-attribute-list))
805 (setq feature (symbol-name feature))
807 "\\(radical\\|strokes\\)@\\([^@*]+\\)\\(\\*\\|$\\)"
809 (setq domain (intern (match-string 2 feature)))
810 (unless (memq domain dest)
811 (setq dest (cons domain dest)))))
812 (sort dest #'string<))))
813 (setq key (intern (format "%s@%s" 'ideographic-radical domain)))
814 (when (and (memq key attributes)
815 (setq value (get-char-attribute char key)))
817 (insert (format "(%s . %S)\t; %c%s"
820 (ideographic-radical radical)
822 (setq attributes (delq key attributes))
824 (setq key (intern (format "%s@%s" 'ideographic-strokes domain)))
825 (when (and (memq key attributes)
826 (setq value (get-char-attribute char key)))
828 (insert (format "(%s . %S)%s"
832 (setq attributes (delq key attributes))
834 (setq key (intern (format "%s@%s" 'total-strokes domain)))
835 (when (and (memq key attributes)
836 (setq value (get-char-attribute char key)))
837 (insert (format "(%s . %S)%s"
841 (setq attributes (delq key attributes))
843 (dolist (feature '(ideographic-radical
846 (setq key (intern (format "%s@%s*sources" feature domain)))
847 (when (and (memq key attributes)
848 (setq value (get-char-attribute char key)))
849 (insert (format "(%s%s" key line-breaking))
851 (insert (format " %s" cell)))
853 (insert line-breaking)
854 (setq attributes (delq key attributes))
857 (when (and (memq 'ideographic-strokes attributes)
858 (setq value (get-char-attribute char 'ideographic-strokes)))
860 (insert (format "(ideographic-strokes . %S)%s"
863 (setq attributes (delq 'ideographic-strokes attributes))
865 (when (and (memq 'kangxi-radical attributes)
866 (setq value (get-char-attribute char 'kangxi-radical)))
867 (unless (eq value radical)
868 (insert (format "(kangxi-radical\t . %S)\t; %c%s"
870 (ideographic-radical value)
873 (setq radical value)))
874 (setq attributes (delq 'kangxi-radical attributes))
876 (when (and (memq 'kangxi-strokes attributes)
877 (setq value (get-char-attribute char 'kangxi-strokes)))
878 (unless (eq value strokes)
879 (insert (format "(kangxi-strokes\t . %S)%s"
883 (setq strokes value)))
884 (setq attributes (delq 'kangxi-strokes attributes))
886 (when (and (memq 'japanese-radical attributes)
887 (setq value (get-char-attribute char 'japanese-radical)))
888 (unless (eq value radical)
889 (insert (format "(japanese-radical\t . %S)\t; %c%s"
891 (ideographic-radical value)
894 (setq radical value)))
895 (setq attributes (delq 'japanese-radical attributes))
897 (when (and (memq 'japanese-strokes attributes)
898 (setq value (get-char-attribute char 'japanese-strokes)))
899 (unless (eq value strokes)
900 (insert (format "(japanese-strokes\t . %S)%s"
904 (setq strokes value)))
905 (setq attributes (delq 'japanese-strokes attributes))
907 (when (and (memq 'cns-radical attributes)
908 (setq value (get-char-attribute char 'cns-radical)))
909 (insert (format "(cns-radical\t . %S)\t; %c%s"
911 (ideographic-radical value)
913 (setq attributes (delq 'cns-radical attributes))
915 (when (and (memq 'cns-strokes attributes)
916 (setq value (get-char-attribute char 'cns-strokes)))
917 (unless (eq value strokes)
918 (insert (format "(cns-strokes\t . %S)%s"
922 (setq strokes value)))
923 (setq attributes (delq 'cns-strokes attributes))
925 (when (and (memq 'shinjigen-1-radical attributes)
926 (setq value (get-char-attribute char 'shinjigen-1-radical)))
927 (unless (eq value radical)
928 (insert (format "(shinjigen-1-radical . %S)\t; %c%s"
930 (ideographic-radical value)
933 (setq radical value)))
934 (setq attributes (delq 'shinjigen-1-radical attributes))
936 (when (and (memq 'ideographic- attributes)
937 (setq value (get-char-attribute char 'ideographic-)))
938 (insert "(ideographic- ")
939 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
942 (setq cell (car value))
944 (setq cell (decode-char '=ucs cell)))
945 (cond ((characterp cell)
949 (insert (format "%S" cell))
950 (char-db-insert-char-spec cell readable))
951 (setq separator lbs))
955 (if (consp (car cell))
956 (char-db-insert-char-spec cell readable)
957 (char-db-insert-char-reference cell readable))
958 (setq separator lbs))
962 (insert (prin1-to-string cell))
963 (setq separator " ")))
964 (setq value (cdr value)))
966 (insert line-breaking)
967 (setq attributes (delq 'ideographic- attributes)))
968 (when (and (memq 'total-strokes attributes)
969 (setq value (get-char-attribute char 'total-strokes)))
970 (insert (format "(total-strokes . %S)%s"
973 (setq attributes (delq 'total-strokes attributes))
975 (when (and (memq '->ideograph attributes)
976 (setq value (get-char-attribute char '->ideograph)))
977 (insert (format "(->ideograph\t%s)%s"
978 (mapconcat (lambda (code)
979 (cond ((symbolp code)
982 (format "#x%04X" code))
985 line-breaking code))))
988 (setq attributes (delq '->ideograph attributes))
990 ;; (when (and (memq '->decomposition attributes)
991 ;; (setq value (get-char-attribute char '->decomposition)))
992 ;; (insert (format "(->decomposition\t%s)%s"
993 ;; (mapconcat (lambda (code)
994 ;; (cond ((symbolp code)
995 ;; (symbol-name code))
996 ;; ((characterp code)
998 ;; (format "%S" code)
1003 ;; (format "#x%04X" code))
1005 ;; (format "%s%S" line-breaking code))))
1008 ;; (setq attributes (delq '->decomposition attributes))
1010 (if (equal (get-char-attribute char '->titlecase)
1011 (get-char-attribute char '->uppercase))
1012 (setq attributes (delq '->titlecase attributes)))
1013 (when (and (memq '->mojikyo attributes)
1014 (setq value (get-char-attribute char '->mojikyo)))
1015 (insert (format "(->mojikyo\t\t. %06d)\t; %c%s"
1016 value (decode-char 'mojikyo value)
1018 (setq attributes (delq '->mojikyo attributes))
1020 (when (and (memq 'hanyu-dazidian-vol attributes)
1021 (setq value (get-char-attribute char 'hanyu-dazidian-vol)))
1022 (insert (format "(hanyu-dazidian-vol . %d)%s"
1023 value line-breaking))
1024 (setq attributes (delq 'hanyu-dazidian-vol attributes))
1026 (when (and (memq 'hanyu-dazidian-page attributes)
1027 (setq value (get-char-attribute char 'hanyu-dazidian-page)))
1028 (insert (format "(hanyu-dazidian-page . %d)%s"
1029 value line-breaking))
1030 (setq attributes (delq 'hanyu-dazidian-page attributes))
1032 (when (and (memq 'hanyu-dazidian-char attributes)
1033 (setq value (get-char-attribute char 'hanyu-dazidian-char)))
1034 (insert (format "(hanyu-dazidian-char . %d)%s"
1035 value line-breaking))
1036 (setq attributes (delq 'hanyu-dazidian-char attributes))
1039 (dolist (ignored '(composition
1040 ->denotational <-subsumptive ->ucs-unified
1041 ->ideographic-component-forms))
1042 (setq attributes (delq ignored attributes))))
1044 (setq name (car attributes))
1045 (if (setq value (get-char-attribute char name))
1046 (cond ((setq ret (find-charset name))
1047 (setq name (charset-name ret))
1048 (if (and (not (memq name dest-ccss))
1050 (setq value (get-char-attribute char name))
1051 (setq dest-ccss (cons name dest-ccss))))
1052 (char-db-insert-ccs-feature name value line-breaking))
1054 ((string-match "^=>ucs@" (symbol-name name))
1055 (insert (format "(%-18s . #x%04X)\t; %c%s"
1056 name value (decode-char '=ucs value)
1059 ((eq name 'jisx0208-1978/4X)
1060 (insert (format "(%-18s . #x%04X)%s"
1066 (not (eq name '->subsumptive))
1067 (not (eq name '->uppercase))
1068 (not (eq name '->lowercase))
1069 (not (eq name '->titlecase))
1070 (not (eq name '->canonical))
1071 (not (eq name '->Bopomofo))
1072 (not (eq name '->mistakable))
1073 (not (eq name '->ideographic-variants))
1074 (null (get-char-attribute
1075 char (intern (format "%s*sources" name))))
1076 (not (string-match "\\*sources$" (symbol-name name)))
1077 (null (get-char-attribute
1078 char (intern (format "%s*note" name))))
1079 (not (string-match "\\*note$" (symbol-name name)))
1080 (or (eq name '<-identical)
1081 (eq name '<-uppercase)
1082 (eq name '<-lowercase)
1083 (eq name '<-titlecase)
1084 (eq name '<-canonical)
1085 (eq name '<-ideographic-variants)
1086 ;; (eq name '<-synonyms)
1087 (string-match "^<-synonyms" (symbol-name name))
1088 (eq name '<-mistakable)
1089 (when (string-match "^->" (symbol-name name))
1091 ((string-match "^->fullwidth" (symbol-name name))
1092 (not (and (consp value)
1093 (characterp (car value))
1095 (car value) '=ucs 'defined-only)))
1100 ((or (eq name 'ideographic-structure)
1101 (eq name 'ideographic-combination)
1102 (eq name 'ideographic-)
1103 (eq name '=decomposition)
1104 (string-match "^=>decomposition" (symbol-name name))
1105 (string-match "^\\(->\\|<-\\)[^*]*$" (symbol-name name))
1106 (string-match "^\\(->\\|<-\\)[^*]*\\*sources$"
1109 (char-db-insert-relation-feature char name value
1112 ((memq name '(ideograph=
1113 original-ideograph-of
1114 ancient-ideograph-of
1117 ;; simplified-ideograph-of
1118 ideographic-variants
1119 ;; ideographic-different-form-of
1121 (insert (format "(%-18s%s " name line-breaking))
1122 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1124 (while (consp value)
1125 (setq cell (car value))
1126 (if (and (consp cell)
1131 (char-db-insert-alist cell readable)
1132 (setq separator lbs))
1135 (insert (prin1-to-string cell))
1136 (setq separator " "))
1137 (setq value (cdr value)))
1139 (insert line-breaking))
1141 (insert (format "(%-18s " name))
1142 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1144 (while (consp value)
1145 (setq cell (car value))
1146 (if (and (consp cell)
1148 (setq ret (condition-case nil
1156 (setq key (car (car rest)))
1157 (if (find-charset key)
1158 (setq cal (cons key cal))
1159 (setq al (cons key al)))
1160 (setq rest (cdr rest)))
1163 (insert-char-attributes ret
1166 (setq separator lbs))
1167 (setq ret (prin1-to-string cell))
1169 (if (< (+ (current-column)
1176 (setq separator " "))
1177 (setq value (cdr value)))
1179 (insert line-breaking))
1181 (insert (format "(%-18s" name))
1182 (setq ret (prin1-to-string value))
1183 (unless (< (+ (current-column)
1187 (insert line-breaking))
1188 (insert " . " ret ")" line-breaking)
1189 ;; (insert (format "(%-18s . %S)%s"
1194 (setq attributes (cdr attributes)))
1197 (defun insert-char-data (char &optional readable
1200 (narrow-to-region (point)(point))
1201 (insert "(define-char
1203 (insert-char-attributes char readable attributes)
1205 (goto-char (point-min))
1206 (while (re-search-forward "[ \t]+$" nil t)
1209 (goto-char (point-min))
1210 (while (re-search-forward "[ \t][ \t][ \t]*" nil t)
1211 (let ((column (current-column))
1212 (indent-tabs-mode t))
1213 (delete-region (match-beginning 0) (point))
1214 (indent-to column)))
1215 (goto-char (point-max))
1216 ;; (tabify (point-min)(point-max))
1219 (defun insert-char-data-with-variant (char &optional printable
1221 script excluded-script)
1222 (insert-char-data char printable)
1223 (let ((variants (char-variants char))
1226 (setq variants (sort variants #'<))
1227 (setq rest variants)
1228 (setq variants (cons char variants))
1230 (setq variant (car rest))
1231 (unless (get-char-attribute variant '<-subsumptive)
1232 (if (and (or (null script)
1233 (null (setq vs (get-char-attribute variant 'script)))
1235 (or (null excluded-script)
1236 (null (setq vs (get-char-attribute variant 'script)))
1237 (not (memq excluded-script vs))))
1238 (unless (and no-ucs-unified (get-char-attribute variant '=ucs))
1239 (insert-char-data variant printable)
1240 (if (setq ret (char-variants variant))
1242 (or (memq (car ret) variants)
1243 ;; (get-char-attribute (car ret) '<-subsumptive)
1244 (setq rest (nconc rest (list (car ret)))))
1245 (setq ret (cdr ret)))))))
1246 (setq rest (cdr rest)))))
1248 (defun insert-char-range-data (min max &optional script excluded-script)
1251 (while (<= code max)
1252 (setq char (decode-char '=ucs code))
1253 (if (encode-char char '=ucs 'defined-only)
1254 (insert-char-data-with-variant char nil 'no-ucs-unified
1255 script excluded-script))
1256 (setq code (1+ code)))))
1258 (defun write-char-range-data-to-file (min max file
1259 &optional script excluded-script)
1260 (let ((coding-system-for-write char-db-file-coding-system))
1262 (insert (format ";; -*- coding: %s -*-\n"
1263 char-db-file-coding-system))
1264 (insert-char-range-data min max script excluded-script)
1265 (write-region (point-min)(point-max) file))))
1267 (defvar what-character-original-window-configuration)
1270 (defun what-char-definition (char)
1271 (interactive (list (char-after)))
1272 (let ((buf (get-buffer-create "*Character Description*"))
1273 (the-buf (current-buffer))
1274 (win-conf (current-window-configuration)))
1276 (make-local-variable 'what-character-original-window-configuration)
1277 (setq what-character-original-window-configuration win-conf)
1278 (setq buffer-read-only nil)
1282 (insert-char-data-with-variant char 'printable)
1283 (unless (char-attribute-alist char)
1284 (insert (format ";; = %c\n"
1285 (let* ((rest (split-char char))
1289 (setq code (logior (lsh code 8)
1291 (decode-char ccs code)))))
1292 ;; (char-db-update-comment)
1293 (set-buffer-modified-p nil)
1294 (view-mode the-buf (lambda (buf)
1295 (set-window-configuration
1296 what-character-original-window-configuration)
1298 (goto-char (point-min)))
1300 (set-window-configuration
1301 what-character-original-window-configuration)
1302 (signal (car err) (cdr err)))))))
1304 (provide 'char-db-util)
1306 ;;; char-db-util.el ends here