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 <wqu@suse.com>
Signed-off-by: Jeff Mahoney <jeffm@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
This commit is contained in:
Jeff Mahoney 2018-03-05 16:49:00 -05:00 committed by David Sterba
parent f114e65591
commit a30c9151c6
3 changed files with 22 additions and 21 deletions

14
btrfs.c
View File

@ -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);

25
help.c
View File

@ -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-<group>'.\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);
}

4
help.h
View File

@ -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))