ESH

Executive Shell
git clone http://git.omkov.net/ESH
Log | Tree | Refs | README | Download

AuthorJamozed <[email protected]>
Date2021-08-08 09:43:04
Commit5c73de53c466e33faebeb362b1623acab081c396
Parent661480bbe6070581bda059b3ad77370c1a350283

Add set builtin

Diffstat

M src/bltn.c | 2 ++
A src/bltns/set.c | 85 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

2 files changed, 87 insertions, 0 deletions

diff --git a/src/bltn.c b/src/bltn.c
index 130b76e..395f428 100644
--- a/src/bltn.c
+++ b/src/bltn.c
@@ -47,6 +47,7 @@ static int bltn_true(char *av[]) { (void)(av); return 0; }
 
 extern int bltn_cd(char *av[]);
 extern int bltn_pwd(char *av[]);
+extern int bltn_set(char *av[]);
 
 static int getret(char *av[]) { printf("%d\n", _ret); return 0; }
 
@@ -58,6 +59,7 @@ struct bltn bltns[] = {
 	{"false", &bltn_false},
 	{"help",  &bltn_help},
 	{"pwd",   &bltn_pwd},
+	{"set",   &bltn_set},
 	{"true",  &bltn_true},
 	{"ret",   &getret},
 	{NULL, NULL}
diff --git a/src/bltns/set.c b/src/bltns/set.c
new file mode 100644
index 0000000..d67d076
--- /dev/null
+++ b/src/bltns/set.c
@@ -0,0 +1,85 @@
+// set.c
+// set builtin source file for ESH
+// Copyright (C) 2020, Jakob Wakeling
+// All rights reserved.
+
+/*
+OMKOV Permissive Licence, version 1.0
+
+Permission is hereby granted, free of charge, to any person obtaining a copy of
+this software and associated documentation files (the "Software"), to deal with
+the Software without restriction, including without limitation the rights to
+use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
+the Software, and to permit persons to whom the Software is furnished to do so,
+subject to the following conditions:
+
+* Redistributions of source code must retain the above copyright notice, this
+  list of conditions and the following disclaimers.
+* Redistributions in binary form must reproduce the above copyright notice, this
+  list of conditions and the following disclaimers in the documentation and/or
+  other materials provided with the distribution.
+* Neither the names of the copyright holders, nor the names of its contributors
+  may be used to endorse or promote products derived from this Software without
+  specific prior written permission.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
+FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE COPYRIGHT
+HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS WITH THE SOFTWARE.
+*/
+
+#include "../conf.h"
+
+#include "../lib/optget.h"
+#include "../lib/error.h"
+#include "../lib/strconv.h"
+
+#include <stddef.h>
+#include <stdio.h>
+
+static struct lop lops[] = {
+	{ "help",     ARG_NUL, 256 },
+	{ "version",  ARG_NUL, 257 },
+	{ "histsize", ARG_REQ, 259 },
+	{ NULL, 0, 0 }
+};
+
+static int mode = 0;
+
+static void hlp(void);
+static void ver(void);
+
+int bltn_set(char *av[]) {
+	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; }
+	case 259: {
+		char *ep; uint64_t n = strtou64(opt.arg, &ep, 10);
+		if (*ep) { warn("%s: invalid histsize", opt.arg); return 1; }
+		conf_histsize = n; return 0;
+	}
+	default: { return 1; }
+	}
+	
+	return 0;
+}
+
+static void hlp(void) {
+	puts("set - Set ESH options\n");
+	puts("Usage: set\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;
+}