1 ;;; -*- coding: iso-2022-7bit; -*-
2 ;;; tramp-uu.el --- uuencode in Lisp
4 ;; Copyright (C) 2002, 2003, 2004, 2005, 2006 Free Software Foundation, Inc.
6 ;; Author: Kai Gro\e,A_\e(Bjohann <kai.grossjohann@gmx.net>
7 ;; Keywords: comm, terminals
9 ;; This file is free software; you can redistribute it and/or modify
10 ;; it under the terms of the GNU General Public License as published by
11 ;; the Free Software Foundation; either version 2, or (at your option)
14 ;; This file is distributed in the hope that it will be useful,
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 ;; GNU General Public License for more details.
19 ;; You should have received a copy of the GNU General Public License
20 ;; along with GNU Emacs; see the file COPYING. If not, write to
21 ;; the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
22 ;; Boston, MA 02110-1301, USA.
26 ;; An implementation of "uuencode" in Lisp. Uses the function
27 ;; base64-encode-region which is built-in to modern Emacsen.
31 (defvar tramp-uu-b64-alphabet
32 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"
33 "Mapping from base64-encoded character to the byte it represents.")
35 (defvar tramp-uu-b64-char-to-byte
41 tramp-uu-b64-alphabet
))
42 "Alist of mapping from base64 character to its byte.")
44 (defun tramp-uu-byte-to-uu-char (byte)
45 "Return the character encoding BYTE."
46 (if (zerop byte
) ?
` (+ byte
32)))
48 (defun tramp-uu-b64-char-to-byte (char)
49 "Return the byte that is encoded as CHAR."
50 (cdr (assq char tramp-uu-b64-char-to-byte
)))
52 (defun tramp-uuencode-region (beg end
)
53 "UU-encode the region between BEG and END."
54 ;; First we base64 encode the region, then we transmogrify that into
56 (let ((len (base64-encode-region beg end t
))
63 (setq c
(char-after (point)))
66 ;; "=" means padding. Insert "`" instead. Not counted for length.
67 (progn (insert "`") (setq len
(1- len
)))
68 (insert (tramp-uu-byte-to-uu-char (tramp-uu-b64-char-to-byte c
)))
70 ;; Every 60 characters, add "M" at beginning of line (as
71 ;; length byte) and insert a newline.
72 (when (zerop (% i
60))
75 (insert (char-to-string (+ 32 (/ (* 3 60) 4)))))
77 ;; If there is something leftover, we compute the length byte
78 ;; for that stuff and insert it and a trailing newline.
79 (unless (zerop (% i
60))
82 (insert (char-to-string (+ 32 (%
(- end beg
) 45)))))
84 ;; Why is there always a "`" line at the end?
87 (insert "begin 600 xxx\n"))))
91 ;;; arch-tag: 7153f2c6-8be5-4cd2-8c06-0fbcf5190ef6
92 ;;; tramp-uu.el ends here