Change in ...libosmocore[master]: vty: command.c: Get rid of huge indentation block

This is merely a historical archive of years 2008-2021, before the migration to mailman3.

A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/gerrit-log@lists.osmocom.org/.

pespin gerrit-no-reply at lists.osmocom.org
Wed Jun 12 11:07:38 UTC 2019


pespin has uploaded this change for review. ( https://gerrit.osmocom.org/c/libosmocore/+/14428


Change subject: vty: command.c: Get rid of huge indentation block
......................................................................

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
---
M src/vty/command.c
1 file changed, 101 insertions(+), 98 deletions(-)



  git pull ssh://gerrit.osmocom.org:29418/libosmocore refs/changes/28/14428/1

diff --git a/src/vty/command.c b/src/vty/command.c
index 104053f..4189c7c 100644
--- a/src/vty/command.c
+++ b/src/vty/command.c
@@ -1510,109 +1510,112 @@
 	 * 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)
+		descvec = vector_slot(cmd_element->strvec, index);
+
+		for (j = 0; j < vector_active(descvec); j++) {
+			desc = vector_slot(descvec, j);
+			if (!desc)
+				continue;
+
+			enum match_type mtype;
+			const char *str = desc->cmd;
+
+			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;
-
-				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;
-				}
-
-				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;
-						}
-
-						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;
-						}
-
-						match++;
-					}
-					break;
-				case EXTEND_MATCH:
-					if (CMD_VARIABLE (str))
-						match++;
-					break;
-				case NO_MATCH:
-				default:
-					break;
-				}
 			}
-			if (!match)
-				vector_slot(v, i) = NULL;
+
+			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;
+					}
+
+					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;
+					}
+
+					match++;
+				}
+				break;
+			case EXTEND_MATCH:
+				if (CMD_VARIABLE (str))
+					match++;
+				break;
+			case NO_MATCH:
+			default:
+				break;
+			}
 		}
+		if (!match)
+			vector_slot(v, i) = NULL;
+	}
 
 free_and_return:
 	if (cmd_deopt_ctx)

-- 
To view, visit https://gerrit.osmocom.org/c/libosmocore/+/14428
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings

Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-Change-Id: I803c4ed38e9ab09bf929528c75a60e6f65da3928
Gerrit-Change-Number: 14428
Gerrit-PatchSet: 1
Gerrit-Owner: pespin <pespin at sysmocom.de>
Gerrit-MessageType: newchange
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20190612/591dd852/attachment.htm>


More information about the gerrit-log mailing list