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
191 ;;; @ char-db formatters
194 (defun char-db-make-char-spec (char)
196 (cond ((characterp char)
197 (cond ((and (setq ret (encode-char char '=ucs 'defined-only))
198 (not (and (<= #xE000 ret)(<= ret #xF8FF))))
199 (setq char-spec (list (cons '=ucs ret)))
200 (cond ((setq ret (get-char-attribute char 'name))
201 (setq char-spec (cons (cons 'name ret) char-spec))
203 ((setq ret (get-char-attribute char 'name*))
204 (setq char-spec (cons (cons 'name* ret) char-spec))
209 (let ((rest char-db-coded-charset-priority-list)
212 (setq ccs (charset-name
213 (find-charset (car rest))))
215 (encode-char char ccs
217 (throw 'tag (cons ccs ret)))
218 (setq rest (cdr rest))))))
219 (setq char-spec (list ret))
220 (dolist (ccs (delq (car ret) (charset-list)))
221 (if (and (or (charset-iso-final-char ccs)
228 (string-match "=ucs@" (symbol-name ccs)))
229 (setq ccs (charset-name ccs))
230 (null (assq ccs char-spec))
231 (setq ret (encode-char char ccs 'defined-only)))
232 (setq char-spec (cons (cons ccs ret) char-spec))))
234 (setq char-spec (split-char char)))
235 (cond ((setq ret (get-char-attribute char 'name))
236 (setq char-spec (cons (cons 'name ret) char-spec))
238 ((setq ret (get-char-attribute char 'name*))
239 (setq char-spec (cons (cons 'name* ret) char-spec))
242 ((setq ret (get-char-attribute
243 char 'ideographic-combination))
245 (cons (cons 'ideographic-combination ret)
252 (defun char-db-insert-char-spec (char &optional readable column
255 (setq column (current-column)))
256 (let (char-spec temp-char)
257 (setq char-spec (char-db-make-char-spec char))
258 (unless (or (characterp char) ; char
260 (setq char (find-char char-spec))
262 ;; define temporary character
263 ;; Current implementation is dirty.
264 (setq temp-char (define-char (cons '(ideograph-daikanwa . 0)
266 (remove-char-attribute temp-char 'ideograph-daikanwa)
267 (setq char temp-char))
268 (insert-char-attributes char
270 (union (mapcar #'car char-spec)
273 ;; undefine temporary character
274 ;; Current implementation is dirty.
275 (setq char-spec (char-attribute-alist temp-char))
277 (remove-char-attribute temp-char (car (car char-spec)))
278 (setq char-spec (cdr char-spec))))))
280 (defun char-db-insert-alist (alist &optional readable column)
282 (setq column (current-column)))
284 (concat "\n" (make-string (1+ column) ?\ )))
288 lbs cell rest separator)
291 (setq name (car (car alist))
292 value (cdr (car alist)))
293 (cond ((eq name 'char)
295 (if (setq ret (condition-case nil
303 (setq key (car (car value)))
304 ;; (if (find-charset key)
305 ;; (setq cal (cons key cal))
306 (setq al (cons key al))
308 (setq value (cdr value)))
309 (insert-char-attributes ret
313 (insert (prin1-to-string value)))
315 (insert line-breaking))
317 (insert (format "(%-18s " name))
318 (setq lbs (concat "\n" (make-string (current-column) ?\ )))
320 (setq cell (car value))
321 (if (and (consp cell)
323 (setq ret (condition-case nil
333 (setq key (car (car rest)))
334 ;; (if (find-charset key)
335 ;; (setq cal (cons key cal))
336 (setq al (cons key al))
338 (setq rest (cdr rest)))
341 (insert-char-attributes ret
345 (setq separator lbs))
348 (insert (prin1-to-string cell))
349 (setq separator " "))
350 (setq value (cdr value)))
352 (insert line-breaking))
354 (insert (format "(%-18s . %S)%s"
357 (setq alist (cdr alist))))
360 (defun char-db-insert-char-reference (plist &optional readable column)
362 (setq column (current-column)))
364 (concat "\n" (make-string (1+ column) ?\ )))
369 (setq name (pop plist))
370 (setq value (pop plist))
371 (cond ((eq name :char)
374 (cond ((numberp value)
375 (setq value (decode-char '=ucs value)))
377 ;; (setq value (or (find-char value)
380 (char-db-insert-char-spec value readable)
381 (insert line-breaking)
384 (insert (format "%s%s\t%d ; %c%s"
387 (ideographic-radical value)
391 (insert (format "%s%s\t%S" separator name value))
392 (setq separator line-breaking)))
396 (defun char-db-decode-isolated-char (ccs code-point)
399 (cond ((eq ccs 'arabic-iso8859-6)
400 (decode-char ccs code-point))
401 ((and (memq ccs '(=gt-pj-1
412 (setq ret (decode-char ccs code-point))
413 (setq ret (encode-char ret '=gt 'defined-only)))
414 (decode-builtin-char '=gt ret))
416 (decode-builtin-char ccs code-point))))
417 (cond ((and (<= 0 (char-int ret))
418 (<= (char-int ret) #x1F))
419 (decode-char '=ucs (+ #x2400 (char-int ret))))
420 ((= (char-int ret) #x7F)
424 (defvar char-db-convert-obsolete-format t)
426 (defun char-db-insert-ccs-feature (name value line-breaking)
429 (cond ((memq name '(=shinjigen
431 =shinjigen@rev =shinjigen/+p@rev))
432 "(%-18s . %04d)\t; %c")
433 ((eq name '=shinjigen@1ed/24pr)
434 "(%-18s . %04d)\t; %c")
435 ((or (memq name '(=daikanwa
436 =daikanwa@rev1 =daikanwa@rev2
438 =gt =>>gt =>gt =gt-k =>>gt-k =cbeta
439 =zinbun-oracle =>zinbun-oracle))
440 (string-match "^=adobe-" (symbol-name name)))
441 "(%-18s . %05d)\t; %c")
443 "(%-18s . %06d)\t; %c")
444 ((>= (charset-dimension name) 2)
445 "(%-18s . #x%04X)\t; %c")
447 "(%-18s . #x%02X)\t; %c"))
449 (if (= (charset-iso-graphic-plane name) 1)
451 (cond ((= (charset-dimension name) 1)
453 ((= (charset-dimension name) 2)
455 ((= (charset-dimension name) 3)
459 (char-db-decode-isolated-char name value)))
460 (if (and (= (charset-chars name) 94)
461 (= (charset-dimension name) 2))
462 (insert (format " [%02d-%02d]"
463 (- (lsh value -8) 32)
464 (- (logand value 255) 32))))
465 (insert line-breaking))
467 (defun char-db-insert-relation-feature (char name value line-breaking
469 (insert (format "(%-18s%s " name line-breaking))
470 (let ((lbs (concat "\n" (make-string (current-column) ?\ )))
471 separator cell sources required-features
474 (setq cell (car value))
476 (setq cell (decode-char '=ucs cell)))
478 ((eq name '->subsumptive)
479 (when (or (not (some (lambda (atr)
480 (get-char-attribute cell atr))
481 char-db-ignored-attributes))
483 (encode-char cell ccs 'defined-only))
487 (let ((char-db-ignored-attributes
489 char-db-ignored-attributes)))
490 (insert-char-attributes cell readable))
491 (setq separator lbs))
496 char (intern (format "%s*sources" name))))
497 (setq required-features nil)
498 (dolist (source sources)
502 shinjigen shinjigen@1ed shinjigen@rev))
503 (setq required-features
504 (union required-features
514 (setq required-features
515 (union required-features
520 ((find-charset (setq ret (intern (format "=%s" source))))
521 (setq required-features
522 (cons ret required-features)))
523 (t (setq required-features
524 (cons source required-features)))))
525 (cond ((string-match "@JP" (symbol-name name))
526 (setq required-features
527 (union required-features
535 ((string-match "@CN" (symbol-name name))
536 (setq required-features
537 (union required-features
544 (insert (format "%S" cell))
545 (char-db-insert-char-spec cell readable
548 (setq separator lbs))
552 (if (consp (car cell))
553 (char-db-insert-char-spec cell readable)
554 (char-db-insert-char-reference cell readable))
555 (setq separator lbs))
559 (insert (prin1-to-string cell))
560 (setq separator " ")))
561 (setq value (cdr value)))
563 (insert line-breaking)))
565 (defun insert-char-attributes (char &optional readable attributes column)
567 (setq column (current-column)))
568 (let (name value ; has-long-ccs-name
572 (concat "\n" (make-string (1+ column) ?\ )))
573 lbs cell separator ret
575 dest-ccss ; sources required-features
580 (if (consp attributes)
582 (dolist (name attributes)
583 (unless (memq name char-db-ignored-attributes)
584 (if (find-charset name)
588 (dolist (name (char-attribute-list))
589 (unless (memq name char-db-ignored-attributes)
590 (if (find-charset name)
594 #'char-attribute-name<)))
596 (when (memq '<-subsumptive attributes)
598 (when (setq value (get-char-attribute char '<-subsumptive))
599 (char-db-insert-relation-feature char '<-subsumptive value
602 (setq attributes (delq '<-subsumptive attributes)))
603 (when (and (memq '<-denotational attributes)
604 (setq value (get-char-attribute char '<-denotational)))
605 (char-db-insert-relation-feature char '<-denotational value
608 (setq attributes (delq '<-denotational attributes)))
609 (when (and (memq 'name attributes)
610 (setq value (get-char-attribute char 'name)))
612 (if (> (+ (current-column) (length value)) 48)
615 value line-breaking))
616 (setq attributes (delq 'name attributes))
618 (when (and (memq 'name* attributes)
619 (setq value (get-char-attribute char 'name*)))
621 (if (> (+ (current-column) (length value)) 48)
624 value line-breaking))
625 (setq attributes (delq 'name* attributes))
627 (when (and (memq 'script attributes)
628 (setq value (get-char-attribute char 'script)))
629 (insert (format "(script\t\t%s)%s"
630 (mapconcat (function prin1-to-string)
633 (setq attributes (delq 'script attributes))
635 (dolist (name '(=>ucs =>ucs*))
636 (when (and (memq name attributes)
637 (setq value (get-char-attribute char name)))
638 (insert (format "(%-18s . #x%04X)\t; %c%s"
639 name value (decode-char '=ucs value)
641 (setq attributes (delq name attributes))))
642 (dolist (name '(=>ucs@gb =>ucs@cns =>ucs@jis =>ucs@ks =>ucs@big5))
643 (when (and (memq name attributes)
644 (setq value (get-char-attribute char name)))
645 (insert (format "(%-18s . #x%04X)\t; %c%s"
650 (symbol-name name) 2)))
653 (setq attributes (delq name attributes))
655 ;; (dolist (name '(=>daikanwa))
656 ;; (when (and (memq name attributes)
657 ;; (setq value (get-char-attribute char name)))
659 ;; (if (integerp value)
660 ;; (format "(%-18s . %05d)\t; %c%s"
661 ;; name value (decode-char '=daikanwa value)
663 ;; (format "(%-18s %s)\t; %c%s"
665 ;; (mapconcat (function prin1-to-string)
667 ;; (char-representative-of-daikanwa char)
669 ;; (setq attributes (delq name attributes))))
670 (when (and (memq 'general-category attributes)
671 (setq value (get-char-attribute char 'general-category)))
673 "(general-category\t%s) ; %s%s"
674 (mapconcat (lambda (cell)
677 (cond ((rassoc value unidata-normative-category-alist)
678 "Normative Category")
679 ((rassoc value unidata-informative-category-alist)
680 "Informative Category")
684 (setq attributes (delq 'general-category attributes))
686 (when (and (memq 'bidi-category attributes)
687 (setq value (get-char-attribute char 'bidi-category)))
688 (insert (format "(bidi-category\t. %S)%s"
691 (setq attributes (delq 'bidi-category attributes))
693 (unless (or (not (memq 'mirrored attributes))
694 (eq (setq value (get-char-attribute char 'mirrored 'empty))
696 (insert (format "(mirrored\t\t. %S)%s"
699 (setq attributes (delq 'mirrored attributes))
702 ((and (memq 'decimal-digit-value attributes)
703 (setq value (get-char-attribute char 'decimal-digit-value)))
704 (insert (format "(decimal-digit-value . %S)%s"
707 (setq attributes (delq 'decimal-digit-value attributes))
708 (when (and (memq 'digit-value attributes)
709 (setq value (get-char-attribute char 'digit-value)))
710 (insert (format "(digit-value\t . %S)%s"
713 (setq attributes (delq 'digit-value attributes))
715 (when (and (memq 'numeric-value attributes)
716 (setq value (get-char-attribute char 'numeric-value)))
717 (insert (format "(numeric-value\t . %S)%s"
720 (setq attributes (delq 'numeric-value attributes))
724 (when (and (memq 'digit-value attributes)
725 (setq value (get-char-attribute char 'digit-value)))
726 (insert (format "(digit-value\t. %S)%s"
729 (setq attributes (delq 'digit-value attributes))
731 (when (and (memq 'numeric-value attributes)
732 (setq value (get-char-attribute char 'numeric-value)))
733 (insert (format "(numeric-value\t. %S)%s"
736 (setq attributes (delq 'numeric-value attributes))
738 (when (and (memq 'iso-10646-comment attributes)
739 (setq value (get-char-attribute char 'iso-10646-comment)))
740 (insert (format "(iso-10646-comment\t. %S)%s"
743 (setq attributes (delq 'iso-10646-comment attributes))
745 (when (and (memq 'morohashi-daikanwa attributes)
746 (setq value (get-char-attribute char 'morohashi-daikanwa)))
747 (insert (format "(morohashi-daikanwa\t%s)%s"
748 (mapconcat (function prin1-to-string) value " ")
750 (setq attributes (delq 'morohashi-daikanwa attributes))
754 (when (and (memq 'ideographic-radical attributes)
755 (setq value (get-char-attribute char 'ideographic-radical)))
757 (insert (format "(ideographic-radical . %S)\t; %c%s"
759 (ideographic-radical radical)
761 (setq attributes (delq 'ideographic-radical attributes))
763 (when (and (memq 'shuowen-radical attributes)
764 (setq value (get-char-attribute char 'shuowen-radical)))
765 (insert (format "(shuowen-radical\t. %S)\t; %c%s"
767 (shuowen-radical value)
769 (setq attributes (delq 'shuowen-radical attributes))
774 char-db-feature-domains
776 (dolist (feature (char-attribute-list))
777 (setq feature (symbol-name feature))
779 "\\(radical\\|strokes\\)@\\([^@*]+\\)\\(\\*\\|$\\)"
781 (setq domain (intern (match-string 2 feature)))
782 (unless (memq domain dest)
783 (setq dest (cons domain dest)))))
784 (sort dest #'string<))))
785 (setq key (intern (format "%s@%s" 'ideographic-radical domain)))
786 (when (and (memq key attributes)
787 (setq value (get-char-attribute char key)))
789 (insert (format "(%s . %S)\t; %c%s"
792 (ideographic-radical radical)
794 (setq attributes (delq key attributes))
796 (setq key (intern (format "%s@%s" 'ideographic-strokes domain)))
797 (when (and (memq key attributes)
798 (setq value (get-char-attribute char key)))
800 (insert (format "(%s . %S)%s"
804 (setq attributes (delq key attributes))
806 (setq key (intern (format "%s@%s" 'total-strokes domain)))
807 (when (and (memq key attributes)
808 (setq value (get-char-attribute char key)))
809 (insert (format "(%s . %S)%s"
813 (setq attributes (delq key attributes))
815 (dolist (feature '(ideographic-radical
818 (setq key (intern (format "%s@%s*sources" feature domain)))
819 (when (and (memq key attributes)
820 (setq value (get-char-attribute char key)))
821 (insert (format "(%s%s" key line-breaking))
823 (insert (format " %s" cell)))
825 (insert line-breaking)
826 (setq attributes (delq key attributes))
829 (when (and (memq 'ideographic-strokes attributes)
830 (setq value (get-char-attribute char 'ideographic-strokes)))
832 (insert (format "(ideographic-strokes . %S)%s"
835 (setq attributes (delq 'ideographic-strokes attributes))
837 (when (and (memq 'kangxi-radical attributes)
838 (setq value (get-char-attribute char 'kangxi-radical)))
839 (unless (eq value radical)
840 (insert (format "(kangxi-radical\t . %S)\t; %c%s"
842 (ideographic-radical value)
845 (setq radical value)))
846 (setq attributes (delq 'kangxi-radical attributes))
848 (when (and (memq 'kangxi-strokes attributes)
849 (setq value (get-char-attribute char 'kangxi-strokes)))
850 (unless (eq value strokes)
851 (insert (format "(kangxi-strokes\t . %S)%s"
855 (setq strokes value)))
856 (setq attributes (delq 'kangxi-strokes attributes))
858 (when (and (memq 'japanese-radical attributes)
859 (setq value (get-char-attribute char 'japanese-radical)))
860 (unless (eq value radical)
861 (insert (format "(japanese-radical\t . %S)\t; %c%s"
863 (ideographic-radical value)
866 (setq radical value)))
867 (setq attributes (delq 'japanese-radical attributes))
869 (when (and (memq 'japanese-strokes attributes)
870 (setq value (get-char-attribute char 'japanese-strokes)))
871 (unless (eq value strokes)
872 (insert (format "(japanese-strokes\t . %S)%s"
876 (setq strokes value)))
877 (setq attributes (delq 'japanese-strokes attributes))
879 (when (and (memq 'cns-radical attributes)
880 (setq value (get-char-attribute char 'cns-radical)))
881 (insert (format "(cns-radical\t . %S)\t; %c%s"
883 (ideographic-radical value)
885 (setq attributes (delq 'cns-radical attributes))
887 (when (and (memq 'cns-strokes attributes)
888 (setq value (get-char-attribute char 'cns-strokes)))
889 (unless (eq value strokes)
890 (insert (format "(cns-strokes\t . %S)%s"
894 (setq strokes value)))
895 (setq attributes (delq 'cns-strokes attributes))
897 (when (and (memq 'shinjigen-1-radical attributes)
898 (setq value (get-char-attribute char 'shinjigen-1-radical)))
899 (unless (eq value radical)
900 (insert (format "(shinjigen-1-radical . %S)\t; %c%s"
902 (ideographic-radical value)
905 (setq radical value)))
906 (setq attributes (delq 'shinjigen-1-radical attributes))
908 (when (and (memq 'ideographic- attributes)
909 (setq value (get-char-attribute char 'ideographic-)))
910 (insert "(ideographic- ")
911 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
914 (setq cell (car value))
916 (setq cell (decode-char '=ucs cell)))
917 (cond ((characterp cell)
921 (insert (format "%S" cell))
922 (char-db-insert-char-spec cell readable))
923 (setq separator lbs))
927 (if (consp (car cell))
928 (char-db-insert-char-spec cell readable)
929 (char-db-insert-char-reference cell readable))
930 (setq separator lbs))
934 (insert (prin1-to-string cell))
935 (setq separator " ")))
936 (setq value (cdr value)))
938 (insert line-breaking)
939 (setq attributes (delq 'ideographic- attributes)))
940 (when (and (memq 'total-strokes attributes)
941 (setq value (get-char-attribute char 'total-strokes)))
942 (insert (format "(total-strokes . %S)%s"
945 (setq attributes (delq 'total-strokes attributes))
947 (when (and (memq '->ideograph attributes)
948 (setq value (get-char-attribute char '->ideograph)))
949 (insert (format "(->ideograph\t%s)%s"
950 (mapconcat (lambda (code)
951 (cond ((symbolp code)
954 (format "#x%04X" code))
957 line-breaking code))))
960 (setq attributes (delq '->ideograph attributes))
962 ;; (when (and (memq '->decomposition attributes)
963 ;; (setq value (get-char-attribute char '->decomposition)))
964 ;; (insert (format "(->decomposition\t%s)%s"
965 ;; (mapconcat (lambda (code)
966 ;; (cond ((symbolp code)
967 ;; (symbol-name code))
968 ;; ((characterp code)
970 ;; (format "%S" code)
975 ;; (format "#x%04X" code))
977 ;; (format "%s%S" line-breaking code))))
980 ;; (setq attributes (delq '->decomposition attributes))
982 (if (equal (get-char-attribute char '->titlecase)
983 (get-char-attribute char '->uppercase))
984 (setq attributes (delq '->titlecase attributes)))
985 (when (and (memq '->mojikyo attributes)
986 (setq value (get-char-attribute char '->mojikyo)))
987 (insert (format "(->mojikyo\t\t. %06d)\t; %c%s"
988 value (decode-char 'mojikyo value)
990 (setq attributes (delq '->mojikyo attributes))
992 (when (and (memq 'hanyu-dazidian-vol attributes)
993 (setq value (get-char-attribute char 'hanyu-dazidian-vol)))
994 (insert (format "(hanyu-dazidian-vol . %d)%s"
995 value line-breaking))
996 (setq attributes (delq 'hanyu-dazidian-vol attributes))
998 (when (and (memq 'hanyu-dazidian-page attributes)
999 (setq value (get-char-attribute char 'hanyu-dazidian-page)))
1000 (insert (format "(hanyu-dazidian-page . %d)%s"
1001 value line-breaking))
1002 (setq attributes (delq 'hanyu-dazidian-page attributes))
1004 (when (and (memq 'hanyu-dazidian-char attributes)
1005 (setq value (get-char-attribute char 'hanyu-dazidian-char)))
1006 (insert (format "(hanyu-dazidian-char . %d)%s"
1007 value line-breaking))
1008 (setq attributes (delq 'hanyu-dazidian-char attributes))
1011 (dolist (ignored '(composition
1012 ->denotational <-subsumptive ->ucs-unified
1013 ->ideographic-component-forms))
1014 (setq attributes (delq ignored attributes))))
1016 (setq name (car attributes))
1017 (if (setq value (get-char-attribute char name))
1018 (cond ((setq ret (find-charset name))
1019 (setq name (charset-name ret))
1020 (if (and (not (memq name dest-ccss))
1022 (setq value (get-char-attribute char name))
1023 (setq dest-ccss (cons name dest-ccss))))
1024 (char-db-insert-ccs-feature name value line-breaking))
1026 ((string-match "^=>ucs@" (symbol-name name))
1027 (insert (format "(%-18s . #x%04X)\t; %c%s"
1028 name value (decode-char '=ucs value)
1031 ((eq name 'jisx0208-1978/4X)
1032 (insert (format "(%-18s . #x%04X)%s"
1038 (not (eq name '->subsumptive))
1039 (not (eq name '->uppercase))
1040 (not (eq name '->lowercase))
1041 (not (eq name '->titlecase))
1042 (not (eq name '->canonical))
1043 (not (eq name '->Bopomofo))
1044 (not (eq name '->mistakable))
1045 (not (eq name '->ideographic-variants))
1046 (null (get-char-attribute
1047 char (intern (format "%s*sources" name))))
1048 (not (string-match "\\*sources$" (symbol-name name)))
1049 (null (get-char-attribute
1050 char (intern (format "%s*note" name))))
1051 (not (string-match "\\*note$" (symbol-name name)))
1052 (or (eq name '<-identical)
1053 (eq name '<-uppercase)
1054 (eq name '<-lowercase)
1055 (eq name '<-titlecase)
1056 (eq name '<-canonical)
1057 (eq name '<-ideographic-variants)
1058 ;; (eq name '<-synonyms)
1059 (string-match "^<-synonyms" (symbol-name name))
1060 (eq name '<-mistakable)
1061 (when (string-match "^->" (symbol-name name))
1063 ((string-match "^->fullwidth" (symbol-name name))
1064 (not (and (consp value)
1065 (characterp (car value))
1067 (car value) '=ucs 'defined-only)))
1072 ((or (eq name 'ideographic-structure)
1073 (eq name 'ideographic-combination)
1074 (eq name 'ideographic-)
1075 (eq name '=decomposition)
1076 (string-match "^=>decomposition" (symbol-name name))
1077 (string-match "^\\(->\\|<-\\)[^*]*$" (symbol-name name))
1078 (string-match "^\\(->\\|<-\\)[^*]*\\*sources$"
1081 (char-db-insert-relation-feature char name value
1084 ((memq name '(ideograph=
1085 original-ideograph-of
1086 ancient-ideograph-of
1089 ;; simplified-ideograph-of
1090 ideographic-variants
1091 ;; ideographic-different-form-of
1093 (insert (format "(%-18s%s " name line-breaking))
1094 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1096 (while (consp value)
1097 (setq cell (car value))
1098 (if (and (consp cell)
1103 (char-db-insert-alist cell readable)
1104 (setq separator lbs))
1107 (insert (prin1-to-string cell))
1108 (setq separator " "))
1109 (setq value (cdr value)))
1111 (insert line-breaking))
1113 (insert (format "(%-18s " name))
1114 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1116 (while (consp value)
1117 (setq cell (car value))
1118 (if (and (consp cell)
1120 (setq ret (condition-case nil
1128 (setq key (car (car rest)))
1129 (if (find-charset key)
1130 (setq cal (cons key cal))
1131 (setq al (cons key al)))
1132 (setq rest (cdr rest)))
1135 (insert-char-attributes ret
1138 (setq separator lbs))
1139 (setq ret (prin1-to-string cell))
1141 (if (< (+ (current-column)
1148 (setq separator " "))
1149 (setq value (cdr value)))
1151 (insert line-breaking))
1153 (insert (format "(%-18s" name))
1154 (setq ret (prin1-to-string value))
1155 (unless (< (+ (current-column)
1159 (insert line-breaking))
1160 (insert " . " ret ")" line-breaking)
1161 ;; (insert (format "(%-18s . %S)%s"
1166 (setq attributes (cdr attributes)))
1169 (defun insert-char-data (char &optional readable
1172 (narrow-to-region (point)(point))
1173 (insert "(define-char
1175 (insert-char-attributes char readable attributes)
1177 (goto-char (point-min))
1178 (while (re-search-forward "[ \t]+$" nil t)
1181 (goto-char (point-min))
1182 (while (re-search-forward "[ \t][ \t][ \t]*" nil t)
1183 (let ((column (current-column))
1184 (indent-tabs-mode t))
1185 (delete-region (match-beginning 0) (point))
1186 (indent-to column)))
1187 (goto-char (point-max))
1188 ;; (tabify (point-min)(point-max))
1191 (defun insert-char-data-with-variant (char &optional printable
1193 script excluded-script)
1194 (insert-char-data char printable)
1195 (let ((variants (char-variants char))
1198 (setq variants (sort variants #'<))
1199 (setq rest variants)
1200 (setq variants (cons char variants))
1202 (setq variant (car rest))
1203 (unless (get-char-attribute variant '<-subsumptive)
1204 (if (and (or (null script)
1205 (null (setq vs (get-char-attribute variant 'script)))
1207 (or (null excluded-script)
1208 (null (setq vs (get-char-attribute variant 'script)))
1209 (not (memq excluded-script vs))))
1210 (unless (and no-ucs-unified (get-char-attribute variant '=ucs))
1211 (insert-char-data variant printable)
1212 (if (setq ret (char-variants variant))
1214 (or (memq (car ret) variants)
1215 ;; (get-char-attribute (car ret) '<-subsumptive)
1216 (setq rest (nconc rest (list (car ret)))))
1217 (setq ret (cdr ret)))))))
1218 (setq rest (cdr rest)))))
1220 (defun insert-char-range-data (min max &optional script excluded-script)
1223 (while (<= code max)
1224 (setq char (decode-char '=ucs code))
1225 (if (encode-char char '=ucs 'defined-only)
1226 (insert-char-data-with-variant char nil 'no-ucs-unified
1227 script excluded-script))
1228 (setq code (1+ code)))))
1230 (defun write-char-range-data-to-file (min max file
1231 &optional script excluded-script)
1232 (let ((coding-system-for-write char-db-file-coding-system))
1234 (insert (format ";; -*- coding: %s -*-\n"
1235 char-db-file-coding-system))
1236 (insert-char-range-data min max script excluded-script)
1237 (write-region (point-min)(point-max) file))))
1239 (defvar what-character-original-window-configuration)
1242 (defun what-char-definition (char)
1243 (interactive (list (char-after)))
1244 (let ((buf (get-buffer-create "*Character Description*"))
1245 (the-buf (current-buffer))
1246 (win-conf (current-window-configuration)))
1248 (make-local-variable 'what-character-original-window-configuration)
1249 (setq what-character-original-window-configuration win-conf)
1250 (setq buffer-read-only nil)
1254 (insert-char-data-with-variant char 'printable)
1255 (unless (char-attribute-alist char)
1256 (insert (format ";; = %c\n"
1257 (let* ((rest (split-char char))
1261 (setq code (logior (lsh code 8)
1263 (decode-char ccs code)))))
1264 ;; (char-db-update-comment)
1265 (set-buffer-modified-p nil)
1266 (view-mode the-buf (lambda (buf)
1267 (set-window-configuration
1268 what-character-original-window-configuration)
1270 (goto-char (point-min)))
1272 (set-window-configuration
1273 what-character-original-window-configuration)
1274 (signal (car err) (cdr err)))))))
1280 (provide 'char-db-util)
1282 ;;; char-db-util.el ends here