Merge branch 'willem' into quinten

This commit is contained in:
Quinten Mennen 2025-02-27 17:46:46 +01:00
commit 3cc3dff55c
6 changed files with 41 additions and 14 deletions

View File

@ -6,7 +6,7 @@
/* By: qmennen <qmennen@student.codam.nl> +#+ */ /* By: qmennen <qmennen@student.codam.nl> +#+ */
/* +#+ */ /* +#+ */
/* Created: 2025/02/05 12:36:08 by whaffman #+# #+# */ /* Created: 2025/02/05 12:36:08 by whaffman #+# #+# */
/* Updated: 2025/02/26 16:19:13 by whaffman ######## odam.nl */ /* Updated: 2025/02/26 17:26:27 by whaffman ######## odam.nl */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -77,6 +77,7 @@ typedef struct s_minishell
t_list *tokens; t_list *tokens;
t_list *commands; t_list *commands;
t_list *freelist; t_list *freelist;
int exit_status;
} t_minishell; } t_minishell;
typedef int (*t_builtin_fn)(t_minishell *, t_command *); typedef int (*t_builtin_fn)(t_minishell *, t_command *);

View File

@ -6,7 +6,7 @@
/* By: willem <willem@student.codam.nl> +#+ */ /* By: willem <willem@student.codam.nl> +#+ */
/* +#+ */ /* +#+ */
/* Created: 2025/02/12 21:25:02 by willem #+# #+# */ /* Created: 2025/02/12 21:25:02 by willem #+# #+# */
/* Updated: 2025/02/26 16:10:39 by whaffman ######## odam.nl */ /* Updated: 2025/02/26 17:42:46 by whaffman ######## odam.nl */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -31,6 +31,7 @@ int executor_execute_pipeline(t_minishell *msh)
current = current->next; current = current->next;
} }
waitpid(last_pid, &exit_status, 0); waitpid(last_pid, &exit_status, 0);
msh->exit_status = ((exit_status) & 0xff00) >> 8;
signal_init_minishell(); signal_init_minishell();
return (((exit_status) & 0xff00) >> 8); return (((exit_status) & 0xff00) >> 8);
} }

View File

@ -6,7 +6,7 @@
/* By: willem <willem@student.codam.nl> +#+ */ /* By: willem <willem@student.codam.nl> +#+ */
/* +#+ */ /* +#+ */
/* Created: 2025/02/12 21:24:52 by willem #+# #+# */ /* Created: 2025/02/12 21:24:52 by willem #+# #+# */
/* Updated: 2025/02/26 16:10:40 by whaffman ######## odam.nl */ /* Updated: 2025/02/26 17:44:36 by whaffman ######## odam.nl */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -33,6 +33,6 @@ pid_t executor_fork(t_minishell *msh, t_command *command)
exit(127); exit(127);
} }
else else
perror("fork"); error_msg("minishell", "fork failed");
return (pid); return (pid);
} }

View File

@ -1,12 +1,12 @@
/* ************************************************************************** */ /* ************************************************************************** */
/* */ /* */
/* ::: :::::::: */ /* :::::::: */
/* expander_parse_string.c :+: :+: :+: */ /* expander_parse_string.c :+: :+: */
/* +:+ +:+ +:+ */ /* +:+ */
/* By: qmennen <qmennen@student.codam.nl> +#+ +:+ +#+ */ /* By: qmennen <qmennen@student.codam.nl> +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+ */
/* Created: 2025/02/18 19:00:35 by qmennen #+# #+# */ /* Created: 2025/02/18 19:00:35 by qmennen #+# #+# */
/* Updated: 2025/02/26 18:33:41 by qmennen ### ########.fr */ /* Updated: 2025/02/26 22:56:05 by whaffman ######## odam.nl */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View File

@ -6,12 +6,31 @@
/* By: qmennen <qmennen@student.codam.nl> +#+ */ /* By: qmennen <qmennen@student.codam.nl> +#+ */
/* +#+ */ /* +#+ */
/* Created: 2025/02/19 13:58:13 by qmennen #+# #+# */ /* Created: 2025/02/19 13:58:13 by qmennen #+# #+# */
/* Updated: 2025/02/26 16:13:42 by whaffman ######## odam.nl */ /* Updated: 2025/02/26 17:41:14 by whaffman ######## odam.nl */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
#include "minishell.h" #include "minishell.h"
static char *ft_itoa_safe(t_minishell *msh, int n)
{
char *str;
str = ft_itoa(n);
check_malloc(msh, str);
return (str);
}
static t_list *create_exit_status_env(t_minishell *msh)
{
t_environment *env;
env = malloc_safe(msh, sizeof(t_environment));
env->name = ft_strdup_safe(msh, "?");
env->value = ft_itoa_safe(msh, msh->exit_status);
return (ft_lstnew_safe(msh, env));
}
t_list *expander_parse_variables(const char *s, t_minishell *msh) t_list *expander_parse_variables(const char *s, t_minishell *msh)
{ {
int i; int i;
@ -28,7 +47,12 @@ t_list *expander_parse_variables(const char *s, t_minishell *msh)
if (env) if (env)
ft_lstadd_back(&var_list, ft_lstnew_safe(msh, env)); ft_lstadd_back(&var_list, ft_lstnew_safe(msh, env));
else else
ft_lstadd_back(&var_list, ft_lstnew_safe(msh, NULL)); {
if (s[i + 1] == '?')
ft_lstadd_back(&var_list, create_exit_status_env(msh));
else
ft_lstadd_back(&var_list, ft_lstnew_safe(msh, NULL));
}
} }
i++; i++;
} }

View File

@ -6,7 +6,7 @@
/* By: whaffman <whaffman@student.codam.nl> +#+ */ /* By: whaffman <whaffman@student.codam.nl> +#+ */
/* +#+ */ /* +#+ */
/* Created: 2025/02/05 16:03:03 by whaffman #+# #+# */ /* Created: 2025/02/05 16:03:03 by whaffman #+# #+# */
/* Updated: 2025/02/26 16:16:37 by whaffman ######## odam.nl */ /* Updated: 2025/02/26 17:39:41 by whaffman ######## odam.nl */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -28,5 +28,6 @@ t_minishell *init_minishell(void)
msh->tokens = NULL; msh->tokens = NULL;
msh->commands = NULL; msh->commands = NULL;
msh->freelist = NULL; msh->freelist = NULL;
msh->exit_status = 0;
return (msh); return (msh);
} }