-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #75 from eguefif/test
Finished prep test and heredoc and fixed bug
- Loading branch information
Showing
12 changed files
with
114 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,7 @@ | |
/* By: maxpelle <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2023/11/10 18:40:07 by eguefif #+# #+# */ | ||
/* Updated: 2023/11/23 11:30:39 by eguefif ### ########.fr */ | ||
/* Updated: 2023/11/23 13:28:36 by eguefif ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
|
@@ -68,6 +68,7 @@ size_t get_count_var_env(char *token); | |
size_t get_env_var_len(char **env_var); | ||
char **get_env_list(char *token, char **env); | ||
size_t get_new_token_size(char *token, char **var_env); | ||
char *clean_tokens_stdin(char *token); | ||
|
||
int ms_execute(t_command *commnands, char ***env); | ||
char *get_command_path(char *command, char **env); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,7 @@ | |
/* By: maxpelle <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2023/11/13 12:16:43 by eguefif #+# #+# */ | ||
/* Updated: 2023/11/23 11:13:39 by eguefif ### ########.fr */ | ||
/* Updated: 2023/11/23 13:28:34 by eguefif ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
|
@@ -60,9 +60,15 @@ static int run(t_command *commands, char ***env) | |
return (1); | ||
if (set_redirections(commands[i], pipe_fd, | ||
commands[i + 1].last)) | ||
return (1); | ||
{ | ||
ms_clean_commands(commands); | ||
exit(0); | ||
} | ||
if (!commands[i].args[0]) | ||
return (0); | ||
{ | ||
ms_clean_commands(commands); | ||
exit (0); | ||
} | ||
ft_exit_nb(commands, handle_child(&commands[i], *env)); | ||
} | ||
if (dup2(pipe_fd[0], 0) == -1) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,7 @@ | |
/* By: eguefif <[email protected].> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2023/11/20 18:40:07 by eguefif #+# #+# */ | ||
/* Updated: 2023/11/20 17:37:48 by eguefif ### ########.fr */ | ||
/* Updated: 2023/11/23 13:28:35 by eguefif ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,7 @@ | |
/* By: maxpelle <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2023/11/10 18:42:06 by eguefif #+# #+# */ | ||
/* Updated: 2023/11/23 11:37:34 by eguefif ### ########.fr */ | ||
/* Updated: 2023/11/23 12:38:41 by eguefif ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
|
@@ -45,29 +45,45 @@ int main(int argc, char **argv, char **env) | |
|
||
char **non_interactive_mode(char **env) | ||
{ | ||
t_command *commands; | ||
char *line; | ||
t_command *commands; | ||
int retval; | ||
|
||
line = get_next_line(0); | ||
while (line) | ||
{ | ||
retval = 0; | ||
if (ms_init_signals() != 0) | ||
break ; | ||
if (check_valid_line_for_history(line)) | ||
{ | ||
commands = ms_parser(line, env); | ||
if (commands->args[0] && ft_strcmp(commands->args[0], "exit") == 0) | ||
{ | ||
if (commands->args[1]) | ||
retval = ft_atoi(commands->args[1]); | ||
env = handle_exit_code(env, retval); | ||
break ; | ||
} | ||
if (line) | ||
free(line); | ||
if (errno == ENOMEM) | ||
break ; | ||
if (commands) | ||
{ | ||
retval = ms_execute(commands, &env); | ||
env = handle_exit_code(env, retval); | ||
} | ||
line = get_next_line(0); | ||
if (line) | ||
free(line); | ||
else | ||
env = handle_exit_code(env, 258); | ||
ms_clean_commands(commands); | ||
} | ||
else if (!line) | ||
{ | ||
ft_printf("exit\n"); | ||
break ; | ||
} | ||
line = get_next_line(0); | ||
} | ||
return (env); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,7 @@ | |
/* By: maxpelle <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2023/11/16 13:15:11 by maxpelle #+# #+# */ | ||
/* Updated: 2023/11/20 17:43:16 by eguefif ### ########.fr */ | ||
/* Updated: 2023/11/23 13:24:07 by eguefif ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
|
@@ -41,8 +41,14 @@ void parser_clean_commands(t_command *commands, char **env) | |
commands[i].args[j] = clean_tokens(commands[i].args[j], env); | ||
} | ||
if (commands[i].redirections.r_stdin) | ||
commands[i].redirections.r_stdin | ||
= clean_tokens(commands[i].redirections.r_stdin, env); | ||
{ | ||
if (commands[i].redirections.heredoc > 0) | ||
commands[i].redirections.r_stdin | ||
= clean_tokens_stdin(commands[i].redirections.r_stdin); | ||
else | ||
commands[i].redirections.r_stdin | ||
= clean_tokens(commands[i].redirections.r_stdin, env); | ||
} | ||
if (commands[i].redirections.r_stdout) | ||
commands[i].redirections.r_stdout | ||
= clean_tokens(commands[i].redirections.r_stdout, env); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,7 @@ | |
/* By: maxpelle <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2023/11/17 14:59:51 by maxpelle #+# #+# */ | ||
/* Updated: 2023/11/20 17:44:15 by eguefif ### ########.fr */ | ||
/* Updated: 2023/11/23 12:59:52 by eguefif ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/* ************************************************************************** */ | ||
/* */ | ||
/* ::: :::::::: */ | ||
/* parser_clean_commands_stdin.c :+: :+: :+: */ | ||
/* +:+ +:+ +:+ */ | ||
/* By: eguefif <[email protected].> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2023/11/23 13:07:15 by eguefif #+# #+# */ | ||
/* Updated: 2023/11/23 13:22:49 by eguefif ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
#include "minishell.h" | ||
|
||
size_t get_quotes_number(char *token); | ||
|
||
char *clean_tokens_stdin(char *token) | ||
{ | ||
size_t size; | ||
size_t i; | ||
size_t j; | ||
char *retval; | ||
|
||
size = get_quotes_number(token); | ||
retval = (char *) malloc(sizeof(char) * (size + 1)); | ||
if (!retval) | ||
{ | ||
free(token); | ||
return (0); | ||
} | ||
retval[size] = 0; | ||
i = 0; | ||
j = 0; | ||
while (i < size) | ||
{ | ||
if (!ft_strchr("\'\"", token[i])) | ||
{ | ||
retval[j] = token[i]; | ||
j++; | ||
} | ||
i++; | ||
} | ||
return (retval); | ||
} | ||
|
||
size_t get_quotes_number(char *token) | ||
{ | ||
size_t retval; | ||
int i; | ||
|
||
retval = 0; | ||
i = 0; | ||
while (token[i]) | ||
{ | ||
if (token[i] == '\'' || token[i] == '\"') | ||
retval++; | ||
i++; | ||
} | ||
return (retval); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,7 @@ | |
/* By: eguefif <[email protected].> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2023/11/17 14:22:53 by eguefif #+# #+# */ | ||
/* Updated: 2023/11/17 14:45:58 by eguefif ### ########.fr */ | ||
/* Updated: 2023/11/23 12:51:53 by eguefif ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
|
@@ -86,7 +86,12 @@ static t_redirections populate_redirection(t_redirections redir, | |
if (token[0] == '<') | ||
{ | ||
if (token[1] == '<') | ||
redir.heredoc = 1; | ||
{ | ||
if (ft_strchr(token, '\"') || ft_strchr(token, '\'')) | ||
redir.heredoc = 1; | ||
else | ||
redir.heredoc = 2; | ||
} | ||
if (redir.r_stdin) | ||
free(redir.r_stdin); | ||
redir.r_stdin = ft_strdup(file); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,7 @@ | |
/* By: eguefif <[email protected].> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2023/11/20 10:12:18 by eguefif #+# #+# */ | ||
/* Updated: 2023/11/20 17:27:02 by eguefif ### ########.fr */ | ||
/* Updated: 2023/11/23 13:28:34 by eguefif ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters