1 ;;; mel-dl.el: Base64 encoder/decoder using DL module
3 ;; Copyright (C) 1998 Free Software Foundation, Inc.
5 ;; Author: MORIOKA Tomohiko <morioka@jaist.ac.jp>
6 ;; Version: $Id: mel-dl.el,v 1.1 1998-01-11 16:21:43 morioka Exp $
7 ;; Keywords: MIME, Base64
9 ;; This file is part of MEL (MIME Encoding Library).
11 ;; This program is free software; you can redistribute it and/or
12 ;; modify it under the terms of the GNU General Public License as
13 ;; published by the Free Software Foundation; either version 2, or (at
14 ;; your option) any later version.
16 ;; This program is distributed in the hope that it will be useful, but
17 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 ;; General Public License for more details.
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs; see the file COPYING. If not, write to the
23 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
24 ;; Boston, MA 02111-1307, USA.
30 (defvar base64-dl-module
31 (expand-file-name "base64.so" exec-directory))
33 (defvar base64-dl-handle
34 (and (file-exists-p base64-dl-module)
35 (dynamic-link base64-dl-module)))
37 (dynamic-call "emacs_base64_init" base64-dl-handle)
39 (defalias 'base64-encode-string 'encode-base64-string)
40 (defalias 'base64-decode-string 'decode-base64-string)
42 (defun base64-encode-region (start end)
43 "Encode current region by base64.
44 START and END are buffer positions."
48 (narrow-to-region start end)
49 (let ((str (buffer-substring start end)))
50 (delete-region start end)
51 (insert (encode-base64-string str))
58 (defun base64-decode-region (start end)
59 "Decode current region by base64.
60 START and END are buffer positions."
64 (narrow-to-region start end)
65 (goto-char (point-min))
66 (while (looking-at ".*\n")
70 (buffer-substring (match-beginning 0) (1- (match-end 0))))
75 (replace-match "")))))
76 (if (looking-at ".*$")
80 (buffer-substring (match-beginning 0) (match-end 0)))
90 ;;; @ base64 encoder/decoder for file
93 (defvar base64-external-encoder '("mmencode")
94 "*list of base64 encoder program name and its arguments.")
96 (defun base64-insert-encoded-file (filename)
97 "Encode contents of file FILENAME to base64, and insert the result.
98 It calls external base64 encoder specified by
99 `base64-external-encoder'. So you must install the program (maybe
100 mmencode included in metamail or XEmacs package)."
101 (interactive (list (read-file-name "Insert encoded file: ")))
102 (apply (function call-process) (car base64-external-encoder)
103 filename t nil (cdr base64-external-encoder))
110 (defun base64-encoded-length (string)
111 (let ((len (length string)))
113 (if (= (mod len 3) 0) 0 1)
123 ;;; mel-dl.el ends here.