From ac0e829733b02020b391f2dfd2f3f9f8f493ebdd Mon Sep 17 00:00:00 2001 From: jozan Date: Wed, 4 Nov 2020 19:16:29 +0000 Subject: Correctly parsed options FossilOrigin-Name: 516ec4118792b465c8f32e4294714c6e5d604fdbfaa709668df82ce8f25f502a --- src/c_opts.c | 14 ++++++++++---- src/c_opts.h | 9 +++++---- 2 files changed, 15 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/c_opts.c b/src/c_opts.c index c586a61..b029916 100644 --- a/src/c_opts.c +++ b/src/c_opts.c @@ -53,6 +53,14 @@ #include "c_opts.h" #include "c_unixize.h" +static void +c_dump_usage(void) +{ + dprintf(STDERR_FILENO, + C_USAGE_FMT, + C_OPTS); +} + static void c_ask_confirm(const char dir[]) { @@ -90,7 +98,7 @@ c_get_opts(struct opts_s* opts, opts->hidden = TRUE; } else if (opt == 'h') { - /* c_dump_usage(); */ + c_dump_usage(); exit(0); } else if (opt == 'i') { @@ -109,9 +117,7 @@ c_get_opts(struct opts_s* opts, opts->verbose = TRUE; } else if (opt == '?') { - dprintf(STDERR_FILENO, - "unixize: %c: unknown option\n", - optopt); + c_dump_usage(); exit(1); } } diff --git a/src/c_opts.h b/src/c_opts.h index 5c08b34..27bacb0 100644 --- a/src/c_opts.h +++ b/src/c_opts.h @@ -44,17 +44,18 @@ */ #ifndef __C_OPTS_H__ -#define __C_OPTS_H__ value +#define __C_OPTS_H__ #ifdef __linux__ -# include +#include #else -# include +#include #endif #include "c_unixize.h" -#define C_OPTS "ahinpRv" +#define C_OPTS "ahinpRv" +#define C_USAGE_FMT "usage: unixize [-%s] [directory]\n" struct opts_s { bool_t hidden; -- cgit v1.2.3