comparison lisp/mel/mel-u.el @ 70:131b0175ea99 r20-0b30

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