1 ;;; char-db-util.el --- Character Database utility -*- coding: utf-8-er; -*-
3 ;; Copyright (C) 1998,1999,2000,2001,2002,2003,2004,2005,2006,2007,
4 ;; 2008,2009,2010,2011,2012,2013,2014,2015,2016 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 ; ?旨 ?曰 ?乃 ?丂 ?可 ?兮 ?号 ?亏 ?喜 ?壴 ; 160
84 ?鼓 ?豈 ?豆 ?豊 ?豐 ?䖒 ?虍 ?虎 ?虤 ?皿 ; 170
85 ?𠙴 ?去 ?血 ?丶 ?丹 ?青 ?井 ?皀 ?鬯 ?食 ; 180
86 ?亼 ?會 ?倉 ?入 ?缶 ?矢 ?高 ?冂 ?𩫏 ?京 ; 190
87 ?亯 ?𣆪 ?畗 ?㐭 ?嗇 ?來 ?麥 ?夊 ?舛 ?䑞 ; 200
88 ?韋 ?弟 ?夂 ?久 ?桀 ?木 ?東 ?林 ?才 ?叒 ; 210
89 ?之 ?帀 ?出 ?𣎵 ?生 ?乇 ?𠂹 ?𠌶 ?華 ?𥝌 ; 220
90 ?稽 ?巢 ?桼 ?束 ?㯻 ?囗 ?員 ?貝 ?邑 ?𨛜 ; 230
91 ?日 ?旦 ?倝 ?㫃 ?冥 ?晶 ?月 ?有 ?明 ?囧 ; 240
92 ?夕 ?多 ?毌 ?𢎘 ?𣐺 ?卣 ?齊 ?朿 ?片 ?鼎 ; 250
93 ?克 ?彔 ?禾 ?秝 ?黍 ?香 ?米 ?毇 ?臼 ?凶 ; 260
94 ?𣎳 ?林 ?麻 ?尗 ?耑 ?韭 ?瓜 ?瓠 ?宀 ?宮 ; 270
95 ?呂 ?穴 ?㝱 ?𤕫 ?冖 ?𠔼 ?冃 ?㒳 ?网 ?襾 ; 280
96 ?巾 ?巿 ?帛 ?白 ?㡀 ?黹 ?人 ?𠤎 ?匕 ?从 ; 290
97 ?比 ?北 ?丘 ?㐺 ?𡈼 ?重 ?臥 ?身 ?㐆 ?衣 ; 300
98 ?裘 ?老 ?毛 ?毳 ?尸 ?尺 ?尾 ?履 ?舟 ?方 ; 310
99 ?儿 ?兄 ?兂 ?皃 ?𠑹 ?先 ?秃 ?見 ?覞 ?欠 ; 320
100 ?㱃 ?㳄 ?旡 ?頁 ?𦣻 ?面 ?丏 ?首 ?𥄉 ?須 ; 330
101 ?彡 ?彣 ?文 ?髟 ?后 ?司 ?卮 ?卩 ?印 ?色 ; 340
102 ?𠨍 ?辟 ?勹 ?包 ?茍 ?鬼 ?甶 ?厶 ?嵬 ?山 ; 350
103 ?屾 ?屵 ?广 ?厂 ?丸 ?危 ?石 ?長 ?勿 ?冄 ; 360
104 ?而 ?豕 ?㣇 ?彑 ?豚 ?豸 ?𤉡 ?易 ?象 ?馬 ; 370
105 ?𢊁 ?鹿 ?麤 ?㲋 ?兔 ?萈 ?犬 ?㹜 ?鼠 ?能 ; 380
106 ?熊 ?火 ?炎 ?黑 ?囪 ?焱 ?炙 ?赤 ?大 ?亦 ; 390
109 (defun shuowen-radical (number)
110 (aref shuowen-radicals (1- number)))
112 (defvar char-db-file-coding-system 'utf-8-mcs-er)
114 (defvar char-db-ignored-attributes '(ideographic-products))
116 (defvar char-db-coded-charset-priority-list
212 ;; =>>>adobe-japan1-0
213 ;; =>>>adobe-japan1-1
214 ;; =>>>adobe-japan1-2
215 ;; =>>>adobe-japan1-3
216 ;; =>>>adobe-japan1-4
217 ;; =>>>adobe-japan1-5
218 ;; =>>>adobe-japan1-6
222 ;; =>>>hanyo-denshi/ja
223 ;; =>>>hanyo-denshi/jb
224 ;; =>>>hanyo-denshi/jc
225 ;; =>>>hanyo-denshi/ft
226 ;; =>>>hanyo-denshi/ib
227 ;; =>>>hanyo-denshi/hg
228 ;; =>>>hanyo-denshi/jt
229 ;; =>>>hanyo-denshi/ks
346 ;;; @ char-db formatters
349 (defun char-db-make-char-spec (char)
351 (cond ((characterp char)
352 (cond ((and (setq ret (encode-char char '=ucs 'defined-only))
353 (not (and (<= #xE000 ret)(<= ret #xF8FF))))
354 (setq char-spec (list (cons '=ucs ret)))
355 (cond ((setq ret (get-char-attribute char 'name))
356 (setq char-spec (cons (cons 'name ret) char-spec))
358 ((setq ret (get-char-attribute char 'name*))
359 (setq char-spec (cons (cons 'name* ret) char-spec))
362 ((encode-char char '=mj 'defined-only)
364 (dolist (ccs (charset-list))
365 (if (and (or (eq ccs '=mj)
366 ;; (eq (charset-property ccs 'iso-ir) 177)
367 (string-match "=ucs@" (symbol-name ccs))
369 (setq ccs (charset-name ccs))
370 (null (assq ccs char-spec))
371 (setq ret (encode-char char ccs 'defined-only)))
372 (setq char-spec (cons (cons ccs ret) char-spec))))
374 ((encode-char char '==mj 'defined-only)
376 (dolist (ccs (charset-list))
377 (if (and (or (eq ccs '==mj)
378 ;; (eq (charset-property ccs 'iso-ir) 177)
379 (string-match "=ucs@" (symbol-name ccs))
381 (setq ccs (charset-name ccs))
382 (null (assq ccs char-spec))
383 (setq ret (encode-char char ccs 'defined-only)))
384 (setq char-spec (cons (cons ccs ret) char-spec))))
386 ((encode-char char '=adobe-japan1 'defined-only)
388 (dolist (ccs (charset-list))
389 (if (and (or (memq ccs
398 ;; (eq (charset-property ccs 'iso-ir) 177)
399 (string-match "=ucs@" (symbol-name ccs))
401 (setq ccs (charset-name ccs))
402 (null (assq ccs char-spec))
403 (setq ret (encode-char char ccs 'defined-only)))
404 (setq char-spec (cons (cons ccs ret) char-spec))))
406 ((encode-char char '==adobe-japan1 'defined-only)
408 (dolist (ccs (charset-list))
409 (if (and (or (memq ccs
418 ;; (eq (charset-property ccs 'iso-ir) 177)
419 (string-match "=ucs@" (symbol-name ccs))
421 (setq ccs (charset-name ccs))
422 (null (assq ccs char-spec))
423 (setq ret (encode-char char ccs 'defined-only)))
424 (setq char-spec (cons (cons ccs ret) char-spec))))
428 (let ((rest char-db-coded-charset-priority-list)
431 (setq ccs (charset-name
432 (find-charset (car rest))))
434 (encode-char char ccs
436 (throw 'tag (cons ccs ret)))
437 (setq rest (cdr rest))))))
438 (setq char-spec (list ret))
439 (dolist (ccs (delq (car ret) (charset-list)))
440 (if (and (or (charset-iso-final-char ccs)
447 (eq (charset-property ccs 'iso-ir) 177)
448 ;; (string-match "=ucs@" (symbol-name ccs))
450 (setq ccs (charset-name ccs))
451 (null (assq ccs char-spec))
452 (setq ret (encode-char char ccs 'defined-only)))
453 (setq char-spec (cons (cons ccs ret) char-spec))))
455 (setq char-spec (split-char char)))
456 (cond ((setq ret (get-char-attribute char 'name))
457 (setq char-spec (cons (cons 'name ret) char-spec))
459 ((setq ret (get-char-attribute char 'name*))
460 (setq char-spec (cons (cons 'name* ret) char-spec))
463 ((setq ret (get-char-attribute
464 char 'ideographic-combination))
466 (cons (cons 'ideographic-combination ret)
473 (defun char-db-insert-char-spec (char &optional readable column
476 (setq column (current-column)))
477 (let (char-spec temp-char)
478 (setq char-spec (char-db-make-char-spec char))
479 (unless (or (characterp char) ; char
481 (setq char (find-char char-spec))
483 ;; define temporary character
484 ;; Current implementation is dirty.
485 (setq temp-char (define-char (cons '(ideograph-daikanwa . 0)
487 (remove-char-attribute temp-char 'ideograph-daikanwa)
488 (setq char temp-char))
489 (insert-char-attributes char
491 (union (mapcar #'car char-spec)
495 ;; undefine temporary character
496 ;; Current implementation is dirty.
497 (setq char-spec (char-attribute-alist temp-char))
499 (remove-char-attribute temp-char (car (car char-spec)))
500 (setq char-spec (cdr char-spec))))))
502 (defun char-db-insert-alist (alist &optional readable column)
504 (setq column (current-column)))
506 (concat "\n" (make-string (1+ column) ?\ )))
510 lbs cell rest separator)
513 (setq name (car (car alist))
514 value (cdr (car alist)))
515 (cond ((eq name 'char)
517 (if (setq ret (condition-case nil
525 (setq key (car (car value)))
526 ;; (if (find-charset key)
527 ;; (setq cal (cons key cal))
528 (setq al (cons key al))
530 (setq value (cdr value)))
531 (insert-char-attributes ret
535 (insert (prin1-to-string value)))
537 (insert line-breaking))
539 (insert (format "(%-18s " name))
540 (setq lbs (concat "\n" (make-string (current-column) ?\ )))
542 (setq cell (car value))
543 (if (and (consp cell)
545 (setq ret (condition-case nil
555 (setq key (car (car rest)))
556 ;; (if (find-charset key)
557 ;; (setq cal (cons key cal))
558 (setq al (cons key al))
560 (setq rest (cdr rest)))
563 (insert-char-attributes ret
567 (setq separator lbs))
570 (insert (prin1-to-string cell))
571 (setq separator " "))
572 (setq value (cdr value)))
574 (insert line-breaking))
576 (insert (format "(%-18s . %S)%s"
579 (setq alist (cdr alist))))
582 (defun char-db-insert-char-reference (plist &optional readable column)
584 (setq column (current-column)))
586 (concat "\n" (make-string (1+ column) ?\ )))
591 (setq name (pop plist))
592 (setq value (pop plist))
593 (cond ((eq name :char)
596 (cond ((numberp value)
597 (setq value (decode-char '=ucs value)))
599 ;; (setq value (or (find-char value)
602 (char-db-insert-char-spec value readable)
603 (insert line-breaking)
606 (insert (format "%s%s\t%d ; %c%s"
609 (ideographic-radical value)
613 (insert (format "%s%s\t%S" separator name value))
614 (setq separator line-breaking)))
618 (defun char-db-decode-isolated-char (ccs code-point)
621 (cond ((eq ccs 'arabic-iso8859-6)
622 (decode-char ccs code-point))
624 ;; (decode-builtin-char '==gt code-point))
625 ((and (memq ccs '(=gt-pj-1
636 (setq ret (decode-char ccs code-point))
637 (setq ret (encode-char ret '=gt 'defined-only)))
638 (decode-builtin-char '=gt ret))
640 (decode-builtin-char ccs code-point))))
642 (or (decode-char ccs code-point)
643 (define-char (list (cons ccs code-point)))))
644 ((and (<= 0 (char-int ret))
645 (<= (char-int ret) #x1F))
646 (decode-char '=ucs (+ #x2400 (char-int ret))))
647 ((= (char-int ret) #x7F)
651 (defvar char-db-convert-obsolete-format t)
653 (defun char-db-insert-ccs-feature (name value line-breaking)
659 ((memq name '(=>iwds-1
662 =shinjigen@1ed ==shinjigen@1ed
663 =shinjigen@rev ==shinjigen@rev
664 =shinjigen/+p@rev ==shinjigen/+p@rev
665 ===daikanwa/ho ==daikanwa/ho
666 =daikanwa/ho =>>daikanwa/ho =>daikanwa/ho))
667 "(%-18s . %04d)\t; %c")
668 ((eq name '=shinjigen@1ed/24pr)
669 "(%-18s . %04d)\t; %c")
673 ==daikanwa =daikanwa =>>daikanwa =>daikanwa
674 =daikanwa@rev1 =daikanwa@rev2
675 =daikanwa/+p ==daikanwa/+p ===daikanwa/+p
677 =daikanwa/+2p =>>daikanwa/+2p
682 =adobe-japan1-0 ==adobe-japan1-0 ===adobe-japan1-0
683 =adobe-japan1-1 ==adobe-japan1-1 ===adobe-japan1-1
684 =adobe-japan1-2 ==adobe-japan1-2 ===adobe-japan1-2
685 =adobe-japan1-3 ==adobe-japan1-3 ===adobe-japan1-3
686 =adobe-japan1-4 ==adobe-japan1-4 ===adobe-japan1-4
687 =adobe-japan1-5 ==adobe-japan1-5 ===adobe-japan1-5
688 =adobe-japan1-6 ==adobe-japan1-6 ===adobe-japan1-6
689 =>>adobe-japan1-0 =+>adobe-japan1-0
690 =>>adobe-japan1-1 =+>adobe-japan1-1
691 =>>adobe-japan1-2 =+>adobe-japan1-2
692 =>>adobe-japan1-3 =+>adobe-japan1-3
693 =>>adobe-japan1-4 =+>adobe-japan1-4
694 =>>adobe-japan1-5 =+>adobe-japan1-5
695 =>>adobe-japan1-6 =+>adobe-japan1-6
696 =>cbeta =cbeta =>>cbeta ==cbeta ===cbeta
697 =zinbun-oracle =>zinbun-oracle
698 ===hng-jou ===hng-keg ===hng-dng ===hng-mam
699 ===hng-drt ===hng-kgk ===hng-myz ===hng-kda
700 ===hng-khi ===hng-khm ===hng-hok ===hng-kyd ===hng-sok
701 ===hng-yhk ===hng-kak ===hng-kar ===hng-kae
702 ===hng-sys ===hng-tsu ===hng-tzj
703 ===hng-hos ===hng-nak ===hng-jhk
704 ===hng-hod ===hng-gok ===hng-ink ===hng-nto
705 ===hng-nkm ===hng-k24 ===hng-nkk
706 ===hng-kcc ===hng-kcj ===hng-kbk ===hng-sik
707 ===hng-skk ===hng-kyu ===hng-ksk ===hng-wan
708 ===hng-okd ===hng-wad ===hng-kmi
709 ===hng-zkd ===hng-doh ===hng-jyu
710 ===hng-tzs ===hng-kss ===hng-kyo
712 ;; (string-match "^=adobe-" (symbol-name name))
714 "(%-18s . %05d)\t; %c")
715 ((memq name '(=hanyo-denshi/ks
716 ==hanyo-denshi/ks ===hanyo-denshi/ks
719 =mj ==mj ===mj =>>mj =>mj
721 "(%-18s . %06d)\t; %c")
722 ((memq name '(=hanyo-denshi/tk ==hanyo-denshi/tk))
723 "(%-18s . %08d)\t; %c")
724 ((>= (charset-dimension name) 2)
725 "(%-18s . #x%04X)\t; %c")
727 "(%-18s . #x%02X)\t; %c"))
729 (if (= (charset-iso-graphic-plane name) 1)
731 (cond ((= (charset-dimension name) 1)
733 ((= (charset-dimension name) 2)
735 ((= (charset-dimension name) 3)
739 (char-db-decode-isolated-char name value)))
740 (if (and (= (charset-chars name) 94)
741 (= (charset-dimension name) 2))
742 (insert (format " [%02d-%02d]"
743 (- (lsh value -8) 32)
744 (- (logand value 255) 32))))
747 (insert (format "(%-18s . %s)" name value))
749 (insert line-breaking))
751 (defun char-db-insert-relation-feature (char name value line-breaking
753 (insert (format "(%-18s%s " name line-breaking))
754 (let ((lbs (concat "\n" (make-string (current-column) ?\ )))
755 separator cell sources required-features
758 (setq cell (car value))
760 (setq cell (decode-char '=ucs cell)))
762 ((eq name '->subsumptive)
763 (when (or (not (some (lambda (atr)
764 (get-char-attribute cell atr))
765 char-db-ignored-attributes))
767 (encode-char cell ccs 'defined-only))
771 (let ((char-db-ignored-attributes
773 char-db-ignored-attributes)))
774 (insert-char-attributes cell readable nil nil 'for-sub-node))
775 (setq separator lbs))
780 char (intern (format "%s*sources" name))))
781 (setq required-features nil)
782 (dolist (source sources)
786 shinjigen shinjigen@1ed shinjigen@rev))
787 (setq required-features
788 (union required-features
800 =shinjigen/+p@rev))))
802 (setq required-features
803 (union required-features
808 ((find-charset (setq ret (intern (format "=%s" source))))
809 (setq required-features
810 (cons ret required-features)))
811 (t (setq required-features
812 (cons source required-features)))))
813 (cond ((string-match "@JP" (symbol-name name))
814 (setq required-features
815 (union required-features
823 ((string-match "@CN" (symbol-name name))
824 (setq required-features
825 (union required-features
832 (insert (format "%S" cell))
833 (char-db-insert-char-spec cell readable
836 (setq separator lbs))
840 (if (consp (car cell))
841 (char-db-insert-char-spec cell readable)
842 (char-db-insert-char-reference cell readable))
843 (setq separator lbs))
847 (insert (prin1-to-string cell))
848 (setq separator " ")))
849 (setq value (cdr value)))
851 (insert line-breaking)))
853 (defun insert-char-attributes (char &optional readable attributes column
856 (setq column (current-column)))
857 (let (name value ; has-long-ccs-name
861 (concat "\n" (make-string (1+ column) ?\ )))
862 lbs cell separator ret
864 dest-ccss ; sources required-features
869 (if (consp attributes)
871 (dolist (name attributes)
872 (unless (memq name char-db-ignored-attributes)
873 (if (find-charset name)
877 (dolist (name (char-attribute-list))
878 (unless (memq name char-db-ignored-attributes)
879 (if (find-charset name)
883 #'char-attribute-name<)))
885 (when (memq '<-subsumptive attributes)
886 (when (or readable (not for-sub-node))
887 (when (setq value (get-char-attribute char '<-subsumptive))
888 (char-db-insert-relation-feature char '<-subsumptive value
891 (setq attributes (delq '<-subsumptive attributes)))
892 (when (and (memq '<-denotational attributes)
893 (setq value (get-char-attribute char '<-denotational)))
894 (char-db-insert-relation-feature char '<-denotational value
897 (setq attributes (delq '<-denotational attributes)))
898 (when (and (memq '<-denotational@component attributes)
899 (setq value (get-char-attribute char '<-denotational@component)))
900 (char-db-insert-relation-feature char '<-denotational@component value
903 (setq attributes (delq '<-denotational@component attributes)))
904 (when (and (memq 'name attributes)
905 (setq value (get-char-attribute char 'name)))
907 (if (> (+ (current-column) (length value)) 48)
910 value line-breaking))
911 (setq attributes (delq 'name attributes))
913 (when (and (memq 'name* attributes)
914 (setq value (get-char-attribute char 'name*)))
916 (if (> (+ (current-column) (length value)) 48)
919 value line-breaking))
920 (setq attributes (delq 'name* attributes))
922 (when (and (memq 'script attributes)
923 (setq value (get-char-attribute char 'script)))
924 (insert (format "(script\t\t%s)%s"
925 (mapconcat (function prin1-to-string)
928 (setq attributes (delq 'script attributes))
930 (dolist (name '(=>ucs =>ucs*))
931 (when (and (memq name attributes)
932 (setq value (get-char-attribute char name)))
933 (insert (format "(%-18s . #x%04X)\t; %c%s"
934 name value (decode-char '=ucs value)
936 (setq attributes (delq name attributes))))
937 (dolist (name '(=>ucs@gb =>ucs@big5))
938 (when (and (memq name attributes)
939 (setq value (get-char-attribute char name)))
940 (insert (format "(%-18s . #x%04X)\t; %c%s"
945 (symbol-name name) 2)))
948 (setq attributes (delq name attributes))
950 ;; (dolist (name '(=>daikanwa))
951 ;; (when (and (memq name attributes)
952 ;; (setq value (get-char-attribute char name)))
954 ;; (if (integerp value)
955 ;; (format "(%-18s . %05d)\t; %c%s"
956 ;; name value (decode-char '=daikanwa value)
958 ;; (format "(%-18s %s)\t; %c%s"
960 ;; (mapconcat (function prin1-to-string)
962 ;; (char-representative-of-daikanwa char)
964 ;; (setq attributes (delq name attributes))))
965 (when (and (memq 'general-category attributes)
966 (setq value (get-char-attribute char 'general-category)))
968 "(general-category\t%s) ; %s%s"
969 (mapconcat (lambda (cell)
972 (cond ((rassoc value unidata-normative-category-alist)
973 "Normative Category")
974 ((rassoc value unidata-informative-category-alist)
975 "Informative Category")
979 (setq attributes (delq 'general-category attributes))
981 (when (and (memq 'bidi-category attributes)
982 (setq value (get-char-attribute char 'bidi-category)))
983 (insert (format "(bidi-category\t. %S)%s"
986 (setq attributes (delq 'bidi-category attributes))
988 (unless (or (not (memq 'mirrored attributes))
989 (eq (setq value (get-char-attribute char 'mirrored 'empty))
991 (insert (format "(mirrored\t\t. %S)%s"
994 (setq attributes (delq 'mirrored attributes))
997 ((and (memq 'decimal-digit-value attributes)
998 (setq value (get-char-attribute char 'decimal-digit-value)))
999 (insert (format "(decimal-digit-value . %S)%s"
1002 (setq attributes (delq 'decimal-digit-value attributes))
1003 (when (and (memq 'digit-value attributes)
1004 (setq value (get-char-attribute char 'digit-value)))
1005 (insert (format "(digit-value\t . %S)%s"
1008 (setq attributes (delq 'digit-value attributes))
1010 (when (and (memq 'numeric-value attributes)
1011 (setq value (get-char-attribute char 'numeric-value)))
1012 (insert (format "(numeric-value\t . %S)%s"
1015 (setq attributes (delq 'numeric-value attributes))
1019 (when (and (memq 'digit-value attributes)
1020 (setq value (get-char-attribute char 'digit-value)))
1021 (insert (format "(digit-value\t. %S)%s"
1024 (setq attributes (delq 'digit-value attributes))
1026 (when (and (memq 'numeric-value attributes)
1027 (setq value (get-char-attribute char 'numeric-value)))
1028 (insert (format "(numeric-value\t. %S)%s"
1031 (setq attributes (delq 'numeric-value attributes))
1033 (when (and (memq 'iso-10646-comment attributes)
1034 (setq value (get-char-attribute char 'iso-10646-comment)))
1035 (insert (format "(iso-10646-comment\t. %S)%s"
1038 (setq attributes (delq 'iso-10646-comment attributes))
1040 (when (and (memq 'morohashi-daikanwa attributes)
1041 (setq value (get-char-attribute char 'morohashi-daikanwa)))
1042 (insert (format "(morohashi-daikanwa\t%s)%s"
1043 (mapconcat (function prin1-to-string) value " ")
1045 (setq attributes (delq 'morohashi-daikanwa attributes))
1049 (when (and (memq 'ideographic-radical attributes)
1050 (setq value (get-char-attribute char 'ideographic-radical)))
1051 (setq radical value)
1052 (insert (format "(ideographic-radical . %S)\t; %c%s"
1054 (ideographic-radical radical)
1056 (setq attributes (delq 'ideographic-radical attributes))
1058 (when (and (memq 'shuowen-radical attributes)
1059 (setq value (get-char-attribute char 'shuowen-radical)))
1060 (insert (format "(shuowen-radical\t. %S)\t; %c%s"
1062 (shuowen-radical value)
1064 (setq attributes (delq 'shuowen-radical attributes))
1069 char-db-feature-domains
1071 (dolist (feature (char-attribute-list))
1072 (setq feature (symbol-name feature))
1074 "\\(radical\\|strokes\\)@\\([^@*]+\\)\\(\\*\\|$\\)"
1076 (setq domain (intern (match-string 2 feature)))
1077 (unless (memq domain dest)
1078 (setq dest (cons domain dest)))))
1079 (sort dest #'string<))))
1080 (setq key (intern (format "%s@%s" 'ideographic-radical domain)))
1081 (when (and (memq key attributes)
1082 (setq value (get-char-attribute char key)))
1083 (setq radical value)
1084 (insert (format "(%s . %S)\t; %c%s"
1087 (ideographic-radical radical)
1089 (setq attributes (delq key attributes))
1091 (setq key (intern (format "%s@%s" 'ideographic-strokes domain)))
1092 (when (and (memq key attributes)
1093 (setq value (get-char-attribute char key)))
1094 (setq strokes value)
1095 (insert (format "(%s . %S)%s"
1099 (setq attributes (delq key attributes))
1101 (setq key (intern (format "%s@%s" 'total-strokes domain)))
1102 (when (and (memq key attributes)
1103 (setq value (get-char-attribute char key)))
1104 (insert (format "(%s . %S)%s"
1108 (setq attributes (delq key attributes))
1110 (dolist (feature '(ideographic-radical
1113 (setq key (intern (format "%s@%s*sources" feature domain)))
1114 (when (and (memq key attributes)
1115 (setq value (get-char-attribute char key)))
1116 (insert (format "(%s%s" key line-breaking))
1117 (dolist (cell value)
1118 (insert (format " %s" cell)))
1120 (insert line-breaking)
1121 (setq attributes (delq key attributes))
1124 (when (and (memq 'ideographic-strokes attributes)
1125 (setq value (get-char-attribute char 'ideographic-strokes)))
1126 (setq strokes value)
1127 (insert (format "(ideographic-strokes . %S)%s"
1130 (setq attributes (delq 'ideographic-strokes attributes))
1132 (when (and (memq 'kangxi-radical attributes)
1133 (setq value (get-char-attribute char 'kangxi-radical)))
1134 (unless (eq value radical)
1135 (insert (format "(kangxi-radical\t . %S)\t; %c%s"
1137 (ideographic-radical value)
1140 (setq radical value)))
1141 (setq attributes (delq 'kangxi-radical attributes))
1143 (when (and (memq 'kangxi-strokes attributes)
1144 (setq value (get-char-attribute char 'kangxi-strokes)))
1145 (unless (eq value strokes)
1146 (insert (format "(kangxi-strokes\t . %S)%s"
1150 (setq strokes value)))
1151 (setq attributes (delq 'kangxi-strokes attributes))
1153 (when (and (memq 'japanese-radical attributes)
1154 (setq value (get-char-attribute char 'japanese-radical)))
1155 (unless (eq value radical)
1156 (insert (format "(japanese-radical\t . %S)\t; %c%s"
1158 (ideographic-radical value)
1161 (setq radical value)))
1162 (setq attributes (delq 'japanese-radical attributes))
1164 (when (and (memq 'japanese-strokes attributes)
1165 (setq value (get-char-attribute char 'japanese-strokes)))
1166 (unless (eq value strokes)
1167 (insert (format "(japanese-strokes\t . %S)%s"
1171 (setq strokes value)))
1172 (setq attributes (delq 'japanese-strokes attributes))
1174 (when (and (memq 'cns-radical attributes)
1175 (setq value (get-char-attribute char 'cns-radical)))
1176 (insert (format "(cns-radical\t . %S)\t; %c%s"
1178 (ideographic-radical value)
1180 (setq attributes (delq 'cns-radical attributes))
1182 (when (and (memq 'cns-strokes attributes)
1183 (setq value (get-char-attribute char 'cns-strokes)))
1184 (unless (eq value strokes)
1185 (insert (format "(cns-strokes\t . %S)%s"
1189 (setq strokes value)))
1190 (setq attributes (delq 'cns-strokes attributes))
1192 ;; (when (and (memq 'shinjigen-1-radical attributes)
1193 ;; (setq value (get-char-attribute char 'shinjigen-1-radical)))
1194 ;; (unless (eq value radical)
1195 ;; (insert (format "(shinjigen-1-radical . %S)\t; %c%s"
1197 ;; (ideographic-radical value)
1200 ;; (setq radical value)))
1201 ;; (setq attributes (delq 'shinjigen-1-radical attributes))
1203 (when (and (memq 'ideographic- attributes)
1204 (setq value (get-char-attribute char 'ideographic-)))
1205 (insert "(ideographic- ")
1206 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1208 (while (consp value)
1209 (setq cell (car value))
1211 (setq cell (decode-char '=ucs cell)))
1212 (cond ((characterp cell)
1216 (insert (format "%S" cell))
1217 (char-db-insert-char-spec cell readable))
1218 (setq separator lbs))
1222 (if (consp (car cell))
1223 (char-db-insert-char-spec cell readable)
1224 (char-db-insert-char-reference cell readable))
1225 (setq separator lbs))
1229 (insert (prin1-to-string cell))
1230 (setq separator " ")))
1231 (setq value (cdr value)))
1233 (insert line-breaking)
1234 (setq attributes (delq 'ideographic- attributes)))
1235 (when (and (memq 'total-strokes attributes)
1236 (setq value (get-char-attribute char 'total-strokes)))
1237 (insert (format "(total-strokes . %S)%s"
1240 (setq attributes (delq 'total-strokes attributes))
1242 (when (and (memq '->ideograph attributes)
1243 (setq value (get-char-attribute char '->ideograph)))
1244 (insert (format "(->ideograph\t%s)%s"
1245 (mapconcat (lambda (code)
1246 (cond ((symbolp code)
1249 (format "#x%04X" code))
1252 line-breaking code))))
1255 (setq attributes (delq '->ideograph attributes))
1257 ;; (when (and (memq '->decomposition attributes)
1258 ;; (setq value (get-char-attribute char '->decomposition)))
1259 ;; (insert (format "(->decomposition\t%s)%s"
1260 ;; (mapconcat (lambda (code)
1261 ;; (cond ((symbolp code)
1262 ;; (symbol-name code))
1263 ;; ((characterp code)
1265 ;; (format "%S" code)
1270 ;; (format "#x%04X" code))
1272 ;; (format "%s%S" line-breaking code))))
1275 ;; (setq attributes (delq '->decomposition attributes))
1277 (if (equal (get-char-attribute char '->titlecase)
1278 (get-char-attribute char '->uppercase))
1279 (setq attributes (delq '->titlecase attributes)))
1280 (when (and (memq '->mojikyo attributes)
1281 (setq value (get-char-attribute char '->mojikyo)))
1282 (insert (format "(->mojikyo\t\t. %06d)\t; %c%s"
1283 value (decode-char 'mojikyo value)
1285 (setq attributes (delq '->mojikyo attributes))
1287 (when (and (memq 'hanyu-dazidian-vol attributes)
1288 (setq value (get-char-attribute char 'hanyu-dazidian-vol)))
1289 (insert (format "(hanyu-dazidian-vol . %d)%s"
1290 value line-breaking))
1291 (setq attributes (delq 'hanyu-dazidian-vol attributes))
1293 (when (and (memq 'hanyu-dazidian-page attributes)
1294 (setq value (get-char-attribute char 'hanyu-dazidian-page)))
1295 (insert (format "(hanyu-dazidian-page . %d)%s"
1296 value line-breaking))
1297 (setq attributes (delq 'hanyu-dazidian-page attributes))
1299 (when (and (memq 'hanyu-dazidian-char attributes)
1300 (setq value (get-char-attribute char 'hanyu-dazidian-char)))
1301 (insert (format "(hanyu-dazidian-char . %d)%s"
1302 value line-breaking))
1303 (setq attributes (delq 'hanyu-dazidian-char attributes))
1306 (dolist (ignored '(composition
1307 ->denotational <-subsumptive ->ucs-unified
1308 ->ideographic-component-forms))
1309 (setq attributes (delq ignored attributes))))
1311 (setq name (car attributes))
1312 (unless (eq (setq value (get-char-attribute char name 'value-is-empty))
1314 (cond ((setq ret (find-charset name))
1315 (setq name (charset-name ret))
1316 (when (not (memq name dest-ccss))
1317 (setq dest-ccss (cons name dest-ccss))
1318 (char-db-insert-ccs-feature name value line-breaking))
1320 ((string-match "^=>ucs@" (symbol-name name))
1321 (insert (format "(%-18s . #x%04X)\t; %c%s"
1322 name value (decode-char '=ucs value)
1325 ((eq name 'jisx0208-1978/4X)
1326 (insert (format "(%-18s . #x%04X)%s"
1332 (not (eq name '->subsumptive))
1333 (not (eq name '->uppercase))
1334 (not (eq name '->lowercase))
1335 (not (eq name '->titlecase))
1336 (not (eq name '->canonical))
1337 (not (eq name '->Bopomofo))
1338 (not (eq name '->mistakable))
1339 (not (eq name '->ideographic-variants))
1340 (null (get-char-attribute
1341 char (intern (format "%s*sources" name))))
1342 (not (string-match "\\*sources$" (symbol-name name)))
1343 (null (get-char-attribute
1344 char (intern (format "%s*note" name))))
1345 (not (string-match "\\*note$" (symbol-name name)))
1346 (or (eq name '<-identical)
1347 (eq name '<-uppercase)
1348 (eq name '<-lowercase)
1349 (eq name '<-titlecase)
1350 (eq name '<-canonical)
1351 (eq name '<-ideographic-variants)
1352 ;; (eq name '<-synonyms)
1353 (string-match "^<-synonyms" (symbol-name name))
1354 (eq name '<-mistakable)
1355 (when (string-match "^->" (symbol-name name))
1357 ((string-match "^->fullwidth" (symbol-name name))
1358 (not (and (consp value)
1359 (characterp (car value))
1361 (car value) '=ucs 'defined-only)))
1366 ((or (eq name 'ideographic-structure)
1367 (eq name 'ideographic-combination)
1368 (eq name 'ideographic-)
1369 (eq name '=decomposition)
1370 (char-feature-base-name= '=decomposition name)
1371 (char-feature-base-name= '=>decomposition name)
1372 ;; (string-match "^=>*decomposition\\(@[^*]+\\)?$"
1373 ;; (symbol-name name))
1374 (string-match "^\\(->\\|<-\\)[^*]*$" (symbol-name name))
1375 (string-match "^\\(->\\|<-\\)[^*]*\\*sources$"
1378 (char-db-insert-relation-feature char name value
1381 ((memq name '(ideograph=
1382 original-ideograph-of
1383 ancient-ideograph-of
1386 ;; simplified-ideograph-of
1387 ideographic-variants
1388 ;; ideographic-different-form-of
1390 (insert (format "(%-18s%s " name line-breaking))
1391 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1393 (while (consp value)
1394 (setq cell (car value))
1395 (if (and (consp cell)
1400 (char-db-insert-alist cell readable)
1401 (setq separator lbs))
1404 (insert (prin1-to-string cell))
1405 (setq separator " "))
1406 (setq value (cdr value)))
1408 (insert line-breaking))
1410 (insert (format "(%-18s " name))
1411 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1413 (while (consp value)
1414 (setq cell (car value))
1415 (if (and (consp cell)
1417 (setq ret (condition-case nil
1425 (setq key (car (car rest)))
1426 (if (find-charset key)
1427 (setq cal (cons key cal))
1428 (setq al (cons key al)))
1429 (setq rest (cdr rest)))
1432 (insert-char-attributes ret
1436 (setq separator lbs))
1437 (setq ret (prin1-to-string cell))
1439 (if (< (+ (current-column)
1446 (setq separator " "))
1447 (setq value (cdr value)))
1449 (insert line-breaking))
1451 (insert (format "(%-18s" name))
1452 (setq ret (prin1-to-string value))
1453 (unless (< (+ (current-column)
1457 (insert line-breaking))
1458 (insert " . " ret ")" line-breaking)
1459 ;; (insert (format "(%-18s . %S)%s"
1464 (setq attributes (cdr attributes)))
1467 (defun insert-char-data (char &optional readable
1470 (narrow-to-region (point)(point))
1471 (insert "(define-char
1473 (insert-char-attributes char readable attributes)
1475 (goto-char (point-min))
1476 (while (re-search-forward "[ \t]+$" nil t)
1479 (goto-char (point-min))
1480 (while (re-search-forward "[ \t][ \t][ \t]*" nil t)
1481 (let ((column (current-column))
1482 (indent-tabs-mode t))
1483 (delete-region (match-beginning 0) (point))
1484 (indent-to column)))
1485 (goto-char (point-max))
1486 ;; (tabify (point-min)(point-max))
1489 (defun insert-char-data-with-variant (char &optional printable
1491 script excluded-script)
1492 (insert-char-data char printable)
1493 (let ((variants (char-variants char))
1496 (setq variants (sort variants #'<))
1497 (setq rest variants)
1498 (setq variants (cons char variants))
1500 (setq variant (car rest))
1501 (unless (get-char-attribute variant '<-subsumptive)
1502 (if (and (or (null script)
1503 (null (setq vs (get-char-attribute variant 'script)))
1505 (or (null excluded-script)
1506 (null (setq vs (get-char-attribute variant 'script)))
1507 (not (memq excluded-script vs))))
1508 (unless (and no-ucs-unified (get-char-attribute variant '=ucs))
1509 (insert-char-data variant printable)
1510 (if (setq ret (char-variants variant))
1512 (or (memq (car ret) variants)
1513 ;; (get-char-attribute (car ret) '<-subsumptive)
1514 (setq rest (nconc rest (list (car ret)))))
1515 (setq ret (cdr ret)))))))
1516 (setq rest (cdr rest)))))
1518 (defun insert-char-range-data (min max &optional script excluded-script)
1521 (while (<= code max)
1522 (setq char (decode-char '=ucs code))
1523 (if (encode-char char '=ucs 'defined-only)
1524 (insert-char-data-with-variant char nil 'no-ucs-unified
1525 script excluded-script))
1526 (setq code (1+ code)))))
1528 (defun write-char-range-data-to-file (min max file
1529 &optional script excluded-script)
1530 (let ((coding-system-for-write char-db-file-coding-system))
1532 (insert (format ";; -*- coding: %s -*-\n"
1533 char-db-file-coding-system))
1534 (insert-char-range-data min max script excluded-script)
1535 (write-region (point-min)(point-max) file))))
1537 (defvar what-character-original-window-configuration)
1540 (defun what-char-definition (char)
1541 (interactive (list (char-after)))
1542 (let ((buf (get-buffer-create "*Character Description*"))
1543 (the-buf (current-buffer))
1544 (win-conf (current-window-configuration)))
1546 (make-local-variable 'what-character-original-window-configuration)
1547 (setq what-character-original-window-configuration win-conf)
1548 (setq buffer-read-only nil)
1552 (insert-char-data-with-variant char 'printable)
1553 (unless (char-attribute-alist char)
1554 (insert (format ";; = %c\n"
1555 (let* ((rest (split-char char))
1559 (setq code (logior (lsh code 8)
1561 (decode-char ccs code)))))
1562 ;; (char-db-update-comment)
1563 (set-buffer-modified-p nil)
1564 (view-mode the-buf (lambda (buf)
1565 (set-window-configuration
1566 what-character-original-window-configuration)
1568 (goto-char (point-min)))
1570 (set-window-configuration
1571 what-character-original-window-configuration)
1572 (signal (car err) (cdr err)))))))
1578 (provide 'char-db-util)
1580 ;;; char-db-util.el ends here