🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: news.software.readers
Article #56800

Re: looking for uudecode source.

#56800
From: Russ Allbery
Date: Sun, 16 Jan 2000 00:00
55 lines
2272 bytes
Michael Praschl <praschl@bigfoot.com> writes:

> i've been lately trying to find a source for uudecode, as i would like
> to include it in my newsreader directly.

> but the only useable thing the searchengines popped up was a pascal
> source, and after porting the decoding part to C, every second in 3
> bytes is decoded wrong, and i cant figure out, where the problem is.

> can somebody post a C or C++ source to this, please?

/* Decoding a single character of uuencoded text. */
#define DEC(c)  (((c) - ' ') & 077)

/* Decode a uuencoded string into another buffer, returning the total
   number of characters.  This is based on 4.4 BSD source. */
int
decode(char *encoded, char *decoded)
{
    int count, length;
    char *in, *out;

    in = encoded;
    out = decoded;
    while (1) {
        length = DEC(*in);
        if (length <= 0) break;
        for (++in; length > 0; in += 4, length -= 3) {
            if (length >= 1) {
                *out = DEC(in[0]) << 2 | DEC(in[1]) >> 4;
                out++;
            }
            if (length >= 2) {
                *out = DEC(in[1]) << 4 | DEC(in[2]) >> 2;
                out++;
            }
            if (length >= 3) {
                *out = DEC(in[2]) << 6 | DEC(in[3]);
                out++;
            }
        }
        if (in[1] != '\0')
            ++in;
        else
            break;
    }
    return (out - decoded);
}  

This isn't particularly forgiving, but I know it works.

-- 
Russ Allbery (rra@stanford.edu)         <URL:http://www.eyrie.org/~eagle/>

Technical Details
Message-ID: <yliu0t1dvg.fsf@windlord.stanford.edu>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!archive.pugleaf.net!archive.newsdeef.eu!mbox2nntp-news.software.readers.mbox.zip!not-for-mail
References: <%Gvg4.29722$c6.1140333@news.chello.at>

Show Full Headers
Complete Article Headers
Message-ID: <yliu0t1dvg.fsf@windlord.stanford.edu>
Subject: Re: looking for uudecode source.
Date: Sun, 16 Jan 2000 00:00:00 +0000
From: Russ Allbery <rra@stanford.edu>
References: <%Gvg4.29722$c6.1140333@news.chello.at>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!archive.pugleaf.net!archive.newsdeef.eu!mbox2nntp-news.software.readers.mbox.zip!not-for-mail
X-Deja-AN: 573618118
Content-Type: text/plain; charset=us-ascii
Organization: The Eyrie
Mime-Version: 1.0
User-Agent: Gnus/5.0802 (Gnus v5.8.2) XEmacs/21.1 (Biscayne)
Newsgroups: news.software.readers