annotate lisp/mail/uudecode.el @ 93382:8e46096e0cb3

* vc.el (vc-status-menu-map, vc-status-mode-map): Bind vc-revert. (vc-status-refresh): Create a temporary buffer and call the `dir-status' backend function from that buffer. * vc-bzr.el (vc-bzr-dir-status): Don't create a buffer. (vc-bzr-after-dir-status): Don't kill the buffer. * vc-cvs.el (vc-cvs-dir-status): Don't create a buffer. (vc-cvs-after-dir-status): Don't kill the buffer. * vc-git.el (vc-git-dir-status): Don't create a buffer. (vc-git-after-dir-status-stage2): Don't kill the buffer. * vc-hg.el (vc-hg-dir-status): Don't create a buffer. (vc-hg-after-dir-status): Don't kill the buffer. * vc-svn.el (vc-svn-dir-status): Don't create a buffer. (vc-svn-after-dir-status): Don't kill the buffer.
author Dan Nicolaescu <dann@ics.uci.edu>
date Sat, 29 Mar 2008 05:34:52 +0000
parents b643f53a57c5
children ef65fa4dca3b
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
86959
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1 ;;; uudecode.el -- elisp native uudecode
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
2
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
3 ;; Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004,
87649
107ccd98fa12 Merge from emacs--rel--22
Miles Bader <miles@gnu.org>
parents: 86962
diff changeset
4 ;; 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
86959
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
5
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
6 ;; Author: Shenghuo Zhu <zsh@cs.rochester.edu>
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
7 ;; Keywords: uudecode news
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
8
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
9 ;; This file is part of GNU Emacs.
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
10
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
11 ;; GNU Emacs is free software; you can redistribute it and/or modify
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
12 ;; it under the terms of the GNU General Public License as published by
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
13 ;; the Free Software Foundation; either version 3, or (at your option)
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
14 ;; any later version.
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
15
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
16 ;; GNU Emacs is distributed in the hope that it will be useful,
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
19 ;; GNU General Public License for more details.
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
20
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
21 ;; You should have received a copy of the GNU General Public License
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
22 ;; along with GNU Emacs; see the file COPYING. If not, write to the
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
23 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
24 ;; Boston, MA 02110-1301, USA.
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
25
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
26 ;;; Commentary:
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
27
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
28 ;;; Code:
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
29
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
30 (eval-when-compile (require 'cl))
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
31
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
32 (eval-and-compile
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
33 (defalias 'uudecode-char-int
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
34 (if (fboundp 'char-int)
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
35 'char-int
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
36 'identity)))
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
37
86962
4a055549d556 (uudecode): New custom group.
Glenn Morris <rgm@gnu.org>
parents: 86959
diff changeset
38 (defgroup uudecode nil
4a055549d556 (uudecode): New custom group.
Glenn Morris <rgm@gnu.org>
parents: 86959
diff changeset
39 "Decoding of uuencoded data."
4a055549d556 (uudecode): New custom group.
Glenn Morris <rgm@gnu.org>
parents: 86959
diff changeset
40 :group 'mail
4a055549d556 (uudecode): New custom group.
Glenn Morris <rgm@gnu.org>
parents: 86959
diff changeset
41 :group 'news)
4a055549d556 (uudecode): New custom group.
Glenn Morris <rgm@gnu.org>
parents: 86959
diff changeset
42
86959
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
43 (defcustom uudecode-decoder-program "uudecode"
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
44 "*Non-nil value should be a string that names a uu decoder.
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
45 The program should expect to read uu data on its standard
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
46 input and write the converted data to its standard output."
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
47 :type 'string
86962
4a055549d556 (uudecode): New custom group.
Glenn Morris <rgm@gnu.org>
parents: 86959
diff changeset
48 :group 'uudecode)
86959
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
49
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
50 (defcustom uudecode-decoder-switches nil
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
51 "*List of command line flags passed to `uudecode-decoder-program'."
86962
4a055549d556 (uudecode): New custom group.
Glenn Morris <rgm@gnu.org>
parents: 86959
diff changeset
52 :group 'uudecode
86959
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
53 :type '(repeat string))
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
54
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
55 (defcustom uudecode-use-external
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
56 (executable-find uudecode-decoder-program)
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
57 "*Use external uudecode program."
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
58 :version "22.1"
86962
4a055549d556 (uudecode): New custom group.
Glenn Morris <rgm@gnu.org>
parents: 86959
diff changeset
59 :group 'uudecode
86959
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
60 :type 'boolean)
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
61
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
62 (defconst uudecode-alphabet "\040-\140")
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
63
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
64 (defconst uudecode-begin-line "^begin[ \t]+[0-7][0-7][0-7][ \t]+\\(.*\\)$")
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
65 (defconst uudecode-end-line "^end[ \t]*$")
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
66
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
67 (defconst uudecode-body-line
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
68 (let ((i 61) (str "^M"))
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
69 (while (> (setq i (1- i)) 0)
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
70 (setq str (concat str "[^a-z]")))
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
71 (concat str ".?$")))
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
72
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
73 (defvar uudecode-temporary-file-directory
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
74 (cond ((fboundp 'temp-directory) (temp-directory))
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
75 ((boundp 'temporary-file-directory) temporary-file-directory)
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
76 ("/tmp")))
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
77
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
78 ;;;###autoload
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
79 (defun uudecode-decode-region-external (start end &optional file-name)
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
80 "Uudecode region between START and END using external program.
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
81 If FILE-NAME is non-nil, save the result to FILE-NAME. The program
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
82 used is specified by `uudecode-decoder-program'."
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
83 (interactive "r\nP")
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
84 (let ((cbuf (current-buffer)) tempfile firstline status)
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
85 (save-excursion
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
86 (goto-char start)
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
87 (when (re-search-forward uudecode-begin-line nil t)
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
88 (forward-line 1)
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
89 (setq firstline (point))
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
90 (cond ((null file-name))
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
91 ((stringp file-name))
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
92 (t
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
93 (setq file-name (read-file-name "File to Name:"
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
94 nil nil nil
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
95 (match-string 1)))))
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
96 (setq tempfile (if file-name
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
97 (expand-file-name file-name)
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
98 (if (fboundp 'make-temp-file)
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
99 (let ((temporary-file-directory
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
100 uudecode-temporary-file-directory))
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
101 (make-temp-file "uu"))
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
102 (expand-file-name
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
103 (make-temp-name "uu")
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
104 uudecode-temporary-file-directory))))
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
105 (let ((cdir default-directory)
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
106 (default-process-coding-system
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
107 (if (featurep 'xemacs)
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
108 ;; In XEmacs, `nil' is not a valid coding system.
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
109 '(binary . binary)
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
110 nil)))
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
111 (unwind-protect
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
112 (with-temp-buffer
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
113 (insert "begin 600 " (file-name-nondirectory tempfile) "\n")
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
114 (insert-buffer-substring cbuf firstline end)
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
115 (cd (file-name-directory tempfile))
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
116 (apply 'call-process-region
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
117 (point-min)
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
118 (point-max)
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
119 uudecode-decoder-program
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
120 nil
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
121 nil
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
122 nil
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
123 uudecode-decoder-switches))
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
124 (cd cdir) (set-buffer cbuf)))
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
125 (if (file-exists-p tempfile)
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
126 (unless file-name
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
127 (goto-char start)
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
128 (delete-region start end)
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
129 (let (format-alist)
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
130 (insert-file-contents-literally tempfile)))
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
131 (message "Can not uudecode")))
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
132 (ignore-errors (or file-name (delete-file tempfile))))))
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
133
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
134 (eval-and-compile
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
135 (defalias 'uudecode-string-to-multibyte
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
136 (cond
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
137 ((featurep 'xemacs)
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
138 'identity)
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
139 ((fboundp 'string-to-multibyte)
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
140 'string-to-multibyte)
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
141 (t
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
142 (lambda (string)
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
143 "Return a multibyte string with the same individual chars as string."
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
144 (mapconcat
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
145 (lambda (ch) (string-as-multibyte (char-to-string ch)))
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
146 string ""))))))
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
147
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
148 ;;;###autoload
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
149 (defun uudecode-decode-region-internal (start end &optional file-name)
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
150 "Uudecode region between START and END without using an external program.
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
151 If FILE-NAME is non-nil, save the result to FILE-NAME."
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
152 (interactive "r\nP")
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
153 (let ((done nil)
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
154 (counter 0)
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
155 (remain 0)
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
156 (bits 0)
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
157 (lim 0) inputpos result
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
158 (non-data-chars (concat "^" uudecode-alphabet)))
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
159 (save-excursion
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
160 (goto-char start)
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
161 (when (re-search-forward uudecode-begin-line nil t)
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
162 (cond ((null file-name))
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
163 ((stringp file-name))
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
164 (t
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
165 (setq file-name (expand-file-name
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
166 (read-file-name "File to Name:"
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
167 nil nil nil
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
168 (match-string 1))))))
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
169 (forward-line 1)
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
170 (skip-chars-forward non-data-chars end)
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
171 (while (not done)
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
172 (setq inputpos (point))
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
173 (setq remain 0 bits 0 counter 0)
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
174 (cond
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
175 ((> (skip-chars-forward uudecode-alphabet end) 0)
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
176 (setq lim (point))
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
177 (setq remain
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
178 (logand (- (uudecode-char-int (char-after inputpos)) 32)
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
179 63))
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
180 (setq inputpos (1+ inputpos))
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
181 (if (= remain 0) (setq done t))
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
182 (while (and (< inputpos lim) (> remain 0))
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
183 (setq bits (+ bits
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
184 (logand
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
185 (-
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
186 (uudecode-char-int (char-after inputpos)) 32)
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
187 63)))
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
188 (if (/= counter 0) (setq remain (1- remain)))
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
189 (setq counter (1+ counter)
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
190 inputpos (1+ inputpos))
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
191 (cond ((= counter 4)
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
192 (setq result (cons
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
193 (concat
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
194 (char-to-string (lsh bits -16))
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
195 (char-to-string (logand (lsh bits -8) 255))
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
196 (char-to-string (logand bits 255)))
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
197 result))
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
198 (setq bits 0 counter 0))
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
199 (t (setq bits (lsh bits 6)))))))
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
200 (cond
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
201 (done)
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
202 ((> 0 remain)
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
203 (error "uucode line ends unexpectly")
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
204 (setq done t))
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
205 ((and (= (point) end) (not done))
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
206 ;;(error "uucode ends unexpectly")
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
207 (setq done t))
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
208 ((= counter 3)
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
209 (setq result (cons
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
210 (concat
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
211 (char-to-string (logand (lsh bits -16) 255))
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
212 (char-to-string (logand (lsh bits -8) 255)))
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
213 result)))
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
214 ((= counter 2)
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
215 (setq result (cons
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
216 (char-to-string (logand (lsh bits -10) 255))
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
217 result))))
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
218 (skip-chars-forward non-data-chars end))
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
219 (if file-name
92782
b643f53a57c5 (uudecode-decode-region-internal): Use set-buffer-multibyte rather than
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 87649
diff changeset
220 (with-temp-file file-name
b643f53a57c5 (uudecode-decode-region-internal): Use set-buffer-multibyte rather than
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 87649
diff changeset
221 (set-buffer-multibyte nil)
b643f53a57c5 (uudecode-decode-region-internal): Use set-buffer-multibyte rather than
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 87649
diff changeset
222 (insert (apply 'concat (nreverse result))))
86959
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
223 (or (markerp end) (setq end (set-marker (make-marker) end)))
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
224 (goto-char start)
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
225 (if enable-multibyte-characters
92782
b643f53a57c5 (uudecode-decode-region-internal): Use set-buffer-multibyte rather than
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 87649
diff changeset
226 (dolist (x (nreverse result))
b643f53a57c5 (uudecode-decode-region-internal): Use set-buffer-multibyte rather than
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 87649
diff changeset
227 (insert (uudecode-string-to-multibyte x)))
86959
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
228 (insert (apply 'concat (nreverse result))))
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
229 (delete-region (point) end))))))
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
230
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
231 ;;;###autoload
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
232 (defun uudecode-decode-region (start end &optional file-name)
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
233 "Uudecode region between START and END.
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
234 If FILE-NAME is non-nil, save the result to FILE-NAME."
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
235 (if uudecode-use-external
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
236 (uudecode-decode-region-external start end file-name)
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
237 (uudecode-decode-region-internal start end file-name)))
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
238
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
239 (provide 'uudecode)
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
240
92782
b643f53a57c5 (uudecode-decode-region-internal): Use set-buffer-multibyte rather than
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 87649
diff changeset
241 ;; arch-tag: e1f09ed5-62b4-4677-9f13-4e81c4fe8ce3
86959
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
242 ;;; uudecode.el ends here