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
201 ;;; @ char-db formatters
204 (defun char-db-make-char-spec (char)
206 (cond ((characterp char)
207 (cond ((and (setq ret (encode-char char '=ucs 'defined-only))
208 (not (and (<= #xE000 ret)(<= ret #xF8FF))))
209 (setq char-spec (list (cons '=ucs ret)))
210 (cond ((setq ret (get-char-attribute char 'name))
211 (setq char-spec (cons (cons 'name ret) char-spec))
213 ((setq ret (get-char-attribute char 'name*))
214 (setq char-spec (cons (cons 'name* ret) char-spec))
219 (let ((rest char-db-coded-charset-priority-list)
222 (setq ccs (charset-name
223 (find-charset (car rest))))
225 (encode-char char ccs
227 (throw 'tag (cons ccs ret)))
228 (setq rest (cdr rest))))))
229 (setq char-spec (list ret))
230 (dolist (ccs (delq (car ret) (charset-list)))
231 (if (and (or (charset-iso-final-char ccs)
238 (string-match "=ucs@" (symbol-name ccs)))
239 (setq ccs (charset-name ccs))
240 (null (assq ccs char-spec))
241 (setq ret (encode-char char ccs 'defined-only)))
242 (setq char-spec (cons (cons ccs ret) char-spec))))
244 (setq char-spec (split-char char)))
245 (cond ((setq ret (get-char-attribute char 'name))
246 (setq char-spec (cons (cons 'name ret) char-spec))
248 ((setq ret (get-char-attribute char 'name*))
249 (setq char-spec (cons (cons 'name* ret) char-spec))
252 ((setq ret (get-char-attribute
253 char 'ideographic-combination))
255 (cons (cons 'ideographic-combination ret)
262 (defun char-db-insert-char-spec (char &optional readable column
265 (setq column (current-column)))
266 (let (char-spec temp-char)
267 (setq char-spec (char-db-make-char-spec char))
268 (unless (or (characterp char) ; char
270 (setq char (find-char char-spec))
272 ;; define temporary character
273 ;; Current implementation is dirty.
274 (setq temp-char (define-char (cons '(ideograph-daikanwa . 0)
276 (remove-char-attribute temp-char 'ideograph-daikanwa)
277 (setq char temp-char))
278 (insert-char-attributes char
280 (union (mapcar #'car char-spec)
283 ;; undefine temporary character
284 ;; Current implementation is dirty.
285 (setq char-spec (char-attribute-alist temp-char))
287 (remove-char-attribute temp-char (car (car char-spec)))
288 (setq char-spec (cdr char-spec))))))
290 (defun char-db-insert-alist (alist &optional readable column)
292 (setq column (current-column)))
294 (concat "\n" (make-string (1+ column) ?\ )))
298 lbs cell rest separator)
301 (setq name (car (car alist))
302 value (cdr (car alist)))
303 (cond ((eq name 'char)
305 (if (setq ret (condition-case nil
313 (setq key (car (car value)))
314 ;; (if (find-charset key)
315 ;; (setq cal (cons key cal))
316 (setq al (cons key al))
318 (setq value (cdr value)))
319 (insert-char-attributes ret
323 (insert (prin1-to-string value)))
325 (insert line-breaking))
327 (insert (format "(%-18s " name))
328 (setq lbs (concat "\n" (make-string (current-column) ?\ )))
330 (setq cell (car value))
331 (if (and (consp cell)
333 (setq ret (condition-case nil
343 (setq key (car (car rest)))
344 ;; (if (find-charset key)
345 ;; (setq cal (cons key cal))
346 (setq al (cons key al))
348 (setq rest (cdr rest)))
351 (insert-char-attributes ret
355 (setq separator lbs))
358 (insert (prin1-to-string cell))
359 (setq separator " "))
360 (setq value (cdr value)))
362 (insert line-breaking))
364 (insert (format "(%-18s . %S)%s"
367 (setq alist (cdr alist))))
370 (defun char-db-insert-char-reference (plist &optional readable column)
372 (setq column (current-column)))
374 (concat "\n" (make-string (1+ column) ?\ )))
379 (setq name (pop plist))
380 (setq value (pop plist))
381 (cond ((eq name :char)
384 (cond ((numberp value)
385 (setq value (decode-char '=ucs value)))
387 ;; (setq value (or (find-char value)
390 (char-db-insert-char-spec value readable)
391 (insert line-breaking)
394 (insert (format "%s%s\t%d ; %c%s"
397 (ideographic-radical value)
401 (insert (format "%s%s\t%S" separator name value))
402 (setq separator line-breaking)))
406 (defun char-db-decode-isolated-char (ccs code-point)
409 (cond ((eq ccs 'arabic-iso8859-6)
410 (decode-char ccs code-point))
411 ((and (memq ccs '(=gt-pj-1
422 (setq ret (decode-char ccs code-point))
423 (setq ret (encode-char ret '=gt 'defined-only)))
424 (decode-builtin-char '=gt ret))
426 (decode-builtin-char ccs code-point))))
427 (cond ((and (<= 0 (char-int ret))
428 (<= (char-int ret) #x1F))
429 (decode-char '=ucs (+ #x2400 (char-int ret))))
430 ((= (char-int ret) #x7F)
434 (defvar char-db-convert-obsolete-format t)
436 (defun char-db-insert-ccs-feature (name value line-breaking)
439 (cond ((memq name '(=shinjigen
441 =shinjigen@rev =shinjigen/+p@rev
443 "(%-18s . %04d)\t; %c")
444 ((eq name '=shinjigen@1ed/24pr)
445 "(%-18s . %04d)\t; %c")
446 ((or (memq name '(=daikanwa
447 =daikanwa@rev1 =daikanwa@rev2
448 =daikanwa/+p =daikanwa/+2p
449 =>>daikanwa =>daikanwa
450 =gt =>>gt =>gt =gt-k =>>gt-k =cbeta
451 =zinbun-oracle =>zinbun-oracle))
452 (string-match "^=adobe-" (symbol-name name)))
453 "(%-18s . %05d)\t; %c")
455 "(%-18s . %06d)\t; %c")
456 ((>= (charset-dimension name) 2)
457 "(%-18s . #x%04X)\t; %c")
459 "(%-18s . #x%02X)\t; %c"))
461 (if (= (charset-iso-graphic-plane name) 1)
463 (cond ((= (charset-dimension name) 1)
465 ((= (charset-dimension name) 2)
467 ((= (charset-dimension name) 3)
471 (char-db-decode-isolated-char name value)))
472 (if (and (= (charset-chars name) 94)
473 (= (charset-dimension name) 2))
474 (insert (format " [%02d-%02d]"
475 (- (lsh value -8) 32)
476 (- (logand value 255) 32))))
477 (insert line-breaking))
479 (defun char-db-insert-relation-feature (char name value line-breaking
481 (insert (format "(%-18s%s " name line-breaking))
482 (let ((lbs (concat "\n" (make-string (current-column) ?\ )))
483 separator cell sources required-features
486 (setq cell (car value))
488 (setq cell (decode-char '=ucs cell)))
490 ((eq name '->subsumptive)
491 (when (or (not (some (lambda (atr)
492 (get-char-attribute cell atr))
493 char-db-ignored-attributes))
495 (encode-char cell ccs 'defined-only))
499 (let ((char-db-ignored-attributes
501 char-db-ignored-attributes)))
502 (insert-char-attributes cell readable))
503 (setq separator lbs))
508 char (intern (format "%s*sources" name))))
509 (setq required-features nil)
510 (dolist (source sources)
514 shinjigen shinjigen@1ed shinjigen@rev))
515 (setq required-features
516 (union required-features
527 (setq required-features
528 (union required-features
533 ((find-charset (setq ret (intern (format "=%s" source))))
534 (setq required-features
535 (cons ret required-features)))
536 (t (setq required-features
537 (cons source required-features)))))
538 (cond ((string-match "@JP" (symbol-name name))
539 (setq required-features
540 (union required-features
548 ((string-match "@CN" (symbol-name name))
549 (setq required-features
550 (union required-features
557 (insert (format "%S" cell))
558 (char-db-insert-char-spec cell readable
561 (setq separator lbs))
565 (if (consp (car cell))
566 (char-db-insert-char-spec cell readable)
567 (char-db-insert-char-reference cell readable))
568 (setq separator lbs))
572 (insert (prin1-to-string cell))
573 (setq separator " ")))
574 (setq value (cdr value)))
576 (insert line-breaking)))
578 (defun insert-char-attributes (char &optional readable attributes column)
580 (setq column (current-column)))
581 (let (name value ; has-long-ccs-name
585 (concat "\n" (make-string (1+ column) ?\ )))
586 lbs cell separator ret
588 dest-ccss ; sources required-features
593 (if (consp attributes)
595 (dolist (name attributes)
596 (unless (memq name char-db-ignored-attributes)
597 (if (find-charset name)
601 (dolist (name (char-attribute-list))
602 (unless (memq name char-db-ignored-attributes)
603 (if (find-charset name)
607 #'char-attribute-name<)))
609 (when (memq '<-subsumptive attributes)
611 (when (setq value (get-char-attribute char '<-subsumptive))
612 (char-db-insert-relation-feature char '<-subsumptive value
615 (setq attributes (delq '<-subsumptive attributes)))
616 (when (and (memq '<-denotational attributes)
617 (setq value (get-char-attribute char '<-denotational)))
618 (char-db-insert-relation-feature char '<-denotational value
621 (setq attributes (delq '<-denotational attributes)))
622 (when (and (memq 'name attributes)
623 (setq value (get-char-attribute char 'name)))
625 (if (> (+ (current-column) (length value)) 48)
628 value line-breaking))
629 (setq attributes (delq 'name attributes))
631 (when (and (memq 'name* attributes)
632 (setq value (get-char-attribute char 'name*)))
634 (if (> (+ (current-column) (length value)) 48)
637 value line-breaking))
638 (setq attributes (delq 'name* attributes))
640 (when (and (memq 'script attributes)
641 (setq value (get-char-attribute char 'script)))
642 (insert (format "(script\t\t%s)%s"
643 (mapconcat (function prin1-to-string)
646 (setq attributes (delq 'script attributes))
648 (dolist (name '(=>ucs =>ucs*))
649 (when (and (memq name attributes)
650 (setq value (get-char-attribute char name)))
651 (insert (format "(%-18s . #x%04X)\t; %c%s"
652 name value (decode-char '=ucs value)
654 (setq attributes (delq name attributes))))
655 (dolist (name '(=>ucs@gb =>ucs@big5))
656 (when (and (memq name attributes)
657 (setq value (get-char-attribute char name)))
658 (insert (format "(%-18s . #x%04X)\t; %c%s"
663 (symbol-name name) 2)))
666 (setq attributes (delq name attributes))
668 ;; (dolist (name '(=>daikanwa))
669 ;; (when (and (memq name attributes)
670 ;; (setq value (get-char-attribute char name)))
672 ;; (if (integerp value)
673 ;; (format "(%-18s . %05d)\t; %c%s"
674 ;; name value (decode-char '=daikanwa value)
676 ;; (format "(%-18s %s)\t; %c%s"
678 ;; (mapconcat (function prin1-to-string)
680 ;; (char-representative-of-daikanwa char)
682 ;; (setq attributes (delq name attributes))))
683 (when (and (memq 'general-category attributes)
684 (setq value (get-char-attribute char 'general-category)))
686 "(general-category\t%s) ; %s%s"
687 (mapconcat (lambda (cell)
690 (cond ((rassoc value unidata-normative-category-alist)
691 "Normative Category")
692 ((rassoc value unidata-informative-category-alist)
693 "Informative Category")
697 (setq attributes (delq 'general-category attributes))
699 (when (and (memq 'bidi-category attributes)
700 (setq value (get-char-attribute char 'bidi-category)))
701 (insert (format "(bidi-category\t. %S)%s"
704 (setq attributes (delq 'bidi-category attributes))
706 (unless (or (not (memq 'mirrored attributes))
707 (eq (setq value (get-char-attribute char 'mirrored 'empty))
709 (insert (format "(mirrored\t\t. %S)%s"
712 (setq attributes (delq 'mirrored attributes))
715 ((and (memq 'decimal-digit-value attributes)
716 (setq value (get-char-attribute char 'decimal-digit-value)))
717 (insert (format "(decimal-digit-value . %S)%s"
720 (setq attributes (delq 'decimal-digit-value attributes))
721 (when (and (memq 'digit-value attributes)
722 (setq value (get-char-attribute char 'digit-value)))
723 (insert (format "(digit-value\t . %S)%s"
726 (setq attributes (delq 'digit-value attributes))
728 (when (and (memq 'numeric-value attributes)
729 (setq value (get-char-attribute char 'numeric-value)))
730 (insert (format "(numeric-value\t . %S)%s"
733 (setq attributes (delq 'numeric-value attributes))
737 (when (and (memq 'digit-value attributes)
738 (setq value (get-char-attribute char 'digit-value)))
739 (insert (format "(digit-value\t. %S)%s"
742 (setq attributes (delq 'digit-value attributes))
744 (when (and (memq 'numeric-value attributes)
745 (setq value (get-char-attribute char 'numeric-value)))
746 (insert (format "(numeric-value\t. %S)%s"
749 (setq attributes (delq 'numeric-value attributes))
751 (when (and (memq 'iso-10646-comment attributes)
752 (setq value (get-char-attribute char 'iso-10646-comment)))
753 (insert (format "(iso-10646-comment\t. %S)%s"
756 (setq attributes (delq 'iso-10646-comment attributes))
758 (when (and (memq 'morohashi-daikanwa attributes)
759 (setq value (get-char-attribute char 'morohashi-daikanwa)))
760 (insert (format "(morohashi-daikanwa\t%s)%s"
761 (mapconcat (function prin1-to-string) value " ")
763 (setq attributes (delq 'morohashi-daikanwa attributes))
767 (when (and (memq 'ideographic-radical attributes)
768 (setq value (get-char-attribute char 'ideographic-radical)))
770 (insert (format "(ideographic-radical . %S)\t; %c%s"
772 (ideographic-radical radical)
774 (setq attributes (delq 'ideographic-radical attributes))
776 (when (and (memq 'shuowen-radical attributes)
777 (setq value (get-char-attribute char 'shuowen-radical)))
778 (insert (format "(shuowen-radical\t. %S)\t; %c%s"
780 (shuowen-radical value)
782 (setq attributes (delq 'shuowen-radical attributes))
787 char-db-feature-domains
789 (dolist (feature (char-attribute-list))
790 (setq feature (symbol-name feature))
792 "\\(radical\\|strokes\\)@\\([^@*]+\\)\\(\\*\\|$\\)"
794 (setq domain (intern (match-string 2 feature)))
795 (unless (memq domain dest)
796 (setq dest (cons domain dest)))))
797 (sort dest #'string<))))
798 (setq key (intern (format "%s@%s" 'ideographic-radical domain)))
799 (when (and (memq key attributes)
800 (setq value (get-char-attribute char key)))
802 (insert (format "(%s . %S)\t; %c%s"
805 (ideographic-radical radical)
807 (setq attributes (delq key attributes))
809 (setq key (intern (format "%s@%s" 'ideographic-strokes domain)))
810 (when (and (memq key attributes)
811 (setq value (get-char-attribute char key)))
813 (insert (format "(%s . %S)%s"
817 (setq attributes (delq key attributes))
819 (setq key (intern (format "%s@%s" 'total-strokes domain)))
820 (when (and (memq key attributes)
821 (setq value (get-char-attribute char key)))
822 (insert (format "(%s . %S)%s"
826 (setq attributes (delq key attributes))
828 (dolist (feature '(ideographic-radical
831 (setq key (intern (format "%s@%s*sources" feature domain)))
832 (when (and (memq key attributes)
833 (setq value (get-char-attribute char key)))
834 (insert (format "(%s%s" key line-breaking))
836 (insert (format " %s" cell)))
838 (insert line-breaking)
839 (setq attributes (delq key attributes))
842 (when (and (memq 'ideographic-strokes attributes)
843 (setq value (get-char-attribute char 'ideographic-strokes)))
845 (insert (format "(ideographic-strokes . %S)%s"
848 (setq attributes (delq 'ideographic-strokes attributes))
850 (when (and (memq 'kangxi-radical attributes)
851 (setq value (get-char-attribute char 'kangxi-radical)))
852 (unless (eq value radical)
853 (insert (format "(kangxi-radical\t . %S)\t; %c%s"
855 (ideographic-radical value)
858 (setq radical value)))
859 (setq attributes (delq 'kangxi-radical attributes))
861 (when (and (memq 'kangxi-strokes attributes)
862 (setq value (get-char-attribute char 'kangxi-strokes)))
863 (unless (eq value strokes)
864 (insert (format "(kangxi-strokes\t . %S)%s"
868 (setq strokes value)))
869 (setq attributes (delq 'kangxi-strokes attributes))
871 (when (and (memq 'japanese-radical attributes)
872 (setq value (get-char-attribute char 'japanese-radical)))
873 (unless (eq value radical)
874 (insert (format "(japanese-radical\t . %S)\t; %c%s"
876 (ideographic-radical value)
879 (setq radical value)))
880 (setq attributes (delq 'japanese-radical attributes))
882 (when (and (memq 'japanese-strokes attributes)
883 (setq value (get-char-attribute char 'japanese-strokes)))
884 (unless (eq value strokes)
885 (insert (format "(japanese-strokes\t . %S)%s"
889 (setq strokes value)))
890 (setq attributes (delq 'japanese-strokes attributes))
892 (when (and (memq 'cns-radical attributes)
893 (setq value (get-char-attribute char 'cns-radical)))
894 (insert (format "(cns-radical\t . %S)\t; %c%s"
896 (ideographic-radical value)
898 (setq attributes (delq 'cns-radical attributes))
900 (when (and (memq 'cns-strokes attributes)
901 (setq value (get-char-attribute char 'cns-strokes)))
902 (unless (eq value strokes)
903 (insert (format "(cns-strokes\t . %S)%s"
907 (setq strokes value)))
908 (setq attributes (delq 'cns-strokes attributes))
910 (when (and (memq 'shinjigen-1-radical attributes)
911 (setq value (get-char-attribute char 'shinjigen-1-radical)))
912 (unless (eq value radical)
913 (insert (format "(shinjigen-1-radical . %S)\t; %c%s"
915 (ideographic-radical value)
918 (setq radical value)))
919 (setq attributes (delq 'shinjigen-1-radical attributes))
921 (when (and (memq 'ideographic- attributes)
922 (setq value (get-char-attribute char 'ideographic-)))
923 (insert "(ideographic- ")
924 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
927 (setq cell (car value))
929 (setq cell (decode-char '=ucs cell)))
930 (cond ((characterp cell)
934 (insert (format "%S" cell))
935 (char-db-insert-char-spec cell readable))
936 (setq separator lbs))
940 (if (consp (car cell))
941 (char-db-insert-char-spec cell readable)
942 (char-db-insert-char-reference cell readable))
943 (setq separator lbs))
947 (insert (prin1-to-string cell))
948 (setq separator " ")))
949 (setq value (cdr value)))
951 (insert line-breaking)
952 (setq attributes (delq 'ideographic- attributes)))
953 (when (and (memq 'total-strokes attributes)
954 (setq value (get-char-attribute char 'total-strokes)))
955 (insert (format "(total-strokes . %S)%s"
958 (setq attributes (delq 'total-strokes attributes))
960 (when (and (memq '->ideograph attributes)
961 (setq value (get-char-attribute char '->ideograph)))
962 (insert (format "(->ideograph\t%s)%s"
963 (mapconcat (lambda (code)
964 (cond ((symbolp code)
967 (format "#x%04X" code))
970 line-breaking code))))
973 (setq attributes (delq '->ideograph attributes))
975 ;; (when (and (memq '->decomposition attributes)
976 ;; (setq value (get-char-attribute char '->decomposition)))
977 ;; (insert (format "(->decomposition\t%s)%s"
978 ;; (mapconcat (lambda (code)
979 ;; (cond ((symbolp code)
980 ;; (symbol-name code))
981 ;; ((characterp code)
983 ;; (format "%S" code)
988 ;; (format "#x%04X" code))
990 ;; (format "%s%S" line-breaking code))))
993 ;; (setq attributes (delq '->decomposition attributes))
995 (if (equal (get-char-attribute char '->titlecase)
996 (get-char-attribute char '->uppercase))
997 (setq attributes (delq '->titlecase attributes)))
998 (when (and (memq '->mojikyo attributes)
999 (setq value (get-char-attribute char '->mojikyo)))
1000 (insert (format "(->mojikyo\t\t. %06d)\t; %c%s"
1001 value (decode-char 'mojikyo value)
1003 (setq attributes (delq '->mojikyo attributes))
1005 (when (and (memq 'hanyu-dazidian-vol attributes)
1006 (setq value (get-char-attribute char 'hanyu-dazidian-vol)))
1007 (insert (format "(hanyu-dazidian-vol . %d)%s"
1008 value line-breaking))
1009 (setq attributes (delq 'hanyu-dazidian-vol attributes))
1011 (when (and (memq 'hanyu-dazidian-page attributes)
1012 (setq value (get-char-attribute char 'hanyu-dazidian-page)))
1013 (insert (format "(hanyu-dazidian-page . %d)%s"
1014 value line-breaking))
1015 (setq attributes (delq 'hanyu-dazidian-page attributes))
1017 (when (and (memq 'hanyu-dazidian-char attributes)
1018 (setq value (get-char-attribute char 'hanyu-dazidian-char)))
1019 (insert (format "(hanyu-dazidian-char . %d)%s"
1020 value line-breaking))
1021 (setq attributes (delq 'hanyu-dazidian-char attributes))
1024 (dolist (ignored '(composition
1025 ->denotational <-subsumptive ->ucs-unified
1026 ->ideographic-component-forms))
1027 (setq attributes (delq ignored attributes))))
1029 (setq name (car attributes))
1030 (if (setq value (get-char-attribute char name))
1031 (cond ((setq ret (find-charset name))
1032 (setq name (charset-name ret))
1033 (if (and (not (memq name dest-ccss))
1035 (setq value (get-char-attribute char name))
1036 (setq dest-ccss (cons name dest-ccss))))
1037 (char-db-insert-ccs-feature name value line-breaking))
1039 ((string-match "^=>ucs@" (symbol-name name))
1040 (insert (format "(%-18s . #x%04X)\t; %c%s"
1041 name value (decode-char '=ucs value)
1044 ((eq name 'jisx0208-1978/4X)
1045 (insert (format "(%-18s . #x%04X)%s"
1051 (not (eq name '->subsumptive))
1052 (not (eq name '->uppercase))
1053 (not (eq name '->lowercase))
1054 (not (eq name '->titlecase))
1055 (not (eq name '->canonical))
1056 (not (eq name '->Bopomofo))
1057 (not (eq name '->mistakable))
1058 (not (eq name '->ideographic-variants))
1059 (null (get-char-attribute
1060 char (intern (format "%s*sources" name))))
1061 (not (string-match "\\*sources$" (symbol-name name)))
1062 (null (get-char-attribute
1063 char (intern (format "%s*note" name))))
1064 (not (string-match "\\*note$" (symbol-name name)))
1065 (or (eq name '<-identical)
1066 (eq name '<-uppercase)
1067 (eq name '<-lowercase)
1068 (eq name '<-titlecase)
1069 (eq name '<-canonical)
1070 (eq name '<-ideographic-variants)
1071 ;; (eq name '<-synonyms)
1072 (string-match "^<-synonyms" (symbol-name name))
1073 (eq name '<-mistakable)
1074 (when (string-match "^->" (symbol-name name))
1076 ((string-match "^->fullwidth" (symbol-name name))
1077 (not (and (consp value)
1078 (characterp (car value))
1080 (car value) '=ucs 'defined-only)))
1085 ((or (eq name 'ideographic-structure)
1086 (eq name 'ideographic-combination)
1087 (eq name 'ideographic-)
1088 (eq name '=decomposition)
1089 (string-match "^=>decomposition" (symbol-name name))
1090 (string-match "^\\(->\\|<-\\)[^*]*$" (symbol-name name))
1091 (string-match "^\\(->\\|<-\\)[^*]*\\*sources$"
1094 (char-db-insert-relation-feature char name value
1097 ((memq name '(ideograph=
1098 original-ideograph-of
1099 ancient-ideograph-of
1102 ;; simplified-ideograph-of
1103 ideographic-variants
1104 ;; ideographic-different-form-of
1106 (insert (format "(%-18s%s " name line-breaking))
1107 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1109 (while (consp value)
1110 (setq cell (car value))
1111 (if (and (consp cell)
1116 (char-db-insert-alist cell readable)
1117 (setq separator lbs))
1120 (insert (prin1-to-string cell))
1121 (setq separator " "))
1122 (setq value (cdr value)))
1124 (insert line-breaking))
1126 (insert (format "(%-18s " name))
1127 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1129 (while (consp value)
1130 (setq cell (car value))
1131 (if (and (consp cell)
1133 (setq ret (condition-case nil
1141 (setq key (car (car rest)))
1142 (if (find-charset key)
1143 (setq cal (cons key cal))
1144 (setq al (cons key al)))
1145 (setq rest (cdr rest)))
1148 (insert-char-attributes ret
1151 (setq separator lbs))
1152 (setq ret (prin1-to-string cell))
1154 (if (< (+ (current-column)
1161 (setq separator " "))
1162 (setq value (cdr value)))
1164 (insert line-breaking))
1166 (insert (format "(%-18s" name))
1167 (setq ret (prin1-to-string value))
1168 (unless (< (+ (current-column)
1172 (insert line-breaking))
1173 (insert " . " ret ")" line-breaking)
1174 ;; (insert (format "(%-18s . %S)%s"
1179 (setq attributes (cdr attributes)))
1182 (defun insert-char-data (char &optional readable
1185 (narrow-to-region (point)(point))
1186 (insert "(define-char
1188 (insert-char-attributes char readable attributes)
1190 (goto-char (point-min))
1191 (while (re-search-forward "[ \t]+$" nil t)
1194 (goto-char (point-min))
1195 (while (re-search-forward "[ \t][ \t][ \t]*" nil t)
1196 (let ((column (current-column))
1197 (indent-tabs-mode t))
1198 (delete-region (match-beginning 0) (point))
1199 (indent-to column)))
1200 (goto-char (point-max))
1201 ;; (tabify (point-min)(point-max))
1204 (defun insert-char-data-with-variant (char &optional printable
1206 script excluded-script)
1207 (insert-char-data char printable)
1208 (let ((variants (char-variants char))
1211 (setq variants (sort variants #'<))
1212 (setq rest variants)
1213 (setq variants (cons char variants))
1215 (setq variant (car rest))
1216 (unless (get-char-attribute variant '<-subsumptive)
1217 (if (and (or (null script)
1218 (null (setq vs (get-char-attribute variant 'script)))
1220 (or (null excluded-script)
1221 (null (setq vs (get-char-attribute variant 'script)))
1222 (not (memq excluded-script vs))))
1223 (unless (and no-ucs-unified (get-char-attribute variant '=ucs))
1224 (insert-char-data variant printable)
1225 (if (setq ret (char-variants variant))
1227 (or (memq (car ret) variants)
1228 ;; (get-char-attribute (car ret) '<-subsumptive)
1229 (setq rest (nconc rest (list (car ret)))))
1230 (setq ret (cdr ret)))))))
1231 (setq rest (cdr rest)))))
1233 (defun insert-char-range-data (min max &optional script excluded-script)
1236 (while (<= code max)
1237 (setq char (decode-char '=ucs code))
1238 (if (encode-char char '=ucs 'defined-only)
1239 (insert-char-data-with-variant char nil 'no-ucs-unified
1240 script excluded-script))
1241 (setq code (1+ code)))))
1243 (defun write-char-range-data-to-file (min max file
1244 &optional script excluded-script)
1245 (let ((coding-system-for-write char-db-file-coding-system))
1247 (insert (format ";; -*- coding: %s -*-\n"
1248 char-db-file-coding-system))
1249 (insert-char-range-data min max script excluded-script)
1250 (write-region (point-min)(point-max) file))))
1252 (defvar what-character-original-window-configuration)
1255 (defun what-char-definition (char)
1256 (interactive (list (char-after)))
1257 (let ((buf (get-buffer-create "*Character Description*"))
1258 (the-buf (current-buffer))
1259 (win-conf (current-window-configuration)))
1261 (make-local-variable 'what-character-original-window-configuration)
1262 (setq what-character-original-window-configuration win-conf)
1263 (setq buffer-read-only nil)
1267 (insert-char-data-with-variant char 'printable)
1268 (unless (char-attribute-alist char)
1269 (insert (format ";; = %c\n"
1270 (let* ((rest (split-char char))
1274 (setq code (logior (lsh code 8)
1276 (decode-char ccs code)))))
1277 ;; (char-db-update-comment)
1278 (set-buffer-modified-p nil)
1279 (view-mode the-buf (lambda (buf)
1280 (set-window-configuration
1281 what-character-original-window-configuration)
1283 (goto-char (point-min)))
1285 (set-window-configuration
1286 what-character-original-window-configuration)
1287 (signal (car err) (cdr err)))))))
1293 (provide 'char-db-util)
1295 ;;; char-db-util.el ends here