vty/command.c: Cosmetic cleanup

this is just changing some of the code to reduce the way too high level
of indentation and thus improve readability.
This commit is contained in:
Harald Welte 2013-02-12 11:08:57 +01:00
parent 647e39f172
commit 80d30fe803
1 changed files with 80 additions and 81 deletions

View File

@ -1531,58 +1531,58 @@ cmd_describe_command_real(vector vline, struct vty *vty, int *status)
/* Filter commands. */ /* Filter commands. */
/* Only words precedes current word will be checked in this loop. */ /* Only words precedes current word will be checked in this loop. */
for (i = 0; i < index; i++) for (i = 0; i < index; i++) {
if ((command = vector_slot(vline, i))) { command = vector_slot(vline, i);
match = if (!command)
cmd_filter(command, cmd_vector, i, any_match); continue;
if (match == vararg_match) { match = cmd_filter(command, cmd_vector, i, any_match);
struct cmd_element *cmd_element;
vector descvec;
unsigned int j, k;
for (j = 0; j < vector_active(cmd_vector); j++) if (match == vararg_match) {
if ((cmd_element = struct cmd_element *cmd_element;
vector_slot(cmd_vector, j)) != NULL vector descvec;
&& unsigned int j, k;
(vector_active
(cmd_element->strvec))) { for (j = 0; j < vector_active(cmd_vector); j++)
descvec = if ((cmd_element =
vector_slot(cmd_element-> vector_slot(cmd_vector, j)) != NULL
strvec, &&
vector_active (vector_active(cmd_element->strvec))) {
(cmd_element-> descvec =
strvec) - 1); vector_slot(cmd_element->
for (k = 0; strvec,
k < vector_active(descvec); vector_active
k++) { (cmd_element->
struct desc *desc = strvec) - 1);
vector_slot(descvec, for (k = 0;
k); k < vector_active(descvec);
vector_set(matchvec, k++) {
desc); struct desc *desc =
} vector_slot(descvec,
k);
vector_set(matchvec,
desc);
} }
}
vector_set(matchvec, &desc_cr); vector_set(matchvec, &desc_cr);
vector_free(cmd_vector); vector_free(cmd_vector);
return matchvec; return matchvec;
}
if ((ret =
is_cmd_ambiguous(command, cmd_vector, i,
match)) == 1) {
vector_free(cmd_vector);
*status = CMD_ERR_AMBIGUOUS;
return NULL;
} else if (ret == 2) {
vector_free(cmd_vector);
*status = CMD_ERR_NO_MATCH;
return NULL;
}
} }
if ((ret = is_cmd_ambiguous(command, cmd_vector, i,
match)) == 1) {
vector_free(cmd_vector);
*status = CMD_ERR_AMBIGUOUS;
return NULL;
} else if (ret == 2) {
vector_free(cmd_vector);
*status = CMD_ERR_NO_MATCH;
return NULL;
}
}
/* Prepare match vector */ /* Prepare match vector */
/* matchvec = vector_init (INIT_MATCHVEC_SIZE); */ /* matchvec = vector_init (INIT_MATCHVEC_SIZE); */
@ -1592,47 +1592,46 @@ cmd_describe_command_real(vector vline, struct vty *vty, int *status)
match = cmd_filter(command, cmd_vector, index, any_match); match = cmd_filter(command, cmd_vector, index, any_match);
/* Make description vector. */ /* Make description vector. */
for (i = 0; i < vector_active(cmd_vector); i++) for (i = 0; i < vector_active(cmd_vector); i++) {
if ((cmd_element = vector_slot(cmd_vector, i)) != NULL) { const char *string = NULL;
const char *string = NULL; vector strvec;
vector strvec = cmd_element->strvec;
/* if command is NULL, index may be equal to vector_active */ cmd_element = vector_slot(cmd_vector, i);
if (command && index >= vector_active(strvec)) if (!cmd_element)
vector_slot(cmd_vector, i) = NULL; continue;
else {
/* Check if command is completed. */
if (command == NULL
&& index == vector_active(strvec)) {
string = "<cr>";
if (!desc_unique_string
(matchvec, string))
vector_set(matchvec, &desc_cr);
} else {
unsigned int j;
vector descvec =
vector_slot(strvec, index);
struct desc *desc;
for (j = 0; j < vector_active(descvec); strvec = cmd_element->strvec;
j++)
if ((desc = /* if command is NULL, index may be equal to vector_active */
vector_slot(descvec, j))) { if (command && index >= vector_active(strvec))
string = vector_slot(cmd_vector, i) = NULL;
cmd_entry_function_desc else {
(command, /* Check if command is completed. */
desc->cmd); if (command == NULL
if (string) { && index == vector_active(strvec)) {
/* Uniqueness check */ string = "<cr>";
if (!desc_unique_string(matchvec, string)) if (!desc_unique_string(matchvec, string))
vector_set vector_set(matchvec, &desc_cr);
(matchvec, } else {
desc); unsigned int j;
} vector descvec = vector_slot(strvec, index);
} struct desc *desc;
for (j = 0; j < vector_active(descvec); j++) {
desc = vector_slot(descvec, j);
if (!desc)
continue;
string = cmd_entry_function_desc
(command, desc->cmd);
if (!string)
continue;
/* Uniqueness check */
if (!desc_unique_string(matchvec, string))
vector_set(matchvec, desc);
} }
} }
} }
}
vector_free(cmd_vector); vector_free(cmd_vector);
if (vector_slot(matchvec, 0) == NULL) { if (vector_slot(matchvec, 0) == NULL) {