Merge branch 'uuencode' of https://github.com/sinetek/retrobsd into sinetek-uuencode

This commit is contained in:
Sergey
2015-07-04 19:14:06 -07:00
10 changed files with 623 additions and 6 deletions

View File

@@ -1288,6 +1288,7 @@ file /share/man/cat1/units.0
file /share/man/cat1/uptime.0 file /share/man/cat1/uptime.0
file /share/man/cat1/users.0 file /share/man/cat1/users.0
file /share/man/cat1/uucp.0 file /share/man/cat1/uucp.0
file /share/man/cat1/uuencode.0
file /share/man/cat1/uulog.0 file /share/man/cat1/uulog.0
file /share/man/cat1/uuname.0 file /share/man/cat1/uuname.0
file /share/man/cat1/uuq.0 file /share/man/cat1/uuq.0

View File

@@ -11,13 +11,13 @@ CFLAGS += -Werror
# Programs that live in subdirectories, and have makefiles of their own. # Programs that live in subdirectories, and have makefiles of their own.
# /bin # /bin
SUBDIR = adb adc-demo aout ar as awk basic calendar cc chflags \ SUBDIR = adb adc-demo aout ar as awk basic calendar cc chflags \
chpass cpp dc diff emg env fdisk find fold forth fstat \ chpass cpp dc devupdate diff emg env fdisk find fold forth \
glcdtest hostname id la lcc lcpp ld ls login make man \ fstat glcdtest hostname id la lcc lcpp ld ls login make \
md5 med more nm passwd picoc portio printf pwm \ man md5 med more nm passwd picoc portio printf pwm \
ranlib re renice retroforth scm setty sl \ ranlib re renice retroforth scm sed setty sh sl smallc \
sed sh smallc smlrc stty sysctl test uname wiznet xargs \ smlrc smux stty sysctl test uname wiznet xargs \
zmodem gtest msec unixbench cron compress date2 tip \ zmodem gtest msec unixbench cron compress date2 tip \
talloc devupdate uucp smux fold talloc uucp uudecode uuencode
# /sbin # /sbin
SUBDIR += chown chroot disktool fsck getty init \ SUBDIR += chown chroot disktool fsck getty init \

1
src/cmd/uudecode/.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
uudecode

32
src/cmd/uudecode/Makefile Normal file
View File

@@ -0,0 +1,32 @@
TOPSRC = $(shell cd ../../..; pwd)
include $(TOPSRC)/target.mk
CFLAGS = -O
SRCS = uudecode.c
OBJS = uudecode.o
all: uudecode
uudecode: ${OBJS}
${CC} ${LDFLAGS} -o uudecode.elf ${OBJS} ${LIBS}
${OBJDUMP} -S uudecode.elf > uudecode.dis
${SIZE} uudecode.elf
${ELF2AOUT} uudecode.elf $@ && rm uudecode.elf
clean:
rm -f *.o uudecode uudecode.elf uudecode.dis tags *~ uudecode.0
depend: ${SRCS}
mkdep ${CFLAGS} ${SRCS}
install: all
install uudecode ${DESTDIR}/bin/uudecode
lint: ${SRCS}
lint -hax ${SRCS}
tags: ${SRCS}
ctags ${SRCS}
# DO NOT DELETE THIS LINE -- mkdep uses it.
# DO NOT PUT ANYTHING AFTER THIS LINE, IT WILL GO AWAY.

187
src/cmd/uudecode/uudecode.c Normal file
View File

