[syslinux] [GIT PULL] elflink cmdline

Matt Fleming matt at console-pimps.org
Fri Apr 1 02:43:13 PDT 2011


Hi,

The following patches are just copying some functionality that exists
in the asm cmdline code into the C version. There's still a few more
things to do but we're getting there.

The following changes since commit 8c576f1fe03e34879921311f46613a35c6530000:

  Merge remote-tracking branch 'mfleming/for-hpa/elflink/fix-compiler-warnings' into elflink (2011-03-16 12:53:58 -0700)

are available in the git repository at:

  git://git.zytor.com/users/mfleming/syslinux.git for-hpa/elflink/cmdline

Matt Fleming (2):
      elflink, cli: TAB key now displays labels
      ldlinux, cli: Add support for F-keys

 com32/elflink/ldlinux/cli.c        |   21 +++++++++
 com32/elflink/ldlinux/config.h     |    2 +
 com32/elflink/ldlinux/ldlinux.c    |    2 +-
 com32/elflink/ldlinux/readconfig.c |   84 ++++++++++++++++++++++++++++++++++++
 com32/elflink/modules/menu.h       |    2 +
 5 files changed, 110 insertions(+), 1 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/config.h b/com32/elflink/ldlinux/config.h
index 37c57da..8f708f1 100644
--- a/com32/elflink/ldlinux/config.h
+++ b/com32/elflink/ldlinux/config.h
@@ -36,4 +36,6 @@ extern short nohalt;		//idle.inc
 extern const char *default_cmd;	//"default" command line
 extern const char *onerror;	//"onerror" command line
 
+extern void cat_help_file(int key);
+
 #endif /* __CONFIG_H__ */
diff --git a/com32/elflink/ldlinux/ldlinux.c b/com32/elflink/ldlinux/ldlinux.c
index 85066b1..1177ef5 100644
--- a/com32/elflink/ldlinux/ldlinux.c
+++ b/com32/elflink/ldlinux/ldlinux.c
@@ -17,7 +17,7 @@ static void enter_cmdline(void)
 
 	/* Enter endless command line prompt, should support "exit" */
 	while (1) {
-		cmdline = edit_cmdline("syslinux$", 1, NULL, NULL);
+		cmdline = edit_cmdline("syslinux$", 1, NULL, cat_help_file);
 		if (!cmdline)
 			continue;
 		/* feng: give up the aux check here */
diff --git a/com32/elflink/ldlinux/readconfig.c b/com32/elflink/ldlinux/readconfig.c
index e13d6d4..66e84df 100644
--- a/com32/elflink/ldlinux/readconfig.c
+++ b/com32/elflink/ldlinux/readconfig.c
@@ -27,6 +27,7 @@
 
 #include "menu.h"
 #include "config.h"
+#include "getkey.h"
 
 const struct menu_parameter mparm[NPARAMS] = {
     [P_WIDTH] = {"width", 0},
@@ -420,6 +421,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;
@@ -606,6 +618,78 @@ static char *is_message_name(char *cmdstr, enum message_number *msgnr)
     return NULL;
 }
 
+static int cat_file(const char *filename)
+{
+	FILE *f;
+	char line[2048];
+
+	f = fopen(filename, "r");
+	if (!f)
+		return -1;
+
+	while (fgets(line, sizeof(line), f) != NULL)
+		printf("%s", line);
+
+	fclose(f);
+	return 0;
+}
+
+void cat_help_file(int key)
+{
+	struct menu *cm = current_menu;
+	int fkey;
+
+	switch (key) {
+	case KEY_F1:
+		fkey = 0;
+		break;
+	case KEY_F2:
+		fkey = 1;
+		break;
+	case KEY_F3:
+		fkey = 2;
+		break;
+	case KEY_F4:
+		fkey = 3;
+		break;
+	case KEY_F5:
+		fkey = 4;
+		break;
+	case KEY_F6:
+		fkey = 5;
+		break;
+	case KEY_F7:
+		fkey = 6;
+		break;
+	case KEY_F8:
+		fkey = 7;
+		break;
+	case KEY_F9:
+		fkey = 8;
+		break;
+	case KEY_F10:
+		fkey = 9;
+		break;
+	case KEY_F11:
+		fkey = 10;
+		break;
+	case KEY_F12:
+		fkey = 11;
+		break;
+	default:
+		fkey = -1;
+		break;
+	}
+
+	if (fkey == -1)
+		return;
+
+	if (cm->fkeyhelp[fkey].textname) {
+		printf("\n");
+		cat_file(cm->fkeyhelp[fkey].textname);
+	}
+}
+
 static char *is_fkey(char *cmdstr, int *fkeyno)
 {
     char *q;
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 mailing list