projects
/
u
/
mdw
/
catacomb
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Manual page for the new `hashsum' program.
[u/mdw/catacomb]
/
hashsum.c
diff --git
a/hashsum.c
b/hashsum.c
index
73ad9dc
..
051fdb1
100644
(file)
--- a/
hashsum.c
+++ b/
hashsum.c
@@
-1,6
+1,6
@@
/* -*-c-*-
*
/* -*-c-*-
*
- * $Id: hashsum.c,v 1.
1 2000/07/15 20:52:34
mdw Exp $
+ * $Id: hashsum.c,v 1.
3 2000/07/29 17:02:43
mdw Exp $
*
* Hash files using some secure hash function
*
*
* Hash files using some secure hash function
*
@@
-30,6
+30,13
@@
/*----- Revision history --------------------------------------------------*
*
* $Log: hashsum.c,v $
/*----- Revision history --------------------------------------------------*
*
* $Log: hashsum.c,v $
+ * Revision 1.3 2000/07/29 17:02:43 mdw
+ * (checkhash): Be pettier about spaces between the hash and filename, for
+ * compatiblity with `md5sum'.
+ *
+ * Revision 1.2 2000/07/15 21:14:05 mdw
+ * Missed `-e' out of the usage string.
+ *
* Revision 1.1 2000/07/15 20:52:34 mdw
* Useful replacement for `md5sum' with support for many different hash
* functions and for reading filename lists from `find'.
* Revision 1.1 2000/07/15 20:52:34 mdw
* Useful replacement for `md5sum' with support for many different hash
* functions and for reading filename lists from `find'.
@@
-419,18
+426,19
@@
static int checkhash(const char *file, unsigned f, const gchash *gch)
/* --- Otherwise it's a hex thing --- */
/* --- Otherwise it's a hex thing --- */
- if ((q = str_getword(&p)) == 0)
+ q = p;
+ while (*p && *p != ' ')
+ p++;
+ if (!*p)
continue;
continue;
+ *p++ = 0;
if (gethex(q, buf, gch->hashsz, 0) < gch->hashsz)
continue;
if (gethex(q, buf, gch->hashsz, 0) < gch->hashsz)
continue;
- while (isspace((unsigned char)*p))
- p++;
- if (*p == '*') {
- p++;
+ if (*p == '*')
ff |= f_binary;
ff |= f_binary;
- }
- if (!*p)
+ else if (*p != ' ')
continue;
continue;
+ p++;
if (f & f_escape) {
DRESET(&dd);
if (f & f_escape) {
DRESET(&dd);
@@
-492,6
+500,11
@@
static int dohash(const char *file, unsigned f, const gchash *gch)
return (rc);
}
return (rc);
}
+static int dofile(const char *file, unsigned f, const gchash *gch)
+{
+ return (f & f_check ? checkhash : dohash)(file, f, gch);
+}
+
static int hashfiles(const char *file, unsigned f, const gchash *gch)
{
FILE *fp;
static int hashfiles(const char *file, unsigned f, const gchash *gch)
{
FILE *fp;
@@
-510,7
+523,7
@@
static int hashfiles(const char *file, unsigned f, const gchash *gch)
DRESET(&d);
if (getstring(fp, 0, &d, f & f_raw))
break;
DRESET(&d);
if (getstring(fp, 0, &d, f & f_raw))
break;
- if ((rrc = do
hash
(d.buf, f, gch)) != 0)
+ if ((rrc = do
file
(d.buf, f, gch)) != 0)
rc = rrc;
}
rc = rrc;
}
@@
-519,11
+532,7
@@
static int hashfiles(const char *file, unsigned f, const gchash *gch)
static int hashsum(const char *file, unsigned f, const gchash *gch)
{
static int hashsum(const char *file, unsigned f, const gchash *gch)
{
- if (f & f_check)
- return (checkhash(file, f, gch));
- if (f & f_files)
- return (hashfiles(file, f, gch));
- return (dohash(file, f, gch));
+ return (f & f_files ? hashfiles : dofile)(file, f, gch);
}
/*----- Main driver -------------------------------------------------------*/
}
/*----- Main driver -------------------------------------------------------*/
@@
-535,7
+544,7
@@
static void version(FILE *fp)
static void usage(FILE *fp)
{
static void usage(FILE *fp)
{
- pquis(fp, "Usage: $ [-f0bcv] [-a algorithm] [files...]\n");
+ pquis(fp, "Usage: $ [-f0
e
bcv] [-a algorithm] [files...]\n");
}
static void help(FILE *fp, const gchash *gch)
}
static void help(FILE *fp, const gchash *gch)