aboutsummaryrefslogtreecommitdiffstats
path: root/scripts/mkhash.c
diff options
context:
space:
mode:
authorINAGAKI Hiroshi <musashino.open@gmail.com>2020-12-17 23:44:28 +0900
committerPetr Štetiar <ynezz@true.cz>2020-12-22 19:11:50 +0100
commitfdcdbdfdef512e0fdd719a704cff827a0633f5dc (patch)
tree25dd7896ca81c9f36a11039d27431da770b28180 /scripts/mkhash.c
parent4771fac99f95e4cdd44d1ece17a2eb425b6b5b9e (diff)
downloadupstream-fdcdbdfdef512e0fdd719a704cff827a0633f5dc.tar.gz
upstream-fdcdbdfdef512e0fdd719a704cff827a0633f5dc.tar.bz2
upstream-fdcdbdfdef512e0fdd719a704cff827a0633f5dc.zip
scripts: add -N option to mkhash for printing without newline
Added "-N" option, it allow printing hash(es) without newline. Signed-off-by: INAGAKI Hiroshi <musashino.open@gmail.com>
Diffstat (limited to 'scripts/mkhash.c')
-rw-r--r--scripts/mkhash.c20
1 files changed, 13 insertions, 7 deletions
diff --git a/scripts/mkhash.c b/scripts/mkhash.c
index 3292433213..ed3d42d4c3 100644
--- a/scripts/mkhash.c
+++ b/scripts/mkhash.c
@@ -747,6 +747,7 @@ static int usage(const char *progname)
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);
@@ -771,7 +772,8 @@ static struct hash_type *get_hash_type(const char *name)
}
-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;
@@ -801,9 +803,10 @@ static int hash_file(struct hash_type *t, const char *filename, bool add_filenam
}
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;
}
@@ -813,13 +816,16 @@ int main(int argc, char **argv)
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);
}
@@ -836,10 +842,10 @@ int main(int argc, char **argv)
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;
}