From d79d3769636dee100de759e376b880a5e1287f73 Mon Sep 17 00:00:00 2001 From: Fortunate-MAN Date: Sat, 14 Jan 2017 15:56:11 +0530 Subject: [PATCH] whoami command #125 --- apps/sh/shell.c | 6 ++- bin/Makefile | 4 +- bin/whoami/opts/main_whoami.c | 61 ++++++++++++++++++++++++++ bin/whoami/whoami.c | 63 +++++++++++++++++++++++++++ include/apps/sh/shell.h | 3 +- include/bin/logname/logname.h | 2 - include/bin/whoami/opts/main_whoami.h | 8 ++++ include/bin/whoami/whoami.h | 8 ++++ 8 files changed, 149 insertions(+), 6 deletions(-) create mode 100644 bin/whoami/opts/main_whoami.c create mode 100644 bin/whoami/whoami.c create mode 100644 include/bin/whoami/opts/main_whoami.h create mode 100644 include/bin/whoami/whoami.h diff --git a/apps/sh/shell.c b/apps/sh/shell.c index 5a0ce95..64743cc 100644 --- a/apps/sh/shell.c +++ b/apps/sh/shell.c @@ -47,7 +47,8 @@ #include #include #include -#include +#include +#include @@ -76,7 +77,8 @@ struct cmd_t *cmds[] = &cmd_pwd, &cmd_logname, &cmd_uname, - &cmd_date, + &cmd_date, + &cmd_whoami, 0 }; diff --git a/bin/Makefile b/bin/Makefile index e1eee2a..fe1e62f 100644 --- a/bin/Makefile +++ b/bin/Makefile @@ -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 diff --git a/bin/whoami/opts/main_whoami.c b/bin/whoami/opts/main_whoami.c new file mode 100644 index 0000000..5bde26e --- /dev/null +++ b/bin/whoami/opts/main_whoami.c @@ -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 . + ** + ** @main_author : Ashish Ahuja + ** + ** @contributors: + + ** Ashish Ahuja: start + **/ + +#include +#include +#include +#include +#include +#include +#include +#include + +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; +} + + diff --git a/bin/whoami/whoami.c b/bin/whoami/whoami.c new file mode 100644 index 0000000..9f9c6b0 --- /dev/null +++ b/bin/whoami/whoami.c @@ -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 . + ** + ** @main_author : Ashish Ahuja + ** + ** @contributors: + + ** Ashish Ahuja: start + **/ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +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 +}; + + diff --git a/include/apps/sh/shell.h b/include/apps/sh/shell.h index 5ee525d..b4bb9fe 100644 --- a/include/apps/sh/shell.h +++ b/include/apps/sh/shell.h @@ -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[]; diff --git a/include/bin/logname/logname.h b/include/bin/logname/logname.h index 3962f87..2e9f702 100644 --- a/include/bin/logname/logname.h +++ b/include/bin/logname/logname.h @@ -4,5 +4,3 @@ extern struct cmd_t cmd_logname; #endif /*_BIN_LOGNAME_H_*/ - - diff --git a/include/bin/whoami/opts/main_whoami.h b/include/bin/whoami/opts/main_whoami.h new file mode 100644 index 0000000..414ed2c --- /dev/null +++ b/include/bin/whoami/opts/main_whoami.h @@ -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_*/ + + diff --git a/include/bin/whoami/whoami.h b/include/bin/whoami/whoami.h new file mode 100644 index 0000000..3660cee --- /dev/null +++ b/include/bin/whoami/whoami.h @@ -0,0 +1,8 @@ +#ifndef _BIN_WHOAMI_H_ +#define _BIN_WHOAMI_H_ + +extern struct cmd_t cmd_whoami; + +#endif /*_BIN_WHOAMI_H_*/ + +