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
194 ;;; @ char-db formatters
197 (defun char-db-make-char-spec (char)
199 (cond ((characterp char)
200 (cond ((and (setq ret (encode-char char '=ucs 'defined-only))
201 (not (and (<= #xE000 ret)(<= ret #xF8FF))))
202 (setq char-spec (list (cons '=ucs ret)))
203 (cond ((setq ret (get-char-attribute char 'name))
204 (setq char-spec (cons (cons 'name ret) char-spec))
206 ((setq ret (get-char-attribute char 'name*))
207 (setq char-spec (cons (cons 'name* ret) char-spec))
212 (let ((rest char-db-coded-charset-priority-list)
215 (setq ccs (charset-name
216 (find-charset (car rest))))
218 (encode-char char ccs
220 (throw 'tag (cons ccs ret)))
221 (setq rest (cdr rest))))))
222 (setq char-spec (list ret))
223 (dolist (ccs (delq (car ret) (charset-list)))
224 (if (and (or (charset-iso-final-char ccs)
231 (string-match "=ucs@" (symbol-name ccs)))
232 (setq ccs (charset-name ccs))
233 (null (assq ccs char-spec))
234 (setq ret (encode-char char ccs 'defined-only)))
235 (setq char-spec (cons (cons ccs ret) char-spec))))
237 (setq char-spec (split-char char)))
238 (cond ((setq ret (get-char-attribute char 'name))
239 (setq char-spec (cons (cons 'name ret) char-spec))
241 ((setq ret (get-char-attribute char 'name*))
242 (setq char-spec (cons (cons 'name* ret) char-spec))
245 ((setq ret (get-char-attribute
246 char 'ideographic-combination))
248 (cons (cons 'ideographic-combination ret)
255 (defun char-db-insert-char-spec (char &optional readable column
258 (setq column (current-column)))
259 (let (char-spec temp-char)
260 (setq char-spec (char-db-make-char-spec char))
261 (unless (or (characterp char) ; char
263 (setq char (find-char char-spec))
265 ;; define temporary character
266 ;; Current implementation is dirty.
267 (setq temp-char (define-char (cons '(ideograph-daikanwa . 0)
269 (remove-char-attribute temp-char 'ideograph-daikanwa)
270 (setq char temp-char))
271 (insert-char-attributes char
273 (union (mapcar #'car char-spec)
276 ;; undefine temporary character
277 ;; Current implementation is dirty.
278 (setq char-spec (char-attribute-alist temp-char))
280 (remove-char-attribute temp-char (car (car char-spec)))
281 (setq char-spec (cdr char-spec))))))
283 (defun char-db-insert-alist (alist &optional readable column)
285 (setq column (current-column)))
287 (concat "\n" (make-string (1+ column) ?\ )))
291 lbs cell rest separator)
294 (setq name (car (car alist))
295 value (cdr (car alist)))
296 (cond ((eq name 'char)
298 (if (setq ret (condition-case nil
306 (setq key (car (car value)))
307 ;; (if (find-charset key)
308 ;; (setq cal (cons key cal))
309 (setq al (cons key al))
311 (setq value (cdr value)))
312 (insert-char-attributes ret
316 (insert (prin1-to-string value)))
318 (insert line-breaking))
320 (insert (format "(%-18s " name))
321 (setq lbs (concat "\n" (make-string (current-column) ?\ )))
323 (setq cell (car value))
324 (if (and (consp cell)
326 (setq ret (condition-case nil
336 (setq key (car (car rest)))
337 ;; (if (find-charset key)
338 ;; (setq cal (cons key cal))
339 (setq al (cons key al))
341 (setq rest (cdr rest)))
344 (insert-char-attributes ret
348 (setq separator lbs))
351 (insert (prin1-to-string cell))
352 (setq separator " "))
353 (setq value (cdr value)))
355 (insert line-breaking))
357 (insert (format "(%-18s . %S)%s"
360 (setq alist (cdr alist))))
363 (defun char-db-insert-char-reference (plist &optional readable column)
365 (setq column (current-column)))
367 (concat "\n" (make-string (1+ column) ?\ )))
372 (setq name (pop plist))
373 (setq value (pop plist))
374 (cond ((eq name :char)
377 (cond ((numberp value)
378 (setq value (decode-char '=ucs value)))
380 ;; (setq value (or (find-char value)
383 (char-db-insert-char-spec value readable)
384 (insert line-breaking)
387 (insert (format "%s%s\t%d ; %c%s"
390 (ideographic-radical value)
394 (insert (format "%s%s\t%S" separator name value))
395 (setq separator line-breaking)))
399 (defun char-db-decode-isolated-char (ccs code-point)
402 (cond ((eq ccs 'arabic-iso8859-6)
403 (decode-char ccs code-point))
404 ((and (memq ccs '(=gt-pj-1
415 (setq ret (decode-char ccs code-point))
416 (setq ret (encode-char ret '=gt 'defined-only)))
417 (decode-builtin-char '=gt ret))
419 (decode-builtin-char ccs code-point))))
420 (cond ((and (<= 0 (char-int ret))
421 (<= (char-int ret) #x1F))
422 (decode-char '=ucs (+ #x2400 (char-int ret))))
423 ((= (char-int ret) #x7F)
427 (defvar char-db-convert-obsolete-format t)
429 (defun char-db-insert-ccs-feature (name value line-breaking)
432 (cond ((memq name '(=shinjigen
434 =shinjigen@rev =shinjigen/+p@rev))
435 "(%-18s . %04d)\t; %c")
436 ((eq name '=shinjigen@1ed/24pr)
437 "(%-18s . %04d)\t; %c")
438 ((or (memq name '(=daikanwa
439 =daikanwa@rev1 =daikanwa@rev2
441 =gt =>>gt =>gt =gt-k =>>gt-k =cbeta
442 =zinbun-oracle =>zinbun-oracle))
443 (string-match "^=adobe-" (symbol-name name)))
444 "(%-18s . %05d)\t; %c")
446 "(%-18s . %06d)\t; %c")
447 ((>= (charset-dimension name) 2)
448 "(%-18s . #x%04X)\t; %c")
450 "(%-18s . #x%02X)\t; %c"))
452 (if (= (charset-iso-graphic-plane name) 1)
454 (cond ((= (charset-dimension name) 1)
456 ((= (charset-dimension name) 2)
458 ((= (charset-dimension name) 3)
462 (char-db-decode-isolated-char name value)))
463 (if (and (= (charset-chars name) 94)
464 (= (charset-dimension name) 2))
465 (insert (format " [%02d-%02d]"
466 (- (lsh value -8) 32)
467 (- (logand value 255) 32))))
468 (insert line-breaking))
470 (defun char-db-insert-relation-feature (char name value line-breaking
472 (insert (format "(%-18s%s " name line-breaking))
473 (let ((lbs (concat "\n" (make-string (current-column) ?\ )))
474 separator cell sources required-features
477 (setq cell (car value))
479 (setq cell (decode-char '=ucs cell)))
481 ((eq name '->subsumptive)
482 (when (or (not (some (lambda (atr)
483 (get-char-attribute cell atr))
484 char-db-ignored-attributes))
486 (encode-char cell ccs 'defined-only))
490 (let ((char-db-ignored-attributes
492 char-db-ignored-attributes)))
493 (insert-char-attributes cell readable))
494 (setq separator lbs))
499 char (intern (format "%s*sources" name))))
500 (setq required-features nil)
501 (dolist (source sources)
505 shinjigen shinjigen@1ed shinjigen@rev))
506 (setq required-features
507 (union required-features
517 (setq required-features
518 (union required-features
523 ((find-charset (setq ret (intern (format "=%s" source))))
524 (setq required-features
525 (cons ret required-features)))
526 (t (setq required-features
527 (cons source required-features)))))
528 (cond ((string-match "@JP" (symbol-name name))
529 (setq required-features
530 (union required-features
538 ((string-match "@CN" (symbol-name name))
539 (setq required-features
540 (union required-features
547 (insert (format "%S" cell))
548 (char-db-insert-char-spec cell readable
551 (setq separator lbs))
555 (if (consp (car cell))
556 (char-db-insert-char-spec cell readable)
557 (char-db-insert-char-reference cell readable))
558 (setq separator lbs))
562 (insert (prin1-to-string cell))
563 (setq separator " ")))
564 (setq value (cdr value)))
566 (insert line-breaking)))
568 (defun insert-char-attributes (char &optional readable attributes column)
570 (setq column (current-column)))
571 (let (name value ; has-long-ccs-name
575 (concat "\n" (make-string (1+ column) ?\ )))
576 lbs cell separator ret
578 dest-ccss ; sources required-features
583 (if (consp attributes)
585 (dolist (name attributes)
586 (unless (memq name char-db-ignored-attributes)
587 (if (find-charset name)
591 (dolist (name (char-attribute-list))
592 (unless (memq name char-db-ignored-attributes)
593 (if (find-charset name)
597 #'char-attribute-name<)))
599 (when (memq '<-subsumptive attributes)
601 (when (setq value (get-char-attribute char '<-subsumptive))
602 (char-db-insert-relation-feature char '<-subsumptive value
605 (setq attributes (delq '<-subsumptive attributes)))
606 (when (and (memq '<-denotational attributes)
607 (setq value (get-char-attribute char '<-denotational)))
608 (char-db-insert-relation-feature char '<-denotational value
611 (setq attributes (delq '<-denotational attributes)))
612 (when (and (memq 'name attributes)
613 (setq value (get-char-attribute char 'name)))
615 (if (> (+ (current-column) (length value)) 48)
618 value line-breaking))
619 (setq attributes (delq 'name attributes))
621 (when (and (memq 'name* attributes)
622 (setq value (get-char-attribute char 'name*)))
624 (if (> (+ (current-column) (length value)) 48)
627 value line-breaking))
628 (setq attributes (delq 'name* attributes))
630 (when (and (memq 'script attributes)
631 (setq value (get-char-attribute char 'script)))
632 (insert (format "(script\t\t%s)%s"
633 (mapconcat (function prin1-to-string)
636 (setq attributes (delq 'script attributes))
638 (dolist (name '(=>ucs =>ucs*))
639 (when (and (memq name attributes)
640 (setq value (get-char-attribute char name)))
641 (insert (format "(%-18s . #x%04X)\t; %c%s"
642 name value (decode-char '=ucs value)
644 (setq attributes (delq name attributes))))
645 (dolist (name '(=>ucs@gb =>ucs@cns =>ucs@jis =>ucs@ks =>ucs@big5))
646 (when (and (memq name attributes)
647 (setq value (get-char-attribute char name)))
648 (insert (format "(%-18s . #x%04X)\t; %c%s"
653 (symbol-name name) 2)))
656 (setq attributes (delq name attributes))
658 ;; (dolist (name '(=>daikanwa))
659 ;; (when (and (memq name attributes)
660 ;; (setq value (get-char-attribute char name)))
662 ;; (if (integerp value)
663 ;; (format "(%-18s . %05d)\t; %c%s"
664 ;; name value (decode-char '=daikanwa value)
666 ;; (format "(%-18s %s)\t; %c%s"
668 ;; (mapconcat (function prin1-to-string)
670 ;; (char-representative-of-daikanwa char)
672 ;; (setq attributes (delq name attributes))))
673 (when (and (memq 'general-category attributes)
674 (setq value (get-char-attribute char 'general-category)))
676 "(general-category\t%s) ; %s%s"
677 (mapconcat (lambda (cell)
680 (cond ((rassoc value unidata-normative-category-alist)
681 "Normative Category")
682 ((rassoc value unidata-informative-category-alist)
683 "Informative Category")
687 (setq attributes (delq 'general-category attributes))
689 (when (and (memq 'bidi-category attributes)
690 (setq value (get-char-attribute char 'bidi-category)))
691 (insert (format "(bidi-category\t. %S)%s"
694 (setq attributes (delq 'bidi-category attributes))
696 (unless (or (not (memq 'mirrored attributes))
697 (eq (setq value (get-char-attribute char 'mirrored 'empty))
699 (insert (format "(mirrored\t\t. %S)%s"
702 (setq attributes (delq 'mirrored attributes))
705 ((and (memq 'decimal-digit-value attributes)
706 (setq value (get-char-attribute char 'decimal-digit-value)))
707 (insert (format "(decimal-digit-value . %S)%s"
710 (setq attributes (delq 'decimal-digit-value attributes))
711 (when (and (memq 'digit-value attributes)
712 (setq value (get-char-attribute char 'digit-value)))
713 (insert (format "(digit-value\t . %S)%s"
716 (setq attributes (delq 'digit-value attributes))
718 (when (and (memq 'numeric-value attributes)
719 (setq value (get-char-attribute char 'numeric-value)))
720 (insert (format "(numeric-value\t . %S)%s"
723 (setq attributes (delq 'numeric-value attributes))
727 (when (and (memq 'digit-value attributes)
728 (setq value (get-char-attribute char 'digit-value)))
729 (insert (format "(digit-value\t. %S)%s"
732 (setq attributes (delq 'digit-value attributes))
734 (when (and (memq 'numeric-value attributes)
735 (setq value (get-char-attribute char 'numeric-value)))
736 (insert (format "(numeric-value\t. %S)%s"
739 (setq attributes (delq 'numeric-value attributes))
741 (when (and (memq 'iso-10646-comment attributes)
742 (setq value (get-char-attribute char 'iso-10646-comment)))
743 (insert (format "(iso-10646-comment\t. %S)%s"
746 (setq attributes (delq 'iso-10646-comment attributes))
748 (when (and (memq 'morohashi-daikanwa attributes)
749 (setq value (get-char-attribute char 'morohashi-daikanwa)))
750 (insert (format "(morohashi-daikanwa\t%s)%s"
751 (mapconcat (function prin1-to-string) value " ")
753 (setq attributes (delq 'morohashi-daikanwa attributes))
757 (when (and (memq 'ideographic-radical attributes)
758 (setq value (get-char-attribute char 'ideographic-radical)))
760 (insert (format "(ideographic-radical . %S)\t; %c%s"
762 (ideographic-radical radical)
764 (setq attributes (delq 'ideographic-radical attributes))
766 (when (and (memq 'shuowen-radical attributes)
767 (setq value (get-char-attribute char 'shuowen-radical)))
768 (insert (format "(shuowen-radical\t. %S)\t; %c%s"
770 (shuowen-radical value)
772 (setq attributes (delq 'shuowen-radical attributes))
777 char-db-feature-domains
779 (dolist (feature (char-attribute-list))
780 (setq feature (symbol-name feature))
782 "\\(radical\\|strokes\\)@\\([^@*]+\\)\\(\\*\\|$\\)"
784 (setq domain (intern (match-string 2 feature)))
785 (unless (memq domain dest)
786 (setq dest (cons domain dest)))))
787 (sort dest #'string<))))
788 (setq key (intern (format "%s@%s" 'ideographic-radical domain)))
789 (when (and (memq key attributes)
790 (setq value (get-char-attribute char key)))
792 (insert (format "(%s . %S)\t; %c%s"
795 (ideographic-radical radical)
797 (setq attributes (delq key attributes))
799 (setq key (intern (format "%s@%s" 'ideographic-strokes domain)))
800 (when (and (memq key attributes)
801 (setq value (get-char-attribute char key)))
803 (insert (format "(%s . %S)%s"
807 (setq attributes (delq key attributes))
809 (setq key (intern (format "%s@%s" 'total-strokes domain)))
810 (when (and (memq key attributes)
811 (setq value (get-char-attribute char key)))
812 (insert (format "(%s . %S)%s"
816 (setq attributes (delq key attributes))
818 (dolist (feature '(ideographic-radical
821 (setq key (intern (format "%s@%s*sources" feature domain)))
822 (when (and (memq key attributes)
823 (setq value (get-char-attribute char key)))
824 (insert (format "(%s%s" key line-breaking))
826 (insert (format " %s" cell)))
828 (insert line-breaking)
829 (setq attributes (delq key attributes))
832 (when (and (memq 'ideographic-strokes attributes)
833 (setq value (get-char-attribute char 'ideographic-strokes)))
835 (insert (format "(ideographic-strokes . %S)%s"
838 (setq attributes (delq 'ideographic-strokes attributes))
840 (when (and (memq 'kangxi-radical attributes)
841 (setq value (get-char-attribute char 'kangxi-radical)))
842 (unless (eq value radical)
843 (insert (format "(kangxi-radical\t . %S)\t; %c%s"
845 (ideographic-radical value)
848 (setq radical value)))
849 (setq attributes (delq 'kangxi-radical attributes))
851 (when (and (memq 'kangxi-strokes attributes)
852 (setq value (get-char-attribute char 'kangxi-strokes)))
853 (unless (eq value strokes)
854 (insert (format "(kangxi-strokes\t . %S)%s"
858 (setq strokes value)))
859 (setq attributes (delq 'kangxi-strokes attributes))
861 (when (and (memq 'japanese-radical attributes)
862 (setq value (get-char-attribute char 'japanese-radical)))
863 (unless (eq value radical)
864 (insert (format "(japanese-radical\t . %S)\t; %c%s"
866 (ideographic-radical value)
869 (setq radical value)))
870 (setq attributes (delq 'japanese-radical attributes))
872 (when (and (memq 'japanese-strokes attributes)
873 (setq value (get-char-attribute char 'japanese-strokes)))
874 (unless (eq value strokes)
875 (insert (format "(japanese-strokes\t . %S)%s"
879 (setq strokes value)))
880 (setq attributes (delq 'japanese-strokes attributes))
882 (when (and (memq 'cns-radical attributes)
883 (setq value (get-char-attribute char 'cns-radical)))
884 (insert (format "(cns-radical\t . %S)\t; %c%s"
886 (ideographic-radical value)
888 (setq attributes (delq 'cns-radical attributes))
890 (when (and (memq 'cns-strokes attributes)
891 (setq value (get-char-attribute char 'cns-strokes)))
892 (unless (eq value strokes)
893 (insert (format "(cns-strokes\t . %S)%s"
897 (setq strokes value)))
898 (setq attributes (delq 'cns-strokes attributes))
900 (when (and (memq 'shinjigen-1-radical attributes)
901 (setq value (get-char-attribute char 'shinjigen-1-radical)))
902 (unless (eq value radical)
903 (insert (format "(shinjigen-1-radical . %S)\t; %c%s"
905 (ideographic-radical value)
908 (setq radical value)))
909 (setq attributes (delq 'shinjigen-1-radical attributes))
911 (when (and (memq 'ideographic- attributes)
912 (setq value (get-char-attribute char 'ideographic-)))
913 (insert "(ideographic- ")
914 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
917 (setq cell (car value))
919 (setq cell (decode-char '=ucs cell)))
920 (cond ((characterp cell)
924 (insert (format "%S" cell))
925 (char-db-insert-char-spec cell readable))
926 (setq separator lbs))
930 (if (consp (car cell))
931 (char-db-insert-char-spec cell readable)
932 (char-db-insert-char-reference cell readable))
933 (setq separator lbs))
937 (insert (prin1-to-string cell))
938 (setq separator " ")))
939 (setq value (cdr value)))
941 (insert line-breaking)
942 (setq attributes (delq 'ideographic- attributes)))
943 (when (and (memq 'total-strokes attributes)
944 (setq value (get-char-attribute char 'total-strokes)))
945 (insert (format "(total-strokes . %S)%s"
948 (setq attributes (delq 'total-strokes attributes))
950 (when (and (memq '->ideograph attributes)
951 (setq value (get-char-attribute char '->ideograph)))
952 (insert (format "(->ideograph\t%s)%s"
953 (mapconcat (lambda (code)
954 (cond ((symbolp code)
957 (format "#x%04X" code))
960 line-breaking code))))
963 (setq attributes (delq '->ideograph attributes))
965 ;; (when (and (memq '->decomposition attributes)
966 ;; (setq value (get-char-attribute char '->decomposition)))
967 ;; (insert (format "(->decomposition\t%s)%s"
968 ;; (mapconcat (lambda (code)
969 ;; (cond ((symbolp code)
970 ;; (symbol-name code))
971 ;; ((characterp code)
973 ;; (format "%S" code)
978 ;; (format "#x%04X" code))
980 ;; (format "%s%S" line-breaking code))))
983 ;; (setq attributes (delq '->decomposition attributes))
985 (if (equal (get-char-attribute char '->titlecase)
986 (get-char-attribute char '->uppercase))
987 (setq attributes (delq '->titlecase attributes)))
988 (when (and (memq '->mojikyo attributes)
989 (setq value (get-char-attribute char '->mojikyo)))
990 (insert (format "(->mojikyo\t\t. %06d)\t; %c%s"
991 value (decode-char 'mojikyo value)
993 (setq attributes (delq '->mojikyo attributes))
995 (when (and (memq 'hanyu-dazidian-vol attributes)
996 (setq value (get-char-attribute char 'hanyu-dazidian-vol)))
997 (insert (format "(hanyu-dazidian-vol . %d)%s"
998 value line-breaking))
999 (setq attributes (delq 'hanyu-dazidian-vol attributes))
1001 (when (and (memq 'hanyu-dazidian-page attributes)
1002 (setq value (get-char-attribute char 'hanyu-dazidian-page)))
1003 (insert (format "(hanyu-dazidian-page . %d)%s"
1004 value line-breaking))
1005 (setq attributes (delq 'hanyu-dazidian-page attributes))
1007 (when (and (memq 'hanyu-dazidian-char attributes)
1008 (setq value (get-char-attribute char 'hanyu-dazidian-char)))
1009 (insert (format "(hanyu-dazidian-char . %d)%s"
1010 value line-breaking))
1011 (setq attributes (delq 'hanyu-dazidian-char attributes))
1014 (dolist (ignored '(composition
1015 ->denotational <-subsumptive ->ucs-unified
1016 ->ideographic-component-forms))
1017 (setq attributes (delq ignored attributes))))
1019 (setq name (car attributes))
1020 (if (setq value (get-char-attribute char name))
1021 (cond ((setq ret (find-charset name))
1022 (setq name (charset-name ret))
1023 (if (and (not (memq name dest-ccss))
1025 (setq value (get-char-attribute char name))
1026 (setq dest-ccss (cons name dest-ccss))))
1027 (char-db-insert-ccs-feature name value line-breaking))
1029 ((string-match "^=>ucs@" (symbol-name name))
1030 (insert (format "(%-18s . #x%04X)\t; %c%s"
1031 name value (decode-char '=ucs value)
1034 ((eq name 'jisx0208-1978/4X)
1035 (insert (format "(%-18s . #x%04X)%s"
1041 (not (eq name '->subsumptive))
1042 (not (eq name '->uppercase))
1043 (not (eq name '->lowercase))
1044 (not (eq name '->titlecase))
1045 (not (eq name '->canonical))
1046 (not (eq name '->Bopomofo))
1047 (not (eq name '->mistakable))
1048 (not (eq name '->ideographic-variants))
1049 (null (get-char-attribute
1050 char (intern (format "%s*sources" name))))
1051 (not (string-match "\\*sources$" (symbol-name name)))
1052 (null (get-char-attribute
1053 char (intern (format "%s*note" name))))
1054 (not (string-match "\\*note$" (symbol-name name)))
1055 (or (eq name '<-identical)
1056 (eq name '<-uppercase)
1057 (eq name '<-lowercase)
1058 (eq name '<-titlecase)
1059 (eq name '<-canonical)
1060 (eq name '<-ideographic-variants)
1061 ;; (eq name '<-synonyms)
1062 (string-match "^<-synonyms" (symbol-name name))
1063 (eq name '<-mistakable)
1064 (when (string-match "^->" (symbol-name name))
1066 ((string-match "^->fullwidth" (symbol-name name))
1067 (not (and (consp value)
1068 (characterp (car value))
1070 (car value) '=ucs 'defined-only)))
1075 ((or (eq name 'ideographic-structure)
1076 (eq name 'ideographic-combination)
1077 (eq name 'ideographic-)
1078 (eq name '=decomposition)
1079 (string-match "^=>decomposition" (symbol-name name))
1080 (string-match "^\\(->\\|<-\\)[^*]*$" (symbol-name name))
1081 (string-match "^\\(->\\|<-\\)[^*]*\\*sources$"
1084 (char-db-insert-relation-feature char name value
1087 ((memq name '(ideograph=
1088 original-ideograph-of
1089 ancient-ideograph-of
1092 ;; simplified-ideograph-of
1093 ideographic-variants
1094 ;; ideographic-different-form-of
1096 (insert (format "(%-18s%s " name line-breaking))
1097 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1099 (while (consp value)
1100 (setq cell (car value))
1101 (if (and (consp cell)
1106 (char-db-insert-alist cell readable)
1107 (setq separator lbs))
1110 (insert (prin1-to-string cell))
1111 (setq separator " "))
1112 (setq value (cdr value)))
1114 (insert line-breaking))
1116 (insert (format "(%-18s " name))
1117 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1119 (while (consp value)
1120 (setq cell (car value))
1121 (if (and (consp cell)
1123 (setq ret (condition-case nil
1131 (setq key (car (car rest)))
1132 (if (find-charset key)
1133 (setq cal (cons key cal))
1134 (setq al (cons key al)))
1135 (setq rest (cdr rest)))
1138 (insert-char-attributes ret
1141 (setq separator lbs))
1142 (setq ret (prin1-to-string cell))
1144 (if (< (+ (current-column)
1151 (setq separator " "))
1152 (setq value (cdr value)))
1154 (insert line-breaking))
1156 (insert (format "(%-18s" name))
1157 (setq ret (prin1-to-string value))
1158 (unless (< (+ (current-column)
1162 (insert line-breaking))
1163 (insert " . " ret ")" line-breaking)
1164 ;; (insert (format "(%-18s . %S)%s"
1169 (setq attributes (cdr attributes)))
1172 (defun insert-char-data (char &optional readable
1175 (narrow-to-region (point)(point))
1176 (insert "(define-char
1178 (insert-char-attributes char readable attributes)
1180 (goto-char (point-min))
1181 (while (re-search-forward "[ \t]+$" nil t)
1184 (goto-char (point-min))
1185 (while (re-search-forward "[ \t][ \t][ \t]*" nil t)
1186 (let ((column (current-column))
1187 (indent-tabs-mode t))
1188 (delete-region (match-beginning 0) (point))
1189 (indent-to column)))
1190 (goto-char (point-max))
1191 ;; (tabify (point-min)(point-max))
1194 (defun insert-char-data-with-variant (char &optional printable
1196 script excluded-script)
1197 (insert-char-data char printable)
1198 (let ((variants (char-variants char))
1201 (setq variants (sort variants #'<))
1202 (setq rest variants)
1203 (setq variants (cons char variants))
1205 (setq variant (car rest))
1206 (unless (get-char-attribute variant '<-subsumptive)
1207 (if (and (or (null script)
1208 (null (setq vs (get-char-attribute variant 'script)))
1210 (or (null excluded-script)
1211 (null (setq vs (get-char-attribute variant 'script)))
1212 (not (memq excluded-script vs))))
1213 (unless (and no-ucs-unified (get-char-attribute variant '=ucs))
1214 (insert-char-data variant printable)
1215 (if (setq ret (char-variants variant))
1217 (or (memq (car ret) variants)
1218 ;; (get-char-attribute (car ret) '<-subsumptive)
1219 (setq rest (nconc rest (list (car ret)))))
1220 (setq ret (cdr ret)))))))
1221 (setq rest (cdr rest)))))
1223 (defun insert-char-range-data (min max &optional script excluded-script)
1226 (while (<= code max)
1227 (setq char (decode-char '=ucs code))
1228 (if (encode-char char '=ucs 'defined-only)
1229 (insert-char-data-with-variant char nil 'no-ucs-unified
1230 script excluded-script))
1231 (setq code (1+ code)))))
1233 (defun write-char-range-data-to-file (min max file
1234 &optional script excluded-script)
1235 (let ((coding-system-for-write char-db-file-coding-system))
1237 (insert (format ";; -*- coding: %s -*-\n"
1238 char-db-file-coding-system))
1239 (insert-char-range-data min max script excluded-script)
1240 (write-region (point-min)(point-max) file))))
1242 (defvar what-character-original-window-configuration)
1245 (defun what-char-definition (char)
1246 (interactive (list (char-after)))
1247 (let ((buf (get-buffer-create "*Character Description*"))
1248 (the-buf (current-buffer))
1249 (win-conf (current-window-configuration)))
1251 (make-local-variable 'what-character-original-window-configuration)
1252 (setq what-character-original-window-configuration win-conf)
1253 (setq buffer-read-only nil)
1257 (insert-char-data-with-variant char 'printable)
1258 (unless (char-attribute-alist char)
1259 (insert (format ";; = %c\n"
1260 (let* ((rest (split-char char))
1264 (setq code (logior (lsh code 8)
1266 (decode-char ccs code)))))
1267 ;; (char-db-update-comment)
1268 (set-buffer-modified-p nil)
1269 (view-mode the-buf (lambda (buf)
1270 (set-window-configuration
1271 what-character-original-window-configuration)
1273 (goto-char (point-min)))
1275 (set-window-configuration
1276 what-character-original-window-configuration)
1277 (signal (car err) (cdr err)))))))
1283 (provide 'char-db-util)
1285 ;;; char-db-util.el ends here