iidecode.icn: Program to decode text in style of uudecode

May 2, 2001; Richard L. Goerwitz, enhanced by Frank J. Lhota
See also: iiencode.icn
This file is in the public domain.
This is an Icon port of the UNIX/C uudecode utility.  Since
uudecode 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 a
command-line switch for xxencoded files (similar to uuencoded
files, but capable of passing unscathed through non-ASCII EBCDIC
sites).

       usage:  iidecode [infile] [-x]

Usage is compatible with that of the UNIX uudecode command, i.e. a
first (optional) argument gives the name the file to be decoded.
If this is omitted, iidecode just uses the standard input.  The -x
switch (peculiar to iidecode) forces use of the the xxdecoding
algorithm.  If you try to decode an xxencoded file without speci-
-x on the command line, iidecode will try to forge ahead anyway.
If it thinks you've made a mistake, iidecode will inform you after
the decode is finished.


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

1)   The coded characters are mapped to "small bytes",
     each with 2 zero high bits, i.e. <<= "\x3F".
2)   We then 'pack' the small bytes by taking groups of 4 small bytes
     (each with 2 zero high bits and 6 data bits) and packing
     the data bits into groups of 3 bytes.

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

Source code | Program Library Page | Icon Home Page