(byte-compile-warn-obsolete): New function.
[emacs.git] / lisp / net / tramp-uu.el
blobbaae917f32c411fdbc784cd2f0cefb1c48ea7841
1 ;;; tramp-uu.el --- uuencode in Lisp
3 ;; Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007,
4 ;; 2008 Free Software Foundation, Inc.
6 ;; Author: Kai Großjohann <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 3, or (at your option)
12 ;; any later version.
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, see
21 ;; <http://www.gnu.org/licenses/>.
23 ;;; Commentary:
25 ;; An implementation of "uuencode" in Lisp. Uses the function
26 ;; base64-encode-region which is built-in to modern Emacsen.
28 ;;; Code:
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
35 (let ((i 0))
36 (mapcar (lambda (c)
37 (prog1
38 (cons c i)
39 (setq i (1+ i))))
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
54 ;; uu encoding.
55 (let ((len (base64-encode-region beg end t))
56 (padding 0)
57 i c)
58 (save-excursion
59 (goto-char beg)
60 (setq i 0)
61 (while (< i len)
62 (setq c (char-after (point)))
63 (delete-char 1)
64 (if (equal c ?=)
65 ;; "=" means padding. Insert "`" instead. Not counted for length.
66 (progn (insert "`") (setq len (1- len)))
67 (insert (tramp-uu-byte-to-uu-char (tramp-uu-b64-char-to-byte c)))
68 (setq i (1+ i)))
69 ;; Every 60 characters, add "M" at beginning of line (as
70 ;; length byte) and insert a newline.
71 (when (zerop (% i 60))
72 (save-excursion
73 (beginning-of-line)
74 (insert (char-to-string (+ 32 (/ (* 3 60) 4)))))
75 (insert "\n")))
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))
79 (save-excursion
80 (beginning-of-line)
81 (insert (char-to-string (+ 32 (% (- end beg) 45)))))
82 (insert "\n"))
83 ;; Why is there always a "`" line at the end?
84 (insert "`\nend\n")
85 (goto-char beg)
86 (insert "begin 600 xxx\n"))))
88 (provide 'tramp-uu)
90 ;; arch-tag: 7153f2c6-8be5-4cd2-8c06-0fbcf5190ef6
91 ;;; tramp-uu.el ends here
93 ;; Local Variables:
94 ;; mode: Emacs-Lisp
95 ;; coding: utf-8
96 ;; End: