* ew-dec.el (ew-decode-field-test): Change column.
[elisp/flim.git] / mel-dl.el
1 ;;; mel-dl.el: Base64 encoder/decoder using DL module
2
3 ;; Copyright (C) 1998 Free Software Foundation, Inc.
4
5 ;; Author: MORIOKA Tomohiko <morioka@jaist.ac.jp>
6 ;; Keywords: MIME, Base64
7
8 ;; This file is part of MEL (MIME Encoding Library).
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 GNU Emacs; see the file COPYING.  If not, write to the
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23 ;; Boston, MA 02111-1307, USA.
24
25 ;;; Code:
26
27 (require 'emu)
28
29 (defvar base64-dl-module
30   (expand-file-name "base64.so" exec-directory))
31
32 (defvar base64-dl-handle
33   (and (file-exists-p base64-dl-module)
34        (dynamic-link base64-dl-module)))
35
36 (dynamic-call "emacs_base64_init" base64-dl-handle)
37
38 (defalias 'base64-dl-encode-string 'encode-base64-string)
39 (defalias 'base64-dl-decode-string 'decode-base64-string)
40
41 (defun base64-dl-encode-region (start end)
42   "Encode current region by base64.
43 START and END are buffer positions."
44   (interactive "r")
45   (save-excursion
46     (save-restriction
47       (narrow-to-region start end)
48       (let ((str (buffer-substring start end)))
49         (delete-region start end)
50         (insert (encode-base64-string str))
51         )
52       (or (bolp)
53           (insert "\n")
54           )
55       )))
56
57 (defun base64-dl-decode-region (start end)
58   "Decode current region by base64.
59 START and END are buffer positions."
60   (interactive "r")
61   (save-excursion
62     (save-restriction
63       (narrow-to-region start end)
64       (goto-char (point-min))
65       (while (looking-at ".*\n")
66         (condition-case err
67             (replace-match
68              (decode-base64-string
69               (buffer-substring (match-beginning 0) (1- (match-end 0))))
70              t t)
71           (error
72            (prog1
73                (message (nth 1 err))
74              (replace-match "")))))
75       (if (looking-at ".*$")
76           (condition-case err
77               (replace-match
78                (decode-base64-string
79                 (buffer-substring (match-beginning 0) (match-end 0)))
80                t t)
81             (error
82              (prog1
83                  (message (nth 1 err))
84                (replace-match "")))
85             ))
86       )))
87
88
89 ;;; @ end
90 ;;;
91
92 (provide 'mel-dl)
93
94 ;;; mel-dl.el ends here.