de48c6e663f72660fa4c13ad43a6b83f4069b298
[chise/ids.git] / ids-dump.el
1 ;;; ids-dump.el --- Dump utility of IDS-* files
2
3 ;; Copyright (C) 2002 MORIOKA Tomohiko
4
5 ;; Author: MORIOKA Tomohiko <tomo@kanji.zinbun.kyoto-u.ac.jp>
6 ;; Keywords: IDS, IDC, Ideographs, UCS, Unicode
7
8 ;; This file is a part of IDS.
9
10 ;; This program 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 ;; This program 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 this program; 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 (require 'ids)
28
29 (defun ids-dump-insert-line (ccs line-spec code)
30   (let ((chr (decode-char ccs code))
31         id-list)
32     (when chr
33       (setq id-list (get-char-attribute chr 'ideographic-structure))
34       (insert (format line-spec
35                       code (decode-builtin-char ccs code)
36                       (if id-list
37                           (ids-format-list id-list)
38                         (char-to-string chr)))))))
39
40 (defun ids-dump-insert-ccs-ranges (ccs line-spec &rest ranges)
41   (let (range code max-code)
42     (while ranges
43       (setq range (car ranges))
44       (cond ((consp range)
45              (setq code (car range)
46                    max-code (cdr range))
47              (while (<= code max-code)
48                (ids-dump-insert-line ccs line-spec code)
49                (setq code (1+ code))))
50             ((integerp range)
51              (ids-dump-insert-line ccs line-spec range))
52             (t (error 'wrong-type-argument range)))
53       (setq ranges (cdr ranges)))))
54
55 (defun ids-dump-insert-daikanwa (start end)
56   (let ((i start)
57         mdh-alist
58         chr sal)
59     (map-char-attribute
60      (lambda (key val)
61        (when (= (length val) 2)
62          (set-alist 'mdh-alist
63                     (car val)
64                     (put-alist (nth 1 val)
65                                key
66                                (cdr (assq (car val) mdh-alist)))))
67        nil)
68      'morohashi-daikanwa)
69     (while (<= i end)
70       (when (setq chr (decode-char 'ideograph-daikanwa i))
71         (insert
72          (format "M-%05d \t%c\t%s\n"
73                  i (decode-builtin-char 'ideograph-daikanwa i)
74                  (ids-format-list
75                   (get-char-attribute chr 'ideographic-structure)))))
76       (when (setq sal (assq i mdh-alist))
77         (setq sal (cdr sal))
78         (when (setq chr (assq 1 sal))
79           (setq chr (cdr chr))
80           (insert
81            (format "M-%05d'\t%c\t%s\n"
82                    i chr
83                    (ids-format-list
84                     (get-char-attribute chr 'ideographic-structure)))))
85         (when (setq chr (assq 2 sal))
86           (setq chr (cdr chr))
87           (insert
88            (format "M-%05d\"\t%c\t%s\n"
89                    i chr
90                    (ids-format-list
91                     (get-char-attribute chr 'ideographic-structure)))))
92         )
93       (setq i (1+ i)))))
94
95 (defun ids-dump-insert-daikanwa-hokan ()
96   (let (chr sal)
97     (map-char-attribute
98      (lambda (key val)
99        (when (and (eq (car val) 'ho)
100                   (null (nthcdr 2 val)))
101          (setq sal (cons (cons (nth 1 val) key) sal)))
102        nil)
103      'morohashi-daikanwa)
104     (setq sal (sort sal (lambda (a b) (< (car a)(car b)))))
105     (dolist (cell sal)
106       (setq chr (cdr cell))
107       (insert
108        (format "MH-%04d \t%c\t%s\n"
109                (car cell)
110                chr
111                (ids-format-list
112                 (get-char-attribute chr 'ideographic-structure)))))))
113
114 (defun ids-dump-insert-jis-x0208-1990 ()
115   (let ((row 16)
116         cell h l code chr)
117     (while (<= row 83)
118       (setq h (+ row 32))
119       (setq cell 1)
120       (while (<= cell 94)
121         (setq l (+ cell 32))
122         (setq chr (make-char 'japanese-jisx0208-1990 h l))
123         (insert
124          (format "J90-%02X%02X\t%c\t%s\n"
125                  h l
126                  (decode-builtin-char 'japanese-jisx0208-1990
127                                       (logior (lsh h 8) l))
128                  (or (ids-format-list
129                       (get-char-attribute chr 'ideographic-structure))
130                      "")))
131         (setq cell (1+ cell)))
132       (setq row (1+ row)))
133     (setq h (+ row 32))
134     (setq cell 1)
135     (while (<= cell 6)
136       (setq l (+ cell 32))
137       (setq chr (make-char 'japanese-jisx0208-1990 h l))
138       (insert
139        (format "J90-%02X%02X\t%c\t%s\n"
140                h l
141                (decode-builtin-char 'japanese-jisx0208-1990
142                                     (logior (lsh h 8) l))
143                (or (ids-format-list
144                     (get-char-attribute chr 'ideographic-structure))
145                    "")))
146       (setq cell (1+ cell)))))
147
148 (defun ids-dump-range (file path func &rest args)
149   (with-temp-buffer
150     (let* ((coding-system-for-write 'utf-8-mcs-er))
151       (if (file-directory-p path)
152           (setq path (expand-file-name file path)))
153       (insert ";; -*- coding: utf-8-mcs-er -*-\n")
154       (apply func args)
155       (write-region (point-min)(point-max) path))))
156
157 ;;;###autoload
158 (defun ids-dump-ucs-basic (filename)
159   (interactive "Fdump IDS-UCS-Basic : ")
160   (ids-dump-range "IDS-UCS-Basic.txt" filename
161                   #'ids-dump-insert-ccs-ranges 'ucs "U+%04X\t%c\t%s\n"
162                   '(#x4E00 . #x9FA5)))
163
164 ;;;###autoload
165 (defun ids-dump-ucs-ext-a (filename)
166   (interactive "Fdump IDS-UCS-Ext-A : ")
167   (ids-dump-range "IDS-UCS-Ext-A.txt" filename
168                   #'ids-dump-insert-ccs-ranges 'ucs "U+%04X\t%c\t%s\n"
169                   '(#x3400 . #x4DB5) #xFA1F #xFA23))
170
171 ;;;###autoload
172 (defun ids-dump-ucs-compat (filename)
173   (interactive "Fdump IDS-UCS-Compat : ")
174   (ids-dump-range "IDS-UCS-Compat.txt" filename
175                   #'ids-dump-insert-ccs-ranges 'ucs "U+%04X\t%c\t%s\n"
176                   '(#xF900 . #xFA1E) '(#xFA20 . #xFA22) '(#xFA24 . #xFA2D)))
177
178 ;;;###autoload
179 (defun ids-dump-ucs-ext-b-1 (filename)
180   (interactive "Fdump IDS-UCS-Ext-B-1 : ")
181   (ids-dump-range "IDS-UCS-Ext-B-1.txt" filename
182                   #'ids-dump-insert-ccs-ranges 'ucs "U-%08X\t%c\t%s\n"
183                   '(#x20000 . #x21FFF)))
184
185 ;;;###autoload
186 (defun ids-dump-ucs-ext-b-2 (filename)
187   (interactive "Fdump IDS-UCS-Ext-B-2 : ")
188   (ids-dump-range "IDS-UCS-Ext-B-2.txt" filename
189                   #'ids-dump-insert-ccs-ranges 'ucs "U-%08X\t%c\t%s\n"
190                   '(#x22000 . #x23FFF)))
191
192 ;;;###autoload
193 (defun ids-dump-ucs-ext-b-3 (filename)
194   (interactive "Fdump IDS-UCS-Ext-B-3 : ")
195   (ids-dump-range "IDS-UCS-Ext-B-3.txt" filename
196                   #'ids-dump-insert-ccs-ranges 'ucs "U-%08X\t%c\t%s\n"
197                   '(#x24000 . #x25FFF)))
198
199 ;;;###autoload
200 (defun ids-dump-ucs-ext-b-4 (filename)
201   (interactive "Fdump IDS-UCS-Ext-B-4 : ")
202   (ids-dump-range "IDS-UCS-Ext-B-4.txt" filename
203                   #'ids-dump-insert-ccs-ranges 'ucs "U-%08X\t%c\t%s\n"
204                   '(#x26000 . #x27FFF)))
205
206 ;;;###autoload
207 (defun ids-dump-ucs-ext-b-5 (filename)
208   (interactive "Fdump IDS-UCS-Ext-B-5 : ")
209   (ids-dump-range "IDS-UCS-Ext-B-5.txt" filename
210                   #'ids-dump-insert-ccs-ranges 'ucs "U-%08X\t%c\t%s\n"
211                   '(#x28000 . #x29FFF)))
212
213 ;;;###autoload
214 (defun ids-dump-ucs-ext-b-6 (filename)
215   (interactive "Fdump IDS-UCS-Ext-B-6 : ")
216   (ids-dump-range "IDS-UCS-Ext-B-6.txt" filename
217                   #'ids-dump-insert-ccs-ranges 'ucs "U-%08X\t%c\t%s\n"
218                   '(#x2A000 . #x2A6D6)))
219
220 ;;;###autoload
221 (defun ids-dump-ucs-compat-supplement (filename)
222   (interactive "Fdump IDS-UCS-Compat-Supplement : ")
223   (ids-dump-range "IDS-UCS-Compat-Supplement.txt" filename
224                   #'ids-dump-insert-ccs-ranges 'ucs "U-%08X\t%c\t%s\n"
225                   '(#x2F800 . #x2FA1D)))
226
227 ;;;###autoload
228 (defun ids-dump-daikanwa-01 (filename)
229   (interactive "Fdump IDS-Daikanwa-01 : ")
230   (ids-dump-range "IDS-Daikanwa-01.txt" filename
231                   #'ids-dump-insert-daikanwa 00001 01449))
232
233 ;;;###autoload
234 (defun ids-dump-daikanwa-02 (filename)
235   (interactive "Fdump IDS-Daikanwa-02 : ")
236   (ids-dump-range "IDS-Daikanwa-02.txt" filename
237                   #'ids-dump-insert-daikanwa 01450 04674))
238
239 ;;;###autoload
240 (defun ids-dump-daikanwa-03 (filename)
241   (interactive "Fdump IDS-Daikanwa-03 : ")
242   (ids-dump-range "IDS-Daikanwa-03.txt" filename
243                   #'ids-dump-insert-daikanwa 04675 07410))
244
245 ;;;###autoload
246 (defun ids-dump-daikanwa-04 (filename)
247   (interactive "Fdump IDS-Daikanwa-04 : ")
248   (ids-dump-range "IDS-Daikanwa-04.txt" filename
249                   #'ids-dump-insert-daikanwa 07411 11529))
250
251 ;;;###autoload
252 (defun ids-dump-daikanwa-05 (filename)
253   (interactive "Fdump IDS-Daikanwa-05 : ")
254   (ids-dump-range "IDS-Daikanwa-05.txt" filename
255                   #'ids-dump-insert-daikanwa 11530 14414))
256
257 ;;;###autoload
258 (defun ids-dump-daikanwa-06 (filename)
259   (interactive "Fdump IDS-Daikanwa-06 : ")
260   (ids-dump-range "IDS-Daikanwa-06.txt" filename
261                   #'ids-dump-insert-daikanwa 14415 17574))
262
263 ;;;###autoload
264 (defun ids-dump-daikanwa-07 (filename)
265   (interactive "Fdump IDS-Daikanwa-07 : ")
266   (ids-dump-range "IDS-Daikanwa-07.txt" filename
267                   #'ids-dump-insert-daikanwa 17575 22677))
268
269 ;;;###autoload
270 (defun ids-dump-daikanwa-08 (filename)
271   (interactive "Fdump IDS-Daikanwa-08 : ")
272   (ids-dump-range "IDS-Daikanwa-08.txt" filename
273                   #'ids-dump-insert-daikanwa 22678 28107))
274
275 ;;;###autoload
276 (defun ids-dump-daikanwa-09 (filename)
277   (interactive "Fdump IDS-Daikanwa-09 : ")
278   (ids-dump-range "IDS-Daikanwa-09.txt" filename
279                   #'ids-dump-insert-daikanwa 28108 32803))
280
281 ;;;###autoload
282 (defun ids-dump-daikanwa-10 (filename)
283   (interactive "Fdump IDS-Daikanwa-10 : ")
284   (ids-dump-range "IDS-Daikanwa-10.txt" filename
285                   #'ids-dump-insert-daikanwa 32804 38699))
286
287 ;;;###autoload
288 (defun ids-dump-daikanwa-11 (filename)
289   (interactive "Fdump IDS-Daikanwa-11 : ")
290   (ids-dump-range "IDS-Daikanwa-11.txt" filename
291                   #'ids-dump-insert-daikanwa 38700 42209))
292
293 ;;;###autoload
294 (defun ids-dump-daikanwa-12 (filename)
295   (interactive "Fdump IDS-Daikanwa-12 : ")
296   (ids-dump-range "IDS-Daikanwa-12.txt" filename
297                   #'ids-dump-insert-daikanwa 42210 48902))
298
299 ;;;###autoload
300 (defun ids-dump-daikanwa-index (filename)
301   (interactive "Fdump IDS-Daikanwa-dx : ")
302   (ids-dump-range "IDS-Daikanwa-dx.txt" filename
303                   #'ids-dump-insert-daikanwa 48903 49964))
304
305 ;;;###autoload
306 (defun ids-dump-daikanwa-hokan (filename)
307   (interactive "Fdump IDS-Daikanwa-ho : ")
308   (ids-dump-range "IDS-Daikanwa-ho.txt" filename
309                   #'ids-dump-insert-daikanwa-hokan))
310
311 ;;;###autoload
312 (defun ids-dump-cbeta (filename)
313   (interactive "Fdump IDS-CBETA : ")
314   (ids-dump-range "IDS-CBETA.txt" filename
315                   #'ids-dump-insert-ccs-ranges
316                   'ideograph-cbeta "CB%05d\t%c\t%s\n"
317                   '(1 . 13363)))
318
319 ;;;###autoload
320 (defun ids-dump-jis-x0208-1990 (filename)
321   (interactive "Fdump IDS-JIS-X0208-1990 : ")
322   (ids-dump-range "IDS-JIS-X0208-1990.txt" filename
323                   #'ids-dump-insert-jis-x0208-1990))
324
325     
326 ;;; @ End.
327 ;;;
328
329 (provide 'ids-dump)
330
331 ;;; ids-dump.el ends here