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,2017 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
214 ;; =>>>adobe-japan1-0
215 ;; =>>>adobe-japan1-1
216 ;; =>>>adobe-japan1-2
217 ;; =>>>adobe-japan1-3
218 ;; =>>>adobe-japan1-4
219 ;; =>>>adobe-japan1-5
220 ;; =>>>adobe-japan1-6
224 ;; =>>>hanyo-denshi/ja
225 ;; =>>>hanyo-denshi/jb
226 ;; =>>>hanyo-denshi/jc
227 ;; =>>>hanyo-denshi/ft
228 ;; =>>>hanyo-denshi/ib
229 ;; =>>>hanyo-denshi/hg
230 ;; =>>>hanyo-denshi/jt
231 ;; =>>>hanyo-denshi/ks
358 =>big5-cdp-itaiji-001
365 ;;; @ char-db formatters
368 (defun char-db-make-char-spec (char)
370 (cond ((characterp char)
371 (cond ((and (setq ret (encode-char char '=ucs 'defined-only))
372 (not (and (<= #xE000 ret)(<= ret #xF8FF))))
373 (setq char-spec (list (cons '=ucs ret)))
374 (cond ((setq ret (get-char-attribute char 'name))
375 (setq char-spec (cons (cons 'name ret) char-spec))
377 ((setq ret (get-char-attribute char 'name*))
378 (setq char-spec (cons (cons 'name* ret) char-spec))
381 ((encode-char char '=mj 'defined-only)
383 (dolist (ccs (charset-list))
384 (if (and (or (eq ccs '=mj)
385 ;; (eq (charset-property ccs 'iso-ir) 177)
386 (string-match "=ucs@" (symbol-name ccs))
388 (setq ccs (charset-name ccs))
389 (null (assq ccs char-spec))
390 (setq ret (encode-char char ccs 'defined-only)))
391 (setq char-spec (cons (cons ccs ret) char-spec))))
393 ((encode-char char '==mj 'defined-only)
395 (dolist (ccs (charset-list))
396 (if (and (or (eq ccs '==mj)
397 ;; (eq (charset-property ccs 'iso-ir) 177)
398 (string-match "=ucs@" (symbol-name ccs))
400 (setq ccs (charset-name ccs))
401 (null (assq ccs char-spec))
402 (setq ret (encode-char char ccs 'defined-only)))
403 (setq char-spec (cons (cons ccs ret) char-spec))))
405 ((encode-char char '=adobe-japan1 'defined-only)
407 (dolist (ccs (charset-list))
408 (if (and (or (memq ccs
417 ;; (eq (charset-property ccs 'iso-ir) 177)
418 (string-match "=ucs@" (symbol-name ccs))
420 (setq ccs (charset-name ccs))
421 (null (assq ccs char-spec))
422 (setq ret (encode-char char ccs 'defined-only)))
423 (setq char-spec (cons (cons ccs ret) char-spec))))
425 ((encode-char char '==adobe-japan1 'defined-only)
427 (dolist (ccs (charset-list))
428 (if (and (or (memq ccs
437 ;; (eq (charset-property ccs 'iso-ir) 177)
438 (string-match "=ucs@" (symbol-name ccs))
440 (setq ccs (charset-name ccs))
441 (null (assq ccs char-spec))
442 (setq ret (encode-char char ccs 'defined-only)))
443 (setq char-spec (cons (cons ccs ret) char-spec))))
447 (let ((rest char-db-coded-charset-priority-list)
450 (setq ccs (charset-name
451 (find-charset (car rest))))
453 (encode-char char ccs
455 (throw 'tag (cons ccs ret)))
456 (setq rest (cdr rest))))))
457 (setq char-spec (list ret))
458 (dolist (ccs (delq (car ret) (charset-list)))
459 (if (and (or (charset-iso-final-char ccs)
466 (eq (charset-property ccs 'iso-ir) 177)
467 ;; (string-match "=ucs@" (symbol-name ccs))
469 (setq ccs (charset-name ccs))
470 (null (assq ccs char-spec))
471 (setq ret (encode-char char ccs 'defined-only)))
472 (setq char-spec (cons (cons ccs ret) char-spec))))
474 (setq char-spec (split-char char)))
475 (cond ((setq ret (get-char-attribute char 'name))
476 (setq char-spec (cons (cons 'name ret) char-spec))
478 ((setq ret (get-char-attribute char 'name*))
479 (setq char-spec (cons (cons 'name* ret) char-spec))
482 ((setq ret (get-char-attribute
483 char 'ideographic-combination))
485 (cons (cons 'ideographic-combination ret)
492 (defun char-db-insert-char-spec (char &optional readable column
495 (setq column (current-column)))
496 (let (char-spec temp-char)
497 (setq char-spec (char-db-make-char-spec char))
498 (unless (or (characterp char) ; char
500 (setq char (find-char char-spec))
502 ;; define temporary character
503 ;; Current implementation is dirty.
504 (setq temp-char (define-char (cons '(ideograph-daikanwa . 0)
506 (remove-char-attribute temp-char 'ideograph-daikanwa)
507 (setq char temp-char))
508 (insert-char-attributes char
510 (union (mapcar #'car char-spec)
514 ;; undefine temporary character
515 ;; Current implementation is dirty.
516 (setq char-spec (char-attribute-alist temp-char))
518 (remove-char-attribute temp-char (car (car char-spec)))
519 (setq char-spec (cdr char-spec))))))
521 (defun char-db-insert-alist (alist &optional readable column)
523 (setq column (current-column)))
525 (concat "\n" (make-string (1+ column) ?\ )))
529 lbs cell rest separator)
532 (setq name (car (car alist))
533 value (cdr (car alist)))
534 (cond ((eq name 'char)
536 (if (setq ret (condition-case nil
544 (setq key (car (car value)))
545 ;; (if (find-charset key)
546 ;; (setq cal (cons key cal))
547 (setq al (cons key al))
549 (setq value (cdr value)))
550 (insert-char-attributes ret
554 (insert (prin1-to-string value)))
556 (insert line-breaking))
558 (insert (format "(%-18s " name))
559 (setq lbs (concat "\n" (make-string (current-column) ?\ )))
561 (setq cell (car value))
562 (if (and (consp cell)
564 (setq ret (condition-case nil
574 (setq key (car (car rest)))
575 ;; (if (find-charset key)
576 ;; (setq cal (cons key cal))
577 (setq al (cons key al))
579 (setq rest (cdr rest)))
582 (insert-char-attributes ret
586 (setq separator lbs))
589 (insert (prin1-to-string cell))
590 (setq separator " "))
591 (setq value (cdr value)))
593 (insert line-breaking))
595 (insert (format "(%-18s . %S)%s"
598 (setq alist (cdr alist))))
601 (defun char-db-insert-char-reference (plist &optional readable column)
603 (setq column (current-column)))
605 (concat "\n" (make-string (1+ column) ?\ )))
610 (setq name (pop plist))
611 (setq value (pop plist))
612 (cond ((eq name :char)
615 (cond ((numberp value)
616 (setq value (decode-char '=ucs value)))
618 ;; (setq value (or (find-char value)
621 (char-db-insert-char-spec value readable)
622 (insert line-breaking)
625 (insert (format "%s%s\t%d ; %c%s"
628 (ideographic-radical value)
632 (insert (format "%s%s\t%S" separator name value))
633 (setq separator line-breaking)))
637 (defun char-db-decode-isolated-char (ccs code-point)
640 (cond ((eq ccs 'arabic-iso8859-6)
641 (decode-char ccs code-point))
643 ;; (decode-builtin-char '==gt code-point))
644 ((and (memq ccs '(=gt-pj-1
655 (setq ret (decode-char ccs code-point))
656 (setq ret (encode-char ret '=gt 'defined-only)))
657 (decode-builtin-char '=gt ret))
659 (decode-builtin-char ccs code-point))))
661 (or (decode-char ccs code-point)
662 (define-char (list (cons ccs code-point)))))
663 ((and (<= 0 (char-int ret))
664 (<= (char-int ret) #x1F))
665 (decode-char '=ucs (+ #x2400 (char-int ret))))
666 ((= (char-int ret) #x7F)
670 (defvar char-db-convert-obsolete-format t)
672 (defun char-db-insert-ccs-feature (name value line-breaking)
678 ((memq name '(=>iwds-1
681 =shinjigen@1ed ==shinjigen@1ed
682 =shinjigen@rev ==shinjigen@rev
683 =shinjigen/+p@rev ==shinjigen/+p@rev
684 ===daikanwa/ho ==daikanwa/ho
685 =daikanwa/ho =>>daikanwa/ho =>daikanwa/ho))
686 "(%-18s . %04d)\t; %c")
687 ((eq name '=shinjigen@1ed/24pr)
688 "(%-18s . %04d)\t; %c")
692 ==daikanwa =daikanwa =>>daikanwa =>daikanwa
693 =daikanwa@rev1 =daikanwa@rev2
694 =daikanwa/+p ==daikanwa/+p ===daikanwa/+p
696 =daikanwa/+2p =>>daikanwa/+2p
701 =adobe-japan1-0 ==adobe-japan1-0 ===adobe-japan1-0
702 =adobe-japan1-1 ==adobe-japan1-1 ===adobe-japan1-1
703 =adobe-japan1-2 ==adobe-japan1-2 ===adobe-japan1-2
704 =adobe-japan1-3 ==adobe-japan1-3 ===adobe-japan1-3
705 =adobe-japan1-4 ==adobe-japan1-4 ===adobe-japan1-4
706 =adobe-japan1-5 ==adobe-japan1-5 ===adobe-japan1-5
707 =adobe-japan1-6 ==adobe-japan1-6 ===adobe-japan1-6
708 =>>adobe-japan1-0 =+>adobe-japan1-0
709 =>>adobe-japan1-1 =+>adobe-japan1-1
710 =>>adobe-japan1-2 =+>adobe-japan1-2
711 =>>adobe-japan1-3 =+>adobe-japan1-3
712 =>>adobe-japan1-4 =+>adobe-japan1-4
713 =>>adobe-japan1-5 =+>adobe-japan1-5
714 =>>adobe-japan1-6 =+>adobe-japan1-6
715 =>cbeta =cbeta =>>cbeta ==cbeta ===cbeta
716 =zinbun-oracle =>zinbun-oracle
717 ===hng-jou ===hng-keg ===hng-dng ===hng-mam
718 ===hng-drt ===hng-kgk ===hng-myz ===hng-kda
719 ===hng-khi ===hng-khm ===hng-hok ===hng-kyd ===hng-sok
720 ===hng-yhk ===hng-kak ===hng-kar ===hng-kae
721 ===hng-sys ===hng-tsu ===hng-tzj
722 ===hng-hos ===hng-nak ===hng-jhk
723 ===hng-hod ===hng-gok ===hng-ink ===hng-nto
724 ===hng-nkm ===hng-k24 ===hng-nkk
725 ===hng-kcc ===hng-kcj ===hng-kbk ===hng-sik
726 ===hng-skk ===hng-kyu ===hng-ksk ===hng-wan
727 ===hng-okd ===hng-wad ===hng-kmi
728 ===hng-zkd ===hng-doh ===hng-jyu
729 ===hng-tzs ===hng-kss ===hng-kyo
731 ;; (string-match "^=adobe-" (symbol-name name))
733 "(%-18s . %05d)\t; %c")
734 ((memq name '(=hanyo-denshi/ks
735 ==hanyo-denshi/ks ===hanyo-denshi/ks
738 =mj ==mj ===mj =>>mj =>mj
740 "(%-18s . %06d)\t; %c")
741 ((memq name '(=hanyo-denshi/tk ==hanyo-denshi/tk))
742 "(%-18s . %08d)\t; %c")
743 ((>= (charset-dimension name) 2)
744 "(%-18s . #x%04X)\t; %c")
746 "(%-18s . #x%02X)\t; %c"))
748 (if (= (charset-iso-graphic-plane name) 1)
750 (cond ((= (charset-dimension name) 1)
752 ((= (charset-dimension name) 2)
754 ((= (charset-dimension name) 3)
758 (char-db-decode-isolated-char name value)))
759 (if (and (= (charset-chars name) 94)
760 (= (charset-dimension name) 2))
761 (insert (format " [%02d-%02d]"
762 (- (lsh value -8) 32)
763 (- (logand value 255) 32))))
766 (insert (format "(%-18s . %s)" name value))
768 (insert line-breaking))
770 (defun char-db-insert-relation-feature (char name value line-breaking
772 (insert (format "(%-18s%s " name line-breaking))
773 (let ((lbs (concat "\n" (make-string (current-column) ?\ )))
774 separator cell sources required-features
776 (if (characterp value)
777 (setq value (list value)))
779 (setq cell (car value))
781 (setq cell (decode-char '=ucs cell)))
783 ((eq name '->subsumptive)
784 (when (or (not (some (lambda (atr)
785 (get-char-attribute cell atr))
786 char-db-ignored-attributes))
788 (encode-char cell ccs 'defined-only))
792 (let ((char-db-ignored-attributes
794 char-db-ignored-attributes)))
795 (insert-char-attributes cell readable nil nil 'for-sub-node))
796 (setq separator lbs))
801 char (intern (format "%s*sources" name))))
802 (setq required-features nil)
803 (dolist (source sources)
807 shinjigen shinjigen@1ed shinjigen@rev))
808 (setq required-features
809 (union required-features
821 =shinjigen/+p@rev))))
823 (setq required-features
824 (union required-features
829 ((find-charset (setq ret (intern (format "=%s" source))))
830 (setq required-features
831 (cons ret required-features)))
832 (t (setq required-features
833 (cons source required-features)))))
834 (cond ((string-match "@JP" (symbol-name name))
835 (setq required-features
836 (union required-features
844 ((string-match "@CN" (symbol-name name))
845 (setq required-features
846 (union required-features
853 (insert (format "%S" cell))
854 (char-db-insert-char-spec cell readable
857 (setq separator lbs))
861 (if (consp (car cell))
862 (char-db-insert-char-spec cell readable)
863 (char-db-insert-char-reference cell readable))
864 (setq separator lbs))
868 (insert (prin1-to-string cell))
869 (setq separator " ")))
870 (setq value (cdr value)))
872 (insert line-breaking)))
874 (defun insert-char-attributes (char &optional readable attributes column
877 (setq column (current-column)))
878 (let (name value ; has-long-ccs-name
882 (concat "\n" (make-string (1+ column) ?\ )))
883 lbs cell separator ret
885 dest-ccss ; sources required-features
890 (if (consp attributes)
892 (dolist (name attributes)
893 (unless (memq name char-db-ignored-attributes)
894 (if (find-charset name)
898 (dolist (name (char-attribute-list))
899 (unless (memq name char-db-ignored-attributes)
900 (if (find-charset name)
904 #'char-attribute-name<)))
906 (when (memq '<-subsumptive attributes)
907 (when (or readable (not for-sub-node))
908 (when (setq value (get-char-attribute char '<-subsumptive))
909 (char-db-insert-relation-feature char '<-subsumptive value
912 (setq attributes (delq '<-subsumptive attributes)))
913 (when (and (memq '<-denotational attributes)
914 (setq value (get-char-attribute char '<-denotational)))
915 (char-db-insert-relation-feature char '<-denotational value
918 (setq attributes (delq '<-denotational attributes)))
919 (when (and (memq '<-denotational@component attributes)
920 (setq value (get-char-attribute char '<-denotational@component)))
921 (char-db-insert-relation-feature char '<-denotational@component value
924 (setq attributes (delq '<-denotational@component attributes)))
925 (when (and (memq 'name attributes)
926 (setq value (get-char-attribute char 'name)))
928 (if (> (+ (current-column) (length value)) 48)
931 value line-breaking))
932 (setq attributes (delq 'name attributes))
934 (when (and (memq 'name* attributes)
935 (setq value (get-char-attribute char 'name*)))
937 (if (> (+ (current-column) (length value)) 48)
940 value line-breaking))
941 (setq attributes (delq 'name* attributes))
943 (when (and (memq 'script attributes)
944 (setq value (get-char-attribute char 'script)))
945 (insert (format "(script\t\t%s)%s"
946 (mapconcat (function prin1-to-string)
949 (setq attributes (delq 'script attributes))
951 (dolist (name '(=>ucs =>ucs*))
952 (when (and (memq name attributes)
953 (setq value (get-char-attribute char name)))
954 (insert (format "(%-18s . #x%04X)\t; %c%s"
955 name value (decode-char '=ucs value)
957 (setq attributes (delq name attributes))))
958 (dolist (name '(=>ucs@gb =>ucs@big5))
959 (when (and (memq name attributes)
960 (setq value (get-char-attribute char name)))
961 (insert (format "(%-18s . #x%04X)\t; %c%s"
966 (symbol-name name) 2)))
969 (setq attributes (delq name attributes))
971 ;; (dolist (name '(=>daikanwa))
972 ;; (when (and (memq name attributes)
973 ;; (setq value (get-char-attribute char name)))
975 ;; (if (integerp value)
976 ;; (format "(%-18s . %05d)\t; %c%s"
977 ;; name value (decode-char '=daikanwa value)
979 ;; (format "(%-18s %s)\t; %c%s"
981 ;; (mapconcat (function prin1-to-string)
983 ;; (char-representative-of-daikanwa char)
985 ;; (setq attributes (delq name attributes))))
986 (when (and (memq 'general-category attributes)
987 (setq value (get-char-attribute char 'general-category)))
989 "(general-category\t%s) ; %s%s"
990 (mapconcat (lambda (cell)
993 (cond ((rassoc value unidata-normative-category-alist)
994 "Normative Category")
995 ((rassoc value unidata-informative-category-alist)
996 "Informative Category")
1000 (setq attributes (delq 'general-category attributes))
1002 (when (and (memq 'bidi-category attributes)
1003 (setq value (get-char-attribute char 'bidi-category)))
1004 (insert (format "(bidi-category\t. %S)%s"
1007 (setq attributes (delq 'bidi-category attributes))
1009 (unless (or (not (memq 'mirrored attributes))
1010 (eq (setq value (get-char-attribute char 'mirrored 'empty))
1012 (insert (format "(mirrored\t\t. %S)%s"
1015 (setq attributes (delq 'mirrored attributes))
1018 ((and (memq 'decimal-digit-value attributes)
1019 (setq value (get-char-attribute char 'decimal-digit-value)))
1020 (insert (format "(decimal-digit-value . %S)%s"
1023 (setq attributes (delq 'decimal-digit-value attributes))
1024 (when (and (memq 'digit-value attributes)
1025 (setq value (get-char-attribute char 'digit-value)))
1026 (insert (format "(digit-value\t . %S)%s"
1029 (setq attributes (delq 'digit-value attributes))
1031 (when (and (memq 'numeric-value attributes)
1032 (setq value (get-char-attribute char 'numeric-value)))
1033 (insert (format "(numeric-value\t . %S)%s"
1036 (setq attributes (delq 'numeric-value attributes))
1040 (when (and (memq 'digit-value attributes)
1041 (setq value (get-char-attribute char 'digit-value)))
1042 (insert (format "(digit-value\t. %S)%s"
1045 (setq attributes (delq 'digit-value attributes))
1047 (when (and (memq 'numeric-value attributes)
1048 (setq value (get-char-attribute char 'numeric-value)))
1049 (insert (format "(numeric-value\t. %S)%s"
1052 (setq attributes (delq 'numeric-value attributes))
1054 (when (and (memq 'iso-10646-comment attributes)
1055 (setq value (get-char-attribute char 'iso-10646-comment)))
1056 (insert (format "(iso-10646-comment\t. %S)%s"
1059 (setq attributes (delq 'iso-10646-comment attributes))
1061 (when (and (memq 'morohashi-daikanwa attributes)
1062 (setq value (get-char-attribute char 'morohashi-daikanwa)))
1063 (insert (format "(morohashi-daikanwa\t%s)%s"
1064 (mapconcat (function prin1-to-string) value " ")
1066 (setq attributes (delq 'morohashi-daikanwa attributes))
1070 (when (and (memq 'ideographic-radical attributes)
1071 (setq value (get-char-attribute char 'ideographic-radical)))
1072 (setq radical value)
1073 (insert (format "(ideographic-radical . %S)\t; %c%s"
1075 (ideographic-radical radical)
1077 (setq attributes (delq 'ideographic-radical attributes))
1079 (when (and (memq 'shuowen-radical attributes)
1080 (setq value (get-char-attribute char 'shuowen-radical)))
1081 (insert (format "(shuowen-radical\t. %S)\t; %c%s"
1083 (shuowen-radical value)
1085 (setq attributes (delq 'shuowen-radical attributes))
1090 char-db-feature-domains
1092 (dolist (feature (char-attribute-list))
1093 (setq feature (symbol-name feature))
1095 "\\(radical\\|strokes\\)@\\([^@*]+\\)\\(\\*\\|$\\)"
1097 (setq domain (intern (match-string 2 feature)))
1098 (unless (memq domain dest)
1099 (setq dest (cons domain dest)))))
1100 (sort dest #'string<))))
1101 (setq key (intern (format "%s@%s" 'ideographic-radical domain)))
1102 (when (and (memq key attributes)
1103 (setq value (get-char-attribute char key)))
1104 (setq radical value)
1105 (insert (format "(%s . %S)\t; %c%s"
1108 (ideographic-radical radical)
1110 (setq attributes (delq key attributes))
1112 (setq key (intern (format "%s@%s" 'ideographic-strokes domain)))
1113 (when (and (memq key attributes)
1114 (setq value (get-char-attribute char key)))
1115 (setq strokes value)
1116 (insert (format "(%s . %S)%s"
1120 (setq attributes (delq key attributes))
1122 (setq key (intern (format "%s@%s" 'total-strokes domain)))
1123 (when (and (memq key attributes)
1124 (setq value (get-char-attribute char key)))
1125 (insert (format "(%s . %S)%s"
1129 (setq attributes (delq key attributes))
1131 (dolist (feature '(ideographic-radical
1134 (setq key (intern (format "%s@%s*sources" feature domain)))
1135 (when (and (memq key attributes)
1136 (setq value (get-char-attribute char key)))
1137 (insert (format "(%s%s" key line-breaking))
1138 (dolist (cell value)
1139 (insert (format " %s" cell)))
1141 (insert line-breaking)
1142 (setq attributes (delq key attributes))
1145 (when (and (memq 'ideographic-strokes attributes)
1146 (setq value (get-char-attribute char 'ideographic-strokes)))
1147 (setq strokes value)
1148 (insert (format "(ideographic-strokes . %S)%s"
1151 (setq attributes (delq 'ideographic-strokes attributes))
1153 (when (and (memq 'kangxi-radical attributes)
1154 (setq value (get-char-attribute char 'kangxi-radical)))
1155 (unless (eq value radical)
1156 (insert (format "(kangxi-radical\t . %S)\t; %c%s"
1158 (ideographic-radical value)
1161 (setq radical value)))
1162 (setq attributes (delq 'kangxi-radical attributes))
1164 (when (and (memq 'kangxi-strokes attributes)
1165 (setq value (get-char-attribute char 'kangxi-strokes)))
1166 (unless (eq value strokes)
1167 (insert (format "(kangxi-strokes\t . %S)%s"
1171 (setq strokes value)))
1172 (setq attributes (delq 'kangxi-strokes attributes))
1174 ;; (when (and (memq 'japanese-radical attributes)
1175 ;; (setq value (get-char-attribute char 'japanese-radical)))
1176 ;; (unless (eq value radical)
1177 ;; (insert (format "(japanese-radical\t . %S)\t; %c%s"
1179 ;; (ideographic-radical value)
1182 ;; (setq radical value)))
1183 ;; (setq attributes (delq 'japanese-radical attributes))
1185 (when (and (memq 'japanese-strokes attributes)
1186 (setq value (get-char-attribute char 'japanese-strokes)))
1187 (unless (eq value strokes)
1188 (insert (format "(japanese-strokes\t . %S)%s"
1192 (setq strokes value)))
1193 (setq attributes (delq 'japanese-strokes attributes))
1195 (when (and (memq 'cns-radical attributes)
1196 (setq value (get-char-attribute char 'cns-radical)))
1197 (insert (format "(cns-radical\t . %S)\t; %c%s"
1199 (ideographic-radical value)
1201 (setq attributes (delq 'cns-radical attributes))
1203 (when (and (memq 'cns-strokes attributes)
1204 (setq value (get-char-attribute char 'cns-strokes)))
1205 (unless (eq value strokes)
1206 (insert (format "(cns-strokes\t . %S)%s"
1210 (setq strokes value)))
1211 (setq attributes (delq 'cns-strokes attributes))
1213 ;; (when (and (memq 'shinjigen-1-radical attributes)
1214 ;; (setq value (get-char-attribute char 'shinjigen-1-radical)))
1215 ;; (unless (eq value radical)
1216 ;; (insert (format "(shinjigen-1-radical . %S)\t; %c%s"
1218 ;; (ideographic-radical value)
1221 ;; (setq radical value)))
1222 ;; (setq attributes (delq 'shinjigen-1-radical attributes))
1224 ;; (when (and (memq 'ideographic- attributes)
1225 ;; (setq value (get-char-attribute char 'ideographic-)))
1226 ;; (insert "(ideographic- ")
1227 ;; (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1229 ;; (while (consp value)
1230 ;; (setq cell (car value))
1231 ;; (if (integerp cell)
1232 ;; (setq cell (decode-char '=ucs cell)))
1233 ;; (cond ((characterp cell)
1237 ;; (insert (format "%S" cell))
1238 ;; (char-db-insert-char-spec cell readable))
1239 ;; (setq separator lbs))
1243 ;; (if (consp (car cell))
1244 ;; (char-db-insert-char-spec cell readable)
1245 ;; (char-db-insert-char-reference cell readable))
1246 ;; (setq separator lbs))
1249 ;; (insert separator))
1250 ;; (insert (prin1-to-string cell))
1251 ;; (setq separator " ")))
1252 ;; (setq value (cdr value)))
1254 ;; (insert line-breaking)
1255 ;; (setq attributes (delq 'ideographic- attributes)))
1256 (when (and (memq 'total-strokes attributes)
1257 (setq value (get-char-attribute char 'total-strokes)))
1258 (insert (format "(total-strokes . %S)%s"
1261 (setq attributes (delq 'total-strokes attributes))
1263 ;; (when (and (memq '->ideograph attributes)
1264 ;; (setq value (get-char-attribute char '->ideograph)))
1265 ;; (insert (format "(->ideograph\t%s)%s"
1266 ;; (mapconcat (lambda (code)
1267 ;; (cond ((symbolp code)
1268 ;; (symbol-name code))
1270 ;; (format "#x%04X" code))
1273 ;; line-breaking code))))
1276 ;; (setq attributes (delq '->ideograph attributes))
1278 ;; (when (and (memq '->decomposition attributes)
1279 ;; (setq value (get-char-attribute char '->decomposition)))
1280 ;; (insert (format "(->decomposition\t%s)%s"
1281 ;; (mapconcat (lambda (code)
1282 ;; (cond ((symbolp code)
1283 ;; (symbol-name code))
1284 ;; ((characterp code)
1286 ;; (format "%S" code)
1291 ;; (format "#x%04X" code))
1293 ;; (format "%s%S" line-breaking code))))
1296 ;; (setq attributes (delq '->decomposition attributes))
1298 (if (equal (get-char-attribute char '->titlecase)
1299 (get-char-attribute char '->uppercase))
1300 (setq attributes (delq '->titlecase attributes)))
1301 (when (and (memq '->mojikyo attributes)
1302 (setq value (get-char-attribute char '->mojikyo)))
1303 (insert (format "(->mojikyo\t\t. %06d)\t; %c%s"
1304 value (decode-char 'mojikyo value)
1306 (setq attributes (delq '->mojikyo attributes))
1308 ;; (when (and (memq 'hanyu-dazidian-vol attributes)
1309 ;; (setq value (get-char-attribute char 'hanyu-dazidian-vol)))
1310 ;; (insert (format "(hanyu-dazidian-vol . %d)%s"
1311 ;; value line-breaking))
1312 ;; (setq attributes (delq 'hanyu-dazidian-vol attributes))
1314 ;; (when (and (memq 'hanyu-dazidian-page attributes)
1315 ;; (setq value (get-char-attribute char 'hanyu-dazidian-page)))
1316 ;; (insert (format "(hanyu-dazidian-page . %d)%s"
1317 ;; value line-breaking))
1318 ;; (setq attributes (delq 'hanyu-dazidian-page attributes))
1320 ;; (when (and (memq 'hanyu-dazidian-char attributes)
1321 ;; (setq value (get-char-attribute char 'hanyu-dazidian-char)))
1322 ;; (insert (format "(hanyu-dazidian-char . %d)%s"
1323 ;; value line-breaking))
1324 ;; (setq attributes (delq 'hanyu-dazidian-char attributes))
1327 (dolist (ignored '(composition
1328 ->denotational <-subsumptive ->ucs-unified
1329 ->ideographic-component-forms))
1330 (setq attributes (delq ignored attributes))))
1332 (setq name (car attributes))
1333 (unless (eq (setq value (get-char-attribute char name 'value-is-empty))
1335 (cond ((setq ret (find-charset name))
1336 (setq name (charset-name ret))
1337 (when (not (memq name dest-ccss))
1338 (setq dest-ccss (cons name dest-ccss))
1339 (char-db-insert-ccs-feature name value line-breaking))
1341 ((string-match "^=>ucs@" (symbol-name name))
1342 (insert (format "(%-18s . #x%04X)\t; %c%s"
1343 name value (decode-char '=ucs value)
1346 ((eq name 'jisx0208-1978/4X)
1347 (insert (format "(%-18s . #x%04X)%s"
1353 (not (eq name '->subsumptive))
1354 (not (eq name '->uppercase))
1355 (not (eq name '->lowercase))
1356 (not (eq name '->titlecase))
1357 (not (eq name '->canonical))
1358 (not (eq name '->Bopomofo))
1359 (not (eq name '->mistakable))
1360 (not (eq name '->ideographic-variants))
1361 (null (get-char-attribute
1362 char (intern (format "%s*sources" name))))
1363 (not (string-match "\\*sources$" (symbol-name name)))
1364 (null (get-char-attribute
1365 char (intern (format "%s*note" name))))
1366 (not (string-match "\\*note$" (symbol-name name)))
1367 (or (eq name '<-identical)
1368 (eq name '<-uppercase)
1369 (eq name '<-lowercase)
1370 (eq name '<-titlecase)
1371 (eq name '<-canonical)
1372 (eq name '<-ideographic-variants)
1373 ;; (eq name '<-synonyms)
1374 (string-match "^<-synonyms" (symbol-name name))
1375 (eq name '<-mistakable)
1376 (when (string-match "^->" (symbol-name name))
1378 ((string-match "^->fullwidth" (symbol-name name))
1379 (not (and (consp value)
1380 (characterp (car value))
1382 (car value) '=ucs 'defined-only)))
1387 ((or (eq name 'ideographic-structure)
1388 (eq name 'ideographic-combination)
1389 ;; (eq name 'ideographic-)
1390 (eq name '=decomposition)
1391 (char-feature-base-name= '=decomposition name)
1392 (char-feature-base-name= '=>decomposition name)
1393 ;; (string-match "^=>*decomposition\\(@[^*]+\\)?$"
1394 ;; (symbol-name name))
1395 (string-match "^\\(->\\|<-\\)[^*]*$" (symbol-name name))
1396 (string-match "^\\(->\\|<-\\)[^*]*\\*sources$"
1399 (char-db-insert-relation-feature char name value
1402 ;; ((memq name '(ideograph=
1403 ;; original-ideograph-of
1404 ;; ancient-ideograph-of
1405 ;; vulgar-ideograph-of
1406 ;; wrong-ideograph-of
1407 ;; ;; simplified-ideograph-of
1408 ;; ideographic-variants
1409 ;; ;; ideographic-different-form-of
1411 ;; (insert (format "(%-18s%s " name line-breaking))
1412 ;; (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1414 ;; (while (consp value)
1415 ;; (setq cell (car value))
1416 ;; (if (and (consp cell)
1417 ;; (consp (car cell)))
1421 ;; (char-db-insert-alist cell readable)
1422 ;; (setq separator lbs))
1424 ;; (insert separator))
1425 ;; (insert (prin1-to-string cell))
1426 ;; (setq separator " "))
1427 ;; (setq value (cdr value)))
1429 ;; (insert line-breaking))
1431 (insert (format "(%-18s " name))
1432 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1434 (while (consp value)
1435 (setq cell (car value))
1436 (if (and (consp cell)
1438 (setq ret (condition-case nil
1446 (setq key (car (car rest)))
1447 (if (find-charset key)
1448 (setq cal (cons key cal))
1449 (setq al (cons key al)))
1450 (setq rest (cdr rest)))
1453 (insert-char-attributes ret
1457 (setq separator lbs))
1458 (setq ret (prin1-to-string cell))
1460 (if (< (+ (current-column)
1467 (setq separator " "))
1468 (setq value (cdr value)))
1470 (insert line-breaking))
1472 (insert (format "(%-18s" name))
1473 (setq ret (prin1-to-string value))
1474 (unless (< (+ (current-column)
1478 (insert line-breaking))
1479 (insert " . " ret ")" line-breaking)
1480 ;; (insert (format "(%-18s . %S)%s"
1485 (setq attributes (cdr attributes)))
1488 (defun insert-char-data (char &optional readable
1491 (narrow-to-region (point)(point))
1492 (insert "(define-char
1494 (insert-char-attributes char readable attributes)
1496 (goto-char (point-min))
1497 (while (re-search-forward "[ \t]+$" nil t)
1500 (goto-char (point-min))
1501 (while (re-search-forward "[ \t][ \t][ \t]*" nil t)
1502 (let ((column (current-column))
1503 (indent-tabs-mode t))
1504 (delete-region (match-beginning 0) (point))
1505 (indent-to column)))
1506 (goto-char (point-max))
1507 ;; (tabify (point-min)(point-max))
1510 (defun insert-char-data-with-variant (char &optional printable
1512 script excluded-script)
1513 (insert-char-data char printable)
1514 (let ((variants (char-variants char))
1517 (setq variants (sort variants #'<))
1518 (setq rest variants)
1519 (setq variants (cons char variants))
1521 (setq variant (car rest))
1522 (unless (get-char-attribute variant '<-subsumptive)
1523 (if (and (or (null script)
1524 (null (setq vs (get-char-attribute variant 'script)))
1526 (or (null excluded-script)
1527 (null (setq vs (get-char-attribute variant 'script)))
1528 (not (memq excluded-script vs))))
1529 (unless (and no-ucs-unified (get-char-attribute variant '=ucs))
1530 (insert-char-data variant printable)
1531 (if (setq ret (char-variants variant))
1533 (or (memq (car ret) variants)
1534 ;; (get-char-attribute (car ret) '<-subsumptive)
1535 (setq rest (nconc rest (list (car ret)))))
1536 (setq ret (cdr ret)))))))
1537 (setq rest (cdr rest)))))
1539 (defun insert-char-range-data (min max &optional script excluded-script)
1542 (while (<= code max)
1543 (setq char (decode-char '=ucs code))
1544 (if (encode-char char '=ucs 'defined-only)
1545 (insert-char-data-with-variant char nil 'no-ucs-unified
1546 script excluded-script))
1547 (setq code (1+ code)))))
1549 (defun write-char-range-data-to-file (min max file
1550 &optional script excluded-script)
1551 (let ((coding-system-for-write char-db-file-coding-system))
1553 (insert (format ";; -*- coding: %s -*-\n"
1554 char-db-file-coding-system))
1555 (insert-char-range-data min max script excluded-script)
1556 (write-region (point-min)(point-max) file))))
1558 (defvar what-character-original-window-configuration)
1561 (defun what-char-definition (char)
1562 (interactive (list (char-after)))
1563 (let ((buf (get-buffer-create "*Character Description*"))
1564 (the-buf (current-buffer))
1565 (win-conf (current-window-configuration)))
1567 (make-local-variable 'what-character-original-window-configuration)
1568 (setq what-character-original-window-configuration win-conf)
1569 (setq buffer-read-only nil)
1573 (insert-char-data-with-variant char 'printable)
1574 (unless (char-attribute-alist char)
1575 (insert (format ";; = %c\n"
1576 (let* ((rest (split-char char))
1580 (setq code (logior (lsh code 8)
1582 (decode-char ccs code)))))
1583 ;; (char-db-update-comment)
1584 (set-buffer-modified-p nil)
1585 (view-mode the-buf (lambda (buf)
1586 (set-window-configuration
1587 what-character-original-window-configuration)
1589 (goto-char (point-min)))
1591 (set-window-configuration
1592 what-character-original-window-configuration)
1593 (signal (car err) (cdr err)))))))
1599 (provide 'char-db-util)
1601 ;;; char-db-util.el ends here