commit 43b8fa1a5820506dbf4cd49146b6f57a6de6e701
parent b55de3d1a257d5e0232e081e402532ef68fcedaf
Author: FRIGN <dev@frign.de>
Date: Sat, 17 Jan 2015 23:38:38 +0100
Add mandoc-manpage for cksum(1) and clean up code
and mark it as done in README.
Diffstat:
M | README | | | 2 | +- |
M | cksum.1 | | | 36 | +++++++++++++++++++++++++++--------- |
M | cksum.c | | | 64 | +++++++++++++++++++++++++++++++--------------------------------- |
3 files changed, 59 insertions(+), 43 deletions(-)
diff --git a/README b/README
@@ -15,7 +15,7 @@ The following tools are implemented (* == finished):
* chmod yes none
chown no -h, -H, -L, -P
chroot non-posix none
- cksum yes none
+* cksum yes none
* cmp yes none
* cols non-posix none
comm yes none
diff --git a/cksum.1 b/cksum.1
@@ -1,9 +1,27 @@
-.TH CKSUM 1 sbase\-VERSION
-.SH NAME
-cksum \- print file checksums
-.SH SYNOPSIS
-.B cksum
-.RI [ file ...]
-.SH DESCRIPTION
-.B cksum
-calculates and prints a cyclic redundancy check (CRC) for each input file.
+.Dd January 17, 2014
+.Dt CKSUM 1 sbase\-VERSION
+.Sh NAME
+.Nm cksum
+.Nd compute file checksum
+.Sh SYNOPSIS
+.Nm cksum
+.Op Ar file ...
+.Sh DESCRIPTION
+.Nm
+calculates a cyclic redundancy check (CRC) of
+.Ar file
+according to
+.St -iso8802-3
+and writes it, the file size in bytes and path to stdout.
+.Pp
+If no
+.Ar file
+is given,
+.Nm
+reads from stdin.
+.Sh STANDARDS
+The
+.Nm
+utility is compliant with the
+.St -p1003.1-2008
+specification.
diff --git a/cksum.c b/cksum.c
@@ -7,14 +7,6 @@
#include "util.h"
-static void cksum(FILE *, const char *);
-
-static void
-usage(void)
-{
- eprintf("usage: %s [files...]\n", argv0);
-}
-
static const unsigned long crctab[] = { 0x00000000,
0x04c11db7, 0x09823b6e, 0x0d4326d9, 0x130476dc, 0x17c56b6b,
0x1a864db2, 0x1e475005, 0x2608edb8, 0x22c9f00f, 0x2f8ad6d6,
@@ -69,31 +61,6 @@ static const unsigned long crctab[] = { 0x00000000,
0xa2f33668, 0xbcb4666d, 0xb8757bda, 0xb5365d03, 0xb1f740b4
};
-int
-main(int argc, char *argv[])
-{
- FILE *fp;
-
- ARGBEGIN {
- default:
- usage();
- } ARGEND;
-
- if (argc == 0) {
- cksum(stdin, NULL);
- } else {
- for (; argc > 0; argc--, argv++) {
- if (!(fp = fopen(argv[0], "r"))) {
- weprintf("fopen %s:", argv[0]);
- continue;
- }
- cksum(fp, argv[0]);
- fclose(fp);
- }
- }
- return 0;
-}
-
static void
cksum(FILE *fp, const char *s)
{
@@ -118,3 +85,34 @@ cksum(FILE *fp, const char *s)
printf(" %s", s);
putchar('\n');
}
+
+static void
+usage(void)
+{
+ eprintf("usage: %s [files ...]\n", argv0);
+}
+
+int
+main(int argc, char *argv[])
+{
+ FILE *fp;
+
+ ARGBEGIN {
+ default:
+ usage();
+ } ARGEND;
+
+ if (argc == 0)
+ cksum(stdin, NULL);
+ else {
+ for (; argc > 0; argc--, argv++) {
+ if (!(fp = fopen(argv[0], "r"))) {
+ weprintf("fopen %s:", argv[0]);
+ continue;
+ }
+ cksum(fp, argv[0]);
+ fclose(fp);
+ }
+ }
+ return 0;
+}