Skip to content

Commit

Permalink
Some more command error support #194, some cleanup too #151
Browse files Browse the repository at this point in the history
  • Loading branch information
double-fault committed Feb 7, 2017
1 parent 90016a4 commit 325dab2
Show file tree
Hide file tree
Showing 16 changed files with 246 additions and 250 deletions.
18 changes: 9 additions & 9 deletions bin/clear/clear.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,12 @@
** along with BoneOS. If not, see <http://www.gnu.org/licenses/>.
**
** @main_author : Amanuel Bogale
**
**
** @contributors:
** Amanuel Bogale <amanuel2> : start
**/
** Ashish Ahuja <Fortunate-MAN>
**/

#include <misc/status_codes.h>
#include <sh/shell.h>
Expand All @@ -32,7 +33,7 @@
#include <stddef.h>
#include <clear/opts/main_clear.h>

struct cmd_opt_t* cmd_clear_opts[] =
struct cmd_opt_t* cmd_clear_opts[] =
{
&cmd_clear_opt_color,
0
Expand All @@ -46,12 +47,11 @@ int cmd_clear_handler(char* cmd)
video_drivers[VGA_VIDEO_DRIVER_INDEX]->clear();
return STATUS_OK;
}

main_clear_opt_handler(cmd);
return STATUS_OK;

return main_clear_opt_handler(cmd);
}

