clean: norm part 1
This commit is contained in:
@ -1,3 +1,15 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* parse.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/03/27 13:44:38 by cchauvet #+# #+# */
|
||||
/* Updated: 2023/03/28 15:42:37 by cchauvet ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "./parse_private.h"
|
||||
|
||||
static int ft_args_parse(char *cmd_str, t_cmd *cmd)
|
||||
@ -30,19 +42,11 @@ static int ft_executable_parse(t_data *data, t_cmd *cmd)
|
||||
ft_closer(cmd->fd_in);
|
||||
ft_closer(cmd->fd_out);
|
||||
}
|
||||
else if (ft_strcmp(cmd->args[0], "env") == 0)
|
||||
own = 1;
|
||||
else if (ft_strcmp(cmd->args[0], "export") == 0)
|
||||
own = 1;
|
||||
else if (ft_strcmp(cmd->args[0], "echo") == 0)
|
||||
own = 1;
|
||||
else if (ft_strcmp(cmd->args[0], "unset") == 0)
|
||||
own = 1;
|
||||
else if (ft_strcmp(cmd->args[0], "exit") == 0)
|
||||
own = 1;
|
||||
else if (ft_strcmp(cmd->args[0], "pwd") == 0)
|
||||
own = 1;
|
||||
else if (ft_strcmp(cmd->args[0], "cd") == 0)
|
||||
else if (ft_strcmp(cmd->args[0], "env") == 0 || (ft_strcmp(cmd->args[0],
|
||||
"export") == 0) || (ft_strcmp(cmd->args[0], "echo") == 0)
|
||||
|| (ft_strcmp(cmd->args[0], "unset") == 0) || (ft_strcmp(cmd->args[0],
|
||||
"exit") == 0) || (ft_strcmp(cmd->args[0], "pwd") == 0)
|
||||
|| (ft_strcmp(cmd->args[0], "cd") == 0))
|
||||
own = 1;
|
||||
else
|
||||
{
|
||||
@ -55,10 +59,23 @@ static int ft_executable_parse(t_data *data, t_cmd *cmd)
|
||||
return (0);
|
||||
}
|
||||
|
||||
int ft_cmd_adder(t_data *data, t_cmd *cmd)
|
||||
{
|
||||
t_list *element;
|
||||
|
||||
element = ft_lstnew(cmd);
|
||||
if (element == NULL)
|
||||
{
|
||||
ft_cmddel(cmd);
|
||||
return (1);
|
||||
}
|
||||
ft_lstadd_back(data->cmds, element);
|
||||
return (0);
|
||||
}
|
||||
|
||||
int ft_cmd_parser(t_data *data, char *cmd_str)
|
||||
{
|
||||
t_cmd *cmd;
|
||||
t_list *element;
|
||||
|
||||
cmd = ft_calloc(sizeof(t_cmd), 1);
|
||||
if (cmd == NULL)
|
||||
@ -81,37 +98,28 @@ int ft_cmd_parser(t_data *data, char *cmd_str)
|
||||
ft_cmddel(cmd);
|
||||
return (1);
|
||||
}
|
||||
element = ft_lstnew(cmd);
|
||||
if (element == NULL)
|
||||
{
|
||||
ft_cmddel(cmd);
|
||||
return (1);
|
||||
}
|
||||
ft_lstadd_back(data->cmds, element);
|
||||
return (0);
|
||||
return (ft_cmd_adder(data, cmd));
|
||||
}
|
||||
|
||||
int ft_cmds_parser(t_data *data, const char *line)
|
||||
{
|
||||
char **tab;
|
||||
size_t i;
|
||||
ssize_t i;
|
||||
|
||||
tab = ft_split_quoted(line, '|');
|
||||
if (tab == NULL)
|
||||
{
|
||||
ft_freer_tab_ultimate(1, tab);
|
||||
ft_eprintf("minishell: malloc failed\n");
|
||||
return (1);
|
||||
}
|
||||
i = 0;
|
||||
while (tab[i] != NULL)
|
||||
i = -1;
|
||||
while (tab[++i] != NULL)
|
||||
{
|
||||
if (ft_cmd_parser(data, tab[i]))
|
||||
{
|
||||
ft_freer_tab_ultimate(1, tab);
|
||||
return (1);
|
||||
}
|
||||
i++;
|
||||
}
|
||||
if (*data->cmds != NULL)
|
||||
{
|
||||
|
@ -1,3 +1,15 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* parse.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/03/28 15:42:38 by cchauvet #+# #+# */
|
||||
/* Updated: 2023/03/28 15:42:39 by cchauvet ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef PARSE_H
|
||||
# define PARSE_H
|
||||
# include "../data/data.h"
|
||||
|
@ -1,3 +1,15 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* parse_private.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/03/28 15:42:44 by cchauvet #+# #+# */
|
||||
/* Updated: 2023/03/28 15:42:45 by cchauvet ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef PARSE_PRIVATE_H
|
||||
# define PARSE_PRIVATE_H
|
||||
# include "../redirection/redirection.h"
|
||||
|
Reference in New Issue
Block a user