1 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
6 ;; Description: Commands for uuencoding/uudecoding marked files.
7 ;; Author: Sandy Rutherford <sandy@math.ubc.ca>
9 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
11 ;;; Requirements and provisions
15 (defvar dired-uu-files-to-decode nil)
16 ;; Fluid var to pass data inside dired-create-files.
18 (defun dired-uucode-file (file ok-flag)
19 ;; uuencode or uudecode FILE.
20 ;; Don't really support the ok-flag, but needed for compatibility
21 (let ((handler (find-file-name-handler file 'dired-uucode-file)))
23 (funcall handler 'dired-uucode-file file ok-flag))
24 ((or (file-symlink-p file) (file-directory-p file))
27 (if (assoc file dired-uu-files-to-decode)
28 (let ((default-directory (file-name-directory file)))
29 (if (dired-check-process
30 (concat "Uudecoding " file) shell-file-name shell-command-switch
31 (format "uudecode %s" file))
32 (signal 'file-error (list "Error uudecoding" file))))
33 (let ((nfile (concat file ".uu")))
34 (if (dired-check-process
35 (concat "Uuencoding " file) shell-file-name shell-command-switch
36 (format "uuencode %s %s > %s"
37 file (file-name-nondirectory file) nfile))
38 (signal 'file-error (list "Error uuencoding" file)))))))))
40 (defun dired-uucode-out-file (file)
41 ;; Returns the name of the output file for the uuencoded FILE.
42 (let ((buff (get-buffer-create " *dired-check-process output*"))
47 (if (string-equal "18." (substring emacs-version 0 3))
48 (call-process "head" file buff nil "-n" "1")
49 (insert-file-contents file nil 0 80))
50 (goto-char (point-min))
51 (if (looking-at "begin [0-9]+ \\([^\n]*\\)\n")
53 (buffer-substring (match-beginning 1) (match-end 1))
54 (file-name-directory file))
58 (defun dired-do-uucode (&optional arg files to-decode)
59 "Uuencode or uudecode marked (or next ARG) files."
61 (let* ((dir (dired-current-directory))
62 (files (dired-get-marked-files nil current-prefix-arg))
63 (arg (prefix-numeric-value current-prefix-arg))
64 (total (length files))
65 rfiles decoders ofile decode encode hint-p)
69 (if (setq ofile (dired-uucode-out-file fn))
70 (setq decoders (cons (cons fn ofile) decoders)))))
72 (setq decode (length decoders)
73 encode (- total decode)
74 hint-p (not (or (zerop decode) (zerop encode))))
81 (if (assoc fn decoders) " [de] " " [en] ")
82 (dired-make-relative fn dir t))
83 (dired-make-relative fn dir t))))
85 (or (memq 'uuencode dired-no-confirm)
86 (dired-mark-pop-up nil 'uuencode rfiles 'y-or-n-p
90 (format "Uuencode %s? " (car rfiles))
91 (format "Uuencode %d file%s? "
92 encode (dired-plural-s encode))))
95 (format "Uudecode %s? " (car rfiles))
96 (format "Uudecode %d file%s? "
97 decode (dired-plural-s decode))))
99 (format "Uudecode %d and uuencode %d file%s? "
100 decode encode (dired-plural-s encode)))))
102 (list arg files decoders)))
103 (let ((dired-uu-files-to-decode to-decode)
105 (if (not (zerop arg))
108 "Uuencode or Uudecode"
112 (if (setq out-file (assoc fn dired-uu-files-to-decode))
115 dired-keep-marker-uucode nil t))))
117 ;;; end of dired-uu.el