1 ;;; uudecode.el -- elisp native uudecode
3 ;; Copyright (c) 1998, 1999, 2000, 2001, 2003 Free Software Foundation, Inc.
5 ;; Author: Shenghuo Zhu <zsh@cs.rochester.edu>
6 ;; Keywords: uudecode news
8 ;; This file is part of GNU Emacs.
10 ;; GNU Emacs is free software; you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation; either version 2, or (at your option)
15 ;; GNU Emacs is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ;; GNU General Public License for more details.
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs; see the file COPYING. If not, write to the
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23 ;; Boston, MA 02111-1307, USA.
29 (autoload 'executable-find "executable")
31 (eval-when-compile (require 'cl))
34 (defalias 'uudecode-char-int
35 (if (fboundp 'char-int)
39 (defcustom uudecode-decoder-program "uudecode"
40 "*Non-nil value should be a string that names a uu decoder.
41 The program should expect to read uu data on its standard
42 input and write the converted data to its standard output."
46 (defcustom uudecode-decoder-switches nil
47 "*List of command line flags passed to `uudecode-decoder-program'."
49 :type '(repeat string))
51 (defcustom uudecode-use-external
52 (executable-find uudecode-decoder-program)
53 "*Use external uudecode program."
57 (defconst uudecode-alphabet "\040-\140")
59 (defconst uudecode-begin-line "^begin[ \t]+[0-7][0-7][0-7][ \t]+\\(.*\\)$")
60 (defconst uudecode-end-line "^end[ \t]*$")
62 (defconst uudecode-body-line
63 (let ((i 61) (str "^M"))
64 (while (> (setq i (1- i)) 0)
65 (setq str (concat str "[^a-z]")))
68 (defvar uudecode-temporary-file-directory
69 (cond ((fboundp 'temp-directory) (temp-directory))
70 ((boundp 'temporary-file-directory) temporary-file-directory)
74 (defun uudecode-decode-region-external (start end &optional file-name)
75 "Uudecode region between START and END using external program.
76 If FILE-NAME is non-nil, save the result to FILE-NAME. The program
77 used is specified by `uudecode-decoder-program'."
79 (let ((cbuf (current-buffer)) tempfile firstline status)
82 (when (re-search-forward uudecode-begin-line nil t)
84 (setq firstline (point))
85 (cond ((null file-name))
88 (setq file-name (read-file-name "File to Name:"
91 (setq tempfile (if file-name
92 (expand-file-name file-name)
93 (if (fboundp 'make-temp-file)
94 (let ((temporary-file-directory
95 uudecode-temporary-file-directory))
96 (make-temp-file "uu"))
99 uudecode-temporary-file-directory))))
100 (let ((cdir default-directory)
101 default-process-coding-system)
104 (insert "begin 600 " (file-name-nondirectory tempfile) "\n")
105 (insert-buffer-substring cbuf firstline end)
106 (cd (file-name-directory tempfile))
107 (apply 'call-process-region
110 uudecode-decoder-program