From 5094cf34a2a7a5d0cdd273434b7ffdeff6518994 Mon Sep 17 00:00:00 2001 From: mr_chocha <49686817+mrchocha@users.noreply.github.com> Date: Sun, 8 Nov 2020 19:53:59 +0530 Subject: [PATCH 1/3] add history command --- src/kernel/kshell.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/kernel/kshell.c b/src/kernel/kshell.c index 0278399..b492d2e 100644 --- a/src/kernel/kshell.c +++ b/src/kernel/kshell.c @@ -107,6 +107,9 @@ bool alt_mode = false; bool ctrl_mode = false; bool super_mode = false; +char history_data[100][RDL_SIZE]; +uint8_t tot_cmds=0; + void run_cmd(char *run) { if (!(strncmp(run, "page 0x", 7))) { show_page_table_layout_for_address(hex2int(run+7)); @@ -135,6 +138,13 @@ void run_cmd(char *run) { } } else if (!strncmp(run, "tree ", 5)) { tree(run + 5); + } + else if (!strncmp(run, "history", 7)){ + for(int i=0;i Date: Wed, 2 Dec 2020 15:39:13 +0530 Subject: [PATCH 2/3] Update kshell.c --- src/kernel/kshell.c | 77 ++++++++++++++++++++++++++++++++++++++------- 1 file changed, 65 insertions(+), 12 deletions(-) diff --git a/src/kernel/kshell.c b/src/kernel/kshell.c index b492d2e..559395f 100644 --- a/src/kernel/kshell.c +++ b/src/kernel/kshell.c @@ -5,6 +5,7 @@ #include #include #include +#include uint8_t keymap[][128] = { {0}, @@ -101,14 +102,72 @@ uint8_t keymap[][128] = { #define KB_LSHIFT 42 #define KB_RSHIFT 54 +/*max history data limit*/ +#define MAX_CMD 100 + bool caps_mode = false; bool shift_mode = false; bool alt_mode = false; bool ctrl_mode = false; bool super_mode = false; -char history_data[100][RDL_SIZE]; -uint8_t tot_cmds=0; + +/* dynamic data strecture*/ +struct Dynamic_List { + char data[RDL_SIZE]; + struct Dynamic_List * next; +}; + + +/*head of dynamic list*/ +struct Dynamic_List *head=NULL; + + +void Add_data(char* data,uint8_t size){ + /*if head node is empty*/ + if(head==NULL){ + head=(struct Dynamic_List *)kmalloc(sizeof(struct Dynamic_List)); + memcpy(head->data,data,size); + head->next=NULL; + return; + } + /*if head node is not empty*/ + struct Dynamic_List *node=NULL, *current=head; + uint8_t i=0; + + /*traverse to the end of dynaic list*/ + while (current!=NULL && current->next!=NULL){ + current=current->next; + i++; + } + + /*check boundry conditions*/ + if(i+1>MAX_CMD)head=head->next; + + /*allocate the memory*/ + node=(struct Dynamic_List *)kmalloc(sizeof(struct Dynamic_List)); + + /*add data to new node*/ + memcpy(node->data,data,size); + node->next=NULL; + + /*assign new node at the end of list*/ + if(current==NULL)current=node; + else current->next=node; +} + +void print_history(){ + /*pointer for travel through list*/ + struct Dynamic_List *node; + node=head; + uint8_t i=0; + /*print data until the end of list*/ + while((node->next)!=NULL){ + kprintf("%07i %05s\n",i+1,node->data); + node=node->next; + i++; + } +} void run_cmd(char *run) { if (!(strncmp(run, "page 0x", 7))) { @@ -140,11 +199,8 @@ void run_cmd(char *run) { tree(run + 5); } else if (!strncmp(run, "history", 7)){ - for(int i=0;i 128) { up = true; @@ -194,17 +251,13 @@ void kshell(unsigned char key) { if (up) { int i; kprintf("\n"); - for (i = 0; i < rdl_index; i++) - { - history_data[tot_cmds][i]=readline[i]; - } + Add_data(readline,rdl_index); run_cmd(readline); rdl_index = 0; for(i=0;i Date: Wed, 2 Dec 2020 15:40:02 +0530 Subject: [PATCH 3/3] Update kshell.c --- src/kernel/kshell.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/kernel/kshell.c b/src/kernel/kshell.c index 559395f..ea7717c 100644 --- a/src/kernel/kshell.c +++ b/src/kernel/kshell.c @@ -135,7 +135,7 @@ void Add_data(char* data,uint8_t size){ struct Dynamic_List *node=NULL, *current=head; uint8_t i=0; - /*traverse to the end of dynaic list*/ + /*traverse to the end of dynamic list*/ while (current!=NULL && current->next!=NULL){ current=current->next; i++;