[comp.sys.hp] Where can I find uuencode

ghewes@bbn.com (Gerald Hewes) (02/13/91)

 I was surprised that uuencode, uudecode is not shipped
on HPUX (or I did not find it on my system). I recall these
are two tiny programs but where could I find the source?
 If source is unavalable HP9000s300 (or 400) and HP9000s800
binaries would be fine.


-------------------------------------------------------------------------------
Gerald T. Hewes  (ghewes@bbn.com)        XMMMMMMMMMX
BBN SPC                                  XMM  |  MMX [Watch Your Step]
150 CambridgePark Drive                  XM .o|o. MX [Low Ceiling    ]
Cambridge MA 02140                   MMMMMM . | . MMMMMM
-------------------------------~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~--------------

-------------------------------------------------------------------------------
Gerald T. Hewes  (ghewes@bbn.com)        XMMMMMMMMMX
BBN SPC                                  XMM  |  MMX [Watch Your Step]
150 CambridgePark Drive                  XM .o|o. MX [Low Ceiling    ]
Cambridge MA 02140                   MMMMMM . | . MMMMMM
-------------------------------~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~--------------

milburn@me10.lbl.gov (John Milburn) (02/15/91)

In article <62703@bbn.BBN.COM> ghewes@BBN.COM () writes:

> I was surprised that uuencode, uudecode is not shipped
>on HPUX (or I did not find it on my system). I recall these
>are two tiny programs but where could I find the source?
> If source is unavalable HP9000s300 (or 400) and HP9000s800
>binaries would be fine.

I have made the binaries available on me10.lbl.gov as pub/uuenc_300.tar.Z .

These are binaries of uuencode and uudecode known to work on the
s300 and s400 machines.

-jem
-- 
JEMilburn@lbl.gov  ...!ucbvax!lbl.gov!JEMilburn

"I don't sing, I don't dance, and I don't like people who do."  -Leterman

