[asterisk-commits] russell: branch russell/indications r176140 - /team/russell/indications/main/

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Mon Feb 16 11:53:09 CST 2009


Author: russell
Date: Mon Feb 16 11:53:09 2009
New Revision: 176140

URL: http://svn.digium.com/svn-view/asterisk?view=rev&rev=176140
Log:
Add tab completion to indications CLI commands

Modified:
    team/russell/indications/main/indications.c

Modified: team/russell/indications/main/indications.c
URL: http://svn.digium.com/svn-view/asterisk/team/russell/indications/main/indications.c?view=diff&rev=176140&r1=176139&r2=176140
==============================================================================
--- team/russell/indications/main/indications.c (original)
+++ team/russell/indications/main/indications.c Mon Feb 16 11:53:09 2009
@@ -619,6 +619,30 @@
 	return ao2_alloc(sizeof(struct ast_tone_zone), ast_tone_zone_destructor);
 }
 
+static char *complete_country(struct ast_cli_args *a)
+{
+	char *res = NULL;
+	struct ao2_iterator i;
+	int which = 0;
+	size_t wordlen;
+	struct ast_tone_zone *tz;
+
+	wordlen = strlen(a->word);
+
+	i = ao2_iterator_init(ast_tone_zones, 0);
+	while ((tz = ao2_iterator_next(&i))) {
+		if (!strncasecmp(a->word, tz->country, wordlen) && ++which > a->n) {
+			res = ast_strdup(tz->country);
+		}
+		tz = ast_tone_zone_unref(tz);
+		if (res) {
+			break;
+		}
+	}
+
+	return res;
+}
+
 static char *handle_cli_indication_add(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
 {
 	struct ast_tone_zone *tz;
@@ -633,7 +657,11 @@
 			"       Add the given indication to the country.\n";
 		return NULL;
 	case CLI_GENERATE:
-		return NULL;
+		if (a->pos == 2) {
+			return complete_country(a);
+		} else {
+			return NULL;
+		}
 	}
 
 	if (a->argc != 5) {
@@ -669,6 +697,38 @@
 		res = CLI_FAILURE;
 	}
 
+	ast_tone_zone_unlock(tz);
+
+	tz = ast_tone_zone_unref(tz);
+
+	return res;
+}
+
+static char *complete_indications(struct ast_cli_args *a)
+{
+	char *res = NULL;
+	int which = 0;
+	size_t wordlen;
+	struct ast_tone_zone_sound *ts;
+	struct ast_tone_zone *tz, tmp_tz = {
+		.nrringcadence = 0,
+	};
+
+	ast_copy_string(tmp_tz.country, a->argv[a->pos - 1], sizeof(tmp_tz.country));
+
+	if (!(tz = ao2_find(ast_tone_zones, &tmp_tz, OBJ_POINTER))) {
+		return NULL;
+	}
+
+	wordlen = strlen(a->word);
+
+	ast_tone_zone_lock(tz);
+	AST_LIST_TRAVERSE(&tz->tones, ts, entry) {
+		if (!strncasecmp(a->word, ts->name, wordlen) && ++which > a->n) {
+			res = ast_strdup(ts->name);
+			break;
+		}
+	}
 	ast_tone_zone_unlock(tz);
 
 	tz = ast_tone_zone_unref(tz);
@@ -689,7 +749,11 @@
 			"       Remove the given indication from the country.\n";
 		return NULL;
 	case CLI_GENERATE:
-		return NULL;
+		if (a->pos == 2) {
+			return complete_country(a);
+		} else if (a->pos == 3) {
+			return complete_indications(a);
+		}
 	}
 
 	if (a->argc != 3 && a->argc != 4) {
@@ -737,7 +801,7 @@
 			"       more verbose list of indications for the specified countries.\n";
 		return NULL;
 	case CLI_GENERATE:
-		return NULL;
+		return complete_country(a);
 	}
 
 	if (a->argc == 2) {




More information about the asterisk-commits mailing list