From 9d23e9654e386af0e18c3adce42d6209998815e9 Mon Sep 17 00:00:00 2001 From: tater Date: Sat, 14 Jul 2018 17:03:50 -0400 Subject: [PATCH] added cmd error handling - thx zi0r --- tdfiglet.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/tdfiglet.c b/tdfiglet.c index e09343e..a875036 100644 --- a/tdfiglet.c +++ b/tdfiglet.c @@ -104,12 +104,10 @@ usage(void) fprintf(stderr, " -c a|m color format ANSI or mirc. Default is ANSI\n"); fprintf(stderr, " -e u|a encode as unicode or ASCII. Default is unicode\n"); fprintf(stderr, " -i print font details.\n"); + fprintf(stderr, " -h usage.\n"); + fprintf(stderr, "\n"); exit(EX_USAGE); - - printf("welp\n"); - - return; } opt_t opt; @@ -125,6 +123,10 @@ main(int argc, char *argv[]) opt.info = false; opt.encoding = ENC_UNICODE; + if (argc < 2) { + usage(); + } + while((o = getopt(argc, argv, "w:j:c:e:i")) != -1) { switch (o) { case 'w': @@ -143,7 +145,6 @@ main(int argc, char *argv[]) break; default: usage(); - exit(EX_USAGE); } break; case 'c': @@ -156,7 +157,6 @@ main(int argc, char *argv[]) break; default: usage(); - exit(EX_USAGE); } break; case 'e': @@ -169,15 +169,15 @@ main(int argc, char *argv[]) break; default: usage(); - exit(EX_USAGE); } break; case 'i': opt.info = true; break; + case 'h': + /* fallthrough */ default: usage(); - exit(EX_USAGE); } }