This commit is contained in:
2024-04-24 14:07:41 +02:00
5 changed files with 35 additions and 35 deletions

View File

@ -6,7 +6,7 @@
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/02/18 18:29:20 by marde-vr #+# #+# */
/* Updated: 2024/04/24 13:06:58 by tomoron ### ########.fr */
/* Updated: 2024/04/24 13:45:58 by marde-vr ### ########.fr */
/* */
/* ************************************************************************** */
@ -21,18 +21,11 @@ int export_invalid_identifier(char *arg, char *name)
return (1);
}
t_env *export_set_env(t_env *env, char *name, char *value, int append)
t_env *set_env(t_env *env, char *name, char *value, int append)
{
t_env *tmp;
tmp = env;
if (!value || !name)
{
free(name);
free(value);
ft_printf_fd(2, "minishell: malloc failed");
return (env);
}
while (tmp)
{
if (!ft_strcmp(name, tmp->name))
@ -53,6 +46,19 @@ t_env *export_set_env(t_env *env, char *name, char *value, int append)
}
tmp = tmp->next;
}
return (env);
}
t_env *export_set_env(t_env *env, char *name, char *value, int append)
{
if (!value || !name)
{
free(name);
free(value);
ft_printf_fd(2, "minishell: malloc failed");
return (env);
}
set_env(env, name, value, append);
return (env_add_back(env, name, value));
}

View File

@ -6,7 +6,7 @@
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/02/02 21:59:20 by tomoron #+# #+# */
/* Updated: 2024/04/24 13:55:40 by tomoron ### ########.fr */
/* Updated: 2024/04/24 14:07:32 by tomoron ### ########.fr */
/* */
/* ************************************************************************** */
@ -77,13 +77,13 @@ t_env *add_shlvl(t_env *env)
char *tmp;
tmp = ft_get_env(env, "SHLVL");
if(!tmp)
if (!tmp)
nb = 0;
else
nb = ft_atoi(tmp);
nb++;
env = export_set_env(env, ft_strdup("SHLVL"), ft_itoa(nb), 0);
return(env);
return (env);
}
int init_minishell(t_msh **msh, int argc, char **argv, char **envp)

View File

@ -6,7 +6,7 @@
/* By: tomoron <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/04/19 14:09:44 by tomoron #+# #+# */
/* Updated: 2024/04/24 11:04:42 by marde-vr ### ########.fr */
/* Updated: 2024/04/24 13:25:20 by marde-vr ### ########.fr */
/* */
/* ************************************************************************** */
@ -55,6 +55,16 @@ int open_out_file(t_msh *msh, t_cmd **cur_cmd, char *filename)
return (0);
}
void go_to_next_out_type(t_cmd **cur_cmd)
{
while (*cur_cmd && (*cur_cmd)->next && (!is_cmd_type(*cur_cmd)
&& !is_output_type(*cur_cmd)))
*cur_cmd = (*cur_cmd)->next;
while (*cur_cmd && (*cur_cmd)->next && !is_output_type(*cur_cmd)
&& !is_operand_type(*cur_cmd) && (*cur_cmd)->cmd_type != PIPE)
*cur_cmd = (*cur_cmd)->next;
}
int get_out_type(t_msh *msh, t_cmd *cmds)
{
t_cmd *cur_cmd;
@ -65,12 +75,7 @@ int get_out_type(t_msh *msh, t_cmd *cmds)
msh->out_fd = 0;
ret = 0;
cur_cmd = cmds;
while (cur_cmd && cur_cmd->next && (!is_cmd_type(cur_cmd)
&& !is_output_type(cur_cmd)))
cur_cmd = cur_cmd->next;
while (cur_cmd && cur_cmd->next && !is_output_type(cur_cmd)
&& !is_operand_type(cur_cmd) && cur_cmd->cmd_type != PIPE)
cur_cmd = cur_cmd->next;
go_to_next_out_type(&cur_cmd);
if (cur_cmd && (cur_cmd->cmd_type == CMD || cur_cmd->cmd_type == PAREN))
msh->out_type = 0;
else if (cur_cmd && is_output_type(cur_cmd) && !is_operand_type(cur_cmd)