Merge remote-tracking branch 'origin/main' into willem

This commit is contained in:
whaffman 2025-02-23 13:36:40 +01:00
commit 1d4316cbf1
19 changed files with 632 additions and 405 deletions

View File

@ -6,7 +6,7 @@
# By: qmennen <qmennen@student.codam.nl> +#+ #
# +#+ #
# Created: 2024/10/15 11:48:46 by whaffman #+# #+# #
# Updated: 2025/02/23 12:30:21 by willem ######## odam.nl #
# Updated: 2025/02/23 13:34:57 by willem ######## odam.nl #
# #
# **************************************************************************** #

View File

@ -1,21 +1,22 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* debug.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: qmennen <qmennen@student.codam.nl> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/02/18 20:06:53 by qmennen #+# #+# */
/* Updated: 2025/02/18 20:10:49 by qmennen ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef DEBUG_H
# define DEBUG_H
# include "minishell.h"
void print_commands(void *param);
void token_print(void *param);
#endif
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* debug.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: qmennen <qmennen@student.codam.nl> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/02/18 20:06:53 by qmennen #+# #+# */
/* Updated: 2025/02/18 20:10:49 by qmennen ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef DEBUG_H
# define DEBUG_H
# include "minishell.h"
void print_commands(void *param);
void token_print(void *param);
void print_redirects(void *param);
#endif

View File

@ -1,49 +1,50 @@
/* ************************************************************************** */
/* */
/* :::::::: */
/* minishell.h :+: :+: */
/* +:+ */
/* By: whaffman <whaffman@student.codam.nl> +#+ */
/* +#+ */
/* Created: 2025/02/04 16:13:13 by whaffman #+# #+# */
/* Updated: 2025/02/20 11:35:24 by whaffman ######## odam.nl */
/* */
/* ************************************************************************** */
#ifndef MINISHELL_H
# define MINISHELL_H
# include "allowed.h"
# include "libft.h"
# include "typedef.h"
# include "signals.h"
# include "environment.h"
# include "prompt.h"
# include "tokenizer.h"
# include "builtin.h"
# include "executor.h"
# include "parser.h"
# include "expander.h"
# include "debug.h"
# include "utils.h"
# define TRUE 1
# define FALSE 0
# define SUCCESS 1
# define FAILURE 0
# define BOLD "\001\033[1m\002"
# define RED "\001\033[0;31m\002"
# define GREEN "\001\033[0;32m\002"
# define YELLOW "\001\033[0;33m\002"
# define BLUE "\001\033[0;34m\002"
# define MAGENTA "\001\033[0;35m\002"
# define CYAN "\001\033[0;36m\002"
# define RESET "\001\033[0m\002"
# define PROMPT RESET "🐚" GREEN "minishell" RESET ": "
# define PROMPT_LEN 51
void token_print(void *param);
#endif
/* ************************************************************************** */
/* */
/* :::::::: */
/* minishell.h :+: :+: */
/* +:+ */
/* By: marvin <marvin@student.42.fr> +#+ */
/* +#+ */
/* Created: 2025/02/04 16:13:13 by whaffman #+# #+# */
/* Updated: 2025/02/23 12:28:23 by Quinten ######## odam.nl */
/* */
/* ************************************************************************** */
#ifndef MINISHELL_H
# define MINISHELL_H
# include "allowed.h"
# include "libft.h"
# include "typedef.h"
# include "signals.h"
# include "environment.h"
# include "prompt.h"
# include "tokenizer.h"
# include "builtin.h"
# include "executor.h"
# include "parser.h"
# include "expander.h"
# include "redirect.h"
# include "debug.h"
# include "utils.h"
# define TRUE 1
# define FALSE 0
# define SUCCESS 1
# define FAILURE 0
# define BOLD "\001\033[1m\002"
# define RED "\001\033[0;31m\002"
# define GREEN "\001\033[0;32m\002"
# define YELLOW "\001\033[0;33m\002"
# define BLUE "\001\033[0;34m\002"
# define MAGENTA "\001\033[0;35m\002"
# define CYAN "\001\033[0;36m\002"
# define RESET "\001\033[0m\002"
# define PROMPT RESET "🐚" GREEN "minishell" RESET ": "
# define PROMPT_LEN 51
void token_print(void *param);
#endif

