merge
This commit is contained in:
commit
f3a8866c56
5 changed files with 52 additions and 17 deletions
|
@ -6,7 +6,7 @@
|
||||||
/* By: jschaft <cecile.schaft@orange.fr> +#+ +:+ +#+ */
|
/* By: jschaft <cecile.schaft@orange.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/04/23 14:15:12 by mcolonna #+# #+# */
|
/* Created: 2024/04/23 14:15:12 by mcolonna #+# #+# */
|
||||||
/* Updated: 2024/06/13 13:00:54 by mcolonna ### ########.fr */
|
/* Updated: 2024/06/25 13:28:18 by mcolonna ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
@ -19,6 +19,6 @@
|
||||||
bool is_builtin(const char *str);
|
bool is_builtin(const char *str);
|
||||||
|
|
||||||
// Execute the builtin command
|
// Execute the builtin command
|
||||||
int exec_builtin(t_call call);
|
int exec_builtin(t_call call, t_env *env);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jschaft <cecile.schaft@orange.fr> +#+ +:+ +#+ */
|
/* By: jschaft <cecile.schaft@orange.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/04/23 14:15:12 by mcolonna #+# #+# */
|
/* Created: 2024/04/23 14:15:12 by mcolonna #+# #+# */
|
||||||
/* Updated: 2024/06/13 13:50:43 by mcolonna ### ########.fr */
|
/* Updated: 2024/06/25 11:46:04 by jschaft ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
@ -15,6 +15,8 @@
|
||||||
|
|
||||||
# include "include.h"
|
# include "include.h"
|
||||||
|
|
||||||
|
t_memclass *get_global_mc_pointer(void);
|
||||||
|
|
||||||
// Set the global mc freed when exit.
|
// Set the global mc freed when exit.
|
||||||
void set_global_mc(t_memclass mc);
|
void set_global_mc(t_memclass mc);
|
||||||
|
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jschaft <cecile.schaft@orange.fr> +#+ +:+ +#+ */
|
/* By: jschaft <cecile.schaft@orange.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/06/03 12:02:45 by jschaft #+# #+# */
|
/* Created: 2024/06/03 12:02:45 by jschaft #+# #+# */
|
||||||
/* Updated: 2024/06/06 16:34:51 by mcolonna ### ########.fr */
|
/* Updated: 2024/06/25 13:37:36 by mcolonna ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
@ -19,8 +19,12 @@ bool is_builtin(const char *str)
|
||||||
return (
|
return (
|
||||||
ft_strncmp(str, "cd", 3) == 0
|
ft_strncmp(str, "cd", 3) == 0
|
||||||
|| ft_strncmp(str, "exit", 5) == 0
|
|| ft_strncmp(str, "exit", 5) == 0
|
||||||
|| ft_strncmp(str, "export", 7) == 0
|
// || ft_strncmp(str, "export", 7) == 0
|
||||||
|| ft_strncmp(str, "unset", 6) == 0);
|
|| ft_strncmp(str, "env", 4) == 0
|
||||||
|
|| ft_strncmp(str, "pwd", 4) == 0
|
||||||
|
// || ft_strncmp(str, "echo", 5) == 0
|
||||||
|
// || ft_strncmp(str, "unset", 6) == 0
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Execute the builtin cd for the specified path.
|
// Execute the builtin cd for the specified path.
|
||||||
|
@ -38,19 +42,48 @@ static int cd_builtin(const char *path)
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Execute the builtin pwd for the current directory.
|
||||||
|
// Return 0 for the sake of returning something for exec_builtin
|
||||||
|
static int pwd_builtin(void)
|
||||||
|
{
|
||||||
|
char *str;
|
||||||
|
|
||||||
|
str = getcwd(NULL, 0);
|
||||||
|
printf("%s\n", str);
|
||||||
|
free(str);
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
|
static int env_builtin(char *const envp[])
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
|
||||||
|
i = 0;
|
||||||
|
while (envp[i] != NULL)
|
||||||
|
{
|
||||||
|
printf("%s\n", envp[i]);
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
// Execute the specified builtin.
|
// Execute the specified builtin.
|
||||||
// The builtin must exist.
|
// The builtin must exist.
|
||||||
// Return the error value returned by the builtin.
|
// Return the error value returned by the builtin.
|
||||||
// TODO all the builtins
|
// TODO all the builtins
|
||||||
int exec_builtin(t_call call)
|
int exec_builtin(t_call call, t_env *env)
|
||||||
{
|
{
|
||||||
if (ft_strncmp(call.program, "cd", 3) == 0)
|
if (ft_strncmp(call.program, "cd", 3) == 0)
|
||||||
return (cd_builtin(call.argv[1]));
|
return (cd_builtin(call.argv[1]));
|
||||||
/* if (ft_strncmp(call.program, "exit", 5) == 0)
|
if (ft_strncmp(call.program, "exit", 5) == 0)
|
||||||
exit_builtin();
|
env->exit = true;
|
||||||
if (ft_strncmp(call.program, "export", 7) == 0)
|
/* if (ft_strncmp(call.program, "export", 7) == 0)
|
||||||
return (export_builtin(call.argv));
|
return (export_builtin(call.argv));
|
||||||
if (ft_strncmp(call.program, "unset", 6) == 0)
|
if (ft_strncmp(call.program, "unset", 6) == 0)
|
||||||
return (unset_builtin());*/
|
return (unset_builtin());*/
|
||||||
|
if (ft_strncmp(call.program, "pwd", 4) == 0)
|
||||||
|
return (pwd_builtin());
|
||||||
|
if (ft_strncmp(call.program, "env", 4) == 0)
|
||||||
|
return (env_builtin(env->envp));
|
||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,13 +6,13 @@
|
||||||
/* By: jschaft <cecile.schaft@orange.fr> +#+ +:+ +#+ */
|
/* By: jschaft <cecile.schaft@orange.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/04/23 15:51:56 by mcolonna #+# #+# */
|
/* Created: 2024/04/23 15:51:56 by mcolonna #+# #+# */
|
||||||
/* Updated: 2024/06/13 13:51:30 by mcolonna ### ########.fr */
|
/* Updated: 2024/06/25 11:45:46 by jschaft ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "include.h"
|
#include "include.h"
|
||||||
|
|
||||||
static t_memclass *get_global_mc_pointer(void)
|
t_memclass *get_global_mc_pointer(void)
|
||||||
{
|
{
|
||||||
static t_memclass r = NULL;
|
static t_memclass r = NULL;
|
||||||
|
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jschaft <cecile.schaft@orange.fr> +#+ +:+ +#+ */
|
/* By: jschaft <cecile.schaft@orange.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/04/24 13:48:00 by jschaft #+# #+# */
|
/* Created: 2024/04/24 13:48:00 by jschaft #+# #+# */
|
||||||
/* Updated: 2024/06/24 16:16:31 by mcolonna ### ########.fr */
|
/* Updated: 2024/06/25 13:40:07 by mcolonna ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
@ -92,7 +92,7 @@ static int create_pipes(t_exec_command_global *global, t_command command)
|
||||||
}
|
}
|
||||||
|
|
||||||
static int exec_each_call(t_exec_command_global *global,
|
static int exec_each_call(t_exec_command_global *global,
|
||||||
t_command command, char *const envp[])
|
t_command command, t_env *env)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
int r;
|
int r;
|
||||||
|
@ -104,9 +104,9 @@ static int exec_each_call(t_exec_command_global *global,
|
||||||
inout[0] = global->pipes[i].pipe[0];
|
inout[0] = global->pipes[i].pipe[0];
|
||||||
inout[1] = global->pipes[i + 1].pipe[1];
|
inout[1] = global->pipes[i + 1].pipe[1];
|
||||||
if (is_builtin(command.calls[i].program))
|
if (is_builtin(command.calls[i].program))
|
||||||
r = exec_builtin(command.calls[i]);
|
r = exec_builtin(command.calls[i], env);
|
||||||
else
|
else
|
||||||
r = execute_call(global, command.calls[i], inout, envp);
|
r = execute_call(global, command.calls[i], inout, env->envp);
|
||||||
if (r)
|
if (r)
|
||||||
return (r);
|
return (r);
|
||||||
}
|
}
|
||||||
|
@ -130,7 +130,7 @@ int execute_command(t_env *env, t_command command)
|
||||||
r = create_pipes(&global, command);
|
r = create_pipes(&global, command);
|
||||||
if (r)
|
if (r)
|
||||||
return (r);
|
return (r);
|
||||||
r = exec_each_call(&global, command, env->envp);
|
r = exec_each_call(&global, command, env);
|
||||||
close_all_pipes(&global);
|
close_all_pipes(&global);
|
||||||
while (wait(NULL) != -1)
|
while (wait(NULL) != -1)
|
||||||
;
|
;
|
||||||
|
|
Loading…
Add table
Reference in a new issue