This commit is contained in:
whaffman 2025-02-26 15:45:10 +01:00
parent a5e877fdd5
commit c2efcca0fa
14 changed files with 95 additions and 93 deletions

View File

@ -31,7 +31,8 @@ t_list *parser_get_commands(t_minishell *minishell)
while (current)
{
token = (t_token *) current->content;
command = parser_command_new(minishell, ft_strdup_safe(minishell, token->value));
command = parser_command_new(minishell,
ft_strdup_safe(minishell, token->value));
command->args = parser_get_arguments(current, minishell);
command->redirect_in = redirect_get_inputs(minishell, current);
command->redirect_out = redirect_get_outputs(minishell, current);

View File

@ -6,7 +6,7 @@
/* By: qmennen <qmennen@student.codam.nl> +#+ */
/* +#+ */
/* Created: 2025/02/11 16:18:21 by qmennen #+# #+# */
/* Updated: 2025/02/25 14:41:57 by whaffman ######## odam.nl */
/* Updated: 2025/02/26 15:32:45 by whaffman ######## odam.nl */
/* */
/* ************************************************************************** */
@ -17,7 +17,6 @@ t_command *parser_command_new(t_minishell *minishell, char *cmd)
t_command *command;
command = malloc_safe(minishell, sizeof(t_command));
\
command->args = NULL;
command->fd_in = 0;
command->fd_out = 1;

View File

@ -1,12 +1,12 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* prompt.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: qmennen <qmennen@student.codam.nl> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* :::::::: */
/* prompt.c :+: :+: */
/* +:+ */
/* By: qmennen <qmennen@student.codam.nl> +#+ */
/* +#+ */
/* Created: 2025/02/04 16:13:08 by whaffman #+# #+# */
/* Updated: 2025/02/25 18:41:56 by qmennen ### ########.fr */
/* Updated: 2025/02/26 15:33:15 by whaffman ######## odam.nl */
/* */
/* ************************************************************************** */
@ -83,7 +83,7 @@ char *get_path(t_minishell *minishell)
ft_strlcpy(result, BLUE, len);
ft_strlcat(result, cwd, len);
ft_strlcat(result, RESET "> ", len);
free_safe(minishell,(void **) &cwd);
free_safe(minishell, (void **) &cwd);
return (result);
}

View File

@ -12,7 +12,7 @@
#include "redirect.h"
static void process_heredoc(t_minishell *ms, t_token *heredoc, t_token *delim)
static void process_heredoc(t_minishell *msh, t_token *heredoc, t_token *delim)
{
char *line;
int fd;
@ -20,7 +20,6 @@ static void process_heredoc(t_minishell *ms, t_token *heredoc, t_token *delim)
fd = open(".ms_heredoc", O_WRONLY | O_CREAT | O_TRUNC, 0644);
if (fd < 0) //TODO: Will this work?
return ;
while (TRUE)
{
line = readline(">");
@ -33,7 +32,7 @@ static void process_heredoc(t_minishell *ms, t_token *heredoc, t_token *delim)
}
close(fd);
heredoc->type = T_REDIRECT_IN;
delim->value = ft_strdup_safe(ms, ".ms_heredoc");
delim->value = ft_strdup_safe(msh, ".ms_heredoc");
}
t_list *redirect_get_inputs(t_minishell *minishell, t_list *list)

View File

@ -12,7 +12,7 @@
#include "minishell.h"
t_list *redirect_get_outputs(t_minishell *minishell, t_list *list)
t_list *redirect_get_outputs(t_minishell *msh, t_list *list)
{
t_list *current;
t_list *redirects;
@ -33,13 +33,13 @@ t_list *redirect_get_outputs(t_minishell *minishell, t_list *list)
if (redirect_is_valid(current, token))
{
ft_lstadd_front(&redirects,
ft_lstnew_safe(minishell, redirect_new(minishell, token->type, ft_strdup_safe(minishell, ((t_token *)current->next->content)->value))));
ft_lstnew_safe(msh, redirect_new(msh, token->type, ft_strdup_safe(msh, ((t_token *)current->next->content)->value))));
current = current->next;
continue ;
}
else
{
ft_lstadd_front(&redirects, ft_lstnew_safe(minishell, redirect_new(minishell, T_ERROR, NULL)));
ft_lstadd_front(&redirects, ft_lstnew_safe(msh, redirect_new(msh, T_ERROR, NULL)));
break ;
}
current = current->next;

View File