View File

@ -1,22 +1,23 @@
/* ************************************************************************** */
/* */
/* :::::::: */
/* parser.h :+: :+: */
/* +:+ */
/* By: qmennen <qmennen@student.codam.nl> +#+ */
/* +#+ */
/* Created: 2025/02/11 14:03:03 by qmennen #+# #+# */
/* Updated: 2025/02/11 17:19:01 by whaffman ######## odam.nl */
/* */
/* ************************************************************************** */
#ifndef PARSER_H
# define PARSER_H
# include "minishell.h"
t_command *parser_command_new(char *cmd);
char **parser_get_arguments(t_list *list, t_minishell *minishell);
t_list *parser_get_commands(t_minishell *minishell);
#endif
/* ************************************************************************** */
/* */
/* :::::::: */
/* parser.h :+: :+: */
/* +:+ */
/* By: qmennen <qmennen@student.codam.nl> +#+ */
/* +#+ */
/* Created: 2025/02/11 14:03:03 by qmennen #+# #+# */
/* Updated: 2025/02/11 17:19:01 by whaffman ######## odam.nl */
/* */
/* ************************************************************************** */
#ifndef PARSER_H
# define PARSER_H
# include "minishell.h"
t_command *parser_command_new(char *cmd);
char **parser_get_arguments(t_list *list, t_minishell *minishell);
t_list *parser_get_commands(t_minishell *minishell);
t_list *parser_get_input_redirects(t_list *list);
#endif

24
inc/redirect.h Normal file
View File

@ -0,0 +1,24 @@
/* ************************************************************************** */
/* */
/* :::::::: */
/* redirect.h :+: :+: */
/* +:+ */
/* By: Quinten <qmennen@student.codam.nl> +#+ */
/* +#+ */
/* Created: 2025/02/23 12:26:29 by Quinten #+# #+# */
/* Updated: 2025/02/23 12:26:29 by Quinten ######## odam.nl */
/* */
/* ************************************************************************** */
#ifndef REDIRECT_H
# define REDIRECT_H
# include "minishell.h"
t_redirect *redirect_new(t_token_type type, char *value);
t_list *redirect_get_inputs(t_list *list);
t_list *redirect_get_outputs(t_list *list);
int redirect_is_valid(t_list *lst, t_token *token);
int redirect_token_type(t_token *token);
int redirect_is_delimiter(t_token *token);
#endif

View File

@ -1,29 +1,29 @@
/* ************************************************************************** */
/* */
/* :::::::: */
/* utils.h :+: :+: */
/* +:+ */
/* By: whaffman <whaffman@student.codam.nl> +#+ */
/* +#+ */
/* Created: 2025/02/05 16:06:35 by whaffman #+# #+# */
/* Updated: 2025/02/20 18:07:19 by whaffman ######## odam.nl */
/* */
/* ************************************************************************** */
#ifndef UTILS_H
# define UTILS_H
void free_minishell_line(t_minishell *minishell);
void free_minishell(t_minishell *minishell);
void free_command_list(void *content);
t_minishell *init_minishell(void);
void print_banner(void);
void print_list(void *content);
void simple_builtins(t_minishell *minishell);
void error_msg(char *func, char *msg);
void check_malloc(void *ptr);
char *ft_strdup_safe(const char *str);
char *ft_strjoin_safe(const char *s1, const char *s2);
void *ft_malloc_safe(size_t size);
#endif // UTILS_H
/* ************************************************************************** */
/* */
/* :::::::: */
/* utils.h :+: :+: */
/* +:+ */
/* By: whaffman <whaffman@student.codam.nl> +#+ */
/* +#+ */
/* Created: 2025/02/05 16:06:35 by whaffman #+# #+# */
/* Updated: 2025/02/20 18:07:19 by whaffman ######## odam.nl */
/* */
/* ************************************************************************** */
#ifndef UTILS_H
# define UTILS_H
void free_minishell_line(t_minishell *minishell);
void free_minishell(t_minishell *minishell);
void free_command_list(void *content);
t_minishell *init_minishell(void);
void print_banner(void);
void print_list(void *content);
void simple_builtins(t_minishell *minishell);
void error_msg(char *func, char *msg);
void check_malloc(void *ptr);
char *ft_strdup_safe(const char *str);
char *ft_strjoin_safe(const char *s1, const char *s2);
void *ft_malloc_safe(size_t size);
#endif // UTILS_H

