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