ESH

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

AuthorJamozed <[email protected]>
Date2021-11-15 13:55:01
Commit14bad1bb658817185a69b92f06be5db52b7b83ae
Parent671f3cde5f8d27a2be3828b1b123b34218f4813c

Prune depreciated compound command handling code

Diffstat

M src/exec.c | 33 ---------------------------------
M src/main.c | 1 +
M src/parse.c | 42 ++++++++++--------------------------------
M src/parse.h | 4 ++--

4 files changed, 13 insertions, 67 deletions

diff --git a/src/exec.c b/src/exec.c
index 7bb29e3..1dbb7b5 100644
--- a/src/exec.c
+++ b/src/exec.c
@@ -44,33 +44,18 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS WITH THE SOFTWARE.
 #include <stdlib.h>
 #include <string.h>
 
-static int execute_comp(ast a);
 static int execute_comm(ast a, int fdi, int fd[2]);
 static int execute_pipe(ast a, int fdi);
 
-static int launch(u8 *av[]);
-
 /* Execute a program. */
 int execute(ast a, int fdi, int fd[2]) {
 	switch (a->k) {
-	case AK_COMP: { return execute_comp(a); }
 	case AK_COMM: { return execute_comm(a, fdi, fd); }
 	case AK_PIPE: { return execute_pipe(a, fdi); }
 	default: { error(-1, "%s: Unimplemented AST", ast_ks[a->k]); }
 	}
 }
 
-/* Execute a compound statement. */
-static int execute_comp(ast a) {
-	register int ret = 0;
-	
-	for (UINT i = 0; i != a->c.al; i += 1) {
-		ret = execute(((ast *)a->c.a)[i], fileno(stdin), NULL);
-	}
-	
-	return ret;
-}
-
 /* Execute a command statement. */
 static int execute_comm(ast a, int fdi, int fd[2]) {
 	if (!a->s) { printf("WDTA?\n"); return _ret; } /* What does this achieve? */
@@ -110,21 +95,3 @@ static int execute_pipe(ast a, int fdi) {
 	int fd[2]; if (pipe(fd) == -1) { warn("PIPE: %s", serr()); return -1; }
 	execute(a->lc, fdi, fd); return execute(a->rc, fd[0], NULL);
 }
-
-/* Fork and execute an executable. */
-static int launch(u8 *av[]) {
-	pid_t pid, wpid; int status;
-	
-	if ((pid = fork()) == 0) {
-		signal(SIGINT, SIG_DFL);
-		
-		if (execvp((char *)av[0], (char **)av) == -1) {
-			if (errno == ENOENT) { warn("%s: Command not found", av[0]); }
-			else { perror((char *)av[0]); } exit(1);
-		}
-	}
-	else if (pid == -1) { perror((char *)av[0]); }
-	else { waitpid(pid, &status, 0); }
-	
-	return status;
-}
diff --git a/src/main.c b/src/main.c
index cdcca1a..4c00b0d 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.
 		command, or running an empty command, which results in blank history
 		entries.
 	TODO investigate builtins and their functionality with regards to pipes.
+	TODO reimplement compound commands without a dedicated AST kind.
 */
 
 #include "conf.h"
diff --git a/src/parse.c b/src/parse.c
index 55c38e1..898e644 100644
--- a/src/parse.c
+++ b/src/parse.c
@@ -44,11 +44,10 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS WITH THE SOFTWARE.
 #include <stdlib.h>
 
 char *ast_ks[] = {
-	"NULL", "COMP", "COMM",
-	"PIPE", "RDIN", "ROUT", "RERR"
+	"NULL", "COMM", "PIPE",
+	"RDIN", "ROUT", "RERR"
 };
 
-static ast parse_comp(lex *l);
 static ast parse_comm(lex *l);
 static ast parse_pipe(lex *l, ast lc);
 static ast parse_rdin(lex *l);
@@ -77,17 +76,6 @@ ast parse(lex *l) {
 	}
 }
 
-/* Parse a compound statement. */
-static ast parse_comp(lex *l) {
-	ast a = ast_init(); a->k = AK_COMP;
-	a->c = stack_init((void (*)(void *))&ast_free);
-	
-	/* Push each command onto the child stack */
-	for (; lex_peek(l).k != TK_EOF;) { stack_push(&a->c, parse_comm(l)); }
-	
-	return a;
-}
-
 /* Parse a command statement. */
 static ast parse_comm(lex *l) {
 	ast a = ast_init(); a->k = AK_COMM;
@@ -125,29 +113,19 @@ static ast parse_rerr(lex *l) {
 /* Print parser debug output with an indent. */
 static void ast_debug_indent(ast a, UINT i) {
 	for (UINT j = 0; j != i; ++j) { printf("\t"); }
+	
 	printf("%s: %s", ast_ks[a->k], a->s);
 
-	/* Print children if present */
-	switch (a->k) {
-	case AK_COMP: {
-		printf("\n");
-		for (UINT j = 0; j != a->c.al; j += 1) {
-			ast_debug_indent(((ast *)a->c.a)[j], i + 1);
-			printf("\n");
-		}
-	} break;
-	case AK_COMM: {
+	if (a->k == AK_COMM) {
 		for (UINT j = 1; j != a->c.al - 1; j += 1) {
 			printf(" %s", ((char **)a->c.a)[j]);
-		} printf("\n");
-	} break;
-	case AK_PIPE: {
-		printf("\n");
-		ast_debug_indent(a->lc, i + 1);
-		ast_debug_indent(a->rc, i + 1);
-	} break;
-	default: { warn("%s: Unimplemented AST (debug)", ast_ks[a->k]); } break;
+		}
 	}
+	
+	printf("\n");
+	
+	if (a->lc) { ast_debug_indent(a->lc, i + 1); }
+	if (a->rc) { ast_debug_indent(a->rc, i + 1); }
 }
 
 /* Print parser debug output. */
diff --git a/src/parse.h b/src/parse.h
index 583db1b..254e910 100644
--- a/src/parse.h
+++ b/src/parse.h
@@ -38,8 +38,8 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS WITH THE SOFTWARE.
 #include "util/util.h"
 
 typedef enum {
-	AK_NULL, AK_COMP, AK_COMM,
-	AK_PIPE, AK_RDIN, AK_ROUT, AK_RERR,
+	AK_NULL, AK_COMM, AK_PIPE,
+	AK_RDIN, AK_ROUT, AK_RERR,
 } ast_k;
 
 typedef struct ast_s *ast;