1 ;;; char-db-util.el --- Character Database utility -*- coding: utf-8-er; -*-
3 ;; Copyright (C) 1998,1999,2000,2001,2002,2003,2004,2005 MORIOKA Tomohiko.
5 ;; Author: MORIOKA Tomohiko <tomo@kanji.zinbun.kyoto-u.ac.jp>
6 ;; Keywords: CHISE, Character Database, ISO/IEC 10646, UCS, Unicode, MULE.
8 ;; This file is part of XEmacs CHISE.
10 ;; XEmacs CHISE is free software; you can redistribute it and/or
11 ;; modify it under the terms of the GNU General Public License as
12 ;; published by the Free Software Foundation; either version 2, or (at
13 ;; your option) any later version.
15 ;; XEmacs CHISE is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 ;; General Public License for more details.
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with XEmacs CHISE; see the file COPYING. If not, write to
22 ;; the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23 ;; Boston, MA 02111-1307, USA.
29 (defconst unidata-normative-category-alist
30 '(("Lu" letter uppercase)
31 ("Ll" letter lowercase)
32 ("Lt" letter titlecase)
33 ("Mn" mark non-spacing)
34 ("Mc" mark spacing-combining)
36 ("Nd" number decimal-digit)
39 ("Zs" separator space)
41 ("Zp" separator paragraph)
44 ("Cs" other surrogate)
45 ("Co" other private-use)
46 ("Cn" other not-assigned)))
48 (defconst unidata-informative-category-alist
49 '(("Lm" letter modifier)
51 ("Pc" punctuation connector)
52 ("Pd" punctuation dash)
53 ("Ps" punctuation open)
54 ("Pe" punctuation close)
55 ("Pi" punctuation initial-quote)
56 ("Pf" punctuation final-quote)
57 ("Po" punctuation other)
59 ("Sc" symbol currency)
60 ("Sk" symbol modifier)
64 (defconst ideographic-radicals
65 (let ((v (make-vector 215 nil))
68 (aset v i (decode-char '=ucs (+ #x2EFF i)))
72 (defun ideographic-radical (number)
73 (aref ideographic-radicals number))
75 (defconst shuowen-radicals
76 [?一 ?上 ?示 ?三 ?王 ?玉 ?玨 ?气 ?士 ?丨 ?屮 ?艸 ?茻])
78 (defun shuowen-radical (number)
79 (aref shuowen-radicals (1- number)))
81 (defvar char-db-file-coding-system 'utf-8-mcs-er)
83 (defvar char-db-feature-domains
84 '(ucs daikanwa cns gt jis jis/alt jis/a jis/b
85 jis-x0212 jis-x0213 cdp shinjigen misc unknown))
87 (defvar char-db-ignored-attributes '(ideographic-products))
89 (defun char-attribute-name< (ka kb)
91 ((eq '->denotational kb)
93 ((eq '->subsumptive kb)
94 (not (eq '->denotational ka)))
95 ((eq '->denotational ka)
97 ((eq '->subsumptive ka)
100 (if (find-charset kb)
101 (if (<= (charset-id ka) 1)
102 (if (<= (charset-id kb) 1)
104 ((= (charset-dimension ka)
105 (charset-dimension kb))
106 (> (charset-id ka)(charset-id kb)))
108 (> (charset-dimension ka)
109 (charset-dimension kb))
112 (if (<= (charset-id kb) 1)
114 (< (charset-id ka)(charset-id kb))))
120 (string< (symbol-name ka)
126 (defvar char-db-coded-charset-priority-list
186 (defun char-db-make-char-spec (char)
188 (cond ((characterp char)
189 (cond ((and (setq ret (encode-char char '=ucs 'defined-only))
190 (not (and (<= #xE000 ret)(<= ret #xF8FF))))
191 (setq char-spec (list (cons '=ucs ret)))
192 (cond ((setq ret (get-char-attribute char 'name))
193 (setq char-spec (cons (cons 'name ret) char-spec))
195 ((setq ret (get-char-attribute char 'name*))
196 (setq char-spec (cons (cons 'name* ret) char-spec))
201 (let ((rest char-db-coded-charset-priority-list)
204 (setq ccs (charset-name
205 (find-charset (car rest))))
207 (encode-char char ccs
209 (throw 'tag (cons ccs ret)))
210 (setq rest (cdr rest))))))
211 (setq char-spec (list ret))
212 (dolist (ccs (delq (car ret) (charset-list)))
213 (if (and (or (charset-iso-final-char ccs)
219 (setq ccs (charset-name ccs))
220 (null (assq ccs char-spec))
221 (setq ret (encode-char char ccs 'defined-only)))
222 (setq char-spec (cons (cons ccs ret) char-spec))))
224 (setq char-spec (split-char char)))
225 (cond ((setq ret (get-char-attribute char 'name))
226 (setq char-spec (cons (cons 'name ret) char-spec))
228 ((setq ret (get-char-attribute char 'name*))
229 (setq char-spec (cons (cons 'name* ret) char-spec))
236 (defun char-db-insert-char-spec (char &optional readable column
239 (setq column (current-column)))
240 (let (char-spec temp-char)
241 (setq char-spec (char-db-make-char-spec char))
242 (unless (or (characterp char) ; char
244 (setq char (find-char char-spec))
246 ;; define temporary character
247 ;; Current implementation is dirty.
248 (setq temp-char (define-char (cons '(ideograph-daikanwa . 0)
250 (remove-char-attribute temp-char 'ideograph-daikanwa)
251 (setq char temp-char))
252 (insert-char-attributes char
254 (union (mapcar #'car char-spec)
257 ;; undefine temporary character
258 ;; Current implementation is dirty.
259 (setq char-spec (char-attribute-alist temp-char))
261 (remove-char-attribute temp-char (car (car char-spec)))
262 (setq char-spec (cdr char-spec))))))
264 (defun char-db-insert-alist (alist &optional readable column)
266 (setq column (current-column)))
268 (concat "\n" (make-string (1+ column) ?\ )))
272 lbs cell rest separator)
275 (setq name (car (car alist))
276 value (cdr (car alist)))
277 (cond ((eq name 'char)
279 (if (setq ret (condition-case nil
287 (setq key (car (car value)))
288 ;; (if (find-charset key)
289 ;; (setq cal (cons key cal))
290 (setq al (cons key al))
292 (setq value (cdr value)))
293 (insert-char-attributes ret
297 (insert (prin1-to-string value)))
299 (insert line-breaking))
301 (insert (format "(%-18s " name))
302 (setq lbs (concat "\n" (make-string (current-column) ?\ )))
304 (setq cell (car value))
305 (if (and (consp cell)
307 (setq ret (condition-case nil
317 (setq key (car (car rest)))
318 ;; (if (find-charset key)
319 ;; (setq cal (cons key cal))
320 (setq al (cons key al))
322 (setq rest (cdr rest)))
325 (insert-char-attributes ret
329 (setq separator lbs))
332 (insert (prin1-to-string cell))
333 (setq separator " "))
334 (setq value (cdr value)))
336 (insert line-breaking))
338 (insert (format "(%-18s . %S)%s"
341 (setq alist (cdr alist))))
344 (defun char-db-insert-char-reference (plist &optional readable column)
346 (setq column (current-column)))
348 (concat "\n" (make-string (1+ column) ?\ )))
353 (setq name (pop plist))
354 (setq value (pop plist))
355 (cond ((eq name :char)
358 (cond ((numberp value)
359 (setq value (decode-char '=ucs value)))
361 ;; (setq value (or (find-char value)
364 (char-db-insert-char-spec value readable)
365 (insert line-breaking)
368 (insert (format "%s%s\t%d ; %c%s"
371 (ideographic-radical value)
375 (insert (format "%s%s\t%S" separator name value))
376 (setq separator line-breaking)))
380 (defun char-db-decode-isolated-char (ccs code-point)
383 (cond ((eq ccs 'arabic-iso8859-6)
384 (decode-char ccs code-point))
385 ((and (memq ccs '(=gt-pj-1
396 (setq ret (decode-char ccs code-point))
397 (setq ret (encode-char ret '=gt 'defined-only)))
398 (decode-builtin-char '=gt ret))
400 (decode-builtin-char ccs code-point))))
401 (cond ((and (<= 0 (char-int ret))
402 (<= (char-int ret) #x1F))
403 (decode-char '=ucs (+ #x2400 (char-int ret))))
404 ((= (char-int ret) #x7F)
408 (defvar char-db-convert-obsolete-format t)
410 (defun char-db-insert-ccs-feature (name value line-breaking)
413 (cond ((memq name '(=daikanwa
414 =daikanwa@rev1 =daikanwa@rev2
415 =gt =gt-k =cbeta =zinbun-oracle))
416 "(%-18s . %05d)\t; %c")
418 "(%-18s . %06d)\t; %c")
419 ((>= (charset-dimension name) 2)
420 "(%-18s . #x%04X)\t; %c")
422 "(%-18s . #x%02X)\t; %c"))
424 (if (= (charset-iso-graphic-plane name) 1)
426 (cond ((= (charset-dimension name) 1)
428 ((= (charset-dimension name) 2)
430 ((= (charset-dimension name) 3)
434 (char-db-decode-isolated-char name value)))
435 (if (and (= (charset-chars name) 94)
436 (= (charset-dimension name) 2))
437 (insert (format " [%02d-%02d]"
438 (- (lsh value -8) 32)
439 (- (logand value 255) 32))))
440 (insert line-breaking))
442 (defun insert-char-attributes (char &optional readable attributes column)
444 (setq column (current-column)))
445 (let (name value ; has-long-ccs-name
449 (concat "\n" (make-string (1+ column) ?\ )))
450 lbs cell separator ret
453 sources required-features
458 (if (consp attributes)
460 (dolist (name attributes)
461 (unless (memq name char-db-ignored-attributes)
462 (if (find-charset name)
466 (dolist (name (char-attribute-list))
467 (unless (memq name char-db-ignored-attributes)
468 (if (find-charset name)
472 #'char-attribute-name<)))
474 (when (and (memq 'name attributes)
475 (setq value (get-char-attribute char 'name)))
477 (if (> (+ (current-column) (length value)) 48)
480 value line-breaking))
481 (setq attributes (delq 'name attributes))
483 (when (and (memq 'name* attributes)
484 (setq value (get-char-attribute char 'name*)))
486 (if (> (+ (current-column) (length value)) 48)
489 value line-breaking))
490 (setq attributes (delq 'name* attributes))
492 (when (and (memq 'script attributes)
493 (setq value (get-char-attribute char 'script)))
494 (insert (format "(script\t\t%s)%s"
495 (mapconcat (function prin1-to-string)
498 (setq attributes (delq 'script attributes))
500 ;; (when (and (memq '<-denotational attributes)
501 ;; (setq value (get-char-attribute char '<-denotational))
502 ;; (null (cdr value))
503 ;; (setq value (encode-char (car value) 'ucs 'defined-only)))
504 ;; (insert (format "(%-18s . #x%04X)\t; %c%s"
505 ;; '=>ucs value (decode-char 'ucs value)
507 ;; (setq attributes (delq '<-denotational attributes)))
508 (dolist (name '(=>ucs =>ucs*))
509 (when (and (memq name attributes)
510 (setq value (get-char-attribute char name)))
511 (insert (format "(%-18s . #x%04X)\t; %c%s"
512 name value (decode-char '=ucs value)
514 (setq attributes (delq name attributes))))
515 (dolist (name '(=>ucs@gb =>ucs@cns =>ucs@jis =>ucs@ks =>ucs@big5))
516 (when (and (memq name attributes)
517 (setq value (get-char-attribute char name)))
518 (insert (format "(%-18s . #x%04X)\t; %c%s"
523 (symbol-name name) 2)))
526 (setq attributes (delq name attributes))
528 (dolist (name '(=>daikanwa))
529 (when (and (memq name attributes)
530 (setq value (get-char-attribute char name)))
533 (format "(%-18s . %05d)\t; %c%s"
534 name value (decode-char '=daikanwa value)
536 (format "(%-18s %s)\t; %c%s"
538 (mapconcat (function prin1-to-string)
540 (char-representative-of-daikanwa char)
542 (setq attributes (delq name attributes))))
543 (when (and (memq 'general-category attributes)
544 (setq value (get-char-attribute char 'general-category)))
546 "(general-category\t%s) ; %s%s"
547 (mapconcat (lambda (cell)
550 (cond ((rassoc value unidata-normative-category-alist)
551 "Normative Category")
552 ((rassoc value unidata-informative-category-alist)
553 "Informative Category")
557 (setq attributes (delq 'general-category attributes))
559 (when (and (memq 'bidi-category attributes)
560 (setq value (get-char-attribute char 'bidi-category)))
561 (insert (format "(bidi-category\t. %S)%s"
564 (setq attributes (delq 'bidi-category attributes))
566 (unless (or (not (memq 'mirrored attributes))
567 (eq (setq value (get-char-attribute char 'mirrored 'empty))
569 (insert (format "(mirrored\t\t. %S)%s"
572 (setq attributes (delq 'mirrored attributes))
575 ((and (memq 'decimal-digit-value attributes)
576 (setq value (get-char-attribute char 'decimal-digit-value)))
577 (insert (format "(decimal-digit-value . %S)%s"
580 (setq attributes (delq 'decimal-digit-value attributes))
581 (when (and (memq 'digit-value attributes)
582 (setq value (get-char-attribute char 'digit-value)))
583 (insert (format "(digit-value\t . %S)%s"
586 (setq attributes (delq 'digit-value attributes))
588 (when (and (memq 'numeric-value attributes)
589 (setq value (get-char-attribute char 'numeric-value)))
590 (insert (format "(numeric-value\t . %S)%s"
593 (setq attributes (delq 'numeric-value attributes))
597 (when (and (memq 'digit-value attributes)
598 (setq value (get-char-attribute char 'digit-value)))
599 (insert (format "(digit-value\t. %S)%s"
602 (setq attributes (delq 'digit-value attributes))
604 (when (and (memq 'numeric-value attributes)
605 (setq value (get-char-attribute char 'numeric-value)))
606 (insert (format "(numeric-value\t. %S)%s"
609 (setq attributes (delq 'numeric-value attributes))
611 (when (and (memq 'iso-10646-comment attributes)
612 (setq value (get-char-attribute char 'iso-10646-comment)))
613 (insert (format "(iso-10646-comment\t. %S)%s"
616 (setq attributes (delq 'iso-10646-comment attributes))
618 (when (and (memq 'morohashi-daikanwa attributes)
619 (setq value (get-char-attribute char 'morohashi-daikanwa)))
620 (insert (format "(morohashi-daikanwa\t%s)%s"
621 (mapconcat (function prin1-to-string) value " ")
623 (setq attributes (delq 'morohashi-daikanwa attributes))
627 (when (and (memq 'ideographic-radical attributes)
628 (setq value (get-char-attribute char 'ideographic-radical)))
630 (insert (format "(ideographic-radical . %S)\t; %c%s"
632 (ideographic-radical radical)
634 (setq attributes (delq 'ideographic-radical attributes))
636 (when (and (memq 'shuowen-radical attributes)
637 (setq value (get-char-attribute char 'shuowen-radical)))
638 (insert (format "(shuowen-radical\t. %S)\t; %c%s"
640 (shuowen-radical value)
642 (setq attributes (delq 'shuowen-radical attributes))
647 char-db-feature-domains
649 (dolist (feature (char-attribute-list))
650 (setq feature (symbol-name feature))
652 "\\(radical\\|strokes\\)@\\([^@*]+\\)\\(\\*\\|$\\)"
654 (setq domain (intern (match-string 2 feature)))
655 (unless (memq domain dest)
656 (setq dest (cons domain dest)))))
657 (sort dest #'string<))))
658 (setq key (intern (format "%s@%s" 'ideographic-radical domain)))
659 (when (and (memq key attributes)
660 (setq value (get-char-attribute char key)))
662 (insert (format "(%s . %S)\t; %c%s"
665 (ideographic-radical radical)
667 (setq attributes (delq key attributes))
669 (setq key (intern (format "%s@%s" 'ideographic-strokes domain)))
670 (when (and (memq key attributes)
671 (setq value (get-char-attribute char key)))
673 (insert (format "(%s . %S)%s"
677 (setq attributes (delq key attributes))
679 (setq key (intern (format "%s@%s" 'total-strokes domain)))
680 (when (and (memq key attributes)
681 (setq value (get-char-attribute char key)))
682 (insert (format "(%s . %S)%s"
686 (setq attributes (delq key attributes))
688 (dolist (feature '(ideographic-radical
691 (setq key (intern (format "%s@%s*sources" feature domain)))
692 (when (and (memq key attributes)
693 (setq value (get-char-attribute char key)))
694 (insert (format "(%s%s" key line-breaking))
696 (insert (format " %s" cell)))
698 (insert line-breaking)
699 (setq attributes (delq key attributes))
702 (when (and (memq 'ideographic-strokes attributes)
703 (setq value (get-char-attribute char 'ideographic-strokes)))
705 (insert (format "(ideographic-strokes . %S)%s"
708 (setq attributes (delq 'ideographic-strokes attributes))
710 (when (and (memq 'kangxi-radical attributes)
711 (setq value (get-char-attribute char 'kangxi-radical)))
712 (unless (eq value radical)
713 (insert (format "(kangxi-radical\t . %S)\t; %c%s"
715 (ideographic-radical value)
718 (setq radical value)))
719 (setq attributes (delq 'kangxi-radical attributes))
721 (when (and (memq 'kangxi-strokes attributes)
722 (setq value (get-char-attribute char 'kangxi-strokes)))
723 (unless (eq value strokes)
724 (insert (format "(kangxi-strokes\t . %S)%s"
728 (setq strokes value)))
729 (setq attributes (delq 'kangxi-strokes attributes))
731 (when (and (memq 'japanese-radical attributes)
732 (setq value (get-char-attribute char 'japanese-radical)))
733 (unless (eq value radical)
734 (insert (format "(japanese-radical\t . %S)\t; %c%s"
736 (ideographic-radical value)
739 (setq radical value)))
740 (setq attributes (delq 'japanese-radical attributes))
742 (when (and (memq 'japanese-strokes attributes)
743 (setq value (get-char-attribute char 'japanese-strokes)))
744 (unless (eq value strokes)
745 (insert (format "(japanese-strokes\t . %S)%s"
749 (setq strokes value)))
750 (setq attributes (delq 'japanese-strokes attributes))
752 (when (and (memq 'cns-radical attributes)
753 (setq value (get-char-attribute char 'cns-radical)))
754 (insert (format "(cns-radical\t . %S)\t; %c%s"
756 (ideographic-radical value)
758 (setq attributes (delq 'cns-radical attributes))
760 (when (and (memq 'cns-strokes attributes)
761 (setq value (get-char-attribute char 'cns-strokes)))
762 (unless (eq value strokes)
763 (insert (format "(cns-strokes\t . %S)%s"
767 (setq strokes value)))
768 (setq attributes (delq 'cns-strokes attributes))
770 (when (and (memq 'shinjigen-1-radical attributes)
771 (setq value (get-char-attribute char 'shinjigen-1-radical)))
772 (unless (eq value radical)
773 (insert (format "(shinjigen-1-radical . %S)\t; %c%s"
775 (ideographic-radical value)
778 (setq radical value)))
779 (setq attributes (delq 'shinjigen-1-radical attributes))
781 (when (and (memq 'ideographic- attributes)
782 (setq value (get-char-attribute char 'ideographic-)))
783 (insert "(ideographic- ")
784 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
787 (setq cell (car value))
789 (setq cell (decode-char '=ucs cell)))
790 (cond ((characterp cell)
794 (insert (format "%S" cell))
795 (char-db-insert-char-spec cell readable))
796 (setq separator lbs))
800 (if (consp (car cell))
801 (char-db-insert-char-spec cell readable)
802 (char-db-insert-char-reference cell readable))
803 (setq separator lbs))
807 (insert (prin1-to-string cell))
808 (setq separator " ")))
809 (setq value (cdr value)))
811 (insert line-breaking)
812 (setq attributes (delq 'ideographic- attributes)))
813 (when (and (memq 'total-strokes attributes)
814 (setq value (get-char-attribute char 'total-strokes)))
815 (insert (format "(total-strokes . %S)%s"
818 (setq attributes (delq 'total-strokes attributes))
820 (when (and (memq '->ideograph attributes)
821 (setq value (get-char-attribute char '->ideograph)))
822 (insert (format "(->ideograph\t%s)%s"
823 (mapconcat (lambda (code)
824 (cond ((symbolp code)
827 (format "#x%04X" code))
830 line-breaking code))))
833 (setq attributes (delq '->ideograph attributes))
835 (when (and (memq '->decomposition attributes)
836 (setq value (get-char-attribute char '->decomposition)))
837 (insert (format "(->decomposition\t%s)%s"
838 (mapconcat (lambda (code)
839 (cond ((symbolp code)
848 (format "#x%04X" code))
850 (format "%s%S" line-breaking code))))
853 (setq attributes (delq '->decomposition attributes))
855 (if (equal (get-char-attribute char '->titlecase)
856 (get-char-attribute char '->uppercase))
857 (setq attributes (delq '->titlecase attributes)))
858 (when (and (memq '->mojikyo attributes)
859 (setq value (get-char-attribute char '->mojikyo)))
860 (insert (format "(->mojikyo\t\t. %06d)\t; %c%s"
861 value (decode-char 'mojikyo value)
863 (setq attributes (delq '->mojikyo attributes))
865 (when (and (memq 'hanyu-dazidian-vol attributes)
866 (setq value (get-char-attribute char 'hanyu-dazidian-vol)))
867 (insert (format "(hanyu-dazidian-vol . %d)%s"
868 value line-breaking))
869 (setq attributes (delq 'hanyu-dazidian-vol attributes))
871 (when (and (memq 'hanyu-dazidian-page attributes)
872 (setq value (get-char-attribute char 'hanyu-dazidian-page)))
873 (insert (format "(hanyu-dazidian-page . %d)%s"
874 value line-breaking))
875 (setq attributes (delq 'hanyu-dazidian-page attributes))
877 (when (and (memq 'hanyu-dazidian-char attributes)
878 (setq value (get-char-attribute char 'hanyu-dazidian-char)))
879 (insert (format "(hanyu-dazidian-char . %d)%s"
880 value line-breaking))
881 (setq attributes (delq 'hanyu-dazidian-char attributes))
884 (dolist (ignored '(composition
885 ->denotational <-subsumptive ->ucs-unified
886 ->ideographic-component-forms))
887 (setq attributes (delq ignored attributes))))
889 (setq name (car attributes))
890 (if (setq value (get-char-attribute char name))
891 (cond ((setq ret (find-charset name))
892 (setq name (charset-name ret))
893 (if (and (not (memq name dest-ccss))
895 (setq value (get-char-attribute char name))
896 (setq dest-ccss (cons name dest-ccss))))
897 (char-db-insert-ccs-feature name value line-breaking))
899 ((string-match "^=>ucs@" (symbol-name name))
900 (insert (format "(%-18s . #x%04X)\t; %c%s"
901 name value (decode-char '=ucs value)
904 ((eq name 'jisx0208-1978/4X)
905 (insert (format "(%-18s . #x%04X)%s"
910 (null (get-char-attribute
912 (intern (format "%s*sources" name))))
913 (not (string-match "\\*sources$" (symbol-name name)))
914 (or (eq name '<-identical)
915 (string-match "^->halfwidth" (symbol-name name))
917 (string-match "^->fullwidth" (symbol-name name))
920 (characterp (car value))
922 (car value) '=ucs 'defined-only))))
923 (string-match "^->simplified" (symbol-name name))
924 (string-match "^->vulgar" (symbol-name name))
925 (string-match "^->wrong" (symbol-name name))
926 (string-match "^->same" (symbol-name name))
927 (string-match "^->formed" (symbol-name name))
928 (string-match "^->original" (symbol-name name))
929 (string-match "^->ancient" (symbol-name name))
930 (string-match "^->Oracle-Bones" (symbol-name name))
933 ((or (eq name 'ideographic-structure)
934 (eq name 'ideographic-combination)
935 (eq name 'ideographic-)
936 (string-match "^\\(->\\|<-\\)" (symbol-name name)))
937 (insert (format "(%-18s%s " name line-breaking))
938 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
941 (setq cell (car value))
943 (setq cell (decode-char '=ucs cell)))
944 (cond ((eq name '->subsumptive)
947 (get-char-attribute cell atr))
948 char-db-ignored-attributes))
950 (encode-char cell ccs
955 (let ((char-db-ignored-attributes
957 char-db-ignored-attributes)))
958 (insert-char-attributes cell readable))
959 (setq separator lbs))
965 (intern (format "%s*sources" name))))
966 (setq required-features nil)
967 (dolist (source sources)
969 ((memq source '(JP JP/Jouyou
971 (setq required-features
972 (union required-features
981 (setq required-features
982 (union required-features
988 (setq ret (intern (format "=%s" source))))
989 (setq required-features
990 (cons ret required-features)))
991 (t (setq required-features
992 (cons source required-features)))))
993 (cond ((string-match "@JP" (symbol-name name))
994 (setq required-features
995 (union required-features
1003 ((string-match "@CN" (symbol-name name))
1004 (setq required-features
1005 (union required-features
1012 (insert (format "%S" cell))
1013 (char-db-insert-char-spec cell readable
1016 (setq separator lbs))
1020 (if (consp (car cell))
1021 (char-db-insert-char-spec cell readable)
1022 (char-db-insert-char-reference cell readable))
1023 (setq separator lbs))
1027 (insert (prin1-to-string cell))
1028 (setq separator " ")))
1029 (setq value (cdr value)))
1031 (insert line-breaking))
1032 ((memq name '(ideograph=
1033 original-ideograph-of
1034 ancient-ideograph-of
1037 ;; simplified-ideograph-of
1038 ideographic-variants
1039 ;; ideographic-different-form-of
1041 (insert (format "(%-18s%s " name line-breaking))
1042 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1044 (while (consp value)
1045 (setq cell (car value))
1046 (if (and (consp cell)
1051 (char-db-insert-alist cell readable)
1052 (setq separator lbs))
1055 (insert (prin1-to-string cell))
1056 (setq separator " "))
1057 (setq value (cdr value)))
1059 (insert line-breaking))
1061 (insert (format "(%-18s " name))
1062 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1064 (while (consp value)
1065 (setq cell (car value))
1066 (if (and (consp cell)
1068 (setq ret (condition-case nil
1076 (setq key (car (car rest)))
1077 (if (find-charset key)
1078 (setq cal (cons key cal))
1079 (setq al (cons key al)))
1080 (setq rest (cdr rest)))
1083 (insert-char-attributes ret
1086 (setq separator lbs))
1087 (setq ret (prin1-to-string cell))
1089 (if (< (+ (current-column)
1096 (setq separator " "))
1097 (setq value (cdr value)))
1099 (insert line-breaking))
1101 (insert (format "(%-18s . %S)%s"
1105 (setq attributes (cdr attributes)))
1108 (defun insert-char-data (char &optional readable
1111 (narrow-to-region (point)(point))
1112 (insert "(define-char
1114 (insert-char-attributes char readable attributes)
1116 (goto-char (point-min))
1117 (while (re-search-forward "[ \t]+$" nil t)
1120 (goto-char (point-min))
1121 (while (re-search-forward "[ \t][ \t][ \t]*" nil t)
1122 (let ((column (current-column))
1123 (indent-tabs-mode t))
1124 (delete-region (match-beginning 0) (point))
1125 (indent-to column)))
1126 (goto-char (point-max))
1127 ;; (tabify (point-min)(point-max))
1130 (defun insert-char-data-with-variant (char &optional printable
1132 script excluded-script)
1133 (insert-char-data char printable)
1134 (let ((variants (char-variants char))
1137 (setq variants (sort variants #'<))
1138 (setq rest variants)
1139 (setq variants (cons char variants))
1141 (setq variant (car rest))
1142 (unless (get-char-attribute variant '<-subsumptive)
1143 (if (and (or (null script)
1144 (null (setq vs (get-char-attribute variant 'script)))
1146 (or (null excluded-script)
1147 (null (setq vs (get-char-attribute variant 'script)))
1148 (not (memq excluded-script vs))))
1149 (unless (and no-ucs-unified (get-char-attribute variant '=ucs))
1150 (insert-char-data variant printable)
1151 (if (setq ret (char-variants variant))
1153 (or (memq (car ret) variants)
1154 ;; (get-char-attribute (car ret) '<-subsumptive)
1155 (setq rest (nconc rest (list (car ret)))))
1156 (setq ret (cdr ret)))))))
1157 (setq rest (cdr rest)))))
1159 (defun insert-char-range-data (min max &optional script excluded-script)
1162 (while (<= code max)
1163 (setq char (decode-char '=ucs code))
1164 (if (encode-char char '=ucs 'defined-only)
1165 (insert-char-data-with-variant char nil 'no-ucs-unified
1166 script excluded-script))
1167 (setq code (1+ code)))))
1169 (defun write-char-range-data-to-file (min max file
1170 &optional script excluded-script)
1171 (let ((coding-system-for-write char-db-file-coding-system))
1173 (insert (format ";; -*- coding: %s -*-\n"
1174 char-db-file-coding-system))
1175 (insert-char-range-data min max script excluded-script)
1176 (write-region (point-min)(point-max) file))))
1178 (defvar what-character-original-window-configuration)
1181 (defun what-char-definition (char)
1182 (interactive (list (char-after)))
1183 (let ((buf (get-buffer-create "*Character Description*"))
1184 (the-buf (current-buffer))
1185 (win-conf (current-window-configuration)))
1187 (make-local-variable 'what-character-original-window-configuration)
1188 (setq what-character-original-window-configuration win-conf)
1189 (setq buffer-read-only nil)
1193 (insert-char-data-with-variant char 'printable)
1194 (unless (char-attribute-alist char)
1195 (insert (format ";; = %c\n"
1196 (let* ((rest (split-char char))
1200 (setq code (logior (lsh code 8)
1202 (decode-char ccs code)))))
1203 ;; (char-db-update-comment)
1204 (set-buffer-modified-p nil)
1205 (view-mode the-buf (lambda (buf)
1206 (set-window-configuration
1207 what-character-original-window-configuration)
1209 (goto-char (point-min)))
1211 (set-window-configuration
1212 what-character-original-window-configuration)
1213 (signal (car err) (cdr err)))))))
1215 (provide 'char-db-util)
1217 ;;; char-db-util.el ends here