[Asterisk-code-review] main/test: Use ast cli completion add. (asterisk[13])

Corey Farrell asteriskteam at digium.com
Sun Mar 18 17:35:17 CDT 2018


Corey Farrell has uploaded this change for review. ( https://gerrit.asterisk.org/8580


Change subject: main/test: Use ast_cli_completion_add.
......................................................................

main/test: Use ast_cli_completion_add.

Change-Id: I5133ff2ba4e030f9733fb3d050c863d72a22ae6b
---
M main/test.c
1 file changed, 24 insertions(+), 24 deletions(-)



  git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/80/8580/1

diff --git a/main/test.c b/main/test.c
index d22f2eb..df3c081 100644
--- a/main/test.c
+++ b/main/test.c
@@ -693,40 +693,40 @@
 	return test;
 }
 
-static char *complete_test_category(const char *line, const char *word, int pos, int state)
+static char *complete_test_category(const char *word, int pos)
 {
-	int which = 0;
 	int wordlen = strlen(word);
-	char *ret = NULL;
 	struct ast_test *test;
 
 	AST_LIST_LOCK(&tests);
 	AST_LIST_TRAVERSE(&tests, test, entry) {
-		if (!strncasecmp(word, test->info.category, wordlen) && ++which > state) {
-			ret = ast_strdup(test->info.category);
-			break;
+		if (!strncasecmp(word, test->info.category, wordlen)) {
+			if (ast_cli_completion_add(ast_strdup(test->info.category))) {
+				break;
+			}
 		}
 	}
 	AST_LIST_UNLOCK(&tests);
-	return ret;
+
+	return NULL;
 }
 
-static char *complete_test_name(const char *line, const char *word, int pos, int state, const char *category)
+static char *complete_test_name(const char *word, const char *category)
 {
-	int which = 0;
 	int wordlen = strlen(word);
-	char *ret = NULL;
 	struct ast_test *test;
 
 	AST_LIST_LOCK(&tests);
 	AST_LIST_TRAVERSE(&tests, test, entry) {
-		if (!test_cat_cmp(test->info.category, category) && (!strncasecmp(word, test->info.name, wordlen) && ++which > state)) {
-			ret = ast_strdup(test->info.name);
-			break;
+		if (!test_cat_cmp(test->info.category, category) && !strncasecmp(word, test->info.name, wordlen)) {
+			if (ast_cli_completion_add(ast_strdup(test->info.name))) {
+				break;
+			}
 		}
 	}
 	AST_LIST_UNLOCK(&tests);
-	return ret;
+
+	return NULL;
 }
 
 /* CLI commands */
@@ -751,16 +751,16 @@
 		return NULL;
 	case CLI_GENERATE:
 		if (a->pos == 3) {
-			return ast_cli_complete(a->word, option1, a->n);
+			return ast_cli_complete(a->word, option1, -1);
 		}
 		if (a->pos == 4) {
-			return complete_test_category(a->line, a->word, a->pos, a->n);
+			return complete_test_category(a->word, a->pos);
 		}
 		if (a->pos == 5) {
-			return ast_cli_complete(a->word, option2, a->n);
+			return ast_cli_complete(a->word, option2, -1);
 		}
 		if (a->pos == 6) {
-			return complete_test_name(a->line, a->word, a->pos, a->n, a->argv[3]);
+			return complete_test_name(a->word, a->argv[3]);
 		}
 		return NULL;
 	case CLI_HANDLER:
@@ -810,16 +810,16 @@
 		return NULL;
 	case CLI_GENERATE:
 		if (a->pos == 2) {
-			return ast_cli_complete(a->word, option1, a->n);
+			return ast_cli_complete(a->word, option1, -1);
 		}
 		if (a->pos == 3) {
-			return complete_test_category(a->line, a->word, a->pos, a->n);
+			return complete_test_category(a->word, a->pos);
 		}
 		if (a->pos == 4) {
-			return ast_cli_complete(a->word, option2, a->n);
+			return ast_cli_complete(a->word, option2, -1);
 		}
 		if (a->pos == 5) {
-			return complete_test_name(a->line, a->word, a->pos, a->n, a->argv[3]);
+			return complete_test_name(a->word, a->argv[3]);
 		}
 		return NULL;
 	case CLI_HANDLER:
@@ -879,7 +879,7 @@
 		return NULL;
 	case CLI_GENERATE:
 		if (a->pos == 3) {
-			return ast_cli_complete(a->word, option1, a->n);
+			return ast_cli_complete(a->word, option1, -1);
 		}
 		return NULL;
 	case CLI_HANDLER:
@@ -952,7 +952,7 @@
 		return NULL;
 	case CLI_GENERATE:
 		if (a->pos == 3) {
-			return ast_cli_complete(a->word, option, a->n);
+			return ast_cli_complete(a->word, option, -1);
 		}
 		return NULL;
 	case CLI_HANDLER:

-- 
To view, visit https://gerrit.asterisk.org/8580
To unsubscribe, visit https://gerrit.asterisk.org/settings

Gerrit-Project: asterisk
Gerrit-Branch: 13
Gerrit-MessageType: newchange
Gerrit-Change-Id: I5133ff2ba4e030f9733fb3d050c863d72a22ae6b
Gerrit-Change-Number: 8580
Gerrit-PatchSet: 1
Gerrit-Owner: Corey Farrell <git at cfware.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20180318/83ddcf88/attachment.html>


More information about the asterisk-code-review mailing list