1 ;;; char-db-util.el --- Character Database utility
3 ;; Copyright (C) 1998,1999,2000,2001,2002,2003,2004 MORIOKA Tomohiko.
5 ;; Author: MORIOKA Tomohiko <tomo@kanji.zinbun.kyoto-u.ac.jp>
6 ;; Keywords: CHISE, Character Database, ISO/IEC 10646, Unicode, UCS-4, 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 (defvar char-db-feature-domains
73 '(ucs daikanwa cns gt jis jis/alt jis/a jis/b
74 jis-x0213 misc unknown))
76 (defvar char-db-ignored-attributes nil)
78 (defun char-attribute-name< (ka kb)
80 ((eq '->denotational kb)
82 ((eq '->subsumptive kb)
83 (not (eq '->denotational ka)))
84 ((eq '->denotational ka)
86 ((eq '->subsumptive ka)
90 (if (<= (charset-id ka) 0)
91 (if (<= (charset-id kb) 0)
93 ((= (charset-dimension ka)
94 (charset-dimension kb))
95 (> (charset-id ka)(charset-id kb)))
97 (> (charset-dimension ka)
98 (charset-dimension kb))
101 (if (<= (charset-id kb) 0)
103 (< (charset-id ka)(charset-id kb))))
109 (string< (symbol-name ka)
115 (defvar char-db-coded-charset-priority-list
130 japanese-jisx0208-1978
171 (defun char-db-make-char-spec (char)
173 (cond ((characterp char)
174 (cond ((and (setq ret (encode-char char '=ucs 'defined-only))
175 (not (and (<= #xE000 ret)(<= ret #xF8FF))))
176 (setq char-spec (list (cons '=ucs ret)))
177 (cond ((setq ret (get-char-attribute char 'name))
178 (setq char-spec (cons (cons 'name ret) char-spec))
180 ((setq ret (get-char-attribute char 'name*))
181 (setq char-spec (cons (cons 'name* ret) char-spec))
186 (let ((rest char-db-coded-charset-priority-list)
189 (setq ccs (charset-name
190 (find-charset (car rest))))
192 (encode-char char ccs
194 (throw 'tag (cons ccs ret)))
195 (setq rest (cdr rest))))))
196 (setq char-spec (list ret))
197 (dolist (ccs (delq (car ret) (charset-list)))
198 (if (and (or (charset-iso-final-char ccs)
204 (setq ret (encode-char char ccs 'defined-only)))
205 (setq char-spec (cons (cons ccs ret) char-spec))))
207 (setq char-spec (split-char char)))
208 (cond ((setq ret (get-char-attribute char 'name))
209 (setq char-spec (cons (cons 'name ret) char-spec))
211 ((setq ret (get-char-attribute char 'name*))
212 (setq char-spec (cons (cons 'name* ret) char-spec))
219 (defun char-db-insert-char-spec (char &optional readable column
222 (setq column (current-column)))
223 (let (char-spec al cal key temp-char)
224 (setq char-spec (char-db-make-char-spec char))
225 (unless (or (characterp char) ; char
227 (setq char (find-char char-spec))
229 ;; define temporary character
230 ;; Current implementation is dirty.
231 (setq temp-char (define-char (cons '(ideograph-daikanwa . 0)
233 (remove-char-attribute temp-char 'ideograph-daikanwa)
234 (setq char temp-char))
238 ;; (setq key (car (car char-spec)))
239 ;; (unless (memq key char-db-ignored-attributes)
240 ;; (if (find-charset key)
241 ;; (if (encode-char char key 'defined-only)
242 ;; (setq cal (cons key cal)))
243 ;; (setq al (cons key al))))
244 ;; (setq char-spec (cdr char-spec)))
246 ;; (setq char-spec (char-db-make-char-spec char))
248 ;; (setq key (car (car char-spec)))
249 ;; (unless (memq key char-db-ignored-attributes)
250 ;; (if (find-charset key)
251 ;; (setq cal (cons key cal))
252 ;; (setq al (cons key al))))
253 ;; (setq char-spec (cdr char-spec)))
256 ;; (memq 'ideographic-structure al))
257 ;; (push 'ideographic-structure al))
258 ;; (dolist (feature required-features)
259 ;; (if (find-charset feature)
260 ;; (if (encode-char char feature 'defined-only)
261 ;; (setq cal (adjoin feature cal)))
262 ;; (setq al (adjoin feature al))))
263 (insert-char-attributes char
266 (union (mapcar #'car char-spec)
270 ;; undefine temporary character
271 ;; Current implementation is dirty.
272 (setq char-spec (char-attribute-alist temp-char))
274 (remove-char-attribute temp-char (car (car char-spec)))
275 (setq char-spec (cdr char-spec))))))
277 (defun char-db-insert-alist (alist &optional readable column)
279 (setq column (current-column)))
281 (concat "\n" (make-string (1+ column) ?\ )))
285 lbs cell rest separator)
288 (setq name (car (car alist))
289 value (cdr (car alist)))
290 (cond ((eq name 'char)
292 (if (setq ret (condition-case nil
299 (setq key (car (car value)))
300 ;; (if (find-charset key)
301 ;; (setq cal (cons key cal))
302 (setq al (cons key al))
304 (setq value (cdr value)))
305 (insert-char-attributes ret
309 (insert (prin1-to-string value)))
311 (insert line-breaking))
313 (insert (format "(%-18s " name))
314 (setq lbs (concat "\n" (make-string (current-column) ?\ )))
316 (setq cell (car value))
317 (if (and (consp cell)
319 (setq ret (condition-case nil
328 (setq key (car (car rest)))
329 ;; (if (find-charset key)
330 ;; (setq cal (cons key cal))
331 (setq al (cons key al))
333 (setq rest (cdr rest)))
336 (insert-char-attributes ret
340 (setq separator lbs))
343 (insert (prin1-to-string cell))
344 (setq separator " "))
345 (setq value (cdr value)))
347 (insert line-breaking))
349 (insert (format "(%-18s . %S)%s"
352 (setq alist (cdr alist))))
355 (defun char-db-insert-char-reference (plist &optional readable column)
357 (setq column (current-column)))
359 (concat "\n" (make-string (1+ column) ?\ )))
364 (setq name (pop plist))
365 (setq value (pop plist))
366 (cond ((eq name :char)
369 (cond ((numberp value)
370 (setq value (decode-char '=ucs value)))
372 ;; (setq value (or (find-char value)
375 (char-db-insert-char-spec value readable)
376 (insert line-breaking)
379 (insert (format "%s%s\t%d ; %c%s"
382 (aref ideographic-radicals value)
386 (insert (format "%s%s\t%S" separator name value))
387 (setq separator line-breaking)))
391 (defun char-db-decode-isolated-char (ccs code-point)
394 (cond ((eq ccs 'arabic-iso8859-6)
395 (decode-char ccs code-point))
396 ((and (memq ccs '(=gt-pj-1
407 (setq ret (decode-char ccs code-point))
408 (setq ret (encode-char ret '=gt 'defined-only)))
409 (decode-builtin-char '=gt ret))
411 (decode-builtin-char ccs code-point))))
412 (cond ((and (<= 0 (char-int ret))
413 (<= (char-int ret) #x1F))
414 (decode-char '=ucs (+ #x2400 (char-int ret))))
415 ((= (char-int ret) #x7F)
419 (defvar char-db-convert-obsolete-format t)
421 (defun insert-char-attributes (char &optional readable attributes column)
423 (setq column (current-column)))
424 (let (name value has-long-ccs-name rest
427 (concat "\n" (make-string (1+ column) ?\ )))
428 lbs cell separator ret
431 sources required-features
436 (if (consp attributes)
438 (dolist (name attributes)
439 (unless (memq name char-db-ignored-attributes)
440 (if (find-charset name)
444 (dolist (name (char-attribute-list))
445 (unless (memq name char-db-ignored-attributes)
446 (if (find-charset name)
450 #'char-attribute-name<)))
452 (when (and (memq 'name attributes)
453 (setq value (get-char-attribute char 'name)))
455 (if (> (+ (current-column) (length value)) 48)
458 value line-breaking))
459 (setq attributes (delq 'name attributes))
461 (when (and (memq 'name* attributes)
462 (setq value (get-char-attribute char 'name*)))
464 (if (> (+ (current-column) (length value)) 48)
467 value line-breaking))
468 (setq attributes (delq 'name* attributes))
470 (when (and (memq 'script attributes)
471 (setq value (get-char-attribute char 'script)))
472 (insert (format "(script\t\t%s)%s"
473 (mapconcat (function prin1-to-string)
476 (setq attributes (delq 'script attributes))
478 (dolist (name '(=>ucs =>ucs*))
479 (when (and (memq name attributes)
480 (setq value (get-char-attribute char name)))
481 (insert (format "(%-18s . #x%04X)\t; %c%s"
482 name value (decode-char '=ucs value)
484 (setq attributes (delq name attributes))))
485 (dolist (name '(=>ucs@gb =>ucs@cns =>ucs@jis =>ucs@ks =>ucs@big5))
486 (when (and (memq name attributes)
487 (setq value (get-char-attribute char name)))
488 (insert (format "(%-18s . #x%04X)\t; %c%s"
493 (symbol-name name) 2)))
496 (setq attributes (delq name attributes))
498 ;; (dolist (name '(=>ucs-gb =>ucs-cns =>ucs-jis =>ucs-ks =>ucs-big5))
499 ;; (when (and (memq name attributes)
500 ;; (setq value (get-char-attribute char name)))
501 ;; (insert (format "(%-18s . #x%04X)\t; %c%s"
504 ;; (substring (symbol-name name) 6)))
506 ;; (decode-char (intern
509 ;; (symbol-name name) 6)))
512 ;; (setq attributes (delq name attributes))))
513 ;; (when (and (memq '->ucs attributes)
514 ;; (setq value (get-char-attribute char '->ucs)))
515 ;; (insert (format (if char-db-convert-obsolete-format
516 ;; "(=>ucs\t\t. #x%04X)\t; %c%s"
517 ;; "(->ucs\t\t. #x%04X)\t; %c%s")
518 ;; value (decode-char '=ucs value)
520 ;; (setq attributes (delq '->ucs attributes))
522 (dolist (name '(=>daikanwa))
523 (when (and (memq name attributes)
524 (setq value (get-char-attribute char name)))
527 (format "(%-18s . %05d)\t; %c%s"
528 name value (decode-char '=daikanwa value)
530 (format "(%-18s %s)\t; %c%s"
532 (mapconcat (function prin1-to-string)
534 (char-representative-of-daikanwa char)
536 (setq attributes (delq name attributes))))
537 (when (and (memq 'general-category attributes)
538 (setq value (get-char-attribute char 'general-category)))
540 "(general-category\t%s) ; %s%s"
541 (mapconcat (lambda (cell)
544 (cond ((rassoc value unidata-normative-category-alist)
545 "Normative Category")
546 ((rassoc value unidata-informative-category-alist)
547 "Informative Category")
551 (setq attributes (delq 'general-category attributes))
553 (when (and (memq 'bidi-category attributes)
554 (setq value (get-char-attribute char 'bidi-category)))
555 (insert (format "(bidi-category\t. %S)%s"
558 (setq attributes (delq 'bidi-category attributes))
560 (unless (or (not (memq 'mirrored attributes))
561 (eq (setq value (get-char-attribute char 'mirrored 'empty))
563 (insert (format "(mirrored\t\t. %S)%s"
566 (setq attributes (delq 'mirrored attributes))
569 ((and (memq 'decimal-digit-value attributes)
570 (setq value (get-char-attribute char 'decimal-digit-value)))
571 (insert (format "(decimal-digit-value . %S)%s"
574 (setq attributes (delq 'decimal-digit-value attributes))
575 (when (and (memq 'digit-value attributes)
576 (setq value (get-char-attribute char 'digit-value)))
577 (insert (format "(digit-value\t . %S)%s"
580 (setq attributes (delq 'digit-value attributes))
582 (when (and (memq 'numeric-value attributes)
583 (setq value (get-char-attribute char 'numeric-value)))
584 (insert (format "(numeric-value\t . %S)%s"
587 (setq attributes (delq 'numeric-value attributes))
591 (when (and (memq 'digit-value attributes)
592 (setq value (get-char-attribute char 'digit-value)))
593 (insert (format "(digit-value\t. %S)%s"
596 (setq attributes (delq 'digit-value attributes))
598 (when (and (memq 'numeric-value attributes)
599 (setq value (get-char-attribute char 'numeric-value)))
600 (insert (format "(numeric-value\t. %S)%s"
603 (setq attributes (delq 'numeric-value attributes))
605 (when (and (memq 'iso-10646-comment attributes)
606 (setq value (get-char-attribute char 'iso-10646-comment)))
607 (insert (format "(iso-10646-comment\t. %S)%s"
610 (setq attributes (delq 'iso-10646-comment attributes))
612 (when (and (memq 'morohashi-daikanwa attributes)
613 (setq value (get-char-attribute char 'morohashi-daikanwa)))
614 (insert (format "(morohashi-daikanwa\t%s)%s"
615 (mapconcat (function prin1-to-string) value " ")
617 (setq attributes (delq 'morohashi-daikanwa attributes))
621 (when (and (memq 'ideographic-radical attributes)
622 (setq value (get-char-attribute char 'ideographic-radical)))
624 (insert (format "(ideographic-radical . %S)\t; %c%s"
626 (aref ideographic-radicals radical)
628 (setq attributes (delq 'ideographic-radical attributes))
631 (dolist (domain char-db-feature-domains)
632 (setq key (intern (format "%s@%s" 'ideographic-radical domain)))
633 (when (and (memq key attributes)
634 (setq value (get-char-attribute char key)))
636 (insert (format "(%s . %S)\t; %c%s"
639 (aref ideographic-radicals radical)
641 (setq attributes (delq key attributes))
643 (setq key (intern (format "%s@%s" 'ideographic-strokes domain)))
644 (when (and (memq key attributes)
645 (setq value (get-char-attribute char key)))
647 (insert (format "(%s . %S)%s"
651 (setq attributes (delq key attributes))
653 (setq key (intern (format "%s@%s" 'total-strokes domain)))
654 (when (and (memq key attributes)
655 (setq value (get-char-attribute char key)))
656 (insert (format "(%s . %S)%s"
660 (setq attributes (delq key attributes))
662 (dolist (feature '(ideographic-radical
665 (setq key (intern (format "%s@%s*sources" feature domain)))
666 (when (and (memq key attributes)
667 (setq value (get-char-attribute char key)))
668 (insert (format "(%s%s" key line-breaking))
670 (insert (format " %s" cell)))
672 (insert line-breaking)
673 (setq attributes (delq key attributes))
676 (when (and (memq 'ideographic-strokes attributes)
677 (setq value (get-char-attribute char 'ideographic-strokes)))
679 (insert (format "(ideographic-strokes . %S)%s"
682 (setq attributes (delq 'ideographic-strokes attributes))
684 (when (and (memq 'kangxi-radical attributes)
685 (setq value (get-char-attribute char 'kangxi-radical)))
686 (unless (eq value radical)
687 (insert (format "(kangxi-radical\t . %S)\t; %c%s"
689 (aref ideographic-radicals value)
692 (setq radical value)))
693 (setq attributes (delq 'kangxi-radical attributes))
695 (when (and (memq 'kangxi-strokes attributes)
696 (setq value (get-char-attribute char 'kangxi-strokes)))
697 (unless (eq value strokes)
698 (insert (format "(kangxi-strokes\t . %S)%s"
702 (setq strokes value)))
703 (setq attributes (delq 'kangxi-strokes attributes))
705 (when (and (memq 'japanese-radical attributes)
706 (setq value (get-char-attribute char 'japanese-radical)))
707 (unless (eq value radical)
708 (insert (format "(japanese-radical\t . %S)\t; %c%s"
710 (aref ideographic-radicals value)
713 (setq radical value)))
714 (setq attributes (delq 'japanese-radical attributes))
716 (when (and (memq 'japanese-strokes attributes)
717 (setq value (get-char-attribute char 'japanese-strokes)))
718 (unless (eq value strokes)
719 (insert (format "(japanese-strokes\t . %S)%s"
723 (setq strokes value)))
724 (setq attributes (delq 'japanese-strokes attributes))
726 (when (and (memq 'cns-radical attributes)
727 (setq value (get-char-attribute char 'cns-radical)))
728 (insert (format "(cns-radical\t . %S)\t; %c%s"
730 (aref ideographic-radicals value)
732 (setq attributes (delq 'cns-radical attributes))
734 (when (and (memq 'cns-strokes attributes)
735 (setq value (get-char-attribute char 'cns-strokes)))
736 (unless (eq value strokes)
737 (insert (format "(cns-strokes\t . %S)%s"
741 (setq strokes value)))
742 (setq attributes (delq 'cns-strokes attributes))
744 (when (and (memq 'shinjigen-1-radical attributes)
745 (setq value (get-char-attribute char 'shinjigen-1-radical)))
746 (unless (eq value radical)
747 (insert (format "(shinjigen-1-radical . %S)\t; %c%s"
749 (aref ideographic-radicals value)
752 (setq radical value)))
753 (setq attributes (delq 'shinjigen-1-radical attributes))
755 (when (and (memq 'ideographic- attributes)
756 (setq value (get-char-attribute char 'ideographic-)))
757 (insert "(ideographic- ")
758 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
761 (setq cell (car value))
763 (setq cell (decode-char '=ucs cell)))
764 (cond ((characterp cell)
768 (insert (format "%S" cell))
769 (char-db-insert-char-spec cell readable))
770 (setq separator lbs))
774 (if (consp (car cell))
775 (char-db-insert-char-spec cell readable)
776 (char-db-insert-char-reference cell readable))
777 (setq separator lbs))
781 (insert (prin1-to-string cell))
782 (setq separator " ")))
783 (setq value (cdr value)))
785 (insert line-breaking)
786 (setq attributes (delq 'ideographic- attributes)))
787 (when (and (memq 'total-strokes attributes)
788 (setq value (get-char-attribute char 'total-strokes)))
789 (insert (format "(total-strokes . %S)%s"
792 (setq attributes (delq 'total-strokes attributes))
794 (when (and (memq '->ideograph attributes)
795 (setq value (get-char-attribute char '->ideograph)))
796 (insert (format "(->ideograph\t%s)%s"
797 (mapconcat (lambda (code)
798 (cond ((symbolp code)
801 (format "#x%04X" code))
804 line-breaking code))))
807 (setq attributes (delq '->ideograph attributes))
809 (when (and (memq '->decomposition attributes)
810 (setq value (get-char-attribute char '->decomposition)))
811 (insert (format "(->decomposition\t%s)%s"
812 (mapconcat (lambda (code)
813 (cond ((symbolp code)
822 (format "#x%04X" code))
824 (format "%s%S" line-breaking code))))
827 (setq attributes (delq '->decomposition attributes))
829 (if (equal (get-char-attribute char '->titlecase)
830 (get-char-attribute char '->uppercase))
831 (setq attributes (delq '->titlecase attributes)))
832 (when (and (memq '->mojikyo attributes)
833 (setq value (get-char-attribute char '->mojikyo)))
834 (insert (format "(->mojikyo\t\t. %06d)\t; %c%s"
835 value (decode-char 'mojikyo value)
837 (setq attributes (delq '->mojikyo attributes))
839 (when (and (memq 'hanyu-dazidian-vol attributes)
840 (setq value (get-char-attribute char 'hanyu-dazidian-vol)))
841 (insert (format "(hanyu-dazidian-vol . %d)%s"
842 value line-breaking))
843 (setq attributes (delq 'hanyu-dazidian-vol attributes))
845 (when (and (memq 'hanyu-dazidian-page attributes)
846 (setq value (get-char-attribute char 'hanyu-dazidian-page)))
847 (insert (format "(hanyu-dazidian-page . %d)%s"
848 value line-breaking))
849 (setq attributes (delq 'hanyu-dazidian-page attributes))
851 (when (and (memq 'hanyu-dazidian-char attributes)
852 (setq value (get-char-attribute char 'hanyu-dazidian-char)))
853 (insert (format "(hanyu-dazidian-char . %d)%s"
854 value line-breaking))
855 (setq attributes (delq 'hanyu-dazidian-char attributes))
858 (dolist (ignored '(composition
859 ->denotational <-subsumptive ->ucs-unified))
860 (setq attributes (delq ignored attributes))))
861 ;; (setq rest ccs-attributes)
864 ;; (setq value (get-char-attribute char (car rest)))
866 ;; (if (>= (length (symbol-name (car rest))) 19)
868 ;; (setq has-long-ccs-name t)
872 ;; (setq rest (cdr rest)))
874 (setq name (car attributes))
875 (if (setq value (get-char-attribute char name))
876 (cond ((setq ret (find-charset name))
877 (setq name (charset-name ret))
878 (if (and (not (memq name dest-ccss))
880 (setq value (get-char-attribute char name))
881 (setq dest-ccss (cons name dest-ccss))))
884 (cond ((memq name '(=daikanwa
885 =daikanwa-rev1 =daikanwa-rev2
887 (if has-long-ccs-name
888 "(%-26s . %05d)\t; %c%s"
889 "(%-18s . %05d)\t; %c%s"))
891 (if has-long-ccs-name
892 "(%-26s . %06d)\t; %c%s"
893 "(%-18s . %06d)\t; %c%s"))
894 ((>= (charset-dimension name) 2)
895 (if has-long-ccs-name
896 "(%-26s . #x%04X)\t; %c%s"
897 "(%-18s . #x%04X)\t; %c%s"))
899 (if has-long-ccs-name
900 "(%-26s . #x%02X)\t; %c%s"
901 "(%-18s . #x%02X)\t; %c%s")))
903 (if (= (charset-iso-graphic-plane name) 1)
905 (cond ((= (charset-dimension name) 1)
907 ((= (charset-dimension name) 2)
909 ((= (charset-dimension name) 3)
913 (char-db-decode-isolated-char name value)
916 ((string-match "^=>ucs@" (symbol-name name))
917 (insert (format "(%-18s . #x%04X)\t; %c%s"
918 name value (decode-char '=ucs value)
921 ((eq name 'jisx0208-1978/4X)
922 (insert (format "(%-18s . #x%04X)%s"
927 (string-match "^->simplified" (symbol-name name)))
929 ((or (eq name 'ideographic-structure)
930 (eq name 'ideographic-)
931 (string-match "^\\(->\\|<-\\)" (symbol-name name)))
932 (insert (format "(%-18s%s " name line-breaking))
933 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
936 (setq cell (car value))
938 (setq cell (decode-char '=ucs cell)))
939 (cond ((eq name '->subsumptive)
942 (get-char-attribute cell atr))
943 char-db-ignored-attributes))
945 (encode-char cell ccs
950 (let ((char-db-ignored-attributes
952 char-db-ignored-attributes)))
953 (insert-char-attributes cell readable))
954 (setq separator lbs))
960 (intern (format "%s*sources" name))))
961 (setq required-features nil)
962 (dolist (source sources)
963 (setq required-features
967 (format "=%s" source))))
971 (when (string-match "@JP" (symbol-name name))
972 (setq required-features
973 (union required-features
984 (insert (format "%S" cell))
985 (char-db-insert-char-spec cell readable
988 (setq separator lbs))
992 (if (consp (car cell))
993 (char-db-insert-char-spec cell readable)
994 (char-db-insert-char-reference cell readable))
995 (setq separator lbs))
999 (insert (prin1-to-string cell))
1000 (setq separator " ")))
1001 (setq value (cdr value)))
1003 (insert line-breaking))
1004 ((memq name '(ideograph=
1005 original-ideograph-of
1006 ancient-ideograph-of
1009 ;; simplified-ideograph-of
1010 ideographic-variants
1011 ;; ideographic-different-form-of
1013 (insert (format "(%-18s%s " name line-breaking))
1014 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1016 (while (consp value)
1017 (setq cell (car value))
1018 (if (and (consp cell)
1023 (char-db-insert-alist cell readable)
1024 (setq separator lbs))
1027 (insert (prin1-to-string cell))
1028 (setq separator " "))
1029 (setq value (cdr value)))
1031 (insert line-breaking))
1033 (insert (format "(%-18s " name))
1034 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1036 (while (consp value)
1037 (setq cell (car value))
1038 (if (and (consp cell)
1040 (setq ret (condition-case nil
1048 (setq key (car (car rest)))
1049 (if (find-charset key)
1050 (setq cal (cons key cal))
1051 (setq al (cons key al)))
1052 (setq rest (cdr rest)))
1055 (insert-char-attributes ret
1058 (setq separator lbs))
1059 (setq ret (prin1-to-string cell))
1061 (if (< (+ (current-column)
1068 (setq separator " "))
1069 (setq value (cdr value)))
1071 (insert line-breaking))
1073 (insert (format "(%-18s . %S)%s"
1077 (setq attributes (cdr attributes)))
1078 ;; (while ccs-attributes
1079 ;; (setq name (charset-name (car ccs-attributes)))
1080 ;; (if (and (not (memq name dest-ccss))
1082 ;; (setq value (get-char-attribute char name))
1083 ;; (setq dest-ccss (cons name dest-ccss))))
1086 ;; (cond ((memq name '(=daikanwa
1087 ;; =daikanwa-rev1 =daikanwa-rev2
1088 ;; =gt =gt-k =cbeta))
1089 ;; (if has-long-ccs-name
1090 ;; "(%-26s . %05d)\t; %c%s"
1091 ;; "(%-18s . %05d)\t; %c%s"))
1092 ;; ((eq name 'mojikyo)
1093 ;; (if has-long-ccs-name
1094 ;; "(%-26s . %06d)\t; %c%s"
1095 ;; "(%-18s . %06d)\t; %c%s"))
1096 ;; ((>= (charset-dimension name) 2)
1097 ;; (if has-long-ccs-name
1098 ;; "(%-26s . #x%04X)\t; %c%s"
1099 ;; "(%-18s . #x%04X)\t; %c%s"))
1101 ;; (if has-long-ccs-name
1102 ;; "(%-26s . #x%02X)\t; %c%s"
1103 ;; "(%-18s . #x%02X)\t; %c%s")))
1105 ;; (if (= (charset-iso-graphic-plane name) 1)
1107 ;; (cond ((= (charset-dimension name) 1)
1109 ;; ((= (charset-dimension name) 2)
1111 ;; ((= (charset-dimension name) 3)
1115 ;; (char-db-decode-isolated-char name value)
1117 ;; (setq ccs-attributes (cdr ccs-attributes)))
1120 (defun insert-char-data (char &optional readable
1123 (narrow-to-region (point)(point))
1124 (insert "(define-char
1126 (insert-char-attributes char readable attributes)
1128 (goto-char (point-min))
1129 (while (re-search-forward "[ \t]+$" nil t)
1132 (goto-char (point-min))
1133 (while (re-search-forward "[ \t][ \t][ \t]*" nil t)
1134 (let ((column (current-column))
1135 (indent-tabs-mode t))
1136 (delete-region (match-beginning 0) (point))
1137 (indent-to column)))
1138 (goto-char (point-max))
1139 ;; (tabify (point-min)(point-max))
1142 (defun insert-char-data-with-variant (char &optional printable
1144 script excluded-script)
1145 (insert-char-data char printable)
1146 (let ((variants (or (char-variants char)
1147 (let ((ucs (get-char-attribute char '->ucs)))
1149 (delete char (char-variants (int-char ucs)))))))
1151 (setq variants (sort variants #'<))
1153 (setq variant (car variants))
1154 (if (and (or (null script)
1155 (null (setq vs (get-char-attribute variant 'script)))
1157 (or (null excluded-script)
1158 (null (setq vs (get-char-attribute variant 'script)))
1159 (not (memq excluded-script vs))))
1160 (or (and no-ucs-unified (get-char-attribute variant '=ucs))
1161 (insert-char-data variant printable)))
1162 (setq variants (cdr variants))
1165 (defun insert-char-range-data (min max &optional script excluded-script)
1168 (while (<= code max)
1169 (setq char (decode-char '=ucs code))
1170 (if (encode-char char '=ucs 'defined-only)
1171 (insert-char-data-with-variant char nil 'no-ucs-unified
1172 script excluded-script))
1173 (setq code (1+ code)))))
1175 (defun write-char-range-data-to-file (min max file
1176 &optional script excluded-script)
1177 (let ((coding-system-for-write 'utf-8-mcs))
1179 (insert ";; -*- coding: utf-8-mcs -*-\n")
1180 (insert-char-range-data min max script excluded-script)
1181 (write-region (point-min)(point-max) file))))
1183 (defvar what-character-original-window-configuration)
1186 (defun what-char-definition (char)
1187 (interactive (list (char-after)))
1188 (let ((buf (get-buffer-create "*Character Description*"))
1189 (the-buf (current-buffer))
1190 (win-conf (current-window-configuration)))
1192 (make-local-variable 'what-character-original-window-configuration)
1193 (setq what-character-original-window-configuration win-conf)
1194 (setq buffer-read-only nil)
1198 (insert-char-data-with-variant char 'printable)
1199 (unless (char-attribute-alist char)
1200 (insert (format ";; = %c\n"
1201 (let* ((rest (split-char char))
1205 (setq code (logior (lsh code 8)
1207 (decode-char ccs code)))))
1208 ;; (char-db-update-comment)
1209 (set-buffer-modified-p nil)
1210 (view-mode the-buf (lambda (buf)
1211 (set-window-configuration
1212 what-character-original-window-configuration)
1214 (goto-char (point-min)))
1216 (set-window-configuration
1217 what-character-original-window-configuration)
1218 (signal (car err) (cdr err)))))))
1220 (provide 'char-db-util)
1222 ;;; char-db-util.el ends here