@@ -0,0 +1,187 @@
/*-
* Copyright (c) 1983, 1993
* The Regents of the University of California. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#ifndef lint
char copyright[] =
"@(#) Copyright (c) 1983, 1993\n\
The Regents of the University of California. All rights reserved.\n";
#endif /* not lint */
#ifndef lint
static char sccsid[] = "@(#)uudecode.c 8.2 (Berkeley) 4/2/94";
#endif /* not lint */
/*
* uudecode [file ...]
*
* create the specified file, decoding as you go.
* used with uuencode.
*/
#include <sys/param.h>
#include <sys/stat.h>
#include <pwd.h>
#include <stdio.h>
#include <string.h>
char *filename;
int
main(argc, argv)
int argc;
char *argv[];
{
extern int errno;
int rval;
if (*++argv) {
rval = 0;
do {
if (!freopen(filename = *argv, "r", stdin)) {
(void)fprintf(stderr, "uudecode: %s: %s\n",
*argv, strerror(errno));
rval = 1;
continue;
}
rval |= decode();
} while (*++argv);
} else {
filename = "stdin";
rval = decode();
}
exit(rval);
}
decode()
{
extern int errno;
struct passwd *pw;
register int n;
register char ch, *p;
int mode, n1;
char buf[MAXPATHLEN];
/* search for header line */
do {
if (!fgets(buf, sizeof(buf), stdin)) {
(void)fprintf(stderr,
"uudecode: %s: no \"begin\" line\n", filename);
return(1);
}
} while (strncmp(buf, "begin ", 6));
(void)sscanf(buf, "begin %o %s", &mode, buf);
/* handle ~user/file format */
if (buf[0] == '~') {
if (!(p = index(buf, '/'))) {
(void)fprintf(stderr, "uudecode: %s: illegal ~user.\n",
filename);
return(1);
}
*p++ = NULL;
if (!(pw = getpwnam(buf + 1))) {
(void)fprintf(stderr, "uudecode: %s: no user %s.\n",
filename, buf);
return(1);
}
n = strlen(pw->pw_dir);
n1 = strlen(p);
if (n + n1 + 2 > MAXPATHLEN) {
(void)fprintf(stderr, "uudecode: %s: path too long.\n",
filename);
return(1);
}
bcopy(p, buf + n + 1, n1 + 1);
bcopy(pw->pw_dir, buf, n);
buf[n] = '/';
}
/* create output file, set mode */
if (!freopen(buf, "w", stdout) ||
fchmod(fileno(stdout), mode&0666)) {
(void)fprintf(stderr, "uudecode: %s: %s: %s\n", buf,
filename, strerror(errno));
return(1);
}
/* for each input line */
for (;;) {
if (!fgets(p = buf, sizeof(buf), stdin)) {
(void)fprintf(stderr, "uudecode: %s: short file.\n",
filename);
return(1);
}
#define DEC(c) (((c) - ' ') & 077) /* single character decode */
/*
* `n' is used to avoid writing out all the characters
* at the end of the file.
*/
if ((n = DEC(*p)) <= 0)
break;
for (++p; n > 0; p += 4, n -= 3)
if (n >= 3) {
ch = DEC(p[0]) << 2 | DEC(p[1]) >> 4;
putchar(ch);
ch = DEC(p[1]) << 4 | DEC(p[2]) >> 2;
putchar(ch);
ch = DEC(p[2]) << 6 | DEC(p[3]);
putchar(ch);
}
else {
if (n >= 1) {
ch = DEC(p[0]) << 2 | DEC(p[1]) >> 4;
putchar(ch);
}
if (n >= 2) {
ch = DEC(p[1]) << 4 | DEC(p[2]) >> 2;
putchar(ch);
}
if (n >= 3) {
ch = DEC(p[2]) << 6 | DEC(p[3]);
putchar(ch);
}
}
}
if (!fgets(buf, sizeof(buf), stdin) || strcmp(buf, "end\n")) {
(void)fprintf(stderr, "uudecode: %s: no \"end\" line.\n",
filename);
return(1);
}
return(0);
}
usage()
{
(void)fprintf(stderr, "usage: uudecode [file ...]\n");
exit(1);
}

1
src/cmd/uuencode/.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
uuencode

38
src/cmd/uuencode/Makefile Normal file
View File

@@ -0,0 +1,38 @@
TOPSRC = $(shell cd ../../..; pwd)
include $(TOPSRC)/target.mk
CFLAGS = -O
SRCS = uuencode.c
OBJS = uuencode.o
MAN = uuencode.0
MANSRC = uuencode.1
all: uuencode $(MAN)
uuencode: ${OBJS}
${CC} ${LDFLAGS} -o uuencode.elf ${OBJS} ${LIBS}
${OBJDUMP} -S uuencode.elf > uuencode.dis
${SIZE} uuencode.elf
${ELF2AOUT} uuencode.elf $@ && rm uuencode.elf
$(MAN): ${MANSRC}
${MANROFF} $< > $@
clean:
rm -f *.o uuencode uuencode.elf uuencode.dis tags *~ uuencode.0
depend: ${SRCS}
mkdep ${CFLAGS} ${SRCS}
install: all
install uuencode ${DESTDIR}/bin/uuencode
cp ${MAN} ${DESTDIR}/share/man/cat1/
lint: ${SRCS}
lint -hax ${SRCS}
tags: ${SRCS}
ctags ${SRCS}
# DO NOT DELETE THIS LINE -- mkdep uses it.
# DO NOT PUT ANYTHING AFTER THIS LINE, IT WILL GO AWAY.

