fix: builtins and pipes *
also: dev: add dev/nocluster.sh
This commit is contained in:
parent
147743058d
commit
c637b5f382
4 changed files with 24 additions and 21 deletions
6
Makefile
6
Makefile
|
@ -17,7 +17,7 @@ LIBRARIES_LINK =
|
|||
# to use with the flag -l
|
||||
LINK =
|
||||
# flags to add to the compiler
|
||||
MORE_FLAGS += $(addprefix -L,$(LIBRARIES_LINK)) $(addprefix -l,$(LIBRARIES_LINK) $(LINK)) $(addprefix -I,$(INCLUDES))
|
||||
MORE_FLAGSS = $(MORE_FLAGS) $(addprefix -L,$(LIBRARIES_LINK)) $(addprefix -l,$(LIBRARIES_LINK) $(LINK)) $(addprefix -I,$(INCLUDES))
|
||||
##### END OF THE INTERESTING PART #####
|
||||
|
||||
|
||||
|
@ -55,7 +55,7 @@ debug :
|
|||
|
||||
$(NAME) : $(O_FILES) $(LIBRARIES)
|
||||
@echo "\e[30;47;1m $(NAME): linking... \e[0m"
|
||||
$(CC) -lreadline -o $(NAME) $(O_FILES) $(LIBRARIES_FILES) $(MORE_FLAGS)
|
||||
$(CC) -lreadline -o $(NAME) $(O_FILES) $(LIBRARIES_FILES) $(MORE_FLAGSS)
|
||||
@echo "\e[30;47;1m $(NAME): linked! \e[0m"
|
||||
|
||||
$(LIBRARIES) :
|
||||
|
@ -68,6 +68,6 @@ endif
|
|||
@echo "\e[30;47;1m $(NAME): library $@ made! \e[0m"
|
||||
|
||||
%.o : %.c
|
||||
$(CC) -c $< -o $@ $(MORE_FLAGS)
|
||||
$(CC) -c $< -o $@ $(MORE_FLAGSS)
|
||||
|
||||
.PHONY : all debug clean fclean re $(LIBRARIES)
|
||||
|
|
3
dev/nocluster.sh
Executable file
3
dev/nocluster.sh
Executable file
|
@ -0,0 +1,3 @@
|
|||
# call this file with "source dev/nocluster.sh"
|
||||
|
||||
alias makee="make MORE_FLAGS=\"-lreadline\""
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jschaft <cecile.schaft@orange.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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)
|
||||
{
|
||||
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)
|
||||
return (exit_builtin(env, call));
|
||||
exit (exit_builtin(env, call));
|
||||
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)
|
||||
return (unset_builtin(env, call));
|
||||
exit (unset_builtin(env, call));
|
||||
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)
|
||||
return (echo_builtin(env, call));
|
||||
exit (echo_builtin(env, call));
|
||||
if (ft_strncmp(call.program, "env", 4) == 0)
|
||||
return (env_builtin(env, call));
|
||||
return (1);
|
||||
exit (env_builtin(env, call));
|
||||
exit (1);
|
||||
}
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jschaft <cecile.schaft@orange.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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,
|
||||
// write the error and return the error status.
|
||||
static int execute_call(
|
||||
t_exec_command_global *global, t_call call, const int inout[2],
|
||||
char *const envp[])
|
||||
t_exec_command_global *global, t_call call,
|
||||
const int inout[2], char *const envp[])
|
||||
{
|
||||
pid_t pid;
|
||||
const char *program_path;
|
||||
|
@ -60,7 +60,10 @@ static int execute_call(
|
|||
if (dup2(inout[0], 0) < 0 || dup2(inout[1], 1) < 0)
|
||||
return (minishell_error("errno"), errno);
|
||||
close_all_pipes(global);
|
||||
execve(program_path, call.argv, envp);
|
||||
if (is_builtin(call.program))
|
||||
exec_builtin(global->env, call);
|
||||
else
|
||||
execve(program_path, call.argv, envp);
|
||||
return (minishell_error("errno"), errno);
|
||||
}
|
||||
return (0);
|
||||
|
@ -97,11 +100,8 @@ static int exec_each_call(t_exec_command_global *global,
|
|||
mc = mem_subclass(fatal_error, global->mc);
|
||||
inout[0] = global->pipes[i].pipe[0];
|
||||
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,
|
||||
variables_envp(env->variables, mc));
|
||||
r = execute_call(global, command.calls[i], inout,
|
||||
variables_envp(env->variables, mc));
|
||||
mem_freeall(mc);
|
||||
if (r)
|
||||
return (r);
|
||||
|
|
Loading…
Add table
Reference in a new issue