Newsgroups: alt.os.linux
Subject: Re: uudecode
From: aclark@netcom.com (Al Clark)
Date: Mon, 06 Apr 92 01:34:29 GMT
Organization: Self

In article <1992Apr6.005012.10798@athena.mit.edu> Epstein@DOCKMASTER.NCSC.MIL writes:
>I was unable to decode digest18 and digest22 linux-0.95c patches using
>linux's uudecode.  I still have a Minix partition and uud which appears
>to work.  The trimmed digest18 had sum 12035 43 with 700 lines and
>digest22 had sum 41985 34 and 559 lines not counting the blank line
>following the end line.  torvalds didn't think there was any problem
>with the postings, the uudecode I was using was a binary gotten off of
>tsx-11 circa 0.12 --- probably compiled circa 0.10
>
>I guess it is time to recompile everything I have source for.  Minix did
>have a several month long discussion of the advantages to uud over
>uudecode.  Don't know whether this is relevant or if fact uudecode was
>compiled so long ago.

I used the uudecode.c below; compiled on linux .95a with gcc 1.40 with
no problems.  Also including uuencode.c for completeness; compiled but
I haven't tested it.
---------------------  uudecode.c ------------------
/* uudecode.c - convert ascii-encoded files back to their original form
 * Usage: uudecode [infile]
 *
 * This command differs from the regular UNIX one in that the embedded
 * file name "/dev/stdout" is recognized, allowing it to be used in a pipeline
 *
 * Written and placed in the public domain by Phil Karn, KA9Q 31 March 1987
 */
#include <stdio.h>
#define	LINELEN	80
#define index strchr   /* added by Al Clark for non-BSD */
#define	MAXREC	64
main(argc,argv)
int argc;
char *argv[];
{
	char linebuf[LINELEN],*index(),*fgets();
	register char *cp;
	register int linelen,i;
	FILE *in,*out;
	
	if(argc > 1){
		if((in = fopen(argv[1],"r")) == NULL){
			fprintf(stderr,"Can't read %s\n",argv[1]);
			exit(1);
		}
	} else
		in = stdin;

	/* Find begin line */
	while(fgets(linebuf,LINELEN,in) != NULL){
		if((cp = index(linebuf,'\n')) != NULL)
			*cp = '\0';
		if(strncmp(linebuf,"begin",5) == 0)
			break;
	}
	if(feof(in)){
		fprintf(stderr,"No begin found\n");
		exit(1);
	}
	/* Find beginning of file name */
	cp = &linebuf[6];
	if((cp = index(cp,' ')) != NULL)
		cp++;
	/* Set up output stream */
	if(cp == NULL || strcmp(cp,"/dev/stdout") == 0){
		out = stdout;
	} else if((out = fopen(cp,"w")) == NULL){
			fprintf(stderr,"Can't open %s\n",cp);
			exit(1);
	}
	/* Now crunch the input file */
	while(fgets(linebuf,LINELEN,in) != NULL){
		linelen = linebuf[0] - ' ';
		/* Some uuencodes put ` (64) instead of space (0) in the
		 * end-of-file record
		 */
		linelen &= 63;
		if(linelen == 0 || strncmp(linebuf,"end",3) == 0)
			break;
		for(cp = &linebuf[1];linelen > 0;cp += 4){
			for(i=0;i<4;i++){
				cp[i] -= ' ';
				cp[i] &= 63;
			}
			putc((cp[0] << 2) | ((cp[1] >> 4) & 0x3),out);
			if(--linelen > 0)
				putc((cp[1] << 4) | ((cp[2] >> 2) & 0xf),out);
			if(--linelen > 0)
				putc((cp[2] << 6) | cp[3],out);
			linelen--;
		}
	}
	fclose(out);
}
--------------------    uuencode.c ----------------------------------------
/* uuencode.c - convert files to ascii-encoded form
 * Usage: uuencode [filename] < infile
 *
 * If [filename] isn't specified, "/dev/stdout" is the default.  This allows
 * use of my uudecode as a pipeline filter.
 *
 * Written and placed in the public domain by Phil Karn, KA9Q
 * 31 March 1987
 */
#include <stdio.h>
#define	LINELEN	45
main(argc,argv)
int argc;
char *argv[];
{
	char linebuf[LINELEN];
	register char *cp;
	register int linelen;

	if(argc > 1)
		printf("begin 0666 %s\n",argv[1]);
	else
		printf("begin 0666 /dev/stdout\n");
	for(;;){
		linelen = fread(linebuf,1,LINELEN,stdin);
		if(linelen <= 0)
			break;
		putchar(' ' + linelen);	/* Record length */
		for(cp = linebuf; cp < &linebuf[linelen]; cp += 3){
			putchar(' ' + ((cp[0] >> 2) & 0x3f));
			putchar(' ' + (((cp[0] << 4) & 0x30) | ((cp[1] >> 4) & 0xf)));
			putchar(' ' + (((cp[1] << 2) & 0x3c) | ((cp[2] >> 6) & 0x3)));
			putchar(' ' + (cp[2] & 0x3f));
		}
		putchar('\n');
	}
	printf(" \n");	/* 0-length null record */
	printf("end\n");
}
-- 
Al - aclark@netcom.com - My opinions are my own.
      *** Practice random kindness and senseless acts of beauty! ***

Xref: sparky alt.os.linux:2279 comp.os.linux:174