105
src/cmd/uuencode/uuencode.1 Normal file
View File

@@ -0,0 +1,105 @@
.\" Copyright (c) 1980, 1990, 1993
.\" The Regents of the University of California. All rights reserved.
.\"
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
.\" are met:
.\" 1. Redistributions of source code must retain the above copyright
.\" notice, this list of conditions and the following disclaimer.
.\" 2. Redistributions in binary form must reproduce the above copyright
.\" notice, this list of conditions and the following disclaimer in the
.\" documentation and/or other materials provided with the distribution.
.\" 3. All advertising materials mentioning features or use of this software
.\" must display the following acknowledgement:
.\" This product includes software developed by the University of
.\" California, Berkeley and its contributors.
.\" 4. Neither the name of the University nor the names of its contributors
.\" may be used to endorse or promote products derived from this software
.\" without specific prior written permission.
.\"
.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
.\" @(#)uuencode.1 8.1 (Berkeley) 6/6/93
.\"
.Dd June 6, 1993
.Dt UUENCODE 1
.Os BSD 4
.Sh NAME
.Nm uuencode ,
.Nm uudecode
.Nd encode/decode a binary file
.Sh SYNOPSIS
.Nm uuencode
.Op Ar file
.Ar name
.Nm uudecode
.Op Ar file ...
.Sh DESCRIPTION
.Nm Uuencode
and
.Nm uudecode
are used to transmit binary files over transmission mediums
that do not support other than simple
.Tn ASCII
data.
.Pp
.Nm Uuencode
reads
.Ar file
(or by default the standard input) and writes an encoded version
to the standard output.
The encoding uses only printing
.Tn ASCII
characters and includes the
mode of the file and the operand
.Ar name
for use by
.Nm uudecode .
.Pp
.Nm Uudecode
transforms
.Em uuencoded
files (or by default, the standard input) into the original form.
The resulting file is named
.Ar name
and will have the mode of the original file except that setuid
and execute bits are not retained.
.Nm Uudecode
ignores any leading and trailing lines.
.Sh EXAMPLES
The following example packages up a source tree, compresses it,
uuencodes it and mails it to a user on another system.
When
.Nm uudecode
is run on the target system, the file ``src_tree.tar.Z'' will be
created which may then be uncompressed and extracted into the original
tree.
.Pp
.Bd -literal -offset indent -compact
tar cf \- src_tree \&| compress \&|
uuencode src_tree.tar.Z \&| mail sys1!sys2!user
.Ed
.Sh SEE ALSO
.Xr compress 1 ,
.Xr mail 1 ,
.Xr uucp 1 ,
.Xr uuencode 5 ,
.Xr format 5
.Sh BUGS
The encoded form of the file is expanded by 35% (3 bytes become 4 plus
control information).
.Sh HISTORY
The
.Nm
command appeared in
.Bx 4.0 .

150
src/cmd/uuencode/uuencode.c Normal file
View File

