iiencode.icn: Program to encode text in the style of uuencode

May 2, 2001; Richard L. Goerwitz, enhanced by Frank J. Lhota
See also: iidecode.icn
This file is in the public domain.
This is an Icon port of the UNIX/C uuencode utility.  Since
uuencode is publicly distributable BSD code, I simply grabbed a
copy, and rewrote it in Icon.  The only basic functional changes I
made to the program were:  (1) To simplify the notion of file mode
(everything is encoded with 0644 permissions), and (2) to add sup-
port for xxencode format (which will generally pass unscathed even
through EBCDIC sites).

Iiencode's usage is compatible with that of the UNIX uuencode
command, i.e. a first (optional) argument gives the name the file
to be encoded.  If this is omitted, iiencode just uses the standard
input.  The second argument specifies the name the encoded file
should be given when it is ultimately decoded.

Extensions to the base uuencode command options include -x and -o.
An -x tells iiencode to use xxencode (rather than uuencode) format.
Option -o causes the following argument to be used as the file
iiencode is to write its output to (the default is &output).  Note
that, on systems with newline translation (e.g. MS-DOS), the -o
argument should always be used.

  iiencode [infile] [-x] remote-filename [-o output-filename]


FIXES: Speeded up substantially (more than twice as fast on my
machine) by using a more icon-ish algorithm.  We encode in two
steps:

1)   We first "unpack" the bytes by taking groups of 3 bytes (24
     bits) and spreading them out by inserting two 0 bits before
     every block of 6 bits.  The result is that each group of 3
     bytes is unpacked to 4 "small bytes", each <<= "\x3F".
2)   The unpacked bytes are mapped to the coded line by using the
     Icon map function.

There are numerous advantages to this approach.  The Icon map
function is much faster than the 'C'-ish alternatives.  We can
process the file one line at a time. Also, the different encoding
mechanisms (old BSD, new BSD, xxencode) can be produces by simply
using different map parameters.

Source code | Program Library Page | Icon Home Page