builtin export redirection
This commit is contained in:
@ -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/04/23 10:56:19 by marde-vr ### ########.fr */
|
/* Updated: 2024/04/23 12:50:19 by tomoron ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -33,11 +33,8 @@ int cmd_is_builtin(t_msh *msh, char *cmd_token)
|
|||||||
g_return_code = cd(msh->tokens);
|
g_return_code = cd(msh->tokens);
|
||||||
else if (!ft_strcmp(cmd_token, "exit"))
|
else if (!ft_strcmp(cmd_token, "exit"))
|
||||||
g_return_code = exit_bt(msh);
|
g_return_code = exit_bt(msh);
|
||||||
else if (!ft_strcmp(cmd_token, "export") && (msh->out_type == PIPE
|
else if (!ft_strcmp(cmd_token, "export") && msh->out_type != PIPE)
|
||||||
|| msh->out_type == RED_O || msh->out_type == RED_O_APP))
|
g_return_code = ft_export(msh, msh->tokens, msh->env);
|
||||||
ft_printf_fd(2, "print the thing into the pipe\n");
|
|
||||||
else if (!ft_strcmp(cmd_token, "export"))
|
|
||||||
g_return_code = ft_export(msh->tokens, msh->env);
|
|
||||||
else if (!ft_strcmp(cmd_token, "unset"))
|
else if (!ft_strcmp(cmd_token, "unset"))
|
||||||
g_return_code = ft_unset(msh);
|
g_return_code = ft_unset(msh);
|
||||||
else
|
else
|
||||||
@ -61,11 +58,9 @@ int exec_builtin(t_msh *msh)
|
|||||||
g_return_code = pwd();
|
g_return_code = pwd();
|
||||||
else if (!ft_strcmp(msh->tokens->value, "cd"))
|
else if (!ft_strcmp(msh->tokens->value, "cd"))
|
||||||
return (1);
|
return (1);
|
||||||
else if (!ft_strcmp(msh->tokens->value, "export") && (msh->out_type == PIPE
|
else if (!ft_strcmp(msh->tokens->value, "export") && msh->out_type == PIPE)
|
||||||
|| msh->out_type == RED_O || msh->out_type == RED_O_APP))
|
g_return_code = ft_export(msh, msh->tokens, msh->env);
|
||||||
ft_printf_fd(2, "catch the printed stuff and put it write it into file\n");
|
|
||||||
else if (!ft_strcmp(msh->tokens->value, "export"))
|
else if (!ft_strcmp(msh->tokens->value, "export"))
|
||||||
//g_return_code = ft_export(msh->tokens, msh->env);
|
|
||||||
return (1);
|
return (1);
|
||||||
else if (!ft_strcmp(msh->tokens->value, "unset"))
|
else if (!ft_strcmp(msh->tokens->value, "unset"))
|
||||||
return (1);
|
return (1);
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
|
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/03/28 13:50:14 by tomoron #+# #+# */
|
/* Created: 2024/03/28 13:50:14 by tomoron #+# #+# */
|
||||||
/* Updated: 2024/04/22 19:55:41 by marde-vr ### ########.fr */
|
/* Updated: 2024/04/23 13:21:32 by tomoron ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -136,6 +136,13 @@ int get_cmd_count(t_cmd *cmds)
|
|||||||
return (nb);
|
return (nb);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int is_parentethis(t_cmd *cmd)
|
||||||
|
{
|
||||||
|
if(!cmd)
|
||||||
|
return(0);
|
||||||
|
return(cmd->cmd_type == PAREN || (cmd->cmd_type == PIPE && cmd->next->cmd_type == PAREN));
|
||||||
|
}
|
||||||
|
|
||||||
void print_signaled(int status)
|
void print_signaled(int status)
|
||||||
{
|
{
|
||||||
int signal;
|
int signal;
|
||||||
|
@ -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/04/22 23:02:44 by tomoron ### ########.fr */
|
/* Updated: 2024/04/23 12:49:46 by tomoron ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -53,20 +53,22 @@ void sort_env(t_env *env)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void print_env_declare(t_env *env_orig)
|
void print_env_declare(t_msh *msh, t_env *env_orig)
|
||||||
{
|
{
|
||||||
t_env *env;
|
t_env *env;
|
||||||
|
|
||||||
env = dup_env(env_orig);
|
env = dup_env(env_orig);
|
||||||
sort_env(env);
|
sort_env(env);
|
||||||
|
if(!msh->out_fd)
|
||||||
|
msh->out_fd = 1;
|
||||||
while (env)
|
while (env)
|
||||||
{
|
{
|
||||||
if (strcmp(env->name, "_"))
|
if (strcmp(env->name, "_"))
|
||||||
{
|
{
|
||||||
if (env->value && *(env->value))
|
if (env->value && *(env->value))
|
||||||
printf("declare -x %s=\"%s\"\n", env->name, env->value);
|
ft_printf_fd(msh->out_fd, "declare -x %s=\"%s\"\n", env->name, env->value);
|
||||||
else
|
else
|
||||||
printf("declare -x %s\n", env->name);
|
ft_printf_fd(msh->out_fd, "declare -x %s\n", env->name);
|
||||||
}
|
}
|
||||||
env = env->next;
|
env = env->next;
|
||||||
}
|
}
|
||||||
@ -115,7 +117,7 @@ t_env *export_set_env(t_env *env, char *name, char *value, int append)
|
|||||||
return (env_add_back(env, name, value));
|
return (env_add_back(env, name, value));
|
||||||
}
|
}
|
||||||
|
|
||||||
int ft_export(t_token *cmd, t_env *env)
|
int ft_export(t_msh *msh, t_token *cmd, t_env *env)
|
||||||
{
|
{
|
||||||
char *arg;
|
char *arg;
|
||||||
char *name;
|
char *name;
|
||||||
@ -124,7 +126,7 @@ int ft_export(t_token *cmd, t_env *env)
|
|||||||
int append;
|
int append;
|
||||||
|
|
||||||
if (cmd && !cmd->next)
|
if (cmd && !cmd->next)
|
||||||
print_env_declare(env);
|
print_env_declare(msh, env);
|
||||||
if (cmd && cmd->next && !cmd->next->next)
|
if (cmd && cmd->next && !cmd->next->next)
|
||||||
{
|
{
|
||||||
arg = cmd->next->value;
|
arg = cmd->next->value;
|
||||||
|
@ -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/04/22 19:30:03 by marde-vr ### ########.fr */
|
/* Updated: 2024/04/23 12:37:16 by tomoron ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -141,7 +141,7 @@ int set_echoctl(int value);
|
|||||||
int is_output_type(t_cmd *cmd);
|
int is_output_type(t_cmd *cmd);
|
||||||
int print_env(t_env *env);
|
int print_env(t_env *env);
|
||||||
t_cmd *free_cmd(t_cmd *cmd);
|
t_cmd *free_cmd(t_cmd *cmd);
|
||||||
int ft_export(t_token *cmd, t_env *env);
|
int ft_export(t_msh *msh, t_token *cmd, t_env *env);
|
||||||
int is_input_type(t_cmd *cmd);
|
int is_input_type(t_cmd *cmd);
|
||||||
void free_env(t_env *env);
|
void free_env(t_env *env);
|
||||||
int ft_unset(t_msh *msh);
|
int ft_unset(t_msh *msh);
|
||||||
|
Reference in New Issue
Block a user