View File

@ -1,38 +1,52 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* print_commands.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: qmennen <qmennen@student.codam.nl> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/02/18 20:06:37 by qmennen #+# #+# */
/* Updated: 2025/02/18 20:11:45 by qmennen ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
void print_commands(void *param)
{
t_command *command;
int i;
command = (t_command *)param;
if (!command)
return ;
printf("command: %s\n", command->command);
printf("args: ");
i = 0;
while (command->args[i++])
printf("%s ", command->args[i]);
printf("\n");
}
void token_print(void *param)
{
t_token *token;
token = (t_token *)param;
printf("token type %i, value %s\n", token->type, token->value);
}
/* ************************************************************************** */
/* */
/* :::::::: */
/* print_commands.c :+: :+: */
/* +:+ */
/* By: marvin <marvin@student.42.fr> +#+ */
/* +#+ */
/* Created: 2025/02/18 20:06:37 by qmennen #+# #+# */
/* Updated: 2025/02/23 12:43:35 by Quinten ######## odam.nl */
/* */
/* ************************************************************************** */
#include "minishell.h"
void print_commands(void *param)
{
t_command *command;
int i;
command = (t_command *)param;
if (!command)
return ;
printf("command: %s\n", command->command);
printf("-- Args: ");
i = 0;
while (command->args[i++])
printf("%s ", command->args[i]);
printf("\n");
printf("-- Input redirects:\n");
ft_lstiter(command->redirect_in, print_redirects);
printf("-- Output redirects:\n");
ft_lstiter(command->redirect_out, print_redirects);
}
void print_redirects(void *param)
{
t_redirect *redirect;
redirect = (t_redirect *)param;
if (!redirect)
return ;
printf(" Redirect %i value %s\n", redirect->type, redirect->value);
}
void token_print(void *param)
{
t_token *token;
token = (t_token *)param;
printf("token type %i, value %s\n", token->type, token->value);
}

View File

@ -1,44 +1,43 @@
/* ************************************************************************** */
/* */
/* :::::::: */
/* main.c :+: :+: */
/* +:+ */
/* By: whaffman <whaffman@student.codam.nl> +#+ */
/* +#+ */
/* Created: 2025/02/04 16:19:22 by whaffman #+# #+# */
/* Updated: 2025/02/19 17:59:24 by whaffman ######## odam.nl */
/* */
/* ************************************************************************** */
#include "libft.h"
#include "minishell.h"
#include "utils.h"
int main(int argc, char **argv, char **envp)
{
t_minishell *minishell;
(void)argc;
(void)argv;
print_banner();
history_load();
minishell = init_minishell();
signal_init_minishell();
environment_parse(envp, &(minishell->environment));
while (TRUE)
{
minishell->line = ft_prompt(minishell);
if (minishell->line == NULL)
break ;
minishell->lexer = ft_lexer_new(minishell->line);
minishell->tokens = ft_parse_input(minishell->lexer);
//ft_lstiter(minishell->tokens, token_print);
minishell->commands = parser_get_commands(minishell);
simple_builtins(minishell);
free_minishell_line(minishell);
ft_lstclear(&minishell->commands, free_command_list);
}
ft_lstclear(&minishell->commands, free_command_list);
free_minishell(minishell);
return (EXIT_SUCCESS);
}
/* ************************************************************************** */
/* */
/* :::::::: */
/* main.c :+: :+: */
/* +:+ */
/* By: whaffman <whaffman@student.codam.nl> +#+ */
/* +#+ */
/* Created: 2025/02/04 16:19:22 by whaffman #+# #+# */
/* Updated: 2025/02/19 17:59:24 by whaffman ######## odam.nl */
/* */
/* ************************************************************************** */
#include "libft.h"
#include "minishell.h"
#include "utils.h"
int main(int argc, char **argv, char **envp)
{
t_minishell *minishell;
(void)argc;
(void)argv;
print_banner();
history_load();
minishell = init_minishell();
signal_init_minishell();
environment_parse(envp, &(minishell->environment));
while (TRUE)
{
minishell->line = ft_prompt(minishell);
if (minishell->line == NULL)
break ;
minishell->lexer = ft_lexer_new(minishell->line);
minishell->tokens = ft_parse_input(minishell->lexer);
//ft_lstiter(minishell->tokens, token_print);
minishell->commands = parser_get_commands(minishell);
simple_builtins(minishell);
free_minishell_line(minishell);
}
ft_lstclear(&minishell->commands, free_command_list);
free_minishell(minishell);
return (EXIT_SUCCESS);
}

