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
195 ;;; @ char-db formatters
198 (defun char-db-make-char-spec (char)
200 (cond ((characterp char)
201 (cond ((and (setq ret (encode-char char '=ucs 'defined-only))
202 (not (and (<= #xE000 ret)(<= ret #xF8FF))))
203 (setq char-spec (list (cons '=ucs ret)))
204 (cond ((setq ret (get-char-attribute char 'name))
205 (setq char-spec (cons (cons 'name ret) char-spec))
207 ((setq ret (get-char-attribute char 'name*))
208 (setq char-spec (cons (cons 'name* ret) char-spec))
213 (let ((rest char-db-coded-charset-priority-list)
216 (setq ccs (charset-name
217 (find-charset (car rest))))
219 (encode-char char ccs
221 (throw 'tag (cons ccs ret)))
222 (setq rest (cdr rest))))))
223 (setq char-spec (list ret))
224 (dolist (ccs (delq (car ret) (charset-list)))
225 (if (and (or (charset-iso-final-char ccs)
232 (string-match "=ucs@" (symbol-name ccs)))
233 (setq ccs (charset-name ccs))
234 (null (assq ccs char-spec))
235 (setq ret (encode-char char ccs 'defined-only)))
236 (setq char-spec (cons (cons ccs ret) char-spec))))
238 (setq char-spec (split-char char)))
239 (cond ((setq ret (get-char-attribute char 'name))
240 (setq char-spec (cons (cons 'name ret) char-spec))
242 ((setq ret (get-char-attribute char 'name*))
243 (setq char-spec (cons (cons 'name* ret) char-spec))
246 ((setq ret (get-char-attribute
247 char 'ideographic-combination))
249 (cons (cons 'ideographic-combination ret)
256 (defun char-db-insert-char-spec (char &optional readable column
259 (setq column (current-column)))
260 (let (char-spec temp-char)
261 (setq char-spec (char-db-make-char-spec char))
262 (unless (or (characterp char) ; char
264 (setq char (find-char char-spec))
266 ;; define temporary character
267 ;; Current implementation is dirty.
268 (setq temp-char (define-char (cons '(ideograph-daikanwa . 0)
270 (remove-char-attribute temp-char 'ideograph-daikanwa)
271 (setq char temp-char))
272 (insert-char-attributes char
274 (union (mapcar #'car char-spec)
277 ;; undefine temporary character
278 ;; Current implementation is dirty.
279 (setq char-spec (char-attribute-alist temp-char))
281 (remove-char-attribute temp-char (car (car char-spec)))
282 (setq char-spec (cdr char-spec))))))
284 (defun char-db-insert-alist (alist &optional readable column)
286 (setq column (current-column)))
288 (concat "\n" (make-string (1+ column) ?\ )))
292 lbs cell rest separator)
295 (setq name (car (car alist))
296 value (cdr (car alist)))
297 (cond ((eq name 'char)
299 (if (setq ret (condition-case nil
307 (setq key (car (car value)))
308 ;; (if (find-charset key)
309 ;; (setq cal (cons key cal))
310 (setq al (cons key al))
312 (setq value (cdr value)))
313 (insert-char-attributes ret
317 (insert (prin1-to-string value)))
319 (insert line-breaking))
321 (insert (format "(%-18s " name))
322 (setq lbs (concat "\n" (make-string (current-column) ?\ )))
324 (setq cell (car value))
325 (if (and (consp cell)
327 (setq ret (condition-case nil
337 (setq key (car (car rest)))
338 ;; (if (find-charset key)
339 ;; (setq cal (cons key cal))
340 (setq al (cons key al))
342 (setq rest (cdr rest)))
345 (insert-char-attributes ret
349 (setq separator lbs))
352 (insert (prin1-to-string cell))
353 (setq separator " "))
354 (setq value (cdr value)))
356 (insert line-breaking))
358 (insert (format "(%-18s . %S)%s"
361 (setq alist (cdr alist))))
364 (defun char-db-insert-char-reference (plist &optional readable column)
366 (setq column (current-column)))
368 (concat "\n" (make-string (1+ column) ?\ )))
373 (setq name (pop plist))
374 (setq value (pop plist))
375 (cond ((eq name :char)
378 (cond ((numberp value)
379 (setq value (decode-char '=ucs value)))
381 ;; (setq value (or (find-char value)
384 (char-db-insert-char-spec value readable)
385 (insert line-breaking)
388 (insert (format "%s%s\t%d ; %c%s"
391 (ideographic-radical value)
395 (insert (format "%s%s\t%S" separator name value))
396 (setq separator line-breaking)))
400 (defun char-db-decode-isolated-char (ccs code-point)
403 (cond ((eq ccs 'arabic-iso8859-6)
404 (decode-char ccs code-point))
405 ((and (memq ccs '(=gt-pj-1
416 (setq ret (decode-char ccs code-point))
417 (setq ret (encode-char ret '=gt 'defined-only)))
418 (decode-builtin-char '=gt ret))
420 (decode-builtin-char ccs code-point))))
421 (cond ((and (<= 0 (char-int ret))
422 (<= (char-int ret) #x1F))
423 (decode-char '=ucs (+ #x2400 (char-int ret))))
424 ((= (char-int ret) #x7F)
428 (defvar char-db-convert-obsolete-format t)
430 (defun char-db-insert-ccs-feature (name value line-breaking)
433 (cond ((memq name '(=shinjigen
435 =shinjigen@rev =shinjigen/+p@rev))
436 "(%-18s . %04d)\t; %c")
437 ((eq name '=shinjigen@1ed/24pr)
438 "(%-18s . %04d)\t; %c")
439 ((or (memq name '(=daikanwa
440 =daikanwa@rev1 =daikanwa@rev2
441 =>>daikanwa =>daikanwa
442 =gt =>>gt =>gt =gt-k =>>gt-k =cbeta
443 =zinbun-oracle =>zinbun-oracle))
444 (string-match "^=adobe-" (symbol-name name)))
445 "(%-18s . %05d)\t; %c")
447 "(%-18s . %06d)\t; %c")
448 ((>= (charset-dimension name) 2)
449 "(%-18s . #x%04X)\t; %c")
451 "(%-18s . #x%02X)\t; %c"))
453 (if (= (charset-iso-graphic-plane name) 1)
455 (cond ((= (charset-dimension name) 1)
457 ((= (charset-dimension name) 2)
459 ((= (charset-dimension name) 3)
463 (char-db-decode-isolated-char name value)))
464 (if (and (= (charset-chars name) 94)
465 (= (charset-dimension name) 2))
466 (insert (format " [%02d-%02d]"
467 (- (lsh value -8) 32)
468 (- (logand value 255) 32))))
469 (insert line-breaking))
471 (defun char-db-insert-relation-feature (char name value line-breaking
473 (insert (format "(%-18s%s " name line-breaking))
474 (let ((lbs (concat "\n" (make-string (current-column) ?\ )))
475 separator cell sources required-features
478 (setq cell (car value))
480 (setq cell (decode-char '=ucs cell)))
482 ((eq name '->subsumptive)
483 (when (or (not (some (lambda (atr)
484 (get-char-attribute cell atr))
485 char-db-ignored-attributes))
487 (encode-char cell ccs 'defined-only))
491 (let ((char-db-ignored-attributes
493 char-db-ignored-attributes)))
494 (insert-char-attributes cell readable))
495 (setq separator lbs))
500 char (intern (format "%s*sources" name))))
501 (setq required-features nil)
502 (dolist (source sources)
506 shinjigen shinjigen@1ed shinjigen@rev))
507 (setq required-features
508 (union required-features
519 (setq required-features
520 (union required-features
525 ((find-charset (setq ret (intern (format "=%s" source))))
526 (setq required-features
527 (cons ret required-features)))
528 (t (setq required-features
529 (cons source required-features)))))
530 (cond ((string-match "@JP" (symbol-name name))
531 (setq required-features
532 (union required-features
540 ((string-match "@CN" (symbol-name name))
541 (setq required-features
542 (union required-features
549 (insert (format "%S" cell))
550 (char-db-insert-char-spec cell readable
553 (setq separator lbs))
557 (if (consp (car cell))
558 (char-db-insert-char-spec cell readable)
559 (char-db-insert-char-reference cell readable))
560 (setq separator lbs))
564 (insert (prin1-to-string cell))
565 (setq separator " ")))
566 (setq value (cdr value)))
568 (insert line-breaking)))
570 (defun insert-char-attributes (char &optional readable attributes column)
572 (setq column (current-column)))
573 (let (name value ; has-long-ccs-name
577 (concat "\n" (make-string (1+ column) ?\ )))
578 lbs cell separator ret
580 dest-ccss ; sources required-features
585 (if (consp attributes)
587 (dolist (name attributes)
588 (unless (memq name char-db-ignored-attributes)
589 (if (find-charset name)
593 (dolist (name (char-attribute-list))
594 (unless (memq name char-db-ignored-attributes)
595 (if (find-charset name)
599 #'char-attribute-name<)))
601 (when (memq '<-subsumptive attributes)
603 (when (setq value (get-char-attribute char '<-subsumptive))
604 (char-db-insert-relation-feature char '<-subsumptive value
607 (setq attributes (delq '<-subsumptive attributes)))
608 (when (and (memq '<-denotational attributes)
609 (setq value (get-char-attribute char '<-denotational)))
610 (char-db-insert-relation-feature char '<-denotational value
613 (setq attributes (delq '<-denotational attributes)))
614 (when (and (memq 'name attributes)
615 (setq value (get-char-attribute char 'name)))
617 (if (> (+ (current-column) (length value)) 48)
620 value line-breaking))
621 (setq attributes (delq 'name attributes))
623 (when (and (memq 'name* attributes)
624 (setq value (get-char-attribute char 'name*)))
626 (if (> (+ (current-column) (length value)) 48)
629 value line-breaking))
630 (setq attributes (delq 'name* attributes))
632 (when (and (memq 'script attributes)
633 (setq value (get-char-attribute char 'script)))
634 (insert (format "(script\t\t%s)%s"
635 (mapconcat (function prin1-to-string)
638 (setq attributes (delq 'script attributes))
640 (dolist (name '(=>ucs =>ucs*))
641 (when (and (memq name attributes)
642 (setq value (get-char-attribute char name)))
643 (insert (format "(%-18s . #x%04X)\t; %c%s"
644 name value (decode-char '=ucs value)
646 (setq attributes (delq name attributes))))
647 (dolist (name '(=>ucs@gb =>ucs@jis =>ucs@ks =>ucs@big5))
648 (when (and (memq name attributes)
649 (setq value (get-char-attribute char name)))
650 (insert (format "(%-18s . #x%04X)\t; %c%s"
655 (symbol-name name) 2)))
658 (setq attributes (delq name attributes))
660 ;; (dolist (name '(=>daikanwa))
661 ;; (when (and (memq name attributes)
662 ;; (setq value (get-char-attribute char name)))
664 ;; (if (integerp value)
665 ;; (format "(%-18s . %05d)\t; %c%s"
666 ;; name value (decode-char '=daikanwa value)
668 ;; (format "(%-18s %s)\t; %c%s"
670 ;; (mapconcat (function prin1-to-string)
672 ;; (char-representative-of-daikanwa char)
674 ;; (setq attributes (delq name attributes))))
675 (when (and (memq 'general-category attributes)
676 (setq value (get-char-attribute char 'general-category)))
678 "(general-category\t%s) ; %s%s"
679 (mapconcat (lambda (cell)
682 (cond ((rassoc value unidata-normative-category-alist)
683 "Normative Category")
684 ((rassoc value unidata-informative-category-alist)
685 "Informative Category")
689 (setq attributes (delq 'general-category attributes))
691 (when (and (memq 'bidi-category attributes)
692 (setq value (get-char-attribute char 'bidi-category)))
693 (insert (format "(bidi-category\t. %S)%s"
696 (setq attributes (delq 'bidi-category attributes))
698 (unless (or (not (memq 'mirrored attributes))
699 (eq (setq value (get-char-attribute char 'mirrored 'empty))
701 (insert (format "(mirrored\t\t. %S)%s"
704 (setq attributes (delq 'mirrored attributes))
707 ((and (memq 'decimal-digit-value attributes)
708 (setq value (get-char-attribute char 'decimal-digit-value)))
709 (insert (format "(decimal-digit-value . %S)%s"
712 (setq attributes (delq 'decimal-digit-value attributes))
713 (when (and (memq 'digit-value attributes)
714 (setq value (get-char-attribute char 'digit-value)))
715 (insert (format "(digit-value\t . %S)%s"
718 (setq attributes (delq 'digit-value attributes))
720 (when (and (memq 'numeric-value attributes)
721 (setq value (get-char-attribute char 'numeric-value)))
722 (insert (format "(numeric-value\t . %S)%s"
725 (setq attributes (delq 'numeric-value attributes))
729 (when (and (memq 'digit-value attributes)
730 (setq value (get-char-attribute char 'digit-value)))
731 (insert (format "(digit-value\t. %S)%s"
734 (setq attributes (delq 'digit-value attributes))
736 (when (and (memq 'numeric-value attributes)
737 (setq value (get-char-attribute char 'numeric-value)))
738 (insert (format "(numeric-value\t. %S)%s"
741 (setq attributes (delq 'numeric-value attributes))
743 (when (and (memq 'iso-10646-comment attributes)
744 (setq value (get-char-attribute char 'iso-10646-comment)))
745 (insert (format "(iso-10646-comment\t. %S)%s"
748 (setq attributes (delq 'iso-10646-comment attributes))
750 (when (and (memq 'morohashi-daikanwa attributes)
751 (setq value (get-char-attribute char 'morohashi-daikanwa)))
752 (insert (format "(morohashi-daikanwa\t%s)%s"
753 (mapconcat (function prin1-to-string) value " ")
755 (setq attributes (delq 'morohashi-daikanwa attributes))
759 (when (and (memq 'ideographic-radical attributes)
760 (setq value (get-char-attribute char 'ideographic-radical)))
762 (insert (format "(ideographic-radical . %S)\t; %c%s"
764 (ideographic-radical radical)
766 (setq attributes (delq 'ideographic-radical attributes))
768 (when (and (memq 'shuowen-radical attributes)
769 (setq value (get-char-attribute char 'shuowen-radical)))
770 (insert (format "(shuowen-radical\t. %S)\t; %c%s"
772 (shuowen-radical value)
774 (setq attributes (delq 'shuowen-radical attributes))
779 char-db-feature-domains
781 (dolist (feature (char-attribute-list))
782 (setq feature (symbol-name feature))
784 "\\(radical\\|strokes\\)@\\([^@*]+\\)\\(\\*\\|$\\)"
786 (setq domain (intern (match-string 2 feature)))
787 (unless (memq domain dest)
788 (setq dest (cons domain dest)))))
789 (sort dest #'string<))))
790 (setq key (intern (format "%s@%s" 'ideographic-radical domain)))
791 (when (and (memq key attributes)
792 (setq value (get-char-attribute char key)))
794 (insert (format "(%s . %S)\t; %c%s"
797 (ideographic-radical radical)
799 (setq attributes (delq key attributes))
801 (setq key (intern (format "%s@%s" 'ideographic-strokes domain)))
802 (when (and (memq key attributes)
803 (setq value (get-char-attribute char key)))
805 (insert (format "(%s . %S)%s"
809 (setq attributes (delq key attributes))
811 (setq key (intern (format "%s@%s" 'total-strokes domain)))
812 (when (and (memq key attributes)
813 (setq value (get-char-attribute char key)))
814 (insert (format "(%s . %S)%s"
818 (setq attributes (delq key attributes))
820 (dolist (feature '(ideographic-radical
823 (setq key (intern (format "%s@%s*sources" feature domain)))
824 (when (and (memq key attributes)
825 (setq value (get-char-attribute char key)))
826 (insert (format "(%s%s" key line-breaking))
828 (insert (format " %s" cell)))
830 (insert line-breaking)
831 (setq attributes (delq key attributes))
834 (when (and (memq 'ideographic-strokes attributes)
835 (setq value (get-char-attribute char 'ideographic-strokes)))
837 (insert (format "(ideographic-strokes . %S)%s"
840 (setq attributes (delq 'ideographic-strokes attributes))
842 (when (and (memq 'kangxi-radical attributes)
843 (setq value (get-char-attribute char 'kangxi-radical)))
844 (unless (eq value radical)
845 (insert (format "(kangxi-radical\t . %S)\t; %c%s"
847 (ideographic-radical value)
850 (setq radical value)))
851 (setq attributes (delq 'kangxi-radical attributes))
853 (when (and (memq 'kangxi-strokes attributes)
854 (setq value (get-char-attribute char 'kangxi-strokes)))
855 (unless (eq value strokes)
856 (insert (format "(kangxi-strokes\t . %S)%s"
860 (setq strokes value)))
861 (setq attributes (delq 'kangxi-strokes attributes))
863 (when (and (memq 'japanese-radical attributes)
864 (setq value (get-char-attribute char 'japanese-radical)))
865 (unless (eq value radical)
866 (insert (format "(japanese-radical\t . %S)\t; %c%s"
868 (ideographic-radical value)
871 (setq radical value)))
872 (setq attributes (delq 'japanese-radical attributes))
874 (when (and (memq 'japanese-strokes attributes)
875 (setq value (get-char-attribute char 'japanese-strokes)))
876 (unless (eq value strokes)
877 (insert (format "(japanese-strokes\t . %S)%s"
881 (setq strokes value)))
882 (setq attributes (delq 'japanese-strokes attributes))
884 (when (and (memq 'cns-radical attributes)
885 (setq value (get-char-attribute char 'cns-radical)))
886 (insert (format "(cns-radical\t . %S)\t; %c%s"
888 (ideographic-radical value)
890 (setq attributes (delq 'cns-radical attributes))
892 (when (and (memq 'cns-strokes attributes)
893 (setq value (get-char-attribute char 'cns-strokes)))
894 (unless (eq value strokes)
895 (insert (format "(cns-strokes\t . %S)%s"
899 (setq strokes value)))
900 (setq attributes (delq 'cns-strokes attributes))
902 (when (and (memq 'shinjigen-1-radical attributes)
903 (setq value (get-char-attribute char 'shinjigen-1-radical)))
904 (unless (eq value radical)
905 (insert (format "(shinjigen-1-radical . %S)\t; %c%s"
907 (ideographic-radical value)
910 (setq radical value)))
911 (setq attributes (delq 'shinjigen-1-radical attributes))
913 (when (and (memq 'ideographic- attributes)
914 (setq value (get-char-attribute char 'ideographic-)))
915 (insert "(ideographic- ")
916 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
919 (setq cell (car value))
921 (setq cell (decode-char '=ucs cell)))
922 (cond ((characterp cell)
926 (insert (format "%S" cell))
927 (char-db-insert-char-spec cell readable))
928 (setq separator lbs))
932 (if (consp (car cell))
933 (char-db-insert-char-spec cell readable)
934 (char-db-insert-char-reference cell readable))
935 (setq separator lbs))
939 (insert (prin1-to-string cell))
940 (setq separator " ")))
941 (setq value (cdr value)))
943 (insert line-breaking)
944 (setq attributes (delq 'ideographic- attributes)))
945 (when (and (memq 'total-strokes attributes)
946 (setq value (get-char-attribute char 'total-strokes)))
947 (insert (format "(total-strokes . %S)%s"
950 (setq attributes (delq 'total-strokes attributes))
952 (when (and (memq '->ideograph attributes)
953 (setq value (get-char-attribute char '->ideograph)))
954 (insert (format "(->ideograph\t%s)%s"
955 (mapconcat (lambda (code)
956 (cond ((symbolp code)
959 (format "#x%04X" code))
962 line-breaking code))))
965 (setq attributes (delq '->ideograph attributes))
967 ;; (when (and (memq '->decomposition attributes)
968 ;; (setq value (get-char-attribute char '->decomposition)))
969 ;; (insert (format "(->decomposition\t%s)%s"
970 ;; (mapconcat (lambda (code)
971 ;; (cond ((symbolp code)
972 ;; (symbol-name code))
973 ;; ((characterp code)
975 ;; (format "%S" code)
980 ;; (format "#x%04X" code))
982 ;; (format "%s%S" line-breaking code))))
985 ;; (setq attributes (delq '->decomposition attributes))
987 (if (equal (get-char-attribute char '->titlecase)
988 (get-char-attribute char '->uppercase))
989 (setq attributes (delq '->titlecase attributes)))
990 (when (and (memq '->mojikyo attributes)
991 (setq value (get-char-attribute char '->mojikyo)))
992 (insert (format "(->mojikyo\t\t. %06d)\t; %c%s"
993 value (decode-char 'mojikyo value)
995 (setq attributes (delq '->mojikyo attributes))
997 (when (and (memq 'hanyu-dazidian-vol attributes)
998 (setq value (get-char-attribute char 'hanyu-dazidian-vol)))
999 (insert (format "(hanyu-dazidian-vol . %d)%s"
1000 value line-breaking))
1001 (setq attributes (delq 'hanyu-dazidian-vol attributes))
1003 (when (and (memq 'hanyu-dazidian-page attributes)
1004 (setq value (get-char-attribute char 'hanyu-dazidian-page)))
1005 (insert (format "(hanyu-dazidian-page . %d)%s"
1006 value line-breaking))
1007 (setq attributes (delq 'hanyu-dazidian-page attributes))
1009 (when (and (memq 'hanyu-dazidian-char attributes)
1010 (setq value (get-char-attribute char 'hanyu-dazidian-char)))
1011 (insert (format "(hanyu-dazidian-char . %d)%s"
1012 value line-breaking))
1013 (setq attributes (delq 'hanyu-dazidian-char attributes))
1016 (dolist (ignored '(composition
1017 ->denotational <-subsumptive ->ucs-unified
1018 ->ideographic-component-forms))
1019 (setq attributes (delq ignored attributes))))
1021 (setq name (car attributes))
1022 (if (setq value (get-char-attribute char name))
1023 (cond ((setq ret (find-charset name))
1024 (setq name (charset-name ret))
1025 (if (and (not (memq name dest-ccss))
1027 (setq value (get-char-attribute char name))
1028 (setq dest-ccss (cons name dest-ccss))))
1029 (char-db-insert-ccs-feature name value line-breaking))
1031 ((string-match "^=>ucs@" (symbol-name name))
1032 (insert (format "(%-18s . #x%04X)\t; %c%s"
1033 name value (decode-char '=ucs value)
1036 ((eq name 'jisx0208-1978/4X)
1037 (insert (format "(%-18s . #x%04X)%s"
1043 (not (eq name '->subsumptive))
1044 (not (eq name '->uppercase))
1045 (not (eq name '->lowercase))
1046 (not (eq name '->titlecase))
1047 (not (eq name '->canonical))
1048 (not (eq name '->Bopomofo))
1049 (not (eq name '->mistakable))
1050 (not (eq name '->ideographic-variants))
1051 (null (get-char-attribute
1052 char (intern (format "%s*sources" name))))
1053 (not (string-match "\\*sources$" (symbol-name name)))
1054 (null (get-char-attribute
1055 char (intern (format "%s*note" name))))
1056 (not (string-match "\\*note$" (symbol-name name)))
1057 (or (eq name '<-identical)
1058 (eq name '<-uppercase)
1059 (eq name '<-lowercase)
1060 (eq name '<-titlecase)
1061 (eq name '<-canonical)
1062 (eq name '<-ideographic-variants)
1063 ;; (eq name '<-synonyms)
1064 (string-match "^<-synonyms" (symbol-name name))
1065 (eq name '<-mistakable)
1066 (when (string-match "^->" (symbol-name name))
1068 ((string-match "^->fullwidth" (symbol-name name))
1069 (not (and (consp value)
1070 (characterp (car value))
1072 (car value) '=ucs 'defined-only)))
1077 ((or (eq name 'ideographic-structure)
1078 (eq name 'ideographic-combination)
1079 (eq name 'ideographic-)
1080 (eq name '=decomposition)
1081 (string-match "^=>decomposition" (symbol-name name))
1082 (string-match "^\\(->\\|<-\\)[^*]*$" (symbol-name name))
1083 (string-match "^\\(->\\|<-\\)[^*]*\\*sources$"
1086 (char-db-insert-relation-feature char name value
1089 ((memq name '(ideograph=
1090 original-ideograph-of
1091 ancient-ideograph-of
1094 ;; simplified-ideograph-of
1095 ideographic-variants
1096 ;; ideographic-different-form-of
1098 (insert (format "(%-18s%s " name line-breaking))
1099 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1101 (while (consp value)
1102 (setq cell (car value))
1103 (if (and (consp cell)
1108 (char-db-insert-alist cell readable)
1109 (setq separator lbs))
1112 (insert (prin1-to-string cell))
1113 (setq separator " "))
1114 (setq value (cdr value)))
1116 (insert line-breaking))
1118 (insert (format "(%-18s " name))
1119 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1121 (while (consp value)
1122 (setq cell (car value))
1123 (if (and (consp cell)
1125 (setq ret (condition-case nil
1133 (setq key (car (car rest)))
1134 (if (find-charset key)
1135 (setq cal (cons key cal))
1136 (setq al (cons key al)))
1137 (setq rest (cdr rest)))
1140 (insert-char-attributes ret
1143 (setq separator lbs))
1144 (setq ret (prin1-to-string cell))
1146 (if (< (+ (current-column)
1153 (setq separator " "))
1154 (setq value (cdr value)))
1156 (insert line-breaking))
1158 (insert (format "(%-18s" name))
1159 (setq ret (prin1-to-string value))
1160 (unless (< (+ (current-column)
1164 (insert line-breaking))
1165 (insert " . " ret ")" line-breaking)
1166 ;; (insert (format "(%-18s . %S)%s"
1171 (setq attributes (cdr attributes)))
1174 (defun insert-char-data (char &optional readable
1177 (narrow-to-region (point)(point))
1178 (insert "(define-char
1180 (insert-char-attributes char readable attributes)
1182 (goto-char (point-min))
1183 (while (re-search-forward "[ \t]+$" nil t)
1186 (goto-char (point-min))
1187 (while (re-search-forward "[ \t][ \t][ \t]*" nil t)
1188 (let ((column (current-column))
1189 (indent-tabs-mode t))
1190 (delete-region (match-beginning 0) (point))
1191 (indent-to column)))
1192 (goto-char (point-max))
1193 ;; (tabify (point-min)(point-max))
1196 (defun insert-char-data-with-variant (char &optional printable
1198 script excluded-script)
1199 (insert-char-data char printable)
1200 (let ((variants (char-variants char))
1203 (setq variants (sort variants #'<))
1204 (setq rest variants)
1205 (setq variants (cons char variants))
1207 (setq variant (car rest))
1208 (unless (get-char-attribute variant '<-subsumptive)
1209 (if (and (or (null script)
1210 (null (setq vs (get-char-attribute variant 'script)))
1212 (or (null excluded-script)
1213 (null (setq vs (get-char-attribute variant 'script)))
1214 (not (memq excluded-script vs))))
1215 (unless (and no-ucs-unified (get-char-attribute variant '=ucs))
1216 (insert-char-data variant printable)
1217 (if (setq ret (char-variants variant))
1219 (or (memq (car ret) variants)
1220 ;; (get-char-attribute (car ret) '<-subsumptive)
1221 (setq rest (nconc rest (list (car ret)))))
1222 (setq ret (cdr ret)))))))
1223 (setq rest (cdr rest)))))
1225 (defun insert-char-range-data (min max &optional script excluded-script)
1228 (while (<= code max)
1229 (setq char (decode-char '=ucs code))
1230 (if (encode-char char '=ucs 'defined-only)
1231 (insert-char-data-with-variant char nil 'no-ucs-unified
1232 script excluded-script))
1233 (setq code (1+ code)))))
1235 (defun write-char-range-data-to-file (min max file
1236 &optional script excluded-script)
1237 (let ((coding-system-for-write char-db-file-coding-system))
1239 (insert (format ";; -*- coding: %s -*-\n"
1240 char-db-file-coding-system))
1241 (insert-char-range-data min max script excluded-script)
1242 (write-region (point-min)(point-max) file))))
1244 (defvar what-character-original-window-configuration)
1247 (defun what-char-definition (char)
1248 (interactive (list (char-after)))
1249 (let ((buf (get-buffer-create "*Character Description*"))
1250 (the-buf (current-buffer))
1251 (win-conf (current-window-configuration)))
1253 (make-local-variable 'what-character-original-window-configuration)
1254 (setq what-character-original-window-configuration win-conf)
1255 (setq buffer-read-only nil)
1259 (insert-char-data-with-variant char 'printable)
1260 (unless (char-attribute-alist char)
1261 (insert (format ";; = %c\n"
1262 (let* ((rest (split-char char))
1266 (setq code (logior (lsh code 8)
1268 (decode-char ccs code)))))
1269 ;; (char-db-update-comment)
1270 (set-buffer-modified-p nil)
1271 (view-mode the-buf (lambda (buf)
1272 (set-window-configuration
1273 what-character-original-window-configuration)
1275 (goto-char (point-min)))
1277 (set-window-configuration
1278 what-character-original-window-configuration)
1279 (signal (car err) (cdr err)))))))
1285 (provide 'char-db-util)
1287 ;;; char-db-util.el ends here