Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.bin/cksum Add a -n flag for the hash output forms, so th...



details:   https://anonhg.NetBSD.org/src/rev/1c3303e05799
branches:  trunk
changeset: 538374:1c3303e05799
user:      atatat <atatat%NetBSD.org@localhost>
date:      Fri Oct 18 20:30:12 2002 +0000

description:
Add a -n flag for the hash output forms, so that the output is
"normal", ie, "hash filename" (like all the simple checksum output
forms) as opposed to "hashname (filename) = hash".  This output form
is, imho, somewhat more useful because you can pass it directly to
sort to find identical files.  For example:

        md5 * | sort | uniq -c | grep -v ' 1 '

diffstat:

 usr.bin/cksum/cksum.1 |  17 +++++++++++++----
 usr.bin/cksum/cksum.c |  33 +++++++++++++++++++++------------
 2 files changed, 34 insertions(+), 16 deletions(-)

diffs (184 lines):

diff -r a9dac544bcf0 -r 1c3303e05799 usr.bin/cksum/cksum.1
--- a/usr.bin/cksum/cksum.1     Fri Oct 18 20:03:02 2002 +0000
+++ b/usr.bin/cksum/cksum.1     Fri Oct 18 20:30:12 2002 +0000
@@ -1,4 +1,4 @@
-.\"    $NetBSD: cksum.1,v 1.18 2002/09/30 11:08:58 grant Exp $
+.\"    $NetBSD: cksum.1,v 1.19 2002/10/18 20:30:12 atatat Exp $
 .\"
 .\" Copyright (c) 1991, 1993
 .\"    The Regents of the University of California.  All rights reserved.
@@ -50,6 +50,7 @@
 .Nd display file checksums and block counts
 .Sh SYNOPSIS
 .Nm
+.Op Fl n
 .Oo
 .Fl m |
 .Fl 1 |
@@ -63,30 +64,35 @@
 .Nm sum
 .Op Ar
 .Nm md2
+.Op Fl n
 .Op Fl p
 .Op Fl t
 .Op Fl x
 .Op Fl s Ar string
 .Op Ar
 .Nm md4
+.Op Fl n
 .Op Fl p
 .Op Fl t
 .Op Fl x
 .Op Fl s Ar string
 .Op Ar
 .Nm md5
+.Op Fl n
 .Op Fl p
 .Op Fl t
 .Op Fl x
 .Op Fl s Ar string
 .Op Ar
 .Nm sha1
+.Op Fl n
 .Op Fl p
 .Op Fl t
 .Op Fl x
 .Op Fl s Ar string
 .Op Ar
 .Nm rmd160
+.Op Fl n
 .Op Fl p
 .Op Fl t
 .Op Fl x
@@ -198,12 +204,15 @@
 The following options apply only when using the one of the message
 digest algorithms:
 .Bl -tag -width indent
+.It Fl n
+Print the hash and the filename in the normal sum output form, with
+the hash at the left and the filename following on the right.
+.It Fl p
+Echo input from standard input to standard output, and append the
+selected message digest.
 .It Fl s Ar string
 Print the hash of the given string
 .Ar string .
-.It Fl p
-Echo input from standard input to standard output, and append the
-selected message digest.
 .It Fl t
 Run a built-in message digest time trial.
 .It Fl x
diff -r a9dac544bcf0 -r 1c3303e05799 usr.bin/cksum/cksum.c
--- a/usr.bin/cksum/cksum.c     Fri Oct 18 20:03:02 2002 +0000
+++ b/usr.bin/cksum/cksum.c     Fri Oct 18 20:30:12 2002 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: cksum.c,v 1.16 2002/03/31 14:43:22 bjh21 Exp $ */
+/*     $NetBSD: cksum.c,v 1.17 2002/10/18 20:30:13 atatat Exp $        */
 
 /*-
  * Copyright (c) 1997 Jason R. Thorpe.  All rights reserved.
@@ -47,7 +47,7 @@
 #if 0
 static char sccsid[] = "@(#)cksum.c    8.2 (Berkeley) 4/28/95";
 #endif
-__RCSID("$NetBSD: cksum.c,v 1.16 2002/03/31 14:43:22 bjh21 Exp $");
+__RCSID("$NetBSD: cksum.c,v 1.17 2002/10/18 20:30:13 atatat Exp $");
 #endif /* not lint */
 
 #include <sys/cdefs.h>
