return lvt_bits;
}
-const struct command_name *find_command_name(const char *name)
+static unsigned _find_lvm_command_enum(const char *name)
{
static int _command_names_count = -1;
int first = 0, last, middle;
else if (i > 0)
last = middle - 1;
else
- return &command_names[middle];
+ return middle;
}
- return NULL;
-}
-
-static const struct command_name *_find_command_name(const char *name)
-{
- if (!islower(name[0]))
- return NULL; /* Commands starts with lower-case */
-
- return find_command_name(name);
+ return -1;
}
-static const char *_is_command_name(char *str)
+const struct command_name *find_command_name(const char *name)
{
- const struct command_name *c;
-
- if ((c = _find_command_name(str)))
- return c->name;
+ int r = _find_lvm_command_enum(name);
- return NULL;
+ return (r < LVM_COMMAND_COUNT) ? &command_names[r] : NULL;
}
static int _is_opt_name(char *str)
int copy_pos = 0;
int skip = 0;
int i;
+ int lvm_command_enum;
memset(&commands, 0, sizeof(commands));
continue;
/* New cmd def begins: command_name <required opt/pos args> */
- if ((name = _is_command_name(line_argv[0]))) {
- if (cmd_count >= COMMAND_COUNT) {
+ if (islower(line_argv[0][0]) && /* All commands are lower-case only */
+ ((lvm_command_enum = _find_lvm_command_enum(line_argv[0])) < LVM_COMMAND_COUNT)) {
+ if (cmd_count >= COMMAND_COUNT)
return 0;
- }
/*
* FIXME: when running one specific command name,
* we can optimize by not parsing command defs
* that don't start with that command name.
*/
-
cmd = &commands[cmd_count];
cmd->command_index = cmd_count;
cmd_count++;
- cmd->name = name;
+ cmd->lvm_command_enum = lvm_command_enum;
+ cmd->name = name = command_names[lvm_command_enum].name;
if (run_name && strcmp(run_name, name)) {
skip = 1;
void print_usage(struct command *cmd, int longhelp, int desc_first)
{
- const struct command_name *cname = _find_command_name(cmd->name);
- const struct command_name_args *cna = (cname) ? &command_names_args[cname->lvm_command_enum] : NULL;
+ const struct command_name *cname = &command_names[cmd->lvm_command_enum];
+ const struct command_name_args *cna = &command_names_args[cname->lvm_command_enum];
int any_req = (cmd->cmd_flags & CMD_FLAG_ANY_REQUIRED_OPT) ? 1 : 0;
int include_extents = 0;
int ro, rp, oo, op, opt_enum, first;
command_fn fn; /* old style */
unsigned int cmd_flags; /* CMD_FLAG_ */
+ uint16_t lvm_command_enum; /* position in commands[] */
/* definitions of opt/pos args */
static void _print_man_usage(char *lvmname, struct command *cmd)
{
- const struct command_name *cname;
- const struct command_name_args *cna;
+ const struct command_name *cname = &command_names[cmd->lvm_command_enum];
+ const struct command_name_args *cna = &command_names_args[cmd->lvm_command_enum];
int any_req = (cmd->cmd_flags & CMD_FLAG_ANY_REQUIRED_OPT) ? 1 : 0;
int sep, ro, rp, oo, op, opt_enum;
int need_ro_indent_end = 0;
uint64_t lv_type_bits = 0;
_was_hyphen = 0;
- if (!(cname = _find_command_name(cmd->name)))
- return;
-
- cna = &command_names_args[cname->lvm_command_enum];
-
printf("\\fB%s\\fP", lvmname);
if (!any_req)
static void _print_man_usage_common_lvm(struct command *cmd)
{
- const struct command_name *cname;
+ const struct command_name *cname = &command_names[cmd->lvm_command_enum];
int i, sep, oo, opt_enum;
- if (!(cname = _find_command_name(cmd->name)))
- return;
-
printf("Common options for lvm:\n");
printf(".\n");
static void _print_man_usage_common_cmd(struct command *cmd)
{
- const struct command_name *cname;
- const struct command_name_args *cna;
+ const struct command_name *cname = &command_names[cmd->lvm_command_enum];
+ const struct command_name_args *cna = &command_names_args[cmd->lvm_command_enum];
int i, sep, oo, opt_enum;
int found_common_command = 0;
- if (!(cname = _find_command_name(cmd->name)))
- return;
-
- cna = &command_names_args[cname->lvm_command_enum];
-
if (cna->variants < 2)
return;
name += 4;
}
- cname = _find_command_name(name);
+ cname = find_command_name(name);
printf(".TH %s 8 \"LVM TOOLS #VERSION#\" \"Red Hat, Inc.\"\n",
_upper_command_name(lvmname));
printf(".\n.SH SYNOPSIS\n.\n");
prev_cmd = cmd;
- if (!(cname = _find_command_name(cmd->name)))
- return 0;
-
- cna = &command_names_args[cname->lvm_command_enum];
+ cname = &command_names[cmd->lvm_command_enum];
+ cna = &command_names_args[cmd->lvm_command_enum];
if (cna->variant_has_ro && cna->variant_has_rp)
printf("\\fB%s\\fP \\fIoption_args\\fP \\fIposition_args\\fP\n", lvmname);