View File

@ -1,39 +1,46 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* parser_get_commands.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: qmennen <qmennen@student.codam.nl> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/02/11 14:06:02 by qmennen #+# #+# */
/* Updated: 2025/02/18 20:36:01 by qmennen ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
t_list *parser_get_commands(t_minishell *minishell)
{
t_list *command_list;
t_list *current;
t_command *command;
t_token *token;
command_list = NULL;
if (!minishell->tokens)
return (NULL);
current = minishell->tokens;
while (current)
{
token = (t_token *) current->content;
command = parser_command_new(ft_strdup(token->value));
command->args = parser_get_arguments(current, minishell);
ft_lstadd_back(&command_list, ft_lstnew(command));
while (current && ((t_token *)current->content)->type < 3)
current = current->next;
if (current && ((t_token *)current->content)->type >= 3)
current = current->next;
}
// ft_lstiter(command_list, print_commands);
return (command_list);
}
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* parser_get_commands.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: qmennen <qmennen@student.codam.nl> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/02/11 14:06:02 by qmennen #+# #+# */
/* Updated: 2025/02/18 20:36:01 by qmennen ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
static int is_command_token(t_token *token)
{
return (token->type < 3 || redirect_token_type(token));
}
t_list *parser_get_commands(t_minishell *minishell)
{
t_list *command_list;
t_list *current;
t_command *command;
t_token *token;
command_list = NULL;
if (!minishell->tokens)
return (NULL);
current = minishell->tokens;
while (current)
{
token = (t_token *) current->content;
command = parser_command_new(ft_strdup(token->value));
command->args = parser_get_arguments(current, minishell);
command->redirect_in = redirect_get_inputs(current);
command->redirect_out = redirect_get_outputs(current);
ft_lstadd_back(&command_list, ft_lstnew(command));
while (current && is_command_token((t_token *)current->content))
current = current->next;
if (current && ((t_token *)current->content)->type >= 3)
current = current->next;
}
ft_lstiter(command_list, print_commands);
return (command_list);
}

View File

@ -0,0 +1,47 @@
/* ************************************************************************** */
/* */
/* :::::::: */
/* redirect_get_inputs.c :+: :+: */
/* +:+ */
/* By: Quinten <qmennen@student.codam.nl> +#+ */
/* +#+ */
/* Created: 2025/02/23 12:29:05 by Quinten #+# #+# */
/* Updated: 2025/02/23 12:29:05 by Quinten ######## odam.nl */
/* */
/* ************************************************************************** */
# include "redirect.h"
t_list *redirect_get_inputs(t_list *list)
{
t_list *current;
t_list *redirects;
t_token *token;
redirects = NULL;
current = list;
while (current)
{
token = (t_token *)current->content;
if (redirect_is_delimiter(token))
break ;
if (token->type != T_REDIRECT_IN && token->type != T_HEREDOC)
{
current = current->next;
continue ;
}
if (redirect_is_valid(current, token))
{
ft_lstadd_front(&redirects, ft_lstnew(redirect_new(token->type, ft_strdup(((t_token *)current->next->content)->value))));
current = current->next;
continue ;
}
else
{
ft_lstadd_front(&redirects, ft_lstnew(redirect_new(T_ERROR, NULL)));
break ;
}
current = current->next;
}
return (redirects);
}

