NetBSD-Users archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
Re: cksum new parameters -q and -r
"Alistair Crooks" <agc%pkgsrc.org@localhost>, Tuesday, August 05, 2014 at 10:46
PM
> Just provide the file as stdin, e.g.
>
> % md5 < Makefile
> c484c4693b61f058087c0bb84091adfb
> %
Hello,
Thank you for your reply. Actually my idea was to omit pipes (as my tool
doesn't support it in an unbitter way),
I've just pushed the things forward and did a research. NetBSD ships with '-n',
an equivalent of '-r' from FreeBSD and OpenBSD. The quiet (-q) mode was added
and the patch against current is attached to this mail.
I'll submit a public-report for this task along with the patch and link to this
thread. I'm open for comments.
Thanks in advance,
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