NetBSD-Bugs archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
bin/49134: cksum, add new option -q -- quiet mode
>Number: 49134
>Category: bin
>Synopsis: cksum, add new option -q -- quiet mode
>Confidential: no
>Severity: non-critical
>Priority: low
>Responsible: bin-bug-people
>State: open
>Class: change-request
>Submitter-Id: net
>Arrival-Date: Wed Aug 20 23:25:00 +0000 2014
>Originator: Kamil Rytarowski
>Release: 6.99.47
>Organization:
>Environment:
NetBSD compaq 6.99.47 NetBSD 6.99.47 (NO_DRM) #0: Sat Jul 26 11:24:44 CEST 2014
root@chieftec:/usr/src/sys/arch/amd64/compile/NO_DRM amd64
>Description:
Family of cksum programs doesn't ship with a quiet mode, contrary to the one
from FreeBSD (-q) and OpenBSD (-q).
Quiet mode is useful when someone needs plain checksum and cannot use (or
simply doesn't want to use) pipes.
Discussion thread:
http://mail-index.netbsd.org/netbsd-users/2014/08/05/msg015067.html
>How-To-Repeat:
N/A
>Fix:
Index: cksum.1
===================================================================
RCS file: /cvsroot/src/usr.bin/cksum/cksum.1,v
retrieving revision 1.45
diff -u -r1.45 cksum.1
--- cksum.1 28 Mar 2013 22:54:25 -0000 1.45
+++ cksum.1 20 Aug 2014 22:57:25 -0000
@@ -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
Index: cksum.c
===================================================================
RCS file: /cvsroot/src/usr.bin/cksum/cksum.c,v
retrieving revision 1.46
diff -u -r1.46 cksum.c
--- cksum.c 18 Oct 2013 20:47:06 -0000 1.46
+++ cksum.c 20 Aug 2014 22:57:25 -0000
@@ -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