From 80d30fe8036b4e79e16e766846a173e822d95512 Mon Sep 17 00:00:00 2001 From: Harald Welte Date: Tue, 12 Feb 2013 11:08:57 +0100 Subject: 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. --- src/vty/command.c | 163 +++++++++++++++++++++++++++--------------------------- 1 file changed, 81 insertions(+), 82 deletions(-) (limited to 'src') diff --git a/src/vty/command.c b/src/vty/command.c index 7a58503f..ac731ee0 100644 --- a/src/vty/command.c +++ b/src/vty/command.c @@ -1531,57 +1531,57 @@ cmd_describe_command_real(vector vline, struct vty *vty, int *status) /* Filter commands. */ /* Only words precedes current word will be checked in this loop. */ - for (i = 0; i < index; i++) - if ((command = vector_slot(vline, i))) { - match = - cmd_filter(command, cmd_vector, i, any_match); + for (i = 0; i < index; i++) { + command = vector_slot(vline, i); + if (!command) + continue; - if (match == vararg_match) { - struct cmd_element *cmd_element; - vector descvec; - unsigned int j, k; - - for (j = 0; j < vector_active(cmd_vector); j++) - if ((cmd_element = - vector_slot(cmd_vector, j)) != NULL - && - (vector_active - (cmd_element->strvec))) { - descvec = - vector_slot(cmd_element-> - strvec, - vector_active - (cmd_element-> - strvec) - 1); - for (k = 0; - k < vector_active(descvec); - k++) { - struct desc *desc = - vector_slot(descvec, - k); - vector_set(matchvec, - desc); - } + match = cmd_filter(command, cmd_vector, i, any_match); + + if (match == vararg_match) { + struct cmd_element *cmd_element; + vector descvec; + unsigned int j, k; + + for (j = 0; j < vector_active(cmd_vector); j++) + if ((cmd_element = + vector_slot(cmd_vector, j)) != NULL + && + (vector_active(cmd_element->strvec))) { + descvec = + vector_slot(cmd_element-> + strvec, + vector_active + (cmd_element-> + strvec) - 1); + for (k = 0; + k < vector_active(descvec); + k++) { + struct desc *desc = + vector_slot(descvec, + k); + vector_set(matchvec, + desc); } + } - vector_set(matchvec, &desc_cr); - vector_free(cmd_vector); + vector_set(matchvec, &desc_cr); + 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 */ /* 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); /* Make description vector. */ - for (i = 0; i < vector_active(cmd_vector); i++) - if ((cmd_element = vector_slot(cmd_vector, i)) != NULL) { - const char *string = NULL; - vector strvec = cmd_element->strvec; + for (i = 0; i < vector_active(cmd_vector); i++) { + const char *string = NULL; + vector strvec; - /* if command is NULL, index may be equal to vector_active */ - if (command && index >= vector_active(strvec)) - vector_slot(cmd_vector, i) = NULL; - else { - /* Check if command is completed. */ - if (command == NULL - && index == vector_active(strvec)) { - string = ""; - 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); - j++) - if ((desc = - vector_slot(descvec, j))) { - string = - cmd_entry_function_desc - (command, - desc->cmd); - if (string) { - /* Uniqueness check */ - if (!desc_unique_string(matchvec, string)) - vector_set - (matchvec, - desc); - } - } + cmd_element = vector_slot(cmd_vector, i); + if (!cmd_element) + continue; + + strvec = cmd_element->strvec; + + /* if command is NULL, index may be equal to vector_active */ + if (command && index >= vector_active(strvec)) + vector_slot(cmd_vector, i) = NULL; + else { + /* Check if command is completed. */ + if (command == NULL + && index == vector_active(strvec)) { + string = ""; + 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); 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); if (vector_slot(matchvec, 0) == NULL) { -- cgit v1.2.3