(M-05280): Modify IDS.
[chise/ids.git] / ids-dump.el
1 ;;; ids-dump.el --- Dump utility of IDS-* files
2
3 ;; Copyright (C) 2002,2003 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                  (or (ids-format-list
75                       (get-char-attribute chr 'ideographic-structure))
76                      ""))))
77       (when (setq sal (assq i mdh-alist))
78         (setq sal (cdr sal))
79         (when (setq chr (assq 1 sal))
80           (setq chr (cdr chr))
81           (insert
82            (format "M-%05d'\t%c\t%s\n"
83                    i chr
84                    (or (ids-format-list
85                         (get-char-attribute chr 'ideographic-structure))
86                        ""))))
87         (when (setq chr (assq 2 sal))
88           (setq chr (cdr chr))
89           (insert
90            (format "M-%05d\"\t%c\t%s\n"
91                    i chr
92                    (ids-format-list
93                     (get-char-attribute chr 'ideographic-structure)))))
94         )
95       (setq i (1+ i)))))
96
97 (defun ids-dump-insert-daikanwa-hokan ()
98   (let (chr sal)
99     (map-char-attribute
100      (lambda (key val)
101        (when (and (eq (car val) 'ho)
102                   (null (nthcdr 2 val)))
103          (setq sal (cons (cons (nth 1 val) key) sal)))
104        nil)
105      'morohashi-daikanwa)
106     (setq sal (sort sal (lambda (a b) (< (car a)(car b)))))
107     (dolist (cell sal)
108       (setq chr (cdr cell))
109       (insert
110        (format "MH-%04d \t%c\t%s\n"
111                (car cell)
112                chr
113                (ids-format-list
114                 (get-char-attribute chr 'ideographic-structure)))))))
115
116 (defun ids-dump-insert-jis-x0208-1990 ()
117   (let ((row 16)
118         cell h l code chr)
119     (while (<= row 83)
120       (setq h (+ row 32))
121       (setq cell 1)
122       (while (<= cell 94)
123         (setq l (+ cell 32))
124         (setq chr (make-char 'japanese-jisx0208-1990 h l))
125         (insert
126          (format "J90-%02X%02X\t%c\t%s\n"
127                  h l
128                  (decode-builtin-char 'japanese-jisx0208-1990
129                                       (logior (lsh h 8) l))
130                  (or (ids-format-list
131                       (get-char-attribute chr 'ideographic-structure))
132                      "")))
133         (setq cell (1+ cell)))
134       (setq row (1+ row)))
135     (setq h (+ row 32))
136     (setq cell 1)
137     (while (<= cell 6)
138       (setq l (+ cell 32))
139       (setq chr (make-char 'japanese-jisx0208-1990 h l))
140       (insert
141        (format "J90-%02X%02X\t%c\t%s\n"
142                h l
143                (decode-builtin-char 'japanese-jisx0208-1990
144                                     (logior (lsh h 8) l))
145                (or (ids-format-list
146                     (get-char-attribute chr 'ideographic-structure))
147                    "")))
148       (setq cell (1+ cell)))))
149
150 (defun ids-dump-insert-big5 (ccs prefix)
151   (let ((h #x81)
152         l code chr structure)
153     (while (<= h #xFE)
154       (setq l #x40)
155       (while (<= l #x7E)
156         (setq chr (make-char ccs h l))
157         (setq structure nil)
158         (when (setq structure
159                     (get-char-attribute chr 'ideographic-structure))
160           (insert
161            (format "%s%02X%02X\t%c\t%s\n"
162                    prefix h l
163                    (decode-builtin-char ccs
164                                         (logior (lsh h 8) l))
165                    (or (ids-format-list
166                         (get-char-attribute chr 'ideographic-structure))
167                        ""))))
168         (setq l (1+ l)))
169       (setq l #xA1)
170       (while (<= l #xFE)
171         (setq chr (make-char ccs h l))
172         (setq structure nil)
173         (when (setq structure
174                     (get-char-attribute chr 'ideographic-structure))
175           (insert
176            (format "%s%02X%02X\t%c\t%s\n"
177                    prefix h l
178                    (decode-builtin-char ccs
179                                         (logior (lsh h 8) l))
180                    (or (ids-format-list
181                         (get-char-attribute chr 'ideographic-structure))
182                        ""))))
183         (setq l (1+ l)))
184       (setq h (1+ h)))))
185
186 (defun ids-dump-range (file path func &rest args)
187   (with-temp-buffer
188     (let* ((coding-system-for-write 'utf-8-mcs-er))
189       (if (file-directory-p path)
190           (setq path (expand-file-name file path)))
191       (insert ";; -*- coding: utf-8-mcs-er -*-\n")
192       (apply func args)
193       (write-region (point-min)(point-max) path))))
194
195 ;;;###autoload
196 (defun ids-dump-ucs-basic (filename)
197   (interactive "Fdump IDS-UCS-Basic : ")
198   (ids-dump-range "IDS-UCS-Basic.txt" filename
199                   #'ids-dump-insert-ccs-ranges 'ucs "U+%04X\t%c\t%s\n"
200                   '(#x4E00 . #x9FA5)))
201
202 ;;;###autoload
203 (defun ids-dump-ucs-ext-a (filename)
204   (interactive "Fdump IDS-UCS-Ext-A : ")
205   (ids-dump-range "IDS-UCS-Ext-A.txt" filename
206                   #'ids-dump-insert-ccs-ranges 'ucs "U+%04X\t%c\t%s\n"
207                   '(#x3400 . #x4DB5) #xFA1F #xFA23))
208
209 ;;;###autoload
210 (defun ids-dump-ucs-compat (filename)
211   (interactive "Fdump IDS-UCS-Compat : ")
212   (ids-dump-range "IDS-UCS-Compat.txt" filename
213                   #'ids-dump-insert-ccs-ranges 'ucs "U+%04X\t%c\t%s\n"
214                   '(#xF900 . #xFA1E) '(#xFA20 . #xFA22) '(#xFA24 . #xFA2D)))
215
216 ;;;###autoload
217 (defun ids-dump-ucs-ext-b-1 (filename)
218   (interactive "Fdump IDS-UCS-Ext-B-1 : ")
219   (ids-dump-range "IDS-UCS-Ext-B-1.txt" filename
220                   #'ids-dump-insert-ccs-ranges 'ucs "U-%08X\t%c\t%s\n"
221                   '(#x20000 . #x21FFF)))
222
223 ;;;###autoload
224 (defun ids-dump-ucs-ext-b-2 (filename)
225   (interactive "Fdump IDS-UCS-Ext-B-2 : ")
226   (ids-dump-range "IDS-UCS-Ext-B-2.txt" filename
227                   #'ids-dump-insert-ccs-ranges 'ucs "U-%08X\t%c\t%s\n"
228                   '(#x22000 . #x23FFF)))
229
230 ;;;###autoload
231 (defun ids-dump-ucs-ext-b-3 (filename)
232   (interactive "Fdump IDS-UCS-Ext-B-3 : ")
233   (ids-dump-range "IDS-UCS-Ext-B-3.txt" filename
234                   #'ids-dump-insert-ccs-ranges 'ucs "U-%08X\t%c\t%s\n"
235                   '(#x24000 . #x25FFF)))
236
237 ;;;###autoload
238 (defun ids-dump-ucs-ext-b-4 (filename)
239   (interactive "Fdump IDS-UCS-Ext-B-4 : ")
240   (ids-dump-range "IDS-UCS-Ext-B-4.txt" filename
241                   #'ids-dump-insert-ccs-ranges 'ucs "U-%08X\t%c\t%s\n"
242                   '(#x26000 . #x27FFF)))
243
244 ;;;###autoload
245 (defun ids-dump-ucs-ext-b-5 (filename)
246   (interactive "Fdump IDS-UCS-Ext-B-5 : ")
247   (ids-dump-range "IDS-UCS-Ext-B-5.txt" filename
248                   #'ids-dump-insert-ccs-ranges 'ucs "U-%08X\t%c\t%s\n"
249                   '(#x28000 . #x29FFF)))
250
251 ;;;###autoload
252 (defun ids-dump-ucs-ext-b-6 (filename)
253   (interactive "Fdump IDS-UCS-Ext-B-6 : ")
254   (ids-dump-range "IDS-UCS-Ext-B-6.txt" filename
255                   #'ids-dump-insert-ccs-ranges 'ucs "U-%08X\t%c\t%s\n"
256                   '(#x2A000 . #x2A6D6)))
257
258 ;;;###autoload
259 (defun ids-dump-ucs-compat-supplement (filename)
260   (interactive "Fdump IDS-UCS-Compat-Supplement : ")
261   (ids-dump-range "IDS-UCS-Compat-Supplement.txt" filename
262                   #'ids-dump-insert-ccs-ranges 'ucs "U-%08X\t%c\t%s\n"
263                   '(#x2F800 . #x2FA1D)))
264
265 ;;;###autoload
266 (defun ids-dump-daikanwa-01 (filename)
267   (interactive "Fdump IDS-Daikanwa-01 : ")
268   (ids-dump-range "IDS-Daikanwa-01.txt" filename
269                   #'ids-dump-insert-daikanwa 00001 01449))
270
271 ;;;###autoload
272 (defun ids-dump-daikanwa-02 (filename)
273   (interactive "Fdump IDS-Daikanwa-02 : ")
274   (ids-dump-range "IDS-Daikanwa-02.txt" filename
275                   #'ids-dump-insert-daikanwa 01450 04674))
276
277 ;;;###autoload
278 (defun ids-dump-daikanwa-03 (filename)
279   (interactive "Fdump IDS-Daikanwa-03 : ")
280   (ids-dump-range "IDS-Daikanwa-03.txt" filename
281                   #'ids-dump-insert-daikanwa 04675 07410))
282
283 ;;;###autoload
284 (defun ids-dump-daikanwa-04 (filename)
285   (interactive "Fdump IDS-Daikanwa-04 : ")
286   (ids-dump-range "IDS-Daikanwa-04.txt" filename
287                   #'ids-dump-insert-daikanwa 07411 11529))
288
289 ;;;###autoload
290 (defun ids-dump-daikanwa-05 (filename)
291   (interactive "Fdump IDS-Daikanwa-05 : ")
292   (ids-dump-range "IDS-Daikanwa-05.txt" filename
293                   #'ids-dump-insert-daikanwa 11530 14414))
294
295 ;;;###autoload
296 (defun ids-dump-daikanwa-06 (filename)
297   (interactive "Fdump IDS-Daikanwa-06 : ")
298   (ids-dump-range "IDS-Daikanwa-06.txt" filename
299                   #'ids-dump-insert-daikanwa 14415 17574))
300
301 ;;;###autoload
302 (defun ids-dump-daikanwa-07 (filename)
303   (interactive "Fdump IDS-Daikanwa-07 : ")
304   (ids-dump-range "IDS-Daikanwa-07.txt" filename
305                   #'ids-dump-insert-daikanwa 17575 22677))
306
307 ;;;###autoload
308 (defun ids-dump-daikanwa-08 (filename)
309   (interactive "Fdump IDS-Daikanwa-08 : ")
310   (ids-dump-range "IDS-Daikanwa-08.txt" filename
311                   #'ids-dump-insert-daikanwa 22678 28107))
312
313 ;;;###autoload
314 (defun ids-dump-daikanwa-09 (filename)
315   (interactive "Fdump IDS-Daikanwa-09 : ")
316   (ids-dump-range "IDS-Daikanwa-09.txt" filename
317                   #'ids-dump-insert-daikanwa 28108 32803))
318
319 ;;;###autoload
320 (defun ids-dump-daikanwa-10 (filename)
321   (interactive "Fdump IDS-Daikanwa-10 : ")
322   (ids-dump-range "IDS-Daikanwa-10.txt" filename
323                   #'ids-dump-insert-daikanwa 32804 38699))
324
325 ;;;###autoload
326 (defun ids-dump-daikanwa-11 (filename)
327   (interactive "Fdump IDS-Daikanwa-11 : ")
328   (ids-dump-range "IDS-Daikanwa-11.txt" filename
329                   #'ids-dump-insert-daikanwa 38700 42209))
330
331 ;;;###autoload
332 (defun ids-dump-daikanwa-12 (filename)
333   (interactive "Fdump IDS-Daikanwa-12 : ")
334   (ids-dump-range "IDS-Daikanwa-12.txt" filename
335                   #'ids-dump-insert-daikanwa 42210 48902))
336
337 ;;;###autoload
338 (defun ids-dump-daikanwa-index (filename)
339   (interactive "Fdump IDS-Daikanwa-dx : ")
340   (ids-dump-range "IDS-Daikanwa-dx.txt" filename
341                   #'ids-dump-insert-daikanwa 48903 49964))
342
343 ;;;###autoload
344 (defun ids-dump-daikanwa-hokan (filename)
345   (interactive "Fdump IDS-Daikanwa-ho : ")
346   (ids-dump-range "IDS-Daikanwa-ho.txt" filename
347                   #'ids-dump-insert-daikanwa-hokan))
348
349 ;;;###autoload
350 (defun ids-dump-cbeta (filename)
351   (interactive "Fdump IDS-CBETA : ")
352   (ids-dump-range "IDS-CBETA.txt" filename
353                   #'ids-dump-insert-ccs-ranges
354                   'ideograph-cbeta "CB%05d\t%c\t%s\n"
355                   '(1 . 13363)))
356
357 ;;;###autoload
358 (defun ids-dump-jis-x0208-1990 (filename)
359   (interactive "Fdump IDS-JIS-X0208-1990 : ")
360   (ids-dump-range "IDS-JIS-X0208-1990.txt" filename
361                   #'ids-dump-insert-jis-x0208-1990))
362
363 ;;;###autoload
364 (defun ids-dump-big5-cdp (filename)
365   (interactive "Fdump IDS-CDP : ")
366   (ids-dump-range "IDS-CDP.txt" filename
367                   #'ids-dump-insert-big5
368                   '=big5-cdp "CDP-"))
369
370     
371 ;;; @ End.
372 ;;;
373
374 (provide 'ids-dump)
375
376 ;;; ids-dump.el ends here