4
|
1 ;;; mel-u.el: uuencode encoder/decoder for GNU Emacs
|
110
|
2
|
|
3 ;; Copyright (C) 1995,1996,1997 Free Software Foundation, Inc.
|
|
4
|
|
5 ;; Author: MORIOKA Tomohiko <morioka@jaist.ac.jp>
|
|
6 ;; Created: 1995/10/25
|
|
7 ;; Version: $Id: mel-u.el,v 1.3 1997/03/16 03:05:15 steve Exp $
|
|
8 ;; Keywords: uuencode
|
|
9
|
|
10 ;; This file is part of MEL (MIME Encoding Library).
|
|
11
|
|
12 ;; This program is free software; you can redistribute it and/or
|
|
13 ;; modify it under the terms of the GNU General Public License as
|
|
14 ;; published by the Free Software Foundation; either version 2, or (at
|
|
15 ;; your option) any later version.
|
|
16
|
|
17 ;; This program is distributed in the hope that it will be useful, but
|
|
18 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
20 ;; General Public License for more details.
|
|
21
|
|
22 ;; You should have received a copy of the GNU General Public License
|
|
23 ;; along with GNU Emacs; see the file COPYING. If not, write to the
|
|
24 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
25 ;; Boston, MA 02111-1307, USA.
|
|
26
|
4
|
27 ;;; Code:
|
|
28
|
|
29 (require 'emu)
|
110
|
30 (require 'mel)
|
4
|
31
|
|
32
|
|
33 ;;; @ variables
|
|
34 ;;;
|
|
35
|
|
36 (defvar uuencode-external-encoder '("uuencode" "-")
|
|
37 "*list of uuencode encoder program name and its arguments.")
|
|
38
|
|
39 (defvar uuencode-external-decoder
|
110
|
40 (list "sh" "-c" (format "(cd %s; uudecode)" mime-temp-directory))
|
4
|
41 "*list of uuencode decoder program name and its arguments.")
|
|
42
|
|
43
|
|
44 ;;; @ uuencode encoder/decoder for region
|
|
45 ;;;
|
|
46
|
110
|
47 (defun uuencode-external-encode-region (start end)
|
|
48 "Encode current region by unofficial uuencode format.
|
|
49 This function uses external uuencode encoder which is specified by
|
|
50 variable `uuencode-external-encoder'."
|
4
|
51 (interactive "*r")
|
|
52 (save-excursion
|
|
53 (as-binary-process (apply (function call-process-region)
|
110
|
54 start end (car uuencode-external-encoder)
|
4
|
55 t t nil (cdr uuencode-external-encoder))
|
|
56 )
|
|
57 ;; for OS/2
|
|
58 ;; regularize line break code
|
|
59 (goto-char (point-min))
|
|
60 (while (re-search-forward "\r$" nil t)
|
|
61 (replace-match "")
|
|
62 )
|
|
63 ))
|
|
64
|
110
|
65 (defun uuencode-external-decode-region (start end)
|
|
66 "Decode current region by unofficial uuencode format.
|
|
67 This function uses external uuencode decoder which is specified by
|
|
68 variable `uuencode-external-decoder'."
|
4
|
69 (interactive "*r")
|
|
70 (save-excursion
|
|
71 (let ((filename (save-excursion
|
|
72 (save-restriction
|
110
|
73 (narrow-to-region start end)
|
|
74 (goto-char start)
|
4
|
75 (if (re-search-forward "^begin [0-9]+ " nil t)
|
|
76 (if (looking-at ".+$")
|
|
77 (buffer-substring (match-beginning 0)
|
|
78 (match-end 0))
|
|
79 ))))))
|
|
80 (if filename
|
|
81 (as-binary-process
|
|
82 (apply (function call-process-region)
|
110
|
83 start end (car uuencode-external-decoder)
|
4
|
84 t nil nil (cdr uuencode-external-decoder))
|
110
|
85 (setq filename (expand-file-name filename mime-temp-directory))
|
|
86 (as-binary-input-file (insert-file-contents filename))
|
4
|
87 (delete-file filename)
|
|
88 ))
|
|
89 )))
|
|
90
|
|
91 (defalias 'uuencode-encode-region 'uuencode-external-encode-region)
|
|
92 (defalias 'uuencode-decode-region 'uuencode-external-decode-region)
|
|
93
|
|
94
|
|
95 ;;; @ uuencode encoder/decoder for file
|
|
96 ;;;
|
|
97
|
|
98 (defun uuencode-insert-encoded-file (filename)
|
110
|
99 "Insert file encoded by unofficial uuencode format.
|
|
100 This function uses external uuencode encoder which is specified by
|
|
101 variable `uuencode-external-encoder'."
|
4
|
102 (interactive (list (read-file-name "Insert encoded file: ")))
|
|
103 (call-process (car uuencode-external-encoder) filename t nil
|
|
104 (file-name-nondirectory filename))
|
|
105 )
|
|
106
|
|
107
|
|
108 ;;; @ end
|
|
109 ;;;
|
|
110
|
|
111 (provide 'mel-u)
|
|
112
|
|
113 ;;; mel-u.el ends here
|