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)
425 (if (consp attributes)
427 (dolist (name attributes)
428 (unless (memq name char-db-ignored-attributes)
431 (dolist (name (char-attribute-list))
432 (unless (memq name char-db-ignored-attributes)
435 #'char-attribute-name<)))
437 (setq column (current-column)))
438 (let (name value has-long-ccs-name rest
441 (concat "\n" (make-string (1+ column) ?\ )))
442 lbs cell separator ret
445 sources required-features)
447 (when (and (memq 'name attributes)
448 (setq value (get-char-attribute char 'name)))
450 (if (> (+ (current-column) (length value)) 48)
453 value line-breaking))
454 (setq attributes (delq 'name attributes))
456 (when (and (memq 'name* attributes)
457 (setq value (get-char-attribute char 'name*)))
459 (if (> (+ (current-column) (length value)) 48)
462 value line-breaking))
463 (setq attributes (delq 'name* attributes))
465 (when (and (memq 'script attributes)
466 (setq value (get-char-attribute char 'script)))
467 (insert (format "(script\t\t%s)%s"
468 (mapconcat (function prin1-to-string)
471 (setq attributes (delq 'script attributes))
473 (dolist (name '(=>ucs =>ucs*))
474 (when (and (memq name attributes)
475 (setq value (get-char-attribute char name)))
476 (insert (format "(%-18s . #x%04X)\t; %c%s"
477 name value (decode-char '=ucs value)
479 (setq attributes (delq name attributes))))
480 (dolist (name '(=>ucs@gb =>ucs@cns =>ucs@jis =>ucs@ks =>ucs@big5))
481 (when (and (memq name attributes)
482 (setq value (get-char-attribute char name)))
483 (insert (format "(%-18s . #x%04X)\t; %c%s"
488 (symbol-name name) 2)))
491 (setq attributes (delq name attributes))
493 ;; (dolist (name '(=>ucs-gb =>ucs-cns =>ucs-jis =>ucs-ks =>ucs-big5))
494 ;; (when (and (memq name attributes)
495 ;; (setq value (get-char-attribute char name)))
496 ;; (insert (format "(%-18s . #x%04X)\t; %c%s"
499 ;; (substring (symbol-name name) 6)))
501 ;; (decode-char (intern
504 ;; (symbol-name name) 6)))
507 ;; (setq attributes (delq name attributes))))
508 ;; (when (and (memq '->ucs attributes)
509 ;; (setq value (get-char-attribute char '->ucs)))
510 ;; (insert (format (if char-db-convert-obsolete-format
511 ;; "(=>ucs\t\t. #x%04X)\t; %c%s"
512 ;; "(->ucs\t\t. #x%04X)\t; %c%s")
513 ;; value (decode-char '=ucs value)
515 ;; (setq attributes (delq '->ucs attributes))
517 (dolist (name '(=>daikanwa))
518 (when (and (memq name attributes)
519 (setq value (get-char-attribute char name)))
522 (format "(%-18s . %05d)\t; %c%s"
523 name value (decode-char '=daikanwa value)
525 (format "(%-18s %s)\t; %c%s"
527 (mapconcat (function prin1-to-string)
529 (char-representative-of-daikanwa char)
531 (setq attributes (delq name attributes))))
532 (when (and (memq 'general-category attributes)
533 (setq value (get-char-attribute char 'general-category)))
535 "(general-category\t%s) ; %s%s"
536 (mapconcat (lambda (cell)
539 (cond ((rassoc value unidata-normative-category-alist)
540 "Normative Category")
541 ((rassoc value unidata-informative-category-alist)
542 "Informative Category")
546 (setq attributes (delq 'general-category attributes))
548 (when (and (memq 'bidi-category attributes)
549 (setq value (get-char-attribute char 'bidi-category)))
550 (insert (format "(bidi-category\t. %S)%s"
553 (setq attributes (delq 'bidi-category attributes))
555 (unless (or (not (memq 'mirrored attributes))
556 (eq (setq value (get-char-attribute char 'mirrored 'empty))
558 (insert (format "(mirrored\t\t. %S)%s"
561 (setq attributes (delq 'mirrored attributes))
564 ((and (memq 'decimal-digit-value attributes)
565 (setq value (get-char-attribute char 'decimal-digit-value)))
566 (insert (format "(decimal-digit-value . %S)%s"
569 (setq attributes (delq 'decimal-digit-value attributes))
570 (when (and (memq 'digit-value attributes)
571 (setq value (get-char-attribute char 'digit-value)))
572 (insert (format "(digit-value\t . %S)%s"
575 (setq attributes (delq 'digit-value attributes))
577 (when (and (memq 'numeric-value attributes)
578 (setq value (get-char-attribute char 'numeric-value)))
579 (insert (format "(numeric-value\t . %S)%s"
582 (setq attributes (delq 'numeric-value attributes))
586 (when (and (memq 'digit-value attributes)
587 (setq value (get-char-attribute char 'digit-value)))
588 (insert (format "(digit-value\t. %S)%s"
591 (setq attributes (delq 'digit-value attributes))
593 (when (and (memq 'numeric-value attributes)
594 (setq value (get-char-attribute char 'numeric-value)))
595 (insert (format "(numeric-value\t. %S)%s"
598 (setq attributes (delq 'numeric-value attributes))
600 (when (and (memq 'iso-10646-comment attributes)
601 (setq value (get-char-attribute char 'iso-10646-comment)))
602 (insert (format "(iso-10646-comment\t. %S)%s"
605 (setq attributes (delq 'iso-10646-comment attributes))
607 (when (and (memq 'morohashi-daikanwa attributes)
608 (setq value (get-char-attribute char 'morohashi-daikanwa)))
609 (insert (format "(morohashi-daikanwa\t%s)%s"
610 (mapconcat (function prin1-to-string) value " ")
612 (setq attributes (delq 'morohashi-daikanwa attributes))
616 (when (and (memq 'ideographic-radical attributes)
617 (setq value (get-char-attribute char 'ideographic-radical)))
619 (insert (format "(ideographic-radical . %S)\t; %c%s"
621 (aref ideographic-radicals radical)
623 (setq attributes (delq 'ideographic-radical attributes))
626 (dolist (domain char-db-feature-domains)
627 (setq key (intern (format "%s@%s" 'ideographic-radical domain)))
628 (when (and (memq key attributes)
629 (setq value (get-char-attribute char key)))
631 (insert (format "(%s . %S)\t; %c%s"
634 (aref ideographic-radicals radical)
636 (setq attributes (delq key attributes))
638 (setq key (intern (format "%s@%s" 'ideographic-strokes domain)))
639 (when (and (memq key attributes)
640 (setq value (get-char-attribute char key)))
642 (insert (format "(%s . %S)%s"
646 (setq attributes (delq key attributes))
648 (setq key (intern (format "%s@%s" 'total-strokes domain)))
649 (when (and (memq key attributes)
650 (setq value (get-char-attribute char key)))
651 (insert (format "(%s . %S)%s"
655 (setq attributes (delq key attributes))
657 (dolist (feature '(ideographic-radical
660 (setq key (intern (format "%s@%s*sources" feature domain)))
661 (when (and (memq key attributes)
662 (setq value (get-char-attribute char key)))
663 (insert (format "(%s%s" key line-breaking))
665 (insert (format " %s" cell)))
667 (insert line-breaking)
668 (setq attributes (delq key attributes))
671 (when (and (memq 'ideographic-strokes attributes)
672 (setq value (get-char-attribute char 'ideographic-strokes)))
674 (insert (format "(ideographic-strokes . %S)%s"
677 (setq attributes (delq 'ideographic-strokes attributes))
679 (when (and (memq 'kangxi-radical attributes)
680 (setq value (get-char-attribute char 'kangxi-radical)))
681 (unless (eq value radical)
682 (insert (format "(kangxi-radical\t . %S)\t; %c%s"
684 (aref ideographic-radicals value)
687 (setq radical value)))
688 (setq attributes (delq 'kangxi-radical attributes))
690 (when (and (memq 'kangxi-strokes attributes)
691 (setq value (get-char-attribute char 'kangxi-strokes)))
692 (unless (eq value strokes)
693 (insert (format "(kangxi-strokes\t . %S)%s"
697 (setq strokes value)))
698 (setq attributes (delq 'kangxi-strokes attributes))
700 (when (and (memq 'japanese-radical attributes)
701 (setq value (get-char-attribute char 'japanese-radical)))
702 (unless (eq value radical)
703 (insert (format "(japanese-radical\t . %S)\t; %c%s"
705 (aref ideographic-radicals value)
708 (setq radical value)))
709 (setq attributes (delq 'japanese-radical attributes))
711 (when (and (memq 'japanese-strokes attributes)
712 (setq value (get-char-attribute char 'japanese-strokes)))
713 (unless (eq value strokes)
714 (insert (format "(japanese-strokes\t . %S)%s"
718 (setq strokes value)))
719 (setq attributes (delq 'japanese-strokes attributes))
721 (when (and (memq 'cns-radical attributes)
722 (setq value (get-char-attribute char 'cns-radical)))
723 (insert (format "(cns-radical\t . %S)\t; %c%s"
725 (aref ideographic-radicals value)
727 (setq attributes (delq 'cns-radical attributes))
729 (when (and (memq 'cns-strokes attributes)
730 (setq value (get-char-attribute char 'cns-strokes)))
731 (unless (eq value strokes)
732 (insert (format "(cns-strokes\t . %S)%s"
736 (setq strokes value)))
737 (setq attributes (delq 'cns-strokes attributes))
739 (when (and (memq 'shinjigen-1-radical attributes)
740 (setq value (get-char-attribute char 'shinjigen-1-radical)))
741 (unless (eq value radical)
742 (insert (format "(shinjigen-1-radical . %S)\t; %c%s"
744 (aref ideographic-radicals value)
747 (setq radical value)))
748 (setq attributes (delq 'shinjigen-1-radical attributes))
750 (when (and (memq 'ideographic- attributes)
751 (setq value (get-char-attribute char 'ideographic-)))
752 (insert "(ideographic- ")
753 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
756 (setq cell (car value))
758 (setq cell (decode-char '=ucs cell)))
759 (cond ((characterp cell)
763 (insert (format "%S" cell))
764 (char-db-insert-char-spec cell readable))
765 (setq separator lbs))
769 (if (consp (car cell))
770 (char-db-insert-char-spec cell readable)
771 (char-db-insert-char-reference cell readable))
772 (setq separator lbs))
776 (insert (prin1-to-string cell))
777 (setq separator " ")))
778 (setq value (cdr value)))
780 (insert line-breaking)
781 (setq attributes (delq 'ideographic- attributes)))
782 (when (and (memq 'total-strokes attributes)
783 (setq value (get-char-attribute char 'total-strokes)))
784 (insert (format "(total-strokes . %S)%s"
787 (setq attributes (delq 'total-strokes attributes))
789 (when (and (memq '->ideograph attributes)
790 (setq value (get-char-attribute char '->ideograph)))
791 (insert (format "(->ideograph\t%s)%s"
792 (mapconcat (lambda (code)
793 (cond ((symbolp code)
796 (format "#x%04X" code))
799 line-breaking code))))
802 (setq attributes (delq '->ideograph attributes))
804 (when (and (memq '->decomposition attributes)
805 (setq value (get-char-attribute char '->decomposition)))
806 (insert (format "(->decomposition\t%s)%s"
807 (mapconcat (lambda (code)
808 (cond ((symbolp code)
817 (format "#x%04X" code))
819 (format "%s%S" line-breaking code))))
822 (setq attributes (delq '->decomposition attributes))
824 (if (equal (get-char-attribute char '->titlecase)
825 (get-char-attribute char '->uppercase))
826 (setq attributes (delq '->titlecase attributes)))
827 (when (and (memq '->mojikyo attributes)
828 (setq value (get-char-attribute char '->mojikyo)))
829 (insert (format "(->mojikyo\t\t. %06d)\t; %c%s"
830 value (decode-char 'mojikyo value)
832 (setq attributes (delq '->mojikyo attributes))
834 (when (and (memq 'hanyu-dazidian-vol attributes)
835 (setq value (get-char-attribute char 'hanyu-dazidian-vol)))
836 (insert (format "(hanyu-dazidian-vol . %d)%s"
837 value line-breaking))
838 (setq attributes (delq 'hanyu-dazidian-vol attributes))
840 (when (and (memq 'hanyu-dazidian-page attributes)
841 (setq value (get-char-attribute char 'hanyu-dazidian-page)))
842 (insert (format "(hanyu-dazidian-page . %d)%s"
843 value line-breaking))
844 (setq attributes (delq 'hanyu-dazidian-page attributes))
846 (when (and (memq 'hanyu-dazidian-char attributes)
847 (setq value (get-char-attribute char 'hanyu-dazidian-char)))
848 (insert (format "(hanyu-dazidian-char . %d)%s"
849 value line-breaking))
850 (setq attributes (delq 'hanyu-dazidian-char attributes))
853 (dolist (ignored '(composition
854 ->denotational <-subsumptive ->ucs-unified))
855 (setq attributes (delq ignored attributes))))
856 ;; (setq rest ccs-attributes)
859 ;; (setq value (get-char-attribute char (car rest)))
861 ;; (if (>= (length (symbol-name (car rest))) 19)
863 ;; (setq has-long-ccs-name t)
867 ;; (setq rest (cdr rest)))
869 (setq name (car attributes))
870 (if (setq value (get-char-attribute char name))
871 (cond ((setq ret (find-charset name))
872 (setq name (charset-name ret))
873 (if (and (not (memq name dest-ccss))
875 (setq value (get-char-attribute char name))
876 (setq dest-ccss (cons name dest-ccss))))
879 (cond ((memq name '(=daikanwa
880 =daikanwa-rev1 =daikanwa-rev2
882 (if has-long-ccs-name
883 "(%-26s . %05d)\t; %c%s"
884 "(%-18s . %05d)\t; %c%s"))
886 (if has-long-ccs-name
887 "(%-26s . %06d)\t; %c%s"
888 "(%-18s . %06d)\t; %c%s"))
889 ((>= (charset-dimension name) 2)
890 (if has-long-ccs-name
891 "(%-26s . #x%04X)\t; %c%s"
892 "(%-18s . #x%04X)\t; %c%s"))
894 (if has-long-ccs-name
895 "(%-26s . #x%02X)\t; %c%s"
896 "(%-18s . #x%02X)\t; %c%s")))
898 (if (= (charset-iso-graphic-plane name) 1)
900 (cond ((= (charset-dimension name) 1)
902 ((= (charset-dimension name) 2)
904 ((= (charset-dimension name) 3)
908 (char-db-decode-isolated-char name value)
911 ((string-match "^=>ucs@" (symbol-name name))
912 (insert (format "(%-18s . #x%04X)\t; %c%s"
913 name value (decode-char '=ucs value)
916 ((eq name 'jisx0208-1978/4X)
917 (insert (format "(%-18s . #x%04X)%s"
922 (string-match "^->simplified" (symbol-name name)))
924 ((or (eq name 'ideographic-structure)
925 (eq name 'ideographic-)
926 (string-match "^\\(->\\|<-\\)" (symbol-name name)))
927 (insert (format "(%-18s%s " name line-breaking))
928 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
931 (setq cell (car value))
933 (setq cell (decode-char '=ucs cell)))
934 (cond ((eq name '->subsumptive)
937 (let ((char-db-ignored-attributes
939 char-db-ignored-attributes)))
940 (insert-char-attributes cell readable))
941 (setq separator lbs))
946 (intern (format "%s*sources" name))))
947 (setq required-features nil)
948 (dolist (source sources)
949 (setq required-features
953 (format "=%s" source))))
957 (when (string-match "@JP" (symbol-name name))
958 (setq required-features
959 (union required-features
970 (insert (format "%S" cell))
971 (char-db-insert-char-spec cell readable
974 (setq separator lbs))
978 (if (consp (car cell))
979 (char-db-insert-char-spec cell readable)
980 (char-db-insert-char-reference cell readable))
981 (setq separator lbs))
985 (insert (prin1-to-string cell))
986 (setq separator " ")))
987 (setq value (cdr value)))
989 (insert line-breaking))
990 ((memq name '(ideograph=
991 original-ideograph-of
995 ;; simplified-ideograph-of
997 ;; ideographic-different-form-of
999 (insert (format "(%-18s%s " name line-breaking))
1000 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1002 (while (consp value)
1003 (setq cell (car value))
1004 (if (and (consp cell)
1009 (char-db-insert-alist cell readable)
1010 (setq separator lbs))
1013 (insert (prin1-to-string cell))
1014 (setq separator " "))
1015 (setq value (cdr value)))
1017 (insert line-breaking))
1019 (insert (format "(%-18s " name))
1020 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1022 (while (consp value)
1023 (setq cell (car value))
1024 (if (and (consp cell)
1026 (setq ret (condition-case nil
1034 (setq key (car (car rest)))
1035 (if (find-charset key)
1036 (setq cal (cons key cal))
1037 (setq al (cons key al)))
1038 (setq rest (cdr rest)))
1041 (insert-char-attributes ret
1044 (setq separator lbs))
1045 (setq ret (prin1-to-string cell))
1047 (if (< (+ (current-column)
1054 (setq separator " "))
1055 (setq value (cdr value)))
1057 (insert line-breaking))
1059 (insert (format "(%-18s . %S)%s"
1063 (setq attributes (cdr attributes)))
1064 ;; (while ccs-attributes
1065 ;; (setq name (charset-name (car ccs-attributes)))
1066 ;; (if (and (not (memq name dest-ccss))
1068 ;; (setq value (get-char-attribute char name))
1069 ;; (setq dest-ccss (cons name dest-ccss))))
1072 ;; (cond ((memq name '(=daikanwa
1073 ;; =daikanwa-rev1 =daikanwa-rev2
1074 ;; =gt =gt-k =cbeta))
1075 ;; (if has-long-ccs-name
1076 ;; "(%-26s . %05d)\t; %c%s"
1077 ;; "(%-18s . %05d)\t; %c%s"))
1078 ;; ((eq name 'mojikyo)
1079 ;; (if has-long-ccs-name
1080 ;; "(%-26s . %06d)\t; %c%s"
1081 ;; "(%-18s . %06d)\t; %c%s"))
1082 ;; ((>= (charset-dimension name) 2)
1083 ;; (if has-long-ccs-name
1084 ;; "(%-26s . #x%04X)\t; %c%s"
1085 ;; "(%-18s . #x%04X)\t; %c%s"))
1087 ;; (if has-long-ccs-name
1088 ;; "(%-26s . #x%02X)\t; %c%s"
1089 ;; "(%-18s . #x%02X)\t; %c%s")))
1091 ;; (if (= (charset-iso-graphic-plane name) 1)
1093 ;; (cond ((= (charset-dimension name) 1)
1095 ;; ((= (charset-dimension name) 2)
1097 ;; ((= (charset-dimension name) 3)
1101 ;; (char-db-decode-isolated-char name value)
1103 ;; (setq ccs-attributes (cdr ccs-attributes)))
1106 (defun insert-char-data (char &optional readable
1109 (narrow-to-region (point)(point))
1110 (insert "(define-char
1112 (insert-char-attributes char readable attributes)
1114 (goto-char (point-min))
1115 (while (re-search-forward "[ \t]+$" nil t)
1118 (goto-char (point-min))
1119 (while (re-search-forward "[ \t][ \t][ \t]*" nil t)
1120 (let ((column (current-column))
1121 (indent-tabs-mode t))
1122 (delete-region (match-beginning 0) (point))
1123 (indent-to column)))
1124 (goto-char (point-max))
1125 ;; (tabify (point-min)(point-max))
1128 (defun insert-char-data-with-variant (char &optional printable
1130 script excluded-script)
1131 (insert-char-data char printable)
1132 (let ((variants (or (char-variants char)
1133 (let ((ucs (get-char-attribute char '->ucs)))
1135 (delete char (char-variants (int-char ucs)))))))
1137 (setq variants (sort variants #'<))
1139 (setq variant (car variants))
1140 (if (and (or (null script)
1141 (null (setq vs (get-char-attribute variant 'script)))
1143 (or (null excluded-script)
1144 (null (setq vs (get-char-attribute variant 'script)))
1145 (not (memq excluded-script vs))))
1146 (or (and no-ucs-unified (get-char-attribute variant '=ucs))
1147 (insert-char-data variant printable)))
1148 (setq variants (cdr variants))
1151 (defun insert-char-range-data (min max &optional script excluded-script)
1154 (while (<= code max)
1155 (setq char (decode-char '=ucs code))
1156 (if (encode-char char '=ucs 'defined-only)
1157 (insert-char-data-with-variant char nil 'no-ucs-unified
1158 script excluded-script))
1159 (setq code (1+ code)))))
1161 (defun write-char-range-data-to-file (min max file
1162 &optional script excluded-script)
1163 (let ((coding-system-for-write 'utf-8-mcs))
1165 (insert ";; -*- coding: utf-8-mcs -*-\n")
1166 (insert-char-range-data min max script excluded-script)
1167 (write-region (point-min)(point-max) file))))
1169 (defvar what-character-original-window-configuration)
1172 (defun what-char-definition (char)
1173 (interactive (list (char-after)))
1174 (let ((buf (get-buffer-create "*Character Description*"))
1175 (the-buf (current-buffer))
1176 (win-conf (current-window-configuration)))
1178 (make-local-variable 'what-character-original-window-configuration)
1179 (setq what-character-original-window-configuration win-conf)
1180 (setq buffer-read-only nil)
1184 (insert-char-data-with-variant char 'printable)
1185 (unless (char-attribute-alist char)
1186 (insert (format ";; = %c\n"
1187 (let* ((rest (split-char char))
1191 (setq code (logior (lsh code 8)
1193 (decode-char ccs code)))))
1194 ;; (char-db-update-comment)
1195 (set-buffer-modified-p nil)
1196 (view-mode the-buf (lambda (buf)
1197 (set-window-configuration
1198 what-character-original-window-configuration)
1200 (goto-char (point-min)))
1202 (set-window-configuration
1203 what-character-original-window-configuration)
1204 (signal (car err) (cdr err)))))))
1206 (provide 'char-db-util)
1208 ;;; char-db-util.el ends here