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 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
197 ;;; @ char-db formatters
200 (defun char-db-make-char-spec (char)
202 (cond ((characterp char)
203 (cond ((and (setq ret (encode-char char '=ucs 'defined-only))
204 (not (and (<= #xE000 ret)(<= ret #xF8FF))))
205 (setq char-spec (list (cons '=ucs ret)))
206 (cond ((setq ret (get-char-attribute char 'name))
207 (setq char-spec (cons (cons 'name ret) char-spec))
209 ((setq ret (get-char-attribute char 'name*))
210 (setq char-spec (cons (cons 'name* ret) char-spec))
215 (let ((rest char-db-coded-charset-priority-list)
218 (setq ccs (charset-name
219 (find-charset (car rest))))
221 (encode-char char ccs
223 (throw 'tag (cons ccs ret)))
224 (setq rest (cdr rest))))))
225 (setq char-spec (list ret))
226 (dolist (ccs (delq (car ret) (charset-list)))
227 (if (and (or (charset-iso-final-char ccs)
234 (string-match "=ucs@" (symbol-name ccs)))
235 (setq ccs (charset-name ccs))
236 (null (assq ccs char-spec))
237 (setq ret (encode-char char ccs 'defined-only)))
238 (setq char-spec (cons (cons ccs ret) char-spec))))
240 (setq char-spec (split-char char)))
241 (cond ((setq ret (get-char-attribute char 'name))
242 (setq char-spec (cons (cons 'name ret) char-spec))
244 ((setq ret (get-char-attribute char 'name*))
245 (setq char-spec (cons (cons 'name* ret) char-spec))
248 ((setq ret (get-char-attribute
249 char 'ideographic-combination))
251 (cons (cons 'ideographic-combination ret)
258 (defun char-db-insert-char-spec (char &optional readable column
261 (setq column (current-column)))
262 (let (char-spec temp-char)
263 (setq char-spec (char-db-make-char-spec char))
264 (unless (or (characterp char) ; char
266 (setq char (find-char char-spec))
268 ;; define temporary character
269 ;; Current implementation is dirty.
270 (setq temp-char (define-char (cons '(ideograph-daikanwa . 0)
272 (remove-char-attribute temp-char 'ideograph-daikanwa)
273 (setq char temp-char))
274 (insert-char-attributes char
276 (union (mapcar #'car char-spec)
279 ;; undefine temporary character
280 ;; Current implementation is dirty.
281 (setq char-spec (char-attribute-alist temp-char))
283 (remove-char-attribute temp-char (car (car char-spec)))
284 (setq char-spec (cdr char-spec))))))
286 (defun char-db-insert-alist (alist &optional readable column)
288 (setq column (current-column)))
290 (concat "\n" (make-string (1+ column) ?\ )))
294 lbs cell rest separator)
297 (setq name (car (car alist))
298 value (cdr (car alist)))
299 (cond ((eq name 'char)
301 (if (setq ret (condition-case nil
309 (setq key (car (car value)))
310 ;; (if (find-charset key)
311 ;; (setq cal (cons key cal))
312 (setq al (cons key al))
314 (setq value (cdr value)))
315 (insert-char-attributes ret
319 (insert (prin1-to-string value)))
321 (insert line-breaking))
323 (insert (format "(%-18s " name))
324 (setq lbs (concat "\n" (make-string (current-column) ?\ )))
326 (setq cell (car value))
327 (if (and (consp cell)
329 (setq ret (condition-case nil
339 (setq key (car (car rest)))
340 ;; (if (find-charset key)
341 ;; (setq cal (cons key cal))
342 (setq al (cons key al))
344 (setq rest (cdr rest)))
347 (insert-char-attributes ret
351 (setq separator lbs))
354 (insert (prin1-to-string cell))
355 (setq separator " "))
356 (setq value (cdr value)))
358 (insert line-breaking))
360 (insert (format "(%-18s . %S)%s"
363 (setq alist (cdr alist))))
366 (defun char-db-insert-char-reference (plist &optional readable column)
368 (setq column (current-column)))
370 (concat "\n" (make-string (1+ column) ?\ )))
375 (setq name (pop plist))
376 (setq value (pop plist))
377 (cond ((eq name :char)
380 (cond ((numberp value)
381 (setq value (decode-char '=ucs value)))
383 ;; (setq value (or (find-char value)
386 (char-db-insert-char-spec value readable)
387 (insert line-breaking)
390 (insert (format "%s%s\t%d ; %c%s"
393 (ideographic-radical value)
397 (insert (format "%s%s\t%S" separator name value))
398 (setq separator line-breaking)))
402 (defun char-db-decode-isolated-char (ccs code-point)
405 (cond ((eq ccs 'arabic-iso8859-6)
406 (decode-char ccs code-point))
407 ((and (memq ccs '(=gt-pj-1
418 (setq ret (decode-char ccs code-point))
419 (setq ret (encode-char ret '=gt 'defined-only)))
420 (decode-builtin-char '=gt ret))
422 (decode-builtin-char ccs code-point))))
423 (cond ((and (<= 0 (char-int ret))
424 (<= (char-int ret) #x1F))
425 (decode-char '=ucs (+ #x2400 (char-int ret))))
426 ((= (char-int ret) #x7F)
430 (defvar char-db-convert-obsolete-format t)
432 (defun char-db-insert-ccs-feature (name value line-breaking)
435 (cond ((memq name '(=shinjigen
437 =shinjigen@rev =shinjigen/+p@rev))
438 "(%-18s . %04d)\t; %c")
439 ((eq name '=shinjigen@1ed/24pr)
440 "(%-18s . %04d)\t; %c")
441 ((or (memq name '(=daikanwa
442 =daikanwa@rev1 =daikanwa@rev2
443 =>>daikanwa =>daikanwa
444 =gt =>>gt =>gt =gt-k =>>gt-k =cbeta
445 =zinbun-oracle =>zinbun-oracle))
446 (string-match "^=adobe-" (symbol-name name)))
447 "(%-18s . %05d)\t; %c")
449 "(%-18s . %06d)\t; %c")
450 ((>= (charset-dimension name) 2)
451 "(%-18s . #x%04X)\t; %c")
453 "(%-18s . #x%02X)\t; %c"))
455 (if (= (charset-iso-graphic-plane name) 1)
457 (cond ((= (charset-dimension name) 1)
459 ((= (charset-dimension name) 2)
461 ((= (charset-dimension name) 3)
465 (char-db-decode-isolated-char name value)))
466 (if (and (= (charset-chars name) 94)
467 (= (charset-dimension name) 2))
468 (insert (format " [%02d-%02d]"
469 (- (lsh value -8) 32)
470 (- (logand value 255) 32))))
471 (insert line-breaking))
473 (defun char-db-insert-relation-feature (char name value line-breaking
475 (insert (format "(%-18s%s " name line-breaking))
476 (let ((lbs (concat "\n" (make-string (current-column) ?\ )))
477 separator cell sources required-features
480 (setq cell (car value))
482 (setq cell (decode-char '=ucs cell)))
484 ((eq name '->subsumptive)
485 (when (or (not (some (lambda (atr)
486 (get-char-attribute cell atr))
487 char-db-ignored-attributes))
489 (encode-char cell ccs 'defined-only))
493 (let ((char-db-ignored-attributes
495 char-db-ignored-attributes)))
496 (insert-char-attributes cell readable))
497 (setq separator lbs))
502 char (intern (format "%s*sources" name))))
503 (setq required-features nil)
504 (dolist (source sources)
508 shinjigen shinjigen@1ed shinjigen@rev))
509 (setq required-features
510 (union required-features
521 (setq required-features
522 (union required-features
527 ((find-charset (setq ret (intern (format "=%s" source))))
528 (setq required-features
529 (cons ret required-features)))
530 (t (setq required-features
531 (cons source required-features)))))
532 (cond ((string-match "@JP" (symbol-name name))
533 (setq required-features
534 (union required-features
542 ((string-match "@CN" (symbol-name name))
543 (setq required-features
544 (union required-features
551 (insert (format "%S" cell))
552 (char-db-insert-char-spec cell readable
555 (setq separator lbs))
559 (if (consp (car cell))
560 (char-db-insert-char-spec cell readable)
561 (char-db-insert-char-reference cell readable))
562 (setq separator lbs))
566 (insert (prin1-to-string cell))
567 (setq separator " ")))
568 (setq value (cdr value)))
570 (insert line-breaking)))
572 (defun insert-char-attributes (char &optional readable attributes column)
574 (setq column (current-column)))
575 (let (name value ; has-long-ccs-name
579 (concat "\n" (make-string (1+ column) ?\ )))
580 lbs cell separator ret
582 dest-ccss ; sources required-features
587 (if (consp attributes)
589 (dolist (name attributes)
590 (unless (memq name char-db-ignored-attributes)
591 (if (find-charset name)
595 (dolist (name (char-attribute-list))
596 (unless (memq name char-db-ignored-attributes)
597 (if (find-charset name)
601 #'char-attribute-name<)))
603 (when (memq '<-subsumptive attributes)
605 (when (setq value (get-char-attribute char '<-subsumptive))
606 (char-db-insert-relation-feature char '<-subsumptive value
609 (setq attributes (delq '<-subsumptive attributes)))
610 (when (and (memq '<-denotational attributes)
611 (setq value (get-char-attribute char '<-denotational)))
612 (char-db-insert-relation-feature char '<-denotational value
615 (setq attributes (delq '<-denotational attributes)))
616 (when (and (memq 'name attributes)
617 (setq value (get-char-attribute char 'name)))
619 (if (> (+ (current-column) (length value)) 48)
622 value line-breaking))
623 (setq attributes (delq 'name attributes))
625 (when (and (memq 'name* attributes)
626 (setq value (get-char-attribute char 'name*)))
628 (if (> (+ (current-column) (length value)) 48)
631 value line-breaking))
632 (setq attributes (delq 'name* attributes))
634 (when (and (memq 'script attributes)
635 (setq value (get-char-attribute char 'script)))
636 (insert (format "(script\t\t%s)%s"
637 (mapconcat (function prin1-to-string)
640 (setq attributes (delq 'script attributes))
642 (dolist (name '(=>ucs =>ucs*))
643 (when (and (memq name attributes)
644 (setq value (get-char-attribute char name)))
645 (insert (format "(%-18s . #x%04X)\t; %c%s"
646 name value (decode-char '=ucs value)
648 (setq attributes (delq name attributes))))
649 (dolist (name '(=>ucs@gb =>ucs@ks =>ucs@big5))
650 (when (and (memq name attributes)
651 (setq value (get-char-attribute char name)))
652 (insert (format "(%-18s . #x%04X)\t; %c%s"
657 (symbol-name name) 2)))
660 (setq attributes (delq name attributes))
662 ;; (dolist (name '(=>daikanwa))
663 ;; (when (and (memq name attributes)
664 ;; (setq value (get-char-attribute char name)))
666 ;; (if (integerp value)
667 ;; (format "(%-18s . %05d)\t; %c%s"
668 ;; name value (decode-char '=daikanwa value)
670 ;; (format "(%-18s %s)\t; %c%s"
672 ;; (mapconcat (function prin1-to-string)
674 ;; (char-representative-of-daikanwa char)
676 ;; (setq attributes (delq name attributes))))
677 (when (and (memq 'general-category attributes)
678 (setq value (get-char-attribute char 'general-category)))
680 "(general-category\t%s) ; %s%s"
681 (mapconcat (lambda (cell)
684 (cond ((rassoc value unidata-normative-category-alist)
685 "Normative Category")
686 ((rassoc value unidata-informative-category-alist)
687 "Informative Category")
691 (setq attributes (delq 'general-category attributes))
693 (when (and (memq 'bidi-category attributes)
694 (setq value (get-char-attribute char 'bidi-category)))
695 (insert (format "(bidi-category\t. %S)%s"
698 (setq attributes (delq 'bidi-category attributes))
700 (unless (or (not (memq 'mirrored attributes))
701 (eq (setq value (get-char-attribute char 'mirrored 'empty))
703 (insert (format "(mirrored\t\t. %S)%s"
706 (setq attributes (delq 'mirrored attributes))
709 ((and (memq 'decimal-digit-value attributes)
710 (setq value (get-char-attribute char 'decimal-digit-value)))
711 (insert (format "(decimal-digit-value . %S)%s"
714 (setq attributes (delq 'decimal-digit-value attributes))
715 (when (and (memq 'digit-value attributes)
716 (setq value (get-char-attribute char 'digit-value)))
717 (insert (format "(digit-value\t . %S)%s"
720 (setq attributes (delq 'digit-value attributes))
722 (when (and (memq 'numeric-value attributes)
723 (setq value (get-char-attribute char 'numeric-value)))
724 (insert (format "(numeric-value\t . %S)%s"
727 (setq attributes (delq 'numeric-value attributes))
731 (when (and (memq 'digit-value attributes)
732 (setq value (get-char-attribute char 'digit-value)))
733 (insert (format "(digit-value\t. %S)%s"
736 (setq attributes (delq 'digit-value attributes))
738 (when (and (memq 'numeric-value attributes)
739 (setq value (get-char-attribute char 'numeric-value)))
740 (insert (format "(numeric-value\t. %S)%s"
743 (setq attributes (delq 'numeric-value attributes))
745 (when (and (memq 'iso-10646-comment attributes)
746 (setq value (get-char-attribute char 'iso-10646-comment)))
747 (insert (format "(iso-10646-comment\t. %S)%s"
750 (setq attributes (delq 'iso-10646-comment attributes))
752 (when (and (memq 'morohashi-daikanwa attributes)
753 (setq value (get-char-attribute char 'morohashi-daikanwa)))
754 (insert (format "(morohashi-daikanwa\t%s)%s"
755 (mapconcat (function prin1-to-string) value " ")
757 (setq attributes (delq 'morohashi-daikanwa attributes))
761 (when (and (memq 'ideographic-radical attributes)
762 (setq value (get-char-attribute char 'ideographic-radical)))
764 (insert (format "(ideographic-radical . %S)\t; %c%s"
766 (ideographic-radical radical)
768 (setq attributes (delq 'ideographic-radical attributes))
770 (when (and (memq 'shuowen-radical attributes)
771 (setq value (get-char-attribute char 'shuowen-radical)))
772 (insert (format "(shuowen-radical\t. %S)\t; %c%s"
774 (shuowen-radical value)
776 (setq attributes (delq 'shuowen-radical attributes))
781 char-db-feature-domains
783 (dolist (feature (char-attribute-list))
784 (setq feature (symbol-name feature))
786 "\\(radical\\|strokes\\)@\\([^@*]+\\)\\(\\*\\|$\\)"
788 (setq domain (intern (match-string 2 feature)))
789 (unless (memq domain dest)
790 (setq dest (cons domain dest)))))
791 (sort dest #'string<))))
792 (setq key (intern (format "%s@%s" 'ideographic-radical domain)))
793 (when (and (memq key attributes)
794 (setq value (get-char-attribute char key)))
796 (insert (format "(%s . %S)\t; %c%s"
799 (ideographic-radical radical)
801 (setq attributes (delq key attributes))
803 (setq key (intern (format "%s@%s" 'ideographic-strokes domain)))
804 (when (and (memq key attributes)
805 (setq value (get-char-attribute char key)))
807 (insert (format "(%s . %S)%s"
811 (setq attributes (delq key attributes))
813 (setq key (intern (format "%s@%s" 'total-strokes domain)))
814 (when (and (memq key attributes)
815 (setq value (get-char-attribute char key)))
816 (insert (format "(%s . %S)%s"
820 (setq attributes (delq key attributes))
822 (dolist (feature '(ideographic-radical
825 (setq key (intern (format "%s@%s*sources" feature domain)))
826 (when (and (memq key attributes)
827 (setq value (get-char-attribute char key)))
828 (insert (format "(%s%s" key line-breaking))
830 (insert (format " %s" cell)))
832 (insert line-breaking)
833 (setq attributes (delq key attributes))
836 (when (and (memq 'ideographic-strokes attributes)
837 (setq value (get-char-attribute char 'ideographic-strokes)))
839 (insert (format "(ideographic-strokes . %S)%s"
842 (setq attributes (delq 'ideographic-strokes attributes))
844 (when (and (memq 'kangxi-radical attributes)
845 (setq value (get-char-attribute char 'kangxi-radical)))
846 (unless (eq value radical)
847 (insert (format "(kangxi-radical\t . %S)\t; %c%s"
849 (ideographic-radical value)
852 (setq radical value)))
853 (setq attributes (delq 'kangxi-radical attributes))
855 (when (and (memq 'kangxi-strokes attributes)
856 (setq value (get-char-attribute char 'kangxi-strokes)))
857 (unless (eq value strokes)
858 (insert (format "(kangxi-strokes\t . %S)%s"
862 (setq strokes value)))
863 (setq attributes (delq 'kangxi-strokes attributes))
865 (when (and (memq 'japanese-radical attributes)
866 (setq value (get-char-attribute char 'japanese-radical)))
867 (unless (eq value radical)
868 (insert (format "(japanese-radical\t . %S)\t; %c%s"
870 (ideographic-radical value)
873 (setq radical value)))
874 (setq attributes (delq 'japanese-radical attributes))
876 (when (and (memq 'japanese-strokes attributes)
877 (setq value (get-char-attribute char 'japanese-strokes)))
878 (unless (eq value strokes)
879 (insert (format "(japanese-strokes\t . %S)%s"
883 (setq strokes value)))
884 (setq attributes (delq 'japanese-strokes attributes))
886 (when (and (memq 'cns-radical attributes)
887 (setq value (get-char-attribute char 'cns-radical)))
888 (insert (format "(cns-radical\t . %S)\t; %c%s"
890 (ideographic-radical value)
892 (setq attributes (delq 'cns-radical attributes))
894 (when (and (memq 'cns-strokes attributes)
895 (setq value (get-char-attribute char 'cns-strokes)))
896 (unless (eq value strokes)
897 (insert (format "(cns-strokes\t . %S)%s"
901 (setq strokes value)))
902 (setq attributes (delq 'cns-strokes attributes))
904 (when (and (memq 'shinjigen-1-radical attributes)
905 (setq value (get-char-attribute char 'shinjigen-1-radical)))
906 (unless (eq value radical)
907 (insert (format "(shinjigen-1-radical . %S)\t; %c%s"
909 (ideographic-radical value)
912 (setq radical value)))
913 (setq attributes (delq 'shinjigen-1-radical attributes))
915 (when (and (memq 'ideographic- attributes)
916 (setq value (get-char-attribute char 'ideographic-)))
917 (insert "(ideographic- ")
918 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
921 (setq cell (car value))
923 (setq cell (decode-char '=ucs cell)))
924 (cond ((characterp cell)
928 (insert (format "%S" cell))
929 (char-db-insert-char-spec cell readable))
930 (setq separator lbs))
934 (if (consp (car cell))
935 (char-db-insert-char-spec cell readable)
936 (char-db-insert-char-reference cell readable))
937 (setq separator lbs))
941 (insert (prin1-to-string cell))
942 (setq separator " ")))
943 (setq value (cdr value)))
945 (insert line-breaking)
946 (setq attributes (delq 'ideographic- attributes)))
947 (when (and (memq 'total-strokes attributes)
948 (setq value (get-char-attribute char 'total-strokes)))
949 (insert (format "(total-strokes . %S)%s"
952 (setq attributes (delq 'total-strokes attributes))
954 (when (and (memq '->ideograph attributes)
955 (setq value (get-char-attribute char '->ideograph)))
956 (insert (format "(->ideograph\t%s)%s"
957 (mapconcat (lambda (code)
958 (cond ((symbolp code)
961 (format "#x%04X" code))
964 line-breaking code))))
967 (setq attributes (delq '->ideograph attributes))
969 ;; (when (and (memq '->decomposition attributes)
970 ;; (setq value (get-char-attribute char '->decomposition)))
971 ;; (insert (format "(->decomposition\t%s)%s"
972 ;; (mapconcat (lambda (code)
973 ;; (cond ((symbolp code)
974 ;; (symbol-name code))
975 ;; ((characterp code)
977 ;; (format "%S" code)
982 ;; (format "#x%04X" code))
984 ;; (format "%s%S" line-breaking code))))
987 ;; (setq attributes (delq '->decomposition attributes))
989 (if (equal (get-char-attribute char '->titlecase)
990 (get-char-attribute char '->uppercase))
991 (setq attributes (delq '->titlecase attributes)))
992 (when (and (memq '->mojikyo attributes)
993 (setq value (get-char-attribute char '->mojikyo)))
994 (insert (format "(->mojikyo\t\t. %06d)\t; %c%s"
995 value (decode-char 'mojikyo value)
997 (setq attributes (delq '->mojikyo attributes))
999 (when (and (memq 'hanyu-dazidian-vol attributes)
1000 (setq value (get-char-attribute char 'hanyu-dazidian-vol)))
1001 (insert (format "(hanyu-dazidian-vol . %d)%s"
1002 value line-breaking))
1003 (setq attributes (delq 'hanyu-dazidian-vol attributes))
1005 (when (and (memq 'hanyu-dazidian-page attributes)
1006 (setq value (get-char-attribute char 'hanyu-dazidian-page)))
1007 (insert (format "(hanyu-dazidian-page . %d)%s"
1008 value line-breaking))
1009 (setq attributes (delq 'hanyu-dazidian-page attributes))
1011 (when (and (memq 'hanyu-dazidian-char attributes)
1012 (setq value (get-char-attribute char 'hanyu-dazidian-char)))
1013 (insert (format "(hanyu-dazidian-char . %d)%s"
1014 value line-breaking))
1015 (setq attributes (delq 'hanyu-dazidian-char attributes))
1018 (dolist (ignored '(composition
1019 ->denotational <-subsumptive ->ucs-unified
1020 ->ideographic-component-forms))
1021 (setq attributes (delq ignored attributes))))
1023 (setq name (car attributes))
1024 (if (setq value (get-char-attribute char name))
1025 (cond ((setq ret (find-charset name))
1026 (setq name (charset-name ret))
1027 (if (and (not (memq name dest-ccss))
1029 (setq value (get-char-attribute char name))
1030 (setq dest-ccss (cons name dest-ccss))))
1031 (char-db-insert-ccs-feature name value line-breaking))
1033 ((string-match "^=>ucs@" (symbol-name name))
1034 (insert (format "(%-18s . #x%04X)\t; %c%s"
1035 name value (decode-char '=ucs value)
1038 ((eq name 'jisx0208-1978/4X)
1039 (insert (format "(%-18s . #x%04X)%s"
1045 (not (eq name '->subsumptive))
1046 (not (eq name '->uppercase))
1047 (not (eq name '->lowercase))
1048 (not (eq name '->titlecase))
1049 (not (eq name '->canonical))
1050 (not (eq name '->Bopomofo))
1051 (not (eq name '->mistakable))
1052 (not (eq name '->ideographic-variants))
1053 (null (get-char-attribute
1054 char (intern (format "%s*sources" name))))
1055 (not (string-match "\\*sources$" (symbol-name name)))
1056 (null (get-char-attribute
1057 char (intern (format "%s*note" name))))
1058 (not (string-match "\\*note$" (symbol-name name)))
1059 (or (eq name '<-identical)
1060 (eq name '<-uppercase)
1061 (eq name '<-lowercase)
1062 (eq name '<-titlecase)
1063 (eq name '<-canonical)
1064 (eq name '<-ideographic-variants)
1065 ;; (eq name '<-synonyms)
1066 (string-match "^<-synonyms" (symbol-name name))
1067 (eq name '<-mistakable)
1068 (when (string-match "^->" (symbol-name name))
1070 ((string-match "^->fullwidth" (symbol-name name))
1071 (not (and (consp value)
1072 (characterp (car value))
1074 (car value) '=ucs 'defined-only)))
1079 ((or (eq name 'ideographic-structure)
1080 (eq name 'ideographic-combination)
1081 (eq name 'ideographic-)
1082 (eq name '=decomposition)
1083 (string-match "^=>decomposition" (symbol-name name))
1084 (string-match "^\\(->\\|<-\\)[^*]*$" (symbol-name name))
1085 (string-match "^\\(->\\|<-\\)[^*]*\\*sources$"
1088 (char-db-insert-relation-feature char name value
1091 ((memq name '(ideograph=
1092 original-ideograph-of
1093 ancient-ideograph-of
1096 ;; simplified-ideograph-of
1097 ideographic-variants
1098 ;; ideographic-different-form-of
1100 (insert (format "(%-18s%s " name line-breaking))
1101 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1103 (while (consp value)
1104 (setq cell (car value))
1105 (if (and (consp cell)
1110 (char-db-insert-alist cell readable)
1111 (setq separator lbs))
1114 (insert (prin1-to-string cell))
1115 (setq separator " "))
1116 (setq value (cdr value)))
1118 (insert line-breaking))
1120 (insert (format "(%-18s " name))
1121 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1123 (while (consp value)
1124 (setq cell (car value))
1125 (if (and (consp cell)
1127 (setq ret (condition-case nil
1135 (setq key (car (car rest)))
1136 (if (find-charset key)
1137 (setq cal (cons key cal))
1138 (setq al (cons key al)))
1139 (setq rest (cdr rest)))
1142 (insert-char-attributes ret
1145 (setq separator lbs))
1146 (setq ret (prin1-to-string cell))
1148 (if (< (+ (current-column)
1155 (setq separator " "))
1156 (setq value (cdr value)))
1158 (insert line-breaking))
1160 (insert (format "(%-18s" name))
1161 (setq ret (prin1-to-string value))
1162 (unless (< (+ (current-column)
1166 (insert line-breaking))
1167 (insert " . " ret ")" line-breaking)
1168 ;; (insert (format "(%-18s . %S)%s"
1173 (setq attributes (cdr attributes)))
1176 (defun insert-char-data (char &optional readable
1179 (narrow-to-region (point)(point))
1180 (insert "(define-char
1182 (insert-char-attributes char readable attributes)
1184 (goto-char (point-min))
1185 (while (re-search-forward "[ \t]+$" nil t)
1188 (goto-char (point-min))
1189 (while (re-search-forward "[ \t][ \t][ \t]*" nil t)
1190 (let ((column (current-column))
1191 (indent-tabs-mode t))
1192 (delete-region (match-beginning 0) (point))
1193 (indent-to column)))
1194 (goto-char (point-max))
1195 ;; (tabify (point-min)(point-max))
1198 (defun insert-char-data-with-variant (char &optional printable
1200 script excluded-script)
1201 (insert-char-data char printable)
1202 (let ((variants (char-variants char))
1205 (setq variants (sort variants #'<))
1206 (setq rest variants)
1207 (setq variants (cons char variants))
1209 (setq variant (car rest))
1210 (unless (get-char-attribute variant '<-subsumptive)
1211 (if (and (or (null script)
1212 (null (setq vs (get-char-attribute variant 'script)))
1214 (or (null excluded-script)
1215 (null (setq vs (get-char-attribute variant 'script)))
1216 (not (memq excluded-script vs))))
1217 (unless (and no-ucs-unified (get-char-attribute variant '=ucs))
1218 (insert-char-data variant printable)
1219 (if (setq ret (char-variants variant))
1221 (or (memq (car ret) variants)
1222 ;; (get-char-attribute (car ret) '<-subsumptive)
1223 (setq rest (nconc rest (list (car ret)))))
1224 (setq ret (cdr ret)))))))
1225 (setq rest (cdr rest)))))
1227 (defun insert-char-range-data (min max &optional script excluded-script)
1230 (while (<= code max)
1231 (setq char (decode-char '=ucs code))
1232 (if (encode-char char '=ucs 'defined-only)
1233 (insert-char-data-with-variant char nil 'no-ucs-unified
1234 script excluded-script))
1235 (setq code (1+ code)))))
1237 (defun write-char-range-data-to-file (min max file
1238 &optional script excluded-script)
1239 (let ((coding-system-for-write char-db-file-coding-system))
1241 (insert (format ";; -*- coding: %s -*-\n"
1242 char-db-file-coding-system))
1243 (insert-char-range-data min max script excluded-script)
1244 (write-region (point-min)(point-max) file))))
1246 (defvar what-character-original-window-configuration)
1249 (defun what-char-definition (char)
1250 (interactive (list (char-after)))
1251 (let ((buf (get-buffer-create "*Character Description*"))
1252 (the-buf (current-buffer))
1253 (win-conf (current-window-configuration)))
1255 (make-local-variable 'what-character-original-window-configuration)
1256 (setq what-character-original-window-configuration win-conf)
1257 (setq buffer-read-only nil)
1261 (insert-char-data-with-variant char 'printable)
1262 (unless (char-attribute-alist char)
1263 (insert (format ";; = %c\n"
1264 (let* ((rest (split-char char))
1268 (setq code (logior (lsh code 8)
1270 (decode-char ccs code)))))
1271 ;; (char-db-update-comment)
1272 (set-buffer-modified-p nil)
1273 (view-mode the-buf (lambda (buf)
1274 (set-window-configuration
1275 what-character-original-window-configuration)
1277 (goto-char (point-min)))
1279 (set-window-configuration
1280 what-character-original-window-configuration)
1281 (signal (car err) (cdr err)))))))
1287 (provide 'char-db-util)
1289 ;;; char-db-util.el ends here