(ids-dump-file-specs-alist): Deleted.
[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                  (ids-format-list
129                   (get-char-attribute chr 'ideographic-structure))))
130         (setq cell (1+ cell)))
131       (setq row (1+ row)))
132     (setq h (+ row 32))
133     (setq cell 1)
134     (while (<= cell 6)
135       (setq l (+ cell 32))
136       (setq chr (make-char 'japanese-jisx0208-1990 h l))
137       (insert
138        (format "J90-%02X%02X\t%c\t%s\n"
139                h l
140                (decode-builtin-char 'japanese-jisx0208-1990
141                                     (logior (lsh h 8) l))
142                (ids-format-list
143                 (get-char-attribute chr 'ideographic-structure))))
144       (setq cell (1+ cell)))))
145
146 (defun ids-dump-range (file path func &rest args)
147   (with-temp-buffer
148     (let* ((coding-system-for-write 'utf-8))
149       (if (file-directory-p path)
150           (setq path (expand-file-name file path)))
151       (insert ";; -*- coding: utf-8 -*-\n")
152       (apply func args)
153       (write-region (point-min)(point-max) path))))
154
155 ;;;###autoload
156 (defun ids-dump-ucs-basic (filename)
157   (interactive "Fdump IDS-UCS-Basic : ")
158   (ids-dump-range "IDS-UCS-Basic.txt" filename
159                   #'ids-dump-insert-ccs-ranges 'ucs "U+%04X\t%c\t%s\n"
160                   '(#x4E00 . #x9FA5)))
161
162 ;;;###autoload
163 (defun ids-dump-ucs-ext-a (filename)
164   (interactive "Fdump IDS-UCS-Ext-A : ")
165   (ids-dump-range "IDS-UCS-Ext-A.txt" filename
166                   #'ids-dump-insert-ccs-ranges 'ucs "U+%04X\t%c\t%s\n"
167                   '(#x3400 . #x4DB5) #xFA1F #xFA23))
168
169 ;;;###autoload
170 (defun ids-dump-ucs-compat (filename)
171   (interactive "Fdump IDS-UCS-Compat : ")
172   (ids-dump-range "IDS-UCS-Compat.txt" filename
173                   #'ids-dump-insert-ccs-ranges 'ucs "U+%04X\t%c\t%s\n"
174                   '(#xF900 . #xFA1E) '(#xFA20 . #xFA22) '(#xFA24 . #xFA2D)))
175
176 ;;;###autoload
177 (defun ids-dump-ucs-ext-b-1 (filename)
178   (interactive "Fdump IDS-UCS-Ext-B-1 : ")
179   (ids-dump-range "IDS-UCS-Ext-B-1.txt" filename
180                   #'ids-dump-insert-ccs-ranges 'ucs "U-%08X\t%c\t%s\n"
181                   '(#x20000 . #x21FFF)))
182
183 ;;;###autoload
184 (defun ids-dump-ucs-ext-b-2 (filename)
185   (interactive "Fdump IDS-UCS-Ext-B-2 : ")
186   (ids-dump-range "IDS-UCS-Ext-B-2.txt" filename
187                   #'ids-dump-insert-ccs-ranges 'ucs "U-%08X\t%c\t%s\n"
188                   '(#x22000 . #x23FFF)))
189
190 ;;;###autoload
191 (defun ids-dump-ucs-ext-b-3 (filename)
192   (interactive "Fdump IDS-UCS-Ext-B-3 : ")
193   (ids-dump-range "IDS-UCS-Ext-B-3.txt" filename
194                   #'ids-dump-insert-ccs-ranges 'ucs "U-%08X\t%c\t%s\n"
195                   '(#x24000 . #x25FFF)))
196
197 ;;;###autoload
198 (defun ids-dump-ucs-ext-b-4 (filename)
199   (interactive "Fdump IDS-UCS-Ext-B-4 : ")
200   (ids-dump-range "IDS-UCS-Ext-B-4.txt" filename
201                   #'ids-dump-insert-ccs-ranges 'ucs "U-%08X\t%c\t%s\n"
202                   '(#x26000 . #x27FFF)))
203
204 ;;;###autoload
205 (defun ids-dump-ucs-ext-b-5 (filename)
206   (interactive "Fdump IDS-UCS-Ext-B-5 : ")
207   (ids-dump-range "IDS-UCS-Ext-B-5.txt" filename
208                   #'ids-dump-insert-ccs-ranges 'ucs "U-%08X\t%c\t%s\n"
209                   '(#x28000 . #x29FFF)))
210
211 ;;;###autoload
212 (defun ids-dump-ucs-ext-b-6 (filename)
213   (interactive "Fdump IDS-UCS-Ext-B-6 : ")
214   (ids-dump-range "IDS-UCS-Ext-B-6.txt" filename
215                   #'ids-dump-insert-ccs-ranges 'ucs "U-%08X\t%c\t%s\n"
216                   '(#x2A000 . #x2A6D6)))
217
218 ;;;###autoload
219 (defun ids-dump-ucs-compat-supplement (filename)
220   (interactive "Fdump IDS-UCS-Compat-Supplement : ")
221   (ids-dump-range "IDS-UCS-Compat-Supplement.txt" filename
222                   #'ids-dump-insert-ccs-ranges 'ucs "U-%08X\t%c\t%s\n"
223                   '(#x2F800 . #x2FA1D)))
224
225 ;;;###autoload
226 (defun ids-dump-daikanwa-01 (filename)
227   (interactive "Fdump IDS-Daikanwa-01 : ")
228   (ids-dump-range "IDS-Daikanwa-01.txt" filename
229                   #'ids-dump-insert-daikanwa 00001 01449))
230
231 ;;;###autoload
232 (defun ids-dump-daikanwa-02 (filename)
233   (interactive "Fdump IDS-Daikanwa-02 : ")
234   (ids-dump-range "IDS-Daikanwa-02.txt" filename
235                   #'ids-dump-insert-daikanwa 01450 04674))
236
237 ;;;###autoload
238 (defun ids-dump-daikanwa-03 (filename)
239   (interactive "Fdump IDS-Daikanwa-03 : ")
240   (ids-dump-range "IDS-Daikanwa-03.txt" filename
241                   #'ids-dump-insert-daikanwa 04675 07410))
242
243 ;;;###autoload
244 (defun ids-dump-daikanwa-04 (filename)
245   (interactive "Fdump IDS-Daikanwa-04 : ")
246   (ids-dump-range "IDS-Daikanwa-04.txt" filename
247                   #'ids-dump-insert-daikanwa 07411 11529))
248
249 ;;;###autoload
250 (defun ids-dump-daikanwa-05 (filename)
251   (interactive "Fdump IDS-Daikanwa-05 : ")
252   (ids-dump-range "IDS-Daikanwa-05.txt" filename
253                   #'ids-dump-insert-daikanwa 11530 14414))
254
255 ;;;###autoload
256 (defun ids-dump-daikanwa-06 (filename)
257   (interactive "Fdump IDS-Daikanwa-06 : ")
258   (ids-dump-range "IDS-Daikanwa-06.txt" filename
259                   #'ids-dump-insert-daikanwa 14415 17574))
260
261 ;;;###autoload
262 (defun ids-dump-daikanwa-07 (filename)
263   (interactive "Fdump IDS-Daikanwa-07 : ")
264   (ids-dump-range "IDS-Daikanwa-07.txt" filename
265                   #'ids-dump-insert-daikanwa 17575 22677))
266
267 ;;;###autoload
268 (defun ids-dump-daikanwa-08 (filename)
269   (interactive "Fdump IDS-Daikanwa-08 : ")
270   (ids-dump-range "IDS-Daikanwa-08.txt" filename
271                   #'ids-dump-insert-daikanwa 22678 28107))
272
273 ;;;###autoload
274 (defun ids-dump-daikanwa-09 (filename)
275   (interactive "Fdump IDS-Daikanwa-09 : ")
276   (ids-dump-range "IDS-Daikanwa-09.txt" filename
277                   #'ids-dump-insert-daikanwa 28108 32803))
278
279 ;;;###autoload
280 (defun ids-dump-daikanwa-10 (filename)
281   (interactive "Fdump IDS-Daikanwa-10 : ")
282   (ids-dump-range "IDS-Daikanwa-10.txt" filename
283                   #'ids-dump-insert-daikanwa 32804 38699))
284
285 ;;;###autoload
286 (defun ids-dump-daikanwa-11 (filename)
287   (interactive "Fdump IDS-Daikanwa-11 : ")
288   (ids-dump-range "IDS-Daikanwa-11.txt" filename
289                   #'ids-dump-insert-daikanwa 38700 42209))
290
291 ;;;###autoload
292 (defun ids-dump-daikanwa-12 (filename)
293   (interactive "Fdump IDS-Daikanwa-12 : ")
294   (ids-dump-range "IDS-Daikanwa-12.txt" filename
295                   #'ids-dump-insert-daikanwa 42210 48902))
296
297 ;;;###autoload
298 (defun ids-dump-daikanwa-index (filename)
299   (interactive "Fdump IDS-Daikanwa-dx : ")
300   (ids-dump-range "IDS-Daikanwa-dx.txt" filename
301                   #'ids-dump-insert-daikanwa 48903 49964))
302
303 ;;;###autoload
304 (defun ids-dump-daikanwa-hokan (filename)
305   (interactive "Fdump IDS-Daikanwa-ho : ")
306   (ids-dump-range "IDS-Daikanwa-ho.txt" filename
307                   #'ids-dump-insert-daikanwa-hokan))
308
309 ;;;###autoload
310 (defun ids-dump-cbeta (filename)
311   (interactive "Fdump IDS-CBETA : ")
312   (ids-dump-range "IDS-CBETA.txt" filename
313                   #'ids-dump-insert-ccs-ranges
314                   'ideograph-cbeta "CB%05d\t%c\t%s\n"
315                   '(1 . 13363)))
316
317 ;;;###autoload
318 (defun ids-dump-jis-x0208-1990 (filename)
319   (interactive "Fdump IDS-JIS-X0208-1990 : ")
320   (ids-dump-range "IDS-JIS-X0208-1990.txt" filename
321                   #'ids-dump-insert-jis-x0208-1990))
322
323     
324 ;;; @ End.
325 ;;;
326
327 (provide 'ids-dump)
328
329 ;;; ids-dump.el ends here