comparison lisp/mel/mel-u.el @ 110:fe104dbd9147 r20-1b7

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