ldlinux, cli: Add support for F-keys
authorMatt Fleming <matt.fleming@linux.intel.com>
Thu, 31 Mar 2011 13:50:19 +0000 (14:50 +0100)
committerMatt Fleming <matt.fleming@linux.intel.com>
Fri, 1 Apr 2011 08:58:02 +0000 (09:58 +0100)
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@linux.intel.com>
com32/elflink/ldlinux/config.h
com32/elflink/ldlinux/ldlinux.c
com32/elflink/ldlinux/readconfig.c

index 37c57da..8f708f1 100644 (file)
@@ -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__ */
index 85066b1..1177ef5 100644 (file)
@@ -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 */
index a29c6c6..66e84df 100644 (file)
@@ -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;