This is an implementation of uuencode in Retro. This takes a file name and renders the uuencoded data to standard output.
First, determine the size of the file.
With this, I can create a buffer to hold the file and read it into memory.
A uuencoded file starts with a header line of the form:
begin <mode> <file><newline>
I am hard coding the mode as 0644.
Here's how uuencoding works:
• Three characters are packed into a cell.
Cat = (C) 01000011 (a) 01100001 (t) 01110100
• This is divided into a quartet of six bit values.
Cat = 010000 110110 000101 110100
• 32 is added to each, yielding a printable character.
• At this point, "Cat" has become 0V%T.
So the basic encoding words will need to pack a cell and then unpack it into characters.
The actual conversion is pretty easy. Output is given as lines, starting with an encoded length followed by the encoded data. The encoded length is just the actual value with 32 added to it and displayed as an ASCII character.
Lines are 45 unencoded characters in length, so will start with an M, except for the last one, which may be shorter.
So:a
And then using the factors to do the conversion:
A uuencoded file ends with two lines:
end
The backtick is used to denote a line with a length of zero characters.