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
193 ;;; @ char-db formatters
196 (defun char-db-make-char-spec (char)
198 (cond ((characterp char)
199 (cond ((and (setq ret (encode-char char '=ucs 'defined-only))
200 (not (and (<= #xE000 ret)(<= ret #xF8FF))))
201 (setq char-spec (list (cons '=ucs ret)))
202 (cond ((setq ret (get-char-attribute char 'name))
203 (setq char-spec (cons (cons 'name ret) char-spec))
205 ((setq ret (get-char-attribute char 'name*))
206 (setq char-spec (cons (cons 'name* ret) char-spec))
211 (let ((rest char-db-coded-charset-priority-list)
214 (setq ccs (charset-name
215 (find-charset (car rest))))
217 (encode-char char ccs
219 (throw 'tag (cons ccs ret)))
220 (setq rest (cdr rest))))))
221 (setq char-spec (list ret))
222 (dolist (ccs (delq (car ret) (charset-list)))
223 (if (and (or (charset-iso-final-char ccs)
230 (string-match "=ucs@" (symbol-name ccs)))
231 (setq ccs (charset-name ccs))
232 (null (assq ccs char-spec))
233 (setq ret (encode-char char ccs 'defined-only)))
234 (setq char-spec (cons (cons ccs ret) char-spec))))
236 (setq char-spec (split-char char)))
237 (cond ((setq ret (get-char-attribute char 'name))
238 (setq char-spec (cons (cons 'name ret) char-spec))
240 ((setq ret (get-char-attribute char 'name*))
241 (setq char-spec (cons (cons 'name* ret) char-spec))
244 ((setq ret (get-char-attribute
245 char 'ideographic-combination))
247 (cons (cons 'ideographic-combination ret)
254 (defun char-db-insert-char-spec (char &optional readable column
257 (setq column (current-column)))
258 (let (char-spec temp-char)
259 (setq char-spec (char-db-make-char-spec char))
260 (unless (or (characterp char) ; char
262 (setq char (find-char char-spec))
264 ;; define temporary character
265 ;; Current implementation is dirty.
266 (setq temp-char (define-char (cons '(ideograph-daikanwa . 0)
268 (remove-char-attribute temp-char 'ideograph-daikanwa)
269 (setq char temp-char))
270 (insert-char-attributes char
272 (union (mapcar #'car char-spec)
275 ;; undefine temporary character
276 ;; Current implementation is dirty.
277 (setq char-spec (char-attribute-alist temp-char))
279 (remove-char-attribute temp-char (car (car char-spec)))
280 (setq char-spec (cdr char-spec))))))
282 (defun char-db-insert-alist (alist &optional readable column)
284 (setq column (current-column)))
286 (concat "\n" (make-string (1+ column) ?\ )))
290 lbs cell rest separator)
293 (setq name (car (car alist))
294 value (cdr (car alist)))
295 (cond ((eq name 'char)
297 (if (setq ret (condition-case nil
305 (setq key (car (car value)))
306 ;; (if (find-charset key)
307 ;; (setq cal (cons key cal))
308 (setq al (cons key al))
310 (setq value (cdr value)))
311 (insert-char-attributes ret
315 (insert (prin1-to-string value)))
317 (insert line-breaking))
319 (insert (format "(%-18s " name))
320 (setq lbs (concat "\n" (make-string (current-column) ?\ )))
322 (setq cell (car value))
323 (if (and (consp cell)
325 (setq ret (condition-case nil
335 (setq key (car (car rest)))
336 ;; (if (find-charset key)
337 ;; (setq cal (cons key cal))
338 (setq al (cons key al))
340 (setq rest (cdr rest)))
343 (insert-char-attributes ret
347 (setq separator lbs))
350 (insert (prin1-to-string cell))
351 (setq separator " "))
352 (setq value (cdr value)))
354 (insert line-breaking))
356 (insert (format "(%-18s . %S)%s"
359 (setq alist (cdr alist))))
362 (defun char-db-insert-char-reference (plist &optional readable column)
364 (setq column (current-column)))
366 (concat "\n" (make-string (1+ column) ?\ )))
371 (setq name (pop plist))
372 (setq value (pop plist))
373 (cond ((eq name :char)
376 (cond ((numberp value)
377 (setq value (decode-char '=ucs value)))
379 ;; (setq value (or (find-char value)
382 (char-db-insert-char-spec value readable)
383 (insert line-breaking)
386 (insert (format "%s%s\t%d ; %c%s"
389 (ideographic-radical value)
393 (insert (format "%s%s\t%S" separator name value))
394 (setq separator line-breaking)))
398 (defun char-db-decode-isolated-char (ccs code-point)
401 (cond ((eq ccs 'arabic-iso8859-6)
402 (decode-char ccs code-point))
403 ((and (memq ccs '(=gt-pj-1
414 (setq ret (decode-char ccs code-point))
415 (setq ret (encode-char ret '=gt 'defined-only)))
416 (decode-builtin-char '=gt ret))
418 (decode-builtin-char ccs code-point))))
419 (cond ((and (<= 0 (char-int ret))
420 (<= (char-int ret) #x1F))
421 (decode-char '=ucs (+ #x2400 (char-int ret))))
422 ((= (char-int ret) #x7F)
426 (defvar char-db-convert-obsolete-format t)
428 (defun char-db-insert-ccs-feature (name value line-breaking)
431 (cond ((memq name '(=shinjigen
433 =shinjigen@rev =shinjigen/+p@rev))
434 "(%-18s . %04d)\t; %c")
435 ((eq name '=shinjigen@1ed/24pr)
436 "(%-18s . %04d)\t; %c")
437 ((or (memq name '(=daikanwa
438 =daikanwa@rev1 =daikanwa@rev2
440 =gt =>>gt =>gt =gt-k =>>gt-k =cbeta
441 =zinbun-oracle =>zinbun-oracle))
442 (string-match "^=adobe-" (symbol-name name)))
443 "(%-18s . %05d)\t; %c")
445 "(%-18s . %06d)\t; %c")
446 ((>= (charset-dimension name) 2)
447 "(%-18s . #x%04X)\t; %c")
449 "(%-18s . #x%02X)\t; %c"))
451 (if (= (charset-iso-graphic-plane name) 1)
453 (cond ((= (charset-dimension name) 1)
455 ((= (charset-dimension name) 2)
457 ((= (charset-dimension name) 3)
461 (char-db-decode-isolated-char name value)))
462 (if (and (= (charset-chars name) 94)
463 (= (charset-dimension name) 2))
464 (insert (format " [%02d-%02d]"
465 (- (lsh value -8) 32)
466 (- (logand value 255) 32))))
467 (insert line-breaking))
469 (defun char-db-insert-relation-feature (char name value line-breaking
471 (insert (format "(%-18s%s " name line-breaking))
472 (let ((lbs (concat "\n" (make-string (current-column) ?\ )))
473 separator cell sources required-features
476 (setq cell (car value))
478 (setq cell (decode-char '=ucs cell)))
480 ((eq name '->subsumptive)
481 (when (or (not (some (lambda (atr)
482 (get-char-attribute cell atr))
483 char-db-ignored-attributes))
485 (encode-char cell ccs 'defined-only))
489 (let ((char-db-ignored-attributes
491 char-db-ignored-attributes)))
492 (insert-char-attributes cell readable))
493 (setq separator lbs))
498 char (intern (format "%s*sources" name))))
499 (setq required-features nil)
500 (dolist (source sources)
504 shinjigen shinjigen@1ed shinjigen@rev))
505 (setq required-features
506 (union required-features
516 (setq required-features
517 (union required-features
522 ((find-charset (setq ret (intern (format "=%s" source))))
523 (setq required-features
524 (cons ret required-features)))
525 (t (setq required-features
526 (cons source required-features)))))
527 (cond ((string-match "@JP" (symbol-name name))
528 (setq required-features
529 (union required-features
537 ((string-match "@CN" (symbol-name name))
538 (setq required-features
539 (union required-features
546 (insert (format "%S" cell))
547 (char-db-insert-char-spec cell readable
550 (setq separator lbs))
554 (if (consp (car cell))
555 (char-db-insert-char-spec cell readable)
556 (char-db-insert-char-reference cell readable))
557 (setq separator lbs))
561 (insert (prin1-to-string cell))
562 (setq separator " ")))
563 (setq value (cdr value)))
565 (insert line-breaking)))
567 (defun insert-char-attributes (char &optional readable attributes column)
569 (setq column (current-column)))
570 (let (name value ; has-long-ccs-name
574 (concat "\n" (make-string (1+ column) ?\ )))
575 lbs cell separator ret
577 dest-ccss ; sources required-features
582 (if (consp attributes)
584 (dolist (name attributes)
585 (unless (memq name char-db-ignored-attributes)
586 (if (find-charset name)
590 (dolist (name (char-attribute-list))
591 (unless (memq name char-db-ignored-attributes)
592 (if (find-charset name)
596 #'char-attribute-name<)))
598 (when (memq '<-subsumptive attributes)
600 (when (setq value (get-char-attribute char '<-subsumptive))
601 (char-db-insert-relation-feature char '<-subsumptive value
604 (setq attributes (delq '<-subsumptive attributes)))
605 (when (and (memq '<-denotational attributes)
606 (setq value (get-char-attribute char '<-denotational)))
607 (char-db-insert-relation-feature char '<-denotational value
610 (setq attributes (delq '<-denotational attributes)))
611 (when (and (memq 'name attributes)
612 (setq value (get-char-attribute char 'name)))
614 (if (> (+ (current-column) (length value)) 48)
617 value line-breaking))
618 (setq attributes (delq 'name attributes))
620 (when (and (memq 'name* attributes)
621 (setq value (get-char-attribute char 'name*)))
623 (if (> (+ (current-column) (length value)) 48)
626 value line-breaking))
627 (setq attributes (delq 'name* attributes))
629 (when (and (memq 'script attributes)
630 (setq value (get-char-attribute char 'script)))
631 (insert (format "(script\t\t%s)%s"
632 (mapconcat (function prin1-to-string)
635 (setq attributes (delq 'script attributes))
637 (dolist (name '(=>ucs =>ucs*))
638 (when (and (memq name attributes)
639 (setq value (get-char-attribute char name)))
640 (insert (format "(%-18s . #x%04X)\t; %c%s"
641 name value (decode-char '=ucs value)
643 (setq attributes (delq name attributes))))
644 (dolist (name '(=>ucs@gb =>ucs@cns =>ucs@jis =>ucs@ks =>ucs@big5))
645 (when (and (memq name attributes)
646 (setq value (get-char-attribute char name)))
647 (insert (format "(%-18s . #x%04X)\t; %c%s"
652 (symbol-name name) 2)))
655 (setq attributes (delq name attributes))
657 ;; (dolist (name '(=>daikanwa))
658 ;; (when (and (memq name attributes)
659 ;; (setq value (get-char-attribute char name)))
661 ;; (if (integerp value)
662 ;; (format "(%-18s . %05d)\t; %c%s"
663 ;; name value (decode-char '=daikanwa value)
665 ;; (format "(%-18s %s)\t; %c%s"
667 ;; (mapconcat (function prin1-to-string)
669 ;; (char-representative-of-daikanwa char)
671 ;; (setq attributes (delq name attributes))))
672 (when (and (memq 'general-category attributes)
673 (setq value (get-char-attribute char 'general-category)))
675 "(general-category\t%s) ; %s%s"
676 (mapconcat (lambda (cell)
679 (cond ((rassoc value unidata-normative-category-alist)
680 "Normative Category")
681 ((rassoc value unidata-informative-category-alist)
682 "Informative Category")
686 (setq attributes (delq 'general-category attributes))
688 (when (and (memq 'bidi-category attributes)
689 (setq value (get-char-attribute char 'bidi-category)))
690 (insert (format "(bidi-category\t. %S)%s"
693 (setq attributes (delq 'bidi-category attributes))
695 (unless (or (not (memq 'mirrored attributes))
696 (eq (setq value (get-char-attribute char 'mirrored 'empty))
698 (insert (format "(mirrored\t\t. %S)%s"
701 (setq attributes (delq 'mirrored attributes))
704 ((and (memq 'decimal-digit-value attributes)
705 (setq value (get-char-attribute char 'decimal-digit-value)))
706 (insert (format "(decimal-digit-value . %S)%s"
709 (setq attributes (delq 'decimal-digit-value attributes))
710 (when (and (memq 'digit-value attributes)
711 (setq value (get-char-attribute char 'digit-value)))
712 (insert (format "(digit-value\t . %S)%s"
715 (setq attributes (delq 'digit-value attributes))
717 (when (and (memq 'numeric-value attributes)
718 (setq value (get-char-attribute char 'numeric-value)))
719 (insert (format "(numeric-value\t . %S)%s"
722 (setq attributes (delq 'numeric-value attributes))
726 (when (and (memq 'digit-value attributes)
727 (setq value (get-char-attribute char 'digit-value)))
728 (insert (format "(digit-value\t. %S)%s"
731 (setq attributes (delq 'digit-value attributes))
733 (when (and (memq 'numeric-value attributes)
734 (setq value (get-char-attribute char 'numeric-value)))
735 (insert (format "(numeric-value\t. %S)%s"
738 (setq attributes (delq 'numeric-value attributes))
740 (when (and (memq 'iso-10646-comment attributes)
741 (setq value (get-char-attribute char 'iso-10646-comment)))
742 (insert (format "(iso-10646-comment\t. %S)%s"
745 (setq attributes (delq 'iso-10646-comment attributes))
747 (when (and (memq 'morohashi-daikanwa attributes)
748 (setq value (get-char-attribute char 'morohashi-daikanwa)))
749 (insert (format "(morohashi-daikanwa\t%s)%s"
750 (mapconcat (function prin1-to-string) value " ")
752 (setq attributes (delq 'morohashi-daikanwa attributes))
756 (when (and (memq 'ideographic-radical attributes)
757 (setq value (get-char-attribute char 'ideographic-radical)))
759 (insert (format "(ideographic-radical . %S)\t; %c%s"
761 (ideographic-radical radical)
763 (setq attributes (delq 'ideographic-radical attributes))
765 (when (and (memq 'shuowen-radical attributes)
766 (setq value (get-char-attribute char 'shuowen-radical)))
767 (insert (format "(shuowen-radical\t. %S)\t; %c%s"
769 (shuowen-radical value)
771 (setq attributes (delq 'shuowen-radical attributes))
776 char-db-feature-domains
778 (dolist (feature (char-attribute-list))
779 (setq feature (symbol-name feature))
781 "\\(radical\\|strokes\\)@\\([^@*]+\\)\\(\\*\\|$\\)"
783 (setq domain (intern (match-string 2 feature)))
784 (unless (memq domain dest)
785 (setq dest (cons domain dest)))))
786 (sort dest #'string<))))
787 (setq key (intern (format "%s@%s" 'ideographic-radical domain)))
788 (when (and (memq key attributes)
789 (setq value (get-char-attribute char key)))
791 (insert (format "(%s . %S)\t; %c%s"
794 (ideographic-radical radical)
796 (setq attributes (delq key attributes))
798 (setq key (intern (format "%s@%s" 'ideographic-strokes domain)))
799 (when (and (memq key attributes)
800 (setq value (get-char-attribute char key)))
802 (insert (format "(%s . %S)%s"
806 (setq attributes (delq key attributes))
808 (setq key (intern (format "%s@%s" 'total-strokes domain)))
809 (when (and (memq key attributes)
810 (setq value (get-char-attribute char key)))
811 (insert (format "(%s . %S)%s"
815 (setq attributes (delq key attributes))
817 (dolist (feature '(ideographic-radical
820 (setq key (intern (format "%s@%s*sources" feature domain)))
821 (when (and (memq key attributes)
822 (setq value (get-char-attribute char key)))
823 (insert (format "(%s%s" key line-breaking))
825 (insert (format " %s" cell)))
827 (insert line-breaking)
828 (setq attributes (delq key attributes))
831 (when (and (memq 'ideographic-strokes attributes)
832 (setq value (get-char-attribute char 'ideographic-strokes)))
834 (insert (format "(ideographic-strokes . %S)%s"
837 (setq attributes (delq 'ideographic-strokes attributes))
839 (when (and (memq 'kangxi-radical attributes)
840 (setq value (get-char-attribute char 'kangxi-radical)))
841 (unless (eq value radical)
842 (insert (format "(kangxi-radical\t . %S)\t; %c%s"
844 (ideographic-radical value)
847 (setq radical value)))
848 (setq attributes (delq 'kangxi-radical attributes))
850 (when (and (memq 'kangxi-strokes attributes)
851 (setq value (get-char-attribute char 'kangxi-strokes)))
852 (unless (eq value strokes)
853 (insert (format "(kangxi-strokes\t . %S)%s"
857 (setq strokes value)))
858 (setq attributes (delq 'kangxi-strokes attributes))
860 (when (and (memq 'japanese-radical attributes)
861 (setq value (get-char-attribute char 'japanese-radical)))
862 (unless (eq value radical)
863 (insert (format "(japanese-radical\t . %S)\t; %c%s"
865 (ideographic-radical value)
868 (setq radical value)))
869 (setq attributes (delq 'japanese-radical attributes))
871 (when (and (memq 'japanese-strokes attributes)
872 (setq value (get-char-attribute char 'japanese-strokes)))
873 (unless (eq value strokes)
874 (insert (format "(japanese-strokes\t . %S)%s"
878 (setq strokes value)))
879 (setq attributes (delq 'japanese-strokes attributes))
881 (when (and (memq 'cns-radical attributes)
882 (setq value (get-char-attribute char 'cns-radical)))
883 (insert (format "(cns-radical\t . %S)\t; %c%s"
885 (ideographic-radical value)
887 (setq attributes (delq 'cns-radical attributes))
889 (when (and (memq 'cns-strokes attributes)
890 (setq value (get-char-attribute char 'cns-strokes)))
891 (unless (eq value strokes)
892 (insert (format "(cns-strokes\t . %S)%s"
896 (setq strokes value)))
897 (setq attributes (delq 'cns-strokes attributes))
899 (when (and (memq 'shinjigen-1-radical attributes)
900 (setq value (get-char-attribute char 'shinjigen-1-radical)))
901 (unless (eq value radical)
902 (insert (format "(shinjigen-1-radical . %S)\t; %c%s"
904 (ideographic-radical value)
907 (setq radical value)))
908 (setq attributes (delq 'shinjigen-1-radical attributes))
910 (when (and (memq 'ideographic- attributes)
911 (setq value (get-char-attribute char 'ideographic-)))
912 (insert "(ideographic- ")
913 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
916 (setq cell (car value))
918 (setq cell (decode-char '=ucs cell)))
919 (cond ((characterp cell)
923 (insert (format "%S" cell))
924 (char-db-insert-char-spec cell readable))
925 (setq separator lbs))
929 (if (consp (car cell))
930 (char-db-insert-char-spec cell readable)
931 (char-db-insert-char-reference cell readable))
932 (setq separator lbs))
936 (insert (prin1-to-string cell))
937 (setq separator " ")))
938 (setq value (cdr value)))
940 (insert line-breaking)
941 (setq attributes (delq 'ideographic- attributes)))
942 (when (and (memq 'total-strokes attributes)
943 (setq value (get-char-attribute char 'total-strokes)))
944 (insert (format "(total-strokes . %S)%s"
947 (setq attributes (delq 'total-strokes attributes))
949 (when (and (memq '->ideograph attributes)
950 (setq value (get-char-attribute char '->ideograph)))
951 (insert (format "(->ideograph\t%s)%s"
952 (mapconcat (lambda (code)
953 (cond ((symbolp code)
956 (format "#x%04X" code))
959 line-breaking code))))
962 (setq attributes (delq '->ideograph attributes))
964 ;; (when (and (memq '->decomposition attributes)
965 ;; (setq value (get-char-attribute char '->decomposition)))
966 ;; (insert (format "(->decomposition\t%s)%s"
967 ;; (mapconcat (lambda (code)
968 ;; (cond ((symbolp code)
969 ;; (symbol-name code))
970 ;; ((characterp code)
972 ;; (format "%S" code)
977 ;; (format "#x%04X" code))
979 ;; (format "%s%S" line-breaking code))))
982 ;; (setq attributes (delq '->decomposition attributes))
984 (if (equal (get-char-attribute char '->titlecase)
985 (get-char-attribute char '->uppercase))
986 (setq attributes (delq '->titlecase attributes)))
987 (when (and (memq '->mojikyo attributes)
988 (setq value (get-char-attribute char '->mojikyo)))
989 (insert (format "(->mojikyo\t\t. %06d)\t; %c%s"
990 value (decode-char 'mojikyo value)
992 (setq attributes (delq '->mojikyo attributes))
994 (when (and (memq 'hanyu-dazidian-vol attributes)
995 (setq value (get-char-attribute char 'hanyu-dazidian-vol)))
996 (insert (format "(hanyu-dazidian-vol . %d)%s"
997 value line-breaking))
998 (setq attributes (delq 'hanyu-dazidian-vol attributes))
1000 (when (and (memq 'hanyu-dazidian-page attributes)
1001 (setq value (get-char-attribute char 'hanyu-dazidian-page)))
1002 (insert (format "(hanyu-dazidian-page . %d)%s"
1003 value line-breaking))
1004 (setq attributes (delq 'hanyu-dazidian-page attributes))
1006 (when (and (memq 'hanyu-dazidian-char attributes)
1007 (setq value (get-char-attribute char 'hanyu-dazidian-char)))
1008 (insert (format "(hanyu-dazidian-char . %d)%s"
1009 value line-breaking))
1010 (setq attributes (delq 'hanyu-dazidian-char attributes))
1013 (dolist (ignored '(composition
1014 ->denotational <-subsumptive ->ucs-unified
1015 ->ideographic-component-forms))
1016 (setq attributes (delq ignored attributes))))
1018 (setq name (car attributes))
1019 (if (setq value (get-char-attribute char name))
1020 (cond ((setq ret (find-charset name))
1021 (setq name (charset-name ret))
1022 (if (and (not (memq name dest-ccss))
1024 (setq value (get-char-attribute char name))
1025 (setq dest-ccss (cons name dest-ccss))))
1026 (char-db-insert-ccs-feature name value line-breaking))
1028 ((string-match "^=>ucs@" (symbol-name name))
1029 (insert (format "(%-18s . #x%04X)\t; %c%s"
1030 name value (decode-char '=ucs value)
1033 ((eq name 'jisx0208-1978/4X)
1034 (insert (format "(%-18s . #x%04X)%s"
1040 (not (eq name '->subsumptive))
1041 (not (eq name '->uppercase))
1042 (not (eq name '->lowercase))
1043 (not (eq name '->titlecase))
1044 (not (eq name '->canonical))
1045 (not (eq name '->Bopomofo))
1046 (not (eq name '->mistakable))
1047 (not (eq name '->ideographic-variants))
1048 (null (get-char-attribute
1049 char (intern (format "%s*sources" name))))
1050 (not (string-match "\\*sources$" (symbol-name name)))
1051 (null (get-char-attribute
1052 char (intern (format "%s*note" name))))
1053 (not (string-match "\\*note$" (symbol-name name)))
1054 (or (eq name '<-identical)
1055 (eq name '<-uppercase)
1056 (eq name '<-lowercase)
1057 (eq name '<-titlecase)
1058 (eq name '<-canonical)
1059 (eq name '<-ideographic-variants)
1060 ;; (eq name '<-synonyms)
1061 (string-match "^<-synonyms" (symbol-name name))
1062 (eq name '<-mistakable)
1063 (when (string-match "^->" (symbol-name name))
1065 ((string-match "^->fullwidth" (symbol-name name))
1066 (not (and (consp value)
1067 (characterp (car value))
1069 (car value) '=ucs 'defined-only)))
1074 ((or (eq name 'ideographic-structure)
1075 (eq name 'ideographic-combination)
1076 (eq name 'ideographic-)
1077 (eq name '=decomposition)
1078 (string-match "^=>decomposition" (symbol-name name))
1079 (string-match "^\\(->\\|<-\\)[^*]*$" (symbol-name name))
1080 (string-match "^\\(->\\|<-\\)[^*]*\\*sources$"
1083 (char-db-insert-relation-feature char name value
1086 ((memq name '(ideograph=
1087 original-ideograph-of
1088 ancient-ideograph-of
1091 ;; simplified-ideograph-of
1092 ideographic-variants
1093 ;; ideographic-different-form-of
1095 (insert (format "(%-18s%s " name line-breaking))
1096 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1098 (while (consp value)
1099 (setq cell (car value))
1100 (if (and (consp cell)
1105 (char-db-insert-alist cell readable)
1106 (setq separator lbs))
1109 (insert (prin1-to-string cell))
1110 (setq separator " "))
1111 (setq value (cdr value)))
1113 (insert line-breaking))
1115 (insert (format "(%-18s " name))
1116 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1118 (while (consp value)
1119 (setq cell (car value))
1120 (if (and (consp cell)
1122 (setq ret (condition-case nil
1130 (setq key (car (car rest)))
1131 (if (find-charset key)
1132 (setq cal (cons key cal))
1133 (setq al (cons key al)))
1134 (setq rest (cdr rest)))
1137 (insert-char-attributes ret
1140 (setq separator lbs))
1141 (setq ret (prin1-to-string cell))
1143 (if (< (+ (current-column)
1150 (setq separator " "))
1151 (setq value (cdr value)))
1153 (insert line-breaking))
1155 (insert (format "(%-18s" name))
1156 (setq ret (prin1-to-string value))
1157 (unless (< (+ (current-column)
1161 (insert line-breaking))
1162 (insert " . " ret ")" line-breaking)
1163 ;; (insert (format "(%-18s . %S)%s"
1168 (setq attributes (cdr attributes)))
1171 (defun insert-char-data (char &optional readable
1174 (narrow-to-region (point)(point))
1175 (insert "(define-char
1177 (insert-char-attributes char readable attributes)
1179 (goto-char (point-min))
1180 (while (re-search-forward "[ \t]+$" nil t)
1183 (goto-char (point-min))
1184 (while (re-search-forward "[ \t][ \t][ \t]*" nil t)
1185 (let ((column (current-column))
1186 (indent-tabs-mode t))
1187 (delete-region (match-beginning 0) (point))
1188 (indent-to column)))
1189 (goto-char (point-max))
1190 ;; (tabify (point-min)(point-max))
1193 (defun insert-char-data-with-variant (char &optional printable
1195 script excluded-script)
1196 (insert-char-data char printable)
1197 (let ((variants (char-variants char))
1200 (setq variants (sort variants #'<))
1201 (setq rest variants)
1202 (setq variants (cons char variants))
1204 (setq variant (car rest))
1205 (unless (get-char-attribute variant '<-subsumptive)
1206 (if (and (or (null script)
1207 (null (setq vs (get-char-attribute variant 'script)))
1209 (or (null excluded-script)
1210 (null (setq vs (get-char-attribute variant 'script)))
1211 (not (memq excluded-script vs))))
1212 (unless (and no-ucs-unified (get-char-attribute variant '=ucs))
1213 (insert-char-data variant printable)
1214 (if (setq ret (char-variants variant))
1216 (or (memq (car ret) variants)
1217 ;; (get-char-attribute (car ret) '<-subsumptive)
1218 (setq rest (nconc rest (list (car ret)))))
1219 (setq ret (cdr ret)))))))
1220 (setq rest (cdr rest)))))
1222 (defun insert-char-range-data (min max &optional script excluded-script)
1225 (while (<= code max)
1226 (setq char (decode-char '=ucs code))
1227 (if (encode-char char '=ucs 'defined-only)
1228 (insert-char-data-with-variant char nil 'no-ucs-unified
1229 script excluded-script))
1230 (setq code (1+ code)))))
1232 (defun write-char-range-data-to-file (min max file
1233 &optional script excluded-script)
1234 (let ((coding-system-for-write char-db-file-coding-system))
1236 (insert (format ";; -*- coding: %s -*-\n"
1237 char-db-file-coding-system))
1238 (insert-char-range-data min max script excluded-script)
1239 (write-region (point-min)(point-max) file))))
1241 (defvar what-character-original-window-configuration)
1244 (defun what-char-definition (char)
1245 (interactive (list (char-after)))
1246 (let ((buf (get-buffer-create "*Character Description*"))
1247 (the-buf (current-buffer))
1248 (win-conf (current-window-configuration)))
1250 (make-local-variable 'what-character-original-window-configuration)
1251 (setq what-character-original-window-configuration win-conf)
1252 (setq buffer-read-only nil)
1256 (insert-char-data-with-variant char 'printable)
1257 (unless (char-attribute-alist char)
1258 (insert (format ";; = %c\n"
1259 (let* ((rest (split-char char))
1263 (setq code (logior (lsh code 8)
1265 (decode-char ccs code)))))
1266 ;; (char-db-update-comment)
1267 (set-buffer-modified-p nil)
1268 (view-mode the-buf (lambda (buf)
1269 (set-window-configuration
1270 what-character-original-window-configuration)
1272 (goto-char (point-min)))
1274 (set-window-configuration
1275 what-character-original-window-configuration)
1276 (signal (car err) (cdr err)))))))
1282 (provide 'char-db-util)
1284 ;;; char-db-util.el ends here