@@ -0,0 +1,150 @@
/*-
* Copyright (c) 1983, 1993
* The Regents of the University of California. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#ifndef lint
char copyright[] =
"@(#) Copyright (c) 1983, 1993\n\
The Regents of the University of California. All rights reserved.\n";
#endif /* not lint */
#ifndef lint
static char sccsid[] = "@(#)uuencode.c 8.2 (Berkeley) 4/2/94";
#endif /* not lint */
/*
* uuencode [input] output
*
* Encode a file so it can be mailed to a remote system.
*/
#include <sys/types.h>
#include <sys/stat.h>
#include <stdio.h>
int
main(argc, argv)
int argc;
char *argv[];
{
extern int optind;
extern int errno;
struct stat sb;
int mode;
char *strerror();
while (getopt(argc, argv, "") != EOF)
usage();
argv += optind;
argc -= optind;
switch(argc) {
case 2: /* optional first argument is input file */
if (!freopen(*argv, "r", stdin) || fstat(fileno(stdin), &sb)) {
(void)fprintf(stderr, "uuencode: %s: %s.\n",
*argv, strerror(errno));
exit(1);
}
#define RWX (S_IRWXU|S_IRWXG|S_IRWXO)
mode = sb.st_mode & RWX;
++argv;
break;
case 1:
#define RW (S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH)
mode = RW & ~umask(RW);
break;
case 0:
default:
usage();
}
(void)printf("begin %o %s\n", mode, *argv);
encode();
(void)printf("end\n");
if (ferror(stdout)) {
(void)fprintf(stderr, "uuencode: write error.\n");
exit(1);
}
exit(0);
}
/* ENC is the basic 1 character encoding function to make a char printing */
#define ENC(c) ((c) ? ((c) & 077) + ' ': '`')
/*
* copy from in to out, encoding as you go along.
*/
encode()
{
register int ch, n;
register char *p;
char buf[80];
while (n = fread(buf, 1, 45, stdin)) {
ch = ENC(n);
if (putchar(ch) == EOF)
break;
for (p = buf; n > 0; n -= 3, p += 3) {
ch = *p >> 2;
ch = ENC(ch);
if (putchar(ch) == EOF)
break;
ch = (*p << 4) & 060 | (p[1] >> 4) & 017;
ch = ENC(ch);
if (putchar(ch) == EOF)
break;
ch = (p[1] << 2) & 074 | (p[2] >> 6) & 03;
ch = ENC(ch);
if (putchar(ch) == EOF)
break;
ch = p[2] & 077;
ch = ENC(ch);
if (putchar(ch) == EOF)
break;
}
if (putchar('\n') == EOF)
break;
}
if (ferror(stdin)) {
(void)fprintf(stderr, "uuencode: read error.\n");
exit(1);
}
ch = ENC('\0');
(void)putchar(ch);
(void)putchar('\n');
}
usage()
{
(void)fprintf(stderr,"usage: uuencode [infile] remotefile\n");
exit(1);
}

View File

@@ -0,0 +1,102 @@
.\" Copyright (c) 1989, 1991, 1993
.\" The Regents of the University of California. All rights reserved.
.\"
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
.\" are met:
.\" 1. Redistributions of source code must retain the above copyright
.\" notice, this list of conditions and the following disclaimer.
.\" 2. Redistributions in binary form must reproduce the above copyright
.\" notice, this list of conditions and the following disclaimer in the
.\" documentation and/or other materials provided with the distribution.
.\" 3. All advertising materials mentioning features or use of this software
.\" must display the following acknowledgement:
.\" This product includes software developed by the University of
.\" California, Berkeley and its contributors.
.\" 4. Neither the name of the University nor the names of its contributors
.\" may be used to endorse or promote products derived from this software
.\" without specific prior written permission.
.\"
.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
.\" @(#)uuencode.format.5 8.2 (Berkeley) 1/12/94
.\"
.Dd January 12, 1994
.Dt UUENCODE 5
.Os BSD 4
.Sh NAME
.Nm uuencode
.Nd format of an encoded uuencode file
.Sh DESCRIPTION
Files output by
.Xr uuencode 1
consist of a header line,
followed by a number of body lines,
and a trailer line.
The
.Xr uudecode 1
command
will ignore any lines preceding the header or
following the trailer.
Lines preceding a header must not, of course,
look like a header.
.Pp
The header line is distinguished by having the first
6 characters
.Dq begin\ \&
(note the trailing space).
The word
.Em begin
is followed by a mode (in octal),
and a string which names the remote file.
A space separates the three items in the header line.
.Pp
The body consists of a number of lines, each at most 62 characters
long (including the trailing newline).
These consist of a character count,
followed by encoded characters,
followed by a newline.
The character count is a single printing character,
and represents an integer, the number of bytes
the rest of the line represents.
Such integers are always in the range from 0 to 63 and can
be determined by subtracting the character space (octal 40)
from the character.
.Pp
Groups of 3 bytes are stored in 4 characters, 6 bits per character.
All are offset by a space to make the characters printing.
The last line may be shorter than the normal 45 bytes.
If the size is not a multiple of 3, this fact can be determined
by the value of the count on the last line.
Extra garbage will be included to make the character count a multiple
of 4.
The body is terminated by a line with a count of zero.
This line consists of one
.Tn ASCII
space.
.Pp
The trailer line consists of
.Dq end
on a line by itself.
.Sh SEE ALSO
.Xr uuencode 1 ,
.Xr uudecode 1 ,
.Xr uusend 1 ,
.Xr uucp 1 ,
.Xr mail 1
.Sh HISTORY
The
.Nm uuencode
file format appeared in
.Bx 4.0 .
.\" It was named uuencode.5 prior to 4.3