[ADD] helo
This commit is contained in:
parent
0bcb738496
commit
5b313a1f5c
3 changed files with 28 additions and 22 deletions
|
@ -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/28 15:30:51 by mcolonna ### ########.fr */
|
/* Updated: 2024/07/01 12:35:09 by jschaft ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
@ -82,18 +82,18 @@ static int env_builtin(t_env *env, t_call call)
|
||||||
int exec_builtin(t_env *env, t_call call)
|
int exec_builtin(t_env *env, t_call call)
|
||||||
{
|
{
|
||||||
if (ft_strncmp(call.program, "cd", 3) == 0)
|
if (ft_strncmp(call.program, "cd", 3) == 0)
|
||||||
return (cd_builtin(env, call));
|
exit (cd_builtin(env, call));
|
||||||
if (ft_strncmp(call.program, "exit", 5) == 0)
|
if (ft_strncmp(call.program, "exit", 5) == 0)
|
||||||
return (exit_builtin(env, call));
|
exit (exit_builtin(env, call));
|
||||||
if (ft_strncmp(call.program, "export", 7) == 0)
|
if (ft_strncmp(call.program, "export", 7) == 0)
|
||||||
return (export_builtin(env, call));
|
exit (export_builtin(env, call));
|
||||||
if (ft_strncmp(call.program, "unset", 6) == 0)
|
if (ft_strncmp(call.program, "unset", 6) == 0)
|
||||||
return (unset_builtin(env, call));
|
exit (unset_builtin(env, call));
|
||||||
if (ft_strncmp(call.program, "pwd", 4) == 0)
|
if (ft_strncmp(call.program, "pwd", 4) == 0)
|
||||||
return (pwd_builtin(env, call));
|
exit (pwd_builtin(env, call));
|
||||||
if (ft_strncmp(call.program, "echo", 5) == 0)
|
if (ft_strncmp(call.program, "echo", 5) == 0)
|
||||||
return (echo_builtin(env, call));
|
exit (echo_builtin(env, call));
|
||||||
if (ft_strncmp(call.program, "env", 4) == 0)
|
if (ft_strncmp(call.program, "env", 4) == 0)
|
||||||
return (env_builtin(env, call));
|
exit (env_builtin(env, call));
|
||||||
return (1);
|
exit (1);
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jschaft <cecile.schaft@orange.fr> +#+ +:+ +#+ */
|
/* By: jschaft <cecile.schaft@orange.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/06/25 13:28:29 by jschaft #+# #+# */
|
/* Created: 2024/06/25 13:28:29 by jschaft #+# #+# */
|
||||||
/* Updated: 2024/06/28 15:30:55 by mcolonna ### ########.fr */
|
/* Updated: 2024/07/01 12:35:28 by jschaft ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
@ -88,9 +88,13 @@ int echo_builtin(t_env *env, t_call call)
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int go_home(t_env *env)
|
static int go_home(t_env *env, const char dest)
|
||||||
{
|
{
|
||||||
return (chdir(variables_get(env->variables, "HOME")));
|
if (dest == 'n')
|
||||||
|
return (chdir(variables_get(env->variables, "HOME")), dest);
|
||||||
|
if (dest == '-')
|
||||||
|
return (chdir(variables_get(env->variables, "OLDPWD")));
|
||||||
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Execute the builtin cd for the specified path.
|
// Execute the builtin cd for the specified path.
|
||||||
|
@ -106,7 +110,9 @@ int cd_builtin(t_env *env, t_call call)
|
||||||
if (argc == 2)
|
if (argc == 2)
|
||||||
r = chdir(call.argv[1]);
|
r = chdir(call.argv[1]);
|
||||||
else if (argc == 1)
|
else if (argc == 1)
|
||||||
r = go_home(env);
|
r = go_home(env, 'n');
|
||||||
|
else if (argc == 2 && ft_strncmp(call.argv[1], "-", 2))
|
||||||
|
r = go_home(env, '-');
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
print_line(fatal_error, 2, "cd: too many arguments");
|
print_line(fatal_error, 2, "cd: too many arguments");
|
||||||
|
|
|
@ -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/28 16:08:02 by mcolonna ### ########.fr */
|
/* Updated: 2024/07/01 12:36:03 by jschaft ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
@ -40,8 +40,8 @@ static void close_all_pipes(t_exec_command_global *global)
|
||||||
// If the program wasn't to found in $PATH, or the fork didn't work,
|
// If the program wasn't to found in $PATH, or the fork didn't work,
|
||||||
// write the error and return the error status.
|
// write the error and return the error status.
|
||||||
static int execute_call(
|
static int execute_call(
|
||||||
t_exec_command_global *global, t_call call, const int inout[2],
|
t_exec_command_global *global, t_call call,
|
||||||
char *const envp[])
|
const int inout[2], char *const envp[])
|
||||||
{
|
{
|
||||||
pid_t pid;
|
pid_t pid;
|
||||||
const char *program_path;
|
const char *program_path;
|
||||||
|
@ -60,6 +60,9 @@ static int execute_call(
|
||||||
if (dup2(inout[0], 0) < 0 || dup2(inout[1], 1) < 0)
|
if (dup2(inout[0], 0) < 0 || dup2(inout[1], 1) < 0)
|
||||||
return (minishell_error("errno"), errno);
|
return (minishell_error("errno"), errno);
|
||||||
close_all_pipes(global);
|
close_all_pipes(global);
|
||||||
|
if (is_builtin(call.program))
|
||||||
|
exec_builtin(global->env, call);
|
||||||
|
else
|
||||||
execve(program_path, call.argv, envp);
|
execve(program_path, call.argv, envp);
|
||||||
return (minishell_error("errno"), errno);
|
return (minishell_error("errno"), errno);
|
||||||
}
|
}
|
||||||
|
@ -97,9 +100,6 @@ static int exec_each_call(t_exec_command_global *global,
|
||||||
mc = mem_subclass(fatal_error, global->mc);
|
mc = mem_subclass(fatal_error, global->mc);
|
||||||
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))
|
|
||||||
r = exec_builtin(env, command.calls[i]);
|
|
||||||
else
|
|
||||||
r = execute_call(global, command.calls[i], inout,
|
r = execute_call(global, command.calls[i], inout,
|
||||||
variables_envp(env->variables, mc));
|
variables_envp(env->variables, mc));
|
||||||
mem_freeall(mc);
|
mem_freeall(mc);
|
||||||
|
|
Loading…
Add table
Reference in a new issue