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, 2010 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 ?鼓 ?豈 ?豆 ?豊 ?豐 ?䖒 ?虍 ?虎 ?虤 ?皿 ; 170
84 ?𠙴 ?去 ?血 ?丶 ?丹 ?青 ?井 ?皀 ?鬯 ?食 ; 180
85 ?亼 ?會 ?倉 ?入 ?缶 ?矢 ?高 ?冂 ?𩫏 ?京 ; 190
86 ?亯 ?𣆪 ?畗 ?㐭 ?嗇 ?來 ?麥 ?夊 ?舛 ?䑞 ; 200
87 ?韋 ?弟 ?夂 ?久 ?桀 ?木 ?東 ?林 ?才 ?叒 ; 210
88 ?之 ?帀 ?出 ?𣎵 ?生 ?乇 ?𠂹 ?𠌶 ?華 ?𥝌 ; 220
89 ?稽 ?巢 ?桼 ?束 ?㯻 ?囗 ?員 ?貝 ?邑 ?𨛜 ; 230
90 ?日 ?旦 ?倝 ?㫃 ?冥 ?晶 ?月 ?有 ?明 ?囧 ; 240
91 ?夕 ?多 ?毌 ?𢎘 ?𣐺 ?卣 ?齊 ?朿 ?片 ?鼎 ; 250
92 ?克 ?彔 ?禾 ?秝 ?黍 ?香 ?米 ?毇 ?臼 ?凶 ; 260
93 ?𣎳 ?林 ?麻 ?尗 ?耑 ?韭 ?瓜 ?瓠 ?宀 ?宮 ; 270
94 ?呂 ?穴 ?㝱 ?𤕫 ?冖 ?𠔼 ?冃 ?㒳 ?网 ?襾 ; 280
95 ?巾 ?巿 ?帛 ?白 ?㡀 ?黹 ?人 ?𠤎 ?匕 ?从 ; 290
98 (defun shuowen-radical (number)
99 (aref shuowen-radicals (1- number)))
101 (defvar char-db-file-coding-system 'utf-8-mcs-er)
103 (defvar char-db-ignored-attributes '(ideographic-products))
105 (defvar char-db-coded-charset-priority-list
198 ;;; @ char-db formatters
201 (defun char-db-make-char-spec (char)
203 (cond ((characterp char)
204 (cond ((and (setq ret (encode-char char '=ucs 'defined-only))
205 (not (and (<= #xE000 ret)(<= ret #xF8FF))))
206 (setq char-spec (list (cons '=ucs ret)))
207 (cond ((setq ret (get-char-attribute char 'name))
208 (setq char-spec (cons (cons 'name ret) char-spec))
210 ((setq ret (get-char-attribute char 'name*))
211 (setq char-spec (cons (cons 'name* ret) char-spec))
216 (let ((rest char-db-coded-charset-priority-list)
219 (setq ccs (charset-name
220 (find-charset (car rest))))
222 (encode-char char ccs
224 (throw 'tag (cons ccs ret)))
225 (setq rest (cdr rest))))))
226 (setq char-spec (list ret))
227 (dolist (ccs (delq (car ret) (charset-list)))
228 (if (and (or (charset-iso-final-char ccs)
235 (string-match "=ucs@" (symbol-name ccs)))
236 (setq ccs (charset-name ccs))
237 (null (assq ccs char-spec))
238 (setq ret (encode-char char ccs 'defined-only)))
239 (setq char-spec (cons (cons ccs ret) char-spec))))
241 (setq char-spec (split-char char)))
242 (cond ((setq ret (get-char-attribute char 'name))
243 (setq char-spec (cons (cons 'name ret) char-spec))
245 ((setq ret (get-char-attribute char 'name*))
246 (setq char-spec (cons (cons 'name* ret) char-spec))
249 ((setq ret (get-char-attribute
250 char 'ideographic-combination))
252 (cons (cons 'ideographic-combination ret)
259 (defun char-db-insert-char-spec (char &optional readable column
262 (setq column (current-column)))
263 (let (char-spec temp-char)
264 (setq char-spec (char-db-make-char-spec char))
265 (unless (or (characterp char) ; char
267 (setq char (find-char char-spec))
269 ;; define temporary character
270 ;; Current implementation is dirty.
271 (setq temp-char (define-char (cons '(ideograph-daikanwa . 0)
273 (remove-char-attribute temp-char 'ideograph-daikanwa)
274 (setq char temp-char))
275 (insert-char-attributes char
277 (union (mapcar #'car char-spec)
280 ;; undefine temporary character
281 ;; Current implementation is dirty.
282 (setq char-spec (char-attribute-alist temp-char))
284 (remove-char-attribute temp-char (car (car char-spec)))
285 (setq char-spec (cdr char-spec))))))
287 (defun char-db-insert-alist (alist &optional readable column)
289 (setq column (current-column)))
291 (concat "\n" (make-string (1+ column) ?\ )))
295 lbs cell rest separator)
298 (setq name (car (car alist))
299 value (cdr (car alist)))
300 (cond ((eq name 'char)
302 (if (setq ret (condition-case nil
310 (setq key (car (car value)))
311 ;; (if (find-charset key)
312 ;; (setq cal (cons key cal))
313 (setq al (cons key al))
315 (setq value (cdr value)))
316 (insert-char-attributes ret
320 (insert (prin1-to-string value)))
322 (insert line-breaking))
324 (insert (format "(%-18s " name))
325 (setq lbs (concat "\n" (make-string (current-column) ?\ )))
327 (setq cell (car value))
328 (if (and (consp cell)
330 (setq ret (condition-case nil
340 (setq key (car (car rest)))
341 ;; (if (find-charset key)
342 ;; (setq cal (cons key cal))
343 (setq al (cons key al))
345 (setq rest (cdr rest)))
348 (insert-char-attributes ret
352 (setq separator lbs))
355 (insert (prin1-to-string cell))
356 (setq separator " "))
357 (setq value (cdr value)))
359 (insert line-breaking))
361 (insert (format "(%-18s . %S)%s"
364 (setq alist (cdr alist))))
367 (defun char-db-insert-char-reference (plist &optional readable column)
369 (setq column (current-column)))
371 (concat "\n" (make-string (1+ column) ?\ )))
376 (setq name (pop plist))
377 (setq value (pop plist))
378 (cond ((eq name :char)
381 (cond ((numberp value)
382 (setq value (decode-char '=ucs value)))
384 ;; (setq value (or (find-char value)
387 (char-db-insert-char-spec value readable)
388 (insert line-breaking)
391 (insert (format "%s%s\t%d ; %c%s"
394 (ideographic-radical value)
398 (insert (format "%s%s\t%S" separator name value))
399 (setq separator line-breaking)))
403 (defun char-db-decode-isolated-char (ccs code-point)
406 (cond ((eq ccs 'arabic-iso8859-6)
407 (decode-char ccs code-point))
408 ((and (memq ccs '(=gt-pj-1
419 (setq ret (decode-char ccs code-point))
420 (setq ret (encode-char ret '=gt 'defined-only)))
421 (decode-builtin-char '=gt ret))
423 (decode-builtin-char ccs code-point))))
424 (cond ((and (<= 0 (char-int ret))
425 (<= (char-int ret) #x1F))
426 (decode-char '=ucs (+ #x2400 (char-int ret))))
427 ((= (char-int ret) #x7F)
431 (defvar char-db-convert-obsolete-format t)
433 (defun char-db-insert-ccs-feature (name value line-breaking)
436 (cond ((memq name '(=shinjigen
438 =shinjigen@rev =shinjigen/+p@rev))
439 "(%-18s . %04d)\t; %c")
440 ((eq name '=shinjigen@1ed/24pr)
441 "(%-18s . %04d)\t; %c")
442 ((or (memq name '(=daikanwa
443 =daikanwa@rev1 =daikanwa@rev2
444 =>>daikanwa =>daikanwa
445 =gt =>>gt =>gt =gt-k =>>gt-k =cbeta
446 =zinbun-oracle =>zinbun-oracle))
447 (string-match "^=adobe-" (symbol-name name)))
448 "(%-18s . %05d)\t; %c")
450 "(%-18s . %06d)\t; %c")
451 ((>= (charset-dimension name) 2)
452 "(%-18s . #x%04X)\t; %c")
454 "(%-18s . #x%02X)\t; %c"))
456 (if (= (charset-iso-graphic-plane name) 1)
458 (cond ((= (charset-dimension name) 1)
460 ((= (charset-dimension name) 2)
462 ((= (charset-dimension name) 3)
466 (char-db-decode-isolated-char name value)))
467 (if (and (= (charset-chars name) 94)
468 (= (charset-dimension name) 2))
469 (insert (format " [%02d-%02d]"
470 (- (lsh value -8) 32)
471 (- (logand value 255) 32))))
472 (insert line-breaking))
474 (defun char-db-insert-relation-feature (char name value line-breaking
476 (insert (format "(%-18s%s " name line-breaking))
477 (let ((lbs (concat "\n" (make-string (current-column) ?\ )))
478 separator cell sources required-features
481 (setq cell (car value))
483 (setq cell (decode-char '=ucs cell)))
485 ((eq name '->subsumptive)
486 (when (or (not (some (lambda (atr)
487 (get-char-attribute cell atr))
488 char-db-ignored-attributes))
490 (encode-char cell ccs 'defined-only))
494 (let ((char-db-ignored-attributes
496 char-db-ignored-attributes)))
497 (insert-char-attributes cell readable))
498 (setq separator lbs))
503 char (intern (format "%s*sources" name))))
504 (setq required-features nil)
505 (dolist (source sources)
509 shinjigen shinjigen@1ed shinjigen@rev))
510 (setq required-features
511 (union required-features
522 (setq required-features
523 (union required-features
528 ((find-charset (setq ret (intern (format "=%s" source))))
529 (setq required-features
530 (cons ret required-features)))
531 (t (setq required-features
532 (cons source required-features)))))
533 (cond ((string-match "@JP" (symbol-name name))
534 (setq required-features
535 (union required-features
543 ((string-match "@CN" (symbol-name name))
544 (setq required-features
545 (union required-features
552 (insert (format "%S" cell))
553 (char-db-insert-char-spec cell readable
556 (setq separator lbs))
560 (if (consp (car cell))
561 (char-db-insert-char-spec cell readable)
562 (char-db-insert-char-reference cell readable))
563 (setq separator lbs))
567 (insert (prin1-to-string cell))
568 (setq separator " ")))
569 (setq value (cdr value)))
571 (insert line-breaking)))
573 (defun insert-char-attributes (char &optional readable attributes column)
575 (setq column (current-column)))
576 (let (name value ; has-long-ccs-name
580 (concat "\n" (make-string (1+ column) ?\ )))
581 lbs cell separator ret
583 dest-ccss ; sources required-features
588 (if (consp attributes)
590 (dolist (name attributes)
591 (unless (memq name char-db-ignored-attributes)
592 (if (find-charset name)
596 (dolist (name (char-attribute-list))
597 (unless (memq name char-db-ignored-attributes)
598 (if (find-charset name)
602 #'char-attribute-name<)))
604 (when (memq '<-subsumptive attributes)
606 (when (setq value (get-char-attribute char '<-subsumptive))
607 (char-db-insert-relation-feature char '<-subsumptive value
610 (setq attributes (delq '<-subsumptive attributes)))
611 (when (and (memq '<-denotational attributes)
612 (setq value (get-char-attribute char '<-denotational)))
613 (char-db-insert-relation-feature char '<-denotational value
616 (setq attributes (delq '<-denotational attributes)))
617 (when (and (memq 'name attributes)
618 (setq value (get-char-attribute char 'name)))
620 (if (> (+ (current-column) (length value)) 48)
623 value line-breaking))
624 (setq attributes (delq 'name attributes))
626 (when (and (memq 'name* attributes)
627 (setq value (get-char-attribute char 'name*)))
629 (if (> (+ (current-column) (length value)) 48)
632 value line-breaking))
633 (setq attributes (delq 'name* attributes))
635 (when (and (memq 'script attributes)
636 (setq value (get-char-attribute char 'script)))
637 (insert (format "(script\t\t%s)%s"
638 (mapconcat (function prin1-to-string)
641 (setq attributes (delq 'script attributes))
643 (dolist (name '(=>ucs =>ucs*))
644 (when (and (memq name attributes)
645 (setq value (get-char-attribute char name)))
646 (insert (format "(%-18s . #x%04X)\t; %c%s"
647 name value (decode-char '=ucs value)
649 (setq attributes (delq name attributes))))
650 (dolist (name '(=>ucs@gb =>ucs@ks =>ucs@big5))
651 (when (and (memq name attributes)
652 (setq value (get-char-attribute char name)))
653 (insert (format "(%-18s . #x%04X)\t; %c%s"
658 (symbol-name name) 2)))
661 (setq attributes (delq name attributes))
663 ;; (dolist (name '(=>daikanwa))
664 ;; (when (and (memq name attributes)
665 ;; (setq value (get-char-attribute char name)))
667 ;; (if (integerp value)
668 ;; (format "(%-18s . %05d)\t; %c%s"
669 ;; name value (decode-char '=daikanwa value)
671 ;; (format "(%-18s %s)\t; %c%s"
673 ;; (mapconcat (function prin1-to-string)
675 ;; (char-representative-of-daikanwa char)
677 ;; (setq attributes (delq name attributes))))
678 (when (and (memq 'general-category attributes)
679 (setq value (get-char-attribute char 'general-category)))
681 "(general-category\t%s) ; %s%s"
682 (mapconcat (lambda (cell)
685 (cond ((rassoc value unidata-normative-category-alist)
686 "Normative Category")
687 ((rassoc value unidata-informative-category-alist)
688 "Informative Category")
692 (setq attributes (delq 'general-category attributes))
694 (when (and (memq 'bidi-category attributes)
695 (setq value (get-char-attribute char 'bidi-category)))
696 (insert (format "(bidi-category\t. %S)%s"
699 (setq attributes (delq 'bidi-category attributes))
701 (unless (or (not (memq 'mirrored attributes))
702 (eq (setq value (get-char-attribute char 'mirrored 'empty))
704 (insert (format "(mirrored\t\t. %S)%s"
707 (setq attributes (delq 'mirrored attributes))
710 ((and (memq 'decimal-digit-value attributes)
711 (setq value (get-char-attribute char 'decimal-digit-value)))
712 (insert (format "(decimal-digit-value . %S)%s"
715 (setq attributes (delq 'decimal-digit-value attributes))
716 (when (and (memq 'digit-value attributes)
717 (setq value (get-char-attribute char 'digit-value)))
718 (insert (format "(digit-value\t . %S)%s"
721 (setq attributes (delq 'digit-value attributes))
723 (when (and (memq 'numeric-value attributes)
724 (setq value (get-char-attribute char 'numeric-value)))
725 (insert (format "(numeric-value\t . %S)%s"
728 (setq attributes (delq 'numeric-value attributes))
732 (when (and (memq 'digit-value attributes)
733 (setq value (get-char-attribute char 'digit-value)))
734 (insert (format "(digit-value\t. %S)%s"
737 (setq attributes (delq 'digit-value attributes))
739 (when (and (memq 'numeric-value attributes)
740 (setq value (get-char-attribute char 'numeric-value)))
741 (insert (format "(numeric-value\t. %S)%s"
744 (setq attributes (delq 'numeric-value attributes))
746 (when (and (memq 'iso-10646-comment attributes)
747 (setq value (get-char-attribute char 'iso-10646-comment)))
748 (insert (format "(iso-10646-comment\t. %S)%s"
751 (setq attributes (delq 'iso-10646-comment attributes))
753 (when (and (memq 'morohashi-daikanwa attributes)
754 (setq value (get-char-attribute char 'morohashi-daikanwa)))
755 (insert (format "(morohashi-daikanwa\t%s)%s"
756 (mapconcat (function prin1-to-string) value " ")
758 (setq attributes (delq 'morohashi-daikanwa attributes))
762 (when (and (memq 'ideographic-radical attributes)
763 (setq value (get-char-attribute char 'ideographic-radical)))
765 (insert (format "(ideographic-radical . %S)\t; %c%s"
767 (ideographic-radical radical)
769 (setq attributes (delq 'ideographic-radical attributes))
771 (when (and (memq 'shuowen-radical attributes)
772 (setq value (get-char-attribute char 'shuowen-radical)))
773 (insert (format "(shuowen-radical\t. %S)\t; %c%s"
775 (shuowen-radical value)
777 (setq attributes (delq 'shuowen-radical attributes))
782 char-db-feature-domains
784 (dolist (feature (char-attribute-list))
785 (setq feature (symbol-name feature))
787 "\\(radical\\|strokes\\)@\\([^@*]+\\)\\(\\*\\|$\\)"
789 (setq domain (intern (match-string 2 feature)))
790 (unless (memq domain dest)
791 (setq dest (cons domain dest)))))
792 (sort dest #'string<))))
793 (setq key (intern (format "%s@%s" 'ideographic-radical domain)))
794 (when (and (memq key attributes)
795 (setq value (get-char-attribute char key)))
797 (insert (format "(%s . %S)\t; %c%s"
800 (ideographic-radical radical)
802 (setq attributes (delq key attributes))
804 (setq key (intern (format "%s@%s" 'ideographic-strokes domain)))
805 (when (and (memq key attributes)
806 (setq value (get-char-attribute char key)))
808 (insert (format "(%s . %S)%s"
812 (setq attributes (delq key attributes))
814 (setq key (intern (format "%s@%s" 'total-strokes domain)))
815 (when (and (memq key attributes)
816 (setq value (get-char-attribute char key)))
817 (insert (format "(%s . %S)%s"
821 (setq attributes (delq key attributes))
823 (dolist (feature '(ideographic-radical
826 (setq key (intern (format "%s@%s*sources" feature domain)))
827 (when (and (memq key attributes)
828 (setq value (get-char-attribute char key)))
829 (insert (format "(%s%s" key line-breaking))
831 (insert (format " %s" cell)))
833 (insert line-breaking)
834 (setq attributes (delq key attributes))
837 (when (and (memq 'ideographic-strokes attributes)
838 (setq value (get-char-attribute char 'ideographic-strokes)))
840 (insert (format "(ideographic-strokes . %S)%s"
843 (setq attributes (delq 'ideographic-strokes attributes))
845 (when (and (memq 'kangxi-radical attributes)
846 (setq value (get-char-attribute char 'kangxi-radical)))
847 (unless (eq value radical)
848 (insert (format "(kangxi-radical\t . %S)\t; %c%s"
850 (ideographic-radical value)
853 (setq radical value)))
854 (setq attributes (delq 'kangxi-radical attributes))
856 (when (and (memq 'kangxi-strokes attributes)
857 (setq value (get-char-attribute char 'kangxi-strokes)))
858 (unless (eq value strokes)
859 (insert (format "(kangxi-strokes\t . %S)%s"
863 (setq strokes value)))
864 (setq attributes (delq 'kangxi-strokes attributes))
866 (when (and (memq 'japanese-radical attributes)
867 (setq value (get-char-attribute char 'japanese-radical)))
868 (unless (eq value radical)
869 (insert (format "(japanese-radical\t . %S)\t; %c%s"
871 (ideographic-radical value)
874 (setq radical value)))
875 (setq attributes (delq 'japanese-radical attributes))
877 (when (and (memq 'japanese-strokes attributes)
878 (setq value (get-char-attribute char 'japanese-strokes)))
879 (unless (eq value strokes)
880 (insert (format "(japanese-strokes\t . %S)%s"
884 (setq strokes value)))
885 (setq attributes (delq 'japanese-strokes attributes))
887 (when (and (memq 'cns-radical attributes)
888 (setq value (get-char-attribute char 'cns-radical)))
889 (insert (format "(cns-radical\t . %S)\t; %c%s"
891 (ideographic-radical value)
893 (setq attributes (delq 'cns-radical attributes))
895 (when (and (memq 'cns-strokes attributes)
896 (setq value (get-char-attribute char 'cns-strokes)))
897 (unless (eq value strokes)
898 (insert (format "(cns-strokes\t . %S)%s"
902 (setq strokes value)))
903 (setq attributes (delq 'cns-strokes attributes))
905 (when (and (memq 'shinjigen-1-radical attributes)
906 (setq value (get-char-attribute char 'shinjigen-1-radical)))
907 (unless (eq value radical)
908 (insert (format "(shinjigen-1-radical . %S)\t; %c%s"
910 (ideographic-radical value)
913 (setq radical value)))
914 (setq attributes (delq 'shinjigen-1-radical attributes))
916 (when (and (memq 'ideographic- attributes)
917 (setq value (get-char-attribute char 'ideographic-)))
918 (insert "(ideographic- ")
919 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
922 (setq cell (car value))
924 (setq cell (decode-char '=ucs cell)))
925 (cond ((characterp cell)
929 (insert (format "%S" cell))
930 (char-db-insert-char-spec cell readable))
931 (setq separator lbs))
935 (if (consp (car cell))
936 (char-db-insert-char-spec cell readable)
937 (char-db-insert-char-reference cell readable))
938 (setq separator lbs))
942 (insert (prin1-to-string cell))
943 (setq separator " ")))
944 (setq value (cdr value)))
946 (insert line-breaking)
947 (setq attributes (delq 'ideographic- attributes)))
948 (when (and (memq 'total-strokes attributes)
949 (setq value (get-char-attribute char 'total-strokes)))
950 (insert (format "(total-strokes . %S)%s"
953 (setq attributes (delq 'total-strokes attributes))
955 (when (and (memq '->ideograph attributes)
956 (setq value (get-char-attribute char '->ideograph)))
957 (insert (format "(->ideograph\t%s)%s"
958 (mapconcat (lambda (code)
959 (cond ((symbolp code)
962 (format "#x%04X" code))
965 line-breaking code))))
968 (setq attributes (delq '->ideograph attributes))
970 ;; (when (and (memq '->decomposition attributes)
971 ;; (setq value (get-char-attribute char '->decomposition)))
972 ;; (insert (format "(->decomposition\t%s)%s"
973 ;; (mapconcat (lambda (code)
974 ;; (cond ((symbolp code)
975 ;; (symbol-name code))
976 ;; ((characterp code)
978 ;; (format "%S" code)
983 ;; (format "#x%04X" code))
985 ;; (format "%s%S" line-breaking code))))
988 ;; (setq attributes (delq '->decomposition attributes))
990 (if (equal (get-char-attribute char '->titlecase)
991 (get-char-attribute char '->uppercase))
992 (setq attributes (delq '->titlecase attributes)))
993 (when (and (memq '->mojikyo attributes)
994 (setq value (get-char-attribute char '->mojikyo)))
995 (insert (format "(->mojikyo\t\t. %06d)\t; %c%s"
996 value (decode-char 'mojikyo value)
998 (setq attributes (delq '->mojikyo attributes))
1000 (when (and (memq 'hanyu-dazidian-vol attributes)
1001 (setq value (get-char-attribute char 'hanyu-dazidian-vol)))
1002 (insert (format "(hanyu-dazidian-vol . %d)%s"
1003 value line-breaking))
1004 (setq attributes (delq 'hanyu-dazidian-vol attributes))
1006 (when (and (memq 'hanyu-dazidian-page attributes)
1007 (setq value (get-char-attribute char 'hanyu-dazidian-page)))
1008 (insert (format "(hanyu-dazidian-page . %d)%s"
1009 value line-breaking))
1010 (setq attributes (delq 'hanyu-dazidian-page attributes))
1012 (when (and (memq 'hanyu-dazidian-char attributes)
1013 (setq value (get-char-attribute char 'hanyu-dazidian-char)))
1014 (insert (format "(hanyu-dazidian-char . %d)%s"
1015 value line-breaking))
1016 (setq attributes (delq 'hanyu-dazidian-char attributes))
1019 (dolist (ignored '(composition
1020 ->denotational <-subsumptive ->ucs-unified
1021 ->ideographic-component-forms))
1022 (setq attributes (delq ignored attributes))))
1024 (setq name (car attributes))
1025 (if (setq value (get-char-attribute char name))
1026 (cond ((setq ret (find-charset name))
1027 (setq name (charset-name ret))
1028 (if (and (not (memq name dest-ccss))
1030 (setq value (get-char-attribute char name))
1031 (setq dest-ccss (cons name dest-ccss))))
1032 (char-db-insert-ccs-feature name value line-breaking))
1034 ((string-match "^=>ucs@" (symbol-name name))
1035 (insert (format "(%-18s . #x%04X)\t; %c%s"
1036 name value (decode-char '=ucs value)
1039 ((eq name 'jisx0208-1978/4X)
1040 (insert (format "(%-18s . #x%04X)%s"
1046 (not (eq name '->subsumptive))
1047 (not (eq name '->uppercase))
1048 (not (eq name '->lowercase))
1049 (not (eq name '->titlecase))
1050 (not (eq name '->canonical))
1051 (not (eq name '->Bopomofo))
1052 (not (eq name '->mistakable))
1053 (not (eq name '->ideographic-variants))
1054 (null (get-char-attribute
1055 char (intern (format "%s*sources" name))))
1056 (not (string-match "\\*sources$" (symbol-name name)))
1057 (null (get-char-attribute
1058 char (intern (format "%s*note" name))))
1059 (not (string-match "\\*note$" (symbol-name name)))
1060 (or (eq name '<-identical)
1061 (eq name '<-uppercase)
1062 (eq name '<-lowercase)
1063 (eq name '<-titlecase)
1064 (eq name '<-canonical)
1065 (eq name '<-ideographic-variants)
1066 ;; (eq name '<-synonyms)
1067 (string-match "^<-synonyms" (symbol-name name))
1068 (eq name '<-mistakable)
1069 (when (string-match "^->" (symbol-name name))
1071 ((string-match "^->fullwidth" (symbol-name name))
1072 (not (and (consp value)
1073 (characterp (car value))
1075 (car value) '=ucs 'defined-only)))
1080 ((or (eq name 'ideographic-structure)
1081 (eq name 'ideographic-combination)
1082 (eq name 'ideographic-)
1083 (eq name '=decomposition)
1084 (string-match "^=>decomposition" (symbol-name name))
1085 (string-match "^\\(->\\|<-\\)[^*]*$" (symbol-name name))
1086 (string-match "^\\(->\\|<-\\)[^*]*\\*sources$"
1089 (char-db-insert-relation-feature char name value
1092 ((memq name '(ideograph=
1093 original-ideograph-of
1094 ancient-ideograph-of
1097 ;; simplified-ideograph-of
1098 ideographic-variants
1099 ;; ideographic-different-form-of
1101 (insert (format "(%-18s%s " name line-breaking))
1102 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1104 (while (consp value)
1105 (setq cell (car value))
1106 (if (and (consp cell)
1111 (char-db-insert-alist cell readable)
1112 (setq separator lbs))
1115 (insert (prin1-to-string cell))
1116 (setq separator " "))
1117 (setq value (cdr value)))
1119 (insert line-breaking))
1121 (insert (format "(%-18s " name))
1122 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1124 (while (consp value)
1125 (setq cell (car value))
1126 (if (and (consp cell)
1128 (setq ret (condition-case nil
1136 (setq key (car (car rest)))
1137 (if (find-charset key)
1138 (setq cal (cons key cal))
1139 (setq al (cons key al)))
1140 (setq rest (cdr rest)))
1143 (insert-char-attributes ret
1146 (setq separator lbs))
1147 (setq ret (prin1-to-string cell))
1149 (if (< (+ (current-column)
1156 (setq separator " "))
1157 (setq value (cdr value)))
1159 (insert line-breaking))
1161 (insert (format "(%-18s" name))
1162 (setq ret (prin1-to-string value))
1163 (unless (< (+ (current-column)
1167 (insert line-breaking))
1168 (insert " . " ret ")" line-breaking)
1169 ;; (insert (format "(%-18s . %S)%s"
1174 (setq attributes (cdr attributes)))
1177 (defun insert-char-data (char &optional readable
1180 (narrow-to-region (point)(point))
1181 (insert "(define-char
1183 (insert-char-attributes char readable attributes)
1185 (goto-char (point-min))
1186 (while (re-search-forward "[ \t]+$" nil t)
1189 (goto-char (point-min))
1190 (while (re-search-forward "[ \t][ \t][ \t]*" nil t)
1191 (let ((column (current-column))
1192 (indent-tabs-mode t))
1193 (delete-region (match-beginning 0) (point))
1194 (indent-to column)))
1195 (goto-char (point-max))
1196 ;; (tabify (point-min)(point-max))
1199 (defun insert-char-data-with-variant (char &optional printable
1201 script excluded-script)
1202 (insert-char-data char printable)
1203 (let ((variants (char-variants char))
1206 (setq variants (sort variants #'<))
1207 (setq rest variants)
1208 (setq variants (cons char variants))
1210 (setq variant (car rest))
1211 (unless (get-char-attribute variant '<-subsumptive)
1212 (if (and (or (null script)
1213 (null (setq vs (get-char-attribute variant 'script)))
1215 (or (null excluded-script)
1216 (null (setq vs (get-char-attribute variant 'script)))
1217 (not (memq excluded-script vs))))
1218 (unless (and no-ucs-unified (get-char-attribute variant '=ucs))
1219 (insert-char-data variant printable)
1220 (if (setq ret (char-variants variant))
1222 (or (memq (car ret) variants)
1223 ;; (get-char-attribute (car ret) '<-subsumptive)
1224 (setq rest (nconc rest (list (car ret)))))
1225 (setq ret (cdr ret)))))))
1226 (setq rest (cdr rest)))))
1228 (defun insert-char-range-data (min max &optional script excluded-script)
1231 (while (<= code max)
1232 (setq char (decode-char '=ucs code))
1233 (if (encode-char char '=ucs 'defined-only)
1234 (insert-char-data-with-variant char nil 'no-ucs-unified
1235 script excluded-script))
1236 (setq code (1+ code)))))
1238 (defun write-char-range-data-to-file (min max file
1239 &optional script excluded-script)
1240 (let ((coding-system-for-write char-db-file-coding-system))
1242 (insert (format ";; -*- coding: %s -*-\n"
1243 char-db-file-coding-system))
1244 (insert-char-range-data min max script excluded-script)
1245 (write-region (point-min)(point-max) file))))
1247 (defvar what-character-original-window-configuration)
1250 (defun what-char-definition (char)
1251 (interactive (list (char-after)))
1252 (let ((buf (get-buffer-create "*Character Description*"))
1253 (the-buf (current-buffer))
1254 (win-conf (current-window-configuration)))
1256 (make-local-variable 'what-character-original-window-configuration)
1257 (setq what-character-original-window-configuration win-conf)
1258 (setq buffer-read-only nil)
1262 (insert-char-data-with-variant char 'printable)
1263 (unless (char-attribute-alist char)
1264 (insert (format ";; = %c\n"
1265 (let* ((rest (split-char char))
1269 (setq code (logior (lsh code 8)
1271 (decode-char ccs code)))))
1272 ;; (char-db-update-comment)
1273 (set-buffer-modified-p nil)
1274 (view-mode the-buf (lambda (buf)
1275 (set-window-configuration
1276 what-character-original-window-configuration)
1278 (goto-char (point-min)))
1280 (set-window-configuration
1281 what-character-original-window-configuration)
1282 (signal (car err) (cdr err)))))))
1288 (provide 'char-db-util)
1290 ;;; char-db-util.el ends here