From 1fa4907569ba3212b460c74327282df20217796a Mon Sep 17 00:00:00 2001 From: Fortunate-MAN Date: Thu, 12 Jan 2017 10:06:06 +0530 Subject: [PATCH] Some more cleanup #151 --- bin/boneshell/boneshell.c | 156 +++++++++++++++++++------------------- 1 file changed, 76 insertions(+), 80 deletions(-) diff --git a/bin/boneshell/boneshell.c b/bin/boneshell/boneshell.c index bd6be9e..a2ba2f5 100644 --- a/bin/boneshell/boneshell.c +++ b/bin/boneshell/boneshell.c @@ -54,101 +54,97 @@ bool executed_internally=false; void removeSpaces(char* source) { - char* i = source; - char* j = source; - while(*j != 0) - { - *i = *j++; - if(*i != ' ') - i++; - } - *i = 0; + char* i = source; + char* j = source; + while(*j != 0) + { + *i = *j++; + if(*i != ' ') + i++; + } + *i = 0; } void loop_terminal() { - shell_instance_cnt+=1; - if (shell_instance_cnt != 1) - printk("Shell #%d\n" , shell_instance_cnt); - printk ("%s release %s started at ", VAR_OSNAME, VAR_RELEASE); - rtc_print_date(); - while(1) - { - start_shell:; - int FG__ = video_drivers[VGA_VIDEO_DRIVER_INDEX]->fg; - int BG__ = video_drivers[VGA_VIDEO_DRIVER_INDEX]->bg; - if(video_drivers[VGA_VIDEO_DRIVER_INDEX]->fg==0x7 && video_drivers[VGA_VIDEO_DRIVER_INDEX]->bg==0x0) - { - printck(2,0,"%s@boneos:",VAR_USER); - printck(1,0,"%s",VAR_PWD); - printck(0x0,0x7,""); - printck(0x7,0x0," $ "); - } - else + shell_instance_cnt+=1; + if (shell_instance_cnt != 1) + printk("Shell #%d\n" , shell_instance_cnt); + printk ("%s release %s started at ", VAR_OSNAME, VAR_RELEASE); + rtc_print_date(); + while(1) { - printk("%s@boneos:",VAR_USER); - printk("%s",VAR_PWD); - printk(" $ "); - } - video_drivers[VGA_VIDEO_DRIVER_INDEX]->fg = FG__; - video_drivers[VGA_VIDEO_DRIVER_INDEX]->bg = BG__; - + start_shell:; + int FG__ = video_drivers[VGA_VIDEO_DRIVER_INDEX]->fg; + int BG__ = video_drivers[VGA_VIDEO_DRIVER_INDEX]->bg; + if(video_drivers[VGA_VIDEO_DRIVER_INDEX]->fg==0x7 && video_drivers[VGA_VIDEO_DRIVER_INDEX]->bg==0x0) + { + printck(2,0,"%s@boneos:",VAR_USER); + printck(1,0,"%s",VAR_PWD); + printck(0x0,0x7,""); + printck(0x7,0x0," $ "); + } + else + { + printk("%s@boneos:",VAR_USER); + printk("%s",VAR_PWD); + printk(" $ "); + } + video_drivers[VGA_VIDEO_DRIVER_INDEX]->fg = FG__; + video_drivers[VGA_VIDEO_DRIVER_INDEX]->bg = BG__; - //continue_read: - scank(true,true, "%s" , cmd_active.value); + scank(true,true, "%s" , cmd_active.value); - if(tab_multiple_opts==true) - { - tab_multiple_opts=false; - goto start_shell; - } - else if(tab_one_opt == true) - { - tab_one_opt = false; - strcpy (cmd_active.value, tab__); - executed_internally = true; - removeSpaces (cmd_active.value); - } - else if (tab_zero_opt == true) - { - key_handler_util_backspace(); - tab_zero_opt = false; - scank (true, true, "%s", cmd_active.value + (strlen (cmd_active.value))); - } + if(tab_multiple_opts==true) + { + tab_multiple_opts=false; + goto start_shell; + } + else if(tab_one_opt == true) + { + tab_one_opt = false; + strcpy (cmd_active.value, tab__); + executed_internally = true; + removeSpaces (cmd_active.value); + } + else if (tab_zero_opt == true) + { + key_handler_util_backspace(); + tab_zero_opt = false; + scank (true, true, "%s", cmd_active.value + (strlen (cmd_active.value))); + } + if(strcmp(cmd_active.value, "exit")==0) + { + shell_instance_cnt-=1; + printk("Exited shell instance #%d\n",shell_instance_cnt+1); + goto end_shell; + } - //removeSpaces(cmd_active.value); - if(strcmp(cmd_active.value, "exit")==0) - { - shell_instance_cnt-=1; - printk("Exited shell instance #%d\n",shell_instance_cnt+1); - goto end_shell; - } + for(int i=0; cmds[i]; i++) + { + if(termcmp(cmds[i]->name, cmd_active.value)==0) + { + if(executed_internally==true) + { + executed_internally=false; + } + cmds[i]->handler(cmd_active.value); + __found = 1; + } + } - for(int i=0; cmds[i]; i++) - { - if(termcmp(cmds[i]->name, cmd_active.value)==0) - { - if(executed_internally==true) + if(__found == 0 && cmd_active.value [0] != '\0') { - executed_internally=false; + printk("Invalid Command '%s' \n", cmd_active.value); + printk("Try 'help' for more information.\n"); } - cmds[i]->handler(cmd_active.value); - __found = 1; - } - } - if(__found == 0 && cmd_active.value [0] != '\0') - { - printk("Invalid Command '%s' \n", cmd_active.value); - printk("Try 'help' for more information.\n"); + __found = 0; + cmd_active_index++; } - - __found = 0; - cmd_active_index++; - } - end_shell:; + end_shell:; } int boneshell_handler(char* cmd) {