aboutsummaryrefslogtreecommitdiffstats
path: root/src/vty/command.c
diff options
context:
space:
mode:
authorPau Espin Pedrol <pespin@sysmocom.de>2019-06-12 13:06:41 +0200
committerpespin <pespin@sysmocom.de>2019-06-12 14:25:11 +0000
commit274ac4dcc3c74f1ff0efcb1cee68c737bfa37044 (patch)
tree3bd033ce0ef59e411cdce701992b60c4e7532d1a /src/vty/command.c
parentde89099f68c5a0c5dea18a877f3bbb58d943e9d6 (diff)
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
Diffstat (limited to 'src/vty/command.c')
-rw-r--r--src/vty/command.c185
1 files changed, 94 insertions, 91 deletions
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)