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
230 ;;; @ char-db formatters
233 (defun char-db-make-char-spec (char)
235 (cond ((characterp char)
236 (cond ((and (setq ret (encode-char char '=ucs 'defined-only))
237 (not (and (<= #xE000 ret)(<= ret #xF8FF))))
238 (setq char-spec (list (cons '=ucs ret)))
239 (cond ((setq ret (get-char-attribute char 'name))
240 (setq char-spec (cons (cons 'name ret) char-spec))
242 ((setq ret (get-char-attribute char 'name*))
243 (setq char-spec (cons (cons 'name* ret) char-spec))
248 (let ((rest char-db-coded-charset-priority-list)
251 (setq ccs (charset-name
252 (find-charset (car rest))))
254 (encode-char char ccs
256 (throw 'tag (cons ccs ret)))
257 (setq rest (cdr rest))))))
258 (setq char-spec (list ret))
259 (dolist (ccs (delq (car ret) (charset-list)))
260 (if (and (or (charset-iso-final-char ccs)
267 (string-match "=ucs@" (symbol-name ccs)))
268 (setq ccs (charset-name ccs))
269 (null (assq ccs char-spec))
270 (setq ret (encode-char char ccs 'defined-only)))
271 (setq char-spec (cons (cons ccs ret) char-spec))))
273 (setq char-spec (split-char char)))
274 (cond ((setq ret (get-char-attribute char 'name))
275 (setq char-spec (cons (cons 'name ret) char-spec))
277 ((setq ret (get-char-attribute char 'name*))
278 (setq char-spec (cons (cons 'name* ret) char-spec))
281 ((setq ret (get-char-attribute
282 char 'ideographic-combination))
284 (cons (cons 'ideographic-combination ret)
291 (defun char-db-insert-char-spec (char &optional readable column
294 (setq column (current-column)))
295 (let (char-spec temp-char)
296 (setq char-spec (char-db-make-char-spec char))
297 (unless (or (characterp char) ; char
299 (setq char (find-char char-spec))
301 ;; define temporary character
302 ;; Current implementation is dirty.
303 (setq temp-char (define-char (cons '(ideograph-daikanwa . 0)
305 (remove-char-attribute temp-char 'ideograph-daikanwa)
306 (setq char temp-char))
307 (insert-char-attributes char
309 (union (mapcar #'car char-spec)
313 ;; undefine temporary character
314 ;; Current implementation is dirty.
315 (setq char-spec (char-attribute-alist temp-char))
317 (remove-char-attribute temp-char (car (car char-spec)))
318 (setq char-spec (cdr char-spec))))))
320 (defun char-db-insert-alist (alist &optional readable column)
322 (setq column (current-column)))
324 (concat "\n" (make-string (1+ column) ?\ )))
328 lbs cell rest separator)
331 (setq name (car (car alist))
332 value (cdr (car alist)))
333 (cond ((eq name 'char)
335 (if (setq ret (condition-case nil
343 (setq key (car (car value)))
344 ;; (if (find-charset key)
345 ;; (setq cal (cons key cal))
346 (setq al (cons key al))
348 (setq value (cdr value)))
349 (insert-char-attributes ret
353 (insert (prin1-to-string value)))
355 (insert line-breaking))
357 (insert (format "(%-18s " name))
358 (setq lbs (concat "\n" (make-string (current-column) ?\ )))
360 (setq cell (car value))
361 (if (and (consp cell)
363 (setq ret (condition-case nil
373 (setq key (car (car rest)))
374 ;; (if (find-charset key)
375 ;; (setq cal (cons key cal))
376 (setq al (cons key al))
378 (setq rest (cdr rest)))
381 (insert-char-attributes ret
385 (setq separator lbs))
388 (insert (prin1-to-string cell))
389 (setq separator " "))
390 (setq value (cdr value)))
392 (insert line-breaking))
394 (insert (format "(%-18s . %S)%s"
397 (setq alist (cdr alist))))
400 (defun char-db-insert-char-reference (plist &optional readable column)
402 (setq column (current-column)))
404 (concat "\n" (make-string (1+ column) ?\ )))
409 (setq name (pop plist))
410 (setq value (pop plist))
411 (cond ((eq name :char)
414 (cond ((numberp value)
415 (setq value (decode-char '=ucs value)))
417 ;; (setq value (or (find-char value)
420 (char-db-insert-char-spec value readable)
421 (insert line-breaking)
424 (insert (format "%s%s\t%d ; %c%s"
427 (ideographic-radical value)
431 (insert (format "%s%s\t%S" separator name value))
432 (setq separator line-breaking)))
436 (defun char-db-decode-isolated-char (ccs code-point)
439 (cond ((eq ccs 'arabic-iso8859-6)
440 (decode-char ccs code-point))
441 ((and (memq ccs '(=gt-pj-1
452 (setq ret (decode-char ccs code-point))
453 (setq ret (encode-char ret '=gt 'defined-only)))
454 (decode-builtin-char '=gt ret))
456 (decode-builtin-char ccs code-point))))
457 (cond ((and (<= 0 (char-int ret))
458 (<= (char-int ret) #x1F))
459 (decode-char '=ucs (+ #x2400 (char-int ret))))
460 ((= (char-int ret) #x7F)
464 (defvar char-db-convert-obsolete-format t)
466 (defun char-db-insert-ccs-feature (name value line-breaking)
472 ((memq name '(=shinjigen
474 =shinjigen@rev =shinjigen/+p@rev
476 "(%-18s . %04d)\t; %c")
477 ((eq name '=shinjigen@1ed/24pr)
478 "(%-18s . %04d)\t; %c")
479 ((or (memq name '(=daikanwa =>>daikanwa =>daikanwa
480 =daikanwa@rev1 =daikanwa@rev2
481 =daikanwa/+p =daikanwa/+2p
482 =gt =>>>gt =>>gt =>gt
486 =zinbun-oracle =>zinbun-oracle))
487 (string-match "^=adobe-" (symbol-name name)))
488 "(%-18s . %05d)\t; %c")
489 ((memq name '(=hanyo-denshi/ks =>>hanyo-denshi/ks mojikyo))
490 "(%-18s . %06d)\t; %c")
491 ((>= (charset-dimension name) 2)
492 "(%-18s . #x%04X)\t; %c")
494 "(%-18s . #x%02X)\t; %c"))
496 (if (= (charset-iso-graphic-plane name) 1)
498 (cond ((= (charset-dimension name) 1)
500 ((= (charset-dimension name) 2)
502 ((= (charset-dimension name) 3)
506 (char-db-decode-isolated-char name value)))
507 (if (and (= (charset-chars name) 94)
508 (= (charset-dimension name) 2))
509 (insert (format " [%02d-%02d]"
510 (- (lsh value -8) 32)
511 (- (logand value 255) 32))))
514 (insert (format "(%-18s . %s)" name value))
516 (insert line-breaking))
518 (defun char-db-insert-relation-feature (char name value line-breaking
520 (insert (format "(%-18s%s " name line-breaking))
521 (let ((lbs (concat "\n" (make-string (current-column) ?\ )))
522 separator cell sources required-features
525 (setq cell (car value))
527 (setq cell (decode-char '=ucs cell)))
529 ((eq name '->subsumptive)
530 (when (or (not (some (lambda (atr)
531 (get-char-attribute cell atr))
532 char-db-ignored-attributes))
534 (encode-char cell ccs 'defined-only))
538 (let ((char-db-ignored-attributes
540 char-db-ignored-attributes)))
541 (insert-char-attributes cell readable nil nil 'for-sub-node))
542 (setq separator lbs))
547 char (intern (format "%s*sources" name))))
548 (setq required-features nil)
549 (dolist (source sources)
553 shinjigen shinjigen@1ed shinjigen@rev))
554 (setq required-features
555 (union required-features
566 (setq required-features
567 (union required-features
572 ((find-charset (setq ret (intern (format "=%s" source))))
573 (setq required-features
574 (cons ret required-features)))
575 (t (setq required-features
576 (cons source required-features)))))
577 (cond ((string-match "@JP" (symbol-name name))
578 (setq required-features
579 (union required-features
587 ((string-match "@CN" (symbol-name name))
588 (setq required-features
589 (union required-features
596 (insert (format "%S" cell))
597 (char-db-insert-char-spec cell readable
600 (setq separator lbs))
604 (if (consp (car cell))
605 (char-db-insert-char-spec cell readable)
606 (char-db-insert-char-reference cell readable))
607 (setq separator lbs))
611 (insert (prin1-to-string cell))
612 (setq separator " ")))
613 (setq value (cdr value)))
615 (insert line-breaking)))
617 (defun insert-char-attributes (char &optional readable attributes column
620 (setq column (current-column)))
621 (let (name value ; has-long-ccs-name
625 (concat "\n" (make-string (1+ column) ?\ )))
626 lbs cell separator ret
628 dest-ccss ; sources required-features
633 (if (consp attributes)
635 (dolist (name attributes)
636 (unless (memq name char-db-ignored-attributes)
637 (if (find-charset name)
641 (dolist (name (char-attribute-list))
642 (unless (memq name char-db-ignored-attributes)
643 (if (find-charset name)
647 #'char-attribute-name<)))
649 (when (memq '<-subsumptive attributes)
650 (when (or readable (not for-sub-node))
651 (when (setq value (get-char-attribute char '<-subsumptive))
652 (char-db-insert-relation-feature char '<-subsumptive value
655 (setq attributes (delq '<-subsumptive attributes)))
656 (when (and (memq '<-denotational attributes)
657 (setq value (get-char-attribute char '<-denotational)))
658 (char-db-insert-relation-feature char '<-denotational value
661 (setq attributes (delq '<-denotational attributes)))
662 (when (and (memq 'name attributes)
663 (setq value (get-char-attribute char 'name)))
665 (if (> (+ (current-column) (length value)) 48)
668 value line-breaking))
669 (setq attributes (delq 'name attributes))
671 (when (and (memq 'name* attributes)
672 (setq value (get-char-attribute char 'name*)))
674 (if (> (+ (current-column) (length value)) 48)
677 value line-breaking))
678 (setq attributes (delq 'name* attributes))
680 (when (and (memq 'script attributes)
681 (setq value (get-char-attribute char 'script)))
682 (insert (format "(script\t\t%s)%s"
683 (mapconcat (function prin1-to-string)
686 (setq attributes (delq 'script attributes))
688 (dolist (name '(=>ucs =>ucs*))
689 (when (and (memq name attributes)
690 (setq value (get-char-attribute char name)))
691 (insert (format "(%-18s . #x%04X)\t; %c%s"
692 name value (decode-char '=ucs value)
694 (setq attributes (delq name attributes))))
695 (dolist (name '(=>ucs@gb =>ucs@big5))
696 (when (and (memq name attributes)
697 (setq value (get-char-attribute char name)))
698 (insert (format "(%-18s . #x%04X)\t; %c%s"
703 (symbol-name name) 2)))
706 (setq attributes (delq name attributes))
708 ;; (dolist (name '(=>daikanwa))
709 ;; (when (and (memq name attributes)
710 ;; (setq value (get-char-attribute char name)))
712 ;; (if (integerp value)
713 ;; (format "(%-18s . %05d)\t; %c%s"
714 ;; name value (decode-char '=daikanwa value)
716 ;; (format "(%-18s %s)\t; %c%s"
718 ;; (mapconcat (function prin1-to-string)
720 ;; (char-representative-of-daikanwa char)
722 ;; (setq attributes (delq name attributes))))
723 (when (and (memq 'general-category attributes)
724 (setq value (get-char-attribute char 'general-category)))
726 "(general-category\t%s) ; %s%s"
727 (mapconcat (lambda (cell)
730 (cond ((rassoc value unidata-normative-category-alist)
731 "Normative Category")
732 ((rassoc value unidata-informative-category-alist)
733 "Informative Category")
737 (setq attributes (delq 'general-category attributes))
739 (when (and (memq 'bidi-category attributes)
740 (setq value (get-char-attribute char 'bidi-category)))
741 (insert (format "(bidi-category\t. %S)%s"
744 (setq attributes (delq 'bidi-category attributes))
746 (unless (or (not (memq 'mirrored attributes))
747 (eq (setq value (get-char-attribute char 'mirrored 'empty))
749 (insert (format "(mirrored\t\t. %S)%s"
752 (setq attributes (delq 'mirrored attributes))
755 ((and (memq 'decimal-digit-value attributes)
756 (setq value (get-char-attribute char 'decimal-digit-value)))
757 (insert (format "(decimal-digit-value . %S)%s"
760 (setq attributes (delq 'decimal-digit-value attributes))
761 (when (and (memq 'digit-value attributes)
762 (setq value (get-char-attribute char 'digit-value)))
763 (insert (format "(digit-value\t . %S)%s"
766 (setq attributes (delq 'digit-value attributes))
768 (when (and (memq 'numeric-value attributes)
769 (setq value (get-char-attribute char 'numeric-value)))
770 (insert (format "(numeric-value\t . %S)%s"
773 (setq attributes (delq 'numeric-value attributes))
777 (when (and (memq 'digit-value attributes)
778 (setq value (get-char-attribute char 'digit-value)))
779 (insert (format "(digit-value\t. %S)%s"
782 (setq attributes (delq 'digit-value attributes))
784 (when (and (memq 'numeric-value attributes)
785 (setq value (get-char-attribute char 'numeric-value)))
786 (insert (format "(numeric-value\t. %S)%s"
789 (setq attributes (delq 'numeric-value attributes))
791 (when (and (memq 'iso-10646-comment attributes)
792 (setq value (get-char-attribute char 'iso-10646-comment)))
793 (insert (format "(iso-10646-comment\t. %S)%s"
796 (setq attributes (delq 'iso-10646-comment attributes))
798 (when (and (memq 'morohashi-daikanwa attributes)
799 (setq value (get-char-attribute char 'morohashi-daikanwa)))
800 (insert (format "(morohashi-daikanwa\t%s)%s"
801 (mapconcat (function prin1-to-string) value " ")
803 (setq attributes (delq 'morohashi-daikanwa attributes))
807 (when (and (memq 'ideographic-radical attributes)
808 (setq value (get-char-attribute char 'ideographic-radical)))
810 (insert (format "(ideographic-radical . %S)\t; %c%s"
812 (ideographic-radical radical)
814 (setq attributes (delq 'ideographic-radical attributes))
816 (when (and (memq 'shuowen-radical attributes)
817 (setq value (get-char-attribute char 'shuowen-radical)))
818 (insert (format "(shuowen-radical\t. %S)\t; %c%s"
820 (shuowen-radical value)
822 (setq attributes (delq 'shuowen-radical attributes))
827 char-db-feature-domains
829 (dolist (feature (char-attribute-list))
830 (setq feature (symbol-name feature))
832 "\\(radical\\|strokes\\)@\\([^@*]+\\)\\(\\*\\|$\\)"
834 (setq domain (intern (match-string 2 feature)))
835 (unless (memq domain dest)
836 (setq dest (cons domain dest)))))
837 (sort dest #'string<))))
838 (setq key (intern (format "%s@%s" 'ideographic-radical domain)))
839 (when (and (memq key attributes)
840 (setq value (get-char-attribute char key)))
842 (insert (format "(%s . %S)\t; %c%s"
845 (ideographic-radical radical)
847 (setq attributes (delq key attributes))
849 (setq key (intern (format "%s@%s" 'ideographic-strokes domain)))
850 (when (and (memq key attributes)
851 (setq value (get-char-attribute char key)))
853 (insert (format "(%s . %S)%s"
857 (setq attributes (delq key attributes))
859 (setq key (intern (format "%s@%s" 'total-strokes domain)))
860 (when (and (memq key attributes)
861 (setq value (get-char-attribute char key)))
862 (insert (format "(%s . %S)%s"
866 (setq attributes (delq key attributes))
868 (dolist (feature '(ideographic-radical
871 (setq key (intern (format "%s@%s*sources" feature domain)))
872 (when (and (memq key attributes)
873 (setq value (get-char-attribute char key)))
874 (insert (format "(%s%s" key line-breaking))
876 (insert (format " %s" cell)))
878 (insert line-breaking)
879 (setq attributes (delq key attributes))
882 (when (and (memq 'ideographic-strokes attributes)
883 (setq value (get-char-attribute char 'ideographic-strokes)))
885 (insert (format "(ideographic-strokes . %S)%s"
888 (setq attributes (delq 'ideographic-strokes attributes))
890 (when (and (memq 'kangxi-radical attributes)
891 (setq value (get-char-attribute char 'kangxi-radical)))
892 (unless (eq value radical)
893 (insert (format "(kangxi-radical\t . %S)\t; %c%s"
895 (ideographic-radical value)
898 (setq radical value)))
899 (setq attributes (delq 'kangxi-radical attributes))
901 (when (and (memq 'kangxi-strokes attributes)
902 (setq value (get-char-attribute char 'kangxi-strokes)))
903 (unless (eq value strokes)
904 (insert (format "(kangxi-strokes\t . %S)%s"
908 (setq strokes value)))
909 (setq attributes (delq 'kangxi-strokes attributes))
911 (when (and (memq 'japanese-radical attributes)
912 (setq value (get-char-attribute char 'japanese-radical)))
913 (unless (eq value radical)
914 (insert (format "(japanese-radical\t . %S)\t; %c%s"
916 (ideographic-radical value)
919 (setq radical value)))
920 (setq attributes (delq 'japanese-radical attributes))
922 (when (and (memq 'japanese-strokes attributes)
923 (setq value (get-char-attribute char 'japanese-strokes)))
924 (unless (eq value strokes)
925 (insert (format "(japanese-strokes\t . %S)%s"
929 (setq strokes value)))
930 (setq attributes (delq 'japanese-strokes attributes))
932 (when (and (memq 'cns-radical attributes)
933 (setq value (get-char-attribute char 'cns-radical)))
934 (insert (format "(cns-radical\t . %S)\t; %c%s"
936 (ideographic-radical value)
938 (setq attributes (delq 'cns-radical attributes))
940 (when (and (memq 'cns-strokes attributes)
941 (setq value (get-char-attribute char 'cns-strokes)))
942 (unless (eq value strokes)
943 (insert (format "(cns-strokes\t . %S)%s"
947 (setq strokes value)))
948 (setq attributes (delq 'cns-strokes attributes))
950 (when (and (memq 'shinjigen-1-radical attributes)
951 (setq value (get-char-attribute char 'shinjigen-1-radical)))
952 (unless (eq value radical)
953 (insert (format "(shinjigen-1-radical . %S)\t; %c%s"
955 (ideographic-radical value)
958 (setq radical value)))
959 (setq attributes (delq 'shinjigen-1-radical attributes))
961 (when (and (memq 'ideographic- attributes)
962 (setq value (get-char-attribute char 'ideographic-)))
963 (insert "(ideographic- ")
964 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
967 (setq cell (car value))
969 (setq cell (decode-char '=ucs cell)))
970 (cond ((characterp cell)
974 (insert (format "%S" cell))
975 (char-db-insert-char-spec cell readable))
976 (setq separator lbs))
980 (if (consp (car cell))
981 (char-db-insert-char-spec cell readable)
982 (char-db-insert-char-reference cell readable))
983 (setq separator lbs))
987 (insert (prin1-to-string cell))
988 (setq separator " ")))
989 (setq value (cdr value)))
991 (insert line-breaking)
992 (setq attributes (delq 'ideographic- attributes)))
993 (when (and (memq 'total-strokes attributes)
994 (setq value (get-char-attribute char 'total-strokes)))
995 (insert (format "(total-strokes . %S)%s"
998 (setq attributes (delq 'total-strokes attributes))
1000 (when (and (memq '->ideograph attributes)
1001 (setq value (get-char-attribute char '->ideograph)))
1002 (insert (format "(->ideograph\t%s)%s"
1003 (mapconcat (lambda (code)
1004 (cond ((symbolp code)
1007 (format "#x%04X" code))
1010 line-breaking code))))
1013 (setq attributes (delq '->ideograph attributes))
1015 ;; (when (and (memq '->decomposition attributes)
1016 ;; (setq value (get-char-attribute char '->decomposition)))
1017 ;; (insert (format "(->decomposition\t%s)%s"
1018 ;; (mapconcat (lambda (code)
1019 ;; (cond ((symbolp code)
1020 ;; (symbol-name code))
1021 ;; ((characterp code)
1023 ;; (format "%S" code)
1028 ;; (format "#x%04X" code))
1030 ;; (format "%s%S" line-breaking code))))
1033 ;; (setq attributes (delq '->decomposition attributes))
1035 (if (equal (get-char-attribute char '->titlecase)
1036 (get-char-attribute char '->uppercase))
1037 (setq attributes (delq '->titlecase attributes)))
1038 (when (and (memq '->mojikyo attributes)
1039 (setq value (get-char-attribute char '->mojikyo)))
1040 (insert (format "(->mojikyo\t\t. %06d)\t; %c%s"
1041 value (decode-char 'mojikyo value)
1043 (setq attributes (delq '->mojikyo attributes))
1045 (when (and (memq 'hanyu-dazidian-vol attributes)
1046 (setq value (get-char-attribute char 'hanyu-dazidian-vol)))
1047 (insert (format "(hanyu-dazidian-vol . %d)%s"
1048 value line-breaking))
1049 (setq attributes (delq 'hanyu-dazidian-vol attributes))
1051 (when (and (memq 'hanyu-dazidian-page attributes)
1052 (setq value (get-char-attribute char 'hanyu-dazidian-page)))
1053 (insert (format "(hanyu-dazidian-page . %d)%s"
1054 value line-breaking))
1055 (setq attributes (delq 'hanyu-dazidian-page attributes))
1057 (when (and (memq 'hanyu-dazidian-char attributes)
1058 (setq value (get-char-attribute char 'hanyu-dazidian-char)))
1059 (insert (format "(hanyu-dazidian-char . %d)%s"
1060 value line-breaking))
1061 (setq attributes (delq 'hanyu-dazidian-char attributes))
1064 (dolist (ignored '(composition
1065 ->denotational <-subsumptive ->ucs-unified
1066 ->ideographic-component-forms))
1067 (setq attributes (delq ignored attributes))))
1069 (setq name (car attributes))
1070 (unless (eq (setq value (get-char-attribute char name 'value-is-empty))
1072 (cond ((setq ret (find-charset name))
1073 (setq name (charset-name ret))
1074 (when (not (memq name dest-ccss))
1075 (setq dest-ccss (cons name dest-ccss))
1076 (char-db-insert-ccs-feature name value line-breaking))
1078 ((string-match "^=>ucs@" (symbol-name name))
1079 (insert (format "(%-18s . #x%04X)\t; %c%s"
1080 name value (decode-char '=ucs value)
1083 ((eq name 'jisx0208-1978/4X)
1084 (insert (format "(%-18s . #x%04X)%s"
1090 (not (eq name '->subsumptive))
1091 (not (eq name '->uppercase))
1092 (not (eq name '->lowercase))
1093 (not (eq name '->titlecase))
1094 (not (eq name '->canonical))
1095 (not (eq name '->Bopomofo))
1096 (not (eq name '->mistakable))
1097 (not (eq name '->ideographic-variants))
1098 (null (get-char-attribute
1099 char (intern (format "%s*sources" name))))
1100 (not (string-match "\\*sources$" (symbol-name name)))
1101 (null (get-char-attribute
1102 char (intern (format "%s*note" name))))
1103 (not (string-match "\\*note$" (symbol-name name)))
1104 (or (eq name '<-identical)
1105 (eq name '<-uppercase)
1106 (eq name '<-lowercase)
1107 (eq name '<-titlecase)
1108 (eq name '<-canonical)
1109 (eq name '<-ideographic-variants)
1110 ;; (eq name '<-synonyms)
1111 (string-match "^<-synonyms" (symbol-name name))
1112 (eq name '<-mistakable)
1113 (when (string-match "^->" (symbol-name name))
1115 ((string-match "^->fullwidth" (symbol-name name))
1116 (not (and (consp value)
1117 (characterp (car value))
1119 (car value) '=ucs 'defined-only)))
1124 ((or (eq name 'ideographic-structure)
1125 (eq name 'ideographic-combination)
1126 (eq name 'ideographic-)
1127 (eq name '=decomposition)
1128 (char-feature-base-name= '=decomposition name)
1129 (char-feature-base-name= '=>decomposition name)
1130 ;; (string-match "^=>*decomposition\\(@[^*]+\\)?$"
1131 ;; (symbol-name name))
1132 (string-match "^\\(->\\|<-\\)[^*]*$" (symbol-name name))
1133 (string-match "^\\(->\\|<-\\)[^*]*\\*sources$"
1136 (char-db-insert-relation-feature char name value
1139 ((memq name '(ideograph=
1140 original-ideograph-of
1141 ancient-ideograph-of
1144 ;; simplified-ideograph-of
1145 ideographic-variants
1146 ;; ideographic-different-form-of
1148 (insert (format "(%-18s%s " name line-breaking))
1149 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1151 (while (consp value)
1152 (setq cell (car value))
1153 (if (and (consp cell)
1158 (char-db-insert-alist cell readable)
1159 (setq separator lbs))
1162 (insert (prin1-to-string cell))
1163 (setq separator " "))
1164 (setq value (cdr value)))
1166 (insert line-breaking))
1168 (insert (format "(%-18s " name))
1169 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1171 (while (consp value)
1172 (setq cell (car value))
1173 (if (and (consp cell)
1175 (setq ret (condition-case nil
1183 (setq key (car (car rest)))
1184 (if (find-charset key)
1185 (setq cal (cons key cal))
1186 (setq al (cons key al)))
1187 (setq rest (cdr rest)))
1190 (insert-char-attributes ret
1194 (setq separator lbs))
1195 (setq ret (prin1-to-string cell))
1197 (if (< (+ (current-column)
1204 (setq separator " "))
1205 (setq value (cdr value)))
1207 (insert line-breaking))
1209 (insert (format "(%-18s" name))
1210 (setq ret (prin1-to-string value))
1211 (unless (< (+ (current-column)
1215 (insert line-breaking))
1216 (insert " . " ret ")" line-breaking)
1217 ;; (insert (format "(%-18s . %S)%s"
1222 (setq attributes (cdr attributes)))
1225 (defun insert-char-data (char &optional readable
1228 (narrow-to-region (point)(point))
1229 (insert "(define-char
1231 (insert-char-attributes char readable attributes)
1233 (goto-char (point-min))
1234 (while (re-search-forward "[ \t]+$" nil t)
1237 (goto-char (point-min))
1238 (while (re-search-forward "[ \t][ \t][ \t]*" nil t)
1239 (let ((column (current-column))
1240 (indent-tabs-mode t))
1241 (delete-region (match-beginning 0) (point))
1242 (indent-to column)))
1243 (goto-char (point-max))
1244 ;; (tabify (point-min)(point-max))
1247 (defun insert-char-data-with-variant (char &optional printable
1249 script excluded-script)
1250 (insert-char-data char printable)
1251 (let ((variants (char-variants char))
1254 (setq variants (sort variants #'<))
1255 (setq rest variants)
1256 (setq variants (cons char variants))
1258 (setq variant (car rest))
1259 (unless (get-char-attribute variant '<-subsumptive)
1260 (if (and (or (null script)
1261 (null (setq vs (get-char-attribute variant 'script)))
1263 (or (null excluded-script)
1264 (null (setq vs (get-char-attribute variant 'script)))
1265 (not (memq excluded-script vs))))
1266 (unless (and no-ucs-unified (get-char-attribute variant '=ucs))
1267 (insert-char-data variant printable)
1268 (if (setq ret (char-variants variant))
1270 (or (memq (car ret) variants)
1271 ;; (get-char-attribute (car ret) '<-subsumptive)
1272 (setq rest (nconc rest (list (car ret)))))
1273 (setq ret (cdr ret)))))))
1274 (setq rest (cdr rest)))))
1276 (defun insert-char-range-data (min max &optional script excluded-script)
1279 (while (<= code max)
1280 (setq char (decode-char '=ucs code))
1281 (if (encode-char char '=ucs 'defined-only)
1282 (insert-char-data-with-variant char nil 'no-ucs-unified
1283 script excluded-script))
1284 (setq code (1+ code)))))
1286 (defun write-char-range-data-to-file (min max file
1287 &optional script excluded-script)
1288 (let ((coding-system-for-write char-db-file-coding-system))
1290 (insert (format ";; -*- coding: %s -*-\n"
1291 char-db-file-coding-system))
1292 (insert-char-range-data min max script excluded-script)
1293 (write-region (point-min)(point-max) file))))
1295 (defvar what-character-original-window-configuration)
1298 (defun what-char-definition (char)
1299 (interactive (list (char-after)))
1300 (let ((buf (get-buffer-create "*Character Description*"))
1301 (the-buf (current-buffer))
1302 (win-conf (current-window-configuration)))
1304 (make-local-variable 'what-character-original-window-configuration)
1305 (setq what-character-original-window-configuration win-conf)
1306 (setq buffer-read-only nil)
1310 (insert-char-data-with-variant char 'printable)
1311 (unless (char-attribute-alist char)
1312 (insert (format ";; = %c\n"
1313 (let* ((rest (split-char char))
1317 (setq code (logior (lsh code 8)
1319 (decode-char ccs code)))))
1320 ;; (char-db-update-comment)
1321 (set-buffer-modified-p nil)
1322 (view-mode the-buf (lambda (buf)
1323 (set-window-configuration
1324 what-character-original-window-configuration)
1326 (goto-char (point-min)))
1328 (set-window-configuration
1329 what-character-original-window-configuration)
1330 (signal (car err) (cdr err)))))))
1336 (provide 'char-db-util)
1338 ;;; char-db-util.el ends here