[syslinux:elflink] elflink, cli: TAB key now displays labels

syslinux-bot for Matt Fleming matt.fleming at linux.intel.com
Mon Apr 4 14:15:11 PDT 2011


Commit-ID:  f8d263e69d65c4257a49bc1a70428e89d492e361
Gitweb:     http://syslinux.zytor.com/commit/f8d263e69d65c4257a49bc1a70428e89d492e361
Author:     Matt Fleming <matt.fleming at linux.intel.com>
AuthorDate: Tue, 29 Mar 2011 13:06:16 +0100
Committer:  Matt Fleming <matt.fleming at linux.intel.com>
CommitDate: Tue, 29 Mar 2011 14:27:02 +0100

elflink, cli: TAB key now displays labels

Now, if the user hits the TAB key at a prompt a list of all labels to
complete the current label typed on the command-line is printed. If
nothing is typed at the command-line all labels are printed.

This feature is available in the asm command-line interface so lets
make it available in the C version.

Signed-off-by: Matt Fleming <matt.fleming at linux.intel.com>


---
 com32/elflink/ldlinux/cli.c        |   21 +++++++++++++++++++++
 com32/elflink/ldlinux/readconfig.c |   11 +++++++++++
 com32/elflink/modules/menu.h       |    2 ++
 3 files changed, 34 insertions(+), 0 deletions(-)

diff --git a/com32/elflink/ldlinux/cli.c b/com32/elflink/ldlinux/cli.c
index 172a9f6..0884525 100644
--- a/com32/elflink/ldlinux/cli.c
+++ b/com32/elflink/ldlinux/cli.c
@@ -18,6 +18,7 @@
 #include "getkey.h"
 #include "menu.h"
 #include "cli.h"
+#include "config.h"
 
 static jmp_buf timeout_jump;
 
@@ -394,6 +395,26 @@ const char *edit_cmdline(const char *input, int top /*, int width */ ,
 	        redraw = 1;
 	    }
 	    break;
+	case KEY_TAB:
+	    {
+		const char *p;
+		size_t len;
+
+		/* Label completion enabled? */
+		if (nocomplete)
+	            break;
+
+		p = cmdline;
+		len = 0;
+		while(*p && !my_isspace(*p)) {
+		    p++;
+		    len++;
+		}
+
+		print_labels(cmdline, len);
+		redraw = 1;
+		break;
+	    }
 
 	default:
 	    if (key >= ' ' && key <= 0xFF && len < MAX_CMDLINE_LEN - 1) {
diff --git a/com32/elflink/ldlinux/readconfig.c b/com32/elflink/ldlinux/readconfig.c
index e13d6d4..a29c6c6 100644
--- a/com32/elflink/ldlinux/readconfig.c
+++ b/com32/elflink/ldlinux/readconfig.c
@@ -420,6 +420,17 @@ static struct menu *end_submenu(void)
     return current_menu->parent ? current_menu->parent : current_menu;
 }
 
+void print_labels(const char *prefix, size_t len)
+{
+    struct menu_entry *me;
+
+    printf("\n");
+    for (me = all_entries; me; me = me->next ) {
+	if (!strncmp(prefix, me->label, len))
+	    printf(" %s\n", me->label);
+    }
+}
+
 static struct menu_entry *find_label(const char *str)
 {
     const char *p;
diff --git a/com32/elflink/modules/menu.h b/com32/elflink/modules/menu.h
index 90b54a5..8041fc9 100644
--- a/com32/elflink/modules/menu.h
+++ b/com32/elflink/modules/menu.h
@@ -184,6 +184,8 @@ extern const int message_base_color, menu_color_table_size;
 int mygetkey(clock_t timeout);
 int show_message_file(const char *filename, const char *background);
 
+extern void print_labels(const char *prefix, size_t len);
+
 /* passwd.c */
 int passwd_compare(const char *passwd, const char *entry);
 



More information about the Syslinux-commits mailing list