Revision
15986
Author
anthm
Date
2009-12-17 11:43:40 -0600 (Thu, 17 Dec 2009)

Log Message

auto remove spaces from tab completion

Modified Paths

Diff

Modified: freeswitch/trunk/libs/esl/fs_cli.c (15985 => 15986)


--- freeswitch/trunk/libs/esl/fs_cli.c	2009-12-17 16:53:25 UTC (rev 15985)
+++ freeswitch/trunk/libs/esl/fs_cli.c	2009-12-17 17:43:40 UTC (rev 15986)
@@ -429,17 +429,57 @@
 
 
 #ifdef HAVE_EDITLINE
+#define end_of_p(_s) (*_s == '\0' ? _s : _s + strlen(_s) - 1)
 
 static unsigned char complete(EditLine * el, int ch)
 {
 	const LineInfo *lf = el_line(el);
 	char cmd_str[2048] = "";
 	unsigned char ret = CC_REDISPLAY;
+	char *dup = strdup(lf->buffer);
+	char *buf = dup;
+	int pos = 0, sc = 0;
+	char *p;
 
+	if (!esl_strlen_zero(lf->cursor) && !esl_strlen_zero(lf->buffer)) {
+		pos = (lf->cursor - lf->buffer);
+	}
+	if (pos > 0) {
+		*(buf + pos) = '\0';
+	}
+
+	if ((p = strchr(buf, '\r')) || (p = strchr(buf, '\n'))) {
+		*p = '\0';
+	}
+
+	while (*buf == ' ') {
+		buf++;
+		sc++;
+	}
+	
+	if (!*buf && sc) {
+		el_deletestr(el, sc);
+	}
+
+	sc = 0;
+
+	p = end_of_p(buf);
+	while(p >= buf && *p == ' ') {
+		sc++;
+		p--;
+	}
+
+	if (sc > 1) {
+		el_deletestr(el, sc - 1);
+		*(p + 2) = '\0';
+	}
+
+	
+
 	if (*lf->cursor) {
-		snprintf(cmd_str, sizeof(cmd_str), "api console_complete c=%ld;%s\n\n", (long int)(lf->cursor - lf->buffer), lf->buffer);
+		snprintf(cmd_str, sizeof(cmd_str), "api console_complete c=%ld;%s\n\n", (long)pos, buf);
 	} else {
-		snprintf(cmd_str, sizeof(cmd_str), "api console_complete %s\n\n", lf->buffer);
+		snprintf(cmd_str, sizeof(cmd_str), "api console_complete %s\n\n", buf);
 	}
 
 	esl_send_recv(global_handle, cmd_str);
@@ -474,6 +514,8 @@
 		fflush(stdout);
 	}	
 
+	esl_safe_free(dup);
+
 	return ret;
 }
 #endif

Modified: freeswitch/trunk/src/switch_console.c (15985 => 15986)


--- freeswitch/trunk/src/switch_console.c	2009-12-17 16:53:25 UTC (rev 15985)
+++ freeswitch/trunk/src/switch_console.c	2009-12-17 17:43:40 UTC (rev 15986)
@@ -540,7 +540,8 @@
 	struct helper h = { 0 };
 	unsigned char ret = CC_REDISPLAY;
 	int pos = 0;
-
+	int sc = 0;
+	
 #ifndef SWITCH_HAVE_LIBEDIT
 	if (!stream) {
 		return CC_ERROR;
@@ -566,17 +567,43 @@
 	}
 
 	while (*buf == ' ') {
+		sc++;
 		buf++;
 	}
 
+	if (!*buf) {
+#ifdef SWITCH_HAVE_LIBEDIT
+		if (h.out && sc) {
+			el_deletestr(el, sc);
+		}
+#endif
+	} 
+
+	sc = 0;
+	p = end_of_p(buf);
+	while(p >= buf && *p == ' ') {
+		sc++;
+		p--;
+	}
+
+	if (sc > 1) {
+#ifdef SWITCH_HAVE_LIBEDIT
+		if (h.out) {
+			el_deletestr(el, sc - 1);
+		}
+#endif
+		*(p + 2) = '\0';
+	}
+
 	for (p = buf; p && *p; p++) {
 		if (*p == ' ') {
 			lp = p;
 			h.words++;
 			while(*p == ' ') p++;
+			if (!*p) break;
 		}
 	}
-
+	
 	if (lp) {
 		buf = lp + 1;
 	}
@@ -591,6 +618,8 @@
 		h.stream->write_function(h.stream, "\n\n");
 	}
 
+
+
 	if (h.words == 0) {
 		sql = switch_mprintf("select distinct name from interfaces where type='api' and name like '%q%%' and hostname='%q' order by name", 
 							 buf, switch_core_get_variable("hostname"));
@@ -670,7 +699,7 @@
 	if (h.out) {
 		fprintf(h.out, "\n\n");
 	}
-	
+
 	if (h.stream) {
 		h.stream->write_function(h.stream, "\n\n");
 		if (h.hits == 1 && !zstr(h.last)) {