| TIP: Click on subject to list as thread! | ANSI |
| echo: | |
|---|---|
| to: | |
| from: | |
| date: | |
| subject: | UU algorithm |
following up a message from Pete Zieger to Mike Ruskai:
MR> Anyone have the algorithm for uuen/decoding files? I'd like to
MR> write en/decoders in REXX.
Here are the two uu programs from snippets:
uudecode.c
/*
** by: John Lots
** patched up for BC++ 3.1 by Alan Eldridge 10/12/92
** (UUCP: alane{at}wozzle.linet.org, FIDO: 1:272/38.473)
*/
#include
#include
#define DEC(c) (char)(((c)-' ')&077)
int main()
{
int n;
char buf[128],a,b,c,d;
scanf("begin %o ", &n);
gets(buf); /* filename */
if (!freopen(buf, "wb", stdout)) /* oops.. */
{
perror(buf);
exit(1);
}
while ((n=getchar())!=EOF&&((n=DEC(n))!=0))
{
while (n>0)
{
a=DEC(getchar());
b=DEC(getchar());
c=DEC(getchar());
d=DEC(getchar());
if (n-->0)
putchar((a>4));
if (n-->0)
putchar((b>2));
if (n-->0)
putchar((c<<6)|d);
}
n=getchar(); /* skip \n */
}
return 0;
}
uuencode.c
/* uuencode.c */
/*
uudecode and uuencode are easily implemented under MSDOS as well. Here are
the sources for Microsoft C v3.0, but if you have another kind of C
compiler, there should be perhaps only 1 change -- the output file of
uudecode and the input file of uuencode must be in binary format. (ie.
binary files, like .EXE files may have byte patterns that are the same as
^Z, which signals end-of-file in non-binary (text) mode).
Don Kneller
UUCP: ...ucbvax!ucsfcgl!kneller
ARPA: kneller{at}ucsf-cgl.ARPA
BITNET: kneller{at}ucsfcgl.BITNET
patched up for BC++ 3.1 by Alan Eldridge 10/12/92
(UUCP: alane{at}wozzle.linet.org, FIDO: 1:272/38.473)
*/
#ifndef lint
#ifndef MSDOS
static char sccsid[] = "{at}(#)uuencode.c 5.1 (Berkeley) 7/2/83"; #endif
#endif
/*
* uuencode [input] output
*
* Encode a file so it can be mailed to a remote system.
*/
#include
#include
#include
#include
/* ENC is the basic 1 character encoding function to make a char printing */
#define ENC(c) (((c) & 077) + ' ')
void encode(FILE *in, FILE *out);
void outdec(char *p, FILE *f);
int fr(FILE *fd, char *buf, int cnt);
main(int argc, char *argv[])
{
FILE *in;
struct stat sbuf;
int mode;
/* optional 1st argument */
if (argc > 2)
{
#ifdef MSDOS
/* Use binary mode */
if ((in = fopen(argv[1], "rb")) == NULL)
{
#else
if ((in = fopen(argv[1], "r")) == NULL)
{
#endif
perror(argv[1]);
exit(1);
}
argv++; argc--;
}
else in = stdin;
if (argc != 2)
{
printf("Usage: uuencode [infile] remotefile\n");
exit(2);
}
/* figure out the input file mode */
fstat(fileno(in), &sbuf);
mode = sbuf.st_mode & 0777;
printf("begin %o %s\n", mode, argv[1]);
encode(in, stdout);
printf("end\n");
return 0;
}
/*
* copy from in to out, encoding as you go along.
*/
void encode(FILE *in, FILE *out)
{
char buf[80];
int i, n;
for (;;)
{
/* 1 (up to) 45 character line */
n = fr(in, buf, 45);
putc(ENC(n), out);
for (i = 0; i < n; i += 3)
outdec(&buf[i], out);
putc('\n', out);
if (n <= 0)
break;
}
}
/*
* output one group of 3 bytes, pointed at by p, on file f.
*/
void outdec(char *p, FILE *f)
{
int c1, c2, c3, c4;
c1 = *p >> 2;
c2 = ((p[0] > 4) & 017);
c3 = ((p[1] > 6) & 03);
c4 = p[2] & 077;
putc(ENC(c1), f);
putc(ENC(c2), f);
putc(ENC(c3), f);
putc(ENC(c4), f);
}
/* fr: like read but stdio */
int fr(FILE *fd, char *buf, int cnt)
{
int c, i;
for (i = 0; i < cnt; i++)
{
c = getc(fd);
if (c == EOF)
return(i);
buf[i] = (char)c;
}
return (cnt);
}
You should be able to figure out how to transliterate this into rexx.
loSmaH cha'
--- timEd-B9
* Origin: Until the People Come Home (1:283/120.1)SEEN-BY: 12/2442 620/243 624/50 632/348 640/820 690/660 711/409 410 413 430 SEEN-BY: 711/807 808 809 934 942 949 712/353 515 713/888 800/1 @PATH: 283/120 121 3615/50 229/2 12/2442 711/409 808 809 934 |
|
| SOURCE: echomail via fidonet.ozzmosis.com | |
Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.