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, 2011 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
201 ;;; @ char-db formatters
204 (defun char-db-make-char-spec (char)
206 (cond ((characterp char)
207 (cond ((and (setq ret (encode-char char '=ucs 'defined-only))
208 (not (and (<= #xE000 ret)(<= ret #xF8FF))))
209 (setq char-spec (list (cons '=ucs ret)))
210 (cond ((setq ret (get-char-attribute char 'name))
211 (setq char-spec (cons (cons 'name ret) char-spec))
213 ((setq ret (get-char-attribute char 'name*))
214 (setq char-spec (cons (cons 'name* ret) char-spec))
219 (let ((rest char-db-coded-charset-priority-list)
222 (setq ccs (charset-name
223 (find-charset (car rest))))
225 (encode-char char ccs
227 (throw 'tag (cons ccs ret)))
228 (setq rest (cdr rest))))))
229 (setq char-spec (list ret))
230 (dolist (ccs (delq (car ret) (charset-list)))
231 (if (and (or (charset-iso-final-char ccs)
238 (string-match "=ucs@" (symbol-name ccs)))
239 (setq ccs (charset-name ccs))
240 (null (assq ccs char-spec))
241 (setq ret (encode-char char ccs 'defined-only)))
242 (setq char-spec (cons (cons ccs ret) char-spec))))
244 (setq char-spec (split-char char)))
245 (cond ((setq ret (get-char-attribute char 'name))
246 (setq char-spec (cons (cons 'name ret) char-spec))
248 ((setq ret (get-char-attribute char 'name*))
249 (setq char-spec (cons (cons 'name* ret) char-spec))
252 ((setq ret (get-char-attribute
253 char 'ideographic-combination))
255 (cons (cons 'ideographic-combination ret)
262 (defun char-db-insert-char-spec (char &optional readable column
265 (setq column (current-column)))
266 (let (char-spec temp-char)
267 (setq char-spec (char-db-make-char-spec char))
268 (unless (or (characterp char) ; char
270 (setq char (find-char char-spec))
272 ;; define temporary character
273 ;; Current implementation is dirty.
274 (setq temp-char (define-char (cons '(ideograph-daikanwa . 0)
276 (remove-char-attribute temp-char 'ideograph-daikanwa)
277 (setq char temp-char))
278 (insert-char-attributes char
280 (union (mapcar #'car char-spec)
283 ;; undefine temporary character
284 ;; Current implementation is dirty.
285 (setq char-spec (char-attribute-alist temp-char))
287 (remove-char-attribute temp-char (car (car char-spec)))
288 (setq char-spec (cdr char-spec))))))
290 (defun char-db-insert-alist (alist &optional readable column)
292 (setq column (current-column)))
294 (concat "\n" (make-string (1+ column) ?\ )))
298 lbs cell rest separator)
301 (setq name (car (car alist))
302 value (cdr (car alist)))
303 (cond ((eq name 'char)
305 (if (setq ret (condition-case nil
313 (setq key (car (car value)))
314 ;; (if (find-charset key)
315 ;; (setq cal (cons key cal))
316 (setq al (cons key al))
318 (setq value (cdr value)))
319 (insert-char-attributes ret
323 (insert (prin1-to-string value)))
325 (insert line-breaking))
327 (insert (format "(%-18s " name))
328 (setq lbs (concat "\n" (make-string (current-column) ?\ )))
330 (setq cell (car value))
331 (if (and (consp cell)
333 (setq ret (condition-case nil
343 (setq key (car (car rest)))
344 ;; (if (find-charset key)
345 ;; (setq cal (cons key cal))
346 (setq al (cons key al))
348 (setq rest (cdr rest)))
351 (insert-char-attributes ret
355 (setq separator lbs))
358 (insert (prin1-to-string cell))
359 (setq separator " "))
360 (setq value (cdr value)))
362 (insert line-breaking))
364 (insert (format "(%-18s . %S)%s"
367 (setq alist (cdr alist))))
370 (defun char-db-insert-char-reference (plist &optional readable column)
372 (setq column (current-column)))
374 (concat "\n" (make-string (1+ column) ?\ )))
379 (setq name (pop plist))
380 (setq value (pop plist))
381 (cond ((eq name :char)
384 (cond ((numberp value)
385 (setq value (decode-char '=ucs value)))
387 ;; (setq value (or (find-char value)
390 (char-db-insert-char-spec value readable)
391 (insert line-breaking)
394 (insert (format "%s%s\t%d ; %c%s"
397 (ideographic-radical value)
401 (insert (format "%s%s\t%S" separator name value))
402 (setq separator line-breaking)))
406 (defun char-db-decode-isolated-char (ccs code-point)
409 (cond ((eq ccs 'arabic-iso8859-6)
410 (decode-char ccs code-point))
411 ((and (memq ccs '(=gt-pj-1
422 (setq ret (decode-char ccs code-point))
423 (setq ret (encode-char ret '=gt 'defined-only)))
424 (decode-builtin-char '=gt ret))
426 (decode-builtin-char ccs code-point))))
427 (cond ((and (<= 0 (char-int ret))
428 (<= (char-int ret) #x1F))
429 (decode-char '=ucs (+ #x2400 (char-int ret))))
430 ((= (char-int ret) #x7F)
434 (defvar char-db-convert-obsolete-format t)
436 (defun char-db-insert-ccs-feature (name value line-breaking)
439 (cond ((memq name '(=shinjigen
441 =shinjigen@rev =shinjigen/+p@rev))
442 "(%-18s . %04d)\t; %c")
443 ((eq name '=shinjigen@1ed/24pr)
444 "(%-18s . %04d)\t; %c")
445 ((or (memq name '(=daikanwa
446 =daikanwa@rev1 =daikanwa@rev2
447 =>>daikanwa =>daikanwa
448 =gt =>>gt =>gt =gt-k =>>gt-k =cbeta
449 =zinbun-oracle =>zinbun-oracle))
450 (string-match "^=adobe-" (symbol-name name)))
451 "(%-18s . %05d)\t; %c")
453 "(%-18s . %06d)\t; %c")
454 ((>= (charset-dimension name) 2)
455 "(%-18s . #x%04X)\t; %c")
457 "(%-18s . #x%02X)\t; %c"))
459 (if (= (charset-iso-graphic-plane name) 1)
461 (cond ((= (charset-dimension name) 1)
463 ((= (charset-dimension name) 2)
465 ((= (charset-dimension name) 3)
469 (char-db-decode-isolated-char name value)))
470 (if (and (= (charset-chars name) 94)
471 (= (charset-dimension name) 2))
472 (insert (format " [%02d-%02d]"
473 (- (lsh value -8) 32)
474 (- (logand value 255) 32))))
475 (insert line-breaking))
477 (defun char-db-insert-relation-feature (char name value line-breaking
479 (insert (format "(%-18s%s " name line-breaking))
480 (let ((lbs (concat "\n" (make-string (current-column) ?\ )))
481 separator cell sources required-features
484 (setq cell (car value))
486 (setq cell (decode-char '=ucs cell)))
488 ((eq name '->subsumptive)
489 (when (or (not (some (lambda (atr)
490 (get-char-attribute cell atr))
491 char-db-ignored-attributes))
493 (encode-char cell ccs 'defined-only))
497 (let ((char-db-ignored-attributes
499 char-db-ignored-attributes)))
500 (insert-char-attributes cell readable))
501 (setq separator lbs))
506 char (intern (format "%s*sources" name))))
507 (setq required-features nil)
508 (dolist (source sources)
512 shinjigen shinjigen@1ed shinjigen@rev))
513 (setq required-features
514 (union required-features
525 (setq required-features
526 (union required-features
531 ((find-charset (setq ret (intern (format "=%s" source))))
532 (setq required-features
533 (cons ret required-features)))
534 (t (setq required-features
535 (cons source required-features)))))
536 (cond ((string-match "@JP" (symbol-name name))
537 (setq required-features
538 (union required-features
546 ((string-match "@CN" (symbol-name name))
547 (setq required-features
548 (union required-features
555 (insert (format "%S" cell))
556 (char-db-insert-char-spec cell readable
559 (setq separator lbs))
563 (if (consp (car cell))
564 (char-db-insert-char-spec cell readable)
565 (char-db-insert-char-reference cell readable))
566 (setq separator lbs))
570 (insert (prin1-to-string cell))
571 (setq separator " ")))
572 (setq value (cdr value)))
574 (insert line-breaking)))
576 (defun insert-char-attributes (char &optional readable attributes column)
578 (setq column (current-column)))
579 (let (name value ; has-long-ccs-name
583 (concat "\n" (make-string (1+ column) ?\ )))
584 lbs cell separator ret
586 dest-ccss ; sources required-features
591 (if (consp attributes)
593 (dolist (name attributes)
594 (unless (memq name char-db-ignored-attributes)
595 (if (find-charset name)
599 (dolist (name (char-attribute-list))
600 (unless (memq name char-db-ignored-attributes)
601 (if (find-charset name)
605 #'char-attribute-name<)))
607 (when (memq '<-subsumptive attributes)
609 (when (setq value (get-char-attribute char '<-subsumptive))
610 (char-db-insert-relation-feature char '<-subsumptive value
613 (setq attributes (delq '<-subsumptive attributes)))
614 (when (and (memq '<-denotational attributes)
615 (setq value (get-char-attribute char '<-denotational)))
616 (char-db-insert-relation-feature char '<-denotational value
619 (setq attributes (delq '<-denotational attributes)))
620 (when (and (memq 'name attributes)
621 (setq value (get-char-attribute char 'name)))
623 (if (> (+ (current-column) (length value)) 48)
626 value line-breaking))
627 (setq attributes (delq 'name attributes))
629 (when (and (memq 'name* attributes)
630 (setq value (get-char-attribute char 'name*)))
632 (if (> (+ (current-column) (length value)) 48)
635 value line-breaking))
636 (setq attributes (delq 'name* attributes))
638 (when (and (memq 'script attributes)
639 (setq value (get-char-attribute char 'script)))
640 (insert (format "(script\t\t%s)%s"
641 (mapconcat (function prin1-to-string)
644 (setq attributes (delq 'script attributes))
646 (dolist (name '(=>ucs =>ucs*))
647 (when (and (memq name attributes)
648 (setq value (get-char-attribute char name)))
649 (insert (format "(%-18s . #x%04X)\t; %c%s"
650 name value (decode-char '=ucs value)
652 (setq attributes (delq name attributes))))
653 (dolist (name '(=>ucs@gb =>ucs@big5))
654 (when (and (memq name attributes)
655 (setq value (get-char-attribute char name)))
656 (insert (format "(%-18s . #x%04X)\t; %c%s"
661 (symbol-name name) 2)))
664 (setq attributes (delq name attributes))
666 ;; (dolist (name '(=>daikanwa))
667 ;; (when (and (memq name attributes)
668 ;; (setq value (get-char-attribute char name)))
670 ;; (if (integerp value)
671 ;; (format "(%-18s . %05d)\t; %c%s"
672 ;; name value (decode-char '=daikanwa value)
674 ;; (format "(%-18s %s)\t; %c%s"
676 ;; (mapconcat (function prin1-to-string)
678 ;; (char-representative-of-daikanwa char)
680 ;; (setq attributes (delq name attributes))))
681 (when (and (memq 'general-category attributes)
682 (setq value (get-char-attribute char 'general-category)))
684 "(general-category\t%s) ; %s%s"
685 (mapconcat (lambda (cell)
688 (cond ((rassoc value unidata-normative-category-alist)
689 "Normative Category")
690 ((rassoc value unidata-informative-category-alist)
691 "Informative Category")
695 (setq attributes (delq 'general-category attributes))
697 (when (and (memq 'bidi-category attributes)
698 (setq value (get-char-attribute char 'bidi-category)))
699 (insert (format "(bidi-category\t. %S)%s"
702 (setq attributes (delq 'bidi-category attributes))
704 (unless (or (not (memq 'mirrored attributes))
705 (eq (setq value (get-char-attribute char 'mirrored 'empty))
707 (insert (format "(mirrored\t\t. %S)%s"
710 (setq attributes (delq 'mirrored attributes))
713 ((and (memq 'decimal-digit-value attributes)
714 (setq value (get-char-attribute char 'decimal-digit-value)))
715 (insert (format "(decimal-digit-value . %S)%s"
718 (setq attributes (delq 'decimal-digit-value attributes))
719 (when (and (memq 'digit-value attributes)
720 (setq value (get-char-attribute char 'digit-value)))
721 (insert (format "(digit-value\t . %S)%s"
724 (setq attributes (delq 'digit-value attributes))
726 (when (and (memq 'numeric-value attributes)
727 (setq value (get-char-attribute char 'numeric-value)))
728 (insert (format "(numeric-value\t . %S)%s"
731 (setq attributes (delq 'numeric-value attributes))
735 (when (and (memq 'digit-value attributes)
736 (setq value (get-char-attribute char 'digit-value)))
737 (insert (format "(digit-value\t. %S)%s"
740 (setq attributes (delq 'digit-value attributes))
742 (when (and (memq 'numeric-value attributes)
743 (setq value (get-char-attribute char 'numeric-value)))
744 (insert (format "(numeric-value\t. %S)%s"
747 (setq attributes (delq 'numeric-value attributes))
749 (when (and (memq 'iso-10646-comment attributes)
750 (setq value (get-char-attribute char 'iso-10646-comment)))
751 (insert (format "(iso-10646-comment\t. %S)%s"
754 (setq attributes (delq 'iso-10646-comment attributes))
756 (when (and (memq 'morohashi-daikanwa attributes)
757 (setq value (get-char-attribute char 'morohashi-daikanwa)))
758 (insert (format "(morohashi-daikanwa\t%s)%s"
759 (mapconcat (function prin1-to-string) value " ")
761 (setq attributes (delq 'morohashi-daikanwa attributes))
765 (when (and (memq 'ideographic-radical attributes)
766 (setq value (get-char-attribute char 'ideographic-radical)))
768 (insert (format "(ideographic-radical . %S)\t; %c%s"
770 (ideographic-radical radical)
772 (setq attributes (delq 'ideographic-radical attributes))
774 (when (and (memq 'shuowen-radical attributes)
775 (setq value (get-char-attribute char 'shuowen-radical)))
776 (insert (format "(shuowen-radical\t. %S)\t; %c%s"
778 (shuowen-radical value)
780 (setq attributes (delq 'shuowen-radical attributes))
785 char-db-feature-domains
787 (dolist (feature (char-attribute-list))
788 (setq feature (symbol-name feature))
790 "\\(radical\\|strokes\\)@\\([^@*]+\\)\\(\\*\\|$\\)"
792 (setq domain (intern (match-string 2 feature)))
793 (unless (memq domain dest)
794 (setq dest (cons domain dest)))))
795 (sort dest #'string<))))
796 (setq key (intern (format "%s@%s" 'ideographic-radical domain)))
797 (when (and (memq key attributes)
798 (setq value (get-char-attribute char key)))
800 (insert (format "(%s . %S)\t; %c%s"
803 (ideographic-radical radical)
805 (setq attributes (delq key attributes))
807 (setq key (intern (format "%s@%s" 'ideographic-strokes domain)))
808 (when (and (memq key attributes)
809 (setq value (get-char-attribute char key)))
811 (insert (format "(%s . %S)%s"
815 (setq attributes (delq key attributes))
817 (setq key (intern (format "%s@%s" 'total-strokes domain)))
818 (when (and (memq key attributes)
819 (setq value (get-char-attribute char key)))
820 (insert (format "(%s . %S)%s"
824 (setq attributes (delq key attributes))
826 (dolist (feature '(ideographic-radical
829 (setq key (intern (format "%s@%s*sources" feature domain)))
830 (when (and (memq key attributes)
831 (setq value (get-char-attribute char key)))
832 (insert (format "(%s%s" key line-breaking))
834 (insert (format " %s" cell)))
836 (insert line-breaking)
837 (setq attributes (delq key attributes))
840 (when (and (memq 'ideographic-strokes attributes)
841 (setq value (get-char-attribute char 'ideographic-strokes)))
843 (insert (format "(ideographic-strokes . %S)%s"
846 (setq attributes (delq 'ideographic-strokes attributes))
848 (when (and (memq 'kangxi-radical attributes)
849 (setq value (get-char-attribute char 'kangxi-radical)))
850 (unless (eq value radical)
851 (insert (format "(kangxi-radical\t . %S)\t; %c%s"
853 (ideographic-radical value)
856 (setq radical value)))
857 (setq attributes (delq 'kangxi-radical attributes))
859 (when (and (memq 'kangxi-strokes attributes)
860 (setq value (get-char-attribute char 'kangxi-strokes)))
861 (unless (eq value strokes)
862 (insert (format "(kangxi-strokes\t . %S)%s"
866 (setq strokes value)))
867 (setq attributes (delq 'kangxi-strokes attributes))
869 (when (and (memq 'japanese-radical attributes)
870 (setq value (get-char-attribute char 'japanese-radical)))
871 (unless (eq value radical)
872 (insert (format "(japanese-radical\t . %S)\t; %c%s"
874 (ideographic-radical value)
877 (setq radical value)))
878 (setq attributes (delq 'japanese-radical attributes))
880 (when (and (memq 'japanese-strokes attributes)
881 (setq value (get-char-attribute char 'japanese-strokes)))
882 (unless (eq value strokes)
883 (insert (format "(japanese-strokes\t . %S)%s"
887 (setq strokes value)))
888 (setq attributes (delq 'japanese-strokes attributes))
890 (when (and (memq 'cns-radical attributes)
891 (setq value (get-char-attribute char 'cns-radical)))
892 (insert (format "(cns-radical\t . %S)\t; %c%s"
894 (ideographic-radical value)
896 (setq attributes (delq 'cns-radical attributes))
898 (when (and (memq 'cns-strokes attributes)
899 (setq value (get-char-attribute char 'cns-strokes)))
900 (unless (eq value strokes)
901 (insert (format "(cns-strokes\t . %S)%s"
905 (setq strokes value)))
906 (setq attributes (delq 'cns-strokes attributes))
908 (when (and (memq 'shinjigen-1-radical attributes)
909 (setq value (get-char-attribute char 'shinjigen-1-radical)))
910 (unless (eq value radical)
911 (insert (format "(shinjigen-1-radical . %S)\t; %c%s"
913 (ideographic-radical value)
916 (setq radical value)))
917 (setq attributes (delq 'shinjigen-1-radical attributes))
919 (when (and (memq 'ideographic- attributes)
920 (setq value (get-char-attribute char 'ideographic-)))
921 (insert "(ideographic- ")
922 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
925 (setq cell (car value))
927 (setq cell (decode-char '=ucs cell)))
928 (cond ((characterp cell)
932 (insert (format "%S" cell))
933 (char-db-insert-char-spec cell readable))
934 (setq separator lbs))
938 (if (consp (car cell))
939 (char-db-insert-char-spec cell readable)
940 (char-db-insert-char-reference cell readable))
941 (setq separator lbs))
945 (insert (prin1-to-string cell))
946 (setq separator " ")))
947 (setq value (cdr value)))
949 (insert line-breaking)
950 (setq attributes (delq 'ideographic- attributes)))
951 (when (and (memq 'total-strokes attributes)
952 (setq value (get-char-attribute char 'total-strokes)))
953 (insert (format "(total-strokes . %S)%s"
956 (setq attributes (delq 'total-strokes attributes))
958 (when (and (memq '->ideograph attributes)
959 (setq value (get-char-attribute char '->ideograph)))
960 (insert (format "(->ideograph\t%s)%s"
961 (mapconcat (lambda (code)
962 (cond ((symbolp code)
965 (format "#x%04X" code))
968 line-breaking code))))
971 (setq attributes (delq '->ideograph attributes))
973 ;; (when (and (memq '->decomposition attributes)
974 ;; (setq value (get-char-attribute char '->decomposition)))
975 ;; (insert (format "(->decomposition\t%s)%s"
976 ;; (mapconcat (lambda (code)
977 ;; (cond ((symbolp code)
978 ;; (symbol-name code))
979 ;; ((characterp code)
981 ;; (format "%S" code)
986 ;; (format "#x%04X" code))
988 ;; (format "%s%S" line-breaking code))))
991 ;; (setq attributes (delq '->decomposition attributes))
993 (if (equal (get-char-attribute char '->titlecase)
994 (get-char-attribute char '->uppercase))
995 (setq attributes (delq '->titlecase attributes)))
996 (when (and (memq '->mojikyo attributes)
997 (setq value (get-char-attribute char '->mojikyo)))
998 (insert (format "(->mojikyo\t\t. %06d)\t; %c%s"
999 value (decode-char 'mojikyo value)
1001 (setq attributes (delq '->mojikyo attributes))
1003 (when (and (memq 'hanyu-dazidian-vol attributes)
1004 (setq value (get-char-attribute char 'hanyu-dazidian-vol)))
1005 (insert (format "(hanyu-dazidian-vol . %d)%s"
1006 value line-breaking))
1007 (setq attributes (delq 'hanyu-dazidian-vol attributes))
1009 (when (and (memq 'hanyu-dazidian-page attributes)
1010 (setq value (get-char-attribute char 'hanyu-dazidian-page)))
1011 (insert (format "(hanyu-dazidian-page . %d)%s"
1012 value line-breaking))
1013 (setq attributes (delq 'hanyu-dazidian-page attributes))
1015 (when (and (memq 'hanyu-dazidian-char attributes)
1016 (setq value (get-char-attribute char 'hanyu-dazidian-char)))
1017 (insert (format "(hanyu-dazidian-char . %d)%s"
1018 value line-breaking))
1019 (setq attributes (delq 'hanyu-dazidian-char attributes))
1022 (dolist (ignored '(composition
1023 ->denotational <-subsumptive ->ucs-unified
1024 ->ideographic-component-forms))
1025 (setq attributes (delq ignored attributes))))
1027 (setq name (car attributes))
1028 (if (setq value (get-char-attribute char name))
1029 (cond ((setq ret (find-charset name))
1030 (setq name (charset-name ret))
1031 (if (and (not (memq name dest-ccss))
1033 (setq value (get-char-attribute char name))
1034 (setq dest-ccss (cons name dest-ccss))))
1035 (char-db-insert-ccs-feature name value line-breaking))
1037 ((string-match "^=>ucs@" (symbol-name name))
1038 (insert (format "(%-18s . #x%04X)\t; %c%s"
1039 name value (decode-char '=ucs value)
1042 ((eq name 'jisx0208-1978/4X)
1043 (insert (format "(%-18s . #x%04X)%s"
1049 (not (eq name '->subsumptive))
1050 (not (eq name '->uppercase))
1051 (not (eq name '->lowercase))
1052 (not (eq name '->titlecase))
1053 (not (eq name '->canonical))
1054 (not (eq name '->Bopomofo))
1055 (not (eq name '->mistakable))
1056 (not (eq name '->ideographic-variants))
1057 (null (get-char-attribute
1058 char (intern (format "%s*sources" name))))
1059 (not (string-match "\\*sources$" (symbol-name name)))
1060 (null (get-char-attribute
1061 char (intern (format "%s*note" name))))
1062 (not (string-match "\\*note$" (symbol-name name)))
1063 (or (eq name '<-identical)
1064 (eq name '<-uppercase)
1065 (eq name '<-lowercase)
1066 (eq name '<-titlecase)
1067 (eq name '<-canonical)
1068 (eq name '<-ideographic-variants)
1069 ;; (eq name '<-synonyms)
1070 (string-match "^<-synonyms" (symbol-name name))
1071 (eq name '<-mistakable)
1072 (when (string-match "^->" (symbol-name name))
1074 ((string-match "^->fullwidth" (symbol-name name))
1075 (not (and (consp value)
1076 (characterp (car value))
1078 (car value) '=ucs 'defined-only)))
1083 ((or (eq name 'ideographic-structure)
1084 (eq name 'ideographic-combination)
1085 (eq name 'ideographic-)
1086 (eq name '=decomposition)
1087 (string-match "^=>decomposition" (symbol-name name))
1088 (string-match "^\\(->\\|<-\\)[^*]*$" (symbol-name name))
1089 (string-match "^\\(->\\|<-\\)[^*]*\\*sources$"
1092 (char-db-insert-relation-feature char name value
1095 ((memq name '(ideograph=
1096 original-ideograph-of
1097 ancient-ideograph-of
1100 ;; simplified-ideograph-of
1101 ideographic-variants
1102 ;; ideographic-different-form-of
1104 (insert (format "(%-18s%s " name line-breaking))
1105 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1107 (while (consp value)
1108 (setq cell (car value))
1109 (if (and (consp cell)
1114 (char-db-insert-alist cell readable)
1115 (setq separator lbs))
1118 (insert (prin1-to-string cell))
1119 (setq separator " "))
1120 (setq value (cdr value)))
1122 (insert line-breaking))
1124 (insert (format "(%-18s " name))
1125 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1127 (while (consp value)
1128 (setq cell (car value))
1129 (if (and (consp cell)
1131 (setq ret (condition-case nil
1139 (setq key (car (car rest)))
1140 (if (find-charset key)
1141 (setq cal (cons key cal))
1142 (setq al (cons key al)))
1143 (setq rest (cdr rest)))
1146 (insert-char-attributes ret
1149 (setq separator lbs))
1150 (setq ret (prin1-to-string cell))
1152 (if (< (+ (current-column)
1159 (setq separator " "))
1160 (setq value (cdr value)))
1162 (insert line-breaking))
1164 (insert (format "(%-18s" name))
1165 (setq ret (prin1-to-string value))
1166 (unless (< (+ (current-column)
1170 (insert line-breaking))
1171 (insert " . " ret ")" line-breaking)
1172 ;; (insert (format "(%-18s . %S)%s"
1177 (setq attributes (cdr attributes)))
1180 (defun insert-char-data (char &optional readable
1183 (narrow-to-region (point)(point))
1184 (insert "(define-char
1186 (insert-char-attributes char readable attributes)
1188 (goto-char (point-min))
1189 (while (re-search-forward "[ \t]+$" nil t)
1192 (goto-char (point-min))
1193 (while (re-search-forward "[ \t][ \t][ \t]*" nil t)
1194 (let ((column (current-column))
1195 (indent-tabs-mode t))
1196 (delete-region (match-beginning 0) (point))
1197 (indent-to column)))
1198 (goto-char (point-max))
1199 ;; (tabify (point-min)(point-max))
1202 (defun insert-char-data-with-variant (char &optional printable
1204 script excluded-script)
1205 (insert-char-data char printable)
1206 (let ((variants (char-variants char))
1209 (setq variants (sort variants #'<))
1210 (setq rest variants)
1211 (setq variants (cons char variants))
1213 (setq variant (car rest))
1214 (unless (get-char-attribute variant '<-subsumptive)
1215 (if (and (or (null script)
1216 (null (setq vs (get-char-attribute variant 'script)))
1218 (or (null excluded-script)
1219 (null (setq vs (get-char-attribute variant 'script)))
1220 (not (memq excluded-script vs))))
1221 (unless (and no-ucs-unified (get-char-attribute variant '=ucs))
1222 (insert-char-data variant printable)
1223 (if (setq ret (char-variants variant))
1225 (or (memq (car ret) variants)
1226 ;; (get-char-attribute (car ret) '<-subsumptive)
1227 (setq rest (nconc rest (list (car ret)))))
1228 (setq ret (cdr ret)))))))
1229 (setq rest (cdr rest)))))
1231 (defun insert-char-range-data (min max &optional script excluded-script)
1234 (while (<= code max)
1235 (setq char (decode-char '=ucs code))
1236 (if (encode-char char '=ucs 'defined-only)
1237 (insert-char-data-with-variant char nil 'no-ucs-unified
1238 script excluded-script))
1239 (setq code (1+ code)))))
1241 (defun write-char-range-data-to-file (min max file
1242 &optional script excluded-script)
1243 (let ((coding-system-for-write char-db-file-coding-system))
1245 (insert (format ";; -*- coding: %s -*-\n"
1246 char-db-file-coding-system))
1247 (insert-char-range-data min max script excluded-script)
1248 (write-region (point-min)(point-max) file))))
1250 (defvar what-character-original-window-configuration)
1253 (defun what-char-definition (char)
1254 (interactive (list (char-after)))
1255 (let ((buf (get-buffer-create "*Character Description*"))
1256 (the-buf (current-buffer))
1257 (win-conf (current-window-configuration)))
1259 (make-local-variable 'what-character-original-window-configuration)
1260 (setq what-character-original-window-configuration win-conf)
1261 (setq buffer-read-only nil)
1265 (insert-char-data-with-variant char 'printable)
1266 (unless (char-attribute-alist char)
1267 (insert (format ";; = %c\n"
1268 (let* ((rest (split-char char))
1272 (setq code (logior (lsh code 8)
1274 (decode-char ccs code)))))
1275 ;; (char-db-update-comment)
1276 (set-buffer-modified-p nil)
1277 (view-mode the-buf (lambda (buf)
1278 (set-window-configuration
1279 what-character-original-window-configuration)
1281 (goto-char (point-min)))
1283 (set-window-configuration
1284 what-character-original-window-configuration)
1285 (signal (car err) (cdr err)))))))
1291 (provide 'char-db-util)
1293 ;;; char-db-util.el ends here