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, 2010 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.
29 (require 'ideograph-subr)
31 (defconst unidata-normative-category-alist
32 '(("Lu" letter uppercase)
33 ("Ll" letter lowercase)
34 ("Lt" letter titlecase)
35 ("Mn" mark non-spacing)
36 ("Mc" mark spacing-combining)
38 ("Nd" number decimal-digit)
41 ("Zs" separator space)
43 ("Zp" separator paragraph)
46 ("Cs" other surrogate)
47 ("Co" other private-use)
48 ("Cn" other not-assigned)))
50 (defconst unidata-informative-category-alist
51 '(("Lm" letter modifier)
53 ("Pc" punctuation connector)
54 ("Pd" punctuation dash)
55 ("Ps" punctuation open)
56 ("Pe" punctuation close)
57 ("Pi" punctuation initial-quote)
58 ("Pf" punctuation final-quote)
59 ("Po" punctuation other)
61 ("Sc" symbol currency)
62 ("Sk" symbol modifier)
66 (defconst shuowen-radicals
67 [?一 ?上 ?示 ?三 ?王 ?玉 ?玨 ?气 ?士 ?丨 ; 010
68 ?屮 ?艸 ?蓐 ?茻 ?小 ?八 ?釆 ?半 ?牛 ?犛 ; 020
69 ?告 ?口 ?凵 ?吅 ?哭 ?走 ?止 ?癶 ?步 ?此 ; 030
70 ?正 ?是 ?辵 ?彳 ?廴 ?㢟 ?行 ?齒 ?牙 ?足 ; 040
71 ?疋 ?品 ?龠 ?冊 ?㗊 ?舌 ?干 ?谷 ?只 ?㕯 ; 050
72 ?句 ?丩 ?古 ?十 ?卅 ?言 ?誩 ?音 ?䇂 ?丵 ; 060
73 ?菐 ?𠬞 ?廾 ?共 ?異 ?舁 ?𦥑 ?䢅 ?爨 ?革 ; 070
74 ?鬲 ?䰜 ?爪 ?𠃨 ?鬥 ?又 ?𠂇 ?㕜 ?支 ?𦘒 ; 080
75 ?聿 ?畫 ?隶 ?臤 ?臣 ?殳 ?殺 ?𠘧 ?寸 ?皮 ; 090
76 ?㼱 ?攴 ?敎 ?卜 ?用 ?爻 ?㸚 ?𥄎 ?目 ?䀠 ; 100
77 ?眉 ?盾 ?自 ?白 ?鼻 ?皕 ?習 ?羽 ?隹 ?奞 ; 110
78 ?萑 ?𦫳 ?苜 ?羊 ?羴 ?瞿 ?雔 ?雥 ?鳥 ?烏 ; 120
79 ?𠦒 ?冓 ?幺 ?𢆶 ?叀 ?玄 ?予 ?放 ?𠬪 ?𣦼 ; 130
80 ?歺 ?死 ?冎 ?骨 ?肉 ?筋 ?刀 ?刃 ?㓞 ?丰 ; 140
81 ?耒 ?𧢲 ?竹 ?箕 ?丌 ?左 ?工 ?㠭 ?巫 ?甘 ; 150
82 ?曰 ?乃 ?丂 ?可 ?兮 ?号 ?亏 ?旨 ?喜 ?壴 ; 160
83 ?鼓 ?豈 ?豆 ?豊 ?豐 ?䖒 ?虍 ?虎 ?虤 ?皿 ; 170
84 ?𠙴 ?去 ?血 ?丶 ?丹 ?青 ?井 ?皀 ?鬯 ?食 ; 180
85 ?亼 ?會 ?倉 ?入 ?缶 ?矢 ?高 ?冂 ?𩫏 ?京 ; 190
86 ?亯 ?𣆪 ?畗 ?㐭 ?嗇 ?來 ?麥 ?夊 ?舛 ?䑞 ; 200
87 ?韋 ?弟 ?夂 ?久 ?桀 ?木 ?東 ?林 ?才 ?叒 ; 210
88 ?之 ?帀 ?出 ?𣎵 ?生 ?乇 ?𠂹 ?𠌶 ?華 ?𥝌 ; 220
89 ?稽 ?巢 ?桼 ?束 ?㯻 ?囗 ?員 ?貝 ?邑 ?𨛜 ; 230
90 ?日 ?旦 ?倝 ?㫃 ?冥 ?晶 ?月 ?有 ?明 ?囧 ; 240
91 ?夕 ?多 ?毌 ?𢎘 ?𣐺 ?卣 ?齊 ?朿 ?片 ?鼎 ; 250
92 ?克 ?彔 ?禾 ?秝 ?黍 ?香 ?米 ?毇 ?臼 ?凶 ; 260
93 ?𣎳 ?林 ?麻 ?尗 ?耑 ?韭 ?瓜 ?瓠 ?宀 ?宮 ; 270
94 ?呂 ?穴 ?㝱 ?𤕫 ?冖 ?𠔼 ?冃 ?㒳 ?网 ?襾 ; 280
95 ?巾 ?巿 ?帛 ?白 ?㡀 ?黹 ?人 ?𠤎 ?匕 ?从 ; 290
98 (defun shuowen-radical (number)
99 (aref shuowen-radicals (1- number)))
101 (defvar char-db-file-coding-system 'utf-8-mcs-er)
103 (defvar char-db-ignored-attributes '(ideographic-products))
105 (defvar char-db-coded-charset-priority-list
199 ;;; @ char-db formatters
202 (defun char-db-make-char-spec (char)
204 (cond ((characterp char)
205 (cond ((and (setq ret (encode-char char '=ucs 'defined-only))
206 (not (and (<= #xE000 ret)(<= ret #xF8FF))))
207 (setq char-spec (list (cons '=ucs ret)))
208 (cond ((setq ret (get-char-attribute char 'name))
209 (setq char-spec (cons (cons 'name ret) char-spec))
211 ((setq ret (get-char-attribute char 'name*))
212 (setq char-spec (cons (cons 'name* ret) char-spec))
217 (let ((rest char-db-coded-charset-priority-list)
220 (setq ccs (charset-name
221 (find-charset (car rest))))
223 (encode-char char ccs
225 (throw 'tag (cons ccs ret)))
226 (setq rest (cdr rest))))))
227 (setq char-spec (list ret))
228 (dolist (ccs (delq (car ret) (charset-list)))
229 (if (and (or (charset-iso-final-char ccs)
236 (string-match "=ucs@" (symbol-name ccs)))
237 (setq ccs (charset-name ccs))
238 (null (assq ccs char-spec))
239 (setq ret (encode-char char ccs 'defined-only)))
240 (setq char-spec (cons (cons ccs ret) char-spec))))
242 (setq char-spec (split-char char)))
243 (cond ((setq ret (get-char-attribute char 'name))
244 (setq char-spec (cons (cons 'name ret) char-spec))
246 ((setq ret (get-char-attribute char 'name*))
247 (setq char-spec (cons (cons 'name* ret) char-spec))
250 ((setq ret (get-char-attribute
251 char 'ideographic-combination))
253 (cons (cons 'ideographic-combination ret)
260 (defun char-db-insert-char-spec (char &optional readable column
263 (setq column (current-column)))
264 (let (char-spec temp-char)
265 (setq char-spec (char-db-make-char-spec char))
266 (unless (or (characterp char) ; char
268 (setq char (find-char char-spec))
270 ;; define temporary character
271 ;; Current implementation is dirty.
272 (setq temp-char (define-char (cons '(ideograph-daikanwa . 0)
274 (remove-char-attribute temp-char 'ideograph-daikanwa)
275 (setq char temp-char))
276 (insert-char-attributes char
278 (union (mapcar #'car char-spec)
281 ;; undefine temporary character
282 ;; Current implementation is dirty.
283 (setq char-spec (char-attribute-alist temp-char))
285 (remove-char-attribute temp-char (car (car char-spec)))
286 (setq char-spec (cdr char-spec))))))
288 (defun char-db-insert-alist (alist &optional readable column)
290 (setq column (current-column)))
292 (concat "\n" (make-string (1+ column) ?\ )))
296 lbs cell rest separator)
299 (setq name (car (car alist))
300 value (cdr (car alist)))
301 (cond ((eq name 'char)
303 (if (setq ret (condition-case nil
311 (setq key (car (car value)))
312 ;; (if (find-charset key)
313 ;; (setq cal (cons key cal))
314 (setq al (cons key al))
316 (setq value (cdr value)))
317 (insert-char-attributes ret
321 (insert (prin1-to-string value)))
323 (insert line-breaking))
325 (insert (format "(%-18s " name))
326 (setq lbs (concat "\n" (make-string (current-column) ?\ )))
328 (setq cell (car value))
329 (if (and (consp cell)
331 (setq ret (condition-case nil
341 (setq key (car (car rest)))
342 ;; (if (find-charset key)
343 ;; (setq cal (cons key cal))
344 (setq al (cons key al))
346 (setq rest (cdr rest)))
349 (insert-char-attributes ret
353 (setq separator lbs))
356 (insert (prin1-to-string cell))
357 (setq separator " "))
358 (setq value (cdr value)))
360 (insert line-breaking))
362 (insert (format "(%-18s . %S)%s"
365 (setq alist (cdr alist))))
368 (defun char-db-insert-char-reference (plist &optional readable column)
370 (setq column (current-column)))
372 (concat "\n" (make-string (1+ column) ?\ )))
377 (setq name (pop plist))
378 (setq value (pop plist))
379 (cond ((eq name :char)
382 (cond ((numberp value)
383 (setq value (decode-char '=ucs value)))
385 ;; (setq value (or (find-char value)
388 (char-db-insert-char-spec value readable)
389 (insert line-breaking)
392 (insert (format "%s%s\t%d ; %c%s"
395 (ideographic-radical value)
399 (insert (format "%s%s\t%S" separator name value))
400 (setq separator line-breaking)))
404 (defun char-db-decode-isolated-char (ccs code-point)
407 (cond ((eq ccs 'arabic-iso8859-6)
408 (decode-char ccs code-point))
409 ((and (memq ccs '(=gt-pj-1
420 (setq ret (decode-char ccs code-point))
421 (setq ret (encode-char ret '=gt 'defined-only)))
422 (decode-builtin-char '=gt ret))
424 (decode-builtin-char ccs code-point))))
425 (cond ((and (<= 0 (char-int ret))
426 (<= (char-int ret) #x1F))
427 (decode-char '=ucs (+ #x2400 (char-int ret))))
428 ((= (char-int ret) #x7F)
432 (defvar char-db-convert-obsolete-format t)
434 (defun char-db-insert-ccs-feature (name value line-breaking)
437 (cond ((memq name '(=shinjigen
439 =shinjigen@rev =shinjigen/+p@rev))
440 "(%-18s . %04d)\t; %c")
441 ((eq name '=shinjigen@1ed/24pr)
442 "(%-18s . %04d)\t; %c")
443 ((or (memq name '(=daikanwa
444 =daikanwa@rev1 =daikanwa@rev2
445 =>>daikanwa =>daikanwa
446 =gt =>>gt =>gt =gt-k =>>gt-k =cbeta
447 =zinbun-oracle =>zinbun-oracle))
448 (string-match "^=adobe-" (symbol-name name)))
449 "(%-18s . %05d)\t; %c")
451 "(%-18s . %06d)\t; %c")
452 ((>= (charset-dimension name) 2)
453 "(%-18s . #x%04X)\t; %c")
455 "(%-18s . #x%02X)\t; %c"))
457 (if (= (charset-iso-graphic-plane name) 1)
459 (cond ((= (charset-dimension name) 1)
461 ((= (charset-dimension name) 2)
463 ((= (charset-dimension name) 3)
467 (char-db-decode-isolated-char name value)))
468 (if (and (= (charset-chars name) 94)
469 (= (charset-dimension name) 2))
470 (insert (format " [%02d-%02d]"
471 (- (lsh value -8) 32)
472 (- (logand value 255) 32))))
473 (insert line-breaking))
475 (defun char-db-insert-relation-feature (char name value line-breaking
477 (insert (format "(%-18s%s " name line-breaking))
478 (let ((lbs (concat "\n" (make-string (current-column) ?\ )))
479 separator cell sources required-features
482 (setq cell (car value))
484 (setq cell (decode-char '=ucs cell)))
486 ((eq name '->subsumptive)
487 (when (or (not (some (lambda (atr)
488 (get-char-attribute cell atr))
489 char-db-ignored-attributes))
491 (encode-char cell ccs 'defined-only))
495 (let ((char-db-ignored-attributes
497 char-db-ignored-attributes)))
498 (insert-char-attributes cell readable))
499 (setq separator lbs))
504 char (intern (format "%s*sources" name))))
505 (setq required-features nil)
506 (dolist (source sources)
510 shinjigen shinjigen@1ed shinjigen@rev))
511 (setq required-features
512 (union required-features
523 (setq required-features
524 (union required-features
529 ((find-charset (setq ret (intern (format "=%s" source))))
530 (setq required-features
531 (cons ret required-features)))
532 (t (setq required-features
533 (cons source required-features)))))
534 (cond ((string-match "@JP" (symbol-name name))
535 (setq required-features
536 (union required-features
544 ((string-match "@CN" (symbol-name name))
545 (setq required-features
546 (union required-features
553 (insert (format "%S" cell))
554 (char-db-insert-char-spec cell readable
557 (setq separator lbs))
561 (if (consp (car cell))
562 (char-db-insert-char-spec cell readable)
563 (char-db-insert-char-reference cell readable))
564 (setq separator lbs))
568 (insert (prin1-to-string cell))
569 (setq separator " ")))
570 (setq value (cdr value)))
572 (insert line-breaking)))
574 (defun insert-char-attributes (char &optional readable attributes column)
576 (setq column (current-column)))
577 (let (name value ; has-long-ccs-name
581 (concat "\n" (make-string (1+ column) ?\ )))
582 lbs cell separator ret
584 dest-ccss ; sources required-features
589 (if (consp attributes)
591 (dolist (name attributes)
592 (unless (memq name char-db-ignored-attributes)
593 (if (find-charset name)
597 (dolist (name (char-attribute-list))
598 (unless (memq name char-db-ignored-attributes)
599 (if (find-charset name)
603 #'char-attribute-name<)))
605 (when (memq '<-subsumptive attributes)
607 (when (setq value (get-char-attribute char '<-subsumptive))
608 (char-db-insert-relation-feature char '<-subsumptive value
611 (setq attributes (delq '<-subsumptive attributes)))
612 (when (and (memq '<-denotational attributes)
613 (setq value (get-char-attribute char '<-denotational)))
614 (char-db-insert-relation-feature char '<-denotational value
617 (setq attributes (delq '<-denotational attributes)))
618 (when (and (memq 'name attributes)
619 (setq value (get-char-attribute char 'name)))
621 (if (> (+ (current-column) (length value)) 48)
624 value line-breaking))
625 (setq attributes (delq 'name attributes))
627 (when (and (memq 'name* attributes)
628 (setq value (get-char-attribute char 'name*)))
630 (if (> (+ (current-column) (length value)) 48)
633 value line-breaking))
634 (setq attributes (delq 'name* attributes))
636 (when (and (memq 'script attributes)
637 (setq value (get-char-attribute char 'script)))
638 (insert (format "(script\t\t%s)%s"
639 (mapconcat (function prin1-to-string)
642 (setq attributes (delq 'script attributes))
644 (dolist (name '(=>ucs =>ucs*))
645 (when (and (memq name attributes)
646 (setq value (get-char-attribute char name)))
647 (insert (format "(%-18s . #x%04X)\t; %c%s"
648 name value (decode-char '=ucs value)
650 (setq attributes (delq name attributes))))
651 (dolist (name '(=>ucs@gb =>ucs@ks =>ucs@big5))
652 (when (and (memq name attributes)
653 (setq value (get-char-attribute char name)))
654 (insert (format "(%-18s . #x%04X)\t; %c%s"
659 (symbol-name name) 2)))
662 (setq attributes (delq name attributes))
664 ;; (dolist (name '(=>daikanwa))
665 ;; (when (and (memq name attributes)
666 ;; (setq value (get-char-attribute char name)))
668 ;; (if (integerp value)
669 ;; (format "(%-18s . %05d)\t; %c%s"
670 ;; name value (decode-char '=daikanwa value)
672 ;; (format "(%-18s %s)\t; %c%s"
674 ;; (mapconcat (function prin1-to-string)
676 ;; (char-representative-of-daikanwa char)
678 ;; (setq attributes (delq name attributes))))
679 (when (and (memq 'general-category attributes)
680 (setq value (get-char-attribute char 'general-category)))
682 "(general-category\t%s) ; %s%s"
683 (mapconcat (lambda (cell)
686 (cond ((rassoc value unidata-normative-category-alist)
687 "Normative Category")
688 ((rassoc value unidata-informative-category-alist)
689 "Informative Category")
693 (setq attributes (delq 'general-category attributes))
695 (when (and (memq 'bidi-category attributes)
696 (setq value (get-char-attribute char 'bidi-category)))
697 (insert (format "(bidi-category\t. %S)%s"
700 (setq attributes (delq 'bidi-category attributes))
702 (unless (or (not (memq 'mirrored attributes))
703 (eq (setq value (get-char-attribute char 'mirrored 'empty))
705 (insert (format "(mirrored\t\t. %S)%s"
708 (setq attributes (delq 'mirrored attributes))
711 ((and (memq 'decimal-digit-value attributes)
712 (setq value (get-char-attribute char 'decimal-digit-value)))
713 (insert (format "(decimal-digit-value . %S)%s"
716 (setq attributes (delq 'decimal-digit-value attributes))
717 (when (and (memq 'digit-value attributes)
718 (setq value (get-char-attribute char 'digit-value)))
719 (insert (format "(digit-value\t . %S)%s"
722 (setq attributes (delq 'digit-value attributes))
724 (when (and (memq 'numeric-value attributes)
725 (setq value (get-char-attribute char 'numeric-value)))
726 (insert (format "(numeric-value\t . %S)%s"
729 (setq attributes (delq 'numeric-value attributes))
733 (when (and (memq 'digit-value attributes)
734 (setq value (get-char-attribute char 'digit-value)))
735 (insert (format "(digit-value\t. %S)%s"
738 (setq attributes (delq 'digit-value attributes))
740 (when (and (memq 'numeric-value attributes)
741 (setq value (get-char-attribute char 'numeric-value)))
742 (insert (format "(numeric-value\t. %S)%s"
745 (setq attributes (delq 'numeric-value attributes))
747 (when (and (memq 'iso-10646-comment attributes)
748 (setq value (get-char-attribute char 'iso-10646-comment)))
749 (insert (format "(iso-10646-comment\t. %S)%s"
752 (setq attributes (delq 'iso-10646-comment attributes))
754 (when (and (memq 'morohashi-daikanwa attributes)
755 (setq value (get-char-attribute char 'morohashi-daikanwa)))
756 (insert (format "(morohashi-daikanwa\t%s)%s"
757 (mapconcat (function prin1-to-string) value " ")
759 (setq attributes (delq 'morohashi-daikanwa attributes))
763 (when (and (memq 'ideographic-radical attributes)
764 (setq value (get-char-attribute char 'ideographic-radical)))
766 (insert (format "(ideographic-radical . %S)\t; %c%s"
768 (ideographic-radical radical)
770 (setq attributes (delq 'ideographic-radical attributes))
772 (when (and (memq 'shuowen-radical attributes)
773 (setq value (get-char-attribute char 'shuowen-radical)))
774 (insert (format "(shuowen-radical\t. %S)\t; %c%s"
776 (shuowen-radical value)
778 (setq attributes (delq 'shuowen-radical attributes))
783 char-db-feature-domains
785 (dolist (feature (char-attribute-list))
786 (setq feature (symbol-name feature))
788 "\\(radical\\|strokes\\)@\\([^@*]+\\)\\(\\*\\|$\\)"
790 (setq domain (intern (match-string 2 feature)))
791 (unless (memq domain dest)
792 (setq dest (cons domain dest)))))
793 (sort dest #'string<))))
794 (setq key (intern (format "%s@%s" 'ideographic-radical domain)))
795 (when (and (memq key attributes)
796 (setq value (get-char-attribute char key)))
798 (insert (format "(%s . %S)\t; %c%s"
801 (ideographic-radical radical)
803 (setq attributes (delq key attributes))
805 (setq key (intern (format "%s@%s" 'ideographic-strokes domain)))
806 (when (and (memq key attributes)
807 (setq value (get-char-attribute char key)))
809 (insert (format "(%s . %S)%s"
813 (setq attributes (delq key attributes))
815 (setq key (intern (format "%s@%s" 'total-strokes domain)))
816 (when (and (memq key attributes)
817 (setq value (get-char-attribute char key)))
818 (insert (format "(%s . %S)%s"
822 (setq attributes (delq key attributes))
824 (dolist (feature '(ideographic-radical
827 (setq key (intern (format "%s@%s*sources" feature domain)))
828 (when (and (memq key attributes)
829 (setq value (get-char-attribute char key)))
830 (insert (format "(%s%s" key line-breaking))
832 (insert (format " %s" cell)))
834 (insert line-breaking)
835 (setq attributes (delq key attributes))
838 (when (and (memq 'ideographic-strokes attributes)
839 (setq value (get-char-attribute char 'ideographic-strokes)))
841 (insert (format "(ideographic-strokes . %S)%s"
844 (setq attributes (delq 'ideographic-strokes attributes))
846 (when (and (memq 'kangxi-radical attributes)
847 (setq value (get-char-attribute char 'kangxi-radical)))
848 (unless (eq value radical)
849 (insert (format "(kangxi-radical\t . %S)\t; %c%s"
851 (ideographic-radical value)
854 (setq radical value)))
855 (setq attributes (delq 'kangxi-radical attributes))
857 (when (and (memq 'kangxi-strokes attributes)
858 (setq value (get-char-attribute char 'kangxi-strokes)))
859 (unless (eq value strokes)
860 (insert (format "(kangxi-strokes\t . %S)%s"
864 (setq strokes value)))
865 (setq attributes (delq 'kangxi-strokes attributes))
867 (when (and (memq 'japanese-radical attributes)
868 (setq value (get-char-attribute char 'japanese-radical)))
869 (unless (eq value radical)
870 (insert (format "(japanese-radical\t . %S)\t; %c%s"
872 (ideographic-radical value)
875 (setq radical value)))
876 (setq attributes (delq 'japanese-radical attributes))
878 (when (and (memq 'japanese-strokes attributes)
879 (setq value (get-char-attribute char 'japanese-strokes)))
880 (unless (eq value strokes)
881 (insert (format "(japanese-strokes\t . %S)%s"
885 (setq strokes value)))
886 (setq attributes (delq 'japanese-strokes attributes))
888 (when (and (memq 'cns-radical attributes)
889 (setq value (get-char-attribute char 'cns-radical)))
890 (insert (format "(cns-radical\t . %S)\t; %c%s"
892 (ideographic-radical value)
894 (setq attributes (delq 'cns-radical attributes))
896 (when (and (memq 'cns-strokes attributes)
897 (setq value (get-char-attribute char 'cns-strokes)))
898 (unless (eq value strokes)
899 (insert (format "(cns-strokes\t . %S)%s"
903 (setq strokes value)))
904 (setq attributes (delq 'cns-strokes attributes))
906 (when (and (memq 'shinjigen-1-radical attributes)
907 (setq value (get-char-attribute char 'shinjigen-1-radical)))
908 (unless (eq value radical)
909 (insert (format "(shinjigen-1-radical . %S)\t; %c%s"
911 (ideographic-radical value)
914 (setq radical value)))
915 (setq attributes (delq 'shinjigen-1-radical attributes))
917 (when (and (memq 'ideographic- attributes)
918 (setq value (get-char-attribute char 'ideographic-)))
919 (insert "(ideographic- ")
920 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
923 (setq cell (car value))
925 (setq cell (decode-char '=ucs cell)))
926 (cond ((characterp cell)
930 (insert (format "%S" cell))
931 (char-db-insert-char-spec cell readable))
932 (setq separator lbs))
936 (if (consp (car cell))
937 (char-db-insert-char-spec cell readable)
938 (char-db-insert-char-reference cell readable))
939 (setq separator lbs))
943 (insert (prin1-to-string cell))
944 (setq separator " ")))
945 (setq value (cdr value)))
947 (insert line-breaking)
948 (setq attributes (delq 'ideographic- attributes)))
949 (when (and (memq 'total-strokes attributes)
950 (setq value (get-char-attribute char 'total-strokes)))
951 (insert (format "(total-strokes . %S)%s"
954 (setq attributes (delq 'total-strokes attributes))
956 (when (and (memq '->ideograph attributes)
957 (setq value (get-char-attribute char '->ideograph)))
958 (insert (format "(->ideograph\t%s)%s"
959 (mapconcat (lambda (code)
960 (cond ((symbolp code)
963 (format "#x%04X" code))
966 line-breaking code))))
969 (setq attributes (delq '->ideograph attributes))
971 ;; (when (and (memq '->decomposition attributes)
972 ;; (setq value (get-char-attribute char '->decomposition)))
973 ;; (insert (format "(->decomposition\t%s)%s"
974 ;; (mapconcat (lambda (code)
975 ;; (cond ((symbolp code)
976 ;; (symbol-name code))
977 ;; ((characterp code)
979 ;; (format "%S" code)
984 ;; (format "#x%04X" code))
986 ;; (format "%s%S" line-breaking code))))
989 ;; (setq attributes (delq '->decomposition attributes))
991 (if (equal (get-char-attribute char '->titlecase)
992 (get-char-attribute char '->uppercase))
993 (setq attributes (delq '->titlecase attributes)))
994 (when (and (memq '->mojikyo attributes)
995 (setq value (get-char-attribute char '->mojikyo)))
996 (insert (format "(->mojikyo\t\t. %06d)\t; %c%s"
997 value (decode-char 'mojikyo value)
999 (setq attributes (delq '->mojikyo attributes))
1001 (when (and (memq 'hanyu-dazidian-vol attributes)
1002 (setq value (get-char-attribute char 'hanyu-dazidian-vol)))
1003 (insert (format "(hanyu-dazidian-vol . %d)%s"
1004 value line-breaking))
1005 (setq attributes (delq 'hanyu-dazidian-vol attributes))
1007 (when (and (memq 'hanyu-dazidian-page attributes)
1008 (setq value (get-char-attribute char 'hanyu-dazidian-page)))
1009 (insert (format "(hanyu-dazidian-page . %d)%s"
1010 value line-breaking))
1011 (setq attributes (delq 'hanyu-dazidian-page attributes))
1013 (when (and (memq 'hanyu-dazidian-char attributes)
1014 (setq value (get-char-attribute char 'hanyu-dazidian-char)))
1015 (insert (format "(hanyu-dazidian-char . %d)%s"
1016 value line-breaking))
1017 (setq attributes (delq 'hanyu-dazidian-char attributes))
1020 (dolist (ignored '(composition
1021 ->denotational <-subsumptive ->ucs-unified
1022 ->ideographic-component-forms))
1023 (setq attributes (delq ignored attributes))))
1025 (setq name (car attributes))
1026 (if (setq value (get-char-attribute char name))
1027 (cond ((setq ret (find-charset name))
1028 (setq name (charset-name ret))
1029 (if (and (not (memq name dest-ccss))
1031 (setq value (get-char-attribute char name))
1032 (setq dest-ccss (cons name dest-ccss))))
1033 (char-db-insert-ccs-feature name value line-breaking))
1035 ((string-match "^=>ucs@" (symbol-name name))
1036 (insert (format "(%-18s . #x%04X)\t; %c%s"
1037 name value (decode-char '=ucs value)
1040 ((eq name 'jisx0208-1978/4X)
1041 (insert (format "(%-18s . #x%04X)%s"
1047 (not (eq name '->subsumptive))
1048 (not (eq name '->uppercase))
1049 (not (eq name '->lowercase))
1050 (not (eq name '->titlecase))
1051 (not (eq name '->canonical))
1052 (not (eq name '->Bopomofo))
1053 (not (eq name '->mistakable))
1054 (not (eq name '->ideographic-variants))
1055 (null (get-char-attribute
1056 char (intern (format "%s*sources" name))))
1057 (not (string-match "\\*sources$" (symbol-name name)))
1058 (null (get-char-attribute
1059 char (intern (format "%s*note" name))))
1060 (not (string-match "\\*note$" (symbol-name name)))
1061 (or (eq name '<-identical)
1062 (eq name '<-uppercase)
1063 (eq name '<-lowercase)
1064 (eq name '<-titlecase)
1065 (eq name '<-canonical)
1066 (eq name '<-ideographic-variants)
1067 ;; (eq name '<-synonyms)
1068 (string-match "^<-synonyms" (symbol-name name))
1069 (eq name '<-mistakable)
1070 (when (string-match "^->" (symbol-name name))
1072 ((string-match "^->fullwidth" (symbol-name name))
1073 (not (and (consp value)
1074 (characterp (car value))
1076 (car value) '=ucs 'defined-only)))
1081 ((or (eq name 'ideographic-structure)
1082 (eq name 'ideographic-combination)
1083 (eq name 'ideographic-)
1084 (eq name '=decomposition)
1085 (string-match "^=>decomposition" (symbol-name name))
1086 (string-match "^\\(->\\|<-\\)[^*]*$" (symbol-name name))
1087 (string-match "^\\(->\\|<-\\)[^*]*\\*sources$"
1090 (char-db-insert-relation-feature char name value
1093 ((memq name '(ideograph=
1094 original-ideograph-of
1095 ancient-ideograph-of
1098 ;; simplified-ideograph-of
1099 ideographic-variants
1100 ;; ideographic-different-form-of
1102 (insert (format "(%-18s%s " name line-breaking))
1103 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1105 (while (consp value)
1106 (setq cell (car value))
1107 (if (and (consp cell)
1112 (char-db-insert-alist cell readable)
1113 (setq separator lbs))
1116 (insert (prin1-to-string cell))
1117 (setq separator " "))
1118 (setq value (cdr value)))
1120 (insert line-breaking))
1122 (insert (format "(%-18s " name))
1123 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1125 (while (consp value)
1126 (setq cell (car value))
1127 (if (and (consp cell)
1129 (setq ret (condition-case nil
1137 (setq key (car (car rest)))
1138 (if (find-charset key)
1139 (setq cal (cons key cal))
1140 (setq al (cons key al)))
1141 (setq rest (cdr rest)))
1144 (insert-char-attributes ret
1147 (setq separator lbs))
1148 (setq ret (prin1-to-string cell))
1150 (if (< (+ (current-column)
1157 (setq separator " "))
1158 (setq value (cdr value)))
1160 (insert line-breaking))
1162 (insert (format "(%-18s" name))
1163 (setq ret (prin1-to-string value))
1164 (unless (< (+ (current-column)
1168 (insert line-breaking))
1169 (insert " . " ret ")" line-breaking)
1170 ;; (insert (format "(%-18s . %S)%s"
1175 (setq attributes (cdr attributes)))
1178 (defun insert-char-data (char &optional readable
1181 (narrow-to-region (point)(point))
1182 (insert "(define-char
1184 (insert-char-attributes char readable attributes)
1186 (goto-char (point-min))
1187 (while (re-search-forward "[ \t]+$" nil t)
1190 (goto-char (point-min))
1191 (while (re-search-forward "[ \t][ \t][ \t]*" nil t)
1192 (let ((column (current-column))
1193 (indent-tabs-mode t))
1194 (delete-region (match-beginning 0) (point))
1195 (indent-to column)))
1196 (goto-char (point-max))
1197 ;; (tabify (point-min)(point-max))
1200 (defun insert-char-data-with-variant (char &optional printable
1202 script excluded-script)
1203 (insert-char-data char printable)
1204 (let ((variants (char-variants char))
1207 (setq variants (sort variants #'<))
1208 (setq rest variants)
1209 (setq variants (cons char variants))
1211 (setq variant (car rest))
1212 (unless (get-char-attribute variant '<-subsumptive)
1213 (if (and (or (null script)
1214 (null (setq vs (get-char-attribute variant 'script)))
1216 (or (null excluded-script)
1217 (null (setq vs (get-char-attribute variant 'script)))
1218 (not (memq excluded-script vs))))
1219 (unless (and no-ucs-unified (get-char-attribute variant '=ucs))
1220 (insert-char-data variant printable)
1221 (if (setq ret (char-variants variant))
1223 (or (memq (car ret) variants)
1224 ;; (get-char-attribute (car ret) '<-subsumptive)
1225 (setq rest (nconc rest (list (car ret)))))
1226 (setq ret (cdr ret)))))))
1227 (setq rest (cdr rest)))))
1229 (defun insert-char-range-data (min max &optional script excluded-script)
1232 (while (<= code max)
1233 (setq char (decode-char '=ucs code))
1234 (if (encode-char char '=ucs 'defined-only)
1235 (insert-char-data-with-variant char nil 'no-ucs-unified
1236 script excluded-script))
1237 (setq code (1+ code)))))
1239 (defun write-char-range-data-to-file (min max file
1240 &optional script excluded-script)
1241 (let ((coding-system-for-write char-db-file-coding-system))
1243 (insert (format ";; -*- coding: %s -*-\n"
1244 char-db-file-coding-system))
1245 (insert-char-range-data min max script excluded-script)
1246 (write-region (point-min)(point-max) file))))
1248 (defvar what-character-original-window-configuration)
1251 (defun what-char-definition (char)
1252 (interactive (list (char-after)))
1253 (let ((buf (get-buffer-create "*Character Description*"))
1254 (the-buf (current-buffer))
1255 (win-conf (current-window-configuration)))
1257 (make-local-variable 'what-character-original-window-configuration)
1258 (setq what-character-original-window-configuration win-conf)
1259 (setq buffer-read-only nil)
1263 (insert-char-data-with-variant char 'printable)
1264 (unless (char-attribute-alist char)
1265 (insert (format ";; = %c\n"
1266 (let* ((rest (split-char char))
1270 (setq code (logior (lsh code 8)
1272 (decode-char ccs code)))))
1273 ;; (char-db-update-comment)
1274 (set-buffer-modified-p nil)
1275 (view-mode the-buf (lambda (buf)
1276 (set-window-configuration
1277 what-character-original-window-configuration)
1279 (goto-char (point-min)))
1281 (set-window-configuration
1282 what-character-original-window-configuration)
1283 (signal (car err) (cdr err)))))))
1289 (provide 'char-db-util)
1291 ;;; char-db-util.el ends here