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
224 ;;; @ char-db formatters
227 (defun char-db-make-char-spec (char)
229 (cond ((characterp char)
230 (cond ((and (setq ret (encode-char char '=ucs 'defined-only))
231 (not (and (<= #xE000 ret)(<= ret #xF8FF))))
232 (setq char-spec (list (cons '=ucs ret)))
233 (cond ((setq ret (get-char-attribute char 'name))
234 (setq char-spec (cons (cons 'name ret) char-spec))
236 ((setq ret (get-char-attribute char 'name*))
237 (setq char-spec (cons (cons 'name* ret) char-spec))
242 (let ((rest char-db-coded-charset-priority-list)
245 (setq ccs (charset-name
246 (find-charset (car rest))))
248 (encode-char char ccs
250 (throw 'tag (cons ccs ret)))
251 (setq rest (cdr rest))))))
252 (setq char-spec (list ret))
253 (dolist (ccs (delq (car ret) (charset-list)))
254 (if (and (or (charset-iso-final-char ccs)
261 (string-match "=ucs@" (symbol-name ccs)))
262 (setq ccs (charset-name ccs))
263 (null (assq ccs char-spec))
264 (setq ret (encode-char char ccs 'defined-only)))
265 (setq char-spec (cons (cons ccs ret) char-spec))))
267 (setq char-spec (split-char char)))
268 (cond ((setq ret (get-char-attribute char 'name))
269 (setq char-spec (cons (cons 'name ret) char-spec))
271 ((setq ret (get-char-attribute char 'name*))
272 (setq char-spec (cons (cons 'name* ret) char-spec))
275 ((setq ret (get-char-attribute
276 char 'ideographic-combination))
278 (cons (cons 'ideographic-combination ret)
285 (defun char-db-insert-char-spec (char &optional readable column
288 (setq column (current-column)))
289 (let (char-spec temp-char)
290 (setq char-spec (char-db-make-char-spec char))
291 (unless (or (characterp char) ; char
293 (setq char (find-char char-spec))
295 ;; define temporary character
296 ;; Current implementation is dirty.
297 (setq temp-char (define-char (cons '(ideograph-daikanwa . 0)
299 (remove-char-attribute temp-char 'ideograph-daikanwa)
300 (setq char temp-char))
301 (insert-char-attributes char
303 (union (mapcar #'car char-spec)
306 ;; undefine temporary character
307 ;; Current implementation is dirty.
308 (setq char-spec (char-attribute-alist temp-char))
310 (remove-char-attribute temp-char (car (car char-spec)))
311 (setq char-spec (cdr char-spec))))))
313 (defun char-db-insert-alist (alist &optional readable column)
315 (setq column (current-column)))
317 (concat "\n" (make-string (1+ column) ?\ )))
321 lbs cell rest separator)
324 (setq name (car (car alist))
325 value (cdr (car alist)))
326 (cond ((eq name 'char)
328 (if (setq ret (condition-case nil
336 (setq key (car (car value)))
337 ;; (if (find-charset key)
338 ;; (setq cal (cons key cal))
339 (setq al (cons key al))
341 (setq value (cdr value)))
342 (insert-char-attributes ret
346 (insert (prin1-to-string value)))
348 (insert line-breaking))
350 (insert (format "(%-18s " name))
351 (setq lbs (concat "\n" (make-string (current-column) ?\ )))
353 (setq cell (car value))
354 (if (and (consp cell)
356 (setq ret (condition-case nil
366 (setq key (car (car rest)))
367 ;; (if (find-charset key)
368 ;; (setq cal (cons key cal))
369 (setq al (cons key al))
371 (setq rest (cdr rest)))
374 (insert-char-attributes ret
378 (setq separator lbs))
381 (insert (prin1-to-string cell))
382 (setq separator " "))
383 (setq value (cdr value)))
385 (insert line-breaking))
387 (insert (format "(%-18s . %S)%s"
390 (setq alist (cdr alist))))
393 (defun char-db-insert-char-reference (plist &optional readable column)
395 (setq column (current-column)))
397 (concat "\n" (make-string (1+ column) ?\ )))
402 (setq name (pop plist))
403 (setq value (pop plist))
404 (cond ((eq name :char)
407 (cond ((numberp value)
408 (setq value (decode-char '=ucs value)))
410 ;; (setq value (or (find-char value)
413 (char-db-insert-char-spec value readable)
414 (insert line-breaking)
417 (insert (format "%s%s\t%d ; %c%s"
420 (ideographic-radical value)
424 (insert (format "%s%s\t%S" separator name value))
425 (setq separator line-breaking)))
429 (defun char-db-decode-isolated-char (ccs code-point)
432 (cond ((eq ccs 'arabic-iso8859-6)
433 (decode-char ccs code-point))
434 ((and (memq ccs '(=gt-pj-1
445 (setq ret (decode-char ccs code-point))
446 (setq ret (encode-char ret '=gt 'defined-only)))
447 (decode-builtin-char '=gt ret))
449 (decode-builtin-char ccs code-point))))
450 (cond ((and (<= 0 (char-int ret))
451 (<= (char-int ret) #x1F))
452 (decode-char '=ucs (+ #x2400 (char-int ret))))
453 ((= (char-int ret) #x7F)
457 (defvar char-db-convert-obsolete-format t)
459 (defun char-db-insert-ccs-feature (name value line-breaking)
462 (cond ((memq name '(=shinjigen
464 =shinjigen@rev =shinjigen/+p@rev
466 "(%-18s . %04d)\t; %c")
467 ((eq name '=shinjigen@1ed/24pr)
468 "(%-18s . %04d)\t; %c")
469 ((or (memq name '(=daikanwa
470 =daikanwa@rev1 =daikanwa@rev2
471 =daikanwa/+p =daikanwa/+2p
472 =>>daikanwa =>daikanwa
473 =gt =>>gt =>gt =gt-k =>>gt-k =>gt-k =cbeta
474 =zinbun-oracle =>zinbun-oracle))
475 (string-match "^=adobe-" (symbol-name name)))
476 "(%-18s . %05d)\t; %c")
477 ((memq name '(=hanyo-denshi/ks =>>hanyo-denshi/ks mojikyo))
478 "(%-18s . %06d)\t; %c")
479 ((>= (charset-dimension name) 2)
480 "(%-18s . #x%04X)\t; %c")
482 "(%-18s . #x%02X)\t; %c"))
484 (if (= (charset-iso-graphic-plane name) 1)
486 (cond ((= (charset-dimension name) 1)
488 ((= (charset-dimension name) 2)
490 ((= (charset-dimension name) 3)
494 (char-db-decode-isolated-char name value)))
495 (if (and (= (charset-chars name) 94)
496 (= (charset-dimension name) 2))
497 (insert (format " [%02d-%02d]"
498 (- (lsh value -8) 32)
499 (- (logand value 255) 32))))
500 (insert line-breaking))
502 (defun char-db-insert-relation-feature (char name value line-breaking
504 (insert (format "(%-18s%s " name line-breaking))
505 (let ((lbs (concat "\n" (make-string (current-column) ?\ )))
506 separator cell sources required-features
509 (setq cell (car value))
511 (setq cell (decode-char '=ucs cell)))
513 ((eq name '->subsumptive)
514 (when (or (not (some (lambda (atr)
515 (get-char-attribute cell atr))
516 char-db-ignored-attributes))
518 (encode-char cell ccs 'defined-only))
522 (let ((char-db-ignored-attributes
524 char-db-ignored-attributes)))
525 (insert-char-attributes cell readable))
526 (setq separator lbs))
531 char (intern (format "%s*sources" name))))
532 (setq required-features nil)
533 (dolist (source sources)
537 shinjigen shinjigen@1ed shinjigen@rev))
538 (setq required-features
539 (union required-features
550 (setq required-features
551 (union required-features
556 ((find-charset (setq ret (intern (format "=%s" source))))
557 (setq required-features
558 (cons ret required-features)))
559 (t (setq required-features
560 (cons source required-features)))))
561 (cond ((string-match "@JP" (symbol-name name))
562 (setq required-features
563 (union required-features
571 ((string-match "@CN" (symbol-name name))
572 (setq required-features
573 (union required-features
580 (insert (format "%S" cell))
581 (char-db-insert-char-spec cell readable
584 (setq separator lbs))
588 (if (consp (car cell))
589 (char-db-insert-char-spec cell readable)
590 (char-db-insert-char-reference cell readable))
591 (setq separator lbs))
595 (insert (prin1-to-string cell))
596 (setq separator " ")))
597 (setq value (cdr value)))
599 (insert line-breaking)))
601 (defun insert-char-attributes (char &optional readable attributes column)
603 (setq column (current-column)))
604 (let (name value ; has-long-ccs-name
608 (concat "\n" (make-string (1+ column) ?\ )))
609 lbs cell separator ret
611 dest-ccss ; sources required-features
616 (if (consp attributes)
618 (dolist (name attributes)
619 (unless (memq name char-db-ignored-attributes)
620 (if (find-charset name)
624 (dolist (name (char-attribute-list))
625 (unless (memq name char-db-ignored-attributes)
626 (if (find-charset name)
630 #'char-attribute-name<)))
632 (when (memq '<-subsumptive attributes)
634 (when (setq value (get-char-attribute char '<-subsumptive))
635 (char-db-insert-relation-feature char '<-subsumptive value
638 (setq attributes (delq '<-subsumptive attributes)))
639 (when (and (memq '<-denotational attributes)
640 (setq value (get-char-attribute char '<-denotational)))
641 (char-db-insert-relation-feature char '<-denotational value
644 (setq attributes (delq '<-denotational attributes)))
645 (when (and (memq 'name attributes)
646 (setq value (get-char-attribute char 'name)))
648 (if (> (+ (current-column) (length value)) 48)
651 value line-breaking))
652 (setq attributes (delq 'name attributes))
654 (when (and (memq 'name* attributes)
655 (setq value (get-char-attribute char 'name*)))
657 (if (> (+ (current-column) (length value)) 48)
660 value line-breaking))
661 (setq attributes (delq 'name* attributes))
663 (when (and (memq 'script attributes)
664 (setq value (get-char-attribute char 'script)))
665 (insert (format "(script\t\t%s)%s"
666 (mapconcat (function prin1-to-string)
669 (setq attributes (delq 'script attributes))
671 (dolist (name '(=>ucs =>ucs*))
672 (when (and (memq name attributes)
673 (setq value (get-char-attribute char name)))
674 (insert (format "(%-18s . #x%04X)\t; %c%s"
675 name value (decode-char '=ucs value)
677 (setq attributes (delq name attributes))))
678 (dolist (name '(=>ucs@gb =>ucs@big5))
679 (when (and (memq name attributes)
680 (setq value (get-char-attribute char name)))
681 (insert (format "(%-18s . #x%04X)\t; %c%s"
686 (symbol-name name) 2)))
689 (setq attributes (delq name attributes))
691 ;; (dolist (name '(=>daikanwa))
692 ;; (when (and (memq name attributes)
693 ;; (setq value (get-char-attribute char name)))
695 ;; (if (integerp value)
696 ;; (format "(%-18s . %05d)\t; %c%s"
697 ;; name value (decode-char '=daikanwa value)
699 ;; (format "(%-18s %s)\t; %c%s"
701 ;; (mapconcat (function prin1-to-string)
703 ;; (char-representative-of-daikanwa char)
705 ;; (setq attributes (delq name attributes))))
706 (when (and (memq 'general-category attributes)
707 (setq value (get-char-attribute char 'general-category)))
709 "(general-category\t%s) ; %s%s"
710 (mapconcat (lambda (cell)
713 (cond ((rassoc value unidata-normative-category-alist)
714 "Normative Category")
715 ((rassoc value unidata-informative-category-alist)
716 "Informative Category")
720 (setq attributes (delq 'general-category attributes))
722 (when (and (memq 'bidi-category attributes)
723 (setq value (get-char-attribute char 'bidi-category)))
724 (insert (format "(bidi-category\t. %S)%s"
727 (setq attributes (delq 'bidi-category attributes))
729 (unless (or (not (memq 'mirrored attributes))
730 (eq (setq value (get-char-attribute char 'mirrored 'empty))
732 (insert (format "(mirrored\t\t. %S)%s"
735 (setq attributes (delq 'mirrored attributes))
738 ((and (memq 'decimal-digit-value attributes)
739 (setq value (get-char-attribute char 'decimal-digit-value)))
740 (insert (format "(decimal-digit-value . %S)%s"
743 (setq attributes (delq 'decimal-digit-value attributes))
744 (when (and (memq 'digit-value attributes)
745 (setq value (get-char-attribute char 'digit-value)))
746 (insert (format "(digit-value\t . %S)%s"
749 (setq attributes (delq 'digit-value attributes))
751 (when (and (memq 'numeric-value attributes)
752 (setq value (get-char-attribute char 'numeric-value)))
753 (insert (format "(numeric-value\t . %S)%s"
756 (setq attributes (delq 'numeric-value attributes))
760 (when (and (memq 'digit-value attributes)
761 (setq value (get-char-attribute char 'digit-value)))
762 (insert (format "(digit-value\t. %S)%s"
765 (setq attributes (delq 'digit-value attributes))
767 (when (and (memq 'numeric-value attributes)
768 (setq value (get-char-attribute char 'numeric-value)))
769 (insert (format "(numeric-value\t. %S)%s"
772 (setq attributes (delq 'numeric-value attributes))
774 (when (and (memq 'iso-10646-comment attributes)
775 (setq value (get-char-attribute char 'iso-10646-comment)))
776 (insert (format "(iso-10646-comment\t. %S)%s"
779 (setq attributes (delq 'iso-10646-comment attributes))
781 (when (and (memq 'morohashi-daikanwa attributes)
782 (setq value (get-char-attribute char 'morohashi-daikanwa)))
783 (insert (format "(morohashi-daikanwa\t%s)%s"
784 (mapconcat (function prin1-to-string) value " ")
786 (setq attributes (delq 'morohashi-daikanwa attributes))
790 (when (and (memq 'ideographic-radical attributes)
791 (setq value (get-char-attribute char 'ideographic-radical)))
793 (insert (format "(ideographic-radical . %S)\t; %c%s"
795 (ideographic-radical radical)
797 (setq attributes (delq 'ideographic-radical attributes))
799 (when (and (memq 'shuowen-radical attributes)
800 (setq value (get-char-attribute char 'shuowen-radical)))
801 (insert (format "(shuowen-radical\t. %S)\t; %c%s"
803 (shuowen-radical value)
805 (setq attributes (delq 'shuowen-radical attributes))
810 char-db-feature-domains
812 (dolist (feature (char-attribute-list))
813 (setq feature (symbol-name feature))
815 "\\(radical\\|strokes\\)@\\([^@*]+\\)\\(\\*\\|$\\)"
817 (setq domain (intern (match-string 2 feature)))
818 (unless (memq domain dest)
819 (setq dest (cons domain dest)))))
820 (sort dest #'string<))))
821 (setq key (intern (format "%s@%s" 'ideographic-radical domain)))
822 (when (and (memq key attributes)
823 (setq value (get-char-attribute char key)))
825 (insert (format "(%s . %S)\t; %c%s"
828 (ideographic-radical radical)
830 (setq attributes (delq key attributes))
832 (setq key (intern (format "%s@%s" 'ideographic-strokes domain)))
833 (when (and (memq key attributes)
834 (setq value (get-char-attribute char key)))
836 (insert (format "(%s . %S)%s"
840 (setq attributes (delq key attributes))
842 (setq key (intern (format "%s@%s" 'total-strokes domain)))
843 (when (and (memq key attributes)
844 (setq value (get-char-attribute char key)))
845 (insert (format "(%s . %S)%s"
849 (setq attributes (delq key attributes))
851 (dolist (feature '(ideographic-radical
854 (setq key (intern (format "%s@%s*sources" feature domain)))
855 (when (and (memq key attributes)
856 (setq value (get-char-attribute char key)))
857 (insert (format "(%s%s" key line-breaking))
859 (insert (format " %s" cell)))
861 (insert line-breaking)
862 (setq attributes (delq key attributes))
865 (when (and (memq 'ideographic-strokes attributes)
866 (setq value (get-char-attribute char 'ideographic-strokes)))
868 (insert (format "(ideographic-strokes . %S)%s"
871 (setq attributes (delq 'ideographic-strokes attributes))
873 (when (and (memq 'kangxi-radical attributes)
874 (setq value (get-char-attribute char 'kangxi-radical)))
875 (unless (eq value radical)
876 (insert (format "(kangxi-radical\t . %S)\t; %c%s"
878 (ideographic-radical value)
881 (setq radical value)))
882 (setq attributes (delq 'kangxi-radical attributes))
884 (when (and (memq 'kangxi-strokes attributes)
885 (setq value (get-char-attribute char 'kangxi-strokes)))
886 (unless (eq value strokes)
887 (insert (format "(kangxi-strokes\t . %S)%s"
891 (setq strokes value)))
892 (setq attributes (delq 'kangxi-strokes attributes))
894 (when (and (memq 'japanese-radical attributes)
895 (setq value (get-char-attribute char 'japanese-radical)))
896 (unless (eq value radical)
897 (insert (format "(japanese-radical\t . %S)\t; %c%s"
899 (ideographic-radical value)
902 (setq radical value)))
903 (setq attributes (delq 'japanese-radical attributes))
905 (when (and (memq 'japanese-strokes attributes)
906 (setq value (get-char-attribute char 'japanese-strokes)))
907 (unless (eq value strokes)
908 (insert (format "(japanese-strokes\t . %S)%s"
912 (setq strokes value)))
913 (setq attributes (delq 'japanese-strokes attributes))
915 (when (and (memq 'cns-radical attributes)
916 (setq value (get-char-attribute char 'cns-radical)))
917 (insert (format "(cns-radical\t . %S)\t; %c%s"
919 (ideographic-radical value)
921 (setq attributes (delq 'cns-radical attributes))
923 (when (and (memq 'cns-strokes attributes)
924 (setq value (get-char-attribute char 'cns-strokes)))
925 (unless (eq value strokes)
926 (insert (format "(cns-strokes\t . %S)%s"
930 (setq strokes value)))
931 (setq attributes (delq 'cns-strokes attributes))
933 (when (and (memq 'shinjigen-1-radical attributes)
934 (setq value (get-char-attribute char 'shinjigen-1-radical)))
935 (unless (eq value radical)
936 (insert (format "(shinjigen-1-radical . %S)\t; %c%s"
938 (ideographic-radical value)
941 (setq radical value)))
942 (setq attributes (delq 'shinjigen-1-radical attributes))
944 (when (and (memq 'ideographic- attributes)
945 (setq value (get-char-attribute char 'ideographic-)))
946 (insert "(ideographic- ")
947 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
950 (setq cell (car value))
952 (setq cell (decode-char '=ucs cell)))
953 (cond ((characterp cell)
957 (insert (format "%S" cell))
958 (char-db-insert-char-spec cell readable))
959 (setq separator lbs))
963 (if (consp (car cell))
964 (char-db-insert-char-spec cell readable)
965 (char-db-insert-char-reference cell readable))
966 (setq separator lbs))
970 (insert (prin1-to-string cell))
971 (setq separator " ")))
972 (setq value (cdr value)))
974 (insert line-breaking)
975 (setq attributes (delq 'ideographic- attributes)))
976 (when (and (memq 'total-strokes attributes)
977 (setq value (get-char-attribute char 'total-strokes)))
978 (insert (format "(total-strokes . %S)%s"
981 (setq attributes (delq 'total-strokes attributes))
983 (when (and (memq '->ideograph attributes)
984 (setq value (get-char-attribute char '->ideograph)))
985 (insert (format "(->ideograph\t%s)%s"
986 (mapconcat (lambda (code)
987 (cond ((symbolp code)
990 (format "#x%04X" code))
993 line-breaking code))))
996 (setq attributes (delq '->ideograph attributes))
998 ;; (when (and (memq '->decomposition attributes)
999 ;; (setq value (get-char-attribute char '->decomposition)))
1000 ;; (insert (format "(->decomposition\t%s)%s"
1001 ;; (mapconcat (lambda (code)
1002 ;; (cond ((symbolp code)
1003 ;; (symbol-name code))
1004 ;; ((characterp code)
1006 ;; (format "%S" code)
1011 ;; (format "#x%04X" code))
1013 ;; (format "%s%S" line-breaking code))))
1016 ;; (setq attributes (delq '->decomposition attributes))
1018 (if (equal (get-char-attribute char '->titlecase)
1019 (get-char-attribute char '->uppercase))
1020 (setq attributes (delq '->titlecase attributes)))
1021 (when (and (memq '->mojikyo attributes)
1022 (setq value (get-char-attribute char '->mojikyo)))
1023 (insert (format "(->mojikyo\t\t. %06d)\t; %c%s"
1024 value (decode-char 'mojikyo value)
1026 (setq attributes (delq '->mojikyo attributes))
1028 (when (and (memq 'hanyu-dazidian-vol attributes)
1029 (setq value (get-char-attribute char 'hanyu-dazidian-vol)))
1030 (insert (format "(hanyu-dazidian-vol . %d)%s"
1031 value line-breaking))
1032 (setq attributes (delq 'hanyu-dazidian-vol attributes))
1034 (when (and (memq 'hanyu-dazidian-page attributes)
1035 (setq value (get-char-attribute char 'hanyu-dazidian-page)))
1036 (insert (format "(hanyu-dazidian-page . %d)%s"
1037 value line-breaking))
1038 (setq attributes (delq 'hanyu-dazidian-page attributes))
1040 (when (and (memq 'hanyu-dazidian-char attributes)
1041 (setq value (get-char-attribute char 'hanyu-dazidian-char)))
1042 (insert (format "(hanyu-dazidian-char . %d)%s"
1043 value line-breaking))
1044 (setq attributes (delq 'hanyu-dazidian-char attributes))
1047 (dolist (ignored '(composition
1048 ->denotational <-subsumptive ->ucs-unified
1049 ->ideographic-component-forms))
1050 (setq attributes (delq ignored attributes))))
1052 (setq name (car attributes))
1053 (if (setq value (get-char-attribute char name))
1054 (cond ((setq ret (find-charset name))
1055 (setq name (charset-name ret))
1056 (if (and (not (memq name dest-ccss))
1058 (setq value (get-char-attribute char name))
1059 (setq dest-ccss (cons name dest-ccss))))
1060 (char-db-insert-ccs-feature name value line-breaking))
1062 ((string-match "^=>ucs@" (symbol-name name))
1063 (insert (format "(%-18s . #x%04X)\t; %c%s"
1064 name value (decode-char '=ucs value)
1067 ((eq name 'jisx0208-1978/4X)
1068 (insert (format "(%-18s . #x%04X)%s"
1074 (not (eq name '->subsumptive))
1075 (not (eq name '->uppercase))
1076 (not (eq name '->lowercase))
1077 (not (eq name '->titlecase))
1078 (not (eq name '->canonical))
1079 (not (eq name '->Bopomofo))
1080 (not (eq name '->mistakable))
1081 (not (eq name '->ideographic-variants))
1082 (null (get-char-attribute
1083 char (intern (format "%s*sources" name))))
1084 (not (string-match "\\*sources$" (symbol-name name)))
1085 (null (get-char-attribute
1086 char (intern (format "%s*note" name))))
1087 (not (string-match "\\*note$" (symbol-name name)))
1088 (or (eq name '<-identical)
1089 (eq name '<-uppercase)
1090 (eq name '<-lowercase)
1091 (eq name '<-titlecase)
1092 (eq name '<-canonical)
1093 (eq name '<-ideographic-variants)
1094 ;; (eq name '<-synonyms)
1095 (string-match "^<-synonyms" (symbol-name name))
1096 (eq name '<-mistakable)
1097 (when (string-match "^->" (symbol-name name))
1099 ((string-match "^->fullwidth" (symbol-name name))
1100 (not (and (consp value)
1101 (characterp (car value))
1103 (car value) '=ucs 'defined-only)))
1108 ((or (eq name 'ideographic-structure)
1109 (eq name 'ideographic-combination)
1110 (eq name 'ideographic-)
1111 (eq name '=decomposition)
1112 (string-match "^=>*decomposition\\(@[^*]+\\)?$"
1114 (string-match "^\\(->\\|<-\\)[^*]*$" (symbol-name name))
1115 (string-match "^\\(->\\|<-\\)[^*]*\\*sources$"
1118 (char-db-insert-relation-feature char name value
1121 ((memq name '(ideograph=
1122 original-ideograph-of
1123 ancient-ideograph-of
1126 ;; simplified-ideograph-of
1127 ideographic-variants
1128 ;; ideographic-different-form-of
1130 (insert (format "(%-18s%s " name line-breaking))
1131 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1133 (while (consp value)
1134 (setq cell (car value))
1135 (if (and (consp cell)
1140 (char-db-insert-alist cell readable)
1141 (setq separator lbs))
1144 (insert (prin1-to-string cell))
1145 (setq separator " "))
1146 (setq value (cdr value)))
1148 (insert line-breaking))
1150 (insert (format "(%-18s " name))
1151 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1153 (while (consp value)
1154 (setq cell (car value))
1155 (if (and (consp cell)
1157 (setq ret (condition-case nil
1165 (setq key (car (car rest)))
1166 (if (find-charset key)
1167 (setq cal (cons key cal))
1168 (setq al (cons key al)))
1169 (setq rest (cdr rest)))
1172 (insert-char-attributes ret
1175 (setq separator lbs))
1176 (setq ret (prin1-to-string cell))
1178 (if (< (+ (current-column)
1185 (setq separator " "))
1186 (setq value (cdr value)))
1188 (insert line-breaking))
1190 (insert (format "(%-18s" name))
1191 (setq ret (prin1-to-string value))
1192 (unless (< (+ (current-column)
1196 (insert line-breaking))
1197 (insert " . " ret ")" line-breaking)
1198 ;; (insert (format "(%-18s . %S)%s"
1203 (setq attributes (cdr attributes)))
1206 (defun insert-char-data (char &optional readable
1209 (narrow-to-region (point)(point))
1210 (insert "(define-char
1212 (insert-char-attributes char readable attributes)
1214 (goto-char (point-min))
1215 (while (re-search-forward "[ \t]+$" nil t)
1218 (goto-char (point-min))
1219 (while (re-search-forward "[ \t][ \t][ \t]*" nil t)
1220 (let ((column (current-column))
1221 (indent-tabs-mode t))
1222 (delete-region (match-beginning 0) (point))
1223 (indent-to column)))
1224 (goto-char (point-max))
1225 ;; (tabify (point-min)(point-max))
1228 (defun insert-char-data-with-variant (char &optional printable
1230 script excluded-script)
1231 (insert-char-data char printable)
1232 (let ((variants (char-variants char))
1235 (setq variants (sort variants #'<))
1236 (setq rest variants)
1237 (setq variants (cons char variants))
1239 (setq variant (car rest))
1240 (unless (get-char-attribute variant '<-subsumptive)
1241 (if (and (or (null script)
1242 (null (setq vs (get-char-attribute variant 'script)))
1244 (or (null excluded-script)
1245 (null (setq vs (get-char-attribute variant 'script)))
1246 (not (memq excluded-script vs))))
1247 (unless (and no-ucs-unified (get-char-attribute variant '=ucs))
1248 (insert-char-data variant printable)
1249 (if (setq ret (char-variants variant))
1251 (or (memq (car ret) variants)
1252 ;; (get-char-attribute (car ret) '<-subsumptive)
1253 (setq rest (nconc rest (list (car ret)))))
1254 (setq ret (cdr ret)))))))
1255 (setq rest (cdr rest)))))
1257 (defun insert-char-range-data (min max &optional script excluded-script)
1260 (while (<= code max)
1261 (setq char (decode-char '=ucs code))
1262 (if (encode-char char '=ucs 'defined-only)
1263 (insert-char-data-with-variant char nil 'no-ucs-unified
1264 script excluded-script))
1265 (setq code (1+ code)))))
1267 (defun write-char-range-data-to-file (min max file
1268 &optional script excluded-script)
1269 (let ((coding-system-for-write char-db-file-coding-system))
1271 (insert (format ";; -*- coding: %s -*-\n"
1272 char-db-file-coding-system))
1273 (insert-char-range-data min max script excluded-script)
1274 (write-region (point-min)(point-max) file))))
1276 (defvar what-character-original-window-configuration)
1279 (defun what-char-definition (char)
1280 (interactive (list (char-after)))
1281 (let ((buf (get-buffer-create "*Character Description*"))
1282 (the-buf (current-buffer))
1283 (win-conf (current-window-configuration)))
1285 (make-local-variable 'what-character-original-window-configuration)
1286 (setq what-character-original-window-configuration win-conf)
1287 (setq buffer-read-only nil)
1291 (insert-char-data-with-variant char 'printable)
1292 (unless (char-attribute-alist char)
1293 (insert (format ";; = %c\n"
1294 (let* ((rest (split-char char))
1298 (setq code (logior (lsh code 8)
1300 (decode-char ccs code)))))
1301 ;; (char-db-update-comment)
1302 (set-buffer-modified-p nil)
1303 (view-mode the-buf (lambda (buf)
1304 (set-window-configuration
1305 what-character-original-window-configuration)
1307 (goto-char (point-min)))
1309 (set-window-configuration
1310 what-character-original-window-configuration)
1311 (signal (car err) (cdr err)))))))
1317 (provide 'char-db-util)
1319 ;;; char-db-util.el ends here