aboutsummaryrefslogtreecommitdiffstats
path: root/src/hush.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/hush.c')
-rw-r--r--src/hush.c18
1 files changed, 6 insertions, 12 deletions
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);