MEL 6.11.
[elisp/flim.git] / mel-g.el
1 ;;; mel-g.el: Gzip64 encoder/decoder for GNU Emacs
2
3 ;; Copyright (C) 1995,1996,1997 MORIOKA Tomohiko
4 ;; Copyright (C) 1996,1997 Shuhei KOBAYASHI
5
6 ;; Author: Shuhei KOBAYASHI <shuhei-k@jaist.ac.jp>
7 ;;      modified by MORIOKA Tomohiko <morioka@jaist.ac.jp>
8 ;; Maintainer: Shuhei KOBAYASHI <shuhei-k@jaist.ac.jp>
9 ;; Created: 1995/10/25
10 ;; Version: $Id: mel-g.el,v 6.2 1997/09/20 15:09:36 shuhei-k Exp $
11 ;; Keywords: Gzip64, base64, gzip, MIME
12
13 ;; This file is part of MEL (MIME Encoding Library).
14
15 ;; This program is free software; you can redistribute it and/or
16 ;; modify it under the terms of the GNU General Public License as
17 ;; published by the Free Software Foundation; either version 2, or (at
18 ;; your option) any later version.
19
20 ;; This program is distributed in the hope that it will be useful, but
21 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
22 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
23 ;; General Public License for more details.
24
25 ;; You should have received a copy of the GNU General Public License
26 ;; along with GNU Emacs; see the file COPYING.  If not, write to the
27 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
28 ;; Boston, MA 02111-1307, USA.
29
30 ;;; Commentary:
31
32 ;;; NOTE: Gzip64 is an experimental Content-Transfer-Encoding and its
33 ;;; use is STRONGLY DISCOURAGED except for private communication.
34
35 ;;; Code:
36
37 (require 'emu)
38 (require 'file-detect)
39
40
41 ;;; @ variables
42 ;;;
43
44 (defvar gzip64-external-encoder
45   (let ((file (exec-installed-p "mmencode")))
46     (and file
47          (` ("sh" "-c" (, (concat "gzip -c | " file))))
48          ))
49   "*list of gzip64 encoder program name and its arguments.")
50
51 (defvar gzip64-external-decoder
52   (let ((file (exec-installed-p "mmencode")))
53     (and file
54          (` ("sh" "-c" (, (concat file " -u | gzip -dc"))))
55          ))
56   "*list of gzip64 decoder program name and its arguments.")
57
58
59 ;;; @ encoder/decoder for region
60 ;;;
61
62 (defun gzip64-external-encode-region (beg end)
63   (interactive "*r")
64   (save-excursion
65     (as-binary-process (apply (function call-process-region)
66                               beg end (car gzip64-external-encoder)
67                               t t nil (cdr gzip64-external-encoder))
68                        )
69     ;; for OS/2
70     ;;   regularize line break code
71     (goto-char (point-min))
72     (while (re-search-forward "\r$" nil t)
73       (replace-match "")
74       )
75     ))
76
77 (defun gzip64-external-decode-region (beg end)
78   (interactive "*r")
79   (save-excursion
80     (as-binary-process (apply (function call-process-region)
81                               beg end (car gzip64-external-decoder)
82                               t t nil (cdr gzip64-external-decoder))
83                        )
84     ))
85
86 (defalias 'gzip64-encode-region 'gzip64-external-encode-region)
87 (defalias 'gzip64-decode-region 'gzip64-external-decode-region)
88
89
90 ;;; @ encoder/decoder for file
91 ;;;
92
93 (defun gzip64-insert-encoded-file (filename)
94   (interactive (list (read-file-name "Insert encoded file: ")))
95   (apply (function call-process) (car gzip64-external-encoder)
96          filename t nil
97          (cdr gzip64-external-encoder))
98   )
99
100
101 ;;; @ end
102 ;;;
103
104 (provide 'mel-g)
105
106 ;;; mel-g.el ends here.