fprintf(stderr, "Usage: %s <hash type> [options] [<file>...]\n"
"Options:\n"
" -n Print filename(s)\n"
+ " -N Suppress trailing newline\n"
"\n"
"Supported hash types:", progname);
}
-static int hash_file(struct hash_type *t, const char *filename, bool add_filename)
+static int hash_file(struct hash_type *t, const char *filename, bool add_filename,
+ bool no_newline)
{
const char *str;
}
if (add_filename)
- printf("%s %s\n", str, filename ? filename : "-");
+ printf("%s %s%s", str, filename ? filename : "-",
+ no_newline ? "" : "\n");
else
- printf("%s\n", str);
+ printf("%s%s", str, no_newline ? "" : "\n");
return 0;
}
struct hash_type *t;
const char *progname = argv[0];
int i, ch;
- bool add_filename = false;
+ bool add_filename = false, no_newline = false;
- while ((ch = getopt(argc, argv, "n")) != -1) {
+ while ((ch = getopt(argc, argv, "nN")) != -1) {
switch (ch) {
case 'n':
add_filename = true;
break;
+ case 'N':
+ no_newline = true;
+ break;
default:
return usage(progname);
}
return usage(progname);
if (argc < 2)
- return hash_file(t, NULL, add_filename);
+ return hash_file(t, NULL, add_filename, no_newline);
for (i = 0; i < argc - 1; i++) {
- int ret = hash_file(t, argv[1 + i], add_filename);
+ int ret = hash_file(t, argv[1 + i], add_filename, no_newline);
if (ret)
return ret;
}