View File

@ -0,0 +1,47 @@
/* ************************************************************************** */
/* */
/* :::::::: */
/* redirect_get_outputs.c :+: :+: */
/* +:+ */
/* By: Quinten <qmennen@student.codam.nl> +#+ */
/* +#+ */
/* Created: 2025/02/23 12:37:24 by Quinten #+# #+# */
/* Updated: 2025/02/23 12:37:24 by Quinten ######## odam.nl */
/* */
/* ************************************************************************** */
#include "minishell.h"
t_list *redirect_get_outputs(t_list *list)
{
t_list *current;
t_list *redirects;
t_token *token;
redirects = NULL;
current = list;
while (current)
{
token = (t_token *)current->content;
if (redirect_is_delimiter(token))
break;
if (token->type != T_REDIRECT_OUT && token->type != T_APPEND_OUT)
{
current = current->next;
continue ;
}
if (redirect_is_valid(current, token))
{
ft_lstadd_front(&redirects, ft_lstnew(redirect_new(token->type, ft_strdup(((t_token *)current->next->content)->value))));
current = current->next;
continue ;
}
else
{
ft_lstadd_front(&redirects, ft_lstnew(redirect_new(T_ERROR, NULL)));
break ;
}
current = current->next;
}
return (redirects);
}

View File

@ -0,0 +1,25 @@
/* ************************************************************************** */
/* */
/* :::::::: */
/* redirect_new.c :+: :+: */
/* +:+ */
/* By: Quinten <qmennen@student.codam.nl> +#+ */
/* +#+ */
/* Created: 2025/02/23 12:27:33 by Quinten #+# #+# */
/* Updated: 2025/02/23 12:27:33 by Quinten ######## odam.nl */
/* */
/* ************************************************************************** */
#include "minishell.h"
t_redirect *redirect_new(t_token_type type, char *value)
{
t_redirect *result;
result = ft_malloc_safe(sizeof(t_redirect));
result->type = type;
result->value = NULL;
if (value)
result->value = value;
return (result);
}

View File

@ -0,0 +1,37 @@
/* ************************************************************************** */
/* */
/* :::::::: */
/* redirect_valid_type.c :+: :+: */
/* +:+ */
/* By: Quinten <qmennen@student.codam.nl> +#+ */
/* +#+ */
/* Created: 2025/02/23 12:30:18 by Quinten #+# #+# */
/* Updated: 2025/02/23 12:30:18 by Quinten ######## odam.nl */
/* */
/* ************************************************************************** */
#include "minishell.h"
int redirect_token_type(t_token *token)
{
return (token->type == T_REDIRECT_IN || token->type == T_HEREDOC ||
token->type == T_REDIRECT_OUT || token->type == T_APPEND_OUT);
}
int redirect_is_valid(t_list *lst, t_token *token)
{
t_token *next;
if (!lst->next)
return (0);
next = (t_token *)lst->next->content;
if (!next)
return (0);
return (redirect_token_type(token) && next->type < 3);
}
int redirect_is_delimiter(t_token *token)
{
return (token->type == T_PIPE || token->type == T_AND ||
token->type == T_OR || token->type == T_EOF || token->type == T_ERROR);
}

View File

@ -1,23 +1,23 @@
/* ************************************************************************** */
/* */
/* :::::::: */
/* check_malloc.c :+: :+: */
/* +:+ */
/* By: whaffman <whaffman@student.codam.nl> +#+ */
/* +#+ */
/* Created: 2025/02/20 18:00:10 by whaffman #+# #+# */
/* Updated: 2025/02/20 18:01:08 by whaffman ######## odam.nl */
/* */
/* ************************************************************************** */
#include "minishell.h"
void check_malloc(void *ptr)
{
if (ptr == NULL)
{
error_msg("malloc", "can't allocate memory");
exit(1);
}
}
/* ************************************************************************** */
/* */
/* :::::::: */
/* check_malloc.c :+: :+: */
/* +:+ */
/* By: whaffman <whaffman@student.codam.nl> +#+ */
/* +#+ */
/* Created: 2025/02/20 18:00:10 by whaffman #+# #+# */
/* Updated: 2025/02/20 18:01:08 by whaffman ######## odam.nl */
/* */
/* ************************************************************************** */
#include "minishell.h"
void check_malloc(void *ptr)
{
if (ptr == NULL)
{
error_msg("malloc", "can't allocate memory");
exit(1);
}
}