@ -12,11 +12,11 @@
#include "minishell.h"
t_redirect *redirect_new(t_minishell * minishell, t_token_type type, char *value)
t_redirect *redirect_new(t_minishell *msh, t_token_type type, char *value)
{
t_redirect *result;
result = malloc_safe(minishell, sizeof(t_redirect));
result = malloc_safe(msh, sizeof(t_redirect));
result->type = type;
result->value = NULL;
if (value)

View File

@ -14,8 +14,10 @@
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);
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)
@ -32,6 +34,9 @@ int redirect_is_valid(t_list *lst, t_token *token)
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);
return (token->type == T_PIPE
|| token->type == T_AND
|| token->type == T_OR
|| token->type == T_EOF
|| token->type == T_ERROR);
}

View File

@ -6,13 +6,12 @@
/* By: whaffman <whaffman@student.codam.nl> +#+ */
/* +#+ */
/* Created: 2025/02/19 12:18:47 by whaffman #+# #+# */
/* Updated: 2025/02/19 17:30:12 by whaffman ######## odam.nl */
/* Updated: 2025/02/26 15:42:30 by whaffman ######## odam.nl */
/* */
/* ************************************************************************** */
#include "minishell.h"
void sigint_minishell_handler(int signum)
{
(void)signum;
@ -36,30 +35,3 @@ void sig_parent_handler(int signum)
(void)signum;
ft_putstr_fd("\n", 1);
}
void signal_init_minishell(void)
{
signal(SIGINT, sigint_minishell_handler);
signal(SIGQUIT, SIG_IGN);
}
void signal_init_parent(void)
{
signal(SIGINT, sig_parent_handler);
signal(SIGQUIT, sig_parent_handler);
}
void signal_init_child(void)
{
signal(SIGINT, SIG_DFL);
signal(SIGQUIT, SIG_DFL);
}
void signal_init_heredoc(void)
{
signal(SIGINT, sigint_heredoc_handler);
signal(SIGQUIT, SIG_IGN);
}

View File

@ -0,0 +1,37 @@
/* ************************************************************************** */
/* */
/* :::::::: */
/* signal_init.c.c :+: :+: */
/* +:+ */
/* By: whaffman <whaffman@student.codam.nl> +#+ */
/* +#+ */
/* Created: 2025/02/26 15:39:01 by whaffman #+# #+# */
/* Updated: 2025/02/26 15:39:46 by whaffman ######## odam.nl */
/* */
/* ************************************************************************** */
#include "minishell.h"
void signal_init_minishell(void)
{
signal(SIGINT, sigint_minishell_handler);
signal(SIGQUIT, SIG_IGN);
}
void signal_init_parent(void)
{
signal(SIGINT, sig_parent_handler);
signal(SIGQUIT, sig_parent_handler);
}
void signal_init_child(void)
{
signal(SIGINT, SIG_DFL);
signal(SIGQUIT, SIG_DFL);
}
void signal_init_heredoc(void)
{
signal(SIGINT, sigint_heredoc_handler);
signal(SIGQUIT, SIG_IGN);
}

View File

@ -12,7 +12,6 @@
#include "minishell.h"
void check_malloc(t_minishell *minishell, void *ptr)
{
t_list *new;

View File

@ -12,7 +12,6 @@
#include "minishell.h"
void error_msg(char *func, char *msg)
{
if (errno)

View File

@ -6,7 +6,7 @@
/* By: whaffman <whaffman@student.codam.nl> +#+ */
/* +#+ */
/* Created: 2025/02/05 16:03:57 by whaffman #+# #+# */
/* Updated: 2025/02/25 16:02:57 by whaffman ######## odam.nl */
/* Updated: 2025/02/26 15:43:00 by whaffman ######## odam.nl */
/* */
/* ************************************************************************** */
@ -14,10 +14,6 @@
void free_minishell(t_minishell **minishell)
{
// if ((*minishell)->line)
// free_minishell_line(*minishell);
// if ((*minishell)->environment)
// environment_free_list(*minishell);
free_freelist(*minishell);
free(*minishell);
*minishell = NULL;

View File

@ -6,16 +6,12 @@
/* By: whaffman <whaffman@student.codam.nl> +#+ */
/* +#+ */
/* Created: 2025/02/25 15:09:34 by whaffman #+# #+# */
/* Updated: 2025/02/25 18:06:06 by whaffman ######## odam.nl */
/* Updated: 2025/02/26 15:43:08 by whaffman ######## odam.nl */
/* */
/* ************************************************************************** */
#include "minishell.h"
#include <execinfo.h>
#include <stdio.h>
#include <stdlib.h>
void free_safe(t_minishell *minishell, void **ptr)
{

View File

@ -20,4 +20,3 @@ char *ft_strjoin_safe(t_minishell *minishell, const char *s1, const char *s2)
check_malloc(minishell, new_str);
return (new_str);
}