Browse Source

fixed exit and export w/no args

master
Michael Ea 3 years ago
parent
commit
23cab6dd5b
  1. 6
      built-in.c
  2. 4
      caller.c
  3. 8
      env.c
  4. 4
      minishell.h

6
built-in.c

@ -3,10 +3,10 @@
/* ::: :::::::: */ /* ::: :::::::: */
/* built-in.c :+: :+: :+: */ /* built-in.c :+: :+: :+: */
/* +:+ +:+ +:+ */ /* +:+ +:+ +:+ */
/* By: narnaud <narnaud@student.42.fr> +#+ +:+ +#+ */ /* By: mea <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2022/01/06 09:02:57 by narnaud #+# #+# */ /* Created: 2022/01/06 09:02:57 by narnaud #+# #+# */
/* Updated: 2022/05/16 09:17:34 by narnaud ### ########.fr */ /* Updated: 2022/05/16 10:44:36 by mea ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -94,7 +94,7 @@ int ft_cd(t_command *cmd)
int ft_exit(t_datas *datas, t_command *cmd) int ft_exit(t_datas *datas, t_command *cmd)
{ {
if (cmd->argc > 1) if (cmd->argc < 2)
halt(datas, EXIT_SUCCESS, 0); halt(datas, EXIT_SUCCESS, 0);
else else
halt(datas, ft_atoi(cmd->argv[1]), 0); halt(datas, ft_atoi(cmd->argv[1]), 0);

4
caller.c

@ -6,7 +6,7 @@
/* By: mea <marvin@42.fr> +#+ +:+ +#+ */ /* By: mea <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2022/05/03 11:48:16 by narnaud #+# #+# */ /* Created: 2022/05/03 11:48:16 by narnaud #+# #+# */
/* Updated: 2022/05/16 08:12:12 by narnaud ### ########.fr */ /* Updated: 2022/05/16 10:42:40 by mea ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -28,7 +28,7 @@ int call_builtin(t_datas *datas, t_command *cmd)
else if (ft_strncmp(cmd->argv[0], "unset", 6) == 0) else if (ft_strncmp(cmd->argv[0], "unset", 6) == 0)
return (ft_unset(datas, cmd)); return (ft_unset(datas, cmd));
else if (ft_strncmp(cmd->argv[0], "env", 4) == 0) else if (ft_strncmp(cmd->argv[0], "env", 4) == 0)
return (ft_env(datas, cmd)); return (ft_env(datas, cmd, 0));
else if (ft_strncmp(cmd->argv[0], "exit", 5) == 0) else if (ft_strncmp(cmd->argv[0], "exit", 5) == 0)
return (ft_exit(datas, cmd)); return (ft_exit(datas, cmd));
else else

8
env.c

@ -6,7 +6,7 @@
/* By: mea <marvin@42.fr> +#+ +:+ +#+ */ /* By: mea <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2022/02/16 09:41:29 by narnaud #+# #+# */ /* Created: 2022/02/16 09:41:29 by narnaud #+# #+# */
/* Updated: 2022/05/12 14:32:41 by mea ### ########.fr */ /* Updated: 2022/05/16 10:43:01 by mea ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -42,7 +42,7 @@ int ft_unset(t_datas *datas, t_command *cmd)
return (0); return (0);
} }
int ft_env(t_datas *datas, t_command *cmd) int ft_env(t_datas *datas, t_command *cmd, int declared_pop)
{ {
int i; int i;
int fd_out; int fd_out;
@ -54,6 +54,8 @@ int ft_env(t_datas *datas, t_command *cmd)
i = 0; i = 0;
while (datas->envp[i]) while (datas->envp[i])
{ {
if (declared_pop)
ft_putstr_fd("declare -x ", fd_out);
ft_putstr_fd(datas->envp[i], fd_out); ft_putstr_fd(datas->envp[i], fd_out);
ft_putchar_fd('\n', fd_out); ft_putchar_fd('\n', fd_out);
i++; i++;
@ -69,7 +71,7 @@ int ft_export(t_datas *datas, t_command *cmd)
int i; int i;
i = 0; i = 0;
if (cmd->argc < 2) if (cmd->argc < 2 && (ft_env(datas, cmd, 1), 1))
return (0); return (0);
new = ft_split(cmd->argv[1], '='); new = ft_split(cmd->argv[1], '=');
name_len = ft_strlen(new[0]); name_len = ft_strlen(new[0]);

4
minishell.h

@ -6,7 +6,7 @@
/* By: mea <marvin@42.fr> +#+ +:+ +#+ */ /* By: mea <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2022/05/02 13:50:44 by narnaud #+# #+# */ /* Created: 2022/05/02 13:50:44 by narnaud #+# #+# */
/* Updated: 2022/05/16 10:23:25 by mea ### ########.fr */ /* Updated: 2022/05/16 10:42:18 by mea ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -76,7 +76,7 @@ int ft_exit(t_datas *datas, t_command *cmd);
// ----------------------------------Env.c // ----------------------------------Env.c
int ft_unset(t_datas *datas, t_command *cmd); int ft_unset(t_datas *datas, t_command *cmd);
int ft_env(t_datas *datas, t_command *cmd); int ft_env(t_datas *datas, t_command *cmd, int declared_pop);
int ft_export(t_datas *datas, t_command *cmd); int ft_export(t_datas *datas, t_command *cmd);
// ----------------------------------Caller.c // ----------------------------------Caller.c

Loading…
Cancel
Save