Use `save-charset-properties' for all coded-charsets when building
[chise/xemacs-chise.git.1] / lisp / utf-2000 / update-cdb.el
1 ;;; update-cdb.el --- Update and/or setup character attribute database
2
3 ;; Copyright (C) 2002,2003,2004 MORIOKA Tomohiko.
4
5 ;; Author: MORIOKA Tomohiko <tomo@kanji.zinbun.kyoto-u.ac.jp>
6 ;; Keywords: Character, Database, CHISE, Unicode, UCS-4, MULE.
7
8 ;; This file is part of XEmacs CHISE.
9
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.
14
15 ;; XEmacs CHISE is distributed in the hope that it will be useful, but
16 ;; 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.
19
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.
24
25 ;;; Code:
26
27 (defun delete-file-with-children (filename)
28   (if (file-directory-p filename)
29       (let ((files
30              (directory-files filename 'full "^[^.]" 'so-sort)))
31         (if files
32             (dolist (file files)
33               (delete-file-with-children file)))
34         (remove-directory filename))
35     (delete-file filename)))
36
37 (cond
38  ((featurep 'chise)
39   (defvar system-char-database-directory
40     (expand-file-name "chise-db"
41                       (or data-directory
42                           "../etc/")))
43
44   (defun file-name-char-attribute-name (filename)
45     (let ((i 0)
46           (base 0)
47           (len (length filename))
48           chr dest)
49       (while (< i len)
50         (if (eq (setq chr (aref filename i)) ?%)
51             (setq dest (concat dest
52                                (substring filename base i)
53                                (char-to-string
54                                 (int-char
55                                  (string-to-int
56                                   (substring filename (1+ i) (+ i 3)) 16))))
57                   i (+ i 3)
58                   base i)
59           (setq i (1+ i))))
60       (concat dest (substring filename base len))))
61
62   (cond
63    ((or load-ignore-elc-files
64         (not (file-exists-p system-char-database-directory)))
65     (if (file-exists-p system-char-database-directory)
66         (delete-file-with-children system-char-database-directory))
67
68     (load "dumped-chars.el")
69     (dolist (file system-char-db-source-file-list)
70       (pureload file))
71
72     (dolist (attribute (char-attribute-list))
73       (save-char-attribute-table attribute))
74
75     (dolist (ccs (charset-list))
76       (save-charset-properties ccs)
77       (save-charset-mapping-table ccs))
78
79     (with-temp-buffer
80       (insert
81        (format
82         "(setq next-defined-char-id #x%X)\n"
83         next-defined-char-id))
84       (write-region (point-min)(point-max)
85                     "../lisp/utf-2000/cid-conf.el"))
86     )
87    (t
88     (if (>= (function-max-args 'char-attribute-list) 1)
89         (char-attribute-list 'rehash)
90       (mapcar (lambda (file)
91                 (mount-char-attribute-table
92                  (intern (file-name-char-attribute-name file))))
93               (directory-files
94                (expand-file-name "system-char-id" ; "character/feature"
95                                  system-char-database-directory)
96                nil nil t t)))
97     (dolist (ccs (charset-list))
98       (reset-charset-mapping-table ccs))
99     (load "../lisp/utf-2000/cid-conf.el")
100     )))
101  (t
102   (load "dumped-chars.el")
103   (dolist (file system-char-db-source-file-list)
104     (pureload file))
105   ))
106
107 (defun char-ref= (cr1 cr2 &optional tester)
108   (cond ((char-ref-p cr1)
109          (if (char-ref-p cr2)
110              (char-spec= (plist-get cr1 :char)
111                          (plist-get cr2 :char) tester)
112            (char-spec= (plist-get cr1 :char) cr2 tester)))
113         (t
114          (char-spec= cr1
115                      (if (char-ref-p cr2)
116                          (plist-get cr2 :char)
117                        cr2)
118                      tester))))
119
120 (defun char-spec= (cs1 cs2 &optional tester)
121   (unless tester
122     (setq tester #'eq))
123   (if (characterp cs1)
124       (if (characterp cs2)
125           (funcall tester cs1 cs2)
126         (funcall tester cs1 (find-char cs2)))
127     (if (characterp cs2)
128         (funcall tester (find-char cs1) cs2)
129       (funcall tester (find-char cs1) (find-char cs2)))))
130
131 (let (ret)
132   (map-char-attribute
133    (lambda (c dc)
134      (if (consp dc)
135          (setq dc (car dc)))
136      (if (listp dc)
137          (if (setq ret (find-char dc))
138              (setq dc ret)))
139      (when (characterp dc)
140        (setq ret (get-char-attribute dc '->uppercase))
141        (if (if (listp ret)
142                (member* c ret :test #'char-ref=)
143              (char-ref= c ret))
144            (put-case-table-pair c dc (standard-case-table))))
145      nil)
146    '->lowercase))
147
148 (garbage-collect)
149
150 ;;; update-cdb.el ends here