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-file-coding-system 'utf-8-mcs-er)
74 (defvar char-db-feature-domains
75 '(ucs daikanwa cns gt jis jis/alt jis/a jis/b
76 jis-x0212 jis-x0213 cdp shinjigen misc unknown))
78 (defvar char-db-ignored-attributes nil)
80 (defun char-attribute-name< (ka kb)
82 ((eq '->denotational kb)
84 ((eq '->subsumptive kb)
85 (not (eq '->denotational ka)))
86 ((eq '->denotational ka)
88 ((eq '->subsumptive ka)
92 (if (<= (charset-id ka) 1)
93 (if (<= (charset-id kb) 1)
95 ((= (charset-dimension ka)
96 (charset-dimension kb))
97 (> (charset-id ka)(charset-id kb)))
99 (> (charset-dimension ka)
100 (charset-dimension kb))
103 (if (<= (charset-id kb) 1)
105 (< (charset-id ka)(charset-id kb))))
111 (string< (symbol-name ka)
117 (defvar char-db-coded-charset-priority-list
175 (defun char-db-make-char-spec (char)
177 (cond ((characterp char)
178 (cond ((and (setq ret (encode-char char '=ucs 'defined-only))
179 (not (and (<= #xE000 ret)(<= ret #xF8FF))))
180 (setq char-spec (list (cons '=ucs ret)))
181 (cond ((setq ret (get-char-attribute char 'name))
182 (setq char-spec (cons (cons 'name ret) char-spec))
184 ((setq ret (get-char-attribute char 'name*))
185 (setq char-spec (cons (cons 'name* ret) char-spec))
190 (let ((rest char-db-coded-charset-priority-list)
193 (setq ccs (charset-name
194 (find-charset (car rest))))
196 (encode-char char ccs
198 (throw 'tag (cons ccs ret)))
199 (setq rest (cdr rest))))))
200 (setq char-spec (list ret))
201 (dolist (ccs (delq (car ret) (charset-list)))
202 (if (and (or (charset-iso-final-char ccs)
208 (setq ccs (charset-name ccs))
209 (null (assq ccs char-spec))
210 (setq ret (encode-char char ccs 'defined-only)))
211 (setq char-spec (cons (cons ccs ret) char-spec))))
213 (setq char-spec (split-char char)))
214 (cond ((setq ret (get-char-attribute char 'name))
215 (setq char-spec (cons (cons 'name ret) char-spec))
217 ((setq ret (get-char-attribute char 'name*))
218 (setq char-spec (cons (cons 'name* ret) char-spec))
225 (defun char-db-insert-char-spec (char &optional readable column
228 (setq column (current-column)))
229 (let (char-spec temp-char)
230 (setq char-spec (char-db-make-char-spec char))
231 (unless (or (characterp char) ; char
233 (setq char (find-char char-spec))
235 ;; define temporary character
236 ;; Current implementation is dirty.
237 (setq temp-char (define-char (cons '(ideograph-daikanwa . 0)
239 (remove-char-attribute temp-char 'ideograph-daikanwa)
240 (setq char temp-char))
241 (insert-char-attributes char
243 (union (mapcar #'car char-spec)
246 ;; undefine temporary character
247 ;; Current implementation is dirty.
248 (setq char-spec (char-attribute-alist temp-char))
250 (remove-char-attribute temp-char (car (car char-spec)))
251 (setq char-spec (cdr char-spec))))))
253 (defun char-db-insert-alist (alist &optional readable column)
255 (setq column (current-column)))
257 (concat "\n" (make-string (1+ column) ?\ )))
261 lbs cell rest separator)
264 (setq name (car (car alist))
265 value (cdr (car alist)))
266 (cond ((eq name 'char)
268 (if (setq ret (condition-case nil
276 (setq key (car (car value)))
277 ;; (if (find-charset key)
278 ;; (setq cal (cons key cal))
279 (setq al (cons key al))
281 (setq value (cdr value)))
282 (insert-char-attributes ret
286 (insert (prin1-to-string value)))
288 (insert line-breaking))
290 (insert (format "(%-18s " name))
291 (setq lbs (concat "\n" (make-string (current-column) ?\ )))
293 (setq cell (car value))
294 (if (and (consp cell)
296 (setq ret (condition-case nil
306 (setq key (car (car rest)))
307 ;; (if (find-charset key)
308 ;; (setq cal (cons key cal))
309 (setq al (cons key al))
311 (setq rest (cdr rest)))
314 (insert-char-attributes ret
318 (setq separator lbs))
321 (insert (prin1-to-string cell))
322 (setq separator " "))
323 (setq value (cdr value)))
325 (insert line-breaking))
327 (insert (format "(%-18s . %S)%s"
330 (setq alist (cdr alist))))
333 (defun char-db-insert-char-reference (plist &optional readable column)
335 (setq column (current-column)))
337 (concat "\n" (make-string (1+ column) ?\ )))
342 (setq name (pop plist))
343 (setq value (pop plist))
344 (cond ((eq name :char)
347 (cond ((numberp value)
348 (setq value (decode-char '=ucs value)))
350 ;; (setq value (or (find-char value)
353 (char-db-insert-char-spec value readable)
354 (insert line-breaking)
357 (insert (format "%s%s\t%d ; %c%s"
360 (aref ideographic-radicals value)
364 (insert (format "%s%s\t%S" separator name value))
365 (setq separator line-breaking)))
369 (defun char-db-decode-isolated-char (ccs code-point)
372 (cond ((eq ccs 'arabic-iso8859-6)
373 (decode-char ccs code-point))
374 ((and (memq ccs '(=gt-pj-1
385 (setq ret (decode-char ccs code-point))
386 (setq ret (encode-char ret '=gt 'defined-only)))
387 (decode-builtin-char '=gt ret))
389 (decode-builtin-char ccs code-point))))
390 (cond ((and (<= 0 (char-int ret))
391 (<= (char-int ret) #x1F))
392 (decode-char '=ucs (+ #x2400 (char-int ret))))
393 ((= (char-int ret) #x7F)
397 (defvar char-db-convert-obsolete-format t)
399 (defun char-db-insert-ccs-feature (name value line-breaking)
402 (cond ((memq name '(=daikanwa
403 =daikanwa@rev1 =daikanwa@rev2
405 "(%-18s . %05d)\t; %c")
407 "(%-18s . %06d)\t; %c")
408 ((>= (charset-dimension name) 2)
409 "(%-18s . #x%04X)\t; %c")
411 "(%-18s . #x%02X)\t; %c"))
413 (if (= (charset-iso-graphic-plane name) 1)
415 (cond ((= (charset-dimension name) 1)
417 ((= (charset-dimension name) 2)
419 ((= (charset-dimension name) 3)
423 (char-db-decode-isolated-char name value)))
424 (if (and (= (charset-chars name) 94)
425 (= (charset-dimension name) 2))
426 (insert (format " [%02d-%02d]"
427 (- (lsh value -8) 32)
428 (- (logand value 255) 32))))
429 (insert line-breaking))
431 (defun insert-char-attributes (char &optional readable attributes column)
433 (setq column (current-column)))
434 (let (name value ; has-long-ccs-name
438 (concat "\n" (make-string (1+ column) ?\ )))
439 lbs cell separator ret
442 sources required-features
447 (if (consp attributes)
449 (dolist (name attributes)
450 (unless (memq name char-db-ignored-attributes)
451 (if (find-charset name)
455 (dolist (name (char-attribute-list))
456 (unless (memq name char-db-ignored-attributes)
457 (if (find-charset name)
461 #'char-attribute-name<)))
463 (when (and (memq 'name attributes)
464 (setq value (get-char-attribute char 'name)))
466 (if (> (+ (current-column) (length value)) 48)
469 value line-breaking))
470 (setq attributes (delq 'name attributes))
472 (when (and (memq 'name* attributes)
473 (setq value (get-char-attribute char 'name*)))
475 (if (> (+ (current-column) (length value)) 48)
478 value line-breaking))
479 (setq attributes (delq 'name* attributes))
481 (when (and (memq 'script attributes)
482 (setq value (get-char-attribute char 'script)))
483 (insert (format "(script\t\t%s)%s"
484 (mapconcat (function prin1-to-string)
487 (setq attributes (delq 'script attributes))
489 ;; (when (and (memq '<-denotational attributes)
490 ;; (setq value (get-char-attribute char '<-denotational))
491 ;; (null (cdr value))
492 ;; (setq value (encode-char (car value) 'ucs 'defined-only)))
493 ;; (insert (format "(%-18s . #x%04X)\t; %c%s"
494 ;; '=>ucs value (decode-char 'ucs value)
496 ;; (setq attributes (delq '<-denotational attributes)))
497 (dolist (name '(=>ucs =>ucs*))
498 (when (and (memq name attributes)
499 (setq value (get-char-attribute char name)))
500 (insert (format "(%-18s . #x%04X)\t; %c%s"
501 name value (decode-char '=ucs value)
503 (setq attributes (delq name attributes))))
504 (dolist (name '(=>ucs@gb =>ucs@cns =>ucs@jis =>ucs@ks =>ucs@big5))
505 (when (and (memq name attributes)
506 (setq value (get-char-attribute char name)))
507 (insert (format "(%-18s . #x%04X)\t; %c%s"
512 (symbol-name name) 2)))
515 (setq attributes (delq name 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))
628 char-db-feature-domains
630 (dolist (feature (char-attribute-list))
631 (setq feature (symbol-name feature))
633 "\\(radical\\|strokes\\)@\\([^@*]+\\)\\(\\*\\|$\\)"
635 (setq domain (intern (match-string 2 feature)))
636 (unless (memq domain dest)
637 (setq dest (cons domain dest)))))
638 (sort dest #'string<))))
639 (setq key (intern (format "%s@%s" 'ideographic-radical domain)))
640 (when (and (memq key attributes)
641 (setq value (get-char-attribute char key)))
643 (insert (format "(%s . %S)\t; %c%s"
646 (aref ideographic-radicals radical)
648 (setq attributes (delq key attributes))
650 (setq key (intern (format "%s@%s" 'ideographic-strokes domain)))
651 (when (and (memq key attributes)
652 (setq value (get-char-attribute char key)))
654 (insert (format "(%s . %S)%s"
658 (setq attributes (delq key attributes))
660 (setq key (intern (format "%s@%s" 'total-strokes domain)))
661 (when (and (memq key attributes)
662 (setq value (get-char-attribute char key)))
663 (insert (format "(%s . %S)%s"
667 (setq attributes (delq key attributes))
669 (dolist (feature '(ideographic-radical
672 (setq key (intern (format "%s@%s*sources" feature domain)))
673 (when (and (memq key attributes)
674 (setq value (get-char-attribute char key)))
675 (insert (format "(%s%s" key line-breaking))
677 (insert (format " %s" cell)))
679 (insert line-breaking)
680 (setq attributes (delq key attributes))
683 (when (and (memq 'ideographic-strokes attributes)
684 (setq value (get-char-attribute char 'ideographic-strokes)))
686 (insert (format "(ideographic-strokes . %S)%s"
689 (setq attributes (delq 'ideographic-strokes attributes))
691 (when (and (memq 'kangxi-radical attributes)
692 (setq value (get-char-attribute char 'kangxi-radical)))
693 (unless (eq value radical)
694 (insert (format "(kangxi-radical\t . %S)\t; %c%s"
696 (aref ideographic-radicals value)
699 (setq radical value)))
700 (setq attributes (delq 'kangxi-radical attributes))
702 (when (and (memq 'kangxi-strokes attributes)
703 (setq value (get-char-attribute char 'kangxi-strokes)))
704 (unless (eq value strokes)
705 (insert (format "(kangxi-strokes\t . %S)%s"
709 (setq strokes value)))
710 (setq attributes (delq 'kangxi-strokes attributes))
712 (when (and (memq 'japanese-radical attributes)
713 (setq value (get-char-attribute char 'japanese-radical)))
714 (unless (eq value radical)
715 (insert (format "(japanese-radical\t . %S)\t; %c%s"
717 (aref ideographic-radicals value)
720 (setq radical value)))
721 (setq attributes (delq 'japanese-radical attributes))
723 (when (and (memq 'japanese-strokes attributes)
724 (setq value (get-char-attribute char 'japanese-strokes)))
725 (unless (eq value strokes)
726 (insert (format "(japanese-strokes\t . %S)%s"
730 (setq strokes value)))
731 (setq attributes (delq 'japanese-strokes attributes))
733 (when (and (memq 'cns-radical attributes)
734 (setq value (get-char-attribute char 'cns-radical)))
735 (insert (format "(cns-radical\t . %S)\t; %c%s"
737 (aref ideographic-radicals value)
739 (setq attributes (delq 'cns-radical attributes))
741 (when (and (memq 'cns-strokes attributes)
742 (setq value (get-char-attribute char 'cns-strokes)))
743 (unless (eq value strokes)
744 (insert (format "(cns-strokes\t . %S)%s"
748 (setq strokes value)))
749 (setq attributes (delq 'cns-strokes attributes))
751 (when (and (memq 'shinjigen-1-radical attributes)
752 (setq value (get-char-attribute char 'shinjigen-1-radical)))
753 (unless (eq value radical)
754 (insert (format "(shinjigen-1-radical . %S)\t; %c%s"
756 (aref ideographic-radicals value)
759 (setq radical value)))
760 (setq attributes (delq 'shinjigen-1-radical attributes))
762 (when (and (memq 'ideographic- attributes)
763 (setq value (get-char-attribute char 'ideographic-)))
764 (insert "(ideographic- ")
765 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
768 (setq cell (car value))
770 (setq cell (decode-char '=ucs cell)))
771 (cond ((characterp cell)
775 (insert (format "%S" cell))
776 (char-db-insert-char-spec cell readable))
777 (setq separator lbs))
781 (if (consp (car cell))
782 (char-db-insert-char-spec cell readable)
783 (char-db-insert-char-reference cell readable))
784 (setq separator lbs))
788 (insert (prin1-to-string cell))
789 (setq separator " ")))
790 (setq value (cdr value)))
792 (insert line-breaking)
793 (setq attributes (delq 'ideographic- attributes)))
794 (when (and (memq 'total-strokes attributes)
795 (setq value (get-char-attribute char 'total-strokes)))
796 (insert (format "(total-strokes . %S)%s"
799 (setq attributes (delq 'total-strokes attributes))
801 (when (and (memq '->ideograph attributes)
802 (setq value (get-char-attribute char '->ideograph)))
803 (insert (format "(->ideograph\t%s)%s"
804 (mapconcat (lambda (code)
805 (cond ((symbolp code)
808 (format "#x%04X" code))
811 line-breaking code))))
814 (setq attributes (delq '->ideograph attributes))
816 (when (and (memq '->decomposition attributes)
817 (setq value (get-char-attribute char '->decomposition)))
818 (insert (format "(->decomposition\t%s)%s"
819 (mapconcat (lambda (code)
820 (cond ((symbolp code)
829 (format "#x%04X" code))
831 (format "%s%S" line-breaking code))))
834 (setq attributes (delq '->decomposition attributes))
836 (if (equal (get-char-attribute char '->titlecase)
837 (get-char-attribute char '->uppercase))
838 (setq attributes (delq '->titlecase attributes)))
839 (when (and (memq '->mojikyo attributes)
840 (setq value (get-char-attribute char '->mojikyo)))
841 (insert (format "(->mojikyo\t\t. %06d)\t; %c%s"
842 value (decode-char 'mojikyo value)
844 (setq attributes (delq '->mojikyo attributes))
846 (when (and (memq 'hanyu-dazidian-vol attributes)
847 (setq value (get-char-attribute char 'hanyu-dazidian-vol)))
848 (insert (format "(hanyu-dazidian-vol . %d)%s"
849 value line-breaking))
850 (setq attributes (delq 'hanyu-dazidian-vol attributes))
852 (when (and (memq 'hanyu-dazidian-page attributes)
853 (setq value (get-char-attribute char 'hanyu-dazidian-page)))
854 (insert (format "(hanyu-dazidian-page . %d)%s"
855 value line-breaking))
856 (setq attributes (delq 'hanyu-dazidian-page attributes))
858 (when (and (memq 'hanyu-dazidian-char attributes)
859 (setq value (get-char-attribute char 'hanyu-dazidian-char)))
860 (insert (format "(hanyu-dazidian-char . %d)%s"
861 value line-breaking))
862 (setq attributes (delq 'hanyu-dazidian-char attributes))
865 (dolist (ignored '(composition
866 ->denotational <-subsumptive ->ucs-unified
867 ->ideographic-component-forms))
868 (setq attributes (delq ignored attributes))))
870 (setq name (car attributes))
871 (if (setq value (get-char-attribute char name))
872 (cond ((setq ret (find-charset name))
873 (setq name (charset-name ret))
874 (if (and (not (memq name dest-ccss))
876 (setq value (get-char-attribute char name))
877 (setq dest-ccss (cons name dest-ccss))))
878 (char-db-insert-ccs-feature name value line-breaking))
880 ((string-match "^=>ucs@" (symbol-name name))
881 (insert (format "(%-18s . #x%04X)\t; %c%s"
882 name value (decode-char '=ucs value)
885 ((eq name 'jisx0208-1978/4X)
886 (insert (format "(%-18s . #x%04X)%s"
891 (null (get-char-attribute
893 (intern (format "%s*sources" name))))
894 (not (string-match "\\*sources$" (symbol-name name)))
895 (or (eq name '<-identical)
896 (string-match "^->halfwidth" (symbol-name name))
898 (string-match "^->fullwidth" (symbol-name name))
901 (characterp (car value))
903 (car value) '=ucs 'defined-only))))
904 (string-match "^->simplified" (symbol-name name))
905 (string-match "^->vulgar" (symbol-name name))
906 (string-match "^->wrong" (symbol-name name))
907 (string-match "^->same" (symbol-name name))
908 (string-match "^->original" (symbol-name name))
909 (string-match "^->ancient" (symbol-name name))
912 ((or (eq name 'ideographic-structure)
913 (eq name 'ideographic-)
914 (string-match "^\\(->\\|<-\\)" (symbol-name name)))
915 (insert (format "(%-18s%s " name line-breaking))
916 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
919 (setq cell (car value))
921 (setq cell (decode-char '=ucs cell)))
922 (cond ((eq name '->subsumptive)
925 (get-char-attribute cell atr))
926 char-db-ignored-attributes))
928 (encode-char cell ccs
933 (let ((char-db-ignored-attributes
935 char-db-ignored-attributes)))
936 (insert-char-attributes cell readable))
937 (setq separator lbs))
943 (intern (format "%s*sources" name))))
944 (setq required-features nil)
945 (dolist (source sources)
947 ((memq source '(JP JP/Jouyou
949 (setq required-features
950 (union required-features
959 (setq required-features
960 (union required-features
966 (setq ret (intern (format "=%s" source))))
967 (setq required-features
968 (cons ret required-features)))
969 (t (setq required-features
970 (cons source required-features)))))
971 (cond ((string-match "@JP" (symbol-name name))
972 (setq required-features
973 (union required-features
981 ((string-match "@CN" (symbol-name name))
982 (setq required-features
983 (union required-features
990 (insert (format "%S" cell))
991 (char-db-insert-char-spec cell readable
994 (setq separator lbs))
998 (if (consp (car cell))
999 (char-db-insert-char-spec cell readable)
1000 (char-db-insert-char-reference cell readable))
1001 (setq separator lbs))
1005 (insert (prin1-to-string cell))
1006 (setq separator " ")))
1007 (setq value (cdr value)))
1009 (insert line-breaking))
1010 ((memq name '(ideograph=
1011 original-ideograph-of
1012 ancient-ideograph-of
1015 ;; simplified-ideograph-of
1016 ideographic-variants
1017 ;; ideographic-different-form-of
1019 (insert (format "(%-18s%s " name line-breaking))
1020 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1022 (while (consp value)
1023 (setq cell (car value))
1024 (if (and (consp cell)
1029 (char-db-insert-alist cell readable)
1030 (setq separator lbs))
1033 (insert (prin1-to-string cell))
1034 (setq separator " "))
1035 (setq value (cdr value)))
1037 (insert line-breaking))
1039 (insert (format "(%-18s " name))
1040 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1042 (while (consp value)
1043 (setq cell (car value))
1044 (if (and (consp cell)
1046 (setq ret (condition-case nil
1054 (setq key (car (car rest)))
1055 (if (find-charset key)
1056 (setq cal (cons key cal))
1057 (setq al (cons key al)))
1058 (setq rest (cdr rest)))
1061 (insert-char-attributes ret
1064 (setq separator lbs))
1065 (setq ret (prin1-to-string cell))
1067 (if (< (+ (current-column)
1074 (setq separator " "))
1075 (setq value (cdr value)))
1077 (insert line-breaking))
1079 (insert (format "(%-18s . %S)%s"
1083 (setq attributes (cdr attributes)))
1086 (defun insert-char-data (char &optional readable
1089 (narrow-to-region (point)(point))
1090 (insert "(define-char
1092 (insert-char-attributes char readable attributes)
1094 (goto-char (point-min))
1095 (while (re-search-forward "[ \t]+$" nil t)
1098 (goto-char (point-min))
1099 (while (re-search-forward "[ \t][ \t][ \t]*" nil t)
1100 (let ((column (current-column))
1101 (indent-tabs-mode t))
1102 (delete-region (match-beginning 0) (point))
1103 (indent-to column)))
1104 (goto-char (point-max))
1105 ;; (tabify (point-min)(point-max))
1108 (defun insert-char-data-with-variant (char &optional printable
1110 script excluded-script)
1111 (insert-char-data char printable)
1112 (let ((variants (or (char-variants char)
1113 (let ((ucs (get-char-attribute char '->ucs)))
1115 (delete char (char-variants (int-char ucs)))))))
1117 (setq variants (sort variants #'<))
1119 (setq variant (car variants))
1120 (unless (get-char-attribute variant '<-subsumptive)
1121 (if (and (or (null script)
1122 (null (setq vs (get-char-attribute variant 'script)))
1124 (or (null excluded-script)
1125 (null (setq vs (get-char-attribute variant 'script)))
1126 (not (memq excluded-script vs))))
1127 (unless (and no-ucs-unified (get-char-attribute variant '=ucs))
1128 (insert-char-data variant printable)
1129 (if (setq ret (char-variants variant))
1131 (or (memq (car ret) variants)
1132 ;; (get-char-attribute (car ret) '<-subsumptive)
1133 (setq variants (append variants (list (car ret)))))
1134 (setq ret (cdr ret)))))))
1135 (setq variants (cdr variants)))))
1137 (defun insert-char-range-data (min max &optional script excluded-script)
1140 (while (<= code max)
1141 (setq char (decode-char '=ucs code))
1142 (if (encode-char char '=ucs 'defined-only)
1143 (insert-char-data-with-variant char nil 'no-ucs-unified
1144 script excluded-script))
1145 (setq code (1+ code)))))
1147 (defun write-char-range-data-to-file (min max file
1148 &optional script excluded-script)
1149 (let ((coding-system-for-write char-db-file-coding-system))
1151 (insert (format ";; -*- coding: %s -*-\n"
1152 char-db-file-coding-system))
1153 (insert-char-range-data min max script excluded-script)
1154 (write-region (point-min)(point-max) file))))
1156 (defvar what-character-original-window-configuration)
1159 (defun what-char-definition (char)
1160 (interactive (list (char-after)))
1161 (let ((buf (get-buffer-create "*Character Description*"))
1162 (the-buf (current-buffer))
1163 (win-conf (current-window-configuration)))
1165 (make-local-variable 'what-character-original-window-configuration)
1166 (setq what-character-original-window-configuration win-conf)
1167 (setq buffer-read-only nil)
1171 (insert-char-data-with-variant char 'printable)
1172 (unless (char-attribute-alist char)
1173 (insert (format ";; = %c\n"
1174 (let* ((rest (split-char char))
1178 (setq code (logior (lsh code 8)
1180 (decode-char ccs code)))))
1181 ;; (char-db-update-comment)
1182 (set-buffer-modified-p nil)
1183 (view-mode the-buf (lambda (buf)
1184 (set-window-configuration
1185 what-character-original-window-configuration)
1187 (goto-char (point-min)))
1189 (set-window-configuration
1190 what-character-original-window-configuration)
1191 (signal (car err) (cdr err)))))))
1193 (provide 'char-db-util)
1195 ;;; char-db-util.el ends here