ESH

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

AuthorJamozed <[email protected]>
Date2021-08-19 10:03:21
Commit5a1a1c1737265d61ca898c1f5e2f50f2cfcfc1ff
Parent61d48de47e99fa859414d8ede55b49257fd1cefb

Begin implementing rc file handling

Diffstat

M CHANGELOG | 3 +++
M src/conf.c | 29 ++++++++++++++++++++++++++++-
M src/conf.h | 2 ++
M src/lineread.c | 4 +++-

4 files changed, 36 insertions, 2 deletions

diff --git a/CHANGELOG b/CHANGELOG
index 68cda6c..2e092b0 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -1,5 +1,8 @@
 0.5.0,
 * Rename OSH to ESH
+* Implement --help and --version
+* Implement command history
+* Implement configuration
 
 0.4.0, 2021-04-01
 * Fix SIGINT handling at prompt
diff --git a/src/conf.c b/src/conf.c
index ed6bea7..5affc85 100644
--- a/src/conf.c
+++ b/src/conf.c
@@ -32,6 +32,33 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS WITH THE SOFTWARE.
 
 #include "conf.h"
 
+#include "lib/error.h"
+
+#include <errno.h>
+#include <stdio.h>
 #include <stdlib.h>
+#include <string.h>
+
+size_t conf_histsize = 8192;
 
-size_t conf_histsize = 0;
+void confread(void) {
+	char *bp, *fp; register size_t bl; FILE *fi;
+	
+	if (!(bp = getenv("XDG_CONFIG_HOME"))) {
+		if (!(bp = getenv("HOME"))) { warn("$HOME is undefined"); return; }
+		bl = strlen(bp); if (!(fp = calloc(bl + 19, sizeof (*fp)))) { return; }
+		memcpy(fp, bp, bl); memcpy(fp + bl, "/.config/esh/eshrc", 18);
+	}
+	else {
+		bl = strlen(bp); if (!(fp = calloc(bl + 11, sizeof (*fp)))) { return; }
+		memcpy(fp, bp, bl); memcpy(fp + bl, "/esh/eshrc", 10);
+	}
+	
+	if (!(fi = fopen(fp, "r")) && errno != ENOENT) {
+		perror(fp); free(fp); return;
+	}
+	
+	/* TODO execute rc file */
+	
+	free(fp); return;
+}
diff --git a/src/conf.h b/src/conf.h
index 8305512..e1f5e32 100644
--- a/src/conf.h
+++ b/src/conf.h
@@ -37,4 +37,6 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS WITH THE SOFTWARE.
 
 extern size_t conf_histsize;
 
+extern void confread(void);
+
 #endif // OMKOV_ESH_CONF_H_SOQSQ8HL
diff --git a/src/lineread.c b/src/lineread.c
index 7180cce..3cc9d10 100644
--- a/src/lineread.c
+++ b/src/lineread.c
@@ -409,7 +409,9 @@ static void histMoveEnd(struct hist *h) {
 
 /* Push a line onto the end of history */
 static void histPush(struct hist *h, struct line l) {
-	if (h->al != h->ac) { ++h->al; h->ap = h->at; if (++h->at == h->ac) { h->at = 0; }}
+	if (h->al != h->ac) {
+		++h->al; h->ap = h->at; if (++h->at == h->ac) { h->at = 0; }
+	}
 	else { h->ap = h->at; if (++h->at == h->ac) { h->at = 0; } h->ah = h->at; }
 
 	free(h->a[h->ap].s); h->a[h->ap] = l; return;