struct cmd_t cmd_clear =
struct cmd_t cmd_clear =
{
.name = "clear",
.usage = "clear [--help] [-color <fg-color> <bg-color>] [-color --def] [-color <--help>] ",
Expand All @@ -65,9 +65,9 @@ struct cmd_t cmd_clear =
"\tcolor with the -color command and providing it\n "
"\ta Foreground as well as a Background Color \n"
"MORE HELP : \n "
"\t[clear -color --help] for help on -color option\n",
"\t[clear -color --help] for help on -color option\n",
.cmd_opts = cmd_clear_opts,
.handler = &cmd_clear_handler,
.handler = &cmd_clear_handler,
.invalid_use_msg = "Invalid use of clear command.\n"
"Type in clear --help for more help.\n",
.privilege = USER
Expand Down
22 changes: 10 additions & 12 deletions bin/clear/opts/color.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,12 @@
** along with BoneOS. If not, see <http://www.gnu.org/licenses/>.
**
** @main_author : Amanuel Bogale
**
**
** @contributors:
** Amanuel Bogale <amanuel2> : start
**/
** Amanuel Bogale <amanuel2> : start
** Ashish Ahuja <Fortunate-MAN>
**/

#include <stddef.h>
#include <stdint.h>
Expand All @@ -32,27 +33,24 @@
#include <string/string.h>
#include <drv/video/VGA/vga.h>




int cmd_clear_color_handler(char* cmd)
{
size_t num_opts = get_opt_count(cmd);
str_t opts[num_opts];
get_opt(cmd,opts);

int _FG = strtoi((char*)opts[2].str, 0, 16);
int _BG = strtoi((char*)opts[3].str, 0, 16);

video_drivers[VGA_VIDEO_DRIVER_INDEX]->fg = _FG;
video_drivers[VGA_VIDEO_DRIVER_INDEX]->bg = _BG;

video_drivers[VGA_VIDEO_DRIVER_INDEX]->clear();

return STATUS_OK;
}

struct cmd_opt_t cmd_clear_opt_color =
struct cmd_opt_t cmd_clear_opt_color =
{
.help = "clear(1) \t\t\t\t BoneOS Terminal Manual \n"
"NAME : \n "
Expand All @@ -74,7 +72,7 @@ struct cmd_opt_t cmd_clear_opt_color =
"\t\t 5 = Purple\t D = Light Purple\n "
"\t\t 6 = Yellow\t E = Light Yellow\n "
"\t\t 7 = White \t F = Bright White\n "
"\t\t--def : Clears to default (BG : 0x7 , FG : 0x0)\n ",
"\t\t--def : Clears to default (BG : 0x7 , FG : 0x0)\n ",
.cmd_opt_name = "-color" ,
.handler = &cmd_clear_color_handler,
.invalid_use_msg = "Invalid Use of -color option. Use command clear -color --help for instructions\n"
Expand Down
82 changes: 40 additions & 42 deletions bin/clear/opts/main_clear.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,13 @@
** along with BoneOS. If not, see <http://www.gnu.org/licenses/>.
**
** @main_author : Amanuel Bogale
**
**
** @contributors:
** Amanuel Bogale <amanuel2> : start
**/

** Ashish Ahuja <Fortunate-MAN>
**/

#include <misc/status_codes.h>
#include <string/string.h>
#include <unistd/unistd.h>
Expand All @@ -34,44 +35,41 @@

int main_clear_opt_handler(char *cmd)
{
size_t num_opts = get_opt_count(cmd);
str_t opts[num_opts];
get_opt(cmd,opts);

if(strcmp(opts[1].str, "-color")==0)
{
if(strcmp(opts[2].str, "--help")==0)
{
printk(cmd_clear_opt_color.help);
}
else if(strcmp(opts[2].str, "--def")==0)
{
video_drivers[VGA_VIDEO_DRIVER_INDEX]->fg = 0x7;
video_drivers[VGA_VIDEO_DRIVER_INDEX]->bg = 0x0;
video_drivers[VGA_VIDEO_DRIVER_INDEX]->clear();
}
else if(opts[2].str[0] == '\0' || opts[3].str[0] == '\0')
{
printk(cmd_clear_opt_color.invalid_use_msg);
}
else
{
cmd_clear_opt_color.handler(cmd);
}
}
else if(strcmp(opts[1].str, "--help")==0)
{
printk(cmd_clear.help);
}
else
{
printk(cmd_clear.invalid_use_msg);
}
return STATUS_OK;
}




size_t num_opts = get_opt_count(cmd);
str_t opts[num_opts];
get_opt(cmd,opts);

if(strcmp(opts[1].str, "-color")==0)
{
if(strcmp(opts[2].str, "--help")==0)
{
printk(cmd_clear_opt_color.help);
}
else if(strcmp(opts[2].str, "--def")==0)
{
video_drivers[VGA_VIDEO_DRIVER_INDEX]->fg = 0x7;
video_drivers[VGA_VIDEO_DRIVER_INDEX]->bg = 0x0;
video_drivers[VGA_VIDEO_DRIVER_INDEX]->clear();
}
else if(opts[2].str[0] == '\0' || opts[3].str[0] == '\0')
{
printk(cmd_clear_opt_color.invalid_use_msg);
return STATUS_FAIL;
}
else
{
cmd_clear_opt_color.handler(cmd);
}
}
else if(strcmp(opts[1].str, "--help")==0)
{
printk(cmd_clear.help);
}
else
{
printk(cmd_clear.invalid_use_msg);
return STATUS_FAIL;
}
return STATUS_OK;
}

20 changes: 10 additions & 10 deletions bin/cursor/cursor.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,12 @@
** along with BoneOS. If not, see <http://www.gnu.org/licenses/>.
**
** @main_author : Amanuel Bogale
**
**
** @contributors:
** Amanuel Bogale <amanuel2> : start
**/
** Ashish Ahuja <Fortunate-MAN>
**/

#include <misc/status_codes.h>
#include <sh/shell.h>
Expand All @@ -29,7 +30,7 @@
#include <cursor/cursor.h>
#include <cursor/opts/main_cursor.h>

struct cmd_opt_t* cmd_cursor_opts[] =
struct cmd_opt_t* cmd_cursor_opts[] =
{
0
};
Expand All @@ -40,15 +41,14 @@ int cmd_cursor_handler(char* cmd)
if(num_opts == 1)
{
printk(cmd_cursor.invalid_use_msg);
return STATUS_OK;
return STATUS_FAIL;
}

main_cursor_opt_handler(cmd);
return STATUS_OK;

return main_cursor_opt_handler(cmd);
}


