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 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
100 (defun shuowen-radical (number)
101 (aref shuowen-radicals (1- number)))
103 (defvar char-db-file-coding-system 'utf-8-mcs-er)
105 (defvar char-db-feature-domains
106 '(ucs ucs/compat daikanwa cns gt jis jis/alt jis/a jis/b
107 jis-x0212 jis-x0213 cdp shinjigen misc unknown))
109 (defvar char-db-ignored-attributes '(ideographic-products))
111 (defun char-attribute-name< (ka kb)
113 ((eq '->denotational kb)
115 ((eq '->subsumptive kb)
116 (not (eq '->denotational ka)))
117 ((eq '->denotational ka)
119 ((eq '->subsumptive ka)
122 (string-match "^->" (symbol-name ka)))
123 (cond ((and (symbolp kb)
124 (string-match "^->" (symbol-name kb)))
125 (string< (symbol-name ka)
130 (string-match "^->" (symbol-name kb)))
133 (string-match "^<-" (symbol-name ka)))
135 (cond ((string-match "^<-" (symbol-name kb))
136 (string< (symbol-name ka)
139 ;; ((string-match "^->" (symbol-name kb))
144 (string-match "^<-" (symbol-name kb)))
146 ;; (not (string-match "^->" (symbol-name ka)))
149 (if (find-charset kb)
150 (if (<= (charset-id ka) 1)
151 (if (<= (charset-id kb) 1)
153 ((= (charset-dimension ka)
154 (charset-dimension kb))
155 (> (charset-id ka)(charset-id kb)))
157 (> (charset-dimension ka)
158 (charset-dimension kb))
161 (if (<= (charset-id kb) 1)
163 (< (charset-id ka)(charset-id kb))))
169 (string< (symbol-name ka)
175 (defvar char-db-coded-charset-priority-list
236 (defun char-db-make-char-spec (char)
238 (cond ((characterp char)
239 (cond ((and (setq ret (encode-char char '=ucs 'defined-only))
240 (not (and (<= #xE000 ret)(<= ret #xF8FF))))
241 (setq char-spec (list (cons '=ucs ret)))
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))
251 (let ((rest char-db-coded-charset-priority-list)
254 (setq ccs (charset-name
255 (find-charset (car rest))))
257 (encode-char char ccs
259 (throw 'tag (cons ccs ret)))
260 (setq rest (cdr rest))))))
261 (setq char-spec (list ret))
262 (dolist (ccs (delq (car ret) (charset-list)))
263 (if (and (or (charset-iso-final-char ccs)
270 (setq ccs (charset-name ccs))
271 (null (assq ccs char-spec))
272 (setq ret (encode-char char ccs 'defined-only)))
273 (setq char-spec (cons (cons ccs ret) char-spec))))
275 (setq char-spec (split-char char)))
276 (cond ((setq ret (get-char-attribute char 'name))
277 (setq char-spec (cons (cons 'name ret) char-spec))
279 ((setq ret (get-char-attribute char 'name*))
280 (setq char-spec (cons (cons 'name* ret) char-spec))
287 (defun char-db-insert-char-spec (char &optional readable column
290 (setq column (current-column)))
291 (let (char-spec temp-char)
292 (setq char-spec (char-db-make-char-spec char))
293 (unless (or (characterp char) ; char
295 (setq char (find-char char-spec))
297 ;; define temporary character
298 ;; Current implementation is dirty.
299 (setq temp-char (define-char (cons '(ideograph-daikanwa . 0)
301 (remove-char-attribute temp-char 'ideograph-daikanwa)
302 (setq char temp-char))
303 (insert-char-attributes char
305 (union (mapcar #'car char-spec)
308 ;; undefine temporary character
309 ;; Current implementation is dirty.
310 (setq char-spec (char-attribute-alist temp-char))
312 (remove-char-attribute temp-char (car (car char-spec)))
313 (setq char-spec (cdr char-spec))))))
315 (defun char-db-insert-alist (alist &optional readable column)
317 (setq column (current-column)))
319 (concat "\n" (make-string (1+ column) ?\ )))
323 lbs cell rest separator)
326 (setq name (car (car alist))
327 value (cdr (car alist)))
328 (cond ((eq name 'char)
330 (if (setq ret (condition-case nil
338 (setq key (car (car value)))
339 ;; (if (find-charset key)
340 ;; (setq cal (cons key cal))
341 (setq al (cons key al))
343 (setq value (cdr value)))
344 (insert-char-attributes ret
348 (insert (prin1-to-string value)))
350 (insert line-breaking))
352 (insert (format "(%-18s " name))
353 (setq lbs (concat "\n" (make-string (current-column) ?\ )))
355 (setq cell (car value))
356 (if (and (consp cell)
358 (setq ret (condition-case nil
368 (setq key (car (car rest)))
369 ;; (if (find-charset key)
370 ;; (setq cal (cons key cal))
371 (setq al (cons key al))
373 (setq rest (cdr rest)))
376 (insert-char-attributes ret
380 (setq separator lbs))
383 (insert (prin1-to-string cell))
384 (setq separator " "))
385 (setq value (cdr value)))
387 (insert line-breaking))
389 (insert (format "(%-18s . %S)%s"
392 (setq alist (cdr alist))))
395 (defun char-db-insert-char-reference (plist &optional readable column)
397 (setq column (current-column)))
399 (concat "\n" (make-string (1+ column) ?\ )))
404 (setq name (pop plist))
405 (setq value (pop plist))
406 (cond ((eq name :char)
409 (cond ((numberp value)
410 (setq value (decode-char '=ucs value)))
412 ;; (setq value (or (find-char value)
415 (char-db-insert-char-spec value readable)
416 (insert line-breaking)
419 (insert (format "%s%s\t%d ; %c%s"
422 (ideographic-radical value)
426 (insert (format "%s%s\t%S" separator name value))
427 (setq separator line-breaking)))
431 (defun char-db-decode-isolated-char (ccs code-point)
434 (cond ((eq ccs 'arabic-iso8859-6)
435 (decode-char ccs code-point))
436 ((and (memq ccs '(=gt-pj-1
447 (setq ret (decode-char ccs code-point))
448 (setq ret (encode-char ret '=gt 'defined-only)))
449 (decode-builtin-char '=gt ret))
451 (decode-builtin-char ccs code-point))))
452 (cond ((and (<= 0 (char-int ret))
453 (<= (char-int ret) #x1F))
454 (decode-char '=ucs (+ #x2400 (char-int ret))))
455 ((= (char-int ret) #x7F)
459 (defvar char-db-convert-obsolete-format t)
461 (defun char-db-insert-ccs-feature (name value line-breaking)
464 (cond ((or (memq name '(=daikanwa
465 =daikanwa@rev1 =daikanwa@rev2
466 =gt =gt-k =cbeta =zinbun-oracle))
467 (string-match "^=adobe-" (symbol-name name)))
468 "(%-18s . %05d)\t; %c")
470 "(%-18s . %06d)\t; %c")
471 ((>= (charset-dimension name) 2)
472 "(%-18s . #x%04X)\t; %c")
474 "(%-18s . #x%02X)\t; %c"))
476 (if (= (charset-iso-graphic-plane name) 1)
478 (cond ((= (charset-dimension name) 1)
480 ((= (charset-dimension name) 2)
482 ((= (charset-dimension name) 3)
486 (char-db-decode-isolated-char name value)))
487 (if (and (= (charset-chars name) 94)
488 (= (charset-dimension name) 2))
489 (insert (format " [%02d-%02d]"
490 (- (lsh value -8) 32)
491 (- (logand value 255) 32))))
492 (insert line-breaking))
494 (defun char-db-insert-relation-feature (char name value line-breaking
496 (insert (format "(%-18s%s " name line-breaking))
497 (let ((lbs (concat "\n" (make-string (current-column) ?\ )))
498 separator cell sources required-features
501 (setq cell (car value))
503 (setq cell (decode-char '=ucs cell)))
505 ((eq name '->subsumptive)
506 (when (or (not (some (lambda (atr)
507 (get-char-attribute cell atr))
508 char-db-ignored-attributes))
510 (encode-char cell ccs 'defined-only))
514 (let ((char-db-ignored-attributes
516 char-db-ignored-attributes)))
517 (insert-char-attributes cell readable))
518 (setq separator lbs))
523 char (intern (format "%s*sources" name))))
524 (setq required-features nil)
525 (dolist (source sources)
527 ((memq source '(JP JP/Jouyou shinjigen-1))
528 (setq required-features
529 (union required-features
538 (setq required-features
539 (union required-features
544 ((find-charset (setq ret (intern (format "=%s" source))))
545 (setq required-features
546 (cons ret required-features)))
547 (t (setq required-features
548 (cons source required-features)))))
549 (cond ((string-match "@JP" (symbol-name name))
550 (setq required-features
551 (union required-features
559 ((string-match "@CN" (symbol-name name))
560 (setq required-features
561 (union required-features
568 (insert (format "%S" cell))
569 (char-db-insert-char-spec cell readable
572 (setq separator lbs))
576 (if (consp (car cell))
577 (char-db-insert-char-spec cell readable)
578 (char-db-insert-char-reference cell readable))
579 (setq separator lbs))
583 (insert (prin1-to-string cell))
584 (setq separator " ")))
585 (setq value (cdr value)))
587 (insert line-breaking)))
589 (defun insert-char-attributes (char &optional readable attributes column)
591 (setq column (current-column)))
592 (let (name value ; has-long-ccs-name
596 (concat "\n" (make-string (1+ column) ?\ )))
597 lbs cell separator ret
599 dest-ccss ; sources required-features
604 (if (consp attributes)
606 (dolist (name attributes)
607 (unless (memq name char-db-ignored-attributes)
608 (if (find-charset name)
612 (dolist (name (char-attribute-list))
613 (unless (memq name char-db-ignored-attributes)
614 (if (find-charset name)
618 #'char-attribute-name<)))
620 (when (memq '<-subsumptive attributes)
622 (when (setq value (get-char-attribute char '<-subsumptive))
623 (char-db-insert-relation-feature char '<-subsumptive value
626 (setq attributes (delq '<-subsumptive attributes)))
627 (when (and (memq '<-denotational attributes)
628 (setq value (get-char-attribute char '<-denotational)))
629 (char-db-insert-relation-feature char '<-denotational value
632 (setq attributes (delq '<-denotational attributes)))
633 (when (and (memq 'name attributes)
634 (setq value (get-char-attribute char 'name)))
636 (if (> (+ (current-column) (length value)) 48)
639 value line-breaking))
640 (setq attributes (delq 'name attributes))
642 (when (and (memq 'name* attributes)
643 (setq value (get-char-attribute char 'name*)))
645 (if (> (+ (current-column) (length value)) 48)
648 value line-breaking))
649 (setq attributes (delq 'name* attributes))
651 (when (and (memq 'script attributes)
652 (setq value (get-char-attribute char 'script)))
653 (insert (format "(script\t\t%s)%s"
654 (mapconcat (function prin1-to-string)
657 (setq attributes (delq 'script attributes))
659 (dolist (name '(=>ucs =>ucs*))
660 (when (and (memq name attributes)
661 (setq value (get-char-attribute char name)))
662 (insert (format "(%-18s . #x%04X)\t; %c%s"
663 name value (decode-char '=ucs value)
665 (setq attributes (delq name attributes))))
666 (dolist (name '(=>ucs@gb =>ucs@cns =>ucs@jis =>ucs@ks =>ucs@big5))
667 (when (and (memq name attributes)
668 (setq value (get-char-attribute char name)))
669 (insert (format "(%-18s . #x%04X)\t; %c%s"
674 (symbol-name name) 2)))
677 (setq attributes (delq name attributes))
679 (dolist (name '(=>daikanwa))
680 (when (and (memq name attributes)
681 (setq value (get-char-attribute char name)))
684 (format "(%-18s . %05d)\t; %c%s"
685 name value (decode-char '=daikanwa value)
687 (format "(%-18s %s)\t; %c%s"
689 (mapconcat (function prin1-to-string)
691 (char-representative-of-daikanwa char)
693 (setq attributes (delq name attributes))))
694 (when (and (memq 'general-category attributes)
695 (setq value (get-char-attribute char 'general-category)))
697 "(general-category\t%s) ; %s%s"
698 (mapconcat (lambda (cell)
701 (cond ((rassoc value unidata-normative-category-alist)
702 "Normative Category")
703 ((rassoc value unidata-informative-category-alist)
704 "Informative Category")
708 (setq attributes (delq 'general-category attributes))
710 (when (and (memq 'bidi-category attributes)
711 (setq value (get-char-attribute char 'bidi-category)))
712 (insert (format "(bidi-category\t. %S)%s"
715 (setq attributes (delq 'bidi-category attributes))
717 (unless (or (not (memq 'mirrored attributes))
718 (eq (setq value (get-char-attribute char 'mirrored 'empty))
720 (insert (format "(mirrored\t\t. %S)%s"
723 (setq attributes (delq 'mirrored attributes))
726 ((and (memq 'decimal-digit-value attributes)
727 (setq value (get-char-attribute char 'decimal-digit-value)))
728 (insert (format "(decimal-digit-value . %S)%s"
731 (setq attributes (delq 'decimal-digit-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))
748 (when (and (memq 'digit-value attributes)
749 (setq value (get-char-attribute char 'digit-value)))
750 (insert (format "(digit-value\t. %S)%s"
753 (setq attributes (delq 'digit-value attributes))
755 (when (and (memq 'numeric-value attributes)
756 (setq value (get-char-attribute char 'numeric-value)))
757 (insert (format "(numeric-value\t. %S)%s"
760 (setq attributes (delq 'numeric-value attributes))
762 (when (and (memq 'iso-10646-comment attributes)
763 (setq value (get-char-attribute char 'iso-10646-comment)))
764 (insert (format "(iso-10646-comment\t. %S)%s"
767 (setq attributes (delq 'iso-10646-comment attributes))
769 (when (and (memq 'morohashi-daikanwa attributes)
770 (setq value (get-char-attribute char 'morohashi-daikanwa)))
771 (insert (format "(morohashi-daikanwa\t%s)%s"
772 (mapconcat (function prin1-to-string) value " ")
774 (setq attributes (delq 'morohashi-daikanwa attributes))
778 (when (and (memq 'ideographic-radical attributes)
779 (setq value (get-char-attribute char 'ideographic-radical)))
781 (insert (format "(ideographic-radical . %S)\t; %c%s"
783 (ideographic-radical radical)
785 (setq attributes (delq 'ideographic-radical attributes))
787 (when (and (memq 'shuowen-radical attributes)
788 (setq value (get-char-attribute char 'shuowen-radical)))
789 (insert (format "(shuowen-radical\t. %S)\t; %c%s"
791 (shuowen-radical value)
793 (setq attributes (delq 'shuowen-radical attributes))
798 char-db-feature-domains
800 (dolist (feature (char-attribute-list))
801 (setq feature (symbol-name feature))
803 "\\(radical\\|strokes\\)@\\([^@*]+\\)\\(\\*\\|$\\)"
805 (setq domain (intern (match-string 2 feature)))
806 (unless (memq domain dest)
807 (setq dest (cons domain dest)))))
808 (sort dest #'string<))))
809 (setq key (intern (format "%s@%s" 'ideographic-radical domain)))
810 (when (and (memq key attributes)
811 (setq value (get-char-attribute char key)))
813 (insert (format "(%s . %S)\t; %c%s"
816 (ideographic-radical radical)
818 (setq attributes (delq key attributes))
820 (setq key (intern (format "%s@%s" 'ideographic-strokes domain)))
821 (when (and (memq key attributes)
822 (setq value (get-char-attribute char key)))
824 (insert (format "(%s . %S)%s"
828 (setq attributes (delq key attributes))
830 (setq key (intern (format "%s@%s" 'total-strokes domain)))
831 (when (and (memq key attributes)
832 (setq value (get-char-attribute char key)))
833 (insert (format "(%s . %S)%s"
837 (setq attributes (delq key attributes))
839 (dolist (feature '(ideographic-radical
842 (setq key (intern (format "%s@%s*sources" feature domain)))
843 (when (and (memq key attributes)
844 (setq value (get-char-attribute char key)))
845 (insert (format "(%s%s" key line-breaking))
847 (insert (format " %s" cell)))
849 (insert line-breaking)
850 (setq attributes (delq key attributes))
853 (when (and (memq 'ideographic-strokes attributes)
854 (setq value (get-char-attribute char 'ideographic-strokes)))
856 (insert (format "(ideographic-strokes . %S)%s"
859 (setq attributes (delq 'ideographic-strokes attributes))
861 (when (and (memq 'kangxi-radical attributes)
862 (setq value (get-char-attribute char 'kangxi-radical)))
863 (unless (eq value radical)
864 (insert (format "(kangxi-radical\t . %S)\t; %c%s"
866 (ideographic-radical value)
869 (setq radical value)))
870 (setq attributes (delq 'kangxi-radical attributes))
872 (when (and (memq 'kangxi-strokes attributes)
873 (setq value (get-char-attribute char 'kangxi-strokes)))
874 (unless (eq value strokes)
875 (insert (format "(kangxi-strokes\t . %S)%s"
879 (setq strokes value)))
880 (setq attributes (delq 'kangxi-strokes attributes))
882 (when (and (memq 'japanese-radical attributes)
883 (setq value (get-char-attribute char 'japanese-radical)))
884 (unless (eq value radical)
885 (insert (format "(japanese-radical\t . %S)\t; %c%s"
887 (ideographic-radical value)
890 (setq radical value)))
891 (setq attributes (delq 'japanese-radical attributes))
893 (when (and (memq 'japanese-strokes attributes)
894 (setq value (get-char-attribute char 'japanese-strokes)))
895 (unless (eq value strokes)
896 (insert (format "(japanese-strokes\t . %S)%s"
900 (setq strokes value)))
901 (setq attributes (delq 'japanese-strokes attributes))
903 (when (and (memq 'cns-radical attributes)
904 (setq value (get-char-attribute char 'cns-radical)))
905 (insert (format "(cns-radical\t . %S)\t; %c%s"
907 (ideographic-radical value)
909 (setq attributes (delq 'cns-radical attributes))
911 (when (and (memq 'cns-strokes attributes)
912 (setq value (get-char-attribute char 'cns-strokes)))
913 (unless (eq value strokes)
914 (insert (format "(cns-strokes\t . %S)%s"
918 (setq strokes value)))
919 (setq attributes (delq 'cns-strokes attributes))
921 (when (and (memq 'shinjigen-1-radical attributes)
922 (setq value (get-char-attribute char 'shinjigen-1-radical)))
923 (unless (eq value radical)
924 (insert (format "(shinjigen-1-radical . %S)\t; %c%s"
926 (ideographic-radical value)
929 (setq radical value)))
930 (setq attributes (delq 'shinjigen-1-radical attributes))
932 (when (and (memq 'ideographic- attributes)
933 (setq value (get-char-attribute char 'ideographic-)))
934 (insert "(ideographic- ")
935 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
938 (setq cell (car value))
940 (setq cell (decode-char '=ucs cell)))
941 (cond ((characterp cell)
945 (insert (format "%S" cell))
946 (char-db-insert-char-spec cell readable))
947 (setq separator lbs))
951 (if (consp (car cell))
952 (char-db-insert-char-spec cell readable)
953 (char-db-insert-char-reference cell readable))
954 (setq separator lbs))
958 (insert (prin1-to-string cell))
959 (setq separator " ")))
960 (setq value (cdr value)))
962 (insert line-breaking)
963 (setq attributes (delq 'ideographic- attributes)))
964 (when (and (memq 'total-strokes attributes)
965 (setq value (get-char-attribute char 'total-strokes)))
966 (insert (format "(total-strokes . %S)%s"
969 (setq attributes (delq 'total-strokes attributes))
971 (when (and (memq '->ideograph attributes)
972 (setq value (get-char-attribute char '->ideograph)))
973 (insert (format "(->ideograph\t%s)%s"
974 (mapconcat (lambda (code)
975 (cond ((symbolp code)
978 (format "#x%04X" code))
981 line-breaking code))))
984 (setq attributes (delq '->ideograph attributes))
986 ;; (when (and (memq '->decomposition attributes)
987 ;; (setq value (get-char-attribute char '->decomposition)))
988 ;; (insert (format "(->decomposition\t%s)%s"
989 ;; (mapconcat (lambda (code)
990 ;; (cond ((symbolp code)
991 ;; (symbol-name code))
992 ;; ((characterp code)
994 ;; (format "%S" code)
999 ;; (format "#x%04X" code))
1001 ;; (format "%s%S" line-breaking code))))
1004 ;; (setq attributes (delq '->decomposition attributes))
1006 (if (equal (get-char-attribute char '->titlecase)
1007 (get-char-attribute char '->uppercase))
1008 (setq attributes (delq '->titlecase attributes)))
1009 (when (and (memq '->mojikyo attributes)
1010 (setq value (get-char-attribute char '->mojikyo)))
1011 (insert (format "(->mojikyo\t\t. %06d)\t; %c%s"
1012 value (decode-char 'mojikyo value)
1014 (setq attributes (delq '->mojikyo attributes))
1016 (when (and (memq 'hanyu-dazidian-vol attributes)
1017 (setq value (get-char-attribute char 'hanyu-dazidian-vol)))
1018 (insert (format "(hanyu-dazidian-vol . %d)%s"
1019 value line-breaking))
1020 (setq attributes (delq 'hanyu-dazidian-vol attributes))
1022 (when (and (memq 'hanyu-dazidian-page attributes)
1023 (setq value (get-char-attribute char 'hanyu-dazidian-page)))
1024 (insert (format "(hanyu-dazidian-page . %d)%s"
1025 value line-breaking))
1026 (setq attributes (delq 'hanyu-dazidian-page attributes))
1028 (when (and (memq 'hanyu-dazidian-char attributes)
1029 (setq value (get-char-attribute char 'hanyu-dazidian-char)))
1030 (insert (format "(hanyu-dazidian-char . %d)%s"
1031 value line-breaking))
1032 (setq attributes (delq 'hanyu-dazidian-char attributes))
1035 (dolist (ignored '(composition
1036 ->denotational <-subsumptive ->ucs-unified
1037 ->ideographic-component-forms))
1038 (setq attributes (delq ignored attributes))))
1040 (setq name (car attributes))
1041 (if (setq value (get-char-attribute char name))
1042 (cond ((setq ret (find-charset name))
1043 (setq name (charset-name ret))
1044 (if (and (not (memq name dest-ccss))
1046 (setq value (get-char-attribute char name))
1047 (setq dest-ccss (cons name dest-ccss))))
1048 (char-db-insert-ccs-feature name value line-breaking))
1050 ((string-match "^=>ucs@" (symbol-name name))
1051 (insert (format "(%-18s . #x%04X)\t; %c%s"
1052 name value (decode-char '=ucs value)
1055 ((eq name 'jisx0208-1978/4X)
1056 (insert (format "(%-18s . #x%04X)%s"
1062 (not (eq name '->subsumptive))
1063 (not (eq name '->uppercase))
1064 (not (eq name '->lowercase))
1065 (not (eq name '->titlecase))
1066 (not (eq name '->canonical))
1067 (not (eq name '->Bopomofo))
1068 (not (eq name '->mistakable))
1069 (not (eq name '->ideographic-variants))
1070 (null (get-char-attribute
1071 char (intern (format "%s*sources" name))))
1072 (not (string-match "\\*sources$" (symbol-name name)))
1073 (null (get-char-attribute
1074 char (intern (format "%s*note" name))))
1075 (not (string-match "\\*note$" (symbol-name name)))
1076 (or (eq name '<-identical)
1077 (eq name '<-uppercase)
1078 (eq name '<-lowercase)
1079 (eq name '<-titlecase)
1080 (eq name '<-canonical)
1081 (eq name '<-ideographic-variants)
1082 ;; (eq name '<-synonyms)
1083 (string-match "^<-synonyms" (symbol-name name))
1084 (eq name '<-mistakable)
1085 (when (string-match "^->" (symbol-name name))
1087 ((string-match "^->fullwidth" (symbol-name name))
1088 (not (and (consp value)
1089 (characterp (car value))
1091 (car value) '=ucs 'defined-only)))
1096 ((or (eq name 'ideographic-structure)
1097 (eq name 'ideographic-combination)
1098 (eq name 'ideographic-)
1099 (eq name '=decomposition)
1100 (string-match "^=>decomposition" (symbol-name name))
1101 (string-match "^\\(->\\|<-\\)[^*]*$" (symbol-name name))
1102 (string-match "^\\(->\\|<-\\)[^*]*\\*sources$"
1105 (char-db-insert-relation-feature char name value
1108 ((memq name '(ideograph=
1109 original-ideograph-of
1110 ancient-ideograph-of
1113 ;; simplified-ideograph-of
1114 ideographic-variants
1115 ;; ideographic-different-form-of
1117 (insert (format "(%-18s%s " name line-breaking))
1118 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1120 (while (consp value)
1121 (setq cell (car value))
1122 (if (and (consp cell)
1127 (char-db-insert-alist cell readable)
1128 (setq separator lbs))
1131 (insert (prin1-to-string cell))
1132 (setq separator " "))
1133 (setq value (cdr value)))
1135 (insert line-breaking))
1137 (insert (format "(%-18s " name))
1138 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1140 (while (consp value)
1141 (setq cell (car value))
1142 (if (and (consp cell)
1144 (setq ret (condition-case nil
1152 (setq key (car (car rest)))
1153 (if (find-charset key)
1154 (setq cal (cons key cal))
1155 (setq al (cons key al)))
1156 (setq rest (cdr rest)))
1159 (insert-char-attributes ret
1162 (setq separator lbs))
1163 (setq ret (prin1-to-string cell))
1165 (if (< (+ (current-column)
1172 (setq separator " "))
1173 (setq value (cdr value)))
1175 (insert line-breaking))
1177 (insert (format "(%-18s" name))
1178 (setq ret (prin1-to-string value))
1179 (unless (< (+ (current-column)
1183 (insert line-breaking))
1184 (insert " . " ret ")" line-breaking)
1185 ;; (insert (format "(%-18s . %S)%s"
1190 (setq attributes (cdr attributes)))
1193 (defun insert-char-data (char &optional readable
1196 (narrow-to-region (point)(point))
1197 (insert "(define-char
1199 (insert-char-attributes char readable attributes)
1201 (goto-char (point-min))
1202 (while (re-search-forward "[ \t]+$" nil t)
1205 (goto-char (point-min))
1206 (while (re-search-forward "[ \t][ \t][ \t]*" nil t)
1207 (let ((column (current-column))
1208 (indent-tabs-mode t))
1209 (delete-region (match-beginning 0) (point))
1210 (indent-to column)))
1211 (goto-char (point-max))
1212 ;; (tabify (point-min)(point-max))
1215 (defun insert-char-data-with-variant (char &optional printable
1217 script excluded-script)
1218 (insert-char-data char printable)
1219 (let ((variants (char-variants char))
1222 (setq variants (sort variants #'<))
1223 (setq rest variants)
1224 (setq variants (cons char variants))
1226 (setq variant (car rest))
1227 (unless (get-char-attribute variant '<-subsumptive)
1228 (if (and (or (null script)
1229 (null (setq vs (get-char-attribute variant 'script)))
1231 (or (null excluded-script)
1232 (null (setq vs (get-char-attribute variant 'script)))
1233 (not (memq excluded-script vs))))
1234 (unless (and no-ucs-unified (get-char-attribute variant '=ucs))
1235 (insert-char-data variant printable)
1236 (if (setq ret (char-variants variant))
1238 (or (memq (car ret) variants)
1239 ;; (get-char-attribute (car ret) '<-subsumptive)
1240 (setq rest (nconc rest (list (car ret)))))
1241 (setq ret (cdr ret)))))))
1242 (setq rest (cdr rest)))))
1244 (defun insert-char-range-data (min max &optional script excluded-script)
1247 (while (<= code max)
1248 (setq char (decode-char '=ucs code))
1249 (if (encode-char char '=ucs 'defined-only)
1250 (insert-char-data-with-variant char nil 'no-ucs-unified
1251 script excluded-script))
1252 (setq code (1+ code)))))
1254 (defun write-char-range-data-to-file (min max file
1255 &optional script excluded-script)
1256 (let ((coding-system-for-write char-db-file-coding-system))
1258 (insert (format ";; -*- coding: %s -*-\n"
1259 char-db-file-coding-system))
1260 (insert-char-range-data min max script excluded-script)
1261 (write-region (point-min)(point-max) file))))
1263 (defvar what-character-original-window-configuration)
1266 (defun what-char-definition (char)
1267 (interactive (list (char-after)))
1268 (let ((buf (get-buffer-create "*Character Description*"))
1269 (the-buf (current-buffer))
1270 (win-conf (current-window-configuration)))
1272 (make-local-variable 'what-character-original-window-configuration)
1273 (setq what-character-original-window-configuration win-conf)
1274 (setq buffer-read-only nil)
1278 (insert-char-data-with-variant char 'printable)
1279 (unless (char-attribute-alist char)
1280 (insert (format ";; = %c\n"
1281 (let* ((rest (split-char char))
1285 (setq code (logior (lsh code 8)
1287 (decode-char ccs code)))))
1288 ;; (char-db-update-comment)
1289 (set-buffer-modified-p nil)
1290 (view-mode the-buf (lambda (buf)
1291 (set-window-configuration
1292 what-character-original-window-configuration)
1294 (goto-char (point-min)))
1296 (set-window-configuration
1297 what-character-original-window-configuration)
1298 (signal (car err) (cdr err)))))))
1300 (provide 'char-db-util)
1302 ;;; char-db-util.el ends here