billk@hpsad.HP.COM (Bill Katz) (02/16/91)

	While uuencode and uudecode are not explicitely included in HPUX (at
least I can't find them on my system either) their functionality is included
in shar(1), which is in my 6.5 manual.  Shar any binary file, and the C source
code for uudecode will be in the archive.  At the same time the file will be
uuencoded.  I hope this helps.

Disclaimer:
I'm not an official spokesman for Hewlett-Packard, I just work on Spectrum
Analyzers.

______________________________________________________________________________

   _   /| 	-ACK!        Bill (the) Katz     Internet: billk@hpsad.hp.com
   \'o.O'	-PFHHHT!     Hewlett-Packard         UUCP: hplabs!hpsad!billk
   =(___)=	-COUGH!      Signal Analysis Div.   Phone: (707) 794-2300
      U		-ACK!	     1212 Valley House Dr.    Fax: (707) 794-4452
			     Rohnert Park, CA 95428
______________________________________________________________________________

den@hpfcso.FC.HP.COM (Don Novy) (02/16/91)

  I emailed source files for uudecode and uuencode, along with some 
documentation to Gerald.

Don Novy
don_novy@fc.hp.com

jewett@hpl-opus.hpl.hp.com (Bob Jewett) (02/16/91)

If you have access to a news archive, look in net.unix in July 1985 (under
"Re: Ken Arnold Curses "primer"...")  Otherwise, send me mail.

Bob

guy@hpgnd.grenoble.hp.com (Guy DUBRISAY) (02/22/91)

This will resolve your need ...


############################ uuencode ##########################################
/*
 *
 * Uuencode -- encode a file so that it's printable ascii, short lines
 *
 * Slightly modified from a version posted to net.sources a while back,
 * and suitable for compilation on the IBM PC
 *
 * modified for Lattice C on the ST - 11.05.85 by MSD
 * modified for ALCYON on the ST -    10-24-86 by RDR
 * modified a little more for MWC...  02/09/87 by JPHD
 * (An optional first argument of the form: -nnumber (e.g. -500), will
 * produce a serie of files that long, linked by the include statement,
 * such files are automatically uudecoded by the companion program.)
 * More mods, - ...		   05/06/87 by jphd
 * Mods for TOPS 20, and more.     08/06/87 by jphd
 *     (remove freopen and rindex...change filename generation...)
 * (A lot more to do about I/O speed, avoiding completely the stdio.h...)
 *
 */


#include <stdio.h>
#include <ctype.h>

#define USAGE 

/* ENC is the basic 1 character encoding function to make a char printing */
#define ENC(c) (((c) & 077) + ' ')

extern FILE  *fopen();
FILE *fp, *outp;
char ofname[80];
int lenofname;
int stdo = 0;

#ifdef ST
#define READ "rb"
#else
#define READ "r"
#endif

int part = 'a', chap = 'a';
#define SEQMAX 'z'
#define SEQMIN 'a'
char seqc = SEQMAX;

int split = 0; fileln = 32000;

main(argc, argv)
int argc; char *argv[];
{
	char *fname;

	if (argc < 2) {
		usage();
		exit(2);
		}
	if (argv[1][0] == '-') {
		fileln = -atoi(argv[1]);
		if (fileln <= 0) {
			fprintf(stderr, "Wrong file length arg.\n");
			exit();
		}
		split = 1;
		argv++;
		argc--;
	}
	if ((fp=fopen(argv[1], READ))==NULL) {  /* binary input !!! */
		fprintf(stderr,"Cannot open %s\n",argv[1]);
		exit(1);
	}
	strcpy(ofname, argv[1]);
	fname = ofname;
	do {
		if (*fname == '.')
			*fname = '\0';
	} while (*fname++);
		/* 8 char prefix + .uue -> 12 chars MAX */
	lenofname = strlen(ofname);
	if (lenofname > 8) ofname[8] = '\0';
	strcat(ofname,".uue");
	lenofname = strlen(ofname);
	if (!split && (argc > 2) && (argv[2][0] == '-')) {
		stdo = 1;
		outp = stdout;
	 } else {
		 makename();
		 if((outp = fopen(ofname, "w")) == NULL) {
			 fprintf(stderr,"Cannot open %s\n", ofname);
			 exit(1);
			 }
	}
	maketable();
	fprintf(outp,"begin %o %s\n", 0644, argv[1]);
	encode();
	fprintf(outp,"end\n");
	fclose(outp);
	exit(0);
}

/* create ASCII table so a mailer can screw it up and the decode
 * program can restore the error.
 */
maketable()
{
	register int i, j;

	fputs("table\n", outp);
	for(i = ' ', j = 0; i < '`' ; j++) {
		if (j == 32)
			putc('\n', outp);
		fputc(i++, outp);
	}
	putc('\n', outp);
}

/*
 * Generate the names needed for single and multiple part encoding.
 */
makename()
{
	if (split) {
		ofname[lenofname - 1] = part;
		ofname[lenofname - 2] = chap;
	}
}

/*
 * copy from in to out, encoding as you go along.
 */
encode()
{
	char buf[80];
	register int i, n;
	register int lines;
	lines = 6;

	for (;;) {
		n = fr(buf, 45);
		putc(ENC(n), outp);
		for (i = 0; i < n; i += 3)
		      outdec(&buf[i]);
		putc(seqc, outp);
		seqc--;
		if (seqc < SEQMIN) seqc = SEQMAX;
		putc('\n', outp);
		++lines;
		if (split && (lines > fileln)) {
			part++;
			if (part > 'z') {
				part = 'a';
				if (chap == 'z')
					chap = 'a'; /* loop ... */
				else
					chap++;
			}
			makename();
			fprintf(outp,"include %s\n",ofname);
			fclose(outp);
			if((outp = fopen(ofname, "w")) == NULL) {
				fprintf(stderr,"Cannot open %s\n",ofname);
				exit(1);
			}
			maketable();
			fprintf(outp,"begin part %c %s\n",part,ofname);
			lines = 6;
		}
		if (n <= 0)
			break;
	}
}

/*
 * output one group of 3 bytes, pointed at by p, on file f.
 */
outdec(p)
register char *p;
{
	register int c1, c2, c3, c4;

	c1 = *p >> 2;
	c2 = (*p << 4) & 060 | (p[1] >> 4) & 017;
	c3 = (p[1] << 2) & 074 | (p[2] >> 6) & 03;
	c4 = p[2] & 077;
	putc(ENC(c1), outp);
	putc(ENC(c2), outp);
	putc(ENC(c3), outp);
	putc(ENC(c4), outp);
}

/* fr: like read but stdio */
int fr(buf, cnt)
register char *buf;
register int cnt;
{
	register int c, i;
	for (i = 0; i < cnt; i++) {
		c = fgetc(fp);
		if (feof(fp))
			return(i);
		buf[i] = c;
	}
	return (cnt);
}

usage()
{
  fprintf(stderr, "Almost foolproof uuencode v3.1 06 Aug 1987\n");
  fprintf(stderr, "Usage: uuencode [-n] inputfile [-]\n");
  fprintf(stderr,
	"SHORT DESCRIPTION\n\
	An optional first argument of the form: -number (e.g. -500),\n\
	will produce a series of files that number of lines long, linked\n\
	by the include statement. The default for 'number' is %d.\n\
	Files produced like this are automatically uudecoded by the\n\
	companion program UUD.\n\
	If a '-' is given as the last argument, output is redirected\n\
	to the standard output.\n", fileln);
}



############################ uudecode ##########################################
/* uudecode.c */

#ifndef lint
static char sccsid[] = "@(#)uudecode.c	5.1 (Berkeley) 7/2/83";
#endif

/*
 * uudecode [input]
 *
 * create the specified file, decoding as you go.
 * used with uuencode.
 */
#include <stdio.h>
#ifndef MSDOS
#include <pwd.h>
#endif
#include <sys/types.h>
#include <sys/stat.h>

/* single character decode */
#define DEC(c)	(((c) - ' ') & 077)

main(argc, argv)
char **argv;
{
	FILE *in, *out;
	struct stat sbuf;
	int mode;
	char dest[128];
	char buf[80];

	/* optional input arg */
	if (argc > 1) {
		if ((in = fopen(argv[1], "r")) == NULL) {
			perror(argv[1]);
			exit(1);
		}
		argv++; argc--;
	} else
		in = stdin;

	if (argc != 1) {
		printf("Usage: uudecode [infile]\n");
		exit(2);
	}

	/* search for header line */
	for (;;) {
		if (fgets(buf, sizeof buf, in) == NULL) {
			fprintf(stderr, "No begin line\n");
			exit(3);
		}
		if (strncmp(buf, "begin ", 6) == 0)
			break;
	}
	sscanf(buf, "begin %o %s", &mode, dest);

	/* handle ~user/file format */
#ifndef MSDOS
	if (dest[0] == '~') {
		char *sl;
		struct passwd *getpwnam();
		char *index();
		struct passwd *user;
		char dnbuf[100];

		sl = index(dest, '/');
		if (sl == NULL) {
			fprintf(stderr, "Illegal ~user\n");
			exit(3);
		}
		*sl++ = 0;
		user = getpwnam(dest+1);
		if (user == NULL) {
			fprintf(stderr, "No such user as %s\n", dest);
			exit(4);
		}
		strcpy(dnbuf, user->pw_dir);
		strcat(dnbuf, "/");
		strcat(dnbuf, sl);
		strcpy(dest, dnbuf);
	}
#endif

	/* create output file */
#ifdef MSDOS
	/* binary output file */
	out = fopen(dest, "wb");
#else
	out = fopen(dest, "w");
#endif
	if (out == NULL) {
		perror(dest);
		exit(4);
	}
	chmod(dest, mode);

	decode(in, out);

	if (fgets(buf, sizeof buf, in) == NULL || strcmp(buf, "end\n")) {
		fprintf(stderr, "No end line\n");
		exit(5);
	}
	exit(0);
}

/*
 * copy from in to out, decoding as you go along.
 */
decode(in, out)
FILE *in;
FILE *out;
{
	char buf[80];
	char *bp;
	int n;

	for (;;) {
		/* for each input line */
		if (fgets(buf, sizeof buf, in) == NULL) {
			printf("Short file\n");
			exit(10);
		}
		n = DEC(buf[0]);
		if (n <= 0)
			break;

		bp = &buf[1];
		while (n > 0) {
			outdec(bp, out, n);
			bp += 4;
			n -= 3;
		}
	}
}

/*
 * output a group of 3 bytes (4 input characters).
 * the input chars are pointed to by p, they are to
 * be output to file f.  n is used to tell us not to
 * output all of them at the end of the file.
 */
outdec(p, f, n)
char *p;
FILE *f;
{
	int c1, c2, c3;

	c1 = DEC(*p) << 2 | DEC(p[1]) >> 4;
	c2 = DEC(p[1]) << 4 | DEC(p[2]) >> 2;
	c3 = DEC(p[2]) << 6 | DEC(p[3]);
	if (n >= 1)
		putc(c1, f);
	if (n >= 2)
		putc(c2, f);
	if (n >= 3)
		putc(c3, f);
}


/* fr: like read but stdio */
int
fr(fd, buf, cnt)
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] = c;
	}
	return (cnt);
}

/*
 * Return the ptr in sp at which the character c appears;
 * NULL if not found
 */

#define	NULL	0

char *
index(sp, c)
register char *sp, c;
{
	do {
		if (*sp == c)
			return(sp);
	} while (*sp++);
	return(NULL);
}