Skip to content

Commit

Permalink
command uname #125
Browse files Browse the repository at this point in the history
  • Loading branch information
double-fault committed Jan 1, 2017
1 parent b1ef878 commit eda34f6
Show file tree
Hide file tree
Showing 9 changed files with 185 additions and 13 deletions.
9 changes: 6 additions & 3 deletions apps/sh/shell.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@
#include <stdbool.h>
#include <help/help.h>
#include <pwd/pwd.h>
#include <logname/logname.h>
#include <logname/logname.h>
#include <uname/uname.h>
#include <sleep/sleep.h>
#include <echo/echo.h>
#include <string/string.h>
Expand Down Expand Up @@ -71,15 +72,17 @@ struct cmd_t *cmds[] =
&cmd_boneshell,
&cmd_exit,
&cmd_pwd,
&cmd_logname
&cmd_logname,
&cmd_uname
,0
};

void init_terminal()
{
assertkm(device_initalized(KBD_DRIVER_INDEX) , "Keyboard not intalized for starting shell!");
TERMINAL_MODE=true;
cmds[CMD_BONEOS_LOGO_INDEX]->handler("boneos_logo");
//cmds[CMD_BONEOS_LOGO_INDEX]->handler("boneos_logo");
printk ("%s release %s started.\n", VAR_OSNAME, VAR_RELEASE);
cmds[CMD_BONESHELL_INDEX]->handler("boneshell");
TERMINAL_MODE=false;
}
Expand Down
13 changes: 8 additions & 5 deletions apps/sh/values.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,19 @@
** along with BoneOS. If not, see <http://www.gnu.org/licenses/>.
**
** @main_author : Amanuel Bogale
**
**
** @contributors:
** Amanuel Bogale <amanuel2> : start
**/
**/

#include <sh/shell.h>
#include <str_t.h>
#include <str_t.h>

char* VAR_USER = "root";
char* VAR_PWD = "/";
char* VAR_PWD = "/";
char* VAR_RELEASE = "0.0.1";
char* VAR_OSNAME = "BoneOS";
char* VAR_PLATFORM = "x86_32";


2 changes: 2 additions & 0 deletions bin/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ CSRCS = \
pwd/opts/main_pwd.c \
logname/logname.c \
logname/opts/main_logname.c \
uname/uname.c \
uname/opts/main_uname.c \
boneshell/boneshell.c