struct cmd_t cmd_cursor =
struct cmd_t cmd_cursor =
{
.name = "cursor",
.usage ="cursor [-t <CRSR_START> <CRSR_END>] [-t block] [-t def] [--help]",
Expand All @@ -63,9 +63,9 @@ struct cmd_t cmd_cursor =
"\t Option Summary \n "
"\t\t [-t <CRSR_START> <CRSR_END>] : cursor now changes to custom type.\n "
"\t\t [-t block] : cursor is changed to a block cursor (START:0,END:20)\n "
"\t\t [-t def] : cursor changes to default underline. (START:15,END:15)\n",
"\t\t [-t def] : cursor changes to default underline. (START:15,END:15)\n",
.cmd_opts = cmd_cursor_opts,
.handler = &cmd_cursor_handler,
.handler = &cmd_cursor_handler,
.invalid_use_msg = "Invalid use of cursor command.\n"
"Type in cursor --help for more help.\n",
.privilege = USER
Expand Down
67 changes: 35 additions & 32 deletions bin/cursor/opts/main_cursor.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,13 @@
** along with BoneOS. If not, see <http://www.gnu.org/licenses/>.
**
** @main_author : Amanuel Bogale
**
**
** @contributors:
** Amanuel Bogale <amanuel2> : start
**/

** Ashish Ahuja <Fortunate-MAN>
**/

#include <misc/status_codes.h>
#include <string/string.h>
#include <unistd/unistd.h>
Expand All @@ -33,36 +34,38 @@

int main_cursor_opt_handler(char *cmd)
{
size_t num_opts = get_opt_count(cmd);
str_t opts[num_opts];
get_opt(cmd,opts);

if(strcmp(opts[1].str,"--help")==0)
printk(cmd_cursor.help);
else if(strcmp(opts[1].str,"-t")==0)
{
if(strcmp(opts[2].str,"def")==0)
video_drivers[VGA_VIDEO_DRIVER_INDEX]->update_cursor(video_drivers[VGA_VIDEO_DRIVER_INDEX]->video_row,video_drivers[VGA_VIDEO_DRIVER_INDEX]->video_column,15,15);
else if(strcmp(opts[2].str,"block")==0)
video_drivers[VGA_VIDEO_DRIVER_INDEX]->update_cursor(video_drivers[VGA_VIDEO_DRIVER_INDEX]->video_row,video_drivers[VGA_VIDEO_DRIVER_INDEX]->video_column,0,20);
else if((strcmp(opts[2].str,"")!=0) || (strcmp(opts[3].str,"")!=0))
{
printk("%s , %s", opts[2].str, opts[3].str);
int _CRSR_START = atoi(opts[2].str);
int _CRSR_END = atoi(opts[3].str);
video_drivers[VGA_VIDEO_DRIVER_INDEX]->update_cursor(video_drivers[VGA_VIDEO_DRIVER_INDEX]->video_row,video_drivers[VGA_VIDEO_DRIVER_INDEX]->video_column,_CRSR_START,_CRSR_END);
}
else
printk(cmd_cursor.invalid_use_msg);
}
else
printk(cmd_cursor.invalid_use_msg);

return STATUS_OK;
}


size_t num_opts = get_opt_count(cmd);
str_t opts[num_opts];
get_opt(cmd,opts);

if(strcmp(opts[1].str,"--help")==0)
printk(cmd_cursor.help);
else if(strcmp(opts[1].str,"-t")==0)
{
if(strcmp(opts[2].str,"def")==0)
video_drivers[VGA_VIDEO_DRIVER_INDEX]->update_cursor(video_drivers[VGA_VIDEO_DRIVER_INDEX]->video_row,video_drivers[VGA_VIDEO_DRIVER_INDEX]->video_column,15,15);
else if(strcmp(opts[2].str,"block")==0)
video_drivers[VGA_VIDEO_DRIVER_INDEX]->update_cursor(video_drivers[VGA_VIDEO_DRIVER_INDEX]->video_row,video_drivers[VGA_VIDEO_DRIVER_INDEX]->video_column,0,20);
else if((strcmp(opts[2].str,"")!=0) || (strcmp(opts[3].str,"")!=0))
{
printk("%s , %s", opts[2].str, opts[3].str);
int _CRSR_START = atoi(opts[2].str);
int _CRSR_END = atoi(opts[3].str);
video_drivers[VGA_VIDEO_DRIVER_INDEX]->update_cursor(video_drivers[VGA_VIDEO_DRIVER_INDEX]->video_row,video_drivers[VGA_VIDEO_DRIVER_INDEX]->video_column,_CRSR_START,_CRSR_END);
}
else
{
printk(cmd_cursor.invalid_use_msg);
return STATUS_FAIL;
}
}
else
{
printk(cmd_cursor.invalid_use_msg);
return STATUS_FAIL;
}

return STATUS_OK;
}


3 changes: 1 addition & 2 deletions bin/date/date.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
** along with BoneOS. If not, see <http://www.gnu.org/licenses/>.
**
** @main_author : Amanuel Bogale
** Ashish Ahuja <Fortunate-MAN>
**
** @contributors:
** Amanuel Bogale <amanuel2> : start
** Ashish Ahuja <Fortunate-MAN>
**/
Expand Down Expand Up @@ -47,7 +47,6 @@ int cmd_date_handler(char* cmd)
return STATUS_OK;
}


struct cmd_t cmd_date =
{
.name = "date",
Expand Down
2 changes: 1 addition & 1 deletion bin/date/opts/main_date.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,6 @@ int main_date_opt_handler (char *cmd)
else
{
printk (cmd_date.invalid_use_msg);
return STATUS_OK;
return STATUS_FAIL;
}
}
Loading

0 comments on commit 325dab2

Please sign in to comment.