1 ;;; char-db-util.el --- Character Database utility -*- coding: utf-8-er; -*-
3 ;; Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006,
4 ;; 2007, 2008, 2009 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.
30 (defconst unidata-normative-category-alist
31 '(("Lu" letter uppercase)
32 ("Ll" letter lowercase)
33 ("Lt" letter titlecase)
34 ("Mn" mark non-spacing)
35 ("Mc" mark spacing-combining)
37 ("Nd" number decimal-digit)
40 ("Zs" separator space)
42 ("Zp" separator paragraph)
45 ("Cs" other surrogate)
46 ("Co" other private-use)
47 ("Cn" other not-assigned)))
49 (defconst unidata-informative-category-alist
50 '(("Lm" letter modifier)
52 ("Pc" punctuation connector)
53 ("Pd" punctuation dash)
54 ("Ps" punctuation open)
55 ("Pe" punctuation close)
56 ("Pi" punctuation initial-quote)
57 ("Pf" punctuation final-quote)
58 ("Po" punctuation other)
60 ("Sc" symbol currency)
61 ("Sk" symbol modifier)
65 (defconst ideographic-radicals
66 (let ((v (make-vector 215 nil))
69 (aset v i (decode-char '=ucs (+ #x2EFF i)))
73 (defun ideographic-radical (number)
74 (aref ideographic-radicals number))
76 (defconst shuowen-radicals
77 [?一 ?上 ?示 ?三 ?王 ?玉 ?玨 ?气 ?士 ?丨 ; 010
78 ?屮 ?艸 ?蓐 ?茻 ?小 ?八 ?釆 ?半 ?牛 ?犛 ; 020
79 ?告 ?口 ?凵 ?吅 ?哭 ?走 ?止 ?癶 ?步 ?此 ; 030
80 ?正 ?是 ?辵 ?彳 ?廴 ?㢟 ?行 ?齒 ?牙 ?足 ; 040
81 ?疋 ?品 ?龠 ?冊 ?㗊 ?舌 ?干 ?谷 ?只 ?㕯 ; 050
82 ?句 ?丩 ?古 ?十 ?卅 ?言 ?誩 ?音 ?䇂 ?丵 ; 060
83 ?菐 ?𠬞 ?廾 ?共 ?異 ?舁 ?𦥑 ?䢅 ?爨 ?革 ; 070
84 ?鬲 ?䰜 ?爪 ?𠃨 ?鬥 ?又 ?𠂇 ?㕜 ?支 ?𦘒 ; 080
85 ?聿 ?畫 ?隶 ?臤 ?臣 ?殳 ?殺 ?𠘧 ?寸 ?皮 ; 090
86 ?㼱 ?攴 ?敎 ?卜 ?用 ?爻 ?㸚 ?𥄎 ?目 ?䀠 ; 100
87 ?眉 ?盾 ?自 ?白 ?鼻 ?皕 ?習 ?羽 ?隹 ?奞 ; 110
88 ?萑 ?𦫳 ?苜 ?羊 ?羴 ?瞿 ?雔 ?雥 ?鳥 ?烏 ; 120
89 ?𠦒 ?冓 ?幺 ?𢆶 ?叀 ?玄 ?予 ?放 ?𠬪 ?𣦼 ; 130
90 ?歺 ?死 ?冎 ?骨 ?肉 ?筋 ?刀 ?刃 ?㓞 ?丰 ; 140
91 ?耒 ?𧢲 ?竹 ?箕 ?丌 ?左 ?工 ?㠭 ?巫 ?甘 ; 150
92 ?曰 ?乃 ?丂 ?可 ?兮 ?号 ?亏 ?旨 ?喜 ?壴 ; 160
93 ?鼓 ?豈 ?豆 ?豊 ?豐 ?䖒 ?虍 ?虎 ?虤 ?皿 ; 170
94 ?𠙴 ?去 ?血 ?丶 ?丹 ?青 ?井 ?皀 ?鬯 ?食 ; 180
95 ?亼 ?會 ?倉 ?入 ?缶 ?矢 ?高 ?冂 ?𩫏 ?京 ; 190
96 ?亯 ?𣆪 ?畗 ?㐭 ?嗇 ?來 ?麥 ?夊 ?舛 ?䑞 ; 200
97 ?韋 ?弟 ?夂 ?久 ?桀 ?木 ?東 ?林 ?才 ?叒 ; 210
98 ?之 ?帀 ?出 ?𣎵 ?生 ?乇 ?𠂹 ?𠌶 ?華 ?𥝌 ; 220
99 ?稽 ?巢 ?桼 ?束 ?㯻 ?囗 ?員 ?貝 ?邑 ?𨛜 ; 230
100 ?日 ?旦 ?倝 ?㫃 ?冥 ?晶 ?月 ?有 ?明 ?囧 ; 240
101 ?夕 ?多 ?毌 ?𢎘 ?𣐺 ?卣 ?齊 ?朿 ?片 ?鼎 ; 250
102 ?克 ?彔 ?禾 ?秝 ?黍 ?香 ?米 ?毇 ?臼 ?凶 ; 260
103 ?𣎳 ?林 ?麻 ?尗 ?耑 ?韭 ?瓜 ?瓠 ?宀 ?宮 ; 270
104 ?呂 ?穴 ?㝱 ?𤕫 ?冖 ?𠔼 ?冃 ?㒳 ?网 ?襾 ; 280
105 ?巾 ?巿 ?帛 ?白 ?㡀 ?黹 ?人 ?𠤎 ?匕 ?从 ; 290
108 (defun shuowen-radical (number)
109 (aref shuowen-radicals (1- number)))
111 (defvar char-db-file-coding-system 'utf-8-mcs-er)
113 (defvar char-db-feature-domains
114 '(ucs ucs/compat daikanwa cns gt jis jis/alt jis/a jis/b
115 jis-x0212 jis-x0213 cdp shinjigen misc unknown))
117 (defvar char-db-ignored-attributes '(ideographic-products))
119 (defun char-attribute-name< (ka kb)
121 ((eq '->denotational kb)
123 ((eq '->subsumptive kb)
124 (not (eq '->denotational ka)))
125 ((eq '->denotational ka)
127 ((eq '->subsumptive ka)
130 (string-match "^->" (symbol-name ka)))
131 (cond ((and (symbolp kb)
132 (string-match "^->" (symbol-name kb)))
133 (string< (symbol-name ka)
138 (string-match "^->" (symbol-name kb)))
141 (string-match "^<-" (symbol-name ka)))
143 (cond ((string-match "^<-" (symbol-name kb))
144 (string< (symbol-name ka)
147 ;; ((string-match "^->" (symbol-name kb))
152 (string-match "^<-" (symbol-name kb)))
154 ;; (not (string-match "^->" (symbol-name ka)))
157 (if (find-charset kb)
159 (if (setq a-ir (charset-property ka 'iso-ir))
160 (if (setq b-ir (charset-property kb 'iso-ir))
163 (< (charset-id ka)(charset-id kb))
173 (if (charset-property kb 'iso-ir)
175 (< (charset-id ka)(charset-id kb)))))
181 (string< (symbol-name ka)
187 (defvar char-db-coded-charset-priority-list
256 (defun char-db-make-char-spec (char)
258 (cond ((characterp char)
259 (cond ((and (setq ret (encode-char char '=ucs 'defined-only))
260 (not (and (<= #xE000 ret)(<= ret #xF8FF))))
261 (setq char-spec (list (cons '=ucs ret)))
262 (cond ((setq ret (get-char-attribute char 'name))
263 (setq char-spec (cons (cons 'name ret) char-spec))
265 ((setq ret (get-char-attribute char 'name*))
266 (setq char-spec (cons (cons 'name* ret) char-spec))
271 (let ((rest char-db-coded-charset-priority-list)
274 (setq ccs (charset-name
275 (find-charset (car rest))))
277 (encode-char char ccs
279 (throw 'tag (cons ccs ret)))
280 (setq rest (cdr rest))))))
281 (setq char-spec (list ret))
282 (dolist (ccs (delq (car ret) (charset-list)))
283 (if (and (or (charset-iso-final-char ccs)
290 (string-match "=ucs@" (symbol-name ccs)))
291 (setq ccs (charset-name ccs))
292 (null (assq ccs char-spec))
293 (setq ret (encode-char char ccs 'defined-only)))
294 (setq char-spec (cons (cons ccs ret) char-spec))))
296 (setq char-spec (split-char char)))
297 (cond ((setq ret (get-char-attribute char 'name))
298 (setq char-spec (cons (cons 'name ret) char-spec))
300 ((setq ret (get-char-attribute char 'name*))
301 (setq char-spec (cons (cons 'name* ret) char-spec))
304 ((setq ret (get-char-attribute
305 char 'ideographic-combination))
307 (cons (cons 'ideographic-combination ret)
314 (defun char-db-insert-char-spec (char &optional readable column
317 (setq column (current-column)))
318 (let (char-spec temp-char)
319 (setq char-spec (char-db-make-char-spec char))
320 (unless (or (characterp char) ; char
322 (setq char (find-char char-spec))
324 ;; define temporary character
325 ;; Current implementation is dirty.
326 (setq temp-char (define-char (cons '(ideograph-daikanwa . 0)
328 (remove-char-attribute temp-char 'ideograph-daikanwa)
329 (setq char temp-char))
330 (insert-char-attributes char
332 (union (mapcar #'car char-spec)
335 ;; undefine temporary character
336 ;; Current implementation is dirty.
337 (setq char-spec (char-attribute-alist temp-char))
339 (remove-char-attribute temp-char (car (car char-spec)))
340 (setq char-spec (cdr char-spec))))))
342 (defun char-db-insert-alist (alist &optional readable column)
344 (setq column (current-column)))
346 (concat "\n" (make-string (1+ column) ?\ )))
350 lbs cell rest separator)
353 (setq name (car (car alist))
354 value (cdr (car alist)))
355 (cond ((eq name 'char)
357 (if (setq ret (condition-case nil
365 (setq key (car (car value)))
366 ;; (if (find-charset key)
367 ;; (setq cal (cons key cal))
368 (setq al (cons key al))
370 (setq value (cdr value)))
371 (insert-char-attributes ret
375 (insert (prin1-to-string value)))
377 (insert line-breaking))
379 (insert (format "(%-18s " name))
380 (setq lbs (concat "\n" (make-string (current-column) ?\ )))
382 (setq cell (car value))
383 (if (and (consp cell)
385 (setq ret (condition-case nil
395 (setq key (car (car rest)))
396 ;; (if (find-charset key)
397 ;; (setq cal (cons key cal))
398 (setq al (cons key al))
400 (setq rest (cdr rest)))
403 (insert-char-attributes ret
407 (setq separator lbs))
410 (insert (prin1-to-string cell))
411 (setq separator " "))
412 (setq value (cdr value)))
414 (insert line-breaking))
416 (insert (format "(%-18s . %S)%s"
419 (setq alist (cdr alist))))
422 (defun char-db-insert-char-reference (plist &optional readable column)
424 (setq column (current-column)))
426 (concat "\n" (make-string (1+ column) ?\ )))
431 (setq name (pop plist))
432 (setq value (pop plist))
433 (cond ((eq name :char)
436 (cond ((numberp value)
437 (setq value (decode-char '=ucs value)))
439 ;; (setq value (or (find-char value)
442 (char-db-insert-char-spec value readable)
443 (insert line-breaking)
446 (insert (format "%s%s\t%d ; %c%s"
449 (ideographic-radical value)
453 (insert (format "%s%s\t%S" separator name value))
454 (setq separator line-breaking)))
458 (defun char-db-decode-isolated-char (ccs code-point)
461 (cond ((eq ccs 'arabic-iso8859-6)
462 (decode-char ccs code-point))
463 ((and (memq ccs '(=gt-pj-1
474 (setq ret (decode-char ccs code-point))
475 (setq ret (encode-char ret '=gt 'defined-only)))
476 (decode-builtin-char '=gt ret))
478 (decode-builtin-char ccs code-point))))
479 (cond ((and (<= 0 (char-int ret))
480 (<= (char-int ret) #x1F))
481 (decode-char '=ucs (+ #x2400 (char-int ret))))
482 ((= (char-int ret) #x7F)
486 (defvar char-db-convert-obsolete-format t)
488 (defun char-db-insert-ccs-feature (name value line-breaking)
491 (cond ((memq name '(=shinjigen
493 =shinjigen@rev =shinjigen/+p@rev))
494 "(%-18s . %04d)\t; %c")
495 ((eq name '=shinjigen@1ed/24pr)
496 "(%-18s . %04d)\t; %c")
497 ((or (memq name '(=daikanwa
498 =daikanwa@rev1 =daikanwa@rev2
499 =gt =>>gt =>gt =gt-k =cbeta =zinbun-oracle))
500 (string-match "^=adobe-" (symbol-name name)))
501 "(%-18s . %05d)\t; %c")
503 "(%-18s . %06d)\t; %c")
504 ((>= (charset-dimension name) 2)
505 "(%-18s . #x%04X)\t; %c")
507 "(%-18s . #x%02X)\t; %c"))
509 (if (= (charset-iso-graphic-plane name) 1)
511 (cond ((= (charset-dimension name) 1)
513 ((= (charset-dimension name) 2)
515 ((= (charset-dimension name) 3)
519 (char-db-decode-isolated-char name value)))
520 (if (and (= (charset-chars name) 94)
521 (= (charset-dimension name) 2))
522 (insert (format " [%02d-%02d]"
523 (- (lsh value -8) 32)
524 (- (logand value 255) 32))))
525 (insert line-breaking))
527 (defun char-db-insert-relation-feature (char name value line-breaking
529 (insert (format "(%-18s%s " name line-breaking))
530 (let ((lbs (concat "\n" (make-string (current-column) ?\ )))
531 separator cell sources required-features
534 (setq cell (car value))
536 (setq cell (decode-char '=ucs cell)))
538 ((eq name '->subsumptive)
539 (when (or (not (some (lambda (atr)
540 (get-char-attribute cell atr))
541 char-db-ignored-attributes))
543 (encode-char cell ccs 'defined-only))
547 (let ((char-db-ignored-attributes
549 char-db-ignored-attributes)))
550 (insert-char-attributes cell readable))
551 (setq separator lbs))
556 char (intern (format "%s*sources" name))))
557 (setq required-features nil)
558 (dolist (source sources)
562 shinjigen shinjigen@1ed shinjigen@rev))
563 (setq required-features
564 (union required-features
574 (setq required-features
575 (union required-features
580 ((find-charset (setq ret (intern (format "=%s" source))))
581 (setq required-features
582 (cons ret required-features)))
583 (t (setq required-features
584 (cons source required-features)))))
585 (cond ((string-match "@JP" (symbol-name name))
586 (setq required-features
587 (union required-features
595 ((string-match "@CN" (symbol-name name))
596 (setq required-features
597 (union required-features
604 (insert (format "%S" cell))
605 (char-db-insert-char-spec cell readable
608 (setq separator lbs))
612 (if (consp (car cell))
613 (char-db-insert-char-spec cell readable)
614 (char-db-insert-char-reference cell readable))
615 (setq separator lbs))
619 (insert (prin1-to-string cell))
620 (setq separator " ")))
621 (setq value (cdr value)))
623 (insert line-breaking)))
625 (defun insert-char-attributes (char &optional readable attributes column)
627 (setq column (current-column)))
628 (let (name value ; has-long-ccs-name
632 (concat "\n" (make-string (1+ column) ?\ )))
633 lbs cell separator ret
635 dest-ccss ; sources required-features
640 (if (consp attributes)
642 (dolist (name attributes)
643 (unless (memq name char-db-ignored-attributes)
644 (if (find-charset name)
648 (dolist (name (char-attribute-list))
649 (unless (memq name char-db-ignored-attributes)
650 (if (find-charset name)
654 #'char-attribute-name<)))
656 (when (memq '<-subsumptive attributes)
658 (when (setq value (get-char-attribute char '<-subsumptive))
659 (char-db-insert-relation-feature char '<-subsumptive value
662 (setq attributes (delq '<-subsumptive attributes)))
663 (when (and (memq '<-denotational attributes)
664 (setq value (get-char-attribute char '<-denotational)))
665 (char-db-insert-relation-feature char '<-denotational value
668 (setq attributes (delq '<-denotational attributes)))
669 (when (and (memq 'name attributes)
670 (setq value (get-char-attribute char 'name)))
672 (if (> (+ (current-column) (length value)) 48)
675 value line-breaking))
676 (setq attributes (delq 'name attributes))
678 (when (and (memq 'name* attributes)
679 (setq value (get-char-attribute char 'name*)))
681 (if (> (+ (current-column) (length value)) 48)
684 value line-breaking))
685 (setq attributes (delq 'name* attributes))
687 (when (and (memq 'script attributes)
688 (setq value (get-char-attribute char 'script)))
689 (insert (format "(script\t\t%s)%s"
690 (mapconcat (function prin1-to-string)
693 (setq attributes (delq 'script attributes))
695 (dolist (name '(=>ucs =>ucs*))
696 (when (and (memq name attributes)
697 (setq value (get-char-attribute char name)))
698 (insert (format "(%-18s . #x%04X)\t; %c%s"
699 name value (decode-char '=ucs value)
701 (setq attributes (delq name attributes))))
702 (dolist (name '(=>ucs@gb =>ucs@cns =>ucs@jis =>ucs@ks =>ucs@big5))
703 (when (and (memq name attributes)
704 (setq value (get-char-attribute char name)))
705 (insert (format "(%-18s . #x%04X)\t; %c%s"
710 (symbol-name name) 2)))
713 (setq attributes (delq name attributes))
715 (dolist (name '(=>daikanwa))
716 (when (and (memq name attributes)
717 (setq value (get-char-attribute char name)))
720 (format "(%-18s . %05d)\t; %c%s"
721 name value (decode-char '=daikanwa value)
723 (format "(%-18s %s)\t; %c%s"
725 (mapconcat (function prin1-to-string)
727 (char-representative-of-daikanwa char)
729 (setq attributes (delq name attributes))))
730 (when (and (memq 'general-category attributes)
731 (setq value (get-char-attribute char 'general-category)))
733 "(general-category\t%s) ; %s%s"
734 (mapconcat (lambda (cell)
737 (cond ((rassoc value unidata-normative-category-alist)
738 "Normative Category")
739 ((rassoc value unidata-informative-category-alist)
740 "Informative Category")
744 (setq attributes (delq 'general-category attributes))
746 (when (and (memq 'bidi-category attributes)
747 (setq value (get-char-attribute char 'bidi-category)))
748 (insert (format "(bidi-category\t. %S)%s"
751 (setq attributes (delq 'bidi-category attributes))
753 (unless (or (not (memq 'mirrored attributes))
754 (eq (setq value (get-char-attribute char 'mirrored 'empty))
756 (insert (format "(mirrored\t\t. %S)%s"
759 (setq attributes (delq 'mirrored attributes))
762 ((and (memq 'decimal-digit-value attributes)
763 (setq value (get-char-attribute char 'decimal-digit-value)))
764 (insert (format "(decimal-digit-value . %S)%s"
767 (setq attributes (delq 'decimal-digit-value attributes))
768 (when (and (memq 'digit-value attributes)
769 (setq value (get-char-attribute char 'digit-value)))
770 (insert (format "(digit-value\t . %S)%s"
773 (setq attributes (delq 'digit-value attributes))
775 (when (and (memq 'numeric-value attributes)
776 (setq value (get-char-attribute char 'numeric-value)))
777 (insert (format "(numeric-value\t . %S)%s"
780 (setq attributes (delq 'numeric-value attributes))
784 (when (and (memq 'digit-value attributes)
785 (setq value (get-char-attribute char 'digit-value)))
786 (insert (format "(digit-value\t. %S)%s"
789 (setq attributes (delq 'digit-value attributes))
791 (when (and (memq 'numeric-value attributes)
792 (setq value (get-char-attribute char 'numeric-value)))
793 (insert (format "(numeric-value\t. %S)%s"
796 (setq attributes (delq 'numeric-value attributes))
798 (when (and (memq 'iso-10646-comment attributes)
799 (setq value (get-char-attribute char 'iso-10646-comment)))
800 (insert (format "(iso-10646-comment\t. %S)%s"
803 (setq attributes (delq 'iso-10646-comment attributes))
805 (when (and (memq 'morohashi-daikanwa attributes)
806 (setq value (get-char-attribute char 'morohashi-daikanwa)))
807 (insert (format "(morohashi-daikanwa\t%s)%s"
808 (mapconcat (function prin1-to-string) value " ")
810 (setq attributes (delq 'morohashi-daikanwa attributes))
814 (when (and (memq 'ideographic-radical attributes)
815 (setq value (get-char-attribute char 'ideographic-radical)))
817 (insert (format "(ideographic-radical . %S)\t; %c%s"
819 (ideographic-radical radical)
821 (setq attributes (delq 'ideographic-radical attributes))
823 (when (and (memq 'shuowen-radical attributes)
824 (setq value (get-char-attribute char 'shuowen-radical)))
825 (insert (format "(shuowen-radical\t. %S)\t; %c%s"
827 (shuowen-radical value)
829 (setq attributes (delq 'shuowen-radical attributes))
834 char-db-feature-domains
836 (dolist (feature (char-attribute-list))
837 (setq feature (symbol-name feature))
839 "\\(radical\\|strokes\\)@\\([^@*]+\\)\\(\\*\\|$\\)"
841 (setq domain (intern (match-string 2 feature)))
842 (unless (memq domain dest)
843 (setq dest (cons domain dest)))))
844 (sort dest #'string<))))
845 (setq key (intern (format "%s@%s" 'ideographic-radical domain)))
846 (when (and (memq key attributes)
847 (setq value (get-char-attribute char key)))
849 (insert (format "(%s . %S)\t; %c%s"
852 (ideographic-radical radical)
854 (setq attributes (delq key attributes))
856 (setq key (intern (format "%s@%s" 'ideographic-strokes domain)))
857 (when (and (memq key attributes)
858 (setq value (get-char-attribute char key)))
860 (insert (format "(%s . %S)%s"
864 (setq attributes (delq key attributes))
866 (setq key (intern (format "%s@%s" 'total-strokes domain)))
867 (when (and (memq key attributes)
868 (setq value (get-char-attribute char key)))
869 (insert (format "(%s . %S)%s"
873 (setq attributes (delq key attributes))
875 (dolist (feature '(ideographic-radical
878 (setq key (intern (format "%s@%s*sources" feature domain)))
879 (when (and (memq key attributes)
880 (setq value (get-char-attribute char key)))
881 (insert (format "(%s%s" key line-breaking))
883 (insert (format " %s" cell)))
885 (insert line-breaking)
886 (setq attributes (delq key attributes))
889 (when (and (memq 'ideographic-strokes attributes)
890 (setq value (get-char-attribute char 'ideographic-strokes)))
892 (insert (format "(ideographic-strokes . %S)%s"
895 (setq attributes (delq 'ideographic-strokes attributes))
897 (when (and (memq 'kangxi-radical attributes)
898 (setq value (get-char-attribute char 'kangxi-radical)))
899 (unless (eq value radical)
900 (insert (format "(kangxi-radical\t . %S)\t; %c%s"
902 (ideographic-radical value)
905 (setq radical value)))
906 (setq attributes (delq 'kangxi-radical attributes))
908 (when (and (memq 'kangxi-strokes attributes)
909 (setq value (get-char-attribute char 'kangxi-strokes)))
910 (unless (eq value strokes)
911 (insert (format "(kangxi-strokes\t . %S)%s"
915 (setq strokes value)))
916 (setq attributes (delq 'kangxi-strokes attributes))
918 (when (and (memq 'japanese-radical attributes)
919 (setq value (get-char-attribute char 'japanese-radical)))
920 (unless (eq value radical)
921 (insert (format "(japanese-radical\t . %S)\t; %c%s"
923 (ideographic-radical value)
926 (setq radical value)))
927 (setq attributes (delq 'japanese-radical attributes))
929 (when (and (memq 'japanese-strokes attributes)
930 (setq value (get-char-attribute char 'japanese-strokes)))
931 (unless (eq value strokes)
932 (insert (format "(japanese-strokes\t . %S)%s"
936 (setq strokes value)))
937 (setq attributes (delq 'japanese-strokes attributes))
939 (when (and (memq 'cns-radical attributes)
940 (setq value (get-char-attribute char 'cns-radical)))
941 (insert (format "(cns-radical\t . %S)\t; %c%s"
943 (ideographic-radical value)
945 (setq attributes (delq 'cns-radical attributes))
947 (when (and (memq 'cns-strokes attributes)
948 (setq value (get-char-attribute char 'cns-strokes)))
949 (unless (eq value strokes)
950 (insert (format "(cns-strokes\t . %S)%s"
954 (setq strokes value)))
955 (setq attributes (delq 'cns-strokes attributes))
957 (when (and (memq 'shinjigen-1-radical attributes)
958 (setq value (get-char-attribute char 'shinjigen-1-radical)))
959 (unless (eq value radical)
960 (insert (format "(shinjigen-1-radical . %S)\t; %c%s"
962 (ideographic-radical value)
965 (setq radical value)))
966 (setq attributes (delq 'shinjigen-1-radical attributes))
968 (when (and (memq 'ideographic- attributes)
969 (setq value (get-char-attribute char 'ideographic-)))
970 (insert "(ideographic- ")
971 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
974 (setq cell (car value))
976 (setq cell (decode-char '=ucs cell)))
977 (cond ((characterp cell)
981 (insert (format "%S" cell))
982 (char-db-insert-char-spec cell readable))
983 (setq separator lbs))
987 (if (consp (car cell))
988 (char-db-insert-char-spec cell readable)
989 (char-db-insert-char-reference cell readable))
990 (setq separator lbs))
994 (insert (prin1-to-string cell))
995 (setq separator " ")))
996 (setq value (cdr value)))
998 (insert line-breaking)
999 (setq attributes (delq 'ideographic- attributes)))
1000 (when (and (memq 'total-strokes attributes)
1001 (setq value (get-char-attribute char 'total-strokes)))
1002 (insert (format "(total-strokes . %S)%s"
1005 (setq attributes (delq 'total-strokes attributes))
1007 (when (and (memq '->ideograph attributes)
1008 (setq value (get-char-attribute char '->ideograph)))
1009 (insert (format "(->ideograph\t%s)%s"
1010 (mapconcat (lambda (code)
1011 (cond ((symbolp code)
1014 (format "#x%04X" code))
1017 line-breaking code))))
1020 (setq attributes (delq '->ideograph attributes))
1022 ;; (when (and (memq '->decomposition attributes)
1023 ;; (setq value (get-char-attribute char '->decomposition)))
1024 ;; (insert (format "(->decomposition\t%s)%s"
1025 ;; (mapconcat (lambda (code)
1026 ;; (cond ((symbolp code)
1027 ;; (symbol-name code))
1028 ;; ((characterp code)
1030 ;; (format "%S" code)
1035 ;; (format "#x%04X" code))
1037 ;; (format "%s%S" line-breaking code))))
1040 ;; (setq attributes (delq '->decomposition attributes))
1042 (if (equal (get-char-attribute char '->titlecase)
1043 (get-char-attribute char '->uppercase))
1044 (setq attributes (delq '->titlecase attributes)))
1045 (when (and (memq '->mojikyo attributes)
1046 (setq value (get-char-attribute char '->mojikyo)))
1047 (insert (format "(->mojikyo\t\t. %06d)\t; %c%s"
1048 value (decode-char 'mojikyo value)
1050 (setq attributes (delq '->mojikyo attributes))
1052 (when (and (memq 'hanyu-dazidian-vol attributes)
1053 (setq value (get-char-attribute char 'hanyu-dazidian-vol)))
1054 (insert (format "(hanyu-dazidian-vol . %d)%s"
1055 value line-breaking))
1056 (setq attributes (delq 'hanyu-dazidian-vol attributes))
1058 (when (and (memq 'hanyu-dazidian-page attributes)
1059 (setq value (get-char-attribute char 'hanyu-dazidian-page)))
1060 (insert (format "(hanyu-dazidian-page . %d)%s"
1061 value line-breaking))
1062 (setq attributes (delq 'hanyu-dazidian-page attributes))
1064 (when (and (memq 'hanyu-dazidian-char attributes)
1065 (setq value (get-char-attribute char 'hanyu-dazidian-char)))
1066 (insert (format "(hanyu-dazidian-char . %d)%s"
1067 value line-breaking))
1068 (setq attributes (delq 'hanyu-dazidian-char attributes))
1071 (dolist (ignored '(composition
1072 ->denotational <-subsumptive ->ucs-unified
1073 ->ideographic-component-forms))
1074 (setq attributes (delq ignored attributes))))
1076 (setq name (car attributes))
1077 (if (setq value (get-char-attribute char name))
1078 (cond ((setq ret (find-charset name))
1079 (setq name (charset-name ret))
1080 (if (and (not (memq name dest-ccss))
1082 (setq value (get-char-attribute char name))
1083 (setq dest-ccss (cons name dest-ccss))))
1084 (char-db-insert-ccs-feature name value line-breaking))
1086 ((string-match "^=>ucs@" (symbol-name name))
1087 (insert (format "(%-18s . #x%04X)\t; %c%s"
1088 name value (decode-char '=ucs value)
1091 ((eq name 'jisx0208-1978/4X)
1092 (insert (format "(%-18s . #x%04X)%s"
1098 (not (eq name '->subsumptive))
1099 (not (eq name '->uppercase))
1100 (not (eq name '->lowercase))
1101 (not (eq name '->titlecase))
1102 (not (eq name '->canonical))
1103 (not (eq name '->Bopomofo))
1104 (not (eq name '->mistakable))
1105 (not (eq name '->ideographic-variants))
1106 (null (get-char-attribute
1107 char (intern (format "%s*sources" name))))
1108 (not (string-match "\\*sources$" (symbol-name name)))
1109 (null (get-char-attribute
1110 char (intern (format "%s*note" name))))
1111 (not (string-match "\\*note$" (symbol-name name)))
1112 (or (eq name '<-identical)
1113 (eq name '<-uppercase)
1114 (eq name '<-lowercase)
1115 (eq name '<-titlecase)
1116 (eq name '<-canonical)
1117 (eq name '<-ideographic-variants)
1118 ;; (eq name '<-synonyms)
1119 (string-match "^<-synonyms" (symbol-name name))
1120 (eq name '<-mistakable)
1121 (when (string-match "^->" (symbol-name name))
1123 ((string-match "^->fullwidth" (symbol-name name))
1124 (not (and (consp value)
1125 (characterp (car value))
1127 (car value) '=ucs 'defined-only)))
1132 ((or (eq name 'ideographic-structure)
1133 (eq name 'ideographic-combination)
1134 (eq name 'ideographic-)
1135 (eq name '=decomposition)
1136 (string-match "^=>decomposition" (symbol-name name))
1137 (string-match "^\\(->\\|<-\\)[^*]*$" (symbol-name name))
1138 (string-match "^\\(->\\|<-\\)[^*]*\\*sources$"
1141 (char-db-insert-relation-feature char name value
1144 ((memq name '(ideograph=
1145 original-ideograph-of
1146 ancient-ideograph-of
1149 ;; simplified-ideograph-of
1150 ideographic-variants
1151 ;; ideographic-different-form-of
1153 (insert (format "(%-18s%s " name line-breaking))
1154 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1156 (while (consp value)
1157 (setq cell (car value))
1158 (if (and (consp cell)
1163 (char-db-insert-alist cell readable)
1164 (setq separator lbs))
1167 (insert (prin1-to-string cell))
1168 (setq separator " "))
1169 (setq value (cdr value)))
1171 (insert line-breaking))
1173 (insert (format "(%-18s " name))
1174 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1176 (while (consp value)
1177 (setq cell (car value))
1178 (if (and (consp cell)
1180 (setq ret (condition-case nil
1188 (setq key (car (car rest)))
1189 (if (find-charset key)
1190 (setq cal (cons key cal))
1191 (setq al (cons key al)))
1192 (setq rest (cdr rest)))
1195 (insert-char-attributes ret
1198 (setq separator lbs))
1199 (setq ret (prin1-to-string cell))
1201 (if (< (+ (current-column)
1208 (setq separator " "))
1209 (setq value (cdr value)))
1211 (insert line-breaking))
1213 (insert (format "(%-18s" name))
1214 (setq ret (prin1-to-string value))
1215 (unless (< (+ (current-column)
1219 (insert line-breaking))
1220 (insert " . " ret ")" line-breaking)
1221 ;; (insert (format "(%-18s . %S)%s"
1226 (setq attributes (cdr attributes)))
1229 (defun insert-char-data (char &optional readable
1232 (narrow-to-region (point)(point))
1233 (insert "(define-char
1235 (insert-char-attributes char readable attributes)
1237 (goto-char (point-min))
1238 (while (re-search-forward "[ \t]+$" nil t)
1241 (goto-char (point-min))
1242 (while (re-search-forward "[ \t][ \t][ \t]*" nil t)
1243 (let ((column (current-column))
1244 (indent-tabs-mode t))
1245 (delete-region (match-beginning 0) (point))
1246 (indent-to column)))
1247 (goto-char (point-max))
1248 ;; (tabify (point-min)(point-max))
1251 (defun insert-char-data-with-variant (char &optional printable
1253 script excluded-script)
1254 (insert-char-data char printable)
1255 (let ((variants (char-variants char))
1258 (setq variants (sort variants #'<))
1259 (setq rest variants)
1260 (setq variants (cons char variants))
1262 (setq variant (car rest))
1263 (unless (get-char-attribute variant '<-subsumptive)
1264 (if (and (or (null script)
1265 (null (setq vs (get-char-attribute variant 'script)))
1267 (or (null excluded-script)
1268 (null (setq vs (get-char-attribute variant 'script)))
1269 (not (memq excluded-script vs))))
1270 (unless (and no-ucs-unified (get-char-attribute variant '=ucs))
1271 (insert-char-data variant printable)
1272 (if (setq ret (char-variants variant))
1274 (or (memq (car ret) variants)
1275 ;; (get-char-attribute (car ret) '<-subsumptive)
1276 (setq rest (nconc rest (list (car ret)))))
1277 (setq ret (cdr ret)))))))
1278 (setq rest (cdr rest)))))
1280 (defun insert-char-range-data (min max &optional script excluded-script)
1283 (while (<= code max)
1284 (setq char (decode-char '=ucs code))
1285 (if (encode-char char '=ucs 'defined-only)
1286 (insert-char-data-with-variant char nil 'no-ucs-unified
1287 script excluded-script))
1288 (setq code (1+ code)))))
1290 (defun write-char-range-data-to-file (min max file
1291 &optional script excluded-script)
1292 (let ((coding-system-for-write char-db-file-coding-system))
1294 (insert (format ";; -*- coding: %s -*-\n"
1295 char-db-file-coding-system))
1296 (insert-char-range-data min max script excluded-script)
1297 (write-region (point-min)(point-max) file))))
1299 (defvar what-character-original-window-configuration)
1302 (defun what-char-definition (char)
1303 (interactive (list (char-after)))
1304 (let ((buf (get-buffer-create "*Character Description*"))
1305 (the-buf (current-buffer))
1306 (win-conf (current-window-configuration)))
1308 (make-local-variable 'what-character-original-window-configuration)
1309 (setq what-character-original-window-configuration win-conf)
1310 (setq buffer-read-only nil)
1314 (insert-char-data-with-variant char 'printable)
1315 (unless (char-attribute-alist char)
1316 (insert (format ";; = %c\n"
1317 (let* ((rest (split-char char))
1321 (setq code (logior (lsh code 8)
1323 (decode-char ccs code)))))
1324 ;; (char-db-update-comment)
1325 (set-buffer-modified-p nil)
1326 (view-mode the-buf (lambda (buf)
1327 (set-window-configuration
1328 what-character-original-window-configuration)
1330 (goto-char (point-min)))
1332 (set-window-configuration
1333 what-character-original-window-configuration)
1334 (signal (car err) (cdr err)))))))
1336 (provide 'char-db-util)
1338 ;;; char-db-util.el ends here