Compare commits
2 Commits
1fdc51a668
...
eb4a8ed663
Author | SHA1 | Date | |
---|---|---|---|
|
eb4a8ed663 | ||
|
3fb6eb65a8 |
Binary file not shown.
BIN
builtins/.echo.c.swp
Normal file
BIN
builtins/.echo.c.swp
Normal file
Binary file not shown.
@ -6,7 +6,11 @@
|
||||
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/02/17 13:09:08 by erey-bet #+# #+# */
|
||||
<<<<<<< HEAD
|
||||
/* Updated: 2023/02/21 21:45:38 by cchauvet ### ########.fr */
|
||||
=======
|
||||
/* Updated: 2023/02/21 22:09:55 by erey-bet ### ########.fr */
|
||||
>>>>>>> 1fdc51a668e616de94c33d5b3b1e9cb51182916d
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
6
cmd.c
6
cmd.c
@ -6,7 +6,7 @@
|
||||
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/02/15 14:18:21 by cchauvet #+# #+# */
|
||||
/* Updated: 2023/02/20 14:47:29 by starnakin ### ########.fr */
|
||||
/* Updated: 2023/02/21 21:54:08 by cchauvet ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -22,6 +22,10 @@ void ft_cmddel(void *ptr)
|
||||
ft_freer_tab_ultimate(1, content->args);
|
||||
if (content->executable != NULL)
|
||||
free(content->executable);
|
||||
if (content->fd_in > 2)
|
||||
close(content->fd_in);
|
||||
if (content->fd_out > 2)
|
||||
close(content->fd_in);
|
||||
free(content);
|
||||
}
|
||||
|
||||
|
19
execution.c
19
execution.c
@ -6,7 +6,7 @@
|
||||
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/02/21 12:45:16 by cchauvet #+# #+# */
|
||||
/* Updated: 2023/02/21 15:45:24 by cchauvet ### ########.fr */
|
||||
/* Updated: 2023/02/21 22:11:34 by cchauvet ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -119,7 +119,7 @@ static int ft_own_cmd(t_list **env, t_cmd *cmd)
|
||||
return (return_code);
|
||||
}
|
||||
|
||||
int ft_cmds_executor(t_list **cmds, t_list **env)
|
||||
int ft_cmds_executor(t_data *data, t_list **cmds)
|
||||
{
|
||||
t_cmd *content;
|
||||
t_list *current;
|
||||
@ -141,25 +141,24 @@ int ft_cmds_executor(t_list **cmds, t_list **env)
|
||||
content->fd_out = fds[1];
|
||||
((t_cmd *) current->next->content)->fd_in = fds[0];
|
||||
}
|
||||
cmd_return = ft_own_cmd(env, content);
|
||||
cmd_return = ft_own_cmd(data->env, content);
|
||||
if (cmd_return == -1)
|
||||
{
|
||||
content->executable = ft_get_executable_path(
|
||||
content->executable, env);
|
||||
content->executable, data->env);
|
||||
if (content->executable != NULL)
|
||||
cmd_return = ft_excutor(content, env);
|
||||
cmd_return = ft_excutor(content, data->env);
|
||||
}
|
||||
if (content->fd_in != 0)
|
||||
close(content->fd_in);
|
||||
if (content->fd_out != 1 && content->fd_out != 2)
|
||||
close(content->fd_out);
|
||||
else if (cmd_return == -2)
|
||||
return (-1);
|
||||
data->exit_code = cmd_return;
|
||||
return_value = ft_itoa(cmd_return);
|
||||
if (return_value == NULL)
|
||||
{
|
||||
ft_eprintf("minishell: malloc failed\n");
|
||||
return (1);
|
||||
}
|
||||
set_value_by_key("?", return_value, env);
|
||||
set_value_by_key("?", return_value, data->env);
|
||||
current = current->next;
|
||||
}
|
||||
return (0);
|
||||
|
11
main.c
11
main.c
@ -6,7 +6,7 @@
|
||||
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/02/16 15:16:14 by cchauvet #+# #+# */
|
||||
/* Updated: 2023/02/21 14:48:07 by cchauvet ### ########.fr */
|
||||
/* Updated: 2023/02/21 22:05:04 by cchauvet ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -35,7 +35,7 @@ static char *ft_get_user_input(t_list **env)
|
||||
return (line);
|
||||
}
|
||||
|
||||
static int ft_minishell(t_list **env, char *line)
|
||||
static int ft_minishell(t_data *data, char *line)
|
||||
{
|
||||
t_list **cmds;
|
||||
int code;
|
||||
@ -64,7 +64,7 @@ static int ft_minishell(t_list **env, char *line)
|
||||
free(line_clean);
|
||||
return (1);
|
||||
}
|
||||
cmds = ft_parse_cmds(line_clean, env, infile, outfile);
|
||||
cmds = ft_parse_cmds(line_clean, data->env, infile, outfile);
|
||||
if (cmds == NULL)
|
||||
{
|
||||
close(outfile);
|
||||
@ -74,7 +74,7 @@ static int ft_minishell(t_list **env, char *line)
|
||||
free(line_clean);
|
||||
return (1);
|
||||
}
|
||||
code = ft_cmds_executor(cmds, env);
|
||||
code = ft_cmds_executor(data, cmds);
|
||||
ft_lstclear(cmds, ft_cmddel);
|
||||
free(cmds);
|
||||
free(line_clean);
|
||||
@ -129,7 +129,7 @@ int main(int ac, char **av, char **env)
|
||||
}
|
||||
while (line != NULL)
|
||||
{
|
||||
if (ft_minishell(data.env, line) == 2)
|
||||
if (ft_minishell(&data, line) == -1)
|
||||
break ;
|
||||
free(line);
|
||||
line = ft_get_user_input(data.env);
|
||||
@ -142,6 +142,7 @@ int main(int ac, char **av, char **env)
|
||||
}
|
||||
ft_lstclear(data.env, env_del);
|
||||
free(data.env);
|
||||
return (data.exit_code);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
16
minishell.h
16
minishell.h
@ -6,7 +6,7 @@
|
||||
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/02/14 13:45:30 by cchauvet #+# #+# */
|
||||
/* Updated: 2023/02/21 15:43:50 by erey-bet ### ########.fr */
|
||||
/* Updated: 2023/02/21 22:03:41 by cchauvet ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -26,6 +26,12 @@
|
||||
# include <readline/history.h>
|
||||
# define DEBUG 0
|
||||
|
||||
typedef struct s_data
|
||||
{
|
||||
t_list **env;
|
||||
int exit_code;
|
||||
} t_data;
|
||||
|
||||
int ft_syntatic_verif(const char *str);
|
||||
int ft_file_is_readable(const char *path);
|
||||
int ft_file_is_writable(const char *path);
|
||||
@ -35,7 +41,7 @@ int ft_infile(char *line);
|
||||
int ft_outfile(char *line);
|
||||
int ft_heredoc(char *stop);
|
||||
size_t ft_seglen_quoted(const char *str, char c);
|
||||
int ft_cmds_executor(t_list **cmds, t_list **env);
|
||||
int ft_cmds_executor(t_data *data, t_list **cmds);
|
||||
char **ft_split_quoted(const char *s, char c);
|
||||
void ft_cmddel(void *content);
|
||||
void env_del(void *content);
|
||||
@ -82,12 +88,6 @@ typedef struct s_cmd
|
||||
char **args;
|
||||
} t_cmd;
|
||||
|
||||
typedef struct s_data
|
||||
{
|
||||
t_list **env;
|
||||
int heredoc;
|
||||
} t_data;
|
||||
|
||||
typedef struct s_env
|
||||
{
|
||||
void *key;
|
||||
|
Loading…
Reference in New Issue
Block a user