Revision
15956
Author
anthm
Date
2009-12-14 18:19:30 -0600 (Mon, 14 Dec 2009)

Log Message

bowl over previous commit that nearly conflicted out 2 hours of coding (grrr) hook new complete api up to FSAPI and export tab completion down to fs_cli

Modified Paths

Diff

Modified: freeswitch/trunk/libs/esl/fs_cli.c (15955 => 15956)


--- freeswitch/trunk/libs/esl/fs_cli.c	2009-12-14 22:36:39 UTC (rev 15955)
+++ freeswitch/trunk/libs/esl/fs_cli.c	2009-12-15 00:19:30 UTC (rev 15956)
@@ -428,6 +428,57 @@
 }
 
 
+#ifdef HAVE_EDITLINE
+
+static unsigned char complete(EditLine * el, int ch)
+{
+	const LineInfo *lf = el_line(el);
+	char cmd_str[2048] = "";
+	unsigned char ret = CC_REDISPLAY;
+
+	if (*lf->cursor) {
+		snprintf(cmd_str, sizeof(cmd_str), "api console_complete c=%ld;%s\n\n", lf->cursor - lf->buffer, lf->buffer);
+	} else {
+		snprintf(cmd_str, sizeof(cmd_str), "api console_complete %s\n\n", lf->buffer);
+	}
+
+	esl_send_recv(global_handle, cmd_str);
+
+
+	if (global_handle->last_sr_event && global_handle->last_sr_event->body) {
+		char *r = global_handle->last_sr_event->body;
+		char *w, *p;
+		
+		if (r) {
+			if ((w = strstr(r, "\n\nwrite="))) {
+				int len = 0;
+				*w = '\0';
+				w += 8;
+
+				len = atoi(w);
+
+				if ((p = strchr(w, ':'))) {
+					w = p + 1;
+				}
+				
+				printf("%s\n\n\n", r);
+
+				el_deletestr(el, len);
+				el_insertstr(el, w);
+				
+			} else {
+				printf("%s\n", r);
+			}
+		}
+
+		fflush(stdout);
+	}	
+
+	return ret;
+}
+#endif
+
+
 int main(int argc, char *argv[])
 {
 	esl_handle_t handle = {{0}};
@@ -673,6 +724,7 @@
 	el = el_init(__FILE__, stdout, stdout, stdout);
 	el_set(el, EL_PROMPT, &prompt);
 	el_set(el, EL_EDITOR, "emacs");
+
 	myhistory = history_init();
 
 	el_set(el, EL_ADDFN, "f1-key", "F1 KEY PRESS", console_f1key);
@@ -711,6 +763,9 @@
 
 	el_set(el, EL_BIND, "\004", "EOF-key", NULL);
 
+	el_set(el, EL_ADDFN, "ed-complete", "Complete argument", complete);
+	el_set(el, EL_BIND, "^I", "ed-complete", NULL);
+
 	if (myhistory == 0) {
 		esl_log(ESL_LOG_ERROR, "history could not be initialized\n");
 		goto done;

Modified: freeswitch/trunk/src/include/switch_console.h (15955 => 15956)


--- freeswitch/trunk/src/include/switch_console.h	2009-12-14 22:36:39 UTC (rev 15955)
+++ freeswitch/trunk/src/include/switch_console.h	2009-12-15 00:19:30 UTC (rev 15956)
@@ -82,9 +82,10 @@
 SWITCH_DECLARE(switch_status_t) switch_console_add_complete_func(const char *name, switch_console_complete_callback_t cb);
 SWITCH_DECLARE(switch_status_t) switch_console_del_complete_func(const char *name);
 SWITCH_DECLARE(switch_status_t) switch_console_run_complete_func(const char *func, const char *line, 
-																 const char *cursor, switch_console_callback_match_t **matches);
+																 const char *last_word, switch_console_callback_match_t **matches);
 SWITCH_DECLARE(void) switch_console_push_match(switch_console_callback_match_t **matches, const char *new_val);
 SWITCH_DECLARE(void) switch_console_free_matches(switch_console_callback_match_t **matches);
+SWITCH_DECLARE(unsigned char) switch_console_complete(const char *line, const char *last_word, FILE *console_out, switch_stream_handle_t *stream);
 
 SWITCH_END_EXTERN_C
 #endif

Modified: freeswitch/trunk/src/mod/applications/mod_commands/mod_commands.c (15955 => 15956)


--- freeswitch/trunk/src/mod/applications/mod_commands/mod_commands.c	2009-12-14 22:36:39 UTC (rev 15955)
+++ freeswitch/trunk/src/mod/applications/mod_commands/mod_commands.c	2009-12-15 00:19:30 UTC (rev 15956)
@@ -767,7 +767,29 @@
 	return SWITCH_STATUS_SUCCESS;
 }
 
+SWITCH_STANDARD_API(console_complete_function)
+{
+	const char *p, *cursor = NULL;
+	int c;
 
+	if (zstr(cmd)) {
+		cmd = " ";
+	}
+	
+	if ((p = strstr(cmd, "c="))) {
+		p += 2;
+		c = atoi(p);
+		if ((p = strchr(p, ';'))) {
+			cmd = p + 1;
+			cursor = cmd + c;
+		}
+	}
+
+	switch_console_complete(cmd, cursor, NULL, stream);
+	return SWITCH_STATUS_SUCCESS;
+}
+
+
 SWITCH_STANDARD_API(eval_function)
 {
 	char *expanded;
@@ -3791,6 +3813,7 @@
 	SWITCH_ADD_API(commands_api_interface, "break", "Break", break_function, BREAK_SYNTAX);
 	SWITCH_ADD_API(commands_api_interface, "complete", "Complete", complete_function, COMPLETE_SYNTAX);
 	SWITCH_ADD_API(commands_api_interface, "cond", "Eval a conditional", cond_function, "<expr> ? <true val> : <false val>");
+	SWITCH_ADD_API(commands_api_interface, "console_complete", "", console_complete_function, "<line>");
 	SWITCH_ADD_API(commands_api_interface, "create_uuid", "Create a uuid", uuid_function, UUID_SYNTAX);
 	SWITCH_ADD_API(commands_api_interface, "db_cache", "db cache management", db_cache_function, "status");
 	SWITCH_ADD_API(commands_api_interface, "domain_exists", "check if a domain exists", domain_exists_function, "<domain>");