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 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
211 ;; =>>>adobe-japan1-0
212 ;; =>>>adobe-japan1-1
213 ;; =>>>adobe-japan1-2
214 ;; =>>>adobe-japan1-3
215 ;; =>>>adobe-japan1-4
216 ;; =>>>adobe-japan1-5
217 ;; =>>>adobe-japan1-6
221 ;; =>>>hanyo-denshi/ja
222 ;; =>>>hanyo-denshi/jb
223 ;; =>>>hanyo-denshi/jc
224 ;; =>>>hanyo-denshi/ft
225 ;; =>>>hanyo-denshi/ib
226 ;; =>>>hanyo-denshi/hg
227 ;; =>>>hanyo-denshi/jt
228 ;; =>>>hanyo-denshi/ks
342 ;;; @ char-db formatters
345 (defun char-db-make-char-spec (char)
347 (cond ((characterp char)
348 (cond ((and (setq ret (encode-char char '=ucs 'defined-only))
349 (not (and (<= #xE000 ret)(<= ret #xF8FF))))
350 (setq char-spec (list (cons '=ucs ret)))
351 (cond ((setq ret (get-char-attribute char 'name))
352 (setq char-spec (cons (cons 'name ret) char-spec))
354 ((setq ret (get-char-attribute char 'name*))
355 (setq char-spec (cons (cons 'name* ret) char-spec))
358 ((encode-char char '=mj 'defined-only)
360 (dolist (ccs (charset-list))
361 (if (and (or (eq ccs '=mj)
362 ;; (eq (charset-property ccs 'iso-ir) 177)
363 (string-match "=ucs@" (symbol-name ccs))
365 (setq ccs (charset-name ccs))
366 (null (assq ccs char-spec))
367 (setq ret (encode-char char ccs 'defined-only)))
368 (setq char-spec (cons (cons ccs ret) char-spec))))
370 ((encode-char char '==mj 'defined-only)
372 (dolist (ccs (charset-list))
373 (if (and (or (eq ccs '==mj)
374 ;; (eq (charset-property ccs 'iso-ir) 177)
375 (string-match "=ucs@" (symbol-name ccs))
377 (setq ccs (charset-name ccs))
378 (null (assq ccs char-spec))
379 (setq ret (encode-char char ccs 'defined-only)))
380 (setq char-spec (cons (cons ccs ret) char-spec))))
382 ((encode-char char '=adobe-japan1 'defined-only)
384 (dolist (ccs (charset-list))
385 (if (and (or (memq ccs
394 ;; (eq (charset-property ccs 'iso-ir) 177)
395 (string-match "=ucs@" (symbol-name ccs))
397 (setq ccs (charset-name ccs))
398 (null (assq ccs char-spec))
399 (setq ret (encode-char char ccs 'defined-only)))
400 (setq char-spec (cons (cons ccs ret) char-spec))))
402 ((encode-char char '==adobe-japan1 'defined-only)
404 (dolist (ccs (charset-list))
405 (if (and (or (memq ccs
414 ;; (eq (charset-property ccs 'iso-ir) 177)
415 (string-match "=ucs@" (symbol-name ccs))
417 (setq ccs (charset-name ccs))
418 (null (assq ccs char-spec))
419 (setq ret (encode-char char ccs 'defined-only)))
420 (setq char-spec (cons (cons ccs ret) char-spec))))
424 (let ((rest char-db-coded-charset-priority-list)
427 (setq ccs (charset-name
428 (find-charset (car rest))))
430 (encode-char char ccs
432 (throw 'tag (cons ccs ret)))
433 (setq rest (cdr rest))))))
434 (setq char-spec (list ret))
435 (dolist (ccs (delq (car ret) (charset-list)))
436 (if (and (or (charset-iso-final-char ccs)
443 (eq (charset-property ccs 'iso-ir) 177)
444 ;; (string-match "=ucs@" (symbol-name ccs))
446 (setq ccs (charset-name ccs))
447 (null (assq ccs char-spec))
448 (setq ret (encode-char char ccs 'defined-only)))
449 (setq char-spec (cons (cons ccs ret) char-spec))))
451 (setq char-spec (split-char char)))
452 (cond ((setq ret (get-char-attribute char 'name))
453 (setq char-spec (cons (cons 'name ret) char-spec))
455 ((setq ret (get-char-attribute char 'name*))
456 (setq char-spec (cons (cons 'name* ret) char-spec))
459 ((setq ret (get-char-attribute
460 char 'ideographic-combination))
462 (cons (cons 'ideographic-combination ret)
469 (defun char-db-insert-char-spec (char &optional readable column
472 (setq column (current-column)))
473 (let (char-spec temp-char)
474 (setq char-spec (char-db-make-char-spec char))
475 (unless (or (characterp char) ; char
477 (setq char (find-char char-spec))
479 ;; define temporary character
480 ;; Current implementation is dirty.
481 (setq temp-char (define-char (cons '(ideograph-daikanwa . 0)
483 (remove-char-attribute temp-char 'ideograph-daikanwa)
484 (setq char temp-char))
485 (insert-char-attributes char
487 (union (mapcar #'car char-spec)
491 ;; undefine temporary character
492 ;; Current implementation is dirty.
493 (setq char-spec (char-attribute-alist temp-char))
495 (remove-char-attribute temp-char (car (car char-spec)))
496 (setq char-spec (cdr char-spec))))))
498 (defun char-db-insert-alist (alist &optional readable column)
500 (setq column (current-column)))
502 (concat "\n" (make-string (1+ column) ?\ )))
506 lbs cell rest separator)
509 (setq name (car (car alist))
510 value (cdr (car alist)))
511 (cond ((eq name 'char)
513 (if (setq ret (condition-case nil
521 (setq key (car (car value)))
522 ;; (if (find-charset key)
523 ;; (setq cal (cons key cal))
524 (setq al (cons key al))
526 (setq value (cdr value)))
527 (insert-char-attributes ret
531 (insert (prin1-to-string value)))
533 (insert line-breaking))
535 (insert (format "(%-18s " name))
536 (setq lbs (concat "\n" (make-string (current-column) ?\ )))
538 (setq cell (car value))
539 (if (and (consp cell)
541 (setq ret (condition-case nil
551 (setq key (car (car rest)))
552 ;; (if (find-charset key)
553 ;; (setq cal (cons key cal))
554 (setq al (cons key al))
556 (setq rest (cdr rest)))
559 (insert-char-attributes ret
563 (setq separator lbs))
566 (insert (prin1-to-string cell))
567 (setq separator " "))
568 (setq value (cdr value)))
570 (insert line-breaking))
572 (insert (format "(%-18s . %S)%s"
575 (setq alist (cdr alist))))
578 (defun char-db-insert-char-reference (plist &optional readable column)
580 (setq column (current-column)))
582 (concat "\n" (make-string (1+ column) ?\ )))
587 (setq name (pop plist))
588 (setq value (pop plist))
589 (cond ((eq name :char)
592 (cond ((numberp value)
593 (setq value (decode-char '=ucs value)))
595 ;; (setq value (or (find-char value)
598 (char-db-insert-char-spec value readable)
599 (insert line-breaking)
602 (insert (format "%s%s\t%d ; %c%s"
605 (ideographic-radical value)
609 (insert (format "%s%s\t%S" separator name value))
610 (setq separator line-breaking)))
614 (defun char-db-decode-isolated-char (ccs code-point)
617 (cond ((eq ccs 'arabic-iso8859-6)
618 (decode-char ccs code-point))
620 ;; (decode-builtin-char '==gt code-point))
621 ((and (memq ccs '(=gt-pj-1
632 (setq ret (decode-char ccs code-point))
633 (setq ret (encode-char ret '=gt 'defined-only)))
634 (decode-builtin-char '=gt ret))
636 (decode-builtin-char ccs code-point))))
638 (or (decode-char ccs code-point)
639 (define-char (list (cons ccs code-point)))))
640 ((and (<= 0 (char-int ret))
641 (<= (char-int ret) #x1F))
642 (decode-char '=ucs (+ #x2400 (char-int ret))))
643 ((= (char-int ret) #x7F)
647 (defvar char-db-convert-obsolete-format t)
649 (defun char-db-insert-ccs-feature (name value line-breaking)
655 ((memq name '(=>iwds-1
658 =shinjigen@1ed ==shinjigen@1ed
659 =shinjigen@rev ==shinjigen@rev
660 =shinjigen/+p@rev ==shinjigen/+p@rev
661 ===daikanwa/ho ==daikanwa/ho
662 =daikanwa/ho =>>daikanwa/ho =>daikanwa/ho))
663 "(%-18s . %04d)\t; %c")
664 ((eq name '=shinjigen@1ed/24pr)
665 "(%-18s . %04d)\t; %c")
669 ==daikanwa =daikanwa =>>daikanwa =>daikanwa
670 =daikanwa@rev1 =daikanwa@rev2
671 =daikanwa/+p ==daikanwa/+p ===daikanwa/+p
673 =daikanwa/+2p =>>daikanwa/+2p
678 =adobe-japan1-0 ==adobe-japan1-0 ===adobe-japan1-0
679 =adobe-japan1-1 ==adobe-japan1-1 ===adobe-japan1-1
680 =adobe-japan1-2 ==adobe-japan1-2 ===adobe-japan1-2
681 =adobe-japan1-3 ==adobe-japan1-3 ===adobe-japan1-3
682 =adobe-japan1-4 ==adobe-japan1-4 ===adobe-japan1-4
683 =adobe-japan1-5 ==adobe-japan1-5 ===adobe-japan1-5
684 =adobe-japan1-6 ==adobe-japan1-6 ===adobe-japan1-6
685 =>>adobe-japan1-0 =+>adobe-japan1-0
686 =>>adobe-japan1-1 =+>adobe-japan1-1
687 =>>adobe-japan1-2 =+>adobe-japan1-2
688 =>>adobe-japan1-3 =+>adobe-japan1-3
689 =>>adobe-japan1-4 =+>adobe-japan1-4
690 =>>adobe-japan1-5 =+>adobe-japan1-5
691 =>>adobe-japan1-6 =+>adobe-japan1-6
692 =>cbeta =cbeta =>>cbeta ==cbeta ===cbeta
693 =zinbun-oracle =>zinbun-oracle
694 ===hng-jou ===hng-keg ===hng-dng ===hng-mam
695 ===hng-drt ===hng-kgk ===hng-myz ===hng-kda
696 ===hng-khi ===hng-khm ===hng-hok ===hng-kyd ===hng-sok
697 ===hng-yhk ===hng-kak ===hng-kar ===hng-kae
698 ===hng-sys ===hng-tsu ===hng-tzj
699 ===hng-hos ===hng-nak ===hng-jhk
700 ===hng-hod ===hng-gok ===hng-ink ===hng-nto
701 ===hng-nkm ===hng-k24 ===hng-nkk
702 ===hng-kcc ===hng-kcj ===hng-kbk ===hng-sik
703 ===hng-skk ===hng-kyu ===hng-ksk ===hng-wan
704 ===hng-okd ===hng-wad ===hng-kmi
705 ===hng-zkd ===hng-doh ===hng-jyu
706 ===hng-tzs ===hng-kss ===hng-kyo
708 ;; (string-match "^=adobe-" (symbol-name name))
710 "(%-18s . %05d)\t; %c")
711 ((memq name '(=hanyo-denshi/ks
712 ==hanyo-denshi/ks ===hanyo-denshi/ks
717 "(%-18s . %06d)\t; %c")
718 ((memq name '(=hanyo-denshi/tk))
719 "(%-18s . %08d)\t; %c")
720 ((>= (charset-dimension name) 2)
721 "(%-18s . #x%04X)\t; %c")
723 "(%-18s . #x%02X)\t; %c"))
725 (if (= (charset-iso-graphic-plane name) 1)
727 (cond ((= (charset-dimension name) 1)
729 ((= (charset-dimension name) 2)
731 ((= (charset-dimension name) 3)
735 (char-db-decode-isolated-char name value)))
736 (if (and (= (charset-chars name) 94)
737 (= (charset-dimension name) 2))
738 (insert (format " [%02d-%02d]"
739 (- (lsh value -8) 32)
740 (- (logand value 255) 32))))
743 (insert (format "(%-18s . %s)" name value))
745 (insert line-breaking))
747 (defun char-db-insert-relation-feature (char name value line-breaking
749 (insert (format "(%-18s%s " name line-breaking))
750 (let ((lbs (concat "\n" (make-string (current-column) ?\ )))
751 separator cell sources required-features
754 (setq cell (car value))
756 (setq cell (decode-char '=ucs cell)))
758 ((eq name '->subsumptive)
759 (when (or (not (some (lambda (atr)
760 (get-char-attribute cell atr))
761 char-db-ignored-attributes))
763 (encode-char cell ccs 'defined-only))
767 (let ((char-db-ignored-attributes
769 char-db-ignored-attributes)))
770 (insert-char-attributes cell readable nil nil 'for-sub-node))
771 (setq separator lbs))
776 char (intern (format "%s*sources" name))))
777 (setq required-features nil)
778 (dolist (source sources)
782 shinjigen shinjigen@1ed shinjigen@rev))
783 (setq required-features
784 (union required-features
796 =shinjigen/+p@rev))))
798 (setq required-features
799 (union required-features
804 ((find-charset (setq ret (intern (format "=%s" source))))
805 (setq required-features
806 (cons ret required-features)))
807 (t (setq required-features
808 (cons source required-features)))))
809 (cond ((string-match "@JP" (symbol-name name))
810 (setq required-features
811 (union required-features
819 ((string-match "@CN" (symbol-name name))
820 (setq required-features
821 (union required-features
828 (insert (format "%S" cell))
829 (char-db-insert-char-spec cell readable
832 (setq separator lbs))
836 (if (consp (car cell))
837 (char-db-insert-char-spec cell readable)
838 (char-db-insert-char-reference cell readable))
839 (setq separator lbs))
843 (insert (prin1-to-string cell))
844 (setq separator " ")))
845 (setq value (cdr value)))
847 (insert line-breaking)))
849 (defun insert-char-attributes (char &optional readable attributes column
852 (setq column (current-column)))
853 (let (name value ; has-long-ccs-name
857 (concat "\n" (make-string (1+ column) ?\ )))
858 lbs cell separator ret
860 dest-ccss ; sources required-features
865 (if (consp attributes)
867 (dolist (name attributes)
868 (unless (memq name char-db-ignored-attributes)
869 (if (find-charset name)
873 (dolist (name (char-attribute-list))
874 (unless (memq name char-db-ignored-attributes)
875 (if (find-charset name)
879 #'char-attribute-name<)))
881 (when (memq '<-subsumptive attributes)
882 (when (or readable (not for-sub-node))
883 (when (setq value (get-char-attribute char '<-subsumptive))
884 (char-db-insert-relation-feature char '<-subsumptive value
887 (setq attributes (delq '<-subsumptive attributes)))
888 (when (and (memq '<-denotational attributes)
889 (setq value (get-char-attribute char '<-denotational)))
890 (char-db-insert-relation-feature char '<-denotational value
893 (setq attributes (delq '<-denotational attributes)))
894 (when (and (memq '<-denotational@component attributes)
895 (setq value (get-char-attribute char '<-denotational@component)))
896 (char-db-insert-relation-feature char '<-denotational@component value
899 (setq attributes (delq '<-denotational@component attributes)))
900 (when (and (memq 'name attributes)
901 (setq value (get-char-attribute char 'name)))
903 (if (> (+ (current-column) (length value)) 48)
906 value line-breaking))
907 (setq attributes (delq 'name attributes))
909 (when (and (memq 'name* attributes)
910 (setq value (get-char-attribute char 'name*)))
912 (if (> (+ (current-column) (length value)) 48)
915 value line-breaking))
916 (setq attributes (delq 'name* attributes))
918 (when (and (memq 'script attributes)
919 (setq value (get-char-attribute char 'script)))
920 (insert (format "(script\t\t%s)%s"
921 (mapconcat (function prin1-to-string)
924 (setq attributes (delq 'script attributes))
926 (dolist (name '(=>ucs =>ucs*))
927 (when (and (memq name attributes)
928 (setq value (get-char-attribute char name)))
929 (insert (format "(%-18s . #x%04X)\t; %c%s"
930 name value (decode-char '=ucs value)
932 (setq attributes (delq name attributes))))
933 (dolist (name '(=>ucs@gb =>ucs@big5))
934 (when (and (memq name attributes)
935 (setq value (get-char-attribute char name)))
936 (insert (format "(%-18s . #x%04X)\t; %c%s"
941 (symbol-name name) 2)))
944 (setq attributes (delq name attributes))
946 ;; (dolist (name '(=>daikanwa))
947 ;; (when (and (memq name attributes)
948 ;; (setq value (get-char-attribute char name)))
950 ;; (if (integerp value)
951 ;; (format "(%-18s . %05d)\t; %c%s"
952 ;; name value (decode-char '=daikanwa value)
954 ;; (format "(%-18s %s)\t; %c%s"
956 ;; (mapconcat (function prin1-to-string)
958 ;; (char-representative-of-daikanwa char)
960 ;; (setq attributes (delq name attributes))))
961 (when (and (memq 'general-category attributes)
962 (setq value (get-char-attribute char 'general-category)))
964 "(general-category\t%s) ; %s%s"
965 (mapconcat (lambda (cell)
968 (cond ((rassoc value unidata-normative-category-alist)
969 "Normative Category")
970 ((rassoc value unidata-informative-category-alist)
971 "Informative Category")
975 (setq attributes (delq 'general-category attributes))
977 (when (and (memq 'bidi-category attributes)
978 (setq value (get-char-attribute char 'bidi-category)))
979 (insert (format "(bidi-category\t. %S)%s"
982 (setq attributes (delq 'bidi-category attributes))
984 (unless (or (not (memq 'mirrored attributes))
985 (eq (setq value (get-char-attribute char 'mirrored 'empty))
987 (insert (format "(mirrored\t\t. %S)%s"
990 (setq attributes (delq 'mirrored attributes))
993 ((and (memq 'decimal-digit-value attributes)
994 (setq value (get-char-attribute char 'decimal-digit-value)))
995 (insert (format "(decimal-digit-value . %S)%s"
998 (setq attributes (delq 'decimal-digit-value attributes))
999 (when (and (memq 'digit-value attributes)
1000 (setq value (get-char-attribute char 'digit-value)))
1001 (insert (format "(digit-value\t . %S)%s"
1004 (setq attributes (delq 'digit-value attributes))
1006 (when (and (memq 'numeric-value attributes)
1007 (setq value (get-char-attribute char 'numeric-value)))
1008 (insert (format "(numeric-value\t . %S)%s"
1011 (setq attributes (delq 'numeric-value attributes))
1015 (when (and (memq 'digit-value attributes)
1016 (setq value (get-char-attribute char 'digit-value)))
1017 (insert (format "(digit-value\t. %S)%s"
1020 (setq attributes (delq 'digit-value attributes))
1022 (when (and (memq 'numeric-value attributes)
1023 (setq value (get-char-attribute char 'numeric-value)))
1024 (insert (format "(numeric-value\t. %S)%s"
1027 (setq attributes (delq 'numeric-value attributes))
1029 (when (and (memq 'iso-10646-comment attributes)
1030 (setq value (get-char-attribute char 'iso-10646-comment)))
1031 (insert (format "(iso-10646-comment\t. %S)%s"
1034 (setq attributes (delq 'iso-10646-comment attributes))
1036 (when (and (memq 'morohashi-daikanwa attributes)
1037 (setq value (get-char-attribute char 'morohashi-daikanwa)))
1038 (insert (format "(morohashi-daikanwa\t%s)%s"
1039 (mapconcat (function prin1-to-string) value " ")
1041 (setq attributes (delq 'morohashi-daikanwa attributes))
1045 (when (and (memq 'ideographic-radical attributes)
1046 (setq value (get-char-attribute char 'ideographic-radical)))
1047 (setq radical value)
1048 (insert (format "(ideographic-radical . %S)\t; %c%s"
1050 (ideographic-radical radical)
1052 (setq attributes (delq 'ideographic-radical attributes))
1054 (when (and (memq 'shuowen-radical attributes)
1055 (setq value (get-char-attribute char 'shuowen-radical)))
1056 (insert (format "(shuowen-radical\t. %S)\t; %c%s"
1058 (shuowen-radical value)
1060 (setq attributes (delq 'shuowen-radical attributes))
1065 char-db-feature-domains
1067 (dolist (feature (char-attribute-list))
1068 (setq feature (symbol-name feature))
1070 "\\(radical\\|strokes\\)@\\([^@*]+\\)\\(\\*\\|$\\)"
1072 (setq domain (intern (match-string 2 feature)))
1073 (unless (memq domain dest)
1074 (setq dest (cons domain dest)))))
1075 (sort dest #'string<))))
1076 (setq key (intern (format "%s@%s" 'ideographic-radical domain)))
1077 (when (and (memq key attributes)
1078 (setq value (get-char-attribute char key)))
1079 (setq radical value)
1080 (insert (format "(%s . %S)\t; %c%s"
1083 (ideographic-radical radical)
1085 (setq attributes (delq key attributes))
1087 (setq key (intern (format "%s@%s" 'ideographic-strokes domain)))
1088 (when (and (memq key attributes)
1089 (setq value (get-char-attribute char key)))
1090 (setq strokes value)
1091 (insert (format "(%s . %S)%s"
1095 (setq attributes (delq key attributes))
1097 (setq key (intern (format "%s@%s" 'total-strokes domain)))
1098 (when (and (memq key attributes)
1099 (setq value (get-char-attribute char key)))
1100 (insert (format "(%s . %S)%s"
1104 (setq attributes (delq key attributes))
1106 (dolist (feature '(ideographic-radical
1109 (setq key (intern (format "%s@%s*sources" feature domain)))
1110 (when (and (memq key attributes)
1111 (setq value (get-char-attribute char key)))
1112 (insert (format "(%s%s" key line-breaking))
1113 (dolist (cell value)
1114 (insert (format " %s" cell)))
1116 (insert line-breaking)
1117 (setq attributes (delq key attributes))
1120 (when (and (memq 'ideographic-strokes attributes)
1121 (setq value (get-char-attribute char 'ideographic-strokes)))
1122 (setq strokes value)
1123 (insert (format "(ideographic-strokes . %S)%s"
1126 (setq attributes (delq 'ideographic-strokes attributes))
1128 (when (and (memq 'kangxi-radical attributes)
1129 (setq value (get-char-attribute char 'kangxi-radical)))
1130 (unless (eq value radical)
1131 (insert (format "(kangxi-radical\t . %S)\t; %c%s"
1133 (ideographic-radical value)
1136 (setq radical value)))
1137 (setq attributes (delq 'kangxi-radical attributes))
1139 (when (and (memq 'kangxi-strokes attributes)
1140 (setq value (get-char-attribute char 'kangxi-strokes)))
1141 (unless (eq value strokes)
1142 (insert (format "(kangxi-strokes\t . %S)%s"
1146 (setq strokes value)))
1147 (setq attributes (delq 'kangxi-strokes attributes))
1149 (when (and (memq 'japanese-radical attributes)
1150 (setq value (get-char-attribute char 'japanese-radical)))
1151 (unless (eq value radical)
1152 (insert (format "(japanese-radical\t . %S)\t; %c%s"
1154 (ideographic-radical value)
1157 (setq radical value)))
1158 (setq attributes (delq 'japanese-radical attributes))
1160 (when (and (memq 'japanese-strokes attributes)
1161 (setq value (get-char-attribute char 'japanese-strokes)))
1162 (unless (eq value strokes)
1163 (insert (format "(japanese-strokes\t . %S)%s"
1167 (setq strokes value)))
1168 (setq attributes (delq 'japanese-strokes attributes))
1170 (when (and (memq 'cns-radical attributes)
1171 (setq value (get-char-attribute char 'cns-radical)))
1172 (insert (format "(cns-radical\t . %S)\t; %c%s"
1174 (ideographic-radical value)
1176 (setq attributes (delq 'cns-radical attributes))
1178 (when (and (memq 'cns-strokes attributes)
1179 (setq value (get-char-attribute char 'cns-strokes)))
1180 (unless (eq value strokes)
1181 (insert (format "(cns-strokes\t . %S)%s"
1185 (setq strokes value)))
1186 (setq attributes (delq 'cns-strokes attributes))
1188 ;; (when (and (memq 'shinjigen-1-radical attributes)
1189 ;; (setq value (get-char-attribute char 'shinjigen-1-radical)))
1190 ;; (unless (eq value radical)
1191 ;; (insert (format "(shinjigen-1-radical . %S)\t; %c%s"
1193 ;; (ideographic-radical value)
1196 ;; (setq radical value)))
1197 ;; (setq attributes (delq 'shinjigen-1-radical attributes))
1199 (when (and (memq 'ideographic- attributes)
1200 (setq value (get-char-attribute char 'ideographic-)))
1201 (insert "(ideographic- ")
1202 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1204 (while (consp value)
1205 (setq cell (car value))
1207 (setq cell (decode-char '=ucs cell)))
1208 (cond ((characterp cell)
1212 (insert (format "%S" cell))
1213 (char-db-insert-char-spec cell readable))
1214 (setq separator lbs))
1218 (if (consp (car cell))
1219 (char-db-insert-char-spec cell readable)
1220 (char-db-insert-char-reference cell readable))
1221 (setq separator lbs))
1225 (insert (prin1-to-string cell))
1226 (setq separator " ")))
1227 (setq value (cdr value)))
1229 (insert line-breaking)
1230 (setq attributes (delq 'ideographic- attributes)))
1231 (when (and (memq 'total-strokes attributes)
1232 (setq value (get-char-attribute char 'total-strokes)))
1233 (insert (format "(total-strokes . %S)%s"
1236 (setq attributes (delq 'total-strokes attributes))
1238 (when (and (memq '->ideograph attributes)
1239 (setq value (get-char-attribute char '->ideograph)))
1240 (insert (format "(->ideograph\t%s)%s"
1241 (mapconcat (lambda (code)
1242 (cond ((symbolp code)
1245 (format "#x%04X" code))
1248 line-breaking code))))
1251 (setq attributes (delq '->ideograph attributes))
1253 ;; (when (and (memq '->decomposition attributes)
1254 ;; (setq value (get-char-attribute char '->decomposition)))
1255 ;; (insert (format "(->decomposition\t%s)%s"
1256 ;; (mapconcat (lambda (code)
1257 ;; (cond ((symbolp code)
1258 ;; (symbol-name code))
1259 ;; ((characterp code)
1261 ;; (format "%S" code)
1266 ;; (format "#x%04X" code))
1268 ;; (format "%s%S" line-breaking code))))
1271 ;; (setq attributes (delq '->decomposition attributes))
1273 (if (equal (get-char-attribute char '->titlecase)
1274 (get-char-attribute char '->uppercase))
1275 (setq attributes (delq '->titlecase attributes)))
1276 (when (and (memq '->mojikyo attributes)
1277 (setq value (get-char-attribute char '->mojikyo)))
1278 (insert (format "(->mojikyo\t\t. %06d)\t; %c%s"
1279 value (decode-char 'mojikyo value)
1281 (setq attributes (delq '->mojikyo attributes))
1283 (when (and (memq 'hanyu-dazidian-vol attributes)
1284 (setq value (get-char-attribute char 'hanyu-dazidian-vol)))
1285 (insert (format "(hanyu-dazidian-vol . %d)%s"
1286 value line-breaking))
1287 (setq attributes (delq 'hanyu-dazidian-vol attributes))
1289 (when (and (memq 'hanyu-dazidian-page attributes)
1290 (setq value (get-char-attribute char 'hanyu-dazidian-page)))
1291 (insert (format "(hanyu-dazidian-page . %d)%s"
1292 value line-breaking))
1293 (setq attributes (delq 'hanyu-dazidian-page attributes))
1295 (when (and (memq 'hanyu-dazidian-char attributes)
1296 (setq value (get-char-attribute char 'hanyu-dazidian-char)))
1297 (insert (format "(hanyu-dazidian-char . %d)%s"
1298 value line-breaking))
1299 (setq attributes (delq 'hanyu-dazidian-char attributes))
1302 (dolist (ignored '(composition
1303 ->denotational <-subsumptive ->ucs-unified
1304 ->ideographic-component-forms))
1305 (setq attributes (delq ignored attributes))))
1307 (setq name (car attributes))
1308 (unless (eq (setq value (get-char-attribute char name 'value-is-empty))
1310 (cond ((setq ret (find-charset name))
1311 (setq name (charset-name ret))
1312 (when (not (memq name dest-ccss))
1313 (setq dest-ccss (cons name dest-ccss))
1314 (char-db-insert-ccs-feature name value line-breaking))
1316 ((string-match "^=>ucs@" (symbol-name name))
1317 (insert (format "(%-18s . #x%04X)\t; %c%s"
1318 name value (decode-char '=ucs value)
1321 ((eq name 'jisx0208-1978/4X)
1322 (insert (format "(%-18s . #x%04X)%s"
1328 (not (eq name '->subsumptive))
1329 (not (eq name '->uppercase))
1330 (not (eq name '->lowercase))
1331 (not (eq name '->titlecase))
1332 (not (eq name '->canonical))
1333 (not (eq name '->Bopomofo))
1334 (not (eq name '->mistakable))
1335 (not (eq name '->ideographic-variants))
1336 (null (get-char-attribute
1337 char (intern (format "%s*sources" name))))
1338 (not (string-match "\\*sources$" (symbol-name name)))
1339 (null (get-char-attribute
1340 char (intern (format "%s*note" name))))
1341 (not (string-match "\\*note$" (symbol-name name)))
1342 (or (eq name '<-identical)
1343 (eq name '<-uppercase)
1344 (eq name '<-lowercase)
1345 (eq name '<-titlecase)
1346 (eq name '<-canonical)
1347 (eq name '<-ideographic-variants)
1348 ;; (eq name '<-synonyms)
1349 (string-match "^<-synonyms" (symbol-name name))
1350 (eq name '<-mistakable)
1351 (when (string-match "^->" (symbol-name name))
1353 ((string-match "^->fullwidth" (symbol-name name))
1354 (not (and (consp value)
1355 (characterp (car value))
1357 (car value) '=ucs 'defined-only)))
1362 ((or (eq name 'ideographic-structure)
1363 (eq name 'ideographic-combination)
1364 (eq name 'ideographic-)
1365 (eq name '=decomposition)
1366 (char-feature-base-name= '=decomposition name)
1367 (char-feature-base-name= '=>decomposition name)
1368 ;; (string-match "^=>*decomposition\\(@[^*]+\\)?$"
1369 ;; (symbol-name name))
1370 (string-match "^\\(->\\|<-\\)[^*]*$" (symbol-name name))
1371 (string-match "^\\(->\\|<-\\)[^*]*\\*sources$"
1374 (char-db-insert-relation-feature char name value
1377 ((memq name '(ideograph=
1378 original-ideograph-of
1379 ancient-ideograph-of
1382 ;; simplified-ideograph-of
1383 ideographic-variants
1384 ;; ideographic-different-form-of
1386 (insert (format "(%-18s%s " name line-breaking))
1387 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1389 (while (consp value)
1390 (setq cell (car value))
1391 (if (and (consp cell)
1396 (char-db-insert-alist cell readable)
1397 (setq separator lbs))
1400 (insert (prin1-to-string cell))
1401 (setq separator " "))
1402 (setq value (cdr value)))
1404 (insert line-breaking))
1406 (insert (format "(%-18s " name))
1407 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1409 (while (consp value)
1410 (setq cell (car value))
1411 (if (and (consp cell)
1413 (setq ret (condition-case nil
1421 (setq key (car (car rest)))
1422 (if (find-charset key)
1423 (setq cal (cons key cal))
1424 (setq al (cons key al)))
1425 (setq rest (cdr rest)))
1428 (insert-char-attributes ret
1432 (setq separator lbs))
1433 (setq ret (prin1-to-string cell))
1435 (if (< (+ (current-column)
1442 (setq separator " "))
1443 (setq value (cdr value)))
1445 (insert line-breaking))
1447 (insert (format "(%-18s" name))
1448 (setq ret (prin1-to-string value))
1449 (unless (< (+ (current-column)
1453 (insert line-breaking))
1454 (insert " . " ret ")" line-breaking)
1455 ;; (insert (format "(%-18s . %S)%s"
1460 (setq attributes (cdr attributes)))
1463 (defun insert-char-data (char &optional readable
1466 (narrow-to-region (point)(point))
1467 (insert "(define-char
1469 (insert-char-attributes char readable attributes)
1471 (goto-char (point-min))
1472 (while (re-search-forward "[ \t]+$" nil t)
1475 (goto-char (point-min))
1476 (while (re-search-forward "[ \t][ \t][ \t]*" nil t)
1477 (let ((column (current-column))
1478 (indent-tabs-mode t))
1479 (delete-region (match-beginning 0) (point))
1480 (indent-to column)))
1481 (goto-char (point-max))
1482 ;; (tabify (point-min)(point-max))
1485 (defun insert-char-data-with-variant (char &optional printable
1487 script excluded-script)
1488 (insert-char-data char printable)
1489 (let ((variants (char-variants char))
1492 (setq variants (sort variants #'<))
1493 (setq rest variants)
1494 (setq variants (cons char variants))
1496 (setq variant (car rest))
1497 (unless (get-char-attribute variant '<-subsumptive)
1498 (if (and (or (null script)
1499 (null (setq vs (get-char-attribute variant 'script)))
1501 (or (null excluded-script)
1502 (null (setq vs (get-char-attribute variant 'script)))
1503 (not (memq excluded-script vs))))
1504 (unless (and no-ucs-unified (get-char-attribute variant '=ucs))
1505 (insert-char-data variant printable)
1506 (if (setq ret (char-variants variant))
1508 (or (memq (car ret) variants)
1509 ;; (get-char-attribute (car ret) '<-subsumptive)
1510 (setq rest (nconc rest (list (car ret)))))
1511 (setq ret (cdr ret)))))))
1512 (setq rest (cdr rest)))))
1514 (defun insert-char-range-data (min max &optional script excluded-script)
1517 (while (<= code max)
1518 (setq char (decode-char '=ucs code))
1519 (if (encode-char char '=ucs 'defined-only)
1520 (insert-char-data-with-variant char nil 'no-ucs-unified
1521 script excluded-script))
1522 (setq code (1+ code)))))
1524 (defun write-char-range-data-to-file (min max file
1525 &optional script excluded-script)
1526 (let ((coding-system-for-write char-db-file-coding-system))
1528 (insert (format ";; -*- coding: %s -*-\n"
1529 char-db-file-coding-system))
1530 (insert-char-range-data min max script excluded-script)
1531 (write-region (point-min)(point-max) file))))
1533 (defvar what-character-original-window-configuration)
1536 (defun what-char-definition (char)
1537 (interactive (list (char-after)))
1538 (let ((buf (get-buffer-create "*Character Description*"))
1539 (the-buf (current-buffer))
1540 (win-conf (current-window-configuration)))
1542 (make-local-variable 'what-character-original-window-configuration)
1543 (setq what-character-original-window-configuration win-conf)
1544 (setq buffer-read-only nil)
1548 (insert-char-data-with-variant char 'printable)
1549 (unless (char-attribute-alist char)
1550 (insert (format ";; = %c\n"
1551 (let* ((rest (split-char char))
1555 (setq code (logior (lsh code 8)
1557 (decode-char ccs code)))))
1558 ;; (char-db-update-comment)
1559 (set-buffer-modified-p nil)
1560 (view-mode the-buf (lambda (buf)
1561 (set-window-configuration
1562 what-character-original-window-configuration)
1564 (goto-char (point-min)))
1566 (set-window-configuration
1567 what-character-original-window-configuration)
1568 (signal (car err) (cdr err)))))))
1574 (provide 'char-db-util)
1576 ;;; char-db-util.el ends here