Skip to content
Snippets Groups Projects
Commit 716d5459 authored by Simion George's avatar Simion George
Browse files

DONE

parent 1b332926
No related branches found
No related tags found
No related merge requests found
Pipeline #98993 passed
...@@ -68,6 +68,7 @@ static int parse_simple(simple_command_t *s, int level, command_t *father) ...@@ -68,6 +68,7 @@ static int parse_simple(simple_command_t *s, int level, command_t *father)
shell_exit(); shell_exit();
} else if (strcmp(command, "cd") == 0) { } else if (strcmp(command, "cd") == 0) {
/* Saving the old output, redirecting if the case, readjusting the ouput to the old one */
int save = dup(STDOUT_FILENO); int save = dup(STDOUT_FILENO);
char *out = get_word(s->out); char *out = get_word(s->out);
int out_fd = open(out, O_WRONLY | O_CREAT | O_TRUNC, 0644); int out_fd = open(out, O_WRONLY | O_CREAT | O_TRUNC, 0644);
...@@ -83,6 +84,7 @@ static int parse_simple(simple_command_t *s, int level, command_t *father) ...@@ -83,6 +84,7 @@ static int parse_simple(simple_command_t *s, int level, command_t *father)
return status; return status;
} else { } else {
/* Getting the environment variable and modifying */
char *envir_var = get_word(s->verb); char *envir_var = get_word(s->verb);
if (strchr(envir_var, '=') != NULL) { if (strchr(envir_var, '=') != NULL) {
...@@ -110,6 +112,7 @@ static int parse_simple(simple_command_t *s, int level, command_t *father) ...@@ -110,6 +112,7 @@ static int parse_simple(simple_command_t *s, int level, command_t *father)
return -1; return -1;
} else if (pid == 0) { } else if (pid == 0) {
/* Saving the in */
char *in = get_word(s->in); char *in = get_word(s->in);
int in_fd = open(in, O_RDONLY); int in_fd = open(in, O_RDONLY);
...@@ -117,6 +120,7 @@ static int parse_simple(simple_command_t *s, int level, command_t *father) ...@@ -117,6 +120,7 @@ static int parse_simple(simple_command_t *s, int level, command_t *father)
free(in); free(in);
if (s->out != NULL && s->err != NULL && strcmp(get_word(s->out), get_word(s->err)) == 0) { if (s->out != NULL && s->err != NULL && strcmp(get_word(s->out), get_word(s->err)) == 0) {
/* For the &> redirection */
char *out = get_word(s->out); char *out = get_word(s->out);
int out_fd; int out_fd;
...@@ -130,6 +134,7 @@ static int parse_simple(simple_command_t *s, int level, command_t *father) ...@@ -130,6 +134,7 @@ static int parse_simple(simple_command_t *s, int level, command_t *father)
free(out); free(out);
} else { } else {
/* Opening the out and error if they exists */
if (s->out != NULL) { if (s->out != NULL) {
char *out = get_word(s->out); char *out = get_word(s->out);
int out_fd; int out_fd;
...@@ -157,6 +162,7 @@ static int parse_simple(simple_command_t *s, int level, command_t *father) ...@@ -157,6 +162,7 @@ static int parse_simple(simple_command_t *s, int level, command_t *father)
} }
} }
/* Getting the commmand and executing it. If error, exit */
int argc = 0; int argc = 0;
char **argv = get_argv(s, &argc); char **argv = get_argv(s, &argc);
...@@ -187,6 +193,7 @@ static bool run_in_parallel(command_t *cmd1, command_t *cmd2, int level, ...@@ -187,6 +193,7 @@ static bool run_in_parallel(command_t *cmd1, command_t *cmd2, int level,
command_t *father) command_t *father)
{ {
/* TODO: Execute cmd1 and cmd2 simultaneously. */ /* TODO: Execute cmd1 and cmd2 simultaneously. */
/* Two kids, both executing down the tree command */
pid_t pid1 = fork(); pid_t pid1 = fork();
...@@ -221,8 +228,11 @@ static bool run_on_pipe(command_t *cmd1, command_t *cmd2, int level, ...@@ -221,8 +228,11 @@ static bool run_on_pipe(command_t *cmd1, command_t *cmd2, int level,
int pipefd[2]; int pipefd[2];
/* Pipe for in - out functionality */
pipe(pipefd); pipe(pipefd);
/* The first end. Closing the end we do not use, */
/* Pointing the output of the first process to the in of the second */
pid_t pid1 = fork(); pid_t pid1 = fork();
if (pid1 == 0) { if (pid1 == 0) {
...@@ -235,6 +245,8 @@ static bool run_on_pipe(command_t *cmd1, command_t *cmd2, int level, ...@@ -235,6 +245,8 @@ static bool run_on_pipe(command_t *cmd1, command_t *cmd2, int level,
exit(stat); exit(stat);
} }
/* Second end. */
/* Taking the input from the ouput end of the pipe (reading one) */
pid_t pid2 = fork(); pid_t pid2 = fork();
if (pid2 == 0) { if (pid2 == 0) {
......
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