cmd->token to cmd->value parce que c'est plus logique
This commit is contained in:
Binary file not shown.
BIN
srcs/.exec.c.swp
BIN
srcs/.exec.c.swp
Binary file not shown.
@ -6,7 +6,7 @@
|
|||||||
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
|
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/03/05 18:20:21 by marde-vr #+# #+# */
|
/* Created: 2024/03/05 18:20:21 by marde-vr #+# #+# */
|
||||||
/* Updated: 2024/03/25 12:36:27 by tomoron ### ########.fr */
|
/* Updated: 2024/03/27 14:59:17 by tomoron ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -51,19 +51,19 @@ int cmd_is_builtin(t_msh *msh, char *cmd_token)
|
|||||||
|
|
||||||
int exec_builtin(t_msh *msh)
|
int exec_builtin(t_msh *msh)
|
||||||
{
|
{
|
||||||
if (!msh->cmds->token)
|
if (!msh->cmds->value)
|
||||||
return (0);
|
return (0);
|
||||||
if (!ft_strcmp(msh->cmds->token, "echo"))
|
if (!ft_strcmp(msh->cmds->value, "echo"))
|
||||||
g_return_code = echo(msh->cmds->next);
|
g_return_code = echo(msh->cmds->next);
|
||||||
else if (!ft_strcmp(msh->cmds->token, "ret"))
|
else if (!ft_strcmp(msh->cmds->value, "ret"))
|
||||||
g_return_code = ft_atoi(msh->cmds->next->token);
|
g_return_code = ft_atoi(msh->cmds->next->value);
|
||||||
else if (!ft_strcmp(msh->cmds->token, "env"))
|
else if (!ft_strcmp(msh->cmds->value, "env"))
|
||||||
g_return_code = print_env(msh->env);
|
g_return_code = print_env(msh->env);
|
||||||
else if (!ft_strcmp(msh->cmds->token, "exit"))
|
else if (!ft_strcmp(msh->cmds->value, "exit"))
|
||||||
exit_bt(msh);
|
exit_bt(msh);
|
||||||
else if (!ft_strcmp(msh->cmds->token, "pwd"))
|
else if (!ft_strcmp(msh->cmds->value, "pwd"))
|
||||||
g_return_code = pwd();
|
g_return_code = pwd();
|
||||||
else if (!ft_strcmp(msh->cmds->token, "cd"))
|
else if (!ft_strcmp(msh->cmds->value, "cd"))
|
||||||
g_return_code = cd(msh->cmds);
|
g_return_code = cd(msh->cmds);
|
||||||
else
|
else
|
||||||
return (0);
|
return (0);
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
|
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/02/16 21:02:54 by marde-vr #+# #+# */
|
/* Created: 2024/02/16 21:02:54 by marde-vr #+# #+# */
|
||||||
/* Updated: 2024/03/06 08:43:53 by marde-vr ### ########.fr */
|
/* Updated: 2024/03/27 14:49:28 by tomoron ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -25,7 +25,7 @@ int cd(t_cmd *args)
|
|||||||
if (!args->next || args->next->type != ARG)
|
if (!args->next || args->next->type != ARG)
|
||||||
new_wd = getenv("HOME");
|
new_wd = getenv("HOME");
|
||||||
else
|
else
|
||||||
new_wd = args->next->token;
|
new_wd = args->next->value;
|
||||||
if (chdir(new_wd) == -1)
|
if (chdir(new_wd) == -1)
|
||||||
{
|
{
|
||||||
perror("minishell: cd");
|
perror("minishell: cd");
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
|
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/03/05 18:22:15 by marde-vr #+# #+# */
|
/* Created: 2024/03/05 18:22:15 by marde-vr #+# #+# */
|
||||||
/* Updated: 2024/03/26 09:19:40 by marde-vr ### ########.fr */
|
/* Updated: 2024/03/27 14:59:43 by tomoron ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -71,9 +71,9 @@ char **get_cmd_args(t_msh *msh)
|
|||||||
if (cur_cmd->type == ARG)
|
if (cur_cmd->type == ARG)
|
||||||
{
|
{
|
||||||
if (!i)
|
if (!i)
|
||||||
cmd_args[i] = remove_path(cur_cmd->token);
|
cmd_args[i] = remove_path(cur_cmd->value);
|
||||||
else
|
else
|
||||||
cmd_args[i] = cur_cmd->token;
|
cmd_args[i] = cur_cmd->value;
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -96,7 +96,7 @@ void remove_command_from_msh(t_msh *msh)
|
|||||||
cmd_tmp = cur_cmd;
|
cmd_tmp = cur_cmd;
|
||||||
cur_cmd = cur_cmd->next;
|
cur_cmd = cur_cmd->next;
|
||||||
msh->in_type = cmd_tmp->type;
|
msh->in_type = cmd_tmp->type;
|
||||||
free(cmd_tmp->token);
|
free(cmd_tmp->value);
|
||||||
free(cmd_tmp);
|
free(cmd_tmp);
|
||||||
msh->cmds = cur_cmd;
|
msh->cmds = cur_cmd;
|
||||||
return ;
|
return ;
|
||||||
@ -104,7 +104,7 @@ void remove_command_from_msh(t_msh *msh)
|
|||||||
cmd_tmp = cur_cmd;
|
cmd_tmp = cur_cmd;
|
||||||
cur_cmd = cur_cmd->next;
|
cur_cmd = cur_cmd->next;
|
||||||
msh->in_type = cur_cmd->type;
|
msh->in_type = cur_cmd->type;
|
||||||
free(cmd_tmp->token);
|
free(cmd_tmp->value);
|
||||||
free(cmd_tmp);
|
free(cmd_tmp);
|
||||||
msh->cmds = cur_cmd;
|
msh->cmds = cur_cmd;
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
|
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/02/18 15:46:50 by tomoron #+# #+# */
|
/* Created: 2024/02/18 15:46:50 by tomoron #+# #+# */
|
||||||
/* Updated: 2024/02/21 12:59:08 by marde-vr ### ########.fr */
|
/* Updated: 2024/03/27 14:56:35 by tomoron ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -18,7 +18,7 @@ void print_parsed_cmd(t_cmd *cmd)
|
|||||||
{
|
{
|
||||||
printf("[");
|
printf("[");
|
||||||
if (cmd->type == ARG)
|
if (cmd->type == ARG)
|
||||||
printf("ARG : \"%s\"", cmd->token);
|
printf("ARG : \"%s\"", cmd->value);
|
||||||
else if (cmd->type == PIPE)
|
else if (cmd->type == PIPE)
|
||||||
printf("PIPE");
|
printf("PIPE");
|
||||||
else if (cmd->type == RED_O)
|
else if (cmd->type == RED_O)
|
||||||
|
12
srcs/echo.c
12
srcs/echo.c
@ -6,7 +6,7 @@
|
|||||||
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
|
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/02/07 15:30:37 by tomoron #+# #+# */
|
/* Created: 2024/02/07 15:30:37 by tomoron #+# #+# */
|
||||||
/* Updated: 2024/03/26 14:14:29 by tomoron ### ########.fr */
|
/* Updated: 2024/03/27 14:55:08 by tomoron ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -26,7 +26,7 @@ void put_args(t_cmd *args)
|
|||||||
{
|
{
|
||||||
if (!first)
|
if (!first)
|
||||||
ft_putchar_fd(' ', STDOUT_FILENO);
|
ft_putchar_fd(' ', STDOUT_FILENO);
|
||||||
ft_putstr_fd(args->token, STDOUT_FILENO);
|
ft_putstr_fd(args->value, STDOUT_FILENO);
|
||||||
first = 0;
|
first = 0;
|
||||||
}
|
}
|
||||||
args = args->next;
|
args = args->next;
|
||||||
@ -40,14 +40,14 @@ int echo(t_cmd *args)
|
|||||||
|
|
||||||
put_nl = 1;
|
put_nl = 1;
|
||||||
i = 1;
|
i = 1;
|
||||||
while (args && args->token && args->token[0] == '-')
|
while (args && args->value && args->value[0] == '-')
|
||||||
{
|
{
|
||||||
while (args->token[i] == 'n')
|
while (args->value[i] == 'n')
|
||||||
i++;
|
i++;
|
||||||
if (!args->token[i])
|
if (!args->value[i])
|
||||||
put_nl = 0;
|
put_nl = 0;
|
||||||
else
|
else
|
||||||
ft_printf("%s ",args->token);
|
ft_printf("%s ",args->value);
|
||||||
args = args->next;
|
args = args->next;
|
||||||
}
|
}
|
||||||
put_args(args);
|
put_args(args);
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
|
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/02/07 14:12:49 by tomoron #+# #+# */
|
/* Created: 2024/02/07 14:12:49 by tomoron #+# #+# */
|
||||||
/* Updated: 2024/03/26 17:33:20 by tomoron ### ########.fr */
|
/* Updated: 2024/03/27 14:49:53 by tomoron ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -60,7 +60,7 @@ void exec_command(t_msh *msh, int i, int cmd_count)
|
|||||||
if (!g_return_code)
|
if (!g_return_code)
|
||||||
get_in_type(msh, msh->cmds);
|
get_in_type(msh, msh->cmds);
|
||||||
}
|
}
|
||||||
if (!cmd_is_builtin(msh, msh->cmds->token))
|
if (!cmd_is_builtin(msh, msh->cmds->value))
|
||||||
get_cmd_path(msh);
|
get_cmd_path(msh);
|
||||||
exec(msh, get_cmd_args(msh), i, cmd_count);
|
exec(msh, get_cmd_args(msh), i, cmd_count);
|
||||||
remove_command_from_msh(msh);
|
remove_command_from_msh(msh);
|
||||||
|
10
srcs/exit.c
10
srcs/exit.c
@ -6,7 +6,7 @@
|
|||||||
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
|
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/02/07 16:04:11 by tomoron #+# #+# */
|
/* Created: 2024/02/07 16:04:11 by tomoron #+# #+# */
|
||||||
/* Updated: 2024/03/26 09:14:22 by marde-vr ### ########.fr */
|
/* Updated: 2024/03/27 14:51:02 by tomoron ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -25,10 +25,10 @@ void get_exit_bt_return_code(t_msh *msh, int *exit_code)
|
|||||||
t_cmd *cur_cmd;
|
t_cmd *cur_cmd;
|
||||||
|
|
||||||
cur_cmd = msh->cmds->next;
|
cur_cmd = msh->cmds->next;
|
||||||
if (cur_cmd && cur_cmd->type == ARG && !ft_strisnbr(cur_cmd->token))
|
if (cur_cmd && cur_cmd->type == ARG && !ft_strisnbr(cur_cmd->value))
|
||||||
numeric_arg_err(cur_cmd->token, exit_code);
|
numeric_arg_err(cur_cmd->value, exit_code);
|
||||||
else if (cur_cmd && cur_cmd->type == ARG)
|
else if (cur_cmd && cur_cmd->type == ARG)
|
||||||
*exit_code = (unsigned char)ft_atoi(cur_cmd->token);
|
*exit_code = (unsigned char)ft_atoi(cur_cmd->value);
|
||||||
else
|
else
|
||||||
*exit_code = g_return_code;
|
*exit_code = g_return_code;
|
||||||
}
|
}
|
||||||
@ -42,7 +42,7 @@ void exit_bt(t_msh *msh)
|
|||||||
cur_cmd = msh->cmds->next;
|
cur_cmd = msh->cmds->next;
|
||||||
ft_printf("exit\n");
|
ft_printf("exit\n");
|
||||||
if (cur_cmd && cur_cmd->next && cur_cmd->next->type == ARG
|
if (cur_cmd && cur_cmd->next && cur_cmd->next->type == ARG
|
||||||
&& ft_strisnbr(cur_cmd->token))
|
&& ft_strisnbr(cur_cmd->value))
|
||||||
{
|
{
|
||||||
ft_putstr_fd("minishell: exit: too many arguments\n", 2);
|
ft_putstr_fd("minishell: exit: too many arguments\n", 2);
|
||||||
g_return_code = 1;
|
g_return_code = 1;
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
|
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/02/18 18:29:20 by marde-vr #+# #+# */
|
/* Created: 2024/02/18 18:29:20 by marde-vr #+# #+# */
|
||||||
/* Updated: 2024/03/26 13:57:26 by tomoron ### ########.fr */
|
/* Updated: 2024/03/27 14:57:44 by tomoron ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -54,7 +54,7 @@ int ft_export(t_msh *msh)
|
|||||||
if (cmd && cmd->next && cmd->next->type == ARG && (!cmd->next->next
|
if (cmd && cmd->next && cmd->next->type == ARG && (!cmd->next->next
|
||||||
|| (cmd->next->next && cmd->next->next->type != ARG)))
|
|| (cmd->next->next && cmd->next->next->type != ARG)))
|
||||||
{
|
{
|
||||||
arg = cmd->next->token;
|
arg = cmd->next->value;
|
||||||
len = 0;
|
len = 0;
|
||||||
while (arg[len] && arg[len] != '=')
|
while (arg[len] && arg[len] != '=')
|
||||||
len++;
|
len++;
|
||||||
@ -109,7 +109,7 @@ int ft_unset(t_msh *msh)
|
|||||||
cmd = cmd->next;
|
cmd = cmd->next;
|
||||||
while (cmd && cmd->type == ARG)
|
while (cmd && cmd->type == ARG)
|
||||||
{
|
{
|
||||||
delete_from_env(msh, cmd->token);
|
delete_from_env(msh, cmd->value);
|
||||||
cmd = cmd->next;
|
cmd = cmd->next;
|
||||||
}
|
}
|
||||||
return (0);
|
return (0);
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
|
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/03/05 18:15:27 by marde-vr #+# #+# */
|
/* Created: 2024/03/05 18:15:27 by marde-vr #+# #+# */
|
||||||
/* Updated: 2024/03/25 13:49:06 by marde-vr ### ########.fr */
|
/* Updated: 2024/03/27 14:58:15 by tomoron ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -30,15 +30,15 @@ void redirect_input(t_msh *msh, int i)
|
|||||||
void open_input_file(t_msh *msh, t_cmd **cur_cmd)
|
void open_input_file(t_msh *msh, t_cmd **cur_cmd)
|
||||||
{
|
{
|
||||||
if ((*cur_cmd)->type == HERE_DOC)
|
if ((*cur_cmd)->type == HERE_DOC)
|
||||||
handle_here_doc(msh, (*cur_cmd)->next->token);
|
handle_here_doc(msh, (*cur_cmd)->next->value);
|
||||||
if ((*cur_cmd)->type == RED_I)
|
if ((*cur_cmd)->type == RED_I)
|
||||||
{
|
{
|
||||||
if (msh->in_fd != 0)
|
if (msh->in_fd != 0)
|
||||||
close(msh->in_fd);
|
close(msh->in_fd);
|
||||||
msh->in_fd = open((*cur_cmd)->next->token, O_RDONLY);
|
msh->in_fd = open((*cur_cmd)->next->value, O_RDONLY);
|
||||||
if (msh->in_fd == -1 && !g_return_code)
|
if (msh->in_fd == -1 && !g_return_code)
|
||||||
{
|
{
|
||||||
ft_printf_fd(2, "minishell: %s: ", (*cur_cmd)->next->token);
|
ft_printf_fd(2, "minishell: %s: ", (*cur_cmd)->next->value);
|
||||||
perror("");
|
perror("");
|
||||||
g_return_code = 1;
|
g_return_code = 1;
|
||||||
}
|
}
|
||||||
|
@ -6,13 +6,13 @@
|
|||||||
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
|
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/02/06 20:46:19 by tomoron #+# #+# */
|
/* Created: 2024/02/06 20:46:19 by tomoron #+# #+# */
|
||||||
/* Updated: 2024/03/25 12:45:39 by marde-vr ### ########.fr */
|
/* Updated: 2024/03/27 14:48:50 by tomoron ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "minishell.h"
|
#include "minishell.h"
|
||||||
|
|
||||||
t_cmd *cmd_add_back(t_cmd *cmd, char *token, t_token_type type)
|
t_cmd *cmd_add_back(t_cmd *cmd, char *value, t_token_type type)
|
||||||
{
|
{
|
||||||
t_cmd *res;
|
t_cmd *res;
|
||||||
t_cmd *current;
|
t_cmd *current;
|
||||||
@ -20,7 +20,7 @@ t_cmd *cmd_add_back(t_cmd *cmd, char *token, t_token_type type)
|
|||||||
res = ft_calloc(1, sizeof(t_cmd));
|
res = ft_calloc(1, sizeof(t_cmd));
|
||||||
if (!res)
|
if (!res)
|
||||||
return (cmd);
|
return (cmd);
|
||||||
res->token = token;
|
res->value = value;
|
||||||
res->type = type;
|
res->type = type;
|
||||||
if (!cmd)
|
if (!cmd)
|
||||||
return (res);
|
return (res);
|
||||||
@ -35,10 +35,10 @@ void free_cmd(t_cmd *cmd)
|
|||||||
{
|
{
|
||||||
if (cmd)
|
if (cmd)
|
||||||
{
|
{
|
||||||
if (cmd && cmd->token)
|
if (cmd && cmd->value)
|
||||||
{
|
{
|
||||||
free(cmd->token);
|
free(cmd->value);
|
||||||
cmd->token = 0;
|
cmd->value = 0;
|
||||||
}
|
}
|
||||||
if (cmd && cmd->next)
|
if (cmd && cmd->next)
|
||||||
{
|
{
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
|
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/02/04 17:31:38 by tomoron #+# #+# */
|
/* Created: 2024/02/04 17:31:38 by tomoron #+# #+# */
|
||||||
/* Updated: 2024/03/26 17:13:30 by tomoron ### ########.fr */
|
/* Updated: 2024/03/27 14:46:04 by tomoron ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -38,7 +38,7 @@ typedef enum e_token_type
|
|||||||
typedef struct s_cmd
|
typedef struct s_cmd
|
||||||
{
|
{
|
||||||
t_token_type type;
|
t_token_type type;
|
||||||
char *token;
|
char *value;
|
||||||
struct s_cmd *next;
|
struct s_cmd *next;
|
||||||
} t_cmd;
|
} t_cmd;
|
||||||
|
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
|
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/03/05 19:10:52 by marde-vr #+# #+# */
|
/* Created: 2024/03/05 19:10:52 by marde-vr #+# #+# */
|
||||||
/* Updated: 2024/03/05 19:28:25 by marde-vr ### ########.fr */
|
/* Updated: 2024/03/27 14:58:29 by tomoron ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -30,10 +30,10 @@ void open_out_file(t_msh *msh, t_cmd **cur_cmd)
|
|||||||
{
|
{
|
||||||
msh->out_type = (*cur_cmd)->type;
|
msh->out_type = (*cur_cmd)->type;
|
||||||
if (msh->out_type == RED_O)
|
if (msh->out_type == RED_O)
|
||||||
msh->out_fd = open((*cur_cmd)->next->token,
|
msh->out_fd = open((*cur_cmd)->next->value,
|
||||||
O_CREAT | O_WRONLY | O_TRUNC, 0644);
|
O_CREAT | O_WRONLY | O_TRUNC, 0644);
|
||||||
if (msh->out_type == RED_O_APP)
|
if (msh->out_type == RED_O_APP)
|
||||||
msh->out_fd = open((*cur_cmd)->next->token,
|
msh->out_fd = open((*cur_cmd)->next->value,
|
||||||
O_CREAT | O_RDWR | O_APPEND, 0644);
|
O_CREAT | O_RDWR | O_APPEND, 0644);
|
||||||
if (msh->out_fd == -1)
|
if (msh->out_fd == -1)
|
||||||
{
|
{
|
||||||
|
15
srcs/parsing_bonus.c
Normal file
15
srcs/parsing_bonus.c
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* parsing_bonus.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: tomoron <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2024/03/27 14:40:44 by tomoron #+# #+# */
|
||||||
|
/* Updated: 2024/03/27 15:01:00 by tomoron ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "minishell.h"
|
||||||
|
|
||||||
|
|
16
srcs/path.c
16
srcs/path.c
@ -6,7 +6,7 @@
|
|||||||
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
|
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/02/21 21:47:15 by marde-vr #+# #+# */
|
/* Created: 2024/02/21 21:47:15 by marde-vr #+# #+# */
|
||||||
/* Updated: 2024/03/26 08:49:24 by marde-vr ### ########.fr */
|
/* Updated: 2024/03/27 14:57:21 by tomoron ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -26,15 +26,15 @@ void find_cmd_path(t_msh *msh, char **paths, int *found)
|
|||||||
tmp = ft_strjoin(path, "/");
|
tmp = ft_strjoin(path, "/");
|
||||||
if (!tmp)
|
if (!tmp)
|
||||||
ft_exit(msh, 1);
|
ft_exit(msh, 1);
|
||||||
path = ft_strjoin(tmp, msh->cmds->token);
|
path = ft_strjoin(tmp, msh->cmds->value);
|
||||||
if (!path)
|
if (!path)
|
||||||
ft_exit(msh, 1);
|
ft_exit(msh, 1);
|
||||||
free(tmp);
|
free(tmp);
|
||||||
if (access(path, X_OK) != -1)
|
if (access(path, X_OK) != -1)
|
||||||
{
|
{
|
||||||
*found = 1;
|
*found = 1;
|
||||||
free(msh->cmds->token);
|
free(msh->cmds->value);
|
||||||
msh->cmds->token = path;
|
msh->cmds->value = path;
|
||||||
break ;
|
break ;
|
||||||
}
|
}
|
||||||
free(path);
|
free(path);
|
||||||
@ -84,7 +84,7 @@ void get_cmd_path(t_msh *msh)
|
|||||||
int found;
|
int found;
|
||||||
|
|
||||||
found = 0;
|
found = 0;
|
||||||
if (ft_strchr(msh->cmds->token, '/'))
|
if (ft_strchr(msh->cmds->value, '/'))
|
||||||
{
|
{
|
||||||
if (!file_access(msh, &found))
|
if (!file_access(msh, &found))
|
||||||
return ;
|
return ;
|
||||||
@ -93,9 +93,9 @@ void get_cmd_path(t_msh *msh)
|
|||||||
get_path(msh, &found);
|
get_path(msh, &found);
|
||||||
if (!found)
|
if (!found)
|
||||||
{
|
{
|
||||||
ft_printf_fd(2, "%s: command not found\n", msh->cmds->token);
|
ft_printf_fd(2, "%s: command not found\n", msh->cmds->value);
|
||||||
free(msh->cmds->token);
|
free(msh->cmds->value);
|
||||||
msh->cmds->token = 0;
|
msh->cmds->value = 0;
|
||||||
g_return_code = 127;
|
g_return_code = 127;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
10
srcs/pipe.c
10
srcs/pipe.c
@ -6,7 +6,7 @@
|
|||||||
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
|
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/03/05 18:17:25 by marde-vr #+# #+# */
|
/* Created: 2024/03/05 18:17:25 by marde-vr #+# #+# */
|
||||||
/* Updated: 2024/03/26 17:21:57 by tomoron ### ########.fr */
|
/* Updated: 2024/03/27 15:00:06 by tomoron ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -31,8 +31,8 @@ void execute_command(t_msh *msh, char **cmd_args, int i)
|
|||||||
{
|
{
|
||||||
char **env;
|
char **env;
|
||||||
|
|
||||||
if (msh->cmds->token && (!ft_strcmp(msh->cmds->token, "cd")
|
if (msh->cmds->value && (!ft_strcmp(msh->cmds->value, "cd")
|
||||||
|| !ft_strcmp(msh->cmds->token, "exit") || exec_builtin(msh)))
|
|| !ft_strcmp(msh->cmds->value, "exit") || exec_builtin(msh)))
|
||||||
{
|
{
|
||||||
while (i >= 0)
|
while (i >= 0)
|
||||||
{
|
{
|
||||||
@ -43,11 +43,11 @@ void execute_command(t_msh *msh, char **cmd_args, int i)
|
|||||||
free(cmd_args);
|
free(cmd_args);
|
||||||
ft_exit(msh, g_return_code);
|
ft_exit(msh, g_return_code);
|
||||||
}
|
}
|
||||||
if (msh->cmds->token)
|
if (msh->cmds->value)
|
||||||
{
|
{
|
||||||
set_echoctl(msh->echoctl);
|
set_echoctl(msh->echoctl);
|
||||||
env = env_to_char_tab(msh->env);
|
env = env_to_char_tab(msh->env);
|
||||||
execve(msh->cmds->token, cmd_args, env);
|
execve(msh->cmds->value, cmd_args, env);
|
||||||
ft_free_str_arr(env);
|
ft_free_str_arr(env);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
12
srcs/utils.c
12
srcs/utils.c
@ -6,7 +6,7 @@
|
|||||||
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
|
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/03/05 18:19:26 by marde-vr #+# #+# */
|
/* Created: 2024/03/05 18:19:26 by marde-vr #+# #+# */
|
||||||
/* Updated: 2024/03/26 17:23:51 by tomoron ### ########.fr */
|
/* Updated: 2024/03/27 15:00:24 by tomoron ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -35,22 +35,22 @@ int file_access(t_msh *msh, int *found)
|
|||||||
{
|
{
|
||||||
int fd;
|
int fd;
|
||||||
|
|
||||||
fd = open(msh->cmds->token, O_DIRECTORY);
|
fd = open(msh->cmds->value, O_DIRECTORY);
|
||||||
if (fd != -1)
|
if (fd != -1)
|
||||||
{
|
{
|
||||||
close(fd);
|
close(fd);
|
||||||
ft_printf_fd(2, "minishell: %s: Is a directory\n", msh->cmds->token);
|
ft_printf_fd(2, "minishell: %s: Is a directory\n", msh->cmds->value);
|
||||||
g_return_code = 126;
|
g_return_code = 126;
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
if (access(msh->cmds->token, X_OK) != -1)
|
if (access(msh->cmds->value, X_OK) != -1)
|
||||||
*found = 1;
|
*found = 1;
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
ft_printf_fd(2, "minishell: %s: ", msh->cmds->token);
|
ft_printf_fd(2, "minishell: %s: ", msh->cmds->value);
|
||||||
perror("");
|
perror("");
|
||||||
g_return_code = 127;
|
g_return_code = 127;
|
||||||
if (access(msh->cmds->token, F_OK) != -1)
|
if (access(msh->cmds->value, F_OK) != -1)
|
||||||
g_return_code = 126;
|
g_return_code = 126;
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user