Module Name: src Committed By: christos Date: Sun Aug 31 07:05:33 UTC 2014
Modified Files: src/usr.bin/cksum: cksum.1 cksum.c Log Message: PR/49134: Kamil Rytarowski: Add -q flag. To generate a diff of this commit: cvs rdiff -u -r1.45 -r1.46 src/usr.bin/cksum/cksum.1 cvs rdiff -u -r1.46 -r1.47 src/usr.bin/cksum/cksum.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/usr.bin/cksum/cksum.1 diff -u src/usr.bin/cksum/cksum.1:1.45 src/usr.bin/cksum/cksum.1:1.46 --- src/usr.bin/cksum/cksum.1:1.45 Thu Mar 28 18:54:25 2013 +++ src/usr.bin/cksum/cksum.1 Sun Aug 31 03:05:33 2014 @@ -1,4 +1,4 @@ -.\" $NetBSD: cksum.1,v 1.45 2013/03/28 22:54:25 njoly Exp $ +.\" $NetBSD: cksum.1,v 1.46 2014/08/31 07:05:33 christos Exp $ .\" .\" Copyright (c) 1991, 1993 .\" The Regents of the University of California. All rights reserved. @@ -32,7 +32,7 @@ .\" .\" @(#)cksum.1 8.2 (Berkeley) 4/28/95 .\" -.Dd June 24, 2012 +.Dd August 31, 2014 .Dt CKSUM 1 .Os .Sh NAME @@ -47,32 +47,32 @@ .Sh SYNOPSIS .Nm cksum .Op Fl n -.Op Fl a Ar algorithm Oo Fl ptx Oc Oo Fl s Ar string Oc +.Op Fl a Ar algorithm Oo Fl pqtx Oc Oo Fl s Ar string Oc .Op Fl o Ar 1 Ns | Ns Ar 2 .Op Ar Li \&| Fl c Oo Fl w Oc Oo Ar sumfile Oc .Nm sum .Op Fl n -.Op Fl a Ar algorithm Oo Fl ptx Oc Oo Fl s Ar string Oc +.Op Fl a Ar algorithm Oo Fl pqtx Oc Oo Fl s Ar string Oc .Op Fl o Ar 1 Ns | Ns Ar 2 .Op Ar Li \&| Fl c Oo Fl w Oc Oo Ar sumfile Oc .Nm md2 -.Op Fl nptx +.Op Fl npqtx .Op Fl s Ar string .Op Ar Li \&| Fl c Oo Fl w Oc Oo Ar sumfile Oc .Nm md4 -.Op Fl nptx +.Op Fl npqtx .Op Fl s Ar string .Op Ar Li \&| Fl c Oo Fl w Oc Oo Ar sumfile Oc .Nm md5 -.Op Fl nptx +.Op Fl npqtx .Op Fl s Ar string .Op Ar Li \&| Fl c Oo Fl w Oc Oo Ar sumfile Oc .Nm rmd160 -.Op Fl nptx +.Op Fl npqtx .Op Fl s Ar string .Op Ar Li \&| Fl c Oo Fl w Oc Oo Ar sumfile Oc .Nm sha1 -.Op Fl nptx +.Op Fl npqtx .Op Fl s Ar string .Op Ar Li \&| Fl c Oo Fl w Oc Oo Ar sumfile Oc .Sh DESCRIPTION @@ -191,6 +191,10 @@ the hash at the left and the filename fo .It Fl p Echo input from standard input to standard output, and append the selected message digest. +.It Fl q +Quiet mode \(em only the checksum is printed out. Overrides the +.Fl n +option. .It Fl s Ar string Print the hash of the given string .Ar string . @@ -323,6 +327,10 @@ The functionality to verify checksum sto .Pq Fl c first appeared in .Nx 4.0 . +Quiet mode +.Pq Fl q +was added in +.Nx 7.0 . .\" .Pp .\" The .\" .Nm sum Index: src/usr.bin/cksum/cksum.c diff -u src/usr.bin/cksum/cksum.c:1.46 src/usr.bin/cksum/cksum.c:1.47 --- src/usr.bin/cksum/cksum.c:1.46 Fri Oct 18 16:47:06 2013 +++ src/usr.bin/cksum/cksum.c Sun Aug 31 03:05:33 2014 @@ -1,4 +1,4 @@ -/* $NetBSD: cksum.c,v 1.46 2013/10/18 20:47:06 christos Exp $ */ +/* $NetBSD: cksum.c,v 1.47 2014/08/31 07:05:33 christos Exp $ */ /*- * Copyright (c) 1991, 1993 @@ -81,7 +81,7 @@ __COPYRIGHT("@(#) Copyright (c) 1991, 19 #if 0 static char sccsid[] = "@(#)cksum.c 8.2 (Berkeley) 4/28/95"; #endif -__RCSID("$NetBSD: cksum.c,v 1.46 2013/10/18 20:47:06 christos Exp $"); +__RCSID("$NetBSD: cksum.c,v 1.47 2014/08/31 07:05:33 christos Exp $"); #endif /* not lint */ #include <sys/types.h> @@ -104,6 +104,9 @@ __RCSID("$NetBSD: cksum.c,v 1.46 2013/10 #include "extern.h" +#define PRINT_NORMAL 0x01 +#define PRINT_QUIET 0x02 + typedef char *(*_filefunc)(const char *, char *); const struct hash { @@ -157,14 +160,15 @@ main(int argc, char **argv) int (*cfncn) (int, u_int32_t *, off_t *); void (*pfncn) (char *, u_int32_t, off_t); const struct hash *hash; - int normal, i, check_warn, do_check; + int i, check_warn, do_check; + int print_flags; cfncn = NULL; pfncn = NULL; pflag = nohashstdin = 0; - normal = 0; check_warn = 0; do_check = 0; + print_flags = 0; setlocale(LC_ALL, ""); @@ -186,7 +190,7 @@ main(int argc, char **argv) } } - while ((ch = getopt(argc, argv, "a:cno:ps:twx")) != -1) + while ((ch = getopt(argc, argv, "a:cno:pqs:twx")) != -1) switch(ch) { case 'a': if (hash) { @@ -221,7 +225,7 @@ main(int argc, char **argv) do_check = 1; break; case 'n': - normal = 1; + print_flags |= PRINT_NORMAL; break; case 'o': if (hash) { @@ -245,6 +249,9 @@ main(int argc, char **argv) requirehash("-p"); pflag = 1; break; + case 'q': + print_flags |= PRINT_QUIET; + break; case 's': if (hash == NULL) requirehash("-s"); @@ -310,7 +317,7 @@ main(int argc, char **argv) * Assume 'normal' output if there's a '(' */ p_filename += 1; - normal = 0; + print_flags &= ~(PRINT_NORMAL); p_cksum = strrchr(p_filename, ')'); if (p_cksum == NULL) { @@ -364,7 +371,7 @@ main(int argc, char **argv) /* * 'normal' output, no (ck)sum */ - normal = 1; + print_flags |= PRINT_NORMAL; nspaces = 1; p_cksum = buf; @@ -468,7 +475,7 @@ main(int argc, char **argv) if (*argv) { fn = *argv++; if (hash != NULL) { - if (hash_digest_file(fn, hash, normal)) { + if (hash_digest_file(fn, hash, print_flags)) { warn("%s", fn); rval = 1; } @@ -497,7 +504,7 @@ main(int argc, char **argv) } static int -hash_digest_file(char *fn, const struct hash *hash, int normal) +hash_digest_file(char *fn, const struct hash *hash, int flags) { char *cp; @@ -505,7 +512,9 @@ hash_digest_file(char *fn, const struct if (cp == NULL) return 1; - if (normal) + if (flags & PRINT_QUIET) + printf("%s\n", cp); + else if (flags & PRINT_NORMAL) printf("%s %s\n", cp, fn); else printf("%s (%s) = %s\n", hash->hashname, fn, cp);