From a30c9151c679e651d9c7711770cb7c17d059eb21 Mon Sep 17 00:00:00 2001 From: Jeff Mahoney Date: Mon, 5 Mar 2018 16:49:00 -0500 Subject: [PATCH] btrfs-progs: help: convert ints used as bools to bool We use an int for 'full', 'all', and 'err' when we really mean a boolean. Reviewed-by: Qu Wenruo Signed-off-by: Jeff Mahoney Signed-off-by: David Sterba --- btrfs.c | 14 +++++++------- help.c | 25 +++++++++++++------------ help.h | 4 ++-- 3 files changed, 22 insertions(+), 21 deletions(-) diff --git a/btrfs.c b/btrfs.c index ec919a88..9444546a 100644 --- a/btrfs.c +++ b/btrfs.c @@ -109,7 +109,7 @@ static void handle_help_options_next_level(const struct cmd_struct *cmd, argv++; help_command_group(cmd->next, argc, argv); } else { - usage_command(cmd, 1, 0); + usage_command(cmd, true, false); } exit(0); @@ -125,7 +125,7 @@ int handle_command_group(const struct cmd_group *grp, int argc, argc--; argv++; if (argc < 1) { - usage_command_group(grp, 0, 0); + usage_command_group(grp, false, false); exit(1); } @@ -212,20 +212,20 @@ static int handle_global_options(int argc, char **argv) static void handle_special_globals(int shift, int argc, char **argv) { - int has_help = 0; - int has_full = 0; + bool has_help = false; + bool has_full = false; int i; for (i = 0; i < shift; i++) { if (strcmp(argv[i], "--help") == 0) - has_help = 1; + has_help = true; else if (strcmp(argv[i], "--full") == 0) - has_full = 1; + has_full = true; } if (has_help) { if (has_full) - usage_command_group(&btrfs_cmd_group, 1, 0); + usage_command_group(&btrfs_cmd_group, true, false); else cmd_help(argc, argv); exit(0); diff --git a/help.c b/help.c index 5f7c38fc..7a22e5e4 100644 --- a/help.c +++ b/help.c @@ -195,8 +195,8 @@ static int do_usage_one_command(const char * const *usagestr, } static int usage_command_internal(const char * const *usagestr, - const char *token, int full, int lst, - int alias, FILE *outf) + const char *token, bool full, bool lst, + bool alias, FILE *outf) { unsigned int flags = 0; int ret; @@ -222,17 +222,17 @@ static int usage_command_internal(const char * const *usagestr, } static void usage_command_usagestr(const char * const *usagestr, - const char *token, int full, int err) + const char *token, bool full, bool err) { FILE *outf = err ? stderr : stdout; int ret; - ret = usage_command_internal(usagestr, token, full, 0, 0, outf); + ret = usage_command_internal(usagestr, token, full, false, false, outf); if (!ret) fputc('\n', outf); } -void usage_command(const struct cmd_struct *cmd, int full, int err) +void usage_command(const struct cmd_struct *cmd, bool full, bool err) { usage_command_usagestr(cmd->usagestr, cmd->token, full, err); } @@ -284,11 +284,11 @@ void usage_unknown_option(const char * const *usagestr, char **argv) __attribute__((noreturn)) void usage(const char * const *usagestr) { - usage_command_usagestr(usagestr, NULL, 1, 1); + usage_command_usagestr(usagestr, NULL, true, true); exit(1); } -static void usage_command_group_internal(const struct cmd_group *grp, int full, +static void usage_command_group_internal(const struct cmd_group *grp, bool full, FILE *outf) { const struct cmd_struct *cmd = grp->commands; @@ -308,7 +308,8 @@ static void usage_command_group_internal(const struct cmd_group *grp, int full, } usage_command_internal(cmd->usagestr, cmd->token, full, - 1, cmd->flags & CMD_ALIAS, outf); + true, cmd->flags & CMD_ALIAS, + outf); if (cmd->flags & CMD_ALIAS) putchar('\n'); continue; @@ -370,7 +371,7 @@ void usage_command_group_short(const struct cmd_group *grp) fprintf(stderr, "All command groups have their manual page named 'btrfs-'.\n"); } -void usage_command_group(const struct cmd_group *grp, int full, int err) +void usage_command_group(const struct cmd_group *grp, bool full, bool err) { const char * const *usagestr = grp->usagestr; FILE *outf = err ? stderr : stdout; @@ -393,7 +394,7 @@ __attribute__((noreturn)) void help_unknown_token(const char *arg, const struct cmd_group *grp) { fprintf(stderr, "%s: unknown token '%s'\n", argv0_buf, arg); - usage_command_group(grp, 0, 1); + usage_command_group(grp, false, true); exit(1); } @@ -415,13 +416,13 @@ void help_ambiguous_token(const char *arg, const struct cmd_group *grp) void help_command_group(const struct cmd_group *grp, int argc, char **argv) { - int full = 0; + bool full = false; if (argc > 1) { if (!strcmp(argv[1], "--full")) full = 1; } - usage_command_group(grp, full, 0); + usage_command_group(grp, full, false); } diff --git a/help.h b/help.h index db9b5042..6920d6c3 100644 --- a/help.h +++ b/help.h @@ -60,8 +60,8 @@ void usage_unknown_option(const char * const *usagestr, char **argv); __attribute__((noreturn)) void usage(const char * const *usagestr); -void usage_command(const struct cmd_struct *cmd, int full, int err); -void usage_command_group(const struct cmd_group *grp, int all, int err); +void usage_command(const struct cmd_struct *cmd, bool full, bool err); +void usage_command_group(const struct cmd_group *grp, bool all, bool err); void usage_command_group_short(const struct cmd_group *grp); __attribute__((noreturn))