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
188 ;;; @ char-db formatters
191 (defun char-db-make-char-spec (char)
193 (cond ((characterp char)
194 (cond ((and (setq ret (encode-char char '=ucs 'defined-only))
195 (not (and (<= #xE000 ret)(<= ret #xF8FF))))
196 (setq char-spec (list (cons '=ucs ret)))
197 (cond ((setq ret (get-char-attribute char 'name))
198 (setq char-spec (cons (cons 'name ret) char-spec))
200 ((setq ret (get-char-attribute char 'name*))
201 (setq char-spec (cons (cons 'name* ret) char-spec))
206 (let ((rest char-db-coded-charset-priority-list)
209 (setq ccs (charset-name
210 (find-charset (car rest))))
212 (encode-char char ccs
214 (throw 'tag (cons ccs ret)))
215 (setq rest (cdr rest))))))
216 (setq char-spec (list ret))
217 (dolist (ccs (delq (car ret) (charset-list)))
218 (if (and (or (charset-iso-final-char ccs)
225 (string-match "=ucs@" (symbol-name ccs)))
226 (setq ccs (charset-name ccs))
227 (null (assq ccs char-spec))
228 (setq ret (encode-char char ccs 'defined-only)))
229 (setq char-spec (cons (cons ccs ret) char-spec))))
231 (setq char-spec (split-char char)))
232 (cond ((setq ret (get-char-attribute char 'name))
233 (setq char-spec (cons (cons 'name ret) char-spec))
235 ((setq ret (get-char-attribute char 'name*))
236 (setq char-spec (cons (cons 'name* ret) char-spec))
239 ((setq ret (get-char-attribute
240 char 'ideographic-combination))
242 (cons (cons 'ideographic-combination ret)
249 (defun char-db-insert-char-spec (char &optional readable column
252 (setq column (current-column)))
253 (let (char-spec temp-char)
254 (setq char-spec (char-db-make-char-spec char))
255 (unless (or (characterp char) ; char
257 (setq char (find-char char-spec))
259 ;; define temporary character
260 ;; Current implementation is dirty.
261 (setq temp-char (define-char (cons '(ideograph-daikanwa . 0)
263 (remove-char-attribute temp-char 'ideograph-daikanwa)
264 (setq char temp-char))
265 (insert-char-attributes char
267 (union (mapcar #'car char-spec)
270 ;; undefine temporary character
271 ;; Current implementation is dirty.
272 (setq char-spec (char-attribute-alist temp-char))
274 (remove-char-attribute temp-char (car (car char-spec)))
275 (setq char-spec (cdr char-spec))))))
277 (defun char-db-insert-alist (alist &optional readable column)
279 (setq column (current-column)))
281 (concat "\n" (make-string (1+ column) ?\ )))
285 lbs cell rest separator)
288 (setq name (car (car alist))
289 value (cdr (car alist)))
290 (cond ((eq name 'char)
292 (if (setq ret (condition-case nil
300 (setq key (car (car value)))
301 ;; (if (find-charset key)
302 ;; (setq cal (cons key cal))
303 (setq al (cons key al))
305 (setq value (cdr value)))
306 (insert-char-attributes ret
310 (insert (prin1-to-string value)))
312 (insert line-breaking))
314 (insert (format "(%-18s " name))
315 (setq lbs (concat "\n" (make-string (current-column) ?\ )))
317 (setq cell (car value))
318 (if (and (consp cell)
320 (setq ret (condition-case nil
330 (setq key (car (car rest)))
331 ;; (if (find-charset key)
332 ;; (setq cal (cons key cal))
333 (setq al (cons key al))
335 (setq rest (cdr rest)))
338 (insert-char-attributes ret
342 (setq separator lbs))
345 (insert (prin1-to-string cell))
346 (setq separator " "))
347 (setq value (cdr value)))
349 (insert line-breaking))
351 (insert (format "(%-18s . %S)%s"
354 (setq alist (cdr alist))))
357 (defun char-db-insert-char-reference (plist &optional readable column)
359 (setq column (current-column)))
361 (concat "\n" (make-string (1+ column) ?\ )))
366 (setq name (pop plist))
367 (setq value (pop plist))
368 (cond ((eq name :char)
371 (cond ((numberp value)
372 (setq value (decode-char '=ucs value)))
374 ;; (setq value (or (find-char value)
377 (char-db-insert-char-spec value readable)
378 (insert line-breaking)
381 (insert (format "%s%s\t%d ; %c%s"
384 (ideographic-radical value)
388 (insert (format "%s%s\t%S" separator name value))
389 (setq separator line-breaking)))
393 (defun char-db-decode-isolated-char (ccs code-point)
396 (cond ((eq ccs 'arabic-iso8859-6)
397 (decode-char ccs code-point))
398 ((and (memq ccs '(=gt-pj-1
409 (setq ret (decode-char ccs code-point))
410 (setq ret (encode-char ret '=gt 'defined-only)))
411 (decode-builtin-char '=gt ret))
413 (decode-builtin-char ccs code-point))))
414 (cond ((and (<= 0 (char-int ret))
415 (<= (char-int ret) #x1F))
416 (decode-char '=ucs (+ #x2400 (char-int ret))))
417 ((= (char-int ret) #x7F)
421 (defvar char-db-convert-obsolete-format t)
423 (defun char-db-insert-ccs-feature (name value line-breaking)
426 (cond ((memq name '(=shinjigen
428 =shinjigen@rev =shinjigen/+p@rev))
429 "(%-18s . %04d)\t; %c")
430 ((eq name '=shinjigen@1ed/24pr)
431 "(%-18s . %04d)\t; %c")
432 ((or (memq name '(=daikanwa
433 =daikanwa@rev1 =daikanwa@rev2
434 =gt =>>gt =>gt =gt-k =>>gt-k =cbeta
435 =zinbun-oracle =>zinbun-oracle))
436 (string-match "^=adobe-" (symbol-name name)))
437 "(%-18s . %05d)\t; %c")
439 "(%-18s . %06d)\t; %c")
440 ((>= (charset-dimension name) 2)
441 "(%-18s . #x%04X)\t; %c")
443 "(%-18s . #x%02X)\t; %c"))
445 (if (= (charset-iso-graphic-plane name) 1)
447 (cond ((= (charset-dimension name) 1)
449 ((= (charset-dimension name) 2)
451 ((= (charset-dimension name) 3)
455 (char-db-decode-isolated-char name value)))
456 (if (and (= (charset-chars name) 94)
457 (= (charset-dimension name) 2))
458 (insert (format " [%02d-%02d]"
459 (- (lsh value -8) 32)
460 (- (logand value 255) 32))))
461 (insert line-breaking))
463 (defun char-db-insert-relation-feature (char name value line-breaking
465 (insert (format "(%-18s%s " name line-breaking))
466 (let ((lbs (concat "\n" (make-string (current-column) ?\ )))
467 separator cell sources required-features
470 (setq cell (car value))
472 (setq cell (decode-char '=ucs cell)))
474 ((eq name '->subsumptive)
475 (when (or (not (some (lambda (atr)
476 (get-char-attribute cell atr))
477 char-db-ignored-attributes))
479 (encode-char cell ccs 'defined-only))
483 (let ((char-db-ignored-attributes
485 char-db-ignored-attributes)))
486 (insert-char-attributes cell readable))
487 (setq separator lbs))
492 char (intern (format "%s*sources" name))))
493 (setq required-features nil)
494 (dolist (source sources)
498 shinjigen shinjigen@1ed shinjigen@rev))
499 (setq required-features
500 (union required-features
510 (setq required-features
511 (union required-features
516 ((find-charset (setq ret (intern (format "=%s" source))))
517 (setq required-features
518 (cons ret required-features)))
519 (t (setq required-features
520 (cons source required-features)))))
521 (cond ((string-match "@JP" (symbol-name name))
522 (setq required-features
523 (union required-features
531 ((string-match "@CN" (symbol-name name))
532 (setq required-features
533 (union required-features
540 (insert (format "%S" cell))
541 (char-db-insert-char-spec cell readable
544 (setq separator lbs))
548 (if (consp (car cell))
549 (char-db-insert-char-spec cell readable)
550 (char-db-insert-char-reference cell readable))
551 (setq separator lbs))
555 (insert (prin1-to-string cell))
556 (setq separator " ")))
557 (setq value (cdr value)))
559 (insert line-breaking)))
561 (defun insert-char-attributes (char &optional readable attributes column)
563 (setq column (current-column)))
564 (let (name value ; has-long-ccs-name
568 (concat "\n" (make-string (1+ column) ?\ )))
569 lbs cell separator ret
571 dest-ccss ; sources required-features
576 (if (consp attributes)
578 (dolist (name attributes)
579 (unless (memq name char-db-ignored-attributes)
580 (if (find-charset name)
584 (dolist (name (char-attribute-list))
585 (unless (memq name char-db-ignored-attributes)
586 (if (find-charset name)
590 #'char-attribute-name<)))
592 (when (memq '<-subsumptive attributes)
594 (when (setq value (get-char-attribute char '<-subsumptive))
595 (char-db-insert-relation-feature char '<-subsumptive value
598 (setq attributes (delq '<-subsumptive attributes)))
599 (when (and (memq '<-denotational attributes)
600 (setq value (get-char-attribute char '<-denotational)))
601 (char-db-insert-relation-feature char '<-denotational value
604 (setq attributes (delq '<-denotational attributes)))
605 (when (and (memq 'name attributes)
606 (setq value (get-char-attribute char 'name)))
608 (if (> (+ (current-column) (length value)) 48)
611 value line-breaking))
612 (setq attributes (delq 'name 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 'script attributes)
624 (setq value (get-char-attribute char 'script)))
625 (insert (format "(script\t\t%s)%s"
626 (mapconcat (function prin1-to-string)
629 (setq attributes (delq 'script attributes))
631 (dolist (name '(=>ucs =>ucs*))
632 (when (and (memq name attributes)
633 (setq value (get-char-attribute char name)))
634 (insert (format "(%-18s . #x%04X)\t; %c%s"
635 name value (decode-char '=ucs value)
637 (setq attributes (delq name attributes))))
638 (dolist (name '(=>ucs@gb =>ucs@cns =>ucs@jis =>ucs@ks =>ucs@big5))
639 (when (and (memq name attributes)
640 (setq value (get-char-attribute char name)))
641 (insert (format "(%-18s . #x%04X)\t; %c%s"
646 (symbol-name name) 2)))
649 (setq attributes (delq name attributes))
651 (dolist (name '(=>daikanwa))
652 (when (and (memq name attributes)
653 (setq value (get-char-attribute char name)))
656 (format "(%-18s . %05d)\t; %c%s"
657 name value (decode-char '=daikanwa value)
659 (format "(%-18s %s)\t; %c%s"
661 (mapconcat (function prin1-to-string)
663 (char-representative-of-daikanwa char)
665 (setq attributes (delq name attributes))))
666 (when (and (memq 'general-category attributes)
667 (setq value (get-char-attribute char 'general-category)))
669 "(general-category\t%s) ; %s%s"
670 (mapconcat (lambda (cell)
673 (cond ((rassoc value unidata-normative-category-alist)
674 "Normative Category")
675 ((rassoc value unidata-informative-category-alist)
676 "Informative Category")
680 (setq attributes (delq 'general-category attributes))
682 (when (and (memq 'bidi-category attributes)
683 (setq value (get-char-attribute char 'bidi-category)))
684 (insert (format "(bidi-category\t. %S)%s"
687 (setq attributes (delq 'bidi-category attributes))
689 (unless (or (not (memq 'mirrored attributes))
690 (eq (setq value (get-char-attribute char 'mirrored 'empty))
692 (insert (format "(mirrored\t\t. %S)%s"
695 (setq attributes (delq 'mirrored attributes))
698 ((and (memq 'decimal-digit-value attributes)
699 (setq value (get-char-attribute char 'decimal-digit-value)))
700 (insert (format "(decimal-digit-value . %S)%s"
703 (setq attributes (delq 'decimal-digit-value attributes))
704 (when (and (memq 'digit-value attributes)
705 (setq value (get-char-attribute char 'digit-value)))
706 (insert (format "(digit-value\t . %S)%s"
709 (setq attributes (delq 'digit-value attributes))
711 (when (and (memq 'numeric-value attributes)
712 (setq value (get-char-attribute char 'numeric-value)))
713 (insert (format "(numeric-value\t . %S)%s"
716 (setq attributes (delq 'numeric-value attributes))
720 (when (and (memq 'digit-value attributes)
721 (setq value (get-char-attribute char 'digit-value)))
722 (insert (format "(digit-value\t. %S)%s"
725 (setq attributes (delq 'digit-value attributes))
727 (when (and (memq 'numeric-value attributes)
728 (setq value (get-char-attribute char 'numeric-value)))
729 (insert (format "(numeric-value\t. %S)%s"
732 (setq attributes (delq 'numeric-value attributes))
734 (when (and (memq 'iso-10646-comment attributes)
735 (setq value (get-char-attribute char 'iso-10646-comment)))
736 (insert (format "(iso-10646-comment\t. %S)%s"
739 (setq attributes (delq 'iso-10646-comment attributes))
741 (when (and (memq 'morohashi-daikanwa attributes)
742 (setq value (get-char-attribute char 'morohashi-daikanwa)))
743 (insert (format "(morohashi-daikanwa\t%s)%s"
744 (mapconcat (function prin1-to-string) value " ")
746 (setq attributes (delq 'morohashi-daikanwa attributes))
750 (when (and (memq 'ideographic-radical attributes)
751 (setq value (get-char-attribute char 'ideographic-radical)))
753 (insert (format "(ideographic-radical . %S)\t; %c%s"
755 (ideographic-radical radical)
757 (setq attributes (delq 'ideographic-radical attributes))
759 (when (and (memq 'shuowen-radical attributes)
760 (setq value (get-char-attribute char 'shuowen-radical)))
761 (insert (format "(shuowen-radical\t. %S)\t; %c%s"
763 (shuowen-radical value)
765 (setq attributes (delq 'shuowen-radical attributes))
770 char-db-feature-domains
772 (dolist (feature (char-attribute-list))
773 (setq feature (symbol-name feature))
775 "\\(radical\\|strokes\\)@\\([^@*]+\\)\\(\\*\\|$\\)"
777 (setq domain (intern (match-string 2 feature)))
778 (unless (memq domain dest)
779 (setq dest (cons domain dest)))))
780 (sort dest #'string<))))
781 (setq key (intern (format "%s@%s" 'ideographic-radical domain)))
782 (when (and (memq key attributes)
783 (setq value (get-char-attribute char key)))
785 (insert (format "(%s . %S)\t; %c%s"
788 (ideographic-radical radical)
790 (setq attributes (delq key attributes))
792 (setq key (intern (format "%s@%s" 'ideographic-strokes domain)))
793 (when (and (memq key attributes)
794 (setq value (get-char-attribute char key)))
796 (insert (format "(%s . %S)%s"
800 (setq attributes (delq key attributes))
802 (setq key (intern (format "%s@%s" 'total-strokes domain)))
803 (when (and (memq key attributes)
804 (setq value (get-char-attribute char key)))
805 (insert (format "(%s . %S)%s"
809 (setq attributes (delq key attributes))
811 (dolist (feature '(ideographic-radical
814 (setq key (intern (format "%s@%s*sources" feature domain)))
815 (when (and (memq key attributes)
816 (setq value (get-char-attribute char key)))
817 (insert (format "(%s%s" key line-breaking))
819 (insert (format " %s" cell)))
821 (insert line-breaking)
822 (setq attributes (delq key attributes))
825 (when (and (memq 'ideographic-strokes attributes)
826 (setq value (get-char-attribute char 'ideographic-strokes)))
828 (insert (format "(ideographic-strokes . %S)%s"
831 (setq attributes (delq 'ideographic-strokes attributes))
833 (when (and (memq 'kangxi-radical attributes)
834 (setq value (get-char-attribute char 'kangxi-radical)))
835 (unless (eq value radical)
836 (insert (format "(kangxi-radical\t . %S)\t; %c%s"
838 (ideographic-radical value)
841 (setq radical value)))
842 (setq attributes (delq 'kangxi-radical attributes))
844 (when (and (memq 'kangxi-strokes attributes)
845 (setq value (get-char-attribute char 'kangxi-strokes)))
846 (unless (eq value strokes)
847 (insert (format "(kangxi-strokes\t . %S)%s"
851 (setq strokes value)))
852 (setq attributes (delq 'kangxi-strokes attributes))
854 (when (and (memq 'japanese-radical attributes)
855 (setq value (get-char-attribute char 'japanese-radical)))
856 (unless (eq value radical)
857 (insert (format "(japanese-radical\t . %S)\t; %c%s"
859 (ideographic-radical value)
862 (setq radical value)))
863 (setq attributes (delq 'japanese-radical attributes))
865 (when (and (memq 'japanese-strokes attributes)
866 (setq value (get-char-attribute char 'japanese-strokes)))
867 (unless (eq value strokes)
868 (insert (format "(japanese-strokes\t . %S)%s"
872 (setq strokes value)))
873 (setq attributes (delq 'japanese-strokes attributes))
875 (when (and (memq 'cns-radical attributes)
876 (setq value (get-char-attribute char 'cns-radical)))
877 (insert (format "(cns-radical\t . %S)\t; %c%s"
879 (ideographic-radical value)
881 (setq attributes (delq 'cns-radical attributes))
883 (when (and (memq 'cns-strokes attributes)
884 (setq value (get-char-attribute char 'cns-strokes)))
885 (unless (eq value strokes)
886 (insert (format "(cns-strokes\t . %S)%s"
890 (setq strokes value)))
891 (setq attributes (delq 'cns-strokes attributes))
893 (when (and (memq 'shinjigen-1-radical attributes)
894 (setq value (get-char-attribute char 'shinjigen-1-radical)))
895 (unless (eq value radical)
896 (insert (format "(shinjigen-1-radical . %S)\t; %c%s"
898 (ideographic-radical value)
901 (setq radical value)))
902 (setq attributes (delq 'shinjigen-1-radical attributes))
904 (when (and (memq 'ideographic- attributes)
905 (setq value (get-char-attribute char 'ideographic-)))
906 (insert "(ideographic- ")
907 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
910 (setq cell (car value))
912 (setq cell (decode-char '=ucs cell)))
913 (cond ((characterp cell)
917 (insert (format "%S" cell))
918 (char-db-insert-char-spec cell readable))
919 (setq separator lbs))
923 (if (consp (car cell))
924 (char-db-insert-char-spec cell readable)
925 (char-db-insert-char-reference cell readable))
926 (setq separator lbs))
930 (insert (prin1-to-string cell))
931 (setq separator " ")))
932 (setq value (cdr value)))
934 (insert line-breaking)
935 (setq attributes (delq 'ideographic- attributes)))
936 (when (and (memq 'total-strokes attributes)
937 (setq value (get-char-attribute char 'total-strokes)))
938 (insert (format "(total-strokes . %S)%s"
941 (setq attributes (delq 'total-strokes attributes))
943 (when (and (memq '->ideograph attributes)
944 (setq value (get-char-attribute char '->ideograph)))
945 (insert (format "(->ideograph\t%s)%s"
946 (mapconcat (lambda (code)
947 (cond ((symbolp code)
950 (format "#x%04X" code))
953 line-breaking code))))
956 (setq attributes (delq '->ideograph attributes))
958 ;; (when (and (memq '->decomposition attributes)
959 ;; (setq value (get-char-attribute char '->decomposition)))
960 ;; (insert (format "(->decomposition\t%s)%s"
961 ;; (mapconcat (lambda (code)
962 ;; (cond ((symbolp code)
963 ;; (symbol-name code))
964 ;; ((characterp code)
966 ;; (format "%S" code)
971 ;; (format "#x%04X" code))
973 ;; (format "%s%S" line-breaking code))))
976 ;; (setq attributes (delq '->decomposition attributes))
978 (if (equal (get-char-attribute char '->titlecase)
979 (get-char-attribute char '->uppercase))
980 (setq attributes (delq '->titlecase attributes)))
981 (when (and (memq '->mojikyo attributes)
982 (setq value (get-char-attribute char '->mojikyo)))
983 (insert (format "(->mojikyo\t\t. %06d)\t; %c%s"
984 value (decode-char 'mojikyo value)
986 (setq attributes (delq '->mojikyo attributes))
988 (when (and (memq 'hanyu-dazidian-vol attributes)
989 (setq value (get-char-attribute char 'hanyu-dazidian-vol)))
990 (insert (format "(hanyu-dazidian-vol . %d)%s"
991 value line-breaking))
992 (setq attributes (delq 'hanyu-dazidian-vol attributes))
994 (when (and (memq 'hanyu-dazidian-page attributes)
995 (setq value (get-char-attribute char 'hanyu-dazidian-page)))
996 (insert (format "(hanyu-dazidian-page . %d)%s"
997 value line-breaking))
998 (setq attributes (delq 'hanyu-dazidian-page attributes))
1000 (when (and (memq 'hanyu-dazidian-char attributes)
1001 (setq value (get-char-attribute char 'hanyu-dazidian-char)))
1002 (insert (format "(hanyu-dazidian-char . %d)%s"
1003 value line-breaking))
1004 (setq attributes (delq 'hanyu-dazidian-char attributes))
1007 (dolist (ignored '(composition
1008 ->denotational <-subsumptive ->ucs-unified
1009 ->ideographic-component-forms))
1010 (setq attributes (delq ignored attributes))))
1012 (setq name (car attributes))
1013 (if (setq value (get-char-attribute char name))
1014 (cond ((setq ret (find-charset name))
1015 (setq name (charset-name ret))
1016 (if (and (not (memq name dest-ccss))
1018 (setq value (get-char-attribute char name))
1019 (setq dest-ccss (cons name dest-ccss))))
1020 (char-db-insert-ccs-feature name value line-breaking))
1022 ((string-match "^=>ucs@" (symbol-name name))
1023 (insert (format "(%-18s . #x%04X)\t; %c%s"
1024 name value (decode-char '=ucs value)
1027 ((eq name 'jisx0208-1978/4X)
1028 (insert (format "(%-18s . #x%04X)%s"
1034 (not (eq name '->subsumptive))
1035 (not (eq name '->uppercase))
1036 (not (eq name '->lowercase))
1037 (not (eq name '->titlecase))
1038 (not (eq name '->canonical))
1039 (not (eq name '->Bopomofo))
1040 (not (eq name '->mistakable))
1041 (not (eq name '->ideographic-variants))
1042 (null (get-char-attribute
1043 char (intern (format "%s*sources" name))))
1044 (not (string-match "\\*sources$" (symbol-name name)))
1045 (null (get-char-attribute
1046 char (intern (format "%s*note" name))))
1047 (not (string-match "\\*note$" (symbol-name name)))
1048 (or (eq name '<-identical)
1049 (eq name '<-uppercase)
1050 (eq name '<-lowercase)
1051 (eq name '<-titlecase)
1052 (eq name '<-canonical)
1053 (eq name '<-ideographic-variants)
1054 ;; (eq name '<-synonyms)
1055 (string-match "^<-synonyms" (symbol-name name))
1056 (eq name '<-mistakable)
1057 (when (string-match "^->" (symbol-name name))
1059 ((string-match "^->fullwidth" (symbol-name name))
1060 (not (and (consp value)
1061 (characterp (car value))
1063 (car value) '=ucs 'defined-only)))
1068 ((or (eq name 'ideographic-structure)
1069 (eq name 'ideographic-combination)
1070 (eq name 'ideographic-)
1071 (eq name '=decomposition)
1072 (string-match "^=>decomposition" (symbol-name name))
1073 (string-match "^\\(->\\|<-\\)[^*]*$" (symbol-name name))
1074 (string-match "^\\(->\\|<-\\)[^*]*\\*sources$"
1077 (char-db-insert-relation-feature char name value
1080 ((memq name '(ideograph=
1081 original-ideograph-of
1082 ancient-ideograph-of
1085 ;; simplified-ideograph-of
1086 ideographic-variants
1087 ;; ideographic-different-form-of
1089 (insert (format "(%-18s%s " name line-breaking))
1090 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1092 (while (consp value)
1093 (setq cell (car value))
1094 (if (and (consp cell)
1099 (char-db-insert-alist cell readable)
1100 (setq separator lbs))
1103 (insert (prin1-to-string cell))
1104 (setq separator " "))
1105 (setq value (cdr value)))
1107 (insert line-breaking))
1109 (insert (format "(%-18s " name))
1110 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1112 (while (consp value)
1113 (setq cell (car value))
1114 (if (and (consp cell)
1116 (setq ret (condition-case nil
1124 (setq key (car (car rest)))
1125 (if (find-charset key)
1126 (setq cal (cons key cal))
1127 (setq al (cons key al)))
1128 (setq rest (cdr rest)))
1131 (insert-char-attributes ret
1134 (setq separator lbs))
1135 (setq ret (prin1-to-string cell))
1137 (if (< (+ (current-column)
1144 (setq separator " "))
1145 (setq value (cdr value)))
1147 (insert line-breaking))
1149 (insert (format "(%-18s" name))
1150 (setq ret (prin1-to-string value))
1151 (unless (< (+ (current-column)
1155 (insert line-breaking))
1156 (insert " . " ret ")" line-breaking)
1157 ;; (insert (format "(%-18s . %S)%s"
1162 (setq attributes (cdr attributes)))
1165 (defun insert-char-data (char &optional readable
1168 (narrow-to-region (point)(point))
1169 (insert "(define-char
1171 (insert-char-attributes char readable attributes)
1173 (goto-char (point-min))
1174 (while (re-search-forward "[ \t]+$" nil t)
1177 (goto-char (point-min))
1178 (while (re-search-forward "[ \t][ \t][ \t]*" nil t)
1179 (let ((column (current-column))
1180 (indent-tabs-mode t))
1181 (delete-region (match-beginning 0) (point))
1182 (indent-to column)))
1183 (goto-char (point-max))
1184 ;; (tabify (point-min)(point-max))
1187 (defun insert-char-data-with-variant (char &optional printable
1189 script excluded-script)
1190 (insert-char-data char printable)
1191 (let ((variants (char-variants char))
1194 (setq variants (sort variants #'<))
1195 (setq rest variants)
1196 (setq variants (cons char variants))
1198 (setq variant (car rest))
1199 (unless (get-char-attribute variant '<-subsumptive)
1200 (if (and (or (null script)
1201 (null (setq vs (get-char-attribute variant 'script)))
1203 (or (null excluded-script)
1204 (null (setq vs (get-char-attribute variant 'script)))
1205 (not (memq excluded-script vs))))
1206 (unless (and no-ucs-unified (get-char-attribute variant '=ucs))
1207 (insert-char-data variant printable)
1208 (if (setq ret (char-variants variant))
1210 (or (memq (car ret) variants)
1211 ;; (get-char-attribute (car ret) '<-subsumptive)
1212 (setq rest (nconc rest (list (car ret)))))
1213 (setq ret (cdr ret)))))))
1214 (setq rest (cdr rest)))))
1216 (defun insert-char-range-data (min max &optional script excluded-script)
1219 (while (<= code max)
1220 (setq char (decode-char '=ucs code))
1221 (if (encode-char char '=ucs 'defined-only)
1222 (insert-char-data-with-variant char nil 'no-ucs-unified
1223 script excluded-script))
1224 (setq code (1+ code)))))
1226 (defun write-char-range-data-to-file (min max file
1227 &optional script excluded-script)
1228 (let ((coding-system-for-write char-db-file-coding-system))
1230 (insert (format ";; -*- coding: %s -*-\n"
1231 char-db-file-coding-system))
1232 (insert-char-range-data min max script excluded-script)
1233 (write-region (point-min)(point-max) file))))
1235 (defvar what-character-original-window-configuration)
1238 (defun what-char-definition (char)
1239 (interactive (list (char-after)))
1240 (let ((buf (get-buffer-create "*Character Description*"))
1241 (the-buf (current-buffer))
1242 (win-conf (current-window-configuration)))
1244 (make-local-variable 'what-character-original-window-configuration)
1245 (setq what-character-original-window-configuration win-conf)
1246 (setq buffer-read-only nil)
1250 (insert-char-data-with-variant char 'printable)
1251 (unless (char-attribute-alist char)
1252 (insert (format ";; = %c\n"
1253 (let* ((rest (split-char char))
1257 (setq code (logior (lsh code 8)
1259 (decode-char ccs code)))))
1260 ;; (char-db-update-comment)
1261 (set-buffer-modified-p nil)
1262 (view-mode the-buf (lambda (buf)
1263 (set-window-configuration
1264 what-character-original-window-configuration)
1266 (goto-char (point-min)))
1268 (set-window-configuration
1269 what-character-original-window-configuration)
1270 (signal (car err) (cdr err)))))))
1276 (provide 'char-db-util)
1278 ;;; char-db-util.el ends here