From 274ac4dcc3c74f1ff0efcb1cee68c737bfa37044 Mon Sep 17 00:00:00 2001 From: Pau Espin Pedrol Date: Wed, 12 Jun 2019 13:06:41 +0200 Subject: vty: command.c: Get rid of huge indentation block Huge conditional block inside for loop is negated in this patch together with a "continue" keyword, similar to what was already done recently in 4742526645d6137dd90ef369f0415afdb91736dc. Change-Id: I803c4ed38e9ab09bf929528c75a60e6f65da3928 --- src/vty/command.c | 185 +++++++++++++++++++++++++++--------------------------- 1 file changed, 94 insertions(+), 91 deletions(-) (limited to 'src/vty/command.c') diff --git a/src/vty/command.c b/src/vty/command.c index 104053ff..4189c7c0 100644 --- a/src/vty/command.c +++ b/src/vty/command.c @@ -1510,109 +1510,112 @@ is_cmd_ambiguous(char *command, vector v, int index, enum match_type type) * or ambiguities to cause a noticeable memory footprint from keeping all allocations. */ void *cmd_deopt_ctx = NULL; - for (i = 0; i < vector_active(v); i++) - if ((cmd_element = vector_slot(v, i)) != NULL) { - int match = 0; + for (i = 0; i < vector_active(v); i++) { + cmd_element = vector_slot(v, i); + if (!cmd_element) + continue; - descvec = vector_slot(cmd_element->strvec, index); + int match = 0; - for (j = 0; j < vector_active(descvec); j++) { - desc = vector_slot(descvec, j); - if (!desc) - continue; + descvec = vector_slot(cmd_element->strvec, index); - enum match_type mtype; - const char *str = desc->cmd; + for (j = 0; j < vector_active(descvec); j++) { + desc = vector_slot(descvec, j); + if (!desc) + continue; - if (CMD_OPTION(str)) { - if (!cmd_deopt_ctx) - cmd_deopt_ctx = - talloc_named_const(tall_vty_cmd_ctx, 0, - __func__); - str = cmd_deopt(cmd_deopt_ctx, str); - if (str == NULL) - continue; - } + enum match_type mtype; + const char *str = desc->cmd; - switch (type) { - case EXACT_MATCH: - if (!(CMD_VARIABLE (str)) - && strcmp(command, str) == 0) - match++; - break; - case PARTLY_MATCH: - if (!(CMD_VARIABLE (str)) - && strncmp(command, str, strlen (command)) == 0) - { - if (matched - && strcmp(matched, - str) != 0) { - ret = 1; /* There is ambiguous match. */ - goto free_and_return; - } else - matched = str; - match++; - } - break; - case RANGE_MATCH: - if (cmd_range_match - (str, command)) { - if (matched - && strcmp(matched, - str) != 0) { - ret = 1; - goto free_and_return; - } else - matched = str; - match++; - } - break; -#ifdef HAVE_IPV6 - case IPV6_MATCH: - if (CMD_IPV6(str)) - match++; - break; - case IPV6_PREFIX_MATCH: - if ((mtype = - cmd_ipv6_prefix_match - (command)) != NO_MATCH) { - if (mtype == PARTLY_MATCH) { - ret = 2; /* There is incomplete match. */ - goto free_and_return; - } + if (CMD_OPTION(str)) { + if (!cmd_deopt_ctx) + cmd_deopt_ctx = + talloc_named_const(tall_vty_cmd_ctx, 0, + __func__); + str = cmd_deopt(cmd_deopt_ctx, str); + if (str == NULL) + continue; + } - match++; + switch (type) { + case EXACT_MATCH: + if (!(CMD_VARIABLE (str)) + && strcmp(command, str) == 0) + match++; + break; + case PARTLY_MATCH: + if (!(CMD_VARIABLE (str)) + && strncmp(command, str, strlen (command)) == 0) + { + if (matched + && strcmp(matched, + str) != 0) { + ret = 1; /* There is ambiguous match. */ + goto free_and_return; + } else + matched = str; + match++; + } + break; + case RANGE_MATCH: + if (cmd_range_match + (str, command)) { + if (matched + && strcmp(matched, + str) != 0) { + ret = 1; + goto free_and_return; + } else + matched = str; + match++; + } + break; +#ifdef HAVE_IPV6 + case IPV6_MATCH: + if (CMD_IPV6(str)) + match++; + break; + case IPV6_PREFIX_MATCH: + if ((mtype = + cmd_ipv6_prefix_match + (command)) != NO_MATCH) { + if (mtype == PARTLY_MATCH) { + ret = 2; /* There is incomplete match. */ + goto free_and_return; } - break; -#endif /* HAVE_IPV6 */ - case IPV4_MATCH: - if (CMD_IPV4(str)) - match++; - break; - case IPV4_PREFIX_MATCH: - if ((mtype = - cmd_ipv4_prefix_match - (command)) != NO_MATCH) { - if (mtype == PARTLY_MATCH) { - ret = 2; /* There is incomplete match. */ - goto free_and_return; - } - match++; + match++; + } + break; +#endif /* HAVE_IPV6 */ + case IPV4_MATCH: + if (CMD_IPV4(str)) + match++; + break; + case IPV4_PREFIX_MATCH: + if ((mtype = + cmd_ipv4_prefix_match + (command)) != NO_MATCH) { + if (mtype == PARTLY_MATCH) { + ret = 2; /* There is incomplete match. */ + goto free_and_return; } - break; - case EXTEND_MATCH: - if (CMD_VARIABLE (str)) - match++; - break; - case NO_MATCH: - default: - break; + + match++; } + break; + case EXTEND_MATCH: + if (CMD_VARIABLE (str)) + match++; + break; + case NO_MATCH: + default: + break; } - if (!match) - vector_slot(v, i) = NULL; } + if (!match) + vector_slot(v, i) = NULL; + } free_and_return: if (cmd_deopt_ctx) -- cgit v1.2.3