1 ;;; tramp-uu.el --- uuencode in Lisp
3 ;; Copyright (C) 2002 Free Software Foundation, Inc.
5 ;; Author: Kai Großjohann <Kai.Grossjohann@CS.Uni-Dortmund.DE>
6 ;; Keywords: comm, terminals
8 ;; This file is free software; you can redistribute it and/or modify
9 ;; it under the terms of the GNU General Public License as published by
10 ;; the Free Software Foundation; either version 2, or (at your option)
13 ;; This file is distributed in the hope that it will be useful,
14 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
15 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 ;; GNU General Public License for more details.
18 ;; You should have received a copy of the GNU General Public License
19 ;; along with GNU Emacs; see the file COPYING. If not, write to
20 ;; the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21 ;; Boston, MA 02111-1307, USA.
25 ;; An implementation of "uuencode" in Lisp. Uses the function
26 ;; base64-encode-region which is built-in to modern Emacsen.
30 (defvar tramp-uu-b64-alphabet
31 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"
32 "Mapping from base64-encoded character to the byte it represents.")
34 (defvar tramp-uu-b64-char-to-byte
40 tramp-uu-b64-alphabet
))
41 "Alist of mapping from base64 character to its byte.")
43 (defun tramp-uu-byte-to-uu-char (byte)
44 "Return the character encoding BYTE."
45 (if (zerop byte
) ?
` (+ byte
32)))
47 (defun tramp-uu-b64-char-to-byte (char)
48 "Return the byte that is encoded as CHAR."
49 (cdr (assq char tramp-uu-b64-char-to-byte
)))
51 (defun tramp-uuencode-region (beg end
)
52 "UU-encode the region between BEG and END."
53 ;; First we base64 encode the region, then we transmogrify that into
55 (let ((len (base64-encode-region beg end t
))
62 (setq c
(char-after (point)))
65 ;; "=" means padding. Insert "`" instead.
67 (insert (tramp-uu-byte-to-uu-char (tramp-uu-b64-char-to-byte c
))))
69 ;; Every 60 characters, add "M" at beginning of line (as
70 ;; length byte) and insert a newline.
71 (when (zerop (% i
60))
74 (insert (char-to-string (+ 32 (/ (* 3 60) 4)))))
76 ;; If there is something leftover, we compute the length byte
77 ;; for that stuff and insert it and a trailing newline.
78 (unless (zerop (% i
60))
81 (insert (char-to-string (+ 32 (%
(- end beg
) 45)))))
83 ;; Why is there always a "`" line at the end?
86 (insert "begin 600 xxx\n"))))
89 ;;; tramp-uu.el ends here