View File

@ -1,34 +1,34 @@
/* ************************************************************************** */
/* */
/* :::::::: */
/* error_msg.c :+: :+: */
/* +:+ */
/* By: whaffman <whaffman@student.codam.nl> +#+ */
/* +#+ */
/* Created: 2025/02/20 17:03:13 by whaffman #+# #+# */
/* Updated: 2025/02/20 17:59:36 by whaffman ######## odam.nl */
/* */
/* ************************************************************************** */
#include "minishell.h"
void error_msg(char *func, char *msg)
{
if (errno)
perror(RED BOLD "minishell" RESET);
else
{
ft_putstr_fd(RED BOLD "minishell" RESET ": ", 2);
if (func != NULL)
{
ft_putstr_fd(func, 2);
ft_putstr_fd(": ", 2);
}
if (msg != NULL)
ft_putstr_fd(msg, 2);
else
ft_putstr_fd("general error", 2);
ft_putstr_fd("\n", 2);
}
}
/* ************************************************************************** */
/* */
/* :::::::: */
/* error_msg.c :+: :+: */
/* +:+ */
/* By: whaffman <whaffman@student.codam.nl> +#+ */
/* +#+ */
/* Created: 2025/02/20 17:03:13 by whaffman #+# #+# */
/* Updated: 2025/02/20 17:59:36 by whaffman ######## odam.nl */
/* */
/* ************************************************************************** */
#include "minishell.h"
void error_msg(char *func, char *msg)
{
if (errno)
perror(RED BOLD "minishell" RESET);
else
{
ft_putstr_fd(RED BOLD "minishell" RESET ": ", 2);
if (func != NULL)
{
ft_putstr_fd(func, 2);
ft_putstr_fd(": ", 2);
}
if (msg != NULL)
ft_putstr_fd(msg, 2);
else
ft_putstr_fd("general error", 2);
ft_putstr_fd("\n", 2);
}
}

View File

@ -1,38 +1,62 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* free_command_list.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: qmennen <qmennen@student.codam.nl> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/02/11 14:24:05 by qmennen #+# #+# */
/* Updated: 2025/02/11 14:27:02 by qmennen ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
static void free_args(char **args)
{
int i;
i = 0;
while (args[i])
{
free(args[i]);
i++;
}
free(args);
}
void free_command_list(void *content)
{
t_command *command;
command = (t_command *)content;
if (command->command)
free(command->command);
if (command->args)
free_args(command->args);
free(command);
}
/* ************************************************************************** */
/* */
/* :::::::: */
/* free_command_list.c :+: :+: */
/* +:+ */
/* By: marvin <marvin@student.42.fr> +#+ */
/* +#+ */
/* Created: 2025/02/11 14:24:05 by qmennen #+# #+# */
/* Updated: 2025/02/23 12:40:17 by Quinten ######## odam.nl */
/* */
/* ************************************************************************** */
#include "minishell.h"
static void free_args(char **args)
{
int i;
i = 0;
while (args[i])
{
free(args[i]);
i++;
}
free(args);
}
static void free_redirects(t_list *lst)
{
t_redirect *redir;
t_list *current;
t_list *last;
current = lst;
while (current)
{
last = current;
redir = (t_redirect *)current->content;
if (redir && redir->value)
free(redir->value);
if (redir)
free(redir);
current = current->next;
free(last);
}
}
void free_command_list(void *content)
{
t_command *command;
command = (t_command *)content;
if (command->command)
free(command->command);
if (command->args)
free_args(command->args);
if (command->redirect_in)
free_redirects(command->redirect_in);
if (command->redirect_out)
free_redirects(command->redirect_out);
free(command);
}

