Author | Jamozed <[email protected]> |
Date | 2021-08-08 09:46:11 |
Commit | 6e65ba3c9750eae6dff2b5ac06a2c1f8b4de34af |
Parent | 5c73de53c466e33faebeb362b1623acab081c396 |
Add --help and --version options
Diffstat
M | src/main.c | | | 34 | ++++++++++++++++++++++++++++++++++ |
1 files changed, 34 insertions, 0 deletions
diff --git a/src/main.c b/src/main.c index 84a0f12..789bdf7 100644 --- a/src/main.c +++ b/src/main.c @@ -35,6 +35,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS WITH THE SOFTWARE. #include "parse.h" #include "lib/error.h" +#include "lib/optget.h" #include <errno.h> #include <setjmp.h> @@ -45,6 +46,12 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS WITH THE SOFTWARE. #include <stdio.h> #include <stdlib.h> +static struct lop lops[] = { + { "help", ARG_NUL, 256 }, + { "version", ARG_NUL, 257 }, + { NULL, 0, 0 } +}; + int _loop = 1, _ret; static jmp_buf jmp; @@ -52,7 +59,17 @@ static sig_atomic_t jmpflag = false; static void reset(int signo); +static void hlp(void); +static void ver(void); + int main(int ac, char *av[]) { (void)(ac); A0 = av[0]; + struct opt opt = OPTGET_INIT; opt.str = ""; opt.lops = lops; + for (int o; (o = optget(&opt, av, 1)) != -1;) switch (o) { + case 256: { hlp(); return 0; } + case 257: { ver(); return 0; } + default: { return 1; } + } + signal(SIGINT, &reset); signal(SIGTSTP, SIG_IGN); signal(SIGQUIT, SIG_IGN); if (errno) { warn("%s", serr()); } @@ -78,3 +95,20 @@ int main(int ac, char *av[]) { (void)(ac); A0 = av[0]; static void reset(int signo) { (void)(signo); if (jmpflag) { siglongjmp(jmp, 1); } } + +static void hlp(void) { + puts("ESH - Executive Shell\n"); + puts("Usage: esh\n"); + puts("Options:"); + puts(" --help Display help information"); + puts(" --version Display version information"); + return; +} + +static void ver(void) { + puts("ESH, version " PROJECT_VERSION); + puts("Copyright (C) 2020, Jakob Wakeling"); + puts("All rights reserved."); + puts("OMKOV Permissive Licence (https://www.omkov.net/OLPE)"); + return; +}