Skip to content
Snippets Groups Projects
Commit fcde7d21 authored by Dana-Maria CĂRUNTU's avatar Dana-Maria CĂRUNTU
Browse files

add sequential command execution (25p)

parent c55097ee
No related branches found
No related tags found
No related merge requests found
Pipeline #98734 passed
......@@ -31,8 +31,6 @@
static bool sanity_check_simple_command(simple_command_t *s);
static bool sanity_check_command(command_t *c);
static void clean_resources(int count, ...);
/**
* Internal change-directory command.
*/
......@@ -80,8 +78,6 @@ static void handle_input_redirection(word_t *in)
DIE(dup2(fd_in, STDIN_FILENO) == -1, "Failed to duplicate file descriptor for input redirection");
// close(fd_in);
// free(input_file);
clean_resources(1, fd_in, input_file);
}
......@@ -101,9 +97,6 @@ static void handle_output_redirection(word_t *out, int io_flags, word_t *err)
DIE(dup2(fd, STDOUT_FILENO) == -1, "Failed to redirect stdout");
DIE(dup2(fd, STDERR_FILENO) == -1, "Failed to redirect stderr");
// close(fd);
// free(output_file);
// free(error_file);
clean_resources(1, fd, output_file);
if (error_file != output_file) {
free(error_file);
......@@ -112,7 +105,6 @@ static void handle_output_redirection(word_t *out, int io_flags, word_t *err)
}
// if stdout and stderr are redirected to different files
// initialise with -1 to indicate that file descriptors are not yet opened
int fd_out = -1, fd_err = -1;
......@@ -122,9 +114,6 @@ static void handle_output_redirection(word_t *out, int io_flags, word_t *err)
DIE(fd_out == -1, "Failed to open output file");
DIE(dup2(fd_out, STDOUT_FILENO) == -1, "Failed to redirect stdout");
// close(fd_out);
// free(output_file);
}
if (error_file) {
......@@ -133,9 +122,6 @@ static void handle_output_redirection(word_t *out, int io_flags, word_t *err)
DIE(fd_err == -1, "Failed to open error file");
DIE(dup2(fd_err, STDERR_FILENO) == -1, "Failed to redirect stderr");
// close(fd_err);
// free(error_file);
}
clean_resources(2, fd_out, output_file, fd_err, error_file);
......@@ -149,7 +135,6 @@ static void handle_redirections(simple_command_t *s)
handle_output_redirection(s->out, s->io_flags, s->err);
}
/**
* Parse a simple command (internal, environment variable assignment,
* external command).
......@@ -277,9 +262,9 @@ int parse_command(command_t *c, int level, command_t *father)
switch (c->op) {
case OP_SEQUENTIAL:
parse_command(c->cmd1, level, c);
return parse_command(c->cmd2, level, c);
/* TODO: Execute the commands one after the other. */
break;
case OP_PARALLEL:
/* TODO: Execute the commands simultaneously. */
break;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment