comparison lisp/mel/mel-b.el @ 155:43dd3413c7c7 r20-3b4

Import from CVS: tag r20-3b4
author cvs
date Mon, 13 Aug 2007 09:39:39 +0200
parents c0c698873ce1
children
comparison
equal deleted inserted replaced
154:94141801dd7e 155:43dd3413c7c7
1 ;;;
2 ;;; mel-b.el: Base64 encoder/decoder for GNU Emacs 1 ;;; mel-b.el: Base64 encoder/decoder for GNU Emacs
3 ;;; 2
4 ;;; Copyright (C) 1995 Free Software Foundation, Inc. 3 ;; Copyright (C) 1992,1995,1996,1997 Free Software Foundation, Inc.
5 ;;; Copyright (C) 1992 ENAMI Tsugutomo 4
6 ;;; Copyright (C) 1995,1996 MORIOKA Tomohiko 5 ;; Author: ENAMI Tsugutomo <enami@sys.ptg.sony.co.jp>
7 ;;; 6 ;; MORIOKA Tomohiko <morioka@jaist.ac.jp>
8 ;;; Author: ENAMI Tsugutomo <enami@sys.ptg.sony.co.jp> 7 ;; Maintainer: MORIOKA Tomohiko <morioka@jaist.ac.jp>
9 ;;; MORIOKA Tomohiko <morioka@jaist.ac.jp> 8 ;; Created: 1995/6/24
10 ;;; Maintainer: MORIOKA Tomohiko <morioka@jaist.ac.jp> 9 ;; Version: $Id: mel-b.el,v 1.3 1997/06/06 00:57:14 steve Exp $
11 ;;; Created: 1995/6/24 10 ;; Keywords: MIME, Base64
12 ;;; Version: 11
13 ;;; $Id: mel-b.el,v 1.2 1996/12/28 21:02:56 steve Exp $ 12 ;; This file is part of MEL (MIME Encoding Library).
14 ;;; Keywords: MIME, Base64 13
15 ;;; 14 ;; This program is free software; you can redistribute it and/or
16 ;;; This file is part of MEL (MIME Encoding Library). 15 ;; modify it under the terms of the GNU General Public License as
17 ;;; 16 ;; published by the Free Software Foundation; either version 2, or (at
18 ;;; This program is free software; you can redistribute it and/or 17 ;; your option) any later version.
19 ;;; modify it under the terms of the GNU General Public License as 18
20 ;;; published by the Free Software Foundation; either version 2, or 19 ;; This program is distributed in the hope that it will be useful, but
21 ;;; (at your option) any later version. 20 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
22 ;;; 21 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
23 ;;; This program is distributed in the hope that it will be useful, 22 ;; General Public License for more details.
24 ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of 23
25 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 24 ;; You should have received a copy of the GNU General Public License
26 ;;; General Public License for more details. 25 ;; along with GNU Emacs; see the file COPYING. If not, write to the
27 ;;; 26 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
28 ;;; You should have received a copy of the GNU General Public License 27 ;; Boston, MA 02111-1307, USA.
29 ;;; along with This program. If not, write to the Free Software 28
30 ;;; Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
31 ;;;
32 ;;; Code: 29 ;;; Code:
33 30
34 (require 'emu) 31 (require 'emu)
35 32
36 33
121 118
122 ;;; @@ base64 encoder/decoder for string 119 ;;; @@ base64 encoder/decoder for string
123 ;;; 120 ;;;
124 121
125 (defun base64-encode-string (string) 122 (defun base64-encode-string (string)
123 "Encode STRING to base64, and return the result."
126 (let ((len (length string)) 124 (let ((len (length string))
127 (b 0)(e 57) 125 (b 0)(e 57)
128 dest) 126 dest)
129 (while (< e len) 127 (while (< e len)
130 (setq dest 128 (setq dest
148 ((= m 2) "==") 146 ((= m 2) "==")
149 )) 147 ))
150 ))) 148 )))
151 149
152 (defun base64-decode-string (string) 150 (defun base64-decode-string (string)
151 "Decode STRING which is encoded in base64, and return the result."
153 (mapconcat (function base64-decode-1) 152 (mapconcat (function base64-decode-1)
154 (pack-sequence string 4) 153 (pack-sequence string 4)
155 "")) 154 ""))
156 155
157 156
220 (as-binary-process (apply (function call-process-region) 219 (as-binary-process (apply (function call-process-region)
221 beg end (car base64-external-decoder) 220 beg end (car base64-external-decoder)
222 t t nil (cdr base64-external-decoder)) 221 t t nil (cdr base64-external-decoder))
223 ))) 222 )))
224 223
225 (defun base64-encode-region (beg end) 224 (defun base64-encode-region (start end)
225 "Encode current region by base64.
226 START and END are buffer positions.
227 This function calls internal base64 encoder if size of region is
228 smaller than `base64-internal-encoding-limit', otherwise it calls
229 external base64 encoder specified by `base64-external-encoder'. In
230 this case, you must install the program (maybe mmencode included in
231 metamail or XEmacs package)."
226 (interactive "r") 232 (interactive "r")
227 (if (and base64-internal-encoding-limit 233 (if (and base64-internal-encoding-limit
228 (> (- end beg) base64-internal-encoding-limit)) 234 (> (- end start) base64-internal-encoding-limit))
229 (base64-external-encode-region beg end) 235 (base64-external-encode-region start end)
230 (base64-internal-encode-region beg end) 236 (base64-internal-encode-region start end)
231 )) 237 ))
232 238
233 (defun base64-decode-region (beg end) 239 (defun base64-decode-region (start end)
240 "Decode current region by base64.
241 START and END are buffer positions.
242 This function calls internal base64 decoder if size of region is
243 smaller than `base64-internal-decoding-limit', otherwise it calls
244 external base64 decoder specified by `base64-external-decoder'. In
245 this case, you must install the program (maybe mmencode included in
246 metamail or XEmacs package)."
234 (interactive "r") 247 (interactive "r")
235 (if (and base64-internal-decoding-limit 248 (if (and base64-internal-decoding-limit
236 (> (- end beg) base64-internal-decoding-limit)) 249 (> (- end start) base64-internal-decoding-limit))
237 (base64-external-decode-region beg end) 250 (base64-external-decode-region start end)
238 (base64-internal-decode-region beg end) 251 (base64-internal-decode-region start end)
239 )) 252 ))
240 253
241 254
242 ;;; @ base64 encoder/decoder for file 255 ;;; @ base64 encoder/decoder for file
243 ;;; 256 ;;;
244 257
245 (defun base64-insert-encoded-file (filename) 258 (defun base64-insert-encoded-file (filename)
259 "Encode contents of file FILENAME to base64, and insert the result.
260 It calls external base64 encoder specified by
261 `base64-external-encoder'. So you must install the program (maybe
262 mmencode included in metamail or XEmacs package)."
246 (interactive (list (read-file-name "Insert encoded file: "))) 263 (interactive (list (read-file-name "Insert encoded file: ")))
247 (apply (function call-process) (car base64-external-encoder) 264 (apply (function call-process) (car base64-external-encoder)
248 filename t nil (cdr base64-external-encoder)) 265 filename t nil (cdr base64-external-encoder))
249 ) 266 )
250 267