[syslinux:elflink] ldlinux, cli: Add support for F-keys

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


Commit-ID:  f97510383b700984948ad4a1c961b67501a2ac48
Gitweb:     http://syslinux.zytor.com/commit/f97510383b700984948ad4a1c961b67501a2ac48
Author:     Matt Fleming <matt.fleming at linux.intel.com>
AuthorDate: Thu, 31 Mar 2011 14:50:19 +0100
Committer:  Matt Fleming <matt.fleming at linux.intel.com>
CommitDate: Fri, 1 Apr 2011 09:58:02 +0100

ldlinux, cli: Add support for F-keys

The old asm command-line interface had support for printing files
containing help messages when the F-keys (F1-F10) were pressed. Add
this support to ldlinux.

The config parser already had support for parsing config files with
F-key directives and the cli code already had support for executing
callbacks when one of the F-keys was hit, so this patch simply glues
all the pieces together and provides a function to cat the help file.

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


---
 com32/elflink/ldlinux/config.h     |    2 +
 com32/elflink/ldlinux/ldlinux.c    |    2 +-
 com32/elflink/ldlinux/readconfig.c |   73 ++++++++++++++++++++++++++++++++++++
 3 files changed, 76 insertions(+), 1 deletions(-)

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 a29c6c6..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},
@@ -617,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;



More information about the Syslinux-commits mailing list