LIBNAME := bin
Expand Down
8 changes: 5 additions & 3 deletions bin/boneshell/boneshell.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,10 @@ void removeSpaces(char* source)
void loop_terminal()
{
shell_instance_cnt+=1;
printk("SHELL INSTANCE #%d\n",shell_instance_cnt);
if (shell_instance_cnt != 1)
{
printk("New shell instance #%d\n",shell_instance_cnt);
}
while(1)
{
start_shell:;
Expand Down Expand Up @@ -110,7 +113,7 @@ void loop_terminal()
if(strcmp(cmd_active.value, "exit")==0)
{
shell_instance_cnt-=1;
printk("EXITED SHELL INSTANCE #%d\n",shell_instance_cnt+1);
printk("Exited shell instance #%d\n",shell_instance_cnt+1);
goto end_shell;
}

Expand All @@ -121,7 +124,6 @@ void loop_terminal()
if(executed_internally==true)
{
executed_internally=false;
printk("EXECUTED INTERNALLY\n");
}
cmds[i]->handler(cmd_active.value);
__found = 1;
Expand Down
80 changes: 80 additions & 0 deletions bin/uname/opts/main_uname.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/**
** This file is part of BoneOS.
**
** BoneOS is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation, either version 3 of the License, or
** (at your option) any later version.
** BoneOS is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
** You should have received a copy of the GNU General Public License
** along with BoneOS. If not, see <http://www.gnu.org/licenses/>.
**
** @main_author : Ashish Ahuja
**
** @contributors:
** Ashish Ahuja<Fortunate-MAN>: start
**/

#include <misc/status_codes.h>
#include <sh/shell.h>
#include <sh/values.h>
#include <drv/video/video.h>
#include <unistd/unistd.h>
#include <stdio/stdio.h>
#include <string/string.h>
#include <sh/values.h>
#include <uname/uname.h>

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

if (num_opts == 1)
{
printk ("%s\n", VAR_OSNAME);
return STATUS_OK;
}
else if (num_opts > 1)
{
if (strcmp (opts [1].str, "--help") == 0)
{
printk (cmd_uname.help);
return STATUS_OK;
}
else if (strcmp (opts [1].str, "-a") == 0)
{
printk ("%s %s %s\n", VAR_OSNAME, VAR_RELEASE, VAR_PLATFORM);
return STATUS_OK;
}
else if (strcmp (opts [1].str, "-p") == 0)
{
printk ("%s\n", VAR_PLATFORM);
return STATUS_OK;
}
else if (strcmp (opts [1].str, "-r") == 0)
{
printk ("%s\n", VAR_RELEASE);
return STATUS_OK;
}
else if (strcmp (opts [1].str, "-n") == 0)
{
printk ("%s\n", VAR_OSNAME);
return STATUS_OK;
}
else
{
printk (cmd_uname.invalid_use_msg);
return STATUS_OK;
}
}

return STATUS_OK;
}
67 changes: 67 additions & 0 deletions bin/uname/uname.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/**
** This file is part of BoneOS.
**
** BoneOS is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation, either version 3 of the License, or
** (at your option) any later version.
** BoneOS is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
** You should have received a copy of the GNU General Public License
** along with BoneOS. If not, see <http://www.gnu.org/licenses/>.
**
** @main_author : Ashish Ahuja
**
** @contributors:
** Ashish Ahuja<Fortunate-MAN>: start
**/

#include <misc/status_codes.h>
#include <sh/shell.h>
#include <drv/video/video.h>
#include <unistd/unistd.h>
#include <stdio/stdio.h>
#include <string/string.h>
#include <sh/values.h>
#include <uname/uname.h>
#include <uname/opts/main_uname.h>

struct cmd_opt_t* cmd_uname_opts[] =
{
0
};

int cmd_uname_handler (char *cmd)
{
main_uname_opt_handler (cmd);
return STATUS_OK;
}

struct cmd_t cmd_uname =
{
.name = "uname",
.usage ="uname",
.help = "uname(1) \t\t\t\t BoneOS Terminal Manual \n"
"NAME : \n "
"\tuname\n"
"SYNOPSIS : \n "
"\tuname [option]\n"
"DESCRIPTION : \n "
"\tPrints out information about the OS.\n"
"OPTIONS : \n "
"\t Option Summary \n "
"\t\t [-n] : prints the OS name\n "
"\t\t [-a] : prints all the options\n "
"\t\t [-r] : prints the current release\n "
"\t\t [-p] : prints the current hardware platform\n",
.cmd_opts = cmd_uname_opts,
.handler = &cmd_uname_handler,
.invalid_use_msg = "Invalid use of uname command.\n"
"Type in uname --help for more help.\n",
.privilege = USER
};
7 changes: 5 additions & 2 deletions include/apps/sh/values.h
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
#ifndef _APPS_TERM_VALUES_H_
#define _APPS_TERM_VALUES_H_

#include <str_t.h>
#include <str_t.h>


extern char* VAR_USER;
extern char* VAR_PWD;
extern char* VAR_PWD;
extern char* VAR_RELEASE;
extern char* VAR_OSNAME;
extern char* VAR_PLATFORM;

extern struct values __values;

Expand Down
6 changes: 6 additions & 0 deletions include/bin/uname/opts/main_uname.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#ifndef _BIN_UNAME_MAINOPT_H_
#define _BIN_UNAME_MAINOPT_H_

int main_uname_opt_handler (char *cmd);

#endif
6 changes: 6 additions & 0 deletions include/bin/uname/uname.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#ifndef _BIN_UNAME_H_
#define _BIN_UNAME_H_

extern struct cmd_t cmd_uname;

#endif

0 comments on commit eda34f6

Please sign in to comment.