Skip to content

Commit

Permalink
whoami command #125
Browse files Browse the repository at this point in the history
  • Loading branch information
double-fault committed Jan 14, 2017
1 parent 4828471 commit d79d376
Show file tree
Hide file tree
Showing 8 changed files with 149 additions and 6 deletions.
6 changes: 4 additions & 2 deletions apps/sh/shell.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@
#include <drv/driver.h>
#include <drv/cmos/rtc/rtc.h>
#include <sh/built-in/exit/exit.h>
#include <date/date.h>
#include <date/date.h>
#include <whoami/whoami.h>



Expand Down Expand Up @@ -76,7 +77,8 @@ struct cmd_t *cmds[] =
&cmd_pwd,
&cmd_logname,
&cmd_uname,
&cmd_date,
&cmd_date,
&cmd_whoami,
0
};

Expand Down
4 changes: 3 additions & 1 deletion bin/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ CSRCS = \
uname/opts/main_uname.c \
boneshell/boneshell.c \
date/date.c \
date/opts/main_date.c
date/opts/main_date.c \
whoami/whoami.c \
whoami/opts/main_whoami.c

LIBNAME := bin

Expand Down
61 changes: 61 additions & 0 deletions bin/whoami/opts/main_whoami.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/**
** 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 <whoami/whoami.h>

int main_whoami_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_USER);
return STATUS_OK;
}
else if (num_opts > 1)
{
if (strcmp (opts [1].str, "--help") == 0)
{
printk (cmd_whoami.help);
return STATUS_OK;
}
else
{
printk (cmd_whoami.invalid_use_msg);
return STATUS_OK;
}
}

return STATUS_OK;
}


63 changes: 63 additions & 0 deletions bin/whoami/whoami.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/**
** 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 <whoami/whoami.h>
#include <whoami/opts/main_whoami.h>

struct cmd_opt_t* cmd_whoami_opts[] =
{
0
};

int cmd_whoami_handler (char *cmd)
{
main_whoami_opt_handler (cmd);
return STATUS_OK;
}

struct cmd_t cmd_whoami =
{
.name = "whoami",
.usage ="whoami [--help]",
.help = "whoami(1) \t\t\t\t BoneOS Terminal Manual \n"
"NAME : \n "
"\twhoami\n"
"SYNOPSIS : \n "
"\twhoami [option] [--help]\n"
"DESCRIPTION : \n "
"\tPrints out the current user.\n",
.cmd_opts = cmd_whoami_opts,
.handler = &cmd_whoami_handler,
.invalid_use_msg = "Invalid use of whoami command.\n"
"Type whoami --help for more help.\n",
.privilege = USER
};


3 changes: 2 additions & 1 deletion include/apps/sh/shell.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ struct typed_cmd
#define CMD_INDEX_PWD 10
#define CMD_LOGNAME_INDEX 11
#define CMD_UNAME_INDEX 12
#define CMD_DATE_INDEX 13
#define CMD_DATE_INDEX 13
#define CMD_WHOAMI_INDEX 14

extern void init_terminal();
extern struct cmd_t *cmds[];
Expand Down
2 changes: 0 additions & 2 deletions include/bin/logname/logname.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,3 @@
extern struct cmd_t cmd_logname;

#endif /*_BIN_LOGNAME_H_*/


8 changes: 8 additions & 0 deletions include/bin/whoami/opts/main_whoami.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#ifndef _BIN_WHOAMI_MAINOPT_H_
#define _BIN_WHOAMI_MAINOPT_H_

int main_whoami_opt_handler (char *cmd);

#endif /*_BIN_WHOAMI_MAINOPT_H_*/


8 changes: 8 additions & 0 deletions include/bin/whoami/whoami.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#ifndef _BIN_WHOAMI_H_
#define _BIN_WHOAMI_H_

extern struct cmd_t cmd_whoami;

#endif /*_BIN_WHOAMI_H_*/


0 comments on commit d79d376

Please sign in to comment.