Mercurial > emacs
comparison lisp/gnus/uudecode.el @ 33566:cef397782e2e
(uudecode-insert-char): Fix bogus feature test.
(uudecode-decode-region-external): Doc fix. Use with-temp-buffer
and make-temp-file.
(uudecode-decode-region): Doc fix.
author | Dave Love <fx@gnu.org> |
---|---|
date | Fri, 17 Nov 2000 12:59:12 +0000 |
parents | 8a75bc99cf0b |
children | 03ae5e62feb4 |
comparison
equal
deleted
inserted
replaced
33565:9c20cc234d0d | 33566:cef397782e2e |
---|---|
25 ;;; Commentary: | 25 ;;; Commentary: |
26 | 26 |
27 ;; Lots of codes are stolen from mm-decode.el, gnus-uu.el and | 27 ;; Lots of codes are stolen from mm-decode.el, gnus-uu.el and |
28 ;; base64.el | 28 ;; base64.el |
29 | 29 |
30 ;; This looks as though it could be made rather more efficient. | 30 ;; This looks as though it could be made rather more efficient for |
31 ;; Encoding could use a lookup table and decoding should presumably | 31 ;; internal working. Encoding could use a lookup table and decoding |
32 ;; use a vector or list buffer for partial results rather than | 32 ;; should presumably use a vector or list buffer for partial results |
33 ;; with-current-buffer. -- fx | 33 ;; rather than with-current-buffer. -- fx |
34 | 34 |
35 ;;; Code: | 35 ;;; Code: |
36 | 36 |
37 (eval-when-compile (require 'cl)) | 37 (eval-when-compile (require 'cl)) |
38 | 38 |
40 (defalias 'uudecode-char-int | 40 (defalias 'uudecode-char-int |
41 (if (fboundp 'char-int) | 41 (if (fboundp 'char-int) |
42 'char-int | 42 'char-int |
43 'identity)) | 43 'identity)) |
44 | 44 |
45 (if (fboundp 'insert-char) | 45 (if (featurep 'xemacs) |
46 (defalias 'uudecode-insert-char 'insert-char) | 46 (defalias 'uudecode-insert-char 'insert-char) |
47 (defun uudecode-insert-char (char &optional count ignored buffer) | 47 (defun uudecode-insert-char (char &optional count ignored buffer) |
48 (if (or (null buffer) (eq buffer (current-buffer))) | 48 (if (or (null buffer) (eq buffer (current-buffer))) |
49 (insert-char char count) | 49 (insert-char char count) |
50 (with-current-buffer buffer | 50 (with-current-buffer buffer |
78 ((boundp 'temporary-file-directory) temporary-file-directory) | 78 ((boundp 'temporary-file-directory) temporary-file-directory) |
79 ("/tmp"))) | 79 ("/tmp"))) |
80 | 80 |
81 ;;;###autoload | 81 ;;;###autoload |
82 (defun uudecode-decode-region-external (start end &optional file-name) | 82 (defun uudecode-decode-region-external (start end &optional file-name) |
83 "Uudecode region between START and END with external decoder. | 83 "Uudecode region between START and END using external program. |
84 | 84 If FILE-NAME is non-nil, save the result to FILE-NAME. The program |
85 If FILE-NAME is non-nil, save the result to FILE-NAME." | 85 used is specified by `uudecode-decoder-program'." |
86 (interactive "r\nP") | 86 (interactive "r\nP") |
87 (let ((cbuf (current-buffer)) tempfile firstline work-buffer status) | 87 (let ((cbuf (current-buffer)) tempfile firstline status) |
88 (save-excursion | 88 (save-excursion |
89 (goto-char start) | 89 (goto-char start) |
90 (when (re-search-forward uudecode-begin-line nil t) | 90 (when (re-search-forward uudecode-begin-line nil t) |
91 (forward-line 1) | 91 (forward-line 1) |
92 (setq firstline (point)) | 92 (setq firstline (point)) |
96 (setq file-name (read-file-name "File to Name:" | 96 (setq file-name (read-file-name "File to Name:" |
97 nil nil nil | 97 nil nil nil |
98 (match-string 1))))) | 98 (match-string 1))))) |
99 (setq tempfile (if file-name | 99 (setq tempfile (if file-name |
100 (expand-file-name file-name) | 100 (expand-file-name file-name) |
101 (make-temp-name | 101 (let ((temporary-file-directory |
102 ;; /tmp/uu... | 102 uudecode-temporary-file-directory)) |
103 (expand-file-name | 103 (make-temp-file "uu")))) |
104 "uu" uudecode-temporary-file-directory)))) | 104 (let ((cdir default-directory) |
105 (let ((cdir default-directory) default-process-coding-system) | 105 default-process-coding-system) |
106 (unwind-protect | 106 (unwind-protect |
107 (progn | 107 (with-temp-buffer |
108 (set-buffer (setq work-buffer | |
109 (generate-new-buffer " *uudecode-work*"))) | |
110 (buffer-disable-undo work-buffer) | |
111 (insert "begin 600 " (file-name-nondirectory tempfile) "\n") | 108 (insert "begin 600 " (file-name-nondirectory tempfile) "\n") |
112 (insert-buffer-substring cbuf firstline end) | 109 (insert-buffer-substring cbuf firstline end) |
113 (cd (file-name-directory tempfile)) | 110 (cd (file-name-directory tempfile)) |
114 (apply 'call-process-region | 111 (apply 'call-process-region |
115 (point-min) | 112 (point-min) |
125 (goto-char start) | 122 (goto-char start) |
126 (delete-region start end) | 123 (delete-region start end) |
127 (let (format-alist) | 124 (let (format-alist) |
128 (insert-file-contents-literally tempfile))) | 125 (insert-file-contents-literally tempfile))) |
129 (message "Can not uudecode"))) | 126 (message "Can not uudecode"))) |
130 (and work-buffer (kill-buffer work-buffer)) | |
131 (ignore-errors (or file-name (delete-file tempfile)))))) | 127 (ignore-errors (or file-name (delete-file tempfile)))))) |
132 | 128 |
133 ;;;###autoload | 129 ;;;###autoload |
134 | |
135 (defun uudecode-decode-region (start end &optional file-name) | 130 (defun uudecode-decode-region (start end &optional file-name) |
136 "Uudecode region between START and END. | 131 "Uudecode region between START and END without using an external program. |
137 If FILE-NAME is non-nil, save the result to FILE-NAME." | 132 If FILE-NAME is non-nil, save the result to FILE-NAME." |
138 (interactive "r\nP") | 133 (interactive "r\nP") |
139 (let ((work-buffer nil) | 134 (let ((work-buffer nil) |
140 (done nil) | 135 (done nil) |
141 (counter 0) | 136 (counter 0) |