From f84e64b593c6e6fda9e2a907d25ed99d8742d619 Mon Sep 17 00:00:00 2001 From: "Douglas B. Rumbaugh" Date: Sat, 1 Nov 2025 15:18:03 -0400 Subject: Added support for required builtins --- src/hush.c | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) (limited to 'src/hush.c') diff --git a/src/hush.c b/src/hush.c index 0d25244..2d40aa7 100644 --- a/src/hush.c +++ b/src/hush.c @@ -15,6 +15,7 @@ #include "lexer.h" #include "command.h" #include "variables.h" +#include "builtin.h" FILE *open_input(int argc, char **argv) { FILE *input_file = (argc > 1) ? fopen(argv[1], "r") : stdin; @@ -37,8 +38,6 @@ static size_t get_command_len(char *cmdstr) { void variable_substitution(command *cmds) { for (command *cmd = cmds; cmd; cmd = cmd->next) { - fprintf(stderr, "Before substitution\n"); - print_commands(stderr, cmd); for (size_t i=0; i < MAX_ARGUMENT_CNT + 1; i++) { if (is_variable(cmd->args[i])) { cmd->args[i] = get_variable(cmd->args[i]); @@ -52,9 +51,6 @@ void variable_substitution(command *cmds) { if (is_variable(cmd->infile)) { cmd->infile = get_variable(cmd->infile); } - - fprintf(stderr, "After substitution\n"); - print_commands(stderr, cmd); } } @@ -94,8 +90,6 @@ int main(int argc, char **argv) { } } - // print_parsed_command(stdout, parsed_cmd); - if (parsed_cmd->type == TKN_VARKEY) { if (!add_variable(parsed_cmd->text, parsed_cmd->next->text)) { fprintf(stderr, "ERROR: Failed to create variable\n"); @@ -113,14 +107,14 @@ int main(int argc, char **argv) { variable_substitution(cmds); for (command *cmd = cmds; cmd; cmd = cmd->next) { - pid_t result = execute_command(cmd); - if (result < 0) { - break; + if (!run_builtin(cmd)) { + pid_t result = execute_command(cmd); + if (result < 0) { + break; + } } } - // print_commands(stdout, cmds); - for (command *cmd = cmds; cmd; cmd = cmd->next) { if (cmd->pid > 0) { waitpid(cmd->pid, NULL, 0); -- cgit v1.2.3