Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/usr.bin/cksum PR/49134: Kamil Rytarowski: Add -q flag.
details: https://anonhg.NetBSD.org/src/rev/26c72632b2f3
branches: trunk
changeset: 331920:26c72632b2f3
user: christos <christos%NetBSD.org@localhost>
date: Sun Aug 31 07:05:33 2014 +0000
description:
PR/49134: Kamil Rytarowski: Add -q flag.
diffstat:
usr.bin/cksum/cksum.1 | 26 +++++++++++++++++---------
usr.bin/cksum/cksum.c | 31 ++++++++++++++++++++-----------
2 files changed, 37 insertions(+), 20 deletions(-)
diffs (201 lines):
diff -r a999111d61c5 -r 26c72632b2f3 usr.bin/cksum/cksum.1
--- a/usr.bin/cksum/cksum.1 Sun Aug 31 07:04:07 2014 +0000
+++ b/usr.bin/cksum/cksum.1 Sun Aug 31 07:05:33 2014 +0000
@@ -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 @@
.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 @@
.Pq Fl c
first appeared in
.Nx 4.0 .
+Quiet mode
+.Pq Fl q
+was added in
+.Nx 7.0 .
.\" .Pp
.\" The
.\" .Nm sum
diff -r a999111d61c5 -r 26c72632b2f3 usr.bin/cksum/cksum.c
--- a/usr.bin/cksum/cksum.c Sun Aug 31 07:04:07 2014 +0000
+++ b/usr.bin/cksum/cksum.c Sun Aug 31 07:05:33 2014 +0000
@@ -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 @@
#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 @@
#include "extern.h"
+#define PRINT_NORMAL 0x01
+#define PRINT_QUIET 0x02
+
typedef char *(*_filefunc)(const char *, char *);
const struct hash {
@@ -157,14 +160,15 @@
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 @@
}
}
- 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 @@
do_check = 1;
break;
case 'n':
- normal = 1;
+ print_flags |= PRINT_NORMAL;
break;
case 'o':
if (hash) {
@@ -245,6 +249,9 @@
requirehash("-p");
pflag = 1;
break;
+ case 'q':
+ print_flags |= PRINT_QUIET;
+ break;
case 's':
if (hash == NULL)
requirehash("-s");
@@ -310,7 +317,7 @@
* 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 @@
/*
* 'normal' output, no (ck)sum
*/
- normal = 1;
+ print_flags |= PRINT_NORMAL;
nspaces = 1;
p_cksum = buf;
@@ -468,7 +475,7 @@
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 @@
}
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 @@
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);
Home |
Main Index |
Thread Index |
Old Index