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
240 ;;; @ char-db formatters
243 (defun char-db-make-char-spec (char)
245 (cond ((characterp char)
246 (cond ((and (setq ret (encode-char char '=ucs 'defined-only))
247 (not (and (<= #xE000 ret)(<= ret #xF8FF))))
248 (setq char-spec (list (cons '=ucs ret)))
249 (cond ((setq ret (get-char-attribute char 'name))
250 (setq char-spec (cons (cons 'name ret) char-spec))
252 ((setq ret (get-char-attribute char 'name*))
253 (setq char-spec (cons (cons 'name* ret) char-spec))
258 (let ((rest char-db-coded-charset-priority-list)
261 (setq ccs (charset-name
262 (find-charset (car rest))))
264 (encode-char char ccs
266 (throw 'tag (cons ccs ret)))
267 (setq rest (cdr rest))))))
268 (setq char-spec (list ret))
269 (dolist (ccs (delq (car ret) (charset-list)))
270 (if (and (or (charset-iso-final-char ccs)
277 (string-match "=ucs@" (symbol-name ccs)))
278 (setq ccs (charset-name ccs))
279 (null (assq ccs char-spec))
280 (setq ret (encode-char char ccs 'defined-only)))
281 (setq char-spec (cons (cons ccs ret) char-spec))))
283 (setq char-spec (split-char char)))
284 (cond ((setq ret (get-char-attribute char 'name))
285 (setq char-spec (cons (cons 'name ret) char-spec))
287 ((setq ret (get-char-attribute char 'name*))
288 (setq char-spec (cons (cons 'name* ret) char-spec))
291 ((setq ret (get-char-attribute
292 char 'ideographic-combination))
294 (cons (cons 'ideographic-combination ret)
301 (defun char-db-insert-char-spec (char &optional readable column
304 (setq column (current-column)))
305 (let (char-spec temp-char)
306 (setq char-spec (char-db-make-char-spec char))
307 (unless (or (characterp char) ; char
309 (setq char (find-char char-spec))
311 ;; define temporary character
312 ;; Current implementation is dirty.
313 (setq temp-char (define-char (cons '(ideograph-daikanwa . 0)
315 (remove-char-attribute temp-char 'ideograph-daikanwa)
316 (setq char temp-char))
317 (insert-char-attributes char
319 (union (mapcar #'car char-spec)
323 ;; undefine temporary character
324 ;; Current implementation is dirty.
325 (setq char-spec (char-attribute-alist temp-char))
327 (remove-char-attribute temp-char (car (car char-spec)))
328 (setq char-spec (cdr char-spec))))))
330 (defun char-db-insert-alist (alist &optional readable column)
332 (setq column (current-column)))
334 (concat "\n" (make-string (1+ column) ?\ )))
338 lbs cell rest separator)
341 (setq name (car (car alist))
342 value (cdr (car alist)))
343 (cond ((eq name 'char)
345 (if (setq ret (condition-case nil
353 (setq key (car (car value)))
354 ;; (if (find-charset key)
355 ;; (setq cal (cons key cal))
356 (setq al (cons key al))
358 (setq value (cdr value)))
359 (insert-char-attributes ret
363 (insert (prin1-to-string value)))
365 (insert line-breaking))
367 (insert (format "(%-18s " name))
368 (setq lbs (concat "\n" (make-string (current-column) ?\ )))
370 (setq cell (car value))
371 (if (and (consp cell)
373 (setq ret (condition-case nil
383 (setq key (car (car rest)))
384 ;; (if (find-charset key)
385 ;; (setq cal (cons key cal))
386 (setq al (cons key al))
388 (setq rest (cdr rest)))
391 (insert-char-attributes ret
395 (setq separator lbs))
398 (insert (prin1-to-string cell))
399 (setq separator " "))
400 (setq value (cdr value)))
402 (insert line-breaking))
404 (insert (format "(%-18s . %S)%s"
407 (setq alist (cdr alist))))
410 (defun char-db-insert-char-reference (plist &optional readable column)
412 (setq column (current-column)))
414 (concat "\n" (make-string (1+ column) ?\ )))
419 (setq name (pop plist))
420 (setq value (pop plist))
421 (cond ((eq name :char)
424 (cond ((numberp value)
425 (setq value (decode-char '=ucs value)))
427 ;; (setq value (or (find-char value)
430 (char-db-insert-char-spec value readable)
431 (insert line-breaking)
434 (insert (format "%s%s\t%d ; %c%s"
437 (ideographic-radical value)
441 (insert (format "%s%s\t%S" separator name value))
442 (setq separator line-breaking)))
446 (defun char-db-decode-isolated-char (ccs code-point)
449 (cond ((eq ccs 'arabic-iso8859-6)
450 (decode-char ccs code-point))
451 ((and (memq ccs '(=gt-pj-1
462 (setq ret (decode-char ccs code-point))
463 (setq ret (encode-char ret '=gt 'defined-only)))
464 (decode-builtin-char '=gt ret))
466 (decode-builtin-char ccs code-point))))
467 (cond ((and (<= 0 (char-int ret))
468 (<= (char-int ret) #x1F))
469 (decode-char '=ucs (+ #x2400 (char-int ret))))
470 ((= (char-int ret) #x7F)
474 (defvar char-db-convert-obsolete-format t)
476 (defun char-db-insert-ccs-feature (name value line-breaking)
482 ((memq name '(=shinjigen
484 =shinjigen@rev =shinjigen/+p@rev
486 "(%-18s . %04d)\t; %c")
487 ((eq name '=shinjigen@1ed/24pr)
488 "(%-18s . %04d)\t; %c")
489 ((or (memq name '(=daikanwa =>>daikanwa =>daikanwa
490 =daikanwa@rev1 =daikanwa@rev2
491 =daikanwa/+p =daikanwa/+2p
492 =gt =>>>gt =>>gt =+>gt =>gt
494 =adobe-japan1-0 =adobe-japan1-1 =adobe-japan1-2
495 =adobe-japan1-3 =adobe-japan1-4 =adobe-japan1-5
496 =adobe-japan1-6 =>>>adobe-japan1 =>>adobe-japan1
499 =zinbun-oracle =>zinbun-oracle))
500 ;; (string-match "^=adobe-" (symbol-name name))
502 "(%-18s . %05d)\t; %c")
503 ((memq name '(=hanyo-denshi/ks =>>hanyo-denshi/ks mojikyo))
504 "(%-18s . %06d)\t; %c")
505 ((>= (charset-dimension name) 2)
506 "(%-18s . #x%04X)\t; %c")
508 "(%-18s . #x%02X)\t; %c"))
510 (if (= (charset-iso-graphic-plane name) 1)
512 (cond ((= (charset-dimension name) 1)
514 ((= (charset-dimension name) 2)
516 ((= (charset-dimension name) 3)
520 (char-db-decode-isolated-char name value)))
521 (if (and (= (charset-chars name) 94)
522 (= (charset-dimension name) 2))
523 (insert (format " [%02d-%02d]"
524 (- (lsh value -8) 32)
525 (- (logand value 255) 32))))
528 (insert (format "(%-18s . %s)" name value))
530 (insert line-breaking))
532 (defun char-db-insert-relation-feature (char name value line-breaking
534 (insert (format "(%-18s%s " name line-breaking))
535 (let ((lbs (concat "\n" (make-string (current-column) ?\ )))
536 separator cell sources required-features
539 (setq cell (car value))
541 (setq cell (decode-char '=ucs cell)))
543 ((eq name '->subsumptive)
544 (when (or (not (some (lambda (atr)
545 (get-char-attribute cell atr))
546 char-db-ignored-attributes))
548 (encode-char cell ccs 'defined-only))
552 (let ((char-db-ignored-attributes
554 char-db-ignored-attributes)))
555 (insert-char-attributes cell readable nil nil 'for-sub-node))
556 (setq separator lbs))
561 char (intern (format "%s*sources" name))))
562 (setq required-features nil)
563 (dolist (source sources)
567 shinjigen shinjigen@1ed shinjigen@rev))
568 (setq required-features
569 (union required-features
580 (setq required-features
581 (union required-features
586 ((find-charset (setq ret (intern (format "=%s" source))))
587 (setq required-features
588 (cons ret required-features)))
589 (t (setq required-features
590 (cons source required-features)))))
591 (cond ((string-match "@JP" (symbol-name name))
592 (setq required-features
593 (union required-features
601 ((string-match "@CN" (symbol-name name))
602 (setq required-features
603 (union required-features
610 (insert (format "%S" cell))
611 (char-db-insert-char-spec cell readable
614 (setq separator lbs))
618 (if (consp (car cell))
619 (char-db-insert-char-spec cell readable)
620 (char-db-insert-char-reference cell readable))
621 (setq separator lbs))
625 (insert (prin1-to-string cell))
626 (setq separator " ")))
627 (setq value (cdr value)))
629 (insert line-breaking)))
631 (defun insert-char-attributes (char &optional readable attributes column
634 (setq column (current-column)))
635 (let (name value ; has-long-ccs-name
639 (concat "\n" (make-string (1+ column) ?\ )))
640 lbs cell separator ret
642 dest-ccss ; sources required-features
647 (if (consp attributes)
649 (dolist (name attributes)
650 (unless (memq name char-db-ignored-attributes)
651 (if (find-charset name)
655 (dolist (name (char-attribute-list))
656 (unless (memq name char-db-ignored-attributes)
657 (if (find-charset name)
661 #'char-attribute-name<)))
663 (when (memq '<-subsumptive attributes)
664 (when (or readable (not for-sub-node))
665 (when (setq value (get-char-attribute char '<-subsumptive))
666 (char-db-insert-relation-feature char '<-subsumptive value
669 (setq attributes (delq '<-subsumptive attributes)))
670 (when (and (memq '<-denotational attributes)
671 (setq value (get-char-attribute char '<-denotational)))
672 (char-db-insert-relation-feature char '<-denotational value
675 (setq attributes (delq '<-denotational attributes)))
676 (when (and (memq 'name attributes)
677 (setq value (get-char-attribute char 'name)))
679 (if (> (+ (current-column) (length value)) 48)
682 value line-breaking))
683 (setq attributes (delq 'name attributes))
685 (when (and (memq 'name* attributes)
686 (setq value (get-char-attribute char 'name*)))
688 (if (> (+ (current-column) (length value)) 48)
691 value line-breaking))
692 (setq attributes (delq 'name* attributes))
694 (when (and (memq 'script attributes)
695 (setq value (get-char-attribute char 'script)))
696 (insert (format "(script\t\t%s)%s"
697 (mapconcat (function prin1-to-string)
700 (setq attributes (delq 'script attributes))
702 (dolist (name '(=>ucs =>ucs*))
703 (when (and (memq name attributes)
704 (setq value (get-char-attribute char name)))
705 (insert (format "(%-18s . #x%04X)\t; %c%s"
706 name value (decode-char '=ucs value)
708 (setq attributes (delq name attributes))))
709 (dolist (name '(=>ucs@gb =>ucs@big5))
710 (when (and (memq name attributes)
711 (setq value (get-char-attribute char name)))
712 (insert (format "(%-18s . #x%04X)\t; %c%s"
717 (symbol-name name) 2)))
720 (setq attributes (delq name attributes))
722 ;; (dolist (name '(=>daikanwa))
723 ;; (when (and (memq name attributes)
724 ;; (setq value (get-char-attribute char name)))
726 ;; (if (integerp value)
727 ;; (format "(%-18s . %05d)\t; %c%s"
728 ;; name value (decode-char '=daikanwa value)
730 ;; (format "(%-18s %s)\t; %c%s"
732 ;; (mapconcat (function prin1-to-string)
734 ;; (char-representative-of-daikanwa char)
736 ;; (setq attributes (delq name attributes))))
737 (when (and (memq 'general-category attributes)
738 (setq value (get-char-attribute char 'general-category)))
740 "(general-category\t%s) ; %s%s"
741 (mapconcat (lambda (cell)
744 (cond ((rassoc value unidata-normative-category-alist)
745 "Normative Category")
746 ((rassoc value unidata-informative-category-alist)
747 "Informative Category")
751 (setq attributes (delq 'general-category attributes))
753 (when (and (memq 'bidi-category attributes)
754 (setq value (get-char-attribute char 'bidi-category)))
755 (insert (format "(bidi-category\t. %S)%s"
758 (setq attributes (delq 'bidi-category attributes))
760 (unless (or (not (memq 'mirrored attributes))
761 (eq (setq value (get-char-attribute char 'mirrored 'empty))
763 (insert (format "(mirrored\t\t. %S)%s"
766 (setq attributes (delq 'mirrored attributes))
769 ((and (memq 'decimal-digit-value attributes)
770 (setq value (get-char-attribute char 'decimal-digit-value)))
771 (insert (format "(decimal-digit-value . %S)%s"
774 (setq attributes (delq 'decimal-digit-value attributes))
775 (when (and (memq 'digit-value attributes)
776 (setq value (get-char-attribute char 'digit-value)))
777 (insert (format "(digit-value\t . %S)%s"
780 (setq attributes (delq 'digit-value attributes))
782 (when (and (memq 'numeric-value attributes)
783 (setq value (get-char-attribute char 'numeric-value)))
784 (insert (format "(numeric-value\t . %S)%s"
787 (setq attributes (delq 'numeric-value attributes))
791 (when (and (memq 'digit-value attributes)
792 (setq value (get-char-attribute char 'digit-value)))
793 (insert (format "(digit-value\t. %S)%s"
796 (setq attributes (delq 'digit-value attributes))
798 (when (and (memq 'numeric-value attributes)
799 (setq value (get-char-attribute char 'numeric-value)))
800 (insert (format "(numeric-value\t. %S)%s"
803 (setq attributes (delq 'numeric-value attributes))
805 (when (and (memq 'iso-10646-comment attributes)
806 (setq value (get-char-attribute char 'iso-10646-comment)))
807 (insert (format "(iso-10646-comment\t. %S)%s"
810 (setq attributes (delq 'iso-10646-comment attributes))
812 (when (and (memq 'morohashi-daikanwa attributes)
813 (setq value (get-char-attribute char 'morohashi-daikanwa)))
814 (insert (format "(morohashi-daikanwa\t%s)%s"
815 (mapconcat (function prin1-to-string) value " ")
817 (setq attributes (delq 'morohashi-daikanwa attributes))
821 (when (and (memq 'ideographic-radical attributes)
822 (setq value (get-char-attribute char 'ideographic-radical)))
824 (insert (format "(ideographic-radical . %S)\t; %c%s"
826 (ideographic-radical radical)
828 (setq attributes (delq 'ideographic-radical attributes))
830 (when (and (memq 'shuowen-radical attributes)
831 (setq value (get-char-attribute char 'shuowen-radical)))
832 (insert (format "(shuowen-radical\t. %S)\t; %c%s"
834 (shuowen-radical value)
836 (setq attributes (delq 'shuowen-radical attributes))
841 char-db-feature-domains
843 (dolist (feature (char-attribute-list))
844 (setq feature (symbol-name feature))
846 "\\(radical\\|strokes\\)@\\([^@*]+\\)\\(\\*\\|$\\)"
848 (setq domain (intern (match-string 2 feature)))
849 (unless (memq domain dest)
850 (setq dest (cons domain dest)))))
851 (sort dest #'string<))))
852 (setq key (intern (format "%s@%s" 'ideographic-radical domain)))
853 (when (and (memq key attributes)
854 (setq value (get-char-attribute char key)))
856 (insert (format "(%s . %S)\t; %c%s"
859 (ideographic-radical radical)
861 (setq attributes (delq key attributes))
863 (setq key (intern (format "%s@%s" 'ideographic-strokes domain)))
864 (when (and (memq key attributes)
865 (setq value (get-char-attribute char key)))
867 (insert (format "(%s . %S)%s"
871 (setq attributes (delq key attributes))
873 (setq key (intern (format "%s@%s" 'total-strokes domain)))
874 (when (and (memq key attributes)
875 (setq value (get-char-attribute char key)))
876 (insert (format "(%s . %S)%s"
880 (setq attributes (delq key attributes))
882 (dolist (feature '(ideographic-radical
885 (setq key (intern (format "%s@%s*sources" feature domain)))
886 (when (and (memq key attributes)
887 (setq value (get-char-attribute char key)))
888 (insert (format "(%s%s" key line-breaking))
890 (insert (format " %s" cell)))
892 (insert line-breaking)
893 (setq attributes (delq key attributes))
896 (when (and (memq 'ideographic-strokes attributes)
897 (setq value (get-char-attribute char 'ideographic-strokes)))
899 (insert (format "(ideographic-strokes . %S)%s"
902 (setq attributes (delq 'ideographic-strokes attributes))
904 (when (and (memq 'kangxi-radical attributes)
905 (setq value (get-char-attribute char 'kangxi-radical)))
906 (unless (eq value radical)
907 (insert (format "(kangxi-radical\t . %S)\t; %c%s"
909 (ideographic-radical value)
912 (setq radical value)))
913 (setq attributes (delq 'kangxi-radical attributes))
915 (when (and (memq 'kangxi-strokes attributes)
916 (setq value (get-char-attribute char 'kangxi-strokes)))
917 (unless (eq value strokes)
918 (insert (format "(kangxi-strokes\t . %S)%s"
922 (setq strokes value)))
923 (setq attributes (delq 'kangxi-strokes attributes))
925 (when (and (memq 'japanese-radical attributes)
926 (setq value (get-char-attribute char 'japanese-radical)))
927 (unless (eq value radical)
928 (insert (format "(japanese-radical\t . %S)\t; %c%s"
930 (ideographic-radical value)
933 (setq radical value)))
934 (setq attributes (delq 'japanese-radical attributes))
936 (when (and (memq 'japanese-strokes attributes)
937 (setq value (get-char-attribute char 'japanese-strokes)))
938 (unless (eq value strokes)
939 (insert (format "(japanese-strokes\t . %S)%s"
943 (setq strokes value)))
944 (setq attributes (delq 'japanese-strokes attributes))
946 (when (and (memq 'cns-radical attributes)
947 (setq value (get-char-attribute char 'cns-radical)))
948 (insert (format "(cns-radical\t . %S)\t; %c%s"
950 (ideographic-radical value)
952 (setq attributes (delq 'cns-radical attributes))
954 (when (and (memq 'cns-strokes attributes)
955 (setq value (get-char-attribute char 'cns-strokes)))
956 (unless (eq value strokes)
957 (insert (format "(cns-strokes\t . %S)%s"
961 (setq strokes value)))
962 (setq attributes (delq 'cns-strokes attributes))
964 (when (and (memq 'shinjigen-1-radical attributes)
965 (setq value (get-char-attribute char 'shinjigen-1-radical)))
966 (unless (eq value radical)
967 (insert (format "(shinjigen-1-radical . %S)\t; %c%s"
969 (ideographic-radical value)
972 (setq radical value)))
973 (setq attributes (delq 'shinjigen-1-radical attributes))
975 (when (and (memq 'ideographic- attributes)
976 (setq value (get-char-attribute char 'ideographic-)))
977 (insert "(ideographic- ")
978 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
981 (setq cell (car value))
983 (setq cell (decode-char '=ucs cell)))
984 (cond ((characterp cell)
988 (insert (format "%S" cell))
989 (char-db-insert-char-spec cell readable))
990 (setq separator lbs))
994 (if (consp (car cell))
995 (char-db-insert-char-spec cell readable)
996 (char-db-insert-char-reference cell readable))
997 (setq separator lbs))
1001 (insert (prin1-to-string cell))
1002 (setq separator " ")))
1003 (setq value (cdr value)))
1005 (insert line-breaking)
1006 (setq attributes (delq 'ideographic- attributes)))
1007 (when (and (memq 'total-strokes attributes)
1008 (setq value (get-char-attribute char 'total-strokes)))
1009 (insert (format "(total-strokes . %S)%s"
1012 (setq attributes (delq 'total-strokes attributes))
1014 (when (and (memq '->ideograph attributes)
1015 (setq value (get-char-attribute char '->ideograph)))
1016 (insert (format "(->ideograph\t%s)%s"
1017 (mapconcat (lambda (code)
1018 (cond ((symbolp code)
1021 (format "#x%04X" code))
1024 line-breaking code))))
1027 (setq attributes (delq '->ideograph attributes))
1029 ;; (when (and (memq '->decomposition attributes)
1030 ;; (setq value (get-char-attribute char '->decomposition)))
1031 ;; (insert (format "(->decomposition\t%s)%s"
1032 ;; (mapconcat (lambda (code)
1033 ;; (cond ((symbolp code)
1034 ;; (symbol-name code))
1035 ;; ((characterp code)
1037 ;; (format "%S" code)
1042 ;; (format "#x%04X" code))
1044 ;; (format "%s%S" line-breaking code))))
1047 ;; (setq attributes (delq '->decomposition attributes))
1049 (if (equal (get-char-attribute char '->titlecase)
1050 (get-char-attribute char '->uppercase))
1051 (setq attributes (delq '->titlecase attributes)))
1052 (when (and (memq '->mojikyo attributes)
1053 (setq value (get-char-attribute char '->mojikyo)))
1054 (insert (format "(->mojikyo\t\t. %06d)\t; %c%s"
1055 value (decode-char 'mojikyo value)
1057 (setq attributes (delq '->mojikyo attributes))
1059 (when (and (memq 'hanyu-dazidian-vol attributes)
1060 (setq value (get-char-attribute char 'hanyu-dazidian-vol)))
1061 (insert (format "(hanyu-dazidian-vol . %d)%s"
1062 value line-breaking))
1063 (setq attributes (delq 'hanyu-dazidian-vol attributes))
1065 (when (and (memq 'hanyu-dazidian-page attributes)
1066 (setq value (get-char-attribute char 'hanyu-dazidian-page)))
1067 (insert (format "(hanyu-dazidian-page . %d)%s"
1068 value line-breaking))
1069 (setq attributes (delq 'hanyu-dazidian-page attributes))
1071 (when (and (memq 'hanyu-dazidian-char attributes)
1072 (setq value (get-char-attribute char 'hanyu-dazidian-char)))
1073 (insert (format "(hanyu-dazidian-char . %d)%s"
1074 value line-breaking))
1075 (setq attributes (delq 'hanyu-dazidian-char attributes))
1078 (dolist (ignored '(composition
1079 ->denotational <-subsumptive ->ucs-unified
1080 ->ideographic-component-forms))
1081 (setq attributes (delq ignored attributes))))
1083 (setq name (car attributes))
1084 (unless (eq (setq value (get-char-attribute char name 'value-is-empty))
1086 (cond ((setq ret (find-charset name))
1087 (setq name (charset-name ret))
1088 (when (not (memq name dest-ccss))
1089 (setq dest-ccss (cons name dest-ccss))
1090 (char-db-insert-ccs-feature name value line-breaking))
1092 ((string-match "^=>ucs@" (symbol-name name))
1093 (insert (format "(%-18s . #x%04X)\t; %c%s"
1094 name value (decode-char '=ucs value)
1097 ((eq name 'jisx0208-1978/4X)
1098 (insert (format "(%-18s . #x%04X)%s"
1104 (not (eq name '->subsumptive))
1105 (not (eq name '->uppercase))
1106 (not (eq name '->lowercase))
1107 (not (eq name '->titlecase))
1108 (not (eq name '->canonical))
1109 (not (eq name '->Bopomofo))
1110 (not (eq name '->mistakable))
1111 (not (eq name '->ideographic-variants))
1112 (null (get-char-attribute
1113 char (intern (format "%s*sources" name))))
1114 (not (string-match "\\*sources$" (symbol-name name)))
1115 (null (get-char-attribute
1116 char (intern (format "%s*note" name))))
1117 (not (string-match "\\*note$" (symbol-name name)))
1118 (or (eq name '<-identical)
1119 (eq name '<-uppercase)
1120 (eq name '<-lowercase)
1121 (eq name '<-titlecase)
1122 (eq name '<-canonical)
1123 (eq name '<-ideographic-variants)
1124 ;; (eq name '<-synonyms)
1125 (string-match "^<-synonyms" (symbol-name name))
1126 (eq name '<-mistakable)
1127 (when (string-match "^->" (symbol-name name))
1129 ((string-match "^->fullwidth" (symbol-name name))
1130 (not (and (consp value)
1131 (characterp (car value))
1133 (car value) '=ucs 'defined-only)))
1138 ((or (eq name 'ideographic-structure)
1139 (eq name 'ideographic-combination)
1140 (eq name 'ideographic-)
1141 (eq name '=decomposition)
1142 (char-feature-base-name= '=decomposition name)
1143 (char-feature-base-name= '=>decomposition name)
1144 ;; (string-match "^=>*decomposition\\(@[^*]+\\)?$"
1145 ;; (symbol-name name))
1146 (string-match "^\\(->\\|<-\\)[^*]*$" (symbol-name name))
1147 (string-match "^\\(->\\|<-\\)[^*]*\\*sources$"
1150 (char-db-insert-relation-feature char name value
1153 ((memq name '(ideograph=
1154 original-ideograph-of
1155 ancient-ideograph-of
1158 ;; simplified-ideograph-of
1159 ideographic-variants
1160 ;; ideographic-different-form-of
1162 (insert (format "(%-18s%s " name line-breaking))
1163 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1165 (while (consp value)
1166 (setq cell (car value))
1167 (if (and (consp cell)
1172 (char-db-insert-alist cell readable)
1173 (setq separator lbs))
1176 (insert (prin1-to-string cell))
1177 (setq separator " "))
1178 (setq value (cdr value)))
1180 (insert line-breaking))
1182 (insert (format "(%-18s " name))
1183 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1185 (while (consp value)
1186 (setq cell (car value))
1187 (if (and (consp cell)
1189 (setq ret (condition-case nil
1197 (setq key (car (car rest)))
1198 (if (find-charset key)
1199 (setq cal (cons key cal))
1200 (setq al (cons key al)))
1201 (setq rest (cdr rest)))
1204 (insert-char-attributes ret
1208 (setq separator lbs))
1209 (setq ret (prin1-to-string cell))
1211 (if (< (+ (current-column)
1218 (setq separator " "))
1219 (setq value (cdr value)))
1221 (insert line-breaking))
1223 (insert (format "(%-18s" name))
1224 (setq ret (prin1-to-string value))
1225 (unless (< (+ (current-column)
1229 (insert line-breaking))
1230 (insert " . " ret ")" line-breaking)
1231 ;; (insert (format "(%-18s . %S)%s"
1236 (setq attributes (cdr attributes)))
1239 (defun insert-char-data (char &optional readable
1242 (narrow-to-region (point)(point))
1243 (insert "(define-char
1245 (insert-char-attributes char readable attributes)
1247 (goto-char (point-min))
1248 (while (re-search-forward "[ \t]+$" nil t)
1251 (goto-char (point-min))
1252 (while (re-search-forward "[ \t][ \t][ \t]*" nil t)
1253 (let ((column (current-column))
1254 (indent-tabs-mode t))
1255 (delete-region (match-beginning 0) (point))
1256 (indent-to column)))
1257 (goto-char (point-max))
1258 ;; (tabify (point-min)(point-max))
1261 (defun insert-char-data-with-variant (char &optional printable
1263 script excluded-script)
1264 (insert-char-data char printable)
1265 (let ((variants (char-variants char))
1268 (setq variants (sort variants #'<))
1269 (setq rest variants)
1270 (setq variants (cons char variants))
1272 (setq variant (car rest))
1273 (unless (get-char-attribute variant '<-subsumptive)
1274 (if (and (or (null script)
1275 (null (setq vs (get-char-attribute variant 'script)))
1277 (or (null excluded-script)
1278 (null (setq vs (get-char-attribute variant 'script)))
1279 (not (memq excluded-script vs))))
1280 (unless (and no-ucs-unified (get-char-attribute variant '=ucs))
1281 (insert-char-data variant printable)
1282 (if (setq ret (char-variants variant))
1284 (or (memq (car ret) variants)
1285 ;; (get-char-attribute (car ret) '<-subsumptive)
1286 (setq rest (nconc rest (list (car ret)))))
1287 (setq ret (cdr ret)))))))
1288 (setq rest (cdr rest)))))
1290 (defun insert-char-range-data (min max &optional script excluded-script)
1293 (while (<= code max)
1294 (setq char (decode-char '=ucs code))
1295 (if (encode-char char '=ucs 'defined-only)
1296 (insert-char-data-with-variant char nil 'no-ucs-unified
1297 script excluded-script))
1298 (setq code (1+ code)))))
1300 (defun write-char-range-data-to-file (min max file
1301 &optional script excluded-script)
1302 (let ((coding-system-for-write char-db-file-coding-system))
1304 (insert (format ";; -*- coding: %s -*-\n"
1305 char-db-file-coding-system))
1306 (insert-char-range-data min max script excluded-script)
1307 (write-region (point-min)(point-max) file))))
1309 (defvar what-character-original-window-configuration)
1312 (defun what-char-definition (char)
1313 (interactive (list (char-after)))
1314 (let ((buf (get-buffer-create "*Character Description*"))
1315 (the-buf (current-buffer))
1316 (win-conf (current-window-configuration)))
1318 (make-local-variable 'what-character-original-window-configuration)
1319 (setq what-character-original-window-configuration win-conf)
1320 (setq buffer-read-only nil)
1324 (insert-char-data-with-variant char 'printable)
1325 (unless (char-attribute-alist char)
1326 (insert (format ";; = %c\n"
1327 (let* ((rest (split-char char))
1331 (setq code (logior (lsh code 8)
1333 (decode-char ccs code)))))
1334 ;; (char-db-update-comment)
1335 (set-buffer-modified-p nil)
1336 (view-mode the-buf (lambda (buf)
1337 (set-window-configuration
1338 what-character-original-window-configuration)
1340 (goto-char (point-min)))
1342 (set-window-configuration
1343 what-character-original-window-configuration)
1344 (signal (car err) (cdr err)))))))
1350 (provide 'char-db-util)
1352 ;;; char-db-util.el ends here