aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorprofkhaos <profkhaos@Khaos-Phantom.(none)>2009-08-17 17:49:57 +0300
committerprofkhaos <profkhaos@Khaos-Phantom.(none)>2009-08-17 17:49:57 +0300
commit97f408c190b315e3bc42d59a5f1fb9bd37afe9f4 (patch)
tree8b8b4fdaa993abd637ce617390a673ceda0ccee3
parentffa9c1e37afc2a805b5ad2d314bcde9eb1886919 (diff)
downloadsyslinux-97f408c190b315e3bc42d59a5f1fb9bd37afe9f4.tar.gz
syslinux-97f408c190b315e3bc42d59a5f1fb9bd37afe9f4.tar.xz
syslinux-97f408c190b315e3bc42d59a5f1fb9bd37afe9f4.zip
Initial cli with history
-rw-r--r--com32/elflink/modules/cli.h10
-rw-r--r--core/elflink/cli.c51
-rw-r--r--core/elflink/cli.h10
-rw-r--r--core/elflink/load_env32.c16
4 files changed, 82 insertions, 5 deletions
diff --git a/com32/elflink/modules/cli.h b/com32/elflink/modules/cli.h
index 8674cfc6..b71c894d 100644
--- a/com32/elflink/modules/cli.h
+++ b/com32/elflink/modules/cli.h
@@ -1,6 +1,16 @@
#ifndef CLI_H
#define CLI_H
+#define MAX_CMD_HISTORY 64
+
+struct cli_command
+{
+ struct list_head list;
+ char command[MAX_CMDLINE_LEN];
+};
+
+struct list_head cli_history_head;
+
extern void clear_screen(void);
extern int mygetkey(clock_t timeout);
extern const char *edit_cmdline(const char *input, int top /*, int width */,int (*pDraw_Menu)(int, int, int),void (*show_fkey)(int));
diff --git a/core/elflink/cli.c b/core/elflink/cli.c
index 0fba61cc..11359ea8 100644
--- a/core/elflink/cli.c
+++ b/core/elflink/cli.c
@@ -9,6 +9,7 @@
#include <netinet/in.h>
#include <limits.h>
#include <minmax.h>
+#include <linux/list.h>
#include "getkey.h"
#include "common.h"
@@ -57,13 +58,15 @@ int mygetkey(clock_t timeout)
const char *edit_cmdline(const char *input, int top /*, int width */,int (*pDraw_Menu)(int, int, int),void (*show_fkey)(int))
{
static char cmdline[MAX_CMDLINE_LEN];
+ char temp_cmdline[MAX_CMDLINE_LEN];
int key, len, prev_len, cursor;
int redraw = 1; /* We enter with the menu already drawn */
int x, y;
bool done = false;
const char *ret;
-
int width = 0;
+ struct cli_command *comm_counter;
+ comm_counter=list_entry(cli_history_head.next, typeof(*comm_counter),list);
if (!width) {
int height;
@@ -86,8 +89,7 @@ const char *edit_cmdline(const char *input, int top /*, int width */,int (*pDraw
/* Enable ASCII on G0 and DEC VT on G1; do it in this order
to avoid confusing the Linux console */
/* clear_screen();
- draw_menu(-1, top, 1);
- prev_len = 0;*/
+ draw_menu(-1, top, 1);*/
clear_screen();
(*pDraw_Menu)(-1, top, 1);
prev_len = 0;
@@ -271,12 +273,48 @@ const char *edit_cmdline(const char *input, int top /*, int width */,int (*pDraw
redraw = 1;
}
break;
-
+ case KEY_DOWN:
+ {
+ if(!list_empty(&cli_history_head))
+ {
+ comm_counter=list_entry(comm_counter->list.next, typeof(*comm_counter),list);
+ if(&comm_counter->list==&cli_history_head)
+ {
+ strcpy(cmdline,temp_cmdline);
+ }
+ else
+ {
+ strcpy(cmdline,comm_counter->command);
+ }
+ cursor=len=strlen(cmdline);
+ redraw = 1;
+ }
+ }
+ break;
+ case KEY_UP:
+ {
+ if(!list_empty(&cli_history_head))
+ {
+ comm_counter=list_entry(comm_counter->list.prev, typeof(*comm_counter),list);
+ if(&comm_counter->list==&cli_history_head)
+ {
+ strcpy(cmdline,temp_cmdline);
+ }
+ else
+ {
+ strcpy(cmdline,comm_counter->command);
+ }
+ cursor=len=strlen(cmdline);
+ redraw = 1;
+ }
+ }
+ break;
default:
if (key >= ' ' && key <= 0xFF && len < MAX_CMDLINE_LEN - 1) {
if (cursor == len) {
+ temp_cmdline[len]=key;
cmdline[len++] = key;
- cmdline[len] = '\0';
+ temp_cmdline[len]= cmdline[len] = '\0';
putchar(key);
cursor++;
x++;
@@ -289,6 +327,9 @@ const char *edit_cmdline(const char *input, int top /*, int width */,int (*pDraw
} else {
memmove(cmdline + cursor + 1, cmdline + cursor,
len - cursor + 1);
+ memmove(temp_cmdline + cursor + 1, temp_cmdline + cursor,
+ len - cursor + 1);
+ temp_cmdline[cursor]=key;
cmdline[cursor++] = key;
len++;
redraw = 1;
diff --git a/core/elflink/cli.h b/core/elflink/cli.h
index 8674cfc6..b71c894d 100644
--- a/core/elflink/cli.h
+++ b/core/elflink/cli.h
@@ -1,6 +1,16 @@
#ifndef CLI_H
#define CLI_H
+#define MAX_CMD_HISTORY 64
+
+struct cli_command
+{
+ struct list_head list;
+ char command[MAX_CMDLINE_LEN];
+};
+
+struct list_head cli_history_head;
+
extern void clear_screen(void);
extern int mygetkey(clock_t timeout);
extern const char *edit_cmdline(const char *input, int top /*, int width */,int (*pDraw_Menu)(int, int, int),void (*show_fkey)(int));
diff --git a/core/elflink/load_env32.c b/core/elflink/load_env32.c
index 38af23f9..9e022c69 100644
--- a/core/elflink/load_env32.c
+++ b/core/elflink/load_env32.c
@@ -7,6 +7,7 @@
#include <syslinux/adv.h>
#include <syslinux/config.h>
#include <setjmp.h>
+#include <linux/list.h>
#include <netinet/in.h>
#include <sys/exec.h>
@@ -71,7 +72,22 @@ void load_env32(com32sys_t * regs)
{
call_constr();
char *cmdline;
+ struct cli_command c1,c2,c3,*aux;
openconsole(&dev_rawcon_r, &dev_ansiserial_w);
+ INIT_LIST_HEAD(&cli_history_head);
+
+ strcpy(c1.command,"command 1");
+ strcpy(c2.command,"command 2");
+ strcpy(c3.command,"command 3");
+ list_add(&(c1.list),&cli_history_head);
+ list_add(&(c2.list),&cli_history_head);
+ list_add(&(c3.list),&cli_history_head);
+
+ list_for_each_entry(aux, &cli_history_head, list)
+ {
+ printf("%s\n",aux->command);
+ }
+
printf("Calling initilization constructor procedures...\n");
printf("Starting 32 bit elf module subsystem...\n");
init_module_subsystem(&core_module);