From fd2323ddc3635fd4295501e0ab676424444f03d8 Mon Sep 17 00:00:00 2001 From: morioka Date: Sun, 11 Jan 1998 16:21:43 +0000 Subject: [PATCH] *** empty log message *** --- mel-dl.el | 123 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 123 insertions(+) create mode 100644 mel-dl.el diff --git a/mel-dl.el b/mel-dl.el new file mode 100644 index 0000000..e42635b --- /dev/null +++ b/mel-dl.el @@ -0,0 +1,123 @@ +;;; mel-dl.el: Base64 encoder/decoder using DL module + +;; Copyright (C) 1998 Free Software Foundation, Inc. + +;; Author: MORIOKA Tomohiko +;; Version: $Id: mel-dl.el,v 1.1 1998-01-11 16:21:43 morioka Exp $ +;; Keywords: MIME, Base64 + +;; This file is part of MEL (MIME Encoding Library). + +;; This program is free software; you can redistribute it and/or +;; modify it under the terms of the GNU General Public License as +;; published by the Free Software Foundation; either version 2, or (at +;; your option) any later version. + +;; This program is distributed in the hope that it will be useful, but +;; WITHOUT ANY WARRANTY; without even the implied warranty of +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +;; General Public License for more details. + +;; You should have received a copy of the GNU General Public License +;; along with GNU Emacs; see the file COPYING. If not, write to the +;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, +;; Boston, MA 02111-1307, USA. + +;;; Code: + +(require 'emu) + +(defvar base64-dl-module + (expand-file-name "base64.so" exec-directory)) + +(defvar base64-dl-handle + (and (file-exists-p base64-dl-module) + (dynamic-link base64-dl-module))) + +(dynamic-call "emacs_base64_init" base64-dl-handle) + +(defalias 'base64-encode-string 'encode-base64-string) +(defalias 'base64-decode-string 'decode-base64-string) + +(defun base64-encode-region (start end) + "Encode current region by base64. +START and END are buffer positions." + (interactive "r") + (save-excursion + (save-restriction + (narrow-to-region start end) + (let ((str (buffer-substring start end))) + (delete-region start end) + (insert (encode-base64-string str)) + ) + (or (bolp) + (insert "\n") + ) + ))) + +(defun base64-decode-region (start end) + "Decode current region by base64. +START and END are buffer positions." + (interactive "r") + (save-excursion + (save-restriction + (narrow-to-region start end) + (goto-char (point-min)) + (while (looking-at ".*\n") + (condition-case err + (replace-match + (decode-base64-string + (buffer-substring (match-beginning 0) (1- (match-end 0)))) + t t) + (error + (prog1 + (message (nth 1 err)) + (replace-match ""))))) + (if (looking-at ".*$") + (condition-case err + (replace-match + (decode-base64-string + (buffer-substring (match-beginning 0) (match-end 0))) + t t) + (error + (prog1 + (message (nth 1 err)) + (replace-match ""))) + )) + ))) + + +;;; @ base64 encoder/decoder for file +;;; + +(defvar base64-external-encoder '("mmencode") + "*list of base64 encoder program name and its arguments.") + +(defun base64-insert-encoded-file (filename) + "Encode contents of file FILENAME to base64, and insert the result. +It calls external base64 encoder specified by +`base64-external-encoder'. So you must install the program (maybe +mmencode included in metamail or XEmacs package)." + (interactive (list (read-file-name "Insert encoded file: "))) + (apply (function call-process) (car base64-external-encoder) + filename t nil (cdr base64-external-encoder)) + ) + + +;;; @ etc +;;; + +(defun base64-encoded-length (string) + (let ((len (length string))) + (* (+ (/ len 3) + (if (= (mod len 3) 0) 0 1) + ) 4) + )) + + +;;; @ end +;;; + +(provide 'mel-dl) + +;;; mel-dl.el ends here. -- 1.7.10.4