@@ -105,7 +105,7 @@
 };
 
 int    main __P((int, char **));
-int    hash_digest_file __P((char *, struct hash *));
+int    hash_digest_file __P((char *, struct hash *, int));
 void   requirehash __P((const char *));
 void   usage __P((void));
 
@@ -121,10 +121,12 @@
        int (*cfncn) __P((int, u_int32_t *, u_int32_t *));
        void (*pfncn) __P((char *, u_int32_t, u_int32_t));
        struct hash *hash;
+       int normal;
 
        cfncn = NULL;
        pfncn = NULL;
        dosum = pflag = nohashstdin = 0;
+       normal = 0;
 
        setlocale(LC_ALL, "");
 
@@ -147,7 +149,7 @@
                }
        }
 
-       while ((ch = getopt(argc, argv, "mo:ps:tx12456")) != -1)
+       while ((ch = getopt(argc, argv, "mno:ps:tx12456")) != -1)
                switch(ch) {
                case '2':
                        if (dosum) {
@@ -185,6 +187,9 @@
                        }
                        hash = &hashes[HASH_RMD160];
                        break;
+               case 'n':
+                       normal = 1;
+                       break;
                case 'o':
                        if (hash) {
                                warnx("%s mutually exclusive with sum",
@@ -239,7 +244,7 @@
                if (*argv) {
                        fn = *argv++;
                        if (hash != NULL) {
-                               if (hash_digest_file(fn, hash)) {
+                               if (hash_digest_file(fn, hash, normal)) {
                                        warn("%s", fn);
                                        rval = 1;
                                }
@@ -267,9 +272,10 @@
 }
 
 int
-hash_digest_file(fn, hash)
+hash_digest_file(fn, hash, normal)
        char *fn;
        struct hash *hash;
+       int normal;
 {
        char buf[41], *cp;
 
@@ -277,7 +283,10 @@
        if (cp == NULL)
                return (1);
 
-       printf("%s (%s) = %s\n", hash->hashname, fn, cp);
+       if (normal)
+               printf("%s %s\n", cp, fn);
+       else
+               printf("%s (%s) = %s\n", hash->hashname, fn, cp);
        return (0);
 }
 
@@ -297,14 +306,14 @@
        (void)fprintf(stderr, "usage: cksum [-m | [-o 1 | 2]] [file ...]\n");
        (void)fprintf(stderr, "       sum [file ...]\n");
        (void)fprintf(stderr,
-           "       md2 [-p | -t | -x | -s string] [file ...]\n");
+           "       md2 [-n] [-p | -t | -x | -s string] [file ...]\n");
        (void)fprintf(stderr,
-           "       md4 [-p | -t | -x | -s string] [file ...]\n");
+           "       md4 [-n] [-p | -t | -x | -s string] [file ...]\n");
        (void)fprintf(stderr,
-           "       md5 [-p | -t | -x | -s string] [file ...]\n");
+           "       md5 [-n] [-p | -t | -x | -s string] [file ...]\n");
        (void)fprintf(stderr,
-           "       sha1 [-p | -t | -x | -s string] [file ...]\n");
+           "       sha1 [-n] [-p | -t | -x | -s string] [file ...]\n");
        (void)fprintf(stderr,
-           "       rmd160 [-p | -t | -x | -s string] [file ...]\n");
+           "       rmd160 [-n] [-p | -t | -x | -s string] [file ...]\n");
        exit(1);
 }



Home | Main Index | Thread Index | Old Index