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= (cr1 cr2)
78 (cond ((char-ref-p cr1)
80 (char-spec= (plist-get cr1 :char)
81 (plist-get cr2 :char))
82 (char-spec= (plist-get cr1 :char) cr2)))
90 (defun char-spec= (cs1 cs2)
94 (eq cs1 (find-char cs2)))
96 (eq (find-char cs1) cs2)
97 (eq (find-char cs1) (find-char cs2)))))
99 (defun char-attribute-name< (ka kb)
105 ((= (charset-dimension ka)
106 (charset-dimension kb))
107 (cond ((= (charset-chars ka)(charset-chars kb))
108 (if (charset-iso-final-char ka)
110 ((>= (charset-iso-final-char ka) ?@)
111 (if (and (charset-iso-final-char kb)
112 (>= (charset-iso-final-char kb) ?@))
113 (< (charset-iso-final-char ka)
114 (charset-iso-final-char kb))
117 (if (charset-iso-final-char kb)
118 (if (>= (charset-iso-final-char kb) ?@)
120 (< (charset-iso-final-char ka)
121 (charset-iso-final-char kb)))
123 (if (charset-iso-final-char kb)
125 (< (charset-id ka)(charset-id kb)))))
126 ((<= (charset-chars ka)(charset-chars kb)))))
128 (< (charset-dimension ka)
129 (charset-dimension kb))
139 (string< (symbol-name ka)
145 (defvar char-db-coded-charset-priority-list
146 (let ((rest default-coded-charset-priority-list)
149 (when (symbolp (car rest))
150 (cond ((memq (car rest)
159 ((string-match "^mojikyo-" (symbol-name (car rest))))
160 ((string-match "^chinese-big5" (symbol-name (car rest))))
161 ((string-match "^ideograph-gt-pj-" (symbol-name (car rest)))
162 (unless (memq 'ideograph-gt dest)
163 (setq dest (cons 'ideograph-gt dest))))
165 (setq dest (cons (car rest) dest)))))
166 (setq rest (cdr rest)))
167 (append (sort dest #'char-attribute-name<)
168 '(chinese-big5-cdp chinese-big5-eten chinese-big5))))
170 (defun char-db-make-char-spec (char)
172 (cond ((characterp char)
173 (cond ((and (setq ret (get-char-attribute char 'ucs))
174 (not (and (<= #xE000 ret)(<= ret #xF8FF))))
175 (setq char-spec (list (cons 'ucs ret)))
176 (if (setq ret (get-char-attribute char 'name))
177 (setq char-spec (cons (cons 'name ret) char-spec)))
180 (let ((default-coded-charset-priority-list
181 char-db-coded-charset-priority-list))
183 (setq char-spec (list ret))
184 (dolist (ccs (delq (car ret) (charset-list)))
185 (if (or (and (charset-iso-final-char ccs)
186 (setq ret (get-char-attribute char ccs)))
187 (eq ccs 'ideograph-daikanwa))
188 (setq char-spec (cons (cons ccs ret) char-spec))))
190 (setq char-spec (split-char char)))
191 (if (setq ret (get-char-attribute char 'name))
192 (setq char-spec (cons (cons 'name ret) char-spec)))
198 (defun char-db-insert-char-spec (char &optional readable column)
200 (setq column (current-column)))
201 (let (char-spec ret al cal key temp-char)
202 (setq char-spec (char-db-make-char-spec char))
203 ;; (cond ((characterp char)
204 ;; (cond ((and (setq ret (get-char-attribute char 'ucs))
205 ;; (not (and (<= #xE000 ret)(<= ret #xF8FF))))
206 ;; (setq char-spec (list (cons 'ucs ret)))
207 ;; (if (setq ret (get-char-attribute char 'name))
208 ;; (setq char-spec (cons (cons 'name ret) char-spec)))
211 ;; (let ((default-coded-charset-priority-list
212 ;; char-db-coded-charset-priority-list))
213 ;; (split-char char)))
214 ;; (setq char-spec (list ret))
215 ;; (dolist (ccs (delq (car ret) (charset-list)))
216 ;; (if (or (and (charset-iso-final-char ccs)
217 ;; (setq ret (get-char-attribute char ccs)))
218 ;; (eq ccs 'ideograph-daikanwa))
219 ;; (setq char-spec (cons (cons ccs ret) char-spec))))
220 ;; (if (null char-spec)
221 ;; (setq char-spec (split-char char)))
222 ;; (if (setq ret (get-char-attribute char 'name))
223 ;; (setq char-spec (cons (cons 'name ret) char-spec)))
226 ;; (setq char-spec char)
228 (unless (or (characterp char) ; char
230 (setq char (find-char char-spec))
232 ;; define temporary character
233 ;; Current implementation is dirty.
234 (setq temp-char (define-char (cons '(ideograph-daikanwa . 0)
236 (remove-char-attribute temp-char 'ideograph-daikanwa)
237 (setq char temp-char))
241 (setq key (car (car char-spec)))
242 (unless (memq key char-db-ignored-attributes)
243 (if (find-charset key)
244 (if (get-char-attribute char key)
245 (setq cal (cons key cal)))
246 (setq al (cons key al))))
247 (setq char-spec (cdr char-spec)))
249 (setq char-spec (char-db-make-char-spec char))
251 (setq key (car (car char-spec)))
252 (unless (memq key char-db-ignored-attributes)
253 (if (find-charset key)
254 (setq cal (cons key cal))
255 (setq al (cons key al))))
256 (setq char-spec (cdr char-spec)))
259 (memq 'ideographic-structure al))
260 (push 'ideographic-structure al))
261 (insert-char-attributes char
265 ;; undefine temporary character
266 ;; Current implementation is dirty.
267 (setq char-spec (char-attribute-alist temp-char))
269 (remove-char-attribute temp-char (car (car char-spec)))
270 (setq char-spec (cdr char-spec))))))
272 (defun char-db-insert-alist (alist &optional readable column)
274 (setq column (current-column)))
276 (concat "\n" (make-string (1+ column) ?\ )))
279 lbs cell rest separator)
282 (setq name (car (car alist))
283 value (cdr (car alist)))
284 (cond ((eq name 'char)
286 (if (setq ret (condition-case nil
293 (setq key (car (car value)))
294 (if (find-charset key)
295 (setq cal (cons key cal))
296 (setq al (cons key al)))
297 (setq value (cdr value)))
298 (insert-char-attributes ret
301 (insert (prin1-to-string value)))
303 (insert line-breaking))
305 (insert (format "(%-18s " name))
306 (setq lbs (concat "\n" (make-string (current-column) ?\ )))
308 (setq cell (car value))
309 (if (and (consp cell)
311 (setq ret (condition-case nil
320 (setq key (car (car rest)))
321 (if (find-charset key)
322 (setq cal (cons key cal))
323 (setq al (cons key al)))
324 (setq rest (cdr rest)))
327 (insert-char-attributes ret
330 (setq separator lbs))
333 (insert (prin1-to-string cell))
334 (setq separator " "))
335 (setq value (cdr value)))
337 (insert line-breaking))
339 (insert (format "(%-18s . %S)%s"
342 (setq alist (cdr alist))))
345 (defun char-db-insert-char-reference (plist &optional readable column)
347 (setq column (current-column)))
349 (concat "\n" (make-string (1+ column) ?\ )))
354 (setq name (pop plist))
355 (setq value (pop plist))
356 (cond ((eq name :char)
359 (cond ((numberp value)
360 (setq value (decode-char 'ucs value)))
362 ;; (setq value (or (find-char value)
365 (char-db-insert-char-spec value readable)
366 (insert line-breaking)
369 (insert (format "%s%s\t%d ; %c%s"
372 (aref ideographic-radicals value)
376 (insert (format "%s%s\t%S" separator name value))
377 (setq separator line-breaking)))
381 (defun char-db-decode-isolated-char (ccs code-point)
384 (cond ((eq ccs 'arabic-iso8859-6)
385 (decode-char ccs code-point))
386 ((and (memq ccs '(ideograph-gt-pj-1
397 (setq ret (decode-char ccs code-point))
398 (setq ret (get-char-attribute ret 'ideograph-gt)))
399 (decode-builtin-char 'ideograph-gt ret))
401 (decode-builtin-char ccs code-point))))
402 (cond ((and (<= 0 (char-int ret))
403 (<= (char-int ret) #x1F))
404 (decode-char 'ucs (+ #x2400 (char-int ret))))
405 ((= (char-int ret) #x7F)
409 (defvar char-db-convert-obsolete-format t)
411 (defun insert-char-attributes (char &optional readable
412 attributes ccs-attributes
417 (if (consp attributes)
419 (dolist (name attributes)
420 (unless (memq name char-db-ignored-attributes)
423 (dolist (name (char-attribute-list))
424 (unless (memq name char-db-ignored-attributes)
425 (if (find-charset name)
429 #'char-attribute-name<))
431 (sort (if ccs-attributes
434 (dolist (name ccs-attributes)
435 (unless (memq name char-db-ignored-attributes)
440 (dolist (name (charset-list))
441 (unless (memq name char-db-ignored-attributes)
444 #'char-attribute-name<)))
446 (setq column (current-column)))
447 (let (name value has-long-ccs-name rest
450 (concat "\n" (make-string (1+ column) ?\ )))
451 lbs cell separator ret
454 (when (and (memq 'name attributes)
455 (setq value (get-char-attribute char 'name)))
457 (if (> (+ (current-column) (length value)) 48)
460 value line-breaking))
461 (setq attributes (delq 'name attributes))
463 (when (and (memq 'script attributes)
464 (setq value (get-char-attribute char 'script)))
465 (insert (format "(script\t\t%s)%s"
466 (mapconcat (function prin1-to-string)
469 (setq attributes (delq 'script attributes))
471 (when (and (memq '=>ucs attributes)
472 (setq value (get-char-attribute char '=>ucs)))
473 (insert (format "(=>ucs\t\t. #x%04X)\t; %c%s"
474 value (decode-char 'ucs value)
476 (setq attributes (delq '=>ucs attributes))
478 (when (and (memq '=>ucs* attributes)
479 (setq value (get-char-attribute char '=>ucs*)))
480 (insert (format "(=>ucs*\t\t. #x%04X)\t; %c%s"
481 value (decode-char 'ucs value)
483 (setq attributes (delq '=>ucs* attributes))
485 (when (and (memq '=>ucs-jis attributes)
486 (setq value (get-char-attribute char '=>ucs-jis)))
487 (insert (format "(=>ucs-jis\t\t. #x%04X)\t; %c%s"
488 value (decode-char 'ucs value)
490 (setq attributes (delq '=>ucs-jis attributes))
492 (when (and (memq '->ucs attributes)
493 (setq value (get-char-attribute char '->ucs)))
494 (insert (format (if char-db-convert-obsolete-format
495 "(=>ucs\t\t. #x%04X)\t; %c%s"
496 "(->ucs\t\t. #x%04X)\t; %c%s")
497 value (decode-char 'ucs value)
499 (setq attributes (delq '->ucs attributes))
501 (when (and (memq 'general-category attributes)
502 (setq value (get-char-attribute char 'general-category)))
504 "(general-category\t%s) ; %s%s"
505 (mapconcat (lambda (cell)
508 (cond ((rassoc value unidata-normative-category-alist)
509 "Normative Category")
510 ((rassoc value unidata-informative-category-alist)
511 "Informative Category")
515 (setq attributes (delq 'general-category attributes))
517 (when (and (memq 'bidi-category attributes)
518 (setq value (get-char-attribute char 'bidi-category)))
519 (insert (format "(bidi-category\t. %S)%s"
522 (setq attributes (delq 'bidi-category attributes))
524 (unless (or (not (memq 'mirrored attributes))
525 (eq (setq value (get-char-attribute char 'mirrored 'empty))
527 (insert (format "(mirrored\t\t. %S)%s"
530 (setq attributes (delq 'mirrored attributes))
533 ((and (memq 'decimal-digit-value attributes)
534 (setq value (get-char-attribute char 'decimal-digit-value)))
535 (insert (format "(decimal-digit-value . %S)%s"
538 (setq attributes (delq 'decimal-digit-value attributes))
539 (when (and (memq 'digit-value attributes)
540 (setq value (get-char-attribute char 'digit-value)))
541 (insert (format "(digit-value\t . %S)%s"
544 (setq attributes (delq 'digit-value attributes))
546 (when (and (memq 'numeric-value attributes)
547 (setq value (get-char-attribute char 'numeric-value)))
548 (insert (format "(numeric-value\t . %S)%s"
551 (setq attributes (delq 'numeric-value attributes))
555 (when (and (memq 'digit-value attributes)
556 (setq value (get-char-attribute char 'digit-value)))
557 (insert (format "(digit-value\t. %S)%s"
560 (setq attributes (delq 'digit-value attributes))
562 (when (and (memq 'numeric-value attributes)
563 (setq value (get-char-attribute char 'numeric-value)))
564 (insert (format "(numeric-value\t. %S)%s"
567 (setq attributes (delq 'numeric-value attributes))
569 (when (and (memq 'iso-10646-comment attributes)
570 (setq value (get-char-attribute char 'iso-10646-comment)))
571 (insert (format "(iso-10646-comment\t. %S)%s"
574 (setq attributes (delq 'iso-10646-comment attributes))
576 (when (and (memq 'morohashi-daikanwa attributes)
577 (setq value (get-char-attribute char 'morohashi-daikanwa)))
578 (insert (format "(morohashi-daikanwa\t%s)%s"
579 (mapconcat (function prin1-to-string) value " ")
581 (setq attributes (delq 'morohashi-daikanwa attributes))
583 ;; (when (and (memq 'hanyu-dazidian attributes)
584 ;; (setq value (get-char-attribute char 'hanyu-dazidian)))
585 ;; (insert (format "(hanyu-dazidian %s)%s"
586 ;; (mapconcat #'number-to-string value " ")
588 ;; (setq attributes (delq 'hanyu-dazidian attributes))
592 (when (and (memq 'ideographic-radical attributes)
593 (setq value (get-char-attribute char 'ideographic-radical)))
595 (insert (format "(ideographic-radical . %S)\t; %c%s"
597 (aref ideographic-radicals radical)
599 (setq attributes (delq 'ideographic-radical attributes))
601 (when (and (memq 'ideographic-strokes attributes)
602 (setq value (get-char-attribute char 'ideographic-strokes)))
604 (insert (format "(ideographic-strokes . %S)%s"
607 (setq attributes (delq 'ideographic-strokes attributes))
609 (when (and (memq 'kangxi-radical attributes)
610 (setq value (get-char-attribute char 'kangxi-radical)))
611 (unless (eq value radical)
612 (insert (format "(kangxi-radical\t . %S)\t; %c%s"
614 (aref ideographic-radicals value)
617 (setq radical value)))
618 (setq attributes (delq 'kangxi-radical attributes))
620 (when (and (memq 'kangxi-strokes attributes)
621 (setq value (get-char-attribute char 'kangxi-strokes)))
622 (unless (eq value strokes)
623 (insert (format "(kangxi-strokes\t . %S)%s"
627 (setq strokes value)))
628 (setq attributes (delq 'kangxi-strokes attributes))
630 (when (and (memq 'japanese-radical attributes)
631 (setq value (get-char-attribute char 'japanese-radical)))
632 (unless (eq value radical)
633 (insert (format "(japanese-radical\t . %S)\t; %c%s"
635 (aref ideographic-radicals value)
638 (setq radical value)))
639 (setq attributes (delq 'japanese-radical attributes))
641 (when (and (memq 'japanese-strokes attributes)
642 (setq value (get-char-attribute char 'japanese-strokes)))
643 (unless (eq value strokes)
644 (insert (format "(japanese-strokes\t . %S)%s"
648 (setq strokes value)))
649 (setq attributes (delq 'japanese-strokes attributes))
651 (when (and (memq 'cns-radical attributes)
652 (setq value (get-char-attribute char 'cns-radical)))
653 (insert (format "(cns-radical\t . %S)\t; %c%s"
655 (aref ideographic-radicals value)
657 (setq attributes (delq 'cns-radical attributes))
659 (when (and (memq 'cns-strokes attributes)
660 (setq value (get-char-attribute char 'cns-strokes)))
661 (unless (eq value strokes)
662 (insert (format "(cns-strokes\t . %S)%s"
666 (setq strokes value)))
667 (setq attributes (delq 'cns-strokes attributes))
669 (when (and (memq 'shinjigen-1-radical attributes)
670 (setq value (get-char-attribute char 'shinjigen-1-radical)))
671 (unless (eq value radical)
672 (insert (format "(shinjigen-1-radical . %S)\t; %c%s"
674 (aref ideographic-radicals value)
677 (setq radical value)))
678 (setq attributes (delq 'shinjigen-1-radical attributes))
680 (when (and (memq 'ideographic- attributes)
681 (setq value (get-char-attribute char 'ideographic-)))
682 (insert "(ideographic- ")
683 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
686 (setq cell (car value))
688 (setq cell (decode-char 'ucs cell)))
689 (cond ((characterp cell)
693 (insert (format "%S" cell))
694 (char-db-insert-char-spec cell readable))
695 (setq separator lbs))
699 (if (consp (car cell))
700 (char-db-insert-char-spec cell readable)
701 (char-db-insert-char-reference cell readable))
702 (setq separator lbs))
706 (insert (prin1-to-string cell))
707 (setq separator " ")))
708 (setq value (cdr value)))
710 (insert line-breaking)
711 (setq attributes (delq 'ideographic- attributes)))
712 (when (and (memq 'total-strokes attributes)
713 (setq value (get-char-attribute char 'total-strokes)))
714 (insert (format "(total-strokes . %S)%s"
717 (setq attributes (delq 'total-strokes attributes))
719 (when (and (memq '->ideograph attributes)
720 (setq value (get-char-attribute char '->ideograph)))
721 (insert (format "(->ideograph\t%s)%s"
722 (mapconcat (lambda (code)
723 (cond ((symbolp code)
726 (format "#x%04X" code))
729 line-breaking code))))
732 (setq attributes (delq '->ideograph attributes))
734 (when (and (memq '->decomposition attributes)
735 (setq value (get-char-attribute char '->decomposition)))
736 (insert (format "(->decomposition\t%s)%s"
737 (mapconcat (lambda (code)
738 (cond ((symbolp code)
747 (format "#x%04X" code))
749 (format "%s%S" line-breaking code))))
752 (setq attributes (delq '->decomposition attributes))
754 (if (equal (get-char-attribute char '->titlecase)
755 (get-char-attribute char '->uppercase))
756 (setq attributes (delq '->titlecase attributes)))
757 (when (and (memq '->mojikyo attributes)
758 (setq value (get-char-attribute char '->mojikyo)))
759 (insert (format "(->mojikyo\t\t. %06d)\t; %c%s"
760 value (decode-char 'mojikyo value)
762 (setq attributes (delq '->mojikyo attributes))
764 (when (and (memq 'hanyu-dazidian-vol attributes)
765 (setq value (get-char-attribute char 'hanyu-dazidian-vol)))
766 (insert (format "(hanyu-dazidian-vol . %d)%s"
767 value line-breaking))
768 (setq attributes (delq 'hanyu-dazidian-vol attributes))
770 (when (and (memq 'hanyu-dazidian-page attributes)
771 (setq value (get-char-attribute char 'hanyu-dazidian-page)))
772 (insert (format "(hanyu-dazidian-page . %d)%s"
773 value line-breaking))
774 (setq attributes (delq 'hanyu-dazidian-page attributes))
776 (when (and (memq 'hanyu-dazidian-char attributes)
777 (setq value (get-char-attribute char 'hanyu-dazidian-char)))
778 (insert (format "(hanyu-dazidian-char . %d)%s"
779 value line-breaking))
780 (setq attributes (delq 'hanyu-dazidian-char attributes))
782 (setq rest ccs-attributes)
785 (setq value (get-char-attribute char (car rest)))
787 (if (>= (length (symbol-name (car rest))) 19)
789 (setq has-long-ccs-name t)
793 (setq rest (cdr rest)))
795 (setq name (car attributes))
796 (if (setq value (get-char-attribute char name))
797 (cond ((eq name 'jisx0208-1978/4X)
798 (insert (format "(%-18s . #x%04X)%s"
801 ((or (eq name 'ideographic-structure)
802 (eq name 'ideographic-)
803 (string-match "^\\(->\\|<-\\)" (symbol-name name)))
804 (insert (format "(%-18s%s " name line-breaking))
805 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
808 (setq cell (car value))
810 (setq cell (decode-char 'ucs cell)))
811 (cond ((characterp cell)
815 (insert (format "%S" cell))
816 (char-db-insert-char-spec cell readable))
817 (setq separator lbs))
821 (if (consp (car cell))
822 (char-db-insert-char-spec cell readable)
823 (char-db-insert-char-reference cell readable))
824 (setq separator lbs))
828 (insert (prin1-to-string cell))
829 (setq separator " ")))
830 (setq value (cdr value)))
832 (insert line-breaking))
833 ((memq name '(ideograph=
834 original-ideograph-of
838 simplified-ideograph-of
840 ideographic-different-form-of))
841 (insert (format "(%-18s%s " name line-breaking))
842 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
845 (setq cell (car value))
846 (if (and (consp cell)
851 (char-db-insert-alist cell readable)
852 (setq separator lbs))
855 (insert (prin1-to-string cell))
856 (setq separator " "))
857 (setq value (cdr value)))
859 (insert line-breaking))
860 ;; ((string-match "^->" (symbol-name name))
862 ;; (format "(%-18s %s)%s"
864 ;; (mapconcat (lambda (code)
865 ;; (cond ((symbolp code)
866 ;; (symbol-name code))
868 ;; (format "#x%04X" code))
871 ;; line-breaking code))))
875 (insert (format "(%-18s " name))
876 (setq lbs (concat "\n" (make-string (current-column) ?\ ))
879 (setq cell (car value))
880 (if (and (consp cell)
882 (setq ret (condition-case nil
890 (setq key (car (car rest)))
891 (if (find-charset key)
892 (setq cal (cons key cal))
893 (setq al (cons key al)))
894 (setq rest (cdr rest)))
897 (insert-char-attributes ret
900 (setq separator lbs))
903 (insert (prin1-to-string cell))
904 (setq separator " "))
905 (setq value (cdr value)))
907 (insert line-breaking))
909 (insert (format "(%-18s . %S)%s"
913 (setq attributes (cdr attributes)))
914 (while ccs-attributes
915 (setq name (car ccs-attributes))
916 (if (and (eq name (charset-name name))
917 (setq value (get-char-attribute char name)))
920 (cond ((memq name '(ideograph-daikanwa-2
924 (if has-long-ccs-name
925 "(%-26s . %05d)\t; %c%s"
926 "(%-18s . %05d)\t; %c%s"))
928 (if has-long-ccs-name
929 "(%-26s . %06d)\t; %c%s"
930 "(%-18s . %06d)\t; %c%s"))
932 (if has-long-ccs-name
933 "(%-26s . #x%04X)\t; %c%s"
934 "(%-18s . #x%04X)\t; %c%s"))
936 (if has-long-ccs-name
937 "(%-26s . #x%02X)\t; %c%s"
938 "(%-18s . #x%02X)\t; %c%s")))
940 (if (= (charset-iso-graphic-plane name) 1)
942 (cond ((= (charset-dimension name) 1)
944 ((= (charset-dimension name) 2)
946 ((= (charset-dimension name) 3)
950 (char-db-decode-isolated-char name value)
952 (setq ccs-attributes (cdr ccs-attributes)))
955 (defun insert-char-data (char &optional readable
956 attributes ccs-attributes)
958 (narrow-to-region (point)(point))
959 (insert "(define-char
961 (insert-char-attributes char readable
962 attributes ccs-attributes)
964 (goto-char (point-min))
965 (while (re-search-forward "[ \t]+$" nil t)
967 (goto-char (point-max))
968 (tabify (point-min)(point-max))
972 (defun char-db-update-comment ()
975 (goto-char (point-min))
976 (let (cdef table char)
977 (while (re-search-forward "^[ \t]*\\(([^.()]+)\\)" nil t)
978 (goto-char (match-beginning 1))
979 (setq cdef (read (current-buffer)))
980 (when (find-charset (car cdef))
981 (goto-char (match-end 0))
984 (not (eq (car cdef) 'ideograph-daikanwa))
985 (or (memq (car cdef) '(ascii latin-viscii-upper
989 japanese-jisx0213-2))
990 (= (char-int (charset-iso-final-char (car cdef)))
992 (apply (function make-char) cdef)
993 (if (setq table (charset-mapping-table (car cdef)))
994 (set-charset-mapping-table (car cdef) nil))
996 (apply (function make-char) cdef)
998 (set-charset-mapping-table (car cdef) table)))))
999 (when (not (or (< (char-int char) 32)
1000 (and (<= 128 (char-int char))
1001 (< (char-int char) 160))))
1002 (delete-region (point) (point-at-eol))
1003 (insert (format "\t; %c" char)))
1006 (defun insert-char-data-with-variant (char &optional printable
1008 script excluded-script)
1009 (insert-char-data char printable)
1010 (let ((variants (or (char-variants char)
1011 (let ((ucs (get-char-attribute char '->ucs)))
1013 (delete char (char-variants (int-char ucs)))))))
1015 (setq variants (sort variants #'<))
1017 (setq variant (car variants))
1018 (if (and (or (null script)
1019 (null (setq vs (get-char-attribute variant 'script)))
1021 (or (null excluded-script)
1022 (null (setq vs (get-char-attribute variant 'script)))
1023 (not (memq excluded-script vs))))
1024 (or (and no-ucs-variant (get-char-attribute variant 'ucs))
1025 (insert-char-data variant printable)))
1026 (setq variants (cdr variants))
1029 (defun insert-char-range-data (min max &optional script excluded-script)
1032 (while (<= code max)
1033 (setq char (decode-char 'ucs code))
1034 (if (get-char-attribute char 'ucs)
1035 (insert-char-data-with-variant char nil 'no-ucs-variant
1036 script excluded-script))
1037 (setq code (1+ code))
1040 (defun write-char-range-data-to-file (min max file
1041 &optional script excluded-script)
1042 (let ((coding-system-for-write 'utf-8))
1044 (insert-char-range-data min max script excluded-script)
1045 (write-region (point-min)(point-max) file))))
1047 (defvar what-character-original-window-configuration)
1050 (defun what-char-definition (char)
1051 (interactive (list (char-after)))
1052 (let ((buf (get-buffer-create "*Character Description*"))
1053 (the-buf (current-buffer))
1054 (win-conf (current-window-configuration)))
1056 (make-local-variable 'what-character-original-window-configuration)
1057 (setq what-character-original-window-configuration win-conf)
1058 (setq buffer-read-only nil)
1062 (insert-char-data-with-variant char 'printable)
1063 (unless (char-attribute-alist char)
1064 (insert (format ";; = %c\n"
1065 (let* ((rest (split-char char))
1069 (setq code (logior (lsh code 8)
1071 (decode-char ccs code)))))
1072 ;; (char-db-update-comment)
1073 (set-buffer-modified-p nil)
1074 (view-mode the-buf (lambda (buf)
1075 (set-window-configuration
1076 what-character-original-window-configuration)
1078 (goto-char (point-min)))
1080 (set-window-configuration
1081 what-character-original-window-configuration)
1082 (signal (car err) (cdr err)))))))
1084 (provide 'char-db-util)
1086 ;;; char-db-util.el ends here