* Copyright (c) 1983 Regents of the University of California.
* Redistribution and use in source and binary forms are permitted
* provided that the above copyright notice and this paragraph are
* duplicated in all such forms and that any documentation,
* advertising materials, and other materials related to such
* distribution and use acknowledge that the software was developed
* by the University of California, Berkeley. The name of the
* University may not be used to endorse or promote products derived
* from this software without specific prior written permission.
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
static char sccsid
[] = "@(#)uudecode.c 5.4 (Berkeley) %G%";
* create the specified file, decoding as you go.
/* single character decode */
#define DEC(c) (((c) - ' ') & 077)
if ((in
= fopen(argv
[1], "r")) == NULL
) {
printf("Usage: uudecode [infile]\n");
/* search for header line */
if (fgets(buf
, sizeof buf
, in
) == NULL
) {
fprintf(stderr
, "No begin line\n");
if (strncmp(buf
, "begin ", 6) == 0)
sscanf(buf
, "begin %o %s", &mode
, dest
);
/* handle ~user/file format */
struct passwd
*getpwnam();
fprintf(stderr
, "Illegal ~user\n");
fprintf(stderr
, "No such user as %s\n", dest
);
strcpy(dnbuf
, user
->pw_dir
);
if (fgets(buf
, sizeof buf
, in
) == NULL
|| strcmp(buf
, "end\n")) {
fprintf(stderr
, "No end line\n");
* copy from in to out, decoding as you go along.
/* for each input line */
if (fgets(buf
, sizeof buf
, in
) == NULL
) {
* 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.
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]);
/* fr: like read but stdio */
* Return the ptr in sp at which the character c appears;