/*----- Guts --------------------------------------------------------------*/
+static int checkjunk(const char *path, const struct stat *st, void *p)
+{
+ const char *what;
+ fhashstate *fh = p;
+
+ if (!st) {
+ if (fh->f & f_verbose)
+ fprintf(stderr, "JUNK (error %s) %s\n", strerror(errno), path);
+ else
+ moan("couldn't stat junk file `%s': %s", path, strerror(errno));
+ } else {
+ what = describefile(st);
+ if (fh->f & f_verbose)
+ fprintf(stderr, "JUNK %s %s\n", what, path);
+ else
+ moan("found junk %s `%s'", what, path);
+ }
+ return (0);
+}
+
+static int warnjunk(const char *path, const struct stat *st, void *p)
+{
+ if (st)
+ moan("unexpected %s `%s'", describefile(st), path);
+ else
+ moan("couldn't stat unexpected file `%s': %s", path, strerror(errno));
+ return (0);
+}
+
static int checkhash(fhashstate *fh, const char *file, const encodeops *e)
{
int rc;
-e, --escape Escape funny characters in filenames.\n\
-c, --check Check message digests rather than emitting them.\n\
-b, --binary When reading files, treat them as binary.\n\
+-p, --progress Show a progress indicator for large files.\n\
-v, --verbose Be verbose when checking digests.\n\
\n\
For a list of hashing algorithms and encodings, type `$ --list'.\n\
{ "escape", 0, 0, 'e' },
{ "check", 0, 0, 'c' },
+ { "junk", 0, 0, 'j' },
{ "binary", 0, 0, 'b' },
{ "verbose", 0, 0, 'v' },
{ "progress", 0, 0, 'p' },
{ 0, 0, 0, 0 }
};
- int i = mdwopt(argc, argv, "hVu a:E:l f0 ecbvp", opts, 0, 0, 0);
+ int i = mdwopt(argc, argv, "hVu a:E:l f0 ecjbvp", opts, 0, 0, 0);
if (i < 0)
break;
case 'c':
fh.f |= f_check;
break;
+ case 'j':
+ fh.f |= FHF_JUNK;
+ break;
case 'b':
fh.f |= FHF_BINARY;
break;
}
}
+ if (fh.f & FHF_JUNK) {
+ if (fh.f & f_check) {
+ if (fhash_junk(&fh, checkjunk, &fh)) rc = EXIT_FAILURE;
+ } else {
+ if (fhash_junk(&fh, warnjunk, 0) < 0) rc = EXIT_FAILURE;
+ }
+ }
+ fhash_free(&fh);
+
return (rc);
}