View File

@ -1,22 +1,22 @@
/* ************************************************************************** */
/* */
/* :::::::: */
/* ft_malloc_safe.c :+: :+: */
/* +:+ */
/* By: whaffman <whaffman@student.codam.nl> +#+ */
/* +#+ */
/* Created: 2025/02/20 18:06:46 by whaffman #+# #+# */
/* Updated: 2025/02/20 18:07:00 by whaffman ######## odam.nl */
/* */
/* ************************************************************************** */
#include "minishell.h"
void *ft_malloc_safe(size_t size)
{
void *ptr;
ptr = malloc(size);
check_malloc(ptr);
return (ptr);
}
/* ************************************************************************** */
/* */
/* :::::::: */
/* ft_malloc_safe.c :+: :+: */
/* +:+ */
/* By: whaffman <whaffman@student.codam.nl> +#+ */
/* +#+ */
/* Created: 2025/02/20 18:06:46 by whaffman #+# #+# */
/* Updated: 2025/02/20 18:07:00 by whaffman ######## odam.nl */
/* */
/* ************************************************************************** */
#include "minishell.h"
void *ft_malloc_safe(size_t size)
{
void *ptr;
ptr = malloc(size);
check_malloc(ptr);
return (ptr);
}

View File

@ -1,22 +1,22 @@
/* ************************************************************************** */
/* */
/* :::::::: */
/* ft_strdup_safe.c :+: :+: */
/* +:+ */
/* By: whaffman <whaffman@student.codam.nl> +#+ */
/* +#+ */
/* Created: 2025/02/20 18:01:27 by whaffman #+# #+# */
/* Updated: 2025/02/20 18:04:53 by whaffman ######## odam.nl */
/* */
/* ************************************************************************** */
#include "minishell.h"
char *ft_strdup_safe(const char *str)
{
char *new_str;
new_str = ft_strdup(str);
check_malloc(new_str);
return (new_str);
}
/* ************************************************************************** */
/* */
/* :::::::: */
/* ft_strdup_safe.c :+: :+: */
/* +:+ */
/* By: whaffman <whaffman@student.codam.nl> +#+ */
/* +#+ */
/* Created: 2025/02/20 18:01:27 by whaffman #+# #+# */
/* Updated: 2025/02/20 18:04:53 by whaffman ######## odam.nl */
/* */
/* ************************************************************************** */
#include "minishell.h"
char *ft_strdup_safe(const char *str)
{
char *new_str;
new_str = ft_strdup(str);
check_malloc(new_str);
return (new_str);
}

View File

@ -1,23 +1,23 @@
/* ************************************************************************** */
/* */
/* :::::::: */
/* ft_strjoin_safe.c :+: :+: */
/* +:+ */
/* By: whaffman <whaffman@student.codam.nl> +#+ */
/* +#+ */
/* Created: 2025/02/20 18:02:31 by whaffman #+# #+# */
/* Updated: 2025/02/20 18:04:23 by whaffman ######## odam.nl */
/* */
/* ************************************************************************** */
#include "minishell.h"
char *ft_strjoin_safe(const char *s1, const char *s2)
{
char *new_str;
new_str = ft_strjoin(s1, s2);
check_malloc(new_str);
return (new_str);
}
/* ************************************************************************** */
/* */
/* :::::::: */
/* ft_strjoin_safe.c :+: :+: */
/* +:+ */
/* By: whaffman <whaffman@student.codam.nl> +#+ */
/* +#+ */
/* Created: 2025/02/20 18:02:31 by whaffman #+# #+# */
/* Updated: 2025/02/20 18:04:23 by whaffman ######## odam.nl */
/* */
/* ************************************************************************** */
#include "minishell.h"
char *ft_strjoin_safe(const char *s1, const char *s2)
{
char *new_str;
new_str = ft_strjoin(s1, s2);
check_malloc(new_str);
return (new_str);
}