Add sum(1) alias, per Matt Green. Various other cleanup. Someone should

finish the addition to the HISTORY section.
This commit is contained in:
mycroft 1995-01-15 06:43:49 +00:00
parent 73c9e168bf
commit 92702177a0
3 changed files with 48 additions and 20 deletions

View File

@ -1,7 +1,9 @@
# from: @(#)Makefile 8.1 (Berkeley) 6/6/93
# $Id: Makefile,v 1.3 1993/11/02 07:33:08 cgd Exp $
# $Id: Makefile,v 1.4 1995/01/15 06:43:49 mycroft Exp $
PROG= cksum
SRCS= cksum.c crc.c print.c sum1.c sum2.c
LINKS= ${BINDIR}/cksum ${BINDIR}/sum
MLINKS= cksum.1 sum.1
.include <bsd.prog.mk>

View File

@ -33,7 +33,7 @@
.\" SUCH DAMAGE.
.\"
.\" from: @(#)cksum.1 8.1 (Berkeley) 6/29/93
.\" $Id: cksum.1,v 1.5 1994/05/20 06:14:31 jtc Exp $
.\" $Id: cksum.1,v 1.6 1995/01/15 06:43:51 mycroft Exp $
.\"
.Dd June 29, 1993
.Dt CKSUM 1
@ -45,6 +45,8 @@
.Nm cksum
.Op Fl o Ar \&1 No \&| Ar \&2
.Op Ar file ...
.Nm sum
.Op Ar file ...
.Sh DESCRIPTION
The
.Nm cksum
@ -56,6 +58,14 @@ the total number of octets in the file and the file name.
If no file name is specified, the standard input is used and no file name
is written.
.Pp
The
.Nm sum
utility is identical to the
.Nm cksum
utility, except that it defaults to using historic algorithm 1, as
described below. It is provided for compatibility only, and should not
be used by new programs.
.Pp
The options are as follows:
.Bl -tag -width indent
.It Fl o
@ -142,7 +152,9 @@ The bit sequence is complemented and the result is the CRC.
.Pp
The
.Nm cksum
utility exits 0 on success, and >0 if an error occurs.
and
.Nm sum
utilities exit 0 on success, and >0 if an error occurs.
.Sh SEE ALSO
The default calculation is identical to that given in pseudo-code
in the following
@ -162,5 +174,12 @@ utility is expected to conform to
.Sh HISTORY
The
.Nm cksum
utility appears in
utility appeared in
.Bx 4.4 .
.\" .Pp
.\" The
.\" .Nm sum
.\" utility appeared in
.\" .Bx ?.?
.\" and
.\" .At V .

View File

@ -42,17 +42,20 @@ static char copyright[] =
#ifndef lint
/* from: static char sccsid[] = "@(#)cksum.c 8.1 (Berkeley) 6/6/93"; */
static char *rcsid = "$Id: cksum.c,v 1.4 1994/12/24 16:02:45 cgd Exp $";
static char *rcsid = "$Id: cksum.c,v 1.5 1995/01/15 06:43:52 mycroft Exp $";
#endif /* not lint */
#include <sys/cdefs.h>
#include <sys/types.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdio.h>
#include <err.h>
#include <errno.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include "extern.h"
void usage __P((void));
@ -62,27 +65,32 @@ main(argc, argv)
int argc;
char **argv;
{
extern int optind;
u_int32_t len, val;
register int ch, fd, rval;
char *fn;
int (*cfncn) __P((int, u_int32_t *, u_int32_t *));
void (*pfncn) __P((char *, u_int32_t, u_int32_t));
extern char *__progname;
cfncn = crc;
pfncn = pcrc;
while ((ch = getopt(argc, argv, "o:")) != EOF)
if (!strcmp(__progname, "sum")) {
cfncn = csum1;
pfncn = psum1;
} else {
cfncn = crc;
pfncn = pcrc;
}
while ((ch = getopt(argc, argv, "o:")) != -1)
switch(ch) {
case 'o':
if (*optarg == '1') {
if (!strcmp(optarg, "1")) {
cfncn = csum1;
pfncn = psum1;
} else if (*optarg == '2') {
} else if (!strcmp(optarg, "2")) {
cfncn = csum2;
pfncn = psum2;
} else {
(void)fprintf(stderr,
"cksum: illegal argument to -o option\n");
warnx("illegal argument to -o option");
usage();
}
break;
@ -100,15 +108,13 @@ main(argc, argv)
if (*argv) {
fn = *argv++;
if ((fd = open(fn, O_RDONLY, 0)) < 0) {
(void)fprintf(stderr, "cksum: %s: %s\n",
fn, strerror(errno));
warn("%s", fn);
rval = 1;
continue;
}
}
if (cfncn(fd, &val, &len)) {
(void)fprintf(stderr, "cksum: %s: %s\n",
fn ? fn : "stdin", strerror(errno));
warn("%s", fn ? fn : "stdin");
rval = 1;
} else
pfncn(fn, val, len);
@ -120,6 +126,7 @@ main(argc, argv)
void
usage()
{
(void)fprintf(stderr, "usage: cksum [-o 1 | 2] [file ...]\n");
exit(1);
}