1 ;;; char-db-util.el --- Character Database utility
3 ;; Copyright (C) 1998,1999,2000,2001,2002 MORIOKA Tomohiko.
5 ;; Author: MORIOKA Tomohiko <tomo@kanji.zinbun.kyoto-u.ac.jp>
6 ;; Keywords: UTF-2000, ISO/IEC 10646, Unicode, UCS-4, MULE.
8 ;; This file is part of XEmacs UTF-2000.
10 ;; XEmacs UTF-2000 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 UTF-2000 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 UTF-2000; 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 (int-char (+ #x2EFF i)))
70 (unless (charset-iso-final-char (car (split-char (aref v 34))))
71 (aset v 34 (make-char 'chinese-gb2312 #x62 #x3A)))
74 (defvar char-db-ignored-attributes nil)
77 (defun char-ref-p (obj)
79 (keywordp (car obj))))
82 (defun char-ref= (cr1 cr2)
83 (cond ((char-ref-p cr1)
85 (char-spec= (plist-get cr1 :char)
86 (plist-get cr2 :char))
87 (char-spec= (plist-get cr1 :char) cr2)))
95 (defun char-spec= (cs1 cs2)
99 (eq cs1 (find-char cs2)))
101 (eq (find-char cs1) cs2)
102 (eq (find-char cs1) (find-char cs2)))))
104 (defun char-attribute-name< (ka kb)
110 ((= (charset-dimension ka)
111 (charset-dimension kb))
112 (cond ((= (charset-chars ka)(charset-chars kb))
113 (if (charset-iso-final-char ka)
115 ((>= (charset-iso-final-char ka) ?@)
116 (if (and (charset-iso-final-char kb)
117 (>= (charset-iso-final-char kb) ?@))
118 (< (charset-iso-final-char ka)
119 (charset-iso-final-char kb))
122 (if (charset-iso-final-char kb)
123 (if (>= (charset-iso-final-char kb) ?@)
125 (< (charset-iso-final-char ka)
126 (charset-iso-final-char kb)))
128 (if (charset-iso-final-char kb)
130 (< (charset-id ka)(charset-id kb)))))
131 ((<= (charset-chars ka)(charset-chars kb)))))
133 (< (charset-dimension ka)
134 (charset-dimension kb))
144 (string< (symbol-name ka)
150 (defvar char-db-coded-charset-priority-list
151 (let ((rest default-coded-charset-priority-list)
154 (when (symbolp (car rest))
155 (cond ((memq (car rest)
164 ((string-match "^mojikyo-" (symbol-name (car rest))))
165 ((string-match "^chinese-big5" (symbol-name (car rest))))
166 ((string-match "^ideograph-gt-pj-" (symbol-name (car rest)))
167 (unless (memq 'ideograph-gt dest)
168 (setq dest (cons 'ideograph-gt dest))))
170 (setq dest (cons (car rest) dest)))))
171 (setq rest (cdr rest)))
172 (append (sort dest #'char-attribute-name<)
173 '(chinese-big5-cdp chinese-big5-eten chinese-big5))))
175 (defun char-db-insert-char-spec (char &optional readable column)
177 (setq column (current-column)))
178 (let (char-spec ret al cal key temp-char)
179 (cond ((characterp char)
180 (cond ((and (setq ret (get-char-attribute char 'ucs))
181 (not (and (<= #xE000 ret)(<= ret #xF8FF))))
182 (setq char-spec (list (cons 'ucs ret)))
183 (if (setq ret (get-char-attribute char 'name))
184 (setq char-spec (cons (cons 'name ret) char-spec)))
187 (let ((default-coded-charset-priority-list
188 char-db-coded-charset-priority-list))
190 (setq char-spec (list ret))
191 (dolist (ccs (delq (car ret) (charset-list)))
192 (if (or (and (charset-iso-final-char ccs)
193 (setq ret (get-char-attribute char ccs)))
194 (eq ccs 'ideograph-daikanwa))
195 (setq char-spec (cons (cons ccs ret) char-spec))))
197 (setq char-spec (split-char char)))
198 (if (setq ret (get-char-attribute char 'name))
199 (setq char-spec (cons (cons 'name ret) char-spec)))
202 (setq char-spec char)
206 (setq char (find-char char-spec))
208 ;; define temporary character
209 ;; Current implementation is dirty.
210 (setq temp-char (define-char (cons '(ideograph-daikanwa . 0)
212 (remove-char-attribute temp-char 'ideograph-daikanwa)
213 (setq char temp-char))
217 (setq key (car (car char-spec)))
218 (unless (memq key char-db-ignored-attributes)
219 (if (find-charset key)
220 (setq cal (cons key cal))
221 (setq al (cons key al))))
222 (setq char-spec (cdr char-spec)))
224 (memq 'ideographic-structure al))
225 (push 'ideographic-structure al))
226 (insert-char-attributes char
230 ;; undefine temporary character
231 ;; Current implementation is dirty.
232 (setq char-spec (char-attribute-alist temp-char))
234 (remove-char-attribute temp-char (car (car char-spec)))
235 (setq char-spec (cdr char-spec))))))
237 (defun char-db-insert-alist (alist &optional readable column)
239 (setq column (current-column)))
241 (concat "\n" (make-string (1+ column) ?\ )))
244 lbs cell rest separator)
247 (setq name (car (car alist))
248 value (cdr (car alist)))
249 (cond ((eq name 'char)
251 (if (setq ret (condition-case nil
258 (setq key (car (car value)))
259 (if (find-charset key)
260 (setq cal (cons key cal))
261 (setq al (cons key al)))
262 (setq value (cdr value)))
263 (insert-char-attributes ret
266 (insert (prin1-to-string value)))
268 (insert line-breaking))
270 (insert (format "(%-18s " name))
271 (setq lbs (concat "\n" (make-string (current-column) ?\ )))
273 (setq cell (car value))
274 (if (and (consp cell)
276 (setq ret (condition-case nil
285 (setq key (car (car rest)))
286 (if (find-charset key)
287 (setq cal (cons key cal))
288 (setq al (cons key al)))
289 (setq rest (cdr rest)))
292 (insert-char-attributes ret
295 (setq separator lbs))
298 (insert (prin1-to-string cell))
299 (setq separator " "))
300 (setq value (cdr value)))
302 (insert line-breaking))
304 (insert (format "(%-18s . %S)%s"
307 (setq alist (cdr alist))))
310 (defun char-db-insert-char-reference (plist &optional readable column)
312 (setq column (current-column)))
314 (concat "\n" (make-string (1+ column) ?\ )))
319 (setq name (pop plist))
320 (setq value (pop plist))
321 (cond ((eq name :char)
324 (cond ((numberp value)
325 (setq value (decode-char 'ucs value)))
327 ;; (setq value (or (find-char value)
330 (char-db-insert-char-spec value readable)
331 (insert line-breaking)
334 (insert (format "%s%s\t%d ; %c%s"
337 (aref ideographic-radicals value)
341 (insert (format "%s%s\t%S" separator name value))
342 (setq separator line-breaking)))
346 (defun char-db-decode-isolated-char (ccs code-point)
349 (cond ((eq ccs 'arabic-iso8859-6)
350 (decode-char ccs code-point))
351 ((and (memq ccs '(ideograph-gt-pj-1
362 (setq ret (decode-char ccs code-point))
363 (setq ret (get-char-attribute ret 'ideograph-gt)))
364 (decode-builtin-char 'ideograph-gt ret))
366 (decode-builtin-char ccs code-point))))
367 (cond ((and (<= 0 (char-int ret))
368 (<= (char-int ret) #x1F))
369 (decode-char 'ucs (+ #x2400 (char-int ret))))
370 ((= (char-int ret) #x7F)
374 (defvar char-db-convert-obsolete-format t)
376 (defun insert-char-attributes (char &optional readable
377 attributes ccs-attributes
382 (if (consp attributes)
384 (dolist (name attributes)
385 (unless (memq name char-db-ignored-attributes)
388 (dolist (name (char-attribute-list))
389 (unless (memq name char-db-ignored-attributes)
390 (if (find-charset name)
394 #'char-attribute-name<))
396 (sort (if ccs-attributes
399 (dolist (name ccs-attributes)
400 (unless (memq name char-db-ignored-attributes)
405 (dolist (name (charset-list))
406 (unless (memq name char-db-ignored-attributes)
409 #'char-attribute-name<)))
411 (setq column (current-column)))
412 (let (name value has-long-ccs-name rest
415 (concat "\n" (make-string (1+ column) ?\ )))
416 lbs cell separator ret
419 (when (and (memq 'name attributes)
420 (setq value (get-char-attribute char 'name)))
422 (if (> (+ (current-column) (length value)) 48)
425 value line-breaking))
426 (setq attributes (delq 'name attributes))
428 (when (and (memq 'script attributes)
429 (setq value (get-char-attribute char 'script)))
430 (insert (format "(script\t\t%s)%s"
431 (mapconcat (function prin1-to-string)
434 (setq attributes (delq 'script attributes))
436 (when (and (memq '=>ucs attributes)
437 (setq value (get-char-attribute char '=>ucs)))
438 (insert (format "(=>ucs\t\t. #x%04X)\t; %c%s"
439 value (decode-char 'ucs value)
441 (setq attributes (delq '=>ucs attributes))
443 (when (and (memq '=>ucs* attributes)
444 (setq value (get-char-attribute char '=>ucs*)))
445 (insert (format "(=>ucs*\t\t. #x%04X)\t; %c%s"
446 value (decode-char 'ucs value)
448 (setq attributes (delq '=>ucs* attributes))
450 (when (and (memq '=>ucs-jis attributes)
451 (setq value (get-char-attribute char '=>ucs-jis)))
452 (insert (format "(=>ucs-jis\t\t. #x%04X)\t; %c%s"
453 value (decode-char 'ucs value)
455 (setq attributes (delq '=>ucs-jis attributes))
457 (when (and (memq '->ucs attributes)
458 (setq value (get-char-attribute char '->ucs)))
459 (insert (format (if char-db-convert-obsolete-format
460 "(=>ucs\t\t. #x%04X)\t; %c%s"
461 "(->ucs\t\t. #x%04X)\t; %c%s")
462 value (decode-char 'ucs value)
464 (setq attributes (delq '->ucs attributes))
466 (when (and (memq 'general-category attributes)
467 (setq value (get-char-attribute char 'general-category)))
469 "(general-category\t%s) ; %s%s"
470 (mapconcat (lambda (cell)
473 (cond ((rassoc value unidata-normative-category-alist)
474 "Normative Category")
475 ((rassoc value unidata-informative-category-alist)
476 "Informative Category")
480 (setq attributes (delq 'general-category attributes))
482 (when (and (memq 'bidi-category attributes)
483 (setq value (get-char-attribute char 'bidi-category)))
484 (insert (format "(bidi-category\t. %S)%s"
487 (setq attributes (delq 'bidi-category attributes))
489 (unless (or (not (memq 'mirrored attributes))
490 (eq (setq value (get-char-attribute char 'mirrored 'empty))
492 (insert (format "(mirrored\t\t. %S)%s"
495 (setq attributes (delq 'mirrored attributes))
498 ((and (memq 'decimal-digit-value attributes)
499 (setq value (get-char-attribute char 'decimal-digit-value)))
500 (insert (format "(decimal-digit-value . %S)%s"
503 (setq attributes (delq 'decimal-digit-value attributes))
504 (when (and (memq 'digit-value attributes)
505 (setq value (get-char-attribute char 'digit-value)))
506 (insert (format "(digit-value\t . %S)%s"
509 (setq attributes (delq 'digit-value attributes))
511 (when (and (memq 'numeric-value attributes)
512 (setq value (get-char-attribute char 'numeric-value)))
513 (insert (format "(numeric-value\t . %S)%s"
516 (setq attributes (delq 'numeric-value attributes))
520 (when (and (memq 'digit-value attributes)
521 (setq value (get-char-attribute char 'digit-value)))
522 (insert (format "(digit-value\t. %S)%s"
525 (setq attributes (delq 'digit-value attributes))
527 (when (and (memq 'numeric-value attributes)
528 (setq value (get-char-attribute char 'numeric-value)))
529 (insert (format "(numeric-value\t. %S)%s"
532 (setq attributes (delq 'numeric-value attributes))
534 (when (and (memq 'iso-10646-comment attributes)
535 (setq value (get-char-attribute char 'iso-10646-comment)))
536 (insert (format "(iso-10646-comment\t. %S)%s"
539 (setq attributes (delq 'iso-10646-comment attributes))
541 (when (and (memq 'morohashi-daikanwa attributes)
542 (setq value (get-char-attribute char 'morohashi-daikanwa)))
543 (insert (format "(morohashi-daikanwa\t%s)%s"
544 (mapconcat (function prin1-to-string) value " ")
546 (setq attributes (delq 'morohashi-daikanwa attributes))
548 ;; (when (and (memq 'hanyu-dazidian attributes)
549 ;; (setq value (get-char-attribute char 'hanyu-dazidian)))
550 ;; (insert (format "(hanyu-dazidian %s)%s"
551 ;; (mapconcat #'number-to-string value " ")
553 ;; (setq attributes (delq 'hanyu-dazidian attributes))
557 (when (and (memq 'ideographic-radical attributes)
558 (setq value (get-char-attribute char 'ideographic-radical)))
560 (insert (format "(ideographic-radical . %S)\t; %c%s"
562 (aref ideographic-radicals radical)
564 (setq attributes (delq 'ideographic-radical attributes))
566 (when (and (memq 'ideographic-strokes attributes)
567 (setq value (get-char-attribute char 'ideographic-strokes)))
569 (insert (format "(ideographic-strokes . %S)%s"
572 (setq attributes (delq 'ideographic-strokes attributes))
574 (when (and (memq 'kangxi-radical attributes)
575 (setq value (get-char-attribute char 'kangxi-radical)))
576 (unless (eq value radical)
577 (insert (format "(kangxi-radical\t . %S)\t; %c%s"
579 (aref ideographic-radicals value)
582 (setq radical value)))
583 (setq attributes (delq 'kangxi-radical attributes))
585 (when (and (memq 'kangxi-strokes attributes)
586 (setq value (get-char-attribute char 'kangxi-strokes)))
587 (unless (eq value strokes)
588 (insert (format "(kangxi-strokes\t . %S)%s"
592 (setq strokes value)))
593 (setq attributes (delq 'kangxi-strokes attributes))
595 (when (and (memq 'japanese-radical attributes)
596 (setq value (get-char-attribute char 'japanese-radical)))
597 (unless (eq value radical)
598 (insert (format "(japanese-radical\t . %S)\t; %c%s"
600 (aref ideographic-radicals value)
603 (setq radical value)))
604 (setq attributes (delq 'japanese-radical attributes))
606 (when (and (memq 'japanese-strokes attributes)
607 (setq value (get-char-attribute char 'japanese-strokes)))
608 (unless (eq value strokes)
609 (insert (format "(japanese-strokes\t . %S)%s"
613 (setq strokes value)))
614 (setq attributes (delq 'japanese-strokes attributes))
616 (when (and (memq 'cns-radical attributes)
617 (setq value (get-char-attribute char 'cns-radical)))
618 (insert (format "(cns-radical\t . %S)\t; %c%s"
620 (aref ideographic-radicals value)
622 (setq attributes (delq 'cns-radical attributes))
624 (when (and (memq 'cns-strokes attributes)
625 (setq value (get-char-attribute char 'cns-strokes)))
626 (unless (eq value strokes)
627 (insert (format "(cns-strokes\t . %S)%s"
631 (setq strokes value)))
632 (setq attributes (delq 'cns-strokes attributes))
634 (when (and (memq 'shinjigen-1-radical attributes)
635 (setq value (get-char-attribute char 'shinjigen-1-radical)))
636 (unless (eq value radical)
637 (insert (format "(shinjigen-1-radical . %S)\t; %c%s"
639 (aref ideographic-radicals value)
642 (setq radical value)))
643 (setq attributes (delq 'shinjigen-1-radical attributes))
645 (when (and (memq 'ideographic- attributes)
646 (setq value (get-char-attribute char 'ideographic-)))
647 (insert "(ideographic- ")
648 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
651 (setq cell (car value))
653 (setq cell (decode-char 'ucs cell)))
654 (cond ((characterp cell)
658 (insert (format "%S" cell))
659 (char-db-insert-char-spec cell readable))
660 (setq separator lbs))
664 (if (consp (car cell))
665 (char-db-insert-char-spec cell readable)
666 (char-db-insert-char-reference cell readable))
667 (setq separator lbs))
671 (insert (prin1-to-string cell))
672 (setq separator " ")))
673 (setq value (cdr value)))
675 (insert line-breaking)
676 (setq attributes (delq 'ideographic- attributes)))
677 (when (and (memq 'total-strokes attributes)
678 (setq value (get-char-attribute char 'total-strokes)))
679 (insert (format "(total-strokes . %S)%s"
682 (setq attributes (delq 'total-strokes attributes))
684 (when (and (memq '->ideograph attributes)
685 (setq value (get-char-attribute char '->ideograph)))
686 (insert (format "(->ideograph\t%s)%s"
687 (mapconcat (lambda (code)
688 (cond ((symbolp code)
691 (format "#x%04X" code))
694 line-breaking code))))
697 (setq attributes (delq '->ideograph attributes))
699 (when (and (memq '->decomposition attributes)
700 (setq value (get-char-attribute char '->decomposition)))
701 (insert (format "(->decomposition\t%s)%s"
702 (mapconcat (lambda (code)
703 (cond ((symbolp code)
712 (format "#x%04X" code))
714 (format "%s%S" line-breaking code))))
717 (setq attributes (delq '->decomposition attributes))
719 (if (equal (get-char-attribute char '->titlecase)
720 (get-char-attribute char '->uppercase))
721 (setq attributes (delq '->titlecase attributes)))
722 (when (and (memq '->mojikyo attributes)
723 (setq value (get-char-attribute char '->mojikyo)))
724 (insert (format "(->mojikyo\t\t. %06d)\t; %c%s"
725 value (decode-char 'mojikyo value)
727 (setq attributes (delq '->mojikyo attributes))
729 (when (and (memq 'hanyu-dazidian-vol attributes)
730 (setq value (get-char-attribute char 'hanyu-dazidian-vol)))
731 (insert (format "(hanyu-dazidian-vol . %d)%s"
732 value line-breaking))
733 (setq attributes (delq 'hanyu-dazidian-vol attributes))
735 (when (and (memq 'hanyu-dazidian-page attributes)
736 (setq value (get-char-attribute char 'hanyu-dazidian-page)))
737 (insert (format "(hanyu-dazidian-page . %d)%s"
738 value line-breaking))
739 (setq attributes (delq 'hanyu-dazidian-page attributes))
741 (when (and (memq 'hanyu-dazidian-char attributes)
742 (setq value (get-char-attribute char 'hanyu-dazidian-char)))
743 (insert (format "(hanyu-dazidian-char . %d)%s"
744 value line-breaking))
745 (setq attributes (delq 'hanyu-dazidian-char attributes))
747 (setq rest ccs-attributes)
750 (setq value (get-char-attribute char (car rest)))
752 (if (>= (length (symbol-name (car rest))) 19)
754 (setq has-long-ccs-name t)
758 (setq rest (cdr rest)))
760 (setq name (car attributes))
761 (if (setq value (get-char-attribute char name))
762 (cond ((eq name 'jisx0208-1978/4X)
763 (insert (format "(%-18s . #x%04X)%s"
766 ((or (eq name 'ideographic-structure)
767 (eq name 'ideographic-)
768 (string-match "^\\(->\\|<-\\)" (symbol-name name)))
769 (insert (format "(%-18s%s " name line-breaking))
770 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
773 (setq cell (car value))
775 (setq cell (decode-char 'ucs cell)))
776 (cond ((characterp cell)
780 (insert (format "%S" cell))
781 (char-db-insert-char-spec cell readable))
782 (setq separator lbs))
786 (if (consp (car cell))
787 (char-db-insert-char-spec cell readable)
788 (char-db-insert-char-reference cell readable))
789 (setq separator lbs))
793 (insert (prin1-to-string cell))
794 (setq separator " ")))
795 (setq value (cdr value)))
797 (insert line-breaking))
798 ((memq name '(ideograph=
799 original-ideograph-of
803 simplified-ideograph-of
805 ideographic-different-form-of))
806 (insert (format "(%-18s%s " name line-breaking))
807 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
810 (setq cell (car value))
811 (if (and (consp cell)
816 (char-db-insert-alist cell readable)
817 (setq separator lbs))
820 (insert (prin1-to-string cell))
821 (setq separator " "))
822 (setq value (cdr value)))
824 (insert line-breaking))
825 ;; ((string-match "^->" (symbol-name name))
827 ;; (format "(%-18s %s)%s"
829 ;; (mapconcat (lambda (code)
830 ;; (cond ((symbolp code)
831 ;; (symbol-name code))
833 ;; (format "#x%04X" code))
836 ;; line-breaking code))))
840 (insert (format "(%-18s " name))
841 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
844 (setq cell (car value))
845 (if (and (consp cell)
847 (setq ret (condition-case nil
855 (setq key (car (car rest)))
856 (if (find-charset key)
857 (setq cal (cons key cal))
858 (setq al (cons key al)))
859 (setq rest (cdr rest)))
862 (insert-char-attributes ret
865 (setq separator lbs))
868 (insert (prin1-to-string cell))
869 (setq separator " "))
870 (setq value (cdr value)))
872 (insert line-breaking))
874 (insert (format "(%-18s . %S)%s"
878 (setq attributes (cdr attributes)))
879 (while ccs-attributes
880 (setq name (car ccs-attributes))
881 (if (and (eq name (charset-name name))
882 (setq value (get-char-attribute char name)))
885 (cond ((memq name '(ideograph-daikanwa-2
889 (if has-long-ccs-name
890 "(%-26s . %05d)\t; %c%s"
891 "(%-18s . %05d)\t; %c%s"))
893 (if has-long-ccs-name
894 "(%-26s . %06d)\t; %c%s"
895 "(%-18s . %06d)\t; %c%s"))
897 (if has-long-ccs-name
898 "(%-26s . #x%04X)\t; %c%s"
899 "(%-18s . #x%04X)\t; %c%s"))
901 (if has-long-ccs-name
902 "(%-26s . #x%02X)\t; %c%s"
903 "(%-18s . #x%02X)\t; %c%s")))
905 (if (= (charset-iso-graphic-plane name) 1)
907 (cond ((= (charset-dimension name) 1)
909 ((= (charset-dimension name) 2)
911 ((= (charset-dimension name) 3)
915 (char-db-decode-isolated-char name value)
917 (setq ccs-attributes (cdr ccs-attributes)))
920 (defun insert-char-data (char &optional readable
921 attributes ccs-attributes)
923 (narrow-to-region (point)(point))
924 (insert "(define-char
926 (insert-char-attributes char readable
927 attributes ccs-attributes)
929 (goto-char (point-min))
930 (while (re-search-forward "[ \t]+$" nil t)
932 (goto-char (point-max))
933 (tabify (point-min)(point-max))
937 (defun char-db-update-comment ()
940 (goto-char (point-min))
941 (let (cdef table char)
942 (while (re-search-forward "^[ \t]*\\(([^.()]+)\\)" nil t)
943 (goto-char (match-beginning 1))
944 (setq cdef (read (current-buffer)))
945 (when (find-charset (car cdef))
946 (goto-char (match-end 0))
949 (not (eq (car cdef) 'ideograph-daikanwa))
950 (or (memq (car cdef) '(ascii latin-viscii-upper
954 japanese-jisx0213-2))
955 (= (char-int (charset-iso-final-char (car cdef)))
957 (apply (function make-char) cdef)
958 (if (setq table (charset-mapping-table (car cdef)))
959 (set-charset-mapping-table (car cdef) nil))
961 (apply (function make-char) cdef)
963 (set-charset-mapping-table (car cdef) table)))))
964 (when (not (or (< (char-int char) 32)
965 (and (<= 128 (char-int char))
966 (< (char-int char) 160))))
967 (delete-region (point) (point-at-eol))
968 (insert (format "\t; %c" char)))
971 (defun insert-char-data-with-variant (char &optional printable
973 script excluded-script)
974 (insert-char-data char printable)
975 (let ((variants (or (char-variants char)
976 (let ((ucs (get-char-attribute char '->ucs)))
978 (delete char (char-variants (int-char ucs)))))))
980 (setq variants (sort variants #'<))
982 (setq variant (car variants))
983 (if (and (or (null script)
984 (null (setq vs (get-char-attribute variant 'script)))
986 (or (null excluded-script)
987 (null (setq vs (get-char-attribute variant 'script)))
988 (not (memq excluded-script vs))))
989 (or (and no-ucs-variant (get-char-attribute variant 'ucs))
990 (insert-char-data variant printable)))
991 (setq variants (cdr variants))
994 (defun insert-char-range-data (min max &optional script excluded-script)
998 (setq char (decode-char 'ucs code))
999 (if (get-char-attribute char 'ucs)
1000 (insert-char-data-with-variant char nil 'no-ucs-variant
1001 script excluded-script))
1002 (setq code (1+ code))
1005 (defun write-char-range-data-to-file (min max file
1006 &optional script excluded-script)
1007 (let ((coding-system-for-write 'utf-8))
1009 (insert-char-range-data min max script excluded-script)
1010 (write-region (point-min)(point-max) file))))
1012 (defvar what-character-original-window-configuration)
1015 (defun what-char-definition (char)
1016 (interactive (list (char-after)))
1017 (let ((buf (get-buffer-create "*Character Description*"))
1018 (the-buf (current-buffer))
1019 (win-conf (current-window-configuration)))
1021 (make-local-variable 'what-character-original-window-configuration)
1022 (setq what-character-original-window-configuration win-conf)
1023 (setq buffer-read-only nil)
1027 (insert-char-data-with-variant char 'printable)
1028 (unless (char-attribute-alist char)
1029 (insert (format ";; = %c\n"
1030 (let* ((rest (split-char char))
1034 (setq code (logior (lsh code 8)
1036 (decode-char ccs code)))))
1037 ;; (char-db-update-comment)
1038 (set-buffer-modified-p nil)
1039 (view-mode the-buf (lambda (buf)
1040 (set-window-configuration
1041 what-character-original-window-configuration)
1043 (goto-char (point-min)))
1045 (set-window-configuration
1046 what-character-original-window-configuration)
1047 (signal (car err) (cdr err)))))))
1049 (provide 'char-db-util)
1051 ;;; char-db-util.el ends here