npm

Unnamed repository; edit this file 'description' to name the repository.
git clone git://git.nihaljere.xyz/npm
Log | Files | Refs

commit 28fcb82b4f815968b60ec91a05ed4c0e13b3e06a
parent c529a7c3fdbce63f9b56daee99779ceb34253a67
Author: Nihal Jere <nihal@nihaljere.xyz>
Date:   Fri, 30 Jul 2021 23:19:56 -0500

npwm: add usage

Diffstat:
Mnpwm.c | 29+++++++++++++++++++++--------
1 file changed, 21 insertions(+), 8 deletions(-)

diff --git a/npwm.c b/npwm.c @@ -51,22 +51,35 @@ error(const char *s) fprintf(stderr, "%s: %s\n", argv0, s); } +void +usage() +{ + fprintf(stderr, "%s: [-d file] | [-e]\n", argv0); + exit(1); +} + int main(int argc, char *argv[]) { char *c; size_t len; FILE *file = NULL; - /* TODO add usage */ - if (argc == 2 && strcmp(argv[1], "-e")) - die("invalid args"); + argv0 = argv[0]; - if (argc == 3 && strcmp(argv[1], "-d")) - die("invalid args"); + if (argc == 1) + usage(); - if (argc < 2) - die("invalid args"); + if (strcmp(argv[1], "-e") && strcmp(argv[1], "-d")) + usage(); - argv0 = argv[0]; + if (!strcmp(argv[1], "-e") && argc != 2) { + error("option -e does not take an argument"); + usage(); + } + + if (!strcmp(argv[1], "-d") && argc != 3) { + error("option -d takes exactly 1 argument"); + usage(); + } if (strcmp(argv[1], "-e") == 0) { if (getrandom(salt, SALT_LEN, 0) < SALT_LEN) {