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
351 =>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
776 (setq cell (car value))
778 (setq cell (decode-char '=ucs cell)))
780 ((eq name '->subsumptive)
781 (when (or (not (some (lambda (atr)
782 (get-char-attribute cell atr))
783 char-db-ignored-attributes))
785 (encode-char cell ccs 'defined-only))
789 (let ((char-db-ignored-attributes
791 char-db-ignored-attributes)))
792 (insert-char-attributes cell readable nil nil 'for-sub-node))
793 (setq separator lbs))
798 char (intern (format "%s*sources" name))))
799 (setq required-features nil)
800 (dolist (source sources)
804 shinjigen shinjigen@1ed shinjigen@rev))
805 (setq required-features
806 (union required-features
818 =shinjigen/+p@rev))))
820 (setq required-features
821 (union required-features
826 ((find-charset (setq ret (intern (format "=%s" source))))
827 (setq required-features
828 (cons ret required-features)))
829 (t (setq required-features
830 (cons source required-features)))))
831 (cond ((string-match "@JP" (symbol-name name))
832 (setq required-features
833 (union required-features
841 ((string-match "@CN" (symbol-name name))
842 (setq required-features
843 (union required-features
850 (insert (format "%S" cell))
851 (char-db-insert-char-spec cell readable
854 (setq separator lbs))
858 (if (consp (car cell))
859 (char-db-insert-char-spec cell readable)
860 (char-db-insert-char-reference cell readable))
861 (setq separator lbs))
865 (insert (prin1-to-string cell))
866 (setq separator " ")))
867 (setq value (cdr value)))
869 (insert line-breaking)))
871 (defun insert-char-attributes (char &optional readable attributes column
874 (setq column (current-column)))
875 (let (name value ; has-long-ccs-name
879 (concat "\n" (make-string (1+ column) ?\ )))
880 lbs cell separator ret
882 dest-ccss ; sources required-features
887 (if (consp attributes)
889 (dolist (name attributes)
890 (unless (memq name char-db-ignored-attributes)
891 (if (find-charset name)
895 (dolist (name (char-attribute-list))
896 (unless (memq name char-db-ignored-attributes)
897 (if (find-charset name)
901 #'char-attribute-name<)))
903 (when (memq '<-subsumptive attributes)
904 (when (or readable (not for-sub-node))
905 (when (setq value (get-char-attribute char '<-subsumptive))
906 (char-db-insert-relation-feature char '<-subsumptive value
909 (setq attributes (delq '<-subsumptive attributes)))
910 (when (and (memq '<-denotational attributes)
911 (setq value (get-char-attribute char '<-denotational)))
912 (char-db-insert-relation-feature char '<-denotational value
915 (setq attributes (delq '<-denotational attributes)))
916 (when (and (memq '<-denotational@component attributes)
917 (setq value (get-char-attribute char '<-denotational@component)))
918 (char-db-insert-relation-feature char '<-denotational@component value
921 (setq attributes (delq '<-denotational@component attributes)))
922 (when (and (memq 'name attributes)
923 (setq value (get-char-attribute char 'name)))
925 (if (> (+ (current-column) (length value)) 48)
928 value line-breaking))
929 (setq attributes (delq 'name attributes))
931 (when (and (memq 'name* attributes)
932 (setq value (get-char-attribute char 'name*)))
934 (if (> (+ (current-column) (length value)) 48)
937 value line-breaking))
938 (setq attributes (delq 'name* attributes))
940 (when (and (memq 'script attributes)
941 (setq value (get-char-attribute char 'script)))
942 (insert (format "(script\t\t%s)%s"
943 (mapconcat (function prin1-to-string)
946 (setq attributes (delq 'script attributes))
948 (dolist (name '(=>ucs =>ucs*))
949 (when (and (memq name attributes)
950 (setq value (get-char-attribute char name)))
951 (insert (format "(%-18s . #x%04X)\t; %c%s"
952 name value (decode-char '=ucs value)
954 (setq attributes (delq name attributes))))
955 (dolist (name '(=>ucs@gb =>ucs@big5))
956 (when (and (memq name attributes)
957 (setq value (get-char-attribute char name)))
958 (insert (format "(%-18s . #x%04X)\t; %c%s"
963 (symbol-name name) 2)))
966 (setq attributes (delq name attributes))
968 ;; (dolist (name '(=>daikanwa))
969 ;; (when (and (memq name attributes)
970 ;; (setq value (get-char-attribute char name)))
972 ;; (if (integerp value)
973 ;; (format "(%-18s . %05d)\t; %c%s"
974 ;; name value (decode-char '=daikanwa value)
976 ;; (format "(%-18s %s)\t; %c%s"
978 ;; (mapconcat (function prin1-to-string)
980 ;; (char-representative-of-daikanwa char)
982 ;; (setq attributes (delq name attributes))))
983 (when (and (memq 'general-category attributes)
984 (setq value (get-char-attribute char 'general-category)))
986 "(general-category\t%s) ; %s%s"
987 (mapconcat (lambda (cell)
990 (cond ((rassoc value unidata-normative-category-alist)
991 "Normative Category")
992 ((rassoc value unidata-informative-category-alist)
993 "Informative Category")
997 (setq attributes (delq 'general-category attributes))
999 (when (and (memq 'bidi-category attributes)
1000 (setq value (get-char-attribute char 'bidi-category)))
1001 (insert (format "(bidi-category\t. %S)%s"
1004 (setq attributes (delq 'bidi-category attributes))
1006 (unless (or (not (memq 'mirrored attributes))
1007 (eq (setq value (get-char-attribute char 'mirrored 'empty))
1009 (insert (format "(mirrored\t\t. %S)%s"
1012 (setq attributes (delq 'mirrored attributes))
1015 ((and (memq 'decimal-digit-value attributes)
1016 (setq value (get-char-attribute char 'decimal-digit-value)))
1017 (insert (format "(decimal-digit-value . %S)%s"
1020 (setq attributes (delq 'decimal-digit-value attributes))
1021 (when (and (memq 'digit-value attributes)
1022 (setq value (get-char-attribute char 'digit-value)))
1023 (insert (format "(digit-value\t . %S)%s"
1026 (setq attributes (delq 'digit-value attributes))
1028 (when (and (memq 'numeric-value attributes)
1029 (setq value (get-char-attribute char 'numeric-value)))
1030 (insert (format "(numeric-value\t . %S)%s"
1033 (setq attributes (delq 'numeric-value attributes))
1037 (when (and (memq 'digit-value attributes)
1038 (setq value (get-char-attribute char 'digit-value)))
1039 (insert (format "(digit-value\t. %S)%s"
1042 (setq attributes (delq 'digit-value attributes))
1044 (when (and (memq 'numeric-value attributes)
1045 (setq value (get-char-attribute char 'numeric-value)))
1046 (insert (format "(numeric-value\t. %S)%s"
1049 (setq attributes (delq 'numeric-value attributes))
1051 (when (and (memq 'iso-10646-comment attributes)
1052 (setq value (get-char-attribute char 'iso-10646-comment)))
1053 (insert (format "(iso-10646-comment\t. %S)%s"
1056 (setq attributes (delq 'iso-10646-comment attributes))
1058 (when (and (memq 'morohashi-daikanwa attributes)
1059 (setq value (get-char-attribute char 'morohashi-daikanwa)))
1060 (insert (format "(morohashi-daikanwa\t%s)%s"
1061 (mapconcat (function prin1-to-string) value " ")
1063 (setq attributes (delq 'morohashi-daikanwa attributes))
1067 (when (and (memq 'ideographic-radical attributes)
1068 (setq value (get-char-attribute char 'ideographic-radical)))
1069 (setq radical value)
1070 (insert (format "(ideographic-radical . %S)\t; %c%s"
1072 (ideographic-radical radical)
1074 (setq attributes (delq 'ideographic-radical attributes))
1076 (when (and (memq 'shuowen-radical attributes)
1077 (setq value (get-char-attribute char 'shuowen-radical)))
1078 (insert (format "(shuowen-radical\t. %S)\t; %c%s"
1080 (shuowen-radical value)
1082 (setq attributes (delq 'shuowen-radical attributes))
1087 char-db-feature-domains
1089 (dolist (feature (char-attribute-list))
1090 (setq feature (symbol-name feature))
1092 "\\(radical\\|strokes\\)@\\([^@*]+\\)\\(\\*\\|$\\)"
1094 (setq domain (intern (match-string 2 feature)))
1095 (unless (memq domain dest)
1096 (setq dest (cons domain dest)))))
1097 (sort dest #'string<))))
1098 (setq key (intern (format "%s@%s" 'ideographic-radical domain)))
1099 (when (and (memq key attributes)
1100 (setq value (get-char-attribute char key)))
1101 (setq radical value)
1102 (insert (format "(%s . %S)\t; %c%s"
1105 (ideographic-radical radical)
1107 (setq attributes (delq key attributes))
1109 (setq key (intern (format "%s@%s" 'ideographic-strokes domain)))
1110 (when (and (memq key attributes)
1111 (setq value (get-char-attribute char key)))
1112 (setq strokes value)
1113 (insert (format "(%s . %S)%s"
1117 (setq attributes (delq key attributes))
1119 (setq key (intern (format "%s@%s" 'total-strokes domain)))
1120 (when (and (memq key attributes)
1121 (setq value (get-char-attribute char key)))
1122 (insert (format "(%s . %S)%s"
1126 (setq attributes (delq key attributes))
1128 (dolist (feature '(ideographic-radical
1131 (setq key (intern (format "%s@%s*sources" feature domain)))
1132 (when (and (memq key attributes)
1133 (setq value (get-char-attribute char key)))
1134 (insert (format "(%s%s" key line-breaking))
1135 (dolist (cell value)
1136 (insert (format " %s" cell)))
1138 (insert line-breaking)
1139 (setq attributes (delq key attributes))
1142 (when (and (memq 'ideographic-strokes attributes)
1143 (setq value (get-char-attribute char 'ideographic-strokes)))
1144 (setq strokes value)
1145 (insert (format "(ideographic-strokes . %S)%s"
1148 (setq attributes (delq 'ideographic-strokes attributes))
1150 (when (and (memq 'kangxi-radical attributes)
1151 (setq value (get-char-attribute char 'kangxi-radical)))
1152 (unless (eq value radical)
1153 (insert (format "(kangxi-radical\t . %S)\t; %c%s"
1155 (ideographic-radical value)
1158 (setq radical value)))
1159 (setq attributes (delq 'kangxi-radical attributes))
1161 (when (and (memq 'kangxi-strokes attributes)
1162 (setq value (get-char-attribute char 'kangxi-strokes)))
1163 (unless (eq value strokes)
1164 (insert (format "(kangxi-strokes\t . %S)%s"
1168 (setq strokes value)))
1169 (setq attributes (delq 'kangxi-strokes attributes))
1171 ;; (when (and (memq 'japanese-radical attributes)
1172 ;; (setq value (get-char-attribute char 'japanese-radical)))
1173 ;; (unless (eq value radical)
1174 ;; (insert (format "(japanese-radical\t . %S)\t; %c%s"
1176 ;; (ideographic-radical value)
1179 ;; (setq radical value)))
1180 ;; (setq attributes (delq 'japanese-radical attributes))
1182 (when (and (memq 'japanese-strokes attributes)
1183 (setq value (get-char-attribute char 'japanese-strokes)))
1184 (unless (eq value strokes)
1185 (insert (format "(japanese-strokes\t . %S)%s"
1189 (setq strokes value)))
1190 (setq attributes (delq 'japanese-strokes attributes))
1192 (when (and (memq 'cns-radical attributes)
1193 (setq value (get-char-attribute char 'cns-radical)))
1194 (insert (format "(cns-radical\t . %S)\t; %c%s"
1196 (ideographic-radical value)
1198 (setq attributes (delq 'cns-radical attributes))
1200 (when (and (memq 'cns-strokes attributes)
1201 (setq value (get-char-attribute char 'cns-strokes)))
1202 (unless (eq value strokes)
1203 (insert (format "(cns-strokes\t . %S)%s"
1207 (setq strokes value)))
1208 (setq attributes (delq 'cns-strokes attributes))
1210 ;; (when (and (memq 'shinjigen-1-radical attributes)
1211 ;; (setq value (get-char-attribute char 'shinjigen-1-radical)))
1212 ;; (unless (eq value radical)
1213 ;; (insert (format "(shinjigen-1-radical . %S)\t; %c%s"
1215 ;; (ideographic-radical value)
1218 ;; (setq radical value)))
1219 ;; (setq attributes (delq 'shinjigen-1-radical attributes))
1221 ;; (when (and (memq 'ideographic- attributes)
1222 ;; (setq value (get-char-attribute char 'ideographic-)))
1223 ;; (insert "(ideographic- ")
1224 ;; (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1226 ;; (while (consp value)
1227 ;; (setq cell (car value))
1228 ;; (if (integerp cell)
1229 ;; (setq cell (decode-char '=ucs cell)))
1230 ;; (cond ((characterp cell)
1234 ;; (insert (format "%S" cell))
1235 ;; (char-db-insert-char-spec cell readable))
1236 ;; (setq separator lbs))
1240 ;; (if (consp (car cell))
1241 ;; (char-db-insert-char-spec cell readable)
1242 ;; (char-db-insert-char-reference cell readable))
1243 ;; (setq separator lbs))
1246 ;; (insert separator))
1247 ;; (insert (prin1-to-string cell))
1248 ;; (setq separator " ")))
1249 ;; (setq value (cdr value)))
1251 ;; (insert line-breaking)
1252 ;; (setq attributes (delq 'ideographic- attributes)))
1253 (when (and (memq 'total-strokes attributes)
1254 (setq value (get-char-attribute char 'total-strokes)))
1255 (insert (format "(total-strokes . %S)%s"
1258 (setq attributes (delq 'total-strokes attributes))
1260 ;; (when (and (memq '->ideograph attributes)
1261 ;; (setq value (get-char-attribute char '->ideograph)))
1262 ;; (insert (format "(->ideograph\t%s)%s"
1263 ;; (mapconcat (lambda (code)
1264 ;; (cond ((symbolp code)
1265 ;; (symbol-name code))
1267 ;; (format "#x%04X" code))
1270 ;; line-breaking code))))
1273 ;; (setq attributes (delq '->ideograph attributes))
1275 ;; (when (and (memq '->decomposition attributes)
1276 ;; (setq value (get-char-attribute char '->decomposition)))
1277 ;; (insert (format "(->decomposition\t%s)%s"
1278 ;; (mapconcat (lambda (code)
1279 ;; (cond ((symbolp code)
1280 ;; (symbol-name code))
1281 ;; ((characterp code)
1283 ;; (format "%S" code)
1288 ;; (format "#x%04X" code))
1290 ;; (format "%s%S" line-breaking code))))
1293 ;; (setq attributes (delq '->decomposition attributes))
1295 (if (equal (get-char-attribute char '->titlecase)
1296 (get-char-attribute char '->uppercase))
1297 (setq attributes (delq '->titlecase attributes)))
1298 (when (and (memq '->mojikyo attributes)
1299 (setq value (get-char-attribute char '->mojikyo)))
1300 (insert (format "(->mojikyo\t\t. %06d)\t; %c%s"
1301 value (decode-char 'mojikyo value)
1303 (setq attributes (delq '->mojikyo attributes))
1305 ;; (when (and (memq 'hanyu-dazidian-vol attributes)
1306 ;; (setq value (get-char-attribute char 'hanyu-dazidian-vol)))
1307 ;; (insert (format "(hanyu-dazidian-vol . %d)%s"
1308 ;; value line-breaking))
1309 ;; (setq attributes (delq 'hanyu-dazidian-vol attributes))
1311 ;; (when (and (memq 'hanyu-dazidian-page attributes)
1312 ;; (setq value (get-char-attribute char 'hanyu-dazidian-page)))
1313 ;; (insert (format "(hanyu-dazidian-page . %d)%s"
1314 ;; value line-breaking))
1315 ;; (setq attributes (delq 'hanyu-dazidian-page attributes))
1317 ;; (when (and (memq 'hanyu-dazidian-char attributes)
1318 ;; (setq value (get-char-attribute char 'hanyu-dazidian-char)))
1319 ;; (insert (format "(hanyu-dazidian-char . %d)%s"
1320 ;; value line-breaking))
1321 ;; (setq attributes (delq 'hanyu-dazidian-char attributes))
1324 (dolist (ignored '(composition
1325 ->denotational <-subsumptive ->ucs-unified
1326 ->ideographic-component-forms))
1327 (setq attributes (delq ignored attributes))))
1329 (setq name (car attributes))
1330 (unless (eq (setq value (get-char-attribute char name 'value-is-empty))
1332 (cond ((setq ret (find-charset name))
1333 (setq name (charset-name ret))
1334 (when (not (memq name dest-ccss))
1335 (setq dest-ccss (cons name dest-ccss))
1336 (char-db-insert-ccs-feature name value line-breaking))
1338 ((string-match "^=>ucs@" (symbol-name name))
1339 (insert (format "(%-18s . #x%04X)\t; %c%s"
1340 name value (decode-char '=ucs value)
1343 ((eq name 'jisx0208-1978/4X)
1344 (insert (format "(%-18s . #x%04X)%s"
1350 (not (eq name '->subsumptive))
1351 (not (eq name '->uppercase))
1352 (not (eq name '->lowercase))
1353 (not (eq name '->titlecase))
1354 (not (eq name '->canonical))
1355 (not (eq name '->Bopomofo))
1356 (not (eq name '->mistakable))
1357 (not (eq name '->ideographic-variants))
1358 (null (get-char-attribute
1359 char (intern (format "%s*sources" name))))
1360 (not (string-match "\\*sources$" (symbol-name name)))
1361 (null (get-char-attribute
1362 char (intern (format "%s*note" name))))
1363 (not (string-match "\\*note$" (symbol-name name)))
1364 (or (eq name '<-identical)
1365 (eq name '<-uppercase)
1366 (eq name '<-lowercase)
1367 (eq name '<-titlecase)
1368 (eq name '<-canonical)
1369 (eq name '<-ideographic-variants)
1370 ;; (eq name '<-synonyms)
1371 (string-match "^<-synonyms" (symbol-name name))
1372 (eq name '<-mistakable)
1373 (when (string-match "^->" (symbol-name name))
1375 ((string-match "^->fullwidth" (symbol-name name))
1376 (not (and (consp value)
1377 (characterp (car value))
1379 (car value) '=ucs 'defined-only)))
1384 ((or (eq name 'ideographic-structure)
1385 (eq name 'ideographic-combination)
1386 ;; (eq name 'ideographic-)
1387 (eq name '=decomposition)
1388 (char-feature-base-name= '=decomposition name)
1389 (char-feature-base-name= '=>decomposition name)
1390 ;; (string-match "^=>*decomposition\\(@[^*]+\\)?$"
1391 ;; (symbol-name name))
1392 (string-match "^\\(->\\|<-\\)[^*]*$" (symbol-name name))
1393 (string-match "^\\(->\\|<-\\)[^*]*\\*sources$"
1396 (char-db-insert-relation-feature char name value
1399 ;; ((memq name '(ideograph=
1400 ;; original-ideograph-of
1401 ;; ancient-ideograph-of
1402 ;; vulgar-ideograph-of
1403 ;; wrong-ideograph-of
1404 ;; ;; simplified-ideograph-of
1405 ;; ideographic-variants
1406 ;; ;; ideographic-different-form-of
1408 ;; (insert (format "(%-18s%s " name line-breaking))
1409 ;; (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1411 ;; (while (consp value)
1412 ;; (setq cell (car value))
1413 ;; (if (and (consp cell)
1414 ;; (consp (car cell)))
1418 ;; (char-db-insert-alist cell readable)
1419 ;; (setq separator lbs))
1421 ;; (insert separator))
1422 ;; (insert (prin1-to-string cell))
1423 ;; (setq separator " "))
1424 ;; (setq value (cdr value)))
1426 ;; (insert line-breaking))
1428 (insert (format "(%-18s " name))
1429 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1431 (while (consp value)
1432 (setq cell (car value))
1433 (if (and (consp cell)
1435 (setq ret (condition-case nil
1443 (setq key (car (car rest)))
1444 (if (find-charset key)
1445 (setq cal (cons key cal))
1446 (setq al (cons key al)))
1447 (setq rest (cdr rest)))
1450 (insert-char-attributes ret
1454 (setq separator lbs))
1455 (setq ret (prin1-to-string cell))
1457 (if (< (+ (current-column)
1464 (setq separator " "))
1465 (setq value (cdr value)))
1467 (insert line-breaking))
1469 (insert (format "(%-18s" name))
1470 (setq ret (prin1-to-string value))
1471 (unless (< (+ (current-column)
1475 (insert line-breaking))
1476 (insert " . " ret ")" line-breaking)
1477 ;; (insert (format "(%-18s . %S)%s"
1482 (setq attributes (cdr attributes)))
1485 (defun insert-char-data (char &optional readable
1488 (narrow-to-region (point)(point))
1489 (insert "(define-char
1491 (insert-char-attributes char readable attributes)
1493 (goto-char (point-min))
1494 (while (re-search-forward "[ \t]+$" nil t)
1497 (goto-char (point-min))
1498 (while (re-search-forward "[ \t][ \t][ \t]*" nil t)
1499 (let ((column (current-column))
1500 (indent-tabs-mode t))
1501 (delete-region (match-beginning 0) (point))
1502 (indent-to column)))
1503 (goto-char (point-max))
1504 ;; (tabify (point-min)(point-max))
1507 (defun insert-char-data-with-variant (char &optional printable
1509 script excluded-script)
1510 (insert-char-data char printable)
1511 (let ((variants (char-variants char))
1514 (setq variants (sort variants #'<))
1515 (setq rest variants)
1516 (setq variants (cons char variants))
1518 (setq variant (car rest))
1519 (unless (get-char-attribute variant '<-subsumptive)
1520 (if (and (or (null script)
1521 (null (setq vs (get-char-attribute variant 'script)))
1523 (or (null excluded-script)
1524 (null (setq vs (get-char-attribute variant 'script)))
1525 (not (memq excluded-script vs))))
1526 (unless (and no-ucs-unified (get-char-attribute variant '=ucs))
1527 (insert-char-data variant printable)
1528 (if (setq ret (char-variants variant))
1530 (or (memq (car ret) variants)
1531 ;; (get-char-attribute (car ret) '<-subsumptive)
1532 (setq rest (nconc rest (list (car ret)))))
1533 (setq ret (cdr ret)))))))
1534 (setq rest (cdr rest)))))
1536 (defun insert-char-range-data (min max &optional script excluded-script)
1539 (while (<= code max)
1540 (setq char (decode-char '=ucs code))
1541 (if (encode-char char '=ucs 'defined-only)
1542 (insert-char-data-with-variant char nil 'no-ucs-unified
1543 script excluded-script))
1544 (setq code (1+ code)))))
1546 (defun write-char-range-data-to-file (min max file
1547 &optional script excluded-script)
1548 (let ((coding-system-for-write char-db-file-coding-system))
1550 (insert (format ";; -*- coding: %s -*-\n"
1551 char-db-file-coding-system))
1552 (insert-char-range-data min max script excluded-script)
1553 (write-region (point-min)(point-max) file))))
1555 (defvar what-character-original-window-configuration)
1558 (defun what-char-definition (char)
1559 (interactive (list (char-after)))
1560 (let ((buf (get-buffer-create "*Character Description*"))
1561 (the-buf (current-buffer))
1562 (win-conf (current-window-configuration)))
1564 (make-local-variable 'what-character-original-window-configuration)
1565 (setq what-character-original-window-configuration win-conf)
1566 (setq buffer-read-only nil)
1570 (insert-char-data-with-variant char 'printable)
1571 (unless (char-attribute-alist char)
1572 (insert (format ";; = %c\n"
1573 (let* ((rest (split-char char))
1577 (setq code (logior (lsh code 8)
1579 (decode-char ccs code)))))
1580 ;; (char-db-update-comment)
1581 (set-buffer-modified-p nil)
1582 (view-mode the-buf (lambda (buf)
1583 (set-window-configuration
1584 what-character-original-window-configuration)
1586 (goto-char (point-min)))
1588 (set-window-configuration
1589 what-character-original-window-configuration)
1590 (signal (car err) (cdr err)))))))
1596 (provide 'char-db-util)
1598 ;;; char-db-util.el ends here