Compare commits
No commits in common. "eb4a8ed663b2f93cd955f7608aa686bd8e767a65" and "1fdc51a668e616de94c33d5b3b1e9cb51182916d" have entirely different histories.
eb4a8ed663
...
1fdc51a668
BIN
.nfs00000000098c85f700000036
Executable file
BIN
.nfs00000000098c85f700000036
Executable file
Binary file not shown.
Binary file not shown.
@ -6,11 +6,7 @@
|
||||
/* 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/21 21:54:08 by cchauvet ### ########.fr */
|
||||
/* Updated: 2023/02/20 14:47:29 by starnakin ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -22,10 +22,6 @@ 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 22:11:34 by cchauvet ### ########.fr */
|
||||
/* Updated: 2023/02/21 15:45:24 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_data *data, t_list **cmds)
|
||||
int ft_cmds_executor(t_list **cmds, t_list **env)
|
||||
{
|
||||
t_cmd *content;
|
||||
t_list *current;
|
||||
@ -141,24 +141,25 @@ int ft_cmds_executor(t_data *data, t_list **cmds)
|
||||
content->fd_out = fds[1];
|
||||
((t_cmd *) current->next->content)->fd_in = fds[0];
|
||||
}
|
||||
cmd_return = ft_own_cmd(data->env, content);
|
||||
cmd_return = ft_own_cmd(env, content);
|
||||
if (cmd_return == -1)
|
||||
{
|
||||
content->executable = ft_get_executable_path(
|
||||
content->executable, data->env);
|
||||
content->executable, env);
|
||||
if (content->executable != NULL)
|
||||
cmd_return = ft_excutor(content, data->env);
|
||||
cmd_return = ft_excutor(content, env);
|
||||
}
|
||||
else if (cmd_return == -2)
|
||||
return (-1);
|
||||
data->exit_code = cmd_return;
|
||||
if (content->fd_in != 0)
|
||||
close(content->fd_in);
|
||||
if (content->fd_out != 1 && content->fd_out != 2)
|
||||
close(content->fd_out);
|
||||
return_value = ft_itoa(cmd_return);
|
||||
if (return_value == NULL)
|
||||
{
|
||||
ft_eprintf("minishell: malloc failed\n");
|
||||
return (1);
|
||||
}
|
||||
set_value_by_key("?", return_value, data->env);
|
||||
set_value_by_key("?", return_value, 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 22:05:04 by cchauvet ### ########.fr */
|
||||
/* Updated: 2023/02/21 14:48:07 by cchauvet ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -35,7 +35,7 @@ static char *ft_get_user_input(t_list **env)
|
||||
return (line);
|
||||
}
|
||||
|
||||
static int ft_minishell(t_data *data, char *line)
|
||||
static int ft_minishell(t_list **env, char *line)
|
||||
{
|
||||
t_list **cmds;
|
||||
int code;
|
||||
@ -64,7 +64,7 @@ static int ft_minishell(t_data *data, char *line)
|
||||
free(line_clean);
|
||||
return (1);
|
||||
}
|
||||
cmds = ft_parse_cmds(line_clean, data->env, infile, outfile);
|
||||
cmds = ft_parse_cmds(line_clean, env, infile, outfile);
|
||||
if (cmds == NULL)
|
||||
{
|
||||
close(outfile);
|
||||
@ -74,7 +74,7 @@ static int ft_minishell(t_data *data, char *line)
|
||||
free(line_clean);
|
||||
return (1);
|
||||
}
|
||||
code = ft_cmds_executor(data, cmds);
|
||||
code = ft_cmds_executor(cmds, env);
|
||||
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, line) == -1)
|
||||
if (ft_minishell(data.env, line) == 2)
|
||||
break ;
|
||||
free(line);
|
||||
line = ft_get_user_input(data.env);
|
||||
@ -142,7 +142,6 @@ 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 22:03:41 by cchauvet ### ########.fr */
|
||||
/* Updated: 2023/02/21 15:43:50 by erey-bet ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -26,12 +26,6 @@
|
||||
# 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);
|
||||
@ -41,7 +35,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_data *data, t_list **cmds);
|
||||
int ft_cmds_executor(t_list **cmds, t_list **env);
|
||||
char **ft_split_quoted(const char *s, char c);
|
||||
void ft_cmddel(void *content);
|
||||
void env_del(void *content);
|
||||
@ -88,6 +82,12 @@ 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