1 ;;; char-db-util.el --- Character Database utility -*- coding: utf-8-er; -*-
3 ;; Copyright (C) 1998,1999,2000,2001,2002,2003,2004,2005,2006,2007,
4 ;; 2008,2009,2010,2011,2012,2013,2014,2015,2016 MORIOKA Tomohiko.
6 ;; Author: MORIOKA Tomohiko <tomo@kanji.zinbun.kyoto-u.ac.jp>
7 ;; Keywords: CHISE, Character Database, ISO/IEC 10646, UCS, Unicode, MULE.
9 ;; This file is part of XEmacs CHISE.
11 ;; XEmacs CHISE is free software; you can redistribute it and/or
12 ;; modify it under the terms of the GNU General Public License as
13 ;; published by the Free Software Foundation; either version 2, or (at
14 ;; your option) any later version.
16 ;; XEmacs CHISE is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 ;; General Public License for more details.
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with XEmacs CHISE; see the file COPYING. If not, write to
23 ;; the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
24 ;; Boston, MA 02111-1307, USA.
29 (require 'ideograph-subr)
31 (defconst unidata-normative-category-alist
32 '(("Lu" letter uppercase)
33 ("Ll" letter lowercase)
34 ("Lt" letter titlecase)
35 ("Mn" mark non-spacing)
36 ("Mc" mark spacing-combining)
38 ("Nd" number decimal-digit)
41 ("Zs" separator space)
43 ("Zp" separator paragraph)
46 ("Cs" other surrogate)
47 ("Co" other private-use)
48 ("Cn" other not-assigned)))
50 (defconst unidata-informative-category-alist
51 '(("Lm" letter modifier)
53 ("Pc" punctuation connector)
54 ("Pd" punctuation dash)
55 ("Ps" punctuation open)
56 ("Pe" punctuation close)
57 ("Pi" punctuation initial-quote)
58 ("Pf" punctuation final-quote)
59 ("Po" punctuation other)
61 ("Sc" symbol currency)
62 ("Sk" symbol modifier)
66 (defconst shuowen-radicals
67 [?一 ?上 ?示 ?三 ?王 ?玉 ?玨 ?气 ?士 ?丨 ; 010
68 ?屮 ?艸 ?蓐 ?茻 ?小 ?八 ?釆 ?半 ?牛 ?犛 ; 020
69 ?告 ?口 ?凵 ?吅 ?哭 ?走 ?止 ?癶 ?步 ?此 ; 030
70 ?正 ?是 ?辵 ?彳 ?廴 ?㢟 ?行 ?齒 ?牙 ?足 ; 040
71 ?疋 ?品 ?龠 ?冊 ?㗊 ?舌 ?干 ?谷 ?只 ?㕯 ; 050
72 ?句 ?丩 ?古 ?十 ?卅 ?言 ?誩 ?音 ?䇂 ?丵 ; 060
73 ?菐 ?𠬞 ?𠬜 ?共 ?異 ?舁 ?𦥑 ?䢅 ?爨 ?革 ; 070
74 ?鬲 ?䰜 ?爪 ?𠃨 ?鬥 ?又 ?𠂇 ?㕜 ?支 ?𦘒 ; 080
75 ?聿 ?畫 ?隶 ?臤 ?臣 ?殳 ?殺 ?𠘧 ?寸 ?皮 ; 090
76 ?㼱 ?攴 ?敎 ?卜 ?用 ?爻 ?㸚 ?𥄎 ?目 ?䀠 ; 100
77 ?眉 ?盾 ?自 ?白 ?鼻 ?皕 ?習 ?羽 ?隹 ?奞 ; 110
78 ?萑 ?𦫳 ?苜 ?羊 ?羴 ?瞿 ?雔 ?雥 ?鳥 ?烏 ; 120
79 ?𠦒 ?冓 ?幺 ?𢆶 ?叀 ?玄 ?予 ?放 ?𠬪 ?𣦼 ; 130
80 ?歺 ?死 ?冎 ?骨 ?肉 ?筋 ?刀 ?刃 ?㓞 ?丰 ; 140
81 ?耒 ?𧢲 ?竹 ?箕 ?丌 ?左 ?工 ?㠭 ?巫 ?甘 ; 150
82 ?曰 ?乃 ?丂 ?可 ?兮 ?号 ?亏 ?旨 ?喜 ?壴 ; 160
83 ; ?旨 ?曰 ?乃 ?丂 ?可 ?兮 ?号 ?亏 ?喜 ?壴 ; 160
84 ?鼓 ?豈 ?豆 ?豊 ?豐 ?䖒 ?虍 ?虎 ?虤 ?皿 ; 170
85 ?𠙴 ?去 ?血 ?丶 ?丹 ?青 ?井 ?皀 ?鬯 ?食 ; 180
86 ?亼 ?會 ?倉 ?入 ?缶 ?矢 ?高 ?冂 ?𩫏 ?京 ; 190
87 ?亯 ?𣆪 ?畗 ?㐭 ?嗇 ?來 ?麥 ?夊 ?舛 ?䑞 ; 200
88 ?韋 ?弟 ?夂 ?久 ?桀 ?木 ?東 ?林 ?才 ?叒 ; 210
89 ?之 ?帀 ?出 ?𣎵 ?生 ?乇 ?𠂹 ?𠌶 ?華 ?𥝌 ; 220
90 ?稽 ?巢 ?桼 ?束 ?㯻 ?囗 ?員 ?貝 ?邑 ?𨛜 ; 230
91 ?日 ?旦 ?倝 ?㫃 ?冥 ?晶 ?月 ?有 ?明 ?囧 ; 240
92 ?夕 ?多 ?毌 ?𢎘 ?𣐺 ?卣 ?齊 ?朿 ?片 ?鼎 ; 250
93 ?克 ?彔 ?禾 ?秝 ?黍 ?香 ?米 ?毇 ?臼 ?凶 ; 260
94 ?𣎳 ?林 ?麻 ?尗 ?耑 ?韭 ?瓜 ?瓠 ?宀 ?宮 ; 270
95 ?呂 ?穴 ?㝱 ?𤕫 ?冖 ?𠔼 ?冃 ?㒳 ?网 ?襾 ; 280
96 ?巾 ?巿 ?帛 ?白 ?㡀 ?黹 ?人 ?𠤎 ?匕 ?从 ; 290
97 ?比 ?北 ?丘 ?㐺 ?𡈼 ?重 ?臥 ?身 ?㐆 ?衣 ; 300
98 ?裘 ?老 ?毛 ?毳 ?尸 ?尺 ?尾 ?履 ?舟 ?方 ; 310
99 ?儿 ?兄 ?兂 ?皃 ?𠑹 ?先 ?秃 ?見 ?覞 ?欠 ; 320
100 ?㱃 ?㳄 ?旡 ?頁 ?𦣻 ?面 ?丏 ?首 ?𥄉 ?須 ; 330
101 ?彡 ?彣 ?文 ?髟 ?后 ?司 ?卮 ?卩 ?印 ?色 ; 340
102 ?𠨍 ?辟 ?勹 ?包 ?茍 ?鬼 ?甶 ?厶 ?嵬 ?山 ; 350
103 ?屾 ?屵 ?广 ?厂 ?丸 ?危 ?石 ?長 ?勿 ?冄 ; 360
104 ?而 ?豕 ?㣇 ?彑 ?豚 ?豸 ?𤉡 ?易 ?象 ?馬 ; 370
105 ?𢊁 ?鹿 ?麤 ?㲋 ?兔 ?萈 ?犬 ?㹜 ?鼠 ?能 ; 380
106 ?熊 ?火 ?炎 ?黑 ?囪 ?焱 ?炙 ?赤 ?大 ?亦 ; 390
109 (defun shuowen-radical (number)
110 (aref shuowen-radicals (1- number)))
112 (defvar char-db-file-coding-system 'utf-8-mcs-er)
114 (defvar char-db-ignored-attributes '(ideographic-products))
116 (defvar char-db-coded-charset-priority-list
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
343 ;;; @ char-db formatters
346 (defun char-db-make-char-spec (char)
348 (cond ((characterp char)
349 (cond ((and (setq ret (encode-char char '=ucs 'defined-only))
350 (not (and (<= #xE000 ret)(<= ret #xF8FF))))
351 (setq char-spec (list (cons '=ucs ret)))
352 (cond ((setq ret (get-char-attribute char 'name))
353 (setq char-spec (cons (cons 'name ret) char-spec))
355 ((setq ret (get-char-attribute char 'name*))
356 (setq char-spec (cons (cons 'name* ret) char-spec))
359 ((encode-char char '=mj 'defined-only)
361 (dolist (ccs (charset-list))
362 (if (and (or (eq ccs '=mj)
363 ;; (eq (charset-property ccs 'iso-ir) 177)
364 (string-match "=ucs@" (symbol-name ccs))
366 (setq ccs (charset-name ccs))
367 (null (assq ccs char-spec))
368 (setq ret (encode-char char ccs 'defined-only)))
369 (setq char-spec (cons (cons ccs ret) char-spec))))
371 ((encode-char char '==mj 'defined-only)
373 (dolist (ccs (charset-list))
374 (if (and (or (eq ccs '==mj)
375 ;; (eq (charset-property ccs 'iso-ir) 177)
376 (string-match "=ucs@" (symbol-name ccs))
378 (setq ccs (charset-name ccs))
379 (null (assq ccs char-spec))
380 (setq ret (encode-char char ccs 'defined-only)))
381 (setq char-spec (cons (cons ccs ret) char-spec))))
383 ((encode-char char '=adobe-japan1 'defined-only)
385 (dolist (ccs (charset-list))
386 (if (and (or (memq ccs
395 ;; (eq (charset-property ccs 'iso-ir) 177)
396 (string-match "=ucs@" (symbol-name ccs))
398 (setq ccs (charset-name ccs))
399 (null (assq ccs char-spec))
400 (setq ret (encode-char char ccs 'defined-only)))
401 (setq char-spec (cons (cons ccs ret) char-spec))))
403 ((encode-char char '==adobe-japan1 'defined-only)
405 (dolist (ccs (charset-list))
406 (if (and (or (memq ccs
415 ;; (eq (charset-property ccs 'iso-ir) 177)
416 (string-match "=ucs@" (symbol-name ccs))
418 (setq ccs (charset-name ccs))
419 (null (assq ccs char-spec))
420 (setq ret (encode-char char ccs 'defined-only)))
421 (setq char-spec (cons (cons ccs ret) char-spec))))
425 (let ((rest char-db-coded-charset-priority-list)
428 (setq ccs (charset-name
429 (find-charset (car rest))))
431 (encode-char char ccs
433 (throw 'tag (cons ccs ret)))
434 (setq rest (cdr rest))))))
435 (setq char-spec (list ret))
436 (dolist (ccs (delq (car ret) (charset-list)))
437 (if (and (or (charset-iso-final-char ccs)
444 (eq (charset-property ccs 'iso-ir) 177)
445 ;; (string-match "=ucs@" (symbol-name ccs))
447 (setq ccs (charset-name ccs))
448 (null (assq ccs char-spec))
449 (setq ret (encode-char char ccs 'defined-only)))
450 (setq char-spec (cons (cons ccs ret) char-spec))))
452 (setq char-spec (split-char char)))
453 (cond ((setq ret (get-char-attribute char 'name))
454 (setq char-spec (cons (cons 'name ret) char-spec))
456 ((setq ret (get-char-attribute char 'name*))
457 (setq char-spec (cons (cons 'name* ret) char-spec))
460 ((setq ret (get-char-attribute
461 char 'ideographic-combination))
463 (cons (cons 'ideographic-combination ret)
470 (defun char-db-insert-char-spec (char &optional readable column
473 (setq column (current-column)))
474 (let (char-spec temp-char)
475 (setq char-spec (char-db-make-char-spec char))
476 (unless (or (characterp char) ; char
478 (setq char (find-char char-spec))
480 ;; define temporary character
481 ;; Current implementation is dirty.
482 (setq temp-char (define-char (cons '(ideograph-daikanwa . 0)
484 (remove-char-attribute temp-char 'ideograph-daikanwa)
485 (setq char temp-char))
486 (insert-char-attributes char
488 (union (mapcar #'car char-spec)
492 ;; undefine temporary character
493 ;; Current implementation is dirty.
494 (setq char-spec (char-attribute-alist temp-char))
496 (remove-char-attribute temp-char (car (car char-spec)))
497 (setq char-spec (cdr char-spec))))))
499 (defun char-db-insert-alist (alist &optional readable column)
501 (setq column (current-column)))
503 (concat "\n" (make-string (1+ column) ?\ )))
507 lbs cell rest separator)
510 (setq name (car (car alist))
511 value (cdr (car alist)))
512 (cond ((eq name 'char)
514 (if (setq ret (condition-case nil
522 (setq key (car (car value)))
523 ;; (if (find-charset key)
524 ;; (setq cal (cons key cal))
525 (setq al (cons key al))
527 (setq value (cdr value)))
528 (insert-char-attributes ret
532 (insert (prin1-to-string value)))
534 (insert line-breaking))
536 (insert (format "(%-18s " name))
537 (setq lbs (concat "\n" (make-string (current-column) ?\ )))
539 (setq cell (car value))
540 (if (and (consp cell)
542 (setq ret (condition-case nil
552 (setq key (car (car rest)))
553 ;; (if (find-charset key)
554 ;; (setq cal (cons key cal))
555 (setq al (cons key al))
557 (setq rest (cdr rest)))
560 (insert-char-attributes ret
564 (setq separator lbs))
567 (insert (prin1-to-string cell))
568 (setq separator " "))
569 (setq value (cdr value)))
571 (insert line-breaking))
573 (insert (format "(%-18s . %S)%s"
576 (setq alist (cdr alist))))
579 (defun char-db-insert-char-reference (plist &optional readable column)
581 (setq column (current-column)))
583 (concat "\n" (make-string (1+ column) ?\ )))
588 (setq name (pop plist))
589 (setq value (pop plist))
590 (cond ((eq name :char)
593 (cond ((numberp value)
594 (setq value (decode-char '=ucs value)))
596 ;; (setq value (or (find-char value)
599 (char-db-insert-char-spec value readable)
600 (insert line-breaking)
603 (insert (format "%s%s\t%d ; %c%s"
606 (ideographic-radical value)
610 (insert (format "%s%s\t%S" separator name value))
611 (setq separator line-breaking)))
615 (defun char-db-decode-isolated-char (ccs code-point)
618 (cond ((eq ccs 'arabic-iso8859-6)
619 (decode-char ccs code-point))
621 ;; (decode-builtin-char '==gt code-point))
622 ((and (memq ccs '(=gt-pj-1
633 (setq ret (decode-char ccs code-point))
634 (setq ret (encode-char ret '=gt 'defined-only)))
635 (decode-builtin-char '=gt ret))
637 (decode-builtin-char ccs code-point))))
639 (or (decode-char ccs code-point)
640 (define-char (list (cons ccs code-point)))))
641 ((and (<= 0 (char-int ret))
642 (<= (char-int ret) #x1F))
643 (decode-char '=ucs (+ #x2400 (char-int ret))))
644 ((= (char-int ret) #x7F)
648 (defvar char-db-convert-obsolete-format t)
650 (defun char-db-insert-ccs-feature (name value line-breaking)
656 ((memq name '(=>iwds-1
659 =shinjigen@1ed ==shinjigen@1ed
660 =shinjigen@rev ==shinjigen@rev
661 =shinjigen/+p@rev ==shinjigen/+p@rev
662 ===daikanwa/ho ==daikanwa/ho
663 =daikanwa/ho =>>daikanwa/ho =>daikanwa/ho))
664 "(%-18s . %04d)\t; %c")
665 ((eq name '=shinjigen@1ed/24pr)
666 "(%-18s . %04d)\t; %c")
670 ==daikanwa =daikanwa =>>daikanwa =>daikanwa
671 =daikanwa@rev1 =daikanwa@rev2
672 =daikanwa/+p ==daikanwa/+p ===daikanwa/+p
674 =daikanwa/+2p =>>daikanwa/+2p
679 =adobe-japan1-0 ==adobe-japan1-0 ===adobe-japan1-0
680 =adobe-japan1-1 ==adobe-japan1-1 ===adobe-japan1-1
681 =adobe-japan1-2 ==adobe-japan1-2 ===adobe-japan1-2
682 =adobe-japan1-3 ==adobe-japan1-3 ===adobe-japan1-3
683 =adobe-japan1-4 ==adobe-japan1-4 ===adobe-japan1-4
684 =adobe-japan1-5 ==adobe-japan1-5 ===adobe-japan1-5
685 =adobe-japan1-6 ==adobe-japan1-6 ===adobe-japan1-6
686 =>>adobe-japan1-0 =+>adobe-japan1-0
687 =>>adobe-japan1-1 =+>adobe-japan1-1
688 =>>adobe-japan1-2 =+>adobe-japan1-2
689 =>>adobe-japan1-3 =+>adobe-japan1-3
690 =>>adobe-japan1-4 =+>adobe-japan1-4
691 =>>adobe-japan1-5 =+>adobe-japan1-5
692 =>>adobe-japan1-6 =+>adobe-japan1-6
693 =>cbeta =cbeta =>>cbeta ==cbeta ===cbeta
694 =zinbun-oracle =>zinbun-oracle
695 ===hng-jou ===hng-keg ===hng-dng ===hng-mam
696 ===hng-drt ===hng-kgk ===hng-myz ===hng-kda
697 ===hng-khi ===hng-khm ===hng-hok ===hng-kyd ===hng-sok
698 ===hng-yhk ===hng-kak ===hng-kar ===hng-kae
699 ===hng-sys ===hng-tsu ===hng-tzj
700 ===hng-hos ===hng-nak ===hng-jhk
701 ===hng-hod ===hng-gok ===hng-ink ===hng-nto
702 ===hng-nkm ===hng-k24 ===hng-nkk
703 ===hng-kcc ===hng-kcj ===hng-kbk ===hng-sik
704 ===hng-skk ===hng-kyu ===hng-ksk ===hng-wan
705 ===hng-okd ===hng-wad ===hng-kmi
706 ===hng-zkd ===hng-doh ===hng-jyu
707 ===hng-tzs ===hng-kss ===hng-kyo
709 ;; (string-match "^=adobe-" (symbol-name name))
711 "(%-18s . %05d)\t; %c")
712 ((memq name '(=hanyo-denshi/ks
713 ==hanyo-denshi/ks ===hanyo-denshi/ks
716 =mj ==mj ===mj =>>mj =>mj
718 "(%-18s . %06d)\t; %c")
719 ((memq name '(=hanyo-denshi/tk))
720 "(%-18s . %08d)\t; %c")
721 ((>= (charset-dimension name) 2)
722 "(%-18s . #x%04X)\t; %c")
724 "(%-18s . #x%02X)\t; %c"))
726 (if (= (charset-iso-graphic-plane name) 1)
728 (cond ((= (charset-dimension name) 1)
730 ((= (charset-dimension name) 2)
732 ((= (charset-dimension name) 3)
736 (char-db-decode-isolated-char name value)))
737 (if (and (= (charset-chars name) 94)
738 (= (charset-dimension name) 2))
739 (insert (format " [%02d-%02d]"
740 (- (lsh value -8) 32)
741 (- (logand value 255) 32))))
744 (insert (format "(%-18s . %s)" name value))
746 (insert line-breaking))
748 (defun char-db-insert-relation-feature (char name value line-breaking
750 (insert (format "(%-18s%s " name line-breaking))
751 (let ((lbs (concat "\n" (make-string (current-column) ?\ )))
752 separator cell sources required-features
755 (setq cell (car value))
757 (setq cell (decode-char '=ucs cell)))
759 ((eq name '->subsumptive)
760 (when (or (not (some (lambda (atr)
761 (get-char-attribute cell atr))
762 char-db-ignored-attributes))
764 (encode-char cell ccs 'defined-only))
768 (let ((char-db-ignored-attributes
770 char-db-ignored-attributes)))
771 (insert-char-attributes cell readable nil nil 'for-sub-node))
772 (setq separator lbs))
777 char (intern (format "%s*sources" name))))
778 (setq required-features nil)
779 (dolist (source sources)
783 shinjigen shinjigen@1ed shinjigen@rev))
784 (setq required-features
785 (union required-features
797 =shinjigen/+p@rev))))
799 (setq required-features
800 (union required-features
805 ((find-charset (setq ret (intern (format "=%s" source))))
806 (setq required-features
807 (cons ret required-features)))
808 (t (setq required-features
809 (cons source required-features)))))
810 (cond ((string-match "@JP" (symbol-name name))
811 (setq required-features
812 (union required-features
820 ((string-match "@CN" (symbol-name name))
821 (setq required-features
822 (union required-features
829 (insert (format "%S" cell))
830 (char-db-insert-char-spec cell readable
833 (setq separator lbs))
837 (if (consp (car cell))
838 (char-db-insert-char-spec cell readable)
839 (char-db-insert-char-reference cell readable))
840 (setq separator lbs))
844 (insert (prin1-to-string cell))
845 (setq separator " ")))
846 (setq value (cdr value)))
848 (insert line-breaking)))
850 (defun insert-char-attributes (char &optional readable attributes column
853 (setq column (current-column)))
854 (let (name value ; has-long-ccs-name
858 (concat "\n" (make-string (1+ column) ?\ )))
859 lbs cell separator ret
861 dest-ccss ; sources required-features
866 (if (consp attributes)
868 (dolist (name attributes)
869 (unless (memq name char-db-ignored-attributes)
870 (if (find-charset name)
874 (dolist (name (char-attribute-list))
875 (unless (memq name char-db-ignored-attributes)
876 (if (find-charset name)
880 #'char-attribute-name<)))
882 (when (memq '<-subsumptive attributes)
883 (when (or readable (not for-sub-node))
884 (when (setq value (get-char-attribute char '<-subsumptive))
885 (char-db-insert-relation-feature char '<-subsumptive value
888 (setq attributes (delq '<-subsumptive attributes)))
889 (when (and (memq '<-denotational attributes)
890 (setq value (get-char-attribute char '<-denotational)))
891 (char-db-insert-relation-feature char '<-denotational value
894 (setq attributes (delq '<-denotational attributes)))
895 (when (and (memq '<-denotational@component attributes)
896 (setq value (get-char-attribute char '<-denotational@component)))
897 (char-db-insert-relation-feature char '<-denotational@component value
900 (setq attributes (delq '<-denotational@component attributes)))
901 (when (and (memq 'name attributes)
902 (setq value (get-char-attribute char 'name)))
904 (if (> (+ (current-column) (length value)) 48)
907 value line-breaking))
908 (setq attributes (delq 'name attributes))
910 (when (and (memq 'name* attributes)
911 (setq value (get-char-attribute char 'name*)))
913 (if (> (+ (current-column) (length value)) 48)
916 value line-breaking))
917 (setq attributes (delq 'name* attributes))
919 (when (and (memq 'script attributes)
920 (setq value (get-char-attribute char 'script)))
921 (insert (format "(script\t\t%s)%s"
922 (mapconcat (function prin1-to-string)
925 (setq attributes (delq 'script attributes))
927 (dolist (name '(=>ucs =>ucs*))
928 (when (and (memq name attributes)
929 (setq value (get-char-attribute char name)))
930 (insert (format "(%-18s . #x%04X)\t; %c%s"
931 name value (decode-char '=ucs value)
933 (setq attributes (delq name attributes))))
934 (dolist (name '(=>ucs@gb =>ucs@big5))
935 (when (and (memq name attributes)
936 (setq value (get-char-attribute char name)))
937 (insert (format "(%-18s . #x%04X)\t; %c%s"
942 (symbol-name name) 2)))
945 (setq attributes (delq name attributes))
947 ;; (dolist (name '(=>daikanwa))
948 ;; (when (and (memq name attributes)
949 ;; (setq value (get-char-attribute char name)))
951 ;; (if (integerp value)
952 ;; (format "(%-18s . %05d)\t; %c%s"
953 ;; name value (decode-char '=daikanwa value)
955 ;; (format "(%-18s %s)\t; %c%s"
957 ;; (mapconcat (function prin1-to-string)
959 ;; (char-representative-of-daikanwa char)
961 ;; (setq attributes (delq name attributes))))
962 (when (and (memq 'general-category attributes)
963 (setq value (get-char-attribute char 'general-category)))
965 "(general-category\t%s) ; %s%s"
966 (mapconcat (lambda (cell)
969 (cond ((rassoc value unidata-normative-category-alist)
970 "Normative Category")
971 ((rassoc value unidata-informative-category-alist)
972 "Informative Category")
976 (setq attributes (delq 'general-category attributes))
978 (when (and (memq 'bidi-category attributes)
979 (setq value (get-char-attribute char 'bidi-category)))
980 (insert (format "(bidi-category\t. %S)%s"
983 (setq attributes (delq 'bidi-category attributes))
985 (unless (or (not (memq 'mirrored attributes))
986 (eq (setq value (get-char-attribute char 'mirrored 'empty))
988 (insert (format "(mirrored\t\t. %S)%s"
991 (setq attributes (delq 'mirrored attributes))
994 ((and (memq 'decimal-digit-value attributes)
995 (setq value (get-char-attribute char 'decimal-digit-value)))
996 (insert (format "(decimal-digit-value . %S)%s"
999 (setq attributes (delq 'decimal-digit-value attributes))
1000 (when (and (memq 'digit-value attributes)
1001 (setq value (get-char-attribute char 'digit-value)))
1002 (insert (format "(digit-value\t . %S)%s"
1005 (setq attributes (delq 'digit-value attributes))
1007 (when (and (memq 'numeric-value attributes)
1008 (setq value (get-char-attribute char 'numeric-value)))
1009 (insert (format "(numeric-value\t . %S)%s"
1012 (setq attributes (delq 'numeric-value attributes))
1016 (when (and (memq 'digit-value attributes)
1017 (setq value (get-char-attribute char 'digit-value)))
1018 (insert (format "(digit-value\t. %S)%s"
1021 (setq attributes (delq 'digit-value attributes))
1023 (when (and (memq 'numeric-value attributes)
1024 (setq value (get-char-attribute char 'numeric-value)))
1025 (insert (format "(numeric-value\t. %S)%s"
1028 (setq attributes (delq 'numeric-value attributes))
1030 (when (and (memq 'iso-10646-comment attributes)
1031 (setq value (get-char-attribute char 'iso-10646-comment)))
1032 (insert (format "(iso-10646-comment\t. %S)%s"
1035 (setq attributes (delq 'iso-10646-comment attributes))
1037 (when (and (memq 'morohashi-daikanwa attributes)
1038 (setq value (get-char-attribute char 'morohashi-daikanwa)))
1039 (insert (format "(morohashi-daikanwa\t%s)%s"
1040 (mapconcat (function prin1-to-string) value " ")
1042 (setq attributes (delq 'morohashi-daikanwa attributes))
1046 (when (and (memq 'ideographic-radical attributes)
1047 (setq value (get-char-attribute char 'ideographic-radical)))
1048 (setq radical value)
1049 (insert (format "(ideographic-radical . %S)\t; %c%s"
1051 (ideographic-radical radical)
1053 (setq attributes (delq 'ideographic-radical attributes))
1055 (when (and (memq 'shuowen-radical attributes)
1056 (setq value (get-char-attribute char 'shuowen-radical)))
1057 (insert (format "(shuowen-radical\t. %S)\t; %c%s"
1059 (shuowen-radical value)
1061 (setq attributes (delq 'shuowen-radical attributes))
1066 char-db-feature-domains
1068 (dolist (feature (char-attribute-list))
1069 (setq feature (symbol-name feature))
1071 "\\(radical\\|strokes\\)@\\([^@*]+\\)\\(\\*\\|$\\)"
1073 (setq domain (intern (match-string 2 feature)))
1074 (unless (memq domain dest)
1075 (setq dest (cons domain dest)))))
1076 (sort dest #'string<))))
1077 (setq key (intern (format "%s@%s" 'ideographic-radical domain)))
1078 (when (and (memq key attributes)
1079 (setq value (get-char-attribute char key)))
1080 (setq radical value)
1081 (insert (format "(%s . %S)\t; %c%s"
1084 (ideographic-radical radical)
1086 (setq attributes (delq key attributes))
1088 (setq key (intern (format "%s@%s" 'ideographic-strokes domain)))
1089 (when (and (memq key attributes)
1090 (setq value (get-char-attribute char key)))
1091 (setq strokes value)
1092 (insert (format "(%s . %S)%s"
1096 (setq attributes (delq key attributes))
1098 (setq key (intern (format "%s@%s" 'total-strokes domain)))
1099 (when (and (memq key attributes)
1100 (setq value (get-char-attribute char key)))
1101 (insert (format "(%s . %S)%s"
1105 (setq attributes (delq key attributes))
1107 (dolist (feature '(ideographic-radical
1110 (setq key (intern (format "%s@%s*sources" feature domain)))
1111 (when (and (memq key attributes)
1112 (setq value (get-char-attribute char key)))
1113 (insert (format "(%s%s" key line-breaking))
1114 (dolist (cell value)
1115 (insert (format " %s" cell)))
1117 (insert line-breaking)
1118 (setq attributes (delq key attributes))
1121 (when (and (memq 'ideographic-strokes attributes)
1122 (setq value (get-char-attribute char 'ideographic-strokes)))
1123 (setq strokes value)
1124 (insert (format "(ideographic-strokes . %S)%s"
1127 (setq attributes (delq 'ideographic-strokes attributes))
1129 (when (and (memq 'kangxi-radical attributes)
1130 (setq value (get-char-attribute char 'kangxi-radical)))
1131 (unless (eq value radical)
1132 (insert (format "(kangxi-radical\t . %S)\t; %c%s"
1134 (ideographic-radical value)
1137 (setq radical value)))
1138 (setq attributes (delq 'kangxi-radical attributes))
1140 (when (and (memq 'kangxi-strokes attributes)
1141 (setq value (get-char-attribute char 'kangxi-strokes)))
1142 (unless (eq value strokes)
1143 (insert (format "(kangxi-strokes\t . %S)%s"
1147 (setq strokes value)))
1148 (setq attributes (delq 'kangxi-strokes attributes))
1150 (when (and (memq 'japanese-radical attributes)
1151 (setq value (get-char-attribute char 'japanese-radical)))
1152 (unless (eq value radical)
1153 (insert (format "(japanese-radical\t . %S)\t; %c%s"
1155 (ideographic-radical value)
1158 (setq radical value)))
1159 (setq attributes (delq 'japanese-radical attributes))
1161 (when (and (memq 'japanese-strokes attributes)
1162 (setq value (get-char-attribute char 'japanese-strokes)))
1163 (unless (eq value strokes)
1164 (insert (format "(japanese-strokes\t . %S)%s"
1168 (setq strokes value)))
1169 (setq attributes (delq 'japanese-strokes attributes))
1171 (when (and (memq 'cns-radical attributes)
1172 (setq value (get-char-attribute char 'cns-radical)))
1173 (insert (format "(cns-radical\t . %S)\t; %c%s"
1175 (ideographic-radical value)
1177 (setq attributes (delq 'cns-radical attributes))
1179 (when (and (memq 'cns-strokes attributes)
1180 (setq value (get-char-attribute char 'cns-strokes)))
1181 (unless (eq value strokes)
1182 (insert (format "(cns-strokes\t . %S)%s"
1186 (setq strokes value)))
1187 (setq attributes (delq 'cns-strokes attributes))
1189 ;; (when (and (memq 'shinjigen-1-radical attributes)
1190 ;; (setq value (get-char-attribute char 'shinjigen-1-radical)))
1191 ;; (unless (eq value radical)
1192 ;; (insert (format "(shinjigen-1-radical . %S)\t; %c%s"
1194 ;; (ideographic-radical value)
1197 ;; (setq radical value)))
1198 ;; (setq attributes (delq 'shinjigen-1-radical attributes))
1200 (when (and (memq 'ideographic- attributes)
1201 (setq value (get-char-attribute char 'ideographic-)))
1202 (insert "(ideographic- ")
1203 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1205 (while (consp value)
1206 (setq cell (car value))
1208 (setq cell (decode-char '=ucs cell)))
1209 (cond ((characterp cell)
1213 (insert (format "%S" cell))
1214 (char-db-insert-char-spec cell readable))
1215 (setq separator lbs))
1219 (if (consp (car cell))
1220 (char-db-insert-char-spec cell readable)
1221 (char-db-insert-char-reference cell readable))
1222 (setq separator lbs))
1226 (insert (prin1-to-string cell))
1227 (setq separator " ")))
1228 (setq value (cdr value)))
1230 (insert line-breaking)
1231 (setq attributes (delq 'ideographic- attributes)))
1232 (when (and (memq 'total-strokes attributes)
1233 (setq value (get-char-attribute char 'total-strokes)))
1234 (insert (format "(total-strokes . %S)%s"
1237 (setq attributes (delq 'total-strokes attributes))
1239 (when (and (memq '->ideograph attributes)
1240 (setq value (get-char-attribute char '->ideograph)))
1241 (insert (format "(->ideograph\t%s)%s"
1242 (mapconcat (lambda (code)
1243 (cond ((symbolp code)
1246 (format "#x%04X" code))
1249 line-breaking code))))
1252 (setq attributes (delq '->ideograph attributes))
1254 ;; (when (and (memq '->decomposition attributes)
1255 ;; (setq value (get-char-attribute char '->decomposition)))
1256 ;; (insert (format "(->decomposition\t%s)%s"
1257 ;; (mapconcat (lambda (code)
1258 ;; (cond ((symbolp code)
1259 ;; (symbol-name code))
1260 ;; ((characterp code)
1262 ;; (format "%S" code)
1267 ;; (format "#x%04X" code))
1269 ;; (format "%s%S" line-breaking code))))
1272 ;; (setq attributes (delq '->decomposition attributes))
1274 (if (equal (get-char-attribute char '->titlecase)
1275 (get-char-attribute char '->uppercase))
1276 (setq attributes (delq '->titlecase attributes)))
1277 (when (and (memq '->mojikyo attributes)
1278 (setq value (get-char-attribute char '->mojikyo)))
1279 (insert (format "(->mojikyo\t\t. %06d)\t; %c%s"
1280 value (decode-char 'mojikyo value)
1282 (setq attributes (delq '->mojikyo attributes))
1284 (when (and (memq 'hanyu-dazidian-vol attributes)
1285 (setq value (get-char-attribute char 'hanyu-dazidian-vol)))
1286 (insert (format "(hanyu-dazidian-vol . %d)%s"
1287 value line-breaking))
1288 (setq attributes (delq 'hanyu-dazidian-vol attributes))
1290 (when (and (memq 'hanyu-dazidian-page attributes)
1291 (setq value (get-char-attribute char 'hanyu-dazidian-page)))
1292 (insert (format "(hanyu-dazidian-page . %d)%s"
1293 value line-breaking))
1294 (setq attributes (delq 'hanyu-dazidian-page attributes))
1296 (when (and (memq 'hanyu-dazidian-char attributes)
1297 (setq value (get-char-attribute char 'hanyu-dazidian-char)))
1298 (insert (format "(hanyu-dazidian-char . %d)%s"
1299 value line-breaking))
1300 (setq attributes (delq 'hanyu-dazidian-char attributes))
1303 (dolist (ignored '(composition
1304 ->denotational <-subsumptive ->ucs-unified
1305 ->ideographic-component-forms))
1306 (setq attributes (delq ignored attributes))))
1308 (setq name (car attributes))
1309 (unless (eq (setq value (get-char-attribute char name 'value-is-empty))
1311 (cond ((setq ret (find-charset name))
1312 (setq name (charset-name ret))
1313 (when (not (memq name dest-ccss))
1314 (setq dest-ccss (cons name dest-ccss))
1315 (char-db-insert-ccs-feature name value line-breaking))
1317 ((string-match "^=>ucs@" (symbol-name name))
1318 (insert (format "(%-18s . #x%04X)\t; %c%s"
1319 name value (decode-char '=ucs value)
1322 ((eq name 'jisx0208-1978/4X)
1323 (insert (format "(%-18s . #x%04X)%s"
1329 (not (eq name '->subsumptive))
1330 (not (eq name '->uppercase))
1331 (not (eq name '->lowercase))
1332 (not (eq name '->titlecase))
1333 (not (eq name '->canonical))
1334 (not (eq name '->Bopomofo))
1335 (not (eq name '->mistakable))
1336 (not (eq name '->ideographic-variants))
1337 (null (get-char-attribute
1338 char (intern (format "%s*sources" name))))
1339 (not (string-match "\\*sources$" (symbol-name name)))
1340 (null (get-char-attribute
1341 char (intern (format "%s*note" name))))
1342 (not (string-match "\\*note$" (symbol-name name)))
1343 (or (eq name '<-identical)
1344 (eq name '<-uppercase)
1345 (eq name '<-lowercase)
1346 (eq name '<-titlecase)
1347 (eq name '<-canonical)
1348 (eq name '<-ideographic-variants)
1349 ;; (eq name '<-synonyms)
1350 (string-match "^<-synonyms" (symbol-name name))
1351 (eq name '<-mistakable)
1352 (when (string-match "^->" (symbol-name name))
1354 ((string-match "^->fullwidth" (symbol-name name))
1355 (not (and (consp value)
1356 (characterp (car value))
1358 (car value) '=ucs 'defined-only)))
1363 ((or (eq name 'ideographic-structure)
1364 (eq name 'ideographic-combination)
1365 (eq name 'ideographic-)
1366 (eq name '=decomposition)
1367 (char-feature-base-name= '=decomposition name)
1368 (char-feature-base-name= '=>decomposition name)
1369 ;; (string-match "^=>*decomposition\\(@[^*]+\\)?$"
1370 ;; (symbol-name name))
1371 (string-match "^\\(->\\|<-\\)[^*]*$" (symbol-name name))
1372 (string-match "^\\(->\\|<-\\)[^*]*\\*sources$"
1375 (char-db-insert-relation-feature char name value
1378 ((memq name '(ideograph=
1379 original-ideograph-of
1380 ancient-ideograph-of
1383 ;; simplified-ideograph-of
1384 ideographic-variants
1385 ;; ideographic-different-form-of
1387 (insert (format "(%-18s%s " name line-breaking))
1388 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1390 (while (consp value)
1391 (setq cell (car value))
1392 (if (and (consp cell)
1397 (char-db-insert-alist cell readable)
1398 (setq separator lbs))
1401 (insert (prin1-to-string cell))
1402 (setq separator " "))
1403 (setq value (cdr value)))
1405 (insert line-breaking))
1407 (insert (format "(%-18s " name))
1408 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1410 (while (consp value)
1411 (setq cell (car value))
1412 (if (and (consp cell)
1414 (setq ret (condition-case nil
1422 (setq key (car (car rest)))
1423 (if (find-charset key)
1424 (setq cal (cons key cal))
1425 (setq al (cons key al)))
1426 (setq rest (cdr rest)))
1429 (insert-char-attributes ret
1433 (setq separator lbs))
1434 (setq ret (prin1-to-string cell))
1436 (if (< (+ (current-column)
1443 (setq separator " "))
1444 (setq value (cdr value)))
1446 (insert line-breaking))
1448 (insert (format "(%-18s" name))
1449 (setq ret (prin1-to-string value))
1450 (unless (< (+ (current-column)
1454 (insert line-breaking))
1455 (insert " . " ret ")" line-breaking)
1456 ;; (insert (format "(%-18s . %S)%s"
1461 (setq attributes (cdr attributes)))
1464 (defun insert-char-data (char &optional readable
1467 (narrow-to-region (point)(point))
1468 (insert "(define-char
1470 (insert-char-attributes char readable attributes)
1472 (goto-char (point-min))
1473 (while (re-search-forward "[ \t]+$" nil t)
1476 (goto-char (point-min))
1477 (while (re-search-forward "[ \t][ \t][ \t]*" nil t)
1478 (let ((column (current-column))
1479 (indent-tabs-mode t))
1480 (delete-region (match-beginning 0) (point))
1481 (indent-to column)))
1482 (goto-char (point-max))
1483 ;; (tabify (point-min)(point-max))
1486 (defun insert-char-data-with-variant (char &optional printable
1488 script excluded-script)
1489 (insert-char-data char printable)
1490 (let ((variants (char-variants char))
1493 (setq variants (sort variants #'<))
1494 (setq rest variants)
1495 (setq variants (cons char variants))
1497 (setq variant (car rest))
1498 (unless (get-char-attribute variant '<-subsumptive)
1499 (if (and (or (null script)
1500 (null (setq vs (get-char-attribute variant 'script)))
1502 (or (null excluded-script)
1503 (null (setq vs (get-char-attribute variant 'script)))
1504 (not (memq excluded-script vs))))
1505 (unless (and no-ucs-unified (get-char-attribute variant '=ucs))
1506 (insert-char-data variant printable)
1507 (if (setq ret (char-variants variant))
1509 (or (memq (car ret) variants)
1510 ;; (get-char-attribute (car ret) '<-subsumptive)
1511 (setq rest (nconc rest (list (car ret)))))
1512 (setq ret (cdr ret)))))))
1513 (setq rest (cdr rest)))))
1515 (defun insert-char-range-data (min max &optional script excluded-script)
1518 (while (<= code max)
1519 (setq char (decode-char '=ucs code))
1520 (if (encode-char char '=ucs 'defined-only)
1521 (insert-char-data-with-variant char nil 'no-ucs-unified
1522 script excluded-script))
1523 (setq code (1+ code)))))
1525 (defun write-char-range-data-to-file (min max file
1526 &optional script excluded-script)
1527 (let ((coding-system-for-write char-db-file-coding-system))
1529 (insert (format ";; -*- coding: %s -*-\n"
1530 char-db-file-coding-system))
1531 (insert-char-range-data min max script excluded-script)
1532 (write-region (point-min)(point-max) file))))
1534 (defvar what-character-original-window-configuration)
1537 (defun what-char-definition (char)
1538 (interactive (list (char-after)))
1539 (let ((buf (get-buffer-create "*Character Description*"))
1540 (the-buf (current-buffer))
1541 (win-conf (current-window-configuration)))
1543 (make-local-variable 'what-character-original-window-configuration)
1544 (setq what-character-original-window-configuration win-conf)
1545 (setq buffer-read-only nil)
1549 (insert-char-data-with-variant char 'printable)
1550 (unless (char-attribute-alist char)
1551 (insert (format ";; = %c\n"
1552 (let* ((rest (split-char char))
1556 (setq code (logior (lsh code 8)
1558 (decode-char ccs code)))))
1559 ;; (char-db-update-comment)
1560 (set-buffer-modified-p nil)
1561 (view-mode the-buf (lambda (buf)
1562 (set-window-configuration
1563 what-character-original-window-configuration)
1565 (goto-char (point-min)))
1567 (set-window-configuration
1568 what-character-original-window-configuration)
1569 (signal (car err) (cdr err)))))))
1575 (provide 'char-db-util)
1577 ;;; char-db-util.el ends here