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
357 =>big5-cdp-itaiji-001
364 ;;; @ char-db formatters
367 (defun char-db-make-char-spec (char)
369 (cond ((characterp char)
370 (cond ((and (setq ret (encode-char char '=ucs 'defined-only))
371 (not (and (<= #xE000 ret)(<= ret #xF8FF))))
372 (setq char-spec (list (cons '=ucs ret)))
373 (cond ((setq ret (get-char-attribute char 'name))
374 (setq char-spec (cons (cons 'name ret) char-spec))
376 ((setq ret (get-char-attribute char 'name*))
377 (setq char-spec (cons (cons 'name* ret) char-spec))
380 ((encode-char char '=mj 'defined-only)
382 (dolist (ccs (charset-list))
383 (if (and (or (eq ccs '=mj)
384 ;; (eq (charset-property ccs 'iso-ir) 177)
385 (string-match "=ucs@" (symbol-name ccs))
387 (setq ccs (charset-name ccs))
388 (null (assq ccs char-spec))
389 (setq ret (encode-char char ccs 'defined-only)))
390 (setq char-spec (cons (cons ccs ret) char-spec))))
392 ((encode-char char '==mj 'defined-only)
394 (dolist (ccs (charset-list))
395 (if (and (or (eq ccs '==mj)
396 ;; (eq (charset-property ccs 'iso-ir) 177)
397 (string-match "=ucs@" (symbol-name ccs))
399 (setq ccs (charset-name ccs))
400 (null (assq ccs char-spec))
401 (setq ret (encode-char char ccs 'defined-only)))
402 (setq char-spec (cons (cons ccs ret) char-spec))))
404 ((encode-char char '=adobe-japan1 'defined-only)
406 (dolist (ccs (charset-list))
407 (if (and (or (memq ccs
416 ;; (eq (charset-property ccs 'iso-ir) 177)
417 (string-match "=ucs@" (symbol-name ccs))
419 (setq ccs (charset-name ccs))
420 (null (assq ccs char-spec))
421 (setq ret (encode-char char ccs 'defined-only)))
422 (setq char-spec (cons (cons ccs ret) char-spec))))
424 ((encode-char char '==adobe-japan1 'defined-only)
426 (dolist (ccs (charset-list))
427 (if (and (or (memq ccs
436 ;; (eq (charset-property ccs 'iso-ir) 177)
437 (string-match "=ucs@" (symbol-name ccs))
439 (setq ccs (charset-name ccs))
440 (null (assq ccs char-spec))
441 (setq ret (encode-char char ccs 'defined-only)))
442 (setq char-spec (cons (cons ccs ret) char-spec))))
446 (let ((rest char-db-coded-charset-priority-list)
449 (setq ccs (charset-name
450 (find-charset (car rest))))
452 (encode-char char ccs
454 (throw 'tag (cons ccs ret)))
455 (setq rest (cdr rest))))))
456 (setq char-spec (list ret))
457 (dolist (ccs (delq (car ret) (charset-list)))
458 (if (and (or (charset-iso-final-char ccs)
465 (eq (charset-property ccs 'iso-ir) 177)
466 ;; (string-match "=ucs@" (symbol-name ccs))
468 (setq ccs (charset-name ccs))
469 (null (assq ccs char-spec))
470 (setq ret (encode-char char ccs 'defined-only)))
471 (setq char-spec (cons (cons ccs ret) char-spec))))
473 (setq char-spec (split-char char)))
474 (cond ((setq ret (get-char-attribute char 'name))
475 (setq char-spec (cons (cons 'name ret) char-spec))
477 ((setq ret (get-char-attribute char 'name*))
478 (setq char-spec (cons (cons 'name* ret) char-spec))
481 ((setq ret (get-char-attribute
482 char 'ideographic-combination))
484 (cons (cons 'ideographic-combination ret)
491 (defun char-db-insert-char-spec (char &optional readable column
494 (setq column (current-column)))
495 (let (char-spec temp-char)
496 (setq char-spec (char-db-make-char-spec char))
497 (unless (or (characterp char) ; char
499 (setq char (find-char char-spec))
501 ;; define temporary character
502 ;; Current implementation is dirty.
503 (setq temp-char (define-char (cons '(ideograph-daikanwa . 0)
505 (remove-char-attribute temp-char 'ideograph-daikanwa)
506 (setq char temp-char))
507 (insert-char-attributes char
509 (union (mapcar #'car char-spec)
513 ;; undefine temporary character
514 ;; Current implementation is dirty.
515 (setq char-spec (char-attribute-alist temp-char))
517 (remove-char-attribute temp-char (car (car char-spec)))
518 (setq char-spec (cdr char-spec))))))
520 (defun char-db-insert-alist (alist &optional readable column)
522 (setq column (current-column)))
524 (concat "\n" (make-string (1+ column) ?\ )))
528 lbs cell rest separator)
531 (setq name (car (car alist))
532 value (cdr (car alist)))
533 (cond ((eq name 'char)
535 (if (setq ret (condition-case nil
543 (setq key (car (car value)))
544 ;; (if (find-charset key)
545 ;; (setq cal (cons key cal))
546 (setq al (cons key al))
548 (setq value (cdr value)))
549 (insert-char-attributes ret
553 (insert (prin1-to-string value)))
555 (insert line-breaking))
557 (insert (format "(%-18s " name))
558 (setq lbs (concat "\n" (make-string (current-column) ?\ )))
560 (setq cell (car value))
561 (if (and (consp cell)
563 (setq ret (condition-case nil
573 (setq key (car (car rest)))
574 ;; (if (find-charset key)
575 ;; (setq cal (cons key cal))
576 (setq al (cons key al))
578 (setq rest (cdr rest)))
581 (insert-char-attributes ret
585 (setq separator lbs))
588 (insert (prin1-to-string cell))
589 (setq separator " "))
590 (setq value (cdr value)))
592 (insert line-breaking))
594 (insert (format "(%-18s . %S)%s"
597 (setq alist (cdr alist))))
600 (defun char-db-insert-char-reference (plist &optional readable column)
602 (setq column (current-column)))
604 (concat "\n" (make-string (1+ column) ?\ )))
609 (setq name (pop plist))
610 (setq value (pop plist))
611 (cond ((eq name :char)
614 (cond ((numberp value)
615 (setq value (decode-char '=ucs value)))
617 ;; (setq value (or (find-char value)
620 (char-db-insert-char-spec value readable)
621 (insert line-breaking)
624 (insert (format "%s%s\t%d ; %c%s"
627 (ideographic-radical value)
631 (insert (format "%s%s\t%S" separator name value))
632 (setq separator line-breaking)))
636 (defun char-db-decode-isolated-char (ccs code-point)
639 (cond ((eq ccs 'arabic-iso8859-6)
640 (decode-char ccs code-point))
642 ;; (decode-builtin-char '==gt code-point))
643 ((and (memq ccs '(=gt-pj-1
654 (setq ret (decode-char ccs code-point))
655 (setq ret (encode-char ret '=gt 'defined-only)))
656 (decode-builtin-char '=gt ret))
658 (decode-builtin-char ccs code-point))))
660 (or (decode-char ccs code-point)
661 (define-char (list (cons ccs code-point)))))
662 ((and (<= 0 (char-int ret))
663 (<= (char-int ret) #x1F))
664 (decode-char '=ucs (+ #x2400 (char-int ret))))
665 ((= (char-int ret) #x7F)
669 (defvar char-db-convert-obsolete-format t)
671 (defun char-db-insert-ccs-feature (name value line-breaking)
677 ((memq name '(=>iwds-1
680 =shinjigen@1ed ==shinjigen@1ed
681 =shinjigen@rev ==shinjigen@rev
682 =shinjigen/+p@rev ==shinjigen/+p@rev
683 ===daikanwa/ho ==daikanwa/ho
684 =daikanwa/ho =>>daikanwa/ho =>daikanwa/ho))
685 "(%-18s . %04d)\t; %c")
686 ((eq name '=shinjigen@1ed/24pr)
687 "(%-18s . %04d)\t; %c")
691 ==daikanwa =daikanwa =>>daikanwa =>daikanwa
692 =daikanwa@rev1 =daikanwa@rev2
693 =daikanwa/+p ==daikanwa/+p ===daikanwa/+p
695 =daikanwa/+2p =>>daikanwa/+2p
700 =adobe-japan1-0 ==adobe-japan1-0 ===adobe-japan1-0
701 =adobe-japan1-1 ==adobe-japan1-1 ===adobe-japan1-1
702 =adobe-japan1-2 ==adobe-japan1-2 ===adobe-japan1-2
703 =adobe-japan1-3 ==adobe-japan1-3 ===adobe-japan1-3
704 =adobe-japan1-4 ==adobe-japan1-4 ===adobe-japan1-4
705 =adobe-japan1-5 ==adobe-japan1-5 ===adobe-japan1-5
706 =adobe-japan1-6 ==adobe-japan1-6 ===adobe-japan1-6
707 =>>adobe-japan1-0 =+>adobe-japan1-0
708 =>>adobe-japan1-1 =+>adobe-japan1-1
709 =>>adobe-japan1-2 =+>adobe-japan1-2
710 =>>adobe-japan1-3 =+>adobe-japan1-3
711 =>>adobe-japan1-4 =+>adobe-japan1-4
712 =>>adobe-japan1-5 =+>adobe-japan1-5
713 =>>adobe-japan1-6 =+>adobe-japan1-6
714 =>cbeta =cbeta =>>cbeta ==cbeta ===cbeta
715 =zinbun-oracle =>zinbun-oracle
716 ===hng-jou ===hng-keg ===hng-dng ===hng-mam
717 ===hng-drt ===hng-kgk ===hng-myz ===hng-kda
718 ===hng-khi ===hng-khm ===hng-hok ===hng-kyd ===hng-sok
719 ===hng-yhk ===hng-kak ===hng-kar ===hng-kae
720 ===hng-sys ===hng-tsu ===hng-tzj
721 ===hng-hos ===hng-nak ===hng-jhk
722 ===hng-hod ===hng-gok ===hng-ink ===hng-nto
723 ===hng-nkm ===hng-k24 ===hng-nkk
724 ===hng-kcc ===hng-kcj ===hng-kbk ===hng-sik
725 ===hng-skk ===hng-kyu ===hng-ksk ===hng-wan
726 ===hng-okd ===hng-wad ===hng-kmi
727 ===hng-zkd ===hng-doh ===hng-jyu
728 ===hng-tzs ===hng-kss ===hng-kyo
730 ;; (string-match "^=adobe-" (symbol-name name))
732 "(%-18s . %05d)\t; %c")
733 ((memq name '(=hanyo-denshi/ks
734 ==hanyo-denshi/ks ===hanyo-denshi/ks
737 =mj ==mj ===mj =>>mj =>mj
739 "(%-18s . %06d)\t; %c")
740 ((memq name '(=hanyo-denshi/tk ==hanyo-denshi/tk))
741 "(%-18s . %08d)\t; %c")
742 ((>= (charset-dimension name) 2)
743 "(%-18s . #x%04X)\t; %c")
745 "(%-18s . #x%02X)\t; %c"))
747 (if (= (charset-iso-graphic-plane name) 1)
749 (cond ((= (charset-dimension name) 1)
751 ((= (charset-dimension name) 2)
753 ((= (charset-dimension name) 3)
757 (char-db-decode-isolated-char name value)))
758 (if (and (= (charset-chars name) 94)
759 (= (charset-dimension name) 2))
760 (insert (format " [%02d-%02d]"
761 (- (lsh value -8) 32)
762 (- (logand value 255) 32))))
765 (insert (format "(%-18s . %s)" name value))
767 (insert line-breaking))
769 (defun char-db-insert-relation-feature (char name value line-breaking
771 (insert (format "(%-18s%s " name line-breaking))
772 (let ((lbs (concat "\n" (make-string (current-column) ?\ )))
773 separator cell sources required-features
775 (if (characterp value)
776 (setq value (list value)))
778 (setq cell (car value))
780 (setq cell (decode-char '=ucs cell)))
782 ((eq name '->subsumptive)
783 (when (or (not (some (lambda (atr)
784 (get-char-attribute cell atr))
785 char-db-ignored-attributes))
787 (encode-char cell ccs 'defined-only))
791 (let ((char-db-ignored-attributes
793 char-db-ignored-attributes)))
794 (insert-char-attributes cell readable nil nil 'for-sub-node))
795 (setq separator lbs))
800 char (intern (format "%s*sources" name))))
801 (setq required-features nil)
802 (dolist (source sources)
806 shinjigen shinjigen@1ed shinjigen@rev))
807 (setq required-features
808 (union required-features
820 =shinjigen/+p@rev))))
822 (setq required-features
823 (union required-features
828 ((find-charset (setq ret (intern (format "=%s" source))))
829 (setq required-features
830 (cons ret required-features)))
831 (t (setq required-features
832 (cons source required-features)))))
833 (cond ((string-match "@JP" (symbol-name name))
834 (setq required-features
835 (union required-features
843 ((string-match "@CN" (symbol-name name))
844 (setq required-features
845 (union required-features
852 (insert (format "%S" cell))
853 (char-db-insert-char-spec cell readable
856 (setq separator lbs))
860 (if (consp (car cell))
861 (char-db-insert-char-spec cell readable)
862 (char-db-insert-char-reference cell readable))
863 (setq separator lbs))
867 (insert (prin1-to-string cell))
868 (setq separator " ")))
869 (setq value (cdr value)))
871 (insert line-breaking)))
873 (defun insert-char-attributes (char &optional readable attributes column
876 (setq column (current-column)))
877 (let (name value ; has-long-ccs-name
881 (concat "\n" (make-string (1+ column) ?\ )))
882 lbs cell separator ret
884 dest-ccss ; sources required-features
889 (if (consp attributes)
891 (dolist (name attributes)
892 (unless (memq name char-db-ignored-attributes)
893 (if (find-charset name)
897 (dolist (name (char-attribute-list))
898 (unless (memq name char-db-ignored-attributes)
899 (if (find-charset name)
903 #'char-attribute-name<)))
905 (when (memq '<-subsumptive attributes)
906 (when (or readable (not for-sub-node))
907 (when (setq value (get-char-attribute char '<-subsumptive))
908 (char-db-insert-relation-feature char '<-subsumptive value
911 (setq attributes (delq '<-subsumptive attributes)))
912 (when (and (memq '<-denotational attributes)
913 (setq value (get-char-attribute char '<-denotational)))
914 (char-db-insert-relation-feature char '<-denotational value
917 (setq attributes (delq '<-denotational attributes)))
918 (when (and (memq '<-denotational@component attributes)
919 (setq value (get-char-attribute char '<-denotational@component)))
920 (char-db-insert-relation-feature char '<-denotational@component value
923 (setq attributes (delq '<-denotational@component attributes)))
924 (when (and (memq 'name attributes)
925 (setq value (get-char-attribute char 'name)))
927 (if (> (+ (current-column) (length value)) 48)
930 value line-breaking))
931 (setq attributes (delq 'name attributes))
933 (when (and (memq 'name* attributes)
934 (setq value (get-char-attribute char 'name*)))
936 (if (> (+ (current-column) (length value)) 48)
939 value line-breaking))
940 (setq attributes (delq 'name* attributes))
942 (when (and (memq 'script attributes)
943 (setq value (get-char-attribute char 'script)))
944 (insert (format "(script\t\t%s)%s"
945 (mapconcat (function prin1-to-string)
948 (setq attributes (delq 'script attributes))
950 (dolist (name '(=>ucs =>ucs*))
951 (when (and (memq name attributes)
952 (setq value (get-char-attribute char name)))
953 (insert (format "(%-18s . #x%04X)\t; %c%s"
954 name value (decode-char '=ucs value)
956 (setq attributes (delq name attributes))))
957 (dolist (name '(=>ucs@gb =>ucs@big5))
958 (when (and (memq name attributes)
959 (setq value (get-char-attribute char name)))
960 (insert (format "(%-18s . #x%04X)\t; %c%s"
965 (symbol-name name) 2)))
968 (setq attributes (delq name attributes))
970 ;; (dolist (name '(=>daikanwa))
971 ;; (when (and (memq name attributes)
972 ;; (setq value (get-char-attribute char name)))
974 ;; (if (integerp value)
975 ;; (format "(%-18s . %05d)\t; %c%s"
976 ;; name value (decode-char '=daikanwa value)
978 ;; (format "(%-18s %s)\t; %c%s"
980 ;; (mapconcat (function prin1-to-string)
982 ;; (char-representative-of-daikanwa char)
984 ;; (setq attributes (delq name attributes))))
985 (when (and (memq 'general-category attributes)
986 (setq value (get-char-attribute char 'general-category)))
988 "(general-category\t%s) ; %s%s"
989 (mapconcat (lambda (cell)
992 (cond ((rassoc value unidata-normative-category-alist)
993 "Normative Category")
994 ((rassoc value unidata-informative-category-alist)
995 "Informative Category")
999 (setq attributes (delq 'general-category attributes))
1001 (when (and (memq 'bidi-category attributes)
1002 (setq value (get-char-attribute char 'bidi-category)))
1003 (insert (format "(bidi-category\t. %S)%s"
1006 (setq attributes (delq 'bidi-category attributes))
1008 (unless (or (not (memq 'mirrored attributes))
1009 (eq (setq value (get-char-attribute char 'mirrored 'empty))
1011 (insert (format "(mirrored\t\t. %S)%s"
1014 (setq attributes (delq 'mirrored attributes))
1017 ((and (memq 'decimal-digit-value attributes)
1018 (setq value (get-char-attribute char 'decimal-digit-value)))
1019 (insert (format "(decimal-digit-value . %S)%s"
1022 (setq attributes (delq 'decimal-digit-value attributes))
1023 (when (and (memq 'digit-value attributes)
1024 (setq value (get-char-attribute char 'digit-value)))
1025 (insert (format "(digit-value\t . %S)%s"
1028 (setq attributes (delq 'digit-value attributes))
1030 (when (and (memq 'numeric-value attributes)
1031 (setq value (get-char-attribute char 'numeric-value)))
1032 (insert (format "(numeric-value\t . %S)%s"
1035 (setq attributes (delq 'numeric-value attributes))
1039 (when (and (memq 'digit-value attributes)
1040 (setq value (get-char-attribute char 'digit-value)))
1041 (insert (format "(digit-value\t. %S)%s"
1044 (setq attributes (delq 'digit-value attributes))
1046 (when (and (memq 'numeric-value attributes)
1047 (setq value (get-char-attribute char 'numeric-value)))
1048 (insert (format "(numeric-value\t. %S)%s"
1051 (setq attributes (delq 'numeric-value attributes))
1053 (when (and (memq 'iso-10646-comment attributes)
1054 (setq value (get-char-attribute char 'iso-10646-comment)))
1055 (insert (format "(iso-10646-comment\t. %S)%s"
1058 (setq attributes (delq 'iso-10646-comment attributes))
1060 (when (and (memq 'morohashi-daikanwa attributes)
1061 (setq value (get-char-attribute char 'morohashi-daikanwa)))
1062 (insert (format "(morohashi-daikanwa\t%s)%s"
1063 (mapconcat (function prin1-to-string) value " ")
1065 (setq attributes (delq 'morohashi-daikanwa attributes))
1069 (when (and (memq 'ideographic-radical attributes)
1070 (setq value (get-char-attribute char 'ideographic-radical)))
1071 (setq radical value)
1072 (insert (format "(ideographic-radical . %S)\t; %c%s"
1074 (ideographic-radical radical)
1076 (setq attributes (delq 'ideographic-radical attributes))
1078 (when (and (memq 'shuowen-radical attributes)
1079 (setq value (get-char-attribute char 'shuowen-radical)))
1080 (insert (format "(shuowen-radical\t. %S)\t; %c%s"
1082 (shuowen-radical value)
1084 (setq attributes (delq 'shuowen-radical attributes))
1089 char-db-feature-domains
1091 (dolist (feature (char-attribute-list))
1092 (setq feature (symbol-name feature))
1094 "\\(radical\\|strokes\\)@\\([^@*]+\\)\\(\\*\\|$\\)"
1096 (setq domain (intern (match-string 2 feature)))
1097 (unless (memq domain dest)
1098 (setq dest (cons domain dest)))))
1099 (sort dest #'string<))))
1100 (setq key (intern (format "%s@%s" 'ideographic-radical domain)))
1101 (when (and (memq key attributes)
1102 (setq value (get-char-attribute char key)))
1103 (setq radical value)
1104 (insert (format "(%s . %S)\t; %c%s"
1107 (ideographic-radical radical)
1109 (setq attributes (delq key attributes))
1111 (setq key (intern (format "%s@%s" 'ideographic-strokes domain)))
1112 (when (and (memq key attributes)
1113 (setq value (get-char-attribute char key)))
1114 (setq strokes value)
1115 (insert (format "(%s . %S)%s"
1119 (setq attributes (delq key attributes))
1121 (setq key (intern (format "%s@%s" 'total-strokes domain)))
1122 (when (and (memq key attributes)
1123 (setq value (get-char-attribute char key)))
1124 (insert (format "(%s . %S)%s"
1128 (setq attributes (delq key attributes))
1130 (dolist (feature '(ideographic-radical
1133 (setq key (intern (format "%s@%s*sources" feature domain)))
1134 (when (and (memq key attributes)
1135 (setq value (get-char-attribute char key)))
1136 (insert (format "(%s%s" key line-breaking))
1137 (dolist (cell value)
1138 (insert (format " %s" cell)))
1140 (insert line-breaking)
1141 (setq attributes (delq key attributes))
1144 (when (and (memq 'ideographic-strokes attributes)
1145 (setq value (get-char-attribute char 'ideographic-strokes)))
1146 (setq strokes value)
1147 (insert (format "(ideographic-strokes . %S)%s"
1150 (setq attributes (delq 'ideographic-strokes attributes))
1152 (when (and (memq 'kangxi-radical attributes)
1153 (setq value (get-char-attribute char 'kangxi-radical)))
1154 (unless (eq value radical)
1155 (insert (format "(kangxi-radical\t . %S)\t; %c%s"
1157 (ideographic-radical value)
1160 (setq radical value)))
1161 (setq attributes (delq 'kangxi-radical attributes))
1163 (when (and (memq 'kangxi-strokes attributes)
1164 (setq value (get-char-attribute char 'kangxi-strokes)))
1165 (unless (eq value strokes)
1166 (insert (format "(kangxi-strokes\t . %S)%s"
1170 (setq strokes value)))
1171 (setq attributes (delq 'kangxi-strokes attributes))
1173 ;; (when (and (memq 'japanese-radical attributes)
1174 ;; (setq value (get-char-attribute char 'japanese-radical)))
1175 ;; (unless (eq value radical)
1176 ;; (insert (format "(japanese-radical\t . %S)\t; %c%s"
1178 ;; (ideographic-radical value)
1181 ;; (setq radical value)))
1182 ;; (setq attributes (delq 'japanese-radical attributes))
1184 (when (and (memq 'japanese-strokes attributes)
1185 (setq value (get-char-attribute char 'japanese-strokes)))
1186 (unless (eq value strokes)
1187 (insert (format "(japanese-strokes\t . %S)%s"
1191 (setq strokes value)))
1192 (setq attributes (delq 'japanese-strokes attributes))
1194 (when (and (memq 'cns-radical attributes)
1195 (setq value (get-char-attribute char 'cns-radical)))
1196 (insert (format "(cns-radical\t . %S)\t; %c%s"
1198 (ideographic-radical value)
1200 (setq attributes (delq 'cns-radical attributes))
1202 (when (and (memq 'cns-strokes attributes)
1203 (setq value (get-char-attribute char 'cns-strokes)))
1204 (unless (eq value strokes)
1205 (insert (format "(cns-strokes\t . %S)%s"
1209 (setq strokes value)))
1210 (setq attributes (delq 'cns-strokes attributes))
1212 ;; (when (and (memq 'shinjigen-1-radical attributes)
1213 ;; (setq value (get-char-attribute char 'shinjigen-1-radical)))
1214 ;; (unless (eq value radical)
1215 ;; (insert (format "(shinjigen-1-radical . %S)\t; %c%s"
1217 ;; (ideographic-radical value)
1220 ;; (setq radical value)))
1221 ;; (setq attributes (delq 'shinjigen-1-radical attributes))
1223 ;; (when (and (memq 'ideographic- attributes)
1224 ;; (setq value (get-char-attribute char 'ideographic-)))
1225 ;; (insert "(ideographic- ")
1226 ;; (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1228 ;; (while (consp value)
1229 ;; (setq cell (car value))
1230 ;; (if (integerp cell)
1231 ;; (setq cell (decode-char '=ucs cell)))
1232 ;; (cond ((characterp cell)
1236 ;; (insert (format "%S" cell))
1237 ;; (char-db-insert-char-spec cell readable))
1238 ;; (setq separator lbs))
1242 ;; (if (consp (car cell))
1243 ;; (char-db-insert-char-spec cell readable)
1244 ;; (char-db-insert-char-reference cell readable))
1245 ;; (setq separator lbs))
1248 ;; (insert separator))
1249 ;; (insert (prin1-to-string cell))
1250 ;; (setq separator " ")))
1251 ;; (setq value (cdr value)))
1253 ;; (insert line-breaking)
1254 ;; (setq attributes (delq 'ideographic- attributes)))
1255 (when (and (memq 'total-strokes attributes)
1256 (setq value (get-char-attribute char 'total-strokes)))
1257 (insert (format "(total-strokes . %S)%s"
1260 (setq attributes (delq 'total-strokes attributes))
1262 ;; (when (and (memq '->ideograph attributes)
1263 ;; (setq value (get-char-attribute char '->ideograph)))
1264 ;; (insert (format "(->ideograph\t%s)%s"
1265 ;; (mapconcat (lambda (code)
1266 ;; (cond ((symbolp code)
1267 ;; (symbol-name code))
1269 ;; (format "#x%04X" code))
1272 ;; line-breaking code))))
1275 ;; (setq attributes (delq '->ideograph attributes))
1277 ;; (when (and (memq '->decomposition attributes)
1278 ;; (setq value (get-char-attribute char '->decomposition)))
1279 ;; (insert (format "(->decomposition\t%s)%s"
1280 ;; (mapconcat (lambda (code)
1281 ;; (cond ((symbolp code)
1282 ;; (symbol-name code))
1283 ;; ((characterp code)
1285 ;; (format "%S" code)
1290 ;; (format "#x%04X" code))
1292 ;; (format "%s%S" line-breaking code))))
1295 ;; (setq attributes (delq '->decomposition attributes))
1297 (if (equal (get-char-attribute char '->titlecase)
1298 (get-char-attribute char '->uppercase))
1299 (setq attributes (delq '->titlecase attributes)))
1300 (when (and (memq '->mojikyo attributes)
1301 (setq value (get-char-attribute char '->mojikyo)))
1302 (insert (format "(->mojikyo\t\t. %06d)\t; %c%s"
1303 value (decode-char 'mojikyo value)
1305 (setq attributes (delq '->mojikyo attributes))
1307 ;; (when (and (memq 'hanyu-dazidian-vol attributes)
1308 ;; (setq value (get-char-attribute char 'hanyu-dazidian-vol)))
1309 ;; (insert (format "(hanyu-dazidian-vol . %d)%s"
1310 ;; value line-breaking))
1311 ;; (setq attributes (delq 'hanyu-dazidian-vol attributes))
1313 ;; (when (and (memq 'hanyu-dazidian-page attributes)
1314 ;; (setq value (get-char-attribute char 'hanyu-dazidian-page)))
1315 ;; (insert (format "(hanyu-dazidian-page . %d)%s"
1316 ;; value line-breaking))
1317 ;; (setq attributes (delq 'hanyu-dazidian-page attributes))
1319 ;; (when (and (memq 'hanyu-dazidian-char attributes)
1320 ;; (setq value (get-char-attribute char 'hanyu-dazidian-char)))
1321 ;; (insert (format "(hanyu-dazidian-char . %d)%s"
1322 ;; value line-breaking))
1323 ;; (setq attributes (delq 'hanyu-dazidian-char attributes))
1326 (dolist (ignored '(composition
1327 ->denotational <-subsumptive ->ucs-unified
1328 ->ideographic-component-forms))
1329 (setq attributes (delq ignored attributes))))
1331 (setq name (car attributes))
1332 (unless (eq (setq value (get-char-attribute char name 'value-is-empty))
1334 (cond ((setq ret (find-charset name))
1335 (setq name (charset-name ret))
1336 (when (not (memq name dest-ccss))
1337 (setq dest-ccss (cons name dest-ccss))
1338 (char-db-insert-ccs-feature name value line-breaking))
1340 ((string-match "^=>ucs@" (symbol-name name))
1341 (insert (format "(%-18s . #x%04X)\t; %c%s"
1342 name value (decode-char '=ucs value)
1345 ((eq name 'jisx0208-1978/4X)
1346 (insert (format "(%-18s . #x%04X)%s"
1352 (not (eq name '->subsumptive))
1353 (not (eq name '->uppercase))
1354 (not (eq name '->lowercase))
1355 (not (eq name '->titlecase))
1356 (not (eq name '->canonical))
1357 (not (eq name '->Bopomofo))
1358 (not (eq name '->mistakable))
1359 (not (eq name '->ideographic-variants))
1360 (null (get-char-attribute
1361 char (intern (format "%s*sources" name))))
1362 (not (string-match "\\*sources$" (symbol-name name)))
1363 (null (get-char-attribute
1364 char (intern (format "%s*note" name))))
1365 (not (string-match "\\*note$" (symbol-name name)))
1366 (or (eq name '<-identical)
1367 (eq name '<-uppercase)
1368 (eq name '<-lowercase)
1369 (eq name '<-titlecase)
1370 (eq name '<-canonical)
1371 (eq name '<-ideographic-variants)
1372 ;; (eq name '<-synonyms)
1373 (string-match "^<-synonyms" (symbol-name name))
1374 (eq name '<-mistakable)
1375 (when (string-match "^->" (symbol-name name))
1377 ((string-match "^->fullwidth" (symbol-name name))
1378 (not (and (consp value)
1379 (characterp (car value))
1381 (car value) '=ucs 'defined-only)))
1386 ((or (eq name 'ideographic-structure)
1387 (eq name 'ideographic-combination)
1388 ;; (eq name 'ideographic-)
1389 (eq name '=decomposition)
1390 (char-feature-base-name= '=decomposition name)
1391 (char-feature-base-name= '=>decomposition name)
1392 ;; (string-match "^=>*decomposition\\(@[^*]+\\)?$"
1393 ;; (symbol-name name))
1394 (string-match "^\\(->\\|<-\\)[^*]*$" (symbol-name name))
1395 (string-match "^\\(->\\|<-\\)[^*]*\\*sources$"
1398 (char-db-insert-relation-feature char name value
1401 ;; ((memq name '(ideograph=
1402 ;; original-ideograph-of
1403 ;; ancient-ideograph-of
1404 ;; vulgar-ideograph-of
1405 ;; wrong-ideograph-of
1406 ;; ;; simplified-ideograph-of
1407 ;; ideographic-variants
1408 ;; ;; ideographic-different-form-of
1410 ;; (insert (format "(%-18s%s " name line-breaking))
1411 ;; (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1413 ;; (while (consp value)
1414 ;; (setq cell (car value))
1415 ;; (if (and (consp cell)
1416 ;; (consp (car cell)))
1420 ;; (char-db-insert-alist cell readable)
1421 ;; (setq separator lbs))
1423 ;; (insert separator))
1424 ;; (insert (prin1-to-string cell))
1425 ;; (setq separator " "))
1426 ;; (setq value (cdr value)))
1428 ;; (insert line-breaking))
1430 (insert (format "(%-18s " name))
1431 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1433 (while (consp value)
1434 (setq cell (car value))
1435 (if (and (consp cell)
1437 (setq ret (condition-case nil
1445 (setq key (car (car rest)))
1446 (if (find-charset key)
1447 (setq cal (cons key cal))
1448 (setq al (cons key al)))
1449 (setq rest (cdr rest)))
1452 (insert-char-attributes ret
1456 (setq separator lbs))
1457 (setq ret (prin1-to-string cell))
1459 (if (< (+ (current-column)
1466 (setq separator " "))
1467 (setq value (cdr value)))
1469 (insert line-breaking))
1471 (insert (format "(%-18s" name))
1472 (setq ret (prin1-to-string value))
1473 (unless (< (+ (current-column)
1477 (insert line-breaking))
1478 (insert " . " ret ")" line-breaking)
1479 ;; (insert (format "(%-18s . %S)%s"
1484 (setq attributes (cdr attributes)))
1487 (defun insert-char-data (char &optional readable
1490 (narrow-to-region (point)(point))
1491 (insert "(define-char
1493 (insert-char-attributes char readable attributes)
1495 (goto-char (point-min))
1496 (while (re-search-forward "[ \t]+$" nil t)
1499 (goto-char (point-min))
1500 (while (re-search-forward "[ \t][ \t][ \t]*" nil t)
1501 (let ((column (current-column))
1502 (indent-tabs-mode t))
1503 (delete-region (match-beginning 0) (point))
1504 (indent-to column)))
1505 (goto-char (point-max))
1506 ;; (tabify (point-min)(point-max))
1509 (defun insert-char-data-with-variant (char &optional printable
1511 script excluded-script)
1512 (insert-char-data char printable)
1513 (let ((variants (char-variants char))
1516 (setq variants (sort variants #'<))
1517 (setq rest variants)
1518 (setq variants (cons char variants))
1520 (setq variant (car rest))
1521 (unless (get-char-attribute variant '<-subsumptive)
1522 (if (and (or (null script)
1523 (null (setq vs (get-char-attribute variant 'script)))
1525 (or (null excluded-script)
1526 (null (setq vs (get-char-attribute variant 'script)))
1527 (not (memq excluded-script vs))))
1528 (unless (and no-ucs-unified (get-char-attribute variant '=ucs))
1529 (insert-char-data variant printable)
1530 (if (setq ret (char-variants variant))
1532 (or (memq (car ret) variants)
1533 ;; (get-char-attribute (car ret) '<-subsumptive)
1534 (setq rest (nconc rest (list (car ret)))))
1535 (setq ret (cdr ret)))))))
1536 (setq rest (cdr rest)))))
1538 (defun insert-char-range-data (min max &optional script excluded-script)
1541 (while (<= code max)
1542 (setq char (decode-char '=ucs code))
1543 (if (encode-char char '=ucs 'defined-only)
1544 (insert-char-data-with-variant char nil 'no-ucs-unified
1545 script excluded-script))
1546 (setq code (1+ code)))))
1548 (defun write-char-range-data-to-file (min max file
1549 &optional script excluded-script)
1550 (let ((coding-system-for-write char-db-file-coding-system))
1552 (insert (format ";; -*- coding: %s -*-\n"
1553 char-db-file-coding-system))
1554 (insert-char-range-data min max script excluded-script)
1555 (write-region (point-min)(point-max) file))))
1557 (defvar what-character-original-window-configuration)
1560 (defun what-char-definition (char)
1561 (interactive (list (char-after)))
1562 (let ((buf (get-buffer-create "*Character Description*"))
1563 (the-buf (current-buffer))
1564 (win-conf (current-window-configuration)))
1566 (make-local-variable 'what-character-original-window-configuration)
1567 (setq what-character-original-window-configuration win-conf)
1568 (setq buffer-read-only nil)
1572 (insert-char-data-with-variant char 'printable)
1573 (unless (char-attribute-alist char)
1574 (insert (format ";; = %c\n"
1575 (let* ((rest (split-char char))
1579 (setq code (logior (lsh code 8)
1581 (decode-char ccs code)))))
1582 ;; (char-db-update-comment)
1583 (set-buffer-modified-p nil)
1584 (view-mode the-buf (lambda (buf)
1585 (set-window-configuration
1586 what-character-original-window-configuration)
1588 (goto-char (point-min)))
1590 (set-window-configuration
1591 what-character-original-window-configuration)
1592 (signal (car err) (cdr err)))))))
1598 (provide 'char-db-util)
1600 ;;; char-db-util.el ends here